diff --git a/blockly_accessible_compressed.js b/blockly_accessible_compressed.js index b58003a0b..82578834f 100644 --- a/blockly_accessible_compressed.js +++ b/blockly_accessible_compressed.js @@ -878,37 +878,35 @@ var Blockly={};Blockly.Blocks=Object(null); Blockly.utils={};Blockly.utils.Coordinate=function(a,b){this.x=a;this.y=b};Blockly.utils.Coordinate.equals=function(a,b){return a==b?!0:a&&b?a.x==b.x&&a.y==b.y:!1};Blockly.utils.Coordinate.distance=function(a,b){var c=a.x-b.x;a=a.y-b.y;return Math.sqrt(c*c+a*a)};Blockly.utils.Coordinate.magnitude=function(a){return Math.sqrt(a.x*a.x+a.y*a.y)};Blockly.utils.Coordinate.difference=function(a,b){return new Blockly.utils.Coordinate(a.x-b.x,a.y-b.y)}; Blockly.utils.Coordinate.sum=function(a,b){return new Blockly.utils.Coordinate(a.x+b.x,a.y+b.y)};Blockly.utils.Coordinate.prototype.scale=function(a){this.x*=a;this.y*=a;return this};Blockly.utils.Coordinate.prototype.translate=function(a,b){this.x+=a;this.y+=b;return this};Blockly.Msg={};goog.getMsgOrig=goog.getMsg;goog.getMsg=function(a,b){var c=goog.getMsg.blocklyMsgMap[a];c&&(a=Blockly.Msg[c]);return goog.getMsgOrig(a,b)};goog.getMsg.blocklyMsgMap={Today:"TODAY"};Blockly.userAgent={}; (function(a){function b(a){return-1!=c.indexOf(a.toUpperCase())}Blockly.userAgent.raw=a;var c=Blockly.userAgent.raw.toUpperCase();Blockly.userAgent.IE=b("Trident")||b("MSIE");Blockly.userAgent.EDGE=b("Edge");Blockly.userAgent.JAVA_FX=b("JavaFX");Blockly.userAgent.WEBKIT=b("WebKit")&&!Blockly.userAgent.EDGE;Blockly.userAgent.GECKO=b("Gecko")&&!Blockly.userAgent.WEBKIT&&!Blockly.userAgent.IE&&!Blockly.userAgent.EDGE;Blockly.userAgent.ANDROID=b("Android");Blockly.userAgent.IPAD=b("iPad");Blockly.userAgent.IPOD= -b("iPod");Blockly.userAgent.IPHONE=b("iPhone")&&!Blockly.userAgent.IPAD&&!Blockly.userAgent.IPOD;Blockly.userAgent.MAC=b("Macintosh");Blockly.userAgent.TABLET=Blockly.userAgent.IPAD||Blockly.userAgent.ANDROID&&!b("Mobile")||b("Silk");Blockly.userAgent.MOBILE=!Blockly.userAgent.TABLET&&(Blockly.userAgent.IPOD||Blockly.userAgent.IPHONE||Blockly.userAgent.ANDROID||b("IEMobile"))})(this.navigator&&this.navigator.userAgent||""); -Blockly.utils.addClass=function(a,b){var c=a.getAttribute("class")||"";if(-1!=(" "+c+" ").indexOf(" "+b+" "))return!1;c&&(c+=" ");a.setAttribute("class",c+b);return!0};Blockly.utils.removeClass=function(a,b){var c=a.getAttribute("class");if(-1==(" "+c+" ").indexOf(" "+b+" "))return!1;c=c.split(/\s+/);for(var d=0;db&&(b=c[d].length);d=-Infinity;var e=1;do{var f=d;var g=a;a=[];var h=c.length/e,k=1;for(d=0;df);return g}; +Blockly.utils.string.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;fd&&(d=h,e=g)}return e?Blockly.utils.string.wrapMutate_(a,e,c):b};Blockly.utils.string.wrapToText_=function(a,b){for(var c=[],d=0;d=h?(e=2,f=h,(h=a.join(""))&&c.push(h),a.length=0):"{"==h?e=3:(a.push("%",h),e=0):2==e?"0"<=h&&"9">=h?f+=h:(c.push(parseInt(f,10)),g--,e=0):3==e&&(""==h?(a.splice(0,0,"%{"),g--,e=0):"}"!=h?a.push(h):(e=a.join(""),/[a-zA-Z][a-zA-Z0-9_]*/.test(e)?(h=e.toUpperCase(), -(h=Blockly.utils.startsWith(h,"BKY_")?h.substring(4):null)&&h in Blockly.Msg?(e=Blockly.Msg[h],"string"==typeof e?Array.prototype.push.apply(c,Blockly.utils.tokenizeInterpolation_(e,b)):b?c.push(String(e)):c.push(e)):c.push("%{"+e+"}")):c.push("%{"+e+"}"),e=a.length=0))}(h=a.join(""))&&c.push(h);b=[];for(g=a.length=0;gc;c++)b[c]=Blockly.utils.genUid.soup_.charAt(Math.random()*a);return b.join("")};Blockly.utils.genUid.soup_="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";Blockly.utils.wrap=function(a,b){a=a.split("\n");for(var c=0;cb&&(b=c[d].length);d=-Infinity;var e=1;do{var f=d;var g=a;a=[];var h=c.length/e,k=1;for(d=0;df);return g}; -Blockly.utils.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;fd&&(d=h,e=g)}return e?Blockly.utils.wrapMutate_(a,e,c):b};Blockly.utils.wrapToText_=function(a,b){for(var c=[],d=0;dc;c++)b[c]=Blockly.utils.genUid.soup_.charAt(Math.random()*a);return b.join("")};Blockly.utils.genUid.soup_="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Blockly.utils.is3dSupported=function(){if(void 0!==Blockly.utils.is3dSupported.cached_)return Blockly.utils.is3dSupported.cached_;if(!Blockly.utils.global.getComputedStyle)return!1;var a=document.createElement("p"),b="none",c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(a,null);for(var d in c)if(void 0!==a.style[d]){a.style[d]="translate3d(1px,1px,1px)";b=Blockly.utils.global.getComputedStyle(a); -if(!b)return document.body.removeChild(a),!1;b=b.getPropertyValue(c[d])}document.body.removeChild(a);Blockly.utils.is3dSupported.cached_="none"!==b;return Blockly.utils.is3dSupported.cached_};Blockly.utils.insertAfter=function(a,b){var c=b.nextSibling;b=b.parentNode;if(!b)throw Error("Reference node has no parent.");c?b.insertBefore(a,c):b.appendChild(a)}; -Blockly.utils.runAfterPageLoad=function(a){if("object"!=typeof document)throw Error("Blockly.utils.runAfterPageLoad() requires browser document.");if("complete"==document.readyState)a();else var b=setInterval(function(){"complete"==document.readyState&&(clearInterval(b),a())},10)};Blockly.utils.setCssTransform=function(a,b){a.style.transform=b;a.style["-webkit-transform"]=b}; -Blockly.utils.getViewportBBox=function(){var a=goog.style.getViewportPageOffset(document);return{right:document.documentElement.clientWidth+a.x,bottom:document.documentElement.clientHeight+a.y,top:a.y,left:a.x}};Blockly.utils.startsWith=function(a,b){return 0==a.lastIndexOf(b,0)};Blockly.utils.arrayRemove=function(a,b){b=a.indexOf(b);if(-1==b)return!1;a.splice(b,1);return!0};Blockly.utils.toRadians=function(a){return a*Math.PI/180};Blockly.utils.toDegrees=function(a){return 180*a/Math.PI}; -Blockly.utils.containsNode=function(a,b){return!!(a.compareDocumentPosition(b)&Node.DOCUMENT_POSITION_CONTAINED_BY)};Blockly.utils.getDocumentScroll=function(){var a=document.documentElement,b=window;return Blockly.userAgent.IE&&b.pageYOffset!=a.scrollTop?new Blockly.utils.Coordinate(a.scrollLeft,a.scrollTop):new Blockly.utils.Coordinate(b.pageXOffset||a.scrollLeft,b.pageYOffset||a.scrollTop)}; -Blockly.utils.getBlockTypeCounts=function(a,b){var c=Object.create(null),d=a.getDescendants(!0);b&&(a=a.getNextBlock())&&(a=d.indexOf(a),d.splice(a,d.length-a));for(a=0;b=d[a];a++)c[b.type]?c[b.type]++:c[b.type]=1;return c};Blockly.utils.clampNumber=function(a,b,c){if(c"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=Blockly.Xml.utils.textToDomDocument(a);if(!a||!a.documentElement||"xml"!=a.documentElement.nodeName.toLowerCase())throw TypeError("Blockly.Xml.textToDom expected an document.");return a.documentElement};Blockly.Xml.clearWorkspaceAndLoadFromXml=function(a,b){b.setResizesEnabled(!1);b.clear();a=Blockly.Xml.domToWorkspace(a,b);b.setResizesEnabled(!0);return a}; Blockly.Xml.domToWorkspace=function(a,b){if(a instanceof Blockly.Workspace){var c=a;a=b;b=c;console.warn("Deprecated call to Blockly.Xml.domToWorkspace, swap the arguments.")}var d;b.RTL&&(d=b.getWidth());c=[];Blockly.Field.startCache();var e=a.childNodes.length,f=Blockly.Events.getGroup();f||Blockly.Events.setGroup(!0);b.setResizesEnabled&&b.setResizesEnabled(!1);var g=!0;try{for(var h=0;hthis.MAX_UNDO&&0<=this.MAX_UNDO;)this.undoStack_.shift();for(var b=0,c;c=this.listeners_[b];b++)c(a)}; Blockly.Workspace.prototype.getBlockById=function(a){return this.blockDB_[a]||null};Blockly.Workspace.prototype.getCommentById=function(a){return this.commentDB_[a]||null};Blockly.Workspace.prototype.allInputsFilled=function(a){for(var b=this.getTopBlocks(!1),c=0,d;d=b[c];c++)if(!d.allInputsFilled(a))return!1;return!0};Blockly.Workspace.prototype.getPotentialVariableMap=function(){return this.potentialVariableMap_}; Blockly.Workspace.prototype.createPotentialVariableMap=function(){this.potentialVariableMap_=new Blockly.VariableMap(this)};Blockly.Workspace.prototype.getVariableMap=function(){return this.variableMap_};Blockly.Workspace.WorkspaceDB_=Object.create(null);Blockly.Workspace.getById=function(a){return Blockly.Workspace.WorkspaceDB_[a]||null};Blockly.Workspace.getAll=function(){var a=[],b;for(b in Blockly.Workspace.WorkspaceDB_)a.push(Blockly.Workspace.WorkspaceDB_[b]);return a}; -Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Workspace.prototype.clearUndo=Blockly.Workspace.prototype.clearUndo;Blockly.Workspace.prototype.addChangeListener=Blockly.Workspace.prototype.addChangeListener;Blockly.Workspace.prototype.removeChangeListener=Blockly.Workspace.prototype.removeChangeListener;Blockly.Bubble=function(a,b,c,d,e,f){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=Blockly.utils.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!e||!f)));this.setAnchorLocation(d);e&&f||(b=this.content_.getBBox(),e=b.width+2*Blockly.Bubble.BORDER_WIDTH,f=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(e,f);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly||(Blockly.bindEventWithChecks_(this.bubbleBack_, -"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEventWithChecks_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=5;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null;Blockly.Bubble.prototype.resizeCallback_=null; +Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Workspace.prototype.clearUndo=Blockly.Workspace.prototype.clearUndo;Blockly.Workspace.prototype.addChangeListener=Blockly.Workspace.prototype.addChangeListener;Blockly.Workspace.prototype.removeChangeListener=Blockly.Workspace.prototype.removeChangeListener;Blockly.Bubble=function(a,b,c,d,e,f){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=Blockly.utils.math.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!e||!f)));this.setAnchorLocation(d);e&&f||(b=this.content_.getBBox(),e=b.width+2*Blockly.Bubble.BORDER_WIDTH,f=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(e,f);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly|| +(Blockly.bindEventWithChecks_(this.bubbleBack_,"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEventWithChecks_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=5;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null;Blockly.Bubble.prototype.resizeCallback_=null; Blockly.Bubble.unbindDragEvents_=function(){Blockly.Bubble.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_),Blockly.Bubble.onMouseUpWrapper_=null);Blockly.Bubble.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_),Blockly.Bubble.onMouseMoveWrapper_=null)};Blockly.Bubble.bubbleMouseUp_=function(){Blockly.Touch.clearTouchIdentifier();Blockly.Bubble.unbindDragEvents_()};Blockly.Bubble.prototype.rendered_=!1;Blockly.Bubble.prototype.anchorXY_=null; Blockly.Bubble.prototype.relativeLeft_=0;Blockly.Bubble.prototype.relativeTop_=0;Blockly.Bubble.prototype.width_=0;Blockly.Bubble.prototype.height_=0;Blockly.Bubble.prototype.autoLayout_=!0; Blockly.Bubble.prototype.createDom_=function(a,b){this.bubbleGroup_=Blockly.utils.createSvgElement("g",{},null);var c={filter:"url(#"+this.workspace_.options.embossFilterId+")"};Blockly.userAgent.JAVA_FX&&(c={});c=Blockly.utils.createSvgElement("g",c,this.bubbleGroup_);this.bubbleArrow_=Blockly.utils.createSvgElement("path",{},c);this.bubbleBack_=Blockly.utils.createSvgElement("rect",{"class":"blocklyDraggable",x:0,y:0,rx:Blockly.Bubble.BORDER_WIDTH,ry:Blockly.Bubble.BORDER_WIDTH},c);b?(this.resizeGroup_= @@ -1031,11 +1029,12 @@ Blockly.Bubble.prototype.setBubbleSize=function(a,b){var c=2*Blockly.Bubble.BORD this.layoutBubble_(),this.positionBubble_(),this.renderArrow_());this.resizeCallback_&&this.resizeCallback_()}; Blockly.Bubble.prototype.renderArrow_=function(){var a=[],b=this.width_/2,c=this.height_/2,d=-this.relativeLeft_,e=-this.relativeTop_;if(b==d&&c==e)a.push("M "+b+","+c);else{e-=c;d-=b;this.workspace_.RTL&&(d*=-1);var f=Math.sqrt(e*e+d*d),g=Math.acos(d/f);0>e&&(g=2*Math.PI-g);var h=g+Math.PI/2;h>2*Math.PI&&(h-=2*Math.PI);var k=Math.sin(h),l=Math.cos(h),n=this.getBubbleSize();h=(n.width+n.height)/Blockly.Bubble.ARROW_THICKNESS;h=Math.min(h,n.width,n.height)/4;n=1-Blockly.Bubble.ANCHOR_RADIUS/f;d=b+ n*d;e=c+n*e;n=b+h*l;var m=c+h*k;b-=h*l;c-=h*k;k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+n+","+m);a.push("C"+(n+f)+","+(m+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)}; -Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();Blockly.utils.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.resizeGroup_=this.bubbleBack_=this.bubbleArrow_=this.bubbleGroup_=null};Blockly.Bubble.prototype.moveDuringDrag=function(a,b){a?a.translateSurface(b.x,b.y):this.moveTo(b.x,b.y);this.relativeLeft_=this.workspace_.RTL?this.anchorXY_.x-b.x-this.width_:b.x-this.anchorXY_.x;this.relativeTop_=b.y-this.anchorXY_.y;this.renderArrow_()}; +Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();Blockly.utils.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.resizeGroup_=this.bubbleBack_=this.bubbleArrow_=this.bubbleGroup_=null};Blockly.Bubble.prototype.moveDuringDrag=function(a,b){a?a.translateSurface(b.x,b.y):this.moveTo(b.x,b.y);this.relativeLeft_=this.workspace_.RTL?this.anchorXY_.x-b.x-this.width_:b.x-this.anchorXY_.x;this.relativeTop_=b.y-this.anchorXY_.y;this.renderArrow_()}; Blockly.Bubble.prototype.getRelativeToSurfaceXY=function(){return new Blockly.utils.Coordinate(this.anchorXY_.x+this.relativeLeft_,this.anchorXY_.y+this.relativeTop_)};Blockly.Bubble.prototype.setAutoLayout=function(a){this.autoLayout_=a};Blockly.Events.Ui=function(a,b,c,d){Blockly.Events.Ui.superClass_.constructor.call(this);this.blockId=a?a.id:null;this.workspaceId=a?a.workspace.id:null;this.element=b;this.oldValue=c;this.newValue=d;this.recordUndo=!1};goog.inherits(Blockly.Events.Ui,Blockly.Events.Abstract);Blockly.Events.Ui.prototype.type=Blockly.Events.UI; Blockly.Events.Ui.prototype.toJson=function(){var a=Blockly.Events.Ui.superClass_.toJson.call(this);a.element=this.element;void 0!==this.newValue&&(a.newValue=this.newValue);this.blockId&&(a.blockId=this.blockId);return a};Blockly.Events.Ui.prototype.fromJson=function(a){Blockly.Events.Ui.superClass_.fromJson.call(this,a);this.element=a.element;this.newValue=a.newValue;this.blockId=a.blockId};Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.collapseHidden=!0;Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconXY_=null; -Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyIconGroup"},null),this.block_.isInFlyout&&Blockly.utils.addClass(this.iconGroup_,"blocklyIconGroupReadonly"),this.drawIcon_(this.iconGroup_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEventWithChecks_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())}; -Blockly.Icon.prototype.dispose=function(){Blockly.utils.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_};Blockly.Icon.prototype.iconClick_=function(a){this.block_.workspace.isDragging()||this.block_.isInFlyout||Blockly.utils.isRightButton(a)||this.setVisible(!this.isVisible())};Blockly.Icon.prototype.updateColour=function(){this.isVisible()&&this.bubble_.setColour(this.block_.getColour())}; +Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyIconGroup"},null),this.block_.isInFlyout&&Blockly.utils.dom.addClass(this.iconGroup_,"blocklyIconGroupReadonly"),this.drawIcon_(this.iconGroup_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEventWithChecks_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())}; +Blockly.Icon.prototype.dispose=function(){Blockly.utils.dom.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_};Blockly.Icon.prototype.iconClick_=function(a){this.block_.workspace.isDragging()||this.block_.isInFlyout||Blockly.utils.isRightButton(a)||this.setVisible(!this.isVisible())}; +Blockly.Icon.prototype.updateColour=function(){this.isVisible()&&this.bubble_.setColour(this.block_.getColour())}; Blockly.Icon.prototype.renderIcon=function(a){if(this.collapseHidden&&this.block_.isCollapsed()||this.block_.isInsertionMarker())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+",5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)}; Blockly.Icon.prototype.setIconLocation=function(a){this.iconXY_=a;this.isVisible()&&this.bubble_.setAnchorLocation(a)};Blockly.Icon.prototype.computeIconLocation=function(){var a=this.block_.getRelativeToSurfaceXY(),b=Blockly.utils.getRelativeXY(this.iconGroup_);a=new Blockly.utils.Coordinate(a.x+b.x+this.SIZE/2,a.y+b.y+this.SIZE/2);Blockly.utils.Coordinate.equals(this.getIconLocation(),a)||this.setIconLocation(a)};Blockly.Icon.prototype.getIconLocation=function(){return this.iconXY_}; Blockly.Comment=function(a){Blockly.Comment.superClass_.constructor.call(this,a);this.createIcon()};goog.inherits(Blockly.Comment,Blockly.Icon);Blockly.Comment.prototype.text_="";Blockly.Comment.prototype.width_=160;Blockly.Comment.prototype.height_=80; @@ -1065,7 +1064,7 @@ Blockly.Connection.prototype.disconnect=function(){var a=this.targetConnection;i Blockly.Connection.prototype.disconnectInternal_=function(a,b){var c;Blockly.Events.isEnabled()&&(c=new Blockly.Events.BlockMove(b));this.targetConnection=this.targetConnection.targetConnection=null;b.setParent(null);c&&(c.recordNew(),Blockly.Events.fire(c))}; Blockly.Connection.prototype.respawnShadow_=function(){var a=this.getSourceBlock(),b=this.getShadowDom();if(a.workspace&&b&&Blockly.Events.recordUndo)if(a=Blockly.Xml.domToBlock(b,a.workspace),a.outputConnection)this.connect(a.outputConnection);else if(a.previousConnection)this.connect(a.previousConnection);else throw Error("Child block does not have output or previous statement.");}; Blockly.Connection.prototype.targetBlock=function(){return this.isConnected()?this.targetConnection.getSourceBlock():null};Blockly.Connection.prototype.checkType_=function(a){if(!this.check_||!a.check_)return!0;for(var b=0;b=this.connections_.length)return-1;for(var c=a.y_,d=b;0<=d&&this.connections_[d].y_==c;){if(this.connections_[d]==a)return d;d--}for(;bc)){var d=b.getSvgXY(a.getSvgRoot());a.outputConnection?(d.x+=(a.RTL?3:-3)*c,d.y+=13*c):a.previousConnection&&(d.x+=(a.RTL?-23:23)*c,d.y+=3*c);a=Blockly.utils.createSvgElement("circle",{cx:d.x,cy:d.y,r:0,fill:"none",stroke:"#888","stroke-width":10},b.getParentSvg());Blockly.BlockAnimations.connectionUiStep_(a,new Date,c)}}; -Blockly.BlockAnimations.connectionUiStep_=function(a,b,c){var d=(new Date-b)/150;1a.workspace.scale)){var b=a.getHeightWidth().height;b=Math.atan(10/b)/Math.PI*180;a.RTL||(b*=-1);Blockly.BlockAnimations.disconnectUiStep_(a.getSvgRoot(),b,new Date)}}; Blockly.BlockAnimations.disconnectUiStep_=function(a,b,c){var d=(new Date-c)/200;1b?!1:Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this,a)}; Blockly.RenderedConnection.prototype.connect=function(a){Blockly.RenderedConnection.superClass_.connect.call(this,a);if(this.hidden_||a.hidden_){a=this.isSuperior()?this:a;a.hidden_?a.hideAll():a.unhideAll();var b=a.targetBlock(),c=a.hidden_?"none":"block";b.getSvgRoot().style.display=c;b.rendered=!a.hidden_}}; Blockly.RenderedConnection.prototype.disconnect=function(){var a=this.isSuperior()?this:this.targetConnection;if(this.targetConnection&&a.hidden_){a.unhideAll();var b=a.targetBlock();b.getSvgRoot().style.display="block";b.rendered=!0;a.setHidden(!0)}Blockly.RenderedConnection.superClass_.disconnect.call(this)}; @@ -1129,20 +1128,20 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_=function(){this.woul Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_=function(a){a=new Blockly.utils.Coordinate(a.x/this.workspace_.scale,a.y/this.workspace_.scale);this.workspace_.isMutator&&a.scale(1/this.workspace_.options.parentWorkspace.scale);return a};Blockly.BlockDragger.prototype.dragIcons_=function(a){for(var b=0;bBlockly.Tooltip.RADIUS_OK&&Blockly.Tooltip.hide()}else Blockly.Tooltip.poisonedElement_!=Blockly.Tooltip.element_&&(clearTimeout(Blockly.Tooltip.showPid_),Blockly.Tooltip.lastX_=a.pageX,Blockly.Tooltip.lastY_=a.pageY,Blockly.Tooltip.showPid_= setTimeout(Blockly.Tooltip.show_,Blockly.Tooltip.HOVER_MS))};Blockly.Tooltip.hide=function(){Blockly.Tooltip.visible&&(Blockly.Tooltip.visible=!1,Blockly.Tooltip.DIV&&(Blockly.Tooltip.DIV.style.display="none"));Blockly.Tooltip.showPid_&&clearTimeout(Blockly.Tooltip.showPid_)};Blockly.Tooltip.block=function(){Blockly.Tooltip.hide();Blockly.Tooltip.blocked_=!0};Blockly.Tooltip.unblock=function(){Blockly.Tooltip.blocked_=!1}; -Blockly.Tooltip.show_=function(){if(!Blockly.Tooltip.blocked_&&(Blockly.Tooltip.poisonedElement_=Blockly.Tooltip.element_,Blockly.Tooltip.DIV)){Blockly.Tooltip.DIV.innerHTML="";for(var a=Blockly.Tooltip.element_.tooltip;"function"==typeof a;)a=a();a=Blockly.utils.wrap(a,Blockly.Tooltip.LIMIT);a=a.split("\n");for(var b=0;bc+window.scrollY&&(e-=Blockly.Tooltip.DIV.offsetHeight+2*Blockly.Tooltip.OFFSET_Y);a?d=Math.max(Blockly.Tooltip.MARGINS-window.scrollX, d):d+Blockly.Tooltip.DIV.offsetWidth>b+window.scrollX-2*Blockly.Tooltip.MARGINS&&(d=b-Blockly.Tooltip.DIV.offsetWidth-2*Blockly.Tooltip.MARGINS);Blockly.Tooltip.DIV.style.top=e+"px";Blockly.Tooltip.DIV.style.left=d+"px"}};Blockly.Gesture=function(a,b){this.startWorkspace_=this.targetBlock_=this.startBlock_=this.startField_=this.startBubble_=this.currentDragDeltaXY_=this.mouseDownXY_=null;this.creatorWorkspace_=b;this.isDraggingBubble_=this.isDraggingBlock_=this.isDraggingWorkspace_=this.hasExceededDragRadius_=!1;this.mostRecentEvent_=a;this.flyout_=this.workspaceDragger_=this.blockDragger_=this.bubbleDragger_=this.onUpWrapper_=this.onMoveWrapper_=null;this.isEnding_=this.hasStarted_=this.calledUpdateIsDragging_=!1; this.healStack_=!Blockly.DRAG_STACK}; @@ -1191,14 +1190,14 @@ Blockly.Gesture.inProgress=function(){for(var a=Blockly.Workspace.getAll(),b=0,c Blockly.Grid.prototype.update=function(a){this.scale_=a;var b=this.spacing_*a||100;this.gridPattern_.setAttribute("width",b);this.gridPattern_.setAttribute("height",b);b=Math.floor(this.spacing_/2)+.5;var c=b-this.length_/2,d=b+this.length_/2;b*=a;c*=a;d*=a;this.setLineAttributes_(this.line1_,a,c,d,b,b);this.setLineAttributes_(this.line2_,a,b,b,c,d)}; Blockly.Grid.prototype.setLineAttributes_=function(a,b,c,d,e,f){a&&(a.setAttribute("stroke-width",b),a.setAttribute("x1",c),a.setAttribute("y1",e),a.setAttribute("x2",d),a.setAttribute("y2",f))};Blockly.Grid.prototype.moveTo=function(a,b){this.gridPattern_.setAttribute("x",a);this.gridPattern_.setAttribute("y",b);(Blockly.userAgent.IE||Blockly.userAgent.EDGE)&&this.update(this.scale_)}; Blockly.Grid.createDom=function(a,b,c){a=Blockly.utils.createSvgElement("pattern",{id:"blocklyGridPattern"+a,patternUnits:"userSpaceOnUse"},c);0=c+this.handleLength_&&(d+= e);this.setHandlePosition(this.constrainHandle_(d));this.onScroll_();a.stopPropagation();a.preventDefault()}}; @@ -1235,8 +1234,8 @@ Blockly.Trashcan.prototype.SPRITE_LEFT_=0;Blockly.Trashcan.prototype.SPRITE_TOP_ Blockly.Trashcan.prototype.createDom=function(){this.svgGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyTrash"},null);var a=String(Math.random()).substring(2);var b=Blockly.utils.createSvgElement("clipPath",{id:"blocklyTrashBodyClipPath"+a},this.svgGroup_);Blockly.utils.createSvgElement("rect",{width:this.WIDTH_,height:this.BODY_HEIGHT_,y:this.LID_HEIGHT_},b);var c=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,x:-this.SPRITE_LEFT_,height:Blockly.SPRITE.height,y:-this.SPRITE_TOP_, "clip-path":"url(#blocklyTrashBodyClipPath"+a+")"},this.svgGroup_);c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.workspace_.options.pathToMedia+Blockly.SPRITE.url);b=Blockly.utils.createSvgElement("clipPath",{id:"blocklyTrashLidClipPath"+a},this.svgGroup_);Blockly.utils.createSvgElement("rect",{width:this.WIDTH_,height:this.LID_HEIGHT_},b);this.svgLid_=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,x:-this.SPRITE_LEFT_,height:Blockly.SPRITE.height,y:-this.SPRITE_TOP_, "clip-path":"url(#blocklyTrashLidClipPath"+a+")"},this.svgGroup_);this.svgLid_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.workspace_.options.pathToMedia+Blockly.SPRITE.url);Blockly.bindEventWithChecks_(this.svgGroup_,"mouseup",this,this.click);Blockly.bindEvent_(c,"mouseover",this,this.mouseOver_);Blockly.bindEvent_(c,"mouseout",this,this.mouseOut_);this.animateLid_();return this.svgGroup_}; -Blockly.Trashcan.prototype.init=function(a){0this.minOpenness_&&1>this.lidOpen_&&(this.lidTask_=setTimeout(this.animateLid_.bind(this),20))}; @@ -1274,22 +1273,22 @@ x1:2*a/3,y1:a-1,x2:a-1,y2:2*a/3},this.resizeGroup_)}; Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_=function(){this.deleteGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyCommentDeleteIcon"},this.svgGroup_);this.deleteIconBorder_=Blockly.utils.createSvgElement("circle",{"class":"blocklyDeleteIconShape",r:"7",cx:"7.5",cy:"7.5"},this.deleteGroup_);Blockly.utils.createSvgElement("line",{x1:"5",y1:"10",x2:"10",y2:"5",stroke:"#fff","stroke-width":"2"},this.deleteGroup_);Blockly.utils.createSvgElement("line",{x1:"5",y1:"5",x2:"10",y2:"10", stroke:"#fff","stroke-width":"2"},this.deleteGroup_)}; Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_=function(a){this.unbindDragEvents_();Blockly.utils.isRightButton(a)||(this.workspace.startDrag(a,new Blockly.utils.Coordinate(this.workspace.RTL?-this.width_:this.width_,this.height_)),this.onMouseUpWrapper_=Blockly.bindEventWithChecks_(document,"mouseup",this,this.resizeMouseUp_),this.onMouseMoveWrapper_=Blockly.bindEventWithChecks_(document,"mousemove",this,this.resizeMouseMove_),Blockly.hideChaff());a.stopPropagation()}; -Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_=function(a){Blockly.utils.addClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted");a.stopPropagation()};Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_=function(){Blockly.utils.removeClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted")};Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_=function(a){this.dispose(!0,!0);a.stopPropagation()}; +Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_=function(a){Blockly.utils.dom.addClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted");a.stopPropagation()};Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_=function(a){Blockly.utils.dom.removeClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted")};Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_=function(a){this.dispose(!0,!0);a.stopPropagation()}; Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_=function(){this.onMouseUpWrapper_&&(Blockly.unbindEvent_(this.onMouseUpWrapper_),this.onMouseUpWrapper_=null);this.onMouseMoveWrapper_&&(Blockly.unbindEvent_(this.onMouseMoveWrapper_),this.onMouseMoveWrapper_=null)};Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_=function(){Blockly.Touch.clearTouchIdentifier();this.unbindDragEvents_()}; Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_=function(a){this.autoLayout_=!1;a=this.workspace.moveDrag(a);this.setSize_(this.RTL?-a.x:a.x,a.y)}; Blockly.WorkspaceCommentSvg.prototype.resizeComment_=function(){var a=this.getHeightWidth(),b=Blockly.WorkspaceCommentSvg.TOP_OFFSET,c=2*Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET;this.foreignObject_.setAttribute("width",a.width);this.foreignObject_.setAttribute("height",a.height-b);this.RTL&&this.foreignObject_.setAttribute("x",-a.width);this.textarea_.style.width=a.width-c+"px";this.textarea_.style.height=a.height-c-b+"px"}; Blockly.WorkspaceCommentSvg.prototype.setSize_=function(a,b){a=Math.max(a,45);b=Math.max(b,20+Blockly.WorkspaceCommentSvg.TOP_OFFSET);this.width_=a;this.height_=b;this.svgRect_.setAttribute("width",a);this.svgRect_.setAttribute("height",b);this.svgRectTarget_.setAttribute("width",a);this.svgRectTarget_.setAttribute("height",b);this.svgHandleTarget_.setAttribute("width",a);this.svgHandleTarget_.setAttribute("height",Blockly.WorkspaceCommentSvg.TOP_OFFSET);this.RTL&&(this.svgRect_.setAttribute("transform", "scale(-1 1)"),this.svgRectTarget_.setAttribute("transform","scale(-1 1)"));var c=Blockly.WorkspaceCommentSvg.RESIZE_SIZE;this.resizeGroup_&&(this.RTL?(this.resizeGroup_.setAttribute("transform","translate("+(-a+c)+","+(b-c)+") scale(-1 1)"),this.deleteGroup_.setAttribute("transform","translate("+(-a+c)+","+-c+") scale(-1 1)")):(this.resizeGroup_.setAttribute("transform","translate("+(a-c)+","+(b-c)+")"),this.deleteGroup_.setAttribute("transform","translate("+(a-c)+","+-c+")")));this.resizeComment_()}; -Blockly.WorkspaceCommentSvg.prototype.disposeInternal_=function(){this.svgHandleTarget_=this.svgRectTarget_=this.foreignObject_=this.textarea_=null;this.disposed_=!0};Blockly.WorkspaceCommentSvg.prototype.setFocus=function(){var a=this;this.focused_=!0;setTimeout(function(){a.disposed_||(a.textarea_.focus(),a.addFocus(),Blockly.utils.addClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.addClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)}; -Blockly.WorkspaceCommentSvg.prototype.blurFocus=function(){var a=this;this.focused_=!1;setTimeout(function(){a.disposed_||(a.textarea_.blur(),a.removeFocus(),Blockly.utils.removeClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.removeClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)};Blockly.WorkspaceDragSurfaceSvg=function(a){this.container_=a;this.createDom()};Blockly.WorkspaceDragSurfaceSvg.prototype.SVG_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.dragGroup_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.container_=null; +Blockly.WorkspaceCommentSvg.prototype.disposeInternal_=function(){this.svgHandleTarget_=this.svgRectTarget_=this.foreignObject_=this.textarea_=null;this.disposed_=!0};Blockly.WorkspaceCommentSvg.prototype.setFocus=function(){var a=this;this.focused_=!0;setTimeout(function(){a.disposed_||(a.textarea_.focus(),a.addFocus(),Blockly.utils.dom.addClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.dom.addClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)}; +Blockly.WorkspaceCommentSvg.prototype.blurFocus=function(){var a=this;this.focused_=!1;setTimeout(function(){a.disposed_||(a.textarea_.blur(),a.removeFocus(),Blockly.utils.dom.removeClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.dom.removeClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)};Blockly.WorkspaceDragSurfaceSvg=function(a){this.container_=a;this.createDom()};Blockly.WorkspaceDragSurfaceSvg.prototype.SVG_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.dragGroup_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.container_=null; Blockly.WorkspaceDragSurfaceSvg.prototype.createDom=function(){this.SVG_||(this.SVG_=Blockly.utils.createSvgElement("svg",{xmlns:Blockly.SVG_NS,"xmlns:html":Blockly.HTML_NS,"xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1","class":"blocklyWsDragSurface blocklyOverflowVisible"},null),this.container_.appendChild(this.SVG_))}; Blockly.WorkspaceDragSurfaceSvg.prototype.translateSurface=function(a,b){a=a.toFixed(0);b=b.toFixed(0);this.SVG_.style.display="block";Blockly.utils.setCssTransform(this.SVG_,"translate3d("+a+"px, "+b+"px, 0px)")};Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation=function(){return Blockly.utils.getRelativeXY(this.SVG_)}; -Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide=function(a){if(!a)throw Error("Couldn't clear and hide the drag surface: missing new surface.");var b=this.SVG_.childNodes[0],c=this.SVG_.childNodes[1];if(!(b&&c&&Blockly.utils.hasClass(b,"blocklyBlockCanvas")&&Blockly.utils.hasClass(c,"blocklyBubbleCanvas")))throw Error("Couldn't clear and hide the drag surface. A node was missing.");null!=this.previousSibling_?Blockly.utils.insertAfter(b,this.previousSibling_):a.insertBefore(b,a.firstChild); -Blockly.utils.insertAfter(c,b);this.SVG_.style.display="none";if(this.SVG_.childNodes.length)throw Error("Drag surface was not cleared.");Blockly.utils.setCssTransform(this.SVG_,"");this.previousSibling_=null}; +Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide=function(a){if(!a)throw Error("Couldn't clear and hide the drag surface: missing new surface.");var b=this.SVG_.childNodes[0],c=this.SVG_.childNodes[1];if(!(b&&c&&Blockly.utils.dom.hasClass(b,"blocklyBlockCanvas")&&Blockly.utils.dom.hasClass(c,"blocklyBubbleCanvas")))throw Error("Couldn't clear and hide the drag surface. A node was missing.");null!=this.previousSibling_?Blockly.utils.dom.insertAfter(b,this.previousSibling_):a.insertBefore(b,a.firstChild); +Blockly.utils.dom.insertAfter(c,b);this.SVG_.style.display="none";if(this.SVG_.childNodes.length)throw Error("Drag surface was not cleared.");Blockly.utils.setCssTransform(this.SVG_,"");this.previousSibling_=null}; Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow=function(a,b,c,d,e,f){if(this.SVG_.childNodes.length)throw Error("Already dragging a block.");this.previousSibling_=c;a.setAttribute("transform","translate(0, 0) scale("+f+")");b.setAttribute("transform","translate(0, 0) scale("+f+")");this.SVG_.setAttribute("width",d);this.SVG_.setAttribute("height",e);this.SVG_.appendChild(a);this.SVG_.appendChild(b);this.SVG_.style.display="block"}; Blockly.ZoomControls=function(a){this.workspace_=a};Blockly.ZoomControls.prototype.WIDTH_=32;Blockly.ZoomControls.prototype.HEIGHT_=110;Blockly.ZoomControls.prototype.MARGIN_BOTTOM_=20;Blockly.ZoomControls.prototype.MARGIN_SIDE_=20;Blockly.ZoomControls.prototype.svgGroup_=null;Blockly.ZoomControls.prototype.left_=0;Blockly.ZoomControls.prototype.top_=0; Blockly.ZoomControls.prototype.createDom=function(){this.svgGroup_=Blockly.utils.createSvgElement("g",{},null);var a=String(Math.random()).substring(2);this.createZoomOutSvg_(a);this.createZoomInSvg_(a);this.workspace_.isMovable()&&this.createZoomResetSvg_(a);return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(a){this.verticalSpacing_=this.MARGIN_BOTTOM_+a;return this.verticalSpacing_+this.HEIGHT_}; -Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; +Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; Blockly.ZoomControls.prototype.position=function(){if(this.verticalSpacing_){var a=this.workspace_.getMetrics();a&&(this.left_=a.toolboxPosition==Blockly.TOOLBOX_AT_LEFT||this.workspace_.horizontalLayout&&!this.workspace_.RTL?a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_-Blockly.Scrollbar.scrollbarThickness:this.MARGIN_SIDE_+Blockly.Scrollbar.scrollbarThickness,a.toolboxPosition==Blockly.TOOLBOX_AT_BOTTOM?(this.top_=this.verticalSpacing_,this.zoomInGroup_.setAttribute("transform","translate(0, 34)"), this.zoomResetGroup_&&this.zoomResetGroup_.setAttribute("transform","translate(0, 77)")):(this.top_=a.viewHeight+a.absoluteTop-this.HEIGHT_-this.verticalSpacing_,this.zoomInGroup_.setAttribute("transform","translate(0, 43)"),this.zoomOutGroup_.setAttribute("transform","translate(0, 77)")),this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))}}; Blockly.ZoomControls.prototype.createZoomOutSvg_=function(a){var b=this.workspace_;this.zoomOutGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyZoom"},this.svgGroup_);var c=Blockly.utils.createSvgElement("clipPath",{id:"blocklyZoomoutClipPath"+a},this.zoomOutGroup_);Blockly.utils.createSvgElement("rect",{width:32,height:32},c);a=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-64,y:-92,"clip-path":"url(#blocklyZoomoutClipPath"+a+")"},this.zoomOutGroup_); @@ -1304,12 +1303,12 @@ Blockly.Procedures.flyoutCategory)};goog.inherits(Blockly.WorkspaceSvg,Blockly.W Blockly.WorkspaceSvg.prototype.startScrollY=0;Blockly.WorkspaceSvg.prototype.dragDeltaXY_=null;Blockly.WorkspaceSvg.prototype.scale=1;Blockly.WorkspaceSvg.prototype.trashcan=null;Blockly.WorkspaceSvg.prototype.scrollbar=null;Blockly.WorkspaceSvg.prototype.flyout_=null;Blockly.WorkspaceSvg.prototype.toolbox_=null;Blockly.WorkspaceSvg.prototype.currentGesture_=null;Blockly.WorkspaceSvg.prototype.blockDragSurface_=null;Blockly.WorkspaceSvg.prototype.workspaceDragSurface_=null; Blockly.WorkspaceSvg.prototype.useWorkspaceDragSurface_=!1;Blockly.WorkspaceSvg.prototype.isDragSurfaceActive_=!1;Blockly.WorkspaceSvg.prototype.injectionDiv_=null;Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_=null;Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_={};Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_={};Blockly.WorkspaceSvg.prototype.configureContextMenu=null;Blockly.WorkspaceSvg.prototype.targetWorkspace=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTM_=null; Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_=!0;Blockly.WorkspaceSvg.prototype.getInverseScreenCTM=function(){if(this.inverseScreenCTMDirty_){var a=this.getParentSvg().getScreenCTM();a&&(this.inverseScreenCTM_=a.inverse(),this.inverseScreenCTMDirty_=!1)}return this.inverseScreenCTM_};Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM=function(){this.inverseScreenCTMDirty_=!0};Blockly.WorkspaceSvg.prototype.isVisible=function(){return this.isVisible_}; -Blockly.WorkspaceSvg.prototype.getSvgXY=function(a){var b=0,c=0,d=1;if(Blockly.utils.containsNode(this.getCanvas(),a)||Blockly.utils.containsNode(this.getBubbleCanvas(),a))d=this.scale;do{var e=Blockly.utils.getRelativeXY(a);if(a==this.getCanvas()||a==this.getBubbleCanvas())d=1;b+=e.x*d;c+=e.y*d;a=a.parentNode}while(a&&a!=this.getParentSvg());return new Blockly.utils.Coordinate(b,c)};Blockly.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return Blockly.utils.getInjectionDivXY_(this.svgBlockCanvas_)}; +Blockly.WorkspaceSvg.prototype.getSvgXY=function(a){var b=0,c=0,d=1;if(Blockly.utils.dom.containsNode(this.getCanvas(),a)||Blockly.utils.dom.containsNode(this.getBubbleCanvas(),a))d=this.scale;do{var e=Blockly.utils.getRelativeXY(a);if(a==this.getCanvas()||a==this.getBubbleCanvas())d=1;b+=e.x*d;c+=e.y*d;a=a.parentNode}while(a&&a!=this.getParentSvg());return new Blockly.utils.Coordinate(b,c)};Blockly.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return Blockly.utils.getInjectionDivXY_(this.svgBlockCanvas_)}; Blockly.WorkspaceSvg.prototype.getInjectionDiv=function(){if(!this.injectionDiv_)for(var a=this.svgGroup_;a;){if(-1!=(" "+(a.getAttribute("class")||"")+" ").indexOf(" injectionDiv ")){this.injectionDiv_=a;break}a=a.parentNode}return this.injectionDiv_};Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper=function(a){this.resizeHandlerWrapper_=a}; Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyWorkspace"},null);a&&(this.svgBackground_=Blockly.utils.createSvgElement("rect",{height:"100%",width:"100%","class":a},this.svgGroup_),"blocklyMainBackground"==a&&this.grid_&&(this.svgBackground_.style.fill="url(#"+this.grid_.getPatternId()+")"));this.svgBlockCanvas_=Blockly.utils.createSvgElement("g",{"class":"blocklyBlockCanvas"},this.svgGroup_);this.svgBubbleCanvas_=Blockly.utils.createSvgElement("g", {"class":"blocklyBubbleCanvas"},this.svgGroup_);this.isFlyout||(Blockly.bindEventWithChecks_(this.svgGroup_,"mousedown",this,this.onMouseDown_,!1,!0),Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.onMouseWheel_));this.options.hasCategories&&(this.toolbox_=new Blockly.Toolbox(this));this.grid_&&this.grid_.update(this.scale);this.recordDeleteAreas();return this.svgGroup_}; -Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;this.currentGesture_&&this.currentGesture_.cancel();Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(Blockly.utils.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.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.removeNode(a)}this.resizeHandlerWrapper_&&(Blockly.unbindEvent_(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)}; +Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;this.currentGesture_&&this.currentGesture_.cancel();Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(Blockly.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.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.dom.removeNode(a)}this.resizeHandlerWrapper_&&(Blockly.unbindEvent_(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)}; Blockly.WorkspaceSvg.prototype.newBlock=function(a,b){return new Blockly.BlockSvg(this,a,b)};Blockly.WorkspaceSvg.prototype.addTrashcan=function(){this.trashcan=new Blockly.Trashcan(this);var a=this.trashcan.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)};Blockly.WorkspaceSvg.prototype.addZoomControls=function(){this.zoomControls_=new Blockly.ZoomControls(this);var a=this.zoomControls_.createDom();this.svgGroup_.appendChild(a)}; Blockly.WorkspaceSvg.prototype.addFlyout_=function(a){var b={disabledPatternId:this.options.disabledPatternId,parentWorkspace:this,RTL:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,toolboxPosition:this.options.toolboxPosition};this.flyout_=this.horizontalLayout?new Blockly.HorizontalFlyout(b):new Blockly.VerticalFlyout(b);this.flyout_.autoClose=!1;return this.flyout_.createDom(a)}; Blockly.WorkspaceSvg.prototype.getFlyout=function(){return this.flyout_?this.flyout_:this.toolbox_?this.toolbox_.flyout_:null};Blockly.WorkspaceSvg.prototype.getToolbox=function(){return this.toolbox_};Blockly.WorkspaceSvg.prototype.updateScreenCalculations_=function(){this.updateInverseScreenCTM();this.recordDeleteAreas()}; @@ -1348,7 +1347,7 @@ this.options.languageTree=a;this.flyout_.show(a.childNodes)}}else if(this.option Blockly.WorkspaceSvg.prototype.zoom=function(a,b,c){c=Math.pow(this.options.zoomOptions.scaleSpeed,c);var d=this.scale*c;if(this.scale!=d){d>this.options.zoomOptions.maxScale?c=this.options.zoomOptions.maxScale/this.scale:dthis.options.zoomOptions.maxScale?a=this.options.zoomOptions.maxScale:this.options.zoomOptions.minScale&&aa||Math.abs(this.workspaceHeight_-b)>a)this.workspaceWidth_=c,this.workspaceHeight_=b,this.bubble_.setBubbleSize(c+a,b+a),this.svgDialog_.setAttribute("width",this.workspaceWidth_), this.svgDialog_.setAttribute("height",this.workspaceHeight_);this.block_.RTL&&(a="translate("+this.workspaceWidth_+",0)",this.workspace_.getCanvas().setAttribute("transform",a));this.workspace_.resize()}; Blockly.Mutator.prototype.setVisible=function(a){if(a!=this.isVisible())if(Blockly.Events.fire(new Blockly.Events.Ui(this.block_,"mutatorOpen",!a,a)),a){this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconXY_,null,null);this.bubble_.setSvgId(this.block_.id);if(a=this.workspace_.options.languageTree)this.workspace_.flyout_.init(this.workspace_),this.workspace_.flyout_.show(a.childNodes);this.rootBlock_=this.block_.decompose(this.workspace_);a=this.rootBlock_.getDescendants(!1); @@ -1397,8 +1396,8 @@ Blockly.Field.prototype.SERIALIZABLE=!1;Blockly.Field.prototype.setSourceBlock=f Blockly.Field.prototype.init=function(){this.fieldGroup_||(this.fieldGroup_=Blockly.utils.createSvgElement("g",{},null),this.isVisible()||(this.fieldGroup_.style.display="none"),this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_),this.initView(),this.updateEditable(),this.setTooltip(),this.bindEvents_(),this.initModel())};Blockly.Field.prototype.initView=function(){this.createBorderRect_();this.createTextElement_()}; Blockly.Field.prototype.createBorderRect_=function(){this.borderRect_=Blockly.utils.createSvgElement("rect",{rx:4,ry:4,x:-Blockly.BlockSvg.SEP_SPACE_X/2,y:0,height:16,width:this.size_.width+Blockly.BlockSvg.SEP_SPACE_X},this.fieldGroup_)};Blockly.Field.prototype.createTextElement_=function(){this.textElement_=Blockly.utils.createSvgElement("text",{"class":"blocklyText",y:this.size_.height-12.5},this.fieldGroup_);this.textContent_=document.createTextNode("");this.textElement_.appendChild(this.textContent_)}; Blockly.Field.prototype.bindEvents_=function(){Blockly.Tooltip.bindMouseEvents(this.getClickTarget_());this.mouseDownWrapper_=Blockly.bindEventWithChecks_(this.getClickTarget_(),"mousedown",this,this.onMouseDown_)};Blockly.Field.prototype.initModel=function(){};Blockly.Field.prototype.fromXml=function(a){this.setValue(a.textContent)};Blockly.Field.prototype.toXml=function(a){a.textContent=this.getValue();return a}; -Blockly.Field.prototype.dispose=function(){this.mouseDownWrapper_&&(Blockly.unbindEvent_(this.mouseDownWrapper_),this.mouseDownWrapper_=null);this.sourceBlock_=null;this.fieldGroup_&&(Blockly.utils.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.validator_=this.borderRect_=this.textElement_=null}; -Blockly.Field.prototype.updateEditable=function(){var a=this.getClickTarget_();this.EDITABLE&&a&&(this.sourceBlock_.isEditable()?(Blockly.utils.addClass(a,"blocklyEditableText"),Blockly.utils.removeClass(a,"blocklyNonEditableText"),a.style.cursor=this.CURSOR):(Blockly.utils.addClass(a,"blocklyNonEditableText"),Blockly.utils.removeClass(a,"blocklyEditableText"),a.style.cursor=""))};Blockly.Field.prototype.isClickable=function(){return!!this.showEditor_&&"function"===typeof this.showEditor_}; +Blockly.Field.prototype.dispose=function(){this.mouseDownWrapper_&&(Blockly.unbindEvent_(this.mouseDownWrapper_),this.mouseDownWrapper_=null);this.sourceBlock_=null;this.fieldGroup_&&(Blockly.utils.dom.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.validator_=this.borderRect_=this.textElement_=null}; +Blockly.Field.prototype.updateEditable=function(){var a=this.getClickTarget_();this.EDITABLE&&a&&(this.sourceBlock_.isEditable()?(Blockly.utils.dom.addClass(a,"blocklyEditableText"),Blockly.utils.dom.removeClass(a,"blocklyNonEditableText"),a.style.cursor=this.CURSOR):(Blockly.utils.dom.addClass(a,"blocklyNonEditableText"),Blockly.utils.dom.removeClass(a,"blocklyEditableText"),a.style.cursor=""))};Blockly.Field.prototype.isClickable=function(){return!!this.showEditor_&&"function"===typeof this.showEditor_}; Blockly.Field.prototype.isCurrentlyEditable=function(){return this.EDITABLE&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()};Blockly.Field.prototype.isSerializable=function(){var a=!1;this.name&&(this.SERIALIZABLE?a=!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."),a=!0));return a};Blockly.Field.prototype.isVisible=function(){return this.visible_}; Blockly.Field.prototype.setVisible=function(a){if(this.visible_!=a){this.visible_=a;var b=this.getSvgRoot();b&&(b.style.display=a?"block":"none")}};Blockly.Field.prototype.setValidator=function(a){this.validator_=a};Blockly.Field.prototype.getValidator=function(){return this.validator_};Blockly.Field.prototype.classValidator=function(a){return a}; Blockly.Field.prototype.callValidator=function(a){var b=this.classValidator(a);if(null===b)return null;void 0!==b&&(a=b);if(b=this.getValidator()){b=b.call(this,a);if(null===b)return null;void 0!==b&&(a=b)}return a};Blockly.Field.prototype.getSvgRoot=function(){return this.fieldGroup_};Blockly.Field.prototype.updateColour=function(){};Blockly.Field.prototype.render_=function(){this.textContent_.nodeValue=this.getDisplayText_();this.updateSize_()}; @@ -1411,7 +1410,7 @@ Blockly.Field.prototype.forceRerender=function(){this.isDirty_=!0;this.sourceBlo Blockly.Field.prototype.setValue=function(a){if(null!==a){var b=this.doClassValidation_(a);void 0!==b&&(a=b);if(null===a)this.doValueInvalid_(),this.isDirty_&&this.forceRerender();else{if(b=this.getValidator())if(b=b.call(this,a),void 0!==b&&(a=b),null===a){this.doValueInvalid_();this.isDirty_&&this.forceRerender();return}b=this.getValue();b!==a&&(this.sourceBlock_&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_,"field",this.name,b,a)),this.doValueUpdate_(a), this.isDirty_&&this.forceRerender())}}};Blockly.Field.prototype.value_=null;Blockly.Field.prototype.doClassValidation_=function(a){return a=this.classValidator(a)};Blockly.Field.prototype.doValueUpdate_=function(a){this.value_=a;this.isDirty_=!0;this.text_=String(a)};Blockly.Field.prototype.doValueInvalid_=function(){};Blockly.Field.prototype.onMouseDown_=function(a){this.sourceBlock_&&this.sourceBlock_.workspace&&(a=this.sourceBlock_.workspace.getGesture(a))&&a.setStartField(this)}; Blockly.Field.prototype.setTooltip=function(a){a||""===a?this.getClickTarget_().tooltip=a:this.getClickTarget_().tooltip=this.sourceBlock_};Blockly.Field.prototype.getClickTarget_=function(){return this.clickTarget_||this.getSvgRoot()};Blockly.Field.prototype.getAbsoluteXY_=function(){return goog.style.getPageOffset(this.borderRect_)};Blockly.Field.prototype.referencesVariables=function(){return!1};Blockly.FieldLabel=function(a,b){this.size_=new goog.math.Size(0,17.5);this.class_=b;a=this.doClassValidation_(a);null===a&&(a="");this.setValue(a)};goog.inherits(Blockly.FieldLabel,Blockly.Field);Blockly.FieldLabel.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.text);return new Blockly.FieldLabel(b,a["class"])};Blockly.FieldLabel.prototype.EDITABLE=!1; -Blockly.FieldLabel.prototype.initView=function(){this.createTextElement_();this.textElement_.setAttribute("y",this.size_.height-5);this.class_&&Blockly.utils.addClass(this.textElement_,this.class_)};Blockly.FieldLabel.prototype.dispose=function(){this.textElement_&&(Blockly.utils.removeNode(this.textElement_),this.textElement_=null)};Blockly.FieldLabel.prototype.doClassValidation_=function(a){return null===a||void 0===a?null:String(a)};Blockly.Field.register("field_label",Blockly.FieldLabel);Blockly.Input=function(a,b,c,d){if(a!=Blockly.DUMMY_INPUT&&!b)throw Error("Value inputs and statement inputs must have non-empty name.");this.type=a;this.name=b;this.sourceBlock_=c;this.connection=d;this.fieldRow=[]};Blockly.Input.prototype.align=Blockly.ALIGN_LEFT;Blockly.Input.prototype.visible_=!0;Blockly.Input.prototype.appendField=function(a,b){this.insertFieldAt(this.fieldRow.length,a,b);return this}; +Blockly.FieldLabel.prototype.initView=function(){this.createTextElement_();this.textElement_.setAttribute("y",this.size_.height-5);this.class_&&Blockly.utils.dom.addClass(this.textElement_,this.class_)};Blockly.FieldLabel.prototype.dispose=function(){this.textElement_&&(Blockly.utils.dom.removeNode(this.textElement_),this.textElement_=null)};Blockly.FieldLabel.prototype.doClassValidation_=function(a){return null===a||void 0===a?null:String(a)};Blockly.Field.register("field_label",Blockly.FieldLabel);Blockly.Input=function(a,b,c,d){if(a!=Blockly.DUMMY_INPUT&&!b)throw Error("Value inputs and statement inputs must have non-empty name.");this.type=a;this.name=b;this.sourceBlock_=c;this.connection=d;this.fieldRow=[]};Blockly.Input.prototype.align=Blockly.ALIGN_LEFT;Blockly.Input.prototype.visible_=!0;Blockly.Input.prototype.appendField=function(a,b){this.insertFieldAt(this.fieldRow.length,a,b);return this}; Blockly.Input.prototype.insertFieldAt=function(a,b,c){if(0>a||a>this.fieldRow.length)throw Error("index "+a+" out of bounds.");if(!b&&!c)return a;"string"==typeof b&&(b=new Blockly.FieldLabel(b));b.setSourceBlock(this.sourceBlock_);this.sourceBlock_.rendered&&b.init();b.name=c;b.prefixField&&(a=this.insertFieldAt(a,b.prefixField));this.fieldRow.splice(a,0,b);++a;b.suffixField&&(a=this.insertFieldAt(a,b.suffixField));this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_()); return a};Blockly.Input.prototype.removeField=function(a){for(var b=0,c;c=this.fieldRow[b];b++)if(c.name===a){c.dispose();this.fieldRow.splice(b,1);this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_());return}throw Error('Field "%s" not found.',a);};Blockly.Input.prototype.isVisible=function(){return this.visible_}; Blockly.Input.prototype.setVisible=function(a){var b=[];if(this.visible_==a)return b;for(var c=(this.visible_=a)?"block":"none",d=0,e;e=this.fieldRow[d];d++)e.setVisible(a);this.connection&&(a?b=this.connection.unhideAll():this.connection.hideAll(),d=this.connection.targetBlock())&&(d.getSvgRoot().style.display=c,a||(d.rendered=!1));return b};Blockly.Input.prototype.setCheck=function(a){if(!this.connection)throw Error("This input does not have a connection.");this.connection.setCheck(a);return this}; @@ -1441,7 +1440,7 @@ Blockly.Block.prototype.setConnectionsHidden=function(a){if(!a&&this.isCollapsed Blockly.Block.prototype.getMatchingConnection=function(a,b){var c=this.getConnections_(!0);a=a.getConnections_(!0);if(c.length!=a.length)throw Error("Connection lists did not match in length.");for(var d=0;d=c)this.hue_=c,this.colour_=Blockly.utils.colour.hueToHex(c);else if(c=Blockly.utils.colour.parse(b))this.colour_=c,this.hue_=null;else throw c='Invalid colour: "'+b+'"',a!=b&&(c+=' (from "'+a+'")'),Error(c);}; +Blockly.Block.prototype.setColour=function(a){var b="string"==typeof a?Blockly.utils.replaceMessageReferences(a):a,c=Number(b);if(!isNaN(c)&&0<=c&&360>=c)this.hue_=c,this.colour_=Blockly.hueToHex(c);else if(c=Blockly.utils.colour.parse(b))this.colour_=c,this.hue_=null;else throw c='Invalid colour: "'+b+'"',a!=b&&(c+=' (from "'+a+'")'),Error(c);}; Blockly.Block.prototype.setStyle=function(a){var b=Blockly.getTheme();if(!b)throw Error("Trying to set block style to "+a+" before theme was defined via Blockly.setTheme().");b=b.getBlockStyle(a);this.styleName_=a;if(b)this.colourSecondary_=b.colourSecondary,this.colourTertiary_=b.colourTertiary,this.hat=b.hat,this.setColour(b.colourPrimary);else throw Error("Invalid style name: "+a);}; Blockly.Block.prototype.setOnChange=function(a){if(a&&"function"!=typeof a)throw Error("onchange must be a function.");this.onchangeWrapper_&&this.workspace.removeChangeListener(this.onchangeWrapper_);if(this.onchange=a)this.onchangeWrapper_=a.bind(this),this.workspace.addChangeListener(this.onchangeWrapper_)};Blockly.Block.prototype.getField=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null}; Blockly.Block.prototype.getVars=function(){for(var a=[],b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)e.referencesVariables()&&a.push(e.getValue());return a};Blockly.Block.prototype.getVarModels=function(){for(var a=[],b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)e.referencesVariables()&&(e=this.workspace.getVariableById(e.getValue()))&&a.push(e);return a}; @@ -1462,7 +1461,7 @@ a.inputsInline&&this.setInputsInline(a.inputsInline);void 0!==a.output&&this.set Blockly.Block.prototype.jsonInitColour_=function(a,b){if("colour"in a)if(void 0===a.colour)console.warn(b+"Undefined colour value.");else{a=a.colour;try{this.setColour(a)}catch(c){console.warn(b+"Illegal colour value: ",a)}}};Blockly.Block.prototype.jsonInitStyle_=function(a,b){a=a.style;try{this.setStyle(a)}catch(c){console.warn(b+"Style does not exist: ",a)}}; Blockly.Block.prototype.mixin=function(a,b){if(void 0!==b&&"boolean"!=typeof b)throw Error("opt_disableCheck must be a boolean if provided");if(!b){b=[];for(var c in a)void 0!==this[c]&&b.push(c);if(b.length)throw Error("Mixin will overwrite block members: "+JSON.stringify(b));}goog.mixin(this,a)}; Blockly.Block.prototype.interpolate_=function(a,b,c){var d=Blockly.utils.tokenizeInterpolation(a),e=[],f=0;a=[];for(var g=0;g=h||h>b.length)throw Error('Block "'+this.type+'": Message index %'+h+" out of range.");if(e[h])throw Error('Block "'+this.type+'": Message index %'+h+" duplicated.");e[h]=!0;f++;a.push(b[h-1])}else(h=h.trim())&&a.push(h)}if(f!=b.length)throw Error('Block "'+this.type+'": Message does not reference all '+b.length+" arg(s)."); -a.length&&("string"==typeof a[a.length-1]||Blockly.utils.startsWith(a[a.length-1].type,"field_"))&&(g={type:"input_dummy"},c&&(g.align=c),a.push(g));c={LEFT:Blockly.ALIGN_LEFT,RIGHT:Blockly.ALIGN_RIGHT,CENTRE:Blockly.ALIGN_CENTRE};b=[];for(g=0;ge.bottom)if(d-f.heighte.bottom)if(d-f.heightc;c+=15)Blockly.utils.createSvgElement("line",{x1:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS,y1:Blockly.FieldAngle.HALF,x2:Blockly.FieldAngle.HALF+ Blockly.FieldAngle.RADIUS-(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+","+Blockly.FieldAngle.HALF+","+Blockly.FieldAngle.HALF+")"},a);c=this.sourceBlock_.getColourBorder();c=null==c.colourBorder?c.colourLight:c.colourBorder;Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(),c);Blockly.DropDownDiv.showPositionedByField(this);this.clickWrapper_=Blockly.bindEvent_(a,"click",this,this.hide_.bind(this));this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove", this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()};Blockly.FieldAngle.prototype.hide_=function(){Blockly.unbindEvent_(this.moveWrapper1_);Blockly.unbindEvent_(this.moveWrapper2_);Blockly.unbindEvent_(this.clickWrapper_);Blockly.DropDownDiv.hideIfOwner(this);Blockly.WidgetDiv.hide()}; -Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;b=a.clientY-b.top-Blockly.FieldAngle.HALF;a=Math.atan(-b/c);isNaN(a)||(a=Blockly.utils.toDegrees(a),0>c?a+=180:0Blockly.FieldAngle.WRAP&& +Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;b=a.clientY-b.top-Blockly.FieldAngle.HALF;a=Math.atan(-b/c);isNaN(a)||(a=Blockly.utils.math.toDegrees(a),0>c?a+=180:0Blockly.FieldAngle.WRAP&& (a-=360),c=String(a),c!=this.text_&&(Blockly.FieldTextInput.htmlInput_.value=a,this.setValue(a),this.text_=c,this.forceRerender()))}; -Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=Blockly.utils.toRadians(a%360);a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF];var c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=Blockly.utils.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS; +Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=Blockly.utils.math.toRadians(a%360);a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF];var c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=Blockly.utils.math.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS; d-=Math.sin(b)*Blockly.FieldAngle.RADIUS;b=Math.abs(Math.floor((b-e)/Math.PI)%2);Blockly.FieldAngle.CLOCKWISE&&(b=1-b);a.push(" l ",f,",",g," A ",Blockly.FieldAngle.RADIUS,",",Blockly.FieldAngle.RADIUS," 0 ",b," ",Number(Blockly.FieldAngle.CLOCKWISE)," ",c,",",d," z")}this.gauge_.setAttribute("d",a.join(""));this.line_.setAttribute("x2",c);this.line_.setAttribute("y2",d)}}; Blockly.FieldAngle.prototype.doClassValidation_=function(a){if(isNaN(a))return null;a=parseFloat(a||0);a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return a};Blockly.Field.register("field_angle",Blockly.FieldAngle);Blockly.FieldCheckbox=function(a,b){a=this.doClassValidation_(a);null===a&&(a="FALSE");Blockly.FieldCheckbox.superClass_.constructor.call(this,a,b);this.size_.width=Blockly.FieldCheckbox.WIDTH};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.fromJson=function(a){return new Blockly.FieldCheckbox(a.checked)};Blockly.FieldCheckbox.WIDTH=5;Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.CHECK_X_OFFSET=-3;Blockly.FieldCheckbox.CHECK_Y_OFFSET=14; Blockly.FieldCheckbox.prototype.SERIALIZABLE=!0;Blockly.FieldCheckbox.prototype.CURSOR="default";Blockly.FieldCheckbox.prototype.isDirty_=!1; -Blockly.FieldCheckbox.prototype.initView=function(){Blockly.FieldCheckbox.superClass_.initView.call(this);this.textElement_.setAttribute("x",Blockly.FieldCheckbox.CHECK_X_OFFSET);this.textElement_.setAttribute("y",Blockly.FieldCheckbox.CHECK_Y_OFFSET);Blockly.utils.addClass(this.textElement_,"blocklyCheckbox");var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.textElement_.appendChild(a);this.textElement_.style.display=this.value_?"block":"none"}; +Blockly.FieldCheckbox.prototype.initView=function(){Blockly.FieldCheckbox.superClass_.initView.call(this);this.textElement_.setAttribute("x",Blockly.FieldCheckbox.CHECK_X_OFFSET);this.textElement_.setAttribute("y",Blockly.FieldCheckbox.CHECK_Y_OFFSET);Blockly.utils.dom.addClass(this.textElement_,"blocklyCheckbox");var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.textElement_.appendChild(a);this.textElement_.style.display=this.value_?"block":"none"}; Blockly.FieldCheckbox.prototype.showEditor_=function(){this.setValue(!this.value_)};Blockly.FieldCheckbox.prototype.doClassValidation_=function(a){return!0===a||"TRUE"===a?"TRUE":!1===a||"FALSE"===a?"FALSE":null};Blockly.FieldCheckbox.prototype.doValueUpdate_=function(a){this.value_=this.convertValueToBool_(a);this.textElement_&&(this.textElement_.style.display=this.value_?"block":"none")};Blockly.FieldCheckbox.prototype.getValue=function(){return this.value_?"TRUE":"FALSE"}; Blockly.FieldCheckbox.prototype.getValueBoolean=function(){return this.value_};Blockly.FieldCheckbox.prototype.getText=function(){return String(this.convertValueToBool_(this.value_))};Blockly.FieldCheckbox.prototype.convertValueToBool_=function(a){return"string"==typeof a?"TRUE"==a:!!a};Blockly.Field.register("field_checkbox",Blockly.FieldCheckbox);Blockly.utils.colour={};Blockly.utils.colour.parse=function(a){a=String(a).toLowerCase().trim();var b=Blockly.utils.colour.names[a];if(b)return b;b="#"==a[0]?a:"#"+a;if(/^#[0-9a-f]{6}$/.test(b))return b;if(/^#[0-9a-f]{3}$/.test(b))return["#",b[1],b[1],b[2],b[2],b[3],b[3]].join("");var c=a.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return c&&(a=Number(c[1]),b=Number(c[2]),c=Number(c[3]),0<=a&&256>a&&0<=b&&256>b&&0<=c&&256>c)?Blockly.utils.colour.rgbToHex(a,b,c):null}; -Blockly.utils.colour.rgbToHex=function(a,b,c){b=a<<16|b<<8|c;return 16>a?"#"+(16777216|b).toString(16).substr(1):"#"+b.toString(16)};Blockly.utils.colour.hexToRgb=function(a){a=parseInt(a.substr(1),16);return[a>>16,a>>8&255,a&255]};Blockly.utils.colour.hueToHex=function(a){return Blockly.utils.colour.hsvToHex(a,Blockly.HSV_SATURATION,255*Blockly.HSV_VALUE)}; +Blockly.utils.colour.rgbToHex=function(a,b,c){b=a<<16|b<<8|c;return 16>a?"#"+(16777216|b).toString(16).substr(1):"#"+b.toString(16)};Blockly.utils.colour.hexToRgb=function(a){a=parseInt(a.substr(1),16);return[a>>16,a>>8&255,a&255]}; Blockly.utils.colour.hsvToHex=function(a,b,c){var d=0,e=0,f=0;if(0==b)f=e=d=c;else{var g=Math.floor(a/60),h=a/60-g;a=c*(1-b);var k=c*(1-b*h);b=c*(1-b*(1-h));switch(g){case 1:d=k;e=c;f=a;break;case 2:d=a;e=c;f=b;break;case 3:d=a;e=k;f=c;break;case 4:d=b;e=a;f=c;break;case 5:d=c;e=a;f=k;break;case 6:case 0:d=c,e=b,f=a}}return Blockly.utils.colour.rgbToHex(Math.floor(d),Math.floor(e),Math.floor(f))}; Blockly.utils.colour.blend=function(a,b,c){a=Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(a));b=Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(b));return Blockly.utils.colour.rgbToHex(Math.round(b[0]+c*(a[0]-b[0])),Math.round(b[1]+c*(a[1]-b[1])),Math.round(b[2]+c*(a[2]-b[2])))}; Blockly.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"};Blockly.FieldColour=function(a,b){a=this.doClassValidation_(a);null===a&&(a=Blockly.FieldColour.COLOURS[0]);Blockly.FieldColour.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.fromJson=function(a){return new Blockly.FieldColour(a.colour)};Blockly.FieldColour.DEFAULT_WIDTH=16;Blockly.FieldColour.DEFAULT_HEIGHT=12;Blockly.FieldColour.prototype.SERIALIZABLE=!0;Blockly.FieldColour.prototype.CURSOR="default"; @@ -1620,9 +1619,9 @@ Blockly.FieldDropdown.prototype.initView=function(){Blockly.FieldDropdown.superC this.textContent_):this.textElement_.appendChild(this.arrow_)};Blockly.FieldDropdown.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,null);var a=this.createMenu_();this.addActionListener_(a);this.positionMenu_(a)};Blockly.FieldDropdown.prototype.addActionListener_=function(a){var b=this;goog.events.listen(a,goog.ui.Component.EventType.ACTION,function(a){if(a=a.target)b.onItemSelected(this,a);Blockly.WidgetDiv.hideIfOwner(b);Blockly.Events.setGroup(!1)})}; Blockly.FieldDropdown.prototype.createMenu_=function(){var a=new goog.ui.Menu;a.setRightToLeft(this.sourceBlock_.RTL);for(var b=this.getOptions(),c=0;ce&&(d.height=e);this.sourceBlock_.RTL&&Blockly.utils.uiMenu.adjustBBoxesForRTL(b,c,d);Blockly.WidgetDiv.positionWithAnchor(b,c,d,this.sourceBlock_.RTL);a.getElement().focus()}; -Blockly.FieldDropdown.prototype.createWidget_=function(a){a.render(Blockly.WidgetDiv.DIV);Blockly.utils.addClass(a.getElement(),"blocklyDropdownMenu");a.setAllowAutoFocus(!0)};Blockly.FieldDropdown.prototype.getAnchorDimensions_=function(){var a=this.getScaledBBox_();this.sourceBlock_.RTL?a.right+=Blockly.FieldDropdown.CHECKMARK_OVERHANG:a.left-=Blockly.FieldDropdown.CHECKMARK_OVERHANG;return a};Blockly.FieldDropdown.prototype.onItemSelected=function(a,b){this.setValue(b.getValue())}; -Blockly.FieldDropdown.prototype.trimOptions_=function(){this.suffixField=this.prefixField=null;var a=this.menuGenerator_;if(Array.isArray(a)){for(var b=!1,c=0;ca.length)){b=[];for(c=0;ca.length)){b=[];for(c=0;c=this.height_||0>=this.width_)throw Error("Height and width values of an image field must be greater than 0.");this.size_=new goog.math.Size(this.width_,this.height_+2*Blockly.BlockSvg.INLINE_PADDING_Y);this.flipRtl_=f;this.text_=d||"";this.setValue(a||"");"function"==typeof e&&(this.clickHandler_= e)};goog.inherits(Blockly.FieldImage,Blockly.Field);Blockly.FieldImage.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.src),c=Number(Blockly.utils.replaceMessageReferences(a.width)),d=Number(Blockly.utils.replaceMessageReferences(a.height)),e=Blockly.utils.replaceMessageReferences(a.alt);return new Blockly.FieldImage(b,c,d,e,null,!!a.flipRtl)};Blockly.FieldImage.prototype.EDITABLE=!1;Blockly.FieldImage.prototype.isDirty_=!1; -Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_)};Blockly.FieldImage.prototype.dispose=function(){this.fieldGroup_&&(Blockly.utils.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.imageElement_=null}; +Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_)};Blockly.FieldImage.prototype.dispose=function(){this.fieldGroup_&&(Blockly.utils.dom.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.imageElement_=null}; Blockly.FieldImage.prototype.doClassValidation_=function(a){return"string"!=typeof a?null:a};Blockly.FieldImage.prototype.doValueUpdate_=function(a){this.value_=a;this.imageElement_&&this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_||"")};Blockly.FieldImage.prototype.getFlipRtl=function(){return this.flipRtl_};Blockly.FieldImage.prototype.setText=function(a){null!==a&&(this.text_=a,this.imageElement_&&this.imageElement_.setAttribute("alt",a||""))}; Blockly.FieldImage.prototype.showEditor_=function(){this.clickHandler_&&this.clickHandler_(this)};Blockly.Field.register("field_image",Blockly.FieldImage);Blockly.FieldNumber=function(a,b,c,d,e){this.setConstraints(b,c,d);a=this.doClassValidation_(a);null===a&&(a=0);Blockly.FieldNumber.superClass_.constructor.call(this,a,e)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.fromJson=function(a){return new Blockly.FieldNumber(a.value,a.min,a.max,a.precision)};Blockly.FieldNumber.prototype.SERIALIZABLE=!0; Blockly.FieldNumber.prototype.setConstraints=function(a,b,c){c=parseFloat(c);this.precision_=isNaN(c)?0:c;c=this.precision_.toString();var d=c.indexOf(".");this.fractionalDigits_=-1==d?-1:c.length-(d+1);a=parseFloat(a);this.min_=isNaN(a)?-Infinity:a;b=parseFloat(b);this.max_=isNaN(b)?Infinity:b;this.setValue(this.getValue())}; @@ -1676,21 +1675,21 @@ Blockly.FlyoutButton.prototype.createDom=function(){var a=this.isLabel_?"blockly rx:4,ry:4},this.svgGroup_);var c=Blockly.utils.createSvgElement("text",{"class":this.isLabel_?"blocklyFlyoutLabelText":"blocklyText",x:0,y:0,"text-anchor":"middle"},this.svgGroup_);c.textContent=Blockly.utils.replaceMessageReferences(this.text_);this.width=Blockly.Field.getCachedWidth(c);this.height=20;this.isLabel_||(this.width+=2*Blockly.FlyoutButton.MARGIN,b.setAttribute("width",this.width),b.setAttribute("height",this.height));a.setAttribute("width",this.width);a.setAttribute("height",this.height); c.setAttribute("x",this.width/2);c.setAttribute("y",this.height-Blockly.FlyoutButton.MARGIN);this.updateTransform_();this.onMouseUpWrapper_=Blockly.bindEventWithChecks_(this.svgGroup_,"mouseup",this,this.onMouseUp_);return this.svgGroup_};Blockly.FlyoutButton.prototype.show=function(){this.updateTransform_();this.svgGroup_.setAttribute("display","block")}; Blockly.FlyoutButton.prototype.updateTransform_=function(){this.svgGroup_.setAttribute("transform","translate("+this.position_.x+","+this.position_.y+")")};Blockly.FlyoutButton.prototype.moveTo=function(a,b){this.position_.x=a;this.position_.y=b;this.updateTransform_()};Blockly.FlyoutButton.prototype.getPosition=function(){return this.position_};Blockly.FlyoutButton.prototype.getTargetWorkspace=function(){return this.targetWorkspace_}; -Blockly.FlyoutButton.prototype.dispose=function(){this.onMouseUpWrapper_&&Blockly.unbindEvent_(this.onMouseUpWrapper_);this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.workspace_=null}; +Blockly.FlyoutButton.prototype.dispose=function(){this.onMouseUpWrapper_&&Blockly.unbindEvent_(this.onMouseUpWrapper_);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.workspace_=null}; Blockly.FlyoutButton.prototype.onMouseUp_=function(a){(a=this.targetWorkspace_.getGesture(a))&&a.cancel();this.isLabel_&&this.callbackKey_?console.warn("Labels should not have callbacks. Label text: "+this.text_):this.isLabel_||this.callbackKey_&&this.targetWorkspace_.getButtonCallback(this.callbackKey_)?this.isLabel_||this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this):console.warn("Buttons should have callbacks. Button text: "+this.text_)};Blockly.Flyout=function(a){a.getMetrics=this.getMetrics_.bind(this);a.setMetrics=this.setMetrics_.bind(this);this.workspace_=new Blockly.WorkspaceSvg(a);this.workspace_.isFlyout=!0;this.RTL=!!a.RTL;this.toolboxPosition_=a.toolboxPosition;this.eventWrappers_=[];this.mats_=[];this.buttons_=[];this.listeners_=[];this.permanentlyDisabled_=[]};Blockly.Flyout.prototype.autoClose=!0;Blockly.Flyout.prototype.isVisible_=!1;Blockly.Flyout.prototype.containerVisible_=!0; Blockly.Flyout.prototype.CORNER_RADIUS=8;Blockly.Flyout.prototype.MARGIN=Blockly.Flyout.prototype.CORNER_RADIUS;Blockly.Flyout.prototype.GAP_X=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.GAP_Y=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.SCROLLBAR_PADDING=2;Blockly.Flyout.prototype.width_=0;Blockly.Flyout.prototype.height_=0;Blockly.Flyout.prototype.dragAngleRange_=70; Blockly.Flyout.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.createSvgElement(a,{"class":"blocklyFlyout",style:"display: none"},null);this.svgBackground_=Blockly.utils.createSvgElement("path",{"class":"blocklyFlyoutBackground"},this.svgGroup_);this.svgGroup_.appendChild(this.workspace_.createDom());return this.svgGroup_}; Blockly.Flyout.prototype.init=function(a){this.targetWorkspace_=a;this.workspace_.targetWorkspace=a;this.scrollbar_=new Blockly.Scrollbar(this.workspace_,this.horizontalLayout_,!1,"blocklyFlyoutScrollbar");this.hide();Array.prototype.push.apply(this.eventWrappers_,Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.wheel_));this.autoClose||(this.filterWrapper_=this.filterForCapacity_.bind(this),this.targetWorkspace_.addChangeListener(this.filterWrapper_));Array.prototype.push.apply(this.eventWrappers_, Blockly.bindEventWithChecks_(this.svgBackground_,"mousedown",this,this.onMouseDown_));this.workspace_.getGesture=this.targetWorkspace_.getGesture.bind(this.targetWorkspace_);this.workspace_.variableMap_=this.targetWorkspace_.getVariableMap();this.workspace_.createPotentialVariableMap()}; -Blockly.Flyout.prototype.dispose=function(){this.hide();Blockly.unbindEvent_(this.eventWrappers_);this.filterWrapper_&&(this.targetWorkspace_.removeChangeListener(this.filterWrapper_),this.filterWrapper_=null);this.scrollbar_&&(this.scrollbar_.dispose(),this.scrollbar_=null);this.workspace_&&(this.workspace_.targetWorkspace=null,this.workspace_.dispose(),this.workspace_=null);this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.svgBackground_=null}; -Blockly.Flyout.prototype.getWidth=function(){return this.width_};Blockly.Flyout.prototype.getHeight=function(){return this.height_};Blockly.Flyout.prototype.getWorkspace=function(){return this.workspace_};Blockly.Flyout.prototype.isVisible=function(){return this.isVisible_};Blockly.Flyout.prototype.setVisible=function(a){var b=a!=this.isVisible();this.isVisible_=a;b&&this.updateDisplay_()}; +Blockly.Flyout.prototype.dispose=function(){this.hide();Blockly.unbindEvent_(this.eventWrappers_);this.filterWrapper_&&(this.targetWorkspace_.removeChangeListener(this.filterWrapper_),this.filterWrapper_=null);this.scrollbar_&&(this.scrollbar_.dispose(),this.scrollbar_=null);this.workspace_&&(this.workspace_.targetWorkspace=null,this.workspace_.dispose(),this.workspace_=null);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.svgBackground_= +null};Blockly.Flyout.prototype.getWidth=function(){return this.width_};Blockly.Flyout.prototype.getHeight=function(){return this.height_};Blockly.Flyout.prototype.getWorkspace=function(){return this.workspace_};Blockly.Flyout.prototype.isVisible=function(){return this.isVisible_};Blockly.Flyout.prototype.setVisible=function(a){var b=a!=this.isVisible();this.isVisible_=a;b&&this.updateDisplay_()}; Blockly.Flyout.prototype.setContainerVisible=function(a){var b=a!=this.containerVisible_;this.containerVisible_=a;b&&this.updateDisplay_()};Blockly.Flyout.prototype.updateDisplay_=function(){var a=this.containerVisible_?this.isVisible():!1;this.svgGroup_.style.display=a?"block":"none";this.scrollbar_.setContainerVisible(a)}; Blockly.Flyout.prototype.positionAt_=function(a,b,c,d){this.svgGroup_.setAttribute("width",a);this.svgGroup_.setAttribute("height",b);"svg"==this.svgGroup_.tagName?Blockly.utils.setCssTransform(this.svgGroup_,"translate("+c+"px,"+d+"px)"):this.svgGroup_.setAttribute("transform","translate("+c+","+d+")");this.scrollbar_&&(this.scrollbar_.setOrigin(c,d),this.scrollbar_.resize(),this.scrollbar_.setPosition_(this.scrollbar_.position_.x,this.scrollbar_.position_.y))}; Blockly.Flyout.prototype.hide=function(){if(this.isVisible()){this.setVisible(!1);for(var a=0,b;b=this.listeners_[a];a++)Blockly.unbindEvent_(b);this.listeners_.length=0;this.reflowWrapper_&&(this.workspace_.removeChangeListener(this.reflowWrapper_),this.reflowWrapper_=null)}}; Blockly.Flyout.prototype.show=function(a){this.workspace_.setResizesEnabled(!1);this.hide();this.clearOldBlocks_();if("string"==typeof a){a=this.workspace_.targetWorkspace.getToolboxCategoryCallback(a);if("function"!=typeof a)throw TypeError("Couldn't find a callback function when opening a toolbox category.");a=a(this.workspace_.targetWorkspace);if(!Array.isArray(a))throw TypeError("Result of toolbox category callback must be an array.");}this.setVisible(!0);var b=[],c=[];this.permanentlyDisabled_.length= 0;for(var d=this.horizontalLayout_?this.GAP_X:this.GAP_Y,e=0,f;f=a[e];e++)if(f.tagName)switch(f.tagName.toUpperCase()){case "BLOCK":var g=Blockly.Xml.domToBlock(f,this.workspace_);g.isEnabled()||this.permanentlyDisabled_.push(g);b.push({type:"block",block:g});f=parseInt(f.getAttribute("gap"),10);c.push(isNaN(f)?d:f);break;case "SEP":f=parseInt(f.getAttribute("gap"),10);!isNaN(f)&&0b.viewBottom||b.contentLeftb.viewRight){c=null;a&&(c=Blockly.Events.getGroup(),Blockly.Events.setGroup(a.group));switch(a.type){case Blockly.Events.BLOCK_CREATE:case Blockly.Events.BLOCK_MOVE:var f=e.getBlockById(a.blockId);f=f.getRootBlock();break;case Blockly.Events.COMMENT_CREATE:case Blockly.Events.COMMENT_MOVE:f=e.getCommentById(a.commentId)}if(f){d=f.getBoundingRectangle();var n=b.viewTop-d.topLeft.y; 0n&&f.moveBy(0,n);n=b.viewLeft-d.topLeft.x;0b&&f.moveBy(b,0)}a&&(a.group||console.log("WARNING: Moved object in bounds but there was no event group. This may break undo."),Blockly.Events.setGroup(c))}}});Blockly.svgResize(e);Blockly.WidgetDiv.createDom();Blockly.DropDownDiv.createDom();Blockly.Tooltip.createDom();return e}; @@ -1812,7 +1811,7 @@ Blockly.defineBlocksWithJsonArray=function(a){for(var b=0;bb&&(b=c[d].length);d=-Infinity;var e=1;do{var f=d;var g=a;var h=[],k=c.length/e,l=1;for(d=0;df);return g}; +Blockly.utils.string.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;fd&&(d=h,e=g)}return e?Blockly.utils.string.wrapMutate_(a,e,c):b};Blockly.utils.string.wrapToText_=function(a,b){for(var c=[],d=0;d=k?(e=2,g=k,(k=f.join(""))&&c.push(k),f.length=0):"{"==k?e=3:(f.push("%",k),e=0):2==e?"0"<=k&&"9">=k?g+=k:(c.push(parseInt(g,10)),h--,e=0):3==e&&(""==k?(f.splice(0,0,"%{"),h--,e=0):"}"!=k?f.push(k):(e=f.join(""),/[a-zA-Z][a-zA-Z0-9_]*/.test(e)?(k=e.toUpperCase(), -(k=Blockly.utils.startsWith(k,"BKY_")?k.substring(4):null)&&k in Blockly.Msg?(e=Blockly.Msg[k],"string"==typeof e?Array.prototype.push.apply(c,Blockly.utils.tokenizeInterpolation_(e,b)):b?c.push(String(e)):c.push(e)):c.push("%{"+e+"}")):c.push("%{"+e+"}"),e=f.length=0))}(k=f.join(""))&&c.push(k);d=[];for(h=f.length=0;hc;c++)b[c]=Blockly.utils.genUid.soup_.charAt(Math.random()*a);return b.join("")};Blockly.utils.genUid.soup_="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";Blockly.utils.wrap=function(a,b){for(var c=a.split("\n"),d=0;db&&(b=c[d].length);d=-Infinity;var e=1;do{var f=d;var g=a;var h=[],k=c.length/e,l=1;for(d=0;df);return g}; -Blockly.utils.wrapScore_=function(a,b,c){for(var d=[0],e=[],f=0;fd&&(d=h,e=g)}return e?Blockly.utils.wrapMutate_(a,e,c):b};Blockly.utils.wrapToText_=function(a,b){for(var c=[],d=0;dc;c++)b[c]=Blockly.utils.genUid.soup_.charAt(Math.random()*a);return b.join("")};Blockly.utils.genUid.soup_="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Blockly.utils.is3dSupported=function(){if(void 0!==Blockly.utils.is3dSupported.cached_)return Blockly.utils.is3dSupported.cached_;if(!Blockly.utils.global.getComputedStyle)return!1;var a=document.createElement("p"),b="none",c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(a,null);for(var d in c)if(void 0!==a.style[d]){a.style[d]="translate3d(1px,1px,1px)";b=Blockly.utils.global.getComputedStyle(a); -if(!b)return document.body.removeChild(a),!1;b=b.getPropertyValue(c[d])}document.body.removeChild(a);Blockly.utils.is3dSupported.cached_="none"!==b;return Blockly.utils.is3dSupported.cached_};Blockly.utils.insertAfter=function(a,b){var c=b.nextSibling,d=b.parentNode;if(!d)throw Error("Reference node has no parent.");c?d.insertBefore(a,c):d.appendChild(a)}; -Blockly.utils.runAfterPageLoad=function(a){if("object"!=typeof document)throw Error("Blockly.utils.runAfterPageLoad() requires browser document.");if("complete"==document.readyState)a();else var b=setInterval(function(){"complete"==document.readyState&&(clearInterval(b),a())},10)};Blockly.utils.setCssTransform=function(a,b){a.style.transform=b;a.style["-webkit-transform"]=b}; -Blockly.utils.getViewportBBox=function(){var a=goog.style.getViewportPageOffset(document);return{right:document.documentElement.clientWidth+a.x,bottom:document.documentElement.clientHeight+a.y,top:a.y,left:a.x}};Blockly.utils.startsWith=function(a,b){return 0==a.lastIndexOf(b,0)};Blockly.utils.arrayRemove=function(a,b){var c=a.indexOf(b);if(-1==c)return!1;a.splice(c,1);return!0};Blockly.utils.toRadians=function(a){return a*Math.PI/180};Blockly.utils.toDegrees=function(a){return 180*a/Math.PI}; -Blockly.utils.containsNode=function(a,b){return!!(a.compareDocumentPosition(b)&Node.DOCUMENT_POSITION_CONTAINED_BY)};Blockly.utils.getDocumentScroll=function(){var a=document.documentElement,b=window;return Blockly.userAgent.IE&&b.pageYOffset!=a.scrollTop?new Blockly.utils.Coordinate(a.scrollLeft,a.scrollTop):new Blockly.utils.Coordinate(b.pageXOffset||a.scrollLeft,b.pageYOffset||a.scrollTop)}; -Blockly.utils.getBlockTypeCounts=function(a,b){var c=Object.create(null),d=a.getDescendants(!0);if(b){var e=a.getNextBlock();e&&(e=d.indexOf(e),d.splice(e,d.length-e))}e=0;for(var f;f=d[e];e++)c[f.type]?c[f.type]++:c[f.type]=1;return c};Blockly.utils.clampNumber=function(a,b,c){if(c"!=d.slice(-2)&&(b+=" ")}a=a.join("\n");a=a.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1");return a.replace(/^\n/,"")}; Blockly.Xml.textToDom=function(a){a=Blockly.Xml.utils.textToDomDocument(a);if(!a||!a.documentElement||"xml"!=a.documentElement.nodeName.toLowerCase())throw TypeError("Blockly.Xml.textToDom expected an document.");return a.documentElement};Blockly.Xml.clearWorkspaceAndLoadFromXml=function(a,b){b.setResizesEnabled(!1);b.clear();var c=Blockly.Xml.domToWorkspace(a,b);b.setResizesEnabled(!0);return c}; Blockly.Xml.domToWorkspace=function(a,b){if(a instanceof Blockly.Workspace){var c=a;a=b;b=c;console.warn("Deprecated call to Blockly.Xml.domToWorkspace, swap the arguments.")}var d;b.RTL&&(d=b.getWidth());c=[];Blockly.Field.startCache();var e=a.childNodes.length,f=Blockly.Events.getGroup();f||Blockly.Events.setGroup(!0);b.setResizesEnabled&&b.setResizesEnabled(!1);var g=!0;try{for(var h=0;hthis.MAX_UNDO&&0<=this.MAX_UNDO;)this.undoStack_.shift();for(var b=0,c;c=this.listeners_[b];b++)c(a)}; Blockly.Workspace.prototype.getBlockById=function(a){return this.blockDB_[a]||null};Blockly.Workspace.prototype.getCommentById=function(a){return this.commentDB_[a]||null};Blockly.Workspace.prototype.allInputsFilled=function(a){for(var b=this.getTopBlocks(!1),c=0,d;d=b[c];c++)if(!d.allInputsFilled(a))return!1;return!0};Blockly.Workspace.prototype.getPotentialVariableMap=function(){return this.potentialVariableMap_}; Blockly.Workspace.prototype.createPotentialVariableMap=function(){this.potentialVariableMap_=new Blockly.VariableMap(this)};Blockly.Workspace.prototype.getVariableMap=function(){return this.variableMap_};Blockly.Workspace.WorkspaceDB_=Object.create(null);Blockly.Workspace.getById=function(a){return Blockly.Workspace.WorkspaceDB_[a]||null};Blockly.Workspace.getAll=function(){var a=[],b;for(b in Blockly.Workspace.WorkspaceDB_)a.push(Blockly.Workspace.WorkspaceDB_[b]);return a}; -Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Workspace.prototype.clearUndo=Blockly.Workspace.prototype.clearUndo;Blockly.Workspace.prototype.addChangeListener=Blockly.Workspace.prototype.addChangeListener;Blockly.Workspace.prototype.removeChangeListener=Blockly.Workspace.prototype.removeChangeListener;Blockly.Bubble=function(a,b,c,d,e,f){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=Blockly.utils.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!e||!f)));this.setAnchorLocation(d);e&&f||(b=this.content_.getBBox(),e=b.width+2*Blockly.Bubble.BORDER_WIDTH,f=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(e,f);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly||(Blockly.bindEventWithChecks_(this.bubbleBack_, -"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEventWithChecks_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=5;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null;Blockly.Bubble.prototype.resizeCallback_=null; +Blockly.Workspace.prototype.clear=Blockly.Workspace.prototype.clear;Blockly.Workspace.prototype.clearUndo=Blockly.Workspace.prototype.clearUndo;Blockly.Workspace.prototype.addChangeListener=Blockly.Workspace.prototype.addChangeListener;Blockly.Workspace.prototype.removeChangeListener=Blockly.Workspace.prototype.removeChangeListener;Blockly.Bubble=function(a,b,c,d,e,f){this.workspace_=a;this.content_=b;this.shape_=c;c=Blockly.Bubble.ARROW_ANGLE;this.workspace_.RTL&&(c=-c);this.arrow_radians_=Blockly.utils.math.toRadians(c);a.getBubbleCanvas().appendChild(this.createDom_(b,!(!e||!f)));this.setAnchorLocation(d);e&&f||(b=this.content_.getBBox(),e=b.width+2*Blockly.Bubble.BORDER_WIDTH,f=b.height+2*Blockly.Bubble.BORDER_WIDTH);this.setBubbleSize(e,f);this.positionBubble_();this.renderArrow_();this.rendered_=!0;a.options.readOnly|| +(Blockly.bindEventWithChecks_(this.bubbleBack_,"mousedown",this,this.bubbleMouseDown_),this.resizeGroup_&&Blockly.bindEventWithChecks_(this.resizeGroup_,"mousedown",this,this.resizeMouseDown_))};Blockly.Bubble.BORDER_WIDTH=6;Blockly.Bubble.ARROW_THICKNESS=5;Blockly.Bubble.ARROW_ANGLE=20;Blockly.Bubble.ARROW_BEND=4;Blockly.Bubble.ANCHOR_RADIUS=8;Blockly.Bubble.onMouseUpWrapper_=null;Blockly.Bubble.onMouseMoveWrapper_=null;Blockly.Bubble.prototype.resizeCallback_=null; Blockly.Bubble.unbindDragEvents_=function(){Blockly.Bubble.onMouseUpWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_),Blockly.Bubble.onMouseUpWrapper_=null);Blockly.Bubble.onMouseMoveWrapper_&&(Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_),Blockly.Bubble.onMouseMoveWrapper_=null)};Blockly.Bubble.bubbleMouseUp_=function(){Blockly.Touch.clearTouchIdentifier();Blockly.Bubble.unbindDragEvents_()};Blockly.Bubble.prototype.rendered_=!1;Blockly.Bubble.prototype.anchorXY_=null; Blockly.Bubble.prototype.relativeLeft_=0;Blockly.Bubble.prototype.relativeTop_=0;Blockly.Bubble.prototype.width_=0;Blockly.Bubble.prototype.height_=0;Blockly.Bubble.prototype.autoLayout_=!0; Blockly.Bubble.prototype.createDom_=function(a,b){this.bubbleGroup_=Blockly.utils.createSvgElement("g",{},null);var c={filter:"url(#"+this.workspace_.options.embossFilterId+")"};Blockly.userAgent.JAVA_FX&&(c={});c=Blockly.utils.createSvgElement("g",c,this.bubbleGroup_);this.bubbleArrow_=Blockly.utils.createSvgElement("path",{},c);this.bubbleBack_=Blockly.utils.createSvgElement("rect",{"class":"blocklyDraggable",x:0,y:0,rx:Blockly.Bubble.BORDER_WIDTH,ry:Blockly.Bubble.BORDER_WIDTH},c);b?(this.resizeGroup_= @@ -1035,11 +1033,12 @@ Blockly.Bubble.prototype.setBubbleSize=function(a,b){var c=2*Blockly.Bubble.BORD this.layoutBubble_(),this.positionBubble_(),this.renderArrow_());this.resizeCallback_&&this.resizeCallback_()}; Blockly.Bubble.prototype.renderArrow_=function(){var a=[],b=this.width_/2,c=this.height_/2,d=-this.relativeLeft_,e=-this.relativeTop_;if(b==d&&c==e)a.push("M "+b+","+c);else{e-=c;d-=b;this.workspace_.RTL&&(d*=-1);var f=Math.sqrt(e*e+d*d),g=Math.acos(d/f);0>e&&(g=2*Math.PI-g);var h=g+Math.PI/2;h>2*Math.PI&&(h-=2*Math.PI);var k=Math.sin(h),l=Math.cos(h),n=this.getBubbleSize();h=(n.width+n.height)/Blockly.Bubble.ARROW_THICKNESS;h=Math.min(h,n.width,n.height)/4;n=1-Blockly.Bubble.ANCHOR_RADIUS/f;d=b+ n*d;e=c+n*e;n=b+h*l;var m=c+h*k;b-=h*l;c-=h*k;k=g+this.arrow_radians_;k>2*Math.PI&&(k-=2*Math.PI);g=Math.sin(k)*f/Blockly.Bubble.ARROW_BEND;f=Math.cos(k)*f/Blockly.Bubble.ARROW_BEND;a.push("M"+n+","+m);a.push("C"+(n+f)+","+(m+g)+" "+d+","+e+" "+d+","+e);a.push("C"+d+","+e+" "+(b+f)+","+(c+g)+" "+b+","+c)}a.push("z");this.bubbleArrow_.setAttribute("d",a.join(" "))};Blockly.Bubble.prototype.setColour=function(a){this.bubbleBack_.setAttribute("fill",a);this.bubbleArrow_.setAttribute("fill",a)}; -Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();Blockly.utils.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.resizeGroup_=this.bubbleBack_=this.bubbleArrow_=this.bubbleGroup_=null};Blockly.Bubble.prototype.moveDuringDrag=function(a,b){a?a.translateSurface(b.x,b.y):this.moveTo(b.x,b.y);this.relativeLeft_=this.workspace_.RTL?this.anchorXY_.x-b.x-this.width_:b.x-this.anchorXY_.x;this.relativeTop_=b.y-this.anchorXY_.y;this.renderArrow_()}; +Blockly.Bubble.prototype.dispose=function(){Blockly.Bubble.unbindDragEvents_();Blockly.utils.dom.removeNode(this.bubbleGroup_);this.shape_=this.content_=this.workspace_=this.resizeGroup_=this.bubbleBack_=this.bubbleArrow_=this.bubbleGroup_=null};Blockly.Bubble.prototype.moveDuringDrag=function(a,b){a?a.translateSurface(b.x,b.y):this.moveTo(b.x,b.y);this.relativeLeft_=this.workspace_.RTL?this.anchorXY_.x-b.x-this.width_:b.x-this.anchorXY_.x;this.relativeTop_=b.y-this.anchorXY_.y;this.renderArrow_()}; Blockly.Bubble.prototype.getRelativeToSurfaceXY=function(){return new Blockly.utils.Coordinate(this.anchorXY_.x+this.relativeLeft_,this.anchorXY_.y+this.relativeTop_)};Blockly.Bubble.prototype.setAutoLayout=function(a){this.autoLayout_=a};Blockly.Events.Ui=function(a,b,c,d){Blockly.Events.Ui.superClass_.constructor.call(this);this.blockId=a?a.id:null;this.workspaceId=a?a.workspace.id:null;this.element=b;this.oldValue=c;this.newValue=d;this.recordUndo=!1};goog.inherits(Blockly.Events.Ui,Blockly.Events.Abstract);Blockly.Events.Ui.prototype.type=Blockly.Events.UI; Blockly.Events.Ui.prototype.toJson=function(){var a=Blockly.Events.Ui.superClass_.toJson.call(this);a.element=this.element;void 0!==this.newValue&&(a.newValue=this.newValue);this.blockId&&(a.blockId=this.blockId);return a};Blockly.Events.Ui.prototype.fromJson=function(a){Blockly.Events.Ui.superClass_.fromJson.call(this,a);this.element=a.element;this.newValue=a.newValue;this.blockId=a.blockId};Blockly.Icon=function(a){this.block_=a};Blockly.Icon.prototype.collapseHidden=!0;Blockly.Icon.prototype.SIZE=17;Blockly.Icon.prototype.bubble_=null;Blockly.Icon.prototype.iconXY_=null; -Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyIconGroup"},null),this.block_.isInFlyout&&Blockly.utils.addClass(this.iconGroup_,"blocklyIconGroupReadonly"),this.drawIcon_(this.iconGroup_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEventWithChecks_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())}; -Blockly.Icon.prototype.dispose=function(){Blockly.utils.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_};Blockly.Icon.prototype.iconClick_=function(a){this.block_.workspace.isDragging()||this.block_.isInFlyout||Blockly.utils.isRightButton(a)||this.setVisible(!this.isVisible())};Blockly.Icon.prototype.updateColour=function(){this.isVisible()&&this.bubble_.setColour(this.block_.getColour())}; +Blockly.Icon.prototype.createIcon=function(){this.iconGroup_||(this.iconGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyIconGroup"},null),this.block_.isInFlyout&&Blockly.utils.dom.addClass(this.iconGroup_,"blocklyIconGroupReadonly"),this.drawIcon_(this.iconGroup_),this.block_.getSvgRoot().appendChild(this.iconGroup_),Blockly.bindEventWithChecks_(this.iconGroup_,"mouseup",this,this.iconClick_),this.updateEditable())}; +Blockly.Icon.prototype.dispose=function(){Blockly.utils.dom.removeNode(this.iconGroup_);this.iconGroup_=null;this.setVisible(!1);this.block_=null};Blockly.Icon.prototype.updateEditable=function(){};Blockly.Icon.prototype.isVisible=function(){return!!this.bubble_};Blockly.Icon.prototype.iconClick_=function(a){this.block_.workspace.isDragging()||this.block_.isInFlyout||Blockly.utils.isRightButton(a)||this.setVisible(!this.isVisible())}; +Blockly.Icon.prototype.updateColour=function(){this.isVisible()&&this.bubble_.setColour(this.block_.getColour())}; Blockly.Icon.prototype.renderIcon=function(a){if(this.collapseHidden&&this.block_.isCollapsed()||this.block_.isInsertionMarker())return this.iconGroup_.setAttribute("display","none"),a;this.iconGroup_.setAttribute("display","block");var b=this.SIZE;this.block_.RTL&&(a-=b);this.iconGroup_.setAttribute("transform","translate("+a+",5)");this.computeIconLocation();return a=this.block_.RTL?a-Blockly.BlockSvg.SEP_SPACE_X:a+(b+Blockly.BlockSvg.SEP_SPACE_X)}; Blockly.Icon.prototype.setIconLocation=function(a){this.iconXY_=a;this.isVisible()&&this.bubble_.setAnchorLocation(a)};Blockly.Icon.prototype.computeIconLocation=function(){var a=this.block_.getRelativeToSurfaceXY(),b=Blockly.utils.getRelativeXY(this.iconGroup_);a=new Blockly.utils.Coordinate(a.x+b.x+this.SIZE/2,a.y+b.y+this.SIZE/2);Blockly.utils.Coordinate.equals(this.getIconLocation(),a)||this.setIconLocation(a)};Blockly.Icon.prototype.getIconLocation=function(){return this.iconXY_}; Blockly.Comment=function(a){Blockly.Comment.superClass_.constructor.call(this,a);this.createIcon()};goog.inherits(Blockly.Comment,Blockly.Icon);Blockly.Comment.prototype.text_="";Blockly.Comment.prototype.width_=160;Blockly.Comment.prototype.height_=80; @@ -1069,7 +1068,7 @@ Blockly.Connection.prototype.disconnect=function(){var a=this.targetConnection;i Blockly.Connection.prototype.disconnectInternal_=function(a,b){var c;Blockly.Events.isEnabled()&&(c=new Blockly.Events.BlockMove(b));this.targetConnection=this.targetConnection.targetConnection=null;b.setParent(null);c&&(c.recordNew(),Blockly.Events.fire(c))}; Blockly.Connection.prototype.respawnShadow_=function(){var a=this.getSourceBlock(),b=this.getShadowDom();if(a.workspace&&b&&Blockly.Events.recordUndo)if(a=Blockly.Xml.domToBlock(b,a.workspace),a.outputConnection)this.connect(a.outputConnection);else if(a.previousConnection)this.connect(a.previousConnection);else throw Error("Child block does not have output or previous statement.");}; Blockly.Connection.prototype.targetBlock=function(){return this.isConnected()?this.targetConnection.getSourceBlock():null};Blockly.Connection.prototype.checkType_=function(a){if(!this.check_||!a.check_)return!0;for(var b=0;b=this.connections_.length)return-1;for(var c=a.y_,d=b;0<=d&&this.connections_[d].y_==c;){if(this.connections_[d]==a)return d;d--}for(;bc)){var d=b.getSvgXY(a.getSvgRoot());a.outputConnection?(d.x+=(a.RTL?3:-3)*c,d.y+=13*c):a.previousConnection&&(d.x+=(a.RTL?-23:23)*c,d.y+=3*c);a=Blockly.utils.createSvgElement("circle",{cx:d.x,cy:d.y,r:0,fill:"none",stroke:"#888","stroke-width":10},b.getParentSvg());Blockly.BlockAnimations.connectionUiStep_(a,new Date,c)}}; -Blockly.BlockAnimations.connectionUiStep_=function(a,b,c){var d=(new Date-b)/150;1a.workspace.scale)){var b=a.getHeightWidth().height;b=Math.atan(10/b)/Math.PI*180;a.RTL||(b*=-1);Blockly.BlockAnimations.disconnectUiStep_(a.getSvgRoot(),b,new Date)}}; Blockly.BlockAnimations.disconnectUiStep_=function(a,b,c){var d=(new Date-c)/200;1b?!1:Blockly.RenderedConnection.superClass_.isConnectionAllowed.call(this,a)}; Blockly.RenderedConnection.prototype.connect=function(a){Blockly.RenderedConnection.superClass_.connect.call(this,a);if(this.hidden_||a.hidden_){a=this.isSuperior()?this:a;a.hidden_?a.hideAll():a.unhideAll();var b=a.targetBlock(),c=a.hidden_?"none":"block";b.getSvgRoot().style.display=c;b.rendered=!a.hidden_}}; Blockly.RenderedConnection.prototype.disconnect=function(){var a=this.isSuperior()?this:this.targetConnection;if(this.targetConnection&&a.hidden_){a.unhideAll();var b=a.targetBlock();b.getSvgRoot().style.display="block";b.rendered=!0;a.setHidden(!0)}Blockly.RenderedConnection.superClass_.disconnect.call(this)}; @@ -1133,20 +1132,20 @@ Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_=function(){this.woul Blockly.BlockDragger.prototype.pixelsToWorkspaceUnits_=function(a){a=new Blockly.utils.Coordinate(a.x/this.workspace_.scale,a.y/this.workspace_.scale);this.workspace_.isMutator&&a.scale(1/this.workspace_.options.parentWorkspace.scale);return a};Blockly.BlockDragger.prototype.dragIcons_=function(a){for(var b=0;bBlockly.Tooltip.RADIUS_OK&&Blockly.Tooltip.hide()}else Blockly.Tooltip.poisonedElement_!=Blockly.Tooltip.element_&&(clearTimeout(Blockly.Tooltip.showPid_),Blockly.Tooltip.lastX_=a.pageX,Blockly.Tooltip.lastY_=a.pageY,Blockly.Tooltip.showPid_= setTimeout(Blockly.Tooltip.show_,Blockly.Tooltip.HOVER_MS))};Blockly.Tooltip.hide=function(){Blockly.Tooltip.visible&&(Blockly.Tooltip.visible=!1,Blockly.Tooltip.DIV&&(Blockly.Tooltip.DIV.style.display="none"));Blockly.Tooltip.showPid_&&clearTimeout(Blockly.Tooltip.showPid_)};Blockly.Tooltip.block=function(){Blockly.Tooltip.hide();Blockly.Tooltip.blocked_=!0};Blockly.Tooltip.unblock=function(){Blockly.Tooltip.blocked_=!1}; -Blockly.Tooltip.show_=function(){if(!Blockly.Tooltip.blocked_&&(Blockly.Tooltip.poisonedElement_=Blockly.Tooltip.element_,Blockly.Tooltip.DIV)){Blockly.Tooltip.DIV.innerHTML="";for(var a=Blockly.Tooltip.element_.tooltip;"function"==typeof a;)a=a();a=Blockly.utils.wrap(a,Blockly.Tooltip.LIMIT);a=a.split("\n");for(var b=0;bc+window.scrollY&&(e-=Blockly.Tooltip.DIV.offsetHeight+2*Blockly.Tooltip.OFFSET_Y);a?d=Math.max(Blockly.Tooltip.MARGINS-window.scrollX, d):d+Blockly.Tooltip.DIV.offsetWidth>b+window.scrollX-2*Blockly.Tooltip.MARGINS&&(d=b-Blockly.Tooltip.DIV.offsetWidth-2*Blockly.Tooltip.MARGINS);Blockly.Tooltip.DIV.style.top=e+"px";Blockly.Tooltip.DIV.style.left=d+"px"}};Blockly.Gesture=function(a,b){this.startWorkspace_=this.targetBlock_=this.startBlock_=this.startField_=this.startBubble_=this.currentDragDeltaXY_=this.mouseDownXY_=null;this.creatorWorkspace_=b;this.isDraggingBubble_=this.isDraggingBlock_=this.isDraggingWorkspace_=this.hasExceededDragRadius_=!1;this.mostRecentEvent_=a;this.flyout_=this.workspaceDragger_=this.blockDragger_=this.bubbleDragger_=this.onUpWrapper_=this.onMoveWrapper_=null;this.isEnding_=this.hasStarted_=this.calledUpdateIsDragging_=!1; this.healStack_=!Blockly.DRAG_STACK}; @@ -1195,14 +1194,14 @@ Blockly.Gesture.inProgress=function(){for(var a=Blockly.Workspace.getAll(),b=0,c Blockly.Grid.prototype.update=function(a){this.scale_=a;var b=this.spacing_*a||100;this.gridPattern_.setAttribute("width",b);this.gridPattern_.setAttribute("height",b);b=Math.floor(this.spacing_/2)+.5;var c=b-this.length_/2,d=b+this.length_/2;b*=a;c*=a;d*=a;this.setLineAttributes_(this.line1_,a,c,d,b,b);this.setLineAttributes_(this.line2_,a,b,b,c,d)}; Blockly.Grid.prototype.setLineAttributes_=function(a,b,c,d,e,f){a&&(a.setAttribute("stroke-width",b),a.setAttribute("x1",c),a.setAttribute("y1",e),a.setAttribute("x2",d),a.setAttribute("y2",f))};Blockly.Grid.prototype.moveTo=function(a,b){this.gridPattern_.setAttribute("x",a);this.gridPattern_.setAttribute("y",b);(Blockly.userAgent.IE||Blockly.userAgent.EDGE)&&this.update(this.scale_)}; Blockly.Grid.createDom=function(a,b,c){a=Blockly.utils.createSvgElement("pattern",{id:"blocklyGridPattern"+a,patternUnits:"userSpaceOnUse"},c);0=c+this.handleLength_&&(d+= e);this.setHandlePosition(this.constrainHandle_(d));this.onScroll_();a.stopPropagation();a.preventDefault()}}; @@ -1239,8 +1238,8 @@ Blockly.Trashcan.prototype.SPRITE_LEFT_=0;Blockly.Trashcan.prototype.SPRITE_TOP_ Blockly.Trashcan.prototype.createDom=function(){this.svgGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyTrash"},null);var a=String(Math.random()).substring(2);var b=Blockly.utils.createSvgElement("clipPath",{id:"blocklyTrashBodyClipPath"+a},this.svgGroup_);Blockly.utils.createSvgElement("rect",{width:this.WIDTH_,height:this.BODY_HEIGHT_,y:this.LID_HEIGHT_},b);var c=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,x:-this.SPRITE_LEFT_,height:Blockly.SPRITE.height,y:-this.SPRITE_TOP_, "clip-path":"url(#blocklyTrashBodyClipPath"+a+")"},this.svgGroup_);c.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.workspace_.options.pathToMedia+Blockly.SPRITE.url);b=Blockly.utils.createSvgElement("clipPath",{id:"blocklyTrashLidClipPath"+a},this.svgGroup_);Blockly.utils.createSvgElement("rect",{width:this.WIDTH_,height:this.LID_HEIGHT_},b);this.svgLid_=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,x:-this.SPRITE_LEFT_,height:Blockly.SPRITE.height,y:-this.SPRITE_TOP_, "clip-path":"url(#blocklyTrashLidClipPath"+a+")"},this.svgGroup_);this.svgLid_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.workspace_.options.pathToMedia+Blockly.SPRITE.url);Blockly.bindEventWithChecks_(this.svgGroup_,"mouseup",this,this.click);Blockly.bindEvent_(c,"mouseover",this,this.mouseOver_);Blockly.bindEvent_(c,"mouseout",this,this.mouseOut_);this.animateLid_();return this.svgGroup_}; -Blockly.Trashcan.prototype.init=function(a){0this.minOpenness_&&1>this.lidOpen_&&(this.lidTask_=setTimeout(this.animateLid_.bind(this),20))}; @@ -1278,22 +1277,22 @@ x1:2*a/3,y1:a-1,x2:a-1,y2:2*a/3},this.resizeGroup_)}; Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_=function(){this.deleteGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyCommentDeleteIcon"},this.svgGroup_);this.deleteIconBorder_=Blockly.utils.createSvgElement("circle",{"class":"blocklyDeleteIconShape",r:"7",cx:"7.5",cy:"7.5"},this.deleteGroup_);Blockly.utils.createSvgElement("line",{x1:"5",y1:"10",x2:"10",y2:"5",stroke:"#fff","stroke-width":"2"},this.deleteGroup_);Blockly.utils.createSvgElement("line",{x1:"5",y1:"5",x2:"10",y2:"10", stroke:"#fff","stroke-width":"2"},this.deleteGroup_)}; Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_=function(a){this.unbindDragEvents_();Blockly.utils.isRightButton(a)||(this.workspace.startDrag(a,new Blockly.utils.Coordinate(this.workspace.RTL?-this.width_:this.width_,this.height_)),this.onMouseUpWrapper_=Blockly.bindEventWithChecks_(document,"mouseup",this,this.resizeMouseUp_),this.onMouseMoveWrapper_=Blockly.bindEventWithChecks_(document,"mousemove",this,this.resizeMouseMove_),Blockly.hideChaff());a.stopPropagation()}; -Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_=function(a){Blockly.utils.addClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted");a.stopPropagation()};Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_=function(){Blockly.utils.removeClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted")};Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_=function(a){this.dispose(!0,!0);a.stopPropagation()}; +Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_=function(a){Blockly.utils.dom.addClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted");a.stopPropagation()};Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_=function(a){Blockly.utils.dom.removeClass(this.deleteIconBorder_,"blocklyDeleteIconHighlighted")};Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_=function(a){this.dispose(!0,!0);a.stopPropagation()}; Blockly.WorkspaceCommentSvg.prototype.unbindDragEvents_=function(){this.onMouseUpWrapper_&&(Blockly.unbindEvent_(this.onMouseUpWrapper_),this.onMouseUpWrapper_=null);this.onMouseMoveWrapper_&&(Blockly.unbindEvent_(this.onMouseMoveWrapper_),this.onMouseMoveWrapper_=null)};Blockly.WorkspaceCommentSvg.prototype.resizeMouseUp_=function(){Blockly.Touch.clearTouchIdentifier();this.unbindDragEvents_()}; Blockly.WorkspaceCommentSvg.prototype.resizeMouseMove_=function(a){this.autoLayout_=!1;a=this.workspace.moveDrag(a);this.setSize_(this.RTL?-a.x:a.x,a.y)}; Blockly.WorkspaceCommentSvg.prototype.resizeComment_=function(){var a=this.getHeightWidth(),b=Blockly.WorkspaceCommentSvg.TOP_OFFSET,c=2*Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET;this.foreignObject_.setAttribute("width",a.width);this.foreignObject_.setAttribute("height",a.height-b);this.RTL&&this.foreignObject_.setAttribute("x",-a.width);this.textarea_.style.width=a.width-c+"px";this.textarea_.style.height=a.height-c-b+"px"}; Blockly.WorkspaceCommentSvg.prototype.setSize_=function(a,b){a=Math.max(a,45);b=Math.max(b,20+Blockly.WorkspaceCommentSvg.TOP_OFFSET);this.width_=a;this.height_=b;this.svgRect_.setAttribute("width",a);this.svgRect_.setAttribute("height",b);this.svgRectTarget_.setAttribute("width",a);this.svgRectTarget_.setAttribute("height",b);this.svgHandleTarget_.setAttribute("width",a);this.svgHandleTarget_.setAttribute("height",Blockly.WorkspaceCommentSvg.TOP_OFFSET);this.RTL&&(this.svgRect_.setAttribute("transform", "scale(-1 1)"),this.svgRectTarget_.setAttribute("transform","scale(-1 1)"));var c=Blockly.WorkspaceCommentSvg.RESIZE_SIZE;this.resizeGroup_&&(this.RTL?(this.resizeGroup_.setAttribute("transform","translate("+(-a+c)+","+(b-c)+") scale(-1 1)"),this.deleteGroup_.setAttribute("transform","translate("+(-a+c)+","+-c+") scale(-1 1)")):(this.resizeGroup_.setAttribute("transform","translate("+(a-c)+","+(b-c)+")"),this.deleteGroup_.setAttribute("transform","translate("+(a-c)+","+-c+")")));this.resizeComment_()}; -Blockly.WorkspaceCommentSvg.prototype.disposeInternal_=function(){this.svgHandleTarget_=this.svgRectTarget_=this.foreignObject_=this.textarea_=null;this.disposed_=!0};Blockly.WorkspaceCommentSvg.prototype.setFocus=function(){var a=this;this.focused_=!0;setTimeout(function(){a.disposed_||(a.textarea_.focus(),a.addFocus(),Blockly.utils.addClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.addClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)}; -Blockly.WorkspaceCommentSvg.prototype.blurFocus=function(){var a=this;this.focused_=!1;setTimeout(function(){a.disposed_||(a.textarea_.blur(),a.removeFocus(),Blockly.utils.removeClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.removeClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)};Blockly.WorkspaceDragSurfaceSvg=function(a){this.container_=a;this.createDom()};Blockly.WorkspaceDragSurfaceSvg.prototype.SVG_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.dragGroup_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.container_=null; +Blockly.WorkspaceCommentSvg.prototype.disposeInternal_=function(){this.svgHandleTarget_=this.svgRectTarget_=this.foreignObject_=this.textarea_=null;this.disposed_=!0};Blockly.WorkspaceCommentSvg.prototype.setFocus=function(){var a=this;this.focused_=!0;setTimeout(function(){a.disposed_||(a.textarea_.focus(),a.addFocus(),Blockly.utils.dom.addClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.dom.addClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)}; +Blockly.WorkspaceCommentSvg.prototype.blurFocus=function(){var a=this;this.focused_=!1;setTimeout(function(){a.disposed_||(a.textarea_.blur(),a.removeFocus(),Blockly.utils.dom.removeClass(a.svgRectTarget_,"blocklyCommentTargetFocused"),Blockly.utils.dom.removeClass(a.svgHandleTarget_,"blocklyCommentHandleTargetFocused"))},0)};Blockly.WorkspaceDragSurfaceSvg=function(a){this.container_=a;this.createDom()};Blockly.WorkspaceDragSurfaceSvg.prototype.SVG_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.dragGroup_=null;Blockly.WorkspaceDragSurfaceSvg.prototype.container_=null; Blockly.WorkspaceDragSurfaceSvg.prototype.createDom=function(){this.SVG_||(this.SVG_=Blockly.utils.createSvgElement("svg",{xmlns:Blockly.SVG_NS,"xmlns:html":Blockly.HTML_NS,"xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1","class":"blocklyWsDragSurface blocklyOverflowVisible"},null),this.container_.appendChild(this.SVG_))}; Blockly.WorkspaceDragSurfaceSvg.prototype.translateSurface=function(a,b){var c=a.toFixed(0),d=b.toFixed(0);this.SVG_.style.display="block";Blockly.utils.setCssTransform(this.SVG_,"translate3d("+c+"px, "+d+"px, 0px)")};Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation=function(){return Blockly.utils.getRelativeXY(this.SVG_)}; -Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide=function(a){if(!a)throw Error("Couldn't clear and hide the drag surface: missing new surface.");var b=this.SVG_.childNodes[0],c=this.SVG_.childNodes[1];if(!(b&&c&&Blockly.utils.hasClass(b,"blocklyBlockCanvas")&&Blockly.utils.hasClass(c,"blocklyBubbleCanvas")))throw Error("Couldn't clear and hide the drag surface. A node was missing.");null!=this.previousSibling_?Blockly.utils.insertAfter(b,this.previousSibling_):a.insertBefore(b,a.firstChild); -Blockly.utils.insertAfter(c,b);this.SVG_.style.display="none";if(this.SVG_.childNodes.length)throw Error("Drag surface was not cleared.");Blockly.utils.setCssTransform(this.SVG_,"");this.previousSibling_=null}; +Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide=function(a){if(!a)throw Error("Couldn't clear and hide the drag surface: missing new surface.");var b=this.SVG_.childNodes[0],c=this.SVG_.childNodes[1];if(!(b&&c&&Blockly.utils.dom.hasClass(b,"blocklyBlockCanvas")&&Blockly.utils.dom.hasClass(c,"blocklyBubbleCanvas")))throw Error("Couldn't clear and hide the drag surface. A node was missing.");null!=this.previousSibling_?Blockly.utils.dom.insertAfter(b,this.previousSibling_):a.insertBefore(b,a.firstChild); +Blockly.utils.dom.insertAfter(c,b);this.SVG_.style.display="none";if(this.SVG_.childNodes.length)throw Error("Drag surface was not cleared.");Blockly.utils.setCssTransform(this.SVG_,"");this.previousSibling_=null}; Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow=function(a,b,c,d,e,f){if(this.SVG_.childNodes.length)throw Error("Already dragging a block.");this.previousSibling_=c;a.setAttribute("transform","translate(0, 0) scale("+f+")");b.setAttribute("transform","translate(0, 0) scale("+f+")");this.SVG_.setAttribute("width",d);this.SVG_.setAttribute("height",e);this.SVG_.appendChild(a);this.SVG_.appendChild(b);this.SVG_.style.display="block"}; Blockly.ZoomControls=function(a){this.workspace_=a};Blockly.ZoomControls.prototype.WIDTH_=32;Blockly.ZoomControls.prototype.HEIGHT_=110;Blockly.ZoomControls.prototype.MARGIN_BOTTOM_=20;Blockly.ZoomControls.prototype.MARGIN_SIDE_=20;Blockly.ZoomControls.prototype.svgGroup_=null;Blockly.ZoomControls.prototype.left_=0;Blockly.ZoomControls.prototype.top_=0; Blockly.ZoomControls.prototype.createDom=function(){this.svgGroup_=Blockly.utils.createSvgElement("g",{},null);var a=String(Math.random()).substring(2);this.createZoomOutSvg_(a);this.createZoomInSvg_(a);this.workspace_.isMovable()&&this.createZoomResetSvg_(a);return this.svgGroup_};Blockly.ZoomControls.prototype.init=function(a){this.verticalSpacing_=this.MARGIN_BOTTOM_+a;return this.verticalSpacing_+this.HEIGHT_}; -Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; +Blockly.ZoomControls.prototype.dispose=function(){this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.workspace_=null}; Blockly.ZoomControls.prototype.position=function(){if(this.verticalSpacing_){var a=this.workspace_.getMetrics();a&&(this.left_=a.toolboxPosition==Blockly.TOOLBOX_AT_LEFT||this.workspace_.horizontalLayout&&!this.workspace_.RTL?a.viewWidth+a.absoluteLeft-this.WIDTH_-this.MARGIN_SIDE_-Blockly.Scrollbar.scrollbarThickness:this.MARGIN_SIDE_+Blockly.Scrollbar.scrollbarThickness,a.toolboxPosition==Blockly.TOOLBOX_AT_BOTTOM?(this.top_=this.verticalSpacing_,this.zoomInGroup_.setAttribute("transform","translate(0, 34)"), this.zoomResetGroup_&&this.zoomResetGroup_.setAttribute("transform","translate(0, 77)")):(this.top_=a.viewHeight+a.absoluteTop-this.HEIGHT_-this.verticalSpacing_,this.zoomInGroup_.setAttribute("transform","translate(0, 43)"),this.zoomOutGroup_.setAttribute("transform","translate(0, 77)")),this.svgGroup_.setAttribute("transform","translate("+this.left_+","+this.top_+")"))}}; Blockly.ZoomControls.prototype.createZoomOutSvg_=function(a){var b=this.workspace_;this.zoomOutGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyZoom"},this.svgGroup_);var c=Blockly.utils.createSvgElement("clipPath",{id:"blocklyZoomoutClipPath"+a},this.zoomOutGroup_);Blockly.utils.createSvgElement("rect",{width:32,height:32},c);a=Blockly.utils.createSvgElement("image",{width:Blockly.SPRITE.width,height:Blockly.SPRITE.height,x:-64,y:-92,"clip-path":"url(#blocklyZoomoutClipPath"+a+")"},this.zoomOutGroup_); @@ -1308,12 +1307,12 @@ Blockly.Procedures.flyoutCategory)};goog.inherits(Blockly.WorkspaceSvg,Blockly.W Blockly.WorkspaceSvg.prototype.startScrollY=0;Blockly.WorkspaceSvg.prototype.dragDeltaXY_=null;Blockly.WorkspaceSvg.prototype.scale=1;Blockly.WorkspaceSvg.prototype.trashcan=null;Blockly.WorkspaceSvg.prototype.scrollbar=null;Blockly.WorkspaceSvg.prototype.flyout_=null;Blockly.WorkspaceSvg.prototype.toolbox_=null;Blockly.WorkspaceSvg.prototype.currentGesture_=null;Blockly.WorkspaceSvg.prototype.blockDragSurface_=null;Blockly.WorkspaceSvg.prototype.workspaceDragSurface_=null; Blockly.WorkspaceSvg.prototype.useWorkspaceDragSurface_=!1;Blockly.WorkspaceSvg.prototype.isDragSurfaceActive_=!1;Blockly.WorkspaceSvg.prototype.injectionDiv_=null;Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_=null;Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_={};Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_={};Blockly.WorkspaceSvg.prototype.configureContextMenu=null;Blockly.WorkspaceSvg.prototype.targetWorkspace=null;Blockly.WorkspaceSvg.prototype.inverseScreenCTM_=null; Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_=!0;Blockly.WorkspaceSvg.prototype.getInverseScreenCTM=function(){if(this.inverseScreenCTMDirty_){var a=this.getParentSvg().getScreenCTM();a&&(this.inverseScreenCTM_=a.inverse(),this.inverseScreenCTMDirty_=!1)}return this.inverseScreenCTM_};Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM=function(){this.inverseScreenCTMDirty_=!0};Blockly.WorkspaceSvg.prototype.isVisible=function(){return this.isVisible_}; -Blockly.WorkspaceSvg.prototype.getSvgXY=function(a){var b=0,c=0,d=1;if(Blockly.utils.containsNode(this.getCanvas(),a)||Blockly.utils.containsNode(this.getBubbleCanvas(),a))d=this.scale;do{var e=Blockly.utils.getRelativeXY(a);if(a==this.getCanvas()||a==this.getBubbleCanvas())d=1;b+=e.x*d;c+=e.y*d;a=a.parentNode}while(a&&a!=this.getParentSvg());return new Blockly.utils.Coordinate(b,c)};Blockly.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return Blockly.utils.getInjectionDivXY_(this.svgBlockCanvas_)}; +Blockly.WorkspaceSvg.prototype.getSvgXY=function(a){var b=0,c=0,d=1;if(Blockly.utils.dom.containsNode(this.getCanvas(),a)||Blockly.utils.dom.containsNode(this.getBubbleCanvas(),a))d=this.scale;do{var e=Blockly.utils.getRelativeXY(a);if(a==this.getCanvas()||a==this.getBubbleCanvas())d=1;b+=e.x*d;c+=e.y*d;a=a.parentNode}while(a&&a!=this.getParentSvg());return new Blockly.utils.Coordinate(b,c)};Blockly.WorkspaceSvg.prototype.getOriginOffsetInPixels=function(){return Blockly.utils.getInjectionDivXY_(this.svgBlockCanvas_)}; Blockly.WorkspaceSvg.prototype.getInjectionDiv=function(){if(!this.injectionDiv_)for(var a=this.svgGroup_;a;){if(-1!=(" "+(a.getAttribute("class")||"")+" ").indexOf(" injectionDiv ")){this.injectionDiv_=a;break}a=a.parentNode}return this.injectionDiv_};Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper=function(a){this.resizeHandlerWrapper_=a}; Blockly.WorkspaceSvg.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.createSvgElement("g",{"class":"blocklyWorkspace"},null);a&&(this.svgBackground_=Blockly.utils.createSvgElement("rect",{height:"100%",width:"100%","class":a},this.svgGroup_),"blocklyMainBackground"==a&&this.grid_&&(this.svgBackground_.style.fill="url(#"+this.grid_.getPatternId()+")"));this.svgBlockCanvas_=Blockly.utils.createSvgElement("g",{"class":"blocklyBlockCanvas"},this.svgGroup_);this.svgBubbleCanvas_=Blockly.utils.createSvgElement("g", {"class":"blocklyBubbleCanvas"},this.svgGroup_);this.isFlyout||(Blockly.bindEventWithChecks_(this.svgGroup_,"mousedown",this,this.onMouseDown_,!1,!0),Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.onMouseWheel_));this.options.hasCategories&&(this.toolbox_=new Blockly.Toolbox(this));this.grid_&&this.grid_.update(this.scale);this.recordDeleteAreas();return this.svgGroup_}; -Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;this.currentGesture_&&this.currentGesture_.cancel();Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(Blockly.utils.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.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.removeNode(a)}this.resizeHandlerWrapper_&&(Blockly.unbindEvent_(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)}; +Blockly.WorkspaceSvg.prototype.dispose=function(){this.rendered=!1;this.currentGesture_&&this.currentGesture_.cancel();Blockly.WorkspaceSvg.superClass_.dispose.call(this);this.svgGroup_&&(Blockly.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.flyoutButtonCallbacks_=this.toolboxCategoryCallbacks_=null;if(!this.options.parentWorkspace){var a=this.getParentSvg().parentNode;a&&Blockly.utils.dom.removeNode(a)}this.resizeHandlerWrapper_&&(Blockly.unbindEvent_(this.resizeHandlerWrapper_),this.resizeHandlerWrapper_=null)}; Blockly.WorkspaceSvg.prototype.newBlock=function(a,b){return new Blockly.BlockSvg(this,a,b)};Blockly.WorkspaceSvg.prototype.addTrashcan=function(){this.trashcan=new Blockly.Trashcan(this);var a=this.trashcan.createDom();this.svgGroup_.insertBefore(a,this.svgBlockCanvas_)};Blockly.WorkspaceSvg.prototype.addZoomControls=function(){this.zoomControls_=new Blockly.ZoomControls(this);var a=this.zoomControls_.createDom();this.svgGroup_.appendChild(a)}; Blockly.WorkspaceSvg.prototype.addFlyout_=function(a){var b={disabledPatternId:this.options.disabledPatternId,parentWorkspace:this,RTL:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,toolboxPosition:this.options.toolboxPosition};this.flyout_=this.horizontalLayout?new Blockly.HorizontalFlyout(b):new Blockly.VerticalFlyout(b);this.flyout_.autoClose=!1;return this.flyout_.createDom(a)}; Blockly.WorkspaceSvg.prototype.getFlyout=function(){return this.flyout_?this.flyout_:this.toolbox_?this.toolbox_.flyout_:null};Blockly.WorkspaceSvg.prototype.getToolbox=function(){return this.toolbox_};Blockly.WorkspaceSvg.prototype.updateScreenCalculations_=function(){this.updateInverseScreenCTM();this.recordDeleteAreas()}; @@ -1352,7 +1351,7 @@ this.options.languageTree=a;this.flyout_.show(a.childNodes)}}else if(this.option Blockly.WorkspaceSvg.prototype.zoom=function(a,b,c){c=Math.pow(this.options.zoomOptions.scaleSpeed,c);var d=this.scale*c;if(this.scale!=d){d>this.options.zoomOptions.maxScale?c=this.options.zoomOptions.maxScale/this.scale:dthis.options.zoomOptions.maxScale?a=this.options.zoomOptions.maxScale:this.options.zoomOptions.minScale&&aa||Math.abs(this.workspaceHeight_-b)>a)this.workspaceWidth_=c,this.workspaceHeight_=b,this.bubble_.setBubbleSize(c+a,b+a),this.svgDialog_.setAttribute("width",this.workspaceWidth_), this.svgDialog_.setAttribute("height",this.workspaceHeight_);this.block_.RTL&&(a="translate("+this.workspaceWidth_+",0)",this.workspace_.getCanvas().setAttribute("transform",a));this.workspace_.resize()}; Blockly.Mutator.prototype.setVisible=function(a){if(a!=this.isVisible())if(Blockly.Events.fire(new Blockly.Events.Ui(this.block_,"mutatorOpen",!a,a)),a){this.bubble_=new Blockly.Bubble(this.block_.workspace,this.createEditor_(),this.block_.svgPath_,this.iconXY_,null,null);this.bubble_.setSvgId(this.block_.id);if(a=this.workspace_.options.languageTree)this.workspace_.flyout_.init(this.workspace_),this.workspace_.flyout_.show(a.childNodes);this.rootBlock_=this.block_.decompose(this.workspace_);a=this.rootBlock_.getDescendants(!1); @@ -1401,8 +1400,8 @@ Blockly.Field.prototype.SERIALIZABLE=!1;Blockly.Field.prototype.setSourceBlock=f Blockly.Field.prototype.init=function(){this.fieldGroup_||(this.fieldGroup_=Blockly.utils.createSvgElement("g",{},null),this.isVisible()||(this.fieldGroup_.style.display="none"),this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_),this.initView(),this.updateEditable(),this.setTooltip(),this.bindEvents_(),this.initModel())};Blockly.Field.prototype.initView=function(){this.createBorderRect_();this.createTextElement_()}; Blockly.Field.prototype.createBorderRect_=function(){this.borderRect_=Blockly.utils.createSvgElement("rect",{rx:4,ry:4,x:-Blockly.BlockSvg.SEP_SPACE_X/2,y:0,height:16,width:this.size_.width+Blockly.BlockSvg.SEP_SPACE_X},this.fieldGroup_)};Blockly.Field.prototype.createTextElement_=function(){this.textElement_=Blockly.utils.createSvgElement("text",{"class":"blocklyText",y:this.size_.height-12.5},this.fieldGroup_);this.textContent_=document.createTextNode("");this.textElement_.appendChild(this.textContent_)}; Blockly.Field.prototype.bindEvents_=function(){Blockly.Tooltip.bindMouseEvents(this.getClickTarget_());this.mouseDownWrapper_=Blockly.bindEventWithChecks_(this.getClickTarget_(),"mousedown",this,this.onMouseDown_)};Blockly.Field.prototype.initModel=function(){};Blockly.Field.prototype.fromXml=function(a){this.setValue(a.textContent)};Blockly.Field.prototype.toXml=function(a){a.textContent=this.getValue();return a}; -Blockly.Field.prototype.dispose=function(){this.mouseDownWrapper_&&(Blockly.unbindEvent_(this.mouseDownWrapper_),this.mouseDownWrapper_=null);this.sourceBlock_=null;this.fieldGroup_&&(Blockly.utils.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.validator_=this.borderRect_=this.textElement_=null}; -Blockly.Field.prototype.updateEditable=function(){var a=this.getClickTarget_();this.EDITABLE&&a&&(this.sourceBlock_.isEditable()?(Blockly.utils.addClass(a,"blocklyEditableText"),Blockly.utils.removeClass(a,"blocklyNonEditableText"),a.style.cursor=this.CURSOR):(Blockly.utils.addClass(a,"blocklyNonEditableText"),Blockly.utils.removeClass(a,"blocklyEditableText"),a.style.cursor=""))};Blockly.Field.prototype.isClickable=function(){return!!this.showEditor_&&"function"===typeof this.showEditor_}; +Blockly.Field.prototype.dispose=function(){this.mouseDownWrapper_&&(Blockly.unbindEvent_(this.mouseDownWrapper_),this.mouseDownWrapper_=null);this.sourceBlock_=null;this.fieldGroup_&&(Blockly.utils.dom.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.validator_=this.borderRect_=this.textElement_=null}; +Blockly.Field.prototype.updateEditable=function(){var a=this.getClickTarget_();this.EDITABLE&&a&&(this.sourceBlock_.isEditable()?(Blockly.utils.dom.addClass(a,"blocklyEditableText"),Blockly.utils.dom.removeClass(a,"blocklyNonEditableText"),a.style.cursor=this.CURSOR):(Blockly.utils.dom.addClass(a,"blocklyNonEditableText"),Blockly.utils.dom.removeClass(a,"blocklyEditableText"),a.style.cursor=""))};Blockly.Field.prototype.isClickable=function(){return!!this.showEditor_&&"function"===typeof this.showEditor_}; Blockly.Field.prototype.isCurrentlyEditable=function(){return this.EDITABLE&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()};Blockly.Field.prototype.isSerializable=function(){var a=!1;this.name&&(this.SERIALIZABLE?a=!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."),a=!0));return a};Blockly.Field.prototype.isVisible=function(){return this.visible_}; Blockly.Field.prototype.setVisible=function(a){if(this.visible_!=a){this.visible_=a;var b=this.getSvgRoot();b&&(b.style.display=a?"block":"none")}};Blockly.Field.prototype.setValidator=function(a){this.validator_=a};Blockly.Field.prototype.getValidator=function(){return this.validator_};Blockly.Field.prototype.classValidator=function(a){return a}; Blockly.Field.prototype.callValidator=function(a){var b=this.classValidator(a);if(null===b)return null;void 0!==b&&(a=b);if(b=this.getValidator()){b=b.call(this,a);if(null===b)return null;void 0!==b&&(a=b)}return a};Blockly.Field.prototype.getSvgRoot=function(){return this.fieldGroup_};Blockly.Field.prototype.updateColour=function(){};Blockly.Field.prototype.render_=function(){this.textContent_.nodeValue=this.getDisplayText_();this.updateSize_()}; @@ -1415,7 +1414,7 @@ Blockly.Field.prototype.forceRerender=function(){this.isDirty_=!0;this.sourceBlo Blockly.Field.prototype.setValue=function(a){if(null!==a){var b=this.doClassValidation_(a);void 0!==b&&(a=b);if(null===a)this.doValueInvalid_(),this.isDirty_&&this.forceRerender();else{if(b=this.getValidator())if(b=b.call(this,a),void 0!==b&&(a=b),null===a){this.doValueInvalid_();this.isDirty_&&this.forceRerender();return}b=this.getValue();b!==a&&(this.sourceBlock_&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.BlockChange(this.sourceBlock_,"field",this.name,b,a)),this.doValueUpdate_(a), this.isDirty_&&this.forceRerender())}}};Blockly.Field.prototype.value_=null;Blockly.Field.prototype.doClassValidation_=function(a){return a=this.classValidator(a)};Blockly.Field.prototype.doValueUpdate_=function(a){this.value_=a;this.isDirty_=!0;this.text_=String(a)};Blockly.Field.prototype.doValueInvalid_=function(){};Blockly.Field.prototype.onMouseDown_=function(a){this.sourceBlock_&&this.sourceBlock_.workspace&&(a=this.sourceBlock_.workspace.getGesture(a))&&a.setStartField(this)}; Blockly.Field.prototype.setTooltip=function(a){a||""===a?this.getClickTarget_().tooltip=a:this.getClickTarget_().tooltip=this.sourceBlock_};Blockly.Field.prototype.getClickTarget_=function(){return this.clickTarget_||this.getSvgRoot()};Blockly.Field.prototype.getAbsoluteXY_=function(){return goog.style.getPageOffset(this.borderRect_)};Blockly.Field.prototype.referencesVariables=function(){return!1};Blockly.FieldLabel=function(a,b){this.size_=new goog.math.Size(0,17.5);this.class_=b;a=this.doClassValidation_(a);null===a&&(a="");this.setValue(a)};goog.inherits(Blockly.FieldLabel,Blockly.Field);Blockly.FieldLabel.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.text);return new Blockly.FieldLabel(b,a["class"])};Blockly.FieldLabel.prototype.EDITABLE=!1; -Blockly.FieldLabel.prototype.initView=function(){this.createTextElement_();this.textElement_.setAttribute("y",this.size_.height-5);this.class_&&Blockly.utils.addClass(this.textElement_,this.class_)};Blockly.FieldLabel.prototype.dispose=function(){this.textElement_&&(Blockly.utils.removeNode(this.textElement_),this.textElement_=null)};Blockly.FieldLabel.prototype.doClassValidation_=function(a){return null===a||void 0===a?null:String(a)};Blockly.Field.register("field_label",Blockly.FieldLabel);Blockly.Input=function(a,b,c,d){if(a!=Blockly.DUMMY_INPUT&&!b)throw Error("Value inputs and statement inputs must have non-empty name.");this.type=a;this.name=b;this.sourceBlock_=c;this.connection=d;this.fieldRow=[]};Blockly.Input.prototype.align=Blockly.ALIGN_LEFT;Blockly.Input.prototype.visible_=!0;Blockly.Input.prototype.appendField=function(a,b){this.insertFieldAt(this.fieldRow.length,a,b);return this}; +Blockly.FieldLabel.prototype.initView=function(){this.createTextElement_();this.textElement_.setAttribute("y",this.size_.height-5);this.class_&&Blockly.utils.dom.addClass(this.textElement_,this.class_)};Blockly.FieldLabel.prototype.dispose=function(){this.textElement_&&(Blockly.utils.dom.removeNode(this.textElement_),this.textElement_=null)};Blockly.FieldLabel.prototype.doClassValidation_=function(a){return null===a||void 0===a?null:String(a)};Blockly.Field.register("field_label",Blockly.FieldLabel);Blockly.Input=function(a,b,c,d){if(a!=Blockly.DUMMY_INPUT&&!b)throw Error("Value inputs and statement inputs must have non-empty name.");this.type=a;this.name=b;this.sourceBlock_=c;this.connection=d;this.fieldRow=[]};Blockly.Input.prototype.align=Blockly.ALIGN_LEFT;Blockly.Input.prototype.visible_=!0;Blockly.Input.prototype.appendField=function(a,b){this.insertFieldAt(this.fieldRow.length,a,b);return this}; Blockly.Input.prototype.insertFieldAt=function(a,b,c){if(0>a||a>this.fieldRow.length)throw Error("index "+a+" out of bounds.");if(!b&&!c)return a;"string"==typeof b&&(b=new Blockly.FieldLabel(b));b.setSourceBlock(this.sourceBlock_);this.sourceBlock_.rendered&&b.init();b.name=c;b.prefixField&&(a=this.insertFieldAt(a,b.prefixField));this.fieldRow.splice(a,0,b);++a;b.suffixField&&(a=this.insertFieldAt(a,b.suffixField));this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_()); return a};Blockly.Input.prototype.removeField=function(a){for(var b=0,c;c=this.fieldRow[b];b++)if(c.name===a){c.dispose();this.fieldRow.splice(b,1);this.sourceBlock_.rendered&&(this.sourceBlock_.render(),this.sourceBlock_.bumpNeighbours_());return}throw Error('Field "%s" not found.',a);};Blockly.Input.prototype.isVisible=function(){return this.visible_}; Blockly.Input.prototype.setVisible=function(a){var b=[];if(this.visible_==a)return b;for(var c=(this.visible_=a)?"block":"none",d=0,e;e=this.fieldRow[d];d++)e.setVisible(a);this.connection&&(a?b=this.connection.unhideAll():this.connection.hideAll(),d=this.connection.targetBlock())&&(d.getSvgRoot().style.display=c,a||(d.rendered=!1));return b};Blockly.Input.prototype.setCheck=function(a){if(!this.connection)throw Error("This input does not have a connection.");this.connection.setCheck(a);return this}; @@ -1445,7 +1444,7 @@ Blockly.Block.prototype.setConnectionsHidden=function(a){if(!a&&this.isCollapsed Blockly.Block.prototype.getMatchingConnection=function(a,b){var c=this.getConnections_(!0),d=a.getConnections_(!0);if(c.length!=d.length)throw Error("Connection lists did not match in length.");for(var e=0;e=c)this.hue_=c,this.colour_=Blockly.utils.colour.hueToHex(c);else if(c=Blockly.utils.colour.parse(b))this.colour_=c,this.hue_=null;else throw c='Invalid colour: "'+b+'"',a!=b&&(c+=' (from "'+a+'")'),Error(c);}; +Blockly.Block.prototype.setColour=function(a){var b="string"==typeof a?Blockly.utils.replaceMessageReferences(a):a,c=Number(b);if(!isNaN(c)&&0<=c&&360>=c)this.hue_=c,this.colour_=Blockly.hueToHex(c);else if(c=Blockly.utils.colour.parse(b))this.colour_=c,this.hue_=null;else throw c='Invalid colour: "'+b+'"',a!=b&&(c+=' (from "'+a+'")'),Error(c);}; Blockly.Block.prototype.setStyle=function(a){var b=Blockly.getTheme();if(!b)throw Error("Trying to set block style to "+a+" before theme was defined via Blockly.setTheme().");b=b.getBlockStyle(a);this.styleName_=a;if(b)this.colourSecondary_=b.colourSecondary,this.colourTertiary_=b.colourTertiary,this.hat=b.hat,this.setColour(b.colourPrimary);else throw Error("Invalid style name: "+a);}; Blockly.Block.prototype.setOnChange=function(a){if(a&&"function"!=typeof a)throw Error("onchange must be a function.");this.onchangeWrapper_&&this.workspace.removeChangeListener(this.onchangeWrapper_);if(this.onchange=a)this.onchangeWrapper_=a.bind(this),this.workspace.addChangeListener(this.onchangeWrapper_)};Blockly.Block.prototype.getField=function(a){for(var b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)if(e.name===a)return e;return null}; Blockly.Block.prototype.getVars=function(){for(var a=[],b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)e.referencesVariables()&&a.push(e.getValue());return a};Blockly.Block.prototype.getVarModels=function(){for(var a=[],b=0,c;c=this.inputList[b];b++)for(var d=0,e;e=c.fieldRow[d];d++)e.referencesVariables()&&(e=this.workspace.getVariableById(e.getValue()))&&a.push(e);return a}; @@ -1466,7 +1465,7 @@ a.inputsInline&&this.setInputsInline(a.inputsInline);void 0!==a.output&&this.set Blockly.Block.prototype.jsonInitColour_=function(a,b){if("colour"in a)if(void 0===a.colour)console.warn(b+"Undefined colour value.");else{var c=a.colour;try{this.setColour(c)}catch(d){console.warn(b+"Illegal colour value: ",c)}}};Blockly.Block.prototype.jsonInitStyle_=function(a,b){var c=a.style;try{this.setStyle(c)}catch(d){console.warn(b+"Style does not exist: ",c)}}; Blockly.Block.prototype.mixin=function(a,b){if(void 0!==b&&"boolean"!=typeof b)throw Error("opt_disableCheck must be a boolean if provided");if(!b){var c=[],d;for(d in a)void 0!==this[d]&&c.push(d);if(c.length)throw Error("Mixin will overwrite block members: "+JSON.stringify(c));}goog.mixin(this,a)}; Blockly.Block.prototype.interpolate_=function(a,b,c){var d=Blockly.utils.tokenizeInterpolation(a),e=[],f=0;a=[];for(var g=0;g=h||h>b.length)throw Error('Block "'+this.type+'": Message index %'+h+" out of range.");if(e[h])throw Error('Block "'+this.type+'": Message index %'+h+" duplicated.");e[h]=!0;f++;a.push(b[h-1])}else(h=h.trim())&&a.push(h)}if(f!=b.length)throw Error('Block "'+this.type+'": Message does not reference all '+b.length+" arg(s)."); -a.length&&("string"==typeof a[a.length-1]||Blockly.utils.startsWith(a[a.length-1].type,"field_"))&&(g={type:"input_dummy"},c&&(g.align=c),a.push(g));c={LEFT:Blockly.ALIGN_LEFT,RIGHT:Blockly.ALIGN_RIGHT,CENTRE:Blockly.ALIGN_CENTRE};b=[];for(g=0;ge.bottom)if(d-f.heighte.bottom)if(d-f.heightc;c+=15)Blockly.utils.createSvgElement("line",{x1:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS,y1:Blockly.FieldAngle.HALF,x2:Blockly.FieldAngle.HALF+ Blockly.FieldAngle.RADIUS-(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+","+Blockly.FieldAngle.HALF+","+Blockly.FieldAngle.HALF+")"},a);c=this.sourceBlock_.getColourBorder();c=null==c.colourBorder?c.colourLight:c.colourBorder;Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(),c);Blockly.DropDownDiv.showPositionedByField(this);this.clickWrapper_=Blockly.bindEvent_(a,"click",this,this.hide_.bind(this));this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove", this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()};Blockly.FieldAngle.prototype.hide_=function(){Blockly.unbindEvent_(this.moveWrapper1_);Blockly.unbindEvent_(this.moveWrapper2_);Blockly.unbindEvent_(this.clickWrapper_);Blockly.DropDownDiv.hideIfOwner(this);Blockly.WidgetDiv.hide()}; -Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;b=a.clientY-b.top-Blockly.FieldAngle.HALF;a=Math.atan(-b/c);isNaN(a)||(a=Blockly.utils.toDegrees(a),0>c?a+=180:0Blockly.FieldAngle.WRAP&& +Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;b=a.clientY-b.top-Blockly.FieldAngle.HALF;a=Math.atan(-b/c);isNaN(a)||(a=Blockly.utils.math.toDegrees(a),0>c?a+=180:0Blockly.FieldAngle.WRAP&& (a-=360),c=String(a),c!=this.text_&&(Blockly.FieldTextInput.htmlInput_.value=a,this.setValue(a),this.text_=c,this.forceRerender()))}; -Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=Blockly.utils.toRadians(a%360);a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF];var c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=Blockly.utils.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS; +Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=Number(this.getText())+Blockly.FieldAngle.OFFSET,b=Blockly.utils.math.toRadians(a%360);a=["M ",Blockly.FieldAngle.HALF,",",Blockly.FieldAngle.HALF];var c=Blockly.FieldAngle.HALF,d=Blockly.FieldAngle.HALF;if(!isNaN(b)){var e=Blockly.utils.math.toRadians(Blockly.FieldAngle.OFFSET),f=Math.cos(e)*Blockly.FieldAngle.RADIUS,g=Math.sin(e)*-Blockly.FieldAngle.RADIUS;Blockly.FieldAngle.CLOCKWISE&&(b=2*e-b);c+=Math.cos(b)*Blockly.FieldAngle.RADIUS; d-=Math.sin(b)*Blockly.FieldAngle.RADIUS;b=Math.abs(Math.floor((b-e)/Math.PI)%2);Blockly.FieldAngle.CLOCKWISE&&(b=1-b);a.push(" l ",f,",",g," A ",Blockly.FieldAngle.RADIUS,",",Blockly.FieldAngle.RADIUS," 0 ",b," ",Number(Blockly.FieldAngle.CLOCKWISE)," ",c,",",d," z")}this.gauge_.setAttribute("d",a.join(""));this.line_.setAttribute("x2",c);this.line_.setAttribute("y2",d)}}; Blockly.FieldAngle.prototype.doClassValidation_=function(a){if(isNaN(a))return null;a=parseFloat(a||0);a%=360;0>a&&(a+=360);a>Blockly.FieldAngle.WRAP&&(a-=360);return a};Blockly.Field.register("field_angle",Blockly.FieldAngle);Blockly.FieldCheckbox=function(a,b){a=this.doClassValidation_(a);null===a&&(a="FALSE");Blockly.FieldCheckbox.superClass_.constructor.call(this,a,b);this.size_.width=Blockly.FieldCheckbox.WIDTH};goog.inherits(Blockly.FieldCheckbox,Blockly.Field);Blockly.FieldCheckbox.fromJson=function(a){return new Blockly.FieldCheckbox(a.checked)};Blockly.FieldCheckbox.WIDTH=5;Blockly.FieldCheckbox.CHECK_CHAR="\u2713";Blockly.FieldCheckbox.CHECK_X_OFFSET=-3;Blockly.FieldCheckbox.CHECK_Y_OFFSET=14; Blockly.FieldCheckbox.prototype.SERIALIZABLE=!0;Blockly.FieldCheckbox.prototype.CURSOR="default";Blockly.FieldCheckbox.prototype.isDirty_=!1; -Blockly.FieldCheckbox.prototype.initView=function(){Blockly.FieldCheckbox.superClass_.initView.call(this);this.textElement_.setAttribute("x",Blockly.FieldCheckbox.CHECK_X_OFFSET);this.textElement_.setAttribute("y",Blockly.FieldCheckbox.CHECK_Y_OFFSET);Blockly.utils.addClass(this.textElement_,"blocklyCheckbox");var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.textElement_.appendChild(a);this.textElement_.style.display=this.value_?"block":"none"}; +Blockly.FieldCheckbox.prototype.initView=function(){Blockly.FieldCheckbox.superClass_.initView.call(this);this.textElement_.setAttribute("x",Blockly.FieldCheckbox.CHECK_X_OFFSET);this.textElement_.setAttribute("y",Blockly.FieldCheckbox.CHECK_Y_OFFSET);Blockly.utils.dom.addClass(this.textElement_,"blocklyCheckbox");var a=document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR);this.textElement_.appendChild(a);this.textElement_.style.display=this.value_?"block":"none"}; Blockly.FieldCheckbox.prototype.showEditor_=function(){this.setValue(!this.value_)};Blockly.FieldCheckbox.prototype.doClassValidation_=function(a){return!0===a||"TRUE"===a?"TRUE":!1===a||"FALSE"===a?"FALSE":null};Blockly.FieldCheckbox.prototype.doValueUpdate_=function(a){this.value_=this.convertValueToBool_(a);this.textElement_&&(this.textElement_.style.display=this.value_?"block":"none")};Blockly.FieldCheckbox.prototype.getValue=function(){return this.value_?"TRUE":"FALSE"}; Blockly.FieldCheckbox.prototype.getValueBoolean=function(){return this.value_};Blockly.FieldCheckbox.prototype.getText=function(){return String(this.convertValueToBool_(this.value_))};Blockly.FieldCheckbox.prototype.convertValueToBool_=function(a){return"string"==typeof a?"TRUE"==a:!!a};Blockly.Field.register("field_checkbox",Blockly.FieldCheckbox);Blockly.utils.colour={};Blockly.utils.colour.parse=function(a){a=String(a).toLowerCase().trim();var b=Blockly.utils.colour.names[a];if(b)return b;b="#"==a[0]?a:"#"+a;if(/^#[0-9a-f]{6}$/.test(b))return b;if(/^#[0-9a-f]{3}$/.test(b))return["#",b[1],b[1],b[2],b[2],b[3],b[3]].join("");var c=a.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return c&&(a=Number(c[1]),b=Number(c[2]),c=Number(c[3]),0<=a&&256>a&&0<=b&&256>b&&0<=c&&256>c)?Blockly.utils.colour.rgbToHex(a,b,c):null}; -Blockly.utils.colour.rgbToHex=function(a,b,c){b=a<<16|b<<8|c;return 16>a?"#"+(16777216|b).toString(16).substr(1):"#"+b.toString(16)};Blockly.utils.colour.hexToRgb=function(a){a=parseInt(a.substr(1),16);return[a>>16,a>>8&255,a&255]};Blockly.utils.colour.hueToHex=function(a){return Blockly.utils.colour.hsvToHex(a,Blockly.HSV_SATURATION,255*Blockly.HSV_VALUE)}; +Blockly.utils.colour.rgbToHex=function(a,b,c){b=a<<16|b<<8|c;return 16>a?"#"+(16777216|b).toString(16).substr(1):"#"+b.toString(16)};Blockly.utils.colour.hexToRgb=function(a){a=parseInt(a.substr(1),16);return[a>>16,a>>8&255,a&255]}; Blockly.utils.colour.hsvToHex=function(a,b,c){var d=0,e=0,f=0;if(0==b)f=e=d=c;else{var g=Math.floor(a/60),h=a/60-g;a=c*(1-b);var k=c*(1-b*h);b=c*(1-b*(1-h));switch(g){case 1:d=k;e=c;f=a;break;case 2:d=a;e=c;f=b;break;case 3:d=a;e=k;f=c;break;case 4:d=b;e=a;f=c;break;case 5:d=c;e=a;f=k;break;case 6:case 0:d=c,e=b,f=a}}return Blockly.utils.colour.rgbToHex(Math.floor(d),Math.floor(e),Math.floor(f))}; Blockly.utils.colour.blend=function(a,b,c){a=Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(a));b=Blockly.utils.colour.hexToRgb(Blockly.utils.colour.parse(b));return Blockly.utils.colour.rgbToHex(Math.round(b[0]+c*(a[0]-b[0])),Math.round(b[1]+c*(a[1]-b[1])),Math.round(b[2]+c*(a[2]-b[2])))}; Blockly.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"};Blockly.FieldColour=function(a,b){a=this.doClassValidation_(a);null===a&&(a=Blockly.FieldColour.COLOURS[0]);Blockly.FieldColour.superClass_.constructor.call(this,a,b)};goog.inherits(Blockly.FieldColour,Blockly.Field);Blockly.FieldColour.fromJson=function(a){return new Blockly.FieldColour(a.colour)};Blockly.FieldColour.DEFAULT_WIDTH=16;Blockly.FieldColour.DEFAULT_HEIGHT=12;Blockly.FieldColour.prototype.SERIALIZABLE=!0;Blockly.FieldColour.prototype.CURSOR="default"; @@ -1629,9 +1628,9 @@ Blockly.FieldDropdown.prototype.initView=function(){Blockly.FieldDropdown.superC this.textContent_):this.textElement_.appendChild(this.arrow_)};Blockly.FieldDropdown.prototype.showEditor_=function(){Blockly.WidgetDiv.show(this,this.sourceBlock_.RTL,null);var a=this.createMenu_();this.addActionListener_(a);this.positionMenu_(a)};Blockly.FieldDropdown.prototype.addActionListener_=function(a){var b=this;goog.events.listen(a,goog.ui.Component.EventType.ACTION,function(a){if(a=a.target)b.onItemSelected(this,a);Blockly.WidgetDiv.hideIfOwner(b);Blockly.Events.setGroup(!1)})}; Blockly.FieldDropdown.prototype.createMenu_=function(){var a=new goog.ui.Menu;a.setRightToLeft(this.sourceBlock_.RTL);for(var b=this.getOptions(),c=0;ce&&(d.height=e);this.sourceBlock_.RTL&&Blockly.utils.uiMenu.adjustBBoxesForRTL(b,c,d);Blockly.WidgetDiv.positionWithAnchor(b,c,d,this.sourceBlock_.RTL);a.getElement().focus()}; -Blockly.FieldDropdown.prototype.createWidget_=function(a){a.render(Blockly.WidgetDiv.DIV);Blockly.utils.addClass(a.getElement(),"blocklyDropdownMenu");a.setAllowAutoFocus(!0)};Blockly.FieldDropdown.prototype.getAnchorDimensions_=function(){var a=this.getScaledBBox_();this.sourceBlock_.RTL?a.right+=Blockly.FieldDropdown.CHECKMARK_OVERHANG:a.left-=Blockly.FieldDropdown.CHECKMARK_OVERHANG;return a};Blockly.FieldDropdown.prototype.onItemSelected=function(a,b){this.setValue(b.getValue())}; -Blockly.FieldDropdown.prototype.trimOptions_=function(){this.suffixField=this.prefixField=null;var a=this.menuGenerator_;if(Array.isArray(a)){for(var b=!1,c=0;ca.length)){b=[];for(c=0;ca.length)){b=[];for(c=0;c=this.height_||0>=this.width_)throw Error("Height and width values of an image field must be greater than 0.");this.size_=new goog.math.Size(this.width_,this.height_+2*Blockly.BlockSvg.INLINE_PADDING_Y);this.flipRtl_=f;this.text_=d||"";this.setValue(a||"");"function"==typeof e&&(this.clickHandler_= e)};goog.inherits(Blockly.FieldImage,Blockly.Field);Blockly.FieldImage.fromJson=function(a){var b=Blockly.utils.replaceMessageReferences(a.src),c=Number(Blockly.utils.replaceMessageReferences(a.width)),d=Number(Blockly.utils.replaceMessageReferences(a.height)),e=Blockly.utils.replaceMessageReferences(a.alt);return new Blockly.FieldImage(b,c,d,e,null,!!a.flipRtl)};Blockly.FieldImage.prototype.EDITABLE=!1;Blockly.FieldImage.prototype.isDirty_=!1; -Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_)};Blockly.FieldImage.prototype.dispose=function(){this.fieldGroup_&&(Blockly.utils.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.imageElement_=null}; +Blockly.FieldImage.prototype.initView=function(){this.imageElement_=Blockly.utils.createSvgElement("image",{height:this.height_+"px",width:this.width_+"px",alt:this.text_},this.fieldGroup_);this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_)};Blockly.FieldImage.prototype.dispose=function(){this.fieldGroup_&&(Blockly.utils.dom.removeNode(this.fieldGroup_),this.fieldGroup_=null);this.imageElement_=null}; Blockly.FieldImage.prototype.doClassValidation_=function(a){return"string"!=typeof a?null:a};Blockly.FieldImage.prototype.doValueUpdate_=function(a){this.value_=a;this.imageElement_&&this.imageElement_.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",this.value_||"")};Blockly.FieldImage.prototype.getFlipRtl=function(){return this.flipRtl_};Blockly.FieldImage.prototype.setText=function(a){null!==a&&(this.text_=a,this.imageElement_&&this.imageElement_.setAttribute("alt",a||""))}; Blockly.FieldImage.prototype.showEditor_=function(){this.clickHandler_&&this.clickHandler_(this)};Blockly.Field.register("field_image",Blockly.FieldImage);Blockly.FieldNumber=function(a,b,c,d,e){this.setConstraints(b,c,d);a=this.doClassValidation_(a);null===a&&(a=0);Blockly.FieldNumber.superClass_.constructor.call(this,a,e)};goog.inherits(Blockly.FieldNumber,Blockly.FieldTextInput);Blockly.FieldNumber.fromJson=function(a){return new Blockly.FieldNumber(a.value,a.min,a.max,a.precision)};Blockly.FieldNumber.prototype.SERIALIZABLE=!0; Blockly.FieldNumber.prototype.setConstraints=function(a,b,c){c=parseFloat(c);this.precision_=isNaN(c)?0:c;c=this.precision_.toString();var d=c.indexOf(".");this.fractionalDigits_=-1==d?-1:c.length-(d+1);a=parseFloat(a);this.min_=isNaN(a)?-Infinity:a;b=parseFloat(b);this.max_=isNaN(b)?Infinity:b;this.setValue(this.getValue())}; @@ -1685,21 +1684,21 @@ Blockly.FlyoutButton.prototype.createDom=function(){var a=this.isLabel_?"blockly rx:4,ry:4},this.svgGroup_);var c=Blockly.utils.createSvgElement("text",{"class":this.isLabel_?"blocklyFlyoutLabelText":"blocklyText",x:0,y:0,"text-anchor":"middle"},this.svgGroup_);c.textContent=Blockly.utils.replaceMessageReferences(this.text_);this.width=Blockly.Field.getCachedWidth(c);this.height=20;this.isLabel_||(this.width+=2*Blockly.FlyoutButton.MARGIN,b.setAttribute("width",this.width),b.setAttribute("height",this.height));a.setAttribute("width",this.width);a.setAttribute("height",this.height); c.setAttribute("x",this.width/2);c.setAttribute("y",this.height-Blockly.FlyoutButton.MARGIN);this.updateTransform_();this.onMouseUpWrapper_=Blockly.bindEventWithChecks_(this.svgGroup_,"mouseup",this,this.onMouseUp_);return this.svgGroup_};Blockly.FlyoutButton.prototype.show=function(){this.updateTransform_();this.svgGroup_.setAttribute("display","block")}; Blockly.FlyoutButton.prototype.updateTransform_=function(){this.svgGroup_.setAttribute("transform","translate("+this.position_.x+","+this.position_.y+")")};Blockly.FlyoutButton.prototype.moveTo=function(a,b){this.position_.x=a;this.position_.y=b;this.updateTransform_()};Blockly.FlyoutButton.prototype.getPosition=function(){return this.position_};Blockly.FlyoutButton.prototype.getTargetWorkspace=function(){return this.targetWorkspace_}; -Blockly.FlyoutButton.prototype.dispose=function(){this.onMouseUpWrapper_&&Blockly.unbindEvent_(this.onMouseUpWrapper_);this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.workspace_=null}; +Blockly.FlyoutButton.prototype.dispose=function(){this.onMouseUpWrapper_&&Blockly.unbindEvent_(this.onMouseUpWrapper_);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.workspace_=null}; Blockly.FlyoutButton.prototype.onMouseUp_=function(a){(a=this.targetWorkspace_.getGesture(a))&&a.cancel();this.isLabel_&&this.callbackKey_?console.warn("Labels should not have callbacks. Label text: "+this.text_):this.isLabel_||this.callbackKey_&&this.targetWorkspace_.getButtonCallback(this.callbackKey_)?this.isLabel_||this.targetWorkspace_.getButtonCallback(this.callbackKey_)(this):console.warn("Buttons should have callbacks. Button text: "+this.text_)};Blockly.Flyout=function(a){a.getMetrics=this.getMetrics_.bind(this);a.setMetrics=this.setMetrics_.bind(this);this.workspace_=new Blockly.WorkspaceSvg(a);this.workspace_.isFlyout=!0;this.RTL=!!a.RTL;this.toolboxPosition_=a.toolboxPosition;this.eventWrappers_=[];this.mats_=[];this.buttons_=[];this.listeners_=[];this.permanentlyDisabled_=[]};Blockly.Flyout.prototype.autoClose=!0;Blockly.Flyout.prototype.isVisible_=!1;Blockly.Flyout.prototype.containerVisible_=!0; Blockly.Flyout.prototype.CORNER_RADIUS=8;Blockly.Flyout.prototype.MARGIN=Blockly.Flyout.prototype.CORNER_RADIUS;Blockly.Flyout.prototype.GAP_X=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.GAP_Y=3*Blockly.Flyout.prototype.MARGIN;Blockly.Flyout.prototype.SCROLLBAR_PADDING=2;Blockly.Flyout.prototype.width_=0;Blockly.Flyout.prototype.height_=0;Blockly.Flyout.prototype.dragAngleRange_=70; Blockly.Flyout.prototype.createDom=function(a){this.svgGroup_=Blockly.utils.createSvgElement(a,{"class":"blocklyFlyout",style:"display: none"},null);this.svgBackground_=Blockly.utils.createSvgElement("path",{"class":"blocklyFlyoutBackground"},this.svgGroup_);this.svgGroup_.appendChild(this.workspace_.createDom());return this.svgGroup_}; Blockly.Flyout.prototype.init=function(a){this.targetWorkspace_=a;this.workspace_.targetWorkspace=a;this.scrollbar_=new Blockly.Scrollbar(this.workspace_,this.horizontalLayout_,!1,"blocklyFlyoutScrollbar");this.hide();Array.prototype.push.apply(this.eventWrappers_,Blockly.bindEventWithChecks_(this.svgGroup_,"wheel",this,this.wheel_));this.autoClose||(this.filterWrapper_=this.filterForCapacity_.bind(this),this.targetWorkspace_.addChangeListener(this.filterWrapper_));Array.prototype.push.apply(this.eventWrappers_, Blockly.bindEventWithChecks_(this.svgBackground_,"mousedown",this,this.onMouseDown_));this.workspace_.getGesture=this.targetWorkspace_.getGesture.bind(this.targetWorkspace_);this.workspace_.variableMap_=this.targetWorkspace_.getVariableMap();this.workspace_.createPotentialVariableMap()}; -Blockly.Flyout.prototype.dispose=function(){this.hide();Blockly.unbindEvent_(this.eventWrappers_);this.filterWrapper_&&(this.targetWorkspace_.removeChangeListener(this.filterWrapper_),this.filterWrapper_=null);this.scrollbar_&&(this.scrollbar_.dispose(),this.scrollbar_=null);this.workspace_&&(this.workspace_.targetWorkspace=null,this.workspace_.dispose(),this.workspace_=null);this.svgGroup_&&(Blockly.utils.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.svgBackground_=null}; -Blockly.Flyout.prototype.getWidth=function(){return this.width_};Blockly.Flyout.prototype.getHeight=function(){return this.height_};Blockly.Flyout.prototype.getWorkspace=function(){return this.workspace_};Blockly.Flyout.prototype.isVisible=function(){return this.isVisible_};Blockly.Flyout.prototype.setVisible=function(a){var b=a!=this.isVisible();this.isVisible_=a;b&&this.updateDisplay_()}; +Blockly.Flyout.prototype.dispose=function(){this.hide();Blockly.unbindEvent_(this.eventWrappers_);this.filterWrapper_&&(this.targetWorkspace_.removeChangeListener(this.filterWrapper_),this.filterWrapper_=null);this.scrollbar_&&(this.scrollbar_.dispose(),this.scrollbar_=null);this.workspace_&&(this.workspace_.targetWorkspace=null,this.workspace_.dispose(),this.workspace_=null);this.svgGroup_&&(Blockly.utils.dom.removeNode(this.svgGroup_),this.svgGroup_=null);this.targetWorkspace_=this.svgBackground_= +null};Blockly.Flyout.prototype.getWidth=function(){return this.width_};Blockly.Flyout.prototype.getHeight=function(){return this.height_};Blockly.Flyout.prototype.getWorkspace=function(){return this.workspace_};Blockly.Flyout.prototype.isVisible=function(){return this.isVisible_};Blockly.Flyout.prototype.setVisible=function(a){var b=a!=this.isVisible();this.isVisible_=a;b&&this.updateDisplay_()}; Blockly.Flyout.prototype.setContainerVisible=function(a){var b=a!=this.containerVisible_;this.containerVisible_=a;b&&this.updateDisplay_()};Blockly.Flyout.prototype.updateDisplay_=function(){var a=this.containerVisible_?this.isVisible():!1;this.svgGroup_.style.display=a?"block":"none";this.scrollbar_.setContainerVisible(a)}; Blockly.Flyout.prototype.positionAt_=function(a,b,c,d){this.svgGroup_.setAttribute("width",a);this.svgGroup_.setAttribute("height",b);"svg"==this.svgGroup_.tagName?Blockly.utils.setCssTransform(this.svgGroup_,"translate("+c+"px,"+d+"px)"):this.svgGroup_.setAttribute("transform","translate("+c+","+d+")");this.scrollbar_&&(this.scrollbar_.setOrigin(c,d),this.scrollbar_.resize(),this.scrollbar_.setPosition_(this.scrollbar_.position_.x,this.scrollbar_.position_.y))}; Blockly.Flyout.prototype.hide=function(){if(this.isVisible()){this.setVisible(!1);for(var a=0,b;b=this.listeners_[a];a++)Blockly.unbindEvent_(b);this.listeners_.length=0;this.reflowWrapper_&&(this.workspace_.removeChangeListener(this.reflowWrapper_),this.reflowWrapper_=null)}}; Blockly.Flyout.prototype.show=function(a){this.workspace_.setResizesEnabled(!1);this.hide();this.clearOldBlocks_();if("string"==typeof a){a=this.workspace_.targetWorkspace.getToolboxCategoryCallback(a);if("function"!=typeof a)throw TypeError("Couldn't find a callback function when opening a toolbox category.");a=a(this.workspace_.targetWorkspace);if(!Array.isArray(a))throw TypeError("Result of toolbox category callback must be an array.");}this.setVisible(!0);var b=[],c=[];this.permanentlyDisabled_.length= 0;for(var d=this.horizontalLayout_?this.GAP_X:this.GAP_Y,e=0,f;f=a[e];e++)if(f.tagName)switch(f.tagName.toUpperCase()){case "BLOCK":var g=Blockly.Xml.domToBlock(f,this.workspace_);g.isEnabled()||this.permanentlyDisabled_.push(g);b.push({type:"block",block:g});f=parseInt(f.getAttribute("gap"),10);c.push(isNaN(f)?d:f);break;case "SEP":f=parseInt(f.getAttribute("gap"),10);!isNaN(f)&&0e?Blockly.WidgetDiv.positionInternal_(a,0,c.height+e):Blockly.WidgetDiv.positionInternal_(a,e,c.height)}; -Blockly.WidgetDiv.calculateX_=function(a,b,c,d){if(d)return b=Math.max(b.right-c.width,a.left),Math.min(b,a.right-c.width);b=Math.min(b.left,a.right-c.width);return Math.max(b,a.left)};Blockly.WidgetDiv.calculateY_=function(a,b,c){return b.bottom+c.height>=a.bottom?b.top-c.height:b.bottom};Blockly.inject=function(a,b){Blockly.checkBlockColourConstants();"string"==typeof a&&(a=document.getElementById(a)||document.querySelector(a));if(!Blockly.utils.containsNode(document,a))throw Error("Error: container is not in current document.");var c=new Blockly.Options(b||{}),d=document.createElement("div");d.className="injectionDiv";a.appendChild(d);var e=Blockly.createDom_(d,c),f=new Blockly.BlockDragSurfaceSvg(d);d=new Blockly.WorkspaceDragSurfaceSvg(d);e=Blockly.createMainWorkspace_(e,c,f,d); -Blockly.setTheme(c.theme);Blockly.init_(e);Blockly.mainWorkspace=e;Blockly.svgResize(e);return e}; +Blockly.WidgetDiv.calculateX_=function(a,b,c,d){if(d)return b=Math.max(b.right-c.width,a.left),Math.min(b,a.right-c.width);b=Math.min(b.left,a.right-c.width);return Math.max(b,a.left)};Blockly.WidgetDiv.calculateY_=function(a,b,c){return b.bottom+c.height>=a.bottom?b.top-c.height:b.bottom};Blockly.inject=function(a,b){Blockly.checkBlockColourConstants();"string"==typeof a&&(a=document.getElementById(a)||document.querySelector(a));if(!Blockly.utils.dom.containsNode(document,a))throw Error("Error: container is not in current document.");var c=new Blockly.Options(b||{}),d=document.createElement("div");d.className="injectionDiv";a.appendChild(d);var e=Blockly.createDom_(d,c),f=new Blockly.BlockDragSurfaceSvg(d);d=new Blockly.WorkspaceDragSurfaceSvg(d);e=Blockly.createMainWorkspace_(e,c, +f,d);Blockly.setTheme(c.theme);Blockly.init_(e);Blockly.mainWorkspace=e;Blockly.svgResize(e);return e}; Blockly.createDom_=function(a,b){a.setAttribute("dir","LTR");goog.ui.Component.setDefaultRightToLeft(b.RTL);Blockly.Css.inject(b.hasCss,b.pathToMedia);var c=Blockly.utils.createSvgElement("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:html":"http://www.w3.org/1999/xhtml","xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1","class":"blocklySvg"},a),d=Blockly.utils.createSvgElement("defs",{},c),e=String(Math.random()).substring(2),f=Blockly.utils.createSvgElement("filter",{id:"blocklyEmbossFilter"+ e},d);Blockly.utils.createSvgElement("feGaussianBlur",{"in":"SourceAlpha",stdDeviation:1,result:"blur"},f);var g=Blockly.utils.createSvgElement("feSpecularLighting",{"in":"blur",surfaceScale:1,specularConstant:.5,specularExponent:10,"lighting-color":"white",result:"specOut"},f);Blockly.utils.createSvgElement("fePointLight",{x:-5E3,y:-1E4,z:2E4},g);Blockly.utils.createSvgElement("feComposite",{"in":"specOut",in2:"SourceAlpha",operator:"in",result:"specOut"},f);Blockly.utils.createSvgElement("feComposite", {"in":"SourceGraphic",in2:"specOut",operator:"arithmetic",k1:0,k2:1,k3:1,k4:0},f);b.embossFilterId=f.id;f=Blockly.utils.createSvgElement("pattern",{id:"blocklyDisabledPattern"+e,patternUnits:"userSpaceOnUse",width:10,height:10},d);Blockly.utils.createSvgElement("rect",{width:10,height:10,fill:"#aaa"},f);Blockly.utils.createSvgElement("path",{d:"M 0 0 L 10 10 M 10 0 L 0 10",stroke:"#cc0"},f);b.disabledPatternId=f.id;b.gridPattern=Blockly.Grid.createDom(e,b.gridOptions,d);return c}; -Blockly.createMainWorkspace_=function(a,b,c,d){b.parentWorkspace=null;var e=new Blockly.WorkspaceSvg(b,c,d);e.scale=b.zoomOptions.startScale;a.appendChild(e.createDom("blocklyMainBackground"));!b.hasCategories&&b.languageTree&&(c=e.addFlyout_("svg"),Blockly.utils.insertAfter(c,a));b.hasTrashcan&&e.addTrashcan();b.zoomOptions&&b.zoomOptions.controls&&e.addZoomControls();e.translate(0,0);Blockly.mainWorkspace=e;b.readOnly||e.isMovable()||e.addChangeListener(function(a){if(!e.isDragging()&&!e.isMovable()&& +Blockly.createMainWorkspace_=function(a,b,c,d){b.parentWorkspace=null;var e=new Blockly.WorkspaceSvg(b,c,d);e.scale=b.zoomOptions.startScale;a.appendChild(e.createDom("blocklyMainBackground"));!b.hasCategories&&b.languageTree&&(c=e.addFlyout_("svg"),Blockly.utils.dom.insertAfter(c,a));b.hasTrashcan&&e.addTrashcan();b.zoomOptions&&b.zoomOptions.controls&&e.addZoomControls();e.translate(0,0);Blockly.mainWorkspace=e;b.readOnly||e.isMovable()||e.addChangeListener(function(a){if(!e.isDragging()&&!e.isMovable()&& -1!=Blockly.Events.BUMP_EVENTS.indexOf(a.type)){var b=Object.create(null),c=e.getMetrics(),d=e.scale;b.viewLeft=c.viewLeft/d;b.viewTop=c.viewTop/d;b.viewRight=(c.viewLeft+c.viewWidth)/d;b.viewBottom=(c.viewTop+c.viewHeight)/d;e.isContentBounded()?(c=e.getBlocksBoundingBox(),b.contentLeft=c.x,b.contentTop=c.y,b.contentRight=c.x+c.width,b.contentBottom=c.y+c.height):(b.contentLeft=c.contentLeft/d,b.contentTop=c.contentTop/d,b.contentRight=(c.contentLeft+c.contentWidth)/d,b.contentBottom=(c.contentTop+ c.contentHeight)/d);if(b.contentTopb.viewBottom||b.contentLeftb.viewRight){c=null;a&&(c=Blockly.Events.getGroup(),Blockly.Events.setGroup(a.group));switch(a.type){case Blockly.Events.BLOCK_CREATE:case Blockly.Events.BLOCK_MOVE:var f=e.getBlockById(a.blockId);f=f.getRootBlock();break;case Blockly.Events.COMMENT_CREATE:case Blockly.Events.COMMENT_MOVE:f=e.getCommentById(a.commentId)}if(f){d=f.getBoundingRectangle();var n=b.viewTop-d.topLeft.y; 0n&&f.moveBy(0,n);n=b.viewLeft-d.topLeft.x;0b&&f.moveBy(b,0)}a&&(a.group||console.log("WARNING: Moved object in bounds but there was no event group. This may break undo."),Blockly.Events.setGroup(c))}}});Blockly.svgResize(e);Blockly.WidgetDiv.createDom();Blockly.DropDownDiv.createDom();Blockly.Tooltip.createDom();return e}; @@ -1816,7 +1815,7 @@ Blockly.defineBlocksWithJsonArray=function(a){for(var b=0;b 1) { - Blockly.utils.removeNode(clone); + Blockly.utils.dom.removeNode(clone); } else { var x = clone.translateX_ + (rtl ? -1 : 1) * clone.bBox_.width * workspaceScale / 2 * percent; @@ -141,7 +142,7 @@ Blockly.BlockAnimations.connectionUiStep_ = function(ripple, start, scale) { var ms = new Date - start; var percent = ms / 150; if (percent > 1) { - Blockly.utils.removeNode(ripple); + Blockly.utils.dom.removeNode(ripple); } else { ripple.setAttribute('r', percent * 25 * scale); ripple.style.opacity = 1 - percent; diff --git a/core/block_render_svg.js b/core/block_render_svg.js index 6c9052934..ebe6012bd 100644 --- a/core/block_render_svg.js +++ b/core/block_render_svg.js @@ -28,7 +28,7 @@ goog.provide('Blockly.BlockSvg.render'); goog.require('Blockly.BlockSvg'); -goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -1199,10 +1199,10 @@ Blockly.BlockSvg.prototype.positionNewBlock = function(newBlock, newConnection, */ Blockly.BlockSvg.prototype.highlightForReplacement = function(add) { if (add) { - Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), + Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyReplaceable'); } else { - Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_), + Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyReplaceable'); } }; diff --git a/core/block_svg.js b/core/block_svg.js index 529e67dac..76d46e53f 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -29,7 +29,6 @@ goog.provide('Blockly.BlockSvg'); goog.require('Blockly.Block'); goog.require('Blockly.BlockAnimations'); goog.require('Blockly.ContextMenu'); -goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.Events'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Events.BlockMove'); @@ -39,6 +38,8 @@ goog.require('Blockly.RenderedConnection'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.Coordinate'); +goog.require('Blockly.utils.dom'); /** @@ -776,11 +777,11 @@ Blockly.BlockSvg.prototype.setDragging = function(adding) { group.skew_ = ''; Blockly.draggingConnections_ = Blockly.draggingConnections_.concat(this.getConnections_(true)); - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } else { Blockly.draggingConnections_ = []; - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } // Recurse through all blocks attached under this one. @@ -794,10 +795,10 @@ Blockly.BlockSvg.prototype.setDragging = function(adding) { */ Blockly.BlockSvg.prototype.updateMovable = function() { if (this.isMovable()) { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable'); } else { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable'); } }; @@ -845,7 +846,7 @@ Blockly.BlockSvg.prototype.setInsertionMarker = function(insertionMarker) { this.isInsertionMarker_ = insertionMarker; if (this.isInsertionMarker_) { this.setColour(Blockly.INSERTION_MARKER_COLOUR); - Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), + Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyInsertionMarker'); } }; @@ -923,7 +924,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { Blockly.Events.fire(deleteEvent); } - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); blockWorkspace.resizeContents(); // Sever JavaScript to DOM connections. this.svgGroup_ = null; @@ -1001,14 +1002,14 @@ Blockly.BlockSvg.prototype.setShadowColour_ = function() { */ Blockly.BlockSvg.prototype.updateDisabled = function() { if (this.disabled || this.getInheritedDisabled()) { - var added = Blockly.utils.addClass( + var added = Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); if (added) { this.svgPath_.setAttribute('fill', 'url(#' + this.workspace.options.disabledPatternId + ')'); } } else { - var removed = Blockly.utils.removeClass( + var removed = Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); if (removed) { this.updateColour(); @@ -1203,7 +1204,7 @@ Blockly.BlockSvg.prototype.setHighlighted = function(highlighted) { * Select this block. Highlight it visually. */ Blockly.BlockSvg.prototype.addSelect = function() { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklySelected'); }; @@ -1211,7 +1212,7 @@ Blockly.BlockSvg.prototype.addSelect = function() { * Unselect this block. Remove its highlighting. */ Blockly.BlockSvg.prototype.removeSelect = function() { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklySelected'); }; @@ -1223,10 +1224,10 @@ Blockly.BlockSvg.prototype.removeSelect = function() { */ Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) { if (enable) { - Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_), + Blockly.utils.dom.addClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); } else { - Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_), + Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); } }; diff --git a/core/blockly.js b/core/blockly.js index eea9c7902..832a6af42 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -600,6 +600,16 @@ Blockly.isNumber = function(str) { return /^\s*-?\d+(\.\d+)?\s*$/.test(str); }; +/** + * Convert a hue (HSV model) into an RGB hex triplet. + * @param {number} hue Hue on a colour wheel (0-360). + * @return {string} RGB code, e.g. '#5ba65b'. + */ +Blockly.hueToHex = function(hue) { + return Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, + Blockly.HSV_VALUE * 255); +}; + /** * Checks old colour constants are not overwritten by the host application. * If a constant is overwritten, it prints a console warning directing the diff --git a/core/bubble.js b/core/bubble.js index 28c1f59f6..7937a7ace 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -30,6 +30,8 @@ goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.Touch'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.math'); goog.require('Blockly.Workspace'); @@ -55,7 +57,7 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY, if (this.workspace_.RTL) { angle = -angle; } - this.arrow_radians_ = Blockly.utils.toRadians(angle); + this.arrow_radians_ = Blockly.utils.math.toRadians(angle); var canvas = workspace.getBubbleCanvas(); canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight))); @@ -758,7 +760,7 @@ Blockly.Bubble.prototype.setColour = function(hexColour) { Blockly.Bubble.prototype.dispose = function() { Blockly.Bubble.unbindDragEvents_(); // Dispose of and unlink the bubble. - Blockly.utils.removeNode(this.bubbleGroup_); + Blockly.utils.dom.removeNode(this.bubbleGroup_); this.bubbleGroup_ = null; this.bubbleArrow_ = null; this.bubbleBack_ = null; diff --git a/core/contextmenu.js b/core/contextmenu.js index 017b11808..3074f1f89 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -36,6 +36,7 @@ goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Msg'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.uiMenu'); goog.require('Blockly.Xml'); @@ -156,7 +157,7 @@ Blockly.ContextMenu.createWidget_ = function(menu) { var div = Blockly.WidgetDiv.DIV; menu.render(div); var menuDom = menu.getElement(); - Blockly.utils.addClass(menuDom, 'blocklyContextMenu'); + Blockly.utils.dom.addClass(menuDom, 'blocklyContextMenu'); // Prevent system context menu when right-clicking a Blockly context menu. Blockly.bindEventWithChecks_( menuDom, 'contextmenu', null, Blockly.utils.noEvent); diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index f5eefa06b..b624b3448 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -28,7 +28,7 @@ goog.provide('Blockly.DropDownDiv'); -goog.require('Blockly.utils'); +goog.require('Blockly.utils.math'); goog.require('goog.style'); @@ -228,10 +228,10 @@ Blockly.DropDownDiv.showPositionedByBlock = function(field, block, * by a particular field. The primary position will be below the field, * and the secondary position above the field. Drop-down will be * constrained to the block's workspace. - * @param {Object} owner The object showing the drop-down. + * @param {!Object} owner The object showing the drop-down. * @param {Function=} opt_onHide Optional callback for when the drop-down is * hidden. - * @param {number} opt_secondaryYOffset Optional Y offset for above-block + * @param {number=} opt_secondaryYOffset Optional Y offset for above-block * positioning. * @return {boolean} True if the menu rendered below block; false if above. */ @@ -272,17 +272,18 @@ Blockly.DropDownDiv.showPositionedByField = function(owner, * @param {Function=} opt_onHide Optional callback for when the drop-down is hidden * @return {boolean} True if the menu rendered at the primary origin point. */ -Blockly.DropDownDiv.show = function(owner, primaryX, primaryY, secondaryX, secondaryY, opt_onHide) { +Blockly.DropDownDiv.show = function(owner, primaryX, primaryY, + secondaryX, secondaryY, opt_onHide) { Blockly.DropDownDiv.owner_ = owner; Blockly.DropDownDiv.onHide_ = opt_onHide; - var metrics = Blockly.DropDownDiv.getPositionMetrics(primaryX, primaryY, secondaryX, secondaryY); - // Update arrow CSS + var metrics = Blockly.DropDownDiv.getPositionMetrics(primaryX, primaryY, + secondaryX, secondaryY); + // Update arrow CSS. Blockly.DropDownDiv.arrow_.style.transform = 'translate(' + - metrics.arrowX + 'px,' + metrics.arrowY + 'px) rotate(45deg)'; - Blockly.DropDownDiv.arrow_.setAttribute('class', - metrics.arrowAtTop ? 'blocklyDropDownArrow arrowTop' : 'blocklyDropDownArrow arrowBottom'); - Blockly.DropDownDiv.arrow_.style.display = - metrics.arrowVisible ? '' : 'none'; + metrics.arrowX + 'px,' + metrics.arrowY + 'px) rotate(45deg)'; + Blockly.DropDownDiv.arrow_.setAttribute('class', metrics.arrowAtTop ? + 'blocklyDropDownArrow arrowTop' : 'blocklyDropDownArrow arrowBottom'); + Blockly.DropDownDiv.arrow_.style.display = metrics.arrowVisible ? '' : 'none'; // When we change `translate` multiple times in close succession, // Chrome may choose to wait and apply them all at once. @@ -328,7 +329,8 @@ Blockly.DropDownDiv.getBoundsInfo_ = function() { * @param {number} secondaryY Secondary/alternative origin point y, in absolute px * @return {Object} Various final metrics, including rendered positions for drop-down and arrow. */ -Blockly.DropDownDiv.getPositionMetrics = function(primaryX, primaryY, secondaryX, secondaryY) { +Blockly.DropDownDiv.getPositionMetrics = function(primaryX, primaryY, + secondaryX, secondaryY) { var boundsInfo = Blockly.DropDownDiv.getBoundsInfo_(); var div = Blockly.DropDownDiv.DIV_; var divSize = goog.style.getSize(div); @@ -364,14 +366,14 @@ Blockly.DropDownDiv.getPositionMetrics = function(primaryX, primaryY, secondaryX // dropdown should appear centered relative to the desired origin point. renderX -= divSize.width / 2; // Fit horizontally in the bounds. - renderX = Blockly.utils.clampNumber( + renderX = Blockly.utils.math.clamp( boundsInfo.left, renderX, boundsInfo.right - divSize.width); // Calculate the absolute arrow X. The arrow wants to be as close to the // origin point as possible. The arrow may not be centered in the dropdown div. var absoluteArrowX = centerX - Blockly.DropDownDiv.ARROW_SIZE / 2; // Keep in overall bounds - absoluteArrowX = Blockly.utils.clampNumber( + absoluteArrowX = Blockly.utils.math.clamp( boundsInfo.left, absoluteArrowX, boundsInfo.right); // Convert the arrow position to be relative to the top left corner of the div. @@ -379,7 +381,7 @@ Blockly.DropDownDiv.getPositionMetrics = function(primaryX, primaryY, secondaryX // Pad the arrow by some pixels, primarily so that it doesn't render on top // of a rounded border. - relativeArrowX = Blockly.utils.clampNumber( + relativeArrowX = Blockly.utils.math.clamp( Blockly.DropDownDiv.ARROW_HORIZONTAL_PADDING, relativeArrowX, divSize.width - Blockly.DropDownDiv.ARROW_HORIZONTAL_PADDING - diff --git a/core/field.js b/core/field.js index 8d9d54b01..1945ef7bf 100644 --- a/core/field.js +++ b/core/field.js @@ -33,6 +33,7 @@ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Gesture'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('goog.math.Size'); goog.require('goog.style'); @@ -337,7 +338,7 @@ Blockly.Field.prototype.dispose = function() { } this.sourceBlock_ = null; if (this.fieldGroup_) { - Blockly.utils.removeNode(this.fieldGroup_); + Blockly.utils.dom.removeNode(this.fieldGroup_); this.fieldGroup_ = null; } this.textElement_ = null; @@ -354,12 +355,12 @@ Blockly.Field.prototype.updateEditable = function() { return; } if (this.sourceBlock_.isEditable()) { - Blockly.utils.addClass(group, 'blocklyEditableText'); - Blockly.utils.removeClass(group, 'blocklyNonEditableText'); + Blockly.utils.dom.addClass(group, 'blocklyEditableText'); + Blockly.utils.dom.removeClass(group, 'blocklyNonEditableText'); group.style.cursor = this.CURSOR; } else { - Blockly.utils.addClass(group, 'blocklyNonEditableText'); - Blockly.utils.removeClass(group, 'blocklyEditableText'); + Blockly.utils.dom.addClass(group, 'blocklyNonEditableText'); + Blockly.utils.dom.removeClass(group, 'blocklyEditableText'); group.style.cursor = ''; } }; diff --git a/core/field_angle.js b/core/field_angle.js index 0b1e4d865..d648f548d 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -30,6 +30,7 @@ goog.require('Blockly.DropDownDiv'); goog.require('Blockly.FieldTextInput'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.math'); /** @@ -253,7 +254,7 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) { // This shouldn't happen, but let's not let this error propagate further. return; } - angle = Blockly.utils.toDegrees(angle); + angle = Blockly.utils.math.toDegrees(angle); // 0: East, 90: North, 180: West, 270: South. if (dx < 0) { angle += 180; @@ -304,12 +305,12 @@ Blockly.FieldAngle.prototype.updateGraph_ = function() { // Always display the input (i.e. getText) even if it is invalid. var angleDegrees = Number(this.getText()) + Blockly.FieldAngle.OFFSET; angleDegrees %= 360; - var angleRadians = Blockly.utils.toRadians(angleDegrees); + var angleRadians = Blockly.utils.math.toRadians(angleDegrees); var path = ['M ', Blockly.FieldAngle.HALF, ',', Blockly.FieldAngle.HALF]; var x2 = Blockly.FieldAngle.HALF; var y2 = Blockly.FieldAngle.HALF; if (!isNaN(angleRadians)) { - var angle1 = Blockly.utils.toRadians(Blockly.FieldAngle.OFFSET); + var angle1 = Blockly.utils.math.toRadians(Blockly.FieldAngle.OFFSET); var x1 = Math.cos(angle1) * Blockly.FieldAngle.RADIUS; var y1 = Math.sin(angle1) * -Blockly.FieldAngle.RADIUS; if (Blockly.FieldAngle.CLOCKWISE) { diff --git a/core/field_checkbox.js b/core/field_checkbox.js index cbb73933c..82f281cad 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -29,7 +29,7 @@ goog.provide('Blockly.FieldCheckbox'); goog.require('Blockly.Events'); goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); -goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -123,7 +123,7 @@ Blockly.FieldCheckbox.prototype.initView = function() { this.textElement_.setAttribute('x', Blockly.FieldCheckbox.CHECK_X_OFFSET); this.textElement_.setAttribute('y', Blockly.FieldCheckbox.CHECK_Y_OFFSET); - Blockly.utils.addClass(this.textElement_, 'blocklyCheckbox'); + Blockly.utils.dom.addClass(this.textElement_, 'blocklyCheckbox'); var textNode = document.createTextNode(Blockly.FieldCheckbox.CHECK_CHAR); this.textElement_.appendChild(textNode); diff --git a/core/field_date.js b/core/field_date.js index 760352403..5d80a665c 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -28,7 +28,7 @@ goog.provide('Blockly.FieldDate'); goog.require('Blockly.Events'); goog.require('Blockly.Field'); -goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('goog.date'); goog.require('goog.date.DateTime'); @@ -200,7 +200,7 @@ Blockly.FieldDate.prototype.updateEditor_ = function() { Blockly.FieldDate.prototype.showEditor_ = function() { this.picker_ = this.createWidget_(); this.picker_.render(Blockly.DropDownDiv.getContentDiv()); - Blockly.utils.addClass(this.picker_.getElement(), 'blocklyDatePicker'); + Blockly.utils.dom.addClass(this.picker_.getElement(), 'blocklyDatePicker'); Blockly.DropDownDiv.showPositionedByField(this); Blockly.DropDownDiv.setColour( this.DROPDOWN_BACKGROUND_COLOUR, this.DROPDOWN_BORDER_COLOUR); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 71f587fcf..13f7fc3f5 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -33,6 +33,8 @@ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Field'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.string'); goog.require('Blockly.utils.uiMenu'); goog.require('goog.events'); @@ -255,7 +257,7 @@ Blockly.FieldDropdown.prototype.positionMenu_ = function(menu) { Blockly.FieldDropdown.prototype.createWidget_ = function(menu) { var div = Blockly.WidgetDiv.DIV; menu.render(div); - Blockly.utils.addClass(menu.getElement(), 'blocklyDropdownMenu'); + Blockly.utils.dom.addClass(menu.getElement(), 'blocklyDropdownMenu'); // Enable autofocus after the initial render to avoid issue #1329. menu.setAllowAutoFocus(true); }; @@ -323,9 +325,9 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() { for (var i = 0; i < options.length; i++) { strings.push(options[i][0]); } - var shortest = Blockly.utils.shortestStringLength(strings); - var prefixLength = Blockly.utils.commonWordPrefix(strings, shortest); - var suffixLength = Blockly.utils.commonWordSuffix(strings, shortest); + var shortest = Blockly.utils.string.shortestStringLength(strings); + var prefixLength = Blockly.utils.string.commonWordPrefix(strings, shortest); + var suffixLength = Blockly.utils.string.commonWordSuffix(strings, shortest); if (!prefixLength && !suffixLength) { return; } diff --git a/core/field_image.js b/core/field_image.js index 9188935d6..e7d8a96c3 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -29,6 +29,7 @@ goog.provide('Blockly.FieldImage'); goog.require('Blockly.Field'); goog.require('Blockly.Tooltip'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('goog.math.Size'); @@ -133,7 +134,7 @@ Blockly.FieldImage.prototype.initView = function() { */ Blockly.FieldImage.prototype.dispose = function() { if (this.fieldGroup_) { - Blockly.utils.removeNode(this.fieldGroup_); + Blockly.utils.dom.removeNode(this.fieldGroup_); this.fieldGroup_ = null; } this.imageElement_ = null; diff --git a/core/field_label.js b/core/field_label.js index b752f74bb..00cb8a35d 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -30,6 +30,7 @@ goog.provide('Blockly.FieldLabel'); goog.require('Blockly.Field'); goog.require('Blockly.Tooltip'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('goog.math.Size'); @@ -82,7 +83,7 @@ Blockly.FieldLabel.prototype.initView = function() { this.createTextElement_(); this.textElement_.setAttribute('y', this.size_.height - 5); if (this.class_) { - Blockly.utils.addClass(this.textElement_, this.class_); + Blockly.utils.dom.addClass(this.textElement_, this.class_); } }; @@ -91,7 +92,7 @@ Blockly.FieldLabel.prototype.initView = function() { */ Blockly.FieldLabel.prototype.dispose = function() { if (this.textElement_) { - Blockly.utils.removeNode(this.textElement_); + Blockly.utils.dom.removeNode(this.textElement_); this.textElement_ = null; } }; diff --git a/core/field_textinput.js b/core/field_textinput.js index b791bcc20..606108e1f 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -34,6 +34,7 @@ goog.require('Blockly.Field'); goog.require('Blockly.Msg'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -179,9 +180,9 @@ Blockly.FieldTextInput.prototype.render_ = function() { var htmlInput = Blockly.FieldTextInput.htmlInput_; this.resizeEditor_(); if (!this.isTextValid_) { - Blockly.utils.addClass(htmlInput, 'blocklyInvalidInput'); + Blockly.utils.dom.addClass(htmlInput, 'blocklyInvalidInput'); } else { - Blockly.utils.removeClass(htmlInput, 'blocklyInvalidInput'); + Blockly.utils.dom.removeClass(htmlInput, 'blocklyInvalidInput'); } } }; diff --git a/core/flyout_base.js b/core/flyout_base.js index e3f081376..8375600d9 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -36,6 +36,7 @@ goog.require('Blockly.Gesture'); goog.require('Blockly.Tooltip'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.Xml'); @@ -278,7 +279,7 @@ Blockly.Flyout.prototype.dispose = function() { this.workspace_ = null; } if (this.svgGroup_) { - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgBackground_ = null; @@ -537,7 +538,7 @@ Blockly.Flyout.prototype.clearOldBlocks_ = function() { for (var j = 0; j < this.mats_.length; j++) { var rect = this.mats_[j]; if (rect) { - Blockly.utils.removeNode(rect); + Blockly.utils.dom.removeNode(rect); } } this.mats_.length = 0; diff --git a/core/flyout_button.js b/core/flyout_button.js index 17f8d6046..34dd9455e 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -28,6 +28,7 @@ goog.provide('Blockly.FlyoutButton'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -228,7 +229,7 @@ Blockly.FlyoutButton.prototype.dispose = function() { Blockly.unbindEvent_(this.onMouseUpWrapper_); } if (this.svgGroup_) { - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.workspace_ = null; diff --git a/core/icon.js b/core/icon.js index 119f3ae9c..27af9f032 100644 --- a/core/icon.js +++ b/core/icon.js @@ -28,6 +28,7 @@ goog.provide('Blockly.Icon'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -79,7 +80,7 @@ Blockly.Icon.prototype.createIcon = function() { this.iconGroup_ = Blockly.utils.createSvgElement('g', {'class': 'blocklyIconGroup'}, null); if (this.block_.isInFlyout) { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } this.drawIcon_(this.iconGroup_); @@ -95,7 +96,7 @@ Blockly.Icon.prototype.createIcon = function() { */ Blockly.Icon.prototype.dispose = function() { // Dispose of and unlink the icon. - Blockly.utils.removeNode(this.iconGroup_); + Blockly.utils.dom.removeNode(this.iconGroup_); this.iconGroup_ = null; // Dispose of and unlink the bubble. this.setVisible(false); diff --git a/core/inject.js b/core/inject.js index 4582ee43d..78f40d9cf 100644 --- a/core/inject.js +++ b/core/inject.js @@ -35,6 +35,7 @@ goog.require('Blockly.Options'); goog.require('Blockly.Tooltip'); goog.require('Blockly.userAgent'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.WorkspaceDragSurfaceSvg'); @@ -56,7 +57,7 @@ Blockly.inject = function(container, opt_options) { document.querySelector(container); } // Verify that the container is in document. - if (!Blockly.utils.containsNode(document, container)) { + if (!Blockly.utils.dom.containsNode(document, container)) { throw Error('Error: container is not in current document.'); } var options = new Blockly.Options(opt_options || {}); @@ -222,7 +223,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, if (!options.hasCategories && options.languageTree) { // Add flyout as an that is a sibling of the workspace svg. var flyout = mainWorkspace.addFlyout_('svg'); - Blockly.utils.insertAfter(flyout, svg); + Blockly.utils.dom.insertAfter(flyout, svg); } if (options.hasTrashcan) { mainWorkspace.addTrashcan(); diff --git a/core/mutator.js b/core/mutator.js index 2e57df43d..5247706c0 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -33,6 +33,7 @@ goog.require('Blockly.Events.BlockChange'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.Icon'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.Xml'); goog.require('Blockly.Xml.utils'); @@ -183,7 +184,7 @@ Blockly.Mutator.prototype.updateEditable = function() { if (!this.block_.isInFlyout) { if (this.block_.isEditable()) { if (this.iconGroup_) { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } @@ -191,7 +192,7 @@ Blockly.Mutator.prototype.updateEditable = function() { // Close any mutator bubble. Icon is not clickable. this.setVisible(false); if (this.iconGroup_) { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.iconGroup_), 'blocklyIconGroupReadonly'); } diff --git a/core/rendered_connection.js b/core/rendered_connection.js index b9ab8f241..f180cfdea 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -27,9 +27,10 @@ goog.provide('Blockly.RenderedConnection'); goog.require('Blockly.Connection'); -goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.Events'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.Coordinate'); +goog.require('Blockly.utils.dom'); /** @@ -266,7 +267,7 @@ Blockly.RenderedConnection.prototype.unhideAll = function() { * Remove the highlighting around this connection. */ Blockly.RenderedConnection.prototype.unhighlight = function() { - Blockly.utils.removeNode(Blockly.Connection.highlightedPath_); + Blockly.utils.dom.removeNode(Blockly.Connection.highlightedPath_); delete Blockly.Connection.highlightedPath_; }; diff --git a/core/scrollbar.js b/core/scrollbar.js index afec9fdc9..9d1cc1c84 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -30,6 +30,7 @@ goog.provide('Blockly.ScrollbarPair'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -56,7 +57,7 @@ Blockly.ScrollbarPair = function(workspace) { 'class': 'blocklyScrollbarBackground' }, null); - Blockly.utils.insertAfter(this.corner_, workspace.getBubbleCanvas()); + Blockly.utils.dom.insertAfter(this.corner_, workspace.getBubbleCanvas()); }; /** @@ -71,7 +72,7 @@ Blockly.ScrollbarPair.prototype.oldHostMetrics_ = null; * Unlink from all DOM elements to prevent memory leaks. */ Blockly.ScrollbarPair.prototype.dispose = function() { - Blockly.utils.removeNode(this.corner_); + Blockly.utils.dom.removeNode(this.corner_); this.corner_ = null; this.workspace_ = null; this.oldHostMetrics_ = null; @@ -346,7 +347,7 @@ Blockly.Scrollbar.prototype.dispose = function() { Blockly.unbindEvent_(this.onMouseDownHandleWrapper_); this.onMouseDownHandleWrapper_ = null; - Blockly.utils.removeNode(this.outerSvg_); + Blockly.utils.dom.removeNode(this.outerSvg_); this.outerSvg_ = null; this.svgGroup_ = null; this.svgBackground_ = null; @@ -624,7 +625,7 @@ Blockly.Scrollbar.prototype.createDom_ = function(opt_class) { 'ry': radius }, this.svgGroup_); - Blockly.utils.insertAfter(this.outerSvg_, this.workspace_.getParentSvg()); + Blockly.utils.dom.insertAfter(this.outerSvg_, this.workspace_.getParentSvg()); }; /** diff --git a/core/theme/classic.js b/core/theme/classic.js index d3bb2cfbc..ad46626ce 100644 --- a/core/theme/classic.js +++ b/core/theme/classic.js @@ -22,7 +22,6 @@ * @fileoverview Classic theme. * Contains multi-coloured border to create shadow effect. */ - 'use strict'; goog.provide('Blockly.Themes.Classic'); @@ -30,6 +29,9 @@ goog.provide('Blockly.Themes.Classic'); goog.require('Blockly.Theme'); +// Temporary holding object. +Blockly.Themes.Classic = {}; + Blockly.Themes.Classic.defaultBlockStyles = { "colour_blocks": { "colourPrimary": "20" diff --git a/core/theme/highcontrast.js b/core/theme/highcontrast.js index 5dfc1bb80..f2737e19c 100644 --- a/core/theme/highcontrast.js +++ b/core/theme/highcontrast.js @@ -29,6 +29,9 @@ goog.provide('Blockly.Themes.HighContrast'); goog.require('Blockly.Theme'); +// Temporary holding object. +Blockly.Themes.HighContrast = {}; + Blockly.Themes.HighContrast.defaultBlockStyles = { "colour_blocks": { "colourPrimary": "#a52714", diff --git a/core/theme/modern.js b/core/theme/modern.js index 0dc0181e4..b6fbd49df 100644 --- a/core/theme/modern.js +++ b/core/theme/modern.js @@ -29,6 +29,9 @@ goog.provide('Blockly.Themes.Modern'); goog.require('Blockly.Theme'); +// Temporary holding object. +Blockly.Themes.Modern = {}; + Blockly.Themes.Modern.defaultBlockStyles = { "colour_blocks": { "colourPrimary": "#a5745b", diff --git a/core/toolbox.js b/core/toolbox.js index 758b184c8..92ad7a91c 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -32,6 +32,7 @@ goog.require('Blockly.Flyout'); goog.require('Blockly.HorizontalFlyout'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Rect'); goog.require('Blockly.VerticalFlyout'); @@ -191,7 +192,7 @@ Blockly.Toolbox.prototype.init = function() { this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions); } // Insert the flyout after the workspace. - Blockly.utils.insertAfter(this.flyout_.createDom('svg'), + Blockly.utils.dom.insertAfter(this.flyout_.createDom('svg'), this.workspace_.getParentSvg()); this.flyout_.init(workspace); @@ -219,7 +220,7 @@ Blockly.Toolbox.prototype.init = function() { Blockly.Toolbox.prototype.dispose = function() { this.flyout_.dispose(); this.tree_.dispose(); - Blockly.utils.removeNode(this.HtmlDiv); + Blockly.utils.dom.removeNode(this.HtmlDiv); this.workspace_ = null; this.lastCategory_ = null; }; @@ -387,7 +388,8 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) { * @param {string} categoryName Name of the toolbox category. * @private */ -Blockly.Toolbox.prototype.setColour_ = function(colourValue, childOut, categoryName) { +Blockly.Toolbox.prototype.setColour_ = function(colourValue, childOut, + categoryName) { // Decode the colour for any potential message references // (eg. `%{BKY_MATH_HUE}`). var colour = Blockly.utils.replaceMessageReferences(colourValue); @@ -399,7 +401,7 @@ Blockly.Toolbox.prototype.setColour_ = function(colourValue, childOut, categoryN this.hasColours_ = true; } else if (typeof colour === 'number' || (typeof colour === 'string' && !isNaN(Number(colour)))) { - childOut.hexColour = Blockly.utils.colour.hueToHex(Number(colour)); + childOut.hexColour = Blockly.hueToHex(Number(colour)); this.hasColours_ = true; } else { childOut.hexColour = ''; @@ -516,7 +518,7 @@ Blockly.Toolbox.prototype.clearSelection = function() { * @package */ Blockly.Toolbox.prototype.addStyle = function(style) { - Blockly.utils.addClass(/** @type {!Element} */ (this.HtmlDiv), style); + Blockly.utils.dom.addClass(/** @type {!Element} */ (this.HtmlDiv), style); }; /** @@ -525,7 +527,7 @@ Blockly.Toolbox.prototype.addStyle = function(style) { * @package */ Blockly.Toolbox.prototype.removeStyle = function(style) { - Blockly.utils.removeClass(/** @type {!Element} */ (this.HtmlDiv), style); + Blockly.utils.dom.removeClass(/** @type {!Element} */ (this.HtmlDiv), style); }; /** diff --git a/core/tooltip.js b/core/tooltip.js index 06d22f85f..eded96dd4 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -35,7 +35,7 @@ */ goog.provide('Blockly.Tooltip'); -goog.require('Blockly.utils'); +goog.require('Blockly.utils.string'); /** @@ -292,7 +292,7 @@ Blockly.Tooltip.show_ = function() { while (typeof tip == 'function') { tip = tip(); } - tip = Blockly.utils.wrap(tip, Blockly.Tooltip.LIMIT); + tip = Blockly.utils.string.wrap(tip, Blockly.Tooltip.LIMIT); // Create new text, line by line. var lines = tip.split('\n'); for (var i = 0; i < lines.length; i++) { diff --git a/core/touch.js b/core/touch.js index 052128cde..c06433a1c 100644 --- a/core/touch.js +++ b/core/touch.js @@ -31,6 +31,7 @@ goog.provide('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.string'); /** @@ -210,7 +211,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) { * @param {!Event} e A touch event. */ Blockly.Touch.setClientFromTouch = function(e) { - if (Blockly.utils.startsWith(e.type, 'touch')) { + if (Blockly.utils.string.startsWith(e.type, 'touch')) { // Map the touch event's properties to the event. var touchPoint = e.changedTouches[0]; e.clientX = touchPoint.clientX; @@ -224,9 +225,9 @@ Blockly.Touch.setClientFromTouch = function(e) { * @return {boolean} True if it is a mouse or touch event; false otherwise. */ Blockly.Touch.isMouseOrTouchEvent = function(e) { - return Blockly.utils.startsWith(e.type, 'touch') || - Blockly.utils.startsWith(e.type, 'mouse') || - Blockly.utils.startsWith(e.type, 'pointer'); + return Blockly.utils.string.startsWith(e.type, 'touch') || + Blockly.utils.string.startsWith(e.type, 'mouse') || + Blockly.utils.string.startsWith(e.type, 'pointer'); }; /** @@ -235,8 +236,8 @@ Blockly.Touch.isMouseOrTouchEvent = function(e) { * @return {boolean} True if it is a touch event; false otherwise. */ Blockly.Touch.isTouchEvent = function(e) { - return Blockly.utils.startsWith(e.type, 'touch') || - Blockly.utils.startsWith(e.type, 'pointer'); + return Blockly.utils.string.startsWith(e.type, 'touch') || + Blockly.utils.string.startsWith(e.type, 'pointer'); }; /** diff --git a/core/trashcan.js b/core/trashcan.js index 2059ff42a..b5c13c0a1 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -27,6 +27,7 @@ goog.provide('Blockly.Trashcan'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.Rect'); goog.require('Blockly.Xml'); @@ -286,7 +287,7 @@ Blockly.Trashcan.prototype.createDom = function() { */ Blockly.Trashcan.prototype.init = function(verticalSpacing) { if (this.workspace_.options.maxTrashcanContents > 0) { - Blockly.utils.insertAfter(this.flyout_.createDom('svg'), + Blockly.utils.dom.insertAfter(this.flyout_.createDom('svg'), this.workspace_.getParentSvg()); this.flyout_.init(this.workspace_); this.flyout_.isBlockCreatable_ = function() { @@ -307,7 +308,7 @@ Blockly.Trashcan.prototype.init = function(verticalSpacing) { */ Blockly.Trashcan.prototype.dispose = function() { if (this.svgGroup_) { - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgLid_ = null; diff --git a/core/ui_menu_utils.js b/core/ui_menu_utils.js index a621827fb..6e1dbaec2 100644 --- a/core/ui_menu_utils.js +++ b/core/ui_menu_utils.js @@ -19,7 +19,7 @@ */ /** - * @fileoverview Utility methods for working with the closure menu + * @fileoverview Utility methods for working with the Closure menu * (goog.ui.menu). * @author fenichel@google.com (Rachel Fenichel) */ diff --git a/core/utils.js b/core/utils.js index 6a4bf79f4..54b33c011 100644 --- a/core/utils.js +++ b/core/utils.js @@ -35,79 +35,11 @@ goog.provide('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.Msg'); goog.require('Blockly.userAgent'); +goog.require('Blockly.utils.string'); goog.require('goog.style'); -/** - * Add a CSS class to a element. - * Similar to Closure's goog.dom.classes.add, except it handles SVG elements. - * @param {!Element} element DOM element to add class to. - * @param {string} className Name of class to add. - * @return {boolean} True if class was added, false if already present. - */ -Blockly.utils.addClass = function(element, className) { - var classes = element.getAttribute('class') || ''; - if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { - return false; - } - if (classes) { - classes += ' '; - } - element.setAttribute('class', classes + className); - return true; -}; - -/** - * Remove a CSS class from a element. - * Similar to Closure's goog.dom.classes.remove, except it handles SVG elements. - * @param {!Element} element DOM element to remove class from. - * @param {string} className Name of class to remove. - * @return {boolean} True if class was removed, false if never present. - */ -Blockly.utils.removeClass = function(element, className) { - var classes = element.getAttribute('class'); - if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { - return false; - } - var classList = classes.split(/\s+/); - for (var i = 0; i < classList.length; i++) { - if (!classList[i] || classList[i] == className) { - classList.splice(i, 1); - i--; - } - } - if (classList.length) { - element.setAttribute('class', classList.join(' ')); - } else { - element.removeAttribute('class'); - } - return true; -}; - -/** - * Checks if an element has the specified CSS class. - * Similar to Closure's goog.dom.classes.has, except it handles SVG elements. - * @param {!Element} element DOM element to check. - * @param {string} className Name of class to check. - * @return {boolean} True if class exists, false otherwise. - * @package - */ -Blockly.utils.hasClass = function(element, className) { - var classes = element.getAttribute('class'); - return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; -}; - -/** - * Removes a node from its parent. No-op if not attached to a parent. - * @param {Node} node The node to remove. - * @return {Node} The node removed if removed; else, null. - */ -// Copied from Closure goog.dom.removeNode -Blockly.utils.removeNode = function(node) { - return node && node.parentNode ? node.parentNode.removeChild(node) : null; -}; - /** * Don't do anything for this event, just halt propagation. * @param {!Event} e An event. @@ -303,90 +235,6 @@ Blockly.utils.getScrollDeltaPixels = function(e) { } }; -/** - * Given an array of strings, return the length of the shortest one. - * @param {!Array.} array Array of strings. - * @return {number} Length of shortest string. - */ -Blockly.utils.shortestStringLength = function(array) { - if (!array.length) { - return 0; - } - return array.reduce(function(a, b) { - return a.length < b.length ? a : b; - }).length; -}; - -/** - * Given an array of strings, return the length of the common prefix. - * Words may not be split. Any space after a word is included in the length. - * @param {!Array.} array Array of strings. - * @param {number=} opt_shortest Length of shortest string. - * @return {number} Length of common prefix. - */ -Blockly.utils.commonWordPrefix = function(array, opt_shortest) { - if (!array.length) { - return 0; - } else if (array.length == 1) { - return array[0].length; - } - var wordPrefix = 0; - var max = opt_shortest || Blockly.utils.shortestStringLength(array); - for (var len = 0; len < max; len++) { - var letter = array[0][len]; - for (var i = 1; i < array.length; i++) { - if (letter != array[i][len]) { - return wordPrefix; - } - } - if (letter == ' ') { - wordPrefix = len + 1; - } - } - for (var i = 1; i < array.length; i++) { - var letter = array[i][len]; - if (letter && letter != ' ') { - return wordPrefix; - } - } - return max; -}; - -/** - * Given an array of strings, return the length of the common suffix. - * Words may not be split. Any space after a word is included in the length. - * @param {!Array.} array Array of strings. - * @param {number=} opt_shortest Length of shortest string. - * @return {number} Length of common suffix. - */ -Blockly.utils.commonWordSuffix = function(array, opt_shortest) { - if (!array.length) { - return 0; - } else if (array.length == 1) { - return array[0].length; - } - var wordPrefix = 0; - var max = opt_shortest || Blockly.utils.shortestStringLength(array); - for (var len = 0; len < max; len++) { - var letter = array[0].substr(-len - 1, 1); - for (var i = 1; i < array.length; i++) { - if (letter != array[i].substr(-len - 1, 1)) { - return wordPrefix; - } - } - if (letter == ' ') { - wordPrefix = len + 1; - } - } - for (var i = 1; i < array.length; i++) { - var letter = array[i].charAt(array[i].length - len - 1); - if (letter && letter != ' ') { - return wordPrefix; - } - } - return max; -}; - /** * Parse a string with any number of interpolation tokens (%1, %2, ...). * It will also replace string table references (e.g., %{bky_my_msg} and @@ -534,7 +382,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, // BKY_ is the prefix used to namespace the strings used in Blockly // core files and the predefined blocks in ../blocks/. // These strings are defined in ../msgs/ files. - var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ? + var bklyKey = Blockly.utils.string.startsWith(keyUpper, 'BKY_') ? keyUpper.substring(4) : null; if (bklyKey && bklyKey in Blockly.Msg) { var rawValue = Blockly.Msg[bklyKey]; @@ -619,174 +467,6 @@ Blockly.utils.genUid = function() { Blockly.utils.genUid.soup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; -/** - * Wrap text to the specified width. - * @param {string} text Text to wrap. - * @param {number} limit Width to wrap each line. - * @return {string} Wrapped text. - */ -Blockly.utils.wrap = function(text, limit) { - var lines = text.split('\n'); - for (var i = 0; i < lines.length; i++) { - lines[i] = Blockly.utils.wrapLine_(lines[i], limit); - } - return lines.join('\n'); -}; - -/** - * Wrap single line of text to the specified width. - * @param {string} text Text to wrap. - * @param {number} limit Width to wrap each line. - * @return {string} Wrapped text. - * @private - */ -Blockly.utils.wrapLine_ = function(text, limit) { - if (text.length <= limit) { - // Short text, no need to wrap. - return text; - } - // Split the text into words. - var words = text.trim().split(/\s+/); - // Set limit to be the length of the largest word. - for (var i = 0; i < words.length; i++) { - if (words[i].length > limit) { - limit = words[i].length; - } - } - - var lastScore; - var score = -Infinity; - var lastText; - var lineCount = 1; - do { - lastScore = score; - lastText = text; - // Create a list of booleans representing if a space (false) or - // a break (true) appears after each word. - var wordBreaks = []; - // Seed the list with evenly spaced linebreaks. - var steps = words.length / lineCount; - var insertedBreaks = 1; - for (var i = 0; i < words.length - 1; i++) { - if (insertedBreaks < (i + 1.5) / steps) { - insertedBreaks++; - wordBreaks[i] = true; - } else { - wordBreaks[i] = false; - } - } - wordBreaks = Blockly.utils.wrapMutate_(words, wordBreaks, limit); - score = Blockly.utils.wrapScore_(words, wordBreaks, limit); - text = Blockly.utils.wrapToText_(words, wordBreaks); - lineCount++; - } while (score > lastScore); - return lastText; -}; - -/** - * Compute a score for how good the wrapping is. - * @param {!Array.} words Array of each word. - * @param {!Array.} wordBreaks Array of line breaks. - * @param {number} limit Width to wrap each line. - * @return {number} Larger the better. - * @private - */ -Blockly.utils.wrapScore_ = function(words, wordBreaks, limit) { - // If this function becomes a performance liability, add caching. - // Compute the length of each line. - var lineLengths = [0]; - var linePunctuation = []; - for (var i = 0; i < words.length; i++) { - lineLengths[lineLengths.length - 1] += words[i].length; - if (wordBreaks[i] === true) { - lineLengths.push(0); - linePunctuation.push(words[i].charAt(words[i].length - 1)); - } else if (wordBreaks[i] === false) { - lineLengths[lineLengths.length - 1]++; - } - } - var maxLength = Math.max.apply(Math, lineLengths); - - var score = 0; - for (var i = 0; i < lineLengths.length; i++) { - // Optimize for width. - // -2 points per char over limit (scaled to the power of 1.5). - score -= Math.pow(Math.abs(limit - lineLengths[i]), 1.5) * 2; - // Optimize for even lines. - // -1 point per char smaller than max (scaled to the power of 1.5). - score -= Math.pow(maxLength - lineLengths[i], 1.5); - // Optimize for structure. - // Add score to line endings after punctuation. - if ('.?!'.indexOf(linePunctuation[i]) != -1) { - score += limit / 3; - } else if (',;)]}'.indexOf(linePunctuation[i]) != -1) { - score += limit / 4; - } - } - // All else being equal, the last line should not be longer than the - // previous line. For example, this looks wrong: - // aaa bbb - // ccc ddd eee - if (lineLengths.length > 1 && lineLengths[lineLengths.length - 1] <= - lineLengths[lineLengths.length - 2]) { - score += 0.5; - } - return score; -}; - -/** - * Mutate the array of line break locations until an optimal solution is found. - * No line breaks are added or deleted, they are simply moved around. - * @param {!Array.} words Array of each word. - * @param {!Array.} wordBreaks Array of line breaks. - * @param {number} limit Width to wrap each line. - * @return {!Array.} New array of optimal line breaks. - * @private - */ -Blockly.utils.wrapMutate_ = function(words, wordBreaks, limit) { - var bestScore = Blockly.utils.wrapScore_(words, wordBreaks, limit); - var bestBreaks; - // Try shifting every line break forward or backward. - for (var i = 0; i < wordBreaks.length - 1; i++) { - if (wordBreaks[i] == wordBreaks[i + 1]) { - continue; - } - var mutatedWordBreaks = [].concat(wordBreaks); - mutatedWordBreaks[i] = !mutatedWordBreaks[i]; - mutatedWordBreaks[i + 1] = !mutatedWordBreaks[i + 1]; - var mutatedScore = - Blockly.utils.wrapScore_(words, mutatedWordBreaks, limit); - if (mutatedScore > bestScore) { - bestScore = mutatedScore; - bestBreaks = mutatedWordBreaks; - } - } - if (bestBreaks) { - // Found an improvement. See if it may be improved further. - return Blockly.utils.wrapMutate_(words, bestBreaks, limit); - } - // No improvements found. Done. - return wordBreaks; -}; - -/** - * Reassemble the array of words into text, with the specified line breaks. - * @param {!Array.} words Array of each word. - * @param {!Array.} wordBreaks Array of line breaks. - * @return {string} Plain text. - * @private - */ -Blockly.utils.wrapToText_ = function(words, wordBreaks) { - var text = []; - for (var i = 0; i < words.length; i++) { - text.push(words[i]); - if (wordBreaks[i] !== undefined) { - text.push(wordBreaks[i] ? '\n' : ' '); - } - } - return text.join(''); -}; - /** * Check if 3D transforms are supported by adding an element * and attempting to set the property. @@ -837,26 +517,6 @@ Blockly.utils.is3dSupported = function() { return Blockly.utils.is3dSupported.cached_; }; -/** - * Insert a node after a reference node. - * Contrast with node.insertBefore function. - * @param {!Element} newNode New element to insert. - * @param {!Element} refNode Existing element to precede new node. - * @package - */ -Blockly.utils.insertAfter = function(newNode, refNode) { - var siblingNode = refNode.nextSibling; - var parentNode = refNode.parentNode; - if (!parentNode) { - throw Error('Reference node has no parent.'); - } - if (siblingNode) { - parentNode.insertBefore(newNode, siblingNode); - } else { - parentNode.appendChild(newNode); - } -}; - /** * Calls a function after the page has loaded, possibly immediately. * @param {function()} fn Function to run. @@ -909,18 +569,6 @@ Blockly.utils.getViewportBBox = function() { }; }; -/** - * Fast prefix-checker. - * Copied from Closure's goog.string.startsWith. - * @param {string} str The string to check. - * @param {string} prefix A string to look for at the start of `str`. - * @return {boolean} True if `str` begins with `prefix`. - * @package - */ -Blockly.utils.startsWith = function(str, prefix) { - return str.lastIndexOf(prefix, 0) == 0; -}; - /** * Removes the first occurrence of a particular value from an array. * @param {!Array} arr Array from which to remove @@ -938,40 +586,6 @@ Blockly.utils.arrayRemove = function(arr, obj) { return true; }; -/** - * Converts degrees to radians. - * Copied from Closure's goog.math.toRadians. - * @param {number} angleDegrees Angle in degrees. - * @return {number} Angle in radians. - * @package - */ -Blockly.utils.toRadians = function(angleDegrees) { - return angleDegrees * Math.PI / 180; -}; - -/** - * Converts radians to degrees. - * Copied from Closure's goog.math.toDegrees. - * @param {number} angleRadians Angle in radians. - * @return {number} Angle in degrees. - * @package - */ -Blockly.utils.toDegrees = function(angleRadians) { - return angleRadians * 180 / Math.PI; -}; - -/** - * Whether a node contains another node. - * @param {!Node} parent The node that should contain the other node. - * @param {!Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendant node. - * @package - */ -Blockly.utils.containsNode = function(parent, descendant) { - return !!(parent.compareDocumentPosition(descendant) & - Node.DOCUMENT_POSITION_CONTAINED_BY); -}; - /** * Gets the document scroll distance as a coordinate object. * Copied from Closure's goog.dom.getDocumentScroll. @@ -1019,23 +633,6 @@ Blockly.utils.getBlockTypeCounts = function(block, opt_stripFollowing) { return typeCountsMap; }; -/** - * Clamp the provided number between the lower bound and the upper bound. - * @param {number} lowerBound The desired lower bound. - * @param {number} number The number to clamp. - * @param {number} upperBound The desired upper bound. - * @return {number} The clamped number. - * @package - */ -Blockly.utils.clampNumber = function(lowerBound, number, upperBound) { - if (upperBound < lowerBound) { - var temp = upperBound; - upperBound = lowerBound; - lowerBound = temp; - } - return Math.max(lowerBound, Math.min(number, upperBound)); -}; - /** * Reference to the global object. */ diff --git a/core/utils_colour.js b/core/utils/colour.js similarity index 94% rename from core/utils_colour.js rename to core/utils/colour.js index 549cd1c61..5a4f6ca71 100644 --- a/core/utils_colour.js +++ b/core/utils/colour.js @@ -103,16 +103,6 @@ Blockly.utils.colour.hexToRgb = function(hexColor) { return [r, g, b]; }; -/** - * Convert a hue (HSV model) into an RGB hex triplet. - * @param {number} hue Hue on a colour wheel (0-360). - * @return {string} RGB code, e.g. '#5ba65b'. - */ -Blockly.utils.colour.hueToHex = function(hue) { - return Blockly.utils.colour.hsvToHex(hue, Blockly.HSV_SATURATION, - Blockly.HSV_VALUE * 255); -}; - /** * Converts an HSV triplet to hex representation. * @param {number} h Hue value in [0, 360]. diff --git a/core/utils_coordinate.js b/core/utils/coordinate.js similarity index 100% rename from core/utils_coordinate.js rename to core/utils/coordinate.js diff --git a/core/utils/dom.js b/core/utils/dom.js new file mode 100644 index 000000000..9151d4499 --- /dev/null +++ b/core/utils/dom.js @@ -0,0 +1,132 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Utility methods for DOM manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +/** + * @name Blockly.utils.dom + * @namespace + */ +goog.provide('Blockly.utils.dom'); + + +/** + * Add a CSS class to a element. + * Similar to Closure's goog.dom.classes.add, except it handles SVG elements. + * @param {!Element} element DOM element to add class to. + * @param {string} className Name of class to add. + * @return {boolean} True if class was added, false if already present. + */ +Blockly.utils.dom.addClass = function(element, className) { + var classes = element.getAttribute('class') || ''; + if ((' ' + classes + ' ').indexOf(' ' + className + ' ') != -1) { + return false; + } + if (classes) { + classes += ' '; + } + element.setAttribute('class', classes + className); + return true; +}; + +/** + * Remove a CSS class from a element. + * Similar to Closure's goog.dom.classes.remove, except it handles SVG elements. + * @param {!Element} element DOM element to remove class from. + * @param {string} className Name of class to remove. + * @return {boolean} True if class was removed, false if never present. + */ +Blockly.utils.dom.removeClass = function(element, className) { + var classes = element.getAttribute('class'); + if ((' ' + classes + ' ').indexOf(' ' + className + ' ') == -1) { + return false; + } + var classList = classes.split(/\s+/); + for (var i = 0; i < classList.length; i++) { + if (!classList[i] || classList[i] == className) { + classList.splice(i, 1); + i--; + } + } + if (classList.length) { + element.setAttribute('class', classList.join(' ')); + } else { + element.removeAttribute('class'); + } + return true; +}; + +/** + * Checks if an element has the specified CSS class. + * Similar to Closure's goog.dom.classes.has, except it handles SVG elements. + * @param {!Element} element DOM element to check. + * @param {string} className Name of class to check. + * @return {boolean} True if class exists, false otherwise. + */ +Blockly.utils.dom.hasClass = function(element, className) { + var classes = element.getAttribute('class'); + return (' ' + classes + ' ').indexOf(' ' + className + ' ') != -1; +}; + +/** + * Removes a node from its parent. No-op if not attached to a parent. + * @param {Node} node The node to remove. + * @return {Node} The node removed if removed; else, null. + */ +// Copied from Closure goog.dom.removeNode +Blockly.utils.dom.removeNode = function(node) { + return node && node.parentNode ? node.parentNode.removeChild(node) : null; +}; + +/** + * Insert a node after a reference node. + * Contrast with node.insertBefore function. + * @param {!Element} newNode New element to insert. + * @param {!Element} refNode Existing element to precede new node. + */ +Blockly.utils.dom.insertAfter = function(newNode, refNode) { + var siblingNode = refNode.nextSibling; + var parentNode = refNode.parentNode; + if (!parentNode) { + throw Error('Reference node has no parent.'); + } + if (siblingNode) { + parentNode.insertBefore(newNode, siblingNode); + } else { + parentNode.appendChild(newNode); + } +}; + +/** + * Whether a node contains another node. + * @param {!Node} parent The node that should contain the other node. + * @param {!Node} descendant The node to test presence of. + * @return {boolean} Whether the parent node contains the descendant node. + */ +Blockly.utils.dom.containsNode = function(parent, descendant) { + return !!(parent.compareDocumentPosition(descendant) & + Node.DOCUMENT_POSITION_CONTAINED_BY); +}; diff --git a/core/utils/math.js b/core/utils/math.js new file mode 100644 index 000000000..7a8cc3ff0 --- /dev/null +++ b/core/utils/math.js @@ -0,0 +1,70 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Utility methods for math. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +/** + * @name Blockly.utils.math + * @namespace + */ +goog.provide('Blockly.utils.math'); + + +/** + * Converts degrees to radians. + * Copied from Closure's goog.math.toRadians. + * @param {number} angleDegrees Angle in degrees. + * @return {number} Angle in radians. + */ +Blockly.utils.math.toRadians = function(angleDegrees) { + return angleDegrees * Math.PI / 180; +}; + +/** + * Converts radians to degrees. + * Copied from Closure's goog.math.toDegrees. + * @param {number} angleRadians Angle in radians. + * @return {number} Angle in degrees. + */ +Blockly.utils.math.toDegrees = function(angleRadians) { + return angleRadians * 180 / Math.PI; +}; + +/** + * Clamp the provided number between the lower bound and the upper bound. + * @param {number} lowerBound The desired lower bound. + * @param {number} number The number to clamp. + * @param {number} upperBound The desired upper bound. + * @return {number} The clamped number. + */ +Blockly.utils.math.clamp = function(lowerBound, number, upperBound) { + if (upperBound < lowerBound) { + var temp = upperBound; + upperBound = lowerBound; + lowerBound = temp; + } + return Math.max(lowerBound, Math.min(number, upperBound)); +}; diff --git a/core/utils_rect.js b/core/utils/rect.js similarity index 100% rename from core/utils_rect.js rename to core/utils/rect.js diff --git a/core/utils/string.js b/core/utils/string.js new file mode 100644 index 000000000..75425f707 --- /dev/null +++ b/core/utils/string.js @@ -0,0 +1,298 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Utility methods for string manipulation. + * These methods are not specific to Blockly, and could be factored out into + * a JavaScript framework such as Closure. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +/** + * @name Blockly.utils.string + * @namespace + */ +goog.provide('Blockly.utils.string'); + + +/** + * Fast prefix-checker. + * Copied from Closure's goog.string.startsWith. + * @param {string} str The string to check. + * @param {string} prefix A string to look for at the start of `str`. + * @return {boolean} True if `str` begins with `prefix`. + */ +Blockly.utils.string.startsWith = function(str, prefix) { + return str.lastIndexOf(prefix, 0) == 0; +}; + +/** + * Given an array of strings, return the length of the shortest one. + * @param {!Array.} array Array of strings. + * @return {number} Length of shortest string. + */ +Blockly.utils.string.shortestStringLength = function(array) { + if (!array.length) { + return 0; + } + return array.reduce(function(a, b) { + return a.length < b.length ? a : b; + }).length; +}; + +/** + * Given an array of strings, return the length of the common prefix. + * Words may not be split. Any space after a word is included in the length. + * @param {!Array.} array Array of strings. + * @param {number=} opt_shortest Length of shortest string. + * @return {number} Length of common prefix. + */ +Blockly.utils.string.commonWordPrefix = function(array, opt_shortest) { + if (!array.length) { + return 0; + } else if (array.length == 1) { + return array[0].length; + } + var wordPrefix = 0; + var max = opt_shortest || Blockly.utils.string.shortestStringLength(array); + for (var len = 0; len < max; len++) { + var letter = array[0][len]; + for (var i = 1; i < array.length; i++) { + if (letter != array[i][len]) { + return wordPrefix; + } + } + if (letter == ' ') { + wordPrefix = len + 1; + } + } + for (var i = 1; i < array.length; i++) { + var letter = array[i][len]; + if (letter && letter != ' ') { + return wordPrefix; + } + } + return max; +}; + +/** + * Given an array of strings, return the length of the common suffix. + * Words may not be split. Any space after a word is included in the length. + * @param {!Array.} array Array of strings. + * @param {number=} opt_shortest Length of shortest string. + * @return {number} Length of common suffix. + */ +Blockly.utils.string.commonWordSuffix = function(array, opt_shortest) { + if (!array.length) { + return 0; + } else if (array.length == 1) { + return array[0].length; + } + var wordPrefix = 0; + var max = opt_shortest || Blockly.utils.string.shortestStringLength(array); + for (var len = 0; len < max; len++) { + var letter = array[0].substr(-len - 1, 1); + for (var i = 1; i < array.length; i++) { + if (letter != array[i].substr(-len - 1, 1)) { + return wordPrefix; + } + } + if (letter == ' ') { + wordPrefix = len + 1; + } + } + for (var i = 1; i < array.length; i++) { + var letter = array[i].charAt(array[i].length - len - 1); + if (letter && letter != ' ') { + return wordPrefix; + } + } + return max; +}; + +/** + * Wrap text to the specified width. + * @param {string} text Text to wrap. + * @param {number} limit Width to wrap each line. + * @return {string} Wrapped text. + */ +Blockly.utils.string.wrap = function(text, limit) { + var lines = text.split('\n'); + for (var i = 0; i < lines.length; i++) { + lines[i] = Blockly.utils.string.wrapLine_(lines[i], limit); + } + return lines.join('\n'); +}; + +/** + * Wrap single line of text to the specified width. + * @param {string} text Text to wrap. + * @param {number} limit Width to wrap each line. + * @return {string} Wrapped text. + * @private + */ +Blockly.utils.string.wrapLine_ = function(text, limit) { + if (text.length <= limit) { + // Short text, no need to wrap. + return text; + } + // Split the text into words. + var words = text.trim().split(/\s+/); + // Set limit to be the length of the largest word. + for (var i = 0; i < words.length; i++) { + if (words[i].length > limit) { + limit = words[i].length; + } + } + + var lastScore; + var score = -Infinity; + var lastText; + var lineCount = 1; + do { + lastScore = score; + lastText = text; + // Create a list of booleans representing if a space (false) or + // a break (true) appears after each word. + var wordBreaks = []; + // Seed the list with evenly spaced linebreaks. + var steps = words.length / lineCount; + var insertedBreaks = 1; + for (var i = 0; i < words.length - 1; i++) { + if (insertedBreaks < (i + 1.5) / steps) { + insertedBreaks++; + wordBreaks[i] = true; + } else { + wordBreaks[i] = false; + } + } + wordBreaks = Blockly.utils.string.wrapMutate_(words, wordBreaks, limit); + score = Blockly.utils.string.wrapScore_(words, wordBreaks, limit); + text = Blockly.utils.string.wrapToText_(words, wordBreaks); + lineCount++; + } while (score > lastScore); + return lastText; +}; + +/** + * Compute a score for how good the wrapping is. + * @param {!Array.} words Array of each word. + * @param {!Array.} wordBreaks Array of line breaks. + * @param {number} limit Width to wrap each line. + * @return {number} Larger the better. + * @private + */ +Blockly.utils.string.wrapScore_ = function(words, wordBreaks, limit) { + // If this function becomes a performance liability, add caching. + // Compute the length of each line. + var lineLengths = [0]; + var linePunctuation = []; + for (var i = 0; i < words.length; i++) { + lineLengths[lineLengths.length - 1] += words[i].length; + if (wordBreaks[i] === true) { + lineLengths.push(0); + linePunctuation.push(words[i].charAt(words[i].length - 1)); + } else if (wordBreaks[i] === false) { + lineLengths[lineLengths.length - 1]++; + } + } + var maxLength = Math.max.apply(Math, lineLengths); + + var score = 0; + for (var i = 0; i < lineLengths.length; i++) { + // Optimize for width. + // -2 points per char over limit (scaled to the power of 1.5). + score -= Math.pow(Math.abs(limit - lineLengths[i]), 1.5) * 2; + // Optimize for even lines. + // -1 point per char smaller than max (scaled to the power of 1.5). + score -= Math.pow(maxLength - lineLengths[i], 1.5); + // Optimize for structure. + // Add score to line endings after punctuation. + if ('.?!'.indexOf(linePunctuation[i]) != -1) { + score += limit / 3; + } else if (',;)]}'.indexOf(linePunctuation[i]) != -1) { + score += limit / 4; + } + } + // All else being equal, the last line should not be longer than the + // previous line. For example, this looks wrong: + // aaa bbb + // ccc ddd eee + if (lineLengths.length > 1 && lineLengths[lineLengths.length - 1] <= + lineLengths[lineLengths.length - 2]) { + score += 0.5; + } + return score; +}; + +/** + * Mutate the array of line break locations until an optimal solution is found. + * No line breaks are added or deleted, they are simply moved around. + * @param {!Array.} words Array of each word. + * @param {!Array.} wordBreaks Array of line breaks. + * @param {number} limit Width to wrap each line. + * @return {!Array.} New array of optimal line breaks. + * @private + */ +Blockly.utils.string.wrapMutate_ = function(words, wordBreaks, limit) { + var bestScore = Blockly.utils.string.wrapScore_(words, wordBreaks, limit); + var bestBreaks; + // Try shifting every line break forward or backward. + for (var i = 0; i < wordBreaks.length - 1; i++) { + if (wordBreaks[i] == wordBreaks[i + 1]) { + continue; + } + var mutatedWordBreaks = [].concat(wordBreaks); + mutatedWordBreaks[i] = !mutatedWordBreaks[i]; + mutatedWordBreaks[i + 1] = !mutatedWordBreaks[i + 1]; + var mutatedScore = + Blockly.utils.string.wrapScore_(words, mutatedWordBreaks, limit); + if (mutatedScore > bestScore) { + bestScore = mutatedScore; + bestBreaks = mutatedWordBreaks; + } + } + if (bestBreaks) { + // Found an improvement. See if it may be improved further. + return Blockly.utils.string.wrapMutate_(words, bestBreaks, limit); + } + // No improvements found. Done. + return wordBreaks; +}; + +/** + * Reassemble the array of words into text, with the specified line breaks. + * @param {!Array.} words Array of each word. + * @param {!Array.} wordBreaks Array of line breaks. + * @return {string} Plain text. + * @private + */ +Blockly.utils.string.wrapToText_ = function(words, wordBreaks) { + var text = []; + for (var i = 0; i < words.length; i++) { + text.push(words[i]); + if (wordBreaks[i] !== undefined) { + text.push(wordBreaks[i] ? '\n' : ' '); + } + } + return text.join(''); +}; + diff --git a/core/workspace.js b/core/workspace.js index 6cf93946f..a630a7a0b 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -28,6 +28,7 @@ goog.provide('Blockly.Workspace'); goog.require('Blockly.Events'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.math'); goog.require('Blockly.VariableMap'); goog.require('Blockly.WorkspaceComment'); @@ -200,7 +201,7 @@ Blockly.Workspace.prototype.getTopBlocks = function(ordered) { var blocks = [].concat(this.topBlocks_); if (ordered && blocks.length > 1) { this.sortObjects_.offset = - Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE)); + Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)); if (this.RTL) { this.sortObjects_.offset *= -1; } @@ -246,7 +247,7 @@ Blockly.Workspace.prototype.getBlocksByType = function(type, ordered) { var blocks = this.typedBlocksDB_[type].slice(0); if (ordered && blocks.length > 1) { this.sortObjects_.offset = - Math.sign(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE)); + Math.sign(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)); if (this.RTL) { this.sortObjects_.offset *= -1; } @@ -299,7 +300,7 @@ Blockly.Workspace.prototype.getTopComments = function(ordered) { var comments = [].concat(this.topComments_); if (ordered && comments.length > 1) { this.sortObjects_.offset = - Math.sin(Blockly.utils.toRadians(Blockly.Workspace.SCAN_ANGLE)); + Math.sin(Blockly.utils.math.toRadians(Blockly.Workspace.SCAN_ANGLE)); if (this.RTL) { this.sortObjects_.offset *= -1; } diff --git a/core/workspace_audio.js b/core/workspace_audio.js index 75e02d04c..063a09be6 100644 --- a/core/workspace_audio.js +++ b/core/workspace_audio.js @@ -28,6 +28,7 @@ goog.provide('Blockly.WorkspaceAudio'); goog.require('Blockly.userAgent'); +goog.require('Blockly.utils'); /** diff --git a/core/workspace_comment_render_svg.js b/core/workspace_comment_render_svg.js index 024140376..0742d8675 100644 --- a/core/workspace_comment_render_svg.js +++ b/core/workspace_comment_render_svg.js @@ -26,8 +26,9 @@ goog.provide('Blockly.WorkspaceCommentSvg.render'); -goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.Coordinate'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.WorkspaceCommentSvg'); @@ -283,7 +284,7 @@ Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) { */ Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { // Highlight the delete icon. - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.deleteIconBorder_), 'blocklyDeleteIconHighlighted'); // This event has been handled. No need to bubble up to the document. @@ -297,7 +298,7 @@ Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) { */ Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(_e) { // Restore highlight on the delete icon. - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.deleteIconBorder_), 'blocklyDeleteIconHighlighted'); }; @@ -441,9 +442,9 @@ Blockly.WorkspaceCommentSvg.prototype.setFocus = function() { } comment.textarea_.focus(); comment.addFocus(); - Blockly.utils.addClass( + Blockly.utils.dom.addClass( comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.addClass( + Blockly.utils.dom.addClass( comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); }, 0); }; @@ -463,9 +464,9 @@ Blockly.WorkspaceCommentSvg.prototype.blurFocus = function() { comment.textarea_.blur(); comment.removeFocus(); - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( comment.svgRectTarget_, 'blocklyCommentTargetFocused'); - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( comment.svgHandleTarget_, 'blocklyCommentHandleTargetFocused'); }, 0); }; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 9fb2776aa..a8051e812 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -33,6 +33,7 @@ goog.require('Blockly.Events.CommentDelete'); goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.Events.Ui'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.WorkspaceComment'); @@ -118,7 +119,7 @@ Blockly.WorkspaceCommentSvg.prototype.dispose = function() { Blockly.Events.fire(new Blockly.Events.CommentDelete(this)); } - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); // Sever JavaScript to DOM connections. this.svgGroup_ = null; this.svgRect_ = null; @@ -233,7 +234,7 @@ Blockly.WorkspaceCommentSvg.prototype.unselect = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.addSelect = function() { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklySelected'); this.setFocus(); }; @@ -243,7 +244,7 @@ Blockly.WorkspaceCommentSvg.prototype.addSelect = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.removeSelect = function() { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklySelected'); this.blurFocus(); }; @@ -253,7 +254,7 @@ Blockly.WorkspaceCommentSvg.prototype.removeSelect = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.addFocus = function() { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyFocused'); }; @@ -262,7 +263,7 @@ Blockly.WorkspaceCommentSvg.prototype.addFocus = function() { * @package */ Blockly.WorkspaceCommentSvg.prototype.removeFocus = function() { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyFocused'); }; @@ -450,10 +451,10 @@ Blockly.WorkspaceCommentSvg.prototype.getBoundingRectangle = function() { */ Blockly.WorkspaceCommentSvg.prototype.updateMovable = function() { if (this.isMovable()) { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable'); } else { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggable'); } }; @@ -478,10 +479,10 @@ Blockly.WorkspaceCommentSvg.prototype.setDragging = function(adding) { var group = this.getSvgRoot(); group.translate_ = ''; group.skew_ = ''; - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } else { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDragging'); } }; @@ -524,10 +525,10 @@ Blockly.WorkspaceCommentSvg.prototype.setContent = function(content) { */ Blockly.WorkspaceCommentSvg.prototype.setDeleteStyle = function(enable) { if (enable) { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); } else { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); } }; diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 1a31a9ab7..4766a9dec 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -31,6 +31,7 @@ goog.provide('Blockly.WorkspaceDragSurfaceSvg'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -141,8 +142,8 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { var blockCanvas = this.SVG_.childNodes[0]; var bubbleCanvas = this.SVG_.childNodes[1]; if (!blockCanvas || !bubbleCanvas || - !Blockly.utils.hasClass(blockCanvas, 'blocklyBlockCanvas') || - !Blockly.utils.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { + !Blockly.utils.dom.hasClass(blockCanvas, 'blocklyBlockCanvas') || + !Blockly.utils.dom.hasClass(bubbleCanvas, 'blocklyBubbleCanvas')) { throw Error('Couldn\'t clear and hide the drag surface. ' + 'A node was missing.'); } @@ -150,13 +151,13 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { // If there is a previous sibling, put the blockCanvas back right afterwards, // otherwise insert it as the first child node in newSurface. if (this.previousSibling_ != null) { - Blockly.utils.insertAfter(blockCanvas, this.previousSibling_); + Blockly.utils.dom.insertAfter(blockCanvas, this.previousSibling_); } else { newSurface.insertBefore(blockCanvas, newSurface.firstChild); } // Reattach the bubble canvas after the blockCanvas. - Blockly.utils.insertAfter(bubbleCanvas, blockCanvas); + Blockly.utils.dom.insertAfter(bubbleCanvas, blockCanvas); // Hide the drag surface. this.SVG_.style.display = 'none'; if (this.SVG_.childNodes.length) { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index b92337759..edb7ca61c 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -42,6 +42,7 @@ goog.require('Blockly.Touch'); goog.require('Blockly.TouchGesture'); goog.require('Blockly.Trashcan'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.VariablesDynamic'); goog.require('Blockly.Workspace'); goog.require('Blockly.WorkspaceAudio'); @@ -435,8 +436,8 @@ Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) { var x = 0; var y = 0; var scale = 1; - if (Blockly.utils.containsNode(this.getCanvas(), element) || - Blockly.utils.containsNode(this.getBubbleCanvas(), element)) { + if (Blockly.utils.dom.containsNode(this.getCanvas(), element) || + Blockly.utils.dom.containsNode(this.getBubbleCanvas(), element)) { // Before the SVG canvas, scale the coordinates. scale = this.scale; } @@ -569,7 +570,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { } Blockly.WorkspaceSvg.superClass_.dispose.call(this); if (this.svgGroup_) { - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.svgBlockCanvas_ = null; @@ -613,7 +614,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { // SVG is injected into (i.e. injectionDiv). var div = this.getParentSvg().parentNode; if (div) { - Blockly.utils.removeNode(div); + Blockly.utils.dom.removeNode(div); } } if (this.resizeHandlerWrapper_) { @@ -1758,10 +1759,10 @@ Blockly.WorkspaceSvg.prototype.zoomToFit = function() { * @package */ Blockly.WorkspaceSvg.prototype.beginCanvasTransition = function() { - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!SVGElement} */ (this.svgBlockCanvas_), 'blocklyCanvasTransitioning'); - Blockly.utils.addClass( + Blockly.utils.dom.addClass( /** @type {!SVGElement} */ (this.svgBubbleCanvas_), 'blocklyCanvasTransitioning'); }; @@ -1771,10 +1772,10 @@ Blockly.WorkspaceSvg.prototype.beginCanvasTransition = function() { * @package */ Blockly.WorkspaceSvg.prototype.endCanvasTransition = function() { - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!SVGElement} */ (this.svgBlockCanvas_), 'blocklyCanvasTransitioning'); - Blockly.utils.removeClass( + Blockly.utils.dom.removeClass( /** @type {!SVGElement} */ (this.svgBubbleCanvas_), 'blocklyCanvasTransitioning'); }; diff --git a/core/xml.js b/core/xml.js index 812e46b1b..a0fe66b73 100644 --- a/core/xml.js +++ b/core/xml.js @@ -35,6 +35,7 @@ goog.require('Blockly.Events.BlockCreate'); goog.require('Blockly.Events.FinishedLoading'); goog.require('Blockly.Events.VarCreate'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.Xml.utils'); @@ -257,7 +258,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) { if (textNode.nodeType == Node.TEXT_NODE && textNode.data.trim() == '' && node.firstChild != textNode) { // Prune whitespace after a tag. - Blockly.utils.removeNode(textNode); + Blockly.utils.dom.removeNode(textNode); } } if (node) { @@ -266,7 +267,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) { if (textNode.nodeType == Node.TEXT_NODE && textNode.data.trim() == '') { // Prune whitespace before a tag. - Blockly.utils.removeNode(textNode); + Blockly.utils.dom.removeNode(textNode); } } } diff --git a/core/zoom_controls.js b/core/zoom_controls.js index 7a4fccb94..c9a68e702 100644 --- a/core/zoom_controls.js +++ b/core/zoom_controls.js @@ -28,6 +28,7 @@ goog.provide('Blockly.ZoomControls'); goog.require('Blockly.Touch'); goog.require('Blockly.utils'); +goog.require('Blockly.utils.dom'); /** @@ -128,7 +129,7 @@ Blockly.ZoomControls.prototype.init = function(verticalSpacing) { */ Blockly.ZoomControls.prototype.dispose = function() { if (this.svgGroup_) { - Blockly.utils.removeNode(this.svgGroup_); + Blockly.utils.dom.removeNode(this.svgGroup_); this.svgGroup_ = null; } this.workspace_ = null; diff --git a/dart_compressed.js b/dart_compressed.js index 7663ee9bb..8dd5a2ba5 100644 --- a/dart_compressed.js +++ b/dart_compressed.js @@ -9,8 +9,8 @@ Blockly.Dart.init=function(a){Blockly.Dart.definitions_=Object.create(null);Bloc for(d=0;dc&&(a=a+" - "+-c,g=Blockly.Dart.ORDER_ADDITIVE); d&&(a=c?"-("+a+")":"-"+a,g=Blockly.Dart.ORDER_UNARY_PREFIX);g=Math.floor(g);e=Math.floor(e);g&&e>=g&&(a="("+a+")")}return a};Blockly.Dart.colour={};Blockly.Dart.addReservedWords("Math");Blockly.Dart.colour_picker=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.Dart.ORDER_ATOMIC]}; Blockly.Dart.colour_random=function(a){Blockly.Dart.definitions_.import_dart_math="import 'dart:math' as Math;";return[Blockly.Dart.provideFunction_("colour_random",["String "+Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_+"() {"," String hex = '0123456789abcdef';"," var rnd = new Math.Random();"," return '#${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}'"," '${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}'"," '${hex[rnd.nextInt(16)]}${hex[rnd.nextInt(16)]}';","}"])+"()",Blockly.Dart.ORDER_UNARY_POSTFIX]}; diff --git a/generators/dart.js b/generators/dart.js index cc24151d8..77dd620dd 100644 --- a/generators/dart.js +++ b/generators/dart.js @@ -27,6 +27,7 @@ goog.provide('Blockly.Dart'); goog.require('Blockly.Generator'); +goog.require('Blockly.utils.string'); /** @@ -198,7 +199,7 @@ Blockly.Dart.scrub_ = function(block, code, opt_thisOnly) { if (!block.outputConnection || !block.outputConnection.targetConnection) { // Collect comment for this block. var comment = block.getCommentText(); - comment = Blockly.utils.wrap(comment, Blockly.Dart.COMMENT_WRAP - 3); + comment = Blockly.utils.string.wrap(comment, Blockly.Dart.COMMENT_WRAP - 3); if (comment) { if (block.getProcedureDef) { // Use documentation comment for function comments. diff --git a/generators/javascript.js b/generators/javascript.js index ce38b726a..9d20ca974 100644 --- a/generators/javascript.js +++ b/generators/javascript.js @@ -27,6 +27,7 @@ goog.provide('Blockly.JavaScript'); goog.require('Blockly.Generator'); +goog.require('Blockly.utils.string'); /** @@ -239,7 +240,8 @@ Blockly.JavaScript.scrub_ = function(block, code, opt_thisOnly) { if (!block.outputConnection || !block.outputConnection.targetConnection) { // Collect comment for this block. var comment = block.getCommentText(); - comment = Blockly.utils.wrap(comment, Blockly.JavaScript.COMMENT_WRAP - 3); + comment = Blockly.utils.string.wrap(comment, + Blockly.JavaScript.COMMENT_WRAP - 3); if (comment) { if (block.getProcedureDef) { // Use a comment block for function comments. diff --git a/generators/lua.js b/generators/lua.js index 0e05c24dc..70a83b2ed 100644 --- a/generators/lua.js +++ b/generators/lua.js @@ -28,6 +28,7 @@ goog.provide('Blockly.Lua'); goog.require('Blockly.Generator'); +goog.require('Blockly.utils.string'); /** @@ -172,7 +173,7 @@ Blockly.Lua.scrub_ = function(block, code, opt_thisOnly) { if (!block.outputConnection || !block.outputConnection.targetConnection) { // Collect comment for this block. var comment = block.getCommentText(); - comment = Blockly.utils.wrap(comment, Blockly.Lua.COMMENT_WRAP - 3); + comment = Blockly.utils.string.wrap(comment, Blockly.Lua.COMMENT_WRAP - 3); if (comment) { commentCode += Blockly.Lua.prefixLines(comment, '-- ') + '\n'; } diff --git a/generators/php.js b/generators/php.js index cd717abe3..0c926e90b 100644 --- a/generators/php.js +++ b/generators/php.js @@ -27,6 +27,7 @@ goog.provide('Blockly.PHP'); goog.require('Blockly.Generator'); +goog.require('Blockly.utils.string'); /** @@ -228,7 +229,7 @@ Blockly.PHP.scrub_ = function(block, code, opt_thisOnly) { if (!block.outputConnection || !block.outputConnection.targetConnection) { // Collect comment for this block. var comment = block.getCommentText(); - comment = Blockly.utils.wrap(comment, Blockly.PHP.COMMENT_WRAP - 3); + comment = Blockly.utils.string.wrap(comment, Blockly.PHP.COMMENT_WRAP - 3); if (comment) { commentCode += Blockly.PHP.prefixLines(comment, '// ') + '\n'; } diff --git a/generators/python.js b/generators/python.js index c3d45b8c1..9a328d98a 100644 --- a/generators/python.js +++ b/generators/python.js @@ -27,6 +27,7 @@ goog.provide('Blockly.Python'); goog.require('Blockly.Generator'); +goog.require('Blockly.utils.string'); /** @@ -254,7 +255,8 @@ Blockly.Python.scrub_ = function(block, code, opt_thisOnly) { if (!block.outputConnection || !block.outputConnection.targetConnection) { // Collect comment for this block. var comment = block.getCommentText(); - comment = Blockly.utils.wrap(comment, Blockly.Python.COMMENT_WRAP - 3); + comment = Blockly.utils.string.wrap(comment, + Blockly.Python.COMMENT_WRAP - 3); if (comment) { if (block.getProcedureDef) { // Use a comment block for function comments. diff --git a/javascript_compressed.js b/javascript_compressed.js index 3f035b567..4160479be 100644 --- a/javascript_compressed.js +++ b/javascript_compressed.js @@ -11,7 +11,7 @@ Blockly.JavaScript.ORDER_ADDITION],[Blockly.JavaScript.ORDER_LOGICAL_AND,Blockly Blockly.JavaScript.init=function(a){Blockly.JavaScript.definitions_=Object.create(null);Blockly.JavaScript.functionNames_=Object.create(null);Blockly.JavaScript.variableDB_?Blockly.JavaScript.variableDB_.reset():Blockly.JavaScript.variableDB_=new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);Blockly.JavaScript.variableDB_.setVariableMap(a.getVariableMap());for(var b=[],c=Blockly.Variables.allDeveloperVariables(a),d=0;dc?Blockly.JavaScript.valueToCode(a,b,Blockly.JavaScript.ORDER_SUBTRACTION)||f:d?Blockly.JavaScript.valueToCode(a,b,Blockly.JavaScript.ORDER_UNARY_NEGATION)||f:Blockly.JavaScript.valueToCode(a,b,e)||f;if(Blockly.isNumber(a))a=parseFloat(a)+c, d&&(a=-a);else{if(0c&&(a=a+" - "+-c,g=Blockly.JavaScript.ORDER_SUBTRACTION);d&&(a=c?"-("+a+")":"-"+a,g=Blockly.JavaScript.ORDER_UNARY_NEGATION);g=Math.floor(g);e=Math.floor(e);g&&e>=g&&(a="("+a+")")}return a};Blockly.JavaScript.colour={};Blockly.JavaScript.colour_picker=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.colour_random=function(a){return[Blockly.JavaScript.provideFunction_("colourRandom",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"() {"," var num = Math.floor(Math.random() * Math.pow(2, 24));"," return '#' + ('00000' + num.toString(16)).substr(-6);","}"])+"()",Blockly.JavaScript.ORDER_FUNCTION_CALL]}; diff --git a/lua_compressed.js b/lua_compressed.js index a82523f77..dad652a7f 100644 --- a/lua_compressed.js +++ b/lua_compressed.js @@ -6,7 +6,7 @@ Blockly.Lua=new Blockly.Generator("Lua");Blockly.Lua.addReservedWords("_,__inext Blockly.Lua.ORDER_ATOMIC=0;Blockly.Lua.ORDER_HIGH=1;Blockly.Lua.ORDER_EXPONENTIATION=2;Blockly.Lua.ORDER_UNARY=3;Blockly.Lua.ORDER_MULTIPLICATIVE=4;Blockly.Lua.ORDER_ADDITIVE=5;Blockly.Lua.ORDER_CONCATENATION=6;Blockly.Lua.ORDER_RELATIONAL=7;Blockly.Lua.ORDER_AND=8;Blockly.Lua.ORDER_OR=9;Blockly.Lua.ORDER_NONE=99; Blockly.Lua.init=function(a){Blockly.Lua.definitions_=Object.create(null);Blockly.Lua.functionNames_=Object.create(null);Blockly.Lua.variableDB_?Blockly.Lua.variableDB_.reset():Blockly.Lua.variableDB_=new Blockly.Names(Blockly.Lua.RESERVED_WORDS_);Blockly.Lua.variableDB_.setVariableMap(a.getVariableMap())}; Blockly.Lua.finish=function(a){var b=[],c;for(c in Blockly.Lua.definitions_)b.push(Blockly.Lua.definitions_[c]);delete Blockly.Lua.definitions_;delete Blockly.Lua.functionNames_;Blockly.Lua.variableDB_.reset();return b.join("\n\n")+"\n\n\n"+a};Blockly.Lua.scrubNakedValue=function(a){return"local _ = "+a+"\n"};Blockly.Lua.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"}; -Blockly.Lua.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();(e=Blockly.utils.wrap(e,Blockly.Lua.COMMENT_WRAP-3))&&(d+=Blockly.Lua.prefixLines(e,"-- ")+"\n");for(var f=0;fc?Blockly.PHP.valueToCode(a,b,Blockly.PHP.ORDER_SUBTRACTION)||f:d?Blockly.PHP.valueToCode(a,b,Blockly.PHP.ORDER_UNARY_NEGATION)||f:Blockly.PHP.valueToCode(a,b,e)||f;if(Blockly.isNumber(a))a=parseFloat(a)+c,d&&(a=-a);else{if(0c&& (a=a+" - "+-c,g=Blockly.PHP.ORDER_SUBTRACTION);d&&(a=c?"-("+a+")":"-"+a,g=Blockly.PHP.ORDER_UNARY_NEGATION);g=Math.floor(g);e=Math.floor(e);g&&e>=g&&(a="("+a+")")}return a};Blockly.PHP.colour={};Blockly.PHP.colour_picker=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.PHP.ORDER_ATOMIC]};Blockly.PHP.colour_random=function(a){return[Blockly.PHP.provideFunction_("colour_random",["function "+Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_+"() {"," return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);","}"])+"()",Blockly.PHP.ORDER_FUNCTION_CALL]}; diff --git a/python_compressed.js b/python_compressed.js index 02168a461..e697c40a2 100644 --- a/python_compressed.js +++ b/python_compressed.js @@ -10,7 +10,7 @@ Blockly.Python.init=function(a){Blockly.Python.PASS=this.INDENT+"pass\n";Blockly " = None");a=Blockly.Variables.allUsedVarModels(a);for(d=0;dc?"int("+a+" - "+-c+")":"int("+a+")",d&&(a="-"+a));return a};Blockly.Python.colour={};Blockly.Python.colour_picker=function(a){return["'"+a.getFieldValue("COLOUR")+"'",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour_random=function(a){Blockly.Python.definitions_.import_random="import random";return["'#%06x' % random.randint(0, 2**24 - 1)",Blockly.Python.ORDER_FUNCTION_CALL]}; Blockly.Python.colour_rgb=function(a){var b=Blockly.Python.provideFunction_("colour_rgb",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(r, g, b):"," r = round(min(100, max(0, r)) * 2.55)"," g = round(min(100, max(0, g)) * 2.55)"," b = round(min(100, max(0, b)) * 2.55)"," return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Python.valueToCode(a,"RED",Blockly.Python.ORDER_NONE)||0,d=Blockly.Python.valueToCode(a,"GREEN",Blockly.Python.ORDER_NONE)||0;a=Blockly.Python.valueToCode(a,"BLUE",Blockly.Python.ORDER_NONE)|| 0;return[b+"("+c+", "+d+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]}; diff --git a/tests/jsunit/index.html b/tests/jsunit/index.html index ccc72d3a4..aa61c8f3f 100644 --- a/tests/jsunit/index.html +++ b/tests/jsunit/index.html @@ -28,6 +28,9 @@ + + + diff --git a/tests/jsunit/utils_dom_test.js b/tests/jsunit/utils_dom_test.js new file mode 100644 index 000000000..7f4264a79 --- /dev/null +++ b/tests/jsunit/utils_dom_test.js @@ -0,0 +1,61 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_addClass() { + var p = document.createElement('p'); + Blockly.utils.dom.addClass(p, 'one'); + assertEquals('Adding "one"', 'one', p.className); + Blockly.utils.dom.addClass(p, 'one'); + assertEquals('Adding duplicate "one"', 'one', p.className); + Blockly.utils.dom.addClass(p, 'two'); + assertEquals('Adding "two"', 'one two', p.className); + Blockly.utils.dom.addClass(p, 'two'); + assertEquals('Adding duplicate "two"', 'one two', p.className); + Blockly.utils.dom.addClass(p, 'three'); + assertEquals('Adding "three"', 'one two three', p.className); +} + +function test_hasClass() { + var p = document.createElement('p'); + p.className = ' one three two three '; + assertTrue('Has "one"', Blockly.utils.dom.hasClass(p, 'one')); + assertTrue('Has "two"', Blockly.utils.dom.hasClass(p, 'two')); + assertTrue('Has "three"', Blockly.utils.dom.hasClass(p, 'three')); + assertFalse('Has no "four"', Blockly.utils.dom.hasClass(p, 'four')); + assertFalse('Has no "t"', Blockly.utils.dom.hasClass(p, 't')); + } + +function test_removeClass() { + var p = document.createElement('p'); + p.className = ' one three two three '; + Blockly.utils.dom.removeClass(p, 'two'); + assertEquals('Removing "two"', 'one three three', p.className); + Blockly.utils.dom.removeClass(p, 'four'); + assertEquals('Removing "four"', 'one three three', p.className); + Blockly.utils.dom.removeClass(p, 'three'); + assertEquals('Removing "three"', 'one', p.className); + Blockly.utils.dom.removeClass(p, 'ne'); + assertEquals('Removing "ne"', 'one', p.className); + Blockly.utils.dom.removeClass(p, 'one'); + assertEquals('Removing "one"', '', p.className); + Blockly.utils.dom.removeClass(p, 'zero'); + assertEquals('Removing "zero"', '', p.className); +} diff --git a/tests/jsunit/utils_math_test.js b/tests/jsunit/utils_math_test.js new file mode 100644 index 000000000..daaf928f9 --- /dev/null +++ b/tests/jsunit/utils_math_test.js @@ -0,0 +1,42 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_toRadians() { + var quarter = Math.PI / 2; + assertEquals('-90', -quarter, Blockly.utils.math.toRadians(-90)); + assertEquals('0', 0, Blockly.utils.math.toRadians(0)); + assertEquals('90', quarter, Blockly.utils.math.toRadians(90)); + assertEquals('180', 2 * quarter, Blockly.utils.math.toRadians(180)); + assertEquals('270', 3 * quarter, Blockly.utils.math.toRadians(270)); + assertEquals('360', 4 * quarter, Blockly.utils.math.toRadians(360)); + assertEquals('450', 5 * quarter, Blockly.utils.math.toRadians(360 + 90)); +} + +function test_toDegrees() { + var quarter = Math.PI / 2; + assertEquals('-90', -90, Blockly.utils.math.toDegrees(-quarter)); + assertEquals('0', 0, Blockly.utils.math.toDegrees(0)); + assertEquals('90', 90, Blockly.utils.math.toDegrees(quarter)); + assertEquals('180', 180, Blockly.utils.math.toDegrees(2 * quarter)); + assertEquals('270', 270, Blockly.utils.math.toDegrees(3 * quarter)); + assertEquals('360', 360, Blockly.utils.math.toDegrees(4 * quarter)); + assertEquals('450', 360 + 90, Blockly.utils.math.toDegrees(5 * quarter)); +} diff --git a/tests/jsunit/utils_string_test.js b/tests/jsunit/utils_string_test.js new file mode 100644 index 000000000..d37e85ea2 --- /dev/null +++ b/tests/jsunit/utils_string_test.js @@ -0,0 +1,81 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_startsWith() { + assertEquals('Does not start with', false, Blockly.utils.string.startsWith('123', '2')); + assertEquals('Start with', true, Blockly.utils.string.startsWith('123', '12')); + assertEquals('Start with empty string 1', true, Blockly.utils.string.startsWith('123', '')); + assertEquals('Start with empty string 2', true, Blockly.utils.string.startsWith('', '')); +} + +function test_commonWordPrefix() { + var len = Blockly.utils.string.commonWordPrefix('one,two,three,four,five'.split(',')); + assertEquals('No prefix', 0, len); + len = Blockly.utils.string.commonWordPrefix('Xone,Xtwo,Xthree,Xfour,Xfive'.split(',')); + assertEquals('No word prefix', 0, len); + len = Blockly.utils.string.commonWordPrefix('abc de,abc de,abc de,abc de'.split(',')); + assertEquals('Full equality', 6, len); + len = Blockly.utils.string.commonWordPrefix('abc deX,abc deY'.split(',')); + assertEquals('One word prefix', 4, len); + len = Blockly.utils.string.commonWordPrefix('abc de,abc deY'.split(',')); + assertEquals('Overflow no', 4, len); + len = Blockly.utils.string.commonWordPrefix('abc de,abc de Y'.split(',')); + assertEquals('Overflow yes', 6, len); + len = Blockly.utils.string.commonWordPrefix(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.utils.string.commonWordPrefix([]); + assertEquals('Empty list', 0, len); + len = Blockly.utils.string.commonWordPrefix('turn left,turn right'.split(',')); + assertEquals('No prefix due to &nbsp;', 0, len); + len = Blockly.utils.string.commonWordPrefix('turn\u00A0left,turn\u00A0right'.split(',')); + assertEquals('No prefix due to \\u00A0', 0, len); +} + +function test_commonWordSuffix() { + var len = Blockly.utils.string.commonWordSuffix('one,two,three,four,five'.split(',')); + assertEquals('No prefix', 0, len); + len = Blockly.utils.string.commonWordSuffix('oneX,twoX,threeX,fourX,fiveX'.split(',')); + assertEquals('No word prefix', 0, len); + len = Blockly.utils.string.commonWordSuffix('abc de,abc de,abc de,abc de'.split(',')); + assertEquals('Full equality', 6, len); + len = Blockly.utils.string.commonWordSuffix('Xabc de,Yabc de'.split(',')); + assertEquals('One word prefix', 3, len); + len = Blockly.utils.string.commonWordSuffix('abc de,Yabc de'.split(',')); + assertEquals('Overflow no', 3, len); + len = Blockly.utils.string.commonWordSuffix('abc de,Y abc de'.split(',')); + assertEquals('Overflow yes', 6, len); + len = Blockly.utils.string.commonWordSuffix(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.utils.string.commonWordSuffix([]); + assertEquals('Empty list', 0, len); +} + +function test_shortestStringLength() { + var len = Blockly.utils.string.shortestStringLength('one,two,three,four,five'.split(',')); + assertEquals('Length of "one"', 3, len); + len = Blockly.utils.string.shortestStringLength('one,two,three,four,five,'.split(',')); + assertEquals('Length of ""', 0, len); + len = Blockly.utils.string.shortestStringLength(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.utils.string.shortestStringLength([]); + assertEquals('Empty list', 0, len); +} + diff --git a/tests/jsunit/utils_test.js b/tests/jsunit/utils_test.js index 305dee7d5..1fd66be99 100644 --- a/tests/jsunit/utils_test.js +++ b/tests/jsunit/utils_test.js @@ -28,100 +28,6 @@ function test_genUid() { } } -function test_addClass() { - var p = document.createElement('p'); - Blockly.utils.addClass(p, 'one'); - assertEquals('Adding "one"', 'one', p.className); - Blockly.utils.addClass(p, 'one'); - assertEquals('Adding duplicate "one"', 'one', p.className); - Blockly.utils.addClass(p, 'two'); - assertEquals('Adding "two"', 'one two', p.className); - Blockly.utils.addClass(p, 'two'); - assertEquals('Adding duplicate "two"', 'one two', p.className); - Blockly.utils.addClass(p, 'three'); - assertEquals('Adding "three"', 'one two three', p.className); -} - -function test_hasClass() { - var p = document.createElement('p'); - p.className = ' one three two three '; - assertTrue('Has "one"', Blockly.utils.hasClass(p, 'one')); - assertTrue('Has "two"', Blockly.utils.hasClass(p, 'two')); - assertTrue('Has "three"', Blockly.utils.hasClass(p, 'three')); - assertFalse('Has no "four"', Blockly.utils.hasClass(p, 'four')); - assertFalse('Has no "t"', Blockly.utils.hasClass(p, 't')); - } - -function test_removeClass() { - var p = document.createElement('p'); - p.className = ' one three two three '; - Blockly.utils.removeClass(p, 'two'); - assertEquals('Removing "two"', 'one three three', p.className); - Blockly.utils.removeClass(p, 'four'); - assertEquals('Removing "four"', 'one three three', p.className); - Blockly.utils.removeClass(p, 'three'); - assertEquals('Removing "three"', 'one', p.className); - Blockly.utils.removeClass(p, 'ne'); - assertEquals('Removing "ne"', 'one', p.className); - Blockly.utils.removeClass(p, 'one'); - assertEquals('Removing "one"', '', p.className); - Blockly.utils.removeClass(p, 'zero'); - assertEquals('Removing "zero"', '', p.className); -} - -function test_shortestStringLength() { - var len = Blockly.utils.shortestStringLength('one,two,three,four,five'.split(',')); - assertEquals('Length of "one"', 3, len); - len = Blockly.utils.shortestStringLength('one,two,three,four,five,'.split(',')); - assertEquals('Length of ""', 0, len); - len = Blockly.utils.shortestStringLength(['Hello World']); - assertEquals('List of one', 11, len); - len = Blockly.utils.shortestStringLength([]); - assertEquals('Empty list', 0, len); -} - -function test_commonWordPrefix() { - var len = Blockly.utils.commonWordPrefix('one,two,three,four,five'.split(',')); - assertEquals('No prefix', 0, len); - len = Blockly.utils.commonWordPrefix('Xone,Xtwo,Xthree,Xfour,Xfive'.split(',')); - assertEquals('No word prefix', 0, len); - len = Blockly.utils.commonWordPrefix('abc de,abc de,abc de,abc de'.split(',')); - assertEquals('Full equality', 6, len); - len = Blockly.utils.commonWordPrefix('abc deX,abc deY'.split(',')); - assertEquals('One word prefix', 4, len); - len = Blockly.utils.commonWordPrefix('abc de,abc deY'.split(',')); - assertEquals('Overflow no', 4, len); - len = Blockly.utils.commonWordPrefix('abc de,abc de Y'.split(',')); - assertEquals('Overflow yes', 6, len); - len = Blockly.utils.commonWordPrefix(['Hello World']); - assertEquals('List of one', 11, len); - len = Blockly.utils.commonWordPrefix([]); - assertEquals('Empty list', 0, len); - len = Blockly.utils.commonWordPrefix('turn left,turn right'.split(',')); - assertEquals('No prefix due to &nbsp;', 0, len); - len = Blockly.utils.commonWordPrefix('turn\u00A0left,turn\u00A0right'.split(',')); - assertEquals('No prefix due to \\u00A0', 0, len); -} - -function test_commonWordSuffix() { - var len = Blockly.utils.commonWordSuffix('one,two,three,four,five'.split(',')); - assertEquals('No prefix', 0, len); - len = Blockly.utils.commonWordSuffix('oneX,twoX,threeX,fourX,fiveX'.split(',')); - assertEquals('No word prefix', 0, len); - len = Blockly.utils.commonWordSuffix('abc de,abc de,abc de,abc de'.split(',')); - assertEquals('Full equality', 6, len); - len = Blockly.utils.commonWordSuffix('Xabc de,Yabc de'.split(',')); - assertEquals('One word prefix', 3, len); - len = Blockly.utils.commonWordSuffix('abc de,Yabc de'.split(',')); - assertEquals('Overflow no', 3, len); - len = Blockly.utils.commonWordSuffix('abc de,Y abc de'.split(',')); - assertEquals('Overflow yes', 6, len); - len = Blockly.utils.commonWordSuffix(['Hello World']); - assertEquals('List of one', 11, len); - len = Blockly.utils.commonWordSuffix([]); - assertEquals('Empty list', 0, len); -} - function test_tokenizeInterpolation() { var tokens = Blockly.utils.tokenizeInterpolation(''); assertArrayEquals('Null interpolation', [], tokens); @@ -233,13 +139,6 @@ function test_replaceMessageReferences() { assertEquals('Message ref and subref dereferenced.', 'before test subref string after', resultString); } -function test_startsWith() { - assertEquals('Does not start with', false, Blockly.utils.startsWith('123', '2')); - assertEquals('Start with', true, Blockly.utils.startsWith('123', '12')); - assertEquals('Start with empty string 1', true, Blockly.utils.startsWith('123', '')); - assertEquals('Start with empty string 2', true, Blockly.utils.startsWith('', '')); -} - function test_arrayRemove() { var arr = [1, 2, 3, 2]; assertEquals('Remove Not found', false, Blockly.utils.arrayRemove(arr, 0)); @@ -250,28 +149,6 @@ function test_arrayRemove() { assertEquals('Remove item again result', '1,3', arr.join(',')); } -function test_toRadians() { - var quarter = Math.PI / 2; - assertEquals('-90', -quarter, Blockly.utils.toRadians(-90)); - assertEquals('0', 0, Blockly.utils.toRadians(0)); - assertEquals('90', quarter, Blockly.utils.toRadians(90)); - assertEquals('180', 2 * quarter, Blockly.utils.toRadians(180)); - assertEquals('270', 3 * quarter, Blockly.utils.toRadians(270)); - assertEquals('360', 4 * quarter, Blockly.utils.toRadians(360)); - assertEquals('450', 5 * quarter, Blockly.utils.toRadians(360 + 90)); -} - -function test_toDegrees() { - var quarter = Math.PI / 2; - assertEquals('-90', -90, Blockly.utils.toDegrees(-quarter)); - assertEquals('0', 0, Blockly.utils.toDegrees(0)); - assertEquals('90', 90, Blockly.utils.toDegrees(quarter)); - assertEquals('180', 180, Blockly.utils.toDegrees(2 * quarter)); - assertEquals('270', 270, Blockly.utils.toDegrees(3 * quarter)); - assertEquals('360', 360, Blockly.utils.toDegrees(4 * quarter)); - assertEquals('450', 360 + 90, Blockly.utils.toDegrees(5 * quarter)); -} - function test_XY_REGEX() { var regex = Blockly.utils.getRelativeXY.XY_REGEX_; var m;