@gglib/utils 0.6.1 → 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 +1248 -637
  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 -1666
  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
@@ -1,1666 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define('Gglib.Utils', ['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Gglib = global.Gglib || {}, global.Gglib.Utils = {})));
5
- }(this, (function (exports) { 'use strict';
6
-
7
- /**
8
- * A wrapper around the ArrayBuffer and DataView. Simplifies reading binary data.
9
- *
10
- * @public
11
- */
12
- var BinaryReader = /** @class */ (function () {
13
- /**
14
- * Creates a new instance of {@link BinaryReader}
15
- *
16
- * @param data - The data to read
17
- */
18
- function BinaryReader(data) {
19
- /**
20
- * Byte order to read. Default is `true`
21
- */
22
- this.littleEndian = true;
23
- this.data = data;
24
- this.view = new DataView(this.data);
25
- this.position = 0;
26
- }
27
- Object.defineProperty(BinaryReader.prototype, "canRead", {
28
- /**
29
- * Checks whether the readers position has not reached the end of the buffer
30
- */
31
- get: function () {
32
- return this.position < this.data.byteLength;
33
- },
34
- enumerable: false,
35
- configurable: true
36
- });
37
- /**
38
- * Reads a specified number of bytes
39
- *
40
- * @param length - The number of bytes to read
41
- * @param output - The destination array to read into
42
- */
43
- BinaryReader.prototype.readBytes = function (length, output) {
44
- if (output === void 0) { output = []; }
45
- while (length > 0) {
46
- output.push(this.view.getUint8(this.position++));
47
- length--;
48
- }
49
- return output;
50
- };
51
- /**
52
- * Reads a specified number of bytes as a byte array
53
- *
54
- * @param length - The number of bytes to read
55
- */
56
- BinaryReader.prototype.readByteArray = function (length) {
57
- return new Int8Array(this.slice(length));
58
- };
59
- BinaryReader.prototype.readBuffer = function (buffer, index, length) {
60
- var end = index + length;
61
- while (index < end) {
62
- buffer[index++] = this.view.getUint8(this.position++);
63
- }
64
- };
65
- /**
66
- * Reads a single unsigned byte value
67
- */
68
- BinaryReader.prototype.readUByte = function () {
69
- return this.view.getUint8(this.position++);
70
- };
71
- /**
72
- * Reads a single signed byte value
73
- */
74
- BinaryReader.prototype.readByte = function () {
75
- return this.view.getInt8(this.position++);
76
- };
77
- /**
78
- * Reads a single unsigned short value
79
- */
80
- BinaryReader.prototype.readUShort = function () {
81
- var result = this.view.getUint16(this.position, this.littleEndian);
82
- this.position += 2;
83
- return result;
84
- };
85
- /**
86
- * Reads a single signed short value
87
- */
88
- BinaryReader.prototype.readShort = function () {
89
- var result = this.view.getInt16(this.position, this.littleEndian);
90
- this.position += 2;
91
- return result;
92
- };
93
- /**
94
- * Reads a single uint32 value
95
- */
96
- BinaryReader.prototype.readUInt = function () {
97
- var result = this.view.getUint32(this.position, this.littleEndian);
98
- this.position += 4;
99
- return result;
100
- };
101
- /**
102
- * Reads a single int32 value
103
- */
104
- BinaryReader.prototype.readInt = function () {
105
- var result = this.view.getInt32(this.position, this.littleEndian);
106
- this.position += 4;
107
- return result;
108
- };
109
- /**
110
- * Reads a two uint32 values as low and high bits.
111
- */
112
- BinaryReader.prototype.readLong = function () {
113
- var lo = this.readUInt();
114
- var hi = this.readUInt() << 32;
115
- return hi + lo;
116
- };
117
- /**
118
- * Reads a single float32 value
119
- */
120
- BinaryReader.prototype.readFloat = function () {
121
- var result = this.view.getFloat32(this.position, this.littleEndian);
122
- this.position += 4;
123
- return result;
124
- };
125
- /**
126
- * Reads a single float64 value
127
- */
128
- BinaryReader.prototype.readDouble = function () {
129
- var result = this.view.getFloat64(this.position, this.littleEndian);
130
- this.position += 8;
131
- return result;
132
- };
133
- /**
134
- * Jumps to the given position on the data array
135
- *
136
- * @param position - The new index
137
- */
138
- BinaryReader.prototype.seekAbsolute = function (position) {
139
- this.position = position;
140
- };
141
- /**
142
- * Jumps to the given position (relative to the current postion) on the data array
143
- *
144
- * @param position - The new relative position
145
- */
146
- BinaryReader.prototype.seekRelative = function (position) {
147
- this.position += position;
148
- };
149
- /**
150
- * Reads a string
151
- *
152
- * @param length - The length in bytes to read
153
- */
154
- BinaryReader.prototype.readString = function (length) {
155
- var result = [];
156
- while (length > 0) {
157
- result.push(String.fromCharCode(this.view.getUint8(this.position++)));
158
- length--;
159
- }
160
- return result.join('');
161
- };
162
- /**
163
- * Returns a section of the buffer starting at current position
164
- *
165
- * @param length - The length to slice
166
- */
167
- BinaryReader.prototype.slice = function (length) {
168
- this.position += length;
169
- return this.data.slice(this.position - length, this.position);
170
- };
171
- BinaryReader.prototype.subarray = function (type, byteLength) {
172
- var result = new type(this.data, this.position, byteLength / type.BYTES_PER_ELEMENT);
173
- this.position += byteLength;
174
- return result;
175
- };
176
- return BinaryReader;
177
- }());
178
-
179
- /**
180
- * A wrapper around a string. Simplifies reading arbitrary formatted text data.
181
- *
182
- * @public
183
- */
184
- var TextReader = /** @class */ (function () {
185
- /**
186
- * Creates a new instance of {@link TextReader}
187
- *
188
- * @param text - The text data to read
189
- */
190
- function TextReader(text) {
191
- this.text = text;
192
- this.index = 0;
193
- /**
194
- * Characters that identify a white space. Default is `' \t\r\n\f'`.
195
- */
196
- this.whitespaces = ' \t\r\n\f';
197
- }
198
- Object.defineProperty(TextReader.prototype, "canRead", {
199
- /**
200
- * Checks whether the readers position has not reached the end of the string
201
- */
202
- get: function () {
203
- return this.index < this.text.length;
204
- },
205
- enumerable: false,
206
- configurable: true
207
- });
208
- Object.defineProperty(TextReader.prototype, "char", {
209
- /**
210
- * Gets the character at the current readers position.
211
- */
212
- get: function () {
213
- return this.text[this.index];
214
- },
215
- enumerable: false,
216
- configurable: true
217
- });
218
- Object.defineProperty(TextReader.prototype, "rest", {
219
- /**
220
- * Gets a substring until the end of the string.
221
- */
222
- get: function () {
223
- return this.text.substring(this.index);
224
- },
225
- enumerable: false,
226
- configurable: true
227
- });
228
- /**
229
- * Advances the readers position to the next character.
230
- *
231
- * @remarks
232
- * If the reader is finished reading, an empty string will be returned
233
- *
234
- * @returns the character at the new position
235
- */
236
- TextReader.prototype.next = function () {
237
- if (!this.canRead) {
238
- return '';
239
- }
240
- this.index++;
241
- return this.char;
242
- };
243
- /**
244
- * Skips whites paces at current position and then reads until next whitespace character
245
- *
246
- * @returns the string that was being read
247
- */
248
- TextReader.prototype.nextToken = function () {
249
- if (!this.canRead) {
250
- return '';
251
- }
252
- var i = this.index;
253
- this.skipWhile(this.whitespaces);
254
- this.skipUntil(this.whitespaces);
255
- this.skipWhile(this.whitespaces);
256
- return this.text.substr(i, this.index - i).trim();
257
- };
258
- /**
259
- * Reads until next occurrence of a new line character
260
- *
261
- * @param cb - on optional callback that will receive a new reader for the new line
262
- * @returns the string that was being read
263
- */
264
- TextReader.prototype.nextLine = function (cb) {
265
- if (!this.canRead) {
266
- return '';
267
- }
268
- var i = this.index;
269
- this.skipUntil('\n');
270
- this.next();
271
- var line = this.text.substr(i, this.index - i).trim();
272
- if (cb) {
273
- cb(new TextReader(line));
274
- }
275
- return line;
276
- };
277
- /**
278
- * Skips until next occurrence of `start` character and then reads the text until the `end` character
279
- *
280
- * @param start - character identifying the begin of a block
281
- * @param end - character identifying the begin of a block
282
- * @param cb - a callback to call with a new text reader
283
- */
284
- TextReader.prototype.nextBlock = function (start, end, cb) {
285
- if (!this.canRead) {
286
- return '';
287
- }
288
- this.skipUntil(start, true);
289
- var iStart = this.index;
290
- var iEnd = this.index;
291
- var depth = 1;
292
- while (this.canRead) {
293
- if (start.indexOf(this.char) >= 0) {
294
- depth++;
295
- }
296
- if (end.indexOf(this.char) >= 0) {
297
- depth--;
298
- if (depth === 0) {
299
- iEnd = this.index;
300
- this.next();
301
- break;
302
- }
303
- }
304
- this.next();
305
- }
306
- var block = this.text.substring(iStart, iEnd);
307
- if (cb) {
308
- cb(new TextReader(block));
309
- }
310
- return block;
311
- };
312
- /**
313
- * Returns the next character but does not advance the reader position.
314
- */
315
- TextReader.prototype.peek = function () {
316
- var i = this.index;
317
- var c = this.next();
318
- this.index = i;
319
- return c;
320
- };
321
- /**
322
- * Returns the next token but does not advance the reader position.
323
- */
324
- TextReader.prototype.peekToken = function () {
325
- var i = this.index;
326
- var t = this.nextToken();
327
- this.index = i;
328
- return t;
329
- };
330
- /**
331
- * Returns the current line but does not advance the reader position
332
- */
333
- TextReader.prototype.peekLine = function () {
334
- var i = this.index;
335
- var l = this.nextLine();
336
- this.index = i;
337
- return l;
338
- };
339
- /**
340
- * Skips all whitespace characters
341
- */
342
- TextReader.prototype.skipWhitespace = function () {
343
- this.skipWhile(this.whitespaces);
344
- };
345
- /**
346
- * Skips all characters in given string
347
- *
348
- * @param char - the characters to skip
349
- */
350
- TextReader.prototype.skipWhile = function (char) {
351
- while (this.canRead && char.indexOf(this.char) >= 0) {
352
- this.next();
353
- }
354
- };
355
- /**
356
- * Skips characters until occurrence of one in the given string
357
- *
358
- * @param char - the characters to stop at
359
- */
360
- TextReader.prototype.skipUntil = function (char, andBeyond) {
361
- if (andBeyond === void 0) { andBeyond = false; }
362
- while (this.canRead && char.indexOf(this.char) === -1) {
363
- this.next();
364
- }
365
- if (andBeyond) {
366
- this.skipWhile(char);
367
- }
368
- };
369
- /**
370
- * Reads the next token but throws an error if it does not match the given value
371
- *
372
- * @param value - The value to match
373
- */
374
- TextReader.prototype.consumeToken = function (value) {
375
- if (this.peekToken() !== value) {
376
- var line = (this.text.match(/\n/g) || []).length;
377
- var post = this.index - this.text.lastIndexOf('\n');
378
- throw new Error("expected token \"" + value + "\" but was \"" + this.peekToken() + "\" at " + line + ":" + post);
379
- }
380
- this.nextToken();
381
- };
382
- /**
383
- * Consumes the next token only if it matches the given value. Otherwise leaves the state untouched.
384
- */
385
- TextReader.prototype.acceptToken = function (value) {
386
- if (this.peekToken() !== value) {
387
- return false;
388
- }
389
- this.nextToken();
390
- return true;
391
- };
392
- return TextReader;
393
- }());
394
-
395
- // for explanation see:
396
- // https://www.debuggex.com/
397
- var regex = /^data:(([a-z0-9-]+\/[a-z0-9+-]+)?((;\s*([a-z0-9-]+=)?(([a-z0-9]+)|("[^"]*")))+)?)?\s*,(.*)$/;
398
- /**
399
- * Describes parts of a data Uri
400
- *
401
- * @public
402
- */
403
- var DataUri = /** @class */ (function () {
404
- function DataUri() {
405
- }
406
- /**
407
- * Checks whether a string represents a data uri
408
- *
409
- * @param uri - The Uri to check
410
- */
411
- DataUri.isDataUri = function (uri) {
412
- return regex.test(uri);
413
- };
414
- /**
415
- * Parses a uri into a data uri object
416
- *
417
- * @param uri - The Uri to parse
418
- */
419
- DataUri.parse = function (uri) {
420
- if (!DataUri.isDataUri(uri)) {
421
- return {
422
- uri: uri,
423
- contentType: undefined,
424
- isBase64: false,
425
- data: undefined,
426
- };
427
- }
428
- var match = regex.exec(uri);
429
- return {
430
- uri: uri,
431
- contentType: match[1] || 'text/plain; charset=US-ASCII',
432
- isBase64: /;\s*base64$/.test(match[1] || ''),
433
- data: match[9],
434
- };
435
- };
436
- return DataUri;
437
- }());
438
-
439
- function triggerEvents(events, args) {
440
- for (var i = 0; i < events.length; i++) {
441
- events[i].callback.apply(events[i].ctx, args);
442
- }
443
- }
444
- /**
445
- * Base class with an event system
446
- *
447
- * @remarks
448
- * Implements logic for binding and unbinding methods to and from events.
449
- * The code is taken from the {@link https://github.com/jashkenas/backbone | Backbone} project
450
- *
451
- * @public
452
- */
453
- var Events = /** @class */ (function () {
454
- function Events() {
455
- this.events = {};
456
- }
457
- /**
458
- * Bind an event to a `callback` function.
459
- *
460
- * @remarks
461
- * Passing `"all"` will bind the callback to all events fired.
462
- * @param name - The name of the event
463
- * @param callback - The function to call when the even fires
464
- * @param context - The value of 'this' inside the callback
465
- */
466
- Events.prototype.on = function (name, callback, context) {
467
- var _this = this;
468
- this.events = this.events || {};
469
- var events = this.events[name] || [];
470
- this.events[name] = events;
471
- events.push({
472
- callback: callback,
473
- context: context,
474
- ctx: context || this,
475
- });
476
- return function () { return _this.off(name, callback); };
477
- };
478
- /**
479
- * Bind an event to only be triggered a single time.
480
- *
481
- * @param name - The name of the event
482
- * @param callback - The function to call when the even fires
483
- * @param context - The value of 'this' inside the callback
484
- */
485
- Events.prototype.once = function (name, callback, context) {
486
- // tslint:disable-next-line
487
- var once = function () {
488
- if (once.called) {
489
- return;
490
- }
491
- once.called = true;
492
- once.parent.off(name, once);
493
- callback.apply(context, arguments);
494
- };
495
- once.parent = this;
496
- once._callback = callback;
497
- return this.on(name, once);
498
- };
499
- /**
500
- * Remove one or many callbacks.
501
- *
502
- * @remarks
503
- * - If `context` is null, removes all callbacks with that function.
504
- * - If `callback` is null, removes all callbacks for the event.
505
- * - If `name` is null, removes all bound callbacks for all events.
506
- *
507
- * @param name - The name of the event to unbind from
508
- * @param callback - The function to unbind
509
- * @param context - The value of 'this' inside the callback
510
- */
511
- Events.prototype.off = function (name, callback, context) {
512
- if (!this.events) {
513
- return this;
514
- }
515
- if (!name && !callback && !context) {
516
- this.events = {};
517
- return this;
518
- }
519
- for (var _i = 0, _a = Object.keys(this.events); _i < _a.length; _i++) {
520
- name = _a[_i];
521
- var events = this.events[name] || [];
522
- var retain = events.filter(function (ev) {
523
- return (callback && callback !== ev.callback && callback !== ev.callback._callback) || (context && context !== ev.context);
524
- });
525
- if (retain.length) {
526
- this.events[name] = retain;
527
- }
528
- else {
529
- delete this.events[name];
530
- }
531
- }
532
- return this;
533
- };
534
- /**
535
- * Trigger one or many events, firing all bound callbacks.
536
- *
537
- * @remarks
538
- * Callbacks are passed the same arguments as `trigger` is, apart from the event name
539
- * (unless you're listening on `"all"`, which will cause your callback to
540
- * receive the true name of the event as the first argument).
541
- *
542
- * @param name - The name of the event to trigger
543
- */
544
- Events.prototype.trigger = function (name) {
545
- var args = [];
546
- for (var _i = 1; _i < arguments.length; _i++) {
547
- args[_i - 1] = arguments[_i];
548
- }
549
- if (!this.events) {
550
- return this;
551
- }
552
- if (this.events[name]) {
553
- triggerEvents(this.events[name], args);
554
- }
555
- if (this.events.all) {
556
- triggerEvents(this.events.all, args);
557
- }
558
- return this;
559
- };
560
- return Events;
561
- }());
562
-
563
- /**
564
- * Checks whether an object is an array
565
- *
566
- * @public
567
- */
568
- var isArray = Array.isArray;
569
- /**
570
- *
571
- * @param v Checks whether an object is an ArrayBufferView
572
- */
573
- function isArrayBufferView(v) {
574
- var it = v;
575
- return it != null && it.buffer != null && it.byteLength != null && it.byteOffset != null;
576
- }
577
- var concatArray = [].concat;
578
- /**
579
- *
580
- * @public
581
- */
582
- function flattenArray(value) {
583
- return concatArray.apply([], value || []);
584
- }
585
- /**
586
- * Removes an item from given array
587
- *
588
- * @param list
589
- * @param item
590
- */
591
- function removeFromArray(list, item) {
592
- var index = list.indexOf(item);
593
- if (index >= 0) {
594
- list.splice(index, 1);
595
- return true;
596
- }
597
- return false;
598
- }
599
- /**
600
- * Adds an item to given array but only if it is not already included
601
- *
602
- * @param set - the array
603
- * @param item - the item
604
- */
605
- function addToArraySet(set, item) {
606
- var index = set.indexOf(item);
607
- if (index === -1) {
608
- set.push(item);
609
- return true;
610
- }
611
- return false;
612
- }
613
- /**
614
- * Pushes an item into the given array. If array is null, a new instance is created
615
- *
616
- * @param list - the array
617
- * @param item - the item
618
- * @returns the given array or a new instance
619
- */
620
- function append(list, item) {
621
- list = list || [];
622
- list.push(item);
623
- return list;
624
- }
625
-
626
- /**
627
- * Gets a value by key from an options object
628
- *
629
- * @public
630
- * @param options - The options object
631
- * @param key - The key to access
632
- * @param fallback - The fallback value
633
- * @returns the value behind the `key`. If the `key` is missing `fallback` is returned.
634
- */
635
- function getOption(options, key, fallback) {
636
- if (options && key in options) {
637
- return options[key];
638
- }
639
- return fallback;
640
- }
641
-
642
- var vendors = ['', 'moz', 'webkit', 'ms', 'o'];
643
- /**
644
- * @public
645
- * @param el
646
- * @param name
647
- * @param variants
648
- */
649
- function vendorProperty(el, name) {
650
- var variants = [];
651
- for (var _i = 2; _i < arguments.length; _i++) {
652
- variants[_i - 2] = arguments[_i];
653
- }
654
- for (var _a = 0, vendors_1 = vendors; _a < vendors_1.length; _a++) {
655
- var prefix = vendors_1[_a];
656
- if (prefix) {
657
- var vendorName = prefix + name[0].toUpperCase() + String(name).substr(1);
658
- if (vendorName in el) {
659
- return vendorName;
660
- }
661
- }
662
- else if (name in el) {
663
- return name.toString();
664
- }
665
- }
666
- for (var _b = 0, variants_1 = variants; _b < variants_1.length; _b++) {
667
- var variant = variants_1[_b];
668
- if (variant in el) {
669
- return variant;
670
- }
671
- }
672
- return null;
673
- }
674
- /**
675
- * @public
676
- * @param el
677
- * @param name
678
- * @param variants
679
- */
680
- function vendorEvent(el, name) {
681
- var variants = [];
682
- for (var _i = 2; _i < arguments.length; _i++) {
683
- variants[_i - 2] = arguments[_i];
684
- }
685
- var suffix = name.toString().replace(/^on/, '');
686
- for (var _a = 0, vendors_2 = vendors; _a < vendors_2.length; _a++) {
687
- var prefix = vendors_2[_a];
688
- var event_1 = 'on' + prefix + suffix;
689
- if (event_1 in el) {
690
- return event_1;
691
- }
692
- }
693
- for (var _b = 0, variants_2 = variants; _b < variants_2.length; _b++) {
694
- var variant = variants_2[_b];
695
- if (variant in el) {
696
- return variant;
697
- }
698
- }
699
- return null;
700
- }
701
- var docHidden = vendorProperty(document, 'hidden');
702
- var docVisibilityState = vendorProperty(document, 'visibilityState');
703
- var docVisibilityChange = vendorEvent(document, 'onvisibilitychange');
704
- /**
705
- * @public
706
- */
707
- var documentVisibilityApi = {
708
- /**
709
- * Checks whether the current document is hidden.
710
- * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden | Document.hidden}
711
- *
712
- * @public
713
- */
714
- get isHidden() {
715
- return getOption(document, docHidden, false);
716
- },
717
- /**
718
- * Checks whether the current document is hidden.
719
- * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden | Document.hidden}
720
- *
721
- * @public
722
- */
723
- get isVisible() {
724
- return getOption(document, docHidden, true);
725
- },
726
- /**
727
- * Gets the visibility state of current document.
728
- * See {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState | Document.visibilityState}
729
- *
730
- * @public
731
- */
732
- get visibilityState() {
733
- return getOption(document, docVisibilityState, 'visible');
734
- },
735
- /**
736
- * Adds a listener to the
737
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/onvisibilitychange | Document.onvisibilitychange}
738
- * event
739
- *
740
- * @public
741
- */
742
- onVisibilityChange: function (callback, options) {
743
- if (docVisibilityChange) {
744
- document.addEventListener(docVisibilityChange, callback, options);
745
- }
746
- },
747
- /**
748
- * Removes a listener from the
749
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/onvisibilitychange | Document.onvisibilitychange}
750
- * event
751
- *
752
- * @public
753
- */
754
- offVisibilityChange: function (callback, options) {
755
- if (docVisibilityChange) {
756
- document.removeEventListener(docVisibilityChange, callback, options);
757
- }
758
- },
759
- };
760
- /**
761
- * @public
762
- */
763
- var PointerLockApi = /** @class */ (function () {
764
- function PointerLockApi() {
765
- this.pointerlockchange = vendorEvent(document, 'pointerlockchange');
766
- this.pointerlockerror = vendorEvent(document, 'pointerlockerror');
767
- this.requestPointerLockName = vendorProperty(document, 'requestPointerLock');
768
- this.exitPointerLockName = vendorProperty(document, 'exitPointerLock');
769
- this.pointerLockElementName = vendorProperty(document, 'pointerLockElement');
770
- }
771
- Object.defineProperty(PointerLockApi.prototype, "isSupported", {
772
- get: function () {
773
- return !!this.exitPointerLockName;
774
- },
775
- enumerable: false,
776
- configurable: true
777
- });
778
- Object.defineProperty(PointerLockApi.prototype, "pointerLockElement", {
779
- get: function () {
780
- return getOption(document, this.pointerLockElementName, null);
781
- },
782
- enumerable: false,
783
- configurable: true
784
- });
785
- PointerLockApi.prototype.onChange = function (callback, options) {
786
- if (this.pointerlockchange) {
787
- document.addEventListener(this.pointerlockchange, callback, options);
788
- }
789
- };
790
- PointerLockApi.prototype.offChange = function (callback, options) {
791
- if (this.pointerlockchange) {
792
- document.removeEventListener(this.pointerlockchange, callback, options);
793
- }
794
- };
795
- PointerLockApi.prototype.onError = function (callback, options) {
796
- if (this.pointerlockerror) {
797
- document.addEventListener(this.pointerlockerror, callback, options);
798
- }
799
- };
800
- PointerLockApi.prototype.offError = function (callback, options) {
801
- if (this.pointerlockerror) {
802
- document.removeEventListener(this.pointerlockerror, callback, options);
803
- }
804
- };
805
- PointerLockApi.prototype.requestLock = function (target) {
806
- this.requestPointerLockName = this.requestPointerLockName || vendorProperty(target, 'requestPointerLock');
807
- if (this.requestPointerLockName) {
808
- target[this.requestPointerLockName]();
809
- }
810
- };
811
- PointerLockApi.prototype.exitLock = function () {
812
- if (this.exitPointerLockName) {
813
- document[this.exitPointerLockName]();
814
- }
815
- };
816
- return PointerLockApi;
817
- }());
818
-
819
- var canvas = null;
820
- /**
821
- * Extracts image data from an {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement | HTMLImageElement}
822
- *
823
- * @public
824
- */
825
- function getImageData(image, width, height) {
826
- if (!image.complete) {
827
- throw new Error('image must be completed');
828
- }
829
- canvas = canvas || document.createElement('canvas');
830
- canvas.width = width || image.naturalWidth;
831
- canvas.height = height || image.naturalHeight;
832
- var ctx = canvas.getContext('2d');
833
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
834
- var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
835
- var data = imgData.data;
836
- var result = [];
837
- result.length = data.length / 4;
838
- for (var i = 0; i < result.length; i += 1) {
839
- result[i] = data[i * 4];
840
- }
841
- return result;
842
- }
843
-
844
- /**
845
- * Gets the current timestamp. Uses performance.now() if available.
846
- *
847
- * @public
848
- */
849
- var getTime = (function () {
850
- if (window.performance && typeof window.performance.now === 'function') {
851
- return function () { return window.performance.now(); };
852
- }
853
- return function () { return Date.now(); };
854
- })();
855
- function withWindowBinding() {
856
- var names = [];
857
- for (var _i = 0; _i < arguments.length; _i++) {
858
- names[_i] = arguments[_i];
859
- }
860
- for (var _a = 0, names_1 = names; _a < names_1.length; _a++) {
861
- var name_1 = names_1[_a];
862
- if (name_1 in window) {
863
- return window[name_1].bind(window);
864
- }
865
- }
866
- return null;
867
- }
868
- /**
869
- * Browsersafe {@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame | requestAnimationFrame }
870
- * function
871
- * @public
872
- */
873
- var requestAnimationFrame = withWindowBinding('requestAnimationFrame', // prefer without wendor prefix
874
- 'mozRequestAnimationFrame', // fallback to vendor prefix
875
- 'webkitRequestAnimationFrame', 'msRequestAnimationFrame') || (function (cb) { return setTimeout(function () { return cb(getTime()); }); }); // no RAF support => usage with setTimeout
876
- /**
877
- * Browsersafe {@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame | cancelAnimationFrame }
878
- * function
879
- * @public
880
- */
881
- var cancelAnimationFrame = withWindowBinding('cancelAnimationFrame', // prefer without wendor prefix
882
- 'mozCancelAnimationFrame', // fallback to vendor prefix
883
- 'webkitCancelAnimationFrame', 'msCancelAnimationFrame', 'clearTimeout');
884
- /**
885
- * Spins the given `update` function in a loop by utilizing `requestAnimationFrame`
886
- *
887
- * @public
888
- * @remarks
889
- * A primitive loop scheduler with no fixed time support or any optimizations.
890
- * Simply schedules the given `update` function with `requestAnimationFrame`.
891
- */
892
- function loop(update) {
893
- var requestId = null;
894
- var timestamp = getTime();
895
- function tick() {
896
- var dt = getTime() - timestamp;
897
- timestamp += dt;
898
- update(timestamp, dt);
899
- requestId = requestAnimationFrame(tick);
900
- }
901
- var looper = function () {
902
- if (requestId == null) {
903
- timestamp = getTime();
904
- requestId = requestAnimationFrame(tick);
905
- }
906
- };
907
- looper.kill = function () {
908
- if (requestId != null) {
909
- cancelAnimationFrame(requestId);
910
- requestId = null;
911
- }
912
- };
913
- looper();
914
- return looper;
915
- }
916
-
917
- /**
918
- * @public
919
- */
920
- function hasOwnProperty(object, property) {
921
- return Object.prototype.hasOwnProperty.call(object, property);
922
- }
923
-
924
- /**
925
- * Checks whether a value is of type 'object' and is not an array or null
926
- *
927
- * @public
928
- */
929
- function isObject(value) {
930
- return value !== null && typeof value === 'object' && !Array.isArray(value);
931
- }
932
- /**
933
- * Picks properties from the given source object if they are not undefined
934
- *
935
- * @public
936
- */
937
- function pick(src) {
938
- var rest = [];
939
- for (var _i = 1; _i < arguments.length; _i++) {
940
- rest[_i - 1] = arguments[_i];
941
- }
942
- var result = {};
943
- for (var i = 1; i < arguments.length; i += 1) {
944
- var key = arguments[i];
945
- var value = src[key];
946
- if (value !== void 0) {
947
- result[key] = value;
948
- }
949
- }
950
- return result;
951
- }
952
- /**
953
- * Creates a copy of an object, an array or a primitive.
954
- *
955
- * @public
956
- */
957
- function copy(srcOrDeep, srcOrDest, dest) {
958
- var deep = false;
959
- var src;
960
- var dst;
961
- if (typeof srcOrDeep === 'boolean') {
962
- deep = srcOrDeep;
963
- src = srcOrDest;
964
- dst = dest;
965
- }
966
- else {
967
- deep = false;
968
- src = srcOrDeep;
969
- dst = srcOrDest;
970
- }
971
- dst = Array.isArray(src) ? [] : {};
972
- var value;
973
- var isArray;
974
- var isObj;
975
- for (var key in src) {
976
- if (hasOwnProperty(src, key)) {
977
- value = src[key];
978
- isArray = Array.isArray(value);
979
- isObj = value != null && typeof value === 'object';
980
- if (deep && value && (isArray || isObj)) {
981
- dst[key] = copy(deep, value);
982
- }
983
- else if (value !== void 0) {
984
- dst[key] = value;
985
- }
986
- }
987
- }
988
- return dst;
989
- }
990
- /**
991
- * Extends the first argument with properties of all latter arguments
992
- *
993
- * @public
994
- */
995
- function extend(dst, a, b, c, d, e, f) {
996
- var length = arguments.length;
997
- if (length < 2 || dst == null) {
998
- return dst;
999
- }
1000
- var i;
1001
- var src;
1002
- for (i = 1; i < length; i += 1) {
1003
- src = arguments[i];
1004
- for (var key in src) {
1005
- if (hasOwnProperty(src, key)) {
1006
- dst[key] = src[key];
1007
- }
1008
- }
1009
- }
1010
- return dst;
1011
- }
1012
-
1013
- /**
1014
- * Removes leading and trailing spaces of a string
1015
- *
1016
- * @public
1017
- */
1018
- function trim(value) {
1019
- return value.replace(/(^\s*|\s*$)/g, '');
1020
- }
1021
- /**
1022
- * Splits a string into lines
1023
- *
1024
- * @public
1025
- */
1026
- function getLines(value) {
1027
- return value.replace(/(\r\n)|\n/g, '\n').split('\n');
1028
- }
1029
- /**
1030
- * Checks whether a value is a string
1031
- *
1032
- * @public
1033
- */
1034
- function isString(value) {
1035
- return typeof value === 'string';
1036
- }
1037
-
1038
- /**
1039
- * A token identifying a type
1040
- *
1041
- * @public
1042
- */
1043
- var TypeToken = /** @class */ (function () {
1044
- function TypeToken(name, options) {
1045
- this.name = name;
1046
- this.factory = (options === null || options === void 0 ? void 0 : options.factory) || (function () { return {}; });
1047
- }
1048
- TypeToken.prototype.toString = function () {
1049
- return "TypeToken " + this.name;
1050
- };
1051
- return TypeToken;
1052
- }());
1053
-
1054
- /**
1055
- * Generates a random uuid string
1056
- *
1057
- * @public
1058
- */
1059
- function uuid() {
1060
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
1061
- var r = Math.random() * 16 | 0; // tslint:disable-line
1062
- var v = c == 'x' ? r : (r & 0x3 | 0x8); // tslint:disable-line
1063
- return v.toString(16);
1064
- });
1065
- }
1066
-
1067
- /**
1068
- * Gets a canvas element by a CSS selector or creates a new instance of HTMLCanvasElement
1069
- *
1070
- * @public
1071
- */
1072
- function getOrCreateCanvas(canvas) {
1073
- if (canvas instanceof HTMLCanvasElement) {
1074
- return canvas;
1075
- }
1076
- if (isString(canvas)) {
1077
- var element = document.getElementById(canvas) || document.querySelector(canvas);
1078
- if (element instanceof HTMLCanvasElement) {
1079
- return element;
1080
- }
1081
- else {
1082
- throw new Error("expected '" + canvas + "' to select a HTMLCanvasElement but got '" + element + "'");
1083
- }
1084
- }
1085
- return document.createElement('canvas');
1086
- }
1087
-
1088
- function setXhrHeaders(xhr, headers) {
1089
- if (!headers) {
1090
- return;
1091
- }
1092
- for (var key in headers) {
1093
- if (hasOwnProperty(headers, key)) {
1094
- xhr.setRequestHeader(key, headers[key]);
1095
- }
1096
- }
1097
- }
1098
- function sendXhr(xhr, options, async) {
1099
- return new Promise(function (resolve, reject) {
1100
- var complete = function () {
1101
- if (200 <= xhr.status && xhr.status < 400) {
1102
- resolve(xhr);
1103
- }
1104
- else {
1105
- reject(xhr);
1106
- }
1107
- };
1108
- if (!async) {
1109
- xhr.send(options.data);
1110
- complete();
1111
- return;
1112
- }
1113
- xhr.onreadystatechange = function () {
1114
- if (xhr.readyState === XMLHttpRequest.DONE) {
1115
- complete();
1116
- }
1117
- };
1118
- xhr.send(options.data);
1119
- });
1120
- }
1121
- /**
1122
- * Creates and send an XMLHttpRequest
1123
- *
1124
- * @public
1125
- * @param options - Request options
1126
- */
1127
- function httpRequest(options) {
1128
- var async = options.async === false ? false : true;
1129
- var xhr = options.xhr || new XMLHttpRequest();
1130
- xhr.open(options.type || 'GET', options.url, async, options.username, options.password);
1131
- setXhrHeaders(xhr, options.headers);
1132
- return sendXhr(xhr, options, async);
1133
- }
1134
- /**
1135
- * @public
1136
- */
1137
- var Http = {
1138
- createXMLHttpRequest: function (responseType) {
1139
- if (responseType === void 0) { responseType = 'text'; }
1140
- var result = new XMLHttpRequest();
1141
- result.responseType = responseType;
1142
- return result;
1143
- },
1144
- request: httpRequest,
1145
- };
1146
-
1147
- /*! *****************************************************************************
1148
- Copyright (c) Microsoft Corporation.
1149
-
1150
- Permission to use, copy, modify, and/or distribute this software for any
1151
- purpose with or without fee is hereby granted.
1152
-
1153
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1154
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1155
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1156
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1157
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1158
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1159
- PERFORMANCE OF THIS SOFTWARE.
1160
- ***************************************************************************** */
1161
-
1162
- function __awaiter(thisArg, _arguments, P, generator) {
1163
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1164
- return new (P || (P = Promise))(function (resolve, reject) {
1165
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1166
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1167
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1168
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1169
- });
1170
- }
1171
-
1172
- function __generator(thisArg, body) {
1173
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1174
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1175
- function verb(n) { return function (v) { return step([n, v]); }; }
1176
- function step(op) {
1177
- if (f) throw new TypeError("Generator is already executing.");
1178
- while (_) try {
1179
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1180
- if (y = 0, t) op = [op[0] & 2, t.value];
1181
- switch (op[0]) {
1182
- case 0: case 1: t = op; break;
1183
- case 4: _.label++; return { value: op[1], done: false };
1184
- case 5: _.label++; y = op[1]; op = [0]; continue;
1185
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
1186
- default:
1187
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1188
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1189
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1190
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1191
- if (t[2]) _.ops.pop();
1192
- _.trys.pop(); continue;
1193
- }
1194
- op = body.call(thisArg, _);
1195
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1196
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1197
- }
1198
- }
1199
-
1200
- /** @deprecated */
1201
- function __spreadArrays() {
1202
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1203
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
1204
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
1205
- r[k] = a[j];
1206
- return r;
1207
- }
1208
-
1209
- function bindConsoleFn(key) {
1210
- if (globalThis.console && key in console) {
1211
- return console[key].bind(console);
1212
- }
1213
- return function () { return null; };
1214
- }
1215
- var EnabledLogger = {
1216
- log: bindConsoleFn('log'),
1217
- info: bindConsoleFn('info'),
1218
- debug: bindConsoleFn('debug'),
1219
- warn: bindConsoleFn('warn'),
1220
- error: bindConsoleFn('error'),
1221
- group: bindConsoleFn('group'),
1222
- groupCollapsed: bindConsoleFn('groupCollapsed'),
1223
- groupEnd: bindConsoleFn('groupEnd'),
1224
- };
1225
- var DisabledLogger = {
1226
- log: function () { return (void 0); },
1227
- info: function () { return (void 0); },
1228
- debug: function () { return (void 0); },
1229
- warn: function () { return (void 0); },
1230
- error: function () { return (void 0); },
1231
- group: function () { return (void 0); },
1232
- groupCollapsed: function () { return (void 0); },
1233
- groupEnd: function () { return (void 0); },
1234
- };
1235
- /**
1236
- * @public
1237
- */
1238
- var Log = {
1239
- /**
1240
- * Disables this logger. No log will be printed to console.
1241
- */
1242
- disable: function () {
1243
- Object.assign(Log, DisabledLogger);
1244
- },
1245
- /**
1246
- * Enables this logger. Logs will be printed to console
1247
- */
1248
- enable: function () {
1249
- Object.assign(Log, EnabledLogger);
1250
- },
1251
- log: bindConsoleFn('log'),
1252
- info: bindConsoleFn('info'),
1253
- debug: bindConsoleFn('debug'),
1254
- warn: bindConsoleFn('warn'),
1255
- error: bindConsoleFn('error'),
1256
- group: bindConsoleFn('group'),
1257
- groupCollapsed: bindConsoleFn('groupCollapsed'),
1258
- groupEnd: bindConsoleFn('groupEnd'),
1259
- /**
1260
- * Calls the function and automatically closes the log group after the result has been resolved
1261
- */
1262
- groupEndAsync: function (fn) {
1263
- var groupEnded = false;
1264
- return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
1265
- return __generator(this, function (_a) {
1266
- Promise.resolve(fn()).then(function (result) {
1267
- if (!groupEnded) {
1268
- groupEnded = true;
1269
- Log.groupEnd();
1270
- }
1271
- resolve(result);
1272
- }).catch(function (err) {
1273
- if (!groupEnded) {
1274
- groupEnded = true;
1275
- Log.groupEnd();
1276
- }
1277
- reject(err);
1278
- });
1279
- return [2 /*return*/];
1280
- });
1281
- }); });
1282
- }
1283
- };
1284
-
1285
- // source: https://github.com/nodejs/node/blob/master/lib/path.js
1286
- var pathSplit = /^(\/?|[\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
1287
- // source: http://blog.stevenlevithan.com/archives/parseuri
1288
- var options = {
1289
- key: [
1290
- 'source',
1291
- 'protocol',
1292
- 'authority',
1293
- 'userInfo',
1294
- 'user',
1295
- 'password',
1296
- 'host',
1297
- 'port',
1298
- 'relative',
1299
- 'path',
1300
- 'directory',
1301
- 'file',
1302
- 'query',
1303
- 'anchor',
1304
- ],
1305
- q: {
1306
- name: 'queryKey',
1307
- parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
1308
- },
1309
- parser: {
1310
- // tslint:disable
1311
- strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
1312
- loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
1313
- // tslint:enable
1314
- },
1315
- };
1316
- function isAbsolute(path) {
1317
- return !!path && path[0] === '/';
1318
- }
1319
- function hasProtocol(path) {
1320
- return !!path && !!path.match(/^[a-zA-Z]+:\/\//i);
1321
- }
1322
- function collapse(path) {
1323
- var wasAbsolute = isAbsolute(path);
1324
- var parts = [];
1325
- for (var _i = 0, _a = path.split(/\//); _i < _a.length; _i++) {
1326
- var token = _a[_i];
1327
- if (!token || token === '.') {
1328
- continue;
1329
- }
1330
- if (token === '..') {
1331
- parts.pop();
1332
- }
1333
- else {
1334
- parts.push(token);
1335
- }
1336
- }
1337
- var result = parts.join('/');
1338
- if (wasAbsolute) {
1339
- result = "/" + result;
1340
- }
1341
- return result;
1342
- }
1343
- /**
1344
- * @public
1345
- */
1346
- var Uri = /** @class */ (function () {
1347
- function Uri() {
1348
- }
1349
- /**
1350
- * Parses a string and extracts all uri components
1351
- */
1352
- Uri.parse = function (path, strict) {
1353
- if (strict === void 0) { strict = true; }
1354
- var o = options;
1355
- var m = o.parser[strict ? 'strict' : 'loose'].exec(path);
1356
- var uri = new Uri();
1357
- var i = 14;
1358
- while (i--) {
1359
- uri[o.key[i]] = m[i] || '';
1360
- }
1361
- uri[o.q.name] = {};
1362
- uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
1363
- if ($1) {
1364
- uri[o.q.name][$1] = $2;
1365
- }
1366
- });
1367
- return uri;
1368
- };
1369
- Uri.dir = function (path) {
1370
- return Uri.parse(path).directory;
1371
- };
1372
- Uri.file = function (path) {
1373
- return pathSplit.exec(path)[2];
1374
- };
1375
- Uri.ext = function (path) {
1376
- return pathSplit.exec(path)[3];
1377
- };
1378
- Uri.merge = function (a, b) {
1379
- if (hasProtocol(b)) {
1380
- return b;
1381
- }
1382
- var aUri = Uri.parse(a);
1383
- var bUri = Uri.parse(b);
1384
- var path = isAbsolute(b) ? b : aUri.directory + bUri.path;
1385
- path = collapse(path);
1386
- if (bUri.query) {
1387
- path += "?" + bUri.query;
1388
- }
1389
- if (bUri.anchor) {
1390
- path += "#" + bUri.anchor;
1391
- }
1392
- var result = '';
1393
- if (aUri.protocol) {
1394
- result = aUri.protocol + '://';
1395
- }
1396
- if (aUri.authority) {
1397
- result += aUri.authority;
1398
- }
1399
- if (!isAbsolute(path)) {
1400
- result += '/';
1401
- }
1402
- return result + path;
1403
- };
1404
- Uri.escape = function (fragment) {
1405
- if (fragment.length > 1) {
1406
- return fragment[0] + fragment.substring(1).replace(/[!"#$%&'()*+,-.\/\\:;<=>?@\[\]^`{|}~]/gi, function (token) { return "\\" + token; });
1407
- }
1408
- return fragment;
1409
- };
1410
- return Uri;
1411
- }());
1412
-
1413
- var workers = [];
1414
- var tasks = new Map();
1415
- var requestCounter = 0;
1416
- /**
1417
- * Provides a mechanism for registering functions as background tasks which can be executed on a worker thread
1418
- *
1419
- * @public
1420
- * @remarks
1421
- * The class is a wrapper around the {@link https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker | Web Worker Api}.
1422
- *
1423
- * To enable the functionality it is required that the `workerUrl` is set and points to
1424
- * a worker script which should run in the worker thread.
1425
- *
1426
- * Functions that should run on the worker thread may be registered at any time, before or after
1427
- * the functionality is enabled.
1428
- *
1429
- * It is important that this class and the registry of background tasks are all bundled
1430
- * in the application bundle as well as in the worker bundle
1431
- *
1432
- * @example
1433
- * ```ts
1434
- * const myTask = WebWorker.task("myBackgroundTask", () => {
1435
- * // do heavy things
1436
- * })
1437
- *
1438
- * WebWorker.enable('http://example.com/gglib.umd.js')
1439
- *
1440
- * myTask() // will run on a worker thread
1441
- * WebWorker.exec("myBackgroundTask") // same task as above
1442
- *
1443
- * WebWorker.disable() // disables webworker functionality
1444
- * myTask() // will run on main thread
1445
- * WebWorker.exec("myBackgroundTask") // same task as above
1446
- * ```
1447
- */
1448
- var WebWorker = /** @class */ (function () {
1449
- function WebWorker(script) {
1450
- this.handler = new Map();
1451
- this.worker = new Worker(script);
1452
- this.worker.onmessage = this.handleMessage.bind(this);
1453
- this.worker.onerror = function (e) { return Log.error(e); };
1454
- }
1455
- /**
1456
- * Enables a webworker and limits to the number of threads
1457
- *
1458
- * @public
1459
- * @param workerCount - Total number of workers to activate
1460
- */
1461
- WebWorker.enable = function (workerUrl, workerCount) {
1462
- if (workerCount === void 0) { workerCount = 1; }
1463
- if (!WebWorker.isSupported || WebWorker.isWorkerContext) {
1464
- return false;
1465
- }
1466
- WebWorker.disable();
1467
- while (workerCount > 0) {
1468
- workers.push(new WebWorker(workerUrl));
1469
- }
1470
- return true;
1471
- };
1472
- /**
1473
- * Disables a webworker script
1474
- *
1475
- * @remarks if `script` is not given all webworker are disabled
1476
- *
1477
- * @public
1478
- */
1479
- WebWorker.disable = function () {
1480
- while (workers.length) {
1481
- workers.pop().terminate();
1482
- }
1483
- };
1484
- /**
1485
- * Registers a named function that can be executed in a webworker thread
1486
- *
1487
- * @public
1488
- *
1489
- * @param name - The task name
1490
- * @param action - The task action
1491
- * @param thread - The worker index on which the action should be executed
1492
- */
1493
- WebWorker.task = function (name, action, thread) {
1494
- if (thread === void 0) { thread = 0; }
1495
- if (tasks.has(name)) {
1496
- Promise.reject("Task '" + name + "' is already defined");
1497
- }
1498
- tasks.set(name, {
1499
- name: name,
1500
- action: action,
1501
- thread: thread,
1502
- });
1503
- return function () {
1504
- var params = [];
1505
- for (var _i = 0; _i < arguments.length; _i++) {
1506
- params[_i] = arguments[_i];
1507
- }
1508
- return WebWorker.exec.apply(WebWorker, __spreadArrays([name], params));
1509
- };
1510
- };
1511
- /**
1512
- * Executes a task that has been previously registered with the `task` method.
1513
- *
1514
- * @public
1515
- * @remarks
1516
- * This will execute a registered task in a web worker thread. If web workers
1517
- * are disabled then the task will be executed in the browser thread instead.
1518
- */
1519
- WebWorker.exec = function (method) {
1520
- var _a;
1521
- var params = [];
1522
- for (var _i = 1; _i < arguments.length; _i++) {
1523
- params[_i - 1] = arguments[_i];
1524
- }
1525
- if (!tasks.has(method)) {
1526
- return Promise.reject(new Error("Task '" + method + "' not found"));
1527
- }
1528
- var task = tasks.get(method);
1529
- var worker = workers[task.thread] || workers[0];
1530
- if (!worker) {
1531
- return Promise.resolve((_a = task.action).call.apply(_a, __spreadArrays([{}], params)));
1532
- }
1533
- return worker.postMessage({
1534
- method: task.name,
1535
- params: params,
1536
- id: requestCounter++,
1537
- });
1538
- };
1539
- WebWorker.prototype.terminate = function () {
1540
- this.worker.terminate();
1541
- };
1542
- WebWorker.prototype.postMessage = function (request) {
1543
- var _this = this;
1544
- request.id = request.id || requestCounter++;
1545
- if (this.handler.has(request.id)) {
1546
- return Promise.reject("A request with same id '" + request.id + "' is already running");
1547
- }
1548
- return new Promise(function (resolve, reject) {
1549
- _this.handler.set(request.id, function (e) {
1550
- _this.handler.delete(request.id);
1551
- if (e.error) {
1552
- reject(e.error);
1553
- }
1554
- else {
1555
- resolve(e.result);
1556
- }
1557
- });
1558
- _this.worker.postMessage(request);
1559
- });
1560
- };
1561
- WebWorker.prototype.handleMessage = function (message) {
1562
- if (!('data' in message) || !message.data) {
1563
- return;
1564
- }
1565
- var data = message.data;
1566
- if (!('id' in data)) {
1567
- return;
1568
- }
1569
- var id = data.id;
1570
- var handle = this.handler.get(id);
1571
- if (handle) {
1572
- handle(data);
1573
- }
1574
- };
1575
- /**
1576
- * Determines whether this context is inside a web worker
1577
- *
1578
- * @public
1579
- */
1580
- WebWorker.isWorkerContext = typeof self['importScripts'] === 'function';
1581
- /**
1582
- * Determines whether this context is inside a browser window
1583
- *
1584
- * @public
1585
- */
1586
- WebWorker.isWindowContext = typeof self['importScripts'] !== 'function';
1587
- /**
1588
- * Determines whether web porker api is supported
1589
- *
1590
- * @public
1591
- */
1592
- WebWorker.isSupported = typeof Worker !== 'undefined';
1593
- return WebWorker;
1594
- }());
1595
- if (WebWorker.isWorkerContext) {
1596
- var worker_1 = globalThis;
1597
- addEventListener('message', function (message) {
1598
- if (!('data' in message) || !message.data) {
1599
- return; // not for us
1600
- }
1601
- var data = message.data;
1602
- var task = tasks.get(data.method);
1603
- if (!task) {
1604
- return; // not for us
1605
- }
1606
- Promise.resolve()
1607
- .then(function () { return task.action.apply({}, data.params); })
1608
- .then(function (result) {
1609
- return {
1610
- id: data.id,
1611
- result: result,
1612
- error: null,
1613
- };
1614
- })
1615
- .catch(function (e) {
1616
- return {
1617
- id: data.id,
1618
- result: null,
1619
- error: e,
1620
- };
1621
- })
1622
- .then(function (response) { return worker_1.postMessage(response); });
1623
- });
1624
- }
1625
-
1626
- exports.BinaryReader = BinaryReader;
1627
- exports.DataUri = DataUri;
1628
- exports.Events = Events;
1629
- exports.Http = Http;
1630
- exports.Log = Log;
1631
- exports.PointerLockApi = PointerLockApi;
1632
- exports.TextReader = TextReader;
1633
- exports.TypeToken = TypeToken;
1634
- exports.Uri = Uri;
1635
- exports.WebWorker = WebWorker;
1636
- exports.addToArraySet = addToArraySet;
1637
- exports.append = append;
1638
- exports.cancelAnimationFrame = cancelAnimationFrame;
1639
- exports.copy = copy;
1640
- exports.documentVisibilityApi = documentVisibilityApi;
1641
- exports.extend = extend;
1642
- exports.flattenArray = flattenArray;
1643
- exports.getImageData = getImageData;
1644
- exports.getLines = getLines;
1645
- exports.getOption = getOption;
1646
- exports.getOrCreateCanvas = getOrCreateCanvas;
1647
- exports.getTime = getTime;
1648
- exports.hasOwnProperty = hasOwnProperty;
1649
- exports.httpRequest = httpRequest;
1650
- exports.isArray = isArray;
1651
- exports.isArrayBufferView = isArrayBufferView;
1652
- exports.isObject = isObject;
1653
- exports.isString = isString;
1654
- exports.loop = loop;
1655
- exports.pick = pick;
1656
- exports.removeFromArray = removeFromArray;
1657
- exports.requestAnimationFrame = requestAnimationFrame;
1658
- exports.trim = trim;
1659
- exports.uuid = uuid;
1660
- exports.vendorEvent = vendorEvent;
1661
- exports.vendorProperty = vendorProperty;
1662
-
1663
- Object.defineProperty(exports, '__esModule', { value: true });
1664
-
1665
- })));
1666
- //# sourceMappingURL=utils.umd.js.map