!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).triangulate=n()}(this,function(){"use strict";function o(t,n,e){return t';var c=t.gradient.colors.length-1;t.gradient.colors.forEach(function(t,n){var e=b(t),a=t.a<1?' stop-opacity="'+t.a+'"':"",r=(n/c*100).toFixed(3);y+='\n\t\t\t\t\t\n\t\t\t\t"}),y+="",p+=' fill="url(#gradient-'+n+')"',0\n\n\t'+y+"\n\t"+p+"\n"}function a(t,n){return t(n={exports:{}},n.exports),n.exports}var c=a(function(t){function x(t,n,e){this.a=t,this.b=n,this.c=e;var a,r,o,i,u=n.x-t.x,s=n.y-t.y,h=e.x-t.x,c=e.y-t.y,l=u*(t.x+n.x)+s*(t.y+n.y),f=h*(t.x+e.x)+c*(t.y+e.y),d=2*(u*(e.y-n.y)-s*(e.x-n.x));Math.abs(d)<1e-6?(a=Math.min(t.x,n.x,e.x),r=Math.min(t.y,n.y,e.y),o=.5*(Math.max(t.x,n.x,e.x)-a),i=.5*(Math.max(t.y,n.y,e.y)-r),this.x=a+o,this.y=r+i):(this.x=(c*l-s*f)/d,this.y=(u*f-h*l)/d,o=this.x-t.x,i=this.y-t.y),this.r=o*o+i*i}function m(t,n){return n.x-t.x}function v(t){var n,e,a,r,o,i=t.length;t:for(;i;)for(e=t[--i],n=t[--i],a=i;a;)if(o=t[--a],n===(r=t[--a])&&e===o||n===o&&e===r){t.splice(i,2),t.splice(a,2),i-=2;continue t}}x.prototype.draw=function(t){t.beginPath(),t.moveTo(this.a.x,this.a.y),t.lineTo(this.b.x,this.b.y),t.lineTo(this.c.x,this.c.y),t.closePath(),t.stroke()},t.exports={Triangle:x,triangulate:function(t){if(t.length<3)return[];t.sort(m);for(var n=t.length-1,e=t[n].x,a=t[0].x,r=t[n].y,o=r;n--;)t[n].yo&&(o=t[n].y);var i,u,s,h=a-e,c=o-r,l=cg[i].r?(y.push(g[i]),g.splice(i,1)):h*h+(c=t[n].y-g[i].y)*c>g[i].r||(p.push(g[i].a,g[i].b,g[i].b,g[i].c,g[i].c,g[i].a),g.splice(i,1));for(v(p),i=p.length;i;)s=p[--i],u=p[--i],g.push(new x(u,s,t[n]))}for(Array.prototype.push.apply(y,g),n=y.length;n--;)(y[n].a.__sentinel||y[n].b.__sentinel||y[n].c.__sentinel)&&y.splice(n,1);return y}}}),l=(c.Triangle,c.triangulate),f=a(function(t,n){function p(t){if(!(this instanceof p))return new p(t);var r=t.width,n=t.height,e=[[-1,0,1],[-2,0,2],[-1,0,1]],a=[[-1,-2,-1],[0,0,0],[1,2,1]],o=[],i=[];function u(a){return function(t,n,e){return a[4*(r*n+t)+(e=e||0)]}}var s,h,c=u(t.data);for(h=0;h>>0;o.push(g,g,g,255)}var y=o;return"function"==typeof Uint8ClampedArray&&(y=new Uint8ClampedArray(o)),y.toImageData=function(){return p.toImageData(y,r,n)},y}function o(t,n,e){return{width:n,height:e,data:t}}p.toImageData=function(t,n,e){if("function"==typeof ImageData&&"[object Uint16Array]"===Object.prototype.toString.call(t))return new ImageData(t,n,e);if("object"!=typeof window||"object"!=typeof window.document)return new o(t,n,e);var a=document.createElement("canvas");if("function"!=typeof a.getContext)return new o(t,n,e);var r=a.getContext("2d").createImageData(n,e);return r.data.set(t),r},t.exports&&(n=t.exports=p),n.Sobel=p});f.Sobel;function d(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}function g(n){if(d(n)){if("undefined"==typeof Uint8ClampedArray){if("undefined"==typeof window)throw new Error("Can't copy imageData in webworker without Uint8ClampedArray support.");return y(n)}var e,t=new Uint8ClampedArray(n.data);if("undefined"==typeof ImageData)return{width:n.width,height:n.height,data:t};try{e=new ImageData(t,n.width,n.height)}catch(t){if("undefined"==typeof window)throw new Error("Can't copy imageData in webworker without proper ImageData() support.");e=y(n)}return e}throw new Error("Given imageData object is not useable.")}function y(t){var n=new u(t.width,t.height).getContext("2d");return n.putImageData(t,0,0),n.getImageData(0,0,t.width,t.height)}var G=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],V=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function q(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}function D(t,n,e){var a=t+"|"+n;e[a]||(e[a]={x:t,y:n}),a=null}function k(t){return t.forEach(function(t){var n,e,a,r,o;t.boundingBox=(n=[t.a,t.b,t.c],r=e=1/0,o=a=-1/0,n.forEach(function(t){t.xa&&(a=t.x),t.y>o&&(o=t.y)}),{x:e,y:r,width:a-e,height:o-r})}),t.filter(function(t){return 0=n.data.length&&(a=n.data.length-5);var r=n.data[a+3]/255;return e&&0==r?e:{r:n.data[a],g:n.data[a+1],b:n.data[a+2],a:r}}function E(t){return{x:.33333*(t.a.x+t.b.x+t.c.x),y:.33333*(t.a.y+t.b.y+t.c.y)}}function I(t){return 0===t.a}function S(t){var n=function(t){if("string"==typeof t){var n=[0,0,0,0];return"#"===t[0]&&(t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(4>N,0!=E?(E=255/E,S[h]=(l*O>>N)*E,S[h+1]=(f*O>>N)*E,S[h+2]=(d*O>>N)*E):S[h]=S[h+1]=S[h+2]=0,l-=y,f-=p,d-=x,g-=m,y-=U.r,p-=U.g,x-=U.b,m-=U.a,u=c+((u=r+a+1)>N,0>N)*E,S[u+1]=(f*O>>N)*E,S[u+2]=(d*O>>N)*E):S[u]=S[u+1]=S[u+2]=0,l-=y,f-=p,d-=x,g-=m,y-=U.r,p-=U.g,x-=U.b,m-=U.a,u=r+((u=o+P)o&&(o=t[a].y);var i,s,u,h=n-e,c=o-r,l=cf[i].r?(y.push(f[i]),f.splice(i,1)):h*h+(c=t[a].y-f[i].y)*c>f[i].r||(p.push(f[i].a,f[i].b,f[i].b,f[i].c,f[i].c,f[i].a),f.splice(i,1));for(v(p),i=p.length;i;)u=p[--i],s=p[--i],f.push(new m(s,u,t[a]))}for(Array.prototype.push.apply(y,f),a=y.length;a--;)(y[a].a.__sentinel||y[a].b.__sentinel||y[a].c.__sentinel)&&y.splice(a,1);return y}}}),delaunay_1=delaunay.Triangle,delaunay_2=delaunay.triangulate,sobel=createCommonjsModule(function(t,a){function p(t){if(!(this instanceof p))return new p(t);var r=t.width,a=t.height,e=[[-1,0,1],[-2,0,2],[-1,0,1]],n=[[-1,-2,-1],[0,0,0],[1,2,1]],o=[],i=[];function s(n){return function(t,a,e){return n[4*(r*a+t)+(e=e||0)]}}var u,h,c=s(t.data);for(h=0;h>>0;o.push(f,f,f,255)}var y=o;return"function"==typeof Uint8ClampedArray&&(y=new Uint8ClampedArray(o)),y.toImageData=function(){return p.toImageData(y,r,a)},y}function o(t,a,e){return{width:a,height:e,data:t}}p.toImageData=function(t,a,e){if("function"==typeof ImageData&&"[object Uint16Array]"===Object.prototype.toString.call(t))return new ImageData(t,a,e);if("object"!=typeof window||"object"!=typeof window.document)return new o(t,a,e);var n=document.createElement("canvas");if("function"!=typeof n.getContext)return new o(t,a,e);var r=n.getContext("2d").createImageData(a,e);return r.data.set(t),r},t.exports&&(a=t.exports=p),a.Sobel=p}),sobel_1=sobel.Sobel;function isImageData(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}var Canvas=function(t,a){void 0===t&&(t=300),void 0===a&&(a=150),"undefined"==typeof window?(this.canvasEl={width:t,height:a},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=a,this.ctx=this.canvasEl.getContext("2d"))},prototypeAccessors={width:{configurable:!0},height:{configurable:!0}};function copyImageData(a){if(isImageData(a)){if("undefined"==typeof Uint8ClampedArray){if("undefined"==typeof window)throw new Error("Can\'t copy imageData in webworker without Uint8ClampedArray support.");return copyImageDataWithCanvas(a)}var e,t=new Uint8ClampedArray(a.data);if("undefined"==typeof ImageData)return{width:a.width,height:a.height,data:t};try{e=new ImageData(t,a.width,a.height)}catch(t){if("undefined"==typeof window)throw new Error("Can\'t copy imageData in webworker without proper ImageData() support.");e=copyImageDataWithCanvas(a)}return e}throw new Error("Given imageData object is not useable.")}function copyImageDataWithCanvas(t){var a=new Canvas(t.width,t.height).getContext("2d");return a.putImageData(t,0,0),a.getImageData(0,0,t.width,t.height)}Canvas.prototype.getContext=function(){return this.ctx},Canvas.prototype.toDataURL=function(t,a,e){if("function"!=typeof e)return this.canvasEl.toDataURL(t,a);e(this.canvasEl.toDataURL(t,a))},prototypeAccessors.width.get=function(){return this.canvasEl.width},prototypeAccessors.width.set=function(t){this.canvasEl.width=t},prototypeAccessors.height.get=function(){return this.canvasEl.height},prototypeAccessors.height.set=function(t){this.canvasEl.height=t},Object.defineProperties(Canvas.prototype,prototypeAccessors),"undefined"!=typeof window&&(Canvas.Image=Image);var mul_table=[512,512,456,512,328,456,335,512,405,328,271,456,388,335,292,512,454,405,364,328,298,271,496,456,420,388,360,335,312,292,273,512,482,454,428,405,383,364,345,328,312,298,284,271,259,496,475,456,437,420,404,388,374,360,347,335,323,312,302,292,282,273,265,512,497,482,468,454,441,428,417,405,394,383,373,364,354,345,337,328,320,312,305,298,291,284,278,271,265,259,507,496,485,475,465,456,446,437,428,420,412,404,396,388,381,374,367,360,354,347,341,335,329,323,318,312,307,302,297,292,287,282,278,273,269,265,261,512,505,497,489,482,475,468,461,454,447,441,435,428,422,417,411,405,399,394,389,383,378,373,368,364,359,354,350,345,341,337,332,328,324,320,316,312,309,305,301,298,294,291,287,284,281,278,274,271,268,265,262,259,257,507,501,496,491,485,480,475,470,465,460,456,451,446,442,437,433,428,424,420,416,412,408,404,400,396,392,388,385,381,377,374,370,367,363,360,357,354,350,347,344,341,338,335,332,329,326,323,320,318,315,312,310,307,304,302,299,297,294,292,289,287,285,282,280,278,275,273,271,269,267,265,263,261,259],shg_table=[9,11,12,13,13,14,14,15,15,15,15,16,16,16,16,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24];function BlurStack(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}function stackblur(t,a,e,n,r,o){var i,s,u,h,c,l,d,g,f,y,p,m,x,v,b,w,C,D,I,E,M,P,T,B,_=t.data,k=o+o+1,A=n-1,j=r-1,S=o+1,U=S*(S+1)/2,V=new BlurStack,W=V;for(u=1;u>G,0!=T?(T=255/T,_[l]=(g*q>>G)*T,_[l+1]=(f*q>>G)*T,_[l+2]=(y*q>>G)*T):_[l]=_[l+1]=_[l+2]=0,g-=m,f-=x,y-=v,p-=b,m-=J.r,x-=J.g,v-=J.b,b-=J.a,h=d+((h=i+o+1)>G,0>G)*T,_[h+1]=(f*q>>G)*T,_[h+2]=(y*q>>G)*T):_[h]=_[h+1]=_[h+2]=0,g-=m,f-=x,y-=v,p-=b,m-=J.r,x-=J.g,v-=J.b,b-=J.a,h=i+((h=s+S)e&&(e=t.x),t.y>r&&(r=t.y)}),{x:a,y:n,width:e-a,height:r-n}}function addBoundingBoxesToPolygons(t,a,e){return t.forEach(function(t){t.boundingBox=getBoundingBox([t.a,t.b,t.c])}),t.filter(function(t){return 0=a.data.length&&(n=a.data.length-5);var r=a.data[n+3]/255;return e&&0==r?e:{r:a.data[n],g:a.data[n+1],b:a.data[n+2],a:r}}function polygonCenter(t){return{x:.33333*(t.a.x+t.b.x+t.c.x),y:.33333*(t.a.y+t.b.y+t.c.y)}}function isTransparent(t){return 0===t.a}function strToColorArr(t){if("string"==typeof t){var a=[0,0,0,0];return"#"===t[0]&&(t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(4