-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript_compressed.js
87 lines (86 loc) · 45.5 KB
/
javascript_compressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Do not edit this file; automatically generated by build.py.
"use strict";
Blockly.JavaScript=new Blockly.Generator("JavaScript");Blockly.JavaScript.addReservedWords("Blockly,break,case,catch,continue,debugger,default,delete,do,else,finally,for,function,if,in,instanceof,new,return,switch,this,throw,try,typeof,var,void,while,with,class,enum,export,extends,import,super,implements,interface,let,package,private,protected,public,static,yield,const,null,true,false,Array,ArrayBuffer,Boolean,Date,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Error,eval,EvalError,Float32Array,Float64Array,Function,Infinity,Int16Array,Int32Array,Int8Array,isFinite,isNaN,Iterator,JSON,Math,NaN,Number,Object,parseFloat,parseInt,RangeError,ReferenceError,RegExp,StopIteration,String,SyntaxError,TypeError,Uint16Array,Uint32Array,Uint8Array,Uint8ClampedArray,undefined,uneval,URIError,applicationCache,closed,Components,content,_content,controllers,crypto,defaultStatus,dialogArguments,directories,document,frameElement,frames,fullScreen,globalStorage,history,innerHeight,innerWidth,length,location,locationbar,localStorage,menubar,messageManager,mozAnimationStartTime,mozInnerScreenX,mozInnerScreenY,mozPaintCount,name,navigator,opener,outerHeight,outerWidth,pageXOffset,pageYOffset,parent,performance,personalbar,pkcs11,returnValue,screen,screenX,screenY,scrollbars,scrollMaxX,scrollMaxY,scrollX,scrollY,self,sessionStorage,sidebar,status,statusbar,toolbar,top,URL,window,addEventListener,alert,atob,back,blur,btoa,captureEvents,clearImmediate,clearInterval,clearTimeout,close,confirm,disableExternalCapture,dispatchEvent,dump,enableExternalCapture,escape,find,focus,forward,GeckoActiveXObject,getAttention,getAttentionWithCycleCount,getComputedStyle,getSelection,home,matchMedia,maximize,minimize,moveBy,moveTo,mozRequestAnimationFrame,open,openDialog,postMessage,print,prompt,QueryInterface,releaseEvents,removeEventListener,resizeBy,resizeTo,restore,routeEvent,scroll,scrollBy,scrollByLines,scrollByPages,scrollTo,setCursor,setImmediate,setInterval,setResizable,setTimeout,showModalDialog,sizeToContent,stop,unescape,updateCommands,XPCNativeWrapper,XPCSafeJSObjectWrapper,onabort,onbeforeunload,onblur,onchange,onclick,onclose,oncontextmenu,ondevicemotion,ondeviceorientation,ondragdrop,onerror,onfocus,onhashchange,onkeydown,onkeypress,onkeyup,onload,onmousedown,onmousemove,onmouseout,onmouseover,onmouseup,onmozbeforepaint,onpaint,onpopstate,onreset,onresize,onscroll,onselect,onsubmit,onunload,onpageshow,onpagehide,Image,Option,Worker,Event,Range,File,FileReader,Blob,BlobBuilder,Attr,CDATASection,CharacterData,Comment,console,DocumentFragment,DocumentType,DomConfiguration,DOMError,DOMErrorHandler,DOMException,DOMImplementation,DOMImplementationList,DOMImplementationRegistry,DOMImplementationSource,DOMLocator,DOMObject,DOMString,DOMStringList,DOMTimeStamp,DOMUserData,Entity,EntityReference,MediaQueryList,MediaQueryListListener,NameList,NamedNodeMap,Node,NodeFilter,NodeIterator,NodeList,Notation,Plugin,PluginArray,ProcessingInstruction,SharedWorker,Text,TimeRanges,Treewalker,TypeInfo,UserDataHandler,Worker,WorkerGlobalScope,HTMLDocument,HTMLElement,HTMLAnchorElement,HTMLAppletElement,HTMLAudioElement,HTMLAreaElement,HTMLBaseElement,HTMLBaseFontElement,HTMLBodyElement,HTMLBRElement,HTMLButtonElement,HTMLCanvasElement,HTMLDirectoryElement,HTMLDivElement,HTMLDListElement,HTMLEmbedElement,HTMLFieldSetElement,HTMLFontElement,HTMLFormElement,HTMLFrameElement,HTMLFrameSetElement,HTMLHeadElement,HTMLHeadingElement,HTMLHtmlElement,HTMLHRElement,HTMLIFrameElement,HTMLImageElement,HTMLInputElement,HTMLKeygenElement,HTMLLabelElement,HTMLLIElement,HTMLLinkElement,HTMLMapElement,HTMLMenuElement,HTMLMetaElement,HTMLModElement,HTMLObjectElement,HTMLOListElement,HTMLOptGroupElement,HTMLOptionElement,HTMLOutputElement,HTMLParagraphElement,HTMLParamElement,HTMLPreElement,HTMLQuoteElement,HTMLScriptElement,HTMLSelectElement,HTMLSourceElement,HTMLSpanElement,HTMLStyleElement,HTMLTableElement,HTMLTableCaptionElement,HTMLTableCellElement,HTMLTableDataCellElement,HTMLTableHeaderCellElement,HTMLTableColElement,HTMLTableRowElement,HTMLTableSectionElement,HTMLTextAreaElement,HTMLTimeElement,HTMLTitleElement,HTMLTrackElement,HTMLUListElement,HTMLUnknownElement,HTMLVideoElement,HTMLCanvasElement,CanvasRenderingContext2D,CanvasGradient,CanvasPattern,TextMetrics,ImageData,CanvasPixelArray,HTMLAudioElement,HTMLVideoElement,NotifyAudioAvailableEvent,HTMLCollection,HTMLAllCollection,HTMLFormControlsCollection,HTMLOptionsCollection,HTMLPropertiesCollection,DOMTokenList,DOMSettableTokenList,DOMStringMap,RadioNodeList,SVGDocument,SVGElement,SVGAElement,SVGAltGlyphElement,SVGAltGlyphDefElement,SVGAltGlyphItemElement,SVGAnimationElement,SVGAnimateElement,SVGAnimateColorElement,SVGAnimateMotionElement,SVGAnimateTransformElement,SVGSetElement,SVGCircleElement,SVGClipPathElement,SVGColorProfileElement,SVGCursorElement,SVGDefsElement,SVGDescElement,SVGEllipseElement,SVGFilterElement,SVGFilterPrimitiveStandardAttributes,SVGFEBlendElement,SVGFEColorMatrixElement,SVGFEComponentTransferElement,SVGFECompositeElement,SVGFEConvolveMatrixElement,SVGFEDiffuseLightingElement,SVGFEDisplacementMapElement,SVGFEDistantLightElement,SVGFEFloodElement,SVGFEGaussianBlurElement,SVGFEImageElement,SVGFEMergeElement,SVGFEMergeNodeElement,SVGFEMorphologyElement,SVGFEOffsetElement,SVGFEPointLightElement,SVGFESpecularLightingElement,SVGFESpotLightElement,SVGFETileElement,SVGFETurbulenceElement,SVGComponentTransferFunctionElement,SVGFEFuncRElement,SVGFEFuncGElement,SVGFEFuncBElement,SVGFEFuncAElement,SVGFontElement,SVGFontFaceElement,SVGFontFaceFormatElement,SVGFontFaceNameElement,SVGFontFaceSrcElement,SVGFontFaceUriElement,SVGForeignObjectElement,SVGGElement,SVGGlyphElement,SVGGlyphRefElement,SVGGradientElement,SVGLinearGradientElement,SVGRadialGradientElement,SVGHKernElement,SVGImageElement,SVGLineElement,SVGMarkerElement,SVGMaskElement,SVGMetadataElement,SVGMissingGlyphElement,SVGMPathElement,SVGPathElement,SVGPatternElement,SVGPolylineElement,SVGPolygonElement,SVGRectElement,SVGScriptElement,SVGStopElement,SVGStyleElement,SVGSVGElement,SVGSwitchElement,SVGSymbolElement,SVGTextElement,SVGTextPathElement,SVGTitleElement,SVGTRefElement,SVGTSpanElement,SVGUseElement,SVGViewElement,SVGVKernElement,SVGAngle,SVGColor,SVGICCColor,SVGElementInstance,SVGElementInstanceList,SVGLength,SVGLengthList,SVGMatrix,SVGNumber,SVGNumberList,SVGPaint,SVGPoint,SVGPointList,SVGPreserveAspectRatio,SVGRect,SVGStringList,SVGTransform,SVGTransformList,SVGAnimatedAngle,SVGAnimatedBoolean,SVGAnimatedEnumeration,SVGAnimatedInteger,SVGAnimatedLength,SVGAnimatedLengthList,SVGAnimatedNumber,SVGAnimatedNumberList,SVGAnimatedPreserveAspectRatio,SVGAnimatedRect,SVGAnimatedString,SVGAnimatedTransformList,SVGPathSegList,SVGPathSeg,SVGPathSegArcAbs,SVGPathSegArcRel,SVGPathSegClosePath,SVGPathSegCurvetoCubicAbs,SVGPathSegCurvetoCubicRel,SVGPathSegCurvetoCubicSmoothAbs,SVGPathSegCurvetoCubicSmoothRel,SVGPathSegCurvetoQuadraticAbs,SVGPathSegCurvetoQuadraticRel,SVGPathSegCurvetoQuadraticSmoothAbs,SVGPathSegCurvetoQuadraticSmoothRel,SVGPathSegLinetoAbs,SVGPathSegLinetoHorizontalAbs,SVGPathSegLinetoHorizontalRel,SVGPathSegLinetoRel,SVGPathSegLinetoVerticalAbs,SVGPathSegLinetoVerticalRel,SVGPathSegMovetoAbs,SVGPathSegMovetoRel,ElementTimeControl,TimeEvent,SVGAnimatedPathData,SVGAnimatedPoints,SVGColorProfileRule,SVGCSSRule,SVGExternalResourcesRequired,SVGFitToViewBox,SVGLangSpace,SVGLocatable,SVGRenderingIntent,SVGStylable,SVGTests,SVGTextContentElement,SVGTextPositioningElement,SVGTransformable,SVGUnitTypes,SVGURIReference,SVGViewSpec,SVGZoomAndPan");
Blockly.JavaScript.ORDER_ATOMIC=0;Blockly.JavaScript.ORDER_MEMBER=1;Blockly.JavaScript.ORDER_NEW=1;Blockly.JavaScript.ORDER_FUNCTION_CALL=2;Blockly.JavaScript.ORDER_INCREMENT=3;Blockly.JavaScript.ORDER_DECREMENT=3;Blockly.JavaScript.ORDER_LOGICAL_NOT=4;Blockly.JavaScript.ORDER_BITWISE_NOT=4;Blockly.JavaScript.ORDER_UNARY_PLUS=4;Blockly.JavaScript.ORDER_UNARY_NEGATION=4;Blockly.JavaScript.ORDER_TYPEOF=4;Blockly.JavaScript.ORDER_VOID=4;Blockly.JavaScript.ORDER_DELETE=4;
Blockly.JavaScript.ORDER_MULTIPLICATION=5;Blockly.JavaScript.ORDER_DIVISION=5;Blockly.JavaScript.ORDER_MODULUS=5;Blockly.JavaScript.ORDER_ADDITION=6;Blockly.JavaScript.ORDER_SUBTRACTION=6;Blockly.JavaScript.ORDER_BITWISE_SHIFT=7;Blockly.JavaScript.ORDER_RELATIONAL=8;Blockly.JavaScript.ORDER_IN=8;Blockly.JavaScript.ORDER_INSTANCEOF=8;Blockly.JavaScript.ORDER_EQUALITY=9;Blockly.JavaScript.ORDER_BITWISE_AND=10;Blockly.JavaScript.ORDER_BITWISE_XOR=11;Blockly.JavaScript.ORDER_BITWISE_OR=12;
Blockly.JavaScript.ORDER_LOGICAL_AND=13;Blockly.JavaScript.ORDER_LOGICAL_OR=14;Blockly.JavaScript.ORDER_CONDITIONAL=15;Blockly.JavaScript.ORDER_ASSIGNMENT=16;Blockly.JavaScript.ORDER_COMMA=17;Blockly.JavaScript.ORDER_NONE=99;Blockly.JavaScript.INFINITE_LOOP_TRAP=null;
Blockly.JavaScript.init=function(){Blockly.JavaScript.definitions_=Object.create(null);if(Blockly.Variables){Blockly.JavaScript.variableDB_?Blockly.JavaScript.variableDB_.reset():Blockly.JavaScript.variableDB_=new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);for(var a=[],b=Blockly.Variables.allVariables(),c=0;c<b.length;c++)a[c]="var "+Blockly.JavaScript.variableDB_.getName(b[c],Blockly.Variables.NAME_TYPE)+";";Blockly.JavaScript.definitions_.variables=a.join("\n")}};
Blockly.JavaScript.finish=function(a){var b=[],c;for(c in Blockly.JavaScript.definitions_)b.push(Blockly.JavaScript.definitions_[c]);return b.join("\n\n")+"\n\n\n"+a};Blockly.JavaScript.scrubNakedValue=function(a){return a+";\n"};Blockly.JavaScript.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"};
Blockly.JavaScript.scrub_=function(a,b){if(null===b)return"";var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=this.prefixLines(d,"// ")+"\n");for(var e=0;e<a.inputList.length;e++)a.inputList[e].type==Blockly.INPUT_VALUE&&(d=a.inputList[e].connection.targetBlock())&&(d=this.allNestedComments(d))&&(c+=this.prefixLines(d,"// "))}e=a.nextConnection&&a.nextConnection.targetBlock();e=this.blockToCode(e);return c+b+e};Blockly.JavaScript.colour={};Blockly.JavaScript.colour_picker=function(a){return["'"+a.getTitleValue("COLOUR")+"'",Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.colour_random=function(a){if(!Blockly.JavaScript.definitions_.colour_random){a=Blockly.JavaScript.variableDB_.getDistinctName("colour_random",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.colour_random.functionName=a;var b=[];b.push("function "+a+"() {");b.push(" var num = Math.floor(Math.random() * Math.pow(2, 24));");b.push(" return '#' + ('00000' + num.toString(16)).substr(-6);");b.push("}");Blockly.JavaScript.definitions_.colour_random=b.join("\n")}return[Blockly.JavaScript.colour_random.functionName+
"()",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.colour_rgb=function(a){var b=Blockly.JavaScript.valueToCode(a,"RED",Blockly.JavaScript.ORDER_COMMA)||0,c=Blockly.JavaScript.valueToCode(a,"GREEN",Blockly.JavaScript.ORDER_COMMA)||0;a=Blockly.JavaScript.valueToCode(a,"BLUE",Blockly.JavaScript.ORDER_COMMA)||0;if(!Blockly.JavaScript.definitions_.colour_rgb){var d=Blockly.JavaScript.variableDB_.getDistinctName("colour_rgb",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.colour_rgb.functionName=d;var e=[];e.push("function "+d+"(r, g, b) {");
e.push(" r = Math.max(Math.min(Number(r), 100), 0) * 2.55;");e.push(" g = Math.max(Math.min(Number(g), 100), 0) * 2.55;");e.push(" b = Math.max(Math.min(Number(b), 100), 0) * 2.55;");e.push(" r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2);");e.push(" g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2);");e.push(" b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2);");e.push(" return '#' + r + g + b;");e.push("}");Blockly.JavaScript.definitions_.colour_rgb=e.join("\n")}return[Blockly.JavaScript.colour_rgb.functionName+
"("+b+", "+c+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.colour_blend=function(a){var b=Blockly.JavaScript.valueToCode(a,"COLOUR1",Blockly.JavaScript.ORDER_COMMA)||"'#000000'",c=Blockly.JavaScript.valueToCode(a,"COLOUR2",Blockly.JavaScript.ORDER_COMMA)||"'#000000'";a=Blockly.JavaScript.valueToCode(a,"RATIO",Blockly.JavaScript.ORDER_COMMA)||.5;if(!Blockly.JavaScript.definitions_.colour_blend){var d=Blockly.JavaScript.variableDB_.getDistinctName("colour_blend",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.colour_blend.functionName=d;
var e=[];e.push("function "+d+"(c1, c2, ratio) {");e.push(" ratio = Math.max(Math.min(Number(ratio), 1), 0);");e.push(" var r1 = parseInt(c1.substring(1, 3), 16);");e.push(" var g1 = parseInt(c1.substring(3, 5), 16);");e.push(" var b1 = parseInt(c1.substring(5, 7), 16);");e.push(" var r2 = parseInt(c2.substring(1, 3), 16);");e.push(" var g2 = parseInt(c2.substring(3, 5), 16);");e.push(" var b2 = parseInt(c2.substring(5, 7), 16);");e.push(" var r = Math.round(r1 * (1 - ratio) + r2 * ratio);");
e.push(" var g = Math.round(g1 * (1 - ratio) + g2 * ratio);");e.push(" var b = Math.round(b1 * (1 - ratio) + b2 * ratio);");e.push(" r = ('0' + (r || 0).toString(16)).slice(-2);");e.push(" g = ('0' + (g || 0).toString(16)).slice(-2);");e.push(" b = ('0' + (b || 0).toString(16)).slice(-2);");e.push(" return '#' + r + g + b;");e.push("}");Blockly.JavaScript.definitions_.colour_blend=e.join("\n")}return[Blockly.JavaScript.colour_blend.functionName+"("+b+", "+c+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.lists={};Blockly.JavaScript.lists_create_empty=function(a){return["[]",Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.lists_create_with=function(a){for(var b=Array(a.itemCount_),c=0;c<a.itemCount_;c++)b[c]=Blockly.JavaScript.valueToCode(a,"ADD"+c,Blockly.JavaScript.ORDER_COMMA)||"null";b="["+b.join(", ")+"]";return[b,Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.lists_repeat=function(a){if(!Blockly.JavaScript.definitions_.lists_repeat){var b=Blockly.JavaScript.variableDB_.getDistinctName("lists_repeat",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.lists_repeat.repeat=b;var c=[];c.push("function "+b+"(value, n) {");c.push(" var array = [];");c.push(" for (var i = 0; i < n; i++) {");c.push(" array[i] = value;");c.push(" }");c.push(" return array;");c.push("}");Blockly.JavaScript.definitions_.lists_repeat=c.join("\n")}b=Blockly.JavaScript.valueToCode(a,
"ITEM",Blockly.JavaScript.ORDER_COMMA)||"null";a=Blockly.JavaScript.valueToCode(a,"NUM",Blockly.JavaScript.ORDER_COMMA)||"0";return[Blockly.JavaScript.lists_repeat.repeat+"("+b+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.lists_length=function(a){return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_FUNCTION_CALL)||"''")+".length",Blockly.JavaScript.ORDER_MEMBER]};
Blockly.JavaScript.lists_isEmpty=function(a){return["!"+(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"[]")+".length",Blockly.JavaScript.ORDER_LOGICAL_NOT]};Blockly.JavaScript.lists_indexOf=function(a){var b="FIRST"==a.getTitleValue("END")?"indexOf":"lastIndexOf",c=Blockly.JavaScript.valueToCode(a,"FIND",Blockly.JavaScript.ORDER_NONE)||"''";return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"[]")+"."+b+"("+c+") + 1",Blockly.JavaScript.ORDER_MEMBER]};
Blockly.JavaScript.lists_getIndex=function(a){var b=a.getTitleValue("MODE")||"GET",c=a.getTitleValue("WHERE")||"FROM_START",d=Blockly.JavaScript.valueToCode(a,"AT",Blockly.JavaScript.ORDER_UNARY_NEGATION)||"1";a=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"[]";if("FIRST"==c){if("GET"==b)return[a+"[0]",Blockly.JavaScript.ORDER_MEMBER];if("GET_REMOVE"==b)return[a+".shift()",Blockly.JavaScript.ORDER_MEMBER];if("REMOVE"==b)return a+".shift();\n"}else if("LAST"==c){if("GET"==
b)return[a+".slice(-1)[0]",Blockly.JavaScript.ORDER_MEMBER];if("GET_REMOVE"==b)return[a+".pop()",Blockly.JavaScript.ORDER_MEMBER];if("REMOVE"==b)return a+".pop();\n"}else if("FROM_START"==c){d=Blockly.isNumber(d)?parseFloat(d)-1:d+" - 1";if("GET"==b)return[a+"["+d+"]",Blockly.JavaScript.ORDER_MEMBER];if("GET_REMOVE"==b)return[a+".splice("+d+", 1)[0]",Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return a+".splice("+d+", 1);\n"}else if("FROM_END"==c){if("GET"==b)return[a+".slice(-"+d+")[0]",
Blockly.JavaScript.ORDER_FUNCTION_CALL];if("GET_REMOVE"==b||"REMOVE"==b){if(!Blockly.JavaScript.definitions_.lists_remove_from_end){c=Blockly.JavaScript.variableDB_.getDistinctName("lists_remove_from_end",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.lists_getIndex.lists_remove_from_end=c;var e=[];e.push("function "+c+"(list, x) {");e.push(" x = list.length - x;");e.push(" return list.splice(x, 1)[0];");e.push("}");Blockly.JavaScript.definitions_.lists_remove_from_end=e.join("\n")}d=Blockly.JavaScript.lists_getIndex.lists_remove_from_end+
"("+a+", "+d+")";if("GET_REMOVE"==b)return[d,Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+";\n"}}else if("RANDOM"==c){Blockly.JavaScript.definitions_.lists_get_random_item||(c=Blockly.JavaScript.variableDB_.getDistinctName("lists_get_random_item",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.lists_getIndex.random=c,e=[],e.push("function "+c+"(list, remove) {"),e.push(" var x = Math.floor(Math.random() * list.length);"),e.push(" if (remove) {"),e.push(" return list.splice(x, 1)[0];"),
e.push(" } else {"),e.push(" return list[x];"),e.push(" }"),e.push("}"),Blockly.JavaScript.definitions_.lists_get_random_item=e.join("\n"));d=Blockly.JavaScript.lists_getIndex.random+"("+a+", "+("GET"!=b)+")";if("GET"==b||"GET_REMOVE"==b)return[d,Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+";\n"}throw"Unhandled combination (lists_getIndex).";};
Blockly.JavaScript.lists_setIndex=function(a){function b(){if(c.match(/^\w+$/))return"";var a=Blockly.JavaScript.variableDB_.getDistinctName("tmp_list",Blockly.Variables.NAME_TYPE),b="var "+a+" = "+c+";\n";c=a;return b}var c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]",d=a.getTitleValue("MODE")||"GET",e=a.getTitleValue("WHERE")||"FROM_START",g=Blockly.JavaScript.valueToCode(a,"AT",Blockly.JavaScript.ORDER_NONE)||"1";a=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||
"null";if("FIRST"==e){if("SET"==d)return c+"[0] = "+a+";\n";if("INSERT"==d)return c+".unshift("+a+");\n"}else if("LAST"==e){if("SET"==d)return e=b(),e+(c+"["+c+".length - 1] = "+a+";\n");if("INSERT"==d)return c+".push("+a+");\n"}else if("FROM_START"==e){g=Blockly.isNumber(g)?parseFloat(g)-1:g+" - 1";if("SET"==d)return c+"["+g+"] = "+a+";\n";if("INSERT"==d)return c+".splice("+g+", 0, "+a+");\n"}else if("FROM_END"==e){e=b();if("SET"==d)return e+=c+"["+c+".length - "+g+"] = "+a+";\n";if("INSERT"==d)return e+=
c+".splice("+c+".length - "+g+", 0, "+a+");\n"}else if("RANDOM"==e){e=b();g=Blockly.JavaScript.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE);e+="var "+g+" = Math.floor(Math.random() * "+c+".length);\n";if("SET"==d)return e+=c+"["+g+"] = "+a+";\n";if("INSERT"==d)return e+=c+".splice("+g+", 0, "+a+");\n"}throw"Unhandled combination (lists_setIndex).";};
Blockly.JavaScript.lists_getSublist=function(a){var b=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]",c=a.getTitleValue("WHERE1"),d=a.getTitleValue("WHERE2"),e=Blockly.JavaScript.valueToCode(a,"AT1",Blockly.JavaScript.ORDER_NONE)||"1";a=Blockly.JavaScript.valueToCode(a,"AT2",Blockly.JavaScript.ORDER_NONE)||"1";if("FIRST"==c&&"LAST"==d)b+=".concat()";else{if(!Blockly.JavaScript.definitions_.lists_get_sublist){var g=Blockly.JavaScript.variableDB_.getDistinctName("lists_get_sublist",
Blockly.Generator.NAME_TYPE);Blockly.JavaScript.lists_getSublist.func=g;var f=[];f.push("function "+g+"(list, where1, at1, where2, at2) {");f.push(" function getAt(where, at) {");f.push(" if (where == 'FROM_START') {");f.push(" at--;");f.push(" } else if (where == 'FROM_END') {");f.push(" at = list.length - at;");f.push(" } else if (where == 'FIRST') {");f.push(" at = 0;");f.push(" } else if (where == 'LAST') {");f.push(" at = list.length - 1;");f.push(" } else {");
f.push(" throw 'Unhandled option (lists_getSublist).';");f.push(" }");f.push(" return at;");f.push(" }");f.push(" at1 = getAt(where1, at1);");f.push(" at2 = getAt(where2, at2) + 1;");f.push(" return list.slice(at1, at2);");f.push("}");Blockly.JavaScript.definitions_.lists_get_sublist=f.join("\n")}b=Blockly.JavaScript.lists_getSublist.func+"("+b+", '"+c+"', "+e+", '"+d+"', "+a+")"}return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.logic={};
Blockly.JavaScript.controls_if=function(a){for(var b=0,c=Blockly.JavaScript.valueToCode(a,"IF"+b,Blockly.JavaScript.ORDER_NONE)||"false",d=Blockly.JavaScript.statementToCode(a,"DO"+b),e="if ("+c+") {\n"+d+"}",b=1;b<=a.elseifCount_;b++)c=Blockly.JavaScript.valueToCode(a,"IF"+b,Blockly.JavaScript.ORDER_NONE)||"false",d=Blockly.JavaScript.statementToCode(a,"DO"+b),e+=" else if ("+c+") {\n"+d+"}";a.elseCount_&&(d=Blockly.JavaScript.statementToCode(a,"ELSE"),e+=" else {\n"+d+"}\n");return e+"\n"};
Blockly.JavaScript.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getTitleValue("OP")],c="=="==b||"!="==b?Blockly.JavaScript.ORDER_EQUALITY:Blockly.JavaScript.ORDER_RELATIONAL,d=Blockly.JavaScript.valueToCode(a,"A",c)||"0";a=Blockly.JavaScript.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]};
Blockly.JavaScript.logic_operation=function(a){var b="AND"==a.getTitleValue("OP")?"&&":"||",c="&&"==b?Blockly.JavaScript.ORDER_LOGICAL_AND:Blockly.JavaScript.ORDER_LOGICAL_OR,d=Blockly.JavaScript.valueToCode(a,"A",c);a=Blockly.JavaScript.valueToCode(a,"B",c);if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};
Blockly.JavaScript.logic_negate=function(a){var b=Blockly.JavaScript.ORDER_LOGICAL_NOT;return["!"+(Blockly.JavaScript.valueToCode(a,"BOOL",b)||"true"),b]};Blockly.JavaScript.logic_boolean=function(a){return["TRUE"==a.getTitleValue("BOOL")?"true":"false",Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.logic_null=function(a){return["null",Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.logic_ternary=function(a){var b=Blockly.JavaScript.valueToCode(a,"IF",Blockly.JavaScript.ORDER_CONDITIONAL)||"false",c=Blockly.JavaScript.valueToCode(a,"THEN",Blockly.JavaScript.ORDER_CONDITIONAL)||"null";a=Blockly.JavaScript.valueToCode(a,"ELSE",Blockly.JavaScript.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.JavaScript.ORDER_CONDITIONAL]};Blockly.JavaScript.loops={};Blockly.JavaScript.controls_repeat=function(a){var b=Number(a.getTitleValue("TIMES")),c=Blockly.JavaScript.statementToCode(a,"DO");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(c=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);a=Blockly.JavaScript.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE);return"for (var "+a+" = 0; "+a+" < "+b+"; "+a+"++) {\n"+c+"}\n"};
Blockly.JavaScript.controls_repeat_ext=function(a){var b=Blockly.JavaScript.valueToCode(a,"TIMES",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",c=Blockly.JavaScript.statementToCode(a,"DO");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(c=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);a="";var d=Blockly.JavaScript.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.JavaScript.variableDB_.getDistinctName("repeat_end",Blockly.Variables.NAME_TYPE),
a+="var "+e+" = "+b+";\n");return a+("for (var "+d+" = 0; "+d+" < "+e+"; "+d+"++) {\n"+c+"}\n")};
Blockly.JavaScript.controls_whileUntil=function(a){var b="UNTIL"==a.getTitleValue("MODE"),c=Blockly.JavaScript.valueToCode(a,"BOOL",b?Blockly.JavaScript.ORDER_LOGICAL_NOT:Blockly.JavaScript.ORDER_NONE)||"false",d=Blockly.JavaScript.statementToCode(a,"DO");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(d=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+d);b&&(c="!"+c);return"while ("+c+") {\n"+d+"}\n"};
Blockly.JavaScript.controls_for=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",d=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",e=Blockly.JavaScript.valueToCode(a,"BY",Blockly.JavaScript.ORDER_ASSIGNMENT)||"1",g=Blockly.JavaScript.statementToCode(a,"DO");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(g=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,
"'"+a.id+"'")+g);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&Blockly.isNumber(e)){var f=parseFloat(c)<=parseFloat(d);a="for ("+b+" = "+c+"; "+b+(f?" <= ":" >= ")+d+"; "+b;b=Math.abs(parseFloat(e));a=(1==b?a+(f?"++":"--"):a+((f?" += ":" -= ")+b))+(") {\n"+g+"}\n")}else a="",f=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(f=Blockly.JavaScript.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="var "+f+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.JavaScript.variableDB_.getDistinctName(b+
"_end",Blockly.Variables.NAME_TYPE),a+="var "+c+" = "+d+";\n"),d=Blockly.JavaScript.variableDB_.getDistinctName(b+"_inc",Blockly.Variables.NAME_TYPE),a+="var "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("Math.abs("+e+");\n"),a+="if ("+f+" > "+c+") {\n",a+=" "+d+" = -"+d+";\n",a+="}\n",a+="for ("+b+" = "+f+";\n "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+";\n "+b+" += "+d+") {\n"+g+"}\n";return a};
Blockly.JavaScript.controls_forEach=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_ASSIGNMENT)||"[]",d=Blockly.JavaScript.statementToCode(a,"DO");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(d=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+d);a=Blockly.JavaScript.variableDB_.getDistinctName(b+"_index",Blockly.Variables.NAME_TYPE);if(c.match(/^\w+$/))b="for (var "+
a+" in "+c+") {\n"+(" "+b+" = "+c+"["+a+"];\n"+d)+"}\n";else var e=Blockly.JavaScript.variableDB_.getDistinctName(b+"_list",Blockly.Variables.NAME_TYPE),d=" "+b+" = "+e+"["+a+"];\n"+d,b="var "+e+" = "+c+";\nfor (var "+a+" in "+e+") {\n"+d+"}\n";return b};Blockly.JavaScript.controls_flow_statements=function(a){switch(a.getTitleValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.JavaScript.math={};Blockly.JavaScript.math_number=function(a){return[parseFloat(a.getTitleValue("NUM")),Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.JavaScript.ORDER_ADDITION],MINUS:[" - ",Blockly.JavaScript.ORDER_SUBTRACTION],MULTIPLY:[" * ",Blockly.JavaScript.ORDER_MULTIPLICATION],DIVIDE:[" / ",Blockly.JavaScript.ORDER_DIVISION],POWER:[null,Blockly.JavaScript.ORDER_COMMA]}[a.getTitleValue("OP")],c=b[0],b=b[1],d=Blockly.JavaScript.valueToCode(a,"A",b)||"0";a=Blockly.JavaScript.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:["Math.pow("+d+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.math_single=function(a){var b=a.getTitleValue("OP"),c;if("NEG"==b)return a=Blockly.JavaScript.valueToCode(a,"NUM",Blockly.JavaScript.ORDER_UNARY_NEGATION)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.JavaScript.ORDER_UNARY_NEGATION];a="SIN"==b||"COS"==b||"TAN"==b?Blockly.JavaScript.valueToCode(a,"NUM",Blockly.JavaScript.ORDER_DIVISION)||"0":Blockly.JavaScript.valueToCode(a,"NUM",Blockly.JavaScript.ORDER_NONE)||"0";switch(b){case "ABS":c="Math.abs("+a+")";break;case "ROOT":c="Math.sqrt("+
a+")";break;case "LN":c="Math.log("+a+")";break;case "EXP":c="Math.exp("+a+")";break;case "POW10":c="Math.pow(10,"+a+")";break;case "ROUND":c="Math.round("+a+")";break;case "ROUNDUP":c="Math.ceil("+a+")";break;case "ROUNDDOWN":c="Math.floor("+a+")";break;case "SIN":c="Math.sin("+a+" / 180 * Math.PI)";break;case "COS":c="Math.cos("+a+" / 180 * Math.PI)";break;case "TAN":c="Math.tan("+a+" / 180 * Math.PI)"}if(c)return[c,Blockly.JavaScript.ORDER_FUNCTION_CALL];switch(b){case "LOG10":c="Math.log("+a+
") / Math.log(10)";break;case "ASIN":c="Math.asin("+a+") / Math.PI * 180";break;case "ACOS":c="Math.acos("+a+") / Math.PI * 180";break;case "ATAN":c="Math.atan("+a+") / Math.PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.JavaScript.ORDER_DIVISION]};
Blockly.JavaScript.math_constant=function(a){return{PI:["Math.PI",Blockly.JavaScript.ORDER_MEMBER],E:["Math.E",Blockly.JavaScript.ORDER_MEMBER],GOLDEN_RATIO:["(1 + Math.sqrt(5)) / 2",Blockly.JavaScript.ORDER_DIVISION],SQRT2:["Math.SQRT2",Blockly.JavaScript.ORDER_MEMBER],SQRT1_2:["Math.SQRT1_2",Blockly.JavaScript.ORDER_MEMBER],INFINITY:["Infinity",Blockly.JavaScript.ORDER_ATOMIC]}[a.getTitleValue("CONSTANT")]};
Blockly.JavaScript.math_number_property=function(a){var b=Blockly.JavaScript.valueToCode(a,"NUMBER_TO_CHECK",Blockly.JavaScript.ORDER_MODULUS)||"0",c=a.getTitleValue("PROPERTY"),d;if("PRIME"==c)return Blockly.JavaScript.definitions_.isPrime||(a=Blockly.JavaScript.variableDB_.getDistinctName("isPrime",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.logic_prime=a,c=[],c.push("function "+a+"(n) {"),c.push(" // http://en.wikipedia.org/wiki/Primality_test#Naive_methods"),c.push(" if (n == 2 || n == 3) {"),
c.push(" return true;"),c.push(" }"),c.push(" // False if n is NaN, negative, is 1, or not whole."),c.push(" // And false if n is divisible by 2 or 3."),c.push(" if (isNaN(n) || n <= 1 || n % 1 != 0 || n % 2 == 0 || n % 3 == 0) {"),c.push(" return false;"),c.push(" }"),c.push(" // Check all the numbers of form 6k +/- 1, up to sqrt(n)."),c.push(" for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {"),c.push(" if (n % (x - 1) == 0 || n % (x + 1) == 0) {"),c.push(" return false;"),c.push(" }"),
c.push(" }"),c.push(" return true;"),c.push("}"),Blockly.JavaScript.definitions_.isPrime=c.join("\n")),d=Blockly.JavaScript.logic_prime+"("+b+")",[d,Blockly.JavaScript.ORDER_FUNCTION_CALL];switch(c){case "EVEN":d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.JavaScript.valueToCode(a,"DIVISOR",Blockly.JavaScript.ORDER_MODULUS)||"0",d=b+" % "+a+" == 0"}return[d,
Blockly.JavaScript.ORDER_EQUALITY]};Blockly.JavaScript.math_change=function(a){var b=Blockly.JavaScript.valueToCode(a,"DELTA",Blockly.JavaScript.ORDER_ADDITION)||"0";a=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE);return a+" = (typeof "+a+" == 'number' ? "+a+" : 0) + "+b+";\n"};Blockly.JavaScript.math_round=Blockly.JavaScript.math_single;Blockly.JavaScript.math_trig=Blockly.JavaScript.math_single;
Blockly.JavaScript.math_on_list=function(a){var b=a.getTitleValue("OP");switch(b){case "SUM":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]";a+=".reduce(function(x, y) {return x + y;})";break;case "MIN":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_COMMA)||"[]";a="Math.min.apply(null, "+a+")";break;case "MAX":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_COMMA)||"[]";a="Math.max.apply(null, "+a+")";break;case "AVERAGE":if(!Blockly.JavaScript.definitions_.math_mean){var c=
Blockly.JavaScript.variableDB_.getDistinctName("math_mean",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.math_on_list.math_mean=c;b=[];b.push("function "+c+"(myList) {");b.push(" return myList.reduce(function(x, y) {return x + y;}) / myList.length;");b.push("}");Blockly.JavaScript.definitions_.math_mean=b.join("\n")}a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=Blockly.JavaScript.math_on_list.math_mean+"("+a+")";break;case "MEDIAN":Blockly.JavaScript.definitions_.math_median||
(c=Blockly.JavaScript.variableDB_.getDistinctName("math_median",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.math_on_list.math_median=c,b=[],b.push("function "+c+"(myList) {"),b.push(" var localList = myList.filter(function (x) {return typeof x == 'number';});"),b.push(" if (!localList.length) return null;"),b.push(" localList.sort(function(a, b) {return b - a;});"),b.push(" if (localList.length % 2 == 0) {"),b.push(" return (localList[localList.length / 2 - 1] + localList[localList.length / 2]) / 2;"),
b.push(" } else {"),b.push(" return localList[(localList.length - 1) / 2];"),b.push(" }"),b.push("}"),Blockly.JavaScript.definitions_.math_median=b.join("\n"));a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=Blockly.JavaScript.math_on_list.math_median+"("+a+")";break;case "MODE":Blockly.JavaScript.definitions_.math_modes||(c=Blockly.JavaScript.variableDB_.getDistinctName("math_modes",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.math_on_list.math_modes=c,b=
[],b.push("function "+c+"(values) {"),b.push(" var modes = [];"),b.push(" var counts = [];"),b.push(" var maxCount = 0;"),b.push(" for (var i = 0; i < values.length; i++) {"),b.push(" var value = values[i];"),b.push(" var found = false;"),b.push(" var thisCount;"),b.push(" for (var j = 0; j < counts.length; j++) {"),b.push(" if (counts[j][0] === value) {"),b.push(" thisCount = ++counts[j][1];"),b.push(" found = true;"),b.push(" break;"),b.push(" }"),
b.push(" }"),b.push(" if (!found) {"),b.push(" counts.push([value, 1]);"),b.push(" thisCount = 1;"),b.push(" }"),b.push(" maxCount = Math.max(thisCount, maxCount);"),b.push(" }"),b.push(" for (var j = 0; j < counts.length; j++) {"),b.push(" if (counts[j][1] == maxCount) {"),b.push(" modes.push(counts[j][0]);"),b.push(" }"),b.push(" }"),b.push(" return modes;"),b.push("}"),Blockly.JavaScript.definitions_.math_modes=b.join("\n"));a=Blockly.JavaScript.valueToCode(a,
"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=Blockly.JavaScript.math_on_list.math_modes+"("+a+")";break;case "STD_DEV":Blockly.JavaScript.definitions_.math_standard_deviation||(c=Blockly.JavaScript.variableDB_.getDistinctName("math_standard_deviation",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.math_on_list.math_standard_deviation=c,b=[],b.push("function "+c+"(numbers) {"),b.push(" var n = numbers.length;"),b.push(" if (!n) return null;"),b.push(" var mean = numbers.reduce(function(x, y) {return x + y;}) / n;"),
b.push(" var variance = 0;"),b.push(" for (var j = 0; j < n; j++) {"),b.push(" variance += Math.pow(numbers[j] - mean, 2);"),b.push(" }"),b.push(" variance = variance / n;"),b.push(" return Math.sqrt(variance);"),b.push("}"),Blockly.JavaScript.definitions_.math_standard_deviation=b.join("\n"));a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=Blockly.JavaScript.math_on_list.math_standard_deviation+"("+a+")";break;case "RANDOM":Blockly.JavaScript.definitions_.math_random_item||
(c=Blockly.JavaScript.variableDB_.getDistinctName("math_random_item",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.math_on_list.math_random_item=c,b=[],b.push("function "+c+"(list) {"),b.push(" var x = Math.floor(Math.random() * list.length);"),b.push(" return list[x];"),b.push("}"),Blockly.JavaScript.definitions_.math_random_item=b.join("\n"));a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=Blockly.JavaScript.math_on_list.math_random_item+"("+a+")";break;default:throw"Unknown operator: "+
b;}return[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.math_modulo=function(a){var b=Blockly.JavaScript.valueToCode(a,"DIVIDEND",Blockly.JavaScript.ORDER_MODULUS)||"0";a=Blockly.JavaScript.valueToCode(a,"DIVISOR",Blockly.JavaScript.ORDER_MODULUS)||"0";return[b+" % "+a,Blockly.JavaScript.ORDER_MODULUS]};
Blockly.JavaScript.math_constrain=function(a){var b=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_COMMA)||"0",c=Blockly.JavaScript.valueToCode(a,"LOW",Blockly.JavaScript.ORDER_COMMA)||"0";a=Blockly.JavaScript.valueToCode(a,"HIGH",Blockly.JavaScript.ORDER_COMMA)||"Infinity";return["Math.min(Math.max("+b+", "+c+"), "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.math_random_int=function(a){var b=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_COMMA)||"0";a=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_COMMA)||"0";if(!Blockly.JavaScript.definitions_.math_random_int){var c=Blockly.JavaScript.variableDB_.getDistinctName("math_random_int",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.math_random_int.random_function=c;var d=[];d.push("function "+c+"(a, b) {");d.push(" if (a > b) {");d.push(" // Swap a and b to ensure a is smaller.");
d.push(" var c = a;");d.push(" a = b;");d.push(" b = c;");d.push(" }");d.push(" return Math.floor(Math.random() * (b - a + 1) + a);");d.push("}");Blockly.JavaScript.definitions_.math_random_int=d.join("\n")}return[Blockly.JavaScript.math_random_int.random_function+"("+b+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.math_random_float=function(a){return["Math.random()",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.procedures={};
Blockly.JavaScript.procedures_defreturn=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("NAME"),Blockly.Procedures.NAME_TYPE),c=Blockly.JavaScript.statementToCode(a,"STACK");Blockly.JavaScript.INFINITE_LOOP_TRAP&&(c=Blockly.JavaScript.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);var d=Blockly.JavaScript.valueToCode(a,"RETURN",Blockly.JavaScript.ORDER_NONE)||"";d&&(d=" return "+d+";\n");for(var e=[],g=0;g<a.arguments_.length;g++)e[g]=Blockly.JavaScript.variableDB_.getName(a.arguments_[g],
Blockly.Variables.NAME_TYPE);c="function "+b+"("+e.join(", ")+") {\n"+c+d+"}";c=Blockly.JavaScript.scrub_(a,c);Blockly.JavaScript.definitions_[b]=c;return null};Blockly.JavaScript.procedures_defnoreturn=Blockly.JavaScript.procedures_defreturn;
Blockly.JavaScript.procedures_callreturn=function(a){for(var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.JavaScript.valueToCode(a,"ARG"+d,Blockly.JavaScript.ORDER_COMMA)||"null";return[b+"("+c.join(", ")+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.procedures_callnoreturn=function(a){for(var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.JavaScript.valueToCode(a,"ARG"+d,Blockly.JavaScript.ORDER_COMMA)||"null";return b+"("+c.join(", ")+");\n"};
Blockly.JavaScript.procedures_ifreturn=function(a){var b="if ("+(Blockly.JavaScript.valueToCode(a,"CONDITION",Blockly.JavaScript.ORDER_NONE)||"false")+") {\n";a.hasReturnValue_?(a=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_NONE)||"null",b+=" return "+a+";\n"):b+=" return;\n";return b+"}\n"};Blockly.JavaScript.text={};Blockly.JavaScript.text=function(a){return[Blockly.JavaScript.quote_(a.getTitleValue("TEXT")),Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.text_join=function(a){var b;if(0==a.itemCount_)return["''",Blockly.JavaScript.ORDER_ATOMIC];if(1==a.itemCount_)return b=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''",["String("+b+")",Blockly.JavaScript.ORDER_FUNCTION_CALL];if(2==a.itemCount_)return b=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''",a=Blockly.JavaScript.valueToCode(a,"ADD1",Blockly.JavaScript.ORDER_NONE)||"''",["String("+b+") + String("+a+")",Blockly.JavaScript.ORDER_ADDITION];
b=Array(a.itemCount_);for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.JavaScript.valueToCode(a,"ADD"+c,Blockly.JavaScript.ORDER_COMMA)||"''";b="["+b.join(",")+"].join('')";return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_append=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE);a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''";return b+" = String("+b+") + String("+a+");\n"};
Blockly.JavaScript.text_length=function(a){return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_FUNCTION_CALL)||"''")+".length",Blockly.JavaScript.ORDER_MEMBER]};Blockly.JavaScript.text_isEmpty=function(a){return["!"+(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''"),Blockly.JavaScript.ORDER_LOGICAL_NOT]};
Blockly.JavaScript.text_indexOf=function(a){var b="FIRST"==a.getTitleValue("END")?"indexOf":"lastIndexOf",c=Blockly.JavaScript.valueToCode(a,"FIND",Blockly.JavaScript.ORDER_NONE)||"''";return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''")+"."+b+"("+c+") + 1",Blockly.JavaScript.ORDER_MEMBER]};
Blockly.JavaScript.text_charAt=function(a){var b=a.getTitleValue("WHERE")||"FROM_START",c=Blockly.JavaScript.valueToCode(a,"AT",Blockly.JavaScript.ORDER_UNARY_NEGATION)||"1";a=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''";switch(b){case "FIRST":return[a+".charAt(0)",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "LAST":return[a+".slice(-1)",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "FROM_START":return c=Blockly.isNumber(c)?parseFloat(c)-1:c+" - 1",[a+".charAt("+
c+")",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "FROM_END":return[a+".slice(-"+c+").charAt(0)",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "RANDOM":return Blockly.JavaScript.definitions_.text_random_letter||(b=Blockly.JavaScript.variableDB_.getDistinctName("text_random_letter",Blockly.Generator.NAME_TYPE),Blockly.JavaScript.text_charAt.text_random_letter=b,c=[],c.push("function "+b+"(text) {"),c.push(" var x = Math.floor(Math.random() * text.length);"),c.push(" return text[x];"),c.push("}"),
Blockly.JavaScript.definitions_.text_random_letter=c.join("\n")),a=Blockly.JavaScript.text_charAt.text_random_letter+"("+a+")",[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]}throw"Unhandled option (text_charAt).";};
Blockly.JavaScript.text_getSubstring=function(a){var b=Blockly.JavaScript.valueToCode(a,"STRING",Blockly.JavaScript.ORDER_MEMBER)||"[]",c=a.getTitleValue("WHERE1"),d=a.getTitleValue("WHERE2"),e=Blockly.JavaScript.valueToCode(a,"AT1",Blockly.JavaScript.ORDER_NONE)||"1";a=Blockly.JavaScript.valueToCode(a,"AT2",Blockly.JavaScript.ORDER_NONE)||"1";if("FIRST"!=c||"LAST"!=d){if(!Blockly.JavaScript.definitions_.text_get_substring){var g=Blockly.JavaScript.variableDB_.getDistinctName("text_get_substring",
Blockly.Generator.NAME_TYPE);Blockly.JavaScript.text_getSubstring.func=g;var f=[];f.push("function "+g+"(text, where1, at1, where2, at2) {");f.push(" function getAt(where, at) {");f.push(" if (where == 'FROM_START') {");f.push(" at--;");f.push(" } else if (where == 'FROM_END') {");f.push(" at = text.length - at;");f.push(" } else if (where == 'FIRST') {");f.push(" at = 0;");f.push(" } else if (where == 'LAST') {");f.push(" at = text.length - 1;");f.push(" } else {");
f.push(" throw 'Unhandled option (text_getSubstring).';");f.push(" }");f.push(" return at;");f.push(" }");f.push(" at1 = getAt(where1, at1);");f.push(" at2 = getAt(where2, at2) + 1;");f.push(" return text.slice(at1, at2);");f.push("}");Blockly.JavaScript.definitions_.text_get_substring=f.join("\n")}b=Blockly.JavaScript.text_getSubstring.func+"("+b+", '"+c+"', "+e+", '"+d+"', "+a+")"}return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_changeCase=function(a){var b={UPPERCASE:".toUpperCase()",LOWERCASE:".toLowerCase()",TITLECASE:null}[a.getTitleValue("CASE")];if(b)a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''",a+=b;else{if(!Blockly.JavaScript.definitions_.text_toTitleCase){b=Blockly.JavaScript.variableDB_.getDistinctName("text_toTitleCase",Blockly.Generator.NAME_TYPE);Blockly.JavaScript.text_changeCase.toTitleCase=b;var c=[];c.push("function "+b+"(str) {");c.push(" return str.replace(/\\S+/g,");
c.push(" function(txt) {return txt[0].toUpperCase() + txt.substring(1).toLowerCase();});");c.push("}");Blockly.JavaScript.definitions_.text_toTitleCase=c.join("\n")}a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''";a=Blockly.JavaScript.text_changeCase.toTitleCase+"("+a+")"}return[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_trim=function(a){var b={LEFT:".trimLeft()",RIGHT:".trimRight()",BOTH:".trim()"}[a.getTitleValue("MODE")];return[(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''")+b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_print=function(a){return"window.alert("+(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''")+");\n"};
Blockly.JavaScript.text_prompt=function(a){var b="window.prompt("+Blockly.JavaScript.quote_(a.getTitleValue("TEXT"))+")";"NUMBER"==a.getTitleValue("TYPE")&&(b="parseFloat("+b+")");return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.variables={};Blockly.JavaScript.variables_get=function(a){return[Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.variables_set=function(a){var b=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0";return Blockly.JavaScript.variableDB_.getName(a.getTitleValue("VAR"),Blockly.Variables.NAME_TYPE)+" = "+b+";\n"};Blockly.JavaScript.big={};Blockly.JavaScript.weather_get_temperature=function(a){return[{BLACKSBURG:60,SEATTLE:47,MIAMI:75,SANJOSE:88,NEWYORK:54}[a.getTitleValue("CITY")],Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.weather_get_forecasts=function(a){return["["+{BLACKSBURG:[60,71,65,66,78,75,66,55,53],SEATTLE:[47,53,42,41,44,50,46,44,42],MIAMI:[75,80,80,81,82,79,78,50,60],SANJOSE:[88,89,92,93,90,88,93,87,85],NEWYORK:[54,50,60,63,65,61,60,59,55]}[a.getTitleValue("CITY")]+"]",Blockly.JavaScript.ORDER_NONE]};
Blockly.JavaScript.stocks_get_current=function(a){return[{FB:-.74,AAPL:-1.13,MSFT:.31,GOOG:-.09}[a.getTitleValue("STOCK")],Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.stocks_get_past=function(a){return["["+{FB:[1.1,1,.7,.12,-.3,-.34,-.1,-.45,-.74],AAPL:[.47,.53,.42,.41,.3,.1,-.46,-.84,-1.13],MSFT:[.75,.8,.71,.67,.5,.15,.09,.03,.31],GOOG:[-.27,-.15,-.11,.12,.3,.1,-.3,-.1,-.09]}[a.getTitleValue("STOCK")]+"]",Blockly.JavaScript.ORDER_NONE]};