@gglib/utils 0.6.2 → 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 (238) hide show
  1. package/LICENSE +7 -0
  2. package/Readme.md +1 -1
  3. package/dist/bundles/utils.esm.js +1904 -0
  4. package/dist/bundles/utils.esm.js.map +1 -0
  5. package/dist/stats.html +211 -170
  6. package/dist/utils/src/collections/IdMap.d.ts +13 -0
  7. package/dist/utils/src/collections/IdMap.d.ts.map +1 -0
  8. package/dist/utils/src/collections/IdMap.js +63 -0
  9. package/dist/utils/src/collections/IdMap.js.map +1 -0
  10. package/dist/utils/src/collections/IdSet.d.ts +11 -0
  11. package/dist/utils/src/collections/IdSet.d.ts.map +1 -0
  12. package/dist/utils/src/collections/IdSet.js +47 -0
  13. package/dist/utils/src/collections/IdSet.js.map +1 -0
  14. package/dist/utils/src/collections/PooledList.d.ts +15 -0
  15. package/dist/utils/src/collections/PooledList.d.ts.map +1 -0
  16. package/dist/utils/src/collections/PooledList.js +44 -0
  17. package/dist/utils/src/collections/PooledList.js.map +1 -0
  18. package/dist/utils/src/collections/PriorityQueue.d.ts +27 -0
  19. package/dist/utils/src/collections/PriorityQueue.d.ts.map +1 -0
  20. package/dist/utils/src/collections/PriorityQueue.js +142 -0
  21. package/dist/utils/src/collections/PriorityQueue.js.map +1 -0
  22. package/dist/utils/src/collections/array.d.ts +27 -0
  23. package/dist/utils/src/collections/array.d.ts.map +1 -0
  24. package/dist/utils/src/collections/array.js +55 -0
  25. package/dist/utils/src/collections/array.js.map +1 -0
  26. package/dist/utils/src/collections/index.d.ts +6 -0
  27. package/dist/utils/src/collections/index.d.ts.map +1 -0
  28. package/dist/utils/src/collections/index.js +6 -0
  29. package/dist/utils/src/collections/index.js.map +1 -0
  30. package/dist/utils/src/events/bus.d.ts +15 -0
  31. package/dist/utils/src/events/bus.d.ts.map +1 -0
  32. package/dist/utils/src/events/bus.js +47 -0
  33. package/dist/utils/src/events/bus.js.map +1 -0
  34. package/dist/utils/src/events/channel.d.ts +23 -0
  35. package/dist/utils/src/events/channel.d.ts.map +1 -0
  36. package/dist/utils/src/events/channel.js +95 -0
  37. package/dist/utils/src/events/channel.js.map +1 -0
  38. package/dist/utils/src/events/emitter.d.ts +14 -0
  39. package/dist/utils/src/events/emitter.d.ts.map +1 -0
  40. package/dist/utils/src/events/emitter.js +37 -0
  41. package/dist/utils/src/events/emitter.js.map +1 -0
  42. package/dist/utils/src/events/index.d.ts +6 -0
  43. package/dist/utils/src/events/index.d.ts.map +1 -0
  44. package/dist/utils/src/events/index.js +6 -0
  45. package/dist/utils/src/events/index.js.map +1 -0
  46. package/dist/utils/src/events/source.d.ts +20 -0
  47. package/dist/utils/src/events/source.d.ts.map +1 -0
  48. package/dist/utils/src/events/source.js +69 -0
  49. package/dist/utils/src/events/source.js.map +1 -0
  50. package/dist/utils/src/events/types.d.ts +3 -0
  51. package/dist/utils/src/events/types.d.ts.map +1 -0
  52. package/dist/utils/src/events/types.js +2 -0
  53. package/dist/utils/src/events/types.js.map +1 -0
  54. package/dist/utils/src/index.d.ts +5 -9
  55. package/dist/utils/src/index.d.ts.map +1 -1
  56. package/dist/utils/src/index.js +5 -9
  57. package/dist/utils/src/index.js.map +1 -1
  58. package/dist/utils/src/{BinaryReader.d.ts → reader/BinaryReader.d.ts} +19 -1
  59. package/dist/utils/src/reader/BinaryReader.d.ts.map +1 -0
  60. package/dist/utils/src/{BinaryReader.js → reader/BinaryReader.js} +80 -61
  61. package/dist/utils/src/reader/BinaryReader.js.map +1 -0
  62. package/dist/utils/src/reader/TextReader.d.ts +245 -0
  63. package/dist/utils/src/reader/TextReader.d.ts.map +1 -0
  64. package/dist/utils/src/reader/TextReader.js +465 -0
  65. package/dist/utils/src/reader/TextReader.js.map +1 -0
  66. package/dist/utils/src/reader/index.d.ts +3 -0
  67. package/dist/utils/src/reader/index.d.ts.map +1 -0
  68. package/dist/utils/src/reader/index.js +3 -0
  69. package/dist/utils/src/reader/index.js.map +1 -0
  70. package/dist/utils/src/types/brand.d.ts +26 -0
  71. package/dist/utils/src/types/brand.d.ts.map +1 -0
  72. package/dist/utils/src/types/brand.js +4 -0
  73. package/dist/utils/src/types/brand.js.map +1 -0
  74. package/dist/utils/src/types/index.d.ts +4 -0
  75. package/dist/utils/src/types/index.d.ts.map +1 -0
  76. package/dist/utils/src/types/index.js +4 -0
  77. package/dist/utils/src/types/index.js.map +1 -0
  78. package/dist/utils/src/types/json-rpc.d.ts +72 -0
  79. package/dist/utils/src/types/json-rpc.d.ts.map +1 -0
  80. package/dist/utils/src/types/json-rpc.js +99 -0
  81. package/dist/utils/src/types/json-rpc.js.map +1 -0
  82. package/dist/utils/src/types/rxjs.d.ts +17 -0
  83. package/dist/utils/src/types/rxjs.d.ts.map +1 -0
  84. package/dist/utils/src/types/rxjs.js +10 -0
  85. package/dist/utils/src/types/rxjs.js.map +1 -0
  86. package/dist/utils/src/uri/index.d.ts +4 -0
  87. package/dist/utils/src/uri/index.d.ts.map +1 -0
  88. package/dist/utils/src/uri/index.js +4 -0
  89. package/dist/utils/src/uri/index.js.map +1 -0
  90. package/dist/utils/src/uri/merge.d.ts +2 -0
  91. package/dist/utils/src/uri/merge.d.ts.map +1 -0
  92. package/dist/utils/src/uri/merge.js +56 -0
  93. package/dist/utils/src/uri/merge.js.map +1 -0
  94. package/dist/utils/src/uri/parse.d.ts +129 -0
  95. package/dist/utils/src/uri/parse.d.ts.map +1 -0
  96. package/dist/utils/src/uri/parse.js +83 -0
  97. package/dist/utils/src/uri/parse.js.map +1 -0
  98. package/dist/utils/src/uri/path.d.ts +22 -0
  99. package/dist/utils/src/uri/path.d.ts.map +1 -0
  100. package/dist/utils/src/uri/path.js +34 -0
  101. package/dist/utils/src/uri/path.js.map +1 -0
  102. package/dist/utils/src/utils/dom.d.ts +7 -2
  103. package/dist/utils/src/utils/dom.d.ts.map +1 -1
  104. package/dist/utils/src/utils/dom.js +59 -63
  105. package/dist/utils/src/utils/dom.js.map +1 -1
  106. package/dist/utils/src/utils/index.d.ts +3 -8
  107. package/dist/utils/src/utils/index.d.ts.map +1 -1
  108. package/dist/utils/src/utils/index.js +3 -8
  109. package/dist/utils/src/utils/index.js.map +1 -1
  110. package/dist/utils/src/utils/logfmt.d.ts +53 -0
  111. package/dist/utils/src/utils/logfmt.d.ts.map +1 -0
  112. package/dist/utils/src/utils/logfmt.js +66 -0
  113. package/dist/utils/src/utils/logfmt.js.map +1 -0
  114. package/dist/utils/src/utils/loop.d.ts +12 -28
  115. package/dist/utils/src/utils/loop.d.ts.map +1 -1
  116. package/dist/utils/src/utils/loop.js +23 -54
  117. package/dist/utils/src/utils/loop.js.map +1 -1
  118. package/dist/utils/src/utils/metric.d.ts +23 -0
  119. package/dist/utils/src/utils/metric.d.ts.map +1 -0
  120. package/dist/utils/src/utils/metric.js +47 -0
  121. package/dist/utils/src/utils/metric.js.map +1 -0
  122. package/dist/utils/src/utils/uuid.js +3 -3
  123. package/dist/utils/src/utils/uuid.js.map +1 -1
  124. package/dist/utils/src/utils/worker.d.ts +18 -0
  125. package/dist/utils/src/utils/worker.d.ts.map +1 -0
  126. package/dist/utils/src/utils/worker.js +23 -0
  127. package/dist/utils/src/utils/worker.js.map +1 -0
  128. package/dist/utils/tsconfig.build.tsbuildinfo +1 -0
  129. package/package.json +11 -4
  130. package/dist/bundles/utils.umd.js +0 -1663
  131. package/dist/bundles/utils.umd.js.map +0 -1
  132. package/dist/utils/src/BinaryReader.d.ts.map +0 -1
  133. package/dist/utils/src/BinaryReader.js.map +0 -1
  134. package/dist/utils/src/BinaryReader.spec.d.ts +0 -2
  135. package/dist/utils/src/BinaryReader.spec.d.ts.map +0 -1
  136. package/dist/utils/src/BinaryReader.spec.js +0 -38
  137. package/dist/utils/src/BinaryReader.spec.js.map +0 -1
  138. package/dist/utils/src/DataUri.d.ts +0 -36
  139. package/dist/utils/src/DataUri.d.ts.map +0 -1
  140. package/dist/utils/src/DataUri.js +0 -45
  141. package/dist/utils/src/DataUri.js.map +0 -1
  142. package/dist/utils/src/DataUri.spec.d.ts +0 -2
  143. package/dist/utils/src/DataUri.spec.d.ts.map +0 -1
  144. package/dist/utils/src/DataUri.spec.js +0 -34
  145. package/dist/utils/src/DataUri.spec.js.map +0 -1
  146. package/dist/utils/src/Events.d.ts +0 -59
  147. package/dist/utils/src/Events.d.ts.map +0 -1
  148. package/dist/utils/src/Events.js +0 -125
  149. package/dist/utils/src/Events.js.map +0 -1
  150. package/dist/utils/src/Events.spec.d.ts +0 -2
  151. package/dist/utils/src/Events.spec.d.ts.map +0 -1
  152. package/dist/utils/src/Events.spec.js +0 -61
  153. package/dist/utils/src/Events.spec.js.map +0 -1
  154. package/dist/utils/src/Http.d.ts +0 -56
  155. package/dist/utils/src/Http.d.ts.map +0 -1
  156. package/dist/utils/src/Http.js +0 -60
  157. package/dist/utils/src/Http.js.map +0 -1
  158. package/dist/utils/src/Http.spec.d.ts +0 -2
  159. package/dist/utils/src/Http.spec.d.ts.map +0 -1
  160. package/dist/utils/src/Http.spec.js +0 -23
  161. package/dist/utils/src/Http.spec.js.map +0 -1
  162. package/dist/utils/src/Immutable.d.ts +0 -10
  163. package/dist/utils/src/Immutable.d.ts.map +0 -1
  164. package/dist/utils/src/Immutable.js +0 -2
  165. package/dist/utils/src/Immutable.js.map +0 -1
  166. package/dist/utils/src/JsonRpc.d.ts +0 -35
  167. package/dist/utils/src/JsonRpc.d.ts.map +0 -1
  168. package/dist/utils/src/JsonRpc.js +0 -2
  169. package/dist/utils/src/JsonRpc.js.map +0 -1
  170. package/dist/utils/src/Log.d.ts +0 -26
  171. package/dist/utils/src/Log.d.ts.map +0 -1
  172. package/dist/utils/src/Log.js +0 -77
  173. package/dist/utils/src/Log.js.map +0 -1
  174. package/dist/utils/src/TextReader.d.ts +0 -100
  175. package/dist/utils/src/TextReader.d.ts.map +0 -1
  176. package/dist/utils/src/TextReader.js +0 -217
  177. package/dist/utils/src/TextReader.js.map +0 -1
  178. package/dist/utils/src/TextReader.spec.d.ts +0 -2
  179. package/dist/utils/src/TextReader.spec.d.ts.map +0 -1
  180. package/dist/utils/src/TextReader.spec.js +0 -42
  181. package/dist/utils/src/TextReader.spec.js.map +0 -1
  182. package/dist/utils/src/Uri.d.ts +0 -29
  183. package/dist/utils/src/Uri.d.ts.map +0 -1
  184. package/dist/utils/src/Uri.js +0 -129
  185. package/dist/utils/src/Uri.js.map +0 -1
  186. package/dist/utils/src/Uri.spec.d.ts +0 -2
  187. package/dist/utils/src/Uri.spec.d.ts.map +0 -1
  188. package/dist/utils/src/Uri.spec.js +0 -43
  189. package/dist/utils/src/Uri.spec.js.map +0 -1
  190. package/dist/utils/src/WebWorker.d.ts +0 -105
  191. package/dist/utils/src/WebWorker.d.ts.map +0 -1
  192. package/dist/utils/src/WebWorker.js +0 -216
  193. package/dist/utils/src/WebWorker.js.map +0 -1
  194. package/dist/utils/src/WebWorker.spec.d.ts +0 -2
  195. package/dist/utils/src/WebWorker.spec.d.ts.map +0 -1
  196. package/dist/utils/src/WebWorker.spec.js +0 -30
  197. package/dist/utils/src/WebWorker.spec.js.map +0 -1
  198. package/dist/utils/src/utils/array.d.ts +0 -39
  199. package/dist/utils/src/utils/array.d.ts.map +0 -1
  200. package/dist/utils/src/utils/array.js +0 -63
  201. package/dist/utils/src/utils/array.js.map +0 -1
  202. package/dist/utils/src/utils/get-canvas.d.ts +0 -7
  203. package/dist/utils/src/utils/get-canvas.d.ts.map +0 -1
  204. package/dist/utils/src/utils/get-canvas.js +0 -22
  205. package/dist/utils/src/utils/get-canvas.js.map +0 -1
  206. package/dist/utils/src/utils/get-option.d.ts +0 -11
  207. package/dist/utils/src/utils/get-option.d.ts.map +0 -1
  208. package/dist/utils/src/utils/get-option.js +0 -16
  209. package/dist/utils/src/utils/get-option.js.map +0 -1
  210. package/dist/utils/src/utils/getImageData.d.ts +0 -7
  211. package/dist/utils/src/utils/getImageData.d.ts.map +0 -1
  212. package/dist/utils/src/utils/getImageData.js +0 -25
  213. package/dist/utils/src/utils/getImageData.js.map +0 -1
  214. package/dist/utils/src/utils/getImageData.spec.d.ts +0 -2
  215. package/dist/utils/src/utils/getImageData.spec.d.ts.map +0 -1
  216. package/dist/utils/src/utils/getImageData.spec.js +0 -22
  217. package/dist/utils/src/utils/getImageData.spec.js.map +0 -1
  218. package/dist/utils/src/utils/hasOwnProperty.d.ts +0 -5
  219. package/dist/utils/src/utils/hasOwnProperty.d.ts.map +0 -1
  220. package/dist/utils/src/utils/hasOwnProperty.js +0 -7
  221. package/dist/utils/src/utils/hasOwnProperty.js.map +0 -1
  222. package/dist/utils/src/utils/loop.spec.d.ts +0 -2
  223. package/dist/utils/src/utils/loop.spec.d.ts.map +0 -1
  224. package/dist/utils/src/utils/loop.spec.js +0 -17
  225. package/dist/utils/src/utils/loop.spec.js.map +0 -1
  226. package/dist/utils/src/utils/object.d.ts +0 -23
  227. package/dist/utils/src/utils/object.d.ts.map +0 -1
  228. package/dist/utils/src/utils/object.js +0 -90
  229. package/dist/utils/src/utils/object.js.map +0 -1
  230. package/dist/utils/src/utils/string.d.ts +0 -19
  231. package/dist/utils/src/utils/string.d.ts.map +0 -1
  232. package/dist/utils/src/utils/string.js +0 -25
  233. package/dist/utils/src/utils/string.js.map +0 -1
  234. package/dist/utils/src/utils/type.d.ts +0 -58
  235. package/dist/utils/src/utils/type.d.ts.map +0 -1
  236. package/dist/utils/src/utils/type.js +0 -17
  237. package/dist/utils/src/utils/type.js.map +0 -1
  238. package/dist/utils/tsconfig.tsbuildinfo +0 -510
