stimulsoft-dashboards-js-vuejs 2025.3.2 → 2025.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  Stimulsoft.Reports.JS
3
- Version: 2025.3.2
4
- Build date: 2025.07.17
3
+ Version: 2025.3.3
4
+ Build date: 2025.07.28
5
5
  License: https://www.stimulsoft.com/en/licensing/reports
6
6
  */
7
7
  import{Stimulsoft}from"./stimulsoft.designer.mjs";(t=>{var e,o;o=e=t.ExternalLibrary||(t.ExternalLibrary={})})(Stimulsoft),((t,e)=>{t.Blockly=e(),Stimulsoft.ExternalLibrary.Blockly=t.Blockly})(this||window,function(){var T={connectionTypes:{INPUT_VALUE:1,OUTPUT_VALUE:2,NEXT_STATEMENT:3,PREVIOUS_STATEMENT:4}},t,e;function o(t){return-1!=e.indexOf(t.toUpperCase())}return T.spritesBase64="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAB8CAQAAAA8hX1TAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAADdcAAA3XAUIom3gAAAkESURBVHja7ZxrbBTXFcePwdiY0LRQ8AMopQ0NzxZCgEB5KeShRBFSPkRtVbX0G1+qKBVVRcSrG8W79393kYuNGzBN0tYJIRgloV+SqA0lwkSxHTcPaKvKBmogSYMNmLW9gIN3//2wr5nZmfXu2uB1NHe+eHfmP3t+955z7rnjmRH5yrblUpDF0ffll/EVUidhGZuFYkAa5Nv5Yfw4eUqCQmECYImEhTZbRFYnVGGhhMQjJSNt/gY5nTAwOQIv2gK8ZNDFES/Ixqxcb1jbXHnLZGASoCw2JsYtJDNtACiUd2Xx7Td+slTLTYuJxhh4OgVgu0lvdrKw1EvZ7TO+UDZJl42LGAGKpM2077xMSANAoXTLFim+fQCdgwCIPG7a94TlHCMKkIkLiYi8ndhzIiVQR9SFkkH8ZlqA+THEsNybojUH8aJ8S6PxVisUSp2NLi/SqNNElmyT5JIEpdwBICQeGZ/vpcSTsjnfS4n0xVyhFI2GYs5tedC4nGOyOHpFfhlfwTqGmcV6gANsYH4EMYv4FIMkGQfgPQzTrkWYWA8wTDJEcGJGOa5efnmrzN/AMwkDEyPAF20B6g26OOIFbmT6iWy8fChHpPBWGD+Xb5kMTAKU8WqK+SHOtAEgySamS6p7pU2+NvzGT2Y1b1pMNMQAt6QAbDPpzU4WZj3ti7l18qUsHW7jC7mJXTYuMtYUGW2mfec5IQ0ASfbSQ2s5XST/lurh7/1CbmJnegARPm7aZ1kP2AB0cwuTs/YMmSIim6RTvnFrgndSehcSEeHbiT0nrIFq40KlpgNOyWWZI2ctC9FhhpjDN9MCzOeXMfNS1gMmgGNMXQ88LANyRXpl8q2eBTbwtBOACGtJkvtsdOFEbGx0OPU2oVTdjolsnHUiMznaJQZZ7gAQoofO64ECKcvqWt+QS4kBu1KCT3KzYykxM7/qoWV2MyoLWWRf+rnlr9vc5ja3ffUaZuIM6Lzp8/67RrH5eY6Qifl5g4CbmZia3eYZ4wK4AC6AC+C20dZYMBzbyE1n4VHu/aMfIDLKAdRoT6DDNgMUugAugAvgArgALoAL4AK4AC6AC5Dj1jB2pAAGRvuCxgVwAVwAF8AFcAFcABfABXABXAAXYNQCXBkWgB4ZqYbDwwGgG0YMQM3G5SEDXNYzREYS4dAQHOmKblCzJb8aGtGcvcozHo9hP1rRhQgiuIRW7MdjnvFZ6y8hggi60KrrstFbMlN213kqp+s69NqOUC/2V04fXI/9Q9EPCaCqRPkQAhFBi97mWxkoZQELAqW+ldiKFkRAhJSvqsRZDxXXY6u9Ht4MR6JuHFbrnyMM6l/419SNG1yhp6EFRAQH7SNBzcZBREC06Gnp9PoV+xs5E/pme73x0HvUy+g2DV83Dqh7047VInwKol2nfU5PL0U7iM/8i617/IvxGYi29L+ilqEdxKep+kTzTcWB6H0r6hNVr/3Qqh4fgdG+CZTaq/zluACq476pg7rZZPwNxOfmdOutyEL/Tqo+2Y/fx1kQ1zQC3zGRz4p6p+rAIlvfbQbx90wcTaRuHN4B0ZKMhaoStIA4mrH+KIhmm1jwLkQQxHuV33LID40gelIRVCWI9qqMH3Krmox2UFUmus2btf40iGdTnecsqBtqHN+I4inSr4Cqw+xI3gr0IaJtn2Py3edbaRsLyxFBKBqMehpCiKhl2WRHvRwR9HkrzO7zEogPqkrSD596F8QB08n2gjjkENpB9NnfRadfBbFPRAT7QP1q1jPUIVDvNWeRMK7vGvS5eD0D1xD2L0mOCoKI+O52+JmwU3ntuxsRBGuKa4oRRMT/vWwBonpP8qk29ScQAYvL3KkfUA/i6xYEgOrlhO4REK2O/RR2Xh+gFcSjeBTEBzmVOf8A1SOxDw1j0QUa+5EF2IprIIhr2G50AzULxNU4u/o9iJ25AOgdoN6L50C9IyeAnSCei59sBYh/mXY/baryTQ+g4ySI2BsN0AT61+Q0AqtBNKM5ea7smn8NiKb4yX4C4qDBeSaizzQTX/PcaQn3n8X+vghaskGGAN4yEJ3oBP3lOQGUg7go6njCSMPTvlhrrQXVesNenfi+CTdAY+JVyxByXDGE9ApjUgbRj37QEIqil6fT+wzvS6gpBnFDcBQEEQbxO8vwmJeK9xsAArFvB3AM10HjnOhfgh5HAy4ZZ4uaYhD91g7QS9Pou4yzhWc8iBtxk35kzuWBOyyn6dOGd0HgAIifJl3IuTpM50L+8rgLObtguuatAHExOXDEf0w/vdnkQL8x7fsniB/G/n4f9K/LKYjXgmhCE4i1OcXAOhDvx4djDL4A9RxTmvsVgtELJerXxjTqvwvE5fgNBWoPiGdyAVAeELWoBZUnpzT6DKj2JD++AGK3tcr0rfKt8kyw5O9dIP6c+PQQiI9zGoGPQf2QehjERzldgvgEVA8mT7cAA+gf/KE2NQvXEQ78wFDcdoO++VmXEvOj06GnCFdBPS/rUmI+iG5TAY4XQHxo7e+U6wVNIP5oQtoD4nUHgKvotS/m8DqIWhER1IJ4LWsHesPkQCIiahLaQPUXZ4SqErwG4rS5cg+Uogf0rbINtMXJss/Uf6tA9HjLYhNaLyLxpJCh+atB9KSsD31zcQVEq8Oi/LtoAdGd6i7YmbpKSDv8U1WHsYLSvwXx38GXk8kuUx0OFZSegzYQ/ara7JV6HnajH0S7nbd7itAIorEmo5dDeorUcRCNyfnXU6RPgOp4ZvqaYqve4kj6D7EL7W04rKqxG4fRFpt3n3da9vm+iTMg3vMO+orIXVNwDMQ585G7pmSrTzveeh724wvTTNyJ57EgrVcuUB2g6nCuTKMliuoAcc670EmfvjL1r8E5UHWktyU2teml+gmEQfVjtSyTq3OBUjSCII6kmhdL1EdAEI32vRco1SdAEG/Ym+ddGNWr45lHW5aXFj1F2B6dvfUpVanWV073TAzcUTldrVeVOAmCCGK7g+9GY2FHrAY7iWf1/Ua9PhXV623O+mG5uOubqqod/s9wWVUPnmmGqrcC/BXHcri8XqjWYzca8T/0oQ+foxG79QOZ344Z1esTRr1ab6//P5G7ylGflo+2AAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTA5LTIzVDE5OjI2OjQ4KzAwOjAwGMCiogAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0wOS0yM1QxOToyNjo0OCswMDowMGmdGh4AAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC",T.constants={},T.LINE_MODE_MULTIPLIER=40,T.PAGE_MODE_MULTIPLIER=125,T.DRAG_RADIUS=5,T.FLYOUT_DRAG_RADIUS=10,T.SNAP_RADIUS=28,T.CONNECTING_SNAP_RADIUS=T.SNAP_RADIUS,T.CURRENT_CONNECTION_PREFERENCE=8,T.BUMP_DELAY=250,T.BUMP_RANDOMNESS=10,T.COLLAPSE_CHARS=30,T.LONGPRESS=750,T.SOUND_LIMIT=100,T.DRAG_STACK=!0,T.HSV_SATURATION=.45,T.HSV_VALUE=.65,T.SPRITE={width:96,height:124,url:"sprites.png"},T.constants.ALIGN={LEFT:-1,CENTRE:0,RIGHT:1},T.DRAG_NONE=0,T.DRAG_STICKY=1,T.DRAG_BEGIN=1,T.DRAG_FREE=2,T.OPPOSITE_TYPE=[],T.OPPOSITE_TYPE[T.connectionTypes.INPUT_VALUE]=T.connectionTypes.OUTPUT_VALUE,T.OPPOSITE_TYPE[T.connectionTypes.OUTPUT_VALUE]=T.connectionTypes.INPUT_VALUE,T.OPPOSITE_TYPE[T.connectionTypes.NEXT_STATEMENT]=T.connectionTypes.PREVIOUS_STATEMENT,T.OPPOSITE_TYPE[T.connectionTypes.PREVIOUS_STATEMENT]=T.connectionTypes.NEXT_STATEMENT,T.DELETE_AREA_NONE=null,T.DELETE_AREA_TRASH=1,T.DELETE_AREA_TOOLBOX=2,T.VARIABLE_CATEGORY_NAME="VARIABLE",T.VARIABLE_DYNAMIC_CATEGORY_NAME="VARIABLE_DYNAMIC",T.PROCEDURE_CATEGORY_NAME="PROCEDURE",T.RENAME_VARIABLE_ID="RENAME_VARIABLE_ID",T.DELETE_VARIABLE_ID="DELETE_VARIABLE_ID",T.constants.COLLAPSED_INPUT_NAME="_TEMP_COLLAPSED_INPUT",T.constants.COLLAPSED_FIELD_NAME="_TEMP_COLLAPSED_FIELD",T.utils={},T.utils.global=function(){return"object"==typeof self?self:"object"==typeof window?window:"object"==typeof global?global:this}(),T.Msg={},T.utils.global.Blockly||(T.utils.global.Blockly={}),T.utils.global.Blockly.Msg||(T.utils.global.Blockly.Msg=T.Msg),T.utils.colour={},T.utils.colour.parse=function(t){t=String(t).toLowerCase().trim();var e=T.utils.colour.names[t];if(e)return e;if(e="#"==(e="0x"==t.substring(0,2)?"#"+t.substring(2):t)[0]?e:"#"+e,/^#[0-9a-f]{6}$/.test(e))return e;if(/^#[0-9a-f]{3}$/.test(e))return["#",e[1],e[1],e[2],e[2],e[3],e[3]].join("");var o=t.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return o&&(t=Number(o[1]),e=Number(o[2]),o=Number(o[3]),0<=t)&&t<256&&0<=e&&e<256&&0<=o&&o<256?T.utils.colour.rgbToHex(t,e,o):null},T.utils.colour.rgbToHex=function(t,e,o){return e=t<<16|e<<8|o,t<16?"#"+(16777216|e).toString(16).substr(1):"#"+e.toString(16)},T.utils.colour.hexToRgb=function(t){if(!(t=T.utils.colour.parse(t)))return[0,0,0];return[(t=parseInt(t.substr(1),16))>>16,t>>8&255,255&t]},T.utils.colour.hsvToHex=function(t,e,o){var i=0,s=0,n=0;if(0==e)n=s=i=o;else{var r=Math.floor(t/60),l=t/60-r,a=(t=o*(1-e),o*(1-e*l));switch(e=o*(1-e*(1-l)),r){case 1:i=a,s=o,n=t;break;case 2:i=t,s=o,n=e;break;case 3:i=t,s=a,n=o;break;case 4:i=e,s=t,n=o;break;case 5:i=o,s=t,n=a;break;case 6:case 0:i=o,s=e,n=t}}return T.utils.colour.rgbToHex(Math.floor(i),Math.floor(s),Math.floor(n))},T.utils.colour.blend=function(t,e,o){if(!(t=T.utils.colour.parse(t)))return null;if(!(e=T.utils.colour.parse(e)))return null;return t=T.utils.colour.hexToRgb(t),e=T.utils.colour.hexToRgb(e),T.utils.colour.rgbToHex(Math.round(e[0]+o*(t[0]-e[0])),Math.round(e[1]+o*(t[1]-e[1])),Math.round(e[2]+o*(t[2]-e[2])))},T.utils.colour.names={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00"},T.utils.Coordinate=function(t,e){this.x=t,this.y=e},T.utils.Coordinate.equals=function(t,e){return t==e||!(!t||!e)&&t.x==e.x&&t.y==e.y},T.utils.Coordinate.distance=function(t,e){var o=t.x-e.x;return t=t.y-e.y,Math.sqrt(o*o+t*t)},T.utils.Coordinate.magnitude=function(t){return Math.sqrt(t.x*t.x+t.y*t.y)},T.utils.Coordinate.difference=function(t,e){return new T.utils.Coordinate(t.x-e.x,t.y-e.y)},T.utils.Coordinate.sum=function(t,e){return new T.utils.Coordinate(t.x+e.x,t.y+e.y)},T.utils.Coordinate.prototype.scale=function(t){return this.x*=t,this.y*=t,this},T.utils.Coordinate.prototype.translate=function(t,e){return this.x+=t,this.y+=e,this},T.utils.Rect=function(t,e,o,i){this.top=t,this.bottom=e,this.left=o,this.right=i},T.utils.Rect.prototype.contains=function(t,e){return t>=this.left&&t<=this.right&&e>=this.top&&e<=this.bottom},T.utils.Rect.prototype.intersects=function(t){return!(this.left>t.right||this.right<t.left||this.top>t.bottom||this.bottom<t.top)},T.utils.string={},T.utils.string.startsWith=function(t,e){return 0==t.lastIndexOf(e,0)},T.utils.string.shortestStringLength=function(t){return t.length?t.reduce(function(t,e){return t.length<e.length?t:e}).length:0},T.utils.string.commonWordPrefix=function(t,e){if(!t.length)return 0;if(1==t.length)return t[0].length;var o=0;e=e||T.utils.string.shortestStringLength(t);for(var i=0;i<e;i++){for(var s=t[0][i],n=1;n<t.length;n++)if(s!=t[n][i])return o;" "==s&&(o=i+1)}for(n=1;n<t.length;n++)if((s=t[n][i])&&" "!=s)return o;return e},T.utils.string.commonWordSuffix=function(t,e){if(!t.length)return 0;if(1==t.length)return t[0].length;var o=0;e=e||T.utils.string.shortestStringLength(t);for(var i=0;i<e;i++){for(var s=t[0].substr(-i-1,1),n=1;n<t.length;n++)if(s!=t[n].substr(-i-1,1))return o;" "==s&&(o=i+1)}for(n=1;n<t.length;n++)if((s=t[n].charAt(t[n].length-i-1))&&" "!=s)return o;return e},T.utils.string.wrap=function(t,e){t=t.split("\n");for(var o=0;o<t.length;o++)t[o]=T.utils.string.wrapLine_(t[o],e);return t.join("\n")},T.utils.string.wrapLine_=function(t,e){if(t.length<=e)return t;for(var o=t.trim().split(/\s+/),i=0;i<o.length;i++)o[i].length>e&&(e=o[i].length);i=-(1/0);var s=1;do{for(var n=i,r=t,l=(t=[],o.length/s),a=1,i=0;i<o.length-1;i++)a<(i+1.5)/l?(a++,t[i]=!0):t[i]=!1;t=T.utils.string.wrapMutate_(o,t,e),i=T.utils.string.wrapScore_(o,t,e),t=T.utils.string.wrapToText_(o,t),s++}while(n<i);return r},T.utils.string.wrapScore_=function(t,e,o){for(var i=[0],s=[],n=0;n<t.length;n++)i[i.length-1]+=t[n].length,!0===e[n]?(i.push(0),s.push(t[n].charAt(t[n].length-1))):!1===e[n]&&i[i.length-1]++;for(t=Math.max.apply(Math,i),n=e=0;n<i.length;n++)e=(e-=2*Math.pow(Math.abs(o-i[n]),1.5))-Math.pow(t-i[n],1.5),-1!=".?!".indexOf(s[n])?e+=o/3:-1!=",;)]}".indexOf(s[n])&&(e+=o/4);return 1<i.length&&i[i.length-1]<=i[i.length-2]&&(e+=.5),e},T.utils.string.wrapMutate_=function(t,e,o){for(var i=T.utils.string.wrapScore_(t,e,o),s,n=0,r,l;n<e.length-1;n++){e[n]!=e[n+1]&&((r=[].concat(e))[n]=!r[n],r[n+1]=!r[n+1],i<(l=T.utils.string.wrapScore_(t,r,o)))&&(i=l,s=r)}return s?T.utils.string.wrapMutate_(t,s,o):e},T.utils.string.wrapToText_=function(t,e){for(var o=[],i=0;i<t.length;i++)o.push(t[i]),void 0!==e[i]&&o.push(e[i]?"\n":" ");return o.join("")},T.utils.Size=function(t,e){this.width=t,this.height=e},T.utils.Size.equals=function(t,e){return t==e||!(!t||!e)&&t.width==e.width&&t.height==e.height},T.utils.style={},T.utils.style.getSize=function(t){if("none"!=T.utils.style.getStyle_(t,"display"))return T.utils.style.getSizeWithDisplay_(t);var e=t.style,o=e.display,i=e.visibility,s=e.position,n=(e.visibility="hidden",e.position="absolute",e.display="inline",t.offsetWidth);return t=t.offsetHeight,e.display=o,e.position=s,e.visibility=i,new T.utils.Size(n,t)},T.utils.style.getSizeWithDisplay_=function(t){return new T.utils.Size(t.offsetWidth,t.offsetHeight)},T.utils.style.getStyle_=function(t,e){return T.utils.style.getComputedStyle(t,e)||T.utils.style.getCascadedStyle(t,e)||t.style&&t.style[e]},T.utils.style.getComputedStyle=function(t,e){return document.defaultView&&document.defaultView.getComputedStyle&&(t=document.defaultView.getComputedStyle(t,null))&&(t[e]||t.getPropertyValue(e))||""},T.utils.style.getCascadedStyle=function(t,e){return t.currentStyle?t.currentStyle[e]:null},T.utils.style.getPageOffset=function(t){var e=new T.utils.Coordinate(0,0),o=(t=t.getBoundingClientRect(),document.documentElement),o=new T.utils.Coordinate(window.pageXOffset||o.scrollLeft,window.pageYOffset||o.scrollTop);return e.x=t.left+o.x,e.y=t.top+o.y,e},T.utils.style.getViewportPageOffset=function(){var t=document.body,e=document.documentElement;return new T.utils.Coordinate(t.scrollLeft||e.scrollLeft,t.scrollTop||e.scrollTop)},T.utils.style.setElementShown=function(t,e){t.style.display=e?"":"none"},T.utils.style.isRightToLeft=function(t){return"rtl"==T.utils.style.getStyle_(t,"direction")},T.utils.style.getBorderBox=function(t){var e=T.utils.style.getComputedStyle(t,"borderLeftWidth"),o=T.utils.style.getComputedStyle(t,"borderRightWidth"),i=T.utils.style.getComputedStyle(t,"borderTopWidth");return t=T.utils.style.getComputedStyle(t,"borderBottomWidth"),{top:parseFloat(i),right:parseFloat(o),bottom:parseFloat(t),left:parseFloat(e)}},T.utils.style.scrollIntoContainerView=function(t,e,o){t=T.utils.style.getContainerOffsetToScrollInto(t,e,o),e.scrollLeft=t.x,e.scrollTop=t.y},T.utils.style.getContainerOffsetToScrollInto=function(t,e,o){var i=T.utils.style.getPageOffset(t),s=T.utils.style.getPageOffset(e),n=T.utils.style.getBorderBox(e),r=i.x-s.x-n.left,i=i.y-s.y-n.top,s=T.utils.style.getSizeWithDisplay_(t);return t=e.clientWidth-s.width,s=e.clientHeight-s.height,n=e.scrollLeft,e=e.scrollTop,o?(n+=r-t/2,e+=i-s/2):(n+=Math.min(r,Math.max(r-t,0)),e+=Math.min(i,Math.max(i-s,0))),new T.utils.Coordinate(n,e)},T.utils.userAgent={},t=T.utils.global.navigator&&T.utils.global.navigator.userAgent||"",T.utils.userAgent.raw=t,e=T.utils.userAgent.raw.toUpperCase(),T.utils.userAgent.IE=o("Trident")||o("MSIE"),T.utils.userAgent.EDGE=o("Edge"),T.utils.userAgent.JAVA_FX=o("JavaFX"),T.utils.userAgent.CHROME=(o("Chrome")||o("CriOS"))&&!T.utils.userAgent.EDGE,T.utils.userAgent.WEBKIT=o("WebKit")&&!T.utils.userAgent.EDGE,T.utils.userAgent.GECKO=o("Gecko")&&!T.utils.userAgent.WEBKIT&&!T.utils.userAgent.IE&&!T.utils.userAgent.EDGE,T.utils.userAgent.ANDROID=o("Android"),T.utils.userAgent.IPAD=o("iPad"),T.utils.userAgent.IPOD=o("iPod"),T.utils.userAgent.IPHONE=o("iPhone")&&!T.utils.userAgent.IPAD&&!T.utils.userAgent.IPOD,T.utils.userAgent.MAC=o("Macintosh"),T.utils.userAgent.TABLET=T.utils.userAgent.IPAD||T.utils.userAgent.ANDROID&&!o("Mobile")||o("Silk"),T.utils.userAgent.MOBILE=!T.utils.userAgent.TABLET&&(T.utils.userAgent.IPOD||T.utils.userAgent.IPHONE||T.utils.userAgent.ANDROID||o("IEMobile")),T.utils.noEvent=function(t){t.preventDefault(),t.stopPropagation()},T.utils.isTargetInput=function(t){return"textarea"==t.target.type||"text"==t.target.type||"number"==t.target.type||"email"==t.target.type||"password"==t.target.type||"search"==t.target.type||"tel"==t.target.type||"url"==t.target.type||t.target.isContentEditable||t.target.dataset&&"true"==t.target.dataset.isTextInput},T.utils.getRelativeXY=function(t){var e=new T.utils.Coordinate(0,0),o=t.getAttribute("x");return o&&(e.x=parseInt(o,10)),(o=t.getAttribute("y"))&&(e.y=parseInt(o,10)),(o=(o=t.getAttribute("transform"))&&o.match(T.utils.getRelativeXY.XY_REGEX_))&&(e.x+=Number(o[1]),o[3])&&(e.y+=Number(o[3])),(t=t.getAttribute("style"))&&-1<t.indexOf("translate")&&(t=t.match(T.utils.getRelativeXY.XY_STYLE_REGEX_))&&(e.x+=Number(t[1]),t[3])&&(e.y+=Number(t[3])),e},T.utils.getInjectionDivXY_=function(t){for(var e=0,o=0;t;){var i=T.utils.getRelativeXY(t);if(e+=i.x,o+=i.y,-1!=(" "+(t.getAttribute("class")||"")+" ").indexOf(" injectionDiv "))break;t=t.parentNode}return new T.utils.Coordinate(e,o)},T.utils.getRelativeXY.XY_REGEX_=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/,T.utils.getRelativeXY.XY_STYLE_REGEX_=/transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/,T.utils.isRightButton=function(t){return!(!t.ctrlKey||!T.utils.userAgent.MAC)||2==t.button},T.utils.mouseToSvg=function(t,e,o){var i=e.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,o=o||e.getScreenCTM().inverse(),i.matrixTransform(o)},T.utils.getScrollDeltaPixels=function(t){switch(t.deltaMode){default:return{x:t.deltaX,y:t.deltaY};case 1:return{x:t.deltaX*T.LINE_MODE_MULTIPLIER,y:t.deltaY*T.LINE_MODE_MULTIPLIER};case 2:return{x:t.deltaX*T.PAGE_MODE_MULTIPLIER,y:t.deltaY*T.PAGE_MODE_MULTIPLIER}}},T.utils.tokenizeInterpolation=function(t){return T.utils.tokenizeInterpolation_(t,!0)},T.utils.replaceMessageReferences=function(t){if("string"!=typeof t)return t;return(t=T.utils.tokenizeInterpolation_(t,!1)).length?String(t[0]):""},T.utils.checkMessageReferences=function(t){for(var e=!0,o=T.Msg,i=t.match(/%{BKY_[A-Z]\w*}/gi),s=0,n;s<i.length;s++){null==o[i[s].toUpperCase().slice(6,-1)]&&(console.warn("No message string for "+i[s]+" in "+t),e=!1)}return e},T.utils.tokenizeInterpolation_=function(t,e){var o=[],i=t.split(""),s=(i.push(""),0);t=[];for(var n=null,r=0;r<i.length;r++){var l=i[r];0==s?"%"==l?((l=t.join(""))&&o.push(l),t.length=0,s=1):t.push(l):1==s?"%"==l?(t.push(l),s=0):e&&"0"<=l&&l<="9"?(s=2,n=l,(l=t.join(""))&&o.push(l),t.length=0):s="{"==l?3:(t.push("%",l),0):2==s?"0"<=l&&l<="9"?n+=l:(o.push(parseInt(n,10)),r--,s=0):3==s&&(""==l?(t.splice(0,0,"%{"),r--,s=0):"}"!=l?t.push(l):(s=t.join(""),/[A-Z]\w*/i.test(s)&&(l=s.toUpperCase(),l=T.utils.string.startsWith(l,"BKY_")?l.substring(4):null)&&l in T.Msg?"string"==typeof(s=T.Msg[l])?Array.prototype.push.apply(o,T.utils.tokenizeInterpolation_(s,e)):o.push(e?String(s):s):o.push("%{"+s+"}"),s=t.length=0))}for((l=t.join(""))&&o.push(l),e=[],r=t.length=0;r<o.length;++r)("string"==typeof o[r]?t:((l=t.join(""))&&e.push(l),t.length=0,e)).push(o[r]);return(l=t.join(""))&&e.push(l),t.length=0,e},T.utils.genUid=function(){for(var t=T.utils.genUid.soup_.length,e=[],o=0;o<20;o++)e[o]=T.utils.genUid.soup_.charAt(Math.random()*t);return e.join("")},T.utils.genUid.soup_="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",T.utils.is3dSupported=function(){if(void 0!==T.utils.is3dSupported.cached_)return T.utils.is3dSupported.cached_;if(!T.utils.global.getComputedStyle)return!1;var t=document.createElement("p"),e="none",o={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"},i;for(i in document.body.insertBefore(t,null),o)if(void 0!==t.style[i]){if(t.style[i]="translate3d(1px,1px,1px)",!(e=T.utils.global.getComputedStyle(t)))return document.body.removeChild(t),!1;e=e.getPropertyValue(o[i])}return document.body.removeChild(t),T.utils.is3dSupported.cached_="none"!==e,T.utils.is3dSupported.cached_},T.utils.runAfterPageLoad=function(t){if("object"!=typeof document)throw Error("Blockly.utils.runAfterPageLoad() requires browser document.");var e=setInterval(function(){clearInterval(e),t()},10)},T.utils.getViewportBBox=function(){var t=T.utils.style.getViewportPageOffset();return new T.utils.Rect(t.y,document.documentElement.clientHeight+t.y,t.x,document.documentElement.clientWidth+t.x)},T.utils.arrayRemove=function(t,e){if(-1==(e=t.indexOf(e)))return!1;return t.splice(e,1),!0},T.utils.getDocumentScroll=function(){var t=document.documentElement,e=window;return T.utils.userAgent.IE&&e.pageYOffset!=t.scrollTop?new T.utils.Coordinate(t.scrollLeft,t.scrollTop):new T.utils.Coordinate(e.pageXOffset||t.scrollLeft,e.pageYOffset||t.scrollTop)},T.utils.getBlockTypeCounts=function(t,e){var o=Object.create(null),i=t.getDescendants(!0);for(e&&(t=t.getNextBlock())&&(t=i.indexOf(t),i.splice(t,i.length-t)),t=0;e=i[t];t++)o[e.type]?o[e.type]++:o[e.type]=1;return o},T.utils.screenToWsCoordinates=function(t,e){var o=e.x,i=(e=e.y,t.getInjectionDiv().getBoundingClientRect()),o=new T.utils.Coordinate(o-i.left,e-i.top);return e=t.getOriginOffsetInPixels(),T.utils.Coordinate.difference(o,e).scale(1/t.scale)},T.utils.parseBlockColour=function(t){var e="string"==typeof t?T.utils.replaceMessageReferences(t):t,o=Number(e);if(!isNaN(o)&&0<=o&&o<=360)return{hue:o,hex:T.utils.colour.hsvToHex(o,T.HSV_SATURATION,255*T.HSV_VALUE)};if(o=T.utils.colour.parse(e))return{hue:null,hex:o};throw o='Invalid colour: "'+e+'"',t!=e&&(o+=' (from "'+t+'")'),Error(o)},T.Touch={},T.Touch.TOUCH_ENABLED="ontouchstart"in T.utils.global||!!(T.utils.global.document&&document.documentElement&&"ontouchstart"in document.documentElement)||!(!T.utils.global.navigator||!T.utils.global.navigator.maxTouchPoints&&!T.utils.global.navigator.msMaxTouchPoints),T.Touch.touchIdentifier_=null,T.Touch.TOUCH_MAP={},T.utils.global.PointerEvent?T.Touch.TOUCH_MAP={mousedown:["pointerdown"],mouseenter:["pointerenter"],mouseleave:["pointerleave"],mousemove:["pointermove"],mouseout:["pointerout"],mouseover:["pointerover"],mouseup:["pointerup","pointercancel"],touchend:["pointerup"],touchcancel:["pointercancel"]}:T.Touch.TOUCH_ENABLED&&(T.Touch.TOUCH_MAP={mousedown:["touchstart"],mousemove:["touchmove"],mouseup:["touchend","touchcancel"]}),T.longPid_=0,T.longStart=function(t,e){T.longStop_(),t.changedTouches&&1!=t.changedTouches.length||(T.longPid_=setTimeout(function(){t.changedTouches&&(t.button=2,t.clientX=t.changedTouches[0].clientX,t.clientY=t.changedTouches[0].clientY),e&&e.handleRightClick(t)},T.LONGPRESS))},T.longStop_=function(){T.longPid_&&(clearTimeout(T.longPid_),T.longPid_=0)},T.Touch.clearTouchIdentifier=function(){T.Touch.touchIdentifier_=null},T.Touch.shouldHandleEvent=function(t){return!T.Touch.isMouseOrTouchEvent(t)||T.Touch.checkTouchIdentifier(t)},T.Touch.getTouchIdentifierFromEvent=function(t){return null!=t.pointerId?t.pointerId:t.changedTouches&&t.changedTouches[0]&&null!=t.changedTouches[0].identifier?t.changedTouches[0].identifier:"mouse"},T.Touch.checkTouchIdentifier=function(t){var e=T.Touch.getTouchIdentifierFromEvent(t);return null!=T.Touch.touchIdentifier_?T.Touch.touchIdentifier_==e:("mousedown"==t.type||"touchstart"==t.type||"pointerdown"==t.type)&&(T.Touch.touchIdentifier_=e,!0)},T.Touch.setClientFromTouch=function(t){var e;T.utils.string.startsWith(t.type,"touch")&&(e=t.changedTouches[0],t.clientX=e.clientX,t.clientY=e.clientY)},T.Touch.isMouseOrTouchEvent=function(t){return T.utils.string.startsWith(t.type,"touch")||T.utils.string.startsWith(t.type,"mouse")||T.utils.string.startsWith(t.type,"pointer")},T.Touch.isTouchEvent=function(t){return T.utils.string.startsWith(t.type,"touch")||T.utils.string.startsWith(t.type,"pointer")},T.Touch.splitEventByTouches=function(t){var e=[];if(t.changedTouches)for(var o=0;o<t.changedTouches.length;o++)e[o]={type:t.type,changedTouches:[t.changedTouches[o]],target:t.target,stopPropagation:function(){t.stopPropagation()},preventDefault:function(){t.preventDefault()}};else e.push(t);return e},T.browserEvents={},T.browserEvents.conditionalBind=function(t,e,s,n,r,o){var l=!1,i=function(t){var e=!r;t=T.Touch.splitEventByTouches(t);for(var o=0,i;i=t[o];o++)e&&!T.Touch.shouldHandleEvent(i)||(T.Touch.setClientFromTouch(i),s?n.call(s,i):n(i),l=!0)},a=[];if(T.utils.global.PointerEvent&&e in T.Touch.TOUCH_MAP)for(var c=0,h;h=T.Touch.TOUCH_MAP[e][c];c++)t.addEventListener(h,i,!1),a.push([t,h,i]);else if(t.addEventListener(e,i,!1),a.push([t,e,i]),e in T.Touch.TOUCH_MAP)for(var u=function(t){var e;i(t),l&&!o&&t.preventDefault()},c=0;h=T.Touch.TOUCH_MAP[e][c];c++)t.addEventListener(h,u,!1),a.push([t,h,u]);return a},T.browserEvents.bind=function(t,e,o,i){var s=function(t){o?i.call(o,t):i(t)},n=[];if(T.utils.global.PointerEvent&&e in T.Touch.TOUCH_MAP)for(var r=0,l;l=T.Touch.TOUCH_MAP[e][r];r++)t.addEventListener(l,s,!1),n.push([t,l,s]);else if(t.addEventListener(e,s,!1),n.push([t,e,s]),e in T.Touch.TOUCH_MAP)for(var a=function(t){var e;t.changedTouches&&1==t.changedTouches.length&&(e=t.changedTouches[0],t.clientX=e.clientX,t.clientY=e.clientY),s(t),t.preventDefault()},r=0;l=T.Touch.TOUCH_MAP[e][r];r++)t.addEventListener(l,a,!1),n.push([t,l,a]);return n},T.browserEvents.unbind=function(t){for(;t.length;){var e=t.pop(),o=e[2];e[0].removeEventListener(e[1],o,!1)}return o},T.registry={},T.registry.typeMap_={},T.registry.DEFAULT="default",T.registry.Type=function(t){this.name_=t},T.registry.Type.prototype.toString=function(){return this.name_},T.registry.Type.CONNECTION_CHECKER=new T.registry.Type("connectionChecker"),T.registry.Type.CURSOR=new T.registry.Type("cursor"),T.registry.Type.EVENT=new T.registry.Type("event"),T.registry.Type.FIELD=new T.registry.Type("field"),T.registry.Type.RENDERER=new T.registry.Type("renderer"),T.registry.Type.TOOLBOX=new T.registry.Type("toolbox"),T.registry.Type.THEME=new T.registry.Type("theme"),T.registry.Type.TOOLBOX_ITEM=new T.registry.Type("toolboxItem"),T.registry.Type.FLYOUTS_VERTICAL_TOOLBOX=new T.registry.Type("flyoutsVerticalToolbox"),T.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX=new T.registry.Type("flyoutsHorizontalToolbox"),T.registry.Type.METRICS_MANAGER=new T.registry.Type("metricsManager"),T.registry.register=function(t,e,o,i){if(!(t instanceof T.registry.Type)&&"string"!=typeof t||""==String(t).trim())throw Error('Invalid type "'+t+'". The type must be a non-empty string or a Blockly.registry.Type.');if(t=String(t).toLowerCase(),"string"!=typeof e||""==e.trim())throw Error('Invalid name "'+e+'". The name must be a non-empty string.');if(e=e.toLowerCase(),!o)throw Error("Can not register a null value");var s,s=(s=T.registry.typeMap_[t])||(T.registry.typeMap_[t]={});if(T.registry.validate_(t,o),!i&&s[e])throw Error('Name "'+e+'" with type "'+t+'" already registered.');s[e]=o},T.registry.validate_=function(t,e){switch(t){case String(T.registry.Type.FIELD):if("function"!=typeof e.fromJson)throw Error('Type "'+t+'" must have a fromJson function')}},T.registry.unregister=function(t,e){t=String(t).toLowerCase(),e=e.toLowerCase();var o=T.registry.typeMap_[t];o&&o[e]?delete T.registry.typeMap_[t][e]:console.warn("Unable to unregister ["+e+"]["+t+"] from the registry.")},T.registry.getItem_=function(t,e,o){t=String(t).toLowerCase(),e=e.toLowerCase();var i=T.registry.typeMap_[t];if(!i||!i[e]){if(e="Unable to find ["+e+"]["+t+"] in the registry.",o)throw Error(e+" You must require or register a "+t+" plugin.");return console.warn(e),null}return i[e]},T.registry.hasItem=function(t,e){return t=String(t).toLowerCase(),e=e.toLowerCase(),!!(t=T.registry.typeMap_[t])&&!!t[e]},T.registry.getClass=function(t,e,o){return T.registry.getItem_(t,e,o)},T.registry.getObject=function(t,e,o){return T.registry.getItem_(t,e,o)},T.registry.getClassFromOptions=function(t,e,o){return"function"==typeof(e=e.plugins[t.toString()]||T.registry.DEFAULT)?e:T.registry.getClass(t,e,o)},T.Events={},T.Events.group_="",T.Events.recordUndo=!0,T.Events.disabled_=0,T.Events.CREATE="create",T.Events.BLOCK_CREATE=T.Events.CREATE,T.Events.DELETE="delete",T.Events.BLOCK_DELETE=T.Events.DELETE,T.Events.CHANGE="change",T.Events.BLOCK_CHANGE=T.Events.CHANGE,T.Events.MOVE="move",T.Events.BLOCK_MOVE=T.Events.MOVE,T.Events.VAR_CREATE="var_create",T.Events.VAR_DELETE="var_delete",T.Events.VAR_RENAME="var_rename",T.Events.UI="ui",T.Events.BLOCK_DRAG="drag",T.Events.SELECTED="selected",T.Events.CLICK="click",T.Events.MARKER_MOVE="marker_move",T.Events.BUBBLE_OPEN="bubble_open",T.Events.TRASHCAN_OPEN="trashcan_open",T.Events.TOOLBOX_ITEM_SELECT="toolbox_item_select",T.Events.THEME_CHANGE="theme_change",T.Events.VIEWPORT_CHANGE="viewport_change",T.Events.COMMENT_CREATE="comment_create",T.Events.COMMENT_DELETE="comment_delete",T.Events.COMMENT_CHANGE="comment_change",T.Events.COMMENT_MOVE="comment_move",T.Events.FINISHED_LOADING="finished_loading",T.Events.BUMP_EVENTS=[T.Events.BLOCK_CREATE,T.Events.BLOCK_MOVE,T.Events.COMMENT_CREATE,T.Events.COMMENT_MOVE],T.Events.FIRE_QUEUE_=[],T.Events.fire=function(t){T.Events.isEnabled()&&(T.Events.FIRE_QUEUE_.length||setTimeout(T.Events.fireNow_,0),T.Events.FIRE_QUEUE_.push(t))},T.Events.fireNow_=function(){for(var t=T.Events.filter(T.Events.FIRE_QUEUE_,!0),e=T.Events.FIRE_QUEUE_.length=0,o,i;o=t[e];e++){o.workspaceId&&(i=T.Workspace.getById(o.workspaceId))&&i.fireChangeListener(o)}},T.Events.filter=function(t,e){t=t.slice(),e||t.reverse();for(var o=[],i=Object.create(null),s=0,n,r,l,a;n=t[s];s++){n.isNull()||(a=(l=i[r=[n.isUiEvent?T.Events.UI:n.type,n.blockId,n.workspaceId].join(" ")])?l.event:null,l?n.type==T.Events.MOVE&&l.index==s-1?(a.newParentId=n.newParentId,a.newInputName=n.newInputName,a.newCoordinate=n.newCoordinate,l.index=s):n.type==T.Events.CHANGE&&n.element==a.element&&n.name==a.name?a.newValue=n.newValue:n.type==T.Events.CLICK&&a.type==T.Events.BUBBLE_OPEN||(i[r]={event:n,index:s},o.push(n)):(i[r]={event:n,index:s},o.push(n)))}for(t=o.filter(function(t){return!t.isNull()}),e||t.reverse(),s=1;n=t[s];s++)n.type==T.Events.CHANGE&&"mutation"==n.element&&t.unshift(t.splice(s,1)[0]);return t},T.Events.clearPendingUndo=function(){for(var t=0,e;e=T.Events.FIRE_QUEUE_[t];t++)e.recordUndo=!1},T.Events.disable=function(){T.Events.disabled_++},T.Events.enable=function(){T.Events.disabled_--},T.Events.isEnabled=function(){return 0==T.Events.disabled_},T.Events.getGroup=function(){return T.Events.group_},T.Events.setGroup=function(t){T.Events.group_="boolean"==typeof t?t?T.utils.genUid():"":t},T.Events.getDescendantIds=function(t){var e=[];t=t.getDescendants(!1);for(var o=0,i;i=t[o];o++)e[o]=i.id;return e},T.Events.fromJson=function(t,e){var o=T.Events.get(t.type);if(!o)throw Error("Unknown event type.");return(o=new o).fromJson(t),o.workspaceId=e.id,o},T.Events.get=function(t){return T.registry.getClass(T.registry.Type.EVENT,t)},T.Events.disableOrphans=function(t){if((t.type==T.Events.MOVE||t.type==T.Events.CREATE)&&t.workspaceId){var e,o=(e=T.Workspace.getById(t.workspaceId)).getBlockById(t.blockId);if(o){t=T.Events.recordUndo;try{T.Events.recordUndo=!1;var i=o.getParent();if(i&&i.isEnabled())for(var s=o.getDescendants(!1),e=0,n;n=s[e];e++)n.setEnabled(!0);else if((o.outputConnection||o.previousConnection)&&!e.isDragging())do{o.setEnabled(!1),o=o.getNextBlock()}while(o)}finally{T.Events.recordUndo=t}}}},T.Events.Abstract=function(){this.isBlank=null,this.workspaceId=void 0,this.group=T.Events.getGroup(),this.recordUndo=T.Events.recordUndo},T.Events.Abstract.prototype.isUiEvent=!1,T.Events.Abstract.prototype.toJson=function(){var t={type:this.type};return this.group&&(t.group=this.group),t},T.Events.Abstract.prototype.fromJson=function(t){this.isBlank=!1,this.group=t.group},T.Events.Abstract.prototype.isNull=function(){return!1},T.Events.Abstract.prototype.run=function(t){},T.Events.Abstract.prototype.getEventWorkspace_=function(){var t;if(!(t=this.workspaceId?T.Workspace.getById(this.workspaceId):t))throw Error("Workspace is null. Event must have been generated from real Blockly events.");return t},T.utils.object={},T.utils.object.inherits=function(t,e){t.superClass_=e.prototype,t.prototype=Object.create(e.prototype),t.prototype.constructor=t},T.utils.object.mixin=function(t,e){for(var o in e)t[o]=e[o]},T.utils.object.deepMerge=function(t,e){for(var o in e)t[o]=null!=e[o]&&"object"==typeof e[o]?T.utils.object.deepMerge(t[o]||Object.create(null),e[o]):e[o];return t},T.utils.object.values=function(e){return Object.values?Object.values(e):Object.keys(e).map(function(t){return e[t]})},T.utils.xml={},T.utils.xml.NAME_SPACE="https://developers.google.com/blockly/xml",T.utils.xml.document=function(){return document},T.utils.xml.createElement=function(t){return T.utils.xml.document().createElementNS(T.utils.xml.NAME_SPACE,t)},T.utils.xml.createTextNode=function(t){return T.utils.xml.document().createTextNode(t)},T.utils.xml.textToDomDocument=function(t){return(new DOMParser).parseFromString(t,"text/xml")},T.utils.xml.domToText=function(t){return(new XMLSerializer).serializeToString(t)},T.inputTypes={VALUE:T.connectionTypes.INPUT_VALUE,STATEMENT:T.connectionTypes.NEXT_STATEMENT,DUMMY:5},T.utils.Svg=function(t){this.tagName_=t},T.utils.Svg.prototype.toString=function(){return this.tagName_},T.utils.Svg.ANIMATE=new T.utils.Svg("animate"),T.utils.Svg.CIRCLE=new T.utils.Svg("circle"),T.utils.Svg.CLIPPATH=new T.utils.Svg("clipPath"),T.utils.Svg.DEFS=new T.utils.Svg("defs"),T.utils.Svg.FECOMPOSITE=new T.utils.Svg("feComposite"),T.utils.Svg.FECOMPONENTTRANSFER=new T.utils.Svg("feComponentTransfer"),T.utils.Svg.FEFLOOD=new T.utils.Svg("feFlood"),T.utils.Svg.FEFUNCA=new T.utils.Svg("feFuncA"),T.utils.Svg.FEGAUSSIANBLUR=new T.utils.Svg("feGaussianBlur"),T.utils.Svg.FEPOINTLIGHT=new T.utils.Svg("fePointLight"),T.utils.Svg.FESPECULARLIGHTING=new T.utils.Svg("feSpecularLighting"),T.utils.Svg.FILTER=new T.utils.Svg("filter"),T.utils.Svg.FOREIGNOBJECT=new T.utils.Svg("foreignObject"),T.utils.Svg.G=new T.utils.Svg("g"),T.utils.Svg.IMAGE=new T.utils.Svg("image"),T.utils.Svg.LINE=new T.utils.Svg("line"),T.utils.Svg.PATH=new T.utils.Svg("path"),T.utils.Svg.PATTERN=new T.utils.Svg("pattern"),T.utils.Svg.POLYGON=new T.utils.Svg("polygon"),T.utils.Svg.RECT=new T.utils.Svg("rect"),T.utils.Svg.SVG=new T.utils.Svg("svg"),T.utils.Svg.TEXT=new T.utils.Svg("text"),T.utils.Svg.TSPAN=new T.utils.Svg("tspan"),T.utils.dom={},T.utils.dom.SVG_NS="http://www.w3.org/2000/svg",T.utils.dom.HTML_NS="http://www.w3.org/1999/xhtml",T.utils.dom.XLINK_NS="http://www.w3.org/1999/xlink",T.utils.dom.NodeType={ELEMENT_NODE:1,TEXT_NODE:3,COMMENT_NODE:8,DOCUMENT_POSITION_CONTAINED_BY:16},T.utils.dom.cacheWidths_=null,T.utils.dom.cacheReference_=0,T.utils.dom.canvasContext_=null,T.utils.dom.createSvgElement=function(t,e,o){for(var i in t=document.createElementNS(T.utils.dom.SVG_NS,String(t)),e)t.setAttribute(i,e[i]);return document.body.runtimeStyle&&(t.runtimeStyle=t.currentStyle=t.style),o&&o.appendChild(t),t},T.utils.dom.addClass=function(t,e){var o=t.getAttribute("class")||"";if(-1!=(" "+o+" ").indexOf(" "+e+" "))return!1;return o&&(o+=" "),t.setAttribute("class",o+e),!0},T.utils.dom.removeClasses=function(t,e){e=e.split(" ");for(var o=0;o<e.length;o++)T.utils.dom.removeClass(t,e[o])},T.utils.dom.removeClass=function(t,e){var o;if(-1==(" "+(o=t.getAttribute("class"))+" ").indexOf(" "+e+" "))return!1;for(var o=o.split(/\s+/),i=0;i<o.length;i++)o[i]&&o[i]!=e||(o.splice(i,1),i--);return o.length?t.setAttribute("class",o.join(" ")):t.removeAttribute("class"),!0},T.utils.dom.hasClass=function(t,e){return-1!=(" "+t.getAttribute("class")+" ").indexOf(" "+e+" ")},T.utils.dom.removeNode=function(t){return t&&t.parentNode?t.parentNode.removeChild(t):null},T.utils.dom.insertAfter=function(t,e){var o=e.nextSibling;if(!(e=e.parentNode))throw Error("Reference node has no parent.");o?e.insertBefore(t,o):e.appendChild(t)},T.utils.dom.containsNode=function(t,e){return!!(t.compareDocumentPosition(e)&T.utils.dom.NodeType.DOCUMENT_POSITION_CONTAINED_BY)},T.utils.dom.setCssTransform=function(t,e){t.style.transform=e,t.style["-webkit-transform"]=e},T.utils.dom.startTextWidthCache=function(){T.utils.dom.cacheReference_++,T.utils.dom.cacheWidths_||(T.utils.dom.cacheWidths_={})},T.utils.dom.stopTextWidthCache=function(){T.utils.dom.cacheReference_--,T.utils.dom.cacheReference_||(T.utils.dom.cacheWidths_=null)},T.utils.dom.getTextWidth=function(e){var t=e.textContent+"\n"+e.className.baseVal,o;if(T.utils.dom.cacheWidths_&&(o=T.utils.dom.cacheWidths_[t]))return o;try{o=T.utils.userAgent.IE||T.utils.userAgent.EDGE?e.getBBox().width:e.getComputedTextLength()}catch(t){return 8*e.textContent.length}return T.utils.dom.cacheWidths_&&(T.utils.dom.cacheWidths_[t]=o),o},T.utils.dom.getFastTextWidth=function(t,e,o,i){return T.utils.dom.getFastTextWidthWithSizeString(t,e+"pt",o,i)},T.utils.dom.getFastTextWidthWithSizeString=function(t,e,o,i){var s=t.textContent,n;if(t=s+"\n"+t.className.baseVal,T.utils.dom.cacheWidths_&&(n=T.utils.dom.cacheWidths_[t]))return n;return T.utils.dom.canvasContext_||((n=document.createElement("canvas")).className="blocklyComputeCanvas",document.body.appendChild(n),T.utils.dom.canvasContext_=n.getContext("2d")),T.utils.dom.canvasContext_.font=o+" "+e+" "+i,n=T.utils.dom.canvasContext_.measureText(s).width,T.utils.dom.cacheWidths_&&(T.utils.dom.cacheWidths_[t]=n),n},T.utils.dom.measureFontMetrics=function(t,e,o,i){var s=document.createElement("span");s.style.font=o+" "+e+" "+i,s.textContent=t,(t=document.createElement("div")).style.width="1px",t.style.height="0px",(e=document.createElement("div")).setAttribute("style","position: fixed; top: 0; left: 0; display: flex;"),e.appendChild(s),e.appendChild(t),document.body.appendChild(e);try{o={},e.style.alignItems="baseline",o.baseline=t.offsetTop-s.offsetTop,e.style.alignItems="flex-end",o.height=t.offsetTop-s.offsetTop}finally{document.body.removeChild(e)}return o},T.Xml={},T.Xml.workspaceToDom=function(t,e){for(var o=T.utils.xml.createElement("xml"),i,s=((i=T.Xml.variablesToDom(T.Variables.allUsedVarModels(t))).hasChildNodes()&&o.appendChild(i),t.getTopComments(!0)),i=0,n;n=s[i];i++)o.appendChild(n.toXmlWithXY(e));for(t=t.getTopBlocks(!0),i=0;s=t[i];i++)o.appendChild(T.Xml.blockToDomWithXY(s,e));return o},T.Xml.variablesToDom=function(t){for(var e=T.utils.xml.createElement("variables"),o=0,i;i=t[o];o++){var s=T.utils.xml.createElement("variable");s.appendChild(T.utils.xml.createTextNode(i.name)),i.type&&s.setAttribute("type",i.type),s.id=i.getId(),e.appendChild(s)}return e},T.Xml.blockToDomWithXY=function(t,e){if(t.isInsertionMarker()&&!(t=t.getChildren(!1)[0]))return new DocumentFragment;var o,i=(t.workspace.RTL&&(o=t.workspace.getWidth()),e=T.Xml.blockToDom(t,e),t.getRelativeToSurfaceXY());return e.setAttribute("x",Math.round(t.workspace.RTL?o-i.x:i.x)),e.setAttribute("y",Math.round(i.y)),e},T.Xml.fieldToDom_=function(t){var e;if(t.isSerializable())return(e=T.utils.xml.createElement("field")).setAttribute("name",t.name||""),t.toXml(e);return null},T.Xml.allFieldsToDom_=function(t,e){for(var o=0,i;i=t.inputList[o];o++)for(var s=0,n;n=i.fieldRow[s];s++)(n=T.Xml.fieldToDom_(n))&&e.appendChild(n)},T.Xml.blockToDom=function(t,e){if(t.isInsertionMarker())return(t=t.getChildren(!1)[0])?T.Xml.blockToDom(t):new DocumentFragment;var o=T.utils.xml.createElement(t.isShadow()?"shadow":"block"),i,s,n,r;for(o.setAttribute("type",t.type),e||o.setAttribute("id",t.id),t.mutationToDom&&(i=t.mutationToDom())&&(i.hasChildNodes()||i.hasAttributes())&&o.appendChild(i),T.Xml.allFieldsToDom_(t,o),(i=t.getCommentText())&&(s=t.commentModel.size,n=t.commentModel.pinned,(r=T.utils.xml.createElement("comment")).appendChild(T.utils.xml.createTextNode(i)),r.setAttribute("pinned",n),r.setAttribute("h",s.height),r.setAttribute("w",s.width),o.appendChild(r)),t.data&&((i=T.utils.xml.createElement("data")).appendChild(T.utils.xml.createTextNode(t.data)),o.appendChild(i)),i=0;s=t.inputList[i];i++){var l,a,n=!0;s.type!=T.inputTypes.DUMMY&&(a=s.connection.targetBlock(),s.type==T.inputTypes.VALUE?l=T.utils.xml.createElement("value"):s.type==T.inputTypes.STATEMENT&&(l=T.utils.xml.createElement("statement")),!(r=s.connection.getShadowDom())||a&&a.isShadow()||l.appendChild(T.Xml.cloneShadow_(r,e)),a&&(r=T.Xml.blockToDom(a,e)).nodeType==T.utils.dom.NodeType.ELEMENT_NODE&&(l.appendChild(r),n=!1),l.setAttribute("name",s.name),n||o.appendChild(l))}return null!=t.inputsInline&&t.inputsInline!=t.inputsInlineDefault&&o.setAttribute("inline",t.inputsInline),t.isCollapsed()&&o.setAttribute("collapsed",!0),t.isEnabled()||o.setAttribute("disabled",!0),t.isDeletable()||t.isShadow()||o.setAttribute("deletable",!1),t.isMovable()||t.isShadow()||o.setAttribute("movable",!1),t.isEditable()||o.setAttribute("editable",!1),(i=t.getNextBlock())&&(r=T.Xml.blockToDom(i,e)).nodeType==T.utils.dom.NodeType.ELEMENT_NODE&&((l=T.utils.xml.createElement("next")).appendChild(r),o.appendChild(l)),!(r=t.nextConnection&&t.nextConnection.getShadowDom())||i&&i.isShadow()||l.appendChild(T.Xml.cloneShadow_(r,e)),o},T.Xml.cloneShadow_=function(t,e){for(var o=t=t.cloneNode(!0),i;o;)if(e&&"shadow"==o.nodeName&&o.removeAttribute("id"),o.firstChild)o=o.firstChild;else{for(;o&&!o.nextSibling;)o=(i=o).parentNode,i.nodeType==T.utils.dom.NodeType.TEXT_NODE&&""==i.data.trim()&&o.firstChild!=i&&T.utils.dom.removeNode(i);o&&(o=(i=o).nextSibling,i.nodeType==T.utils.dom.NodeType.TEXT_NODE)&&""==i.data.trim()&&T.utils.dom.removeNode(i)}return t},T.Xml.domToText=function(t){return T.utils.xml.domToText(t).replace(/<(\w+)([^<]*)\/>/g,"<$1$2></$1>")},T.Xml.domToPrettyText=function(t){t=T.Xml.domToText(t).split("<");for(var e="",o=1;o<t.length;o++){var i=t[o];"/"==i[0]&&(e=e.substring(2)),t[o]=e+"<"+i,"/"!=i[0]&&"/>"!=i.slice(-2)&&(e+=" ")}return(t=(t=t.join("\n")).replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1</$2>")).replace(/^\n/,"")},T.Xml.textToDom=function(t){var e=T.utils.xml.textToDomDocument(t);if(!e||!e.documentElement||e.getElementsByTagName("parsererror").length)throw Error("textToDom was unable to parse: "+t);return e.documentElement},T.Xml.clearWorkspaceAndLoadFromXml=function(t,e){return e.setResizesEnabled(!1),e.clear(),t=T.Xml.domToWorkspace(t,e),e.setResizesEnabled(!0),t},T.Xml.domToWorkspace=function(t,e){var o,i,s=(t instanceof T.Workspace&&(o=t,t=e,e=o,console.warn("Deprecated call to Blockly.Xml.domToWorkspace, swap the arguments.")),e.RTL&&(i=e.getWidth()),o=[],T.utils.dom.startTextWidthCache(),T.Events.getGroup()),n=(s||T.Events.setGroup(!0),e.setResizesEnabled&&e.setResizesEnabled(!1),!0);try{for(var r=0,l;l=t.childNodes[r];r++){var a=l.nodeName.toLowerCase(),c=l;if("block"==a||"shadow"==a&&!T.Events.recordUndo){var h=T.Xml.domToBlock(c,e),u=(o.push(h.id),c.hasAttribute("x")?parseInt(c.getAttribute("x"),10):10),g=c.hasAttribute("y")?parseInt(c.getAttribute("y"),10):10;isNaN(u)||isNaN(g)||h.moveBy(e.RTL?i-u:u,g),n=!1}else{if("shadow"==a)throw TypeError("Shadow block cannot be a top-level block.");if("comment"==a)e.rendered?T.WorkspaceCommentSvg?T.WorkspaceCommentSvg.fromXml(c,e,i):console.warn("Missing require for Blockly.WorkspaceCommentSvg, ignoring workspace comment."):T.WorkspaceComment?T.WorkspaceComment.fromXml(c,e):console.warn("Missing require for Blockly.WorkspaceComment, ignoring workspace comment.");else if("variables"==a){if(!n)throw Error("'variables' tag must exist once before block and shadow tag elements in the workspace XML, but it was found in another location.");T.Xml.domToVariables(c,e),n=!1}}}}finally{s||T.Events.setGroup(!1),T.utils.dom.stopTextWidthCache()}return e.setResizesEnabled&&e.setResizesEnabled(!0),T.Events.fire(new(T.Events.get(T.Events.FINISHED_LOADING))(e)),o},T.Xml.appendDomToWorkspace=function(t,e){var o;if(Object.prototype.hasOwnProperty.call(e,"scale")&&(o=e.getBlocksBoundingBox()),t=T.Xml.domToWorkspace(t,e),o&&o.top!=o.bottom){for(var i=o.bottom,s=e.RTL?o.right:o.left,n=1/0,r=-(1/0),l=1/0,o=0;o<t.length;o++){var a=e.getBlockById(t[o]).getRelativeToSurfaceXY();a.y<l&&(l=a.y),a.x<n&&(n=a.x),r<a.x&&(r=a.x)}for(i=i-l+10,s=e.RTL?s-r:s-n,o=0;o<t.length;o++)e.getBlockById(t[o]).moveBy(s,i)}return t},T.Xml.domToBlock=function(t,e){var o;t instanceof T.Workspace&&(o=t,t=e,e=o,console.warn("Deprecated call to Blockly.Xml.domToBlock, swap the arguments.")),T.Events.disable(),o=e.getAllVariables();try{var i=T.Xml.domToBlockHeadless_(t,e),s=i.getDescendants(!1);if(e.rendered){i.setConnectionTracking(!1);for(var n=s.length-1;0<=n;n--)s[n].initSvg();for(n=s.length-1;0<=n;n--)s[n].render(!1);setTimeout(function(){i.disposed||i.setConnectionTracking(!0)},1),i.updateDisabled(),e.resizeContents()}else for(n=s.length-1;0<=n;n--)s[n].initModel()}finally{T.Events.enable()}if(T.Events.isEnabled()){for(t=T.Variables.getAddedVariables(e,o),n=0;n<t.length;n++)e=t[n],T.Events.fire(new(T.Events.get(T.Events.VAR_CREATE))(e));T.Events.fire(new(T.Events.get(T.Events.CREATE))(i))}return i},T.Xml.domToVariables=function(t,e){for(var o=0,i,s,n;i=t.childNodes[o];o++){i.nodeType==T.utils.dom.NodeType.ELEMENT_NODE&&(s=i.getAttribute("type"),n=i.getAttribute("id"),e.createVariable(i.textContent,s,n))}},T.Xml.mapSupportedXmlTags_=function(t){for(var e={mutation:[],comment:[],data:[],field:[],input:[],next:[]},o=0,i;i=t.childNodes[o];o++)if(i.nodeType!=T.utils.dom.NodeType.TEXT_NODE)switch(i.nodeName.toLowerCase()){case"mutation":e.mutation.push(i);break;case"comment":if(!T.Comment){console.warn("Missing require for Blockly.Comment, ignoring block comment.");break}e.comment.push(i);break;case"data":e.data.push(i);break;case"title":case"field":e.field.push(i);break;case"value":case"statement":e.input.push(i);break;case"next":e.next.push(i);break;default:console.warn("Ignoring unknown tag: "+i.nodeName)}return e},T.Xml.applyMutationTagNodes_=function(t,e){for(var o=!1,i=0,s;s=t[i];i++)e.domToMutation&&(e.domToMutation(s),e.initSvg)&&(o=!0);return o},T.Xml.applyCommentTagNodes_=function(t,e){for(var o=0,i;i=t[o];o++){var s=i.textContent,n="true"==i.getAttribute("pinned"),r=parseInt(i.getAttribute("w"),10),i=parseInt(i.getAttribute("h"),10);e.setCommentText(s),e.commentModel.pinned=n,isNaN(r)||isNaN(i)||(e.commentModel.size=new T.utils.Size(r,i)),n&&e.getCommentIcon&&!e.isInFlyout&&setTimeout(function(){e.getCommentIcon().setVisible(!0)},1)}},T.Xml.applyDataTagNodes_=function(t,e){for(var o=0,i;i=t[o];o++)e.data=i.textContent},T.Xml.applyFieldTagNodes_=function(t,e){for(var o=0,i;i=t[o];o++){var s=i.getAttribute("name");T.Xml.domToField_(e,s,i)}},T.Xml.findChildBlocks_=function(t){for(var e={childBlockElement:null,childShadowElement:null},o=0,i;i=t.childNodes[o];o++)i.nodeType==T.utils.dom.NodeType.ELEMENT_NODE&&("block"==i.nodeName.toLowerCase()?e.childBlockElement=i:"shadow"==i.nodeName.toLowerCase()&&(e.childShadowElement=i));return e},T.Xml.applyInputTagNodes_=function(t,e,o,i){for(var s=0,n;n=t[s];s++){var r=n.getAttribute("name"),l=o.getInput(r);if(!l){console.warn("Ignoring non-existent input "+r+" in block "+i);break}if((n=T.Xml.findChildBlocks_(n)).childBlockElement){if(!l.connection)throw TypeError("Input connection does not exist.");T.Xml.domToBlockHeadless_(n.childBlockElement,e,l.connection,!1)}n.childShadowElement&&l.connection.setShadowDom(n.childShadowElement)}},T.Xml.applyNextTagNodes_=function(t,e,o){for(var i=0,s;s=t[i];i++){if((s=T.Xml.findChildBlocks_(s)).childBlockElement){if(!o.nextConnection)throw TypeError("Next statement does not exist.");if(o.nextConnection.isConnected())throw TypeError("Next statement is already connected.");T.Xml.domToBlockHeadless_(s.childBlockElement,e,o.nextConnection,!0)}s.childShadowElement&&o.nextConnection&&o.nextConnection.setShadowDom(s.childShadowElement)}},T.Xml.domToBlockHeadless_=function(t,e,o,i){var s=t.getAttribute("type");if(!s)throw TypeError("Block type unspecified: "+t.outerHTML);var n=t.getAttribute("id"),n=e.newBlock(s,n),r=T.Xml.mapSupportedXmlTags_(t),l=T.Xml.applyMutationTagNodes_(r.mutation,n);if(T.Xml.applyCommentTagNodes_(r.comment,n),T.Xml.applyDataTagNodes_(r.data,n),o)if(i){if(!n.previousConnection)throw TypeError("Next block does not have previous statement.");o.connect(n.previousConnection)}else if(n.outputConnection)o.connect(n.outputConnection);else{if(!n.previousConnection)throw TypeError("Child block does not have output or previous statement.");o.connect(n.previousConnection)}if(T.Xml.applyFieldTagNodes_(r.field,n),T.Xml.applyInputTagNodes_(r.input,e,n,s),T.Xml.applyNextTagNodes_(r.next,e,n),l&&n.initSvg(),(e=t.getAttribute("inline"))&&n.setInputsInline("true"==e),(e=t.getAttribute("disabled"))&&n.setEnabled("true"!=e&&"disabled"!=e),(e=t.getAttribute("deletable"))&&n.setDeletable("true"==e),(e=t.getAttribute("movable"))&&n.setMovable("true"==e),(e=t.getAttribute("editable"))&&n.setEditable("true"==e),(e=t.getAttribute("collapsed"))&&n.setCollapsed("true"==e),"shadow"==t.nodeName.toLowerCase()){for(t=n.getChildren(!1),e=0;o=t[e];e++)if(!o.isShadow())throw TypeError("Shadow block not allowed non-shadow child.");if(n.getVarModels().length)throw TypeError("Shadow blocks cannot have variable references.");n.setShadow(!0)}return n},T.Xml.domToField_=function(t,e,o){var i=t.getField(e);i?i.fromXml(o):console.warn("Ignoring non-existent field "+e+" in block "+t.type)},T.Xml.deleteNext=function(t){for(var e=0,o;o=t.childNodes[e];e++)if("next"==o.nodeName.toLowerCase()){t.removeChild(o);break}},T.Events.BlockBase=function(t){T.Events.BlockBase.superClass_.constructor.call(this),this.blockId=(this.isBlank=void 0===t)?"":t.id,this.workspaceId=this.isBlank?"":t.workspace.id},T.utils.object.inherits(T.Events.BlockBase,T.Events.Abstract),T.Events.BlockBase.prototype.toJson=function(){var t=T.Events.BlockBase.superClass_.toJson.call(this);return t.blockId=this.blockId,t},T.Events.BlockBase.prototype.fromJson=function(t){T.Events.BlockBase.superClass_.fromJson.call(this,t),this.blockId=t.blockId},T.Events.Change=function(t,e,o,i,s){T.Events.Change.superClass_.constructor.call(this,t),t&&(this.element=void 0===e?"":e,this.name=void 0===o?"":o,this.oldValue=void 0===i?"":i,this.newValue=void 0===s?"":s)},T.utils.object.inherits(T.Events.Change,T.Events.BlockBase),T.Events.BlockChange=T.Events.Change,T.Events.Change.prototype.type=T.Events.CHANGE,T.Events.Change.prototype.toJson=function(){var t=T.Events.Change.superClass_.toJson.call(this);return t.element=this.element,this.name&&(t.name=this.name),t.oldValue=this.oldValue,t.newValue=this.newValue,t},T.Events.Change.prototype.fromJson=function(t){T.Events.Change.superClass_.fromJson.call(this,t),this.element=t.element,this.name=t.name,this.oldValue=t.oldValue,this.newValue=t.newValue},T.Events.Change.prototype.isNull=function(){return this.oldValue==this.newValue},T.Events.Change.prototype.run=function(t){var e=this.getEventWorkspace_().getBlockById(this.blockId);if(e)switch(e.mutator&&e.mutator.setVisible(!1),t=t?this.newValue:this.oldValue,this.element){case"field":(e=e.getField(this.name))?e.setValue(t):console.warn("Can't set non-existent field: "+this.name);break;case"comment":e.setCommentText(t||null);break;case"collapsed":e.setCollapsed(!!t);break;case"disabled":e.setEnabled(!t);break;case"inline":e.setInputsInline(!!t);break;case"mutation":var o="",i;e.mutationToDom&&(o=(o=e.mutationToDom())&&T.Xml.domToText(o)),e.domToMutation&&(i=T.Xml.textToDom(t||"<mutation/>"),e.domToMutation(i)),T.Events.fire(new(T.Events.get(T.Events.CHANGE))(e,"mutation",null,o,t));break;default:console.warn("Unknown change type: "+this.element)}else console.warn("Can't change non-existent block: "+this.blockId)},T.Events.Create=function(t){T.Events.Create.superClass_.constructor.call(this,t),t&&(t.isShadow()&&(this.recordUndo=!1),this.xml=t.workspace.rendered?T.Xml.blockToDomWithXY(t):T.Xml.blockToDom(t),this.ids=T.Events.getDescendantIds(t))},T.utils.object.inherits(T.Events.Create,T.Events.BlockBase),T.Events.BlockCreate=T.Events.Create,T.Events.Create.prototype.type=T.Events.CREATE,T.Events.Create.prototype.toJson=function(){var t=T.Events.Create.superClass_.toJson.call(this);return t.xml=T.Xml.domToText(this.xml),t.ids=this.ids,this.recordUndo||(t.recordUndo=this.recordUndo),t},T.Events.Create.prototype.fromJson=function(t){T.Events.Create.superClass_.fromJson.call(this,t),this.xml=T.Xml.textToDom(t.xml),this.ids=t.ids,void 0!==t.recordUndo&&(this.recordUndo=t.recordUndo)},T.Events.Create.prototype.run=function(t){var e=this.getEventWorkspace_(),o;if(t)(t=T.utils.xml.createElement("xml")).appendChild(this.xml),T.Xml.domToWorkspace(t,e);else{t=0;for(;o=this.ids[t];t++){var i=e.getBlockById(o);i?i.dispose(!1):o==this.blockId&&console.warn("Can't uncreate non-existent block: "+o)}}},T.Events.Delete=function(t){if(T.Events.Delete.superClass_.constructor.call(this,t),t){if(t.getParent())throw Error("Connected blocks cannot be deleted.");t.isShadow()&&(this.recordUndo=!1),this.oldXml=t.workspace.rendered?T.Xml.blockToDomWithXY(t):T.Xml.blockToDom(t),this.ids=T.Events.getDescendantIds(t)}},T.utils.object.inherits(T.Events.Delete,T.Events.BlockBase),T.Events.BlockDelete=T.Events.Delete,T.Events.Delete.prototype.type=T.Events.DELETE,T.Events.Delete.prototype.toJson=function(){var t=T.Events.Delete.superClass_.toJson.call(this);return t.oldXml=T.Xml.domToText(this.oldXml),t.ids=this.ids,this.recordUndo||(t.recordUndo=this.recordUndo),t},T.Events.Delete.prototype.fromJson=function(t){T.Events.Delete.superClass_.fromJson.call(this,t),this.oldXml=T.Xml.textToDom(t.oldXml),this.ids=t.ids,void 0!==t.recordUndo&&(this.recordUndo=t.recordUndo)},T.Events.Delete.prototype.run=function(t){var e=this.getEventWorkspace_(),o;if(t){t=0;for(;o=this.ids[t];t++){var i=e.getBlockById(o);i?i.dispose(!1):o==this.blockId&&console.warn("Can't delete non-existent block: "+o)}}else(t=T.utils.xml.createElement("xml")).appendChild(this.oldXml),T.Xml.domToWorkspace(t,e)},T.Events.Move=function(t){T.Events.Move.superClass_.constructor.call(this,t),t&&(t.isShadow()&&(this.recordUndo=!1),t=this.currentLocation_(),this.oldParentId=t.parentId,this.oldInputName=t.inputName,this.oldCoordinate=t.coordinate)},T.utils.object.inherits(T.Events.Move,T.Events.BlockBase),T.Events.BlockMove=T.Events.Move,T.Events.Move.prototype.type=T.Events.MOVE,T.Events.Move.prototype.toJson=function(){var t=T.Events.Move.superClass_.toJson.call(this);return this.newParentId&&(t.newParentId=this.newParentId),this.newInputName&&(t.newInputName=this.newInputName),this.newCoordinate&&(t.newCoordinate=Math.round(this.newCoordinate.x)+","+Math.round(this.newCoordinate.y)),this.recordUndo||(t.recordUndo=this.recordUndo),t},T.Events.Move.prototype.fromJson=function(t){var e;T.Events.Move.superClass_.fromJson.call(this,t),this.newParentId=t.newParentId,this.newInputName=t.newInputName,t.newCoordinate&&(e=t.newCoordinate.split(","),this.newCoordinate=new T.utils.Coordinate(Number(e[0]),Number(e[1]))),void 0!==t.recordUndo&&(this.recordUndo=t.recordUndo)},T.Events.Move.prototype.recordNew=function(){var t=this.currentLocation_();this.newParentId=t.parentId,this.newInputName=t.inputName,this.newCoordinate=t.coordinate},T.Events.Move.prototype.currentLocation_=function(){var t=this.getEventWorkspace_().getBlockById(this.blockId),e={},o=t.getParent();return o?(e.parentId=o.id,(t=o.getInputWithBlock(t))&&(e.inputName=t.name)):e.coordinate=t.getRelativeToSurfaceXY(),e},T.Events.Move.prototype.isNull=function(){return this.oldParentId==this.newParentId&&this.oldInputName==this.newInputName&&T.utils.Coordinate.equals(this.oldCoordinate,this.newCoordinate)},T.Events.Move.prototype.run=function(t){var e,o;if(o=(e=this.getEventWorkspace_()).getBlockById(this.blockId)){var i=t?this.newParentId:this.oldParentId,s=t?this.newInputName:this.oldInputName,n=t?this.newCoordinate:this.oldCoordinate,r,o,e;if(t=null,i&&!(t=e.getBlockById(i)))return void console.warn("Can't connect to non-existent block: "+i);o.getParent()&&o.unplug(),n?(s=o.getRelativeToSurfaceXY(),o.moveBy(n.x-s.x,n.y-s.y)):(e=(o=o.outputConnection||o.previousConnection).type,s?(t=t.getInput(s))&&(r=t.connection):e==T.connectionTypes.PREVIOUS_STATEMENT&&(r=t.nextConnection),r?o.connect(r):console.warn("Can't connect to non-existent input: "+s))}else console.warn("Can't move non-existent block: "+this.blockId)},T.registry.register(T.registry.Type.EVENT,T.Events.CREATE,T.Events.Create),T.registry.register(T.registry.Type.EVENT,T.Events.DELETE,T.Events.Delete),T.registry.register(T.registry.Type.EVENT,T.Events.CHANGE,T.Events.Change),T.registry.register(T.registry.Type.EVENT,T.Events.MOVE,T.Events.Move),T.Events.FinishedLoading=function(t){this.isBlank=void 0===t,this.workspaceId=t?t.id:"",this.group=T.Events.getGroup(),this.recordUndo=!1},T.utils.object.inherits(T.Events.FinishedLoading,T.Events.Abstract),T.Events.FinishedLoading.prototype.type=T.Events.FINISHED_LOADING,T.Events.FinishedLoading.prototype.toJson=function(){var t={type:this.type};return this.group&&(t.group=this.group),this.workspaceId&&(t.workspaceId=this.workspaceId),t},T.Events.FinishedLoading.prototype.fromJson=function(t){this.isBlank=!1,this.workspaceId=t.workspaceId,this.group=t.group},T.registry.register(T.registry.Type.EVENT,T.Events.FINISHED_LOADING,T.Events.FinishedLoading),T.Events.UiBase=function(t){T.Events.UiBase.superClass_.constructor.call(this),this.isBlank=void 0===t,this.workspaceId=t||"",this.recordUndo=!1},T.utils.object.inherits(T.Events.UiBase,T.Events.Abstract),T.Events.UiBase.prototype.isUiEvent=!0,T.Events.Ui=function(t,e,o,i){T.Events.Ui.superClass_.constructor.call(this,t?t.workspace.id:void 0),this.blockId=t?t.id:null,this.element=void 0===e?"":e,this.oldValue=void 0===o?"":o,this.newValue=void 0===i?"":i},T.utils.object.inherits(T.Events.Ui,T.Events.UiBase),T.Events.Ui.prototype.type=T.Events.UI,T.Events.Ui.prototype.toJson=function(){var t=T.Events.Ui.superClass_.toJson.call(this);return t.element=this.element,void 0!==this.newValue&&(t.newValue=this.newValue),this.blockId&&(t.blockId=this.blockId),t},T.Events.Ui.prototype.fromJson=function(t){T.Events.Ui.superClass_.fromJson.call(this,t),this.element=t.element,this.newValue=t.newValue,this.blockId=t.blockId},T.registry.register(T.registry.Type.EVENT,T.Events.UI,T.Events.Ui),T.Events.VarBase=function(t){T.Events.VarBase.superClass_.constructor.call(this),this.varId=(this.isBlank=void 0===t)?"":t.getId(),this.workspaceId=this.isBlank?"":t.workspace.id},T.utils.object.inherits(T.Events.VarBase,T.Events.Abstract),T.Events.VarBase.prototype.toJson=function(){var t=T.Events.VarBase.superClass_.toJson.call(this);return t.varId=this.varId,t},T.Events.VarBase.prototype.fromJson=function(t){T.Events.VarBase.superClass_.toJson.call(this),this.varId=t.varId},T.Events.VarCreate=function(t){T.Events.VarCreate.superClass_.constructor.call(this,t),t&&(this.varType=t.type,this.varName=t.name)},T.utils.object.inherits(T.Events.VarCreate,T.Events.VarBase),T.Events.VarCreate.prototype.type=T.Events.VAR_CREATE,T.Events.VarCreate.prototype.toJson=function(){var t=T.Events.VarCreate.superClass_.toJson.call(this);return t.varType=this.varType,t.varName=this.varName,t},T.Events.VarCreate.prototype.fromJson=function(t){T.Events.VarCreate.superClass_.fromJson.call(this,t),this.varType=t.varType,this.varName=t.varName},T.Events.VarCreate.prototype.run=function(t){var e=this.getEventWorkspace_();t?e.createVariable(this.varName,this.varType,this.varId):e.deleteVariableById(this.varId)},T.Events.VarDelete=function(t){T.Events.VarDelete.superClass_.constructor.call(this,t),t&&(this.varType=t.type,this.varName=t.name)},T.utils.object.inherits(T.Events.VarDelete,T.Events.VarBase),T.Events.VarDelete.prototype.type=T.Events.VAR_DELETE,T.Events.VarDelete.prototype.toJson=function(){var t=T.Events.VarDelete.superClass_.toJson.call(this);return t.varType=this.varType,t.varName=this.varName,t},T.Events.VarDelete.prototype.fromJson=function(t){T.Events.VarDelete.superClass_.fromJson.call(this,t),this.varType=t.varType,this.varName=t.varName},T.Events.VarDelete.prototype.run=function(t){var e=this.getEventWorkspace_();t?e.deleteVariableById(this.varId):e.createVariable(this.varName,this.varType,this.varId)},T.Events.VarRename=function(t,e){T.Events.VarRename.superClass_.constructor.call(this,t),t&&(this.oldName=t.name,this.newName=void 0===e?"":e)},T.utils.object.inherits(T.Events.VarRename,T.Events.VarBase),T.Events.VarRename.prototype.type=T.Events.VAR_RENAME,T.Events.VarRename.prototype.toJson=function(){var t=T.Events.VarRename.superClass_.toJson.call(this);return t.oldName=this.oldName,t.newName=this.newName,t},T.Events.VarRename.prototype.fromJson=function(t){T.Events.VarRename.superClass_.fromJson.call(this,t),this.oldName=t.oldName,this.newName=t.newName},T.Events.VarRename.prototype.run=function(t){var e=this.getEventWorkspace_();t?e.renameVariableById(this.varId,this.newName):e.renameVariableById(this.varId,this.oldName)},T.registry.register(T.registry.Type.EVENT,T.Events.VAR_CREATE,T.Events.VarCreate),T.registry.register(T.registry.Type.EVENT,T.Events.VAR_DELETE,T.Events.VarDelete),T.registry.register(T.registry.Type.EVENT,T.Events.VAR_RENAME,T.Events.VarRename),T.BlockDragSurfaceSvg=function(t){this.container_=t,this.createDom()},T.BlockDragSurfaceSvg.prototype.SVG_=null,T.BlockDragSurfaceSvg.prototype.dragGroup_=null,T.BlockDragSurfaceSvg.prototype.container_=null,T.BlockDragSurfaceSvg.prototype.scale_=1,T.BlockDragSurfaceSvg.prototype.surfaceXY_=null,T.BlockDragSurfaceSvg.prototype.createDom=function(){this.SVG_||(this.SVG_=T.utils.dom.createSvgElement(T.utils.Svg.SVG,{xmlns:T.utils.dom.SVG_NS,"xmlns:html":T.utils.dom.HTML_NS,"xmlns:xlink":T.utils.dom.XLINK_NS,version:"1.1",class:"blocklyBlockDragSurface"},this.container_),this.dragGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{},this.SVG_))},T.BlockDragSurfaceSvg.prototype.setBlocksAndShow=function(t){if(this.dragGroup_.childNodes.length)throw Error("Already dragging a block.");this.dragGroup_.appendChild(t),this.SVG_.style.display="block",this.surfaceXY_=new T.utils.Coordinate(0,0)},T.BlockDragSurfaceSvg.prototype.translateAndScaleGroup=function(t,e,o){this.scale_=o,t=t.toFixed(0),e=e.toFixed(0),this.dragGroup_.setAttribute("transform","translate("+t+","+e+") scale("+o+")")},T.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_=function(){var t=this.surfaceXY_.x,e=this.surfaceXY_.y,t=t.toFixed(0),e=e.toFixed(0);this.SVG_.style.display="block",T.utils.dom.setCssTransform(this.SVG_,"translate3d("+t+"px, "+e+"px, 0px)")},T.BlockDragSurfaceSvg.prototype.translateSurface=function(t,e){this.surfaceXY_=new T.utils.Coordinate(t*this.scale_,e*this.scale_),this.translateSurfaceInternal_()},T.BlockDragSurfaceSvg.prototype.getSurfaceTranslation=function(){var t=T.utils.getRelativeXY(this.SVG_);return new T.utils.Coordinate(t.x/this.scale_,t.y/this.scale_)},T.BlockDragSurfaceSvg.prototype.getGroup=function(){return this.dragGroup_},T.BlockDragSurfaceSvg.prototype.getCurrentBlock=function(){return this.dragGroup_.firstChild},T.BlockDragSurfaceSvg.prototype.clearAndHide=function(t){if(t?t.appendChild(this.getCurrentBlock()):this.dragGroup_.removeChild(this.getCurrentBlock()),this.SVG_.style.display="none",this.dragGroup_.childNodes.length)throw Error("Drag group was not cleared.");this.surfaceXY_=null},T.Css={},T.Css.injected_=!1,T.Css.register=function(t){if(T.Css.injected_)throw Error("CSS already injected");Array.prototype.push.apply(T.Css.CONTENT,t),t.length=0},T.Css.inject=function(t,e){var o;T.Css.injected_||(T.Css.injected_=!0,o=T.Css.CONTENT.join("\n"),T.Css.CONTENT.length=0,t&&(t=e.replace(/[\\/]$/,""),o=o.replace(/<<<PATH>>>/g,t),(t=document.createElement("style")).id="blockly-common-style",o=document.createTextNode(o),t.appendChild(o),document.head.insertBefore(t,document.head.firstChild)))},T.Css.CONTENT=[".blocklySvg {","background-color: #fff;","outline: none;","overflow: hidden;","position: absolute;","display: block;","}",".blocklyWidgetDiv {","display: none;","position: absolute;","z-index: 99999;","}",".injectionDiv {","height: 100%;","position: relative;","overflow: hidden;","touch-action: none;","}",".blocklyNonSelectable {","user-select: none;","-ms-user-select: none;","-webkit-user-select: none;","}",".blocklyWsDragSurface {","display: none;","position: absolute;","top: 0;","left: 0;","}",".blocklyWsDragSurface.blocklyOverflowVisible {","overflow: visible;","}",".blocklyBlockDragSurface {","display: none;","position: absolute;","top: 0;","left: 0;","right: 0;","bottom: 0;","overflow: visible !important;","z-index: 50;","}",".blocklyBlockCanvas.blocklyCanvasTransitioning,",".blocklyBubbleCanvas.blocklyCanvasTransitioning {","transition: transform .5s;","}",".blocklyTooltipDiv {","background-color: #ffffc7;","border: 1px solid #ddc;","box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);","color: #000;","display: none;","font: 9pt sans-serif;","opacity: .9;","padding: 2px;","position: absolute;","z-index: 100000;","}",".blocklyDropDownDiv {","position: absolute;","left: 0;","top: 0;","z-index: 10000;","display: none;","border: 1px solid;","border-color: #dadce0;","background-color: #fff;","border-radius: 2px;","padding: 4px;","box-shadow: 0 0 3px 1px rgba(0,0,0,.3);","}",".blocklyDropDownDiv.blocklyFocused {","box-shadow: 0 0 6px 1px rgba(0,0,0,.3);","}",".blocklyDropDownContent {","max-height: 300px;","overflow: auto;","overflow-x: hidden;","position: relative;","}",".blocklyDropDownArrow {","position: absolute;","left: 0;","top: 0;","width: 16px;","height: 16px;","z-index: -1;","background-color: inherit;","border-color: inherit;","}",".blocklyDropDownButton {","display: inline-block;","float: left;","padding: 0;","margin: 4px;","border-radius: 4px;","outline: none;","border: 1px solid;","transition: box-shadow .1s;","cursor: pointer;","}",".blocklyArrowTop {","border-top: 1px solid;","border-left: 1px solid;","border-top-left-radius: 4px;","border-color: inherit;","}",".blocklyArrowBottom {","border-bottom: 1px solid;","border-right: 1px solid;","border-bottom-right-radius: 4px;","border-color: inherit;","}",".blocklyResizeSE {","cursor: se-resize;","fill: #aaa;","}",".blocklyResizeSW {","cursor: sw-resize;","fill: #aaa;","}",".blocklyResizeLine {","stroke: #515A5A;","stroke-width: 1;","}",".blocklyHighlightedConnectionPath {","fill: none;","stroke: #fc3;","stroke-width: 4px;","}",".blocklyPathLight {","fill: none;","stroke-linecap: round;","stroke-width: 1;","}",".blocklySelected>.blocklyPathLight {","display: none;","}",".blocklyDraggable {",'cursor: url("<<<PATH>>>/handopen.cur"), auto;',"cursor: grab;","cursor: -webkit-grab;","}",".blocklyDragging {",'cursor: url("<<<PATH>>>/handclosed.cur"), auto;',"cursor: grabbing;","cursor: -webkit-grabbing;","}",".blocklyDraggable:active {",'cursor: url("<<<PATH>>>/handclosed.cur"), auto;',"cursor: grabbing;","cursor: -webkit-grabbing;","}",".blocklyBlockDragSurface .blocklyDraggable {",'cursor: url("<<<PATH>>>/handclosed.cur"), auto;',"cursor: grabbing;","cursor: -webkit-grabbing;","}",".blocklyDragging.blocklyDraggingDelete {",'cursor: url("<<<PATH>>>/handdelete.cur"), auto;',"}",".blocklyDragging>.blocklyPath,",".blocklyDragging>.blocklyPathLight {","fill-opacity: .8;","stroke-opacity: .8;","}",".blocklyDragging>.blocklyPathDark {","display: none;","}",".blocklyDisabled>.blocklyPath {","fill-opacity: .5;","stroke-opacity: .5;","}",".blocklyDisabled>.blocklyPathLight,",".blocklyDisabled>.blocklyPathDark {","display: none;","}",".blocklyInsertionMarker>.blocklyPath,",".blocklyInsertionMarker>.blocklyPathLight,",".blocklyInsertionMarker>.blocklyPathDark {","fill-opacity: .2;","stroke: none;","}",".blocklyMultilineText {","font-family: monospace;","}",".blocklyNonEditableText>text {","pointer-events: none;","}",".blocklyFlyout {","position: absolute;","z-index: 20;","}",".blocklyText text {","cursor: default;","}",".blocklySvg text,",".blocklyBlockDragSurface text {","user-select: none;","-ms-user-select: none;","-webkit-user-select: none;","cursor: inherit;","}",".blocklyHidden {","display: none;","}",".blocklyFieldDropdown:not(.blocklyHidden) {","display: block;","}",".blocklyIconGroup {","cursor: default;","}",".blocklyIconGroup:not(:hover),",".blocklyIconGroupReadonly {","opacity: .6;","}",".blocklyIconShape {","fill: #00f;","stroke: #fff;","stroke-width: 1px;","}",".blocklyIconSymbol {","fill: #fff;","}",".blocklyMinimalBody {","margin: 0;","padding: 0;","}",".blocklyHtmlInput {","border: none;","border-radius: 4px;","height: 100%;","margin: 0;","outline: none;","padding: 0;","width: 100%;","text-align: center;","display: block;","box-sizing: border-box;","}",".blocklyHtmlInput::-ms-clear {","display: none;","}",".blocklyMainBackground {","stroke-width: 1;","stroke: #c6c6c6;","}",".blocklyMutatorBackground {","fill: #fff;","stroke: #ddd;","stroke-width: 1;","}",".blocklyFlyoutBackground {","fill: #ddd;","fill-opacity: .8;","}",".blocklyMainWorkspaceScrollbar {","z-index: 20;","}",".blocklyFlyoutScrollbar {","z-index: 30;","}",".blocklyScrollbarHorizontal,",".blocklyScrollbarVertical {","position: absolute;","outline: none;","}",".blocklyScrollbarBackground {","opacity: 0;","}",".blocklyScrollbarHandle {","fill: #ccc;","}",".blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,",".blocklyScrollbarHandle:hover {","fill: #bbb;","}",".blocklyFlyout .blocklyScrollbarHandle {","fill: #bbb;","}",".blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,",".blocklyFlyout .blocklyScrollbarHandle:hover {","fill: #aaa;","}",".blocklyInvalidInput {","background: #faa;","}",".blocklyVerticalMarker {","stroke-width: 3px;","fill: rgba(255,255,255,.5);","pointer-events: none;","}",".blocklyComputeCanvas {","position: absolute;","width: 0;","height: 0;","}",".blocklyNoPointerEvents {","pointer-events: none;","}",".blocklyContextMenu {","border-radius: 4px;","max-height: 100%;","}",".blocklyDropdownMenu {","border-radius: 2px;","padding: 0 !important;","}",".blocklyDropdownMenu .blocklyMenuItem {","padding-left: 28px;","}",".blocklyDropdownMenu .blocklyMenuItemRtl {","padding-left: 5px;","padding-right: 28px;","}",".blocklyWidgetDiv .blocklyMenu {","background: #fff;","border: 1px solid transparent;","box-shadow: 0 0 3px 1px rgba(0,0,0,.3);","font: normal 13px Arial, sans-serif;","margin: 0;","outline: none;","padding: 4px 0;","position: absolute;","overflow-y: auto;","overflow-x: hidden;","max-height: 100%;","z-index: 20000;","}",".blocklyWidgetDiv .blocklyMenu.blocklyFocused {","box-shadow: 0 0 6px 1px rgba(0,0,0,.3);","}",".blocklyDropDownDiv .blocklyMenu {","background: inherit;","border: inherit;",'font: normal 13px "Helvetica Neue", Helvetica, sans-serif;',"outline: none;","position: relative;","z-index: 20000;","}",".blocklyMenuItem {","border: none;","color: #000;","cursor: pointer;","list-style: none;","margin: 0;","min-width: 7em;","padding: 6px 15px;","white-space: nowrap;","}",".blocklyMenuItemDisabled {","color: #ccc;","cursor: inherit;","}",".blocklyMenuItemHighlight {","background-color: rgba(0,0,0,.1);","}",".blocklyMenuItemCheckbox {","height: 16px;","position: absolute;","width: 16px;","}",".blocklyMenuItemSelected .blocklyMenuItemCheckbox {","float: left;","margin-left: -24px;","position: static;","}",".blocklyMenuItemRtl .blocklyMenuItemCheckbox {","float: right;","margin-right: -24px;","}"],T.utils.math={},T.utils.math.toRadians=function(t){return t*Math.PI/180},T.utils.math.toDegrees=function(t){return 180*t/Math.PI},T.utils.math.clamp=function(t,e,o){var i;return o<t&&(i=o,o=t,t=i),Math.max(t,Math.min(e,o))},T.DropDownDiv=function(){},T.DropDownDiv.boundsElement_=null,T.DropDownDiv.owner_=null,T.DropDownDiv.positionToField_=null,T.DropDownDiv.ARROW_SIZE=16,T.DropDownDiv.BORDER_SIZE=1,T.DropDownDiv.ARROW_HORIZONTAL_PADDING=12,T.DropDownDiv.PADDING_Y=16,T.DropDownDiv.ANIMATION_TIME=.25,T.DropDownDiv.animateOutTimer_=null,T.DropDownDiv.onHide_=null,T.DropDownDiv.rendererClassName_="",T.DropDownDiv.themeClassName_="",T.DropDownDiv.createDom=function(){var t,e;T.DropDownDiv.DIV_||((t=document.createElement("div")).className="blocklyDropDownDiv",(T.parentContainer||document.body).appendChild(t),T.DropDownDiv.DIV_=t,(e=document.createElement("div")).className="blocklyDropDownContent",t.appendChild(e),T.DropDownDiv.content_=e,(e=document.createElement("div")).className="blocklyDropDownArrow",t.appendChild(e),T.DropDownDiv.arrow_=e,T.DropDownDiv.DIV_.style.opacity=0,T.DropDownDiv.DIV_.style.transition="transform "+T.DropDownDiv.ANIMATION_TIME+"s, opacity "+T.DropDownDiv.ANIMATION_TIME+"s",t.addEventListener("focusin",function(){T.utils.dom.addClass(t,"blocklyFocused")}),t.addEventListener("focusout",function(){T.utils.dom.removeClass(t,"blocklyFocused")}))},T.DropDownDiv.setBoundsElement=function(t){T.DropDownDiv.boundsElement_=t},T.DropDownDiv.getContentDiv=function(){return T.DropDownDiv.content_},T.DropDownDiv.clearContent=function(){T.DropDownDiv.content_.textContent="",T.DropDownDiv.content_.style.width=""},T.DropDownDiv.setColour=function(t,e){T.DropDownDiv.DIV_.style.backgroundColor=t,T.DropDownDiv.DIV_.style.borderColor=e},T.DropDownDiv.showPositionedByBlock=function(t,e,o,i){return T.DropDownDiv.showPositionedByRect_(T.DropDownDiv.getScaledBboxOfBlock_(e),t,o,i)},T.DropDownDiv.showPositionedByField=function(t,e,o){return T.DropDownDiv.positionToField_=!0,T.DropDownDiv.showPositionedByRect_(T.DropDownDiv.getScaledBboxOfField_(t),t,e,o)},T.DropDownDiv.getScaledBboxOfBlock_=function(t){var e=t.getSvgRoot(),o=e.getBBox(),i=t.workspace.scale;return t=o.height*i,o=o.width*i,e=T.utils.style.getPageOffset(e),new T.utils.Rect(e.y,e.y+t,e.x,e.x+o)},T.DropDownDiv.getScaledBboxOfField_=function(t){return t=t.getScaledBBox(),new T.utils.Rect(t.top,t.bottom,t.left,t.right)},T.DropDownDiv.showPositionedByRect_=function(t,e,o,i){var s=t.left+(t.right-t.left)/2,n=t.bottom;t=t.top,i&&(t+=i);for(var r=(i=e.getSourceBlock()).workspace;r.options.parentWorkspace;)r=r.options.parentWorkspace;return T.DropDownDiv.setBoundsElement(r.getParentSvg().parentNode),T.DropDownDiv.show(e,i.RTL,s,n,s,t,o)},T.DropDownDiv.show=function(t,e,o,i,s,n,r){return T.DropDownDiv.owner_=t,T.DropDownDiv.onHide_=r||null,(t=T.DropDownDiv.DIV_).style.direction=e?"rtl":"ltr",e=T.getMainWorkspace(),T.DropDownDiv.rendererClassName_=e.getRenderer().getClassName(),T.DropDownDiv.themeClassName_=e.getTheme().getClassName(),T.utils.dom.addClass(t,T.DropDownDiv.rendererClassName_),T.utils.dom.addClass(t,T.DropDownDiv.themeClassName_),T.DropDownDiv.positionInternal_(o,i,s,n)},T.DropDownDiv.getBoundsInfo_=function(){var t=T.utils.style.getPageOffset(T.DropDownDiv.boundsElement_),e=T.utils.style.getSize(T.DropDownDiv.boundsElement_);return{left:t.x,right:t.x+e.width,top:t.y,bottom:t.y+e.height,width:e.width,height:e.height}},T.DropDownDiv.getPositionMetrics_=function(t,e,o,i){var s=T.DropDownDiv.getBoundsInfo_(),n=T.utils.style.getSize(T.DropDownDiv.DIV_);return e+n.height<s.bottom?T.DropDownDiv.getPositionBelowMetrics_(t,e,s,n):i-n.height>s.top?T.DropDownDiv.getPositionAboveMetrics_(o,i,s,n):e+n.height<document.documentElement.clientHeight?T.DropDownDiv.getPositionBelowMetrics_(t,e,s,n):i-n.height>document.documentElement.clientTop?T.DropDownDiv.getPositionAboveMetrics_(o,i,s,n):T.DropDownDiv.getPositionTopOfPageMetrics_(t,s,n)},T.DropDownDiv.getPositionBelowMetrics_=function(t,e,o,i){return{initialX:(t=T.DropDownDiv.getPositionX(t,o.left,o.right,i.width)).divX,initialY:e,finalX:t.divX,finalY:e+T.DropDownDiv.PADDING_Y,arrowX:t.arrowX,arrowY:-(T.DropDownDiv.ARROW_SIZE/2+T.DropDownDiv.BORDER_SIZE),arrowAtTop:!0,arrowVisible:!0}},T.DropDownDiv.getPositionAboveMetrics_=function(t,e,o,i){return{initialX:(t=T.DropDownDiv.getPositionX(t,o.left,o.right,i.width)).divX,initialY:e-i.height,finalX:t.divX,finalY:e-i.height-T.DropDownDiv.PADDING_Y,arrowX:t.arrowX,arrowY:i.height-2*T.DropDownDiv.BORDER_SIZE-T.DropDownDiv.ARROW_SIZE/2,arrowAtTop:!1,arrowVisible:!0}},T.DropDownDiv.getPositionTopOfPageMetrics_=function(t,e,o){return{initialX:(t=T.DropDownDiv.getPositionX(t,e.left,e.right,o.width)).divX,initialY:0,finalX:t.divX,finalY:0,arrowAtTop:null,arrowX:null,arrowY:null,arrowVisible:!1}},T.DropDownDiv.getPositionX=function(t,e,o,i){var s=t;return t=T.utils.math.clamp(e,t-i/2,o-i),s-=T.DropDownDiv.ARROW_SIZE/2,e=T.DropDownDiv.ARROW_HORIZONTAL_PADDING,{arrowX:i=T.utils.math.clamp(e,s-t,i-e-T.DropDownDiv.ARROW_SIZE),divX:t}},T.DropDownDiv.isVisible=function(){return!!T.DropDownDiv.owner_},T.DropDownDiv.hideIfOwner=function(t,e){return T.DropDownDiv.owner_===t&&(e?T.DropDownDiv.hideWithoutAnimation():T.DropDownDiv.hide(),!0)},T.DropDownDiv.hide=function(){var t=T.DropDownDiv.DIV_;t.style.transform="translate(0, 0)",t.style.opacity=0,T.DropDownDiv.animateOutTimer_=setTimeout(function(){T.DropDownDiv.hideWithoutAnimation()},1e3*T.DropDownDiv.ANIMATION_TIME),T.DropDownDiv.onHide_&&(T.DropDownDiv.onHide_(),T.DropDownDiv.onHide_=null)},T.DropDownDiv.hideWithoutAnimation=function(){var t;T.DropDownDiv.isVisible()&&(T.DropDownDiv.animateOutTimer_&&clearTimeout(T.DropDownDiv.animateOutTimer_),(t=T.DropDownDiv.DIV_).style.transform="",t.style.left="",t.style.top="",t.style.opacity=0,t.style.display="none",t.style.backgroundColor="",t.style.borderColor="",T.DropDownDiv.onHide_&&(T.DropDownDiv.onHide_(),T.DropDownDiv.onHide_=null),T.DropDownDiv.clearContent(),T.DropDownDiv.owner_=null,T.DropDownDiv.rendererClassName_&&(T.utils.dom.removeClass(t,T.DropDownDiv.rendererClassName_),T.DropDownDiv.rendererClassName_=""),T.DropDownDiv.themeClassName_&&(T.utils.dom.removeClass(t,T.DropDownDiv.themeClassName_),T.DropDownDiv.themeClassName_=""),T.getMainWorkspace().markFocused())},T.DropDownDiv.positionInternal_=function(t,e,o,i){(t=T.DropDownDiv.getPositionMetrics_(t,e,o,i)).arrowVisible?(T.DropDownDiv.arrow_.style.display="",T.DropDownDiv.arrow_.style.transform="translate("+t.arrowX+"px,"+t.arrowY+"px) rotate(45deg)",T.DropDownDiv.arrow_.setAttribute("class",t.arrowAtTop?"blocklyDropDownArrow blocklyArrowTop":"blocklyDropDownArrow blocklyArrowBottom")):T.DropDownDiv.arrow_.style.display="none",e=Math.floor(t.initialX),o=Math.floor(t.initialY),i=Math.floor(t.finalX);var s=Math.floor(t.finalY),n=T.DropDownDiv.DIV_;return n.style.left=e+"px",n.style.top=o+"px",n.style.display="block",n.style.opacity=1,n.style.transform="translate("+(i-e)+"px,"+(s-o)+"px)",!!t.arrowAtTop},T.DropDownDiv.repositionForWindowResize=function(){var t,e,t,e;T.DropDownDiv.owner_?(e=(t=T.DropDownDiv.owner_).getSourceBlock(),e=(t=T.DropDownDiv.positionToField_?T.DropDownDiv.getScaledBboxOfField_(t):T.DropDownDiv.getScaledBboxOfBlock_(e)).left+(t.right-t.left)/2,T.DropDownDiv.positionInternal_(e,t.bottom,e,t.top)):T.DropDownDiv.hide()},T.Grid=function(t,e){this.gridPattern_=t,this.spacing_=e.spacing,this.length_=e.length,this.line2_=(this.line1_=t.firstChild)&&this.line1_.nextSibling,this.snapToGrid_=e.snap},T.Grid.prototype.scale_=1,T.Grid.prototype.dispose=function(){this.gridPattern_=null},T.Grid.prototype.shouldSnap=function(){return this.snapToGrid_},T.Grid.prototype.getSpacing=function(){return this.spacing_},T.Grid.prototype.getPatternId=function(){return this.gridPattern_.id},T.Grid.prototype.update=function(t){this.scale_=t;var e=this.spacing_*t||100,o=(this.gridPattern_.setAttribute("width",e),this.gridPattern_.setAttribute("height",e),(e=Math.floor(this.spacing_/2)+.5)-this.length_/2),i=e+this.length_/2;this.setLineAttributes_(this.line1_,t,o*=t,i*=t,e*=t,e),this.setLineAttributes_(this.line2_,t,e,e,o,i)},T.Grid.prototype.setLineAttributes_=function(t,e,o,i,s,n){t&&(t.setAttribute("stroke-width",e),t.setAttribute("x1",o),t.setAttribute("y1",s),t.setAttribute("x2",i),t.setAttribute("y2",n))},T.Grid.prototype.moveTo=function(t,e){this.gridPattern_.setAttribute("x",t),this.gridPattern_.setAttribute("y",e),(T.utils.userAgent.IE||T.utils.userAgent.EDGE)&&this.update(this.scale_)},T.Grid.createDom=function(t,e,o){return t=T.utils.dom.createSvgElement(T.utils.Svg.PATTERN,{id:"blocklyGridPattern"+t,patternUnits:"userSpaceOnUse"},o),0<e.length&&0<e.spacing?(T.utils.dom.createSvgElement(T.utils.Svg.LINE,{stroke:e.colour},t),1<e.length&&T.utils.dom.createSvgElement(T.utils.Svg.LINE,{stroke:e.colour},t)):T.utils.dom.createSvgElement(T.utils.Svg.LINE,{},t),t},T.Theme=function(t,e,o,i){this.name=t,this.blockStyles=e||Object.create(null),this.categoryStyles=o||Object.create(null),this.componentStyles=i||Object.create(null),this.fontStyle=Object.create(null),this.startHats=null,T.registry.register(T.registry.Type.THEME,t,this)},T.Theme.prototype.getClassName=function(){return this.name+"-theme"},T.Theme.prototype.setBlockStyle=function(t,e){this.blockStyles[t]=e},T.Theme.prototype.setCategoryStyle=function(t,e){this.categoryStyles[t]=e},T.Theme.prototype.getComponentStyle=function(t){return(t=this.componentStyles[t])&&"string"==typeof t&&this.getComponentStyle(t)?this.getComponentStyle(t):t?String(t):null},T.Theme.prototype.setComponentStyle=function(t,e){this.componentStyles[t]=e},T.Theme.prototype.setFontStyle=function(t){this.fontStyle=t},T.Theme.prototype.setStartHats=function(t){this.startHats=t},T.Theme.defineTheme=function(t,e){var o=new T.Theme(t),i=e.base;return i&&(i="string"==typeof i?T.registry.getObject(T.registry.Type.THEME,i):i)instanceof T.Theme&&(T.utils.object.deepMerge(o,i),o.name=t),T.utils.object.deepMerge(o.blockStyles,e.blockStyles),T.utils.object.deepMerge(o.categoryStyles,e.categoryStyles),T.utils.object.deepMerge(o.componentStyles,e.componentStyles),T.utils.object.deepMerge(o.fontStyle,e.fontStyle),null!=e.startHats&&(o.startHats=e.startHats),o},T.Themes={},T.Themes.Classic={},T.Themes.Classic.defaultBlockStyles={colour_blocks:{colourPrimary:"#f3aa60"},list_blocks:{colourPrimary:"#ecc01c"},logic_blocks:{colourPrimary:"#91c854"},loop_blocks:{colourPrimary:"#aa0d43"},math_blocks:{colourPrimary:"#00948a"},procedure_blocks:{colourPrimary:"290"},text_blocks:{colourPrimary:"#9365b8"},variable_blocks:{colourPrimary:"330"},variable_dynamic_blocks:{colourPrimary:"#bf717f"},hat_blocks:{colourPrimary:"330",hat:"cap"}},T.Themes.Classic.categoryStyles={colour_category:{colour:"20"},list_category:{colour:"260"},logic_category:{colour:"210"},loop_category:{colour:"120"},math_category:{colour:"230"},procedure_category:{colour:"290"},text_category:{colour:"160"},variable_category:{colour:"330"},variable_dynamic_category:{colour:"310"}},T.Themes.Classic=new T.Theme("classic",T.Themes.Classic.defaultBlockStyles,T.Themes.Classic.categoryStyles),T.utils.IdGenerator={},T.utils.IdGenerator.nextId_=0,T.utils.IdGenerator.getNextUniqueId=function(){return"blockly-"+(T.utils.IdGenerator.nextId_++).toString(36)},T.utils.Metrics=function(){},T.utils.toolbox={},T.utils.toolbox.CATEGORY_TOOLBOX_KIND="categoryToolbox",T.utils.toolbox.FLYOUT_TOOLBOX_KIND="flyoutToolbox",T.utils.toolbox.Position={TOP:0,BOTTOM:1,LEFT:2,RIGHT:3},T.utils.toolbox.convertToolboxDefToJson=function(t){if(!t)return null;return(t instanceof Element||"string"==typeof t)&&(t=T.utils.toolbox.parseToolboxTree(t),t=T.utils.toolbox.convertToToolboxJson_(t)),T.utils.toolbox.validateToolbox_(t),t},T.utils.toolbox.validateToolbox_=function(t){var e=t.kind;if(t=t.contents,e&&e!=T.utils.toolbox.FLYOUT_TOOLBOX_KIND&&e!=T.utils.toolbox.CATEGORY_TOOLBOX_KIND)throw Error("Invalid toolbox kind "+e+". Please supply either "+T.utils.toolbox.FLYOUT_TOOLBOX_KIND+" or "+T.utils.toolbox.CATEGORY_TOOLBOX_KIND);if(!t)throw Error("Toolbox must have a contents attribute.")},T.utils.toolbox.convertFlyoutDefToJsonArray=function(t){return t?t.contents||(Array.isArray(t)&&0<t.length&&!t[0].nodeType?t:T.utils.toolbox.xmlToJsonArray_(t)):[]},T.utils.toolbox.hasCategories=function(t){if(!t)return!1;var e=t.kind;return e?e==T.utils.toolbox.CATEGORY_TOOLBOX_KIND:!!t.contents.filter(function(t){return"CATEGORY"==t.kind.toUpperCase()}).length},T.utils.toolbox.isCategoryCollapsible=function(t){return!(!t||!t.contents||!t.contents.filter(function(t){return"CATEGORY"==t.kind.toUpperCase()}).length)},T.utils.toolbox.convertToToolboxJson_=function(t){var e={contents:T.utils.toolbox.xmlToJsonArray_(t)};return t instanceof Node&&T.utils.toolbox.addAttributes_(t,e),e},T.utils.toolbox.xmlToJsonArray_=function(t){var e=[],o,o=(o=t.childNodes)||t,i,s,n;for(t=0;i=o[t];t++){i.tagName&&(s={},n=i.tagName.toUpperCase(),"BLOCK"==(s.kind=n)?s.blockxml=i:i.childNodes&&0<i.childNodes.length&&(s.contents=T.utils.toolbox.xmlToJsonArray_(i)),T.utils.toolbox.addAttributes_(i,s),e.push(s))}return e},T.utils.toolbox.addAttributes_=function(t,e){for(var o=0;o<t.attributes.length;o++){var i=t.attributes[o];-1<i.nodeName.indexOf("css-")?(e.cssconfig=e.cssconfig||{},e.cssconfig[i.nodeName.replace("css-","")]=i.value):e[i.nodeName]=i.value}},T.utils.toolbox.parseToolboxTree=function(t){if(t){if("string"!=typeof t&&(T.utils.userAgent.IE&&t.outerHTML?t=t.outerHTML:t instanceof Element||(t=null)),"string"==typeof t&&"xml"!=(t=T.Xml.textToDom(t)).nodeName.toLowerCase())throw TypeError("Toolbox should be an <xml> document.")}else t=null;return t},T.Options=function(t){var e=!!t.readOnly,o,i,s,n,r,l,a,c,h=(e?(o=null,a=l=r=n=s=i=!1):(o=T.utils.toolbox.convertToolboxDefToJson(t.toolbox),i=T.utils.toolbox.hasCategories(o),void 0===(s=t.trashcan)&&(s=i),c=t.maxTrashcanContents,s?void 0===c&&(c=32):c=0,void 0===(n=t.collapse)&&(n=i),void 0===(r=t.comments)&&(r=i),void 0===(l=t.disable)&&(l=i),void 0===(a=t.sounds)&&(a=!0)),!!t.rtl),u=t.horizontalLayout,g,g="end"!==(g=t.toolboxPosition),p=(g=(u=void 0===u?!1:u)?g?T.utils.toolbox.Position.TOP:T.utils.toolbox.Position.BOTTOM:g==h?T.utils.toolbox.Position.RIGHT:T.utils.toolbox.Position.LEFT,t.css),d=(void 0===p&&(p=!0),"https://blockly-demo.appspot.com/static/media/"),_=(t.media?d=t.media:t.path&&(d=t.path+"media/"),void 0===t.oneBasedIndex||!!t.oneBasedIndex),I=t.renderer||"geras",C=t.plugins||{};this.RTL=h,this.oneBasedIndex=_,this.collapse=n,this.comments=r,this.disable=l,this.readOnly=e,this.maxBlocks=t.maxBlocks||1/0,this.maxInstances=t.maxInstances,this.pathToMedia=d,this.hasCategories=i,this.moveOptions=T.Options.parseMoveOptions_(t,i),this.hasScrollbars=!!this.moveOptions.scrollbars,this.hasTrashcan=s,this.maxTrashcanContents=c,this.hasSounds=a,this.hasCss=p,this.horizontalLayout=u,this.languageTree=o,this.gridOptions=T.Options.parseGridOptions_(t),this.zoomOptions=T.Options.parseZoomOptions_(t),this.toolboxPosition=g,this.theme=T.Options.parseThemeOptions_(t),this.renderer=I,this.rendererOverrides=t.rendererOverrides,this.gridPattern=null,this.parentWorkspace=t.parentWorkspace,this.plugins=C},T.BlocklyOptions=function(){},T.Options.parseMoveOptions_=function(t,e){var o=t.move||{},i={};return void 0===o.scrollbars&&void 0===t.scrollbars?i.scrollbars=e:"object"==typeof o.scrollbars?(i.scrollbars={},i.scrollbars.horizontal=!!o.scrollbars.horizontal,i.scrollbars.vertical=!!o.scrollbars.vertical,i.scrollbars.horizontal&&i.scrollbars.vertical?i.scrollbars=!0:i.scrollbars.horizontal||i.scrollbars.vertical||(i.scrollbars=!1)):i.scrollbars=!!o.scrollbars||!!t.scrollbars,i.wheel=i.scrollbars&&void 0!==o.wheel?!!o.wheel:"object"==typeof i.scrollbars,i.drag=!(!i.scrollbars||void 0!==o.drag&&!o.drag),i},T.Options.parseZoomOptions_=function(t){t=t.zoom||{};var e={};return e.controls=void 0!==t.controls&&!!t.controls,e.wheel=void 0!==t.wheel&&!!t.wheel,e.startScale=void 0===t.startScale?1:Number(t.startScale),e.maxScale=void 0===t.maxScale?3:Number(t.maxScale),e.minScale=void 0===t.minScale?.3:Number(t.minScale),e.scaleSpeed=void 0===t.scaleSpeed?1.2:Number(t.scaleSpeed),e.pinch=void 0===t.pinch?e.wheel||e.controls:!!t.pinch,e},T.Options.parseGridOptions_=function(t){t=t.grid||{};var e={};return e.spacing=Number(t.spacing)||0,e.colour=t.colour||"#888",e.length=void 0===t.length?1:Number(t.length),e.snap=0<e.spacing&&!!t.snap,e},T.Options.parseThemeOptions_=function(t){return"string"==typeof(t=t.theme||T.Themes.Classic)?T.registry.getObject(T.registry.Type.THEME,t):t instanceof T.Theme?t:T.Theme.defineTheme(t.name||"builtin"+T.utils.IdGenerator.getNextUniqueId(),t)},T.Options.parseToolboxTree=function(t){return T.utils.deprecation.warn("Blockly.Options.parseToolboxTree","September 2020","September 2021","Blockly.utils.toolbox.parseToolboxTree"),T.utils.toolbox.parseToolboxTree(t)},T.ScrollbarPair=function(t,e,o,i){this.workspace_=t,o=void 0===o||o;var s=(e=void 0===e||e)&&o;e&&(this.hScroll=new T.Scrollbar(t,!0,s,i)),o&&(this.vScroll=new T.Scrollbar(t,!1,s,i)),s&&(this.corner_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{height:T.Scrollbar.scrollbarThickness,width:T.Scrollbar.scrollbarThickness,class:"blocklyScrollbarBackground"},null),T.utils.dom.insertAfter(this.corner_,t.getBubbleCanvas())),this.oldHostMetrics_=null},T.ScrollbarPair.prototype.dispose=function(){T.utils.dom.removeNode(this.corner_),this.oldHostMetrics_=this.workspace_=this.corner_=null,this.hScroll&&(this.hScroll.dispose(),this.hScroll=null),this.vScroll&&(this.vScroll.dispose(),this.vScroll=null)},T.ScrollbarPair.prototype.resize=function(){var t=this.workspace_.getMetrics();if(t){var e=!1,o=!1;if(this.oldHostMetrics_&&this.oldHostMetrics_.viewWidth==t.viewWidth&&this.oldHostMetrics_.viewHeight==t.viewHeight&&this.oldHostMetrics_.absoluteTop==t.absoluteTop&&this.oldHostMetrics_.absoluteLeft==t.absoluteLeft?(this.oldHostMetrics_&&this.oldHostMetrics_.scrollWidth==t.scrollWidth&&this.oldHostMetrics_.viewLeft==t.viewLeft&&this.oldHostMetrics_.scrollLeft==t.scrollLeft||(e=!0),this.oldHostMetrics_&&this.oldHostMetrics_.scrollHeight==t.scrollHeight&&this.oldHostMetrics_.viewTop==t.viewTop&&this.oldHostMetrics_.scrollTop==t.scrollTop||(o=!0)):o=e=!0,e||o){try{T.Events.disable(),this.hScroll&&e&&this.hScroll.resize(t),this.vScroll&&o&&this.vScroll.resize(t)}finally{T.Events.enable()}this.workspace_.maybeFireViewportChangeEvent()}this.hScroll&&this.vScroll&&(this.oldHostMetrics_&&this.oldHostMetrics_.viewWidth==t.viewWidth&&this.oldHostMetrics_.absoluteLeft==t.absoluteLeft||this.corner_.setAttribute("x",this.vScroll.position.x),this.oldHostMetrics_&&this.oldHostMetrics_.viewHeight==t.viewHeight&&this.oldHostMetrics_.absoluteTop==t.absoluteTop||this.corner_.setAttribute("y",this.hScroll.position.y)),this.oldHostMetrics_=t}},T.ScrollbarPair.prototype.canScrollHorizontally=function(){return!!this.hScroll},T.ScrollbarPair.prototype.canScrollVertically=function(){return!!this.vScroll},T.ScrollbarPair.prototype.setOrigin=function(t,e){this.hScroll&&this.hScroll.setOrigin(t,e),this.vScroll&&this.vScroll.setOrigin(t,e)},T.ScrollbarPair.prototype.set=function(t,e,o){this.hScroll&&this.hScroll.set(t,!1),this.vScroll&&this.vScroll.set(e,!1),!o&&void 0!==o||(t={},this.hScroll&&(t.x=this.hScroll.getRatio_()),this.vScroll&&(t.y=this.vScroll.getRatio_()),this.workspace_.setMetrics(t))},T.ScrollbarPair.prototype.setX=function(t){this.hScroll&&this.hScroll.set(t,!0)},T.ScrollbarPair.prototype.setY=function(t){this.vScroll&&this.vScroll.set(t,!0)},T.ScrollbarPair.prototype.setContainerVisible=function(t){this.hScroll&&this.hScroll.setContainerVisible(t),this.vScroll&&this.vScroll.setContainerVisible(t)},T.ScrollbarPair.prototype.isVisible=function(){var t=!1;return this.hScroll&&(t=this.hScroll.isVisible()),t=this.vScroll?t||this.vScroll.isVisible():t},T.ScrollbarPair.prototype.resizeContent=function(t){this.hScroll&&this.hScroll.resizeContentHorizontal(t),this.vScroll&&this.vScroll.resizeContentVertical(t)},T.ScrollbarPair.prototype.resizeView=function(t){this.hScroll&&this.hScroll.resizeViewHorizontal(t),this.vScroll&&this.vScroll.resizeViewVertical(t)},T.Scrollbar=function(t,e,o,i){this.workspace_=t,this.pair_=o||!1,this.horizontal_=e,this.ratio=this.oldHostMetrics_=null,this.createDom_(i),this.position=new T.utils.Coordinate(0,0),t=T.Scrollbar.scrollbarThickness,e?(this.svgBackground_.setAttribute("height",t),this.outerSvg_.setAttribute("height",t),this.svgHandle_.setAttribute("height",t-5),this.svgHandle_.setAttribute("y",2.5),this.lengthAttribute_="width",this.positionAttribute_="x"):(this.svgBackground_.setAttribute("width",t),this.outerSvg_.setAttribute("width",t),this.svgHandle_.setAttribute("width",t-5),this.svgHandle_.setAttribute("x",2.5),this.lengthAttribute_="height",this.positionAttribute_="y"),this.onMouseDownBarWrapper_=T.browserEvents.conditionalBind(this.svgBackground_,"mousedown",this,this.onMouseDownBar_),this.onMouseDownHandleWrapper_=T.browserEvents.conditionalBind(this.svgHandle_,"mousedown",this,this.onMouseDownHandle_)},T.Scrollbar.prototype.origin_=new T.utils.Coordinate(0,0),T.Scrollbar.prototype.startDragMouse_=0,T.Scrollbar.prototype.scrollbarLength_=0,T.Scrollbar.prototype.handleLength_=0,T.Scrollbar.prototype.handlePosition_=0,T.Scrollbar.prototype.isVisible_=!0,T.Scrollbar.prototype.containerVisible_=!0,T.Scrollbar.scrollbarThickness=15,T.Touch.TOUCH_ENABLED&&(T.Scrollbar.scrollbarThickness=25),T.Scrollbar.SCROLLBAR_MARGIN=.5,T.Scrollbar.metricsAreEquivalent_=function(t,e){return!(!t||!e||t.viewWidth!=e.viewWidth||t.viewHeight!=e.viewHeight||t.viewLeft!=e.viewLeft||t.viewTop!=e.viewTop||t.absoluteTop!=e.absoluteTop||t.absoluteLeft!=e.absoluteLeft||t.scrollWidth!=e.scrollWidth||t.scrollHeight!=e.scrollHeight||t.scrollLeft!=e.scrollLeft||t.scrollTop!=e.scrollTop)},T.Scrollbar.prototype.dispose=function(){this.cleanUp_(),T.browserEvents.unbind(this.onMouseDownBarWrapper_),this.onMouseDownBarWrapper_=null,T.browserEvents.unbind(this.onMouseDownHandleWrapper_),this.onMouseDownHandleWrapper_=null,T.utils.dom.removeNode(this.outerSvg_),this.svgBackground_=this.svgGroup_=this.outerSvg_=null,this.svgHandle_&&(this.workspace_.getThemeManager().unsubscribe(this.svgHandle_),this.svgHandle_=null),this.workspace_=null},T.Scrollbar.prototype.constrainHandleLength_=function(t){return t=t<=0||isNaN(t)?0:Math.min(t,this.scrollbarLength_)},T.Scrollbar.prototype.setHandleLength_=function(t){this.handleLength_=t,this.svgHandle_.setAttribute(this.lengthAttribute_,this.handleLength_)},T.Scrollbar.prototype.constrainHandlePosition_=function(t){return t=t<=0||isNaN(t)?0:Math.min(t,this.scrollbarLength_-this.handleLength_)},T.Scrollbar.prototype.setHandlePosition=function(t){this.handlePosition_=t,this.svgHandle_.setAttribute(this.positionAttribute_,this.handlePosition_)},T.Scrollbar.prototype.setScrollbarLength_=function(t){this.scrollbarLength_=t,this.outerSvg_.setAttribute(this.lengthAttribute_,this.scrollbarLength_),this.svgBackground_.setAttribute(this.lengthAttribute_,this.scrollbarLength_)},T.Scrollbar.prototype.setPosition=function(t,e){this.position.x=t,this.position.y=e,T.utils.dom.setCssTransform(this.outerSvg_,"translate("+(this.position.x+this.origin_.x)+"px,"+(this.position.y+this.origin_.y)+"px)")},T.Scrollbar.prototype.resize=function(t){if(!t&&!(t=this.workspace_.getMetrics()))return;T.Scrollbar.metricsAreEquivalent_(t,this.oldHostMetrics_)||(this.horizontal_?this.resizeHorizontal_(t):this.resizeVertical_(t),this.oldHostMetrics_=t,this.updateMetrics_())},T.Scrollbar.prototype.requiresViewResize_=function(t){return!this.oldHostMetrics_||this.oldHostMetrics_.viewWidth!==t.viewWidth||this.oldHostMetrics_.viewHeight!==t.viewHeight||this.oldHostMetrics_.absoluteLeft!==t.absoluteLeft||this.oldHostMetrics_.absoluteTop!==t.absoluteTop},T.Scrollbar.prototype.resizeHorizontal_=function(t){this.requiresViewResize_(t)?this.resizeViewHorizontal(t):this.resizeContentHorizontal(t)},T.Scrollbar.prototype.resizeViewHorizontal=function(t){var e=t.viewWidth-2*T.Scrollbar.SCROLLBAR_MARGIN;this.pair_&&(e-=T.Scrollbar.scrollbarThickness),this.setScrollbarLength_(Math.max(0,e)),e=t.absoluteLeft+T.Scrollbar.SCROLLBAR_MARGIN,this.pair_&&this.workspace_.RTL&&(e+=T.Scrollbar.scrollbarThickness),this.setPosition(e,t.absoluteTop+t.viewHeight-T.Scrollbar.scrollbarThickness-T.Scrollbar.SCROLLBAR_MARGIN),this.resizeContentHorizontal(t)},T.Scrollbar.prototype.resizeContentHorizontal=function(t){var e,e,o;t.viewWidth>=t.scrollWidth?(this.setHandleLength_(this.scrollbarLength_),this.setHandlePosition(0),this.pair_||this.setVisible(!1)):(this.pair_||this.setVisible(!0),e=this.scrollbarLength_*t.viewWidth/t.scrollWidth,e=this.constrainHandleLength_(e),this.setHandleLength_(e),e=t.scrollWidth-t.viewWidth,o=this.scrollbarLength_-this.handleLength_,t=this.constrainHandlePosition_(t=(t.viewLeft-t.scrollLeft)/e*o),this.setHandlePosition(t),this.ratio=o/e)},T.Scrollbar.prototype.resizeVertical_=function(t){this.requiresViewResize_(t)?this.resizeViewVertical(t):this.resizeContentVertical(t)},T.Scrollbar.prototype.resizeViewVertical=function(t){var e=t.viewHeight-2*T.Scrollbar.SCROLLBAR_MARGIN;this.pair_&&(e-=T.Scrollbar.scrollbarThickness),this.setScrollbarLength_(Math.max(0,e)),this.setPosition(this.workspace_.RTL?t.absoluteLeft+T.Scrollbar.SCROLLBAR_MARGIN:t.absoluteLeft+t.viewWidth-T.Scrollbar.scrollbarThickness-T.Scrollbar.SCROLLBAR_MARGIN,t.absoluteTop+T.Scrollbar.SCROLLBAR_MARGIN),this.resizeContentVertical(t)},T.Scrollbar.prototype.resizeContentVertical=function(t){var e,e,o;t.viewHeight>=t.scrollHeight?(this.setHandleLength_(this.scrollbarLength_),this.setHandlePosition(0),this.pair_||this.setVisible(!1)):(this.pair_||this.setVisible(!0),e=this.scrollbarLength_*t.viewHeight/t.scrollHeight,e=this.constrainHandleLength_(e),this.setHandleLength_(e),e=t.scrollHeight-t.viewHeight,o=this.scrollbarLength_-this.handleLength_,t=this.constrainHandlePosition_(t=(t.viewTop-t.scrollTop)/e*o),this.setHandlePosition(t),this.ratio=o/e)},T.Scrollbar.prototype.createDom_=function(t){var e="blocklyScrollbar"+(this.horizontal_?"Horizontal":"Vertical");t&&(e+=" "+t),this.outerSvg_=T.utils.dom.createSvgElement(T.utils.Svg.SVG,{class:e},null),this.svgGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{},this.outerSvg_),this.svgBackground_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{class:"blocklyScrollbarBackground"},this.svgGroup_),t=Math.floor((T.Scrollbar.scrollbarThickness-5)/2),this.svgHandle_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{class:"blocklyScrollbarHandle",rx:t,ry:t},this.svgGroup_),this.workspace_.getThemeManager().subscribe(this.svgHandle_,"scrollbarColour","fill"),this.workspace_.getThemeManager().subscribe(this.svgHandle_,"scrollbarOpacity","fill-opacity"),T.utils.dom.insertAfter(this.outerSvg_,this.workspace_.getParentSvg())},T.Scrollbar.prototype.isVisible=function(){return this.isVisible_},T.Scrollbar.prototype.setContainerVisible=function(t){var e=t!=this.containerVisible_;this.containerVisible_=t,e&&this.updateDisplay_()},T.Scrollbar.prototype.setVisible=function(t){var e=t!=this.isVisible();if(this.pair_)throw Error("Unable to toggle visibility of paired scrollbars.");this.isVisible_=t,e&&this.updateDisplay_()},T.Scrollbar.prototype.updateDisplay_=function(){this.containerVisible_&&this.isVisible()?this.outerSvg_.setAttribute("display","block"):this.outerSvg_.setAttribute("display","none")},T.Scrollbar.prototype.onMouseDownBar_=function(t){var e,e,o,o,i,s;this.workspace_.markFocused(),T.Touch.clearTouchIdentifier(),this.cleanUp_(),T.utils.isRightButton(t)?t.stopPropagation():(e=T.utils.mouseToSvg(t,this.workspace_.getParentSvg(),this.workspace_.getInverseScreenCTM()),e=this.horizontal_?e.x:e.y,o=T.utils.getInjectionDivXY_(this.svgHandle_),o=this.horizontal_?o.x:o.y,i=this.handlePosition_,s=.95*this.handleLength_,e<=o?i-=s:e>=o+this.handleLength_&&(i+=s),this.setHandlePosition(this.constrainHandlePosition_(i)),this.updateMetrics_(),t.stopPropagation(),t.preventDefault())},T.Scrollbar.prototype.onMouseDownHandle_=function(t){this.workspace_.markFocused(),this.cleanUp_(),T.utils.isRightButton(t)?t.stopPropagation():(this.startDragHandle=this.handlePosition_,this.workspace_.setupDragSurface(),this.startDragMouse_=this.horizontal_?t.clientX:t.clientY,T.Scrollbar.onMouseUpWrapper_=T.browserEvents.conditionalBind(document,"mouseup",this,this.onMouseUpHandle_),T.Scrollbar.onMouseMoveWrapper_=T.browserEvents.conditionalBind(document,"mousemove",this,this.onMouseMoveHandle_),t.stopPropagation(),t.preventDefault())},T.Scrollbar.prototype.onMouseMoveHandle_=function(t){this.setHandlePosition(this.constrainHandlePosition_(this.startDragHandle+((this.horizontal_?t.clientX:t.clientY)-this.startDragMouse_))),this.updateMetrics_()},T.Scrollbar.prototype.onMouseUpHandle_=function(){this.workspace_.resetDragSurface(),T.Touch.clearTouchIdentifier(),this.cleanUp_()},T.Scrollbar.prototype.cleanUp_=function(){T.hideChaff(!0),T.Scrollbar.onMouseUpWrapper_&&(T.browserEvents.unbind(T.Scrollbar.onMouseUpWrapper_),T.Scrollbar.onMouseUpWrapper_=null),T.Scrollbar.onMouseMoveWrapper_&&(T.browserEvents.unbind(T.Scrollbar.onMouseMoveWrapper_),T.Scrollbar.onMouseMoveWrapper_=null)},T.Scrollbar.prototype.getRatio_=function(){var t=this.handlePosition_/(this.scrollbarLength_-this.handleLength_);return t=isNaN(t)?0:t},T.Scrollbar.prototype.updateMetrics_=function(){var t=this.getRatio_(),e={};this.horizontal_?e.x=t:e.y=t,this.workspace_.setMetrics(e)},T.Scrollbar.prototype.set=function(t,e){this.setHandlePosition(this.constrainHandlePosition_(t*this.ratio)),!e&&void 0!==e||this.updateMetrics_()},T.Scrollbar.prototype.setOrigin=function(t,e){this.origin_=new T.utils.Coordinate(t,e)},T.Tooltip={},T.Tooltip.visible=!1,T.Tooltip.blocked_=!1,T.Tooltip.LIMIT=50,T.Tooltip.mouseOutPid_=0,T.Tooltip.showPid_=0,T.Tooltip.lastX_=0,T.Tooltip.lastY_=0,T.Tooltip.element_=null,T.Tooltip.poisonedElement_=null,T.Tooltip.OFFSET_X=0,T.Tooltip.OFFSET_Y=10,T.Tooltip.RADIUS_OK=10,T.Tooltip.HOVER_MS=750,T.Tooltip.MARGINS=5,T.Tooltip.DIV=null,T.Tooltip.getTooltipOfObject=function(t){if(t=T.Tooltip.getTargetObject_(t)){for(t=t.tooltip;"function"==typeof t;)t=t();if("string"!=typeof t)throw Error("Tooltip function must return a string.");return t}return""},T.Tooltip.getTargetObject_=function(t){for(;t&&t.tooltip;){if("string"==typeof t.tooltip||"function"==typeof t.tooltip)return t;t=t.tooltip}return null},T.Tooltip.createDom=function(){T.Tooltip.DIV||(T.Tooltip.DIV=document.createElement("div"),T.Tooltip.DIV.className="blocklyTooltipDiv",(T.parentContainer||document.body).appendChild(T.Tooltip.DIV))},T.Tooltip.bindMouseEvents=function(t){t.mouseOverWrapper_=T.browserEvents.bind(t,"mouseover",null,T.Tooltip.onMouseOver_),t.mouseOutWrapper_=T.browserEvents.bind(t,"mouseout",null,T.Tooltip.onMouseOut_),t.addEventListener("mousemove",T.Tooltip.onMouseMove_,!1)},T.Tooltip.unbindMouseEvents=function(t){t&&(T.browserEvents.unbind(t.mouseOverWrapper_),T.browserEvents.unbind(t.mouseOutWrapper_),t.removeEventListener("mousemove",T.Tooltip.onMouseMove_))},T.Tooltip.onMouseOver_=function(t){T.Tooltip.blocked_||(t=T.Tooltip.getTargetObject_(t.currentTarget),T.Tooltip.element_!=t&&(T.Tooltip.hide(),T.Tooltip.poisonedElement_=null,T.Tooltip.element_=t),clearTimeout(T.Tooltip.mouseOutPid_))},T.Tooltip.onMouseOut_=function(t){T.Tooltip.blocked_||(T.Tooltip.mouseOutPid_=setTimeout(function(){T.Tooltip.element_=null,T.Tooltip.poisonedElement_=null,T.Tooltip.hide()},1),clearTimeout(T.Tooltip.showPid_))},T.Tooltip.onMouseMove_=function(t){var e;T.Tooltip.element_&&T.Tooltip.element_.tooltip&&!T.Tooltip.blocked_&&(T.Tooltip.visible?(e=T.Tooltip.lastX_-t.pageX,t=T.Tooltip.lastY_-t.pageY,Math.sqrt(e*e+t*t)>T.Tooltip.RADIUS_OK&&T.Tooltip.hide()):T.Tooltip.poisonedElement_!=T.Tooltip.element_&&(clearTimeout(T.Tooltip.showPid_),T.Tooltip.lastX_=t.pageX,T.Tooltip.lastY_=t.pageY,T.Tooltip.showPid_=setTimeout(T.Tooltip.show_,T.Tooltip.HOVER_MS)))},T.Tooltip.dispose=function(){T.Tooltip.element_=null,T.Tooltip.poisonedElement_=null,T.Tooltip.hide()},T.Tooltip.hide=function(){T.Tooltip.visible&&(T.Tooltip.visible=!1,T.Tooltip.DIV)&&(T.Tooltip.DIV.style.display="none"),T.Tooltip.showPid_&&clearTimeout(T.Tooltip.showPid_)},T.Tooltip.block=function(){T.Tooltip.hide(),T.Tooltip.blocked_=!0},T.Tooltip.unblock=function(){T.Tooltip.blocked_=!1},T.Tooltip.show_=function(){if(!T.Tooltip.blocked_&&(T.Tooltip.poisonedElement_=T.Tooltip.element_,T.Tooltip.DIV)){T.Tooltip.DIV.textContent="";var t=T.Tooltip.getTooltipOfObject(T.Tooltip.element_),t;t=(t=T.utils.string.wrap(t,T.Tooltip.LIMIT)).split("\n");for(var e=0;e<t.length;e++){var o=document.createElement("div");o.appendChild(document.createTextNode(t[e])),T.Tooltip.DIV.appendChild(o)}t=T.Tooltip.element_.RTL,e=document.documentElement.clientWidth,o=document.documentElement.clientHeight,T.Tooltip.DIV.style.direction=t?"rtl":"ltr",T.Tooltip.DIV.style.display="block",T.Tooltip.visible=!0;var i=T.Tooltip.lastX_,i=t?i-(T.Tooltip.OFFSET_X+T.Tooltip.DIV.offsetWidth):i+T.Tooltip.OFFSET_X,s=T.Tooltip.lastY_+T.Tooltip.OFFSET_Y;s+T.Tooltip.DIV.offsetHeight>o+window.scrollY&&(s-=T.Tooltip.DIV.offsetHeight+2*T.Tooltip.OFFSET_Y),t?i=Math.max(T.Tooltip.MARGINS-window.scrollX,i):i+T.Tooltip.DIV.offsetWidth>e+window.scrollX-2*T.Tooltip.MARGINS&&(i=e-T.Tooltip.DIV.offsetWidth-2*T.Tooltip.MARGINS),T.Tooltip.DIV.style.top=s+"px",T.Tooltip.DIV.style.left=i+"px"}},T.utils.aria={},T.utils.aria.ARIA_PREFIX_="aria-",T.utils.aria.ROLE_ATTRIBUTE_="role",T.utils.aria.Role={GRID:"grid",GRIDCELL:"gridcell",GROUP:"group",LISTBOX:"listbox",MENU:"menu",MENUITEM:"menuitem",MENUITEMCHECKBOX:"menuitemcheckbox",OPTION:"option",PRESENTATION:"presentation",ROW:"row",TREE:"tree",TREEITEM:"treeitem"},T.utils.aria.State={ACTIVEDESCENDANT:"activedescendant",COLCOUNT:"colcount",DISABLED:"disabled",EXPANDED:"expanded",INVALID:"invalid",LABEL:"label",LABELLEDBY:"labelledby",LEVEL:"level",ORIENTATION:"orientation",POSINSET:"posinset",ROWCOUNT:"rowcount",SELECTED:"selected",SETSIZE:"setsize",VALUEMAX:"valuemax",VALUEMIN:"valuemin"},T.utils.aria.setRole=function(t,e){t.setAttribute(T.utils.aria.ROLE_ATTRIBUTE_,e)},T.utils.aria.setState=function(t,e,o){Array.isArray(o)&&(o=o.join(" ")),t.setAttribute(T.utils.aria.ARIA_PREFIX_+e,o)},T.WorkspaceDragSurfaceSvg=function(t){this.container_=t,this.createDom()},T.WorkspaceDragSurfaceSvg.prototype.SVG_=null,T.WorkspaceDragSurfaceSvg.prototype.container_=null,T.WorkspaceDragSurfaceSvg.prototype.createDom=function(){this.SVG_||(this.SVG_=T.utils.dom.createSvgElement(T.utils.Svg.SVG,{xmlns:T.utils.dom.SVG_NS,"xmlns:html":T.utils.dom.HTML_NS,"xmlns:xlink":T.utils.dom.XLINK_NS,version:"1.1",class:"blocklyWsDragSurface blocklyOverflowVisible"},null),this.container_.appendChild(this.SVG_))},T.WorkspaceDragSurfaceSvg.prototype.translateSurface=function(t,e){t=t.toFixed(0),e=e.toFixed(0),this.SVG_.style.display="block",T.utils.dom.setCssTransform(this.SVG_,"translate3d("+t+"px, "+e+"px, 0px)")},T.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation=function(){return T.utils.getRelativeXY(this.SVG_)},T.WorkspaceDragSurfaceSvg.prototype.clearAndHide=function(t){if(!t)throw Error("Couldn't clear and hide the drag surface: missing new surface.");var e=this.SVG_.childNodes[0],o=this.SVG_.childNodes[1];if(!(e&&o&&T.utils.dom.hasClass(e,"blocklyBlockCanvas")&&T.utils.dom.hasClass(o,"blocklyBubbleCanvas")))throw Error("Couldn't clear and hide the drag surface. A node was missing.");if(null!=this.previousSibling_?T.utils.dom.insertAfter(e,this.previousSibling_):t.insertBefore(e,t.firstChild),T.utils.dom.insertAfter(o,e),this.SVG_.style.display="none",this.SVG_.childNodes.length)throw Error("Drag surface was not cleared.");T.utils.dom.setCssTransform(this.SVG_,""),this.previousSibling_=null},T.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow=function(t,e,o,i,s,n){if(this.SVG_.childNodes.length)throw Error("Already dragging a block.");this.previousSibling_=o,t.setAttribute("transform","translate(0, 0) scale("+n+")"),e.setAttribute("transform","translate(0, 0) scale("+n+")"),this.SVG_.setAttribute("width",i),this.SVG_.setAttribute("height",s),this.SVG_.appendChild(t),this.SVG_.appendChild(e),this.SVG_.style.display="block"},T.blockRendering={},T.blockRendering.useDebugger=!1,T.blockRendering.register=function(t,e){T.registry.register(T.registry.Type.RENDERER,t,e)},T.blockRendering.unregister=function(t){T.registry.unregister(T.registry.Type.RENDERER,t)},T.blockRendering.startDebugger=function(){T.blockRendering.useDebugger=!0},T.blockRendering.stopDebugger=function(){T.blockRendering.useDebugger=!1},T.blockRendering.init=function(t,e,o){return(t=new(T.registry.getClass(T.registry.Type.RENDERER,t))(t)).init(e,o),t},T.ASTNode=function(t,e,o){if(!e)throw Error("Cannot create a node without a location.");this.type_=t,this.isConnection_=T.ASTNode.isConnectionType_(t),this.location_=e,this.wsCoordinate_=null,this.processParams_(o||null)},T.ASTNode.types={FIELD:"field",BLOCK:"block",INPUT:"input",OUTPUT:"output",NEXT:"next",PREVIOUS:"previous",STACK:"stack",WORKSPACE:"workspace"},T.ASTNode.NAVIGATE_ALL_FIELDS=!1,T.ASTNode.DEFAULT_OFFSET_Y=-20,T.ASTNode.isConnectionType_=function(t){switch(t){case T.ASTNode.types.PREVIOUS:case T.ASTNode.types.NEXT:case T.ASTNode.types.INPUT:case T.ASTNode.types.OUTPUT:return!0}return!1},T.ASTNode.createFieldNode=function(t){return t?new T.ASTNode(T.ASTNode.types.FIELD,t):null},T.ASTNode.createConnectionNode=function(t){if(!t)return null;var e=t.type;return e==T.connectionTypes.INPUT_VALUE||e==T.connectionTypes.NEXT_STATEMENT&&t.getParentInput()?T.ASTNode.createInputNode(t.getParentInput()):e==T.connectionTypes.NEXT_STATEMENT?new T.ASTNode(T.ASTNode.types.NEXT,t):e==T.connectionTypes.OUTPUT_VALUE?new T.ASTNode(T.ASTNode.types.OUTPUT,t):e==T.connectionTypes.PREVIOUS_STATEMENT?new T.ASTNode(T.ASTNode.types.PREVIOUS,t):null},T.ASTNode.createInputNode=function(t){return t&&t.connection?new T.ASTNode(T.ASTNode.types.INPUT,t.connection):null},T.ASTNode.createBlockNode=function(t){return t?new T.ASTNode(T.ASTNode.types.BLOCK,t):null},T.ASTNode.createStackNode=function(t){return t?new T.ASTNode(T.ASTNode.types.STACK,t):null},T.ASTNode.createWorkspaceNode=function(t,e){return e&&t?new T.ASTNode(T.ASTNode.types.WORKSPACE,t,{wsCoordinate:e}):null},T.ASTNode.createTopNode=function(t){var e=t.previousConnection||t.outputConnection;return e?T.ASTNode.createConnectionNode(e):T.ASTNode.createBlockNode(t)},T.ASTNode.prototype.processParams_=function(t){t&&t.wsCoordinate&&(this.wsCoordinate_=t.wsCoordinate)},T.ASTNode.prototype.getLocation=function(){return this.location_},T.ASTNode.prototype.getType=function(){return this.type_},T.ASTNode.prototype.getWsCoordinate=function(){return this.wsCoordinate_},T.ASTNode.prototype.isConnection=function(){return this.isConnection_},T.ASTNode.prototype.findNextForInput_=function(){for(var t,e=(t=this.location_.getParentInput()).getSourceBlock(),t=e.inputList.indexOf(t)+1,o;o=e.inputList[t];t++){for(var i=o.fieldRow,s=0,n;n=i[s];s++)if(n.isClickable()||T.ASTNode.NAVIGATE_ALL_FIELDS)return T.ASTNode.createFieldNode(n);if(o.connection)return T.ASTNode.createInputNode(o)}return null},T.ASTNode.prototype.findNextForField_=function(){for(var t,e=(t=this.location_).getParentInput(),o=t.getSourceBlock(),i=o.inputList.indexOf(e),t=e.fieldRow.indexOf(t)+1;e=o.inputList[i];i++){for(var s=e.fieldRow;t<s.length;){if(s[t].isClickable()||T.ASTNode.NAVIGATE_ALL_FIELDS)return T.ASTNode.createFieldNode(s[t]);t++}if(t=0,e.connection)return T.ASTNode.createInputNode(e)}return null},T.ASTNode.prototype.findPrevForInput_=function(){for(var t=this.location_.getParentInput(),e=t.getSourceBlock(),o=e.inputList.indexOf(t),i;i=e.inputList[o];o--){if(i.connection&&i!==t)return T.ASTNode.createInputNode(i);for(var i,s=(i=i.fieldRow).length-1,n;n=i[s];s--)if(n.isClickable()||T.ASTNode.NAVIGATE_ALL_FIELDS)return T.ASTNode.createFieldNode(n)}return null},T.ASTNode.prototype.findPrevForField_=function(){for(var t,e=(t=this.location_).getParentInput(),o=t.getSourceBlock(),i=o.inputList.indexOf(e),t=e.fieldRow.indexOf(t)-1,s;s=o.inputList[i];i--){if(s.connection&&s!==e)return T.ASTNode.createInputNode(s);for(s=s.fieldRow;-1<t;){if(s[t].isClickable()||T.ASTNode.NAVIGATE_ALL_FIELDS)return T.ASTNode.createFieldNode(s[t]);t--}0<=i-1&&(t=o.inputList[i-1].fieldRow.length-1)}return null},T.ASTNode.prototype.navigateBetweenStacks_=function(t){var e;if(!(e=(e=this.getLocation())instanceof T.Block?e:e.getSourceBlock())||!e.workspace)return null;for(var o=e.getRootBlock(),e=o.workspace.getTopBlocks(!0),i=0,s;s=e[i];i++)if(o.id==s.id)return-1==(t=i+(t?1:-1))||t==e.length?null:T.ASTNode.createStackNode(e[t]);throw Error("Couldn't find "+(t?"next":"previous")+" stack?!")},T.ASTNode.prototype.findTopASTNodeForBlock_=function(t){var e=t.previousConnection||t.outputConnection;return e?T.ASTNode.createConnectionNode(e):T.ASTNode.createBlockNode(t)},T.ASTNode.prototype.getOutAstNodeForBlock_=function(t){if(!t)return null;var e=(t=t.getTopStackBlock()).previousConnection||t.outputConnection;return e&&e.targetConnection&&e.targetConnection.getParentInput()?T.ASTNode.createInputNode(e.targetConnection.getParentInput()):T.ASTNode.createStackNode(t)},T.ASTNode.prototype.findFirstFieldOrInput_=function(t){t=t.inputList;for(var e=0,o;o=t[e];e++){for(var i=o.fieldRow,s=0,n;n=i[s];s++)if(n.isClickable()||T.ASTNode.NAVIGATE_ALL_FIELDS)return T.ASTNode.createFieldNode(n);if(o.connection)return T.ASTNode.createInputNode(o)}return null},T.ASTNode.prototype.getSourceBlock=function(){return this.getType()===T.ASTNode.types.BLOCK||this.getType()===T.ASTNode.types.STACK?this.getLocation():this.getType()===T.ASTNode.types.WORKSPACE?null:this.getLocation().getSourceBlock()},T.ASTNode.prototype.next=function(){switch(this.type_){case T.ASTNode.types.STACK:return this.navigateBetweenStacks_(!0);case T.ASTNode.types.OUTPUT:var t=this.location_;return T.ASTNode.createBlockNode(t.getSourceBlock());case T.ASTNode.types.FIELD:return this.findNextForField_();case T.ASTNode.types.INPUT:return this.findNextForInput_();case T.ASTNode.types.BLOCK:return T.ASTNode.createConnectionNode(this.location_.nextConnection);case T.ASTNode.types.PREVIOUS:return t=this.location_,T.ASTNode.createBlockNode(t.getSourceBlock());case T.ASTNode.types.NEXT:return t=this.location_,T.ASTNode.createConnectionNode(t.targetConnection)}return null},T.ASTNode.prototype.in=function(){switch(this.type_){case T.ASTNode.types.WORKSPACE:var t=this.location_.getTopBlocks(!0);if(0<t.length)return T.ASTNode.createStackNode(t[0]);break;case T.ASTNode.types.STACK:return t=this.location_,this.findTopASTNodeForBlock_(t);case T.ASTNode.types.BLOCK:return t=this.location_,this.findFirstFieldOrInput_(t);case T.ASTNode.types.INPUT:return T.ASTNode.createConnectionNode(this.location_.targetConnection)}return null},T.ASTNode.prototype.prev=function(){switch(this.type_){case T.ASTNode.types.STACK:return this.navigateBetweenStacks_(!1);case T.ASTNode.types.FIELD:return this.findPrevForField_();case T.ASTNode.types.INPUT:return this.findPrevForInput_();case T.ASTNode.types.BLOCK:var t=this.location_;return T.ASTNode.createConnectionNode(t.previousConnection||t.outputConnection);case T.ASTNode.types.PREVIOUS:if((t=(t=this.location_).targetConnection)&&!t.getParentInput())return T.ASTNode.createConnectionNode(t);break;case T.ASTNode.types.NEXT:return t=this.location_,T.ASTNode.createBlockNode(t.getSourceBlock())}return null},T.ASTNode.prototype.out=function(){switch(this.type_){case T.ASTNode.types.STACK:var t=this.location_,e=t.getRelativeToSurfaceXY(),e=new T.utils.Coordinate(e.x,e.y+T.ASTNode.DEFAULT_OFFSET_Y);return T.ASTNode.createWorkspaceNode(t.workspace,e);case T.ASTNode.types.OUTPUT:return(e=(t=this.location_).targetConnection)?T.ASTNode.createConnectionNode(e):T.ASTNode.createStackNode(t.getSourceBlock());case T.ASTNode.types.FIELD:return T.ASTNode.createBlockNode(this.location_.getSourceBlock());case T.ASTNode.types.INPUT:return t=this.location_,T.ASTNode.createBlockNode(t.getSourceBlock());case T.ASTNode.types.BLOCK:return t=this.location_,this.getOutAstNodeForBlock_(t);case T.ASTNode.types.PREVIOUS:return t=this.location_,this.getOutAstNodeForBlock_(t.getSourceBlock());case T.ASTNode.types.NEXT:return t=this.location_,this.getOutAstNodeForBlock_(t.getSourceBlock())}return null},T.Blocks=Object.create(null),T.utils.deprecation={},T.utils.deprecation.warn=function(t,e,o,i){t=t+" was deprecated on "+e+" and will be deleted on "+o+".",i&&(t+="\nUse "+i+" instead."),console.warn(t)},T.Connection=function(t,e){this.sourceBlock_=t,this.type=e},T.Connection.CAN_CONNECT=0,T.Connection.REASON_SELF_CONNECTION=1,T.Connection.REASON_WRONG_TYPE=2,T.Connection.REASON_TARGET_NULL=3,T.Connection.REASON_CHECKS_FAILED=4,T.Connection.REASON_DIFFERENT_WORKSPACES=5,T.Connection.REASON_SHADOW_PARENT=6,T.Connection.REASON_DRAG_CHECKS_FAILED=7,T.Connection.prototype.targetConnection=null,T.Connection.prototype.disposed=!1,T.Connection.prototype.check_=null,T.Connection.prototype.shadowDom_=null,T.Connection.prototype.x=0,T.Connection.prototype.y=0,T.Connection.prototype.connect_=function(t){var e=this,o=e.getSourceBlock(),i=t.getSourceBlock(),s;if(t.isConnected()&&t.disconnect(),e.isConnected()){var n=e.targetBlock(),r=e.getShadowDom(),l;if(e.shadowDom_=null,n.isShadow())r=T.Xml.blockToDom(n),n.dispose(!1),n=null;else if(e.type==T.connectionTypes.INPUT_VALUE){if(!n.outputConnection)throw Error("Orphan block does not have an output connection.");var a=T.Connection.lastConnectionInRow(i,n);a&&(n.outputConnection.connect(a),n=null)}else if(e.type==T.connectionTypes.NEXT_STATEMENT){if(!n.previousConnection)throw Error("Orphan block does not have a previous connection.");for(a=i;a.nextConnection;){var c=a.getNextBlock();if(!c||c.isShadow()){n.workspace.connectionChecker.canConnect(n.previousConnection,a.nextConnection,!1)&&(a.nextConnection.connect(n.previousConnection),n=null);break}a=c}}n&&(e.disconnect(),T.Events.recordUndo)&&(l=T.Events.getGroup(),setTimeout(function(){n.workspace&&!n.getParent()&&(T.Events.setGroup(l),n.outputConnection?n.outputConnection.onFailedConnect(e):n.previousConnection&&n.previousConnection.onFailedConnect(e),T.Events.setGroup(!1))},T.BUMP_DELAY)),e.shadowDom_=r}T.Events.isEnabled()&&(s=new(T.Events.get(T.Events.BLOCK_MOVE))(i)),T.Connection.connectReciprocally_(e,t),i.setParent(o),s&&(s.recordNew(),T.Events.fire(s))},T.Connection.prototype.dispose=function(){var t;this.isConnected()&&(this.setShadowDom(null),t=this.targetBlock())&&t.unplug(),this.disposed=!0},T.Connection.prototype.getSourceBlock=function(){return this.sourceBlock_},T.Connection.prototype.isSuperior=function(){return this.type==T.connectionTypes.INPUT_VALUE||this.type==T.connectionTypes.NEXT_STATEMENT},T.Connection.prototype.isConnected=function(){return!!this.targetConnection},T.Connection.prototype.canConnectWithReason=function(t){return T.utils.deprecation.warn("Connection.prototype.canConnectWithReason","July 2020","July 2021","the workspace's connection checker"),this.getConnectionChecker().canConnectWithReason(this,t,!1)},T.Connection.prototype.checkConnection=function(t){T.utils.deprecation.warn("Connection.prototype.checkConnection","July 2020","July 2021","the workspace's connection checker");var e=this.getConnectionChecker(),o=e.canConnectWithReason(this,t,!1);if(o!=T.Connection.CAN_CONNECT)throw Error(e.getErrorMessage(o,this,t))},T.Connection.prototype.getConnectionChecker=function(){return this.sourceBlock_.workspace.connectionChecker},T.Connection.prototype.isConnectionAllowed=function(t){return T.utils.deprecation.warn("Connection.prototype.isConnectionAllowed","July 2020","July 2021","the workspace's connection checker"),this.getConnectionChecker().canConnect(this,t,!0)},T.Connection.prototype.onFailedConnect=function(t){},T.Connection.prototype.connect=function(t){var e;this.targetConnection!=t&&this.getConnectionChecker().canConnect(this,t,!1)&&((e=T.Events.getGroup())||T.Events.setGroup(!0),this.isSuperior()?this.connect_(t):t.connect_(this),e||T.Events.setGroup(!1))},T.Connection.connectReciprocally_=function(t,e){if(!t||!e)throw Error("Cannot connect null connections.");(t.targetConnection=e).targetConnection=t},T.Connection.singleConnection_=function(t,e){var o=null;e=e.outputConnection;for(var i=0;i<t.inputList.length;i++){var s=t.inputList[i].connection,n=e.getConnectionChecker();if(s&&s.type==T.connectionTypes.INPUT_VALUE&&n.canConnect(e,s,!1)){if(o)return null;o=s}}return o},T.Connection.lastConnectionInRow=function(t,e){for(var o;o=T.Connection.singleConnection_(t,e);)if(!(t=o.targetBlock())||t.isShadow())return o;return null},T.Connection.prototype.disconnect=function(){var t=this.targetConnection,e,o,t;if(!t)throw Error("Source connection not connected.");if(t.targetConnection!=this)throw Error("Target connection not connected to source connection.");this.isSuperior()?(e=this.sourceBlock_,o=t.getSourceBlock(),t=this):(e=t.getSourceBlock(),o=this.sourceBlock_);var i=T.Events.getGroup();i||T.Events.setGroup(!0),this.disconnectInternal_(e,o),o.isShadow()||t.respawnShadow_(),i||T.Events.setGroup(!1)},T.Connection.prototype.disconnectInternal_=function(t,e){var o;T.Events.isEnabled()&&(o=new(T.Events.get(T.Events.BLOCK_MOVE))(e)),this.targetConnection=this.targetConnection.targetConnection=null,e.setParent(null),o&&(o.recordNew(),T.Events.fire(o))},T.Connection.prototype.respawnShadow_=function(){var t=this.getSourceBlock(),e=this.getShadowDom();if(t.workspace&&e)if((t=T.Xml.domToBlock(e,t.workspace)).outputConnection)this.connect(t.outputConnection);else{if(!t.previousConnection)throw Error("Child block does not have output or previous statement.");this.connect(t.previousConnection)}},T.Connection.prototype.targetBlock=function(){return this.isConnected()?this.targetConnection.getSourceBlock():null},T.Connection.prototype.checkType=function(t){return T.utils.deprecation.warn("Connection.prototype.checkType","October 2019","January 2021","the workspace's connection checker"),this.getConnectionChecker().canConnect(this,t,!1)},T.Connection.prototype.checkType_=function(t){return T.utils.deprecation.warn("Connection.prototype.checkType_","October 2019","January 2021","the workspace's connection checker"),this.checkType(t)},T.Connection.prototype.onCheckChanged_=function(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||(this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug()},T.Connection.prototype.setCheck=function(t){return t?(Array.isArray(t)||(t=[t]),this.check_=t,this.onCheckChanged_()):this.check_=null,this},T.Connection.prototype.getCheck=function(){return this.check_},T.Connection.prototype.setShadowDom=function(t){this.shadowDom_=t,(t=this.targetBlock())?t.isShadow()&&(t.dispose(!1),this.respawnShadow_()):this.respawnShadow_()},T.Connection.prototype.getShadowDom=function(){return this.shadowDom_},T.Connection.prototype.neighbours=function(t){return[]},T.Connection.prototype.getParentInput=function(){for(var t=null,e=this.sourceBlock_,o=e.inputList,i=0;i<e.inputList.length;i++)if(o[i].connection===this){t=o[i];break}return t},T.Connection.prototype.toString=function(){var t=this.sourceBlock_;if(!t)return"Orphan Connection";if(t.outputConnection==this)var e="Output Connection of ";else if(t.previousConnection==this)e="Previous Connection of ";else if(t.nextConnection==this)e="Next Connection of ";else{for(var e=null,o=0,i;i=t.inputList[o];o++)if(i.connection==this){e=i;break}if(!e)return console.warn("Connection not actually connected to sourceBlock_"),"Orphan Connection";e='Input "'+e.name+'" connection on '}return e+t.toDevString()},T.Extensions={},T.Extensions.ALL_={},T.Extensions.register=function(t,e){if("string"!=typeof t||""==t.trim())throw Error('Error: Invalid extension name "'+t+'"');if(T.Extensions.ALL_[t])throw Error('Error: Extension "'+t+'" is already registered.');if("function"!=typeof e)throw Error('Error: Extension "'+t+'" must be a function');T.Extensions.ALL_[t]=e},T.Extensions.registerMixin=function(t,e){if(!e||"object"!=typeof e)throw Error('Error: Mixin "'+t+'" must be a object');T.Extensions.register(t,function(){this.mixin(e)})},T.Extensions.registerMutator=function(t,e,o,i){var s='Error when registering mutator "'+t+'": ',n=(T.Extensions.checkHasFunction_(s,e.domToMutation,"domToMutation"),T.Extensions.checkHasFunction_(s,e.mutationToDom,"mutationToDom"),T.Extensions.checkMutatorDialog_(e,s));if(o&&"function"!=typeof o)throw Error('Extension "'+t+'" is not a function');T.Extensions.register(t,function(){if(n){if(!T.Mutator)throw Error(s+"Missing require for Blockly.Mutator");this.setMutator(new T.Mutator(i||[]))}this.mixin(e),o&&o.apply(this)})},T.Extensions.unregister=function(t){T.Extensions.ALL_[t]?delete T.Extensions.ALL_[t]:console.warn('No extension mapping for name "'+t+'" found to unregister')},T.Extensions.apply=function(t,e,o){var i=T.Extensions.ALL_[t],s;if("function"!=typeof i)throw Error('Error: Extension "'+t+'" not found.');if(o?T.Extensions.checkNoMutatorProperties_(t,e):s=T.Extensions.getMutatorProperties_(e),i.apply(e),o)T.Extensions.checkBlockHasMutatorProperties_('Error after applying mutator "'+t+'": ',e);else if(!T.Extensions.mutatorPropertiesMatch_(s,e))throw Error('Error when applying extension "'+t+'": mutation properties changed when applying a non-mutator extension.')},T.Extensions.checkHasFunction_=function(t,e,o){if(!e)throw Error(t+'missing required property "'+o+'"');if("function"!=typeof e)throw Error(t+'" required property "'+o+'" must be a function')},T.Extensions.checkNoMutatorProperties_=function(t,e){if(T.Extensions.getMutatorProperties_(e).length)throw Error('Error: tried to apply mutation "'+t+'" to a block that already has mutator functions. Block id: '+e.id)},T.Extensions.checkMutatorDialog_=function(t,e){var o=void 0!==t.compose,i=void 0!==t.decompose;if(o&&i){if("function"!=typeof t.compose)throw Error(e+"compose must be a function.");if("function"!=typeof t.decompose)throw Error(e+"decompose must be a function.");return!0}if(o||i)throw Error(e+'Must have both or neither of "compose" and "decompose"');return!1},T.Extensions.checkBlockHasMutatorProperties_=function(t,e){if("function"!=typeof e.domToMutation)throw Error(t+'Applying a mutator didn\'t add "domToMutation"');if("function"!=typeof e.mutationToDom)throw Error(t+'Applying a mutator didn\'t add "mutationToDom"');T.Extensions.checkMutatorDialog_(e,t)},T.Extensions.getMutatorProperties_=function(t){var e=[];return void 0!==t.domToMutation&&e.push(t.domToMutation),void 0!==t.mutationToDom&&e.push(t.mutationToDom),void 0!==t.compose&&e.push(t.compose),void 0!==t.decompose&&e.push(t.decompose),e},T.Extensions.mutatorPropertiesMatch_=function(t,e){if((e=T.Extensions.getMutatorProperties_(e)).length!=t.length)return!1;for(var o=0;o<e.length;o++)if(t[o]!=e[o])return!1;return!0},T.Extensions.buildTooltipForDropdown=function(o,i){var s=[];return"object"==typeof document&&T.utils.runAfterPageLoad(function(){for(var t in i)T.utils.checkMessageReferences(i[t])}),function(){this.type&&-1==s.indexOf(this.type)&&(T.Extensions.checkDropdownOptionsInTable_(this,o,i),s.push(this.type)),this.setTooltip(function(){var t=String(this.getFieldValue(o)),e=i[t];return null==e?-1==s.indexOf(this.type)&&(t="No tooltip mapping for value "+t+" of field "+o,null!=this.type&&(t+=" of block type "+this.type),console.warn(t+".")):e=T.utils.replaceMessageReferences(e),e}.bind(this))}},T.Extensions.checkDropdownOptionsInTable_=function(t,e,o){var i;if(!(i=t.getField(e)).isOptionListDynamic())for(var i=i.getOptions(),s=0;s<i.length;++s){var n=i[s][1];null==o[n]&&console.warn("No tooltip mapping for value "+n+" of field "+e+" of block type "+t.type)}},T.Extensions.buildTooltipWithFieldText=function(e,o){return"object"==typeof document&&T.utils.runAfterPageLoad(function(){T.utils.checkMessageReferences(e)}),function(){this.setTooltip(function(){var t=this.getField(o);return T.utils.replaceMessageReferences(e).replace("%1",t?t.getText():"")}.bind(this))}},T.Extensions.extensionParentTooltip_=function(){this.tooltipWhenNotConnected_=this.tooltip,this.setTooltip(function(){var t=this.getParent();return t&&t.getInputsInline()&&t.tooltip||this.tooltipWhenNotConnected_}.bind(this))},T.Extensions.register("parent_tooltip_when_inline",T.Extensions.extensionParentTooltip_),T.fieldRegistry={},T.fieldRegistry.register=function(t,e){T.registry.register(T.registry.Type.FIELD,t,e)},T.fieldRegistry.unregister=function(t){T.registry.unregister(T.registry.Type.FIELD,t)},T.fieldRegistry.fromJson=function(t){var e=T.registry.getObject(T.registry.Type.FIELD,t.type);return e?e.fromJson(t):(console.warn("Blockly could not create a field of type "+t.type+". The field is probably not being registered. This could be because the file is not loaded, the field does not register itself (Issue #1584), or the registration is not being reached."),null)},T.blockAnimations={},T.blockAnimations.disconnectPid_=0,T.blockAnimations.disconnectGroup_=null,T.blockAnimations.disposeUiEffect=function(t){var e=t.workspace,o=t.getSvgRoot();e.getAudioManager().play("delete"),t=e.getSvgXY(o),(o=o.cloneNode(!0)).translateX_=t.x,o.translateY_=t.y,o.setAttribute("transform","translate("+t.x+","+t.y+")"),e.getParentSvg().appendChild(o),o.bBox_=o.getBBox(),T.blockAnimations.disposeUiStep_(o,e.RTL,new Date,e.scale)},T.blockAnimations.disposeUiStep_=function(t,e,o,i){var s=(new Date-o)/150;1<s?T.utils.dom.removeNode(t):(t.setAttribute("transform","translate("+(t.translateX_+(e?-1:1)*t.bBox_.width*i/2*s)+","+(t.translateY_+t.bBox_.height*i*s)+") scale("+(1-s)*i+")"),setTimeout(T.blockAnimations.disposeUiStep_,10,t,e,o,i))},T.blockAnimations.connectionUiEffect=function(t){var e=t.workspace,o=e.scale,i;e.getAudioManager().play("click"),o<1||(i=e.getSvgXY(t.getSvgRoot()),t.outputConnection?(i.x+=(t.RTL?3:-3)*o,i.y+=13*o):t.previousConnection&&(i.x+=(t.RTL?-23:23)*o,i.y+=3*o),t=T.utils.dom.createSvgElement(T.utils.Svg.CIRCLE,{cx:i.x,cy:i.y,r:0,fill:"none",stroke:"#888","stroke-width":10},e.getParentSvg()),T.blockAnimations.connectionUiStep_(t,new Date,o))},T.blockAnimations.connectionUiStep_=function(t,e,o){var i=(new Date-e)/150;1<i?T.utils.dom.removeNode(t):(t.setAttribute("r",25*i*o),t.style.opacity=1-i,T.blockAnimations.disconnectPid_=setTimeout(T.blockAnimations.connectionUiStep_,10,t,e,o))},T.blockAnimations.disconnectUiEffect=function(t){var e,e;t.workspace.getAudioManager().play("disconnect"),t.workspace.scale<1||(e=t.getHeightWidth().height,e=Math.atan(10/e)/Math.PI*180,t.RTL||(e*=-1),T.blockAnimations.disconnectUiStep_(t.getSvgRoot(),e,new Date))},T.blockAnimations.disconnectUiStep_=function(t,e,o){var i=(new Date-o)/200;1<i?t.skew_="":(t.skew_="skewX("+Math.round(Math.sin(i*Math.PI*3)*(1-i)*e)+")",T.blockAnimations.disconnectGroup_=t,T.blockAnimations.disconnectPid_=setTimeout(T.blockAnimations.disconnectUiStep_,10,t,e,o)),t.setAttribute("transform",t.translate_+t.skew_)},T.blockAnimations.disconnectUiStop=function(){var t;T.blockAnimations.disconnectGroup_&&(clearTimeout(T.blockAnimations.disconnectPid_),(t=T.blockAnimations.disconnectGroup_).skew_="",t.setAttribute("transform",t.translate_),T.blockAnimations.disconnectGroup_=null)},T.Events.BlockDrag=function(t,e,o){T.Events.BlockDrag.superClass_.constructor.call(this,t?t.workspace.id:void 0),this.blockId=t?t.id:null,this.isStart=e,this.blocks=o},T.utils.object.inherits(T.Events.BlockDrag,T.Events.UiBase),T.Events.BlockDrag.prototype.type=T.Events.BLOCK_DRAG,T.Events.BlockDrag.prototype.toJson=function(){var t=T.Events.BlockDrag.superClass_.toJson.call(this);return t.isStart=this.isStart,t.blockId=this.blockId,t.blocks=this.blocks,t},T.Events.BlockDrag.prototype.fromJson=function(t){T.Events.BlockDrag.superClass_.fromJson.call(this,t),this.isStart=t.isStart,this.blockId=t.blockId,this.blocks=t.blocks},T.registry.register(T.registry.Type.EVENT,T.Events.BLOCK_DRAG,T.Events.BlockDrag),T.InsertionMarkerManager=function(t){this.topBlock_=T.selected=t,this.workspace_=t.workspace,this.lastMarker_=this.lastOnStack_=null,this.firstMarker_=this.createMarkerBlock_(this.topBlock_),this.localConnection_=this.closestConnection_=null,this.wouldDeleteBlock_=!1,this.fadedBlock_=this.highlightedBlock_=this.markerConnection_=null,this.availableConnections_=this.initAvailableConnections_()},T.InsertionMarkerManager.PREVIEW_TYPE={INSERTION_MARKER:0,INPUT_OUTLINE:1,REPLACEMENT_FADE:2},T.InsertionMarkerManager.prototype.dispose=function(){this.availableConnections_.length=0,T.Events.disable();try{this.firstMarker_&&this.firstMarker_.dispose(),this.lastMarker_&&this.lastMarker_.dispose()}finally{T.Events.enable()}},T.InsertionMarkerManager.prototype.updateAvailableConnections=function(){this.availableConnections_=this.initAvailableConnections_()},T.InsertionMarkerManager.prototype.wouldDeleteBlock=function(){return this.wouldDeleteBlock_},T.InsertionMarkerManager.prototype.wouldConnectBlock=function(){return!!this.closestConnection_},T.InsertionMarkerManager.prototype.applyConnections=function(){var t;this.closestConnection_&&(T.Events.disable(),this.hidePreview_(),T.Events.enable(),this.localConnection_.connect(this.closestConnection_),this.topBlock_.rendered)&&(t=this.localConnection_.isSuperior()?this.closestConnection_:this.localConnection_,T.blockAnimations.connectionUiEffect(t.getSourceBlock()),this.topBlock_.getRootBlock().bringToFront())},T.InsertionMarkerManager.prototype.update=function(t,e){var o=this.getCandidate_(t);((this.wouldDeleteBlock_=this.shouldDelete_(o,e))||this.shouldUpdatePreviews_(o,t))&&(T.Events.disable(),this.maybeHidePreview_(o),this.maybeShowPreview_(o),T.Events.enable())},T.InsertionMarkerManager.prototype.createMarkerBlock_=function(t){var e=t.type;T.Events.disable();try{var o=this.workspace_.newBlock(e),i;for(o.setInsertionMarker(!0),t.mutationToDom&&(i=t.mutationToDom())&&o.domToMutation(i),e=0;e<t.inputList.length;e++){var s=t.inputList[e];if(s.name!=T.constants.COLLAPSED_INPUT_NAME)for(var n=o.inputList[e],i=0;i<s.fieldRow.length;i++)n.fieldRow[i].setValue(s.fieldRow[i].getValue())}o.setCollapsed(t.isCollapsed()),o.setInputsInline(t.getInputsInline()),o.initSvg(),o.getSvgRoot().setAttribute("visibility","hidden")}finally{T.Events.enable()}return o},T.InsertionMarkerManager.prototype.initAvailableConnections_=function(){var t=this.topBlock_.getConnections_(!1),e=this.topBlock_.lastConnectionInStack();if(e&&e!=this.topBlock_.nextConnection){if(t.push(e),this.lastOnStack_=e,this.lastMarker_){T.Events.disable();try{this.lastMarker_.dispose()}finally{T.Events.enable()}}this.lastMarker_=this.createMarkerBlock_(e.getSourceBlock())}return t},T.InsertionMarkerManager.prototype.shouldUpdatePreviews_=function(t,e){var o=t.local,i=t.closest;if(t=t.radius,!o||!i)return!(!this.localConnection_||!this.closestConnection_);if(this.localConnection_&&this.closestConnection_){if(this.closestConnection_==i&&this.localConnection_==o)return!1;return o=this.localConnection_.x+e.x-this.closestConnection_.x,e=this.localConnection_.y+e.y-this.closestConnection_.y,e=Math.sqrt(o*o+e*e),!(i&&e-T.CURRENT_CONNECTION_PREFERENCE<t)}if(!this.localConnection_&&!this.closestConnection_)return!0;return console.error("Only one of localConnection_ and closestConnection_ was set."),console.error("Returning true from shouldUpdatePreviews, but it's not clear why."),!0},T.InsertionMarkerManager.prototype.getCandidate_=function(t){for(var e=this.getStartRadius_(),o=null,i=null,s=0;s<this.availableConnections_.length;s++){var n=this.availableConnections_[s],r=n.closest(e,t);r.connection&&(o=r.connection,i=n,e=r.radius)}return{closest:o,local:i,radius:e}},T.InsertionMarkerManager.prototype.getStartRadius_=function(){return this.closestConnection_&&this.localConnection_?T.CONNECTING_SNAP_RADIUS:T.SNAP_RADIUS},T.InsertionMarkerManager.prototype.shouldDelete_=function(t,e){return t=t&&!!t.closest&&e!=T.DELETE_AREA_TOOLBOX,!!e&&!this.topBlock_.getParent()&&this.topBlock_.isDeletable()&&!t},T.InsertionMarkerManager.prototype.maybeShowPreview_=function(t){var e;this.wouldDeleteBlock_||(e=t.closest,t=t.local,e&&(e==this.closestConnection_||e.getSourceBlock().isInsertionMarker()?console.log("Trying to connect to an insertion marker"):(this.closestConnection_=e,this.localConnection_=t,this.showPreview_())))},T.InsertionMarkerManager.prototype.showPreview_=function(){var t=this.closestConnection_,e=this.workspace_.getRenderer();switch(e.getConnectionPreviewMethod(t,this.localConnection_,this.topBlock_)){case T.InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE:this.showInsertionInputOutline_();break;case T.InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER:this.showInsertionMarker_();break;case T.InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE:this.showReplacementFade_()}t&&e.shouldHighlightConnection(t)&&t.highlight()},T.InsertionMarkerManager.prototype.maybeHidePreview_=function(t){var e;(!t.closest||(e=this.closestConnection_!=t.closest,t=this.localConnection_!=t.local,this.closestConnection_&&this.localConnection_&&(e||t||this.wouldDeleteBlock_)))&&this.hidePreview_(),this.localConnection_=this.closestConnection_=this.markerConnection_=null},T.InsertionMarkerManager.prototype.hidePreview_=function(){this.closestConnection_&&this.closestConnection_.targetBlock()&&this.workspace_.getRenderer().shouldHighlightConnection(this.closestConnection_)&&this.closestConnection_.unhighlight(),this.fadedBlock_?this.hideReplacementFade_():this.highlightedBlock_?this.hideInsertionInputOutline_():this.markerConnection_&&this.hideInsertionMarker_()},T.InsertionMarkerManager.prototype.showInsertionMarker_=function(){var t=this.localConnection_,e=this.closestConnection_,o=this.lastOnStack_&&t==this.lastOnStack_?this.lastMarker_:this.firstMarker_,t;if((t=o.getMatchingConnection(t.getSourceBlock(),t))==this.markerConnection_)throw Error("Made it to showInsertionMarker_ even though the marker isn't changing");o.render(),o.rendered=!0,o.getSvgRoot().setAttribute("visibility","visible"),t&&e&&o.positionNearConnection(t,e),e&&t.connect(e),this.markerConnection_=t},T.InsertionMarkerManager.prototype.hideInsertionMarker_=function(){if(this.markerConnection_){var t=this.markerConnection_,e=t.getSourceBlock(),o=e.nextConnection,i=e.previousConnection,s=e.outputConnection,s=t.type==T.connectionTypes.INPUT_VALUE&&!(s&&s.targetConnection);if(!(t!=o||i&&i.targetConnection)||s?t.targetBlock().unplug(!1):t.type==T.connectionTypes.NEXT_STATEMENT&&t!=o?((o=t.targetConnection).getSourceBlock().unplug(!1),i=i?i.targetConnection:null,e.unplug(!0),i&&i.connect(o)):e.unplug(!0),t.targetConnection)throw Error("markerConnection_ still connected at the end of disconnectInsertionMarker");this.markerConnection_=null,e.getSvgRoot().setAttribute("visibility","hidden")}else console.log("No insertion marker connection to disconnect")},T.InsertionMarkerManager.prototype.showInsertionInputOutline_=function(){var t=this.closestConnection_;this.highlightedBlock_=t.getSourceBlock(),this.highlightedBlock_.highlightShapeForInput(t,!0)},T.InsertionMarkerManager.prototype.hideInsertionInputOutline_=function(){this.highlightedBlock_.highlightShapeForInput(this.closestConnection_,!1),this.highlightedBlock_=null},T.InsertionMarkerManager.prototype.showReplacementFade_=function(){this.fadedBlock_=this.closestConnection_.targetBlock(),this.fadedBlock_.fadeForReplacement(!0)},T.InsertionMarkerManager.prototype.hideReplacementFade_=function(){this.fadedBlock_.fadeForReplacement(!1),this.fadedBlock_=null},T.InsertionMarkerManager.prototype.getInsertionMarkers=function(){var t=[];return this.firstMarker_&&t.push(this.firstMarker_),this.lastMarker_&&t.push(this.lastMarker_),t},T.BlockDragger=function(t,e){this.draggingBlock_=t,this.workspace_=e,this.draggedConnectionManager_=new T.InsertionMarkerManager(this.draggingBlock_),this.deleteArea_=null,this.wouldDeleteBlock_=!1,this.startXY_=this.draggingBlock_.getRelativeToSurfaceXY(),this.dragIconData_=T.BlockDragger.initIconData_(t)},T.BlockDragger.prototype.dispose=function(){this.dragIconData_.length=0,this.draggedConnectionManager_&&this.draggedConnectionManager_.dispose()},T.BlockDragger.initIconData_=function(t){var e=[];t=t.getDescendants(!1);for(var o=0,i;i=t[o];o++)for(var i=i.getIcons(),s=0;s<i.length;s++){var n={location:i[s].getIconLocation(),icon:i[s]};e.push(n)}return e},T.BlockDragger.prototype.startBlockDrag=function(t,e){T.Events.getGroup()||T.Events.setGroup(!0),this.fireDragStartEvent_(),this.workspace_.isMutator&&this.draggingBlock_.bringToFront(),T.utils.dom.startTextWidthCache(),this.workspace_.setResizesEnabled(!1),T.blockAnimations.disconnectUiStop(),(this.draggingBlock_.getParent()||e&&this.draggingBlock_.nextConnection&&this.draggingBlock_.nextConnection.targetBlock())&&(this.draggingBlock_.unplug(e),t=this.pixelsToWorkspaceUnits_(t),t=T.utils.Coordinate.sum(this.startXY_,t),this.draggingBlock_.translate(t.x,t.y),T.blockAnimations.disconnectUiEffect(this.draggingBlock_),this.draggedConnectionManager_.updateAvailableConnections()),this.draggingBlock_.setDragging(!0),this.draggingBlock_.moveToDragSurface(),(t=this.workspace_.getToolbox())&&"function"==typeof t.addStyle&&(e=this.draggingBlock_.isDeletable()?"blocklyToolboxDelete":"blocklyToolboxGrab",t.addStyle(e))},T.BlockDragger.prototype.fireDragStartEvent_=function(){var t=new(T.Events.get(T.Events.BLOCK_DRAG))(this.draggingBlock_,!0,this.draggingBlock_.getDescendants(!1));T.Events.fire(t)},T.BlockDragger.prototype.dragBlock=function(t,e){e=this.pixelsToWorkspaceUnits_(e);var o=T.utils.Coordinate.sum(this.startXY_,e);this.draggingBlock_.moveDuringDrag(o),this.dragIcons_(e),this.deleteArea_=this.workspace_.isDeleteArea(t),this.draggedConnectionManager_.update(e,this.deleteArea_),this.updateCursorDuringBlockDrag_()},T.BlockDragger.prototype.endBlockDrag=function(t,e){this.dragBlock(t,e),this.dragIconData_=[],this.fireDragEndEvent_(),T.utils.dom.stopTextWidthCache(),T.blockAnimations.disconnectUiStop(),t=this.pixelsToWorkspaceUnits_(e),e=T.utils.Coordinate.sum(this.startXY_,t),this.draggingBlock_.moveOffDragSurface(e),this.maybeDeleteBlock_()||(this.draggingBlock_.moveConnections(t.x,t.y),this.draggingBlock_.setDragging(!1),this.fireMoveEvent_(),this.draggedConnectionManager_.wouldConnectBlock()?this.draggedConnectionManager_.applyConnections():this.draggingBlock_.render(),this.draggingBlock_.scheduleSnapAndBump()),this.workspace_.setResizesEnabled(!0),(t=this.workspace_.getToolbox())&&"function"==typeof t.removeStyle&&(e=this.draggingBlock_.isDeletable()?"blocklyToolboxDelete":"blocklyToolboxGrab",t.removeStyle(e)),T.Events.setGroup(!1)},T.BlockDragger.prototype.fireDragEndEvent_=function(){var t=new(T.Events.get(T.Events.BLOCK_DRAG))(this.draggingBlock_,!1,this.draggingBlock_.getDescendants(!1));T.Events.fire(t)},T.BlockDragger.prototype.fireMoveEvent_=function(){var t=new(T.Events.get(T.Events.BLOCK_MOVE))(this.draggingBlock_);t.oldCoordinate=this.startXY_,t.recordNew(),T.Events.fire(t)},T.BlockDragger.prototype.maybeDeleteBlock_=function(){var t=this.workspace_.trashcan;return this.wouldDeleteBlock_?(t&&setTimeout(t.closeLid.bind(t),100),this.fireMoveEvent_(),this.draggingBlock_.dispose(!1,!0),T.draggingConnections=[]):t&&t.closeLid(),this.wouldDeleteBlock_},T.BlockDragger.prototype.updateCursorDuringBlockDrag_=function(){this.wouldDeleteBlock_=this.draggedConnectionManager_.wouldDeleteBlock();var t=this.workspace_.trashcan;this.wouldDeleteBlock_?(this.draggingBlock_.setDeleteStyle(!0),this.deleteArea_==T.DELETE_AREA_TRASH&&t&&t.setLidOpen(!0)):(this.draggingBlock_.setDeleteStyle(!1),t&&t.setLidOpen(!1))},T.BlockDragger.prototype.pixelsToWorkspaceUnits_=function(t){return t=new T.utils.Coordinate(t.x/this.workspace_.scale,t.y/this.workspace_.scale),this.workspace_.isMutator&&t.scale(1/this.workspace_.options.parentWorkspace.scale),t},T.BlockDragger.prototype.dragIcons_=function(t){for(var e=0;e<this.dragIconData_.length;e++){var o=this.dragIconData_[e];o.icon.setIconLocation(T.utils.Coordinate.sum(o.location,t))}},T.BlockDragger.prototype.getInsertionMarkers=function(){return this.draggedConnectionManager_&&this.draggedConnectionManager_.getInsertionMarkers?this.draggedConnectionManager_.getInsertionMarkers():[]},T.IConnectionChecker=function(){},T.ConnectionChecker=function(){},T.ConnectionChecker.prototype.canConnect=function(t,e,o,i){return this.canConnectWithReason(t,e,o,i)==T.Connection.CAN_CONNECT},T.ConnectionChecker.prototype.canConnectWithReason=function(t,e,o,i){var s=this.doSafetyChecks(t,e);return s!=T.Connection.CAN_CONNECT?s:this.doTypeChecks(t,e)?o&&!this.doDragChecks(t,e,i||0)?T.Connection.REASON_DRAG_CHECKS_FAILED:T.Connection.CAN_CONNECT:T.Connection.REASON_CHECKS_FAILED},T.ConnectionChecker.prototype.getErrorMessage=function(t,e,o){switch(t){case T.Connection.REASON_SELF_CONNECTION:return"Attempted to connect a block to itself.";case T.Connection.REASON_DIFFERENT_WORKSPACES:return"Blocks not on same workspace.";case T.Connection.REASON_WRONG_TYPE:return"Attempt to connect incompatible types.";case T.Connection.REASON_TARGET_NULL:return"Target connection is null.";case T.Connection.REASON_CHECKS_FAILED:return"Connection checks failed. "+e+" expected "+e.getCheck()+", found "+o.getCheck();case T.Connection.REASON_SHADOW_PARENT:return"Connecting non-shadow to shadow block.";case T.Connection.REASON_DRAG_CHECKS_FAILED:return"Drag checks failed.";default:return"Unknown connection failure: this should never happen!"}},T.ConnectionChecker.prototype.doSafetyChecks=function(t,e){if(!t||!e)return T.Connection.REASON_TARGET_NULL;var o,i;return t.isSuperior()?(o=t.getSourceBlock(),i=e.getSourceBlock()):(i=t.getSourceBlock(),o=e.getSourceBlock()),o==i?T.Connection.REASON_SELF_CONNECTION:e.type!=T.OPPOSITE_TYPE[t.type]?T.Connection.REASON_WRONG_TYPE:o.workspace!==i.workspace?T.Connection.REASON_DIFFERENT_WORKSPACES:o.isShadow()&&!i.isShadow()?T.Connection.REASON_SHADOW_PARENT:T.Connection.CAN_CONNECT},T.ConnectionChecker.prototype.doTypeChecks=function(t,e){if(t=t.getCheck(),e=e.getCheck(),!t||!e)return!0;for(var o=0;o<t.length;o++)if(-1!=e.indexOf(t[o]))return!0;return!1},T.ConnectionChecker.prototype.doDragChecks=function(t,e,o){if(t.distanceFrom(e)>o||e.getSourceBlock().isInsertionMarker())return!1;switch(e.type){case T.connectionTypes.PREVIOUS_STATEMENT:return this.canConnectToPrevious_(t,e);case T.connectionTypes.OUTPUT_VALUE:if(e.isConnected()&&!e.targetBlock().isInsertionMarker()||t.isConnected())return!1;break;case T.connectionTypes.INPUT_VALUE:if(e.isConnected()&&!e.targetBlock().isMovable()&&!e.targetBlock().isShadow())return!1;break;case T.connectionTypes.NEXT_STATEMENT:if(e.isConnected()&&!t.getSourceBlock().nextConnection&&!e.targetBlock().isShadow()&&e.targetBlock().nextConnection)return!1;break;default:return!1}return-1==T.draggingConnections.indexOf(e)},T.ConnectionChecker.prototype.canConnectToPrevious_=function(t,e){if(t.targetConnection||-1!=T.draggingConnections.indexOf(e))return!1;if(!e.targetConnection)return!0;return!!(t=e.targetBlock()).isInsertionMarker()&&!t.getPreviousBlock()},T.registry.register(T.registry.Type.CONNECTION_CHECKER,T.registry.DEFAULT,T.ConnectionChecker),T.VariableMap=function(t){this.variableMap_=Object.create(null),this.workspace=t},T.VariableMap.prototype.clear=function(){this.variableMap_=Object.create(null)},T.VariableMap.prototype.renameVariable=function(t,e){var o=this.getVariable(e,t.type),i=this.workspace.getAllBlocks(!1);T.Events.setGroup(!0);try{o&&o.getId()!=t.getId()?this.renameVariableWithConflict_(t,e,o,i):this.renameVariableAndUses_(t,e,i)}finally{T.Events.setGroup(!1)}},T.VariableMap.prototype.renameVariableById=function(t,e){var o=this.getVariableById(t);if(!o)throw Error("Tried to rename a variable that didn't exist. ID: "+t);this.renameVariable(o,e)},T.VariableMap.prototype.renameVariableAndUses_=function(t,e,o){for(T.Events.fire(new(T.Events.get(T.Events.VAR_RENAME))(t,e)),t.name=e,e=0;e<o.length;e++)o[e].updateVarName(t)},T.VariableMap.prototype.renameVariableWithConflict_=function(t,e,o,i){var s=t.type;for(e!=o.name&&this.renameVariableAndUses_(o,e,i),e=0;e<i.length;e++)i[e].renameVarById(t.getId(),o.getId());T.Events.fire(new(T.Events.get(T.Events.VAR_DELETE))(t)),t=this.getVariablesOfType(s).indexOf(t),this.variableMap_[s].splice(t,1)},T.VariableMap.prototype.createVariable=function(t,e,o){var i=this.getVariable(t,e);if(i){if(o&&i.getId()!=o)throw Error('Variable "'+t+'" is already in use and its id is "'+i.getId()+'" which conflicts with the passed in id, "'+o+'".');return i}if(o&&this.getVariableById(o))throw Error('Variable id, "'+o+'", is already in use.');return i=o||T.utils.genUid(),i=new T.VariableModel(this.workspace,t,e=e||"",i),(t=this.variableMap_[e]||[]).push(i),delete this.variableMap_[e],this.variableMap_[e]=t,i},T.VariableMap.prototype.deleteVariable=function(t){for(var e=this.variableMap_[t.type],o=0,i;i=e[o];o++)if(i.getId()==t.getId()){e.splice(o,1),T.Events.fire(new(T.Events.get(T.Events.VAR_DELETE))(t));break}},T.VariableMap.prototype.deleteVariableById=function(t){var e=this.getVariableById(t);if(e){var o=e.name,i=this.getVariableUsesById(t),s;for(t=0;s=i[t];t++)if("procedures_defnoreturn"==s.type||"procedures_defreturn"==s.type)return t=s.getFieldValue("NAME"),o=T.Msg.CANNOT_DELETE_VARIABLE_PROCEDURE.replace("%1",o).replace("%2",t),void T.alert(o);var n=this;1<i.length?(o=T.Msg.DELETE_VARIABLE_CONFIRMATION.replace("%1",String(i.length)).replace("%2",o),T.confirm(o,function(t){t&&e&&n.deleteVariableInternal(e,i)})):n.deleteVariableInternal(e,i)}else console.warn("Can't delete non-existent variable: "+t)},T.VariableMap.prototype.deleteVariableInternal=function(t,e){var o=T.Events.getGroup();o||T.Events.setGroup(!0);try{for(var i=0;i<e.length;i++)e[i].dispose(!0);this.deleteVariable(t)}finally{o||T.Events.setGroup(!1)}},T.VariableMap.prototype.getVariable=function(t,e){if(e=this.variableMap_[e||""])for(var o=0,i;i=e[o];o++)if(T.Names.equals(i.name,t))return i;return null},T.VariableMap.prototype.getVariableById=function(t){for(var e=Object.keys(this.variableMap_),o=0;o<e.length;o++)for(var i=e[o],s=0,n;n=this.variableMap_[i][s];s++)if(n.getId()==t)return n;return null},T.VariableMap.prototype.getVariablesOfType=function(t){return(t=this.variableMap_[t||""])?t.slice():[]},T.VariableMap.prototype.getVariableTypes=function(t){var e={};T.utils.object.mixin(e,this.variableMap_),t&&t.getPotentialVariableMap()&&T.utils.object.mixin(e,t.getPotentialVariableMap().variableMap_),t=Object.keys(e);for(var e=!1,o=0;o<t.length;o++)""==t[o]&&(e=!0);return e||t.push(""),t},T.VariableMap.prototype.getAllVariables=function(){var t=[],e;for(e in this.variableMap_)t=t.concat(this.variableMap_[e]);return t},T.VariableMap.prototype.getAllVariableNames=function(){var t=[],e;for(e in this.variableMap_)for(var o=this.variableMap_[e],i=0,s;s=o[i];i++)t.push(s.name);return t},T.VariableMap.prototype.getVariableUsesById=function(t){for(var e=[],o=this.workspace.getAllBlocks(!1),i=0;i<o.length;i++){var s=o[i].getVarModels();if(s)for(var n=0;n<s.length;n++)s[n].getId()==t&&e.push(o[i])}return e},T.Workspace=function(t){this.id=T.utils.genUid(),(T.Workspace.WorkspaceDB_[this.id]=this).options=t||new T.Options({}),this.RTL=!!this.options.RTL,this.horizontalLayout=!!this.options.horizontalLayout,this.toolboxPosition=this.options.toolboxPosition,this.connectionChecker=new(T.registry.getClassFromOptions(T.registry.Type.CONNECTION_CHECKER,this.options,!0))(this),this.topBlocks_=[],this.topComments_=[],this.commentDB_=Object.create(null),this.listeners_=[],this.undoStack_=[],this.redoStack_=[],this.blockDB_=Object.create(null),this.typedBlocksDB_=Object.create(null),this.variableMap_=new T.VariableMap(this),this.potentialVariableMap_=null},T.Workspace.prototype.rendered=!1,T.Workspace.prototype.isClearing=!1,T.Workspace.prototype.MAX_UNDO=1024,T.Workspace.prototype.connectionDBList=null,T.Workspace.prototype.dispose=function(){this.listeners_.length=0,this.clear(),delete T.Workspace.WorkspaceDB_[this.id]},T.Workspace.SCAN_ANGLE=3,T.Workspace.prototype.sortObjects_=function(t,e){return t=t.getRelativeToSurfaceXY(),e=e.getRelativeToSurfaceXY(),t.y+T.Workspace.prototype.sortObjects_.offset*t.x-(e.y+T.Workspace.prototype.sortObjects_.offset*e.x)},T.Workspace.prototype.addTopBlock=function(t){this.topBlocks_.push(t)},T.Workspace.prototype.removeTopBlock=function(t){if(!T.utils.arrayRemove(this.topBlocks_,t))throw Error("Block not present in workspace's list of top-most blocks.")},T.Workspace.prototype.getTopBlocks=function(t){var e=[].concat(this.topBlocks_);return t&&1<e.length&&(this.sortObjects_.offset=Math.sin(T.utils.math.toRadians(T.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),e.sort(this.sortObjects_)),e},T.Workspace.prototype.addTypedBlock=function(t){this.typedBlocksDB_[t.type]||(this.typedBlocksDB_[t.type]=[]),this.typedBlocksDB_[t.type].push(t)},T.Workspace.prototype.removeTypedBlock=function(t){this.typedBlocksDB_[t.type].splice(this.typedBlocksDB_[t.type].indexOf(t),1),this.typedBlocksDB_[t.type].length||delete this.typedBlocksDB_[t.type]},T.Workspace.prototype.getBlocksByType=function(t,e){if(!this.typedBlocksDB_[t])return[];return t=this.typedBlocksDB_[t].slice(0),e&&1<t.length&&(this.sortObjects_.offset=Math.sin(T.utils.math.toRadians(T.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),t.sort(this.sortObjects_)),t},T.Workspace.prototype.addTopComment=function(t){this.topComments_.push(t),this.commentDB_[t.id]&&console.warn('Overriding an existing comment on this workspace, with id "'+t.id+'"'),this.commentDB_[t.id]=t},T.Workspace.prototype.removeTopComment=function(t){if(!T.utils.arrayRemove(this.topComments_,t))throw Error("Comment not present in workspace's list of top-most comments.");delete this.commentDB_[t.id]},T.Workspace.prototype.getTopComments=function(t){var e=[].concat(this.topComments_);return t&&1<e.length&&(this.sortObjects_.offset=Math.sin(T.utils.math.toRadians(T.Workspace.SCAN_ANGLE)),this.RTL&&(this.sortObjects_.offset*=-1),e.sort(this.sortObjects_)),e},T.Workspace.prototype.getAllBlocks=function(t){if(t){t=this.getTopBlocks(!0);for(var e=[],o=0;o<t.length;o++)e.push.apply(e,t[o].getDescendants(!0))}else for(e=this.getTopBlocks(!1),o=0;o<e.length;o++)e.push.apply(e,e[o].getChildren(!1));return e.filter(function(t){return!t.isInsertionMarker()})},T.Workspace.prototype.clear=function(){this.isClearing=!0;try{var t=T.Events.getGroup();for(t||T.Events.setGroup(!0);this.topBlocks_.length;)this.topBlocks_[0].dispose(!1);for(;this.topComments_.length;)this.topComments_[this.topComments_.length-1].dispose(!1);t||T.Events.setGroup(!1),this.variableMap_.clear(),this.potentialVariableMap_&&this.potentialVariableMap_.clear()}finally{this.isClearing=!1}},T.Workspace.prototype.renameVariableById=function(t,e){this.variableMap_.renameVariableById(t,e)},T.Workspace.prototype.createVariable=function(t,e,o){return this.variableMap_.createVariable(t,e,o)},T.Workspace.prototype.getVariableUsesById=function(t){return this.variableMap_.getVariableUsesById(t)},T.Workspace.prototype.deleteVariableById=function(t){this.variableMap_.deleteVariableById(t)},T.Workspace.prototype.getVariable=function(t,e){return this.variableMap_.getVariable(t,e)},T.Workspace.prototype.getVariableById=function(t){return this.variableMap_.getVariableById(t)},T.Workspace.prototype.getVariablesOfType=function(t){return this.variableMap_.getVariablesOfType(t)},T.Workspace.prototype.getVariableTypes=function(){return this.variableMap_.getVariableTypes(this)},T.Workspace.prototype.getAllVariables=function(){return this.variableMap_.getAllVariables()},T.Workspace.prototype.getAllVariableNames=function(){return this.variableMap_.getAllVariableNames()},T.Workspace.prototype.getWidth=function(){return 0},T.Workspace.prototype.newBlock=function(t,e){return new T.Block(this,t,e)},T.Workspace.prototype.remainingCapacity=function(){return isNaN(this.options.maxBlocks)?1/0:this.options.maxBlocks-this.getAllBlocks(!1).length},T.Workspace.prototype.remainingCapacityOfType=function(t){return this.options.maxInstances?(void 0!==this.options.maxInstances[t]?this.options.maxInstances[t]:1/0)-this.getBlocksByType(t,!1).length:1/0},T.Workspace.prototype.isCapacityAvailable=function(t){if(!this.hasBlockLimits())return!0;var e=0,o;for(o in t){if(t[o]>this.remainingCapacityOfType(o))return!1;e+=t[o]}return!(e>this.remainingCapacity())},T.Workspace.prototype.hasBlockLimits=function(){return 1/0!=this.options.maxBlocks||!!this.options.maxInstances},T.Workspace.prototype.getUndoStack=function(){return this.undoStack_},T.Workspace.prototype.getRedoStack=function(){return this.redoStack_},T.Workspace.prototype.undo=function(t){var e=t?this.redoStack_:this.undoStack_,o=t?this.undoStack_:this.redoStack_,i=e.pop();if(i){for(var s=[i];e.length&&i.group&&i.group==e[e.length-1].group;)s.push(e.pop());for(e=0;i=s[e];e++)o.push(i);s=T.Events.filter(s,t),T.Events.recordUndo=!1;try{for(e=0;i=s[e];e++)i.run(t)}finally{T.Events.recordUndo=!0}}},T.Workspace.prototype.clearUndo=function(){this.undoStack_.length=0,this.redoStack_.length=0,T.Events.clearPendingUndo()},T.Workspace.prototype.addChangeListener=function(t){return this.listeners_.push(t),t},T.Workspace.prototype.removeChangeListener=function(t){T.utils.arrayRemove(this.listeners_,t)},T.Workspace.prototype.fireChangeListener=function(t){if(t.recordUndo)for(this.undoStack_.push(t),this.redoStack_.length=0;this.undoStack_.length>this.MAX_UNDO&&0<=this.MAX_UNDO;)this.undoStack_.shift();for(var e=0,o;o=this.listeners_[e];e++)o(t)},T.Workspace.prototype.getBlockById=function(t){return this.blockDB_[t]||null},T.Workspace.prototype.setBlockById=function(t,e){this.blockDB_[t]=e},T.Workspace.prototype.removeBlockById=function(t){delete this.blockDB_[t]},T.Workspace.prototype.getCommentById=function(t){return this.commentDB_[t]||null},T.Workspace.prototype.allInputsFilled=function(t){for(var e=this.getTopBlocks(!1),o=0,i;i=e[o];o++)if(!i.allInputsFilled(t))return!1;return!0},T.Workspace.prototype.getPotentialVariableMap=function(){return this.potentialVariableMap_},T.Workspace.prototype.createPotentialVariableMap=function(){this.potentialVariableMap_=new T.VariableMap(this)},T.Workspace.prototype.getVariableMap=function(){return this.variableMap_},T.Workspace.prototype.setVariableMap=function(t){this.variableMap_=t},T.Workspace.WorkspaceDB_=Object.create(null),T.Workspace.getById=function(t){return T.Workspace.WorkspaceDB_[t]||null},T.Workspace.getAll=function(){var t=[],e;for(e in T.Workspace.WorkspaceDB_)t.push(T.Workspace.WorkspaceDB_[e]);return t},T.Bubble=function(t,e,o,i,s,n){this.workspace_=t,this.content_=e,this.shape_=o,this.onMouseDownResizeWrapper_=this.onMouseDownBubbleWrapper_=this.moveCallback_=this.resizeCallback_=null,this.disposed=!1,o=T.Bubble.ARROW_ANGLE,this.workspace_.RTL&&(o=-o),this.arrow_radians_=T.utils.math.toRadians(o),t.getBubbleCanvas().appendChild(this.createDom_(e,!(!s||!n))),this.setAnchorLocation(i),s&&n||(s=(t=this.content_.getBBox()).width+2*T.Bubble.BORDER_WIDTH,n=t.height+2*T.Bubble.BORDER_WIDTH),this.setBubbleSize(s,n),this.positionBubble_(),this.renderArrow_(),this.rendered_=!0},T.Bubble.BORDER_WIDTH=6,T.Bubble.ARROW_THICKNESS=5,T.Bubble.ARROW_ANGLE=20,T.Bubble.ARROW_BEND=4,T.Bubble.ANCHOR_RADIUS=8,T.Bubble.onMouseUpWrapper_=null,T.Bubble.onMouseMoveWrapper_=null,T.Bubble.unbindDragEvents_=function(){T.Bubble.onMouseUpWrapper_&&(T.browserEvents.unbind(T.Bubble.onMouseUpWrapper_),T.Bubble.onMouseUpWrapper_=null),T.Bubble.onMouseMoveWrapper_&&(T.browserEvents.unbind(T.Bubble.onMouseMoveWrapper_),T.Bubble.onMouseMoveWrapper_=null)},T.Bubble.bubbleMouseUp_=function(t){T.Touch.clearTouchIdentifier(),T.Bubble.unbindDragEvents_()},T.Bubble.prototype.rendered_=!1,T.Bubble.prototype.anchorXY_=null,T.Bubble.prototype.relativeLeft_=0,T.Bubble.prototype.relativeTop_=0,T.Bubble.prototype.width_=0,T.Bubble.prototype.height_=0,T.Bubble.prototype.autoLayout_=!0,T.Bubble.prototype.createDom_=function(t,e){this.bubbleGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{},null);var o={filter:"url(#"+this.workspace_.getRenderer().getConstants().embossFilterId+")"};return T.utils.userAgent.JAVA_FX&&(o={}),o=T.utils.dom.createSvgElement(T.utils.Svg.G,o,this.bubbleGroup_),this.bubbleArrow_=T.utils.dom.createSvgElement(T.utils.Svg.PATH,{},o),this.bubbleBack_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{class:"blocklyDraggable",x:0,y:0,rx:T.Bubble.BORDER_WIDTH,ry:T.Bubble.BORDER_WIDTH},o),e?(this.resizeGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{class:this.workspace_.RTL?"blocklyResizeSW":"blocklyResizeSE"},this.bubbleGroup_),e=2*T.Bubble.BORDER_WIDTH,T.utils.dom.createSvgElement(T.utils.Svg.POLYGON,{points:"0,x x,x x,0".replace(/x/g,e.toString())},this.resizeGroup_),T.utils.dom.createSvgElement(T.utils.Svg.LINE,{class:"blocklyResizeLine",x1:e/3,y1:e-1,x2:e-1,y2:e/3},this.resizeGroup_),T.utils.dom.createSvgElement(T.utils.Svg.LINE,{class:"blocklyResizeLine",x1:2*e/3,y1:e-1,x2:e-1,y2:2*e/3},this.resizeGroup_)):this.resizeGroup_=null,this.workspace_.options.readOnly||(this.onMouseDownBubbleWrapper_=T.browserEvents.conditionalBind(this.bubbleBack_,"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&(this.onMouseDownResizeWrapper_=T.browserEvents.conditionalBind(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))),this.bubbleGroup_.appendChild(t),this.bubbleGroup_},T.Bubble.prototype.getSvgRoot=function(){return this.bubbleGroup_},T.Bubble.prototype.setSvgId=function(t){this.bubbleGroup_.dataset&&(this.bubbleGroup_.dataset.blockId=t)},T.Bubble.prototype.bubbleMouseDown_=function(t){var e=this.workspace_.getGesture(t);e&&e.handleBubbleStart(t,this)},T.Bubble.prototype.showContextMenu=function(t){},T.Bubble.prototype.isDeletable=function(){return!1},T.Bubble.prototype.setDeleteStyle=function(t){},T.Bubble.prototype.resizeMouseDown_=function(t){this.promote(),T.Bubble.unbindDragEvents_(),T.utils.isRightButton(t)||(this.workspace_.startDrag(t,new T.utils.Coordinate(this.workspace_.RTL?-this.width_:this.width_,this.height_)),T.Bubble.onMouseUpWrapper_=T.browserEvents.conditionalBind(document,"mouseup",this,T.Bubble.bubbleMouseUp_),T.Bubble.onMouseMoveWrapper_=T.browserEvents.conditionalBind(document,"mousemove",this,this.resizeMouseMove_),T.hideChaff()),t.stopPropagation()},T.Bubble.prototype.resizeMouseMove_=function(t){this.autoLayout_=!1,t=this.workspace_.moveDrag(t),this.setBubbleSize(this.workspace_.RTL?-t.x:t.x,t.y),this.workspace_.RTL&&this.positionBubble_()},T.Bubble.prototype.registerResizeEvent=function(t){this.resizeCallback_=t},T.Bubble.prototype.registerMoveEvent=function(t){this.moveCallback_=t},T.Bubble.prototype.promote=function(){var t=this.bubbleGroup_.parentNode;return t.lastChild!==this.bubbleGroup_&&(t.appendChild(this.bubbleGroup_),!0)},T.Bubble.prototype.setAnchorLocation=function(t){this.anchorXY_=t,this.rendered_&&this.positionBubble_()},T.Bubble.prototype.layoutBubble_=function(){var t=this.workspace_.getMetricsManager().getViewMetrics(!0),e=this.getOptimalRelativeLeft_(t),o=this.getOptimalRelativeTop_(t),i=this.shape_.getBBox(),s={x:e,y:-this.height_-this.workspace_.getRenderer().getConstants().MIN_BLOCK_HEIGHT},n={x:-this.width_-30,y:o},o={x:i.width,y:o},r={x:e,y:i.height},e=i.width<i.height?o:r,i=i.width<i.height?r:o,r=(o=this.getOverlap_(s,t),this.getOverlap_(n,t)),l=this.getOverlap_(e,t),t=this.getOverlap_(i,t);o==(t=Math.max(o,r,l,t))?(this.relativeLeft_=s.x,this.relativeTop_=s.y):r==t?(this.relativeLeft_=n.x,this.relativeTop_=n.y):l==t?(this.relativeLeft_=e.x,this.relativeTop_=e.y):(this.relativeLeft_=i.x,this.relativeTop_=i.y)},T.Bubble.prototype.getOverlap_=function(t,e){var o=this.workspace_.RTL?this.anchorXY_.x-t.x-this.width_:t.x+this.anchorXY_.x;return t=t.y+this.anchorXY_.y,Math.max(0,Math.min(1,(Math.min(o+this.width_,e.left+e.width)-Math.max(o,e.left))*(Math.min(t+this.height_,e.top+e.height)-Math.max(t,e.top))/(this.width_*this.height_)))},T.Bubble.prototype.getOptimalRelativeLeft_=function(t){var e=-this.width_/4,o,i,s,n;if(this.width_>t.width)return e;return this.workspace_.RTL?(i=(o=this.anchorXY_.x-e)-this.width_,s=t.left+t.width,n=t.left+T.Scrollbar.scrollbarThickness/this.workspace_.scale):(o=(i=e+this.anchorXY_.x)+this.width_,n=t.left,s=t.left+t.width-T.Scrollbar.scrollbarThickness/this.workspace_.scale),this.workspace_.RTL?i<n?e=-(n-this.anchorXY_.x+this.width_):s<o&&(e=-(s-this.anchorXY_.x)):i<n?e=n-this.anchorXY_.x:s<o&&(e=s-this.anchorXY_.x-this.width_),e},T.Bubble.prototype.getOptimalRelativeTop_=function(t){var e=-this.height_/4;if(this.height_>t.height)return e;var o=this.anchorXY_.y+e,i=o+this.height_,s=t.top,n=(t=t.top+t.height-T.Scrollbar.scrollbarThickness/this.workspace_.scale,this.anchorXY_.y);return o<s?e=s-n:t<i&&(e=t-n-this.height_),e},T.Bubble.prototype.positionBubble_=function(){var t=this.anchorXY_.x,t=this.workspace_.RTL?t-(this.relativeLeft_+this.width_):t+this.relativeLeft_;this.moveTo(t,this.relativeTop_+this.anchorXY_.y)},T.Bubble.prototype.moveTo=function(t,e){this.bubbleGroup_.setAttribute("transform","translate("+t+","+e+")")},T.Bubble.prototype.setDragging=function(t){!t&&this.moveCallback_&&this.moveCallback_()},T.Bubble.prototype.getBubbleSize=function(){return new T.utils.Size(this.width_,this.height_)},T.Bubble.prototype.setBubbleSize=function(t,e){var o=2*T.Bubble.BORDER_WIDTH;t=Math.max(t,o+45),e=Math.max(e,o+20),this.width_=t,this.height_=e,this.bubbleBack_.setAttribute("width",t),this.bubbleBack_.setAttribute("height",e),this.resizeGroup_&&(this.workspace_.RTL?this.resizeGroup_.setAttribute("transform","translate("+2*T.Bubble.BORDER_WIDTH+","+(e-o)+") scale(-1 1)"):this.resizeGroup_.setAttribute("transform","translate("+(t-o)+","+(e-o)+")")),this.autoLayout_&&this.layoutBubble_(),this.positionBubble_(),this.renderArrow_(),this.resizeCallback_&&this.resizeCallback_()},T.Bubble.prototype.renderArrow_=function(){var t=[],e=this.width_/2,o=this.height_/2,i=-this.relativeLeft_,s=-this.relativeTop_,n,r,l,a,c,h,l,i,s,h,u;e==i&&o==s?t.push("M "+e+","+o):(s-=o,i-=e,this.workspace_.RTL&&(i*=-1),n=Math.sqrt(s*s+i*i),r=Math.acos(i/n),l=(r=s<0?2*Math.PI-r:r)+Math.PI/2,2*Math.PI<l&&(l-=2*Math.PI),a=Math.sin(l),c=Math.cos(l),l=((h=this.getBubbleSize()).width+h.height)/T.Bubble.ARROW_THICKNESS,l=Math.min(l,h.width,h.height)/4,i=e+(h=1-T.Bubble.ANCHOR_RADIUS/n)*i,s=o+h*s,h=e+l*c,u=o+l*a,e-=l*c,o-=l*a,(a=r+this.arrow_radians_)>2*Math.PI&&(a-=2*Math.PI),r=Math.sin(a)*n/T.Bubble.ARROW_BEND,n=Math.cos(a)*n/T.Bubble.ARROW_BEND,t.push("M"+h+","+u),t.push("C"+(h+n)+","+(u+r)+" "+i+","+s+" "+i+","+s),t.push("C"+i+","+s+" "+(e+n)+","+(o+r)+" "+e+","+o)),t.push("z"),this.bubbleArrow_.setAttribute("d",t.join(" "))},T.Bubble.prototype.setColour=function(t){this.bubbleBack_.setAttribute("fill",t),this.bubbleArrow_.setAttribute("fill",t)},T.Bubble.prototype.dispose=function(){this.onMouseDownBubbleWrapper_&&T.browserEvents.unbind(this.onMouseDownBubbleWrapper_),this.onMouseDownResizeWrapper_&&T.browserEvents.unbind(this.onMouseDownResizeWrapper_),T.Bubble.unbindDragEvents_(),T.utils.dom.removeNode(this.bubbleGroup_),this.disposed=!0},T.Bubble.prototype.moveDuringDrag=function(t,e){t?t.translateSurface(e.x,e.y):this.moveTo(e.x,e.y),this.relativeLeft_=this.workspace_.RTL?this.anchorXY_.x-e.x-this.width_:e.x-this.anchorXY_.x,this.relativeTop_=e.y-this.anchorXY_.y,this.renderArrow_()},T.Bubble.prototype.getRelativeToSurfaceXY=function(){return new T.utils.Coordinate(this.workspace_.RTL?-this.relativeLeft_+this.anchorXY_.x-this.width_:this.anchorXY_.x+this.relativeLeft_,this.anchorXY_.y+this.relativeTop_)},T.Bubble.prototype.setAutoLayout=function(t){this.autoLayout_=t},T.Bubble.textToDom=function(t){var e=T.utils.dom.createSvgElement(T.utils.Svg.TEXT,{class:"blocklyText blocklyBubbleText blocklyNoPointerEvents",y:T.Bubble.BORDER_WIDTH},null);t=t.split("\n");for(var o=0;o<t.length;o++){var i=T.utils.dom.createSvgElement(T.utils.Svg.TSPAN,{dy:"1em",x:T.Bubble.BORDER_WIDTH},e),s=document.createTextNode(t[o]);i.appendChild(s)}return e},T.Bubble.createNonEditableBubble=function(t,e,o){if((o=new T.Bubble(e.workspace,t,e.pathObject.svgPath,o,null,null)).setSvgId(e.id),e.RTL){e=t.getBBox().width;for(var i=0,s;s=t.childNodes[i];i++)s.setAttribute("text-anchor","end"),s.setAttribute("x",e+T.Bubble.BORDER_WIDTH)}return o},T.Events.CommentBase=function(t){this.commentId=(this.isBlank=void 0===t)?"":t.id,this.workspaceId=this.isBlank?"":t.workspace.id,this.group=T.Events.getGroup(),this.recordUndo=T.Events.recordUndo},T.utils.object.inherits(T.Events.CommentBase,T.Events.Abstract),T.Events.CommentBase.prototype.toJson=function(){var t=T.Events.CommentBase.superClass_.toJson.call(this);return this.commentId&&(t.commentId=this.commentId),t},T.Events.CommentBase.prototype.fromJson=function(t){T.Events.CommentBase.superClass_.fromJson.call(this,t),this.commentId=t.commentId},T.Events.CommentChange=function(t,e,o){T.Events.CommentChange.superClass_.constructor.call(this,t),t&&(this.oldContents_=void 0===e?"":e,this.newContents_=void 0===o?"":o)},T.utils.object.inherits(T.Events.CommentChange,T.Events.CommentBase),T.Events.CommentChange.prototype.type=T.Events.COMMENT_CHANGE,T.Events.CommentChange.prototype.toJson=function(){var t=T.Events.CommentChange.superClass_.toJson.call(this);return t.oldContents=this.oldContents_,t.newContents=this.newContents_,t},T.Events.CommentChange.prototype.fromJson=function(t){T.Events.CommentChange.superClass_.fromJson.call(this,t),this.oldContents_=t.oldContents,this.newContents_=t.newContents},T.Events.CommentChange.prototype.isNull=function(){return this.oldContents_==this.newContents_},T.Events.CommentChange.prototype.run=function(t){var e=this.getEventWorkspace_().getCommentById(this.commentId);e?e.setContent(t?this.newContents_:this.oldContents_):console.warn("Can't change non-existent comment: "+this.commentId)},T.Events.CommentCreate=function(t){T.Events.CommentCreate.superClass_.constructor.call(this,t),t&&(this.xml=t.toXmlWithXY())},T.utils.object.inherits(T.Events.CommentCreate,T.Events.CommentBase),T.Events.CommentCreate.prototype.type=T.Events.COMMENT_CREATE,T.Events.CommentCreate.prototype.toJson=function(){var t=T.Events.CommentCreate.superClass_.toJson.call(this);return t.xml=T.Xml.domToText(this.xml),t},T.Events.CommentCreate.prototype.fromJson=function(t){T.Events.CommentCreate.superClass_.fromJson.call(this,t),this.xml=T.Xml.textToDom(t.xml)},T.Events.CommentCreate.prototype.run=function(t){T.Events.CommentCreateDeleteHelper(this,t)},T.Events.CommentCreateDeleteHelper=function(t,e){var o=t.getEventWorkspace_();e?((e=T.utils.xml.createElement("xml")).appendChild(t.xml),T.Xml.domToWorkspace(e,o)):(o=o.getCommentById(t.commentId))?o.dispose(!1,!1):console.warn("Can't uncreate non-existent comment: "+t.commentId)},T.Events.CommentDelete=function(t){T.Events.CommentDelete.superClass_.constructor.call(this,t),t&&(this.xml=t.toXmlWithXY())},T.utils.object.inherits(T.Events.CommentDelete,T.Events.CommentBase),T.Events.CommentDelete.prototype.type=T.Events.COMMENT_DELETE,T.Events.CommentDelete.prototype.toJson=function(){return T.Events.CommentDelete.superClass_.toJson.call(this)},T.Events.CommentDelete.prototype.fromJson=function(t){T.Events.CommentDelete.superClass_.fromJson.call(this,t)},T.Events.CommentDelete.prototype.run=function(t){T.Events.CommentCreateDeleteHelper(this,!t)},T.Events.CommentMove=function(t){T.Events.CommentMove.superClass_.constructor.call(this,t),t&&(this.comment_=t,this.oldCoordinate_=t.getXY(),this.newCoordinate_=null)},T.utils.object.inherits(T.Events.CommentMove,T.Events.CommentBase),T.Events.CommentMove.prototype.recordNew=function(){if(!this.comment_)throw Error("Tried to record the new position of a comment on the same event twice.");this.newCoordinate_=this.comment_.getXY(),this.comment_=null},T.Events.CommentMove.prototype.type=T.Events.COMMENT_MOVE,T.Events.CommentMove.prototype.setOldCoordinate=function(t){this.oldCoordinate_=t},T.Events.CommentMove.prototype.toJson=function(){var t=T.Events.CommentMove.superClass_.toJson.call(this);return this.oldCoordinate_&&(t.oldCoordinate=Math.round(this.oldCoordinate_.x)+","+Math.round(this.oldCoordinate_.y)),this.newCoordinate_&&(t.newCoordinate=Math.round(this.newCoordinate_.x)+","+Math.round(this.newCoordinate_.y)),t},T.Events.CommentMove.prototype.fromJson=function(t){var e;T.Events.CommentMove.superClass_.fromJson.call(this,t),t.oldCoordinate&&(e=t.oldCoordinate.split(","),this.oldCoordinate_=new T.utils.Coordinate(Number(e[0]),Number(e[1]))),t.newCoordinate&&(e=t.newCoordinate.split(","),this.newCoordinate_=new T.utils.Coordinate(Number(e[0]),Number(e[1])))},T.Events.CommentMove.prototype.isNull=function(){return T.utils.Coordinate.equals(this.oldCoordinate_,this.newCoordinate_)},T.Events.CommentMove.prototype.run=function(t){var e=this.getEventWorkspace_().getCommentById(this.commentId),o;e?(t=t?this.newCoordinate_:this.oldCoordinate_,o=e.getXY(),e.moveBy(t.x-o.x,t.y-o.y)):console.warn("Can't move non-existent comment: "+this.commentId)},T.registry.register(T.registry.Type.EVENT,T.Events.COMMENT_CREATE,T.Events.CommentCreate),T.registry.register(T.registry.Type.EVENT,T.Events.COMMENT_CHANGE,T.Events.CommentChange),T.registry.register(T.registry.Type.EVENT,T.Events.COMMENT_MOVE,T.Events.CommentMove),T.registry.register(T.registry.Type.EVENT,T.Events.COMMENT_DELETE,T.Events.CommentDelete),T.BubbleDragger=function(t,e){this.draggingBubble_=t,this.workspace_=e,this.deleteArea_=null,this.wouldDeleteBubble_=!1,this.startXY_=this.draggingBubble_.getRelativeToSurfaceXY(),this.dragSurface_=T.utils.is3dSupported()&&e.getBlockDragSurface()?e.getBlockDragSurface():null},T.BubbleDragger.prototype.dispose=function(){this.dragSurface_=this.workspace_=this.draggingBubble_=null},T.BubbleDragger.prototype.startBubbleDrag=function(){T.Events.getGroup()||T.Events.setGroup(!0),this.workspace_.setResizesEnabled(!1),this.draggingBubble_.setAutoLayout(!1),this.dragSurface_&&this.moveToDragSurface_(),this.draggingBubble_.setDragging&&this.draggingBubble_.setDragging(!0);var t=this.workspace_.getToolbox(),e;t&&"function"==typeof t.addStyle&&(e=this.draggingBubble_.isDeletable()?"blocklyToolboxDelete":"blocklyToolboxGrab",t.addStyle(e))},T.BubbleDragger.prototype.dragBubble=function(t,e){e=this.pixelsToWorkspaceUnits_(e),e=T.utils.Coordinate.sum(this.startXY_,e),this.draggingBubble_.moveDuringDrag(this.dragSurface_,e),this.draggingBubble_.isDeletable()&&(this.deleteArea_=this.workspace_.isDeleteArea(t),this.updateCursorDuringBubbleDrag_())},T.BubbleDragger.prototype.maybeDeleteBubble_=function(){var t=this.workspace_.trashcan;return this.wouldDeleteBubble_?(t&&setTimeout(t.closeLid.bind(t),100),this.fireMoveEvent_(),this.draggingBubble_.dispose(!1,!0)):t&&t.closeLid(),this.wouldDeleteBubble_},T.BubbleDragger.prototype.updateCursorDuringBubbleDrag_=function(){this.wouldDeleteBubble_=this.deleteArea_!=T.DELETE_AREA_NONE;var t=this.workspace_.trashcan;this.wouldDeleteBubble_?(this.draggingBubble_.setDeleteStyle(!0),this.deleteArea_==T.DELETE_AREA_TRASH&&t&&t.setLidOpen(!0)):(this.draggingBubble_.setDeleteStyle(!1),t&&t.setLidOpen(!1))},T.BubbleDragger.prototype.endBubbleDrag=function(t,e){this.dragBubble(t,e),t=this.pixelsToWorkspaceUnits_(e),t=T.utils.Coordinate.sum(this.startXY_,t),this.draggingBubble_.moveTo(t.x,t.y),this.maybeDeleteBubble_()||(this.dragSurface_&&this.dragSurface_.clearAndHide(this.workspace_.getBubbleCanvas()),this.draggingBubble_.setDragging&&this.draggingBubble_.setDragging(!1),this.fireMoveEvent_()),this.workspace_.setResizesEnabled(!0),(t=this.workspace_.getToolbox())&&"function"==typeof t.removeStyle&&(e=this.draggingBubble_.isDeletable()?"blocklyToolboxDelete":"blocklyToolboxGrab",t.removeStyle(e)),T.Events.setGroup(!1)},T.BubbleDragger.prototype.fireMoveEvent_=function(){var t;this.draggingBubble_.isComment&&((t=new(T.Events.get(T.Events.COMMENT_MOVE))(this.draggingBubble_)).setOldCoordinate(this.startXY_),t.recordNew(),T.Events.fire(t))},T.BubbleDragger.prototype.pixelsToWorkspaceUnits_=function(t){return t=new T.utils.Coordinate(t.x/this.workspace_.scale,t.y/this.workspace_.scale),this.workspace_.isMutator&&t.scale(1/this.workspace_.options.parentWorkspace.scale),t},T.BubbleDragger.prototype.moveToDragSurface_=function(){this.draggingBubble_.moveTo(0,0),this.dragSurface_.translateSurface(this.startXY_.x,this.startXY_.y),this.dragSurface_.setBlocksAndShow(this.draggingBubble_.getSvgRoot())},T.Events.Click=function(t,e,o){T.Events.Click.superClass_.constructor.call(this,t?t.workspace.id:e),this.blockId=t?t.id:null,this.targetType=o},T.utils.object.inherits(T.Events.Click,T.Events.UiBase),T.Events.Click.prototype.type=T.Events.CLICK,T.Events.Click.prototype.toJson=function(){var t=T.Events.Click.superClass_.toJson.call(this);return t.targetType=this.targetType,this.blockId&&(t.blockId=this.blockId),t},T.Events.Click.prototype.fromJson=function(t){T.Events.Click.superClass_.fromJson.call(this,t),this.targetType=t.targetType,this.blockId=t.blockId},T.registry.register(T.registry.Type.EVENT,T.Events.CLICK,T.Events.Click),T.WorkspaceDragger=function(t){this.workspace_=t,this.horizontalScrollEnabled_=this.workspace_.isMovableHorizontally(),this.verticalScrollEnabled_=this.workspace_.isMovableVertically(),this.startScrollXY_=new T.utils.Coordinate(t.scrollX,t.scrollY)},T.WorkspaceDragger.prototype.dispose=function(){this.workspace_=null},T.WorkspaceDragger.prototype.startDrag=function(){T.selected&&T.selected.unselect(),this.workspace_.setupDragSurface()},T.WorkspaceDragger.prototype.endDrag=function(t){this.drag(t),this.workspace_.resetDragSurface()},T.WorkspaceDragger.prototype.drag=function(t){if(t=T.utils.Coordinate.sum(this.startScrollXY_,t),this.horizontalScrollEnabled_&&this.verticalScrollEnabled_)this.workspace_.scroll(t.x,t.y);else if(this.horizontalScrollEnabled_)this.workspace_.scroll(t.x,this.workspace_.scrollY);else{if(!this.verticalScrollEnabled_)throw new TypeError("Invalid state.");this.workspace_.scroll(this.workspace_.scrollX,t.y)}},T.Gesture=function(t,e){this.mouseDownXY_=null,this.currentDragDeltaXY_=new T.utils.Coordinate(0,0),this.startWorkspace_=this.targetBlock_=this.startBlock_=this.startField_=this.startBubble_=null,this.creatorWorkspace_=e,this.isDraggingBubble_=this.isDraggingBlock_=this.isDraggingWorkspace_=this.hasExceededDragRadius_=!1,this.mostRecentEvent_=t,this.flyout_=this.workspaceDragger_=this.blockDragger_=this.bubbleDragger_=this.onUpWrapper_=this.onMoveWrapper_=null,this.isEnding_=this.hasStarted_=this.calledUpdateIsDragging_=!1,this.healStack_=!T.DRAG_STACK},T.Gesture.prototype.dispose=function(){T.Touch.clearTouchIdentifier(),T.Tooltip.unblock(),this.creatorWorkspace_.clearGesture(),this.onMoveWrapper_&&T.browserEvents.unbind(this.onMoveWrapper_),this.onUpWrapper_&&T.browserEvents.unbind(this.onUpWrapper_),this.blockDragger_&&this.blockDragger_.dispose(),this.workspaceDragger_&&this.workspaceDragger_.dispose(),this.bubbleDragger_&&this.bubbleDragger_.dispose()},T.Gesture.prototype.updateFromEvent_=function(t){var e=new T.utils.Coordinate(t.clientX,t.clientY);this.updateDragDelta_(e)&&(this.updateIsDragging_(),T.longStop_()),this.mostRecentEvent_=t},T.Gesture.prototype.updateDragDelta_=function(t){return this.currentDragDeltaXY_=T.utils.Coordinate.difference(t,this.mouseDownXY_),!this.hasExceededDragRadius_&&(this.hasExceededDragRadius_=T.utils.Coordinate.magnitude(this.currentDragDeltaXY_)>(this.flyout_?T.FLYOUT_DRAG_RADIUS:T.DRAG_RADIUS))},T.Gesture.prototype.updateIsDraggingFromFlyout_=function(){return!(!this.targetBlock_||!this.flyout_.isBlockCreatable_(this.targetBlock_)||this.flyout_.isScrollable()&&!this.flyout_.isDragTowardWorkspace(this.currentDragDeltaXY_)||(this.startWorkspace_=this.flyout_.targetWorkspace,this.startWorkspace_.updateScreenCalculationsIfScrolled(),T.Events.getGroup()||T.Events.setGroup(!0),this.startBlock_=null,this.targetBlock_=this.flyout_.createBlock(this.targetBlock_),this.targetBlock_.select(),0))},T.Gesture.prototype.updateIsDraggingBubble_=function(){if(!this.startBubble_)return!1;return this.isDraggingBubble_=!0,this.startDraggingBubble_(),!0},T.Gesture.prototype.updateIsDraggingBlock_=function(){if(!this.targetBlock_)return!1;return this.flyout_?this.isDraggingBlock_=this.updateIsDraggingFromFlyout_():this.targetBlock_.isMovable()&&(this.isDraggingBlock_=!0),!!this.isDraggingBlock_&&(this.startDraggingBlock_(),!0)},T.Gesture.prototype.updateIsDraggingWorkspace_=function(){(this.flyout_?this.flyout_.isScrollable():this.startWorkspace_&&this.startWorkspace_.isDraggable())&&(this.workspaceDragger_=new T.WorkspaceDragger(this.startWorkspace_),this.isDraggingWorkspace_=!0,this.workspaceDragger_.startDrag())},T.Gesture.prototype.updateIsDragging_=function(){if(this.calledUpdateIsDragging_)throw Error("updateIsDragging_ should only be called once per gesture.");this.calledUpdateIsDragging_=!0,this.updateIsDraggingBubble_()||this.updateIsDraggingBlock_()||this.updateIsDraggingWorkspace_()},T.Gesture.prototype.startDraggingBlock_=function(){this.blockDragger_=new T.BlockDragger(this.targetBlock_,this.startWorkspace_),this.blockDragger_.startBlockDrag(this.currentDragDeltaXY_,this.healStack_),this.blockDragger_.dragBlock(this.mostRecentEvent_,this.currentDragDeltaXY_)},T.Gesture.prototype.startDraggingBubble_=function(){this.bubbleDragger_=new T.BubbleDragger(this.startBubble_,this.startWorkspace_),this.bubbleDragger_.startBubbleDrag(),this.bubbleDragger_.dragBubble(this.mostRecentEvent_,this.currentDragDeltaXY_)},T.Gesture.prototype.doStart=function(t){T.utils.isTargetInput(t)?this.cancel():(this.hasStarted_=!0,T.blockAnimations.disconnectUiStop(),this.startWorkspace_.updateScreenCalculationsIfScrolled(),this.startWorkspace_.isMutator&&this.startWorkspace_.resize(),T.hideChaff(!!this.flyout_),this.startWorkspace_.markFocused(),this.mostRecentEvent_=t,T.Tooltip.block(),this.targetBlock_&&this.targetBlock_.select(),T.utils.isRightButton(t)?this.handleRightClick(t):("touchstart"!=t.type.toLowerCase()&&"pointerdown"!=t.type.toLowerCase()||"mouse"==t.pointerType||T.longStart(t,this),this.mouseDownXY_=new T.utils.Coordinate(t.clientX,t.clientY),this.healStack_=t.altKey||t.ctrlKey||t.metaKey,this.bindMouseEvents(t)))},T.Gesture.prototype.bindMouseEvents=function(t){this.onMoveWrapper_=T.browserEvents.conditionalBind(document,"mousemove",null,this.handleMove.bind(this)),this.onUpWrapper_=T.browserEvents.conditionalBind(document,"mouseup",null,this.handleUp.bind(this)),t.preventDefault(),t.stopPropagation()},T.Gesture.prototype.handleMove=function(t){this.updateFromEvent_(t),this.isDraggingWorkspace_?this.workspaceDragger_.drag(this.currentDragDeltaXY_):this.isDraggingBlock_?this.blockDragger_.dragBlock(this.mostRecentEvent_,this.currentDragDeltaXY_):this.isDraggingBubble_&&this.bubbleDragger_.dragBubble(this.mostRecentEvent_,this.currentDragDeltaXY_),t.preventDefault(),t.stopPropagation()},T.Gesture.prototype.handleUp=function(t){this.updateFromEvent_(t),T.longStop_(),this.isEnding_?console.log("Trying to end a gesture recursively."):(this.isEnding_=!0,this.isDraggingBubble_?this.bubbleDragger_.endBubbleDrag(t,this.currentDragDeltaXY_):this.isDraggingBlock_?this.blockDragger_.endBlockDrag(t,this.currentDragDeltaXY_):this.isDraggingWorkspace_?this.workspaceDragger_.endDrag(this.currentDragDeltaXY_):this.isBubbleClick_()?this.doBubbleClick_():this.isFieldClick_()?this.doFieldClick_():this.isBlockClick_()?this.doBlockClick_():this.isWorkspaceClick_()&&this.doWorkspaceClick_(t),t.preventDefault(),t.stopPropagation(),this.dispose())},T.Gesture.prototype.cancel=function(){this.isEnding_||(T.longStop_(),this.isDraggingBubble_?this.bubbleDragger_.endBubbleDrag(this.mostRecentEvent_,this.currentDragDeltaXY_):this.isDraggingBlock_?this.blockDragger_.endBlockDrag(this.mostRecentEvent_,this.currentDragDeltaXY_):this.isDraggingWorkspace_&&this.workspaceDragger_.endDrag(this.currentDragDeltaXY_),this.dispose())},T.Gesture.prototype.handleRightClick=function(t){this.targetBlock_?(this.bringBlockToFront_(),T.hideChaff(!!this.flyout_),this.targetBlock_.showContextMenu(t)):this.startBubble_?this.startBubble_.showContextMenu(t):this.startWorkspace_&&!this.flyout_&&(T.hideChaff(),this.startWorkspace_.showContextMenu(t)),t.preventDefault(),t.stopPropagation(),this.dispose()},T.Gesture.prototype.handleWsStart=function(t,e){if(this.hasStarted_)throw Error("Tried to call gesture.handleWsStart, but the gesture had already been started.");this.setStartWorkspace_(e),this.mostRecentEvent_=t,this.doStart(t)},T.Gesture.prototype.fireWorkspaceClick_=function(t){T.Events.fire(new(T.Events.get(T.Events.CLICK))(null,t.id,"workspace"))},T.Gesture.prototype.handleFlyoutStart=function(t,e){if(this.hasStarted_)throw Error("Tried to call gesture.handleFlyoutStart, but the gesture had already been started.");this.setStartFlyout_(e),this.handleWsStart(t,e.getWorkspace())},T.Gesture.prototype.handleBlockStart=function(t,e){if(this.hasStarted_)throw Error("Tried to call gesture.handleBlockStart, but the gesture had already been started.");this.setStartBlock(e),this.mostRecentEvent_=t},T.Gesture.prototype.handleBubbleStart=function(t,e){if(this.hasStarted_)throw Error("Tried to call gesture.handleBubbleStart, but the gesture had already been started.");this.setStartBubble(e),this.mostRecentEvent_=t},T.Gesture.prototype.doBubbleClick_=function(){this.startBubble_.setFocus&&this.startBubble_.setFocus(),this.startBubble_.select&&this.startBubble_.select()},T.Gesture.prototype.doFieldClick_=function(){this.startField_.showEditor(this.mostRecentEvent_),this.bringBlockToFront_()},T.Gesture.prototype.doBlockClick_=function(){var t;this.flyout_&&this.flyout_.autoClose?this.targetBlock_.isEnabled()&&(T.Events.getGroup()||T.Events.setGroup(!0),this.flyout_.createBlock(this.targetBlock_).scheduleSnapAndBump()):(t=new(T.Events.get(T.Events.CLICK))(this.startBlock_,this.startWorkspace_.id,"block"),T.Events.fire(t)),this.bringBlockToFront_(),T.Events.setGroup(!1)},T.Gesture.prototype.doWorkspaceClick_=function(t){t=this.creatorWorkspace_,T.selected&&T.selected.unselect(),this.fireWorkspaceClick_(this.startWorkspace_||t)},T.Gesture.prototype.bringBlockToFront_=function(){this.targetBlock_&&!this.flyout_&&this.targetBlock_.bringToFront()},T.Gesture.prototype.setStartField=function(t){if(this.hasStarted_)throw Error("Tried to call gesture.setStartField, but the gesture had already been started.");this.startField_||(this.startField_=t)},T.Gesture.prototype.setStartBubble=function(t){this.startBubble_||(this.startBubble_=t)},T.Gesture.prototype.setStartBlock=function(t){this.startBlock_||this.startBubble_||((this.startBlock_=t).isInFlyout&&t!=t.getRootBlock()?this.setTargetBlock_(t.getRootBlock()):this.setTargetBlock_(t))},T.Gesture.prototype.setTargetBlock_=function(t){t.isShadow()?this.setTargetBlock_(t.getParent()):this.targetBlock_=t},T.Gesture.prototype.setStartWorkspace_=function(t){this.startWorkspace_||(this.startWorkspace_=t)},T.Gesture.prototype.setStartFlyout_=function(t){this.flyout_||(this.flyout_=t)},T.Gesture.prototype.isBubbleClick_=function(){return!!this.startBubble_&&!this.hasExceededDragRadius_},T.Gesture.prototype.isBlockClick_=function(){return!!this.startBlock_&&!this.hasExceededDragRadius_&&!this.isFieldClick_()},T.Gesture.prototype.isFieldClick_=function(){return!!this.startField_&&this.startField_.isClickable()&&!this.hasExceededDragRadius_&&(!this.flyout_||!this.flyout_.autoClose)},T.Gesture.prototype.isWorkspaceClick_=function(){return!(this.startBlock_||this.startBubble_||this.startField_||this.hasExceededDragRadius_)},T.Gesture.prototype.isDragging=function(){return this.isDraggingWorkspace_||this.isDraggingBlock_||this.isDraggingBubble_},T.Gesture.prototype.hasStarted=function(){return this.hasStarted_},T.Gesture.prototype.getInsertionMarkers=function(){return this.blockDragger_?this.blockDragger_.getInsertionMarkers():[]},T.Gesture.inProgress=function(){for(var t=T.Workspace.getAll(),e=0,o;o=t[e];e++)if(o.currentGesture_)return!0;return!1},T.Field=function(t,e,o){this.value_=this.DEFAULT_VALUE,this.tooltip_=this.validator_=null,this.size_=new T.utils.Size(0,0),this.constants_=this.mouseDownWrapper_=this.textContent_=this.textElement_=this.borderRect_=this.fieldGroup_=this.markerSvg_=this.cursorSvg_=null,o&&this.configure_(o),this.setValue(t),e&&this.setValidator(e)},T.Field.prototype.DEFAULT_VALUE=null,T.Field.prototype.name=void 0,T.Field.prototype.disposed=!1,T.Field.prototype.maxDisplayLength=50,T.Field.prototype.sourceBlock_=null,T.Field.prototype.isDirty_=!0,T.Field.prototype.visible_=!0,T.Field.prototype.clickTarget_=null,T.Field.NBSP=" ",T.Field.prototype.EDITABLE=!0,T.Field.prototype.SERIALIZABLE=!1,T.Field.prototype.configure_=function(t){var e=t.tooltip;(e="string"==typeof e?T.utils.replaceMessageReferences(t.tooltip):e)&&this.setTooltip(e)},T.Field.prototype.setSourceBlock=function(t){if(this.sourceBlock_)throw Error("Field already bound to a block.");this.sourceBlock_=t},T.Field.prototype.getConstants=function(){return!this.constants_&&this.sourceBlock_&&this.sourceBlock_.workspace&&this.sourceBlock_.workspace.rendered&&(this.constants_=this.sourceBlock_.workspace.getRenderer().getConstants()),this.constants_},T.Field.prototype.getSourceBlock=function(){return this.sourceBlock_},T.Field.prototype.init=function(){this.fieldGroup_||(this.fieldGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{},null),this.isVisible()||(this.fieldGroup_.style.display="none"),this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_),this.initView(),this.updateEditable(),this.setTooltip(this.tooltip_),this.bindEvents_(),this.initModel())},T.Field.prototype.initView=function(){this.createBorderRect_(),this.createTextElement_()},T.Field.prototype.initModel=function(){},T.Field.prototype.createBorderRect_=function(){this.borderRect_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{rx:this.getConstants().FIELD_BORDER_RECT_RADIUS,ry:this.getConstants().FIELD_BORDER_RECT_RADIUS,x:0,y:0,height:this.size_.height,width:this.size_.width,class:"blocklyFieldRect"},this.fieldGroup_)},T.Field.prototype.createTextElement_=function(){this.textElement_=T.utils.dom.createSvgElement(T.utils.Svg.TEXT,{class:"blocklyText"},this.fieldGroup_),this.getConstants().FIELD_TEXT_BASELINE_CENTER&&this.textElement_.setAttribute("dominant-baseline","central"),this.textContent_=document.createTextNode(""),this.textElement_.appendChild(this.textContent_)},T.Field.prototype.bindEvents_=function(){T.Tooltip.bindMouseEvents(this.getClickTarget_()),this.mouseDownWrapper_=T.browserEvents.conditionalBind(this.getClickTarget_(),"mousedown",this,this.onMouseDown_)},T.Field.prototype.fromXml=function(t){this.setValue(t.textContent)},T.Field.prototype.toXml=function(t){return t.textContent=this.getValue(),t},T.Field.prototype.dispose=function(){T.DropDownDiv.hideIfOwner(this),T.WidgetDiv.hideIfOwner(this),T.Tooltip.unbindMouseEvents(this.getClickTarget_()),this.mouseDownWrapper_&&T.browserEvents.unbind(this.mouseDownWrapper_),T.utils.dom.removeNode(this.fieldGroup_),this.disposed=!0},T.Field.prototype.updateEditable=function(){var t=this.fieldGroup_;this.EDITABLE&&t&&(this.sourceBlock_.isEditable()?(T.utils.dom.addClass(t,"blocklyEditableText"),T.utils.dom.removeClass(t,"blocklyNonEditableText"),t.style.cursor=this.CURSOR):(T.utils.dom.addClass(t,"blocklyNonEditableText"),T.utils.dom.removeClass(t,"blocklyEditableText"),t.style.cursor=""))},T.Field.prototype.isClickable=function(){return!!this.sourceBlock_&&this.sourceBlock_.isEditable()&&!!this.showEditor_&&"function"==typeof this.showEditor_},T.Field.prototype.isCurrentlyEditable=function(){return this.EDITABLE&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()},T.Field.prototype.isSerializable=function(){var t=!1;return this.name&&(this.SERIALIZABLE?t=!0:this.EDITABLE&&(console.warn("Detected an editable field that was not serializable. Please define SERIALIZABLE property as true on all editable custom fields. Proceeding with serialization."),t=!0)),t},T.Field.prototype.isVisible=function(){return this.visible_},T.Field.prototype.setVisible=function(t){var e;this.visible_!=t&&(this.visible_=t,e=this.getSvgRoot())&&(e.style.display=t?"block":"none")},T.Field.prototype.setValidator=function(t){this.validator_=t},T.Field.prototype.getValidator=function(){return this.validator_},T.Field.prototype.getSvgRoot=function(){return this.fieldGroup_},T.Field.prototype.applyColour=function(){},T.Field.prototype.render_=function(){this.textContent_&&(this.textContent_.nodeValue=this.getDisplayText_()),this.updateSize_()},T.Field.prototype.showEditor=function(t){this.isClickable()&&this.showEditor_(t)},T.Field.prototype.updateSize_=function(t){var e=this.getConstants(),o=2*(t=null!=t?t:this.borderRect_?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0),i=e.FIELD_TEXT_HEIGHT,s=0;this.textElement_&&(o+=s=T.utils.dom.getFastTextWidth(this.textElement_,e.FIELD_TEXT_FONTSIZE,e.FIELD_TEXT_FONTWEIGHT,e.FIELD_TEXT_FONTFAMILY)),this.borderRect_&&(i=Math.max(i,e.FIELD_BORDER_RECT_HEIGHT)),this.size_.height=i,this.size_.width=o,this.positionTextElement_(t,s),this.positionBorderRect_()},T.Field.prototype.positionTextElement_=function(t,e){var o,i;this.textElement_&&(o=this.getConstants(),i=this.size_.height/2,this.textElement_.setAttribute("x",this.sourceBlock_.RTL?this.size_.width-e-t:t),this.textElement_.setAttribute("y",o.FIELD_TEXT_BASELINE_CENTER?i:i-o.FIELD_TEXT_HEIGHT/2+o.FIELD_TEXT_BASELINE))},T.Field.prototype.positionBorderRect_=function(){this.borderRect_&&(this.borderRect_.setAttribute("width",this.size_.width),this.borderRect_.setAttribute("height",this.size_.height),this.borderRect_.setAttribute("rx",this.getConstants().FIELD_BORDER_RECT_RADIUS),this.borderRect_.setAttribute("ry",this.getConstants().FIELD_BORDER_RECT_RADIUS))},T.Field.prototype.getSize=function(){if(!this.isVisible())return new T.utils.Size(0,0);return this.isDirty_?(this.render_(),this.isDirty_=!1):this.visible_&&0==this.size_.width&&(console.warn("Deprecated use of setting size_.width to 0 to rerender a field. Set field.isDirty_ to true instead."),this.render_()),this.size_},T.Field.prototype.getScaledBBox=function(){var t,e,o,i,t;return this.borderRect_?(t=this.borderRect_.getBoundingClientRect(),o=T.utils.style.getPageOffset(this.borderRect_),i=t.width,t=t.height):(t=this.sourceBlock_.getHeightWidth(),e=this.sourceBlock_.workspace.scale,o=this.getAbsoluteXY_(),i=t.width*e,t=t.height*e,T.utils.userAgent.GECKO?(o.x+=1.5*e,o.y+=1.5*e):T.utils.userAgent.EDGE||T.utils.userAgent.IE||(o.x-=.5*e,o.y-=.5*e),i+=1*e,t+=1*e),new T.utils.Rect(o.y,o.y+t,o.x,o.x+i)},T.Field.prototype.getDisplayText_=function(){var t=this.getText();if(!t)return T.Field.NBSP;return t=(t=t.length>this.maxDisplayLength?t.substring(0,this.maxDisplayLength-2)+"…":t).replace(/\s/g,T.Field.NBSP),this.sourceBlock_&&this.sourceBlock_.RTL&&(t+="‏"),t},T.Field.prototype.getText=function(){if(this.getText_){var t=this.getText_.call(this);if(null!==t)return String(t)}return String(this.getValue())},T.Field.prototype.markDirty=function(){this.isDirty_=!0,this.constants_=null},T.Field.prototype.forceRerender=function(){this.isDirty_=!0,this.sourceBlock_&&this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours(),this.updateMarkers_())},T.Field.prototype.setValue=function(t){if(null!==t){var e=this.doClassValidation_(t),o,e;if(!((t=this.processValidation_(t,e))instanceof Error)){if((e=this.getValidator())&&(e=e.call(this,t),(t=this.processValidation_(t,e))instanceof Error))return;(e=this.sourceBlock_)&&e.disposed||((o=this.getValue())===t?this.doValueUpdate_(t):(e&&T.Events.isEnabled()&&T.Events.fire(new(T.Events.get(T.Events.BLOCK_CHANGE))(e,"field",this.name||null,o,t)),this.doValueUpdate_(t),this.isDirty_&&this.forceRerender()))}}},T.Field.prototype.processValidation_=function(t,e){if(null===e)return this.doValueInvalid_(t),this.isDirty_&&this.forceRerender(),Error();return t=void 0!==e?e:t},T.Field.prototype.getValue=function(){return this.value_},T.Field.prototype.doClassValidation_=function(t){return null==t?null:t},T.Field.prototype.doValueUpdate_=function(t){this.value_=t,this.isDirty_=!0},T.Field.prototype.doValueInvalid_=function(t){},T.Field.prototype.onMouseDown_=function(t){this.sourceBlock_&&this.sourceBlock_.workspace&&(t=this.sourceBlock_.workspace.getGesture(t))&&t.setStartField(this)},T.Field.prototype.setTooltip=function(t){t||""===t||(t=this.sourceBlock_);var e=this.getClickTarget_();e?e.tooltip=t:this.tooltip_=t},T.Field.prototype.getTooltip=function(){var t=this.getClickTarget_();return t?T.Tooltip.getTooltipOfObject(t):T.Tooltip.getTooltipOfObject({tooltip:this.tooltip_})},T.Field.prototype.getClickTarget_=function(){return this.clickTarget_||this.getSvgRoot()},T.Field.prototype.getAbsoluteXY_=function(){return T.utils.style.getPageOffset(this.getClickTarget_())},T.Field.prototype.referencesVariables=function(){return!1},T.Field.prototype.getParentInput=function(){for(var t=null,e=this.sourceBlock_,o=e.inputList,i=0;i<e.inputList.length;i++)for(var s=o[i],n=s.fieldRow,r=0;r<n.length;r++)if(n[r]===this){t=s;break}return t},T.Field.prototype.getFlipRtl=function(){return!1},T.Field.prototype.isTabNavigable=function(){return!1},T.Field.prototype.onShortcut=function(t){return!1},T.Field.prototype.setCursorSvg=function(t){t?(this.fieldGroup_.appendChild(t),this.cursorSvg_=t):this.cursorSvg_=null},T.Field.prototype.setMarkerSvg=function(t){t?(this.fieldGroup_.appendChild(t),this.markerSvg_=t):this.markerSvg_=null},T.Field.prototype.updateMarkers_=function(){var t=this.sourceBlock_.workspace;t.keyboardAccessibilityMode&&this.cursorSvg_&&t.getCursor().draw(),t.keyboardAccessibilityMode&&this.markerSvg_&&t.getMarker(T.MarkerManager.LOCAL_MARKER).draw()},T.FieldLabel=function(t,e,o){this.class_=null,T.FieldLabel.superClass_.constructor.call(this,t,null,o),o||(this.class_=e||null)},T.utils.object.inherits(T.FieldLabel,T.Field),T.FieldLabel.prototype.DEFAULT_VALUE="",T.FieldLabel.fromJson=function(t){var e=T.utils.replaceMessageReferences(t.text);return new T.FieldLabel(e,void 0,t)},T.FieldLabel.prototype.EDITABLE=!1,T.FieldLabel.prototype.configure_=function(t){T.FieldLabel.superClass_.configure_.call(this,t),this.class_=t["class"]},T.FieldLabel.prototype.initView=function(){this.createTextElement_(),this.class_&&T.utils.dom.addClass(this.textElement_,this.class_)},T.FieldLabel.prototype.doClassValidation_=function(t){return null==t?null:String(t)},T.FieldLabel.prototype.setClass=function(t){this.textElement_&&(this.class_&&T.utils.dom.removeClass(this.textElement_,this.class_),t)&&T.utils.dom.addClass(this.textElement_,t),this.class_=t},T.fieldRegistry.register("field_label",T.FieldLabel),T.Input=function(t,e,o,i){if(t!=T.inputTypes.DUMMY&&!e)throw Error("Value inputs and statement inputs must have non-empty name.");this.type=t,this.name=e,this.sourceBlock_=o,this.connection=i,this.fieldRow=[]},T.Input.prototype.align=T.constants.ALIGN.LEFT,T.Input.prototype.visible_=!0,T.Input.prototype.getSourceBlock=function(){return this.sourceBlock_},T.Input.prototype.appendField=function(t,e){return this.insertFieldAt(this.fieldRow.length,t,e),this},T.Input.prototype.insertFieldAt=function(t,e,o){if(t<0||t>this.fieldRow.length)throw Error("index "+t+" out of bounds.");if(!(e||""==e&&o))return t;return(e="string"==typeof e?T.fieldRegistry.fromJson({type:"field_label",text:e}):e).setSourceBlock(this.sourceBlock_),this.sourceBlock_.rendered&&(e.init(),e.applyColour()),e.name=o,e.setVisible(this.isVisible()),e.prefixField&&(t=this.insertFieldAt(t,e.prefixField)),this.fieldRow.splice(t,0,e),++t,e.suffixField&&(t=this.insertFieldAt(t,e.suffixField)),this.sourceBlock_.rendered&&(this.sourceBlock_=this.sourceBlock_,this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours()),t},T.Input.prototype.removeField=function(t,e){for(var o=0,i;i=this.fieldRow[o];o++)if(i.name===t)return i.dispose(),this.fieldRow.splice(o,1),this.sourceBlock_.rendered&&(this.sourceBlock_=this.sourceBlock_,this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours()),!0;if(e)return!1;throw Error('Field "'+t+'" not found.')},T.Input.prototype.isVisible=function(){return this.visible_},T.Input.prototype.setVisible=function(t){var e=[];if(this.visible_==t)return e;this.visible_=t;for(var o=0,i;i=this.fieldRow[o];o++)i.setVisible(t);return this.connection&&(this.connection=this.connection,t?e=this.connection.startTrackingAll():this.connection.stopTrackingAll(),o=this.connection.targetBlock())&&(o.getSvgRoot().style.display=t?"block":"none"),e},T.Input.prototype.markDirty=function(){for(var t=0,e;e=this.fieldRow[t];t++)e.markDirty()},T.Input.prototype.setCheck=function(t){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.setCheck(t),this},T.Input.prototype.setAlign=function(t){return this.align=t,this.sourceBlock_.rendered&&(this.sourceBlock_=this.sourceBlock_,this.sourceBlock_.render()),this},T.Input.prototype.setShadowDom=function(t){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.setShadowDom(t),this},T.Input.prototype.getShadowDom=function(){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.getShadowDom()},T.Input.prototype.init=function(){if(this.sourceBlock_.workspace.rendered)for(var t=0;t<this.fieldRow.length;t++)this.fieldRow[t].init()},T.Input.prototype.dispose=function(){for(var t=0,e;e=this.fieldRow[t];t++)e.dispose();this.connection&&this.connection.dispose(),this.sourceBlock_=null},T.Block=function(t,e,o){if(T.Generator&&void 0!==T.Generator.prototype[e])throw Error('Block prototypeName "'+e+'" conflicts with Blockly.Generator members.');if(this.id=o&&!t.getBlockById(o)?o:T.utils.genUid(),t.setBlockById(this.id,this),this.previousConnection=this.nextConnection=this.outputConnection=null,this.inputList=[],this.inputsInline=void 0,this.disabled=!1,this.tooltip="",this.contextMenu=!0,this.parentBlock_=null,this.childBlocks_=[],this.editable_=this.movable_=this.deletable_=!0,this.collapsed_=this.isShadow_=!1,this.comment=this.outputShape_=null,this.commentModel={text:null,pinned:!1,size:new T.utils.Size(160,80)},this.xy_=new T.utils.Coordinate(0,0),this.workspace=t,this.isInFlyout=t.isFlyout,this.isInMutator=t.isMutator,this.RTL=t.RTL,this.isInsertionMarker_=!1,this.hat=void 0,this.rendered=null,this.statementInputCount=0,e){if(this.type=e,!(o=T.Blocks[e])||"object"!=typeof o)throw TypeError("Unknown block type: "+e);T.utils.object.mixin(this,o)}t.addTopBlock(this),t.addTypedBlock(this),(t=T.Events.getGroup())||T.Events.setGroup(!0),e=T.Events.recordUndo;try{"function"==typeof this.init&&(T.Events.recordUndo=!1,this.init(),T.Events.recordUndo=e),T.Events.isEnabled()&&T.Events.fire(new(T.Events.get(T.Events.BLOCK_CREATE))(this))}finally{t||T.Events.setGroup(!1),T.Events.recordUndo=e}this.inputsInlineDefault=this.inputsInline,"function"==typeof this.onchange&&this.setOnChange(this.onchange)},T.Block.COLLAPSED_INPUT_NAME=T.constants.COLLAPSED_INPUT_NAME,T.Block.COLLAPSED_FIELD_NAME=T.constants.COLLAPSED_FIELD_NAME,T.Block.prototype.data=null,T.Block.prototype.disposed=!1,T.Block.prototype.hue_=null,T.Block.prototype.colour_="#000000",T.Block.prototype.styleName_=null,T.Block.prototype.dispose=function(t){if(this.workspace){this.onchangeWrapper_&&this.workspace.removeChangeListener(this.onchangeWrapper_),this.unplug(t),T.Events.isEnabled()&&T.Events.fire(new(T.Events.get(T.Events.BLOCK_DELETE))(this)),T.Events.disable();try{this.workspace&&(this.workspace.removeTopBlock(this),this.workspace.removeTypedBlock(this),this.workspace.removeBlockById(this.id),this.workspace=null),T.selected==this&&(T.selected=null);for(var e=this.childBlocks_.length-1,o;0<=e;e--)this.childBlocks_[e].dispose(!1);for(e=0;o=this.inputList[e];e++)o.dispose();this.inputList.length=0;for(var i=this.getConnections_(!0),e=0,s;s=i[e];e++)s.dispose()}finally{T.Events.enable(),this.disposed=!0}}},T.Block.prototype.initModel=function(){for(var t=0,e;e=this.inputList[t];t++)for(var o=0,i;i=e.fieldRow[o];o++)i.initModel&&i.initModel()},T.Block.prototype.unplug=function(t){this.outputConnection?this.unplugFromRow_(t):this.previousConnection&&this.unplugFromStack_(t)},T.Block.prototype.unplugFromRow_=function(t){var e=null;this.outputConnection.isConnected()&&(e=this.outputConnection.targetConnection,this.outputConnection.disconnect()),e&&(t=t&&this.getOnlyValueConnection_())&&t.isConnected()&&!t.targetBlock().isShadow()&&((t=t.targetConnection).disconnect(),this.workspace.connectionChecker.canConnect(t,e,!1)?e.connect(t):t.onFailedConnect(e))},T.Block.prototype.getOnlyValueConnection_=function(){for(var t=null,e=0;e<this.inputList.length;e++){var o=this.inputList[e].connection;if(o&&o.type==T.connectionTypes.INPUT_VALUE&&o.targetConnection){if(t)return null;t=o}}return t},T.Block.prototype.unplugFromStack_=function(t){var e=null,o=(this.previousConnection.isConnected()&&(e=this.previousConnection.targetConnection,this.previousConnection.disconnect()),this.getNextBlock());t&&o&&!o.isShadow()&&((t=this.nextConnection.targetConnection).disconnect(),e)&&this.workspace.connectionChecker.canConnect(e,t,!1)&&e.connect(t)},T.Block.prototype.getConnections_=function(t){t=[],this.outputConnection&&t.push(this.outputConnection),this.previousConnection&&t.push(this.previousConnection),this.nextConnection&&t.push(this.nextConnection);for(var e=0,o;o=this.inputList[e];e++)o.connection&&t.push(o.connection);return t},T.Block.prototype.lastConnectionInStack=function(){for(var t=this.nextConnection;t;){var e=t.targetBlock();if(!e)return t;t=e.nextConnection}return null},T.Block.prototype.bumpNeighbours=function(){},T.Block.prototype.getParent=function(){return this.parentBlock_},T.Block.prototype.getInputWithBlock=function(t){for(var e=0,o;o=this.inputList[e];e++)if(o.connection&&o.connection.targetBlock()==t)return o;return null},T.Block.prototype.getSurroundParent=function(){var t=this;do{var e=t,t;if(!(t=t.getParent()))return null}while(t.getNextBlock()==e);return t},T.Block.prototype.getNextBlock=function(){return this.nextConnection&&this.nextConnection.targetBlock()},T.Block.prototype.getPreviousBlock=function(){return this.previousConnection&&this.previousConnection.targetBlock()},T.Block.prototype.getFirstStatementConnection=function(){for(var t=0,e;e=this.inputList[t];t++)if(e.connection&&e.connection.type==T.connectionTypes.NEXT_STATEMENT)return e.connection;return null},T.Block.prototype.getRootBlock=function(){var t=this;do{var e=t,t=e.parentBlock_}while(t);return e},T.Block.prototype.getTopStackBlock=function(){var t=this;do{var e=t.getPreviousBlock()}while(e&&e.getNextBlock()==t&&(t=e));return t},T.Block.prototype.getChildren=function(t){if(!t)return this.childBlocks_;t=[];for(var e=0,o;o=this.inputList[e];e++)o.connection&&(o=o.connection.targetBlock())&&t.push(o);return(e=this.getNextBlock())&&t.push(e),t},T.Block.prototype.setParent=function(t){if(t!=this.parentBlock_){if(this.parentBlock_){if(T.utils.arrayRemove(this.parentBlock_.childBlocks_,this),this.previousConnection&&this.previousConnection.isConnected())throw Error("Still connected to previous block.");if(this.outputConnection&&this.outputConnection.isConnected())throw Error("Still connected to parent block.");this.parentBlock_=null}else this.workspace.removeTopBlock(this);(this.parentBlock_=t)?t.childBlocks_.push(this):this.workspace.addTopBlock(this)}},T.Block.prototype.getDescendants=function(t){for(var e=[this],o=this.getChildren(t),i,s=0;i=o[s];s++)e.push.apply(e,i.getDescendants(t));return e},T.Block.prototype.isDeletable=function(){return this.deletable_&&!this.isShadow_&&!(this.workspace&&this.workspace.options.readOnly)},T.Block.prototype.setDeletable=function(t){this.deletable_=t},T.Block.prototype.isMovable=function(){return this.movable_&&!this.isShadow_&&!(this.workspace&&this.workspace.options.readOnly)},T.Block.prototype.setMovable=function(t){this.movable_=t},T.Block.prototype.isDuplicatable=function(){return!this.workspace.hasBlockLimits()||this.workspace.isCapacityAvailable(T.utils.getBlockTypeCounts(this,!0))},T.Block.prototype.isShadow=function(){return this.isShadow_},T.Block.prototype.setShadow=function(t){this.isShadow_=t},T.Block.prototype.isInsertionMarker=function(){return this.isInsertionMarker_},T.Block.prototype.setInsertionMarker=function(t){this.isInsertionMarker_=t},T.Block.prototype.isEditable=function(){return this.editable_&&!(this.workspace&&this.workspace.options.readOnly)},T.Block.prototype.setEditable=function(t){this.editable_=t,t=0;for(var e;e=this.inputList[t];t++)for(var o=0,i;i=e.fieldRow[o];o++)i.updateEditable()},T.Block.prototype.isDisposed=function(){return this.disposed},T.Block.prototype.getMatchingConnection=function(t,e){var o=this.getConnections_(!0);if(t=t.getConnections_(!0),o.length!=t.length)throw Error("Connection lists did not match in length.");for(var i=0;i<t.length;i++)if(t[i]==e)return o[i];return null},T.Block.prototype.setHelpUrl=function(t){this.helpUrl=t},T.Block.prototype.setTooltip=function(t){this.tooltip=t},T.Block.prototype.getTooltip=function(){return T.Tooltip.getTooltipOfObject(this)},T.Block.prototype.getColour=function(){return this.colour_},T.Block.prototype.getStyleName=function(){return this.styleName_},T.Block.prototype.getHue=function(){return this.hue_},T.Block.prototype.setColour=function(t){t=T.utils.parseBlockColour(t),this.hue_=t.hue,this.colour_=t.hex},T.Block.prototype.setStyle=function(t){this.styleName_=t},T.Block.prototype.setOnChange=function(t){if(t&&"function"!=typeof t)throw Error("onchange must be a function.");this.onchangeWrapper_&&this.workspace.removeChangeListener(this.onchangeWrapper_),(this.onchange=t)&&(this.onchangeWrapper_=t.bind(this),this.workspace.addChangeListener(this.onchangeWrapper_))},T.Block.prototype.getField=function(t){for(var e=0,o;o=this.inputList[e];e++)for(var i=0,s;s=o.fieldRow[i];i++)if(s.name==t)return s;return null},T.Block.prototype.getVars=function(){for(var t=[],e=0,o;o=this.inputList[e];e++)for(var i=0,s;s=o.fieldRow[i];i++)s.referencesVariables()&&t.push(s.getValue());return t},T.Block.prototype.getVarModels=function(){for(var t=[],e=0,o;o=this.inputList[e];e++)for(var i=0,s;s=o.fieldRow[i];i++)s.referencesVariables()&&(s=this.workspace.getVariableById(s.getValue()))&&t.push(s);return t},T.Block.prototype.updateVarName=function(t){for(var e=0,o;o=this.inputList[e];e++)for(var i=0,s;s=o.fieldRow[i];i++)s.referencesVariables()&&t.getId()==s.getValue()&&s.refreshVariableName()},T.Block.prototype.renameVarById=function(t,e){for(var o=0,i;i=this.inputList[o];o++)for(var s=0,n;n=i.fieldRow[s];s++)n.referencesVariables()&&t==n.getValue()&&n.setValue(e)},T.Block.prototype.getFieldValue=function(t){return(t=this.getField(t))?t.getValue():null},T.Block.prototype.setFieldValue=function(t,e){var o=this.getField(e);if(!o)throw Error('Field "'+e+'" not found.');o.setValue(t)},T.Block.prototype.setPreviousStatement=function(t,e){if(t){if(void 0===e&&(e=null),!this.previousConnection){if(this.outputConnection)throw Error("Remove output connection prior to adding previous connection.");this.previousConnection=this.makeConnection_(T.connectionTypes.PREVIOUS_STATEMENT)}this.previousConnection.setCheck(e)}else if(this.previousConnection){if(this.previousConnection.isConnected())throw Error("Must disconnect previous statement before removing connection.");this.previousConnection.dispose(),this.previousConnection=null}},T.Block.prototype.setNextStatement=function(t,e){if(t)void 0===e&&(e=null),this.nextConnection||(this.nextConnection=this.makeConnection_(T.connectionTypes.NEXT_STATEMENT)),this.nextConnection.setCheck(e);else if(this.nextConnection){if(this.nextConnection.isConnected())throw Error("Must disconnect next statement before removing connection.");this.nextConnection.dispose(),this.nextConnection=null}},T.Block.prototype.setOutput=function(t,e){if(t){if(void 0===e&&(e=null),!this.outputConnection){if(this.previousConnection)throw Error("Remove previous connection prior to adding output connection.");this.outputConnection=this.makeConnection_(T.connectionTypes.OUTPUT_VALUE)}this.outputConnection.setCheck(e)}else if(this.outputConnection){if(this.outputConnection.isConnected())throw Error("Must disconnect output value before removing connection.");this.outputConnection.dispose(),this.outputConnection=null}},T.Block.prototype.setInputsInline=function(t){this.inputsInline!=t&&(T.Events.fire(new(T.Events.get(T.Events.BLOCK_CHANGE))(this,"inline",null,this.inputsInline,t)),this.inputsInline=t)},T.Block.prototype.getInputsInline=function(){if(null!=this.inputsInline)return this.inputsInline;for(var t=1;t<this.inputList.length;t++)if(this.inputList[t-1].type==T.inputTypes.DUMMY&&this.inputList[t].type==T.inputTypes.DUMMY)return!1;for(t=1;t<this.inputList.length;t++)if(this.inputList[t-1].type==T.inputTypes.VALUE&&this.inputList[t].type==T.inputTypes.DUMMY)return!0;return!1},T.Block.prototype.setOutputShape=function(t){this.outputShape_=t},T.Block.prototype.getOutputShape=function(){return this.outputShape_},T.Block.prototype.isEnabled=function(){return!this.disabled},T.Block.prototype.setEnabled=function(t){this.isEnabled()!=t&&(T.Events.fire(new(T.Events.get(T.Events.BLOCK_CHANGE))(this,"disabled",null,this.disabled,!t)),this.disabled=!t)},T.Block.prototype.getInheritedDisabled=function(){for(var t=this.getSurroundParent();t;){if(t.disabled)return!0;t=t.getSurroundParent()}return!1},T.Block.prototype.isCollapsed=function(){return this.collapsed_},T.Block.prototype.setCollapsed=function(t){this.collapsed_!=t&&(T.Events.fire(new(T.Events.get(T.Events.BLOCK_CHANGE))(this,"collapsed",null,this.collapsed_,t)),this.collapsed_=t)},T.Block.prototype.toString=function(t,e){function o(t){var e=t.getCheck();return(e=!e&&t.targetConnection?t.targetConnection.getCheck():e)&&(-1!=e.indexOf("Boolean")||-1!=e.indexOf("Number"))}function i(){r&&r.getType()==l.getType()&&r.getLocation()==l.getLocation()&&(r=null)}var s=[],n=(e=e||"?",T.ASTNode.NAVIGATE_ALL_FIELDS);T.ASTNode.NAVIGATE_ALL_FIELDS=!0;for(var r=T.ASTNode.createBlockNode(this),l=r;r;){switch(r.getType()){case T.ASTNode.types.INPUT:var a=r.getLocation();r.in()?o(a)&&s.push("("):s.push(e);break;case T.ASTNode.types.FIELD:(a=r.getLocation()).name!=T.constants.COLLAPSED_FIELD_NAME&&s.push(a.getText())}if(!(r=(a=r).in()||a.next())){for(r=a.out(),i();r&&!r.next();)r=r.out(),i(),r&&r.getType()==T.ASTNode.types.INPUT&&o(r.getLocation())&&s.push(")");r=r&&r.next()}}for(T.ASTNode.NAVIGATE_ALL_FIELDS=n,e=2,n=s.length;e<n;e++)"("==s[e-2]&&")"==s[e]&&(s[e-2]=s[e-1],s.splice(e-1,2),n-=2);return s=s.join(" ").replace(/(\() | (\))/gim,"$1$2").trim()||"???",s=t&&s.length>t?s.substring(0,t-3)+"...":s},T.Block.prototype.appendValueInput=function(t){return this.appendInput_(T.inputTypes.VALUE,t)},T.Block.prototype.appendStatementInput=function(t){return this.appendInput_(T.inputTypes.STATEMENT,t)},T.Block.prototype.appendDummyInput=function(t){return this.appendInput_(T.inputTypes.DUMMY,t||"")},T.Block.prototype.jsonInit=function(t){var e=t.type?'Block "'+t.type+'": ':"";if(t.output&&t.previousStatement)throw Error(e+"Must not have both an output and a previousStatement.");if(t.style&&t.style.hat&&(this.hat=t.style.hat,t.style=null),t.style&&t.colour)throw Error(e+"Must not have both a colour and a style.");t.style?this.jsonInitStyle_(t,e):this.jsonInitColour_(t,e);for(var o=0;void 0!==t["message"+o];)this.interpolate_(t["message"+o],t["args"+o]||[],t["lastDummyAlign"+o],e),o++;if(void 0!==t.inputsInline&&this.setInputsInline(t.inputsInline),void 0!==t.output&&this.setOutput(!0,t.output),void 0!==t.outputShape&&this.setOutputShape(t.outputShape),void 0!==t.previousStatement&&this.setPreviousStatement(!0,t.previousStatement),void 0!==t.nextStatement&&this.setNextStatement(!0,t.nextStatement),void 0!==t.tooltip&&(o=t.tooltip,o=T.utils.replaceMessageReferences(o),this.setTooltip(o)),void 0!==t.enableContextMenu&&(o=t.enableContextMenu,this.contextMenu=!!o),void 0!==t.helpUrl&&(o=t.helpUrl,o=T.utils.replaceMessageReferences(o),this.setHelpUrl(o)),"string"==typeof t.extensions&&(console.warn(e+"JSON attribute 'extensions' should be an array of strings. Found raw string in JSON for '"+t.type+"' block."),t.extensions=[t.extensions]),void 0!==t.mutator&&T.Extensions.apply(t.mutator,this,!0),Array.isArray(t.extensions))for(t=t.extensions,e=0;e<t.length;++e)T.Extensions.apply(t[e],this,!1)},T.Block.prototype.jsonInitColour_=function(e,o){if("colour"in e)if(void 0===e.colour)console.warn(o+"Undefined colour value.");else{e=e.colour;try{this.setColour(e)}catch(t){console.warn(o+"Illegal colour value: ",e)}}},T.Block.prototype.jsonInitStyle_=function(e,o){e=e.style;try{this.setStyle(e)}catch(t){console.warn(o+"Style does not exist: ",e)}},T.Block.prototype.mixin=function(t,e){if(void 0!==e&&"boolean"!=typeof e)throw Error("opt_disableCheck must be a boolean if provided");if(!e){for(var o in e=[],t)void 0!==this[o]&&e.push(o);if(e.length)throw Error("Mixin will overwrite block members: "+JSON.stringify(e))}T.utils.object.mixin(this,t)},T.Block.prototype.interpolate_=function(t,e,o,i){t=T.utils.tokenizeInterpolation(t),this.validateTokens_(t,e.length),e=this.interpolateArguments_(t,e,o),o=[],t=0;for(var s;s=e[t];t++)if(this.isInputKeyword_(s.type)){if(s=this.inputFromJson_(s,i)){for(var n=0,r;r=o[n];n++)s.appendField(r[0],r[1]);o.length=0}}else(n=this.fieldFromJson_(s))&&o.push([n,s.name])},T.Block.prototype.validateTokens_=function(t,e){for(var o=[],i=0,s=0;s<t.length;s++){var n=t[s];if("number"==typeof n){if(n<1||e<n)throw Error('Block "'+this.type+'": Message index %'+n+" out of range.");if(o[n])throw Error('Block "'+this.type+'": Message index %'+n+" duplicated.");o[n]=!0,i++}}if(i!=e)throw Error('Block "'+this.type+'": Message does not reference all '+e+" arg(s).")},T.Block.prototype.interpolateArguments_=function(t,e,o){for(var i=[],s=0;s<t.length;s++){var n=t[s];if("string"==typeof(n="number"==typeof n?e[n-1]:n)&&!(n=this.stringToFieldJson_(n)))continue;i.push(n)}return(t=i.length)&&!this.isInputKeyword_(i[t-1].type)&&(t={type:"input_dummy"},o&&(t.align=o),i.push(t)),i},T.Block.prototype.fieldFromJson_=function(t){var e=T.fieldRegistry.fromJson(t);return!e&&t.alt?"string"==typeof t.alt?(t=this.stringToFieldJson_(t.alt))?this.fieldFromJson_(t):null:this.fieldFromJson_(t.alt):e},T.Block.prototype.inputFromJson_=function(t,e){var o={LEFT:T.constants.ALIGN.LEFT,RIGHT:T.constants.ALIGN.RIGHT,CENTRE:T.constants.ALIGN.CENTRE,CENTER:T.constants.ALIGN.CENTRE},i=null;switch(t.type){case"input_value":i=this.appendValueInput(t.name);break;case"input_statement":i=this.appendStatementInput(t.name);break;case"input_dummy":i=this.appendDummyInput(t.name)}if(!i)return null;return t.check&&i.setCheck(t.check),t.align&&(void 0===(o=o[t.align.toUpperCase()])?console.warn(e+"Illegal align value: ",t.align):i.setAlign(o)),i},T.Block.prototype.isInputKeyword_=function(t){return"input_value"==t||"input_statement"==t||"input_dummy"==t},T.Block.prototype.stringToFieldJson_=function(t){return(t=t.trim())?{type:"field_label",text:t}:null},T.Block.prototype.appendInput_=function(t,e){var o=null;return t!=T.inputTypes.VALUE&&t!=T.inputTypes.STATEMENT||(o=this.makeConnection_(t)),t==T.inputTypes.STATEMENT&&this.statementInputCount++,t=new T.Input(t,e,this,o),this.inputList.push(t),t},T.Block.prototype.moveInputBefore=function(t,e){if(t!=e){for(var o=-1,i=e?-1:this.inputList.length,s=0,n;n=this.inputList[s];s++)if(n.name==t){if(o=s,-1!=i)break}else if(e&&n.name==e&&(i=s,-1!=o))break;if(-1==o)throw Error('Named input "'+t+'" not found.');if(-1==i)throw Error('Reference input "'+e+'" not found.');this.moveNumberedInputBefore(o,i)}},T.Block.prototype.moveNumberedInputBefore=function(t,e){if(t==e)throw Error("Can't move input to itself.");if(t>=this.inputList.length)throw RangeError("Input index "+t+" out of bounds.");if(e>this.inputList.length)throw RangeError("Reference input "+e+" out of bounds.");var o=this.inputList[t];this.inputList.splice(t,1),t<e&&e--,this.inputList.splice(e,0,o)},T.Block.prototype.removeInput=function(t,e){for(var o=0,i;i=this.inputList[o];o++)if(i.name==t)return i.type==T.inputTypes.STATEMENT&&this.statementInputCount--,i.dispose(),this.inputList.splice(o,1),!0;if(e)return!1;throw Error("Input not found: "+t)},T.Block.prototype.getInput=function(t){for(var e=0,o;o=this.inputList[e];e++)if(o.name==t)return o;return null},T.Block.prototype.getInputTargetBlock=function(t){return(t=this.getInput(t))&&t.connection&&t.connection.targetBlock()},T.Block.prototype.getCommentText=function(){return this.commentModel.text},T.Block.prototype.setCommentText=function(t){this.commentModel.text!=t&&(T.Events.fire(new(T.Events.get(T.Events.BLOCK_CHANGE))(this,"comment",null,this.commentModel.text,t)),this.comment=this.commentModel.text=t)},T.Block.prototype.setWarningText=function(t,e){},T.Block.prototype.setMutator=function(t){},T.Block.prototype.getRelativeToSurfaceXY=function(){return this.xy_},T.Block.prototype.moveBy=function(t,e){if(this.parentBlock_)throw Error("Block has parent.");var o=new(T.Events.get(T.Events.BLOCK_MOVE))(this);this.xy_.translate(t,e),o.recordNew(),T.Events.fire(o)},T.Block.prototype.makeConnection_=function(t){return new T.Connection(this,t)},T.Block.prototype.allInputsFilled=function(t){if(!(t=void 0===t?!0:t)&&this.isShadow())return!1;for(var e=0,o;o=this.inputList[e];e++)if(o.connection&&(!(o=o.connection.targetBlock())||!o.allInputsFilled(t)))return!1;return!(e=this.getNextBlock())||e.allInputsFilled(t)},T.Block.prototype.toDevString=function(){var t=this.type?'"'+this.type+'" block':"Block";return this.id&&(t+=' (id="'+this.id+'")'),t},T.blockRendering.IPathObject=function(t,e){},T.utils.KeyCodes={WIN_KEY_FF_LINUX:0,MAC_ENTER:3,BACKSPACE:8,TAB:9,NUM_CENTER:12,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PLUS_SIGN:43,PRINT_SCREEN:44,INSERT:45,DELETE:46,ZERO:48,ONE:49,TWO:50,THREE:51,FOUR:52,FIVE:53,SIX:54,SEVEN:55,EIGHT:56,NINE:57,FF_SEMICOLON:59,FF_EQUALS:61,FF_DASH:173,FF_HASH:163,QUESTION_MARK:63,AT_SIGN:64,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,META:91,WIN_KEY_RIGHT:92,CONTEXT_MENU:93,NUM_ZERO:96,NUM_ONE:97,NUM_TWO:98,NUM_THREE:99,NUM_FOUR:100,NUM_FIVE:101,NUM_SIX:102,NUM_SEVEN:103,NUM_EIGHT:104,NUM_NINE:105,NUM_MULTIPLY:106,NUM_PLUS:107,NUM_MINUS:109,NUM_PERIOD:110,NUM_DIVISION:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,NUMLOCK:144,SCROLL_LOCK:145,FIRST_MEDIA_KEY:166,LAST_MEDIA_KEY:183,SEMICOLON:186,DASH:189,EQUALS:187,COMMA:188,PERIOD:190,SLASH:191,APOSTROPHE:192,TILDE:192,SINGLE_QUOTE:222,OPEN_SQUARE_BRACKET:219,BACKSLASH:220,CLOSE_SQUARE_BRACKET:221,WIN_KEY:224,MAC_FF_META:224,MAC_WK_CMD_LEFT:91,MAC_WK_CMD_RIGHT:93,WIN_IME:229,VK_NONAME:252,PHANTOM:255},T.Menu=function(){this.menuItems_=[],this.roleName_=this.element_=this.onKeyDownHandler_=this.mouseLeaveHandler_=this.mouseEnterHandler_=this.clickHandler_=this.mouseOverHandler_=this.highlightedItem_=this.openingCoords=null},T.Menu.prototype.addChild=function(t){this.menuItems_.push(t)},T.Menu.prototype.render=function(t){var e=document.createElement("div");e.className="blocklyMenu goog-menu blocklyNonSelectable",e.tabIndex=0,this.roleName_&&T.utils.aria.setRole(e,this.roleName_),this.element_=e;for(var o=0,i;i=this.menuItems_[o];o++)e.appendChild(i.createDom());this.mouseOverHandler_=T.browserEvents.conditionalBind(e,"mouseover",this,this.handleMouseOver_,!0),this.clickHandler_=T.browserEvents.conditionalBind(e,"click",this,this.handleClick_,!0),this.mouseEnterHandler_=T.browserEvents.conditionalBind(e,"mouseenter",this,this.handleMouseEnter_,!0),this.mouseLeaveHandler_=T.browserEvents.conditionalBind(e,"mouseleave",this,this.handleMouseLeave_,!0),this.onKeyDownHandler_=T.browserEvents.conditionalBind(e,"keydown",this,this.handleKeyEvent_),t.appendChild(e)},T.Menu.prototype.getElement=function(){return this.element_},T.Menu.prototype.focus=function(){var t=this.getElement();t&&(t.focus({preventScroll:!0}),T.utils.dom.addClass(t,"blocklyFocused"))},T.Menu.prototype.blur_=function(){var t=this.getElement();t&&(t.blur(),T.utils.dom.removeClass(t,"blocklyFocused"))},T.Menu.prototype.setRole=function(t){this.roleName_=t},T.Menu.prototype.dispose=function(){this.mouseOverHandler_&&(T.browserEvents.unbind(this.mouseOverHandler_),this.mouseOverHandler_=null),this.clickHandler_&&(T.browserEvents.unbind(this.clickHandler_),this.clickHandler_=null),this.mouseEnterHandler_&&(T.browserEvents.unbind(this.mouseEnterHandler_),this.mouseEnterHandler_=null),this.mouseLeaveHandler_&&(T.browserEvents.unbind(this.mouseLeaveHandler_),this.mouseLeaveHandler_=null),this.onKeyDownHandler_&&(T.browserEvents.unbind(this.onKeyDownHandler_),this.onKeyDownHandler_=null);for(var t=0,e;e=this.menuItems_[t];t++)e.dispose();this.element_=null},T.Menu.prototype.getMenuItem_=function(t){for(var e=this.getElement();t&&t!=e;){if(T.utils.dom.hasClass(t,"blocklyMenuItem"))for(var o=0,i;i=this.menuItems_[o];o++)if(i.getElement()==t)return i;t=t.parentElement}return null},T.Menu.prototype.setHighlighted=function(t){var e=this.highlightedItem_;e&&(e.setHighlighted(!1),this.highlightedItem_=null),t&&(t.setHighlighted(!0),this.highlightedItem_=t,e=this.getElement(),T.utils.style.scrollIntoContainerView(t.getElement(),e),T.utils.aria.setState(e,T.utils.aria.State.ACTIVEDESCENDANT,t.getId()))},T.Menu.prototype.highlightNext=function(){var t=this.menuItems_.indexOf(this.highlightedItem_);this.highlightHelper_(t,1)},T.Menu.prototype.highlightPrevious=function(){var t=this.menuItems_.indexOf(this.highlightedItem_);this.highlightHelper_(t<0?this.menuItems_.length:t,-1)},T.Menu.prototype.highlightFirst_=function(){this.highlightHelper_(-1,1)},T.Menu.prototype.highlightLast_=function(){this.highlightHelper_(this.menuItems_.length,-1)},T.Menu.prototype.highlightHelper_=function(t,e){t+=e;for(var o;o=this.menuItems_[t];){if(o.isEnabled()){this.setHighlighted(o);break}t+=e}},T.Menu.prototype.handleMouseOver_=function(t){(t=this.getMenuItem_(t.target))&&(t.isEnabled()?this.highlightedItem_!=t&&this.setHighlighted(t):this.setHighlighted(null))},T.Menu.prototype.handleClick_=function(t){var e=this.openingCoords;if(this.openingCoords=null,e&&"number"==typeof t.clientX){var o=new T.utils.Coordinate(t.clientX,t.clientY);if(T.utils.Coordinate.distance(e,o)<1)return}(t=this.getMenuItem_(t.target))&&t.performAction()},T.Menu.prototype.handleMouseEnter_=function(t){this.focus()},T.Menu.prototype.handleMouseLeave_=function(t){this.getElement()&&(this.blur_(),this.setHighlighted(null))},T.Menu.prototype.handleKeyEvent_=function(t){if(this.menuItems_.length&&!(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)){var e=this.highlightedItem_;switch(t.keyCode){case T.utils.KeyCodes.ENTER:case T.utils.KeyCodes.SPACE:e&&e.performAction();break;case T.utils.KeyCodes.UP:this.highlightPrevious();break;case T.utils.KeyCodes.DOWN:this.highlightNext();break;case T.utils.KeyCodes.PAGE_UP:case T.utils.KeyCodes.HOME:this.highlightFirst_();break;case T.utils.KeyCodes.PAGE_DOWN:case T.utils.KeyCodes.END:this.highlightLast_();break;default:return}t.preventDefault(),t.stopPropagation()}},T.Menu.prototype.getSize=function(){var t=this.getElement(),e=T.utils.style.getSize(t);return e.height=t.scrollHeight,e},T.MenuItem=function(t,e){this.content_=t,this.value_=e,this.enabled_=!0,this.element_=null,this.rightToLeft_=!1,this.roleName_=null,this.highlight_=this.checked_=this.checkable_=!1,this.actionHandler_=null},T.MenuItem.prototype.createDom=function(){var t=document.createElement("div"),e=(t.id=T.utils.IdGenerator.getNextUniqueId(),(this.element_=t).className="blocklyMenuItem goog-menuitem "+(this.enabled_?"":"blocklyMenuItemDisabled goog-menuitem-disabled ")+(this.checked_?"blocklyMenuItemSelected goog-option-selected ":"")+(this.highlight_?"blocklyMenuItemHighlight goog-menuitem-highlight ":"")+(this.rightToLeft_?"blocklyMenuItemRtl goog-menuitem-rtl ":""),document.createElement("div")),o;return e.className="blocklyMenuItemContent goog-menuitem-content",this.checkable_&&((o=document.createElement("div")).className="blocklyMenuItemCheckbox goog-menuitem-checkbox",e.appendChild(o)),o=this.content_,"string"==typeof this.content_&&(o=document.createTextNode(this.content_)),e.appendChild(o),t.appendChild(e),this.roleName_&&T.utils.aria.setRole(t,this.roleName_),T.utils.aria.setState(t,T.utils.aria.State.SELECTED,this.checkable_&&this.checked_||!1),T.utils.aria.setState(t,T.utils.aria.State.DISABLED,!this.enabled_),t},T.MenuItem.prototype.dispose=function(){this.element_=null},T.MenuItem.prototype.getElement=function(){return this.element_},T.MenuItem.prototype.getId=function(){return this.element_.id},T.MenuItem.prototype.getValue=function(){return this.value_},T.MenuItem.prototype.setRightToLeft=function(t){this.rightToLeft_=t},T.MenuItem.prototype.setRole=function(t){this.roleName_=t},T.MenuItem.prototype.setCheckable=function(t){this.checkable_=t},T.MenuItem.prototype.setChecked=function(t){this.checked_=t},T.MenuItem.prototype.setHighlighted=function(t){this.highlight_=t;var e=this.getElement();e&&this.isEnabled()&&(t?(T.utils.dom.addClass(e,"blocklyMenuItemHighlight"),T.utils.dom.addClass(e,"goog-menuitem-highlight")):(T.utils.dom.removeClass(e,"blocklyMenuItemHighlight"),T.utils.dom.removeClass(e,"goog-menuitem-highlight")))},T.MenuItem.prototype.isEnabled=function(){return this.enabled_},T.MenuItem.prototype.setEnabled=function(t){this.enabled_=t},T.MenuItem.prototype.performAction=function(){this.isEnabled()&&this.actionHandler_&&this.actionHandler_(this)},T.MenuItem.prototype.onAction=function(t,e){this.actionHandler_=t.bind(e)},T.WidgetDiv={},T.WidgetDiv.owner_=null,T.WidgetDiv.dispose_=null,T.WidgetDiv.rendererClassName_="",T.WidgetDiv.themeClassName_="",T.WidgetDiv.createDom=function(){T.WidgetDiv.DIV||(T.WidgetDiv.DIV=document.createElement("div"),T.WidgetDiv.DIV.className="blocklyWidgetDiv",(T.parentContainer||document.body).appendChild(T.WidgetDiv.DIV))},T.WidgetDiv.show=function(t,e,o){T.WidgetDiv.hide(),T.WidgetDiv.owner_=t,T.WidgetDiv.dispose_=o,(t=T.WidgetDiv.DIV).style.direction=e?"rtl":"ltr",t.style.display="block",e=T.getMainWorkspace(),T.WidgetDiv.rendererClassName_=e.getRenderer().getClassName(),T.WidgetDiv.themeClassName_=e.getTheme().getClassName(),T.utils.dom.addClass(t,T.WidgetDiv.rendererClassName_),T.utils.dom.addClass(t,T.WidgetDiv.themeClassName_)},T.WidgetDiv.hide=function(){var t;T.WidgetDiv.isVisible()&&(T.WidgetDiv.owner_=null,(t=T.WidgetDiv.DIV).style.display="none",t.style.left="",t.style.top="",T.WidgetDiv.dispose_&&T.WidgetDiv.dispose_(),T.WidgetDiv.dispose_=null,t.textContent="",T.WidgetDiv.rendererClassName_&&(T.utils.dom.removeClass(t,T.WidgetDiv.rendererClassName_),T.WidgetDiv.rendererClassName_=""),T.WidgetDiv.themeClassName_&&(T.utils.dom.removeClass(t,T.WidgetDiv.themeClassName_),T.WidgetDiv.themeClassName_=""),T.getMainWorkspace().markFocused())},T.WidgetDiv.isVisible=function(){return!!T.WidgetDiv.owner_},T.WidgetDiv.hideIfOwner=function(t){T.WidgetDiv.owner_==t&&T.WidgetDiv.hide()},T.WidgetDiv.positionInternal_=function(t,e,o){T.WidgetDiv.DIV.style.left=t+"px",T.WidgetDiv.DIV.style.top=e+"px",T.WidgetDiv.DIV.style.height=o+"px"},T.WidgetDiv.positionWithAnchor=function(t,e,o,i){var s=T.WidgetDiv.calculateY_(t,e,o);t=T.WidgetDiv.calculateX_(t,e,o,i),s<0?T.WidgetDiv.positionInternal_(t,0,o.height+s):T.WidgetDiv.positionInternal_(t,s,o.height)},T.WidgetDiv.calculateX_=function(t,e,o,i){if(i)return e=Math.max(e.right-o.width,t.left),Math.min(e,t.right-o.width);return e=Math.min(e.left,t.right-o.width),Math.max(e,t.left)},T.WidgetDiv.calculateY_=function(t,e,o){return e.bottom+o.height>=t.bottom?e.top-o.height:e.bottom},T.ContextMenu={},T.ContextMenu.currentBlock=null,T.ContextMenu.menu_=null,T.ContextMenu.show=function(t,e,o){var i;T.WidgetDiv.show(T.ContextMenu,o,T.ContextMenu.dispose),e.length?(i=T.ContextMenu.populate_(e,o),T.ContextMenu.menu_=i,T.ContextMenu.position_(i,t,o),setTimeout(function(){i.focus()},1),T.ContextMenu.currentBlock=null):T.ContextMenu.hide()},T.ContextMenu.populate_=function(t,e){var o=new T.Menu;o.setRole(T.utils.aria.Role.MENU);for(var i=0,s;s=t[i];i++){var n=new T.MenuItem(s.text);n.setRightToLeft(e),n.setRole(T.utils.aria.Role.MENUITEM),o.addChild(n),n.setEnabled(s.enabled),s.enabled&&n.onAction(function(t){T.ContextMenu.hide(),this.callback(this.scope)},s)}return o},T.ContextMenu.position_=function(t,e,o){var i=T.utils.getViewportBBox(),s=(e=new T.utils.Rect(e.clientY+i.top,e.clientY+i.top,e.clientX+i.left,e.clientX+i.left),T.ContextMenu.createWidget_(t),t.getSize());o&&(e.left+=s.width,e.right+=s.width,i.left+=s.width,i.right+=s.width),T.WidgetDiv.positionWithAnchor(i,e,s,o),t.focus()},T.ContextMenu.createWidget_=function(t){t.render(T.WidgetDiv.DIV);var e=t.getElement();T.utils.dom.addClass(e,"blocklyContextMenu"),T.browserEvents.conditionalBind(e,"contextmenu",null,T.utils.noEvent),t.focus()},T.ContextMenu.hide=function(){T.WidgetDiv.hideIfOwner(T.ContextMenu),T.ContextMenu.currentBlock=null},T.ContextMenu.dispose=function(){T.ContextMenu.menu_&&(T.ContextMenu.menu_.dispose(),T.ContextMenu.menu_=null)},T.ContextMenu.callbackFactory=function(o,i){return function(){T.Events.disable();try{var t=T.Xml.domToBlock(i,o.workspace),e=o.getRelativeToSurfaceXY();e.x=o.RTL?e.x-T.SNAP_RADIUS:e.x+T.SNAP_RADIUS,e.y+=2*T.SNAP_RADIUS,t.moveBy(e.x,e.y)}finally{T.Events.enable()}T.Events.isEnabled()&&!t.isShadow()&&T.Events.fire(new(T.Events.get(T.Events.BLOCK_CREATE))(t)),t.select()}},T.ContextMenu.commentDeleteOption=function(t){return{text:T.Msg.REMOVE_COMMENT,enabled:!0,callback:function(){T.Events.setGroup(!0),t.dispose(!0,!0),T.Events.setGroup(!1)}}},T.ContextMenu.commentDuplicateOption=function(t){return{text:T.Msg.DUPLICATE_COMMENT,enabled:!0,callback:function(){T.duplicate(t)}}},T.ContextMenu.workspaceCommentOption=function(i,s){if(!T.WorkspaceCommentSvg)throw Error("Missing require for Blockly.WorkspaceCommentSvg");var t={enabled:!T.utils.userAgent.IE};return t.text=T.Msg.ADD_COMMENT,t.callback=function(){var t=new T.WorkspaceCommentSvg(i,T.Msg.WORKSPACE_COMMENT_DEFAULT_TEXT,T.WorkspaceCommentSvg.DEFAULT_SIZE,T.WorkspaceCommentSvg.DEFAULT_SIZE),e=i.getInjectionDiv().getBoundingClientRect(),e=new T.utils.Coordinate(s.clientX-e.left,s.clientY-e.top),o=i.getOriginOffsetInPixels();(e=T.utils.Coordinate.difference(e,o)).scale(1/i.scale),t.moveBy(e.x,e.y),i.rendered&&(t.initSvg(),t.render(),t.select())},t},T.ContextMenuRegistry=function(){(T.ContextMenuRegistry.registry=this).registry_={}},T.ContextMenuRegistry.ScopeType={BLOCK:"block",WORKSPACE:"workspace"},T.ContextMenuRegistry.registry=null,T.ContextMenuRegistry.prototype.register=function(t){if(this.registry_[t.id])throw Error('Menu item with id "'+t.id+'" is already registered.');this.registry_[t.id]=t},T.ContextMenuRegistry.prototype.unregister=function(t){if(!this.registry_[t])throw Error('Menu item with id "'+t+'" not found.');delete this.registry_[t]},T.ContextMenuRegistry.prototype.getItem=function(t){return this.registry_[t]||null},T.ContextMenuRegistry.prototype.getContextMenuOptions=function(o,i){var s=[],n=this.registry_;return Object.keys(n).forEach(function(t){var e;t=n[t],o==t.scopeType&&"hidden"!=(e=t.preconditionFn(i))&&(t={text:"function"==typeof t.displayText?t.displayText(i):t.displayText,enabled:"enabled"==e,callback:t.callback,scope:i,weight:t.weight},s.push(t))}),s.sort(function(t,e){return t.weight-e.weight}),s},new T.ContextMenuRegistry,T.Events.Selected=function(t,e,o){T.Events.Selected.superClass_.constructor.call(this,o),this.oldElementId=t,this.newElementId=e},T.utils.object.inherits(T.Events.Selected,T.Events.UiBase),T.Events.Selected.prototype.type=T.Events.SELECTED,T.Events.Selected.prototype.toJson=function(){var t=T.Events.Selected.superClass_.toJson.call(this);return t.oldElementId=this.oldElementId,t.newElementId=this.newElementId,t},T.Events.Selected.prototype.fromJson=function(t){T.Events.Selected.superClass_.fromJson.call(this,t),this.oldElementId=t.oldElementId,this.newElementId=t.newElementId},T.registry.register(T.registry.Type.EVENT,T.Events.SELECTED,T.Events.Selected),T.RenderedConnection=function(t,e){T.RenderedConnection.superClass_.constructor.call(this,t,e),this.db_=t.workspace.connectionDBList[e],this.dbOpposite_=t.workspace.connectionDBList[T.OPPOSITE_TYPE[e]],this.offsetInBlock_=new T.utils.Coordinate(0,0),this.trackedState_=T.RenderedConnection.TrackedState.WILL_TRACK,this.targetConnection=null},T.utils.object.inherits(T.RenderedConnection,T.Connection),T.RenderedConnection.TrackedState={WILL_TRACK:-1,UNTRACKED:0,TRACKED:1},T.RenderedConnection.prototype.dispose=function(){T.RenderedConnection.superClass_.dispose.call(this),this.trackedState_==T.RenderedConnection.TrackedState.TRACKED&&this.db_.removeConnection(this,this.y)},T.RenderedConnection.prototype.getSourceBlock=function(){return T.RenderedConnection.superClass_.getSourceBlock.call(this)},T.RenderedConnection.prototype.targetBlock=function(){return T.RenderedConnection.superClass_.targetBlock.call(this)},T.RenderedConnection.prototype.distanceFrom=function(t){var e=this.x-t.x;return t=this.y-t.y,Math.sqrt(e*e+t*t)},T.RenderedConnection.prototype.bumpAwayFrom=function(t){if(!this.sourceBlock_.workspace.isDragging()){var e=this.sourceBlock_.getRootBlock();if(!e.isInFlyout){var o=!1;if(!e.isMovable()){if(!(e=t.getSourceBlock().getRootBlock()).isMovable())return;t=this,o=!0}var i=T.selected==e,s=(i||e.addSelect(),t.x+T.SNAP_RADIUS+Math.floor(Math.random()*T.BUMP_RANDOMNESS)-this.x),n=t.y+T.SNAP_RADIUS+Math.floor(Math.random()*T.BUMP_RANDOMNESS)-this.y;o&&(n=-n),e.RTL&&(s=t.x-T.SNAP_RADIUS-Math.floor(Math.random()*T.BUMP_RANDOMNESS)-this.x),e.moveBy(s,n),i||e.removeSelect()}}},T.RenderedConnection.prototype.moveTo=function(t,e){this.trackedState_==T.RenderedConnection.TrackedState.WILL_TRACK?(this.db_.addConnection(this,e),this.trackedState_=T.RenderedConnection.TrackedState.TRACKED):this.trackedState_==T.RenderedConnection.TrackedState.TRACKED&&(this.db_.removeConnection(this,this.y),this.db_.addConnection(this,e)),this.x=t,this.y=e},T.RenderedConnection.prototype.moveBy=function(t,e){this.moveTo(this.x+t,this.y+e)},T.RenderedConnection.prototype.moveToOffset=function(t){this.moveTo(t.x+this.offsetInBlock_.x,t.y+this.offsetInBlock_.y)},T.RenderedConnection.prototype.setOffsetInBlock=function(t,e){this.offsetInBlock_.x=t,this.offsetInBlock_.y=e},T.RenderedConnection.prototype.getOffsetInBlock=function(){return this.offsetInBlock_},T.RenderedConnection.prototype.tighten=function(){var t=this.targetConnection.x-this.x,e=this.targetConnection.y-this.y;if(0!=t||0!=e){var o=this.targetBlock(),i=o.getSvgRoot();if(!i)throw Error("block is not rendered.");i=T.utils.getRelativeXY(i),o.getSvgRoot().setAttribute("transform","translate("+(i.x-t)+","+(i.y-e)+")"),o.moveConnections(-t,-e)}},T.RenderedConnection.prototype.closest=function(t,e){return this.dbOpposite_.searchForClosest(this,t,e)},T.RenderedConnection.prototype.highlight=function(){var t,e=(t=this.sourceBlock_.workspace.getRenderer().getConstants()).shapeFor(this),e=this.type==T.connectionTypes.INPUT_VALUE||this.type==T.connectionTypes.OUTPUT_VALUE?(t=t.TAB_OFFSET_FROM_TOP,T.utils.svgPaths.moveBy(0,-t)+T.utils.svgPaths.lineOnAxis("v",t)+e.pathDown+T.utils.svgPaths.lineOnAxis("v",t)):(t=t.NOTCH_OFFSET_LEFT-t.CORNER_RADIUS,T.utils.svgPaths.moveBy(-t,0)+T.utils.svgPaths.lineOnAxis("h",t)+e.pathLeft+T.utils.svgPaths.lineOnAxis("h",t)),t=this.sourceBlock_.getRelativeToSurfaceXY();T.Connection.highlightedPath_=T.utils.dom.createSvgElement(T.utils.Svg.PATH,{class:"blocklyHighlightedConnectionPath",d:e,transform:"translate("+(this.x-t.x)+","+(this.y-t.y)+")"+(this.sourceBlock_.RTL?" scale(-1 1)":"")},this.sourceBlock_.getSvgRoot())},T.RenderedConnection.prototype.unhighlight=function(){T.utils.dom.removeNode(T.Connection.highlightedPath_),delete T.Connection.highlightedPath_},T.RenderedConnection.prototype.setTracking=function(t){t&&this.trackedState_==T.RenderedConnection.TrackedState.TRACKED||!t&&this.trackedState_==T.RenderedConnection.TrackedState.UNTRACKED||this.sourceBlock_.isInFlyout||(t?(this.db_.addConnection(this,this.y),this.trackedState_=T.RenderedConnection.TrackedState.TRACKED):(this.trackedState_==T.RenderedConnection.TrackedState.TRACKED&&this.db_.removeConnection(this,this.y),this.trackedState_=T.RenderedConnection.TrackedState.UNTRACKED))},T.RenderedConnection.prototype.stopTrackingAll=function(){if(this.setTracking(!1),this.targetConnection)for(var t=this.targetBlock().getDescendants(!1),e=0;e<t.length;e++){for(var o=t[e],i=o.getConnections_(!0),s=0;s<i.length;s++)i[s].setTracking(!1);for(o=o.getIcons(),s=0;s<o.length;s++)o[s].setVisible(!1)}},T.RenderedConnection.prototype.startTrackingAll=function(){this.setTracking(!0);var t=[];if(this.type!=T.connectionTypes.INPUT_VALUE&&this.type!=T.connectionTypes.NEXT_STATEMENT)return t;var e=this.targetBlock(),o;if(e){e.isCollapsed()?(o=[],e.outputConnection&&o.push(e.outputConnection),e.nextConnection&&o.push(e.nextConnection),e.previousConnection&&o.push(e.previousConnection)):o=e.getConnections_(!0);for(var i=0;i<o.length;i++)t.push.apply(t,o[i].startTrackingAll());t.length||(t[0]=e)}return t},T.RenderedConnection.prototype.isConnectionAllowed=function(t,e){return T.utils.deprecation.warn("RenderedConnection.prototype.isConnectionAllowed","July 2020","July 2021","Blockly.Workspace.prototype.getConnectionChecker().canConnect"),!(this.distanceFrom(t)>e)&&T.RenderedConnection.superClass_.isConnectionAllowed.call(this,t)},T.RenderedConnection.prototype.onFailedConnect=function(t){this.bumpAwayFrom(t)},T.RenderedConnection.prototype.disconnectInternal_=function(t,e){T.RenderedConnection.superClass_.disconnectInternal_.call(this,t,e),t.rendered&&t.render(),e.rendered&&(e.updateDisabled(),e.render(),e.getSvgRoot().style.display="block")},T.RenderedConnection.prototype.respawnShadow_=function(){T.RenderedConnection.superClass_.respawnShadow_.call(this);var t=this.targetBlock();t&&(t.initSvg(),t.render(!1),(t=this.getSourceBlock()).rendered)&&t.render()},T.RenderedConnection.prototype.neighbours=function(t){return this.dbOpposite_.getNeighbours(this,t)},T.RenderedConnection.prototype.connect_=function(t){T.RenderedConnection.superClass_.connect_.call(this,t);var e=this.getSourceBlock(),o=(t=t.getSourceBlock(),e.rendered),i=t.rendered;o&&e.updateDisabled(),i&&t.updateDisabled(),o&&i&&(this.type==T.connectionTypes.NEXT_STATEMENT||this.type==T.connectionTypes.PREVIOUS_STATEMENT?t:e).render(),(e=e.getInputWithBlock(t))&&(e=e.isVisible(),t.getSvgRoot().style.display=e?"block":"none")},T.RenderedConnection.prototype.onCheckChanged_=function(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||((this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug(),this.sourceBlock_.bumpNeighbours())},T.Marker=function(){this.drawer_=this.curNode_=this.colour=null,this.type="marker"},T.Marker.prototype.setDrawer=function(t){this.drawer_=t},T.Marker.prototype.getDrawer=function(){return this.drawer_},T.Marker.prototype.getCurNode=function(){return this.curNode_},T.Marker.prototype.setCurNode=function(t){var e=this.curNode_;this.curNode_=t,this.drawer_&&this.drawer_.draw(e,this.curNode_)},T.Marker.prototype.draw=function(){this.drawer_&&this.drawer_.draw(this.curNode_,this.curNode_)},T.Marker.prototype.hide=function(){this.drawer_&&this.drawer_.hide()},T.Marker.prototype.dispose=function(){this.getDrawer()&&this.getDrawer().dispose()},T.Cursor=function(){T.Cursor.superClass_.constructor.call(this),this.type="cursor"},T.utils.object.inherits(T.Cursor,T.Marker),T.Cursor.prototype.next=function(){var t=this.getCurNode();if(!t)return null;for(t=t.next();t&&t.next()&&(t.getType()==T.ASTNode.types.NEXT||t.getType()==T.ASTNode.types.BLOCK);)t=t.next();return t&&this.setCurNode(t),t},T.Cursor.prototype.in=function(){var t=this.getCurNode();if(!t)return null;return(t=(t=t.getType()!=T.ASTNode.types.PREVIOUS&&t.getType()!=T.ASTNode.types.OUTPUT?t:t.next()).in())&&this.setCurNode(t),t},T.Cursor.prototype.prev=function(){var t=this.getCurNode();if(!t)return null;for(t=t.prev();t&&t.prev()&&(t.getType()==T.ASTNode.types.NEXT||t.getType()==T.ASTNode.types.BLOCK);)t=t.prev();return t&&this.setCurNode(t),t},T.Cursor.prototype.out=function(){var t=this.getCurNode();if(!t)return null;return(t=(t=t.out())&&t.getType()==T.ASTNode.types.BLOCK?t.prev()||t:t)&&this.setCurNode(t),t},T.registry.register(T.registry.Type.CURSOR,T.registry.DEFAULT,T.Cursor),T.BasicCursor=function(){T.BasicCursor.superClass_.constructor.call(this)},T.utils.object.inherits(T.BasicCursor,T.Cursor),T.BasicCursor.registrationName="basicCursor",T.BasicCursor.prototype.next=function(){var t=this.getCurNode();if(!t)return null;return(t=this.getNextNode_(t,this.validNode_))&&this.setCurNode(t),t},T.BasicCursor.prototype.in=function(){return this.next()},T.BasicCursor.prototype.prev=function(){var t=this.getCurNode();if(!t)return null;return(t=this.getPreviousNode_(t,this.validNode_))&&this.setCurNode(t),t},T.BasicCursor.prototype.out=function(){return this.prev()},T.BasicCursor.prototype.getNextNode_=function(t,e){if(!t)return null;var o=t.in()||t.next();if(e(o))return o;if(o)return this.getNextNode_(o,e);return e(t=this.findSiblingOrParent_(t.out()))?t:t?this.getNextNode_(t,e):null},T.BasicCursor.prototype.getPreviousNode_=function(t,e){if(!t)return null;var o=t.prev(),o;return e(o=o?this.getRightMostChild_(o):t.out())?o:o?this.getPreviousNode_(o,e):null},T.BasicCursor.prototype.validNode_=function(t){var e=!1;return e=(t=t&&t.getType())!=T.ASTNode.types.OUTPUT&&t!=T.ASTNode.types.INPUT&&t!=T.ASTNode.types.FIELD&&t!=T.ASTNode.types.NEXT&&t!=T.ASTNode.types.PREVIOUS&&t!=T.ASTNode.types.WORKSPACE?e:!0},T.BasicCursor.prototype.findSiblingOrParent_=function(t){if(!t)return null;var e=t.next();return e||this.findSiblingOrParent_(t.out())},T.BasicCursor.prototype.getRightMostChild_=function(t){if(!t.in())return t;for(t=t.in();t.next();)t=t.next();return this.getRightMostChild_(t)},T.registry.register(T.registry.Type.CURSOR,T.BasicCursor.registrationName,T.BasicCursor),T.TabNavigateCursor=function(){T.TabNavigateCursor.superClass_.constructor.call(this)},T.utils.object.inherits(T.TabNavigateCursor,T.BasicCursor),T.TabNavigateCursor.prototype.validNode_=function(t){var e=!1,o=t&&t.getType();return e=t&&(t=t.getLocation(),o==T.ASTNode.types.FIELD)&&t&&t.isTabNavigable()&&t.isClickable()?!0:e},T.BlockSvg=function(t,e,o){this.svgGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{},null),this.svgGroup_.translate_="",this.style=t.getRenderer().getConstants().getBlockStyle(null),this.pathObject=t.getRenderer().makePathObject(this.svgGroup_,this.style),this.renderIsInProgress_=this.rendered=!1,this.workspace=t,this.previousConnection=this.nextConnection=this.outputConnection=null,this.useDragSurface_=T.utils.is3dSupported()&&!!t.getBlockDragSurface();var i=this.pathObject.svgPath;i.tooltip=this,T.Tooltip.bindMouseEvents(i),T.BlockSvg.superClass_.constructor.call(this,t,e,o),this.svgGroup_.dataset?this.svgGroup_.dataset.id=this.id:T.utils.userAgent.IE&&this.svgGroup_.setAttribute("data-id",this.id)},T.utils.object.inherits(T.BlockSvg,T.Block),T.BlockSvg.prototype.height=0,T.BlockSvg.prototype.width=0,T.BlockSvg.prototype.warningTextDb_=null,T.BlockSvg.INLINE=-1,T.BlockSvg.COLLAPSED_WARNING_ID="TEMP_COLLAPSED_WARNING_",T.BlockSvg.prototype.initSvg=function(){if(!this.workspace.rendered)throw TypeError("Workspace is headless.");for(var t=0,e;e=this.inputList[t];t++)e.init();for(e=this.getIcons(),t=0;t<e.length;t++)e[t].createIcon();this.applyColour(),this.pathObject.updateMovable(this.isMovable()),t=this.getSvgRoot(),this.workspace.options.readOnly||this.eventsInit_||!t||T.browserEvents.conditionalBind(t,"mousedown",this,this.onMouseDown_),this.eventsInit_=!0,t.parentNode||this.workspace.getCanvas().appendChild(t)},T.BlockSvg.prototype.getColourSecondary=function(){return this.style.colourSecondary},T.BlockSvg.prototype.getColourTertiary=function(){return this.style.colourTertiary},T.BlockSvg.prototype.getColourShadow=function(){return T.utils.deprecation.warn("BlockSvg.prototype.getColourShadow","January 2020","January 2021","style.colourSecondary"),this.getColourSecondary()},T.BlockSvg.prototype.getColourBorder=function(){return T.utils.deprecation.warn("BlockSvg.prototype.getColourBorder","January 2020","January 2021","style.colourTertiary"),{colourBorder:this.getColourTertiary(),colourLight:null,colourDark:null}},T.BlockSvg.prototype.select=function(){if(this.isShadow()&&this.getParent())this.getParent().select();else if(T.selected!=this){var t=null;if(T.selected){t=T.selected.id,T.Events.disable();try{T.selected.unselect()}finally{T.Events.enable()}}t=new(T.Events.get(T.Events.SELECTED))(t,this.id,this.workspace.id),T.Events.fire(t),(T.selected=this).addSelect()}},T.BlockSvg.prototype.unselect=function(){var t;T.selected==this&&((t=new(T.Events.get(T.Events.SELECTED))(this.id,null,this.workspace.id)).workspaceId=this.workspace.id,T.Events.fire(t),T.selected=null,this.removeSelect())},T.BlockSvg.prototype.mutator=null,T.BlockSvg.prototype.comment=null,T.BlockSvg.prototype.commentIcon_=null,T.BlockSvg.prototype.warning=null,T.BlockSvg.prototype.getIcons=function(){var t=[];return this.mutator&&t.push(this.mutator),this.commentIcon_&&t.push(this.commentIcon_),this.warning&&t.push(this.warning),t},T.BlockSvg.prototype.setParent=function(t){var e=this.parentBlock_,o,i;t!=e&&(T.utils.dom.startTextWidthCache(),T.BlockSvg.superClass_.setParent.call(this,t),T.utils.dom.stopTextWidthCache(),o=this.getSvgRoot(),!this.workspace.isClearing)&&o&&(i=this.getRelativeToSurfaceXY(),t?(t.getSvgRoot().appendChild(o),t=this.getRelativeToSurfaceXY(),this.moveConnections(t.x-i.x,t.y-i.y)):e&&(this.workspace.getCanvas().appendChild(o),this.translate(i.x,i.y)),this.applyColour())},T.BlockSvg.prototype.getRelativeToSurfaceXY=function(){var t=0,e=0,o=this.useDragSurface_?this.workspace.getBlockDragSurface().getGroup():null,i=this.getSvgRoot();if(i)do{var s=T.utils.getRelativeXY(i);t+=s.x,e+=s.y,this.useDragSurface_&&this.workspace.getBlockDragSurface().getCurrentBlock()==i&&(t+=(s=this.workspace.getBlockDragSurface().getSurfaceTranslation()).x,e+=s.y),i=i.parentNode}while(i&&i!=this.workspace.getCanvas()&&i!=o);return new T.utils.Coordinate(t,e)},T.BlockSvg.prototype.moveBy=function(t,e){if(this.parentBlock_)throw Error("Block has parent.");var o=T.Events.isEnabled(),i,s=(o&&(i=new(T.Events.get(T.Events.BLOCK_MOVE))(this)),this.getRelativeToSurfaceXY());this.translate(s.x+t,s.y+e),this.moveConnections(t,e),o&&(i.recordNew(),T.Events.fire(i)),this.workspace.resizeContents()},T.BlockSvg.prototype.translate=function(t,e){this.getSvgRoot().setAttribute("transform","translate("+t+","+e+")")},T.BlockSvg.prototype.moveToDragSurface=function(){var t;this.useDragSurface_&&(t=this.getRelativeToSurfaceXY(),this.clearTransformAttributes_(),this.workspace.getBlockDragSurface().translateSurface(t.x,t.y),t=this.getSvgRoot())&&this.workspace.getBlockDragSurface().setBlocksAndShow(t)},T.BlockSvg.prototype.moveTo=function(t){var e=this.getRelativeToSurfaceXY();this.moveBy(t.x-e.x,t.y-e.y)},T.BlockSvg.prototype.moveOffDragSurface=function(t){this.useDragSurface_&&(this.translate(t.x,t.y),this.workspace.getBlockDragSurface().clearAndHide(this.workspace.getCanvas()))},T.BlockSvg.prototype.moveDuringDrag=function(t){this.useDragSurface_?this.workspace.getBlockDragSurface().translateSurface(t.x,t.y):(this.svgGroup_.translate_="translate("+t.x+","+t.y+")",this.svgGroup_.setAttribute("transform",this.svgGroup_.translate_+this.svgGroup_.skew_))},T.BlockSvg.prototype.clearTransformAttributes_=function(){this.getSvgRoot().removeAttribute("transform")},T.BlockSvg.prototype.snapToGrid=function(){var t,e,o,i,t,e;!this.workspace||this.workspace.isDragging()||this.getParent()||this.isInFlyout||(t=this.workspace.getGrid())&&t.shouldSnap()&&(o=(e=t.getSpacing())/2,i=this.getRelativeToSurfaceXY(),t=Math.round((i.x-o)/e)*e+o-i.x,e=Math.round((i.y-o)/e)*e+o-i.y,t=Math.round(t),e=Math.round(e),0==t&&0==e||this.moveBy(t,e))},T.BlockSvg.prototype.getBoundingRectangle=function(){var t=this.getRelativeToSurfaceXY(),e=this.getHeightWidth(),o,i,i=this.RTL?(o=t.x-e.width,t.x):(o=t.x,t.x+e.width);return new T.utils.Rect(t.y,t.y+e.height,o,i)},T.BlockSvg.prototype.markDirty=function(){this.pathObject.constants=this.workspace.getRenderer().getConstants();for(var t=0,e;e=this.inputList[t];t++)e.markDirty()},T.BlockSvg.prototype.setCollapsed=function(t){this.collapsed_!=t&&(T.BlockSvg.superClass_.setCollapsed.call(this,t),t?this.rendered&&this.render():this.updateCollapsed_())},T.BlockSvg.prototype.updateCollapsed_=function(){for(var t=this.isCollapsed(),e=T.constants.COLLAPSED_INPUT_NAME,o=T.constants.COLLAPSED_FIELD_NAME,i=0,s;s=this.inputList[i];i++)s.name!=e&&s.setVisible(!t);if(t){for(s=this.getIcons(),i=0;t=s[i];i++)t.setVisible(!1);i=this.toString(T.COLLAPSE_CHARS),(s=this.getField(o))?s.setValue(i):(s=this.getInput(e)||this.appendDummyInput(e)).appendField(new T.FieldLabel(i),o)}else this.updateDisabled(),this.removeInput(e)},T.BlockSvg.prototype.tab=function(t,e){var o=new T.TabNavigateCursor;o.setCurNode(T.ASTNode.createFieldNode(t)),t=o.getCurNode(),e?o.next():o.prev(),(e=o.getCurNode())&&e!==t&&(e.getLocation().showEditor(),this.workspace.keyboardAccessibilityMode)&&this.workspace.getCursor().setCurNode(e)},T.BlockSvg.prototype.onMouseDown_=function(t){var e=this.workspace&&this.workspace.getGesture(t);e&&e.handleBlockStart(t,this)},T.BlockSvg.prototype.showHelp=function(){var t="function"==typeof this.helpUrl?this.helpUrl():this.helpUrl;t&&window.open(t)},T.BlockSvg.prototype.generateContextMenu=function(){if(this.workspace.options.readOnly||!this.contextMenu)return null;var t=T.ContextMenuRegistry.registry.getContextMenuOptions(T.ContextMenuRegistry.ScopeType.BLOCK,{block:this});return this.customContextMenu&&this.customContextMenu(t),t},T.BlockSvg.prototype.showContextMenu=function(t){var e=this.generateContextMenu();e&&e.length&&(T.ContextMenu.show(t,e,this.RTL),T.ContextMenu.currentBlock=this)},T.BlockSvg.prototype.moveConnections=function(t,e){if(this.rendered){for(var o=this.getConnections_(!1),i=0;i<o.length;i++)o[i].moveBy(t,e);for(o=this.getIcons(),i=0;i<o.length;i++)o[i].computeIconLocation();for(i=0;i<this.childBlocks_.length;i++)this.childBlocks_[i].moveConnections(t,e)}},T.BlockSvg.prototype.setDragging=function(t){var e;for(t?((e=this.getSvgRoot()).translate_="",e.skew_="",T.draggingConnections=T.draggingConnections.concat(this.getConnections_(!0)),T.utils.dom.addClass(this.svgGroup_,"blocklyDragging")):(T.draggingConnections=[],T.utils.dom.removeClass(this.svgGroup_,"blocklyDragging")),e=0;e<this.childBlocks_.length;e++)this.childBlocks_[e].setDragging(t)},T.BlockSvg.prototype.setMovable=function(t){T.BlockSvg.superClass_.setMovable.call(this,t),this.pathObject.updateMovable(t)},T.BlockSvg.prototype.setEditable=function(t){T.BlockSvg.superClass_.setEditable.call(this,t),t=this.getIcons();for(var e=0;e<t.length;e++)t[e].updateEditable()},T.BlockSvg.prototype.setShadow=function(t){T.BlockSvg.superClass_.setShadow.call(this,t),this.applyColour()},T.BlockSvg.prototype.setInsertionMarker=function(t){this.isInsertionMarker_!=t&&(this.isInsertionMarker_=t)&&(this.setColour(this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR),this.pathObject.updateInsertionMarker(!0))},T.BlockSvg.prototype.getSvgRoot=function(){return this.svgGroup_},T.BlockSvg.prototype.dispose=function(t,e){if(this.workspace){T.Tooltip.dispose(),T.Tooltip.unbindMouseEvents(this.pathObject.svgPath),T.utils.dom.startTextWidthCache();var o=this.workspace;if(T.selected==this&&(this.unselect(),this.workspace.cancelCurrentGesture()),T.ContextMenu.currentBlock==this&&T.ContextMenu.hide(),e&&this.rendered&&(this.unplug(t),T.blockAnimations.disposeUiEffect(this)),this.rendered=!1,this.warningTextDb_){for(var i in this.warningTextDb_)clearTimeout(this.warningTextDb_[i]);this.warningTextDb_=null}for(e=this.getIcons(),i=0;i<e.length;i++)e[i].dispose();T.BlockSvg.superClass_.dispose.call(this,!!t),T.utils.dom.removeNode(this.svgGroup_),o.resizeContents(),this.svgGroup_=null,T.utils.dom.stopTextWidthCache()}},T.BlockSvg.prototype.toCopyData=function(){if(this.isInsertionMarker_)return null;var t=T.Xml.blockToDom(this,!0),e=(T.Xml.deleteNext(t),this.getRelativeToSurfaceXY());return t.setAttribute("x",this.RTL?-e.x:e.x),t.setAttribute("y",e.y),{xml:t,source:this.workspace,typeCounts:T.utils.getBlockTypeCounts(this,!0)}},T.BlockSvg.prototype.applyColour=function(){this.pathObject.applyColour(this);for(var t=this.getIcons(),e=0;e<t.length;e++)t[e].applyColour();for(t=0;e=this.inputList[t];t++)for(var o=0,i;i=e.fieldRow[o];o++)i.applyColour()},T.BlockSvg.prototype.updateDisabled=function(){var t=this.getChildren(!1);if(this.applyColour(),!this.isCollapsed())for(var e=0,o;o=t[e];e++)o.rendered&&o.updateDisabled()},T.BlockSvg.prototype.getCommentIcon=function(){return this.commentIcon_},T.BlockSvg.prototype.setCommentText=function(t){if(!T.Comment)throw Error("Missing require for Blockly.Comment");this.commentModel.text!=t&&(T.BlockSvg.superClass_.setCommentText.call(this,t),!!this.commentIcon_==(t=null!=t)?this.commentIcon_.updateText():(t?this.comment=this.commentIcon_=new T.Comment(this):(this.commentIcon_.dispose(),this.comment=this.commentIcon_=null),this.rendered&&(this.render(),this.bumpNeighbours())))},T.BlockSvg.prototype.setWarningText=function(t,e){if(!T.Warning)throw Error("Missing require for Blockly.Warning");this.warningTextDb_||(this.warningTextDb_=Object.create(null));var o=e||"";if(o)this.warningTextDb_[o]&&(clearTimeout(this.warningTextDb_[o]),delete this.warningTextDb_[o]);else for(var i in this.warningTextDb_)clearTimeout(this.warningTextDb_[i]),delete this.warningTextDb_[i];if(this.workspace.isDragging()){var s=this;this.warningTextDb_[o]=setTimeout(function(){s.workspace&&(delete s.warningTextDb_[o],s.setWarningText(t,o))},100)}else{if(e=!1,"string"==typeof(t=this.isInFlyout?null:t)){for(var i=this.getSurroundParent(),n=null;i;)i.isCollapsed()&&(n=i),i=i.getSurroundParent();n&&n.setWarningText(T.Msg.COLLAPSED_WARNINGS_WARNING,T.BlockSvg.COLLAPSED_WARNING_ID),this.warning||(this.warning=new T.Warning(this),e=!0),this.warning.setText(t,o)}else this.warning&&!o?(this.warning.dispose(),e=!0):this.warning&&(e=this.warning.getText(),this.warning.setText("",o),(i=this.warning.getText())||this.warning.dispose(),e=e!=i);e&&this.rendered&&(this.render(),this.bumpNeighbours())}},T.BlockSvg.prototype.setMutator=function(t){this.mutator&&this.mutator!==t&&this.mutator.dispose(),t&&(t.setBlock(this),(this.mutator=t).createIcon()),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.setEnabled=function(t){this.isEnabled()!=t&&(T.BlockSvg.superClass_.setEnabled.call(this,t),this.rendered)&&!this.getInheritedDisabled()&&this.updateDisabled()},T.BlockSvg.prototype.setHighlighted=function(t){this.rendered&&this.pathObject.updateHighlighted(t)},T.BlockSvg.prototype.addSelect=function(){this.pathObject.updateSelected(!0)},T.BlockSvg.prototype.removeSelect=function(){this.pathObject.updateSelected(!1)},T.BlockSvg.prototype.setDeleteStyle=function(t){this.pathObject.updateDraggingDelete(t)},T.BlockSvg.prototype.getColour=function(){return this.style.colourPrimary},T.BlockSvg.prototype.setColour=function(t){T.BlockSvg.superClass_.setColour.call(this,t),t=this.workspace.getRenderer().getConstants().getBlockStyleForColour(this.colour_),this.pathObject.setStyle(t.style),this.style=t.style,this.styleName_=t.name,this.applyColour()},T.BlockSvg.prototype.setStyle=function(t){var e=this.workspace.getRenderer().getConstants().getBlockStyle(t);if(this.styleName_=t,!e)throw Error("Invalid style name: "+t);this.hat=e.hat,this.pathObject.setStyle(e),this.colour_=e.colourPrimary,this.style=e,this.applyColour()},T.BlockSvg.prototype.bringToFront=function(){var t=this;do{var e=t.getSvgRoot(),o=e.parentNode,i=o.childNodes;i[i.length-1]!==e&&o.appendChild(e),t=t.getParent()}while(t)},T.BlockSvg.prototype.setPreviousStatement=function(t,e){T.BlockSvg.superClass_.setPreviousStatement.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.setNextStatement=function(t,e){T.BlockSvg.superClass_.setNextStatement.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.setOutput=function(t,e){T.BlockSvg.superClass_.setOutput.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.setInputsInline=function(t){T.BlockSvg.superClass_.setInputsInline.call(this,t),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.removeInput=function(t,e){return t=T.BlockSvg.superClass_.removeInput.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours()),t},T.BlockSvg.prototype.moveNumberedInputBefore=function(t,e){T.BlockSvg.superClass_.moveNumberedInputBefore.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours())},T.BlockSvg.prototype.appendInput_=function(t,e){return t=T.BlockSvg.superClass_.appendInput_.call(this,t,e),this.rendered&&(this.render(),this.bumpNeighbours()),t},T.BlockSvg.prototype.setConnectionTracking=function(t){var e;if(this.previousConnection&&this.previousConnection.setTracking(t),this.outputConnection&&this.outputConnection.setTracking(t),this.nextConnection&&(this.nextConnection.setTracking(t),e=this.nextConnection.targetBlock())&&e.setConnectionTracking(t),!this.collapsed_)for(e=0;e<this.inputList.length;e++){var o=this.inputList[e].connection;o&&(o.setTracking(t),o=o.targetBlock())&&o.setConnectionTracking(t)}},T.BlockSvg.prototype.getConnections_=function(t){var e=[],o;if((t||this.rendered)&&(this.outputConnection&&e.push(this.outputConnection),this.previousConnection&&e.push(this.previousConnection),this.nextConnection&&e.push(this.nextConnection),t||!this.collapsed_)){t=0;for(;o=this.inputList[t];t++)o.connection&&e.push(o.connection)}return e},T.BlockSvg.prototype.lastConnectionInStack=function(){return T.BlockSvg.superClass_.lastConnectionInStack.call(this)},T.BlockSvg.prototype.getMatchingConnection=function(t,e){return T.BlockSvg.superClass_.getMatchingConnection.call(this,t,e)},T.BlockSvg.prototype.makeConnection_=function(t){return new T.RenderedConnection(this,t)},T.BlockSvg.prototype.bumpNeighbours=function(){if(this.workspace&&!this.workspace.isDragging()){var t=this.getRootBlock();if(!t.isInFlyout)for(var e=this.getConnections_(!1),o=0,i;i=e[o];o++){i.isConnected()&&i.isSuperior()&&i.targetBlock().bumpNeighbours();for(var s=i.neighbours(T.SNAP_RADIUS),n=0,r;r=s[n];n++)i.isConnected()&&r.isConnected()||r.getSourceBlock().getRootBlock()!=t&&(i.isSuperior()?r.bumpAwayFrom(i):i.bumpAwayFrom(r))}}},T.BlockSvg.prototype.scheduleSnapAndBump=function(){var t=this,e=T.Events.getGroup();setTimeout(function(){T.Events.setGroup(e),t.snapToGrid(),T.Events.setGroup(!1)},T.BUMP_DELAY/2),setTimeout(function(){T.Events.setGroup(e),t.bumpNeighbours(),T.Events.setGroup(!1)},T.BUMP_DELAY)},T.BlockSvg.prototype.positionNearConnection=function(t,e){t.type!=T.connectionTypes.NEXT_STATEMENT&&t.type!=T.connectionTypes.INPUT_VALUE||this.moveBy(e.x-t.x,e.y-t.y)},T.BlockSvg.prototype.getParent=function(){return T.BlockSvg.superClass_.getParent.call(this)},T.BlockSvg.prototype.getRootBlock=function(){return T.BlockSvg.superClass_.getRootBlock.call(this)},T.BlockSvg.prototype.render=function(t){if(!this.renderIsInProgress_){this.renderIsInProgress_=!0;try{var e;this.rendered=!0,T.utils.dom.startTextWidthCache(),this.isCollapsed()&&this.updateCollapsed_(),this.workspace.getRenderer().render(this),this.updateConnectionLocations_(),!1!==t&&((e=this.getParent())?e.render(!0):this.workspace.resizeContents()),T.utils.dom.stopTextWidthCache(),this.updateMarkers_()}finally{this.renderIsInProgress_=!1}}},T.BlockSvg.prototype.updateMarkers_=function(){this.workspace.keyboardAccessibilityMode&&this.pathObject.cursorSvg&&this.workspace.getCursor().draw(),this.workspace.keyboardAccessibilityMode&&this.pathObject.markerSvg&&this.workspace.getMarker(T.MarkerManager.LOCAL_MARKER).draw()},T.BlockSvg.prototype.updateConnectionLocations_=function(){var t=this.getRelativeToSurfaceXY();this.previousConnection&&this.previousConnection.moveToOffset(t),this.outputConnection&&this.outputConnection.moveToOffset(t);for(var e=0;e<this.inputList.length;e++){var o=this.inputList[e].connection;o&&(o.moveToOffset(t),o.isConnected())&&o.tighten()}this.nextConnection&&(this.nextConnection.moveToOffset(t),this.nextConnection.isConnected())&&this.nextConnection.tighten()},T.BlockSvg.prototype.setCursorSvg=function(t){this.pathObject.setCursorSvg(t)},T.BlockSvg.prototype.setMarkerSvg=function(t){this.pathObject.setMarkerSvg(t)},T.BlockSvg.prototype.getHeightWidth=function(){var t=this.height,e=this.width,o=this.getNextBlock(),o,i;return o&&(o=o.getHeightWidth(),i=this.workspace.getRenderer().getConstants().NOTCH_HEIGHT,t+=o.height-i,e=Math.max(e,o.width)),{height:t,width:e}},T.BlockSvg.prototype.fadeForReplacement=function(t){this.pathObject.updateReplacementFade(t)},T.BlockSvg.prototype.highlightShapeForInput=function(t,e){this.pathObject.updateShapeForInputHighlight(t,e)},T.ConnectionDB=function(t){this.connections_=[],this.connectionChecker_=t},T.ConnectionDB.prototype.addConnection=function(t,e){e=this.calculateIndexForYPos_(e),this.connections_.splice(e,0,t)},T.ConnectionDB.prototype.findIndexOfConnection_=function(t,e){if(!this.connections_.length)return-1;var o=this.calculateIndexForYPos_(e);if(o>=this.connections_.length)return-1;e=t.y;for(var i=o;0<=i&&this.connections_[i].y==e;){if(this.connections_[i]==t)return i;i--}for(;o<this.connections_.length&&this.connections_[o].y==e;){if(this.connections_[o]==t)return o;o++}return-1},T.ConnectionDB.prototype.calculateIndexForYPos_=function(t){if(!this.connections_.length)return 0;for(var e=0,o=this.connections_.length;e<o;){var i=Math.floor((e+o)/2);if(this.connections_[i].y<t)e=i+1;else{if(!(this.connections_[i].y>t)){e=i;break}o=i}}return e},T.ConnectionDB.prototype.removeConnection=function(t,e){if(-1==(t=this.findIndexOfConnection_(t,e)))throw Error("Unable to find connection in connectionDB.");this.connections_.splice(t,1)},T.ConnectionDB.prototype.getNeighbours=function(t,i){function e(t){var e=n-s[t].x,o=r-s[t].y;return Math.sqrt(e*e+o*o)<=i&&a.push(s[t]),o<i}var s=this.connections_,n=t.x,r=t.y;t=0;for(var o,l=o=s.length-2;t<l;)s[l].y<r?t=l:o=l,l=Math.floor((t+o)/2);var a=[],o=t=l;if(s.length){for(;0<=t&&e(t);)t--;do{o++}while(o<s.length&&e(o))}return a},T.ConnectionDB.prototype.isInYRange_=function(t,e,o){return Math.abs(this.connections_[t].y-e)<=o},T.ConnectionDB.prototype.searchForClosest=function(t,e,o){if(!this.connections_.length)return{connection:null,radius:e};var i=t.y,s=t.x,n=(t.x=s+o.x,t.y=i+o.y,this.calculateIndexForYPos_(t.y));o=null;for(var r=e,l,a=n-1;0<=a&&this.isInYRange_(a,t.y,e);)l=this.connections_[a],this.connectionChecker_.canConnect(t,l,!0,r)&&(r=(o=l).distanceFrom(t)),a--;for(;n<this.connections_.length&&this.isInYRange_(n,t.y,e);)l=this.connections_[n],this.connectionChecker_.canConnect(t,l,!0,r)&&(r=(o=l).distanceFrom(t)),n++;return t.x=s,t.y=i,{connection:o,radius:r}},T.ConnectionDB.init=function(t){var e=[];return e[T.connectionTypes.INPUT_VALUE]=new T.ConnectionDB(t),e[T.connectionTypes.OUTPUT_VALUE]=new T.ConnectionDB(t),e[T.connectionTypes.NEXT_STATEMENT]=new T.ConnectionDB(t),e[T.connectionTypes.PREVIOUS_STATEMENT]=new T.ConnectionDB(t),e},T.Events.ThemeChange=function(t,e){T.Events.ThemeChange.superClass_.constructor.call(this,e),this.themeName=t},T.utils.object.inherits(T.Events.ThemeChange,T.Events.UiBase),T.Events.ThemeChange.prototype.type=T.Events.THEME_CHANGE,T.Events.ThemeChange.prototype.toJson=function(){var t=T.Events.ThemeChange.superClass_.toJson.call(this);return t.themeName=this.themeName,t},T.Events.ThemeChange.prototype.fromJson=function(t){T.Events.ThemeChange.superClass_.fromJson.call(this,t),this.themeName=t.themeName},T.registry.register(T.registry.Type.EVENT,T.Events.THEME_CHANGE,T.Events.ThemeChange),T.Events.ViewportChange=function(t,e,o,i,s){T.Events.ViewportChange.superClass_.constructor.call(this,i),this.viewTop=t,this.viewLeft=e,this.scale=o,this.oldScale=s},T.utils.object.inherits(T.Events.ViewportChange,T.Events.UiBase),T.Events.ViewportChange.prototype.type=T.Events.VIEWPORT_CHANGE,T.Events.ViewportChange.prototype.toJson=function(){var t=T.Events.ViewportChange.superClass_.toJson.call(this);return t.viewTop=this.viewTop,t.viewLeft=this.viewLeft,t.scale=this.scale,t.oldScale=this.oldScale,t},T.Events.ViewportChange.prototype.fromJson=function(t){T.Events.ViewportChange.superClass_.fromJson.call(this,t),this.viewTop=t.viewTop,this.viewLeft=t.viewLeft,this.scale=t.scale,this.oldScale=t.oldScale},T.registry.register(T.registry.Type.EVENT,T.Events.VIEWPORT_CHANGE,T.Events.ViewportChange),T.MarkerManager=function(t){this.cursorSvg_=this.cursor_=null,this.markers_={},this.workspace_=t},T.MarkerManager.LOCAL_MARKER="local_marker_1",T.MarkerManager.prototype.registerMarker=function(t,e){this.markers_[t]&&this.unregisterMarker(t),e.setDrawer(this.workspace_.getRenderer().makeMarkerDrawer(this.workspace_,e)),this.setMarkerSvg(e.getDrawer().createDom()),this.markers_[t]=e},T.MarkerManager.prototype.unregisterMarker=function(t){var e=this.markers_[t];if(!e)throw Error("Marker with id "+t+" does not exist. Can only unregistermarkers that exist.");e.dispose(),delete this.markers_[t]},T.MarkerManager.prototype.getCursor=function(){return this.cursor_},T.MarkerManager.prototype.getMarker=function(t){return this.markers_[t]},T.MarkerManager.prototype.setCursor=function(t){this.cursor_&&this.cursor_.getDrawer()&&this.cursor_.getDrawer().dispose(),(this.cursor_=t)&&(t=this.workspace_.getRenderer().makeMarkerDrawer(this.workspace_,this.cursor_),this.cursor_.setDrawer(t),this.setCursorSvg(this.cursor_.getDrawer().createDom()))},T.MarkerManager.prototype.setCursorSvg=function(t){t?(this.workspace_.getBlockCanvas().appendChild(t),this.cursorSvg_=t):this.cursorSvg_=null},T.MarkerManager.prototype.setMarkerSvg=function(t){t?this.workspace_.getBlockCanvas()&&(this.cursorSvg_?this.workspace_.getBlockCanvas().insertBefore(t,this.cursorSvg_):this.workspace_.getBlockCanvas().appendChild(t)):this.markerSvg_=null},T.MarkerManager.prototype.updateMarkers=function(){this.workspace_.keyboardAccessibilityMode&&this.cursorSvg_&&this.workspace_.getCursor().draw()},T.MarkerManager.prototype.dispose=function(){for(var t=Object.keys(this.markers_),e=0,o;o=t[e];e++)this.unregisterMarker(o);this.markers_=null,this.cursor_&&(this.cursor_.dispose(),this.cursor_=null)},T.IMetricsManager=function(){},T.MetricsManager=function(t){this.workspace_=t},T.MetricsManager.prototype.getDimensionsPx_=function(t){var e=0,o=0;return t&&(e=t.getWidth(),o=t.getHeight()),new T.utils.Size(e,o)},T.MetricsManager.prototype.getFlyoutMetrics=function(t){return{width:(t=this.getDimensionsPx_(this.workspace_.getFlyout(t))).width,height:t.height,position:this.workspace_.toolboxPosition}},T.MetricsManager.prototype.getToolboxMetrics=function(){var t=this.getDimensionsPx_(this.workspace_.getToolbox());return{width:t.width,height:t.height,position:this.workspace_.toolboxPosition}},T.MetricsManager.prototype.getSvgMetrics=function(){return this.workspace_.getCachedParentSvgSize()},T.MetricsManager.prototype.getAbsoluteMetrics=function(){var t=0,e=this.getToolboxMetrics(),o=this.getFlyoutMetrics(!0),i=!!this.workspace_.getToolbox(),s=!!this.workspace_.getFlyout(!0),n,r=(n=(i?e:o).position)==T.utils.toolbox.Position.LEFT,n=n==T.utils.toolbox.Position.TOP;return i&&r?t=e.width:s&&r&&(t=o.width),r=0,i&&n?r=e.height:s&&n&&(r=o.height),{top:r,left:t}},T.MetricsManager.prototype.getViewMetrics=function(t){t=t?this.workspace_.scale:1;var e=this.getSvgMetrics(),o=this.getToolboxMetrics(),i=this.getFlyoutMetrics(!0),s=(this.workspace_.getToolbox()?o:i).position;return this.workspace_.getToolbox()?s==T.utils.toolbox.Position.TOP||s==T.utils.toolbox.Position.BOTTOM?e.height-=o.height:s!=T.utils.toolbox.Position.LEFT&&s!=T.utils.toolbox.Position.RIGHT||(e.width-=o.width):this.workspace_.getFlyout(!0)&&(s==T.utils.toolbox.Position.TOP||s==T.utils.toolbox.Position.BOTTOM?e.height-=i.height:s!=T.utils.toolbox.Position.LEFT&&s!=T.utils.toolbox.Position.RIGHT||(e.width-=i.width)),{height:e.height/t,width:e.width/t,top:-this.workspace_.scrollY/t,left:-this.workspace_.scrollX/t}},T.MetricsManager.prototype.getContentMetrics=function(t){t=t?1:this.workspace_.scale;var e=this.workspace_.getBlocksBoundingBox();return{height:(e.bottom-e.top)*t,width:(e.right-e.left)*t,top:e.top*t,left:e.left*t}},T.MetricsManager.prototype.hasFixedEdges=function(){return!this.workspace_.isMovableHorizontally()||!this.workspace_.isMovableVertically()},T.MetricsManager.prototype.getComputedFixedEdges_=function(t){if(!this.hasFixedEdges())return{};var e=this.workspace_.isMovableHorizontally(),o=this.workspace_.isMovableVertically(),i=(t=t||this.getViewMetrics(!1),{});return o||(i.top=t.top,i.bottom=t.top+t.height),e||(i.left=t.left,i.right=t.left+t.width),i},T.MetricsManager.prototype.getPaddedContent_=function(t,e){var o=e.top+e.height,i=e.left+e.width,s=t.width,n=s/2,r=(t=t.height)/2;return{top:Math.min(e.top-r,o-t),bottom:Math.max(o+r,e.top+t),left:Math.min(e.left-n,i-s),right:Math.max(i+n,e.left+s)}},T.MetricsManager.prototype.getScrollMetrics=function(t,e,o){t=t?this.workspace_.scale:1,e=e||this.getViewMetrics(!1);var i=o||this.getContentMetrics(),s=(o=this.getComputedFixedEdges_(e),e=this.getPaddedContent_(e,i),i=(void 0!==o.top?o:e).top,(void 0!==o.left?o:e).left);return{top:i/t,left:s/t,width:((void 0!==o.right?o:e).right-s)/t,height:((void 0!==o.bottom?o:e).bottom-i)/t}},T.MetricsManager.prototype.getUiMetrics=function(){return{viewMetrics:this.getViewMetrics(),absoluteMetrics:this.getAbsoluteMetrics(),toolboxMetrics:this.getToolboxMetrics()}},T.MetricsManager.prototype.getMetrics=function(){var t=this.getToolboxMetrics(),e=this.getFlyoutMetrics(!0),o=this.getSvgMetrics(),i=this.getAbsoluteMetrics(),s=this.getViewMetrics(),n=this.getContentMetrics(),r=this.getScrollMetrics(!1,s,n);return{contentHeight:n.height,contentWidth:n.width,contentTop:n.top,contentLeft:n.left,scrollHeight:r.height,scrollWidth:r.width,scrollTop:r.top,scrollLeft:r.left,viewHeight:s.height,viewWidth:s.width,viewTop:s.top,viewLeft:s.left,absoluteTop:i.top,absoluteLeft:i.left,svgHeight:o.height,svgWidth:o.width,toolboxWidth:t.width,toolboxHeight:t.height,toolboxPosition:t.position,flyoutWidth:e.width,flyoutHeight:e.height}},T.registry.register(T.registry.Type.METRICS_MANAGER,T.registry.DEFAULT,T.MetricsManager),T.FlyoutMetricsManager=function(t,e){this.flyout_=e,T.FlyoutMetricsManager.superClass_.constructor.call(this,t)},T.utils.object.inherits(T.FlyoutMetricsManager,T.MetricsManager),T.FlyoutMetricsManager.prototype.getBoundingBox_=function(){try{var e=this.workspace_.getCanvas().getBBox()}catch(t){e={height:0,y:0,width:0,x:0}}return e},T.FlyoutMetricsManager.prototype.getContentMetrics=function(t){var e=this.getBoundingBox_();return t=t?1:this.workspace_.scale,{height:e.height*t,width:e.width*t,top:e.y*t,left:e.x*t}},T.FlyoutMetricsManager.prototype.getScrollMetrics=function(t,e,o){return e=o||this.getContentMetrics(),o=this.flyout_.MARGIN*this.workspace_.scale,t=t?this.workspace_.scale:1,{height:(e.height+2*o)/t,width:(e.width+e.left+o)/t,top:0,left:0}},T.FlyoutMetricsManager.prototype.getViewMetrics=function(t){var e=this.getSvgMetrics(),o,e;return t=t?this.workspace_.scale:1,{height:(e=this.flyout_.horizontalLayout?(o=e.width-2*this.flyout_.SCROLLBAR_PADDING,e.height-this.flyout_.SCROLLBAR_PADDING):(o=e.width-this.flyout_.SCROLLBAR_PADDING,e.height-2*this.flyout_.SCROLLBAR_PADDING))/t,width:o/t,top:-this.workspace_.scrollY/t,left:-this.workspace_.scrollX/t}},T.FlyoutMetricsManager.prototype.getAbsoluteMetrics=function(){var t=this.flyout_.SCROLLBAR_PADDING;return this.flyout_.horizontalLayout?{top:0,left:t}:{top:t,left:0}},T.PluginManager=function(){this.pluginData_={},this.typeToPluginIds_={}},T.PluginManager.prototype.addPlugin=function(t){this.pluginData_[t.id]=t;for(var e=0,o;o=t.types[e];e++)o=String(o).toLowerCase(),void 0===this.typeToPluginIds_[o]?this.typeToPluginIds_[o]=[t.id]:this.typeToPluginIds_[o].push(t.id)},T.PluginManager.prototype.getPlugin=function(t){return this.pluginData_[t]&&this.pluginData_[t].plugin},T.PluginManager.prototype.getPlugins=function(t,e){if(t=String(t).toLowerCase(),!(t=this.typeToPluginIds_[t]))return[];var o=[],i,s;return e?(i=[],s=this.pluginData_,t.forEach(function(t){i.push(s[t])}),i.sort(function(t,e){return t.weight-e.weight}),i.forEach(function(t){o.push(t.plugin)})):(s=this.pluginData_,t.forEach(function(t){o.push(s[t].plugin)})),o},T.PluginManager.Type=function(t){this.name_=t},T.PluginManager.Type.prototype.toString=function(){return this.name_},T.PluginManager.Type.POSITIONABLE=new T.PluginManager.Type("positionable"),T.ThemeManager=function(t,e){this.workspace_=t,this.theme_=e,this.subscribedWorkspaces_=[],this.componentDB_=Object.create(null)},T.ThemeManager.prototype.getTheme=function(){return this.theme_},T.ThemeManager.prototype.setTheme=function(t){var e=this.theme_,o;for(this.theme_=t,(t=this.workspace_.getInjectionDiv())&&(e&&T.utils.dom.removeClass(t,e.getClassName()),T.utils.dom.addClass(t,this.theme_.getClassName())),e=0;t=this.subscribedWorkspaces_[e];e++)t.refreshTheme();for(e=0,t=Object.keys(this.componentDB_);o=t[e];e++)for(var i=0,s;s=this.componentDB_[o][i];i++){var n=s.element,s=s.propertyName,r=this.theme_&&this.theme_.getComponentStyle(o);n.style[s]=r||""}T.hideChaff()},T.ThemeManager.prototype.subscribeWorkspace=function(t){this.subscribedWorkspaces_.push(t)},T.ThemeManager.prototype.unsubscribeWorkspace=function(t){if((t=this.subscribedWorkspaces_.indexOf(t))<0)throw Error("Cannot unsubscribe a workspace that hasn't been subscribed.");this.subscribedWorkspaces_.splice(t,1)},T.ThemeManager.prototype.subscribe=function(t,e,o){this.componentDB_[e]||(this.componentDB_[e]=[]),this.componentDB_[e].push({element:t,propertyName:o}),e=this.theme_&&this.theme_.getComponentStyle(e),t.style[o]=e||""},T.ThemeManager.prototype.unsubscribe=function(t){if(t)for(var e=Object.keys(this.componentDB_),o=0,i;i=e[o];o++){for(var s=this.componentDB_[i],n=s.length-1;0<=n;n--)s[n].element===t&&s.splice(n,1);this.componentDB_[i].length||delete this.componentDB_[i]}},T.ThemeManager.prototype.dispose=function(){this.componentDB_=this.subscribedWorkspaces_=this.theme_=this.owner_=null},T.TouchGesture=function(t,e){T.TouchGesture.superClass_.constructor.call(this,t,e),this.isMultiTouch_=!1,this.cachedPoints_=Object.create(null),this.startDistance_=this.previousScale_=0,this.isPinchZoomEnabled_=this.onStartWrapper_=null},T.utils.object.inherits(T.TouchGesture,T.Gesture),T.TouchGesture.ZOOM_IN_MULTIPLIER=5,T.TouchGesture.ZOOM_OUT_MULTIPLIER=6,T.TouchGesture.prototype.doStart=function(t){this.isPinchZoomEnabled_=this.startWorkspace_.options.zoomOptions&&this.startWorkspace_.options.zoomOptions.pinch,T.TouchGesture.superClass_.doStart.call(this,t),!this.isEnding_&&T.Touch.isTouchEvent(t)&&this.handleTouchStart(t)},T.TouchGesture.prototype.bindMouseEvents=function(t){this.onStartWrapper_=T.browserEvents.conditionalBind(document,"mousedown",null,this.handleStart.bind(this),!0),this.onMoveWrapper_=T.browserEvents.conditionalBind(document,"mousemove",null,this.handleMove.bind(this),!0),this.onUpWrapper_=T.browserEvents.conditionalBind(document,"mouseup",null,this.handleUp.bind(this),!0),t.preventDefault(),t.stopPropagation()},T.TouchGesture.prototype.handleStart=function(t){!this.isDragging()&&T.Touch.isTouchEvent(t)&&(this.handleTouchStart(t),this.isMultiTouch())&&T.longStop_()},T.TouchGesture.prototype.handleMove=function(t){this.isDragging()?T.Touch.shouldHandleEvent(t)&&T.TouchGesture.superClass_.handleMove.call(this,t):this.isMultiTouch()?(T.Touch.isTouchEvent(t)&&this.handleTouchMove(t),T.longStop_()):T.TouchGesture.superClass_.handleMove.call(this,t)},T.TouchGesture.prototype.handleUp=function(t){T.Touch.isTouchEvent(t)&&!this.isDragging()&&this.handleTouchEnd(t),!this.isMultiTouch()||this.isDragging()?T.Touch.shouldHandleEvent(t)&&T.TouchGesture.superClass_.handleUp.call(this,t):(t.preventDefault(),t.stopPropagation(),this.dispose())},T.TouchGesture.prototype.isMultiTouch=function(){return this.isMultiTouch_},T.TouchGesture.prototype.dispose=function(){T.TouchGesture.superClass_.dispose.call(this),this.onStartWrapper_&&T.browserEvents.unbind(this.onStartWrapper_)},T.TouchGesture.prototype.handleTouchStart=function(t){var e=T.Touch.getTouchIdentifierFromEvent(t);this.cachedPoints_[e]=this.getTouchPoint(t),2==(e=Object.keys(this.cachedPoints_)).length&&(this.startDistance_=T.utils.Coordinate.distance(this.cachedPoints_[e[0]],this.cachedPoints_[e[1]]),this.isMultiTouch_=!0,t.preventDefault())},T.TouchGesture.prototype.handleTouchMove=function(t){var e=T.Touch.getTouchIdentifierFromEvent(t);this.cachedPoints_[e]=this.getTouchPoint(t),e=Object.keys(this.cachedPoints_),this.isPinchZoomEnabled_&&2===e.length?this.handlePinch_(t):T.TouchGesture.superClass_.handleMove.call(this,t)},T.TouchGesture.prototype.handlePinch_=function(t){var e=Object.keys(this.cachedPoints_),o,o,i,s,e=T.utils.Coordinate.distance(this.cachedPoints_[e[0]],this.cachedPoints_[e[1]])/this.startDistance_;0<this.previousScale_&&1/0>this.previousScale_&&(o=0<(o=e-this.previousScale_)?o*T.TouchGesture.ZOOM_IN_MULTIPLIER:o*T.TouchGesture.ZOOM_OUT_MULTIPLIER,i=this.startWorkspace_,s=T.utils.mouseToSvg(t,i.getParentSvg(),i.getInverseScreenCTM()),i.zoom(s.x,s.y,o)),this.previousScale_=e,t.preventDefault()},T.TouchGesture.prototype.handleTouchEnd=function(t){t=T.Touch.getTouchIdentifierFromEvent(t),this.cachedPoints_[t]&&delete this.cachedPoints_[t],Object.keys(this.cachedPoints_).length<2&&(this.cachedPoints_=Object.create(null),this.previousScale_=0)},T.TouchGesture.prototype.getTouchPoint=function(t){return this.startWorkspace_?new T.utils.Coordinate(t.pageX||t.changedTouches[0].pageX,t.pageY||t.changedTouches[0].pageY):null},T.WorkspaceAudio=function(t){this.parentWorkspace_=t,this.SOUNDS_=Object.create(null)},T.WorkspaceAudio.prototype.lastSound_=null,T.WorkspaceAudio.prototype.dispose=function(){this.SOUNDS_=this.parentWorkspace_=null},T.WorkspaceAudio.prototype.load=function(t,e){if(t.length){try{var o=new T.utils.global.Audio}catch(t){return}for(var i,s=0;s<t.length;s++){var n=t[s],r=n.match(/\.(\w+)$/);if(r&&o.canPlayType("audio/"+r[1])){i=new T.utils.global.Audio(n);break}}i&&i.play&&(this.SOUNDS_[e]=i)}},T.WorkspaceAudio.prototype.preload=function(){for(var t in this.SOUNDS_){var e=this.SOUNDS_[t],o=(e.volume=.01,e.play());if(void 0!==o?o.then(e.pause).catch(function(){}):e.pause(),T.utils.userAgent.IPAD||T.utils.userAgent.IPHONE)break}},T.WorkspaceAudio.prototype.play=function(t,e){var o=this.SOUNDS_[t];o?(t=new Date,null!=this.lastSound_&&t-this.lastSound_<T.SOUND_LIMIT||(this.lastSound_=t,(o=T.utils.userAgent.IPAD||T.utils.userAgent.ANDROID?o:o.cloneNode()).volume=void 0===e?1:e,o.play())):this.parentWorkspace_&&this.parentWorkspace_.getAudioManager().play(t,e)},T.WorkspaceSvg=function(t,e,o){T.WorkspaceSvg.superClass_.constructor.call(this,t),this.metricsManager_=new(T.registry.getClassFromOptions(T.registry.Type.METRICS_MANAGER,t,!0))(this),this.getMetrics=t.getMetrics||this.metricsManager_.getMetrics.bind(this.metricsManager_),this.setMetrics=t.setMetrics||T.WorkspaceSvg.setTopLevelWorkspaceMetrics_,this.pluginManager_=new T.PluginManager,this.connectionDBList=T.ConnectionDB.init(this.connectionChecker),e&&(this.blockDragSurface_=e),o&&(this.workspaceDragSurface_=o),this.useWorkspaceDragSurface_=!!this.workspaceDragSurface_&&T.utils.is3dSupported(),this.highlightedBlocks_=[],this.audioManager_=new T.WorkspaceAudio(t.parentWorkspace),this.grid_=this.options.gridPattern?new T.Grid(this.options.gridPattern,t.gridOptions):null,this.markerManager_=new T.MarkerManager(this),this.toolboxCategoryCallbacks_={},this.flyoutButtonCallbacks_={},T.Variables&&T.Variables.flyoutCategory&&this.registerToolboxCategoryCallback(T.VARIABLE_CATEGORY_NAME,T.Variables.flyoutCategory),T.VariablesDynamic&&T.VariablesDynamic.flyoutCategory&&this.registerToolboxCategoryCallback(T.VARIABLE_DYNAMIC_CATEGORY_NAME,T.VariablesDynamic.flyoutCategory),T.Procedures&&T.Procedures.flyoutCategory&&(this.registerToolboxCategoryCallback(T.PROCEDURE_CATEGORY_NAME,T.Procedures.flyoutCategory),this.addChangeListener(T.Procedures.mutatorOpenListener)),this.themeManager_=this.options.parentWorkspace?this.options.parentWorkspace.getThemeManager():new T.ThemeManager(this,this.options.theme||T.Themes.Classic),this.themeManager_.subscribeWorkspace(this),this.renderer_=T.blockRendering.init(this.options.renderer||"geras",this.getTheme(),this.options.rendererOverrides),this.cachedParentSvg_=null,this.keyboardAccessibilityMode=!1,this.topBoundedElements_=[],this.cachedParentSvgSize_=new T.utils.Size(0,0)},T.utils.object.inherits(T.WorkspaceSvg,T.Workspace),T.WorkspaceSvg.prototype.resizeHandlerWrapper_=null,T.WorkspaceSvg.prototype.rendered=!0,T.WorkspaceSvg.prototype.isVisible_=!0,T.WorkspaceSvg.prototype.isFlyout=!1,T.WorkspaceSvg.prototype.isMutator=!1,T.WorkspaceSvg.prototype.resizesEnabled_=!0,T.WorkspaceSvg.prototype.scrollX=0,T.WorkspaceSvg.prototype.scrollY=0,T.WorkspaceSvg.prototype.startScrollX=0,T.WorkspaceSvg.prototype.startScrollY=0,T.WorkspaceSvg.prototype.dragDeltaXY_=null,T.WorkspaceSvg.prototype.scale=1,T.WorkspaceSvg.prototype.oldScale_=1,T.WorkspaceSvg.prototype.oldTop_=0,T.WorkspaceSvg.prototype.oldLeft_=0,T.WorkspaceSvg.prototype.trashcan=null,T.WorkspaceSvg.prototype.scrollbar=null,T.WorkspaceSvg.prototype.flyout_=null,T.WorkspaceSvg.prototype.toolbox_=null,T.WorkspaceSvg.prototype.currentGesture_=null,T.WorkspaceSvg.prototype.blockDragSurface_=null,T.WorkspaceSvg.prototype.workspaceDragSurface_=null,T.WorkspaceSvg.prototype.useWorkspaceDragSurface_=!1,T.WorkspaceSvg.prototype.isDragSurfaceActive_=!1,T.WorkspaceSvg.prototype.injectionDiv_=null,T.WorkspaceSvg.prototype.lastRecordedPageScroll_=null,T.WorkspaceSvg.prototype.targetWorkspace=null,T.WorkspaceSvg.prototype.inverseScreenCTM_=null,T.WorkspaceSvg.prototype.inverseScreenCTMDirty_=!0,T.WorkspaceSvg.prototype.getMarkerManager=function(){return this.markerManager_},T.WorkspaceSvg.prototype.getMetricsManager=function(){return this.metricsManager_},T.WorkspaceSvg.prototype.setMetricsManager=function(t){this.metricsManager_=t,this.getMetrics=this.metricsManager_.getMetrics.bind(this.metricsManager_)},T.WorkspaceSvg.prototype.getPluginManager=function(){return this.pluginManager_},T.WorkspaceSvg.prototype.setCursorSvg=function(t){this.markerManager_.setCursorSvg(t)},T.WorkspaceSvg.prototype.setMarkerSvg=function(t){this.markerManager_.setMarkerSvg(t)},T.WorkspaceSvg.prototype.getMarker=function(t){return this.markerManager_?this.markerManager_.getMarker(t):null},T.WorkspaceSvg.prototype.getCursor=function(){return this.markerManager_?this.markerManager_.getCursor():null},T.WorkspaceSvg.prototype.getRenderer=function(){return this.renderer_},T.WorkspaceSvg.prototype.getThemeManager=function(){return this.themeManager_},T.WorkspaceSvg.prototype.getTheme=function(){return this.themeManager_.getTheme()},T.WorkspaceSvg.prototype.setTheme=function(t){t=t||T.Themes.Classic,this.themeManager_.setTheme(t)},T.WorkspaceSvg.prototype.refreshTheme=function(){this.svgGroup_&&this.renderer_.refreshDom(this.svgGroup_,this.getTheme()),this.updateBlockStyles_(this.getAllBlocks(!1).filter(function(t){return void 0!==t.getStyleName()})),this.refreshToolboxSelection(),this.toolbox_&&this.toolbox_.refreshTheme(),this.isVisible()&&this.setVisible(!0);var t=new(T.Events.get(T.Events.THEME_CHANGE))(this.getTheme().name,this.id);T.Events.fire(t)},T.WorkspaceSvg.prototype.updateBlockStyles_=function(t){for(var e=0,o;o=t[e];e++){var i=o.getStyleName();i&&(o.setStyle(i),o.mutator)&&o.mutator.updateBlockStyle()}},T.WorkspaceSvg.prototype.getInverseScreenCTM=function(){var t;return this.inverseScreenCTMDirty_&&(t=this.getParentSvg().getScreenCTM())&&(this.inverseScreenCTM_=t.inverse(),this.inverseScreenCTMDirty_=!1),this.inverseScreenCTM_},T.WorkspaceSvg.prototype.updateInverseScreenCTM=function(){this.inverseScreenCTMDirty_=!0},T.WorkspaceSvg.prototype.isVisible=function(){return this.isVisible_},T.WorkspaceSvg.prototype.getSvgXY=function(t){var e=0,o=0,i=1;(T.utils.dom.containsNode(this.getCanvas(),t)||T.utils.dom.containsNode(this.getBubbleCanvas(),t))&&(i=this.scale);do{var s=T.utils.getRelativeXY(t);t!=this.getCanvas()&&t!=this.getBubbleCanvas()||(i=1),e+=s.x*i,o+=s.y*i,t=t.parentNode}while(t&&t!=this.getParentSvg());return new T.utils.Coordinate(e,o)},T.WorkspaceSvg.prototype.getCachedParentSvgSize=function(){var t=this.cachedParentSvgSize_;return new T.utils.Size(t.width,t.height)},T.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return T.utils.getInjectionDivXY_(this.getCanvas())},T.WorkspaceSvg.prototype.getInjectionDiv=function(){if(!this.injectionDiv_)for(var t=this.svgGroup_;t;){if(-1!=(" "+(t.getAttribute("class")||"")+" ").indexOf(" injectionDiv ")){this.injectionDiv_=t;break}t=t.parentNode}return this.injectionDiv_},T.WorkspaceSvg.prototype.getBlockCanvas=function(){return this.svgBlockCanvas_},T.WorkspaceSvg.prototype.setResizeHandlerWrapper=function(t){this.resizeHandlerWrapper_=t},T.WorkspaceSvg.prototype.createDom=function(t){return this.svgGroup_=T.utils.dom.createSvgElement(T.utils.Svg.G,{class:"blocklyWorkspace"},null),t&&(this.svgBackground_=T.utils.dom.createSvgElement(T.utils.Svg.RECT,{height:"100%",width:"100%",class:t},this.svgGroup_),"blocklyMainBackground"==t&&this.grid_?this.svgBackground_.style.fill="url(#"+this.grid_.getPatternId()+")":this.themeManager_.subscribe(this.svgBackground_,"workspaceBackgroundColour","fill")),this.svgBlockCanvas_=T.utils.dom.createSvgElement(T.utils.Svg.G,{class:"blocklyBlockCanvas"},this.svgGroup_),this.svgBubbleCanvas_=T.utils.dom.createSvgElement(T.utils.Svg.G,{class:"blocklyBubbleCanvas"},this.svgGroup_),this.isFlyout||(T.browserEvents.conditionalBind(this.svgGroup_,"mousedown",this,this.onMouseDown_,!1,!0),T.browserEvents.conditionalBind(this.svgGroup_,"wheel",this,this.onMouseWheel_)),this.options.hasCategories&&(this.toolbox_=new(T.registry.getClassFromOptions(T.registry.Type.TOOLBOX,this.options,!0))(this)),this.grid_&&this.grid_.update(this.scale),this.recordDeleteAreas(),(t=T.registry.getClassFromOptions(T.registry.Type.CURSOR,this.options))&&this.markerManager_.setCursor(new t),this.renderer_.createDom(this.svgGroup_,this.getTheme()),this.svgGroup_},T.WorkspaceSvg.prototype.dispose=function(){var t;this.rendered=!1,this.currentGesture_&&this.currentGesture_.cancel(),this.svgGroup_&&(T.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null),this.svgBubbleCanvas_=this.svgBlockCanvas_=null,this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null),this.flyout_&&(this.flyout_.dispose(),this.flyout_=null),this.trashcan&&(this.trashcan.dispose(),this.trashcan=null),this.scrollbar&&(this.scrollbar.dispose(),this.scrollbar=null),this.zoomControls_&&(this.zoomControls_.dispose(),this.zoomControls_=null),this.audioManager_&&(this.audioManager_.dispose(),this.audioManager_=null),this.grid_&&(this.grid_.dispose(),this.grid_=null),this.renderer_.dispose(),this.markerManager_&&(this.markerManager_.dispose(),this.markerManager_=null),T.WorkspaceSvg.superClass_.dispose.call(this),this.themeManager_&&(this.themeManager_.unsubscribeWorkspace(this),this.themeManager_.unsubscribe(this.svgBackground_),this.options.parentWorkspace||(this.themeManager_.dispose(),this.themeManager_=null)),this.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=this.connectionDBList=null,this.options.parentWorkspace||(t=this.getParentSvg())&&t.parentNode&&T.utils.dom.removeNode(t.parentNode),this.resizeHandlerWrapper_&&(T.browserEvents.unbind(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)},T.WorkspaceSvg.prototype.newBlock=function(t,e){return new T.BlockSvg(this,t,e)},T.WorkspaceSvg.prototype.addTrashcan=function(){if(!T.Trashcan)throw Error("Missing require for Blockly.Trashcan");this.trashcan=new T.Trashcan(this);var t=this.trashcan.createDom();this.svgGroup_.insertBefore(t,this.svgBlockCanvas_),this.pluginManager_.addPlugin({id:"trashcan",plugin:this.trashcan,weight:1,types:[T.PluginManager.Type.POSITIONABLE]})},T.WorkspaceSvg.prototype.addZoomControls=function(){if(!T.ZoomControls)throw Error("Missing require for Blockly.ZoomControls");this.zoomControls_=new T.ZoomControls(this);var t=this.zoomControls_.createDom();this.svgGroup_.appendChild(t),this.pluginManager_.addPlugin({id:"zoomControls",plugin:this.zoomControls_,weight:2,types:[T.PluginManager.Type.POSITIONABLE]})},T.WorkspaceSvg.prototype.addFlyout=function(t){var e=new T.Options({parentWorkspace:this,rtl:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,renderer:this.options.renderer,rendererOverrides:this.options.rendererOverrides,move:{scrollbars:!0}});return e.toolboxPosition=this.options.toolboxPosition,this.flyout_=new(this.horizontalLayout?T.registry.getClassFromOptions(T.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX,this.options,!0):T.registry.getClassFromOptions(T.registry.Type.FLYOUTS_VERTICAL_TOOLBOX,this.options,!0))(e),this.flyout_.autoClose=!1,this.flyout_.getWorkspace().setVisible(!0),this.flyout_.createDom(t)},T.WorkspaceSvg.prototype.getFlyout=function(t){return this.flyout_||t?this.flyout_:this.toolbox_?this.toolbox_.getFlyout():null},T.WorkspaceSvg.prototype.getToolbox=function(){return this.toolbox_},T.WorkspaceSvg.prototype.updateScreenCalculations_=function(){this.updateInverseScreenCTM(),this.recordDeleteAreas()},T.WorkspaceSvg.prototype.resizeContents=function(){this.resizesEnabled_&&this.rendered&&(this.scrollbar&&this.scrollbar.resize(),this.updateInverseScreenCTM())},T.WorkspaceSvg.prototype.resize=function(){this.toolbox_&&this.toolbox_.position(),this.flyout_&&this.flyout_.position();for(var t=this.pluginManager_.getPlugins(T.PluginManager.Type.POSITIONABLE,!0),e=this.getMetricsManager().getUiMetrics(),o=[],i=0,s;s=t[i];i++)s.position(e,o),o.push(s.getBoundingRectangle());this.scrollbar&&this.scrollbar.resize(),this.updateScreenCalculations_()},T.WorkspaceSvg.prototype.updateScreenCalculationsIfScrolled=function(){var t=T.utils.getDocumentScroll();T.utils.Coordinate.equals(this.lastRecordedPageScroll_,t)||(this.lastRecordedPageScroll_=t,this.updateScreenCalculations_())},T.WorkspaceSvg.prototype.getCanvas=function(){return this.svgBlockCanvas_},T.WorkspaceSvg.prototype.setCachedParentSvgSize=function(t,e){var o=this.getParentSvg();t&&(this.cachedParentSvgSize_.width=t,o.cachedWidth_=t),e&&(this.cachedParentSvgSize_.height=e,o.cachedHeight_=e)},T.WorkspaceSvg.prototype.getBubbleCanvas=function(){return this.svgBubbleCanvas_},T.WorkspaceSvg.prototype.getParentSvg=function(){if(!this.cachedParentSvg_)for(var t=this.svgGroup_;t;){if("svg"==t.tagName){this.cachedParentSvg_=t;break}t=t.parentNode}return this.cachedParentSvg_},T.WorkspaceSvg.prototype.maybeFireViewportChangeEvent=function(){var t,e,o,i;T.Events.isEnabled()&&(t=this.scale,e=-this.scrollY,o=-this.scrollX,t==this.oldScale_&&Math.abs(e-this.oldTop_)<1&&Math.abs(o-this.oldLeft_)<1||(i=new(T.Events.get(T.Events.VIEWPORT_CHANGE))(e,o,t,this.id,this.oldScale_),this.oldScale_=t,this.oldTop_=e,this.oldLeft_=o,T.Events.fire(i)))},T.WorkspaceSvg.prototype.translate=function(t,e){var o;this.useWorkspaceDragSurface_&&this.isDragSurfaceActive_?this.workspaceDragSurface_.translateSurface(t,e):(o="translate("+t+","+e+") scale("+this.scale+")",this.svgBlockCanvas_.setAttribute("transform",o),this.svgBubbleCanvas_.setAttribute("transform",o)),this.blockDragSurface_&&this.blockDragSurface_.translateAndScaleGroup(t,e,this.scale),this.grid_&&this.grid_.moveTo(t,e),this.maybeFireViewportChangeEvent()},T.WorkspaceSvg.prototype.resetDragSurface=function(){var t;this.useWorkspaceDragSurface_&&(this.isDragSurfaceActive_=!1,t=this.workspaceDragSurface_.getSurfaceTranslation(),this.workspaceDragSurface_.clearAndHide(this.svgGroup_),t="translate("+t.x+","+t.y+") scale("+this.scale+")",this.svgBlockCanvas_.setAttribute("transform",t),this.svgBubbleCanvas_.setAttribute("transform",t))},T.WorkspaceSvg.prototype.setupDragSurface=function(){var t,e,o,i;this.useWorkspaceDragSurface_&&!this.isDragSurfaceActive_&&(this.isDragSurfaceActive_=!0,t=this.svgBlockCanvas_.previousSibling,e=parseInt(this.getParentSvg().getAttribute("width"),10),o=parseInt(this.getParentSvg().getAttribute("height"),10),i=T.utils.getRelativeXY(this.getCanvas()),this.workspaceDragSurface_.setContentsAndShow(this.getCanvas(),this.getBubbleCanvas(),t,e,o,this.scale),this.workspaceDragSurface_.translateSurface(i.x,i.y))},T.WorkspaceSvg.prototype.getBlockDragSurface=function(){return this.blockDragSurface_},T.WorkspaceSvg.prototype.getWidth=function(){var t=this.getMetrics();return t?t.viewWidth/this.scale:0},T.WorkspaceSvg.prototype.setVisible=function(t){if(this.isVisible_=t,this.svgGroup_)if(this.scrollbar&&this.scrollbar.setContainerVisible(t),this.getFlyout()&&this.getFlyout().setContainerVisible(t),this.getParentSvg().style.display=t?"block":"none",this.toolbox_&&this.toolbox_.setVisible(t),t){for(var e=(t=this.getAllBlocks(!1)).length-1;0<=e;e--)t[e].markDirty();this.render(),this.toolbox_&&this.toolbox_.position()}else T.hideChaff(!0)},T.WorkspaceSvg.prototype.render=function(){for(var t=this.getAllBlocks(!1),e=t.length-1;0<=e;e--)t[e].render(!1);if(this.currentGesture_)for(t=this.currentGesture_.getInsertionMarkers(),e=0;e<t.length;e++)t[e].render(!1);this.markerManager_.updateMarkers()},T.WorkspaceSvg.prototype.highlightBlock=function(t,e){if(void 0===e){for(var o=0,i;i=this.highlightedBlocks_[o];o++)i.setHighlighted(!1);this.highlightedBlocks_.length=0}(i=t?this.getBlockById(t):null)&&((t=void 0===e||e)?-1==this.highlightedBlocks_.indexOf(i)&&this.highlightedBlocks_.push(i):T.utils.arrayRemove(this.highlightedBlocks_,i),i.setHighlighted(t))},T.WorkspaceSvg.prototype.paste=function(t){!this.rendered||!t.tagName||t.getElementsByTagName("block").length>=this.remainingCapacity()||(this.currentGesture_&&this.currentGesture_.cancel(),"comment"==t.tagName.toLowerCase()?this.pasteWorkspaceComment_(t):this.pasteBlock_(t))},T.WorkspaceSvg.prototype.pasteBlock_=function(t){T.Events.disable();try{var e=T.Xml.domToBlock(t,this),o=parseInt(t.getAttribute("x"),10),i=parseInt(t.getAttribute("y"),10);if(!isNaN(o)&&!isNaN(i)){this.RTL&&(o=-o);do{t=!1;for(var s=this.getAllBlocks(!1),n=0,r;r=s[n];n++){var l=r.getRelativeToSurfaceXY();if(Math.abs(o-l.x)<=1&&Math.abs(i-l.y)<=1){t=!0;break}}if(!t)for(var a=e.getConnections_(!1),n=0,c;c=a[n];n++)if(c.closest(T.SNAP_RADIUS,new T.utils.Coordinate(o,i)).connection){t=!0;break}t&&(o=this.RTL?o-T.SNAP_RADIUS:o+T.SNAP_RADIUS,i+=2*T.SNAP_RADIUS)}while(t);e.moveBy(o,i)}}finally{T.Events.enable()}T.Events.isEnabled()&&!e.isShadow()&&T.Events.fire(new(T.Events.get(T.Events.BLOCK_CREATE))(e)),e.select()},T.WorkspaceSvg.prototype.pasteWorkspaceComment_=function(t){T.Events.disable();try{var e=T.WorkspaceCommentSvg.fromXml(t,this),o=parseInt(t.getAttribute("x"),10),i=parseInt(t.getAttribute("y"),10);isNaN(o)||isNaN(i)||(this.RTL&&(o=-o),e.moveBy(o+50,i+50))}finally{T.Events.enable()}T.Events.isEnabled()&&T.WorkspaceComment.fireCreateEvent(e),e.select()},T.WorkspaceSvg.prototype.refreshToolboxSelection=function(){var t=this.isFlyout?this.targetWorkspace:this;t&&!t.currentGesture_&&t.toolbox_&&t.toolbox_.getFlyout()&&t.toolbox_.refreshSelection()},T.WorkspaceSvg.prototype.renameVariableById=function(t,e){T.WorkspaceSvg.superClass_.renameVariableById.call(this,t,e),this.refreshToolboxSelection()},T.WorkspaceSvg.prototype.deleteVariableById=function(t){T.WorkspaceSvg.superClass_.deleteVariableById.call(this,t),this.refreshToolboxSelection()},T.WorkspaceSvg.prototype.createVariable=function(t,e,o){return t=T.WorkspaceSvg.superClass_.createVariable.call(this,t,e,o),this.refreshToolboxSelection(),t},T.WorkspaceSvg.prototype.recordDeleteAreas=function(){this.deleteAreaTrash_=this.trashcan&&this.svgGroup_.parentNode?this.trashcan.getClientRect():null,this.deleteAreaToolbox_=this.flyout_?this.flyout_.getClientRect():this.toolbox_&&"function"==typeof this.toolbox_.getClientRect?this.toolbox_.getClientRect():null},T.WorkspaceSvg.prototype.isDeleteArea=function(t){return this.deleteAreaTrash_&&this.deleteAreaTrash_.contains(t.clientX,t.clientY)?T.DELETE_AREA_TRASH:this.deleteAreaToolbox_&&this.deleteAreaToolbox_.contains(t.clientX,t.clientY)?T.DELETE_AREA_TOOLBOX:T.DELETE_AREA_NONE},T.WorkspaceSvg.prototype.onMouseDown_=function(t){var e=this.getGesture(t);e&&e.handleWsStart(t,this)},T.WorkspaceSvg.prototype.startDrag=function(t,e){(t=T.utils.mouseToSvg(t,this.getParentSvg(),this.getInverseScreenCTM())).x/=this.scale,t.y/=this.scale,this.dragDeltaXY_=T.utils.Coordinate.difference(e,t)},T.WorkspaceSvg.prototype.moveDrag=function(t){return(t=T.utils.mouseToSvg(t,this.getParentSvg(),this.getInverseScreenCTM())).x/=this.scale,t.y/=this.scale,T.utils.Coordinate.sum(this.dragDeltaXY_,t)},T.WorkspaceSvg.prototype.isDragging=function(){return null!=this.currentGesture_&&this.currentGesture_.isDragging()},T.WorkspaceSvg.prototype.isDraggable=function(){return this.options.moveOptions&&this.options.moveOptions.drag},T.WorkspaceSvg.prototype.isMovable=function(){return this.options.moveOptions&&!!this.options.moveOptions.scrollbars||this.options.moveOptions&&this.options.moveOptions.wheel||this.options.moveOptions&&this.options.moveOptions.drag||this.options.zoomOptions&&this.options.zoomOptions.wheel||this.options.zoomOptions&&this.options.zoomOptions.pinch},T.WorkspaceSvg.prototype.isMovableHorizontally=function(){var t=!!this.scrollbar;return this.isMovable()&&(!t||t&&this.scrollbar.canScrollHorizontally())},