/g,"<$1$2>$1>")},Be=function(t){t=Me(t).split("<");let e="";for(let s=1;s"!==i.slice(-2)&&(e+=" ")}return(t=(t=t.join("\n")).replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,"$1$2>")).replace(/^\n/,"")},Pe=function(t,e){return e.setResizesEnabled(!1),e.clear(),t=Ar.domToWorkspace$$module$build$src$core$xml(t,e),e.setResizesEnabled(!0),t},Ar.domToWorkspace$$module$build$src$core$xml=function(t,e){let s=0;e.RTL&&(s=e.getWidth());const i=[];ut();const o=Ar.getGroup$$module$build$src$core$events$utils();o||Ar.setGroup$$module$build$src$core$events$utils(!0),e.setResizesEnabled&&e.setResizesEnabled(!1);let n=!0;try{for(let o,r=0;o=t.childNodes[r];r++){const t=o.nodeName.toLowerCase(),r=o;if("block"===t||"shadow"===t&&!I()){const t=He(r,e);let o;i.push(t.id);const l=parseInt(null!=(o=r.getAttribute("x"))?o:"10",10);let a;const h=parseInt(null!=(a=r.getAttribute("y"))?a:"10",10);isNaN(l)||isNaN(h)||t.moveBy(e.RTL?s-l:l,h,["create"]),n=!1}else{if("shadow"===t)throw TypeError("Shadow block cannot be a top-level block.");if("comment"===t)e.rendered?uh.fromXmlRendered(r,e,s):lh.fromXml(r,e);else if("variables"===t){if(!n)throw Error("'variables' tag must exist once before block and shadow tag elements in the workspace XML, but it was found in another location.");Ge(r,e),n=!1}}}}finally{Ar.setGroup$$module$build$src$core$events$utils(o),e.setResizesEnabled&&e.setResizesEnabled(!0),e.rendered&&ye(),dt()}return S(new(B(pl))(e)),i},Fe=function(t,e){if(!e.getBlocksBoundingBox)return Ar.domToWorkspace$$module$build$src$core$xml(t,e);var s=e.getBlocksBoundingBox();if(t=Ar.domToWorkspace$$module$build$src$core$xml(t,e),s&&s.top!==s.bottom){var i=s.bottom;s=e.RTL?s.right:s.left;var o=1/0;let n=-1/0,r=1/0;for(let s=0;sn&&(n=i.x)}for(i=i-r+10,s=e.RTL?s-n:s-o,o=0;oh.setBubbleVisible(n)),1)}},ze=function(t,e){for(let s=0;s{t.disposed||t.setConnectionTracking(!0)}),1)}return r},gs=function(t,e,{parentConnection:s,isShadow:i=!1}={}){if(!t.type)throw new Th(t);const o=e.newBlock(t.type,t.id);return o.setShadow(i),bs(o,t),_s(o,t),ms(o,t),fs(s,o,t),Es(o,t),Ts(o,t),ks(o,t),ws(o,t),$s(o,e.rendered),o},bs=function(t,e){let s=void 0===e.x?0:e.x;e=void 0===e.y?0:e.y;const i=t.workspace;s=i.RTL?i.getWidth()-s:s,t.moveBy(s,e)},_s=function(t,e){e.collapsed&&t.setCollapsed(!0),!1===e.deletable&&t.setDeletable(!1),!1===e.movable&&t.setMovable(!1),!1===e.editable&&t.setEditable(!1),!1===e.enabled&&t.setEnabled(!1),void 0!==e.inline&&t.setInputsInline(e.inline),void 0!==e.data&&(t.data=e.data)},ms=function(t,e){e.extraState&&(t.loadExtraState?t.loadExtraState(e.extraState):t.domToMutation&&t.domToMutation(Ar.textToDom$$module$build$src$core$utils$xml(e.extraState)))},fs=function(t,e,s){if(t){if(t.getSourceBlock().isShadow()&&!e.isShadow())throw new yh(s);if(t.type===Ar.inputTypes$$module$build$src$core$inputs$input_types.VALUE){var i=e.outputConnection;if(!i)throw new kh("output",e,s)}else if(!(i=e.previousConnection))throw new kh("previous",e,s);if(!t.connect(i)){const o=e.workspace.connectionChecker;throw new wh(o.getErrorMessage(o.canConnectWithReason(i,t,!1),i,t),t.type===Ar.inputTypes$$module$build$src$core$inputs$input_types.VALUE?"output connection":"previous connection",e,s)}}},Es=function(t,e){if(e.icons){var s=Object.keys(e.icons);for(const o of s){s=e.icons[o];var i=t.getIcon(o);if(!i){if(!(i=n(Mr.ICON,o,!1)))throw new $h(o,t,e);i=new i(t),t.addIcon(i)}ts(i)&&i.loadState(s)}}},Ts=function(t,e){if(e.fields){var s=Object.keys(e.fields);for(let i=0;ie.id!=t.id)).map((t=>t.getRelativeToSurfaceXY()));for(;vs(la.sum(i,o),n)||Is(t,o,s);)e.RTL?o.translate(-s,2*s):o.translate(s,2*s);t.moveTo(la.sum(i,o))},vs=function(t,e){return e.some((e=>1>=Math.abs(e.x-t.x)&&1>=Math.abs(e.y-t.y)))},Is=function(t,e,s){return t.getConnections_(!1).some((t=>!!t.closest(s,e).connection))},Ss=function(t){return et("Blockly.clipboard.copy","v11","v12","myCopyable.toCopyData()"),Gh.copyInternal(t)},Rs=function(t){const e=t.toCopyData();let s;return Fh=e,Hh=null!=(s=t.workspace)?s:null,e},Ds=function(t,e,s){return t&&e?As(t,e,s):Fh&&Hh?As(Fh,Hh):null},As=function(t,e,s){let i,o,n;return e=null!=(i=e.getRootWorkspace())?i:e,null!=(n=null==(o=r(Mr.PASTER,t.paster,!1))?void 0:o.paste(t,e,s))?n:null},Ns=function(t){return et("Blockly.clipboard.duplicate","v11","v12","Blockly.clipboard.paste(myCopyable.toCopyData(), myWorkspace)"),Gh.duplicateInternal(t)},Os=function(t){const e=t.toCopyData();return e?Ds(e,t.workspace):null},xs=function(t,e){t.setAttribute(Xh,e)},Ls=function(t,e,s){Array.isArray(s)&&(s=s.join(" ")),t.setAttribute(zh+e,`${s}`)},Ms=function(){return Kh},Bs=function(t){if(Kh=t,null===t){let t;null==(t=document.querySelector("."+Qh))||t.remove()}},Ps=function(){document.querySelector("."+Qh)||((Kh=document.createElement("div")).className=Qh,(m()||document.body).appendChild(Kh))},Fs=function(t,e,s){Hs(),Zh=t,qh=s,(t=Kh)&&(t.style.direction=e?"rtl":"ltr",t.style.display="block",e=p(),tc=e.getRenderer().getClassName(),ec=e.getTheme().getClassName(),tc&&it(t,tc),ec&&it(t,ec))},Hs=function(){if(Gs()){Zh=null;var t=Kh;t&&(t.style.display="none",t.style.left="",t.style.top="",qh&&qh(),qh=null,t.textContent="",tc&&(nt(t,tc),tc=""),ec&&(nt(t,ec),ec=""),p().markFocused())}},Gs=function(){return!!Zh},Us=function(t){Zh===t&&Hs()},Ws=function(t,e,s){Kh.style.left=t+"px",Kh.style.top=e+"px",Kh.style.height=s+"px"},Vs=function(t,e,s,i){const o=Xs(t,e,s);t=zs(t,e,s,i),0>o?Ws(t,0,s.height+o):Ws(t,o,s.height)},zs=function(t,e,s,i){return i?Math.min(Math.max(e.right-s.width,t.left),t.right-s.width):Math.max(Math.min(e.left,t.right-s.width),t.left)},Xs=function(t,e,s){return e.bottom+s.height>=t.bottom?e.top-s.height:e.bottom},Ys=function(t){return!(null==t||!t.repositionForWindowResize)},Ks=function(){Ys(Zh)&&Zh.repositionForWindowResize()||Hs()},Js=function(){return ic},js=function(t){ic=t},Zs=function(t,e,s){if(Fs(oc,s,ii),e.length){var i=qs(e,s);nc=i,Qs(i,t,s),setTimeout((function(){i.focus()}),1),ic=null}else si()},qs=function(t,e){const s=new Jh;s.setRole(Wh.MENU);for(let i=0;i{setTimeout((()=>{o.callback(o.scope)}),0)}))}),{})}return s},Qs=function(t,e,s){const i=St();e=new fa(e.clientY+i.top,e.clientY+i.top,e.clientX+i.left,e.clientX+i.left),ti(t);const o=t.getSize();s&&(e.left+=o.width,e.right+=o.width,i.left+=o.width,i.right+=o.width),Vs(i,e,o,s),t.focus()},ti=function(t){var e=Ms();if(!e)throw Error("Attempting to create a context menu when widget div is null");e=t.render(e),it(e,"blocklyContextMenu"),z(e,"contextmenu",null,ei),t.focus()},ei=function(t){t.preventDefault(),t.stopPropagation()},si=function(){Us(oc),ic=null},ii=function(){nc&&(nc.dispose(),nc=null)},Ar.callbackFactory$$module$build$src$core$contextmenu=function(t,e){return()=>{let s;Ar.disable$$module$build$src$core$events$utils();try{s=e instanceof Element?He(e,t.workspace):ps(e,t.workspace);const i=t.getRelativeToSurfaceXY();i.x=t.RTL?i.x-Ar.config$$module$build$src$core$config.snapRadius:i.x+Ar.config$$module$build$src$core$config.snapRadius,i.y+=2*Ar.config$$module$build$src$core$config.snapRadius,s.moveBy(i.x,i.y)}finally{Ar.enable$$module$build$src$core$events$utils()}return O()&&!s.isShadow()&&S(new(B(Ar.CREATE$$module$build$src$core$events$utils))(s)),s.select(),s}},oi=function(t){return{text:Ar.Msg$$module$build$src$core$msg.REMOVE_COMMENT,enabled:!0,callback:function(){Ar.setGroup$$module$build$src$core$events$utils(!0),t.dispose(),Ar.setGroup$$module$build$src$core$events$utils(!1)}}},ni=function(t){return{text:Ar.Msg$$module$build$src$core$msg.DUPLICATE_COMMENT,enabled:!0,callback:function(){const e=t.toCopyData();e&&Ds(e,t.workspace)}}},ri=function(t,e){const s={enabled:!0};return s.text=Ar.Msg$$module$build$src$core$msg.ADD_COMMENT,s.callback=function(){const s=new uh(t,Ar.Msg$$module$build$src$core$msg.WORKSPACE_COMMENT_DEFAULT_TEXT,uh.DEFAULT_SIZE,uh.DEFAULT_SIZE);var i=t.getInjectionDiv().getBoundingClientRect();i=new la(e.clientX-i.left,e.clientY-i.top);const o=t.getOriginOffsetInPixels();(i=la.difference(i,o)).scale(1/t.scale),s.moveBy(i.x,i.y),t.rendered&&(s.initSvg(),s.render(),s.select())},s},li=function(t){return t*Math.PI/180},ai=function(t){return 180*t/Math.PI},hi=function(t,e,s){if(ss)){var i=e.getSvgXY(t.getSvgRoot());t.outputConnection?(i.x+=(t.RTL?3:-3)*s,i.y+=13*s):t.previousConnection&&(i.x+=(t.RTL?-23:23)*s,i.y+=3*s);var o=st(ma.CIRCLE,{cx:i.x,cy:i.y,r:0,fill:"none",stroke:"#888","stroke-width":10},e.getParentSvg());t=st(ma.ANIMATE,{id:"animationCircle",begin:"indefinite",attributeName:"r",dur:"150ms",from:0,to:25*s},o),e=st(ma.ANIMATE,{id:"animationOpacity",begin:"indefinite",attributeName:"opacity",dur:"150ms",from:1,to:0},o),t.beginElement(),e.beginElement(),setTimeout((()=>{lt(o)}),150)}},Li=function(t){if(Bi(),t.workspace.getAudioManager().play("disconnect"),!(1>t.workspace.scale)){var e=t.getHeightWidth().height;e=Math.atan(10/e)/Math.PI*180,t.RTL||(e*=-1),Rc=t,Mi(t,e,new Date)}},Mi=function(t,e,s){const i=((new Date).getTime()-s.getTime())/200;let o="";1>=i&&(o=`skewX(${Math.round(Math.sin(i*Math.PI*3)*(1-i)*e)})`,Sc=setTimeout(Mi,10,t,e,s)),t.getSvgRoot().setAttribute("transform",`${t.getTranslation()} ${o}`)},Bi=function(){Rc&&(Sc&&(clearTimeout(Sc),Sc=null),Rc.getSvgRoot().setAttribute("transform",Rc.getTranslation()),Rc=null)},Pi=function(t,e){return et("Blockly.utils.string.startsWith()","April 2022","April 2023","Use built-in string.startsWith"),t.startsWith(e)},Fi=function(t){return t.length?t.reduce((function(t,e){return t.lengthe&&(e=s[i].length);var o=-1/0;let n,r=1;do{i=o,n=t,t=[],o=s.length/r;let l=1;for(let e=0;ei);return n},Wi=function(t,e,s){const i=[0],o=[];for(var n=0;no&&(o=l,i=r)}return i?Vi(t,i,s):e},zi=function(t,e){const s=[];for(let i=0;ijc&&no()}else Yc!==Xc&&(clearTimeout(Wc),Vc=t.pageX,zc=t.pageY,Wc=setTimeout(uo,Zc))},oo=function(){Yc=Xc=null,no()},no=function(){Fc&&(Fc=!1,Qc&&(Qc.style.display="none")),Wc&&(clearTimeout(Wc),Wc=0)},ro=function(){no(),Hc=!0},lo=function(){Hc=!1},ao=function(){Qc&&Xc&&("function"==typeof Pc?Pc(Qc,Xc):ho())},ho=function(){var t=ji(Xc);t=(t=Ar.wrap$$module$build$src$core$utils$string(t,Gc)).split("\n");for(let e=0;es+window.scrollY&&(o-=Qc.offsetHeight+2*Jc),t?i=Math.max(qc-window.scrollX,i):i+Qc.offsetWidth>e+window.scrollX-2*qc&&(i=e-Qc.offsetWidth-2*qc),{x:i,y:o}},uo=function(){if(!Hc&&(Yc=Xc,Qc)){Qc.textContent="",ao();var t=Xc.RTL;Qc.style.direction=t?"rtl":"ltr",Qc.style.display="block",Fc=!0;var{x:e,y:s}=co(t);Qc.style.left=e+"px",Qc.style.top=s+"px"}},po=function(t,e){for(const s in e)t[s]=null!==e[s]&&"object"==typeof e[s]?po(t[s]||Object.create(null),e[s]):e[s];return t},go=function(t){return void 0!==t.bubbleIsVisible&&void 0!==t.setBubbleVisible},bo=function(){return cu},_o=function(t){cu=t},mo=function(){return uu},fo=function(t){uu=t},Eo=function(t){t=`${t}`.toLowerCase().trim();var e=du[t];if(e)return e;if(e="#"===(e="0x"===t.substring(0,2)?"#"+t.substring(2):t)[0]?e:"#"+e,/^#[0-9a-f]{6}$/.test(e))return e;if(/^#[0-9a-f]{3}$/.test(e))return["#",e[1],e[1],e[2],e[2],e[3],e[3]].join("");var s=t.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return s&&(t=Number(s[1]),e=Number(s[2]),s=Number(s[3]),0<=t&&256>t&&0<=e&&256>e&&0<=s&&256>s)?To(t,e,s):null},To=function(t,e,s){return e=t<<16|e<<8|s,16>t?"#"+(16777216|e).toString(16).substr(1):"#"+e.toString(16)},ko=function(t){return(t=Eo(t))?[(t=parseInt(t.substr(1),16))>>16,t>>8&255,255&t]:[0,0,0]},wo=function(t,e,s){let i=0,o=0,n=0;if(0===e)n=o=i=s;else{const r=Math.floor(t/60),l=t/60-r;t=s*(1-e);const a=s*(1-e*l);switch(e=s*(1-e*(1-l)),r){case 1:i=a,o=s,n=t;break;case 2:i=t,o=s,n=e;break;case 3:i=t,o=a,n=s;break;case 4:i=e,o=t,n=s;break;case 5:i=s,o=t,n=a;break;case 6:case 0:i=s,o=e,n=t}}return To(Math.floor(i),Math.floor(o),Math.floor(n))},yo=function(t,e,s){return(t=Eo(t))&&(e=Eo(e))?(t=ko(t),e=ko(e),To(Math.round(e[0]+s*(t[0]-e[0])),Math.round(e[1]+s*(t[1]-e[1])),Math.round(e[2]+s*(t[2]-e[2])))):null},$o=function(t){return wo(t,cu,255*uu)},Co=function(t,e,s){const i=[];var o=t.split("");o.push("");var n=0;t=[];let r=null;for(let h=0;h=l?(n=2,r=l,(l=t.join(""))&&i.push(l),t.length=0):"{"===l?n=3:(t.push("%",l),n=0);else if(2===n)if("0"<=l&&"9">=l)r+=l;else{var a=void 0;i.push(parseInt(null!=(a=r)?a:"",10)),h--,n=0}else 3===n&&(""===l?(t.splice(0,0,"%{"),h--,n=0):"}"!==l?t.push(l):(n=t.join(""),/[A-Z]\w*/i.test(n)?(l=(l=n.toUpperCase()).startsWith("BKY_")?l.substring(4):null)&&l in Ar.Msg$$module$build$src$core$msg?"string"==typeof(n=Ar.Msg$$module$build$src$core$msg[l])?Array.prototype.push.apply(i,Co(n,e,s)):e?i.push(`${n}`):i.push(n):i.push("%{"+n+"}"):i.push("%{"+n+"}"),n=t.length=0))}for((e=t.join(""))&&i.push(e),a=[],t.length=0,o=0;o=s)return{hue:s,hex:wo(s,bo(),255*mo())};if(s=Eo(e))return{hue:null,hex:s};throw s='Invalid colour: "'+e+'"',t!==e&&(s+=' (from "'+t+'")'),Error(s)},Do=function(t){return void 0!==t.getProcedureModel&&void 0!==t.doProcedureUpdate&&void 0!==t.isProcedureDef},Ao=function(t){return void 0!==t.startPublishing&&void 0!==t.stopPublishing},No=function(e,s){t(Mr.FIELD,e,s)},Oo=function(t){s(Mr.FIELD,t)},Ar.fromJson$$module$build$src$core$field_registry=function(t){return Tu.fromJsonInternal(t)},xo=function(t){const e=r(Mr.FIELD,t.type);if(e){if("function"!=typeof e.fromJson)throw new TypeError("returned Field was not a IRegistrableField");return e.fromJson(t)}return console.warn("Blockly could not create a field of type "+t.type+". The field is probably not being registered. This could be because the file is not loaded, the field does not register itself (Issue #1584), or the registration is not being reached."),null},Lo=function(t){let e=!1;const s=t.map((([t,s])=>"string"==typeof t?[Io(t),s]:(e=!0,[null!==t.alt?Object.assign({},t,{alt:Io(t.alt)}):Object.assign({},t),s])));if(e||2>t.length)return{options:s};var i=s.map((([t])=>t)),o=Fi(i);t=Hi(i,o);const n=Gi(i,o);return!t&&!n||o<=t+n?{options:s}:(o=t?i[0].substring(0,t-1):void 0,i=n?i[0].substr(1-n):void 0,{options:Mo(s,t,n),prefix:o,suffix:i})},Mo=function(t,e,s){return t.map((([t,i])=>[t.substring(e,t.length-s),i]))},Bo=function(t){if(!Array.isArray(t))throw TypeError("FieldDropdown options must be an array.");if(!t.length)throw TypeError("FieldDropdown options must not be an empty array.");let e=!1;for(let s=0;s!t.getReturnTypes())).map((t=>[t.getName(),t.getParameters().map((t=>t.getName())),!1]));t.getBlocksByType("procedures_defnoreturn",!1).forEach((t=>{!Do(t)&&se(t)&&e.push(t.getProcedureDef())}));const s=t.getProcedureMap().getProcedures().filter((t=>!!t.getReturnTypes())).map((t=>[t.getName(),t.getParameters().map((t=>t.getName())),!0]));return t.getBlocksByType("procedures_defreturn",!1).forEach((t=>{!Do(t)&&se(t)&&s.push(t.getProcedureDef())})),e.sort(cn),s.sort(cn),[e,s]},cn=function(t,e){return t[0].localeCompare(e[0],void 0,{sensitivity:"base"})},Ar.findLegalName$$module$build$src$core$procedures=function(t,e){if(e.isInFlyout)return t;for(t=t||Ar.Msg$$module$build$src$core$msg.UNNAMED_KEY||"unnamed";!un(t,e.workspace,e);){const e=t.match(/^(.*?)(\d+)$/);t=e?e[1]+(parseInt(e[2])+1):t+"2"}return t},un=function(t,e,s){return!dn(t,e,s)},dn=function(t,e,s){for(const i of e.getAllBlocks(!1))if(i!==s&&se(i)&&Ar.Names$$module$build$src$core$names.equals(i.getProcedureDef()[0],t))return!0;s=s&&Do(s)?null==s?void 0:s.getProcedureModel():void 0;for(const i of e.getProcedureMap().getProcedures())if(i!==s&&Ar.Names$$module$build$src$core$names.equals(i.getName(),t))return!0;return!1},Ar.rename$$module$build$src$core$procedures=function(t){var e=this.getSourceBlock();if(!e)throw new _u;t=t.trim();const s=Ar.findLegalName$$module$build$src$core$procedures(t,e);Do(e)&&!e.isInsertionMarker()&&e.getProcedureModel().setName(s);const i=this.getValue();if(i!==t&&i!==s)for(t=e.workspace.getAllBlocks(!1),e=0;efn(e,t)||ie(e)&&Ar.Names$$module$build$src$core$names.equals(e.getProcedureCall(),t)))},fn=function(t,e){return Do(t)&&!t.isProcedureDef()&&t.getProcedureModel()&&Ar.Names$$module$build$src$core$names.equals(t.getProcedureModel().getName(),e)},Ar.mutateCallers$$module$build$src$core$procedures=function(t){const e=I();var s=t.getProcedureDef()[0];const i=t.mutationToDom(!0);t=mn(s,t.workspace);for(let n,r=0;n=t[r];r++){s=(s=n.mutationToDom())&&Ot(s),n.domToMutation&&n.domToMutation(i);var o=n.mutationToDom();s!==(o=o&&Ot(o))&&(v(!1),S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(n,"mutation",null,s,o)),v(e))}},Ar.getDefinition$$module$build$src$core$procedures=function(t,e){for(const s of e.getAllBlocks(!1))if(Do(s)&&s.isProcedureDef()&&Ar.Names$$module$build$src$core$names.equals(s.getProcedureModel().getName(),t)||se(s)&&Ar.Names$$module$build$src$core$names.equals(s.getProcedureDef()[0],t))return s;return null},En=function(t){return t.isDynamic},Tn=function(t){let e=t.outputConnection;return(!e||t.previousConnection&&t.previousConnection.isConnected())&&(e=t.previousConnection),e},kn=function(t,e){if(!t||!e)throw Error("Cannot connect null connections.");t.targetConnection=e,e.targetConnection=t},wn=function(t,e){let s=null;const i=null==(e=e.outputConnection)?void 0:e.getConnectionChecker();for(let o,n=0;o=t.inputList[n];n++){const t=o.connection;let n;if(t&&null!=(n=i)&&n.canConnect(e,t,!1)){if(s)return null;s=t}}return s},yn=function(t,e){let s;for(;s=wn(t,e);)if(!(t=s.targetBlock())||t.isShadow())return s;return null},$n=function(e,s){t(Mr.RENDERER,e,s)},Cn=function(t){s(Mr.RENDERER,t)},vn=function(t,e,s){return(t=new(n(Mr.RENDERER,t))(t)).init(e,s),t},In=function(t){he(t.getTargetWorkspace(),void 0,"String")},Sn=function(t){he(t.getTargetWorkspace(),void 0,"Number")},Rn=function(t){he(t.getTargetWorkspace(),void 0,"Colour")},Dn=function(t){let e=[],s=document.createElement("button");return s.setAttribute("text",Ar.Msg$$module$build$src$core$msg.NEW_STRING_VARIABLE),s.setAttribute("callbackKey","CREATE_VARIABLE_STRING"),e.push(s),s=document.createElement("button"),s.setAttribute("text",Ar.Msg$$module$build$src$core$msg.NEW_NUMBER_VARIABLE),s.setAttribute("callbackKey","CREATE_VARIABLE_NUMBER"),e.push(s),s=document.createElement("button"),s.setAttribute("text",Ar.Msg$$module$build$src$core$msg.NEW_COLOUR_VARIABLE),s.setAttribute("callbackKey","CREATE_VARIABLE_COLOUR"),e.push(s),t.registerButtonCallback("CREATE_VARIABLE_STRING",In),t.registerButtonCallback("CREATE_VARIABLE_NUMBER",Sn),t.registerButtonCallback("CREATE_VARIABLE_COLOUR",Rn),t=An(t),e.concat(t)},An=function(t){const e=[];if(0<(t=t.getAllVariables()).length){if(Hr.variables_set_dynamic){var s=t[t.length-1];const i=Ar.createElement$$module$build$src$core$utils$xml("block");i.setAttribute("type","variables_set_dynamic"),i.setAttribute("gap","24"),i.appendChild(_e(s)),e.push(i)}if(Hr.variables_get_dynamic){t.sort(sh.compareByName);for(let i,o=0;i=t[o];o++)(s=Ar.createElement$$module$build$src$core$utils$xml("block")).setAttribute("type","variables_get_dynamic"),s.setAttribute("gap","8"),s.appendChild(_e(i)),e.push(s)}}return e},Nn=function(t){t.resizeContents()},On=function(t){return void 0!==t.toCopyData},xn=function(){Tp.registry.register({name:kp.ESCAPE,preconditionFn:t=>!t.options.readOnly,callback:t=>(t.hideChaff(),!0),keyCodes:[Ru.ESC]})},Ln=function(){Tp.registry.register({name:kp.DELETE,preconditionFn(t){const e=b();return!t.options.readOnly&&null!=e&&e.isDeletable()},callback:(t,e)=>(e.preventDefault(),!su.inProgress()&&(b().checkAndDelete(),!0)),keyCodes:[Ru.DELETE,Ru.BACKSPACE]})},Mn=function(){const t=Tp.registry.createSerializedKey(Ru.C,[Ru.CTRL]),e=Tp.registry.createSerializedKey(Ru.C,[Ru.ALT]),s=Tp.registry.createSerializedKey(Ru.C,[Ru.META]);Tp.registry.register({name:kp.COPY,preconditionFn(t){const e=b();return!t.options.readOnly&&!su.inProgress()&&null!=e&&e.isDeletable()&&e.isMovable()&&On(e)},callback:(t,e)=>(e.preventDefault(),t.hideChaff(),!(!(e=b())||!On(e))&&(wp=e.toCopyData(),yp=t,!!wp)),keyCodes:[t,e,s]})},Bn=function(){const t=Tp.registry.createSerializedKey(Ru.X,[Ru.CTRL]),e=Tp.registry.createSerializedKey(Ru.X,[Ru.ALT]),s=Tp.registry.createSerializedKey(Ru.X,[Ru.META]);Tp.registry.register({name:kp.CUT,preconditionFn(t){const e=b();return!t.options.readOnly&&!su.inProgress()&&null!=e&&e instanceof sp&&e.isDeletable()&&e.isMovable()&&!e.workspace.isFlyout},callback(t){const e=b();return!(!e||!On(e))&&(wp=e.toCopyData(),yp=t,e.checkAndDelete(),!0)},keyCodes:[t,e,s]})},Pn=function(){const t=Tp.registry.createSerializedKey(Ru.V,[Ru.CTRL]),e=Tp.registry.createSerializedKey(Ru.V,[Ru.ALT]),s=Tp.registry.createSerializedKey(Ru.V,[Ru.META]);Tp.registry.register({name:kp.PASTE,preconditionFn:t=>!t.options.readOnly&&!su.inProgress(),callback:()=>!(!wp||!yp)&&!!Ds(wp,yp),keyCodes:[t,e,s]})},Fn=function(){const t=Tp.registry.createSerializedKey(Ru.Z,[Ru.CTRL]),e=Tp.registry.createSerializedKey(Ru.Z,[Ru.ALT]),s=Tp.registry.createSerializedKey(Ru.Z,[Ru.META]);Tp.registry.register({name:kp.UNDO,preconditionFn:t=>!t.options.readOnly&&!su.inProgress(),callback:t=>(t.hideChaff(),t.undo(!1),!0),keyCodes:[t,e,s]})},Hn=function(){const t=Tp.registry.createSerializedKey(Ru.Z,[Ru.SHIFT,Ru.CTRL]),e=Tp.registry.createSerializedKey(Ru.Z,[Ru.SHIFT,Ru.ALT]),s=Tp.registry.createSerializedKey(Ru.Z,[Ru.SHIFT,Ru.META]),i=Tp.registry.createSerializedKey(Ru.Y,[Ru.CTRL]);Tp.registry.register({name:kp.REDO,preconditionFn:t=>!su.inProgress()&&!t.options.readOnly,callback:t=>(t.hideChaff(),t.undo(!0),!0),keyCodes:[t,e,s,i]})},Gn=function(){xn(),Ln(),Mn(),Bn(),Pn(),Fn(),Hn()},Un=function(t){const e={id:t.getId(),name:t.getName(),returnTypes:t.getReturnTypes()};return t.getParameters().length?(e.parameters=t.getParameters().map((t=>Wn(t))),e):e},Wn=function(t){const e={id:t.getId(),name:t.getName()};return t.getTypes().length?(e.types=t.getTypes(),e):e},Vn=function(t,e,s,i){if(t=new t(i,s.name,s.id).setReturnTypes(s.returnTypes),!s.parameters)return t;for(const[o,n]of s.parameters.entries())t.insertParameter(zn(e,n,i),o);return t},zn=function(t,e,s){return t=new t(s,e.name,e.id),e.types&&t.setTypes(e.types),t},Xn=function(t){const e=Object.create(null),s=l(Mr.SERIALIZER,!0);for(const i in s){let o;const n=null==(o=s[i])?void 0:o.save(t);n&&(e[i]=n)}return e},Yn=function(t,e,{recordUndo:s=!1}={}){var i=l(Mr.SERIALIZER,!0);if(i){i=Object.entries(i).sort(((t,e)=>e[1].priority-t[1].priority));var o=I();v(s),(s=Ar.getGroup$$module$build$src$core$events$utils())||Ar.setGroup$$module$build$src$core$events$utils(!0),ut(),e instanceof Vd&&e.setResizesEnabled(!1);for(const[,t]of i.reverse()){let s;null==(s=t)||s.clear(e)}for(let[s,o]of i.reverse())if(t[s]){let i;null==(i=o)||i.load(t[s],e)}e instanceof Vd&&e.setResizesEnabled(!0),dt(),S(new(B(pl))(e)),Ar.setGroup$$module$build$src$core$events$utils(s),v(o)}},Kn=function(t,e,s){const i=s.getBoundingRectangle(),o=i.right-i.left,n=hi(e.top,i.top,e.top+e.height-(i.bottom-i.top))-i.top;let r=e.left;return e=e.left+e.width-o,t.RTL?r=Math.min(e,r):e=Math.max(r,e),!(!(t=hi(r,i.left,e)-i.left)&&!n)&&(s.moveBy(t,n,["inbounds"]),!0)},Jn=function(t){return e=>{var s,i=t.getMetricsManager();if(i.hasFixedEdges()&&!t.isDragging())if(-1!==gl.indexOf(null!=(s=e.type)?s:"")){s=i.getScrollMetrics(!0);const o=jn(t,e);o&&(i=Ar.getGroup$$module$build$src$core$events$utils()||!1,Ar.setGroup$$module$build$src$core$events$utils(e.group),Kn(t,s,o)&&!e.group&&console.warn("Moved object in bounds but there was no event group. This may break undo."),Ar.setGroup$$module$build$src$core$events$utils(i))}else e.type===al&&e.scale&&e.oldScale&&e.scale>e.oldScale&&Zn(t)}},jn=function(t,e){let s=null;switch(e.type){case Ar.CREATE$$module$build$src$core$events$utils:case Ar.MOVE$$module$build$src$core$events$utils:(s=t.getBlockById(e.blockId))&&(s=s.getRootBlock());break;case hl:case dl:s=t.getCommentById(e.commentId)}return s},Zn=function(t){var e=t.getMetricsManager();if(e.hasFixedEdges()&&!t.isDragging()){e=e.getScrollMetrics(!0);var s=t.getTopBoundedElements();for(let i,o=0;i=s[o];o++)Kn(t,e,i)}},qn=function(t,e){const s=[];for(const i of t.getIcons())go(i)&&!i.bubbleIsVisible()||(s.push({location:e,icon:i}),i.onLocationChange(e));for(const i of t.getChildren(!1))s.push(...qn(i,la.sum(e,i.relativeCoords)));return s},Qn=function(){lc.registry.register({displayText:()=>Ar.Msg$$module$build$src$core$msg.UNDO,preconditionFn:t=>0Ar.Msg$$module$build$src$core$msg.REDO,preconditionFn:t=>0Ar.Msg$$module$build$src$core$msg.CLEAN_UP,preconditionFn:t=>t.workspace.isMovable()?1Ar.Msg$$module$build$src$core$msg.COLLAPSE_ALL,preconditionFn(t){if(t.workspace.options.collapse){t=t.workspace.getTopBlocks(!1);for(let e=0;eAr.Msg$$module$build$src$core$msg.EXPAND_ALL,preconditionFn(t){if(t.workspace.options.collapse){t=t.workspace.getTopBlocks(!1);for(let e=0;et.workspace?1===(t=rr(t.workspace).length)?Ar.Msg$$module$build$src$core$msg.DELETE_BLOCK:Ar.Msg$$module$build$src$core$msg.DELETE_X_BLOCKS.replace("%1",`${t}`):"",preconditionFn:t=>t.workspace&&0e.length?lr(e):jt(Ar.Msg$$module$build$src$core$msg.DELETE_ALL_BLOCKS.replace("%1",String(e.length)),(function(t){t&&lr(e)}))}},scopeType:lc.ScopeType.WORKSPACE,id:"workspaceDelete",weight:6})},hr=function(){Qn(),tr(),er(),ir(),or(),ar()},cr=function(){lc.registry.register({displayText:()=>Ar.Msg$$module$build$src$core$msg.DUPLICATE_BLOCK,preconditionFn:t=>!(t=t.block).isInFlyout&&t.isDeletable()&&t.isMovable()?t.isDuplicatable()?"enabled":"disabled":"hidden",callback(t){if(t.block){var e=t.block.toCopyData();e&&Ds(e,t.block.workspace)}},scopeType:lc.ScopeType.BLOCK,id:"blockDuplicate",weight:1})},ur=function(){lc.registry.register({displayText:t=>t.block.hasIcon(Mu.TYPE)?Ar.Msg$$module$build$src$core$msg.REMOVE_COMMENT:Ar.Msg$$module$build$src$core$msg.ADD_COMMENT,preconditionFn:t=>!(t=t.block).isInFlyout&&t.workspace.options.comments&&!t.isCollapsed()&&t.isEditable()?"enabled":"hidden",callback(t){(t=t.block).hasIcon(Mu.TYPE)?t.setCommentText(null):t.setCommentText("")},scopeType:lc.ScopeType.BLOCK,id:"blockComment",weight:2})},dr=function(){lc.registry.register({displayText:t=>t.block.getInputsInline()?Ar.Msg$$module$build$src$core$msg.EXTERNAL_INPUTS:Ar.Msg$$module$build$src$core$msg.INLINE_INPUTS,preconditionFn(t){if(!(t=t.block).isInFlyout&&t.isMovable()&&!t.isCollapsed())for(let e=1;et.block.isCollapsed()?Ar.Msg$$module$build$src$core$msg.EXPAND_BLOCK:Ar.Msg$$module$build$src$core$msg.COLLAPSE_BLOCK,preconditionFn:t=>!(t=t.block).isInFlyout&&t.isMovable()&&t.workspace.options.collapse?"enabled":"hidden",callback(t){t.block.setCollapsed(!t.block.isCollapsed())},scopeType:lc.ScopeType.BLOCK,id:"blockCollapseExpand",weight:4})},gr=function(){lc.registry.register({displayText:t=>t.block.isEnabled()?Ar.Msg$$module$build$src$core$msg.DISABLE_BLOCK:Ar.Msg$$module$build$src$core$msg.ENABLE_BLOCK,preconditionFn:t=>!(t=t.block).isInFlyout&&t.workspace.options.disable&&t.isEditable()?t.getInheritedDisabled()?"disabled":"enabled":"hidden",callback(t){t=t.block;const e=Ar.getGroup$$module$build$src$core$events$utils();e||Ar.setGroup$$module$build$src$core$events$utils(!0),t.setEnabled(!t.isEnabled()),Ar.setGroup$$module$build$src$core$events$utils(e)},scopeType:lc.ScopeType.BLOCK,id:"blockDisable",weight:5})},br=function(){lc.registry.register({displayText(t){var e=t.block;return t=e.getDescendants(!1).length,(e=e.getNextBlock())&&(t-=e.getDescendants(!1).length),1===t?Ar.Msg$$module$build$src$core$msg.DELETE_BLOCK:Ar.Msg$$module$build$src$core$msg.DELETE_X_BLOCKS.replace("%1",`${t}`)},preconditionFn:t=>!t.block.isInFlyout&&t.block.isDeletable()?"enabled":"hidden",callback(t){t.block&&t.block.checkAndDelete()},scopeType:lc.ScopeType.BLOCK,id:"blockDelete",weight:6})},_r=function(){lc.registry.register({displayText:()=>Ar.Msg$$module$build$src$core$msg.HELP,preconditionFn:t=>("function"==typeof(t=t.block).helpUrl?t.helpUrl():t.helpUrl)?"enabled":"hidden",callback(t){t.block.showHelp()},scopeType:lc.ScopeType.BLOCK,id:"blockHelp",weight:7})},mr=function(){cr(),ur(),dr(),pr(),gr(),br(),_r()},fr=function(){hr(),mr()},Er=function(t,e){var s=null;let i;if(s="string"==typeof t?document.getElementById(t)||document.querySelector(t):t,!document.contains(s)&&document!==(null==(i=s)?void 0:i.ownerDocument))throw Error("Error: container is not in current document");t=new au(e||{}),(e=document.createElement("div")).className="injectionDiv",e.tabIndex=0,Ls(e,Vh.LABEL,Ar.Msg$$module$build$src$core$msg.WORKSPACE_ARIA_LABEL),s.appendChild(e),s=Tr(e,t);const o=kr(e,s,t);return wr(o),g(o),E(o),e.addEventListener("focusin",(function(){g(o)})),o},Tr=function(t,e){t.setAttribute("dir","LTR"),tt(e.hasCss,e.pathToMedia),t=st(ma.SVG,{xmlns:ca,"xmlns:html":ua,"xmlns:xlink":da,version:"1.1",class:"blocklySvg",tabindex:"0"},t);const s=st(ma.DEFS,{},t),i=String(Math.random()).substring(2);return e.gridPattern=iu.createDom(i,e.gridOptions,s),t},kr=function(t,e,s){s.parentWorkspace=null;const i=(s=new Vd(s)).options;s.scale=i.zoomOptions.startScale,e.appendChild(s.createDom("blocklyMainBackground",t));var o=s.getRenderer().getClassName();return o&&it(t,o),(o=s.getTheme().getClassName())&&it(t,o),!i.hasCategories&&i.languageTree&&(t=s.addFlyout(ma.SVG),at(t,e)),i.hasTrashcan&&s.addTrashcan(),i.zoomOptions&&i.zoomOptions.controls&&s.addZoomControls(),s.getThemeManager().subscribe(e,"workspaceBackgroundColour","background-color"),s.translate(0,0),s.addChangeListener(Jn(s)),E(s),Ps(),ci(),qi(),s},wr=function(t){const e=t.options;var s=t.getParentSvg();if(z(s.parentNode,"contextmenu",null,(function(t){K(t)||t.preventDefault()})),s=z(window,"resize",null,(function(){no(),t.hideComponents(!0),Ai(),Ks(),E(t),Zn(t)})),t.setResizeHandlerWrapper(s),$r(),e.languageTree){s=t.getToolbox();const i=t.getFlyout(!0);s?s.init():i&&(i.init(t),i.show(e.languageTree),"function"==typeof i.scrollToStart&&i.scrollToStart())}e.hasTrashcan&&t.trashcan.init(),e.zoomOptions&&e.zoomOptions.controls&&t.zoomControls_.init(),e.moveOptions&&e.moveOptions.scrollbars?(t.scrollbar=new Dp(t,!0===e.moveOptions.scrollbars||!!e.moveOptions.scrollbars.horizontal,!0===e.moveOptions.scrollbars||!!e.moveOptions.scrollbars.vertical,"blocklyMainWorkspaceScrollbar"),t.scrollbar.resize()):t.setMetrics({x:.5,y:.5}),e.hasSounds&&Cr(e.pathToMedia,t)},yr=function(t){const e=p();e&&!(K(t)||e.rendered&&!e.isVisible())&&Tp.registry.onKeyDown(e,t)},$r=function(){Cg||(z(document,"scroll",null,(function(){const t=c();for(let e,s=0;e=t[s];s++)e instanceof Vd&&e.updateInverseScreenCTM()})),z(document,"keydown",null,yr),X(document,"touchend",null,H),X(document,"touchcancel",null,H),Yl&&z(window,"orientationchange",document,(function(){E(p())}))),Cg=!0},Cr=function(t,e){function s(){for(;o.length;){const t=o.pop();t&&Y(t)}i.preload()}const i=e.getAudioManager();i.load([t+"click.mp3",t+"click.wav",t+"click.ogg"],"click"),i.load([t+"disconnect.wav",t+"disconnect.mp3",t+"disconnect.ogg"],"disconnect"),i.load([t+"delete.mp3",t+"delete.ogg",t+"delete.wav"],"delete");const o=[];o.push(z(document,"pointermove",null,s,!0)),o.push(z(document,"touchstart",null,s,!0))},vr=function(t){return void 0!==t.getType&&void 0!==t.initView&&void 0!==t.dispose&&void 0!==t.getWeight&&void 0!==t.getSize&&void 0!==t.applyColour&&void 0!==t.hideForInsertionMarker&&void 0!==t.updateEditable&&void 0!==t.updateCollapsed&&void 0!==t.isShownWhenCollapsed&&void 0!==t.setOffsetInBlock&&void 0!==t.onLocationChange&&void 0!==t.onClick},Ir=function(t){return void 0!==t.paste},Sr=function(t){return t.isSelectable()},Rr=function(t){p().hideChaff(t)},(Dr=Dr||{}).scope={},Dr.ASSUME_ES5=!1,Dr.ASSUME_NO_NATIVE_MAP=!1,Dr.ASSUME_NO_NATIVE_SET=!1,Dr.SIMPLE_FROUND_POLYFILL=!1,Dr.ISOLATE_POLYFILLS=!1,Dr.FORCE_POLYFILL_PROMISE=!1,Dr.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1,Dr.defineProperty=Dr.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,s){return t==Array.prototype||t==Object.prototype||(t[e]=s.value),t},Dr.getGlobal=function(t){t=["object"==typeof globalThis&&globalThis,t,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var e=0;e>>0,Dr.propertyToPolyfillSymbol[o]=Dr.IS_SYMBOL_NATIVE?Dr.global.Symbol(o):Dr.POLYFILL_PREFIX+s+"$"+o),Dr.defineProperty(i,Dr.propertyToPolyfillSymbol[o],{configurable:!0,writable:!0,value:e})))},Dr.polyfill("globalThis",(function(t){return t||Dr.global}),"es_2020","es3"),Dr.arrayIteratorImpl=function(t){var e=0;return function(){return e{const t=[];for(let e=0;20>e;e++)t[e]=fl.charAt(88*Math.random());return t.join("")}},Tl=0,kl={TEST_ONLY:El};kl.genUid=C,kl.getNextUniqueId=$,Xr="",Yr=!0,Kr=0,Ar.CREATE$$module$build$src$core$events$utils="create",Ar.CREATE$$module$build$src$core$events$utils,Ar.DELETE$$module$build$src$core$events$utils="delete",Ar.DELETE$$module$build$src$core$events$utils,Ar.CHANGE$$module$build$src$core$events$utils="change",Ar.CHANGE$$module$build$src$core$events$utils,Jr="block_field_intermediate_change",Ar.MOVE$$module$build$src$core$events$utils="move",Ar.MOVE$$module$build$src$core$events$utils,jr="var_create",Zr="var_delete",qr="var_rename",Qr="ui",tl="drag",el="selected",sl="click",il="marker_move",ol="bubble_open",nl="trashcan_open",rl="toolbox_item_select",ll="theme_change",al="viewport_change",hl="comment_create",cl="comment_delete",ul="comment_change",dl="comment_move",pl="finished_loading",gl=[Ar.CREATE$$module$build$src$core$events$utils,Ar.MOVE$$module$build$src$core$events$utils,hl,dl],_l={FIRE_QUEUE:bl=[],fireNow:D,fireInternal:R,setGroupInternal:x},(ml={BLOCK_CHANGE:Ar.CHANGE$$module$build$src$core$events$utils,BLOCK_CREATE:Ar.CREATE$$module$build$src$core$events$utils,BLOCK_DELETE:Ar.DELETE$$module$build$src$core$events$utils,BLOCK_DRAG:tl,BLOCK_FIELD_INTERMEDIATE_CHANGE:Jr,BLOCK_MOVE:Ar.MOVE$$module$build$src$core$events$utils,BUBBLE_OPEN:ol,BUMP_EVENTS:gl,CHANGE:Ar.CHANGE$$module$build$src$core$events$utils,CLICK:sl,COMMENT_CHANGE:ul,COMMENT_CREATE:hl,COMMENT_DELETE:cl,COMMENT_MOVE:dl,CREATE:Ar.CREATE$$module$build$src$core$events$utils,DELETE:Ar.DELETE$$module$build$src$core$events$utils,FINISHED_LOADING:pl,MARKER_MOVE:il,MOVE:Ar.MOVE$$module$build$src$core$events$utils,SELECTED:el,TEST_ONLY:_l,THEME_CHANGE:ll,TOOLBOX_ITEM_SELECT:rl,TRASHCAN_OPEN:nl,UI:Qr,VAR_CREATE:jr,VAR_DELETE:Zr,VAR_RENAME:qr,VIEWPORT_CHANGE:al}).clearPendingUndo=N,ml.disable=Ar.disable$$module$build$src$core$events$utils,ml.disableOrphans=P,ml.enable=Ar.enable$$module$build$src$core$events$utils,ml.filter=A,ml.fire=S,ml.fromJson=M,ml.get=B,ml.getDescendantIds=L,ml.getGroup=Ar.getGroup$$module$build$src$core$events$utils,ml.getRecordUndo=I,ml.isEnabled=O,ml.setGroup=Ar.setGroup$$module$build$src$core$events$utils,ml.setRecordUndo=v;var wl,yl,$l=class{constructor(){this.workspaceId=void 0,this.isUiEvent=!1,this.type="",this.group=Ar.getGroup$$module$build$src$core$events$utils(),this.recordUndo=I()}toJson(){return{type:this.type,group:this.group}}static fromJson(t,e,s){return s.isBlank=!1,s.group=t.group||"",s.workspaceId=e.id,s}isNull(){return!1}run(t){}getEventWorkspace_(){let t;if(this.workspaceId&&(t=h(this.workspaceId)),!t)throw Error("Workspace is null. Event must have been generated from real Blockly events.");return t}},Cl=class extends $l{constructor(t){super(),this.recordUndo=!1,this.isUiEvent=!0,this.isBlank=void 0===t,this.workspaceId=t||""}},vl=class extends Cl{constructor(t,e,s){null===(e=t?t.workspace.id:e)&&(e=void 0),super(e),this.type=sl,this.blockId=t?t.id:void 0,this.targetType=s}toJson(){const t=super.toJson();if(!this.targetType)throw Error("The click target type is undefined. Either pass a block to the constructor, or call fromJson");return t.targetType=this.targetType,t.blockId=this.blockId,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new vl)).targetType=t.targetType,e.blockId=t.blockId,e}};(yl=wl||(wl={})).BLOCK="block",yl.WORKSPACE="workspace",yl.ZOOM_CONTROLS="zoom_controls",t(Mr.EVENT,sl,vl);var Il={};Il.Click=vl,Il.ClickTarget=wl;var Sl,Rl,Dl,Al,Nl,Ol,xl,Ll,Ml,Bl,Pl=750,Fl="ontouchstart"in globalThis||!!(globalThis.document&&document.documentElement&&"ontouchstart"in document.documentElement)||!(!globalThis.navigator||!globalThis.navigator.maxTouchPoints&&!globalThis.navigator.msMaxTouchPoints),Hl=null,Gl={mousedown:["pointerdown"],mouseenter:["pointerenter"],mouseleave:["pointerleave"],mousemove:["pointermove"],mouseout:["pointerout"],mouseover:["pointerover"],mouseup:["pointerup","pointercancel"],touchend:["pointerup"],touchcancel:["pointercancel"]},Ul=0,Wl={TOUCH_ENABLED:Fl,TOUCH_MAP:Gl};Wl.checkTouchIdentifier=V,Wl.clearTouchIdentifier=G,Wl.getTouchIdentifierFromEvent=W,Wl.longStart=F,Wl.longStop=H,Wl.shouldHandleEvent=U,function(t){function e(t){return-1!==s.indexOf(t.toUpperCase())}const s=(Sl=t).toUpperCase();Rl=e("JavaFX"),Dl=e("WebKit"),Al=e("Gecko")&&!Dl,Nl=e("Android"),t=globalThis.navigator&&globalThis.navigator.maxTouchPoints,Ol=e("iPad")||e("Macintosh")&&0{e.push(this.componentData.get(t))})),e.sort((function(t,e){return t.weight-e.weight})),e.forEach((function(t){s.push(t.component)}))}else t.forEach((t=>{s.push(this.componentData.get(t).component)}));return s}};ia.Capability=sa;var oa=!1,na='\n.blocklySvg {\n background-color: #fff;\n outline: none;\n overflow: hidden; /* IE overflows by default. */\n position: absolute;\n display: block;\n}\n\n.blocklyWidgetDiv {\n display: none;\n position: absolute;\n z-index: 99999; /* big value for bootstrap3 compatibility */\n}\n\n.injectionDiv {\n height: 100%;\n position: relative;\n overflow: hidden; /* So blocks in drag surface disappear at edges */\n touch-action: none;\n}\n\n.blocklyNonSelectable {\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n}\n\n.blocklyBlockCanvas.blocklyCanvasTransitioning,\n.blocklyBubbleCanvas.blocklyCanvasTransitioning {\n transition: transform .5s;\n}\n\n.blocklyTooltipDiv {\n background-color: #ffffc7;\n border: 1px solid #ddc;\n box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);\n color: #000;\n display: none;\n font: 9pt sans-serif;\n opacity: .9;\n padding: 2px;\n position: absolute;\n z-index: 100000; /* big value for bootstrap3 compatibility */\n}\n\n.blocklyDropDownDiv {\n position: absolute;\n left: 0;\n top: 0;\n z-index: 1000;\n display: none;\n border: 1px solid;\n border-color: #dadce0;\n background-color: #fff;\n border-radius: 2px;\n padding: 4px;\n box-shadow: 0 0 3px 1px rgba(0,0,0,.3);\n}\n\n.blocklyDropDownDiv.blocklyFocused {\n box-shadow: 0 0 6px 1px rgba(0,0,0,.3);\n}\n\n.blocklyDropDownContent {\n max-height: 300px; /* @todo: spec for maximum height. */\n overflow: auto;\n overflow-x: hidden;\n position: relative;\n}\n\n.blocklyDropDownArrow {\n position: absolute;\n left: 0;\n top: 0;\n width: 16px;\n height: 16px;\n z-index: -1;\n background-color: inherit;\n border-color: inherit;\n}\n\n.blocklyDropDownButton {\n display: inline-block;\n float: left;\n padding: 0;\n margin: 4px;\n border-radius: 4px;\n outline: none;\n border: 1px solid;\n transition: box-shadow .1s;\n cursor: pointer;\n}\n\n.blocklyArrowTop {\n border-top: 1px solid;\n border-left: 1px solid;\n border-top-left-radius: 4px;\n border-color: inherit;\n}\n\n.blocklyArrowBottom {\n border-bottom: 1px solid;\n border-right: 1px solid;\n border-bottom-right-radius: 4px;\n border-color: inherit;\n}\n\n.blocklyResizeSE {\n cursor: se-resize;\n fill: #aaa;\n}\n\n.blocklyResizeSW {\n cursor: sw-resize;\n fill: #aaa;\n}\n\n.blocklyResizeLine {\n stroke: #515A5A;\n stroke-width: 1;\n}\n\n.blocklyHighlightedConnectionPath {\n fill: none;\n stroke: #fc3;\n stroke-width: 4px;\n}\n\n.blocklyPathLight {\n fill: none;\n stroke-linecap: round;\n stroke-width: 1;\n}\n\n.blocklySelected>.blocklyPathLight {\n display: none;\n}\n\n.blocklyDraggable {\n cursor: grab;\n cursor: -webkit-grab;\n}\n\n.blocklyDragging {\n cursor: grabbing;\n cursor: -webkit-grabbing;\n}\n\n /* Changes cursor on mouse down. Not effective in Firefox because of\n https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */\n.blocklyDraggable:active {\n cursor: grabbing;\n cursor: -webkit-grabbing;\n}\n\n.blocklyDragging.blocklyDraggingDelete {\n cursor: url("<<>>/handdelete.cur"), auto;\n}\n\n.blocklyDragging>.blocklyPath,\n.blocklyDragging>.blocklyPathLight {\n fill-opacity: .8;\n stroke-opacity: .8;\n}\n\n.blocklyDragging>.blocklyPathDark {\n display: none;\n}\n\n.blocklyDisabled>.blocklyPath {\n fill-opacity: .5;\n stroke-opacity: .5;\n}\n\n.blocklyDisabled>.blocklyPathLight,\n.blocklyDisabled>.blocklyPathDark {\n display: none;\n}\n\n.blocklyInsertionMarker>.blocklyPath,\n.blocklyInsertionMarker>.blocklyPathLight,\n.blocklyInsertionMarker>.blocklyPathDark {\n fill-opacity: .2;\n stroke: none;\n}\n\n.blocklyMultilineText {\n font-family: monospace;\n}\n\n.blocklyNonEditableText>text {\n pointer-events: none;\n}\n\n.blocklyFlyout {\n position: absolute;\n z-index: 20;\n}\n\n.blocklyText text {\n cursor: default;\n}\n\n/*\n Don\'t allow users to select text. It gets annoying when trying to\n drag a block and selected text moves instead.\n*/\n.blocklySvg text {\n user-select: none;\n -ms-user-select: none;\n -webkit-user-select: none;\n cursor: inherit;\n}\n\n.blocklyHidden {\n display: none;\n}\n\n.blocklyFieldDropdown:not(.blocklyHidden) {\n display: block;\n}\n\n.blocklyIconGroup {\n cursor: default;\n}\n\n.blocklyIconGroup:not(:hover),\n.blocklyIconGroupReadonly {\n opacity: .6;\n}\n\n.blocklyIconShape {\n fill: #00f;\n stroke: #fff;\n stroke-width: 1px;\n}\n\n.blocklyIconSymbol {\n fill: #fff;\n}\n\n.blocklyMinimalBody {\n margin: 0;\n padding: 0;\n}\n\n.blocklyHtmlInput {\n border: none;\n border-radius: 4px;\n height: 100%;\n margin: 0;\n outline: none;\n padding: 0;\n width: 100%;\n text-align: center;\n display: block;\n box-sizing: border-box;\n}\n\n/* Remove the increase and decrease arrows on the field number editor */\ninput.blocklyHtmlInput[type=number]::-webkit-inner-spin-button,\ninput.blocklyHtmlInput[type=number]::-webkit-outer-spin-button {\n -webkit-appearance: none;\n margin: 0;\n}\n\ninput[type=number] {\n -moz-appearance: textfield;\n}\n\n.blocklyMainBackground {\n stroke-width: 1;\n stroke: #c6c6c6; /* Equates to #ddd due to border being off-pixel. */\n}\n\n.blocklyMutatorBackground {\n fill: #fff;\n stroke: #ddd;\n stroke-width: 1;\n}\n\n.blocklyFlyoutBackground {\n fill: #ddd;\n fill-opacity: .8;\n}\n\n.blocklyMainWorkspaceScrollbar {\n z-index: 20;\n}\n\n.blocklyFlyoutScrollbar {\n z-index: 30;\n}\n\n.blocklyScrollbarHorizontal,\n.blocklyScrollbarVertical {\n position: absolute;\n outline: none;\n}\n\n.blocklyScrollbarBackground {\n opacity: 0;\n}\n\n.blocklyScrollbarHandle {\n fill: #ccc;\n}\n\n.blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,\n.blocklyScrollbarHandle:hover {\n fill: #bbb;\n}\n\n/* Darken flyout scrollbars due to being on a grey background. */\n/* By contrast, workspace scrollbars are on a white background. */\n.blocklyFlyout .blocklyScrollbarHandle {\n fill: #bbb;\n}\n\n.blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,\n.blocklyFlyout .blocklyScrollbarHandle:hover {\n fill: #aaa;\n}\n\n.blocklyInvalidInput {\n background: #faa;\n}\n\n.blocklyVerticalMarker {\n stroke-width: 3px;\n fill: rgba(255,255,255,.5);\n pointer-events: none;\n}\n\n.blocklyComputeCanvas {\n position: absolute;\n width: 0;\n height: 0;\n}\n\n.blocklyNoPointerEvents {\n pointer-events: none;\n}\n\n.blocklyContextMenu {\n border-radius: 4px;\n max-height: 100%;\n}\n\n.blocklyDropdownMenu {\n border-radius: 2px;\n padding: 0 !important;\n}\n\n.blocklyDropdownMenu .blocklyMenuItem {\n /* 28px on the left for icon or checkbox. */\n padding-left: 28px;\n}\n\n/* BiDi override for the resting state. */\n.blocklyDropdownMenu .blocklyMenuItemRtl {\n /* Flip left/right padding for BiDi. */\n padding-left: 5px;\n padding-right: 28px;\n}\n\n.blocklyWidgetDiv .blocklyMenu {\n background: #fff;\n border: 1px solid transparent;\n box-shadow: 0 0 3px 1px rgba(0,0,0,.3);\n font: normal 13px Arial, sans-serif;\n margin: 0;\n outline: none;\n padding: 4px 0;\n position: absolute;\n overflow-y: auto;\n overflow-x: hidden;\n max-height: 100%;\n z-index: 20000; /* Arbitrary, but some apps depend on it... */\n}\n\n.blocklyWidgetDiv .blocklyMenu.blocklyFocused {\n box-shadow: 0 0 6px 1px rgba(0,0,0,.3);\n}\n\n.blocklyDropDownDiv .blocklyMenu {\n background: inherit; /* Compatibility with gapi, reset from goog-menu */\n border: inherit; /* Compatibility with gapi, reset from goog-menu */\n font: normal 13px "Helvetica Neue", Helvetica, sans-serif;\n outline: none;\n position: relative; /* Compatibility with gapi, reset from goog-menu */\n z-index: 20000; /* Arbitrary, but some apps depend on it... */\n}\n\n/* State: resting. */\n.blocklyMenuItem {\n border: none;\n color: #000;\n cursor: pointer;\n list-style: none;\n margin: 0;\n /* 7em on the right for shortcut. */\n min-width: 7em;\n padding: 6px 15px;\n white-space: nowrap;\n}\n\n/* State: disabled. */\n.blocklyMenuItemDisabled {\n color: #ccc;\n cursor: inherit;\n}\n\n/* State: hover. */\n.blocklyMenuItemHighlight {\n background-color: rgba(0,0,0,.1);\n}\n\n/* State: selected/checked. */\n.blocklyMenuItemCheckbox {\n height: 16px;\n position: absolute;\n width: 16px;\n}\n\n.blocklyMenuItemSelected .blocklyMenuItemCheckbox {\n background: url(<<>>/sprites.png) no-repeat -48px -16px;\n float: left;\n margin-left: -24px;\n position: static; /* Scroll with the menu. */\n}\n\n.blocklyMenuItemRtl .blocklyMenuItemCheckbox {\n float: right;\n margin-right: -24px;\n}\n\n.blocklyBlockDragSurface {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n overflow: visible !important;\n z-index: 80;\n pointer-events: none;\n}\n',ra={};ra.inject=tt,ra.register=Q;var la=class{constructor(t,e){this.x=t,this.y=e}clone(){return new la(this.x,this.y)}scale(t){return this.x*=t,this.y*=t,this}translate(t,e){return this.x+=t,this.y+=e,this}static equals(t,e){return t===e||!(!t||!e)&&(t.x===e.x&&t.y===e.y)}static distance(t,e){const s=t.x-e.x;return t=t.y-e.y,Math.sqrt(s*s+t*t)}static magnitude(t){return Math.sqrt(t.x*t.x+t.y*t.y)}static difference(t,e){return new la(t.x-e.x,t.y-e.y)}static sum(t,e){return new la(t.x+e.x,t.y+e.y)}},aa={};aa.warn=et;var ha,ca="http://www.w3.org/2000/svg",ua="http://www.w3.org/1999/xhtml",da="http://www.w3.org/1999/xlink";!function(t){t[t.ELEMENT_NODE=1]="ELEMENT_NODE",t[t.TEXT_NODE=3]="TEXT_NODE",t[t.COMMENT_NODE=8]="COMMENT_NODE"}(ha||(ha={}));var pa=null,ga=0,ba=null,_a={HTML_NS:ua};_a.NodeType=ha,_a.SVG_NS=ca,_a.XLINK_NS=da,_a.addClass=it,_a.containsNode=ht,_a.createSvgElement=st,_a.getFastTextWidth=gt,_a.getFastTextWidthWithSizeString=bt,_a.getTextWidth=pt,_a.hasClass=rt,_a.insertAfter=at,_a.measureFontMetrics=_t,_a.removeClass=nt,_a.removeClasses=ot,_a.removeNode=lt,_a.setCssTransform=ct,_a.startTextWidthCache=ut,_a.stopTextWidthCache=dt;var ma=class{constructor(t){this.tagName=t}toString(){return this.tagName}};ma.ANIMATE=new ma("animate"),ma.CIRCLE=new ma("circle"),ma.CLIPPATH=new ma("clipPath"),ma.DEFS=new ma("defs"),ma.FECOMPOSITE=new ma("feComposite"),ma.FECOMPONENTTRANSFER=new ma("feComponentTransfer"),ma.FEFLOOD=new ma("feFlood"),ma.FEFUNCA=new ma("feFuncA"),ma.FEGAUSSIANBLUR=new ma("feGaussianBlur"),ma.FEPOINTLIGHT=new ma("fePointLight"),ma.FESPECULARLIGHTING=new ma("feSpecularLighting"),ma.FILTER=new ma("filter"),ma.FOREIGNOBJECT=new ma("foreignObject"),ma.G=new ma("g"),ma.IMAGE=new ma("image"),ma.LINE=new ma("line"),ma.PATH=new ma("path"),ma.PATTERN=new ma("pattern"),ma.POLYGON=new ma("polygon"),ma.RECT=new ma("rect"),ma.SVG=new ma("svg"),ma.TEXT=new ma("text"),ma.TSPAN=new ma("tspan");var fa=class{constructor(t,e,s,i){this.top=t,this.bottom=e,this.left=s,this.right=i}getHeight(){return this.bottom-this.top}getWidth(){return this.right-this.left}contains(t,e){return t>=this.left&&t<=this.right&&e>=this.top&&e<=this.bottom}intersects(t){return!(this.left>t.right||this.rightt.bottom||this.bottom=t||isNaN(t)?0:Math.min(t,this.scrollbarLength)}setHandleLength(t){this.handleLength=t,this.svgHandle.setAttribute(this.lengthAttribute_,String(this.handleLength))}constrainHandlePosition(t){return 0>=t||isNaN(t)?0:Math.min(t,this.scrollbarLength-this.handleLength)}setHandlePosition(t){this.handlePosition=t,this.svgHandle.setAttribute(this.positionAttribute_,String(this.handlePosition))}setScrollbarLength(t){this.scrollbarLength=t,this.outerSvg.setAttribute(this.lengthAttribute_,String(this.scrollbarLength)),this.svgBackground.setAttribute(this.lengthAttribute_,String(this.scrollbarLength))}setPosition(t,e){this.position.x=t,this.position.y=e,ct(this.outerSvg,"translate("+(this.position.x+this.origin.x)+"px,"+(this.position.y+this.origin.y)+"px)")}resize(t){(t||(t=this.workspace.getMetrics()))&&(this.oldHostMetrics&&Ca.metricsAreEquivalent(t,this.oldHostMetrics)||(this.horizontal?this.resizeHorizontal(t):this.resizeVertical(t),this.oldHostMetrics=t,this.updateMetrics()))}requiresViewResize(t){return!this.oldHostMetrics||(this.oldHostMetrics.viewWidth!==t.viewWidth||this.oldHostMetrics.viewHeight!==t.viewHeight||this.oldHostMetrics.absoluteLeft!==t.absoluteLeft||this.oldHostMetrics.absoluteTop!==t.absoluteTop)}resizeHorizontal(t){this.requiresViewResize(t)?this.resizeViewHorizontal(t):this.resizeContentHorizontal(t)}resizeViewHorizontal(t){var e=t.viewWidth-2*this.margin;this.pair&&(e-=Ca.scrollbarThickness),this.setScrollbarLength(Math.max(0,e)),e=t.absoluteLeft+this.margin,this.pair&&this.workspace.RTL&&(e+=Ca.scrollbarThickness),this.setPosition(e,t.absoluteTop+t.viewHeight-Ca.scrollbarThickness-this.margin),this.resizeContentHorizontal(t)}resizeContentHorizontal(t){if(t.viewWidth>=t.scrollWidth)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var e=this.scrollbarLength*t.viewWidth/t.scrollWidth;e=this.constrainHandleLength(e),this.setHandleLength(e),e=t.scrollWidth-t.viewWidth;var s=this.scrollbarLength-this.handleLength;t=(t.viewLeft-t.scrollLeft)/e*s,t=this.constrainHandlePosition(t),this.setHandlePosition(t),this.ratio=s/e}}resizeVertical(t){this.requiresViewResize(t)?this.resizeViewVertical(t):this.resizeContentVertical(t)}resizeViewVertical(t){let e=t.viewHeight-2*this.margin;this.pair&&(e-=Ca.scrollbarThickness),this.setScrollbarLength(Math.max(0,e)),this.setPosition(this.workspace.RTL?t.absoluteLeft+this.margin:t.absoluteLeft+t.viewWidth-Ca.scrollbarThickness-this.margin,t.absoluteTop+this.margin),this.resizeContentVertical(t)}resizeContentVertical(t){if(t.viewHeight>=t.scrollHeight)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var e=this.scrollbarLength*t.viewHeight/t.scrollHeight;e=this.constrainHandleLength(e),this.setHandleLength(e),e=t.scrollHeight-t.viewHeight;var s=this.scrollbarLength-this.handleLength;t=(t.viewTop-t.scrollTop)/e*s,t=this.constrainHandlePosition(t),this.setHandlePosition(t),this.ratio=s/e}}isVisible(){return this.isHandleVisible}setContainerVisible(t){const e=t!==this.containerVisible;this.containerVisible=t,e&&this.updateDisplay_()}setVisible(t){if(this.pair)throw Error("Unable to toggle visibility of paired scrollbars.");this.setVisibleInternal(t)}setVisibleInternal(t){const e=t!==this.isVisible();this.isHandleVisible=t,e&&this.updateDisplay_()}updateDisplay_(){this.containerVisible&&this.isVisible()?this.outerSvg.setAttribute("display","block"):this.outerSvg.setAttribute("display","none")}onMouseDownBar(t){if(this.workspace.markFocused(),G(),this.cleanUp(),J(t))t.stopPropagation();else{var e=j(t,this.workspace.getParentSvg(),this.workspace.getInverseScreenCTM());e=this.horizontal?e.x:e.y;var s=It(this.svgHandle);s=this.horizontal?s.x:s.y;var i=this.handlePosition,o=.95*this.handleLength;e<=s?i-=o:e>=s+this.handleLength&&(i+=o),this.setHandlePosition(this.constrainHandlePosition(i)),this.updateMetrics(),t.stopPropagation(),t.preventDefault()}}onMouseDownHandle(t){this.workspace.markFocused(),this.cleanUp(),J(t)?t.stopPropagation():(this.startDragHandle=this.handlePosition,this.startDragMouse=this.horizontal?t.clientX:t.clientY,this.onMouseUpWrapper_=z(document,"pointerup",this,this.onMouseUpHandle),this.onMouseMoveWrapper_=z(document,"pointermove",this,this.onMouseMoveHandle),t.stopPropagation(),t.preventDefault())}onMouseMoveHandle(t){this.setHandlePosition(this.constrainHandlePosition(this.startDragHandle+((this.horizontal?t.clientX:t.clientY)-this.startDragMouse))),this.updateMetrics()}onMouseUpHandle(){G(),this.cleanUp()}cleanUp(){this.workspace.hideChaff(!0),this.onMouseUpWrapper_&&(Y(this.onMouseUpWrapper_),this.onMouseUpWrapper_=null),this.onMouseMoveWrapper_&&(Y(this.onMouseMoveWrapper_),this.onMouseMoveWrapper_=null)}getRatio_(){let t=this.handlePosition/(this.scrollbarLength-this.handleLength);return isNaN(t)&&(t=0),t}updateMetrics(){const t=this.getRatio_();this.horizontal?this.workspace.setMetrics({x:t}):this.workspace.setMetrics({y:t})}set(t,e){this.setHandlePosition(this.constrainHandlePosition(t*this.ratio)),(e||void 0===e)&&this.updateMetrics()}setOrigin(t,e){this.origin=new la(t,e)}static metricsAreEquivalent(t,e){return t.viewWidth===e.viewWidth&&t.viewHeight===e.viewHeight&&t.viewLeft===e.viewLeft&&t.viewTop===e.viewTop&&t.absoluteTop===e.absoluteTop&&t.absoluteLeft===e.absoluteLeft&&t.scrollWidth===e.scrollWidth&&t.scrollHeight===e.scrollHeight&&t.scrollLeft===e.scrollLeft&&t.scrollTop===e.scrollTop}};Ca.scrollbarThickness=Fl?25:15,Ca.DEFAULT_SCROLLBAR_MARGIN=.5;var va={parseFromString:function(){throw Error("DOMParser was not found in the global scope and was not properly injected using injectDependencies")}},Ia={serializeToString:function(){throw Error("XMLSerializer was not foundin the global scope and was not properly injected using injectDependencies")}},{document:Sa,DOMParser:Ra,XMLSerializer:Da}=globalThis;Ra&&(va=new Ra),Da&&(Ia=new Da);var Aa="https://developers.google.com/blockly/xml",Na=/[\x00-\x09\x0B\x0C\x0E-\x1F]/g,Oa={NAME_SPACE:Aa};Oa.createElement=Ar.createElement$$module$build$src$core$utils$xml,Oa.createTextNode=Ar.createTextNode$$module$build$src$core$utils$xml,Oa.domToText=Ot,Oa.injectDependencies=Nt,Oa.textToDom=Ar.textToDom$$module$build$src$core$utils$xml;var xa,La="categoryToolbox",Ma="flyoutToolbox";!function(t){t[t.TOP=0]="TOP",t[t.BOTTOM=1]="BOTTOM",t[t.LEFT=2]="LEFT",t[t.RIGHT=3]="RIGHT"}(xa||(xa={}));var Ba,Pa,Fa,Ha={hasCategoriesInternal:Ft},Ga={};Ga.Position=xa,Ga.TEST_ONLY=Ha,Ga.convertFlyoutDefToJsonArray=Bt,Ga.convertToolboxDefToJson=Lt,Ga.hasCategories=Pt,Ga.isCategoryCollapsible=Ht,Ga.parseToolboxTree=Vt,function(t){t[t.TOP=0]="TOP",t[t.BOTTOM=1]="BOTTOM"}(Ba||(Ba={})),function(t){t[t.LEFT=0]="LEFT",t[t.RIGHT=1]="RIGHT"}(Pa||(Pa={})),function(t){t[t.UP=0]="UP",t[t.DOWN=1]="DOWN"}(Fa||(Fa={}));var Ua={};Ua.bumpDirection=Fa,Ua.bumpPositionRect=Yt,Ua.getCornerOppositeToolbox=Xt,Ua.getStartPositionRect=zt,Ua.horizontalPosition=Pa,Ua.verticalPosition=Ba;var Wa={width:96,height:124,url:"sprites.png"},Va=class{constructor(t){this.workspace=t,this.id="zoomControls",this.boundEvents=[],this.zoomResetGroup=this.zoomOutGroup=this.zoomInGroup=null,this.HEIGHT=this.WIDTH=32,this.SMALL_SPACING=2,this.LARGE_SPACING=11,this.MARGIN_HORIZONTAL=this.MARGIN_VERTICAL=20,this.svgGroup=null,this.top=this.left=0,this.initialized=!1}createDom(){this.svgGroup=st(ma.G,{});const t=String(Math.random()).substring(2);return this.createZoomOutSvg(t),this.createZoomInSvg(t),this.workspace.isMovable()&&this.createZoomResetSvg(t),this.svgGroup}init(){this.workspace.getComponentManager().addComponent({component:this,weight:2,capabilities:[ia.Capability.POSITIONABLE]}),this.initialized=!0}dispose(){this.workspace.getComponentManager().removeComponent("zoomControls"),this.svgGroup&<(this.svgGroup);for(const t of this.boundEvents)Y(t);this.boundEvents.length=0}getBoundingRectangle(){let t=this.SMALL_SPACING+2*this.HEIGHT;return this.zoomResetGroup&&(t+=this.LARGE_SPACING+this.HEIGHT),new fa(this.top,this.top+t,this.left,this.left+this.WIDTH)}position(t,e){if(this.initialized){var s,i=Xt(this.workspace,t),o=this.SMALL_SPACING+2*this.HEIGHT;if(this.zoomResetGroup&&(o+=this.LARGE_SPACING+this.HEIGHT),t=zt(i,new Ea(this.WIDTH,o),this.MARGIN_HORIZONTAL,this.MARGIN_VERTICAL,t,this.workspace),i=i.vertical,e=Yt(t,this.MARGIN_VERTICAL,i===Ba.TOP?Fa.DOWN:Fa.UP,e),i===Ba.TOP){var n,r=this.SMALL_SPACING+this.HEIGHT;null==(n=this.zoomInGroup)||n.setAttribute("transform","translate(0, "+r+")"),this.zoomResetGroup&&this.zoomResetGroup.setAttribute("transform","translate(0, "+(r+this.LARGE_SPACING+this.HEIGHT)+")")}else{let t;n=this.zoomResetGroup?this.LARGE_SPACING+this.HEIGHT:0,null==(t=this.zoomInGroup)||t.setAttribute("transform","translate(0, "+n+")"),n=n+this.SMALL_SPACING+this.HEIGHT,null==(r=this.zoomOutGroup)||r.setAttribute("transform","translate(0, "+n+")")}this.top=e.top,this.left=e.left,null==(s=this.svgGroup)||s.setAttribute("transform","translate("+this.left+","+this.top+")")}}createZoomOutSvg(t){this.zoomOutGroup=st(ma.G,{class:"blocklyZoom blocklyZoomOut"},this.svgGroup);const e=st(ma.CLIPPATH,{id:"blocklyZoomoutClipPath"+t},this.zoomOutGroup);st(ma.RECT,{width:32,height:32},e),st(ma.IMAGE,{width:Wa.width,height:Wa.height,x:-64,y:-92,"clip-path":"url(#blocklyZoomoutClipPath"+t+")"},this.zoomOutGroup).setAttributeNS(da,"xlink:href",this.workspace.options.pathToMedia+Wa.url),this.boundEvents.push(z(this.zoomOutGroup,"pointerdown",null,this.zoom.bind(this,-1)))}createZoomInSvg(t){this.zoomInGroup=st(ma.G,{class:"blocklyZoom blocklyZoomIn"},this.svgGroup);const e=st(ma.CLIPPATH,{id:"blocklyZoominClipPath"+t},this.zoomInGroup);st(ma.RECT,{width:32,height:32},e),st(ma.IMAGE,{width:Wa.width,height:Wa.height,x:-32,y:-92,"clip-path":"url(#blocklyZoominClipPath"+t+")"},this.zoomInGroup).setAttributeNS(da,"xlink:href",this.workspace.options.pathToMedia+Wa.url),this.boundEvents.push(z(this.zoomInGroup,"pointerdown",null,this.zoom.bind(this,1)))}zoom(t,e){this.workspace.markFocused(),this.workspace.zoomCenter(t),this.fireZoomEvent(),G(),e.stopPropagation(),e.preventDefault()}createZoomResetSvg(t){this.zoomResetGroup=st(ma.G,{class:"blocklyZoom blocklyZoomReset"},this.svgGroup);const e=st(ma.CLIPPATH,{id:"blocklyZoomresetClipPath"+t},this.zoomResetGroup);st(ma.RECT,{width:32,height:32},e),st(ma.IMAGE,{width:Wa.width,height:Wa.height,y:-92,"clip-path":"url(#blocklyZoomresetClipPath"+t+")"},this.zoomResetGroup).setAttributeNS(da,"xlink:href",this.workspace.options.pathToMedia+Wa.url),this.boundEvents.push(z(this.zoomResetGroup,"pointerdown",null,this.resetZoom.bind(this)))}resetZoom(t){this.workspace.markFocused();const e=Math.log(this.workspace.options.zoomOptions.startScale/this.workspace.scale)/Math.log(this.workspace.options.zoomOptions.scaleSpeed);this.workspace.beginCanvasTransition(),this.workspace.zoomCenter(e),this.workspace.scrollCenter(),setTimeout(this.workspace.endCanvasTransition.bind(this.workspace),500),this.fireZoomEvent(),G(),t.stopPropagation(),t.preventDefault()}fireZoomEvent(){const t=new(B(sl))(null,this.workspace.id,"zoom_controls");S(t)}};Q("\n.blocklyZoom>image, .blocklyZoom>svg>image {\n opacity: .4;\n}\n\n.blocklyZoom>image:hover, .blocklyZoom>svg>image:hover {\n opacity: .6;\n}\n\n.blocklyZoom>image:active, .blocklyZoom>svg>image:active {\n opacity: .8;\n}\n");var za=class{constructor(t){this.name=t}toString(){return this.name}equals(t){return this.name===t.toString()}};za.MUTATOR=new za("mutator"),za.WARNING=new za("warning"),za.COMMENT=new za("comment");!function(t){t[t.VALUE=1]="VALUE",t[t.STATEMENT=3]="STATEMENT",t[t.DUMMY=5]="DUMMY",t[t.CUSTOM=6]="CUSTOM",t[t.END_ROW=7]="END_ROW"}(Ar.inputTypes$$module$build$src$core$inputs$input_types||(Ar.inputTypes$$module$build$src$core$inputs$input_types={}));Ar.inputTypes$$module$build$src$core$inputs$input_types;var Xa=function(t,e){window.alert(t),e&&e()},Ya=function(t,e){e(window.confirm(t))},Ka=function(t,e,s){s(window.prompt(t,e))},Ja={confirmInternal:Zt},ja={TEST_ONLY:Ja};ja.alert=Kt,ja.confirm=jt,ja.prompt=Qt,ja.setAlert=Jt,ja.setConfirm=qt,ja.setPrompt=te;var Za,qa;Ar.Msg$$module$build$src$core$msg=Object.create(null),Za=function(t){Object.keys(t).forEach((function(e){Ar.Msg$$module$build$src$core$msg[e]=t[e]}))},qa={Msg:Ar.Msg$$module$build$src$core$msg,setLocale:Za};var Qa={};Qa.isLegacyProcedureCallBlock=ie,Qa.isLegacyProcedureDefBlock=se;var th=class extends $l{constructor(t){super(),this.isBlank=void 0===t,t&&(this.varId=t.getId(),this.workspaceId=t.workspace.id)}toJson(){const t=super.toJson();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");return t.varId=this.varId,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new th)).varId=t.varId,e}},eh=class extends th{constructor(t){super(t),this.type=jr,t&&(this.varType=t.type,this.varName=t.name)}toJson(){const t=super.toJson();if(void 0===this.varType)throw Error("The var type is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson");return t.varType=this.varType,t.varName=this.varName,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new eh)).varType=t.varType,e.varName=t.varName,e}run(t){const e=this.getEventWorkspace_();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson");t?e.createVariable(this.varName,this.varType,this.varId):e.deleteVariableById(this.varId)}};t(Mr.EVENT,jr,eh);var sh=class{constructor(t,e,s,i){this.workspace=t,this.name=e,this.type=s||"",this.id_=i||C()}getId(){return this.id_}static compareByName(t,e){return t.name.localeCompare(e.name,void 0,{sensitivity:"base"})}},ih="VARIABLE",oh="ijkmnopqrstuvwxyzabcdefgh",nh={generateUniqueNameInternal:le},rh={CATEGORY_NAME:ih,TEST_ONLY:nh,VAR_LETTER_OPTIONS:oh};rh.allDeveloperVariables=Ar.allDeveloperVariables$$module$build$src$core$variables,rh.allUsedVarModels=Ar.allUsedVarModels$$module$build$src$core$variables,rh.createVariableButtonHandler=he,rh.flyoutCategory=oe,rh.flyoutCategoryBlocks=ne,rh.generateUniqueName=re,rh.generateUniqueNameFromOptions=ae,rh.generateVariableFieldDom=_e,rh.getAddedVariables=fe,rh.getOrCreateVariablePackage=Ar.getOrCreateVariablePackage$$module$build$src$core$variables,rh.getVariable=Ar.getVariable$$module$build$src$core$variables,rh.nameUsedWithAnyType=de,rh.nameUsedWithConflictingParam=pe,rh.promptName=ce,rh.renameVariable=Ar.renameVariable$$module$build$src$core$variables;var lh=class{constructor(t,e,s,i,o){this.workspace=t,this.editable=this.movable=this.deletable=!0,this.disposed_=!1,this.isComment=!0,this.id=o&&!t.getCommentById(o)?o:C(),t.addTopComment(this),this.xy_=new la(0,0),this.height_=s,this.width_=i,this.RTL=t.RTL,this.content_=e,lh.fireCreateEvent(this)}dispose(){this.disposed_||(O()&&S(new(B(cl))(this)),this.workspace.removeTopComment(this),this.disposed_=!0)}getHeight(){return this.height_}setHeight(t){this.height_=t}getWidth(){return this.width_}setWidth(t){this.width_=t}getRelativeToSurfaceXY(){return new la(this.xy_.x,this.xy_.y)}moveBy(t,e){const s=new(B(dl))(this);this.xy_.translate(t,e),s.recordNew(),S(s)}isDeletable(){return this.deletable&&!(this.workspace&&this.workspace.options.readOnly)}setDeletable(t){this.deletable=t}isMovable(){return this.movable&&!(this.workspace&&this.workspace.options.readOnly)}setMovable(t){this.movable=t}isEditable(){return this.editable&&!(this.workspace&&this.workspace.options.readOnly)}setEditable(t){this.editable=t}getContent(){return this.content_}setContent(t){this.content_!==t&&(S(new(B(ul))(this,this.content_,t)),this.content_=t)}toXmlWithXY(t){return(t=this.toXml(t)).setAttribute("x",String(Math.round(this.xy_.x))),t.setAttribute("y",String(Math.round(this.xy_.y))),t.setAttribute("h",String(this.height_)),t.setAttribute("w",String(this.width_)),t}toXml(t){const e=Ar.createElement$$module$build$src$core$utils$xml("comment");return t||(e.id=this.id),e.textContent=this.getContent(),e}static fireCreateEvent(t){if(O()){const e=Ar.getGroup$$module$build$src$core$events$utils();e||Ar.setGroup$$module$build$src$core$events$utils(!0);try{S(new(B(hl))(t))}finally{Ar.setGroup$$module$build$src$core$events$utils(e)}}}static fromXml(t,e){var s=lh.parseAttributes(t);return e=new lh(e,s.content,s.h,s.w,s.id),s=t.getAttribute("x"),t=t.getAttribute("y"),s=s?parseInt(s,10):NaN,t=t?parseInt(t,10):NaN,isNaN(s)||isNaN(t)||e.moveBy(s,t),lh.fireCreateEvent(e),e}static parseAttributes(t){const e=t.getAttribute("h"),s=t.getAttribute("w"),i=t.getAttribute("x"),o=t.getAttribute("y"),n=t.getAttribute("id");if(!n)throw Error("No ID present in XML comment definition.");let r;return{id:n,h:e?parseInt(e):100,w:s?parseInt(s):100,x:i?parseInt(i):NaN,y:o?parseInt(o):NaN,content:null!=(r=t.textContent)?r:""}}},ah=class extends Cl{constructor(t,e,s){super(s),this.type=el,this.oldElementId=null!=t?t:void 0,this.newElementId=null!=e?e:void 0}toJson(){const t=super.toJson();return t.oldElementId=this.oldElementId,t.newElementId=this.newElementId,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new ah)).oldElementId=t.oldElementId,e.newElementId=t.newElementId,e}};t(Mr.EVENT,el,ah);var hh={};hh.register=Ee,hh.unregister=Te;var ch=class{paste(t,e,s){const i=t.commentState;if(s)i.setAttribute("x",`${s.x}`),i.setAttribute("y",`${s.y}`);else{var o;let t;s=parseInt(null!=(o=i.getAttribute("x"))?o:"0")+50,o=parseInt(null!=(t=i.getAttribute("y"))?t:"0")+50,i.setAttribute("x",`${s}`),i.setAttribute("y",`${o}`)}return uh.fromXmlRendered(t.commentState,e)}};ch.TYPE="workspace-comment",Ee(ch.TYPE,new ch);var uh=class extends lh{constructor(t,e,s,i,o){super(t,e,s,i,o),this.onMouseMoveWrapper=this.onMouseUpWrapper=null,this.eventsInit=!1,this.deleteIconBorder=this.deleteGroup=this.resizeGroup=this.foreignObject=this.svgHandleTarget=this.svgRectTarget=this.textarea=null,this.rendered=this.autoLayout=this.focused=!1,this.svgGroup=st(ma.G,{class:"blocklyComment"}),this.workspace=t,this.svgRect_=st(ma.RECT,{class:"blocklyCommentRect",x:0,y:0,rx:3,ry:3}),this.svgGroup.appendChild(this.svgRect_),this.render()}dispose(){this.disposed_||(b()===this&&(this.unselect(),this.workspace.cancelCurrentGesture()),O()&&S(new(B(cl))(this)),lt(this.svgGroup),Ar.disable$$module$build$src$core$events$utils(),super.dispose(),Ar.enable$$module$build$src$core$events$utils())}initSvg(t){if(!this.workspace.rendered)throw TypeError("Workspace is headless.");this.workspace.options.readOnly||this.eventsInit||(z(this.svgRectTarget,"pointerdown",this,this.pathMouseDown),z(this.svgHandleTarget,"pointerdown",this,this.pathMouseDown)),this.eventsInit=!0,this.updateMovable(),this.getSvgRoot().parentNode||this.workspace.getBubbleCanvas().appendChild(this.getSvgRoot()),!t&&this.textarea&&this.textarea.select()}pathMouseDown(t){const e=this.workspace.getGesture(t);e&&e.handleBubbleStart(t,this)}showContextMenu(t){throw Error("The implementation of showContextMenu should be monkey-patched in by blockly.ts")}select(){if(b()!==this){var t=null;if(b()){t=b().id,Ar.disable$$module$build$src$core$events$utils();try{b().unselect()}finally{Ar.enable$$module$build$src$core$events$utils()}}t=new(B(el))(t,this.id,this.workspace.id),S(t),_(this),this.addSelect()}}unselect(){if(b()===this){var t=new(B(el))(this.id,null,this.workspace.id);S(t),_(null),this.removeSelect(),this.blurFocus()}}addSelect(){it(this.svgGroup,"blocklySelected"),this.setFocus()}removeSelect(){it(this.svgGroup,"blocklySelected"),this.blurFocus()}addFocus(){it(this.svgGroup,"blocklyFocused")}removeFocus(){nt(this.svgGroup,"blocklyFocused")}getRelativeToSurfaceXY(){const t=this.workspace.getLayerManager();if(!t)throw Error("Cannot calculate position because the workspace has not been appended");let e=0,s=0,i=this.getSvgRoot();if(i)do{const t=vt(i);e+=t.x,s+=t.y,i=i.parentNode}while(i&&!t.hasLayer(i)&&null!==i);return this.xy_=new la(e,s)}moveBy(t,e){const s=new(B(dl))(this),i=this.getRelativeToSurfaceXY();this.translate(i.x+t,i.y+e),this.xy_=new la(i.x+t,i.y+e),s.recordNew(),S(s),this.workspace.resizeContents()}translate(t,e){this.xy_=new la(t,e),this.getSvgRoot().setAttribute("transform","translate("+t+","+e+")")}moveDuringDrag(t){t=`translate(${t.x}, ${t.y})`,this.getSvgRoot().setAttribute("transform",t)}moveTo(t,e){this.translate(t,e)}clearTransformAttributes(){this.getSvgRoot().removeAttribute("transform")}getBoundingRectangle(){var t=this.getRelativeToSurfaceXY();const e=this.getHeightWidth(),s=t.y,i=t.y+e.height;let o;return this.RTL?(o=t.x-e.width,t=t.x):(o=t.x,t=t.x+e.width),new fa(s,i,o,t)}updateMovable(){this.isMovable()?it(this.svgGroup,"blocklyDraggable"):nt(this.svgGroup,"blocklyDraggable")}setMovable(t){super.setMovable(t),this.updateMovable()}setEditable(t){super.setEditable(t),this.textarea&&(this.textarea.readOnly=!t)}setDragging(t){t?it(this.getSvgRoot(),"blocklyDragging"):nt(this.getSvgRoot(),"blocklyDragging")}getSvgRoot(){return this.svgGroup}getContent(){return this.textarea?this.textarea.value:this.content_}setContent(t){super.setContent(t),this.textarea&&(this.textarea.value=t)}setDeleteStyle(t){t?it(this.svgGroup,"blocklyDraggingDelete"):nt(this.svgGroup,"blocklyDraggingDelete")}setAutoLayout(t){}toXmlWithXY(t){let e=0;this.workspace.RTL&&(e=this.workspace.getWidth()),t=this.toXml(t);const s=this.getRelativeToSurfaceXY();return t.setAttribute("x",String(Math.round(this.workspace.RTL?e-s.x:s.x))),t.setAttribute("y",String(Math.round(s.y))),t.setAttribute("h",String(this.getHeight())),t.setAttribute("w",String(this.getWidth())),t}toCopyData(){return{paster:ch.TYPE,commentState:this.toXmlWithXY()}}getHeightWidth(){return{width:this.getWidth(),height:this.getHeight()}}render(){if(!this.rendered){var t=this.getHeightWidth(),e=this.createEditor();this.svgGroup.appendChild(e),this.svgHandleTarget=st(ma.RECT,{class:"blocklyCommentHandleTarget",x:0,y:0}),this.svgGroup.appendChild(this.svgHandleTarget),this.svgRectTarget=st(ma.RECT,{class:"blocklyCommentTarget",x:0,y:0,rx:3,ry:3}),this.svgGroup.appendChild(this.svgRectTarget),this.addResizeDom(),this.isDeletable()&&this.addDeleteDom(),this.setSize(t.width,t.height),this.textarea.value=this.content_,this.rendered=!0,this.resizeGroup&&z(this.resizeGroup,"pointerdown",this,this.resizeMouseDown),this.isDeletable()&&(z(this.deleteGroup,"pointerdown",this,this.deleteMouseDown),z(this.deleteGroup,"pointerout",this,this.deleteMouseOut),z(this.deleteGroup,"pointerup",this,this.deleteMouseUp))}}createEditor(){this.foreignObject=st(ma.FOREIGNOBJECT,{x:0,y:uh.TOP_OFFSET,class:"blocklyCommentForeignObject"});const t=document.createElementNS(ua,"body");t.setAttribute("xmlns",ua),t.className="blocklyMinimalBody";const e=document.createElementNS(ua,"textarea");return e.className="blocklyCommentTextarea",e.setAttribute("dir",this.RTL?"RTL":"LTR"),e.readOnly=!this.isEditable(),t.appendChild(e),this.textarea=e,this.foreignObject.appendChild(t),z(e,"wheel",this,(function(t){t.stopPropagation()})),z(e,"change",this,(function(t){this.setContent(e.value)})),this.foreignObject}addResizeDom(){this.resizeGroup=st(ma.G,{class:this.RTL?"blocklyResizeSW":"blocklyResizeSE"},this.svgGroup),st(ma.POLYGON,{points:"0,8 8,8 8,0"},this.resizeGroup),st(ma.LINE,{class:"blocklyResizeLine",x1:8/3,y1:7,x2:7,y2:8/3},this.resizeGroup),st(ma.LINE,{class:"blocklyResizeLine",x1:16/3,y1:7,x2:7,y2:16/3},this.resizeGroup)}addDeleteDom(){this.deleteGroup=st(ma.G,{class:"blocklyCommentDeleteIcon"},this.svgGroup),this.deleteIconBorder=st(ma.CIRCLE,{class:"blocklyDeleteIconShape",r:"7",cx:"7.5",cy:"7.5"},this.deleteGroup),st(ma.LINE,{x1:"5",y1:"10",x2:"10",y2:"5",stroke:"#fff","stroke-width":"2"},this.deleteGroup),st(ma.LINE,{x1:"5",y1:"5",x2:"10",y2:"10",stroke:"#fff","stroke-width":"2"},this.deleteGroup)}resizeMouseDown(t){this.unbindDragEvents(),J(t)||(this.workspace.startDrag(t,new la(this.workspace.RTL?-this.width_:this.width_,this.height_)),this.onMouseUpWrapper=z(document,"pointerup",this,this.resizeMouseUp),this.onMouseMoveWrapper=z(document,"pointermove",this,this.resizeMouseMove),this.workspace.hideChaff()),t.stopPropagation()}deleteMouseDown(t){this.deleteIconBorder&&it(this.deleteIconBorder,"blocklyDeleteIconHighlighted"),t.stopPropagation()}deleteMouseOut(t){this.deleteIconBorder&&nt(this.deleteIconBorder,"blocklyDeleteIconHighlighted")}deleteMouseUp(t){this.dispose(),t.stopPropagation()}unbindDragEvents(){this.onMouseUpWrapper&&(Y(this.onMouseUpWrapper),this.onMouseUpWrapper=null),this.onMouseMoveWrapper&&(Y(this.onMouseMoveWrapper),this.onMouseMoveWrapper=null)}resizeMouseUp(t){G(),this.unbindDragEvents()}resizeMouseMove(t){this.autoLayout=!1,t=this.workspace.moveDrag(t),this.setSize(this.RTL?-t.x:t.x,t.y)}resizeComment(){const t=this.getHeightWidth(),e=uh.TOP_OFFSET;let s,i;if(null==(s=this.foreignObject)||s.setAttribute("width",String(t.width)),null==(i=this.foreignObject)||i.setAttribute("height",String(t.height-e)),this.RTL){let e;null==(e=this.foreignObject)||e.setAttribute("x",String(-t.width))}this.textarea&&(this.textarea.style.width=t.width-4+"px",this.textarea.style.height=t.height-4-e+"px")}setSize(t,e){let s,i,o,n;if(t=Math.max(t,45),e=Math.max(e,20+uh.TOP_OFFSET),this.width_=t,this.height_=e,this.svgRect_.setAttribute("width",`${t}`),this.svgRect_.setAttribute("height",`${e}`),null==(s=this.svgRectTarget)||s.setAttribute("width",`${t}`),null==(i=this.svgRectTarget)||i.setAttribute("height",`${e}`),null==(o=this.svgHandleTarget)||o.setAttribute("width",`${t}`),null==(n=this.svgHandleTarget)||n.setAttribute("height",String(uh.TOP_OFFSET)),this.RTL){let t;this.svgRect_.setAttribute("transform","scale(-1 1)"),null==(t=this.svgRectTarget)||t.setAttribute("transform","scale(-1 1)")}if(this.resizeGroup)if(this.RTL){let s;this.resizeGroup.setAttribute("transform","translate("+(8-t)+","+(e-8)+") scale(-1 1)"),null==(s=this.deleteGroup)||s.setAttribute("transform","translate("+(8-t)+","+"-8) scale(-1 1)")}else{let s;this.resizeGroup.setAttribute("transform","translate("+(t-8)+","+(e-8)+")"),null==(s=this.deleteGroup)||s.setAttribute("transform","translate("+(t-8)+","+"-8)")}this.resizeComment()}setFocus(){this.focused=!0,setTimeout((()=>{this.disposed_||(this.textarea.focus(),this.addFocus(),this.svgRectTarget&&it(this.svgRectTarget,"blocklyCommentTargetFocused"),this.svgHandleTarget&&it(this.svgHandleTarget,"blocklyCommentHandleTargetFocused"))}),0)}blurFocus(){this.focused=!1,setTimeout((()=>{this.disposed_||(this.textarea.blur(),this.removeFocus(),this.svgRectTarget&&nt(this.svgRectTarget,"blocklyCommentTargetFocused"),this.svgHandleTarget&&nt(this.svgHandleTarget,"blocklyCommentHandleTargetFocused"))}),0)}static fromXmlRendered(t,e,s){let i;Ar.disable$$module$build$src$core$events$utils();try{const o=lh.parseAttributes(t);if(i=new uh(e,o.content,o.h,o.w,o.id),e.rendered&&(i.initSvg(!0),i.render()),!isNaN(o.x)&&!isNaN(o.y))if(e.RTL){const t=s||e.getWidth();i.moveBy(t-o.x,o.y)}else i.moveBy(o.x,o.y)}finally{Ar.enable$$module$build$src$core$events$utils()}return lh.fireCreateEvent(i),i}};uh.DEFAULT_SIZE=100,uh.TOP_OFFSET=10,Q("\n.blocklyCommentForeignObject {\n position: relative;\n z-index: 0;\n}\n\n.blocklyCommentRect {\n fill: #E7DE8E;\n stroke: #bcA903;\n stroke-width: 1px;\n}\n\n.blocklyCommentTarget {\n fill: transparent;\n stroke: #bcA903;\n}\n\n.blocklyCommentTargetFocused {\n fill: none;\n}\n\n.blocklyCommentHandleTarget {\n fill: none;\n}\n\n.blocklyCommentHandleTargetFocused {\n fill: transparent;\n}\n\n.blocklyFocused>.blocklyCommentRect {\n fill: #B9B272;\n stroke: #B9B272;\n}\n\n.blocklySelected>.blocklyCommentTarget {\n stroke: #fc3;\n stroke-width: 3px;\n}\n\n.blocklyCommentDeleteIcon {\n cursor: pointer;\n fill: #000;\n display: none;\n}\n\n.blocklySelected > .blocklyCommentDeleteIcon {\n display: block;\n}\n\n.blocklyDeleteIconShape {\n fill: #000;\n stroke: #000;\n stroke-width: 1px;\n}\n\n.blocklyDeleteIconShape.blocklyDeleteIconHighlighted {\n stroke: #fc3;\n}\n");var dh=new Set,ph=new WeakSet,gh=null,bh=null,_h=0,mh={};mh.finishQueuedRenders=we,mh.queueRender=ke,mh.triggerQueuedRenders=ye;var fh={};fh.appendDomToWorkspace=Fe,fh.blockToDom=xe,fh.blockToDomWithXY=Ae,fh.clearWorkspaceAndLoadFromXml=Pe,fh.deleteNext=qe,fh.domToBlock=Ar.domToBlock$$module$build$src$core$xml,fh.domToBlockInternal=He,fh.domToPrettyText=Be,fh.domToText=Me,fh.domToVariables=Ge,fh.domToWorkspace=Ar.domToWorkspace$$module$build$src$core$xml,fh.variablesToDom=De,fh.workspaceToDom=Re;var Eh=class extends Error{},Th=class extends Eh{constructor(t){super("Expected to find a 'type' property, defining the block type"),this.state=t}},kh=class extends Eh{constructor(t,e,s){super(`The block ${e.toDevString()} is missing a(n) ${t}\nconnection`),this.block=e,this.state=s}},wh=class extends Eh{constructor(t,e,s,i){super(`The block ${s.toDevString()} could not connect its\n${e} to its parent, because: ${t}`),this.childBlock=s,this.childState=i}},yh=class extends Eh{constructor(t){super("Encountered a real block which is defined as a child of a shadow\nblock. It is an invariant of Blockly that shadow blocks only have shadow\nchildren"),this.state=t}},$h=class extends Eh{constructor(t,e,s){super(`Cannot add an icon of type '${t}' to the block ${e.toDevString()}, because there is no icon registered with type '${t}'. Make sure that all of your icons have been registered.`),this.block=e,this.state=s}},Ch={};Ch.BadConnectionCheck=wh,Ch.DeserializationError=Eh,Ch.MissingBlockType=Th,Ch.MissingConnection=kh,Ch.RealChildOfShadow=yh,Ch.UnregisteredIcon=$h;var vh={BLOCKS:50,PROCEDURES:75,VARIABLES:100},Ih={};Ih.register=es,Ih.unregister=ss;var Sh=class{constructor(){this.priority=50}save(t){const e=[];for(const s of t.getTopBlocks(!1))(t=is(s,{addCoordinates:!0,doFullSerialization:!1}))&&e.push(t);return e.length?{languageVersion:0,blocks:e}:null}load(t,e){t=t.blocks;for(const s of t)ds(s,e,{recordUndo:I()})}clear(t){for(const e of t.getTopBlocks(!1))e.dispose(!1)}};es("blocks",new Sh);var Rh={};Rh.BlockSerializer=Sh,Rh.append=ds,Rh.appendInternal=ps,Rh.save=is;var Dh=class extends $l{constructor(t){super(),this.isBlank=!t,t&&(this.blockId=t.id,this.workspaceId=t.workspace.id)}toJson(){const t=super.toJson();if(!this.blockId)throw Error("The block ID is undefined. Either pass a block to the constructor, or call fromJson");return t.blockId=this.blockId,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Dh)).blockId=t.blockId,e}},Ah=class extends Dh{constructor(t){super(t),this.type=Ar.CREATE$$module$build$src$core$events$utils,t&&(t.isShadow()&&(this.recordUndo=!1),this.xml=Ae(t),this.ids=L(t),this.json=is(t,{addCoordinates:!0}))}toJson(){const t=super.toJson();if(!this.xml)throw Error("The block XML is undefined. Either pass a block to the constructor, or call fromJson");if(!this.ids)throw Error("The block IDs are undefined. Either pass a block to the constructor, or call fromJson");if(!this.json)throw Error("The block JSON is undefined. Either pass a block to the constructor, or call fromJson");return t.xml=Me(this.xml),t.ids=this.ids,t.json=this.json,this.recordUndo||(t.recordUndo=this.recordUndo),t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Ah)).xml=Ar.textToDom$$module$build$src$core$utils$xml(t.xml),e.ids=t.ids,e.json=t.json,void 0!==t.recordUndo&&(e.recordUndo=t.recordUndo),e}run(t){const e=this.getEventWorkspace_();if(!this.json)throw Error("The block JSON is undefined. Either pass a block to the constructor, or call fromJson");if(!this.ids)throw Error("The block IDs are undefined. Either pass a block to the constructor, or call fromJson");if(!Nh(e,this.ids))if(t)ds(this.json,e);else for(t=0;tt.getBlockById(e))).filter((t=>t&&t.isShadow())).length===e.length};t(Mr.EVENT,Ar.CREATE$$module$build$src$core$events$utils,Ah);var Oh=class extends Cl{constructor(t,e){super(e),this.type=ll,this.themeName=t}toJson(){const t=super.toJson();if(!this.themeName)throw Error("The theme name is undefined. Either pass a theme name to the constructor, or call fromJson");return t.themeName=this.themeName,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Oh)).themeName=t.themeName,e}};t(Mr.EVENT,ll,Oh);var xh=class extends Cl{constructor(t,e,s,i,o){super(i),this.type=al,this.viewTop=t,this.viewLeft=e,this.scale=s,this.oldScale=o}toJson(){const t=super.toJson();if(void 0===this.viewTop)throw Error("The view top is undefined. Either pass a value to the constructor, or call fromJson");if(void 0===this.viewLeft)throw Error("The view left is undefined. Either pass a value to the constructor, or call fromJson");if(void 0===this.scale)throw Error("The scale is undefined. Either pass a value to the constructor, or call fromJson");if(void 0===this.oldScale)throw Error("The old scale is undefined. Either pass a value to the constructor, or call fromJson");return t.viewTop=this.viewTop,t.viewLeft=this.viewLeft,t.scale=this.scale,t.oldScale=this.oldScale,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new xh)).viewTop=t.viewTop,e.viewLeft=t.viewLeft,e.scale=t.scale,e.oldScale=t.oldScale,e}};t(Mr.EVENT,al,xh);var Lh;Ar.config$$module$build$src$core$config={dragRadius:5,flyoutDragRadius:10,snapRadius:28,connectingSnapRadius:28,currentConnectionPreference:8,bumpDelay:250},Ar.config$$module$build$src$core$config,function(t){t[t.INPUT_VALUE=1]="INPUT_VALUE",t[t.OUTPUT_VALUE=2]="OUTPUT_VALUE",t[t.NEXT_STATEMENT=3]="NEXT_STATEMENT",t[t.PREVIOUS_STATEMENT=4]="PREVIOUS_STATEMENT"}(Lh||(Lh={}));var Mh=class{constructor(t){this.connectionChecker=t,this.connections=[]}addConnection(t,e){e=this.calculateIndexForYPos(e),this.connections.splice(e,0,t)}findIndexOfConnection(t,e){if(!this.connections.length)return-1;const s=this.calculateIndexForYPos(e);if(s>=this.connections.length)return-1;e=t.y;let i=s;for(;0<=i&&this.connections[i].y===e;){if(this.connections[i]===t)return i;i--}for(i=s;it)){e=i;break}s=i}}return e}removeConnection(t,e){if(-1===(t=this.findIndexOfConnection(t,e)))throw Error("Unable to find connection in connectionDB.");this.connections.splice(t,1)}getNeighbours(t,e){function s(t){const s=o-i[t].x,r=n-i[t].y;return Math.sqrt(s*s+r*r)<=e&&a.push(i[t]),rt?this.menuItems.length:t,-1)}highlightFirst(){this.highlightHelper(-1,1)}highlightLast(){this.highlightHelper(this.menuItems.length,-1)}highlightHelper(t,e){let s;for(t+=e;s=this.menuItems[t];){if(s.isEnabled()){this.setHighlighted(s);break}t+=e}}handleMouseOver(t){(t=this.getMenuItem(t.target))&&(t.isEnabled()?this.highlightedItem!==t&&this.setHighlighted(t):this.setHighlighted(null))}handleClick(t){const e=this.openingCoords;if(this.openingCoords=null,e&&"number"==typeof t.clientX){const s=new la(t.clientX,t.clientY);if(1>la.distance(e,s))return}(t=this.getMenuItem(t.target))&&t.performAction()}handleMouseEnter(t){this.focus()}handleMouseLeave(t){this.getElement()&&(this.blur(),this.setHighlighted(null))}handleKeyEvent(t){if(this.menuItems.length&&!(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)){var e=this.highlightedItem;switch(t.key){case"Enter":case" ":e&&e.performAction();break;case"ArrowUp":this.highlightPrevious();break;case"ArrowDown":this.highlightNext();break;case"PageUp":case"Home":this.highlightFirst();break;case"PageDown":case"End":this.highlightLast();break;default:return}t.preventDefault(),t.stopPropagation()}}getSize(){const t=this.getElement(),e=mt(t);return e.height=t.scrollHeight,e}},jh=class{constructor(t,e){this.content=t,this.opt_value=e,this.enabled=!0,this.element=null,this.rightToLeft=!1,this.roleName=null,this.highlight=this.checked=this.checkable=!1,this.actionHandler=null}createDom(){const t=document.createElement("div");t.id=$(),this.element=t,t.className="blocklyMenuItem goog-menuitem "+(this.enabled?"":"blocklyMenuItemDisabled goog-menuitem-disabled ")+(this.checked?"blocklyMenuItemSelected goog-option-selected ":"")+(this.highlight?"blocklyMenuItemHighlight goog-menuitem-highlight ":"")+(this.rightToLeft?"blocklyMenuItemRtl goog-menuitem-rtl ":"");const e=document.createElement("div");if(e.className="blocklyMenuItemContent goog-menuitem-content",this.checkable){var s=document.createElement("div");s.className="blocklyMenuItemCheckbox goog-menuitem-checkbox",e.appendChild(s)}return s=this.content,"string"==typeof this.content&&(s=document.createTextNode(this.content)),e.appendChild(s),t.appendChild(e),this.roleName&&xs(t,this.roleName),Ls(t,Vh.SELECTED,this.checkable&&this.checked||!1),Ls(t,Vh.DISABLED,!this.enabled),t}dispose(){this.element=null}getElement(){return this.element}getId(){return this.element.id}getValue(){let t;return null!=(t=this.opt_value)?t:null}setRightToLeft(t){this.rightToLeft=t}setRole(t){this.roleName=t}setCheckable(t){this.checkable=t}setChecked(t){this.checked=t}setHighlighted(t){this.highlight=t;const e=this.getElement();e&&this.isEnabled()&&(t?(it(e,"blocklyMenuItemHighlight"),it(e,"goog-menuitem-highlight")):(nt(e,"blocklyMenuItemHighlight"),nt(e,"goog-menuitem-highlight")))}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}performAction(){this.isEnabled()&&this.actionHandler&&this.actionHandler(this)}onAction(t,e){this.actionHandler=t.bind(e)}},Zh=null,qh=null,Qh="blocklyWidgetDiv",tc="",ec="",sc={};sc.createDom=Ps,sc.getDiv=Ms,sc.hide=Hs,sc.hideIfOwner=Us,sc.isVisible=Gs,sc.positionWithAnchor=Vs,sc.repositionForWindowResize=Ks,sc.show=Fs,sc.testOnly_setDiv=Bs;var ic=null,oc={},nc=null,rc={};rc.callbackFactory=Ar.callbackFactory$$module$build$src$core$contextmenu,rc.commentDeleteOption=oi,rc.commentDuplicateOption=ni,rc.dispose=ii,rc.getCurrentBlock=Js,rc.hide=si,rc.setCurrentBlock=js,rc.show=Zs,rc.workspaceCommentOption=ri;var lc=class{constructor(){this.registry_=new Map,this.reset()}reset(){this.registry_.clear()}register(t){if(this.registry_.has(t.id))throw Error('Menu item with ID "'+t.id+'" is already registered.');this.registry_.set(t.id,t)}unregister(t){if(!this.registry_.has(t))throw Error('Menu item with ID "'+t+'" not found.');this.registry_.delete(t)}getItem(t){let e;return null!=(e=this.registry_.get(t))?e:null}getContextMenuOptions(t,e){const s=[];for(const o of this.registry_.values())if(t===o.scopeType){var i=o.preconditionFn(e);"hidden"!==i&&(i={text:"function"==typeof o.displayText?o.displayText(e):o.displayText,enabled:"enabled"===i,callback:o.callback,scope:e,weight:o.weight},s.push(i))}return s.sort((function(t,e){return t.weight-e.weight})),s}};!function(t){var e=t.ScopeType||(t.ScopeType={});e.BLOCK="block",e.WORKSPACE="workspace",t.registry=new t}(lc||(lc={}));var ac=lc.ScopeType,hc={};hc.ContextMenuRegistry=lc,hc.ScopeType=ac;var cc={};cc.clamp=hi,cc.toDegrees=ai,cc.toRadians=li;var uc,dc,pc,gc=16,bc=1,_c=12,mc=16,fc=.25,Ec=null,Tc=null,kc="",wc="",yc=null,$c=null,Cc=null,vc={getBoundsInfo:function(){const t=kt(yc),e=mt(yc);return{left:t.x,right:t.x+e.width,top:t.y,bottom:t.y+e.height,width:e.width,height:e.height}},getPositionMetrics:function(t,e,s,i){const o=vc.getBoundsInfo(),n=mt(uc);return e+n.heighto.top?yi(s,i,o,n):e+n.heightdocument.documentElement.clientTop?yi(s,i,o,n):$i(t,o,n)}},Ic={ANIMATION_TIME:fc,ARROW_HORIZONTAL_PADDING:_c,ARROW_SIZE:gc,BORDER_SIZE:bc,PADDING_Y:mc,TEST_ONLY:vc};Ic.clearContent=gi,Ic.createDom=ci,Ic.getContentDiv=pi,Ic.getOwner=di,Ic.getPositionX=Ci,Ic.hide=Si,Ic.hideIfOwner=Ii,Ic.hideWithoutAnimation=Ri,Ic.isVisible=vi,Ic.repositionForWindowResize=Ai,Ic.setBoundsElement=ui,Ic.setColour=bi,Ic.show=ki,Ic.showPositionedByBlock=_i,Ic.showPositionedByField=mi;var Sc=null,Rc=null,Dc={};Dc.connectionUiEffect=xi,Dc.disconnectUiEffect=Li,Dc.disconnectUiStop=Bi,Dc.disposeUiEffect=Ni;var Ac=100,Nc=class{constructor(t,e){this.bubble=t,this.workspace=e,this.dragTarget_=null,this.wouldDeleteBubble_=!1,this.startXY_=this.bubble.getRelativeToSurfaceXY()}startBubbleDrag(){let t;Ar.getGroup$$module$build$src$core$events$utils()||Ar.setGroup$$module$build$src$core$events$utils(!0),this.workspace.setResizesEnabled(!1),this.bubble.setAutoLayout&&this.bubble.setAutoLayout(!1),null==(t=this.workspace.getLayerManager())||t.moveToDragLayer(this.bubble),this.bubble.setDragging&&this.bubble.setDragging(!0)}dragBubble(t,e){e=this.pixelsToWorkspaceUnits_(e),e=la.sum(this.startXY_,e),this.bubble.moveDuringDrag(e),e=this.dragTarget_,this.dragTarget_=this.workspace.getDragTarget(t),t=this.wouldDeleteBubble_,this.wouldDeleteBubble_=this.shouldDelete_(this.dragTarget_),t!==this.wouldDeleteBubble_&&this.updateCursorDuringBubbleDrag_(),this.dragTarget_!==e&&(e&&e.onDragExit(this.bubble),this.dragTarget_&&this.dragTarget_.onDragEnter(this.bubble)),this.dragTarget_&&this.dragTarget_.onDragOver(this.bubble)}shouldDelete_(t){return!(!t||!this.workspace.getComponentManager().hasCapability(t.id,ia.Capability.DELETE_AREA))&&t.wouldDelete(this.bubble,!1)}updateCursorDuringBubbleDrag_(){this.bubble.setDeleteStyle(this.wouldDeleteBubble_)}endBubbleDrag(t,e){if(this.dragBubble(t,e),this.dragTarget_&&this.dragTarget_.shouldPreventMove(this.bubble)?t=this.startXY_:(t=this.pixelsToWorkspaceUnits_(e),t=la.sum(this.startXY_,t)),this.bubble.moveTo(t.x,t.y),this.dragTarget_&&this.dragTarget_.onDrop(this.bubble),this.wouldDeleteBubble_)this.fireMoveEvent_(),this.bubble.dispose();else{if(this.bubble.setDragging){let t;this.bubble.setDragging(!1),null==(t=this.workspace.getLayerManager())||t.moveOffDragLayer(this.bubble,Ac)}this.fireMoveEvent_()}this.workspace.setResizesEnabled(!0),Ar.setGroup$$module$build$src$core$events$utils(!1)}fireMoveEvent_(){if(this.bubble instanceof uh){const t=new(B(dl))(this.bubble);t.setOldCoordinate(this.startXY_),t.recordNew(),S(t)}}pixelsToWorkspaceUnits_(t){return t=new la(t.x/this.workspace.scale,t.y/this.workspace.scale),this.workspace.isMutator&&t.scale(1/this.workspace.options.parentWorkspace.scale),t}},Oc=!0,xc=[];xc[Lh.INPUT_VALUE]=Lh.OUTPUT_VALUE,xc[Lh.OUTPUT_VALUE]=Lh.INPUT_VALUE,xc[Lh.NEXT_STATEMENT]=Lh.PREVIOUS_STATEMENT,xc[Lh.PREVIOUS_STATEMENT]=Lh.NEXT_STATEMENT;var Lc="RENAME_VARIABLE_ID",Mc="DELETE_VARIABLE_ID",Bc={};Bc.commonWordPrefix=Hi,Bc.commonWordSuffix=Gi,Bc.isNumber=Ar.isNumber$$module$build$src$core$utils$string,Bc.shortestStringLength=Fi,Bc.startsWith=Pi,Bc.wrap=Ar.wrap$$module$build$src$core$utils$string;var Pc=void 0,Fc=!1,Hc=!1,Gc=50,Uc=0,Wc=0,Vc=0,zc=0,Xc=null,Yc=null,Kc=0,Jc=10,jc=10,Zc=750,qc=5,Qc=null,tu={HOVER_MS:Zc,LIMIT:Gc,MARGINS:qc,OFFSET_X:Kc,OFFSET_Y:Jc,RADIUS_OK:jc};tu.bindMouseEvents=Qi,tu.block=ro,tu.createDom=qi,tu.dispose=oo,tu.getCustomTooltip=Yi,tu.getDiv=Ji,tu.getTooltipOfObject=ji,tu.hide=no,tu.isVisible=Ki,tu.setCustomTooltip=Xi,tu.unbindMouseEvents=to,tu.unblock=lo;var eu=class{constructor(t){this.workspace=t,this.horizontalScrollEnabled_=this.workspace.isMovableHorizontally(),this.verticalScrollEnabled_=this.workspace.isMovableVertically(),this.startScrollXY_=new la(t.scrollX,t.scrollY)}dispose(){this.workspace=null}startDrag(){b()&&b().unselect()}endDrag(t){this.drag(t)}drag(t){if(t=la.sum(this.startScrollXY_,t),this.horizontalScrollEnabled_&&this.verticalScrollEnabled_)this.workspace.scroll(t.x,t.y);else if(this.horizontalScrollEnabled_)this.workspace.scroll(t.x,this.workspace.scrollY);else{if(!this.verticalScrollEnabled_)throw new TypeError("Invalid state.");this.workspace.scroll(this.workspace.scrollX,t.y)}}},su=class{constructor(t,e){this.creatorWorkspace=e,this.mouseDownXY=new la(0,0),this.startWorkspace_=this.targetBlock=this.startBlock=this.startIcon=this.startField=this.startBubble=null,this.hasExceededDragRadius=!1,this.boundEvents=[],this.flyout=this.workspaceDragger=this.blockDragger=this.bubbleDragger=null,this.isMultiTouch_=this.isEnding_=this.gestureHasStarted=this.calledUpdateIsDragging=!1,this.cachedPoints=new Map,this.startDistance=this.previousScale=0,this.currentDropdownOwner=this.isPinchZoomEnabled=null,this.mostRecentEvent=t,this.currentDragDeltaXY=new la(0,0),this.healStack=!1}dispose(){G(),lo(),this.creatorWorkspace.clearGesture();for(const t of this.boundEvents)Y(t);this.boundEvents.length=0,this.blockDragger&&this.blockDragger.dispose(),this.workspaceDragger&&this.workspaceDragger.dispose()}updateFromEvent(t){const e=new la(t.clientX,t.clientY);this.updateDragDelta(e)&&(this.updateIsDragging(),H()),this.mostRecentEvent=t}updateDragDelta(t){return this.currentDragDeltaXY=la.difference(t,this.mouseDownXY),!this.hasExceededDragRadius&&(this.hasExceededDragRadius=la.magnitude(this.currentDragDeltaXY)>(this.flyout?Ar.config$$module$build$src$core$config.flyoutDragRadius:Ar.config$$module$build$src$core$config.dragRadius))}updateIsDraggingFromFlyout(){let t;if(!this.targetBlock||null==(t=this.flyout)||!t.isBlockCreatable(this.targetBlock))return!1;if(!this.flyout.targetWorkspace)throw Error("Cannot update dragging from the flyout because the ' +\n 'flyout's target workspace is undefined");return!(this.flyout.isScrollable()&&!this.flyout.isDragTowardWorkspace(this.currentDragDeltaXY))&&(this.startWorkspace_=this.flyout.targetWorkspace,this.startWorkspace_.updateScreenCalculationsIfScrolled(),Ar.getGroup$$module$build$src$core$events$utils()||Ar.setGroup$$module$build$src$core$events$utils(!0),this.startBlock=null,this.targetBlock=this.flyout.createBlock(this.targetBlock),this.targetBlock.select(),!0)}updateIsDraggingBubble(){return!!this.startBubble&&(this.startDraggingBubble(),!0)}updateIsDraggingBlock(){if(!this.targetBlock)return!1;if(this.flyout){if(this.updateIsDraggingFromFlyout())return this.startDraggingBlock(),!0}else if(this.targetBlock.isMovable())return this.startDraggingBlock(),!0;return!1}updateIsDraggingWorkspace(){if(!this.startWorkspace_)throw Error("Cannot update dragging the workspace because the start workspace is undefined");(this.flyout?this.flyout.isScrollable():this.startWorkspace_&&this.startWorkspace_.isDraggable())&&(this.workspaceDragger=new eu(this.startWorkspace_),this.workspaceDragger.startDrag())}updateIsDragging(){if(this.calledUpdateIsDragging)throw Error("updateIsDragging_ should only be called once per gesture.");this.calledUpdateIsDragging=!0,this.updateIsDraggingBubble()||this.updateIsDraggingBlock()||this.updateIsDraggingWorkspace()}startDraggingBlock(){this.blockDragger=new(a(Mr.BLOCK_DRAGGER,this.creatorWorkspace.options,!0))(this.targetBlock,this.startWorkspace_),this.blockDragger.startDrag(this.currentDragDeltaXY,this.healStack),this.blockDragger.drag(this.mostRecentEvent,this.currentDragDeltaXY)}startDraggingBubble(){if(!this.startBubble)throw Error("Cannot update dragging the bubble because the start bubble is undefined");if(!this.startWorkspace_)throw Error("Cannot update dragging the bubble because the start workspace is undefined");this.bubbleDragger=new Nc(this.startBubble,this.startWorkspace_),this.bubbleDragger.startBubbleDrag(),this.bubbleDragger.dragBubble(this.mostRecentEvent,this.currentDragDeltaXY)}doStart(t){if(!this.startWorkspace_)throw Error("Cannot start the touch gesture becauase the start workspace is undefined");this.isPinchZoomEnabled=this.startWorkspace_.options.zoomOptions&&this.startWorkspace_.options.zoomOptions.pinch,K(t)?this.cancel():(this.gestureHasStarted=!0,Bi(),this.startWorkspace_.updateScreenCalculationsIfScrolled(),this.startWorkspace_.isMutator&&this.startWorkspace_.resize(),this.currentDropdownOwner=di(),this.startWorkspace_.hideChaff(!!this.flyout),this.startWorkspace_.markFocused(),this.mostRecentEvent=t,ro(),this.targetBlock&&this.targetBlock.select(),J(t)?this.handleRightClick(t):("pointerdown"===t.type.toLowerCase()&&"mouse"!==t.pointerType&&F(t,this),this.mouseDownXY=new la(t.clientX,t.clientY),this.healStack=t.altKey||t.ctrlKey||t.metaKey,this.bindMouseEvents(t),this.isEnding_||this.handleTouchStart(t)))}bindMouseEvents(t){this.boundEvents.push(z(document,"pointerdown",null,this.handleStart.bind(this),!0)),this.boundEvents.push(z(document,"pointermove",null,this.handleMove.bind(this),!0)),this.boundEvents.push(z(document,"pointerup",null,this.handleUp.bind(this),!0)),t.preventDefault(),t.stopPropagation()}handleStart(t){this.isDragging()||(this.handleTouchStart(t),this.isMultiTouch()&&H())}handleMove(t){this.isDragging()&&U(t)||!this.isMultiTouch()?(this.updateFromEvent(t),this.workspaceDragger?this.workspaceDragger.drag(this.currentDragDeltaXY):this.blockDragger?this.blockDragger.drag(this.mostRecentEvent,this.currentDragDeltaXY):this.bubbleDragger&&this.bubbleDragger.dragBubble(this.mostRecentEvent,this.currentDragDeltaXY),t.preventDefault(),t.stopPropagation()):this.isMultiTouch()&&(this.handleTouchMove(t),H())}handleUp(t){if(this.isDragging()||this.handleTouchEnd(t),!this.isMultiTouch()||this.isDragging()){if(!U(t))return;if(this.updateFromEvent(t),H(),this.isEnding_)return void console.log("Trying to end a gesture recursively.");this.isEnding_=!0,this.bubbleDragger?this.bubbleDragger.endBubbleDrag(t,this.currentDragDeltaXY):this.blockDragger?this.blockDragger.endDrag(t,this.currentDragDeltaXY):this.workspaceDragger?this.workspaceDragger.endDrag(this.currentDragDeltaXY):this.isBubbleClick()?this.doBubbleClick():this.isFieldClick()?this.doFieldClick():this.isIconClick()?this.doIconClick():this.isBlockClick()?this.doBlockClick():this.isWorkspaceClick()&&this.doWorkspaceClick(t)}t.preventDefault(),t.stopPropagation(),this.dispose()}handleTouchStart(t){var e=W(t);this.cachedPoints.set(e,this.getTouchPoint(t));var s=Array.from(this.cachedPoints.keys());2===s.length&&(e=this.cachedPoints.get(s[0]),s=this.cachedPoints.get(s[1]),this.startDistance=la.distance(e,s),this.isMultiTouch_=!0,t.preventDefault())}handleTouchMove(t){const e=W(t);this.cachedPoints.set(e,this.getTouchPoint(t)),this.isPinchZoomEnabled&&2===this.cachedPoints.size?this.handlePinch(t):this.handleMove(t)}handlePinch(t){var e=Array.from(this.cachedPoints.keys()),s=this.cachedPoints.get(e[0]);if(e=this.cachedPoints.get(e[1]),s=la.distance(s,e)/this.startDistance,0this.previousScale){if(e=0<(e=s-this.previousScale)?5*e:6*e,!this.startWorkspace_)throw Error("Cannot handle a pinch because the start workspace is undefined");const i=this.startWorkspace_,o=j(t,i.getParentSvg(),i.getInverseScreenCTM());i.zoom(o.x,o.y,e)}this.previousScale=s,t.preventDefault()}handleTouchEnd(t){t=W(t),this.cachedPoints.has(t)&&this.cachedPoints.delete(t),2>this.cachedPoints.size&&(this.cachedPoints.clear(),this.previousScale=0)}getTouchPoint(t){return this.startWorkspace_?new la(t.pageX,t.pageY):null}isMultiTouch(){return this.isMultiTouch_}cancel(){this.isEnding_||(H(),this.bubbleDragger?this.bubbleDragger.endBubbleDrag(this.mostRecentEvent,this.currentDragDeltaXY):this.blockDragger?this.blockDragger.endDrag(this.mostRecentEvent,this.currentDragDeltaXY):this.workspaceDragger&&this.workspaceDragger.endDrag(this.currentDragDeltaXY),this.dispose())}handleRightClick(t){this.targetBlock?(this.bringBlockToFront(),this.targetBlock.workspace.hideChaff(!!this.flyout),this.targetBlock.showContextMenu(t)):this.startBubble?this.startBubble.showContextMenu(t):this.startWorkspace_&&!this.flyout&&(this.startWorkspace_.hideChaff(),this.startWorkspace_.showContextMenu(t)),t.preventDefault(),t.stopPropagation(),this.dispose()}handleWsStart(t,e){if(this.gestureHasStarted)throw Error("Tried to call gesture.handleWsStart, but the gesture had already been started.");this.setStartWorkspace(e),this.mostRecentEvent=t,this.doStart(t)}fireWorkspaceClick(t){S(new(B(sl))(null,t.id,"workspace"))}handleFlyoutStart(t,e){if(this.gestureHasStarted)throw Error("Tried to call gesture.handleFlyoutStart, but the gesture had already been started.");this.setStartFlyout(e),this.handleWsStart(t,e.getWorkspace())}handleBlockStart(t,e){if(this.gestureHasStarted)throw Error("Tried to call gesture.handleBlockStart, but the gesture had already been started.");this.setStartBlock(e),this.mostRecentEvent=t}handleBubbleStart(t,e){if(this.gestureHasStarted)throw Error("Tried to call gesture.handleBubbleStart, but the gesture had already been started.");this.setStartBubble(e),this.mostRecentEvent=t}doBubbleClick(){this.startBubble instanceof uh&&(this.startBubble.setFocus(),this.startBubble.select())}doFieldClick(){if(!this.startField)throw Error("Cannot do a field click because the start field is undefined");this.currentDropdownOwner!==this.startField&&this.startField.showEditor(this.mostRecentEvent),this.bringBlockToFront()}doIconClick(){if(!this.startIcon)throw Error("Cannot do an icon click because the start icon is undefined");this.bringBlockToFront(),this.startIcon.onClick()}doBlockClick(){if(this.flyout&&this.flyout.autoClose){if(!this.targetBlock)throw Error("Cannot do a block click because the target block is undefined");this.targetBlock.isEnabled()&&(Ar.getGroup$$module$build$src$core$events$utils()||Ar.setGroup$$module$build$src$core$events$utils(!0),this.flyout.createBlock(this.targetBlock).scheduleSnapAndBump())}else{if(!this.startWorkspace_)throw Error("Cannot do a block click because the start workspace is undefined");const t=new(B(sl))(this.startBlock,this.startWorkspace_.id,"block");S(t)}this.bringBlockToFront(),Ar.setGroup$$module$build$src$core$events$utils(!1)}doWorkspaceClick(t){t=this.creatorWorkspace,b()&&b().unselect(),this.fireWorkspaceClick(this.startWorkspace_||t)}bringBlockToFront(){this.targetBlock&&!this.flyout&&this.targetBlock.bringToFront()}setStartField(t){if(this.gestureHasStarted)throw Error("Tried to call gesture.setStartField, but the gesture had already been started.");this.startField||(this.startField=t)}setStartIcon(t){if(this.gestureHasStarted)throw Error("Tried to call gesture.setStartIcon, but the gesture had already been started.");this.startIcon||(this.startIcon=t)}setStartBubble(t){this.startBubble||(this.startBubble=t)}setStartBlock(t){this.startBlock||this.startBubble||(this.startBlock=t,t.isInFlyout&&t!==t.getRootBlock()?this.setTargetBlock(t.getRootBlock()):this.setTargetBlock(t))}setTargetBlock(t){t.isShadow()?this.setTargetBlock(t.getParent()):this.targetBlock=t}setStartWorkspace(t){this.startWorkspace_||(this.startWorkspace_=t)}setStartFlyout(t){this.flyout||(this.flyout=t)}isBubbleClick(){return!!this.startBubble&&!this.hasExceededDragRadius}isBlockClick(){return!(!this.startBlock||this.hasExceededDragRadius||this.isFieldClick()||this.isIconClick())}isFieldClick(){return!!this.startField&&(this.startField.isClickable()&&!this.hasExceededDragRadius&&(!this.flyout||this.startField.isClickableInFlyout(this.flyout.autoClose)))}isIconClick(){if(!this.startIcon)return!1;const t=!this.flyout||!this.startIcon.isClickableInFlyout||this.startIcon.isClickableInFlyout(this.flyout.autoClose);return!this.hasExceededDragRadius&&t}isWorkspaceClick(){return!(this.startBlock||this.startBubble||this.startField||this.hasExceededDragRadius)}isDragging(){return!!this.workspaceDragger||!!this.blockDragger||!!this.bubbleDragger}hasStarted(){return this.gestureHasStarted}getInsertionMarkers(){return this.blockDragger?this.blockDragger.getInsertionMarkers():[]}getCurrentDragger(){let t,e;return null!=(e=null!=(t=this.blockDragger)?t:this.workspaceDragger)?e:this.bubbleDragger}static inProgress(){const t=c();for(let e,s=0;e=t[s];s++)if(e.currentGesture_)return!0;return!1}},iu=class{constructor(t,e){let s,i,o;this.pattern=t,this.spacing=null!=(s=e.spacing)?s:0,this.length=null!=(i=e.length)?i:1,this.line2=(this.line1=t.firstChild)&&this.line1.nextSibling,this.snapToGrid=null!=(o=e.snap)&&o}shouldSnap(){return this.snapToGrid}getSpacing(){return this.spacing}getPatternId(){return this.pattern.id}update(t){var e=this.spacing*t;this.pattern.setAttribute("width",`${e}`),this.pattern.setAttribute("height",`${e}`);let s=(e=Math.floor(this.spacing/2)+.5)-this.length/2,i=e+this.length/2;e*=t,s*=t,i*=t,this.setLineAttributes(this.line1,t,s,i,e,e),this.setLineAttributes(this.line2,t,e,e,s,i)}setLineAttributes(t,e,s,i,o,n){t&&(t.setAttribute("stroke-width",`${e}`),t.setAttribute("x1",`${s}`),t.setAttribute("y1",`${o}`),t.setAttribute("x2",`${i}`),t.setAttribute("y2",`${n}`))}moveTo(t,e){this.pattern.setAttribute("x",`${t}`),this.pattern.setAttribute("y",`${e}`)}static createDom(t,e,s){let i,o;if(t=st(ma.PATTERN,{id:"blocklyGridPattern"+t,patternUnits:"userSpaceOnUse"},s),0<(null!=(i=e.length)?i:1)&&0<(null!=(o=e.spacing)?o:0)){let s;st(ma.LINE,{stroke:e.colour},t),null!=(s=e.length)&&s&&st(ma.LINE,{stroke:e.colour},t)}else st(ma.LINE,{},t);return t}},ou=class{constructor(t){this.workspace=t,this.cursorSvg_=this.cursor_=null,this.markers=new Map,this.markerSvg_=null}registerMarker(t,e){this.markers.has(t)&&this.unregisterMarker(t),e.setDrawer(this.workspace.getRenderer().makeMarkerDrawer(this.workspace,e)),this.setMarkerSvg(e.getDrawer().createDom()),this.markers.set(t,e)}unregisterMarker(t){const e=this.markers.get(t);if(!e)throw Error("Marker with ID "+t+" does not exist. Can only unregister markers that exist.");e.dispose(),this.markers.delete(t)}getCursor(){return this.cursor_}getMarker(t){return this.markers.get(t)||null}setCursor(t){this.cursor_&&this.cursor_.getDrawer()&&this.cursor_.getDrawer().dispose(),(this.cursor_=t)&&(t=this.workspace.getRenderer().makeMarkerDrawer(this.workspace,this.cursor_),this.cursor_.setDrawer(t),this.setCursorSvg(this.cursor_.getDrawer().createDom()))}setCursorSvg(t){t?(this.workspace.getBlockCanvas().appendChild(t),this.cursorSvg_=t):this.cursorSvg_=null}setMarkerSvg(t){t?this.workspace.getBlockCanvas()&&(this.cursorSvg_?this.workspace.getBlockCanvas().insertBefore(t,this.cursorSvg_):this.workspace.getBlockCanvas().appendChild(t)):this.markerSvg_=null}updateMarkers(){this.workspace.keyboardAccessibilityMode&&this.cursorSvg_&&this.workspace.getCursor().draw()}dispose(){const t=Object.keys(this.markers);for(let e,s=0;e=t[s];s++)this.unregisterMarker(e);this.markers.clear(),this.cursor_&&(this.cursor_.dispose(),this.cursor_=null)}};ou.LOCAL_MARKER="local_marker_1";var nu={};nu.deepMerge=po;var ru=class{constructor(e,s,i,o){this.name=e,this.startHats=!1,this.blockStyles=s||Object.create(null),this.categoryStyles=i||Object.create(null),this.componentStyles=o||Object.create(null),this.fontStyle=Object.create(null),t(Mr.THEME,e,this,!0)}getClassName(){return this.name+"-theme"}setBlockStyle(t,e){this.blockStyles[t]=e}setCategoryStyle(t,e){this.categoryStyles[t]=e}getComponentStyle(t){if(!(t=this.componentStyles[t]))return null;if("string"==typeof t){const e=this.getComponentStyle(t);if(e)return e}return`${t}`}setComponentStyle(t,e){this.componentStyles[t]=e}setFontStyle(t){this.fontStyle=t}setStartHats(t){this.startHats=t}static defineTheme(t,e){t=t.toLowerCase();const s=new ru(t);let i=e.base;if(i){if("string"==typeof i){let t;i=null!=(t=r(Mr.THEME,i))?t:void 0}i instanceof ru&&(po(s,i),s.name=t)}return po(s.blockStyles,e.blockStyles),po(s.categoryStyles,e.categoryStyles),po(s.componentStyles,e.componentStyles),po(s.fontStyle,e.fontStyle),null!==e.startHats&&(s.startHats=e.startHats),s}},lu=new ru("classic",{colour_blocks:{colourPrimary:"20"},list_blocks:{colourPrimary:"260"},logic_blocks:{colourPrimary:"210"},loop_blocks:{colourPrimary:"120"},math_blocks:{colourPrimary:"230"},procedure_blocks:{colourPrimary:"290"},text_blocks:{colourPrimary:"160"},variable_blocks:{colourPrimary:"330"},variable_dynamic_blocks:{colourPrimary:"310"},hat_blocks:{colourPrimary:"330",hat:"cap"}},{colour_category:{colour:"20"},list_category:{colour:"260"},logic_category:{colour:"210"},loop_category:{colour:"120"},math_category:{colour:"230"},procedure_category:{colour:"290"},text_category:{colour:"160"},variable_category:{colour:"330"},variable_dynamic_category:{colour:"310"}}),au=class{constructor(t){this.gridPattern=null,this.getMetrics=this.setMetrics=void 0;let e=null,s=!1;var i=!1,o=!1,n=!1,r=!1,l=!1;const a=!!t.readOnly;var h;a||(e=Lt(null!=(h=t.toolbox)?h:null),s=Pt(e),i=void 0===(i=t.trashcan)?s:i,o=void 0===(o=t.collapse)?s:o,n=void 0===(n=t.comments)?s:n,r=void 0===(r=t.disable)?s:r,l=void 0===(l=t.sounds)||l);h=t.maxTrashcanContents,i?void 0===h&&(h=32):h=0;const c=!!t.rtl;let u=t.horizontalLayout;void 0===u&&(u=!1);var d="end"!==t.toolboxPosition;d=u?d?xa.TOP:xa.BOTTOM:d===c?xa.RIGHT:xa.LEFT;let p=t.css;void 0===p&&(p=!0);let g="https://blockly-demo.appspot.com/static/media/";t.media?g=t.media.endsWith("/")?t.media:t.media+"/":"path"in t&&(et("path","Nov 2014","Jul 2023","media"),g=t.path+"media/");const b=t.oneBasedIndex,_=t.renderer||"geras",m=t.plugins||{};let f,E,T,k=t.modalInputs;void 0===k&&(k=!0),this.RTL=c,this.oneBasedIndex=void 0===b||b,this.collapse=o,this.comments=n,this.disable=r,this.readOnly=a,this.maxBlocks=t.maxBlocks||1/0,this.maxInstances=null!=(f=t.maxInstances)?f:null,this.modalInputs=k,this.pathToMedia=g,this.hasCategories=s,this.moveOptions=au.parseMoveOptions_(t,s),this.hasScrollbars=!!this.moveOptions.scrollbars,this.hasTrashcan=i,this.maxTrashcanContents=h,this.hasSounds=l,this.hasCss=p,this.horizontalLayout=u,this.languageTree=e,this.gridOptions=au.parseGridOptions_(t),this.zoomOptions=au.parseZoomOptions_(t),this.toolboxPosition=d,this.theme=au.parseThemeOptions_(t),this.renderer=_,this.rendererOverrides=null!=(E=t.rendererOverrides)?E:null,this.parentWorkspace=null!=(T=t.parentWorkspace)?T:null,this.plugins=m}static parseMoveOptions_(t,e){const s=t.move||{},i={};return void 0===s.scrollbars&&void 0===t.scrollbars?i.scrollbars=e:"object"==typeof s.scrollbars?(i.scrollbars={horizontal:!!s.scrollbars.horizontal,vertical:!!s.scrollbars.vertical},i.scrollbars.horizontal&&i.scrollbars.vertical?i.scrollbars=!0:i.scrollbars.horizontal||i.scrollbars.vertical||(i.scrollbars=!1)):i.scrollbars=!!s.scrollbars||!!t.scrollbars,i.wheel=i.scrollbars&&void 0!==s.wheel?!!s.wheel:"object"==typeof i.scrollbars,i.drag=!!i.scrollbars&&(void 0===s.drag||!!s.drag),i}static parseZoomOptions_(t){t=t.zoom||{};const e={};return e.controls=void 0!==t.controls&&!!t.controls,e.wheel=void 0!==t.wheel&&!!t.wheel,e.startScale=void 0===t.startScale?1:Number(t.startScale),e.maxScale=void 0===t.maxScale?3:Number(t.maxScale),e.minScale=void 0===t.minScale?.3:Number(t.minScale),e.scaleSpeed=void 0===t.scaleSpeed?1.2:Number(t.scaleSpeed),e.pinch=void 0===t.pinch?e.wheel||e.controls:!!t.pinch,e}static parseGridOptions_(t){t=t.grid||{};const e={};return e.spacing=Number(t.spacing)||0,e.colour=t.colour||"#888",e.length=void 0===t.length?1:Number(t.length),e.snap=0")),S(new hu(e,"mutation",null,s,t));break;default:console.warn("Unknown change type: "+this.element)}}static getExtraBlockState_(t){return t.saveExtraState?(t=t.saveExtraState(!0))?JSON.stringify(t):"":t.mutationToDom&&(t=t.mutationToDom())?Me(t):""}};t(Mr.EVENT,Ar.CHANGE$$module$build$src$core$events$utils,hu);var cu=.45,uu=.65,du={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00"},pu={};pu.blend=yo,pu.getHsvSaturation=bo,pu.getHsvValue=mo,pu.hexToRgb=ko,pu.hsvToHex=wo,pu.hueToHex=$o,pu.names=du,pu.parse=Eo,pu.rgbToHex=To,pu.setHsvSaturation=_o,pu.setHsvValue=fo;var gu={};gu.checkMessageReferences=So,gu.parseBlockColour=Ro,gu.replaceMessageReferences=Io,gu.tokenizeInterpolation=vo;var bu=class{constructor(t,e,s){this.DEFAULT_VALUE=null,this.name=void 0,this.constants_=this.mouseDownWrapper_=this.textContent_=this.textElement_=this.borderRect_=this.fieldGroup_=this.markerSvg_=this.cursorSvg_=this.tooltip_=this.validator_=null,this.disposed=!1,this.maxDisplayLength=50,this.sourceBlock_=null,this.enabled_=this.visible_=this.isDirty_=!0,this.suffixField=this.prefixField=this.clickTarget_=null,this.EDITABLE=!0,this.SERIALIZABLE=!1,this.CURSOR="",this.value_="DEFAULT_VALUE"in new.target.prototype?new.target.prototype.DEFAULT_VALUE:this.DEFAULT_VALUE,this.size_=new Ea(0,0),t!==bu.SKIP_SETUP&&(s&&this.configure_(s),this.setValue(t),e&&this.setValidator(e))}configure_(t){t.tooltip&&this.setTooltip(Io(t.tooltip))}setSourceBlock(t){if(this.sourceBlock_)throw Error("Field already bound to a block");this.sourceBlock_=t}getConstants(){return!this.constants_&&this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()&&this.sourceBlock_.workspace.rendered&&(this.constants_=this.sourceBlock_.workspace.getRenderer().getConstants()),this.constants_}getSourceBlock(){return this.sourceBlock_}init(){this.fieldGroup_||(this.fieldGroup_=st(ma.G,{}),this.isVisible()||(this.fieldGroup_.style.display="none"),this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_),this.initView(),this.updateEditable(),this.setTooltip(this.tooltip_),this.bindEvents_(),this.initModel())}initView(){this.createBorderRect_(),this.createTextElement_()}initModel(){}isFullBlockField(){return!this.borderRect_}createBorderRect_(){this.borderRect_=st(ma.RECT,{rx:this.getConstants().FIELD_BORDER_RECT_RADIUS,ry:this.getConstants().FIELD_BORDER_RECT_RADIUS,x:0,y:0,height:this.size_.height,width:this.size_.width,class:"blocklyFieldRect"},this.fieldGroup_)}createTextElement_(){this.textElement_=st(ma.TEXT,{class:"blocklyText"},this.fieldGroup_),this.getConstants().FIELD_TEXT_BASELINE_CENTER&&this.textElement_.setAttribute("dominant-baseline","central"),this.textContent_=document.createTextNode(""),this.textElement_.appendChild(this.textContent_)}bindEvents_(){const t=this.getClickTarget_();if(!t)throw Error("A click target has not been set.");Qi(t),this.mouseDownWrapper_=z(t,"pointerdown",this,this.onMouseDown_)}fromXml(t){this.setValue(t.textContent)}toXml(t){return t.textContent=this.getValue(),t}saveState(t){return null!==(t=this.saveLegacyState(bu))?t:this.getValue()}loadState(t){this.loadLegacyState(bu,t)||this.setValue(t)}saveLegacyState(t){return t.prototype.saveState===this.saveState&&t.prototype.toXml!==this.toXml?((t=Ar.createElement$$module$build$src$core$utils$xml("field")).setAttribute("name",this.name||""),Ot(this.toXml(t)).replace(' xmlns="https://developers.google.com/blockly/xml"',"")):null}loadLegacyState(t,e){return t.prototype.loadState===this.loadState&&t.prototype.fromXml!==this.fromXml&&(this.fromXml(Ar.textToDom$$module$build$src$core$utils$xml(e)),!0)}dispose(){let t;Ii(this),Us(this),null!=(t=this.getSourceBlock())&&t.isDeadOrDying()||lt(this.fieldGroup_),this.disposed=!0}updateEditable(){const t=this.fieldGroup_,e=this.getSourceBlock();this.EDITABLE&&t&&e&&(this.enabled_&&e.isEditable()?(it(t,"blocklyEditableText"),nt(t,"blocklyNonEditableText"),t.style.cursor=this.CURSOR):(it(t,"blocklyNonEditableText"),nt(t,"blocklyEditableText"),t.style.cursor=""))}setEnabled(t){this.enabled_=t,this.updateEditable()}isEnabled(){return this.enabled_}isClickable(){return this.enabled_&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()&&this.showEditor_!==bu.prototype.showEditor_}isClickableInFlyout(t){return!t}isCurrentlyEditable(){return this.enabled_&&this.EDITABLE&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()}isSerializable(){let t=!1;return this.name&&(this.SERIALIZABLE?t=!0:this.EDITABLE&&(console.warn("Detected an editable field that was not serializable. Please define SERIALIZABLE property as true on all editable custom fields. Proceeding with serialization."),t=!0)),t}isVisible(){return this.visible_}setVisible(t){if(this.visible_!==t){this.visible_=t;var e=this.fieldGroup_;e&&(e.style.display=t?"block":"none")}}setValidator(t){this.validator_=t}getValidator(){return this.validator_}getSvgRoot(){return this.fieldGroup_}getBorderRect(){if(!this.borderRect_)throw Error(`The border rectangle is ${this.borderRect_}.`);return this.borderRect_}getTextElement(){if(!this.textElement_)throw Error(`The text element is ${this.textElement_}.`);return this.textElement_}getTextContent(){if(!this.textContent_)throw Error(`The text content is ${this.textContent_}.`);return this.textContent_}applyColour(){}render_(){this.textContent_&&(this.textContent_.nodeValue=this.getDisplayText_()),this.updateSize_()}showEditor(t){this.isClickable()&&this.showEditor_(t)}showEditor_(t){}repositionForWindowResize(){return!1}updateSize_(t){const e=this.getConstants();let s=2*(t=void 0!==t?t:this.isFullBlockField()?0:this.getConstants().FIELD_BORDER_RECT_X_PADDING),i=e.FIELD_TEXT_HEIGHT,o=0;this.textElement_&&(o=gt(this.textElement_,e.FIELD_TEXT_FONTSIZE,e.FIELD_TEXT_FONTWEIGHT,e.FIELD_TEXT_FONTFAMILY),s+=o),this.isFullBlockField()||(i=Math.max(i,e.FIELD_BORDER_RECT_HEIGHT)),this.size_.height=i,this.size_.width=s,this.positionTextElement_(t,o),this.positionBorderRect_()}positionTextElement_(t,e){if(this.textElement_){var s,i=this.getConstants(),o=this.size_.height/2;this.textElement_.setAttribute("x",String(null!=(s=this.getSourceBlock())&&s.RTL?this.size_.width-e-t:t)),this.textElement_.setAttribute("y",String(i.FIELD_TEXT_BASELINE_CENTER?o:o-i.FIELD_TEXT_HEIGHT/2+i.FIELD_TEXT_BASELINE))}}positionBorderRect_(){this.borderRect_&&(this.borderRect_.setAttribute("width",String(this.size_.width)),this.borderRect_.setAttribute("height",String(this.size_.height)),this.borderRect_.setAttribute("rx",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)),this.borderRect_.setAttribute("ry",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)))}getSize(){return this.isVisible()?(this.isDirty_?(this.render_(),this.isDirty_=!1):this.visible_&&0===this.size_.width&&(this.render_(),0!==this.size_.width&&console.warn("Deprecated use of setting size_.width to 0 to rerender a field. Set field.isDirty_ to true instead.")),this.size_):new Ea(0,0)}getScaledBBox(){let t;var e=this.getSourceBlock();if(!e)throw new _u;if(this.isFullBlockField()){var s=this.sourceBlock_.getHeightWidth();const i=e.workspace.scale;t=this.getAbsoluteXY_(),e=(s.width+1)*i,s=(s.height+1)*i,zl?(t.x+=1.5*i,t.y+=1.5*i):(t.x-=.5*i,t.y-=.5*i)}else s=this.borderRect_.getBoundingClientRect(),t=kt(this.borderRect_),e=s.width,s=s.height;return new fa(t.y,t.y+s,t.x,t.x+e)}onLocationChange(t){}getDisplayText_(){let t=this.getText();return t?(t.length>this.maxDisplayLength&&(t=t.substring(0,this.maxDisplayLength-2)+"…"),t=t.replace(/\s/g,bu.NBSP),this.sourceBlock_&&this.sourceBlock_.RTL&&(t+=""),t):bu.NBSP}getText(){const t=this.getText_();return String(null!==t?t:this.getValue())}getText_(){return null}markDirty(){this.isDirty_=!0,this.constants_=null}forceRerender(){this.isDirty_=!0,this.sourceBlock_&&this.sourceBlock_.rendered&&(this.sourceBlock_.queueRender(),this.sourceBlock_.bumpNeighbours())}setValue(t,e=!0){if(null!==t){var s,i=this.doClassValidation_(t);if(!((t=this.processValidation_(t,i))instanceof Error))i=null==(s=this.getValidator())?void 0:s.call(this,t),(s=this.processValidation_(t,i))instanceof Error||((t=this.sourceBlock_)&&t.disposed||((i=this.getValue())===s?this.doValueUpdate_(s):(this.doValueUpdate_(s),e&&t&&O()&&S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(t,"field",this.name||null,i,s)),this.isDirty_&&this.forceRerender())))}}processValidation_(t,e){return null===e?(this.doValueInvalid_(t),this.isDirty_&&this.forceRerender(),Error()):void 0===e?t:e}getValue(){return this.value_}doClassValidation_(t){return null==t?null:t}doValueUpdate_(t){this.value_=t,this.isDirty_=!0}doValueInvalid_(t){}onMouseDown_(t){this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()&&(t=this.sourceBlock_.workspace.getGesture(t))&&t.setStartField(this)}setTooltip(t){t||""===t||(t=this.sourceBlock_);const e=this.getClickTarget_();e?e.tooltip=t:this.tooltip_=t}getTooltip(){const t=this.getClickTarget_();return ji(t||{tooltip:this.tooltip_})}getClickTarget_(){return this.clickTarget_||this.getSvgRoot()}getAbsoluteXY_(){return kt(this.getClickTarget_())}referencesVariables(){return!1}refreshVariableName(){}getParentInput(){let t=null;const e=this.getSourceBlock();if(!e)throw new _u;const s=e.inputList;for(let i=0;ie[1]===t))?t:(this.sourceBlock_&&console.warn("Cannot set the dropdown's value to an unavailable option. Block type: "+this.sourceBlock_.type+", Field name: "+this.name+", Value: "+t),null)}doValueUpdate_(t){super.doValueUpdate_(t),t=this.getOptions(!0);for(let e,s=0;e=t[s];s++)e[1]===this.value_&&(this.selectedOption=e)}applyColour(){const t=this.sourceBlock_.style;this.borderRect_&&(this.borderRect_.setAttribute("stroke",t.colourTertiary),this.menu_?this.borderRect_.setAttribute("fill",t.colourTertiary):this.borderRect_.setAttribute("fill","transparent")),this.sourceBlock_&&this.arrow&&(this.sourceBlock_.isShadow()?this.arrow.style.fill=t.colourSecondary:this.arrow.style.fill=t.colourPrimary)}render_(){this.getTextContent().nodeValue="",this.imageElement.style.display="none";const t=this.selectedOption&&this.selectedOption[0];t&&"object"==typeof t?this.renderSelectedImage(t):this.renderSelectedText(),this.positionBorderRect_()}renderSelectedImage(t){const e=this.getSourceBlock();if(!e)throw new _u;this.imageElement.style.display="",this.imageElement.setAttributeNS(da,"xlink:href",t.src),this.imageElement.setAttribute("height",String(t.height)),this.imageElement.setAttribute("width",String(t.width));const s=Number(t.height);t=Number(t.width);var i=!!this.borderRect_;const o=Math.max(i?this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT:0,s+yu);let n;i=i?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0,n=this.svgArrow?this.positionSVGArrow(t+i,o/2-this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE/2):gt(this.arrow,this.getConstants().FIELD_TEXT_FONTSIZE,this.getConstants().FIELD_TEXT_FONTWEIGHT,this.getConstants().FIELD_TEXT_FONTFAMILY),this.size_.width=t+n+2*i,this.size_.height=o;let r=0;e.RTL?this.imageElement.setAttribute("x",`${i+n}`):(r=t+n,this.getTextElement().setAttribute("text-anchor","end"),this.imageElement.setAttribute("x",`${i}`)),this.imageElement.setAttribute("y",String(o/2-s/2)),this.positionTextElement_(r+i,t+n)}renderSelectedText(){this.getTextContent().nodeValue=this.getDisplayText_();var t=this.getTextElement();it(t,"blocklyDropdownText"),t.setAttribute("text-anchor","start");var e=!!this.borderRect_;t=Math.max(e?this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT:0,this.getConstants().FIELD_TEXT_HEIGHT);const s=gt(this.getTextElement(),this.getConstants().FIELD_TEXT_FONTSIZE,this.getConstants().FIELD_TEXT_FONTWEIGHT,this.getConstants().FIELD_TEXT_FONTFAMILY);e=e?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0;let i=0;this.svgArrow&&(i=this.positionSVGArrow(s+e,t/2-this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE/2)),this.size_.width=s+i+2*e,this.size_.height=t,this.positionTextElement_(e,s)}positionSVGArrow(t,e){if(!this.svgArrow)return 0;const s=this.getSourceBlock();if(!s)throw new _u;const i=this.borderRect_?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0,o=this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING,n=this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE;return this.svgArrow.setAttribute("transform","translate("+(s.RTL?i:t+o)+","+e+")"),n+o}getText_(){if(!this.selectedOption)return null;const t=this.selectedOption[0];return"object"==typeof t?t.alt:t}static fromJson(t){if(!t.options)throw Error("options are required for the dropdown field. The options property must be assigned an array of [humanReadableValue, languageNeutralValue] tuples.");return new this(t.options,void 0,t)}};wu.CHECKMARK_OVERHANG=25,wu.MAX_MENU_HEIGHT_VH=.45,wu.ARROW_CHAR="▾";var yu=10;No("field_dropdown",wu);var $u,Cu=class{constructor(t,e,s){this.workspace=t,this.anchor=e,this.ownerRect=s,this.size=new Ea(0,0),this.colour="#ffffff",this.disposed=!1,this.relativeLeft=this.relativeTop=0,this.svgRoot=st(ma.G,{},t.getBubbleCanvas()),t=st(ma.G,{filter:`url(#${this.workspace.getRenderer().getConstants().embossFilterId})`},this.svgRoot),this.tail=st(ma.PATH,{},t),this.background=st(ma.RECT,{class:"blocklyDraggable",x:0,y:0,rx:$u.BORDER_WIDTH,ry:$u.BORDER_WIDTH},t),this.contentContainer=st(ma.G,{},this.svgRoot),z(this.background,"pointerdown",this,this.onMouseDown)}dispose(){lt(this.svgRoot),this.disposed=!0}setAnchorLocation(t,e=!1){this.anchor=t,e?this.positionByRect(this.ownerRect):this.positionRelativeToAnchor(),this.renderTail()}setPositionRelativeToAnchor(t,e){this.relativeLeft=t,this.relativeTop=e,this.positionRelativeToAnchor(),this.renderTail()}getSize(){return this.size}setSize(t,e=!1){t.width=Math.max(t.width,$u.MIN_SIZE),t.height=Math.max(t.height,$u.MIN_SIZE),this.size=t,this.background.setAttribute("width",`${t.width}`),this.background.setAttribute("height",`${t.height}`),e?this.positionByRect(this.ownerRect):this.positionRelativeToAnchor(),this.renderTail()}getColour(){return this.colour}setColour(t){this.colour=t,this.tail.setAttribute("fill",t),this.background.setAttribute("fill",t)}onMouseDown(t){let e;null==(e=this.workspace.getGesture(t))||e.handleBubbleStart(t,this)}positionRelativeToAnchor(){let t=this.anchor.x;t=this.workspace.RTL?t-(this.relativeLeft+this.size.width):t+this.relativeLeft,this.moveTo(t,this.relativeTop+this.anchor.y)}moveTo(t,e){this.svgRoot.setAttribute("transform",`translate(${t}, ${e})`)}positionByRect(t=new fa(0,0,0,0)){var e=this.workspace.getMetricsManager().getViewMetrics(!0),s=this.getOptimalRelativeLeft(e),i=this.getOptimalRelativeTop(e);const o={x:s,y:-this.size.height-this.workspace.getRenderer().getConstants().MIN_BLOCK_HEIGHT},n={x:-this.size.width-30,y:i};i={x:t.getWidth(),y:i};var r={x:s,y:t.getHeight()};s=t.getWidth()t.width)return e;if(t=this.getWorkspaceViewRect(t),this.workspace.RTL){var s=this.anchor.x-e;s-this.size.widtht.right&&(e=-(t.right-this.anchor.x))}else{const i=(s=e+this.anchor.x)+this.size.width;st.right&&(e=t.right-this.anchor.x-this.size.width)}return e}getOptimalRelativeTop(t){let e=-this.size.height/4;if(this.size.height>t.height)return e;const s=this.anchor.y+e,i=s+this.size.height;return s<(t=this.getWorkspaceViewRect(t)).top?e=t.top-this.anchor.y:i>t.bottom&&(e=t.bottom-this.anchor.y-this.size.height),e}getWorkspaceViewRect(t){const e=t.top;let s=t.top+t.height,i=t.left;return t=t.left+t.width,s-=this.getScrollbarThickness(),this.workspace.RTL?i-=this.getScrollbarThickness():t-=this.getScrollbarThickness(),new fa(e,s,i,t)}getScrollbarThickness(){return Ca.scrollbarThickness/this.workspace.scale}renderTail(){const t=[];var e=this.size.width/2,s=this.size.height/2,i=-this.relativeLeft,o=-this.relativeTop;if(e===i&&s===o)t.push("M "+e+","+s);else{o-=s,i-=e,this.workspace.RTL&&(i*=-1);var n=Math.sqrt(o*o+i*i),r=Math.acos(i/n);0>o&&(r=2*Math.PI-r);var l=r+Math.PI/2;l>2*Math.PI&&(l-=2*Math.PI);var a=Math.sin(l);const h=Math.cos(l);let c=(this.size.width+this.size.height)/$u.TAIL_THICKNESS;c=Math.min(c,this.size.width,this.size.height)/4,i=e+(l=1-$u.ANCHOR_RADIUS/n)*i,o=s+l*o,l=e+c*h;const u=s+c*a;e-=c*h,s-=c*a,(a=r+(a=li(this.workspace.RTL?-$u.TAIL_ANGLE:$u.TAIL_ANGLE)))>2*Math.PI&&(a-=2*Math.PI),r=Math.sin(a)*n/$u.TAIL_BEND,n=Math.cos(a)*n/$u.TAIL_BEND,t.push("M"+l+","+u),t.push("C"+(l+n)+","+(u+r)+" "+i+","+o+" "+i+","+o),t.push("C"+i+","+o+" "+(e+n)+","+(s+r)+" "+e+","+s)}let h;t.push("z"),null==(h=this.tail)||h.setAttribute("d",t.join(" "))}bringToFront(){let t;const e=null==(t=this.svgRoot)?void 0:t.parentNode;return!(!this.svgRoot||(null==e?void 0:e.lastChild)===this.svgRoot)&&(null==e||e.appendChild(this.svgRoot),!0)}getRelativeToSurfaceXY(){return new la(this.workspace.RTL?-this.relativeLeft+this.anchor.x-this.size.width:this.anchor.x+this.relativeLeft,this.anchor.y+this.relativeTop)}getSvgRoot(){return this.svgRoot}moveDuringDrag(t){this.moveTo(t.x,t.y),this.relativeLeft=this.workspace.RTL?this.anchor.x-t.x-this.size.width:t.x-this.anchor.x,this.relativeTop=t.y-this.anchor.y,this.renderTail()}setDragging(t){}setDeleteStyle(t){}isDeletable(){return!1}showContextMenu(t){}};$u=Cu,Cu.BORDER_WIDTH=6,Cu.DOUBLE_BORDER=2*$u.BORDER_WIDTH,Cu.MIN_SIZE=$u.DOUBLE_BORDER,Cu.TAIL_THICKNESS=1,Cu.TAIL_ANGLE=20,Cu.TAIL_BEND=4,Cu.ANCHOR_RADIUS=8;var vu=class extends Cu{constructor(t,e,s,i){let o,n;super(e,s,i),this.workspace=e,this.anchor=s,this.ownerRect=i,this.autoLayout=!0,e=new au(t),this.validateWorkspaceOptions(e),this.svgDialog=st(ma.SVG,{x:Cu.BORDER_WIDTH,y:Cu.BORDER_WIDTH},this.contentContainer),t.parentWorkspace=this.workspace,this.miniWorkspace=this.newWorkspaceSvg(new au(t)),this.miniWorkspace.internalIsMutator=!0,t=this.miniWorkspace.createDom("blocklyMutatorBackground"),this.svgDialog.appendChild(t),e.languageTree&&(t.insertBefore(this.miniWorkspace.addFlyout(ma.G),this.miniWorkspace.getCanvas()),null==(t=this.miniWorkspace.getFlyout())||t.init(this.miniWorkspace),null==t||t.show(e.languageTree)),this.miniWorkspace.addChangeListener(this.onWorkspaceChange.bind(this)),null==(o=this.miniWorkspace.getFlyout())||null==(n=o.getWorkspace())||n.addChangeListener(this.onWorkspaceChange.bind(this)),this.updateBubbleSize()}dispose(){this.miniWorkspace.dispose(),super.dispose()}getWorkspace(){return this.miniWorkspace}addWorkspaceChangeListener(t){this.miniWorkspace.addChangeListener(t)}validateWorkspaceOptions(t){if(t.hasCategories)throw Error("The miniworkspace bubble does not support toolboxes with categories");if(t.hasTrashcan)throw Error("The miniworkspace bubble does not support trashcans");if(t.zoomOptions.controls||t.zoomOptions.wheel||t.zoomOptions.pinch)throw Error("The miniworkspace bubble does not support zooming");if(t.moveOptions.scrollbars||t.moveOptions.wheel||t.moveOptions.drag)throw Error("The miniworkspace bubble does not scrolling/moving the workspace");if(t.horizontalLayout)throw Error("The miniworkspace bubble does not support horizontal layouts")}onWorkspaceChange(){this.bumpBlocksIntoBounds(),this.updateBubbleSize()}bumpBlocksIntoBounds(){if(!this.miniWorkspace.isDragging())for(const t of this.miniWorkspace.getTopBlocks(!1)){const e=t.getRelativeToSurfaceXY();if(20>e.y&&t.moveBy(0,20-e.y),t.RTL){let s=-20;const i=this.miniWorkspace.getFlyout();i&&(s-=i.getWidth()),e.x>s&&t.moveBy(s-e.x,0)}else 20>e.x&&t.moveBy(20-e.x,0)}}updateBubbleSize(){if(!this.miniWorkspace.isDragging()){var t=this.getSize(),e=this.calculateWorkspaceSize();Math.abs(t.width-e.width)({kind:"block",type:t})))}),e}getAnchorLocation(){return la.sum(this.workspaceLocation,new la(8.5,8.5))}getBubbleOwnerRect(){const t=this.sourceBlock.getSvgRoot().getBBox();return new fa(t.y,t.y+t.height,t.x,t.x+t.width)}createRootBlock(){if(!this.sourceBlock.decompose)throw Error("Blocks with mutator icons must include a decompose method");for(var t of(this.rootBlock=this.sourceBlock.decompose(this.miniWorkspaceBubble.getWorkspace()),this.rootBlock.getDescendants(!1)))t.queueRender();let e,s,i,o;this.rootBlock.setMovable(!1),this.rootBlock.setDeletable(!1),t=null!=(o=null==(e=this.miniWorkspaceBubble)||null==(s=e.getWorkspace())||null==(i=s.getFlyout())?void 0:i.getWidth())?o:0,this.rootBlock.moveBy(this.rootBlock.RTL?-(t+16):16,16)}addSaveConnectionsListener(){this.sourceBlock.saveConnections&&this.rootBlock&&(this.saveConnectionsListener=()=>{this.sourceBlock.saveConnections&&this.rootBlock&&this.sourceBlock.saveConnections(this.rootBlock)},this.saveConnectionsListener(),this.sourceBlock.workspace.addChangeListener(this.saveConnectionsListener))}createMiniWorkspaceChangeListener(){return t=>{Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon.isIgnorableMutatorEvent(t)||this.updateWorkspacePid||(this.updateWorkspacePid=setTimeout((()=>{this.updateWorkspacePid=null,this.recomposeSourceBlock()}),0))}}static isIgnorableMutatorEvent(t){return t.isUiEvent||t.type===Ar.CREATE$$module$build$src$core$events$utils||t.type===Ar.CHANGE$$module$build$src$core$events$utils&&"disabled"===t.element}recomposeSourceBlock(){if(this.rootBlock){if(!this.sourceBlock.compose)throw Error("Blocks with mutator icons must include a compose method");var t=Ar.getGroup$$module$build$src$core$events$utils();t||Ar.setGroup$$module$build$src$core$events$utils(!0);var e=hu.getExtraBlockState_(this.sourceBlock);this.sourceBlock.compose(this.rootBlock);var s=hu.getExtraBlockState_(this.sourceBlock);e!==s&&S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(this.sourceBlock,"mutation",null,e,s)),Ar.setGroup$$module$build$src$core$events$utils(t)}}getWorkspace(){let t;return null==(t=this.miniWorkspaceBubble)?void 0:t.getWorkspace()}static reconnect(t,e,s){return et("MutatorIcon.reconnect","v10","v11","connection.reconnect"),!!t&&t.reconnect(e,s)}static findParentWs(t){return et("MutatorIcon.findParentWs","v10","v11","workspace.getRootWorkspace"),t.getRootWorkspace()}},Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon.TYPE=za.MUTATOR,Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon.WEIGHT=1;Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon;var Iu=Object.create(null),Su={allExtensions:Iu};Ar.register$$module$build$src$core$extensions("parent_tooltip_when_inline",Zo);var Ru,Du={TEST_ONLY:Su};Du.apply=Ho,Du.buildTooltipForDropdown=Ar.buildTooltipForDropdown$$module$build$src$core$extensions,Du.buildTooltipWithFieldText=Ar.buildTooltipWithFieldText$$module$build$src$core$extensions,Du.isRegistered=Fo,Du.register=Ar.register$$module$build$src$core$extensions,Du.registerMixin=Ar.registerMixin$$module$build$src$core$extensions,Du.registerMutator=Ar.registerMutator$$module$build$src$core$extensions,Du.runAfterPageLoad=Jo,Du.unregister=Po,function(t){t[t.WIN_KEY_FF_LINUX=0]="WIN_KEY_FF_LINUX",t[t.MAC_ENTER=3]="MAC_ENTER",t[t.BACKSPACE=8]="BACKSPACE",t[t.TAB=9]="TAB",t[t.NUM_CENTER=12]="NUM_CENTER",t[t.ENTER=13]="ENTER",t[t.SHIFT=16]="SHIFT",t[t.CTRL=17]="CTRL",t[t.ALT=18]="ALT",t[t.PAUSE=19]="PAUSE",t[t.CAPS_LOCK=20]="CAPS_LOCK",t[t.ESC=27]="ESC",t[t.SPACE=32]="SPACE",t[t.PAGE_UP=33]="PAGE_UP",t[t.PAGE_DOWN=34]="PAGE_DOWN",t[t.END=35]="END",t[t.HOME=36]="HOME",t[t.LEFT=37]="LEFT",t[t.UP=38]="UP",t[t.RIGHT=39]="RIGHT",t[t.DOWN=40]="DOWN",t[t.PLUS_SIGN=43]="PLUS_SIGN",t[t.PRINT_SCREEN=44]="PRINT_SCREEN",t[t.INSERT=45]="INSERT",t[t.DELETE=46]="DELETE",t[t.ZERO=48]="ZERO",t[t.ONE=49]="ONE",t[t.TWO=50]="TWO",t[t.THREE=51]="THREE",t[t.FOUR=52]="FOUR",t[t.FIVE=53]="FIVE",t[t.SIX=54]="SIX",t[t.SEVEN=55]="SEVEN",t[t.EIGHT=56]="EIGHT",t[t.NINE=57]="NINE",t[t.FF_SEMICOLON=59]="FF_SEMICOLON",t[t.FF_EQUALS=61]="FF_EQUALS",t[t.FF_DASH=173]="FF_DASH",t[t.FF_HASH=163]="FF_HASH",t[t.QUESTION_MARK=63]="QUESTION_MARK",t[t.AT_SIGN=64]="AT_SIGN",t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.J=74]="J",t[t.K=75]="K",t[t.L=76]="L",t[t.M=77]="M",t[t.N=78]="N",t[t.O=79]="O",t[t.P=80]="P",t[t.Q=81]="Q",t[t.R=82]="R",t[t.S=83]="S",t[t.T=84]="T",t[t.U=85]="U",t[t.V=86]="V",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.Z=90]="Z",t[t.META=91]="META",t[t.WIN_KEY_RIGHT=92]="WIN_KEY_RIGHT",t[t.CONTEXT_MENU=93]="CONTEXT_MENU",t[t.NUM_ZERO=96]="NUM_ZERO",t[t.NUM_ONE=97]="NUM_ONE",t[t.NUM_TWO=98]="NUM_TWO",t[t.NUM_THREE=99]="NUM_THREE",t[t.NUM_FOUR=100]="NUM_FOUR",t[t.NUM_FIVE=101]="NUM_FIVE",t[t.NUM_SIX=102]="NUM_SIX",t[t.NUM_SEVEN=103]="NUM_SEVEN",t[t.NUM_EIGHT=104]="NUM_EIGHT",t[t.NUM_NINE=105]="NUM_NINE",t[t.NUM_MULTIPLY=106]="NUM_MULTIPLY",t[t.NUM_PLUS=107]="NUM_PLUS",t[t.NUM_MINUS=109]="NUM_MINUS",t[t.NUM_PERIOD=110]="NUM_PERIOD",t[t.NUM_DIVISION=111]="NUM_DIVISION",t[t.F1=112]="F1",t[t.F2=113]="F2",t[t.F3=114]="F3",t[t.F4=115]="F4",t[t.F5=116]="F5",t[t.F6=117]="F6",t[t.F7=118]="F7",t[t.F8=119]="F8",t[t.F9=120]="F9",t[t.F10=121]="F10",t[t.F11=122]="F11",t[t.F12=123]="F12",t[t.NUMLOCK=144]="NUMLOCK",t[t.SCROLL_LOCK=145]="SCROLL_LOCK",t[t.FIRST_MEDIA_KEY=166]="FIRST_MEDIA_KEY",t[t.LAST_MEDIA_KEY=183]="LAST_MEDIA_KEY",t[t.SEMICOLON=186]="SEMICOLON",t[t.DASH=189]="DASH",t[t.EQUALS=187]="EQUALS",t[t.COMMA=188]="COMMA",t[t.PERIOD=190]="PERIOD",t[t.SLASH=191]="SLASH",t[t.APOSTROPHE=192]="APOSTROPHE",t[t.TILDE=192]="TILDE",t[t.SINGLE_QUOTE=222]="SINGLE_QUOTE",t[t.OPEN_SQUARE_BRACKET=219]="OPEN_SQUARE_BRACKET",t[t.BACKSLASH=220]="BACKSLASH",t[t.CLOSE_SQUARE_BRACKET=221]="CLOSE_SQUARE_BRACKET",t[t.WIN_KEY=224]="WIN_KEY",t[t.MAC_FF_META=224]="MAC_FF_META",t[t.MAC_WK_CMD_LEFT=91]="MAC_WK_CMD_LEFT",t[t.MAC_WK_CMD_RIGHT=93]="MAC_WK_CMD_RIGHT",t[t.WIN_IME=229]="WIN_IME",t[t.VK_NONAME=252]="VK_NONAME",t[t.PHANTOM=255]="PHANTOM"}(Ru||(Ru={}));var Au={};Au.arc=rn,Au.curve=Qo,Au.line=on,Au.lineOnAxis=nn,Au.lineTo=sn,Au.moveBy=en,Au.moveTo=tn,Au.point=qo;var Nu={};Nu.Coordinate=la,Nu.KeyCodes=Ru,Nu.Rect=fa,Nu.Size=Ea,Nu.Svg=ma,Nu.aria=Yh,Nu.array=ea,Nu.browserEvents=ta,Nu.colour=pu,Nu.deprecation=aa,Nu.dom=_a,Nu.extensions=Du,Nu.idGenerator=kl,Nu.math=cc,Nu.object=nu,Nu.parsing=gu,Nu.string=Bc,Nu.style=ka,Nu.svgMath=$a,Nu.svgPaths=Au,Nu.toolbox=Ga,Nu.userAgent=Zl,Nu.xml=Oa;var Ou={};Ou.register=ln,Ou.unregister=an;var xu=class extends Cu{constructor(t,e,s,i){super(e,s,i),this.text=t,this.workspace=e,this.anchor=s,this.ownerRect=i,this.paragraph=this.stringToSvg(t,this.contentContainer),this.updateBubbleSize()}getText(){return this.text}setText(t){this.text=t,lt(this.paragraph),this.paragraph=this.stringToSvg(t,this.contentContainer),this.updateBubbleSize()}stringToSvg(t,e){return e=this.createParagraph(e),t=this.createSpans(e,t),this.workspace.RTL&&this.rightAlignSpans(e.getBBox().width,t),e}createParagraph(t){return st(ma.TEXT,{class:"blocklyText blocklyBubbleText blocklyNoPointerEvents",y:Cu.BORDER_WIDTH},t)}createSpans(t,e){return e.split("\n").map((e=>{const s=st(ma.TSPAN,{dy:"1em",x:Cu.BORDER_WIDTH},t);return e=document.createTextNode(e),s.appendChild(e),s}))}rightAlignSpans(t,e){for(const s of e)s.setAttribute("text-anchor","end"),s.setAttribute("x",`${t+Cu.BORDER_WIDTH}`)}updateBubbleSize(){const t=this.paragraph.getBBox();this.setSize(new Ea(t.width+2*Cu.BORDER_WIDTH,t.height+2*Cu.BORDER_WIDTH),!0)}},Lu=class extends Cu{constructor(t,e,s){super(t,e,s),this.workspace=t,this.anchor=e,this.ownerRect=s,this.resizePointerMoveListener=this.resizePointerUpListener=null,this.textChangeListeners=[],this.sizeChangeListeners=[],this.text="",this.DEFAULT_SIZE=new Ea(160+Cu.DOUBLE_BORDER,80+Cu.DOUBLE_BORDER),this.MIN_SIZE=new Ea(45+Cu.DOUBLE_BORDER,20+Cu.DOUBLE_BORDER),({inputRoot:this.inputRoot,textArea:this.textArea}=this.createEditor(this.contentContainer)),this.resizeGroup=this.createResizeHandle(this.svgRoot),this.setSize(this.DEFAULT_SIZE,!0)}getText(){return this.text}setText(t){this.text=t,this.textArea.value=t,this.onTextChange()}addTextChangeListener(t){this.textChangeListeners.push(t)}addSizeChangeListener(t){this.sizeChangeListeners.push(t)}createEditor(t){t=st(ma.FOREIGNOBJECT,{x:Cu.BORDER_WIDTH,y:Cu.BORDER_WIDTH},t);const e=document.createElementNS(ua,"body");e.setAttribute("xmlns",ua),e.className="blocklyMinimalBody";const s=document.createElementNS(ua,"textarea");return s.className="blocklyCommentTextarea",s.setAttribute("dir",this.workspace.RTL?"RTL":"LTR"),e.appendChild(s),t.appendChild(e),this.bindTextAreaEvents(s),setTimeout((()=>{s.focus()}),0),{inputRoot:t,textArea:s}}bindTextAreaEvents(t){z(t,"wheel",this,(t=>{t.stopPropagation()})),z(t,"focus",this,this.onStartEdit,!0),z(t,"change",this,this.onTextChange)}createResizeHandle(t){t=st(ma.G,{class:this.workspace.RTL?"blocklyResizeSW":"blocklyResizeSE"},t);const e=2*Cu.BORDER_WIDTH;return st(ma.POLYGON,{points:`0,${e} ${e},${e} ${e},0`},t),st(ma.LINE,{class:"blocklyResizeLine",x1:e/3,y1:e-1,x2:e-1,y2:e/3},t),st(ma.LINE,{class:"blocklyResizeLine",x1:2*e/3,y1:e-1,x2:e-1,y2:2*e/3},t),z(t,"pointerdown",this,this.onResizePointerDown),t}setSize(t,e=!1){t.width=Math.max(t.width,this.MIN_SIZE.width),t.height=Math.max(t.height,this.MIN_SIZE.height);const s=t.width-Cu.DOUBLE_BORDER,i=t.height-Cu.DOUBLE_BORDER;this.inputRoot.setAttribute("width",`${s}`),this.inputRoot.setAttribute("height",`${i}`),this.textArea.style.width=s-4+"px",this.textArea.style.height=i-4+"px",this.workspace.RTL?this.resizeGroup.setAttribute("transform",`translate(${Cu.DOUBLE_BORDER}, ${i}) scale(-1 1)`):this.resizeGroup.setAttribute("transform",`translate(${s}, ${i})`),super.setSize(t,e),this.onSizeChange()}getSize(){return super.getSize()}onResizePointerDown(t){this.bringToFront(),J(t)||(this.workspace.startDrag(t,new la(this.workspace.RTL?-this.getSize().width:this.getSize().width,this.getSize().height)),this.resizePointerUpListener=z(document,"pointerup",this,this.onResizePointerUp),this.resizePointerMoveListener=z(document,"pointermove",this,this.onResizePointerMove),this.workspace.hideChaff()),t.stopPropagation()}onResizePointerUp(t){G(),this.resizePointerUpListener&&(Y(this.resizePointerUpListener),this.resizePointerUpListener=null),this.resizePointerMoveListener&&(Y(this.resizePointerMoveListener),this.resizePointerMoveListener=null)}onResizePointerMove(t){t=this.workspace.moveDrag(t),this.setSize(new Ea(this.workspace.RTL?-t.x:t.x,t.y),!1),this.onSizeChange()}onStartEdit(){this.bringToFront()&&this.textArea.focus()}onTextChange(){this.text=this.textArea.value;for(const t of this.textChangeListeners)t()}onSizeChange(){for(const t of this.sizeChangeListeners)t()}};Q("\n.blocklyCommentTextarea {\n background-color: #fef49c;\n border: 0;\n display: block;\n margin: 0;\n outline: 0;\n padding: 3px;\n resize: none;\n text-overflow: hidden;\n}\n");var Mu=class extends Eu{constructor(t){super(t),this.sourceBlock=t,this.textBubble=this.textInputBubble=null,this.text="",this.bubbleSize=new Ea(160,80),this.bubbleVisiblity=!1}getType(){return Mu.TYPE}initView(t){this.svgRoot||(super.initView(t),st(ma.CIRCLE,{class:"blocklyIconShape",r:"8",cx:"8",cy:"8"},this.svgRoot),st(ma.PATH,{class:"blocklyIconSymbol",d:"m6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.4050.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25-1.201,0.998 -1.201,1.528 -1.204,2.19z"},this.svgRoot),st(ma.RECT,{class:"blocklyIconSymbol",x:"6.8",y:"10.78",height:"2",width:"2"},this.svgRoot),it(this.svgRoot,"blockly-icon-comment"))}dispose(){let t,e;super.dispose(),null==(t=this.textInputBubble)||t.dispose(),null==(e=this.textBubble)||e.dispose()}getWeight(){return Mu.WEIGHT}getSize(){return new Ea(17,17)}applyColour(){super.applyColour();const t=this.sourceBlock.style.colourPrimary;let e,s;null==(e=this.textInputBubble)||e.setColour(t),null==(s=this.textBubble)||s.setColour(t)}updateEditable(){super.updateEditable(),this.bubbleIsVisible()&&(this.setBubbleVisible(!1),this.setBubbleVisible(!0))}onLocationChange(t){let e,s;super.onLocationChange(t),t=this.getAnchorLocation(),null==(e=this.textInputBubble)||e.setAnchorLocation(t),null==(s=this.textBubble)||s.setAnchorLocation(t)}setText(t){const e=this.text;let s,i;S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(this.sourceBlock,"comment",null,e,t)),this.text=t,null==(s=this.textInputBubble)||s.setText(this.text),null==(i=this.textBubble)||i.setText(this.text)}getText(){return this.text}setBubbleSize(t){let e;this.bubbleSize=t,null==(e=this.textInputBubble)||e.setSize(this.bubbleSize,!0)}getBubbleSize(){return this.bubbleSize}saveState(){return this.text?{text:this.text,pinned:this.bubbleIsVisible(),height:this.bubbleSize.height,width:this.bubbleSize.width}:null}loadState(t){let e,s,i,o;this.text=null!=(e=t.text)?e:"",this.bubbleSize=new Ea(null!=(s=t.width)?s:160,null!=(i=t.height)?i:80),this.bubbleVisiblity=null!=(o=t.pinned)&&o,setTimeout((()=>this.setBubbleVisible(this.bubbleVisiblity)),1)}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}onTextChange(){if(this.textInputBubble){var t=this.textInputBubble.getText();this.text!==t&&(S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(this.sourceBlock,"comment",null,this.text,t)),this.text=t)}}onSizeChange(){this.textInputBubble&&(this.bubbleSize=this.textInputBubble.getSize())}bubbleIsVisible(){return this.bubbleVisiblity}setBubbleVisible(t){t&&(this.textBubble||this.textInputBubble)||(t||this.textBubble||this.textInputBubble)&&(this.bubbleVisiblity=t,this.sourceBlock.rendered&&!this.sourceBlock.isInFlyout&&(t?(this.sourceBlock.isEditable()?this.showEditableBubble():this.showNonEditableBubble(),this.applyColour()):this.hideBubble(),S(new(B(ol))(this.sourceBlock,t,"comment"))))}showEditableBubble(){this.textInputBubble=new Lu(this.sourceBlock.workspace,this.getAnchorLocation(),this.getBubbleOwnerRect()),this.textInputBubble.setText(this.getText()),this.textInputBubble.setSize(this.bubbleSize,!0),this.textInputBubble.addTextChangeListener((()=>this.onTextChange())),this.textInputBubble.addSizeChangeListener((()=>this.onSizeChange()))}showNonEditableBubble(){this.textBubble=new xu(this.getText(),this.sourceBlock.workspace,this.getAnchorLocation(),this.getBubbleOwnerRect())}hideBubble(){let t,e;null==(t=this.textInputBubble)||t.dispose(),this.textInputBubble=null,null==(e=this.textBubble)||e.dispose(),this.textBubble=null}getAnchorLocation(){return la.sum(this.workspaceLocation,new la(8.5,8.5))}getBubbleOwnerRect(){const t=this.sourceBlock.getSvgRoot().getBBox();return new fa(t.y,t.y+t.height,t.x,t.x+t.width)}};Mu.TYPE=za.COMMENT,Mu.WEIGHT=3,ln(Mu.TYPE,Mu);var Bu=class extends Eu{constructor(t){super(t),this.sourceBlock=t,this.textMap=new Map,this.textBubble=null}getType(){return Bu.TYPE}initView(t){this.svgRoot||(super.initView(t),st(ma.PATH,{class:"blocklyIconShape",d:"M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z"},this.svgRoot),st(ma.PATH,{class:"blocklyIconSymbol",d:"m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z"},this.svgRoot),st(ma.RECT,{class:"blocklyIconSymbol",x:"7",y:"11",height:"2",width:"2"},this.svgRoot),it(this.svgRoot,"blockly-icon-warning"))}dispose(){let t;super.dispose(),null==(t=this.textBubble)||t.dispose()}getWeight(){return Bu.WEIGHT}getSize(){return new Ea(17,17)}applyColour(){let t;super.applyColour(),null==(t=this.textBubble)||t.setColour(this.sourceBlock.style.colourPrimary)}updateCollapsed(){}isShownWhenCollapsed(){return!0}onLocationChange(t){let e;super.onLocationChange(t),null==(e=this.textBubble)||e.setAnchorLocation(this.getAnchorLocation())}addMessage(t,e){if(this.textMap.get(e)===t)return this;let s;return t?this.textMap.set(e,t):this.textMap.delete(e),null==(s=this.textBubble)||s.setText(this.getText()),this}getText(){return[...this.textMap.values()].join("\n")}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}bubbleIsVisible(){return!!this.textBubble}setBubbleVisible(t){if(this.bubbleIsVisible()!==t){if(t)this.textBubble=new xu(this.getText(),this.sourceBlock.workspace,this.getAnchorLocation(),this.getBubbleOwnerRect()),this.applyColour();else{let t;null==(t=this.textBubble)||t.dispose(),this.textBubble=null}S(new(B(ol))(this.sourceBlock,t,"warning"))}}getAnchorLocation(){return la.sum(this.workspaceLocation,new la(8.5,8.5))}getBubbleOwnerRect(){const t=this.sourceBlock.getSvgRoot().getBBox();return new fa(t.y,t.y+t.height,t.x,t.x+t.width)}};Bu.TYPE=za.WARNING,Bu.WEIGHT=2;var Pu=class extends Error{constructor(t){super(`Tried to append an icon of type ${t.getType()} when an icon of that type already exists on the block. Use getIcon to access the existing icon.`),this.icon=t}},Fu={};Fu.DuplicateIconType=Pu;var Hu,Gu,Uu={};Uu.CommentIcon=Mu,Uu.Icon=Eu,Uu.IconType=za,Uu.MutatorIcon=Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon,Uu.WarningIcon=Bu,Uu.exceptions=Fu,Uu.registry=Ou,Hu="PROCEDURE",Ar.DEFAULT_ARG$$module$build$src$core$procedures="x",(Gu={CATEGORY_NAME:Hu,DEFAULT_ARG:Ar.DEFAULT_ARG$$module$build$src$core$procedures}).ObservableProcedureMap=fu,Gu.allProcedures=hn,Gu.findLegalName=Ar.findLegalName$$module$build$src$core$procedures,Gu.flyoutCategory=pn,Gu.getCallers=mn,Gu.getDefinition=Ar.getDefinition$$module$build$src$core$procedures,Gu.isNameUsed=dn,Gu.isProcedureBlock=Do,Gu.mutateCallers=Ar.mutateCallers$$module$build$src$core$procedures,Gu.mutatorOpenListener=bn,Gu.rename=Ar.rename$$module$build$src$core$procedures;var Wu=new class{constructor(){this.NONE=0,this.FIELD=1,this.HAT=2,this.ICON=4,this.SPACER=8,this.BETWEEN_ROW_SPACER=16,this.IN_ROW_SPACER=32,this.EXTERNAL_VALUE_INPUT=64,this.INPUT=128,this.INLINE_INPUT=256,this.STATEMENT_INPUT=512,this.CONNECTION=1024,this.PREVIOUS_CONNECTION=2048,this.NEXT_CONNECTION=4096,this.OUTPUT_CONNECTION=8192,this.CORNER=16384,this.LEFT_SQUARE_CORNER=32768,this.LEFT_ROUND_CORNER=65536,this.RIGHT_SQUARE_CORNER=131072,this.RIGHT_ROUND_CORNER=262144,this.JAGGED_EDGE=524288,this.ROW=1048576,this.TOP_ROW=2097152,this.BOTTOM_ROW=4194304,this.INPUT_ROW=8388608,this.LEFT_CORNER=this.LEFT_SQUARE_CORNER|this.LEFT_ROUND_CORNER,this.RIGHT_CORNER=this.RIGHT_SQUARE_CORNER|this.RIGHT_ROUND_CORNER,this.nextTypeValue_=16777216}getType(t){return Object.prototype.hasOwnProperty.call(this,t)||(this[t]=this.nextTypeValue_,this.nextTypeValue_<<=1),this[t]}isField(t){return t.type&this.FIELD}isHat(t){return t.type&this.HAT}isIcon(t){return t.type&this.ICON}isSpacer(t){return t.type&this.SPACER}isInRowSpacer(t){return t.type&this.IN_ROW_SPACER}isInput(t){return t.type&this.INPUT}isExternalInput(t){return t.type&this.EXTERNAL_VALUE_INPUT}isInlineInput(t){return t.type&this.INLINE_INPUT}isStatementInput(t){return t.type&this.STATEMENT_INPUT}isPreviousConnection(t){return t.type&this.PREVIOUS_CONNECTION}isNextConnection(t){return t.type&this.NEXT_CONNECTION}isPreviousOrNextConnection(t){return t.type&(this.PREVIOUS_CONNECTION|this.NEXT_CONNECTION)}isLeftRoundedCorner(t){return t.type&this.LEFT_ROUND_CORNER}isRightRoundedCorner(t){return t.type&this.RIGHT_ROUND_CORNER}isLeftSquareCorner(t){return t.type&this.LEFT_SQUARE_CORNER}isRightSquareCorner(t){return t.type&this.RIGHT_SQUARE_CORNER}isCorner(t){return t.type&this.CORNER}isJaggedEdge(t){return t.type&this.JAGGED_EDGE}isRow(t){return t.type&this.ROW}isBetweenRowSpacer(t){return t.type&this.BETWEEN_ROW_SPACER}isTopRow(t){return t.type&this.TOP_ROW}isBottomRow(t){return t.type&this.BOTTOM_ROW}isTopOrBottomRow(t){return t.type&(this.TOP_ROW|this.BOTTOM_ROW)}isInputRow(t){return t.type&this.INPUT_ROW}},Vu=class{constructor(t){this.centerline=this.xPos=this.height=this.width=0,this.constants_=t,this.type=Wu.NONE,this.notchOffset=this.constants_.NOTCH_OFFSET_LEFT}},zu=class{constructor(t){this.elements=[],this.xPos=this.yPos=this.widthWithConnectedBlocks=this.minWidth=this.minHeight=this.width=this.height=0,this.hasStatement=this.hasExternalInput=!1,this.statementEdge=0,this.hasJaggedEdge=this.hasDummyInput=this.hasInlineInput=!1,this.align=null,this.constants_=t,this.type=Wu.ROW,this.notchOffset=this.constants_.NOTCH_OFFSET_LEFT}getLastInput(){for(let t=this.elements.length-1;0<=t;t--){const e=this.elements[t];if(Wu.isInput(e))return e}return null}measure(){throw Error("Unexpected attempt to measure a base Row.")}startsWithElemSpacer(){return!0}endsWithElemSpacer(){return!0}getFirstSpacer(){for(let t=0;trect,`,`${t} .blocklyEditableText>rect {`,`fill: ${this.FIELD_BORDER_RECT_COLOUR};`,"fill-opacity: .6;","stroke: none;","}",`${t} .blocklyNonEditableText>text,`,`${t} .blocklyEditableText>text {`,"fill: #000;","}",`${t} .blocklyFlyoutLabelText {`,"fill: #000;","}",`${t} .blocklyText.blocklyBubbleText {`,"fill: #000;","}",`${t} .blocklyEditableText:not(.editing):hover>rect {`,"stroke: #fff;","stroke-width: 2;","}",`${t} .blocklyHtmlInput {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,`font-weight: ${this.FIELD_TEXT_FONTWEIGHT};`,"}",`${t} .blocklySelected>.blocklyPath {`,"stroke: #fc3;","stroke-width: 3px;","}",`${t} .blocklyHighlightedConnectionPath {`,"stroke: #fc3;","}",`${t} .blocklyReplaceable .blocklyPath {`,"fill-opacity: .5;","}",`${t} .blocklyReplaceable .blocklyPathLight,`,`${t} .blocklyReplaceable .blocklyPathDark {`,"display: none;","}",`${t} .blocklyInsertionMarker>.blocklyPath {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,"stroke: none;","}"]}},dd={};dd.ConstantProvider=ud,dd.isDynamicShape=En;var pd=class{constructor(t,e){this.inlinePath_=this.outlinePath_="",this.block_=t,this.info_=e,this.topLeft_=t.getRelativeToSurfaceXY(),this.constants_=e.getRenderer().getConstants()}draw(){this.drawOutline_(),this.drawInternals_(),this.block_.pathObject.setPath(this.outlinePath_+"\n"+this.inlinePath_),this.info_.RTL&&this.block_.pathObject.flipRTL(),this.recordSizeOnBlock_()}hideHiddenIcons_(){et("hideHiddenIcons_","v10","v11")}recordSizeOnBlock_(){this.block_.height=this.info_.height,this.block_.width=this.info_.widthWithChildren}drawOutline_(){this.drawTop_();for(let t=1;tt||t>this.fieldRow.length)throw Error("index "+t+" out of bounds.");return e||""===e&&s?("string"==typeof e&&(e=Ar.fromJson$$module$build$src$core$field_registry({type:"field_label",text:e})),e.setSourceBlock(this.sourceBlock),this.sourceBlock.rendered&&(e.init(),e.applyColour()),e.name=s,e.setVisible(this.isVisible()),e.prefixField&&(t=this.insertFieldAt(t,e.prefixField)),this.fieldRow.splice(t,0,e),t++,e.suffixField&&(t=this.insertFieldAt(t,e.suffixField)),this.sourceBlock.rendered&&(this.sourceBlock.queueRender(),this.sourceBlock.bumpNeighbours()),t):t}removeField(t,e){for(let e,s=0;e=this.fieldRow[s];s++)if(e.name===t)return e.dispose(),this.fieldRow.splice(s,1),this.sourceBlock.rendered&&(this.sourceBlock.queueRender(),this.sourceBlock.bumpNeighbours()),!0;if(e)return!1;throw Error('Field "'+t+'" not found.')}isVisible(){return this.visible}setVisible(t){let e=[];if(this.visible===t)return e;this.visible=t;for(let e,s=0;e=this.fieldRow[s];s++)e.setVisible(t);if(this.connection){var s=this.connection;t?e=s.startTrackingAll():s.stopTrackingAll(),(s=s.targetBlock())&&(s.getSvgRoot().style.display=t?"block":"none")}return e}markDirty(){for(let t,e=0;t=this.fieldRow[e];e++)t.markDirty()}setCheck(t){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.setCheck(t),this}setAlign(t){return this.align=t,this.sourceBlock.rendered&&this.sourceBlock.queueRender(),this}setShadowDom(t){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.setShadowDom(t),this}getShadowDom(){if(!this.connection)throw Error("This input does not have a connection.");return this.connection.getShadowDom()}init(){if(this.sourceBlock.workspace.rendered)for(let t=0;t{xi(s.getSourceBlock()),setTimeout((()=>{i.bringToFront()}),0)}))}}}update(t,e){const s=this.getCandidate(t);((this.wouldDeleteBlock=this.shouldDelete(!!s,e))||this.shouldUpdatePreviews(s,t))&&(Ar.disable$$module$build$src$core$events$utils(),this.maybeHidePreview(s),this.maybeShowPreview(s),Ar.enable$$module$build$src$core$events$utils())}createMarkerBlock(t){var e=t.type;let s;Ar.disable$$module$build$src$core$events$utils();try{if(s=this.workspace.newBlock(e),s.setInsertionMarker(!0),t.saveExtraState){var i=t.saveExtraState(!0);i&&s.loadExtraState&&s.loadExtraState(i)}else if(t.mutationToDom){const e=t.mutationToDom();e&&s.domToMutation&&s.domToMutation(e)}for(e=0;e{let t,e;null==(t=o)||t.positionNearConnection(l,n,r),null==(e=o)||e.getSvgRoot().setAttribute("visibility","visible")})),this.markerConnection=i}hideInsertionMarker(){if(this.markerConnection){var t,e=this.markerConnection,s=e.getSourceBlock(),i=s.outputConnection;if(null!=(t=s.previousConnection)&&t.targetConnection||null!=i&&i.targetConnection)s.unplug(!0);else{let t;null==(t=e.targetBlock())||t.unplug(!1)}if(e.targetConnection)throw Error("markerConnection still connected at the end of disconnectInsertionMarker");this.markerConnection=null,(e=s.getSvgRoot())&&e.setAttribute("visibility","hidden")}}showInsertionInputOutline(t){t=t.closest,this.highlightedBlock=t.getSourceBlock(),this.highlightedBlock.highlightShapeForInput(t,!0)}hideInsertionInputOutline(){if(this.highlightedBlock){if(!this.activeCandidate)throw Error("Cannot hide the insertion marker outline because there is no active candidate");this.highlightedBlock.highlightShapeForInput(this.activeCandidate.closest,!1),this.highlightedBlock=null}}showReplacementFade(t){if(this.fadedBlock=t.closest.targetBlock(),!this.fadedBlock)throw Error("Cannot show the replacement fade because the closest connection does not have a target block");this.fadedBlock.fadeForReplacement(!0)}hideReplacementFade(){this.fadedBlock&&(this.fadedBlock.fadeForReplacement(!1),this.fadedBlock=null)}getInsertionMarkers(){const t=[];return this.firstMarker&&t.push(this.firstMarker),this.lastMarker&&t.push(this.lastMarker),t}disposeInsertionMarker(t){if(t){Ar.disable$$module$build$src$core$events$utils();try{t.dispose()}finally{Ar.enable$$module$build$src$core$events$utils()}}}};!function(t){(t=t.PREVIEW_TYPE||(t.PREVIEW_TYPE={}))[t.INSERTION_MARKER=0]="INSERTION_MARKER",t[t.INPUT_OUTLINE=1]="INPUT_OUTLINE",t[t.REPLACEMENT_FADE=2]="REPLACEMENT_FADE"}(Rd||(Rd={}));var Dd=Rd.PREVIEW_TYPE,Ad={};Ad.InsertionMarkerManager=Rd,Ad.PreviewType=Dd;var Nd=class{constructor(t){this.overrides=null,this.name=t}getClassName(){return this.name+"-renderer"}init(t,e){this.constants_=this.makeConstants_(),e&&(this.overrides=e,Object.assign(this.constants_,e)),this.constants_.setTheme(t),this.constants_.init()}createDom(t,e){this.constants_.createDom(t,this.name+"-"+e.name,"."+this.getClassName()+"."+e.getClassName())}refreshDom(t,e){const s=this.getConstants();s.dispose(),this.constants_=this.makeConstants_(),this.overrides&&Object.assign(this.constants_,this.overrides),this.constants_.randomIdentifier=s.randomIdentifier,this.constants_.setTheme(e),this.constants_.init(),this.createDom(t,e)}dispose(){this.constants_&&this.constants_.dispose()}makeConstants_(){return new ud}makeRenderInfo_(t){return new Ed(this,t)}makeDrawer_(t,e){return new pd(t,e)}makeMarkerDrawer(t,e){return new wd(t,this.getConstants(),e)}makePathObject(t,e){return new yd(t,e,this.constants_)}getConstants(){return this.constants_}shouldHighlightConnection(t){return!0}orphanCanConnectAtEnd(t,e,s){return!!$d.getConnectionForOrphanedConnection(t,s===Lh.OUTPUT_VALUE?e.outputConnection:e.previousConnection)}getConnectionPreviewMethod(t,e,s){return e.type===Lh.OUTPUT_VALUE||e.type===Lh.PREVIOUS_STATEMENT?!t.isConnected()||this.orphanCanConnectAtEnd(s,t.targetBlock(),e.type)?Rd.PREVIEW_TYPE.INSERTION_MARKER:Rd.PREVIEW_TYPE.REPLACEMENT_FADE:Rd.PREVIEW_TYPE.INSERTION_MARKER}render(t){const e=this.makeRenderInfo_(t);e.measure(),this.makeDrawer_(t,e).draw()}},Od={};Od.BottomRow=Xu,Od.Connection=Yu,Od.ConstantProvider=ud,Od.Drawer=pd,Od.ExternalValueInput=Ju,Od.Field=ju,Od.Hat=Zu,Od.Icon=qu,Od.InRowSpacer=Qu,Od.InlineInput=td,Od.InputConnection=Ku,Od.InputRow=sd,Od.JaggedEdge=id,Od.MarkerSvg=wd,Od.Measurable=Vu,Od.NextConnection=od,Od.OutputConnection=nd,Od.PathObject=yd,Od.PreviousConnection=rd,Od.RenderInfo=Ed,Od.Renderer=Nd,Od.RoundCorner=ld,Od.Row=zu,Od.SpacerRow=ad,Od.SquareCorner=hd,Od.StatementInput=ed,Od.TopRow=cd,Od.Types=Wu,Od.init=vn,Od.register=$n,Od.unregister=Cn;var xd=class{constructor(t,e){this.workspace=t,this.theme=e,this.subscribedWorkspaces_=[],this.componentDB=new Map}getTheme(){return this.theme}setTheme(t){var e=this.theme;this.theme=t,(t=this.workspace.getInjectionDiv())&&(e&&(e=e.getClassName())&&nt(t,e),(e=this.theme.getClassName())&&it(t,e));for(let t,e=0;t=this.subscribedWorkspaces_[e];e++)t.refreshTheme();for(const[s,i]of this.componentDB)for(const o of i){t=o.element,e=o.propertyName;const i=this.theme&&this.theme.getComponentStyle(s);t.style.setProperty(e,i||"")}for(const t of this.subscribedWorkspaces_)t.hideChaff()}subscribeWorkspace(t){this.subscribedWorkspaces_.push(t)}unsubscribeWorkspace(t){if(!q(this.subscribedWorkspaces_,t))throw Error("Cannot unsubscribe a workspace that hasn't been subscribed.")}subscribe(t,e,s){this.componentDB.has(e)||this.componentDB.set(e,[]),this.componentDB.get(e).push({element:t,propertyName:s}),e=this.theme&&this.theme.getComponentStyle(e),t.style.setProperty(s,e||"")}unsubscribe(t){if(t)for(const[e,s]of this.componentDB){for(let e=s.length-1;0<=e;e--)s[e].element===t&&s.splice(e,1);s.length||this.componentDB.delete(e)}}dispose(){this.subscribedWorkspaces_.length=0,this.componentDB.clear()}},Ld="VARIABLE_DYNAMIC",Md={CATEGORY_NAME:Ld};Md.flyoutCategory=Dn,Md.flyoutCategoryBlocks=An,Md.onCreateVariableButtonClick_Colour=Rn,Md.onCreateVariableButtonClick_Number=Sn,Md.onCreateVariableButtonClick_String=In;var Bd=class{canConnect(t,e,s,i){return this.canConnectWithReason(t,e,s,i)===$d.CAN_CONNECT}canConnectWithReason(t,e,s,i){const o=this.doSafetyChecks(t,e);return o!==$d.CAN_CONNECT?o:this.doTypeChecks(t,e)?s&&!this.doDragChecks(t,e,i||0)?$d.REASON_DRAG_CHECKS_FAILED:$d.CAN_CONNECT:$d.REASON_CHECKS_FAILED}getErrorMessage(t,e,s){switch(t){case $d.REASON_SELF_CONNECTION:return"Attempted to connect a block to itself.";case $d.REASON_DIFFERENT_WORKSPACES:return"Blocks not on same workspace.";case $d.REASON_WRONG_TYPE:return"Attempt to connect incompatible types.";case $d.REASON_TARGET_NULL:return"Target connection is null.";case $d.REASON_CHECKS_FAILED:return"Connection checks failed. "+e+" expected "+e.getCheck()+", found "+s.getCheck();case $d.REASON_SHADOW_PARENT:return"Connecting non-shadow to shadow block.";case $d.REASON_DRAG_CHECKS_FAILED:return"Drag checks failed.";case $d.REASON_PREVIOUS_AND_OUTPUT:return"Block would have an output and a previous connection.";default:return"Unknown connection failure: this should never happen!"}}doSafetyChecks(t,e){if(!t||!e)return $d.REASON_TARGET_NULL;let s,i,o;return t.isSuperior()?(s=t.getSourceBlock(),i=e.getSourceBlock(),o=e):(i=t.getSourceBlock(),s=e.getSourceBlock(),o=t,t=e),s===i?$d.REASON_SELF_CONNECTION:o.type!==xc[t.type]?$d.REASON_WRONG_TYPE:s.workspace!==i.workspace?$d.REASON_DIFFERENT_WORKSPACES:s.isShadow()&&!i.isShadow()?$d.REASON_SHADOW_PARENT:o.type===Lh.OUTPUT_VALUE&&i.previousConnection&&i.previousConnection.isConnected()||o.type===Lh.PREVIOUS_STATEMENT&&i.outputConnection&&i.outputConnection.isConnected()?$d.REASON_PREVIOUS_AND_OUTPUT:$d.CAN_CONNECT}doTypeChecks(t,e){if(t=t.getCheck(),e=e.getCheck(),!t||!e)return!0;for(let s=0;ss||e.getSourceBlock().isInsertionMarker())return!1;switch(e.type){case Lh.PREVIOUS_STATEMENT:return this.canConnectToPrevious_(t,e);case Lh.OUTPUT_VALUE:if(e.isConnected()&&!e.targetBlock().isInsertionMarker()||t.isConnected())return!1;break;case Lh.INPUT_VALUE:if(e.isConnected()&&!e.targetBlock().isMovable()&&!e.targetBlock().isShadow())return!1;break;case Lh.NEXT_STATEMENT:if(e.isConnected()&&!t.getSourceBlock().nextConnection&&!e.targetBlock().isShadow()&&e.targetBlock().nextConnection||e.targetBlock()&&!e.targetBlock().isMovable()&&!e.targetBlock().isShadow())return!1;break;default:return!1}return-1===Wr.indexOf(e)}canConnectToPrevious_(t,e){return!t.targetConnection&&-1===Wr.indexOf(e)&&(!e.targetConnection||!!(t=e.targetBlock()).isInsertionMarker()&&!t.getPreviousBlock())}};t(Mr.CONNECTION_CHECKER,Lr,Bd);var Pd=class extends th{constructor(t){super(t),this.type=Zr,t&&(this.varType=t.type,this.varName=t.name)}toJson(){const t=super.toJson();if(void 0===this.varType)throw Error("The var type is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson");return t.varType=this.varType,t.varName=this.varName,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Pd)).varType=t.varType,e.varName=t.varName,e}run(t){const e=this.getEventWorkspace_();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.varName)throw Error("The var name is undefined. Either pass a variable to the constructor, or call fromJson");t?e.deleteVariableById(this.varId):e.createVariable(this.varName,this.varType,this.varId)}};t(Mr.EVENT,Zr,Pd);var Fd=class extends th{constructor(t,e){super(t),this.type=qr,t&&(this.oldName=t.name,this.newName=void 0===e?"":e)}toJson(){const t=super.toJson();if(!this.oldName)throw Error("The old var name is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.newName)throw Error("The new var name is undefined. Either pass a value to the constructor, or call fromJson");return t.oldName=this.oldName,t.newName=this.newName,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Fd)).oldName=t.oldName,e.newName=t.newName,e}run(t){const e=this.getEventWorkspace_();if(!this.varId)throw Error("The var ID is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.oldName)throw Error("The old var name is undefined. Either pass a variable to the constructor, or call fromJson");if(!this.newName)throw Error("The new var name is undefined. Either pass a value to the constructor, or call fromJson");t?e.renameVariableById(this.varId,this.newName):e.renameVariableById(this.varId,this.oldName)}};t(Mr.EVENT,qr,Fd);var Hd=class{constructor(t){this.workspace=t,this.variableMap=new Map}clear(){for(const t of this.variableMap.values())for(;0{t&&e&&this.deleteVariableInternal(e,i)}))):this.deleteVariableInternal(e,i)}else console.warn("Can't delete non-existent variable: "+t)}deleteVariableInternal(t,e){const s=Ar.getGroup$$module$build$src$core$events$utils();s||Ar.setGroup$$module$build$src$core$events$utils(!0);try{for(let t=0;tt.name))}getVariableUsesById(t){const e=[],s=this.workspace.getAllBlocks(!1);for(let i=0;ithis.remainingCapacityOfType(s))return!1;e+=t[s]}return!(e>this.remainingCapacity())}hasBlockLimits(){return 1/0!==this.options.maxBlocks||!!this.options.maxInstances}getUndoStack(){return this.undoStack_}getRedoStack(){return this.redoStack_}undo(t){var e=t?this.redoStack_:this.undoStack_,s=t?this.undoStack_:this.redoStack_;const i=e.pop();if(i){for(var o=[i];e.length&&i.group&&i.group===e[e.length-1].group;){const t=e.pop();t&&o.push(t)}for(e=0;ethis.MAX_UNDO&&0<=this.MAX_UNDO;)this.undoStack_.shift();for(let e=0;et[0]-e[0]));for(const[n,r]of o)if(t{},document.body.addEventListener("wheel",this.dummyWheelListener),z(this.svgGroup_,"wheel",this,this.onMouseWheel_)),this.options.hasCategories&&(this.toolbox_=new(a(Mr.TOOLBOX,this.options,!0))(this)),this.grid&&this.grid.update(this.scale),this.recordDragTargets(),(t=a(Mr.CURSOR,this.options))&&this.markerManager.setCursor(new t),this.renderer.createDom(this.svgGroup_,this.getTheme()),this.svgGroup_}dispose(){if(this.rendered=!1,this.currentGesture_&&this.currentGesture_.cancel(),this.svgGroup_&<(this.svgGroup_),this.toolbox_&&(this.toolbox_.dispose(),this.toolbox_=null),this.flyout&&(this.flyout.dispose(),this.flyout=null),this.trashcan&&(this.trashcan.dispose(),this.trashcan=null),this.scrollbar&&(this.scrollbar.dispose(),this.scrollbar=null),this.zoomControls_&&this.zoomControls_.dispose(),this.audioManager&&this.audioManager.dispose(),this.grid&&(this.grid=null),this.renderer.dispose(),this.markerManager&&this.markerManager.dispose(),super.dispose(),this.themeManager_&&(this.themeManager_.unsubscribeWorkspace(this),this.themeManager_.unsubscribe(this.svgBackground_),this.options.parentWorkspace||this.themeManager_.dispose()),this.connectionDBList.length=0,this.toolboxCategoryCallbacks.clear(),this.flyoutButtonCallbacks.clear(),!this.options.parentWorkspace){const t=this.getParentSvg();t&&t.parentNode&<(t.parentNode)}this.resizeHandlerWrapper&&(Y(this.resizeHandlerWrapper),this.resizeHandlerWrapper=null),this.dummyWheelListener&&(document.body.removeEventListener("wheel",this.dummyWheelListener),this.dummyWheelListener=null)}addTrashcan(){this.trashcan=Vd.newTrashcan(this);const t=this.trashcan.createDom();this.svgGroup_.insertBefore(t,this.getCanvas())}static newTrashcan(t){throw Error("The implementation of newTrashcan should be monkey-patched in by blockly.ts")}addZoomControls(){this.zoomControls_=new Va(this);const t=this.zoomControls_.createDom();this.svgGroup_.appendChild(t)}addFlyout(t){const e=new au({parentWorkspace:this,rtl:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,renderer:this.options.renderer,rendererOverrides:this.options.rendererOverrides,move:{scrollbars:!0}});return e.toolboxPosition=this.options.toolboxPosition,this.flyout=this.horizontalLayout?new(a(Mr.FLYOUTS_HORIZONTAL_TOOLBOX,this.options,!0))(e):new(a(Mr.FLYOUTS_VERTICAL_TOOLBOX,this.options,!0))(e),this.flyout.autoClose=!1,this.flyout.getWorkspace().setVisible(!0),this.flyout.createDom(t)}getFlyout(t){return this.flyout||t?this.flyout:this.toolbox_?this.toolbox_.getFlyout():null}getToolbox(){return this.toolbox_}updateScreenCalculations_(){this.updateInverseScreenCTM(),this.recordDragTargets()}resizeContents(){this.resizesEnabled&&this.rendered&&(this.scrollbar&&this.scrollbar.resize(),this.updateInverseScreenCTM())}resize(){this.toolbox_&&this.toolbox_.position(),this.flyout&&this.flyout.position();const t=this.componentManager.getComponents(ia.Capability.POSITIONABLE,!0),e=this.getMetricsManager().getUiMetrics(),s=[];for(let i,o=0;i=t[o];o++){i.position(e,s);const t=i.getBoundingRectangle();t&&s.push(t)}this.scrollbar&&this.scrollbar.resize(),this.updateScreenCalculations_()}updateScreenCalculationsIfScrolled(){const t=Rt();la.equals(this.lastRecordedPageScroll,t)||(this.lastRecordedPageScroll=t,this.updateScreenCalculations_())}getLayerManager(){return this.layerManager}getCanvas(){return this.layerManager.getBlockLayer()}setCachedParentSvgSize(t,e){const s=this.getParentSvg();null!=t&&(this.cachedParentSvgSize.width=t,s.setAttribute("data-cached-width",`${t}`)),null!=e&&(this.cachedParentSvgSize.height=e,s.setAttribute("data-cached-height",`${e}`))}getBubbleCanvas(){return this.layerManager.getBubbleLayer()}getParentSvg(){if(!this.cachedParentSvg){let t=this.svgGroup_;for(;t;){if("svg"===t.tagName){this.cachedParentSvg=t;break}t=t.parentNode}}return this.cachedParentSvg}maybeFireViewportChangeEvent(){if(O()){var t=this.scale,e=-this.scrollY,s=-this.scrollX;if(!(t===this.oldScale&&1>Math.abs(e-this.oldTop)&&1>Math.abs(s-this.oldLeft))){var i=new(B(al))(e,s,t,this.id,this.oldScale);this.oldScale=t,this.oldTop=e,this.oldLeft=s,S(i)}}}translate(t,e){let s,i;null==(s=this.layerManager)||s.translateLayers(new la(t,e),this.scale),null==(i=this.grid)||i.moveTo(t,e),this.maybeFireViewportChangeEvent()}getWidth(){const t=this.getMetrics();return t?t.viewWidth/this.scale:0}setVisible(t){this.isVisible_=t,this.svgGroup_&&(this.scrollbar&&this.scrollbar.setContainerVisible(t),this.getFlyout()&&this.getFlyout().setContainerVisible(t),this.getParentSvg().style.display=t?"block":"none",this.toolbox_&&this.toolbox_.setVisible(t),t||this.hideChaff(!0))}render(){for(var t=this.getAllBlocks(!1),e=t.length-1;0<=e;e--)t[e].queueRender();if(this.currentGesture_)for(t=this.currentGesture_.getInsertionMarkers(),e=0;e{this.markerManager.updateMarkers()}))}highlightBlock(t,e){if(void 0===e){for(let t,e=0;t=this.highlightedBlocks[e];e++)t.setHighlighted(!1);this.highlightedBlocks.length=0}(t=t?this.getBlockById(t):null)&&((e=void 0===e||e)?-1===this.highlightedBlocks.indexOf(t)&&this.highlightedBlocks.push(t):q(this.highlightedBlocks,t),t.setHighlighted(e))}paste(t){if(et("Blockly.WorkspaceSvg.prototype.paste","v10","v11","Blockly.clipboard.paste"),!this.rendered||!t.type&&!t.tagName)return null;this.currentGesture_&&this.currentGesture_.cancel();const e=Ar.getGroup$$module$build$src$core$events$utils();let s;e||Ar.setGroup$$module$build$src$core$events$utils(!0);try{s=t.type?this.pasteBlock_(null,t):"comment"===t.tagName.toLowerCase()?this.pasteWorkspaceComment_(t):this.pasteBlock_(t,null)}finally{Ar.setGroup$$module$build$src$core$events$utils(e)}return s}pasteBlock_(t,e){let s;Ar.disable$$module$build$src$core$events$utils();try{let i=0,o=0;if(t){let e,n;s=He(t,this),i=parseInt(null!=(e=t.getAttribute("x"))?e:"0"),this.RTL&&(i=-i),o=parseInt(null!=(n=t.getAttribute("y"))?n:"0")}else e&&(s=ds(e,this),i=e.x||10,this.RTL&&(i=this.getWidth()-i),o=e.y||10);if(!isNaN(i)&&!isNaN(o)){let t;do{t=!1;const e=this.getAllBlocks(!1);for(let s,n=0;s=e[n];n++){const e=s.getRelativeToSurfaceXY();if(1>=Math.abs(i-e.x)&&1>=Math.abs(o-e.y)){t=!0;break}}if(!t){const e=s.getConnections_(!1);for(let s,n=0;s=e[n];n++)if(s.closest(Ar.config$$module$build$src$core$config.snapRadius,new la(i,o)).connection){t=!0;break}}t&&(i=this.RTL?i-Ar.config$$module$build$src$core$config.snapRadius:i+Ar.config$$module$build$src$core$config.snapRadius,o+=2*Ar.config$$module$build$src$core$config.snapRadius)}while(t);s.moveTo(new la(i,o))}}finally{Ar.enable$$module$build$src$core$events$utils()}return O()&&!s.isShadow()&&S(new(B(Ar.CREATE$$module$build$src$core$events$utils))(s)),s.select(),s}pasteWorkspaceComment_(t){let e;Ar.disable$$module$build$src$core$events$utils();try{e=uh.fromXmlRendered(t,this);let s,i,o=parseInt(null!=(s=t.getAttribute("x"))?s:"0"),n=parseInt(null!=(i=t.getAttribute("y"))?i:"0");isNaN(o)||isNaN(n)||(this.RTL&&(o=-o),e.moveBy(o+50,n+50))}finally{Ar.enable$$module$build$src$core$events$utils()}return O()&&lh.fireCreateEvent(e),e.select(),e}refreshToolboxSelection(){const t=this.isFlyout?this.targetWorkspace:this;t&&!t.currentGesture_&&t.toolbox_&&t.toolbox_.getFlyout()&&t.toolbox_.refreshSelection()}renameVariableById(t,e){super.renameVariableById(t,e),this.refreshToolboxSelection()}deleteVariableById(t){super.deleteVariableById(t),this.refreshToolboxSelection()}createVariable(t,e,s){return t=super.createVariable(t,e,s),this.refreshToolboxSelection(),t}recordDragTargets(){const t=this.componentManager.getComponents(ia.Capability.DRAG_TARGET,!0);this.dragTargetAreas=[];for(let e,s=0;e=t[s];s++){const t=e.getClientRect();t&&this.dragTargetAreas.push({component:e,clientRect:t})}}newBlock(t,e){throw Error("The implementation of newBlock should be monkey-patched in by blockly.ts")}getDragTarget(t){for(let e,s=0;e=this.dragTargetAreas[s];s++)if(e.clientRect.contains(t.clientX,t.clientY))return e.component;return null}onMouseDown_(t){const e=this.getGesture(t);e&&e.handleWsStart(t,this)}startDrag(t,e){(t=j(t,this.getParentSvg(),this.getInverseScreenCTM())).x/=this.scale,t.y/=this.scale,this.dragDeltaXY=la.difference(e,t)}moveDrag(t){return(t=j(t,this.getParentSvg(),this.getInverseScreenCTM())).x/=this.scale,t.y/=this.scale,la.sum(this.dragDeltaXY,t)}isDragging(){return null!==this.currentGesture_&&this.currentGesture_.isDragging()}isDraggable(){return this.options.moveOptions&&this.options.moveOptions.drag}isMovable(){return this.options.moveOptions&&!!this.options.moveOptions.scrollbars||this.options.moveOptions&&this.options.moveOptions.wheel||this.options.moveOptions&&this.options.moveOptions.drag||this.options.zoomOptions&&this.options.zoomOptions.wheel||this.options.zoomOptions&&this.options.zoomOptions.pinch}isMovableHorizontally(){const t=!!this.scrollbar;return this.isMovable()&&(!t||t&&this.scrollbar.canScrollHorizontally())}isMovableVertically(){const t=!!this.scrollbar;return this.isMovable()&&(!t||t&&this.scrollbar.canScrollVertically())}onMouseWheel_(t){if(su.inProgress())t.preventDefault(),t.stopPropagation();else{var e=this.options.zoomOptions&&this.options.zoomOptions.wheel,s=this.options.moveOptions&&this.options.moveOptions.wheel;if(e||s){var i=Z(t);if(Jl)var o=t.metaKey;e&&(t.ctrlKey||o||!s)?(i=-i.y/50,e=j(t,this.getParentSvg(),this.getInverseScreenCTM()),this.zoom(e.x,e.y,i)):(e=this.scrollX-i.x,s=this.scrollY-i.y,t.shiftKey&&!i.x&&(e=this.scrollX-i.y,s=this.scrollY),this.scroll(e,s)),t.preventDefault()}}}getBlocksBoundingBox(){const t=this.getTopBoundedElements();if(!t.length)return new fa(0,0,0,0);const e=t[0].getBoundingRectangle();for(let i=1;ie.bottom&&(e.bottom=s.bottom),s.lefte.right&&(e.right=s.right))}return e}cleanUp(){this.setResizesEnabled(!1),Ar.setGroup$$module$build$src$core$events$utils(!0);const t=this.getTopBlocks(!0);let e=0;for(let s,i=0;s=t[i];i++){if(!s.isMovable())continue;const t=s.getRelativeToSurfaceXY();s.moveBy(-t.x,e-t.y,["cleanup"]),s.snapToGrid(),e=s.getRelativeToSurfaceXY().y+s.getHeightWidth().height+this.renderer.getConstants().MIN_BLOCK_HEIGHT}Ar.setGroup$$module$build$src$core$events$utils(!1),this.setResizesEnabled(!0)}showContextMenu(t){if(!this.options.readOnly&&!this.isFlyout){var e=lc.registry.getContextMenuOptions(lc.ScopeType.WORKSPACE,{workspace:this});this.configureContextMenu&&this.configureContextMenu(e,t),Zs(t,e,this.RTL)}}updateToolbox(t){if(t=Lt(t)){if(!this.options.languageTree)throw Error("Existing toolbox is null. Can't create new toolbox.");if(Pt(t)){if(!this.toolbox_)throw Error("Existing toolbox has no categories. Can't change mode.");this.options.languageTree=t,this.toolbox_.render(t)}else{if(!this.flyout)throw Error("Existing toolbox has categories. Can't change mode.");this.options.languageTree=t,this.flyout.show(t)}}else if(this.options.languageTree)throw Error("Can't nullify an existing toolbox.")}markFocused(){this.options.parentWorkspace?this.options.parentWorkspace.markFocused():(g(this),this.getParentSvg().focus({preventScroll:!0}))}zoom(t,e,s){s=Math.pow(this.options.zoomOptions.scaleSpeed,s);const i=this.scale*s;if(this.scale!==i){i>this.options.zoomOptions.maxScale?s=this.options.zoomOptions.maxScale/this.scale:ithis.options.zoomOptions.maxScale?t=this.options.zoomOptions.maxScale:this.options.zoomOptions.minScale&&te.autoHide(t)))}static setTopLevelWorkspaceMetrics_(t){const e=this.getMetrics();"number"==typeof t.x&&(this.scrollX=-(e.scrollLeft+(e.scrollWidth-e.viewWidth)*t.x)),"number"==typeof t.y&&(this.scrollY=-(e.scrollTop+(e.scrollHeight-e.viewHeight)*t.y)),this.translate(this.scrollX+e.absoluteLeft,this.scrollY+e.absoluteTop)}},zd={};zd.WorkspaceSvg=Vd,zd.resizeSvgContents=Nn;var Xd=class extends Cl{constructor(t,e){super(e),this.type=nl,this.isOpen=t}toJson(){const t=super.toJson();if(void 0===this.isOpen)throw Error("Whether this is already open or not is undefined. Either pass a value to the constructor, or call fromJson");return t.isOpen=this.isOpen,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Xd)).isOpen=t.isOpen,e}};t(Mr.EVENT,nl,Xd);var Yd=class extends Dh{constructor(t){if(super(t),this.type=Ar.DELETE$$module$build$src$core$events$utils,t){if(t.getParent())throw Error("Connected blocks cannot be deleted.");t.isShadow()&&(this.recordUndo=!1),this.oldXml=Ae(t),this.ids=L(t),this.wasShadow=t.isShadow(),this.oldJson=is(t,{addCoordinates:!0})}}toJson(){const t=super.toJson();if(!this.oldXml)throw Error("The old block XML is undefined. Either pass a block to the constructor, or call fromJson");if(!this.ids)throw Error("The block IDs are undefined. Either pass a block to the constructor, or call fromJson");if(void 0===this.wasShadow)throw Error("Whether the block was a shadow is undefined. Either pass a block to the constructor, or call fromJson");if(!this.oldJson)throw Error("The old block JSON is undefined. Either pass a block to the constructor, or call fromJson");return t.oldXml=Me(this.oldXml),t.ids=this.ids,t.wasShadow=this.wasShadow,t.oldJson=this.oldJson,this.recordUndo||(t.recordUndo=this.recordUndo),t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Yd)).oldXml=Ar.textToDom$$module$build$src$core$utils$xml(t.oldXml),e.ids=t.ids,e.wasShadow=t.wasShadow||"shadow"===e.oldXml.tagName.toLowerCase(),e.oldJson=t.oldJson,void 0!==t.recordUndo&&(e.recordUndo=t.recordUndo),e}run(t){const e=this.getEventWorkspace_();if(!this.ids)throw Error("The block IDs are undefined. Either pass a block to the constructor, or call fromJson");if(!this.oldJson)throw Error("The old block JSON is undefined. Either pass a block to the constructor, or call fromJson");if(t)for(t=0;tt.disposeInternal())),this.inputList.forEach((t=>t.dispose())),this.inputList.length=0,this.getConnections_(!0).forEach((t=>t.dispose())),this.disposed=!0)}isDeadOrDying(){return this.disposing||this.disposed}initModel(){for(const t of this.inputList)for(const e of t.fieldRow)e.initModel&&e.initModel()}unplug(t){this.outputConnection&&this.unplugFromRow_(t),this.previousConnection&&this.unplugFromStack_(t)}unplugFromRow_(t){let e,s=null;null!=(e=this.outputConnection)&&e.isConnected()&&(s=this.outputConnection.targetConnection,this.outputConnection.disconnect()),s&&t&&(t=this.getOnlyValueConnection_())&&t.isConnected()&&!t.targetBlock().isShadow()&&(null==(t=t.targetConnection)||t.disconnect(),this.workspace.connectionChecker.canConnect(t,s,!1)?s.connect(t):null==t||t.onFailedConnect(s))}getOnlyValueConnection_(){let t=null;for(let e=0;e(t=t+("("===s||")"===e?"":" ")+e,s=e[e.length-1],t)),"")).trim()||"???",t&&e.length>t&&(e=e.substring(0,t-3)+"..."),e}toTokens(t="?"){const e=[];for(const i of this.inputList)if(i.name!=Cd){for(const t of i.fieldRow)e.push(t.getText());if(i.connection){const o=i.connection.targetBlock();if(o){var s=i.connection;let n=s.getCheck();!n&&s.targetConnection&&(n=s.targetConnection.getCheck()),(s=!!n&&(-1!==n.indexOf("Boolean")||-1!==n.indexOf("Number")))&&e.push("("),e.push(...o.toTokens(t)),s&&e.push(")")}else e.push(t)}}return e}appendValueInput(t){return this.appendInput(new Ar.ValueInput$$module$build$src$core$inputs$value_input(t,this))}appendStatementInput(t){return this.statementInputCount++,this.appendInput(new fd(t,this))}appendDummyInput(t=""){return this.appendInput(new _d(t,this))}appendEndRowInput(t=""){return this.appendInput(new md(t,this))}appendInput(t){return this.inputList.push(t),t}appendInputFromRegistry(t,e){return(t=n(Mr.INPUT,t,!1))?this.appendInput(new t(e,this)):null}jsonInit(t){var e=t.type?'Block "'+t.type+'": ':"";if(t.output&&t.previousStatement)throw Error(e+"Must not have both an output and a previousStatement.");for(var s=0;t["args"+s];){if(void 0===t["message"+s])throw Error(e+`args${s} must have a corresponding message (message${s}).`);s++}if(t.style&&t.style.hat&&(this.hat=t.style.hat,t.style=null),t.style&&t.colour)throw Error(e+"Must not have both a colour and a style.");for(t.style?this.jsonInitStyle_(t,e):this.jsonInitColour_(t,e),s=0;void 0!==t["message"+s];)this.interpolate_(t["message"+s],t["args"+s]||[],t["implicitAlign"+s]||t["lastDummyAlign"+s],e),s++;if(void 0!==t.inputsInline&&(Ar.disable$$module$build$src$core$events$utils(),this.setInputsInline(t.inputsInline),Ar.enable$$module$build$src$core$events$utils()),void 0!==t.output&&this.setOutput(!0,t.output),void 0!==t.outputShape&&this.setOutputShape(t.outputShape),void 0!==t.previousStatement&&this.setPreviousStatement(!0,t.previousStatement),void 0!==t.nextStatement&&this.setNextStatement(!0,t.nextStatement),void 0!==t.tooltip&&(s=Io(t.tooltip),this.setTooltip(s)),void 0!==t.enableContextMenu&&(this.contextMenu=!!t.enableContextMenu),void 0!==t.suppressPrefixSuffix&&(this.suppressPrefixSuffix=!!t.suppressPrefixSuffix),void 0!==t.helpUrl&&(s=Io(t.helpUrl),this.setHelpUrl(s)),"string"==typeof t.extensions&&(console.warn(e+"JSON attribute 'extensions' should be an array of strings. Found raw string in JSON for '"+t.type+"' block."),t.extensions=[t.extensions]),void 0!==t.mutator&&Ho(t.mutator,this,!0),t=t.extensions,Array.isArray(t))for(e=0;en||n>e)throw Error('Block "'+this.type+'": Message index %'+n+" out of range.");if(s[n])throw Error('Block "'+this.type+'": Message index %'+n+" duplicated.");s[n]=!0,i++}}if(i!==e)throw Error('Block "'+this.type+'": Message does not reference all '+e+" arg(s).")}interpolateArguments_(t,e,s){const i=[];for(let n=0;n=this.inputList.length)throw RangeError("Input index "+t+" out of bounds.");if(e>this.inputList.length)throw RangeError("Reference input "+e+" out of bounds.");const s=this.inputList[t];this.inputList.splice(t,1),tt.getWeight()-e.getWeight())),t}removeIcon(t){if(!this.hasIcon(t))return!1;let e;return null==(e=this.getIcon(t))||e.dispose(),this.icons=this.icons.filter((e=>!e.getType().equals(t))),!0}hasIcon(t){return this.icons.some((e=>e.getType().equals(t)))}getIcon(t){return t instanceof za?this.icons.find((e=>e.getType().equals(t))):this.icons.find((e=>e.getType().toString()===t))}getIcons(){return[...this.icons]}getRelativeToSurfaceXY(){return this.xy_}moveBy(t,e,s){if(this.parentBlock_)throw Error("Block has parent");const i=new(B(Ar.MOVE$$module$build$src$core$events$utils))(this);s&&i.setReason(s),this.xy_.translate(t,e),i.recordNew(),S(i)}makeConnection_(t){return new $d(this,t)}allInputsFilled(t){if(void 0===t&&(t=!0),!t&&this.isShadow())return!1;for(let s,i=0;s=this.inputList[i];i++)if(s.connection){var e=s.connection.targetBlock();if(!e||!e.allInputsFilled(t))return!1}return!(e=this.getNextBlock())||e.allInputsFilled(t)}toDevString(){let t=this.type?'"'+this.type+'" block':"Block";return this.id&&(t+=' (id="'+this.id+'")'),t}};Kd.COLLAPSED_INPUT_NAME=Cd,Kd.COLLAPSED_FIELD_NAME=vd;var Jd=class{constructor(){this.drawer=this.curNode=this.colour=null,this.type="marker"}setDrawer(t){this.drawer=t}getDrawer(){return this.drawer}getCurNode(){return this.curNode}setCurNode(t){const e=this.curNode;this.curNode=t,this.drawer&&this.drawer.draw(e,this.curNode)}draw(){this.drawer&&this.drawer.draw(this.curNode,this.curNode)}hide(){this.drawer&&this.drawer.hide()}dispose(){this.getDrawer()&&this.getDrawer().dispose()}},jd=class extends Jd{constructor(){super(),this.type="cursor"}next(){var t=this.getCurNode();if(!t)return null;for(t=t.next();t&&t.next()&&(t.getType()===Td.types.NEXT||t.getType()===Td.types.BLOCK);)t=t.next();return t&&this.setCurNode(t),t}in(){var t=this.getCurNode();if(!t)return null;let e,s;return t.getType()!==Td.types.PREVIOUS&&t.getType()!==Td.types.OUTPUT||(t=t.next()),(t=null!=(s=null==(e=t)?void 0:e.in())?s:null)&&this.setCurNode(t),t}prev(){var t=this.getCurNode();if(!t)return null;for(t=t.prev();t&&t.prev()&&(t.getType()===Td.types.NEXT||t.getType()===Td.types.BLOCK);)t=t.prev();return t&&this.setCurNode(t),t}out(){var t=this.getCurNode();return t?((t=t.out())&&t.getType()===Td.types.BLOCK&&(t=t.prev()||t),t&&this.setCurNode(t),t):null}};t(Mr.CURSOR,Lr,jd);var Zd=class extends jd{constructor(){super()}next(){var t=this.getCurNode();return t?((t=this.getNextNode_(t,this.validNode_))&&this.setCurNode(t),t):null}in(){return this.next()}prev(){var t=this.getCurNode();return t?((t=this.getPreviousNode_(t,this.validNode_))&&this.setCurNode(t),t):null}out(){return this.prev()}getNextNode_(t,e){if(!t)return null;const s=t.in()||t.next();return e(s)?s:s?this.getNextNode_(s,e):e(t=this.findSiblingOrParent(t.out()))?t:t?this.getNextNode_(t,e):null}getPreviousNode_(t,e){if(!t)return null;let s=t.prev();return s=s?this.getRightMostChild(s):t.out(),e(s)?s:s?this.getPreviousNode_(s,e):null}validNode_(t){let e=!1;return(t=t&&t.getType())!==Td.types.OUTPUT&&t!==Td.types.INPUT&&t!==Td.types.FIELD&&t!==Td.types.NEXT&&t!==Td.types.PREVIOUS&&t!==Td.types.WORKSPACE||(e=!0),e}findSiblingOrParent(t){if(!t)return null;const e=t.next();return e||this.findSiblingOrParent(t.out())}getRightMostChild(t){if(!t.in())return t;for(t=t.in();t&&t.next();)t=t.next();return this.getRightMostChild(t)}};Zd.registrationName="basicCursor",t(Mr.CURSOR,Zd.registrationName,Zd);var qd=class extends Zd{validNode_(t){let e=!1;const s=t&&t.getType();return t&&(t=t.getLocation(),s===Td.types.FIELD&&t&&t.isTabNavigable()&&t.isClickable()&&(e=!0)),e}},Qd=class extends $d{constructor(t,e){super(t,e),this.targetConnection=this.highlightPath=null,this.db=t.workspace.connectionDBList[e],this.dbOpposite=t.workspace.connectionDBList[xc[e]],this.offsetInBlock=new la(0,0),this.trackedState=Qd.TrackedState.WILL_TRACK}dispose(){super.dispose(),this.trackedState===Qd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y),this.highlightPath&&(lt(this.highlightPath),this.highlightPath=null)}getSourceBlock(){return super.getSourceBlock()}targetBlock(){return super.targetBlock()}distanceFrom(t){const e=this.x-t.x;return t=this.y-t.y,Math.sqrt(e*e+t*t)}bumpAwayFrom(t){if(!this.sourceBlock_.workspace.isDragging()){var e=this.sourceBlock_.getRootBlock();if(!e.isInFlyout){var s=!1;if(!e.isMovable()){if(!(e=t.getSourceBlock().getRootBlock()).isMovable())return;t=this,s=!0}var i=b()==e;i||e.addSelect();var o=t.x+Ar.config$$module$build$src$core$config.snapRadius+Math.floor(10*Math.random())-this.x,n=t.y+Ar.config$$module$build$src$core$config.snapRadius+Math.floor(10*Math.random())-this.y;s&&(n=-n),e.RTL&&(o=t.x-Ar.config$$module$build$src$core$config.snapRadius-Math.floor(10*Math.random())-this.x),e.moveBy(o,n,["bump"]),i||e.removeSelect()}}}moveTo(t,e){let s=!1;return this.trackedState===Qd.TrackedState.WILL_TRACK?(this.db.addConnection(this,e),this.trackedState=Qd.TrackedState.TRACKED,s=!0):this.trackedState===Qd.TrackedState.TRACKED&&(this.db.removeConnection(this,this.y),this.db.addConnection(this,e),s=!0),this.x=t,this.y=e,s}moveBy(t,e){return this.moveTo(this.x+t,this.y+e)}moveToOffset(t){return this.moveTo(t.x+this.offsetInBlock.x,t.y+this.offsetInBlock.y)}setOffsetInBlock(t,e){this.offsetInBlock.x=t,this.offsetInBlock.y=e}getOffsetInBlock(){return this.offsetInBlock}tightenEfficiently(){var t=this.targetConnection;const e=this.targetBlock();t&&e&&(t=la.difference(this.offsetInBlock,t.offsetInBlock),e.translate(t.x,t.y))}closest(t,e){return this.dbOpposite.searchForClosest(this,t,e)}highlight(){if(!this.highlightPath){var t=this.sourceBlock_.workspace.getRenderer().getConstants(),e=t.shapeFor(this);this.type===Lh.INPUT_VALUE||this.type===Lh.OUTPUT_VALUE?(t=t.TAB_OFFSET_FROM_TOP,e=en(0,-t)+nn("v",t)+e.pathDown+nn("v",t)):(t=t.NOTCH_OFFSET_LEFT-t.CORNER_RADIUS,e=en(-t,0)+nn("h",t)+e.pathLeft+nn("h",t)),t=this.offsetInBlock,this.highlightPath=st(ma.PATH,{class:"blocklyHighlightedConnectionPath",d:e,transform:`translate(${t.x}, ${t.y})`+(this.sourceBlock_.RTL?" scale(-1 1)":"")},this.sourceBlock_.getSvgRoot())}}unhighlight(){this.highlightPath&&(lt(this.highlightPath),this.highlightPath=null)}setTracking(t){t&&this.trackedState===Qd.TrackedState.TRACKED||!t&&this.trackedState===Qd.TrackedState.UNTRACKED||this.sourceBlock_.isInFlyout||(t?(this.db.addConnection(this,this.y),this.trackedState=Qd.TrackedState.TRACKED):(this.trackedState===Qd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y),this.trackedState=Qd.TrackedState.UNTRACKED))}stopTrackingAll(){if(this.setTracking(!1),this.targetConnection){const t=this.targetBlock().getDescendants(!1);for(let e=0;eclearTimeout(t))),this.warningTextDb.clear(),this.getIcons().forEach((t=>t.dispose())))}checkAndDelete(){this.workspace.isFlyout||(Ar.setGroup$$module$build$src$core$events$utils(!0),this.workspace.hideChaff(),this.outputConnection?this.dispose(!1,!0):this.dispose(!0,!0),Ar.setGroup$$module$build$src$core$events$utils(!1))}toCopyData(){return this.isInsertionMarker_?null:{paster:Bh.TYPE,blockState:is(this,{addCoordinates:!0,addNextBlocks:!1}),typeCounts:T(this,!0)}}applyColour(){this.pathObject.applyColour(this);const t=this.getIcons();for(let e=0;e{this.isDeadOrDying()||(this.warningTextDb.delete(e),this.setWarningText(t,e))}),100));else if(this.isInFlyout&&(t=null),s=this.getIcon(Bu.TYPE),t){let i=this.getSurroundParent(),o=null;for(;i;)i.isCollapsed()&&(o=i),i=i.getSurroundParent();o&&o.setWarningText(Ar.Msg$$module$build$src$core$msg.COLLAPSED_WARNINGS_WARNING,sp.COLLAPSED_WARNING_ID),s?s.addMessage(t,e):this.addIcon(new Bu(this).addMessage(t,e))}else s&&(e?(s.addMessage("",e),s.getText()||this.removeIcon(Bu.TYPE)):this.removeIcon(Bu.TYPE))}setMutator(t){this.removeIcon(Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon.TYPE),t&&this.addIcon(t)}addIcon(t){return super.addIcon(t),t instanceof Bu&&(this.warning=t),t instanceof Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon&&(this.mutator=t),this.rendered&&(t.initView(this.createIconPointerDownListener(t)),t.applyColour(),t.updateEditable(),this.queueRender(),ye(),this.bumpNeighbours()),t}createIconPointerDownListener(t){return e=>{this.isDeadOrDying()||(e=this.workspace.getGesture(e))&&e.setStartIcon(t)}}removeIcon(t){const e=super.removeIcon(t);return t.equals(Bu.TYPE)&&(this.warning=null),t.equals(Ar.MutatorIcon$$module$build$src$core$icons$mutator_icon.TYPE)&&(this.mutator=null),this.rendered&&(this.queueRender(),ye(),this.bumpNeighbours()),e}setEnabled(t){this.isEnabled()!==t&&(super.setEnabled(t),this.rendered&&!this.getInheritedDisabled()&&this.updateDisabled())}setHighlighted(t){this.rendered&&this.pathObject.updateHighlighted(t)}addSelect(){this.pathObject.updateSelected(!0)}removeSelect(){this.pathObject.updateSelected(!1)}setDeleteStyle(t){this.pathObject.updateDraggingDelete(t)}getColour(){return this.style.colourPrimary}setColour(t){super.setColour(t),t=this.workspace.getRenderer().getConstants().getBlockStyleForColour(this.colour_),this.pathObject.setStyle(t.style),this.style=t.style,this.styleName_=t.name,this.applyColour()}setStyle(t){const e=this.workspace.getRenderer().getConstants().getBlockStyle(t);if(this.styleName_=t,!e)throw Error("Invalid style name: "+t);this.hat=e.hat,this.pathObject.setStyle(e),this.colour_=e.colourPrimary,this.style=e,this.applyColour()}bringToFront(t=!1){let e=this;if(!e.isDeadOrDying())do{const s=e.getSvgRoot(),i=s.parentNode,o=i.childNodes;if(o[o.length-1]!==s&&i.appendChild(s),t)break;e=e.getParent()}while(e)}setPreviousStatement(t,e){super.setPreviousStatement(t,e),this.rendered&&(this.queueRender(),this.bumpNeighbours())}setNextStatement(t,e){super.setNextStatement(t,e),this.rendered&&(this.queueRender(),this.bumpNeighbours())}setOutput(t,e){super.setOutput(t,e),this.rendered&&(this.queueRender(),this.bumpNeighbours())}setInputsInline(t){super.setInputsInline(t),this.rendered&&(this.queueRender(),this.bumpNeighbours())}removeInput(t,e){return t=super.removeInput(t,e),this.rendered&&(this.queueRender(),this.bumpNeighbours()),t}moveNumberedInputBefore(t,e){super.moveNumberedInputBefore(t,e),this.rendered&&(this.queueRender(),this.bumpNeighbours())}appendInput(t){return super.appendInput(t),this.rendered&&(this.queueRender(),this.bumpNeighbours()),t}setConnectionTracking(t){if(this.previousConnection&&this.previousConnection.setTracking(t),this.outputConnection&&this.outputConnection.setTracking(t),this.nextConnection){this.nextConnection.setTracking(t);var e=this.nextConnection.targetBlock();e&&e.setConnectionTracking(t)}if(!this.collapsed_)for(e=0;e{const e=Ar.getGroup$$module$build$src$core$events$utils();Ar.setGroup$$module$build$src$core$events$utils(t),this.getRootBlock().bumpNeighboursInternal(),Ar.setGroup$$module$build$src$core$events$utils(e),this.bumpNeighboursPid=0}),Ar.config$$module$build$src$core$config.bumpDelay)}}bumpNeighboursInternal(){const t=this.getRootBlock();if(!(this.isDeadOrDying()||this.workspace.isDragging()||t.isInFlyout))for(const e of this.getConnections_(!1)){if(e.isSuperior()){let t;null==(t=e.targetBlock())||t.bumpNeighboursInternal()}for(const s of e.neighbours(Ar.config$$module$build$src$core$config.snapRadius))s.getSourceBlock().getRootBlock()!==t&&(e.isConnected()&&s.isConnected()||(e.isSuperior()?s.bumpAwayFrom(e):e.bumpAwayFrom(s)))}}scheduleSnapAndBump(){const t=Ar.getGroup$$module$build$src$core$events$utils();setTimeout((()=>{Ar.setGroup$$module$build$src$core$events$utils(t),this.snapToGrid(),Ar.setGroup$$module$build$src$core$events$utils(!1)}),Ar.config$$module$build$src$core$config.bumpDelay/2),this.bumpNeighbours()}positionNearConnection(t,e,s){if(t.type===Lh.NEXT_STATEMENT||t.type===Lh.INPUT_VALUE){let i=e.x;e=e.y,i+=s.x-t.getOffsetInBlock().x,e+=s.y-t.getOffsetInBlock().y,this.moveBy(i,e)}}getChildren(t){return super.getChildren(t)}queueRender(){return ke(this)}render(){this.queueRender(),ye()}renderEfficiently(){this.rendered=!0,ut(),this.isCollapsed()&&this.updateCollapsed_(),this.isEnabled()||this.updateDisabled(),this.workspace.getRenderer().render(this),this.tightenChildrenEfficiently(),dt(),this.updateMarkers_()}tightenChildrenEfficiently(){for(const t of this.inputList){const e=t.connection;e&&e.tightenEfficiently()}this.nextConnection&&this.nextConnection.tightenEfficiently()}updateMarkers_(){this.workspace.keyboardAccessibilityMode&&this.pathObject.cursorSvg&&this.workspace.getCursor().draw(),this.workspace.keyboardAccessibilityMode&&this.pathObject.markerSvg&&this.workspace.getMarker(ou.LOCAL_MARKER).draw();for(const t of this.inputList)for(const e of t.fieldRow)e.updateMarkers_()}setCursorSvg(t){this.pathObject.setCursorSvg(t)}setMarkerSvg(t){this.pathObject.setMarkerSvg(t)}getHeightWidth(){let t=this.height,e=this.width;var s=this.getNextBlock();if(s){s=s.getHeightWidth();const i=this.workspace.getRenderer().getConstants().NOTCH_HEIGHT;t+=s.height-i,e=Math.max(e,s.width)}return{height:t,width:e}}fadeForReplacement(t){this.pathObject.updateReplacementFade(t)}highlightShapeForInput(t,e){this.pathObject.updateShapeForInputHighlight(t,e)}};sp.INLINE=-1,sp.COLLAPSED_WARNING_ID="TEMP_COLLAPSED_WARNING_";var ip=class{constructor(){}onDragEnter(t){}onDragOver(t){}onDragExit(t){}onDrop(t){}getClientRect(){return null}shouldPreventMove(t){return!1}},op=class extends ip{constructor(){super(),this.wouldDelete_=!1}wouldDelete(t,e){return t instanceof sp?(t=!t.getParent()&&t.isDeletable(),this.updateWouldDelete_(t&&!e)):this.updateWouldDelete_(t.isDeletable()),this.wouldDelete_}updateWouldDelete_(t){this.wouldDelete_=t}},np=class extends op{constructor(t){super(),this.workspace=t,this.id="trashcan",this.contents=[],this.flyout=null,this.isLidOpen=!1,this.minOpenness=0,this.lidTask=this.svgLid=this.svgGroup=null,this.top=this.left=this.lidOpen=0,this.initialized=!1,0>=this.workspace.options.maxTrashcanContents||(t=new au({scrollbars:!0,parentWorkspace:this.workspace,rtl:this.workspace.RTL,oneBasedIndex:this.workspace.options.oneBasedIndex,renderer:this.workspace.options.renderer,rendererOverrides:this.workspace.options.rendererOverrides,move:{scrollbars:!0}}),this.workspace.horizontalLayout?(t.toolboxPosition=this.workspace.toolboxPosition===xa.TOP?xa.BOTTOM:xa.TOP,this.flyout=new(a(Mr.FLYOUTS_HORIZONTAL_TOOLBOX,this.workspace.options,!0))(t)):(t.toolboxPosition=this.workspace.toolboxPosition===xa.RIGHT?xa.LEFT:xa.RIGHT,this.flyout=new(a(Mr.FLYOUTS_VERTICAL_TOOLBOX,this.workspace.options,!0))(t)),this.workspace.addChangeListener(this.onDelete.bind(this)))}createDom(){let t;this.svgGroup=st(ma.G,{class:"blocklyTrash"});const e=String(Math.random()).substring(2);t=st(ma.CLIPPATH,{id:"blocklyTrashBodyClipPath"+e},this.svgGroup),st(ma.RECT,{width:rp,height:lp,y:ap},t);const s=st(ma.IMAGE,{width:Wa.width,x:-dp,height:Wa.height,y:-pp,"clip-path":"url(#blocklyTrashBodyClipPath"+e+")"},this.svgGroup);return s.setAttributeNS(da,"xlink:href",this.workspace.options.pathToMedia+Wa.url),t=st(ma.CLIPPATH,{id:"blocklyTrashLidClipPath"+e},this.svgGroup),st(ma.RECT,{width:rp,height:ap},t),this.svgLid=st(ma.IMAGE,{width:Wa.width,x:-dp,height:Wa.height,y:-pp,"clip-path":"url(#blocklyTrashLidClipPath"+e+")"},this.svgGroup),this.svgLid.setAttributeNS(da,"xlink:href",this.workspace.options.pathToMedia+Wa.url),X(this.svgGroup,"pointerdown",this,this.blockMouseDownWhenOpenable),X(this.svgGroup,"pointerup",this,this.click),X(s,"pointerover",this,this.mouseOver),X(s,"pointerout",this,this.mouseOut),this.animateLid(),this.svgGroup}init(){0{let s,i;null==(s=this.flyout)||s.show(t),e.cursor="",null==(i=this.workspace.scrollbar)||i.setVisible(!1)}),10),this.fireUiEvent(!0)}}closeFlyout(){var t,e;this.contentsIsOpen()&&(null==(t=this.flyout)||t.hide(),null==(e=this.workspace.scrollbar)||e.setVisible(!0),this.fireUiEvent(!1),this.workspace.recordDragTargets())}autoHide(t){!t&&this.flyout&&this.closeFlyout()}emptyContents(){this.hasContents()&&(this.contents.length=0,this.setMinOpenness(0),this.closeFlyout())}position(t,e){if(this.initialized){var s,i=Xt(this.workspace,t);t=zt(i,new Ea(rp,lp+ap),cp,hp,t,this.workspace),e=Yt(t,hp,i.vertical===Ba.TOP?Fa.DOWN:Fa.UP,e),this.top=e.top,this.left=e.left,null==(s=this.svgGroup)||s.setAttribute("transform","translate("+this.left+","+this.top+")")}}getBoundingRectangle(){return new fa(this.top,this.top+lp+ap,this.left,this.left+rp)}getClientRect(){if(!this.svgGroup)return null;var t=this.svgGroup.getBoundingClientRect();const e=t.top+pp-up;return t=t.left+dp-up,new fa(e,e+ap+lp+2*up,t,t+rp+2*up)}onDragOver(t){this.setLidOpen(this.wouldDelete_)}onDragExit(t){this.setLidOpen(!1)}onDrop(t){setTimeout(this.setLidOpen.bind(this,!1),100)}setLidOpen(t){this.isLidOpen!==t&&(this.lidTask&&clearTimeout(this.lidTask),this.isLidOpen=t,this.animateLid())}animateLid(){const t=_p;var e=1/(t+1);this.lidOpen+=this.isLidOpen?e:-e,this.lidOpen=Math.min(Math.max(this.lidOpen,this.minOpenness),1),this.setLidAngle(this.lidOpen*Ep),e=mp+this.lidOpen*(fp-mp),this.svgGroup&&(this.svgGroup.style.opacity=`${e}`),this.lidOpen>this.minOpenness&&1>this.lidOpen&&(this.lidTask=setTimeout(this.animateLid.bind(this),bp/t))}setLidAngle(t){const e=this.workspace.toolboxPosition===xa.RIGHT||this.workspace.horizontalLayout&&this.workspace.RTL;let s;null==(s=this.svgLid)||s.setAttribute("transform","rotate("+(e?-t:t)+","+(e?4:rp-4)+","+(ap-2)+")")}setMinOpenness(t){this.minOpenness=t,this.isLidOpen||this.setLidAngle(t*Ep)}closeLid(){this.setLidOpen(!1)}click(){this.hasContents()&&!this.workspace.isDragging()&&this.openFlyout()}fireUiEvent(t){t=new(B(nl))(t,this.workspace.id),S(t)}blockMouseDownWhenOpenable(t){!this.contentsIsOpen()&&this.hasContents()&&t.stopPropagation()}mouseOver(){this.hasContents()&&this.setLidOpen(!0)}mouseOut(){this.setLidOpen(!1)}onDelete(t){if(!(0>=this.workspace.options.maxTrashcanContents||t.type!==Ar.DELETE$$module$build$src$core$events$utils||t.type!==Ar.DELETE$$module$build$src$core$events$utils||t.wasShadow)){if(!t.oldJson)throw Error("Encountered a delete event without proper oldJson");if(t=JSON.stringify(this.cleanBlockJson(t.oldJson)),-1===this.contents.indexOf(t)){for(this.contents.unshift(t);this.contents.length>this.workspace.options.maxTrashcanContents;)this.contents.pop();this.setMinOpenness(gp)}}}cleanBlockJson(t){return function t(e){if(e){if(delete e.id,delete e.x,delete e.y,delete e.enabled,e.icons&&e.icons.comment){var s=e.icons.comment;delete s.height,delete s.width,delete s.pinned}for(var i in s=e.inputs){var o=s[i];const e=o.block;o=o.shadow,e&&t(e),o&&t(o)}e.next&&(e=(i=e.next).block,i=i.shadow,e&&t(e),i&&t(i))}}(t=JSON.parse(JSON.stringify(t))),Object.assign({},{kind:"BLOCK"},t)}},rp=47,lp=44,ap=16,hp=20,cp=20,up=10,dp=0,pp=32,gp=.1,bp=80,_p=4,mp=.4,fp=.8,Ep=45,Tp=class{constructor(){this.shortcuts=new Map,this.keyMap=new Map,this.reset()}reset(){this.shortcuts.clear(),this.keyMap.clear()}register(t,e){if(this.shortcuts.get(t.name)&&!e)throw Error(`Shortcut named "${t.name}" already exists.`);if(this.shortcuts.set(t.name,t),(e=t.keyCodes)&&0Un(t)))).length?t:null}load(t,e){const s=e.getProcedureMap();for(const i of t)s.add(Vn(this.procedureModelClass,this.parameterModelClass,i,e))}clear(t){t.getProcedureMap().clear()}}};Cp.loadParameter=zn,Cp.loadProcedure=Vn,Cp.saveParameter=Wn,Cp.saveProcedure=Un;var vp=class{constructor(){this.priority=100}save(t){const e=[];for(const s of t.getAllVariables())t={name:s.name,id:s.getId()},s.type&&(t.type=s.type),e.push(t);return e.length?e:null}load(t,e){for(const s of t)e.createVariable(s.name,s.type,s.id)}clear(t){t.getVariableMap().clear()}};es("variables",new vp);var Ip={};Ip.VariableSerializer=vp;var Sp={};Sp.load=Yn,Sp.save=Xn;var Rp={blocks:Rh,exceptions:Ch,priorities:vh,procedures:Cp,registry:Ih,variables:Ip,workspaces:Sp},Dp=class{constructor(t,e,s,i,o){this.workspace=t,this.oldHostMetrics_=this.corner_=this.vScroll=this.hScroll=null,s=void 0===s||s;const n=(e=void 0===e||e)&&s;e&&(this.hScroll=new Ca(t,!0,n,i,o)),s&&(this.vScroll=new Ca(t,!1,n,i,o)),n&&(this.corner_=st(ma.RECT,{height:Ca.scrollbarThickness,width:Ca.scrollbarThickness,class:"blocklyScrollbarBackground"}),at(this.corner_,t.getBubbleCanvas()))}dispose(){lt(this.corner_),this.oldHostMetrics_=this.corner_=null,this.hScroll&&(this.hScroll.dispose(),this.hScroll=null),this.vScroll&&(this.vScroll.dispose(),this.vScroll=null)}resize(){const t=this.workspace.getMetrics();if(t){var e=!1,s=!1;if(this.oldHostMetrics_&&this.oldHostMetrics_.viewWidth===t.viewWidth&&this.oldHostMetrics_.viewHeight===t.viewHeight&&this.oldHostMetrics_.absoluteTop===t.absoluteTop&&this.oldHostMetrics_.absoluteLeft===t.absoluteLeft?(this.oldHostMetrics_&&this.oldHostMetrics_.scrollWidth===t.scrollWidth&&this.oldHostMetrics_.viewLeft===t.viewLeft&&this.oldHostMetrics_.scrollLeft===t.scrollLeft||(e=!0),this.oldHostMetrics_&&this.oldHostMetrics_.scrollHeight===t.scrollHeight&&this.oldHostMetrics_.viewTop===t.viewTop&&this.oldHostMetrics_.scrollTop===t.scrollTop||(s=!0)):s=e=!0,e||s){try{Ar.disable$$module$build$src$core$events$utils(),this.hScroll&&e&&this.hScroll.resize(t),this.vScroll&&s&&this.vScroll.resize(t)}finally{Ar.enable$$module$build$src$core$events$utils()}this.workspace.maybeFireViewportChangeEvent()}if(this.hScroll&&this.vScroll){if(!this.oldHostMetrics_||this.oldHostMetrics_.viewWidth!==t.viewWidth||this.oldHostMetrics_.absoluteLeft!==t.absoluteLeft){let t;null==(t=this.corner_)||t.setAttribute("x",String(this.vScroll.position.x))}if(!this.oldHostMetrics_||this.oldHostMetrics_.viewHeight!==t.viewHeight||this.oldHostMetrics_.absoluteTop!==t.absoluteTop){let t;null==(t=this.corner_)||t.setAttribute("y",String(this.hScroll.position.y))}}this.oldHostMetrics_=t}}canScrollHorizontally(){return!!this.hScroll}canScrollVertically(){return!!this.vScroll}setOrigin(t,e){this.hScroll&&this.hScroll.setOrigin(t,e),this.vScroll&&this.vScroll.setOrigin(t,e)}set(t,e,s){this.hScroll&&this.hScroll.set(t,!1),this.vScroll&&this.vScroll.set(e,!1),(s||void 0===s)&&(t={},this.hScroll&&(t.x=this.hScroll.getRatio_()),this.vScroll&&(t.y=this.vScroll.getRatio_()),this.workspace.setMetrics(t))}setX(t){this.hScroll&&this.hScroll.set(t,!0)}setY(t){this.vScroll&&this.vScroll.set(t,!0)}setContainerVisible(t){this.hScroll&&this.hScroll.setContainerVisible(t),this.vScroll&&this.vScroll.setContainerVisible(t)}isVisible(){let t=!1;return this.hScroll&&(t=this.hScroll.isVisible()),this.vScroll&&(t=t||this.vScroll.isVisible()),t}setVisible(t){this.hScroll&&this.hScroll.setVisibleInternal(t),this.vScroll&&this.vScroll.setVisibleInternal(t)}resizeContent(t){this.hScroll&&this.hScroll.resizeContentHorizontal(t),this.vScroll&&this.vScroll.resizeContentVertical(t)}resizeView(t){this.hScroll&&this.hScroll.resizeViewHorizontal(t),this.vScroll&&this.vScroll.resizeViewVertical(t)}},Ap=class{constructor(t){this.workspace_=t}getDimensionsPx_(t){let e=0,s=0;return t&&(e=t.getWidth(),s=t.getHeight()),new Ea(e,s)}getFlyoutMetrics(t){return{width:(t=this.getDimensionsPx_(this.workspace_.getFlyout(t))).width,height:t.height,position:this.workspace_.toolboxPosition}}getToolboxMetrics(){const t=this.getDimensionsPx_(this.workspace_.getToolbox());return{width:t.width,height:t.height,position:this.workspace_.toolboxPosition}}getSvgMetrics(){return this.workspace_.getCachedParentSvgSize()}getAbsoluteMetrics(){let t=0,e=0;const s=this.getToolboxMetrics(),i=this.getFlyoutMetrics(),o=!!this.workspace_.getToolbox();var n;const r=!(null!=(n=this.workspace_.getFlyout())&&n.autoClose),l=(n=o?s.position:i.position)===xa.TOP;return n===xa.LEFT&&(o&&(t+=s.width),r&&(t+=i.width)),l&&(o&&(e+=s.height),r&&(e+=i.height)),{top:e,left:t}}getViewMetrics(t){t=t?this.workspace_.scale:1;const e=this.getSvgMetrics(),s=this.getToolboxMetrics(),i=this.getFlyoutMetrics(),o=!!this.workspace_.getToolbox();var n;const r=!(null!=(n=this.workspace_.getFlyout())&&n.autoClose),l=(n=o?s.position:i.position)===xa.LEFT||n===xa.RIGHT;return n!==xa.TOP&&n!==xa.BOTTOM||(o&&(e.height-=s.height),r&&(e.height-=i.height)),l&&(o&&(e.width-=s.width),r&&(e.width-=i.width)),{height:e.height/t,width:e.width/t,top:-this.workspace_.scrollY/t,left:-this.workspace_.scrollX/t}}getContentMetrics(t){t=t?1:this.workspace_.scale;const e=this.workspace_.getBlocksBoundingBox();return{height:(e.bottom-e.top)*t,width:(e.right-e.left)*t,top:e.top*t,left:e.left*t}}hasFixedEdges(){return!this.workspace_.isMovableHorizontally()||!this.workspace_.isMovableVertically()}getComputedFixedEdges_(t){if(!this.hasFixedEdges())return{};const e=this.workspace_.isMovableHorizontally(),s=this.workspace_.isMovableVertically();t=t||this.getViewMetrics(!1);const i={};return s||(i.top=t.top,i.bottom=t.top+t.height),e||(i.left=t.left,i.right=t.left+t.width),i}getPaddedContent_(t,e){const s=e.top+e.height,i=e.left+e.width,o=t.width,n=o/2,r=(t=t.height)/2;return{top:Math.min(e.top-r,s-t),bottom:Math.max(s+r,e.top+t),left:Math.min(e.left-n,i-o),right:Math.max(i+n,e.left+o)}}getScrollMetrics(t,e,s){t=t?this.workspace_.scale:1,e=e||this.getViewMetrics(!1);var i=s||this.getContentMetrics();s=this.getComputedFixedEdges_(e),e=this.getPaddedContent_(e,i),i=void 0!==s.top?s.top:e.top;const o=void 0!==s.left?s.left:e.left;return{top:i/t,left:o/t,width:((void 0!==s.right?s.right:e.right)-o)/t,height:((void 0!==s.bottom?s.bottom:e.bottom)-i)/t}}getUiMetrics(){return{viewMetrics:this.getViewMetrics(),absoluteMetrics:this.getAbsoluteMetrics(),toolboxMetrics:this.getToolboxMetrics()}}getMetrics(){const t=this.getToolboxMetrics(),e=this.getFlyoutMetrics(!0),s=this.getSvgMetrics(),i=this.getAbsoluteMetrics(),o=this.getViewMetrics(),n=this.getContentMetrics(),r=this.getScrollMetrics(!1,o,n);return{contentHeight:n.height,contentWidth:n.width,contentTop:n.top,contentLeft:n.left,scrollHeight:r.height,scrollWidth:r.width,scrollTop:r.top,scrollLeft:r.left,viewHeight:o.height,viewWidth:o.width,viewTop:o.top,viewLeft:o.left,absoluteTop:i.top,absoluteLeft:i.left,svgHeight:s.height,svgWidth:s.width,toolboxWidth:t.width,toolboxHeight:t.height,toolboxPosition:t.position,flyoutWidth:e.width,flyoutHeight:e.height}}};t(Mr.METRICS_MANAGER,Lr,Ap);var Np=class extends $l{constructor(t){super(),this.isBlank=!0,this.recordUndo=!1,this.type=pl,this.isBlank=!!t,t&&(this.workspaceId=t.id)}};t(Mr.EVENT,pl,Np);var Op=class extends Cl{constructor(t,e,s){super(t?t.workspace.id:void 0),this.type=tl,t&&(this.blockId=t.id,this.isStart=e,this.blocks=s)}toJson(){const t=super.toJson();if(void 0===this.isStart)throw Error("Whether this event is the start of a drag is undefined. Either pass the value to the constructor, or call fromJson");if(void 0===this.blockId)throw Error("The block ID is undefined. Either pass a block to the constructor, or call fromJson");return t.isStart=this.isStart,t.blockId=this.blockId,t.blocks=this.blocks,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Op)).isStart=t.isStart,e.blockId=t.blockId,e.blocks=t.blocks,e}};t(Mr.EVENT,tl,Op);var xp={};xp.bumpIntoBounds=Kn,xp.bumpIntoBoundsHandler=Jn,xp.bumpTopObjectsIntoBounds=Zn;var Lp=class{constructor(t,e){this.dragTarget_=null,this.wouldDeleteBlock_=!1,this.dragIconData_=[],this.draggingBlock_=t,this.draggedConnectionManager_=new Rd(this.draggingBlock_),this.workspace_=e,this.startXY_=this.draggingBlock_.getRelativeToSurfaceXY(),this.dragIconData_=qn(t,this.startXY_)}dispose(){this.dragIconData_.length=0,this.draggedConnectionManager_&&this.draggedConnectionManager_.dispose()}startDrag(t,e){let s;Ar.getGroup$$module$build$src$core$events$utils()||Ar.setGroup$$module$build$src$core$events$utils(!0),this.fireDragStartEvent_(),this.draggingBlock_.bringToFront(!0),ut(),this.workspace_.setResizesEnabled(!1),Bi(),this.shouldDisconnect_(e)&&this.disconnectBlock_(e,t),this.draggingBlock_.setDragging(!0),null==(s=this.workspace_.getLayerManager())||s.moveToDragLayer(this.draggingBlock_)}shouldDisconnect_(t){return!!(this.draggingBlock_.getParent()||t&&this.draggingBlock_.nextConnection&&this.draggingBlock_.nextConnection.targetBlock())}disconnectBlock_(t,e){this.draggingBlock_.unplug(t),t=this.pixelsToWorkspaceUnits_(e),t=la.sum(this.startXY_,t),this.draggingBlock_.translate(t.x,t.y),Li(this.draggingBlock_),this.draggedConnectionManager_.updateAvailableConnections()}fireDragStartEvent_(){const t=new(B(tl))(this.draggingBlock_,!0,this.draggingBlock_.getDescendants(!1));S(t)}drag(t,e){e=this.pixelsToWorkspaceUnits_(e);var s=la.sum(this.startXY_,e);this.draggingBlock_.moveDuringDrag(s),s=this.dragTarget_,this.dragTarget_=this.workspace_.getDragTarget(t),this.draggedConnectionManager_.update(e,this.dragTarget_),t=this.wouldDeleteBlock_,this.wouldDeleteBlock_=this.draggedConnectionManager_.wouldDeleteBlock,t!==this.wouldDeleteBlock_&&this.updateCursorDuringBlockDrag_(),this.dragTarget_!==s&&(s&&s.onDragExit(this.draggingBlock_),this.dragTarget_&&this.dragTarget_.onDragEnter(this.draggingBlock_)),this.dragTarget_&&this.dragTarget_.onDragOver(this.draggingBlock_)}endDrag(t,e){if(this.drag(t,e),this.fireDragEndEvent_(),dt(),Bi(),t=null,this.dragTarget_&&this.dragTarget_.shouldPreventMove(this.draggingBlock_)||(t=this.getNewLocationAfterDrag_(e).delta),this.dragTarget_&&this.dragTarget_.onDrop(this.draggingBlock_),!this.maybeDeleteBlock_()){let e;null==(e=this.workspace_.getLayerManager())||e.moveOffDragLayer(this.draggingBlock_,50),this.draggingBlock_.setDragging(!1),t?this.updateBlockAfterMove_():Kn(this.draggingBlock_.workspace,this.workspace_.getMetricsManager().getScrollMetrics(!0),this.draggingBlock_)}this.workspace_.setResizesEnabled(!0),Ar.setGroup$$module$build$src$core$events$utils(!1)}getNewLocationAfterDrag_(t){return{delta:t=this.pixelsToWorkspaceUnits_(t),newLocation:la.sum(this.startXY_,t)}}maybeDeleteBlock_(){return!!this.wouldDeleteBlock_&&(this.fireMoveEvent_(),this.draggingBlock_.dispose(!1,!0),Wr.length=0,!0)}updateBlockAfterMove_(){this.fireMoveEvent_(),this.draggedConnectionManager_.wouldConnectBlock()?this.draggedConnectionManager_.applyConnections():this.draggingBlock_.queueRender(),this.draggingBlock_.scheduleSnapAndBump()}fireDragEndEvent_(){const t=new(B(tl))(this.draggingBlock_,!1,this.draggingBlock_.getDescendants(!1));S(t)}updateToolboxStyle_(t){const e=this.workspace_.getToolbox();if(e){const s=this.draggingBlock_.isDeletable()?"blocklyToolboxDelete":"blocklyToolboxGrab";t&&"function"==typeof e.removeStyle?e.removeStyle(s):t||"function"!=typeof e.addStyle||e.addStyle(s)}}fireMoveEvent_(){if(!this.draggingBlock_.isDeadOrDying()){var t=new(B(Ar.MOVE$$module$build$src$core$events$utils))(this.draggingBlock_);t.setReason(["drag"]),t.oldCoordinate=this.startXY_,t.recordNew(),S(t)}}updateCursorDuringBlockDrag_(){this.draggingBlock_.setDeleteStyle(this.wouldDeleteBlock_)}pixelsToWorkspaceUnits_(t){return t=new la(t.x/this.workspace_.scale,t.y/this.workspace_.scale),this.workspace_.isMutator&&t.scale(1/this.workspace_.options.parentWorkspace.scale),t}dragIcons_(){et("Blockly.BlockDragger.prototype.dragIcons_","v10","v11")}getInsertionMarkers(){return this.draggedConnectionManager_&&this.draggedConnectionManager_.getInsertionMarkers?this.draggedConnectionManager_.getInsertionMarkers():[]}};t(Mr.BLOCK_DRAGGER,Lr,Lp);var Mp={};Mp.Bubble=Cu,Mp.MiniWorkspaceBubble=vu,Mp.TextBubble=xu,Mp.TextInputBubble=Lu;var Bp=class extends Dh{constructor(t,e,s,i){super(t),this.type=Jr,this.recordUndo=!1,t&&(this.name=e,this.oldValue=s,this.newValue=i)}toJson(){const t=super.toJson();if(!this.name)throw Error("The changed field name is undefined. Either pass a name to the constructor, or call fromJson.");return t.name=this.name,t.oldValue=this.oldValue,t.newValue=this.newValue,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Bp)).name=t.name,e.oldValue=t.oldValue,e.newValue=t.newValue,e}isNull(){return this.oldValue===this.newValue}run(t){var e=this.getEventWorkspace_();if(!this.blockId)throw Error("The block ID is undefined. Either pass a block to the constructor, or call fromJson");if(!(e=e.getBlockById(this.blockId)))throw Error("The associated block is undefined. Either pass a block to the constructor, or call fromJson");t=t?this.newValue:this.oldValue,(e=e.getField(this.name))?e.setValue(t):console.warn("Can't set non-existent field: "+this.name)}};t(Mr.EVENT,Jr,Bp);var Pp=class extends Dh{constructor(t){super(t),this.type=Ar.MOVE$$module$build$src$core$events$utils,t&&(t.isShadow()&&(this.recordUndo=!1),t=this.currentLocation_(),this.oldParentId=t.parentId,this.oldInputName=t.inputName,this.oldCoordinate=t.coordinate)}toJson(){const t=super.toJson();return t.oldParentId=this.oldParentId,t.oldInputName=this.oldInputName,this.oldCoordinate&&(t.oldCoordinate=`${Math.round(this.oldCoordinate.x)}, ${Math.round(this.oldCoordinate.y)}`),t.newParentId=this.newParentId,t.newInputName=this.newInputName,this.newCoordinate&&(t.newCoordinate=`${Math.round(this.newCoordinate.x)}, ${Math.round(this.newCoordinate.y)}`),this.reason&&(t.reason=this.reason),this.recordUndo||(t.recordUndo=this.recordUndo),t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Pp)).oldParentId=t.oldParentId,e.oldInputName=t.oldInputName,t.oldCoordinate&&(s=t.oldCoordinate.split(","),e.oldCoordinate=new la(Number(s[0]),Number(s[1]))),e.newParentId=t.newParentId,e.newInputName=t.newInputName,t.newCoordinate&&(s=t.newCoordinate.split(","),e.newCoordinate=new la(Number(s[0]),Number(s[1]))),void 0!==t.reason&&(e.reason=t.reason),void 0!==t.recordUndo&&(e.recordUndo=t.recordUndo),e}recordNew(){const t=this.currentLocation_();this.newParentId=t.parentId,this.newInputName=t.inputName,this.newCoordinate=t.coordinate}setReason(t){this.reason=t}currentLocation_(){var t=this.getEventWorkspace_();if(!this.blockId)throw Error("The block ID is undefined. Either pass a block to the constructor, or call fromJson");var e=t.getBlockById(this.blockId);if(!e)throw Error("The block associated with the block move event could not be found");t={};const s=e.getParent();return s?(t.parentId=s.id,(e=s.getInputWithBlock(e))&&(t.inputName=e.name)):t.coordinate=e.getRelativeToSurfaceXY(),t}isNull(){return this.oldParentId===this.newParentId&&this.oldInputName===this.newInputName&&la.equals(this.oldCoordinate,this.newCoordinate)}run(t){var e=this.getEventWorkspace_();if(!this.blockId)throw Error("The block ID is undefined. Either pass a block to the constructor, or call fromJson");var s=e.getBlockById(this.blockId);if(s){var i=t?this.newParentId:this.oldParentId,o=t?this.newInputName:this.oldInputName;if(t=t?this.newCoordinate:this.oldCoordinate,i){var n=e.getBlockById(i);if(!n)return void console.warn("Can't connect to non-existent block: "+i)}if(s.getParent()&&s.unplug(),t)o=s.getRelativeToSurfaceXY(),s.moveBy(t.x-o.x,t.y-o.y,this.reason);else{let t,i;(!(e=s.outputConnection)||s.previousConnection&&s.previousConnection.isConnected())&&(e=s.previousConnection),s=null==(i=e)?void 0:i.type,o?(s=n.getInput(o))&&(t=s.connection):s===Lh.PREVIOUS_STATEMENT&&(t=n.nextConnection),t&&e?e.connect(t):console.warn("Can't connect to non-existent input: "+o)}}else console.warn("Can't move non-existent block: "+this.blockId)}};t(Mr.EVENT,Ar.MOVE$$module$build$src$core$events$utils,Pp);var Fp,Hp=class extends Cl{constructor(t,e,s){super(t?t.workspace.id:void 0),this.type=ol,t&&(this.blockId=t.id,this.isOpen=e,this.bubbleType=s)}toJson(){const t=super.toJson();if(void 0===this.isOpen)throw Error("Whether this event is for opening the bubble is undefined. Either pass the value to the constructor, or call fromJson");if(!this.bubbleType)throw Error("The type of bubble is undefined. Either pass the value to the constructor, or call fromJson");return t.isOpen=this.isOpen,t.bubbleType=this.bubbleType,t.blockId=this.blockId||"",t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Hp)).isOpen=t.isOpen,e.bubbleType=t.bubbleType,e.blockId=t.blockId,e}};!function(t){t.MUTATOR="mutator",t.COMMENT="comment",t.WARNING="warning"}(Fp||(Fp={})),t(Mr.EVENT,ol,Hp);var Gp={};Gp.BubbleOpen=Hp,Gp.BubbleType=Fp;var Up=class extends $l{constructor(t){super(),this.isBlank=!t,t&&(this.commentId=t.id,this.workspaceId=t.workspace.id,this.group=Ar.getGroup$$module$build$src$core$events$utils(),this.recordUndo=I())}toJson(){const t=super.toJson();if(!this.commentId)throw Error("The comment ID is undefined. Either pass a comment to the constructor, or call fromJson");return t.commentId=this.commentId,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Up)).commentId=t.commentId,e}static CommentCreateDeleteHelper(t,e){var s=t.getEventWorkspace_();if(e){if(e=Ar.createElement$$module$build$src$core$utils$xml("xml"),!t.xml)throw Error("Ecountered a comment event without proper xml");e.appendChild(t.xml),Ar.domToWorkspace$$module$build$src$core$xml(e,s)}else{if(!t.commentId)throw Error("The comment ID is undefined. Either pass a comment to the constructor, or call fromJson");(s=s.getCommentById(t.commentId))?s.dispose():console.warn("Can't uncreate non-existent comment: "+t.commentId)}}},Wp=class extends Up{constructor(t,e,s){super(t),this.type=ul,t&&(this.oldContents_=void 0===e?"":e,this.newContents_=void 0===s?"":s)}toJson(){const t=super.toJson();if(!this.oldContents_)throw Error("The old contents is undefined. Either pass a value to the constructor, or call fromJson");if(!this.newContents_)throw Error("The new contents is undefined. Either pass a value to the constructor, or call fromJson");return t.oldContents=this.oldContents_,t.newContents=this.newContents_,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Wp)).oldContents_=t.oldContents,e.newContents_=t.newContents,e}isNull(){return this.oldContents_===this.newContents_}run(t){var e=this.getEventWorkspace_();if(!this.commentId)throw Error("The comment ID is undefined. Either pass a comment to the constructor, or call fromJson");if(e=e.getCommentById(this.commentId)){var s=t?this.newContents_:this.oldContents_;if(!s){if(t)throw Error("The new contents is undefined. Either pass a value to the constructor, or call fromJson");throw Error("The old contents is undefined. Either pass a value to the constructor, or call fromJson")}e.setContent(s)}else console.warn("Can't change non-existent comment: "+this.commentId)}};t(Mr.EVENT,ul,Wp);var Vp=class extends Up{constructor(t){super(t),this.type=hl,t&&(this.xml=t.toXmlWithXY())}toJson(){const t=super.toJson();if(!this.xml)throw Error("The comment XML is undefined. Either pass a comment to the constructor, or call fromJson");return t.xml=Me(this.xml),t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Vp)).xml=Ar.textToDom$$module$build$src$core$utils$xml(t.xml),e}run(t){Up.CommentCreateDeleteHelper(this,t)}};t(Mr.EVENT,hl,Vp);var zp=class extends Up{constructor(t){super(t),this.type=cl,t&&(this.xml=t.toXmlWithXY())}run(t){Up.CommentCreateDeleteHelper(this,!t)}toJson(){const t=super.toJson();if(!this.xml)throw Error("The comment XML is undefined. Either pass a comment to the constructor, or call fromJson");return t.xml=Me(this.xml),t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new zp)).xml=Ar.textToDom$$module$build$src$core$utils$xml(t.xml),e}};t(Mr.EVENT,cl,zp);var Xp=class extends Up{constructor(t){super(t),this.type=dl,t&&(this.comment_=t,this.oldCoordinate_=t.getRelativeToSurfaceXY())}recordNew(){if(this.newCoordinate_)throw Error("Tried to record the new position of a comment on the same event twice.");if(!this.comment_)throw Error("The comment is undefined. Pass a comment to the constructor if you want to use the record functionality");this.newCoordinate_=this.comment_.getRelativeToSurfaceXY()}setOldCoordinate(t){this.oldCoordinate_=t}toJson(){const t=super.toJson();if(!this.oldCoordinate_)throw Error("The old comment position is undefined. Either pass a comment to the constructor, or call fromJson");if(!this.newCoordinate_)throw Error("The new comment position is undefined. Either call recordNew, or call fromJson");return t.oldCoordinate=`${Math.round(this.oldCoordinate_.x)}, ${Math.round(this.oldCoordinate_.y)}`,t.newCoordinate=Math.round(this.newCoordinate_.x)+","+Math.round(this.newCoordinate_.y),t}static fromJson(t,e,s){return e=super.fromJson(t,e,null!=s?s:new Xp),s=t.oldCoordinate.split(","),e.oldCoordinate_=new la(Number(s[0]),Number(s[1])),s=t.newCoordinate.split(","),e.newCoordinate_=new la(Number(s[0]),Number(s[1])),e}isNull(){return la.equals(this.oldCoordinate_,this.newCoordinate_)}run(t){var e=this.getEventWorkspace_();if(!this.commentId)throw Error("The comment ID is undefined. Either pass a comment to the constructor, or call fromJson");if(e=e.getCommentById(this.commentId)){if(!(t=t?this.newCoordinate_:this.oldCoordinate_))throw Error("Either oldCoordinate_ or newCoordinate_ is undefined. Either pass a comment to the constructor and call recordNew, or call fromJson");var s=e.getRelativeToSurfaceXY();e.moveBy(t.x-s.x,t.y-s.y)}else console.warn("Can't move non-existent comment: "+this.commentId)}};t(Mr.EVENT,dl,Xp);var Yp=class extends Cl{constructor(t,e,s){super(s),this.type=rl,this.oldItem=null!=t?t:void 0,this.newItem=null!=e?e:void 0}toJson(){const t=super.toJson();return t.oldItem=this.oldItem,t.newItem=this.newItem,t}static fromJson(t,e,s){return(e=super.fromJson(t,e,null!=s?s:new Yp)).oldItem=t.oldItem,e.newItem=t.newItem,e}};t(Mr.EVENT,rl,Yp);Ar.CHANGE$$module$build$src$core$events$utils,Ar.CREATE$$module$build$src$core$events$utils,Ar.DELETE$$module$build$src$core$events$utils,Ar.MOVE$$module$build$src$core$events$utils,Ar.CHANGE$$module$build$src$core$events$utils,Ar.CREATE$$module$build$src$core$events$utils,Ar.DELETE$$module$build$src$core$events$utils,Ar.MOVE$$module$build$src$core$events$utils,Ar.disable$$module$build$src$core$events$utils,Ar.enable$$module$build$src$core$events$utils,Ar.getGroup$$module$build$src$core$events$utils,Ar.setGroup$$module$build$src$core$events$utils;var Kp={};Kp.Abstract=$l,Kp.BLOCK_CHANGE=Ar.CHANGE$$module$build$src$core$events$utils,Kp.BLOCK_CREATE=Ar.CREATE$$module$build$src$core$events$utils,Kp.BLOCK_DELETE=Ar.DELETE$$module$build$src$core$events$utils,Kp.BLOCK_DRAG=tl,Kp.BLOCK_FIELD_INTERMEDIATE_CHANGE=Jr,Kp.BLOCK_MOVE=Ar.MOVE$$module$build$src$core$events$utils,Kp.BUBBLE_OPEN=ol,Kp.BUMP_EVENTS=gl,Kp.BlockBase=Dh,Kp.BlockChange=hu,Kp.BlockCreate=Ah,Kp.BlockDelete=Yd,Kp.BlockDrag=Op,Kp.BlockFieldIntermediateChange=Bp,Kp.BlockMove=Pp,Kp.BubbleOpen=Hp,Kp.BubbleType=Fp,Kp.CHANGE=Ar.CHANGE$$module$build$src$core$events$utils,Kp.CLICK=sl,Kp.COMMENT_CHANGE=ul,Kp.COMMENT_CREATE=hl,Kp.COMMENT_DELETE=cl,Kp.COMMENT_MOVE=dl,Kp.CREATE=Ar.CREATE$$module$build$src$core$events$utils,Kp.Click=vl,Kp.ClickTarget=wl,Kp.CommentBase=Up,Kp.CommentChange=Wp,Kp.CommentCreate=Vp,Kp.CommentDelete=zp,Kp.CommentMove=Xp,Kp.DELETE=Ar.DELETE$$module$build$src$core$events$utils,Kp.FINISHED_LOADING=pl,Kp.FinishedLoading=Np,Kp.MARKER_MOVE=il,Kp.MOVE=Ar.MOVE$$module$build$src$core$events$utils,Kp.MarkerMove=kd,Kp.SELECTED=el,Kp.Selected=ah,Kp.THEME_CHANGE=ll,Kp.TOOLBOX_ITEM_SELECT=rl,Kp.TRASHCAN_OPEN=nl,Kp.ThemeChange=Oh,Kp.ToolboxItemSelect=Yp,Kp.TrashcanOpen=Xd,Kp.UI=Qr,Kp.UiBase=Cl,Kp.VAR_CREATE=jr,Kp.VAR_DELETE=Zr,Kp.VAR_RENAME=qr,Kp.VIEWPORT_CHANGE=al,Kp.VarBase=th,Kp.VarCreate=eh,Kp.VarDelete=Pd,Kp.VarRename=Fd,Kp.ViewportChange=xh,Kp.clearPendingUndo=N,Kp.disable=Ar.disable$$module$build$src$core$events$utils,Kp.disableOrphans=P,Kp.enable=Ar.enable$$module$build$src$core$events$utils,Kp.filter=A,Kp.fire=S,Kp.fromJson=M,Kp.get=B,Kp.getDescendantIds=L,Kp.getGroup=Ar.getGroup$$module$build$src$core$events$utils,Kp.getRecordUndo=I,Kp.isEnabled=O,Kp.setGroup=Ar.setGroup$$module$build$src$core$events$utils,Kp.setRecordUndo=v;var Jp=class extends ud{constructor(){super(),this.GRID_UNIT=4,this.CURSOR_COLOUR="#ffa200",this.CURSOR_RADIUS=5,this.JAGGED_TEETH_WIDTH=this.JAGGED_TEETH_HEIGHT=0,this.START_HAT_HEIGHT=22,this.START_HAT_WIDTH=96,this.SHAPES={HEXAGONAL:1,ROUND:2,SQUARE:3,PUZZLE:4,NOTCH:5},this.SHAPE_IN_SHAPE_PADDING={1:{0:5*this.GRID_UNIT,1:2*this.GRID_UNIT,2:5*this.GRID_UNIT,3:5*this.GRID_UNIT},2:{0:3*this.GRID_UNIT,1:3*this.GRID_UNIT,2:1*this.GRID_UNIT,3:2*this.GRID_UNIT},3:{0:2*this.GRID_UNIT,1:2*this.GRID_UNIT,2:2*this.GRID_UNIT,3:2*this.GRID_UNIT}},this.FULL_BLOCK_FIELDS=!0,this.FIELD_TEXT_FONTWEIGHT="bold",this.FIELD_TEXT_FONTFAMILY='"Helvetica Neue", "Segoe UI", Helvetica, sans-serif',this.FIELD_COLOUR_FULL_BLOCK=this.FIELD_TEXTINPUT_BOX_SHADOW=this.FIELD_DROPDOWN_SVG_ARROW=this.FIELD_DROPDOWN_COLOURED_DIV=this.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW=!0,this.SELECTED_GLOW_COLOUR="#fff200",this.SELECTED_GLOW_SIZE=.5,this.REPLACEMENT_GLOW_COLOUR="#fff200",this.REPLACEMENT_GLOW_SIZE=2,this.selectedGlowFilterId="",this.selectedGlowFilter=null,this.replacementGlowFilterId="",this.SQUARED=this.ROUNDED=this.HEXAGONAL=this.replacementGlowFilter=null,this.SMALL_PADDING=this.GRID_UNIT,this.MEDIUM_PADDING=2*this.GRID_UNIT,this.MEDIUM_LARGE_PADDING=3*this.GRID_UNIT,this.LARGE_PADDING=4*this.GRID_UNIT,this.CORNER_RADIUS=1*this.GRID_UNIT,this.NOTCH_WIDTH=9*this.GRID_UNIT,this.NOTCH_HEIGHT=2*this.GRID_UNIT,this.STATEMENT_INPUT_NOTCH_OFFSET=this.NOTCH_OFFSET_LEFT=3*this.GRID_UNIT,this.MIN_BLOCK_WIDTH=2*this.GRID_UNIT,this.MIN_BLOCK_HEIGHT=12*this.GRID_UNIT,this.EMPTY_STATEMENT_INPUT_HEIGHT=6*this.GRID_UNIT,this.TOP_ROW_MIN_HEIGHT=this.CORNER_RADIUS,this.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT=this.LARGE_PADDING,this.BOTTOM_ROW_MIN_HEIGHT=this.CORNER_RADIUS,this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT=6*this.GRID_UNIT,this.STATEMENT_BOTTOM_SPACER=-this.NOTCH_HEIGHT,this.STATEMENT_INPUT_SPACER_MIN_WIDTH=40*this.GRID_UNIT,this.STATEMENT_INPUT_PADDING_LEFT=4*this.GRID_UNIT,this.EMPTY_INLINE_INPUT_PADDING=4*this.GRID_UNIT,this.EMPTY_INLINE_INPUT_HEIGHT=8*this.GRID_UNIT,this.DUMMY_INPUT_MIN_HEIGHT=8*this.GRID_UNIT,this.DUMMY_INPUT_SHADOW_MIN_HEIGHT=6*this.GRID_UNIT,this.CURSOR_WS_WIDTH=20*this.GRID_UNIT,this.FIELD_TEXT_FONTSIZE=3*this.GRID_UNIT,this.FIELD_BORDER_RECT_RADIUS=this.CORNER_RADIUS,this.FIELD_BORDER_RECT_X_PADDING=2*this.GRID_UNIT,this.FIELD_BORDER_RECT_Y_PADDING=1.625*this.GRID_UNIT,this.FIELD_BORDER_RECT_HEIGHT=8*this.GRID_UNIT,this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT=8*this.GRID_UNIT,this.FIELD_DROPDOWN_SVG_ARROW_PADDING=this.FIELD_BORDER_RECT_X_PADDING,this.FIELD_COLOUR_DEFAULT_WIDTH=6*this.GRID_UNIT,this.FIELD_COLOUR_DEFAULT_HEIGHT=8*this.GRID_UNIT,this.FIELD_CHECKBOX_X_OFFSET=1*this.GRID_UNIT,this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH=12*this.GRID_UNIT}setFontConstants_(t){super.setFontConstants_(t),this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT=this.FIELD_BORDER_RECT_HEIGHT=this.FIELD_TEXT_HEIGHT+2*this.FIELD_BORDER_RECT_Y_PADDING}init(){super.init(),this.HEXAGONAL=this.makeHexagonal(),this.ROUNDED=this.makeRounded(),this.SQUARED=this.makeSquared(),this.STATEMENT_INPUT_NOTCH_OFFSET=this.NOTCH_OFFSET_LEFT+this.INSIDE_CORNERS.rightWidth}setDynamicProperties_(t){super.setDynamicProperties_(t),this.SELECTED_GLOW_COLOUR=t.getComponentStyle("selectedGlowColour")||this.SELECTED_GLOW_COLOUR;const e=Number(t.getComponentStyle("selectedGlowSize"));this.SELECTED_GLOW_SIZE=e&&!isNaN(e)?e:this.SELECTED_GLOW_SIZE,this.REPLACEMENT_GLOW_COLOUR=t.getComponentStyle("replacementGlowColour")||this.REPLACEMENT_GLOW_COLOUR,this.REPLACEMENT_GLOW_SIZE=(t=Number(t.getComponentStyle("replacementGlowSize")))&&!isNaN(t)?t:this.REPLACEMENT_GLOW_SIZE}dispose(){super.dispose(),this.selectedGlowFilter&<(this.selectedGlowFilter),this.replacementGlowFilter&<(this.replacementGlowFilter)}makeStartHat(){const t=this.START_HAT_HEIGHT,e=this.START_HAT_WIDTH;return{height:t,width:e,path:Qo("c",[qo(25,-t),qo(71,-t),qo(e,0)])}}makeHexagonal(){function t(t,s,i){var o=t/2;return sn(-(i=i?-1:1)*(o=o>e?e:o),t=(s?-1:1)*t/2)+sn(i*o,t)}const e=this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH;return{type:this.SHAPES.HEXAGONAL,isDynamic:!0,width:t=>(t/=2)>e?e:t,height:t=>t,connectionOffsetY:t=>t/2,connectionOffsetX:t=>-t,pathDown:e=>t(e,!1,!1),pathUp:e=>t(e,!0,!1),pathRightDown:e=>t(e,!1,!0),pathRightUp:e=>t(e,!1,!0)}}makeRounded(){function t(t,e,i){const o=t>s?t-s:0;return rn("a","0 0,1",t=(t>s?s:t)/2,qo((e?-1:1)*t,(e?-1:1)*t))+nn("v",(i?1:-1)*o)+rn("a","0 0,1",t,qo((e?1:-1)*t,(e?-1:1)*t))}const e=this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH,s=2*e;return{type:this.SHAPES.ROUND,isDynamic:!0,width:t=>(t/=2)>e?e:t,height:t=>t,connectionOffsetY:t=>t/2,connectionOffsetX:t=>-t,pathDown:e=>t(e,!1,!1),pathUp:e=>t(e,!0,!1),pathRightDown:e=>t(e,!1,!0),pathRightUp:e=>t(e,!1,!0)}}makeSquared(){function t(t,s,i){return t-=2*e,rn("a","0 0,1",e,qo((s?-1:1)*e,(s?-1:1)*e))+nn("v",(i?1:-1)*t)+rn("a","0 0,1",e,qo((s?1:-1)*e,(s?-1:1)*e))}const e=this.CORNER_RADIUS;return{type:this.SHAPES.SQUARE,isDynamic:!0,width:t=>e,height:t=>t,connectionOffsetY:t=>t/2,connectionOffsetX:t=>-t,pathDown:e=>t(e,!1,!1),pathUp:e=>t(e,!0,!1),pathRightDown:e=>t(e,!1,!0),pathRightUp:e=>t(e,!1,!0)}}shapeFor(t){let e=t.getCheck();switch(!e&&t.targetConnection&&(e=t.targetConnection.getCheck()),t.type){case Lh.INPUT_VALUE:case Lh.OUTPUT_VALUE:if(null!==(t=t.getSourceBlock().getOutputShape()))switch(t){case this.SHAPES.HEXAGONAL:return this.HEXAGONAL;case this.SHAPES.ROUND:return this.ROUNDED;case this.SHAPES.SQUARE:return this.SQUARED}return e&&-1!==e.indexOf("Boolean")?this.HEXAGONAL:(e&&-1!==e.indexOf("Number")||e&&e.indexOf("String"),this.ROUNDED);case Lh.PREVIOUS_STATEMENT:case Lh.NEXT_STATEMENT:return this.NOTCH;default:throw Error("Unknown type")}}makeNotch(){function t(t){return Qo("c",[qo(t*o/2,0),qo(t*o*3/4,r/2),qo(t*o,r)])+on([qo(t*o,n)])+Qo("c",[qo(t*o/4,r/2),qo(t*o/2,r),qo(t*o,r)])+nn("h",t*i)+Qo("c",[qo(t*o/2,0),qo(t*o*3/4,-r/2),qo(t*o,-r)])+on([qo(t*o,-n)])+Qo("c",[qo(t*o/4,-r/2),qo(t*o/2,-r),qo(t*o,-r)])}const e=this.NOTCH_WIDTH,s=this.NOTCH_HEIGHT,i=e/3,o=i/3,n=s/2,r=n/2,l=t(1),a=t(-1);return{type:this.SHAPES.NOTCH,width:e,height:s,pathLeft:l,pathRight:a}}makeInsideCorners(){const t=this.CORNER_RADIUS,e=rn("a","0 0,0",t,qo(-t,t)),s=rn("a","0 0,1",t,qo(-t,t));return{width:t,height:t,pathTop:e,pathBottom:rn("a","0 0,0",t,qo(t,t)),rightWidth:t,rightHeight:t,pathTopRight:s,pathBottomRight:rn("a","0 0,1",t,qo(t,t))}}generateSecondaryColour_(t){return yo("#000",t,.15)||t}generateTertiaryColour_(t){return yo("#000",t,.25)||t}createDom(t,e,s){super.createDom(t,e,s),t=st(ma.DEFS,{},t),e=st(ma.FILTER,{id:"blocklySelectedGlowFilter"+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},t),st(ma.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:this.SELECTED_GLOW_SIZE},e),s=st(ma.FECOMPONENTTRANSFER,{result:"outBlur"},e),st(ma.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},s),st(ma.FEFLOOD,{"flood-color":this.SELECTED_GLOW_COLOUR,"flood-opacity":1,result:"outColor"},e),st(ma.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},e),this.selectedGlowFilterId=e.id,this.selectedGlowFilter=e,t=st(ma.FILTER,{id:"blocklyReplacementGlowFilter"+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},t),st(ma.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:this.REPLACEMENT_GLOW_SIZE},t),e=st(ma.FECOMPONENTTRANSFER,{result:"outBlur"},t),st(ma.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},e),st(ma.FEFLOOD,{"flood-color":this.REPLACEMENT_GLOW_COLOUR,"flood-opacity":1,result:"outColor"},t),st(ma.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},t),st(ma.FECOMPOSITE,{in:"SourceGraphic",in2:"outGlow",operator:"over"},t),this.replacementGlowFilterId=t.id,this.replacementGlowFilter=t}getCSS_(t){return[`${t} .blocklyText,`,`${t} .blocklyFlyoutLabelText {`,`font: ${this.FIELD_TEXT_FONTWEIGHT} ${this.FIELD_TEXT_FONTSIZE}pt ${this.FIELD_TEXT_FONTFAMILY};`,"}",`${t} .blocklyText {`,"fill: #fff;","}",`${t} .blocklyNonEditableText>rect:not(.blocklyDropdownRect),`,`${t} .blocklyEditableText>rect:not(.blocklyDropdownRect) {`,`fill: ${this.FIELD_BORDER_RECT_COLOUR};`,"}",`${t} .blocklyNonEditableText>text,`,`${t} .blocklyEditableText>text,`,`${t} .blocklyNonEditableText>g>text,`,`${t} .blocklyEditableText>g>text {`,"fill: #575E75;","}",`${t} .blocklyFlyoutLabelText {`,"fill: #575E75;","}",`${t} .blocklyText.blocklyBubbleText {`,"fill: #575E75;","}",`${t} .blocklyDraggable:not(.blocklyDisabled)`," .blocklyEditableText:not(.editing):hover>rect,",`${t} .blocklyDraggable:not(.blocklyDisabled)`," .blocklyEditableText:not(.editing):hover>.blocklyPath {","stroke: #fff;","stroke-width: 2;","}",`${t} .blocklyHtmlInput {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,`font-weight: ${this.FIELD_TEXT_FONTWEIGHT};`,"color: #575E75;","}",`${t} .blocklyDropdownText {`,"fill: #fff !important;","}",`${t}.blocklyWidgetDiv .goog-menuitem,`,`${t}.blocklyDropDownDiv .goog-menuitem {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,"}",`${t}.blocklyDropDownDiv .goog-menuitem-content {`,"color: #fff;","}",`${t} .blocklyHighlightedConnectionPath {`,`stroke: ${this.SELECTED_GLOW_COLOUR};`,"}",`${t} .blocklyDisabled > .blocklyOutlinePath {`,`fill: url(#blocklyDisabledPattern${this.randomIdentifier})`,"}",`${t} .blocklyInsertionMarker>.blocklyPath {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,"stroke: none;","}"]}},jp=class extends pd{constructor(t,e){super(t,e)}draw(){const t=this.block_.pathObject;t.beginDrawing(),this.drawOutline_(),this.drawInternals_(),t.setPath(this.outlinePath_+"\n"+this.inlinePath_),this.info_.RTL&&t.flipRTL(),this.recordSizeOnBlock_(),this.info_.outputConnection&&(t.outputShapeType=this.info_.outputConnection.shape.type),t.endDrawing()}drawOutline_(){this.info_.outputConnection&&this.info_.outputConnection.isDynamicShape&&!this.info_.hasStatementInput&&!this.info_.bottomRow.hasNextConnection?(this.drawFlatTop_(),this.drawRightDynamicConnection_(),this.drawFlatBottom_(),this.drawLeftDynamicConnection_()):super.drawOutline_()}drawLeft_(){this.info_.outputConnection&&this.info_.outputConnection.isDynamicShape?this.drawLeftDynamicConnection_():super.drawLeft_()}drawRightSideRow_(t){if(!(0>=t.height)){if(Wu.isSpacer(t)){const i=t.precedesStatement;var e=t.followsStatement;if(i||e){const o=this.constants_.INSIDE_CORNERS;var s=o.rightHeight;return s=t.height-(i?s:0),e=e?o.pathBottomRight:"",t=0=s||0>=e)throw Error("Height and width values of an image field must be greater than 0.");this.size_=new Ea(e,s+Zp.Y_PADDING),this.imageHeight=s,"function"==typeof o&&(this.clickHandler=o),t!==bu.SKIP_SETUP&&(r?this.configure_(r):(this.flipRtl=!!n,this.altText=Io(i)||""),this.setValue(Io(t)))}configure_(t){super.configure_(t),t.flipRtl&&(this.flipRtl=t.flipRtl),t.alt&&(this.altText=Io(t.alt))}initView(){this.imageElement=st(ma.IMAGE,{height:this.imageHeight+"px",width:this.size_.width+"px",alt:this.altText},this.fieldGroup_),this.imageElement.setAttributeNS(da,"xlink:href",this.value_),this.clickHandler&&(this.imageElement.style.cursor="pointer")}updateSize_(){}doClassValidation_(t){return"string"!=typeof t?null:t}doValueUpdate_(t){this.value_=t,this.imageElement&&this.imageElement.setAttributeNS(da,"xlink:href",this.value_)}getFlipRtl(){return this.flipRtl}setAlt(t){t!==this.altText&&(this.altText=t||"",this.imageElement&&this.imageElement.setAttribute("alt",this.altText))}showEditor_(){this.clickHandler&&this.clickHandler(this)}setOnClickHandler(t){this.clickHandler=t}getText_(){return this.altText}static fromJson(t){if(!t.src||!t.width||!t.height)throw Error("src, width, and height values for an image field arerequired. The width and height must be non-zero.");return new this(t.src,t.width,t.height,void 0,void 0,void 0,t)}};Zp.Y_PADDING=1,No("field_image",Zp),Zp.prototype.DEFAULT_VALUE="";var qp=class extends bu{constructor(t,e,s){super(bu.SKIP_SETUP),this.spellcheck_=!0,this.htmlInput_=null,this.isTextValid_=this.isBeingEdited_=!1,this.onKeyInputWrapper_=this.onKeyDownWrapper_=this.valueWhenEditorWasOpened_=null,this.fullBlockClickTarget_=!1,this.workspace_=null,this.SERIALIZABLE=!0,this.CURSOR="text",t!==bu.SKIP_SETUP&&(s&&this.configure_(s),this.setValue(t),e&&this.setValidator(e))}configure_(t){super.configure_(t),void 0!==t.spellcheck&&(this.spellcheck_=t.spellcheck)}initView(){if(!this.getSourceBlock())throw new _u;super.initView(),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot())}isFullBlockField(){const t=this.getSourceBlock();if(!t)throw new _u;let e;return this.fullBlockClickTarget_=!(null==(e=this.getConstants())||!e.FULL_BLOCK_FIELDS)&&t.isSimpleReporter()}doValueInvalid_(t){this.isBeingEdited_&&(this.isDirty_=!0,this.isTextValid_=!1,t=this.value_,this.value_=this.htmlInput_.getAttribute("data-untyped-default-value"),this.sourceBlock_&&O()&&S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(this.sourceBlock_,"field",this.name||null,t,this.value_)))}doValueUpdate_(t){this.isTextValid_=this.isDirty_=!0,this.value_=t}applyColour(){const t=this.getSourceBlock();if(!t)throw new _u;this.getConstants().FULL_BLOCK_FIELDS&&this.fieldGroup_&&(!this.isFullBlockField()&&this.borderRect_?(this.borderRect_.style.display="block",this.borderRect_.setAttribute("stroke",t.style.colourTertiary)):(this.borderRect_.style.display="none",t.pathObject.svgPath.setAttribute("fill",this.getConstants().FIELD_BORDER_RECT_COLOUR)))}getSize(){let t;return null!=(t=this.getConstants())&&t.FULL_BLOCK_FIELDS&&(this.render_(),this.isDirty_=!1),super.getSize()}onLocationChange(){this.isBeingEdited_&&this.resizeEditor_()}render_(){if(super.render_(),this.isBeingEdited_){var t=this.htmlInput_;this.isTextValid_?(nt(t,"blocklyInvalidInput"),Ls(t,Vh.INVALID,!1)):(it(t,"blocklyInvalidInput"),Ls(t,Vh.INVALID,!0))}if(!(t=this.getSourceBlock()))throw new _u;this.getConstants().FULL_BLOCK_FIELDS&&t.applyColour()}setSpellcheck(t){t!==this.spellcheck_&&(this.spellcheck_=t,this.htmlInput_&&this.htmlInput_.setAttribute("spellcheck",this.spellcheck_))}showEditor_(t,e=!1){this.workspace_=this.sourceBlock_.workspace,!e&&this.workspace_.options.modalInputs&&(jl||Xl||Yl)?this.showPromptEditor_():this.showInlineEditor_(e)}showPromptEditor_(){Qt(Ar.Msg$$module$build$src$core$msg.CHANGE_VALUE_TITLE,this.getText(),(t=>{null!==t&&this.setValue(this.getValueFromEditorText_(t)),this.onFinishEditing_(this.value_)}))}showInlineEditor_(t){const e=this.getSourceBlock();if(!e)throw new _u;Fs(this,e.RTL,this.widgetDispose_.bind(this)),this.htmlInput_=this.widgetCreate_(),this.isBeingEdited_=!0,this.valueWhenEditorWasOpened_=this.value_,t||(this.htmlInput_.focus({preventScroll:!0}),this.htmlInput_.select())}widgetCreate_(){var t=this.getSourceBlock();if(!t)throw new _u;Ar.setGroup$$module$build$src$core$events$utils(!0);const e=Ms();var s=this.getClickTarget_();if(!s)throw Error("A click target has not been set.");it(s,"editing"),(s=document.createElement("input")).className="blocklyHtmlInput",s.setAttribute("spellcheck",this.spellcheck_);const i=this.workspace_.getScale();var o=this.getConstants().FIELD_TEXT_FONTSIZE*i+"pt";return e.style.fontSize=o,s.style.fontSize=o,o=qp.BORDERRADIUS*i+"px",this.isFullBlockField()&&(o=((o=this.getScaledBBox()).bottom-o.top)/2+"px",t=t.getParent()?t.getParent().style.colourTertiary:this.sourceBlock_.style.colourTertiary,s.style.border=1*i+"px solid "+t,e.style.borderRadius=o,e.style.transition="box-shadow 0.25s ease 0s",this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW&&(e.style.boxShadow="rgba(255, 255, 255, 0.3) 0 0 0 "+4*i+"px")),s.style.borderRadius=o,e.appendChild(s),s.value=s.defaultValue=this.getEditorText_(this.value_),s.setAttribute("data-untyped-default-value",String(this.value_)),this.resizeEditor_(),this.bindInputEvents_(s),s}widgetDispose_(){this.isBeingEdited_=!1,this.isTextValid_=!0,this.forceRerender(),this.onFinishEditing_(this.value_),this.sourceBlock_&&O()&&null!==this.valueWhenEditorWasOpened_&&this.valueWhenEditorWasOpened_!==this.value_&&(S(new(B(Ar.CHANGE$$module$build$src$core$events$utils))(this.sourceBlock_,"field",this.name||null,this.valueWhenEditorWasOpened_,this.value_)),this.valueWhenEditorWasOpened_=null),Ar.setGroup$$module$build$src$core$events$utils(!1),this.unbindInputEvents_();var t=Ms().style;if(t.width="auto",t.height="auto",t.fontSize="",t.transition="",t.boxShadow="",this.htmlInput_=null,!(t=this.getClickTarget_()))throw Error("A click target has not been set.");nt(t,"editing")}onFinishEditing_(t){}bindInputEvents_(t){this.onKeyDownWrapper_=z(t,"keydown",this,this.onHtmlInputKeyDown_),this.onKeyInputWrapper_=z(t,"input",this,this.onHtmlInputChange_)}unbindInputEvents_(){this.onKeyDownWrapper_&&(Y(this.onKeyDownWrapper_),this.onKeyDownWrapper_=null),this.onKeyInputWrapper_&&(Y(this.onKeyInputWrapper_),this.onKeyInputWrapper_=null)}onHtmlInputKeyDown_(t){"Enter"===t.key?(Hs(),Ri()):"Escape"===t.key?(this.setValue(this.htmlInput_.getAttribute("data-untyped-default-value")),Hs(),Ri()):"Tab"===t.key&&(Hs(),Ri(),this.sourceBlock_.tab(this,!t.shiftKey),t.preventDefault())}onHtmlInputChange_(t){t=this.value_,this.setValue(this.getValueFromEditorText_(this.htmlInput_.value),!1),this.sourceBlock_&&O()&&this.value_!==t&&S(new(B(Jr))(this.sourceBlock_,this.name||null,t,this.value_))}setEditorValue_(t,e=!0){this.isDirty_=!0,this.isBeingEdited_&&(this.htmlInput_.value=this.getEditorText_(t)),this.setValue(t,e)}resizeEditor_(){var t=this.getSourceBlock();if(!t)throw new _u;const e=Ms(),s=this.getScaledBBox();e.style.width=s.right-s.left+"px",e.style.height=s.bottom-s.top+"px",t=new la(t.RTL?s.right-e.offsetWidth:s.left,s.top),e.style.left=t.x+"px",e.style.top=t.y+"px"}repositionForWindowResize(){const t=this.getSourceBlock();return t instanceof sp&&(Kn(this.workspace_,this.workspace_.getMetricsManager().getViewMetrics(!0),t)||this.resizeEditor_(),!0)}isTabNavigable(){return!0}getText_(){return this.isBeingEdited_&&this.htmlInput_?this.htmlInput_.value:null}getEditorText_(t){return`${t}`}getValueFromEditorText_(t){return t}};qp.BORDERRADIUS=4;var Qp=class extends qp{constructor(t,e,s){super(t,e,s)}doClassValidation_(t){return void 0===t?null:`${t}`}static fromJson(t){return new this(Io(t.text),void 0,t)}};No("field_input",Qp),Qp.prototype.DEFAULT_VALUE="";var tg=class extends Xu{constructor(t){super(t)}endsWithElemSpacer(){return!1}hasLeftSquareCorner(t){return!!t.outputConnection}hasRightSquareCorner(t){return!!t.outputConnection&&!t.statementInputCount&&!t.nextConnection}},eg=class extends ed{constructor(t,e){if(super(t,e),this.connectedBottomNextConnection=!1,this.connectedBlock){for(t=this.connectedBlock;e=t.getNextBlock();)t=e;t.nextConnection||(this.height=this.connectedBlockHeight,this.connectedBottomNextConnection=!0)}}},sg=class extends Vu{constructor(t){super(t),this.width=this.height=0,this.type|=Wu.getType("RIGHT_CONNECTION")}},ig=class extends cd{constructor(t){super(t)}endsWithElemSpacer(){return!1}hasLeftSquareCorner(t){const e=(t.hat?"cap"===t.hat:this.constants_.ADD_START_HATS)&&!t.outputConnection&&!t.previousConnection;return!!t.outputConnection||e}hasRightSquareCorner(t){return!!t.outputConnection&&!t.statementInputCount&&!t.nextConnection}},og=class extends Ed{constructor(t,e){super(t,e),this.isInline=!0,this.renderer_=t,this.constants_=this.renderer_.getConstants(),this.topRow=new ig(this.constants_),this.bottomRow=new tg(this.constants_),this.isMultiRow=!e.getInputsInline()||e.isCollapsed(),this.hasStatementInput=0=this.rows.length-1?!!this.bottomRow.hasNextConnection:!!i.precedesStatement,Wu.isInputRow(n)&&n.hasStatement){let s,i;n.measure(),e=n.width-(null!=(i=null==(s=n.getLastInput())?void 0:s.width)?i:0)+t}else if(s&&(2===o||i)&&Wu.isInputRow(n)&&!n.hasStatement){i=n.xPos,s=null;for(let t=0;ts?s:this.height/2)*(1-Math.sin(Math.acos((s-this.constants_.SMALL_PADDING)/s)));return 0}if(Wu.isInlineInput(t)&&t instanceof Ku){const o=t.connectedBlock;return null==(t=o?o.pathObject.outputShapeType:t.shape.type)||o&&o.outputConnection&&(o.statementInputCount||o.nextConnection)||s===i.SHAPES.HEXAGONAL&&s!==t?0:e-this.constants_.SHAPE_IN_SHAPE_PADDING[s][t]}return Wu.isField(t)&&t instanceof ju?s===i.SHAPES.ROUND&&t.field instanceof Qp?e-2.75*i.GRID_UNIT:e-this.constants_.SHAPE_IN_SHAPE_PADDING[s][0]:Wu.isIcon(t)?this.constants_.SMALL_PADDING:0}finalizeVerticalAlignment_(){if(!this.outputConnection)for(let i=2;i=this.rows.length-1?!!this.bottomRow.hasNextConnection:!!r.precedesStatement;if(t?this.topRow.hasPreviousConnection:o.followsStatement){var s=n.elements[1];if(s=3===n.elements.length&&s instanceof ju&&(s.field instanceof gd||s.field instanceof Zp),!t&&s)o.height-=this.constants_.SMALL_PADDING,r.height-=this.constants_.SMALL_PADDING,n.height-=this.constants_.MEDIUM_PADDING;else if(t||e){if(e){for(t=!1,e=0;ee;e+=15)st(ma.LINE,{x1:ug.HALF+ug.RADIUS,y1:ug.HALF,x2:ug.HALF+ug.RADIUS-(0==e%45?10:5),y2:ug.HALF,class:"blocklyAngleMarks",transform:"rotate("+e+","+ug.HALF+","+ug.HALF+")"},t);return this.boundEvents.push(z(t,"click",this,this.hide)),this.boundEvents.push(z(e,"pointerdown",this,this.onMouseMove_,!0)),this.boundEvents.push(z(e,"pointermove",this,this.onMouseMove_,!0)),t}dropdownDispose(){for(const t of this.boundEvents)Y(t);this.boundEvents.length=0,this.line=this.gauge=null}hide(){Ii(this),Hs()}onMouseMove_(t){var e=this.gauge.ownerSVGElement.getBoundingClientRect();const s=t.clientX-e.left-ug.HALF;t=t.clientY-e.top-ug.HALF,e=Math.atan(-t/s),isNaN(e)||(e=ai(e),0>s?e+=180:0(t%=360)&&(t+=360),t>this.wrap&&(t-=360),t}static fromJson(t){return new this(t.angle,void 0,t)}};ug.HALF=50,ug.RADIUS=ug.HALF-1,ug.CLOCKWISE=!1,ug.OFFSET=0,ug.WRAP=360,ug.ROUND=15,No("field_angle",ug),ug.prototype.DEFAULT_VALUE=0,Q("\n.blocklyAngleCircle {\n stroke: #444;\n stroke-width: 1;\n fill: #ddd;\n fill-opacity: 0.8;\n}\n\n.blocklyAngleMarks {\n stroke: #444;\n stroke-width: 1;\n}\n\n.blocklyAngleGauge {\n fill: #f88;\n fill-opacity: 0.8;\n pointer-events: none;\n}\n\n.blocklyAngleLine {\n stroke: #f00;\n stroke-width: 2;\n stroke-linecap: round;\n pointer-events: none;\n}\n"),function(t){t.COMPASS="compass",t.PROTRACTOR="protractor"}(cg||(cg={}));var dg={};dg.FieldAngle=ug,dg.Mode=cg;var pg=class extends bu{constructor(t,e,s){super(bu.SKIP_SETUP),this.SERIALIZABLE=!0,this.CURSOR="default",this.value_=this.value_,this.checkChar=pg.CHECK_CHAR,t!==bu.SKIP_SETUP&&(s&&this.configure_(s),this.setValue(t),e&&this.setValidator(e))}configure_(t){super.configure_(t),t.checkCharacter&&(this.checkChar=t.checkCharacter)}saveState(){const t=this.saveLegacyState(pg);return null!==t?t:this.getValueBoolean()}initView(){super.initView();const t=this.getTextElement();it(t,"blocklyCheckbox"),t.style.display=this.value_?"block":"none"}render_(){this.textContent_&&(this.textContent_.nodeValue=this.getDisplayText_()),this.updateSize_(this.getConstants().FIELD_CHECKBOX_X_OFFSET)}getDisplayText_(){return this.checkChar}setCheckCharacter(t){this.checkChar=t||pg.CHECK_CHAR,this.forceRerender()}showEditor_(){this.setValue(!this.value_)}doClassValidation_(t){return!0===t||"TRUE"===t?"TRUE":!1===t||"FALSE"===t?"FALSE":null}doValueUpdate_(t){this.value_=this.convertValueToBool_(t),this.textElement_&&(this.textElement_.style.display=this.value_?"block":"none")}getValue(){return this.value_?"TRUE":"FALSE"}getValueBoolean(){return this.value_}getText(){return String(this.convertValueToBool_(this.value_))}convertValueToBool_(t){return"string"==typeof t?"TRUE"===t:!!t}static fromJson(t){return new this(t.checked,void 0,t)}};pg.CHECK_CHAR="✓",No("field_checkbox",pg),pg.prototype.DEFAULT_VALUE=!1;var gg=class extends bu{constructor(t,e,s){super(bu.SKIP_SETUP),this.highlightedIndex=this.picker=null,this.boundEvents=[],this.SERIALIZABLE=!0,this.CURSOR="default",this.isDirty_=!1,this.titles=this.colours=null,this.columns=0,t!==bu.SKIP_SETUP&&(s&&this.configure_(s),this.setValue(t),e&&this.setValidator(e))}configure_(t){super.configure_(t),t.colourOptions&&(this.colours=t.colourOptions),t.colourTitles&&(this.titles=t.colourTitles),t.columns&&(this.columns=t.columns)}initView(){this.size_=new Ea(this.getConstants().FIELD_COLOUR_DEFAULT_WIDTH,this.getConstants().FIELD_COLOUR_DEFAULT_HEIGHT),this.createBorderRect_(),this.getBorderRect().style.fillOpacity="1",this.getBorderRect().setAttribute("stroke","#fff"),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot())}isFullBlockField(){const t=this.getSourceBlock();if(!t)throw new _u;const e=this.getConstants();return t.isSimpleReporter()&&!(null==e||!e.FIELD_COLOUR_FULL_BLOCK)}applyColour(){const t=this.getSourceBlock();if(!t)throw new _u;if(this.fieldGroup_){var e=this.borderRect_;if(!e)throw Error("The border rect has not been initialized");this.isFullBlockField()?(e.style.display="none",t.pathObject.svgPath.setAttribute("fill",this.getValue()),t.pathObject.svgPath.setAttribute("stroke","#fff")):(e.style.display="block",e.style.fill=this.getValue())}}getSize(){let t;return null!=(t=this.getConstants())&&t.FIELD_COLOUR_FULL_BLOCK&&(this.render_(),this.isDirty_=!1),super.getSize()}render_(){super.render_();const t=this.getSourceBlock();if(!t)throw new _u;t.applyColour()}updateSize_(t){var e=this.getConstants();this.isFullBlockField()?(t=2*(null!=t?t:0),e=e.FIELD_TEXT_HEIGHT):(t=e.FIELD_COLOUR_DEFAULT_WIDTH,e=e.FIELD_COLOUR_DEFAULT_HEIGHT),this.size_.height=e,this.size_.width=t,this.positionBorderRect_()}doClassValidation_(t){return"string"!=typeof t?null:Eo(t)}getText(){let t=this.value_;return/^#(.)\1(.)\2(.)\3$/.test(t)&&(t="#"+t[1]+t[3]+t[5]),t}setColours(t,e){return this.colours=t,e&&(this.titles=e),this}setColumns(t){return this.columns=t,this}showEditor_(){this.dropdownCreate(),pi().appendChild(this.picker),mi(this,this.dropdownDispose.bind(this)),this.picker.focus({preventScroll:!0})}onClick(t){null!==(t=(t=t.target)&&t.getAttribute("data-colour"))&&(this.setValue(t),Ii(this))}onKeyDown(t){let e=!0;var s;switch(t.key){case"ArrowUp":this.moveHighlightBy(0,-1);break;case"ArrowDown":this.moveHighlightBy(0,1);break;case"ArrowLeft":this.moveHighlightBy(-1,0);break;case"ArrowRight":this.moveHighlightBy(1,0);break;case"Enter":(s=this.getHighlighted())&&(null!==(s=s.getAttribute("data-colour"))&&this.setValue(s)),Ri();break;default:e=!1}e&&t.stopPropagation()}moveHighlightBy(t,e){if(this.highlightedIndex){var s=this.colours||gg.COLOURS,i=this.columns||gg.COLUMNS,o=this.highlightedIndex%i,n=Math.floor(this.highlightedIndex/i);o+=t,n+=e,0>t?0>o&&0o&&(o=0):0i-1&&ni-1&&o--:0>e?0>n&&(n=0):0Math.floor(s.length/i)-1&&(n=Math.floor(s.length/i)-1),this.setHighlightedCell(this.picker.childNodes[n].childNodes[o],n*i+o)}}onMouseMove(t){const e=(t=t.target)&&Number(t.getAttribute("data-index"));null!==e&&e!==this.highlightedIndex&&this.setHighlightedCell(t,e)}onMouseEnter(){let t;null==(t=this.picker)||t.focus({preventScroll:!0})}onMouseLeave(){var t;null==(t=this.picker)||t.blur(),(t=this.getHighlighted())&&nt(t,"blocklyColourHighlighted")}getHighlighted(){if(!this.highlightedIndex)return null;const t=this.columns||gg.COLUMNS,e=this.picker.childNodes[Math.floor(this.highlightedIndex/t)];return e?e.childNodes[this.highlightedIndex%t]:null}setHighlightedCell(t,e){const s=this.getHighlighted();s&&nt(s,"blocklyColourHighlighted"),it(t,"blocklyColourHighlighted"),this.highlightedIndex=e,(t=t.getAttribute("id"))&&this.picker&&Ls(this.picker,Vh.ACTIVEDESCENDANT,t)}dropdownCreate(){const t=this.columns||gg.COLUMNS,e=this.colours||gg.COLOURS,s=this.titles||gg.TITLES,i=this.getValue(),o=document.createElement("table");let n;o.className="blocklyColourTable",o.tabIndex=0,o.dir="ltr",xs(o,Wh.GRID),Ls(o,Vh.EXPANDED,!0),Ls(o,Vh.ROWCOUNT,Math.floor(e.length/t)),Ls(o,Vh.COLCOUNT,t);for(let r=0;rtr>td {\n border: 0.5px solid #888;\n box-sizing: border-box;\n cursor: pointer;\n display: inline-block;\n height: 20px;\n padding: 0;\n width: 20px;\n}\n\n.blocklyColourTable>tr>td.blocklyColourHighlighted {\n border-color: #eee;\n box-shadow: 2px 2px 7px 2px rgba(0, 0, 0, 0.3);\n position: relative;\n}\n\n.blocklyColourSelected, .blocklyColourSelected:hover {\n border-color: #eee !important;\n outline: 1px solid #333;\n position: relative;\n}\n");var bg=class extends gd{constructor(t,e,s){super(String(null!=t?t:""),e,s),this.EDITABLE=!1,this.SERIALIZABLE=!0}static fromJson(t){return new this(Io(t.text),void 0,t)}};No("field_label_serializable",bg);var _g=class extends Qp{constructor(t,e,s){super(bu.SKIP_SETUP),this.textGroup=null,this.maxLines_=1/0,this.isOverflowedY_=!1,t!==bu.SKIP_SETUP&&(s&&this.configure_(s),this.setValue(t),e&&this.setValidator(e))}configure_(t){super.configure_(t),t.maxLines&&this.setMaxLines(t.maxLines)}toXml(t){return t.textContent=this.getValue().replace(/\n/g,"
"),t}fromXml(t){this.setValue(t.textContent.replace(/
/g,"\n"))}saveState(){const t=this.saveLegacyState(_g);return null!==t?t:this.getValue()}loadState(t){this.loadLegacyState(bu,t)||this.setValue(t)}initView(){this.createBorderRect_(),this.textGroup=st(ma.G,{class:"blocklyEditableText"},this.fieldGroup_)}getDisplayText_(){const t=this.getSourceBlock();if(!t)throw new _u;let e=this.getText();if(!e)return bu.NBSP;const s=e.split("\n");e="";const i=this.isOverflowedY_?this.maxLines_:s.length;for(let t=0;tthis.maxDisplayLength?o=o.substring(0,this.maxDisplayLength-4)+"...":this.isOverflowedY_&&t===i-1&&(o=o.substring(0,o.length-3)+"..."),o=o.replace(/\s/g,bu.NBSP),e+=o,t!==i-1&&(e+="\n")}return t.RTL&&(e+=""),e}doValueUpdate_(t){super.doValueUpdate_(t),null!==this.value_&&(this.isOverflowedY_=this.value_.split("\n").length>this.maxLines_)}render_(){var t=this.getSourceBlock();if(!t)throw new _u;for(var e,s=this.textGroup;e=s.firstChild;)s.removeChild(e);e=this.getDisplayText_().split("\n");let i=0;for(let t=0;to&&(o=l),n+=this.getConstants().FIELD_TEXT_HEIGHT+(0this.maxDisplayLength&&(t[l]=t[l].substring(0,this.maxDisplayLength)),r.textContent=t[l];const n=gt(r,e,s,i);n>o&&(o=n)}o+=this.htmlInput_.offsetWidth-this.htmlInput_.clientWidth}this.borderRect_&&(n+=2*this.getConstants().FIELD_BORDER_RECT_Y_PADDING,o+=2*this.getConstants().FIELD_BORDER_RECT_X_PADDING,this.borderRect_.setAttribute("width",`${o}`),this.borderRect_.setAttribute("height",`${n}`)),this.size_.width=o,this.size_.height=n,this.positionBorderRect_()}showEditor_(t,e){super.showEditor_(t,e),this.forceRerender()}widgetCreate_(){const t=Ms(),e=this.workspace_.getScale(),s=document.createElement("textarea");s.className="blocklyHtmlInput blocklyHtmlTextAreaInput",s.setAttribute("spellcheck",String(this.spellcheck_));var i=this.getConstants().FIELD_TEXT_FONTSIZE*e+"pt";t.style.fontSize=i,s.style.fontSize=i,s.style.borderRadius=Qp.BORDERRADIUS*e+"px",i=this.getConstants().FIELD_BORDER_RECT_X_PADDING*e;const o=this.getConstants().FIELD_BORDER_RECT_Y_PADDING*e/2;return s.style.padding=o+"px "+i+"px "+o+"px "+i+"px",i=this.getConstants().FIELD_TEXT_HEIGHT+this.getConstants().FIELD_BORDER_RECT_Y_PADDING,s.style.lineHeight=i*e+"px",t.appendChild(s),s.value=s.defaultValue=this.getEditorText_(this.value_),s.setAttribute("data-untyped-default-value",String(this.value_)),s.setAttribute("data-old-value",""),zl?setTimeout(this.resizeEditor_.bind(this),0):this.resizeEditor_(),this.bindInputEvents_(s),s}setMaxLines(t){"number"==typeof t&&0this.max_&&(t.max=`${this.max_}`,Ls(t,Vh.VALUEMAX,this.max_)),t}static fromJson(t){return new this(t.value,void 0,void 0,void 0,void 0,t)}};No("field_number",mg),mg.prototype.DEFAULT_VALUE=0;var fg=class extends wu{constructor(t,e,s,i,o){super(bu.SKIP_SETUP),this.defaultType="",this.variableTypes=[],this.variable=null,this.SERIALIZABLE=!0,this.menuGenerator_=fg.dropdownCreate,this.defaultVariableName="string"==typeof t?t:"",this.size_=new Ea(0,0),t!==bu.SKIP_SETUP&&(o?this.configure_(o):this.setTypes(s,i),e&&this.setValidator(e))}configure_(t){super.configure_(t),this.setTypes(t.variableTypes,t.defaultType)}initModel(){var t=this.getSourceBlock();if(!t)throw new _u;this.variable||(t=Ar.getOrCreateVariablePackage$$module$build$src$core$variables(t.workspace,null,this.defaultVariableName,this.defaultType),this.doValueUpdate_(t.getId()))}shouldAddBorderRect_(){const t=this.getSourceBlock();if(!t)throw new _u;return super.shouldAddBorderRect_()&&(!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW||"variables_get"!==t.type)}fromXml(t){var e=this.getSourceBlock();if(!e)throw new _u;const s=t.getAttribute("id"),i=t.textContent,o=t.getAttribute("variabletype")||t.getAttribute("variableType")||"";if(e=Ar.getOrCreateVariablePackage$$module$build$src$core$variables(e.workspace,s,i,o),null!==o&&o!==e.type)throw Error("Serialized variable type with id '"+e.getId()+"' had type "+e.type+", and does not match variable field that references it: "+Me(t)+".");this.setValue(e.getId())}toXml(t){return this.initModel(),t.id=this.variable.getId(),t.textContent=this.variable.name,this.variable.type&&t.setAttribute("variabletype",this.variable.type),t}saveState(t){var e=this.saveLegacyState(fg);return null!==e||(this.initModel(),e={id:this.variable.getId()},t&&(e.name=this.variable.name,e.type=this.variable.type)),e}loadState(t){const e=this.getSourceBlock();if(!e)throw new _u;this.loadLegacyState(fg,t)||(t=Ar.getOrCreateVariablePackage$$module$build$src$core$variables(e.workspace,t.id||null,t.name,t.type||""),this.setValue(t.getId()))}setSourceBlock(t){if(t.isShadow())throw Error("Variable fields are not allowed to exist on shadow blocks.");super.setSourceBlock(t)}getValue(){return this.variable?this.variable.getId():null}getText(){return this.variable?this.variable.name:""}getVariable(){return this.variable}getValidator(){return this.variable?this.validator_:null}doClassValidation_(t){if(null===t)return null;var e=this.getSourceBlock();if(!e)throw new _u;return(e=Ar.getVariable$$module$build$src$core$variables(e.workspace,t))?(e=e.type,this.typeIsAllowed(e)?t:(console.warn("Variable type doesn't match this field! Type was "+e),null)):(console.warn("Variable id doesn't point to a real variable! ID was "+t),null)}doValueUpdate_(t){const e=this.getSourceBlock();if(!e)throw new _u;this.variable=Ar.getVariable$$module$build$src$core$variables(e.workspace,t),super.doValueUpdate_(t)}typeIsAllowed(t){const e=this.getVariableTypes();if(!e)return!0;for(let s=0;s{const s=this.targetWorkspace.getGesture(e);s&&(s.setStartBlock(t),s.handleFlyoutStart(e,this))}}onMouseDown(t){const e=this.targetWorkspace.getGesture(t);e&&e.handleFlyoutStart(t,this)}isBlockCreatable(t){return t.isEnabled()}createBlock(t){let e=null;Ar.disable$$module$build$src$core$events$utils();var s=this.targetWorkspace.getAllVariables();this.targetWorkspace.setResizesEnabled(!1);try{e=this.placeNewBlock(t)}finally{Ar.enable$$module$build$src$core$events$utils()}if(this.targetWorkspace.hideChaff(),t=fe(this.targetWorkspace,s),O()){for(Ar.setGroup$$module$build$src$core$events$utils(!0),s=0;s90-e||t>-90-e&&t<-90+e}getClientRect(){if(!this.svgGroup_||this.autoClose||!this.isVisible())return null;const t=this.svgGroup_.getBoundingClientRect(),e=t.top;return this.toolboxPosition_===xa.TOP?new fa(-1e9,e+t.height,-1e9,1e9):new fa(e,1e9,-1e9,1e9)}reflowInternal_(){this.workspace_.scale=this.getFlyoutScale();let t=0;const e=this.workspace_.getTopBlocks(!1);for(let s,i=0;s=e[i];i++)t=Math.max(t,s.getHeightWidth().height);const s=this.buttons_;for(let e,i=0;e=s[i];i++)t=Math.max(t,e.height);if(t+=1.5*this.MARGIN,t*=this.workspace_.scale,t+=Ca.scrollbarThickness,this.height_!==t){for(let t,s=0;t=e[s];s++)this.rectMap_.has(t)&&this.moveRectToBlock_(this.rectMap_.get(t),t);this.targetWorkspace.scrollbar||this.autoClose||this.targetWorkspace.getFlyout()!==this||this.toolboxPosition_!==xa.TOP||this.targetWorkspace.translate(this.targetWorkspace.scrollX,this.targetWorkspace.scrollY+t),this.height_=t,this.position(),this.targetWorkspace.resizeContents(),this.targetWorkspace.recordDragTargets()}}};t(Mr.FLYOUTS_HORIZONTAL_TOOLBOX,Lr,yg);var $g=class extends wg{constructor(t){super(t)}setMetrics_(t){if(this.isVisible()){var e=this.workspace_.getMetricsManager(),s=e.getScrollMetrics(),i=e.getViewMetrics();e=e.getAbsoluteMetrics(),"number"==typeof t.y&&(this.workspace_.scrollY=-(s.top+(s.height-i.height)*t.y)),this.workspace_.translate(this.workspace_.scrollX+e.left,this.workspace_.scrollY+e.top)}}getX(){if(!this.isVisible())return 0;var t=this.targetWorkspace.getMetricsManager();const e=t.getAbsoluteMetrics(),s=t.getViewMetrics();return t=t.getToolboxMetrics(),this.targetWorkspace.toolboxPosition===this.toolboxPosition_?this.targetWorkspace.getToolbox()?this.toolboxPosition_===xa.LEFT?t.width:s.width-this.width_:this.toolboxPosition_===xa.LEFT?0:s.width:this.toolboxPosition_===xa.LEFT?0:s.width+e.left-this.width_}getY(){return 0}position(){if(this.isVisible()&&this.targetWorkspace.isVisible()){var t=this.targetWorkspace.getMetricsManager().getViewMetrics();this.height_=t.height,this.setBackgroundPath(this.width_-this.CORNER_RADIUS,t.height-2*this.CORNER_RADIUS),t=this.getX();var e=this.getY();this.positionAt_(this.width_,this.height_,t,e)}}setBackgroundPath(t,e){const s=this.toolboxPosition_===xa.RIGHT;var i=t+this.CORNER_RADIUS;(i=["M "+(s?i:0)+",0"]).push("h",s?-t:t),i.push("a",this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,s?0:1,s?-this.CORNER_RADIUS:this.CORNER_RADIUS,this.CORNER_RADIUS),i.push("v",Math.max(0,e)),i.push("a",this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,s?0:1,s?this.CORNER_RADIUS:-this.CORNER_RADIUS,this.CORNER_RADIUS),i.push("h",s?t:-t),i.push("z"),this.svgBackground_.setAttribute("d",i.join(" "))}scrollToStart(){let t;null==(t=this.workspace_.scrollbar)||t.setY(0)}wheel_(t){var e=Z(t);if(e.y){const t=this.workspace_.getMetricsManager(),s=t.getScrollMetrics();let i;e=t.getViewMetrics().top-s.top+e.y,null==(i=this.workspace_.scrollbar)||i.setY(e),Hs(),Ri()}t.preventDefault(),t.stopPropagation()}layout_(t,e){this.workspace_.scale=this.targetWorkspace.scale;var s=this.MARGIN;const i=this.RTL?s:s+this.tabWidth_;for(let l,a=0;l=t[a];a++)if("block"===l.type){var o=l.block,n=o.getDescendants(!1);for(let t,e=0;t=n[e];e++)t.isInFlyout=!0;n=o.getSvgRoot();const t=o.getHeightWidth();var r=o.outputConnection?i-this.tabWidth_:i;o.moveBy(r,s),r=this.createRect_(o,this.RTL?r-t.width:r,s,t,a),this.addBlockListeners_(n,o,r),s+=t.height+e[a]}else"button"===l.type&&(o=l.button,this.initFlyoutButton_(o,i,s),s+=o.height+e[a])}isDragTowardWorkspace(t){t=Math.atan2(t.y,t.x)/Math.PI*180;const e=this.dragAngleRange_;return t-e||t<-180+e||t>180-e}getClientRect(){if(!this.svgGroup_||this.autoClose||!this.isVisible())return null;const t=this.svgGroup_.getBoundingClientRect(),e=t.left;return this.toolboxPosition_===xa.LEFT?new fa(-1e9,1e9,-1e9,e+t.width):new fa(-1e9,1e9,e,1e9)}reflowInternal_(){this.workspace_.scale=this.getFlyoutScale();let t=0;var e=this.workspace_.getTopBlocks(!1);for(let i,o=0;i=e[o];o++){var s=i.getHeightWidth().width;i.outputConnection&&(s-=this.tabWidth_),t=Math.max(t,s)}for(let e,s=0;e=this.buttons_[s];s++)t=Math.max(t,e.width);if(t+=1.5*this.MARGIN+this.tabWidth_,t*=this.workspace_.scale,t+=Ca.scrollbarThickness,this.width_!==t){for(let i,o=0;i=e[o];o++){if(this.RTL){s=i.getRelativeToSurfaceXY().x;let e=t/this.workspace_.scale-this.MARGIN;i.outputConnection||(e-=this.tabWidth_),i.moveBy(e-s,0)}this.rectMap_.has(i)&&this.moveRectToBlock_(this.rectMap_.get(i),i)}if(this.RTL)for(let s,i=0;s=this.buttons_[i];i++)e=s.getPosition().y,s.moveTo(t/this.workspace_.scale-s.width-this.MARGIN-this.tabWidth_,e);this.targetWorkspace.scrollbar||this.autoClose||this.targetWorkspace.getFlyout()!==this||this.toolboxPosition_!==xa.LEFT||this.targetWorkspace.translate(this.targetWorkspace.scrollX+t,this.targetWorkspace.scrollY),this.width_=t,this.position(),this.targetWorkspace.resizeContents(),this.targetWorkspace.recordDragTargets()}}};$g.registryName="verticalFlyout",t(Mr.FLYOUTS_VERTICAL_TOOLBOX,Lr,$g);Ar.CodeGenerator$$module$build$src$core$generator=class{constructor(t){this.forBlock=Object.create(null),this.FUNCTION_NAME_PLACEHOLDER_="{leCUI8hutHZI4480Dc}",this.STATEMENT_SUFFIX=this.STATEMENT_PREFIX=this.INFINITE_LOOP_TRAP=null,this.INDENT=" ",this.COMMENT_WRAP=60,this.ORDER_OVERRIDES=[],this.isInitialized=null,this.RESERVED_WORDS_="",this.definitions_=Object.create(null),this.functionNames_=Object.create(null),this.nameDB_=void 0,this.name_=t,this.FUNCTION_NAME_PLACEHOLDER_REGEXP_=new RegExp(this.FUNCTION_NAME_PLACEHOLDER_,"g")}workspaceToCode(t){t||(console.warn("No workspace specified in workspaceToCode call. Guessing."),t=p());var e=[];this.init(t),t=t.getTopBlocks(!0);for(let s,i=0;s=t[i];i++){let t=this.blockToCode(s);Array.isArray(t)&&(t=t[0]),t&&(s.outputConnection&&(t=this.scrubNakedValue(t),this.STATEMENT_PREFIX&&!s.suppressPrefixSuffix&&(t=this.injectId(this.STATEMENT_PREFIX,s)+t),this.STATEMENT_SUFFIX&&!s.suppressPrefixSuffix&&(t+=this.injectId(this.STATEMENT_SUFFIX,s))),e.push(t))}return e=e.join("\n"),(e=(e=(e=this.finish(e)).replace(/^\s+\n/,"")).replace(/\n\s+$/,"\n")).replace(/[ \t]+\n/g,"\n")}prefixLines(t,e){return e+t.replace(/(?!\n$)\n/g,"\n"+e)}allNestedComments(t){const e=[];t=t.getDescendants(!0);for(let s=0;s.blocklyPathLight,`,`${t} .blocklyInsertionMarker>.blocklyPathDark {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,"stroke: none;","}"])}},Sg=class{constructor(t){this.inlineSteps_=this.steps_="",this.info_=t,this.RTL_=this.info_.RTL,t=t.getRenderer(),this.constants_=t.getConstants(),this.highlightConstants_=t.getHighlightConstants(),this.highlightOffset=this.highlightConstants_.OFFSET,this.outsideCornerPaths_=this.highlightConstants_.OUTSIDE_CORNER,this.insideCornerPaths_=this.highlightConstants_.INSIDE_CORNER,this.puzzleTabPaths_=this.highlightConstants_.PUZZLE_TAB,this.notchPaths_=this.highlightConstants_.NOTCH,this.startPaths_=this.highlightConstants_.START_HAT,this.jaggedTeethPaths_=this.highlightConstants_.JAGGED_TEETH}getPath(){return this.steps_+"\n"+this.inlineSteps_}drawTopCorner(t){this.steps_+=en(t.xPos,this.info_.startY);for(let e,s=0;e=t.elements[s];s++)Wu.isLeftSquareCorner(e)?this.steps_+=this.highlightConstants_.START_POINT:Wu.isLeftRoundedCorner(e)?this.steps_+=this.outsideCornerPaths_.topLeft(this.RTL_):Wu.isPreviousConnection(e)?this.steps_+=this.notchPaths_.pathLeft:Wu.isHat(e)?this.steps_+=this.startPaths_.path(this.RTL_):Wu.isSpacer(e)&&0!==e.width&&(this.steps_+=nn("H",e.xPos+e.width-this.highlightOffset));this.steps_+=nn("H",t.xPos+t.width-this.highlightOffset)}drawJaggedEdge_(t){this.info_.RTL&&(this.steps_+=this.jaggedTeethPaths_.pathLeft+nn("v",t.height-this.jaggedTeethPaths_.height-this.highlightOffset))}drawValueInput(t){const e=t.getLastInput();if(this.RTL_){const s=t.height-e.connectionHeight;this.steps_+=tn(e.xPos+e.width-this.highlightOffset,t.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)+nn("v",s)}else this.steps_+=tn(e.xPos+e.width,t.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)}drawStatementInput(t){const e=t.getLastInput();if(e)if(this.RTL_){const s=t.height-2*this.insideCornerPaths_.height;this.steps_+=tn(e.xPos,t.yPos)+this.insideCornerPaths_.pathTop(this.RTL_)+nn("v",s)+this.insideCornerPaths_.pathBottom(this.RTL_)+sn(t.width-e.xPos-this.insideCornerPaths_.width,0)}else this.steps_+=tn(e.xPos,t.yPos+t.height)+this.insideCornerPaths_.pathBottom(this.RTL_)+sn(t.width-e.xPos-this.insideCornerPaths_.width,0)}drawRightSideRow(t){const e=t.xPos+t.width-this.highlightOffset;t instanceof ad&&t.followsStatement&&(this.steps_+=nn("H",e)),this.RTL_&&(this.steps_+=nn("H",e),t.height>this.highlightOffset&&(this.steps_+=nn("V",t.yPos+t.height-this.highlightOffset)))}drawBottomRow(t){if(this.RTL_)this.steps_+=nn("V",t.baseline-this.highlightOffset);else{const e=this.info_.bottomRow.elements[0];Wu.isLeftSquareCorner(e)?this.steps_+=tn(t.xPos+this.highlightOffset,t.baseline-this.highlightOffset):Wu.isLeftRoundedCorner(e)&&(this.steps_+=tn(t.xPos,t.baseline),this.steps_+=this.outsideCornerPaths_.bottomLeft())}}drawLeft(){var t=this.info_.outputConnection;t&&(t=t.connectionOffsetY+t.height,this.RTL_?this.steps_+=tn(this.info_.startX,t):(this.steps_+=tn(this.info_.startX+this.highlightOffset,this.info_.bottomRow.baseline-this.highlightOffset),this.steps_+=nn("V",t)),this.steps_+=this.puzzleTabPaths_.pathUp(this.RTL_)),this.RTL_||(t=this.info_.topRow,Wu.isLeftRoundedCorner(t.elements[0])?this.steps_+=nn("V",this.outsideCornerPaths_.height):this.steps_+=nn("V",t.capline+this.highlightOffset))}drawInlineInput(t){const e=this.highlightOffset,s=t.xPos+t.connectionWidth;var i=t.centerline-t.height/2;const o=t.width-t.connectionWidth,n=i+e;this.RTL_?(i=t.connectionOffsetY-e,t=t.height-(t.connectionOffsetY+t.connectionHeight)+e,this.inlineSteps_+=tn(s-e,n)+nn("v",i)+this.puzzleTabPaths_.pathDown(this.RTL_)+nn("v",t)+nn("h",o)):this.inlineSteps_+=tn(t.xPos+t.width+e,n)+nn("v",t.height)+nn("h",-o)+tn(s,i+t.connectionOffsetY)+this.puzzleTabPaths_.pathDown(this.RTL_)}},Rg=class extends pd{constructor(t,e){super(t,e),this.highlighter_=new Sg(e)}draw(){this.drawOutline_(),this.drawInternals_();const t=this.block_.pathObject;t.setPath(this.outlinePath_+"\n"+this.inlinePath_),t.setHighlightPath(this.highlighter_.getPath()),this.info_.RTL&&t.flipRTL(),this.recordSizeOnBlock_()}drawTop_(){this.highlighter_.drawTopCorner(this.info_.topRow),this.highlighter_.drawRightSideRow(this.info_.topRow),super.drawTop_()}drawJaggedEdge_(t){this.highlighter_.drawJaggedEdge_(t),super.drawJaggedEdge_(t)}drawValueInput_(t){this.highlighter_.drawValueInput(t),super.drawValueInput_(t)}drawStatementInput_(t){this.highlighter_.drawStatementInput(t),super.drawStatementInput_(t)}drawRightSideRow_(t){this.highlighter_.drawRightSideRow(t),this.outlinePath_+=nn("H",t.xPos+t.width)+nn("V",t.yPos+t.height)}drawBottom_(){this.highlighter_.drawBottomRow(this.info_.bottomRow),super.drawBottom_()}drawLeft_(){this.highlighter_.drawLeft(),super.drawLeft_()}drawInlineInput_(t){this.highlighter_.drawInlineInput(t),super.drawInlineInput_(t)}positionInlineInputConnection_(t){const e=t.centerline-t.height/2;if(t.connectionModel){let s=t.xPos+t.connectionWidth+this.constants_.DARK_PATH_OFFSET;this.info_.RTL&&(s*=-1),t.connectionModel.setOffsetInBlock(s,e+t.connectionOffsetY+this.constants_.DARK_PATH_OFFSET)}}positionStatementInputConnection_(t){const e=t.getLastInput();if(null!=e&&e.connectionModel){let s=t.xPos+t.statementEdge+e.notchOffset;s=this.info_.RTL?-1*s:s+this.constants_.DARK_PATH_OFFSET,e.connectionModel.setOffsetInBlock(s,t.yPos+this.constants_.DARK_PATH_OFFSET)}}positionExternalValueConnection_(t){const e=t.getLastInput();if(e&&e.connectionModel){let s=t.xPos+t.width+this.constants_.DARK_PATH_OFFSET;this.info_.RTL&&(s*=-1),e.connectionModel.setOffsetInBlock(s,t.yPos)}}positionNextConnection_(){const t=this.info_.bottomRow;if(t.connection){const e=t.connection,s=e.xPos;e.connectionModel.setOffsetInBlock((this.info_.RTL?-s:s)+this.constants_.DARK_PATH_OFFSET/2,t.baseline+this.constants_.DARK_PATH_OFFSET)}}},Dg=class{constructor(t){this.OFFSET=.5,this.constantProvider=t,this.START_POINT=en(this.OFFSET,this.OFFSET)}init(){this.INSIDE_CORNER=this.makeInsideCorner(),this.OUTSIDE_CORNER=this.makeOutsideCorner(),this.PUZZLE_TAB=this.makePuzzleTab(),this.NOTCH=this.makeNotch(),this.JAGGED_TEETH=this.makeJaggedTeeth(),this.START_HAT=this.makeStartHat()}makeInsideCorner(){const t=this.constantProvider.CORNER_RADIUS,e=this.OFFSET,s=(1-Math.SQRT1_2)*(t+e)-e,i=en(s,s)+rn("a","0 0,0",t,qo(-s-e,t-s)),o=rn("a","0 0,0",t+e,qo(t+e,t+e)),n=en(s,-s)+rn("a","0 0,0",t+e,qo(t-s,s+e));return{width:t+e,height:t,pathTop:t=>t?i:"",pathBottom:t=>t?o:n}}makeOutsideCorner(){const t=this.constantProvider.CORNER_RADIUS,e=this.OFFSET,s=(1-Math.SQRT1_2)*(t-e)+e,i=en(s,s)+rn("a","0 0,1",t-e,qo(t-s,-s+e)),o=en(e,t)+rn("a","0 0,1",t-e,qo(t,-t+e)),n=-s,r=en(s,n)+rn("a","0 0,1",t-e,qo(-s+e,-n-t));return{height:t,topLeft:t=>t?i:o,bottomLeft:()=>r}}makePuzzleTab(){const t=this.constantProvider.TAB_WIDTH,e=this.constantProvider.TAB_HEIGHT,s=en(-2,3.4-e)+sn(-.45*t,-2.1),i=nn("v",2.5)+en(.97*-t,2.5)+Qo("q",[qo(.05*-t,10),qo(.3*t,9.5)])+en(.67*t,-1.9)+nn("v",2.5),o=nn("v",-1.5)+en(-.92*t,-.5)+Qo("q",[qo(-.19*t,-5.5),qo(0,-11)])+en(.92*t,1),n=en(-5,e-.7)+sn(.46*t,-2.1);return{width:t,height:e,pathUp:t=>t?s:o,pathDown:t=>t?i:n}}makeNotch(){return{pathLeft:nn("h",this.OFFSET)+this.constantProvider.NOTCH.pathLeft}}makeJaggedTeeth(){return{pathLeft:sn(5.1,2.6)+en(-10.2,6.8)+sn(5.1,2.6),height:12,width:10.2}}makeStartHat(){const t=this.constantProvider.START_HAT.height,e=en(25,-8.7)+Qo("c",[qo(29.7,-6.2),qo(57.2,-.5),qo(75,8.7)]),s=Qo("c",[qo(17.8,-9.2),qo(45.3,-14.9),qo(75,-8.7)])+tn(100.5,t+.5);return{path:t=>t?e:s}}},Ag=class extends td{constructor(t,e){super(t,e),this.constants_=t,this.connectedBlock&&(this.width+=this.constants_.DARK_PATH_OFFSET,this.height+=this.constants_.DARK_PATH_OFFSET)}},Ng=class extends ed{constructor(t,e){super(t,e),this.constants_=t,this.connectedBlock&&(this.height+=this.constants_.DARK_PATH_OFFSET)}},Og=class extends Ed{constructor(t,e){super(t,e),this.renderer_=t}getRenderer(){return this.renderer_}populateBottomRow_(){super.populateBottomRow_(),this.block_.inputList.length&&this.block_.inputList[this.block_.inputList.length-1]instanceof fd||(this.bottomRow.minHeight=this.constants_.MEDIUM_PADDING-this.constants_.DARK_PATH_OFFSET)}addInput_(t,e){this.isInline&&t instanceof Ar.ValueInput$$module$build$src$core$inputs$value_input?(e.elements.push(new Ag(this.constants_,t)),e.hasInlineInput=!0):t instanceof fd?(e.elements.push(new Ng(this.constants_,t)),e.hasStatement=!0):t instanceof Ar.ValueInput$$module$build$src$core$inputs$value_input?(e.elements.push(new Ju(this.constants_,t)),e.hasExternalInput=!0):(t instanceof _d||t instanceof md)&&(e.minHeight=Math.max(e.minHeight,this.constants_.DUMMY_INPUT_MIN_HEIGHT),e.hasDummyInput=!0),this.isInline||null!==e.align||(e.align=t.align)}addElemSpacing_(){let t=!1;for(let e,s=0;e=this.rows[s];s++)e.hasExternalInput&&(t=!0);for(let s,i=0;s=this.rows[i];i++){var e=s.elements;if(s.elements=[],s.startsWithElemSpacer()&&s.elements.push(new Qu(this.constants_,this.getInRowSpacing_(null,e[0]))),e.length){for(let t=0;t>>/sprites.png);\n height: 16px;\n vertical-align: middle;\n visibility: hidden;\n width: 16px;\n}\n\n.blocklyTreeIconClosed {\n background-position: -32px -1px;\n}\n\n.blocklyToolboxDiv[dir="RTL"] .blocklyTreeIconClosed {\n background-position: 0 -1px;\n}\n\n.blocklyTreeSelected>.blocklyTreeIconClosed {\n background-position: -32px -17px;\n}\n\n.blocklyToolboxDiv[dir="RTL"] .blocklyTreeSelected>.blocklyTreeIconClosed {\n background-position: 0 -17px;\n}\n\n.blocklyTreeIconOpen {\n background-position: -16px -1px;\n}\n\n.blocklyTreeSelected>.blocklyTreeIconOpen {\n background-position: -16px -17px;\n}\n\n.blocklyTreeLabel {\n cursor: default;\n font: 16px sans-serif;\n padding: 0 3px;\n vertical-align: middle;\n}\n\n.blocklyToolboxDelete .blocklyTreeLabel {\n cursor: url("<<>>/handdelete.cur"), auto;\n}\n\n.blocklyTreeSelected .blocklyTreeLabel {\n color: #fff;\n}\n'),t(Mr.TOOLBOX_ITEM,Kg.registrationName,Kg);var Jg=class extends Yg{constructor(t,e){super(t,e),this.cssConfig_={container:"blocklyTreeSeparator"},this.htmlDiv_=null,Object.assign(this.cssConfig_,t.cssconfig||t.cssConfig)}init(){this.createDom_()}createDom_(){const t=document.createElement("div"),e=this.cssConfig_.container;return e&&it(t,e),this.htmlDiv_=t}getDiv(){return this.htmlDiv_}dispose(){lt(this.htmlDiv_)}};Jg.registrationName="sep",Q('\n.blocklyTreeSeparator {\n border-bottom: solid #e5e5e5 1px;\n height: 0;\n margin: 5px 0;\n}\n\n.blocklyToolboxDiv[layout="h"] .blocklyTreeSeparator {\n border-right: solid #e5e5e5 1px;\n border-bottom: none;\n height: auto;\n margin: 0 5px 0 5px;\n padding: 5px 0;\n width: 0;\n}\n'),t(Mr.TOOLBOX_ITEM,Jg.registrationName,Jg);var jg=class extends Kg{constructor(t,e,s){super(t,e,s),this.subcategoriesDiv_=null,this.expanded_=!1,this.toolboxItems_=[]}makeDefaultCssConfig_(){const t=super.makeDefaultCssConfig_();return t.contents="blocklyToolboxContents",t}parseContents_(t){if("custom"in t)this.flyoutItems_=t.custom;else{const e=t.contents;if(e){this.flyoutItems_=[],t=!0;for(let s=0;s>>/handdelete.cur"), auto;\n}\n\n.blocklyToolboxGrab {\n cursor: url("<<>>/handclosed.cur"), auto;\n cursor: grabbing;\n cursor: -webkit-grabbing;\n}\n\n/* Category tree in Toolbox. */\n.blocklyToolboxDiv {\n background-color: #ddd;\n overflow-x: visible;\n overflow-y: auto;\n padding: 4px 0 4px 0;\n position: absolute;\n z-index: 70; /* so blocks go under toolbox when dragging */\n -webkit-tap-highlight-color: transparent; /* issue #1345 */\n}\n\n.blocklyToolboxContents {\n display: flex;\n flex-wrap: wrap;\n flex-direction: column;\n}\n\n.blocklyToolboxContents:focus {\n outline: none;\n}\n'),t(Mr.TOOLBOX,Lr,Zg);var qg=Ar.Align$$module$build$src$core$inputs$align.LEFT,Qg=Ar.Align$$module$build$src$core$inputs$align.CENTRE,tb=Ar.Align$$module$build$src$core$inputs$align.RIGHT,eb=Lh.INPUT_VALUE,sb=Lh.OUTPUT_VALUE,ib=Lh.NEXT_STATEMENT,ob=Lh.PREVIOUS_STATEMENT,nb=Ar.inputTypes$$module$build$src$core$inputs$input_types.DUMMY,rb=xa.TOP,lb=xa.BOTTOM,ab=xa.LEFT,hb=xa.RIGHT;Gd.prototype.newBlock=function(t,e){return new Kd(this,t,e)},Vd.prototype.newBlock=function(t,e){return new sp(this,t,e)},Vd.newTrashcan=function(t){return new np(t)},uh.prototype.showContextMenu=function(t){if(!this.workspace.options.readOnly){var e=[];this.isDeletable()&&this.isMovable()&&(e.push(ni(this)),e.push(oi(this))),Zs(t,e,this.RTL)}},vu.prototype.newWorkspaceSvg=function(t){return new Vd(t)},Ar.Names$$module$build$src$core$names.prototype.populateProcedures=function(t){t=(t=hn(t))[0].concat(t[1]);for(let e=0;e