trilium/libraries/jsplumb.js

1 line
204 KiB
JavaScript
Raw Normal View History

(function(){void 0===Math.sgn&&(Math.sgn=function(t){return 0==t?0:t>0?1:-1});var t=function(t,e){return{x:t.x-e.x,y:t.y-e.y}},e=function(t,e){return t.x*e.x+t.y*e.y},n=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},i=function(t,e){return{x:t.x*e,y:t.y*e}},s=Math.pow(2,-65),o=function(e,i){for(var s=[],o=r(e,i),l=i.length-1,u=a(o,2*l-1,s,0),c=t(e,i[0]),d=n(c),p=0,f=0;f<u;f++){c=t(e,h(i,l,s[f],null,null));var g=n(c);g<d&&(d=g,p=s[f])}return c=t(e,i[l]),(g=n(c))<d&&(d=g,p=1),{location:p,distance:d}},r=function(n,s){for(var o=s.length-1,r=2*o-1,a=[],l=[],u=[],c=[],h=[[1,.6,.3,.1],[.4,.6,.6,.4],[.1,.3,.6,1]],d=0;d<=o;d++)a[d]=t(s[d],n);for(d=0;d<=o-1;d++)l[d]=t(s[d+1],s[d]),l[d]=i(l[d],3);for(var p=0;p<=o-1;p++)for(var f=0;f<=o;f++)u[p]||(u[p]=[]),u[p][f]=e(l[p],a[f]);for(d=0;d<=r;d++)c[d]||(c[d]=[]),c[d].y=0,c[d].x=parseFloat(d)/r;for(var g=o,m=o-1,v=0;v<=g+m;v++){var b=Math.max(0,v-m),y=Math.min(v,g);for(d=b;d<=y;d++){var P=v-d;c[d+P].y+=u[P][d]*h[P][d]}}return c},a=function(t,e,n,i){var s,o,r=[],d=[],p=[],f=[];switch(l(t,e)){case 0:return 0;case 1:if(i>=64)return n[0]=(t[0].x+t[e].x)/2,1;if(u(t,e))return n[0]=c(t,e),1}h(t,e,.5,r,d),s=a(r,e,p,i+1),o=a(d,e,f,i+1);for(var g=0;g<s;g++)n[g]=p[g];for(g=0;g<o;g++)n[g+s]=f[g];return s+o},l=function(t,e){var n,i,s=0;n=i=Math.sgn(t[0].y);for(var o=1;o<=e;o++)(n=Math.sgn(t[o].y))!=i&&s++,i=n;return s},u=function(t,e){var n,i,o,r,a,l,u,c,h;r=t[0].y-t[e].y,a=t[e].x-t[0].x,l=t[0].x*t[e].y-t[e].x*t[0].y,c=h=0;for(var d=1;d<e;d++){var p=r*t[d].x+a*t[d].y+l;p>c?c=p:p<h&&(h=p)}return 0,1,0,n=(1*(l-c)-0*(u=a))*(1/(0*u-1*r)),i=(1*(l-h)-0*(u=a))*(1/(0*u-1*r)),o=Math.min(n,i),Math.max(n,i)-o<s?1:0},c=function(t,e){var n=t[e].x-t[0].x,i=t[e].y-t[0].y,s=t[0].x-0;return 0+1*((n*(t[0].y-0)-i*s)*(1/(0*n-1*i)))},h=function(t,e,n,i,s){for(var o=[[]],r=0;r<=e;r++)o[0][r]=t[r];for(var a=1;a<=e;a++)for(r=0;r<=e-a;r++)o[a]||(o[a]=[]),o[a][r]||(o[a][r]={}),o[a][r].x=(1-n)*o[a-1][r].x+n*o[a-1][r+1].x,o[a][r].y=(1-n)*o[a-1][r].y+n*o[a-1][r+1].y;if(null!=i)for(r=0;r<=e;r++)i[r]=o[r][0];if(null!=s)for(r=0;r<=e;r++)s[r]=o[e-r][r];return o[e][0]},d={},p=function(t,e){for(var n=function(t){var e=d[t];if(!e){var n=function(t){return function(e){return t}},i=function(){return function(t){return t}},s=function(){return function(t){return 1-t}},o=function(t){return function(e){for(var n=1,i=0;i<t.length;i++)n*=t[i](e);return n}};(e=[]).push(new function(){return function(e){return Math.pow(e,t)}});for(var r=1;r<t;r++){for(var a=[new n(t)],l=0;l<t-r;l++)a.push(new i);for(l=0;l<r;l++)a.push(new s);e.push(new o(a))}e.push(new function(){return function(e){return Math.pow(1-e,t)}}),d[t]=e}return e}(t.length-1),i=0,s=0,o=0;o<t.length;o++)i+=t[o].x*n[o](e),s+=t[o].y*n[o](e);return{x:i,y:s}},f=function(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))},g=function(t){return t[0].x===t[1].x&&t[0].y===t[1].y},m=function(t,e,n){if(g(t))return{point:t[0],location:e};for(var i=p(t,e),s=0,o=e,r=n>0?1:-1,a=null;s<Math.abs(n);)a=p(t,o+=.005*r),s+=f(a,i),i=a;return{point:a,location:o}},v=function(t,e){var n=p(t,e),i=p(t.slice(0,t.length-1),e),s=i.y-n.y,o=i.x-n.x;return 0===s?1/0:Math.atan(s/o)},b=function(t,e,n,i,s){var o=i-e,r=t-n,a=t*(e-i)+e*(n-t),l=function(t){return[y(t,"x"),y(t,"y")]}(s),u=[o*l[0][0]+r*l[1][0],o*l[0][1]+r*l[1][1],o*l[0][2]+r*l[1][2],o*l[0][3]+r*l[1][3]+a],c=function(t,e,n,i){var s,o,r=e/t,a=n/t,l=i/t,u=(3*a-Math.pow(r,2))/9,c=(9*r*a-27*l-2*Math.pow(r,3))/54,h=Math.pow(u,3)+Math.pow(c,2),d=[];if(h>=0)s=P(c+Math.sqrt(h))*Math.pow(Math.abs(c+Math.sqrt(h)),1/3),o=P(c-Math.sqrt(h))*Math.pow(Math.abs(c-Math.sqrt(h)),1/3),d[0]=-r/3+(s+o),d[1]=-r/3-(s+o)/2,d[2]=-r/3-(s+o)/2,0!==Math.abs(Math.sqrt(3)*(s-o)/2)&&(d[1]=-1,d[2]=-1);else{var p=Math.acos(c/Math.sqrt(-Math.pow(u,3)));d[0]=2*Math.sqrt(-u)*Math.cos(p/3)-r/3,d[1]=2*Math.sqrt(-u)*Math.cos((p+2*Math.PI)/3)-r/3,d[2]=2*Math.sqrt(-u)*Math.cos((p+4*Math.PI)/3)-r/3}for(var f=0;f<3;f++)(d[f]<0||d[f]>1)&&(d[f]=-1);return d}.apply(null,u),h=[];if(null!=c)for(var d=0;d<3;d++){var p,f=c[d],g=Math.pow(f,2),m=Math.pow(f,3),v=[l[0][0]*m+l[0][1]*g+l[0][2]*f+l[0][3]