@rootreeweb/js-lib 4.0.10

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 (218) hide show
  1. package/README.md +49 -0
  2. package/dist/cjs/browser/dom.cjs +95 -0
  3. package/dist/cjs/browser/dom.d.ts +44 -0
  4. package/dist/cjs/browser/dom.d.ts.map +1 -0
  5. package/dist/cjs/browser/dom.js.map +1 -0
  6. package/dist/cjs/browser/download.cjs +40 -0
  7. package/dist/cjs/browser/download.d.ts +16 -0
  8. package/dist/cjs/browser/download.d.ts.map +1 -0
  9. package/dist/cjs/browser/download.js.map +1 -0
  10. package/dist/cjs/browser/index.cjs +20 -0
  11. package/dist/cjs/browser/index.d.ts +4 -0
  12. package/dist/cjs/browser/index.d.ts.map +1 -0
  13. package/dist/cjs/browser/index.js.map +1 -0
  14. package/dist/cjs/browser/queryOrThrow.cjs +42 -0
  15. package/dist/cjs/browser/queryOrThrow.d.ts +44 -0
  16. package/dist/cjs/browser/queryOrThrow.d.ts.map +1 -0
  17. package/dist/cjs/browser/queryOrThrow.js.map +1 -0
  18. package/dist/cjs/general/arrays.cjs +151 -0
  19. package/dist/cjs/general/arrays.d.ts +70 -0
  20. package/dist/cjs/general/arrays.d.ts.map +1 -0
  21. package/dist/cjs/general/arrays.js.map +1 -0
  22. package/dist/cjs/general/boolean.cjs +19 -0
  23. package/dist/cjs/general/boolean.d.ts +10 -0
  24. package/dist/cjs/general/boolean.d.ts.map +1 -0
  25. package/dist/cjs/general/boolean.js.map +1 -0
  26. package/dist/cjs/general/clock.cjs +22 -0
  27. package/dist/cjs/general/clock.d.ts +12 -0
  28. package/dist/cjs/general/clock.d.ts.map +1 -0
  29. package/dist/cjs/general/clock.js.map +1 -0
  30. package/dist/cjs/general/dates/create.cjs +81 -0
  31. package/dist/cjs/general/dates/create.d.ts +54 -0
  32. package/dist/cjs/general/dates/create.d.ts.map +1 -0
  33. package/dist/cjs/general/dates/create.js.map +1 -0
  34. package/dist/cjs/general/dates/dates.cjs +88 -0
  35. package/dist/cjs/general/dates/dates.d.ts +56 -0
  36. package/dist/cjs/general/dates/dates.d.ts.map +1 -0
  37. package/dist/cjs/general/dates/dates.js.map +1 -0
  38. package/dist/cjs/general/dates/get.cjs +77 -0
  39. package/dist/cjs/general/dates/get.d.ts +41 -0
  40. package/dist/cjs/general/dates/get.d.ts.map +1 -0
  41. package/dist/cjs/general/dates/get.js.map +1 -0
  42. package/dist/cjs/general/dates/index.cjs +20 -0
  43. package/dist/cjs/general/dates/index.d.ts +4 -0
  44. package/dist/cjs/general/dates/index.d.ts.map +1 -0
  45. package/dist/cjs/general/dates/index.js.map +1 -0
  46. package/dist/cjs/general/forms.cjs +31 -0
  47. package/dist/cjs/general/forms.d.ts +17 -0
  48. package/dist/cjs/general/forms.d.ts.map +1 -0
  49. package/dist/cjs/general/forms.js.map +1 -0
  50. package/dist/cjs/general/images.cjs +23 -0
  51. package/dist/cjs/general/images.d.ts +17 -0
  52. package/dist/cjs/general/images.d.ts.map +1 -0
  53. package/dist/cjs/general/images.js.map +1 -0
  54. package/dist/cjs/general/index.cjs +31 -0
  55. package/dist/cjs/general/index.d.ts +15 -0
  56. package/dist/cjs/general/index.d.ts.map +1 -0
  57. package/dist/cjs/general/index.js.map +1 -0
  58. package/dist/cjs/general/localization.cjs +199 -0
  59. package/dist/cjs/general/localization.d.ts +83 -0
  60. package/dist/cjs/general/localization.d.ts.map +1 -0
  61. package/dist/cjs/general/localization.js.map +1 -0
  62. package/dist/cjs/general/maps.cjs +63 -0
  63. package/dist/cjs/general/maps.d.ts +35 -0
  64. package/dist/cjs/general/maps.d.ts.map +1 -0
  65. package/dist/cjs/general/maps.js.map +1 -0
  66. package/dist/cjs/general/messenger/createMessenger.cjs +68 -0
  67. package/dist/cjs/general/messenger/createMessenger.d.ts +10 -0
  68. package/dist/cjs/general/messenger/createMessenger.d.ts.map +1 -0
  69. package/dist/cjs/general/messenger/createMessenger.js.map +1 -0
  70. package/dist/cjs/general/messenger/index.cjs +19 -0
  71. package/dist/cjs/general/messenger/index.d.ts +3 -0
  72. package/dist/cjs/general/messenger/index.d.ts.map +1 -0
  73. package/dist/cjs/general/messenger/index.js.map +1 -0
  74. package/dist/cjs/general/messenger/types.cjs +3 -0
  75. package/dist/cjs/general/messenger/types.d.ts +26 -0
  76. package/dist/cjs/general/messenger/types.d.ts.map +1 -0
  77. package/dist/cjs/general/messenger/types.js.map +1 -0
  78. package/dist/cjs/general/namedEntities.cjs +260 -0
  79. package/dist/cjs/general/namedEntities.d.ts +256 -0
  80. package/dist/cjs/general/namedEntities.d.ts.map +1 -0
  81. package/dist/cjs/general/namedEntities.js.map +1 -0
  82. package/dist/cjs/general/numbers.cjs +94 -0
  83. package/dist/cjs/general/numbers.d.ts +43 -0
  84. package/dist/cjs/general/numbers.d.ts.map +1 -0
  85. package/dist/cjs/general/numbers.js.map +1 -0
  86. package/dist/cjs/general/objects.cjs +98 -0
  87. package/dist/cjs/general/objects.d.ts +45 -0
  88. package/dist/cjs/general/objects.d.ts.map +1 -0
  89. package/dist/cjs/general/objects.js.map +1 -0
  90. package/dist/cjs/general/sorting.cjs +72 -0
  91. package/dist/cjs/general/sorting.d.ts +32 -0
  92. package/dist/cjs/general/sorting.d.ts.map +1 -0
  93. package/dist/cjs/general/sorting.js.map +1 -0
  94. package/dist/cjs/general/string.cjs +73 -0
  95. package/dist/cjs/general/string.d.ts +31 -0
  96. package/dist/cjs/general/string.d.ts.map +1 -0
  97. package/dist/cjs/general/string.js.map +1 -0
  98. package/dist/cjs/general/timeout.cjs +17 -0
  99. package/dist/cjs/general/timeout.d.ts +8 -0
  100. package/dist/cjs/general/timeout.d.ts.map +1 -0
  101. package/dist/cjs/general/timeout.js.map +1 -0
  102. package/dist/cjs/index.cjs +20 -0
  103. package/dist/cjs/index.d.ts +4 -0
  104. package/dist/cjs/index.d.ts.map +1 -0
  105. package/dist/cjs/index.js.map +1 -0
  106. package/dist/cjs/node/index.cjs +30 -0
  107. package/dist/cjs/node/index.d.ts +25 -0
  108. package/dist/cjs/node/index.d.ts.map +1 -0
  109. package/dist/cjs/node/index.js.map +1 -0
  110. package/dist/esm/browser/dom.d.ts +44 -0
  111. package/dist/esm/browser/dom.d.ts.map +1 -0
  112. package/dist/esm/browser/dom.js +88 -0
  113. package/dist/esm/browser/dom.js.map +1 -0
  114. package/dist/esm/browser/download.d.ts +16 -0
  115. package/dist/esm/browser/download.d.ts.map +1 -0
  116. package/dist/esm/browser/download.js +36 -0
  117. package/dist/esm/browser/download.js.map +1 -0
  118. package/dist/esm/browser/index.d.ts +4 -0
  119. package/dist/esm/browser/index.d.ts.map +1 -0
  120. package/dist/esm/browser/index.js +4 -0
  121. package/dist/esm/browser/index.js.map +1 -0
  122. package/dist/esm/browser/queryOrThrow.d.ts +44 -0
  123. package/dist/esm/browser/queryOrThrow.d.ts.map +1 -0
  124. package/dist/esm/browser/queryOrThrow.js +39 -0
  125. package/dist/esm/browser/queryOrThrow.js.map +1 -0
  126. package/dist/esm/general/arrays.d.ts +70 -0
  127. package/dist/esm/general/arrays.d.ts.map +1 -0
  128. package/dist/esm/general/arrays.js +144 -0
  129. package/dist/esm/general/arrays.js.map +1 -0
  130. package/dist/esm/general/boolean.d.ts +10 -0
  131. package/dist/esm/general/boolean.d.ts.map +1 -0
  132. package/dist/esm/general/boolean.js +16 -0
  133. package/dist/esm/general/boolean.js.map +1 -0
  134. package/dist/esm/general/clock.d.ts +12 -0
  135. package/dist/esm/general/clock.d.ts.map +1 -0
  136. package/dist/esm/general/clock.js +19 -0
  137. package/dist/esm/general/clock.js.map +1 -0
  138. package/dist/esm/general/dates/create.d.ts +54 -0
  139. package/dist/esm/general/dates/create.d.ts.map +1 -0
  140. package/dist/esm/general/dates/create.js +73 -0
  141. package/dist/esm/general/dates/create.js.map +1 -0
  142. package/dist/esm/general/dates/dates.d.ts +56 -0
  143. package/dist/esm/general/dates/dates.d.ts.map +1 -0
  144. package/dist/esm/general/dates/dates.js +82 -0
  145. package/dist/esm/general/dates/dates.js.map +1 -0
  146. package/dist/esm/general/dates/get.d.ts +41 -0
  147. package/dist/esm/general/dates/get.d.ts.map +1 -0
  148. package/dist/esm/general/dates/get.js +70 -0
  149. package/dist/esm/general/dates/get.js.map +1 -0
  150. package/dist/esm/general/dates/index.d.ts +4 -0
  151. package/dist/esm/general/dates/index.d.ts.map +1 -0
  152. package/dist/esm/general/dates/index.js +4 -0
  153. package/dist/esm/general/dates/index.js.map +1 -0
  154. package/dist/esm/general/forms.d.ts +17 -0
  155. package/dist/esm/general/forms.d.ts.map +1 -0
  156. package/dist/esm/general/forms.js +27 -0
  157. package/dist/esm/general/forms.js.map +1 -0
  158. package/dist/esm/general/images.d.ts +17 -0
  159. package/dist/esm/general/images.d.ts.map +1 -0
  160. package/dist/esm/general/images.js +20 -0
  161. package/dist/esm/general/images.js.map +1 -0
  162. package/dist/esm/general/index.d.ts +15 -0
  163. package/dist/esm/general/index.d.ts.map +1 -0
  164. package/dist/esm/general/index.js +15 -0
  165. package/dist/esm/general/index.js.map +1 -0
  166. package/dist/esm/general/localization.d.ts +83 -0
  167. package/dist/esm/general/localization.d.ts.map +1 -0
  168. package/dist/esm/general/localization.js +188 -0
  169. package/dist/esm/general/localization.js.map +1 -0
  170. package/dist/esm/general/maps.d.ts +35 -0
  171. package/dist/esm/general/maps.d.ts.map +1 -0
  172. package/dist/esm/general/maps.js +59 -0
  173. package/dist/esm/general/maps.js.map +1 -0
  174. package/dist/esm/general/messenger/createMessenger.d.ts +10 -0
  175. package/dist/esm/general/messenger/createMessenger.d.ts.map +1 -0
  176. package/dist/esm/general/messenger/createMessenger.js +65 -0
  177. package/dist/esm/general/messenger/createMessenger.js.map +1 -0
  178. package/dist/esm/general/messenger/index.d.ts +3 -0
  179. package/dist/esm/general/messenger/index.d.ts.map +1 -0
  180. package/dist/esm/general/messenger/index.js +3 -0
  181. package/dist/esm/general/messenger/index.js.map +1 -0
  182. package/dist/esm/general/messenger/types.d.ts +26 -0
  183. package/dist/esm/general/messenger/types.d.ts.map +1 -0
  184. package/dist/esm/general/messenger/types.js +2 -0
  185. package/dist/esm/general/messenger/types.js.map +1 -0
  186. package/dist/esm/general/namedEntities.d.ts +256 -0
  187. package/dist/esm/general/namedEntities.d.ts.map +1 -0
  188. package/dist/esm/general/namedEntities.js +257 -0
  189. package/dist/esm/general/namedEntities.js.map +1 -0
  190. package/dist/esm/general/numbers.d.ts +43 -0
  191. package/dist/esm/general/numbers.d.ts.map +1 -0
  192. package/dist/esm/general/numbers.js +87 -0
  193. package/dist/esm/general/numbers.js.map +1 -0
  194. package/dist/esm/general/objects.d.ts +45 -0
  195. package/dist/esm/general/objects.d.ts.map +1 -0
  196. package/dist/esm/general/objects.js +91 -0
  197. package/dist/esm/general/objects.js.map +1 -0
  198. package/dist/esm/general/sorting.d.ts +32 -0
  199. package/dist/esm/general/sorting.d.ts.map +1 -0
  200. package/dist/esm/general/sorting.js +67 -0
  201. package/dist/esm/general/sorting.js.map +1 -0
  202. package/dist/esm/general/string.d.ts +31 -0
  203. package/dist/esm/general/string.d.ts.map +1 -0
  204. package/dist/esm/general/string.js +68 -0
  205. package/dist/esm/general/string.js.map +1 -0
  206. package/dist/esm/general/timeout.d.ts +8 -0
  207. package/dist/esm/general/timeout.d.ts.map +1 -0
  208. package/dist/esm/general/timeout.js +14 -0
  209. package/dist/esm/general/timeout.js.map +1 -0
  210. package/dist/esm/index.d.ts +4 -0
  211. package/dist/esm/index.d.ts.map +1 -0
  212. package/dist/esm/index.js +4 -0
  213. package/dist/esm/index.js.map +1 -0
  214. package/dist/esm/node/index.d.ts +25 -0
  215. package/dist/esm/node/index.d.ts.map +1 -0
  216. package/dist/esm/node/index.js +27 -0
  217. package/dist/esm/node/index.js.map +1 -0
  218. package/package.json +62 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Add an event to all elements that match the provided selector.
