phaser4-rex-plugins
Version:
9 lines (8 loc) • 36.6 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcsvscenarioplugin=e()}(void 0,(function(){"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function r(){}function s(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,r,n,a){if("function"!=typeof r)throw new TypeError("The listener must be a function");var o=new s(r,n||t,a),h=i?i+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],o]:t._events[h].push(o):(t._events[h]=o,t._eventsCount++),t}function a(t,e){0==--t._eventsCount?t._events=new r:delete t._events[e]}function o(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(i=!1)),o.prototype.eventNames=function(){var t,r,s=[];if(0===this._eventsCount)return s;for(r in t=this._events)e.call(t,r)&&s.push(i?r.slice(1):r);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},o.prototype.listeners=function(t){var e=i?i+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var s=0,n=r.length,a=new Array(n);s<n;s++)a[s]=r[s].fn;return a},o.prototype.listenerCount=function(t){var e=i?i+t:t,r=this._events[e];return r?r.fn?1:r.length:0},o.prototype.emit=function(t,e,r,s,n,a){var o=i?i+t:t;if(!this._events[o])return!1;var h,u,l=this._events[o],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,r),!0;case 4:return l.fn.call(l.context,e,r,s),!0;case 5:return l.fn.call(l.context,e,r,s,n),!0;case 6:return l.fn.call(l.context,e,r,s,n,a),!0}for(u=1,h=new Array(c-1);u<c;u++)h[u-1]=arguments[u];l.fn.apply(l.context,h)}else{var d,f=l.length;for(u=0;u<f;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,r);break;case 4:l[u].fn.call(l[u].context,e,r,s);break;default:if(!h)for(d=1,h=new Array(c-1);d<c;d++)h[d-1]=arguments[d];l[u].fn.apply(l[u].context,h)}}return!0},o.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},o.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},o.prototype.removeListener=function(t,e,r,s){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return a(this,n),this;var o=this._events[n];if(o.fn)o.fn!==e||s&&!o.once||r&&o.context!==r||a(this,n);else{for(var h=0,u=[],l=o.length;h<l;h++)(o[h].fn!==e||s&&!o[h].once||r&&o[h].context!==r)&&u.push(o[h]);u.length?this._events[n]=1===u.length?u[0]:u:a(this,n)}return this},o.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&a(this,e)):(this._events=new r,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=i,o.EventEmitter=o,t.exports=o}(e);var i=t(e.exports);class r extends i{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var s={setEventEmitter(t,e){return void 0===e&&(e=r),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},n=function(t,e,i){if(!t||"number"==typeof t)return i;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return i;e=e.split(".")}for(var r=e,s=t,n=i,a=0;a<r.length;a++){if(e=r[a],!s.hasOwnProperty(e)){n=i;break}s=n=s[e]}return n},a={exports:{}};
/* @license
Papa Parse
v5.4.1
https://github.com/mholt/PapaParse
License: MIT
*/
!function(t){t.exports=function t(){var e="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==e?e:{},i=!e.document&&!!e.postMessage,r=e.IS_PAPA_WORKER||!1,s={},n=0,a={parse:function(i,r){var o=(r=r||{}).dynamicTyping||!1;if(E(o)&&(r.dynamicTypingFunction=o,o={}),r.dynamicTyping=o,r.transform=!!E(r.transform)&&r.transform,r.worker&&a.WORKERS_SUPPORTED){var h=function(){if(!a.WORKERS_SUPPORTED)return!1;var i,r,o=(i=e.URL||e.webkitURL||null,r=t.toString(),a.BLOB_URL||(a.BLOB_URL=i.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",r,")();"],{type:"text/javascript"})))),h=new e.Worker(o);return h.onmessage=v,h.id=n++,s[h.id]=h}();return h.userStep=r.step,h.userChunk=r.chunk,h.userComplete=r.complete,h.userError=r.error,r.step=E(r.step),r.chunk=E(r.chunk),r.complete=E(r.complete),r.error=E(r.error),delete r.worker,void h.postMessage({input:i,config:r,workerId:h.id})}var f=null;return a.NODE_STREAM_INPUT,"string"==typeof i?(i=function(t){return 65279===t.charCodeAt(0)?t.slice(1):t}(i),f=r.download?new u(r):new c(r)):!0===i.readable&&E(i.read)&&E(i.on)?f=new d(r):(e.File&&i instanceof File||i instanceof Object)&&(f=new l(r)),f.stream(i)},unparse:function(t,e){var i=!1,r=!0,s=",",n="\r\n",o='"',h=o+o,u=!1,l=null,c=!1;!function(){if("object"==typeof e){if("string"!=typeof e.delimiter||a.BAD_DELIMITERS.filter((function(t){return-1!==e.delimiter.indexOf(t)})).length||(s=e.delimiter),("boolean"==typeof e.quotes||"function"==typeof e.quotes||Array.isArray(e.quotes))&&(i=e.quotes),"boolean"!=typeof e.skipEmptyLines&&"string"!=typeof e.skipEmptyLines||(u=e.skipEmptyLines),"string"==typeof e.newline&&(n=e.newline),"string"==typeof e.quoteChar&&(o=e.quoteChar),"boolean"==typeof e.header&&(r=e.header),Array.isArray(e.columns)){if(0===e.columns.length)throw new Error("Option columns is empty");l=e.columns}void 0!==e.escapeChar&&(h=e.escapeChar+o),("boolean"==typeof e.escapeFormulae||e.escapeFormulae instanceof RegExp)&&(c=e.escapeFormulae instanceof RegExp?e.escapeFormulae:/^[=+\-@\t\r].*$/)}}();var d=new RegExp(p(o),"g");if("string"==typeof t&&(t=JSON.parse(t)),Array.isArray(t)){if(!t.length||Array.isArray(t[0]))return f(null,t,u);if("object"==typeof t[0])return f(l||Object.keys(t[0]),t,u)}else if("object"==typeof t)return"string"==typeof t.data&&(t.data=JSON.parse(t.data)),Array.isArray(t.data)&&(t.fields||(t.fields=t.meta&&t.meta.fields||l),t.fields||(t.fields=Array.isArray(t.data[0])?t.fields:"object"==typeof t.data[0]?Object.keys(t.data[0]):[]),Array.isArray(t.data[0])||"object"==typeof t.data[0]||(t.data=[t.data])),f(t.fields||[],t.data||[],u);throw new Error("Unable to serialize unrecognized input");function f(t,e,i){var a="";"string"==typeof t&&(t=JSON.parse(t)),"string"==typeof e&&(e=JSON.parse(e));var o=Array.isArray(t)&&0<t.length,h=!Array.isArray(e[0]);if(o&&r){for(var u=0;u<t.length;u++)0<u&&(a+=s),a+=m(t[u],u);0<e.length&&(a+=n)}for(var l=0;l<e.length;l++){var c=o?t.length:e[l].length,d=!1,f=o?0===Object.keys(e[l]).length:0===e[l].length;if(i&&!o&&(d="greedy"===i?""===e[l].join("").trim():1===e[l].length&&0===e[l][0].length),"greedy"===i&&o){for(var p=[],v=0;v<c;v++){var g=h?t[v]:v;p.push(e[l][g])}d=""===p.join("").trim()}if(!d){for(var _=0;_<c;_++){0<_&&!f&&(a+=s);var y=o&&h?t[_]:_;a+=m(e[l][y],_)}l<e.length-1&&(!i||0<c&&!f)&&(a+=n)}}return a}function m(t,e){if(null==t)return"";if(t.constructor===Date)return JSON.stringify(t).slice(1,25);var r=!1;c&&"string"==typeof t&&c.test(t)&&(t="'"+t,r=!0);var n=t.toString().replace(d,h);return(r=r||!0===i||"function"==typeof i&&i(t,e)||Array.isArray(i)&&i[e]||function(t,e){for(var i=0;i<e.length;i++)if(-1<t.indexOf(e[i]))return!0;return!1}(n,a.BAD_DELIMITERS)||-1<n.indexOf(s)||" "===n.charAt(0)||" "===n.charAt(n.length-1))?o+n+o:n}}};if(a.RECORD_SEP=String.fromCharCode(30),a.UNIT_SEP=String.fromCharCode(31),a.BYTE_ORDER_MARK="\ufeff",a.BAD_DELIMITERS=["\r","\n",'"',a.BYTE_ORDER_MARK],a.WORKERS_SUPPORTED=!i&&!!e.Worker,a.NODE_STREAM_INPUT=1,a.LocalChunkSize=10485760,a.RemoteChunkSize=5242880,a.DefaultDelimiter=",",a.Parser=m,a.ParserHandle=f,a.NetworkStreamer=u,a.FileStreamer=l,a.StringStreamer=c,a.ReadableStreamStreamer=d,e.jQuery){var o=e.jQuery;o.fn.parse=function(t){var i=t.config||{},r=[];return this.each((function(t){if("INPUT"!==o(this).prop("tagName").toUpperCase()||"file"!==o(this).attr("type").toLowerCase()||!e.FileReader||!this.files||0===this.files.length)return!0;for(var s=0;s<this.files.length;s++)r.push({file:this.files[s],inputElem:this,instanceConfig:o.extend({},i)})})),s(),this;function s(){if(0!==r.length){var e,i,s,h,u=r[0];if(E(t.before)){var l=t.before(u.file,u.inputElem);if("object"==typeof l){if("abort"===l.action)return e="AbortError",i=u.file,s=u.inputElem,h=l.reason,void(E(t.error)&&t.error({name:e},i,s,h));if("skip"===l.action)return void n();"object"==typeof l.config&&(u.instanceConfig=o.extend(u.instanceConfig,l.config))}else if("skip"===l)return void n()}var c=u.instanceConfig.complete;u.instanceConfig.complete=function(t){E(c)&&c(t,u.file,u.inputElem),n()},a.parse(u.file,u.instanceConfig)}else E(t.complete)&&t.complete()}function n(){r.splice(0,1),s()}}}function h(t){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(t){var e=y(t);e.chunkSize=parseInt(e.chunkSize),t.step||t.chunk||(e.chunkSize=null),this._handle=new f(e),(this._handle.streamer=this)._config=e}.call(this,t),this.parseChunk=function(t,i){if(this.isFirstChunk&&E(this._config.beforeFirstChunk)){var s=this._config.beforeFirstChunk(t);void 0!==s&&(t=s)}this.isFirstChunk=!1,this._halted=!1;var n=this._partialLine+t;this._partialLine="";var o=this._handle.parse(n,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var h=o.meta.cursor;this._finished||(this._partialLine=n.substring(h-this._baseIndex),this._baseIndex=h),o&&o.data&&(this._rowCount+=o.data.length);var u=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(r)e.postMessage({results:o,workerId:a.WORKER_ID,finished:u});else if(E(this._config.chunk)&&!i){if(this._config.chunk(o,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);o=void 0,this._completeResults=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(o.data),this._completeResults.errors=this._completeResults.errors.concat(o.errors),this._completeResults.meta=o.meta),this._completed||!u||!E(this._config.complete)||o&&o.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),u||o&&o.meta.paused||this._nextChunk(),o}this._halted=!0},this._sendError=function(t){E(this._config.error)?this._config.error(t):r&&this._config.error&&e.postMessage({workerId:a.WORKER_ID,error:t,finished:!1})}}function u(t){var e;(t=t||{}).chunkSize||(t.chunkSize=a.RemoteChunkSize),h.call(this,t),this._nextChunk=i?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(t){this._input=t,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(e=new XMLHttpRequest,this._config.withCredentials&&(e.withCredentials=this._config.withCredentials),i||(e.onload=b(this._chunkLoaded,this),e.onerror=b(this._chunkError,this)),e.open(this._config.downloadRequestBody?"POST":"GET",this._input,!i),this._config.downloadRequestHeaders){var t=this._config.downloadRequestHeaders;for(var r in t)e.setRequestHeader(r,t[r])}if(this._config.chunkSize){var s=this._start+this._config.chunkSize-1;e.setRequestHeader("Range","bytes="+this._start+"-"+s)}try{e.send(this._config.downloadRequestBody)}catch(t){this._chunkError(t.message)}i&&0===e.status&&this._chunkError()}},this._chunkLoaded=function(){4===e.readyState&&(e.status<200||400<=e.status?this._chunkError():(this._start+=this._config.chunkSize?this._config.chunkSize:e.responseText.length,this._finished=!this._config.chunkSize||this._start>=function(t){var e=t.getResponseHeader("Content-Range");return null===e?-1:parseInt(e.substring(e.lastIndexOf("/")+1))}(e),this.parseChunk(e.responseText)))},this._chunkError=function(t){var i=e.statusText||t;this._sendError(new Error(i))}}function l(t){var e,i;(t=t||{}).chunkSize||(t.chunkSize=a.LocalChunkSize),h.call(this,t);var r="undefined"!=typeof FileReader;this.stream=function(t){this._input=t,i=t.slice||t.webkitSlice||t.mozSlice,r?((e=new FileReader).onload=b(this._chunkLoaded,this),e.onerror=b(this._chunkError,this)):e=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var t=this._input;if(this._config.chunkSize){var s=Math.min(this._start+this._config.chunkSize,this._input.size);t=i.call(t,this._start,s)}var n=e.readAsText(t,this._config.encoding);r||this._chunkLoaded({target:{result:n}})},this._chunkLoaded=function(t){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(t.target.result)},this._chunkError=function(){this._sendError(e.error)}}function c(t){var e;h.call(this,t=t||{}),this.stream=function(t){return e=t,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var t,i=this._config.chunkSize;return i?(t=e.substring(0,i),e=e.substring(i)):(t=e,e=""),this._finished=!e,this.parseChunk(t)}}}function d(t){h.call(this,t=t||{});var e=[],i=!0,r=!1;this.pause=function(){h.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){h.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(t){this._input=t,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){r&&1===e.length&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),e.length?this.parseChunk(e.shift()):i=!0},this._streamData=b((function(t){try{e.push("string"==typeof t?t:t.toString(this._config.encoding)),i&&(i=!1,this._checkIsFinished(),this.parseChunk(e.shift()))}catch(t){this._streamError(t)}}),this),this._streamError=b((function(t){this._streamCleanUp(),this._sendError(t)}),this),this._streamEnd=b((function(){this._streamCleanUp(),r=!0,this._streamData("")}),this),this._streamCleanUp=b((function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)}),this)}function f(t){var e,i,r,s=Math.pow(2,53),n=-s,o=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,h=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,u=this,l=0,c=0,d=!1,f=!1,v=[],g={data:[],errors:[],meta:{}};if(E(t.step)){var _=t.step;t.step=function(e){if(g=e,C())w();else{if(w(),0===g.data.length)return;l+=e.data.length,t.preview&&l>t.preview?i.abort():(g.data=g.data[0],_(g,u))}}}function b(e){return"greedy"===t.skipEmptyLines?""===e.join("").trim():1===e.length&&0===e[0].length}function w(){return g&&r&&(k("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),r=!1),t.skipEmptyLines&&(g.data=g.data.filter((function(t){return!b(t)}))),C()&&function(){if(g)if(Array.isArray(g.data[0])){for(var e=0;C()&&e<g.data.length;e++)g.data[e].forEach(i);g.data.splice(0,1)}else g.data.forEach(i);function i(e,i){E(t.transformHeader)&&(e=t.transformHeader(e,i)),v.push(e)}}(),function(){if(!g||!t.header&&!t.dynamicTyping&&!t.transform)return g;function e(e,i){var r,s=t.header?{}:[];for(r=0;r<e.length;r++){var n=r,a=e[r];t.header&&(n=r>=v.length?"__parsed_extra":v[r]),t.transform&&(a=t.transform(a,n)),a=x(n,a),"__parsed_extra"===n?(s[n]=s[n]||[],s[n].push(a)):s[n]=a}return t.header&&(r>v.length?k("FieldMismatch","TooManyFields","Too many fields: expected "+v.length+" fields but parsed "+r,c+i):r<v.length&&k("FieldMismatch","TooFewFields","Too few fields: expected "+v.length+" fields but parsed "+r,c+i)),s}var i=1;return!g.data.length||Array.isArray(g.data[0])?(g.data=g.data.map(e),i=g.data.length):g.data=e(g.data,0),t.header&&g.meta&&(g.meta.fields=v),c+=i,g}()}function C(){return t.header&&0===v.length}function x(e,i){return r=e,t.dynamicTypingFunction&&void 0===t.dynamicTyping[r]&&(t.dynamicTyping[r]=t.dynamicTypingFunction(r)),!0===(t.dynamicTyping[r]||t.dynamicTyping)?"true"===i||"TRUE"===i||"false"!==i&&"FALSE"!==i&&(function(t){if(o.test(t)){var e=parseFloat(t);if(n<e&&e<s)return!0}return!1}(i)?parseFloat(i):h.test(i)?new Date(i):""===i?null:i):i;var r}function k(t,e,i,r){var s={type:t,code:e,message:i};void 0!==r&&(s.row=r),g.errors.push(s)}this.parse=function(s,n,o){var h=t.quoteChar||'"';if(t.newline||(t.newline=function(t,e){t=t.substring(0,1048576);var i=new RegExp(p(e)+"([^]*?)"+p(e),"gm"),r=(t=t.replace(i,"")).split("\r"),s=t.split("\n"),n=1<s.length&&s[0].length<r[0].length;if(1===r.length||n)return"\n";for(var a=0,o=0;o<r.length;o++)"\n"===r[o][0]&&a++;return a>=r.length/2?"\r\n":"\r"}(s,h)),r=!1,t.delimiter)E(t.delimiter)&&(t.delimiter=t.delimiter(s),g.meta.delimiter=t.delimiter);else{var u=function(e,i,r,s,n){var o,h,u,l;n=n||[",","\t","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var c=0;c<n.length;c++){var d=n[c],f=0,p=0,v=0;u=void 0;for(var g=new m({comments:s,delimiter:d,newline:i,preview:10}).parse(e),_=0;_<g.data.length;_++)if(r&&b(g.data[_]))v++;else{var y=g.data[_].length;p+=y,void 0!==u?0<y&&(f+=Math.abs(y-u),u=y):u=y}0<g.data.length&&(p/=g.data.length-v),(void 0===h||f<=h)&&(void 0===l||l<p)&&1.99<p&&(h=f,o=d,l=p)}return{successful:!!(t.delimiter=o),bestDelimiter:o}}(s,t.newline,t.skipEmptyLines,t.comments,t.delimitersToGuess);u.successful?t.delimiter=u.bestDelimiter:(r=!0,t.delimiter=a.DefaultDelimiter),g.meta.delimiter=t.delimiter}var l=y(t);return t.preview&&t.header&&l.preview++,e=s,i=new m(l),g=i.parse(e,n,o),w(),d?{meta:{paused:!0}}:g||{meta:{paused:!1}}},this.paused=function(){return d},this.pause=function(){d=!0,i.abort(),e=E(t.chunk)?"":e.substring(i.getCharIndex())},this.resume=function(){u.streamer._halted?(d=!1,u.streamer.parseChunk(e,!0)):setTimeout(u.resume,3)},this.aborted=function(){return f},this.abort=function(){f=!0,i.abort(),g.meta.aborted=!0,E(t.complete)&&t.complete(g),e=""}}function p(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function m(t){var e,i=(t=t||{}).delimiter,r=t.newline,s=t.comments,n=t.step,o=t.preview,h=t.fastMode,u=e=void 0===t.quoteChar||null===t.quoteChar?'"':t.quoteChar;if(void 0!==t.escapeChar&&(u=t.escapeChar),("string"!=typeof i||-1<a.BAD_DELIMITERS.indexOf(i))&&(i=","),s===i)throw new Error("Comment character same as delimiter");!0===s?s="#":("string"!=typeof s||-1<a.BAD_DELIMITERS.indexOf(s))&&(s=!1),"\n"!==r&&"\r"!==r&&"\r\n"!==r&&(r="\n");var l=0,c=!1;this.parse=function(a,d,f){if("string"!=typeof a)throw new Error("Input must be a string");var m=a.length,v=i.length,g=r.length,_=s.length,y=E(n),b=[],w=[],C=[],x=l=0;if(!a)return K();if(t.header&&!d){var k=a.split(r)[0].split(i),S=[],O={},L=!1;for(var R in k){var I=k[R];E(t.transformHeader)&&(I=t.transformHeader(I,R));var T=I,N=O[I]||0;for(0<N&&(L=!0,T=I+"_"+N),O[I]=N+1;S.includes(T);)T=T+"_"+N;S.push(T)}if(L){var A=a.split(r);A[0]=S.join(i),a=A.join(r)}}if(h||!1!==h&&-1===a.indexOf(e)){for(var F=a.split(r),P=0;P<F.length;P++){if(C=F[P],l+=C.length,P!==F.length-1)l+=r.length;else if(f)return K();if(!s||C.substring(0,_)!==s){if(y){if(b=[],J(C.split(i)),$(),c)return K()}else J(C.split(i));if(o&&o<=P)return b=b.slice(0,o),K(!0)}}return K()}for(var D=a.indexOf(i,l),M=a.indexOf(r,l),j=new RegExp(p(u)+p(e),"g"),U=a.indexOf(e,l);;)if(a[l]!==e)if(s&&0===C.length&&a.substring(l,l+_)===s){if(-1===M)return K();l=M+g,M=a.indexOf(r,l),D=a.indexOf(i,l)}else if(-1!==D&&(D<M||-1===M))C.push(a.substring(l,D)),l=D+v,D=a.indexOf(i,l);else{if(-1===M)break;if(C.push(a.substring(l,M)),W(M+g),y&&($(),c))return K();if(o&&b.length>=o)return K(!0)}else for(U=l,l++;;){if(-1===(U=a.indexOf(e,U+1)))return f||w.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:b.length,index:l}),B();if(U===m-1)return B(a.substring(l,U).replace(j,e));if(e!==u||a[U+1]!==u){if(e===u||0===U||a[U-1]!==u){-1!==D&&D<U+1&&(D=a.indexOf(i,U+1)),-1!==M&&M<U+1&&(M=a.indexOf(r,U+1));var q=H(-1===M?D:Math.min(D,M));if(a.substr(U+1+q,v)===i){C.push(a.substring(l,U).replace(j,e)),a[l=U+1+q+v]!==e&&(U=a.indexOf(e,l)),D=a.indexOf(i,l),M=a.indexOf(r,l);break}var z=H(M);if(a.substring(U+1+z,U+1+z+g)===r){if(C.push(a.substring(l,U).replace(j,e)),W(U+1+z+g),D=a.indexOf(i,l),U=a.indexOf(e,l),y&&($(),c))return K();if(o&&b.length>=o)return K(!0);break}w.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:b.length,index:l}),U++}}else U++}return B();function J(t){b.push(t),x=l}function H(t){var e=0;if(-1!==t){var i=a.substring(U+1,t);i&&""===i.trim()&&(e=i.length)}return e}function B(t){return f||(void 0===t&&(t=a.substring(l)),C.push(t),l=m,J(C),y&&$()),K()}function W(t){l=t,J(C),C=[],M=a.indexOf(r,l)}function K(t){return{data:b,errors:w,meta:{delimiter:i,linebreak:r,aborted:c,truncated:!!t,cursor:x+(d||0)}}}function $(){n(K()),b=[],w=[]}},this.abort=function(){c=!0},this.getCharIndex=function(){return l}}function v(t){var e=t.data,i=s[e.workerId],r=!1;if(e.error)i.userError(e.error,e.file);else if(e.results&&e.results.data){var n={abort:function(){r=!0,g(e.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:_,resume:_};if(E(i.userStep)){for(var a=0;a<e.results.data.length&&(i.userStep({data:e.results.data[a],errors:e.results.errors,meta:e.results.meta},n),!r);a++);delete e.results}else E(i.userChunk)&&(i.userChunk(e.results,n,e.file),delete e.results)}e.finished&&!r&&g(e.workerId,e.results)}function g(t,e){var i=s[t];E(i.userComplete)&&i.userComplete(e),i.terminate(),delete s[t]}function _(){throw new Error("Not implemented.")}function y(t){if("object"!=typeof t||null===t)return t;var e=Array.isArray(t)?[]:{};for(var i in t)e[i]=y(t[i]);return e}function b(t,e){return function(){t.apply(e,arguments)}}function E(t){return"function"==typeof t}return r&&(e.onmessage=function(t){var i=t.data;if(void 0===a.WORKER_ID&&i&&(a.WORKER_ID=i.workerId),"string"==typeof i.input)e.postMessage({workerId:a.WORKER_ID,results:a.parse(i.input,i.config),finished:!0});else if(e.File&&i.input instanceof File||i.input instanceof Object){var r=a.parse(i.input,i.config);r&&e.postMessage({workerId:a.WORKER_ID,results:r,finished:!0})}}),(u.prototype=Object.create(h.prototype)).constructor=u,(l.prototype=Object.create(h.prototype)).constructor=l,(c.prototype=Object.create(c.prototype)).constructor=c,(d.prototype=Object.create(h.prototype)).constructor=d,a}()}(a);var o=t(a.exports),h=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e];return t},u=function(t,e){var i=Array.isArray(t);if(void 0===e?e=i?[]:{}:h(e),i){e.length=t.length;for(var r=0,s=t.length;r<s;r++)e[r]=t[r]}else for(var n in t)e[n]=t[n];return e};class l{constructor(t){this.scenario=t,this.queue=[],this.currentIdx=-1,this.nextIdx=0}resetFromJSON(t){var e=n(t,"queue",void 0);return void 0===e?h(this.queue):u(e,this.queue),this.currentIdx=n(t,"curIdx",-1),this.nextIdx=n(t,"nextIdx",0),this}clear(){return this.currentIdx=-1,this.nextIdx=0,this.queue.length=0,this}append(t){return this.queue.push(t),this}setNextIndex(t){return void 0===t&&(t=this.currentIdx+1),this.nextIdx=t,this}get(t){return void 0===t&&(t=this.nextIdx),this.currentIdx=t,this.queue[t]}get length(){return this.queue.length}}class c{constructor(t,e){this.scenario=t,this.type=e}resetFromJSON(t){}toJSON(){return{}}parse(t,e){return t}run(t){}}var d=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,f=/^0x[0-9A-F]+$/i,p=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(d.test(t))t=parseFloat(t);else if(f.test(t))t=parseInt(t,16);else switch(t){case"false":t=!1;break;case"true":t=!0;break;case"null":t=null;break;case"undefined":t=void 0}return t},m=function(t,e,i){var r,s,a=n(i,"reverse",!1);if(s=t[0],"[object Array]"===Object.prototype.toString.call(s))if(a)for(o=(h=t.length)-1;o>=0;o--)r=m(t[o],e,i);else for(var o=0,h=t.length;o<h;o++)r=m(t[o],e,i);else r=v(t,e,i);return r},v=function(t,e,i){var r,s=n(i,"argsConvert",void 0),a=n(i,"argsConvertScope",void 0),o=t[0];if(g=function(t,e,i,r){void 0===i&&(i=0),void 0===r&&(r=e.length),t.length=r-i;for(var s=0,n=t.length;s<n;s++)t[s]=e[s+i];return t}(g,t,1),s){!0===s&&(s=p,a=void 0);for(var h=0,u=g.length;h<u;h++)g[h]=a?s.call(a,g[h],t):s(g[h],t)}return"string"==typeof o?null==(r=e[o])&&(r=n(e,o,null)):r=o,r.apply(e,g)},g=[];class _ extends c{constructor(t){super(t,"-"),this.task=void 0,this.lastMethodName=void 0}resetFromJSON(t){this.task&&(this.task.off("complete",this.resume,this),this.task=void 0)}parse(t,e){var i=function(t,e){if(!(e>=t.length)){for(var i=t.length-1,r=t[e],s=e;s<i;s++)t[s]=t[s+1];return t.length=i,r}}(t,0),r=this.scenario,s=r.argsConvert,n=r.argsConvertScope;if(s){!0===s&&(s=p,n=void 0);for(var a=1,o=t.length;a<o;a++)t[a]=n?s.call(n,t[a],t):s(t[a],t)}return t=[i,t]}run(t){if(this.validate(t)){var e=t[1];this.lastMethodName=e[0];var i=m(e,this.scenario.scope);i&&"function"==typeof i.once?(i.once("complete",this.resume,this),this.pause(),this.task=i):this.task=void 0}else this.scenario.error(`Command '${y(t)}' is not found in scope`)}validate(t){var e=y(t);if(null===e)return!1;var i=this.scenario.scope,r=i[e];return null==r&&(r=n(i,e,null)),!!r}pause(){this.scenario.pause()}resume(){this.task=void 0;var t=this.scenario;t.resume(),t.runNextCmd()}}var y=function(t){var e=t[1];if(!e)return null;var i=e[0];return i||null};class b extends c{constructor(t){super(t,"wait")}parse(t,e){t.length=2;var i=this.getEventName(t);return isNaN(i)||(t[1]=parseFloat(i)),t}run(t){var e=this.getEventName(t);"number"==typeof e?this.waitTime(e):this.waitEvent(e)}waitTime(t){t>this.scenario.offset?(t-=this.scenario.offset,this.scenario.offset=0,this.scenario.isDebugMode&&this.scenario.log("#WAIT: "+t),this.scenario.wait(t)):this.scenario.offset-=t}waitEvent(t){this.scenario.isDebugMode&&this.scenario.log("#WAIT: "+t),this.scenario.wait(t)}getEventName(t){var e=t[1];return null==e&&(e="",t[1]=e),e}}class E extends c{constructor(t){super(t,"label"),this.labels={},this.prevLabel="",this.lastLabel=""}resetFromJSON(t){this.prevLabel=n(t,"preLabel",""),this.lastLabel=n(t,"lastLabel","");var e=n(t,"labels",void 0);void 0===e?h(this.labels):u(e,this.labels)}toJSON(){return{preLabel:this.prevLabel,lastLabel:this.lastLabel,labels:this.labels}}parse(t,e){t.length=2;var i=this.getLabel(t);return this.addLabel(i,e),t}run(t){var e=this.getLabel(t);this.scenario.isDebugMode&&this.scenario.log("#LABEL: "+e),this.prevLabel=this.lastLabel,this.lastLabel=e;var i=this.scenario;i.emit("labelchange",this.lastLabel,this.prevLabel,i.scope,i)}getLabel(t){var e=t[1];return null==e&&(e="",t[1]=e),e}addLabel(t,e){this.labels[t]=e}getIndex(t){return""!==t&&this.hasLabel(t)?this.labels[t]:0}hasLabel(t){return this.labels.hasOwnProperty(t)}}class w extends c{constructor(t){super(t,"exit")}parse(t,e){return t.length=1,t}run(t){this.scenario.log("#EXIT"),this.scenario.complete()}}class C extends c{constructor(t){super(t,"goto")}parse(t,e){return t.length=2,t}run(t){var e=this.getLabel(t);this.scenario.isDebugMode&&this.scenario.log("#GOTO label: "+e),this.scenario.goto(e)}getLabel(t){var e=t[1];return null==e&&(e="",t[1]=e),e}}class x extends c{constructor(t){super(t,"if")}parse(t,e){t.length=4;var i="("+this.getCond(t)+")";return t[1]=new Function("return "+i),t}run(t){var e=this.getCond(t).call(this.scenario.scope),i=e?this.getTrueLabel(t):this.getFalseLabel(t);""!==i&&(this.scenario.isDebugMode&&this.scenario.log("#IF "+e+"- GOTO label: "+i),this.scenario.goto(i))}getCond(t){var e=t[1];return null!=e&&""!==e||(e="true",t[1]=e),e}getTrueLabel(t){var e=t[2];return null==e&&(e="",t[2]=e),e}getFalseLabel(t){var e=t[3];return null==e&&(e="",t[3]=e),e}}class k{constructor(t){this.cmds={"-":new _(t),wait:new b(t),label:new E(t),exit:new w(t),goto:new C(t),if:new x(t)}}resetFromJSON(t){for(var e in this.cmds)this.cmds[e].resetFromJSON(n(t,e,void 0));return this}toJSON(){var t={};for(var e in this.cmds)t[e]=this.cmds[e].toJSON();return t}get(t){return this.cmds[t]}isValidCmdName(t){return this.cmds.hasOwnProperty(t)}}var S=function(t){return function(t,e){return new Promise((function(i,r){t.once(e,(function(){i()}))}))}(t,"complete")};let O=class{constructor(t){this.parent=t,this.timeScale=1,this.paused=!1,this.deltaT=10,this.timerId=null,this.timeoutCallback=null,this.time=0,this.remainingTime=0}destroy(){return this.stop(),this}start(t,e){this.time=t,this.remainingTime=t,this.timeoutCallback=e;var i=this;return this.timerId=setInterval((function(){if(!i.paused&&(i.remainingTime-=i.deltaT*i.timeScale,i.remainingTime<=0&&(i.stop(),i.timeoutCallback))){var t=i.timeoutCallback;i.timeoutCallback=null,t()}}),i.deltaT),this}stop(){return clearInterval(this.timerId),this.timerId=null,this}pause(){return this.paused=!0,this}resume(){return this.paused=!1,this}setTimeScale(t){return this.timeScale=t,this}};class L{constructor(t,e){void 0===t&&(t={}),this.parent=t,this.setEventEmitter(n(e,"eventEmitter",void 0)),this.timer=this.createTimer(t,e),this._timeScale=1,this.instMem=new l(this),this.cmdHandlers=new k(this),this.resetFromJSON(e),this.boot(t,e)}boot(t,e){return this}createTimer(t,e){return new O(t)}resetFromJSON(t){return this._inRunCmdLoop=!1,this.isRunning=n(t,"state",!1),this.isPaused=n(t,"pause",!1),this.waitEvent=n(t,"wait",void 0),this.scope=n(t,"scope",void 0),this.timeUnit=n(t,"timeUnit",0),this.cmdPrefix=n(t,"prefix",I),this.argsConvert=n(t,"argsConvert",!0),this.argsConvertScope=n(t,"argsConvertScope",void 0),this.cmdHandlers.resetFromJSON(n(t,"handlers",void 0)),this.instMem.resetFromJSON(n(t,"instMem",void 0)),this.delimiter=n(t,"delimiter",","),this.translateCommandNameCallback=n(t,"translateCommandNameCallback",void 0),this}toJSON(){return{state:this.isRunning,pause:this.isPaused,wait:this.waitEvent,scope:this.scope,timeUnit:this.timeUnit,prefix:this.cmdPrefix,argsConvert:this.argsConvert,argsConvertScope:this.argsConvertScope,handlers:this.cmdHandlers.toJSON(),instMem:this.instMem.toJSON(),delimiter:this.delimiter}}shutdown(){this.parent&&(this.destroyEventEmitter(),this.clear(),this.timer.destroy(),this.parent=void 0)}destroy(){this.shutdown()}load(t,e,i){return this.clear(),this.timeUnit=n(i,"timeUnit",this.timeUnit),"string"==typeof this.timeUnit&&(this.timeUnit=R[this.timeUnit]),this.cmdPrefix=n(i,"prefix",this.cmdPrefix),"string"==typeof this.cmdPrefix&&(this.cmdPrefix=new RegExp(this.cmdPrefix)),this.argsConvert=n(i,"argsConvert",this.argsConvert),this.argsConvertScope=n(i,"argsConvertScope",this.argsConvertScope),this.scope=e,this.delimiter=n(i,"delimiter",this.delimiter),this.translateCommandNameCallback=n(i,"translateCommandNameCallback",this.translateCommandNameCallback),this.append(t),this}clear(){this.stop(),this.instMem.resetFromJSON(),this.cmdHandlers.resetFromJSON()}start(t){this.stop();var e=n(t,"label","");return this.offset=n(t,"offset",0),this.isDebugMode&&this.log("Start at Label: "+e),!!this.goto(e)&&(this.isRunning=!0,this.runNextCmd(),!0)}play(t){return this.start(t),this}playPromise(t){var e=S(this);return this.start(t),e}getIndex(t){var e=this.getCmdHandler("label").getIndex(t);return null==e&&this.error(`Label: ${t} is not found`),e}goto(t){var e;return null!=(e="string"==typeof t?this.getIndex(t):t)&&(this.instMem.setNextIndex(e),!0)}get timeScale(){return this._timeScale}set timeScale(t){this._timeScale=t,this.timer.setTimeScale(t)}setTimeScale(t){return this.timeScale=t,this}wait(t){if(this.waitEvent=t,"number"==typeof t){var e=t;1===this.timeUnit&&(e*=1e3);var i=this;this.timer.start(e,(function(){i.continue(t)}))}else this.emit(`wait.${t}`,this);return this.emit("wait",t,this),this}stop(){return this.isRunning?(this.isRunning=!1,this.isPaused=!1,this.waitEvent=void 0,this.timer.stop(),this):this}complete(){return this.emit("complete",this.scope,this),this.stop(),this}append(t){var e=o.parse(t,{delimiter:this.delimiter}).data;return this.parse(e),this}pause(){return this.isRunning?(this.isPaused||(this.isPaused=!0,this.timer.pause()),this):this}resume(){return this.isRunning&&this.isPaused?(this.isPaused=!1,this.timer.resume(),this):this}continue(t){return!this.isRunning||this.isPaused||void 0===this.waitEvent||!0!==t&&t!==this.waitEvent||(this.waitEvent=void 0,this.runNextCmd()),this}get lastLabel(){return this.cmdHandlers.cmds.label.lastLabel}get previousLabel(){return this.cmdHandlers.cmds.label.prevLabel}get lastCustomCommandName(){return this.cmdHandlers.cmds["-"].lastMethodName}getCmdHandler(t){return"string"!=typeof t&&(t=t[0]),this.cmdHandlers.get(t)}parse(t){for(var e,i,r=this.cmdPrefix,s=0,n=t.length;s<n;s++)if("-"===(i=(e=t[s])[0]))this.appendCustomCommand(e);else if(isNaN(i))if(r.test(i)){var a=i.match(r);e[0]=a[1].toLowerCase(),this.appendCommand(e)||this.error(`Line ${s}: ${JSON.stringify(e)} is not a valid command`)}else this.appendCommand(["wait",i]),e[0]="-",this.appendCommand(e);else{var o=parseFloat(i);o>0&&this.appendCommand(["wait",o]),this.appendCustomCommand(e)}return this}appendCommand(t){var e=this.getCmdHandler(t);return null!=e&&((t=e.parse(t,this.instMem.length))&&this.instMem.append(t),!0)}appendCustomCommand(t){return t[0]="-",this.translateCommandNameCallback&&(t[1]=this.translateCommandNameCallback(t[1])),this.appendCommand(t)}runNextCmd(){if(!this._inRunCmdLoop){var t,e=this.instMem;for(this._inRunCmdLoop=!0;this.isRunning&&!this.isPaused&&void 0===this.waitEvent;){if(t=e.get(),e.setNextIndex(),null==t){this.complete();break}this.getCmdHandler(t).run(t)}return this._inRunCmdLoop=!1,this}}log(t){return this.emit("log",t,this.scope,this),this}get isDebugMode(){return this.listenerCount("log")>0}error(t){return this.emit("error",t,this.scope,this),this}}Object.assign(L.prototype,s);const R={ms:0,s:1,sec:1},I=/^#([a-zA-Z]+)/;class T{constructor(t){this.scene=t,this.timeScale=1,this.timer=null}destroy(){return this.stop(),this}start(t,e){return this.timer&&(this.timer.remove(),this.timer=void 0),this.timer=this.scene.time.delayedCall(t,e),this.timer.timeScale=this.timeScale,this}stop(){return this.timer&&(this.timer.remove(),this.timer=void 0),this}pause(){return this.timer&&(this.timer.paused=!0),this}resume(){return this.timer&&(this.timer.paused=!1),this}setTimeScale(t){return this.timeScale=t,this.timer&&(this.timer.timeScale=t),this}}class N extends L{constructor(t,e){super(t,e)}boot(t,e){return t.sys.events.once("shutdown",this.destroy,this),super.boot(t,e),this}createTimer(t,e){return new T(t)}}class A extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new N(t,e)}}return A}));