forked from BrainJS/brain.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.min.js
468 lines (364 loc) · 436 KB
/
browser.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/**
* Modules in this bundle
* @license
*
* brain.js:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Heather Arthur <[email protected]>
* homepage: https://github.com/brainjs/brain.js#readme
* version: 1.6.1
*
* acorn:
* license: MIT (http://opensource.org/licenses/MIT)
* maintainers: Marijn Haverbeke <[email protected]>, Ingvar Stepanyan <[email protected]>, Adrian Heine <http://adrianheine.de>
* homepage: https://github.com/acornjs/acorn
* version: 5.7.2
*
* base64-js:
* license: MIT (http://opensource.org/licenses/MIT)
* author: T. Jameson Little <[email protected]>
* homepage: https://github.com/beatgammit/base64-js
* version: 1.3.0
*
* buffer:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Feross Aboukhadijeh <[email protected]>
* contributors: Romain Beauxis <[email protected]>, James Halliday <[email protected]>
* homepage: https://github.com/feross/buffer
* version: 4.9.1
*
* core-util-is:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Isaac Z. Schlueter <[email protected]> (http://blog.izs.me/)
* version: 1.0.2
*
* events:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com)
* version: 1.1.1
*
* gpu.js:
* license: MIT (http://opensource.org/licenses/MIT)
* author: The gpu.js Team
* homepage: http://gpu.rocks/
* version: 1.10.4
*
* ieee754:
* license: BSD-3-Clause (http://opensource.org/licenses/BSD-3-Clause)
* author: Feross Aboukhadijeh <[email protected]>
* contributors: Romain Beauxis <[email protected]>
* version: 1.1.12
*
* inherits:
* license: ISC (http://opensource.org/licenses/ISC)
* version: 2.0.3
*
* isarray:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Julian Gruber <[email protected]>
* homepage: https://github.com/juliangruber/isarray
* version: 1.0.0
*
* process:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Roman Shtylman <[email protected]>
* version: 0.11.10
*
* process-nextick-args:
* license: MIT (http://opensource.org/licenses/MIT)
* homepage: https://github.com/calvinmetcalf/process-nextick-args
* version: 2.0.0
*
* readable-stream:
* license: MIT (http://opensource.org/licenses/MIT)
* version: 2.3.6
*
* safe-buffer:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Feross Aboukhadijeh <[email protected]>
* homepage: https://github.com/feross/safe-buffer
* version: 5.1.2
*
* stream-browserify:
* license: MIT (http://opensource.org/licenses/MIT)
* author: James Halliday <[email protected]>
* homepage: https://github.com/substack/stream-browserify
* version: 2.0.1
*
* string_decoder:
* license: MIT (http://opensource.org/licenses/MIT)
* homepage: https://github.com/nodejs/string_decoder
* version: 1.1.1
*
* thaw.js:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Robert Lee Plummer Jr. <[email protected]>
* homepage: https://github.com/robertleeplummerjr/thaw.js#readme
* version: 2.0.0
*
* timers-browserify:
* licenses: MIT (http://opensource.org/licenses/MIT)
* author: J. Ryan Stinnett <[email protected]> (http://convolv.es/)
* contributors: Guy Bedford <[email protected]>, Ionut-Cristian Florescu <[email protected]>, James Halliday <[email protected]>, Jan Schär <[email protected]>, Johannes Ewald <[email protected]>, Jonathan Prins <[email protected]>, Matt Esch <[email protected]>
* homepage: https://github.com/jryans/timers-browserify
* version: 1.4.2
*
* util-deprecate:
* license: MIT (http://opensource.org/licenses/MIT)
* author: Nathan Rajlich <[email protected]> (http://n8.io/)
* homepage: https://github.com/TooTallNate/util-deprecate
* version: 1.0.2
*
* This header is generated by licensify (https://github.com/twada/licensify)
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.brain = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),CrossValidate=function(){function e(r,t){_classCallCheck(this,e),this.Classifier=r,this.options=t,this.json=null}return _createClass(e,[{key:"testPartition",value:function(e,r,t){var n=new this.Classifier(this.options),s=Date.now(),o=n.train(r,e),a=Date.now(),i=n.test(t),l=Date.now();return Object.assign({},i,{trainTime:a-s,testTime:l-a,iterations:o.iterations,error:o.error,total:i.total,learningRate:n.trainOpts.learningRate,hiddenLayers:n.hiddenLayers,network:n.toJSON()})}},{key:"shuffleArray",value:function(e){for(var r=e.length-1;r>0;r--){var t=Math.floor(Math.random()*(r+1)),n=e[r];e[r]=e[t],e[t]=n}return e}},{key:"train",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:4;if(e.length<t)throw new Error("Training set size is too small for "+e.length+" k folds of "+t);var n=e.length/t;if(e.constructor===Array)this.shuffleArray(e);else{var s={};this.shuffleArray(Object.keys(e)).forEach(function(r){s[r]=e[r]}),e=s}for(var o={trainTime:0,testTime:0,iterations:0,error:0},a={total:0},i={total:0,truePos:0,trueNeg:0,falsePos:0,falseNeg:0},l=[],u=void 0,f=null,c=0;c<t;c++){var h=e.slice(0),v=h.splice(c*n,n),y=h,g=this.testPartition(r,y,v);null===f&&(f=g.hasOwnProperty("falseNeg")&&g.hasOwnProperty("falsePos")&&g.hasOwnProperty("trueNeg")&&g.hasOwnProperty("truePos"))&&Object.assign(a,i);for(u in o)u in o&&(o[u]+=g[u]);for(u in a)u in a&&(a[u]+=g[u]);l.push(g)}for(u in o)u in o&&(o[u]/=t);return f&&(a.precision=a.truePos/(a.truePos+a.falsePos),a.recall=a.truePos/(a.truePos+a.falseNeg),a.accuracy=(a.trueNeg+a.truePos)/a.total),a.testSize=n,a.trainSize=e.length-n,this.json={avgs:o,stats:a,sets:l}}},{key:"toNeuralNetwork",value:function(){return this.fromJSON(this.json)}},{key:"toJSON",value:function(){return this.json}},{key:"fromJSON",value:function(e){var r=this.Classifier,t=e.sets.reduce(function(e,r){return e.error<r.error?e:r},{error:1/0}).network;if(r.fromJSON)return r.fromJSON(t);var n=new r;return n.fromJSON(t),n}}]),e}();exports.default=CrossValidate;
},{}],2:[function(require,module,exports){
"use strict";function likely(e,r){var l=r.run(e),t=null,u=-1;for(var n in l){var i=l[n];i>u&&(t=n,u=i)}return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=likely;
},{}],3:[function(require,module,exports){
"use strict";function _classCallCheck(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},_createClass=function(){function r(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}return function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}(),lookup=function(){function r(){_classCallCheck(this,r)}return _createClass(r,null,[{key:"toTable",value:function(e){var t=e.reduce(function(r,e){return Object.assign(r,e)},{});return r.toHash(t)}},{key:"toTable2D",value:function(r){for(var e={},t=0,n=0;n<r.length;n++)for(var o=r[n],a=0;a<o.length;a++){var u=o[a];for(var f in u)u.hasOwnProperty(f)&&!e.hasOwnProperty(f)&&(e[f]=t++)}return e}},{key:"toInputTable",value:function(r){for(var e={},t=0,n=0;n<r.length;n++)for(var o in r[n].input)e.hasOwnProperty(o)||(e[o]=t++);return e}},{key:"toInputTable2D",value:function(r){for(var e={},t=0,n=0;n<r.length;n++)for(var o=r[n].input,a=0;a<o.length;a++){var u=o[a];for(var f in u)e.hasOwnProperty(f)||(e[f]=t++)}return e}},{key:"toOutputTable",value:function(r){for(var e={},t=0,n=0;n<r.length;n++)for(var o in r[n].output)e.hasOwnProperty(o)||(e[o]=t++);return e}},{key:"toOutputTable2D",value:function(r){for(var e={},t=0,n=0;n<r.length;n++)for(var o=r[n].output,a=0;a<o.length;a++){var u=o[a];for(var f in u)e.hasOwnProperty(f)||(e[f]=t++)}return e}},{key:"toHash",value:function(r){var e={},t=0;for(var n in r)e[n]=t++;return e}},{key:"toArray",value:function(r,e,t){var n=new Float32Array(t);for(var o in r)n[r[o]]=e.hasOwnProperty(o)?e[o]:0;return n}},{key:"toArrayShort",value:function(r,e){var t=[];for(var n in r){if(!e.hasOwnProperty(n))break;t[r[n]]=e[n]}return Float32Array.from(t)}},{key:"toArrays",value:function(r,e,t){for(var n=[],o=0;o<e.length;o++)n.push(this.toArray(r,e[o],t));return n}},{key:"toObject",value:function(r,e){var t={};for(var n in r)t[n]=e[r[n]];return t}},{key:"toObjectPartial",value:function(r,e){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o={},a=0;for(var u in r)t>0&&a++<t||n>0&&a++>=n||(o[u]=e[r[u]-t]);return o}},{key:"lookupFromArray",value:function(r){for(var e={},t=0,n=r.length;n-- >0;)e[r[n]]=t++;return e}},{key:"dataShape",value:function(r){var e=[];r.input?(e.push("datum"),r=r.input):Array.isArray(r)&&(r[0].input?(e.push("array","datum"),r=r[0].input):(e.push("array"),r=r[0]));for(var t=void 0;r;){for(t in r)break;if(!r.hasOwnProperty(t))break;if(Array.isArray(r)||r.buffer instanceof ArrayBuffer)e.push("array"),r=r[t];else{if("object"!==(void 0===r?"undefined":_typeof(r)))throw new Error("unhandled signature");e.push("object"),r=r[t]}}return e.push(void 0===r?"undefined":_typeof(r)),e}},{key:"addKeys",value:function(r,e){if(!Array.isArray(r)){e=e||{};var t=Object.keys(e).length;for(var n in r)r.hasOwnProperty(n)&&(e.hasOwnProperty(n)||(e[n]=t++));return e}}}]),r}();exports.default=lookup;
},{}],4:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function weightedSumSigmoid(t,e,a){for(var r=e[this.thread.x],s=0;s<this.constants.size;s++)r+=t[this.thread.x][s]*a[s];return 1/(1+Math.exp(-r))}function weightedSumRelu(t,e,a){for(var r=e[this.thread.x],s=0;s<this.constants.size;s++)r+=t[this.thread.x][s]*a[s];return r<0?0:r}function weightedSumLeakyRelu(t,e,a){for(var r=e[this.thread.x],s=0;s<this.constants.size;s++)r+=t[this.thread.x][s]*a[s];return r<0?0:.01*r}function weightedSumTanh(t,e,a){for(var r=e[this.thread.x],s=0;s<this.constants.size;s++)r+=t[this.thread.x][s]*a[s];return Math.tanh(r)}function calcErrorOutput(t,e){return e[this.thread.x]-t}function calcDeltasSigmoid(t,e){return t*e*(1-e)}function calcDeltasRelu(t,e){return e>0?t:0}function calcDeltasLeakyRelu(t,e){return e>0?t:.01*t}function calcDeltasTanh(t,e){return(1-e*e)*t}function calcError(t,e){for(var a=0,r=0;r<this.constants.size;r++)a+=e[r]*t[r][this.thread.x];return a}function calcChanges(t,e,a){return this.constants.learningRate*e[this.thread.y]*a[this.thread.x]+this.constants.momentum*t[this.thread.y][this.thread.x]}function addWeights(t,e){return t+e[this.thread.y][this.thread.x]}function addBiases(t,e){return t[this.thread.x]+e[this.thread.x]*this.constants.learningRate}function mse(t){for(var e=0,a=0;a<this.constants.size;a++)e+=Math.pow(t[a],2);return e/this.constants.size}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var a=0;a<e.length;a++){var r=e[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,a,r){return a&&t(e.prototype,a),r&&t(e,r),e}}(),_get=function t(e,a,r){null===e&&(e=Function.prototype);var s=Object.getOwnPropertyDescriptor(e,a);if(void 0===s){var i=Object.getPrototypeOf(e);return null===i?void 0:t(i,a,r)}if("value"in s)return s.value;var u=s.get;if(void 0!==u)return u.call(r)},_neuralNetwork=require("./neural-network"),_neuralNetwork2=_interopRequireDefault(_neuralNetwork),_lookup=require("./lookup"),_lookup2=_interopRequireDefault(_lookup),_gpu=require("gpu.js"),_gpu2=_interopRequireDefault(_gpu),NeuralNetworkGPU=function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,e);var a=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return a.forwardPropagate=[],a.backwardPropagate=[],a.changesPropagate=[],a.biasesPropagate=[],a.biasCopies=[],a.copyBias=[],a.changesCopies=[],a.copyChanges=[],a.weightsCopies=[],a.copyWeights=[],a.errorCheckInterval=100,a.gpu=new _gpu2.default({mode:t.mode}),a}return _inherits(e,t),_createClass(e,[{key:"initialize",value:function(){_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"initialize",this).call(this),this.buildRunInput(),this.buildCalculateDeltas(),this.buildGetChanges(),this.buildChangeBiases(),this.buildGetMSE()}},{key:"setActivation",value:function(){}},{key:"trainPattern",value:function(t,e){return this.runInput(t.input),this.calculateDeltas(t.output),this.adjustWeights(),e?this.getMSE(this.errors[this.outputLayer])[0]:null}},{key:"adjustWeights",value:function(){this.getChanges(),this.changeBiases()}},{key:"buildRunInput",value:function(){var t=null;switch(this.activation){case"sigmoid":t=weightedSumSigmoid;break;case"relu":t=weightedSumRelu;break;case"leaky-relu":t=weightedSumLeakyRelu;break;case"tanh":t=weightedSumTanh;break;default:throw new Error("unknown activation "+this.activation)}for(var e=1;e<=this.outputLayer;e++)this.forwardPropagate[e]=this.gpu.createKernel(t,{output:[this.sizes[e]],outputToTexture:!0,hardcodeConstants:!0,constants:{size:this.sizes[e-1]}});this.texturizeInputData=this.gpu.createKernel(function(t){return t[this.thread.x]},{output:[this.sizes[1]],outputToTexture:!0,hardcodeConstants:!0,outputImmutable:!0})}},{key:"runInput",value:function(t){var e=void 0;this.outputs[0]=t;for(var a=1;a<=this.outputLayer;a++)this.outputs[a]=this.forwardPropagate[a](this.weights[a],this.biases[a],t),e=t=this.outputs[a];return e}},{key:"buildCalculateDeltas",value:function(){var t=null;switch(this.activation){case"sigmoid":t=calcDeltasSigmoid;break;case"relu":t=calcDeltasRelu;break;case"leaky-relu":t=calcDeltasLeakyRelu;break;case"tanh":t=calcDeltasTanh;break;default:throw new Error("unknown activation "+this.activation)}for(var e=this.outputLayer;e>0;e--)e===this.outputLayer?this.backwardPropagate[e]=this.gpu.createKernelMap({error:_gpu2.default.alias("calcErrorOutput",calcErrorOutput),deltas:_gpu2.default.alias("calcDeltas",t)},function(e,a){var r=e[this.thread.x];return t(calcErrorOutput(r,a),r)},{output:[this.sizes[e]],outputToTexture:!0,hardcodeConstants:!0}):this.backwardPropagate[e]=this.gpu.createKernelMap({error:_gpu2.default.alias("calcError",calcError),deltas:_gpu2.default.alias("calcDeltas",t)},function(e,a,r){var s=a[this.thread.x];return t(calcError(e,r),s)},{output:[this.sizes[e]],outputToTexture:!0,hardcodeConstants:!0,constants:{size:this.deltas[e+1].length}})}},{key:"calculateDeltas",value:function(t){for(var e=this.outputLayer;e>0;e--){var a=void 0;a=e===this.outputLayer?this.backwardPropagate[e](this.outputs[e],t):this.backwardPropagate[e](this.weights[e+1],this.outputs[e],this.deltas[e+1]),this.deltas[e]=a.deltas,this.errors[e]=a.error}}},{key:"buildGetChanges",value:function(){for(var t=1;t<=this.outputLayer;t++)this.changesPropagate[t]=this.gpu.createKernelMap({weights:_gpu2.default.alias("addWeights",addWeights),changes:_gpu2.default.alias("calcChanges",calcChanges)},function(t,e,a,r){return addWeights(calcChanges(r,e,t),a)},{output:[this.sizes[t-1],this.sizes[t]],outputToTexture:!0,hardcodeConstants:!0,constants:{size:this.outputs[t-1].length,learningRate:this.trainOpts.learningRate,momentum:this.trainOpts.momentum}}),this.copyChanges[t]=this.gpu.createKernel(function(t){return t[this.thread.y][this.thread.x]},{output:this.changesPropagate[t].output,outputToTexture:!0,hardCodeConstants:!0}),this.copyWeights[t]=this.gpu.createKernel(function(t){return t[this.thread.y][this.thread.x]},{output:this.changesPropagate[t].output,outputToTexture:!0,hardCodeConstants:!0})}},{key:"getChanges",value:function(){for(var t=1;t<=this.outputLayer;t++){var e=this.changesPropagate[t](this.outputs[t-1],this.deltas[t],this.weightsCopies[t]||this.weights[t],this.changesCopies[t]||this.changes[t]);this.changes[t]=e.changes,this.weights[t]=e.weights,this.changesCopies[t]=this.copyChanges[t](e.changes),this.weightsCopies[t]=this.copyWeights[t](e.weights)}}},{key:"buildChangeBiases",value:function(){for(var t=1;t<=this.outputLayer;t++)this.biasesPropagate[t]=this.gpu.createKernel(addBiases,{output:[this.sizes[t]],outputToTexture:!0,hardcodeConstants:!0,constants:{learningRate:this.trainOpts.learningRate}}),this.copyBias[t]=this.gpu.createKernel(function(t){return t[this.thread.x]},{output:this.biasesPropagate[t].output,outputToTexture:!0,hardCodeConstants:!0})}},{key:"changeBiases",value:function(){for(var t=1;t<=this.outputLayer;t++)this.biases[t]=this.biasesPropagate[t](this.biasCopies[t]||this.biases[t],this.deltas[t]),this.biasCopies[t]=this.copyBias[t](this.biases[t])}},{key:"buildGetMSE",value:function(){this.getMSE=this.gpu.createKernel(mse,{output:[1],hardcodeConstants:!0,constants:{size:this.sizes[this.outputLayer]}})}},{key:"run",value:function(t){if(!this.isRunnable)return null;this.inputLookup&&(t=_lookup2.default.toArray(this.inputLookup,t,this.inputLookupLength));var e=this.texturizeInputData(t),a=this.runInput(e),r=void 0;return r=a.toArray?a.toArray(this.gpu):a,this.outputLookup&&(r=_lookup2.default.toObject(this.outputLookup,r)),r}},{key:"prepTraining",value:function(t,e){var a=this;this.updateTrainingOptions(e),t=this.formatData(t);var r=Date.now()+this.trainOpts.timeout,s={error:1,iterations:0};this.verifyIsInitialized(t);var i=this.gpu.createKernel(function(t){return t[this.thread.x]},{output:[t[0].output.length],outputToTexture:!0,hardcodeConstants:!0,outputImmutable:!0});return{data:t.map(function(t){return{input:a.texturizeInputData(t.input),output:i(t.output)}}),status:s,endTime:r}}},{key:"toJSON",value:function(){var t=this;if(!this.weights[1].toArray)return _get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"toJSON",this).call(this);for(var a=[],r=[],s=1;s<=this.outputLayer;s++)a[s]=Array.from(this.weights[s].toArray(this.gpu)),r[s]=Array.from(this.biases[s].toArray(this.gpu));return _neuralNetwork2.default.prototype.toJSON.call({inputLookup:this.inputLookup,outputLookup:this.outputLookup,outputLayer:this.outputLayer,sizes:this.sizes,getTrainOptsJSON:function(){return t.getTrainOptsJSON()},weights:a,biases:r})}}]),e}(_neuralNetwork2.default);exports.default=NeuralNetworkGPU;
},{"./lookup":3,"./neural-network":5,"gpu.js":89}],5:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}function getTypedArrayFn(t,i){if(t.buffer instanceof ArrayBuffer)return null;if(Array.isArray(t))return _cast.arrayToFloat32Array;var e=Object.keys(i).length;return function(t){var s=new Float32Array(e);for(var r in i)s[i[r]]=t[r]||0;return s}}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,i){for(var e=0;e<i.length;e++){var s=i[e];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(i,e,s){return e&&t(i.prototype,e),s&&t(i,s),i}}(),_thaw=require("thaw.js"),_thaw2=_interopRequireDefault(_thaw),_lookup2=require("./lookup"),_lookup3=_interopRequireDefault(_lookup2),_max=require("./utilities/max"),_max2=_interopRequireDefault(_max),_mse=require("./utilities/mse"),_mse2=_interopRequireDefault(_mse),_randos=require("./utilities/randos"),_randos2=_interopRequireDefault(_randos),_range=require("./utilities/range"),_range2=_interopRequireDefault(_range),_toArray=require("./utilities/to-array"),_toArray2=_interopRequireDefault(_toArray),_zeros=require("./utilities/zeros"),_zeros2=_interopRequireDefault(_zeros),_lookupTable=require("./utilities/lookup-table"),_lookupTable2=_interopRequireDefault(_lookupTable),_cast=require("./utilities/cast"),NeuralNetwork=function(){function t(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,t),Object.assign(this,this.constructor.defaults,i),this.trainOpts={},this.updateTrainingOptions(Object.assign({},this.constructor.trainDefaults,i)),this.sizes=null,this.outputLayer=null,this.biases=null,this.weights=null,this.outputs=null,this.deltas=null,this.changes=null,this.errors=null,this.errorCheckInterval=1,this.constructor.prototype.hasOwnProperty("runInput")||(this.runInput=null),this.constructor.prototype.hasOwnProperty("calculateDeltas")||(this.calculateDeltas=null),this.inputLookup=null,this.inputLookupLength=null,this.outputLookup=null,this.outputLookupLength=null}return _createClass(t,null,[{key:"trainDefaults",get:function(){return{iterations:2e4,errorThresh:.005,log:!1,logPeriod:10,learningRate:.3,momentum:.1,callback:null,callbackPeriod:10,timeout:1/0,praxis:null,beta1:.9,beta2:.999,epsilon:1e-8}}},{key:"defaults",get:function(){return{leakyReluAlpha:.01,binaryThresh:.5,hiddenLayers:null,activation:"sigmoid"}}}]),_createClass(t,[{key:"initialize",value:function(){if(!this.sizes)throw new Error("Sizes must be set before initializing");this.outputLayer=this.sizes.length-1,this.biases=[],this.weights=[],this.outputs=[],this.deltas=[],this.changes=[],this.errors=[];for(var t=0;t<=this.outputLayer;t++){var i=this.sizes[t];if(this.deltas[t]=(0,_zeros2.default)(i),this.errors[t]=(0,_zeros2.default)(i),this.outputs[t]=(0,_zeros2.default)(i),t>0){this.biases[t]=(0,_randos2.default)(i),this.weights[t]=new Array(i),this.changes[t]=new Array(i);for(var e=0;e<i;e++){var s=this.sizes[t-1];this.weights[t][e]=(0,_randos2.default)(s),this.changes[t][e]=(0,_zeros2.default)(s)}}}this.setActivation(),"adam"===this.trainOpts.praxis&&this._setupAdam()}},{key:"setActivation",value:function(t){switch(this.activation=t||this.activation,this.activation){case"sigmoid":this.runInput=this.runInput||this._runInputSigmoid,this.calculateDeltas=this.calculateDeltas||this._calculateDeltasSigmoid;break;case"relu":this.runInput=this.runInput||this._runInputRelu,this.calculateDeltas=this.calculateDeltas||this._calculateDeltasRelu;break;case"leaky-relu":this.runInput=this.runInput||this._runInputLeakyRelu,this.calculateDeltas=this.calculateDeltas||this._calculateDeltasLeakyRelu;break;case"tanh":this.runInput=this.runInput||this._runInputTanh,this.calculateDeltas=this.calculateDeltas||this._calculateDeltasTanh;break;default:throw new Error("unknown activation "+this.activation+", The activation should be one of ['sigmoid', 'relu', 'leaky-relu', 'tanh']")}}},{key:"run",value:function(t){if(!this.isRunnable)return null;this.inputLookup&&(t=_lookup3.default.toArray(this.inputLookup,t,this.inputLookupLength));var i=this.runInput(t).slice(0);return this.outputLookup&&(i=_lookup3.default.toObject(this.outputLookup,i)),i}},{key:"_runInputSigmoid",value:function(t){this.outputs[0]=t;for(var i=null,e=1;e<=this.outputLayer;e++){for(var s=0;s<this.sizes[e];s++){for(var r=this.weights[e][s],a=this.biases[e][s],u=0;u<r.length;u++)a+=r[u]*t[u];this.outputs[e][s]=1/(1+Math.exp(-a))}i=t=this.outputs[e]}return i}},{key:"_runInputRelu",value:function(t){this.outputs[0]=t;for(var i=null,e=1;e<=this.outputLayer;e++){for(var s=0;s<this.sizes[e];s++){for(var r=this.weights[e][s],a=this.biases[e][s],u=0;u<r.length;u++)a+=r[u]*t[u];this.outputs[e][s]=a<0?0:a}i=t=this.outputs[e]}return i}},{key:"_runInputLeakyRelu",value:function(t){this.outputs[0]=t;for(var i=this.leakyReluAlpha,e=null,s=1;s<=this.outputLayer;s++){for(var r=0;r<this.sizes[s];r++){for(var a=this.weights[s][r],u=this.biases[s][r],n=0;n<a.length;n++)u+=a[n]*t[n];this.outputs[s][r]=u<0?0:i*u}e=t=this.outputs[s]}return e}},{key:"_runInputTanh",value:function(t){this.outputs[0]=t;for(var i=null,e=1;e<=this.outputLayer;e++){for(var s=0;s<this.sizes[e];s++){for(var r=this.weights[e][s],a=this.biases[e][s],u=0;u<r.length;u++)a+=r[u]*t[u];this.outputs[e][s]=Math.tanh(a)}i=t=this.outputs[e]}return i}},{key:"verifyIsInitialized",value:function(t){var i=this;this.sizes||(this.sizes=[],this.sizes.push(t[0].input.length),this.hiddenLayers?this.hiddenLayers.forEach(function(t){i.sizes.push(t)}):this.sizes.push(Math.max(3,Math.floor(t[0].input.length/2))),this.sizes.push(t[0].output.length),this.initialize())}},{key:"updateTrainingOptions",value:function(t){var i=this.constructor.trainDefaults;for(var e in i)i.hasOwnProperty(e)&&(this.trainOpts[e]=t.hasOwnProperty(e)?t[e]:i[e]);this.validateTrainingOptions(this.trainOpts),this.setLogMethod(t.log||this.trainOpts.log),this.activation=t.activation||this.activation}},{key:"validateTrainingOptions",value:function(t){var i={iterations:function(t){return"number"==typeof t&&t>0},errorThresh:function(t){return"number"==typeof t&&t>0&&t<1},log:function(t){return"function"==typeof t||"boolean"==typeof t},logPeriod:function(t){return"number"==typeof t&&t>0},learningRate:function(t){return"number"==typeof t&&t>0&&t<1},momentum:function(t){return"number"==typeof t&&t>0&&t<1},callback:function(t){return"function"==typeof t||null===t},callbackPeriod:function(t){return"number"==typeof t&&t>0},timeout:function(t){return"number"==typeof t&&t>0}};for(var e in i)if(i.hasOwnProperty(e)&&t.hasOwnProperty(e)&&!i[e](t[e]))throw new Error("["+e+", "+t[e]+"] is out of normal training range, your network will probably not train.")}},{key:"getTrainOptsJSON",value:function(){var t=this;return Object.keys(this.constructor.trainDefaults).reduce(function(i,e){return"timeout"===e&&t.trainOpts[e]===1/0?i:"callback"===e?i:(t.trainOpts[e]&&(i[e]=t.trainOpts[e]),"log"===e&&(i.log="function"==typeof i.log),i)},{})}},{key:"setLogMethod",value:function(t){this.trainOpts.log="function"==typeof t?t:!!t&&console.log}},{key:"calculateTrainingError",value:function(t){for(var i=0,e=0;e<t.length;++e)i+=this.trainPattern(t[e],!0);return i/t.length}},{key:"trainPatterns",value:function(t){for(var i=0;i<t.length;++i)this.trainPattern(t[i])}},{key:"trainingTick",value:function(t,i,e){return!(i.iterations>=this.trainOpts.iterations||i.error<=this.trainOpts.errorThresh||Date.now()>=e)&&(i.iterations++,this.trainOpts.log&&i.iterations%this.trainOpts.logPeriod==0?(i.error=this.calculateTrainingError(t),this.trainOpts.log("iterations: "+i.iterations+", training error: "+i.error)):i.iterations%this.errorCheckInterval==0?i.error=this.calculateTrainingError(t):this.trainPatterns(t),this.trainOpts.callback&&i.iterations%this.trainOpts.callbackPeriod==0&&this.trainOpts.callback({iterations:i.iterations,error:i.error}),!0)}},{key:"prepTraining",value:function(t,i){this.updateTrainingOptions(i),t=this.formatData(t);var e=Date.now()+this.trainOpts.timeout,s={error:1,iterations:0};return this.verifyIsInitialized(t),{data:t,status:s,endTime:e}}},{key:"train",value:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=void 0,s=void 0,r=this.prepTraining(t,i);for(t=r.data,e=r.status,s=r.endTime;this.trainingTick(t,e,s););return e}},{key:"trainAsync",value:function(t){var i=this,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=void 0,r=void 0,a=this.prepTraining(t,e);return t=a.data,s=a.status,r=a.endTime,new Promise(function(e,a){try{var u=new _thaw2.default(new Array(i.trainOpts.iterations),{delay:!0,each:function(){return i.trainingTick(t,s,r)||u.stop()},done:function(){return e(s)}});u.tick()}catch(t){a({trainError:t,status:s})}})}},{key:"trainPattern",value:function(t,i){return this.runInput(t.input),this.calculateDeltas(t.output),this.adjustWeights(),i?(0,_mse2.default)(this.errors[this.outputLayer]):null}},{key:"_calculateDeltasSigmoid",value:function(t){for(var i=this.outputLayer;i>=0;i--)for(var e=0;e<this.sizes[i];e++){var s=this.outputs[i][e],r=0;if(i===this.outputLayer)r=t[e]-s;else for(var a=this.deltas[i+1],u=0;u<a.length;u++)r+=a[u]*this.weights[i+1][u][e];this.errors[i][e]=r,this.deltas[i][e]=r*s*(1-s)}}},{key:"_calculateDeltasRelu",value:function(t){for(var i=this.outputLayer;i>=0;i--)for(var e=0;e<this.sizes[i];e++){var s=this.outputs[i][e],r=0;if(i===this.outputLayer)r=t[e]-s;else for(var a=this.deltas[i+1],u=0;u<a.length;u++)r+=a[u]*this.weights[i+1][u][e];this.errors[i][e]=r,this.deltas[i][e]=s>0?r:0}}},{key:"_calculateDeltasLeakyRelu",value:function(t){for(var i=this.leakyReluAlpha,e=this.outputLayer;e>=0;e--)for(var s=0;s<this.sizes[e];s++){var r=this.outputs[e][s],a=0;if(e===this.outputLayer)a=t[s]-r;else for(var u=this.deltas[e+1],n=0;n<u.length;n++)a+=u[n]*this.weights[e+1][n][s];this.errors[e][s]=a,this.deltas[e][s]=r>0?a:i*a}}},{key:"_calculateDeltasTanh",value:function(t){for(var i=this.outputLayer;i>=0;i--)for(var e=0;e<this.sizes[i];e++){var s=this.outputs[i][e],r=0;if(i===this.outputLayer)r=t[e]-s;else for(var a=this.deltas[i+1],u=0;u<a.length;u++)r+=a[u]*this.weights[i+1][u][e];this.errors[i][e]=r,this.deltas[i][e]=(1-s*s)*r}}},{key:"adjustWeights",value:function(){for(var t=1;t<=this.outputLayer;t++)for(var i=this.outputs[t-1],e=0;e<this.sizes[t];e++){for(var s=this.deltas[t][e],r=0;r<i.length;r++){var a=this.changes[t][e][r];a=this.trainOpts.learningRate*s*i[r]+this.trainOpts.momentum*a,this.changes[t][e][r]=a,this.weights[t][e][r]+=a}this.biases[t][e]+=this.trainOpts.learningRate*s}}},{key:"_setupAdam",value:function(){this.biasChangesLow=[],this.biasChangesHigh=[],this.changesLow=[],this.changesHigh=[],this.iterations=0;for(var t=0;t<=this.outputLayer;t++){var i=this.sizes[t];if(t>0){this.biasChangesLow[t]=(0,_zeros2.default)(i),this.biasChangesHigh[t]=(0,_zeros2.default)(i),this.changesLow[t]=new Array(i),this.changesHigh[t]=new Array(i);for(var e=0;e<i;e++){var s=this.sizes[t-1];this.changesLow[t][e]=(0,_zeros2.default)(s),this.changesHigh[t][e]=(0,_zeros2.default)(s)}}}this.adjustWeights=this._adjustWeightsAdam}},{key:"_adjustWeightsAdam",value:function(){var t=this.trainOpts;this.iterations++;for(var i=1;i<=this.outputLayer;i++)for(var e=this.outputs[i-1],s=0;s<this.sizes[i];s++){for(var r=this.deltas[i][s],a=0;a<e.length;a++){var u=r*e[a],n=this.changesLow[i][s][a]*t.beta1+(1-t.beta1)*u,o=this.changesHigh[i][s][a]*t.beta2+(1-t.beta2)*u*u,h=n/(1-Math.pow(t.beta1,this.iterations)),l=o/(1-Math.pow(t.beta2,this.iterations));this.changesLow[i][s][a]=n,this.changesHigh[i][s][a]=o,this.weights[i][s][a]+=this.trainOpts.learningRate*h/(Math.sqrt(l)+t.epsilon)}var p=this.deltas[i][s],c=this.biasChangesLow[i][s]*t.beta1+(1-t.beta1)*p,f=this.biasChangesHigh[i][s]*t.beta2+(1-t.beta2)*p*p,g=this.biasChangesLow[i][s]/(1-Math.pow(t.beta1,this.iterations)),v=this.biasChangesHigh[i][s]/(1-Math.pow(t.beta2,this.iterations));this.biasChangesLow[i][s]=c,this.biasChangesHigh[i][s]=f,this.biases[i][s]+=t.learningRate*g/(Math.sqrt(v)+t.epsilon)}}},{key:"formatData",value:function(t){if(Array.isArray(t)||(t=[t]),!Array.isArray(t[0].input))if(this.inputLookup)this.inputLookupLength=Object.keys(this.inputLookup).length;else{var i=new _lookupTable2.default(t,"input");this.inputLookup=i.table,this.inputLookupLength=i.length}if(!Array.isArray(t[0].output))if(this.outputLookup)this.outputLookupLength=Object.keys(this.outputLookup).length;else{var e=new _lookupTable2.default(t,"output");this.outputLookup=e.table,this.outputLookupLength=e.length}if(void 0===this._formatInput&&(this._formatInput=getTypedArrayFn(t[0].input,this.inputLookup),this._formatOutput=getTypedArrayFn(t[0].output,this.outputLookup)),this._formatInput&&this._formatOutput){for(var s=[],r=0;r<t.length;r++)s.push({input:this._formatInput(t[r].input),output:this._formatOutput(t[r].output)});return s}if(this._formatInput){for(var a=[],u=0;u<t.length;u++)a.push({input:this._formatInput(t[u].input),output:t[u].output});return a}if(this._formatOutput){for(var n=[],o=0;o<t.length;o++)n.push({input:t[o].input,output:this._formatOutput(t[o].output)});return n}return t}},{key:"addFormat",value:function(t){this.inputLookup=_lookup3.default.addKeys(t.input,this.inputLookup),this.inputLookup&&(this.inputLookupLength=Object.keys(this.inputLookup).length),this.outputLookup=_lookup3.default.addKeys(t.output,this.outputLookup),this.outputLookup&&(this.outputLookupLength=Object.keys(this.outputLookup).length)}},{key:"test",value:function(t){var i=this;t=this.formatData(t);var e=1===t[0].output.length,s=[],r=0;if(e){for(var a=0,u=0,n=0,o=0,h=0;h<t.length;h++)!function(e){var h=i.runInput(t[e].input),l=t[e].output,p=h[0]>i.binaryThresh?1:0,c=l[0];if(p!==c){var f=t[e];s.push({input:f.input,output:f.output,actual:p,expected:c})}0===p&&0===c?o++:1===p&&1===c?n++:0===p&&1===c?u++:1===p&&0===c&&a++,r+=(0,_mse2.default)(h.map(function(t,i){return l[i]-t}))}(h);return{error:r/t.length,misclasses:s,total:t.length,trueNeg:o,truePos:n,falseNeg:u,falsePos:a,precision:n>0?n/(n+a):0,recall:n>0?n/(n+u):0,accuracy:(o+n)/t.length}}for(var h=0;h<t.length;h++)!function(e){var a=i.runInput(t[e].input),u=t[e].output,n=a.indexOf((0,_max2.default)(a)),o=u.indexOf((0,_max2.default)(u));if(n!==o){var h=t[e];s.push({input:h.input,output:h.output,actual:n,expected:o})}r+=(0,_mse2.default)(a.map(function(t,i){return u[i]-t}))}(h);return{error:r/t.length,misclasses:s,total:t.length}}},{key:"toJSON",value:function(){for(var t=[],i=0;i<=this.outputLayer;i++){t[i]={};var e=void 0;e=0===i&&this.inputLookup?Object.keys(this.inputLookup):this.outputLookup&&i===this.outputLayer?Object.keys(this.outputLookup):(0,_range2.default)(0,this.sizes[i]);for(var s=0;s<e.length;s++){var r=e[s];if(t[i][r]={},i>0){t[i][r].bias=this.biases[i][s],t[i][r].weights={};for(var a in t[i-1]){var u=a;1===i&&this.inputLookup&&(u=this.inputLookup[a]),t[i][r].weights[a]=this.weights[i][s][u]}}}}return{sizes:this.sizes.slice(0),layers:t,outputLookup:null!==this.outputLookup,inputLookup:null!==this.inputLookup,activation:this.activation,trainOpts:this.getTrainOptsJSON()}}},{key:"fromJSON",value:function(t){Object.assign(this,this.constructor.defaults,t),this.sizes=t.sizes,this.initialize();for(var i=0;i<=this.outputLayer;i++){var e=t.layers[i];if(0!==i||e[0]&&!t.inputLookup?i!==this.outputLayer||e[0]&&!t.outputLookup||(this.outputLookup=_lookup3.default.toHash(e)):(this.inputLookup=_lookup3.default.toHash(e),this.inputLookupLength=Object.keys(this.inputLookup).length),i>0){var s=Object.keys(e);this.sizes[i]=s.length;for(var r in s){var a=s[r];this.biases[i][r]=e[a].bias,this.weights[i][r]=(0,_toArray2.default)(e[a].weights)}}}return t.hasOwnProperty("trainOpts")&&this.updateTrainingOptions(t.trainOpts),this}},{key:"toFunction",value:function(){function t(r,a,u){if(0===a)return"string"==typeof u?"input['"+u+"']":"input["+u+"]";var n=r[a],o=n[u],h=["(",o.bias];for(var l in o.weights)o.weights[l]<0?h.push(o.weights[l]+"*"+t(r,a-1,l)):h.push("+"+o.weights[l]+"*"+t(r,a-1,l));switch(h.push(")"),i){case"sigmoid":return"1/(1+1/Math.exp("+h.join("")+"))";case"relu":return s=!0,"((v="+h.join("")+")<0?0:v)";case"leaky-relu":return s=!0,"((v="+h.join("")+")<0?0:"+e+"*v)";case"tanh":return"Math.tanh("+h.join("")+")";default:throw new Error("unknown activation type "+i)}}var i=this.activation,e=this.leakyReluAlpha,s=!1,r=this.toJSON().layers,a=[],u=void 0;for(var n in r[r.length-1])a.push(t(r,r.length-1,n));return u=this.outputLookup?"{"+Object.keys(this.outputLookup).map(function(t,i){return"'"+t+"':"+a[i]})+"}":"["+a.join(",")+"]",new Function("input",(s?"var v;":"")+"return "+u+";")}},{key:"isRunnable",get:function(){var t=this;if(!this.runInput)return console.error("Activation function has not been initialized, did you run train()?"),!1;var i=["sizes","outputLayer","biases","weights","outputs","deltas","changes","errors"].filter(function(i){return null===t[i]});return!(i.length>0)||(console.error("Some settings have not been initialized correctly, did you run train()? Found issues with: "+i.join(", ")),!1)}}]),t}();exports.default=NeuralNetwork;
},{"./lookup":3,"./utilities/cast":38,"./utilities/lookup-table":40,"./utilities/max":41,"./utilities/mse":42,"./utilities/randos":46,"./utilities/range":47,"./utilities/to-array":48,"./utilities/zeros":50,"thaw.js":114}],6:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_gru=require("./gru"),_gru2=_interopRequireDefault(_gru),_rnnTimeStep=require("./rnn-time-step"),_rnnTimeStep2=_interopRequireDefault(_rnnTimeStep),GRUTimeStep=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"getModel",value:function(e,t){return _gru2.default.prototype.getModel(e,t)}},{key:"getEquation",value:function(e,t,r,n){return _gru2.default.prototype.getEquation(e,t,r,n)}}]),t}(_rnnTimeStep2.default);exports.default=GRUTimeStep;
},{"./gru":7,"./matrix":16,"./rnn-time-step":34}],7:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_randomMatrix=require("./matrix/random-matrix"),_randomMatrix2=_interopRequireDefault(_randomMatrix),_rnn=require("./rnn"),_rnn2=_interopRequireDefault(_rnn),GRU=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"getModel",value:function(e,t){return{updateGateInputMatrix:new _randomMatrix2.default(e,t,.08),updateGateHiddenMatrix:new _randomMatrix2.default(e,e,.08),updateGateBias:new _matrix2.default(e,1),resetGateInputMatrix:new _randomMatrix2.default(e,t,.08),resetGateHiddenMatrix:new _randomMatrix2.default(e,e,.08),resetGateBias:new _matrix2.default(e,1),cellWriteInputMatrix:new _randomMatrix2.default(e,t,.08),cellWriteHiddenMatrix:new _randomMatrix2.default(e,e,.08),cellWriteBias:new _matrix2.default(e,1)}}},{key:"getEquation",value:function(e,t,r,n){var a=e.sigmoid.bind(e),i=e.add.bind(e),u=e.multiply.bind(e),o=e.multiplyElement.bind(e),l=e.tanh.bind(e),d=e.allOnes.bind(e),s=e.cloneNegative.bind(e),c=a(i(i(u(n.updateGateInputMatrix,t),u(n.updateGateHiddenMatrix,r)),n.updateGateBias)),f=a(i(i(u(n.resetGateInputMatrix,t),u(n.resetGateHiddenMatrix,r)),n.resetGateBias)),p=l(i(i(u(n.cellWriteInputMatrix,t),u(n.cellWriteHiddenMatrix,o(f,r))),n.cellWriteBias));return i(o(i(d(c.rows,c.columns),s(c)),p),o(r,c))}}]),t}(_rnn2.default);exports.default=GRU;
},{"./matrix":16,"./matrix/random-matrix":23,"./rnn":35}],8:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_lstm=require("./lstm"),_lstm2=_interopRequireDefault(_lstm),_rnnTimeStep=require("./rnn-time-step"),_rnnTimeStep2=_interopRequireDefault(_rnnTimeStep),LSTMTimeStep=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"getModel",value:function(e,t){return _lstm2.default.prototype.getModel.call(this,e,t)}},{key:"getEquation",value:function(e,t,r,n){return _lstm2.default.prototype.getEquation.call(this,e,t,r,n)}}]),t}(_rnnTimeStep2.default);exports.default=LSTMTimeStep;
},{"./lstm":9,"./matrix":16,"./rnn-time-step":34}],9:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_randomMatrix=require("./matrix/random-matrix"),_randomMatrix2=_interopRequireDefault(_randomMatrix),_rnn=require("./rnn"),_rnn2=_interopRequireDefault(_rnn),LSTM=function(t){function e(){return _classCallCheck(this,e),_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return _inherits(e,t),_createClass(e,[{key:"getModel",value:function(t,e){return{inputMatrix:new _randomMatrix2.default(t,e,.08),inputHidden:new _randomMatrix2.default(t,t,.08),inputBias:new _matrix2.default(t,1),forgetMatrix:new _randomMatrix2.default(t,e,.08),forgetHidden:new _randomMatrix2.default(t,t,.08),forgetBias:new _matrix2.default(t,1),outputMatrix:new _randomMatrix2.default(t,e,.08),outputHidden:new _randomMatrix2.default(t,t,.08),outputBias:new _matrix2.default(t,1),cellActivationMatrix:new _randomMatrix2.default(t,e,.08),cellActivationHidden:new _randomMatrix2.default(t,t,.08),cellActivationBias:new _matrix2.default(t,1)}}},{key:"getEquation",value:function(t,e,r,n){var i=t.sigmoid.bind(t),a=t.add.bind(t),o=t.multiply.bind(t),u=t.multiplyElement.bind(t),l=t.tanh.bind(t),d=i(a(a(o(n.inputMatrix,e),o(n.inputHidden,r)),n.inputBias)),f=i(a(a(o(n.forgetMatrix,e),o(n.forgetHidden,r)),n.forgetBias)),c=i(a(a(o(n.outputMatrix,e),o(n.outputHidden,r)),n.outputBias)),s=l(a(a(o(n.cellActivationMatrix,e),o(n.cellActivationHidden,r)),n.cellActivationBias));return u(c,l(a(u(f,r),u(d,s))))}}]),e}(_rnn2.default);exports.default=LSTM;
},{"./matrix":16,"./matrix/random-matrix":23,"./rnn":35}],10:[function(require,module,exports){
"use strict";function addB(e,t,d){for(var a=0;a<e.deltas.length;a++)t.deltas[a]=e.deltas[a],d.deltas[a]=e.deltas[a]}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=addB;
},{}],11:[function(require,module,exports){
"use strict";function add(e,t,s){for(var d=0;d<t.weights.length;d++)e.weights[d]=t.weights[d]+s.weights[d],e.deltas[d]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=add;
},{}],12:[function(require,module,exports){
"use strict";function allOnes(e){for(var t=0;t<e.weights.length;t++)e.weights[t]=1,e.deltas[t]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=allOnes;
},{}],13:[function(require,module,exports){
"use strict";function cloneNegative(e,s){e.rows=parseInt(s.rows),e.columns=parseInt(s.columns),e.weights=s.weights.slice(0),e.deltas=s.deltas.slice(0);for(var t=0;t<s.weights.length;t++)e.weights[t]=-s.weights[t],e.deltas[t]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=cloneNegative;
},{}],14:[function(require,module,exports){
"use strict";function copy(e,s){e.rows=parseInt(s.rows),e.columns=parseInt(s.columns),e.weights=s.weights.slice(0),e.deltas=s.deltas.slice(0)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=copy;
},{}],15:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var u=t[r];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(e,u.key,u)}}return function(t,r,u){return r&&e(t.prototype,r),u&&e(t,u),t}}(),_=require("./"),_2=_interopRequireDefault(_),_onesMatrix=require("./ones-matrix"),_onesMatrix2=_interopRequireDefault(_onesMatrix),_copy=require("./copy"),_copy2=_interopRequireDefault(_copy),_cloneNegative2=require("./clone-negative"),_cloneNegative3=_interopRequireDefault(_cloneNegative2),_add2=require("./add"),_add3=_interopRequireDefault(_add2),_addB=require("./add-b"),_addB2=_interopRequireDefault(_addB),_allOnes2=require("./all-ones"),_allOnes3=_interopRequireDefault(_allOnes2),_multiply2=require("./multiply"),_multiply3=_interopRequireDefault(_multiply2),_multiplyB=require("./multiply-b"),_multiplyB2=_interopRequireDefault(_multiplyB),_multiplyElement2=require("./multiply-element"),_multiplyElement3=_interopRequireDefault(_multiplyElement2),_multiplyElementB=require("./multiply-element-b"),_multiplyElementB2=_interopRequireDefault(_multiplyElementB),_relu2=require("./relu"),_relu3=_interopRequireDefault(_relu2),_reluB=require("./relu-b"),_reluB2=_interopRequireDefault(_reluB),_rowPluck=require("./row-pluck"),_rowPluck2=_interopRequireDefault(_rowPluck),_rowPluckB=require("./row-pluck-b"),_rowPluckB2=_interopRequireDefault(_rowPluckB),_sigmoid2=require("./sigmoid"),_sigmoid3=_interopRequireDefault(_sigmoid2),_sigmoidB=require("./sigmoid-b"),_sigmoidB2=_interopRequireDefault(_sigmoidB),_tanh2=require("./tanh"),_tanh3=_interopRequireDefault(_tanh2),_tanhB=require("./tanh-b"),_tanhB2=_interopRequireDefault(_tanhB),_softmax=require("./softmax"),_softmax2=_interopRequireDefault(_softmax),Equation=function(){function e(){_classCallCheck(this,e),this.inputRow=0,this.inputValue=null,this.states=[]}return _createClass(e,[{key:"add",value:function(e,t){if(e.weights.length!==t.weights.length)throw new Error("misaligned matrices");var r=new _2.default(e.rows,e.columns);return this.states.push({left:e,right:t,product:r,forwardFn:_add3.default,backpropagationFn:_addB2.default}),r}},{key:"allOnes",value:function(e,t){var r=new _2.default(e,t);return this.states.push({left:r,product:r,forwardFn:_allOnes3.default}),r}},{key:"cloneNegative",value:function(e){var t=new _2.default(e.rows,e.columns);return this.states.push({left:e,product:t,forwardFn:_cloneNegative3.default}),t}},{key:"subtract",value:function(e,t){if(e.weights.length!==t.weights.length)throw new Error("misaligned matrices");return this.add(this.add(this.allOnes(e.rows,e.columns),this.cloneNegative(e)),t)}},{key:"multiply",value:function(e,t){if(e.columns!==t.rows)throw new Error("misaligned matrices");var r=new _2.default(e.rows,t.columns);return this.states.push({left:e,right:t,product:r,forwardFn:_multiply3.default,backpropagationFn:_multiplyB2.default}),r}},{key:"multiplyElement",value:function(e,t){if(e.weights.length!==t.weights.length)throw new Error("misaligned matrices");var r=new _2.default(e.rows,e.columns);return this.states.push({left:e,right:t,product:r,forwardFn:_multiplyElement3.default,backpropagationFn:_multiplyElementB2.default}),r}},{key:"relu",value:function(e){var t=new _2.default(e.rows,e.columns);return this.states.push({left:e,product:t,forwardFn:_relu3.default,backpropagationFn:_reluB2.default}),t}},{key:"input",value:function(e){var t=this;return this.states.push({product:e,forwardFn:function(r){r.weights=e.weights=t.inputValue}}),e}},{key:"inputMatrixToRow",value:function(e){var t=this,r=new _2.default(e.columns,1);return this.states.push({left:e,get right(){return t.inputRow},product:r,forwardFn:_rowPluck2.default,backpropagationFn:_rowPluckB2.default}),r}},{key:"sigmoid",value:function(e){var t=new _2.default(e.rows,e.columns);return this.states.push({left:e,product:t,forwardFn:_sigmoid3.default,backpropagationFn:_sigmoidB2.default}),t}},{key:"tanh",value:function(e){var t=new _2.default(e.rows,e.columns);return this.states.push({left:e,product:t,forwardFn:_tanh3.default,backpropagationFn:_tanhB2.default}),t}},{key:"observe",value:function(e){var t=0,r=0;return this.states.push({forwardFn:function(){t++},backpropagationFn:function(){r++}}),e}},{key:"runIndex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.inputRow=e;for(var t=void 0,r=0,u=this.states.length;r<u;r++)t=this.states[r],t.hasOwnProperty("forwardFn")&&t.forwardFn(t.product,t.left,t.right);return t.product}},{key:"runInput",value:function(e){this.inputValue=e;for(var t=void 0,r=0,u=this.states.length;r<u;r++)t=this.states[r],t.hasOwnProperty("forwardFn")&&t.forwardFn(t.product,t.left,t.right);return t.product}},{key:"backpropagate",value:function(){for(var e=this.states.length,t=void 0;e-- >0;)t=this.states[e],t.hasOwnProperty("backpropagationFn")&&t.backpropagationFn(t.product,t.left,t.right);return t.product}},{key:"backpropagateIndex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.inputRow=e;for(var t=this.states.length,r=void 0;t-- >0;)r=this.states[t],r.hasOwnProperty("backpropagationFn")&&r.backpropagationFn(r.product,r.left,r.right);return r.product}},{key:"predictTarget",value:function(e,t){for(var r=this.runInput(e),u=0,a=0;a<r.weights.length;a++){var n=r.weights[a]-t[a];u+=Math.abs(n),r.deltas[a]=n}return u}},{key:"predictTargetIndex",value:function(e,t){var r=this.runIndex(e),u=r,a=(0,_softmax2.default)(r);return u.deltas=a.weights.slice(0),u.deltas[t]-=1,-Math.log2(a.weights[t])}}]),e}();exports.default=Equation;
},{"./":16,"./add":11,"./add-b":10,"./all-ones":12,"./clone-negative":13,"./copy":14,"./multiply":21,"./multiply-b":18,"./multiply-element":20,"./multiply-element-b":19,"./ones-matrix":22,"./relu":25,"./relu-b":24,"./row-pluck":27,"./row-pluck-b":26,"./sigmoid":30,"./sigmoid-b":29,"./softmax":31,"./tanh":33,"./tanh-b":32}],16:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var r=t[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,s,r){return s&&e(t.prototype,s),r&&e(t,r),t}}(),_zeros=require("../../utilities/zeros"),_zeros2=_interopRequireDefault(_zeros),Matrix=function(){function e(t,s){_classCallCheck(this,e),void 0!==t&&void 0!==s&&(this.rows=t,this.columns=s,this.weights=(0,_zeros2.default)(t*s),this.deltas=(0,_zeros2.default)(t*s))}return _createClass(e,[{key:"getWeights",value:function(e,t){var s=this.columns*e+t;if(s<0&&s>=this.weights.length)throw new Error("get accessor is skewed");return this.weights[s]}},{key:"setWeight",value:function(e,t,s){var r=this.columns*e+t;if(r<0&&r>=this.weights.length)throw new Error("set accessor is skewed");this.weights[r]=s}},{key:"setDeltas",value:function(e,t,s){var r=this.columns*e+t;if(r<0&&r>=this.weights.length)throw new Error("set accessor is skewed");this.deltas[r]=s}},{key:"toJSON",value:function(){return{rows:this.rows,columns:this.columns,weights:this.weights.slice(0)}}},{key:"weightsToArray",value:function(){for(var e=[],t=0,s=0,r=0;r<this.weights.length;r++)0===s&&e.push([]),e[t].push(this.weights[r]),++s>=this.columns&&(s=0,t++);return e}},{key:"deltasToArray",value:function(){for(var e=[],t=0,s=0,r=0;r<this.deltas.length;r++)0===s&&e.push([]),e[t].push(this.deltas[r]),++s>=this.columns&&(s=0,t++);return e}}],[{key:"fromJSON",value:function(t){for(var s=new e(t.rows,t.columns),r=0,i=t.rows*t.columns;r<i;r++)s.weights[r]=t.weights[r];return s}},{key:"fromArray",value:function(t,s){var r=t.length,i=t[0].length,n=new e(r,i);s=s||t;for(var o=0;o<r;o++)for(var u=t[o],a=s[o],l=0;l<i;l++)n.setWeight(o,l,u[l]),n.setDeltas(o,l,a[l]);return n}}]),e}();exports.default=Matrix;
},{"../../utilities/zeros":50}],17:[function(require,module,exports){
"use strict";function maxI(e){for(var t=e.weights,r=t[0],a=0,o=1;o<t.length;o++){var s=t[o];s<r||(a=o,r=s)}return a}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=maxI;
},{}],18:[function(require,module,exports){
"use strict";function multiplyB(e,t,r){for(var s=t.rows,l=t.columns,o=r.columns,a=0;a<s;a++)for(var u=l*a,i=o*a,d=0;d<o;d++)for(var f=0;f<l;f++){var c=o*f,n=u+f,p=c+d,v=e.deltas[i+d];t.deltas[n]+=r.weights[p]*v,r.deltas[p]+=t.weights[n]*v}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=multiplyB;
},{}],19:[function(require,module,exports){
"use strict";function multiplyElementB(e,t,l){for(var s=0;s<t.weights.length;s++)t.deltas[s]=l.weights[s]*e.deltas[s],l.deltas[s]=t.weights[s]*e.deltas[s]}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=multiplyElementB;
},{}],20:[function(require,module,exports){
"use strict";function multiplyElement(e,t,l){for(var s=t.weights,i=0;i<s.length;i++)e.weights[i]=t.weights[i]*l.weights[i],e.deltas[i]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=multiplyElement;
},{}],21:[function(require,module,exports){
"use strict";function multiply(e,t,r){for(var s=t.rows,l=t.columns,o=r.columns,u=0;u<s;u++)for(var a=l*u,i=o*u,f=0;f<o;f++){for(var c=0,d=0;d<l;d++){var n=o*d,p=a+d,v=n+f;c+=t.weights[p]*r.weights[v],t.deltas[p]=0,r.deltas[v]=0}e.weights[i+f]=c}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=multiply;
},{}],22:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _=require("./"),_2=_interopRequireDefault(_),_ones=require("../../utilities/ones"),_ones2=_interopRequireDefault(_ones),OnesMatrix=function(e){function t(e,r){_classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));return o.rows=e,o.columns=r,o.weights=(0,_ones2.default)(e*r),o.deltas=(0,_ones2.default)(e*r),o}return _inherits(t,e),t}(_2.default);exports.default=OnesMatrix;
},{"../../utilities/ones":43,"./":16}],23:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _=require("./"),_2=_interopRequireDefault(_),_random=require("../../utilities/random"),RandomMatrix=function(e){function t(e,r,o){_classCallCheck(this,t);var n=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));n.rows=e,n.columns=r,n.std=o;for(var i=0,s=n.weights.length;i<s;i++)n.weights[i]=(0,_random.randomF)(-o,o);return n}return _inherits(t,e),t}(_2.default);exports.default=RandomMatrix;
},{"../../utilities/random":45,"./":16}],24:[function(require,module,exports){
"use strict";function reluB(e,t){for(var l=0;l<e.deltas.length;l++)t.deltas[l]=t.weights[l]>0?e.deltas[l]:0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=reluB;
},{}],25:[function(require,module,exports){
"use strict";function relu(e,t){for(var r=0;r<t.weights.length;r++)e.weights[r]=Math.max(0,t.weights[r]),e.deltas[r]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=relu;
},{}],26:[function(require,module,exports){
"use strict";function rowPluckB(e,t,o){for(var r=t.columns,l=r*o,s=0;s<r;s++)t.deltas[l+s]=e.deltas[s]}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=rowPluckB;
},{}],27:[function(require,module,exports){
"use strict";function rowPluck(e,t,o){for(var r=t.columns,s=r*o,u=0;u<r;u++)e.weights[u]=t.weights[s+u],e.deltas[u]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=rowPluck;
},{}],28:[function(require,module,exports){
"use strict";function sampleI(e){for(var r=randomF(0,1),a=0,o=0,t=e.weights;;){if((a+=t[o])>r)return o;o++}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=sampleI;var _random=require("../../utilities/random"),randomF=_random.randomF;
},{"../../utilities/random":45}],29:[function(require,module,exports){
"use strict";function sigmoidB(e,t){for(var s=0;s<e.deltas.length;s++){var d=e.weights[s];t.deltas[s]=d*(1-d)*e.deltas[s]}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=sigmoidB;
},{}],30:[function(require,module,exports){
"use strict";function sigmoid(e,t){for(var i=0;i<t.weights.length;i++)e.weights[i]=1/(1+Math.exp(-t.weights[i])),e.deltas[i]=0}function sig(e){return 1/(1+Math.exp(-e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=sigmoid;
},{}],31:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function softmax(e){for(var t=new _2.default(e.rows,e.columns),r=-999999,s=0;s<e.weights.length;s++)e.weights[s]>r&&(r=e.weights[s]);for(var i=0,u=0;u<e.weights.length;u++)t.weights[u]=Math.exp(e.weights[u]-r),i+=t.weights[u];for(var o=0;o<e.weights.length;o++)t.weights[o]/=i;return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=softmax;var _=require("./"),_2=_interopRequireDefault(_);
},{"./":16}],32:[function(require,module,exports){
"use strict";function tanhB(e,t){for(var a=0;a<e.deltas.length;a++){var s=e.weights[a];t.deltas[a]=(1-s*s)*e.deltas[a]}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=tanhB;
},{}],33:[function(require,module,exports){
"use strict";function tanh(t,e){for(var s=0;s<e.weights.length;s++)t.weights[s]=Math.tanh(e.weights[s]),t.deltas[s]=0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=tanh;
},{}],34:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,r){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?t:r}function _inherits(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,r){for(var e=0;e<r.length;e++){var u=r[e];u.enumerable=u.enumerable||!1,u.configurable=!0,"value"in u&&(u.writable=!0),Object.defineProperty(t,u.key,u)}}return function(r,e,u){return e&&t(r.prototype,e),u&&t(r,u),r}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_randomMatrix=require("./matrix/random-matrix"),_randomMatrix2=_interopRequireDefault(_randomMatrix),_equation=require("./matrix/equation"),_equation2=_interopRequireDefault(_equation),_rnn=require("./rnn"),_rnn2=_interopRequireDefault(_rnn),_zeros=require("../utilities/zeros"),_zeros2=_interopRequireDefault(_zeros),_softmax=require("./matrix/softmax"),_softmax2=_interopRequireDefault(_softmax),_random=require("../utilities/random"),_sampleI=require("./matrix/sample-i"),_sampleI2=_interopRequireDefault(_sampleI),_maxI=require("./matrix/max-i"),_maxI2=_interopRequireDefault(_maxI),_lookup=require("../lookup"),_lookup2=_interopRequireDefault(_lookup),_lookupTable2=require("../utilities/lookup-table"),_lookupTable3=_interopRequireDefault(_lookupTable2),_arrayLookupTable=require("../utilities/array-lookup-table"),_arrayLookupTable2=_interopRequireDefault(_arrayLookupTable),_cast=require("../utilities/cast"),RNNTimeStep=function(t){function r(){return _classCallCheck(this,r),_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).apply(this,arguments))}return _inherits(r,t),_createClass(r,[{key:"createOutputMatrix",value:function(){var t=this.model,r=this.outputSize,e=this.hiddenLayers[this.hiddenLayers.length-1];t.outputConnector=new _randomMatrix2.default(r,e,.08),t.output=new _randomMatrix2.default(r,1,.08)}},{key:"bindEquation",value:function(){var t=this.model,r=this.hiddenLayers,e=t.hiddenLayers,u=new _equation2.default,n=[],o=t.equationConnections.length>0?t.equationConnections[t.equationConnections.length-1]:this.initialLayerInputs,a=this.getEquation(u,u.input(new _matrix2.default(this.inputSize,1)),o[0],e[0]);n.push(a);for(var i=1,s=r.length;i<s;i++)a=this.getEquation(u,a,o[i],e[i]),n.push(a);t.equationConnections.push(n),u.add(u.multiply(t.outputConnector,a),t.output),t.equations.push(u)}},{key:"mapModel",value:function(){var t=this.model,r=t.hiddenLayers,e=t.allMatrices;if(this.initialLayerInputs=this.hiddenLayers.map(function(t){return new _matrix2.default(t,1)}),this.createHiddenLayers(),!t.hiddenLayers.length)throw new Error("net.hiddenLayers not set");for(var u=0,n=r.length;u<n;u++){var o=r[u];for(var a in o)o.hasOwnProperty(a)&&e.push(o[a])}if(this.createOutputMatrix(),!t.outputConnector)throw new Error("net.model.outputConnector not set");if(!t.output)throw new Error("net.model.output not set");e.push(t.outputConnector),e.push(t.output)}},{key:"backpropagate",value:function(){for(var t=this.model.equations.length-1;t>-1;t--)this.model.equations[t].backpropagate()}},{key:"run",value:function(t){return 1===this.inputSize?this.outputLookup?(this.run=this.runObject,this.runObject(t)):(this.run=this.runNumbers,this.runNumbers(t)):(this.run=this.runArrays,this.runArrays(t))}},{key:"forecast",value:function(t,r){return 1===this.inputSize?this.outputLookup?(this.forecast=this.runObject,this.runObject(t)):(this.forecast=this.forecastNumbers,this.forecastNumbers(t,r)):this.outputLookup?(this.forecast=this.forecastObjects,this.forecastObjects(t,r)):(this.forecast=this.forecastArrays,this.forecastArrays(t,r))}},{key:"train",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.trainOpts=r=Object.assign({},this.constructor.trainDefaults,r);var e=r.iterations,u=r.errorThresh,n=!0===r.log?console.log:r.log,o=r.logPeriod,a=r.callback,i=r.callbackPeriod;1!==this.inputSize&&this.inputSize||this.setSize(t),t=this.formatData(t);var s=1/0,p=void 0;for(this.verifyIsInitialized(t),p=0;p<e&&s>u;p++){for(var h=0,l=0;l<t.length;l++){h+=this.trainPattern(t[l],!0)}if(s=h/t.length,isNaN(s))throw new Error("network error rate is unexpected NaN, check network configurations and try again");n&&p%o==0&&n("iterations: "+p+", training error: "+s),a&&p%i==0&&a({error:s,iterations:p})}return{error:s,iterations:p}}},{key:"verifyIsInitialized",value:function(t){t[0].input?this.trainInput=this.trainInputOutput:t[0].length>0&&(t[0][0].length>0?this.trainInput=this.trainArrays:this.inputSize>1?this.trainInput=this.trainArrays:this.trainInput=this.trainNumbers),this.model||this.initialize()}},{key:"setSize",value:function(t){switch(_lookup2.default.dataShape(t).join(",")){case"array,array,number":case"array,object,number":case"array,datum,array,number":case"array,datum,object,number":break;case"array,array,array,number":this.inputSize=this.outputSize=t[0][0].length;break;case"array,array,object,number":this.inputSize=this.outputSize=Object.keys(_lookup2.default.toTable2D(t)).length;break;case"array,datum,array,array,number":this.inputSize=this.outputSize=t[0].input[0].length;break;case"array,datum,array,object,number":this.inputSize=Object.keys(_lookup2.default.toInputTable2D(t)).length,this.outputSize=Object.keys(_lookup2.default.toOutputTable2D(t)).length;break;default:throw new Error("unknown data shape or configuration")}}},{key:"trainNumbers",value:function(t){for(var r=this.model,e=r.equations;e.length<t.length;)this.bindEquation();for(var u=0,n=0,o=t.length-1;n<o;n++)u+=e[n].predictTarget(t[n],t[n+1]);return this.end(),u/t.length}},{key:"runNumbers",value:function(t){if(!this.isRunnable)return null;var r=this.model,e=r.equations;for(this.inputLookup&&(t=_lookup2.default.toArray(this.inputLookup,t,this.inputLookupLength));e.length<=t.length;)this.bindEquation();for(var u=void 0,n=0;n<t.length;n++)u=e[n].runInput([t[n]]);return this.end(),u.weights[0]}},{key:"forecastNumbers",value:function(t,r){if(!this.isRunnable)return null;for(var e=this.model,u=e.equations,n=t.length+r;u.length<=n;)this.bindEquation();for(var o=void 0,a=0,i=0;i<t.length;i++)o=u[a++].runInput([t[i]]);for(var s=[o.weights[0]],p=0,h=r-1;p<h;p++)o=u[a++].runInput(o.weights),s.push(o.weights[0]);return this.end(),s}},{key:"runObject",value:function(t){if(this.inputLookup===this.outputLookup){var r=_lookup2.default.toArrayShort(this.inputLookup,t);return _lookup2.default.toObjectPartial(this.outputLookup,this.forecastNumbers(r,this.outputLookupLength-r.length),r.length)}return _lookup2.default.toObject(this.outputLookup,this.forecastNumbers(_lookup2.default.toArray(this.inputLookup,t,this.inputLookupLength),this.outputLookupLength))}},{key:"forecastObjects",value:function(t,r){var e=this;return t=t.map(function(t){return _lookup2.default.toArray(e.outputLookup,t,e.outputLookupLength)}),this.forecastArrays(t,r).map(function(t){return _lookup2.default.toObject(e.outputLookup,t)})}},{key:"trainInputOutput",value:function(t){for(var r=this.model,e=t.input,u=t.output,n=e.length+u.length,o=r.equations;o.length<n;)this.bindEquation();for(var a=0,i=0,s=0,p=e.length-1;s<p;s++)a+=o[i++].predictTarget(e[s],e[s+1]);a+=o[i++].predictTarget(e[e.length-1],u[0]);for(var h=0,l=u.length-1;h<l;h++)a+=o[i++].predictTarget(u[h],u[h+1]);return this.end(),a/n}},{key:"trainArrays",value:function(t){for(var r=this.model,e=r.equations;e.length<t.length;)this.bindEquation();for(var u=0,n=0,o=t.length-1;n<o;n++)u+=e[n].predictTarget(t[n],t[n+1]);return this.end(),u/t.length}},{key:"runArrays",value:function(t){if(!this.isRunnable)return null;for(var r=this.model,e=r.equations;e.length<=t.length;)this.bindEquation();this.inputLookup&&(t=_lookup2.default.toArrays(this.inputLookup,t,this.inputLookupLength));for(var u=void 0,n=0;n<t.length;n++){u=e[n].runInput(t[n]).weights}return this.end(),this.outputLookup?_lookup2.default.toObject(this.outputLookup,u):u}},{key:"forecastArrays",value:function(t,r){if(!this.isRunnable)return null;for(var e=this.model,u=e.equations,n=t.length+r;u.length<=n;)this.bindEquation();for(var o=void 0,a=0,i=0;i<t.length;i++)o=u[a++].runInput(t[i]);for(var s=[o.weights],p=0,h=r-1;p<h;p++)o=u[a++].runInput(o.weights),s.push(o.weights.slice(0));return this.end(),s}},{key:"end",value:function(){this.model.equations[this.model.equations.length-1].runInput(new Float32Array(this.outputSize))}},{key:"formatData",value:function(t){var r=_lookup2.default.dataShape(t).join(","),e=[];switch(r){case"array,number":if(1!==this.inputSize)throw new Error("inputSize must be 1 for this data size");if(1!==this.outputSize)throw new Error("outputSize must be 1 for this data size");for(var u=0;u<t.length;u++)e.push(Float32Array.from([t[u]]));return[e];case"array,array,number":if(1===this.inputSize&&1===this.outputSize){for(var n=0;n<t.length;n++)e.push((0,_cast.arrayToFloat32Arrays)(t[n]));return e}if(this.inputSize!==t[0].length)throw new Error("inputSize must match data input size");if(this.outputSize!==t[0].length)throw new Error("outputSize must match data input size");for(var o=0;o<t.length;o++)e.push(Float32Array.from(t[o]));return[e];case"array,object,number":if(1!==this.inputSize)throw new Error("inputSize must be 1 for this data size");if(1!==this.outputSize)throw new Error("outputSize must be 1 for this data size");if(!this.inputLookup){var a=new _lookupTable3.default(t);this.inputLookup=this.outputLookup=a.table,this.inputLookupLength=this.outputLookupLength=a.length}for(var i=0;i<t.length;i++)e.push((0,_cast.objectToFloat32Arrays)(t[i]));return e;case"array,datum,array,number":if(1!==this.inputSize)throw new Error("inputSize must be 1 for this data size");if(1!==this.outputSize)throw new Error("outputSize must be 1 for this data size");for(var s=0;s<t.length;s++){var p=t[s];e.push({input:(0,_cast.arrayToFloat32Arrays)(p.input),output:(0,_cast.arrayToFloat32Arrays)(p.output)})}return e;case"array,datum,object,number":if(1!==this.inputSize)throw new Error("inputSize must be 1 for this data size");if(1!==this.outputSize)throw new Error("outputSize must be 1 for this data size");if(!this.inputLookup){var h=new _lookupTable3.default(t,"input");this.inputLookup=h.table,this.inputLookupLength=h.length}if(!this.outputLookup){var l=new _lookupTable3.default(t,"output");this.outputLookup=l.table,this.outputLookupLength=l.length}for(var f=0;f<t.length;f++){var c=t[f];e.push({input:(0,_cast.objectToFloat32Arrays)(c.input),output:(0,_cast.objectToFloat32Arrays)(c.output)})}return e;case"array,array,array,number":for(var d=0;d<t.length;d++)e.push((0,_cast.arraysToFloat32Arrays)(t[d]));return e;case"array,array,object,number":if(!this.inputLookup){var g=new _lookupTable3.default(t);this.inputLookup=this.outputLookup=g.table,this.inputLookupLength=this.outputLookupLength=g.length}for(var k=0;k<t.length;k++){for(var y=[],b=0;b<t[k].length;b++)y.push((0,_cast.objectToFloat32Array)(t[k][b],this.inputLookup,this.inputLookupLength));e.push(y)}return e;case"array,datum,array,array,number":if(1===this.inputSize&&1===this.outputSize)for(var v=0;v<t.length;v++){var m=t[v];e.push({input:Float32Array.from(m.input),output:Float32Array.from(m.output)})}else{if(this.inputSize!==t[0].input[0].length)throw new Error("inputSize must match data input size");if(this.outputSize!==t[0].output[0].length)throw new Error("outputSize must match data output size");for(var L=0;L<t.length;L++){var _=t[L];e.push({input:(0,_cast.arraysToFloat32Arrays)(_.input),output:(0,_cast.arraysToFloat32Arrays)(_.output)})}}return e;case"array,datum,array,object,number":if(!this.inputLookup){var w=new _arrayLookupTable2.default(t,"input");this.inputLookup=w.table,this.inputLookupLength=w.length}if(!this.outputLookup){var S=new _arrayLookupTable2.default(t,"output");this.outputLookup=S.table,this.outputLookupLength=S.length}for(var z=0;z<t.length;z++){var O=t[z];e.push({input:(0,_cast.objectsToFloat32Arrays)(O.input,this.inputLookup,this.inputLookupLength),output:(0,_cast.objectsToFloat32Arrays)(O.output,this.outputLookup,this.outputLookupLength)})}return e;default:throw new Error("unknown data shape or configuration")}}},{key:"test",value:function(t){var r=this.formatData(t),e=[],u=0;switch(_lookup2.default.dataShape(t).join(",")){case"array,array,number":if(1===this.inputSize){for(var n=0;n<r.length;n++){var o=r[n],a=this.run(o.splice(0,o.length-1)),i=o[o.length-1][0],s=i-a,p=s*s;if(u+=p,Math.abs(p)>this.trainOpts.errorThresh){var h=t[n];Object.assign(h,{value:o,actual:a}),e.push(h)}}break}throw new Error("unknown data shape or configuration");case"array,array,array,number":for(var l=0;l<r.length;l++){for(var f=r[l],c=this.run(f.splice(0,f.length-1)),d=f[f.length-1],g=0,k=0,y=0;y<c.length;y++){k++;var b=d[y]-c[y];g+=b*b}if(u+=g/k,Math.abs(g)>this.trainOpts.errorThresh){var v=t[l];e.push({value:v,actual:c})}}break;case"array,object,number":for(var m=0;m<r.length;m++){var L=r[m],_=this.run(_lookup2.default.toObjectPartial(this.outputLookup,L,0,L.length-1)),w=L[L.length-1],S=0,z=void 0;for(z in _);var O=w[m]-_[z];if(S+=O*O,u+=S,Math.abs(S)>this.trainOpts.errorThresh){var j=t[m];e.push({value:j,actual:_})}}break;case"array,array,object,number":for(var q=0;q<r.length;q++){var x=r[q],I=this.run(x.slice(0,x.length-1)),T=t[q][x.length-1],E=0,N=0;for(var A in I){var F=T[A]-I[A];E+=F*F,N++}if(u+=E/N,Math.abs(E)>this.trainOpts.errorThresh){var C=t[q];e.push({value:C,actual:I})}}break;case"array,datum,array,number":case"array,datum,object,number":for(var R=0;R<r.length;R++){for(var M=r[R],D=this.forecast(M.input,M.output.length),P=0,J=0,K=0;K<D.length;K++){var H=M.output[K][0]-D[K];P+=H*H,J++}if(u+=P/J,Math.abs(P)>this.trainOpts.errorThresh){var V=t[R];Object.assign(V,{actual:this.outputLookup?_lookup2.default.toObject(this.outputLookup,D):D}),e.push(V)}}break;case"array,datum,array,array,number":for(var Z=0;Z<r.length;Z++){for(var B=r[Z],G=this.forecast(B.input,B.output.length),Q=0,U=0;U<G.length;U++)for(var W=0;W<G[U].length;W++){var X=B.output[U][W]-G[U][W];Q+=X*X}if(u+=Q,Math.abs(Q)>this.trainOpts.errorThresh){var Y=t[Z];e.push({input:Y.input,output:Y.output,actual:G})}}break;case"array,datum,array,object,number":for(var $=0;$<r.length;$++){for(var tt=r[$],rt=this.forecast(tt.input,tt.output.length),et=0,ut=0;ut<rt.length;ut++)for(var nt in rt[ut]){var ot=t[$].output[ut][nt]-rt[ut][nt];et+=ot*ot}if(u+=et,Math.abs(et)>this.trainOpts.errorThresh){var at=t[$];e.push({input:at.input,output:at.output,actual:rt})}}break;default:throw new Error("unknown data shape or configuration")}return{error:u/r.length,misclasses:e,total:r.length}}},{key:"addFormat",value:function(t){switch(_lookup2.default.dataShape(t).join(",")){case"array,array,number":case"datum,array,array,number":case"array,number":case"datum,array,number":return;case"datum,object,number":this.inputLookup=_lookup2.default.addKeys(t.input,this.inputLookup),this.inputLookup&&(this.inputLookupLength=Object.keys(this.inputLookup).length),this.outputLookup=_lookup2.default.addKeys(t.output,this.outputLookup),this.outputLookup&&(this.outputLookupLength=Object.keys(this.outputLookup).length);break;case"object,number":this.inputLookup=this.outputLookup=_lookup2.default.addKeys(t,this.inputLookup),this.inputLookup&&(this.inputLookupLength=this.outputLookupLength=Object.keys(this.inputLookup).length);break;case"array,object,number":for(var r=0;r<t.length;r++)this.inputLookup=this.outputLookup=_lookup2.default.addKeys(t[r],this.inputLookup),this.inputLookup&&(this.inputLookupLength=this.outputLookupLength=Object.keys(this.inputLookup).length);break;case"datum,array,object,number":for(var e=0;e<t.input.length;e++)this.inputLookup=_lookup2.default.addKeys(t.input[e],this.inputLookup),this.inputLookup&&(this.inputLookupLength=Object.keys(this.inputLookup).length);for(var u=0;u<t.output.length;u++)this.outputLookup=_lookup2.default.addKeys(t.output[u],this.outputLookup),this.outputLookup&&(this.outputLookupLength=Object.keys(this.outputLookup).length);break;default:throw new Error("unknown data shape or configuration")}}},{key:"toJSON",value:function(){var t=this.constructor.defaults;this.model||this.initialize();var r=this.model,e={};for(var u in t)t.hasOwnProperty(u)&&(e[u]=this[u]);return{type:this.constructor.name,options:e,hiddenLayers:r.hiddenLayers.map(function(t){var r={};for(var e in t)r[e]=t[e].toJSON();return r}),outputConnector:this.model.outputConnector.toJSON(),output:this.model.output.toJSON()}}},{key:"fromJSON",value:function(t){var r=this.constructor.defaults,e=t.options;this.model=null,this.hiddenLayers=null;var u=[],n=[];(t.hiddenLayers||t.hiddenSizes).forEach(function(t){var r={};for(var e in t)r[e]=_matrix2.default.fromJSON(t[e]),u.push(r[e]);n.push(r)});var o=_matrix2.default.fromJSON(t.outputConnector);u.push(o);var a=_matrix2.default.fromJSON(t.output);u.push(a),Object.assign(this,r,e),e.hiddenSizes&&(this.hiddenLayers=e.hiddenSizes),this.model={hiddenLayers:n,output:a,allMatrices:u,outputConnector:o,equations:[],equationConnections:[]},this.initialLayerInputs=this.hiddenLayers.map(function(t){return new _matrix2.default(t,1)}),this.bindEquation()}},{key:"toFunction",value:function(){function t(t,e){for(var u=0,n=l.length;u<n;u++){var o=l[u];if(u===e){var a=r(t);switch(t){case o.left:if(a>-1)return"typeof prevStates["+a+"] === 'object' ? prevStates["+a+"].product : new Matrix("+t.rows+", "+t.columns+")";case o.right:if(a>-1)return"typeof prevStates["+a+"] === 'object' ? prevStates["+a+"].product : new Matrix("+t.rows+", "+t.columns+")";case o.product:return"new Matrix("+t.rows+", "+t.columns+")";default:throw Error("unknown state")}}if(t===o.product)return"states["+u+"].product";if(t===o.right)return"states["+u+"].right";if(t===o.left)return"states["+u+"].left"}}function r(t){for(var r=u.equationConnections[0],e=n[0].states,o=0,a=e.length;o<a;o++)if(e[o].product===t)return o;return r.indexOf(t)}function e(r,e){if(!r||!r.rows||!r.columns)return"null";if(r===u.outputConnector)return"json.outputConnector";if(r===u.output)return"json.output";for(var n=0,o=u.hiddenLayers.length;n<o;n++){var a=u.hiddenLayers[n];for(var i in a)if(a.hasOwnProperty(i)&&a[i]===r)return"json.hiddenLayers["+n+"]."+i}return t(r,e)}for(var u=this.model,n=this.model.equations,o=this.inputSize,a=this.inputLookup,i=this.inputLookupLength,s=this.outputLookup,p=this.outputLookupLength,h=n[1],l=h.states,f=JSON.stringify(this.toJSON()),c=[],d={},g=[],k=0,y=l.length;k<y;k++){var b=l[k];c.push("states["+k+"] = {\n name: '"+b.forwardFn.name+"',\n left: "+e(b.left,k)+",\n right: "+e(b.right,k)+",\n product: "+e(b.product,k)+"\n }");var v=b.forwardFn.name;d[v]||(d[v]=!0,g.push(" case '"+v+"':"+("forwardFn"!==v?" //compiled from "+function(t){return"src/recurrent/matrix/"+t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})+".js"}(v):"")+"\n "+function(t){return t=t.toString().split("{"),t.shift(),t=t.join("{"),t=t.split("}"),t.pop(),t.join("}").split("\n").join("\n ").replace("product.weights = _input.weights = _this.inputValue;",a&&1===o?"product.weights = _i < input.length ? input[_i]: prevStates[prevStates.length - 1].product.weights;":1===o?"product.weights = [input[_i]];":"product.weights = input[_i];").replace("product.deltas[i] = 0;","").replace("product.deltas[column] = 0;","").replace("left.deltas[leftIndex] = 0;","").replace("right.deltas[rightIndex] = 0;","").replace("product.deltas = left.deltas.slice(0);","")}(b.forwardFn.toString())+"\n break;"))}var m=1===this.inputSize&&this.outputLookup,L="\n var input = "+(this.inputLookup?"lookupInput(rawInput)":"rawInput")+";\n var json = "+f+";\n var output = [];\n var states = [];\n var prevStates;\n var state;\n var max = "+(m?a===s?i:"input.length + "+(p-1):"input.length")+";\n for (var _i = 0; _i < max; _i++) {\n prevStates = states;\n states = [];\n "+c.join(";\n ")+";\n for (var stateIndex = 0, stateMax = "+c.length+"; stateIndex < stateMax; stateIndex++) {\n state = states[stateIndex];\n var product = state.product;\n var left = state.left;\n var right = state.right;\n \n switch (state.name) {\n"+g.join("\n")+"\n }\n }\n "+(1===o&&a?"if (_i >= input.length - 1) { output.push(state.product.weights); }":"output = state.product.weights;")+"\n }\n "+(s?s===a?"return lookupOutputPartial(output, input)":"return lookupOutput(output)":1===o?"return output[0]":"return output")+";\n "+function(){return a?1===o?a===s?"function lookupInput(input) {\n var table = "+JSON.stringify(a)+";\n var result = [];\n for (var p in table) {\n if (!input.hasOwnProperty(p)) break;\n result.push(Float32Array.from([input[p]]));\n }\n return result;\n }":"function lookupInput(input) {\n var table = "+JSON.stringify(a)+";\n var result = [];\n for (var p in table) {\n result.push(Float32Array.from([input[p]]));\n }\n return result;\n }":"function lookupInput(rawInputs) {\n var table = "+JSON.stringify(a)+";\n var result = [];\n for (var i = 0; i < rawInputs.length; i++) {\n var rawInput = rawInputs[i];\n var input = new Float32Array("+i+");\n for (var p in table) {\n input[table[p]] = rawInput.hasOwnProperty(p) ? rawInput[p] : 0;\n }\n result.push(input);\n }\n return result;\n }":""}()+"\n "+function(){return s?1===o?a===s?"function lookupOutputPartial(output, input) {\n var table = "+JSON.stringify(s)+";\n var offset = input.length;\n var result = {};\n var i = 0;\n for (var p in table) {\n if (i++ < offset) continue;\n result[p] = output[table[p] - offset][0];\n }\n return result;\n }":"function lookupOutput(output) {\n var table = "+JSON.stringify(s)+";\n var result = {};\n for (var p in table) {\n result[p] = output[table[p]][0];\n }\n return result;\n }":"function lookupOutput(output) {\n var table = "+JSON.stringify(s)+";\n var result = {};\n for (var p in table) {\n result[p] = output[table[p]];\n }\n return result;\n }":""}()+"\n \n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n "+_zeros2.default.toString()+"\n "+_softmax2.default.toString().replace("_2.default","Matrix")+"\n "+_random.randomF.toString()+"\n "+_sampleI2.default.toString()+"\n "+_maxI2.default.toString();return new Function("rawInput",L)}}]),r}(_rnn2.default);exports.default=RNNTimeStep,RNNTimeStep.defaults={inputSize:1,hiddenLayers:[20],outputSize:1,learningRate:_rnn2.default.defaults.learningRate,decayRate:_rnn2.default.defaults.decayRate,smoothEps:_rnn2.default.defaults.smoothEps,regc:_rnn2.default.defaults.regc,clipval:_rnn2.default.defaults.clipval},RNNTimeStep.trainDefaults=_rnn2.default.trainDefaults;
},{"../lookup":3,"../utilities/array-lookup-table":37,"../utilities/cast":38,"../utilities/lookup-table":40,"../utilities/random":45,"../utilities/zeros":50,"./matrix":16,"./matrix/equation":15,"./matrix/max-i":17,"./matrix/random-matrix":23,"./matrix/sample-i":28,"./matrix/softmax":31,"./rnn":35}],35:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),_matrix=require("./matrix"),_matrix2=_interopRequireDefault(_matrix),_randomMatrix=require("./matrix/random-matrix"),_randomMatrix2=_interopRequireDefault(_randomMatrix),_equation=require("./matrix/equation"),_equation2=_interopRequireDefault(_equation),_sampleI=require("./matrix/sample-i"),_sampleI2=_interopRequireDefault(_sampleI),_maxI=require("./matrix/max-i"),_maxI2=_interopRequireDefault(_maxI),_softmax=require("./matrix/softmax"),_softmax2=_interopRequireDefault(_softmax),_copy=require("./matrix/copy"),_copy2=_interopRequireDefault(_copy),_random=require("../utilities/random"),_zeros=require("../utilities/zeros"),_zeros2=_interopRequireDefault(_zeros),_dataFormatter=require("../utilities/data-formatter"),_dataFormatter2=_interopRequireDefault(_dataFormatter),_neuralNetwork=require("../neural-network"),_neuralNetwork2=_interopRequireDefault(_neuralNetwork),RNN=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,t);var r=this.constructor.defaults;Object.assign(this,r,e),this.trainOpts={},this.updateTrainingOptions(Object.assign({},this.constructor.trainDefaults,e)),this.stepCache={},this.runs=0,this.ratioClipped=null,this.model=null,this.inputLookup=null,this.inputLookupLength=null,this.outputLookup=null,this.outputLookupLength=null,e.json&&this.fromJSON(e.json)}return _createClass(t,[{key:"initialize",value:function(){this.model={input:null,hiddenLayers:[],output:null,equations:[],allMatrices:[],equationConnections:[],outputConnector:null},this.dataFormatter&&(this.inputSize=this.inputRange=this.outputSize=this.dataFormatter.characters.length),this.mapModel()}},{key:"createHiddenLayers",value:function(){this.model.hiddenLayers.push(this.getModel(this.hiddenLayers[0],this.inputSize));for(var t=this.hiddenLayers[0],e=1;e<this.hiddenLayers.length;e++){var r=this.hiddenLayers[e];this.model.hiddenLayers.push(this.getModel(r,t)),t=r}}},{key:"getModel",value:function(t,e){return{weight:new _randomMatrix2.default(t,e,.08),transition:new _randomMatrix2.default(t,t,.08),bias:new _matrix2.default(t,1)}}},{key:"getEquation",value:function(t,e,r,n){var a=t.relu.bind(t),i=t.add.bind(t),o=t.multiply.bind(t);return a(i(i(o(n.weight,e),o(n.transition,r)),n.bias))}},{key:"createInputMatrix",value:function(){this.model.input=new _randomMatrix2.default(this.inputRange+1,this.inputSize,.08)}},{key:"createOutputMatrix",value:function(){var t=this.model,e=this.outputSize,r=this.hiddenLayers[this.hiddenLayers.length-1];t.outputConnector=new _randomMatrix2.default(e+1,r,.08),t.output=new _matrix2.default(e+1,1)}},{key:"bindEquation",value:function(){var t=this.model,e=new _equation2.default,r=[],n=t.equationConnections.length>0?t.equationConnections[t.equationConnections.length-1]:this.initialLayerInputs,a=this.getEquation(e,e.inputMatrixToRow(t.input),n[0],t.hiddenLayers[0]);r.push(a);for(var i=1,o=this.hiddenLayers.length;i<o;i++)a=this.getEquation(e,a,n[i],t.hiddenLayers[i]),r.push(a);t.equationConnections.push(r),e.add(e.multiply(t.outputConnector,a),t.output),t.equations.push(e)}},{key:"mapModel",value:function(){var t=this.model,e=t.hiddenLayers,r=t.allMatrices;if(this.initialLayerInputs=this.hiddenLayers.map(function(t){return new _matrix2.default(t,1)}),this.createInputMatrix(),!t.input)throw new Error("net.model.input not set");if(r.push(t.input),this.createHiddenLayers(),!t.hiddenLayers.length)throw new Error("net.hiddenLayers not set");for(var n=0,a=e.length;n<a;n++){var i=e[n];for(var o in i)i.hasOwnProperty(o)&&r.push(i[o])}if(this.createOutputMatrix(),!t.outputConnector)throw new Error("net.model.outputConnector not set");if(!t.output)throw new Error("net.model.output not set");r.push(t.outputConnector),r.push(t.output)}},{key:"trainPattern",value:function(t,e){var r=this.trainInput(t);if(this.backpropagate(t),this.adjustWeights(),e)return r}},{key:"trainInput",value:function(t){this.runs++;for(var e=this.model,r=t.length,n=0,a=void 0;e.equations.length<=t.length+1;)this.bindEquation();for(var i=-1,o=t.length;i<o;i++){var u=i+1;a=e.equations[u];var s=-1===i?0:t[i]+1,l=i===r-1?0:t[i+1]+1;n+=a.predictTargetIndex(s,l)}return Math.pow(2,n/(r-1))/100}},{key:"backpropagate",value:function(t){for(var e=t.length,r=this.model,n=r.equations;e>0;)n[e].backpropagateIndex(t[e-1]+1),e--;n[0].backpropagateIndex(0)}},{key:"adjustWeights",value:function(){for(var t=this.regc,e=this.clipval,r=this.model,n=this.decayRate,a=this.stepCache,i=this.smoothEps,o=this.trainOpts,u=o.learningRate,s=r.allMatrices,l=0,h=0,d=0;d<s.length;d++){var p=s[d],f=p.weights,c=p.deltas;d in a||(a[d]=(0,_zeros2.default)(p.rows*p.columns));for(var m=a[d],g=0;g<f.length;g++){var v=c[g],y=f[g];m[g]=m[g]*n+(1-n)*v*v,v>e&&(v=e,l++),v<-e&&(v=-e,l++),h++,f[g]=y+-u*v/Math.sqrt(m[g]+i)-t*y}}this.ratioClipped=l/h}},{key:"run",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,n=this.maxPredictionLength+t.length+(this.dataFormatter?this.dataFormatter.specialIndexes.length:0);if(!this.isRunnable)return null;for(var a=this.formatDataIn(t),i=this.model,o=[],u=0;;){for(var s=0===u?0:u<a.length?a[u-1]+1:o[u-1];i.equations.length<=u;)this.bindEquation();var l=i.equations[u],h=l.runIndex(s),d=new _matrix2.default(i.output.rows,i.output.columns);if((0,_copy2.default)(d,h),1!==r&&e)for(var p=0,f=d.weights.length;p<f;p++)d.weights[p]/=r;var c=(0,_softmax2.default)(d),m=e?(0,_sampleI2.default)(c):(0,_maxI2.default)(c);if(u++,0===m)break;if(u>=n)break;o.push(m)}return this.formatDataOut(a,o.slice(a.length).map(function(t){return t-1}))}},{key:"verifyIsInitialized",value:function(t){this.model||this.initialize()}},{key:"updateTrainingOptions",value:function(t){var e=this;Object.keys(this.constructor.trainDefaults).forEach(function(r){return e.trainOpts[r]=t.hasOwnProperty(r)?t[r]:e.trainOpts[r]}),this.validateTrainingOptions(this.trainOpts),this.setLogMethod(t.log||this.trainOpts.log),this.activation=t.activation||this.activation}},{key:"validateTrainingOptions",value:function(t){_neuralNetwork2.default.prototype.validateTrainingOptions.call(this,t)}},{key:"setLogMethod",value:function(t){this.trainOpts.log="function"==typeof t?t:!!t&&console.log}},{key:"prepTraining",value:function(t,e){this.updateTrainingOptions(e),t=this.formatData(t);var r=Date.now()+this.trainOpts.timeout,n={error:1,iterations:0};return this.verifyIsInitialized(t),{data:t,status:n,endTime:r}}},{key:"train",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.trainOpts=e=Object.assign({},this.constructor.trainDefaults,e);var r=e.iterations,n=e.errorThresh,a=!0===e.log?console.log:e.log,i=e.logPeriod,o=e.callback,u=e.callbackPeriod,s=1/0,l=void 0;for(this.hasOwnProperty("setupData")&&(t=this.setupData(t)),this.verifyIsInitialized(),l=0;l<r&&s>n;l++){for(var h=0,d=0;d<t.length;d++){h+=this.trainPattern(t[d],!0)}if(s=h/t.length,isNaN(s))throw new Error("network error rate is unexpected NaN, check network configurations and try again");a&&l%i==0&&a("iterations: "+l+", training error: "+s),o&&l%u==0&&o({error:s,iterations:l})}return{error:s,iterations:l}}},{key:"addFormat",value:function(){throw new Error("not yet implemented")}},{key:"toJSON",value:function(){var t=this.constructor.defaults;this.model||this.initialize();var e=this.model,r={};for(var n in t)t.hasOwnProperty(n)&&(r[n]=this[n]);return{type:this.constructor.name,options:r,input:e.input.toJSON(),hiddenLayers:e.hiddenLayers.map(function(t){var e={};for(var r in t)e[r]=t[r].toJSON();return e}),outputConnector:this.model.outputConnector.toJSON(),output:this.model.output.toJSON()}}},{key:"fromJSON",value:function(t){var e=this.constructor.defaults,r=t.options;this.model=null,this.hiddenLayers=null;var n=[],a=_matrix2.default.fromJSON(t.input);n.push(a);var i=[];(t.hiddenLayers||t.hiddenSizes).forEach(function(t){var e={};for(var r in t)e[r]=_matrix2.default.fromJSON(t[r]),n.push(e[r]);i.push(e)});var o=_matrix2.default.fromJSON(t.outputConnector);n.push(o);var u=_matrix2.default.fromJSON(t.output);n.push(u),Object.assign(this,e,r),r.hiddenSizes&&(this.hiddenLayers=r.hiddenSizes),r.dataFormatter&&(this.dataFormatter=_dataFormatter2.default.fromJSON(r.dataFormatter)),this.model={input:a,hiddenLayers:i,output:u,allMatrices:n,outputConnector:o,equations:[],equationConnections:[]},this.initialLayerInputs=this.hiddenLayers.map(function(t){return new _matrix2.default(t,1)}),this.bindEquation()}},{key:"toFunction",value:function(){function t(t,r){for(var n=0,a=u.length;n<a;n++){var i=u[n];if(n===r){var o=e(t);switch(t){case i.left:if(o>-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.right:if(o>-1)return"typeof prevStates["+o+"] === 'object' ? prevStates["+o+"].product : new Matrix("+t.rows+", "+t.columns+")";case i.product:return"new Matrix("+t.rows+", "+t.columns+")";default:throw Error("unknown state")}}if(t===i.product)return"states["+n+"].product";if(t===i.right)return"states["+n+"].right";if(t===i.left)return"states["+n+"].left"}}function e(t){for(var e=a.equationConnections[0],r=i[0].states,n=0,o=r.length;n<o;n++)if(r[n].product===t)return n;return e.indexOf(t)}function r(e,r){if(!e||!e.rows||!e.columns)return"null";if(e===a.input)return"json.input";if(e===a.outputConnector)return"json.outputConnector";if(e===a.output)return"json.output";for(var n=0,i=a.hiddenLayers.length;n<i;n++){var o=a.hiddenLayers[n];for(var u in o)if(o.hasOwnProperty(u)&&o[u]===e)return"json.hiddenLayers["+n+"]."+u}return t(e,r)}function n(t){return t=t.toString().split("{"),t.shift(),t=t.join("{"),t=t.split("}"),t.pop(),t.join("}").split("\n").join("\n ").replace("product.deltas[i] = 0;","").replace("product.deltas[column] = 0;","").replace("left.deltas[leftIndex] = 0;","").replace("right.deltas[rightIndex] = 0;","").replace("product.deltas = left.deltas.slice(0);","")}for(var a=this.model,i=this.model.equations,o=i[1],u=o.states,s=JSON.stringify(this.toJSON()),l=[],h={},d=[],p=0,f=u.length;p<f;p++){var c=u[p];l.push("states["+p+"] = {\n name: '"+c.forwardFn.name+"',\n left: "+r(c.left,p)+",\n right: "+r(c.right,p)+",\n product: "+r(c.product,p)+"\n }");var m=c.forwardFn.name;h[m]||(h[m]=!0,d.push(" case '"+m+"': //compiled from "+function(t){return"src/recurrent/matrix/"+t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})+".js"}(m)+"\n "+n(c.forwardFn.toString())+"\n break;"))}var g="\n if (typeof rawInput === 'undefined') rawInput = [];\n if (typeof isSampleI === 'undefined') isSampleI = false;\n if (typeof temperature === 'undefined') temperature = 1;\n "+(this.dataFormatter?this.dataFormatter.toFunctionString():"")+"\n \n var input = "+(this.dataFormatter&&"function"==typeof this.formatDataIn?"formatDataIn(rawInput)":"rawInput")+";\n var json = "+s+";\n var maxPredictionLength = input.length + "+this.maxPredictionLength+";\n var _i = 0;\n var output = [];\n var states = [];\n var prevStates;\n while (true) {\n var previousIndex = (_i === 0\n ? 0\n : _i < input.length\n ? input[_i - 1] + 1\n : output[_i - 1])\n ;\n var rowPluckIndex = previousIndex;\n var state;\n prevStates = states;\n states = [];\n "+l.join(";\n ")+";\n for (var stateIndex = 0, stateMax = "+l.length+"; stateIndex < stateMax; stateIndex++) {\n state = states[stateIndex];\n var product = state.product;\n var left = state.left;\n var right = state.right;\n \n switch (state.name) {\n"+d.join("\n")+"\n }\n }\n \n var logProbabilities = state.product;\n if (temperature !== 1 && isSampleI) {\n for (var q = 0, nq = logProbabilities.weights.length; q < nq; q++) {\n logProbabilities.weights[q] /= temperature;\n }\n }\n\n var probs = softmax(logProbabilities);\n var nextIndex = isSampleI ? sampleI(probs) : maxI(probs);\n \n _i++;\n if (nextIndex === 0) {\n break;\n }\n if (_i >= maxPredictionLength) {\n break;\n }\n\n output.push(nextIndex);\n }\n "+(this.dataFormatter&&"function"==typeof this.formatDataOut?"return formatDataOut(input, output.slice(input.length).map(function(value) { return value - 1; }))":"return output.slice(input.length).map(function(value) { return value - 1; })")+";\n function Matrix(rows, columns) {\n this.rows = rows;\n this.columns = columns;\n this.weights = zeros(rows * columns);\n }\n "+(this.dataFormatter&&"function"==typeof this.formatDataIn?"function formatDataIn(input, output) { "+n(this.formatDataIn.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+(null!==this.dataFormatter&&"function"==typeof this.formatDataOut?"function formatDataOut(input, output) { "+n(this.formatDataOut.toString()).replace(/this[.]dataFormatter[\n\s]+[.]/g,"").replace(/this[.]dataFormatter[.]/g,"").replace(/this[.]dataFormatter/g,"true")+" }":"")+"\n "+_zeros2.default.toString()+"\n "+_softmax2.default.toString().replace("_2.default","Matrix")+"\n "+_random.randomF.toString()+"\n "+_sampleI2.default.toString()+"\n "+_maxI2.default.toString();return new Function("rawInput","isSampleI","temperature",g)}},{key:"isRunnable",get:function(){return 0!==this.model.equations.length||(console.error("No equations bound, did you run train()?"),!1)}}]),t}();exports.default=RNN,RNN.defaults={inputSize:20,inputRange:20,hiddenLayers:[20,20],outputSize:20,decayRate:.999,smoothEps:1e-8,regc:1e-6,clipval:5,maxPredictionLength:100,setupData:function(t){if(!("string"==typeof t[0]||Array.isArray(t[0])||t[0].hasOwnProperty("input")&&t[0].hasOwnProperty("output")))return t;var e=[],r=[];if("string"==typeof t[0]||Array.isArray(t[0])){if(!this.dataFormatter){for(var n=0;n<t.length;n++)e.push(t[n]);this.dataFormatter=new _dataFormatter2.default(e)}for(var a=0,i=t.length;a<i;a++)r.push(this.formatDataIn(t[a]))}else{if(!this.dataFormatter){for(var o=0;o<t.length;o++)e.push(t[o].input),e.push(t[o].output);this.dataFormatter=_dataFormatter2.default.fromArrayInputOutput(e),this.dataFormatter.addUnrecognized()}for(var u=0,s=t.length;u<s;u++)r.push(this.formatDataIn(t[u].input,t[u].output))}return r},formatDataIn:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return this.dataFormatter?this.dataFormatter.indexTable.hasOwnProperty("stop-input")?this.dataFormatter.toIndexesInputOutput(t,e):this.dataFormatter.toIndexes(t):t},formatDataOut:function(t,e){return this.dataFormatter?this.dataFormatter.toCharacters(e).join(""):e},dataFormatter:null},RNN.trainDefaults={iterations:2e4,errorThresh:.005,log:!1,logPeriod:10,learningRate:.01,callback:null,callbackPeriod:10};
},{"../neural-network":5,"../utilities/data-formatter":39,"../utilities/random":45,"../utilities/zeros":50,"./matrix":16,"./matrix/copy":14,"./matrix/equation":15,"./matrix/max-i":17,"./matrix/random-matrix":23,"./matrix/sample-i":28,"./matrix/softmax":31}],36:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,r,i){return r&&t(e.prototype,r),i&&t(e,i),e}}(),_stream=require("stream"),TrainStream=function(t){function e(t){_classCallCheck(this,e);var r=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{objectMode:!0}));if(t=t||{},!t.neuralNetwork)throw new Error("no neural network specified");var i=t,a=i.neuralNetwork;r.neuralNetwork=a,r.dataFormatDetermined=!1,r.i=0,r.size=0,r.count=0,r.sum=0,r.floodCallback=t.floodCallback,r.doneTrainingCallback=t.doneTrainingCallback,a.updateTrainingOptions(t);var o=a.trainOpts;return r.iterations=o.iterations,r.errorThresh=o.errorThresh,r.log=o.log,r.logPeriod=o.logPeriod,r.callbackPeriod=o.callbackPeriod,r.callback=o.callback,r.on("finish",r.finishStreamIteration.bind(r)),r}return _inherits(e,t),_createClass(e,[{key:"endInputs",value:function(){this.write(!1)}},{key:"_write",value:function(t,e,r){if(!t)return this.emit("finish"),r();if(!this.dataFormatDetermined)return this.size++,this.neuralNetwork.addFormat(t),this.firstDatum=this.firstDatum||t,r();this.count++;var i=this.neuralNetwork.formatData(t);this.sum+=this.neuralNetwork.trainPattern(i[0],!0),r()}},{key:"finishStreamIteration",value:function(){if(this.dataFormatDetermined&&this.size!==this.count&&this.log("This iteration's data length was different from the first."),!this.dataFormatDetermined){var t=this.neuralNetwork.formatData(this.firstDatum);return this.neuralNetwork.verifyIsInitialized(t),this.dataFormatDetermined=!0,void("function"==typeof this.floodCallback&&this.floodCallback())}var e=this.sum/this.size;if(this.log&&this.i%this.logPeriod==0&&this.log("iterations: "+this.i+", training error: "+e),this.callback&&this.i%this.callbackPeriod==0&&this.callback({error:e,iterations:this.i}),this.sum=0,this.count=0,++this.i<this.iterations&&e>this.errorThresh){if("function"==typeof this.floodCallback)return this.floodCallback()}else if("function"==typeof this.doneTrainingCallback)return this.doneTrainingCallback({error:e,iterations:this.i})}}]),e}(_stream.Writable);exports.default=TrainStream;
},{"stream":112}],37:[function(require,module,exports){
"use strict";function ArrayLookupTable(e,r){this.length=0,this.prop=r;for(var t=this.table={},o=0;o<e.length;o++)for(var a=e[o],l=a[r],s=0;s<l.length;s++)for(var h in l[s])t.hasOwnProperty(h)||(t[h]=this.length++)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=ArrayLookupTable;
},{}],38:[function(require,module,exports){
"use strict";function arraysToFloat32Arrays(r){for(var a=[],o=0;o<r.length;o++)a.push(Float32Array.from(r[o]));return a}function arrayToFloat32Arrays(r){for(var a=[],o=0;o<r.length;o++)a.push(Float32Array.from([r[o]]));return a}function arrayToFloat32Array(r){return Float32Array.from(r)}function objectsToFloat32Arrays(r,a,o){for(var t=[],e=0;e<r.length;e++){var y=r[e],s=new Float32Array(o);for(var l in y)y.hasOwnProperty(l)&&(s[a[l]]=y[l]);t.push(s)}return t}function objectToFloat32Arrays(r){var a=[];for(var o in r)a.push(Float32Array.from([r[o]]));return a}function objectToFloat32Array(r,a,o){var t=new Float32Array(o);for(var e in r)r.hasOwnProperty(e)&&(t[a[e]]=r[e]);return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.arraysToFloat32Arrays=arraysToFloat32Arrays,exports.arrayToFloat32Arrays=arrayToFloat32Arrays,exports.arrayToFloat32Array=arrayToFloat32Array,exports.objectsToFloat32Arrays=objectsToFloat32Arrays,exports.objectToFloat32Arrays=objectToFloat32Arrays,exports.objectToFloat32Array=objectToFloat32Array;
},{}],39:[function(require,module,exports){
"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),DataFormatter=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;_classCallCheck(this,e),void 0!==t&&(this.values=t,this.indexTable={},this.characterTable={},this.characters=[],this.specialIndexes=[],this.buildCharactersFromIterable(t),this.buildTables(r))}return _createClass(e,[{key:"buildCharactersFromIterable",value:function(e){for(var t={},r=0,n=e.length;r<n;r++){var a=e[r];if(a.hasOwnProperty("length"))for(var i=0,u=a.length;i<u;i++){var o=a[i];t.hasOwnProperty(o)||(t[o]=!0,this.characters.push(o))}else{var s=e[r];if(t.hasOwnProperty(s))continue;t[r]=!0,this.characters.push(s)}}}},{key:"buildTables",value:function(e){for(var t=this.characters.length,r=0;r<t;r++){var n=this.characters[r];r>=e&&(this.indexTable[n]=r,this.characterTable[r]=n)}}},{key:"toIndexes",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[],n=this.indexTable,a=0,i=e.length;a<i;a++){var u=e[a],o=n[u];if(void 0===o){if(!n.unrecognized)throw new Error('unrecognized character "'+u+'"');o=n.unrecognized}o<t||r.push(o)}return r}},{key:"toIndexesInputOutput",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=void 0;return n="string"==typeof e?this.toIndexes(e.split("").concat(["stop-input","start-output"]),r):this.toIndexes(e.concat(["stop-input","start-output"]),r),null===t?n:"string"==typeof t?n.concat(this.toIndexes(t.split(""),r)):n.concat(this.toIndexes(t,r))}},{key:"toCharacters",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[],n=this.characterTable,a=this.indexTable,i=0,u=e.length;i<u;i++){var o=e[i];if(!(o<t)){var s=n[o];if(void 0===s){if(!a.unrecognized)throw new Error('unrecognized index "'+o+'"');s=n[a.unrecognized]}else null!==s&&r.push(s)}}return r}},{key:"toString",value:function(e,t){return this.toCharacters(e,t).join("")}},{key:"addInputOutput",value:function(){this.addSpecial("stop-input"),this.addSpecial("start-output")}},{key:"addUnrecognized",value:function(){this.addSpecial("unrecognized")}},{key:"addSpecial",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=this.indexTable[e]=this.characters.length;this.characterTable[r]=t,this.specialIndexes.push(this.characters.length),this.characters.push(e)}},{key:"countSpecial",value:function(e){for(var t=0,r=0;r<this.specialIndexes;r++)for(var n=-1;n=e.indexOf(this.specialIndexes[r],n)>-1;)t++;return t}},{key:"toFunctionString",value:function(){return"\nvar characterTable = "+JSON.stringify(this.characterTable)+";\nvar indexTable = "+JSON.stringify(this.indexTable)+";\nvar characters = "+JSON.stringify(this.characters)+";\n"+this.toIndexes.toString().replace(/(let|var) indexTable = this[.]indexTable;\n/,"").replace(/this[.]/g,"")+"\n"+this.toIndexesInputOutput.toString().replace(/this[.]/g,"")+"\n"+this.toCharacters.toString().replace(/(let|var) characterTable = this[.]characterTable;\n/g,"").replace(/this[.]/,"")+"\n"}}],[{key:"fromAllPrintable",value:function(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["\n"],n=32;n<=126;n++)r.push(String.fromCharCode(n));return new e(r,t)}},{key:"fromAllPrintableInputOutput",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["\n"],n=e.fromAllPrintable(t,r);return n.addInputOutput(),n}},{key:"fromStringInputOutput",value:function(t,r){var n,a=(n=String.prototype).concat.apply(n,_toConsumableArray(new Set(t))),i=new e(a,r);return i.addInputOutput(),i}},{key:"fromArrayInputOutput",value:function(t,r){var n=new e(t.filter(function(e,t,r){return r.indexOf(e)===t}).sort(),r);return n.addInputOutput(),n}},{key:"fromString",value:function(t,r){var n;return new e((n=String.prototype).concat.apply(n,_toConsumableArray(new Set(t))),r)}},{key:"fromJSON",value:function(t){var r=new e;return r.indexTable=t.indexTable,r.characterTable=t.characterTable,r.values=t.values,r.characters=t.characters,r.specialIndexes=t.specialIndexes,r}}]),e}();exports.default=DataFormatter;
},{}],40:[function(require,module,exports){
"use strict";function LookupTable(r,e){if(this.length=0,e){this.prop=e;for(var t=this.table={},a=0;a<r.length;a++){var o=r[a],h=o[e];for(var s in h)t.hasOwnProperty(s)||(t[s]=this.length++)}}else if(Array.isArray(r[0]))for(var l=this.table={},i=0;i<r.length;i++)for(var n=r[i],f=0;f<n.length;f++){var v=n[f];for(var p in v)l.hasOwnProperty(p)||(l[p]=this.length++)}else for(var g=this.table={},u=0;u<r.length;u++){var b=r[u];for(var y in b)g.hasOwnProperty(y)||(g[y]=this.length++)}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=LookupTable;
},{}],41:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function max(e){return Math.max.apply(Math,(0,_toArray2.default)(e))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=max;var _toArray=require("./to-array"),_toArray2=_interopRequireDefault(_toArray);
},{"./to-array":48}],42:[function(require,module,exports){
"use strict";function mse(e){for(var t=0,r=0;r<e.length;r++)t+=e[r]*e[r];return t/e.length}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=mse;
},{}],43:[function(require,module,exports){
"use strict";function ones(e){if("undefined"!=typeof Float32Array)return new Float32Array(e).fill(1);for(var r=new Array(e),t=0;t<e;t++)r[t]=1;return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=ones;
},{}],44:[function(require,module,exports){
"use strict";function randomWeight(){return.4*Math.random()-.2}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=randomWeight;
},{}],45:[function(require,module,exports){
"use strict";function randomF(a,r){return Math.random()*(r-a)+a}function randomI(a,r){return Math.floor(Math.random()*(r-a)+a)}function randomN(a,r){return a+gaussRandom()*r}function gaussRandom(){if(gaussRandom.returnV)return gaussRandom.returnV=!1,gaussRandom.vVal;var a=2*Math.random()-1,r=2*Math.random()-1,n=a*a+r*r;if(0==n||n>1)return gaussRandom();var o=Math.sqrt(-2*Math.log(n)/n);return gaussRandom.vVal=r*o,gaussRandom.returnV=!0,a*o}Object.defineProperty(exports,"__esModule",{value:!0}),exports.randomF=randomF,exports.randomI=randomI,exports.randomN=randomN,gaussRandom.returnV=!1,gaussRandom.vVal=0;
},{}],46:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function randos(e){for(var r=new Float32Array(e),t=0;t<e;t++)r[t]=(0,_randomWeight2.default)();return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=randos;var _randomWeight=require("./random-weight"),_randomWeight2=_interopRequireDefault(_randomWeight);
},{"./random-weight":44}],47:[function(require,module,exports){
"use strict";function range(e,r){for(var t=[];e<r;e++)t.push(e);return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=range;
},{}],48:[function(require,module,exports){
"use strict";function toArray(r){if(Array.isArray(r))return r;var e=Object.keys(r),t=new Float32Array(e.length);for(var a in e)t[a]=r[e[a]];return t}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=toArray;
},{}],49:[function(require,module,exports){
"use strict";function _toConsumableArray(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e<t.length;e++)r[e]=t[e];return r}return Array.from(t)}function toSVG(t,e){var r={line:{width:"0.5",color:"black"},inputs:{color:"rgba(0, 128, 0, 0.5)",label:!1},outputs:{color:"rgba(100, 149, 237, 0.5)"},hidden:{color:"rgba(255, 127, 80, 0.5)"},fontSize:"14px",radius:"8",width:"400",height:"250"},i="number"==typeof t.inputSize&&"number"==typeof t.outputSize&&t.inputSize>0&&t.outputSize>0&&[t.inputSize].concat(_toConsumableArray(t.hiddenLayers),[t.outputSize]);if(e=Object.assign(r,e),e.inputs.label=e.inputs.label.length==t.inputSize&&e.inputs.label,i){var o='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="'+e.width+'" height="'+e.height+'">',l=e.width/i.length;return i.forEach(function(t,r){var n=e.height/t;[].concat(_toConsumableArray(Array(t))).forEach(function(t,s){if(0==r)o+='<rect x="'+(l/2-e.radius)+'" y="'+(n/2+s*n-e.radius)+'" width="'+2*e.radius+'" height="'+2*e.radius+'" stroke="black" stroke-width="1" fill="'+e.inputs.color+'" />',o+='<line x1="'+l/4+'" y1="'+(n/2+s*n)+'" x2="'+(l/2-e.radius)+'" y2="'+(n/2+s*n)+'" style="stroke:'+e.line.color+";stroke-width:"+e.line.width+'" />',e.inputs.label&&(o+='<text x="'+l/8+'" y="'+(n/2+s*n-5)+'" fill="black" font-size= "'+e.fontSize+'">'+e.inputs.label[s]+"</text>");else{var a=e.height/i[r-1];r==i.length-1?(o+='<circle cx="'+(l/2+r*l)+'" cy="'+(n/2+s*n)+'" r="'+e.radius+'" stroke="black" stroke-width="1" fill="'+e.outputs.color+'" />',o+='<line x1="'+(l/2+r*l+e.radius)+'" y1="'+(n/2+s*n)+'" x2="'+(l/2+r*l+l/4)+'" y2="'+(n/2+s*n)+'" style="stroke:'+e.line.color+";stroke-width:"+e.line.width+'" />'):o+='<circle cx="'+(l/2+r*l)+'" cy="'+(n/2+s*n)+'" r="'+e.radius+'" stroke="black" stroke-width="1" fill="'+e.hidden.color+'" />';for(var u=0;u<i[r-1];u++)o+='<line x1="'+(l/2+(r-1)*l+e.radius)+'" y1="'+(a/2+u*a)+'" x2="'+(l/2+r*l-e.radius)+'" y2="'+(n/2+s*n)+'" style="stroke:'+e.line.color+";stroke-width:"+e.line.width+'" />'}})}),o+="</svg>"}return!1}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=toSVG;
},{}],50:[function(require,module,exports){
"use strict";function zeros(e){return new Float32Array(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=zeros;
},{}],51:[function(require,module,exports){
var CrossValidate=require("./dist/cross-validate").default,likely=require("./dist/likely").default,lookup=require("./dist/lookup").default,NeuralNetwork=require("./dist/neural-network").default,NeuralNetworkGPU=require("./dist/neural-network-gpu").default,TrainStream=require("./dist/train-stream").default,RNNTimeStep=require("./dist/recurrent/rnn-time-step").default,LSTMTimeStep=require("./dist/recurrent/lstm-time-step").default,GRUTimeStep=require("./dist/recurrent/gru-time-step").default,RNN=require("./dist/recurrent/rnn").default,LSTM=require("./dist/recurrent/lstm").default,GRU=require("./dist/recurrent/gru").default,utilities={max:require("./dist/utilities/max").default,mse:require("./dist/utilities/mse").default,ones:require("./dist/utilities/ones").default,random:require("./dist/utilities/random").default,randomWeight:require("./dist/utilities/random-weight").default,randos:require("./dist/utilities/randos").default,range:require("./dist/utilities/range").default,toArray:require("./dist/utilities/to-array").default,DataFormatter:require("./dist/utilities/data-formatter").default,zeros:require("./dist/utilities/zeros").default,toSVG:require("./dist/utilities/to-svg").default},brain={CrossValidate:CrossValidate,likely:likely,lookup:lookup,NeuralNetwork:NeuralNetwork,NeuralNetworkGPU:NeuralNetworkGPU,TrainStream:TrainStream,recurrent:{RNNTimeStep:RNNTimeStep,LSTMTimeStep:LSTMTimeStep,GRUTimeStep:GRUTimeStep,RNN:RNN,LSTM:LSTM,GRU:GRU},utilities:utilities};"undefined"!=typeof window&&(window.brain=brain),"undefined"!=typeof self&&(self.brain=brain),"undefined"!=typeof module&&(module.exports=brain);
},{"./dist/cross-validate":1,"./dist/likely":2,"./dist/lookup":3,"./dist/neural-network":5,"./dist/neural-network-gpu":4,"./dist/recurrent/gru":7,"./dist/recurrent/gru-time-step":6,"./dist/recurrent/lstm":9,"./dist/recurrent/lstm-time-step":8,"./dist/recurrent/rnn":35,"./dist/recurrent/rnn-time-step":34,"./dist/train-stream":36,"./dist/utilities/data-formatter":39,"./dist/utilities/max":41,"./dist/utilities/mse":42,"./dist/utilities/ones":43,"./dist/utilities/random":45,"./dist/utilities/random-weight":44,"./dist/utilities/randos":46,"./dist/utilities/range":47,"./dist/utilities/to-array":48,"./dist/utilities/to-svg":49,"./dist/utilities/zeros":50}],52:[function(require,module,exports){
"use strict";function getLens(o){var r=o.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=o.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function byteLength(o){var r=getLens(o),e=r[0],t=r[1];return 3*(e+t)/4-t}function _byteLength(o,r,e){return 3*(r+e)/4-e}function toByteArray(o){for(var r,e=getLens(o),t=e[0],n=e[1],u=new Arr(_byteLength(o,t,n)),p=0,a=n>0?t-4:t,h=0;h<a;h+=4)r=revLookup[o.charCodeAt(h)]<<18|revLookup[o.charCodeAt(h+1)]<<12|revLookup[o.charCodeAt(h+2)]<<6|revLookup[o.charCodeAt(h+3)],u[p++]=r>>16&255,u[p++]=r>>8&255,u[p++]=255&r;return 2===n&&(r=revLookup[o.charCodeAt(h)]<<2|revLookup[o.charCodeAt(h+1)]>>4,u[p++]=255&r),1===n&&(r=revLookup[o.charCodeAt(h)]<<10|revLookup[o.charCodeAt(h+1)]<<4|revLookup[o.charCodeAt(h+2)]>>2,u[p++]=r>>8&255,u[p++]=255&r),u}function tripletToBase64(o){return lookup[o>>18&63]+lookup[o>>12&63]+lookup[o>>6&63]+lookup[63&o]}function encodeChunk(o,r,e){for(var t,n=[],u=r;u<e;u+=3)t=(o[u]<<16&16711680)+(o[u+1]<<8&65280)+(255&o[u+2]),n.push(tripletToBase64(t));return n.join("")}function fromByteArray(o){for(var r,e=o.length,t=e%3,n=[],u=0,p=e-t;u<p;u+=16383)n.push(encodeChunk(o,u,u+16383>p?p:u+16383));return 1===t?(r=o[e-1],n.push(lookup[r>>2]+lookup[r<<4&63]+"==")):2===t&&(r=(o[e-2]<<8)+o[e-1],n.push(lookup[r>>10]+lookup[r>>4&63]+lookup[r<<2&63]+"=")),n.join("")}exports.byteLength=byteLength,exports.toByteArray=toByteArray,exports.fromByteArray=fromByteArray;for(var lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i<len;++i)lookup[i]=code[i],revLookup[code.charCodeAt(i)]=i;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;
},{}],53:[function(require,module,exports){
},{}],54:[function(require,module,exports){
(function (global){
"use strict";function typedArraySupport(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(t,e){if(kMaxLength()<e)throw new RangeError("Invalid typed array length");return Buffer.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e),t.__proto__=Buffer.prototype):(null===t&&(t=new Buffer(e)),t.length=e),t}function Buffer(t,e,r){if(!(Buffer.TYPED_ARRAY_SUPPORT||this instanceof Buffer))return new Buffer(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,t)}return from(this,t,e,r)}function from(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?fromArrayBuffer(t,e,r,n):"string"==typeof e?fromString(t,e,r):fromObject(t,e)}function assertSize(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function alloc(t,e,r,n){return assertSize(e),e<=0?createBuffer(t,e):void 0!==r?"string"==typeof n?createBuffer(t,e).fill(r,n):createBuffer(t,e).fill(r):createBuffer(t,e)}function allocUnsafe(t,e){if(assertSize(e),t=createBuffer(t,e<0?0:0|checked(e)),!Buffer.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function fromString(t,e,r){if("string"==typeof r&&""!==r||(r="utf8"),!Buffer.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|byteLength(e,r);t=createBuffer(t,n);var f=t.write(e,r);return f!==n&&(t=t.slice(0,f)),t}function fromArrayLike(t,e){var r=e.length<0?0:0|checked(e.length);t=createBuffer(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function fromArrayBuffer(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n),Buffer.TYPED_ARRAY_SUPPORT?(t=e,t.__proto__=Buffer.prototype):t=fromArrayLike(t,e),t}function fromObject(t,e){if(Buffer.isBuffer(e)){var r=0|checked(e.length);return t=createBuffer(t,r),0===t.length?t:(e.copy(t,0,0,r),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||isnan(e.length)?createBuffer(t,0):fromArrayLike(t,e);if("Buffer"===e.type&&isArray(e.data))return fromArrayLike(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(t){if(t>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|t}function SlowBuffer(t){return+t!=t&&(t=0),Buffer.alloc(+t)}function byteLength(t,e){if(Buffer.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return utf8ToBytes(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return base64ToBytes(t).length;default:if(n)return utf8ToBytes(t).length;e=(""+e).toLowerCase(),n=!0}}function slowToString(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,e>>>=0,r<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return hexSlice(this,e,r);case"utf8":case"utf-8":return utf8Slice(this,e,r);case"ascii":return asciiSlice(this,e,r);case"latin1":case"binary":return latin1Slice(this,e,r);case"base64":return base64Slice(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function swap(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function bidirectionalIndexOf(t,e,r,n,f){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=f?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(f)return-1;r=t.length-1}else if(r<0){if(!f)return-1;r=0}if("string"==typeof e&&(e=Buffer.from(e,n)),Buffer.isBuffer(e))return 0===e.length?-1:arrayIndexOf(t,e,r,n,f);if("number"==typeof e)return e&=255,Buffer.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?f?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):arrayIndexOf(t,[e],r,n,f);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(t,e,r,n,f){function i(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}var o=1,u=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,u/=2,s/=2,r/=2}var a;if(f){var h=-1;for(a=r;a<u;a++)if(i(t,a)===i(e,-1===h?0:a-h)){if(-1===h&&(h=a),a-h+1===s)return h*o}else-1!==h&&(a-=a-h),h=-1}else for(r+s>u&&(r=u-s),a=r;a>=0;a--){for(var c=!0,l=0;l<s;l++)if(i(t,a+l)!==i(e,l)){c=!1;break}if(c)return a}return-1}function hexWrite(t,e,r,n){r=Number(r)||0;var f=t.length-r;n?(n=Number(n))>f&&(n=f):n=f;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var o=0;o<n;++o){var u=parseInt(e.substr(2*o,2),16);if(isNaN(u))return o;t[r+o]=u}return o}function utf8Write(t,e,r,n){return blitBuffer(utf8ToBytes(e,t.length-r),t,r,n)}function asciiWrite(t,e,r,n){return blitBuffer(asciiToBytes(e),t,r,n)}function latin1Write(t,e,r,n){return asciiWrite(t,e,r,n)}function base64Write(t,e,r,n){return blitBuffer(base64ToBytes(e),t,r,n)}function ucs2Write(t,e,r,n){return blitBuffer(utf16leToBytes(e,t.length-r),t,r,n)}function base64Slice(t,e,r){return 0===e&&r===t.length?base64.fromByteArray(t):base64.fromByteArray(t.slice(e,r))}function utf8Slice(t,e,r){r=Math.min(t.length,r);for(var n=[],f=e;f<r;){var i=t[f],o=null,u=i>239?4:i>223?3:i>191?2:1;if(f+u<=r){var s,a,h,c;switch(u){case 1:i<128&&(o=i);break;case 2:s=t[f+1],128==(192&s)&&(c=(31&i)<<6|63&s)>127&&(o=c);break;case 3:s=t[f+1],a=t[f+2],128==(192&s)&&128==(192&a)&&(c=(15&i)<<12|(63&s)<<6|63&a)>2047&&(c<55296||c>57343)&&(o=c);break;case 4:s=t[f+1],a=t[f+2],h=t[f+3],128==(192&s)&&128==(192&a)&&128==(192&h)&&(c=(15&i)<<18|(63&s)<<12|(63&a)<<6|63&h)>65535&&c<1114112&&(o=c)}}null===o?(o=65533,u=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),f+=u}return decodeCodePointsArray(n)}function decodeCodePointsArray(t){var e=t.length;if(e<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=MAX_ARGUMENTS_LENGTH));return r}function asciiSlice(t,e,r){var n="";r=Math.min(t.length,r);for(var f=e;f<r;++f)n+=String.fromCharCode(127&t[f]);return n}function latin1Slice(t,e,r){var n="";r=Math.min(t.length,r);for(var f=e;f<r;++f)n+=String.fromCharCode(t[f]);return n}function hexSlice(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var f="",i=e;i<r;++i)f+=toHex(t[i]);return f}function utf16leSlice(t,e,r){for(var n=t.slice(e,r),f="",i=0;i<n.length;i+=2)f+=String.fromCharCode(n[i]+256*n[i+1]);return f}function checkOffset(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function checkInt(t,e,r,n,f,i){if(!Buffer.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>f||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function objectWriteUInt16(t,e,r,n){e<0&&(e=65535+e+1);for(var f=0,i=Math.min(t.length-r,2);f<i;++f)t[r+f]=(e&255<<8*(n?f:1-f))>>>8*(n?f:1-f)}function objectWriteUInt32(t,e,r,n){e<0&&(e=4294967295+e+1);for(var f=0,i=Math.min(t.length-r,4);f<i;++f)t[r+f]=e>>>8*(n?f:3-f)&255}function checkIEEE754(t,e,r,n,f,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function writeFloat(t,e,r,n,f){return f||checkIEEE754(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),ieee754.write(t,e,r,n,23,4),r+4}function writeDouble(t,e,r,n,f){return f||checkIEEE754(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),ieee754.write(t,e,r,n,52,8),r+8}function base64clean(t){if(t=stringtrim(t).replace(INVALID_BASE64_RE,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function stringtrim(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function toHex(t){return t<16?"0"+t.toString(16):t.toString(16)}function utf8ToBytes(t,e){e=e||1/0;for(var r,n=t.length,f=null,i=[],o=0;o<n;++o){if((r=t.charCodeAt(o))>55295&&r<57344){if(!f){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&i.push(239,191,189);continue}f=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),f=r;continue}r=65536+(f-55296<<10|r-56320)}else f&&(e-=3)>-1&&i.push(239,191,189);if(f=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function asciiToBytes(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function utf16leToBytes(t,e){for(var r,n,f,i=[],o=0;o<t.length&&!((e-=2)<0);++o)r=t.charCodeAt(o),n=r>>8,f=r%256,i.push(f),i.push(n);return i}function base64ToBytes(t){return base64.toByteArray(base64clean(t))}function blitBuffer(t,e,r,n){for(var f=0;f<n&&!(f+r>=e.length||f>=t.length);++f)e[f+r]=t[f];return f}function isnan(t){return t!==t}var base64=require("base64-js"),ieee754=require("ieee754"),isArray=require("isarray");exports.Buffer=Buffer,exports.SlowBuffer=SlowBuffer,exports.INSPECT_MAX_BYTES=50,Buffer.TYPED_ARRAY_SUPPORT=void 0!==global.TYPED_ARRAY_SUPPORT?global.TYPED_ARRAY_SUPPORT:typedArraySupport(),exports.kMaxLength=kMaxLength(),Buffer.poolSize=8192,Buffer._augment=function(t){return t.__proto__=Buffer.prototype,t},Buffer.from=function(t,e,r){return from(null,t,e,r)},Buffer.TYPED_ARRAY_SUPPORT&&(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&Buffer[Symbol.species]===Buffer&&Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:!0})),Buffer.alloc=function(t,e,r){return alloc(null,t,e,r)},Buffer.allocUnsafe=function(t){return allocUnsafe(null,t)},Buffer.allocUnsafeSlow=function(t){return allocUnsafe(null,t)},Buffer.isBuffer=function(t){return!(null==t||!t._isBuffer)},Buffer.compare=function(t,e){if(!Buffer.isBuffer(t)||!Buffer.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,f=0,i=Math.min(r,n);f<i;++f)if(t[f]!==e[f]){r=t[f],n=e[f];break}return r<n?-1:n<r?1:0},Buffer.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(t,e){if(!isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return Buffer.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=Buffer.allocUnsafe(e),f=0;for(r=0;r<t.length;++r){var i=t[r];if(!Buffer.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,f),f+=i.length}return n},Buffer.byteLength=byteLength,Buffer.prototype._isBuffer=!0,Buffer.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)swap(this,e,e+1);return this},Buffer.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)swap(this,e,e+3),swap(this,e+1,e+2);return this},Buffer.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)swap(this,e,e+7),swap(this,e+1,e+6),swap(this,e+2,e+5),swap(this,e+3,e+4);return this},Buffer.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?utf8Slice(this,0,t):slowToString.apply(this,arguments)},Buffer.prototype.equals=function(t){if(!Buffer.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===Buffer.compare(this,t)},Buffer.prototype.inspect=function(){var t="",e=exports.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},Buffer.prototype.compare=function(t,e,r,n,f){if(!Buffer.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===f&&(f=this.length),e<0||r>t.length||n<0||f>this.length)throw new RangeError("out of range index");if(n>=f&&e>=r)return 0;if(n>=f)return-1;if(e>=r)return 1;if(e>>>=0,r>>>=0,n>>>=0,f>>>=0,this===t)return 0;for(var i=f-n,o=r-e,u=Math.min(i,o),s=this.slice(n,f),a=t.slice(e,r),h=0;h<u;++h)if(s[h]!==a[h]){i=s[h],o=a[h];break}return i<o?-1:o<i?1:0},Buffer.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},Buffer.prototype.indexOf=function(t,e,r){return bidirectionalIndexOf(this,t,e,r,!0)},Buffer.prototype.lastIndexOf=function(t,e,r){return bidirectionalIndexOf(this,t,e,r,!1)},Buffer.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var f=this.length-e;if((void 0===r||r>f)&&(r=f),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return hexWrite(this,t,e,r);case"utf8":case"utf-8":return utf8Write(this,t,e,r);case"ascii":return asciiWrite(this,t,e,r);case"latin1":case"binary":return latin1Write(this,t,e,r);case"base64":return base64Write(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;Buffer.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var n;if(Buffer.TYPED_ARRAY_SUPPORT)n=this.subarray(t,e),n.__proto__=Buffer.prototype;else{var f=e-t;n=new Buffer(f,void 0);for(var i=0;i<f;++i)n[i]=this[i+t]}return n},Buffer.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t],f=1,i=0;++i<e&&(f*=256);)n+=this[t+i]*f;return n},Buffer.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t+--e],f=1;e>0&&(f*=256);)n+=this[t+--e]*f;return n},Buffer.prototype.readUInt8=function(t,e){return e||checkOffset(t,1,this.length),this[t]},Buffer.prototype.readUInt16LE=function(t,e){return e||checkOffset(t,2,this.length),this[t]|this[t+1]<<8},Buffer.prototype.readUInt16BE=function(t,e){return e||checkOffset(t,2,this.length),this[t]<<8|this[t+1]},Buffer.prototype.readUInt32LE=function(t,e){return e||checkOffset(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Buffer.prototype.readUInt32BE=function(t,e){return e||checkOffset(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Buffer.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=this[t],f=1,i=0;++i<e&&(f*=256);)n+=this[t+i]*f;return f*=128,n>=f&&(n-=Math.pow(2,8*e)),n},Buffer.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||checkOffset(t,e,this.length);for(var n=e,f=1,i=this[t+--n];n>0&&(f*=256);)i+=this[t+--n]*f;return f*=128,i>=f&&(i-=Math.pow(2,8*e)),i},Buffer.prototype.readInt8=function(t,e){return e||checkOffset(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Buffer.prototype.readInt16LE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt16BE=function(t,e){e||checkOffset(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},Buffer.prototype.readInt32LE=function(t,e){return e||checkOffset(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Buffer.prototype.readInt32BE=function(t,e){return e||checkOffset(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Buffer.prototype.readFloatLE=function(t,e){return e||checkOffset(t,4,this.length),ieee754.read(this,t,!0,23,4)},Buffer.prototype.readFloatBE=function(t,e){return e||checkOffset(t,4,this.length),ieee754.read(this,t,!1,23,4)},Buffer.prototype.readDoubleLE=function(t,e){return e||checkOffset(t,8,this.length),ieee754.read(this,t,!0,52,8)},Buffer.prototype.readDoubleBE=function(t,e){return e||checkOffset(t,8,this.length),ieee754.read(this,t,!1,52,8)},Buffer.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e|=0,r|=0,!n){checkInt(this,t,e,r,Math.pow(2,8*r)-1,0)}var f=1,i=0;for(this[e]=255&t;++i<r&&(f*=256);)this[e+i]=t/f&255;return e+r},Buffer.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e|=0,r|=0,!n){checkInt(this,t,e,r,Math.pow(2,8*r)-1,0)}var f=r-1,i=1;for(this[e+f]=255&t;--f>=0&&(i*=256);)this[e+f]=t/i&255;return e+r},Buffer.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},Buffer.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var f=Math.pow(2,8*r-1);checkInt(this,t,e,r,f-1,-f)}var i=0,o=1,u=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===u&&0!==this[e+i-1]&&(u=1),this[e+i]=(t/o>>0)-u&255;return e+r},Buffer.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var f=Math.pow(2,8*r-1);checkInt(this,t,e,r,f-1,-f)}var i=r-1,o=1,u=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===u&&0!==this[e+i+1]&&(u=1),this[e+i]=(t/o>>0)-u&255;return e+r},Buffer.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},Buffer.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):objectWriteUInt16(this,t,e,!0),e+2},Buffer.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):objectWriteUInt16(this,t,e,!1),e+2},Buffer.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):objectWriteUInt32(this,t,e,!0),e+4},Buffer.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||checkInt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Buffer.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):objectWriteUInt32(this,t,e,!1),e+4},Buffer.prototype.writeFloatLE=function(t,e,r){return writeFloat(this,t,e,!0,r)},Buffer.prototype.writeFloatBE=function(t,e,r){return writeFloat(this,t,e,!1,r)},Buffer.prototype.writeDoubleLE=function(t,e,r){return writeDouble(this,t,e,!0,r)},Buffer.prototype.writeDoubleBE=function(t,e,r){return writeDouble(this,t,e,!1,r)},Buffer.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var f,i=n-r;if(this===t&&r<e&&e<n)for(f=i-1;f>=0;--f)t[f+e]=this[f+r];else if(i<1e3||!Buffer.TYPED_ARRAY_SUPPORT)for(f=0;f<i;++f)t[f+e]=this[f+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},Buffer.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var f=t.charCodeAt(0);f<256&&(t=f)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!Buffer.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0);var i;if("number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var o=Buffer.isBuffer(t)?t:utf8ToBytes(new Buffer(t,n).toString()),u=o.length;for(i=0;i<r-e;++i)this[i+e]=o[i%u]}return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"base64-js":52,"ieee754":91,"isarray":94}],55:[function(require,module,exports){
(function (Buffer){
function isArray(r){return Array.isArray?Array.isArray(r):"[object Array]"===objectToString(r)}function isBoolean(r){return"boolean"==typeof r}function isNull(r){return null===r}function isNullOrUndefined(r){return null==r}function isNumber(r){return"number"==typeof r}function isString(r){return"string"==typeof r}function isSymbol(r){return"symbol"==typeof r}function isUndefined(r){return void 0===r}function isRegExp(r){return"[object RegExp]"===objectToString(r)}function isObject(r){return"object"==typeof r&&null!==r}function isDate(r){return"[object Date]"===objectToString(r)}function isError(r){return"[object Error]"===objectToString(r)||r instanceof Error}function isFunction(r){return"function"==typeof r}function isPrimitive(r){return null===r||"boolean"==typeof r||"number"==typeof r||"string"==typeof r||"symbol"==typeof r||void 0===r}function objectToString(r){return Object.prototype.toString.call(r)}exports.isArray=isArray,exports.isBoolean=isBoolean,exports.isNull=isNull,exports.isNullOrUndefined=isNullOrUndefined,exports.isNumber=isNumber,exports.isString=isString,exports.isSymbol=isSymbol,exports.isUndefined=isUndefined,exports.isRegExp=isRegExp,exports.isObject=isObject,exports.isDate=isDate,exports.isError=isError,exports.isFunction=isFunction,exports.isPrimitive=isPrimitive,exports.isBuffer=Buffer.isBuffer;
}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
},{"../../is-buffer/index.js":93}],56:[function(require,module,exports){
function EventEmitter(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function isFunction(e){return"function"==typeof e}function isNumber(e){return"number"==typeof e}function isObject(e){return"object"==typeof e&&null!==e}function isUndefined(e){return void 0===e}module.exports=EventEmitter,EventEmitter.EventEmitter=EventEmitter,EventEmitter.prototype._events=void 0,EventEmitter.prototype._maxListeners=void 0,EventEmitter.defaultMaxListeners=10,EventEmitter.prototype.setMaxListeners=function(e){if(!isNumber(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},EventEmitter.prototype.emit=function(e){var t,i,n,s,r,o;if(this._events||(this._events={}),"error"===e&&(!this._events.error||isObject(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(i=this._events[e],isUndefined(i))return!1;if(isFunction(i))switch(arguments.length){case 1:i.call(this);break;case 2:i.call(this,arguments[1]);break;case 3:i.call(this,arguments[1],arguments[2]);break;default:s=Array.prototype.slice.call(arguments,1),i.apply(this,s)}else if(isObject(i))for(s=Array.prototype.slice.call(arguments,1),o=i.slice(),n=o.length,r=0;r<n;r++)o[r].apply(this,s);return!0},EventEmitter.prototype.addListener=function(e,t){var i;if(!isFunction(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,isFunction(t.listener)?t.listener:t),this._events[e]?isObject(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,isObject(this._events[e])&&!this._events[e].warned&&(i=isUndefined(this._maxListeners)?EventEmitter.defaultMaxListeners:this._maxListeners)&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.once=function(e,t){function i(){this.removeListener(e,i),n||(n=!0,t.apply(this,arguments))}if(!isFunction(t))throw TypeError("listener must be a function");var n=!1;return i.listener=t,this.on(e,i),this},EventEmitter.prototype.removeListener=function(e,t){var i,n,s,r;if(!isFunction(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],s=i.length,n=-1,i===t||isFunction(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(isObject(i)){for(r=s;r-- >0;)if(i[r]===t||i[r].listener&&i[r].listener===t){n=r;break}if(n<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},EventEmitter.prototype.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],isFunction(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},EventEmitter.prototype.listeners=function(e){return this._events&&this._events[e]?isFunction(this._events[e])?[this._events[e]]:this._events[e].slice():[]},EventEmitter.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(isFunction(t))return 1;if(t)return t.length}return 0},EventEmitter.listenerCount=function(e,t){return e.listenerCount(t)};
},{}],57:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var FunctionBuilderBase=require("../function-builder-base"),CPUFunctionNode=require("./function-node");module.exports=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.Node=CPUFunctionNode,e}return _inherits(t,e),t}(FunctionBuilderBase);
},{"../function-builder-base":62,"./function-node":58}],58:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var s=0;s<e.length;s++){var n=e[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,s,n){return s&&t(e.prototype,s),n&&t(e,n),e}}(),BaseFunctionNode=require("../function-node-base"),utils=require("../../core/utils");module.exports=function(t){function e(t,s,n){_classCallCheck(this,e);var i=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,s,n));return i.paramSizes=n?n.paramSizes:[],i.memberStates=[],i}return _inherits(e,t),_createClass(e,[{key:"pushMemberState",value:function(t){this.memberStates.push(t)}},{key:"popMemberState",value:function(t){if(this.memberState!==t)throw new Error("Cannot popMemberState "+t+" when in "+this.memberState);this.memberStates.pop()}},{key:"generate",value:function(){return this.debug&&console.log(this),this.functionStringArray=this.astGeneric(this.getJsAST(),[]),this.functionString=this.functionStringArray.join("").trim(),this.functionString}},{key:"getFunctionPrototypeString",value:function(){return this.webGlFunctionPrototypeString?this.webGlFunctionPrototypeString:this.webGlFunctionPrototypeString=this.generate()}},{key:"astFunctionDeclaration",value:function(t,e){return this.builder.addFunction(null,utils.getAstString(this.jsFunctionString,t)),e}},{key:"astFunctionPrototype",value:function(t,e){if(this.isRootKernel||this.isSubKernel)return e;e.push(this.returnType),e.push(" "),e.push(this.functionName),e.push("(");for(var s=0;s<this.paramNames.length;++s)s>0&&e.push(", "),e.push("user_"),e.push(this.paramNames[s]);return e.push(");\n"),e}},{key:"astFunctionExpression",value:function(t,e){if(!this.isRootKernel){e.push("function"),e.push(" "),e.push(this.functionName),e.push("(");for(var s=0;s<this.paramNames.length;++s){var n=this.paramNames[s];s>0&&e.push(", "),e.push("user_"),e.push(n)}e.push(") {\n")}for(var i=0;i<t.body.body.length;++i)this.astGeneric(t.body.body[i],e),e.push("\n");return this.isRootKernel||e.push("}\n"),e}},{key:"astReturnStatement",value:function(t,e){return this.isRootKernel?(e.push("kernelResult = "),this.astGeneric(t.argument,e),e.push(";")):this.isSubKernel?(e.push(this.functionName+"Result = "),this.astGeneric(t.argument,e),e.push(";"),e.push("return "+this.functionName+"Result;")):(e.push("return "),this.astGeneric(t.argument,e),e.push(";")),e}},{key:"astLiteral",value:function(t,e){if(isNaN(t.value))throw this.astErrorOutput("Non-numeric literal not supported : "+t.value,t);return e.push(t.value),e}},{key:"astBinaryExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astIdentifierExpression",value:function(t,e){if("Identifier"!==t.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",t);switch(this.state){case"input-index-y":case"input-index-z":e.push("(")}switch(t.name){case"gpu_threadX":e.push("threadId.x");break;case"gpu_threadY":e.push("threadId.y");break;case"gpu_threadZ":e.push("threadId.z");break;case"gpu_outputX":e.push("uOutputDim.x");break;case"gpu_outputY":e.push("uOutputDim.y");break;case"gpu_outputZ":e.push("uOutputDim.z");break;case"Infinity":e.push("Infinity");break;default:if(this.constants&&this.constants.hasOwnProperty(t.name))e.push("constants_"+t.name);else{var s=this.getUserParamName(t.name);null!==s?e.push("user_"+s):e.push("user_"+t.name)}}switch(this.state){case"input-index-y":var n=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+n[0]+")");break;case"input-index-z":var i=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+i[0]*i[1]+")")}return e}},{key:"astForStatement",value:function(t,e){if("ForStatement"!==t.type)throw this.astErrorOutput("Invalid for statement",t);if(t.test&&"BinaryExpression"===t.test.type){if(("Identifier"===t.test.right.type||"Literal"===t.test.right.type)&&"<"===t.test.operator&&!1===this.isIdentifierConstant(t.test.right.name)){if(this.loopMaxIterations||(console.warn("Warning: loopMaxIterations is not set! Using default of 1000 which may result in unintended behavior."),console.warn("Set loopMaxIterations or use a for loop of fixed length to silence this message.")),e.push("for ("),this.astGeneric(t.init,e),";"!==e[e.length-1]&&e.push(";"),this.astGeneric(t.test.left,e),e.push(t.test.operator),e.push("LOOP_MAX"),e.push(";"),this.astGeneric(t.update,e),e.push(")"),e.push("{\n"),e.push("if ("),this.astGeneric(t.test.left,e),e.push(t.test.operator),this.astGeneric(t.test.right,e),e.push(") {\n"),"BlockStatement"===t.body.type)for(var s=0;s<t.body.body.length;s++)this.astGeneric(t.body.body[s],e);else this.astGeneric(t.body,e);return e.push("} else {\n"),e.push("break;\n"),e.push("}\n"),e.push("}\n"),e}if(t.init.declarations){var n=JSON.parse(JSON.stringify(t.init.declarations)),i=t.update.argument;if(!Array.isArray(n)||n.length<1)throw console.log(this.jsFunctionString),new Error("Error: Incompatible for loop declaration");if(n.length>1){for(var r=null,a=0;a<n.length;a++){var u=n[a];u.id.name===i.name?(r=u,n.splice(a,1)):(e.push("var "),this.astGeneric(u,e),e.push(";"))}e.push("for (let "),this.astGeneric(r,e),e.push(";")}else e.push("for ("),this.astGeneric(t.init,e);return this.astGeneric(t.test,e),e.push(";"),this.astGeneric(t.update,e),e.push(")"),this.astGeneric(t.body,e),e}}throw this.astErrorOutput("Invalid for statement",t)}},{key:"astWhileStatement",value:function(t,e){if("WhileStatement"!==t.type)throw this.astErrorOutput("Invalid while statement",t);return e.push("for (let i = 0; i < LOOP_MAX; i++) {"),e.push("if ("),this.astGeneric(t.test,e),e.push(") {\n"),this.astGeneric(t.body,e),e.push("} else {\n"),e.push("break;\n"),e.push("}\n"),e.push("}\n"),e}},{key:"astDoWhileStatement",value:function(t,e){if("DoWhileStatement"!==t.type)throw this.astErrorOutput("Invalid while statement",t);return e.push("for (let i = 0; i < LOOP_MAX; i++) {"),this.astGeneric(t.body,e),e.push("if (!"),this.astGeneric(t.test,e),e.push(") {\n"),e.push("break;\n"),e.push("}\n"),e.push("}\n"),e}},{key:"astAssignmentExpression",value:function(t,e){return this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e}},{key:"astEmptyStatement",value:function(t,e){return e}},{key:"astBlockStatement",value:function(t,e){e.push("{\n");for(var s=0;s<t.body.length;s++)this.astGeneric(t.body[s],e);return e.push("}\n"),e}},{key:"astExpressionStatement",value:function(t,e){return this.astGeneric(t.expression,e),e.push(";"),e}},{key:"astVariableDeclaration",value:function(t,e){e.push("var ");for(var s=0;s<t.declarations.length;s++)this.declarations[t.declarations[s].id.name]="var",s>0&&e.push(","),this.astGeneric(t.declarations[s],e);return e.push(";"),e}},{key:"astVariableDeclarator",value:function(t,e){return this.astGeneric(t.id,e),null!==t.init&&(e.push("="),this.astGeneric(t.init,e)),e}},{key:"astIfStatement",value:function(t,e){return e.push("if ("),this.astGeneric(t.test,e),e.push(")"),"BlockStatement"===t.consequent.type?this.astGeneric(t.consequent,e):(e.push(" {\n"),this.astGeneric(t.consequent,e),e.push("\n}\n")),t.alternate&&(e.push("else "),"BlockStatement"===t.alternate.type?this.astGeneric(t.alternate,e):(e.push(" {\n"),this.astGeneric(t.alternate,e),e.push("\n}\n"))),e}},{key:"astBreakStatement",value:function(t,e){return e.push("break;\n"),e}},{key:"astContinueStatement",value:function(t,e){return e.push("continue;\n"),e}},{key:"astLogicalExpression",value:function(t,e){return e.push("("),this.astGeneric(t.left,e),e.push(t.operator),this.astGeneric(t.right,e),e.push(")"),e}},{key:"astUpdateExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astUnaryExpression",value:function(t,e){return t.prefix?(e.push(t.operator),this.astGeneric(t.argument,e)):(this.astGeneric(t.argument,e),e.push(t.operator)),e}},{key:"astThisExpression",value:function(t,e){return e.push("_this"),e}},{key:"astMemberExpression",value:function(t,e){if(t.computed)if("Identifier"===t.object.type||"MemberExpression"===t.object.type&&t.object.object.object&&"ThisExpression"===t.object.object.object.type&&"constants"===t.object.object.property.name)this.pushState("identifier"),this.astGeneric(t.object,e),this.popState("identifier"),e.push("["),this.isInput(t.object.name),this.astGeneric(t.property,e),e.push("]");else if(t.object.object)if(t.object.object.object&&this.isInput(t.object.object.object.name)){this.pushMemberState(t.object.object.object.name),this.pushState("input-index-z"),this.astGeneric(t.object,e);var s=e.pop();e.push(" + "),this.popState("input-index-z"),this.pushState("input-index"),this.astGeneric(t.property,e),this.popState("input-index"),e.push(s),this.popMemberState(t.object.object.object.name)}else if(this.isInput(t.object.object.name)){this.pushMemberState(t.object.object.name),this.isState("input-index-z")||this.pushState("input-index-y"),this.astGeneric(t.object,e);var n=e.pop();e.push(" + "),this.isState("input-index-z")||this.popState("input-index-y");var i=this.isState("input-index-z");i?this.pushState("input-index-y"):this.pushState("input-index"),this.astGeneric(t.property,e),i?this.popState("input-index-y"):this.popState("input-index"),e.push(n),this.popMemberState(t.object.object.name)}else{this.astGeneric(t.object,e);var r=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(r)}else{this.astGeneric(t.object,e);var a=e.pop();e.push("]["),this.astGeneric(t.property,e),e.push(a)}else{var u=this.astMemberExpressionUnroll(t);switch("Identifier"===t.property.type&&t.computed&&(u="user_"+u),0===u.indexOf("this.constants")?u="constants_"+u.substring(15):0===u.indexOf("this")&&(u="_"+u),this.state){case"input-index-y":case"input-index-z":e.push("(")}switch(u){case"_this.output.x":e.push(this.output[0]);break;case"_this.output.y":e.push(this.output[1]);break;case"_this.output.z":e.push(this.output[2]);break;default:t.object&&t.object.name&&this.declarations[t.object.name]&&e.push("user_"),e.push(u)}switch(this.state){case"input-index-y":var o=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+o[0]+")");break;case"input-index-z":var h=this.paramSizes[this.paramNames.indexOf(this.memberState)];e.push(" * "+h[0]*h[1]+")")}}return e}},{key:"astSequenceExpression",value:function(t,e){for(var s=0;s<t.expressions.length;s++)s>0&&e.push(","),this.astGeneric(t.expressions,e);return e}},{key:"astCallExpression",value:function(t,e){if(t.callee){var s=this.astMemberExpressionUnroll(t.callee);this.calledFunctions.indexOf(s)<0&&this.calledFunctions.push(s),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[s]=[]);var n=[];this.calledFunctionsArguments[s].push(n),e.push(s),e.push("(");for(var i=0;i<t.arguments.length;++i){var r=t.arguments[i];if(i>0&&e.push(", "),this.astGeneric(r,e),"Identifier"===r.type){var a=this.paramNames.indexOf(r.name);-1===a?n.push(null):n.push({name:r.name,type:this.paramTypes[a]})}else n.push(null)}return e.push(")"),e}throw this.astErrorOutput("Unknown CallExpression",t)}},{key:"astArrayExpression",value:function(t,e){var s=t.elements.length;e.push("[");for(var n=0;n<s;++n){n>0&&e.push(", ");var i=t.elements[n];this.astGeneric(i,e)}return e.push("]"),e}},{key:"astDebuggerStatement",value:function(t,e){return e.push("debugger;"),e}},{key:"memberState",get:function(){return this.memberStates[this.memberStates.length-1]}}]),e}(BaseFunctionNode);
},{"../../core/utils":88,"../function-node-base":63}],59:[function(require,module,exports){
"use strict";function removeFnNoise(n){return/^function /.test(n)&&(n=n.substring(9)),n.replace(/[_]typeof/g,"typeof")}function removeNoise(n){return n.replace(/[_]typeof/g,"typeof")}var utils=require("../../core/utils"),kernelRunShortcut=require("../kernel-run-shortcut");module.exports=function(n,t){return"() => {\n "+kernelRunShortcut.toString()+";\n const utils = {\n allPropertiesOf: "+removeNoise(utils.allPropertiesOf.toString())+",\n clone: "+removeNoise(utils.clone.toString())+",\n checkOutput: "+removeNoise(utils.checkOutput.toString())+"\n };\n const Utils = utils;\n let Input = function() {};\n class "+(t||"Kernel")+" {\n constructor() { \n this.argumentsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.built = false;\n this.program = null;\n this.paramNames = "+JSON.stringify(n.paramNames)+";\n this.paramTypes = "+JSON.stringify(n.paramTypes)+";\n this.texSize = "+JSON.stringify(n.texSize)+";\n this.output = "+JSON.stringify(n.output)+";\n this._kernelString = `"+n._kernelString+"`;\n this.output = "+JSON.stringify(n.output)+";\n\t\t this.run = function() {\n this.run = null;\n this.build();\n return this.run.apply(this, arguments);\n }.bind(this);\n this.thread = {\n x: 0,\n y: 0,\n z: 0\n };\n }\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setInput(Type) { Input = Type; }\n "+removeFnNoise(n.build.toString())+"\n "+removeFnNoise(n.setupParams.toString())+"\n "+removeFnNoise(n.setupConstants.toString())+"\n run () { "+n.kernelString+" }\n getKernelString() { return this._kernelString; }\n "+removeFnNoise(n.validateOptions.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"};
},{"../../core/utils":88,"../kernel-run-shortcut":65}],60:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),KernelBase=require("../kernel-base"),utils=require("../../core/utils"),kernelString=require("./kernel-string");module.exports=function(t){function e(t,r){_classCallCheck(this,e);var n=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r));return n._fn=null,n.run=null,n._canvasCtx=null,n._imageData=null,n._colorData=null,n._kernelString=null,n.thread={x:0,y:0,z:0},n.run=function(){return this.run=null,this.build.apply(this,arguments),this.run.apply(this,arguments)}.bind(n),n}return _inherits(e,t),_createClass(e,[{key:"validateOptions",value:function(){if(!this.output||0===this.output.length){if(1!==arguments.length)throw"Auto dimensions only supported for kernels with only one input";var t=utils.getArgumentType(arguments[0]);if("Array"===t)this.output=utils.getDimensions(t);else{if("NumberTexture"!==t&&"ArrayTexture(4)"!==t)throw"Auto dimensions not supported for input type: "+t;this.output=arguments[0].output}}utils.checkOutput(this.output)}},{key:"build",value:function(){this.setupConstants(),this.setupParams(arguments),this.validateOptions();var t=this._canvas;t&&(this._canvasCtx=t.getContext("2d"));for(var e=this.threadDim=utils.clone(this.output);e.length<3;)e.push(1);if(this.graphical){var r=this._canvas;if(!r)throw new Error("no canvas available for using graphical output");r.width=e[0],r.height=e[1],this._imageData=this._canvasCtx.createImageData(e[0],e[1]),this._colorData=new Uint8ClampedArray(e[0]*e[1]*4)}var n=this.getKernelString();this.debug&&(console.log("Options:"),console.dir(this),console.log("Function output:"),console.log(n)),this.kernelString=n,this.run=new Function([],n).bind(this)()}},{key:"color",value:function(t,e,r,n){void 0===n&&(n=1),t=Math.floor(255*t),e=Math.floor(255*e),r=Math.floor(255*r),n=Math.floor(255*n);var s=this.output[0],a=this.output[1],i=this.thread.x,u=a-this.thread.y-1,o=i+u*s;this._colorData[4*o+0]=t,this._colorData[4*o+1]=e,this._colorData[4*o+2]=r,this._colorData[4*o+3]=n}},{key:"getKernelString",value:function(){if(null!==this._kernelString)return this._kernelString;for(var t=this.functionBuilder,e=this.threadDim||(this.threadDim=utils.clone(this.output));e.length<3;)e.push(1);if(t.addKernel(this.fnString,{prototypeOnly:!1,constants:this.constants,output:e,debug:this.debug,loopMaxIterations:this.loopMaxIterations,paramNames:this.paramNames,paramTypes:this.paramTypes,paramSizes:this.paramSizes,constantTypes:this.constantTypes}),t.addFunctions(this.functions,{constants:this.constants,output:e}),t.addNativeFunctions(this.nativeFunctions),null!==this.subKernels){this.subKernelOutputTextures=[],this.subKernelOutputVariableNames=[];for(var r=0;r<this.subKernels.length;r++){var n=this.subKernels[r];t.addSubKernel(n,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations}),this.subKernelOutputVariableNames.push(n.name+"Result")}}else if(null!==this.subKernelProperties){this.subKernelOutputVariableNames=[];var s=0;for(var a in this.subKernelProperties)if(this.subKernelProperties.hasOwnProperty(a)){var i=this.subKernelProperties[a];t.addSubKernel(i),this.subKernelOutputVariableNames.push(i.name+"Result"),s++}}var u=t.getPrototypes("kernel"),o=null;return u.length>1?u=u.filter(function(t){return/^function/.test(t)?t:(o=t,!1)}):o=u.shift(),this._kernelString="\n\t\tvar LOOP_MAX = "+this._getLoopMaxString()+"\n\t\tvar constants = this.constants;\n\t\tvar _this = this;\n return function ("+this.paramNames.map(function(t){return"user_"+t}).join(", ")+") {\n "+this._processConstants()+"\n "+this._processParams()+"\n "+this._kernelLoop(o)+"\n if (this.graphical) {\n this._imageData.data.set(this._colorData);\n this._canvasCtx.putImageData(this._imageData, 0, 0);\n return;\n }\n "+this._kernelOutput()+"\n "+(u.length>0?u.join("\n"):"")+"\n }.bind(this);"}},{key:"toString",value:function(){return kernelString(this)}},{key:"_getLoopMaxString",value:function(){return this.loopMaxIterations?" "+parseInt(this.loopMaxIterations)+";\n":" 1000;\n"}},{key:"_processConstants",value:function(){if(!this.constants)return"";var t=[];for(var e in this.constants){switch(this.constantTypes[e]){case"HTMLImage":t.push(" var constants_"+e+" = this._imageTo2DArray(this.constants."+e+")");break;case"HTMLImageArray":t.push(" var constants_"+e+" = this._imageTo3DArray(this.constants."+e+")");break;case"Input":t.push(" var constants_"+e+" = this.constants."+e+".value");break;default:t.push(" var constants_"+e+" = this.constants."+e)}}return t.join("\n")}},{key:"_processParams",value:function(){for(var t=[],e=0;e<this.paramTypes.length;e++)switch(this.paramTypes[e]){case"HTMLImage":t.push(" user_"+this.paramNames[e]+" = this._imageTo2DArray(user_"+this.paramNames[e]+")");break;case"HTMLImageArray":t.push(" user_"+this.paramNames[e]+" = this._imageTo3DArray(user_"+this.paramNames[e]+")");break;case"Input":t.push(" user_"+this.paramNames[e]+" = user_"+this.paramNames[e]+".value")}return t.join(";\n")}},{key:"_imageTo2DArray",value:function(t){var e=this._canvas;e.width<t.width&&(e.width=t.width),e.height<t.height&&(e.height=t.height);var r=this._canvasCtx;r.drawImage(t,0,0,t.width,t.height);for(var n=r.getImageData(0,0,t.width,t.height).data,s=new Array(t.height),a=0,i=t.height-1;i>=0;i--){s[i]=new Array(t.width);for(var u=0;u<t.width;u++){var o=n[a++]/255,l=n[a++]/255,h=n[a++]/255,p=n[a++]/255,c=[o,l,h,p];c.r=o,c.g=l,c.b=h,c.a=p,s[i][u]=c}}return s}},{key:"_imageTo3DArray",value:function(t){for(var e=new Array(t.length),r=0;r<t.length;r++)e[r]=this._imageTo2DArray(t[r]);return e}},{key:"_kernelLoop",value:function(t){switch(this.output.length){case 1:return this._kernel1DLoop(t);case 2:return this._kernel2DLoop(t);case 3:return this._kernel3DLoop(t);default:throw new Error("unsupported size kernel")}}},{key:"_kernel1DLoop",value:function(t){var e=this.threadDim;return"\n var result = new Float32Array("+e[0]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+" = new Float32Array("+e[0]+");\n"}).join("")+"\n for (var x = 0; x < "+e[0]+"; x++) {\n this.thread.x = x;\n this.thread.y = 0;\n this.thread.z = 0;\n var kernelResult;\n "+t+"\n result[x] = kernelResult;\n "+this._mapSubKernels(function(t){return"result_"+t+"[x] = "+t+";\n"}).join("")+"\n }"}},{key:"_kernel2DLoop",value:function(t){var e=this.threadDim;return"\n var result = new Array("+e[1]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+" = new Array("+e[1]+");\n"}).join("")+"\n for (var y = 0; y < "+e[1]+"; y++) {\n this.thread.z = 0;\n this.thread.y = y;\n var resultX = result[y] = new Float32Array("+e[0]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+"X = result_"+t+"[y] = new Float32Array("+e[0]+");\n"}).join("")+"\n for (var x = 0; x < "+e[0]+"; x++) {\n \tthis.thread.x = x;\n var kernelResult;\n "+t+"\n resultX[x] = kernelResult;\n "+this._mapSubKernels(function(t){return"result_"+t+"X[x] = "+t+";\n"}).join("")+"\n }\n }"}},{key:"_kernel3DLoop",value:function(t){var e=this.threadDim;return"\n var result = new Array("+e[2]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+" = new Array("+e[2]+");\n"}).join("")+"\n for (var z = 0; z < "+e[2]+"; z++) {\n this.thread.z = z;\n var resultY = result[z] = new Array("+e[1]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+"Y = result_"+t+"[z] = new Array("+e[1]+");\n"}).join("")+"\n for (var y = 0; y < "+e[1]+"; y++) {\n this.thread.y = y;\n var resultX = resultY[y] = new Float32Array("+e[0]+");\n "+this._mapSubKernels(function(t){return"var result_"+t+"X = result_"+t+"Y[y] = new Float32Array("+e[0]+");\n"}).join("")+"\n for (var x = 0; x < "+e[0]+"; x++) {\n \tthis.thread.x = x;\n var kernelResult;\n "+t+"\n resultX[x] = kernelResult;\n "+this._mapSubKernels(function(t){return"result_"+t+"X[x] = "+t+";\n"}).join("")+"\n }\n }\n }"}},{key:"_kernelOutput",value:function(){var t=this;return this.subKernelOutputVariableNames?"return {\n result: result,\n "+Object.keys(this.subKernelProperties||this.subKernelOutputVariableNames).map(function(e,r){return e+": result_"+t.subKernelOutputVariableNames[r]}).join(",\n")+"\n };":"return result;"}},{key:"_mapSubKernels",value:function(t){return null===this.subKernelOutputVariableNames?[""]:this.subKernelOutputVariableNames.map(t)}}]),e}(KernelBase);
},{"../../core/utils":88,"../kernel-base":64,"./kernel-string":59}],61:[function(require,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),utils=require("../../core/utils"),RunnerBase=require("../runner-base"),CPUKernel=require("./kernel"),CPUFunctionBuilder=require("./function-builder");module.exports=function(e){function r(e){_classCallCheck(this,r);var t=_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,new CPUFunctionBuilder,e));return t.Kernel=CPUKernel,t.kernel=null,t}return _inherits(r,e),_createClass(r,[{key:"getMode",value:function(){return"cpu"}}]),r}(RunnerBase);
},{"../../core/utils":88,"../runner-base":66,"./function-builder":57,"./kernel":60}],62:[function(require,module,exports){
"use strict";function _classCallCheck(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}();module.exports=function(){function t(n){_classCallCheck(this,t),this.nodeMap={},this.nativeFunctions={},this.gpu=n,this.rootKernel=null,this.Node=null}return _createClass(t,[{key:"addNativeFunction",value:function(t,n){this.nativeFunctions[t]=n}},{key:"addFunction",value:function(t,n,e){this.addFunctionNode(new this.Node(t,n,e).setBuilder(this))}},{key:"addFunctions",value:function(t,n){if(t)if(Array.isArray(t))for(var e=0;e<t.length;e++)this.addFunction(null,t[e],n);else for(var i in t)this.addFunction(i,t[i],n)}},{key:"addNativeFunctions",value:function(t){for(var n in t)t.hasOwnProperty(n)&&this.addNativeFunction(n,t[n])}},{key:"addFunctionNode",value:function(t){this.nodeMap[t.functionName]=t,t.isRootKernel&&(this.rootKernel=t)}},{key:"traceFunctionCalls",value:function(t,n,e){t=t||"kernel",n=n||[];var i=this.nodeMap[t];if(i){var o=n.indexOf(t);if(-1===o){n.push(t),e&&(i.parent=e),i.getFunctionString();for(var r=0;r<i.calledFunctions.length;++r)this.traceFunctionCalls(i.calledFunctions[r],n,i)}else{var s=n.splice(o,1)[0];n.push(s)}}return this.nativeFunctions[t]&&(n.indexOf(t)>=0||n.push(t)),n}},{key:"addKernel",value:function(t,n){var e=new this.Node("kernel",t,n);return e.setBuilder(this),e.isRootKernel=!0,this.addFunctionNode(e),e}},{key:"addSubKernel",value:function(t,n){var e=new this.Node(null,t,n);return e.setBuilder(this),e.isSubKernel=!0,this.addFunctionNode(e),e}},{key:"getPrototypeString",value:function(t){return this.getPrototypes(t).join("\n")}},{key:"getPrototypes",value:function(t){return this.rootKernel.generate(),t?this.getPrototypesFromFunctionNames(this.traceFunctionCalls(t,[]).reverse()):this.getPrototypesFromFunctionNames(Object.keys(this.nodeMap))}},{key:"getStringFromFunctionNames",value:function(t){for(var n=[],e=0;e<t.length;++e){this.nodeMap[t[e]]&&n.push(this.nodeMap[t[e]].getFunctionString())}return n.join("\n")}},{key:"getPrototypesFromFunctionNames",value:function(t,n){for(var e=[],i=0;i<t.length;++i){var o=t[i],r=this.nodeMap[o];r?e.push(r.getFunctionPrototypeString(n)):this.nativeFunctions[o]&&e.push(this.nativeFunctions[o])}return e}},{key:"getPrototypeStringFromFunctionNames",value:function(t,n){return this.getPrototypesFromFunctionNames(t,n).toString()}},{key:"getString",value:function(t,n){return void 0===n&&(n={}),t?this.getStringFromFunctionNames(this.traceFunctionCalls(t,[],n).reverse(),n):this.getStringFromFunctionNames(Object.keys(this.nodeMap),n)}}]),t}();
},{}],63:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),utils=require("../core/utils"),acorn=require("acorn");module.exports=function(){function BaseFunctionNode(t,e,n){_classCallCheck(this,BaseFunctionNode),this.calledFunctions=[],this.calledFunctionsArguments={},this.builder=null,this.isRootKernel=!1,this.isSubKernel=!1,this.parent=null,this.debug=null,this.prototypeOnly=null,this.constants=null,this.output=null,this.declarations={},this.states=[],this.fixIntegerDivisionAccuracy=null;var r=void 0,s=void 0;if(n&&(n.hasOwnProperty("debug")&&(this.debug=n.debug),n.hasOwnProperty("prototypeOnly")&&(this.prototypeOnly=n.prototypeOnly),n.hasOwnProperty("constants")&&(this.constants=n.constants),n.hasOwnProperty("output")&&(this.output=n.output),n.hasOwnProperty("loopMaxIterations")&&(this.loopMaxIterations=n.loopMaxIterations),n.hasOwnProperty("paramTypes")&&(this.paramTypes=r=n.paramTypes),n.hasOwnProperty("constantTypes")?this.constantTypes=n.constantTypes:this.constantTypes={},n.hasOwnProperty("returnType")&&(s=n.returnType),n.hasOwnProperty("fixIntegerDivisionAccuracy")&&(this.fixIntegerDivisionAccuracy=n.fixIntegerDivisionAccuracy)),!e)throw"jsFunction, parameter is missing";if(this.jsFunctionString=e.toString(),!utils.isFunctionString(this.jsFunctionString))throw console.error("jsFunction, to string conversion check failed: not a function?",this.jsFunctionString),"jsFunction, to string conversion check failed: not a function?";if(utils.isFunction(e)?this.jsFunction=e:this.jsFunction=null,this.functionName=t||e&&e.name||utils.getFunctionNameFromString(this.jsFunctionString),!this.functionName)throw"jsFunction, missing name argument or value";if(this.paramNames=utils.getParamNamesFromString(this.jsFunctionString),r){if(Array.isArray(r)){if(r.length!==this.paramNames.length)throw"Invalid argument type array length, against function length -> ("+r.length+","+this.paramNames.length+")";this.paramTypes=r}else if("object"===(void 0===r?"undefined":_typeof(r))){var i=Object.keys(r);if(r.hasOwnProperty("returns")&&(this.returnType=r.returns,i.splice(i.indexOf("returns"),1)),i.length>0&&i.length!==this.paramNames.length)throw"Invalid argument type array length, against function length -> ("+i.length+","+this.paramNames.length+")";this.paramTypes=this.paramNames.map(function(t){return r.hasOwnProperty(t)?r[t]:"Number"})}}else this.paramTypes=[];this.returnType||(this.returnType=s||"Number")}return _createClass(BaseFunctionNode,[{key:"isIdentifierConstant",value:function(t){return!!this.constants&&this.constants.hasOwnProperty(t)}},{key:"isInput",value:function(t){return"Input"===this.paramTypes[this.paramNames.indexOf(t)]}},{key:"setBuilder",value:function(t){return this.builder=t,this}},{key:"pushState",value:function(t){this.states.push(t)}},{key:"popState",value:function(t){if(this.state!==t)throw new Error("Cannot popState "+t+" when in "+this.state);this.states.pop()}},{key:"isState",value:function(t){return this.state===t}},{key:"getJsFunction",value:function getJsFunction(){if(this.jsFunction)return this.jsFunction;if(this.jsFunctionString)return this.jsFunction=eval(this.jsFunctionString),this.jsFunction;throw"Missing jsFunction, and jsFunctionString parameter"}},{key:"astMemberExpressionUnroll",value:function(t){if("Identifier"===t.type)return t.name;if("ThisExpression"===t.type)return"this";if("MemberExpression"===t.type&&t.object&&t.property)return t.object.hasOwnProperty("name")&&"_"===t.object.name[0]?this.astMemberExpressionUnroll(t.property):this.astMemberExpressionUnroll(t.object)+"."+this.astMemberExpressionUnroll(t.property);if(t.hasOwnProperty("expressions")){var e=t.expressions[0];if("Literal"===e.type&&0===e.value&&2===t.expressions.length)return this.astMemberExpressionUnroll(t.expressions[1])}throw this.astErrorOutput("Unknown CallExpression_unroll",t)}},{key:"getJsAST",value:function(t){if(this.jsFunctionAST)return this.jsFunctionAST;if(null===(t=t||acorn))throw"Missing JS to AST parser";var e=t.parse("var "+this.functionName+" = "+this.jsFunctionString+";",{locations:!0});if(null===e)throw"Failed to parse JS code";var n=e.body[0].declarations[0].init;return this.jsFunctionAST=n,n}},{key:"getFunctionString",value:function(){return this.generate(),this.functionString}},{key:"setFunctionString",value:function(t){this.functionString=t}},{key:"getParamType",value:function(t){var e=this.paramNames.indexOf(t);if(-1===e)return this.declarations.hasOwnProperty(t)?this.declarations[t]:"Number";if(this.parent){if(this.paramTypes[e])return this.paramTypes[e];for(var n=this.parent.calledFunctionsArguments[this.functionName],r=0;r<n.length;r++){var s=n[r];if(null!==s[e])return this.paramTypes[e]=s[e].type}}else if(this.paramTypes[e])return this.paramTypes[e];return"Number"}},{key:"getConstantType",value:function(t){return this.constantTypes[t]?this.constantTypes[t]:null}},{key:"getUserParamName",value:function(t){var e=this.paramNames.indexOf(t);if(-1===e)return null;if(!this.parent||!this.isSubKernel)return null;for(var n=this.parent.calledFunctionsArguments[this.functionName],r=0;r<n.length;r++){var s=n[r],i=s[e];if(null!==i&&"Integer"!==i.type)return i.name}return null}},{key:"generate",value:function(t){throw new Error("generate not defined on BaseFunctionNode")}},{key:"astGeneric",value:function(t,e){if(null===t)throw this.astErrorOutput("NULL ast",t);if(Array.isArray(t)){for(var n=0;n<t.length;n++)this.astGeneric(t[n],e);return e}switch(t.type){case"FunctionDeclaration":return this.astFunctionDeclaration(t,e);case"FunctionExpression":return this.astFunctionExpression(t,e);case"ReturnStatement":return this.astReturnStatement(t,e);case"Literal":return this.astLiteral(t,e);case"BinaryExpression":return this.astBinaryExpression(t,e);case"Identifier":return this.astIdentifierExpression(t,e);case"AssignmentExpression":return this.astAssignmentExpression(t,e);case"ExpressionStatement":return this.astExpressionStatement(t,e);case"EmptyStatement":return this.astEmptyStatement(t,e);case"BlockStatement":return this.astBlockStatement(t,e);case"IfStatement":return this.astIfStatement(t,e);case"BreakStatement":return this.astBreakStatement(t,e);case"ContinueStatement":return this.astContinueStatement(t,e);case"ForStatement":return this.astForStatement(t,e);case"WhileStatement":return this.astWhileStatement(t,e);case"DoWhileStatement":return this.astDoWhileStatement(t,e);case"VariableDeclaration":return this.astVariableDeclaration(t,e);case"VariableDeclarator":return this.astVariableDeclarator(t,e);case"ThisExpression":return this.astThisExpression(t,e);case"SequenceExpression":return this.astSequenceExpression(t,e);case"UnaryExpression":return this.astUnaryExpression(t,e);case"UpdateExpression":return this.astUpdateExpression(t,e);case"LogicalExpression":return this.astLogicalExpression(t,e);case"MemberExpression":return this.astMemberExpression(t,e);case"CallExpression":return this.astCallExpression(t,e);case"ArrayExpression":return this.astArrayExpression(t,e);case"DebuggerStatement":return this.astDebuggerStatement(t,e)}throw this.astErrorOutput("Unknown ast type : "+t.type,t)}},{key:"astErrorOutput",value:function(t,e){return console.error(utils.getAstString(this.jsFunctionString,e)),console.error(t,e,this),t}},{key:"astDebuggerStatement",value:function(t,e){return e}},{key:"astFunctionDeclaration",value:function(t,e){return e}},{key:"astFunctionExpression",value:function(t,e){return e}},{key:"astReturnStatement",value:function(t,e){return e}},{key:"astLiteral",value:function(t,e){return e}},{key:"astBinaryExpression",value:function(t,e){return e}},{key:"astIdentifierExpression",value:function(t,e){return e}},{key:"astAssignmentExpression",value:function(t,e){return e}},{key:"astExpressionStatement",value:function(t,e){return e}},{key:"astEmptyStatement",value:function(t,e){return e}},{key:"astBlockStatement",value:function(t,e){return e}},{key:"astIfStatement",value:function(t,e){return e}},{key:"astBreakStatement",value:function(t,e){return e}},{key:"astContinueStatement",value:function(t,e){return e}},{key:"astForStatement",value:function(t,e){return e}},{key:"astWhileStatement",value:function(t,e){return e}},{key:"astDoWhileStatement",value:function(t,e){return e}},{key:"astVariableDeclaration",value:function(t,e){return e}},{key:"astVariableDeclarator",value:function(t,e){return e}},{key:"astThisExpression",value:function(t,e){return e}},{key:"astSequenceExpression",value:function(t,e){return e}},{key:"astUnaryExpression",value:function(t,e){return e}},{key:"astUpdateExpression",value:function(t,e){return e}},{key:"astLogicalExpression",value:function(t,e){return e}},{key:"astMemberExpression",value:function(t,e){return e}},{key:"astCallExpression",value:function(t,e){return e}},{key:"astArrayExpression",value:function(t,e){return e}},{key:"pushParameter",value:function(t,e){this.isState("in-get-call-parameters")?t.push("int("+e+")"):t.push(e)}},{key:"state",get:function(){return this.states[this.states.length-1]}}]),BaseFunctionNode}();
},{"../core/utils":88,"acorn":90}],64:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(e,n,s){return n&&t(e.prototype,n),s&&t(e,s),e}}(),utils=require("../core/utils"),Input=require("../core/input");module.exports=function(){function t(e,n){_classCallCheck(this,t),this.paramNames=utils.getParamNamesFromString(e),this.fnString=e,this.output=null,this.debug=!1,this.graphical=!1,this.loopMaxIterations=0,this.constants=null,this.wraparound=null,this.hardcodeConstants=null,this.outputToTexture=null,this.outputImmutable=null,this.texSize=null,this._canvas=null,this._webGl=null,this.threadDim=null,this.floatTextures=null,this.floatOutput=null,this.floatOutputForce=null,this.addFunction=null,this.functions=null,this.nativeFunctions=null,this.subKernels=null,this.subKernelProperties=null,this.subKernelNames=null,this.subKernelOutputVariableNames=null,this.functionBuilder=null,this.paramTypes=null,this.paramSizes=null,this.constantTypes=null,this.fixIntegerDivisionAccuracy=null;for(var s in n)n.hasOwnProperty(s)&&this.hasOwnProperty(s)&&(this[s]=n[s]);n.hasOwnProperty("canvas")&&(this._canvas=n.canvas),n.hasOwnProperty("webGl")&&(this._webGl=n.webGl),n.hasOwnProperty("output")&&this.setOutput(n.output),this._canvas||(this._canvas=utils.initCanvas())}return _createClass(t,[{key:"build",value:function(){throw new Error('"build" not defined on Base')}},{key:"setupParams",value:function(t){this.paramTypes=[],this.paramSizes=[];for(var e=0;e<t.length;e++){var n=t[e];this.paramTypes.push(utils.getArgumentType(n)),this.paramSizes.push(n.constructor===Input?n.size:null)}}},{key:"setupConstants",value:function(){if(this.constantTypes={},this.constants)for(var t in this.constants)this.constantTypes[t]=utils.getArgumentType(this.constants[t])}},{key:"setFunctions",value:function(t){return this.functions=t,this}},{key:"setOutput",value:function(t){return t.hasOwnProperty("x")?t.hasOwnProperty("y")?t.hasOwnProperty("z")?this.output=[t.x,t.y,t.z]:this.output=[t.x,t.y]:this.output=[t.x]:this.output=t,this}},{key:"setDebug",value:function(t){return this.debug=t,this}},{key:"setGraphical",value:function(t){return this.graphical=t,this}},{key:"setLoopMaxIterations",value:function(t){return this.loopMaxIterations=t,this}},{key:"setFixIntegerDivisionAccuracy",value:function(t){return this.fixIntegerDivisionAccuracy=t,this}},{key:"setConstants",value:function(t){return this.constants=t,this}},{key:"setWraparound",value:function(t){return console.warn("Wraparound mode is not supported and undocumented."),this.wraparound=t,this}},{key:"setHardcodeConstants",value:function(t){return this.hardcodeConstants=t,this}},{key:"setOutputToTexture",value:function(t){return this.outputToTexture=t,this}},{key:"setOutputImmutable",value:function(t){return this.outputImmutable=t,this}},{key:"setFloatTextures",value:function(t){return this.floatTextures=t,this}},{key:"setFloatOutput",value:function(t){return this.floatOutput=t,this}},{key:"setFloatOutputForce",value:function(t){return this.floatOutputForce=t,this}},{key:"setCanvas",value:function(t){return this._canvas=t,this}},{key:"setWebGl",value:function(t){return this._webGl=t,this}},{key:"getCanvas",value:function(){return this._canvas}},{key:"getWebGl",value:function(){return this._webGl}},{key:"validateOptions",value:function(){throw new Error("validateOptions not defined")}},{key:"exec",value:function(){return this.execute.apply(this,arguments)}},{key:"execute",value:function(){var t=this,e=1===arguments.length?[arguments[0]]:Array.apply(null,arguments);return utils.newPromise(function(n,s){try{n(t.run.apply(t,e))}catch(t){s(t)}})}},{key:"addSubKernel",value:function(t){return null===this.subKernels&&(this.subKernels=[],this.subKernelNames=[]),this.subKernels.push(t),this.subKernelNames.push(utils.getFunctionNameFromString(t)),this}},{key:"addSubKernelProperty",value:function(t,e){if(null===this.subKernelProperties&&(this.subKernelProperties={},this.subKernelNames=[]),this.subKernelProperties.hasOwnProperty(t))throw new Error("cannot add sub kernel "+t+", already defined");return this.subKernelProperties[t]=e,this.subKernelNames.push(utils.getFunctionNameFromString(e)),this}},{key:"addNativeFunction",value:function(t,e){this.functionBuilder.addNativeFunction(t,e)}},{key:"destroy",value:function(){}}]),t}();
},{"../core/input":85,"../core/utils":88}],65:[function(require,module,exports){
"use strict";var utils=require("../core/utils");module.exports=function(t){var n=function(){return t.run.apply(t,arguments)};return utils.allPropertiesOf(t).forEach(function(e){"_"===e[0]&&"_"===e[1]||("function"==typeof t[e]?n[e]="add"===e.substring(0,3)||"set"===e.substring(0,3)?function(){return t[e].apply(t,arguments),n}:t[e].bind(t):(n.__defineGetter__(e,function(){return t[e]}),n.__defineSetter__(e,function(n){t[e]=n})))}),n.kernel=t,n};
},{"../core/utils":88}],66:[function(require,module,exports){
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),utils=require("../core/utils"),kernelRunShortcut=require("./kernel-run-shortcut");module.exports=function(){function e(n,t){_classCallCheck(this,e),t=t||{},this.kernel=t.kernel,this.canvas=t.canvas,this.webGl=t.webGl,this.fn=null,this.functionBuilder=n,this.fnString=null,this.endianness=utils.systemEndianness()}return _createClass(e,[{key:"textureToArray",value:function(e){return this.createKernel(function(e){return e[this.thread.z][this.thread.y][this.thread.x]})(e)}},{key:"deleteTexture",value:function(e){this.webGl.deleteTexture(e.texture)}},{key:"buildPromiseKernel",value:function(){throw new Error("not yet implemented")}},{key:"getMode",value:function(){throw new Error('"mode" not implemented on BaseRunner')}},{key:"buildKernel",value:function(e,n){n=Object.assign({},n||{});var t=e.toString();return n.functionBuilder||(n.functionBuilder=this.functionBuilder),n.canvas||(n.canvas=this.canvas),n.webGl||(n.webGl=this.webgl),kernelRunShortcut(new this.Kernel(t,n))}}]),e}();
},{"../core/utils":88,"./kernel-run-shortcut":65}],67:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function _round(e){return Math.floor(e+.5)}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),FunctionBuilderBase=require("../function-builder-base"),WebGLFunctionNode=require("./function-node");module.exports=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.Node=WebGLFunctionNode,e}return _inherits(t,e),_createClass(t,[{key:"polyfillStandardFunctions",value:function(){this.addFunction("round",_round)}}],[{key:"round",value:function(e){return _round(e)}}]),t}(FunctionBuilderBase);
},{"../function-builder-base":62,"./function-node":68}],68:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function webGlRegexOptimize(e){return e.replace(DECODE32_ENCODE32,"((").replace(ENCODE32_DECODE32,"((")}var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var r=t[s];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,s,r){return s&&e(t.prototype,s),r&&e(t,r),t}}(),FunctionNodeBase=require("../function-node-base"),utils=require("../../core/utils"),jsMathPrefix="Math.",localPrefix="this.",constantsPrefix="this.constants.",DECODE32_ENCODE32=/decode32\(\s+encode32\(/g,ENCODE32_DECODE32=/encode32\(\s+decode32\(/g,debugLog=function(){};module.exports=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"generate",value:function(){return this.debug&&debugLog(this),this.prototypeOnly?this.astFunctionPrototype(this.getJsAST(),[]).join("").trim():(this.functionStringArray=this.astGeneric(this.getJsAST(),[]),this.functionString=webGlRegexOptimize(this.functionStringArray.join("").trim()),this.functionString)}},{key:"astFunctionDeclaration",value:function(e,t){return this.builder.addFunction(null,utils.getAstString(this.jsFunctionString,e)),t}},{key:"astFunctionPrototype",value:function(e,t){if(this.isRootKernel||this.isSubKernel)return t;var s=this.returnType,r=typeMap[s];if(!r)throw new Error("unknown type "+s);t.push(r),t.push(" "),t.push(this.functionName),t.push("(");for(var i=0;i<this.paramNames.length;++i)i>0&&t.push(", "),t.push(this.paramTypes[i]),t.push(" "),t.push("user_"),t.push(this.paramNames[i]);return t.push(");\n"),t}},{key:"astFunctionExpression",value:function(e,t){if(this.isRootKernel)t.push("void");else{var s=this.returnType,r=typeMap[s];if(!r)throw new Error("unknown type "+s);t.push(r)}if(t.push(" "),t.push(this.functionName),t.push("("),!this.isRootKernel)for(var i=0;i<this.paramNames.length;++i){var a=this.paramNames[i];i>0&&t.push(", ");var n=this.getParamType(a),o=typeMap[n];if(!o)throw new Error("unknown type "+n);t.push(o),t.push(" "),t.push("user_"),t.push(a)}t.push(") {\n");for(var u=0;u<e.body.body.length;++u)this.astGeneric(e.body.body[u],t),t.push("\n");return t.push("}\n"),t}},{key:"astReturnStatement",value:function(e,t){return this.isRootKernel?(t.push("kernelResult = "),this.astGeneric(e.argument,t),t.push(";"),t.push("return;")):this.isSubKernel?(t.push(this.functionName+"Result = "),this.astGeneric(e.argument,t),t.push(";"),t.push("return "+this.functionName+"Result;")):(t.push("return "),this.astGeneric(e.argument,t),t.push(";")),t}},{key:"astLiteral",value:function(e,t){if(isNaN(e.value))throw this.astErrorOutput("Non-numeric literal not supported : "+e.value,e);t.push(e.value);var s=this.isState("in-get-call-parameters");return Number.isInteger(e.value)?s||t.push(".0"):s&&(t.pop(),t.push("int("),t.push(e.value),t.push(")")),t}},{key:"astBinaryExpression",value:function(e,t){var s=this.isState("in-get-call-parameters");return s&&(this.pushState("not-in-get-call-parameters"),t.push("int")),t.push("("),"%"===e.operator?(t.push("mod("),this.astGeneric(e.left,t),t.push(","),this.astGeneric(e.right,t),t.push(")")):"==="===e.operator?(this.astGeneric(e.left,t),t.push("=="),this.astGeneric(e.right,t)):"!=="===e.operator?(this.astGeneric(e.left,t),t.push("!="),this.astGeneric(e.right,t)):this.fixIntegerDivisionAccuracy&&"/"===e.operator?(t.push("div_with_int_check("),this.astGeneric(e.left,t),t.push(", "),this.astGeneric(e.right,t),t.push(")")):(this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t)),t.push(")"),s&&this.popState("not-in-get-call-parameters"),t}},{key:"astIdentifierExpression",value:function(e,t){if("Identifier"!==e.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",e);var s=!this.isState("in-get-call-parameters");switch(e.name){case"gpu_threadX":s&&t.push("float("),t.push("threadId.x"),s&&t.push(")");break;case"gpu_threadY":s&&t.push("float("),t.push("threadId.y"),s&&t.push(")");break;case"gpu_threadZ":s&&t.push("float("),t.push("threadId.z"),s&&t.push(")");break;case"gpu_outputX":t.push("uOutputDim.x");break;case"gpu_outputY":t.push("uOutputDim.y");break;case"gpu_outputZ":t.push("uOutputDim.z");break;case"Infinity":t.push("3.402823466e+38");break;default:var r=this.getUserParamName(e.name);null!==r?this.pushParameter(t,"user_"+r):this.pushParameter(t,"user_"+e.name)}return t}},{key:"astForStatement",value:function(e,t){if("ForStatement"!==e.type)throw this.astErrorOutput("Invalid for statment",e);if(e.test&&"BinaryExpression"===e.test.type){if("Identifier"===e.test.right.type&&"<"===e.test.operator&&!1===this.isIdentifierConstant(e.test.right.name)){if(this.loopMaxIterations||(console.warn("Warning: loopMaxIterations is not set! Using default of 1000 which may result in unintended behavior."),console.warn("Set loopMaxIterations or use a for loop of fixed length to silence this message.")),t.push("for ("),this.astGeneric(e.init,t),this.astGeneric(e.test.left,t),t.push(e.test.operator),t.push("LOOP_MAX"),t.push(";"),this.astGeneric(e.update,t),t.push(")"),t.push("{\n"),t.push("if ("),this.astGeneric(e.test.left,t),t.push(e.test.operator),this.astGeneric(e.test.right,t),t.push(") {\n"),"BlockStatement"===e.body.type)for(var s=0;s<e.body.body.length;s++)this.astGeneric(e.body.body[s],t);else this.astGeneric(e.body,t);return t.push("\n} else {\n"),t.push("break;\n"),t.push("}\n"),t.push("}\n"),t}var r=JSON.parse(JSON.stringify(e.init.declarations)),i=e.update.argument;if(!Array.isArray(r)||r.length<1)throw debugLog(this.jsFunctionString),new Error("Error: Incompatible for loop declaration");if(r.length>1){for(var a=null,n=0;n<r.length;n++){var o=r[n];o.id.name===i.name?(a=o,r.splice(n,1)):(t.push("float "),this.astGeneric(o,t),t.push(";"))}t.push("for (float "),this.astGeneric(a,t),t.push(";")}else t.push("for ("),this.astGeneric(e.init,t);return this.astGeneric(e.test,t),t.push(";"),this.astGeneric(e.update,t),t.push(")"),this.astGeneric(e.body,t),t}throw this.astErrorOutput("Invalid for statement",e)}},{key:"astWhileStatement",value:function(e,t){if("WhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statment",e);return t.push("for (float i = 0.0; i < LOOP_MAX; i++) {"),t.push("if ("),this.astGeneric(e.test,t),t.push(") {\n"),this.astGeneric(e.body,t),t.push("} else {\n"),t.push("break;\n"),t.push("}\n"),t.push("}\n"),t}},{key:"astDoWhileStatement",value:function(e,t){if("DoWhileStatement"!==e.type)throw this.astErrorOutput("Invalid while statment",e);return t.push("for (float i = 0.0; i < LOOP_MAX; i++) {"),this.astGeneric(e.body,t),t.push("if (!"),this.astGeneric(e.test,t),t.push(") {\n"),t.push("break;\n"),t.push("}\n"),t.push("}\n"),t}},{key:"astAssignmentExpression",value:function(e,t){if("%="!==e.operator)return this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t),t;this.astGeneric(e.left,t),t.push("="),t.push("mod("),this.astGeneric(e.left,t),t.push(","),this.astGeneric(e.right,t),t.push(")")}},{key:"astEmptyStatement",value:function(e,t){return t}},{key:"astBlockStatement",value:function(e,t){t.push("{\n");for(var s=0;s<e.body.length;s++)this.astGeneric(e.body[s],t);return t.push("}\n"),t}},{key:"astExpressionStatement",value:function(e,t){return this.astGeneric(e.expression,t),t.push(";"),t}},{key:"astVariableDeclaration",value:function(e,t){for(var s=0;s<e.declarations.length;s++){var r=e.declarations[s];s>0&&t.push(",");var i=[];this.astGeneric(r,i);var a="Number";if(0===s){var n=r.init;if(n)if(n.object){if("MemberExpression"===n.object.type&&n.object.object)if("ThisExpression"!==n.object.object.type||!n.object.property||"thread"!==n.object.property.name&&"output"!==n.object.property.name){if("Identifier"===n.object.object.type){var o=this.getParamType(n.object.object.name);a=typeLookupMap[o]}else if(n.object.object.object&&"Identifier"===n.object.object.object.type){var u=this.getParamType(n.object.object.object.name);a=typeLookupMap[u]}else if(n.object.object.object&&n.object.object.object.object&&"ThisExpression"===n.object.object.object.object.type&&"constants"===n.object.object.object.property.name){var p=this.getConstantType(n.object.object.property.name);a=typeLookupMap[p]}else if(n.object.object.object&&n.object.object.object.object&&n.object.object.object.object.object&&"ThisExpression"===n.object.object.object.object.object.type&&"constants"===n.object.object.object.object.property.name){var h=this.getConstantType(n.object.object.object.property.name);a=typeLookupMap[h]}}else a="Integer";if(!a)throw new Error("unknown lookup type "+typeLookupMap)}else if(n.name&&this.declarations[n.name])a=this.declarations[n.name];else if("ArrayExpression"===n.type)a="Array("+n.elements.length+")";else if("CallExpression"===n.type){var c=this.builder.nodeMap[n.callee.name];c&&c.returnType&&(a=c.returnType)}var l=typeMap[a];if(!l)throw new Error("type "+a+" not handled");t.push(l+" ")}this.declarations[r.id.name]=a,t.push.apply(t,i)}return t.push(";"),t}},{key:"astVariableDeclarator",value:function(e,t){return this.astGeneric(e.id,t),null!==e.init&&(t.push("="),this.astGeneric(e.init,t)),t}},{key:"astIfStatement",value:function(e,t){return t.push("if ("),this.astGeneric(e.test,t),t.push(")"),"BlockStatement"===e.consequent.type?this.astGeneric(e.consequent,t):(t.push(" {\n"),this.astGeneric(e.consequent,t),t.push("\n}\n")),e.alternate&&(t.push("else "),"BlockStatement"===e.alternate.type?this.astGeneric(e.alternate,t):(t.push(" {\n"),this.astGeneric(e.alternate,t),t.push("\n}\n"))),t}},{key:"astBreakStatement",value:function(e,t){return t.push("break;\n"),t}},{key:"astContinueStatement",value:function(e,t){return t.push("continue;\n"),t}},{key:"astLogicalExpression",value:function(e,t){return t.push("("),this.astGeneric(e.left,t),t.push(e.operator),this.astGeneric(e.right,t),t.push(")"),t}},{key:"astUpdateExpression",value:function(e,t){return e.prefix?(t.push(e.operator),this.astGeneric(e.argument,t)):(this.astGeneric(e.argument,t),t.push(e.operator)),t}},{key:"astUnaryExpression",value:function(e,t){return e.prefix?(t.push(e.operator),this.astGeneric(e.argument,t)):(this.astGeneric(e.argument,t),t.push(e.operator)),t}},{key:"astThisExpression",value:function(e,t){return t.push("this"),t}},{key:"astMemberExpression",value:function(e,t){if(debugLog("[in] astMemberExpression "+e.object.type),e.computed)if("Identifier"===e.object.type||"MemberExpression"===e.object.type&&e.object.object.object&&"ThisExpression"===e.object.object.object.type&&"constants"===e.object.object.property.name){var s=e.object.name,r=this.functionName||"kernel",i=!1;if(this.paramNames){var a=this.paramNames.indexOf(s);a>=0&&"Number"===this.paramTypes[a]&&(i=!0)}if(debugLog("- astMemberExpression "+s+" "+r),i)this.astGeneric(e.object,t),t.push("[int("),this.astGeneric(e.property,t),t.push(")]");else{var n=this.isState("in-get-call-parameters"),o=this.isState("multi-member-expression");o&&this.popState("multi-member-expression"),this.pushState("not-in-get-call-parameters");var u=null;switch(e.object.name?u=this.declarations[e.object.name]?this.declarations[e.object.name]:this.getParamType(e.object.name):e.object&&e.object.object&&e.object.object.object&&"ThisExpression"===e.object.object.object.type&&(u=this.getConstantType(e.object.property.name)),u){case"Array(2)":case"Array(3)":case"Array(4)":this.astGeneric(e.object,t),t.push("["),t.push(e.property.raw),t.push("]"),o&&this.popState("not-in-get-call-parameters");break;case"HTMLImageArray":t.push("getImage3D("),this.astGeneric(e.object,t),t.push(", ivec2("),this.astGeneric(e.object,t),t.push("Size[0],"),this.astGeneric(e.object,t),t.push("Size[1]), ivec3("),this.astGeneric(e.object,t),t.push("Dim[0],"),this.astGeneric(e.object,t),t.push("Dim[1],"),this.astGeneric(e.object,t),t.push("Dim[2]"),t.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(e.property,t),o||this.popState("in-get-call-parameters"),t.push(")");break;case"ArrayTexture(4)":case"HTMLImage":t.push("getImage2D("),this.astGeneric(e.object,t),t.push(", ivec2("),this.astGeneric(e.object,t),t.push("Size[0],"),this.astGeneric(e.object,t),t.push("Size[1]), ivec3("),this.astGeneric(e.object,t),t.push("Dim[0],"),this.astGeneric(e.object,t),t.push("Dim[1],"),this.astGeneric(e.object,t),t.push("Dim[2]"),t.push("), "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(e.property,t),o||this.popState("in-get-call-parameters"),t.push(")");break;default:n&&t.push("int("),t.push("get("),this.astGeneric(e.object,t),t.push(", ivec2("),this.astGeneric(e.object,t),t.push("Size[0],"),this.astGeneric(e.object,t),t.push("Size[1]), ivec3("),this.astGeneric(e.object,t),t.push("Dim[0],"),this.astGeneric(e.object,t),t.push("Dim[1],"),this.astGeneric(e.object,t),t.push("Dim[2]"),t.push("), "),this.astGeneric(e.object,t),t.push("BitRatio"),t.push(", "),this.popState("not-in-get-call-parameters"),this.pushState("in-get-call-parameters"),this.astGeneric(e.property,t),o||this.popState("in-get-call-parameters"),t.push(")"),n&&t.push(")")}}}else{debugLog("- astMemberExpression obj:",e.object);var p=(this.states.length,this.isState("in-get-call-parameters"));p||this.pushState("multi-member-expression"),this.astGeneric(e.object,t),this.isState("multi-member-expression")&&this.popState("multi-member-expression");var h=!p&&this.isState("in-get-call-parameters"),c=t.pop();t.push(","),debugLog("- astMemberExpression prop:",e.property);var l=this.isState("should-pop-in-get-call-parameters");l&&this.popState("should-pop-in-get-call-parameters"),this.astGeneric(e.property,t),t.push(c),h?this.pushState("should-pop-in-get-call-parameters"):l&&this.popState("in-get-call-parameters")}else{var b=this.astMemberExpressionUnroll(e),m=b.toLowerCase();debugLog("- astMemberExpression unrolled:",b),0===b.indexOf(constantsPrefix)&&(b="constants_"+b.slice(constantsPrefix.length));var f=!this.isState("in-get-call-parameters");switch(m){case"this.thread.x":f&&t.push("float("),t.push("threadId.x"),f&&t.push(")");break;case"this.thread.y":f&&t.push("float("),t.push("threadId.y"),f&&t.push(")");break;case"this.thread.z":f&&t.push("float("),t.push("threadId.z"),f&&t.push(")");break;case"this.output.x":t.push(this.output[0]+".0");break;case"this.output.y":t.push(this.output[1]+".0");break;case"this.output.z":t.push(this.output[2]+".0");break;default:e.object&&e.object.name&&this.declarations[e.object.name]&&t.push("user_"),t.push(b)}}return debugLog("[out] astMemberExpression "+e.object.type),t}},{key:"astSequenceExpression",value:function(e,t){for(var s=0;s<e.expressions.length;s++)s>0&&t.push(","),this.astGeneric(e.expressions,t);return t}},{key:"astCallExpression",value:function(e,t){if(e.callee){var s=this.astMemberExpressionUnroll(e.callee);0===s.indexOf(jsMathPrefix)&&(s=s.slice(jsMathPrefix.length)),0===s.indexOf(localPrefix)&&(s=s.slice(localPrefix.length)),"atan2"===s&&(s="atan"),this.calledFunctions.indexOf(s)<0&&this.calledFunctions.push(s),this.hasOwnProperty("funcName")||(this.calledFunctionsArguments[s]=[]);var r=[];this.calledFunctionsArguments[s].push(r),t.push(s),t.push("(");for(var i=0;i<e.arguments.length;++i){var a=e.arguments[i];if(i>0&&t.push(", "),this.astGeneric(a,t),"Identifier"===a.type){var n=this.paramNames.indexOf(a.name);-1===n?r.push(null):r.push({name:a.name,type:this.paramTypes[n]||"Number"})}else r.push(null)}return t.push(")"),t}throw this.astErrorOutput("Unknown CallExpression",e)}},{key:"astArrayExpression",value:function(e,t){var s=e.elements.length;t.push("vec"+s+"(");for(var r=0;r<s;++r){r>0&&t.push(", ");var i=e.elements[r];this.astGeneric(i,t)}return t.push(")"),t}},{key:"getFunctionPrototypeString",value:function(){return this.webGlFunctionPrototypeString?this.webGlFunctionPrototypeString:this.webGlFunctionPrototypeString=this.generate()}},{key:"build",value:function(){return this.getFunctionPrototypeString().length>0}}]),t}(FunctionNodeBase);var typeMap={Array:"sampler2D","Array(2)":"vec2","Array(3)":"vec3","Array(4)":"vec4",Array2D:"sampler2D",Array3D:"sampler2D",Float:"float",Input:"sampler2D",Integer:"float",Number:"float",NumberTexture:"sampler2D","ArrayTexture(4)":"sampler2D"},typeLookupMap={Array:"Number",Array2D:"Number",Array3D:"Number",HTMLImage:"Array(4)",HTMLImageArray:"Array(4)",NumberTexture:"Number","ArrayTexture(4)":"Array(4)"};
},{"../../core/utils":88,"../function-node-base":63}],69:[function(require,module,exports){
"use strict";function removeFnNoise(t){return/^function /.test(t)&&(t=t.substring(9)),t.replace(/[_]typeof/g,"typeof")}function removeNoise(t){return t.replace(/[_]typeof/g,"typeof")}var utils=require("../../core/utils"),kernelRunShortcut=require("../kernel-run-shortcut"),Input=require("../../core/input"),Texture=require("../../core/texture");module.exports=function(t,e){return"() => {\n "+kernelRunShortcut.toString()+";\n const utils = {\n allPropertiesOf: "+removeNoise(utils.allPropertiesOf.toString())+",\n clone: "+removeNoise(utils.clone.toString())+",\n splitArray: "+removeNoise(utils.splitArray.toString())+",\n getArgumentType: "+removeNoise(utils.getArgumentType.toString())+",\n getDimensions: "+removeNoise(utils.getDimensions.toString())+",\n dimToTexSize: "+removeNoise(utils.dimToTexSize.toString())+",\n flattenTo: "+removeNoise(utils.flattenTo.toString())+",\n flatten2dArrayTo: "+removeNoise(utils.flatten2dArrayTo.toString())+",\n flatten3dArrayTo: "+removeNoise(utils.flatten3dArrayTo.toString())+",\n systemEndianness: '"+removeNoise(utils.systemEndianness())+"',\n initWebGl: "+removeNoise(utils.initWebGl.toString())+",\n isArray: "+removeNoise(utils.isArray.toString())+",\n checkOutput: "+removeNoise(utils.checkOutput.toString())+"\n };\n const Utils = utils;\n const canvases = [];\n const maxTexSizes = {};\n let Texture = function() {};\n let Input = function() {}; \n class "+(e||"Kernel")+" {\n constructor() {\n this.maxTexSize = null;\n this.argumentsLength = 0;\n this.constantsLength = 0;\n this._canvas = null;\n this._webGl = null;\n this.program = null;\n this.outputToTexture = "+(t.outputToTexture?"true":"false")+";\n this.paramNames = "+JSON.stringify(t.paramNames)+";\n this.paramTypes = "+JSON.stringify(t.paramTypes)+";\n this.texSize = "+JSON.stringify(t.texSize)+";\n this.output = "+JSON.stringify(t.output)+";\n this.compiledFragShaderString = `"+t.compiledFragShaderString+"`;\n\t\t this.compiledVertShaderString = `"+t.compiledVertShaderString+"`;\n\t\t this.programUniformLocationCache = {};\n\t\t this.textureCache = {};\n\t\t this.subKernelOutputTextures = null;\n\t\t this.subKernelOutputVariableNames = null;\n\t\t this.uniform1fCache = {};\n\t\t this.uniform1iCache = {};\n\t\t this.uniform2fCache = {};\n\t\t this.uniform2fvCache = {};\n\t\t this.uniform2ivCache = {};\n\t\t this.uniform3fvCache = {};\n\t\t this.uniform3ivCache = {};\n }\n _getFragShaderString() { return this.compiledFragShaderString; }\n _getVertShaderString() { return this.compiledVertShaderString; }\n validateOptions() {}\n setupParams() {}\n setupConstants() {}\n setCanvas(canvas) { this._canvas = canvas; return this; }\n setWebGl(webGl) { this._webGl = webGl; return this; }\n setTexture(Type) { Texture = Type; }\n setInput(Type) { Input = Type; }\n "+removeFnNoise(t.getUniformLocation.toString())+"\n "+removeFnNoise(t.build.toString())+"\n\t\t "+removeFnNoise(t.run.toString())+"\n\t\t "+removeFnNoise(t._addArgument.toString())+"\n\t\t "+removeFnNoise(t._formatArrayTransfer.toString())+"\n\t\t "+removeFnNoise(t.getArgumentTexture.toString())+"\n\t\t "+removeFnNoise(t.getTextureCache.toString())+"\n\t\t "+removeFnNoise(t.getOutputTexture.toString())+"\n\t\t "+removeFnNoise(t.renderOutput.toString())+"\n\t\t "+removeFnNoise(t.updateMaxTexSize.toString())+"\n\t\t "+removeFnNoise(t._setupOutputTexture.toString())+"\n\t\t "+removeFnNoise(t.detachTextureCache.toString())+"\n\t\t "+removeFnNoise(t.setUniform1f.toString())+"\n\t\t "+removeFnNoise(t.setUniform1i.toString())+"\n\t\t "+removeFnNoise(t.setUniform2f.toString())+"\n\t\t "+removeFnNoise(t.setUniform2fv.toString())+"\n\t\t "+removeFnNoise(t.setUniform2iv.toString())+"\n\t\t "+removeFnNoise(t.setUniform3fv.toString())+"\n\t\t "+removeFnNoise(t.setUniform3iv.toString())+"\n };\n return kernelRunShortcut(new Kernel());\n };"};
},{"../../core/input":85,"../../core/texture":86,"../../core/utils":88,"../kernel-run-shortcut":65}],70:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _get=function t(e,r,i){null===e&&(e=Function.prototype);var s=Object.getOwnPropertyDescriptor(e,r);if(void 0===s){var n=Object.getPrototypeOf(e);return null===n?void 0:t(n,r,i)}if("value"in s)return s.value;var a=s.get;if(void 0!==a)return a.call(i)},_createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,r,i){return r&&t(e.prototype,r),i&&t(e,i),e}}(),KernelBase=require("../kernel-base"),utils=require("../../core/utils"),Texture=require("../../core/texture"),fragShaderString=require("./shader-frag"),vertShaderString=require("./shader-vert"),kernelString=require("./kernel-string"),canvases=[],maxTexSizes={};module.exports=function(t){function e(t,r){_classCallCheck(this,e);var i=_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r));return i.textureCache={},i.threadDim={},i.programUniformLocationCache={},i.framebuffer=null,i.buffer=null,i.program=null,i.outputToTexture=r.outputToTexture,i.endianness=utils.systemEndianness(),i.subKernelOutputTextures=null,i.subKernelOutputVariableNames=null,i.argumentsLength=0,i.constantsLength=0,i.compiledFragShaderString=null,i.compiledVertShaderString=null,i.fragShader=null,i.vertShader=null,i.drawBuffersMap=null,i.outputTexture=null,i.maxTexSize=null,i.uniform1fCache={},i.uniform1iCache={},i.uniform2fCache={},i.uniform2fvCache={},i.uniform2ivCache={},i.uniform3fvCache={},i.uniform3ivCache={},i._webGl||(i._webGl=i.initWebGl()),i}return _inherits(e,t),_createClass(e,null,[{key:"fragShaderString",get:function(){return fragShaderString}},{key:"vertShaderString",get:function(){return vertShaderString}}]),_createClass(e,[{key:"initWebGl",value:function(){return utils.initWebGl(this.getCanvas())}},{key:"validateOptions",value:function(){var t=utils.isFloatReadPixelsSupported();if(!0===this.floatTextures&&!utils.OES_texture_float)throw new Error("Float textures are not supported on this browser");if(!0===this.floatOutput&&!0!==this.floatOutputForce&&!t)throw new Error("Float texture outputs are not supported on this browser");void 0===this.floatTextures&&utils.OES_texture_float&&(this.floatTextures=!0,this.floatOutput=t);var e=utils.hasIntegerDivisionAccuracyBug();if(null===this.fixIntegerDivisionAccuracy?this.fixIntegerDivisionAccuracy=e:this.fixIntegerDivisionAccuracy&&!e&&(this.fixIntegerDivisionAccuracy=!1),utils.checkOutput(this.output),!this.output||0===this.output.length){if(1!==arguments.length)throw new Error("Auto output only supported for kernels with only one input");var r=utils.getArgumentType(arguments[0]);if("Array"===r)this.output=utils.getDimensions(r);else{if("NumberTexture"!==r&&"ArrayTexture(4)"!==r)throw new Error("Auto output not supported for input type: "+r);this.output=arguments[0].output}}if(this.texSize=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},this.output,!0),this.graphical){if(2!==this.output.length)throw new Error("Output must have 2 dimensions on graphical mode");this.floatOutput&&(this.floatOutput=!1,console.warn("Cannot use graphical mode and float output at the same time")),this.texSize=utils.clone(this.output)}else void 0===this.floatOutput&&utils.OES_texture_float&&(this.floatOutput=!0)}},{key:"updateMaxTexSize",value:function(){var t=this.texSize,e=this._canvas;if(null===this.maxTexSize){var r=canvases.indexOf(e);-1===r&&(r=canvases.length,canvases.push(e),maxTexSizes[r]=[t[0],t[1]]),this.maxTexSize=maxTexSizes[r]}this.maxTexSize[0]<t[0]&&(this.maxTexSize[0]=t[0]),this.maxTexSize[1]<t[1]&&(this.maxTexSize[1]=t[1])}},{key:"build",value:function(){this.validateOptions(),this.setupConstants(),this.setupParams(arguments),this.updateMaxTexSize();var t=this.texSize,e=this._webGl,r=this._canvas;e.enable(e.SCISSOR_TEST),e.viewport(0,0,this.maxTexSize[0],this.maxTexSize[1]),r.width=this.maxTexSize[0],r.height=this.maxTexSize[1];for(var i=this.threadDim=utils.clone(this.output);i.length<3;)i.push(1);this.functionBuilder&&this._addKernels();var s=this._getVertShaderString(arguments),n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,s),e.compileShader(n),this.vertShader=n;var a=this._getFragShaderString(arguments),u=e.createShader(e.FRAGMENT_SHADER);if(e.shaderSource(u,a),e.compileShader(u),this.fragShader=u,!e.getShaderParameter(n,e.COMPILE_STATUS))throw console.log(s),console.error("An error occurred compiling the shaders: "+e.getShaderInfoLog(n)),new Error("Error compiling vertex shader");if(!e.getShaderParameter(u,e.COMPILE_STATUS))throw console.log(a),console.error("An error occurred compiling the shaders: "+e.getShaderInfoLog(u)),new Error("Error compiling fragment shader");this.debug&&(console.log("Options:"),console.dir(this),console.log("GLSL Shader Output:"),console.log(a));var o=this.program=e.createProgram();e.attachShader(o,n),e.attachShader(o,u),e.linkProgram(o),this.framebuffer=e.createFramebuffer(),this.framebuffer.width=t[0],this.framebuffer.height=t[1];var h=new Float32Array([-1,-1,1,-1,-1,1,1,1]),l=new Float32Array([0,0,1,0,0,1,1,1]),f=h.byteLength,T=this.buffer;T?e.bindBuffer(e.ARRAY_BUFFER,T):(T=this.buffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,T),e.bufferData(e.ARRAY_BUFFER,h.byteLength+l.byteLength,e.STATIC_DRAW)),e.bufferSubData(e.ARRAY_BUFFER,0,h),e.bufferSubData(e.ARRAY_BUFFER,f,l);var c=e.getAttribLocation(this.program,"aPos");e.enableVertexAttribArray(c),e.vertexAttribPointer(c,2,e.FLOAT,e.FALSE,0,0);var E=e.getAttribLocation(this.program,"aTexCoord");e.enableVertexAttribArray(E),e.vertexAttribPointer(E,2,e.FLOAT,e.FALSE,0,f),e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer);for(var _ in this.constants){var m=this.constants[_],g=utils.getArgumentType(m);"Float"!==g&&"Integer"!==g&&(e.useProgram(this.program),this._addConstant(this.constants[_],g,_),this.constantsLength++)}this.outputImmutable||(this._setupOutputTexture(),null!==this.subKernelOutputVariableNames&&this.subKernelOutputVariableNames.length>0&&this._setupSubOutputTextures(this.subKernelOutputVariableNames.length))}},{key:"run",value:function(){null===this.program&&this.build.apply(this,arguments);var t=this.paramNames,e=this.paramTypes,r=this.texSize,i=this._webGl;i.useProgram(this.program),i.scissor(0,0,r[0],r[1]),this.hardcodeConstants||(this.setUniform3iv("uOutputDim",this.threadDim),this.setUniform2iv("uTexSize",r)),this.setUniform2f("ratio",r[0]/this.maxTexSize[0],r[1]/this.maxTexSize[1]),this.argumentsLength=0;for(var s=0;s<t.length;s++)this._addArgument(arguments[s],e[s],t[s]);if(this.graphical)return this.outputToTexture?(i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer),this.outputTexture&&!this.outputImmutable||this._setupOutputTexture(),i.drawArrays(i.TRIANGLE_STRIP,0,4),new Texture(this.outputTexture,r,this.threadDim,this.output,this._webGl,"ArrayTexture(4)")):(i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),void i.drawArrays(i.TRIANGLE_STRIP,0,4));i.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer),this.outputImmutable&&this._setupOutputTexture();var n=this.outputTexture;if(null!==this.subKernelOutputVariableNames&&(this.outputImmutable&&(this.subKernelOutputTextures=[],this._setupSubOutputTextures(this.subKernelOutputVariableNames.length)),this.drawBuffers.drawBuffersWEBGL(this.drawBuffersMap)),i.drawArrays(i.TRIANGLE_STRIP,0,4),null!==this.subKernelOutputTextures){if(null!==this.subKernels){var a=[];a.result=this.renderOutput(n);for(var u=0;u<this.subKernels.length;u++)a.push(new Texture(this.subKernelOutputTextures[u],r,this.threadDim,this.output,this._webGl));return a}if(null!==this.subKernelProperties){var o={result:this.renderOutput(n)},h=0;for(var l in this.subKernelProperties)this.subKernelProperties.hasOwnProperty(l)&&(o[l]=new Texture(this.subKernelOutputTextures[h],r,this.threadDim,this.output,this._webGl),h++);return o}}return this.renderOutput(n)}},{key:"renderOutput",value:function(t){var e=this.texSize,r=this._webGl,i=this.threadDim,s=this.output;if(this.outputToTexture)return new Texture(t,e,this.threadDim,s,this._webGl);var n=void 0;if(this.floatOutput){var a=e[0],u=Math.ceil(e[1]/4);n=new Float32Array(a*u*4),r.readPixels(0,0,a,u,r.RGBA,r.FLOAT,n)}else{var o=new Uint8Array(e[0]*e[1]*4);r.readPixels(0,0,e[0],e[1],r.RGBA,r.UNSIGNED_BYTE,o),n=new Float32Array(o.buffer)}if(n=n.subarray(0,i[0]*i[1]*i[2]),1===s.length)return n;if(2===s.length)return utils.splitArray(n,s[0]);if(3===s.length){return utils.splitArray(n,s[0]*s[1]).map(function(t){return utils.splitArray(t,s[0])})}}},{key:"getOutputTexture",value:function(){return this.outputTexture}},{key:"_setupOutputTexture",value:function(){var t=this._webGl,e=this.texSize,r=this.outputTexture=this._webGl.createTexture();t.activeTexture(t.TEXTURE0+this.constantsLength+this.paramNames.length),t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.floatOutput?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e[0],e[1],0,t.RGBA,t.FLOAT,null):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e[0],e[1],0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0)}},{key:"_setupSubOutputTextures",value:function(t){for(var e=this._webGl,r=this.texSize,i=this.drawBuffersMap=[e.COLOR_ATTACHMENT0],s=this.subKernelOutputTextures=[],n=0;n<t;n++){var a=this._webGl.createTexture();s.push(a),i.push(e.COLOR_ATTACHMENT0+n+1),e.activeTexture(e.TEXTURE0+this.constantsLength+this.paramNames.length+n),e.bindTexture(e.TEXTURE_2D,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),this.floatOutput?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r[0],r[1],0,e.RGBA,e.FLOAT,null):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r[0],r[1],0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+n+1,e.TEXTURE_2D,a,0)}}},{key:"getArgumentTexture",value:function(t){return this.getTextureCache("ARGUMENT_"+t)}},{key:"getTextureCache",value:function(t){return this.textureCache.hasOwnProperty(t)?this.textureCache[t]:this.textureCache[t]=this._webGl.createTexture()}},{key:"detachTextureCache",value:function(t){delete this.textureCache[t]}},{key:"setUniform1f",value:function(t,e){if(this.uniform1fCache.hasOwnProperty(t)){if(e===this.uniform1fCache[t])return}this.uniform1fCache[t]=e;var r=this.getUniformLocation(t);this._webGl.uniform1f(r,e)}},{key:"setUniform1i",value:function(t,e){if(this.uniform1iCache.hasOwnProperty(t)){if(e===this.uniform1iCache[t])return}this.uniform1iCache[t]=e;var r=this.getUniformLocation(t);this._webGl.uniform1i(r,e)}},{key:"setUniform2f",value:function(t,e,r){if(this.uniform2fCache.hasOwnProperty(t)){var i=this.uniform2fCache[t];if(e===i[0]&&r===i[1])return}this.uniform2fCache[t]=[e,r];var s=this.getUniformLocation(t);this._webGl.uniform2f(s,e,r)}},{key:"setUniform2fv",value:function(t,e){if(this.uniform2fvCache.hasOwnProperty(t)){var r=this.uniform2fvCache[t];if(e[0]===r[0]&&e[1]===r[1])return}this.uniform2fvCache[t]=e;var i=this.getUniformLocation(t);this._webGl.uniform2fv(i,e)}},{key:"setUniform2iv",value:function(t,e){if(this.uniform2ivCache.hasOwnProperty(t)){var r=this.uniform2ivCache[t];if(e[0]===r[0]&&e[1]===r[1])return}this.uniform2ivCache[t]=e;var i=this.getUniformLocation(t);this._webGl.uniform2iv(i,e)}},{key:"setUniform3fv",value:function(t,e){if(this.uniform3fvCache.hasOwnProperty(t)){var r=this.uniform3fvCache[t];if(e[0]===r[0]&&e[1]===r[1]&&e[2]===r[2])return}this.uniform3fvCache[t]=e;var i=this.getUniformLocation(t);this._webGl.uniform3fv(i,e)}},{key:"setUniform3iv",value:function(t,e){if(this.uniform3ivCache.hasOwnProperty(t)){var r=this.uniform3ivCache[t];if(e[0]===r[0]&&e[1]===r[1]&&e[2]===r[2])return}this.uniform3ivCache[t]=e;var i=this.getUniformLocation(t);this._webGl.uniform3iv(i,e)}},{key:"getUniformLocation",value:function(t){return this.programUniformLocationCache.hasOwnProperty(t)?this.programUniformLocationCache[t]:this.programUniformLocationCache[t]=this._webGl.getUniformLocation(this.program,t)}},{key:"_getFragShaderArtifactMap",value:function(t){return{HEADER:this._getHeaderString(),LOOP_MAX:this._getLoopMaxString(),CONSTANTS:this._getConstantsString(),DECODE32_ENDIANNESS:this._getDecode32EndiannessString(),ENCODE32_ENDIANNESS:this._getEncode32EndiannessString(),DIVIDE_WITH_INTEGER_CHECK:this._getDivideWithIntegerCheckString(),GET_WRAPAROUND:this._getGetWraparoundString(),GET_TEXTURE_CHANNEL:this._getGetTextureChannelString(),GET_TEXTURE_INDEX:this._getGetTextureIndexString(),GET_RESULT:this._getGetResultString(),MAIN_PARAMS:this._getMainParamsString(t),MAIN_CONSTANTS:this._getMainConstantsString(),KERNEL:this._getKernelString(),MAIN_RESULT:this._getMainResultString()}}},{key:"_addArgument",value:function(t,e,r){var i=this._webGl,s=this.getArgumentTexture(r);switch(t instanceof Texture&&(e=t.type),e){case"Array":case"Array(2)":case"Array(3)":case"Array(4)":case"Array2D":case"Array3D":var n=utils.getDimensions(t,!0),a=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},n);i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var u=a[0]*a[1],o=this._formatArrayTransfer(t,u),h=o.valuesFlat,l=o.bitRatio,f=void 0;this.floatTextures?i.texImage2D(i.TEXTURE_2D,0,i.RGBA,a[0],a[1],0,i.RGBA,i.FLOAT,h):(f=new Uint8Array(h.buffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,a[0]/l,a[1],0,i.RGBA,i.UNSIGNED_BYTE,f)),this.hardcodeConstants||(this.setUniform3iv("user_"+r+"Dim",n),this.setUniform2iv("user_"+r+"Size",a)),this.setUniform1i("user_"+r+"BitRatio",l),this.setUniform1i("user_"+r,this.argumentsLength);break;case"Integer":case"Float":case"Number":this.setUniform1f("user_"+r,t);break;case"Input":var T=t,c=T.size,E=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},c);i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var _=E[0]*E[1],m=this._formatArrayTransfer(t.value,_),g=m.valuesFlat,p=m.bitRatio;if(this.floatTextures)i.texImage2D(i.TEXTURE_2D,0,i.RGBA,E[0],E[1],0,i.RGBA,i.FLOAT,inputArray);else{var x=new Uint8Array(g.buffer);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,E[0]/p,E[1],0,i.RGBA,i.UNSIGNED_BYTE,x)}this.hardcodeConstants||(this.setUniform3iv("user_"+r+"Dim",c),this.setUniform2iv("user_"+r+"Size",E)),this.setUniform1i("user_"+r+"BitRatio",p),this.setUniform1i("user_"+r,this.argumentsLength);break;case"HTMLImage":var d=t,R=[d.width,d.height,1],v=[d.width,d.height];i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var b=i.RGBA,A=i.RGBA,S=i.UNSIGNED_BYTE;i.texImage2D(i.TEXTURE_2D,0,b,A,S,d),this.setUniform3iv("user_"+r+"Dim",R),this.setUniform2iv("user_"+r+"Size",v),this.setUniform1i("user_"+r,this.argumentsLength);break;case"ArrayTexture(4)":case"NumberTexture":var U=t,y=U.dimensions,D=U.size;i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,U.texture),this.setUniform3iv("user_"+r+"Dim",y),this.setUniform2iv("user_"+r+"Size",D),this.setUniform1i("user_"+r+"BitRatio",1),this.setUniform1i("user_"+r,this.argumentsLength);break;default:throw new Error("Input type not supported (WebGL): "+t)}this.argumentsLength++}},{key:"_addConstant",value:function(t,e,r){var i=this._webGl,s=this.getArgumentTexture(r);switch(t instanceof Texture&&(e=t.type),e){case"Array":var n=utils.getDimensions(t,!0),a=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},n);i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var u=a[0]*a[1],o=this._formatArrayTransfer(t,u),h=o.valuesFlat,l=o.bitRatio,f=void 0;this.floatTextures?i.texImage2D(i.TEXTURE_2D,0,i.RGBA,a[0],a[1],0,i.RGBA,i.FLOAT,h):(f=new Uint8Array(h.buffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,a[0]/l,a[1],0,i.RGBA,i.UNSIGNED_BYTE,f)),this.hardcodeConstants||(this.setUniform3iv("constants_"+r+"Dim",n),this.setUniform2iv("constants_"+r+"Size",a)),this.setUniform1i("constants_"+r+"BitRatio",l),this.setUniform1i("constants_"+r,this.constantsLength);break;case"Input":var T=t,c=T.size,E=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},c);i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var _=E[0]*E[1],m=this._formatArrayTransfer(t.value,_),g=m.valuesFlat,p=m.bitRatio;if(this.floatTextures)i.texImage2D(i.TEXTURE_2D,0,i.RGBA,E[0],E[1],0,i.RGBA,i.FLOAT,inputArray);else{var x=new Uint8Array(g.buffer);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,E[0]/p,E[1],0,i.RGBA,i.UNSIGNED_BYTE,x)}this.hardcodeConstants||(this.setUniform3iv("constants_"+r+"Dim",c),this.setUniform2iv("constants_"+r+"Size",E)),this.setUniform1i("constants_"+r+"BitRatio",p),this.setUniform1i("constants_"+r,this.constantsLength);break;case"HTMLImage":var d=t,R=[d.width,d.height,1],v=[d.width,d.height];i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var b=i.RGBA,A=i.RGBA,S=i.UNSIGNED_BYTE;i.texImage2D(i.TEXTURE_2D,0,b,A,S,d),this.setUniform3iv("constants_"+r+"Dim",R),this.setUniform2iv("constants_"+r+"Size",v),this.setUniform1i("constants_"+r,this.constantsLength);break;case"ArrayTexture(4)":case"NumberTexture":var U=t,y=U.dimensions,D=U.size;i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,U.texture),this.setUniform3iv("constants_"+r+"Dim",y),this.setUniform2iv("constants_"+r+"Size",D),this.setUniform1i("constants_"+r+"BitRatio",1),this.setUniform1i("constants_"+r,this.constantsLength);break;case"Integer":case"Float":default:throw new Error("Input type not supported (WebGL): "+t)}}},{key:"_formatArrayTransfer",value:function(t,e){var r=1,i=t;if(utils.isArray(t[0])||this.floatTextures)i=new Float32Array(e),utils.flattenTo(t,i);else switch(t.constructor){case Uint8Array:case Int8Array:r=4;break;case Uint16Array:case Int16Array:r=2;case Float32Array:case Int32Array:break;default:i=new Float32Array(e),utils.flattenTo(t,i)}return{bitRatio:r,valuesFlat:i}}},{key:"_getHeaderString",value:function(){return null!==this.subKernels||null!==this.subKernelProperties?"#extension GL_EXT_draw_buffers : require\n":""}},{key:"_getLoopMaxString",value:function(){return this.loopMaxIterations?" "+parseInt(this.loopMaxIterations)+".0;\n":" 1000.0;\n"}},{key:"_getConstantsString",value:function(){var t=[],e=this.threadDim,r=this.texSize;return this.hardcodeConstants?t.push("ivec3 uOutputDim = ivec3("+e[0]+","+e[1]+", "+e[2]+")","ivec2 uTexSize = ivec2("+r[0]+", "+r[1]+")"):t.push("uniform ivec3 uOutputDim","uniform ivec2 uTexSize"),this._linesToString(t)}},{key:"_getTextureCoordinate",value:function(){var t=this.subKernelOutputVariableNames;return null===t||t.length<1?"varying vec2 vTexCoord;\n":"out vec2 vTexCoord;\n"}},{key:"_getDecode32EndiannessString",value:function(){return"LE"===this.endianness?"":" rgba.rgba = rgba.abgr;\n"}},{key:"_getEncode32EndiannessString",value:function(){return"LE"===this.endianness?"":" rgba.rgba = rgba.abgr;\n"}},{key:"_getDivideWithIntegerCheckString",value:function(){return this.fixIntegerDivisionAccuracy?"\n\t\t\t float div_with_int_check(float x, float y) {\n\t\t\t if (floor(x) == x && floor(y) == y && integerMod(x, y) == 0.0) {\n\t\t\t return float(int(x)/int(y));\n\t\t\t }\n\t\t\t return x / y;\n\t\t\t}\n\t\t\t":""}},{key:"_getGetWraparoundString",value:function(){return this.wraparound?" xyz = mod(xyz, texDim);\n":""}},{key:"_getGetTextureChannelString",value:function(){return this.floatTextures?this._linesToString([" int channel = integerMod(index, 4)"," index = index / 4"]):""}},{key:"_getGetTextureIndexString",value:function(){return this.floatTextures?" index = index / 4;\n":""}},{key:"_getGetResultString",value:function(){return this.floatTextures?this._linesToString([" if (channel == 0) return texel.r"," if (channel == 1) return texel.g"," if (channel == 2) return texel.b"," if (channel == 3) return texel.a"]):" return decode(texel, x, bitRatio);"}},{key:"_getMainParamsString",value:function(t){for(var e=[],r=this.paramTypes,i=this.paramNames,s=0;s<i.length;s++){var n=t[s],a=i[s],u=r[s];if(this.hardcodeConstants)if("Array"===u||"NumberTexture"===u||"ArrayTexture(4)"===u){var o=utils.getDimensions(n,!0),h=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},o);e.push("uniform sampler2D user_"+a,"ivec2 user_"+a+"Size = ivec2("+h[0]+", "+h[1]+")","ivec3 user_"+a+"Dim = ivec3("+o[0]+", "+o[1]+", "+o[2]+")","uniform int user_"+a+"BitRatio")}else"Integer"===u?e.push("float user_"+a+" = "+n+".0"):"Float"===u&&e.push("float user_"+a+" = "+n);else if("Array"===u||"NumberTexture"===u||"ArrayTexture(4)"===u||"Input"===u||"HTMLImage"===u)e.push("uniform sampler2D user_"+a,"uniform ivec2 user_"+a+"Size","uniform ivec3 user_"+a+"Dim"),"HTMLImage"!==u&&e.push("uniform int user_"+a+"BitRatio");else{if("Integer"!==u&&"Float"!==u)throw new Error("Param type "+u+" not supported in WebGL, only WebGL2");e.push("uniform float user_"+a)}}return this._linesToString(e)}},{key:"_getMainConstantsString",value:function(){var t=[];if(this.constants)for(var e in this.constants)if(this.constants.hasOwnProperty(e)){var r=this.constants[e],i=utils.getArgumentType(r);switch(i){case"Integer":t.push("const float constants_"+e+" = "+parseInt(r)+".0");break;case"Float":t.push("const float constants_"+e+" = "+parseFloat(r));break;case"Array":case"Input":case"HTMLImage":case"NumberTexture":case"ArrayTexture(4)":t.push("uniform sampler2D constants_"+e,"uniform ivec2 constants_"+e+"Size","uniform ivec3 constants_"+e+"Dim","uniform int constants_"+e+"BitRatio");break;default:throw new Error("Unsupported constant "+e+" type "+i)}}return this._linesToString(t)}},{key:"_getKernelString",value:function(){var t=[],e=this.subKernelOutputVariableNames;if(null!==e){t.push("float kernelResult = 0.0");for(var r=0;r<e.length;r++)t.push("float "+e[r]+" = 0.0")}else t.push("float kernelResult = 0.0");return this._linesToString(t)+this.functionBuilder.getPrototypeString("kernel")}},{key:"_getMainResultString",value:function(){var t=this.subKernelOutputVariableNames,e=[];if(this.floatOutput&&e.push(" index *= 4"),this.graphical)e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragColor = actualColor");else if(this.floatOutput)for(var r=["r","g","b","a"],i=0;i<r.length;++i){if(e.push(" threadId = indexTo3D(index, uOutputDim)"),e.push(" kernel()"),t){e.push(" gl_FragData[0]."+r[i]+" = kernelResult");for(var s=0;s<t.length;++s)e.push(" gl_FragData["+(s+1)+"]."+r[i]+" = "+t[s])}else e.push(" gl_FragColor."+r[i]+" = kernelResult");i<r.length-1&&e.push(" index += 1")}else if(null!==t){e.push(" threadId = indexTo3D(index, uOutputDim)"),e.push(" kernel()"),e.push(" gl_FragData[0] = encode32(kernelResult)");for(var n=0;n<t.length;n++)e.push(" gl_FragData["+(n+1)+"] = encode32("+t[n]+")")}else e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()"," gl_FragColor = encode32(kernelResult)");return this._linesToString(e)}},{key:"_linesToString",value:function(t){return t.length>0?t.join(";\n")+";\n":"\n"}},{key:"_replaceArtifacts",value:function(t,e){return t.replace(/[ ]*__([A-Z]+[0-9]*([_]?[A-Z])*)__;\n/g,function(t,r){if(e.hasOwnProperty(r))return e[r];throw"unhandled artifact "+r})}},{key:"_addKernels",value:function(){var t=this,e=this.functionBuilder,r=this._webGl;if(e.addFunctions(this.functions,{constants:this.constants,output:this.output}),e.addNativeFunctions(this.nativeFunctions),e.addKernel(this.fnString,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations,paramNames:this.paramNames,paramTypes:this.paramTypes,constantTypes:this.constantTypes,fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),null!==this.subKernels){if(!(this.drawBuffers=r.getExtension("WEBGL_draw_buffers")))throw new Error("could not instantiate draw buffers extension");this.subKernelOutputVariableNames=[],this.subKernels.forEach(function(e){return t._addSubKernel(e)})}else if(null!==this.subKernelProperties){var i=this.drawBuffers=r.getExtension("WEBGL_draw_buffers");if(!i)throw new Error("could not instantiate draw buffers extension");this.subKernelOutputVariableNames=[],Object.keys(this.subKernelProperties).forEach(function(e){return t._addSubKernel(t.subKernelProperties[e])})}}},{key:"_addSubKernel",value:function(t){this.functionBuilder.addSubKernel(t,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations,fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),this.subKernelOutputVariableNames.push(t.name+"Result")}},{key:"_getFragShaderString",value:function(t){return null!==this.compiledFragShaderString?this.compiledFragShaderString:this.compiledFragShaderString=this._replaceArtifacts(this.constructor.fragShaderString,this._getFragShaderArtifactMap(t))}},{key:"_getVertShaderString",value:function(t){return null!==this.compiledVertShaderString?this.compiledVertShaderString:this.compiledVertShaderString=this.constructor.vertShaderString}},{key:"toString",value:function(){return kernelString(this)}},{key:"addFunction",value:function(t){this.functionBuilder.addFunction(null,t)}},{key:"destroy",value:function(t){_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this.outputTexture&&this._webGl.deleteTexture(this.outputTexture),this.buffer&&this._webGl.deleteBuffer(this.buffer),this.framebuffer&&this._webGl.deleteFramebuffer(this.framebuffer),this.vertShader&&this._webGl.deleteShader(this.vertShader),this.fragShader&&this._webGl.deleteShader(this.fragShader),this.program&&this._webGl.deleteProgram(this.program);for(var r=Object.keys(this.textureCache),i=0;i<r.length;i++){var s=r[i];this._webGl.deleteTexture(this.textureCache[s])}if(this.subKernelOutputTextures)for(var n=0;n<this.subKernelOutputTextures.length;n++)this._webGl.deleteTexture(this.subKernelOutputTextures[n]);if(t){var a=canvases.indexOf(this._canvas);a>=0&&(canvases[a]=null,maxTexSizes[a]=null)}delete this._webGl}}]),e}(KernelBase);
},{"../../core/texture":86,"../../core/utils":88,"../kernel-base":64,"./kernel-string":69,"./shader-frag":72,"./shader-vert":73}],71:[function(require,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),RunnerBase=require("../runner-base"),WebGLKernel=require("./kernel"),WebGLFunctionBuilder=require("./function-builder");module.exports=function(e){function r(e){_classCallCheck(this,r);var t=_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,new WebGLFunctionBuilder,e));return t.Kernel=WebGLKernel,t.kernel=null,t}return _inherits(r,e),_createClass(r,[{key:"getMode",value:function(){return"gpu"}}]),r}(RunnerBase);
},{"../runner-base":66,"./function-builder":67,"./kernel":70}],72:[function(require,module,exports){
"use strict";module.exports="__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n\n__CONSTANTS__;\n\nvarying vec2 vTexCoord;\n\nvec4 round(vec4 x) {\n return floor(x + 0.5);\n}\n\nfloat round(float x) {\n return floor(x + 0.5);\n}\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nfloat integerMod(float x, float y) {\n float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nint integerMod(int x, int y) {\n return x - (y * int(x / y));\n}\n\n__DIVIDE_WITH_INTEGER_CHECK__;\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nfloat decode32(vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nvec4 encode32(float f) {\n float F = abs(f);\n float sign = f < 0.0 ? 1.0 : 0.0;\n float exponent = floor(log2(F));\n float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nfloat decode(vec4 rgba, int x, int bitRatio) {\n if (bitRatio == 1) {\n return decode32(rgba);\n }\n __DECODE32_ENDIANNESS__;\n int channel = integerMod(x, bitRatio);\n if (bitRatio == 4) {\n if (channel == 0) return rgba.r * 255.0;\n if (channel == 1) return rgba.g * 255.0;\n if (channel == 2) return rgba.b * 255.0;\n if (channel == 3) return rgba.a * 255.0;\n }\n else {\n if (channel == 0) return rgba.r * 255.0 + rgba.g * 65280.0;\n if (channel == 1) return rgba.b * 255.0 + rgba.a * 65280.0;\n }\n}\n\nint index;\nivec3 threadId;\n\nivec3 indexTo3D(int idx, ivec3 texDim) {\n int z = int(idx / (texDim.x * texDim.y));\n idx -= z * int(texDim.x * texDim.y);\n int y = int(idx / texDim.x);\n int x = int(integerMod(idx, texDim.x));\n return ivec3(x, y, z);\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int z, int y, int x) {\n ivec3 xyz = ivec3(x, y, z);\n __GET_WRAPAROUND__;\n int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);\n __GET_TEXTURE_CHANNEL__;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n __GET_TEXTURE_INDEX__;\n vec4 texel = texture2D(tex, st / vec2(texSize));\n __GET_RESULT__;\n \n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n ivec3 xyz = ivec3(x, y, z);\n __GET_WRAPAROUND__;\n int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);\n __GET_TEXTURE_CHANNEL__;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n __GET_TEXTURE_INDEX__;\n return texture2D(tex, st / vec2(texSize));\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int y, int x) {\n return get(tex, texSize, texDim, bitRatio, int(0), y, x);\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int y, int x) {\n return getImage2D(tex, texSize, texDim, int(0), y, x);\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int x) {\n return get(tex, texSize, texDim, bitRatio, int(0), int(0), x);\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int x) {\n return getImage2D(tex, texSize, texDim, int(0), int(0), x);\n}\n\n\nvec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\nvoid color(sampler2D image) {\n actualColor = texture2D(image, vTexCoord);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
},{}],73:[function(require,module,exports){
"use strict";module.exports="precision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nattribute vec2 aPos;\nattribute vec2 aTexCoord;\n\nvarying vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";
},{}],74:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),WebGLKernel=require("./kernel"),utils=require("../../core/utils");module.exports=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"validateOptions",value:function(){this.texSize=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},this.output,!0)}}]),t}(WebGLKernel);
},{"../../core/utils":88,"./kernel":70}],75:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var FunctionBuilderBase=require("../function-builder-base"),WebGL2FunctionNode=require("./function-node");module.exports=function(e){function t(){_classCallCheck(this,t);var e=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.Node=WebGL2FunctionNode,e}return _inherits(t,e),t}(FunctionBuilderBase);
},{"../function-builder-base":62,"./function-node":76}],76:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function webGlRegexOptimize(e){return e.replace(DECODE32_ENCODE32,"((").replace(ENCODE32_DECODE32,"((")}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),WebGLFunctionNode=require("../web-gl/function-node"),DECODE32_ENCODE32=/decode32\(\s+encode32\(/g,ENCODE32_DECODE32=/encode32\(\s+decode32\(/g;module.exports=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"generate",value:function(){return this.debug&&console.log(this),this.prototypeOnly?this.astFunctionPrototype(this.getJsAST(),[]).join("").trim():(this.functionStringArray=this.astGeneric(this.getJsAST(),[]),this.functionString=webGlRegexOptimize(this.functionStringArray.join("").trim()),this.functionString)}},{key:"astIdentifierExpression",value:function(e,t){if("Identifier"!==e.type)throw this.astErrorOutput("IdentifierExpression - not an Identifier",e);var r=!this.isState("in-get-call-parameters");switch(e.name){case"gpu_threadX":r&&t.push("float("),t.push("threadId.x"),r&&t.push(")");break;case"gpu_threadY":r&&t.push("float("),t.push("threadId.y"),r&&t.push(")");break;case"gpu_threadZ":r&&t.push("float("),t.push("threadId.z"),r&&t.push(")");break;case"gpu_outputX":t.push("uOutputDim.x");break;case"gpu_outputY":t.push("uOutputDim.y");break;case"gpu_outputZ":t.push("uOutputDim.z");break;case"Infinity":t.push("intBitsToFloat(2139095039)");break;default:var n=this.getUserParamName(e.name);null!==n?this.pushParameter(t,"user_"+n):this.pushParameter(t,"user_"+e.name)}return t}}]),t}(WebGLFunctionNode);
},{"../web-gl/function-node":68}],77:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,r,i){return r&&t(e.prototype,r),i&&t(e,i),e}}(),WebGLKernel=require("../web-gl/kernel"),utils=require("../../core/utils"),Texture=require("../../core/texture"),fragShaderString=require("./shader-frag"),vertShaderString=require("./shader-vert");module.exports=function(t){function e(){return _classCallCheck(this,e),_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return _inherits(e,t),_createClass(e,[{key:"initWebGl",value:function(){return utils.initWebGl2(this.getCanvas())}},{key:"validateOptions",value:function(){var t=utils.isFloatReadPixelsSupportedWebGL2();if(!0===this.floatOutput&&!0!==this.floatOutputForce&&!t)throw new Error("Float texture outputs are not supported on this browser");void 0===this.floatTextures&&(this.floatTextures=!0,this.floatOutput=t);var e=utils.hasIntegerDivisionAccuracyBug();if(null===this.fixIntegerDivisionAccuracy?this.fixIntegerDivisionAccuracy=e:this.fixIntegerDivisionAccuracy&&!e&&(this.fixIntegerDivisionAccuracy=!1),utils.checkOutput(this.output),!this.output||0===this.output.length){if(1!==arguments.length)throw new Error("Auto output only supported for kernels with only one input");var r=utils.getArgumentType(arguments[0]);if("Array"===r)this.output=utils.getDimensions(r);else{if("NumberTexture"!==r&&"ArrayTexture(4)"!==r)throw new Error("Auto output not supported for input type: "+r);this.output=arguments[0].output}}if(this.texSize=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},this.output,!0),this.graphical){if(2!==this.output.length)throw new Error("Output must have 2 dimensions on graphical mode");this.floatOutput&&(this.floatOutput=!1,console.warn("Cannot use graphical mode and float output at the same time")),this.texSize=utils.clone(this.output)}else void 0===this.floatOutput&&(this.floatOutput=!0);(this.floatOutput||this.floatOutputForce)&&this._webGl.getExtension("EXT_color_buffer_float")}},{key:"run",value:function(){null===this.program&&this.build.apply(this,arguments);var t=this.paramNames,e=this.paramTypes,r=this.texSize,i=this._webGl;i.useProgram(this.program),i.scissor(0,0,r[0],r[1]),this.hardcodeConstants||(this.setUniform3iv("uOutputDim",new Int32Array(this.threadDim)),this.setUniform2iv("uTexSize",r)),this.setUniform2f("ratio",r[0]/this.maxTexSize[0],r[1]/this.maxTexSize[1]),this.argumentsLength=0;for(var s=0;s<t.length;s++)this._addArgument(arguments[s],e[s],t[s]);if(this.graphical)return this.outputToTexture?(i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer),this.outputTexture&&!this.outputImmutable||this._setupOutputTexture(),i.drawArrays(i.TRIANGLE_STRIP,0,4),new Texture(this.outputTexture,r,this.threadDim,this.output,this._webGl,"ArrayTexture(4)")):(i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),void i.drawArrays(i.TRIANGLE_STRIP,0,4));i.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer),this.outputImmutable&&this._setupOutputTexture();var a=this.outputTexture;if(null!==this.subKernelOutputVariableNames&&(this.outputImmutable&&(this.subKernelOutputTextures=[],this._setupSubOutputTextures(this.subKernelOutputVariableNames.length)),i.drawBuffers(this.drawBuffersMap)),i.drawArrays(i.TRIANGLE_STRIP,0,4),null!==this.subKernelOutputTextures){if(null!==this.subKernels){var n=[];n.result=this.renderOutput(a);for(var u=0;u<this.subKernels.length;u++)n.push(new Texture(this.subKernelOutputTextures[u],r,this.threadDim,this.output,this._webGl));return n}if(null!==this.subKernelProperties){var o={result:this.renderOutput(a)},h=0;for(var T in this.subKernelProperties)this.subKernelProperties.hasOwnProperty(T)&&(o[T]=new Texture(this.subKernelOutputTextures[h],r,this.threadDim,this.output,this._webGl),h++);return o}}return this.renderOutput(a)}},{key:"getOutputTexture",value:function(){return this.outputTexture}},{key:"_setupOutputTexture",value:function(){var t=this._webGl,e=this.texSize,r=this.outputTexture=this._webGl.createTexture();t.activeTexture(t.TEXTURE0+this.constantsLength+this.paramNames.length),t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),this.floatOutput?t.texImage2D(t.TEXTURE_2D,0,t.RGBA32F,e[0],e[1],0,t.RGBA,t.FLOAT,null):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e[0],e[1],0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0)}},{key:"_setupSubOutputTextures",value:function(t){for(var e=this._webGl,r=this.texSize,i=this.drawBuffersMap=[e.COLOR_ATTACHMENT0],s=this.subKernelOutputTextures=[],a=0;a<t;a++){var n=this._webGl.createTexture();s.push(n),i.push(e.COLOR_ATTACHMENT0+a+1),e.activeTexture(e.TEXTURE0+this.constantsLength+this.paramNames.length+a),e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),this.floatOutput?e.texImage2D(e.TEXTURE_2D,0,e.RGBA32F,r[0],r[1],0,e.RGBA,e.FLOAT,null):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,r[0],r[1],0,e.RGBA,e.UNSIGNED_BYTE,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+a+1,e.TEXTURE_2D,n,0)}}},{key:"_addArgument",value:function(t,e,r){var i=this._webGl,s=this.getArgumentTexture(r);switch(t instanceof Texture&&(e=t.type),e){case"Array":var a=utils.getDimensions(t,!0),n=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},a);i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var u=n[0]*n[1],o=this._formatArrayTransfer(t,u),h=o.valuesFlat,T=o.bitRatio,E=void 0;this.floatTextures?i.texImage2D(i.TEXTURE_2D,0,i.RGBA32F,n[0],n[1],0,i.RGBA,i.FLOAT,h):(E=new Uint8Array(h.buffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,n[0]/T,n[1],0,i.RGBA,i.UNSIGNED_BYTE,E)),this.hardcodeConstants||(this.setUniform3iv("user_"+r+"Dim",a),this.setUniform2iv("user_"+r+"Size",n)),this.setUniform1i("user_"+r+"BitRatio",T),this.setUniform1i("user_"+r,this.argumentsLength);break;case"Integer":case"Float":case"Number":this.setUniform1f("user_"+r,t);break;case"Input":var l=t,_=l.size,R=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},_);i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var f=R[0]*R[1],p=this._formatArrayTransfer(t.value,f),c=p.valuesFlat,m=p.bitRatio;if(this.floatTextures)i.texImage2D(i.TEXTURE_2D,0,i.RGBA32F,R[0],R[1],0,i.RGBA,i.FLOAT,inputArray);else{var g=new Uint8Array(c.buffer);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,R[0]/m,R[1],0,i.RGBA,i.UNSIGNED_BYTE,g)}this.hardcodeConstants||(this.setUniform3iv("user_"+r+"Dim",_),this.setUniform2iv("user_"+r+"Size",R)),this.setUniform1i("user_"+r+"BitRatio",m),this.setUniform1i("user_"+r,this.argumentsLength);break;case"HTMLImage":var x=t,A=[x.width,x.height,1],U=[x.width,x.height];i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var d=i.RGBA,D=i.RGBA,v=i.UNSIGNED_BYTE;i.texImage2D(i.TEXTURE_2D,0,d,D,v,x),this.setUniform3iv("user_"+r+"Dim",A),this.setUniform2iv("user_"+r+"Size",U),this.setUniform1i("user_"+r,this.argumentsLength);break;case"HTMLImageArray":var b=t,S=[b[0].width,b[0].height,b.length],X=[b[0].width,b[0].height];i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D_ARRAY,s),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var I=i.RGBA,y=b[0].width,L=b[0].height,O=b.length,G=i.RGBA,P=i.UNSIGNED_BYTE;i.texImage3D(i.TEXTURE_2D_ARRAY,0,I,y,L,O,0,G,P,null);for(var N=0;N<b.length;N++){i.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,N,b[N].width,b[N].height,1,G,P,b[N])}this.setUniform3iv("user_"+r+"Dim",S),this.setUniform2iv("user_"+r+"Size",X),this.setUniform1i("user_"+r,this.argumentsLength);break;case"ArrayTexture(4)":case"NumberTexture":var F=t,w=F.dimensions,B=F.size;i.activeTexture(i.TEXTURE0+this.constantsLength+this.argumentsLength),i.bindTexture(i.TEXTURE_2D,F.texture),this.setUniform3iv("user_"+r+"Dim",w),this.setUniform2iv("user_"+r+"Size",B),this.setUniform1i("user_"+r+"BitRatio",1),this.setUniform1i("user_"+r,this.argumentsLength);break;default:throw new Error("Input type not supported (WebGL): "+t)}this.argumentsLength++}},{key:"_getMainConstantsString",value:function(){var t=[];if(this.constants)for(var e in this.constants)if(this.constants.hasOwnProperty(e)){var r=this.constants[e],i=utils.getArgumentType(r);switch(i){case"Integer":t.push("const float constants_"+e+" = "+parseInt(r)+".0");break;case"Float":t.push("const float constants_"+e+" = "+parseFloat(r));break;case"Array":case"Input":case"HTMLImage":case"ArrayTexture(4)":case"NumberTexture":t.push("uniform highp sampler2D constants_"+e,"uniform highp ivec2 constants_"+e+"Size","uniform highp ivec3 constants_"+e+"Dim","uniform highp int constants_"+e+"BitRatio");break;case"HTMLImageArray":t.push("uniform highp sampler2DArray constants_"+e,"uniform highp ivec2 constants_"+e+"Size","uniform highp ivec3 constants_"+e+"Dim","uniform highp int constants_"+e+"BitRatio");break;default:throw new Error("Unsupported constant "+e+" type "+i)}}return this._linesToString(t)}},{key:"_addConstant",value:function(t,e,r){var i=this._webGl,s=this.getArgumentTexture(r);switch(t instanceof Texture&&(e=t.type),e){case"Array":var a=utils.getDimensions(t,!0),n=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},a);i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var u=n[0]*n[1],o=this._formatArrayTransfer(t,u),h=o.valuesFlat,T=o.bitRatio,E=void 0;this.floatTextures?i.texImage2D(i.TEXTURE_2D,0,i.RGBA,n[0],n[1],0,i.RGBA,i.FLOAT,h):(E=new Uint8Array(h.buffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,n[0]/T,n[1],0,i.RGBA,i.UNSIGNED_BYTE,E)),this.hardcodeConstants||(this.setUniform3iv("constants_"+r+"Dim",a),this.setUniform2iv("constants_"+r+"Size",n)),this.setUniform1i("constants_"+r+"BitRatio",T),this.setUniform1i("constants_"+r,this.constantsLength);break;case"Input":var l=t,_=l.size,R=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},_);i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);var f=R[0]*R[1],p=this._formatArrayTransfer(t.value,f),c=p.valuesFlat,m=p.bitRatio;if(this.floatTextures)i.texImage2D(i.TEXTURE_2D,0,i.RGBA32F,R[0],R[1],0,i.RGBA,i.FLOAT,inputArray);else{var g=new Uint8Array(c.buffer);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,R[0]/m,R[1],0,i.RGBA,i.UNSIGNED_BYTE,g)}this.hardcodeConstants||(this.setUniform3iv("constants_"+r+"Dim",_),this.setUniform2iv("constants_"+r+"Size",R)),this.setUniform1i("constants_"+r+"BitRatio",m),this.setUniform1i("constants_"+r,this.constantsLength);break;case"HTMLImage":var x=t,A=[x.width,x.height,1],U=[x.width,x.height];i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var d=i.RGBA,D=i.RGBA,v=i.UNSIGNED_BYTE;i.texImage2D(i.TEXTURE_2D,0,d,D,v,x),this.setUniform3iv("constants_"+r+"Dim",A),this.setUniform2iv("constants_"+r+"Size",U),this.setUniform1i("constants_"+r,this.constantsLength);break;case"HTMLImageArray":var b=t,S=[b[0].width,b[0].height,b.length],X=[b[0].width,b[0].height];i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D_ARRAY,s),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,i.NEAREST),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0);var I=i.RGBA,y=b[0].width,L=b[0].height,O=b.length,G=i.RGBA,P=i.UNSIGNED_BYTE;i.texImage3D(i.TEXTURE_2D_ARRAY,0,I,y,L,O,0,G,P,null);for(var N=0;N<b.length;N++){i.texSubImage3D(i.TEXTURE_2D_ARRAY,0,0,0,N,b[N].width,b[N].height,1,G,P,b[N])}this.setUniform3iv("constants_"+r+"Dim",S),this.setUniform2iv("constants_"+r+"Size",X),this.setUniform1i("constants_"+r,this.constantsLength);break;case"ArrayTexture(4)":case"NumberTexture":var F=t,w=F.dimensions,B=F.size;i.activeTexture(i.TEXTURE0+this.constantsLength),i.bindTexture(i.TEXTURE_2D,F.texture),this.setUniform3iv("constants_"+r+"Dim",w),this.setUniform2iv("constants_"+r+"Size",B),this.setUniform1i("constants_"+r+"BitRatio",1),this.setUniform1i("constants_"+r,this.constantsLength);break;case"Integer":case"Float":default:throw new Error("Input type not supported (WebGL): "+t)}}},{key:"_getGetResultString",value:function(){return this.floatTextures?" return texel[channel];":" return decode(texel, x, bitRatio);"}},{key:"_getHeaderString",value:function(){return""}},{key:"_getTextureCoordinate",value:function(){var t=this.subKernelOutputVariableNames;return null===t||t.length<1?"in highp vec2 vTexCoord;\n":"out highp vec2 vTexCoord;\n"}},{key:"_getMainParamsString",value:function(t){for(var e=[],r=this.paramTypes,i=this.paramNames,s=0;s<i.length;s++){var a=t[s],n=i[s],u=r[s];if(this.hardcodeConstants)if("Array"===u||"NumberTexture"===u||"ArrayTexture(4)"===u){var o=utils.getDimensions(a,!0),h=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},o);e.push("uniform highp sampler2D user_"+n,"highp ivec2 user_"+n+"Size = ivec2("+h[0]+", "+h[1]+")","highp ivec3 user_"+n+"Dim = ivec3("+o[0]+", "+o[1]+", "+o[2]+")","uniform highp int user_"+n+"BitRatio")}else"Integer"===u?e.push("highp float user_"+n+" = "+a+".0"):"Float"===u&&e.push("highp float user_"+n+" = "+a);else"Array"===u||"NumberTexture"===u||"ArrayTexture(4)"===u||"Input"===u||"HTMLImage"===u?(e.push("uniform highp sampler2D user_"+n,"uniform highp ivec2 user_"+n+"Size","uniform highp ivec3 user_"+n+"Dim"),"HTMLImage"!==u&&e.push("uniform highp int user_"+n+"BitRatio")):"HTMLImageArray"===u?e.push("uniform highp sampler2DArray user_"+n,"uniform highp ivec2 user_"+n+"Size","uniform highp ivec3 user_"+n+"Dim"):"Integer"!==u&&"Float"!==u||e.push("uniform float user_"+n)}return this._linesToString(e)}},{key:"_getKernelString",value:function(){var t=[],e=this.subKernelOutputVariableNames;if(null!==e){t.push("float kernelResult = 0.0"),t.push("layout(location = 0) out vec4 data0");for(var r=0;r<e.length;r++)t.push("float "+e[r]+" = 0.0","layout(location = "+(r+1)+") out vec4 data"+(r+1))}else t.push("out vec4 data0"),t.push("float kernelResult = 0.0");return this._linesToString(t)+this.functionBuilder.getPrototypeString("kernel")}},{key:"_getMainResultString",value:function(){var t=this.subKernelOutputVariableNames,e=[];if(this.floatOutput&&e.push(" index *= 4"),this.graphical)e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0 = actualColor");else if(this.floatOutput)for(var r=["r","g","b","a"],i=0;i<r.length;++i){if(e.push(" threadId = indexTo3D(index, uOutputDim)"),e.push(" kernel()"),t){e.push(" data0."+r[i]+" = kernelResult");for(var s=0;s<t.length;++s)e.push(" data"+(s+1)+"."+r[i]+" = "+t[s])}else e.push(" data0."+r[i]+" = kernelResult");i<r.length-1&&e.push(" index += 1")}else if(null!==t){e.push(" threadId = indexTo3D(index, uOutputDim)"),e.push(" kernel()"),e.push(" data0 = encode32(kernelResult)");for(var a=0;a<t.length;a++)e.push(" data"+(a+1)+" = encode32("+t[a]+")")}else e.push(" threadId = indexTo3D(index, uOutputDim)"," kernel()"," data0 = encode32(kernelResult)");return this._linesToString(e)}},{key:"_addKernels",value:function(){var t=this,e=this.functionBuilder;this._webGl;e.addFunctions(this.functions,{constants:this.constants,output:this.output}),e.addNativeFunctions(this.nativeFunctions),e.addKernel(this.fnString,{prototypeOnly:!1,constants:this.constants,output:this.output,debug:this.debug,loopMaxIterations:this.loopMaxIterations,paramNames:this.paramNames,paramTypes:this.paramTypes,constantTypes:this.constantTypes,fixIntegerDivisionAccuracy:this.fixIntegerDivisionAccuracy}),null!==this.subKernels?(this.subKernelOutputTextures=[],this.subKernelOutputVariableNames=[],this.subKernels.forEach(function(e){return t._addSubKernel(e)})):null!==this.subKernelProperties&&(this.subKernelOutputTextures=[],this.subKernelOutputVariableNames=[],Object.keys(this.subKernelProperties).forEach(function(e){return t._addSubKernel(t.subKernelProperties[e])}))}},{key:"_getFragShaderString",value:function(t){return null!==this.compiledFragShaderString?this.compiledFragShaderString:this.compiledFragShaderString=this._replaceArtifacts(this.constructor.fragShaderString,this._getFragShaderArtifactMap(t))}},{key:"_getVertShaderString",value:function(t){return null!==this.compiledVertShaderString?this.compiledVertShaderString:this.compiledVertShaderString=this.constructor.vertShaderString}}],[{key:"fragShaderString",get:function(){return fragShaderString}},{key:"vertShaderString",get:function(){return vertShaderString}}]),e}(WebGLKernel);
},{"../../core/texture":86,"../../core/utils":88,"../web-gl/kernel":70,"./shader-frag":79,"./shader-vert":80}],78:[function(require,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)}var _createClass=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),RunnerBase=require("../runner-base"),WebGL2FunctionBuilder=require("./function-builder"),WebGL2Kernel=require("./kernel");module.exports=function(e){function r(e){_classCallCheck(this,r);var t=_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,new WebGL2FunctionBuilder,e));return t.Kernel=WebGL2Kernel,t.kernel=null,t}return _inherits(r,e),_createClass(r,[{key:"getMode",value:function(){return"gpu"}}]),r}(RunnerBase);
},{"../runner-base":66,"./function-builder":75,"./kernel":77}],79:[function(require,module,exports){
"use strict";module.exports="#version 300 es\n__HEADER__;\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nconst float LOOP_MAX = __LOOP_MAX__;\n\n__CONSTANTS__;\n\nin vec2 vTexCoord;\n\nvec2 integerMod(vec2 x, float y) {\n vec2 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec3 integerMod(vec3 x, float y) {\n vec3 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nvec4 integerMod(vec4 x, vec4 y) {\n vec4 res = floor(mod(x, y));\n return res * step(1.0 - floor(y), -res);\n}\n\nfloat integerMod(float x, float y) {\n float res = floor(mod(x, y));\n return res * (res > floor(y) - 1.0 ? 0.0 : 1.0);\n}\n\nint integerMod(int x, int y) {\n return x - (y * int(x/y));\n}\n\n__DIVIDE_WITH_INTEGER_CHECK__;\n\n// Here be dragons!\n// DO NOT OPTIMIZE THIS CODE\n// YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE\n// LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME\nconst vec2 MAGIC_VEC = vec2(1.0, -256.0);\nconst vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0);\nconst vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536\nfloat decode32(vec4 rgba) {\n __DECODE32_ENDIANNESS__;\n rgba *= 255.0;\n vec2 gte128;\n gte128.x = rgba.b >= 128.0 ? 1.0 : 0.0;\n gte128.y = rgba.a >= 128.0 ? 1.0 : 0.0;\n float exponent = 2.0 * rgba.a - 127.0 + dot(gte128, MAGIC_VEC);\n float res = exp2(round(exponent));\n rgba.b = rgba.b - 128.0 * gte128.x;\n res = dot(rgba, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res;\n res *= gte128.y * -2.0 + 1.0;\n return res;\n}\n\nvec4 encode32(float f) {\n float F = abs(f);\n float sign = f < 0.0 ? 1.0 : 0.0;\n float exponent = floor(log2(F));\n float mantissa = (exp2(-exponent) * F);\n // exponent += floor(log2(mantissa));\n vec4 rgba = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV;\n rgba.rg = integerMod(rgba.rg, 256.0);\n rgba.b = integerMod(rgba.b, 128.0);\n rgba.a = exponent*0.5 + 63.5;\n rgba.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0;\n rgba = floor(rgba);\n rgba *= 0.003921569; // 1/255\n __ENCODE32_ENDIANNESS__;\n return rgba;\n}\n// Dragons end here\n\nfloat decode(vec4 rgba, int x, int bitRatio) {\n if (bitRatio == 1) {\n return decode32(rgba);\n }\n __DECODE32_ENDIANNESS__;\n int channel = integerMod(x, bitRatio);\n if (bitRatio == 4) {\n return rgba[channel] * 255.0;\n }\n else {\n return rgba[channel*2] * 255.0 + rgba[channel*2 + 1] * 65280.0;\n }\n}\n\nint index;\nivec3 threadId;\n\nivec3 indexTo3D(int idx, ivec3 texDim) {\n int z = int(idx / (texDim.x * texDim.y));\n idx -= z * int(texDim.x * texDim.y);\n int y = int(idx / texDim.x);\n int x = int(integerMod(idx, texDim.x));\n return ivec3(x, y, z);\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int z, int y, int x) {\n ivec3 xyz = ivec3(x, y, z);\n __GET_WRAPAROUND__;\n int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);\n __GET_TEXTURE_CHANNEL__;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n __GET_TEXTURE_INDEX__;\n vec4 texel = texture(tex, st / vec2(texSize));\n __GET_RESULT__;\n \n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n ivec3 xyz = ivec3(x, y, z);\n __GET_WRAPAROUND__;\n int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);\n __GET_TEXTURE_CHANNEL__;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n __GET_TEXTURE_INDEX__;\n return texture(tex, st / vec2(texSize));\n}\n\nvec4 getImage3D(sampler2DArray tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) {\n ivec3 xyz = ivec3(x, y, z);\n __GET_WRAPAROUND__;\n int index = xyz.x + texDim.x * (xyz.y + texDim.y * xyz.z);\n __GET_TEXTURE_CHANNEL__;\n int w = texSize.x;\n vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5;\n __GET_TEXTURE_INDEX__;\n return texture(tex, vec3(st / vec2(texSize), z));\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int y, int x) {\n return get(tex, texSize, texDim, bitRatio, 0, y, x);\n}\n\nfloat get(sampler2D tex, ivec2 texSize, ivec3 texDim, int bitRatio, int x) {\n return get(tex, texSize, texDim, bitRatio, 0, 0, x);\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int y, int x) {\n return getImage2D(tex, texSize, texDim, 0, y, x);\n}\n\nvec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int x) {\n return getImage2D(tex, texSize, texDim, 0, 0, x);\n}\n\nvec4 actualColor;\nvoid color(float r, float g, float b, float a) {\n actualColor = vec4(r,g,b,a);\n}\n\nvoid color(float r, float g, float b) {\n color(r,g,b,1.0);\n}\n\n__MAIN_PARAMS__;\n__MAIN_CONSTANTS__;\n__KERNEL__;\n\nvoid main(void) {\n index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;\n __MAIN_RESULT__;\n}";
},{}],80:[function(require,module,exports){
"use strict";module.exports="#version 300 es\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\n\nin vec2 aPos;\nin vec2 aTexCoord;\n\nout vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}";
},{}],81:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),WebGLKernel=require("./kernel"),utils=require("../../core/utils");module.exports=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"validateOptions",value:function(){this._webGl.getExtension("EXT_color_buffer_float"),this.texSize=utils.dimToTexSize({floatTextures:this.floatTextures,floatOutput:this.floatOutput},this.output,!0)}}]),t}(WebGLKernel);
},{"../../core/utils":88,"./kernel":77}],82:[function(require,module,exports){
"use strict";var utils=require("./utils");module.exports=function(t,r){var n=r.toString();return new Function("return function "+t+" ("+utils.getParamNamesFromString(n).join(", ")+") {"+utils.getFunctionBodyFromString(n)+"}")()};
},{"./utils":88}],83:[function(require,module,exports){
"use strict";function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,r){for(var n=0;n<r.length;n++){var t=r[n];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(r,n,t){return n&&e(r.prototype,n),t&&e(r,t),r}}(),UtilsCore=require("./utils-core");module.exports=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"validateKernelObj",value:function(e){if(null===e)throw"KernelObj being validated is NULL";if("string"==typeof e){try{e=JSON.parse(e)}catch(e){throw console.error(e),"Failed to convert KernelObj from JSON string"}if(null===e)throw"Invalid (NULL) KernelObj JSON string representation"}if(!0!==e.isKernelObj)throw"Failed missing isKernelObj flag check";return e}},{key:"loadKernelObj",value:function(e,r){e=validateKernelObj(e)}}]),e}();
},{"./utils-core":87}],84:[function(require,module,exports){
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}function _inherits(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}var _createClass=function(){function e(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(n,r,t){return r&&e(n.prototype,r),t&&e(n,t),n}}(),utils=require("./utils"),WebGLRunner=require("../backend/web-gl/runner"),WebGL2Runner=require("../backend/web-gl2/runner"),CPURunner=require("../backend/cpu/runner"),WebGLValidatorKernel=require("../backend/web-gl/validator-kernel"),WebGL2ValidatorKernel=require("../backend/web-gl2/validator-kernel"),GPUCore=require("./gpu-core"),GPU=function(e){function n(e){_classCallCheck(this,n);var r=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));e=e||{},r._canvas=e.canvas||null,r._webGl=e.webGl||null;var t=e.mode,u=void 0;if(utils.isWebGlSupported())if(r._webGl)if("undefined"!=typeof WebGL2RenderingContext&&r._webGl.constructor===WebGL2RenderingContext)u="webgl2";else{if("undefined"==typeof WebGLRenderingContext||r._webGl.constructor!==WebGLRenderingContext)throw new Error("unknown WebGL Context");u="webgl"}else u=t||"gpu";else{if(t&&"cpu"!==t)throw new Error('A requested mode of "'+t+'" and is not supported');console.warn("Warning: gpu not supported, falling back to cpu support"),u="cpu"}r.kernels=[];var i={canvas:r._canvas,webGl:r._webGl};switch(u){case"cpu":r._runner=new CPURunner(i);break;case"gpu":var a=r.getGPURunner();r._runner=new a(i);break;case"webgl2":r._runner=new WebGL2Runner(i);break;case"webgl":r._runner=new WebGLRunner(i);break;case"webgl2-validator":r._runner=new WebGL2Runner(i),r._runner.Kernel=WebGL2ValidatorKernel;break;case"webgl-validator":r._runner=new WebGLRunner(i),r._runner.Kernel=WebGLValidatorKernel;break;default:throw new Error('"'+t+'" mode is not defined')}return r}return _inherits(n,e),_createClass(n,[{key:"createKernel",value:function(e,n){if(void 0===e)throw"Missing fn parameter";if(!utils.isFunction(e)&&"string"!=typeof e)throw"fn parameter not a function";var r=Object.assign({webGl:this._webGl,canvas:this._canvas},n||{}),t=this._runner.buildKernel(e,r);return this._canvas||(this._canvas=t.getCanvas()),this._runner.canvas||(this._runner.canvas=t.getCanvas()),this.kernels.push(t),t}},{key:"createKernelMap",value:function(){var e=void 0,n=void 0;"function"==typeof arguments[arguments.length-2]?(e=arguments[arguments.length-2],n=arguments[arguments.length-1]):e=arguments[arguments.length-1],utils.isWebGlDrawBuffersSupported()||(this._runner=new CPURunner(n));var r=this.createKernel(e,n);if(Array.isArray(arguments[0]))for(var t=arguments[0],u=0;u<t.length;u++)r.addSubKernel(t[u]);else{var i=arguments[0];for(var a in i)i.hasOwnProperty(a)&&r.addSubKernelProperty(a,i[a])}return r}},{key:"combineKernels",value:function(){var e=arguments[arguments.length-2],n=arguments[arguments.length-1];if("cpu"===this.getMode())return n;for(var r=arguments[0].getCanvas(),t=arguments[0].getWebGl(),u=0;u<arguments.length-1;u++)arguments[u].setCanvas(r).setWebGl(t).setOutputToTexture(!0);return function(){n.apply(null,arguments);var r=e.texSize,t=e.getWebGl(),u=e.threadDim,i=void 0;if(e.floatOutput){var a=r[0],o=Math.ceil(r[1]/4);i=new Float32Array(a*o*4),t.readPixels(0,0,a,o,t.RGBA,t.FLOAT,i)}else{var l=new Uint8Array(r[0]*r[1]*4);t.readPixels(0,0,r[0],r[1],t.RGBA,t.UNSIGNED_BYTE,l),i=new Float32Array(l.buffer)}if(i=i.subarray(0,u[0]*u[1]*u[2]),1===e.output.length)return i;if(2===e.output.length)return utils.splitArray(i,e.output[0]);if(3===e.output.length){return utils.splitArray(i,e.output[0]*e.output[1]).map(function(n){return utils.splitArray(n,e.output[0])})}}}},{key:"getGPURunner",value:function(){return"undefined"!=typeof WebGL2RenderingContext&&utils.isWebGl2Supported()?WebGL2Runner:"undefined"!=typeof WebGLRenderingContext?WebGLRunner:void 0}},{key:"addFunction",value:function(e,n){return this._runner.functionBuilder.addFunction(null,e,n),this}},{key:"addNativeFunction",value:function(e,n){return this._runner.functionBuilder.addNativeFunction(e,n),this}},{key:"getMode",value:function(){return this._runner.getMode()}},{key:"isWebGlSupported",value:function(){return utils.isWebGlSupported()}},{key:"hasIntegerDivisionAccuracyBug",value:function(){return utils.hasIntegerDivisionAccuracyBug()}},{key:"getCanvas",value:function(){return this._canvas}},{key:"getWebGl",value:function(){return this._webGl}},{key:"destroy",value:function(){var e=this;setTimeout(function(){for(var n=e.kernels,r=!e._webGl&&n.length&&n[0]._webGl,t=0;t<e.kernels.length;t++)e.kernels[t].destroy(!0);if(r){r.OES_texture_float=null,r.OES_texture_float_linear=null,r.OES_element_index_uint=null;var u=r.getExtension("WEBGL_lose_context");u&&u.loseContext()}},0)}}]),n}(GPUCore);Object.assign(GPU,GPUCore),module.exports=GPU;
},{"../backend/cpu/runner":61,"../backend/web-gl/runner":71,"../backend/web-gl/validator-kernel":74,"../backend/web-gl2/runner":78,"../backend/web-gl2/validator-kernel":81,"./gpu-core":83,"./utils":88}],85:[function(require,module,exports){
"use strict";function _classCallCheck(s,i){if(!(s instanceof i))throw new TypeError("Cannot call a class as a function")}module.exports=function s(i,e){if(_classCallCheck(this,s),this.value=i,Array.isArray(e)){this.size=[];for(var t=0;t<e.length;t++)this.size[t]=e[t];for(;this.size.length<3;)this.size.push(1)}else e.z?this.size=[e.x,e.y,e.z]:e.y?this.size=[e.x,e.y,1]:this.size=[e.x,1,1]};
},{}],86:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();module.exports=function(){function e(t,r,n,i,s){var u=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"NumberTexture";_classCallCheck(this,e),this.texture=t,this.size=r,this.dimensions=n,this.output=i,this.webGl=s,this.kernel=null,this.type=u}return _createClass(e,[{key:"toArray",value:function(e){if(!e)throw new Error("You need to pass the GPU object for toArray to work.");return this.kernel?this.kernel(this):(this.kernel=e.createKernel(function(e){return e[this.thread.z][this.thread.y][this.thread.x]}).setOutput(this.output),this.kernel(this))}},{key:"delete",value:function(){return this.webGl.deleteTexture(this.texture)}}]),e}();
},{}],87:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),UtilsCore=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"isCanvas",value:function(e){return null!==e&&(e.nodeName&&e.getContext&&"CANVAS"===e.nodeName.toUpperCase()||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)}},{key:"isCanvasSupported",value:function(){return _isCanvasSupported}},{key:"initCanvas",value:function(){if(!_isCanvasSupported)return null;var e="undefined"!=typeof document?document.createElement("canvas"):new OffscreenCanvas(0,0);return e.width=2,e.height=2,e}},{key:"isWebGl",value:function(e){return e&&"function"==typeof e.getExtension}},{key:"isWebGl2",value:function(e){return e&&"undefined"!=typeof WebGL2RenderingContext&&e instanceof WebGL2RenderingContext}},{key:"isWebGlSupported",value:function(){return _isWebGlSupported}},{key:"isWebGl2Supported",value:function(){return _isWebGl2Supported}},{key:"isWebGlDrawBuffersSupported",value:function(){return _isWebGlDrawBuffersSupported}},{key:"initWebGlDefaultOptions",value:function(){return{alpha:!1,depth:!1,antialias:!1}}},{key:"initWebGl",value:function(t){if((void 0!==_isCanvasSupported||null===t)&&!_isCanvasSupported)return null;if(!e.isCanvas(t))throw new Error("Invalid canvas object - "+t);var n=null,r=e.initWebGlDefaultOptions();try{n=t.getContext("experimental-webgl",r)}catch(e){}return null===n&&(n=t.getContext("webgl2",r)||t.getContext("webgl",r)),n&&(n.OES_texture_float=n.getExtension("OES_texture_float"),n.OES_texture_float_linear=n.getExtension("OES_texture_float_linear"),n.OES_element_index_uint=n.getExtension("OES_element_index_uint")),n}},{key:"initWebGl2",value:function(t){if((void 0!==_isCanvasSupported||null===t)&&!_isCanvasSupported)return null;if(!e.isCanvas(t))throw new Error("Invalid canvas object - "+t);return t.getContext("webgl2",e.initWebGlDefaultOptions())}},{key:"checkOutput",value:function(e){if(!e||!Array.isArray(e))throw new Error("kernel.output not an array");for(var t=0;t<e.length;t++)if(isNaN(e[t])||e[t]<1)throw new Error("kernel.output["+t+"] incorrectly defined as `"+e[t]+"`, needs to be numeric, and greater than 0")}}]),e}(),_isCanvasSupported="undefined"!=typeof document?UtilsCore.isCanvas(document.createElement("canvas")):"undefined"!=typeof OffscreenCanvas,_testingWebGl=UtilsCore.initWebGl(UtilsCore.initCanvas()),_testingWebGl2=UtilsCore.initWebGl2(UtilsCore.initCanvas()),_isWebGlSupported=UtilsCore.isWebGl(_testingWebGl),_isWebGl2Supported=UtilsCore.isWebGl2(_testingWebGl2),_isWebGlDrawBuffersSupported=_isWebGlSupported&&Boolean(_testingWebGl.getExtension("WEBGL_draw_buffers"));_isWebGlSupported?(UtilsCore.OES_texture_float=_testingWebGl.OES_texture_float,UtilsCore.OES_texture_float_linear=_testingWebGl.OES_texture_float_linear,UtilsCore.OES_element_index_uint=_testingWebGl.OES_element_index_uint):(UtilsCore.OES_texture_float=!1,UtilsCore.OES_texture_float_linear=!1,UtilsCore.OES_element_index_uint=!1),module.exports=UtilsCore;
},{}],88:[function(require,module,exports){
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),UtilsCore=require("./utils-core"),Input=require("./input"),Texture=require("./texture"),FUNCTION_NAME=/function ([^(]*)/,STRIP_COMMENTS=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,ARGUMENT_NAMES=/([^\s,]+)/g,_systemEndianness=function(){var e=new ArrayBuffer(4),t=new Uint32Array(e),n=new Uint8Array(e);if(t[0]=3735928559,239===n[0])return"LE";if(222===n[0])return"BE";throw new Error("unknown endianness")}(),_isFloatReadPixelsSupported=null,_isFloatReadPixelsSupportedWebGL2=null,_isMixedIdentifiersSupported=function(){try{return new Function("let i = 1; const j = 1;")(),!0}catch(e){return!1}}(),_hasIntegerDivisionAccuracyBug=null,Utils=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,e),_createClass(t,null,[{key:"systemEndianness",value:function(){return _systemEndianness}},{key:"isFunction",value:function(e){return"function"==typeof e}},{key:"isFunctionString",value:function(e){return null!==e&&"function"===e.toString().slice(0,"function".length).toLowerCase()}},{key:"getFunctionNameFromString",value:function(e){return FUNCTION_NAME.exec(e)[1]}},{key:"getFunctionBodyFromString",value:function(e){return e.substring(e.indexOf("{")+1,e.lastIndexOf("}"))}},{key:"getParamNamesFromString",value:function(e){var t=e.toString().replace(STRIP_COMMENTS,""),n=t.slice(t.indexOf("(")+1,t.indexOf(")")).match(ARGUMENT_NAMES);return null===n&&(n=[]),n}},{key:"clone",value:function(e){if(null===e||"object"!==(void 0===e?"undefined":_typeof(e))||e.hasOwnProperty("isActiveClone"))return e;var n=e.constructor();for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(e.isActiveClone=null,n[r]=t.clone(e[r]),delete e.isActiveClone);return n}},{key:"newPromise",value:function(e){var t=Promise||small_promise;if(null===t)throw TypeError("Browser is missing Promise implementation. Consider adding small_promise.js polyfill");return new t(e)}},{key:"functionBinder",value:function(e,t){return e.bind?e.bind(t):function(){var n=1===arguments.length?[arguments[0]]:Array.apply(null,arguments);return e.apply(t,n)}}},{key:"isArray",value:function(e){return!isNaN(e.length)}},{key:"getArgumentType",value:function(e){return t.isArray(e)?"IMG"===e[0].nodeName?"HTMLImageArray":"Array":"number"==typeof e?Number.isInteger(e)?"Integer":"Float":e instanceof Texture?e.type:e instanceof Input?"Input":"IMG"===e.nodeName?"HTMLImage":"Unknown"}},{key:"isFloatReadPixelsSupported",value:function(){if(null!==_isFloatReadPixelsSupported)return _isFloatReadPixelsSupported;var e=require("../index"),t=new e({mode:"webgl-validator"}),n=t.createKernel(function(){return 1},{output:[2],floatTextures:!0,floatOutput:!0,floatOutputForce:!0})();return _isFloatReadPixelsSupported=1===n[0],t.destroy(),_isFloatReadPixelsSupported}},{key:"isFloatReadPixelsSupportedWebGL2",value:function(){if(null!==_isFloatReadPixelsSupportedWebGL2)return _isFloatReadPixelsSupportedWebGL2;var e=require("../index"),t=new e({mode:"webgl2-validator"}),n=t.createKernel(function(){return 1},{output:[2],floatTextures:!0,floatOutput:!0,floatOutputForce:!0})();return _isFloatReadPixelsSupportedWebGL2=1===n[0],t.destroy(),_isFloatReadPixelsSupportedWebGL2}},{key:"hasIntegerDivisionAccuracyBug",value:function(){if(null!==_hasIntegerDivisionAccuracyBug)return _hasIntegerDivisionAccuracyBug;var e=require("../index"),t=new e({mode:"webgl-validator"}),n=t.createKernel(function(e,t){return e[this.thread.x]/t[this.thread.x]},{output:[1]})([6,6030401],[3,3991]);return _hasIntegerDivisionAccuracyBug=2!==n[0]||1511!==n[1],t.destroy(),_hasIntegerDivisionAccuracyBug}},{key:"isMixedIdentifiersSupported",value:function(){return _isMixedIdentifiersSupported}},{key:"dimToTexSize",value:function(e,t,n){for(var r=t[0],o=t[0],i=t[1],u=1;u<t.length;u++)r*=t[u];if(!e.floatTextures||n&&!e.floatOutput||(o=r=Math.ceil(r/4)),i>1&&o*i===r)return[o,i];for(var a=Math.sqrt(r),l=Math.ceil(a),s=Math.floor(a);l*s>r;)l--,s=Math.ceil(r/l);return o=s,i=Math.ceil(r/o),[o,i]}},{key:"getDimensions",value:function(e,n){var r=void 0;if(t.isArray(e)){for(var o=[],i=e;t.isArray(i);)o.push(i.length),i=i[0];r=o.reverse()}else if(e instanceof Texture)r=e.output;else{if(!(e instanceof Input))throw"Unknown dimensions of "+e;r=e.size}if(n)for(r=t.clone(r);r.length<3;)r.push(1);return new Int32Array(r)}},{key:"pad",value:function(e,t){function n(e){return Array.apply(null,new Array(e)).map(Number.prototype.valueOf,0)}for(var r=e.length+2*t,o=e.map(function(e){return[].concat(n(t),e,n(t))}),i=0;i<t;i++)o=[].concat([n(r)],o,[n(r)]);return o}},{key:"flatten2dArrayTo",value:function(e,t){for(var n=0,r=0;r<e.length;r++)t.set(e[r],n),n+=e[r].length}},{key:"flatten3dArrayTo",value:function(e,t){for(var n=0,r=0;r<e.length;r++)for(var o=0;o<e[r].length;o++)t.set(e[r][o],n),n+=e[r][o].length}},{key:"flattenTo",value:function(e,n){t.isArray(e[0])?t.isArray(e[0][0])?t.flatten3dArrayTo(e,n):t.flatten2dArrayTo(e,n):n.set(e)}},{key:"splitArray",value:function(e,t){for(var n=[],r=0;r<e.length;r+=t)n.push(new e.constructor(e.buffer,4*r+e.byteOffset,t));return n}},{key:"getAstString",value:function(e,t){var n=Array.isArray(e)?e:e.split(/\r?\n/g),r=t.loc.start,o=t.loc.end,i=[];i.push(n[r.line-1].slice(r.column));for(var u=r.line;u<o.line-1;u++)i.push(n[u]);return i.push(n[o.line-1].slice(0,o.column)),i.join("\n")}},{key:"allPropertiesOf",value:function(e){var t=[];do{t.push.apply(t,Object.getOwnPropertyNames(e))}while(e=Object.getPrototypeOf(e));return t}}]),t}(UtilsCore);Object.assign(Utils,UtilsCore),module.exports=Utils;
},{"../index":89,"./input":85,"./texture":86,"./utils-core":87}],89:[function(require,module,exports){
"use strict";var GPU=require("./core/gpu"),alias=require("./core/alias"),utils=require("./core/utils"),Input=require("./core/input"),Texture=require("./core/texture"),CPUFunctionBuilder=require("./backend/cpu/function-builder"),CPUFunctionNode=require("./backend/cpu/function-node"),CPUKernel=require("./backend/cpu/kernel"),CPURunner=require("./backend/cpu/runner"),WebGLFunctionBuilder=require("./backend/web-gl/function-builder"),WebGLFunctionNode=require("./backend/web-gl/function-node"),WebGLKernel=require("./backend/web-gl/kernel"),WebGLRunner=require("./backend/web-gl/runner"),WebGL2FunctionBuilder=require("./backend/web-gl2/function-builder"),WebGL2FunctionNode=require("./backend/web-gl2/function-node"),WebGL2Kernel=require("./backend/web-gl2/kernel"),WebGL2Runner=require("./backend/web-gl2/runner");GPU.alias=alias,GPU.utils=utils,GPU.Texture=Texture,GPU.Input=Input,GPU.input=function(e,n){return new Input(e,n)},GPU.CPUFunctionBuilder=CPUFunctionBuilder,GPU.CPUFunctionNode=CPUFunctionNode,GPU.CPUKernel=CPUKernel,GPU.CPURunner=CPURunner,GPU.WebGLFunctionBuilder=WebGLFunctionBuilder,GPU.WebGLFunctionNode=WebGLFunctionNode,GPU.WebGLKernel=WebGLKernel,GPU.WebGLRunner=WebGLRunner,GPU.WebGL2FunctionBuilder=WebGL2FunctionBuilder,GPU.WebGL2FunctionNode=WebGL2FunctionNode,GPU.WebGL2Kernel=WebGL2Kernel,GPU.WebGL2Runner=WebGL2Runner,"undefined"!=typeof module&&(module.exports=GPU),"undefined"!=typeof window&&(window.GPU=GPU),"undefined"!=typeof self&&(self.GPU=GPU);
},{"./backend/cpu/function-builder":57,"./backend/cpu/function-node":58,"./backend/cpu/kernel":60,"./backend/cpu/runner":61,"./backend/web-gl/function-builder":67,"./backend/web-gl/function-node":68,"./backend/web-gl/kernel":70,"./backend/web-gl/runner":71,"./backend/web-gl2/function-builder":75,"./backend/web-gl2/function-node":76,"./backend/web-gl2/kernel":77,"./backend/web-gl2/runner":78,"./core/alias":82,"./core/gpu":84,"./core/input":85,"./core/texture":86,"./core/utils":88}],90:[function(require,module,exports){
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.acorn={})}(this,function(t){"use strict";function e(t,e){for(var i=65536,s=0;s<e.length;s+=2){if((i+=e[s])>t)return!1;if((i+=e[s+1])>=t)return!0}}function i(t,i){return t<65?36===t:t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&M.test(String.fromCharCode(t)):!1!==i&&e(t,U)))}function s(t,i){return t<48?36===t:t<58||!(t<65)&&(t<91||(t<97?95===t:t<123||(t<=65535?t>=170&&F.test(String.fromCharCode(t)):!1!==i&&(e(t,U)||e(t,G)))))}function r(t,e){return new q(t,{beforeExpr:!0,binop:e})}function a(t,e){return void 0===e&&(e={}),e.keyword=t,j[t]=new q(t,e)}function n(t,e){return 10===t||13===t||!e&&(8232===t||8233===t)}function o(t,e){return $.call(t,e)}function h(t,e){for(var i=1,s=0;;){K.lastIndex=s;var r=K.exec(t);if(!(r&&r.index<e))return new et(i,e-s);++i,s=r.index+r[0].length}}function p(t){var e={};for(var i in st)e[i]=t&&o(t,i)?t[i]:st[i];if(e.ecmaVersion>=2015&&(e.ecmaVersion-=2009),null==e.allowReserved&&(e.allowReserved=e.ecmaVersion<5),tt(e.onToken)){var s=e.onToken;e.onToken=function(t){return s.push(t)}}return tt(e.onComment)&&(e.onComment=c(e,e.onComment)),e}function c(t,e){return function(i,s,r,a,n,o){var h={type:i?"Block":"Line",value:s,start:r,end:a};t.locations&&(h.loc=new it(this,n,o)),t.ranges&&(h.range=[r,a]),e.push(h)}}function u(t){return new RegExp("^(?:"+t.replace(/ /g,"|")+")$")}function l(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1}function d(t,e,i,s){return t.type=e,t.end=i,this.options.locations&&(t.loc.end=s),this.options.ranges&&(t.range[1]=i),t}function f(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function m(t){return 36===t||t>=40&&t<=43||46===t||63===t||t>=91&&t<=94||t>=123&&t<=125}function x(t){return i(t,!0)||36===t||95===t}function g(t){return s(t,!0)||36===t||95===t||8204===t||8205===t}function v(t){return t>=65&&t<=90||t>=97&&t<=122}function y(t){return t>=0&&t<=1114111}function _(t){return 100===t||68===t||115===t||83===t||119===t||87===t}function b(t){return v(t)||95===t}function k(t){return b(t)||C(t)}function C(t){return t>=48&&t<=57}function S(t){return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function E(t){return t>=65&&t<=70?t-65+10:t>=97&&t<=102?t-97+10:t-48}function w(t){return t>=48&&t<=55}function A(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function I(t,e){return new at(e,t).parse()}function P(t,e,i){var s=new at(i,t,e);return s.nextToken(),s.parseExpression()}function L(t,e){return new at(e,t)}function N(e,i,s){t.parse_dammit=e,t.LooseParser=i,t.pluginsLoose=s}var T={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},V="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",R={5:V,6:V+" const class extends export import super"},D=/^in(stanceof)?$/,O="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࢠ-ࢴࢶ-ࢽऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲈᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿯ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞹꟷ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭥꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",B="·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛࣓-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ංඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ູົຼ່-ໍ໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠐-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭ᳲ-᳴᳷-᳹᷀-᷹᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_",M=new RegExp("["+O+"]"),F=new RegExp("["+O+B+"]");O=B=null;var U=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,477,28,11,0,9,21,190,52,76,44,33,24,27,35,30,0,12,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,26,230,43,117,63,32,0,257,0,11,39,8,0,22,0,12,39,3,3,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,270,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,68,12,0,67,12,65,1,31,6129,15,754,9486,286,82,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,15,7472,3104,541],G=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,525,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,4,9,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,280,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239],q=function(t,e){void 0===e&&(e={}),this.label=t,this.keyword=e.keyword,this.beforeExpr=!!e.beforeExpr,this.startsExpr=!!e.startsExpr,this.isLoop=!!e.isLoop,this.isAssign=!!e.isAssign,this.prefix=!!e.prefix,this.postfix=!!e.postfix,this.binop=e.binop||null,this.updateContext=null},H={beforeExpr:!0},W={startsExpr:!0},j={},z={num:new q("num",W),regexp:new q("regexp",W),string:new q("string",W),name:new q("name",W),eof:new q("eof"),bracketL:new q("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new q("]"),braceL:new q("{",{beforeExpr:!0,startsExpr:!0}),braceR:new q("}"),parenL:new q("(",{beforeExpr:!0,startsExpr:!0}),parenR:new q(")"),comma:new q(",",H),semi:new q(";",H),colon:new q(":",H),dot:new q("."),question:new q("?",H),arrow:new q("=>",H),template:new q("template"),invalidTemplate:new q("invalidTemplate"),ellipsis:new q("...",H),backQuote:new q("`",W),dollarBraceL:new q("${",{beforeExpr:!0,startsExpr:!0}),eq:new q("=",{beforeExpr:!0,isAssign:!0}),assign:new q("_=",{beforeExpr:!0,isAssign:!0}),incDec:new q("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new q("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:r("||",1),logicalAND:r("&&",2),bitwiseOR:r("|",3),bitwiseXOR:r("^",4),bitwiseAND:r("&",5),equality:r("==/!=/===/!==",6),relational:r("</>/<=/>=",7),bitShift:r("<</>>/>>>",8),plusMin:new q("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:r("%",10),star:r("*",10),slash:r("/",10),starstar:new q("**",{beforeExpr:!0}),_break:a("break"),_case:a("case",H),_catch:a("catch"),_continue:a("continue"),_debugger:a("debugger"),_default:a("default",H),_do:a("do",{isLoop:!0,beforeExpr:!0}),_else:a("else",H),_finally:a("finally"),_for:a("for",{isLoop:!0}),_function:a("function",W),_if:a("if"),_return:a("return",H),_switch:a("switch"),_throw:a("throw",H),_try:a("try"),_var:a("var"),_const:a("const"),_while:a("while",{isLoop:!0}),_with:a("with"),_new:a("new",{beforeExpr:!0,startsExpr:!0}),_this:a("this",W),_super:a("super",W),_class:a("class",W),_extends:a("extends",H),_export:a("export"),_import:a("import"),_null:a("null",W),_true:a("true",W),_false:a("false",W),_in:a("in",{beforeExpr:!0,binop:7}),_instanceof:a("instanceof",{beforeExpr:!0,binop:7}),_typeof:a("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:a("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:a("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},Q=/\r\n?|\n|\u2028|\u2029/,K=new RegExp(Q.source,"g"),X=/[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/,Y=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,Z=Object.prototype,$=Z.hasOwnProperty,J=Z.toString,tt=Array.isArray||function(t){return"[object Array]"===J.call(t)},et=function(t,e){this.line=t,this.column=e};et.prototype.offset=function(t){return new et(this.line,this.column+t)};var it=function(t,e,i){this.start=e,this.end=i,null!==t.sourceFile&&(this.source=t.sourceFile)},st={ecmaVersion:7,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:!1,allowHashBang:!1,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1,plugins:{}},rt={},at=function(t,e,i){this.options=t=p(t),this.sourceFile=t.sourceFile,this.keywords=u(R[t.ecmaVersion>=6?6:5]);var s="";if(!t.allowReserved){for(var r=t.ecmaVersion;!(s=T[r]);r--);"module"===t.sourceType&&(s+=" await")}this.reservedWords=u(s);var a=(s?s+" ":"")+T.strict;this.reservedWordsStrict=u(a),this.reservedWordsStrictBind=u(a+" "+T.strictBind),this.input=String(e),this.containsEsc=!1,this.loadPlugins(t.plugins),i?(this.pos=i,this.lineStart=this.input.lastIndexOf("\n",i-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(Q).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=z.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule="module"===t.sourceType,this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.inFunction=this.inGenerator=this.inAsync=!1,this.yieldPos=this.awaitPos=0,this.labels=[],0===this.pos&&t.allowHashBang&&"#!"===this.input.slice(0,2)&&this.skipLineComment(2),this.scopeStack=[],this.enterFunctionScope(),this.regexpState=null};at.prototype.isKeyword=function(t){return this.keywords.test(t)},at.prototype.isReservedWord=function(t){return this.reservedWords.test(t)},at.prototype.extend=function(t,e){this[t]=e(this[t])},at.prototype.loadPlugins=function(t){var e=this;for(var i in t){var s=rt[i];if(!s)throw new Error("Plugin '"+i+"' not found");s(e,t[i])}},at.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};var nt=at.prototype,ot=/^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;nt.strictDirective=function(t){for(var e=this;;){Y.lastIndex=t,t+=Y.exec(e.input)[0].length;var i=ot.exec(e.input.slice(t));if(!i)return!1;if("use strict"===(i[1]||i[2]))return!0;t+=i[0].length}},nt.eat=function(t){return this.type===t&&(this.next(),!0)},nt.isContextual=function(t){return this.type===z.name&&this.value===t&&!this.containsEsc},nt.eatContextual=function(t){return!!this.isContextual(t)&&(this.next(),!0)},nt.expectContextual=function(t){this.eatContextual(t)||this.unexpected()},nt.canInsertSemicolon=function(){return this.type===z.eof||this.type===z.braceR||Q.test(this.input.slice(this.lastTokEnd,this.start))},nt.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0},nt.semicolon=function(){this.eat(z.semi)||this.insertSemicolon()||this.unexpected()},nt.afterTrailingComma=function(t,e){if(this.type===t)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),e||this.next(),!0},nt.expect=function(t){this.eat(t)||this.unexpected()},nt.unexpected=function(t){this.raise(null!=t?t:this.start,"Unexpected token")},nt.checkPatternErrors=function(t,e){if(t){t.trailingComma>-1&&this.raiseRecoverable(t.trailingComma,"Comma is not permitted after the rest element");var i=e?t.parenthesizedAssign:t.parenthesizedBind;i>-1&&this.raiseRecoverable(i,"Parenthesized pattern")}},nt.checkExpressionErrors=function(t,e){if(!t)return!1;var i=t.shorthandAssign,s=t.doubleProto;if(!e)return i>=0||s>=0;i>=0&&this.raise(i,"Shorthand property assignments are valid only in destructuring patterns"),s>=0&&this.raiseRecoverable(s,"Redefinition of __proto__ property")},nt.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,"Yield expression cannot be a default value"),this.awaitPos&&this.raise(this.awaitPos,"Await expression cannot be a default value")},nt.isSimpleAssignTarget=function(t){return"ParenthesizedExpression"===t.type?this.isSimpleAssignTarget(t.expression):"Identifier"===t.type||"MemberExpression"===t.type};var ht=at.prototype;ht.parseTopLevel=function(t){var e=this,i={};for(t.body||(t.body=[]);this.type!==z.eof;){var s=e.parseStatement(!0,!0,i);t.body.push(s)}return this.adaptDirectivePrologue(t.body),this.next(),this.options.ecmaVersion>=6&&(t.sourceType=this.options.sourceType),this.finishNode(t,"Program")};var pt={kind:"loop"},ct={kind:"switch"};ht.isLet=function(){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;Y.lastIndex=this.pos;var t=Y.exec(this.input),e=this.pos+t[0].length,r=this.input.charCodeAt(e);if(91===r||123===r)return!0;if(i(r,!0)){for(var a=e+1;s(this.input.charCodeAt(a),!0);)++a;var n=this.input.slice(e,a);if(!D.test(n))return!0}return!1},ht.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;Y.lastIndex=this.pos;var t=Y.exec(this.input),e=this.pos+t[0].length;return!(Q.test(this.input.slice(this.pos,e))||"function"!==this.input.slice(e,e+8)||e+8!==this.input.length&&s(this.input.charAt(e+8)))},ht.parseStatement=function(t,e,i){var s,r=this.type,a=this.startNode();switch(this.isLet()&&(r=z._var,s="let"),r){case z._break:case z._continue:return this.parseBreakContinueStatement(a,r.keyword);case z._debugger:return this.parseDebuggerStatement(a);case z._do:return this.parseDoStatement(a);case z._for:return this.parseForStatement(a);case z._function:return!t&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(a,!1);case z._class:return t||this.unexpected(),this.parseClass(a,!0);case z._if:return this.parseIfStatement(a);case z._return:return this.parseReturnStatement(a);case z._switch:return this.parseSwitchStatement(a);case z._throw:return this.parseThrowStatement(a);case z._try:return this.parseTryStatement(a);case z._const:case z._var:return s=s||this.value,t||"var"===s||this.unexpected(),this.parseVarStatement(a,s);case z._while:return this.parseWhileStatement(a);case z._with:return this.parseWithStatement(a);case z.braceL:return this.parseBlock();case z.semi:return this.parseEmptyStatement(a);case z._export:case z._import:return this.options.allowImportExportEverywhere||(e||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),r===z._import?this.parseImport(a):this.parseExport(a,i);default:if(this.isAsyncFunction())return t||this.unexpected(),this.next(),this.parseFunctionStatement(a,!0);var n=this.value,o=this.parseExpression();return r===z.name&&"Identifier"===o.type&&this.eat(z.colon)?this.parseLabeledStatement(a,n,o):this.parseExpressionStatement(a,o)}},ht.parseBreakContinueStatement=function(t,e){var i=this,s="break"===e;this.next(),this.eat(z.semi)||this.insertSemicolon()?t.label=null:this.type!==z.name?this.unexpected():(t.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var a=i.labels[r];if(null==t.label||a.name===t.label.name){if(null!=a.kind&&(s||"loop"===a.kind))break;if(t.label&&s)break}}return r===this.labels.length&&this.raise(t.start,"Unsyntactic "+e),this.finishNode(t,s?"BreakStatement":"ContinueStatement")},ht.parseDebuggerStatement=function(t){return this.next(),this.semicolon(),this.finishNode(t,"DebuggerStatement")},ht.parseDoStatement=function(t){return this.next(),this.labels.push(pt),t.body=this.parseStatement(!1),this.labels.pop(),this.expect(z._while),t.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(z.semi):this.semicolon(),this.finishNode(t,"DoWhileStatement")},ht.parseForStatement=function(t){this.next();var e=this.options.ecmaVersion>=9&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction)&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(pt),this.enterLexicalScope(),this.expect(z.parenL),this.type===z.semi)return e>-1&&this.unexpected(e),this.parseFor(t,null);var i=this.isLet();if(this.type===z._var||this.type===z._const||i){var s=this.startNode(),r=i?"let":this.value;return this.next(),(this.parseVar(s,!0,r),this.finishNode(s,"VariableDeclaration"),!(this.type===z._in||this.options.ecmaVersion>=6&&this.isContextual("of"))||1!==s.declarations.length||"var"!==r&&s.declarations[0].init)?(e>-1&&this.unexpected(e),this.parseFor(t,s)):(this.options.ecmaVersion>=9&&(this.type===z._in?e>-1&&this.unexpected(e):t.await=e>-1),this.parseForIn(t,s))}var a=new l,n=this.parseExpression(!0,a);return this.type===z._in||this.options.ecmaVersion>=6&&this.isContextual("of")?(this.options.ecmaVersion>=9&&(this.type===z._in?e>-1&&this.unexpected(e):t.await=e>-1),this.toAssignable(n,!1,a),this.checkLVal(n),this.parseForIn(t,n)):(this.checkExpressionErrors(a,!0),e>-1&&this.unexpected(e),this.parseFor(t,n))},ht.parseFunctionStatement=function(t,e){return this.next(),this.parseFunction(t,!0,!1,e)},ht.parseIfStatement=function(t){return this.next(),t.test=this.parseParenExpression(),t.consequent=this.parseStatement(!this.strict&&this.type===z._function),t.alternate=this.eat(z._else)?this.parseStatement(!this.strict&&this.type===z._function):null,this.finishNode(t,"IfStatement")},ht.parseReturnStatement=function(t){return this.inFunction||this.options.allowReturnOutsideFunction||this.raise(this.start,"'return' outside of function"),this.next(),this.eat(z.semi)||this.insertSemicolon()?t.argument=null:(t.argument=this.parseExpression(),this.semicolon()),this.finishNode(t,"ReturnStatement")},ht.parseSwitchStatement=function(t){var e=this;this.next(),t.discriminant=this.parseParenExpression(),t.cases=[],this.expect(z.braceL),this.labels.push(ct),this.enterLexicalScope();for(var i,s=!1;this.type!==z.braceR;)if(e.type===z._case||e.type===z._default){var r=e.type===z._case;i&&e.finishNode(i,"SwitchCase"),t.cases.push(i=e.startNode()),i.consequent=[],e.next(),r?i.test=e.parseExpression():(s&&e.raiseRecoverable(e.lastTokStart,"Multiple default clauses"),s=!0,i.test=null),e.expect(z.colon)}else i||e.unexpected(),i.consequent.push(e.parseStatement(!0));return this.exitLexicalScope(),i&&this.finishNode(i,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(t,"SwitchStatement")},ht.parseThrowStatement=function(t){return this.next(),Q.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),t.argument=this.parseExpression(),this.semicolon(),this.finishNode(t,"ThrowStatement")};var ut=[];ht.parseTryStatement=function(t){if(this.next(),t.block=this.parseBlock(),t.handler=null,this.type===z._catch){var e=this.startNode();this.next(),this.eat(z.parenL)?(e.param=this.parseBindingAtom(),this.enterLexicalScope(),this.checkLVal(e.param,"let"),this.expect(z.parenR)):(this.options.ecmaVersion<10&&this.unexpected(),e.param=null,this.enterLexicalScope()),e.body=this.parseBlock(!1),this.exitLexicalScope(),t.handler=this.finishNode(e,"CatchClause")}return t.finalizer=this.eat(z._finally)?this.parseBlock():null,t.handler||t.finalizer||this.raise(t.start,"Missing catch or finally clause"),this.finishNode(t,"TryStatement")},ht.parseVarStatement=function(t,e){return this.next(),this.parseVar(t,!1,e),this.semicolon(),this.finishNode(t,"VariableDeclaration")},ht.parseWhileStatement=function(t){return this.next(),t.test=this.parseParenExpression(),this.labels.push(pt),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"WhileStatement")},ht.parseWithStatement=function(t){return this.strict&&this.raise(this.start,"'with' in strict mode"),this.next(),t.object=this.parseParenExpression(),t.body=this.parseStatement(!1),this.finishNode(t,"WithStatement")},ht.parseEmptyStatement=function(t){return this.next(),this.finishNode(t,"EmptyStatement")},ht.parseLabeledStatement=function(t,e,i){for(var s=this,r=0,a=s.labels;r<a.length;r+=1){a[r].name===e&&s.raise(i.start,"Label '"+e+"' is already declared")}for(var n=this.type.isLoop?"loop":this.type===z._switch?"switch":null,o=this.labels.length-1;o>=0;o--){var h=s.labels[o];if(h.statementStart!==t.start)break;h.statementStart=s.start,h.kind=n}return this.labels.push({name:e,kind:n,statementStart:this.start}),t.body=this.parseStatement(!0),("ClassDeclaration"===t.body.type||"VariableDeclaration"===t.body.type&&"var"!==t.body.kind||"FunctionDeclaration"===t.body.type&&(this.strict||t.body.generator||t.body.async))&&this.raiseRecoverable(t.body.start,"Invalid labeled declaration"),this.labels.pop(),t.label=i,this.finishNode(t,"LabeledStatement")},ht.parseExpressionStatement=function(t,e){return t.expression=e,this.semicolon(),this.finishNode(t,"ExpressionStatement")},ht.parseBlock=function(t){var e=this;void 0===t&&(t=!0);var i=this.startNode();for(i.body=[],this.expect(z.braceL),t&&this.enterLexicalScope();!this.eat(z.braceR);){var s=e.parseStatement(!0);i.body.push(s)}return t&&this.exitLexicalScope(),this.finishNode(i,"BlockStatement")},ht.parseFor=function(t,e){return t.init=e,this.expect(z.semi),t.test=this.type===z.semi?null:this.parseExpression(),this.expect(z.semi),t.update=this.type===z.parenR?null:this.parseExpression(),this.expect(z.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,"ForStatement")},ht.parseForIn=function(t,e){var i=this.type===z._in?"ForInStatement":"ForOfStatement";return this.next(),"ForInStatement"===i&&("AssignmentPattern"===e.type||"VariableDeclaration"===e.type&&null!=e.declarations[0].init&&(this.strict||"Identifier"!==e.declarations[0].id.type))&&this.raise(e.start,"Invalid assignment in for-in loop head"),t.left=e,t.right="ForInStatement"===i?this.parseExpression():this.parseMaybeAssign(),this.expect(z.parenR),this.exitLexicalScope(),t.body=this.parseStatement(!1),this.labels.pop(),this.finishNode(t,i)},ht.parseVar=function(t,e,i){var s=this;for(t.declarations=[],t.kind=i;;){var r=s.startNode();if(s.parseVarId(r,i),s.eat(z.eq)?r.init=s.parseMaybeAssign(e):"const"!==i||s.type===z._in||s.options.ecmaVersion>=6&&s.isContextual("of")?"Identifier"===r.id.type||e&&(s.type===z._in||s.isContextual("of"))?r.init=null:s.raise(s.lastTokEnd,"Complex binding patterns require an initialization value"):s.unexpected(),t.declarations.push(s.finishNode(r,"VariableDeclarator")),!s.eat(z.comma))break}return t},ht.parseVarId=function(t,e){t.id=this.parseBindingAtom(e),this.checkLVal(t.id,e,!1)},ht.parseFunction=function(t,e,i,s){this.initFunction(t),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!s)&&(t.generator=this.eat(z.star)),this.options.ecmaVersion>=8&&(t.async=!!s),e&&(t.id="nullableID"===e&&this.type!==z.name?null:this.parseIdent(),t.id&&this.checkLVal(t.id,this.inModule&&!this.inFunction?"let":"var"));var r=this.inGenerator,a=this.inAsync,n=this.yieldPos,o=this.awaitPos,h=this.inFunction;return this.inGenerator=t.generator,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),e||(t.id=this.type===z.name?this.parseIdent():null),this.parseFunctionParams(t),this.parseFunctionBody(t,i),this.inGenerator=r,this.inAsync=a,this.yieldPos=n,this.awaitPos=o,this.inFunction=h,this.finishNode(t,e?"FunctionDeclaration":"FunctionExpression")},ht.parseFunctionParams=function(t){this.expect(z.parenL),t.params=this.parseBindingList(z.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()},ht.parseClass=function(t,e){var i=this;this.next(),this.parseClassId(t,e),this.parseClassSuper(t);var s=this.startNode(),r=!1;for(s.body=[],this.expect(z.braceL);!this.eat(z.braceR);){var a=i.parseClassMember(s);a&&"MethodDefinition"===a.type&&"constructor"===a.kind&&(r&&i.raise(a.start,"Duplicate constructor in the same class"),r=!0)}return t.body=this.finishNode(s,"ClassBody"),this.finishNode(t,e?"ClassDeclaration":"ClassExpression")},ht.parseClassMember=function(t){var e=this;if(this.eat(z.semi))return null;var i=this.startNode(),s=function(t,s){void 0===s&&(s=!1);var r=e.start,a=e.startLoc;return!!e.eatContextual(t)&&(!(e.type===z.parenL||s&&e.canInsertSemicolon())||(i.key&&e.unexpected(),i.computed=!1,i.key=e.startNodeAt(r,a),i.key.name=t,e.finishNode(i.key,"Identifier"),!1))};i.kind="method",i.static=s("static");var r=this.eat(z.star),a=!1;r||(this.options.ecmaVersion>=8&&s("async",!0)?(a=!0,r=this.options.ecmaVersion>=9&&this.eat(z.star)):s("get")?i.kind="get":s("set")&&(i.kind="set")),i.key||this.parsePropertyName(i);var n=i.key;return i.computed||i.static||!("Identifier"===n.type&&"constructor"===n.name||"Literal"===n.type&&"constructor"===n.value)?i.static&&"Identifier"===n.type&&"prototype"===n.name&&this.raise(n.start,"Classes may not have a static property named prototype"):("method"!==i.kind&&this.raise(n.start,"Constructor can't have get/set modifier"),r&&this.raise(n.start,"Constructor can't be a generator"),a&&this.raise(n.start,"Constructor can't be an async method"),i.kind="constructor"),this.parseClassMethod(t,i,r,a),"get"===i.kind&&0!==i.value.params.length&&this.raiseRecoverable(i.value.start,"getter should have no params"),"set"===i.kind&&1!==i.value.params.length&&this.raiseRecoverable(i.value.start,"setter should have exactly one param"),"set"===i.kind&&"RestElement"===i.value.params[0].type&&this.raiseRecoverable(i.value.params[0].start,"Setter cannot use rest params"),i},ht.parseClassMethod=function(t,e,i,s){e.value=this.parseMethod(i,s),t.body.push(this.finishNode(e,"MethodDefinition"))},ht.parseClassId=function(t,e){t.id=this.type===z.name?this.parseIdent():!0===e?this.unexpected():null},ht.parseClassSuper=function(t){t.superClass=this.eat(z._extends)?this.parseExprSubscripts():null},ht.parseExport=function(t,e){var i=this;if(this.next(),this.eat(z.star))return this.expectContextual("from"),this.type!==z.string&&this.unexpected(),t.source=this.parseExprAtom(),this.semicolon(),this.finishNode(t,"ExportAllDeclaration");if(this.eat(z._default)){this.checkExport(e,"default",this.lastTokStart);var s;if(this.type===z._function||(s=this.isAsyncFunction())){var r=this.startNode();this.next(),s&&this.next(),t.declaration=this.parseFunction(r,"nullableID",!1,s)}else if(this.type===z._class){var a=this.startNode();t.declaration=this.parseClass(a,"nullableID")}else t.declaration=this.parseMaybeAssign(),this.semicolon();return this.finishNode(t,"ExportDefaultDeclaration")}if(this.shouldParseExportStatement())t.declaration=this.parseStatement(!0),"VariableDeclaration"===t.declaration.type?this.checkVariableExport(e,t.declaration.declarations):this.checkExport(e,t.declaration.id.name,t.declaration.id.start),t.specifiers=[],t.source=null;else{if(t.declaration=null,t.specifiers=this.parseExportSpecifiers(e),this.eatContextual("from"))this.type!==z.string&&this.unexpected(),t.source=this.parseExprAtom();else{for(var n=0,o=t.specifiers;n<o.length;n+=1){var h=o[n];i.checkUnreserved(h.local)}t.source=null}this.semicolon()}return this.finishNode(t,"ExportNamedDeclaration")},ht.checkExport=function(t,e,i){t&&(o(t,e)&&this.raiseRecoverable(i,"Duplicate export '"+e+"'"),t[e]=!0)},ht.checkPatternExport=function(t,e){var i=this,s=e.type;if("Identifier"===s)this.checkExport(t,e.name,e.start);else if("ObjectPattern"===s)for(var r=0,a=e.properties;r<a.length;r+=1){var n=a[r];i.checkPatternExport(t,n)}else if("ArrayPattern"===s)for(var o=0,h=e.elements;o<h.length;o+=1){var p=h[o];p&&i.checkPatternExport(t,p)}else"Property"===s?this.checkPatternExport(t,e.value):"AssignmentPattern"===s?this.checkPatternExport(t,e.left):"RestElement"===s?this.checkPatternExport(t,e.argument):"ParenthesizedExpression"===s&&this.checkPatternExport(t,e.expression)},ht.checkVariableExport=function(t,e){var i=this;if(t)for(var s=0,r=e;s<r.length;s+=1){var a=r[s];i.checkPatternExport(t,a.id)}},ht.shouldParseExportStatement=function(){return"var"===this.type.keyword||"const"===this.type.keyword||"class"===this.type.keyword||"function"===this.type.keyword||this.isLet()||this.isAsyncFunction()},ht.parseExportSpecifiers=function(t){var e=this,i=[],s=!0;for(this.expect(z.braceL);!this.eat(z.braceR);){if(s)s=!1;else if(e.expect(z.comma),e.afterTrailingComma(z.braceR))break;var r=e.startNode();r.local=e.parseIdent(!0),r.exported=e.eatContextual("as")?e.parseIdent(!0):r.local,e.checkExport(t,r.exported.name,r.exported.start),i.push(e.finishNode(r,"ExportSpecifier"))}return i},ht.parseImport=function(t){return this.next(),this.type===z.string?(t.specifiers=ut,t.source=this.parseExprAtom()):(t.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),t.source=this.type===z.string?this.parseExprAtom():this.unexpected()),this.semicolon(),this.finishNode(t,"ImportDeclaration")},ht.parseImportSpecifiers=function(){var t=this,e=[],i=!0;if(this.type===z.name){var s=this.startNode();if(s.local=this.parseIdent(),this.checkLVal(s.local,"let"),e.push(this.finishNode(s,"ImportDefaultSpecifier")),!this.eat(z.comma))return e}if(this.type===z.star){var r=this.startNode();return this.next(),this.expectContextual("as"),r.local=this.parseIdent(),this.checkLVal(r.local,"let"),e.push(this.finishNode(r,"ImportNamespaceSpecifier")),e}for(this.expect(z.braceL);!this.eat(z.braceR);){if(i)i=!1;else if(t.expect(z.comma),t.afterTrailingComma(z.braceR))break;var a=t.startNode();a.imported=t.parseIdent(!0),t.eatContextual("as")?a.local=t.parseIdent():(t.checkUnreserved(a.imported),a.local=a.imported),t.checkLVal(a.local,"let"),e.push(t.finishNode(a,"ImportSpecifier"))}return e},ht.adaptDirectivePrologue=function(t){for(var e=0;e<t.length&&this.isDirectiveCandidate(t[e]);++e)t[e].directive=t[e].expression.raw.slice(1,-1)},ht.isDirectiveCandidate=function(t){return"ExpressionStatement"===t.type&&"Literal"===t.expression.type&&"string"==typeof t.expression.value&&('"'===this.input[t.start]||"'"===this.input[t.start])};var lt=at.prototype;lt.toAssignable=function(t,e,i){var s=this;if(this.options.ecmaVersion>=6&&t)switch(t.type){case"Identifier":this.inAsync&&"await"===t.name&&this.raise(t.start,"Can not use 'await' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"RestElement":break;case"ObjectExpression":t.type="ObjectPattern",i&&this.checkPatternErrors(i,!0);for(var r=0,a=t.properties;r<a.length;r+=1){var n=a[r];s.toAssignable(n,e),
"RestElement"!==n.type||"ArrayPattern"!==n.argument.type&&"ObjectPattern"!==n.argument.type||s.raise(n.argument.start,"Unexpected token")}break;case"Property":"init"!==t.kind&&this.raise(t.key.start,"Object pattern can't contain getter or setter"),this.toAssignable(t.value,e);break;case"ArrayExpression":t.type="ArrayPattern",i&&this.checkPatternErrors(i,!0),this.toAssignableList(t.elements,e);break;case"SpreadElement":t.type="RestElement",this.toAssignable(t.argument,e),"AssignmentPattern"===t.argument.type&&this.raise(t.argument.start,"Rest elements cannot have a default value");break;case"AssignmentExpression":"="!==t.operator&&this.raise(t.left.end,"Only '=' operator can be used for specifying default value."),t.type="AssignmentPattern",delete t.operator,this.toAssignable(t.left,e);case"AssignmentPattern":break;case"ParenthesizedExpression":this.toAssignable(t.expression,e);break;case"MemberExpression":if(!e)break;default:this.raise(t.start,"Assigning to rvalue")}else i&&this.checkPatternErrors(i,!0);return t},lt.toAssignableList=function(t,e){for(var i=this,s=t.length,r=0;r<s;r++){var a=t[r];a&&i.toAssignable(a,e)}if(s){var n=t[s-1];6===this.options.ecmaVersion&&e&&n&&"RestElement"===n.type&&"Identifier"!==n.argument.type&&this.unexpected(n.argument.start)}return t},lt.parseSpread=function(t){var e=this.startNode();return this.next(),e.argument=this.parseMaybeAssign(!1,t),this.finishNode(e,"SpreadElement")},lt.parseRestBinding=function(){var t=this.startNode();return this.next(),6===this.options.ecmaVersion&&this.type!==z.name&&this.unexpected(),t.argument=this.parseBindingAtom(),this.finishNode(t,"RestElement")},lt.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case z.bracketL:var t=this.startNode();return this.next(),t.elements=this.parseBindingList(z.bracketR,!0,!0),this.finishNode(t,"ArrayPattern");case z.braceL:return this.parseObj(!0)}return this.parseIdent()},lt.parseBindingList=function(t,e,i){for(var s=this,r=[],a=!0;!this.eat(t);)if(a?a=!1:s.expect(z.comma),e&&s.type===z.comma)r.push(null);else{if(i&&s.afterTrailingComma(t))break;if(s.type===z.ellipsis){var n=s.parseRestBinding();s.parseBindingListItem(n),r.push(n),s.type===z.comma&&s.raise(s.start,"Comma is not permitted after the rest element"),s.expect(t);break}var o=s.parseMaybeDefault(s.start,s.startLoc);s.parseBindingListItem(o),r.push(o)}return r},lt.parseBindingListItem=function(t){return t},lt.parseMaybeDefault=function(t,e,i){if(i=i||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(z.eq))return i;var s=this.startNodeAt(t,e);return s.left=i,s.right=this.parseMaybeAssign(),this.finishNode(s,"AssignmentPattern")},lt.checkLVal=function(t,e,i){var s=this;switch(t.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(t.name)&&this.raiseRecoverable(t.start,(e?"Binding ":"Assigning to ")+t.name+" in strict mode"),i&&(o(i,t.name)&&this.raiseRecoverable(t.start,"Argument name clash"),i[t.name]=!0),e&&"none"!==e&&(("var"===e&&!this.canDeclareVarName(t.name)||"var"!==e&&!this.canDeclareLexicalName(t.name))&&this.raiseRecoverable(t.start,"Identifier '"+t.name+"' has already been declared"),"var"===e?this.declareVarName(t.name):this.declareLexicalName(t.name));break;case"MemberExpression":e&&this.raiseRecoverable(t.start,"Binding member expression");break;case"ObjectPattern":for(var r=0,a=t.properties;r<a.length;r+=1){var n=a[r];s.checkLVal(n,e,i)}break;case"Property":this.checkLVal(t.value,e,i);break;case"ArrayPattern":for(var h=0,p=t.elements;h<p.length;h+=1){var c=p[h];c&&s.checkLVal(c,e,i)}break;case"AssignmentPattern":this.checkLVal(t.left,e,i);break;case"RestElement":this.checkLVal(t.argument,e,i);break;case"ParenthesizedExpression":this.checkLVal(t.expression,e,i);break;default:this.raise(t.start,(e?"Binding":"Assigning to")+" rvalue")}};var dt=at.prototype;dt.checkPropClash=function(t,e,i){if(!(this.options.ecmaVersion>=9&&"SpreadElement"===t.type||this.options.ecmaVersion>=6&&(t.computed||t.method||t.shorthand))){var s,r=t.key;switch(r.type){case"Identifier":s=r.name;break;case"Literal":s=String(r.value);break;default:return}var a=t.kind;if(this.options.ecmaVersion>=6)return void("__proto__"===s&&"init"===a&&(e.proto&&(i&&i.doubleProto<0?i.doubleProto=r.start:this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),e.proto=!0));s="$"+s;var n=e[s];if(n){var o;o="init"===a?this.strict&&n.init||n.get||n.set:n.init||n[a],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else n=e[s]={init:!1,get:!1,set:!1};n[a]=!0}},dt.parseExpression=function(t,e){var i=this,s=this.start,r=this.startLoc,a=this.parseMaybeAssign(t,e);if(this.type===z.comma){var n=this.startNodeAt(s,r);for(n.expressions=[a];this.eat(z.comma);)n.expressions.push(i.parseMaybeAssign(t,e));return this.finishNode(n,"SequenceExpression")}return a},dt.parseMaybeAssign=function(t,e,i){if(this.inGenerator&&this.isContextual("yield"))return this.parseYield();var s=!1,r=-1,a=-1;e?(r=e.parenthesizedAssign,a=e.trailingComma,e.parenthesizedAssign=e.trailingComma=-1):(e=new l,s=!0);var n=this.start,o=this.startLoc;this.type!==z.parenL&&this.type!==z.name||(this.potentialArrowAt=this.start);var h=this.parseMaybeConditional(t,e);if(i&&(h=i.call(this,h,n,o)),this.type.isAssign){var p=this.startNodeAt(n,o);return p.operator=this.value,p.left=this.type===z.eq?this.toAssignable(h,!1,e):h,s||l.call(e),e.shorthandAssign=-1,this.checkLVal(h),this.next(),p.right=this.parseMaybeAssign(t),this.finishNode(p,"AssignmentExpression")}return s&&this.checkExpressionErrors(e,!0),r>-1&&(e.parenthesizedAssign=r),a>-1&&(e.trailingComma=a),h},dt.parseMaybeConditional=function(t,e){var i=this.start,s=this.startLoc,r=this.parseExprOps(t,e);if(this.checkExpressionErrors(e))return r;if(this.eat(z.question)){var a=this.startNodeAt(i,s);return a.test=r,a.consequent=this.parseMaybeAssign(),this.expect(z.colon),a.alternate=this.parseMaybeAssign(t),this.finishNode(a,"ConditionalExpression")}return r},dt.parseExprOps=function(t,e){var i=this.start,s=this.startLoc,r=this.parseMaybeUnary(e,!1);return this.checkExpressionErrors(e)?r:r.start===i&&"ArrowFunctionExpression"===r.type?r:this.parseExprOp(r,i,s,-1,t)},dt.parseExprOp=function(t,e,i,s,r){var a=this.type.binop;if(null!=a&&(!r||this.type!==z._in)&&a>s){var n=this.type===z.logicalOR||this.type===z.logicalAND,o=this.value;this.next();var h=this.start,p=this.startLoc,c=this.parseExprOp(this.parseMaybeUnary(null,!1),h,p,a,r),u=this.buildBinary(e,i,t,c,o,n);return this.parseExprOp(u,e,i,s,r)}return t},dt.buildBinary=function(t,e,i,s,r,a){var n=this.startNodeAt(t,e);return n.left=i,n.operator=r,n.right=s,this.finishNode(n,a?"LogicalExpression":"BinaryExpression")},dt.parseMaybeUnary=function(t,e){var i,s=this,r=this.start,a=this.startLoc;if(this.isContextual("await")&&(this.inAsync||!this.inFunction&&this.options.allowAwaitOutsideFunction))i=this.parseAwait(),e=!0;else if(this.type.prefix){var n=this.startNode(),o=this.type===z.incDec;n.operator=this.value,n.prefix=!0,this.next(),n.argument=this.parseMaybeUnary(null,!0),this.checkExpressionErrors(t,!0),o?this.checkLVal(n.argument):this.strict&&"delete"===n.operator&&"Identifier"===n.argument.type?this.raiseRecoverable(n.start,"Deleting local variable in strict mode"):e=!0,i=this.finishNode(n,o?"UpdateExpression":"UnaryExpression")}else{if(i=this.parseExprSubscripts(t),this.checkExpressionErrors(t))return i;for(;this.type.postfix&&!this.canInsertSemicolon();){var h=s.startNodeAt(r,a);h.operator=s.value,h.prefix=!1,h.argument=i,s.checkLVal(i),s.next(),i=s.finishNode(h,"UpdateExpression")}}return!e&&this.eat(z.starstar)?this.buildBinary(r,a,i,this.parseMaybeUnary(null,!1),"**",!1):i},dt.parseExprSubscripts=function(t){var e=this.start,i=this.startLoc,s=this.parseExprAtom(t),r="ArrowFunctionExpression"===s.type&&")"!==this.input.slice(this.lastTokStart,this.lastTokEnd);if(this.checkExpressionErrors(t)||r)return s;var a=this.parseSubscripts(s,e,i);return t&&"MemberExpression"===a.type&&(t.parenthesizedAssign>=a.start&&(t.parenthesizedAssign=-1),t.parenthesizedBind>=a.start&&(t.parenthesizedBind=-1)),a},dt.parseSubscripts=function(t,e,i,s){for(var r=this,a=this.options.ecmaVersion>=8&&"Identifier"===t.type&&"async"===t.name&&this.lastTokEnd===t.end&&!this.canInsertSemicolon()&&"async"===this.input.slice(t.start,t.end),n=void 0;;)if((n=r.eat(z.bracketL))||r.eat(z.dot)){var o=r.startNodeAt(e,i);o.object=t,o.property=n?r.parseExpression():r.parseIdent(!0),o.computed=!!n,n&&r.expect(z.bracketR),t=r.finishNode(o,"MemberExpression")}else if(!s&&r.eat(z.parenL)){var h=new l,p=r.yieldPos,c=r.awaitPos;r.yieldPos=0,r.awaitPos=0;var u=r.parseExprList(z.parenR,r.options.ecmaVersion>=8,!1,h);if(a&&!r.canInsertSemicolon()&&r.eat(z.arrow))return r.checkPatternErrors(h,!1),r.checkYieldAwaitInDefaultParams(),r.yieldPos=p,r.awaitPos=c,r.parseArrowExpression(r.startNodeAt(e,i),u,!0);r.checkExpressionErrors(h,!0),r.yieldPos=p||r.yieldPos,r.awaitPos=c||r.awaitPos;var d=r.startNodeAt(e,i);d.callee=t,d.arguments=u,t=r.finishNode(d,"CallExpression")}else{if(r.type!==z.backQuote)return t;var f=r.startNodeAt(e,i);f.tag=t,f.quasi=r.parseTemplate({isTagged:!0}),t=r.finishNode(f,"TaggedTemplateExpression")}},dt.parseExprAtom=function(t){var e,i=this.potentialArrowAt===this.start;switch(this.type){case z._super:return this.inFunction||this.raise(this.start,"'super' outside of function or class"),e=this.startNode(),this.next(),this.type!==z.dot&&this.type!==z.bracketL&&this.type!==z.parenL&&this.unexpected(),this.finishNode(e,"Super");case z._this:return e=this.startNode(),this.next(),this.finishNode(e,"ThisExpression");case z.name:var s=this.start,r=this.startLoc,a=this.containsEsc,n=this.parseIdent(this.type!==z.name);if(this.options.ecmaVersion>=8&&!a&&"async"===n.name&&!this.canInsertSemicolon()&&this.eat(z._function))return this.parseFunction(this.startNodeAt(s,r),!1,!1,!0);if(i&&!this.canInsertSemicolon()){if(this.eat(z.arrow))return this.parseArrowExpression(this.startNodeAt(s,r),[n],!1);if(this.options.ecmaVersion>=8&&"async"===n.name&&this.type===z.name&&!a)return n=this.parseIdent(),!this.canInsertSemicolon()&&this.eat(z.arrow)||this.unexpected(),this.parseArrowExpression(this.startNodeAt(s,r),[n],!0)}return n;case z.regexp:var o=this.value;return e=this.parseLiteral(o.value),e.regex={pattern:o.pattern,flags:o.flags},e;case z.num:case z.string:return this.parseLiteral(this.value);case z._null:case z._true:case z._false:return e=this.startNode(),e.value=this.type===z._null?null:this.type===z._true,e.raw=this.type.keyword,this.next(),this.finishNode(e,"Literal");case z.parenL:var h=this.start,p=this.parseParenAndDistinguishExpression(i);return t&&(t.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(t.parenthesizedAssign=h),t.parenthesizedBind<0&&(t.parenthesizedBind=h)),p;case z.bracketL:return e=this.startNode(),this.next(),e.elements=this.parseExprList(z.bracketR,!0,!0,t),this.finishNode(e,"ArrayExpression");case z.braceL:return this.parseObj(!1,t);case z._function:return e=this.startNode(),this.next(),this.parseFunction(e,!1);case z._class:return this.parseClass(this.startNode(),!1);case z._new:return this.parseNew();case z.backQuote:return this.parseTemplate();default:this.unexpected()}},dt.parseLiteral=function(t){var e=this.startNode();return e.value=t,e.raw=this.input.slice(this.start,this.end),this.next(),this.finishNode(e,"Literal")},dt.parseParenExpression=function(){this.expect(z.parenL);var t=this.parseExpression();return this.expect(z.parenR),t},dt.parseParenAndDistinguishExpression=function(t){var e,i=this,s=this.start,r=this.startLoc,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var n,o=this.start,h=this.startLoc,p=[],c=!0,u=!1,d=new l,f=this.yieldPos,m=this.awaitPos;for(this.yieldPos=0,this.awaitPos=0;this.type!==z.parenR;){if(c?c=!1:i.expect(z.comma),a&&i.afterTrailingComma(z.parenR,!0)){u=!0;break}if(i.type===z.ellipsis){n=i.start,p.push(i.parseParenItem(i.parseRestBinding())),i.type===z.comma&&i.raise(i.start,"Comma is not permitted after the rest element");break}p.push(i.parseMaybeAssign(!1,d,i.parseParenItem))}var x=this.start,g=this.startLoc;if(this.expect(z.parenR),t&&!this.canInsertSemicolon()&&this.eat(z.arrow))return this.checkPatternErrors(d,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=f,this.awaitPos=m,this.parseParenArrowList(s,r,p);p.length&&!u||this.unexpected(this.lastTokStart),n&&this.unexpected(n),this.checkExpressionErrors(d,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=m||this.awaitPos,p.length>1?(e=this.startNodeAt(o,h),e.expressions=p,this.finishNodeAt(e,"SequenceExpression",x,g)):e=p[0]}else e=this.parseParenExpression();if(this.options.preserveParens){var v=this.startNodeAt(s,r);return v.expression=e,this.finishNode(v,"ParenthesizedExpression")}return e},dt.parseParenItem=function(t){return t},dt.parseParenArrowList=function(t,e,i){return this.parseArrowExpression(this.startNodeAt(t,e),i)};var ft=[];dt.parseNew=function(){var t=this.startNode(),e=this.parseIdent(!0);if(this.options.ecmaVersion>=6&&this.eat(z.dot)){t.meta=e;var i=this.containsEsc;return t.property=this.parseIdent(!0),("target"!==t.property.name||i)&&this.raiseRecoverable(t.property.start,"The only valid meta property for new is new.target"),this.inFunction||this.raiseRecoverable(t.start,"new.target can only be used in functions"),this.finishNode(t,"MetaProperty")}var s=this.start,r=this.startLoc;return t.callee=this.parseSubscripts(this.parseExprAtom(),s,r,!0),this.eat(z.parenL)?t.arguments=this.parseExprList(z.parenR,this.options.ecmaVersion>=8,!1):t.arguments=ft,this.finishNode(t,"NewExpression")},dt.parseTemplateElement=function(t){var e=t.isTagged,i=this.startNode();return this.type===z.invalidTemplate?(e||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),i.value={raw:this.value,cooked:null}):i.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,"\n"),cooked:this.value},this.next(),i.tail=this.type===z.backQuote,this.finishNode(i,"TemplateElement")},dt.parseTemplate=function(t){var e=this;void 0===t&&(t={});var i=t.isTagged;void 0===i&&(i=!1);var s=this.startNode();this.next(),s.expressions=[];var r=this.parseTemplateElement({isTagged:i});for(s.quasis=[r];!r.tail;)e.expect(z.dollarBraceL),s.expressions.push(e.parseExpression()),e.expect(z.braceR),s.quasis.push(r=e.parseTemplateElement({isTagged:i}));return this.next(),this.finishNode(s,"TemplateLiteral")},dt.isAsyncProp=function(t){return!t.computed&&"Identifier"===t.key.type&&"async"===t.key.name&&(this.type===z.name||this.type===z.num||this.type===z.string||this.type===z.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===z.star)&&!Q.test(this.input.slice(this.lastTokEnd,this.start))},dt.parseObj=function(t,e){var i=this,s=this.startNode(),r=!0,a={};for(s.properties=[],this.next();!this.eat(z.braceR);){if(r)r=!1;else if(i.expect(z.comma),i.afterTrailingComma(z.braceR))break;var n=i.parseProperty(t,e);t||i.checkPropClash(n,a,e),s.properties.push(n)}return this.finishNode(s,t?"ObjectPattern":"ObjectExpression")},dt.parseProperty=function(t,e){var i,s,r,a,n=this.startNode();if(this.options.ecmaVersion>=9&&this.eat(z.ellipsis))return t?(n.argument=this.parseIdent(!1),this.type===z.comma&&this.raise(this.start,"Comma is not permitted after the rest element"),this.finishNode(n,"RestElement")):(this.type===z.parenL&&e&&(e.parenthesizedAssign<0&&(e.parenthesizedAssign=this.start),e.parenthesizedBind<0&&(e.parenthesizedBind=this.start)),n.argument=this.parseMaybeAssign(!1,e),this.type===z.comma&&e&&e.trailingComma<0&&(e.trailingComma=this.start),this.finishNode(n,"SpreadElement"));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(t||e)&&(r=this.start,a=this.startLoc),t||(i=this.eat(z.star)));var o=this.containsEsc;return this.parsePropertyName(n),!t&&!o&&this.options.ecmaVersion>=8&&!i&&this.isAsyncProp(n)?(s=!0,i=this.options.ecmaVersion>=9&&this.eat(z.star),this.parsePropertyName(n,e)):s=!1,this.parsePropertyValue(n,t,i,s,r,a,e,o),this.finishNode(n,"Property")},dt.parsePropertyValue=function(t,e,i,s,r,a,n,o){if((i||s)&&this.type===z.colon&&this.unexpected(),this.eat(z.colon))t.value=e?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,n),t.kind="init";else if(this.options.ecmaVersion>=6&&this.type===z.parenL)e&&this.unexpected(),t.kind="init",t.method=!0,t.value=this.parseMethod(i,s);else if(e||o||!(this.options.ecmaVersion>=5)||t.computed||"Identifier"!==t.key.type||"get"!==t.key.name&&"set"!==t.key.name||this.type===z.comma||this.type===z.braceR)this.options.ecmaVersion>=6&&!t.computed&&"Identifier"===t.key.type?(this.checkUnreserved(t.key),t.kind="init",e?t.value=this.parseMaybeDefault(r,a,t.key):this.type===z.eq&&n?(n.shorthandAssign<0&&(n.shorthandAssign=this.start),t.value=this.parseMaybeDefault(r,a,t.key)):t.value=t.key,t.shorthand=!0):this.unexpected();else{(i||s)&&this.unexpected(),t.kind=t.key.name,this.parsePropertyName(t),t.value=this.parseMethod(!1);var h="get"===t.kind?0:1;if(t.value.params.length!==h){var p=t.value.start;"get"===t.kind?this.raiseRecoverable(p,"getter should have no params"):this.raiseRecoverable(p,"setter should have exactly one param")}else"set"===t.kind&&"RestElement"===t.value.params[0].type&&this.raiseRecoverable(t.value.params[0].start,"Setter cannot use rest params")}},dt.parsePropertyName=function(t){if(this.options.ecmaVersion>=6){if(this.eat(z.bracketL))return t.computed=!0,t.key=this.parseMaybeAssign(),this.expect(z.bracketR),t.key;t.computed=!1}return t.key=this.type===z.num||this.type===z.string?this.parseExprAtom():this.parseIdent(!0)},dt.initFunction=function(t){t.id=null,this.options.ecmaVersion>=6&&(t.generator=!1,t.expression=!1),this.options.ecmaVersion>=8&&(t.async=!1)},dt.parseMethod=function(t,e){var i=this.startNode(),s=this.inGenerator,r=this.inAsync,a=this.yieldPos,n=this.awaitPos,o=this.inFunction;return this.initFunction(i),this.options.ecmaVersion>=6&&(i.generator=t),this.options.ecmaVersion>=8&&(i.async=!!e),this.inGenerator=i.generator,this.inAsync=i.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,this.enterFunctionScope(),this.expect(z.parenL),i.params=this.parseBindingList(z.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(i,!1),this.inGenerator=s,this.inAsync=r,this.yieldPos=a,this.awaitPos=n,this.inFunction=o,this.finishNode(i,"FunctionExpression")},dt.parseArrowExpression=function(t,e,i){var s=this.inGenerator,r=this.inAsync,a=this.yieldPos,n=this.awaitPos,o=this.inFunction;return this.enterFunctionScope(),this.initFunction(t),this.options.ecmaVersion>=8&&(t.async=!!i),this.inGenerator=!1,this.inAsync=t.async,this.yieldPos=0,this.awaitPos=0,this.inFunction=!0,t.params=this.toAssignableList(e,!0),this.parseFunctionBody(t,!0),this.inGenerator=s,this.inAsync=r,this.yieldPos=a,this.awaitPos=n,this.inFunction=o,this.finishNode(t,"ArrowFunctionExpression")},dt.parseFunctionBody=function(t,e){var i=e&&this.type!==z.braceL,s=this.strict,r=!1;if(i)t.body=this.parseMaybeAssign(),t.expression=!0,this.checkParams(t,!1);else{var a=this.options.ecmaVersion>=7&&!this.isSimpleParamList(t.params);s&&!a||(r=this.strictDirective(this.end))&&a&&this.raiseRecoverable(t.start,"Illegal 'use strict' directive in function with non-simple parameter list");var n=this.labels;this.labels=[],r&&(this.strict=!0),this.checkParams(t,!s&&!r&&!e&&this.isSimpleParamList(t.params)),t.body=this.parseBlock(!1),t.expression=!1,this.adaptDirectivePrologue(t.body.body),this.labels=n}this.exitFunctionScope(),this.strict&&t.id&&this.checkLVal(t.id,"none"),this.strict=s},dt.isSimpleParamList=function(t){for(var e=0,i=t;e<i.length;e+=1){if("Identifier"!==i[e].type)return!1}return!0},dt.checkParams=function(t,e){for(var i=this,s={},r=0,a=t.params;r<a.length;r+=1){var n=a[r];i.checkLVal(n,"var",e?null:s)}},dt.parseExprList=function(t,e,i,s){for(var r=this,a=[],n=!0;!this.eat(t);){if(n)n=!1;else if(r.expect(z.comma),e&&r.afterTrailingComma(t))break;var o=void 0;i&&r.type===z.comma?o=null:r.type===z.ellipsis?(o=r.parseSpread(s),s&&r.type===z.comma&&s.trailingComma<0&&(s.trailingComma=r.start)):o=r.parseMaybeAssign(!1,s),a.push(o)}return a},dt.checkUnreserved=function(t){var e=t.start,i=t.end,s=t.name;if(this.inGenerator&&"yield"===s&&this.raiseRecoverable(e,"Can not use 'yield' as identifier inside a generator"),this.inAsync&&"await"===s&&this.raiseRecoverable(e,"Can not use 'await' as identifier inside an async function"),this.isKeyword(s)&&this.raise(e,"Unexpected keyword '"+s+"'"),!(this.options.ecmaVersion<6&&-1!==this.input.slice(e,i).indexOf("\\"))){(this.strict?this.reservedWordsStrict:this.reservedWords).test(s)&&(this.inAsync||"await"!==s||this.raiseRecoverable(e,"Can not use keyword 'await' outside an async function"),this.raiseRecoverable(e,"The keyword '"+s+"' is reserved"))}},dt.parseIdent=function(t,e){var i=this.startNode();return t&&"never"===this.options.allowReserved&&(t=!1),this.type===z.name?i.name=this.value:this.type.keyword?(i.name=this.type.keyword,"class"!==i.name&&"function"!==i.name||this.lastTokEnd===this.lastTokStart+1&&46===this.input.charCodeAt(this.lastTokStart)||this.context.pop()):this.unexpected(),this.next(),this.finishNode(i,"Identifier"),t||this.checkUnreserved(i),i},dt.parseYield=function(){this.yieldPos||(this.yieldPos=this.start);var t=this.startNode();return this.next(),this.type===z.semi||this.canInsertSemicolon()||this.type!==z.star&&!this.type.startsExpr?(t.delegate=!1,t.argument=null):(t.delegate=this.eat(z.star),t.argument=this.parseMaybeAssign()),this.finishNode(t,"YieldExpression")},dt.parseAwait=function(){this.awaitPos||(this.awaitPos=this.start);var t=this.startNode();return this.next(),t.argument=this.parseMaybeUnary(null,!0),this.finishNode(t,"AwaitExpression")};var mt=at.prototype;mt.raise=function(t,e){var i=h(this.input,t);e+=" ("+i.line+":"+i.column+")";var s=new SyntaxError(e);throw s.pos=t,s.loc=i,s.raisedAt=this.pos,s},mt.raiseRecoverable=mt.raise,mt.curPosition=function(){if(this.options.locations)return new et(this.curLine,this.pos-this.lineStart)};var xt=at.prototype,gt=Object.assign||function(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];for(var s=0,r=e;s<r.length;s+=1){var a=r[s];for(var n in a)o(a,n)&&(t[n]=a[n])}return t};xt.enterFunctionScope=function(){this.scopeStack.push({var:{},lexical:{},childVar:{},parentLexical:{}})},xt.exitFunctionScope=function(){this.scopeStack.pop()},xt.enterLexicalScope=function(){var t=this.scopeStack[this.scopeStack.length-1],e={var:{},lexical:{},childVar:{},parentLexical:{}};this.scopeStack.push(e),gt(e.parentLexical,t.lexical,t.parentLexical)},xt.exitLexicalScope=function(){var t=this.scopeStack.pop(),e=this.scopeStack[this.scopeStack.length-1];gt(e.childVar,t.var,t.childVar)},xt.canDeclareVarName=function(t){var e=this.scopeStack[this.scopeStack.length-1];return!o(e.lexical,t)&&!o(e.parentLexical,t)},xt.canDeclareLexicalName=function(t){var e=this.scopeStack[this.scopeStack.length-1];return!o(e.lexical,t)&&!o(e.var,t)&&!o(e.childVar,t)},xt.declareVarName=function(t){this.scopeStack[this.scopeStack.length-1].var[t]=!0},xt.declareLexicalName=function(t){this.scopeStack[this.scopeStack.length-1].lexical[t]=!0};var vt=function(t,e,i){this.type="",this.start=e,this.end=0,t.options.locations&&(this.loc=new it(t,i)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[e,0])},yt=at.prototype;yt.startNode=function(){return new vt(this,this.start,this.startLoc)},yt.startNodeAt=function(t,e){return new vt(this,t,e)},yt.finishNode=function(t,e){return d.call(this,t,e,this.lastTokEnd,this.lastTokEndLoc)},yt.finishNodeAt=function(t,e,i,s){return d.call(this,t,e,i,s)};var _t=function(t,e,i,s,r){this.token=t,this.isExpr=!!e,this.preserveSpace=!!i,this.override=s,this.generator=!!r},bt={b_stat:new _t("{",!1),b_expr:new _t("{",!0),b_tmpl:new _t("${",!1),p_stat:new _t("(",!1),p_expr:new _t("(",!0),q_tmpl:new _t("`",!0,!0,function(t){return t.tryReadTemplateToken()}),f_stat:new _t("function",!1),f_expr:new _t("function",!0),f_expr_gen:new _t("function",!0,!1,null,!0),f_gen:new _t("function",!1,!1,null,!0)},kt=at.prototype;kt.initialContext=function(){return[bt.b_stat]},kt.braceIsBlock=function(t){var e=this.curContext();return e===bt.f_expr||e===bt.f_stat||(t!==z.colon||e!==bt.b_stat&&e!==bt.b_expr?t===z._return||t===z.name&&this.exprAllowed?Q.test(this.input.slice(this.lastTokEnd,this.start)):t===z._else||t===z.semi||t===z.eof||t===z.parenR||t===z.arrow||(t===z.braceL?e===bt.b_stat:t!==z._var&&t!==z.name&&!this.exprAllowed):!e.isExpr)},kt.inGeneratorContext=function(){for(var t=this,e=this.context.length-1;e>=1;e--){var i=t.context[e];if("function"===i.token)return i.generator}return!1},kt.updateContext=function(t){var e,i=this.type;i.keyword&&t===z.dot?this.exprAllowed=!1:(e=i.updateContext)?e.call(this,t):this.exprAllowed=i.beforeExpr},z.parenR.updateContext=z.braceR.updateContext=function(){if(1===this.context.length)return void(this.exprAllowed=!0);var t=this.context.pop();t===bt.b_stat&&"function"===this.curContext().token&&(t=this.context.pop()),this.exprAllowed=!t.isExpr},z.braceL.updateContext=function(t){this.context.push(this.braceIsBlock(t)?bt.b_stat:bt.b_expr),this.exprAllowed=!0},z.dollarBraceL.updateContext=function(){this.context.push(bt.b_tmpl),this.exprAllowed=!0},z.parenL.updateContext=function(t){var e=t===z._if||t===z._for||t===z._with||t===z._while;this.context.push(e?bt.p_stat:bt.p_expr),this.exprAllowed=!0},z.incDec.updateContext=function(){},z._function.updateContext=z._class.updateContext=function(t){t.beforeExpr&&t!==z.semi&&t!==z._else&&(t!==z.colon&&t!==z.braceL||this.curContext()!==bt.b_stat)?this.context.push(bt.f_expr):this.context.push(bt.f_stat),this.exprAllowed=!1},z.backQuote.updateContext=function(){this.curContext()===bt.q_tmpl?this.context.pop():this.context.push(bt.q_tmpl),this.exprAllowed=!1},z.star.updateContext=function(t){if(t===z._function){var e=this.context.length-1;this.context[e]===bt.f_expr?this.context[e]=bt.f_expr_gen:this.context[e]=bt.f_gen}this.exprAllowed=!0},z.name.updateContext=function(t){var e=!1;this.options.ecmaVersion>=6&&("of"===this.value&&!this.exprAllowed||"yield"===this.value&&this.inGeneratorContext())&&(e=!0),this.exprAllowed=e};var Ct={$LONE:["ASCII","ASCII_Hex_Digit","AHex","Alphabetic","Alpha","Any","Assigned","Bidi_Control","Bidi_C","Bidi_Mirrored","Bidi_M","Case_Ignorable","CI","Cased","Changes_When_Casefolded","CWCF","Changes_When_Casemapped","CWCM","Changes_When_Lowercased","CWL","Changes_When_NFKC_Casefolded","CWKCF","Changes_When_Titlecased","CWT","Changes_When_Uppercased","CWU","Dash","Default_Ignorable_Code_Point","DI","Deprecated","Dep","Diacritic","Dia","Emoji","Emoji_Component","Emoji_Modifier","Emoji_Modifier_Base","Emoji_Presentation","Extender","Ext","Grapheme_Base","Gr_Base","Grapheme_Extend","Gr_Ext","Hex_Digit","Hex","IDS_Binary_Operator","IDSB","IDS_Trinary_Operator","IDST","ID_Continue","IDC","ID_Start","IDS","Ideographic","Ideo","Join_Control","Join_C","Logical_Order_Exception","LOE","Lowercase","Lower","Math","Noncharacter_Code_Point","NChar","Pattern_Syntax","Pat_Syn","Pattern_White_Space","Pat_WS","Quotation_Mark","QMark","Radical","Regional_Indicator","RI","Sentence_Terminal","STerm","Soft_Dotted","SD","Terminal_Punctuation","Term","Unified_Ideograph","UIdeo","Uppercase","Upper","Variation_Selector","VS","White_Space","space","XID_Continue","XIDC","XID_Start","XIDS"],General_Category:["Cased_Letter","LC","Close_Punctuation","Pe","Connector_Punctuation","Pc","Control","Cc","cntrl","Currency_Symbol","Sc","Dash_Punctuation","Pd","Decimal_Number","Nd","digit","Enclosing_Mark","Me","Final_Punctuation","Pf","Format","Cf","Initial_Punctuation","Pi","Letter","L","Letter_Number","Nl","Line_Separator","Zl","Lowercase_Letter","Ll","Mark","M","Combining_Mark","Math_Symbol","Sm","Modifier_Letter","Lm","Modifier_Symbol","Sk","Nonspacing_Mark","Mn","Number","N","Open_Punctuation","Ps","Other","C","Other_Letter","Lo","Other_Number","No","Other_Punctuation","Po","Other_Symbol","So","Paragraph_Separator","Zp","Private_Use","Co","Punctuation","P","punct","Separator","Z","Space_Separator","Zs","Spacing_Mark","Mc","Surrogate","Cs","Symbol","S","Titlecase_Letter","Lt","Unassigned","Cn","Uppercase_Letter","Lu"],Script:["Adlam","Adlm","Ahom","Anatolian_Hieroglyphs","Hluw","Arabic","Arab","Armenian","Armn","Avestan","Avst","Balinese","Bali","Bamum","Bamu","Bassa_Vah","Bass","Batak","Batk","Bengali","Beng","Bhaiksuki","Bhks","Bopomofo","Bopo","Brahmi","Brah","Braille","Brai","Buginese","Bugi","Buhid","Buhd","Canadian_Aboriginal","Cans","Carian","Cari","Caucasian_Albanian","Aghb","Chakma","Cakm","Cham","Cherokee","Cher","Common","Zyyy","Coptic","Copt","Qaac","Cuneiform","Xsux","Cypriot","Cprt","Cyrillic","Cyrl","Deseret","Dsrt","Devanagari","Deva","Duployan","Dupl","Egyptian_Hieroglyphs","Egyp","Elbasan","Elba","Ethiopic","Ethi","Georgian","Geor","Glagolitic","Glag","Gothic","Goth","Grantha","Gran","Greek","Grek","Gujarati","Gujr","Gurmukhi","Guru","Han","Hani","Hangul","Hang","Hanunoo","Hano","Hatran","Hatr","Hebrew","Hebr","Hiragana","Hira","Imperial_Aramaic","Armi","Inherited","Zinh","Qaai","Inscriptional_Pahlavi","Phli","Inscriptional_Parthian","Prti","Javanese","Java","Kaithi","Kthi","Kannada","Knda","Katakana","Kana","Kayah_Li","Kali","Kharoshthi","Khar","Khmer","Khmr","Khojki","Khoj","Khudawadi","Sind","Lao","Laoo","Latin","Latn","Lepcha","Lepc","Limbu","Limb","Linear_A","Lina","Linear_B","Linb","Lisu","Lycian","Lyci","Lydian","Lydi","Mahajani","Mahj","Malayalam","Mlym","Mandaic","Mand","Manichaean","Mani","Marchen","Marc","Masaram_Gondi","Gonm","Meetei_Mayek","Mtei","Mende_Kikakui","Mend","Meroitic_Cursive","Merc","Meroitic_Hieroglyphs","Mero","Miao","Plrd","Modi","Mongolian","Mong","Mro","Mroo","Multani","Mult","Myanmar","Mymr","Nabataean","Nbat","New_Tai_Lue","Talu","Newa","Nko","Nkoo","Nushu","Nshu","Ogham","Ogam","Ol_Chiki","Olck","Old_Hungarian","Hung","Old_Italic","Ital","Old_North_Arabian","Narb","Old_Permic","Perm","Old_Persian","Xpeo","Old_South_Arabian","Sarb","Old_Turkic","Orkh","Oriya","Orya","Osage","Osge","Osmanya","Osma","Pahawh_Hmong","Hmng","Palmyrene","Palm","Pau_Cin_Hau","Pauc","Phags_Pa","Phag","Phoenician","Phnx","Psalter_Pahlavi","Phlp","Rejang","Rjng","Runic","Runr","Samaritan","Samr","Saurashtra","Saur","Sharada","Shrd","Shavian","Shaw","Siddham","Sidd","SignWriting","Sgnw","Sinhala","Sinh","Sora_Sompeng","Sora","Soyombo","Soyo","Sundanese","Sund","Syloti_Nagri","Sylo","Syriac","Syrc","Tagalog","Tglg","Tagbanwa","Tagb","Tai_Le","Tale","Tai_Tham","Lana","Tai_Viet","Tavt","Takri","Takr","Tamil","Taml","Tangut","Tang","Telugu","Telu","Thaana","Thaa","Thai","Tibetan","Tibt","Tifinagh","Tfng","Tirhuta","Tirh","Ugaritic","Ugar","Vai","Vaii","Warang_Citi","Wara","Yi","Yiii","Zanabazar_Square","Zanb"]};Array.prototype.push.apply(Ct.$LONE,Ct.General_Category),Ct.gc=Ct.General_Category,Ct.sc=Ct.Script_Extensions=Ct.scx=Ct.Script;var St=at.prototype,Et=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":""),this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=[],this.backReferenceNames=[]};Et.prototype.reset=function(t,e,i){var s=-1!==i.indexOf("u");this.start=0|t,this.source=e+"",this.flags=i,this.switchU=s&&this.parser.options.ecmaVersion>=6,this.switchN=s&&this.parser.options.ecmaVersion>=9},Et.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)},Et.prototype.at=function(t){var e=this.source,i=e.length;if(t>=i)return-1;var s=e.charCodeAt(t);return!this.switchU||s<=55295||s>=57344||t+1>=i?s:(s<<10)+e.charCodeAt(t+1)-56613888},
Et.prototype.nextIndex=function(t){var e=this.source,i=e.length;if(t>=i)return i;var s=e.charCodeAt(t);return!this.switchU||s<=55295||s>=57344||t+1>=i?t+1:t+2},Et.prototype.current=function(){return this.at(this.pos)},Et.prototype.lookahead=function(){return this.at(this.nextIndex(this.pos))},Et.prototype.advance=function(){this.pos=this.nextIndex(this.pos)},Et.prototype.eat=function(t){return this.current()===t&&(this.advance(),!0)},St.validateRegExpFlags=function(t){for(var e=this,i=t.validFlags,s=t.flags,r=0;r<s.length;r++){var a=s.charAt(r);-1===i.indexOf(a)&&e.raise(t.start,"Invalid regular expression flag"),s.indexOf(a,r+1)>-1&&e.raise(t.start,"Duplicate regular expression flag")}},St.validateRegExpPattern=function(t){this.regexp_pattern(t),!t.switchN&&this.options.ecmaVersion>=9&&t.groupNames.length>0&&(t.switchN=!0,this.regexp_pattern(t))},St.regexp_pattern=function(t){t.pos=0,t.lastIntValue=0,t.lastStringValue="",t.lastAssertionIsQuantifiable=!1,t.numCapturingParens=0,t.maxBackReference=0,t.groupNames.length=0,t.backReferenceNames.length=0,this.regexp_disjunction(t),t.pos!==t.source.length&&(t.eat(41)&&t.raise("Unmatched ')'"),(t.eat(93)||t.eat(125))&&t.raise("Lone quantifier brackets")),t.maxBackReference>t.numCapturingParens&&t.raise("Invalid escape");for(var e=0,i=t.backReferenceNames;e<i.length;e+=1){var s=i[e];-1===t.groupNames.indexOf(s)&&t.raise("Invalid named capture referenced")}},St.regexp_disjunction=function(t){var e=this;for(this.regexp_alternative(t);t.eat(124);)e.regexp_alternative(t);this.regexp_eatQuantifier(t,!0)&&t.raise("Nothing to repeat"),t.eat(123)&&t.raise("Lone quantifier brackets")},St.regexp_alternative=function(t){for(;t.pos<t.source.length&&this.regexp_eatTerm(t););},St.regexp_eatTerm=function(t){return this.regexp_eatAssertion(t)?(t.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(t)&&t.switchU&&t.raise("Invalid quantifier"),!0):!(t.switchU?!this.regexp_eatAtom(t):!this.regexp_eatExtendedAtom(t))&&(this.regexp_eatQuantifier(t),!0)},St.regexp_eatAssertion=function(t){var e=t.pos;if(t.lastAssertionIsQuantifiable=!1,t.eat(94)||t.eat(36))return!0;if(t.eat(92)){if(t.eat(66)||t.eat(98))return!0;t.pos=e}if(t.eat(40)&&t.eat(63)){var i=!1;if(this.options.ecmaVersion>=9&&(i=t.eat(60)),t.eat(61)||t.eat(33))return this.regexp_disjunction(t),t.eat(41)||t.raise("Unterminated group"),t.lastAssertionIsQuantifiable=!i,!0}return t.pos=e,!1},St.regexp_eatQuantifier=function(t,e){return void 0===e&&(e=!1),!!this.regexp_eatQuantifierPrefix(t,e)&&(t.eat(63),!0)},St.regexp_eatQuantifierPrefix=function(t,e){return t.eat(42)||t.eat(43)||t.eat(63)||this.regexp_eatBracedQuantifier(t,e)},St.regexp_eatBracedQuantifier=function(t,e){var i=t.pos;if(t.eat(123)){var s=0,r=-1;if(this.regexp_eatDecimalDigits(t)&&(s=t.lastIntValue,t.eat(44)&&this.regexp_eatDecimalDigits(t)&&(r=t.lastIntValue),t.eat(125)))return-1!==r&&r<s&&!e&&t.raise("numbers out of order in {} quantifier"),!0;t.switchU&&!e&&t.raise("Incomplete quantifier"),t.pos=i}return!1},St.regexp_eatAtom=function(t){return this.regexp_eatPatternCharacters(t)||t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)},St.regexp_eatReverseSolidusAtomEscape=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatAtomEscape(t))return!0;t.pos=e}return!1},St.regexp_eatUncapturingGroup=function(t){var e=t.pos;if(t.eat(40)){if(t.eat(63)&&t.eat(58)){if(this.regexp_disjunction(t),t.eat(41))return!0;t.raise("Unterminated group")}t.pos=e}return!1},St.regexp_eatCapturingGroup=function(t){if(t.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(t):63===t.current()&&t.raise("Invalid group"),this.regexp_disjunction(t),t.eat(41))return t.numCapturingParens+=1,!0;t.raise("Unterminated group")}return!1},St.regexp_eatExtendedAtom=function(t){return t.eat(46)||this.regexp_eatReverseSolidusAtomEscape(t)||this.regexp_eatCharacterClass(t)||this.regexp_eatUncapturingGroup(t)||this.regexp_eatCapturingGroup(t)||this.regexp_eatInvalidBracedQuantifier(t)||this.regexp_eatExtendedPatternCharacter(t)},St.regexp_eatInvalidBracedQuantifier=function(t){return this.regexp_eatBracedQuantifier(t,!0)&&t.raise("Nothing to repeat"),!1},St.regexp_eatSyntaxCharacter=function(t){var e=t.current();return!!m(e)&&(t.lastIntValue=e,t.advance(),!0)},St.regexp_eatPatternCharacters=function(t){for(var e=t.pos,i=0;-1!==(i=t.current())&&!m(i);)t.advance();return t.pos!==e},St.regexp_eatExtendedPatternCharacter=function(t){var e=t.current();return!(-1===e||36===e||e>=40&&e<=43||46===e||63===e||91===e||94===e||124===e)&&(t.advance(),!0)},St.regexp_groupSpecifier=function(t){if(t.eat(63)){if(this.regexp_eatGroupName(t))return-1!==t.groupNames.indexOf(t.lastStringValue)&&t.raise("Duplicate capture group name"),void t.groupNames.push(t.lastStringValue);t.raise("Invalid group")}},St.regexp_eatGroupName=function(t){if(t.lastStringValue="",t.eat(60)){if(this.regexp_eatRegExpIdentifierName(t)&&t.eat(62))return!0;t.raise("Invalid capture group name")}return!1},St.regexp_eatRegExpIdentifierName=function(t){if(t.lastStringValue="",this.regexp_eatRegExpIdentifierStart(t)){for(t.lastStringValue+=f(t.lastIntValue);this.regexp_eatRegExpIdentifierPart(t);)t.lastStringValue+=f(t.lastIntValue);return!0}return!1},St.regexp_eatRegExpIdentifierStart=function(t){var e=t.pos,i=t.current();return t.advance(),92===i&&this.regexp_eatRegExpUnicodeEscapeSequence(t)&&(i=t.lastIntValue),x(i)?(t.lastIntValue=i,!0):(t.pos=e,!1)},St.regexp_eatRegExpIdentifierPart=function(t){var e=t.pos,i=t.current();return t.advance(),92===i&&this.regexp_eatRegExpUnicodeEscapeSequence(t)&&(i=t.lastIntValue),g(i)?(t.lastIntValue=i,!0):(t.pos=e,!1)},St.regexp_eatAtomEscape=function(t){return!!(this.regexp_eatBackReference(t)||this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)||t.switchN&&this.regexp_eatKGroupName(t))||(t.switchU&&(99===t.current()&&t.raise("Invalid unicode escape"),t.raise("Invalid escape")),!1)},St.regexp_eatBackReference=function(t){var e=t.pos;if(this.regexp_eatDecimalEscape(t)){var i=t.lastIntValue;if(t.switchU)return i>t.maxBackReference&&(t.maxBackReference=i),!0;if(i<=t.numCapturingParens)return!0;t.pos=e}return!1},St.regexp_eatKGroupName=function(t){if(t.eat(107)){if(this.regexp_eatGroupName(t))return t.backReferenceNames.push(t.lastStringValue),!0;t.raise("Invalid named reference")}return!1},St.regexp_eatCharacterEscape=function(t){return this.regexp_eatControlEscape(t)||this.regexp_eatCControlLetter(t)||this.regexp_eatZero(t)||this.regexp_eatHexEscapeSequence(t)||this.regexp_eatRegExpUnicodeEscapeSequence(t)||!t.switchU&&this.regexp_eatLegacyOctalEscapeSequence(t)||this.regexp_eatIdentityEscape(t)},St.regexp_eatCControlLetter=function(t){var e=t.pos;if(t.eat(99)){if(this.regexp_eatControlLetter(t))return!0;t.pos=e}return!1},St.regexp_eatZero=function(t){return 48===t.current()&&!C(t.lookahead())&&(t.lastIntValue=0,t.advance(),!0)},St.regexp_eatControlEscape=function(t){var e=t.current();return 116===e?(t.lastIntValue=9,t.advance(),!0):110===e?(t.lastIntValue=10,t.advance(),!0):118===e?(t.lastIntValue=11,t.advance(),!0):102===e?(t.lastIntValue=12,t.advance(),!0):114===e&&(t.lastIntValue=13,t.advance(),!0)},St.regexp_eatControlLetter=function(t){var e=t.current();return!!v(e)&&(t.lastIntValue=e%32,t.advance(),!0)},St.regexp_eatRegExpUnicodeEscapeSequence=function(t){var e=t.pos;if(t.eat(117)){if(this.regexp_eatFixedHexDigits(t,4)){var i=t.lastIntValue;if(t.switchU&&i>=55296&&i<=56319){var s=t.pos;if(t.eat(92)&&t.eat(117)&&this.regexp_eatFixedHexDigits(t,4)){var r=t.lastIntValue;if(r>=56320&&r<=57343)return t.lastIntValue=1024*(i-55296)+(r-56320)+65536,!0}t.pos=s,t.lastIntValue=i}return!0}if(t.switchU&&t.eat(123)&&this.regexp_eatHexDigits(t)&&t.eat(125)&&y(t.lastIntValue))return!0;t.switchU&&t.raise("Invalid unicode escape"),t.pos=e}return!1},St.regexp_eatIdentityEscape=function(t){if(t.switchU)return!!this.regexp_eatSyntaxCharacter(t)||!!t.eat(47)&&(t.lastIntValue=47,!0);var e=t.current();return!(99===e||t.switchN&&107===e)&&(t.lastIntValue=e,t.advance(),!0)},St.regexp_eatDecimalEscape=function(t){t.lastIntValue=0;var e=t.current();if(e>=49&&e<=57){do{t.lastIntValue=10*t.lastIntValue+(e-48),t.advance()}while((e=t.current())>=48&&e<=57);return!0}return!1},St.regexp_eatCharacterClassEscape=function(t){var e=t.current();if(_(e))return t.lastIntValue=-1,t.advance(),!0;if(t.switchU&&this.options.ecmaVersion>=9&&(80===e||112===e)){if(t.lastIntValue=-1,t.advance(),t.eat(123)&&this.regexp_eatUnicodePropertyValueExpression(t)&&t.eat(125))return!0;t.raise("Invalid property name")}return!1},St.regexp_eatUnicodePropertyValueExpression=function(t){var e=t.pos;if(this.regexp_eatUnicodePropertyName(t)&&t.eat(61)){var i=t.lastStringValue;if(this.regexp_eatUnicodePropertyValue(t)){var s=t.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(t,i,s),!0}}if(t.pos=e,this.regexp_eatLoneUnicodePropertyNameOrValue(t)){var r=t.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(t,r),!0}return!1},St.regexp_validateUnicodePropertyNameAndValue=function(t,e,i){Ct.hasOwnProperty(e)&&-1!==Ct[e].indexOf(i)||t.raise("Invalid property name")},St.regexp_validateUnicodePropertyNameOrValue=function(t,e){-1===Ct.$LONE.indexOf(e)&&t.raise("Invalid property name")},St.regexp_eatUnicodePropertyName=function(t){var e=0;for(t.lastStringValue="";b(e=t.current());)t.lastStringValue+=f(e),t.advance();return""!==t.lastStringValue},St.regexp_eatUnicodePropertyValue=function(t){var e=0;for(t.lastStringValue="";k(e=t.current());)t.lastStringValue+=f(e),t.advance();return""!==t.lastStringValue},St.regexp_eatLoneUnicodePropertyNameOrValue=function(t){return this.regexp_eatUnicodePropertyValue(t)},St.regexp_eatCharacterClass=function(t){if(t.eat(91)){if(t.eat(94),this.regexp_classRanges(t),t.eat(93))return!0;t.raise("Unterminated character class")}return!1},St.regexp_classRanges=function(t){for(var e=this;this.regexp_eatClassAtom(t);){var i=t.lastIntValue;if(t.eat(45)&&e.regexp_eatClassAtom(t)){var s=t.lastIntValue;!t.switchU||-1!==i&&-1!==s||t.raise("Invalid character class"),-1!==i&&-1!==s&&i>s&&t.raise("Range out of order in character class")}}},St.regexp_eatClassAtom=function(t){var e=t.pos;if(t.eat(92)){if(this.regexp_eatClassEscape(t))return!0;if(t.switchU){var i=t.current();(99===i||w(i))&&t.raise("Invalid class escape"),t.raise("Invalid escape")}t.pos=e}var s=t.current();return 93!==s&&(t.lastIntValue=s,t.advance(),!0)},St.regexp_eatClassEscape=function(t){var e=t.pos;if(t.eat(98))return t.lastIntValue=8,!0;if(t.switchU&&t.eat(45))return t.lastIntValue=45,!0;if(!t.switchU&&t.eat(99)){if(this.regexp_eatClassControlLetter(t))return!0;t.pos=e}return this.regexp_eatCharacterClassEscape(t)||this.regexp_eatCharacterEscape(t)},St.regexp_eatClassControlLetter=function(t){var e=t.current();return!(!C(e)&&95!==e)&&(t.lastIntValue=e%32,t.advance(),!0)},St.regexp_eatHexEscapeSequence=function(t){var e=t.pos;if(t.eat(120)){if(this.regexp_eatFixedHexDigits(t,2))return!0;t.switchU&&t.raise("Invalid escape"),t.pos=e}return!1},St.regexp_eatDecimalDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;C(i=t.current());)t.lastIntValue=10*t.lastIntValue+(i-48),t.advance();return t.pos!==e},St.regexp_eatHexDigits=function(t){var e=t.pos,i=0;for(t.lastIntValue=0;S(i=t.current());)t.lastIntValue=16*t.lastIntValue+E(i),t.advance();return t.pos!==e},St.regexp_eatLegacyOctalEscapeSequence=function(t){if(this.regexp_eatOctalDigit(t)){var e=t.lastIntValue;if(this.regexp_eatOctalDigit(t)){var i=t.lastIntValue;e<=3&&this.regexp_eatOctalDigit(t)?t.lastIntValue=64*e+8*i+t.lastIntValue:t.lastIntValue=8*e+i}else t.lastIntValue=e;return!0}return!1},St.regexp_eatOctalDigit=function(t){var e=t.current();return w(e)?(t.lastIntValue=e-48,t.advance(),!0):(t.lastIntValue=0,!1)},St.regexp_eatFixedHexDigits=function(t,e){var i=t.pos;t.lastIntValue=0;for(var s=0;s<e;++s){var r=t.current();if(!S(r))return t.pos=i,!1;t.lastIntValue=16*t.lastIntValue+E(r),t.advance()}return!0};var wt=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new it(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},At=at.prototype;At.next=function(){this.options.onToken&&this.options.onToken(new wt(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()},At.getToken=function(){return this.next(),new wt(this)},"undefined"!=typeof Symbol&&(At[Symbol.iterator]=function(){var t=this;return{next:function(){var e=t.getToken();return{done:e.type===z.eof,value:e}}}}),At.curContext=function(){return this.context[this.context.length-1]},At.nextToken=function(){var t=this.curContext();return t&&t.preserveSpace||this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length?this.finishToken(z.eof):t.override?t.override(this):void this.readToken(this.fullCharCodeAtPos())},At.readToken=function(t){return i(t,this.options.ecmaVersion>=6)||92===t?this.readWord():this.getTokenFromCode(t)},At.fullCharCodeAtPos=function(){var t=this.input.charCodeAt(this.pos);return t<=55295||t>=57344?t:(t<<10)+this.input.charCodeAt(this.pos+1)-56613888},At.skipBlockComment=function(){var t=this,e=this.options.onComment&&this.curPosition(),i=this.pos,s=this.input.indexOf("*/",this.pos+=2);if(-1===s&&this.raise(this.pos-2,"Unterminated comment"),this.pos=s+2,this.options.locations){K.lastIndex=i;for(var r;(r=K.exec(this.input))&&r.index<this.pos;)++t.curLine,t.lineStart=r.index+r[0].length}this.options.onComment&&this.options.onComment(!0,this.input.slice(i+2,s),i,this.pos,e,this.curPosition())},At.skipLineComment=function(t){for(var e=this,i=this.pos,s=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=t);this.pos<this.input.length&&!n(r);)r=e.input.charCodeAt(++e.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(i+t,this.pos),i,this.pos,s,this.curPosition())},At.skipSpace=function(){var t=this;t:for(;this.pos<this.input.length;){var e=t.input.charCodeAt(t.pos);switch(e){case 32:case 160:++t.pos;break;case 13:10===t.input.charCodeAt(t.pos+1)&&++t.pos;case 10:case 8232:case 8233:++t.pos,t.options.locations&&(++t.curLine,t.lineStart=t.pos);break;case 47:switch(t.input.charCodeAt(t.pos+1)){case 42:t.skipBlockComment();break;case 47:t.skipLineComment(2);break;default:break t}break;default:if(!(e>8&&e<14||e>=5760&&X.test(String.fromCharCode(e))))break t;++t.pos}}},At.finishToken=function(t,e){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var i=this.type;this.type=t,this.value=e,this.updateContext(i)},At.readToken_dot=function(){var t=this.input.charCodeAt(this.pos+1);if(t>=48&&t<=57)return this.readNumber(!0);var e=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&46===t&&46===e?(this.pos+=3,this.finishToken(z.ellipsis)):(++this.pos,this.finishToken(z.dot))},At.readToken_slash=function(){var t=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):61===t?this.finishOp(z.assign,2):this.finishOp(z.slash,1)},At.readToken_mult_modulo_exp=function(t){var e=this.input.charCodeAt(this.pos+1),i=1,s=42===t?z.star:z.modulo;return this.options.ecmaVersion>=7&&42===t&&42===e&&(++i,s=z.starstar,e=this.input.charCodeAt(this.pos+2)),61===e?this.finishOp(z.assign,i+1):this.finishOp(s,i)},At.readToken_pipe_amp=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?this.finishOp(124===t?z.logicalOR:z.logicalAND,2):61===e?this.finishOp(z.assign,2):this.finishOp(124===t?z.bitwiseOR:z.bitwiseAND,1)},At.readToken_caret=function(){return 61===this.input.charCodeAt(this.pos+1)?this.finishOp(z.assign,2):this.finishOp(z.bitwiseXOR,1)},At.readToken_plus_min=function(t){var e=this.input.charCodeAt(this.pos+1);return e===t?45!==e||this.inModule||62!==this.input.charCodeAt(this.pos+2)||0!==this.lastTokEnd&&!Q.test(this.input.slice(this.lastTokEnd,this.pos))?this.finishOp(z.incDec,2):(this.skipLineComment(3),this.skipSpace(),this.nextToken()):61===e?this.finishOp(z.assign,2):this.finishOp(z.plusMin,1)},At.readToken_lt_gt=function(t){var e=this.input.charCodeAt(this.pos+1),i=1;return e===t?(i=62===t&&62===this.input.charCodeAt(this.pos+2)?3:2,61===this.input.charCodeAt(this.pos+i)?this.finishOp(z.assign,i+1):this.finishOp(z.bitShift,i)):33!==e||60!==t||this.inModule||45!==this.input.charCodeAt(this.pos+2)||45!==this.input.charCodeAt(this.pos+3)?(61===e&&(i=2),this.finishOp(z.relational,i)):(this.skipLineComment(4),this.skipSpace(),this.nextToken())},At.readToken_eq_excl=function(t){var e=this.input.charCodeAt(this.pos+1);return 61===e?this.finishOp(z.equality,61===this.input.charCodeAt(this.pos+2)?3:2):61===t&&62===e&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(z.arrow)):this.finishOp(61===t?z.eq:z.prefix,1)},At.getTokenFromCode=function(t){switch(t){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(z.parenL);case 41:return++this.pos,this.finishToken(z.parenR);case 59:return++this.pos,this.finishToken(z.semi);case 44:return++this.pos,this.finishToken(z.comma);case 91:return++this.pos,this.finishToken(z.bracketL);case 93:return++this.pos,this.finishToken(z.bracketR);case 123:return++this.pos,this.finishToken(z.braceL);case 125:return++this.pos,this.finishToken(z.braceR);case 58:return++this.pos,this.finishToken(z.colon);case 63:return++this.pos,this.finishToken(z.question);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(z.backQuote);case 48:var e=this.input.charCodeAt(this.pos+1);if(120===e||88===e)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(111===e||79===e)return this.readRadixNumber(8);if(98===e||66===e)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(t);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(t);case 124:case 38:return this.readToken_pipe_amp(t);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(t);case 60:case 62:return this.readToken_lt_gt(t);case 61:case 33:return this.readToken_eq_excl(t);case 126:return this.finishOp(z.prefix,1)}this.raise(this.pos,"Unexpected character '"+A(t)+"'")},At.finishOp=function(t,e){var i=this.input.slice(this.pos,this.pos+e);return this.pos+=e,this.finishToken(t,i)},At.readRegexp=function(){for(var t,e,i=this,s=this.pos;;){i.pos>=i.input.length&&i.raise(s,"Unterminated regular expression");var r=i.input.charAt(i.pos);if(Q.test(r)&&i.raise(s,"Unterminated regular expression"),t)t=!1;else{if("["===r)e=!0;else if("]"===r&&e)e=!1;else if("/"===r&&!e)break;t="\\"===r}++i.pos}var a=this.input.slice(s,this.pos);++this.pos;var n=this.pos,o=this.readWord1();this.containsEsc&&this.unexpected(n);var h=this.regexpState||(this.regexpState=new Et(this));h.reset(s,a,o),this.validateRegExpFlags(h),this.validateRegExpPattern(h);var p=null;try{p=new RegExp(a,o)}catch(t){}return this.finishToken(z.regexp,{pattern:a,flags:o,value:p})},At.readInt=function(t,e){for(var i=this,s=this.pos,r=0,a=0,n=null==e?1/0:e;a<n;++a){var o=i.input.charCodeAt(i.pos),h=void 0;if((h=o>=97?o-97+10:o>=65?o-65+10:o>=48&&o<=57?o-48:1/0)>=t)break;++i.pos,r=r*t+h}return this.pos===s||null!=e&&this.pos-s!==e?null:r},At.readRadixNumber=function(t){this.pos+=2;var e=this.readInt(t);return null==e&&this.raise(this.start+2,"Expected number in radix "+t),i(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(z.num,e)},At.readNumber=function(t){var e=this.pos;t||null!==this.readInt(10)||this.raise(e,"Invalid number");var s=this.pos-e>=2&&48===this.input.charCodeAt(e);s&&this.strict&&this.raise(e,"Invalid number"),s&&/[89]/.test(this.input.slice(e,this.pos))&&(s=!1);var r=this.input.charCodeAt(this.pos);46!==r||s||(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),69!==r&&101!==r||s||(r=this.input.charCodeAt(++this.pos),43!==r&&45!==r||++this.pos,null===this.readInt(10)&&this.raise(e,"Invalid number")),i(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var a=this.input.slice(e,this.pos),n=s?parseInt(a,8):parseFloat(a);return this.finishToken(z.num,n)},At.readCodePoint=function(){var t,e=this.input.charCodeAt(this.pos);if(123===e){this.options.ecmaVersion<6&&this.unexpected();var i=++this.pos;t=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,t>1114111&&this.invalidStringToken(i,"Code point out of bounds")}else t=this.readHexChar(4);return t},At.readString=function(t){for(var e=this,i="",s=++this.pos;;){e.pos>=e.input.length&&e.raise(e.start,"Unterminated string constant");var r=e.input.charCodeAt(e.pos);if(r===t)break;92===r?(i+=e.input.slice(s,e.pos),i+=e.readEscapedChar(!1),s=e.pos):(n(r,e.options.ecmaVersion>=10)&&e.raise(e.start,"Unterminated string constant"),++e.pos)}return i+=this.input.slice(s,this.pos++),this.finishToken(z.string,i)};var It={};At.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(t){if(t!==It)throw t;this.readInvalidTemplateToken()}this.inTemplateElement=!1},At.invalidStringToken=function(t,e){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw It;this.raise(t,e)},At.readTmplToken=function(){for(var t=this,e="",i=this.pos;;){t.pos>=t.input.length&&t.raise(t.start,"Unterminated template");var s=t.input.charCodeAt(t.pos);if(96===s||36===s&&123===t.input.charCodeAt(t.pos+1))return t.pos!==t.start||t.type!==z.template&&t.type!==z.invalidTemplate?(e+=t.input.slice(i,t.pos),t.finishToken(z.template,e)):36===s?(t.pos+=2,t.finishToken(z.dollarBraceL)):(++t.pos,t.finishToken(z.backQuote));if(92===s)e+=t.input.slice(i,t.pos),e+=t.readEscapedChar(!0),i=t.pos;else if(n(s)){switch(e+=t.input.slice(i,t.pos),++t.pos,s){case 13:10===t.input.charCodeAt(t.pos)&&++t.pos;case 10:e+="\n";break;default:e+=String.fromCharCode(s)}t.options.locations&&(++t.curLine,t.lineStart=t.pos),i=t.pos}else++t.pos}},At.readInvalidTemplateToken=function(){for(var t=this;this.pos<this.input.length;this.pos++)switch(t.input[t.pos]){case"\\":++t.pos;break;case"$":if("{"!==t.input[t.pos+1])break;case"`":return t.finishToken(z.invalidTemplate,t.input.slice(t.start,t.pos))}this.raise(this.start,"Unterminated template")},At.readEscapedChar=function(t){var e=this.input.charCodeAt(++this.pos);switch(++this.pos,e){case 110:return"\n";case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return A(this.readCodePoint());case 116:return"\t";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:10===this.input.charCodeAt(this.pos)&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";default:if(e>=48&&e<=55){var i=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],s=parseInt(i,8);return s>255&&(i=i.slice(0,-1),s=parseInt(i,8)),this.pos+=i.length-1,e=this.input.charCodeAt(this.pos),"0"===i&&56!==e&&57!==e||!this.strict&&!t||this.invalidStringToken(this.pos-1-i.length,t?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(s)}return String.fromCharCode(e)}},At.readHexChar=function(t){var e=this.pos,i=this.readInt(16,t);return null===i&&this.invalidStringToken(e,"Bad character escape sequence"),i},At.readWord1=function(){var t=this;this.containsEsc=!1;for(var e="",r=!0,a=this.pos,n=this.options.ecmaVersion>=6;this.pos<this.input.length;){var o=t.fullCharCodeAtPos();if(s(o,n))t.pos+=o<=65535?1:2;else{if(92!==o)break;t.containsEsc=!0,e+=t.input.slice(a,t.pos);var h=t.pos;117!==t.input.charCodeAt(++t.pos)&&t.invalidStringToken(t.pos,"Expecting Unicode escape sequence \\uXXXX"),++t.pos;var p=t.readCodePoint();(r?i:s)(p,n)||t.invalidStringToken(h,"Invalid Unicode escape"),e+=A(p),a=t.pos}r=!1}return e+this.input.slice(a,this.pos)},At.readWord=function(){var t=this.readWord1(),e=z.name;return this.keywords.test(t)&&(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword "+t),e=j[t]),this.finishToken(e,t)};t.version="5.7.2",t.parse=I,t.parseExpressionAt=P,t.tokenizer=L,t.addLooseExports=N,t.Parser=at,t.plugins=rt,t.defaultOptions=st,t.Position=et,t.SourceLocation=it,t.getLineInfo=h,t.Node=vt,t.TokenType=q,t.tokTypes=z,t.keywordTypes=j,t.TokContext=_t,t.tokContexts=bt,t.isIdentifierChar=s,t.isIdentifierStart=i,t.Token=wt,t.isNewLine=n,t.lineBreak=Q,t.lineBreakG=K,t.nonASCIIwhitespace=X,Object.defineProperty(t,"__esModule",{value:!0})});
},{}],91:[function(require,module,exports){
exports.read=function(a,o,t,r,h){var M,p,w=8*h-r-1,f=(1<<w)-1,e=f>>1,i=-7,N=t?h-1:0,n=t?-1:1,s=a[o+N];for(N+=n,M=s&(1<<-i)-1,s>>=-i,i+=w;i>0;M=256*M+a[o+N],N+=n,i-=8);for(p=M&(1<<-i)-1,M>>=-i,i+=r;i>0;p=256*p+a[o+N],N+=n,i-=8);if(0===M)M=1-e;else{if(M===f)return p?NaN:1/0*(s?-1:1);p+=Math.pow(2,r),M-=e}return(s?-1:1)*p*Math.pow(2,M-r)},exports.write=function(a,o,t,r,h,M){var p,w,f,e=8*M-h-1,i=(1<<e)-1,N=i>>1,n=23===h?Math.pow(2,-24)-Math.pow(2,-77):0,s=r?0:M-1,u=r?1:-1,l=o<0||0===o&&1/o<0?1:0;for(o=Math.abs(o),isNaN(o)||o===1/0?(w=isNaN(o)?1:0,p=i):(p=Math.floor(Math.log(o)/Math.LN2),o*(f=Math.pow(2,-p))<1&&(p--,f*=2),o+=p+N>=1?n/f:n*Math.pow(2,1-N),o*f>=2&&(p++,f/=2),p+N>=i?(w=0,p=i):p+N>=1?(w=(o*f-1)*Math.pow(2,h),p+=N):(w=o*Math.pow(2,N-1)*Math.pow(2,h),p=0));h>=8;a[t+s]=255&w,s+=u,w/=256,h-=8);for(p=p<<h|w,e+=h;e>0;a[t+s]=255&p,s+=u,p/=256,e-=8);a[t+s-u]|=128*l};
},{}],92:[function(require,module,exports){
"function"==typeof Object.create?module.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:module.exports=function(t,e){t.super_=e;var o=function(){};o.prototype=e.prototype,t.prototype=new o,t.prototype.constructor=t};
},{}],93:[function(require,module,exports){
function isBuffer(f){return!!f.constructor&&"function"==typeof f.constructor.isBuffer&&f.constructor.isBuffer(f)}function isSlowBuffer(f){return"function"==typeof f.readFloatLE&&"function"==typeof f.slice&&isBuffer(f.slice(0,0))}module.exports=function(f){return null!=f&&(isBuffer(f)||isSlowBuffer(f)||!!f._isBuffer)};
},{}],94:[function(require,module,exports){
var toString={}.toString;module.exports=Array.isArray||function(r){return"[object Array]"==toString.call(r)};
},{}],95:[function(require,module,exports){
(function (process){
"use strict";function nextTick(e,n,c,r){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var s,t,o=arguments.length;switch(o){case 0:case 1:return process.nextTick(e);case 2:return process.nextTick(function(){e.call(null,n)});case 3:return process.nextTick(function(){e.call(null,n,c)});case 4:return process.nextTick(function(){e.call(null,n,c,r)});default:for(s=new Array(o-1),t=0;t<s.length;)s[t++]=arguments[t];return process.nextTick(function(){e.apply(null,s)})}}!process.version||0===process.version.indexOf("v0.")||0===process.version.indexOf("v1.")&&0!==process.version.indexOf("v1.8.")?module.exports={nextTick:nextTick}:module.exports=process;
}).call(this,require('_process'))
},{"_process":96}],96:[function(require,module,exports){
function defaultSetTimout(){throw new Error("setTimeout has not been defined")}function defaultClearTimeout(){throw new Error("clearTimeout has not been defined")}function runTimeout(e){if(cachedSetTimeout===setTimeout)return setTimeout(e,0);if((cachedSetTimeout===defaultSetTimout||!cachedSetTimeout)&&setTimeout)return cachedSetTimeout=setTimeout,setTimeout(e,0);try{return cachedSetTimeout(e,0)}catch(t){try{return cachedSetTimeout.call(null,e,0)}catch(t){return cachedSetTimeout.call(this,e,0)}}}function runClearTimeout(e){if(cachedClearTimeout===clearTimeout)return clearTimeout(e);if((cachedClearTimeout===defaultClearTimeout||!cachedClearTimeout)&&clearTimeout)return cachedClearTimeout=clearTimeout,clearTimeout(e);try{return cachedClearTimeout(e)}catch(t){try{return cachedClearTimeout.call(null,e)}catch(t){return cachedClearTimeout.call(this,e)}}}function cleanUpNextTick(){draining&¤tQueue&&(draining=!1,currentQueue.length?queue=currentQueue.concat(queue):queueIndex=-1,queue.length&&drainQueue())}function drainQueue(){if(!draining){var e=runTimeout(cleanUpNextTick);draining=!0;for(var t=queue.length;t;){for(currentQueue=queue,queue=[];++queueIndex<t;)currentQueue&¤tQueue[queueIndex].run();queueIndex=-1,t=queue.length}currentQueue=null,draining=!1,runClearTimeout(e)}}function Item(e,t){this.fun=e,this.array=t}function noop(){}var process=module.exports={},cachedSetTimeout,cachedClearTimeout;!function(){try{cachedSetTimeout="function"==typeof setTimeout?setTimeout:defaultSetTimout}catch(e){cachedSetTimeout=defaultSetTimout}try{cachedClearTimeout="function"==typeof clearTimeout?clearTimeout:defaultClearTimeout}catch(e){cachedClearTimeout=defaultClearTimeout}}();var queue=[],draining=!1,currentQueue,queueIndex=-1;process.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];queue.push(new Item(e,t)),1!==queue.length||draining||runTimeout(drainQueue)},Item.prototype.run=function(){this.fun.apply(null,this.array)},process.title="browser",process.browser=!0,process.env={},process.argv=[],process.version="",process.versions={},process.on=noop,process.addListener=noop,process.once=noop,process.off=noop,process.removeListener=noop,process.removeAllListeners=noop,process.emit=noop,process.prependListener=noop,process.prependOnceListener=noop,process.listeners=function(e){return[]},process.binding=function(e){throw new Error("process.binding is not supported")},process.cwd=function(){return"/"},process.chdir=function(e){throw new Error("process.chdir is not supported")},process.umask=function(){return 0};
},{}],97:[function(require,module,exports){
module.exports=require("./lib/_stream_duplex.js");
},{"./lib/_stream_duplex.js":98}],98:[function(require,module,exports){
"use strict";function Duplex(e){if(!(this instanceof Duplex))return new Duplex(e);Readable.call(this,e),Writable.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",onend)}function onend(){this.allowHalfOpen||this._writableState.ended||pna.nextTick(onEndNT,this)}function onEndNT(e){e.end()}var pna=require("process-nextick-args"),objectKeys=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};module.exports=Duplex;var util=require("core-util-is");util.inherits=require("inherits");var Readable=require("./_stream_readable"),Writable=require("./_stream_writable");util.inherits(Duplex,Readable);for(var keys=objectKeys(Writable.prototype),v=0;v<keys.length;v++){var method=keys[v];Duplex.prototype[method]||(Duplex.prototype[method]=Writable.prototype[method])}Object.defineProperty(Duplex.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(Duplex.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}}),Duplex.prototype._destroy=function(e,t){this.push(null),this.end(),pna.nextTick(t,e)};
},{"./_stream_readable":100,"./_stream_writable":102,"core-util-is":55,"inherits":92,"process-nextick-args":95}],99:[function(require,module,exports){
"use strict";function PassThrough(r){if(!(this instanceof PassThrough))return new PassThrough(r);Transform.call(this,r)}module.exports=PassThrough;var Transform=require("./_stream_transform"),util=require("core-util-is");util.inherits=require("inherits"),util.inherits(PassThrough,Transform),PassThrough.prototype._transform=function(r,s,i){i(null,r)};
},{"./_stream_transform":101,"core-util-is":55,"inherits":92}],100:[function(require,module,exports){
(function (process,global){
"use strict";function _uint8ArrayToBuffer(e){return Buffer.from(e)}function _isUint8Array(e){return Buffer.isBuffer(e)||e instanceof OurUint8Array}function prependListener(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}function ReadableState(e,t){Duplex=Duplex||require("./_stream_duplex"),e=e||{};var r=t instanceof Duplex;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var n=e.highWaterMark,a=e.readableHighWaterMark,i=this.objectMode?16:16384;this.highWaterMark=n||0===n?n:r&&(a||0===a)?a:i,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new BufferList,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(StringDecoder||(StringDecoder=require("string_decoder/").StringDecoder),this.decoder=new StringDecoder(e.encoding),this.encoding=e.encoding)}function Readable(e){if(Duplex=Duplex||require("./_stream_duplex"),!(this instanceof Readable))return new Readable(e);this._readableState=new ReadableState(e,this),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),Stream.call(this)}function readableAddChunk(e,t,r,n,a){var i=e._readableState;if(null===t)i.reading=!1,onEofChunk(e,i);else{var d;a||(d=chunkInvalid(i,t)),d?e.emit("error",d):i.objectMode||t&&t.length>0?("string"==typeof t||i.objectMode||Object.getPrototypeOf(t)===Buffer.prototype||(t=_uint8ArrayToBuffer(t)),n?i.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):addChunk(e,i,t,!0):i.ended?e.emit("error",new Error("stream.push() after EOF")):(i.reading=!1,i.decoder&&!r?(t=i.decoder.write(t),i.objectMode||0!==t.length?addChunk(e,i,t,!1):maybeReadMore(e,i)):addChunk(e,i,t,!1))):n||(i.reading=!1)}return needMoreData(i)}function addChunk(e,t,r,n){t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,n?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&emitReadable(e)),maybeReadMore(e,t)}function chunkInvalid(e,t){var r;return _isUint8Array(t)||"string"==typeof t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function needMoreData(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||0===e.length)}function computeNewHighWaterMark(e){return e>=MAX_HWM?e=MAX_HWM:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function howMuchToRead(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=computeNewHighWaterMark(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function onEofChunk(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,emitReadable(e)}}function emitReadable(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(debug("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?pna.nextTick(emitReadable_,e):emitReadable_(e))}function emitReadable_(e){debug("emit readable"),e.emit("readable"),flow(e)}function maybeReadMore(e,t){t.readingMore||(t.readingMore=!0,pna.nextTick(maybeReadMore_,e,t))}function maybeReadMore_(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(debug("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}function pipeOnDrain(e){return function(){var t=e._readableState;debug("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&EElistenerCount(e,"data")&&(t.flowing=!0,flow(e))}}function nReadingNextTick(e){debug("readable nexttick read 0"),e.read(0)}function resume(e,t){t.resumeScheduled||(t.resumeScheduled=!0,pna.nextTick(resume_,e,t))}function resume_(e,t){t.reading||(debug("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),flow(e),t.flowing&&!t.reading&&e.read(0)}function flow(e){var t=e._readableState;for(debug("flow",t.flowing);t.flowing&&null!==e.read(););}function fromList(e,t){if(0===t.length)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=fromListPartial(e,t.buffer,t.decoder),r}function fromListPartial(e,t,r){var n;return e<t.head.data.length?(n=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):n=e===t.head.data.length?t.shift():r?copyFromBufferString(e,t):copyFromBuffer(e,t),n}function copyFromBufferString(e,t){var r=t.head,n=1,a=r.data;for(e-=a.length;r=r.next;){var i=r.data,d=e>i.length?i.length:e;if(d===i.length?a+=i:a+=i.slice(0,e),0===(e-=d)){d===i.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=i.slice(d));break}++n}return t.length-=n,a}function copyFromBuffer(e,t){var r=Buffer.allocUnsafe(e),n=t.head,a=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var i=n.data,d=e>i.length?i.length:e;if(i.copy(r,r.length-e,0,d),0===(e-=d)){d===i.length?(++a,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=i.slice(d));break}++a}return t.length-=a,r}function endReadable(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,pna.nextTick(endReadableNT,t,e))}function endReadableNT(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function indexOf(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}var pna=require("process-nextick-args");module.exports=Readable;var isArray=require("isarray"),Duplex;Readable.ReadableState=ReadableState;var EE=require("events").EventEmitter,EElistenerCount=function(e,t){return e.listeners(t).length},Stream=require("./internal/streams/stream"),Buffer=require("safe-buffer").Buffer,OurUint8Array=global.Uint8Array||function(){},util=require("core-util-is");util.inherits=require("inherits");var debugUtil=require("util"),debug=void 0;debug=debugUtil&&debugUtil.debuglog?debugUtil.debuglog("stream"):function(){};var BufferList=require("./internal/streams/BufferList"),destroyImpl=require("./internal/streams/destroy"),StringDecoder;util.inherits(Readable,Stream);var kProxyEvents=["error","close","destroy","pause","resume"];Object.defineProperty(Readable.prototype,"destroyed",{get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),Readable.prototype.destroy=destroyImpl.destroy,Readable.prototype._undestroy=destroyImpl.undestroy,Readable.prototype._destroy=function(e,t){this.push(null),t(e)},Readable.prototype.push=function(e,t){var r,n=this._readableState;return n.objectMode?r=!0:"string"==typeof e&&(t=t||n.defaultEncoding,t!==n.encoding&&(e=Buffer.from(e,t),t=""),r=!0),readableAddChunk(this,e,t,!1,r)},Readable.prototype.unshift=function(e){return readableAddChunk(this,e,null,!0,!1)},Readable.prototype.isPaused=function(){return!1===this._readableState.flowing},Readable.prototype.setEncoding=function(e){return StringDecoder||(StringDecoder=require("string_decoder/").StringDecoder),this._readableState.decoder=new StringDecoder(e),this._readableState.encoding=e,this};var MAX_HWM=8388608;Readable.prototype.read=function(e){debug("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return debug("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?endReadable(this):emitReadable(this),null;if(0===(e=howMuchToRead(e,t))&&t.ended)return 0===t.length&&endReadable(this),null;var n=t.needReadable;debug("need readable",n),(0===t.length||t.length-e<t.highWaterMark)&&(n=!0,debug("length less than watermark",n)),t.ended||t.reading?(n=!1,debug("reading or ended",n)):n&&(debug("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=howMuchToRead(r,t)));var a;return a=e>0?fromList(e,t):null,null===a?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&endReadable(this)),null!==a&&this.emit("data",a),a},Readable.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},Readable.prototype.pipe=function(e,t){function r(e,t){debug("onunpipe"),e===s&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,a())}function n(){debug("onend"),e.end()}function a(){debug("cleanup"),e.removeListener("close",o),e.removeListener("finish",u),e.removeListener("drain",b),e.removeListener("error",d),e.removeListener("unpipe",r),s.removeListener("end",n),s.removeListener("end",l),s.removeListener("data",i),c=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||b()}function i(t){debug("ondata"),g=!1,!1!==e.write(t)||g||((1===h.pipesCount&&h.pipes===e||h.pipesCount>1&&-1!==indexOf(h.pipes,e))&&!c&&(debug("false write response, pause",s._readableState.awaitDrain),s._readableState.awaitDrain++,g=!0),s.pause())}function d(t){debug("onerror",t),l(),e.removeListener("error",d),0===EElistenerCount(e,"error")&&e.emit("error",t)}function o(){e.removeListener("finish",u),l()}function u(){debug("onfinish"),e.removeListener("close",o),l()}function l(){debug("unpipe"),s.unpipe(e)}var s=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,debug("pipe count=%d opts=%j",h.pipesCount,t);var f=(!t||!1!==t.end)&&e!==process.stdout&&e!==process.stderr,p=f?n:l;h.endEmitted?pna.nextTick(p):s.once("end",p),e.on("unpipe",r);var b=pipeOnDrain(s);e.on("drain",b);var c=!1,g=!1;return s.on("data",i),prependListener(e,"error",d),e.once("close",o),e.once("finish",u),e.emit("pipe",s),h.flowing||(debug("pipe resume"),s.resume()),e},Readable.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var n=t.pipes,a=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i<a;i++)n[i].emit("unpipe",this,r);return this}var d=indexOf(t.pipes,e);return-1===d?this:(t.pipes.splice(d,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,r),this)},Readable.prototype.on=function(e,t){var r=Stream.prototype.on.call(this,e,t);if("data"===e)!1!==this._readableState.flowing&&this.resume();else if("readable"===e){var n=this._readableState;n.endEmitted||n.readableListening||(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&emitReadable(this):pna.nextTick(nReadingNextTick,this))}return r},Readable.prototype.addListener=Readable.prototype.on,Readable.prototype.resume=function(){var e=this._readableState;return e.flowing||(debug("resume"),e.flowing=!0,resume(this,e)),this},Readable.prototype.pause=function(){return debug("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(debug("pause"),this._readableState.flowing=!1,this.emit("pause")),this},Readable.prototype.wrap=function(e){var t=this,r=this._readableState,n=!1;e.on("end",function(){if(debug("wrapped end"),r.decoder&&!r.ended){var e=r.decoder.end();e&&e.length&&t.push(e)}t.push(null)}),e.on("data",function(a){if(debug("wrapped data"),r.decoder&&(a=r.decoder.write(a)),(!r.objectMode||null!==a&&void 0!==a)&&(r.objectMode||a&&a.length)){t.push(a)||(n=!0,e.pause())}});for(var a in e)void 0===this[a]&&"function"==typeof e[a]&&(this[a]=function(t){return function(){return e[t].apply(e,arguments)}}(a));for(var i=0;i<kProxyEvents.length;i++)e.on(kProxyEvents[i],this.emit.bind(this,kProxyEvents[i]));return this._read=function(t){debug("wrapped _read",t),n&&(n=!1,e.resume())},this},Object.defineProperty(Readable.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Readable._fromList=fromList;
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./_stream_duplex":98,"./internal/streams/BufferList":103,"./internal/streams/destroy":104,"./internal/streams/stream":105,"_process":96,"core-util-is":55,"events":56,"inherits":92,"isarray":94,"process-nextick-args":95,"safe-buffer":111,"string_decoder/":106,"util":53}],101:[function(require,module,exports){
"use strict";function afterTransform(r,t){var n=this._transformState;n.transforming=!1;var e=n.writecb;if(!e)return this.emit("error",new Error("write callback called multiple times"));n.writechunk=null,n.writecb=null,null!=t&&this.push(t),e(r);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function Transform(r){if(!(this instanceof Transform))return new Transform(r);Duplex.call(this,r),this._transformState={afterTransform:afterTransform.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,r&&("function"==typeof r.transform&&(this._transform=r.transform),"function"==typeof r.flush&&(this._flush=r.flush)),this.on("prefinish",prefinish)}function prefinish(){var r=this;"function"==typeof this._flush?this._flush(function(t,n){done(r,t,n)}):done(this,null,null)}function done(r,t,n){if(t)return r.emit("error",t);if(null!=n&&r.push(n),r._writableState.length)throw new Error("Calling transform done when ws.length != 0");if(r._transformState.transforming)throw new Error("Calling transform done when still transforming");return r.push(null)}module.exports=Transform;var Duplex=require("./_stream_duplex"),util=require("core-util-is");util.inherits=require("inherits"),util.inherits(Transform,Duplex),Transform.prototype.push=function(r,t){return this._transformState.needTransform=!1,Duplex.prototype.push.call(this,r,t)},Transform.prototype._transform=function(r,t,n){throw new Error("_transform() is not implemented")},Transform.prototype._write=function(r,t,n){var e=this._transformState;if(e.writecb=n,e.writechunk=r,e.writeencoding=t,!e.transforming){var i=this._readableState;(e.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},Transform.prototype._read=function(r){var t=this._transformState;null!==t.writechunk&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0},Transform.prototype._destroy=function(r,t){var n=this;Duplex.prototype._destroy.call(this,r,function(r){t(r),n.emit("close")})};
},{"./_stream_duplex":98,"core-util-is":55,"inherits":92}],102:[function(require,module,exports){
(function (process,global,setImmediate){
"use strict";function WriteReq(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function CorkedRequest(e){var t=this;this.next=null,this.entry=null,this.finish=function(){onCorkedFinish(t,e)}}function _uint8ArrayToBuffer(e){return Buffer.from(e)}function _isUint8Array(e){return Buffer.isBuffer(e)||e instanceof OurUint8Array}function nop(){}function WritableState(e,t){Duplex=Duplex||require("./_stream_duplex"),e=e||{};var r=t instanceof Duplex;this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var i=e.highWaterMark,n=e.writableHighWaterMark,o=this.objectMode?16:16384;this.highWaterMark=i||0===i?i:r&&(n||0===n)?n:o,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===e.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){onwrite(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new CorkedRequest(this)}function Writable(e){if(Duplex=Duplex||require("./_stream_duplex"),!(realHasInstance.call(Writable,this)||this instanceof Duplex))return new Writable(e);this._writableState=new WritableState(e,this),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),Stream.call(this)}function writeAfterEnd(e,t){var r=new Error("write after end");e.emit("error",r),pna.nextTick(t,r)}function validChunk(e,t,r,i){var n=!0,o=!1;return null===r?o=new TypeError("May not write null values to stream"):"string"==typeof r||void 0===r||t.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(e.emit("error",o),pna.nextTick(i,o),n=!1),n}function decodeChunk(e,t,r){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=Buffer.from(t,r)),t}function writeOrBuffer(e,t,r,i,n,o){if(!r){var a=decodeChunk(t,i,n);i!==a&&(r=!0,n="buffer",i=a)}var s=t.objectMode?1:i.length;t.length+=s;var f=t.length<t.highWaterMark;if(f||(t.needDrain=!0),t.writing||t.corked){var u=t.lastBufferedRequest;t.lastBufferedRequest={chunk:i,encoding:n,isBuf:r,callback:o,next:null},u?u.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else doWrite(e,t,!1,s,i,n,o);return f}function doWrite(e,t,r,i,n,o,a){t.writelen=i,t.writecb=a,t.writing=!0,t.sync=!0,r?e._writev(n,t.onwrite):e._write(n,o,t.onwrite),t.sync=!1}function onwriteError(e,t,r,i,n){--t.pendingcb,r?(pna.nextTick(n,i),pna.nextTick(finishMaybe,e,t),e._writableState.errorEmitted=!0,e.emit("error",i)):(n(i),e._writableState.errorEmitted=!0,e.emit("error",i),finishMaybe(e,t))}function onwriteStateUpdate(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function onwrite(e,t){var r=e._writableState,i=r.sync,n=r.writecb;if(onwriteStateUpdate(r),t)onwriteError(e,r,i,t,n);else{var o=needFinish(r);o||r.corked||r.bufferProcessing||!r.bufferedRequest||clearBuffer(e,r),i?asyncWrite(afterWrite,e,r,o,n):afterWrite(e,r,o,n)}}function afterWrite(e,t,r,i){r||onwriteDrain(e,t),t.pendingcb--,i(),finishMaybe(e,t)}function onwriteDrain(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function clearBuffer(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var i=t.bufferedRequestCount,n=new Array(i),o=t.corkedRequestsFree;o.entry=r;for(var a=0,s=!0;r;)n[a]=r,r.isBuf||(s=!1),r=r.next,a+=1;n.allBuffers=s,doWrite(e,t,!0,t.length,n,"",o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new CorkedRequest(t),t.bufferedRequestCount=0}else{for(;r;){var f=r.chunk,u=r.encoding,l=r.callback;if(doWrite(e,t,!1,t.objectMode?1:f.length,f,u,l),r=r.next,t.bufferedRequestCount--,t.writing)break}null===r&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}function needFinish(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function callFinal(e,t){e._final(function(r){t.pendingcb--,r&&e.emit("error",r),t.prefinished=!0,e.emit("prefinish"),finishMaybe(e,t)})}function prefinish(e,t){t.prefinished||t.finalCalled||("function"==typeof e._final?(t.pendingcb++,t.finalCalled=!0,pna.nextTick(callFinal,e,t)):(t.prefinished=!0,e.emit("prefinish")))}function finishMaybe(e,t){var r=needFinish(t);return r&&(prefinish(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"))),r}function endWritable(e,t,r){t.ending=!0,finishMaybe(e,t),r&&(t.finished?pna.nextTick(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function onCorkedFinish(e,t,r){var i=e.entry;for(e.entry=null;i;){var n=i.callback;t.pendingcb--,n(r),i=i.next}t.corkedRequestsFree?t.corkedRequestsFree.next=e:t.corkedRequestsFree=e}var pna=require("process-nextick-args");module.exports=Writable;var asyncWrite=!process.browser&&["v0.10","v0.9."].indexOf(process.version.slice(0,5))>-1?setImmediate:pna.nextTick,Duplex;Writable.WritableState=WritableState;var util=require("core-util-is");util.inherits=require("inherits");var internalUtil={deprecate:require("util-deprecate")},Stream=require("./internal/streams/stream"),Buffer=require("safe-buffer").Buffer,OurUint8Array=global.Uint8Array||function(){},destroyImpl=require("./internal/streams/destroy");util.inherits(Writable,Stream),WritableState.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(WritableState.prototype,"buffer",{get:internalUtil.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var realHasInstance;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(realHasInstance=Function.prototype[Symbol.hasInstance],Object.defineProperty(Writable,Symbol.hasInstance,{value:function(e){return!!realHasInstance.call(this,e)||this===Writable&&(e&&e._writableState instanceof WritableState)}})):realHasInstance=function(e){return e instanceof this},Writable.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},Writable.prototype.write=function(e,t,r){var i=this._writableState,n=!1,o=!i.objectMode&&_isUint8Array(e);return o&&!Buffer.isBuffer(e)&&(e=_uint8ArrayToBuffer(e)),"function"==typeof t&&(r=t,t=null),o?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof r&&(r=nop),i.ended?writeAfterEnd(this,r):(o||validChunk(this,i,e,r))&&(i.pendingcb++,n=writeOrBuffer(this,i,o,e,t,r)),n},Writable.prototype.cork=function(){this._writableState.corked++},Writable.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||clearBuffer(this,e))},Writable.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(Writable.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Writable.prototype._write=function(e,t,r){r(new Error("_write() is not implemented"))},Writable.prototype._writev=null,Writable.prototype.end=function(e,t,r){var i=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||i.finished||endWritable(this,i,r)},Object.defineProperty(Writable.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),Writable.prototype.destroy=destroyImpl.destroy,Writable.prototype._undestroy=destroyImpl.undestroy,Writable.prototype._destroy=function(e,t){this.end(),t(e)};
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
},{"./_stream_duplex":98,"./internal/streams/destroy":104,"./internal/streams/stream":105,"_process":96,"core-util-is":55,"inherits":92,"process-nextick-args":95,"safe-buffer":111,"timers":116,"util-deprecate":117}],103:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function copyBuffer(t,e,i){t.copy(e,i)}var Buffer=require("safe-buffer").Buffer,util=require("util");module.exports=function(){function t(){_classCallCheck(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,i=""+e.data;e=e.next;)i+=t+e.data;return i},t.prototype.concat=function(t){if(0===this.length)return Buffer.alloc(0);if(1===this.length)return this.head.data;for(var e=Buffer.allocUnsafe(t>>>0),i=this.head,n=0;i;)copyBuffer(i.data,e,n),n+=i.data.length,i=i.next;return e},t}(),util&&util.inspect&&util.inspect.custom&&(module.exports.prototype[util.inspect.custom]=function(){var t=util.inspect({length:this.length});return this.constructor.name+" "+t});
},{"safe-buffer":111,"util":53}],104:[function(require,module,exports){
"use strict";function destroy(t,e){var r=this,a=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return a||i?(e?e(t):!t||this._writableState&&this._writableState.errorEmitted||pna.nextTick(emitErrorNT,this,t),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,function(t){!e&&t?(pna.nextTick(emitErrorNT,r,t),r._writableState&&(r._writableState.errorEmitted=!0)):e&&e(t)}),this)}function undestroy(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function emitErrorNT(t,e){t.emit("error",e)}var pna=require("process-nextick-args");module.exports={destroy:destroy,undestroy:undestroy};
},{"process-nextick-args":95}],105:[function(require,module,exports){
module.exports=require("events").EventEmitter;
},{"events":56}],106:[function(require,module,exports){
"use strict";function _normalizeEncoding(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}function normalizeEncoding(t){var e=_normalizeEncoding(t);if("string"!=typeof e&&(Buffer.isEncoding===isEncoding||!isEncoding(t)))throw new Error("Unknown encoding: "+t);return e||t}function StringDecoder(t){this.encoding=normalizeEncoding(t);var e;switch(this.encoding){case"utf16le":this.text=utf16Text,this.end=utf16End,e=4;break;case"utf8":this.fillLast=utf8FillLast,e=4;break;case"base64":this.text=base64Text,this.end=base64End,e=3;break;default:return this.write=simpleWrite,void(this.end=simpleEnd)}this.lastNeed=0,this.lastTotal=0,this.lastChar=Buffer.allocUnsafe(e)}function utf8CheckByte(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function utf8CheckIncomplete(t,e,s){var i=e.length-1;if(i<s)return 0;var n=utf8CheckByte(e[i]);return n>=0?(n>0&&(t.lastNeed=n-1),n):--i<s||-2===n?0:(n=utf8CheckByte(e[i]))>=0?(n>0&&(t.lastNeed=n-2),n):--i<s||-2===n?0:(n=utf8CheckByte(e[i]),n>=0?(n>0&&(2===n?n=0:t.lastNeed=n-3),n):0)}function utf8CheckExtraBytes(t,e,s){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}function utf8FillLast(t){var e=this.lastTotal-this.lastNeed,s=utf8CheckExtraBytes(this,t,e);return void 0!==s?s:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function utf8Text(t,e){var s=utf8CheckIncomplete(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=s;var i=t.length-(s-this.lastNeed);return t.copy(this.lastChar,0,i),t.toString("utf8",e,i)}function utf8End(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"�":e}function utf16Text(t,e){if((t.length-e)%2==0){var s=t.toString("utf16le",e);if(s){var i=s.charCodeAt(s.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],s.slice(0,-1)}return s}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function utf16End(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var s=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,s)}return e}function base64Text(t,e){var s=(t.length-e)%3;return 0===s?t.toString("base64",e):(this.lastNeed=3-s,this.lastTotal=3,1===s?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-s))}function base64End(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function simpleWrite(t){return t.toString(this.encoding)}function simpleEnd(t){return t&&t.length?this.write(t):""}var Buffer=require("safe-buffer").Buffer,isEncoding=Buffer.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};exports.StringDecoder=StringDecoder,StringDecoder.prototype.write=function(t){if(0===t.length)return"";var e,s;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";s=this.lastNeed,this.lastNeed=0}else s=0;return s<t.length?e?e+this.text(t,s):this.text(t,s):e||""},StringDecoder.prototype.end=utf8End,StringDecoder.prototype.text=utf8Text,StringDecoder.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length};
},{"safe-buffer":111}],107:[function(require,module,exports){
module.exports=require("./readable").PassThrough;
},{"./readable":108}],108:[function(require,module,exports){
exports=module.exports=require("./lib/_stream_readable.js"),exports.Stream=exports,exports.Readable=exports,exports.Writable=require("./lib/_stream_writable.js"),exports.Duplex=require("./lib/_stream_duplex.js"),exports.Transform=require("./lib/_stream_transform.js"),exports.PassThrough=require("./lib/_stream_passthrough.js");
},{"./lib/_stream_duplex.js":98,"./lib/_stream_passthrough.js":99,"./lib/_stream_readable.js":100,"./lib/_stream_transform.js":101,"./lib/_stream_writable.js":102}],109:[function(require,module,exports){
module.exports=require("./readable").Transform;
},{"./readable":108}],110:[function(require,module,exports){
module.exports=require("./lib/_stream_writable.js");
},{"./lib/_stream_writable.js":102}],111:[function(require,module,exports){
function copyProps(f,r){for(var e in f)r[e]=f[e]}function SafeBuffer(f,r,e){return Buffer(f,r,e)}var buffer=require("buffer"),Buffer=buffer.Buffer;Buffer.from&&Buffer.alloc&&Buffer.allocUnsafe&&Buffer.allocUnsafeSlow?module.exports=buffer:(copyProps(buffer,exports),exports.Buffer=SafeBuffer),copyProps(Buffer,SafeBuffer),SafeBuffer.from=function(f,r,e){if("number"==typeof f)throw new TypeError("Argument must not be a number");return Buffer(f,r,e)},SafeBuffer.alloc=function(f,r,e){if("number"!=typeof f)throw new TypeError("Argument must be a number");var u=Buffer(f);return void 0!==r?"string"==typeof e?u.fill(r,e):u.fill(r):u.fill(0),u},SafeBuffer.allocUnsafe=function(f){if("number"!=typeof f)throw new TypeError("Argument must be a number");return Buffer(f)},SafeBuffer.allocUnsafeSlow=function(f){if("number"!=typeof f)throw new TypeError("Argument must be a number");return buffer.SlowBuffer(f)};
},{"buffer":54}],112:[function(require,module,exports){
function Stream(){EE.call(this)}module.exports=Stream;var EE=require("events").EventEmitter,inherits=require("inherits");inherits(Stream,EE),Stream.Readable=require("readable-stream/readable.js"),Stream.Writable=require("readable-stream/writable.js"),Stream.Duplex=require("readable-stream/duplex.js"),Stream.Transform=require("readable-stream/transform.js"),Stream.PassThrough=require("readable-stream/passthrough.js"),Stream.Stream=Stream,Stream.prototype.pipe=function(e,r){function t(r){e.writable&&!1===e.write(r)&&m.pause&&m.pause()}function n(){m.readable&&m.resume&&m.resume()}function a(){u||(u=!0,e.end())}function o(){u||(u=!0,"function"==typeof e.destroy&&e.destroy())}function i(e){if(s(),0===EE.listenerCount(this,"error"))throw e}function s(){m.removeListener("data",t),e.removeListener("drain",n),m.removeListener("end",a),m.removeListener("close",o),m.removeListener("error",i),e.removeListener("error",i),m.removeListener("end",s),m.removeListener("close",s),e.removeListener("close",s)}var m=this;m.on("data",t),e.on("drain",n),e._isStdio||r&&!1===r.end||(m.on("end",a),m.on("close",o));var u=!1;return m.on("error",i),e.on("error",i),m.on("end",s),m.on("close",s),e.on("close",s),e.emit("pipe",m),e};
},{"events":56,"inherits":92,"readable-stream/duplex.js":97,"readable-stream/passthrough.js":107,"readable-stream/readable.js":108,"readable-stream/transform.js":109,"readable-stream/writable.js":110}],113:[function(require,module,exports){
"use strict";function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),_=require("./"),_2=_interopRequireDefault(_),Block=function(){function t(e,n){_classCallCheck(this,t),this.index=0,this.thaws=[],this.count=n||200,this.options=e}return _createClass(t,[{key:"add",value:function(t){return this._next().add(t),this}},{key:"addArray",value:function(t){return this._next().addArray(t),this}},{key:"insert",value:function(t){return this._next().insert(t),this}},{key:"insertArray",value:function(t){return this._next().insertArray(t),this}},{key:"stop",value:function(){for(var t=0;t<this.thaws.length;t++)this.thaws[t].stop();return this}},{key:"_next",value:function(){var t=null,e=this.thaws;return e.length<this.count?e.push(t=new _2.default([],this.options)):t=e[this.index],this.index++,this.index>=this.count&&(this.index=0),t}}]),t}();exports.default=Block;
},{"./":114}],114:[function(require,module,exports){
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.Block=void 0;var _thaw=require("./thaw"),_thaw2=_interopRequireDefault(_thaw),_block=require("./block"),_block2=_interopRequireDefault(_block);exports.default=_thaw2.default,exports.Block=_block2.default,"undefined"!=typeof window&&(window.Thaw=_thaw2.default,window.Thaw.Block=_block2.default);
},{"./block":113,"./thaw":115}],115:[function(require,module,exports){
"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function thaw(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Thaw(t,e)}Object.defineProperty(exports,"__esModule",{value:!0});var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},_createClass=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}();exports.thaw=thaw;var thawing=!1,thaws=[],Thaw=function(){function t(e){var i=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};_classCallCheck(this,t);var s=_extends({},this.constructor.defaultSettings,n),a=s.each,r=s.done;this.items=e,this.i=0,this.options=n;var h=this.tick=function(){if(!(i.i<0||(i.timeout=setTimeout(h,0),thawing))){var t=e[i.i];if(i.i>=e.length)return null!==r&&(thawing=!0,r(t,i.i),thawing=!1),i.i=-1,void clearTimeout(i.timeout);null!==a?(thawing=!0,a(t,i.i),thawing=!1):void 0!==t&&t(),i.i++}};thaws.push(this),n.delay||h()}return _createClass(t,null,[{key:"stopAll",value:function(){for(var t=0;t<thaws.length;t++)thaws[t].stop()}},{key:"defaultSettings",get:function(){return{each:null,done:null}}},{key:"isThawing",get:function(){return thawing}}]),_createClass(t,[{key:"makeReady",value:function(){return this.i<0&&(this.i=this.items.length,!0)}},{key:"add",value:function(t){var e=this.makeReady();return this.items.push(t),e&&this.tick(),this}},{key:"insert",value:function(t){var e=this.makeReady();return this.items.splice(this.i,0,t),e&&this.tick(),this}},{key:"addArray",value:function(t){var e=this.makeReady();return this.items=this.items.concat(t),e&&this.tick(),this}},{key:"insertArray",value:function(t){var e=this.makeReady(),i=this.items,n=t,s=this.items.splice(this.i,this.items.length-this.i+1);return this.items=i.concat(n,s),e&&this.tick(),this}},{key:"stop",value:function(){return this.i=-1,clearTimeout(this.timeout),this.options.done&&this.options.done(),this}}]),t}();exports.default=Thaw;
},{}],116:[function(require,module,exports){
(function (setImmediate,clearImmediate){
function Timeout(e,t){this._id=e,this._clearFn=t}var nextTick=require("process/browser.js").nextTick,apply=Function.prototype.apply,slice=Array.prototype.slice,immediateIds={},nextImmediateId=0;exports.setTimeout=function(){return new Timeout(apply.call(setTimeout,window,arguments),clearTimeout)},exports.setInterval=function(){return new Timeout(apply.call(setInterval,window,arguments),clearInterval)},exports.clearTimeout=exports.clearInterval=function(e){e.close()},Timeout.prototype.unref=Timeout.prototype.ref=function(){},Timeout.prototype.close=function(){this._clearFn.call(window,this._id)},exports.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},exports.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},exports._unrefActive=exports.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},exports.setImmediate="function"==typeof setImmediate?setImmediate:function(e){var t=nextImmediateId++,i=!(arguments.length<2)&&slice.call(arguments,1);return immediateIds[t]=!0,nextTick(function(){immediateIds[t]&&(i?e.apply(null,i):e.call(null),exports.clearImmediate(t))}),t},exports.clearImmediate="function"==typeof clearImmediate?clearImmediate:function(e){delete immediateIds[e]};
}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
},{"process/browser.js":96,"timers":116}],117:[function(require,module,exports){
(function (global){
function deprecate(r,e){function o(){if(!t){if(config("throwDeprecation"))throw new Error(e);config("traceDeprecation")?console.trace(e):console.warn(e),t=!0}return r.apply(this,arguments)}if(config("noDeprecation"))return r;var t=!1;return o}function config(r){try{if(!global.localStorage)return!1}catch(r){return!1}var e=global.localStorage[r];return null!=e&&"true"===String(e).toLowerCase()}module.exports=deprecate;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}]},{},[51])(51)
});