UNPKG

pxt-core

Version:

Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors

1 lines 4.3 MB
!function e(t,n,i){function r(s,a){if(!n[s]){if(!t[s]){var l="function"==typeof require&&require;if(!a&&l)return l(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[s]={exports:{}};t[s][0].call(u.exports,function(e){return r(t[s][1][e]||e)},u,u.exports,e,t,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.BlockDragger=void 0;const i=e("blockly");class r extends i.dragging.Dragger{onDrag(e,t){super.onDrag(e,t);const n=document.getElementsByClassName("blocklyToolbox")[0],r=document.getElementsByClassName("blocklyTreeRoot")[0]||document.getElementsByClassName("blocklyFlyout")[0],o=document.getElementById("blocklyTrashIcon");if(r&&o){const t=r.getBoundingClientRect(),l=(s=r.getBoundingClientRect(),a=e.clientX,Math.abs(a-(s.left+s.width/2))),c=i.Gesture.inProgress();if(c&&l<200||!c&&function(e,t){return t-(e.left+e.width)<0}(t,e.clientX)){const e=l/200;o.style.opacity=""+(1-e),o.style.display="block",n&&(r.style.opacity=`${e}`,l<50&&pxt.BrowserUtils.addClass(n,"blocklyToolboxDeleting"))}else o.style.display="none",r.style.opacity="1",n&&pxt.BrowserUtils.removeClass(n,"blocklyToolboxDeleting")}var s,a}onDragEnd(e){super.onDragEnd(e);const t=document.getElementsByClassName("blocklyToolbox")[0],n=document.getElementsByClassName("blocklyTreeRoot")[0]||document.getElementsByClassName("blocklyFlyout")[0],i=document.getElementById("blocklyTrashIcon");i&&n&&(i.style.display="none",n.style.opacity="1",t&&pxt.BrowserUtils.removeClass(t,"blocklyToolboxDeleting"))}}n.BlockDragger=r},{blockly:437}],2:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.BreakpointIcon=void 0;const i=e("blockly");class r extends i.icons.Icon{constructor(e,t){super(e),this.onStateChange=t,this.isSet_=!1}getType(){return r.type}initView(e){super.initView(e),this.breakpointSvg||(this.breakpointSvg=i.utils.dom.createSvgElement("circle",{class:"blocklyBreakpointSymbol",stroke:"white","stroke-width":2,cx:7,cy:11.5,r:8},this.svgRoot),this.updateColor())}getSize(){return new i.utils.Size(25,25)}onClick(){this.isSet_=!this.isSet_,this.updateColor(),this.onStateChange(this.sourceBlock,this.isSet_)}isEnabled(){return this.isSet_}setEnabled(e){this.isSet_=e,this.updateColor()}updateColor(){this.breakpointSvg&&this.breakpointSvg.setAttribute("fill",this.isSet_?"#FF0000":"#CCCCCC")}}n.BreakpointIcon=r,r.type=new i.icons.IconType("breakpoint")},{blockly:437}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initFunctions=void 0;const i=e("blockly"),r=e("../help"),o=e("../plugins/functions"),s=e("../toolbox"),a=e("../fields"),l=e("../loader"),c=e("../importer"),u=e("../fields/field_imagenotext");function d(e,t){if(!t)return[];let n=[];if(!pxt.appTarget.appTheme.hideFlyoutHeadings){let e=(0,s.createFlyoutHeadingLabel)(lf("Functions"),pxt.toolbox.getNamespaceColor("functions"),pxt.toolbox.getNamespaceIcon("functions"),"blocklyFlyoutIconfunctions");n.push(e)}const r=lf("Make a Function..."),o=lf("New function name:");let a=i.utils.xml.createElement("button");a.setAttribute("text",r),a.setAttribute("callbackKey","CREATE_FUNCTION");return e.registerButtonCallback("CREATE_FUNCTION",function(t){let n=t=>{i.dialog.prompt(o,t,function(t){pxt.tickEvent("blocks.makeafunction"),t&&(t=t.replace(/[\s\xa0]+/g," ").replace(/^ | $/g,""))==r&&(t=null),t&&(e.getVariableMap().getVariable(t)?i.dialog.alert(i.Msg.VARIABLE_ALREADY_EXISTS.replace("%1",t.toLowerCase()),function(){n(t)}):i.Procedures.isNameUsed(t,e)?(t=>{let n=e.getTopBlocks(!0)[0],r=10,o=10;if(n){let e=n.getRelativeToSurfaceXY();r=e.x+i.SNAP_RADIUS*(n.RTL?-1:1),o=e.y+2*i.SNAP_RADIUS}let s=i.utils.xml.createElement("xml"),a=i.utils.xml.createElement("block");a.setAttribute("type","procedures_defnoreturn"),a.setAttribute("x",String(r)),a.setAttribute("y",String(o));let l=i.utils.xml.createElement("field");l.setAttribute("name","NAME"),l.appendChild(document.createTextNode(t)),a.appendChild(l),s.appendChild(a);let u=(0,c.domToWorkspaceNoEvents)(s,e);i.hideChaff();let d=e.getBlockById(u[0]);d.select(),e.centerOnBlock(d.id,!0)})(t):i.dialog.alert(i.Msg.PROCEDURE_ALREADY_EXISTS.replace("%1",t.toLowerCase()),function(){n(t)}))})};n("doSomething")}),n.push(a),function(e,t){for(let r=0;r<e.length;r++){let o=e[r][0],s=(e[r][1],i.utils.xml.createElement("block"));s.setAttribute("type",t),s.setAttribute("gap","16"),s.setAttribute("colour",pxt.toolbox.getNamespaceColor("functions"));let a=i.utils.xml.createElement("field");a.textContent=o,a.setAttribute("name","NAME"),s.appendChild(a),n.push(s)}}(i.Procedures.allProcedures(e)[0],"procedures_callnoreturn"),n}n.initFunctions=function(){const e=i.Msg;e.FUNCTION_CREATE_NEW=lf("Make a Function..."),e.FUNCTION_WARNING_DUPLICATE_ARG=lf("Functions cannot use the same argument name more than once."),e.FUNCTION_WARNING_ARG_NAME_IS_FUNCTION_NAME=lf("Argument names must not be the same as the function name."),e.FUNCTION_WARNING_EMPTY_NAME=lf("Function and argument names cannot be empty."),e.FUNCTIONS_DEFAULT_FUNCTION_NAME=lf("doSomething"),e.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME=lf("bool"),e.FUNCTIONS_DEFAULT_STRING_ARG_NAME=lf("text"),e.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME=lf("num"),e.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME=lf("arg"),e.FUNCTION_FLYOUT_LABEL=lf("Your Functions"),e.FUNCTIONS_CREATE_CALL_OPTION=lf("Create 'call {0}'","%1"),e.FUNCTIONS_DEFNORETURN_TITLE=lf("function"),e.PROCEDURES_HUE=pxt.toolbox.getNamespaceColor("functions"),e.REPORTERS_HUE=pxt.toolbox.getNamespaceColor("variables");const t="procedures_defnoreturn",n=pxt.blocks.getBlockDefinition(t);e.PROCEDURES_DEFNORETURN_TITLE=n.block.PROCEDURES_DEFNORETURN_TITLE,e.PROCEDURE_ALREADY_EXISTS=n.block.PROCEDURE_ALREADY_EXISTS,i.Blocks.procedures_defnoreturn.init=function(){let e=new i.FieldTextInput("",i.Procedures.rename);this.appendDummyInput().appendField(i.Msg.PROCEDURES_DEFNORETURN_TITLE).appendField(e,"NAME").appendField("","PARAMS"),this.setColour(pxt.toolbox.getNamespaceColor("functions")),this.arguments_=[],this.argumentVarModels_=[],this.hat="cap",this.setStatements_(!0),this.statementConnection_=null},(0,r.installBuiltinHelpInfo)(t);const s="procedures_callnoreturn",h=pxt.blocks.getBlockDefinition(s);e.PROCEDURES_CALLRETURN_TOOLTIP=n.tooltip.toString(),i.Blocks.procedures_callnoreturn={init:function(){let e=new a.FieldProcedure("");this.appendDummyInput("TOPROW").appendField(h.block.PROCEDURES_CALLNORETURN_TITLE).appendField(e,"NAME"),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(pxt.toolbox.getNamespaceColor("functions")),this.arguments_=[],this.quarkConnections_={},this.quarkIds_=null},getProcedureCall:function(){return this.getFieldValue("NAME")},renameProcedure:function(e,t){i.Names.equals(e,this.getProcedureCall())&&this.setFieldValue(t,"NAME")},onchange:function(e){if(this.workspace&&!this.workspace.isFlyout&&!this.isInsertionMarker())if(e.type==i.Events.CREATE&&-1!=e.ids.indexOf(this.id)){let t=this.getProcedureCall(),n=i.Procedures.getDefinition(t,this.workspace);if(!n||n.type==this.defType_&&JSON.stringify(n.arguments_)==JSON.stringify(this.arguments_)||(n=null),!n){i.Events.setGroup(e.group);let t=i.utils.xml.createElement("xml"),n=i.utils.xml.createElement("block");n.setAttribute("type",this.defType_);let r=this.getRelativeToSurfaceXY(),o=r.x+i.SNAP_RADIUS*(this.RTL?-1:1),s=r.y+2*i.SNAP_RADIUS;n.setAttribute("x",o),n.setAttribute("y",s);let a=i.utils.xml.createElement("field");a.setAttribute("name","NAME"),a.appendChild(document.createTextNode(this.getProcedureCall())),n.appendChild(a),t.appendChild(n),(0,c.domToWorkspaceNoEvents)(t,this.workspace),i.Events.setGroup(!1)}}else if(e.type==i.Events.DELETE){let t=this.getProcedureCall();i.Procedures.getDefinition(t,this.workspace)||(i.Events.setGroup(e.group),this.dispose(!0,!1),i.Events.setGroup(!1))}},mutationToDom:function(){const e=document.createElement("mutation");return e.setAttribute("name",this.getProcedureCall()),e},domToMutation:function(e){const t=e.getAttribute("name");this.renameProcedure(this.getProcedureCall(),t)},customContextMenu:function(e){let t={enabled:!0};t.text=i.Msg.PROCEDURES_HIGHLIGHT_DEF;let n=this.getProcedureCall(),r=this.workspace;t.callback=function(){let e=i.Procedures.getDefinition(n,r);e&&e.select()},e.push(t)},defType_:"procedures_defnoreturn"},(0,r.installBuiltinHelpInfo)(s);const p="function_definition",f=pxt.blocks.getBlockDefinition(p);e.FUNCTIONS_EDIT_OPTION=f.block.FUNCTIONS_EDIT_OPTION,(0,r.installBuiltinHelpInfo)(p);const g="function_call",m=pxt.blocks.getBlockDefinition(g);e.FUNCTIONS_CALL_TITLE=m.block.FUNCTIONS_CALL_TITLE,e.FUNCTIONS_GO_TO_DEFINITION_OPTION=m.block.FUNCTIONS_GO_TO_DEFINITION_OPTION,(0,r.installBuiltinHelpInfo)(g),(0,r.installBuiltinHelpInfo)("function_call_output");const b="function_return";i.Blocks[b]={init:function(){!function(e){const t=pxt.blocks.getBlockDefinition("function_return"),n="0_add_button",r="0_rem_button";i.Extensions.apply("inline-svgs",e,!1);let o,s=!0;function a(){const i=e.getInput("RETURN_VALUE");if(s){if(!i){for(;e.getInput("");)e.removeInput("");e.jsonInit({message0:t.block.message_with_value,args0:[{type:"input_value",name:"RETURN_VALUE",check:null}],previousStatement:null,colour:pxt.toolbox.getNamespaceColor("functions")})}if(e.getInput(n)&&e.removeInput(n),e.getInput(r)||h(),o){const t=e.workspace.getBlockById(o);t&&t.outputConnection&&!t.outputConnection.targetBlock()&&e.getInput("RETURN_VALUE").connection.connect(t.outputConnection),o=void 0}}else{if(i){const n=i.connection.targetBlock();n&&(n.isShadow()&&n.setShadow(!1),i.connection.disconnect(),o=n.id),e.removeInput("RETURN_VALUE"),e.jsonInit({message0:t.block.message_no_value,args0:[],previousStatement:null,colour:pxt.toolbox.getNamespaceColor("functions")})}e.getInput(r)&&e.removeInput(r),e.getInput(n)||d()}e.setInputsInline(!0)}function l(e,t){e.setAttribute("no_return_value",t?"false":"true")}function c(e){return"true"!==e.getAttribute("no_return_value")}function d(){g(n,e.ADD_IMAGE_DATAURI,lf("Add return value"))}function h(){g(r,e.REMOVE_IMAGE_DATAURI,lf("Remove return value"))}function p(){return i.Xml.domToText(e.mutationToDom())}function f(t,n){t!==n&&i.Events.fire(new i.Events.BlockChange(e,"mutation",null,t,n))}function g(t,n,i){e.appendDummyInput(t).appendField(new u.FieldImageNoText(n,24,24,i,()=>{const e=p();s=!s;const t=p();f(e,t),a();f(t,p())},!1))}a(),e.domToMutation=e=>{e.hasAttribute("last_connected_id")&&(o=e.getAttribute("last_connected_id")),s=c(e),a()},e.mutationToDom=()=>{const t=document.createElement("mutation");return l(t,!!e.getInput("RETURN_VALUE")),o&&t.setAttribute("last_connected_id",o),t}}(this)},onchange:function(e){const t=this;if(!t.workspace||t.workspace.isFlyout)return;const n=e.type===i.Events.BLOCK_CREATE&&-1!=e.ids.indexOf(t.id),r=e.type===i.Events.BLOCK_DRAG&&e.blocks.some(e=>e.id===t.id);if(n||r){const n=t.getRootBlock();if(n.type===b||null!=n.previousConnection)return;n.type!==p&&(i.Events.setGroup(e.group),t.previousConnection.disconnect(),i.Events.setGroup(!1))}}},(0,r.installBuiltinHelpInfo)(b),i.Procedures.flyoutCategory=d;const y={number:pxt.blocks.defaultIconForArgType("number"),boolean:pxt.blocks.defaultIconForArgType("boolean"),string:pxt.blocks.defaultIconForArgType("string"),Array:pxt.blocks.defaultIconForArgType("Array")},v={},_=pxt.appTarget.runtime&&pxt.appTarget.runtime.functionsOptions;_&&_.extraFunctionEditorTypes&&_.extraFunctionEditorTypes.forEach(e=>{y[e.typeName]=e.icon||pxt.blocks.defaultIconForArgType(),e.defaultName&&(v[e.typeName]=e.defaultName)});for(const e of Object.keys(y))o.FunctionManager.getInstance().setIconForType(e,y[e]);for(const e of Object.keys(v))o.FunctionManager.getInstance().setArgumentNameForType(e,v[e]);i.Blocks.argument_reporter_custom&&(i.Blocks.argument_reporter_custom.domToMutation=function(e){const t=e.getAttribute("typename");this.typeName_=t,(0,l.setOutputCheck)(this,t,l.cachedBlockInfo)});const E=i.Blocks.function_definition.makeCallOption;i.Blocks.function_definition.makeCallOption=function(){const e=E.call(this),t=this.getName();return e.text=pxt.Util.lf("Create 'call {0}'",t),e}}},{"../fields":70,"../fields/field_imagenotext":38,"../help":72,"../importer":73,"../loader":77,"../plugins/functions":112,"../toolbox":140,blockly:437}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initLists=void 0;const i=e("blockly"),r=e("../help"),o=e("../constants");n.initLists=function(){const e=i.Msg,t="lists_create_with",n=pxt.blocks.getBlockDefinition(t);e.LISTS_CREATE_EMPTY_TITLE=n.block.LISTS_CREATE_EMPTY_TITLE,e.LISTS_CREATE_WITH_INPUT_WITH=n.block.LISTS_CREATE_WITH_INPUT_WITH,e.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD=n.block.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD,e.LISTS_CREATE_WITH_ITEM_TITLE=n.block.LISTS_CREATE_WITH_ITEM_TITLE,(0,r.installBuiltinHelpInfo)(t);const s="lists_length",a=pxt.blocks.getBlockDefinition(s);e.LISTS_LENGTH_TITLE=a.block.LISTS_LENGTH_TITLE,i.Blocks[s].init=function(){this.jsonInit({message0:e.LISTS_LENGTH_TITLE,args0:[{type:"input_value",name:"VALUE",check:["Array"]}],output:"Number",outputShape:o.provider.SHAPES.ROUND})},(0,r.installBuiltinHelpInfo)(s);const l="lists_index_get",c=pxt.blocks.getBlockDefinition(l);i.Blocks.lists_index_get={init:function(){this.jsonInit({message0:c.block.message0,args0:[{type:"input_value",name:"LIST",check:"Array"},{type:"input_value",name:"INDEX",check:"Number"}],colour:pxt.toolbox.blockColors.arrays,outputShape:o.provider.SHAPES.ROUND,inputsInline:!0}),this.setPreviousStatement(!1),this.setNextStatement(!1),this.setOutput(!0),(0,r.setBuiltinHelpInfo)(this,l)}};const u="lists_index_set",d=pxt.blocks.getBlockDefinition(u);i.Blocks[u]={init:function(){this.jsonInit({message0:d.block.message0,args0:[{type:"input_value",name:"LIST",check:"Array"},{type:"input_value",name:"INDEX",check:"Number"},{type:"input_value",name:"VALUE",check:null}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.blockColors.arrays,inputsInline:!0}),(0,r.setBuiltinHelpInfo)(this,u)}}}},{"../constants":18,"../help":72,blockly:437}],5:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initLogic=void 0;const i=e("blockly"),r=e("../help");n.initLogic=function(){const e=i.Msg,t="controls_if",n=pxt.blocks.getBlockDefinition(t),o=n.tooltip;e.CONTROLS_IF_MSG_IF=n.block.CONTROLS_IF_MSG_IF,e.CONTROLS_IF_MSG_THEN=n.block.CONTROLS_IF_MSG_THEN,e.CONTROLS_IF_MSG_ELSE=n.block.CONTROLS_IF_MSG_ELSE,e.CONTROLS_IF_MSG_ELSEIF=n.block.CONTROLS_IF_MSG_ELSEIF,e.CONTROLS_IF_TOOLTIP_1=o.CONTROLS_IF_TOOLTIP_1,e.CONTROLS_IF_TOOLTIP_2=o.CONTROLS_IF_TOOLTIP_2,e.CONTROLS_IF_TOOLTIP_3=o.CONTROLS_IF_TOOLTIP_3,e.CONTROLS_IF_TOOLTIP_4=o.CONTROLS_IF_TOOLTIP_4,(0,r.installBuiltinHelpInfo)(t);const s="logic_compare",a=pxt.blocks.getBlockDefinition(s).tooltip;e.LOGIC_COMPARE_TOOLTIP_EQ=a.LOGIC_COMPARE_TOOLTIP_EQ,e.LOGIC_COMPARE_TOOLTIP_NEQ=a.LOGIC_COMPARE_TOOLTIP_NEQ,e.LOGIC_COMPARE_TOOLTIP_LT=a.LOGIC_COMPARE_TOOLTIP_LT,e.LOGIC_COMPARE_TOOLTIP_LTE=a.LOGIC_COMPARE_TOOLTIP_LTE,e.LOGIC_COMPARE_TOOLTIP_GT=a.LOGIC_COMPARE_TOOLTIP_GT,e.LOGIC_COMPARE_TOOLTIP_GTE=a.LOGIC_COMPARE_TOOLTIP_GTE,(0,r.installBuiltinHelpInfo)(s);const l="logic_operation",c=pxt.blocks.getBlockDefinition(l),u=c.tooltip;e.LOGIC_OPERATION_AND=c.block.LOGIC_OPERATION_AND,e.LOGIC_OPERATION_OR=c.block.LOGIC_OPERATION_OR,e.LOGIC_OPERATION_TOOLTIP_AND=u.LOGIC_OPERATION_TOOLTIP_AND,e.LOGIC_OPERATION_TOOLTIP_OR=u.LOGIC_OPERATION_TOOLTIP_OR,(0,r.installBuiltinHelpInfo)(l);const d="logic_negate",h=pxt.blocks.getBlockDefinition(d);e.LOGIC_NEGATE_TITLE=h.block.LOGIC_NEGATE_TITLE,(0,r.installBuiltinHelpInfo)(d);const p="logic_boolean",f=pxt.blocks.getBlockDefinition(p);e.LOGIC_BOOLEAN_TRUE=f.block.LOGIC_BOOLEAN_TRUE,e.LOGIC_BOOLEAN_FALSE=f.block.LOGIC_BOOLEAN_FALSE,(0,r.installBuiltinHelpInfo)(p)}},{"../help":72,blockly:437}],6:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initLoops=void 0;const i=e("blockly"),r=e("../help"),o=e("../plugins/duplicateOnDrag");n.initLoops=function(){const e=i.Msg,t="controls_repeat_ext",n=pxt.blocks.getBlockDefinition(t);e.CONTROLS_REPEAT_TITLE=n.block.CONTROLS_REPEAT_TITLE,e.CONTROLS_REPEAT_INPUT_DO=n.block.CONTROLS_REPEAT_INPUT_DO,(0,r.installBuiltinHelpInfo)(t);const s="device_while",a=pxt.blocks.getBlockDefinition(s);i.Blocks[s]={init:function(){this.jsonInit({message0:a.block.message0,args0:[{type:"input_value",name:"COND",check:"Boolean"}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.getNamespaceColor("loops")}),this.appendStatementInput("DO").appendField(a.block.appendField),(0,r.setBuiltinHelpInfo)(this,s)}};const l="pxt_controls_for",c=pxt.blocks.getBlockDefinition(l);i.Blocks[l]={init:function(){this.jsonInit({message0:c.block.message0,args0:[{type:"input_value",name:"VAR",variable:c.block.variable,check:"Variable"},{type:"input_value",name:"TO",check:"Number"}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.getNamespaceColor("loops"),inputsInline:!0}),this.appendStatementInput("DO").appendField(c.block.appendField);let e=this;(0,r.setHelpResources)(this,l,c.name,function(){return pxt.U.rlf(c.tooltip,e.getInputTargetBlock("VAR")?e.getInputTargetBlock("VAR").getField("VAR").getText():"")},c.url,String(pxt.toolbox.getNamespaceColor("loops")))},getVars:function(){return[this.getField("VAR").getText()]},renameVar:function(e,t){const n=this.getField("VAR");i.Names.equals(e,n.getText())&&n.setValue(t)}},(0,o.setDuplicateOnDrag)(l,"VAR");const u="controls_simple_for",d=pxt.blocks.getBlockDefinition(u);i.Blocks[u]={init:function(){this.jsonInit({message0:d.block.message0,args0:[{type:"field_variable",name:"VAR",variable:d.block.variable,variableTypes:[""]},{type:"input_value",name:"TO",check:"Number"}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.getNamespaceColor("loops"),inputsInline:!0}),this.appendStatementInput("DO").appendField(d.block.appendField);let e=this;(0,r.setHelpResources)(this,u,d.name,function(){return pxt.U.rlf(d.tooltip,e.getField("VAR").getText())},d.url,String(pxt.toolbox.getNamespaceColor("loops")))},getVars:function(){return[this.getField("VAR").getText()]},renameVar:function(e,t){const n=this.getField("VAR");i.Names.equals(e,n.getText())&&n.setValue(t)},customContextMenu:function(e){var t,n;if(!this.isCollapsed()&&!(null===(n=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===n?void 0:n.readOnly)){let t={enabled:!0},n=this.getField("VAR").getText();t.text=lf("Create 'get {0}'",n);let r=i.utils.xml.createElement("field");r.textContent=n,r.setAttribute("name","VAR");let o=i.utils.xml.createElement("block");o.setAttribute("type","variables_get"),o.appendChild(r),t.callback=i.ContextMenu.callbackFactory(this,o),e.push(t)}}};const h=pxt.blocks.getBlockDefinition(ts.pxtc.TS_BREAK_TYPE);i.Blocks[pxtc.TS_BREAK_TYPE]={init:function(){const e=pxt.toolbox.getNamespaceColor("loops");this.jsonInit({message0:h.block.message0,inputsInline:!0,previousStatement:null,nextStatement:null,colour:e}),(0,r.setHelpResources)(this,ts.pxtc.TS_BREAK_TYPE,h.name,h.tooltip,h.url,e,void 0,void 0,!1)}};const p=pxt.blocks.getBlockDefinition(ts.pxtc.TS_CONTINUE_TYPE);i.Blocks[pxtc.TS_CONTINUE_TYPE]={init:function(){const e=pxt.toolbox.getNamespaceColor("loops");this.jsonInit({message0:p.block.message0,inputsInline:!0,previousStatement:null,nextStatement:null,colour:e}),(0,r.setHelpResources)(this,ts.pxtc.TS_CONTINUE_TYPE,p.name,p.tooltip,p.url,e,void 0,void 0,!1)}};const f="#cccccc";i.Blocks[pxtc.COLLAPSED_BLOCK]={init:function(){this.jsonInit({message0:"...",inputsInline:!0,previousStatement:null,nextStatement:null,colour:f}),(0,r.setHelpResources)(this,ts.pxtc.COLLAPSED_BLOCK,"...",lf("a few blocks"),void 0,f,void 0,void 0,!1)}};const g="pxt_controls_for_of",m=pxt.blocks.getBlockDefinition(g);i.Blocks[g]={init:function(){this.jsonInit({message0:m.block.message0,args0:[{type:"input_value",name:"VAR",variable:m.block.variable,check:"Variable"},{type:"input_value",name:"LIST",check:["Array","String"]}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.blockColors.loops,inputsInline:!0}),this.appendStatementInput("DO").appendField(m.block.appendField);let e=this;(0,r.setHelpResources)(this,g,m.name,function(){return pxt.Util.rlf(m.tooltip,e.getInputTargetBlock("VAR")?e.getInputTargetBlock("VAR").getField("VAR").getText():"")},m.url,String(pxt.toolbox.getNamespaceColor("loops")))}},(0,o.setDuplicateOnDrag)(g,"VAR");const b="controls_for_of",y=pxt.blocks.getBlockDefinition(b);i.Blocks[b]={init:function(){this.jsonInit({message0:y.block.message0,args0:[{type:"field_variable",name:"VAR",variable:y.block.variable,variableTypes:[""]},{type:"input_value",name:"LIST",check:"Array"}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.blockColors.loops,inputsInline:!0}),this.appendStatementInput("DO").appendField(y.block.appendField);let e=this;(0,r.setHelpResources)(this,b,y.name,function(){return pxt.Util.rlf(y.tooltip,e.getField("VAR").getText())},y.url,String(pxt.toolbox.getNamespaceColor("loops")))}}}},{"../help":72,"../plugins/duplicateOnDrag":92,blockly:437}],7:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initMathRoundBlock=n.initMathOpBlock=n.initMath=void 0;const i=e("blockly"),r=e("../help"),o=e("../constants"),s=e("../composableMutations"),a=e("../fields/field_dropdown");function l(){const e=pxt.blocks.MATH_FUNCTIONS.unary.concat(pxt.blocks.MATH_FUNCTIONS.binary).concat(pxt.blocks.MATH_FUNCTIONS.infix),t="math_js_op",n=pxt.blocks.getBlockDefinition(t);function l(e,t){const n=e.appendValueInput("ARG"+(t?1:0));n.setCheck("Number"),t&&(n.connection.setShadowDom(function(){if(!c){c=document.createElement("shadow"),c.setAttribute("type","math_number");const e=document.createElement("field");e.setAttribute("name","NUM"),e.textContent="0",c.appendChild(e)}return c}()),n.connection.respawnShadow_())}function u(e,t){let n=!!e.getInput("ARG1");t?(n&&e.moveInputBefore("op_dropdown","ARG1"),e.moveInputBefore("ARG0","op_dropdown")):(n&&e.moveInputBefore("ARG0","ARG1"),e.moveInputBefore("op_dropdown","ARG0"))}i.Blocks[t]={init:function(){const t=this;t.setPreviousStatement(!1),t.setNextStatement(!1),t.setOutput(!0,"Number"),t.setOutputShape(o.provider.SHAPES.ROUND),t.setInputsInline(!0);t.appendDummyInput("op_dropdown").appendField(new a.FieldDropdown(e.map(e=>[n.block[e],e]),e=>function(e,t){!function(e){return-1!==pxt.blocks.MATH_FUNCTIONS.unary.indexOf(e)}(t)?e.getInput("ARG1")||l(e,!0):e.removeInput("ARG1",!0);return u(e,function(e){return-1!==pxt.blocks.MATH_FUNCTIONS.infix.indexOf(e)}(t)),t}(t,e)),"OP"),l(t,!1),(0,s.appendMutation)(t,{mutationToDom:e=>{let n;for(let e=0;e<t.inputList.length;e++){const i=t.inputList[e];if("op_dropdown"===i.name){n=!1;break}if("ARG0"===i.name){n=!0;break}}return e.setAttribute("op-type",(t.getInput("ARG1")?n?"infix":"binary":"unary").toString()),e},domToMutation:e=>{if(e.hasAttribute("op-type")){const n=e.getAttribute("op-type");"unary"!=n&&l(t,!0),u(t,"infix"===n)}}})}},(0,r.installHelpResources)(t,n.name,function(e){return n.tooltip[e.getFieldValue("OP")]},n.url,pxt.toolbox.getNamespaceColor(n.category))}let c;function u(){const e=pxt.blocks.ROUNDING_FUNCTIONS,t="math_js_round",n=pxt.blocks.getBlockDefinition(t);i.Blocks[t]={init:function(){const t=this;t.setPreviousStatement(!1),t.setNextStatement(!1),t.setOutput(!0,"Number"),t.setOutputShape(o.provider.SHAPES.ROUND),t.setInputsInline(!0);t.appendDummyInput("round_dropdown").appendField(new a.FieldDropdown(e.map(e=>[n.block[e],e])),"OP"),function(e){const t=e.appendValueInput("ARG0");t.setCheck("Number")}(t)}},(0,r.installHelpResources)(t,n.name,function(e){return n.tooltip[e.getFieldValue("OP")]},n.url,pxt.toolbox.getNamespaceColor(n.category))}n.initMath=function(e){const t="math_op2",n=pxt.blocks.getBlockDefinition(t),s=n.tooltip;i.Blocks[t]={init:function(){this.jsonInit({message0:n.block.message0,args0:[{type:"field_dropdown",name:"op",options:[[n.block.optionMin,"min"],[n.block.optionMax,"max"]]},{type:"input_value",name:"x",check:"Number"},{type:"input_value",name:"y",check:"Number"}],inputsInline:!0,output:"Number",outputShape:o.provider.SHAPES.ROUND,colour:pxt.toolbox.getNamespaceColor("math")}),(0,r.setHelpResources)(this,t,n.name,function(e){return s[e.getFieldValue("op")]},n.url,pxt.toolbox.getNamespaceColor(n.category))},codeCard:(0,r.attachCardInfo)(e,"Math.min")};const a="math_op3",c=pxt.blocks.getBlockDefinition(a);i.Blocks[a]={init:function(){this.jsonInit({message0:c.block.message0,args0:[{type:"input_value",name:"x",check:"Number"}],inputsInline:!0,output:"Number",outputShape:o.provider.SHAPES.ROUND,colour:pxt.toolbox.getNamespaceColor("math")}),(0,r.setBuiltinHelpInfo)(this,a)},codeCard:(0,r.attachCardInfo)(e,"Math.abs")},["math_number","math_integer","math_whole_number","math_number_minmax"].forEach(e=>{const t=pxt.blocks.getBlockDefinition(e);(0,r.installHelpResources)(e,t.name,t.tooltip,t.url,"#fff","#fff","#fff")});const d=i.Msg,h="math_arithmetic",p=pxt.blocks.getBlockDefinition(h),f=p.tooltip;d.MATH_ADDITION_SYMBOL=p.block.MATH_ADDITION_SYMBOL,d.MATH_SUBTRACTION_SYMBOL=p.block.MATH_SUBTRACTION_SYMBOL,d.MATH_MULTIPLICATION_SYMBOL=p.block.MATH_MULTIPLICATION_SYMBOL,d.MATH_DIVISION_SYMBOL=p.block.MATH_DIVISION_SYMBOL,d.MATH_POWER_SYMBOL=p.block.MATH_POWER_SYMBOL,(0,r.installHelpResources)(h,p.name,function(e){return f[e.getFieldValue("OP")]},p.url,pxt.toolbox.getNamespaceColor(p.category));const g="math_modulo",m=pxt.blocks.getBlockDefinition(g);d.MATH_MODULO_TITLE=m.block.MATH_MODULO_TITLE,(0,r.installBuiltinHelpInfo)(g),l(),u()},n.initMathOpBlock=l,n.initMathRoundBlock=u},{"../composableMutations":17,"../constants":18,"../fields/field_dropdown":34,"../help":72,blockly:437}],8:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initOnStart=void 0;const i=e("blockly"),r=e("../fields"),o=e("../help");n.initOnStart=function(){const e=pxt.blocks.getBlockDefinition(ts.pxtc.ON_START_TYPE);if(i.Blocks[ts.pxtc.ON_START_TYPE]={init:function(){var t;let n=null===(t=pxt.appTarget.runtime)||void 0===t?void 0:t.onStartColor;n&&(n=pxt.toolbox.getAccessibleBackground(n)),this.jsonInit({message0:e.block.message0,args0:[{type:"input_dummy"},{type:"input_statement",name:"HANDLER"}],colour:n||pxt.toolbox.getNamespaceColor("loops")}),(0,o.setHelpResources)(this,ts.pxtc.ON_START_TYPE,e.name,e.tooltip,e.url,n||pxt.toolbox.getNamespaceColor("loops"),void 0,void 0,!!pxt.appTarget.runtime&&pxt.appTarget.runtime.onStartUnDeletable)}},i.Blocks[pxtc.TS_STATEMENT_TYPE]={init:function(){let e,t,n=this;n.setColour("#717171"),n.setPreviousStatement(!0),n.setNextStatement(!0),n.setInputsInline(!1),n.domToMutation=e=>{const i=parseInt(e.getAttribute("numlines"));n.declaredVariables=e.getAttribute("declaredvars"),t=[];for(let n=0;n<i;n++){const i=e.getAttribute("line"+n);t.push(i)}n.setPythonEnabled(!1)},n.mutationToDom=()=>{let e=document.createElement("mutation");return t&&(t.forEach((t,n)=>e.setAttribute("line"+n,t)),e.setAttribute("numlines",t.length.toString())),n.declaredVariables&&e.setAttribute("declaredvars",this.declaredVariables),e},n.setPythonEnabled=i=>{if(e!==i){for(;n.inputList.length;)n.removeInput(n.inputList[0].name);e=i,i?(n.appendDummyInput().appendField(pxt.Util.lf("<python code>"),"LINE0"),n.setTooltip(lf("A Python statement that could not be converted to blocks"))):(t.forEach((e,t)=>{n.appendDummyInput().appendField(e,"LINE"+t)}),n.setTooltip(lf("A JavaScript statement that could not be converted to blocks")))}},n.getLines=()=>t,n.setEditable(!1),(0,o.setHelpResources)(this,pxtc.TS_STATEMENT_TYPE,lf("JavaScript statement"),lf("A JavaScript statement that could not be converted to blocks"),"/blocks/javascript-blocks","#717171")}},i.Blocks[pxtc.TS_OUTPUT_TYPE]={init:function(){let e=this;e.setColour("#717171"),e.setPreviousStatement(!1),e.setNextStatement(!1),e.setOutput(!0),e.setEditable(!1),e.appendDummyInput().appendField(new r.FieldTsExpression(""),"EXPRESSION"),e.setPythonEnabled=t=>{e.getField("EXPRESSION").setPythonEnabled(t),t?e.setTooltip(lf("A Python expression that could not be converted to blocks")):e.setTooltip(lf("A JavaScript expression that could not be converted to blocks"))},(0,o.setHelpResources)(e,pxtc.TS_OUTPUT_TYPE,lf("JavaScript expression"),lf("A JavaScript expression that could not be converted to blocks"),"/blocks/javascript-blocks","#717171")}},pxt.appTarget.runtime&&pxt.appTarget.runtime.pauseUntilBlock){const e=pxt.appTarget.runtime.pauseUntilBlock,t=pxt.blocks.getBlockDefinition(ts.pxtc.PAUSE_UNTIL_TYPE);i.Blocks[pxtc.PAUSE_UNTIL_TYPE]={init:function(){const n=e.color||pxt.toolbox.getNamespaceColor("loops");this.jsonInit({message0:t.block.message0,args0:[{type:"input_value",name:"PREDICATE",check:"Boolean"}],inputsInline:!0,previousStatement:null,nextStatement:null,colour:n}),(0,o.setHelpResources)(this,ts.pxtc.PAUSE_UNTIL_TYPE,t.name,t.tooltip,t.url,n,void 0,void 0,!1)}}}}},{"../fields":70,"../help":72,blockly:437}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initText=void 0;const i=e("blockly"),r=e("../help"),o=e("../constants");n.initText=function(){const e=pxt.blocks.getBlockDefinition("text");(0,r.installHelpResources)("text",e.name,e.tooltip,e.url,"#fff","#fff","#fff");const t="text_length",n=pxt.blocks.getBlockDefinition(t);i.Msg.TEXT_LENGTH_TITLE=n.block.TEXT_LENGTH_TITLE,i.Blocks[t].init=function(){this.jsonInit({message0:i.Msg.TEXT_LENGTH_TITLE,args0:[{type:"input_value",name:"VALUE",check:["String"]}],output:"Number",outputShape:o.provider.SHAPES.ROUND})},(0,r.installBuiltinHelpInfo)(t);const s="text_join",a=pxt.blocks.getBlockDefinition(s);i.Msg.TEXT_JOIN_TITLE_CREATEWITH=a.block.TEXT_JOIN_TITLE_CREATEWITH,(0,r.installBuiltinHelpInfo)(s)}},{"../constants":18,"../help":72,blockly:437}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.initVariables=n.CREATE_VAR_BTN_ID=void 0;const i=e("blockly"),r=e("../toolbox"),o=e("../help");function s(e,t){let o=[];if(!pxt.appTarget.appTheme.hideFlyoutHeadings){const e=(0,r.createFlyoutHeadingLabel)(lf("Variables"),pxt.toolbox.getNamespaceColor("variables"),pxt.toolbox.getNamespaceIcon("variables"));o.push(e)}const s=document.createElement("button");s.setAttribute("text",lf("Make a Variable...")),s.setAttribute("callbackKey","CREATE_VARIABLE"),s.setAttribute("id",n.CREATE_VAR_BTN_ID),e.registerButtonCallback("CREATE_VARIABLE",function(e){i.Variables.createVariableButtonHandler(e.getTargetWorkspace())}),o.push(s);const a=i.Variables.flyoutCategoryBlocks(e);return o=o.concat(a),o}n.CREATE_VAR_BTN_ID="create-variable-btn",n.initVariables=function(){let e=lf("{id:var}item");i.Variables.flyoutCategory=s,i.Variables.flyoutCategoryBlocks=function(e){let t=e.getVariableMap().getVariablesOfType(""),n=[];if(t.length>0){let e=t[t.length-1];t.sort(i.Variables.compareByName);for(let e=0;e<t.length;e++){const o=t[e];if(i.Blocks.variables_get){const e=(0,r.mkVariableFieldBlock)("variables_get",o.getId(),o.getType(),o.getName(),!1);e.setAttribute("gap","8"),n.push(e)}}if(n[n.length-1].setAttribute("gap","24"),(i.Blocks.variables_change||i.Blocks.variables_set)&&n.unshift((0,r.createFlyoutGroupLabel)(lf("Your Variables"))),i.Blocks.variables_change){let t=i.Blocks.variables_get?20:8;const o=(0,r.mkVariableFieldBlock)("variables_change",e.getId(),e.getType(),e.getName(),!1);o.setAttribute("gap",t+"");{let e=i.utils.xml.createElement("value");e.setAttribute("name","VALUE");let t=i.utils.xml.createElement("shadow");t.setAttribute("type","math_number"),e.appendChild(t);let n=i.utils.xml.createElement("field");n.setAttribute("name","NUM"),n.appendChild(document.createTextNode("1")),t.appendChild(n),o.appendChild(e)}n.unshift(o)}if(i.Blocks.variables_set){let t=i.Blocks.variables_change?8:24;const o=(0,r.mkVariableFieldBlock)("variables_set",e.getId(),e.getType(),e.getName(),!1);o.setAttribute("gap",t+"");{let e=i.utils.xml.createElement("value");e.setAttribute("name","VALUE");let t=i.utils.xml.createElement("shadow");t.setAttribute("type","math_number"),e.appendChild(t);let n=i.utils.xml.createElement("field");n.setAttribute("name","NUM"),n.appendChild(document.createTextNode("0")),t.appendChild(n),o.appendChild(e)}n.unshift(o)}}return n};const t=i.Msg,n="variables_get",a=pxt.blocks.getBlockDefinition(n);t.VARIABLES_GET_CREATE_SET=a.block.VARIABLES_GET_CREATE_SET,i.Blocks[n]={init:function(){this.jsonInit({type:"variables_get",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}",variableTypes:[""]}],output:null,style:"variable_blocks",helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableSetterGetter"]}),(0,o.setBuiltinHelpInfo)(this,n)}},(0,o.installBuiltinHelpInfo)("variables_get_reporter"),t.RENAME_VARIABLE=lf("Rename variable..."),t.DELETE_VARIABLE=lf('Delete the "%1" variable'),t.DELETE_VARIABLE_CONFIRMATION=lf('Delete %1 uses of the "%2" variable?'),t.NEW_VARIABLE_DROPDOWN=lf("New variable...");const l="variables_set",c=pxt.blocks.getBlockDefinition(l);t.VARIABLES_SET=c.block.VARIABLES_SET,t.VARIABLES_DEFAULT_NAME=e,t.VARIABLES_SET_CREATE_GET=lf("Create 'get %1'"),i.Blocks[l]={init:function(){this.jsonInit({type:"variables_set",message0:"%{BKY_VARIABLES_SET}",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}",variableTypes:[""]},{type:"input_value",name:"VALUE"}],previousStatement:null,nextStatement:null,style:"variable_blocks",tooltip:"%{BKY_VARIABLES_SET_TOOLTIP}",helpUrl:"%{BKY_VARIABLES_SET_HELPURL}",extensions:["contextMenu_variableSetterGetter"]}),(0,o.setBuiltinHelpInfo)(this,l)}};const u="variables_change",d=pxt.blocks.getBlockDefinition(u);i.Blocks[u]={init:function(){this.jsonInit({message0:d.block.message0,args0:[{type:"field_variable",name:"VAR",variable:e,variableTypes:[""]},{type:"input_value",name:"VALUE",check:"Number"}],inputsInline:!0,previousStatement:null,nextStatement:null,colour:pxt.toolbox.getNamespaceColor("variables")}),(0,o.setBuiltinHelpInfo)(this,u)},customContextMenu:function(e){var t,n;if(!(null===(n=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===n?void 0:n.readOnly)&&!this.isInFlyout){let t={enabled:this.workspace.remainingCapacity()>0},n=this.getField("VAR").getText();t.text=lf("Create 'get {0}'",n);let r=i.utils.xml.createElement("field");r.textContent=n,r.setAttribute("name","VAR");let o=i.utils.xml.createElement("block");o.setAttribute("type","variables_get"),o.appendChild(r),t.callback=i.ContextMenu.callbackFactory(this,o),e.push(t)}}},t.NEW_VARIABLE_TITLE=lf("New variable name:"),t.RENAME_VARIABLE_TITLE=lf("Rename all '%1' variables to:")}},{"../help":72,"../toolbox":140,blockly:437}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.renderCodeCard=void 0;const i=e("./render");n.renderCodeCard=function(e,t={}){const n=e.url?/^[^:]+:\/\//.test(e.url)?e.url:"/"+e.url.replace(/^\.?\/?/,""):e.youTubeId?`https://youtu.be/${e.youTubeId}`:void 0,r=!!n,o=(e,t,n="div",i="")=>{let r=document.createElement(n);return t&&(r.className=t),e&&e.appendChild(r),i&&r.appendChild(document.createTextNode(i+"")),r};let s=o(null,"ui "+(e.style||"card")+" "+(e.color||"")+(r?" link":""),r?"a":"div");if(t.role&&s.setAttribute("role",t.role),"option"===t.role&&s.setAttribute("aria-selected","true"),r){const e=s;e.href=n,/^https?:\/\//.test(n)&&(e.target="_blank")}if(!t.hideHeader&&e.header){let t=o(s,"ui content "+(e.responsive?" tall desktop only":""));e.header&&o(t,"description","span",e.header)}const a=(t.shortName?e.shortName:"")||e.name;let l=o(s,"ui image"+(e.responsive?" tall landscape only":""));if(e.label){let t=document.createElement("label");t.className=`ui ${e.labelClass?e.labelClass:"orange right ribbon"} label`,t.textContent=e.label,l.appendChild(t)}if(e.blocksXml){const t=(0,i.render)(e.blocksXml);if(t){let e=o(l,"");e.setAttribute("style","width:100%; min-height:10em"),e.appendChild(t)}else pxt.error("failed to render blocks"),pxt.debug(e.blocksXml)}if(e.typeScript){let t=document.createElement("pre");t.appendChild(document.createTextNode(e.typeScript)),l.appendChild(t)}if(e.imageUrl||(e.youTubeId?`https://img.youtube.com/vi/${e.youTubeId}/0.jpg`:void 0)){let t=document.createElement("div");t.className="ui imagewrapper";let n=document.createElement("div");n.className="ui cardimage",n.style.backgroundImage=`url("${e.imageUrl}")`,n.title=a,n.setAttribute("role","presentation"),t.appendChild(n),l.appendChild(t)}if("file"==e.cardType){let e=o(s,"ui fileimage");l.appendChild(e)}if(a||e.description){let t=o(s,"ui content");if(a&&(s.setAttribute("aria-label",a),o(t,"header","div",a)),e.description){const n=o(t,"ui description"),i=/((?:\.{1,3})|[\!\?…])/.exec(e.description);let r=e.description+".";if(i){const t=i[1];r=e.description.split(t)[0]+t}n.appendChild(document.createTextNode(r))}}if(e.time){let t=o(s,"meta");if(e.time){o(t,"date","span").appendChild(document.createTextNode(pxt.Util.timeSince(e.time)))}}if(e.extracontent){o(s,"extra content","div").appendChild(document.createTextNode(e.extracontent))}return s}},{"./render":138}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.workerOpAsync=n.compileExpression=n.AUTO_DISABLED_REASON=n.callKey=n.compileAsync=n.compileBlockAsync=n.PXT_WARNING_ID=void 0;const i=e("blockly"),r=e("./environment"),o=e("./typeChecker"),s=e("./util"),a=e("../toolbox"),l=e("../legacyMutations"),c=e("./variables"),u=e("../fields");function d(e,t){if(e.type===ts.pxtc.ON_START_TYPE)return 0;const n=t.stdCallTable[e.type],i=h(t,e),r=1+ts.pxtc.Util.codalHash16(i);return n&&n.attrs.afterOnStart?r:-r}function h(e,t){if(t.type==ts.pxtc.ON_START_TYPE)return JSON.stringify({name:ts.pxtc.ON_START_TYPE});if(t.type==ts.pxtc.FUNCTION_DEFINITION_TYPE)return JSON.stringify({type:"function",name:t.getFieldValue("function_name")});return JSON.stringify(p(t)).replace(/"id"\s*:\s*"[^"]+"/g,"")}function p(e){const t=[],n=[];for(const r of e.inputList){for(const e of r.fieldRow)e.name&&t.push(e.getText());r.type===i.inputs.inputTypes.VALUE&&(r.connection.targetBlock()?n.push(p(r.connection.targetBlock())):n.push(null))}return{type:e.type,fields:t,inputs:n}}function f(e,t){e.setDisabledReason(!t,n.AUTO_DISABLED_REASON);const i=e.getDescendants(!1);for(const e of i)e.setDisabledReason(!t,n.AUTO_DISABLED_REASON)}function g(e){e.setDisabledReason(!1,n.AUTO_DISABLED_REASON),e.setDisabledReason(!1,i.constants.MANUALLY_DISABLED),e.setDisabledReason(!1,"ORPHANED_BLOCK")}function m(e,t){if(t.isInsertionMarker())return[];let n;const i=[];switch(e.stats[t.type]=(e.stats[t.type]||0)+1,k(t,i),t.type){case"controls_if":n=function(e,t,n){let i=[];for(let r=0;r<=t.elseifCount_;++r){let o=b(e,(0,s.getInputTargetBlock)(e,t,"IF"+r),n),a=y(e,(0,s.getInputTargetBlock)(e,t,"DO"+r)),l=pxt.blocks.mkText("if (");r>0&&(l=pxt.blocks.mkText("else if ("),l.glueToBlock=pxt.blocks.GlueMode.WithSpace),(0,s.append)(i,[l,o,pxt.blocks.mkText(")"),a])}if(t.elseCount_){let n=pxt.blocks.mkText("else");n.glueToBlock=pxt.blocks.GlueMode.WithSpace,(0,s.append)(i,[n,y(e,(0,s.getInputTargetBlock)(e,t,"ELSE"))])}return i}(e,t,i);break;case"pxt_controls_for":case"controls_for":case"controls_simple_for":n=function(e,t,n){let i=(0,s.getInputTargetBlock)(e,t,"TO"),r=(0,s.getInputTargetBlock)(e,t,"DO"),a=(0,s.getInputTargetBlock)(e,t,"BY"),l=(0,s.getInputTargetBlock)(e,t,"FROM"),c=!a||a.type.match(/^math_number/)&&1==F(a),u=(0,o.lookup)(e,t,(0,s.getLoopVariableField)(e,t).getField("VAR").getText());return[pxt.blocks.mkText("for (let "+u.escapedName+" = "),l?b(e,l,n):pxt.blocks.mkText("0"),pxt.blocks.mkText("; "),pxt.blocks.mkInfix(pxt.blocks.mkText(u.escapedName),"<=",b(e,i,n)),pxt.blocks.mkText("; "),c?pxt.blocks.mkText(u.escapedName+"++"):pxt.blocks.mkInfix(pxt.blocks.mkText(u.escapedName),"+=",b(e,a,n)),pxt.blocks.mkText(")"),y(e,r)]}(e,t,i);break;case"pxt_controls_for_of":case"controls_for_of":n=function(e,t,n){let i,r=(0,s.getInputTargetBlock)(e,t,"LIST"),a=(0,s.getInputTargetBlock)(e,t,"DO");i=r&&"placeholder"!==r.type?b(e,r,n):pxt.blocks.mkText("[0]");let l=(0,o.lookup)(e,t,(0,s.getLoopVariableField)(e,t).getField("VAR").getText());return[pxt.blocks.mkText("for (let "+l.escapedName+" of "),i,pxt.blocks.mkText(")"),y(e,a)]}(e,t,i);break;case"variables_set":n=[_(e,t,i)];break;case"variables_change":n=[E(e,t,i)];break;case"controls_repeat_ext":n=function(e,t,n){let i=b(e,(0,s.getInputTargetBlock)(e,t,"TIMES"),n),r=y(e,(0,s.getInputTargetBlock)(e,t,"DO")),a=n=>!(0,o.lookup)(e,t,n),l="index";for(let e=2;!a(l);e++)l="index"+e;return[pxt.blocks.mkText("for (let "+l+" = 0; "),pxt.blocks.mkInfix(pxt.blocks.mkText(l),"<",i),pxt.blocks.mkText("; "+l+"++)"),r]}(e,t,i);break;case"device_while":n=function(e,t,n){let i=b(e,(0,s.getInputTargetBlock)(e,t,"COND"),n),r=y(e,(0,s.getInputTargetBlock)(e,t,"DO"));return[pxt.blocks.mkText("while ("),i,pxt.blocks.mkText(")"),r]}(e,t,i);break;case"procedures_defnoreturn":n=function(e,t){const n=(0,s.escapeVarName)(t.getFieldValue("NAME"),e,!0),i=(0,s.getInputTargetBlock)(e,t,"STACK");return[pxt.blocks.mkText("function "+n+"() "),y(e,i)]}(e,t);break;case"function_definition":n=function(e,t){const n=(0,s.escapeVarName)(t.getField("function_name").getText(),e,!0),i=(0,s.getInputTargetBlock)(e,t,"STACK"),r=t.getArguments().map(n=>{if("Array"==n.type){const i=(0,o.lookup)(e,t,n.name),r=(0,o.getConcreteType)(i.type),a=(null==r?void 0:r.type)&&"Array"!==r.type?r.type:"any[]";return`${(0,s.escapeVarName)(n.name,e)}: ${a}`}return`${(0,s.escapeVarName)(n.name,e)}: ${n.type}`}),a=(0,o.isFunctionRecursive)(e,t,!1);return[pxt.blocks.mkText(`function ${n} (${r.join(", ")})${a?": any":""}`),y(e,i)]}(e,t);break;case"procedures_callnoreturn":n=[I(e,t,i)];break;case"function_call":n=[O(e,t,i,!0)];break;case pxtc.TS_RETURN_STATEMENT_TYPE:n=[N(e,t,i)];break;case ts.pxtc.ON_START_TYPE:n=function(e,t){const n=(0,s.getInputTargetBlock)(e,t,"HANDLER"),i=y(e,n);pxt.appTarget.compile&&pxt.appTarget.compile.onStartText&&i&&i.children&&i.children.unshift(pxt.blocks.mkStmt(pxt.blocks.mkText(`// ${pxtc.ON_START_COMMENT}\n`)));return i}(e,t).children;break;case pxtc.TS_STATEMENT_TYPE:n=function(e,t){return t.getLines().map(e=>pxt.blocks.mkText(e+"\n"))}(0,t);break;case pxtc.PAUSE_UNTIL_TYPE:n=function(e,t,n){const i=pxt.appTarget.runtime&&pxt.appTarget.runtime.pauseUntilBlock;pxt.U.assert(!!i,"target has block enabled");const r=i.namespace,o=i.callName||"pauseUntil",s=D(e,t,{definitionName:"PREDICATE",actualName:"PREDICATE"},n),a=[pxt.blocks.mkGroup([pxt.blocks.mkText("() => "),s])];return r?[pxt.blocks.mkStmt(pxt.blocks.H.namespaceCall(r,o,a,!1))]:[pxt.blocks.mkStmt(pxt.blocks.H.mkCall(o,a,!1,!1))]}(e,t,i);break;case pxtc.TS_DEBUGGER_TYPE:n=function(e,t){if("1"==t.getFieldValue("ON_OFF"))return[pxt.blocks.mkText("debugger;\n")];return[]}(0,t);break;case pxtc.TS_BREAK_TYPE:n=[pxt.blocks.mkText("break;\n")];break;case pxtc.TS_CONTINUE_TYPE:n=[pxt.blocks.mkText("continue;\n")];break;default:n=e.stdCallTable[t.type]?[R(e,t,i)]:[pxt.blocks.mkStmt(b(e,t,i))]}let r=n[n.length-1];return r&&!r.id&&(r.id=t.id),i.length&&function(e,t){const n=[];for(const t of e)for(const e of t.split("\n"))n.push(pxt.blocks.mkText(`// ${e}`)),n.push(pxt.blocks.mkNewLine());for(const e of n.reverse())t.unshift(e)}(i,n),n.forEach(e=>{!(e.type===pxt.blocks.NT.Block||e.type===pxt.blocks.NT.Prefix&&pxt.Util.startsWith(e.op,"//"))||t.type==pxtc.ON_START_TYPE&&e.id||(e.id=t.id)}),n}function b(e,t,n){let i;if(pxt.U.assert(null!=t),e.stats[t.type]=(e.stats[t.type]||0)+1,k(t,n),"placeholder"!=t.type&&t.isEnabled&&t.isEnabled())switch(t.type){case"math_number":case"math_integer":case"math_whole_number":case"math_number_minmax":i=j(e,t,n);break;case"math_op2":i=function(e,t,n){let i=t.getFieldValue("op"),r=b(e,(0,s.getInputTargetBlock)(e,t,"x"),n),o=b(e,(0,s.getInputTargetBlock)(e,t,"y"),n);return pxt.blocks.H.mathCall(i,[r,o])}(e,t,n);break;case"math_op3":i=function(e,t,n){let i=b(e,(0,s.getInputTargetBlock)(e,t,"x"),n);return pxt.blocks.H.mathCall("abs",[i])}(e,t,n);break;case"math_arithmetic":case"logic_compare":case"logic_operation":i=function(e,t,n){let i=t.getFieldValue("OP"),r=(0,s.getInputTargetBlock)(e,t,"A"),a=(0,s.getInputTargetBlock)(e,t,"B"),l=[b(e,r,n),b(e,a,n)];c=i,-1!==["LT","LTE","GT","GTE","EQ","NEQ"].indexOf(c)&&P(e,r)&&P(e,a)&&pxt.blocks.flattenNode([l[0]]).output!==pxt.blocks.flattenNode([l[1]]).output&&(l=l.map(e=>pxt.blocks.H.mkParenthesizedExpression(pxt.blocks.mkGroup([e,pxt.blocks.mkText(" as any")]))));var c;const u=(0,o.returnType)(e,r);if((0,o.isStringType)(u)){if("EQ"==i)return pxt.blocks.H.mkSimpleCall("==",l);if("NEQ"==i)return pxt.blocks.H.mkSimpleCall("!=",l)}else if((0,o.isBooleanType)(u))return pxt.blocks.H.mkSimpleCall(A[i],l);return pxt.U.assert(i in A),pxt.blocks.H.mkSimpleCall(A[i],l)}(e,t,n);break;case"math_modulo":i=function(e,t,n){let i=(0,s.getInputTargetBlock)(e,t,"DIVIDEND"),r=(0,s.getInputTargetBlock)(e,t,"DIVISOR"),o=[b(e,i,n),b(e,r,n)];return pxt.blocks.H.mkSimpleCall("%",o)}(e,t,n);break;case"logic_boolean":i=function(e,t){return pxt.blocks.H.mkBooleanLiteral("TRUE"==t.getFieldValue("BOOL"))}(0,t);break;case"logic_negate":i=function(e,t,n){let i=b(e,(0,s.getInputTargetBlock)(e,t,"BOOL"),n);return pxt.blocks.mkPrefix("!",[pxt.blocks.H.mkParenthesizedExpression(i)])}(e,t,n);break;case"variables_get":case"variables_get_reporter":i=function(e,t){const n=t.getField("VAR").getText();let i=(0,o.lookup)(e,t,n);if(!i)return pxt.blocks.mkText(n);i.firstReference||(i.firstReference=t);return pxt.U.assert(null!=i&&null!=i.type),pxt.blocks.mkText(i.escapedName)}(e,t);break;case"text":i=function(e,t){return pxt.blocks.H.mkStringLiteral(t.getFieldValue("TEXT"))}(0,t);break;case"text_join":i=function(e,t,n){let i,r=0;for(;;){const o=(0,s.getInputTargetBlock)(e,t,"ADD"+r);if(r++,!o){if(r<t.inputList.length)continue;break}const a=b(e,o,n);i=i?pxt.blocks.H.mkSimpleCall("+",[i,a]):0===o.type.indexOf("text")?a:pxt.blocks.H.mkSimpleCall("+",[pxt.blocks.H.mkStringLiteral(""),a])}if(!i)return pxt.blocks.H.mkStringLiteral("");return i}(e,t,n);break;case"lists_create_with":i=function(e,t,n){let i=t.inputList.map(t=>t.connection&&t.connection.targetBlock()?b(e,t.connection.targetBlock(),n):void 0).filter(e=>!!e);return pxt.blocks.H.mkArrayLiteral(i,!t.getInputsInline())}(e,t,n);break;case"lists_index_get":i=function(e,t,n){const i=(0,s.getInputTargetBlock)(e,t,"LIST"),r=b(e,i,n),o=b(e,(0,s.getInputTargetBlock)(e,t,"INDEX"),n);return pxt.blocks.mkGroup([r,pxt.blocks.mkText("["),o,pxt.blocks.mkText("]")])}(e,t,n);break;case"lists_index_set":i=function(e,t,n){const i=(0,s.getInputTargetBlock)(e,t,"LIST"),r=b(e,i,n),o=b(e,(0,s.getInputTargetBlock)(e,t,"INDEX"),n),a=b(e,(0,s.getInputTargetBlock)(e,t,"VALUE"),n),l=pxt.blocks.mkGroup([r,pxt.blocks.mkText("["),o,pxt.blocks.mkText("] = "),a]);return"lists_create_with"===i.type?v(l):l}(e,t,n);break;case"math_js_op":case"math_js_round":i=function(e,t,n){const i=t.getFieldValue("OP"),r=[b(e,(0,s.getInputTargetBlock)(e,t,"ARG0"),n)];t.getInput("ARG1")&&r.push(b(e,(0,s.getInputTargetBlock)(e,t,"ARG1"),n));return pxt.blocks.H.mathCall(i,r)}(e,t,n);break;case pxtc.TS_OUTPUT_TYPE:i=function(e,t){return pxt.blocks.mkText(t.getFieldValue("EXPRESSION").trim())}(0,t);break;case"argument_reporter_boolean":case"argument_reporter_number":case"argument_reporter_string":case"argument_reporter_array":case"argument_reporter_custom":i=function(e,t){const n=(0,s.escapeVarName)(t.getFieldValue("VALUE"),e);return pxt.blocks.mkText(n)}(e,t);break;case"function_call_output":i=O(e,t,n,!1);break;default:let r=e.stdCallTable[t.type];r?i=r.imageLiteral?x(e,t,r.imageLiteral,r.imageLiteralColumns,r.imageLiteralRows,r.namespace,r.f,(0,s.visibleParams)(r,(0,s.countOptionals)(t,r)).map(i=>D(e,t,i,n))):M(e,t,r,n):(pxt.reportError("blocks","unable to compile expression",{details:t.type}),i=(0,o.defaultValueForType)((0,o.returnType)(e,t)))}else{if("Array"===(0,o.find)((0,o.returnType)(e,t)).type){let n="lists_index_get"===t.getParent().type;if(!n){const i=e.stdCallTable[t.getParent().type];n=i&&i.isExpression}const r=pxt.blocks.mkText("[0]");i=n?r:v(r)}else i=(0,o.defaultValueForType)((0,o.returnType)(e,t))}return i.id=t.id,i}function y(e,t){let n=[],i=t;for(;t;)t.isEnabled()&&(0,s.append)(n,m(e,t)),t=t.getNextBlock();return i&&e.blockDeclarations[i.id]&&e.blockDeclarations[i.id].filter(e=>!e.alreadyDeclared).forEach(t=>{n.unshift(S(t,e.blocksInfo)),t.alreadyDeclared=r.BlockDeclarationType.Implicit}),pxt.blocks.mkBlock(n)}function v(e){const t=pxt.blocks.mkStmt(pxt.blocks.mkText(";"));return t.glueToBlock=pxt.blocks.GlueMode.NoSpace,pxt.blocks.mkGroup([t,e])}function _(e,t,n){let i=(0,s.getInputTargetBlock)(e,t,"VALUE"),a=(0,o.lookup)(e,t,t.getField("VAR").getText());let l=e.idToScope[t.id].declaredVars[a.name]===a&&!a.firstReference&&!a.alreadyDeclared;l&&(0,s.forEachChildExpression)(t,t=>{if("variables_get"===t.type){(0,o.lookup)(e,t,t.getField("VAR").getText())===a&&(l=!1)}},!0);let c=b(e,i,n),u=a.escapedName+" = ";if(a.isAssigned=!0,l){a.alreadyDeclared=r.BlockDeclarationType.Assigned;const t=(0,o.getConcreteType)(a.type);if(u=`let ${a.escapedName} = `,t){const n=(0,o.getConcreteType)((0,o.returnType)(e,i));t.type!==n.type&&(u=`let ${a.escapedName}: ${t.type} = `)}}else a.firstReference||(a.firstReference=t);return pxt.blocks.mkStmt(pxt.blocks.mkText(u),c)}function E(e,t,n){let i=(0,s.getInputTargetBlock)(e,t,"VALUE"),r=(0,o.lookup)(e,t,t.getField("VAR").getText()),a=b(e,i,n),l=pxt.blocks.mkText(r.escapedName);return pxt.blocks.mkStmt(pxt.blocks.mkInfix(l,"+=",a))}function T(e,t,n,i,r,a){const c=i.map(n=>D(e,t,n,a)),u=(0,s.getInputTargetBlock)(e,t,"HANDLER"),d=y(e,u);let h;if(pxt.appTarget.compile&&pxt.appTarget.compile.emptyEventHandlerComment