pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
1 lines • 4.28 MB
JavaScript
!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(),s=function(e,t){return Math.abs(t-(e.left+e.width/2))}(r.getBoundingClientRect(),e.clientX),a=i.Gesture.inProgress();if(a&&s<200||!a&&function(e,t){return t-(e.left+e.width)<0}(t,e.clientX)){const e=s/200;o.style.opacity=""+(1-e),o.style.display="block",n&&(r.style.opacity=`${e}`,s<50&&pxt.BrowserUtils.addClass(n,"blocklyToolboxDeleting"))}else o.style.display="none",r.style.opacity="1",n&&pxt.BrowserUtils.removeClass(n,"blocklyToolboxDeleting")}}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:424}],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:424}],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");return a.setAttribute("text",r),a.setAttribute("callbackKey","CREATE_FUNCTION"),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 t=0;t<e.length;t++){let r=e[t][0],o=(e[t][1],i.utils.xml.createElement("block"));o.setAttribute("type","procedures_callnoreturn"),o.setAttribute("gap","16"),o.setAttribute("colour",pxt.toolbox.getNamespaceColor("functions"));let s=i.utils.xml.createElement("field");s.textContent=r,s.setAttribute("name","NAME"),o.appendChild(s),n.push(o)}}(i.Procedures.allProcedures(e)[0]),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=pxt.blocks.getBlockDefinition("procedures_defnoreturn");e.PROCEDURES_DEFNORETURN_TITLE=t.block.PROCEDURES_DEFNORETURN_TITLE,e.PROCEDURE_ALREADY_EXISTS=t.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)("procedures_defnoreturn");const n=pxt.blocks.getBlockDefinition("procedures_callnoreturn");e.PROCEDURES_CALLRETURN_TOOLTIP=t.tooltip.toString(),i.Blocks.procedures_callnoreturn={init:function(){let e=new a.FieldProcedure("");this.appendDummyInput("TOPROW").appendField(n.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)("procedures_callnoreturn");const s=pxt.blocks.getBlockDefinition("function_definition");e.FUNCTIONS_EDIT_OPTION=s.block.FUNCTIONS_EDIT_OPTION,(0,r.installBuiltinHelpInfo)("function_definition");const h=pxt.blocks.getBlockDefinition("function_call");e.FUNCTIONS_CALL_TITLE=h.block.FUNCTIONS_CALL_TITLE,e.FUNCTIONS_GO_TO_DEFINITION_OPTION=h.block.FUNCTIONS_GO_TO_DEFINITION_OPTION,(0,r.installBuiltinHelpInfo)("function_call"),(0,r.installBuiltinHelpInfo)("function_call_output"),i.Blocks.function_return={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)||d(r,e.REMOVE_IMAGE_DATAURI,lf("Remove return value")),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(n,e.ADD_IMAGE_DATAURI,lf("Add return value"))}e.setInputsInline(!0)}function l(){return i.Xml.domToText(e.mutationToDom())}function c(t,n){t!==n&&i.Events.fire(new i.Events.BlockChange(e,"mutation",null,t,n))}function d(t,n,i){e.appendDummyInput(t).appendField(new u.FieldImageNoText(n,24,24,i,(()=>{const e=l();s=!s;const t=l();c(e,t),a(),c(t,l())}),!1))}a(),e.domToMutation=e=>{e.hasAttribute("last_connected_id")&&(o=e.getAttribute("last_connected_id")),s=function(e){return"true"!==e.getAttribute("no_return_value")}(e),a()},e.mutationToDom=()=>{const t=document.createElement("mutation");return function(e,t){e.setAttribute("no_return_value",t?"false":"true")}(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("function_return"===n.type||null!=n.previousConnection)return;"function_definition"!==n.type&&(i.Events.setGroup(e.group),t.previousConnection.disconnect(),i.Events.setGroup(!1))}}},(0,r.installBuiltinHelpInfo)("function_return"),i.Procedures.flyoutCategory=d;const p={number:pxt.blocks.defaultIconForArgType("number"),boolean:pxt.blocks.defaultIconForArgType("boolean"),string:pxt.blocks.defaultIconForArgType("string"),Array:pxt.blocks.defaultIconForArgType("Array")},f={},g=pxt.appTarget.runtime&&pxt.appTarget.runtime.functionsOptions;g&&g.extraFunctionEditorTypes&&g.extraFunctionEditorTypes.forEach((e=>{p[e.typeName]=e.icon||pxt.blocks.defaultIconForArgType(),e.defaultName&&(f[e.typeName]=e.defaultName)}));for(const e of Object.keys(p))o.FunctionManager.getInstance().setIconForType(e,p[e]);for(const e of Object.keys(f))o.FunctionManager.getInstance().setArgumentNameForType(e,f[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 m=i.Blocks.function_definition.makeCallOption;i.Blocks.function_definition.makeCallOption=function(){const e=m.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":111,"../toolbox":139,blockly:424}],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=pxt.blocks.getBlockDefinition("lists_create_with");e.LISTS_CREATE_EMPTY_TITLE=t.block.LISTS_CREATE_EMPTY_TITLE,e.LISTS_CREATE_WITH_INPUT_WITH=t.block.LISTS_CREATE_WITH_INPUT_WITH,e.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD=t.block.LISTS_CREATE_WITH_CONTAINER_TITLE_ADD,e.LISTS_CREATE_WITH_ITEM_TITLE=t.block.LISTS_CREATE_WITH_ITEM_TITLE,(0,r.installBuiltinHelpInfo)("lists_create_with");const n=pxt.blocks.getBlockDefinition("lists_length");e.LISTS_LENGTH_TITLE=n.block.LISTS_LENGTH_TITLE,i.Blocks.lists_length.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)("lists_length");const s=pxt.blocks.getBlockDefinition("lists_index_get");i.Blocks.lists_index_get={init:function(){this.jsonInit({message0:s.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,"lists_index_get")}};const a=pxt.blocks.getBlockDefinition("lists_index_set");i.Blocks.lists_index_set={init:function(){this.jsonInit({message0:a.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,"lists_index_set")}}}},{"../constants":18,"../help":72,blockly:424}],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=pxt.blocks.getBlockDefinition("controls_if"),n=t.tooltip;e.CONTROLS_IF_MSG_IF=t.block.CONTROLS_IF_MSG_IF,e.CONTROLS_IF_MSG_THEN=t.block.CONTROLS_IF_MSG_THEN,e.CONTROLS_IF_MSG_ELSE=t.block.CONTROLS_IF_MSG_ELSE,e.CONTROLS_IF_MSG_ELSEIF=t.block.CONTROLS_IF_MSG_ELSEIF,e.CONTROLS_IF_TOOLTIP_1=n.CONTROLS_IF_TOOLTIP_1,e.CONTROLS_IF_TOOLTIP_2=n.CONTROLS_IF_TOOLTIP_2,e.CONTROLS_IF_TOOLTIP_3=n.CONTROLS_IF_TOOLTIP_3,e.CONTROLS_IF_TOOLTIP_4=n.CONTROLS_IF_TOOLTIP_4,(0,r.installBuiltinHelpInfo)("controls_if");const o=pxt.blocks.getBlockDefinition("logic_compare").tooltip;e.LOGIC_COMPARE_TOOLTIP_EQ=o.LOGIC_COMPARE_TOOLTIP_EQ,e.LOGIC_COMPARE_TOOLTIP_NEQ=o.LOGIC_COMPARE_TOOLTIP_NEQ,e.LOGIC_COMPARE_TOOLTIP_LT=o.LOGIC_COMPARE_TOOLTIP_LT,e.LOGIC_COMPARE_TOOLTIP_LTE=o.LOGIC_COMPARE_TOOLTIP_LTE,e.LOGIC_COMPARE_TOOLTIP_GT=o.LOGIC_COMPARE_TOOLTIP_GT,e.LOGIC_COMPARE_TOOLTIP_GTE=o.LOGIC_COMPARE_TOOLTIP_GTE,(0,r.installBuiltinHelpInfo)("logic_compare");const s=pxt.blocks.getBlockDefinition("logic_operation"),a=s.tooltip;e.LOGIC_OPERATION_AND=s.block.LOGIC_OPERATION_AND,e.LOGIC_OPERATION_OR=s.block.LOGIC_OPERATION_OR,e.LOGIC_OPERATION_TOOLTIP_AND=a.LOGIC_OPERATION_TOOLTIP_AND,e.LOGIC_OPERATION_TOOLTIP_OR=a.LOGIC_OPERATION_TOOLTIP_OR,(0,r.installBuiltinHelpInfo)("logic_operation");const l=pxt.blocks.getBlockDefinition("logic_negate");e.LOGIC_NEGATE_TITLE=l.block.LOGIC_NEGATE_TITLE,(0,r.installBuiltinHelpInfo)("logic_negate");const c=pxt.blocks.getBlockDefinition("logic_boolean");e.LOGIC_BOOLEAN_TRUE=c.block.LOGIC_BOOLEAN_TRUE,e.LOGIC_BOOLEAN_FALSE=c.block.LOGIC_BOOLEAN_FALSE,(0,r.installBuiltinHelpInfo)("logic_boolean")}},{"../help":72,blockly:424}],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=pxt.blocks.getBlockDefinition("controls_repeat_ext");e.CONTROLS_REPEAT_TITLE=t.block.CONTROLS_REPEAT_TITLE,e.CONTROLS_REPEAT_INPUT_DO=t.block.CONTROLS_REPEAT_INPUT_DO,(0,r.installBuiltinHelpInfo)("controls_repeat_ext");const n=pxt.blocks.getBlockDefinition("device_while");i.Blocks.device_while={init:function(){this.jsonInit({message0:n.block.message0,args0:[{type:"input_value",name:"COND",check:"Boolean"}],previousStatement:null,nextStatement:null,colour:pxt.toolbox.getNamespaceColor("loops")}),this.appendStatementInput("DO").appendField(n.block.appendField),(0,r.setBuiltinHelpInfo)(this,"device_while")}};const s=pxt.blocks.getBlockDefinition("pxt_controls_for");i.Blocks.pxt_controls_for={init:function(){this.jsonInit({message0:s.block.message0,args0:[{type:"input_value",name:"VAR",variable:s.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(s.block.appendField);let e=this;(0,r.setHelpResources)(this,"pxt_controls_for",s.name,(function(){return pxt.U.rlf(s.tooltip,e.getInputTargetBlock("VAR")?e.getInputTargetBlock("VAR").getField("VAR").getText():"")}),s.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)("pxt_controls_for","VAR");const a=pxt.blocks.getBlockDefinition("controls_simple_for");i.Blocks.controls_simple_for={init:function(){this.jsonInit({message0:a.block.message0,args0:[{type:"field_variable",name:"VAR",variable:a.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(a.block.appendField);let e=this;(0,r.setHelpResources)(this,"controls_simple_for",a.name,(function(){return pxt.U.rlf(a.tooltip,e.getField("VAR").getText())}),a.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 l=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:l.block.message0,inputsInline:!0,previousStatement:null,nextStatement:null,colour:e}),(0,r.setHelpResources)(this,ts.pxtc.TS_BREAK_TYPE,l.name,l.tooltip,l.url,e,void 0,void 0,!1)}};const c=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:c.block.message0,inputsInline:!0,previousStatement:null,nextStatement:null,colour:e}),(0,r.setHelpResources)(this,ts.pxtc.TS_CONTINUE_TYPE,c.name,c.tooltip,c.url,e,void 0,void 0,!1)}},i.Blocks[pxtc.COLLAPSED_BLOCK]={init:function(){this.jsonInit({message0:"...",inputsInline:!0,previousStatement:null,nextStatement:null,colour:"#cccccc"}),(0,r.setHelpResources)(this,ts.pxtc.COLLAPSED_BLOCK,"...",lf("a few blocks"),void 0,"#cccccc",void 0,void 0,!1)}};const u=pxt.blocks.getBlockDefinition("pxt_controls_for_of");i.Blocks.pxt_controls_for_of={init:function(){this.jsonInit({message0:u.block.message0,args0:[{type:"input_value",name:"VAR",variable:u.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(u.block.appendField);let e=this;(0,r.setHelpResources)(this,"pxt_controls_for_of",u.name,(function(){return pxt.Util.rlf(u.tooltip,e.getInputTargetBlock("VAR")?e.getInputTargetBlock("VAR").getField("VAR").getText():"")}),u.url,String(pxt.toolbox.getNamespaceColor("loops")))}},(0,o.setDuplicateOnDrag)("pxt_controls_for_of","VAR");const d=pxt.blocks.getBlockDefinition("controls_for_of");i.Blocks.controls_for_of={init:function(){this.jsonInit({message0:d.block.message0,args0:[{type:"field_variable",name:"VAR",variable:d.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(d.block.appendField);let e=this;(0,r.setHelpResources)(this,"controls_for_of",d.name,(function(){return pxt.Util.rlf(d.tooltip,e.getField("VAR").getText())}),d.url,String(pxt.toolbox.getNamespaceColor("loops")))}}}},{"../help":72,"../plugins/duplicateOnDrag":91,blockly:424}],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=pxt.blocks.getBlockDefinition("math_js_op");function n(e,t){const n=e.appendValueInput("ARG"+(t?1:0));n.setCheck("Number"),t&&(n.connection.setShadowDom(function(){if(!c){(c=document.createElement("shadow")).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 l(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.math_js_op={init:function(){const i=this;i.setPreviousStatement(!1),i.setNextStatement(!1),i.setOutput(!0,"Number"),i.setOutputShape(o.provider.SHAPES.ROUND),i.setInputsInline(!0),i.appendDummyInput("op_dropdown").appendField(new a.FieldDropdown(e.map((e=>[t.block[e],e])),(e=>function(e,t){return!function(e){return-1!==pxt.blocks.MATH_FUNCTIONS.unary.indexOf(e)}(t)?e.getInput("ARG1")||n(e,!0):e.removeInput("ARG1",!0),l(e,function(e){return-1!==pxt.blocks.MATH_FUNCTIONS.infix.indexOf(e)}(t)),t}(i,e))),"OP"),n(i,!1),(0,s.appendMutation)(i,{mutationToDom:e=>{let t;for(let e=0;e<i.inputList.length;e++){const n=i.inputList[e];if("op_dropdown"===n.name){t=!1;break}if("ARG0"===n.name){t=!0;break}}return e.setAttribute("op-type",(i.getInput("ARG1")?t?"infix":"binary":"unary").toString()),e},domToMutation:e=>{if(e.hasAttribute("op-type")){const t=e.getAttribute("op-type");"unary"!=t&&n(i,!0),l(i,"infix"===t)}}})}},(0,r.installHelpResources)("math_js_op",t.name,(function(e){return t.tooltip[e.getFieldValue("OP")]}),t.url,pxt.toolbox.getNamespaceColor(t.category))}let c;function u(){const e=pxt.blocks.ROUNDING_FUNCTIONS,t=pxt.blocks.getBlockDefinition("math_js_round");i.Blocks.math_js_round={init:function(){const n=this;n.setPreviousStatement(!1),n.setNextStatement(!1),n.setOutput(!0,"Number"),n.setOutputShape(o.provider.SHAPES.ROUND),n.setInputsInline(!0),n.appendDummyInput("round_dropdown").appendField(new a.FieldDropdown(e.map((e=>[t.block[e],e]))),"OP"),function(e){e.appendValueInput("ARG0").setCheck("Number")}(n)}},(0,r.installHelpResources)("math_js_round",t.name,(function(e){return t.tooltip[e.getFieldValue("OP")]}),t.url,pxt.toolbox.getNamespaceColor(t.category))}n.initMath=function(e){const t=pxt.blocks.getBlockDefinition("math_op2"),n=t.tooltip;i.Blocks.math_op2={init:function(){this.jsonInit({message0:lf("%1 of %2 and %3"),args0:[{type:"field_dropdown",name:"op",options:[[lf("{id:op}min"),"min"],[lf("{id:op}max"),"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,"math_op2",t.name,(function(e){return n[e.getFieldValue("op")]}),t.url,pxt.toolbox.getNamespaceColor(t.category))},codeCard:(0,r.attachCardInfo)(e,"Math.min")};const s=pxt.blocks.getBlockDefinition("math_op3");i.Blocks.math_op3={init:function(){this.jsonInit({message0:s.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,"math_op3")},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 a=i.Msg,c=pxt.blocks.getBlockDefinition("math_arithmetic"),d=c.tooltip;a.MATH_ADDITION_SYMBOL=c.block.MATH_ADDITION_SYMBOL,a.MATH_SUBTRACTION_SYMBOL=c.block.MATH_SUBTRACTION_SYMBOL,a.MATH_MULTIPLICATION_SYMBOL=c.block.MATH_MULTIPLICATION_SYMBOL,a.MATH_DIVISION_SYMBOL=c.block.MATH_DIVISION_SYMBOL,a.MATH_POWER_SYMBOL=c.block.MATH_POWER_SYMBOL,(0,r.installHelpResources)("math_arithmetic",c.name,(function(e){return d[e.getFieldValue("OP")]}),c.url,pxt.toolbox.getNamespaceColor(c.category));const h=pxt.blocks.getBlockDefinition("math_modulo");a.MATH_MODULO_TITLE=h.block.MATH_MODULO_TITLE,(0,r.installBuiltinHelpInfo)("math_modulo"),l(),u()},n.initMathOpBlock=l,n.initMathRoundBlock=u},{"../composableMutations":17,"../constants":18,"../fields/field_dropdown":34,"../help":72,blockly:424}],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:424}],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=pxt.blocks.getBlockDefinition("text_length");i.Msg.TEXT_LENGTH_TITLE=t.block.TEXT_LENGTH_TITLE,i.Blocks.text_length.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)("text_length");const n=pxt.blocks.getBlockDefinition("text_join");i.Msg.TEXT_JOIN_TITLE_CREATEWITH=n.block.TEXT_JOIN_TITLE_CREATEWITH,(0,r.installBuiltinHelpInfo)("text_join")}},{"../constants":18,"../help":72,blockly:424}],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.concat(a)}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=pxt.blocks.getBlockDefinition("variables_get");t.VARIABLES_GET_CREATE_SET=n.block.VARIABLES_GET_CREATE_SET,i.Blocks.variables_get={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,"variables_get")}},(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 a=pxt.blocks.getBlockDefinition("variables_set");t.VARIABLES_SET=a.block.VARIABLES_SET,t.VARIABLES_DEFAULT_NAME=e,t.VARIABLES_SET_CREATE_GET=lf("Create 'get %1'"),i.Blocks.variables_set={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,"variables_set")}};const l=pxt.blocks.getBlockDefinition("variables_change");i.Blocks.variables_change={init:function(){this.jsonInit({message0:l.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,"variables_change")},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":139,blockly:424}],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");e.time&&o(t,"date","span").appendChild(document.createTextNode(pxt.Util.timeSince(e.time)))}return e.extracontent&&o(s,"extra content","div").appendChild(document.createTextNode(e.extracontent)),s}},{"./render":137}],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){return t.type==ts.pxtc.ON_START_TYPE?JSON.stringify({name:ts.pxtc.ON_START_TYPE}):t.type==ts.pxtc.FUNCTION_DEFINITION_TYPE?JSON.stringify({type:"function",name:t.getFieldValue("function_name")}):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 (")).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,n){const i=(0,s.escapeVarName)(t.getFieldValue("NAME"),e,!0),r=(0,s.getInputTargetBlock)(e,t,"STACK");return[pxt.blocks.mkText("function "+i+"() "),y(e,r)]}(e,t);break;case"function_definition":n=function(e,t,n){const i=(0,s.escapeVarName)(t.getField("function_name").getText(),e,!0),r=(0,s.getInputTargetBlock)(e,t,"STACK"),a=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}`})),l=(0,o.isFunctionRecursive)(e,t,!1);return[pxt.blocks.mkText(`function ${i} (${a.join(", ")})${l?": any":""}`),y(e,r)]}(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=y(e,(0,s.getInputTargetBlock)(e,t,"HANDLER"));return pxt.appTarget.compile&&pxt.appTarget.compile.onStartText&&n&&n.children&&n.children.unshift(pxt.blocks.mkStmt(pxt.blocks.mkText(`// ${pxtc.ON_START_COMMENT}\n`))),n}(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){return"1"==t.getFieldValue("ON_OFF")?[pxt.blocks.mkText("debugger;\n")]:[]}(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=function(e,t,n){return pxt.blocks.H.mkNumberLiteral(F(t))}(0,t);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)];(function(e){return-1!==["LT","LTE","GT","GTE","EQ","NEQ"].indexOf(e)})(i)&&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")])))));const c=(0,o.returnType)(e,r);if((0,o.isStringType)(c)){if("EQ"==i)return pxt.blocks.H.mkSimpleCall("==",l);if("NEQ"==i)return pxt.blocks.H.mkSimpleCall("!=",l)}else if((0,o.isBooleanType)(c))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,n){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);return i?(i.firstReference||(i.firstReference=t),pxt.U.assert(null!=i&&null!=i.type),pxt.blocks.mkText(i.escapedName)):pxt.blocks.mkText(n)}(e,t);break;case"text":i=function(e,t,n){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])}return i||pxt.blocks.H.mkStringLiteral("")}(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=b(e,(0,s.getInputTargetBlock)(e,t,"LIST"),n),r=b(e,(0,s.getInputTargetBlock)(e,t,"INDEX"),n);return pxt.blocks.mkGroup([i,pxt.blocks.mkText("["),r,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)];return t.getInput("ARG1")&&r.push(b(e,(0,s.getInputTargetBlock)(e,t,"ARG1"),n)),pxt.blocks.H.mathCall(i,r)}(e,t,n);break;case pxtc.TS_OUTPUT_TYPE:i=function(e,t,n){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,n){const i=(0,s.escapeVarName)(t.getFieldValue("VALUE"),e);return pxt.blocks.mkText(i)}(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()),l=e.idToScope[t.id].declaredVars[a.name]===a&&!a.firstReference&&!a.alreadyDeclared;l&&(0,s.forEachChildExpression)(t,(t=>{"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.escapedNa