3
+ *
4
+ * @template T The type of the element to add the event to.
5
+ * @param selector The CSS selector to match.
6
+ * @param eventName The event to listen for. Ex. click
7
+ * @param callback The function to call on the event being triggered.
8
+ */
9
+ export declare function addListenerToSelector<T extends HTMLElement>(selector: string, eventName: string, callback: (e: Event, element: T) => unknown): void;
10
+ /**
11
+ * Executes a function once the DOM is ready.
12
+ *
13
+ * @param callback The function to execute.
14
+ */
15
+ export declare function ready(callback: () => unknown): void;
16
+ /**
17
+ * Removes all the children from the provided element.
18
+ *
19
+ * @param element The element to remove the children of.
20
+ */
21
+ export declare function removeChildren(element: Element): void;
22
+ /**
23
+ * Sets a property on all elements that match the provided selector. Note: these
24
+ * are not CSS properties or necessarily HTML attributes.
25
+ *
26
+ * @template TElement The type of the element to set the property on.
27
+ * @template TProperty The property to set.
28
+ * @param selector The CSS selector to match.
29
+ * @param property The property to set.
30
+ * @param value The value to set the property to.
31
+ */
32
+ export declare function setPropertyOnSelector<TElement extends HTMLElement, TProperty extends keyof TElement & string>(selector: string, property: TProperty, value: string & TElement[TProperty]): void;
33
+ /**
34
+ * Waits for an element to exist before executing a callback.
35
+ *
36
+ * @param containerSelector The selector for the container of the element to
37
+ * watch for.
38
+ * @param waitingForSelector The selector for the element to watch for.
39
+ * @param callback The function to execute once the element exists.
40
+ * @param runOnce If true, the callback will only be executed once.
41
+ * @returns False if the container element does not exist. Undefined otherwise.
42
+ */
43
+ export declare function waitFor(containerSelector: string, waitingForSelector: string, callback: () => unknown, runOnce?: boolean): false | undefined;
44
+ //# sourceMappingURL=dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../../src/browser/dom.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,WAAW,EAC1D,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GACzC,IAAI,CAKN;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,OAAO,GAAG,IAAI,CAQnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAIrD;AACD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,SAAS,WAAW,EAC5B,SAAS,SAAS,MAAM,QAAQ,GAAG,MAAM,EAEzC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,GACjC,IAAI,CAKN;AACD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACtB,iBAAiB,EAAE,MAAM,EACzB,kBAAkB,EAAE,MAAM,EAC1B,QAAQ,EAAE,MAAM,OAAO,EACvB,OAAO,UAAQ,GACb,KAAK,GAAG,SAAS,CAqBnB"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Add an event to all elements that match the provided selector.
3
+ *
4
+ * @template T The type of the element to add the event to.
5
+ * @param selector The CSS selector to match.
6
+ * @param eventName The event to listen for. Ex. click
7
+ * @param callback The function to call on the event being triggered.
8
+ */
9
+ export function addListenerToSelector(selector, eventName, callback) {
10
+ const elements = document.querySelectorAll(selector);
11
+ elements.forEach((element) => {
12
+ element.addEventListener(eventName, (e) => callback(e, element));
13
+ });
14
+ }
15
+ /**
16
+ * Executes a function once the DOM is ready.
17
+ *
18
+ * @param callback The function to execute.
19
+ */
20
+ export function ready(callback) {
21
+ if (document.readyState !== "loading") {
22
+ callback();
23
+ }
24
+ else {
25
+ document.addEventListener("DOMContentLoaded", () => {
26
+ callback();
27
+ });
28
+ }
29
+ }
30
+ /**
31
+ * Removes all the children from the provided element.
32
+ *
33
+ * @param element The element to remove the children of.
34
+ */
35
+ export function removeChildren(element) {
36
+ while (element.firstChild) {
37
+ element.removeChild(element.firstChild);
38
+ }
39
+ }
40
+ /**
41
+ * Sets a property on all elements that match the provided selector. Note: these
42
+ * are not CSS properties or necessarily HTML attributes.
43
+ *
44
+ * @template TElement The type of the element to set the property on.
45
+ * @template TProperty The property to set.
46
+ * @param selector The CSS selector to match.
47
+ * @param property The property to set.
48
+ * @param value The value to set the property to.
49
+ */
50
+ export function setPropertyOnSelector(selector, property, value) {
51
+ const elements = document.querySelectorAll(selector);
52
+ elements.forEach((element) => {
53
+ element.setAttribute(property, value);
54
+ });
55
+ }
56
+ /**
57
+ * Waits for an element to exist before executing a callback.
58
+ *
59
+ * @param containerSelector The selector for the container of the element to
60
+ * watch for.
61
+ * @param waitingForSelector The selector for the element to watch for.
62
+ * @param callback The function to execute once the element exists.
63
+ * @param runOnce If true, the callback will only be executed once.
64
+ * @returns False if the container element does not exist. Undefined otherwise.
65
+ */
66
+ export function waitFor(containerSelector, waitingForSelector, callback, runOnce = false) {
67
+ const observerOptions = {
68
+ childList: true,
69
+ subtree: true,
70
+ };
71
+ const elementToWatch = document.querySelector(containerSelector);
72
+ if (!elementToWatch) {
73
+ return false;
74
+ }
75
+ if (elementToWatch.querySelector(waitingForSelector)) {
76
+ callback();
77
+ }
78
+ const observer = new MutationObserver(() => {
79
+ if (!elementToWatch.querySelector(waitingForSelector))
80
+ return;
81
+ if (runOnce) {
82
+ observer.disconnect();
83
+ }
84
+ callback();
85
+ });
86
+ observer.observe(elementToWatch, observerOptions);
87
+ }
88
+ //# sourceMappingURL=dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../src/browser/dom.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACpC,QAAgB,EAChB,SAAiB,EACjB,QAA2C;IAE3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAI,QAAQ,CAAC,CAAC;IACxD,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,QAAuB;IAC5C,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACvC,QAAQ,EAAE,CAAC;IACZ,CAAC;SAAM,CAAC;QACP,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;YAClD,QAAQ,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC9C,OAAO,OAAO,CAAC,UAAU,EAAE,CAAC;QAC3B,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;AACF,CAAC;AACD;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAIpC,QAAgB,EAChB,QAAmB,EACnB,KAAmC;IAEnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAW,QAAQ,CAAC,CAAC;IAC/D,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACJ,CAAC;AACD;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CACtB,iBAAyB,EACzB,kBAA0B,EAC1B,QAAuB,EACvB,OAAO,GAAG,KAAK;IAEf,MAAM,eAAe,GAAG;QACvB,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;KACb,CAAC;IACF,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACjE,IAAI,CAAC,cAAc,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,cAAc,CAAC,aAAa,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACtD,QAAQ,EAAE,CAAC;IACZ,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE;QAC1C,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,kBAAkB,CAAC;YAAE,OAAO;QAC9D,IAAI,OAAO,EAAE,CAAC;YACb,QAAQ,CAAC,UAAU,EAAE,CAAC;QACvB,CAAC;QACD,QAAQ,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\n * Add an event to all elements that match the provided selector.\n *\n * @template T The type of the element to add the event to.\n * @param selector The CSS selector to match.\n * @param eventName The event to listen for. Ex. click\n * @param callback The function to call on the event being triggered.\n */\nexport function addListenerToSelector<T extends HTMLElement>(\n\tselector: string,\n\teventName: string,\n\tcallback: (e: Event, element: T) => unknown,\n): void {\n\tconst elements = document.querySelectorAll<T>(selector);\n\telements.forEach((element) => {\n\t\telement.addEventListener(eventName, (e) => callback(e, element));\n\t});\n}\n\n/**\n * Executes a function once the DOM is ready.\n *\n * @param callback The function to execute.\n */\nexport function ready(callback: () => unknown): void {\n\tif (document.readyState !== \"loading\") {\n\t\tcallback();\n\t} else {\n\t\tdocument.addEventListener(\"DOMContentLoaded\", () => {\n\t\t\tcallback();\n\t\t});\n\t}\n}\n\n/**\n * Removes all the children from the provided element.\n *\n * @param element The element to remove the children of.\n */\nexport function removeChildren(element: Element): void {\n\twhile (element.firstChild) {\n\t\telement.removeChild(element.firstChild);\n\t}\n}\n/**\n * Sets a property on all elements that match the provided selector. Note: these\n * are not CSS properties or necessarily HTML attributes.\n *\n * @template TElement The type of the element to set the property on.\n * @template TProperty The property to set.\n * @param selector The CSS selector to match.\n * @param property The property to set.\n * @param value The value to set the property to.\n */\nexport function setPropertyOnSelector<\n\tTElement extends HTMLElement,\n\tTProperty extends keyof TElement & string,\n>(\n\tselector: string,\n\tproperty: TProperty,\n\tvalue: string & TElement[TProperty],\n): void {\n\tconst elements = document.querySelectorAll<TElement>(selector);\n\telements.forEach((element) => {\n\t\telement.setAttribute(property, value);\n\t});\n}\n/**\n * Waits for an element to exist before executing a callback.\n *\n * @param containerSelector The selector for the container of the element to\n * watch for.\n * @param waitingForSelector The selector for the element to watch for.\n * @param callback The function to execute once the element exists.\n * @param runOnce If true, the callback will only be executed once.\n * @returns False if the container element does not exist. Undefined otherwise.\n */\nexport function waitFor(\n\tcontainerSelector: string,\n\twaitingForSelector: string,\n\tcallback: () => unknown,\n\trunOnce = false,\n): false | undefined {\n\tconst observerOptions = {\n\t\tchildList: true,\n\t\tsubtree: true,\n\t};\n\tconst elementToWatch = document.querySelector(containerSelector);\n\tif (!elementToWatch) {\n\t\treturn false;\n\t}\n\n\tif (elementToWatch.querySelector(waitingForSelector)) {\n\t\tcallback();\n\t}\n\tconst observer = new MutationObserver(() => {\n\t\tif (!elementToWatch.querySelector(waitingForSelector)) return;\n\t\tif (runOnce) {\n\t\t\tobserver.disconnect();\n\t\t}\n\t\tcallback();\n\t});\n\tobserver.observe(elementToWatch, observerOptions);\n}\n"]}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Downloads a text file with the specified file name and content.
3
+ *
4
+ * @param fileName - The name of the file to be downloaded.
5
+ * @param text - The content of the file.
6
+ * @param raw Bypasses encoding if true.
7
+ */
8
+ export declare function download(fileName: string, text: string, raw?: boolean): void;
9
+ /**
10
+ * Downloads a binary file with the specified file name and content.
11
+ *
12
+ * @param fileName - The name of the file to be downloaded.
13
+ * @param binary - The content of the file.
14
+ */
15
+ export declare function downloadBinary(fileName: string, binary: ArrayBuffer): void;
16
+ //# sourceMappingURL=download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../../src/browser/download.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,UAAQ,GAAG,IAAI,CAc1E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAe1E"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Downloads a text file with the specified file name and content.
3
+ *
4
+ * @param fileName - The name of the file to be downloaded.
5
+ * @param text - The content of the file.
6
+ * @param raw Bypasses encoding if true.
7
+ */
8
+ export function download(fileName, text, raw = false) {
9
+ const element = document.createElement("a");
10
+ element.setAttribute("href", raw ? text : "data:text/plain;charset=utf-8," + encodeURIComponent(text));
11
+ element.setAttribute("download", fileName);
12
+ element.style.display = "none";
13
+ document.body.appendChild(element);
14
+ element.click();
15
+ document.body.removeChild(element);
16
+ }
17
+ /**
18
+ * Downloads a binary file with the specified file name and content.
19
+ *
20
+ * @param fileName - The name of the file to be downloaded.
21
+ * @param binary - The content of the file.
22
+ */
23
+ export function downloadBinary(fileName, binary) {
24
+ const blob = new Blob([binary], {
25
+ type: "application/octet-stream",
26
+ });
27
+ const blobUrl = URL.createObjectURL(blob);
28
+ const link = document.createElement("a");
29
+ link.href = blobUrl;
30
+ link.download = fileName;
31
+ document.body.appendChild(link);
32
+ link.click();
33
+ document.body.removeChild(link);
34
+ URL.revokeObjectURL(blobUrl);
35
+ }
36
+ //# sourceMappingURL=download.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download.js","sourceRoot":"","sources":["../../../src/browser/download.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAY,EAAE,GAAG,GAAG,KAAK;IACnE,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5C,OAAO,CAAC,YAAY,CACnB,MAAM,EACN,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CACxE,CAAC;IACF,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE3C,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,MAAmB;IACnE,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE;QAC/B,IAAI,EAAE,0BAA0B;KAChC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;IACpB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAEzB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;IAEb,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Downloads a text file with the specified file name and content.\n *\n * @param fileName - The name of the file to be downloaded.\n * @param text - The content of the file.\n * @param raw Bypasses encoding if true.\n */\nexport function download(fileName: string, text: string, raw = false): void {\n\tconst element = document.createElement(\"a\");\n\telement.setAttribute(\n\t\t\"href\",\n\t\traw ? text : \"data:text/plain;charset=utf-8,\" + encodeURIComponent(text),\n\t);\n\telement.setAttribute(\"download\", fileName);\n\n\telement.style.display = \"none\";\n\tdocument.body.appendChild(element);\n\n\telement.click();\n\n\tdocument.body.removeChild(element);\n}\n\n/**\n * Downloads a binary file with the specified file name and content.\n *\n * @param fileName - The name of the file to be downloaded.\n * @param binary - The content of the file.\n */\nexport function downloadBinary(fileName: string, binary: ArrayBuffer): void {\n\tconst blob = new Blob([binary], {\n\t\ttype: \"application/octet-stream\",\n\t});\n\tconst blobUrl = URL.createObjectURL(blob);\n\n\tconst link = document.createElement(\"a\");\n\tlink.href = blobUrl;\n\tlink.download = fileName;\n\n\tdocument.body.appendChild(link);\n\tlink.click();\n\n\tdocument.body.removeChild(link);\n\tURL.revokeObjectURL(blobUrl);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./dom.js";
2
+ export * from "./download.js";
3
+ export * from "./queryOrThrow.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./dom.js";
2
+ export * from "./download.js";
3
+ export * from "./queryOrThrow.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/browser/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./dom.js\";\nexport * from \"./download.js\";\nexport * from \"./queryOrThrow.js\";\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Overload for querying with a selector and validating the element type.
3
+ *
4
+ * @template T The specific Element type to return.
5
+ * @param selector The selector to query.
6
+ * @param type The constructor of the element type to validate against (e.g.,
7
+ * HTMLInputElement).
8
+ * @returns The element that was found and validated.
9
+ * @throws {Error} If the element is not found or is not of the specified type.
10
+ */
11
+ export declare function queryOrThrow<T extends Element>(selector: string, type: new () => T): T;
12
+ /**
13
+ * Overload for querying within a parent element and validating the element
14
+ * type.
15
+ *
16
+ * @template T The specific Element type to return.
17
+ * @param parent The parent element to query within.
18
+ * @param selector The selector to query.
19
+ * @param type The constructor of the element type to validate against (e.g.,
20
+ * HTMLInputElement).
21
+ * @returns The element that was found and validated.
22
+ * @throws {Error} If the element is not found or is not of the specified type.
23
+ */
24
+ export declare function queryOrThrow<T extends Element>(parent: Element, selector: string, type: new () => T): T;
25
+ /**
26
+ * Overload for querying with just a selector.
27
+ *
28
+ * @template T The generic Element type to return.
29
+ * @param selector The selector to query.
30
+ * @returns The element that was found.
31
+ * @throws {Error} If the element is not found.
32
+ */
33
+ export declare function queryOrThrow<T extends Element>(selector: string): T;
34
+ /**
35
+ * Overload for querying within a parent element with just a selector.
36
+ *
37
+ * @template T The generic Element type to return.
38
+ * @param parent The parent element to query within.
39
+ * @param selector The selector to query.
40
+ * @returns The element that was found.
41
+ * @throws {Error} If the element is not found.
42
+ */
43
+ export declare function queryOrThrow<T extends Element>(parent: Element, selector: string): T;
44
+ //# sourceMappingURL=queryOrThrow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryOrThrow.d.ts","sourceRoot":"","sources":["../../../src/browser/queryOrThrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAC7C,QAAQ,EAAE,MAAM,EAEhB,IAAI,EAAE,UAAU,CAAC,GACf,CAAC,CAAC;AACL;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAC7C,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,MAAM,EAEhB,IAAI,EAAE,UAAU,CAAC,GACf,CAAC,CAAC;AACL;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC;AACrE;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,EAC7C,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,MAAM,GACd,CAAC,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Implementation of queryOrThrow. Queries an element and optionally validates
3
+ * its type.
4
+ *
5
+ * @template T The type of the element to query.
6
+ * @param arg1 The parent element or the selector string.
7
+ * @param arg2 The selector string or the element type constructor.
8
+ * @param arg3 The element type constructor.
9
+ * @returns The element that was found.
10
+ * @throws {Error} If the element is not found or fails the type validation.
11
+ */
12
+ export function queryOrThrow(arg1, arg2, arg3) {
13
+ let parent;
14
+ let selector;
15
+ let type;
16
+ if (typeof arg1 === "string") {
17
+ parent = document;
18
+ selector = arg1;
19
+ if (typeof arg2 === "function") {
20
+ type = arg2;
21
+ }
22
+ }
23
+ else {
24
+ parent = arg1;
25
+ selector = arg2; // Overloads guarantee arg2 is a string here.
26
+ if (typeof arg3 === "function") {
27
+ type = arg3;
28
+ }
29
+ }
30
+ const el = parent.querySelector(selector);
31
+ if (!el) {
32
+ throw new Error(`Element matching selector "${selector}" not found.`);
33
+ }
34
+ if (type && !(el instanceof type)) {
35
+ throw new Error(`Element matching selector "${selector}" is not an instance of "${type.name}". Found "${el.constructor.name}" instead.`);
36
+ }
37
+ return el;
38
+ }
39
+ //# sourceMappingURL=queryOrThrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryOrThrow.js","sourceRoot":"","sources":["../../../src/browser/queryOrThrow.ts"],"names":[],"mappings":"AAuDA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAC3B,IAAsB,EACtB,IAA6B,EAC7B,IAAkB;IAElB,IAAI,MAA0B,CAAC;IAC/B,IAAI,QAAgB,CAAC;IACrB,IAAI,IAA+B,CAAC;IAEpC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,QAAQ,CAAC;QAClB,QAAQ,GAAG,IAAI,CAAC;QAChB,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YAChC,IAAI,GAAG,IAAI,CAAC;QACb,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,GAAG,IAAI,CAAC;QACd,QAAQ,GAAG,IAAc,CAAC,CAAC,6CAA6C;QACxE,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;YAChC,IAAI,GAAG,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAC;IAE7C,IAAI,CAAC,EAAE,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,QAAQ,cAAc,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,IAAI,IAAI,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACd,8BAA8B,QAAQ,4BAA4B,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC,WAAW,CAAC,IAAI,YAAY,CACvH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC","sourcesContent":["/**\n * Overload for querying with a selector and validating the element type.\n *\n * @template T The specific Element type to return.\n * @param selector The selector to query.\n * @param type The constructor of the element type to validate against (e.g.,\n * HTMLInputElement).\n * @returns The element that was found and validated.\n * @throws {Error} If the element is not found or is not of the specified type.\n */\nexport function queryOrThrow<T extends Element>(\n\tselector: string,\n\t// eslint-disable-next-line @typescript-eslint/unified-signatures\n\ttype: new () => T,\n): T;\n/**\n * Overload for querying within a parent element and validating the element\n * type.\n *\n * @template T The specific Element type to return.\n * @param parent The parent element to query within.\n * @param selector The selector to query.\n * @param type The constructor of the element type to validate against (e.g.,\n * HTMLInputElement).\n * @returns The element that was found and validated.\n * @throws {Error} If the element is not found or is not of the specified type.\n */\nexport function queryOrThrow<T extends Element>(\n\tparent: Element,\n\tselector: string,\n\t// eslint-disable-next-line @typescript-eslint/unified-signatures\n\ttype: new () => T,\n): T;\n/**\n * Overload for querying with just a selector.\n *\n * @template T The generic Element type to return.\n * @param selector The selector to query.\n * @returns The element that was found.\n * @throws {Error} If the element is not found.\n */\nexport function queryOrThrow<T extends Element>(selector: string): T;\n/**\n * Overload for querying within a parent element with just a selector.\n *\n * @template T The generic Element type to return.\n * @param parent The parent element to query within.\n * @param selector The selector to query.\n * @returns The element that was found.\n * @throws {Error} If the element is not found.\n */\nexport function queryOrThrow<T extends Element>(\n\tparent: Element,\n\tselector: string,\n): T;\n/**\n * Implementation of queryOrThrow. Queries an element and optionally validates\n * its type.\n *\n * @template T The type of the element to query.\n * @param arg1 The parent element or the selector string.\n * @param arg2 The selector string or the element type constructor.\n * @param arg3 The element type constructor.\n * @returns The element that was found.\n * @throws {Error} If the element is not found or fails the type validation.\n */\nexport function queryOrThrow<T extends Element>(\n\targ1: Element | string,\n\targ2?: (new () => T) | string,\n\targ3?: new () => T,\n): T {\n\tlet parent: Document | Element;\n\tlet selector: string;\n\tlet type: (new () => T) | undefined;\n\n\tif (typeof arg1 === \"string\") {\n\t\tparent = document;\n\t\tselector = arg1;\n\t\tif (typeof arg2 === \"function\") {\n\t\t\ttype = arg2;\n\t\t}\n\t} else {\n\t\tparent = arg1;\n\t\tselector = arg2 as string; // Overloads guarantee arg2 is a string here.\n\t\tif (typeof arg3 === \"function\") {\n\t\t\ttype = arg3;\n\t\t}\n\t}\n\n\tconst el = parent.querySelector<T>(selector);\n\n\tif (!el) {\n\t\tthrow new Error(`Element matching selector \"${selector}\" not found.`);\n\t}\n\n\tif (type && !(el instanceof type)) {\n\t\tthrow new Error(\n\t\t\t`Element matching selector \"${selector}\" is not an instance of \"${type.name}\". Found \"${el.constructor.name}\" instead.`,\n\t\t);\n\t}\n\n\treturn el;\n}\n"]}
@@ -0,0 +1,70 @@
1
+ export declare enum Direction {
2
+ Left = 0,
3
+ Right = 1
4
+ }
5
+ /**
6
+ * Remove duplicates from an array
7
+ *
8
+ * @template TData The type of the array
9
+ * @param data The array to remove duplicates from
10
+ * @returns The array with duplicates removed
11
+ */
12
+ export declare function dedupe<TData>(data: TData[]): TData[];
13
+ /**
14
+ * Mutates the position field in an array of objects to enforce uniqueness.
15
+ *
16
+ * @template TData The type of the objects in the array.
17
+ * @param array The array of objects.
18
+ * @throws {Error} If an undefined item is found in the array.
19
+ */
20
+ export declare function enforceUniquePositions<TData extends {
21
+ position: number;
22
+ }>(array: TData[]): void;
23
+ /**
24
+ * Get the next index or previous index in array, looping around if necessary.
25
+ *
26
+ * @param currentIndex The current index.
27
+ * @param direction The direction to move in.
28
+ * @param items The array of items.
29
+ * @returns The next index.
30
+ */
31
+ export declare function getLoopedIndex(currentIndex: number, direction: Direction, items: number | unknown[]): number;
32
+ /**
33
+ * Reassigns the position field in an array of objects.
34
+ *
35
+ * @example
36
+ * const array = [
37
+ * { id: 1, position: 0 },
38
+ * { id: 2, position: 1 },
39
+ * { id: 3, position: 2 },
40
+ * ];
41
+ * const newArray = moveItemInArray(array, "id", 2, 1);
42
+ * // newArray is now [{ id: 1, position: 0 }, { id: 3, position: 1 }, { id: 2, position: 2 }];
43
+ *
44
+ * const notIntrinsicallyOrderedArray = [
45
+ * { id: 1, position: 0 },
46
+ * { id: 3, position: 2 },
47
+ * { id: 2, position: 1 },
48
+ * { id: 4, position: 3 },
49
+ * ];
50
+ * const newArray2 = moveItemInArray(
51
+ * notIntrinsicallyOrderedArray,
52
+ * "id",
53
+ * 2,
54
+ * -1,
55
+ * );
56
+ * // newArray2 is now [{ id: 1, position: 0 }, { id: 2, position: 1 }, { id: 3, position: 2 }, { id: 4, position: 3 }];
57
+ *
58
+ * @template T The type of the objects in the array. The objects must have a
59
+ * numeric `position` field.
60
+ * @template K The key field in an array item.
61
+ * @param array The array of objects.
62
+ * @param idField The field to use as the id.
63
+ * @param id The id of the item to move.
64
+ * @param direction The direction to move the item in. 1 for down, -1 for up.
65
+ * @returns An array with the new position values set.
66
+ */
67
+ export declare function moveItemInArray<T extends {
68
+ position: number;
69
+ }, K extends keyof T>(array: T[], idField: K, id: T[K], direction: -1 | 1): T[];
70
+ //# sourceMappingURL=arrays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../../../src/general/arrays.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACpB,IAAI,IAAA;IACJ,KAAK,IAAA;CACL;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EACxE,KAAK,EAAE,KAAK,EAAE,GACZ,IAAI,CAON;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC7B,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,GACvB,MAAM,CAOR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,eAAe,CAC9B,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC9B,CAAC,SAAS,MAAM,CAAC,EAChB,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAa1D"}
@@ -0,0 +1,144 @@
1
+ export var Direction;
2
+ (function (Direction) {
3
+ Direction[Direction["Left"] = 0] = "Left";
4
+ Direction[Direction["Right"] = 1] = "Right";
5
+ })(Direction || (Direction = {}));
6
+ /**
7
+ * Remove duplicates from an array
8
+ *
9
+ * @template TData The type of the array
10
+ * @param data The array to remove duplicates from
11
+ * @returns The array with duplicates removed
12
+ */
13
+ export function dedupe(data) {
14
+ return [...new Set(data)];
15
+ }
16
+ /**
17
+ * Mutates the position field in an array of objects to enforce uniqueness.
18
+ *
19
+ * @template TData The type of the objects in the array.
20
+ * @param array The array of objects.
21
+ * @throws {Error} If an undefined item is found in the array.
22
+ */
23
+ export function enforceUniquePositions(array) {
24
+ const newArray = [...array];
25
+ newArray.sort((a, b) => a.position - b.position);
26
+ for (let i = 0; i < newArray.length; i++) {
27
+ const item = getItemAtIndex(newArray, i);
28
+ item.position = i;
29
+ }
30
+ }
31
+ /**
32
+ * Get the next index or previous index in array, looping around if necessary.
33
+ *
34
+ * @param currentIndex The current index.
35
+ * @param direction The direction to move in.
36
+ * @param items The array of items.
37
+ * @returns The next index.
38
+ */
39
+ export function getLoopedIndex(currentIndex, direction, items) {
40
+ const length = Array.isArray(items) ? items.length : items;
41
+ if (direction === Direction.Left) {
42
+ return currentIndex - 1 < 0 ? length - 1 : currentIndex - 1;
43
+ }
44
+ else {
45
+ return currentIndex + 2 > length ? 0 : currentIndex + 1;
46
+ }
47
+ }
48
+ /**
49
+ * Reassigns the position field in an array of objects.
50
+ *
51
+ * @example
52
+ * const array = [
53
+ * { id: 1, position: 0 },
54
+ * { id: 2, position: 1 },
55
+ * { id: 3, position: 2 },
56
+ * ];
57
+ * const newArray = moveItemInArray(array, "id", 2, 1);
58
+ * // newArray is now [{ id: 1, position: 0 }, { id: 3, position: 1 }, { id: 2, position: 2 }];
59
+ *
60
+ * const notIntrinsicallyOrderedArray = [
61
+ * { id: 1, position: 0 },
62
+ * { id: 3, position: 2 },
63
+ * { id: 2, position: 1 },
64
+ * { id: 4, position: 3 },
65
+ * ];
66
+ * const newArray2 = moveItemInArray(
67
+ * notIntrinsicallyOrderedArray,
68
+ * "id",
69
+ * 2,
70
+ * -1,
71
+ * );
72
+ * // newArray2 is now [{ id: 1, position: 0 }, { id: 2, position: 1 }, { id: 3, position: 2 }, { id: 4, position: 3 }];
73
+ *
74
+ * @template T The type of the objects in the array. The objects must have a
75
+ * numeric `position` field.
76
+ * @template K The key field in an array item.
77
+ * @param array The array of objects.
78
+ * @param idField The field to use as the id.
79
+ * @param id The id of the item to move.
80
+ * @param direction The direction to move the item in. 1 for down, -1 for up.
81
+ * @returns An array with the new position values set.
82
+ */
83
+ export function moveItemInArray(array, idField, id, direction) {
84
+ const newArray = [...array];
85
+ const index = newArray.findIndex((item) => item[idField] === id);
86
+ if (index === -1) {
87
+ return newArray;
88
+ }
89
+ const item = getItemAtIndex(newArray, index);
90
+ const originalPosition = item.position;
91
+ for (let i = 0; i < newArray.length; i++) {
92
+ handleItem(i, index, direction, newArray, originalPosition);
93
+ }
94
+ return newArray;
95
+ }
96
+ /**
97
+ * Gets an item at a specific index in an array, throwing an error if the item
98
+ * is undefined.
99
+ *
100
+ * @template TData The type of the items in the array.
101
+ * @param array The array to get the item from.
102
+ * @param index The index of the item to get.
103
+ * @returns The item at the specified index.
104
+ * @throws {Error} If the item at the specified index is undefined.
105
+ */
106
+ function getItemAtIndex(array, index) {
107
+ // eslint-disable-next-line security/detect-object-injection
108
+ const item = array[index];
109
+ if (item === undefined) {
110
+ throw new Error("Undefined item in array at index " + String(index));
111
+ }
112
+ return item;
113
+ }
114
+ /**
115
+ * Handles the movement of each item within an array.
116
+ *
117
+ * @template T The type of the array item
118
+ * @param currentIndex The index of the item who's movement is being handled.
119
+ * @param indexBeingMoved The index of the item that was moved.
120
+ * @param direction Whether the indexBeingMoved is moving ahead or back.
121
+ * @param newArray The array being built.
122
+ * @param originalPosition The original position of the item being moved.
123
+ */
124
+ function handleItem(currentIndex, indexBeingMoved, direction, newArray, originalPosition) {
125
+ const item = getItemAtIndex(newArray, currentIndex);
126
+ if (currentIndex === indexBeingMoved) {
127
+ if (direction === -1 || currentIndex < newArray.length - 1) {
128
+ item.position += direction;
129
+ }
130
+ }
131
+ else if (direction === 1) {
132
+ if (item.position > originalPosition &&
133
+ item.position <= originalPosition + 1) {
134
+ item.position--;
135
+ }
136
+ }
137
+ else {
138
+ if (item.position < originalPosition &&
139
+ item.position >= originalPosition - 1) {
140
+ item.position++;
141
+ }
142
+ }
143
+ }
144
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.js","sourceRoot":"","sources":["../../../src/general/arrays.ts"],"names":[],"mappings":"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","sourcesContent":["export enum Direction {\n\tLeft,\n\tRight,\n}\n\n/**\n * Remove duplicates from an array\n *\n * @template TData The type of the array\n * @param data The array to remove duplicates from\n * @returns The array with duplicates removed\n */\nexport function dedupe<TData>(data: TData[]): TData[] {\n\treturn [...new Set(data)];\n}\n\n/**\n * Mutates the position field in an array of objects to enforce uniqueness.\n *\n * @template TData The type of the objects in the array.\n * @param array The array of objects.\n * @throws {Error} If an undefined item is found in the array.\n */\nexport function enforceUniquePositions<TData extends { position: number }>(\n\tarray: TData[],\n): void {\n\tconst newArray = [...array];\n\tnewArray.sort((a, b) => a.position - b.position);\n\tfor (let i = 0; i < newArray.length; i++) {\n\t\tconst item = getItemAtIndex(newArray, i);\n\t\titem.position = i;\n\t}\n}\n\n/**\n * Get the next index or previous index in array, looping around if necessary.\n *\n * @param currentIndex The current index.\n * @param direction The direction to move in.\n * @param items The array of items.\n * @returns The next index.\n */\nexport function getLoopedIndex(\n\tcurrentIndex: number,\n\tdirection: Direction,\n\titems: number | unknown[],\n): number {\n\tconst length = Array.isArray(items) ? items.length : items;\n\tif (direction === Direction.Left) {\n\t\treturn currentIndex - 1 < 0 ? length - 1 : currentIndex - 1;\n\t} else {\n\t\treturn currentIndex + 2 > length ? 0 : currentIndex + 1;\n\t}\n}\n\n/**\n * Reassigns the position field in an array of objects.\n *\n * @example\n * \tconst array = [\n * \t\t{ id: 1, position: 0 },\n * \t\t{ id: 2, position: 1 },\n * \t\t{ id: 3, position: 2 },\n * \t];\n * \tconst newArray = moveItemInArray(array, \"id\", 2, 1);\n * \t// newArray is now [{ id: 1, position: 0 }, { id: 3, position: 1 }, { id: 2, position: 2 }];\n *\n * \tconst notIntrinsicallyOrderedArray = [\n * \t\t{ id: 1, position: 0 },\n * \t\t{ id: 3, position: 2 },\n * \t\t{ id: 2, position: 1 },\n * \t\t{ id: 4, position: 3 },\n * \t];\n * \tconst newArray2 = moveItemInArray(\n * \t\tnotIntrinsicallyOrderedArray,\n * \t\t\"id\",\n * \t\t2,\n * \t\t-1,\n * \t);\n * \t// newArray2 is now [{ id: 1, position: 0 }, { id: 2, position: 1 }, { id: 3, position: 2 }, { id: 4, position: 3 }];\n *\n * @template T The type of the objects in the array. The objects must have a\n * numeric `position` field.\n * @template K The key field in an array item.\n * @param array The array of objects.\n * @param idField The field to use as the id.\n * @param id The id of the item to move.\n * @param direction The direction to move the item in. 1 for down, -1 for up.\n * @returns An array with the new position values set.\n */\nexport function moveItemInArray<\n\tT extends { position: number },\n\tK extends keyof T,\n>(array: T[], idField: K, id: T[K], direction: -1 | 1): T[] {\n\tconst newArray = [...array];\n\tconst index = newArray.findIndex((item) => item[idField] === id);\n\tif (index === -1) {\n\t\treturn newArray;\n\t}\n\tconst item = getItemAtIndex(newArray, index);\n\tconst originalPosition = item.position;\n\tfor (let i = 0; i < newArray.length; i++) {\n\t\thandleItem<T>(i, index, direction, newArray, originalPosition);\n\t}\n\n\treturn newArray;\n}\n\n/**\n * Gets an item at a specific index in an array, throwing an error if the item\n * is undefined.\n *\n * @template TData The type of the items in the array.\n * @param array The array to get the item from.\n * @param index The index of the item to get.\n * @returns The item at the specified index.\n * @throws {Error} If the item at the specified index is undefined.\n */\nfunction getItemAtIndex<TData>(array: TData[], index: number) {\n\t// eslint-disable-next-line security/detect-object-injection\n\tconst item = array[index];\n\tif (item === undefined) {\n\t\tthrow new Error(\"Undefined item in array at index \" + String(index));\n\t}\n\treturn item;\n}\n\n/**\n * Handles the movement of each item within an array.\n *\n * @template T The type of the array item\n * @param currentIndex The index of the item who's movement is being handled.\n * @param indexBeingMoved The index of the item that was moved.\n * @param direction Whether the indexBeingMoved is moving ahead or back.\n * @param newArray The array being built.\n * @param originalPosition The original position of the item being moved.\n */\nfunction handleItem<T extends { position: number }>(\n\tcurrentIndex: number,\n\tindexBeingMoved: number,\n\tdirection: number,\n\tnewArray: T[],\n\toriginalPosition: number,\n) {\n\tconst item = getItemAtIndex(newArray, currentIndex);\n\tif (currentIndex === indexBeingMoved) {\n\t\tif (direction === -1 || currentIndex < newArray.length - 1) {\n\t\t\titem.position += direction;\n\t\t}\n\t} else if (direction === 1) {\n\t\tif (\n\t\t\titem.position > originalPosition &&\n\t\t\titem.position <= originalPosition + 1\n\t\t) {\n\t\t\titem.position--;\n\t\t}\n\t} else {\n\t\tif (\n\t\t\titem.position < originalPosition &&\n\t\t\titem.position >= originalPosition - 1\n\t\t) {\n\t\t\titem.position++;\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Replace a boolean value with a more user-friendly string. Does nothing if the
3
+ * existing value was a string
4
+ *
5
+ * @param rawValue The value to convert.
6
+ * @returns A user-friendly string representation of the value that was passed
7
+ * in.
8
+ */
9
+ export declare function getPrettyValue(rawValue: boolean | string): string;
10
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../src/general/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAIjE"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Replace a boolean value with a more user-friendly string. Does nothing if the
3
+ * existing value was a string
4
+ *
5
+ * @param rawValue The value to convert.
6
+ * @returns A user-friendly string representation of the value that was passed
7
+ * in.
8
+ */
9
+ export function getPrettyValue(rawValue) {
10
+ if (rawValue === true)
11
+ return "Yes";
12
+ if (rawValue === false)
13
+ return "No";
14
+ return rawValue;
15
+ }
16
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../src/general/boolean.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,QAA0B;IACxD,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Replace a boolean value with a more user-friendly string. Does nothing if the\n * existing value was a string\n *\n * @param rawValue The value to convert.\n * @returns A user-friendly string representation of the value that was passed\n * in.\n */\nexport function getPrettyValue(rawValue: boolean | string): string {\n\tif (rawValue === true) return \"Yes\";\n\tif (rawValue === false) return \"No\";\n\treturn rawValue;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Gets the rotations for the clock hands, with 0deg being 12 o'clock.
3
+ *
4
+ * @param date The date to get the rotations for.
5
+ * @returns The rotations for the clock hands.
6
+ */
7
+ export declare function getClockRotations(date: Date): {
8
+ hours: number;
9
+ minutes: number;
10
+ seconds: number;
11
+ };
12
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../../src/general/clock.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CAChB,CAYA"}
@@ -0,0 +1,19 @@
1
+ import { toPrecision } from "./numbers.js";
2
+ /**
3
+ * Gets the rotations for the clock hands, with 0deg being 12 o'clock.
4
+ *
5
+ * @param date The date to get the rotations for.
6
+ * @returns The rotations for the clock hands.
7
+ */
8
+ export function getClockRotations(date) {
9
+ const secondsPercentage = date.getSeconds() / 60;
10
+ const minutesInSeconds = date.getMinutes() * 60;
11
+ const minutesPercentage = (minutesInSeconds + date.getSeconds()) / (60 * 60);
12
+ const hoursInSeconds = (date.getHours() % 12) * 60 * 60;
13
+ const hoursPercentage = (hoursInSeconds + minutesInSeconds + date.getSeconds()) / (12 * 60 * 60);
14
+ const hours = toPrecision(hoursPercentage * 360, 2);
15
+ const minutes = toPrecision(minutesPercentage * 360, 2);
16
+ const seconds = toPrecision(secondsPercentage * 360, 2);
17
+ return { hours, minutes, seconds };
18
+ }
19
+ //# sourceMappingURL=clock.js.map