mpercivalxyz

this website!
Log | Files | Refs

besogo.min.js (40336B)


      1 (function(){function q(b,a){b.getAttribute("tabindex")||b.setAttribute("tabindex","0");b.addEventListener("keydown",function(c){c=c||window.event;switch(c.keyCode){case 33:a.prevNode(10);break;case 34:a.nextNode(10);break;case 35:a.nextNode(-1);break;case 36:a.prevNode(-1);break;case 37:c.shiftKey?a.prevBranchPoint():a.prevNode(1);break;case 38:a.nextSibling(-1);break;case 39:a.nextNode(1);break;case 40:a.nextSibling(1);break;case 46:a.cutCurrent()}33<=c.keyCode&&40>=c.keyCode&&c.preventDefault()})}
      2 function l(b,a){b.addEventListener("wheel",function(c){c=c||window.event;0<c.deltaY?(a.nextNode(1),c.preventDefault()):0>c.deltaY&&(a.prevNode(1),c.preventDefault())})}function m(b,a){try{var c=e.parseSgf(b)}catch(g){return}e.loadSgf(c,a)}function t(b,a,c){var g=new XMLHttpRequest;g.onreadystatechange=function(){4===g.readyState&&200===g.status&&(m(g.responseText,a),w(a,c))};g.overrideMimeType("text/plain");g.open("GET",b,!0);g.send()}function w(b,a){function c(d,p){var h;d=d.split(/D+/);for(h=0;h<
      3 d.length;h++)d[h]&&(p?b.getCurrent().children.length&&(b.nextNode(1),b.nextSibling(d[h]-1)):b.nextNode(+d[h]))}var g,f;a=a.split(/[Nn]+/);for(g=0;g<a.length;g++){var k=a[g].split(/[Bb]+/);c(k[0],!1);for(f=1;f<k.length;f++)c(k[f],!0)}}var e=window.besogo=window.besogo||{};e.VERSION="0.0.2-alpha";e.create=function(b,a){function c(v,r){r&&v>r?(b.style["flex-direction"]="row",p.style.height=r+"px",p.style.width=r+"px",h&&(h.style.height=r+"px",h.style.width=v-r+"px")):(b.style["flex-direction"]="column",
      4 p.style.height=v+"px",p.style.width=v+"px",h&&(r&&(h.style.height=r-v+"px"),h.style.width=v+"px"))}function g(v,r){var B=document.createElement("div");v&&(B.className=v);r=r||b;r.appendChild(B);return B}var f={control:e.makeControlPanel,names:e.makeNamesPanel,comment:e.makeCommentPanel,tool:e.makeToolPanel,tree:e.makeTreePanel,file:e.makeFilePanel},k=b.textContent||b.innerText||"";b.className+=" besogo-container";a=a||{};a.size=e.parseSize(a.size||19);a.coord=a.coord||"none";a.tool=a.tool||"auto";
      5 ""===a.panels&&(a.panels=[]);a.panels=a.panels||"control+names+comment+tool+tree+file";"string"===typeof a.panels&&(a.panels=a.panels.split("+"));a.path=a.path||"";void 0===a.shadows?a.shadows="auto":"off"===a.shadows&&(a.shadows=!1);var d=e.makeEditor(a.size.x,a.size.y);b.besogoEditor=d;d.setTool(a.tool);d.setCoordStyle(a.coord);a.realstones?(d.REAL_STONES=!0,d.SHADOWS=a.shadows):d.SHADOWS=a.shadows&&"auto"!==a.shadows;a.nokeys||q(b,d);if(a.sgf){k=!1;try{new URL(a.sgf),k=!0}catch(v){}try{k?t(a.sgf,
      6 d,a.path):(m(a.sgf,d),w(d,a.path))}catch(v){console.error(v)}}else k.match(/s*(s*;/)&&(m(k,d),w(d,a.path));for("number"!==typeof a.variants&&"string"!==typeof a.variants||d.setVariantStyle(+a.variants);b.firstChild;)b.removeChild(b.firstChild);var p=g("besogo-board");e.makeBoardDisplay(p,d);a.nowheel||l(p,d);if(0<a.panels.length){var h=g("besogo-panels");for(k=0;k<a.panels.length;k++){var u=a.panels[k];if(f[u])f[u](g("besogo-"+u,h),d)}h.firstChild||(b.removeChild(h),h=!1)}a.resize=a.resize||"auto";
      7 "auto"===a.resize?(d=function(){var v=window.innerHeight,r=parseFloat(getComputedStyle(b.parentElement).width),B=+(a.maxwidth||-1),D=a.orient||"auto",n=+(a.portratio||200)/100,z=+(a.landratio||200)/100,C=+(a.minpanelswidth||350),I=+(a.minpanelsheight||400),M=+(a.transwidth||600);r=0<B&&B<r?B:r;"portrait"!==D&&"landscape"!==D&&(D=r<M||"view"===D&&r<v?"portrait":"landscape");if("portrait"===D){if(!isNaN(n)){var N=n*r;h&&(N=N-r<I?r+I:N)}}else"landscape"===D&&(N=h?isNaN(z)?v:r/z:r,h&&(N=r<N+C?r-C:N));
      8 c(r,N);b.style.width=r+"px"},window.addEventListener("resize",d),d()):"fixed"===a.resize?c(b.clientWidth,b.clientHeight):"fill"===a.resize&&(d=function(){var v=parseFloat(getComputedStyle(b.parentElement).height),r=parseFloat(getComputedStyle(b.parentElement).width),B=+(a.minpanelswidth||350),D=+(a.minpanelsheight||300),n=0,z=0;r>=v?(b.style["flex-direction"]="row",h&&(n=r-v>=B?r-v:B),h.style.height=v+"px",h.style.width=n+"px",p.style.height=v+"px",p.style.width=r-n+"px"):(b.style["flex-direction"]=
      9 "column",h&&(z=v-r>=D?v-r:D),h.style.height=z+"px",h.style.width=r+"px",p.style.height=v-z+"px",p.style.width=r+"px")},window.addEventListener("resize",d),d())};e.parseSize=function(b){var a;b=(b+"").replace(/s/g,"");if(a=b.match(/^(d+):(d+)$/)){var c=+a[1];b=+a[2]}else b.match(/^d+$/)?(c=+b,b=+b):c=b=19;if(52<c||1>c||52<b||1>b)c=b=19;return{x:c,y:b}};e.autoInit=function(){function b(d,p){return-1!==d.className.split(" ").indexOf(p)}var a=document.getElementsByTagName("div"),c=[],g,f;for(g=0;g<
     10 a.length;g++)(b(a[g],"besogo-editor")||b(a[g],"besogo-viewer")||b(a[g],"besogo-diagram"))&&!b(a[g],"besogo-container")&&c.push(a[g]);for(g=0;g<c.length;g++){a={};b(c[g],"besogo-editor")?(a.panels="control names comment tool tree file".split(" "),a.tool="auto"):b(c[g],"besogo-viewer")?(a.panels=["control","names","comment"],a.tool="navOnly"):b(c[g],"besogo-diagram")&&(a.panels=[],a.tool="navOnly");var k=c[g].attributes;for(f=0;f<k.length;f++)a[k[f].name]=k[f].value;e.create(c[g],a)}}})();besogo.makeBoardDisplay=function(q,l){function m(){Q=!0;M=[];D.removeChild(C);q.removeEventListener("touchstart",m)}function t(A){var x="";v=("none"===A?0:75)+6;var y=2*v+88*r;var H=2*v+88*B;D=besogo.svgEl("svg",{width:"100%",height:"100%",viewBox:"0 0 "+y+" "+H});D.appendChild(besogo.svgEl("rect",{width:y,height:H,"class":"besogo-svg-board"}));D.appendChild(besogo.svgEl("rect",{width:88*(r-1),height:88*(B-1),x:h(1),y:h(1),"class":"besogo-svg-lines"}));for(y=2;y<=B-1;y++)x+="M"+h(1)+","+h(y)+"h"+
     11 88*(r-1);for(y=2;y<=r-1;y++)x+="M"+h(y)+","+h(1)+"v"+88*(B-1);D.appendChild(besogo.svgEl("path",{d:x,"class":"besogo-svg-lines"}));e();"none"!==A&&w(A);n=besogo.svgEl("g");z=besogo.svgEl("g");D.appendChild(n);D.appendChild(z);Q||(C=besogo.svgEl("g"),D.appendChild(C));for(x=1;x<=r;x++)for(y=1;y<=B;y++)A=besogo.svgEl("rect",{x:h(x)-44,y:h(y)-44,width:88,height:88,opacity:0}),A.addEventListener("click",b(x,y)),Q||(A.addEventListener("mouseover",a(x,y)),A.addEventListener("mouseout",c(x,y))),D.appendChild(A);
     12 if(l.REAL_STONES)for(A=besogo.BLACK_STONES*besogo.WHITE_STONES,N=[],x=1;x<=r;x++)for(y=1;y<=B;y++)N[u(x,y)]=Math.floor(Math.random()*A)}function w(A){function x(G,E,O){G=besogo.svgEl("text",{x:G,y:E,dy:".65ex","font-size":32,"text-anchor":"middle","font-family":"Helvetica, Arial, sans-serif",fill:"black"});G.appendChild(document.createTextNode(O));D.appendChild(G)}var y=besogo.coord[A](r,B),H=y.x,K=y.xb||y.x;A=y.y;y=y.yb||y.y;var F;for(F=1;F<=r;F++){var J=h(F);x(J,h(1)-85,H[F]);x(J,h(B)+85,K[F])}for(F=
     13 1;F<=B;F++)H=h(F),x(h(1)-85,H,A[F]),x(h(r)+85,H,y[F])}function e(){function A(K,F){x+="M"+h(K)+","+h(F)+"l0,0"}var x="";if(r%2&&B%2){var y=(r-1)/2+1;var H=(B-1)/2+1;A(y,H);17<=r&&17<=B&&(A(4,H),A(r-3,H),A(y,4),A(y,B-3))}11<=r&&11<=B?(A(4,4),A(4,B-3),A(r-3,4),A(r-3,B-3)):8<=r&&8<=B&&(A(3,3),A(3,B-2),A(r-2,3),A(r-2,B-2));x&&D.appendChild(besogo.svgEl("path",{d:x,"stroke-linecap":"round","class":"besogo-svg-hoshi"}))}function b(A,x){return function(y){l.click(A,x,y.ctrlKey,y.shiftKey);Q||a(A,x)()}}function a(A,
     14 x){return function(){var y=M[u(A,x)];y&&y.setAttribute("visibility","visible")}}function c(A,x){return function(){var y=M[u(A,x)];y&&y.setAttribute("visibility","hidden")}}function g(A){var x=besogo.svgEl("g"),y,H,K;if(l.SHADOWS){var F=besogo.svgShadowGroup();x.appendChild(F)}for(y=1;y<=r;y++)for(H=1;H<=B;H++)if(K=A.getStone(y,H)){var J=h(y);var G=h(H);l.REAL_STONES?x.appendChild(besogo.realStone(J,G,K,N[u(y,H)])):x.appendChild(besogo.svgStone(J,G,K));l.SHADOWS&&(F.appendChild(besogo.svgShadow(J-
     15 2,G-4)),F.appendChild(besogo.svgShadow(J+2,G+4)))}D.replaceChild(x,n);n=x}function f(A){var x,y,H=besogo.svgEl("g"),K=A.move,F=l.getVariants(),J;I=[];for(x=1;x<=r;x++)for(y=1;y<=B;y++)if(J=A.getMarkup(x,y)){var G=h(x);var E=h(y);var O=A.getStone(x,y);var P=-1===O?"white":"black";K&&K.x===x&&K.y===y?P=d(F,A,x,y)?besogo.PURP:besogo.BLUE:d(F,A,x,y)&&(P=besogo.RED);if("number"===typeof J)switch(J){case 1:var L=besogo.svgCircle(G,E,P);break;case 2:L=besogo.svgSquare(G,E,P);break;case 3:L=besogo.svgTriangle(G,
     16 E,P);break;case 4:L=besogo.svgCross(G,E,P);break;case 5:L=besogo.svgBlock(G,E,P)}else O||(L=k(G,E),H.appendChild(L)),L=besogo.svgLabel(G,E,P,J);H.appendChild(L);I[u(x,y)]=L}K&&0!==K.x&&0!==K.y&&(x=K.x,y=K.y,I[u(x,y)]||(P=d(F,A,x,y)?besogo.PURP:besogo.BLUE,L=besogo.svgPlus(h(x),h(y),P),H.appendChild(L),I[u(x,y)]=L));for(x=0;x<F.length;x++)F[x]!==A&&(L=F[x].move)&&0!==L.x&&!I[u(L.x,L.y)]&&(E=A.getStone(L.x,L.y),y=h(L.x),G=h(L.y),E||(E=k(y,G),H.appendChild(E)),E=String.fromCharCode(65+x%26),E=besogo.svgLabel(y,
     17 G,besogo.LRED,E),H.appendChild(E),I[u(L.x,L.y)]=E);D.replaceChild(H,z);z=H}function k(A,x){return besogo.svgEl("rect",{x:A-44,y:x-44,height:88,width:88,opacity:.85,stroke:"none","class":"besogo-svg-board besogo-svg-backer"})}function d(A,x,y,H){var K,F;for(K=0;K<A.length;K++)if(A[K]!==x&&(F=A[K].move)&&F.x===y&&F.y===H)return!0;return!1}function p(A){if(!Q){var x,y,H=besogo.svgEl("g"),K=l.getTool(),F;M=[];H.setAttribute("opacity","0.35");if("navOnly"===K)for(A=A.children,x=0;x<A.length;x++){if((F=
     18 A[x].move)&&0!==F.x){var J=h(F.x);var G=h(F.y);var E=besogo.svgStone(J,G,F.color);E.setAttribute("visibility","hidden");H.appendChild(E);M[u(F.x,F.y)]=E}}else for(x=1;x<=r;x++)for(y=1;y<=B;y++){E=null;J=h(x);G=h(y);F=A.getStone(x,y);var O=-1===F?"white":"black";switch(K){case "auto":E=besogo.svgStone(J,G,A.nextMove());break;case "playB":E=besogo.svgStone(J,G,-1);break;case "playW":E=besogo.svgStone(J,G,1);break;case "addB":-1===F?E=besogo.svgCross(J,G,besogo.RED):(E=besogo.svgEl("g"),E.appendChild(besogo.svgStone(J,
     19 G,-1)),E.appendChild(besogo.svgPlus(J,G,besogo.RED)));break;case "addW":1===F?E=besogo.svgCross(J,G,besogo.RED):(E=besogo.svgEl("g"),E.appendChild(besogo.svgStone(J,G,1)),E.appendChild(besogo.svgPlus(J,G,besogo.RED)));break;case "addE":F&&(E=besogo.svgCross(J,G,besogo.RED));break;case "circle":E=besogo.svgCircle(J,G,O);break;case "square":E=besogo.svgSquare(J,G,O);break;case "triangle":E=besogo.svgTriangle(J,G,O);break;case "cross":E=besogo.svgCross(J,G,O);break;case "block":E=besogo.svgBlock(J,G,
     20 O);break;case "label":E=besogo.svgLabel(J,G,O,l.getLabel())}E&&(E.setAttribute("visibility","hidden"),H.appendChild(E),M[u(x,y)]=E)}D.replaceChild(H,C);C=H}}function h(A){return v+44+88*(A-1)}function u(A,x){return(A-1)*B+(x-1)}var v,r=l.getCurrent().getSize().x,B=l.getCurrent().getSize().y,D,n,z,C,I,M,N,Q=!1;t(l.getCoordStyle());q.appendChild(D);l.addListener(function(A){var x=l.getCurrent(),y=x.getSize(),H=!1,K=D;if(y.x!==r||y.y!==B||A.coord)r=y.x,B=y.y,t(A.coord||l.getCoordStyle()),q.replaceChild(D,
     21 K),H=!0;H||A.navChange||A.stoneChange?(g(x),f(x),p(x)):A.markupChange||A.treeChange?(f(x),p(x)):(A.tool||A.label)&&p(x)});(function(A){g(A);f(A);p(A)})(l.getCurrent());q.addEventListener("touchstart",m)};besogo.makeCommentPanel=function(q,l){function m(d){if(d.navChange){var p=l.getCurrent().comment||"";var h=a;p=document.createTextNode(p);h.replaceChild(p,w.C);w.C=p;l.getCurrent()===l.getRoot()&&e.firstChild&&"none"===b.style.display?e.style.display="table":e.style.display="none";c.style.display="none";a.style.display="block"}else void 0!==d.comment&&(h=a,p=document.createTextNode(d.comment),h.replaceChild(p,w.C),w.C=p,c.value=d.comment);if(d.gameInfo){h=d.gameInfo;p=document.createElement("table");
     22 var u;p.className="besogo-gameInfo";for(u=0;u<f.length;u++){var v=f[u];if(h[v]){var r=document.createElement("tr");p.appendChild(r);var B=document.createElement("td");B.appendChild(document.createTextNode(k[v]));r.appendChild(B);B=document.createElement("td");v=document.createTextNode(h[v]);B.appendChild(v);r.appendChild(B)}}p.firstChild&&"none"!==e.style.display||(p.style.display="none");q.replaceChild(p,e);e=p;t(d.gameInfo)}}function t(d){var p=document.createElement("table"),h=g.concat(f),u;p.className=
     23 "besogo-gameInfo";for(u=0;u<h.length;u++){var v=h[u];var r=document.createElement("tr");p.appendChild(r);var B=document.createElement("td");B.appendChild(document.createTextNode(k[v]));r.appendChild(B);B=document.createElement("td");var D=document.createElement("input");d[v]&&(D.value=d[v]);D.onblur=function(n,z){return function(){l.setGameInfo(n.value,z)}}(D,v);D.addEventListener("keydown",function(n){n=n||window.event;n.stopPropagation()});B.appendChild(D);r.appendChild(B)}"none"===b.style.display&&
     24 (p.style.display="none");q.replaceChild(p,b);b=p}var w={},e=document.createElement("table"),b=document.createElement("table"),a=document.createElement("div"),c=document.createElement("textarea"),g="PW WR WT PB BR BT".split(" "),f="HA KM RU TM OT GN EV PC RO DT RE ON GC AN US SO CP".split(" "),k={PW:"White Player",WR:"White Rank",WT:"White Team",PB:"Black Player",BR:"Black Rank",BT:"Black Team",HA:"Handicap",KM:"Komi",RU:"Rules",TM:"Timing",OT:"Overtime",GN:"Game Name",EV:"Event",PC:"Place",RO:"Round",
     25 DT:"Date",RE:"Result",ON:"Opening",GC:"Comments",AN:"Annotator",US:"Recorder",SO:"Source",CP:"Copyright"};q.appendChild(function(){var d=document.createElement("input");d.type="button";d.value="Info";d.title="Show/hide game info";d.onclick=function(){e.style.display="none"===e.style.display&&e.firstChild?"table":"none";b.style.display="none"};return d}());q.appendChild(function(){var d=document.createElement("input");d.type="button";d.value="Edit Info";d.title="Edit game info";d.onclick=function(){b.style.display=
     26 "none"===b.style.display?"table":"none";e.style.display="none"};return d}());q.appendChild(function(){var d=document.createElement("input");d.type="button";d.value="Comment";d.title="Edit comment";d.onclick=function(){"none"===c.style.display?(a.style.display="none",e.style.display="none",c.value=l.getCurrent().comment,c.style.display="block"):(c.style.display="none",a.style.display="block")};return d}());q.appendChild(e);q.appendChild(b);w.C=document.createTextNode("");q.appendChild(a);a.appendChild(w.C);
     27 q.appendChild(c);c.onblur=function(){l.setComment(c.value)};c.addEventListener("keydown",function(d){d=d||window.event;d.stopPropagation()});l.addListener(m);m({navChange:!0,gameInfo:l.getGameInfo()});b.style.display="none"};besogo.makeControlPanel=function(q,l){function m(d){function p(u){u%2?(g.setAttribute("fill","black"),f.setAttribute("fill",besogo.BLUE),a.title="Variants: child/[sibling]"):(g.setAttribute("fill",besogo.BLUE),f.setAttribute("fill",besogo.RED),a.title="Variants: [child]/sibling");2<=u?(k.setAttribute("visibility","visible"),c.title="Variants: show/[hide]"):(k.setAttribute("visibility","hidden"),c.title="Variants: [show]/hide")}function h(u,v){var r;for(r=0;r<u.length;r++)u[r].setAttribute("fill",
     28 v)}void 0!==d.variantStyle&&p(d.variantStyle);if(d.navChange||d.treeChange)d=l.getCurrent(),d.parent?(h(w,"black"),1<d.parent.children.length?h(b,"black"):h(b,besogo.GREY)):(h(w,besogo.GREY),h(b,besogo.GREY)),d.children.length?h(e,"black"):h(e,besogo.GREY)}function t(){return besogo.svgEl("svg",{width:"100%",height:"100%",viewBox:"0 0 100 100"})}var w=[],e=[],b=[],a,c,g,f,k;(function(){function d(p,h,u){var v=document.createElement("button"),r=t();h=besogo.svgEl("polygon",{points:h,stroke:"none",
     29 fill:"black"});v.title=p;v.onclick=u;v.appendChild(r);r.appendChild(h);q.appendChild(v);return h}w.push(d("First node","5,10 5,90 25,90 25,50 95,90 95,10 25,50 25,10",function(){l.prevNode(-1)}));w.push(d("Jump back","95,10 50,50 50,10 5,50 50,90 50,50 95,90",function(){l.prevNode(10)}));w.push(d("Previous node","85,10 85,90 15,50",function(){l.prevNode(1)}));e.push(d("Next node","15,10 15,90 85,50",function(){l.nextNode(1)}));e.push(d("Jump forward","5,10 50,50 50,10 95,50 50,90 50,50 5,90",function(){l.nextNode(10)}));
     30 e.push(d("Last node","95,10 95,90 75,90 75,50 5,90 5,10 75,50 75,10",function(){l.nextNode(-1)}));b.push(d("Previous sibling","10,85 90,85 50,15",function(){l.nextSibling(-1)}));b.push(d("Next sibling","10,15 90,15 50,85",function(){l.nextSibling(1)}))})();(function(){a=document.createElement("button");a.onclick=function(){l.toggleVariantStyle(!1)};q.appendChild(a);var d=t();a.appendChild(d);var p=besogo.svgEl("path",{d:"m75,25h-50l50,50",stroke:"black","stroke-width":5,fill:"none"});d.appendChild(p);
     31 g=besogo.svgEl("circle",{cx:25,cy:25,r:20,stroke:"none"});d.appendChild(g);f=besogo.svgEl("circle",{cx:75,cy:25,r:20,stroke:"none"});d.appendChild(f);p=besogo.svgEl("circle",{cx:75,cy:75,r:20,fill:besogo.RED,stroke:"none"});d.appendChild(p);c=document.createElement("button");c.onclick=function(){l.toggleVariantStyle(!0)};q.appendChild(c);d=t();c.appendChild(d);d.appendChild(besogo.svgLabel(50,50,besogo.RED,"A"));k=besogo.svgCross(50,50,"black");d.appendChild(k);p=document.createElement("button");
     32 p.onclick=function(){l.toggleCoordStyle()};p.title="Toggle coordinates";q.appendChild(p);d=t();p.appendChild(d);d.appendChild(besogo.svgLabel(50,50,"black","u56db4"))})();l.addListener(m);m({navChange:!0,variantStyle:l.getVariantStyle()})};(function(){function q(m){return"ABCDEFGHJKLMNOPQRSTUVWXYZ".charAt((m-1)%25)}function l(m){var t="";20<=m?t="u4e00u4e8cu4e09u56dbu4e94u516du4e03u516bu4e5d".charAt(m/10-1)+"u5341":10<=m&&(t="u5341");m%10&&(t+="u4e00u4e8cu4e09u56dbu4e94u516du4e03u516bu4e5d".charAt((m-1)%10));return t}besogo.coord={};besogo.coord.none=function(m,t){return!1};besogo.coord.western=function(m,t){var w={x:[],y:[]},e;for(e=1;e<=m;e++)w.x[e]=q(e);for(e=1;e<=t;e++)w.y[e]=t-e+1+"";return w};besogo.coord.numeric=
     33 function(m,t){var w={x:[],y:[]},e;for(e=1;e<=m;e++)w.x[e]=e+"";for(e=1;e<=t;e++)w.y[e]=e+"";return w};besogo.coord.pierre=function(m,t){var w={x:[],xb:[],y:[],yb:[]},e;for(e=1;e<=m/2;e++)w.x[e]="a"+e,w.x[m-e+1]="b"+e,w.xb[e]="d"+e,w.xb[m-e+1]="c"+e;m%2&&(e=Math.ceil(m/2),w.x[e]="a",w.xb[e]="c");for(e=1;e<=t/2;e++)w.y[e]="a"+e,w.y[t-e+1]="d"+e,w.yb[e]="b"+e,w.yb[t-e+1]="c"+e;t%2&&(e=Math.ceil(t/2),w.y[e]="d",w.yb[e]="b");return w};besogo.coord.corner=function(m,t){var w={x:[],y:[]},e;for(e=1;e<=m;e++)w.x[e]=
     34 e<m/2+1?q(e):m-e+1+"";for(e=1;e<=t;e++)w.y[e]=t-e+1+"",w.y[e]=e>t/2?q(t-e+1):e+"";return w};besogo.coord.eastcor=function(m,t){var w={x:[],y:[]},e;for(e=1;e<=m;e++)w.x[e]=e<m/2+1?l(e):m-e+1+"";for(e=1;e<=t;e++)w.y[e]=t-e+1+"",w.y[e]=e>t/2?l(t-e+1):e+"";return w};besogo.coord.eastern=function(m,t){var w={x:[],y:[]},e;for(e=1;e<=m;e++)w.x[e]=e+"";for(e=1;e<=t;e++)w.y[e]=l(e);return w}})();besogo.makeEditor=function(q,l){function m(n){"string"===typeof n&&(h=(n=n.replace(/s/g," ").trim())||"1",p="label",c({tool:p,label:h}))}function t(n,z,C){var I,M=f.children;for(I=0;I<M.length;I++){var N=M[I].move;if(C){if(w(n,z,M[I]))return!0}else if(N&&N.x===n&&N.y===z)return f=M[I],c({navChange:!0}),!0}return C&&w(n,z,g,f)?!0:!1}function w(n,z,C,I){var M,N=C.children;if(I&&I===C)return!1;if((M=C.move)&&M.x===n&&M.y===z)return f=C,c({navChange:!0}),!0;for(C=0;C<N.length;C++)if(w(n,z,N[C],I))return!0;
     35 return!1}function e(n,z,C,I){if(f.isMutable("move")&&f.parent)f.playMove(n,z,C,I)&&c({stoneChange:!0});else{var M=f.makeChild();M.playMove(n,z,C,I)&&(f.addChild(M),f=M,c({treeChange:!0,navChange:!0,stoneChange:!0}))}}function b(n,z,C){if(C===f.getStone(n,z))if(0!==C)C=0;else return;if(f.isMutable("setup"))f.placeSetup(n,z,C)&&c({stoneChange:!0});else{var I=f.makeChild();I.placeSetup(n,z,C)&&(f.addChild(I),f=I,c({treeChange:!0,navChange:!0,stoneChange:!0}))}}function a(n,z,C){if(C===f.getMarkup(n,
     36 z))if(0!==C)C=0;else return;f.addMarkup(n,z,C)&&("string"===typeof C&&(/^-?d+$/.test(C)?m(""+(+C+1)):/[A-Za-z]$/.test(C)&&(n=C.charAt(C.length-1),n="z"===n?"A":"Z"===n?"a":String.fromCharCode(n.charCodeAt()+1),m(C.slice(0,C.length-1)+n))),c({markupChange:!0}))}function c(n,z){!z&&n.navChange&&(u=[]);for(z=0;z<k.length;z++)k[z](n)}var g=besogo.makeGameRoot(q,l),f=g,k=[],d="navOnly auto playB playW addB addW addE clrMark circle square triangle cross block label".split(" "),p="auto",h="1",u=[],v={},
     37 r="none numeric western eastern pierre corner eastcor".split(" "),B="none",D=0;return{addListener:function(n){k.push(n)},click:function(n,z,C,I){switch(p){case "navOnly":t(n,z,I);break;case "auto":t(n,z,I)||I||e(n,z,0,C);break;case "playB":e(n,z,-1,C);break;case "playW":e(n,z,1,C);break;case "addB":C?e(n,z,-1,!0):b(n,z,-1);break;case "addW":C?e(n,z,1,!0):b(n,z,1);break;case "addE":b(n,z,0);break;case "clrMark":a(n,z,0);break;case "circle":a(n,z,1);break;case "square":a(n,z,2);break;case "triangle":a(n,
     38 z,3);break;case "cross":a(n,z,4);break;case "block":a(n,z,5);break;case "label":a(n,z,h)}},nextNode:function(n){if(0===f.children.length)return!1;for(;0<f.children.length&&0!==n;)f=u.length?u.pop():f.children[0],n--;c({navChange:!0},!0)},prevNode:function(n){if(null===f.parent)return!1;for(;f.parent&&0!==n;)u.push(f),f=f.parent,n--;c({navChange:!0},!0)},nextSibling:function(n){if(f.parent){var z=f.parent.children;if(1!==z.length){var C=z.indexOf(f);C=(C+n)%z.length;0>C&&(C+=z.length);f=z[C];c({navChange:!0})}}},
     39 prevBranchPoint:function(n){if(null===f.parent)return!1;for(u.push(f);f.parent&&1===f.parent.children.length;)f=f.parent;if(f.parent)f=f.parent,c({navChange:!0});else return f=u.pop(f),!1},toggleCoordStyle:function(){B=r[(r.indexOf(B)+1)%r.length];c({coord:B})},getCoordStyle:function(){return B},setCoordStyle:function(n){besogo.coord[n]&&(B=n,c({coord:n}))},toggleVariantStyle:function(n){var z=D%2,C=D-z;n?C=(C+2)%4:z=(z+1)%2;D=z+C;c({variantStyle:D,markupChange:!0})},getVariantStyle:function(){return D},
     40 setVariantStyle:function(n){if(0===n||1===n||2===n||3===n)D=n,c({variantStyle:D,markupChange:!0})},getGameInfo:function(){return v},setGameInfo:function(n,z){z?v[z]=n:v=n;c({gameInfo:v})},setComment:function(n){n=n.trim();n=n.replace(/rn/g,"n").replace(/nr/g,"n").replace(/r/g,"n");n.replace(/ftvu0085u00a0/g," ");f.comment=n;c({comment:n})},getTool:function(){return p},setTool:function(n){return"label"===n&&n===p?(/^-?d+$/.test(h)?m("A"):m("1"),!0):-1!==d.indexOf(n)&&p!==n?(p=n,c({tool:p,
     41 label:h}),!0):!1},getLabel:function(){return h},setLabel:m,getVariants:function(){return 2<=D?[]:1===D?f.parent?f.parent.children:[]:f.children},getCurrent:function(){return f},setCurrent:function(n){f!==n&&(f=n,c({navChange:!0}))},cutCurrent:function(){var n=f.parent;"navOnly"!==p&&n&&!0===confirm("Delete this branch?")&&(n.removeChild(f),f=n,c({treeChange:!0,navChange:!0}))},promote:function(){"navOnly"!==p&&f.parent&&f.parent.promote(f)&&c({treeChange:!0})},demote:function(){"navOnly"!==p&&f.parent&&
     42 f.parent.demote(f)&&c({treeChange:!0})},getRoot:function(){return g},loadRoot:function(n){f=g=n;c({treeChange:!0,navChange:!0,stoneChange:!0})}}};besogo.makeFilePanel=function(q,l){function m(a){var c=document.createElement("input");c.type="button";c.value=a+"x"+a;"?"===a?(c.title="New custom size board",c.onclick=function(){var g=prompt("Enter custom size for new boardnEverything not saved will be lost","19:19");g&&(g=besogo.parseSize(g),l.loadRoot(besogo.makeGameRoot(g.x,g.y)),l.setGameInfo({}))}):(c.title="New "+a+"x"+a+" board",c.onclick=function(){confirm(c.title+"?nEverything not saved will be lost")&&(l.loadRoot(besogo.makeGameRoot(a,
     43 a)),l.setGameInfo({}))});q.appendChild(c)}function t(){var a=document.createElement("input");a.type="file";a.style.display="none";a.onchange=w;return a}function w(a){a=a.target.files[0];var c=new FileReader,g=t();q.replaceChild(g,e);e=g;c.onload=function(f){try{var k=besogo.parseSgf(f.target.result)}catch(d){alert("SGF parse error at "+d.at+":n"+d.message);return}besogo.loadSgf(k,l)};confirm("Load '"+a.name+"'?nEverything not saved will be lost")&&c.readAsText(a)}m(9);m(13);m(19);m("?");var e=t();
     44 q.appendChild(e);var b=document.createElement("input");b.type="button";b.value="Open";b.title="Import SGF";b.onclick=function(){e.click()};q.appendChild(b);b=document.createElement("input");b.type="button";b.value="Save";b.title="Export SGF";b.onclick=function(){var a=prompt("Save file as","export.sgf");if(a){var c=besogo.composeSgf(l),g=document.createElement("a");c=new Blob([c],{encoding:"UTF-8",type:"text/plain;charset=UTF-8"});g.download=a;g.href=URL.createObjectURL(c);g.style.display="none";
     45 q.appendChild(g);g.click();q.removeChild(g)}};q.appendChild(b)};besogo.makeGameRoot=function(q,l){function m(b,a){b.parent=a;b.children=[];b.move=null;b.setupStones=[];b.markup=[];b.comment=""}function t(b,a,c,g,f){var k=[];if(!w(b,a,c,g,k))for(a=0;a<k.length;a++)b["board"+k[a].x+"-"+k[a].y]=0,f.push(k[a])}function w(b,a,c,g,f){var k;if(1>a||1>c||a>q||c>l||b.getStone(a,c)===g)return!1;if(!b.getStone(a,c))return!0;for(k=0;k<f.length;k++)if(f[k].x===a&&f[k].y===c)return!1;f.push({x:a,y:c});return w(b,a-1,c,g,f)||w(b,a+1,c,g,f)||w(b,a,c-1,g,f)||w(b,a,c+1,g,f)?!0:
     46 !1}var e={blackCaps:0,whiteCaps:0,moveNumber:0};m(e,null);e.playMove=function(b,a,c,g){var f=!1;if(!this.isMutable("move"))return!1;c||=this.nextMove();if(1>b||1>a||b>q||a>l)return this.move={x:0,y:0,color:c,captures:0,overwrite:!1},this.lastMove=c,this.moveNumber++,!0;if(this.getStone(b,a)){if(!g)return!1;f=!0}var k=Object.create(this);var d=[];k["board"+b+"-"+a]=c;t(k,b-1,a,c,d);t(k,b+1,a,c,d);t(k,b,a-1,c,d);t(k,b,a+1,c,d);var p=d.length;var h=this.parent?this.parent.move:null;if(!g&&h&&h.color===
     47 -c&&!1===h.overwrite&&1===h.captures&&1===p&&!k.getStone(h.x,h.y)||0===p&&(t(k,b,a,-c,d),p=-d.length,0>p&&!g))return!1;0>c*p?this.blackCaps+=Math.abs(p):this.whiteCaps+=Math.abs(p);this["board"+b+"-"+a]=c;for(g=0;g<d.length;g++)this["board"+d[g].x+"-"+d[g].y]=0;this.move={x:b,y:a,color:c,captures:p,overwrite:f};this.lastMove=c;this.moveNumber++;return!0};e.nextMove=function(){var b,a,c=0;if(this.lastMove)return-this.lastMove;for(b=1;b<=q;b++)for(a=1;a<=l;a++)c+=this.getStone(b,a);return 0>c?1:-1};
     48 e.placeSetup=function(b,a,c){var g=this.parent&&this.parent.getStone(b,a)||0;if(1>b||1>a||b>q||a>l||!this.isMutable("setup")||this.getStone(b,a)===c)return!1;this["board"+b+"-"+a]=c;this.setupStones[(b-1)*l+(a-1)]=c-g;return!0};e.addMarkup=function(b,a,c){if(1>b||1>a||b>q||a>l||this.getMarkup(b,a)===c)return!1;this.markup[(b-1)*l+(a-1)]=c;return!0};e.getStone=function(b,a){return this["board"+b+"-"+a]||0};e.getSetup=function(b,a){if(this.setupStones[(b-1)*l+(a-1)])switch(this.getStone(b,a)){case 0:return"AE";
     49 case -1:return"AB";case 1:return"AW"}else return!1};e.getMarkup=function(b,a){return this.markup[(b-1)*l+(a-1)]||0};e.getType=function(){var b;if(this.move)return"move";for(b=0;b<this.setupStones.length;b++)if(this.setupStones[b])return"setup";return"empty"};e.isMutable=function(b){return"move"===b&&"empty"===this.getType()&&0===this.children.length||"setup"===b&&"move"!==this.getType()&&0===this.children.length?!0:!1};e.getSiblings=function(){return this.parent&&this.parent.children||[]};e.makeChild=
     50 function(){var b=Object.create(this);m(b,this);return b};e.addChild=function(b){this.children.push(b)};e.removeChild=function(b){b=this.children.indexOf(b);return-1!==b?(this.children.splice(b,1),!0):!1};e.promote=function(b){var a=this.children.indexOf(b);return 0<a?(this.children[a]=this.children[a-1],this.children[a-1]=b,!0):!1};e.demote=function(b){var a=this.children.indexOf(b);return-1!==a&&a<this.children.length-1?(this.children[a]=this.children[a+1],this.children[a+1]=b,!0):!1};e.getSize=
     51 function(){return{x:q,y:l}};return e};besogo.loadSgf=function(q,l){function m(c,g){var f;for(f=0;f<c.props.length;f++){var k=g;var d=c.props[f];switch(d.id){case "B":d=w(d.values[0]);k.playMove(d.x,d.y,-1,!0);break;case "W":d=w(d.values[0]);k.playMove(d.x,d.y,1,!0);break;case "AB":t(d.values,k,"placeSetup",-1);break;case "AW":t(d.values,k,"placeSetup",1);break;case "AE":t(d.values,k,"placeSetup",0);break;case "CR":t(d.values,k,"addMarkup",1);break;case "SQ":t(d.values,k,"addMarkup",2);break;case "TR":t(d.values,k,"addMarkup",3);break;
     52 case "M":case "MA":t(d.values,k,"addMarkup",4);break;case "SL":t(d.values,k,"addMarkup",5);break;case "L":case "LB":t(d.values,k,"addMarkup","label");break;case "C":k.comment=k.comment?k.comment+("n"+d.values.join().trim()):d.values.join().trim()}}for(f=0;f<c.children.length;f++)k=g.makeChild(),g.addChild(k),m(c.children[f],k)}function t(c,g,f,k){var d,p;for(d=0;d<c.length;d++){var h=w(c[d].slice(0,2));if("label"===k){var u=c[d].slice(3).replace(/n/g," ");g[f](h.x,h.y,u)}else if(":"===c[d].charAt(2)){var v=
     53 w(c[d].slice(3));if(v.x===h.x&&v.y===h.y)g[f](h.x,h.y,k);else if(v.x<h.x||v.y<h.y)g[f](h.x,h.y,k),g[f](v.x,v.y,k);else for(u=h.x;u<=v.x;u++)for(p=h.y;p<=v.y;p++)g[f](u,p,k)}else g[f](h.x,h.y,k)}}function w(c){return c.match(/^[A-Za-z]{2}$/)?{x:e(c.charAt(0)),y:e(c.charAt(1))}:{x:0,y:0}}function e(c){return c.match(/[A-Z]/)?c.charCodeAt(0)-65+27:c.charCodeAt(0)-97+1}var b={x:19,y:19};(function(c){var g="PB BR BT PW WR WT HA KM RU TM OT DT EV GN PC RO GC ON RE AN CP SO US".split(" "),f={},k;for(k=0;k<
     54 c.props.length;k++){var d=c.props[k].id;var p=c.props[k].values.join().trim();"SZ"===d?b=besogo.parseSize(p):"ST"===d?l.setVariantStyle(+p):-1!==g.indexOf(d)&&("GC"!==d&&(p=p.replace(/n/g," ")),p&&(f[d]=p))}l.setGameInfo(f)})(q);var a=besogo.makeGameRoot(b.x,b.y);m(q,a);l.loadRoot(a)};besogo.makeNamesPanel=function(q,l){function m(k){var d=0;if(k.gameInfo){var p=(k.gameInfo.PW||"White")+" ("+(k.gameInfo.WR||"?")+")"+(k.gameInfo.WT?" "+k.gameInfo.WT:"");p=document.createTextNode(p);e.replaceChild(p,a);a=p;p=(k.gameInfo.PB||"Black")+" ("+(k.gameInfo.BR||"?")+")"+(k.gameInfo.BT?" "+k.gameInfo.BT:"");p=document.createTextNode(p);b.replaceChild(p,c);c=p}if(k.navChange||k.stoneChange)k=l.getCurrent(),k.move&&0===k.move.x&&0===k.move.y&&(d=k.move.color),t(g,(1===d?"Passed  ":"")+k.whiteCaps),
     55 t(f,k.blackCaps+(-1===d?"  Passed":""))}function t(k,d){for(d=document.createTextNode(d);k.firstChild;)k.removeChild(k.firstChild);k.appendChild(d)}var w=document.createElement("div"),e=document.createElement("div"),b=document.createElement("div"),a=document.createTextNode(""),c=document.createTextNode(""),g=document.createElement("span"),f=document.createElement("span");w.className="besogo-playerInfo";e.className="besogo-whiteInfo";b.className="besogo-blackInfo";g.className="besogo-whiteCaps";g.title=
     56 "White captures";f.className="besogo-blackCaps";f.title="Black captures";e.appendChild(a);e.appendChild(g);b.appendChild(c);b.appendChild(f);w.appendChild(e);w.appendChild(b);q.appendChild(w);l.addListener(m);m({navChange:!0,gameInfo:l.getGameInfo()})};besogo.parseSgf=function(q){function l(g){throw{name:"Syntax Error",message:g,at:a,text:q};}function m(g){g&&g!==c&&l("Expected '"+g+"' instead of '"+c+"'");a++;return c=q.charAt(a)}function t(){for(;c&&" ">=c;)m()}function w(){return"n"===c?("r"===q.charAt(a+1)&&m(),!0):"r"===c?("n"===q.charAt(a+1)&&m(),!0):!1}function e(){var g;m("(");t();";"!==c&&l("Sub-tree missing root");var f=b();t();for(g=f;";"===c;){var k=b();g.children.push(k);g=k;t()}for(;"("===c;)k=e(),g.children.push(k),t();m(")");
     57 return f}function b(){var g,f={props:[],children:[]};m(";");for(t();c&&";"!==c&&"("!==c&&")"!==c;){for(g={id:"",values:[]};c&&/[A-Za-z]/.test(c);)/[A-Z]/.test(c)&&(g.id+=c),m();g.id||l("Missing property ID");for(t();"["===c;){var k=g.values,d=k.push,p="";for(m("[");c&&"]"!==c;)"\"===c?(m("\"),w()||(p=" ">=c?p+" ":p+c)):p=w()?p+"n":" ">=c?p+" ":p+c,m();m("]");d.call(k,p);t()}0===g.values.length&&l("Missing property values");f.props.push(g);t()}return f}for(var a=0,c=q.charAt(a);c&&"("!==c;)m();
     58 return e()};besogo.composeSgf=function(q){function l(b){var a=";",c=b.children;if(!b.parent){var g="FF[4]GM[1]CA[UTF-8]AP[besogo:"+besogo.VERSION+"]",f=b.getSize().x,k=b.getSize().y,d=q.getGameInfo(),p=!1;g=(f===k?g+("SZ["+f+"]"):g+("SZ["+f+":"+k+"]"))+("ST["+q.getVariantStyle()+"]n");for(h in d)d.hasOwnProperty(h)&&d[h]&&(g+=h+"["+t(d[h])+"]",p=!0);a+=g+(p?"n":"")}var h=a;a="";if("move"===b.getType())f=b.move,a+=1===f.color?"W":"B",a+="["+w(f.x,f.y)+"]";else if("setup"===b.getType()){g={AB:[],AW:[],AE:[]};
     59 for(k=1;k<=b.getSize().x;k++)for(d=1;d<=b.getSize().y;d++)(f=b.getSetup(k,d))&&g[f].push({x:k,y:d});a+=m(g)}g={CR:[],SQ:[],TR:[],MA:[],SL:[],LB:[]};for(k=1;k<=b.getSize().x;k++)for(d=1;d<=b.getSize().y;d++)if(f=b.getMarkup(k,d))"string"===typeof f?g.LB.push({x:k,y:d,label:f}):(f=["CR","SQ","TR","MA","SL"][f-1],g[f].push({x:k,y:d}));a+=m(g);b.comment&&(a=a+(a?"n":"")+("C["+t(b.comment)+"]"));a=h+a;if(1===c.length)a+="n"+l(c[0]);else if(1<c.length)for(b=0;b<c.length;b++)a+="n("+l(c[b])+")";return a}
     60 function m(b){var a="",c,g;for(c in b)if(b.hasOwnProperty(c)){var f=b[c];if(0<f.length)for(a+=c,g=0;g<f.length;g++)a+="["+w(f[g].x,f[g].y),f[g].label&&(a+=":"+t(f[g].label)),a+="]"}return a}function t(b){b=b.replace(/\/g,"\\");return b.replace(/]/g,"\]")}function w(b,a){return 0===b||0===a?"":e(b)+e(a)}function e(b){return 26<b?String.fromCharCode(65+b-27):String.fromCharCode(97+b-1)}return"("+l(q.getRoot())+")"};(function(){besogo.RED="#be0119";besogo.LRED="#ff474c";besogo.BLUE="#0165fc";besogo.PURP="#9a0eea";besogo.GREY="#929591";besogo.GOLD="#dbb40c";besogo.TURQ="#06c2ac";besogo.BLACK_STONES=4;besogo.WHITE_STONES=11;besogo.svgEl=function(q,l){var m;q=document.createElementNS("http://www.w3.org/2000/svg",q);for(m in l||{})l.hasOwnProperty(m)&&q.setAttribute(m,l[m]);return q};besogo.svgShadowGroup=function(){var q=besogo.svgEl("g"),l=besogo.svgEl("filter",{id:"blur"}),m=besogo.svgEl("feGaussianBlur",{in:"SourceGraphic",
     61 stdDeviation:"2"});l.appendChild(m);q.appendChild(l);return q};besogo.svgShadow=function(q,l){return besogo.svgEl("circle",{cx:q,cy:l,r:43,stroke:"none",fill:"black",opacity:.32,filter:"url(#blur)"})};besogo.realStone=function(q,l,m,t){m=0>m?"black"+t%besogo.BLACK_STONES:"white"+t%besogo.WHITE_STONES;m="/besogo/img/"+m+".png";q=besogo.svgEl("image",{x:q-44,y:l-44,height:88,width:88});q.setAttributeNS("http://www.w3.org/1999/xlink","href",m);return q};besogo.svgStone=function(q,l,m){var t="besogo-svg-greyStone";
     62 -1===m?t="besogo-svg-blackStone":1===m&&(t="besogo-svg-whiteStone");return besogo.svgEl("circle",{cx:q,cy:l,r:42,"class":t})};besogo.svgCircle=function(q,l,m){return besogo.svgEl("circle",{cx:q,cy:l,r:27,stroke:m,"stroke-width":8,fill:"none"})};besogo.svgSquare=function(q,l,m){return besogo.svgEl("rect",{x:q-23,y:l-23,width:46,height:46,stroke:m,"stroke-width":8,fill:"none"})};besogo.svgTriangle=function(q,l,m){return besogo.svgEl("polygon",{points:""+q+","+(l-30)+" "+(q-26)+","+(l+15)+" "+(q+26)+
     63 ","+(l+15),stroke:m,"stroke-width":8,fill:"none"})};besogo.svgCross=function(q,l,m){return besogo.svgEl("path",{d:"m"+(q-24)+","+(l-24)+"l48,48m0,-48l-48,48",stroke:m,"stroke-width":8,fill:"none"})};besogo.svgPlus=function(q,l,m){return besogo.svgEl("path",{d:"m"+q+","+(l-28)+"v56m-28,-28h56",stroke:m,"stroke-width":8,fill:"none"})};besogo.svgBlock=function(q,l,m){return besogo.svgEl("rect",{x:q-18,y:l-18,width:36,height:36,stroke:"none","stroke-width":8,fill:m})};besogo.svgLabel=function(q,l,m,t){3<
     64 t.length&&(t=t.slice(0,2)+"u2026");switch(t.length){case 1:var w=72;break;case 2:w=56;break;case 3:w=36}q=besogo.svgEl("text",{x:q,y:l,dy:".65ex","font-size":w,"text-anchor":"middle","font-family":"Helvetica, Arial, sans-serif",fill:m});q.appendChild(document.createTextNode(t));return q}})();besogo.makeToolPanel=function(q,l){function m(g,f){var k=document.createElement("button"),d=besogo.svgEl("svg",{width:"100%",height:"100%",viewBox:"-55 -55 110 110"}),p=besogo.svgEl("rect",{x:-50,y:-50,width:100,height:100,fill:"none","stroke-width":8,stroke:besogo.GOLD,rx:20,ry:20,visibility:"hidden"});q.appendChild(k);k.appendChild(d);k.onclick=function(){"auto"===g&&"auto"===l.getTool()?l.setTool("navOnly"):l.setTool(g)};k.title=f;e[g]=p;d.appendChild(p);return d}function t(g,f,k){var d=document.createElement("input");
     65 d.type="button";d.value=g;d.title=f;d.onclick=k;q.appendChild(d)}function w(g){var f;g.label&&(c.value=g.label);if(g.tool)for(f in e)e.hasOwnProperty(f)&&(g.tool===f?e[f].setAttribute("visibility","visible"):e[f].setAttribute("visibility","hidden"))}var e={};var b=m("auto","Auto-play/navigatencrtl+click to force ko, suicide, overwritenshift+click to jump to move");b.appendChild(function(g,f){var k=besogo.svgEl("g");k.appendChild(besogo.svgEl("path",{d:"m"+g+","+(f-44)+" a44 44 0 0 1 0,88z",stroke:"none",
     66 fill:"black"}));k.appendChild(besogo.svgEl("path",{d:"m"+g+","+(f+44)+"a44 44 0 0 1 0,-88a22 22 0 0 1 0,44z",stroke:"none",fill:"white"}));k.appendChild(besogo.svgEl("circle",{cx:g,cy:f+22,r:22,stroke:"none",fill:"black"}));return k}(0,0));b=m("addB","Set blacknctrl+click to play");var a=besogo.svgEl("g");a.appendChild(besogo.svgStone(0,0,-1));b.appendChild(a);b=m("addW","Set whitenctrl+click to play");a=besogo.svgEl("g");a.appendChild(besogo.svgStone(0,0,1));b.appendChild(a);b=m("addE","Set empty point");
     67 a=besogo.svgEl("g");a.appendChild(besogo.svgStone(0,0));a.appendChild(besogo.svgCross(0,0,besogo.RED));b.appendChild(a);b=m("circle","Circle");b.appendChild(besogo.svgCircle(0,0,"black"));b=m("square","Square");b.appendChild(besogo.svgSquare(0,0,"black"));b=m("triangle","Triangle");b.appendChild(besogo.svgTriangle(0,0,"black"));b=m("cross","Cross");b.appendChild(besogo.svgCross(0,0,"black"));b=m("block","Block");b.appendChild(besogo.svgBlock(0,0,"black"));b=m("clrMark","Clear mark");a=besogo.svgEl("g");
     68 a.appendChild(besogo.svgTriangle(0,0,besogo.GREY));a.appendChild(besogo.svgCross(0,0,besogo.RED));b.appendChild(a);b=m("label","Label");b.appendChild(besogo.svgLabel(0,0,"black","A1"));var c=document.createElement("input");c.type="text";c.title="Next label";c.onblur=function(){l.setLabel(c.value)};c.addEventListener("keydown",function(g){g=g||window.event;g.stopPropagation()});q.appendChild(c);t("Pass","Pass move",function(){var g=l.getTool();"navOnly"!==g&&"auto"!==g&&"playB"!==g&&"playW"!==g&&l.setTool("auto");
     69 l.click(0,0,!1)});t("Raise","Raise variation",function(){l.promote()});t("Lower","Lower variation",function(){l.demote()});t("Cut","Remove branch",function(){l.cutCurrent()});l.addListener(w);w({label:l.getLabel(),tool:l.getTool()})};besogo.makeTreePanel=function(q,l){function m(h){var u=q.clientWidth,v=q.clientHeight,r=q.scrollTop,B=q.scrollLeft,D=.25*(h.getAttribute("x")-5),n=.25*(h.getAttribute("y")-5);D<B?q.scrollLeft=D:D+30>B+u&&(q.scrollLeft=D+30-u);n<r?q.scrollTop=n:n+30>r+v&&(q.scrollTop=n+30-v);h.setAttribute("opacity",1);h.onmouseover=null;h.onmouseout=null;d.appendChild(h);p=h}function t(h){h.setAttribute("opacity",0);h.onmouseover=function(){h.setAttribute("opacity",.5)};h.onmouseout=function(){h.setAttribute("opacity",
     70 0)};f.appendChild(h)}function w(){var h=l.getCurrent(),u=l.getRoot(),v=[],r=f,B=besogo.svgEl("rect",{height:"100%",width:"100%","class":"besogo-svg-board besogo-svg-backer"});f=besogo.svgEl("svg");d=besogo.svgEl("g");k=besogo.svgEl("g");f.appendChild(B);f.appendChild(d);f.appendChild(k);u=e(u,0,0,v);k.appendChild(g(u,"black"));u=120*v.length;v=120*Math.max.apply(Math,v);f.setAttribute("viewBox","0 0 "+u+" "+v);f.setAttribute("height",.25*v);f.setAttribute("width",.25*u);r?q.replaceChild(f,r):q.appendChild(f);
     71 m(h.navTreeMarker)}function e(h,u,v,r){var B=h.children,D;if(0===B.length)var n="m"+(120*u+60)+","+(120*v+60);else{var z=r[u+1]||0;z=z<v?v:z;v<z-1&&(v=z-1);n=e(B[0],u+1,z,r)+c(u,v,r);for(D=1;D<B.length;D++)z=r[u+1],z=e(B[D],u+1,z,r)+c(u,v,r,z-1),k.appendChild(g(z,"black"))}f.appendChild(b(h,u,v));a(h,u,v);r[u]=v+1;return n}function b(h,u,v){switch(h.getType()){case "move":var r=h.move.color;var B=besogo.svgEl("g");B.appendChild(besogo.svgStone(120*u+60,120*v+60,r));B.appendChild(besogo.svgLabel(120*
     72 u+60,120*v+60,-1===r?"white":"black",""+h.moveNumber));break;case "setup":B=besogo.svgEl("g");B.appendChild(besogo.svgStone(120*u+60,120*v+60));B.appendChild(besogo.svgPlus(120*u+60,120*v+60,besogo.RED));break;default:B=besogo.svgStone(120*u+60,120*v+60)}h.navTreeIcon=B;h.navTreeX=u;h.navTreeY=v;return B}function a(h,u,v){u=besogo.svgEl("rect",{x:120*u+60-55,y:120*v+60-55,width:110,height:110,fill:besogo.TURQ});u.onclick=function(){l.setCurrent(h)};h.navTreeMarker=u;t(u)}function c(h,u,v,r){h=v[h+
     73 1]-1;return h===u?"h-120":h===u+1?"l-120,-120":r&&r!==u?"l-60,-60v-"+120*(h-r):"l-60,-60v-"+120*(h-u-1)+"l-60,-60"}function g(h,u){return besogo.svgEl("path",{d:h,stroke:u,"stroke-width":8,fill:"none"})}var f,k,d,p;w();l.addListener(function(h){if(h.treeChange)w();else if(h.navChange)h=l.getCurrent(),t(p),m(h.navTreeMarker);else if(h.stoneChange){var u=l.getCurrent();h=u.navTreeIcon;u=b(u,u.navTreeX,u.navTreeY);f.replaceChild(u,h)}})};