text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rextoonifypipelineplugin=t()}(this,function(){"use strict";function a(e){return(a="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})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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)}}function i(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function u(r){var o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=l(r);if(o){var n=l(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return f(this,e)}}function c(e){return null==e||""===e||0===e.length}var e=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,t=Phaser.Utils.Objects.GetValue,v=Phaser.Display.Color.IntegerToRGB,h=Phaser.Display.Color,p=function(){s(r,e);var n=u(r);function r(e){var t;return o(this,r),(t=n.call(this,{game:e,renderTarget:!0,fragShader:"#ifdef GL_FRAGMENT_PRECISION_HIGH\n#define highmedp highp\n#else\n#define highmedp mediump\n#endif\nprecision highmedp float;\n\n// Scene buffer\nuniform sampler2D uMainSampler; \nvarying vec2 outTexCoord;\nuniform vec2 texSize;\n\n// Effect parameters\nuniform float edgeThreshold; // 0.2;\nuniform float hStep;  // 60\nuniform float sStep;  // 0.15\nuniform float vStep;  // 0.33\nuniform vec3 edgeColor; // (0, 0, 0);\nvec3 RGBToHSV(vec3 color) {\n  float minv, maxv, delta;\n  vec3 res;\n  minv = min(min(color.r, color.g), color.b);\n  maxv = max(max(color.r, color.g), color.b);\n  res.z = maxv;            // v\n\n  delta = maxv - minv;\n  if( maxv != 0.0 ) {\n    res.y = delta / maxv;      // s\n  } else {\n    // s = 0, v is undefined\n    res.y = 0.0;\n    res.x = -1.0;\n    return res;\n  }\n\n  if( color.r == maxv ) {\n    res.x = ( color.g - color.b ) / delta;      // between yellow & magenta\n  } else if( color.g == maxv ) {\n    res.x = 2.0 + ( color.b - color.r ) / delta;   // between cyan & yellow\n  } else {\n    res.x = 4.0 + ( color.r - color.g ) / delta;   // between magenta & cyan\n  }\n\n  res.x = res.x * 60.0;            // degrees\n  if( res.x < 0.0 ) {\n    res.x = res.x + 360.0;\n  }\n   \n  return res;\n}\nfloat AvgRGB(vec4 color) {\n  return (color.r + color.g + color.b)/3.0;\n}\n#define EDGEGAIN 5.0\nbool IsEdge(vec2 coords, vec2 texSize, float threshold) {\n  if (threshold > 1.0) {\n    return false;\n  }\n\n  vec2 tc = coords * texSize;\n  \n  float pixel[9];\n  int k = 0;\n  float delta;\n\n  // read neighboring pixel intensities\n  pixel[0] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float(-1), float(-1))) / texSize )  );\n  pixel[1] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float(-1), float( 0))) / texSize )  );\n  pixel[2] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float(-1), float( 1))) / texSize )  );\n  pixel[3] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 0), float(-1))) / texSize )  );\n  pixel[4] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 0), float( 0))) / texSize )  );\n  pixel[5] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 0), float( 1))) / texSize )  );\n  pixel[6] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 1), float(-1))) / texSize )  );\n  pixel[7] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 1), float( 0))) / texSize )  );\n  pixel[8] = AvgRGB( texture2D( uMainSampler, (tc + vec2(float( 1), float( 1))) / texSize )  );\n\n  // average color differences around neighboring pixels\n  delta = (abs(pixel[1]-pixel[7])+\n           abs(pixel[5]-pixel[3]) +\n           abs(pixel[0]-pixel[8])+\n           abs(pixel[2]-pixel[6])\n           )/4.0;\n\n  return (clamp(delta*EDGEGAIN, 0.0, 1.0) >= threshold);\n}\nvec3 HSVToRGB(float h, float s, float v) {\n  int i;\n  float f, p, q, t;\n  vec3 res;\n  if( s == 0.0 ) {\n    // achromatic (grey)\n    res.x = v;\n    res.y = v;\n    res.z = v;\n    return res;\n  }\n\n  h /= 60.0;         // sector 0 to 5\n  i = int(floor( h ));\n  f = h - float(i);         // factorial part of h\n  p = v * ( 1.0 - s );\n  q = v * ( 1.0 - s * f );\n  t = v * ( 1.0 - s * ( 1.0 - f ) );  \n  if (i == 0) {\n    res.x = v;\n    res.y = t;\n    res.z = p;\n  } else if (i == 1) {\n    res.x = q;\n    res.y = v;\n    res.z = p;\n  } else if (i == 2) {\n    res.x = p;\n    res.y = v;\n    res.z = t;\n  } else if (i == 3) {\n    res.x = p;\n    res.y = q;\n    res.z = v;\n  } else if (i == 4) {\n    res.x = t;\n    res.y = p;\n    res.z = v;\n  } else { // i == 5\n    res.x = v;\n    res.y = p;\n    res.z = q;\n  }\n  return res;\n}\n\nvoid main() {\n  vec4 front = texture2D(uMainSampler, outTexCoord);  \n  vec3 colorLevel;\n  if ((hStep > 0.0) || (sStep > 0.0) || (vStep > 0.0)) {\n    vec3 colorHsv = RGBToHSV(front.rgb);  \n    if (hStep > 0.0) {\n      colorHsv.x = min(floor((colorHsv.x / hStep) + 0.5) * hStep, 360.0);\n    }\n    if (sStep > 0.0) {\n      colorHsv.y = min(floor((colorHsv.y / sStep) + 0.5) * sStep, 1.0);\n    }\n    if (vStep > 0.0) {\n      colorHsv.z = min(floor((colorHsv.z / vStep) + 0.5) * vStep, 1.0);\n    }\n    colorLevel = HSVToRGB(colorHsv.x, colorHsv.y, colorHsv.z);\n  } else {\n    colorLevel = front.rgb;\n  }\n\n  vec3 outColor = (IsEdge(outTexCoord, texSize, edgeThreshold))? edgeColor : colorLevel;\n  gl_FragColor = vec4(outColor, front.a);\n}\n"}))._edgeGain=0,t._edgeThreshold=0,t._hueLevels=0,t._satLevels=0,t._valLevels=0,t._edgeColor=new h,t}return i(r,[{key:"resetFromJSON",value:function(e){return this.setEdgeThreshold(t(e,"edgeThreshold",.2)),this.setHueLevels(t(e,"hueLevels",0)),this.setSatLevels(t(e,"satLevels",0)),this.setValLevels(t(e,"valLevels",0)),this.setEdgeColor(t(e,"edgeColor",0)),this}},{key:"onPreRender",value:function(){this.set1f("edgeThreshold",this._edgeThreshold),this.set1f("hStep",this.hueStep),this.set1f("sStep",this.satStep),this.set1f("vStep",this.valStep),this.set3f("edgeColor",this._edgeColor.redGL,this._edgeColor.greenGL,this._edgeColor.blueGL),this.set2f("texSize",this.renderer.width,this.renderer.height)}},{key:"setEdgeThreshold",value:function(e){return this.edgeThreshold=e,this}},{key:"setHueLevels",value:function(e){return this.hueLevels=e,this}},{key:"setSatLevels",value:function(e){return this.satLevels=e,this}},{key:"setValLevels",value:function(e){return this.valLevels=e,this}},{key:"setEdgeColor",value:function(e){return this.edgeColor=e,this}},{key:"edgeThreshold",get:function(){return this._edgeThreshold},set:function(e){this._edgeThreshold=e}},{key:"hueLevels",get:function(){return this._hueLevels},set:function(e){this._hueLevels=e}},{key:"hueStep",get:function(){return 0<this._hueLevels?360/this._hueLevels:0}},{key:"satLevels",get:function(){return this._satLevels},set:function(e){this._satLevels=e}},{key:"satStep",get:function(){return 0<this._satLevels?1/this._satLevels:0}},{key:"valLevels",get:function(){return this._valLevels},set:function(e){this._valLevels=e}},{key:"valStep",get:function(){return 0<this._valLevels?1/this._valLevels:0}},{key:"edgeColor",get:function(){return this._edgeColor},set:function(e){"number"==typeof e&&(e=v(e)),this._edgeColor.setFromRGB(e)}}]),r}(),d=Phaser.Utils.Array.SpliceOne,g=function(){s(t,Phaser.Plugins.BasePlugin);var e=u(t);function t(){return o(this,t),e.apply(this,arguments)}return i(t,[{key:"setPostPipelineClass",value:function(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}},{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this),this.game.renderer.pipelines.addPostPipeline(this.postFxPipelineName,this.PostFxPipelineClass)}},{key:"add",value:function(e,t){e.setPostPipeline(this.PostFxPipelineClass);var n=e.postPipelines[e.postPipelines.length-1];return n.resetFromJSON(t),n}},{key:"remove",value:function(e,t){if(void 0===t){for(var n=(r=e.postPipelines).length-1;0<=n;n--){(i=r[n])instanceof this.PostFxPipelineClass&&(i.destroy(),d(r,n))}return[]}n=0;for(var r,o=(r=e.postPipelines).length;n<o;n++){var i;(i=r[n]).name===t&&(i.destroy(),d(r,n))}}},{key:"get",value:function(e,t){if(void 0===t){for(var n=[],r=0,o=(i=e.postPipelines).length;r<o;r++){(s=i[r])instanceof this.PostFxPipelineClass&&n.push(s)}return n}var i;for(r=0,o=(i=e.postPipelines).length;r<o;r++){var s;if((s=i[r]).name===t)return s}}}]),t}(),x=function(){s(r,g);var n=u(r);function r(e){var t;return o(this,r),(t=n.call(this,e)).setPostPipelineClass(p,"rexToonifyPostFx"),t}return r}();return function(e,t,n){if("object"===a(e)){if(c(t)){if(null==n)return;"object"===a(n)&&(e=n)}else{"string"==typeof t&&(t=t.split("."));var r=t.pop();(function(e,t,n){var r=e;if(!c(t)){var o;"string"==typeof t&&(t=t.split("."));for(var i=0,s=t.length;i<s;i++){var l;if(null==r[o=t[i]]||"object"!==a(r[o]))l=i!==s-1||void 0===n?{}:n,r[o]=l;r=r[o]}}return r})(e,t)[r]=n}}}(window,"RexPlugins.Pipelines.ToonifyPostFx",p),x});
  