!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).triangulate=e()}(this,function(){"use strict";function o(t,e,n){return t';var f=t.gradient.colors.length-1;t.gradient.colors.forEach(function(t,e){var n=w(t),r=t.a<1?' stop-opacity="'+t.a+'"':"",a=(e/f*100).toFixed(3);y+='\n\t\t\t\t\t\n\t\t\t\t"}),y+="",p+=' fill="url(#gradient-'+e+')"',0\n\n\t'+y+"\n\t"+p+"\n"}var rt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function at(){throw new Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}function r(t,e){return t(e={exports:{}},e.exports),e.exports}var d=r(function(t){function v(t,e,n){this.a=t,this.b=e,this.c=n;var r,a,o,i,s=e.x-t.x,u=e.y-t.y,c=n.x-t.x,f=n.y-t.y,l=s*(t.x+e.x)+u*(t.y+e.y),h=c*(t.x+n.x)+f*(t.y+n.y),d=2*(s*(n.y-e.y)-u*(n.x-e.x));Math.abs(d)<1e-6?(r=Math.min(t.x,e.x,n.x),a=Math.min(t.y,e.y,n.y),o=.5*(Math.max(t.x,e.x,n.x)-r),i=.5*(Math.max(t.y,e.y,n.y)-a),this.x=r+o,this.y=a+i):(this.x=(f*l-u*h)/d,this.y=(s*h-c*l)/d,o=this.x-t.x,i=this.y-t.y),this.r=o*o+i*i}function m(t,e){return e.x-t.x}function b(t){var e,n,r,a,o,i=t.length;t:for(;i;)for(n=t[--i],e=t[--i],r=i;r;)if(o=t[--r],e===(a=t[--r])&&n===o||e===o&&n===a){t.splice(i,2),t.splice(r,2),i-=2;continue t}}v.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:v,triangulate:function(t){if(t.length<3)return[];t.sort(m);for(var e=t.length-1,n=t[e].x,r=t[0].x,a=t[e].y,o=a;e--;)t[e].yo&&(o=t[e].y);var i,s,u,c=r-n,f=o-a,l=fg[i].r?(y.push(g[i]),g.splice(i,1)):c*c+(f=t[e].y-g[i].y)*f>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(b(p),i=p.length;i;)u=p[--i],s=p[--i],g.push(new v(s,u,t[e]))}for(Array.prototype.push.apply(y,g),e=y.length;e--;)(y[e].a.__sentinel||y[e].b.__sentinel||y[e].c.__sentinel)&&y.splice(e,1);return y}}}),g=(d.Triangle,d.triangulate),y=r(function(t,e){function p(t){if(!(this instanceof p))return new p(t);var a=t.width,e=t.height,n=[[-1,0,1],[-2,0,2],[-1,0,1]],r=[[-1,-2,-1],[0,0,0],[1,2,1]],o=[],i=[];function s(r){return function(t,e,n){return r[4*(a*e+t)+(n=n||0)]}}var u,c,f=s(t.data);for(c=0;c>>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,a,e)},y}function o(t,e,n){return{width:e,height:n,data:t}}p.toImageData=function(t,e,n){if("function"==typeof ImageData&&"[object Uint16Array]"===Object.prototype.toString.call(t))return new ImageData(t,e,n);if("object"!=typeof window||"object"!=typeof window.document)return new o(t,e,n);var r=document.createElement("canvas");if("function"!=typeof r.getContext)return new o(t,e,n);var a=r.getContext("2d").createImageData(e,n);return a.data.set(t),a},t.exports&&(e=t.exports=p),e.Sobel=p});y.Sobel;function E(t){return t&&"number"==typeof t.width&&"number"==typeof t.height&&t.data&&"number"==typeof t.data.length&&"object"==typeof t.data}function _(e){if(E(e)){if("undefined"==typeof Uint8ClampedArray){if("undefined"==typeof window)throw new Error("Can't copy imageData in webworker without Uint8ClampedArray support.");return j(e)}var n,t=new Uint8ClampedArray(e.data);if("undefined"==typeof ImageData)return{width:e.width,height:e.height,data:t};try{n=new ImageData(t,e.width,e.height)}catch(t){if("undefined"==typeof window)throw new Error("Can't copy imageData in webworker without proper ImageData() support.");n=j(e)}return n}throw new Error("Given imageData object is not useable.")}function j(t){var e=new s(t.width,t.height).getContext("2d");return e.putImageData(t,0,0),e.getImageData(0,0,t.width,t.height)}var B=[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],q=[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 R(){this.r=0,this.g=0,this.b=0,this.a=0,this.next=null}function T(t,e,n){var r=t+"|"+e;n[r]||(n[r]={x:t,y:e}),r=null}function S(t){return t.forEach(function(t){var e,n,r,a,o;t.boundingBox=(e=[t.a,t.b,t.c],a=n=1/0,o=r=-1/0,e.forEach(function(t){t.xr&&(r=t.x),t.y>o&&(o=t.y)}),{x:n,y:a,width:r-n,height:o-a})}),t.filter(function(t){return 0=e.data.length&&(r=e.data.length-5);var a=e.data[r+3]/255;return n&&0==a?n:{r:e.data[r],g:e.data[r+1],b:e.data[r+2],a:a}}function O(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 k(t){return 0===t.a}function I(t){var e=function(t){if("string"==typeof t){var e=[0,0,0,0];return"#"===t[0]&&(t.length<7&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(4>U,0!=T?(T=255/T,D[c]=(l*W>>U)*T,D[c+1]=(h*W>>U)*T,D[c+2]=(d*W>>U)*T):D[c]=D[c+1]=D[c+2]=0,l-=y,h-=p,d-=v,g-=m,y-=L.r,p-=L.g,v-=L.b,m-=L.a,s=f+((s=a+r+1)>U,0>U)*T,D[s+1]=(h*W>>U)*T,D[s+2]=(d*W>>U)*T):D[s]=D[s+1]=D[s+2]=0,l-=y,h-=p,d-=v,g-=m,y-=L.r,p-=L.g,v-=L.b,m-=L.a,s=a+((s=o+P)o&&(o=t[e].y);var i,s,u,c=n-a,h=o-r,l=hf[i].r?(y.push(f[i]),f.splice(i,1)):c*c+(h=t[e].y-f[i].y)*h>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(b(p),i=p.length;i;)u=p[--i],s=p[--i],f.push(new m(s,u,t[e]))}for(Array.prototype.push.apply(y,f),e=y.length;e--;)(y[e].a.__sentinel||y[e].b.__sentinel||y[e].c.__sentinel)&&y.splice(e,1);return y}}}),delaunay_1=delaunay.Triangle,delaunay_2=delaunay.triangulate,sobel=createCommonjsModule(function(t,e){function p(t){if(!(this instanceof p))return new p(t);var r=t.width,e=t.height,a=[[-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,e,a){return n[4*(r*e+t)+(a=a||0)]}}var u,c,h=s(t.data);for(c=0;c>>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,e)},y}function o(t,e,a){return{width:e,height:a,data:t}}p.toImageData=function(t,e,a){if("function"==typeof ImageData&&"[object Uint16Array]"===Object.prototype.toString.call(t))return new ImageData(t,e,a);if("object"!=typeof window||"object"!=typeof window.document)return new o(t,e,a);var n=document.createElement("canvas");if("function"!=typeof n.getContext)return new o(t,e,a);var r=n.getContext("2d").createImageData(e,a);return r.data.set(t),r},t.exports&&(e=t.exports=p),e.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,e){void 0===t&&(t=300),void 0===e&&(e=150),"undefined"==typeof window?(this.canvasEl={width:t,height:e},this.ctx=null):(this.canvasEl=document.createElement("canvas"),this.canvasEl.width=t,this.canvasEl.height=e,this.ctx=this.canvasEl.getContext("2d"))},prototypeAccessors={width:{configurable:!0},height:{configurable:!0}};function copyImageData(e){if(isImageData(e)){if("undefined"==typeof Uint8ClampedArray){if("undefined"==typeof window)throw new Error("Can\'t copy imageData in webworker without Uint8ClampedArray support.");return copyImageDataWithCanvas(e)}var a,t=new Uint8ClampedArray(e.data);if("undefined"==typeof ImageData)return{width:e.width,height:e.height,data:t};try{a=new ImageData(t,e.width,e.height)}catch(t){if("undefined"==typeof window)throw new Error("Can\'t copy imageData in webworker without proper ImageData() support.");a=copyImageDataWithCanvas(e)}return a}throw new Error("Given imageData object is not useable.")}function copyImageDataWithCanvas(t){var e=new Canvas(t.width,t.height).getContext("2d");return e.putImageData(t,0,0),e.getImageData(0,0,t.width,t.height)}Canvas.prototype.getContext=function(){return this.ctx},Canvas.prototype.toDataURL=function(t,e,a){if("function"!=typeof a)return this.canvasEl.toDataURL(t,e);a(this.canvasEl.toDataURL(t,e))},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,e,a,n,r,o){var i,s,u,c,h,l,g,d,f,y,p,m,x,b,v,w,C,D,P,I,j,O,E,M,T=t.data,k=o+o+1,_=n-1,B=r-1,S=o+1,A=S*(S+1)/2,U=new BlurStack,V=U;for(u=1;u>q,0!=E?(E=255/E,T[l]=(d*N>>q)*E,T[l+1]=(f*N>>q)*E,T[l+2]=(y*N>>q)*E):T[l]=T[l+1]=T[l+2]=0,d-=m,f-=x,y-=b,p-=v,m-=J.r,x-=J.g,b-=J.b,v-=J.a,c=g+((c=i+o+1)<_?c:_)<<2,d+=w+=J.r=T[c],f+=C+=J.g=T[c+1],y+=D+=J.b=T[c+2],p+=P+=J.a=T[c+3],J=J.next,m+=I=L.r,x+=j=L.g,b+=O=L.b,v+=E=L.a,w-=I,C-=j,D-=O,P-=E,L=L.next,l+=4;g+=n}for(i=0;i>q,0>q)*E,T[c+1]=(f*N>>q)*E,T[c+2]=(y*N>>q)*E):T[c]=T[c+1]=T[c+2]=0,d-=m,f-=x,y-=b,p-=v,m-=J.r,x-=J.g,b-=J.b,v-=J.a,c=i+((c=s+S)a&&(a=t.x),t.y>r&&(r=t.y)}),{x:e,y:n,width:a-e,height:r-n}}function addBoundingBoxesToPolygons(t,e,a){return t.forEach(function(t){t.boundingBox=getBoundingBox([t.a,t.b,t.c])}),t.filter(function(t){return 0=e.data.length&&(n=e.data.length-5);var r=e.data[n+3]/255;return a&&0==r?a:{r:e.data[n],g:e.data[n+1],b:e.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}var getOwnPropertySymbols=Object.getOwnPropertySymbols,hasOwnProperty=Object.prototype.hasOwnProperty,propIsEnumerable=Object.prototype.propertyIsEnumerable;function toObject(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function shouldUseNative(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},a=0;a<10;a++)e["_"+String.fromCharCode(a)]=a;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach(function(t){n[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(t){return!1}}var objectAssign=shouldUseNative()?Object.assign:function(t,e){for(var a,n,r=arguments,o=toObject(t),i=1;i