@@ -0,0 +1,1904 @@
1
+ function idMap() {
2
+ const keys = [];
3
+ const values = [];
4
+ const mapToIndex = new Map();
5
+ let size = 0;
6
+ return {
7
+ get size() {
8
+ return size;
9
+ },
10
+ get keys() {
11
+ return keys;
12
+ },
13
+ get values() {
14
+ return values;
15
+ },
16
+ set(id, value) {
17
+ if (!mapToIndex.has(id)) {
18
+ mapToIndex.set(id, size);
19
+ keys[size] = id;
20
+ values[size] = value;
21
+ size++;
22
+ }
23
+ else {
24
+ values[mapToIndex.get(id)] = value;
25
+ }
26
+ return this;
27
+ },
28
+ get(id) {
29
+ return values[mapToIndex.get(id)];
30
+ },
31
+ clear() {
32
+ size = 0;
33
+ keys.length = 0;
34
+ values.length = 0;
35
+ mapToIndex.clear();
36
+ },
37
+ has(id) {
38
+ return mapToIndex.has(id);
39
+ },
40
+ indexOf(id) {
41
+ var _a;
42
+ return (_a = mapToIndex.get(id)) !== null && _a !== void 0 ? _a : -1;
43
+ },
44
+ delete(id) {
45
+ const index = mapToIndex.get(id);
46
+ if (index == null || index >= size) {
47
+ return false;
48
+ }
49
+ const lastIndex = --size;
50
+ const lastKey = keys[lastIndex];
51
+ if (index !== lastIndex) {
52
+ keys[index] = lastKey;
53
+ values[index] = values[lastIndex];
54
+ mapToIndex.set(lastKey, index);
55
+ }
56
+ keys.length = size;
57
+ values.length = size;
58
+ mapToIndex.delete(id);
59
+ return true;
60
+ },
61
+ };
62
+ }
63
+
64
+ function idSet() {
65
+ const values = [];
66
+ const mapToIndex = new Map();
67
+ let size = 0;
68
+ return {
69
+ [Symbol.iterator]: () => values[Symbol.iterator](),
70
+ get size() {
71
+ return size;
72
+ },
73
+ get values() {
74
+ return values;
75
+ },
76
+ add(id) {
77
+ if (!mapToIndex.has(id)) {
78
+ mapToIndex.set(id, size);
79
+ values[size++] = id;
80
+ }
81
+ },
82
+ clear() {
83
+ size = 0;
84
+ values.length = 0;
85
+ mapToIndex.clear();
86
+ },
87
+ has(id) {
88
+ return mapToIndex.has(id);
89
+ },
90
+ indexOf(id) {
91
+ var _a;
92
+ return (_a = mapToIndex.get(id)) !== null && _a !== void 0 ? _a : -1;
93
+ },
94
+ delete(id) {
95
+ const index = mapToIndex.get(id);
96
+ if (index == null || index >= size) {
97
+ return;
98
+ }
99
+ const lastIndex = --size;
100
+ const last = values[lastIndex];
101
+ if (index !== lastIndex) {
102
+ values[index] = last;
103
+ mapToIndex.set(last, index);
104
+ }
105
+ values.length = size;
106
+ mapToIndex.delete(id);
107
+ },
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Removes the first occurrence of an item from the array while preserving order.
113
+ * Mutates the input array.
114
+ *
115
+ * @returns true if an item was found and removed, otherwise false
116
+ */
117
+ function removeItem(list, item) {
118
+ const index = list.indexOf(item);
119
+ if (index >= 0) {
120
+ list.splice(index, 1);
121
+ return true;
122
+ }
123
+ return false;
124
+ }
125
+ /**
126
+ * Removes an item from the array without preserving order (swap-with-last removal).
127
+ * This is a constant-time removal but mutates element order.
128
+ * Mutates the input array.
129
+ *
130
+ * @returns true if an item was found and removed, otherwise false
131
+ */
132
+ function removeItemUnordered(list, item) {
133
+ const index = list.indexOf(item);
134
+ if (index < 0) {
135
+ return false;
136
+ }
137
+ if (index !== list.length - 1) {
138
+ list[index] = list[list.length - 1];
139
+ }
140
+ list.length--;
141
+ return true;
142
+ }
143
+ /**
144
+ * Adds an item to the array only if it is not already present.
145
+ * Performs a linear search using indexOf before insertion.
146
+ * Mutates the array.
147
+ */
148
+ function addItemIfAbsent(list, item) {
149
+ const index = list.indexOf(item);
150
+ if (index === -1) {
151
+ list.push(item);
152
+ return true;
153
+ }
154
+ return false;
155
+ }
156
+ /**
157
+ * Appends an item to the array. If the array is null or undefined,
158
+ * a new array is created and returned.
159
+ */
160
+ function append(list, item) {
161
+ list = list || [];
162
+ list.push(item);
163
+ return list;
164
+ }
165
+
166
+ class PooledList {
167
+ constructor(factory) {
168
+ this.pools = [];
169
+ this.count = 0;
170
+ this.factory = factory;
171
+ }
172
+ push(item) {
173
+ this.pools[this.count++] = item;
174
+ }
175
+ clear() {
176
+ this.count = 0;
177
+ }
178
+ reset() {
179
+ this.count = 0;
180
+ }
181
+ get size() {
182
+ return this.count;
183
+ }
184
+ item(index) {
185
+ if (index < 0 || index >= this.count) {
186
+ return null;
187
+ }
188
+ return this.pools[index];
189
+ }
190
+ next() {
191
+ if (!this.factory) {
192
+ throw new Error('No factory function provided for PooledList');
193
+ }
194
+ const item = this.nextAvailable() || this.factory();
195
+ this.push(item);
196
+ return item;
197
+ }
198
+ nextAvailable() {
199
+ return this.item(this.count);
200
+ }
201
+ toArray(target = []) {
202
+ target.length = this.count;
203
+ for (let i = 0; i < this.count; i++) {
204
+ target[i] = this.pools[i];
205
+ }
206
+ return target;
207
+ }
208
+ }
209
+
210
+ class PriorityQueue {
211
+ constructor() {
212
+ this.heap = [];
213
+ this.indexMap = new Map();
214
+ this.orderCounter = 0;
215
+ }
216
+ get entries() {
217
+ return this.heap;
218
+ }
219
+ size() {
220
+ return this.heap.length;
221
+ }
222
+ has(id) {
223
+ return this.indexMap.has(id);
224
+ }
225
+ peek() {
226
+ var _a;
227
+ return (_a = this.heap[0]) === null || _a === void 0 ? void 0 : _a.value;
228
+ }
229
+ peekNode() {
230
+ return this.heap[0];
231
+ }
232
+ push(id, priority, value) {
233
+ if (this.indexMap.has(id)) {
234
+ throw new Error(`Duplicate id: ${id}`);
235
+ }
236
+ const node = {
237
+ id,
238
+ priority,
239
+ order: this.orderCounter++,
240
+ value,
241
+ };
242
+ this.heap.push(node);
243
+ const index = this.heap.length - 1;
244
+ this.indexMap.set(id, index);
245
+ this.bubbleUp(index);
246
+ }
247
+ pop() {
248
+ if (this.heap.length === 0) {
249
+ return undefined;
250
+ }
251
+ const root = this.heap[0];
252
+ const last = this.heap.pop();
253
+ this.indexMap.delete(root.id);
254
+ if (this.heap.length > 0) {
255
+ this.heap[0] = last;
256
+ this.indexMap.set(last.id, 0);
257
+ this.bubbleDown(0);
258
+ }
259
+ return root.value;
260
+ }
261
+ remove(id) {
262
+ const index = this.indexMap.get(id);
263
+ if (index == null) {
264
+ return false;
265
+ }
266
+ const last = this.heap.pop();
267
+ this.indexMap.delete(id);
268
+ if (index < this.heap.length) {
269
+ this.heap[index] = last;
270
+ this.indexMap.set(last.id, index);
271
+ // rebalance both directions
272
+ if (!this.bubbleUp(index)) {
273
+ this.bubbleDown(index);
274
+ }
275
+ }
276
+ return true;
277
+ }
278
+ updatePriority(id, newPriority) {
279
+ const index = this.indexMap.get(id);
280
+ if (index == null) {
281
+ return;
282
+ }
283
+ const node = this.heap[index];
284
+ const oldPriority = node.priority;
285
+ node.priority = newPriority;
286
+ if (newPriority < oldPriority) {
287
+ this.bubbleUp(index);
288
+ }
289
+ else if (newPriority > oldPriority) {
290
+ this.bubbleDown(index);
291
+ }
292
+ }
293
+ get(id) {
294
+ const index = this.indexMap.get(id);
295
+ return index !== undefined ? this.heap[index].value : undefined;
296
+ }
297
+ clear() {
298
+ this.heap = [];
299
+ this.indexMap.clear();
300
+ }
301
+ compare(a, b) {
302
+ if (a.priority !== b.priority) {
303
+ return a.priority - b.priority;
304
+ }
305
+ return a.order - b.order; // stability
306
+ }
307
+ swap(i, j) {
308
+ const tmp = this.heap[i];
309
+ this.heap[i] = this.heap[j];
310
+ this.heap[j] = tmp;
311
+ this.indexMap.set(this.heap[i].id, i);
312
+ this.indexMap.set(this.heap[j].id, j);
313
+ }
314
+ bubbleUp(index) {
315
+ let moved = false;
316
+ while (index > 0) {
317
+ const parent = (index - 1) >> 1;
318
+ if (this.compare(this.heap[index], this.heap[parent]) < 0) {
319
+ this.swap(index, parent);
320
+ index = parent;
321
+ moved = true;
322
+ }
323
+ else {
324
+ break;
325
+ }
326
+ }
327
+ return moved;
328
+ }
329
+ bubbleDown(index) {
330
+ const length = this.heap.length;
331
+ while (true) {
332
+ let smallest = index;
333
+ const left = index * 2 + 1;
334
+ const right = index * 2 + 2;
335
+ if (left < length && this.compare(this.heap[left], this.heap[smallest]) < 0) {
336
+ smallest = left;
337
+ }
338
+ if (right < length && this.compare(this.heap[right], this.heap[smallest]) < 0) {
339
+ smallest = right;
340
+ }
341
+ if (smallest !== index) {
342
+ this.swap(index, smallest);
343
+ index = smallest;
344
+ }
345
+ else {
346
+ break;
347
+ }
348
+ }
349
+ }
350
+ }
351
+
352
+ function brand(value) {
353
+ return value;
354
+ }
355
+
356
+ /******************************************************************************
357
+ Copyright (c) Microsoft Corporation.
358
+
359
+ Permission to use, copy, modify, and/or distribute this software for any
360
+ purpose with or without fee is hereby granted.
361
+
362
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
363
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
364
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
365
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
366
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
367
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
368
+ PERFORMANCE OF THIS SOFTWARE.
369
+ ***************************************************************************** */
370
+
371
+ function __rest(s, e) {
372
+ var t = {};
373
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
374
+ t[p] = s[p];
375
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
376
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
377
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
378
+ t[p[i]] = s[p[i]];
379
+ }
380
+ return t;
381
+ }
382
+
383
+ function __awaiter(thisArg, _arguments, P, generator) {
384
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
385
+ return new (P || (P = Promise))(function (resolve, reject) {
386
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
387
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
388
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
389
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
390
+ });
391
+ }
392
+
393
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
394
+ var e = new Error(message);
395
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
396
+ };
397
+
398
+ class JsonRpcClient {
399
+ nextId() {
400
+ return `rpc:${this.idCounter++}`;
401
+ }
402
+ constructor(delegate) {
403
+ this.pending = new Map();
404
+ this.idCounter = 0;
405
+ this.delegate = delegate;
406
+ }
407
+ sendRequest(rpc, transfer, timeoutMs = 0) {
408
+ return new Promise((resolve, reject) => {
409
+ if (rpc.id == null) {
410
+ console.warn('RPC request is missing an id. Assigning a generated id to the request.', rpc);
411
+ rpc.id = this.nextId();
412
+ }
413
+ const id = rpc.id;
414
+ let timer;
415
+ if (timeoutMs > 0) {
416
+ timer = setTimeout(() => {
417
+ this.pending.delete(id);
418
+ reject(new Error(`RPC request timed out after ${timeoutMs}ms. Request: ${rpc.method}`));
419
+ }, timeoutMs);
420
+ }
421
+ this.pending.set(rpc.id, {
422
+ id: rpc.id,
423
+ request: rpc,
424
+ resolve: (value) => {
425
+ if (timer) {
426
+ clearTimeout(timer);
427
+ }
428
+ resolve(value);
429
+ },
430
+ reject: (reason) => {
431
+ if (timer) {
432
+ clearTimeout(timer);
433
+ }
434
+ reject(reason);
435
+ },
436
+ });
437
+ this.delegate(rpc, transfer);
438
+ });
439
+ }
440
+ handleResponse(response) {
441
+ var _a;
442
+ const pending = this.pending.get(response.id);
443
+ if (!pending) {
444
+ return;
445
+ }
446
+ this.pending.delete(response.id);
447
+ if (response.error == null) {
448
+ pending.resolve(response.result);
449
+ }
450
+ else {
451
+ (_a = pending.reject) === null || _a === void 0 ? void 0 : _a.call(pending, response.error);
452
+ }
453
+ }
454
+ }
455
+ function jsonRpcWorker({ worker }) {
456
+ const client = new JsonRpcClient((rpc, transfer) => {
457
+ worker.postMessage(rpc, transfer || []);
458
+ });
459
+ worker.addEventListener('message', (e) => {
460
+ client.handleResponse(e.data);
461
+ });
462
+ return {
463
+ worker,
464
+ nextId: client.nextId.bind(client),
465
+ request: client.sendRequest.bind(client),
466
+ };
467
+ }
468
+ function postJsonRpc(target, message) {
469
+ target.postMessage(message);
470
+ }
471
+ function jsonRpcHandler(target, handler) {
472
+ target.addEventListener('message', (event) => __awaiter(this, void 0, void 0, function* () {
473
+ var _a;
474
+ const request = event.data;
475
+ try {
476
+ const result = yield Promise.resolve(handler(request));
477
+ postJsonRpc(self, {
478
+ id: request.id,
479
+ error: null,
480
+ result: result,
481
+ });
482
+ }
483
+ catch (error) {
484
+ postJsonRpc(self, {
485
+ id: request.id,
486
+ error: {
487
+ code: -32000,
488
+ message: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : String(error),
489
+ },
490
+ result: null,
491
+ });
492
+ }
493
+ }));
494
+ }
495
+
496
+ const SymbolObservable = (typeof Symbol === 'function' && Symbol.observable) || '@@observable';
497
+ function toObservableLike(source) {
498
+ return {
499
+ subscribe: source.subscribe.bind(source),
500
+ [SymbolObservable]() {
501
+ return this;
502
+ },
503
+ };
504
+ }
505
+
506
+ function eventType(key) {
507
+ return brand(key);
508
+ }
509
+ class EventChannel {
510
+ constructor() {
511
+ this.handlers = new Set();
512
+ this.toRemove = [];
513
+ this.toAdd = [];
514
+ this.notifyDepth = 0;
515
+ }
516
+ add(handler) {
517
+ this.toAdd.push(handler);
518
+ if (this.notifyDepth === 0) {
519
+ this.processPending();
520
+ }
521
+ return () => this.remove(handler);
522
+ }
523
+ once(handler) {
524
+ const wrapper = (arg) => {
525
+ this.remove(wrapper);
526
+ handler(arg);
527
+ };
528
+ return this.add(wrapper);
529
+ }
530
+ remove(handler) {
531
+ this.toRemove.push(handler);
532
+ if (this.notifyDepth === 0) {
533
+ this.processPending();
534
+ }
535
+ }
536
+ emit(arg) {
537
+ var _a;
538
+ if (this.notifyDepth > 0) {
539
+ console.warn(`[${typeName(this.type)}] Nested notify calls detected.`, new Error().stack);
540
+ return false;
541
+ }
542
+ this.notifyDepth++;
543
+ for (const observer of this.handlers) {
544
+ try {
545
+ observer(arg);
546
+ }
547
+ catch (e) {
548
+ console.error(e);
549
+ }
550
+ }
551
+ try {
552
+ (_a = this.capture) === null || _a === void 0 ? void 0 : _a.call(this, this.type, arg);
553
+ }
554
+ catch (e) {
555
+ console.error(e);
556
+ }
557
+ this.notifyDepth--;
558
+ if (this.notifyDepth === 0) {
559
+ this.processPending();
560
+ }
561
+ return true;
562
+ }
563
+ clear() {
564
+ if (this.notifyDepth) {
565
+ console.warn(`[${typeName(this.type)}] clear was called during notify.`, new Error().stack);
566
+ }
567
+ this.handlers.clear();
568
+ }
569
+ subscribe(observer) {
570
+ let setter;
571
+ if (typeof observer === 'function') {
572
+ setter = observer;
573
+ }
574
+ else if (typeof (observer === null || observer === void 0 ? void 0 : observer.next) === 'function') {
575
+ setter = observer.next.bind(observer);
576
+ }
577
+ else {
578
+ setter = () => void 0;
579
+ }
580
+ return {
581
+ unsubscribe: this.add(setter),
582
+ };
583
+ }
584
+ [SymbolObservable]() {
585
+ return this;
586
+ }
587
+ }
588
+ function typeName(type) {
589
+ if (typeof type === 'string') {
590
+ return type;
591
+ }
592
+ else if (typeof type === 'symbol') {
593
+ return type.toString();
594
+ }
595
+ else {
596
+ return String(type);
597
+ }
598
+ }
599
+
600
+ function eventSource(name, capture) {
601
+ return new EventSource(name, capture);
602
+ }
603
+ class EventSource extends EventChannel {
604
+ constructor(type, capture) {
605
+ super();
606
+ this.type = type !== null && type !== void 0 ? type : 'EventSource';
607
+ this.capture = capture;
608
+ }
609
+ processPending() {
610
+ while (this.toRemove.length > 0) {
611
+ const handler = this.toRemove.shift();
612
+ this.handlers.delete(handler);
613
+ }
614
+ while (this.toAdd.length > 0) {
615
+ const handler = this.toAdd.shift();
616
+ this.handlers.add(handler);
617
+ }
618
+ }
619
+ }
620
+ function valueSource(options) {
621
+ return new ValueSource(null, options);
622
+ }
623
+ class ValueSource extends EventChannel {
624
+ constructor(type, options) {
625
+ super();
626
+ this.hasValue = false;
627
+ this.type = type !== null && type !== void 0 ? type : 'ValueSource';
628
+ if (options) {
629
+ this.value = options.initialValue;
630
+ this.hasValue = true;
631
+ }
632
+ else {
633
+ this.value = undefined;
634
+ this.hasValue = false;
635
+ }
636
+ this.subscribe((v) => (this.value = v));
637
+ }
638
+ processPending() {
639
+ while (this.toRemove.length > 0) {
640
+ const handler = this.toRemove.shift();
641
+ this.handlers.delete(handler);
642
+ }
643
+ while (this.toAdd.length > 0) {
644
+ const handler = this.toAdd.shift();
645
+ this.handlers.add(handler);
646
+ if (this.hasValue) {
647
+ try {
648
+ handler(this.value);
649
+ }
650
+ catch (e) {
651
+ console.error(e);
652
+ }
653
+ }
654
+ }
655
+ }
656
+ getValue() {
657
+ return this.value;
658
+ }
659
+ setValue(v) {
660
+ const changed = this.value !== v;
661
+ this.value = v;
662
+ if (changed) {
663
+ this.emit(this.value);
664
+ }
665
+ }
666
+ }
667
+
668
+ class EventBus {
669
+ constructor() {
670
+ this.channels = {};
671
+ this.registry = new Map();
672
+ }
673
+ channel(name) {
674
+ var _a;
675
+ (_a = this.channels)[name] || (_a[name] = eventSource(name));
676
+ return this.channels[name];
677
+ }
678
+ on(event, handler) {
679
+ return this.channel(event).add(handler);
680
+ }
681
+ off(event, handler) {
682
+ this.channel(event).remove(handler);
683
+ }
684
+ once(event, handler) {
685
+ return this.channel(event).once(handler);
686
+ }
687
+ emit(event, arg) {
688
+ var _a;
689
+ (_a = this.channels[event]) === null || _a === void 0 ? void 0 : _a.emit(arg);
690
+ }
691
+ register(emitter) {
692
+ if (this.registry.has(emitter)) {
693
+ throw new Error('Emitter is already registered');
694
+ }
695
+ const uncapture = emitter.capture((type, arg) => {
696
+ this.emit(type, arg);
697
+ });
698
+ const unregister = () => {
699
+ uncapture();
700
+ this.registry.delete(emitter);
701
+ };
702
+ this.registry.set(emitter, unregister);
703
+ return unregister;
704
+ }
705
+ unregister(emitter) {
706
+ const unregister = this.registry.get(emitter);
707
+ if (!unregister) {
708
+ throw new Error('Emitter is not registered');
709
+ }
710
+ unregister();
711
+ }
712
+ }
713
+
714
+ class EventEmitter {
715
+ constructor() {
716
+ this.channels = {};
717
+ this.captures = [];
718
+ }
719
+ channel(name) {
720
+ var _a;
721
+ (_a = this.channels)[name] || (_a[name] = eventSource(name, (type, arg) => this.emitCapture(type, arg)));
722
+ return this.channels[name];
723
+ }
724
+ capture(handler) {
725
+ this.captures.push(handler);
726
+ return () => {
727
+ removeItemUnordered(this.captures, handler);
728
+ };
729
+ }
730
+ on(event, handler) {
731
+ return this.channel(event).add(handler);
732
+ }
733
+ off(event, handler) {
734
+ this.channel(event).remove(handler);
735
+ }
736
+ once(event, handler) {
737
+ return this.channel(event).once(handler);
738
+ }
739
+ emit(event, arg) {
740
+ this.channel(event).emit(arg);
741
+ }
742
+ emitCapture(event, arg) {
743
+ for (const handler of this.captures) {
744
+ handler(event, arg);
745
+ }
746
+ }
747
+ }
748
+
749
+ /**
750
+ * A wrapper around the ArrayBuffer and DataView. Simplifies reading binary data.
751
+ *
752
+ * @public
753
+ */
754
+ class BinaryReader {
755
+ /**
756
+ * The number of bytes remaining to read
757
+ */
758
+ get remaining() {
759
+ return this.data.byteLength - this.position;
760
+ }
761
+ /**
762
+ * Creates a new instance of {@link BinaryReader}
763
+ *
764
+ * @param data - The data to read
765
+ */
766
+ constructor(data) {
767
+ /**
768
+ * Byte order to read. Default is `true`
769
+ */
770
+ this.littleEndian = true;
771
+ this.data = data;
772
+ this.view = new DataView(this.data);
773
+ this.position = 0;
774
+ }
775
+ /**
776
+ * Checks whether the readers position has not reached the end of the buffer
777
+ */
778
+ get canRead() {
779
+ return this.position < this.data.byteLength;
780
+ }
781
+ /**
782
+ * Reads a single character from the current position without advancing the position.
783
+ */
784
+ get char() {
785
+ return String.fromCharCode(this.byte);
786
+ }
787
+ /**
788
+ * Reads a single byte from the current position without advancing the position.
789
+ */
790
+ get byte() {
791
+ return this.data[this.position];
792
+ }
793
+ /**
794
+ * Reads a specified number of bytes
795
+ *
796
+ * @param length - The number of bytes to read
797
+ * @param output - The destination array to read into
798
+ */
799
+ readBytes(length, output = []) {
800
+ while (length > 0) {
801
+ output.push(this.view.getUint8(this.position++));
802
+ length--;
803
+ }
804
+ return output;
805
+ }
806
+ /**
807
+ * Reads a specified number of bytes as a byte array
808
+ *
809
+ * @param length - The number of bytes to read
810
+ */
811
+ readByteArray(length) {
812
+ return new Int8Array(this.slice(length));
813
+ }
814
+ /**
815
+ * Reads a specified number of bytes as a byte array
816
+ *
817
+ * @param length - The number of bytes to read
818
+ */
819
+ readUByteArray(length) {
820
+ return new Uint8Array(this.slice(length));
821
+ }
822
+ readBuffer(buffer, index, length) {
823
+ let end = index + length;
824
+ while (index < end) {
825
+ buffer[index++] = this.view.getUint8(this.position++);
826
+ }
827
+ }
828
+ /**
829
+ * Reads a single unsigned byte value
830
+ */
831
+ readUByte() {
832
+ return this.view.getUint8(this.position++);
833
+ }
834
+ /**
835
+ * Reads a single signed byte value
836
+ */
837
+ readByte() {
838
+ return this.view.getInt8(this.position++);
839
+ }
840
+ /**
841
+ * Reads a single unsigned short value
842
+ */
843
+ readUShort() {
844
+ let result = this.view.getUint16(this.position, this.littleEndian);
845
+ this.position += 2;
846
+ return result;
847
+ }
848
+ /**
849
+ * Reads a single signed short value
850
+ */
851
+ readShort() {
852
+ let result = this.view.getInt16(this.position, this.littleEndian);
853
+ this.position += 2;
854
+ return result;
855
+ }
856
+ /**
857
+ * Reads a single uint32 value
858
+ */
859
+ readUInt() {
860
+ let result = this.view.getUint32(this.position, this.littleEndian);
861
+ this.position += 4;
862
+ return result;
863
+ }
864
+ /**
865
+ * Reads a single int32 value
866
+ */
867
+ readInt() {
868
+ let result = this.view.getInt32(this.position, this.littleEndian);
869
+ this.position += 4;
870
+ return result;
871
+ }
872
+ /**
873
+ * Reads a two uint32 values as low and high bits.
874
+ */
875
+ readLong() {
876
+ let lo = this.readUInt();
877
+ let hi = this.readUInt() << 32;
878
+ return hi + lo;
879
+ }
880
+ /**
881
+ * Reads a single float32 value
882
+ */
883
+ readFloat() {
884
+ let result = this.view.getFloat32(this.position, this.littleEndian);
885
+ this.position += 4;
886
+ return result;
887
+ }
888
+ /**
889
+ * Reads a single float64 value
890
+ */
891
+ readDouble() {
892
+ let result = this.view.getFloat64(this.position, this.littleEndian);
893
+ this.position += 8;
894
+ return result;
895
+ }
896
+ /**
897
+ * Jumps to the given position on the data array
898
+ *
899
+ * @param position - The new index
900
+ */
901
+ seekAbsolute(position) {
902
+ this.position = position;
903
+ }
904
+ /**
905
+ * Jumps to the given position (relative to the current postion) on the data array
906
+ *
907
+ * @param position - The new relative position
908
+ */
909
+ seekRelative(position) {
910
+ this.position += position;
911
+ }
912
+ /**
913
+ * Reads a string
914
+ *
915
+ * @param length - The length in bytes to read
916
+ */
917
+ readString(length) {
918
+ let result = [];
919
+ while (length > 0) {
920
+ result.push(String.fromCharCode(this.view.getUint8(this.position++)));
921
+ length--;
922
+ }
923
+ return result.join('');
924
+ }
925
+ /**
926
+ * Returns a section of the buffer starting at current position
927
+ *
928
+ * @param length - The length to slice
929
+ */
930
+ slice(length) {
931
+ this.position += length;
932
+ return this.data.slice(this.position - length, this.position);
933
+ }
934
+ subarray(type, byteLength) {
935
+ const result = new type(this.data, this.position, byteLength / type.BYTES_PER_ELEMENT);
936
+ this.position += byteLength;
937
+ return result;
938
+ }
939
+ }
940
+
941
+ const TextCharKind = {
942
+ Whitespace: 0,
943
+ Symbol: 1,
944
+ };
945
+ /**
946
+ * A wrapper around a string. Simplifies reading arbitrary formatted text data.
947
+ *
948
+ * @public
949
+ */
950
+ class TextReader {
951
+ /**
952
+ * Checks whether the readers position has not reached the end of the string
953
+ */
954
+ get canRead() {
955
+ return this.index < this.text.length;
956
+ }
957
+ /**
958
+ * Gets the character at the current readers position.
959
+ */
960
+ get char() {
961
+ return this.text.charAt(this.index);
962
+ }
963
+ get charCode() {
964
+ return this.text.charCodeAt(this.index);
965
+ }
966
+ /**
967
+ * Gets a substring until the end of the string.
968
+ */
969
+ get rest() {
970
+ return this.text.substring(this.index);
971
+ }
972
+ /**
973
+ * Detects whether the character at current position is a symbol
974
+ */
975
+ get isSymbol() {
976
+ return this.charMap.get(this.char) === TextCharKind.Symbol;
977
+ }
978
+ /**
979
+ * Detects whether the character at current position is a whitespace
980
+ */
981
+ get isWhitespace() {
982
+ return this.charMap.get(this.char) === TextCharKind.Whitespace;
983
+ }
984
+ /**
985
+ * Detects whether the character at current position is a '\n'
986
+ */
987
+ get isNewLine() {
988
+ return this.char === '\n';
989
+ }
990
+ /**
991
+ * Detects whether the caracter at current position is neither whitespace nor symbol
992
+ */
993
+ get isToken() {
994
+ return !(this.isWhitespace || this.isSymbol);
995
+ }
996
+ /**
997
+ * Detects whether the caracter at current position is [0-9]
998
+ */
999
+ get isNumeric() {
1000
+ const c = this.charCode;
1001
+ return c >= 48 && c <= 57;
1002
+ }
1003
+ /**
1004
+ * Detects whether the caracter at current position is [a-zA-Z]
1005
+ */
1006
+ get isAlpha() {
1007
+ const c = this.charCode;
1008
+ return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
1009
+ }
1010
+ get position() {
1011
+ return this.index;
1012
+ }
1013
+ /**
1014
+ * Creates a new instance of {@link TextReader}
1015
+ *
1016
+ * @param text - The text data to read
1017
+ */
1018
+ constructor(text, options) {
1019
+ var _a, _b;
1020
+ this.index = 0;
1021
+ this.charMap = new Map();
1022
+ this.cachedSets = new Map();
1023
+ this.text = text;
1024
+ this.options = options;
1025
+ const whitespaces = (_a = options === null || options === void 0 ? void 0 : options.whitespaces) !== null && _a !== void 0 ? _a : ' \t\r\n\f';
1026
+ whitespaces.split('').forEach((it) => {
1027
+ this.charMap.set(it, TextCharKind.Whitespace);
1028
+ });
1029
+ const symbols = (_b = options === null || options === void 0 ? void 0 : options.symbols) !== null && _b !== void 0 ? _b : '.+-/*%<>[](){}^|&~=!:;,?';
1030
+ symbols.split('').forEach((it) => {
1031
+ this.charMap.set(it, TextCharKind.Symbol);
1032
+ });
1033
+ }
1034
+ getSet(set) {
1035
+ let result = this.cachedSets.get(set);
1036
+ if (!result) {
1037
+ result = new Set(set.split(''));
1038
+ this.cachedSets.set(set, result);
1039
+ }
1040
+ return result;
1041
+ }
1042
+ /**
1043
+ * Sets the current reader position to the given index
1044
+ */
1045
+ seek(index) {
1046
+ this.index = index;
1047
+ }
1048
+ /**
1049
+ * Returns the string that is in front of current position
1050
+ *
1051
+ * @param count - number of characters to peek
1052
+ */
1053
+ peek(count) {
1054
+ return count == null || count === 1 ? this.char : this.text.substr(this.index, count);
1055
+ }
1056
+ /**
1057
+ *
1058
+ * @param offset
1059
+ * @param count
1060
+ * @returns
1061
+ */
1062
+ peekOffset(offset, count) {
1063
+ return this.text.substr(this.index + offset, count !== null && count !== void 0 ? count : 1);
1064
+ }
1065
+ /**
1066
+ * Returns the text that is in front of current position (see `readText`)
1067
+ */
1068
+ peekText() {
1069
+ const i = this.index;
1070
+ const t = this.readText();
1071
+ this.index = i;
1072
+ return t;
1073
+ }
1074
+ /**
1075
+ * Returns the token that is in front of current position (see `readToken`)
1076
+ */
1077
+ peekToken() {
1078
+ const i = this.index;
1079
+ const t = this.readToken();
1080
+ this.index = i;
1081
+ return t;
1082
+ }
1083
+ /**
1084
+ * Return the text from current position until next new line terminator
1085
+ */
1086
+ peekLine() {
1087
+ const i = this.index;
1088
+ const l = this.readLine();
1089
+ this.index = i;
1090
+ return l;
1091
+ }
1092
+ /**
1093
+ * Moves pointer back to unread the given number of characters
1094
+ */
1095
+ unread(count) {
1096
+ this.index = Math.max(0, this.index - Math.abs(count));
1097
+ }
1098
+ /**
1099
+ * Reads the given number of characters.
1100
+ *
1101
+ * @remarks
1102
+ * If the reader is finished reading, an empty string will be returned
1103
+ *
1104
+ * @returns the string that was read
1105
+ */
1106
+ read(count) {
1107
+ if (!this.canRead) {
1108
+ return '';
1109
+ }
1110
+ if (count > 1) {
1111
+ const result = this.text.substr(this.index, count);
1112
+ this.index += count;
1113
+ return result;
1114
+ }
1115
+ const result = this.char;
1116
+ this.index++;
1117
+ return result;
1118
+ }
1119
+ /**
1120
+ * Skips initial whitespaces and then reads everything until next occurance of a whitespace
1121
+ *
1122
+ * @returns the string that was read
1123
+ */
1124
+ readText() {
1125
+ if (!this.canRead) {
1126
+ return '';
1127
+ }
1128
+ this.skipWhitespace();
1129
+ const i = this.index;
1130
+ this.skipUntilWhitespace();
1131
+ return this.text.substr(i, this.index - i).trim();
1132
+ }
1133
+ /**
1134
+ * Skips initial whitespaces and then reads everything until next occurance of a whitespace or symbol
1135
+ *
1136
+ * @returns the string that was read
1137
+ */
1138
+ readToken() {
1139
+ if (!this.canRead) {
1140
+ return '';
1141
+ }
1142
+ this.skipWhitespace();
1143
+ const i = this.index;
1144
+ this.skipUntilWhitespaceOrSymbol();
1145
+ return this.text.substr(i, this.index - i).trim();
1146
+ }
1147
+ /**
1148
+ * Reads until next occurrence of a new line character and trims the result
1149
+ *
1150
+ * @param cb - on optional callback that will receive a new reader for the new line
1151
+ * @returns the trimmed string that was being read
1152
+ */
1153
+ readLine(cb) {
1154
+ const line = this.readLineRaw().trim();
1155
+ if (cb) {
1156
+ cb(this.createReader(line));
1157
+ }
1158
+ return line;
1159
+ }
1160
+ /**
1161
+ * Reads until next occurrence of a new line character
1162
+ *
1163
+ * @param cb - on optional callback that will receive a new reader for the new line
1164
+ * @returns the string that was being read
1165
+ */
1166
+ readLineRaw(cb) {
1167
+ if (!this.canRead) {
1168
+ return '';
1169
+ }
1170
+ const i = this.index;
1171
+ this.skipUntil('\n');
1172
+ this.skip(1);
1173
+ const line = this.text.substr(i, this.index - i);
1174
+ if (cb) {
1175
+ cb(this.createReader(line));
1176
+ }
1177
+ return line;
1178
+ }
1179
+ /**
1180
+ * Skips leading whitespaces and then reads a block that is determined by the `open` and `close` character.
1181
+ *
1182
+ * @param start - character set identifying the begin of a block. Usually an opening parenthesis.
1183
+ * @param end - character set identifying the end of a block. Usually matching parenthesis.
1184
+ * @param cb - a callback to call with a new text reader
1185
+ */
1186
+ readBlock(open, close, cb) {
1187
+ if (!this.canRead) {
1188
+ return '';
1189
+ }
1190
+ this.skipWhitespace();
1191
+ if (this.char !== open) {
1192
+ throw new Error(`expected '${open}' at current position but was ${this.char}`);
1193
+ }
1194
+ let iStart = this.index + 1;
1195
+ let iEnd = iStart;
1196
+ let depth = 0;
1197
+ while (this.canRead) {
1198
+ if (this.char === open) {
1199
+ depth++;
1200
+ }
1201
+ if (this.char === close) {
1202
+ depth--;
1203
+ }
1204
+ if (depth === 0) {
1205
+ iEnd = this.index;
1206
+ this.skip(1);
1207
+ break;
1208
+ }
1209
+ this.skip(1);
1210
+ }
1211
+ const block = this.text.substring(iStart, iEnd);
1212
+ if (cb) {
1213
+ cb(this.createReader(block));
1214
+ }
1215
+ return block;
1216
+ }
1217
+ /**
1218
+ * Reads a sequence of characters that are in given set
1219
+ *
1220
+ * @param cahrSet - the allowed character set
1221
+ * @returns the text being read
1222
+ */
1223
+ readWhile(cahrSet) {
1224
+ const set = this.getSet(cahrSet);
1225
+ const i = this.index;
1226
+ while (this.canRead && set.has(this.char)) {
1227
+ this.index += 1;
1228
+ }
1229
+ return this.text.substr(i, this.index - i);
1230
+ }
1231
+ /**
1232
+ * Reads everything until any character from given charset occurs
1233
+ *
1234
+ * @param charSet - the character set
1235
+ * @param inclusive - wheter to also read the boundary characters
1236
+ * @returns the text being read
1237
+ */
1238
+ readUntil(charSet, inclusive) {
1239
+ const i = this.index;
1240
+ this.skipUntil(charSet, inclusive);
1241
+ return this.text.substr(i, this.index - i);
1242
+ }
1243
+ /**
1244
+ * Reads everything until the given sequence occurs
1245
+ *
1246
+ * @param charSet - the character sequence
1247
+ * @param inclusive - wheter to also read the sequence at the end
1248
+ * @returns the text being read
1249
+ */
1250
+ readUntilText(sequence, inclusive) {
1251
+ const i = this.index;
1252
+ this.skipUntilSequence(sequence, inclusive);
1253
+ return this.text.substr(i, this.index - i);
1254
+ }
1255
+ /**
1256
+ * Skips the given number of characters
1257
+ *
1258
+ * @param count - the character count
1259
+ */
1260
+ skip(count) {
1261
+ this.index += count;
1262
+ }
1263
+ /**
1264
+ * Skips all whitespace characters
1265
+ */
1266
+ skipWhitespace() {
1267
+ while (this.canRead && this.isWhitespace) {
1268
+ this.index += 1;
1269
+ }
1270
+ }
1271
+ /**
1272
+ * Skips all symbol characters
1273
+ */
1274
+ skipSymbols() {
1275
+ while (this.canRead && this.isSymbol) {
1276
+ this.index += 1;
1277
+ }
1278
+ }
1279
+ /**
1280
+ * Skips all whitespace and symbol characters
1281
+ */
1282
+ skipWhitespaceAndSymbols() {
1283
+ while (this.canRead && (this.isWhitespace || this.isSymbol)) {
1284
+ this.index += 1;
1285
+ }
1286
+ }
1287
+ /**
1288
+ * Skips all characters in given character set
1289
+ *
1290
+ * @param charset - the characters to skip
1291
+ */
1292
+ skipChars(charset) {
1293
+ while (this.canRead && charset.indexOf(this.char) >= 0) {
1294
+ this.index += 1;
1295
+ }
1296
+ }
1297
+ /**
1298
+ * Skips characters until the next whitespace
1299
+ */
1300
+ skipUntilWhitespace() {
1301
+ while (this.canRead && !this.isWhitespace) {
1302
+ this.index += 1;
1303
+ }
1304
+ }
1305
+ /**
1306
+ * Skips characters until the next symbol
1307
+ */
1308
+ skipUntilSymbol() {
1309
+ while (this.canRead && !this.isSymbol) {
1310
+ this.index += 1;
1311
+ }
1312
+ }
1313
+ /**
1314
+ * Skips characters until the next whitespace or symbol
1315
+ */
1316
+ skipUntilWhitespaceOrSymbol() {
1317
+ while (this.canRead && !(this.isWhitespace || this.isSymbol)) {
1318
+ this.index += 1;
1319
+ }
1320
+ }
1321
+ /**
1322
+ * Skips characters until occurrence of one in the given string
1323
+ *
1324
+ * @param charset - the characters to stop at
1325
+ * @param consume -
1326
+ */
1327
+ skipUntil(charset, consume) {
1328
+ const set = this.getSet(charset);
1329
+ while (this.canRead && !set.has(this.char)) {
1330
+ this.skip(1);
1331
+ }
1332
+ if (consume) {
1333
+ this.skipChars(charset);
1334
+ }
1335
+ }
1336
+ /**
1337
+ * Skips forward until the occurence of given sequence
1338
+ *
1339
+ * @param sequence - the sequence to search for
1340
+ * @param consume - whether to consume the found sequence
1341
+ */
1342
+ skipUntilSequence(sequence, consume) {
1343
+ while (this.canRead) {
1344
+ if (this.char !== sequence[0]) {
1345
+ this.skip(1);
1346
+ }
1347
+ else if (this.peek(sequence.length) === sequence) {
1348
+ if (consume) {
1349
+ this.skip(sequence.length);
1350
+ }
1351
+ return;
1352
+ }
1353
+ else {
1354
+ this.skip(1);
1355
+ }
1356
+ }
1357
+ }
1358
+ /**
1359
+ * Consumes the next token only if it matches the given value. Otherwise leaves the state untouched.
1360
+ */
1361
+ accept(value) {
1362
+ const actual = this.peek(value.length);
1363
+ if (actual === value) {
1364
+ this.index += value.length;
1365
+ return value;
1366
+ }
1367
+ return undefined;
1368
+ }
1369
+ /**
1370
+ * Checks whether the value at current position equals the given value
1371
+ *
1372
+ * @param value
1373
+ */
1374
+ assert(value, consume) {
1375
+ const actual = this.peek(value.length);
1376
+ if (actual !== value) {
1377
+ throw new Error(`Expected '${value}' at current position but was '${actual}'\n${this.createErrorText()}`);
1378
+ }
1379
+ if (consume) {
1380
+ this.index += value.length;
1381
+ }
1382
+ }
1383
+ /**
1384
+ * Checks whether the value at current position equals the given value
1385
+ *
1386
+ * @param value
1387
+ */
1388
+ assertChar(value, consume) {
1389
+ if (this.char !== value) {
1390
+ throw new Error(`Expected '${value}' at current position but was '${this.char}'\n${this.createErrorText()}`);
1391
+ }
1392
+ if (consume) {
1393
+ this.index += 1;
1394
+ }
1395
+ }
1396
+ createErrorText(offset = 10) {
1397
+ const start = Math.max(this.index - 10, 0);
1398
+ const end = Math.min(this.index + 10, this.text.length - 1);
1399
+ return ' '.repeat(offset) + 'v\n' + `${this.text.substring(start, end)}`;
1400
+ }
1401
+ createReader(text) {
1402
+ return new TextReader(text, this.options);
1403
+ }
1404
+ }
1405
+
1406
+ //! parseUri 3.0.2; Steven Levithan; MIT License
1407
+ /**
1408
+ * Splits any URI into its parts.
1409
+ *
1410
+ * @param {string} uri
1411
+ * @param {'default' | 'friendly'} [mode] Parsing mode. Default follows official URI rules.
1412
+ * Friendly handles human-friendly URLs like `'example.com/index.html'` as expected.
1413
+ * @returns {ParseUriObject} Object with URI parts, plus `queryParams`.
1414
+ */
1415
+ function parseUri(uri, mode = 'default') {
1416
+ var _a, _b;
1417
+ uri = uri.trim();
1418
+ const { groups } = cache.parser[mode].exec(uri);
1419
+ const _c = Object.assign(Object.assign({ href: uri }, groups), (groups.protocol && groups.hasAuth == null ? blankUrnProps : null)), result = __rest(_c, ["hasAuth"]);
1420
+ // Replace `undefined` for non-participating capturing groups
1421
+ Object.keys(result).forEach((key) => { var _a; return ((_a = result[key]) !== null && _a !== void 0 ? _a : (result[key] = '')); });
1422
+ return Object.assign(result, Object.assign(Object.assign({}, (_b = (_a = cache.tlds) === null || _a === void 0 ? void 0 : _a.exec(result.hostname)) === null || _b === void 0 ? void 0 : _b.groups), { queryParams: new URLSearchParams(`?${result.query}`) }));
1423
+ }
1424
+ parseUri.dir = (path) => parseUri(path).directory;
1425
+ const blankUrnProps = {
1426
+ directory: '',
1427
+ filename: '',
1428
+ suffix: '',
1429
+ };
1430
+ function getParser(mode) {
1431
+ // Forward and backslashes have lost all meaning for web protocols (http, https, ws, wss, ftp)
1432
+ // and protocol-relative URLs. Also handle multiple colons in protocol delimiter for security
1433
+ const authorityDelimiter = String.raw `(?:(?:(?<=^(?:https?|wss?|ftp):):*|^:+)[\\/]*|^[\\/]{2,}|//)`;
1434
+ const authority = {
1435
+ default: { start: `(?<hasAuth>${authorityDelimiter}`, end: ')?' },
1436
+ friendly: { start: `(?<hasAuth>${authorityDelimiter}?)`, end: '' },
1437
+ };
1438
+ // See file: free-spacing-regex.md
1439
+ return RegExp(String.raw `^(?<origin>(?:(?<protocol>[a-z][^\s:@\\/?#.]*):)?${authority[mode].start}(?<authority>(?:(?<userinfo>(?<username>[^:@\\/?#]*)(?::(?<password>[^\\/?#]*))?)?@)?(?<host>(?<hostname>\d{1,3}(?:\.\d{1,3}){3}(?=[:\\/?#]|$)|\[[a-f\d]{0,4}(?::[a-f\d]{0,4}){2,7}(?:%[^\]]*)?\]|(?<subdomain>[^:\\/?#]*?)\.??(?<domain>(?:[^.:\\/?#]*\.)?(?<tld>[^.:\\/?#]*))(?=[:\\/?#]|$))?(?::(?<port>[^:\\/?#]*))?))${authority[mode].end})(?<resource>(?<pathname>(?<directory>(?:[^\\/?#]*[\\/])*)(?<filename>(?:[^.?#]+|\.(?![^.?#]+(?:[?#]|$)))*(?:\.(?<suffix>[^.?#]+))?))(?:\?(?<query>[^#]*))?(?:\#(?<fragment>.*))?)`, 'i');
1440
+ }
1441
+ const cache = {
1442
+ tlds: null,
1443
+ parser: {
1444
+ default: getParser('default'),
1445
+ friendly: getParser('friendly'),
1446
+ },
1447
+ };
1448
+
1449
+ function mergeUri(parentUri, resourceUri, base) {
1450
+ if (hasProtocol(resourceUri)) {
1451
+ return resourceUri;
1452
+ }
1453
+ let parent = parseUri(parentUri);
1454
+ let resource = parseUri(resourceUri);
1455
+ let path = isAbsolute(resourceUri) ? resource.pathname : parent.directory + resource.pathname;
1456
+ path = collapse(path);
1457
+ if (resource.query) {
1458
+ path += `?${resource.query}`;
1459
+ }
1460
+ if (resource.fragment) {
1461
+ path += `#${resource.fragment}`;
1462
+ }
1463
+ let result = base || '';
1464
+ if (!result) {
1465
+ if (parent.protocol) {
1466
+ result = parent.protocol + '://';
1467
+ }
1468
+ if (parent.authority) {
1469
+ result += parent.authority;
1470
+ }
1471
+ }
1472
+ if (!isAbsolute(path) && !result.endsWith('/')) {
1473
+ result += '/';
1474
+ }
1475
+ return result + path;
1476
+ }
1477
+ function isAbsolute(path) {
1478
+ return !!path && path[0] === '/';
1479
+ }
1480
+ function hasProtocol(path) {
1481
+ return !!path && !!path.match(/^[a-zA-Z]+:/i);
1482
+ }
1483
+ function collapse(path) {
1484
+ const wasAbsolute = isAbsolute(path);
1485
+ const parts = [];
1486
+ for (const token of path.split(/\//)) {
1487
+ if (!token || token === '.') {
1488
+ continue;
1489
+ }
1490
+ if (token === '..') {
1491
+ parts.pop();
1492
+ }
1493
+ else {
1494
+ parts.push(token);
1495
+ }
1496
+ }
1497
+ let result = parts.join('/');
1498
+ if (wasAbsolute) {
1499
+ result = `/${result}`;
1500
+ }
1501
+ return result;
1502
+ }
1503
+
1504
+ /**
1505
+ * Parses the uri and returns the directory part without trailing slash
1506
+ *
1507
+ * @example
1508
+ * dirname('http://example.com/foo/bar/baz.png') // returns 'http://example.com/foo/bar'
1509
+ */
1510
+ function dirname(uri) {
1511
+ const result = parseUri(uri).directory;
1512
+ if (result.endsWith('/') || result.endsWith('\\')) {
1513
+ return result.slice(0, -1);
1514
+ }
1515
+ return result;
1516
+ }
1517
+ /**
1518
+ * Parses the uri and returns the filename part
1519
+ *
1520
+ * @example
1521
+ * filename('http://example.com/foo/bar/baz.png') // returns 'baz.png'
1522
+ */
1523
+ function filename(uri) {
1524
+ return parseUri(uri).filename || '';
1525
+ }
1526
+ /**
1527
+ * Parses the uri and returns the extension part with leading dot
1528
+ *
1529
+ * @example
1530
+ * extname('http://example.com/foo/bar/baz.png') // returns '.png'
1531
+ */
1532
+ function extname(uri) {
1533
+ const suffix = parseUri(uri).suffix;
1534
+ return suffix ? `.${suffix}` : '';
1535
+ }
1536
+
1537
+ const vendors = ['', 'moz', 'webkit', 'ms', 'o'];
1538
+ /**
1539
+ * @public
1540
+ * @param el
1541
+ * @param name
1542
+ * @param variants
1543
+ */
1544
+ function vendorProperty(el, name, ...variants) {
1545
+ if (!el) {
1546
+ return null;
1547
+ }
1548
+ for (const prefix of vendors) {
1549
+ if (prefix) {
1550
+ const vendorName = prefix + String(name)[0].toUpperCase() + String(name).substr(1);
1551
+ if (vendorName in el) {
1552
+ return vendorName;
1553
+ }
1554
+ }
1555
+ else if (name in el) {
1556
+ return name.toString();
1557
+ }
1558
+ }
1559
+ for (const variant of variants) {
1560
+ if (variant in el) {
1561
+ return variant;
1562
+ }
1563
+ }
1564
+ return null;
1565
+ }
1566
+ /**
1567
+ * @public
1568
+ * @param el
1569
+ * @param name
1570
+ * @param variants
1571
+ */
1572
+ function vendorEvent(el, name, ...variants) {
1573
+ if (!el) {
1574
+ return null;
1575
+ }
1576
+ const suffix = name.toString().replace(/^on/, '');
1577
+ for (const prefix of vendors) {
1578
+ const event = 'on' + prefix + suffix;
1579
+ if (event in el) {
1580
+ return event;
1581
+ }
1582
+ }
1583
+ for (const variant of variants) {
1584
+ if (variant in el) {
1585
+ return variant;
1586
+ }
1587
+ }
1588
+ return null;
1589
+ }
1590
+ const docHidden = vendorProperty(globalThis.document, 'hidden');
1591
+ const docVisibilityState = vendorProperty(globalThis.document, 'visibilityState');
1592
+ const docVisibilityChange = vendorEvent(globalThis.document, 'onvisibilitychange');
1593
+ /**
1594
+ * @public
1595
+ */
1596
+ const documentVisibilityApi = {
1597
+ /**
1598
+ * Checks whether the current document is hidden.
1599
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden | Document.hidden}
1600
+ *
1601
+ * @public
1602
+ */
1603
+ get isHidden() {
1604
+ var _a;
1605
+ return (_a = document[docHidden]) !== null && _a !== void 0 ? _a : false;
1606
+ },
1607
+ /**
1608
+ * Checks whether the current document is hidden.
1609
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden | Document.hidden}
1610
+ *
1611
+ * @public
1612
+ */
1613
+ get isVisible() {
1614
+ var _a;
1615
+ return !((_a = document[docHidden]) !== null && _a !== void 0 ? _a : false);
1616
+ },
1617
+ /**
1618
+ * Gets the visibility state of current document.
1619
+ * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState | Document.visibilityState}
1620
+ *
1621
+ * @public
1622
+ */
1623
+ get visibilityState() {
1624
+ var _a;
1625
+ return (_a = document[docVisibilityState]) !== null && _a !== void 0 ? _a : 'visible';
1626
+ },
1627
+ /**
1628
+ * Adds a listener to the
1629
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/onvisibilitychange | Document.onvisibilitychange}
1630
+ * event
1631
+ *
1632
+ * @public
1633
+ */
1634
+ onVisibilityChange(callback, options) {
1635
+ if (docVisibilityChange) {
1636
+ document.addEventListener(docVisibilityChange, callback, options);
1637
+ }
1638
+ },
1639
+ /**
1640
+ * Removes a listener from the
1641
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/onvisibilitychange | Document.onvisibilitychange}
1642
+ * event
1643
+ *
1644
+ * @public
1645
+ */
1646
+ offVisibilityChange(callback, options) {
1647
+ if (docVisibilityChange) {
1648
+ document.removeEventListener(docVisibilityChange, callback, options);
1649
+ }
1650
+ },
1651
+ };
1652
+ /**
1653
+ * @public
1654
+ */
1655
+ class PointerLockApi {
1656
+ constructor() {
1657
+ this.pointerlockchange = vendorEvent(document, 'pointerlockchange');
1658
+ this.pointerlockerror = vendorEvent(document, 'pointerlockerror');
1659
+ this.requestPointerLockName = vendorProperty(document, 'requestPointerLock');
1660
+ this.exitPointerLockName = vendorProperty(document, 'exitPointerLock');
1661
+ this.pointerLockElementName = vendorProperty(document, 'pointerLockElement');
1662
+ }
1663
+ get isSupported() {
1664
+ return !!this.exitPointerLockName;
1665
+ }
1666
+ get pointerLockElement() {
1667
+ var _a;
1668
+ return (_a = document[this.pointerLockElementName]) !== null && _a !== void 0 ? _a : null;
1669
+ }
1670
+ onChange(callback, options) {
1671
+ if (this.pointerlockchange) {
1672
+ document.addEventListener(this.pointerlockchange, callback, options);
1673
+ }
1674
+ }
1675
+ offChange(callback, options) {
1676
+ if (this.pointerlockchange) {
1677
+ document.removeEventListener(this.pointerlockchange, callback, options);
1678
+ }
1679
+ }
1680
+ onError(callback, options) {
1681
+ if (this.pointerlockerror) {
1682
+ document.addEventListener(this.pointerlockerror, callback, options);
1683
+ }
1684
+ }
1685
+ offError(callback, options) {
1686
+ if (this.pointerlockerror) {
1687
+ document.removeEventListener(this.pointerlockerror, callback, options);
1688
+ }
1689
+ }
1690
+ requestLock(target) {
1691
+ this.requestPointerLockName = this.requestPointerLockName || vendorProperty(target, 'requestPointerLock');
1692
+ if (this.requestPointerLockName) {
1693
+ target[this.requestPointerLockName]();
1694
+ }
1695
+ }
1696
+ exitLock() {
1697
+ if (this.exitPointerLockName) {
1698
+ document[this.exitPointerLockName]();
1699
+ }
1700
+ }
1701
+ }
1702
+ function withResolvers() {
1703
+ let resolve;
1704
+ let reject;
1705
+ const promise = new Promise((res, rej) => {
1706
+ resolve = res;
1707
+ reject = rej;
1708
+ });
1709
+ return { promise, resolve, reject };
1710
+ }
1711
+
1712
+ /**
1713
+ * A primitive loop scheduler with no fixed time support or any optimizations.
1714
+ * Simply schedules the given `frame` function with `requestAnimationFrame`.
1715
+ *
1716
+ * @public
1717
+ */
1718
+ function loop(frame, autostart = true) {
1719
+ let requestId = null;
1720
+ let timestamp = performance.now();
1721
+ function tick() {
1722
+ const dt = performance.now() - timestamp;
1723
+ timestamp += dt;
1724
+ frame(timestamp / 1000, dt / 1000);
1725
+ requestId = requestAnimationFrame(tick);
1726
+ }
1727
+ function start() {
1728
+ if (requestId == null) {
1729
+ timestamp = performance.now();
1730
+ requestId = requestAnimationFrame(tick);
1731
+ }
1732
+ return looper;
1733
+ }
1734
+ function stop() {
1735
+ if (requestId != null) {
1736
+ cancelAnimationFrame(requestId);
1737
+ requestId = null;
1738
+ }
1739
+ return looper;
1740
+ }
1741
+ const looper = {
1742
+ start,
1743
+ stop,
1744
+ get isRunning() {
1745
+ return requestId != null;
1746
+ },
1747
+ };
1748
+ if (autostart) {
1749
+ looper.start();
1750
+ }
1751
+ return looper;
1752
+ }
1753
+
1754
+ /**
1755
+ * Generates a random uuid string
1756
+ *
1757
+ * @public
1758
+ */
1759
+ function uuid() {
1760
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
1761
+ let r = Math.random() * 16 | 0; // tslint:disable-line
1762
+ let v = c == 'x' ? r : (r & 0x3 | 0x8); // tslint:disable-line
1763
+ return v.toString(16);
1764
+ });
1765
+ }
1766
+
1767
+ const NAMED_STYLES = {
1768
+ // text color
1769
+ blue: 'color: #4E79A7',
1770
+ orange: 'color: #F28E2B',
1771
+ red: 'color: #E15759',
1772
+ teal: 'color: #76B7B2',
1773
+ green: 'color: #59A14F',
1774
+ yellow: 'color: #EDC948',
1775
+ purple: 'color: #B07AA1',
1776
+ pink: 'color: #FF9DA7',
1777
+ brown: 'color: #9C755F',
1778
+ gray: 'color: #BAB0AC',
1779
+ white: 'color:#fff',
1780
+ black: 'color:#000',
1781
+ // decoration
1782
+ bold: 'font-weight:bold',
1783
+ dim: 'opacity:0.5',
1784
+ italic: 'font-style:italic',
1785
+ };
1786
+ function createChain(styles) {
1787
+ const css = () => styles.join(';');
1788
+ function call(...args) {
1789
+ if (styles.length === 0)
1790
+ return args;
1791
+ return [args.map(() => '%c%s').join(' '), ...args.flatMap((arg) => [css(), String(arg)])];
1792
+ }
1793
+ const methods = {
1794
+ color: (value) => createChain([...styles, `color:${value}`]),
1795
+ bg: (value) => createChain([...styles, `background:${value}`]),
1796
+ badge: (color, label) => [
1797
+ `%c ${label} %c`,
1798
+ `background:${color};color:#fff;border-radius:3px;padding:2px 0px;font-weight:bold;font-size:0.85em`,
1799
+ 'color:inherit;background:none',
1800
+ ],
1801
+ merge: (...messages) => [
1802
+ messages.map((m) => m[0]).join(' '),
1803
+ ...messages.flatMap((m) => m.slice(1)),
1804
+ ],
1805
+ };
1806
+ return new Proxy(call, {
1807
+ get(_, prop) {
1808
+ if (prop in methods) {
1809
+ return methods[prop];
1810
+ }
1811
+ if (prop in NAMED_STYLES) {
1812
+ return createChain([...styles, NAMED_STYLES[prop]]);
1813
+ }
1814
+ return undefined;
1815
+ },
1816
+ });
1817
+ }
1818
+ const lfmt = createChain([]);
1819
+ // Usage examples:
1820
+ //
1821
+ // console.log(...lfmt.red.bold("[ERROR]", "something broke"))
1822
+ // console.log(...lfmt.green("✓ ready"))
1823
+ // console.log(...lfmt.dim("cache miss:", key))
1824
+ // console.log(...lfmt.color("#e67e22").bold("custom color"))
1825
+ // console.log(...lfmt.bg("navy").white.bold("[DB]"), rawQueryNotStyled)
1826
+ //
1827
+ // const tag = lfmt.badge("MyComponent", "#4a9eff")
1828
+ // console.log(...tag, "message")
1829
+ //
1830
+ // const tag = lfmt.merge(lfmt.badge("App", "#4a9eff"), lfmt.badge("Auth", "#f1c40f"))
1831
+ // console.log(...tag, "user logged in")
1832
+
1833
+ const isWorkerContext = typeof globalThis['importScripts'] === 'function';
1834
+ /**
1835
+ * Determines whether this context is inside a browser window
1836
+ *
1837
+ * @public
1838
+ */
1839
+ const isWindowContext = typeof globalThis['importScripts'] !== 'function';
1840
+ /**
1841
+ * Determines whether web porker api is supported
1842
+ *
1843
+ * @public
1844
+ */
1845
+ const isWorkerSupported = typeof Worker !== 'undefined';
1846
+ /**
1847
+ * Gets the current worker context if available
1848
+ */
1849
+ function getWorkerContext() {
1850
+ if (isWorkerContext) {
1851
+ return globalThis;
1852
+ }
1853
+ return null;
1854
+ }
1855
+
1856
+ class MetricSampler {
1857
+ constructor(options) {
1858
+ var _a, _b;
1859
+ this.current = 0;
1860
+ this.average = 0;
1861
+ this.min = 0;
1862
+ this.max = 0;
1863
+ this.sum = 0; // sum of last window
1864
+ this.totalSamples = 0; // all-time count
1865
+ this.accSum = 0;
1866
+ this.accMin = Infinity;
1867
+ this.accMax = -Infinity;
1868
+ this.count = 0;
1869
+ this.label = (_a = options === null || options === void 0 ? void 0 : options.label) !== null && _a !== void 0 ? _a : 'MetricSampler';
1870
+ this.windowSize = (_b = options === null || options === void 0 ? void 0 : options.windowSize) !== null && _b !== void 0 ? _b : 60;
1871
+ }
1872
+ sample(value) {
1873
+ this.current = value;
1874
+ this.totalSamples++;
1875
+ this.accSum += value;
1876
+ if (value < this.accMin) {
1877
+ this.accMin = value;
1878
+ }
1879
+ if (value > this.accMax) {
1880
+ this.accMax = value;
1881
+ }
1882
+ if (++this.count === this.windowSize) {
1883
+ this.average = this.accSum / this.count;
1884
+ this.min = this.accMin;
1885
+ this.max = this.accMax;
1886
+ this.sum = this.accSum;
1887
+ this.resetWindow();
1888
+ }
1889
+ }
1890
+ reset() {
1891
+ this.current = this.average = this.min = this.max = this.sum = 0;
1892
+ this.totalSamples = 0;
1893
+ this.resetWindow();
1894
+ }
1895
+ resetWindow() {
1896
+ this.accSum = 0;
1897
+ this.accMin = Infinity;
1898
+ this.accMax = -Infinity;
1899
+ this.count = 0;
1900
+ }
1901
+ }
1902
+
1903
+ export { BinaryReader, EventBus, EventChannel, EventEmitter, EventSource, JsonRpcClient, MetricSampler, PointerLockApi, PooledList, PriorityQueue, SymbolObservable, TextCharKind, TextReader, ValueSource, addItemIfAbsent, append, brand, dirname, documentVisibilityApi, eventSource, eventType, extname, filename, getWorkerContext, idMap, idSet, isWindowContext, isWorkerContext, isWorkerSupported, jsonRpcHandler, jsonRpcWorker, lfmt, loop, mergeUri, parseUri, postJsonRpc, removeItem, removeItemUnordered, toObservableLike, uuid, valueSource, vendorEvent, vendorProperty, withResolvers };
1904
+ //# sourceMappingURL=utils.esm.js.map