iobroker.javascript 10.1.0 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +7 -6
  2. package/admin/assets/AiChatPanel-C_WbKMGX.js +242 -0
  3. package/admin/assets/{AiDiffView-zJTEnv05.js → AiDiffView-BtXbDWZ8.js} +1 -1
  4. package/admin/assets/{Debugger-DCMWjeGm.js → Debugger-DAdJnEhw.js} +4 -4
  5. package/admin/assets/{Error-CBC2oZzb.js → Error-DQ1pzKcf.js} +1 -1
  6. package/admin/assets/{Import-B-F9IhZ-.js → Import-BjMtH6Gk.js} +1 -1
  7. package/admin/assets/RulesEditor-dDRPHw4X.js +1 -0
  8. package/admin/assets/{ScriptEditor-CMYUt5S4.js → ScriptEditor-CZSc7rwE.js} +1 -1
  9. package/admin/assets/ScriptEditorVanillaMonaco-DEKg14_A.js +3 -0
  10. package/admin/assets/{_virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-7EPUlgCk.js → _virtual_mf-localSharedImportMap___mfe_internal__iobroker_javascript__mf_owner__1-DPmwd_G2.js} +1 -1
  11. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-C8inUeKt.js +1243 -0
  12. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-VcQjt7_9.js +9 -0
  13. package/admin/assets/aiPromptBuilder-D5FDo74i.js +1 -0
  14. package/admin/assets/{blockly-C4zJerWL.js → blockly-DBw-ytY1.js} +11 -11
  15. package/admin/assets/blocks_action-BqfWEwpf.js +1 -0
  16. package/admin/assets/{blocks_convert-BZlKcd02.js → blocks_convert-CX0i-JfS.js} +3 -3
  17. package/admin/assets/blocks_logic-D-QSzw95.js +1 -0
  18. package/admin/assets/blocks_number-D7JuNYsw.js +1 -0
  19. package/admin/assets/blocks_object-C9DzAlc7.js +1 -0
  20. package/admin/assets/blocks_procedures-BJMz6HWW.js +3 -0
  21. package/admin/assets/blocks_sendto-DRh7lk9o.js +5 -0
  22. package/admin/assets/{blocks_switch-DViYCmQd.js → blocks_switch-BfmboMex.js} +2 -2
  23. package/admin/assets/blocks_system-B-78JfAc.js +1 -0
  24. package/admin/assets/{blocks_text-BOvtHN2r.js → blocks_text-CGbR0Ozw.js} +1 -1
  25. package/admin/assets/blocks_time-5vS2geJg.js +1 -0
  26. package/admin/assets/blocks_timeout-BdaTywfN.js +1 -0
  27. package/admin/assets/{blocks_trigger-gwXvuAHV.js → blocks_trigger-D8kgHKbg.js} +2 -2
  28. package/admin/assets/blocks_words-BhHIf_1o.js +1 -0
  29. package/admin/assets/{cronHoverProvider-DjY3jLvQ.js → cronHoverProvider-DpgESCox.js} +1 -1
  30. package/admin/assets/{dist-D6o4h8Pd.js → dist-CaOsN0XW.js} +1 -1
  31. package/admin/assets/{field_cron-BMQWPb61.js → field_cron-B40zwSfJ.js} +1 -1
  32. package/admin/assets/{field_oid-BGIMv9gw.js → field_oid-KfoBnEM9.js} +1 -1
  33. package/admin/assets/{field_script-CdzYBCe6.js → field_script-yXhe1iCp.js} +1 -1
  34. package/admin/assets/helpers-B0ByElPJ.js +1 -0
  35. package/admin/assets/{hostInit-DBlZi_Kt.js → hostInit-9REPDUe7.js} +1 -1
  36. package/admin/assets/index-07o_WKsX.js +726 -0
  37. package/admin/assets/index-Z8Hkv58g.css +1 -0
  38. package/admin/assets/{inlineChatWidget-SDoyVtOR.js → inlineChatWidget-B9y_gQcH.js} +1 -1
  39. package/admin/assets/{inlineDiffController-CnHE3Rwd.js → inlineDiffController-C07CdIFo.js} +1 -1
  40. package/admin/assets/{mf-entry-bootstrap-0-a03ecebd.js → mf-entry-bootstrap-0-efcb49d3.js} +3 -2
  41. package/admin/assets/stateHoverProvider-CqeoOjXs.js +9 -0
  42. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-BwSvIKEV.js +1 -0
  43. package/admin/custom/assets/Components-BCQTjBgm.js +1 -0
  44. package/admin/custom/assets/{_virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-DljJyQQg.js → _virtual_mf-localSharedImportMap___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1-BuAc8OyX.js} +1 -1
  45. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-BGJv4zZP.js +1 -0
  46. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-BD2OkSge.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_styled__loadShare__.js-B4E6MFJ4.js} +1 -1
  47. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-pM642JFd.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-aRlxyEhq.js} +86 -86
  48. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-DQwzYx75.js +1494 -0
  49. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__leaflet__loadShare__.js-h-rCw3iz.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__leaflet__loadShare__.js-n2zIPi0L.js} +1 -1
  50. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-xxszBNje.js +9 -0
  51. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__date_mf_2_fns__prebuild__-D5hqXJXI.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__date_mf_2_fns__prebuild__-Tq7tesSS.js} +1 -1
  52. package/admin/custom/assets/{_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__leaflet__prebuild__-DARUoA03.js → _virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__prebuild__leaflet__prebuild__-BeF0jEWM.js} +1 -1
  53. package/admin/custom/assets/{hostInit-0DGPuZTB.js → hostInit-CHwrowP4.js} +1 -1
  54. package/admin/custom/assets/{index-DcFI5r-g.js → index-Cm6xl9K4.js} +1 -1
  55. package/admin/custom/assets/{lib-BlUjuGH7.js → lib-bhrFL6jR.js} +1 -1
  56. package/admin/custom/assets/{mf-entry-bootstrap-0-efd847a6.js → mf-entry-bootstrap-0-f08941e2.js} +3 -2
  57. package/admin/custom/assets/{setYear-BaCcPbbI.js → setYear-DzTZ2h9A.js} +1 -1
  58. package/admin/custom/assets/virtualExposes-B5LJmnfO.js +1 -0
  59. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-ML-chjs6.js +1 -0
  60. package/admin/custom/assets/{virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-DPck7zEs.js → virtual_mf-exposes___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-C3ImybiM.js} +2 -2
  61. package/admin/custom/customComponents.js +12 -1
  62. package/admin/custom/i18n/de.json +11 -1
  63. package/admin/custom/i18n/en.json +11 -1
  64. package/admin/custom/i18n/es.json +11 -1
  65. package/admin/custom/i18n/fr.json +11 -1
  66. package/admin/custom/i18n/it.json +11 -1
  67. package/admin/custom/i18n/nl.json +11 -1
  68. package/admin/custom/i18n/pl.json +11 -1
  69. package/admin/custom/i18n/pt.json +11 -1
  70. package/admin/custom/i18n/ru.json +11 -1
  71. package/admin/custom/i18n/uk.json +11 -1
  72. package/admin/custom/i18n/zh-cn.json +11 -1
  73. package/admin/i18n/de.json +3 -0
  74. package/admin/i18n/en.json +3 -0
  75. package/admin/i18n/es.json +3 -0
  76. package/admin/i18n/fr.json +3 -0
  77. package/admin/i18n/it.json +3 -0
  78. package/admin/i18n/nl.json +3 -0
  79. package/admin/i18n/pl.json +3 -0
  80. package/admin/i18n/pt.json +3 -0
  81. package/admin/i18n/ru.json +3 -0
  82. package/admin/i18n/uk.json +3 -0
  83. package/admin/i18n/zh-cn.json +3 -0
  84. package/admin/jsonConfig.json +31 -0
  85. package/admin/mf-manifest.json +1 -1
  86. package/admin/mf-stats.json +1 -1
  87. package/admin/remoteEntry.js +12 -1
  88. package/admin/tab.html +6 -15
  89. package/build/lib/javascript.d.ts +48 -0
  90. package/build/lib/sandbox.js +2 -0
  91. package/build/lib/sandbox.js.map +1 -1
  92. package/build/lib/secrets.js +220 -0
  93. package/build/lib/secrets.js.map +1 -0
  94. package/build/main.js +51 -0
  95. package/build/main.js.map +1 -1
  96. package/build/types.d.ts +7 -0
  97. package/docs/en/blockly.md +29 -0
  98. package/docs/en/javascript.md +56 -0
  99. package/io-package.json +15 -14
  100. package/package.json +2 -2
  101. package/admin/assets/AiChatPanel-C4kuqP2U.js +0 -237
  102. package/admin/assets/AiScriptAnalyzer--BHML2rN.js +0 -9
  103. package/admin/assets/BlocklyEditor-BB77aFJI.js +0 -84
  104. package/admin/assets/ContextWrapper-C2yvd2Tn.css +0 -1
  105. package/admin/assets/ContextWrapper-W2H0z6zD.js +0 -136
  106. package/admin/assets/RulesEditor-ByjgEaVo.js +0 -1
  107. package/admin/assets/ScriptEditorVanillaMonaco-v12-gORS.js +0 -3
  108. package/admin/assets/Send-CChqR5Oy.js +0 -1
  109. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare___mf_0_iobroker_mf_1_gui_mf_2_components__loadShare__.js-DuplUOZN.js +0 -1243
  110. package/admin/assets/_virtual_mf___mfe_internal__iobroker_javascript__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-JkwfVf8d.js +0 -9
  111. package/admin/assets/aiCodeLensProvider-BGvIu6hH.js +0 -4
  112. package/admin/assets/aiPromptBuilder-Bs27qOHT.js +0 -7
  113. package/admin/assets/blocklyDarkTheme-DEiAX5DT.js +0 -1
  114. package/admin/assets/blocks_action-CvnOHXwt.js +0 -1
  115. package/admin/assets/blocks_logic-B33Pypxr.js +0 -1
  116. package/admin/assets/blocks_number-k2IjE7OH.js +0 -1
  117. package/admin/assets/blocks_object-B64vSfel.js +0 -1
  118. package/admin/assets/blocks_procedures-BpvNI5dO.js +0 -3
  119. package/admin/assets/blocks_sendto-pwZchfe0.js +0 -5
  120. package/admin/assets/blocks_system-BZZcGqTJ.js +0 -1
  121. package/admin/assets/blocks_time-BH2F-ylT.js +0 -1
  122. package/admin/assets/blocks_timeout-C3BoW4XJ.js +0 -1
  123. package/admin/assets/blocks_words-D8PL_nSE.js +0 -1
  124. package/admin/assets/helpers-Crmcgphg.js +0 -1
  125. package/admin/assets/index-BHhhebRG.css +0 -1
  126. package/admin/assets/index-BvPVHv3P.js +0 -192
  127. package/admin/assets/javascript-DVIhlTDr.js +0 -218
  128. package/admin/assets/mjs-Bh7xFIpd.js +0 -90
  129. package/admin/assets/stateHoverProvider-D0iXo6YF.js +0 -9
  130. package/admin/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__iobroker_javascript__remoteEntry_js-DYEYnOkt.js +0 -1
  131. package/admin/custom/assets/Components-CuFt9lAY.js +0 -1
  132. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-D0M1SjIE.js +0 -1
  133. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare___mf_0_iobroker_mf_1_json_mf_2_config__loadShare__.js-BLelmJ7Y.js +0 -1494
  134. package/admin/custom/assets/_virtual_mf___mfe_internal__ConfigCustomJavascriptSet__mf_owner__1__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-BGiB1l5e.js +0 -9
  135. package/admin/custom/assets/virtualExposes-DGxNcyb6.js +0 -1
  136. package/admin/custom/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__ConfigCustomJavascriptSet__customComponents_js-DVNwFcUr.js +0 -1
@@ -3,13 +3,13 @@ import{o as e,r as t,t as n}from"./rolldown-runtime-C0FnF6B9.js";var r=n(((e,t)=
3
3
  `)+(ds?`\xA0`:``),ds=!ds,n.appendChild(e),rs.length=0,ns=es.OFF},10)},h=function(e,t,n){var r=document.createElementNS(`http://www.w3.org/2000/svg`,`${e}`);e!==A.SVG.toString()&&e!==A.G.toString()&&r.tagName!==A.SVG.toString()&&r.tagName!==A.G.toString()||p(r,O.NONE);for(let e in t)r.setAttribute(e,`${t[e]}`);return n&&n.appendChild(r),r},g=function(e,t){return t=t.split(` `),!t.every(t=>e.classList.contains(t))&&(e.classList.add(...t),!0)},ce=function(e,t){e.classList.remove(...t.split(` `))},_=function(e,t){return t=t.split(` `),!t.every(t=>!e.classList.contains(t))&&(e.classList.remove(...t),!0)},le=function(e,t){return e.classList.contains(t)},v=function(e){return e&&e.parentNode?e.parentNode.removeChild(e):null},ue=function(e,t){var n=t.nextSibling;if(t=t.parentNode,!t)throw Error(`Reference node has no parent.`);n?t.insertBefore(e,n):t.appendChild(e)},de=function(e,t){e.style.transform=t,e.style[`-webkit-transform`]=t},fe=function(){gs++,hs||=Object.create(null)},pe=function(){gs--,gs||(hs=null)},me=function(e){var t=e.textContent+`
4
4
  `+e.className.baseVal,n;return hs&&(n=hs[t])?n:(n=window.getComputedStyle(e),n=he(e,n.fontSize,n.fontWeight,n.fontFamily),hs&&(hs[t]=n),n)},he=function(e,t,n,r){var i=e.textContent;e=i+`
5
5
  `+e.className.baseVal;var a;return hs&&(a=hs[e])?a:(_s||=(a=document.createElement(`canvas`),a.className=`blocklyComputeCanvas`,document.body.appendChild(a),a.getContext(`2d`)),i&&_s?(_s.font=n+` `+t+` `+r,a=_s.measureText(i).width):a=0,hs&&(hs[e]=a),a)},ge=function(e,t,n,r){var i=document.createElement(`span`);i.style.font=n+` `+t+` `+r,i.textContent=e,e=document.createElement(`div`),e.style.width=`1px`,e.style.height=`0`,t=document.createElement(`div`),t.style.display=`flex`,t.style.position=`fixed`,t.style.top=`0`,t.style.left=`0`,t.appendChild(i),t.appendChild(e),document.body.appendChild(t),n={height:0,baseline:0};try{t.style.alignItems=`baseline`,n.baseline=e.offsetTop-i.offsetTop,t.style.alignItems=`flex-end`,n.height=e.offsetTop-i.offsetTop}finally{document.body.removeChild(t)}return n},_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,De,Oe,ke,Ae,je,Me,Ne,Pe,Fe,y,Ie,Le,Re,ze,Be,Ve,He,Ue,b,We,Ge,Ke,qe,Je,Ye,x,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt,Zt,Qt,$t,en,tn,nn,rn,an,on,sn,cn,ln,un,dn,fn,pn,mn,hn,gn,_n,vn,yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn,$n,er,tr,nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi,pi,mi,hi,S,gi,_i,vi,yi,bi,C,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,w;e.t=function(){return xs.getFocusManager()},_e=function(e){return e&&typeof e.getFocusableElement==`function`&&typeof e.getFocusableTree==`function`&&typeof e.onNodeFocus==`function`&&typeof e.onNodeBlur==`function`&&typeof e.canBeFocused==`function`},ve=function(e){return _e(e)&&typeof e.id==`string`&&typeof e.workspace==`object`&&typeof e.select==`function`&&typeof e.unselect==`function`},ye=function(e,t){for(let n in t)e[n]=t[n]!==null&&Array.isArray(t[n])?ye(e[n]||[],t[n]):t[n]!==null&&typeof t[n]==`object`?ye(e[n]||Object.create(null),t[n]):t[n];return e},be=function(e,t,n,r){e=e+` was deprecated in `+t+` and will be deleted in `+n+`.`,r&&(e+=`
6
- Use `+r+` instead.`),Ts.has(e)||(Ts.add(e),console.warn(e))},xe=function(e){return Ds[e]||null},Se=function(){var e=[];for(let t in Ds)e.push(Ds[t]);return e},Ce=function(e){Ds[e.id]=e},we=function(e){delete Ds[e.id]},Te=function(){return Os},Ee=function(t){Os=t,t.rendered&&e.t().setPopoverFocusRoot(t.getInjectionDiv())},De=function(){var t=e.t().getFocusedNode();return t&&ve(t)?t:null},Oe=function(e){var t=De(),n=new(x(E.SELECTED))((t==null?void 0:t.id)??null,(e==null?void 0:e.id)??null,(e==null?void 0:e.workspace.id)??(t==null?void 0:t.workspace.id)??``);b(n)},ke=function(e=Os){return ks||(e&&e.rendered?e.getInjectionDiv():null)},Ae=function(e){ks=e},je=function(e){for(;e.options.parentWorkspace;)e=e.options.parentWorkspace;var t=e.getParentSvg(),n=e.getCachedParentSvgSize(),r=t.parentElement;if(r instanceof HTMLElement){var i=r.offsetWidth;r=r.offsetHeight,n.width!==i&&(t.setAttribute(`width`,i+`px`),e.setCachedParentSvgSize(i,null)),n.height!==r&&(t.setAttribute(`height`,r+`px`),e.setCachedParentSvgSize(null,r)),e.resize()}},Me=function(e,t){var n=Object.create(null),r=e.getDescendants(!0);t&&(e=e.getNextBlock())&&(e=r.indexOf(e),r.splice(e,r.length-e));for(let e=0,t;t=r[e];e++)n[t.type]?n[t.type]++:n[t.type]=1;return n},Ne=function(e){return function(){this.jsonInit(e)}},Pe=function(e){js.defineBlocksWithJsonArrayInternal(e)},e.yb=function(e){var t={};for(let n=0;n<e.length;n++){let r=e[n];if(!r){console.warn(`Block definition #${n} in JSON array is ${r}. Skipping`);continue}let i=r.type;i?t[i]={init:Ne(r)}:console.warn(`Block definition #${n} in JSON array is missing a type attribute. Skipping.`)}return t},e.Ab=function(e){for(let t of Object.keys(e)){let n=e[t];t in $o&&console.warn(`Block definition "${t}" overwrites previous definition.`),$o[t]=n}},Fe=function(t){var n=Os,r=e.t().getFocusedTree();for(let e of Se())if(r===e){n=e;break}!l(t)&&n&&(!n.rendered||n.isFlyout||n.isVisible())&&j.registry.onKeyDown(n,t)},y=function(e,t,n,r){if(!(e instanceof M)&&typeof e!=`string`||`${e}`.trim()===``)throw Error(`Invalid type "`+e+`". The type must be a non-empty string or a Blockly.registry.Type.`);if(e=`${e}`.toLowerCase(),typeof t!=`string`||t.trim()===``)throw Error(`Invalid name "`+t+`". The name must be a non-empty string.`);var i=t.toLowerCase();if(!n)throw Error(`Can not register a null value`);var a=Ns[e],o=Fs[e];switch(a||(a=Ns[e]=Object.create(null),o=Fs[e]=Object.create(null)),e){case String(M.FIELD):if(typeof n.fromJson!=`function`)throw Error(`Type "`+e+`" must have a fromJson function`)}if(!r&&a[i]&&a[i]!==n)throw Error(`Name "`+i+`" with type "`+e+`" already registered.`);a[i]=n,o[i]=t},Ie=function(e,t){e=`${e}`.toLowerCase(),t=t.toLowerCase();var n=Ns[e];n&&n[t]?(delete Ns[e][t],delete Fs[e][t]):console.warn(`Unable to unregister [`+t+`][`+e+`] from the registry.`)},Le=function(e,t,n){e=`${e}`.toLowerCase(),t=t.toLowerCase();var r=Ns[e];if(!r||!r[t]){if(t=`Unable to find [`+t+`][`+e+`] in the registry.`,n)throw Error(t+` You must require or register a `+e+` plugin.`);return console.warn(t),null}return r[t]},Re=function(e,t){return e=`${e}`.toLowerCase(),t=t.toLowerCase(),(e=Ns[e])?!!e[t]:!1},ze=function(e,t,n){return Le(e,t,n)},Be=function(e,t,n){e=`${e}`.toLowerCase();var r=Ns[e];if(!r){if(r=`Unable to find [${e}] in the registry.`,n)throw Error(`${r} You must require or register a ${e} plugin.`);return console.warn(r),null}if(!t)return r;e=Fs[e],n=Object.create(null);for(let t of Object.keys(r))n[e[t]]=r[t];return n},Ve=function(e,t,n){return t=t.plugins[String(e)]||`default`,typeof t==`function`?t:Le(e,t,n)},He=function(){return`blockly-`+(Rs++).toString(36)},Ue=function(){return Ls.genUid()},b=function(e){Vs.fireInternal(e)},We=function(){var e=Ke(Bs);Bs.length=0;for(let t of e){if(!t.workspaceId)continue;let e;(e=xe(t.workspaceId))==null||e.fireChangeListener(t)}},Ge=function(e){if(e.type===E.BLOCK_CHANGE&&e.element===`mutation`){let t;for(t=Bs.length;t>0;t--){let n=Bs[t-1];if(n.group!==e.group||n.workspaceId!==e.workspaceId||n.type!==E.BLOCK_MOVE||n.newParentId!==e.blockId)break}Bs.splice(t,0,e)}else Bs.push(e)},Ke=function(e){var t=[];for(let n of e)e=t[t.length-1],!n.isNull()&&(!e||e.workspaceId!==n.workspaceId||e.group!==n.group?t.push(n):n.type===E.BLOCK_MOVE&&e.type===E.BLOCK_MOVE&&n.blockId===e.blockId?(e.newParentId=n.newParentId,e.newInputName=n.newInputName,e.newCoordinate=n.newCoordinate,(e.reason||n.reason)&&(e.reason=Array.from(new Set((e.reason??[]).concat(n.reason??[]))))):n.type===E.BLOCK_CHANGE&&e.type===E.BLOCK_CHANGE&&n.blockId===e.blockId&&n.element===e.element&&n.name===e.name?e.newValue=n.newValue:n.type===E.VIEWPORT_CHANGE&&e.type===E.VIEWPORT_CHANGE?(e.viewTop=n.viewTop,e.viewLeft=n.viewLeft,e.scale=n.scale,e.oldScale=n.oldScale):(n.type!==E.CLICK||e.type!==E.BUBBLE_OPEN)&&(n.type===E.SELECTED&&e.type===E.SELECTED&&e.newElementId===void 0?(e.newElementId=n.newElementId,e.oldElementId===e.newElementId&&t.pop()):t.push(n)));return e=t.filter(e=>!e.isNull())},qe=function(){for(let e=0,t;t=Bs[e];e++)t.recordUndo=!1},Je=function(){return e.Ub===0},e.B=function(e){Vs.setGroupInternal(e)},Ye=function(e){var t=[];e=e.getDescendants(!1);for(let n=0,r;r=e[n];n++)t[n]=r.id;return t},x=function(e){var t=Le(M.EVENT,e,void 0);if(!t)throw Error(`Event type ${e} not found in registry.`);return t},Xe=function(t){Object.keys(t).forEach(function(n){e.C[n]=t[n]})},Ze=function(e){return Us.getSizeInternal(e)},Qe=function(e,t){return e=window.getComputedStyle(e),e[t]||e.getPropertyValue(t)},$e=function(e){var t=new N(0,0);e=e.getBoundingClientRect();var n=document.documentElement;return n=new N(window.pageXOffset||n.scrollLeft,window.pageYOffset||n.scrollTop),t.x=e.left+n.x,t.y=e.top+n.y,t},et=function(){var e=document.body,t=document.documentElement;return new N(e.scrollLeft||t.scrollLeft,e.scrollTop||t.scrollTop)},tt=function(e){var t=parseFloat(Qe(e,`borderLeftWidth`)),n=parseFloat(Qe(e,`borderRightWidth`)),r=parseFloat(Qe(e,`borderTopWidth`));return e=parseFloat(Qe(e,`borderBottomWidth`)),new P(r,e,t,n)},nt=function(e,t,n){e=rt(e,t,n),t.scrollLeft=e.x,t.scrollTop=e.y},rt=function(e,t,n){var r=$e(e),i=$e(t),a=tt(t),o=r.x-i.x-a.left;return r=r.y-i.y-a.top,i=new F(e.offsetWidth,e.offsetHeight),e=t.clientWidth-i.width,i=t.clientHeight-i.height,a=t.scrollLeft,t=t.scrollTop,n?(a+=o-e/2,t+=r-i/2):(a+=Math.min(o,Math.max(o-e,0)),t+=Math.min(r,Math.max(r-i,0))),new N(a,t)},it=function(e){var t=new N(0,0),n=e.x&&e.getAttribute(`x`),r=e.y&&e.getAttribute(`y`);return n&&(t.x=parseInt(n)),r&&(t.y=parseInt(r)),(n=(n=e.getAttribute(`transform`))&&n.match(Gs))&&(t.x+=Number(n[1]),n[3]&&(t.y+=Number(n[3]))),(e=e.getAttribute(`style`))&&e.includes(`translate`)&&(e=e.match(Ks))&&(t.x+=Number(e[1]),e[3]&&(t.y+=Number(e[3]))),t},at=function(e){for(var t=0,n=0;e;){let r=it(e);if(t+=r.x,n+=r.y,(` `+(e.getAttribute(`class`)||``)+` `).includes(` injectionDiv `))break;e=e.parentNode}return new N(t,n)},ot=function(){var e=et();return new P(e.y,document.documentElement.clientHeight+e.y,e.x,document.documentElement.clientWidth+e.x)},st=function(){var e=document.documentElement,t=window;return new N(t.pageXOffset||e.scrollLeft,t.pageYOffset||e.scrollTop)},ct=function(e,t){var n=t.x;t=t.y;var r=e.getInjectionDiv().getBoundingClientRect();return n=new N(n-r.left,t-r.top),t=e.getOriginOffsetInPixels(),N.difference(n,t).scale(1/e.scale)},lt=function(e,t){var n=t.scale(e.scale);t=n.x,n=n.y;var r=e.getInjectionDiv().getBoundingClientRect();return e=e.getOriginOffsetInPixels(),new N(t+r.left+e.x,n+r.top+e.y)},e.rc=function(e){return Zs.createElementNS(`https://developers.google.com/blockly/xml`,e)},e.sc=function(e){return Zs.createTextNode(e)},e.uc=function(e){var t=Ys.parseFromString(e,`text/xml`);if(t&&t.documentElement&&!t.getElementsByTagName(`parsererror`).length)return t.documentElement;if((t=Ys.parseFromString(e,`text/html`))&&t.body.firstChild&&t.body.firstChild.nodeName.toLowerCase()===`xml`)return t.body.firstChild;throw Error(`DOMParser was unable to parse: ${e}`)},ut=function(e){return dt(Xs.serializeToString(e))},dt=function(e){return e.replace(ec,e=>`&#${e.charCodeAt(0)};`)},ft=function(e){if(!e)return null;if(e instanceof Element||typeof e==`string`){e=vt(e);var t={contents:gt(e)};e instanceof Node&&_t(e,t),e=t}t=e.kind;var n=e.contents;if(t&&t!==`flyoutToolbox`&&t!==`categoryToolbox`)throw Error(`Invalid toolbox kind `+t+`. Please supply either flyoutToolbox or categoryToolbox`);if(!n)throw Error(`Toolbox must have a contents attribute.`);return e},pt=function(e){return e?e.contents?e.contents:Array.isArray(e)&&e.length>0&&!e[0].nodeType?e:gt(e):[]},mt=function(e){return rc.hasCategoriesInternal(e)},ht=function(e){return e&&e.contents?!!e.contents.filter(function(e){return e.kind.toUpperCase()===`CATEGORY`}).length:!1},gt=function(e){var t=[],n=e.childNodes;n||=e;for(let r=0,i;i=n[r];r++){if(!i.tagName)continue;e={};let n=i.tagName.toUpperCase();e.kind=n,n===`BLOCK`?e.blockxml=i:i.childNodes&&i.childNodes.length>0&&(e.contents=gt(i)),_t(i,e),t.push(e)}return t},_t=function(e,t){for(let n=0;n<e.attributes.length;n++){let r=e.attributes[n];r.nodeName.includes(`css-`)?(t.cssconfig=t.cssconfig||{},t.cssconfig[r.nodeName.replace(`css-`,``)]=r.value):t[r.nodeName]=r.value}},vt=function(t){var n=null;if(t)if(typeof t==`string`){if(n=e.uc(t),n.nodeName.toLowerCase()!==`xml`)throw TypeError(`Toolbox should be an <xml> document.`)}else t instanceof Element&&(n=t);return n},yt=function(e,t,n,r,i,a){var o=a.scrollbar&&a.scrollbar.canScrollVertically();return e.horizontal===sc.LEFT?(n=i.absoluteMetrics.left+n,o&&a.RTL&&(n+=Js.scrollbarThickness)):(n=i.absoluteMetrics.left+i.viewMetrics.width-t.width-n,o&&!a.RTL&&(n-=Js.scrollbarThickness)),e.vertical===ac.TOP?e=i.absoluteMetrics.top+r:(e=i.absoluteMetrics.top+i.viewMetrics.height-t.height-r,a.scrollbar&&a.scrollbar.canScrollHorizontally()&&(e-=Js.scrollbarThickness)),new P(e,e+t.height,n,n+t.width)},bt=function(e,t){return{horizontal:t.toolboxMetrics.position===I.LEFT||e.horizontalLayout&&!e.RTL?sc.RIGHT:sc.LEFT,vertical:t.toolboxMetrics.position===I.BOTTOM?ac.TOP:ac.BOTTOM}},xt=function(e,t,n,r){var i=e.left,a=e.right-e.left,o=e.bottom-e.top;for(let s=0;s<r.length;s++){let c=r[s];e.intersects(c)&&(e=n===lc.UP?c.top-o-t:c.bottom+t,e=new P(e,e+o,i,i+a),s=-1)}return e},St=function(e,t){y(M.SERIALIZER,e,t)},Ct=function(e,{addCoordinates:t=!1,saveIds:n=!0}={}){var r=e.workspace,i=Object.create(null);return i.height=e.getSize().height,i.width=e.getSize().width,n&&(i.id=e.id),t&&(t=e.getRelativeToSurfaceXY(),i.x=r.RTL?r.getWidth()-t.x:t.x,i.y=t.y),e.getText()&&(i.text=e.getText()),e.isCollapsed()&&(i.collapsed=!0),e.isOwnEditable()||(i.editable=!1),e.isOwnMovable()||(i.movable=!1),e.isOwnDeletable()||(i.deletable=!1),i},wt=function(t,n,{recordUndo:r=!1}={}){var i=e.Qc;if(e.Qc=r,r=n.newComment(t.id),t.text!==void 0&&r.setText(t.text),t.x!==void 0||t.y!==void 0){let e=r.getRelativeToSurfaceXY(),i=t.x??e.x;i=n.RTL?n.getWidth()-i:i;var a;n=(a=t.y)??e.y,r.moveTo(new N(i,n))}return(t.width!==void 0||t.height)&&(a=r.getSize(),r.setSize(new F(t.width??a.width,t.height??a.height))),t.collapsed!==void 0&&r.setCollapsed(t.collapsed),t.editable!==void 0&&r.setEditable(t.editable),t.movable!==void 0&&r.setMovable(t.movable),t.deletable!==void 0&&r.setDeletable(t.deletable),e.Qc=i,r},Tt=function(e,t){y(M.PASTER,e,t)},Et=function(e){for(var t=e.workspace,n=e.getRelativeToSurfaceXY(),r=new N(0,0),i=t.getTopComments(!1).filter(t=>t.id!==e.id).map(e=>e.getRelativeToSurfaceXY());Dt(N.sum(n,r),i);)r.translate(t.RTL?-30:30,30);e.moveTo(N.sum(n,r))},Dt=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},Ot=function(e){return e&&typeof e.saveState==`function`&&typeof e.loadState==`function`},kt=function(e){return Mt(e),Po?(Nt(),Promise.resolve()):(Ac||=new Promise(e=>{jc=e,Mc=window.requestAnimationFrame(()=>{Nt(),e()})}),Ac)},At=function(){return Ac||Promise.resolve()},jt=function(e){e||window.cancelAnimationFrame(Mc),Nt(e),!e&&jc&&jc()},Mt=function(t){Oc.add(t),kc.set(t,e.gd);var n=t.getParent();n?Mt(n):Dc.add(t)},Nt=function(t){var n=t?new Set([t]):new Set([...Dc].map(e=>e.workspace)),r=[...Dc].filter(Ft).filter(e=>n.has(e.workspace));for(var i of r)It(i);for(let e of n)e.resizeContents(),e.connectionDBList.forEach(e=>e==null?void 0:e.beginBulkUpdates());for(var a of r)i=a.getRelativeToSurfaceXY(),a.updateComponentLocations(i);for(var o of n)o.connectionDBList.forEach(e=>e==null?void 0:e.endBulkUpdates());for(let t of r)a=e.gd,(o=kc.get(t))&&e.B(o),t.bumpNeighbours(),e.B(a);for(let e of r)Pt(e);t||(Ac=null)},Pt=function(e){Dc.delete(e),Oc.delete(e),kc.delete(e);for(let t of e.getChildren(!1))Pt(t)},Ft=function(e){return!e.isDisposed()&&!e.getParent()},It=function(e){if(Oc.has(e)&&e.initialized){for(let t of e.getChildren(!1))It(t);e.renderEfficiently()}},Lt=function(e,t){Ut(Fc.ALERT,e,t,void 0)},Rt=function(e,t){Ut(Fc.CONFIRM,e,t,void 0)},zt=function(e,t,n){Ut(Fc.PROMPT,e,n,t)},Bt=function(e,t){Rc(e,t)},Vt=function(e,t){zc(e,t)},Ht=function(e,t,n){Bc(e,t,n)},Ut=function(...[t,n,r,i]){var a=document.createElement(`dialog`),o=document.createElement(`form`),s=document.createElement(`label`),c=document.createElement(`input`),l=document.createElement(`div`),u=document.createElement(`button`);a.className=`blocklyDialog`,o.className=`blocklyDialogForm`,s.className=`blocklyDialogPrompt`,l.className=`blocklyDialogButtonRow`,u.className=`blocklyDialogConfirmButton`,o.setAttribute(`method`,`dialog`),s.textContent=n,s.setAttribute(`for`,`blockly-form-input`),u.textContent=e.C.DIALOG_OK,u.value=`ok`,a.appendChild(o),o.appendChild(s),t===Fc.PROMPT&&(c.id=`blockly-form-input`,c.className=`blocklyDialogInput`,c.type=`text`,c.name=`input`,c.autofocus=!0,i&&(c.value=i),o.appendChild(c)),l.appendChild(u),(t===Fc.CONFIRM||t===Fc.PROMPT)&&(n=document.createElement(`button`),n.className=`blocklyDialogCancelButton`,n.textContent=e.C.DIALOG_CANCEL,n.value=`cancel`,l.appendChild(n)),o.appendChild(l);var d;Lc===0&&(d=e.t().ephemeralFocusTaken()?void 0:e.t().takeEphemeralFocus(a)),Lc++,a.addEventListener(`close`,()=>{if(Lc--,!Lc){let e;(e=d)==null||e()}switch(a.remove(),t){case Fc.CONFIRM:r(a.returnValue===`ok`);break;case Fc.PROMPT:r(a.returnValue===`ok`?c.value:null);break;case Fc.ALERT:r==null||r()}}),document.body.appendChild(a),a.showModal()},Wt=function(e){return typeof e.bubbleIsVisible==`function`&&typeof e.setBubbleVisible==`function`&&typeof e.getBubble==`function`},Gt=function(e,t){return t.map(t=>e.getBlockById(t)).filter(e=>e&&e.isShadow()).length===t.length},Kt=function(e){return e&&typeof e.getProcedureDef==`function`},qt=function(e){return e.getVariableModel!==void 0},e.Bd=function(e){e=e.getAllBlocks(!1);var t=new Set;for(let n=0;n<e.length;n++){let r=e[n].getVarModels();if(r)for(let e=0;e<r.length;e++){let n=r[e];n.getId()&&t.add(n)}}return Array.from(t.values())},e.Cd=function(e){e=e.getAllBlocks(!1);var t=new Set;for(let r=0,i;i=e[r];r++){var n=i.getDeveloperVariables;if(n){n=n();for(let e=0;e<n.length;e++)t.add(n[e])}}return Array.from(t.values())},Jt=function(e){return $o.variables_set||$o.variables_get||console.warn(`There are no variable blocks, but there is a variable category.`),e.registerButtonCallback(`CREATE_VARIABLE`,function(e){$t(e.getTargetWorkspace())}),[{kind:`button`,text:`%{BKY_NEW_VARIABLE}`,callbackkey:`CREATE_VARIABLE`},...Xt(e,e.getVariableMap().getVariablesOfType(``),!0)]},Yt=function(e){return{VAR:{name:e.getName(),type:e.getType()}}},Xt=function(e,t,n,r=`variables_get`,i=`variables_set`){n&&=$o.math_change,e=[];var a=t.slice(-1)[0];return a&&($o[i]&&e.push({kind:`block`,type:i,gap:n?8:24,fields:Yt(a)}),n&&e.push({kind:`block`,type:`math_change`,gap:$o[r]?20:8,fields:Yt(a),inputs:{DELTA:{shadow:{type:`math_number`,fields:{NUM:1}}}}})),$o[r]&&e.push(...t.sort(ln).map(e=>({kind:`block`,type:r,gap:8,fields:Yt(e)}))),e},Zt=function(e){return Ql.generateUniqueNameInternal(e)},Qt=function(e,t){if(!t.length)return e;for(var n=``,r=`ijkmnopqrstuvwxyzabcdefgh`.indexOf(e);;){let i=!1;for(let n=0;n<t.length;n++)if(t[n].toLowerCase()===e){i=!0;break}if(!i)break;r++,r===25&&(r=0,n=`${Number(n)+1}`),e=`ijkmnopqrstuvwxyzabcdefgh`.charAt(r)+n}return e},$t=function(t,n,r){function i(r){en(e.C.NEW_VARIABLE_TITLE,r,function(r){if(r){var o=nn(r,t);if(o){if(o.getType()===a)var s=e.C.VARIABLE_ALREADY_EXISTS.replace(`%1`,o.getName());else s=e.C.VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE,s=s.replace(`%1`,o.getName()).replace(`%2`,o.getType());Bt(s,function(){i(r)})}else{let i=t.getVariableMap().createVariable(r,a);n&&n(r);let o=(s=t.getFlyout())==null?void 0:s.getWorkspace();if(o&&z.getIsActive()){var c=t=>{t.type===e.Od&&(t=t.blockId)&&(t=o.getBlockById(t))&&t.type===`variables_set`&&t.getFieldValue(`VAR`)===i.getId()&&(e.t().focusNode(t),o.removeChangeListener(c))};o.addChangeListener(c)}}}else n&&n(null)})}var a=r||``;i(``)},e.Rd=function(t,n,r){function i(a){var o=e.C.RENAME_VARIABLE_TITLE.replace(`%1`,n.getName());en(o,a,function(a){if(a){var o=tn(a,n.getType(),t),s=rn(n.getName(),a,t);if(o||s){var c=``;o?c=e.C.VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE.replace(`%1`,o.getName()).replace(`%2`,o.getType()):s&&(c=e.C.VARIABLE_ALREADY_EXISTS_FOR_A_PARAMETER.replace(`%1`,a).replace(`%2`,s)),Bt(c,function(){i(a)})}else t.getVariableMap().renameVariable(n,a),r&&r(a)}else r&&r(null)})}i(``)},en=function(t,n,r){Ht(t,n,function(t){t&&(t=t.replace(/[\s\xa0]+/g,` `).trim(),t===e.C.RENAME_VARIABLE||t===e.C.NEW_VARIABLE)&&(t=null),r(t)})},tn=function(e,t,n){n=n.getVariableMap().getAllVariables(),e=e.toLowerCase();for(let r=0,i;i=n[r];r++)if(i.getName().toLowerCase()===e&&i.getType()!==t)return i;return null},nn=function(e,t){t=t.getVariableMap().getAllVariables(),e=e.toLowerCase();for(let n=0,r;r=t[n];n++)if(r.getName().toLowerCase()===e)return r;return null},rn=function(e,t,n){return n.getProcedureMap().getProcedures().length?an(e,t,n):on(e,t,n)},an=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getProcedureMap().getProcedures();for(let i of n){var r=i.getParameters().filter(qt).map(e=>e.getVariableModel().getName());if(r&&(n=r.some(t=>t.toLowerCase()===e),r=r.some(e=>e.toLowerCase()===t),n&&r))return i.getName()}return null},on=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getAllBlocks(!1);for(let i of n){if(!Kt(i))continue;n=i.getProcedureDef();var r=n[1];let a=r.some(t=>t.toLowerCase()===e);if(r=r.some(e=>e.toLowerCase()===t),a&&r)return n[0]}return null},sn=function(t){var n=e.rc(`field`);return n.setAttribute(`name`,`VAR`),n.setAttribute(`id`,t.getId()),n.setAttribute(`variabletype`,t.getType()),t=e.sc(t.getName()),n.appendChild(t),n},e.Wd=function(t,n,r,i){var a=e.Vd(t,n,r,i);if(!a){a=t.getVariableMap();let e=t.getPotentialVariableMap();r||=Zt(t.isFlyout?t.targetWorkspace:t),a=e?e.createVariable(r,i,n??void 0):a.createVariable(r,i,n)}return a},e.Vd=function(e,t,n,r){var i=e.getPotentialVariableMap(),a=null;if(t&&(a=e.getVariableMap().getVariableById(t),!a&&i&&(a=i.getVariableById(t)),a))return a;if(n){if(r===void 0)throw Error(`Tried to look up a variable by name without a type`);a=e.getVariableMap().getVariable(n,r),!a&&i&&(a=i.getVariable(n,r))}return a},cn=function(e,t){e=e.getVariableMap().getAllVariables();var n=[];if(t.length!==e.length)for(let r=0;r<e.length;r++){let i=e[r];t.includes(i)||n.push(i)}return n},ln=function(e,t){return Zl.compare(e.getName(),t.getName())},un=function(e,t){var n=[];e=e.getAllBlocks(!1);for(let r=0;r<e.length;r++){let i=e[r].getVarModels();if(i)for(let a=0;a<i.length;a++)i[a].getId()===t&&n.push(e[r])}return n},e.$d=function(t,n,r){var i=n.getName(),a=un(t,n.getId());for(let t=a.length-1;t>=0;t--){let n=a[t];if(n.type===`procedures_defnoreturn`||n.type===`procedures_defreturn`){r=String(n.getFieldValue(`NAME`)),i=e.C.CANNOT_DELETE_VARIABLE_PROCEDURE.replace(`%1`,i).replace(`%2`,r),Rc(i,void 0);return}n===r&&a.splice(t,1)}r&&a.length||a.length>1?(i=e.C.DELETE_VARIABLE_CONFIRMATION.replace(`%1`,String(a.length+(r&&!r.workspace.isFlyout?1:0))).replace(`%2`,i),Vt(i,e=>{e&&n&&t.getVariableMap().deleteVariable(n)})):t.getVariableMap().deleteVariable(n)},dn=function(e,{addCoordinates:t=!1,addInputBlocks:n=!0,addNextBlocks:r=!0,doFullSerialization:i=!0,saveIds:a=!0}={}){if(e.isInsertionMarker())return null;var o={type:e.type,id:a?e.id:void 0};if(t){t=e.workspace;var s=e.getRelativeToSurfaceXY();o.x=Math.round(t.RTL?t.getWidth()-s.x:s.x),o.y=Math.round(s.y)}e.isCollapsed()&&(o.collapsed=!0),e.isEnabled()||(o.disabledReasons=Array.from(e.getDisabledReasons())),e.isOwnDeletable()||(o.deletable=!1),e.isOwnMovable()||(o.movable=!1),e.isOwnEditable()||(o.editable=!1),e.inputsInline!==void 0&&e.inputsInline!==e.inputsInlineDefault&&(o.inline=e.inputsInline),e.data&&(o.data=e.data),e.saveExtraState?(t=e.saveExtraState(i),t!==null&&(o.extraState=t)):e.mutationToDom&&(t=e.mutationToDom(),t!==null&&(o.extraState=ti(t).replace(` xmlns="https://developers.google.com/blockly/xml"`,``))),t=Object.create(null);for(var c of e.getIcons())Ot(c)&&(s=c.saveState(i))&&(t[c.getType().toString()]=s);Object.keys(t).length&&(o.icons=t),c=Object.create(null);for(var l of e.getFields())l.isSerializable()&&(c[l.name]=l.saveState(i));if(Object.keys(c).length&&(o.fields=c),n){for(n=Object.create(null),l=0;l<e.inputList.length;l++)c=e.inputList[l],c.connection&&(t=fn(c.connection,i,a))&&(n[c.name]=t);Object.keys(n).length&&(o.inputs=n)}return r&&e.nextConnection&&(e=fn(e.nextConnection,i,a))&&(o.next=e),o},fn=function(e,t,n){var r=e.getShadowState(!0);if(e=e.targetBlock(),!r&&!e)return null;var i=Object.create(null);return r&&(i.shadow=r),e&&!e.isShadow()&&(i.block=dn(e,{doFullSerialization:t,saveIds:n})),i},pn=function(e,t,{recordUndo:n=!1}={}){return e=mn(e,t,{recordUndo:n}),t.rendered&&jt(),e},mn=function(t,n,{parentConnection:r,isShadow:i=!1,recordUndo:a=!1}={}){var o=e.Qc;e.Qc=a,(a=e.gd)||e.B(!0),e.Ub++;var s=n.getVariableMap().getAllVariables();try{var c=hn(t,n,{parentConnection:r,isShadow:i})}finally{e.Ub--}if(gn(n,s),Je()&&b(new(x(E.BLOCK_CREATE))(c)),e.B(a),e.Qc=o,n.rendered){let e=c;setTimeout(()=>{e.disposed||e.setConnectionTracking(!0)},1)}return c},hn=function(t,n,{parentConnection:r,isShadow:i=!1}={}){if(!t.type)throw new tu(t);var a=n.newBlock(t.type,t.id);a.setShadow(i),i=t.x===void 0?0:t.x;var o=t.y===void 0?0:t.y,s=a.workspace;if(i=s.RTL?s.getWidth()-i:i,a.moveBy(i,o),t.collapsed&&a.setCollapsed(!0),t.deletable===!1&&a.setDeletable(!1),t.movable===!1&&a.setMovable(!1),t.editable===!1&&a.setEditable(!1),t.enabled===!1&&a.setDisabledReason(!0,`MANUALLY_DISABLED`),Array.isArray(t.disabledReasons))for(var c of t.disabledReasons)a.setDisabledReason(!0,c);if(t.inline!==void 0&&a.setInputsInline(t.inline),t.data!==void 0&&(a.data=t.data),t.extraState&&(a.loadExtraState?a.loadExtraState(t.extraState):a.domToMutation&&a.domToMutation(e.uc(t.extraState))),r){if(r.getSourceBlock().isShadow()&&!a.isShadow())throw new iu(t);if(r.type===e.je.VALUE){if(c=a.outputConnection,!c)throw new nu(`output`,a,t)}else if(c=a.previousConnection,!c)throw new nu(`previous`,a,t);if(!r.connect(c))throw n=a.workspace.connectionChecker,new ru(n.getErrorMessage(n.canConnectWithReason(c,r,!1),c,r),r.type===e.je.VALUE?`output connection`:`previous connection`,a,t)}if(t.icons){r=Object.keys(t.icons);for(var l of r){if(r=t.icons[l],c=a.getIcon(l),!c){if(c=Le(M.ICON,l,!1),!c)throw new au(l,a,t);c=new c(a),a.addIcon(c)}Ot(c)&&c.loadState(r)}}if(t.fields)for(l=Object.keys(t.fields),r=0;r<l.length;r++)c=l[r],i=t.fields[c],(o=a.getField(c))?o.loadState(i):console.warn(`Ignoring non-existant field ${c} in block ${a.type}`);if(t.inputs)for(l=Object.keys(t.inputs),r=0;r<l.length;r++){if(c=l[r],i=a.getInput(c),!i||!i.connection)throw new nu(c,a,t);_n(i.connection,t.inputs[c])}if(t.next){if(!a.nextConnection)throw new nu(`next`,a,t);_n(a.nextConnection,t.next)}if(n.rendered){a.setConnectionTracking(!1),a.initSvg(),a.queueRender();for(let e of a.getIcons())e.onLocationChange(a.getRelativeToSurfaceXY())}else a.initModel();return a},gn=function(e,t){if(Je())for(e=cn(e,t),t=0;t<e.length;t++){let n=e[t];b(new(x(E.VAR_CREATE))(n))}},_n=function(e,t){t.shadow&&e.setShadowState(t.shadow),t.block&&hn(t.block,e.getSourceBlock().workspace,{parentConnection:e})},vn=function(e){return e=yn(e,lu),e.length?e[0].join(Vo?` `:` + `):``},yn=function(t,n){if(t=j.registry.getKeyCodesByShortcutName(t),t.length===0)return[];t=t.map(e=>e.split(`+`)),t.forEach(e=>e.sort((e,t)=>(e=bn(e),t=bn(t),e-t))),t.sort((e,t)=>(e=+!!e.includes(`Meta`),+!!t.includes(`Meta`)-e));var r=t.filter(e=>e.includes(`Meta`)===Vo);return r=r.length===0?t:r,r.sort((e,t)=>e.length-t.length),(r.some(e=>e.some(e=>e===`Meta`||e===`Alt`||e===`Control`))?[r[0]]:r).map(t=>t.map(t=>{if(Number.isFinite(+t))if(t=+t,t>=65&&t<=90)t=String.fromCharCode(t);else{var n={8:e.C.BACKSPACE_KEY,9:e.C.TAB_KEY,13:e.C.ENTER_KEY,16:e.C.SHIFT_KEY,17:e.C.CONTROL_KEY,18:e.C.ALT_KEY,19:e.C.PAUSE_KEY,20:e.C.CAPS_LOCK_KEY,27:e.C.ESCAPE,32:e.C.SPACE_KEY,33:e.C.PAGE_UP_KEY,34:e.C.PAGE_DOWN_KEY,35:e.C.END_KEY,36:e.C.HOME_KEY,37:`←`,38:`↑`,39:`→`,40:`↓`,45:e.C.INSERT_KEY,46:e.C.DELETE_KEY,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,59:`;`,61:`=`,93:e.C.CONTEXT_MENU_KEY,96:`0`,97:`1`,98:`2`,99:`3`,100:`4`,101:`5`,102:`6`,103:`7`,104:`8`,105:`9`,106:`×`,107:`+`,109:`−`,110:`.`,111:`÷`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,186:`;`,187:`=`,189:`-`,188:`,`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`,224:`⌘`}[t];n?t=n:(console.warn(`Unknown key code: `+t),t=String.fromCharCode(t))}return t}).map(e=>{var t=n[e]??e;return t.charAt(0).toUpperCase()+t.substring(1)}))},bn=function(e){return e=uu.indexOf(e),e===-1?Number.MAX_VALUE:e},xn=function(e){return e&&typeof e.init==`function`&&typeof e.getDiv==`function`&&typeof e.getId==`function`&&typeof e.getParent==`function`&&typeof e.getLevel==`function`&&typeof e.isSelectable==`function`&&typeof e.isCollapsible==`function`&&typeof e.dispose==`function`&&typeof e.getClickTarget==`function`&&typeof e.setVisible_==`function`&&typeof e.getParentToolbox==`function`},Sn=function(e){return typeof e.getName==`function`&&typeof e.getContents==`function`&&typeof e.setSelected==`function`&&typeof e.onClick==`function`&&xn(e)&&e.isSelectable()},Cn=function(t,n=ss.STANDARD,r){return[n>=ss.STANDARD&&En(t),Tn(t),...Dn(t,n,r),n===ss.LOQUACIOUS&&Mn(t),n>=ss.STANDARD&&(t.isEnabled()?void 0:e.C.BLOCK_LABEL_DISABLED),n>=ss.STANDARD&&(t.isCollapsed()?e.C.BLOCK_LABEL_COLLAPSED:void 0),n>=ss.LOQUACIOUS&&(t.isShadow()?e.C.BLOCK_LABEL_REPLACEABLE:void 0),n>=ss.STANDARD&&Ln(t),n>=ss.LOQUACIOUS&&t.getAriaRoleDescription()].filter(e=>!!e).join(`, `)},wn=function(t,n,r=ss.STANDARD){var i=r>=ss.LOQUACIOUS,a=[],o=t.fieldRow.filter(e=>e.isVisible()).flatMap((e,t,n)=>{if(e.isLabelField()){if(t<n.length-1&&n[t+1].isLabelField())return a.push(e.computeAriaLabel(i)),[];if(a.length>=1)return a.push(e.computeAriaLabel(i)),e=a.join(` `),a=[],e}return e.computeAriaLabel(i)});if(!o.length&&n){let e=t.getSourceBlock().inputList,i=e.indexOf(t);if(i>0)return wn(e[i-1],n,r)}var s;return t.type===e.je.VALUE&&((s=t.connection)==null?void 0:s.targetConnection)===null&&r>=ss.STANDARD&&o.push(e.C.INPUT_LABEL_EMPTY),o.filter(e=>!!e)},Tn=function(t){var n,r,i=(n=t.outputConnection??t.previousConnection)==null||(r=n.targetConnection)==null?void 0:r.getParentInput();if(i&&(t=i.getSourceBlock(),!t.isInsertionMarker())){if(n=i.getAriaLabelText())t=n;else{if(!t.statementInputCount||(n=t.inputList.find(t=>t.type===e.je.STATEMENT),i===n)||(t=An(t,i,!1),!t.length))return;t=t.join(`, `)}return i.type===e.je.STATEMENT?(i=Array.isArray(t)?t.join(` `):t,e.C.BLOCK_LABEL_BEGIN_PREFIX.replace(`%1`,i)):t}},En=function(t){if(!t.isInFlyout&&!t.isDragging())return t.getRootBlock()===t?e.C.BLOCK_LABEL_BEGIN_STACK:void 0},Dn=function(t,n=ss.STANDARD,r){if(r)return[r];if(r=t=t.inputList.filter(e=>e.isVisible()),n<=ss.STANDARD){let n=t.filter(t=>t.type===e.je.STATEMENT);n.length>1&&(r=t.slice(0,t.indexOf(n[0])+1))}var i=[];return r.flatMap((t,r,a)=>{var o=t.getLabel(n),s;if(s=r<a.length-1&&kn(t)&&On(a[r+1])){s=a[r+1];let n;r=((n=t.connection)==null?void 0:n.type)===L.NEXT_STATEMENT||t.type===e.je.END_ROW;let i;s=!(!t.getSourceBlock().getInputsInline()||((i=s.connection)==null?void 0:i.type)===L.NEXT_STATEMENT||r)}return s?(i.push(o),[]):On(t)&&i.length>0?(i.push(o),t=i.join(` `),i=[],t):o})},On=function(e){return e=e.fieldRow.filter(e=>e.isVisible()),e.length>0&&e[0].isLabelField()},kn=function(t){return t.type===e.je.VALUE||t.type===e.je.STATEMENT?!1:(t=t.fieldRow.filter(e=>e.isVisible()),t.length>0&&t[t.length-1].isLabelField())},An=function(t,n,r){var i=t.inputList.indexOf(n);if(i===-1)throw Error(`Input with name "${n.name}" not found on block with id "${t.id}".`);var a=n.type===e.je.STATEMENT,o=a?jn(t.inputList,i):i,s=t.inputList.slice(o,i+1).filter(e=>e.isVisible()),c=s.map(e=>e.getLabel(ss.TERSE,e!==n||r)),l=a&&c.slice(0,-1).some(e=>!!e);return c.map((t,n)=>{if(t)return t;if(t=s[n],!(t.type===e.je.DUMMY||t.type===e.je.END_ROW||a&&n===c.length-1&&l))return e.C.INPUT_LABEL_INDEX.replace(`%1`,(t.getIndex()+1).toString())}).filter(e=>e!==void 0)},jn=function(t,n){for(--n;n>=0;n--)if(t[n].type===e.je.STATEMENT)return n+1;return 0},Mn=function(t){var n=t.workspace.getToolbox();if(n){var r=void 0;for(let e of n.getToolboxItems())if(Sn(e)){if(n=e.getContents(),Array.isArray(n)&&n.some(e=>e.kind.toLowerCase()===`block`&&`type`in e&&e.type===t.type)){r=e;break}`getColour`in e&&typeof e.getColour==`function`&&e.getColour()===t.getColour()&&(r=e)}if(r)return e.C.BLOCK_LABEL_TOOLBOX_CATEGORY.replace(`%1`,r.getName())}},Nn=function(t){switch(t){case du.BEFORE:return e.C.ANNOUNCE_MOVE_BEFORE;case du.AFTER:return e.C.ANNOUNCE_MOVE_AFTER;case du.INSIDE:return e.C.ANNOUNCE_MOVE_INSIDE;case du.AROUND:return e.C.ANNOUNCE_MOVE_AROUND;default:return e.C.ANNOUNCE_MOVE_TO}},Pn=function(t,n){var r=t.getParentInput();if(!r)return n;var i=r.getAriaLabelText();if(!i){if(t=An(t.getSourceBlock(),r,!0),!t.length)return n;i=t.join(`, `)}return n?e.C.ANNOUNCE_MOVE_OF.replace(`%1`,i).replace(`%2`,n):i},Fn=function(e,t,n,r=!1){var i=In(e,t),a=Nn(i),o=![du.BEFORE,du.AFTER].includes(i);return i=o&&n(!0),n=o&&n(!1),r=r?e.getSourceBlock().getStackBlocksCountLabel():``,o=t.getSourceBlock().getAriaLabel(ss.TERSE),i&&(r=Pn(e,r)),n&&(o=Pn(t,o)),a.replace(`%1`,r).replace(`%2`,o)},In=function(e,t){switch(e.type){case L.INPUT_VALUE:case L.OUTPUT_VALUE:return du.TO;case L.NEXT_STATEMENT:return e===e.getSourceBlock().nextConnection?du.BEFORE:du.AROUND;case L.PREVIOUS_STATEMENT:return t===t.getSourceBlock().nextConnection?du.AFTER:du.INSIDE}return du.UNKNOWN},Ln=function(t){var n=t.inputList.filter(t=>t.type===e.je.STATEMENT).length;if(n>1)return e.C.BLOCK_LABEL_HAS_BRANCHES.replace(`%1`,n.toString());switch(t.inputList.reduce((e,t)=>{var n;return t.fieldRow.reduce((e,t)=>t.EDITABLE&&!t.isFullBlockField()?++e:e,e)+ +(((n=t.connection)==null?void 0:n.type)===L.INPUT_VALUE)},0)){case 0:break;case 1:return e.C.BLOCK_LABEL_HAS_INPUT;default:return e.C.BLOCK_LABEL_HAS_INPUTS}},Rn=function(e){return e*Math.PI/180},zn=function(e,t,n){if(n<e){let t=n;n=e,e=t}return Math.max(e,Math.min(t,n))},Bn=function(){document.querySelector(`.blocklyDropDownDiv`)||(B=document.createElement(`div`),B.className=`blocklyDropDownDiv`,B.tabIndex=-1,B.id=He(),(ke()||document.body).appendChild(B),vu=document.createElement(`div`),vu.className=`blocklyDropDownContent`,B.appendChild(vu),wu=o(vu,`keydown`,null,Fe),yu=document.createElement(`div`),yu.className=`blocklyDropDownArrow`,B.appendChild(yu),B.style.opacity=`0`,B.style.transition=`transform 0.25s, opacity 0.25s`)},Vn=function(){Cu&&=(Cu(!1),null),$n()},Hn=function(){wu&&=(c(wu),null),B.remove(),Bn()},Un=function(e,t){B.style.backgroundColor=e,B.style.borderColor=t},Wn=function(e,t,n,r=!0){return Su=!0,qn(Kn(e),e,r,t,n)},Gn=function(e){var t=e.getSvgRoot(),n=e.workspace.scale,r=e.height*n;return e=e.width*n,t=$e(t),new P(t.y,t.y+r,t.x,t.x+e)},Kn=function(e){return e=e.getScaledBBox(),new P(e.top,e.bottom,e.left,e.right)},qn=function(e,t,n,r,i){var a=e.left+(e.right-e.left)/2,o=e.bottom;e=e.top,i&&(e+=i),i=t.getSourceBlock();for(var s=i.workspace;s.options.parentWorkspace;)s=s.options.parentWorkspace;return bu=s.getParentSvg().parentNode,Jn(t,i.RTL,a,o,a,e,n,r)},Jn=function(t,n,r,i,a,o,s,c){e.t().registerPopoverFocusLossHandler(Vn);var l;return(l=ke())==null||l.appendChild(B),xu=t,hu=c||null,B.style.direction=n?`rtl`:`ltr`,t=Os,gu=t.getRenderer().getClassName(),_u=t.getTheme().getClassName(),g(B,gu),g(B,_u),n=ae(t.getFocusableElement(),k.OWNS),m(t.getFocusableElement(),k.OWNS,n?[n,B.id]:B.id),t.getFocusableElement().classList.add(`blocklyShowingDropDownDiv`),r=tr(r,i,a,o),s&&(Cu=e.t().takeEphemeralFocus(B)),r},Yn=function(e,t,n,r){return e=Zn(e,n.left,n.right,r.width),{initialX:e.divX,initialY:t,finalX:e.divX,finalY:t+16,arrowX:e.arrowX,arrowY:-9,arrowAtTop:!0,arrowVisible:!0}},Xn=function(e,t,n,r){return e=Zn(e,n.left,n.right,r.width),{initialX:e.divX,initialY:t-r.height,finalX:e.divX,finalY:t-r.height-16,arrowX:e.arrowX,arrowY:r.height-2-8,arrowAtTop:!1,arrowVisible:!0}},Zn=function(e,t,n,r){return t=zn(t,e-r/2,n-r),e=e-8-t,e=zn(12,e,r-12-16),{arrowX:e,divX:t}},Qn=function(e,t){return xu===e&&(t?er():$n(),!0)},$n=function(){xu&&(e.t().unregisterPopoverFocusLossHandler(Vn),B.style.transform=`translate(0, 0)`,B.style.opacity=`0`,mu=setTimeout(function(){er()},250),hu&&=(hu(),null))},er=function(){if(xu){mu&&clearTimeout(mu),hu&&=(hu(),null),xu=null;var e=Os,t=ae(e.getFocusableElement(),k.OWNS)??``;m(e.getFocusableElement(),k.OWNS,t.replace(B.id,``)),e.getFocusableElement().classList.remove(`blocklyShowingDropDownDiv`),e.markFocused(),Cu&&=(Cu(),null),Hn()}},tr=function(e,t,n,r){e=Tu.getPositionMetrics(e,t,n,r),e.arrowVisible?(t=e.arrowX,n=e.arrowY,r=e.arrowAtTop?45:225,yu.style.display=``,yu.style.transform=`translate(${t}px, ${n}px) rotate(${r}deg)`,yu.setAttribute(`class`,`blocklyDropDownArrow`)):yu.style.display=`none`,t=Math.floor(e.initialX),n=Math.floor(e.initialY),r=Math.floor(e.finalX);var i=Math.floor(e.finalY),a=B.parentElement;return a&&(a=a.getBoundingClientRect(),t-=a.left+window.scrollX,r-=a.left+window.scrollX,n-=a.top+window.scrollY,i-=a.top+window.scrollY),B.style.left=t+`px`,B.style.top=n+`px`,B.style.visibility=`visible`,B.style.opacity=`1`,B.style.transform=`translate(`+(r-t)+`px,`+(i-n)+`px)`,!!e.arrowAtTop},nr=function(){if(xu){var e=xu.getSourceBlock();e=Su?Kn(xu):Gn(e);let t=e.left+(e.right-e.left)/2;tr(t,e.bottom,t,e.top)}else $n()},rr=function(e){return e.length?e.reduce(function(e,t){return e.length<t.length?e:t}).length:0},ir=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=rr(e);var r;for(r=0;r<t;r++){for(var i=e[0][r],a=1;a<e.length;a++)if(i!==e[a][r])return n;i===` `&&(n=r+1)}for(i=1;i<e.length;i++)if((a=e[i][r])&&a!==` `)return n;return t},ar=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=rr(e);var r;for(r=0;r<t;r++){for(var i=e[0].substr(-r-1,1),a=1;a<e.length;a++)if(i!==e[a].substr(-r-1,1))return n;i===` `&&(n=r+1)}for(i=1;i<e.length;i++)if((a=e[i].charAt(e[i].length-r-1))&&a!==` `)return n;return t},e.yf=function(e,t){e=e.split(`
6
+ Use `+r+` instead.`),Ts.has(e)||(Ts.add(e),console.warn(e))},xe=function(e){return Ds[e]||null},Se=function(){var e=[];for(let t in Ds)e.push(Ds[t]);return e},Ce=function(e){Ds[e.id]=e},we=function(e){delete Ds[e.id]},Te=function(){return Os},Ee=function(t){Os=t,t.rendered&&e.t().setPopoverFocusRoot(t.getInjectionDiv())},De=function(){var t=e.t().getFocusedNode();return t&&ve(t)?t:null},Oe=function(e){var t=De(),n=new(x(E.SELECTED))((t==null?void 0:t.id)??null,(e==null?void 0:e.id)??null,(e==null?void 0:e.workspace.id)??(t==null?void 0:t.workspace.id)??``);b(n)},ke=function(e=Os){return ks||(e&&e.rendered?e.getInjectionDiv():null)},Ae=function(e){ks=e},je=function(e){for(;e.options.parentWorkspace;)e=e.options.parentWorkspace;var t=e.getParentSvg(),n=e.getCachedParentSvgSize(),r=t.parentElement;if(r instanceof HTMLElement){var i=r.offsetWidth;r=r.offsetHeight,n.width!==i&&(t.setAttribute(`width`,i+`px`),e.setCachedParentSvgSize(i,null)),n.height!==r&&(t.setAttribute(`height`,r+`px`),e.setCachedParentSvgSize(null,r)),e.resize()}},Me=function(e,t){var n=Object.create(null),r=e.getDescendants(!0);t&&(e=e.getNextBlock())&&(e=r.indexOf(e),r.splice(e,r.length-e));for(let e=0,t;t=r[e];e++)n[t.type]?n[t.type]++:n[t.type]=1;return n},Ne=function(e){return function(){this.jsonInit(e)}},Pe=function(e){js.defineBlocksWithJsonArrayInternal(e)},e.yb=function(e){var t={};for(let n=0;n<e.length;n++){let r=e[n];if(!r){console.warn(`Block definition #${n} in JSON array is ${r}. Skipping`);continue}let i=r.type;i?t[i]={init:Ne(r)}:console.warn(`Block definition #${n} in JSON array is missing a type attribute. Skipping.`)}return t},e.Ab=function(e){for(let t of Object.keys(e)){let n=e[t];t in $o&&console.warn(`Block definition "${t}" overwrites previous definition.`),$o[t]=n}},Fe=function(t){var n=Os,r=e.t().getFocusedTree();for(let e of Se())if(r===e){n=e;break}!l(t)&&n&&(!n.rendered||n.isFlyout||n.isVisible())&&j.registry.onKeyDown(n,t)},y=function(e,t,n,r){if(!(e instanceof M)&&typeof e!=`string`||`${e}`.trim()===``)throw Error(`Invalid type "`+e+`". The type must be a non-empty string or a Blockly.registry.Type.`);if(e=`${e}`.toLowerCase(),typeof t!=`string`||t.trim()===``)throw Error(`Invalid name "`+t+`". The name must be a non-empty string.`);var i=t.toLowerCase();if(!n)throw Error(`Can not register a null value`);var a=Ns[e],o=Fs[e];switch(a||(a=Ns[e]=Object.create(null),o=Fs[e]=Object.create(null)),e){case String(M.FIELD):if(typeof n.fromJson!=`function`)throw Error(`Type "`+e+`" must have a fromJson function`)}if(!r&&a[i]&&a[i]!==n)throw Error(`Name "`+i+`" with type "`+e+`" already registered.`);a[i]=n,o[i]=t},Ie=function(e,t){e=`${e}`.toLowerCase(),t=t.toLowerCase();var n=Ns[e];n&&n[t]?(delete Ns[e][t],delete Fs[e][t]):console.warn(`Unable to unregister [`+t+`][`+e+`] from the registry.`)},Le=function(e,t,n){e=`${e}`.toLowerCase(),t=t.toLowerCase();var r=Ns[e];if(!r||!r[t]){if(t=`Unable to find [`+t+`][`+e+`] in the registry.`,n)throw Error(t+` You must require or register a `+e+` plugin.`);return console.warn(t),null}return r[t]},Re=function(e,t){return e=`${e}`.toLowerCase(),t=t.toLowerCase(),(e=Ns[e])?!!e[t]:!1},ze=function(e,t,n){return Le(e,t,n)},Be=function(e,t,n){e=`${e}`.toLowerCase();var r=Ns[e];if(!r){if(r=`Unable to find [${e}] in the registry.`,n)throw Error(`${r} You must require or register a ${e} plugin.`);return console.warn(r),null}if(!t)return r;e=Fs[e],n=Object.create(null);for(let t of Object.keys(r))n[e[t]]=r[t];return n},Ve=function(e,t,n){return t=t.plugins[String(e)]||`default`,typeof t==`function`?t:Le(e,t,n)},He=function(){return`blockly-`+(Rs++).toString(36)},Ue=function(){return Ls.genUid()},b=function(e){Vs.fireInternal(e)},We=function(){var e=Ke(Bs);Bs.length=0;for(let t of e){if(!t.workspaceId)continue;let e;(e=xe(t.workspaceId))==null||e.fireChangeListener(t)}},Ge=function(e){if(e.type===E.BLOCK_CHANGE&&e.element===`mutation`){let t;for(t=Bs.length;t>0;t--){let n=Bs[t-1];if(n.group!==e.group||n.workspaceId!==e.workspaceId||n.type!==E.BLOCK_MOVE||n.newParentId!==e.blockId)break}Bs.splice(t,0,e)}else Bs.push(e)},Ke=function(e){var t=[];for(let n of e)e=t[t.length-1],!n.isNull()&&(!e||e.workspaceId!==n.workspaceId||e.group!==n.group?t.push(n):n.type===E.BLOCK_MOVE&&e.type===E.BLOCK_MOVE&&n.blockId===e.blockId?(e.newParentId=n.newParentId,e.newInputName=n.newInputName,e.newCoordinate=n.newCoordinate,(e.reason||n.reason)&&(e.reason=Array.from(new Set((e.reason??[]).concat(n.reason??[]))))):n.type===E.BLOCK_CHANGE&&e.type===E.BLOCK_CHANGE&&n.blockId===e.blockId&&n.element===e.element&&n.name===e.name?e.newValue=n.newValue:n.type===E.VIEWPORT_CHANGE&&e.type===E.VIEWPORT_CHANGE?(e.viewTop=n.viewTop,e.viewLeft=n.viewLeft,e.scale=n.scale,e.oldScale=n.oldScale):(n.type!==E.CLICK||e.type!==E.BUBBLE_OPEN)&&(n.type===E.SELECTED&&e.type===E.SELECTED&&e.newElementId===void 0?(e.newElementId=n.newElementId,e.oldElementId===e.newElementId&&t.pop()):t.push(n)));return e=t.filter(e=>!e.isNull())},qe=function(){for(let e=0,t;t=Bs[e];e++)t.recordUndo=!1},Je=function(){return e.Ub===0},e.B=function(e){Vs.setGroupInternal(e)},Ye=function(e){var t=[];e=e.getDescendants(!1);for(let n=0,r;r=e[n];n++)t[n]=r.id;return t},x=function(e){var t=Le(M.EVENT,e,void 0);if(!t)throw Error(`Event type ${e} not found in registry.`);return t},Xe=function(t){Object.keys(t).forEach(function(n){e.C[n]=t[n]})},Ze=function(e){return Us.getSizeInternal(e)},Qe=function(e,t){return e=window.getComputedStyle(e),e[t]||e.getPropertyValue(t)},$e=function(e){var t=new N(0,0);e=e.getBoundingClientRect();var n=document.documentElement;return n=new N(window.pageXOffset||n.scrollLeft,window.pageYOffset||n.scrollTop),t.x=e.left+n.x,t.y=e.top+n.y,t},et=function(){var e=document.body,t=document.documentElement;return new N(e.scrollLeft||t.scrollLeft,e.scrollTop||t.scrollTop)},tt=function(e){var t=parseFloat(Qe(e,`borderLeftWidth`)),n=parseFloat(Qe(e,`borderRightWidth`)),r=parseFloat(Qe(e,`borderTopWidth`));return e=parseFloat(Qe(e,`borderBottomWidth`)),new P(r,e,t,n)},nt=function(e,t,n){e=rt(e,t,n),t.scrollLeft=e.x,t.scrollTop=e.y},rt=function(e,t,n){var r=$e(e),i=$e(t),a=tt(t),o=r.x-i.x-a.left;return r=r.y-i.y-a.top,i=new F(e.offsetWidth,e.offsetHeight),e=t.clientWidth-i.width,i=t.clientHeight-i.height,a=t.scrollLeft,t=t.scrollTop,n?(a+=o-e/2,t+=r-i/2):(a+=Math.min(o,Math.max(o-e,0)),t+=Math.min(r,Math.max(r-i,0))),new N(a,t)},it=function(e){var t=new N(0,0),n=e.x&&e.getAttribute(`x`),r=e.y&&e.getAttribute(`y`);return n&&(t.x=parseInt(n)),r&&(t.y=parseInt(r)),(n=(n=e.getAttribute(`transform`))&&n.match(Gs))&&(t.x+=Number(n[1]),n[3]&&(t.y+=Number(n[3]))),(e=e.getAttribute(`style`))&&e.includes(`translate`)&&(e=e.match(Ks))&&(t.x+=Number(e[1]),e[3]&&(t.y+=Number(e[3]))),t},at=function(e){for(var t=0,n=0;e;){let r=it(e);if(t+=r.x,n+=r.y,(` `+(e.getAttribute(`class`)||``)+` `).includes(` injectionDiv `))break;e=e.parentNode}return new N(t,n)},ot=function(){var e=et();return new P(e.y,document.documentElement.clientHeight+e.y,e.x,document.documentElement.clientWidth+e.x)},st=function(){var e=document.documentElement,t=window;return new N(t.pageXOffset||e.scrollLeft,t.pageYOffset||e.scrollTop)},ct=function(e,t){var n=t.x;t=t.y;var r=e.getInjectionDiv().getBoundingClientRect();return n=new N(n-r.left,t-r.top),t=e.getOriginOffsetInPixels(),N.difference(n,t).scale(1/e.scale)},lt=function(e,t){var n=t.scale(e.scale);t=n.x,n=n.y;var r=e.getInjectionDiv().getBoundingClientRect();return e=e.getOriginOffsetInPixels(),new N(t+r.left+e.x,n+r.top+e.y)},e.rc=function(e){return Zs.createElementNS(`https://developers.google.com/blockly/xml`,e)},e.sc=function(e){return Zs.createTextNode(e)},e.uc=function(e){var t=Ys.parseFromString(e,`text/xml`);if(t&&t.documentElement&&!t.getElementsByTagName(`parsererror`).length)return t.documentElement;if((t=Ys.parseFromString(e,`text/html`))&&t.body.firstChild&&t.body.firstChild.nodeName.toLowerCase()===`xml`)return t.body.firstChild;throw Error(`DOMParser was unable to parse: ${e}`)},ut=function(e){return dt(Xs.serializeToString(e))},dt=function(e){return e.replace(ec,e=>`&#${e.charCodeAt(0)};`)},ft=function(e){if(!e)return null;if(e instanceof Element||typeof e==`string`){e=vt(e);var t={contents:gt(e)};e instanceof Node&&_t(e,t),e=t}t=e.kind;var n=e.contents;if(t&&t!==`flyoutToolbox`&&t!==`categoryToolbox`)throw Error(`Invalid toolbox kind `+t+`. Please supply either flyoutToolbox or categoryToolbox`);if(!n)throw Error(`Toolbox must have a contents attribute.`);return e},pt=function(e){return e?e.contents?e.contents:Array.isArray(e)&&e.length>0&&!e[0].nodeType?e:gt(e):[]},mt=function(e){return rc.hasCategoriesInternal(e)},ht=function(e){return e&&e.contents?!!e.contents.filter(function(e){return e.kind.toUpperCase()===`CATEGORY`}).length:!1},gt=function(e){var t=[],n=e.childNodes;n||=e;for(let r=0,i;i=n[r];r++){if(!i.tagName)continue;e={};let n=i.tagName.toUpperCase();e.kind=n,n===`BLOCK`?e.blockxml=i:i.childNodes&&i.childNodes.length>0&&(e.contents=gt(i)),_t(i,e),t.push(e)}return t},_t=function(e,t){for(let n=0;n<e.attributes.length;n++){let r=e.attributes[n];r.nodeName.includes(`css-`)?(t.cssconfig=t.cssconfig||{},t.cssconfig[r.nodeName.replace(`css-`,``)]=r.value):t[r.nodeName]=r.value}},vt=function(t){var n=null;if(t){if(typeof t==`string`){if(n=e.uc(t),n.nodeName.toLowerCase()!==`xml`)throw TypeError(`Toolbox should be an <xml> document.`)}else t instanceof Element&&(n=t)}return n},yt=function(e,t,n,r,i,a){var o=a.scrollbar&&a.scrollbar.canScrollVertically();return e.horizontal===sc.LEFT?(n=i.absoluteMetrics.left+n,o&&a.RTL&&(n+=Js.scrollbarThickness)):(n=i.absoluteMetrics.left+i.viewMetrics.width-t.width-n,o&&!a.RTL&&(n-=Js.scrollbarThickness)),e.vertical===ac.TOP?e=i.absoluteMetrics.top+r:(e=i.absoluteMetrics.top+i.viewMetrics.height-t.height-r,a.scrollbar&&a.scrollbar.canScrollHorizontally()&&(e-=Js.scrollbarThickness)),new P(e,e+t.height,n,n+t.width)},bt=function(e,t){return{horizontal:t.toolboxMetrics.position===I.LEFT||e.horizontalLayout&&!e.RTL?sc.RIGHT:sc.LEFT,vertical:t.toolboxMetrics.position===I.BOTTOM?ac.TOP:ac.BOTTOM}},xt=function(e,t,n,r){var i=e.left,a=e.right-e.left,o=e.bottom-e.top;for(let s=0;s<r.length;s++){let c=r[s];e.intersects(c)&&(e=n===lc.UP?c.top-o-t:c.bottom+t,e=new P(e,e+o,i,i+a),s=-1)}return e},St=function(e,t){y(M.SERIALIZER,e,t)},Ct=function(e,{addCoordinates:t=!1,saveIds:n=!0}={}){var r=e.workspace,i=Object.create(null);return i.height=e.getSize().height,i.width=e.getSize().width,n&&(i.id=e.id),t&&(t=e.getRelativeToSurfaceXY(),i.x=r.RTL?r.getWidth()-t.x:t.x,i.y=t.y),e.getText()&&(i.text=e.getText()),e.isCollapsed()&&(i.collapsed=!0),e.isOwnEditable()||(i.editable=!1),e.isOwnMovable()||(i.movable=!1),e.isOwnDeletable()||(i.deletable=!1),i},wt=function(t,n,{recordUndo:r=!1}={}){var i=e.Qc;if(e.Qc=r,r=n.newComment(t.id),t.text!==void 0&&r.setText(t.text),t.x!==void 0||t.y!==void 0){let e=r.getRelativeToSurfaceXY(),i=t.x??e.x;i=n.RTL?n.getWidth()-i:i;var a;n=(a=t.y)??e.y,r.moveTo(new N(i,n))}return(t.width!==void 0||t.height)&&(a=r.getSize(),r.setSize(new F(t.width??a.width,t.height??a.height))),t.collapsed!==void 0&&r.setCollapsed(t.collapsed),t.editable!==void 0&&r.setEditable(t.editable),t.movable!==void 0&&r.setMovable(t.movable),t.deletable!==void 0&&r.setDeletable(t.deletable),e.Qc=i,r},Tt=function(e,t){y(M.PASTER,e,t)},Et=function(e){for(var t=e.workspace,n=e.getRelativeToSurfaceXY(),r=new N(0,0),i=t.getTopComments(!1).filter(t=>t.id!==e.id).map(e=>e.getRelativeToSurfaceXY());Dt(N.sum(n,r),i);)r.translate(t.RTL?-30:30,30);e.moveTo(N.sum(n,r))},Dt=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},Ot=function(e){return e&&typeof e.saveState==`function`&&typeof e.loadState==`function`},kt=function(e){return Mt(e),Po?(Nt(),Promise.resolve()):(Ac||=new Promise(e=>{jc=e,Mc=window.requestAnimationFrame(()=>{Nt(),e()})}),Ac)},At=function(){return Ac||Promise.resolve()},jt=function(e){e||window.cancelAnimationFrame(Mc),Nt(e),!e&&jc&&jc()},Mt=function(t){Oc.add(t),kc.set(t,e.gd);var n=t.getParent();n?Mt(n):Dc.add(t)},Nt=function(t){var n=t?new Set([t]):new Set([...Dc].map(e=>e.workspace)),r=[...Dc].filter(Ft).filter(e=>n.has(e.workspace));for(var i of r)It(i);for(let e of n)e.resizeContents(),e.connectionDBList.forEach(e=>e==null?void 0:e.beginBulkUpdates());for(var a of r)i=a.getRelativeToSurfaceXY(),a.updateComponentLocations(i);for(var o of n)o.connectionDBList.forEach(e=>e==null?void 0:e.endBulkUpdates());for(let t of r)a=e.gd,(o=kc.get(t))&&e.B(o),t.bumpNeighbours(),e.B(a);for(let e of r)Pt(e);t||(Ac=null)},Pt=function(e){Dc.delete(e),Oc.delete(e),kc.delete(e);for(let t of e.getChildren(!1))Pt(t)},Ft=function(e){return!e.isDisposed()&&!e.getParent()},It=function(e){if(Oc.has(e)&&e.initialized){for(let t of e.getChildren(!1))It(t);e.renderEfficiently()}},Lt=function(e,t){Ut(Fc.ALERT,e,t,void 0)},Rt=function(e,t){Ut(Fc.CONFIRM,e,t,void 0)},zt=function(e,t,n){Ut(Fc.PROMPT,e,n,t)},Bt=function(e,t){Rc(e,t)},Vt=function(e,t){zc(e,t)},Ht=function(e,t,n){Bc(e,t,n)},Ut=function(...[t,n,r,i]){var a=document.createElement(`dialog`),o=document.createElement(`form`),s=document.createElement(`label`),c=document.createElement(`input`),l=document.createElement(`div`),u=document.createElement(`button`);a.className=`blocklyDialog`,o.className=`blocklyDialogForm`,s.className=`blocklyDialogPrompt`,l.className=`blocklyDialogButtonRow`,u.className=`blocklyDialogConfirmButton`,o.setAttribute(`method`,`dialog`),s.textContent=n,s.setAttribute(`for`,`blockly-form-input`),u.textContent=e.C.DIALOG_OK,u.value=`ok`,a.appendChild(o),o.appendChild(s),t===Fc.PROMPT&&(c.id=`blockly-form-input`,c.className=`blocklyDialogInput`,c.type=`text`,c.name=`input`,c.autofocus=!0,i&&(c.value=i),o.appendChild(c)),l.appendChild(u),(t===Fc.CONFIRM||t===Fc.PROMPT)&&(n=document.createElement(`button`),n.className=`blocklyDialogCancelButton`,n.textContent=e.C.DIALOG_CANCEL,n.value=`cancel`,l.appendChild(n)),o.appendChild(l);var d;Lc===0&&(d=e.t().ephemeralFocusTaken()?void 0:e.t().takeEphemeralFocus(a)),Lc++,a.addEventListener(`close`,()=>{if(Lc--,!Lc){let e;(e=d)==null||e()}switch(a.remove(),t){case Fc.CONFIRM:r(a.returnValue===`ok`);break;case Fc.PROMPT:r(a.returnValue===`ok`?c.value:null);break;case Fc.ALERT:r==null||r()}}),document.body.appendChild(a),a.showModal()},Wt=function(e){return typeof e.bubbleIsVisible==`function`&&typeof e.setBubbleVisible==`function`&&typeof e.getBubble==`function`},Gt=function(e,t){return t.map(t=>e.getBlockById(t)).filter(e=>e&&e.isShadow()).length===t.length},Kt=function(e){return e&&typeof e.getProcedureDef==`function`},qt=function(e){return e.getVariableModel!==void 0},e.Bd=function(e){e=e.getAllBlocks(!1);var t=new Set;for(let n=0;n<e.length;n++){let r=e[n].getVarModels();if(r)for(let e=0;e<r.length;e++){let n=r[e];n.getId()&&t.add(n)}}return Array.from(t.values())},e.Cd=function(e){e=e.getAllBlocks(!1);var t=new Set;for(let r=0,i;i=e[r];r++){var n=i.getDeveloperVariables;if(n){n=n();for(let e=0;e<n.length;e++)t.add(n[e])}}return Array.from(t.values())},Jt=function(e){return $o.variables_set||$o.variables_get||console.warn(`There are no variable blocks, but there is a variable category.`),e.registerButtonCallback(`CREATE_VARIABLE`,function(e){$t(e.getTargetWorkspace())}),[{kind:`button`,text:`%{BKY_NEW_VARIABLE}`,callbackkey:`CREATE_VARIABLE`},...Xt(e,e.getVariableMap().getVariablesOfType(``),!0)]},Yt=function(e){return{VAR:{name:e.getName(),type:e.getType()}}},Xt=function(e,t,n,r=`variables_get`,i=`variables_set`){n&&=$o.math_change,e=[];var a=t.slice(-1)[0];return a&&($o[i]&&e.push({kind:`block`,type:i,gap:n?8:24,fields:Yt(a)}),n&&e.push({kind:`block`,type:`math_change`,gap:$o[r]?20:8,fields:Yt(a),inputs:{DELTA:{shadow:{type:`math_number`,fields:{NUM:1}}}}})),$o[r]&&e.push(...t.sort(ln).map(e=>({kind:`block`,type:r,gap:8,fields:Yt(e)}))),e},Zt=function(e){return Ql.generateUniqueNameInternal(e)},Qt=function(e,t){if(!t.length)return e;for(var n=``,r=`ijkmnopqrstuvwxyzabcdefgh`.indexOf(e);;){let i=!1;for(let n=0;n<t.length;n++)if(t[n].toLowerCase()===e){i=!0;break}if(!i)break;r++,r===25&&(r=0,n=`${Number(n)+1}`),e=`ijkmnopqrstuvwxyzabcdefgh`.charAt(r)+n}return e},$t=function(t,n,r){function i(r){en(e.C.NEW_VARIABLE_TITLE,r,function(r){if(r){var o=nn(r,t);if(o){if(o.getType()===a)var s=e.C.VARIABLE_ALREADY_EXISTS.replace(`%1`,o.getName());else s=e.C.VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE,s=s.replace(`%1`,o.getName()).replace(`%2`,o.getType());Bt(s,function(){i(r)})}else{let i=t.getVariableMap().createVariable(r,a);n&&n(r);let o=(s=t.getFlyout())==null?void 0:s.getWorkspace();if(o&&z.getIsActive()){var c=t=>{t.type===e.Od&&(t=t.blockId)&&(t=o.getBlockById(t))&&t.type===`variables_set`&&t.getFieldValue(`VAR`)===i.getId()&&(e.t().focusNode(t),o.removeChangeListener(c))};o.addChangeListener(c)}}}else n&&n(null)})}var a=r||``;i(``)},e.Rd=function(t,n,r){function i(a){var o=e.C.RENAME_VARIABLE_TITLE.replace(`%1`,n.getName());en(o,a,function(a){if(a){var o=tn(a,n.getType(),t),s=rn(n.getName(),a,t);if(o||s){var c=``;o?c=e.C.VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE.replace(`%1`,o.getName()).replace(`%2`,o.getType()):s&&(c=e.C.VARIABLE_ALREADY_EXISTS_FOR_A_PARAMETER.replace(`%1`,a).replace(`%2`,s)),Bt(c,function(){i(a)})}else t.getVariableMap().renameVariable(n,a),r&&r(a)}else r&&r(null)})}i(``)},en=function(t,n,r){Ht(t,n,function(t){t&&(t=t.replace(/[\s\xa0]+/g,` `).trim(),t===e.C.RENAME_VARIABLE||t===e.C.NEW_VARIABLE)&&(t=null),r(t)})},tn=function(e,t,n){n=n.getVariableMap().getAllVariables(),e=e.toLowerCase();for(let r=0,i;i=n[r];r++)if(i.getName().toLowerCase()===e&&i.getType()!==t)return i;return null},nn=function(e,t){t=t.getVariableMap().getAllVariables(),e=e.toLowerCase();for(let n=0,r;r=t[n];n++)if(r.getName().toLowerCase()===e)return r;return null},rn=function(e,t,n){return n.getProcedureMap().getProcedures().length?an(e,t,n):on(e,t,n)},an=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getProcedureMap().getProcedures();for(let i of n){var r=i.getParameters().filter(qt).map(e=>e.getVariableModel().getName());if(r&&(n=r.some(t=>t.toLowerCase()===e),r=r.some(e=>e.toLowerCase()===t),n&&r))return i.getName()}return null},on=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getAllBlocks(!1);for(let i of n){if(!Kt(i))continue;n=i.getProcedureDef();var r=n[1];let a=r.some(t=>t.toLowerCase()===e);if(r=r.some(e=>e.toLowerCase()===t),a&&r)return n[0]}return null},sn=function(t){var n=e.rc(`field`);return n.setAttribute(`name`,`VAR`),n.setAttribute(`id`,t.getId()),n.setAttribute(`variabletype`,t.getType()),t=e.sc(t.getName()),n.appendChild(t),n},e.Wd=function(t,n,r,i){var a=e.Vd(t,n,r,i);if(!a){a=t.getVariableMap();let e=t.getPotentialVariableMap();r||=Zt(t.isFlyout?t.targetWorkspace:t),a=e?e.createVariable(r,i,n??void 0):a.createVariable(r,i,n)}return a},e.Vd=function(e,t,n,r){var i=e.getPotentialVariableMap(),a=null;if(t&&(a=e.getVariableMap().getVariableById(t),!a&&i&&(a=i.getVariableById(t)),a))return a;if(n){if(r===void 0)throw Error(`Tried to look up a variable by name without a type`);a=e.getVariableMap().getVariable(n,r),!a&&i&&(a=i.getVariable(n,r))}return a},cn=function(e,t){e=e.getVariableMap().getAllVariables();var n=[];if(t.length!==e.length)for(let r=0;r<e.length;r++){let i=e[r];t.includes(i)||n.push(i)}return n},ln=function(e,t){return Zl.compare(e.getName(),t.getName())},un=function(e,t){var n=[];e=e.getAllBlocks(!1);for(let r=0;r<e.length;r++){let i=e[r].getVarModels();if(i)for(let a=0;a<i.length;a++)i[a].getId()===t&&n.push(e[r])}return n},e.$d=function(t,n,r){var i=n.getName(),a=un(t,n.getId());for(let t=a.length-1;t>=0;t--){let n=a[t];if(n.type===`procedures_defnoreturn`||n.type===`procedures_defreturn`){r=String(n.getFieldValue(`NAME`)),i=e.C.CANNOT_DELETE_VARIABLE_PROCEDURE.replace(`%1`,i).replace(`%2`,r),Rc(i,void 0);return}n===r&&a.splice(t,1)}r&&a.length||a.length>1?(i=e.C.DELETE_VARIABLE_CONFIRMATION.replace(`%1`,String(a.length+(r&&!r.workspace.isFlyout?1:0))).replace(`%2`,i),Vt(i,e=>{e&&n&&t.getVariableMap().deleteVariable(n)})):t.getVariableMap().deleteVariable(n)},dn=function(e,{addCoordinates:t=!1,addInputBlocks:n=!0,addNextBlocks:r=!0,doFullSerialization:i=!0,saveIds:a=!0}={}){if(e.isInsertionMarker())return null;var o={type:e.type,id:a?e.id:void 0};if(t){t=e.workspace;var s=e.getRelativeToSurfaceXY();o.x=Math.round(t.RTL?t.getWidth()-s.x:s.x),o.y=Math.round(s.y)}e.isCollapsed()&&(o.collapsed=!0),e.isEnabled()||(o.disabledReasons=Array.from(e.getDisabledReasons())),e.isOwnDeletable()||(o.deletable=!1),e.isOwnMovable()||(o.movable=!1),e.isOwnEditable()||(o.editable=!1),e.inputsInline!==void 0&&e.inputsInline!==e.inputsInlineDefault&&(o.inline=e.inputsInline),e.data&&(o.data=e.data),e.saveExtraState?(t=e.saveExtraState(i),t!==null&&(o.extraState=t)):e.mutationToDom&&(t=e.mutationToDom(),t!==null&&(o.extraState=ti(t).replace(` xmlns="https://developers.google.com/blockly/xml"`,``))),t=Object.create(null);for(var c of e.getIcons())Ot(c)&&(s=c.saveState(i))&&(t[c.getType().toString()]=s);Object.keys(t).length&&(o.icons=t),c=Object.create(null);for(var l of e.getFields())l.isSerializable()&&(c[l.name]=l.saveState(i));if(Object.keys(c).length&&(o.fields=c),n){for(n=Object.create(null),l=0;l<e.inputList.length;l++)c=e.inputList[l],c.connection&&(t=fn(c.connection,i,a))&&(n[c.name]=t);Object.keys(n).length&&(o.inputs=n)}return r&&e.nextConnection&&(e=fn(e.nextConnection,i,a))&&(o.next=e),o},fn=function(e,t,n){var r=e.getShadowState(!0);if(e=e.targetBlock(),!r&&!e)return null;var i=Object.create(null);return r&&(i.shadow=r),e&&!e.isShadow()&&(i.block=dn(e,{doFullSerialization:t,saveIds:n})),i},pn=function(e,t,{recordUndo:n=!1}={}){return e=mn(e,t,{recordUndo:n}),t.rendered&&jt(),e},mn=function(t,n,{parentConnection:r,isShadow:i=!1,recordUndo:a=!1}={}){var o=e.Qc;e.Qc=a,(a=e.gd)||e.B(!0),e.Ub++;var s=n.getVariableMap().getAllVariables();try{var c=hn(t,n,{parentConnection:r,isShadow:i})}finally{e.Ub--}if(gn(n,s),Je()&&b(new(x(E.BLOCK_CREATE))(c)),e.B(a),e.Qc=o,n.rendered){let e=c;setTimeout(()=>{e.disposed||e.setConnectionTracking(!0)},1)}return c},hn=function(t,n,{parentConnection:r,isShadow:i=!1}={}){if(!t.type)throw new tu(t);var a=n.newBlock(t.type,t.id);a.setShadow(i),i=t.x===void 0?0:t.x;var o=t.y===void 0?0:t.y,s=a.workspace;if(i=s.RTL?s.getWidth()-i:i,a.moveBy(i,o),t.collapsed&&a.setCollapsed(!0),t.deletable===!1&&a.setDeletable(!1),t.movable===!1&&a.setMovable(!1),t.editable===!1&&a.setEditable(!1),t.enabled===!1&&a.setDisabledReason(!0,`MANUALLY_DISABLED`),Array.isArray(t.disabledReasons))for(var c of t.disabledReasons)a.setDisabledReason(!0,c);if(t.inline!==void 0&&a.setInputsInline(t.inline),t.data!==void 0&&(a.data=t.data),t.extraState&&(a.loadExtraState?a.loadExtraState(t.extraState):a.domToMutation&&a.domToMutation(e.uc(t.extraState))),r){if(r.getSourceBlock().isShadow()&&!a.isShadow())throw new iu(t);if(r.type===e.je.VALUE){if(c=a.outputConnection,!c)throw new nu(`output`,a,t)}else if(c=a.previousConnection,!c)throw new nu(`previous`,a,t);if(!r.connect(c))throw n=a.workspace.connectionChecker,new ru(n.getErrorMessage(n.canConnectWithReason(c,r,!1),c,r),r.type===e.je.VALUE?`output connection`:`previous connection`,a,t)}if(t.icons){r=Object.keys(t.icons);for(var l of r){if(r=t.icons[l],c=a.getIcon(l),!c){if(c=Le(M.ICON,l,!1),!c)throw new au(l,a,t);c=new c(a),a.addIcon(c)}Ot(c)&&c.loadState(r)}}if(t.fields)for(l=Object.keys(t.fields),r=0;r<l.length;r++)c=l[r],i=t.fields[c],(o=a.getField(c))?o.loadState(i):console.warn(`Ignoring non-existant field ${c} in block ${a.type}`);if(t.inputs)for(l=Object.keys(t.inputs),r=0;r<l.length;r++){if(c=l[r],i=a.getInput(c),!i||!i.connection)throw new nu(c,a,t);_n(i.connection,t.inputs[c])}if(t.next){if(!a.nextConnection)throw new nu(`next`,a,t);_n(a.nextConnection,t.next)}if(n.rendered){a.setConnectionTracking(!1),a.initSvg(),a.queueRender();for(let e of a.getIcons())e.onLocationChange(a.getRelativeToSurfaceXY())}else a.initModel();return a},gn=function(e,t){if(Je())for(e=cn(e,t),t=0;t<e.length;t++){let n=e[t];b(new(x(E.VAR_CREATE))(n))}},_n=function(e,t){t.shadow&&e.setShadowState(t.shadow),t.block&&hn(t.block,e.getSourceBlock().workspace,{parentConnection:e})},vn=function(e){return e=yn(e,lu),e.length?e[0].join(Vo?` `:` + `):``},yn=function(t,n){if(t=j.registry.getKeyCodesByShortcutName(t),t.length===0)return[];t=t.map(e=>e.split(`+`)),t.forEach(e=>e.sort((e,t)=>(e=bn(e),t=bn(t),e-t))),t.sort((e,t)=>(e=+!!e.includes(`Meta`),+!!t.includes(`Meta`)-e));var r=t.filter(e=>e.includes(`Meta`)===Vo);return r=r.length===0?t:r,r.sort((e,t)=>e.length-t.length),(r.some(e=>e.some(e=>e===`Meta`||e===`Alt`||e===`Control`))?[r[0]]:r).map(t=>t.map(t=>{if(Number.isFinite(+t)){if(t=+t,t>=65&&t<=90)t=String.fromCharCode(t);else{var n={8:e.C.BACKSPACE_KEY,9:e.C.TAB_KEY,13:e.C.ENTER_KEY,16:e.C.SHIFT_KEY,17:e.C.CONTROL_KEY,18:e.C.ALT_KEY,19:e.C.PAUSE_KEY,20:e.C.CAPS_LOCK_KEY,27:e.C.ESCAPE,32:e.C.SPACE_KEY,33:e.C.PAGE_UP_KEY,34:e.C.PAGE_DOWN_KEY,35:e.C.END_KEY,36:e.C.HOME_KEY,37:`←`,38:`↑`,39:`→`,40:`↓`,45:e.C.INSERT_KEY,46:e.C.DELETE_KEY,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,59:`;`,61:`=`,93:e.C.CONTEXT_MENU_KEY,96:`0`,97:`1`,98:`2`,99:`3`,100:`4`,101:`5`,102:`6`,103:`7`,104:`8`,105:`9`,106:`×`,107:`+`,109:`−`,110:`.`,111:`÷`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,186:`;`,187:`=`,189:`-`,188:`,`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`,224:`⌘`}[t];n?t=n:(console.warn(`Unknown key code: `+t),t=String.fromCharCode(t))}}return t}).map(e=>{var t=n[e]??e;return t.charAt(0).toUpperCase()+t.substring(1)}))},bn=function(e){return e=uu.indexOf(e),e===-1?Number.MAX_VALUE:e},xn=function(e){return e&&typeof e.init==`function`&&typeof e.getDiv==`function`&&typeof e.getId==`function`&&typeof e.getParent==`function`&&typeof e.getLevel==`function`&&typeof e.isSelectable==`function`&&typeof e.isCollapsible==`function`&&typeof e.dispose==`function`&&typeof e.getClickTarget==`function`&&typeof e.setVisible_==`function`&&typeof e.getParentToolbox==`function`},Sn=function(e){return typeof e.getName==`function`&&typeof e.getContents==`function`&&typeof e.setSelected==`function`&&typeof e.onClick==`function`&&xn(e)&&e.isSelectable()},Cn=function(t,n=ss.STANDARD,r){return[n>=ss.STANDARD&&En(t),Tn(t),...Dn(t,n,r),n===ss.LOQUACIOUS&&Mn(t),n>=ss.STANDARD&&(t.isEnabled()?void 0:e.C.BLOCK_LABEL_DISABLED),n>=ss.STANDARD&&(t.isCollapsed()?e.C.BLOCK_LABEL_COLLAPSED:void 0),n>=ss.LOQUACIOUS&&(t.isShadow()?e.C.BLOCK_LABEL_REPLACEABLE:void 0),n>=ss.STANDARD&&Ln(t),n>=ss.LOQUACIOUS&&t.getAriaRoleDescription()].filter(e=>!!e).join(`, `)},wn=function(t,n,r=ss.STANDARD){var i=r>=ss.LOQUACIOUS,a=[],o=t.fieldRow.filter(e=>e.isVisible()).flatMap((e,t,n)=>{if(e.isLabelField()){if(t<n.length-1&&n[t+1].isLabelField())return a.push(e.computeAriaLabel(i)),[];if(a.length>=1)return a.push(e.computeAriaLabel(i)),e=a.join(` `),a=[],e}return e.computeAriaLabel(i)});if(!o.length&&n){let e=t.getSourceBlock().inputList,i=e.indexOf(t);if(i>0)return wn(e[i-1],n,r)}var s;return t.type===e.je.VALUE&&((s=t.connection)==null?void 0:s.targetConnection)===null&&r>=ss.STANDARD&&o.push(e.C.INPUT_LABEL_EMPTY),o.filter(e=>!!e)},Tn=function(t){var n,r,i=(n=t.outputConnection??t.previousConnection)==null||(r=n.targetConnection)==null?void 0:r.getParentInput();if(i&&(t=i.getSourceBlock(),!t.isInsertionMarker())){if(n=i.getAriaLabelText())t=n;else{if(!t.statementInputCount||(n=t.inputList.find(t=>t.type===e.je.STATEMENT),i===n)||(t=An(t,i,!1),!t.length))return;t=t.join(`, `)}return i.type===e.je.STATEMENT?(i=Array.isArray(t)?t.join(` `):t,e.C.BLOCK_LABEL_BEGIN_PREFIX.replace(`%1`,i)):t}},En=function(t){if(!t.isInFlyout&&!t.isDragging())return t.getRootBlock()===t?e.C.BLOCK_LABEL_BEGIN_STACK:void 0},Dn=function(t,n=ss.STANDARD,r){if(r)return[r];if(r=t=t.inputList.filter(e=>e.isVisible()),n<=ss.STANDARD){let n=t.filter(t=>t.type===e.je.STATEMENT);n.length>1&&(r=t.slice(0,t.indexOf(n[0])+1))}var i=[];return r.flatMap((t,r,a)=>{var o=t.getLabel(n),s;if(s=r<a.length-1&&kn(t)&&On(a[r+1])){s=a[r+1];let n;r=((n=t.connection)==null?void 0:n.type)===L.NEXT_STATEMENT||t.type===e.je.END_ROW;let i;s=!(!t.getSourceBlock().getInputsInline()||((i=s.connection)==null?void 0:i.type)===L.NEXT_STATEMENT||r)}return s?(i.push(o),[]):On(t)&&i.length>0?(i.push(o),t=i.join(` `),i=[],t):o})},On=function(e){return e=e.fieldRow.filter(e=>e.isVisible()),e.length>0&&e[0].isLabelField()},kn=function(t){return t.type===e.je.VALUE||t.type===e.je.STATEMENT?!1:(t=t.fieldRow.filter(e=>e.isVisible()),t.length>0&&t[t.length-1].isLabelField())},An=function(t,n,r){var i=t.inputList.indexOf(n);if(i===-1)throw Error(`Input with name "${n.name}" not found on block with id "${t.id}".`);var a=n.type===e.je.STATEMENT,o=a?jn(t.inputList,i):i,s=t.inputList.slice(o,i+1).filter(e=>e.isVisible()),c=s.map(e=>e.getLabel(ss.TERSE,e!==n||r)),l=a&&c.slice(0,-1).some(e=>!!e);return c.map((t,n)=>{if(t)return t;if(t=s[n],!(t.type===e.je.DUMMY||t.type===e.je.END_ROW||a&&n===c.length-1&&l))return e.C.INPUT_LABEL_INDEX.replace(`%1`,(t.getIndex()+1).toString())}).filter(e=>e!==void 0)},jn=function(t,n){for(--n;n>=0;n--)if(t[n].type===e.je.STATEMENT)return n+1;return 0},Mn=function(t){var n=t.workspace.getToolbox();if(n){var r=void 0;for(let e of n.getToolboxItems())if(Sn(e)){if(n=e.getContents(),Array.isArray(n)&&n.some(e=>e.kind.toLowerCase()===`block`&&`type`in e&&e.type===t.type)){r=e;break}`getColour`in e&&typeof e.getColour==`function`&&e.getColour()===t.getColour()&&(r=e)}if(r)return e.C.BLOCK_LABEL_TOOLBOX_CATEGORY.replace(`%1`,r.getName())}},Nn=function(t){switch(t){case du.BEFORE:return e.C.ANNOUNCE_MOVE_BEFORE;case du.AFTER:return e.C.ANNOUNCE_MOVE_AFTER;case du.INSIDE:return e.C.ANNOUNCE_MOVE_INSIDE;case du.AROUND:return e.C.ANNOUNCE_MOVE_AROUND;default:return e.C.ANNOUNCE_MOVE_TO}},Pn=function(t,n){var r=t.getParentInput();if(!r)return n;var i=r.getAriaLabelText();if(!i){if(t=An(t.getSourceBlock(),r,!0),!t.length)return n;i=t.join(`, `)}return n?e.C.ANNOUNCE_MOVE_OF.replace(`%1`,i).replace(`%2`,n):i},Fn=function(e,t,n,r=!1){var i=In(e,t),a=Nn(i),o=![du.BEFORE,du.AFTER].includes(i);return i=o&&n(!0),n=o&&n(!1),r=r?e.getSourceBlock().getStackBlocksCountLabel():``,o=t.getSourceBlock().getAriaLabel(ss.TERSE),i&&(r=Pn(e,r)),n&&(o=Pn(t,o)),a.replace(`%1`,r).replace(`%2`,o)},In=function(e,t){switch(e.type){case L.INPUT_VALUE:case L.OUTPUT_VALUE:return du.TO;case L.NEXT_STATEMENT:return e===e.getSourceBlock().nextConnection?du.BEFORE:du.AROUND;case L.PREVIOUS_STATEMENT:return t===t.getSourceBlock().nextConnection?du.AFTER:du.INSIDE}return du.UNKNOWN},Ln=function(t){var n=t.inputList.filter(t=>t.type===e.je.STATEMENT).length;if(n>1)return e.C.BLOCK_LABEL_HAS_BRANCHES.replace(`%1`,n.toString());switch(t.inputList.reduce((e,t)=>{var n;return t.fieldRow.reduce((e,t)=>t.EDITABLE&&!t.isFullBlockField()?++e:e,e)+ +(((n=t.connection)==null?void 0:n.type)===L.INPUT_VALUE)},0)){case 0:break;case 1:return e.C.BLOCK_LABEL_HAS_INPUT;default:return e.C.BLOCK_LABEL_HAS_INPUTS}},Rn=function(e){return e*Math.PI/180},zn=function(e,t,n){if(n<e){let t=n;n=e,e=t}return Math.max(e,Math.min(t,n))},Bn=function(){document.querySelector(`.blocklyDropDownDiv`)||(B=document.createElement(`div`),B.className=`blocklyDropDownDiv`,B.tabIndex=-1,B.id=He(),(ke()||document.body).appendChild(B),vu=document.createElement(`div`),vu.className=`blocklyDropDownContent`,B.appendChild(vu),wu=o(vu,`keydown`,null,Fe),yu=document.createElement(`div`),yu.className=`blocklyDropDownArrow`,B.appendChild(yu),B.style.opacity=`0`,B.style.transition=`transform 0.25s, opacity 0.25s`)},Vn=function(){Cu&&=(Cu(!1),null),$n()},Hn=function(){wu&&=(c(wu),null),B.remove(),Bn()},Un=function(e,t){B.style.backgroundColor=e,B.style.borderColor=t},Wn=function(e,t,n,r=!0){return Su=!0,qn(Kn(e),e,r,t,n)},Gn=function(e){var t=e.getSvgRoot(),n=e.workspace.scale,r=e.height*n;return e=e.width*n,t=$e(t),new P(t.y,t.y+r,t.x,t.x+e)},Kn=function(e){return e=e.getScaledBBox(),new P(e.top,e.bottom,e.left,e.right)},qn=function(e,t,n,r,i){var a=e.left+(e.right-e.left)/2,o=e.bottom;e=e.top,i&&(e+=i),i=t.getSourceBlock();for(var s=i.workspace;s.options.parentWorkspace;)s=s.options.parentWorkspace;return bu=s.getParentSvg().parentNode,Jn(t,i.RTL,a,o,a,e,n,r)},Jn=function(t,n,r,i,a,o,s,c){e.t().registerPopoverFocusLossHandler(Vn);var l;return(l=ke())==null||l.appendChild(B),xu=t,hu=c||null,B.style.direction=n?`rtl`:`ltr`,t=Os,gu=t.getRenderer().getClassName(),_u=t.getTheme().getClassName(),g(B,gu),g(B,_u),n=ae(t.getFocusableElement(),k.OWNS),m(t.getFocusableElement(),k.OWNS,n?[n,B.id]:B.id),t.getFocusableElement().classList.add(`blocklyShowingDropDownDiv`),r=tr(r,i,a,o),s&&(Cu=e.t().takeEphemeralFocus(B)),r},Yn=function(e,t,n,r){return e=Zn(e,n.left,n.right,r.width),{initialX:e.divX,initialY:t,finalX:e.divX,finalY:t+16,arrowX:e.arrowX,arrowY:-9,arrowAtTop:!0,arrowVisible:!0}},Xn=function(e,t,n,r){return e=Zn(e,n.left,n.right,r.width),{initialX:e.divX,initialY:t-r.height,finalX:e.divX,finalY:t-r.height-16,arrowX:e.arrowX,arrowY:r.height-2-8,arrowAtTop:!1,arrowVisible:!0}},Zn=function(e,t,n,r){return t=zn(t,e-r/2,n-r),e=e-8-t,e=zn(12,e,r-12-16),{arrowX:e,divX:t}},Qn=function(e,t){return xu===e&&(t?er():$n(),!0)},$n=function(){xu&&(e.t().unregisterPopoverFocusLossHandler(Vn),B.style.transform=`translate(0, 0)`,B.style.opacity=`0`,mu=setTimeout(function(){er()},250),hu&&=(hu(),null))},er=function(){if(xu){mu&&clearTimeout(mu),hu&&=(hu(),null),xu=null;var e=Os,t=ae(e.getFocusableElement(),k.OWNS)??``;m(e.getFocusableElement(),k.OWNS,t.replace(B.id,``)),e.getFocusableElement().classList.remove(`blocklyShowingDropDownDiv`),e.markFocused(),Cu&&=(Cu(),null),Hn()}},tr=function(e,t,n,r){e=Tu.getPositionMetrics(e,t,n,r),e.arrowVisible?(t=e.arrowX,n=e.arrowY,r=e.arrowAtTop?45:225,yu.style.display=``,yu.style.transform=`translate(${t}px, ${n}px) rotate(${r}deg)`,yu.setAttribute(`class`,`blocklyDropDownArrow`)):yu.style.display=`none`,t=Math.floor(e.initialX),n=Math.floor(e.initialY),r=Math.floor(e.finalX);var i=Math.floor(e.finalY),a=B.parentElement;return a&&(a=a.getBoundingClientRect(),t-=a.left+window.scrollX,r-=a.left+window.scrollX,n-=a.top+window.scrollY,i-=a.top+window.scrollY),B.style.left=t+`px`,B.style.top=n+`px`,B.style.visibility=`visible`,B.style.opacity=`1`,B.style.transform=`translate(`+(r-t)+`px,`+(i-n)+`px)`,!!e.arrowAtTop},nr=function(){if(xu){var e=xu.getSourceBlock();e=Su?Kn(xu):Gn(e);let t=e.left+(e.right-e.left)/2;tr(t,e.bottom,t,e.top)}else $n()},rr=function(e){return e.length?e.reduce(function(e,t){return e.length<t.length?e:t}).length:0},ir=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=rr(e);var r;for(r=0;r<t;r++){for(var i=e[0][r],a=1;a<e.length;a++)if(i!==e[a][r])return n;i===` `&&(n=r+1)}for(i=1;i<e.length;i++)if((a=e[i][r])&&a!==` `)return n;return t},ar=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=rr(e);var r;for(r=0;r<t;r++){for(var i=e[0].substr(-r-1,1),a=1;a<e.length;a++)if(i!==e[a].substr(-r-1,1))return n;i===` `&&(n=r+1)}for(i=1;i<e.length;i++)if((a=e[i].charAt(e[i].length-r-1))&&a!==` `)return n;return t},e.yf=function(e,t){e=e.split(`
7
7
  `);for(let l=0;l<e.length;l++){var n=l;a:{var r=void 0;let n;var i=e[l],a=t;if(i.length<=a){a=i;break a}let u=i.trim().split(/\s+/);for(r=0;r<u.length;r++)u[r].length>a&&(a=u[r].length);var o=-1/0;let d=1;do{n=o,r=i;var s=[];o=u.length/d,i=1;for(var c=0;c<u.length-1;c++)i<(c+1.5)/o?(i++,s[c]=!0):s[c]=!1;s=sr(u,s,a),o=or(u,s,a),i=u,c=[];for(let e=0;e<i.length;e++)c.push(i[e]),s[e]!==void 0&&c.push(s[e]?`
8
8
  `:` `);i=c.join(``),d++}while(o>n);a=r}e[n]=a}return e.join(`
9
- `)},or=function(e,t,n){for(var r=[0],i=[],a=0;a<e.length;a++)r[r.length-1]+=e[a].length,t[a]===!0?(r.push(0),i.push(e[a].charAt(e[a].length-1))):t[a]===!1&&r[r.length-1]++;for(e=Math.max(...r),t=0,a=0;a<r.length;a++)t-=Math.abs(n-r[a])**1.5*2,t-=(e-r[a])**1.5,`.?!`.includes(i[a])?t+=n/3:`,;)]}`.includes(i[a])&&(t+=n/4);return r.length>1&&r[r.length-1]<=r[r.length-2]&&(t+=.5),t},sr=function(e,t,n){var r=or(e,t,n);for(let a=0;a<t.length-1;a++){if(t[a]===t[a+1])continue;let o=[].concat(t);o[a]=!o[a],o[a+1]=!o[a+1];let s=or(e,o,n);if(s>r){r=s;var i=o}}return i?sr(e,i,n):t},e.zf=function(e){return/^\s*-?\d+(\.\d+)?\s*$/.test(e)},cr=function(e){if(e=lr(e)){for(e=e.tooltip;typeof e==`function`;)e=e();if(typeof e!=`string`)throw Error(`Tooltip function must return a string.`);return e}return``},lr=function(e){for(;e&&e.tooltip;){if(typeof e.tooltip==`string`||typeof e.tooltip==`function`)return e;e=e.tooltip}return null},ur=function(){document.querySelector(`.blocklyTooltipDiv`)||(Lu=document.createElement(`div`),Lu.className=`blocklyTooltipDiv`,(ke()||document.body).appendChild(Lu))},dr=function(e){e.mouseOverWrapper_=s(e,`pointerover`,null,pr),e.mouseOutWrapper_=s(e,`pointerout`,null,mr),e.addEventListener(`pointermove`,hr,!1)},fr=function(e){e&&(c(e.mouseOverWrapper_),c(e.mouseOutWrapper_),e.removeEventListener(`pointermove`,hr))},pr=function(e){Au||(e=lr(e.currentTarget),Fu!==e&&(_r(),Iu=null,Fu=e),clearTimeout(ju))},mr=function(){Au||(ju=setTimeout(function(){Iu=Fu=null,_r()},1),clearTimeout(Mu),Mu=0)},hr=function(e){if(Fu&&Fu.tooltip&&!Au)if(ku){let t=Nu-e.pageX;e=Pu-e.pageY,Math.sqrt(t*t+e*e)>10&&_r()}else Iu!==Fu&&(clearTimeout(Mu),Nu=e.pageX,Pu=e.pageY,Mu=setTimeout(()=>{if(this instanceof Element)for(let t of Se()){if(!t.rendered)continue;let n;if((n=t.getInjectionDiv())!=null&&n.contains(this)){var e=t;break}}br(e)},750))},gr=function(){Iu=Fu=null,_r()},_r=function(){ku&&(ku=!1,Lu&&(Lu.style.display=`none`)),Mu&&=(clearTimeout(Mu),0)},vr=function(e,t){Fu!==e&&(_r(),Iu=null,Fu=e),Fu&&Fu.tooltip&&!Au&&(e=e.getFocusableElement().getBoundingClientRect(),Nu=Fu.RTL?e.x+e.width:e.x,Pu=e.y+e.height,br(t))},yr=function(){_r(),Au=!0},br=function(t){if(!Au&&(Iu=Fu,Lu)){var n;if((n=ke(t))==null||n.appendChild(Lu),Lu.textContent=``,Lu&&Fu)if(typeof Ou==`function`)Ou(Lu,Fu);else for(t=cr(Fu),t=e.yf(t,50),t=t.split(`
10
- `),n=0;n<t.length;n++){var r=document.createElement(`div`);r.appendChild(document.createTextNode(t[n])),Lu.appendChild(r)}t=Fu.RTL,Lu.style.direction=t?`rtl`:`ltr`,Lu.style.display=`block`,ku=!0,n=document.documentElement.clientWidth,r=document.documentElement.clientHeight;var i=Nu;i=t?i-(0+Lu.offsetWidth):i+0;var a=Pu+10,o,s=(o=Lu)==null?void 0:o.parentElement;s&&(o=s.getBoundingClientRect(),i-=o.left+window.scrollX,a-=o.top+window.scrollY),a+Lu.offsetHeight>r+window.scrollY&&(a-=Lu.offsetHeight+20),t?i=Math.max(5-window.scrollX,i):i+Lu.offsetWidth>n+window.scrollX-10&&(i=n-Lu.offsetWidth-10);var{x:c,y:l}={x:i,y:a};Lu.style.left=c+`px`,Lu.style.top=l+`px`}},xr=function(e){e=`${e}`.toLowerCase().trim();var t=Vu[e];if(t||(t=e.substring(0,2)===`0x`?`#`+e.substring(2):e,t=t[0]===`#`?t:`#`+t,/^#[0-9a-f]{6}$/.test(t)))return t;if(/^#[0-9a-f]{3}$/.test(t))return[`#`,t[1],t[1],t[2],t[2],t[3],t[3]].join(``);var n=e.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return n&&(e=Number(n[1]),t=Number(n[2]),n=Number(n[3]),e>=0&&e<256&&t>=0&&t<256&&n>=0&&n<256)?Sr(e,t,n):null},Sr=function(e,t,n){return t=e<<16|t<<8|n,e<16?`#`+(16777216|t).toString(16).substr(1):`#`+t.toString(16)},Cr=function(e){return e=xr(e),e?(e=parseInt(e.substr(1),16),[e>>16,e>>8&255,e&255]):[0,0,0]},wr=function(e,t,n){var r=0,i=0,a=0;if(t===0)a=i=r=n;else{let o=Math.floor(e/60),s=e/60-o;e=n*(1-t);let c=n*(1-t*s);switch(t=n*(1-t*(1-s)),o){case 1:r=c,i=n,a=e;break;case 2:r=e,i=n,a=t;break;case 3:r=e,i=c,a=n;break;case 4:r=t,i=e,a=n;break;case 5:r=n,i=e,a=c;break;case 6:case 0:r=n,i=t,a=e}}return Sr(Math.floor(r),Math.floor(i),Math.floor(a))},Tr=function(e,t,n){return e=xr(e),!e||(t=xr(t),!t)?null:(e=Cr(e),t=Cr(t),Sr(Math.round(t[0]+n*(e[0]-t[0])),Math.round(t[1]+n*(e[1]-t[1])),Math.round(t[2]+n*(e[2]-t[2]))))},Er=function(e){return wr(e,zu,Bu*255)},Dr=function(t,n,r){var i=[],a=t.split(``);a.push(``);var o=0;t=[];var s=null;for(let u=0;u<a.length;u++){var c=a[u];if(o===0)if(c===`%`)(o=t.join(``))&&i.push(o),t.length=0,o=1;else if(r&&c===`
11
- `){let e=t.join(``);e&&i.push(e),t.length=0,i.push(c)}else t.push(c);else if(o===1)c===`%`?(t.push(c),o=0):n&&`0`<=c&&c<=`9`?(o=2,s=c,(c=t.join(``))&&i.push(c),t.length=0):c===`{`?o=3:(t.push(`%`,c),o=0);else if(o===2)if(`0`<=c&&c<=`9`)s+=c;else{var l=void 0;i.push(parseInt((l=s)??``,10)),u--,o=0}else o===3&&(c===``?(t.splice(0,0,`%{`),u--,o=0):c===`}`?(o=t.join(``),/[A-Z]\w*/i.test(o)?(c=o.toUpperCase(),(c=c.startsWith(`BKY_`)?c.substring(4):null)&&c in e.C?(o=e.C[c],typeof o==`string`?Array.prototype.push.apply(i,Dr(o,n,r)):n?i.push(`${o}`):i.push(o)):i.push(`%{`+o+`}`)):i.push(`%{`+o+`}`),o=t.length=0):t.push(c))}for((n=t.join(``))&&i.push(n),l=[],t.length=0,a=0;a<i.length;a++)typeof i[a]!=`string`||r&&i[a]===`
12
- `?((n=t.join(``))&&l.push(n),t.length=0,l.push(i[a])):t.push(i[a]);return(n=t.join(``))&&l.push(n),t.length=0,l},Or=function(e){return Dr(e,!0,!0)},kr=function(e){return typeof e==`string`?(e=Dr(e,!1,!1),e.length?String(e[0]):``):e},Ar=function(e){var t=typeof e==`string`?kr(e):e,n=Number(t);if(!isNaN(n)&&0<=n&&n<=360)return{hue:n,hex:wr(n,zu,Bu*255)};if(n=xr(t))return{hue:null,hex:n};throw n=`Invalid colour: "`+t+`"`,e!==t&&(n+=` (from "`+e+`")`),Error(n)},jr=function(){Zu&&=(Zu(!1),null),Pr()},Mr=function(){var e=ke()||document.body,t=document.querySelector(`div.blocklyWidgetDiv`);t?Xu=t:(Xu=document.createElement(`div`),Xu.id=He(),Xu.className=`blocklyWidgetDiv`,Xu.tabIndex=-1),o(Xu,`keydown`,null,Fe),e.appendChild(Xu)},Nr=function(t,n,r,i,a=!0){if(Pr(),Gu=t,qu=r,r=Xu){Ku=i??Os;var o=ae(Ku.getFocusableElement(),k.OWNS);m(Ku.getFocusableElement(),k.OWNS,o?[o,r.id]:r.id),Ku.getFocusableElement().classList.add(`blocklyShowingWidgetDiv`);var s;(s=ke())==null||s.appendChild(r),r.style.direction=n?`rtl`:`ltr`,r.style.display=`block`,!i&&t instanceof V&&t.getSourceBlock(),Ju=Ku.getRenderer().getClassName(),Yu=Ku.getTheme().getClassName(),Ju&&g(r,Ju),Yu&&g(r,Yu),a&&(Zu=e.t().takeEphemeralFocus(r)),e.t().registerPopoverFocusLossHandler(jr)}},Pr=function(){if(Gu){Gu=null;var t=Xu;if(t){e.t().unregisterPopoverFocusLossHandler(jr),t.style.display=`none`,t.style.left=``,t.style.top=``,qu&&=(qu(),null),t.textContent=``,Ju&&=(_(t,Ju),``),Yu&&=(_(t,Yu),``);var n;(n=Ku)==null||n.markFocused(),Zu&&=(Zu(),null),Ku&&Xu&&(t=ae(Ku.getFocusableElement(),k.OWNS)??``,m(Ku.getFocusableElement(),k.OWNS,t.replace(Xu.id,``)),Ku.getFocusableElement().classList.remove(`blocklyShowingWidgetDiv`))}}},Fr=function(e){Gu===e&&Pr()},Ir=function(e){for(var t=Ku===null,n=e;!t&&n;){if(n===e){t=!0;break}n=e.options.parentWorkspace}t&&Pr()},Lr=function(e,t,n){if(Xu){var r=Xu.parentElement;r&&(r=r.getBoundingClientRect(),e-=r.left+window.scrollX,t-=r.top+window.scrollY),Xu.style.left=e+`px`,Xu.style.top=t+`px`,Xu.style.height=n+`px`}},Rr=function(e,t,n,r){var i=t.bottom+n.height>=e.bottom?t.top-n.height:t.bottom;e=r?Math.min(Math.max(t.right-n.width,e.left),e.right-n.width):Math.max(Math.min(t.left,e.right-n.width),e.left),i<0?Lr(e,0,n.height+i):Lr(e,i,n.height)},zr=function(){var e;(e=Gu)!=null&&e.repositionForWindowResize&&Gu.repositionForWindowResize()||Pr()},Br=function(e,t,n,r,i){if(Nr(ed,n,Gr,r),t.length){i||(e instanceof PointerEvent?i=new N(e.clientX,e.clientY):(console.warn(`Context menu opened with keyboard but no location given`),i=new N(0,0)));var a=Vr(t,n,e,i);td=a,Hr(a,n,i),setTimeout(function(){a.focus()},1),$u=null}else Wr()},Vr=function(e,t,n,r){var i=new wc;i.setRole(O.MENU);for(let a=0;a<e.length;a++){let o=e[a];if(o.separator){i.addChild(new Tc);continue}let s=new Cc(Kr(o));s.setRightToLeft(t),s.setRole(O.MENUITEM),i.addChild(s),s.setEnabled(o.enabled),o.enabled&&s.onAction(function(e,t){Wr(),requestAnimationFrame(()=>{setTimeout(()=>{o.callback(o.scope,n,t,r)},0)})},{})}return i},Hr=function(e,t,n){var r=ot();n=new P(n.y+r.top,n.y+r.top,n.x+r.left,n.x+r.left);var i=Xu;if(!i)throw Error(`Attempting to create a context menu when widget div is null`);i=e.render(i),g(i,`blocklyContextMenu`),o(i,`contextmenu`,null,Ur),e.focus(),i=e.getSize(),t&&(n.left+=i.width,n.right+=i.width,r.left+=i.width,r.right+=i.width),Rr(r,n,i,t),e.focus()},Ur=function(e){e.preventDefault(),e.stopPropagation()},Wr=function(){Fr(ed),$u=null;var e;(e=td)==null||e.dispose(),td=null},Gr=function(){td&&=(td.dispose(),null)},e.Pg=function(t,n){return()=>{e.Ub++;try{var r=n instanceof Element?ri(n,t.workspace):mn(n,t.workspace);let i=t.getRelativeToSurfaceXY();i.x=t.RTL?i.x-e.Og.snapRadius:i.x+e.Og.snapRadius,i.y+=e.Og.snapRadius*2,r.moveBy(i.x,i.y)}finally{e.Ub--}return Je()&&!r.isShadow()&&b(new(x(E.BLOCK_CREATE))(r)),e.t().focusNode(r),r}},Kr=function(e){var t=e.text;if(t&&!(t instanceof HTMLElement)){let n=document.createElement(`div`);n.className=`blocklyShortcutContainer`;let r=document.createElement(`span`);return r.textContent=t,t=document.createElement(`span`),t.className=`blocklyShortcut`,e=`id`in e&&e.associatedKeyboardShortcut?vn(e.associatedKeyboardShortcut):``,t.textContent=` ${e}`,n.appendChild(r),n.appendChild(t),n}return e.text},qr=function(e,t){return t=d(t,e.getParentSvg(),e.getInverseScreenCTM()),t.x/=e.scale,t.y/=e.scale,t},Jr=function(e,t,n){t=qr(e,t),sd.set(e,N.difference(n,t))},Yr=function(e,t){if(t=qr(e,t),e=sd.get(e),!e)throw Error(`Drag not initialized`);return N.sum(e,t)},Xr=function(t,n=!1){var r=e.rc(`comment`);n||r.setAttribute(`id`,t.id),n=t.workspace;var i=t.getRelativeToSurfaceXY().clone();return i.x=n.RTL?n.getWidth()-i.x:i.x,r.setAttribute(`x`,`${i.x}`),r.setAttribute(`y`,`${i.y}`),r.setAttribute(`w`,`${t.getSize().width}`),r.setAttribute(`h`,`${t.getSize().height}`),t.getText()&&(r.textContent=t.getText()),t.isCollapsed()&&r.setAttribute(`collapsed`,`true`),t.isOwnEditable()||r.setAttribute(`editable`,`false`),t.isOwnMovable()||r.setAttribute(`movable`,`false`),t.isOwnDeletable()||r.setAttribute(`deletable`,`false`),r},Zr=function(t){var n=e.rc(`variables`);for(let r=0;r<t.length;r++){let i=t[r],a=e.rc(`variable`);a.appendChild(e.sc(i.getName())),i.getType()&&a.setAttribute(`type`,i.getType()),a.id=i.getId(),n.appendChild(a)}return n},Qr=function(e,t){if(e.isInsertionMarker()&&(e=e.getChildren(!1)[0],!e))return new DocumentFragment;var n=0;if(e.workspace.RTL&&(n=e.workspace.getWidth()),t=$r(e,t),t.nodeType===ps.ELEMENT_NODE){let r=e.getRelativeToSurfaceXY();t.setAttribute(`x`,String(Math.round(e.workspace.RTL?n-r.x:r.x))),t.setAttribute(`y`,String(Math.round(r.y)))}return t},$r=function(t,n){if(t.isInsertionMarker())return(n=t.getChildren(!1)[0])?$r(n):new DocumentFragment;var r=e.rc(t.isShadow()?`shadow`:`block`);if(r.setAttribute(`type`,t.type),n||(r.id=t.id),t.mutationToDom){var i=t.mutationToDom();i&&(i.hasChildNodes()||i.hasAttributes())&&r.appendChild(i)}for(var a of t.getFields())a.isSerializable()?(i=e.rc(`field`),i.setAttribute(`name`,a.name||``),i=a.toXml(i)):i=null,i&&r.appendChild(i);if(a=t.getCommentText()){var o=t.getIcon(Kc.COMMENT);i=o.getBubbleSize();var s=o.bubbleIsVisible();o=o.getBubbleLocation();var c=e.rc(`comment`);c.appendChild(e.sc(a)),c.setAttribute(`pinned`,`${s}`),c.setAttribute(`h`,`${i.height}`),c.setAttribute(`w`,`${i.width}`),o&&(c.setAttribute(`x`,`${t.workspace.RTL?t.workspace.getWidth()-(o.x+i.width):o.x}`),c.setAttribute(`y`,`${o.y}`)),r.appendChild(c)}for(t.data&&(a=e.rc(`data`),a.appendChild(e.sc(t.data)),r.appendChild(a)),a=0;a<t.inputList.length;a++){i=t.inputList[a];var l=void 0;s=!0,i.type!==e.je.DUMMY&&i.type!==e.je.END_ROW&&(o=i.connection.targetBlock(),i.type===e.je.VALUE?l=e.rc(`value`):i.type===e.je.STATEMENT&&(l=e.rc(`statement`)),c=i.connection.getShadowDom(),!c||o&&o.isShadow()||l.appendChild(ei(c,n)),o&&(o=$r(o,n),o.nodeType===ps.ELEMENT_NODE&&(l.appendChild(o),s=!1)),l.setAttribute(`name`,i.name),s||r.appendChild(l))}if(t.inputsInline!==void 0&&t.inputsInline!==t.inputsInlineDefault&&r.setAttribute(`inline`,String(t.inputsInline)),t.isCollapsed()&&r.setAttribute(`collapsed`,`true`),t.isEnabled()||r.setAttribute(`disabled-reasons`,Array.from(t.getDisabledReasons()).map(encodeURIComponent).join(`,`)),t.isOwnDeletable()||r.setAttribute(`deletable`,`false`),t.isOwnMovable()||r.setAttribute(`movable`,`false`),t.isOwnEditable()||r.setAttribute(`editable`,`false`),l=t.getNextBlock(),l&&(a=$r(l,n),a.nodeType===ps.ELEMENT_NODE)){var u=e.rc(`next`);u.appendChild(a),r.appendChild(u)}return t=t.nextConnection&&t.nextConnection.getShadowDom(),!t||l&&l.isShadow()||u.appendChild(ei(t,n)),r},ei=function(e,t){for(var n=e=e.cloneNode(!0),r;n;)if(t&&n.nodeName===`shadow`&&n.removeAttribute(`id`),n.firstChild)n=n.firstChild;else{for(;n&&!n.nextSibling;){r=n,n=n.parentNode;let e;r.nodeType===ps.TEXT_NODE&&r.data.trim()===``&&((e=n)==null?void 0:e.firstChild)!==r&&v(r)}n&&(r=n,n=n.nextSibling,r.nodeType===ps.TEXT_NODE&&r.data.trim()===``&&v(r))}return e},ti=function(e){return ut(e).replace(/<(\w+)([^<]*)\/>/g,`<$1$2></$1>`)},e.ch=function(t,n){var r=0;n.RTL&&(r=n.getWidth());var i=[];fe();var a=e.gd;a||e.B(!0),n.setResizesEnabled&&n.setResizesEnabled(!1);var o=!0;try{for(let a=0,s;s=t.childNodes[a];a++){let t=s.nodeName.toLowerCase(),a=s;if(t===`block`||t===`shadow`&&!e.Qc){let e=ri(a,n);i.push(e.id);let t=parseInt(a.getAttribute(`x`)??`10`,10),s=parseInt(a.getAttribute(`y`)??`10`,10);isNaN(t)||isNaN(s)||e.moveBy(n.RTL?r-t:t,s,[`create`]),o=!1}else{if(t===`shadow`)throw TypeError(`Shadow block cannot be a top-level block.`);if(t===`comment`)ni(a,n);else if(t===`variables`){if(o)ii(a,n);else throw Error(`'variables' tag must exist once before block and shadow tag elements in the workspace XML, but it was found in another location.`);o=!1}}}}finally{e.B(a),n.setResizesEnabled&&n.setResizesEnabled(!0),n.rendered&&jt(),pe()}return b(new(x(E.FINISHED_LOADING))(n)),i},ni=function(e,t){var n,r=(n=e.getAttribute(`id`))??void 0;n=t.rendered?new md(t,r):new pd(t,r);var i;n.setText((i=e.textContent)??``);var a;i=parseInt((a=e.getAttribute(`x`))??``,10),a=parseInt(e.getAttribute(`y`)??``,10),isNaN(i)||isNaN(a)||(i=t.RTL?t.getWidth()-i:i,n.moveTo(new N(i,a)));var o;return t=parseInt((o=e.getAttribute(`w`))??``,10),o=parseInt(e.getAttribute(`h`)??``,10),isNaN(t)||isNaN(o)||n.setSize(new F(t,o)),e.getAttribute(`collapsed`)===`true`&&n.setCollapsed(!0),e.getAttribute(`editable`)===`false`&&n.setEditable(!1),e.getAttribute(`movable`)===`false`&&n.setMovable(!1),e.getAttribute(`deletable`)===`false`&&n.setDeletable(!1),n},e.fh=function(e,t){return e=ri(e,t),t.rendered&&jt(),e},ri=function(t,n){e.Ub++;var r=n.getVariableMap().getAllVariables();try{var i=si(t,n);if(n.rendered){let e=i,t=i.getDescendants(!1);e.setConnectionTracking(!1);for(let e=t.length-1;e>=0;e--)t[e].initSvg();for(let e=t.length-1;e>=0;e--)t[e].queueRender();setTimeout(function(){e.disposed||e.setConnectionTracking(!0)},1),n.resizeContents()}else{let e=i.getDescendants(!1);for(let t=e.length-1;t>=0;t--)e[t].initModel()}}finally{e.Ub--}if(Je()){for(t=cn(n,r),n=0;n<t.length;n++)r=t[n],b(new(x(E.VAR_CREATE))(r));b(new(x(E.BLOCK_CREATE))(i))}return i},ii=function(e,t){for(let r=0;r<e.children.length;r++){var n=e.children[r];let i=n.getAttribute(`type`),a=n.getAttribute(`id`);if(n=n.textContent,!n)break;t.getVariableMap().createVariable(n,i??void 0,a)}},ai=function(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r.textContent,a=r.getAttribute(`pinned`)===`true`,o=parseInt(r.getAttribute(`w`)??`50`,10),s=parseInt(r.getAttribute(`h`)??`50`,10),c=parseInt(r.getAttribute(`x`)??``,10),l=parseInt(r.getAttribute(`y`)??``,10);t.setCommentText(i);let u=t.getIcon(Kc.COMMENT);isNaN(o)||isNaN(s)||u.setBubbleSize(new F(o,s)),u.setBubbleVisible(a),setTimeout(()=>{isNaN(c)||isNaN(l)||(c=t.workspace.RTL?t.workspace.getWidth()-(c+o):c,u.setBubbleLocation(new N(c,l))),u.setBubbleVisible(a)},1)}},oi=function(e){var t=null,n=null;for(let r=0;r<e.childNodes.length;r++){let i=e.childNodes[r];i.nodeType===ps.ELEMENT_NODE&&(i.nodeName.toLowerCase()===`block`?t=i:i.nodeName.toLowerCase()===`shadow`&&(n=i))}return{childBlockElement:t,childShadowElement:n}},si=function(e,t,n,r){var i,a=e.getAttribute(`type`);if(!a)throw TypeError(`Block type unspecified: `+e.outerHTML);var o=(i=e.getAttribute(`id`))??void 0;i=t.newBlock(a,o);var s=[],c=[],l=[],u=[],d=[];o=[];for(var ee=0;ee<e.children.length;ee++){var f=e.children[ee];if(f.nodeType!==ps.TEXT_NODE)switch(f.nodeName.toLowerCase()){case`mutation`:s.push(f);break;case`comment`:c.push(f);break;case`data`:l.push(f);break;case`title`:case`field`:u.push(f);break;case`value`:case`statement`:d.push(f);break;case`next`:o.push(f);break;default:console.warn(`Ignoring unknown tag: `+f.nodeName)}}for(ee=!1,f=0;f<s.length;f++){let e=s[f];i.domToMutation&&(i.domToMutation(e),i.initSvg&&(ee=!0))}for(s=ee,ai(c,i),c=l,l=0;l<c.length;l++)i.data=c[l].textContent;if(n){if(r)if(i.previousConnection)r=i.previousConnection;else throw TypeError(`Next block does not have previous statement.`);else if(i.outputConnection)r=i.outputConnection;else if(i.previousConnection)r=i.previousConnection;else throw TypeError(`Child block does not have output or previous statement.`);if(!n.connect(r))throw e=i.workspace.connectionChecker,TypeError(e.getErrorMessage(e.canConnectWithReason(r,n,!1),r,n))}for(n=u,u=0;u<n.length;u++)c=n[u],(l=c.getAttribute(`name`))?(r=i,(ee=r.getField(l))?ee.fromXml(c):console.warn(`Ignoring non-existent field `+l+` in block `+r.type)):console.warn(`Ignoring unnamed field in block ${i.type}`);for(n=0;n<d.length;n++){if(u=d[n],r=(c=u.getAttribute(`name`))?i.getInput(c):null,!r){console.warn(`Ignoring non-existent input `+c+` in block `+a);break}if(u=oi(u),u.childBlockElement){if(!r.connection)throw TypeError(`Input connection does not exist.`);si(u.childBlockElement,t,r.connection,!1)}if(u.childShadowElement){var te=void 0;(te=r.connection)==null||te.setShadowDom(u.childShadowElement)}}for(a=o,te=0;te<a.length;te++){if(o=oi(a[te]),o.childBlockElement){if(!i.nextConnection)throw TypeError(`Next statement does not exist.`);if(i.nextConnection.isConnected())throw TypeError(`Next statement is already connected.`);si(o.childBlockElement,t,i.nextConnection,!0)}o.childShadowElement&&i.nextConnection&&i.nextConnection.setShadowDom(o.childShadowElement)}if(s&&i.initSvg(),(t=e.getAttribute(`inline`))&&i.setInputsInline(t===`true`),(t=e.getAttribute(`disabled`))&&i.setDisabledReason(t===`true`||t===`disabled`,`MANUALLY_DISABLED`),t=e.getAttribute(`disabled-reasons`),t!==null)for(var ne of t.split(`,`))i.setDisabledReason(!0,decodeURIComponent(ne));if((ne=e.getAttribute(`deletable`))&&i.setDeletable(ne===`true`),(ne=e.getAttribute(`movable`))&&i.setMovable(ne===`true`),(ne=e.getAttribute(`editable`))&&i.setEditable(ne===`true`),(ne=e.getAttribute(`collapsed`))&&i.setCollapsed(ne===`true`),e.nodeName.toLowerCase()===`shadow`){for(e=i.getChildren(!1),ne=0;ne<e.length;ne++)if(!e[ne].isShadow())throw TypeError(`Shadow block not allowed non-shadow child.`);i.setShadow(!0)}return i},ci=function(e,t){y(M.FIELD,e,t,!0)},e.lh=function(e){return gd.fromJsonInternal(e)},li=function(e){return e&&typeof e==`object`&&`src`in e&&typeof e.src==`string`&&`alt`in e&&typeof e.alt==`string`&&`width`in e&&typeof e.width==`number`&&`height`in e&&typeof e.height==`number`},e.oh=function(e,t){if(typeof e!=`string`||e.trim()===``)throw Error(`Error: Invalid extension name "`+e+`"`);if(kd[e])throw Error(`Error: Extension "`+e+`" is already registered.`);if(typeof t!=`function`)throw Error(`Error: Extension "`+e+`" must be a function`);kd[e]=t},e.ph=function(t,n){if(!n||typeof n!=`object`)throw Error(`Error: Mixin "`+t+`" must be a object`);e.oh(t,function(){this.mixin(n)})},e.th=function(t,n,r,i){var a=`Error when registering mutator "`+t+`": `;pi(a,n);var o=fi(n.compose,n.decompose,a+` compose/decompose`);if(r&&typeof r!=`function`)throw Error(a+`Extension "`+t+`" is not a function`);e.oh(t,function(){o&&this.setMutator(new e.sh(i||[],this)),this.mixin(n),r&&r.apply(this)})},ui=function(e){return!!kd[e]},di=function(e,t,n){var r=kd[e];if(typeof r!=`function`)throw Error(`Error: Extension "`+e+`" not found.`);if(n){if(mi(t).length)throw Error(`Error: tried to apply mutation "`+e+`" to a block that already has mutator functions. Block id: `+t.id)}else var i=mi(t);if(r.apply(t),n)pi(`Error after applying mutator "`+e+`": `,t);else{a:if(n=i,t=mi(t),t.length!==n.length)t=!1;else{for(r=0;r<t.length;r++)if(n[r]!==t[r]){t=!1;break a}t=!0}if(!t)throw Error(`Error when applying extension "`+e+`": mutation properties changed when applying a non-mutator extension.`)}},fi=function(e,t,n){if(e&&t){if(typeof e!=`function`||typeof t!=`function`)throw Error(n+` must be a function`);return!0}if(!e&&!t)return!1;throw Error(n+`Must have both or neither functions`)},pi=function(e,t){var n=fi(t.mutationToDom,t.domToMutation,e+` mutationToDom/domToMutation`),r=fi(t.saveExtraState,t.loadExtraState,e+` saveExtraState/loadExtraState`);if(!n&&!r)throw Error(e+`Mutations must contain either XML hooks, or JSON hooks, or both`);fi(t.compose,t.decompose,e+` compose/decompose`)},mi=function(e){var t=[];return e.domToMutation!==void 0&&t.push(e.domToMutation),e.mutationToDom!==void 0&&t.push(e.mutationToDom),e.saveExtraState!==void 0&&t.push(e.saveExtraState),e.loadExtraState!==void 0&&t.push(e.loadExtraState),e.compose!==void 0&&t.push(e.compose),e.decompose!==void 0&&t.push(e.decompose),t},e.yh=function(e,t){var n=[];return function(){n.includes(this.type)||(hi(this,e,t),n.push(this.type)),this.setTooltip(function(){var n=String(this.getFieldValue(e));return kr(t[n])}.bind(this))}},hi=function(e,t,n){var r=e.getField(t);if(r instanceof vd&&!r.isOptionListDynamic()){r=r.getOptions();for(let i of r)i!==vd.SEPARATOR&&([,r]=i,n[r]===void 0&&console.warn(`No tooltip mapping for value ${r} of field ${t} of block type ${e.type}.`))}},e.Ah=function(e,t){return function(){this.setTooltip(function(){var n=this.getField(t);return kr(e).replace(`%1`,n?n.getText():``)}.bind(this))}},S=function(e,t){return` `+e+`,`+t+` `},gi=function(e,t){return` `+e+t.join(``)},_i=function(e,t){return` M `+e+`,`+t+` `},vi=function(e,t){return` m `+e+`,`+t+` `},yi=function(e,t){return` l `+e+`,`+t+` `},bi=function(e){return` l`+e.join(``)},C=function(e,t){return` `+e+` `+t+` `},xi=function(e,t,n,r){return e+` `+n+` `+n+` `+t+r},Si=function(e,t){var n=null;t=t.outputConnection;var r=t==null?void 0:t.getConnectionChecker();for(let i=0,a;a=e.inputList[i];i++){let e=a.connection;if(e&&r!=null&&r.canConnect(t,e,!1)){if(n)return null;n=e}}return n},Ci=function(e){return _e(e)&&typeof e.getType==`function`&&typeof e.initView==`function`&&typeof e.dispose==`function`&&typeof e.getWeight==`function`&&typeof e.getSize==`function`&&typeof e.applyColour==`function`&&typeof e.hideForInsertionMarker==`function`&&typeof e.updateEditable==`function`&&typeof e.updateCollapsed==`function`&&typeof e.isShownWhenCollapsed==`function`&&typeof e.setOffsetInBlock==`function`&&typeof e.onLocationChange==`function`&&typeof e.onClick==`function`},wi=function(e){if(!(e.getDescendants(!1).length>100)){var t=e.workspace,n=e.getSvgRoot();t.getAudioManager().play(`delete`);var r=e.getRelativeToSurfaceXY(),i=n.cloneNode(!0);i.setAttribute(`transform`,`translate(`+r.x+`,`+r.y+`)`);var a;(a=t.getLayerManager())==null||a.appendToAnimationLayer({getSvgRoot:()=>i}),Ti(i,{x:r.x,y:r.y,width:e.width,height:e.height},t.RTL,new Date)}},Ti=function(e,t,n,r){var i=(new Date().getTime()-r.getTime())/150;i>1?v(e):(e.setAttribute(`transform`,`translate(`+(t.x+(n?-1:1)*t.width/2*i)+`,`+(t.y+t.height/2*i)+`) scale(`+(1-i)+`)`),setTimeout(Ti,10,e,t,n,r))},Ei=function(e){var t=e.workspace,n=t.scale;if(t.getAudioManager().play(`click`),!(n<1)){var r=t.getSvgXY(e.getSvgRoot());e.outputConnection?(r.x+=(e.RTL?3:-3)*n,r.y+=13*n):e.previousConnection&&(r.x+=(e.RTL?-23:23)*n,r.y+=3*n);var i=h(A.CIRCLE,{cx:r.x,cy:r.y,r:0,fill:`none`,stroke:`#888`,"stroke-width":10},t.getParentSvg());e=h(A.ANIMATE,{id:`animationCircle`,begin:`indefinite`,attributeName:`r`,dur:`150ms`,from:0,to:25*n},i),t=h(A.ANIMATE,{id:`animationOpacity`,begin:`indefinite`,attributeName:`opacity`,dur:`150ms`,from:1,to:0},i),e.beginElement(),t.beginElement(),setTimeout(()=>void v(i),150)}},Di=function(e){if(ki(),e.workspace.getAudioManager().play(`disconnect`),!(e.workspace.scale<1)){var t=e.getHeightWidth().height;t=Math.atan(10/t)/Math.PI*180,e.RTL||(t*=-1),Yd=e,Oi(e,t,new Date,0)}},Oi=function(e,t,n,r){var i=[.66,1,.66,0,-.66,-1,-.66,0],a=``;n.getTime()+200>new Date().getTime()&&(a=`skewX(${Math.round(i[r%i.length]*t)})`,Jd=setTimeout(Oi,15,e,t,n,r+1)),e.getSvgRoot().setAttribute(`transform`,`${e.getTranslation()} ${a}`)},ki=function(){Yd&&=(Jd&&=(clearTimeout(Jd),null),Yd.getSvgRoot().setAttribute(`transform`,Yd.getTranslation()),null)},Ai=function(t,n){t.workspace.RTL&&(n.x=t.workspace.getWidth()-n.x);for(var r=t.workspace,i=e.Og.snapRadius,a=N.difference(n,t.getRelativeToSurfaceXY()),o=new N(0,0),s=r.getAllBlocks(!1).filter(e=>e.id!=t.id).map(e=>e.getRelativeToSurfaceXY());ji(N.sum(n,o),s)||Mi(t,N.sum(a,o),i);)r.RTL?o.translate(-i,i*2):o.translate(i,i*2);t.moveTo(N.sum(n,o))},ji=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},Mi=function(e,t,n){return e.getConnections_(!1).some(e=>!!e.closest(n,t).connection)},Ni=function(e,t,n){var r=n.getBoundingRectangle(),i=r.right-r.left,a=zn(t.top,r.top,t.top+t.height-(r.bottom-r.top))-r.top,o=t.left;return t=t.left+t.width-i,e.RTL?o=Math.min(t,o):t=Math.max(o,t),(e=zn(o,r.left,t)-r.left)||a?(n.moveBy(e,a,[`inbounds`]),!0):!1},Pi=function(t){return n=>{var r=t.getMetricsManager();if(r.hasFixedEdges()&&!t.isDragging()){var i;if(Qo.includes((i=n.type)??``)){switch(r=r.getScrollMetrics(!0),i=null,n.type){case E.BLOCK_CREATE:case E.BLOCK_MOVE:(i=t.getBlockById(n.blockId))&&(i=i.getRootBlock());break;case E.COMMENT_CREATE:case E.COMMENT_MOVE:case E.COMMENT_RESIZE:i=t.getCommentById(n.commentId)}if(i){var a=e.gd||!1;e.B(n.group),Ni(t,r,i)&&!n.group&&console.warn(`Moved object in bounds but there was no event group. This may break undo.`),e.B(a)}}else n.type===E.VIEWPORT_CHANGE&&n.scale&&n.oldScale&&n.scale>n.oldScale&&Fi(t)}}},Fi=function(e){var t=e.getMetricsManager();if(t.hasFixedEdges()&&!e.isDragging()){t=t.getScrollMetrics(!0);var n=e.getTopBoundedElements();for(let r=0,i;i=n[r];r++)Ni(e,t,i)}},Ii=function(e,t){var n=e.toCopyData();return $d=n,ef=ve(e)&&e.workspace instanceof Mp?e.workspace:null,tf=t,n},Li=function(e,t,n){return e&&t?Ri(e,t,n):$d&&ef?Ri($d,ef,tf):null},Ri=function(e,t,n){t=t.isMutator?t:t.options.parentWorkspace??t;var r;return((r=Le(M.PASTER,e.paster,!1))==null?void 0:r.paste(e,t,n))??null},zi=function(e){return e&&typeof e.toCopyData==`function`},Bi=function(e){return e&&typeof e.isDeletable==`function`&&typeof e.dispose==`function`&&typeof e.setDeleteStyle==`function`},Vi=function(e){return e&&typeof e.getRelativeToSurfaceXY==`function`&&typeof e.isMovable==`function`&&typeof e.startDrag==`function`&&typeof e.drag==`function`&&typeof e.endDrag==`function`&&typeof e.revertDrag==`function`},Hi=function(){j.registry.register({name:J.ESCAPE,preconditionFn(e){return!e.isReadOnly()},callback(e){return e.hideChaff(),!0},keyCodes:[U.ESC],displayText:()=>e.C.SHORTCUTS_ESCAPE})},Ui=function(){j.registry.register({name:J.DELETE,preconditionFn(t,n){return n=n.focusedNode,(n=!t.isReadOnly()&&n!=null&&Bi(n)&&n.isDeletable()&&!t.isDragging()&&!e.t().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),n=i.focusedNode,n instanceof gf?n.checkAndDelete():Bi(n)&&n.isDeletable()&&(e.B(!0),n.dispose(),e.B(!1),t.getAudioManager().play(`delete`)),!0},keyCodes:[U.DELETE,U.BACKSPACE],displayText:()=>e.C.SHORTCUTS_DELETE})},Wi=function(e){return zi(e)&&Bi(e)&&Vi(e)?e.isCopyable?e.isCopyable():e instanceof gf||e instanceof md?e.isOwnDeletable()&&e.isOwnMovable():e.isDeletable()&&e.isMovable():!1},Gi=function(){var t=j.registry.createSerializedKey(U.C,[U.CTRL_CMD]);j.registry.register({name:J.COPY,preconditionFn(t,n){n=n.focusedNode;var r=t.isFlyout?t.targetWorkspace:t;return(n=!!n&&!!r&&!r.isDragging()&&!e.t().ephemeralFocusTaken()&&Wi(n))||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),r=i.focusedNode,!r||!zi(r)||!Wi(r)||(i=t.isFlyout?t.targetWorkspace:t,!i)?!1:(r.workspace.isFlyout||i.hideChaff(),i=Vi(r)&&r.workspace==i?r.getRelativeToSurfaceXY():void 0,(r=!!Ii(r,i))&&n instanceof KeyboardEvent&&Pc.show(t,{message:e.C.KEYBOARD_NAV_COPIED_HINT.replace(`%1`,vn(J.PASTE)),duration:7,id:`copiedHint`}),r)},keyCodes:[t],displayText:()=>e.C.COPY_SHORTCUT})},Ki=function(){var t=j.registry.createSerializedKey(U.X,[U.CTRL_CMD]);j.registry.register({name:J.CUT,preconditionFn(t,n){return n=n.focusedNode,(n=!!n&&!t.isReadOnly()&&!t.isDragging()&&!e.t().ephemeralFocusTaken()&&Wi(n)&&Bi(n)&&n.isDeletable())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return r=i.focusedNode,r&&Wi(r)&&Bi(r)&&r.isDeletable()&&zi(r)?(i=Vi(r)?r.getRelativeToSurfaceXY():void 0,i=Ii(r,i),r instanceof gf?(r.checkAndDelete(),n.preventDefault()):Bi(r)&&(e.B(!0),r.dispose(),e.B(!1),t.getAudioManager().play(`delete`),n.preventDefault()),i&&n instanceof KeyboardEvent&&Pc.show(t,{message:e.C.KEYBOARD_NAV_CUT_HINT.replace(`%1`,vn(J.PASTE)),duration:7,id:`cutHint`}),!!i):!1},keyCodes:[t],displayText:()=>e.C.CUT_SHORTCUT})},qi=function(){var t=j.registry.createSerializedKey(U.V,[U.CTRL_CMD]);j.registry.register({name:J.PASTE,preconditionFn(){var t=ef;if(!t||!t.rendered)return!1;var n=t.isFlyout?t.targetWorkspace:t;return(n=!!$d&&!!n&&!n.isReadOnly()&&!n.isDragging()&&!e.t().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(t,n){var r=$d,i=e.t().getFocusedNode();if(!r)return!1;var a=ef;if(!a||(Pc.hide(t,`cutHint`),Pc.hide(t,`copiedHint`),t=a.isFlyout?a.targetWorkspace:a,!t||t.isReadOnly()))return!1;if(n instanceof PointerEvent){var o=ct(t,new N(n.clientX,n.clientY));return!!Li(r,t,o)}if(n=(o=t.getNavigator().getSourceBlockFromNode(i))==null?void 0:o.getRelativeToSurfaceXY())return!!Li(r,t,n);if(o=tf,!o)return!!Li(r,t);var{left:s,top:c,width:l,height:u}=t.getMetricsManager().getViewMetrics(!0);return new P(c,c+u,s,s+l).contains(o.x,o.y)?!!Li(r,t):(o=new N(s+l/2,c+u/2),!!Li(r,t,o))},keyCodes:[t],displayText:()=>e.C.PASTE_SHORTCUT})},Ji=function(){var t=j.registry.createSerializedKey(U.Z,[U.CTRL_CMD]);j.registry.register({name:J.UNDO,preconditionFn(t){return!t.isReadOnly()&&!t.isDragging()&&!e.t().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.undo(),t.preventDefault(),!0},keyCodes:[t],displayText:()=>e.C.UNDO})},Yi=function(){var t=j.registry.createSerializedKey(U.Z,[U.CTRL_CMD,U.SHIFT]),n=j.registry.createSerializedKey(U.Y,[U.CTRL]);j.registry.register({name:J.REDO,preconditionFn(t){return!t.isDragging()&&!t.isReadOnly()&&!e.t().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.redo(),t.preventDefault(),!0},keyCodes:[t,n],displayText:()=>e.C.REDO})},Xi=function(){var t=t=>{var n=e.t().getFocusedNode();return Vi(n)?n:t.getNavigator().getSourceBlockFromNode(e.t().getFocusedNode())??void 0},n=j.registry.createSerializedKey(U.M,[U.SHIFT]),r={name:J.START_MOVE,preconditionFn:e=>(e=t(e),!!e&&G.mover.canMove(e)),callback:(n,r)=>(z.setIsActive(!0),(n=t(n))&&e.t().focusNode(n),!!n&&G.mover.startMove(n,r)),keyCodes:[U.M],displayText:()=>e.C.SHORTCUTS_START_MOVE};n=[r,Object.assign({},r,{name:J.START_MOVE_STACK,keyCodes:[n],displayText:()=>e.C.SHORTCUTS_START_MOVE_STACK}),{name:J.FINISH_MOVE,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>G.mover.finishMove(t),keyCodes:[U.ENTER,U.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_FINISH_MOVE},{name:J.ABORT_MOVE,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>G.mover.abortMove(t),keyCodes:[U.ESC],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_ABORT_MOVE},{name:J.MOVE_LEFT,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.LEFT,t)),keyCodes:[U.LEFT,j.registry.createSerializedKey(U.LEFT,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_LEFT},{name:J.MOVE_RIGHT,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.RIGHT,t)),keyCodes:[U.RIGHT,j.registry.createSerializedKey(U.RIGHT,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_RIGHT},{name:J.MOVE_UP,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.UP,t)),keyCodes:[U.UP,j.registry.createSerializedKey(U.UP,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_UP},{name:J.MOVE_DOWN,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.DOWN,t)),keyCodes:[U.DOWN,j.registry.createSerializedKey(U.DOWN,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_DOWN}];for(let e of n)j.registry.register(e)},Zi=function(){var t=j.registry.createSerializedKey(U.ENTER,[U.CTRL_CMD]),n=j.registry.createSerializedKey(U.F10,[U.SHIFT]);j.registry.register({name:J.MENU,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{if(z.setIsActive(!0),(t=e.t().getFocusedNode())&&typeof t.showContextMenu==`function`){t.showContextMenu(n);let e;return(e=td)==null||e.highlightNext(),!0}return!1},keyCodes:[t,n,U.CONTEXT_MENU],displayText:()=>e.C.SHORTCUTS_SHOW_CONTEXT_MENU})},Qi=function(){var t={right:{name:J.NAVIGATE_RIGHT,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r,i;return n=t.RTL?(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getOutNode():(i=e.t().getFocusedTree())==null?void 0:i.getNavigator().getInNode(),n?(e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.RIGHT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_RIGHT},left:{name:J.NAVIGATE_LEFT,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r,i;return n=t.RTL?(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getInNode():(i=e.t().getFocusedTree())==null?void 0:i.getNavigator().getOutNode(),n?(e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.LEFT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_LEFT},down:{name:J.NAVIGATE_DOWN,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r;return n=(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getNextNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.DOWN],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_DOWN},up:{name:J.NAVIGATE_UP,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r;return n=(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getPreviousNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.UP],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_UP}};for(let e of Object.values(t))j.registry.register(e)},$i=function(){j.registry.register({name:J.FOCUS_WORKSPACE,preconditionFn:e=>!e.isDragging(),callback:t=>(z.setIsActive(!0),t=cf(t),e.t().focusNode(t.getWorkspaceFocusTarget()??t),!0),keyCodes:[U.W],displayText:()=>e.C.SHORTCUTS_FOCUS_WORKSPACE})},ea=function(){j.registry.register({name:J.FOCUS_TOOLBOX,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{var r=t.getToolbox();if(r)z.setIsActive(!0),e.t().focusTree(r);else{if(t=t.getFlyout(),!t)return!1;z.setIsActive(!0),e.t().focusTree(t.getWorkspace())}return n.preventDefault(),!0},keyCodes:[U.T],displayText:()=>e.C.SHORTCUTS_FOCUS_TOOLBOX})},ta=function(){j.registry.register({name:J.INFORMATION,preconditionFn:()=>!0,callback:t=>{var n=e.t().getFocusedNode(),r=t.getNavigator().getSourceBlockFromNode(n);if(r)return t=Cn(r,ss.LOQUACIOUS),se(t),!0;if(n===t){n=cf(t),t=n.getTopBlocks().length,n=n.getTopComments().length,r=t===0?`WORKSPACE_CONTENTS_BLOCKS_ZERO`:t===1?`WORKSPACE_CONTENTS_BLOCKS_ONE`:`WORKSPACE_CONTENTS_BLOCKS_MANY`;let i=``;return n>0&&(i=e.C[n===1?`WORKSPACE_CONTENTS_COMMENTS_ONE`:`WORKSPACE_CONTENTS_COMMENTS_MANY`].replace(`%1`,String(n))),t=e.C[r].replace(`%1`,String(t)).replace(`%2`,i),se(t),!0}return!1},keyCodes:[U.I],displayText:()=>e.C.SHORTCUTS_INFORMATION})},na=function(){var t=j.registry.createSerializedKey(U.I,[U.SHIFT]);j.registry.register({name:J.EXTENDED_INFORMATION,preconditionFn:()=>!0,callback:t=>{if(t=t.getNavigator().getSourceBlockFromNode(e.t().getFocusedNode()),!t)return!1;for(var n=[],r=t,i;(i=r.outputConnection)!=null&&i.isConnected();)r=r.getParent();for(r!==t&&n.push(Cn(r,ss.TERSE)),i=r.getParent();i;)n.push(Cn(i,ss.TERSE)),i=i.getParent();if(n.length){n.reverse();let r;(r=t.outputConnection)!=null&&r.isConnected()||n.push(e.C.CURRENT_BLOCK_ANNOUNCEMENT.replace(`%1`,Cn(t,ss.TERSE))),se(e.C.PARENT_BLOCKS_ANNOUNCEMENT.replace(`%1`,n.join(`,`)))}else se(e.C.NO_PARENT_ANNOUNCEMENT);return!0},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_EXTENDED_INFORMATION})},ra=function(){var t=j.registry.createSerializedKey(U.X,[U.SHIFT]);j.registry.register({name:J.DISCONNECT,preconditionFn:(e,t)=>(t=t.focusedNode,(t=!e.isDragging()&&!e.isReadOnly()&&t instanceof gf&&!t.isShadow())||e.getAudioManager().playErrorBeep(),t),callback:(t,n)=>(z.setIsActive(!0),t=e.t().getFocusedNode(),t instanceof gf&&(n=!(n instanceof KeyboardEvent&&n.shiftKey),e.B(!0),t.unplug(n),e.B(!1),!0)),keyCodes:[U.X,t],displayText:()=>e.C.SHORTCUTS_DISCONNECT})},ia=function(){var t=(t,n=e.t().getFocusedNode())=>{var r=t.getNavigator();for(let e=n;e&&e!==t;e=r.getParent(e))n=e;return ve(n)?n:null},n={name:J.PREVIOUS_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!xu&&!Gu,callback:n=>{z.setIsActive(!0);var r=t(n);return!r||(n=t(n,n.getNavigator().navigateStacks(r,-1)),!n)?!1:(e.t().focusNode(n),!0)},keyCodes:[U.B],displayText:()=>e.C.SHORTCUTS_PREVIOUS_STACK};j.registry.register({name:J.NEXT_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!xu&&!Gu,callback:n=>{z.setIsActive(!0);var r=t(n);return!r||(n=n.getNavigator().navigateStacks(r,1),!n)?!1:(e.t().focusNode(n),!0)},keyCodes:[U.N],displayText:()=>e.C.SHORTCUTS_NEXT_STACK}),j.registry.register(n)},aa=function(){var t=()=>{var t=e.t().getFocusedTree();return t instanceof Mp&&t.isFlyout&&t.targetWorkspace?t.targetWorkspace.getFlyout()??null:null},n=t=>{var n=t.getWorkspace().getNavigator();t=t.getContents().map(e=>e.getElement());for(var r=e.t().getFocusedNode()??null;r&&!t.includes(r);)r=n.getParent(r);return r},r=(e,t)=>{var r=e.getContents().map(e=>e.getElement());e=(e=n(e))?r.indexOf(e):t===1?-1:r.length;for(let n=1;n<=r.length;n++){var i=e+t*n;if(i<0||i>=r.length)break;if(i=r[i],i instanceof af&&i.isLabel())return i}return null},i=j.registry.createSerializedKey(U.H,[U.SHIFT]);i={name:J.PREVIOUS_HEADING,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,-1),!n)?!1:(z.setIsActive(!0),e.t().focusNode(n),!0)},keyCodes:[i],displayText:()=>e.C.SHORTCUTS_PREVIOUS_HEADING},j.registry.register({name:J.NEXT_HEADING,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,1),!n)?!1:(z.setIsActive(!0),e.t().focusNode(n),!0)},keyCodes:[U.H],displayText:()=>e.C.SHORTCUTS_NEXT_HEADING}),j.registry.register(i)},oa=function(){j.registry.register({name:J.PERFORM_ACTION,preconditionFn:t=>!t.isDragging()&&!xu&&!Gu&&!e.t().ephemeralFocusTaken(),callback:(t,n)=>{if(z.setIsActive(!0),(t=e.t().getFocusedNode())&&`performAction`in t){n.preventDefault();let e;return(e=t.performAction)==null||e.call(t,n),!0}return!1},keyCodes:[U.ENTER,U.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_PERFORM_ACTION})},sa=function(){j.registry.register({name:J.DUPLICATE,preconditionFn:(e,t)=>({focusedNode:t}=t,(t=!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout&&(t instanceof gf?t.isDuplicatable():!0))||e.getAudioManager().playErrorBeep(),t),callback:(e,t,n,r)=>(z.setIsActive(!0),t=zi(r.focusedNode)&&r.focusedNode,(t&&=t.toCopyData())?!!Li(t,e):!1),keyCodes:[U.D],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_DUPLICATE})},ca=function(){j.registry.register({name:J.CLEANUP,preconditionFn:e=>!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout,callback:e=>(z.setIsActive(!0),e.cleanUp(),!0),keyCodes:[U.C],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_CLEANUP})},la=function(){var t=j.registry.createSerializedKey(U.J,[U.CTRL_CMD]);j.registry.register({name:J.SHOW_TOOLTIP,preconditionFn:e=>!e.isDragging(),callback:t=>{var n=e.t().getFocusedNode();return n!==null&&(z.setIsActive(!0),vr(n,t)),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_SHOW_TOOLTIP})},ua=function(){var t=j.registry.createSerializedKey(U.A,[U.ALT,U.SHIFT]),n=!1;j.registry.register({name:J.TOGGLE_SCREENREADER,preconditionFn:()=>!0,callback:(t,r)=>{n=!n,z.setScopeChangeAudioCuesEnabled(n),t.getNavigator().setNavigationLoops(!n);var i;(i=t.getToolbox())==null||i.getNavigator().setNavigationLoops(!n);var a;return(a=t.getFlyout())==null||a.getWorkspace().getNavigator().setNavigationLoops(!n),Pc.show(t,{message:(n?e.C.SCREENREADER_MODE_ENABLED:e.C.SCREENREADER_MODE_DISABLED).replace(`%1`,vn(J.TOGGLE_SCREENREADER)),duration:7,id:`screenreaderHint`}),r.preventDefault(),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_TOGGLE_SCREENREADER_MODE})},da=function(){j.registry.register({name:J.JUMP_BLOCK_START,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode)return!1;t=t.getNavigator().getSourceBlockFromNode(i.focusedNode);var a;return(a=t)!=null&&a.getFullBlockField()&&t.getParent()&&(t=t.getParent()),t?(e.t().focusNode(t),!0):!1},keyCodes:[U.HOME],displayText:()=>e.C.SHORTCUTS_JUMP_BLOCK_START})},fa=function(){j.registry.register({name:J.JUMP_BLOCK_END,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode)return!1;t=t.getNavigator().getSourceBlockFromNode(i.focusedNode);var a;return(a=t)!=null&&a.getFullBlockField()&&t.getParent()&&(t=t.getParent()),!t||(a=t.inputList,!a.length)||(a=a[a.length-1].connection,!(a&&a instanceof Bd))?!1:(e.t().focusNode(a),!0)},keyCodes:[U.END],displayText:()=>e.C.SHORTCUTS_JUMP_BLOCK_END})},pa=function(){j.registry.register({name:J.JUMP_TOP_STACK,preconditionFn:lf,callback(t,n,r,i){return!i.focusedNode||(t=t.getNavigator().getSourceBlockFromNode(i.focusedNode),!t)?!1:(t=t.getRootBlock(),e.t().focusNode(t),!0)},keyCodes:[U.PAGE_UP],displayText:()=>e.C.SHORTCUTS_JUMP_TOP_STACK})},ma=function(){j.registry.register({name:J.JUMP_BOTTOM_STACK,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode||(t=t.getNavigator().getSourceBlockFromNode(i.focusedNode),!t))return!1;var a;return t=(a=t.getRootBlock().lastConnectionInStack(!1))==null?void 0:a.getSourceBlock(),t?(a=t.getDescendants(!0),a=a[a.length-1],e.t().focusNode(a),!0):!1},keyCodes:[U.PAGE_DOWN],displayText:()=>e.C.SHORTCUTS_JUMP_BOTTOM_STACK})},ha=function(){var t=j.registry.createSerializedKey(U.HOME,[U.CTRL_CMD]);j.registry.register({name:J.JUMP_FIRST_BLOCK,preconditionFn:t=>!t.isDragging()&&!e.t().ephemeralFocusTaken(),callback(t){return t=t.getTopBlocks(!0),t.length?(e.t().focusNode(t[0]),!0):!1},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_JUMP_FIRST_BLOCK})},ga=function(){var t=j.registry.createSerializedKey(U.END,[U.CTRL_CMD]);j.registry.register({name:J.JUMP_LAST_BLOCK,preconditionFn:t=>!t.isDragging()&&!e.t().ephemeralFocusTaken(),callback(t){return t=t.getAllBlocks(!0),t.length?(e.t().focusNode(t[t.length-1]),!0):!1},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_JUMP_LAST_BLOCK})},_a=function(){Hi(),Ui(),Gi(),Ki(),qi(),Ji(),Yi()},va=function(){Zi(),Xi(),$i(),ea(),Qi(),ra(),ia(),aa(),oa(),sa(),ca(),la()},ya=function(){ta(),na(),ua()},ba=function(t,n=!1){var r=e.C.KEYBOARD_NAV_UNCONSTRAINED_MOVE_HINT.replace(`%1`,zo||Lo||Ro?e.C.COMMAND_KEY:e.C.CONTROL_KEY).replace(`%2`,e.C.ENTER_KEY);Pc.show(t,{message:r,id:`unconstrainedMoveHint`,oncePerSession:!n})},xa=function(t){var n=e.C.KEYBOARD_NAV_CONSTRAINED_MOVE_HINT.replace(`%1`,e.C.ENTER_KEY);Pc.show(t,{message:n,id:`constrainedMoveHint`,oncePerSession:!0})},Sa=function(e){var t=[];for(var n of e.getIcons()){if(e.isCollapsed()&&!n.isShownWhenCollapsed())continue;t.push(n);let r;Wt(n)&&n.bubbleIsVisible()&&(r=n.getBubble())&&t.push(r)}for(let r of e.inputList)r.isVisible()&&(t.push(...r.fieldRow),n=r.connection,n&&(t.push(n),n=n.targetBlock(),n&&(t.push(n),(n=n.lastConnectionInStack(!1))&&t.push(n))));return e.nextConnection&&!e.isCollapsed()&&t.push(e.nextConnection),t},Ca=function(e,t,n){return e=Sa(e),t=e.indexOf(t),t===-1?null:(n=t+n,n>=0&&n<e.length?e[n]:null)},wa=function(e){return e&&typeof e.getChildToolboxItems==`function`&&typeof e.isExpanded==`function`&&typeof e.toggleExpanded==`function`&&Sn(e)&&e.isCollapsible()},Ta=function(e){var t=e.options.toolboxPosition;return e.options.RTL&&t!==I.TOP&&t!==I.BOTTOM?t===I.LEFT?I.RIGHT:I.LEFT:t},Ea=function(e,t){y(M.ICON,e.toString(),t)},Da=function(e){return typeof e.getProcedureModel==`function`&&typeof e.doProcedureUpdate==`function`&&typeof e.isProcedureDef==`function`},Oa=function(e){return e&&typeof e.startPublishing==`function`&&typeof e.stopPublishing==`function`},ka=function(e){var t=e.getProcedureMap().getProcedures().filter(e=>!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!1]);e.getBlocksByType(`procedures_defnoreturn`,!1).forEach(e=>{!Da(e)&&Kt(e)&&t.push(e.getProcedureDef())});var n=e.getProcedureMap().getProcedures().filter(e=>!!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!0]);return e.getBlocksByType(`procedures_defreturn`,!1).forEach(e=>{!Da(e)&&Kt(e)&&n.push(e.getProcedureDef())}),t.sort(Aa),n.sort(Aa),[t,n]},Aa=function(e,t){return e[0].localeCompare(t[0],void 0,{sensitivity:`base`})},e.jj=function(t,n){if(n.isInFlyout)return t;for(t=t||e.C.UNNAMED_KEY||`unnamed`;ja(t,n.workspace,n);){let e=t.match(/^(.*?)(\d+)$/);t=e?e[1]+(parseInt(e[2])+1):t+`2`}return t},ja=function(t,n,r){for(let i of n.getAllBlocks(!1))if(i!==r&&Kt(i)&&e.kj.equals(i.getProcedureDef()[0],t))return!0;r=r&&Da(r)?r==null?void 0:r.getProcedureModel():void 0;for(let i of n.getProcedureMap().getProcedures())if(i!==r&&e.kj.equals(i.getName(),t))return!0;return!1},e.mj=function(t){var n=this.getSourceBlock();if(!n)throw new Wu;t=t.trim();var r=e.jj(t,n);Da(n)&&!n.isInsertionMarker()&&n.getProcedureModel().setName(r);var i=this.getValue();if(i!==t&&i!==r)for(t=n.workspace.getAllBlocks(!1),n=0;n<t.length;n++){let e=t[n];e.renameProcedure&&e.renameProcedure(i,r)}return r},Ma=function(t){function n(e,t){for(let[n,i]of e)r.push({kind:`block`,type:t,gap:16,extraState:{name:n,params:i}})}var r=[];return $o.procedures_defnoreturn&&r.push({kind:`block`,type:`procedures_defnoreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFNORETURN_PROCEDURE}}),$o.procedures_defreturn&&r.push({kind:`block`,type:`procedures_defreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFRETURN_PROCEDURE}}),$o.procedures_ifreturn&&r.push({kind:`block`,type:`procedures_ifreturn`,gap:16}),r.length&&(r[r.length-1].gap=24),t=ka(t),n(t[0],`procedures_callnoreturn`),n(t[1],`procedures_callreturn`),r},Na=function(t){var n=[],r=t.getBlocksByType(`procedures_mutatorarg`,!1);for(let e=0,t;t=r[e];e++)n.push(t.getFieldValue(`NAME`));r=e.rc(`xml`);var i=e.rc(`block`);i.setAttribute(`type`,`procedures_mutatorarg`);var a=e.rc(`field`);a.setAttribute(`name`,`NAME`),n=Qt(`x`,n),n=e.sc(n),a.appendChild(n),i.appendChild(a),r.appendChild(i),t.updateToolbox(r)},Pa=function(t){if(t.type===E.BUBBLE_OPEN&&t.bubbleType===`mutator`&&t.isOpen&&t.blockId){t=xe(t.workspaceId).getBlockById(t.blockId);var n=t.type;(n===`procedures_defnoreturn`||n===`procedures_defreturn`)&&(t=t.getIcon(e.sh.TYPE).getWorkspace(),Na(t),t.addChangeListener(Fa))}},Fa=function(e){(e.type===E.BLOCK_CREATE||e.type===E.BLOCK_DELETE||e.type===E.BLOCK_CHANGE||e.type===E.BLOCK_FIELD_INTERMEDIATE_CHANGE)&&(e=xe(e.workspaceId),Na(e))},Ia=function(t,n){return n.getAllBlocks(!1).filter(n=>Da(n)&&!n.isProcedureDef()&&n.getProcedureModel()&&e.kj.equals(n.getProcedureModel().getName(),t)||n&&typeof n.getProcedureCall==`function`&&typeof n.renameProcedure==`function`&&e.kj.equals(n.getProcedureCall(),t))},e.sj=function(t){var n=e.Qc,r=t.getProcedureDef()[0],i=t.mutationToDom(!0);t=Ia(r,t.workspace);for(let o=0,s;s=t[o];o++){r=(r=s.mutationToDom())&&ut(r),s.domToMutation&&s.domToMutation(i);var a=s.mutationToDom();a&&=ut(a),r!==a&&(e.Qc=!1,b(new(x(E.BLOCK_CHANGE))(s,`mutation`,null,r,a)),e.Qc=n)}},e.tj=function(t,n){for(let r of n.getAllBlocks(!1))if(Da(r)&&r.isProcedureDef()&&e.kj.equals(r.getProcedureModel().getName(),t)||Kt(r)&&e.kj.equals(r.getProcedureDef()[0],t))return r;return null},La=function(e,t){y(M.RENDERER,e,t)},Ra=function(e,t,n){return e=new(Le(M.RENDERER,e,void 0))(e),e.init(t,n),e},za=function(e){$t(e.getTargetWorkspace(),void 0,`String`)},Ba=function(e){$t(e.getTargetWorkspace(),void 0,`Number`)},Va=function(e){$t(e.getTargetWorkspace(),void 0,`Colour`)},Ha=function(t){return $o.variables_set_dynamic||$o.variables_get_dynamic||console.warn(`There are no dynamic variable blocks, but there is a dynamic variable category.`),t.registerButtonCallback(`CREATE_VARIABLE_STRING`,za),t.registerButtonCallback(`CREATE_VARIABLE_NUMBER`,Ba),t.registerButtonCallback(`CREATE_VARIABLE_COLOUR`,Va),[{kind:`button`,text:e.C.NEW_STRING_VARIABLE,callbackkey:`CREATE_VARIABLE_STRING`},{kind:`button`,text:e.C.NEW_NUMBER_VARIABLE,callbackkey:`CREATE_VARIABLE_NUMBER`},{kind:`button`,text:e.C.NEW_COLOUR_VARIABLE,callbackkey:`CREATE_VARIABLE_COLOUR`},...Xt(t,t.getVariableMap().getAllVariables(),!1,`variables_get_dynamic`,`variables_set_dynamic`)]},Ua=function(e){var t=e.saveState();return e.getParameters().length&&(t.parameters=e.getParameters().map(e=>e.saveState())),t},Wa=function(e,t,n,r){if(e=e.loadState(n,r),!n.parameters)return e;for(let[i,a]of n.parameters.entries())e.insertParameter(t.loadState(a,r),i);return e},Ga=function(e,t){e.setAttribute(`dir`,`LTR`),ne(e,t.hasCss,t.pathToMedia);var n=h(A.SVG,{xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`,class:`blocklySvg`},e),r=h(A.DEFS,{},n),i=String(Math.random()).substring(2);return t.gridPattern=Gf.createDom(i,t.gridOptions,r,e),n},Ka=function(e,t,n){n.parentWorkspace=null,n=new Mp(n);var r=n.options;n.scale=r.zoomOptions.startScale,t.appendChild(n.createDom(`blocklyMainBackground`,e));var i=n.getRenderer().getClassName();return i&&g(e,i),(i=n.getTheme().getClassName())&&g(e,i),!r.hasCategories&&r.languageTree&&(i=n.addFlyout(A.SVG),e.insertBefore(i,t)),r.hasTrashcan&&n.addTrashcan(),r.zoomOptions&&r.zoomOptions.controls&&n.addZoomControls(),n.getThemeManager().subscribe(t,`workspaceBackgroundColour`,`background-color`),n.translate(0,0),n.addChangeListener(Pi(n)),je(n),Mr(),Bn(),ur(),n},qa=function(e){var t=e.options,n=e.getParentSvg();if(o(n.parentNode,`contextmenu`,null,function(e){l(e)||e.preventDefault()}),n=o(window,`resize`,null,function(){_r(),e.hideComponents(!0),nr(),zr(),je(e),Fi(e)}),e.setResizeHandlerWrapper(n),Ja(),t.languageTree){n=e.getToolbox();let r=e.getFlyout(!0);n?n.init():r&&(r.init(e),r.show(t.languageTree),typeof r.scrollToStart==`function`&&r.scrollToStart())}t.hasTrashcan&&e.trashcan.init(),t.zoomOptions&&t.zoomOptions.controls&&e.zoomControls_.init(),t.moveOptions&&t.moveOptions.scrollbars?(e.scrollbar=new Bf(e,t.moveOptions.scrollbars===!0||!!t.moveOptions.scrollbars.horizontal,t.moveOptions.scrollbars===!0||!!t.moveOptions.scrollbars.vertical,`blocklyMainWorkspaceScrollbar`),e.scrollbar.resize()):e.setMetrics({x:.5,y:.5}),t.hasSounds&&Ya(t.pathToMedia,e)},Ja=function(){pm||(o(document,`scroll`,null,function(){var e=Se();for(let t=0,n;n=e[t];t++)n instanceof Mp&&n.updateInverseScreenCTM()}),s(document,`touchend`,null,n),s(document,`touchcancel`,null,n),s(document,`keydown`,null,function(e){e.key===`Tab`&&z.setIsActive(!0)})),pm=!0},Ya=function(e,t){t=t.getAudioManager(),t.load([`${e}click.mp3`],`click`),t.load([`${e}disconnect.mp3`],`disconnect`),t.load([`${e}delete.mp3`],`delete`),t.load([`${e}drop.mp3`],`drop`)},Xa=function(){H.registry.register({displayText(){return e.C.UNDO},preconditionFn(e){return e.workspace.getUndoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.undo()},scopeType:H.ScopeType.WORKSPACE,id:`undoWorkspace`,weight:1,associatedKeyboardShortcut:`undo`})},Za=function(){H.registry.register({displayText(){return e.C.REDO},preconditionFn(e){return e.workspace.getRedoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.redo()},scopeType:H.ScopeType.WORKSPACE,id:`redoWorkspace`,weight:2,associatedKeyboardShortcut:`redo`})},Qa=function(){H.registry.register({displayText(){return e.C.CLEAN_UP},preconditionFn(e){return e.workspace.isMovable()?e.workspace.getTopBlocks(!1).length>1?`enabled`:`disabled`:`hidden`},callback(e){e.workspace.cleanUp()},scopeType:H.ScopeType.WORKSPACE,id:`cleanWorkspace`,weight:3,associatedKeyboardShortcut:`cleanup`})},$a=function(t,n){function r(n){a--,n.setCollapsed(t),a===0&&e.B(!1)}var i=0,a=0;e.B(!0);for(let e=0;e<n.length;e++){let t=n[e];for(;t;)a++,setTimeout(r.bind(null,t),i),t=t.getNextBlock(),i+=10}},eo=function(){H.registry.register({displayText(){return e.C.COLLAPSE_ALL},preconditionFn(e){if(e.workspace.options.collapse){e=e.workspace.getTopBlocks(!1);for(let t=0;t<e.length;t++){let n=e[t];for(;n;){if(!n.isCollapsed())return`enabled`;n=n.getNextBlock()}}return`disabled`}return`hidden`},callback(e){$a(!0,e.workspace.getTopBlocks(!0))},scopeType:H.ScopeType.WORKSPACE,id:`collapseWorkspace`,weight:4})},to=function(){H.registry.register({displayText(){return e.C.EXPAND_ALL},preconditionFn(e){if(e.workspace.options.collapse){e=e.workspace.getTopBlocks(!1);for(let t=0;t<e.length;t++){let n=e[t];for(;n;){if(n.isCollapsed())return`enabled`;n=n.getNextBlock()}}return`disabled`}return`hidden`},callback(e){$a(!1,e.workspace.getTopBlocks(!0))},scopeType:H.ScopeType.WORKSPACE,id:`expandWorkspace`,weight:5})},no=function(e,t){if(e.isDeletable())Array.prototype.push.apply(t,e.getDescendants(!1));else{e=e.getChildren(!1);for(let n=0;n<e.length;n++)no(e[n],t)}},ro=function(e){var t=[];e=e.getTopBlocks(!0);for(let n=0;n<e.length;n++)no(e[n],t);return t},io=function(t,n){n?e.B(n):(e.B(!0),n=e.gd);var r=t.shift();r&&(r.isDeadOrDying()?io(t,n):(r.dispose(!1,!0),setTimeout(io,10,t,n))),e.B(!1)},ao=function(){H.registry.register({displayText(t){return t.workspace?(t=ro(t.workspace).length,t===1?e.C.DELETE_BLOCK:e.C.DELETE_X_BLOCKS.replace(`%1`,`${t}`)):``},preconditionFn(e){return e.workspace&&ro(e.workspace).length>0?`enabled`:`disabled`},callback(t){if(t.workspace){t.workspace.cancelCurrentGesture();var n=ro(t.workspace);n.length<2?io(n):Vt(e.C.DELETE_ALL_BLOCKS.replace(`%1`,String(n.length)),function(e){e&&io(n)})}},scopeType:H.ScopeType.WORKSPACE,id:`workspaceDelete`,weight:6})},oo=function(){H.registry.register({displayText(){return e.C.DUPLICATE_BLOCK},preconditionFn(e){return e=e.block,!e.isInFlyout&&e.isDeletable()&&e.isMovable()?e.isDuplicatable()?`enabled`:`disabled`:`hidden`},callback(e){if(e.block){var t=e.block.toCopyData();t&&Li(t,e.block.workspace)}},scopeType:H.ScopeType.BLOCK,id:`blockDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},so=function(){H.registry.register({displayText(t){return t.block.hasIcon(Jf.TYPE)?e.C.REMOVE_COMMENT:e.C.ADD_COMMENT},preconditionFn(e){e=e.block;var t;if((t=e&&!e.isInFlyout&&e.workspace.options.comments&&!e.isCollapsed()&&e.isEditable())&&!(t=e.hasIcon(Jf.TYPE))){if(e&&e.isSimpleReporter()){var n;e=(n=e.getFields().next().value)==null?void 0:n.isFullBlockField()}else e=!1;t=!e}return t?`enabled`:`hidden`},callback(e){(e=e.block)&&e.hasIcon(Jf.TYPE)?e.setCommentText(null):e.setCommentText(``)},scopeType:H.ScopeType.BLOCK,id:`blockComment`,weight:2})},co=function(){H.registry.register({displayText(t){return t.block.getInputsInline()?e.C.EXTERNAL_INPUTS:e.C.INLINE_INPUTS},preconditionFn(e){if(e=e.block,!e.isInFlyout&&e.isMovable()&&!e.isCollapsed()){for(let t=1;t<e.inputList.length;t++)if(!(e.inputList[t-1]instanceof am||e.inputList[t]instanceof am))return`enabled`}return`hidden`},callback(e){e.block.setInputsInline(!e.block.getInputsInline())},scopeType:H.ScopeType.BLOCK,id:`blockInline`,weight:3})},lo=function(){H.registry.register({displayText(t){return t.block.isCollapsed()?e.C.EXPAND_BLOCK:e.C.COLLAPSE_BLOCK},preconditionFn(e){return e=e.block,!e.isInFlyout&&e.isMovable()&&e.workspace.options.collapse?`enabled`:`hidden`},callback(e){e.block.setCollapsed(!e.block.isCollapsed())},scopeType:H.ScopeType.BLOCK,id:`blockCollapseExpand`,weight:4})},uo=function(){H.registry.register({displayText(t){return t.block.hasDisabledReason(`MANUALLY_DISABLED`)?e.C.ENABLE_BLOCK:e.C.DISABLE_BLOCK},preconditionFn(e){if(e=e.block,!e.isInFlyout&&e.workspace.options.disable&&e.isEditable()){var t=e.getDisabledReasons();return t=t.size>+!!t.has(`MANUALLY_DISABLED`),e.getInheritedDisabled()||t?`disabled`:`enabled`}return`hidden`},callback(t){t=t.block;var n=e.gd;n||e.B(!0),t.setDisabledReason(!t.hasDisabledReason(`MANUALLY_DISABLED`),`MANUALLY_DISABLED`),e.B(n)},scopeType:H.ScopeType.BLOCK,id:`blockDisable`,weight:5})},fo=function(){H.registry.register({displayText(t){var n=t.block;return t=n.getDescendants(!1).length,(n=n.getNextBlock())&&(t-=n.getDescendants(!1).length),t===1?e.C.DELETE_BLOCK:e.C.DELETE_X_BLOCKS.replace(`%1`,`${t}`)},preconditionFn(e){return!e.block.isInFlyout&&e.block.isDeletable()?`enabled`:`hidden`},callback(t){t.block&&(e.t().focusNode(t.block),t.block.checkAndDelete())},scopeType:H.ScopeType.BLOCK,id:`blockDelete`,weight:6,associatedKeyboardShortcut:`delete`})},po=function(){H.registry.register({displayText(){return e.C.HELP},preconditionFn(e){return e=e.block,(typeof e.helpUrl==`function`?e.helpUrl():e.helpUrl)?`enabled`:`hidden`},callback(e){e.block.showHelp()},scopeType:H.ScopeType.BLOCK,id:`blockHelp`,weight:7})},mo=function(){H.registry.register({displayText:()=>e.C.REMOVE_COMMENT,preconditionFn(e){var t;return(t=e.comment)!=null&&t.isDeletable()?`enabled`:`hidden`},callback(t){e.B(!0);var n;(n=t.comment)==null||n.dispose(),e.B(!1);var r;(r=t.comment)==null||r.workspace.getAudioManager().play(`delete`)},scopeType:H.ScopeType.COMMENT,id:`commentDelete`,weight:6,associatedKeyboardShortcut:`delete`})},ho=function(){H.registry.register({displayText:()=>e.C.DUPLICATE_COMMENT,preconditionFn(e){var t;return(t=e.comment)!=null&&t.isMovable()?`enabled`:`hidden`},callback(e){if(e.comment){var t=e.comment.toCopyData();t&&Li(t,e.comment.workspace)}},scopeType:H.ScopeType.COMMENT,id:`commentDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},go=function(){H.registry.register({displayText:()=>e.C.ADD_COMMENT,preconditionFn:e=>{var t;return(t=e.workspace)!=null&&t.isMutator?`hidden`:`enabled`},callback:(t,n,r,i)=>{(t=t.workspace)&&(e.B(!0),n=new md(t),n.moveTo(ct(t,new N(i.x,i.y))),e.t().focusNode(n),e.B(!1))},scopeType:H.ScopeType.WORKSPACE,id:`commentCreate`,weight:8})},_o=function(){Xa(),Za(),Qa(),eo(),to(),ao(),oo(),so(),co(),lo(),uo(),fo(),po()},w||={},w.scope={},w.ASSUME_ES2020=!1,w.ASSUME_ES6=w.ASSUME_ES2020,w.ASSUME_ES5=w.ASSUME_ES6,w.ASSUME_NO_NATIVE_MAP=!1,w.ASSUME_NO_NATIVE_SET=!1,w.ISOLATE_POLYFILLS=!1,w.FORCE_POLYFILL_PROMISE=!1,w.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1,w.INSTRUMENT_ASYNC_CONTEXT=!0,w.objectCreate=w.ASSUME_ES5||typeof Object.create==`function`?Object.create:function(e){function t(){}return t.prototype=e,new t},w.defineProperty=w.ASSUME_ES5||typeof Object.defineProperties==`function`?Object.defineProperty:function(e,t,n){return e==Array.prototype||e==Object.prototype||(e[t]=n.value),e},w.getGlobal=function(e){e=[typeof globalThis==`object`&&globalThis,e,typeof window==`object`&&window,typeof self==`object`&&self,typeof global==`object`&&global];for(var t=0;t<e.length;++t){var n=e[t];if(n&&n.Math==Math)return n}throw Error(`Cannot find global object`)},w.global=w.ASSUME_ES2020?globalThis:w.getGlobal(this),w.IS_SYMBOL_NATIVE=typeof Symbol==`function`&&typeof Symbol(`x`)==`symbol`,w.TRUST_ES6_POLYFILLS=!w.ISOLATE_POLYFILLS||w.IS_SYMBOL_NATIVE,w.polyfills={},w.propertyToPolyfillSymbol={},w.POLYFILL_PREFIX=`$jscp$`;var vo=`Int8 Uint8 Uint8Clamped Int16 Uint16 Int32 Uint32 Float32 Float64`.split(` `);w.global.BigInt64Array&&(vo.push(`BigInt64`),vo.push(`BigUint64`)),w.TYPED_ARRAY_CLASSES=vo,w.polyfillTypedArrayMethod=function(e,t,n,r){if(t)for(var i=0;i<w.TYPED_ARRAY_CLASSES.length;i++){var a=w.TYPED_ARRAY_CLASSES[i]+`Array.prototype.`+e;w.ISOLATE_POLYFILLS?w.polyfillIsolated(a,t,n,r):w.polyfillUnisolated(a,t,n,r)}},w.polyfill=function(e,t,n,r){t&&(w.ISOLATE_POLYFILLS?w.polyfillIsolated(e,t,n,r):w.polyfillUnisolated(e,t,n,r))},w.polyfillUnisolated=function(e,t){var n=w.global;e=e.split(`.`);for(var r=0;r<e.length-1;r++){var i=e[r];if(!(i in n))return;n=n[i]}e=e[e.length-1],r=n[e],t=t(r),t!=r&&t!=null&&w.defineProperty(n,e,{configurable:!0,writable:!0,value:t})},w.polyfillIsolated=function(e,t,n){var r=e.split(`.`);e=r.length===1;var i=r[0];i=!e&&i in w.polyfills?w.polyfills:w.global;for(var a=0;a<r.length-1;a++){var o=r[a];if(!(o in i))return;i=i[o]}r=r[r.length-1],n=w.IS_SYMBOL_NATIVE&&n===`es6`?i[r]:null,t=t(n),t!=null&&(e?w.defineProperty(w.polyfills,r,{configurable:!0,writable:!0,value:t}):t!==n&&(w.propertyToPolyfillSymbol[r]===void 0&&(e=Math.random()*1e9>>>0,w.propertyToPolyfillSymbol[r]=w.IS_SYMBOL_NATIVE?w.global.Symbol(r):w.POLYFILL_PREFIX+e+`$`+r),w.defineProperty(i,w.propertyToPolyfillSymbol[r],{configurable:!0,writable:!0,value:t})))},w.getConstructImplementation=function(){function e(){function e(){}return new e,Reflect.construct(e,[],function(){}),new e instanceof e}if(w.TRUST_ES6_POLYFILLS&&typeof Reflect<`u`&&Reflect.construct){if(e())return Reflect.construct;var t=Reflect.construct;return function(e,n,r){return e=t(e,n),r&&Reflect.setPrototypeOf(e,r.prototype),e}}return function(e,t,n){return n===void 0&&(n=e),n=w.objectCreate(n.prototype||Object.prototype),Function.prototype.apply.call(e,n,t)||n}},w.construct={valueOf:w.getConstructImplementation}.valueOf(),w.underscoreProtoCanBeSet=function(){var e={a:!0},t={};try{return t.__proto__=e,t.a}catch{}return!1},w.setPrototypeOf=w.ASSUME_ES6||w.TRUST_ES6_POLYFILLS&&typeof Object.setPrototypeOf==`function`?Object.setPrototypeOf:w.underscoreProtoCanBeSet()?function(e,t){if(e.__proto__=t,e.__proto__!==t)throw TypeError(e+` is not extensible`);return e}:null,w.inherits=function(e,t){if(e.prototype=w.objectCreate(t.prototype),e.prototype.constructor=e,w.ASSUME_ES6||w.setPrototypeOf){var n=w.setPrototypeOf;n(e,t)}else for(n in t)if(n!=`prototype`)if(Object.defineProperties){var r=Object.getOwnPropertyDescriptor(t,n);r&&Object.defineProperty(e,n,r)}else e[n]=t[n];e.superClass_=t.prototype},w.arrayIteratorImpl=function(e){var t=0;return function(){return t<e.length?{done:!1,value:e[t++]}:{done:!0}}},w.arrayIterator=function(e){return{next:w.arrayIteratorImpl(e)}},w.makeIterator=function(e){var t=typeof Symbol<`u`&&Symbol.iterator&&e[Symbol.iterator];if(t)return t.call(e);if(typeof e.length==`number`)return w.arrayIterator(e);throw Error(String(e)+` is not an iterable or ArrayLike`)},w.arrayFromIterator=function(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n},w.arrayFromIterable=function(e){return e instanceof Array?e:w.arrayFromIterator(w.makeIterator(e))},w.generator={},w.generator.ensureIteratorResultIsObject_=function(e){if(!(e instanceof Object))throw TypeError(`Iterator result `+e+` is not an object`)},w.generator.Context=function(){this.isRunning_=!1,this.yieldAllIterator_=null,this.yieldResult=void 0,this.nextAddress=1,this.finallyAddress_=this.catchAddress_=0,this.finallyContexts_=this.abruptCompletion_=null},w.generator.Context.prototype.start_=function(){if(this.isRunning_)throw TypeError(`Generator is already running`);this.isRunning_=!0},w.generator.Context.prototype.stop_=function(){this.isRunning_=!1},w.generator.Context.prototype.jumpToErrorHandler_=function(){this.nextAddress=this.catchAddress_||this.finallyAddress_},w.generator.Context.prototype.next_=function(e){this.yieldResult=e},w.generator.Context.prototype.throw_=function(e){this.abruptCompletion_={exception:e,isException:!0},this.jumpToErrorHandler_()},w.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},w.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},w.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},w.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},w.generator.Context.prototype.return=function(e){this.abruptCompletion_={return:e},this.nextAddress=this.finallyAddress_},w.generator.Context.prototype.return=w.generator.Context.prototype.return,w.generator.Context.prototype.jumpThroughFinallyBlocks=function(e){this.abruptCompletion_={jumpTo:e},this.nextAddress=this.finallyAddress_},w.generator.Context.prototype.jumpThroughFinallyBlocks=w.generator.Context.prototype.jumpThroughFinallyBlocks,w.generator.Context.prototype.yield=function(e,t){return this.nextAddress=t,{value:e}},w.generator.Context.prototype.yield=w.generator.Context.prototype.yield,w.generator.Context.prototype.yieldAll=function(e,t){e=w.makeIterator(e);var n=e.next();if(w.generator.ensureIteratorResultIsObject_(n),n.done)this.yieldResult=n.value,this.nextAddress=t;else return this.yieldAllIterator_=e,this.yield(n.value,t)},w.generator.Context.prototype.yieldAll=w.generator.Context.prototype.yieldAll,w.generator.Context.prototype.jumpTo=function(e){this.nextAddress=e},w.generator.Context.prototype.jumpTo=w.generator.Context.prototype.jumpTo,w.generator.Context.prototype.jumpToEnd=function(){this.nextAddress=0},w.generator.Context.prototype.jumpToEnd=w.generator.Context.prototype.jumpToEnd,w.generator.Context.prototype.setCatchFinallyBlocks=function(e,t){this.catchAddress_=e,t!=null&&(this.finallyAddress_=t)},w.generator.Context.prototype.setCatchFinallyBlocks=w.generator.Context.prototype.setCatchFinallyBlocks,w.generator.Context.prototype.setFinallyBlock=function(e){this.catchAddress_=0,this.finallyAddress_=e||0},w.generator.Context.prototype.setFinallyBlock=w.generator.Context.prototype.setFinallyBlock,w.generator.Context.prototype.leaveTryBlock=function(e,t){this.nextAddress=e,this.catchAddress_=t||0},w.generator.Context.prototype.leaveTryBlock=w.generator.Context.prototype.leaveTryBlock,w.generator.Context.prototype.enterCatchBlock=function(e){return this.catchAddress_=e||0,e=this.abruptCompletion_.exception,this.abruptCompletion_=null,e},w.generator.Context.prototype.enterCatchBlock=w.generator.Context.prototype.enterCatchBlock,w.generator.Context.prototype.enterFinallyBlock=function(e,t,n){n?this.finallyContexts_[n]=this.abruptCompletion_:this.finallyContexts_=[this.abruptCompletion_],this.catchAddress_=e||0,this.finallyAddress_=t||0},w.generator.Context.prototype.enterFinallyBlock=w.generator.Context.prototype.enterFinallyBlock,w.generator.Context.prototype.leaveFinallyBlock=function(e,t){if(t=this.finallyContexts_.splice(t||0)[0],t=this.abruptCompletion_=this.abruptCompletion_||t){if(t.isException)return this.jumpToErrorHandler_();t.jumpTo!=null&&this.finallyAddress_<t.jumpTo?(this.nextAddress=t.jumpTo,this.abruptCompletion_=null):this.nextAddress=this.finallyAddress_}else this.nextAddress=e},w.generator.Context.prototype.leaveFinallyBlock=w.generator.Context.prototype.leaveFinallyBlock,w.generator.Context.prototype.forIn=function(e){return new w.generator.Context.PropertyIterator(e)},w.generator.Context.prototype.forIn=w.generator.Context.prototype.forIn,w.generator.Context.PropertyIterator=function(e){for(var t in this.object_=e,this.properties_=[],e)this.properties_.push(t);this.properties_.reverse()},w.generator.Context.PropertyIterator.prototype.getNext=function(){for(;this.properties_.length>0;){var e=this.properties_.pop();if(e in this.object_)return e}return null},w.generator.Context.PropertyIterator.prototype.getNext=w.generator.Context.PropertyIterator.prototype.getNext,w.generator.Engine_=function(e){this.context_=new w.generator.Context,this.program_=e},w.generator.Engine_.prototype.next_=function(e){return this.context_.start_(),this.context_.yieldAllIterator_?this.yieldAllStep_(this.context_.yieldAllIterator_.next,e,this.context_.next_):(this.context_.next_(e),this.nextStep_())},w.generator.Engine_.prototype.return_=function(e){this.context_.start_();var t=this.context_.yieldAllIterator_;return t?this.yieldAllStep_(`return`in t?t.return:function(e){return{value:e,done:!0}},e,this.context_.return):(this.context_.return(e),this.nextStep_())},w.generator.Engine_.prototype.throw_=function(e){return this.context_.start_(),this.context_.yieldAllIterator_?this.yieldAllStep_(this.context_.yieldAllIterator_.throw,e,this.context_.next_):(this.context_.throw_(e),this.nextStep_())},w.generator.Engine_.prototype.yieldAllStep_=function(e,t,n){try{var r=e.call(this.context_.yieldAllIterator_,t);if(w.generator.ensureIteratorResultIsObject_(r),!r.done)return this.context_.stop_(),r;var i=r.value}catch(e){return this.context_.yieldAllIterator_=null,this.context_.throw_(e),this.nextStep_()}return this.context_.yieldAllIterator_=null,n.call(this.context_,i),this.nextStep_()},w.generator.Engine_.prototype.nextStep_=function(){for(;this.context_.nextAddress;)try{var e=this.program_(this.context_);if(e)return this.context_.stop_(),{value:e.value,done:!1}}catch(e){this.context_.yieldResult=void 0,this.context_.throw_(e)}if(this.context_.stop_(),this.context_.abruptCompletion_){if(e=this.context_.abruptCompletion_,this.context_.abruptCompletion_=null,e.isException)throw e.exception;return{value:e.return,done:!0}}return{value:void 0,done:!0}},w.generator.Generator_=function(e){this.next=function(t){return e.next_(t)},this.throw=function(t){return e.throw_(t)},this.return=function(t){return e.return_(t)},this[Symbol.iterator]=function(){return this}},w.generator.createGenerator=function(e,t){return t=new w.generator.Generator_(new w.generator.Engine_(t)),w.setPrototypeOf&&e.prototype&&w.setPrototypeOf(t,e.prototype),t},w.asyncExecutePromiseGenerator=function(e){function t(t){return e.next(t)}function n(t){return e.throw(t)}return new Promise(function(r,i){function a(e){e.done?r(e.value):Promise.resolve(e.value).then(t,n).then(a,i)}a(e.next())})},w.asyncExecutePromiseGeneratorFunction=function(e){return w.asyncExecutePromiseGenerator(e())},w.asyncExecutePromiseGeneratorProgram=function(e){return w.asyncExecutePromiseGenerator(new w.generator.Generator_(new w.generator.Engine_(e)))},w.polyfill(`globalThis`,function(e){return e||w.global},`es_2020`,`es3`),w.polyfill(`Array.prototype.includes`,function(e){return e||function(e,t){var n=this;n instanceof String&&(n=String(n));var r=n.length;for(t||=0,t<0&&(t=Math.max(t+r,0));t<r;t++){var i=n[t];if(i===e||Object.is(i,e))return!0}return!1}},`es7`,`es3`),w.owns=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},w.polyfill(`Object.values`,function(e){return e||function(e){var t=[],n;for(n in e)w.owns(e,n)&&t.push(e[n]);return t}},`es8`,`es3`),w.checkEs6ConformanceViaProxy=function(){try{var e={},t=Object.create(new w.global.Proxy(e,{get:function(n,r,i){return n==e&&r==`q`&&i==t}}));return t.q===!0}catch{return!1}},w.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS=!1,w.ES6_CONFORMANCE=w.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS&&w.checkEs6ConformanceViaProxy(),w.initSymbol=function(){},w.iteratorPrototype=function(e){return e={next:e},e[Symbol.iterator]=function(){return this},e},w.MapEntry=function(){},w.polyfill(`Set.prototype.difference`,function(e){return e||function(e){w.checkIsSetInstance(this),w.checkIsSetLike(e);var t=w.getSmallerAndLargerSets(this,e);e=new Set(this);var n=t.smallerSetIterator;t=t.largerSet;for(var r=n.next();!r.done;)t.has(r.value)&&e.delete(r.value),r=n.next();return e}},`es_next`,`es6`),w.checkIsSetLike=function(e){if(typeof e!=`object`||!e||typeof e.size!=`number`||e.size<0||typeof e.keys!=`function`||typeof e.has!=`function`)throw TypeError(`Argument must be set-like`)},w.checkIsValidIterator=function(e){if(typeof e!=`object`||!e||typeof e.next!=`function`)throw TypeError(`Invalid iterator.`);return e},w.getSmallerAndLargerSets=function(e,t){return e.size<=t.size?{smallerSetIterator:e.keys(),largerSet:t}:{smallerSetIterator:w.checkIsValidIterator(t.keys()),largerSet:e}},w.checkIsSetInstance=function(e){if(!(e instanceof Set))throw TypeError(`Method must be called on an instance of Set.`)},w.iteratorFromArray=function(e,t){if(w.ASSUME_ES6)return e[Symbol.iterator]();e instanceof String&&(e+=``);var n=0,r=!1,i={next:function(){if(!r&&n<e.length){var i=n++;return{value:t(i,e[i]),done:!1}}return r=!0,{done:!0,value:void 0}}};return i[Symbol.iterator]=function(){return i},i},w.polyfill(`Array.prototype.values`,function(e){return e||function(){return w.iteratorFromArray(this,function(e,t){return t})}},`es8`,`es3`),w.polyfill(`Array.prototype.flatMap`,function(e){return e||function(e,t){var n=[];return Array.prototype.forEach.call(this,function(r,i){r=e.call(t,r,i,this),Array.isArray(r)?n.push.apply(n,r):n.push(r)}),n}},`es9`,`es5`),w.polyfill(`Array.prototype.flat`,function(e){return e||function(e){e=e===void 0?1:e;var t=[];return Array.prototype.forEach.call(this,function(n){Array.isArray(n)&&e>0?(n=Array.prototype.flat.call(n,e-1),t.push.apply(t,n)):t.push(n)}),t}},`es9`,`es5`),w.polyfill(`Object.entries`,function(e){return e||function(e){var t=[],n;for(n in e)w.owns(e,n)&&t.push([n,e[n]]);return t}},`es8`,`es3`);var yo=`ontouchstart`in globalThis||!!(globalThis.document&&document.documentElement&&`ontouchstart`in document.documentElement)||!(!globalThis.navigator||!globalThis.navigator.maxTouchPoints&&!globalThis.navigator.msMaxTouchPoints),bo=null,xo={mousedown:[`pointerdown`],mouseenter:[`pointerenter`],mouseleave:[`pointerleave`],mousemove:[`pointermove`],mouseout:[`pointerout`],mouseover:[`pointerover`],mouseup:[`pointerup`,`pointercancel`],touchend:[`pointerup`],touchcancel:[`pointercancel`]},So=0,Co={TOUCH_ENABLED:yo,TOUCH_MAP:xo};Co.checkTouchIdentifier=a,Co.clearTouchIdentifier=function(){bo=null},Co.getTouchIdentifierFromEvent=i,Co.longStart=t,Co.longStop=n,Co.shouldHandleEvent=r;var wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No;(function(e){function t(e){return n.includes(e.toUpperCase())}wo=e;var n=wo.toUpperCase();To=t(`JavaFX`),Eo=t(`WebKit`),Do=t(`Gecko`)&&!Eo,Oo=t(`Android`),e=globalThis.navigator&&globalThis.navigator.maxTouchPoints,ko=t(`iPad`)||t(`Macintosh`)&&e>0,Ao=t(`iPhone`)&&!ko,jo=t(`Macintosh`),Mo=ko||Oo&&!t(`Mobile`)||t(`Silk`),No=!Mo&&(Ao||Oo)})(globalThis.navigator&&globalThis.navigator.userAgent||``);var Po=To,Fo=Do,Io=Oo,Lo=ko,Ro=Ao,zo=jo,Bo=No,Vo=zo||Lo||Ro,Ho={ANDROID:Io,APPLE:Vo,GECKO:Fo,IPAD:Lo,IPHONE:Ro,JavaFx:Po,MAC:zo,MOBILE:Bo,raw:wo},Uo={};Uo.bind=s,Uo.conditionalBind=o,Uo.getScrollDeltaPixels=ee,Uo.isRightButton=u,Uo.isTargetInput=l,Uo.mouseToSvg=d,Uo.unbind=c;var Wo={};Wo.removeElem=f;var Go=class{constructor(e){this.name=e}toString(){return this.name}};Go.POSITIONABLE=new Go(`positionable`),Go.DRAG_TARGET=new Go(`drag_target`),Go.DELETE_AREA=new Go(`delete_area`),Go.AUTOHIDEABLE=new Go(`autohideable`),Go.FOCUSABLE=new Go(`focusable`);var T=class{constructor(){this.componentData=new Map,this.capabilityToComponentIds=new Map}addComponent(e,t){var n=e.component.id;if(!t&&this.componentData.has(n)){var r;throw Error(`Plugin "`+n+`" with capabilities "`+((r=this.componentData.get(n))==null?void 0:r.capabilities)+`" already added.`)}for(this.componentData.set(n,e),t=[],r=0;r<e.capabilities.length;r++){let i=String(e.capabilities[r]).toLowerCase();if(t.push(i),this.capabilityToComponentIds.has(i)){let e;(e=this.capabilityToComponentIds.get(i))==null||e.push(n)}else this.capabilityToComponentIds.set(i,[n])}this.componentData.get(n).capabilities=t}removeComponent(e){var t=this.componentData.get(e);if(t){for(let n=0;n<t.capabilities.length;n++){let r=String(t.capabilities[n]).toLowerCase();f(this.capabilityToComponentIds.get(r),e)}this.componentData.delete(e)}}addCapability(e,t){if(!this.getComponent(e))throw Error(`Cannot add capability, "`+t+`". Plugin "`+e+`" has not been added to the ComponentManager`);if(this.hasCapability(e,t))console.warn(`Plugin "`+e+`already has capability "`+t+`"`);else{t=`${t}`.toLowerCase();var n;(n=this.componentData.get(e))==null||n.capabilities.push(t);var r;(r=this.capabilityToComponentIds.get(t))==null||r.push(e)}}removeCapability(e,t){if(!this.getComponent(e))throw Error(`Cannot remove capability, "`+t+`". Plugin "`+e+`" has not been added to the ComponentManager`);this.hasCapability(e,t)?(t=`${t}`.toLowerCase(),f(this.componentData.get(e).capabilities,t),f(this.capabilityToComponentIds.get(t),e)):console.warn(`Plugin "`+e+`doesn't have capability "`+t+`" to remove`)}hasCapability(e,t){return t=`${t}`.toLowerCase(),this.componentData.has(e)&&this.componentData.get(e).capabilities.includes(t)}getComponent(e){var t;return(t=this.componentData.get(e))==null?void 0:t.component}getComponents(e,t){if(e=`${e}`.toLowerCase(),e=this.capabilityToComponentIds.get(e),!e)return[];var n=[];if(t){let t=[];e.forEach(e=>{t.push(this.componentData.get(e))}),t.sort(function(e,t){return e.weight-t.weight}),t.forEach(function(e){n.push(e.component)})}else e.forEach(e=>{n.push(this.componentData.get(e).component)});return n}};T.Capability=Go;var Ko=T||={},qo=Ko.ComponentWeight||={};qo[qo.TOOLBOX_WEIGHT=0]=`TOOLBOX_WEIGHT`,qo[qo.FLYOUT_WEIGHT=1]=`FLYOUT_WEIGHT`,qo[qo.TRASHCAN_WEIGHT=2]=`TRASHCAN_WEIGHT`,qo[qo.ZOOM_CONTROLS_WEIGHT=3]=`ZOOM_CONTROLS_WEIGHT`;var Jo=new WeakSet,Yo=[],Xo=`
9
+ `)},or=function(e,t,n){for(var r=[0],i=[],a=0;a<e.length;a++)r[r.length-1]+=e[a].length,t[a]===!0?(r.push(0),i.push(e[a].charAt(e[a].length-1))):t[a]===!1&&r[r.length-1]++;for(e=Math.max(...r),t=0,a=0;a<r.length;a++)t-=Math.abs(n-r[a])**1.5*2,t-=(e-r[a])**1.5,`.?!`.includes(i[a])?t+=n/3:`,;)]}`.includes(i[a])&&(t+=n/4);return r.length>1&&r[r.length-1]<=r[r.length-2]&&(t+=.5),t},sr=function(e,t,n){var r=or(e,t,n);for(let a=0;a<t.length-1;a++){if(t[a]===t[a+1])continue;let o=[].concat(t);o[a]=!o[a],o[a+1]=!o[a+1];let s=or(e,o,n);if(s>r){r=s;var i=o}}return i?sr(e,i,n):t},e.zf=function(e){return/^\s*-?\d+(\.\d+)?\s*$/.test(e)},cr=function(e){if(e=lr(e)){for(e=e.tooltip;typeof e==`function`;)e=e();if(typeof e!=`string`)throw Error(`Tooltip function must return a string.`);return e}return``},lr=function(e){for(;e&&e.tooltip;){if(typeof e.tooltip==`string`||typeof e.tooltip==`function`)return e;e=e.tooltip}return null},ur=function(){document.querySelector(`.blocklyTooltipDiv`)||(Lu=document.createElement(`div`),Lu.className=`blocklyTooltipDiv`,(ke()||document.body).appendChild(Lu))},dr=function(e){e.mouseOverWrapper_=s(e,`pointerover`,null,pr),e.mouseOutWrapper_=s(e,`pointerout`,null,mr),e.addEventListener(`pointermove`,hr,!1)},fr=function(e){e&&(c(e.mouseOverWrapper_),c(e.mouseOutWrapper_),e.removeEventListener(`pointermove`,hr))},pr=function(e){Au||(e=lr(e.currentTarget),Fu!==e&&(_r(),Iu=null,Fu=e),clearTimeout(ju))},mr=function(){Au||(ju=setTimeout(function(){Iu=Fu=null,_r()},1),clearTimeout(Mu),Mu=0)},hr=function(e){if(Fu&&Fu.tooltip&&!Au){if(ku){let t=Nu-e.pageX;e=Pu-e.pageY,Math.sqrt(t*t+e*e)>10&&_r()}else Iu!==Fu&&(clearTimeout(Mu),Nu=e.pageX,Pu=e.pageY,Mu=setTimeout(()=>{if(this instanceof Element)for(let t of Se()){if(!t.rendered)continue;let n;if((n=t.getInjectionDiv())!=null&&n.contains(this)){var e=t;break}}br(e)},750))}},gr=function(){Iu=Fu=null,_r()},_r=function(){ku&&(ku=!1,Lu&&(Lu.style.display=`none`)),Mu&&=(clearTimeout(Mu),0)},vr=function(e,t){Fu!==e&&(_r(),Iu=null,Fu=e),Fu&&Fu.tooltip&&!Au&&(e=e.getFocusableElement().getBoundingClientRect(),Nu=Fu.RTL?e.x+e.width:e.x,Pu=e.y+e.height,br(t))},yr=function(){_r(),Au=!0},br=function(t){if(!Au&&(Iu=Fu,Lu)){var n;if((n=ke(t))==null||n.appendChild(Lu),Lu.textContent=``,Lu&&Fu){if(typeof Ou==`function`)Ou(Lu,Fu);else for(t=cr(Fu),t=e.yf(t,50),t=t.split(`
10
+ `),n=0;n<t.length;n++){var r=document.createElement(`div`);r.appendChild(document.createTextNode(t[n])),Lu.appendChild(r)}}t=Fu.RTL,Lu.style.direction=t?`rtl`:`ltr`,Lu.style.display=`block`,ku=!0,n=document.documentElement.clientWidth,r=document.documentElement.clientHeight;var i=Nu;i=t?i-(0+Lu.offsetWidth):i+0;var a=Pu+10,o,s=(o=Lu)==null?void 0:o.parentElement;s&&(o=s.getBoundingClientRect(),i-=o.left+window.scrollX,a-=o.top+window.scrollY),a+Lu.offsetHeight>r+window.scrollY&&(a-=Lu.offsetHeight+20),t?i=Math.max(5-window.scrollX,i):i+Lu.offsetWidth>n+window.scrollX-10&&(i=n-Lu.offsetWidth-10);var{x:c,y:l}={x:i,y:a};Lu.style.left=c+`px`,Lu.style.top=l+`px`}},xr=function(e){e=`${e}`.toLowerCase().trim();var t=Vu[e];if(t||(t=e.substring(0,2)===`0x`?`#`+e.substring(2):e,t=t[0]===`#`?t:`#`+t,/^#[0-9a-f]{6}$/.test(t)))return t;if(/^#[0-9a-f]{3}$/.test(t))return[`#`,t[1],t[1],t[2],t[2],t[3],t[3]].join(``);var n=e.match(/^(?:rgb)?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);return n&&(e=Number(n[1]),t=Number(n[2]),n=Number(n[3]),e>=0&&e<256&&t>=0&&t<256&&n>=0&&n<256)?Sr(e,t,n):null},Sr=function(e,t,n){return t=e<<16|t<<8|n,e<16?`#`+(16777216|t).toString(16).substr(1):`#`+t.toString(16)},Cr=function(e){return e=xr(e),e?(e=parseInt(e.substr(1),16),[e>>16,e>>8&255,e&255]):[0,0,0]},wr=function(e,t,n){var r=0,i=0,a=0;if(t===0)a=i=r=n;else{let o=Math.floor(e/60),s=e/60-o;e=n*(1-t);let c=n*(1-t*s);switch(t=n*(1-t*(1-s)),o){case 1:r=c,i=n,a=e;break;case 2:r=e,i=n,a=t;break;case 3:r=e,i=c,a=n;break;case 4:r=t,i=e,a=n;break;case 5:r=n,i=e,a=c;break;case 6:case 0:r=n,i=t,a=e}}return Sr(Math.floor(r),Math.floor(i),Math.floor(a))},Tr=function(e,t,n){return e=xr(e),!e||(t=xr(t),!t)?null:(e=Cr(e),t=Cr(t),Sr(Math.round(t[0]+n*(e[0]-t[0])),Math.round(t[1]+n*(e[1]-t[1])),Math.round(t[2]+n*(e[2]-t[2]))))},Er=function(e){return wr(e,zu,Bu*255)},Dr=function(t,n,r){var i=[],a=t.split(``);a.push(``);var o=0;t=[];var s=null;for(let u=0;u<a.length;u++){var c=a[u];if(o===0){if(c===`%`)(o=t.join(``))&&i.push(o),t.length=0,o=1;else if(r&&c===`
11
+ `){let e=t.join(``);e&&i.push(e),t.length=0,i.push(c)}else t.push(c)}else if(o===1)c===`%`?(t.push(c),o=0):n&&`0`<=c&&c<=`9`?(o=2,s=c,(c=t.join(``))&&i.push(c),t.length=0):c===`{`?o=3:(t.push(`%`,c),o=0);else if(o===2){if(`0`<=c&&c<=`9`)s+=c;else{var l=void 0;i.push(parseInt((l=s)??``,10)),u--,o=0}}else o===3&&(c===``?(t.splice(0,0,`%{`),u--,o=0):c===`}`?(o=t.join(``),/[A-Z]\w*/i.test(o)?(c=o.toUpperCase(),(c=c.startsWith(`BKY_`)?c.substring(4):null)&&c in e.C?(o=e.C[c],typeof o==`string`?Array.prototype.push.apply(i,Dr(o,n,r)):n?i.push(`${o}`):i.push(o)):i.push(`%{`+o+`}`)):i.push(`%{`+o+`}`),o=t.length=0):t.push(c))}for((n=t.join(``))&&i.push(n),l=[],t.length=0,a=0;a<i.length;a++)typeof i[a]!=`string`||r&&i[a]===`
12
+ `?((n=t.join(``))&&l.push(n),t.length=0,l.push(i[a])):t.push(i[a]);return(n=t.join(``))&&l.push(n),t.length=0,l},Or=function(e){return Dr(e,!0,!0)},kr=function(e){return typeof e==`string`?(e=Dr(e,!1,!1),e.length?String(e[0]):``):e},Ar=function(e){var t=typeof e==`string`?kr(e):e,n=Number(t);if(!isNaN(n)&&0<=n&&n<=360)return{hue:n,hex:wr(n,zu,Bu*255)};if(n=xr(t))return{hue:null,hex:n};throw n=`Invalid colour: "`+t+`"`,e!==t&&(n+=` (from "`+e+`")`),Error(n)},jr=function(){Zu&&=(Zu(!1),null),Pr()},Mr=function(){var e=ke()||document.body,t=document.querySelector(`div.blocklyWidgetDiv`);t?Xu=t:(Xu=document.createElement(`div`),Xu.id=He(),Xu.className=`blocklyWidgetDiv`,Xu.tabIndex=-1),o(Xu,`keydown`,null,Fe),e.appendChild(Xu)},Nr=function(t,n,r,i,a=!0){if(Pr(),Gu=t,qu=r,r=Xu){Ku=i??Os;var o=ae(Ku.getFocusableElement(),k.OWNS);m(Ku.getFocusableElement(),k.OWNS,o?[o,r.id]:r.id),Ku.getFocusableElement().classList.add(`blocklyShowingWidgetDiv`);var s;(s=ke())==null||s.appendChild(r),r.style.direction=n?`rtl`:`ltr`,r.style.display=`block`,!i&&t instanceof V&&t.getSourceBlock(),Ju=Ku.getRenderer().getClassName(),Yu=Ku.getTheme().getClassName(),Ju&&g(r,Ju),Yu&&g(r,Yu),a&&(Zu=e.t().takeEphemeralFocus(r)),e.t().registerPopoverFocusLossHandler(jr)}},Pr=function(){if(Gu){Gu=null;var t=Xu;if(t){e.t().unregisterPopoverFocusLossHandler(jr),t.style.display=`none`,t.style.left=``,t.style.top=``,qu&&=(qu(),null),t.textContent=``,Ju&&=(_(t,Ju),``),Yu&&=(_(t,Yu),``);var n;(n=Ku)==null||n.markFocused(),Zu&&=(Zu(),null),Ku&&Xu&&(t=ae(Ku.getFocusableElement(),k.OWNS)??``,m(Ku.getFocusableElement(),k.OWNS,t.replace(Xu.id,``)),Ku.getFocusableElement().classList.remove(`blocklyShowingWidgetDiv`))}}},Fr=function(e){Gu===e&&Pr()},Ir=function(e){for(var t=Ku===null,n=e;!t&&n;){if(n===e){t=!0;break}n=e.options.parentWorkspace}t&&Pr()},Lr=function(e,t,n){if(Xu){var r=Xu.parentElement;r&&(r=r.getBoundingClientRect(),e-=r.left+window.scrollX,t-=r.top+window.scrollY),Xu.style.left=e+`px`,Xu.style.top=t+`px`,Xu.style.height=n+`px`}},Rr=function(e,t,n,r){var i=t.bottom+n.height>=e.bottom?t.top-n.height:t.bottom;e=r?Math.min(Math.max(t.right-n.width,e.left),e.right-n.width):Math.max(Math.min(t.left,e.right-n.width),e.left),i<0?Lr(e,0,n.height+i):Lr(e,i,n.height)},zr=function(){var e;(e=Gu)!=null&&e.repositionForWindowResize&&Gu.repositionForWindowResize()||Pr()},Br=function(e,t,n,r,i){if(Nr(ed,n,Gr,r),t.length){i||(e instanceof PointerEvent?i=new N(e.clientX,e.clientY):(console.warn(`Context menu opened with keyboard but no location given`),i=new N(0,0)));var a=Vr(t,n,e,i);td=a,Hr(a,n,i),setTimeout(function(){a.focus()},1),$u=null}else Wr()},Vr=function(e,t,n,r){var i=new wc;i.setRole(O.MENU);for(let a=0;a<e.length;a++){let o=e[a];if(o.separator){i.addChild(new Tc);continue}let s=new Cc(Kr(o));s.setRightToLeft(t),s.setRole(O.MENUITEM),i.addChild(s),s.setEnabled(o.enabled),o.enabled&&s.onAction(function(e,t){Wr(),requestAnimationFrame(()=>{setTimeout(()=>{o.callback(o.scope,n,t,r)},0)})},{})}return i},Hr=function(e,t,n){var r=ot();n=new P(n.y+r.top,n.y+r.top,n.x+r.left,n.x+r.left);var i=Xu;if(!i)throw Error(`Attempting to create a context menu when widget div is null`);i=e.render(i),g(i,`blocklyContextMenu`),o(i,`contextmenu`,null,Ur),e.focus(),i=e.getSize(),t&&(n.left+=i.width,n.right+=i.width,r.left+=i.width,r.right+=i.width),Rr(r,n,i,t),e.focus()},Ur=function(e){e.preventDefault(),e.stopPropagation()},Wr=function(){Fr(ed),$u=null;var e;(e=td)==null||e.dispose(),td=null},Gr=function(){td&&=(td.dispose(),null)},e.Pg=function(t,n){return()=>{e.Ub++;try{var r=n instanceof Element?ri(n,t.workspace):mn(n,t.workspace);let i=t.getRelativeToSurfaceXY();i.x=t.RTL?i.x-e.Og.snapRadius:i.x+e.Og.snapRadius,i.y+=e.Og.snapRadius*2,r.moveBy(i.x,i.y)}finally{e.Ub--}return Je()&&!r.isShadow()&&b(new(x(E.BLOCK_CREATE))(r)),e.t().focusNode(r),r}},Kr=function(e){var t=e.text;if(t&&!(t instanceof HTMLElement)){let n=document.createElement(`div`);n.className=`blocklyShortcutContainer`;let r=document.createElement(`span`);return r.textContent=t,t=document.createElement(`span`),t.className=`blocklyShortcut`,e=`id`in e&&e.associatedKeyboardShortcut?vn(e.associatedKeyboardShortcut):``,t.textContent=` ${e}`,n.appendChild(r),n.appendChild(t),n}return e.text},qr=function(e,t){return t=d(t,e.getParentSvg(),e.getInverseScreenCTM()),t.x/=e.scale,t.y/=e.scale,t},Jr=function(e,t,n){t=qr(e,t),sd.set(e,N.difference(n,t))},Yr=function(e,t){if(t=qr(e,t),e=sd.get(e),!e)throw Error(`Drag not initialized`);return N.sum(e,t)},Xr=function(t,n=!1){var r=e.rc(`comment`);n||r.setAttribute(`id`,t.id),n=t.workspace;var i=t.getRelativeToSurfaceXY().clone();return i.x=n.RTL?n.getWidth()-i.x:i.x,r.setAttribute(`x`,`${i.x}`),r.setAttribute(`y`,`${i.y}`),r.setAttribute(`w`,`${t.getSize().width}`),r.setAttribute(`h`,`${t.getSize().height}`),t.getText()&&(r.textContent=t.getText()),t.isCollapsed()&&r.setAttribute(`collapsed`,`true`),t.isOwnEditable()||r.setAttribute(`editable`,`false`),t.isOwnMovable()||r.setAttribute(`movable`,`false`),t.isOwnDeletable()||r.setAttribute(`deletable`,`false`),r},Zr=function(t){var n=e.rc(`variables`);for(let r=0;r<t.length;r++){let i=t[r],a=e.rc(`variable`);a.appendChild(e.sc(i.getName())),i.getType()&&a.setAttribute(`type`,i.getType()),a.id=i.getId(),n.appendChild(a)}return n},Qr=function(e,t){if(e.isInsertionMarker()&&(e=e.getChildren(!1)[0],!e))return new DocumentFragment;var n=0;if(e.workspace.RTL&&(n=e.workspace.getWidth()),t=$r(e,t),t.nodeType===ps.ELEMENT_NODE){let r=e.getRelativeToSurfaceXY();t.setAttribute(`x`,String(Math.round(e.workspace.RTL?n-r.x:r.x))),t.setAttribute(`y`,String(Math.round(r.y)))}return t},$r=function(t,n){if(t.isInsertionMarker())return(n=t.getChildren(!1)[0])?$r(n):new DocumentFragment;var r=e.rc(t.isShadow()?`shadow`:`block`);if(r.setAttribute(`type`,t.type),n||(r.id=t.id),t.mutationToDom){var i=t.mutationToDom();i&&(i.hasChildNodes()||i.hasAttributes())&&r.appendChild(i)}for(var a of t.getFields())a.isSerializable()?(i=e.rc(`field`),i.setAttribute(`name`,a.name||``),i=a.toXml(i)):i=null,i&&r.appendChild(i);if(a=t.getCommentText()){var o=t.getIcon(Kc.COMMENT);i=o.getBubbleSize();var s=o.bubbleIsVisible();o=o.getBubbleLocation();var c=e.rc(`comment`);c.appendChild(e.sc(a)),c.setAttribute(`pinned`,`${s}`),c.setAttribute(`h`,`${i.height}`),c.setAttribute(`w`,`${i.width}`),o&&(c.setAttribute(`x`,`${t.workspace.RTL?t.workspace.getWidth()-(o.x+i.width):o.x}`),c.setAttribute(`y`,`${o.y}`)),r.appendChild(c)}for(t.data&&(a=e.rc(`data`),a.appendChild(e.sc(t.data)),r.appendChild(a)),a=0;a<t.inputList.length;a++){i=t.inputList[a];var l=void 0;s=!0,i.type!==e.je.DUMMY&&i.type!==e.je.END_ROW&&(o=i.connection.targetBlock(),i.type===e.je.VALUE?l=e.rc(`value`):i.type===e.je.STATEMENT&&(l=e.rc(`statement`)),c=i.connection.getShadowDom(),!c||o&&o.isShadow()||l.appendChild(ei(c,n)),o&&(o=$r(o,n),o.nodeType===ps.ELEMENT_NODE&&(l.appendChild(o),s=!1)),l.setAttribute(`name`,i.name),s||r.appendChild(l))}if(t.inputsInline!==void 0&&t.inputsInline!==t.inputsInlineDefault&&r.setAttribute(`inline`,String(t.inputsInline)),t.isCollapsed()&&r.setAttribute(`collapsed`,`true`),t.isEnabled()||r.setAttribute(`disabled-reasons`,Array.from(t.getDisabledReasons()).map(encodeURIComponent).join(`,`)),t.isOwnDeletable()||r.setAttribute(`deletable`,`false`),t.isOwnMovable()||r.setAttribute(`movable`,`false`),t.isOwnEditable()||r.setAttribute(`editable`,`false`),l=t.getNextBlock(),l&&(a=$r(l,n),a.nodeType===ps.ELEMENT_NODE)){var u=e.rc(`next`);u.appendChild(a),r.appendChild(u)}return t=t.nextConnection&&t.nextConnection.getShadowDom(),!t||l&&l.isShadow()||u.appendChild(ei(t,n)),r},ei=function(e,t){for(var n=e=e.cloneNode(!0),r;n;)if(t&&n.nodeName===`shadow`&&n.removeAttribute(`id`),n.firstChild)n=n.firstChild;else{for(;n&&!n.nextSibling;){r=n,n=n.parentNode;let e;r.nodeType===ps.TEXT_NODE&&r.data.trim()===``&&((e=n)==null?void 0:e.firstChild)!==r&&v(r)}n&&(r=n,n=n.nextSibling,r.nodeType===ps.TEXT_NODE&&r.data.trim()===``&&v(r))}return e},ti=function(e){return ut(e).replace(/<(\w+)([^<]*)\/>/g,`<$1$2></$1>`)},e.ch=function(t,n){var r=0;n.RTL&&(r=n.getWidth());var i=[];fe();var a=e.gd;a||e.B(!0),n.setResizesEnabled&&n.setResizesEnabled(!1);var o=!0;try{for(let a=0,s;s=t.childNodes[a];a++){let t=s.nodeName.toLowerCase(),a=s;if(t===`block`||t===`shadow`&&!e.Qc){let e=ri(a,n);i.push(e.id);let t=parseInt(a.getAttribute(`x`)??`10`,10),s=parseInt(a.getAttribute(`y`)??`10`,10);isNaN(t)||isNaN(s)||e.moveBy(n.RTL?r-t:t,s,[`create`]),o=!1}else{if(t===`shadow`)throw TypeError(`Shadow block cannot be a top-level block.`);if(t===`comment`)ni(a,n);else if(t===`variables`){if(o)ii(a,n);else throw Error(`'variables' tag must exist once before block and shadow tag elements in the workspace XML, but it was found in another location.`);o=!1}}}}finally{e.B(a),n.setResizesEnabled&&n.setResizesEnabled(!0),n.rendered&&jt(),pe()}return b(new(x(E.FINISHED_LOADING))(n)),i},ni=function(e,t){var n,r=(n=e.getAttribute(`id`))??void 0;n=t.rendered?new md(t,r):new pd(t,r);var i;n.setText((i=e.textContent)??``);var a;i=parseInt((a=e.getAttribute(`x`))??``,10),a=parseInt(e.getAttribute(`y`)??``,10),isNaN(i)||isNaN(a)||(i=t.RTL?t.getWidth()-i:i,n.moveTo(new N(i,a)));var o;return t=parseInt((o=e.getAttribute(`w`))??``,10),o=parseInt(e.getAttribute(`h`)??``,10),isNaN(t)||isNaN(o)||n.setSize(new F(t,o)),e.getAttribute(`collapsed`)===`true`&&n.setCollapsed(!0),e.getAttribute(`editable`)===`false`&&n.setEditable(!1),e.getAttribute(`movable`)===`false`&&n.setMovable(!1),e.getAttribute(`deletable`)===`false`&&n.setDeletable(!1),n},e.fh=function(e,t){return e=ri(e,t),t.rendered&&jt(),e},ri=function(t,n){e.Ub++;var r=n.getVariableMap().getAllVariables();try{var i=si(t,n);if(n.rendered){let e=i,t=i.getDescendants(!1);e.setConnectionTracking(!1);for(let e=t.length-1;e>=0;e--)t[e].initSvg();for(let e=t.length-1;e>=0;e--)t[e].queueRender();setTimeout(function(){e.disposed||e.setConnectionTracking(!0)},1),n.resizeContents()}else{let e=i.getDescendants(!1);for(let t=e.length-1;t>=0;t--)e[t].initModel()}}finally{e.Ub--}if(Je()){for(t=cn(n,r),n=0;n<t.length;n++)r=t[n],b(new(x(E.VAR_CREATE))(r));b(new(x(E.BLOCK_CREATE))(i))}return i},ii=function(e,t){for(let r=0;r<e.children.length;r++){var n=e.children[r];let i=n.getAttribute(`type`),a=n.getAttribute(`id`);if(n=n.textContent,!n)break;t.getVariableMap().createVariable(n,i??void 0,a)}},ai=function(e,t){for(let n=0;n<e.length;n++){let r=e[n],i=r.textContent,a=r.getAttribute(`pinned`)===`true`,o=parseInt(r.getAttribute(`w`)??`50`,10),s=parseInt(r.getAttribute(`h`)??`50`,10),c=parseInt(r.getAttribute(`x`)??``,10),l=parseInt(r.getAttribute(`y`)??``,10);t.setCommentText(i);let u=t.getIcon(Kc.COMMENT);isNaN(o)||isNaN(s)||u.setBubbleSize(new F(o,s)),u.setBubbleVisible(a),setTimeout(()=>{isNaN(c)||isNaN(l)||(c=t.workspace.RTL?t.workspace.getWidth()-(c+o):c,u.setBubbleLocation(new N(c,l))),u.setBubbleVisible(a)},1)}},oi=function(e){var t=null,n=null;for(let r=0;r<e.childNodes.length;r++){let i=e.childNodes[r];i.nodeType===ps.ELEMENT_NODE&&(i.nodeName.toLowerCase()===`block`?t=i:i.nodeName.toLowerCase()===`shadow`&&(n=i))}return{childBlockElement:t,childShadowElement:n}},si=function(e,t,n,r){var i,a=e.getAttribute(`type`);if(!a)throw TypeError(`Block type unspecified: `+e.outerHTML);var o=(i=e.getAttribute(`id`))??void 0;i=t.newBlock(a,o);var s=[],c=[],l=[],u=[],d=[];o=[];for(var ee=0;ee<e.children.length;ee++){var f=e.children[ee];if(f.nodeType!==ps.TEXT_NODE)switch(f.nodeName.toLowerCase()){case`mutation`:s.push(f);break;case`comment`:c.push(f);break;case`data`:l.push(f);break;case`title`:case`field`:u.push(f);break;case`value`:case`statement`:d.push(f);break;case`next`:o.push(f);break;default:console.warn(`Ignoring unknown tag: `+f.nodeName)}}for(ee=!1,f=0;f<s.length;f++){let e=s[f];i.domToMutation&&(i.domToMutation(e),i.initSvg&&(ee=!0))}for(s=ee,ai(c,i),c=l,l=0;l<c.length;l++)i.data=c[l].textContent;if(n){if(r){if(i.previousConnection)r=i.previousConnection;else throw TypeError(`Next block does not have previous statement.`)}else if(i.outputConnection)r=i.outputConnection;else if(i.previousConnection)r=i.previousConnection;else throw TypeError(`Child block does not have output or previous statement.`);if(!n.connect(r))throw e=i.workspace.connectionChecker,TypeError(e.getErrorMessage(e.canConnectWithReason(r,n,!1),r,n))}for(n=u,u=0;u<n.length;u++)c=n[u],(l=c.getAttribute(`name`))?(r=i,(ee=r.getField(l))?ee.fromXml(c):console.warn(`Ignoring non-existent field `+l+` in block `+r.type)):console.warn(`Ignoring unnamed field in block ${i.type}`);for(n=0;n<d.length;n++){if(u=d[n],r=(c=u.getAttribute(`name`))?i.getInput(c):null,!r){console.warn(`Ignoring non-existent input `+c+` in block `+a);break}if(u=oi(u),u.childBlockElement){if(!r.connection)throw TypeError(`Input connection does not exist.`);si(u.childBlockElement,t,r.connection,!1)}if(u.childShadowElement){var te=void 0;(te=r.connection)==null||te.setShadowDom(u.childShadowElement)}}for(a=o,te=0;te<a.length;te++){if(o=oi(a[te]),o.childBlockElement){if(!i.nextConnection)throw TypeError(`Next statement does not exist.`);if(i.nextConnection.isConnected())throw TypeError(`Next statement is already connected.`);si(o.childBlockElement,t,i.nextConnection,!0)}o.childShadowElement&&i.nextConnection&&i.nextConnection.setShadowDom(o.childShadowElement)}if(s&&i.initSvg(),(t=e.getAttribute(`inline`))&&i.setInputsInline(t===`true`),(t=e.getAttribute(`disabled`))&&i.setDisabledReason(t===`true`||t===`disabled`,`MANUALLY_DISABLED`),t=e.getAttribute(`disabled-reasons`),t!==null)for(var ne of t.split(`,`))i.setDisabledReason(!0,decodeURIComponent(ne));if((ne=e.getAttribute(`deletable`))&&i.setDeletable(ne===`true`),(ne=e.getAttribute(`movable`))&&i.setMovable(ne===`true`),(ne=e.getAttribute(`editable`))&&i.setEditable(ne===`true`),(ne=e.getAttribute(`collapsed`))&&i.setCollapsed(ne===`true`),e.nodeName.toLowerCase()===`shadow`){for(e=i.getChildren(!1),ne=0;ne<e.length;ne++)if(!e[ne].isShadow())throw TypeError(`Shadow block not allowed non-shadow child.`);i.setShadow(!0)}return i},ci=function(e,t){y(M.FIELD,e,t,!0)},e.lh=function(e){return gd.fromJsonInternal(e)},li=function(e){return e&&typeof e==`object`&&`src`in e&&typeof e.src==`string`&&`alt`in e&&typeof e.alt==`string`&&`width`in e&&typeof e.width==`number`&&`height`in e&&typeof e.height==`number`},e.oh=function(e,t){if(typeof e!=`string`||e.trim()===``)throw Error(`Error: Invalid extension name "`+e+`"`);if(kd[e])throw Error(`Error: Extension "`+e+`" is already registered.`);if(typeof t!=`function`)throw Error(`Error: Extension "`+e+`" must be a function`);kd[e]=t},e.ph=function(t,n){if(!n||typeof n!=`object`)throw Error(`Error: Mixin "`+t+`" must be a object`);e.oh(t,function(){this.mixin(n)})},e.th=function(t,n,r,i){var a=`Error when registering mutator "`+t+`": `;pi(a,n);var o=fi(n.compose,n.decompose,a+` compose/decompose`);if(r&&typeof r!=`function`)throw Error(a+`Extension "`+t+`" is not a function`);e.oh(t,function(){o&&this.setMutator(new e.sh(i||[],this)),this.mixin(n),r&&r.apply(this)})},ui=function(e){return!!kd[e]},di=function(e,t,n){var r=kd[e];if(typeof r!=`function`)throw Error(`Error: Extension "`+e+`" not found.`);if(n){if(mi(t).length)throw Error(`Error: tried to apply mutation "`+e+`" to a block that already has mutator functions. Block id: `+t.id)}else var i=mi(t);if(r.apply(t),n)pi(`Error after applying mutator "`+e+`": `,t);else{a:if(n=i,t=mi(t),t.length!==n.length)t=!1;else{for(r=0;r<t.length;r++)if(n[r]!==t[r]){t=!1;break a}t=!0}if(!t)throw Error(`Error when applying extension "`+e+`": mutation properties changed when applying a non-mutator extension.`)}},fi=function(e,t,n){if(e&&t){if(typeof e!=`function`||typeof t!=`function`)throw Error(n+` must be a function`);return!0}if(!e&&!t)return!1;throw Error(n+`Must have both or neither functions`)},pi=function(e,t){var n=fi(t.mutationToDom,t.domToMutation,e+` mutationToDom/domToMutation`),r=fi(t.saveExtraState,t.loadExtraState,e+` saveExtraState/loadExtraState`);if(!n&&!r)throw Error(e+`Mutations must contain either XML hooks, or JSON hooks, or both`);fi(t.compose,t.decompose,e+` compose/decompose`)},mi=function(e){var t=[];return e.domToMutation!==void 0&&t.push(e.domToMutation),e.mutationToDom!==void 0&&t.push(e.mutationToDom),e.saveExtraState!==void 0&&t.push(e.saveExtraState),e.loadExtraState!==void 0&&t.push(e.loadExtraState),e.compose!==void 0&&t.push(e.compose),e.decompose!==void 0&&t.push(e.decompose),t},e.yh=function(e,t){var n=[];return function(){n.includes(this.type)||(hi(this,e,t),n.push(this.type)),this.setTooltip(function(){var n=String(this.getFieldValue(e));return kr(t[n])}.bind(this))}},hi=function(e,t,n){var r=e.getField(t);if(r instanceof vd&&!r.isOptionListDynamic()){r=r.getOptions();for(let i of r)i!==vd.SEPARATOR&&([,r]=i,n[r]===void 0&&console.warn(`No tooltip mapping for value ${r} of field ${t} of block type ${e.type}.`))}},e.Ah=function(e,t){return function(){this.setTooltip(function(){var n=this.getField(t);return kr(e).replace(`%1`,n?n.getText():``)}.bind(this))}},S=function(e,t){return` `+e+`,`+t+` `},gi=function(e,t){return` `+e+t.join(``)},_i=function(e,t){return` M `+e+`,`+t+` `},vi=function(e,t){return` m `+e+`,`+t+` `},yi=function(e,t){return` l `+e+`,`+t+` `},bi=function(e){return` l`+e.join(``)},C=function(e,t){return` `+e+` `+t+` `},xi=function(e,t,n,r){return e+` `+n+` `+n+` `+t+r},Si=function(e,t){var n=null;t=t.outputConnection;var r=t==null?void 0:t.getConnectionChecker();for(let i=0,a;a=e.inputList[i];i++){let e=a.connection;if(e&&r!=null&&r.canConnect(t,e,!1)){if(n)return null;n=e}}return n},Ci=function(e){return _e(e)&&typeof e.getType==`function`&&typeof e.initView==`function`&&typeof e.dispose==`function`&&typeof e.getWeight==`function`&&typeof e.getSize==`function`&&typeof e.applyColour==`function`&&typeof e.hideForInsertionMarker==`function`&&typeof e.updateEditable==`function`&&typeof e.updateCollapsed==`function`&&typeof e.isShownWhenCollapsed==`function`&&typeof e.setOffsetInBlock==`function`&&typeof e.onLocationChange==`function`&&typeof e.onClick==`function`},wi=function(e){if(!(e.getDescendants(!1).length>100)){var t=e.workspace,n=e.getSvgRoot();t.getAudioManager().play(`delete`);var r=e.getRelativeToSurfaceXY(),i=n.cloneNode(!0);i.setAttribute(`transform`,`translate(`+r.x+`,`+r.y+`)`);var a;(a=t.getLayerManager())==null||a.appendToAnimationLayer({getSvgRoot:()=>i}),Ti(i,{x:r.x,y:r.y,width:e.width,height:e.height},t.RTL,new Date)}},Ti=function(e,t,n,r){var i=(new Date().getTime()-r.getTime())/150;i>1?v(e):(e.setAttribute(`transform`,`translate(`+(t.x+(n?-1:1)*t.width/2*i)+`,`+(t.y+t.height/2*i)+`) scale(`+(1-i)+`)`),setTimeout(Ti,10,e,t,n,r))},Ei=function(e){var t=e.workspace,n=t.scale;if(t.getAudioManager().play(`click`),!(n<1)){var r=t.getSvgXY(e.getSvgRoot());e.outputConnection?(r.x+=(e.RTL?3:-3)*n,r.y+=13*n):e.previousConnection&&(r.x+=(e.RTL?-23:23)*n,r.y+=3*n);var i=h(A.CIRCLE,{cx:r.x,cy:r.y,r:0,fill:`none`,stroke:`#888`,"stroke-width":10},t.getParentSvg());e=h(A.ANIMATE,{id:`animationCircle`,begin:`indefinite`,attributeName:`r`,dur:`150ms`,from:0,to:25*n},i),t=h(A.ANIMATE,{id:`animationOpacity`,begin:`indefinite`,attributeName:`opacity`,dur:`150ms`,from:1,to:0},i),e.beginElement(),t.beginElement(),setTimeout(()=>void v(i),150)}},Di=function(e){if(ki(),e.workspace.getAudioManager().play(`disconnect`),!(e.workspace.scale<1)){var t=e.getHeightWidth().height;t=Math.atan(10/t)/Math.PI*180,e.RTL||(t*=-1),Yd=e,Oi(e,t,new Date,0)}},Oi=function(e,t,n,r){var i=[.66,1,.66,0,-.66,-1,-.66,0],a=``;n.getTime()+200>new Date().getTime()&&(a=`skewX(${Math.round(i[r%i.length]*t)})`,Jd=setTimeout(Oi,15,e,t,n,r+1)),e.getSvgRoot().setAttribute(`transform`,`${e.getTranslation()} ${a}`)},ki=function(){Yd&&=(Jd&&=(clearTimeout(Jd),null),Yd.getSvgRoot().setAttribute(`transform`,Yd.getTranslation()),null)},Ai=function(t,n){t.workspace.RTL&&(n.x=t.workspace.getWidth()-n.x);for(var r=t.workspace,i=e.Og.snapRadius,a=N.difference(n,t.getRelativeToSurfaceXY()),o=new N(0,0),s=r.getAllBlocks(!1).filter(e=>e.id!=t.id).map(e=>e.getRelativeToSurfaceXY());ji(N.sum(n,o),s)||Mi(t,N.sum(a,o),i);)r.RTL?o.translate(-i,i*2):o.translate(i,i*2);t.moveTo(N.sum(n,o))},ji=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},Mi=function(e,t,n){return e.getConnections_(!1).some(e=>!!e.closest(n,t).connection)},Ni=function(e,t,n){var r=n.getBoundingRectangle(),i=r.right-r.left,a=zn(t.top,r.top,t.top+t.height-(r.bottom-r.top))-r.top,o=t.left;return t=t.left+t.width-i,e.RTL?o=Math.min(t,o):t=Math.max(o,t),(e=zn(o,r.left,t)-r.left)||a?(n.moveBy(e,a,[`inbounds`]),!0):!1},Pi=function(t){return n=>{var r=t.getMetricsManager();if(r.hasFixedEdges()&&!t.isDragging()){var i;if(Qo.includes((i=n.type)??``)){switch(r=r.getScrollMetrics(!0),i=null,n.type){case E.BLOCK_CREATE:case E.BLOCK_MOVE:(i=t.getBlockById(n.blockId))&&(i=i.getRootBlock());break;case E.COMMENT_CREATE:case E.COMMENT_MOVE:case E.COMMENT_RESIZE:i=t.getCommentById(n.commentId)}if(i){var a=e.gd||!1;e.B(n.group),Ni(t,r,i)&&!n.group&&console.warn(`Moved object in bounds but there was no event group. This may break undo.`),e.B(a)}}else n.type===E.VIEWPORT_CHANGE&&n.scale&&n.oldScale&&n.scale>n.oldScale&&Fi(t)}}},Fi=function(e){var t=e.getMetricsManager();if(t.hasFixedEdges()&&!e.isDragging()){t=t.getScrollMetrics(!0);var n=e.getTopBoundedElements();for(let r=0,i;i=n[r];r++)Ni(e,t,i)}},Ii=function(e,t){var n=e.toCopyData();return $d=n,ef=ve(e)&&e.workspace instanceof Mp?e.workspace:null,tf=t,n},Li=function(e,t,n){return e&&t?Ri(e,t,n):$d&&ef?Ri($d,ef,tf):null},Ri=function(e,t,n){t=t.isMutator?t:t.options.parentWorkspace??t;var r;return((r=Le(M.PASTER,e.paster,!1))==null?void 0:r.paste(e,t,n))??null},zi=function(e){return e&&typeof e.toCopyData==`function`},Bi=function(e){return e&&typeof e.isDeletable==`function`&&typeof e.dispose==`function`&&typeof e.setDeleteStyle==`function`},Vi=function(e){return e&&typeof e.getRelativeToSurfaceXY==`function`&&typeof e.isMovable==`function`&&typeof e.startDrag==`function`&&typeof e.drag==`function`&&typeof e.endDrag==`function`&&typeof e.revertDrag==`function`},Hi=function(){j.registry.register({name:J.ESCAPE,preconditionFn(e){return!e.isReadOnly()},callback(e){return e.hideChaff(),!0},keyCodes:[U.ESC],displayText:()=>e.C.SHORTCUTS_ESCAPE})},Ui=function(){j.registry.register({name:J.DELETE,preconditionFn(t,n){return n=n.focusedNode,(n=!t.isReadOnly()&&n!=null&&Bi(n)&&n.isDeletable()&&!t.isDragging()&&!e.t().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),n=i.focusedNode,n instanceof gf?n.checkAndDelete():Bi(n)&&n.isDeletable()&&(e.B(!0),n.dispose(),e.B(!1),t.getAudioManager().play(`delete`)),!0},keyCodes:[U.DELETE,U.BACKSPACE],displayText:()=>e.C.SHORTCUTS_DELETE})},Wi=function(e){return zi(e)&&Bi(e)&&Vi(e)?e.isCopyable?e.isCopyable():e instanceof gf||e instanceof md?e.isOwnDeletable()&&e.isOwnMovable():e.isDeletable()&&e.isMovable():!1},Gi=function(){var t=j.registry.createSerializedKey(U.C,[U.CTRL_CMD]);j.registry.register({name:J.COPY,preconditionFn(t,n){n=n.focusedNode;var r=t.isFlyout?t.targetWorkspace:t;return(n=!!n&&!!r&&!r.isDragging()&&!e.t().ephemeralFocusTaken()&&Wi(n))||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),r=i.focusedNode,!r||!zi(r)||!Wi(r)||(i=t.isFlyout?t.targetWorkspace:t,!i)?!1:(r.workspace.isFlyout||i.hideChaff(),i=Vi(r)&&r.workspace==i?r.getRelativeToSurfaceXY():void 0,(r=!!Ii(r,i))&&n instanceof KeyboardEvent&&Pc.show(t,{message:e.C.KEYBOARD_NAV_COPIED_HINT.replace(`%1`,vn(J.PASTE)),duration:7,id:`copiedHint`}),r)},keyCodes:[t],displayText:()=>e.C.COPY_SHORTCUT})},Ki=function(){var t=j.registry.createSerializedKey(U.X,[U.CTRL_CMD]);j.registry.register({name:J.CUT,preconditionFn(t,n){return n=n.focusedNode,(n=!!n&&!t.isReadOnly()&&!t.isDragging()&&!e.t().ephemeralFocusTaken()&&Wi(n)&&Bi(n)&&n.isDeletable())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return r=i.focusedNode,r&&Wi(r)&&Bi(r)&&r.isDeletable()&&zi(r)?(i=Vi(r)?r.getRelativeToSurfaceXY():void 0,i=Ii(r,i),r instanceof gf?(r.checkAndDelete(),n.preventDefault()):Bi(r)&&(e.B(!0),r.dispose(),e.B(!1),t.getAudioManager().play(`delete`),n.preventDefault()),i&&n instanceof KeyboardEvent&&Pc.show(t,{message:e.C.KEYBOARD_NAV_CUT_HINT.replace(`%1`,vn(J.PASTE)),duration:7,id:`cutHint`}),!!i):!1},keyCodes:[t],displayText:()=>e.C.CUT_SHORTCUT})},qi=function(){var t=j.registry.createSerializedKey(U.V,[U.CTRL_CMD]);j.registry.register({name:J.PASTE,preconditionFn(){var t=ef;if(!t||!t.rendered)return!1;var n=t.isFlyout?t.targetWorkspace:t;return(n=!!$d&&!!n&&!n.isReadOnly()&&!n.isDragging()&&!e.t().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(t,n){var r=$d,i=e.t().getFocusedNode();if(!r)return!1;var a=ef;if(!a||(Pc.hide(t,`cutHint`),Pc.hide(t,`copiedHint`),t=a.isFlyout?a.targetWorkspace:a,!t||t.isReadOnly()))return!1;if(n instanceof PointerEvent){var o=ct(t,new N(n.clientX,n.clientY));return!!Li(r,t,o)}if(n=(o=t.getNavigator().getSourceBlockFromNode(i))==null?void 0:o.getRelativeToSurfaceXY())return!!Li(r,t,n);if(o=tf,!o)return!!Li(r,t);var{left:s,top:c,width:l,height:u}=t.getMetricsManager().getViewMetrics(!0);return new P(c,c+u,s,s+l).contains(o.x,o.y)?!!Li(r,t):(o=new N(s+l/2,c+u/2),!!Li(r,t,o))},keyCodes:[t],displayText:()=>e.C.PASTE_SHORTCUT})},Ji=function(){var t=j.registry.createSerializedKey(U.Z,[U.CTRL_CMD]);j.registry.register({name:J.UNDO,preconditionFn(t){return!t.isReadOnly()&&!t.isDragging()&&!e.t().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.undo(),t.preventDefault(),!0},keyCodes:[t],displayText:()=>e.C.UNDO})},Yi=function(){var t=j.registry.createSerializedKey(U.Z,[U.CTRL_CMD,U.SHIFT]),n=j.registry.createSerializedKey(U.Y,[U.CTRL]);j.registry.register({name:J.REDO,preconditionFn(t){return!t.isDragging()&&!t.isReadOnly()&&!e.t().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.redo(),t.preventDefault(),!0},keyCodes:[t,n],displayText:()=>e.C.REDO})},Xi=function(){var t=t=>{var n=e.t().getFocusedNode();return Vi(n)?n:t.getNavigator().getSourceBlockFromNode(e.t().getFocusedNode())??void 0},n=j.registry.createSerializedKey(U.M,[U.SHIFT]),r={name:J.START_MOVE,preconditionFn:e=>(e=t(e),!!e&&G.mover.canMove(e)),callback:(n,r)=>(z.setIsActive(!0),(n=t(n))&&e.t().focusNode(n),!!n&&G.mover.startMove(n,r)),keyCodes:[U.M],displayText:()=>e.C.SHORTCUTS_START_MOVE};n=[r,Object.assign({},r,{name:J.START_MOVE_STACK,keyCodes:[n],displayText:()=>e.C.SHORTCUTS_START_MOVE_STACK}),{name:J.FINISH_MOVE,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>G.mover.finishMove(t),keyCodes:[U.ENTER,U.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_FINISH_MOVE},{name:J.ABORT_MOVE,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>G.mover.abortMove(t),keyCodes:[U.ESC],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_ABORT_MOVE},{name:J.MOVE_LEFT,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.LEFT,t)),keyCodes:[U.LEFT,j.registry.createSerializedKey(U.LEFT,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_LEFT},{name:J.MOVE_RIGHT,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.RIGHT,t)),keyCodes:[U.RIGHT,j.registry.createSerializedKey(U.RIGHT,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_RIGHT},{name:J.MOVE_UP,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.UP,t)),keyCodes:[U.UP,j.registry.createSerializedKey(U.UP,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_UP},{name:J.MOVE_DOWN,preconditionFn:()=>G.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),G.mover.move(bd.DOWN,t)),keyCodes:[U.DOWN,j.registry.createSerializedKey(U.DOWN,[U.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_DOWN}];for(let e of n)j.registry.register(e)},Zi=function(){var t=j.registry.createSerializedKey(U.ENTER,[U.CTRL_CMD]),n=j.registry.createSerializedKey(U.F10,[U.SHIFT]);j.registry.register({name:J.MENU,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{if(z.setIsActive(!0),(t=e.t().getFocusedNode())&&typeof t.showContextMenu==`function`){t.showContextMenu(n);let e;return(e=td)==null||e.highlightNext(),!0}return!1},keyCodes:[t,n,U.CONTEXT_MENU],displayText:()=>e.C.SHORTCUTS_SHOW_CONTEXT_MENU})},Qi=function(){var t={right:{name:J.NAVIGATE_RIGHT,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r,i;return n=t.RTL?(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getOutNode():(i=e.t().getFocusedTree())==null?void 0:i.getNavigator().getInNode(),n?(e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.RIGHT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_RIGHT},left:{name:J.NAVIGATE_LEFT,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r,i;return n=t.RTL?(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getInNode():(i=e.t().getFocusedTree())==null?void 0:i.getNavigator().getOutNode(),n?(e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.LEFT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_LEFT},down:{name:J.NAVIGATE_DOWN,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r;return n=(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getNextNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.DOWN],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_DOWN},up:{name:J.NAVIGATE_UP,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu,callback:(t,n)=>{n.preventDefault(),z.setIsActive(!0);var r;return n=(r=e.t().getFocusedTree())==null?void 0:r.getNavigator().getPreviousNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.t().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)},keyCodes:[U.UP],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_UP}};for(let e of Object.values(t))j.registry.register(e)},$i=function(){j.registry.register({name:J.FOCUS_WORKSPACE,preconditionFn:e=>!e.isDragging(),callback:t=>(z.setIsActive(!0),t=cf(t),e.t().focusNode(t.getWorkspaceFocusTarget()??t),!0),keyCodes:[U.W],displayText:()=>e.C.SHORTCUTS_FOCUS_WORKSPACE})},ea=function(){j.registry.register({name:J.FOCUS_TOOLBOX,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{var r=t.getToolbox();if(r)z.setIsActive(!0),e.t().focusTree(r);else{if(t=t.getFlyout(),!t)return!1;z.setIsActive(!0),e.t().focusTree(t.getWorkspace())}return n.preventDefault(),!0},keyCodes:[U.T],displayText:()=>e.C.SHORTCUTS_FOCUS_TOOLBOX})},ta=function(){j.registry.register({name:J.INFORMATION,preconditionFn:()=>!0,callback:t=>{var n=e.t().getFocusedNode(),r=t.getNavigator().getSourceBlockFromNode(n);if(r)return t=Cn(r,ss.LOQUACIOUS),se(t),!0;if(n===t){n=cf(t),t=n.getTopBlocks().length,n=n.getTopComments().length,r=t===0?`WORKSPACE_CONTENTS_BLOCKS_ZERO`:t===1?`WORKSPACE_CONTENTS_BLOCKS_ONE`:`WORKSPACE_CONTENTS_BLOCKS_MANY`;let i=``;return n>0&&(i=e.C[n===1?`WORKSPACE_CONTENTS_COMMENTS_ONE`:`WORKSPACE_CONTENTS_COMMENTS_MANY`].replace(`%1`,String(n))),t=e.C[r].replace(`%1`,String(t)).replace(`%2`,i),se(t),!0}return!1},keyCodes:[U.I],displayText:()=>e.C.SHORTCUTS_INFORMATION})},na=function(){var t=j.registry.createSerializedKey(U.I,[U.SHIFT]);j.registry.register({name:J.EXTENDED_INFORMATION,preconditionFn:()=>!0,callback:t=>{if(t=t.getNavigator().getSourceBlockFromNode(e.t().getFocusedNode()),!t)return!1;for(var n=[],r=t,i;(i=r.outputConnection)!=null&&i.isConnected();)r=r.getParent();for(r!==t&&n.push(Cn(r,ss.TERSE)),i=r.getParent();i;)n.push(Cn(i,ss.TERSE)),i=i.getParent();if(n.length){n.reverse();let r;(r=t.outputConnection)!=null&&r.isConnected()||n.push(e.C.CURRENT_BLOCK_ANNOUNCEMENT.replace(`%1`,Cn(t,ss.TERSE))),se(e.C.PARENT_BLOCKS_ANNOUNCEMENT.replace(`%1`,n.join(`,`)))}else se(e.C.NO_PARENT_ANNOUNCEMENT);return!0},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_EXTENDED_INFORMATION})},ra=function(){var t=j.registry.createSerializedKey(U.X,[U.SHIFT]);j.registry.register({name:J.DISCONNECT,preconditionFn:(e,t)=>(t=t.focusedNode,(t=!e.isDragging()&&!e.isReadOnly()&&t instanceof gf&&!t.isShadow())||e.getAudioManager().playErrorBeep(),t),callback:(t,n)=>(z.setIsActive(!0),t=e.t().getFocusedNode(),t instanceof gf&&(n=!(n instanceof KeyboardEvent&&n.shiftKey),e.B(!0),t.unplug(n),e.B(!1),!0)),keyCodes:[U.X,t],displayText:()=>e.C.SHORTCUTS_DISCONNECT})},ia=function(){var t=(t,n=e.t().getFocusedNode())=>{var r=t.getNavigator();for(let e=n;e&&e!==t;e=r.getParent(e))n=e;return ve(n)?n:null},n={name:J.PREVIOUS_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!xu&&!Gu,callback:n=>{z.setIsActive(!0);var r=t(n);return!r||(n=t(n,n.getNavigator().navigateStacks(r,-1)),!n)?!1:(e.t().focusNode(n),!0)},keyCodes:[U.B],displayText:()=>e.C.SHORTCUTS_PREVIOUS_STACK};j.registry.register({name:J.NEXT_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!xu&&!Gu,callback:n=>{z.setIsActive(!0);var r=t(n);return!r||(n=n.getNavigator().navigateStacks(r,1),!n)?!1:(e.t().focusNode(n),!0)},keyCodes:[U.N],displayText:()=>e.C.SHORTCUTS_NEXT_STACK}),j.registry.register(n)},aa=function(){var t=()=>{var t=e.t().getFocusedTree();return t instanceof Mp&&t.isFlyout&&t.targetWorkspace?t.targetWorkspace.getFlyout()??null:null},n=t=>{var n=t.getWorkspace().getNavigator();t=t.getContents().map(e=>e.getElement());for(var r=e.t().getFocusedNode()??null;r&&!t.includes(r);)r=n.getParent(r);return r},r=(e,t)=>{var r=e.getContents().map(e=>e.getElement());e=(e=n(e))?r.indexOf(e):t===1?-1:r.length;for(let n=1;n<=r.length;n++){var i=e+t*n;if(i<0||i>=r.length)break;if(i=r[i],i instanceof af&&i.isLabel())return i}return null},i=j.registry.createSerializedKey(U.H,[U.SHIFT]);i={name:J.PREVIOUS_HEADING,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,-1),!n)?!1:(z.setIsActive(!0),e.t().focusNode(n),!0)},keyCodes:[i],displayText:()=>e.C.SHORTCUTS_PREVIOUS_HEADING},j.registry.register({name:J.NEXT_HEADING,preconditionFn:e=>!e.isDragging()&&!xu&&!Gu&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,1),!n)?!1:(z.setIsActive(!0),e.t().focusNode(n),!0)},keyCodes:[U.H],displayText:()=>e.C.SHORTCUTS_NEXT_HEADING}),j.registry.register(i)},oa=function(){j.registry.register({name:J.PERFORM_ACTION,preconditionFn:t=>!t.isDragging()&&!xu&&!Gu&&!e.t().ephemeralFocusTaken(),callback:(t,n)=>{if(z.setIsActive(!0),(t=e.t().getFocusedNode())&&`performAction`in t){n.preventDefault();let e;return(e=t.performAction)==null||e.call(t,n),!0}return!1},keyCodes:[U.ENTER,U.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_PERFORM_ACTION})},sa=function(){j.registry.register({name:J.DUPLICATE,preconditionFn:(e,t)=>({focusedNode:t}=t,(t=!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout&&(t instanceof gf?t.isDuplicatable():!0))||e.getAudioManager().playErrorBeep(),t),callback:(e,t,n,r)=>(z.setIsActive(!0),t=zi(r.focusedNode)&&r.focusedNode,(t&&=t.toCopyData())?!!Li(t,e):!1),keyCodes:[U.D],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_DUPLICATE})},ca=function(){j.registry.register({name:J.CLEANUP,preconditionFn:e=>!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout,callback:e=>(z.setIsActive(!0),e.cleanUp(),!0),keyCodes:[U.C],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_CLEANUP})},la=function(){var t=j.registry.createSerializedKey(U.J,[U.CTRL_CMD]);j.registry.register({name:J.SHOW_TOOLTIP,preconditionFn:e=>!e.isDragging(),callback:t=>{var n=e.t().getFocusedNode();return n!==null&&(z.setIsActive(!0),vr(n,t)),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_SHOW_TOOLTIP})},ua=function(){var t=j.registry.createSerializedKey(U.A,[U.ALT,U.SHIFT]),n=!1;j.registry.register({name:J.TOGGLE_SCREENREADER,preconditionFn:()=>!0,callback:(t,r)=>{n=!n,z.setScopeChangeAudioCuesEnabled(n),t.getNavigator().setNavigationLoops(!n);var i;(i=t.getToolbox())==null||i.getNavigator().setNavigationLoops(!n);var a;return(a=t.getFlyout())==null||a.getWorkspace().getNavigator().setNavigationLoops(!n),Pc.show(t,{message:(n?e.C.SCREENREADER_MODE_ENABLED:e.C.SCREENREADER_MODE_DISABLED).replace(`%1`,vn(J.TOGGLE_SCREENREADER)),duration:7,id:`screenreaderHint`}),r.preventDefault(),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_TOGGLE_SCREENREADER_MODE})},da=function(){j.registry.register({name:J.JUMP_BLOCK_START,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode)return!1;t=t.getNavigator().getSourceBlockFromNode(i.focusedNode);var a;return(a=t)!=null&&a.getFullBlockField()&&t.getParent()&&(t=t.getParent()),t?(e.t().focusNode(t),!0):!1},keyCodes:[U.HOME],displayText:()=>e.C.SHORTCUTS_JUMP_BLOCK_START})},fa=function(){j.registry.register({name:J.JUMP_BLOCK_END,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode)return!1;t=t.getNavigator().getSourceBlockFromNode(i.focusedNode);var a;return(a=t)!=null&&a.getFullBlockField()&&t.getParent()&&(t=t.getParent()),!t||(a=t.inputList,!a.length)||(a=a[a.length-1].connection,!(a&&a instanceof Bd))?!1:(e.t().focusNode(a),!0)},keyCodes:[U.END],displayText:()=>e.C.SHORTCUTS_JUMP_BLOCK_END})},pa=function(){j.registry.register({name:J.JUMP_TOP_STACK,preconditionFn:lf,callback(t,n,r,i){return!i.focusedNode||(t=t.getNavigator().getSourceBlockFromNode(i.focusedNode),!t)?!1:(t=t.getRootBlock(),e.t().focusNode(t),!0)},keyCodes:[U.PAGE_UP],displayText:()=>e.C.SHORTCUTS_JUMP_TOP_STACK})},ma=function(){j.registry.register({name:J.JUMP_BOTTOM_STACK,preconditionFn:lf,callback(t,n,r,i){if(!i.focusedNode||(t=t.getNavigator().getSourceBlockFromNode(i.focusedNode),!t))return!1;var a;return t=(a=t.getRootBlock().lastConnectionInStack(!1))==null?void 0:a.getSourceBlock(),t?(a=t.getDescendants(!0),a=a[a.length-1],e.t().focusNode(a),!0):!1},keyCodes:[U.PAGE_DOWN],displayText:()=>e.C.SHORTCUTS_JUMP_BOTTOM_STACK})},ha=function(){var t=j.registry.createSerializedKey(U.HOME,[U.CTRL_CMD]);j.registry.register({name:J.JUMP_FIRST_BLOCK,preconditionFn:t=>!t.isDragging()&&!e.t().ephemeralFocusTaken(),callback(t){return t=t.getTopBlocks(!0),t.length?(e.t().focusNode(t[0]),!0):!1},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_JUMP_FIRST_BLOCK})},ga=function(){var t=j.registry.createSerializedKey(U.END,[U.CTRL_CMD]);j.registry.register({name:J.JUMP_LAST_BLOCK,preconditionFn:t=>!t.isDragging()&&!e.t().ephemeralFocusTaken(),callback(t){return t=t.getAllBlocks(!0),t.length?(e.t().focusNode(t[t.length-1]),!0):!1},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_JUMP_LAST_BLOCK})},_a=function(){Hi(),Ui(),Gi(),Ki(),qi(),Ji(),Yi()},va=function(){Zi(),Xi(),$i(),ea(),Qi(),ra(),ia(),aa(),oa(),sa(),ca(),la()},ya=function(){ta(),na(),ua()},ba=function(t,n=!1){var r=e.C.KEYBOARD_NAV_UNCONSTRAINED_MOVE_HINT.replace(`%1`,zo||Lo||Ro?e.C.COMMAND_KEY:e.C.CONTROL_KEY).replace(`%2`,e.C.ENTER_KEY);Pc.show(t,{message:r,id:`unconstrainedMoveHint`,oncePerSession:!n})},xa=function(t){var n=e.C.KEYBOARD_NAV_CONSTRAINED_MOVE_HINT.replace(`%1`,e.C.ENTER_KEY);Pc.show(t,{message:n,id:`constrainedMoveHint`,oncePerSession:!0})},Sa=function(e){var t=[];for(var n of e.getIcons()){if(e.isCollapsed()&&!n.isShownWhenCollapsed())continue;t.push(n);let r;Wt(n)&&n.bubbleIsVisible()&&(r=n.getBubble())&&t.push(r)}for(let r of e.inputList)r.isVisible()&&(t.push(...r.fieldRow),n=r.connection,n&&(t.push(n),n=n.targetBlock(),n&&(t.push(n),(n=n.lastConnectionInStack(!1))&&t.push(n))));return e.nextConnection&&!e.isCollapsed()&&t.push(e.nextConnection),t},Ca=function(e,t,n){return e=Sa(e),t=e.indexOf(t),t===-1?null:(n=t+n,n>=0&&n<e.length?e[n]:null)},wa=function(e){return e&&typeof e.getChildToolboxItems==`function`&&typeof e.isExpanded==`function`&&typeof e.toggleExpanded==`function`&&Sn(e)&&e.isCollapsible()},Ta=function(e){var t=e.options.toolboxPosition;return e.options.RTL&&t!==I.TOP&&t!==I.BOTTOM?t===I.LEFT?I.RIGHT:I.LEFT:t},Ea=function(e,t){y(M.ICON,e.toString(),t)},Da=function(e){return typeof e.getProcedureModel==`function`&&typeof e.doProcedureUpdate==`function`&&typeof e.isProcedureDef==`function`},Oa=function(e){return e&&typeof e.startPublishing==`function`&&typeof e.stopPublishing==`function`},ka=function(e){var t=e.getProcedureMap().getProcedures().filter(e=>!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!1]);e.getBlocksByType(`procedures_defnoreturn`,!1).forEach(e=>{!Da(e)&&Kt(e)&&t.push(e.getProcedureDef())});var n=e.getProcedureMap().getProcedures().filter(e=>!!e.getReturnTypes()).map(e=>[e.getName(),e.getParameters().map(e=>e.getName()),!0]);return e.getBlocksByType(`procedures_defreturn`,!1).forEach(e=>{!Da(e)&&Kt(e)&&n.push(e.getProcedureDef())}),t.sort(Aa),n.sort(Aa),[t,n]},Aa=function(e,t){return e[0].localeCompare(t[0],void 0,{sensitivity:`base`})},e.jj=function(t,n){if(n.isInFlyout)return t;for(t=t||e.C.UNNAMED_KEY||`unnamed`;ja(t,n.workspace,n);){let e=t.match(/^(.*?)(\d+)$/);t=e?e[1]+(parseInt(e[2])+1):t+`2`}return t},ja=function(t,n,r){for(let i of n.getAllBlocks(!1))if(i!==r&&Kt(i)&&e.kj.equals(i.getProcedureDef()[0],t))return!0;r=r&&Da(r)?r==null?void 0:r.getProcedureModel():void 0;for(let i of n.getProcedureMap().getProcedures())if(i!==r&&e.kj.equals(i.getName(),t))return!0;return!1},e.mj=function(t){var n=this.getSourceBlock();if(!n)throw new Wu;t=t.trim();var r=e.jj(t,n);Da(n)&&!n.isInsertionMarker()&&n.getProcedureModel().setName(r);var i=this.getValue();if(i!==t&&i!==r)for(t=n.workspace.getAllBlocks(!1),n=0;n<t.length;n++){let e=t[n];e.renameProcedure&&e.renameProcedure(i,r)}return r},Ma=function(t){function n(e,t){for(let[n,i]of e)r.push({kind:`block`,type:t,gap:16,extraState:{name:n,params:i}})}var r=[];return $o.procedures_defnoreturn&&r.push({kind:`block`,type:`procedures_defnoreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFNORETURN_PROCEDURE}}),$o.procedures_defreturn&&r.push({kind:`block`,type:`procedures_defreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFRETURN_PROCEDURE}}),$o.procedures_ifreturn&&r.push({kind:`block`,type:`procedures_ifreturn`,gap:16}),r.length&&(r[r.length-1].gap=24),t=ka(t),n(t[0],`procedures_callnoreturn`),n(t[1],`procedures_callreturn`),r},Na=function(t){var n=[],r=t.getBlocksByType(`procedures_mutatorarg`,!1);for(let e=0,t;t=r[e];e++)n.push(t.getFieldValue(`NAME`));r=e.rc(`xml`);var i=e.rc(`block`);i.setAttribute(`type`,`procedures_mutatorarg`);var a=e.rc(`field`);a.setAttribute(`name`,`NAME`),n=Qt(`x`,n),n=e.sc(n),a.appendChild(n),i.appendChild(a),r.appendChild(i),t.updateToolbox(r)},Pa=function(t){if(t.type===E.BUBBLE_OPEN&&t.bubbleType===`mutator`&&t.isOpen&&t.blockId){t=xe(t.workspaceId).getBlockById(t.blockId);var n=t.type;(n===`procedures_defnoreturn`||n===`procedures_defreturn`)&&(t=t.getIcon(e.sh.TYPE).getWorkspace(),Na(t),t.addChangeListener(Fa))}},Fa=function(e){(e.type===E.BLOCK_CREATE||e.type===E.BLOCK_DELETE||e.type===E.BLOCK_CHANGE||e.type===E.BLOCK_FIELD_INTERMEDIATE_CHANGE)&&(e=xe(e.workspaceId),Na(e))},Ia=function(t,n){return n.getAllBlocks(!1).filter(n=>Da(n)&&!n.isProcedureDef()&&n.getProcedureModel()&&e.kj.equals(n.getProcedureModel().getName(),t)||n&&typeof n.getProcedureCall==`function`&&typeof n.renameProcedure==`function`&&e.kj.equals(n.getProcedureCall(),t))},e.sj=function(t){var n=e.Qc,r=t.getProcedureDef()[0],i=t.mutationToDom(!0);t=Ia(r,t.workspace);for(let o=0,s;s=t[o];o++){r=(r=s.mutationToDom())&&ut(r),s.domToMutation&&s.domToMutation(i);var a=s.mutationToDom();a&&=ut(a),r!==a&&(e.Qc=!1,b(new(x(E.BLOCK_CHANGE))(s,`mutation`,null,r,a)),e.Qc=n)}},e.tj=function(t,n){for(let r of n.getAllBlocks(!1))if(Da(r)&&r.isProcedureDef()&&e.kj.equals(r.getProcedureModel().getName(),t)||Kt(r)&&e.kj.equals(r.getProcedureDef()[0],t))return r;return null},La=function(e,t){y(M.RENDERER,e,t)},Ra=function(e,t,n){return e=new(Le(M.RENDERER,e,void 0))(e),e.init(t,n),e},za=function(e){$t(e.getTargetWorkspace(),void 0,`String`)},Ba=function(e){$t(e.getTargetWorkspace(),void 0,`Number`)},Va=function(e){$t(e.getTargetWorkspace(),void 0,`Colour`)},Ha=function(t){return $o.variables_set_dynamic||$o.variables_get_dynamic||console.warn(`There are no dynamic variable blocks, but there is a dynamic variable category.`),t.registerButtonCallback(`CREATE_VARIABLE_STRING`,za),t.registerButtonCallback(`CREATE_VARIABLE_NUMBER`,Ba),t.registerButtonCallback(`CREATE_VARIABLE_COLOUR`,Va),[{kind:`button`,text:e.C.NEW_STRING_VARIABLE,callbackkey:`CREATE_VARIABLE_STRING`},{kind:`button`,text:e.C.NEW_NUMBER_VARIABLE,callbackkey:`CREATE_VARIABLE_NUMBER`},{kind:`button`,text:e.C.NEW_COLOUR_VARIABLE,callbackkey:`CREATE_VARIABLE_COLOUR`},...Xt(t,t.getVariableMap().getAllVariables(),!1,`variables_get_dynamic`,`variables_set_dynamic`)]},Ua=function(e){var t=e.saveState();return e.getParameters().length&&(t.parameters=e.getParameters().map(e=>e.saveState())),t},Wa=function(e,t,n,r){if(e=e.loadState(n,r),!n.parameters)return e;for(let[i,a]of n.parameters.entries())e.insertParameter(t.loadState(a,r),i);return e},Ga=function(e,t){e.setAttribute(`dir`,`LTR`),ne(e,t.hasCss,t.pathToMedia);var n=h(A.SVG,{xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`,class:`blocklySvg`},e),r=h(A.DEFS,{},n),i=String(Math.random()).substring(2);return t.gridPattern=Gf.createDom(i,t.gridOptions,r,e),n},Ka=function(e,t,n){n.parentWorkspace=null,n=new Mp(n);var r=n.options;n.scale=r.zoomOptions.startScale,t.appendChild(n.createDom(`blocklyMainBackground`,e));var i=n.getRenderer().getClassName();return i&&g(e,i),(i=n.getTheme().getClassName())&&g(e,i),!r.hasCategories&&r.languageTree&&(i=n.addFlyout(A.SVG),e.insertBefore(i,t)),r.hasTrashcan&&n.addTrashcan(),r.zoomOptions&&r.zoomOptions.controls&&n.addZoomControls(),n.getThemeManager().subscribe(t,`workspaceBackgroundColour`,`background-color`),n.translate(0,0),n.addChangeListener(Pi(n)),je(n),Mr(),Bn(),ur(),n},qa=function(e){var t=e.options,n=e.getParentSvg();if(o(n.parentNode,`contextmenu`,null,function(e){l(e)||e.preventDefault()}),n=o(window,`resize`,null,function(){_r(),e.hideComponents(!0),nr(),zr(),je(e),Fi(e)}),e.setResizeHandlerWrapper(n),Ja(),t.languageTree){n=e.getToolbox();let r=e.getFlyout(!0);n?n.init():r&&(r.init(e),r.show(t.languageTree),typeof r.scrollToStart==`function`&&r.scrollToStart())}t.hasTrashcan&&e.trashcan.init(),t.zoomOptions&&t.zoomOptions.controls&&e.zoomControls_.init(),t.moveOptions&&t.moveOptions.scrollbars?(e.scrollbar=new Bf(e,t.moveOptions.scrollbars===!0||!!t.moveOptions.scrollbars.horizontal,t.moveOptions.scrollbars===!0||!!t.moveOptions.scrollbars.vertical,`blocklyMainWorkspaceScrollbar`),e.scrollbar.resize()):e.setMetrics({x:.5,y:.5}),t.hasSounds&&Ya(t.pathToMedia,e)},Ja=function(){pm||(o(document,`scroll`,null,function(){var e=Se();for(let t=0,n;n=e[t];t++)n instanceof Mp&&n.updateInverseScreenCTM()}),s(document,`touchend`,null,n),s(document,`touchcancel`,null,n),s(document,`keydown`,null,function(e){e.key===`Tab`&&z.setIsActive(!0)})),pm=!0},Ya=function(e,t){t=t.getAudioManager(),t.load([`${e}click.mp3`],`click`),t.load([`${e}disconnect.mp3`],`disconnect`),t.load([`${e}delete.mp3`],`delete`),t.load([`${e}drop.mp3`],`drop`)},Xa=function(){H.registry.register({displayText(){return e.C.UNDO},preconditionFn(e){return e.workspace.getUndoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.undo()},scopeType:H.ScopeType.WORKSPACE,id:`undoWorkspace`,weight:1,associatedKeyboardShortcut:`undo`})},Za=function(){H.registry.register({displayText(){return e.C.REDO},preconditionFn(e){return e.workspace.getRedoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.redo()},scopeType:H.ScopeType.WORKSPACE,id:`redoWorkspace`,weight:2,associatedKeyboardShortcut:`redo`})},Qa=function(){H.registry.register({displayText(){return e.C.CLEAN_UP},preconditionFn(e){return e.workspace.isMovable()?e.workspace.getTopBlocks(!1).length>1?`enabled`:`disabled`:`hidden`},callback(e){e.workspace.cleanUp()},scopeType:H.ScopeType.WORKSPACE,id:`cleanWorkspace`,weight:3,associatedKeyboardShortcut:`cleanup`})},$a=function(t,n){function r(n){a--,n.setCollapsed(t),a===0&&e.B(!1)}var i=0,a=0;e.B(!0);for(let e=0;e<n.length;e++){let t=n[e];for(;t;)a++,setTimeout(r.bind(null,t),i),t=t.getNextBlock(),i+=10}},eo=function(){H.registry.register({displayText(){return e.C.COLLAPSE_ALL},preconditionFn(e){if(e.workspace.options.collapse){e=e.workspace.getTopBlocks(!1);for(let t=0;t<e.length;t++){let n=e[t];for(;n;){if(!n.isCollapsed())return`enabled`;n=n.getNextBlock()}}return`disabled`}return`hidden`},callback(e){$a(!0,e.workspace.getTopBlocks(!0))},scopeType:H.ScopeType.WORKSPACE,id:`collapseWorkspace`,weight:4})},to=function(){H.registry.register({displayText(){return e.C.EXPAND_ALL},preconditionFn(e){if(e.workspace.options.collapse){e=e.workspace.getTopBlocks(!1);for(let t=0;t<e.length;t++){let n=e[t];for(;n;){if(n.isCollapsed())return`enabled`;n=n.getNextBlock()}}return`disabled`}return`hidden`},callback(e){$a(!1,e.workspace.getTopBlocks(!0))},scopeType:H.ScopeType.WORKSPACE,id:`expandWorkspace`,weight:5})},no=function(e,t){if(e.isDeletable())Array.prototype.push.apply(t,e.getDescendants(!1));else{e=e.getChildren(!1);for(let n=0;n<e.length;n++)no(e[n],t)}},ro=function(e){var t=[];e=e.getTopBlocks(!0);for(let n=0;n<e.length;n++)no(e[n],t);return t},io=function(t,n){n?e.B(n):(e.B(!0),n=e.gd);var r=t.shift();r&&(r.isDeadOrDying()?io(t,n):(r.dispose(!1,!0),setTimeout(io,10,t,n))),e.B(!1)},ao=function(){H.registry.register({displayText(t){return t.workspace?(t=ro(t.workspace).length,t===1?e.C.DELETE_BLOCK:e.C.DELETE_X_BLOCKS.replace(`%1`,`${t}`)):``},preconditionFn(e){return e.workspace&&ro(e.workspace).length>0?`enabled`:`disabled`},callback(t){if(t.workspace){t.workspace.cancelCurrentGesture();var n=ro(t.workspace);n.length<2?io(n):Vt(e.C.DELETE_ALL_BLOCKS.replace(`%1`,String(n.length)),function(e){e&&io(n)})}},scopeType:H.ScopeType.WORKSPACE,id:`workspaceDelete`,weight:6})},oo=function(){H.registry.register({displayText(){return e.C.DUPLICATE_BLOCK},preconditionFn(e){return e=e.block,!e.isInFlyout&&e.isDeletable()&&e.isMovable()?e.isDuplicatable()?`enabled`:`disabled`:`hidden`},callback(e){if(e.block){var t=e.block.toCopyData();t&&Li(t,e.block.workspace)}},scopeType:H.ScopeType.BLOCK,id:`blockDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},so=function(){H.registry.register({displayText(t){return t.block.hasIcon(Jf.TYPE)?e.C.REMOVE_COMMENT:e.C.ADD_COMMENT},preconditionFn(e){e=e.block;var t;if((t=e&&!e.isInFlyout&&e.workspace.options.comments&&!e.isCollapsed()&&e.isEditable())&&!(t=e.hasIcon(Jf.TYPE))){if(e&&e.isSimpleReporter()){var n;e=(n=e.getFields().next().value)==null?void 0:n.isFullBlockField()}else e=!1;t=!e}return t?`enabled`:`hidden`},callback(e){(e=e.block)&&e.hasIcon(Jf.TYPE)?e.setCommentText(null):e.setCommentText(``)},scopeType:H.ScopeType.BLOCK,id:`blockComment`,weight:2})},co=function(){H.registry.register({displayText(t){return t.block.getInputsInline()?e.C.EXTERNAL_INPUTS:e.C.INLINE_INPUTS},preconditionFn(e){if(e=e.block,!e.isInFlyout&&e.isMovable()&&!e.isCollapsed()){for(let t=1;t<e.inputList.length;t++)if(!(e.inputList[t-1]instanceof am||e.inputList[t]instanceof am))return`enabled`}return`hidden`},callback(e){e.block.setInputsInline(!e.block.getInputsInline())},scopeType:H.ScopeType.BLOCK,id:`blockInline`,weight:3})},lo=function(){H.registry.register({displayText(t){return t.block.isCollapsed()?e.C.EXPAND_BLOCK:e.C.COLLAPSE_BLOCK},preconditionFn(e){return e=e.block,!e.isInFlyout&&e.isMovable()&&e.workspace.options.collapse?`enabled`:`hidden`},callback(e){e.block.setCollapsed(!e.block.isCollapsed())},scopeType:H.ScopeType.BLOCK,id:`blockCollapseExpand`,weight:4})},uo=function(){H.registry.register({displayText(t){return t.block.hasDisabledReason(`MANUALLY_DISABLED`)?e.C.ENABLE_BLOCK:e.C.DISABLE_BLOCK},preconditionFn(e){if(e=e.block,!e.isInFlyout&&e.workspace.options.disable&&e.isEditable()){var t=e.getDisabledReasons();return t=t.size>+!!t.has(`MANUALLY_DISABLED`),e.getInheritedDisabled()||t?`disabled`:`enabled`}return`hidden`},callback(t){t=t.block;var n=e.gd;n||e.B(!0),t.setDisabledReason(!t.hasDisabledReason(`MANUALLY_DISABLED`),`MANUALLY_DISABLED`),e.B(n)},scopeType:H.ScopeType.BLOCK,id:`blockDisable`,weight:5})},fo=function(){H.registry.register({displayText(t){var n=t.block;return t=n.getDescendants(!1).length,(n=n.getNextBlock())&&(t-=n.getDescendants(!1).length),t===1?e.C.DELETE_BLOCK:e.C.DELETE_X_BLOCKS.replace(`%1`,`${t}`)},preconditionFn(e){return!e.block.isInFlyout&&e.block.isDeletable()?`enabled`:`hidden`},callback(t){t.block&&(e.t().focusNode(t.block),t.block.checkAndDelete())},scopeType:H.ScopeType.BLOCK,id:`blockDelete`,weight:6,associatedKeyboardShortcut:`delete`})},po=function(){H.registry.register({displayText(){return e.C.HELP},preconditionFn(e){return e=e.block,(typeof e.helpUrl==`function`?e.helpUrl():e.helpUrl)?`enabled`:`hidden`},callback(e){e.block.showHelp()},scopeType:H.ScopeType.BLOCK,id:`blockHelp`,weight:7})},mo=function(){H.registry.register({displayText:()=>e.C.REMOVE_COMMENT,preconditionFn(e){var t;return(t=e.comment)!=null&&t.isDeletable()?`enabled`:`hidden`},callback(t){e.B(!0);var n;(n=t.comment)==null||n.dispose(),e.B(!1);var r;(r=t.comment)==null||r.workspace.getAudioManager().play(`delete`)},scopeType:H.ScopeType.COMMENT,id:`commentDelete`,weight:6,associatedKeyboardShortcut:`delete`})},ho=function(){H.registry.register({displayText:()=>e.C.DUPLICATE_COMMENT,preconditionFn(e){var t;return(t=e.comment)!=null&&t.isMovable()?`enabled`:`hidden`},callback(e){if(e.comment){var t=e.comment.toCopyData();t&&Li(t,e.comment.workspace)}},scopeType:H.ScopeType.COMMENT,id:`commentDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},go=function(){H.registry.register({displayText:()=>e.C.ADD_COMMENT,preconditionFn:e=>{var t;return(t=e.workspace)!=null&&t.isMutator?`hidden`:`enabled`},callback:(t,n,r,i)=>{(t=t.workspace)&&(e.B(!0),n=new md(t),n.moveTo(ct(t,new N(i.x,i.y))),e.t().focusNode(n),e.B(!1))},scopeType:H.ScopeType.WORKSPACE,id:`commentCreate`,weight:8})},_o=function(){Xa(),Za(),Qa(),eo(),to(),ao(),oo(),so(),co(),lo(),uo(),fo(),po()},w||={},w.scope={},w.ASSUME_ES2020=!1,w.ASSUME_ES6=w.ASSUME_ES2020,w.ASSUME_ES5=w.ASSUME_ES6,w.ASSUME_NO_NATIVE_MAP=!1,w.ASSUME_NO_NATIVE_SET=!1,w.ISOLATE_POLYFILLS=!1,w.FORCE_POLYFILL_PROMISE=!1,w.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1,w.INSTRUMENT_ASYNC_CONTEXT=!0,w.objectCreate=w.ASSUME_ES5||typeof Object.create==`function`?Object.create:function(e){function t(){}return t.prototype=e,new t},w.defineProperty=w.ASSUME_ES5||typeof Object.defineProperties==`function`?Object.defineProperty:function(e,t,n){return e==Array.prototype||e==Object.prototype||(e[t]=n.value),e},w.getGlobal=function(e){e=[typeof globalThis==`object`&&globalThis,e,typeof window==`object`&&window,typeof self==`object`&&self,typeof global==`object`&&global];for(var t=0;t<e.length;++t){var n=e[t];if(n&&n.Math==Math)return n}throw Error(`Cannot find global object`)},w.global=w.ASSUME_ES2020?globalThis:w.getGlobal(this),w.IS_SYMBOL_NATIVE=typeof Symbol==`function`&&typeof Symbol(`x`)==`symbol`,w.TRUST_ES6_POLYFILLS=!w.ISOLATE_POLYFILLS||w.IS_SYMBOL_NATIVE,w.polyfills={},w.propertyToPolyfillSymbol={},w.POLYFILL_PREFIX=`$jscp$`;var vo=`Int8 Uint8 Uint8Clamped Int16 Uint16 Int32 Uint32 Float32 Float64`.split(` `);w.global.BigInt64Array&&(vo.push(`BigInt64`),vo.push(`BigUint64`)),w.TYPED_ARRAY_CLASSES=vo,w.polyfillTypedArrayMethod=function(e,t,n,r){if(t)for(var i=0;i<w.TYPED_ARRAY_CLASSES.length;i++){var a=w.TYPED_ARRAY_CLASSES[i]+`Array.prototype.`+e;w.ISOLATE_POLYFILLS?w.polyfillIsolated(a,t,n,r):w.polyfillUnisolated(a,t,n,r)}},w.polyfill=function(e,t,n,r){t&&(w.ISOLATE_POLYFILLS?w.polyfillIsolated(e,t,n,r):w.polyfillUnisolated(e,t,n,r))},w.polyfillUnisolated=function(e,t){var n=w.global;e=e.split(`.`);for(var r=0;r<e.length-1;r++){var i=e[r];if(!(i in n))return;n=n[i]}e=e[e.length-1],r=n[e],t=t(r),t!=r&&t!=null&&w.defineProperty(n,e,{configurable:!0,writable:!0,value:t})},w.polyfillIsolated=function(e,t,n){var r=e.split(`.`);e=r.length===1;var i=r[0];i=!e&&i in w.polyfills?w.polyfills:w.global;for(var a=0;a<r.length-1;a++){var o=r[a];if(!(o in i))return;i=i[o]}r=r[r.length-1],n=w.IS_SYMBOL_NATIVE&&n===`es6`?i[r]:null,t=t(n),t!=null&&(e?w.defineProperty(w.polyfills,r,{configurable:!0,writable:!0,value:t}):t!==n&&(w.propertyToPolyfillSymbol[r]===void 0&&(e=Math.random()*1e9>>>0,w.propertyToPolyfillSymbol[r]=w.IS_SYMBOL_NATIVE?w.global.Symbol(r):w.POLYFILL_PREFIX+e+`$`+r),w.defineProperty(i,w.propertyToPolyfillSymbol[r],{configurable:!0,writable:!0,value:t})))},w.getConstructImplementation=function(){function e(){function e(){}return new e,Reflect.construct(e,[],function(){}),new e instanceof e}if(w.TRUST_ES6_POLYFILLS&&typeof Reflect<`u`&&Reflect.construct){if(e())return Reflect.construct;var t=Reflect.construct;return function(e,n,r){return e=t(e,n),r&&Reflect.setPrototypeOf(e,r.prototype),e}}return function(e,t,n){return n===void 0&&(n=e),n=w.objectCreate(n.prototype||Object.prototype),Function.prototype.apply.call(e,n,t)||n}},w.construct={valueOf:w.getConstructImplementation}.valueOf(),w.underscoreProtoCanBeSet=function(){var e={a:!0},t={};try{return t.__proto__=e,t.a}catch{}return!1},w.setPrototypeOf=w.ASSUME_ES6||w.TRUST_ES6_POLYFILLS&&typeof Object.setPrototypeOf==`function`?Object.setPrototypeOf:w.underscoreProtoCanBeSet()?function(e,t){if(e.__proto__=t,e.__proto__!==t)throw TypeError(e+` is not extensible`);return e}:null,w.inherits=function(e,t){if(e.prototype=w.objectCreate(t.prototype),e.prototype.constructor=e,w.ASSUME_ES6||w.setPrototypeOf){var n=w.setPrototypeOf;n(e,t)}else for(n in t)if(n!=`prototype`){if(Object.defineProperties){var r=Object.getOwnPropertyDescriptor(t,n);r&&Object.defineProperty(e,n,r)}else e[n]=t[n]}e.superClass_=t.prototype},w.arrayIteratorImpl=function(e){var t=0;return function(){return t<e.length?{done:!1,value:e[t++]}:{done:!0}}},w.arrayIterator=function(e){return{next:w.arrayIteratorImpl(e)}},w.makeIterator=function(e){var t=typeof Symbol<`u`&&Symbol.iterator&&e[Symbol.iterator];if(t)return t.call(e);if(typeof e.length==`number`)return w.arrayIterator(e);throw Error(String(e)+` is not an iterable or ArrayLike`)},w.arrayFromIterator=function(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n},w.arrayFromIterable=function(e){return e instanceof Array?e:w.arrayFromIterator(w.makeIterator(e))},w.generator={},w.generator.ensureIteratorResultIsObject_=function(e){if(!(e instanceof Object))throw TypeError(`Iterator result `+e+` is not an object`)},w.generator.Context=function(){this.isRunning_=!1,this.yieldAllIterator_=null,this.yieldResult=void 0,this.nextAddress=1,this.finallyAddress_=this.catchAddress_=0,this.finallyContexts_=this.abruptCompletion_=null},w.generator.Context.prototype.start_=function(){if(this.isRunning_)throw TypeError(`Generator is already running`);this.isRunning_=!0},w.generator.Context.prototype.stop_=function(){this.isRunning_=!1},w.generator.Context.prototype.jumpToErrorHandler_=function(){this.nextAddress=this.catchAddress_||this.finallyAddress_},w.generator.Context.prototype.next_=function(e){this.yieldResult=e},w.generator.Context.prototype.throw_=function(e){this.abruptCompletion_={exception:e,isException:!0},this.jumpToErrorHandler_()},w.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},w.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},w.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},w.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},w.generator.Context.prototype.return=function(e){this.abruptCompletion_={return:e},this.nextAddress=this.finallyAddress_},w.generator.Context.prototype.return=w.generator.Context.prototype.return,w.generator.Context.prototype.jumpThroughFinallyBlocks=function(e){this.abruptCompletion_={jumpTo:e},this.nextAddress=this.finallyAddress_},w.generator.Context.prototype.jumpThroughFinallyBlocks=w.generator.Context.prototype.jumpThroughFinallyBlocks,w.generator.Context.prototype.yield=function(e,t){return this.nextAddress=t,{value:e}},w.generator.Context.prototype.yield=w.generator.Context.prototype.yield,w.generator.Context.prototype.yieldAll=function(e,t){e=w.makeIterator(e);var n=e.next();if(w.generator.ensureIteratorResultIsObject_(n),n.done)this.yieldResult=n.value,this.nextAddress=t;else return this.yieldAllIterator_=e,this.yield(n.value,t)},w.generator.Context.prototype.yieldAll=w.generator.Context.prototype.yieldAll,w.generator.Context.prototype.jumpTo=function(e){this.nextAddress=e},w.generator.Context.prototype.jumpTo=w.generator.Context.prototype.jumpTo,w.generator.Context.prototype.jumpToEnd=function(){this.nextAddress=0},w.generator.Context.prototype.jumpToEnd=w.generator.Context.prototype.jumpToEnd,w.generator.Context.prototype.setCatchFinallyBlocks=function(e,t){this.catchAddress_=e,t!=null&&(this.finallyAddress_=t)},w.generator.Context.prototype.setCatchFinallyBlocks=w.generator.Context.prototype.setCatchFinallyBlocks,w.generator.Context.prototype.setFinallyBlock=function(e){this.catchAddress_=0,this.finallyAddress_=e||0},w.generator.Context.prototype.setFinallyBlock=w.generator.Context.prototype.setFinallyBlock,w.generator.Context.prototype.leaveTryBlock=function(e,t){this.nextAddress=e,this.catchAddress_=t||0},w.generator.Context.prototype.leaveTryBlock=w.generator.Context.prototype.leaveTryBlock,w.generator.Context.prototype.enterCatchBlock=function(e){return this.catchAddress_=e||0,e=this.abruptCompletion_.exception,this.abruptCompletion_=null,e},w.generator.Context.prototype.enterCatchBlock=w.generator.Context.prototype.enterCatchBlock,w.generator.Context.prototype.enterFinallyBlock=function(e,t,n){n?this.finallyContexts_[n]=this.abruptCompletion_:this.finallyContexts_=[this.abruptCompletion_],this.catchAddress_=e||0,this.finallyAddress_=t||0},w.generator.Context.prototype.enterFinallyBlock=w.generator.Context.prototype.enterFinallyBlock,w.generator.Context.prototype.leaveFinallyBlock=function(e,t){if(t=this.finallyContexts_.splice(t||0)[0],t=this.abruptCompletion_=this.abruptCompletion_||t){if(t.isException)return this.jumpToErrorHandler_();t.jumpTo!=null&&this.finallyAddress_<t.jumpTo?(this.nextAddress=t.jumpTo,this.abruptCompletion_=null):this.nextAddress=this.finallyAddress_}else this.nextAddress=e},w.generator.Context.prototype.leaveFinallyBlock=w.generator.Context.prototype.leaveFinallyBlock,w.generator.Context.prototype.forIn=function(e){return new w.generator.Context.PropertyIterator(e)},w.generator.Context.prototype.forIn=w.generator.Context.prototype.forIn,w.generator.Context.PropertyIterator=function(e){for(var t in this.object_=e,this.properties_=[],e)this.properties_.push(t);this.properties_.reverse()},w.generator.Context.PropertyIterator.prototype.getNext=function(){for(;this.properties_.length>0;){var e=this.properties_.pop();if(e in this.object_)return e}return null},w.generator.Context.PropertyIterator.prototype.getNext=w.generator.Context.PropertyIterator.prototype.getNext,w.generator.Engine_=function(e){this.context_=new w.generator.Context,this.program_=e},w.generator.Engine_.prototype.next_=function(e){return this.context_.start_(),this.context_.yieldAllIterator_?this.yieldAllStep_(this.context_.yieldAllIterator_.next,e,this.context_.next_):(this.context_.next_(e),this.nextStep_())},w.generator.Engine_.prototype.return_=function(e){this.context_.start_();var t=this.context_.yieldAllIterator_;return t?this.yieldAllStep_(`return`in t?t.return:function(e){return{value:e,done:!0}},e,this.context_.return):(this.context_.return(e),this.nextStep_())},w.generator.Engine_.prototype.throw_=function(e){return this.context_.start_(),this.context_.yieldAllIterator_?this.yieldAllStep_(this.context_.yieldAllIterator_.throw,e,this.context_.next_):(this.context_.throw_(e),this.nextStep_())},w.generator.Engine_.prototype.yieldAllStep_=function(e,t,n){try{var r=e.call(this.context_.yieldAllIterator_,t);if(w.generator.ensureIteratorResultIsObject_(r),!r.done)return this.context_.stop_(),r;var i=r.value}catch(e){return this.context_.yieldAllIterator_=null,this.context_.throw_(e),this.nextStep_()}return this.context_.yieldAllIterator_=null,n.call(this.context_,i),this.nextStep_()},w.generator.Engine_.prototype.nextStep_=function(){for(;this.context_.nextAddress;)try{var e=this.program_(this.context_);if(e)return this.context_.stop_(),{value:e.value,done:!1}}catch(e){this.context_.yieldResult=void 0,this.context_.throw_(e)}if(this.context_.stop_(),this.context_.abruptCompletion_){if(e=this.context_.abruptCompletion_,this.context_.abruptCompletion_=null,e.isException)throw e.exception;return{value:e.return,done:!0}}return{value:void 0,done:!0}},w.generator.Generator_=function(e){this.next=function(t){return e.next_(t)},this.throw=function(t){return e.throw_(t)},this.return=function(t){return e.return_(t)},this[Symbol.iterator]=function(){return this}},w.generator.createGenerator=function(e,t){return t=new w.generator.Generator_(new w.generator.Engine_(t)),w.setPrototypeOf&&e.prototype&&w.setPrototypeOf(t,e.prototype),t},w.asyncExecutePromiseGenerator=function(e){function t(t){return e.next(t)}function n(t){return e.throw(t)}return new Promise(function(r,i){function a(e){e.done?r(e.value):Promise.resolve(e.value).then(t,n).then(a,i)}a(e.next())})},w.asyncExecutePromiseGeneratorFunction=function(e){return w.asyncExecutePromiseGenerator(e())},w.asyncExecutePromiseGeneratorProgram=function(e){return w.asyncExecutePromiseGenerator(new w.generator.Generator_(new w.generator.Engine_(e)))},w.polyfill(`globalThis`,function(e){return e||w.global},`es_2020`,`es3`),w.polyfill(`Array.prototype.includes`,function(e){return e||function(e,t){var n=this;n instanceof String&&(n=String(n));var r=n.length;for(t||=0,t<0&&(t=Math.max(t+r,0));t<r;t++){var i=n[t];if(i===e||Object.is(i,e))return!0}return!1}},`es7`,`es3`),w.owns=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},w.polyfill(`Object.values`,function(e){return e||function(e){var t=[],n;for(n in e)w.owns(e,n)&&t.push(e[n]);return t}},`es8`,`es3`),w.checkEs6ConformanceViaProxy=function(){try{var e={},t=Object.create(new w.global.Proxy(e,{get:function(n,r,i){return n==e&&r==`q`&&i==t}}));return t.q===!0}catch{return!1}},w.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS=!1,w.ES6_CONFORMANCE=w.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS&&w.checkEs6ConformanceViaProxy(),w.initSymbol=function(){},w.iteratorPrototype=function(e){return e={next:e},e[Symbol.iterator]=function(){return this},e},w.MapEntry=function(){},w.polyfill(`Set.prototype.difference`,function(e){return e||function(e){w.checkIsSetInstance(this),w.checkIsSetLike(e);var t=w.getSmallerAndLargerSets(this,e);e=new Set(this);var n=t.smallerSetIterator;t=t.largerSet;for(var r=n.next();!r.done;)t.has(r.value)&&e.delete(r.value),r=n.next();return e}},`es_next`,`es6`),w.checkIsSetLike=function(e){if(typeof e!=`object`||!e||typeof e.size!=`number`||e.size<0||typeof e.keys!=`function`||typeof e.has!=`function`)throw TypeError(`Argument must be set-like`)},w.checkIsValidIterator=function(e){if(typeof e!=`object`||!e||typeof e.next!=`function`)throw TypeError(`Invalid iterator.`);return e},w.getSmallerAndLargerSets=function(e,t){return e.size<=t.size?{smallerSetIterator:e.keys(),largerSet:t}:{smallerSetIterator:w.checkIsValidIterator(t.keys()),largerSet:e}},w.checkIsSetInstance=function(e){if(!(e instanceof Set))throw TypeError(`Method must be called on an instance of Set.`)},w.iteratorFromArray=function(e,t){if(w.ASSUME_ES6)return e[Symbol.iterator]();e instanceof String&&(e+=``);var n=0,r=!1,i={next:function(){if(!r&&n<e.length){var i=n++;return{value:t(i,e[i]),done:!1}}return r=!0,{done:!0,value:void 0}}};return i[Symbol.iterator]=function(){return i},i},w.polyfill(`Array.prototype.values`,function(e){return e||function(){return w.iteratorFromArray(this,function(e,t){return t})}},`es8`,`es3`),w.polyfill(`Array.prototype.flatMap`,function(e){return e||function(e,t){var n=[];return Array.prototype.forEach.call(this,function(r,i){r=e.call(t,r,i,this),Array.isArray(r)?n.push.apply(n,r):n.push(r)}),n}},`es9`,`es5`),w.polyfill(`Array.prototype.flat`,function(e){return e||function(e){e=e===void 0?1:e;var t=[];return Array.prototype.forEach.call(this,function(n){Array.isArray(n)&&e>0?(n=Array.prototype.flat.call(n,e-1),t.push.apply(t,n)):t.push(n)}),t}},`es9`,`es5`),w.polyfill(`Object.entries`,function(e){return e||function(e){var t=[],n;for(n in e)w.owns(e,n)&&t.push([n,e[n]]);return t}},`es8`,`es3`);var yo=`ontouchstart`in globalThis||!!(globalThis.document&&document.documentElement&&`ontouchstart`in document.documentElement)||!(!globalThis.navigator||!globalThis.navigator.maxTouchPoints&&!globalThis.navigator.msMaxTouchPoints),bo=null,xo={mousedown:[`pointerdown`],mouseenter:[`pointerenter`],mouseleave:[`pointerleave`],mousemove:[`pointermove`],mouseout:[`pointerout`],mouseover:[`pointerover`],mouseup:[`pointerup`,`pointercancel`],touchend:[`pointerup`],touchcancel:[`pointercancel`]},So=0,Co={TOUCH_ENABLED:yo,TOUCH_MAP:xo};Co.checkTouchIdentifier=a,Co.clearTouchIdentifier=function(){bo=null},Co.getTouchIdentifierFromEvent=i,Co.longStart=t,Co.longStop=n,Co.shouldHandleEvent=r;var wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No;(function(e){function t(e){return n.includes(e.toUpperCase())}wo=e;var n=wo.toUpperCase();To=t(`JavaFX`),Eo=t(`WebKit`),Do=t(`Gecko`)&&!Eo,Oo=t(`Android`),e=globalThis.navigator&&globalThis.navigator.maxTouchPoints,ko=t(`iPad`)||t(`Macintosh`)&&e>0,Ao=t(`iPhone`)&&!ko,jo=t(`Macintosh`),Mo=ko||Oo&&!t(`Mobile`)||t(`Silk`),No=!Mo&&(Ao||Oo)})(globalThis.navigator&&globalThis.navigator.userAgent||``);var Po=To,Fo=Do,Io=Oo,Lo=ko,Ro=Ao,zo=jo,Bo=No,Vo=zo||Lo||Ro,Ho={ANDROID:Io,APPLE:Vo,GECKO:Fo,IPAD:Lo,IPHONE:Ro,JavaFx:Po,MAC:zo,MOBILE:Bo,raw:wo},Uo={};Uo.bind=s,Uo.conditionalBind=o,Uo.getScrollDeltaPixels=ee,Uo.isRightButton=u,Uo.isTargetInput=l,Uo.mouseToSvg=d,Uo.unbind=c;var Wo={};Wo.removeElem=f;var Go=class{constructor(e){this.name=e}toString(){return this.name}};Go.POSITIONABLE=new Go(`positionable`),Go.DRAG_TARGET=new Go(`drag_target`),Go.DELETE_AREA=new Go(`delete_area`),Go.AUTOHIDEABLE=new Go(`autohideable`),Go.FOCUSABLE=new Go(`focusable`);var T=class{constructor(){this.componentData=new Map,this.capabilityToComponentIds=new Map}addComponent(e,t){var n=e.component.id;if(!t&&this.componentData.has(n)){var r;throw Error(`Plugin "`+n+`" with capabilities "`+((r=this.componentData.get(n))==null?void 0:r.capabilities)+`" already added.`)}for(this.componentData.set(n,e),t=[],r=0;r<e.capabilities.length;r++){let i=String(e.capabilities[r]).toLowerCase();if(t.push(i),this.capabilityToComponentIds.has(i)){let e;(e=this.capabilityToComponentIds.get(i))==null||e.push(n)}else this.capabilityToComponentIds.set(i,[n])}this.componentData.get(n).capabilities=t}removeComponent(e){var t=this.componentData.get(e);if(t){for(let n=0;n<t.capabilities.length;n++){let r=String(t.capabilities[n]).toLowerCase();f(this.capabilityToComponentIds.get(r),e)}this.componentData.delete(e)}}addCapability(e,t){if(!this.getComponent(e))throw Error(`Cannot add capability, "`+t+`". Plugin "`+e+`" has not been added to the ComponentManager`);if(this.hasCapability(e,t))console.warn(`Plugin "`+e+`already has capability "`+t+`"`);else{t=`${t}`.toLowerCase();var n;(n=this.componentData.get(e))==null||n.capabilities.push(t);var r;(r=this.capabilityToComponentIds.get(t))==null||r.push(e)}}removeCapability(e,t){if(!this.getComponent(e))throw Error(`Cannot remove capability, "`+t+`". Plugin "`+e+`" has not been added to the ComponentManager`);this.hasCapability(e,t)?(t=`${t}`.toLowerCase(),f(this.componentData.get(e).capabilities,t),f(this.capabilityToComponentIds.get(t),e)):console.warn(`Plugin "`+e+`doesn't have capability "`+t+`" to remove`)}hasCapability(e,t){return t=`${t}`.toLowerCase(),this.componentData.has(e)&&this.componentData.get(e).capabilities.includes(t)}getComponent(e){var t;return(t=this.componentData.get(e))==null?void 0:t.component}getComponents(e,t){if(e=`${e}`.toLowerCase(),e=this.capabilityToComponentIds.get(e),!e)return[];var n=[];if(t){let t=[];e.forEach(e=>{t.push(this.componentData.get(e))}),t.sort(function(e,t){return e.weight-t.weight}),t.forEach(function(e){n.push(e.component)})}else e.forEach(e=>{n.push(this.componentData.get(e).component)});return n}};T.Capability=Go;var Ko=T||={},qo=Ko.ComponentWeight||={};qo[qo.TOOLBOX_WEIGHT=0]=`TOOLBOX_WEIGHT`,qo[qo.FLYOUT_WEIGHT=1]=`FLYOUT_WEIGHT`,qo[qo.TRASHCAN_WEIGHT=2]=`TRASHCAN_WEIGHT`,qo[qo.ZOOM_CONTROLS_WEIGHT=3]=`ZOOM_CONTROLS_WEIGHT`;var Jo=new WeakSet,Yo=[],Xo=`
13
13
  :is(
14
14
  .injectionDiv,
15
15
  .blocklyWidgetDiv,
@@ -649,7 +649,7 @@ input[type=number] {
649
649
  flex-direction: ${Bo||Vo?`row-reverse`:`row`};
650
650
  column-gap: 8px;
651
651
  }
652
- `,Zo={};Zo.inject=ne,Zo.register=te;var E,D=E||={};D.BLOCK_CREATE=`create`,D.BLOCK_DELETE=`delete`,D.BLOCK_CHANGE=`change`,D.BLOCK_FIELD_INTERMEDIATE_CHANGE=`block_field_intermediate_change`,D.BLOCK_MOVE=`move`,D.VAR_CREATE=`var_create`,D.VAR_DELETE=`var_delete`,D.VAR_RENAME=`var_rename`,D.VAR_TYPE_CHANGE=`var_type_change`,D.UI=`ui`,D.BLOCK_DRAG=`drag`,D.SELECTED=`selected`,D.CLICK=`click`,D.MARKER_MOVE=`marker_move`,D.BUBBLE_OPEN=`bubble_open`,D.TRASHCAN_OPEN=`trashcan_open`,D.TOOLBOX_ITEM_SELECT=`toolbox_item_select`,D.THEME_CHANGE=`theme_change`,D.VIEWPORT_CHANGE=`viewport_change`,D.COMMENT_CREATE=`comment_create`,D.COMMENT_DELETE=`comment_delete`,D.COMMENT_CHANGE=`comment_change`,D.COMMENT_MOVE=`comment_move`,D.COMMENT_RESIZE=`comment_resize`,D.COMMENT_DRAG=`comment_drag`,D.COMMENT_COLLAPSE=`comment_collapse`,D.FINISHED_LOADING=`finished_loading`;var Qo=[E.BLOCK_CREATE,E.BLOCK_MOVE,E.COMMENT_CREATE,E.COMMENT_MOVE],$o=Object.create(null),es,ts=es||={};ts.ASSERTIVE=`assertive`,ts.OFF=`off`,ts.POLITE=`polite`;var ns=es.OFF,rs=[],O,is=O||={};is.APPLICATION=`application`,is.BUTTON=`button`,is.CHECKBOX=`checkbox`,is.DIALOG=`dialog`,is.FIGURE=`figure`,is.GENERIC=`generic`,is.GRID=`grid`,is.GRIDCELL=`gridcell`,is.GROUP=`group`,is.LIST=`list`,is.LISTBOX=`listbox`,is.LISTITEM=`listitem`,is.MENU=`menu`,is.MENUITEM=`menuitem`,is.NONE=`none`,is.OPTION=`option`,is.REGION=`region`,is.ROW=`row`,is.SEPARATOR=`separator`,is.STATUS=`status`,is.TEXTBOX=`textbox`,is.TREE=`tree`,is.TREEITEM=`treeitem`;var as=O.STATUS,k,os=k||={};os.ACTIVEDESCENDANT=`activedescendant`,os.ATOMIC=`atomic`,os.CHECKED=`checked`,os.CONTROLS=`controls`,os.DISABLED=`disabled`,os.EXPANDED=`expanded`,os.HASPOPUP=`haspopup`,os.HIDDEN=`hidden`,os.INVALID=`invalid`,os.LABEL=`label`,os.LABELLEDBY=`labelledby`,os.LEVEL=`level`,os.LIVE=`live`,os.PRESSED=`pressed`,os.ROLEDESCRIPTION=`roledescription`,os.SELECTED=`selected`,os.VALUEMAX=`valuemax`,os.VALUEMIN=`valuemin`,os.OWNS=`owns`;var ss,cs=ss||={};cs[cs.TERSE=0]=`TERSE`,cs[cs.STANDARD=1]=`STANDARD`,cs[cs.LOQUACIOUS=2]=`LOQUACIOUS`;var ls=null,us,ds=!1,fs={};fs.LiveRegionAssertiveness=es,fs.Role=O,fs.State=k,fs.Verbosity=ss,fs.announceDynamicAriaState=se,fs.clearState=ie,fs.getRole=function(e){return(e=e.getAttribute(`role`))&&Object.values(O).includes(e)?e:null},fs.getState=ae,fs.initializeGlobalAriaLiveRegion=oe,fs.removeRole=re,fs.setRole=p,fs.setState=m;var A=class{constructor(e){this.tagName=e}toString(){return this.tagName}};A.ANIMATE=new A(`animate`),A.CIRCLE=new A(`circle`),A.CLIPPATH=new A(`clipPath`),A.DEFS=new A(`defs`),A.FECOMPOSITE=new A(`feComposite`),A.FECOMPONENTTRANSFER=new A(`feComponentTransfer`),A.FEFLOOD=new A(`feFlood`),A.FEFUNCA=new A(`feFuncA`),A.FEGAUSSIANBLUR=new A(`feGaussianBlur`),A.FEPOINTLIGHT=new A(`fePointLight`),A.FESPECULARLIGHTING=new A(`feSpecularLighting`),A.FILTER=new A(`filter`),A.FOREIGNOBJECT=new A(`foreignObject`),A.G=new A(`g`),A.IMAGE=new A(`image`),A.LINE=new A(`line`),A.PATH=new A(`path`),A.PATTERN=new A(`pattern`),A.POLYGON=new A(`polygon`),A.RECT=new A(`rect`),A.SVG=new A(`svg`),A.TEXT=new A(`text`),A.TSPAN=new A(`tspan`);var ps,ms=ps||={};ms[ms.ELEMENT_NODE=1]=`ELEMENT_NODE`,ms[ms.TEXT_NODE=3]=`TEXT_NODE`,ms[ms.COMMENT_NODE=8]=`COMMENT_NODE`;var hs=null,gs=0,_s=null,vs={HTML_NS:`http://www.w3.org/1999/xhtml`};vs.NodeType=ps,vs.SVG_NS=`http://www.w3.org/2000/svg`,vs.XLINK_NS=`http://www.w3.org/1999/xlink`,vs.addClass=g,vs.createSvgElement=h,vs.getFastTextWidth=function(e,t,n,r){return he(e,t+`pt`,n,r)},vs.getFastTextWidthWithSizeString=he,vs.getTextWidth=me,vs.hasClass=le,vs.insertAfter=ue,vs.measureFontMetrics=ge,vs.removeClass=_,vs.removeClasses=ce,vs.removeNode=v,vs.setCssTransform=de,vs.startTextWidthCache=fe,vs.stopTextWidthCache=pe;var ys=class{static findFocusedNode(e){var t=e.getRootFocusableNode();if(!t.canBeFocused())return null;var n=t.getFocusableElement();return le(n,ys.ACTIVE_CLASS_NAME)||le(n,ys.PASSIVE_CSS_CLASS_NAME)||(t=n.querySelector(this.ACTIVE_FOCUS_NODE_CSS_SELECTOR),(t instanceof HTMLElement||t instanceof SVGElement)&&(t=ys.findFocusableNodeFor(t,e)))?t:(n=n.querySelector(this.PASSIVE_FOCUS_NODE_CSS_SELECTOR),(n instanceof HTMLElement||n instanceof SVGElement)&&(e=ys.findFocusableNodeFor(n,e))?e:null)}static findFocusableNodeFor(e,t){if(!e.id||e.id===`null`||t.getNestedTrees().map(t=>ys.findFocusableNodeFor(e,t)).findIndex(e=>!!e)!==-1)return null;var n=t.getRootFocusableNode();if(n.canBeFocused()&&e===n.getFocusableElement())return n;var r;return(n=(r=t.lookUpFocusableNode(e.id))??null)?n:(r=e.parentElement,!n&&r?ys.findFocusableNodeFor(r,t):null)}};ys.ACTIVE_CLASS_NAME=`blocklyActiveFocus`,ys.PASSIVE_CSS_CLASS_NAME=`blocklyPassiveFocus`,ys.ACTIVE_FOCUS_NODE_CSS_SELECTOR=`.${ys.ACTIVE_CLASS_NAME}`,ys.PASSIVE_FOCUS_NODE_CSS_SELECTOR=`.${ys.PASSIVE_CSS_CLASS_NAME}`;var bs=class{constructor(e,t){this.tree=e,this.rootShouldBeAutoTabbable=t}},xs=class{constructor(e){this.previouslyFocusedNode=this.focusedNode=null,this.registeredTrees=[],this.isUpdatingFocusedNode=this.recentlyLostAllFocus=this.lockFocusStateChanges=this.currentlyHoldsEphemeralFocus=!1,this.popoverFocusLossHandlers=new Set,this.popoverFocusOutHandler=e=>{e=e.relatedTarget;var t;if(e===null||e instanceof Node&&((t=this.popoverFocusRoot)==null||!t.contains(e)))for(let e of this.popoverFocusLossHandlers)e()};var t=e=>{if(!this.isUpdatingFocusedNode){this.recentlyLostAllFocus=!e;var t=null;if(e instanceof HTMLElement||e instanceof SVGElement){for(var n of this.registeredTrees)if(t=ys.findFocusableNodeFor(e,n.tree))break}if(t&&t.canBeFocused()){e=t.getFocusableTree();let r;n=(r=this.focusedNode)==null?void 0:r.getFocusableTree(),t===e.getRootFocusableNode()&&e!==n?this.focusTree(e):this.focusNode(t)}else this.defocusCurrentFocusedNode()}};e(`focusin`,e=>{e instanceof FocusEvent&&t(document.activeElement)}),e(`focusout`,e=>{e instanceof FocusEvent&&t(e.relatedTarget)})}registerTree(e,t=!1){if(this.ensureManagerIsUnlocked(),this.isRegistered(e))throw Error(`Attempted to re-register already registered tree: ${e}.`);this.registeredTrees.push(new bs(e,t));var n=e.getRootFocusableNode().getFocusableElement();if(!n.id||n.id===`null`)throw Error(`Attempting to register a tree with a root element that has an invalid ID: ${e}.`);t&&(n.tabIndex=0)}isRegistered(e){return!!this.lookUpRegistration(e)}lookUpRegistration(e){return this.registeredTrees.find(t=>t.tree===e)??null}unregisterTree(e){if(this.ensureManagerIsUnlocked(),!this.isRegistered(e))throw Error(`Attempted to unregister not registered tree: ${e}.`);var t=this.registeredTrees.findIndex(t=>t.tree===e),n=this.registeredTrees[t];this.registeredTrees.splice(t,1),t=ys.findFocusedNode(e);var r=e.getRootFocusableNode();t&&this.removeHighlight(t),this.focusedNode!==t&&this.focusedNode!==r||this.updateFocusedNode(null),this.removeHighlight(r),n.rootShouldBeAutoTabbable&&e.getRootFocusableNode().getFocusableElement().removeAttribute(`tabindex`)}getFocusedTree(){var e;return((e=this.focusedNode)==null?void 0:e.getFocusableTree())??null}getFocusedNode(){return this.focusedNode}focusTree(e){if(this.ensureManagerIsUnlocked(),!this.isRegistered(e))throw Error(`Attempted to focus unregistered tree: ${e}.`);var t=ys.findFocusedNode(e),n=e.getRestoredFocusableNode(t);e=e.getRootFocusableNode(),this.focusNode(n??t??e)}focusNode(e){this.ensureManagerIsUnlocked();var t=!this.currentlyHoldsEphemeralFocus;t&&(this.isUpdatingFocusedNode=!0);var n,r=((n=this.focusedNode)==null?void 0:n.getFocusableElement())!==document.activeElement;if(this.focusedNode!==e||r)if(e.canBeFocused()){if(n=e.getFocusableTree(),!this.isRegistered(n))throw Error(`Attempted to focus unregistered node: ${e}.`);r=e.getFocusableElement(),r.id&&r.id!==`null`||console.warn(`Trying to focus a node that has an invalid ID.`);var i=ys.findFocusableNodeFor(r,n);r=ys.findFocusedNode(n);var a=e;if(i!==e){a=n.getRestoredFocusableNode(r),e=n.getRootFocusableNode();var o;a=(o=a??r)??e}e=this.focusedNode,o=e==null?void 0:e.getFocusableTree(),e&&this.passivelyFocusNode(e,n),n=n.getRootFocusableNode(),r&&this.removeHighlight(r),n!==a&&this.removeHighlight(n),this.currentlyHoldsEphemeralFocus||this.activelyFocusNode(a,o??null),this.updateFocusedNode(a)}else console.warn(`Trying to focus a node that can't be focused.`);t&&(this.isUpdatingFocusedNode=!1)}takeEphemeralFocus(e){if(this.ensureManagerIsUnlocked(),this.currentlyHoldsEphemeralFocus)throw Error(`Attempted to take ephemeral focus when it's already held, with new element: ${e}.`);this.currentlyHoldsEphemeralFocus=!0,this.focusedNode&&this.passivelyFocusNode(this.focusedNode,null),e.focus({preventScroll:!0});var t=!1;return(n=!0)=>{if(t)throw Error(`Attempted to finish ephemeral focus twice for element: ${e}.`);if(t=!0,this.currentlyHoldsEphemeralFocus=!1,this.focusedNode&&n){this.activelyFocusNode(this.focusedNode,null);let e=this.focusedNode;setTimeout(()=>{!this.focusedNode&&this.previouslyFocusedNode===e&&this.recentlyLostAllFocus&&this.focusNode(e)},0)}}}ephemeralFocusTaken(){return this.currentlyHoldsEphemeralFocus}ensureManagerIsUnlocked(){if(this.lockFocusStateChanges)throw Error(`FocusManager state changes cannot happen in a tree/node focus/blur callback.`)}updateFocusedNode(e){this.previouslyFocusedNode=this.focusedNode,this.focusedNode=e}defocusCurrentFocusedNode(){this.focusedNode&&!this.currentlyHoldsEphemeralFocus&&(this.passivelyFocusNode(this.focusedNode,null),this.updateFocusedNode(null))}activelyFocusNode(e,t){this.lockFocusStateChanges=!0;var n=e.getFocusableTree(),r=e.getFocusableElement(),i,a=(i=this.lookUpRegistration(n))==null?void 0:i.rootShouldBeAutoTabbable;n!==t&&(n.onTreeFocus(e,t),a&&(n.getRootFocusableNode().getFocusableElement().tabIndex=-1)),e.onNodeFocus(),this.lockFocusStateChanges=!1,a&&e===n.getRootFocusableNode()||r.hasAttribute(`tabindex`)||(r.tabIndex=-1),this.setNodeToVisualActiveFocus(e),r.focus({preventScroll:!0})}passivelyFocusNode(e,t){this.lockFocusStateChanges=!0;var n=e.getFocusableTree();if(n!==t){n.onTreeBlur(t);let e;(e=this.lookUpRegistration(n))!=null&&e.rootShouldBeAutoTabbable&&(n.getRootFocusableNode().getFocusableElement().tabIndex=0)}e.onNodeBlur(),this.lockFocusStateChanges=!1,n!==t&&this.setNodeToVisualPassiveFocus(e)}setNodeToVisualActiveFocus(e){e=e.getFocusableElement(),g(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),_(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}setNodeToVisualPassiveFocus(e){e=e.getFocusableElement(),_(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),g(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}removeHighlight(e){e=e.getFocusableElement(),_(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),_(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}static getFocusManager(){return xs.focusManager||=new xs(document.addEventListener),xs.focusManager}setPopoverFocusRoot(e){var t;(t=this.popoverFocusRoot)==null||t.removeEventListener(`focusout`,this.popoverFocusOutHandler),this.popoverFocusRoot=e,this.popoverFocusRoot.addEventListener(`focusout`,this.popoverFocusOutHandler)}registerPopoverFocusLossHandler(e){this.popoverFocusLossHandlers.add(e)}unregisterPopoverFocusLossHandler(e){this.popoverFocusLossHandlers.delete(e)}};xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyActiveFocus`,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyPassiveFocus`,xs.focusManager=null;var Ss={};Ss.deepMerge=ye;var j=class{constructor(){this.shortcuts=new Map,this.keyMap=new Map,this.reset()}reset(){this.shortcuts.clear(),this.keyMap.clear()}register(e,t){if(this.shortcuts.get(e.name)&&!t)throw Error(`Shortcut named "${e.name}" already exists.`);if(this.shortcuts.set(e.name,e),t=e.keyCodes,t!=null&&t.length)for(let n of t)this.addKeyMapping(n,e.name,!!e.allowCollision)}unregister(e){return this.shortcuts.get(e)?(this.removeAllKeyMappings(e),this.shortcuts.delete(e),!0):(console.warn(`Keyboard shortcut named "${e}" not found.`),!1)}addKeyMapping(e,t,n){e=`${e}`;var r=this.keyMap.get(e);if(r&&!n)throw Error(`Shortcut named "${t}" collides with shortcuts "${r}"`);r&&n?r.unshift(t):this.keyMap.set(e,[t])}removeKeyMapping(e,t,n){var r=this.keyMap.get(e);if(!r)return n||console.warn(`No keyboard shortcut named "${t}" registered with key code "${e}"`),!1;var i=r.indexOf(t);return i>-1?(r.splice(i,1),r.length===0&&this.keyMap.delete(e),!0):(n||console.warn(`No keyboard shortcut named "${t}" registered with key code "${e}"`),!1)}removeAllKeyMappings(e){for(let t of this.keyMap.keys())this.removeKeyMapping(t,e,!0)}setKeyMap(e){this.keyMap.clear();for(let t in e)this.keyMap.set(t,e[t])}getKeyMap(){var e=Object.create(null);for(let[t,n]of this.keyMap)e[t]=n;return e}getRegistry(){var e=Object.create(null);for(let[t,n]of this.shortcuts)e[t]=n;return ye(Object.create(null),e)}onKeyDown(t,n){var r=this.serializeKeyEvent(n);if(r=this.getShortcutNamesByKeyCode(r),!r)return!1;for(let i of r){if(r=this.shortcuts.get(i),!r||r.preconditionFn&&!r.preconditionFn(t,{focusedNode:e.t().getFocusedNode()??void 0}))continue;let a;if((a=r.callback)!=null&&a.call(r,t,n,r,{focusedNode:e.t().getFocusedNode()??void 0}))return!0}return!1}getShortcutNamesByKeyCode(e){var t;return((t=this.keyMap.get(e))==null?void 0:t.slice())||[]}getKeyCodesByShortcutName(e){var t=[];for(let[n,r]of this.keyMap)r.indexOf(e)>-1&&t.push(n);return t}serializeKeyEvent(e){var t=``;for(let n in j.modifierKeys)e.getModifierState(n)&&(t!==``&&(t+=`+`),t+=n);return t!==``&&e.keyCode?t+=`+`+e.keyCode:e.keyCode&&(t=String(e.keyCode)),t}checkModifiers(e){for(let t of e)if(!(t in j.modifierKeys))throw Error(t+` is not a valid modifier key.`)}createSerializedKey(e,t){var n=``;if(t){this.checkModifiers(t);for(let e in j.modifierKeys)t.includes(j.modifierKeys[e])&&(n!==``&&(n+=`+`),n+=e)}return n!==``&&e?n+=`+`+e:e&&(n=`${e}`),n}};j.registry=new j;var Cs=j||={},ws=Cs.modifierKeys||={};ws[ws.Shift=16]=`Shift`,ws[ws.Control=17]=`Control`,ws[ws.Alt=18]=`Alt`,ws[ws.Meta=91]=`Meta`;var Ts=new Set,Es={};Es.warn=be;var Ds=Object.create(null),Os,ks,As=[],js={defineBlocksWithJsonArrayInternal:function(t){e.Ab(e.yb(t))}},Ms={TEST_ONLY:js};Ms.createBlockDefinitionsFromJsonArray=e.yb,Ms.defineBlocks=e.Ab,Ms.defineBlocksWithJsonArray=Pe,Ms.draggingConnections=As,Ms.fireSelectedEvent=Oe,Ms.getAllWorkspaces=Se,Ms.getBlockTypeCounts=Me,Ms.getMainWorkspace=Te,Ms.getParentContainer=ke,Ms.getSelected=De,Ms.getWorkspaceById=xe,Ms.globalShortcutHandler=Fe,Ms.registerWorkspace=Ce,Ms.setMainWorkspace=Ee,Ms.setParentContainer=Ae,Ms.setSelected=function(t){e.t().focusNode(t)},Ms.svgResize=je,Ms.unregisterWorkpace=function(e){be(`Blockly.common.unregisterWorkpace`,`v13`,`v14`,`Blockly.common.unregisterWorkspace`),we(e)},Ms.unregisterWorkspace=we;var Ns=Object.create(null),Ps={typeMap:Ns},Fs=Object.create(null),M=class{constructor(e){this.name=e}toString(){return this.name}};M.CONNECTION_CHECKER=new M(`connectionChecker`),M.CONNECTION_PREVIEWER=new M(`connectionPreviewer`),M.EVENT=new M(`event`),M.FIELD=new M(`field`),M.INPUT=new M(`input`),M.RENDERER=new M(`renderer`),M.TOOLBOX=new M(`toolbox`),M.THEME=new M(`theme`),M.TOOLBOX_ITEM=new M(`toolboxItem`),M.FLYOUTS_VERTICAL_TOOLBOX=new M(`flyoutsVerticalToolbox`),M.FLYOUTS_HORIZONTAL_TOOLBOX=new M(`flyoutsHorizontalToolbox`),M.FLYOUT_INFLATER=new M(`flyoutInflater`),M.METRICS_MANAGER=new M(`metricsManager`),M.BLOCK_DRAGGER=new M(`blockDragger`),M.SERIALIZER=new M(`serializer`),M.ICON=new M(`icon`),M.PASTER=new M(`paster`),M.VARIABLE_MODEL=new M(`variableModel`),M.VARIABLE_MAP=new M(`variableMap`);var Is={DEFAULT:`default`,TEST_ONLY:Ps};Is.Type=M,Is.getAllItems=Be,Is.getClass=ze,Is.getClassFromOptions=Ve,Is.getObject=function(e,t,n){return Le(e,t,n)},Is.hasItem=Re,Is.register=y,Is.unregister=Ie;var Ls={genUid:()=>{var e=[];for(let t=0;t<20;t++)e[t]="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.random()*88);return e.join(``)}},Rs=0,zs={TEST_ONLY:Ls};zs.genUid=Ue,zs.getNextUniqueId=He;var Bs,Vs;e.gd=``,e.Qc=!0,e.Ub=0,Bs=[],Vs={FIRE_QUEUE:Bs,enqueueEvent:Ge,fireNow:We,fireInternal:function(e){if(Je()){if(!Bs.length)try{requestAnimationFrame(()=>{setTimeout(We,0)})}catch{setTimeout(We,0)}Ge(e)}},setGroupInternal:function(t){e.gd=typeof t==`boolean`?t?Ue():``:t}};var Hs;e.C=Object.create(null),Hs={Msg:e.C,setLocale:Xe};var N=class{constructor(e,t){this.x=e,this.y=t}clone(){return new N(this.x,this.y)}scale(e){return this.x*=e,this.y*=e,this}translate(e,t){return this.x+=e,this.y+=t,this}static equals(e,t){return e===t?!0:e&&t?e.x===t.x&&e.y===t.y:!1}static distance(e,t){var n=e.x-t.x;return e=e.y-t.y,Math.sqrt(n*n+e*e)}static magnitude(e){return Math.sqrt(e.x*e.x+e.y*e.y)}static difference(e,t){return new N(e.x-t.x,e.y-t.y)}static sum(e,t){return new N(e.x+t.x,e.y+t.y)}},P=class{constructor(e,t,n,r){this.top=e,this.bottom=t,this.left=n,this.right=r}static from(e){return new P(e.y,e.y+e.height,e.x,e.x+e.width)}clone(){return new P(this.top,this.bottom,this.left,this.right)}getHeight(){return this.bottom-this.top}getWidth(){return this.right-this.left}getOrigin(){return new N(this.left,this.top)}contains(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}intersects(e){return this.left<=e.right&&this.right>=e.left&&this.bottom>=e.top&&this.top<=e.bottom}static equals(e,t){return e===t?!0:e&&t?e.top===t.top&&e.bottom===t.bottom&&e.left===t.left&&e.right===t.right:!1}static createFromPoint(e,t,n){var r=e.x;return e=e.y,new P(e,e+n,r,r+t)}},F=class{constructor(e,t){this.width=e,this.height=t}static equals(e,t){return e===t?!0:e&&t?e.width===t.width&&e.height===t.height:!1}static max(e,t){return new F(Math.max(e.width,t.width),Math.max(e.height,t.height))}static min(e,t){return new F(Math.min(e.width,t.width),Math.min(e.height,t.height))}},Us={getSizeInternal:function(e){if(Qe(e,`display`)!==`none`)return new F(e.offsetWidth,e.offsetHeight);var t=e.style,n=t.display,r=t.visibility,i=t.position;t.visibility=`hidden`,t.position=`absolute`,t.display=`inline`;var a=e.offsetWidth;return e=e.offsetHeight,t.display=n,t.position=i,t.visibility=r,new F(a,e)}},Ws={TEST_ONLY:Us};Ws.getBorderBox=tt,Ws.getComputedStyle=Qe,Ws.getContainerOffsetToScrollInto=rt,Ws.getPageOffset=$e,Ws.getSize=Ze,Ws.getViewportPageOffset=et,Ws.scrollIntoContainerView=nt;var Gs=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/,Ks=/transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/,qs={TEST_ONLY:{XY_REGEX:Gs,XY_STYLE_REGEX:Ks}};qs.getDocumentScroll=st,qs.getInjectionDivXY=at,qs.getRelativeXY=it,qs.getViewportBBox=ot,qs.screenToWsCoordinates=ct,qs.wsToScreenCoordinates=lt;var Js=class{constructor(e,t,n,r,i){this.workspace=e,this.horizontal=t,this.oldHostMetrics=null,this.ratio=1,this.origin=new N(0,0),this.startDragHandle=this.handlePosition=this.handleLength=this.scrollbarLength=this.startDragMouse=0,this.containerVisible=this.isHandleVisible=!0,this.position=new N(0,0),this.onMouseMoveWrapper_=this.onMouseUpWrapper_=null,this.pair=n||!1,this.margin=i===void 0?Js.DEFAULT_SCROLLBAR_MARGIN:i,e=`blocklyScrollbar`+(this.horizontal?`Horizontal`:`Vertical`),r&&(e+=` `+r),this.outerSvg=h(A.SVG,{class:e}),r=h(A.G,{},this.outerSvg),this.svgBackground=h(A.RECT,{class:`blocklyScrollbarBackground`},r),e=Math.floor((Js.scrollbarThickness-5)/2),this.svgHandle=h(A.RECT,{class:`blocklyScrollbarHandle`,rx:e,ry:e},r),this.workspace.getThemeManager().subscribe(this.svgHandle,`scrollbarColour`,`fill`),this.workspace.getThemeManager().subscribe(this.svgHandle,`scrollbarOpacity`,`fill-opacity`),ue(this.outerSvg,this.workspace.getParentSvg()),this.setInitialThickness(),t?(this.lengthAttribute_=`width`,this.positionAttribute_=`x`):(this.lengthAttribute_=`height`,this.positionAttribute_=`y`),this.onMouseDownBarWrapper_=o(this.svgBackground,`pointerdown`,this,this.onMouseDownBar),this.onMouseDownHandleWrapper_=o(this.svgHandle,`pointerdown`,this,this.onMouseDownHandle)}setInitialThickness(){var e=Js.scrollbarThickness;this.horizontal?(this.svgBackground.setAttribute(`height`,String(e)),this.outerSvg.setAttribute(`height`,String(e)),this.svgHandle.setAttribute(`height`,String(e-5)),this.svgHandle.setAttribute(`y`,`2.5`)):(this.svgBackground.setAttribute(`width`,String(e)),this.outerSvg.setAttribute(`width`,String(e)),this.svgHandle.setAttribute(`width`,String(e-5)),this.svgHandle.setAttribute(`x`,`2.5`))}dispose(){this.cleanUp(),c(this.onMouseDownBarWrapper_),c(this.onMouseDownHandleWrapper_),v(this.outerSvg),this.workspace.getThemeManager().unsubscribe(this.svgHandle)}constrainHandleLength(e){return e=e<=0||isNaN(e)?0:Math.min(e,this.scrollbarLength)}setHandleLength(e){this.handleLength=e,this.svgHandle.setAttribute(this.lengthAttribute_,String(this.handleLength))}constrainHandlePosition(e){return e=e<=0||isNaN(e)?0:Math.min(e,this.scrollbarLength-this.handleLength)}setHandlePosition(e){this.handlePosition=e,this.svgHandle.setAttribute(this.positionAttribute_,String(this.handlePosition))}setScrollbarLength(e){this.scrollbarLength=e,this.outerSvg.setAttribute(this.lengthAttribute_,String(this.scrollbarLength)),this.svgBackground.setAttribute(this.lengthAttribute_,String(this.scrollbarLength))}setPosition(e,t){this.position.x=e,this.position.y=t,de(this.outerSvg,`translate(`+(this.position.x+this.origin.x)+`px,`+(this.position.y+this.origin.y)+`px)`)}resize(e){!e&&(e=this.workspace.getMetrics(),!e)||this.oldHostMetrics&&Js.metricsAreEquivalent(e,this.oldHostMetrics)||(this.horizontal?this.resizeHorizontal(e):this.resizeVertical(e),this.oldHostMetrics=e,this.updateMetrics())}requiresViewResize(e){return!this.oldHostMetrics||this.oldHostMetrics.viewWidth!==e.viewWidth||this.oldHostMetrics.viewHeight!==e.viewHeight||this.oldHostMetrics.absoluteLeft!==e.absoluteLeft||this.oldHostMetrics.absoluteTop!==e.absoluteTop}resizeHorizontal(e){this.requiresViewResize(e)?this.resizeViewHorizontal(e):this.resizeContentHorizontal(e)}resizeViewHorizontal(e){var t=e.viewWidth-this.margin*2;this.pair&&(t-=Js.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),t=e.absoluteLeft+this.margin,this.pair&&this.workspace.RTL&&(t+=Js.scrollbarThickness),this.setPosition(t,e.absoluteTop+e.viewHeight-Js.scrollbarThickness-this.margin),this.resizeContentHorizontal(e)}resizeContentHorizontal(e){if(e.viewWidth>=e.scrollWidth)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var t=this.scrollbarLength*e.viewWidth/e.scrollWidth;t=this.constrainHandleLength(t),this.setHandleLength(t),t=e.scrollWidth-e.viewWidth;var n=this.scrollbarLength-this.handleLength;e=(e.viewLeft-e.scrollLeft)/t*n,e=this.constrainHandlePosition(e),this.setHandlePosition(e),this.ratio=n/t}}resizeVertical(e){this.requiresViewResize(e)?this.resizeViewVertical(e):this.resizeContentVertical(e)}resizeViewVertical(e){var t=e.viewHeight-this.margin*2;this.pair&&(t-=Js.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),this.setPosition(this.workspace.RTL?e.absoluteLeft+this.margin:e.absoluteLeft+e.viewWidth-Js.scrollbarThickness-this.margin,e.absoluteTop+this.margin),this.resizeContentVertical(e)}resizeContentVertical(e){if(e.viewHeight>=e.scrollHeight)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var t=this.scrollbarLength*e.viewHeight/e.scrollHeight;t=this.constrainHandleLength(t),this.setHandleLength(t),t=e.scrollHeight-e.viewHeight;var n=this.scrollbarLength-this.handleLength;e=(e.viewTop-e.scrollTop)/t*n,e=this.constrainHandlePosition(e),this.setHandlePosition(e),this.ratio=n/t}}isVisible(){return this.isHandleVisible}setContainerVisible(e){var t=e!==this.containerVisible;this.containerVisible=e,t&&this.updateDisplay_()}setVisible(e){if(this.pair)throw Error(`Unable to toggle visibility of paired scrollbars.`);this.setVisibleInternal(e)}setVisibleInternal(e){var t=e!==this.isVisible();this.isHandleVisible=e,t&&this.updateDisplay_()}updateDisplay_(){this.containerVisible&&this.isVisible()?this.outerSvg.setAttribute(`display`,`block`):this.outerSvg.setAttribute(`display`,`none`)}onMouseDownBar(e){if(this.workspace.markFocused(),bo=null,this.cleanUp(),u(e))e.stopPropagation();else{var t=d(e,this.workspace.getParentSvg(),this.workspace.getInverseScreenCTM());t=this.horizontal?t.x:t.y;var n=at(this.svgHandle);n=this.horizontal?n.x:n.y;var r=this.handlePosition,i=this.handleLength*.95;t<=n?r-=i:t>=n+this.handleLength&&(r+=i),this.setHandlePosition(this.constrainHandlePosition(r)),this.updateMetrics(),e.stopPropagation(),e.preventDefault()}}onMouseDownHandle(e){this.workspace.markFocused(),this.cleanUp(),u(e)?e.stopPropagation():(this.startDragHandle=this.handlePosition,this.startDragMouse=this.horizontal?e.clientX:e.clientY,this.onMouseUpWrapper_=o(document,`pointerup`,this,this.onMouseUpHandle),this.onMouseMoveWrapper_=o(document,`pointermove`,this,this.onMouseMoveHandle),e.stopPropagation(),e.preventDefault())}onMouseMoveHandle(e){this.setHandlePosition(this.constrainHandlePosition(this.startDragHandle+((this.horizontal?e.clientX:e.clientY)-this.startDragMouse))),this.updateMetrics()}onMouseUpHandle(){bo=null,this.cleanUp()}cleanUp(){this.workspace.hideChaff(!0),this.onMouseUpWrapper_&&=(c(this.onMouseUpWrapper_),null),this.onMouseMoveWrapper_&&=(c(this.onMouseMoveWrapper_),null)}getRatio_(){var e=this.handlePosition/(this.scrollbarLength-this.handleLength);return isNaN(e)&&(e=0),e}updateMetrics(){var e=this.getRatio_();this.horizontal?this.workspace.setMetrics({x:e}):this.workspace.setMetrics({y:e})}set(e,t){this.setHandlePosition(this.constrainHandlePosition(e*this.ratio)),(t||t===void 0)&&this.updateMetrics()}setOrigin(e,t){this.origin=new N(e,t)}static metricsAreEquivalent(e,t){return e.viewWidth===t.viewWidth&&e.viewHeight===t.viewHeight&&e.viewLeft===t.viewLeft&&e.viewTop===t.viewTop&&e.absoluteTop===t.absoluteTop&&e.absoluteLeft===t.absoluteLeft&&e.scrollWidth===t.scrollWidth&&e.scrollHeight===t.scrollHeight&&e.scrollLeft===t.scrollLeft&&e.scrollTop===t.scrollTop}};Js.scrollbarThickness=yo?25:15,Js.DEFAULT_SCROLLBAR_MARGIN=.5;var Ys={parseFromString:function(){throw Error(`DOMParser was not found in the global scope and was not properly injected using injectDependencies`)}},Xs={serializeToString:function(){throw Error(`XMLSerializer was not foundin the global scope and was not properly injected using injectDependencies`)}},{document:Zs,DOMParser:Qs,XMLSerializer:$s}=globalThis;Qs&&(Ys=new Qs),$s&&(Xs=new $s);var ec=/[\x00-\x09\x0B\x0C\x0E-\x1F]/g,tc={NAME_SPACE:`https://developers.google.com/blockly/xml`};tc.createElement=e.rc,tc.createTextNode=e.sc,tc.domToText=ut,tc.injectDependencies=function(e){({document:Zs=Zs,DOMParser:Qs=Qs,XMLSerializer:$s=$s}=e),Ys=new Qs,Xs=new $s},tc.textToDom=e.uc;var I,nc=I||={};nc[nc.TOP=0]=`TOP`,nc[nc.BOTTOM=1]=`BOTTOM`,nc[nc.LEFT=2]=`LEFT`,nc[nc.RIGHT=3]=`RIGHT`;var rc={hasCategoriesInternal:function(e){if(!e)return!1;var t=e.kind;return t?t===`categoryToolbox`:!!e.contents.filter(e=>e.kind.toUpperCase()===`CATEGORY`).length}},ic={};ic.Position=I,ic.TEST_ONLY=rc,ic.convertFlyoutDefToJsonArray=pt,ic.convertToolboxDefToJson=ft,ic.hasCategories=mt,ic.isCategoryCollapsible=ht,ic.parseToolboxTree=vt;var ac,oc=ac||={};oc[oc.TOP=0]=`TOP`,oc[oc.BOTTOM=1]=`BOTTOM`;var sc,cc=sc||={};cc[cc.LEFT=0]=`LEFT`,cc[cc.RIGHT=1]=`RIGHT`;var lc,uc=lc||={};uc[uc.UP=0]=`UP`,uc[uc.DOWN=1]=`DOWN`;var dc={};dc.bumpDirection=lc,dc.bumpPositionRect=xt,dc.getCornerOppositeToolbox=bt,dc.getStartPositionRect=yt,dc.horizontalPosition=sc,dc.verticalPosition=ac;var fc={width:96,height:124,url:`sprites.svg`},pc=class{constructor(e,t){this.workspace=e,this.group=t,this.pointerDownHandler=o(t,`pointerdown`,null,this.performAction.bind(this)),p(t,O.BUTTON),this.id=He(),this.group.id=this.id}zoom(e,t){this.workspace.markFocused(),this.workspace.zoomCenter(e),this.fireZoomEvent(),bo=null,t.stopPropagation(),t.preventDefault()}fireZoomEvent(){var e=new(x(E.CLICK))(null,this.workspace.id,`zoom_controls`);b(e)}getFocusableElement(){return this.group}getFocusableTree(){return this.workspace}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!0}dispose(){c(this.pointerDownHandler)}},mc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomIn`,tabindex:`0`},n),m(n,k.LABEL,e.C.ZOOM_IN),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoominClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,x:-32,y:-92,"clip-path":`url(#blocklyZoominClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.zoom(1,e)}},hc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomOut`,tabindex:`0`},n),m(n,k.LABEL,e.C.ZOOM_OUT),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoomoutClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,x:-64,y:-92,"clip-path":`url(#blocklyZoomoutClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.zoom(-1,e)}},gc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomReset`,tabindex:`0`},n),m(n,k.LABEL,e.C.RESET_ZOOM),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoomresetClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,y:-92,"clip-path":`url(#blocklyZoomresetClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.workspace.markFocused();var t=Math.log(this.workspace.options.zoomOptions.startScale/this.workspace.scale)/Math.log(this.workspace.options.zoomOptions.scaleSpeed);this.workspace.beginCanvasTransition(),this.workspace.zoomCenter(t),this.workspace.scrollCenter(),setTimeout(this.workspace.endCanvasTransition.bind(this.workspace),500),this.fireZoomEvent(),bo=null,e.stopPropagation(),e.preventDefault()}},_c=class{constructor(e){this.workspace=e,this.id=`zoomControls`,this.zoomResetControl=this.zoomOutControl=this.zoomInControl=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=h(A.G,{}),this.zoomOutControl=new hc(this.workspace,this.svgGroup),this.zoomInControl=new mc(this.workspace,this.svgGroup),this.workspace.isMovable()&&(this.zoomResetControl=new gc(this.workspace,this.svgGroup));for(let e of[this.zoomOutControl,this.zoomInControl,this.zoomResetControl])e&&this.workspace.getComponentManager().addComponent({component:e,weight:T.ComponentWeight.ZOOM_CONTROLS_WEIGHT,capabilities:[T.Capability.FOCUSABLE]});return this.svgGroup}init(){this.workspace.getComponentManager().addComponent({component:this,weight:T.ComponentWeight.ZOOM_CONTROLS_WEIGHT,capabilities:[T.Capability.POSITIONABLE]}),this.initialized=!0}dispose(){this.workspace.getComponentManager().removeComponent(`zoomControls`),this.svgGroup&&v(this.svgGroup);var e;(e=this.zoomInControl)==null||e.dispose();var t;(t=this.zoomOutControl)==null||t.dispose();var n;(n=this.zoomResetControl)==null||n.dispose()}getBoundingRectangle(){var e=this.SMALL_SPACING+2*this.HEIGHT;return this.zoomResetControl&&(e+=this.LARGE_SPACING+this.HEIGHT),new P(this.top,this.top+e,this.left,this.left+this.WIDTH)}position(e,t){if(this.initialized){var n=bt(this.workspace,e),r=this.SMALL_SPACING+2*this.HEIGHT;if(this.zoomResetControl&&(r+=this.LARGE_SPACING+this.HEIGHT),e=yt(n,new F(this.WIDTH,r),this.MARGIN_HORIZONTAL,this.MARGIN_VERTICAL,e,this.workspace),n=n.vertical,t=xt(e,this.MARGIN_VERTICAL,n===ac.TOP?lc.DOWN:lc.UP,t),n===ac.TOP){var i=this.SMALL_SPACING+this.HEIGHT,a;(a=this.zoomInControl)==null||a.getFocusableElement().setAttribute(`transform`,`translate(0, `+i+`)`),this.zoomResetControl&&(i=i+this.LARGE_SPACING+this.HEIGHT,this.zoomResetControl.getFocusableElement().setAttribute(`transform`,`translate(0, `+i+`)`))}else{a=this.zoomResetControl?this.LARGE_SPACING+this.HEIGHT:0;let e;(e=this.zoomInControl)==null||e.getFocusableElement().setAttribute(`transform`,`translate(0, `+a+`)`),a=a+this.SMALL_SPACING+this.HEIGHT,(i=this.zoomOutControl)==null||i.getFocusableElement().setAttribute(`transform`,`translate(0, `+a+`)`)}this.top=t.top,this.left=t.left;var o;(o=this.svgGroup)==null||o.setAttribute(`transform`,`translate(`+this.left+`,`+this.top+`)`)}}};te(`
652
+ `,Zo={};Zo.inject=ne,Zo.register=te;var E,D=E||={};D.BLOCK_CREATE=`create`,D.BLOCK_DELETE=`delete`,D.BLOCK_CHANGE=`change`,D.BLOCK_FIELD_INTERMEDIATE_CHANGE=`block_field_intermediate_change`,D.BLOCK_MOVE=`move`,D.VAR_CREATE=`var_create`,D.VAR_DELETE=`var_delete`,D.VAR_RENAME=`var_rename`,D.VAR_TYPE_CHANGE=`var_type_change`,D.UI=`ui`,D.BLOCK_DRAG=`drag`,D.SELECTED=`selected`,D.CLICK=`click`,D.MARKER_MOVE=`marker_move`,D.BUBBLE_OPEN=`bubble_open`,D.TRASHCAN_OPEN=`trashcan_open`,D.TOOLBOX_ITEM_SELECT=`toolbox_item_select`,D.THEME_CHANGE=`theme_change`,D.VIEWPORT_CHANGE=`viewport_change`,D.COMMENT_CREATE=`comment_create`,D.COMMENT_DELETE=`comment_delete`,D.COMMENT_CHANGE=`comment_change`,D.COMMENT_MOVE=`comment_move`,D.COMMENT_RESIZE=`comment_resize`,D.COMMENT_DRAG=`comment_drag`,D.COMMENT_COLLAPSE=`comment_collapse`,D.FINISHED_LOADING=`finished_loading`;var Qo=[E.BLOCK_CREATE,E.BLOCK_MOVE,E.COMMENT_CREATE,E.COMMENT_MOVE],$o=Object.create(null),es,ts=es||={};ts.ASSERTIVE=`assertive`,ts.OFF=`off`,ts.POLITE=`polite`;var ns=es.OFF,rs=[],O,is=O||={};is.APPLICATION=`application`,is.BUTTON=`button`,is.CHECKBOX=`checkbox`,is.DIALOG=`dialog`,is.FIGURE=`figure`,is.GENERIC=`generic`,is.GRID=`grid`,is.GRIDCELL=`gridcell`,is.GROUP=`group`,is.LIST=`list`,is.LISTBOX=`listbox`,is.LISTITEM=`listitem`,is.MENU=`menu`,is.MENUITEM=`menuitem`,is.NONE=`none`,is.OPTION=`option`,is.REGION=`region`,is.ROW=`row`,is.SEPARATOR=`separator`,is.STATUS=`status`,is.TEXTBOX=`textbox`,is.TREE=`tree`,is.TREEITEM=`treeitem`;var as=O.STATUS,k,os=k||={};os.ACTIVEDESCENDANT=`activedescendant`,os.ATOMIC=`atomic`,os.CHECKED=`checked`,os.CONTROLS=`controls`,os.DISABLED=`disabled`,os.EXPANDED=`expanded`,os.HASPOPUP=`haspopup`,os.HIDDEN=`hidden`,os.INVALID=`invalid`,os.LABEL=`label`,os.LABELLEDBY=`labelledby`,os.LEVEL=`level`,os.LIVE=`live`,os.PRESSED=`pressed`,os.ROLEDESCRIPTION=`roledescription`,os.SELECTED=`selected`,os.VALUEMAX=`valuemax`,os.VALUEMIN=`valuemin`,os.OWNS=`owns`;var ss,cs=ss||={};cs[cs.TERSE=0]=`TERSE`,cs[cs.STANDARD=1]=`STANDARD`,cs[cs.LOQUACIOUS=2]=`LOQUACIOUS`;var ls=null,us,ds=!1,fs={};fs.LiveRegionAssertiveness=es,fs.Role=O,fs.State=k,fs.Verbosity=ss,fs.announceDynamicAriaState=se,fs.clearState=ie,fs.getRole=function(e){return(e=e.getAttribute(`role`))&&Object.values(O).includes(e)?e:null},fs.getState=ae,fs.initializeGlobalAriaLiveRegion=oe,fs.removeRole=re,fs.setRole=p,fs.setState=m;var A=class{constructor(e){this.tagName=e}toString(){return this.tagName}};A.ANIMATE=new A(`animate`),A.CIRCLE=new A(`circle`),A.CLIPPATH=new A(`clipPath`),A.DEFS=new A(`defs`),A.FECOMPOSITE=new A(`feComposite`),A.FECOMPONENTTRANSFER=new A(`feComponentTransfer`),A.FEFLOOD=new A(`feFlood`),A.FEFUNCA=new A(`feFuncA`),A.FEGAUSSIANBLUR=new A(`feGaussianBlur`),A.FEPOINTLIGHT=new A(`fePointLight`),A.FESPECULARLIGHTING=new A(`feSpecularLighting`),A.FILTER=new A(`filter`),A.FOREIGNOBJECT=new A(`foreignObject`),A.G=new A(`g`),A.IMAGE=new A(`image`),A.LINE=new A(`line`),A.PATH=new A(`path`),A.PATTERN=new A(`pattern`),A.POLYGON=new A(`polygon`),A.RECT=new A(`rect`),A.SVG=new A(`svg`),A.TEXT=new A(`text`),A.TSPAN=new A(`tspan`);var ps,ms=ps||={};ms[ms.ELEMENT_NODE=1]=`ELEMENT_NODE`,ms[ms.TEXT_NODE=3]=`TEXT_NODE`,ms[ms.COMMENT_NODE=8]=`COMMENT_NODE`;var hs=null,gs=0,_s=null,vs={HTML_NS:`http://www.w3.org/1999/xhtml`};vs.NodeType=ps,vs.SVG_NS=`http://www.w3.org/2000/svg`,vs.XLINK_NS=`http://www.w3.org/1999/xlink`,vs.addClass=g,vs.createSvgElement=h,vs.getFastTextWidth=function(e,t,n,r){return he(e,t+`pt`,n,r)},vs.getFastTextWidthWithSizeString=he,vs.getTextWidth=me,vs.hasClass=le,vs.insertAfter=ue,vs.measureFontMetrics=ge,vs.removeClass=_,vs.removeClasses=ce,vs.removeNode=v,vs.setCssTransform=de,vs.startTextWidthCache=fe,vs.stopTextWidthCache=pe;var ys=class{static findFocusedNode(e){var t=e.getRootFocusableNode();if(!t.canBeFocused())return null;var n=t.getFocusableElement();return le(n,ys.ACTIVE_CLASS_NAME)||le(n,ys.PASSIVE_CSS_CLASS_NAME)||(t=n.querySelector(this.ACTIVE_FOCUS_NODE_CSS_SELECTOR),(t instanceof HTMLElement||t instanceof SVGElement)&&(t=ys.findFocusableNodeFor(t,e)))?t:(n=n.querySelector(this.PASSIVE_FOCUS_NODE_CSS_SELECTOR),(n instanceof HTMLElement||n instanceof SVGElement)&&(e=ys.findFocusableNodeFor(n,e))?e:null)}static findFocusableNodeFor(e,t){if(!e.id||e.id===`null`||t.getNestedTrees().map(t=>ys.findFocusableNodeFor(e,t)).findIndex(e=>!!e)!==-1)return null;var n=t.getRootFocusableNode();if(n.canBeFocused()&&e===n.getFocusableElement())return n;var r;return(n=(r=t.lookUpFocusableNode(e.id))??null)?n:(r=e.parentElement,!n&&r?ys.findFocusableNodeFor(r,t):null)}};ys.ACTIVE_CLASS_NAME=`blocklyActiveFocus`,ys.PASSIVE_CSS_CLASS_NAME=`blocklyPassiveFocus`,ys.ACTIVE_FOCUS_NODE_CSS_SELECTOR=`.${ys.ACTIVE_CLASS_NAME}`,ys.PASSIVE_FOCUS_NODE_CSS_SELECTOR=`.${ys.PASSIVE_CSS_CLASS_NAME}`;var bs=class{constructor(e,t){this.tree=e,this.rootShouldBeAutoTabbable=t}},xs=class{constructor(e){this.previouslyFocusedNode=this.focusedNode=null,this.registeredTrees=[],this.isUpdatingFocusedNode=this.recentlyLostAllFocus=this.lockFocusStateChanges=this.currentlyHoldsEphemeralFocus=!1,this.popoverFocusLossHandlers=new Set,this.popoverFocusOutHandler=e=>{e=e.relatedTarget;var t;if(e===null||e instanceof Node&&((t=this.popoverFocusRoot)==null||!t.contains(e)))for(let e of this.popoverFocusLossHandlers)e()};var t=e=>{if(!this.isUpdatingFocusedNode){this.recentlyLostAllFocus=!e;var t=null;if(e instanceof HTMLElement||e instanceof SVGElement){for(var n of this.registeredTrees)if(t=ys.findFocusableNodeFor(e,n.tree))break}if(t&&t.canBeFocused()){e=t.getFocusableTree();let r;n=(r=this.focusedNode)==null?void 0:r.getFocusableTree(),t===e.getRootFocusableNode()&&e!==n?this.focusTree(e):this.focusNode(t)}else this.defocusCurrentFocusedNode()}};e(`focusin`,e=>{e instanceof FocusEvent&&t(document.activeElement)}),e(`focusout`,e=>{e instanceof FocusEvent&&t(e.relatedTarget)})}registerTree(e,t=!1){if(this.ensureManagerIsUnlocked(),this.isRegistered(e))throw Error(`Attempted to re-register already registered tree: ${e}.`);this.registeredTrees.push(new bs(e,t));var n=e.getRootFocusableNode().getFocusableElement();if(!n.id||n.id===`null`)throw Error(`Attempting to register a tree with a root element that has an invalid ID: ${e}.`);t&&(n.tabIndex=0)}isRegistered(e){return!!this.lookUpRegistration(e)}lookUpRegistration(e){return this.registeredTrees.find(t=>t.tree===e)??null}unregisterTree(e){if(this.ensureManagerIsUnlocked(),!this.isRegistered(e))throw Error(`Attempted to unregister not registered tree: ${e}.`);var t=this.registeredTrees.findIndex(t=>t.tree===e),n=this.registeredTrees[t];this.registeredTrees.splice(t,1),t=ys.findFocusedNode(e);var r=e.getRootFocusableNode();t&&this.removeHighlight(t),this.focusedNode!==t&&this.focusedNode!==r||this.updateFocusedNode(null),this.removeHighlight(r),n.rootShouldBeAutoTabbable&&e.getRootFocusableNode().getFocusableElement().removeAttribute(`tabindex`)}getFocusedTree(){var e;return((e=this.focusedNode)==null?void 0:e.getFocusableTree())??null}getFocusedNode(){return this.focusedNode}focusTree(e){if(this.ensureManagerIsUnlocked(),!this.isRegistered(e))throw Error(`Attempted to focus unregistered tree: ${e}.`);var t=ys.findFocusedNode(e),n=e.getRestoredFocusableNode(t);e=e.getRootFocusableNode(),this.focusNode(n??t??e)}focusNode(e){this.ensureManagerIsUnlocked();var t=!this.currentlyHoldsEphemeralFocus;t&&(this.isUpdatingFocusedNode=!0);var n,r=((n=this.focusedNode)==null?void 0:n.getFocusableElement())!==document.activeElement;if(this.focusedNode!==e||r){if(e.canBeFocused()){if(n=e.getFocusableTree(),!this.isRegistered(n))throw Error(`Attempted to focus unregistered node: ${e}.`);r=e.getFocusableElement(),r.id&&r.id!==`null`||console.warn(`Trying to focus a node that has an invalid ID.`);var i=ys.findFocusableNodeFor(r,n);r=ys.findFocusedNode(n);var a=e;if(i!==e){a=n.getRestoredFocusableNode(r),e=n.getRootFocusableNode();var o;a=(o=a??r)??e}e=this.focusedNode,o=e==null?void 0:e.getFocusableTree(),e&&this.passivelyFocusNode(e,n),n=n.getRootFocusableNode(),r&&this.removeHighlight(r),n!==a&&this.removeHighlight(n),this.currentlyHoldsEphemeralFocus||this.activelyFocusNode(a,o??null),this.updateFocusedNode(a)}else console.warn(`Trying to focus a node that can't be focused.`)}t&&(this.isUpdatingFocusedNode=!1)}takeEphemeralFocus(e){if(this.ensureManagerIsUnlocked(),this.currentlyHoldsEphemeralFocus)throw Error(`Attempted to take ephemeral focus when it's already held, with new element: ${e}.`);this.currentlyHoldsEphemeralFocus=!0,this.focusedNode&&this.passivelyFocusNode(this.focusedNode,null),e.focus({preventScroll:!0});var t=!1;return(n=!0)=>{if(t)throw Error(`Attempted to finish ephemeral focus twice for element: ${e}.`);if(t=!0,this.currentlyHoldsEphemeralFocus=!1,this.focusedNode&&n){this.activelyFocusNode(this.focusedNode,null);let e=this.focusedNode;setTimeout(()=>{!this.focusedNode&&this.previouslyFocusedNode===e&&this.recentlyLostAllFocus&&this.focusNode(e)},0)}}}ephemeralFocusTaken(){return this.currentlyHoldsEphemeralFocus}ensureManagerIsUnlocked(){if(this.lockFocusStateChanges)throw Error(`FocusManager state changes cannot happen in a tree/node focus/blur callback.`)}updateFocusedNode(e){this.previouslyFocusedNode=this.focusedNode,this.focusedNode=e}defocusCurrentFocusedNode(){this.focusedNode&&!this.currentlyHoldsEphemeralFocus&&(this.passivelyFocusNode(this.focusedNode,null),this.updateFocusedNode(null))}activelyFocusNode(e,t){this.lockFocusStateChanges=!0;var n=e.getFocusableTree(),r=e.getFocusableElement(),i,a=(i=this.lookUpRegistration(n))==null?void 0:i.rootShouldBeAutoTabbable;n!==t&&(n.onTreeFocus(e,t),a&&(n.getRootFocusableNode().getFocusableElement().tabIndex=-1)),e.onNodeFocus(),this.lockFocusStateChanges=!1,a&&e===n.getRootFocusableNode()||r.hasAttribute(`tabindex`)||(r.tabIndex=-1),this.setNodeToVisualActiveFocus(e),r.focus({preventScroll:!0})}passivelyFocusNode(e,t){this.lockFocusStateChanges=!0;var n=e.getFocusableTree();if(n!==t){n.onTreeBlur(t);let e;(e=this.lookUpRegistration(n))!=null&&e.rootShouldBeAutoTabbable&&(n.getRootFocusableNode().getFocusableElement().tabIndex=0)}e.onNodeBlur(),this.lockFocusStateChanges=!1,n!==t&&this.setNodeToVisualPassiveFocus(e)}setNodeToVisualActiveFocus(e){e=e.getFocusableElement(),g(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),_(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}setNodeToVisualPassiveFocus(e){e=e.getFocusableElement(),_(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),g(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}removeHighlight(e){e=e.getFocusableElement(),_(e,xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),_(e,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}static getFocusManager(){return xs.focusManager||=new xs(document.addEventListener),xs.focusManager}setPopoverFocusRoot(e){var t;(t=this.popoverFocusRoot)==null||t.removeEventListener(`focusout`,this.popoverFocusOutHandler),this.popoverFocusRoot=e,this.popoverFocusRoot.addEventListener(`focusout`,this.popoverFocusOutHandler)}registerPopoverFocusLossHandler(e){this.popoverFocusLossHandlers.add(e)}unregisterPopoverFocusLossHandler(e){this.popoverFocusLossHandlers.delete(e)}};xs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyActiveFocus`,xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyPassiveFocus`,xs.focusManager=null;var Ss={};Ss.deepMerge=ye;var j=class{constructor(){this.shortcuts=new Map,this.keyMap=new Map,this.reset()}reset(){this.shortcuts.clear(),this.keyMap.clear()}register(e,t){if(this.shortcuts.get(e.name)&&!t)throw Error(`Shortcut named "${e.name}" already exists.`);if(this.shortcuts.set(e.name,e),t=e.keyCodes,t!=null&&t.length)for(let n of t)this.addKeyMapping(n,e.name,!!e.allowCollision)}unregister(e){return this.shortcuts.get(e)?(this.removeAllKeyMappings(e),this.shortcuts.delete(e),!0):(console.warn(`Keyboard shortcut named "${e}" not found.`),!1)}addKeyMapping(e,t,n){e=`${e}`;var r=this.keyMap.get(e);if(r&&!n)throw Error(`Shortcut named "${t}" collides with shortcuts "${r}"`);r&&n?r.unshift(t):this.keyMap.set(e,[t])}removeKeyMapping(e,t,n){var r=this.keyMap.get(e);if(!r)return n||console.warn(`No keyboard shortcut named "${t}" registered with key code "${e}"`),!1;var i=r.indexOf(t);return i>-1?(r.splice(i,1),r.length===0&&this.keyMap.delete(e),!0):(n||console.warn(`No keyboard shortcut named "${t}" registered with key code "${e}"`),!1)}removeAllKeyMappings(e){for(let t of this.keyMap.keys())this.removeKeyMapping(t,e,!0)}setKeyMap(e){this.keyMap.clear();for(let t in e)this.keyMap.set(t,e[t])}getKeyMap(){var e=Object.create(null);for(let[t,n]of this.keyMap)e[t]=n;return e}getRegistry(){var e=Object.create(null);for(let[t,n]of this.shortcuts)e[t]=n;return ye(Object.create(null),e)}onKeyDown(t,n){var r=this.serializeKeyEvent(n);if(r=this.getShortcutNamesByKeyCode(r),!r)return!1;for(let i of r){if(r=this.shortcuts.get(i),!r||r.preconditionFn&&!r.preconditionFn(t,{focusedNode:e.t().getFocusedNode()??void 0}))continue;let a;if((a=r.callback)!=null&&a.call(r,t,n,r,{focusedNode:e.t().getFocusedNode()??void 0}))return!0}return!1}getShortcutNamesByKeyCode(e){var t;return((t=this.keyMap.get(e))==null?void 0:t.slice())||[]}getKeyCodesByShortcutName(e){var t=[];for(let[n,r]of this.keyMap)r.indexOf(e)>-1&&t.push(n);return t}serializeKeyEvent(e){var t=``;for(let n in j.modifierKeys)e.getModifierState(n)&&(t!==``&&(t+=`+`),t+=n);return t!==``&&e.keyCode?t+=`+`+e.keyCode:e.keyCode&&(t=String(e.keyCode)),t}checkModifiers(e){for(let t of e)if(!(t in j.modifierKeys))throw Error(t+` is not a valid modifier key.`)}createSerializedKey(e,t){var n=``;if(t){this.checkModifiers(t);for(let e in j.modifierKeys)t.includes(j.modifierKeys[e])&&(n!==``&&(n+=`+`),n+=e)}return n!==``&&e?n+=`+`+e:e&&(n=`${e}`),n}};j.registry=new j;var Cs=j||={},ws=Cs.modifierKeys||={};ws[ws.Shift=16]=`Shift`,ws[ws.Control=17]=`Control`,ws[ws.Alt=18]=`Alt`,ws[ws.Meta=91]=`Meta`;var Ts=new Set,Es={};Es.warn=be;var Ds=Object.create(null),Os,ks,As=[],js={defineBlocksWithJsonArrayInternal:function(t){e.Ab(e.yb(t))}},Ms={TEST_ONLY:js};Ms.createBlockDefinitionsFromJsonArray=e.yb,Ms.defineBlocks=e.Ab,Ms.defineBlocksWithJsonArray=Pe,Ms.draggingConnections=As,Ms.fireSelectedEvent=Oe,Ms.getAllWorkspaces=Se,Ms.getBlockTypeCounts=Me,Ms.getMainWorkspace=Te,Ms.getParentContainer=ke,Ms.getSelected=De,Ms.getWorkspaceById=xe,Ms.globalShortcutHandler=Fe,Ms.registerWorkspace=Ce,Ms.setMainWorkspace=Ee,Ms.setParentContainer=Ae,Ms.setSelected=function(t){e.t().focusNode(t)},Ms.svgResize=je,Ms.unregisterWorkpace=function(e){be(`Blockly.common.unregisterWorkpace`,`v13`,`v14`,`Blockly.common.unregisterWorkspace`),we(e)},Ms.unregisterWorkspace=we;var Ns=Object.create(null),Ps={typeMap:Ns},Fs=Object.create(null),M=class{constructor(e){this.name=e}toString(){return this.name}};M.CONNECTION_CHECKER=new M(`connectionChecker`),M.CONNECTION_PREVIEWER=new M(`connectionPreviewer`),M.EVENT=new M(`event`),M.FIELD=new M(`field`),M.INPUT=new M(`input`),M.RENDERER=new M(`renderer`),M.TOOLBOX=new M(`toolbox`),M.THEME=new M(`theme`),M.TOOLBOX_ITEM=new M(`toolboxItem`),M.FLYOUTS_VERTICAL_TOOLBOX=new M(`flyoutsVerticalToolbox`),M.FLYOUTS_HORIZONTAL_TOOLBOX=new M(`flyoutsHorizontalToolbox`),M.FLYOUT_INFLATER=new M(`flyoutInflater`),M.METRICS_MANAGER=new M(`metricsManager`),M.BLOCK_DRAGGER=new M(`blockDragger`),M.SERIALIZER=new M(`serializer`),M.ICON=new M(`icon`),M.PASTER=new M(`paster`),M.VARIABLE_MODEL=new M(`variableModel`),M.VARIABLE_MAP=new M(`variableMap`);var Is={DEFAULT:`default`,TEST_ONLY:Ps};Is.Type=M,Is.getAllItems=Be,Is.getClass=ze,Is.getClassFromOptions=Ve,Is.getObject=function(e,t,n){return Le(e,t,n)},Is.hasItem=Re,Is.register=y,Is.unregister=Ie;var Ls={genUid:()=>{var e=[];for(let t=0;t<20;t++)e[t]="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.random()*88);return e.join(``)}},Rs=0,zs={TEST_ONLY:Ls};zs.genUid=Ue,zs.getNextUniqueId=He;var Bs,Vs;e.gd=``,e.Qc=!0,e.Ub=0,Bs=[],Vs={FIRE_QUEUE:Bs,enqueueEvent:Ge,fireNow:We,fireInternal:function(e){if(Je()){if(!Bs.length)try{requestAnimationFrame(()=>{setTimeout(We,0)})}catch{setTimeout(We,0)}Ge(e)}},setGroupInternal:function(t){e.gd=typeof t==`boolean`?t?Ue():``:t}};var Hs;e.C=Object.create(null),Hs={Msg:e.C,setLocale:Xe};var N=class{constructor(e,t){this.x=e,this.y=t}clone(){return new N(this.x,this.y)}scale(e){return this.x*=e,this.y*=e,this}translate(e,t){return this.x+=e,this.y+=t,this}static equals(e,t){return e===t?!0:e&&t?e.x===t.x&&e.y===t.y:!1}static distance(e,t){var n=e.x-t.x;return e=e.y-t.y,Math.sqrt(n*n+e*e)}static magnitude(e){return Math.sqrt(e.x*e.x+e.y*e.y)}static difference(e,t){return new N(e.x-t.x,e.y-t.y)}static sum(e,t){return new N(e.x+t.x,e.y+t.y)}},P=class{constructor(e,t,n,r){this.top=e,this.bottom=t,this.left=n,this.right=r}static from(e){return new P(e.y,e.y+e.height,e.x,e.x+e.width)}clone(){return new P(this.top,this.bottom,this.left,this.right)}getHeight(){return this.bottom-this.top}getWidth(){return this.right-this.left}getOrigin(){return new N(this.left,this.top)}contains(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}intersects(e){return this.left<=e.right&&this.right>=e.left&&this.bottom>=e.top&&this.top<=e.bottom}static equals(e,t){return e===t?!0:e&&t?e.top===t.top&&e.bottom===t.bottom&&e.left===t.left&&e.right===t.right:!1}static createFromPoint(e,t,n){var r=e.x;return e=e.y,new P(e,e+n,r,r+t)}},F=class{constructor(e,t){this.width=e,this.height=t}static equals(e,t){return e===t?!0:e&&t?e.width===t.width&&e.height===t.height:!1}static max(e,t){return new F(Math.max(e.width,t.width),Math.max(e.height,t.height))}static min(e,t){return new F(Math.min(e.width,t.width),Math.min(e.height,t.height))}},Us={getSizeInternal:function(e){if(Qe(e,`display`)!==`none`)return new F(e.offsetWidth,e.offsetHeight);var t=e.style,n=t.display,r=t.visibility,i=t.position;t.visibility=`hidden`,t.position=`absolute`,t.display=`inline`;var a=e.offsetWidth;return e=e.offsetHeight,t.display=n,t.position=i,t.visibility=r,new F(a,e)}},Ws={TEST_ONLY:Us};Ws.getBorderBox=tt,Ws.getComputedStyle=Qe,Ws.getContainerOffsetToScrollInto=rt,Ws.getPageOffset=$e,Ws.getSize=Ze,Ws.getViewportPageOffset=et,Ws.scrollIntoContainerView=nt;var Gs=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/,Ks=/transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/,qs={TEST_ONLY:{XY_REGEX:Gs,XY_STYLE_REGEX:Ks}};qs.getDocumentScroll=st,qs.getInjectionDivXY=at,qs.getRelativeXY=it,qs.getViewportBBox=ot,qs.screenToWsCoordinates=ct,qs.wsToScreenCoordinates=lt;var Js=class{constructor(e,t,n,r,i){this.workspace=e,this.horizontal=t,this.oldHostMetrics=null,this.ratio=1,this.origin=new N(0,0),this.startDragHandle=this.handlePosition=this.handleLength=this.scrollbarLength=this.startDragMouse=0,this.containerVisible=this.isHandleVisible=!0,this.position=new N(0,0),this.onMouseMoveWrapper_=this.onMouseUpWrapper_=null,this.pair=n||!1,this.margin=i===void 0?Js.DEFAULT_SCROLLBAR_MARGIN:i,e=`blocklyScrollbar`+(this.horizontal?`Horizontal`:`Vertical`),r&&(e+=` `+r),this.outerSvg=h(A.SVG,{class:e}),r=h(A.G,{},this.outerSvg),this.svgBackground=h(A.RECT,{class:`blocklyScrollbarBackground`},r),e=Math.floor((Js.scrollbarThickness-5)/2),this.svgHandle=h(A.RECT,{class:`blocklyScrollbarHandle`,rx:e,ry:e},r),this.workspace.getThemeManager().subscribe(this.svgHandle,`scrollbarColour`,`fill`),this.workspace.getThemeManager().subscribe(this.svgHandle,`scrollbarOpacity`,`fill-opacity`),ue(this.outerSvg,this.workspace.getParentSvg()),this.setInitialThickness(),t?(this.lengthAttribute_=`width`,this.positionAttribute_=`x`):(this.lengthAttribute_=`height`,this.positionAttribute_=`y`),this.onMouseDownBarWrapper_=o(this.svgBackground,`pointerdown`,this,this.onMouseDownBar),this.onMouseDownHandleWrapper_=o(this.svgHandle,`pointerdown`,this,this.onMouseDownHandle)}setInitialThickness(){var e=Js.scrollbarThickness;this.horizontal?(this.svgBackground.setAttribute(`height`,String(e)),this.outerSvg.setAttribute(`height`,String(e)),this.svgHandle.setAttribute(`height`,String(e-5)),this.svgHandle.setAttribute(`y`,`2.5`)):(this.svgBackground.setAttribute(`width`,String(e)),this.outerSvg.setAttribute(`width`,String(e)),this.svgHandle.setAttribute(`width`,String(e-5)),this.svgHandle.setAttribute(`x`,`2.5`))}dispose(){this.cleanUp(),c(this.onMouseDownBarWrapper_),c(this.onMouseDownHandleWrapper_),v(this.outerSvg),this.workspace.getThemeManager().unsubscribe(this.svgHandle)}constrainHandleLength(e){return e=e<=0||isNaN(e)?0:Math.min(e,this.scrollbarLength)}setHandleLength(e){this.handleLength=e,this.svgHandle.setAttribute(this.lengthAttribute_,String(this.handleLength))}constrainHandlePosition(e){return e=e<=0||isNaN(e)?0:Math.min(e,this.scrollbarLength-this.handleLength)}setHandlePosition(e){this.handlePosition=e,this.svgHandle.setAttribute(this.positionAttribute_,String(this.handlePosition))}setScrollbarLength(e){this.scrollbarLength=e,this.outerSvg.setAttribute(this.lengthAttribute_,String(this.scrollbarLength)),this.svgBackground.setAttribute(this.lengthAttribute_,String(this.scrollbarLength))}setPosition(e,t){this.position.x=e,this.position.y=t,de(this.outerSvg,`translate(`+(this.position.x+this.origin.x)+`px,`+(this.position.y+this.origin.y)+`px)`)}resize(e){!e&&(e=this.workspace.getMetrics(),!e)||this.oldHostMetrics&&Js.metricsAreEquivalent(e,this.oldHostMetrics)||(this.horizontal?this.resizeHorizontal(e):this.resizeVertical(e),this.oldHostMetrics=e,this.updateMetrics())}requiresViewResize(e){return!this.oldHostMetrics||this.oldHostMetrics.viewWidth!==e.viewWidth||this.oldHostMetrics.viewHeight!==e.viewHeight||this.oldHostMetrics.absoluteLeft!==e.absoluteLeft||this.oldHostMetrics.absoluteTop!==e.absoluteTop}resizeHorizontal(e){this.requiresViewResize(e)?this.resizeViewHorizontal(e):this.resizeContentHorizontal(e)}resizeViewHorizontal(e){var t=e.viewWidth-this.margin*2;this.pair&&(t-=Js.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),t=e.absoluteLeft+this.margin,this.pair&&this.workspace.RTL&&(t+=Js.scrollbarThickness),this.setPosition(t,e.absoluteTop+e.viewHeight-Js.scrollbarThickness-this.margin),this.resizeContentHorizontal(e)}resizeContentHorizontal(e){if(e.viewWidth>=e.scrollWidth)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var t=this.scrollbarLength*e.viewWidth/e.scrollWidth;t=this.constrainHandleLength(t),this.setHandleLength(t),t=e.scrollWidth-e.viewWidth;var n=this.scrollbarLength-this.handleLength;e=(e.viewLeft-e.scrollLeft)/t*n,e=this.constrainHandlePosition(e),this.setHandlePosition(e),this.ratio=n/t}}resizeVertical(e){this.requiresViewResize(e)?this.resizeViewVertical(e):this.resizeContentVertical(e)}resizeViewVertical(e){var t=e.viewHeight-this.margin*2;this.pair&&(t-=Js.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),this.setPosition(this.workspace.RTL?e.absoluteLeft+this.margin:e.absoluteLeft+e.viewWidth-Js.scrollbarThickness-this.margin,e.absoluteTop+this.margin),this.resizeContentVertical(e)}resizeContentVertical(e){if(e.viewHeight>=e.scrollHeight)this.setHandleLength(this.scrollbarLength),this.setHandlePosition(0),this.pair||this.setVisible(!1);else{this.pair||this.setVisible(!0);var t=this.scrollbarLength*e.viewHeight/e.scrollHeight;t=this.constrainHandleLength(t),this.setHandleLength(t),t=e.scrollHeight-e.viewHeight;var n=this.scrollbarLength-this.handleLength;e=(e.viewTop-e.scrollTop)/t*n,e=this.constrainHandlePosition(e),this.setHandlePosition(e),this.ratio=n/t}}isVisible(){return this.isHandleVisible}setContainerVisible(e){var t=e!==this.containerVisible;this.containerVisible=e,t&&this.updateDisplay_()}setVisible(e){if(this.pair)throw Error(`Unable to toggle visibility of paired scrollbars.`);this.setVisibleInternal(e)}setVisibleInternal(e){var t=e!==this.isVisible();this.isHandleVisible=e,t&&this.updateDisplay_()}updateDisplay_(){this.containerVisible&&this.isVisible()?this.outerSvg.setAttribute(`display`,`block`):this.outerSvg.setAttribute(`display`,`none`)}onMouseDownBar(e){if(this.workspace.markFocused(),bo=null,this.cleanUp(),u(e))e.stopPropagation();else{var t=d(e,this.workspace.getParentSvg(),this.workspace.getInverseScreenCTM());t=this.horizontal?t.x:t.y;var n=at(this.svgHandle);n=this.horizontal?n.x:n.y;var r=this.handlePosition,i=this.handleLength*.95;t<=n?r-=i:t>=n+this.handleLength&&(r+=i),this.setHandlePosition(this.constrainHandlePosition(r)),this.updateMetrics(),e.stopPropagation(),e.preventDefault()}}onMouseDownHandle(e){this.workspace.markFocused(),this.cleanUp(),u(e)?e.stopPropagation():(this.startDragHandle=this.handlePosition,this.startDragMouse=this.horizontal?e.clientX:e.clientY,this.onMouseUpWrapper_=o(document,`pointerup`,this,this.onMouseUpHandle),this.onMouseMoveWrapper_=o(document,`pointermove`,this,this.onMouseMoveHandle),e.stopPropagation(),e.preventDefault())}onMouseMoveHandle(e){this.setHandlePosition(this.constrainHandlePosition(this.startDragHandle+((this.horizontal?e.clientX:e.clientY)-this.startDragMouse))),this.updateMetrics()}onMouseUpHandle(){bo=null,this.cleanUp()}cleanUp(){this.workspace.hideChaff(!0),this.onMouseUpWrapper_&&=(c(this.onMouseUpWrapper_),null),this.onMouseMoveWrapper_&&=(c(this.onMouseMoveWrapper_),null)}getRatio_(){var e=this.handlePosition/(this.scrollbarLength-this.handleLength);return isNaN(e)&&(e=0),e}updateMetrics(){var e=this.getRatio_();this.horizontal?this.workspace.setMetrics({x:e}):this.workspace.setMetrics({y:e})}set(e,t){this.setHandlePosition(this.constrainHandlePosition(e*this.ratio)),(t||t===void 0)&&this.updateMetrics()}setOrigin(e,t){this.origin=new N(e,t)}static metricsAreEquivalent(e,t){return e.viewWidth===t.viewWidth&&e.viewHeight===t.viewHeight&&e.viewLeft===t.viewLeft&&e.viewTop===t.viewTop&&e.absoluteTop===t.absoluteTop&&e.absoluteLeft===t.absoluteLeft&&e.scrollWidth===t.scrollWidth&&e.scrollHeight===t.scrollHeight&&e.scrollLeft===t.scrollLeft&&e.scrollTop===t.scrollTop}};Js.scrollbarThickness=yo?25:15,Js.DEFAULT_SCROLLBAR_MARGIN=.5;var Ys={parseFromString:function(){throw Error(`DOMParser was not found in the global scope and was not properly injected using injectDependencies`)}},Xs={serializeToString:function(){throw Error(`XMLSerializer was not foundin the global scope and was not properly injected using injectDependencies`)}},{document:Zs,DOMParser:Qs,XMLSerializer:$s}=globalThis;Qs&&(Ys=new Qs),$s&&(Xs=new $s);var ec=/[\x00-\x09\x0B\x0C\x0E-\x1F]/g,tc={NAME_SPACE:`https://developers.google.com/blockly/xml`};tc.createElement=e.rc,tc.createTextNode=e.sc,tc.domToText=ut,tc.injectDependencies=function(e){({document:Zs=Zs,DOMParser:Qs=Qs,XMLSerializer:$s=$s}=e),Ys=new Qs,Xs=new $s},tc.textToDom=e.uc;var I,nc=I||={};nc[nc.TOP=0]=`TOP`,nc[nc.BOTTOM=1]=`BOTTOM`,nc[nc.LEFT=2]=`LEFT`,nc[nc.RIGHT=3]=`RIGHT`;var rc={hasCategoriesInternal:function(e){if(!e)return!1;var t=e.kind;return t?t===`categoryToolbox`:!!e.contents.filter(e=>e.kind.toUpperCase()===`CATEGORY`).length}},ic={};ic.Position=I,ic.TEST_ONLY=rc,ic.convertFlyoutDefToJsonArray=pt,ic.convertToolboxDefToJson=ft,ic.hasCategories=mt,ic.isCategoryCollapsible=ht,ic.parseToolboxTree=vt;var ac,oc=ac||={};oc[oc.TOP=0]=`TOP`,oc[oc.BOTTOM=1]=`BOTTOM`;var sc,cc=sc||={};cc[cc.LEFT=0]=`LEFT`,cc[cc.RIGHT=1]=`RIGHT`;var lc,uc=lc||={};uc[uc.UP=0]=`UP`,uc[uc.DOWN=1]=`DOWN`;var dc={};dc.bumpDirection=lc,dc.bumpPositionRect=xt,dc.getCornerOppositeToolbox=bt,dc.getStartPositionRect=yt,dc.horizontalPosition=sc,dc.verticalPosition=ac;var fc={width:96,height:124,url:`sprites.svg`},pc=class{constructor(e,t){this.workspace=e,this.group=t,this.pointerDownHandler=o(t,`pointerdown`,null,this.performAction.bind(this)),p(t,O.BUTTON),this.id=He(),this.group.id=this.id}zoom(e,t){this.workspace.markFocused(),this.workspace.zoomCenter(e),this.fireZoomEvent(),bo=null,t.stopPropagation(),t.preventDefault()}fireZoomEvent(){var e=new(x(E.CLICK))(null,this.workspace.id,`zoom_controls`);b(e)}getFocusableElement(){return this.group}getFocusableTree(){return this.workspace}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!0}dispose(){c(this.pointerDownHandler)}},mc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomIn`,tabindex:`0`},n),m(n,k.LABEL,e.C.ZOOM_IN),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoominClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,x:-32,y:-92,"clip-path":`url(#blocklyZoominClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.zoom(1,e)}},hc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomOut`,tabindex:`0`},n),m(n,k.LABEL,e.C.ZOOM_OUT),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoomoutClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,x:-64,y:-92,"clip-path":`url(#blocklyZoomoutClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.zoom(-1,e)}},gc=class extends pc{constructor(t,n){var r=String(Math.random()).substring(2);n=h(A.G,{class:`blocklyZoom blocklyZoomReset`,tabindex:`0`},n),m(n,k.LABEL,e.C.RESET_ZOOM),h(A.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=h(A.CLIPPATH,{id:`blocklyZoomresetClipPath`+r},n);h(A.RECT,{width:32,height:32},i),h(A.IMAGE,{width:fc.width,height:fc.height,y:-92,"clip-path":`url(#blocklyZoomresetClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+fc.url),super(t,n)}performAction(e){this.workspace.markFocused();var t=Math.log(this.workspace.options.zoomOptions.startScale/this.workspace.scale)/Math.log(this.workspace.options.zoomOptions.scaleSpeed);this.workspace.beginCanvasTransition(),this.workspace.zoomCenter(t),this.workspace.scrollCenter(),setTimeout(this.workspace.endCanvasTransition.bind(this.workspace),500),this.fireZoomEvent(),bo=null,e.stopPropagation(),e.preventDefault()}},_c=class{constructor(e){this.workspace=e,this.id=`zoomControls`,this.zoomResetControl=this.zoomOutControl=this.zoomInControl=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=h(A.G,{}),this.zoomOutControl=new hc(this.workspace,this.svgGroup),this.zoomInControl=new mc(this.workspace,this.svgGroup),this.workspace.isMovable()&&(this.zoomResetControl=new gc(this.workspace,this.svgGroup));for(let e of[this.zoomOutControl,this.zoomInControl,this.zoomResetControl])e&&this.workspace.getComponentManager().addComponent({component:e,weight:T.ComponentWeight.ZOOM_CONTROLS_WEIGHT,capabilities:[T.Capability.FOCUSABLE]});return this.svgGroup}init(){this.workspace.getComponentManager().addComponent({component:this,weight:T.ComponentWeight.ZOOM_CONTROLS_WEIGHT,capabilities:[T.Capability.POSITIONABLE]}),this.initialized=!0}dispose(){this.workspace.getComponentManager().removeComponent(`zoomControls`),this.svgGroup&&v(this.svgGroup);var e;(e=this.zoomInControl)==null||e.dispose();var t;(t=this.zoomOutControl)==null||t.dispose();var n;(n=this.zoomResetControl)==null||n.dispose()}getBoundingRectangle(){var e=this.SMALL_SPACING+2*this.HEIGHT;return this.zoomResetControl&&(e+=this.LARGE_SPACING+this.HEIGHT),new P(this.top,this.top+e,this.left,this.left+this.WIDTH)}position(e,t){if(this.initialized){var n=bt(this.workspace,e),r=this.SMALL_SPACING+2*this.HEIGHT;if(this.zoomResetControl&&(r+=this.LARGE_SPACING+this.HEIGHT),e=yt(n,new F(this.WIDTH,r),this.MARGIN_HORIZONTAL,this.MARGIN_VERTICAL,e,this.workspace),n=n.vertical,t=xt(e,this.MARGIN_VERTICAL,n===ac.TOP?lc.DOWN:lc.UP,t),n===ac.TOP){var i=this.SMALL_SPACING+this.HEIGHT,a;(a=this.zoomInControl)==null||a.getFocusableElement().setAttribute(`transform`,`translate(0, `+i+`)`),this.zoomResetControl&&(i=i+this.LARGE_SPACING+this.HEIGHT,this.zoomResetControl.getFocusableElement().setAttribute(`transform`,`translate(0, `+i+`)`))}else{a=this.zoomResetControl?this.LARGE_SPACING+this.HEIGHT:0;let e;(e=this.zoomInControl)==null||e.getFocusableElement().setAttribute(`transform`,`translate(0, `+a+`)`),a=a+this.SMALL_SPACING+this.HEIGHT,(i=this.zoomOutControl)==null||i.getFocusableElement().setAttribute(`transform`,`translate(0, `+a+`)`)}this.top=t.top,this.left=t.left;var o;(o=this.svgGroup)==null||o.setAttribute(`transform`,`translate(`+this.left+`,`+this.top+`)`)}}};te(`
653
653
  .blocklyZoom>image, .blocklyZoom>svg>image {
654
654
  opacity: .4;
655
655
  }
@@ -692,7 +692,7 @@ input[type=number] {
692
692
  border: none;
693
693
  cursor: pointer;
694
694
  }
695
- `);var Fc,Ic=Fc||={};Ic[Ic.ALERT=1]=`ALERT`,Ic[Ic.CONFIRM=2]=`CONFIRM`,Ic[Ic.PROMPT=3]=`PROMPT`;var Lc=0,Rc=Lt,zc=Rt,Bc=zt,Vc=Pc.show.bind(Pc),Hc=Vc,Uc={};Uc.alert=Bt,Uc.confirm=Vt,Uc.prompt=Ht,Uc.setAlert=function(e=Lt){Rc=e},Uc.setConfirm=function(e=Rt){zc=e},Uc.setPrompt=function(e=zt){Bc=e},Uc.setToast=function(e=Vc){Hc=e},Uc.toast=function(e,t){Hc(e,t)};var Wc=class{constructor(){this.workspaceId=void 0,this.isUiEvent=!1,this.type=``,this.group=e.gd,this.recordUndo=e.Qc}toJson(){return{type:this.type,group:this.group}}static fromJson(e,t,n){return n.isBlank=!1,n.group=e.group||``,n.workspaceId=t.id,n}isNull(){return!1}run(){}getEventWorkspace_(){var e;if(this.workspaceId&&(e=xe(this.workspaceId)),!e)throw Error(`Workspace is null. Event must have been generated from real Blockly events.`);return e}},Gc=class extends Wc{constructor(e){super(),this.isBlank=!0,this.isBlank=!e,e&&(this.blockId=e.id,this.workspaceId=e.workspace.id)}toJson(){var e=super.toJson();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);return e.blockId=this.blockId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new Gc),t.blockId=e.blockId,t}},Kc=class{constructor(e){this.name=e}toString(){return this.name}equals(e){return this.name===e.toString()}};Kc.MUTATOR=new Kc(`mutator`),Kc.WARNING=new Kc(`warning`),Kc.COMMENT=new Kc(`comment`);var qc=class extends Gc{constructor(e,t,n,r,i){super(e),this.type=E.BLOCK_CHANGE,e&&(this.element=t,this.name=n||void 0,this.oldValue=r,this.newValue=i)}toJson(){var e=super.toJson();if(!this.element)throw Error(`The changed element is undefined. Either pass an element to the constructor, or call fromJson`);return e.element=this.element,e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,this.disabledReason&&(e.disabledReason=this.disabledReason),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new qc),t.element=e.element,t.name=e.name,t.oldValue=e.oldValue,t.newValue=e.newValue,e.disabledReason!==void 0&&(t.disabledReason=e.disabledReason),t}setDisabledReason(e){if(this.element!==`disabled`)throw Error(`Cannot set the disabled reason for a BlockChange event if the element is not "disabled".`);this.disabledReason=e}isNull(){return this.oldValue===this.newValue}run(t){var n=this.getEventWorkspace_();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);if(n=n.getBlockById(this.blockId),!n)throw Error(`The associated block is undefined. Either pass a block to the constructor, or call fromJson`);var r=n.getIcon(Kc.MUTATOR);switch(r&&Wt(r)&&r.bubbleIsVisible()&&r.setBubbleVisible(!1),t=t?this.newValue:this.oldValue,this.element){case`field`:(n=n.getField(this.name))?n.setValue(t):console.warn(`Can't set non-existent field: `+this.name);break;case`comment`:n.setCommentText(t??null);break;case`collapsed`:n.setCollapsed(!!t);break;case`disabled`:var i;n.setDisabledReason(!!t,(i=this.disabledReason)??`MANUALLY_DISABLED`);break;case`inline`:n.setInputsInline(!!t);break;case`mutation`:i=qc.getExtraBlockState_(n),n.loadExtraState?n.loadExtraState(JSON.parse(t||`{}`)):n.domToMutation&&n.domToMutation(e.uc(t||`<mutation/>`)),b(new qc(n,`mutation`,null,i,t));break;default:console.warn(`Unknown change type: `+this.element)}}static getExtraBlockState_(e){return e.saveExtraState?(e=e.saveExtraState(!0))?JSON.stringify(e):``:e.mutationToDom&&(e=e.mutationToDom())?ti(e):``}};y(M.EVENT,E.BLOCK_CHANGE,qc);var Jc=class extends Gc{constructor(e){super(e),this.type=E.BLOCK_CREATE,e&&(e.isShadow()&&(this.recordUndo=!1),this.ids=Ye(e),this.json=dn(e,{addCoordinates:!0}))}toJson(){var e=super.toJson();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 e.ids=this.ids,e.json=this.json,this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Jc),t.ids=e.ids,t.json=e.json,e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}run(e){var t=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(!Gt(t,this.ids))if(e)pn(this.json,t);else for(e=0;e<this.ids.length;e++){let n=this.ids[e],r=t.getBlockById(n);r?r.dispose(!1):n===this.blockId&&console.warn(`Can't uncreate non-existent block: `+n)}}};y(M.EVENT,E.BLOCK_CREATE,Jc);var Yc=class extends Gc{constructor(e){if(super(e),this.type=E.BLOCK_DELETE,e){if(e.getParent())throw Error(`Connected blocks cannot be deleted.`);e.isShadow()&&(this.recordUndo=!1),this.ids=Ye(e),this.wasShadow=e.isShadow(),this.oldJson=dn(e,{addCoordinates:!0})}}toJson(){var e=super.toJson();if(!this.ids)throw Error(`The block IDs are undefined. Either pass a block to the constructor, or call fromJson`);if(this.wasShadow===void 0)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 e.ids=this.ids,e.wasShadow=this.wasShadow,e.oldJson=this.oldJson,this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Yc),t.ids=e.ids,t.wasShadow=e.wasShadow,t.oldJson=e.oldJson,e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}run(e){var t=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(e)for(e=0;e<this.ids.length;e++){let n=this.ids[e],r=t.getBlockById(n);r?r.dispose(!1):n===this.blockId&&console.warn(`Can't delete non-existent block: `+n)}else pn(this.oldJson,t)}};y(M.EVENT,E.BLOCK_DELETE,Yc);var Xc=class extends Wc{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.isUiEvent=!0,this.isBlank=e===void 0,this.workspaceId=e||``}},Zc=class extends Xc{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=E.BLOCK_DRAG,e&&(this.blockId=e.id,this.isStart=t,this.blocks=n)}toJson(){var e=super.toJson();if(this.isStart===void 0)throw Error(`Whether this event is the start of a drag is undefined. Either pass the value to the constructor, or call fromJson`);if(this.blockId===void 0)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);return e.isStart=this.isStart,e.blockId=this.blockId,e.blocks=this.blocks,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new Zc),t.isStart=e.isStart,t.blockId=e.blockId,t.blocks=e.blocks,t}};y(M.EVENT,E.BLOCK_DRAG,Zc);var Qc=class extends Gc{constructor(e,t,n,r){super(e),this.type=E.BLOCK_FIELD_INTERMEDIATE_CHANGE,this.recordUndo=!1,e&&(this.name=t,this.oldValue=n,this.newValue=r)}toJson(){var e=super.toJson();if(!this.name)throw Error(`The changed field name is undefined. Either pass a name to the constructor, or call fromJson.`);return e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Qc),t.name=e.name,t.oldValue=e.oldValue,t.newValue=e.newValue,t}isNull(){return this.oldValue===this.newValue}run(e){var t=this.getEventWorkspace_();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);if(t=t.getBlockById(this.blockId),!t)throw Error(`The associated block is undefined. Either pass a block to the constructor, or call fromJson`);e=e?this.newValue:this.oldValue,(t=t.getField(this.name))?t.setValue(e):console.warn(`Can't set non-existent field: `+this.name)}};y(M.EVENT,E.BLOCK_FIELD_INTERMEDIATE_CHANGE,Qc);var L,$c=L||={};$c[$c.INPUT_VALUE=1]=`INPUT_VALUE`,$c[$c.OUTPUT_VALUE=2]=`OUTPUT_VALUE`,$c[$c.NEXT_STATEMENT=3]=`NEXT_STATEMENT`,$c[$c.PREVIOUS_STATEMENT=4]=`PREVIOUS_STATEMENT`;var el=class extends Gc{constructor(e){super(e),this.type=E.BLOCK_MOVE,e&&(e.isShadow()&&(this.recordUndo=!1),e=this.currentLocation(),this.oldParentId=e.parentId,this.oldInputName=e.inputName,this.oldCoordinate=e.coordinate)}toJson(){var e=super.toJson();return e.oldParentId=this.oldParentId,e.oldInputName=this.oldInputName,this.oldCoordinate&&(e.oldCoordinate=`${Math.round(this.oldCoordinate.x)}, ${Math.round(this.oldCoordinate.y)}`),e.newParentId=this.newParentId,e.newInputName=this.newInputName,this.newCoordinate&&(e.newCoordinate=`${Math.round(this.newCoordinate.x)}, ${Math.round(this.newCoordinate.y)}`),this.reason&&(e.reason=this.reason),this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new el),t.oldParentId=e.oldParentId,t.oldInputName=e.oldInputName,e.oldCoordinate&&(n=e.oldCoordinate.split(`,`),t.oldCoordinate=new N(Number(n[0]),Number(n[1]))),t.newParentId=e.newParentId,t.newInputName=e.newInputName,e.newCoordinate&&(n=e.newCoordinate.split(`,`),t.newCoordinate=new N(Number(n[0]),Number(n[1]))),e.reason!==void 0&&(t.reason=e.reason),e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}recordNew(){var e=this.currentLocation();this.newParentId=e.parentId,this.newInputName=e.inputName,this.newCoordinate=e.coordinate}setReason(e){this.reason=e}currentLocation(){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 t=e.getBlockById(this.blockId);if(!t)throw Error(`The block associated with the block move event could not be found`);e={};var n=t.getParent();return n?(e.parentId=n.id,(t=n.getInputWithBlock(t))&&(e.inputName=t.name)):e.coordinate=t.getRelativeToSurfaceXY(),e}isNull(){return this.oldParentId===this.newParentId&&this.oldInputName===this.newInputName&&N.equals(this.oldCoordinate,this.newCoordinate)}run(e){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 n=t.getBlockById(this.blockId);if(n){var r=e?this.newParentId:this.oldParentId,i=e?this.newInputName:this.oldInputName;if(e=e?this.newCoordinate:this.oldCoordinate,r){var a=t.getBlockById(r);if(!a){console.warn(`Can't connect to non-existent block: `+r);return}}if(n.getParent()&&n.unplug(),e)i=n.getRelativeToSurfaceXY(),n.moveBy(e.x-i.x,e.y-i.y,this.reason);else{t=n.outputConnection,(!t||n.previousConnection&&n.previousConnection.isConnected())&&(t=n.previousConnection);let e,r;n=(r=t)==null?void 0:r.type,i?(n=a.getInput(i))&&(e=n.connection):n===L.PREVIOUS_STATEMENT&&(e=a.nextConnection),e&&t?t.connect(e):console.warn(`Can't connect to non-existent input: `+i)}}else console.warn(`Can't move non-existent block: `+this.blockId)}};y(M.EVENT,E.BLOCK_MOVE,el);var tl=class extends Xc{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=E.BUBBLE_OPEN,e&&(this.blockId=e.id,this.isOpen=t,this.bubbleType=n)}toJson(){var e=super.toJson();if(this.isOpen===void 0)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 e.isOpen=this.isOpen,e.bubbleType=this.bubbleType,e.blockId=this.blockId||``,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new tl),t.isOpen=e.isOpen,t.bubbleType=e.bubbleType,t.blockId=e.blockId,t}},nl,rl=nl||={};rl.MUTATOR=`mutator`,rl.COMMENT=`comment`,rl.WARNING=`warning`,y(M.EVENT,E.BUBBLE_OPEN,tl);var il=class extends Xc{constructor(e,t,n){t=e?e.workspace.id:t,t===null&&(t=void 0),super(t),this.type=E.CLICK,this.blockId=e?e.id:void 0,this.targetType=n}toJson(){var e=super.toJson();if(!this.targetType)throw Error(`The click target type is undefined. Either pass a block to the constructor, or call fromJson`);return e.targetType=this.targetType,e.blockId=this.blockId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new il),t.targetType=e.targetType,t.blockId=e.blockId,t}},al,ol=al||={};ol.BLOCK=`block`,ol.WORKSPACE=`workspace`,ol.ZOOM_CONTROLS=`zoom_controls`,y(M.EVENT,E.CLICK,il);var sl=class extends Wc{constructor(t){super(),this.isBlank=!0,this.isBlank=!t,t&&(this.commentId=t.id,this.workspaceId=t.workspace.id,this.group=e.gd,this.recordUndo=e.Qc)}toJson(){var e=super.toJson();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);return e.commentId=this.commentId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new sl),t.commentId=e.commentId,t}static CommentCreateDeleteHelper(e,t){var n=e.getEventWorkspace_();if(t){if(!e.json)throw Error(`Encountered a comment event without proper json`);wt(e.json,n)}else{if(!e.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);(t=n.getCommentById(e.commentId))?t.dispose():console.warn(`Can't delete non-existent comment: `+e.commentId)}}},cl=class extends sl{constructor(e,t,n){super(e),this.type=E.COMMENT_CHANGE,e&&(this.oldContents_=t===void 0?``:t,this.newContents_=n===void 0?``:n)}toJson(){var e=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 e.oldContents=this.oldContents_,e.newContents=this.newContents_,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new cl),t.oldContents_=e.oldContents,t.newContents_=e.newContents,t}isNull(){return this.oldContents_===this.newContents_}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){var n=e?this.newContents_:this.oldContents_;if(n===void 0)throw Error(e?`The new contents is undefined. Either pass a value to the constructor, or call fromJson`:`The old contents is undefined. Either pass a value to the constructor, or call fromJson`);t.setText(n)}else console.warn(`Can't change non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_CHANGE,cl);var ll=class extends sl{constructor(e,t){super(e),this.newCollapsed=t,this.type=E.COMMENT_COLLAPSE}toJson(){var e=super.toJson();if(this.newCollapsed===void 0)throw Error(`The new collapse value undefined. Either call recordNew, or call fromJson`);return e.newCollapsed=this.newCollapsed,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ll),t.newCollapsed=e.newCollapsed,t}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);(t=t.getCommentById(this.commentId))?t.setCollapsed(e?!!this.newCollapsed:!this.newCollapsed):console.warn(`Can't collapse or uncollapse non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_COLLAPSE,ll);var ul=class extends sl{constructor(e){super(e),this.type=E.COMMENT_CREATE,e&&(this.json=Ct(e,{addCoordinates:!0}))}toJson(){var e=super.toJson();if(!this.json)throw Error(`The comment JSON is undefined. Either pass a block to the constructor, or call fromJson`);return e.json=this.json,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ul),t.json=e.json,t}run(e){sl.CommentCreateDeleteHelper(this,e)}};y(M.EVENT,E.COMMENT_CREATE,ul);var dl=class extends sl{constructor(e){super(e),this.type=E.COMMENT_DELETE,e&&(this.json=Ct(e,{addCoordinates:!0}))}run(e){sl.CommentCreateDeleteHelper(this,!e)}toJson(){var e=super.toJson();if(!this.json)throw Error(`The comment JSON is undefined. Either pass a block to the constructor, or call fromJson`);return e.json=this.json,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new dl),t.json=e.json,t}};y(M.EVENT,E.COMMENT_DELETE,dl);var fl=class extends Xc{constructor(e,t){super(e?e.workspace.id:void 0),this.type=E.COMMENT_DRAG,e&&(this.commentId=e.id,this.isStart=t)}toJson(){var e=super.toJson();if(this.isStart===void 0)throw Error(`Whether this event is the start of a drag is undefined. Either pass the value to the constructor, or call fromJson`);if(this.commentId===void 0)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);return e.isStart=this.isStart,e.commentId=this.commentId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new fl),t.isStart=e.isStart,t.commentId=e.commentId,t}};y(M.EVENT,E.COMMENT_DRAG,fl);var pl=class extends sl{constructor(e){super(e),this.type=E.COMMENT_MOVE,e&&(this.comment_=e,this.oldCoordinate_=e.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()}setReason(e){this.reason=e}setOldCoordinate(e){this.oldCoordinate_=e}toJson(){var e=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 e.oldCoordinate=`${Math.round(this.oldCoordinate_.x)}, ${Math.round(this.oldCoordinate_.y)}`,e.newCoordinate=Math.round(this.newCoordinate_.x)+`,`+Math.round(this.newCoordinate_.y),e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new pl),n=e.oldCoordinate.split(`,`),t.oldCoordinate_=new N(Number(n[0]),Number(n[1])),n=e.newCoordinate.split(`,`),t.newCoordinate_=new N(Number(n[0]),Number(n[1])),t}isNull(){return N.equals(this.oldCoordinate_,this.newCoordinate_)}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){if(e=e?this.newCoordinate_:this.oldCoordinate_,!e)throw Error(`Either oldCoordinate_ or newCoordinate_ is undefined. Either pass a comment to the constructor and call recordNew, or call fromJson`);t.moveTo(e)}else console.warn(`Can't move non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_MOVE,pl);var ml=class extends sl{constructor(e){super(e),this.type=E.COMMENT_RESIZE,e&&(this.oldSize=e.getSize())}recordCurrentSizeAsNewSize(){if(this.newSize)throw Error(`Tried to record the new size of a comment on the same event twice.`);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),!e)throw Error(`The comment associated with the comment resize event could not be found`);this.newSize=e.getSize()}toJson(){var e=super.toJson();if(!this.oldSize)throw Error(`The old comment size is undefined. Either pass a comment to the constructor, or call fromJson`);if(!this.newSize)throw Error(`The new comment size is undefined. Either call recordCurrentSizeAsNewSize, or call fromJson`);return e.oldWidth=Math.round(this.oldSize.width),e.oldHeight=Math.round(this.oldSize.height),e.newWidth=Math.round(this.newSize.width),e.newHeight=Math.round(this.newSize.height),e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ml),t.oldSize=new F(e.oldWidth,e.oldHeight),t.newSize=new F(e.newWidth,e.newHeight),t}isNull(){return F.equals(this.oldSize,this.newSize)}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){if(e=e?this.newSize:this.oldSize,!e)throw Error(`Either oldSize or newSize is undefined. Either pass a comment to the constructor and call recordCurrentSizeAsNewSize, or call fromJson`);t.setSize(e)}else console.warn(`Can't resize non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_RESIZE,ml);var hl=class extends Xc{constructor(e,t,n){super(n),this.type=E.SELECTED,this.oldElementId=e??void 0,this.newElementId=t??void 0}toJson(){var e=super.toJson();return e.oldElementId=this.oldElementId,e.newElementId=this.newElementId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new hl),t.oldElementId=e.oldElementId,t.newElementId=e.newElementId,t}};y(M.EVENT,E.SELECTED,hl);var gl=class extends Xc{constructor(e,t){super(t),this.type=E.THEME_CHANGE,this.themeName=e}toJson(){var e=super.toJson();if(!this.themeName)throw Error(`The theme name is undefined. Either pass a theme name to the constructor, or call fromJson`);return e.themeName=this.themeName,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new gl),t.themeName=e.themeName,t}};y(M.EVENT,E.THEME_CHANGE,gl);var _l=class extends Xc{constructor(e,t,n){super(n),this.type=E.TOOLBOX_ITEM_SELECT,this.oldItem=e??void 0,this.newItem=t??void 0}toJson(){var e=super.toJson();return e.oldItem=this.oldItem,e.newItem=this.newItem,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new _l),t.oldItem=e.oldItem,t.newItem=e.newItem,t}};y(M.EVENT,E.TOOLBOX_ITEM_SELECT,_l);var vl=class extends Xc{constructor(e,t){super(t),this.type=E.TRASHCAN_OPEN,this.isOpen=e}toJson(){var e=super.toJson();if(this.isOpen===void 0)throw Error(`Whether this is already open or not is undefined. Either pass a value to the constructor, or call fromJson`);return e.isOpen=this.isOpen,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new vl),t.isOpen=e.isOpen,t}};y(M.EVENT,E.TRASHCAN_OPEN,vl);var yl=class extends Wc{constructor(e){super(),this.isBlank=!0,this.isBlank=e===void 0,e&&(this.varId=e.getId(),this.workspaceId=e.getWorkspace().id)}toJson(){var e=super.toJson();if(!this.varId)throw Error(`The var ID is undefined. Either pass a variable to the constructor, or call fromJson`);return e.varId=this.varId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new yl),t.varId=e.varId,t}},bl=class extends yl{constructor(e){super(e),this.type=E.VAR_CREATE,e&&(this.varType=e.getType(),this.varName=e.getName())}toJson(){var e=super.toJson();if(this.varType===void 0)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 e.varType=this.varType,e.varName=this.varName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new bl),t.varType=e.varType,t.varName=e.varName,t}run(e){var t=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=t.getVariableMap(),e?t.createVariable(this.varName,this.varType,this.varId):(e=t.getVariableById(this.varId))&&t.deleteVariable(e)}};y(M.EVENT,E.VAR_CREATE,bl);var xl=class extends yl{constructor(e){super(e),this.type=E.VAR_DELETE,e&&(this.varType=e.getType(),this.varName=e.getName())}toJson(){var e=super.toJson();if(this.varType===void 0)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 e.varType=this.varType,e.varName=this.varName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new xl),t.varType=e.varType,t.varName=e.varName,t}run(e){var t=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=t.getVariableMap(),e?(e=t.getVariableById(this.varId))&&t.deleteVariable(e):t.createVariable(this.varName,this.varType,this.varId)}};y(M.EVENT,E.VAR_DELETE,xl);var Sl=class extends yl{constructor(e,t){super(e),this.type=E.VAR_RENAME,e&&(this.oldName=e.getName(),this.newName=t===void 0?``:t)}toJson(){var e=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 e.oldName=this.oldName,e.newName=this.newName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new Sl),t.oldName=e.oldName,t.newName=e.newName,t}run(e){var t=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=t.getVariableMap();var n=t.getVariableById(this.varId);e?n&&t.renameVariable(n,this.newName):n&&t.renameVariable(n,this.oldName)}};y(M.EVENT,E.VAR_RENAME,Sl);var Cl=class extends yl{constructor(e,t,n){super(e),this.oldType=t,this.newType=n,this.type=E.VAR_TYPE_CHANGE}toJson(){var e=super.toJson();if(!this.oldType||!this.newType)throw Error(`The variable's types are undefined. Either pass them to the constructor, or call fromJson`);return e.oldType=this.oldType,e.newType=this.newType,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new Cl),t.oldType=e.oldType,t.newType=e.newType,t}run(e){var t=this.getEventWorkspace_();if(!this.varId)throw Error(`The var ID is undefined. Either pass a variable to the constructor, or call fromJson`);if(!this.oldType||!this.newType)throw Error(`The variable's types are undefined. Either pass them to the constructor, or call fromJson`);var n=t.getVariableMap().getVariableById(this.varId);n&&(e?t.getVariableMap().changeVariableType(n,this.newType):t.getVariableMap().changeVariableType(n,this.oldType))}};y(M.EVENT,E.VAR_TYPE_CHANGE,Cl);var wl=class extends Xc{constructor(e,t,n,r,i){super(r),this.type=E.VIEWPORT_CHANGE,this.viewTop=e,this.viewLeft=t,this.scale=n,this.oldScale=i}toJson(){var e=super.toJson();if(this.viewTop===void 0)throw Error(`The view top is undefined. Either pass a value to the constructor, or call fromJson`);if(this.viewLeft===void 0)throw Error(`The view left is undefined. Either pass a value to the constructor, or call fromJson`);if(this.scale===void 0)throw Error(`The scale is undefined. Either pass a value to the constructor, or call fromJson`);if(this.oldScale===void 0)throw Error(`The old scale is undefined. Either pass a value to the constructor, or call fromJson`);return e.viewTop=this.viewTop,e.viewLeft=this.viewLeft,e.scale=this.scale,e.oldScale=this.oldScale,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new wl),t.viewTop=e.viewTop,t.viewLeft=e.viewLeft,t.scale=e.scale,t.oldScale=e.oldScale,t}};y(M.EVENT,E.VIEWPORT_CHANGE,wl);var Tl=class extends Wc{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.type=E.FINISHED_LOADING,this.isBlank=!!e,e&&(this.workspaceId=e.id)}};y(M.EVENT,E.FINISHED_LOADING,Tl);var El,Dl,Ol,kl,Al,jl,Ml,Nl,Pl,Fl,Il,Ll,Rl,zl,Bl,Vl,Hl,Ul,Wl,Gl,Kl,ql,Jl,Yl,R;e.km=E.BLOCK_CHANGE,e.Od=E.BLOCK_CREATE,e.lm=E.BLOCK_DELETE,El=E.BLOCK_DRAG,e.nm=E.BLOCK_MOVE,Dl=E.BLOCK_FIELD_INTERMEDIATE_CHANGE,Ol=E.BUBBLE_OPEN,kl=E.BLOCK_CHANGE,Al=E.CLICK,jl=E.COMMENT_CHANGE,Ml=E.COMMENT_CREATE,Nl=E.COMMENT_DELETE,Pl=E.COMMENT_MOVE,Fl=E.COMMENT_RESIZE,Il=E.COMMENT_DRAG,Ll=E.BLOCK_CREATE,Rl=E.BLOCK_DELETE,zl=E.FINISHED_LOADING,Bl=E.BLOCK_MOVE,Vl=E.SELECTED,Hl=E.THEME_CHANGE,Ul=E.TOOLBOX_ITEM_SELECT,Wl=E.TRASHCAN_OPEN,Gl=E.UI,Kl=E.VAR_CREATE,ql=E.VAR_DELETE,Jl=E.VAR_RENAME,Yl=E.VIEWPORT_CHANGE,R={},R.Abstract=Wc,R.BLOCK_CHANGE=e.km,R.BLOCK_CREATE=e.Od,R.BLOCK_DELETE=e.lm,R.BLOCK_DRAG=El,R.BLOCK_FIELD_INTERMEDIATE_CHANGE=Dl,R.BLOCK_MOVE=e.nm,R.BUBBLE_OPEN=Ol,R.BUMP_EVENTS=Qo,R.BlockBase=Gc,R.BlockChange=qc,R.BlockCreate=Jc,R.BlockDelete=Yc,R.BlockDrag=Zc,R.BlockFieldIntermediateChange=Qc,R.BlockMove=el,R.BubbleOpen=tl,R.BubbleType=nl,R.CHANGE=kl,R.CLICK=Al,R.COMMENT_CHANGE=jl,R.COMMENT_CREATE=Ml,R.COMMENT_DELETE=Nl,R.COMMENT_DRAG=Il,R.COMMENT_MOVE=Pl,R.COMMENT_RESIZE=Fl,R.CREATE=Ll,R.Click=il,R.ClickTarget=al,R.CommentBase=sl,R.CommentChange=cl,R.CommentCollapse=ll,R.CommentCreate=ul,R.CommentDelete=dl,R.CommentDrag=fl,R.CommentMove=pl,R.CommentResize=ml,R.DELETE=Rl,R.FINISHED_LOADING=zl,R.FinishedLoading=Tl,R.MOVE=Bl,R.SELECTED=Vl,R.Selected=hl,R.THEME_CHANGE=Hl,R.TOOLBOX_ITEM_SELECT=Ul,R.TRASHCAN_OPEN=Wl,R.ThemeChange=gl,R.ToolboxItemSelect=_l,R.TrashcanOpen=vl,R.UI=Gl,R.UiBase=Xc,R.VAR_CREATE=Kl,R.VAR_DELETE=ql,R.VAR_RENAME=Jl,R.VIEWPORT_CHANGE=Yl,R.VarBase=yl,R.VarCreate=bl,R.VarDelete=xl,R.VarRename=Sl,R.VarTypeChange=Cl,R.ViewportChange=wl,R.clearPendingUndo=qe,R.disable=function(){e.Ub++},R.disableOrphans=function(t){if((t.type===E.BLOCK_MOVE||t.type===E.BLOCK_CREATE||t.type===E.BLOCK_DRAG&&!t.isStart)&&t.workspaceId){var n=xe(t.workspaceId);if(!t.blockId)throw Error(`Encountered a blockEvent without a proper blockId`);if(t=n.getBlockById(t.blockId)){let r=e.Qc;try{e.Qc=!1;let r=t.getParent();if(r&&!r.hasDisabledReason(`ORPHANED_BLOCK`)){let e=t.getDescendants(!1);for(let t=0,n;n=e[t];t++)n.setDisabledReason(!1,`ORPHANED_BLOCK`)}else if((t.outputConnection||t.previousConnection)&&!n.isDragging())do t.setDisabledReason(!0,`ORPHANED_BLOCK`),t=t.getNextBlock();while(t)}finally{e.Qc=r}}}},R.enable=function(){e.Ub--},R.filter=Ke,R.fire=b,R.fromJson=function(e,t){var n=x(e.type);if(!n)throw Error(`Unknown event type.`);return n.fromJson(e,t)},R.get=x,R.getDescendantIds=Ye,R.getGroup=function(){return e.gd},R.getRecordUndo=function(){return e.Qc},R.isEnabled=Je,R.setGroup=e.B,R.setRecordUndo=function(t){e.Qc=t};var Xl=class{constructor(){this.scopeChangeAudioCuesEnabled=this.isActive=!1,this.activeClassName=`blocklyKeyboardNavigation`}setIsActive(e=!0){this.isActive=e,this.updateActiveVisualization()}getIsActive(){return this.isActive}setScopeChangeAudioCuesEnabled(e){this.scopeChangeAudioCuesEnabled=e}getScopeChangeAudioCuesEnabled(){return this.scopeChangeAudioCuesEnabled}updateActiveVisualization(){var e=Os.getInjectionDiv().parentElement;this.isActive?e==null||e.classList.add(this.activeClassName):e==null||e.classList.remove(this.activeClassName)}},z=new Xl,Zl=new Intl.Collator(void 0,{sensitivity:`base`}),Ql={generateUniqueNameInternal:function(e){return Qt(`i`,e.getVariableMap().getAllVariables().map(e=>e.getName()))}},$l={CATEGORY_NAME:`VARIABLE`,TEST_ONLY:Ql,VAR_LETTER_OPTIONS:`ijkmnopqrstuvwxyzabcdefgh`};$l.allDeveloperVariables=e.Cd,$l.allUsedVarModels=e.Bd,$l.compareByName=ln,$l.createVariableButtonHandler=$t,$l.deleteVariable=e.$d,$l.flyoutCategory=Jt,$l.flyoutCategoryBlocks=function(t){t=t.getVariableMap().getVariablesOfType(``);var n=[];if(t.length>0){var r=t[t.length-1];if($o.variables_set){var i=e.rc(`block`);i.setAttribute(`type`,`variables_set`),i.setAttribute(`gap`,$o.math_change?`8`:`24`),i.appendChild(sn(r)),n.push(i)}if($o.math_change&&(i=e.rc(`block`),i.setAttribute(`type`,`math_change`),i.setAttribute(`gap`,$o.variables_get?`20`:`8`),i.appendChild(sn(r)),r=e.uc(`<value name="DELTA"><shadow type="math_number"><field name="NUM">1</field></shadow></value>`),i.appendChild(r),n.push(i)),$o.variables_get){t.sort(ln);for(let i=0,a;a=t[i];i++)r=e.rc(`block`),r.setAttribute(`type`,`variables_get`),r.setAttribute(`gap`,`8`),r.appendChild(sn(a)),n.push(r)}}return n},$l.generateUniqueName=Zt,$l.generateUniqueNameFromOptions=Qt,$l.generateVariableFieldDom=sn,$l.getAddedVariables=cn,$l.getOrCreateVariablePackage=e.Wd,$l.getVariable=e.Vd,$l.getVariableUsesById=un,$l.jsonFlyoutCategoryBlocks=Xt,$l.nameUsedWithAnyType=nn,$l.nameUsedWithConflictingParam=rn,$l.promptName=en,$l.renameVariable=e.Rd;var eu=class extends Error{},tu=class extends eu{constructor(e){super(`Expected to find a 'type' property, defining the block type`),this.state=e}},nu=class extends eu{constructor(e,t,n){super(`The block ${t.toDevString()} is missing a(n) ${e}
695
+ `);var Fc,Ic=Fc||={};Ic[Ic.ALERT=1]=`ALERT`,Ic[Ic.CONFIRM=2]=`CONFIRM`,Ic[Ic.PROMPT=3]=`PROMPT`;var Lc=0,Rc=Lt,zc=Rt,Bc=zt,Vc=Pc.show.bind(Pc),Hc=Vc,Uc={};Uc.alert=Bt,Uc.confirm=Vt,Uc.prompt=Ht,Uc.setAlert=function(e=Lt){Rc=e},Uc.setConfirm=function(e=Rt){zc=e},Uc.setPrompt=function(e=zt){Bc=e},Uc.setToast=function(e=Vc){Hc=e},Uc.toast=function(e,t){Hc(e,t)};var Wc=class{constructor(){this.workspaceId=void 0,this.isUiEvent=!1,this.type=``,this.group=e.gd,this.recordUndo=e.Qc}toJson(){return{type:this.type,group:this.group}}static fromJson(e,t,n){return n.isBlank=!1,n.group=e.group||``,n.workspaceId=t.id,n}isNull(){return!1}run(){}getEventWorkspace_(){var e;if(this.workspaceId&&(e=xe(this.workspaceId)),!e)throw Error(`Workspace is null. Event must have been generated from real Blockly events.`);return e}},Gc=class extends Wc{constructor(e){super(),this.isBlank=!0,this.isBlank=!e,e&&(this.blockId=e.id,this.workspaceId=e.workspace.id)}toJson(){var e=super.toJson();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);return e.blockId=this.blockId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new Gc),t.blockId=e.blockId,t}},Kc=class{constructor(e){this.name=e}toString(){return this.name}equals(e){return this.name===e.toString()}};Kc.MUTATOR=new Kc(`mutator`),Kc.WARNING=new Kc(`warning`),Kc.COMMENT=new Kc(`comment`);var qc=class extends Gc{constructor(e,t,n,r,i){super(e),this.type=E.BLOCK_CHANGE,e&&(this.element=t,this.name=n||void 0,this.oldValue=r,this.newValue=i)}toJson(){var e=super.toJson();if(!this.element)throw Error(`The changed element is undefined. Either pass an element to the constructor, or call fromJson`);return e.element=this.element,e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,this.disabledReason&&(e.disabledReason=this.disabledReason),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new qc),t.element=e.element,t.name=e.name,t.oldValue=e.oldValue,t.newValue=e.newValue,e.disabledReason!==void 0&&(t.disabledReason=e.disabledReason),t}setDisabledReason(e){if(this.element!==`disabled`)throw Error(`Cannot set the disabled reason for a BlockChange event if the element is not "disabled".`);this.disabledReason=e}isNull(){return this.oldValue===this.newValue}run(t){var n=this.getEventWorkspace_();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);if(n=n.getBlockById(this.blockId),!n)throw Error(`The associated block is undefined. Either pass a block to the constructor, or call fromJson`);var r=n.getIcon(Kc.MUTATOR);switch(r&&Wt(r)&&r.bubbleIsVisible()&&r.setBubbleVisible(!1),t=t?this.newValue:this.oldValue,this.element){case`field`:(n=n.getField(this.name))?n.setValue(t):console.warn(`Can't set non-existent field: `+this.name);break;case`comment`:n.setCommentText(t??null);break;case`collapsed`:n.setCollapsed(!!t);break;case`disabled`:var i;n.setDisabledReason(!!t,(i=this.disabledReason)??`MANUALLY_DISABLED`);break;case`inline`:n.setInputsInline(!!t);break;case`mutation`:i=qc.getExtraBlockState_(n),n.loadExtraState?n.loadExtraState(JSON.parse(t||`{}`)):n.domToMutation&&n.domToMutation(e.uc(t||`<mutation/>`)),b(new qc(n,`mutation`,null,i,t));break;default:console.warn(`Unknown change type: `+this.element)}}static getExtraBlockState_(e){return e.saveExtraState?(e=e.saveExtraState(!0))?JSON.stringify(e):``:e.mutationToDom&&(e=e.mutationToDom())?ti(e):``}};y(M.EVENT,E.BLOCK_CHANGE,qc);var Jc=class extends Gc{constructor(e){super(e),this.type=E.BLOCK_CREATE,e&&(e.isShadow()&&(this.recordUndo=!1),this.ids=Ye(e),this.json=dn(e,{addCoordinates:!0}))}toJson(){var e=super.toJson();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 e.ids=this.ids,e.json=this.json,this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Jc),t.ids=e.ids,t.json=e.json,e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}run(e){var t=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(!Gt(t,this.ids)){if(e)pn(this.json,t);else for(e=0;e<this.ids.length;e++){let n=this.ids[e],r=t.getBlockById(n);r?r.dispose(!1):n===this.blockId&&console.warn(`Can't uncreate non-existent block: `+n)}}}};y(M.EVENT,E.BLOCK_CREATE,Jc);var Yc=class extends Gc{constructor(e){if(super(e),this.type=E.BLOCK_DELETE,e){if(e.getParent())throw Error(`Connected blocks cannot be deleted.`);e.isShadow()&&(this.recordUndo=!1),this.ids=Ye(e),this.wasShadow=e.isShadow(),this.oldJson=dn(e,{addCoordinates:!0})}}toJson(){var e=super.toJson();if(!this.ids)throw Error(`The block IDs are undefined. Either pass a block to the constructor, or call fromJson`);if(this.wasShadow===void 0)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 e.ids=this.ids,e.wasShadow=this.wasShadow,e.oldJson=this.oldJson,this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Yc),t.ids=e.ids,t.wasShadow=e.wasShadow,t.oldJson=e.oldJson,e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}run(e){var t=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(e)for(e=0;e<this.ids.length;e++){let n=this.ids[e],r=t.getBlockById(n);r?r.dispose(!1):n===this.blockId&&console.warn(`Can't delete non-existent block: `+n)}else pn(this.oldJson,t)}};y(M.EVENT,E.BLOCK_DELETE,Yc);var Xc=class extends Wc{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.isUiEvent=!0,this.isBlank=e===void 0,this.workspaceId=e||``}},Zc=class extends Xc{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=E.BLOCK_DRAG,e&&(this.blockId=e.id,this.isStart=t,this.blocks=n)}toJson(){var e=super.toJson();if(this.isStart===void 0)throw Error(`Whether this event is the start of a drag is undefined. Either pass the value to the constructor, or call fromJson`);if(this.blockId===void 0)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);return e.isStart=this.isStart,e.blockId=this.blockId,e.blocks=this.blocks,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new Zc),t.isStart=e.isStart,t.blockId=e.blockId,t.blocks=e.blocks,t}};y(M.EVENT,E.BLOCK_DRAG,Zc);var Qc=class extends Gc{constructor(e,t,n,r){super(e),this.type=E.BLOCK_FIELD_INTERMEDIATE_CHANGE,this.recordUndo=!1,e&&(this.name=t,this.oldValue=n,this.newValue=r)}toJson(){var e=super.toJson();if(!this.name)throw Error(`The changed field name is undefined. Either pass a name to the constructor, or call fromJson.`);return e.name=this.name,e.oldValue=this.oldValue,e.newValue=this.newValue,e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new Qc),t.name=e.name,t.oldValue=e.oldValue,t.newValue=e.newValue,t}isNull(){return this.oldValue===this.newValue}run(e){var t=this.getEventWorkspace_();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);if(t=t.getBlockById(this.blockId),!t)throw Error(`The associated block is undefined. Either pass a block to the constructor, or call fromJson`);e=e?this.newValue:this.oldValue,(t=t.getField(this.name))?t.setValue(e):console.warn(`Can't set non-existent field: `+this.name)}};y(M.EVENT,E.BLOCK_FIELD_INTERMEDIATE_CHANGE,Qc);var L,$c=L||={};$c[$c.INPUT_VALUE=1]=`INPUT_VALUE`,$c[$c.OUTPUT_VALUE=2]=`OUTPUT_VALUE`,$c[$c.NEXT_STATEMENT=3]=`NEXT_STATEMENT`,$c[$c.PREVIOUS_STATEMENT=4]=`PREVIOUS_STATEMENT`;var el=class extends Gc{constructor(e){super(e),this.type=E.BLOCK_MOVE,e&&(e.isShadow()&&(this.recordUndo=!1),e=this.currentLocation(),this.oldParentId=e.parentId,this.oldInputName=e.inputName,this.oldCoordinate=e.coordinate)}toJson(){var e=super.toJson();return e.oldParentId=this.oldParentId,e.oldInputName=this.oldInputName,this.oldCoordinate&&(e.oldCoordinate=`${Math.round(this.oldCoordinate.x)}, ${Math.round(this.oldCoordinate.y)}`),e.newParentId=this.newParentId,e.newInputName=this.newInputName,this.newCoordinate&&(e.newCoordinate=`${Math.round(this.newCoordinate.x)}, ${Math.round(this.newCoordinate.y)}`),this.reason&&(e.reason=this.reason),this.recordUndo||(e.recordUndo=this.recordUndo),e}static fromJson(e,t,n){return t=Gc.fromJson(e,t,n??new el),t.oldParentId=e.oldParentId,t.oldInputName=e.oldInputName,e.oldCoordinate&&(n=e.oldCoordinate.split(`,`),t.oldCoordinate=new N(Number(n[0]),Number(n[1]))),t.newParentId=e.newParentId,t.newInputName=e.newInputName,e.newCoordinate&&(n=e.newCoordinate.split(`,`),t.newCoordinate=new N(Number(n[0]),Number(n[1]))),e.reason!==void 0&&(t.reason=e.reason),e.recordUndo!==void 0&&(t.recordUndo=e.recordUndo),t}recordNew(){var e=this.currentLocation();this.newParentId=e.parentId,this.newInputName=e.inputName,this.newCoordinate=e.coordinate}setReason(e){this.reason=e}currentLocation(){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 t=e.getBlockById(this.blockId);if(!t)throw Error(`The block associated with the block move event could not be found`);e={};var n=t.getParent();return n?(e.parentId=n.id,(t=n.getInputWithBlock(t))&&(e.inputName=t.name)):e.coordinate=t.getRelativeToSurfaceXY(),e}isNull(){return this.oldParentId===this.newParentId&&this.oldInputName===this.newInputName&&N.equals(this.oldCoordinate,this.newCoordinate)}run(e){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 n=t.getBlockById(this.blockId);if(n){var r=e?this.newParentId:this.oldParentId,i=e?this.newInputName:this.oldInputName;if(e=e?this.newCoordinate:this.oldCoordinate,r){var a=t.getBlockById(r);if(!a){console.warn(`Can't connect to non-existent block: `+r);return}}if(n.getParent()&&n.unplug(),e)i=n.getRelativeToSurfaceXY(),n.moveBy(e.x-i.x,e.y-i.y,this.reason);else{t=n.outputConnection,(!t||n.previousConnection&&n.previousConnection.isConnected())&&(t=n.previousConnection);let e,r;n=(r=t)==null?void 0:r.type,i?(n=a.getInput(i))&&(e=n.connection):n===L.PREVIOUS_STATEMENT&&(e=a.nextConnection),e&&t?t.connect(e):console.warn(`Can't connect to non-existent input: `+i)}}else console.warn(`Can't move non-existent block: `+this.blockId)}};y(M.EVENT,E.BLOCK_MOVE,el);var tl=class extends Xc{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=E.BUBBLE_OPEN,e&&(this.blockId=e.id,this.isOpen=t,this.bubbleType=n)}toJson(){var e=super.toJson();if(this.isOpen===void 0)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 e.isOpen=this.isOpen,e.bubbleType=this.bubbleType,e.blockId=this.blockId||``,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new tl),t.isOpen=e.isOpen,t.bubbleType=e.bubbleType,t.blockId=e.blockId,t}},nl,rl=nl||={};rl.MUTATOR=`mutator`,rl.COMMENT=`comment`,rl.WARNING=`warning`,y(M.EVENT,E.BUBBLE_OPEN,tl);var il=class extends Xc{constructor(e,t,n){t=e?e.workspace.id:t,t===null&&(t=void 0),super(t),this.type=E.CLICK,this.blockId=e?e.id:void 0,this.targetType=n}toJson(){var e=super.toJson();if(!this.targetType)throw Error(`The click target type is undefined. Either pass a block to the constructor, or call fromJson`);return e.targetType=this.targetType,e.blockId=this.blockId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new il),t.targetType=e.targetType,t.blockId=e.blockId,t}},al,ol=al||={};ol.BLOCK=`block`,ol.WORKSPACE=`workspace`,ol.ZOOM_CONTROLS=`zoom_controls`,y(M.EVENT,E.CLICK,il);var sl=class extends Wc{constructor(t){super(),this.isBlank=!0,this.isBlank=!t,t&&(this.commentId=t.id,this.workspaceId=t.workspace.id,this.group=e.gd,this.recordUndo=e.Qc)}toJson(){var e=super.toJson();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);return e.commentId=this.commentId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new sl),t.commentId=e.commentId,t}static CommentCreateDeleteHelper(e,t){var n=e.getEventWorkspace_();if(t){if(!e.json)throw Error(`Encountered a comment event without proper json`);wt(e.json,n)}else{if(!e.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);(t=n.getCommentById(e.commentId))?t.dispose():console.warn(`Can't delete non-existent comment: `+e.commentId)}}},cl=class extends sl{constructor(e,t,n){super(e),this.type=E.COMMENT_CHANGE,e&&(this.oldContents_=t===void 0?``:t,this.newContents_=n===void 0?``:n)}toJson(){var e=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 e.oldContents=this.oldContents_,e.newContents=this.newContents_,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new cl),t.oldContents_=e.oldContents,t.newContents_=e.newContents,t}isNull(){return this.oldContents_===this.newContents_}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){var n=e?this.newContents_:this.oldContents_;if(n===void 0)throw Error(e?`The new contents is undefined. Either pass a value to the constructor, or call fromJson`:`The old contents is undefined. Either pass a value to the constructor, or call fromJson`);t.setText(n)}else console.warn(`Can't change non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_CHANGE,cl);var ll=class extends sl{constructor(e,t){super(e),this.newCollapsed=t,this.type=E.COMMENT_COLLAPSE}toJson(){var e=super.toJson();if(this.newCollapsed===void 0)throw Error(`The new collapse value undefined. Either call recordNew, or call fromJson`);return e.newCollapsed=this.newCollapsed,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ll),t.newCollapsed=e.newCollapsed,t}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);(t=t.getCommentById(this.commentId))?t.setCollapsed(e?!!this.newCollapsed:!this.newCollapsed):console.warn(`Can't collapse or uncollapse non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_COLLAPSE,ll);var ul=class extends sl{constructor(e){super(e),this.type=E.COMMENT_CREATE,e&&(this.json=Ct(e,{addCoordinates:!0}))}toJson(){var e=super.toJson();if(!this.json)throw Error(`The comment JSON is undefined. Either pass a block to the constructor, or call fromJson`);return e.json=this.json,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ul),t.json=e.json,t}run(e){sl.CommentCreateDeleteHelper(this,e)}};y(M.EVENT,E.COMMENT_CREATE,ul);var dl=class extends sl{constructor(e){super(e),this.type=E.COMMENT_DELETE,e&&(this.json=Ct(e,{addCoordinates:!0}))}run(e){sl.CommentCreateDeleteHelper(this,!e)}toJson(){var e=super.toJson();if(!this.json)throw Error(`The comment JSON is undefined. Either pass a block to the constructor, or call fromJson`);return e.json=this.json,e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new dl),t.json=e.json,t}};y(M.EVENT,E.COMMENT_DELETE,dl);var fl=class extends Xc{constructor(e,t){super(e?e.workspace.id:void 0),this.type=E.COMMENT_DRAG,e&&(this.commentId=e.id,this.isStart=t)}toJson(){var e=super.toJson();if(this.isStart===void 0)throw Error(`Whether this event is the start of a drag is undefined. Either pass the value to the constructor, or call fromJson`);if(this.commentId===void 0)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);return e.isStart=this.isStart,e.commentId=this.commentId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new fl),t.isStart=e.isStart,t.commentId=e.commentId,t}};y(M.EVENT,E.COMMENT_DRAG,fl);var pl=class extends sl{constructor(e){super(e),this.type=E.COMMENT_MOVE,e&&(this.comment_=e,this.oldCoordinate_=e.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()}setReason(e){this.reason=e}setOldCoordinate(e){this.oldCoordinate_=e}toJson(){var e=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 e.oldCoordinate=`${Math.round(this.oldCoordinate_.x)}, ${Math.round(this.oldCoordinate_.y)}`,e.newCoordinate=Math.round(this.newCoordinate_.x)+`,`+Math.round(this.newCoordinate_.y),e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new pl),n=e.oldCoordinate.split(`,`),t.oldCoordinate_=new N(Number(n[0]),Number(n[1])),n=e.newCoordinate.split(`,`),t.newCoordinate_=new N(Number(n[0]),Number(n[1])),t}isNull(){return N.equals(this.oldCoordinate_,this.newCoordinate_)}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){if(e=e?this.newCoordinate_:this.oldCoordinate_,!e)throw Error(`Either oldCoordinate_ or newCoordinate_ is undefined. Either pass a comment to the constructor and call recordNew, or call fromJson`);t.moveTo(e)}else console.warn(`Can't move non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_MOVE,pl);var ml=class extends sl{constructor(e){super(e),this.type=E.COMMENT_RESIZE,e&&(this.oldSize=e.getSize())}recordCurrentSizeAsNewSize(){if(this.newSize)throw Error(`Tried to record the new size of a comment on the same event twice.`);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),!e)throw Error(`The comment associated with the comment resize event could not be found`);this.newSize=e.getSize()}toJson(){var e=super.toJson();if(!this.oldSize)throw Error(`The old comment size is undefined. Either pass a comment to the constructor, or call fromJson`);if(!this.newSize)throw Error(`The new comment size is undefined. Either call recordCurrentSizeAsNewSize, or call fromJson`);return e.oldWidth=Math.round(this.oldSize.width),e.oldHeight=Math.round(this.oldSize.height),e.newWidth=Math.round(this.newSize.width),e.newHeight=Math.round(this.newSize.height),e}static fromJson(e,t,n){return t=sl.fromJson(e,t,n??new ml),t.oldSize=new F(e.oldWidth,e.oldHeight),t.newSize=new F(e.newWidth,e.newHeight),t}isNull(){return F.equals(this.oldSize,this.newSize)}run(e){var t=this.getEventWorkspace_();if(!this.commentId)throw Error(`The comment ID is undefined. Either pass a comment to the constructor, or call fromJson`);if(t=t.getCommentById(this.commentId)){if(e=e?this.newSize:this.oldSize,!e)throw Error(`Either oldSize or newSize is undefined. Either pass a comment to the constructor and call recordCurrentSizeAsNewSize, or call fromJson`);t.setSize(e)}else console.warn(`Can't resize non-existent comment: `+this.commentId)}};y(M.EVENT,E.COMMENT_RESIZE,ml);var hl=class extends Xc{constructor(e,t,n){super(n),this.type=E.SELECTED,this.oldElementId=e??void 0,this.newElementId=t??void 0}toJson(){var e=super.toJson();return e.oldElementId=this.oldElementId,e.newElementId=this.newElementId,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new hl),t.oldElementId=e.oldElementId,t.newElementId=e.newElementId,t}};y(M.EVENT,E.SELECTED,hl);var gl=class extends Xc{constructor(e,t){super(t),this.type=E.THEME_CHANGE,this.themeName=e}toJson(){var e=super.toJson();if(!this.themeName)throw Error(`The theme name is undefined. Either pass a theme name to the constructor, or call fromJson`);return e.themeName=this.themeName,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new gl),t.themeName=e.themeName,t}};y(M.EVENT,E.THEME_CHANGE,gl);var _l=class extends Xc{constructor(e,t,n){super(n),this.type=E.TOOLBOX_ITEM_SELECT,this.oldItem=e??void 0,this.newItem=t??void 0}toJson(){var e=super.toJson();return e.oldItem=this.oldItem,e.newItem=this.newItem,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new _l),t.oldItem=e.oldItem,t.newItem=e.newItem,t}};y(M.EVENT,E.TOOLBOX_ITEM_SELECT,_l);var vl=class extends Xc{constructor(e,t){super(t),this.type=E.TRASHCAN_OPEN,this.isOpen=e}toJson(){var e=super.toJson();if(this.isOpen===void 0)throw Error(`Whether this is already open or not is undefined. Either pass a value to the constructor, or call fromJson`);return e.isOpen=this.isOpen,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new vl),t.isOpen=e.isOpen,t}};y(M.EVENT,E.TRASHCAN_OPEN,vl);var yl=class extends Wc{constructor(e){super(),this.isBlank=!0,this.isBlank=e===void 0,e&&(this.varId=e.getId(),this.workspaceId=e.getWorkspace().id)}toJson(){var e=super.toJson();if(!this.varId)throw Error(`The var ID is undefined. Either pass a variable to the constructor, or call fromJson`);return e.varId=this.varId,e}static fromJson(e,t,n){return t=Wc.fromJson(e,t,n??new yl),t.varId=e.varId,t}},bl=class extends yl{constructor(e){super(e),this.type=E.VAR_CREATE,e&&(this.varType=e.getType(),this.varName=e.getName())}toJson(){var e=super.toJson();if(this.varType===void 0)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 e.varType=this.varType,e.varName=this.varName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new bl),t.varType=e.varType,t.varName=e.varName,t}run(e){var t=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=t.getVariableMap(),e?t.createVariable(this.varName,this.varType,this.varId):(e=t.getVariableById(this.varId))&&t.deleteVariable(e)}};y(M.EVENT,E.VAR_CREATE,bl);var xl=class extends yl{constructor(e){super(e),this.type=E.VAR_DELETE,e&&(this.varType=e.getType(),this.varName=e.getName())}toJson(){var e=super.toJson();if(this.varType===void 0)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 e.varType=this.varType,e.varName=this.varName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new xl),t.varType=e.varType,t.varName=e.varName,t}run(e){var t=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=t.getVariableMap(),e?(e=t.getVariableById(this.varId))&&t.deleteVariable(e):t.createVariable(this.varName,this.varType,this.varId)}};y(M.EVENT,E.VAR_DELETE,xl);var Sl=class extends yl{constructor(e,t){super(e),this.type=E.VAR_RENAME,e&&(this.oldName=e.getName(),this.newName=t===void 0?``:t)}toJson(){var e=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 e.oldName=this.oldName,e.newName=this.newName,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new Sl),t.oldName=e.oldName,t.newName=e.newName,t}run(e){var t=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=t.getVariableMap();var n=t.getVariableById(this.varId);e?n&&t.renameVariable(n,this.newName):n&&t.renameVariable(n,this.oldName)}};y(M.EVENT,E.VAR_RENAME,Sl);var Cl=class extends yl{constructor(e,t,n){super(e),this.oldType=t,this.newType=n,this.type=E.VAR_TYPE_CHANGE}toJson(){var e=super.toJson();if(!this.oldType||!this.newType)throw Error(`The variable's types are undefined. Either pass them to the constructor, or call fromJson`);return e.oldType=this.oldType,e.newType=this.newType,e}static fromJson(e,t,n){return t=yl.fromJson(e,t,n??new Cl),t.oldType=e.oldType,t.newType=e.newType,t}run(e){var t=this.getEventWorkspace_();if(!this.varId)throw Error(`The var ID is undefined. Either pass a variable to the constructor, or call fromJson`);if(!this.oldType||!this.newType)throw Error(`The variable's types are undefined. Either pass them to the constructor, or call fromJson`);var n=t.getVariableMap().getVariableById(this.varId);n&&(e?t.getVariableMap().changeVariableType(n,this.newType):t.getVariableMap().changeVariableType(n,this.oldType))}};y(M.EVENT,E.VAR_TYPE_CHANGE,Cl);var wl=class extends Xc{constructor(e,t,n,r,i){super(r),this.type=E.VIEWPORT_CHANGE,this.viewTop=e,this.viewLeft=t,this.scale=n,this.oldScale=i}toJson(){var e=super.toJson();if(this.viewTop===void 0)throw Error(`The view top is undefined. Either pass a value to the constructor, or call fromJson`);if(this.viewLeft===void 0)throw Error(`The view left is undefined. Either pass a value to the constructor, or call fromJson`);if(this.scale===void 0)throw Error(`The scale is undefined. Either pass a value to the constructor, or call fromJson`);if(this.oldScale===void 0)throw Error(`The old scale is undefined. Either pass a value to the constructor, or call fromJson`);return e.viewTop=this.viewTop,e.viewLeft=this.viewLeft,e.scale=this.scale,e.oldScale=this.oldScale,e}static fromJson(e,t,n){return t=Xc.fromJson(e,t,n??new wl),t.viewTop=e.viewTop,t.viewLeft=e.viewLeft,t.scale=e.scale,t.oldScale=e.oldScale,t}};y(M.EVENT,E.VIEWPORT_CHANGE,wl);var Tl=class extends Wc{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.type=E.FINISHED_LOADING,this.isBlank=!!e,e&&(this.workspaceId=e.id)}};y(M.EVENT,E.FINISHED_LOADING,Tl);var El,Dl,Ol,kl,Al,jl,Ml,Nl,Pl,Fl,Il,Ll,Rl,zl,Bl,Vl,Hl,Ul,Wl,Gl,Kl,ql,Jl,Yl,R;e.km=E.BLOCK_CHANGE,e.Od=E.BLOCK_CREATE,e.lm=E.BLOCK_DELETE,El=E.BLOCK_DRAG,e.nm=E.BLOCK_MOVE,Dl=E.BLOCK_FIELD_INTERMEDIATE_CHANGE,Ol=E.BUBBLE_OPEN,kl=E.BLOCK_CHANGE,Al=E.CLICK,jl=E.COMMENT_CHANGE,Ml=E.COMMENT_CREATE,Nl=E.COMMENT_DELETE,Pl=E.COMMENT_MOVE,Fl=E.COMMENT_RESIZE,Il=E.COMMENT_DRAG,Ll=E.BLOCK_CREATE,Rl=E.BLOCK_DELETE,zl=E.FINISHED_LOADING,Bl=E.BLOCK_MOVE,Vl=E.SELECTED,Hl=E.THEME_CHANGE,Ul=E.TOOLBOX_ITEM_SELECT,Wl=E.TRASHCAN_OPEN,Gl=E.UI,Kl=E.VAR_CREATE,ql=E.VAR_DELETE,Jl=E.VAR_RENAME,Yl=E.VIEWPORT_CHANGE,R={},R.Abstract=Wc,R.BLOCK_CHANGE=e.km,R.BLOCK_CREATE=e.Od,R.BLOCK_DELETE=e.lm,R.BLOCK_DRAG=El,R.BLOCK_FIELD_INTERMEDIATE_CHANGE=Dl,R.BLOCK_MOVE=e.nm,R.BUBBLE_OPEN=Ol,R.BUMP_EVENTS=Qo,R.BlockBase=Gc,R.BlockChange=qc,R.BlockCreate=Jc,R.BlockDelete=Yc,R.BlockDrag=Zc,R.BlockFieldIntermediateChange=Qc,R.BlockMove=el,R.BubbleOpen=tl,R.BubbleType=nl,R.CHANGE=kl,R.CLICK=Al,R.COMMENT_CHANGE=jl,R.COMMENT_CREATE=Ml,R.COMMENT_DELETE=Nl,R.COMMENT_DRAG=Il,R.COMMENT_MOVE=Pl,R.COMMENT_RESIZE=Fl,R.CREATE=Ll,R.Click=il,R.ClickTarget=al,R.CommentBase=sl,R.CommentChange=cl,R.CommentCollapse=ll,R.CommentCreate=ul,R.CommentDelete=dl,R.CommentDrag=fl,R.CommentMove=pl,R.CommentResize=ml,R.DELETE=Rl,R.FINISHED_LOADING=zl,R.FinishedLoading=Tl,R.MOVE=Bl,R.SELECTED=Vl,R.Selected=hl,R.THEME_CHANGE=Hl,R.TOOLBOX_ITEM_SELECT=Ul,R.TRASHCAN_OPEN=Wl,R.ThemeChange=gl,R.ToolboxItemSelect=_l,R.TrashcanOpen=vl,R.UI=Gl,R.UiBase=Xc,R.VAR_CREATE=Kl,R.VAR_DELETE=ql,R.VAR_RENAME=Jl,R.VIEWPORT_CHANGE=Yl,R.VarBase=yl,R.VarCreate=bl,R.VarDelete=xl,R.VarRename=Sl,R.VarTypeChange=Cl,R.ViewportChange=wl,R.clearPendingUndo=qe,R.disable=function(){e.Ub++},R.disableOrphans=function(t){if((t.type===E.BLOCK_MOVE||t.type===E.BLOCK_CREATE||t.type===E.BLOCK_DRAG&&!t.isStart)&&t.workspaceId){var n=xe(t.workspaceId);if(!t.blockId)throw Error(`Encountered a blockEvent without a proper blockId`);if(t=n.getBlockById(t.blockId)){let r=e.Qc;try{e.Qc=!1;let r=t.getParent();if(r&&!r.hasDisabledReason(`ORPHANED_BLOCK`)){let e=t.getDescendants(!1);for(let t=0,n;n=e[t];t++)n.setDisabledReason(!1,`ORPHANED_BLOCK`)}else if((t.outputConnection||t.previousConnection)&&!n.isDragging())do t.setDisabledReason(!0,`ORPHANED_BLOCK`),t=t.getNextBlock();while(t)}finally{e.Qc=r}}}},R.enable=function(){e.Ub--},R.filter=Ke,R.fire=b,R.fromJson=function(e,t){var n=x(e.type);if(!n)throw Error(`Unknown event type.`);return n.fromJson(e,t)},R.get=x,R.getDescendantIds=Ye,R.getGroup=function(){return e.gd},R.getRecordUndo=function(){return e.Qc},R.isEnabled=Je,R.setGroup=e.B,R.setRecordUndo=function(t){e.Qc=t};var Xl=class{constructor(){this.scopeChangeAudioCuesEnabled=this.isActive=!1,this.activeClassName=`blocklyKeyboardNavigation`}setIsActive(e=!0){this.isActive=e,this.updateActiveVisualization()}getIsActive(){return this.isActive}setScopeChangeAudioCuesEnabled(e){this.scopeChangeAudioCuesEnabled=e}getScopeChangeAudioCuesEnabled(){return this.scopeChangeAudioCuesEnabled}updateActiveVisualization(){var e=Os.getInjectionDiv().parentElement;this.isActive?e==null||e.classList.add(this.activeClassName):e==null||e.classList.remove(this.activeClassName)}},z=new Xl,Zl=new Intl.Collator(void 0,{sensitivity:`base`}),Ql={generateUniqueNameInternal:function(e){return Qt(`i`,e.getVariableMap().getAllVariables().map(e=>e.getName()))}},$l={CATEGORY_NAME:`VARIABLE`,TEST_ONLY:Ql,VAR_LETTER_OPTIONS:`ijkmnopqrstuvwxyzabcdefgh`};$l.allDeveloperVariables=e.Cd,$l.allUsedVarModels=e.Bd,$l.compareByName=ln,$l.createVariableButtonHandler=$t,$l.deleteVariable=e.$d,$l.flyoutCategory=Jt,$l.flyoutCategoryBlocks=function(t){t=t.getVariableMap().getVariablesOfType(``);var n=[];if(t.length>0){var r=t[t.length-1];if($o.variables_set){var i=e.rc(`block`);i.setAttribute(`type`,`variables_set`),i.setAttribute(`gap`,$o.math_change?`8`:`24`),i.appendChild(sn(r)),n.push(i)}if($o.math_change&&(i=e.rc(`block`),i.setAttribute(`type`,`math_change`),i.setAttribute(`gap`,$o.variables_get?`20`:`8`),i.appendChild(sn(r)),r=e.uc(`<value name="DELTA"><shadow type="math_number"><field name="NUM">1</field></shadow></value>`),i.appendChild(r),n.push(i)),$o.variables_get){t.sort(ln);for(let i=0,a;a=t[i];i++)r=e.rc(`block`),r.setAttribute(`type`,`variables_get`),r.setAttribute(`gap`,`8`),r.appendChild(sn(a)),n.push(r)}}return n},$l.generateUniqueName=Zt,$l.generateUniqueNameFromOptions=Qt,$l.generateVariableFieldDom=sn,$l.getAddedVariables=cn,$l.getOrCreateVariablePackage=e.Wd,$l.getVariable=e.Vd,$l.getVariableUsesById=un,$l.jsonFlyoutCategoryBlocks=Xt,$l.nameUsedWithAnyType=nn,$l.nameUsedWithConflictingParam=rn,$l.promptName=en,$l.renameVariable=e.Rd;var eu=class extends Error{},tu=class extends eu{constructor(e){super(`Expected to find a 'type' property, defining the block type`),this.state=e}},nu=class extends eu{constructor(e,t,n){super(`The block ${t.toDevString()} is missing a(n) ${e}
696
696
  connection`),this.block=t,this.state=n}},ru=class extends eu{constructor(e,t,n,r){super(`The block ${n.toDevString()} could not connect its
697
697
  ${t} to its parent, because: ${e}`),this.childBlock=n,this.childState=r}},iu=class extends eu{constructor(e){super(`Encountered a real block which is defined as a child of a shadow
698
698
  block. It is an invariant of Blockly that shadow blocks only have shadow
@@ -822,7 +822,7 @@ children`),this.state=e}},au=class extends eu{constructor(e,t,n){super(`Cannot a
822
822
  width: 100%;
823
823
  height: 100%;
824
824
  }
825
- `);var Fd=class{constructor(e){this.connectionChecker=e,this.connections=[],this.bulkCounter=0}addConnection(e,t){t=this.calculateIndexForYPos(t),this.connections.splice(t,0,e)}findIndexOfConnection(e,t){if(!this.connections.length)return-1;var n=this.calculateIndexForYPos(t);if(n>=this.connections.length)return-1;t=e.y;for(var r=n;r>=0&&this.connections[r].y===t;){if(this.connections[r]===e)return r;r--}for(r=n;r<this.connections.length&&this.connections[r].y===t;){if(this.connections[r]===e)return r;r++}return-1}calculateIndexForYPos(e){if(!this.connections.length)return 0;for(var t=0,n=this.connections.length;t<n;){let r=Math.floor((t+n)/2);if(this.connections[r].y<e)t=r+1;else if(this.connections[r].y>e)n=r;else{t=r;break}}return t}removeConnection(e,t){if(e=this.findIndexOfConnection(e,t),e===-1)throw Error(`Unable to find connection in connectionDB.`);this.connections.splice(e,1)}reorderConnection(e,t){this.bulkCounter===0&&(this.removeConnection(e,e.y),this.addConnection(e,t))}getNeighbours(e,t){function n(e){var n=i-r[e].x,o=a-r[e].y;return Math.sqrt(n*n+o*o)<=t&&c.push(r[e]),o<t}var r=this.connections,i=e.x,a=e.y;e=0;for(var o=r.length-2,s=o;e<s;)r[s].y<a?e=s:o=s,s=Math.floor((e+o)/2);var c=[];if(o=e=s,r.length){for(;e>=0&&n(e);)e--;do o++;while(o<r.length&&n(o))}return c}isInYRange(e,t,n){return Math.abs(this.connections[e].y-t)<=n}searchForClosest(e,t,n){if(!this.connections.length)return{connection:null,radius:t};var r=e.y,i=e.x;e.x=i+n.x,e.y=r+n.y;var a=this.calculateIndexForYPos(e.y);n=null;for(var o=t,s,c=a-1;c>=0&&this.isInYRange(c,e.y,t);)s=this.connections[c],this.connectionChecker.canConnect(e,s,!0,o)&&(n=s,o=s.distanceFrom(e)),c--;for(;a<this.connections.length&&this.isInYRange(a,e.y,t);)s=this.connections[a],this.connectionChecker.canConnect(e,s,!0,o)&&(n=s,o=s.distanceFrom(e)),a++;return e.x=i,e.y=r,{connection:n,radius:o}}beginBulkUpdates(){this.bulkCounter++}endBulkUpdates(){if(this.bulkCounter===0)throw Error(`Bulk updates are already ended.`);this.bulkCounter--,this.bulkCounter===0&&this.reorderConnections()}reorderConnections(){this.connections.sort((e,t)=>e.y-t.y)}static init(e){var t=[];return t[L.INPUT_VALUE]=new Fd(e),t[L.OUTPUT_VALUE]=new Fd(e),t[L.NEXT_STATEMENT]=new Fd(e),t[L.PREVIOUS_STATEMENT]=new Fd(e),t}},q=class{constructor(e,t){if(this.type=t,this.targetConnection=null,this.disposed=!1,this.shadowDom=this.check=null,this.y=this.x=0,this.shadowState=null,this.sourceBlock_=e,e.id.includes(`_connection`))throw Error(`Connection ID indicator is contained in block ID. This will cause problems with focus: ${e.id}.`);this.id=`${e.id}_connection_${He()}`}connect_(e){var t=L.INPUT_VALUE,n=this.getSourceBlock(),r=e.getSourceBlock();if(e.isConnected()&&e.disconnectInternal(!1),this.isConnected()){let e=this.stashShadowState(),t=this.targetBlock();if(t.isShadow())t.dispose(!1);else{this.disconnectInternal();var i=t}this.applyShadowState(e)}if(Je()){var a=new(x(E.BLOCK_MOVE))(r);a.setReason([`connect`])}if(!this||!e)throw Error(`Cannot connect null connections.`);this.targetConnection=e,e.targetConnection=this,r.setParent(n),a&&(a.recordNew(),b(a)),i&&(e=this.type===t?i.outputConnection:i.previousConnection)&&((r=q.getConnectionForOrphanedConnection(r,e))?e.connect(r):e.onFailedConnect(this))}dispose(){if(this.isConnected()){this.isSuperior()&&this.setShadowStateInternal();let e=this.targetBlock();e&&!e.isDeadOrDying()&&e.unplug()}this.disposed=!0}getSourceBlock(){return this.sourceBlock_}isSuperior(){return this.type===L.INPUT_VALUE||this.type===L.NEXT_STATEMENT}isConnected(){return!!this.targetConnection}getConnectionChecker(){return this.sourceBlock_.workspace.connectionChecker}onFailedConnect(){}connect(t){if(this.targetConnection===t)return!0;if(this.getConnectionChecker().canConnect(this,t,!1)){let n=e.gd;n||e.B(!0),this.isSuperior()?this.connect_(t):t.connect_(this),e.B(n)}return this.isConnected()}disconnect(){this.disconnectInternal()}disconnectInternal(t=!0){var{parentConnection:n,childConnection:r}=this.getParentAndChildConnections();if(!n||!r)throw Error(`Source connection not connected.`);var i=e.gd;if(i||e.B(!0),Je()){var a=new(x(E.BLOCK_MOVE))(r.getSourceBlock());a.setReason([`disconnect`])}var o=this.targetConnection;o&&(o.targetConnection=null),this.targetConnection=null,t&&r.getSourceBlock().setParent(null),a&&(a.recordNew(),b(a)),r.getSourceBlock().isShadow()||n.respawnShadow_(),e.B(i)}getParentAndChildConnections(){return this.targetConnection?this.isSuperior()?{parentConnection:this,childConnection:this.targetConnection}:{parentConnection:this.targetConnection,childConnection:this}:{}}respawnShadow_(){this.createShadowBlock(!0)}reconnect(e,t){if(this.getSourceBlock().isDeadOrDying())return!1;var n;return t=(n=e.getInput(t))==null?void 0:n.connection,n=this.targetBlock(),n&&n!==e||!t||t.targetConnection===this?!1:(t.isConnected()&&t.disconnect(),t.connect(this),!0)}targetBlock(){if(this.isConnected()){let e;return((e=this.targetConnection)==null?void 0:e.getSourceBlock())??null}return null}onCheckChanged_(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||(this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug()}setCheck(e){return e?(Array.isArray(e)||(e=[e]),this.check=e,this.onCheckChanged_()):this.check=null,this}getCheck(){return this.check}setShadowDom(e){this.setShadowStateInternal({shadowDom:e})}getShadowDom(e){return e&&this.targetBlock().isShadow()?$r(this.targetBlock()):this.shadowDom}setShadowState(e){this.setShadowStateInternal({shadowState:e})}getShadowState(e){return e&&this.targetBlock()&&this.targetBlock().isShadow()?dn(this.targetBlock()):this.shadowState}neighbours(){return[]}getParentInput(){var e=null,t=this.sourceBlock_.inputList;for(let n=0;n<t.length;n++)if(t[n].connection===this){e=t[n];break}return e}toString(){var e=this.sourceBlock_;if(!e)return`Orphan Connection`;if(e.outputConnection===this)var t=`Output Connection of `;else if(e.previousConnection===this)t=`Previous Connection of `;else if(e.nextConnection===this)t=`Next Connection of `;else{t=null;for(let n=0,r;r=e.inputList[n];n++)if(r.connection===this){t=r;break}if(t)t=`Input "`+t.name+`" connection on `;else return console.warn(`Connection not actually connected to sourceBlock_`),`Orphan Connection`}return t+e.toDevString()}stashShadowState(){var e=this.getShadowDom(!0),t=this.getShadowState(!0);return this.shadowState=this.shadowDom=null,{shadowDom:e,shadowState:t}}applyShadowState({shadowDom:e,shadowState:t}){this.shadowDom=e,this.shadowState=t}setShadowStateInternal({shadowDom:e=null,shadowState:t=null}={}){this.shadowDom=e,this.shadowState=t,this.getSourceBlock().isDeadOrDying()||((e=this.targetBlock())?e.isShadow()?(e.dispose(!1),this.respawnShadow_(),this.targetBlock()&&this.targetBlock().isShadow()&&this.serializeShadow(this.targetBlock())):(e=this.createShadowBlock(!1),this.serializeShadow(e),e&&e.dispose(!1)):(this.respawnShadow_(),this.targetBlock()&&this.targetBlock().isShadow()&&this.serializeShadow(this.targetBlock())))}createShadowBlock(e){var t=this.getSourceBlock(),n=this.getShadowState(),r=this.getShadowDom();if(t.isDeadOrDying()||!n&&!r)return null;if(n)return t=mn(n,t.workspace,{parentConnection:e?this:void 0,isShadow:!0,recordUndo:!1});if(r){if(t=ri(r,t.workspace),e)if(this.type===L.INPUT_VALUE){if(!t.outputConnection)throw Error(`Shadow block is missing an output connection`);if(!this.connect(t.outputConnection))throw Error(`Could not connect shadow block to connection`)}else if(this.type===L.NEXT_STATEMENT){if(!t.previousConnection)throw Error(`Shadow block is missing previous connection`);if(!this.connect(t.previousConnection))throw Error(`Could not connect shadow block to connection`)}else throw Error(`Cannot connect a shadow block to a previous/output connection`);return t}return null}serializeShadow(e){e&&(this.shadowDom=$r(e),this.shadowState=dn(e))}static getConnectionForOrphanedConnection(e,t){if(t.type===L.OUTPUT_VALUE){a:{t=t.getSourceBlock();for(var n;n=Si(e,t);)if(e=n.targetBlock(),!e||e.isShadow()){t=n;break a}t=null}return t}return e=e.lastConnectionInStack(!0),n=t.getConnectionChecker(),e&&n.canConnect(t,e,!1)?e:null}};q.CAN_CONNECT=0,q.REASON_SELF_CONNECTION=1,q.REASON_WRONG_TYPE=2,q.REASON_TARGET_NULL=3,q.REASON_CHECKS_FAILED=4,q.REASON_DIFFERENT_WORKSPACES=5,q.REASON_SHADOW_PARENT=6,q.REASON_DRAG_CHECKS_FAILED=7,q.REASON_PREVIOUS_AND_OUTPUT=8;var Id=class extends Error{constructor(e){super(`Tried to append an icon of type ${e.getType()} when an icon of that type already exists on the block. Use getIcon to access the existing icon.`),this.icon=e}},Ld={};Ld.DuplicateIconType=Id;var Rd=e.En||={};Rd[Rd.LEFT=-1]=`LEFT`,Rd[Rd.CENTRE=0]=`CENTRE`,Rd[Rd.RIGHT=1]=`RIGHT`;var zd=[];zd[L.INPUT_VALUE]=L.OUTPUT_VALUE,zd[L.OUTPUT_VALUE]=L.INPUT_VALUE,zd[L.NEXT_STATEMENT]=L.PREVIOUS_STATEMENT,zd[L.PREVIOUS_STATEMENT]=L.NEXT_STATEMENT;var Bd=class extends q{constructor(e,t){super(e,t),this.highlighted=!1,this.targetConnection=null,this.db=e.workspace.connectionDBList[t],this.dbOpposite=e.workspace.connectionDBList[zd[t]],this.offsetInBlock=new N(0,0),this.trackedState=Bd.TrackedState.WILL_TRACK}dispose(){super.dispose(),this.trackedState===Bd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y);var e,t;(t=(e=this.sourceBlock_.pathObject).removeConnectionHighlight)==null||t.call(e,this)}getSourceBlock(){return super.getSourceBlock()}targetBlock(){return super.targetBlock()}distanceFrom(e){var t=this.x-e.x;return e=this.y-e.y,Math.sqrt(t*t+e*e)}bumpAwayFrom(t,n=!1){if(!this.sourceBlock_.workspace.isDragging()){var r=e.Og.snapRadius+Math.floor(Math.random()*10),i=e.Og.snapRadius+Math.floor(Math.random()*10),a=t.sourceBlock_.getRootBlock(),o=this.sourceBlock_.getRootBlock();if(!a.isInFlyout&&!o.isInFlyout){var s=!0;if(o.isMovable())a.isMovable()&&n&&(i=-i);else if(a.isMovable())s=!1,r=-r,i=-i;else return;n=s?t:this,t=s?this:t,a=s?o:a,a.RTL&&(r=-r),a.moveBy(n.x+r-t.x,n.y+i-t.y,[`bump`])}}}moveTo(e,t){var n=this.x!==e||this.y!==t,r=!1;return this.trackedState===Bd.TrackedState.WILL_TRACK?(this.db.addConnection(this,t),this.trackedState=Bd.TrackedState.TRACKED,r=!0):this.trackedState===Bd.TrackedState.TRACKED&&n&&(this.db.reorderConnection(this,t),r=!0),this.x=e,this.y=t,r}moveBy(e,t){return this.moveTo(this.x+e,this.y+t)}moveToOffset(e){return this.moveTo(e.x+this.offsetInBlock.x,e.y+this.offsetInBlock.y)}setOffsetInBlock(e,t){this.offsetInBlock.x=e,this.offsetInBlock.y=t}getOffsetInBlock(){return this.offsetInBlock}tightenEfficiently(){var e=this.targetConnection,t=this.targetBlock();e&&t&&(e=N.difference(this.offsetInBlock,e.offsetInBlock),this.insertionMarker&&(this.type===L.INPUT_VALUE?e.x+=this.insertionMarker.getHeightWidth().width:e.y+=this.insertionMarker.getHeightWidth().height),t.translate(e.x,e.y))}closest(e,t){return this.dbOpposite.searchForClosest(this,e,t)}setAriaRole(t){var n=this.type===L.INPUT_VALUE?e.C.INPUT_LABEL_VALUE:e.C.INPUT_LABEL_STATEMENT;p(t,O.FIGURE),m(t,k.ROLEDESCRIPTION,n)}recomputeAriaContext(t){this.setAriaRole(t);var n,r,i=this.getParentInput()??((n=this.getSourceBlock().getTopStackBlock().previousConnection)==null||(r=n.targetConnection)==null?void 0:r.getParentInput());i?(n=(i==null?void 0:i.getAriaLabelText())??An(i.getSourceBlock(),i,!0).join(`, `),this.type===L.NEXT_STATEMENT?m(t,k.LABEL,e.C.INPUT_LABEL_END_STATEMENT.replace(`%1`,n)):m(t,k.LABEL,n)):m(t,k.LABEL,e.C.INPUT_LABEL_EMPTY)}highlight(){this.highlighted=!0;var e=this.findHighlightSvg();e&&(g(e,`blocklyHighlightedConnectionPathVisible`),requestAnimationFrame(()=>{var t=e.parentElement;if(t)for(;e.nextSibling;)t.insertBefore(e.nextSibling,e)}),this.recomputeAriaContext(e))}unhighlight(){this.highlighted=!1;var e=this.findHighlightSvg();e&&_(e,`blocklyHighlightedConnectionPathVisible`)}isHighlighted(){return this.highlighted}setTracking(e){e&&this.trackedState===Bd.TrackedState.TRACKED||!e&&this.trackedState===Bd.TrackedState.UNTRACKED||this.sourceBlock_.isInFlyout||(e?(this.db.addConnection(this,this.y),this.trackedState=Bd.TrackedState.TRACKED):(this.trackedState===Bd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y),this.trackedState=Bd.TrackedState.UNTRACKED))}stopTrackingAll(){if(this.setTracking(!1),this.targetConnection){let e=this.targetBlock().getDescendants(!1);for(let t=0;t<e.length;t++){let n=e[t],r=n.getConnections_(!0);for(let e=0;e<r.length;e++)r[e].setTracking(!1);for(let e of n.getIcons())Wt(e)&&e.setBubbleVisible(!1)}}}startTrackingAll(){this.setTracking(!0);var e=[];if(this.type!==L.INPUT_VALUE&&this.type!==L.NEXT_STATEMENT)return e;var t=this.targetBlock();if(t){let n;t.isCollapsed()?(n=[],t.outputConnection&&n.push(t.outputConnection),t.nextConnection&&n.push(t.nextConnection),t.previousConnection&&n.push(t.previousConnection)):n=t.getConnections_(!0);for(let t=0;t<n.length;t++)e.push(...n[t].startTrackingAll());e.length||(e=[t])}return e}onFailedConnect(t){var n=this.getSourceBlock();if(e.Qc){let r=e.gd;setTimeout(function(){n.isDisposed()||n.getParent()||(e.B(r),this.bumpAwayFrom(t),e.B(!1))}.bind(this),e.Og.bumpDelay)}}disconnectInternal(t=!0){var{parentConnection:n,childConnection:r}=this.getParentAndChildConnections();if(n&&r){var i=e.gd;i||e.B(!0);var a=n.getSourceBlock(),o=r.getSourceBlock();super.disconnectInternal(t),a.queueRender(),o.updateDisabled(),o.queueRender(),o.getSvgRoot().style.display=`block`,e.B(i)}}respawnShadow_(){super.respawnShadow_();var e=this.targetBlock();e&&(e.initSvg(),e.queueRender())}neighbours(e){return this.dbOpposite.getNeighbours(this,e)}connect_(e){super.connect_(e);var t=this.getSourceBlock();e=e.getSourceBlock(),t.updateDisabled(),e.updateDisabled(),e.queueRender(),(t=t.getInputWithBlock(e))&&(t=t.isVisible(),e.getSvgRoot().style.display=t?`block`:`none`)}onCheckChanged_(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||(this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug()}setCheck(e){return super.setCheck(e),this.sourceBlock_.queueRender(),this}showContextMenu(e){var t=H.registry.getContextMenuOptions({focusedNode:this},e);if(t.length){var n=this.getSourceBlock(),r=n.workspace;if(e instanceof PointerEvent)var i=new N(e.clientX,e.clientY);else i=new N(this.x,this.y),i=lt(r,i).translate(n.RTL?-5:5,5);Br(e,t,n.RTL,r,i)}}getFocusableElement(){var e=this.findHighlightSvg();if(e)return e;throw Error(`No highlight SVG found corresponding to this connection.`)}getFocusableTree(){return this.getSourceBlock().workspace}onNodeFocus(){this.highlight();var e=this.getSourceBlock();e.workspace.isFlyout||e.moveSvgRootToFront(),e.workspace.scrollBoundsIntoView(e.getBoundingRectangleWithoutChildren())}onNodeBlur(){this.unhighlight()}canBeFocused(){return this.findHighlightSvg()!==null}findHighlightSvg(){return this.getSourceBlock().getSvgRoot().getRootNode().getElementById(this.id)}attachInsertionMarker(e){this.insertionMarker=e}detachInsertionMarker(){this.insertionMarker=void 0}getInsertionMarker(){return this.insertionMarker}},Vd=Bd||={},Hd=Vd.TrackedState||={};Hd[Hd.WILL_TRACK=-1]=`WILL_TRACK`,Hd[Hd.UNTRACKED=0]=`UNTRACKED`,Hd[Hd.TRACKED=1]=`TRACKED`;var Ud=class{constructor(t,n){this.name=t,this.sourceBlock=n,this.fieldRow=[],this.align=e.En.LEFT,this.visible=!0,this.ariaLabelProvider=null,this.type=e.je.CUSTOM,this.connection=null}getSourceBlock(){return this.sourceBlock}appendField(e,t){return this.insertFieldAt(this.fieldRow.length,e,t),this}insertFieldAt(t,n,r){if(t<0||t>this.fieldRow.length)throw Error(`index `+t+` out of bounds.`);return n||n===``&&r?(typeof n==`string`&&(n=e.lh({type:`field_label`,text:n})),n.setSourceBlock(this.sourceBlock),this.sourceBlock.initialized&&this.initField(n),n.name=r,n.setVisible(this.isVisible()),n.prefixField&&(t=this.insertFieldAt(t,n.prefixField)),this.fieldRow.splice(t,0,n),t++,n.suffixField&&(t=this.insertFieldAt(t,n.suffixField)),this.sourceBlock.rendered&&this.sourceBlock.queueRender(),t):t}removeField(e,t){for(let t=0,n;n=this.fieldRow[t];t++)if(n.name===e)return n.dispose(),this.fieldRow.splice(t,1),this.sourceBlock.rendered&&this.sourceBlock.queueRender(),!0;if(t)return!1;throw Error(`Field "`+e+`" not found.`)}isVisible(){return this.visible}setVisible(e){var t=[];if(this.visible===e)return t;this.visible=e;for(let t=0,n;n=this.fieldRow[t];t++)n.setVisible(e);if(this.connection&&this.connection instanceof Bd){e?t=this.connection.startTrackingAll():this.connection.stopTrackingAll();let n=this.connection.targetBlock();n&&(n.getSvgRoot().style.display=e?`block`:`none`)}return t}markDirty(){for(let e=0,t;t=this.fieldRow[e];e++)t.markDirty()}setCheck(e){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.setCheck(e),this}setAlign(e){return this.align=e,this.sourceBlock.rendered&&this.sourceBlock.queueRender(),this}setShadowDom(e){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.setShadowDom(e),this}getShadowDom(){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.getShadowDom()}init(){for(let e of this.fieldRow)e.init()}setAriaLabelProvider(e){return this.ariaLabelProvider=e,this}getAriaLabelText(){return this.ariaLabelProvider?typeof this.ariaLabelProvider==`string`?kr(this.ariaLabelProvider):this.ariaLabelProvider(this):null}initModel(){for(let e of this.fieldRow)e.initModel()}initField(e){this.sourceBlock.rendered?e.init():e.initModel()}dispose(){for(let e=0,t;t=this.fieldRow[e];e++)t.dispose();this.connection&&this.connection.dispose()}makeConnection(e){return this.sourceBlock.makeConnection_(e)}getRowId(){var e=this.getSourceBlock().inputList;if(this===e.find(e=>e.isVisible())||this===e[0])return this.getSourceBlock().getRowId();var t=e.indexOf(this),n,r=((n=e[t-1].connection)==null?void 0:n.type)===L.NEXT_STATEMENT,i;return((i=this.connection)==null?void 0:i.type)===L.NEXT_STATEMENT||r?`${this.getSourceBlock().id}-input${t}`:e[t-1].getRowId()}getLabel(e=ss.STANDARD,t=!0){if(!this.isVisible())return``;var n=wn(this,!1,e),r;return t&&((r=this.connection)==null?void 0:r.type)===L.INPUT_VALUE&&(t=this.connection.targetBlock())&&!t.isInsertionMarker()&&n.push(Dn(t,e).join(`, `)),n.join(`, `)}getIndex(){var t=[e.je.DUMMY,e.je.END_ROW];return this.getSourceBlock().inputList.filter(e=>!t.includes(e.type)).indexOf(this)}},Wd=class extends Ud{constructor(t,n){super(t,n),this.name=t,this.type=e.je.DUMMY}},Gd=class extends Ud{constructor(t,n){super(t,n),this.name=t,this.type=e.je.END_ROW}},Kd=class extends Ud{constructor(t,n){if(!t)throw Error(`Statement inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.je.STATEMENT,this.connection=this.makeConnection(L.NEXT_STATEMENT)}};e.Nn=class extends Ud{constructor(t,n){if(!t)throw Error(`Value inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.je.VALUE,this.connection=this.makeConnection(L.INPUT_VALUE)}};var qd=class{constructor(e,t,n){if(this.data=null,this.disposed=!1,this.hue=null,this.colour_=`#000000`,this.styleName_=``,this.suppressPrefixSuffix=!1,this.previousConnection=this.nextConnection=this.outputConnection=null,this.inputList=[],this.icons=[],this.disabledReasons=new Set,this.tooltip=``,this.contextMenu=!0,this.parentBlock_=null,this.childBlocks_=[],this.editable=this.movable=this.deletable=!0,this.collapsed_=this.shadow=!1,this.outputShape_=null,this.rendered=this.isInsertionMarker_=this.initialized=this.disposing=!1,this.onchangeWrapper=this.helpUrl=null,this.statementInputCount=0,this.workspace=e,this.id=n&&!e.getBlockById(n)?n:Ue(),e.setBlockById(this.id,this),this.xy=new N(0,0),this.isInFlyout=e.isFlyout,this.isInMutator=e.isMutator,this.RTL=e.RTL,t){if(this.type=t,n=$o[t],!n||typeof n!=`object`)throw TypeError(`Invalid block definition for type: `+t);Object.assign(this,n)}e.addTopBlock(this),e.addTypedBlock(this),new.target===qd&&this.doInit_()}doInit_(){var t=e.gd;t||e.B(!0);var n=e.Qc;try{typeof this.init==`function`&&(e.Qc=!1,this.init(),e.Qc=n),Je()&&b(new(x(E.BLOCK_CREATE))(this))}finally{e.B(t),e.Qc=n}this.inputsInlineDefault=this.inputsInline,typeof this.onchange==`function`&&this.setOnChange(this.onchange)}dispose(e=!1){this.disposing=!0,this.tooltip=``,this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.unplug(e),Je()&&b(new(x(E.BLOCK_DELETE))(this)),this.workspace.removeTopBlock(this),this.disposeInternal()}disposeInternal(){this.disposing=!0,this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.workspace.removeTypedBlock(this),this.workspace.removeBlockById(this.id),typeof this.destroy==`function`&&this.destroy(),this.childBlocks_.forEach(e=>e.disposeInternal()),this.inputList.forEach(e=>e.dispose()),this.inputList.length=0,this.getConnections_(!0).forEach(e=>e.dispose()),this.disposed=!0}isDeadOrDying(){return this.disposing||this.disposed}initModel(){if(!this.initialized){for(let e of this.inputList)e.initModel();this.initialized=!0}}unplug(e){this.outputConnection&&this.unplugFromRow(e),this.previousConnection&&this.unplugFromStack(e)}unplugFromRow(e){var t=null,n;(n=this.outputConnection)!=null&&n.isConnected()&&(t=this.outputConnection.targetConnection,this.outputConnection.disconnect()),t&&e&&(e=this.getOnlyValueConnection())&&e.isConnected()&&!e.targetBlock().isShadow()&&(e=e.targetConnection,e==null||e.disconnect(),this.workspace.connectionChecker.canConnect(e,t,!1)?t.connect(e):e==null||e.onFailedConnect(t))}getOnlyValueConnection(){var e=null;for(let t=0;t<this.inputList.length;t++){let n=this.inputList[t].connection;if(n&&n.type===L.INPUT_VALUE&&n.targetConnection){if(e)return null;e=n}}return e}unplugFromStack(e){var t=null,n;if((n=this.previousConnection)!=null&&n.isConnected()&&(t=this.previousConnection.targetConnection,this.previousConnection.disconnect()),e){for(e=this.getNextBlock();e&&(e.isShadow()||!e.isMovable());)e=e.getNextBlock();if(e){var r,i,a;e=((r=e.previousConnection)==null||(i=r.targetBlock())==null||(a=i.nextConnection)==null?void 0:a.targetConnection)??null,e==null||e.disconnect(),t&&this.workspace.connectionChecker.canConnect(t,e,!1)&&t.connect(e)}}}getConnections_(){var e=[];this.outputConnection&&e.push(this.outputConnection),this.previousConnection&&e.push(this.previousConnection),this.nextConnection&&e.push(this.nextConnection);for(let t=0,n;n=this.inputList[t];t++)n.connection&&e.push(n.connection);return e}lastConnectionInStack(e){for(var t=this.nextConnection;t;){let n=t.targetBlock();if(!n||e&&n.isShadow())return t;t=n.nextConnection}return null}bumpNeighbours(){}getParent(){return this.parentBlock_}getInputWithBlock(e){for(let t=0,n;n=this.inputList[t];t++)if(n.connection&&n.connection.targetBlock()===e)return n;return null}getSurroundParent(){var e=this;do{var t=e;if(e=e.getParent(),!e)return null}while(e.getNextBlock()===t);return e}getNextBlock(){return this.nextConnection&&this.nextConnection.targetBlock()}getPreviousBlock(){return this.previousConnection&&this.previousConnection.targetBlock()}getRootBlock(){var e=this;do{var t=e;e=t.parentBlock_}while(e);return t}getTopStackBlock(){var e=this;do var t=e.getPreviousBlock();while(t&&t.getNextBlock()===e&&(e=t));return e}getChildren(e){if(!e)return this.childBlocks_;e=[];for(let n=0,r;r=this.inputList[n];n++)if(r.connection){var t=r.connection.targetBlock();t&&e.push(t)}return(t=this.getNextBlock())&&e.push(t),e}setParent(e){if(e!==this.parentBlock_){var t=this.previousConnection&&this.previousConnection.targetBlock()||this.outputConnection&&this.outputConnection.targetBlock(),n=!!t;if(n&&e&&t!==e)throw Error(`Block connected to superior one that is not new parent.`);if(!n&&e)throw Error(`Block not connected to new parent.`);if(n&&!e)throw Error(`Cannot set parent to null while block is still connected to superior block.`);this.parentBlock_?f(this.parentBlock_.childBlocks_,this):this.workspace.removeTopBlock(this),(this.parentBlock_=e)?e.childBlocks_.push(this):this.workspace.addTopBlock(this)}}getDescendants(e){var t=[this],n=this.getChildren(e);for(let r,i=0;r=n[i];i++)t.push(...r.getDescendants(e));return t}isDeletable(){return this.deletable&&!this.isInFlyout&&!this.shadow&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnDeletable(){return this.deletable}setDeletable(e){this.deletable=e}isMovable(){return this.movable&&!this.isInFlyout&&!this.shadow&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnMovable(){return this.movable}setMovable(e){this.movable=e}isDuplicatable(){return!this.workspace.hasBlockLimits()||this.workspace.isCapacityAvailable(Me(this,!0))}isShadow(){return this.shadow}setShadow(e){this.shadow=e}isInsertionMarker(){return this.isInsertionMarker_}setInsertionMarker(e){this.isInsertionMarker_=e}isEditable(){return this.editable&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnEditable(){return this.editable}setEditable(e){this.editable=e;for(let e of this.getFields())e.updateEditable()}isDisposed(){return this.disposed}getFullBlockField(){if(!this.isSimpleReporter())return null;var e,t=(e=this.inputList[0])==null?void 0:e.fieldRow[0];return t!=null&&t.isFullBlockField()?t:null}isSimpleReporter(){if(!this.outputConnection)return!1;for(let e of this.inputList)if(e.connection||e.fieldRow.length>1)return!1;return!0}getMatchingConnection(e,t){var n=this.getConnections_(!0);if(e=e.getConnections_(!0),n.length!==e.length)throw Error(`Connection lists did not match in length.`);for(let r=0;r<e.length;r++)if(e[r]===t)return n[r];return null}setHelpUrl(e){this.helpUrl=e}setTooltip(e){this.tooltip=e}getTooltip(){return cr(this)}getColour(){return this.colour_}getStyleName(){return this.styleName_}getHue(){return this.hue}setColour(e){e=Ar(e),this.hue=e.hue,this.colour_=e.hex}setStyle(e){this.styleName_=e}setOnChange(e){if(e&&typeof e!=`function`)throw Error(`onchange must be a function.`);this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.onchange=e,this.onchangeWrapper=e.bind(this),this.workspace.addChangeListener(this.onchangeWrapper)}getField(e){if(typeof e!=`string`)throw TypeError(`Block.prototype.getField expects a string with the field name but received `+(e===void 0?`nothing`:e+` of type `+typeof e)+` instead`);for(let t of this.getFields())if(t.name===e)return t;return null}*getFields(){for(let e of this.inputList)for(let t of e.fieldRow)yield t}getVarModels(){var e=[];for(let t of this.getFields())if(t.referencesVariables()){let n=this.workspace.getVariableMap().getVariableById(t.getValue());n&&e.push(n)}return e}updateVarName(e){for(let t of this.getFields())t.referencesVariables()&&e.getId()===t.getValue()&&t.refreshVariableName()}renameVarById(e,t){for(let n of this.getFields())n.referencesVariables()&&e===n.getValue()&&n.setValue(t)}getFieldValue(e){return(e=this.getField(e))?e.getValue():null}setFieldValue(e,t){var n=this.getField(t);if(!n)throw Error(`Field "`+t+`" not found.`);n.setValue(e)}setPreviousStatement(e,t){if(e)t===void 0&&(t=null),this.previousConnection||=this.makeConnection_(L.PREVIOUS_STATEMENT),this.previousConnection.setCheck(t);else if(this.previousConnection){if(this.previousConnection.isConnected())throw Error(`Must disconnect previous statement before removing connection.`);this.previousConnection.dispose(),this.previousConnection=null}}setNextStatement(e,t){if(e)t===void 0&&(t=null),this.nextConnection||=this.makeConnection_(L.NEXT_STATEMENT),this.nextConnection.setCheck(t);else if(this.nextConnection){if(this.nextConnection.isConnected())throw Error(`Must disconnect next statement before removing connection.`);this.nextConnection.dispose(),this.nextConnection=null}}setOutput(e,t){if(e)t===void 0&&(t=null),this.outputConnection||=this.makeConnection_(L.OUTPUT_VALUE),this.outputConnection.setCheck(t);else if(this.outputConnection){if(this.outputConnection.isConnected())throw Error(`Must disconnect output value before removing connection.`);this.outputConnection.dispose(),this.outputConnection=null}}setInputsInline(e){this.inputsInline!==e&&(b(new(x(E.BLOCK_CHANGE))(this,`inline`,null,this.inputsInline,e)),this.inputsInline=e)}getInputsInline(){if(this.inputsInline!==void 0)return this.inputsInline;for(var t=1;t<this.inputList.length;t++)if(this.inputList[t-1]instanceof Wd&&this.inputList[t]instanceof Wd)return!1;for(t=1;t<this.inputList.length;t++)if(this.inputList[t-1]instanceof e.Nn&&this.inputList[t]instanceof Wd)return!0;for(t=0;t<this.inputList.length;t++)if(this.inputList[t]instanceof Gd)return!0;return!1}setOutputShape(e){this.outputShape_=e}getOutputShape(){return this.outputShape_}isEnabled(){return this.disabledReasons.size===0}setDisabledReason(e,t){e||this.workspace.options.disable||!this.hasDisabledReason(`MANUALLY_DISABLED`)||t==`MANUALLY_DISABLED`||this.setDisabledReason(!1,`MANUALLY_DISABLED`),this.disabledReasons.has(t)!==e&&(e?this.disabledReasons.add(t):this.disabledReasons.delete(t),e=new(x(E.BLOCK_CHANGE))(this,`disabled`,null,!e,e),e.setDisabledReason(t),b(e))}getInheritedDisabled(){for(var e=this.getSurroundParent();e;){if(!e.isEnabled())return!0;e=e.getSurroundParent()}return!1}hasDisabledReason(e){return this.disabledReasons.has(e)}getDisabledReasons(){return this.disabledReasons}isCollapsed(){return this.collapsed_}setCollapsed(e){this.collapsed_!==e&&(b(new(x(E.BLOCK_CHANGE))(this,`collapsed`,null,this.collapsed_,e)),this.collapsed_=e)}setAriaRoleDescriptionProvider(e){this.ariaRoleDescriptionProvider=e}getAriaRoleDescription(){return this.ariaRoleDescriptionProvider?typeof this.ariaRoleDescriptionProvider==`function`?this.ariaRoleDescriptionProvider():kr(this.ariaRoleDescriptionProvider):this.statementInputCount?e.C.BLOCK_LABEL_CONTAINER:this.outputConnection?e.C.BLOCK_LABEL_VALUE:e.C.BLOCK_LABEL_STATEMENT}toString(e,t){t=this.toTokens(t);for(let e=2;e<t.length;e++)t[e-2]===`(`&&t[e]===`)`&&(t[e-2]=t[e-1],t.splice(e-1,2));var n=``;return t=t.reduce((e,t)=>(e=e+(n===`(`||t===`)`?``:` `)+t,n=t[t.length-1],e),``),t=t.trim()||`???`,e&&t.length>e&&(t=t.substring(0,e-3)+`...`),t}toTokens(e=`?`){var t=[];for(let r of this.inputList)if(r.name!=`_TEMP_COLLAPSED_INPUT`){for(let e of r.fieldRow)t.push(e.getText());if(r.connection){let i=r.connection.targetBlock();if(i){var n=r.connection;let a=n.getCheck();!a&&n.targetConnection&&(a=n.targetConnection.getCheck()),(n=!!a&&(a.includes(`Boolean`)||a.includes(`Number`)))&&t.push(`(`),t.push(...i.toTokens(e)),n&&t.push(`)`)}else t.push(e)}}return t}appendValueInput(t){return this.appendInput(new e.Nn(t,this))}appendStatementInput(e){return this.statementInputCount++,this.appendInput(new Kd(e,this))}appendDummyInput(e=``){return this.appendInput(new Wd(e,this))}appendEndRowInput(e=``){return this.appendInput(new Gd(e,this))}appendInput(e){return this.inputList.push(e),e}appendInputFromRegistry(e,t){return(e=Le(M.INPUT,e,!1))?this.appendInput(new e(t,this)):null}jsonInit(t){var n=t.type?`Block "`+t.type+`": `:``;if(t.output&&t.previousStatement)throw Error(n+`Must not have both an output and a previousStatement.`);for(var r=0;t[`args${r}`];){if(t[`message${r}`]===void 0)throw Error(n+`args${r} must have a corresponding message (message${r}).`);r++}if(t.style&&typeof t.style==`object`&&(this.hat=t.style.hat,t.style=null),t.style&&t.colour)throw Error(n+`Must not have both a colour and a style.`);for(t.style?this.jsonInitStyle(t,n):this.jsonInitColour(t,n),r=0;t[`message${r}`]!==void 0;)this.interpolate(t[`message${r}`]||``,t[`args${r}`]||[],t[`implicitAlign${r}`]||t[`lastDummyAlign${r}`],n),r++;if(t.inputsInline!==void 0&&(e.Ub++,this.setInputsInline(t.inputsInline),e.Ub--),t.output!==void 0&&this.setOutput(!0,t.output),t.outputShape!==void 0&&this.setOutputShape(t.outputShape),t.previousStatement!==void 0&&this.setPreviousStatement(!0,t.previousStatement),t.nextStatement!==void 0&&this.setNextStatement(!0,t.nextStatement),t.tooltip!==void 0&&(r=kr(t.tooltip),this.setTooltip(r)),t.enableContextMenu!==void 0&&(this.contextMenu=!!t.enableContextMenu),t.suppressPrefixSuffix!==void 0&&(this.suppressPrefixSuffix=!!t.suppressPrefixSuffix),t.helpUrl!==void 0&&(r=kr(t.helpUrl),this.setHelpUrl(r)),t.ariaRoleDescription!==void 0&&this.setAriaRoleDescriptionProvider(t.ariaRoleDescription),typeof t.extensions==`string`&&(console.warn(n+`JSON attribute 'extensions' should be an array of strings. Found raw string in JSON for '`+t.type+`' block.`),t.extensions=[t.extensions]),t.mutator!==void 0&&di(t.mutator,this,!0),t=t.extensions,Array.isArray(t))for(n=0;n<t.length;n++)di(t[n],this,!1)}jsonInitColour(e,t){if(`colour`in e)if(e.colour===void 0)console.warn(t+`Undefined colour value.`);else{e=e.colour;try{this.setColour(e)}catch{console.warn(t+`Illegal colour value: `,e)}}}jsonInitStyle(e,t){e=e.style;try{this.setStyle(e)}catch{console.warn(t+`Style does not exist: `,e)}}mixin(e,t){if(t!==void 0&&typeof t!=`boolean`)throw Error(`opt_disableCheck must be a boolean if provided`);if(!t){t=[];for(let n in e)this[n]!==void 0&&t.push(n);if(t.length)throw Error(`Mixin will overwrite block members: `+JSON.stringify(t))}Object.assign(this,e)}interpolate(e,t,n,r){e=Or(e),this.validateTokens(e,t.length),t=this.interpolateArguments(e,t,n),n=[];for(let i=0,a;a=t[i];i++)if(this.isInputKeyword(a.type)){if(e=this.inputFromJson(a,r)){for(let t=0,r;r=n[t];t++)e.appendField(r[0],r[1]);n.length=0}}else(e=this.fieldFromJson(a))&&n.push([e,a.name])}validateTokens(e,t){var n=[],r=0;for(let i=0;i<e.length;i++){let a=e[i];if(typeof a==`number`){if(a<1||a>t)throw Error(`Block "`+this.type+`": Message index %`+a+` out of range.`);if(n[a])throw Error(`Block "`+this.type+`": Message index %`+a+` duplicated.`);n[a]=!0,r++}}if(r!==t)throw Error(`Block "`+this.type+`": Message does not reference all `+t+` arg(s).`)}interpolateArguments(e,t,n){var r=[];for(let a=0;a<e.length;a++){var i=e[a];if(typeof i==`number`&&(i=t[i-1]),typeof i==`string`){if(i===`
825
+ `);var Fd=class{constructor(e){this.connectionChecker=e,this.connections=[],this.bulkCounter=0}addConnection(e,t){t=this.calculateIndexForYPos(t),this.connections.splice(t,0,e)}findIndexOfConnection(e,t){if(!this.connections.length)return-1;var n=this.calculateIndexForYPos(t);if(n>=this.connections.length)return-1;t=e.y;for(var r=n;r>=0&&this.connections[r].y===t;){if(this.connections[r]===e)return r;r--}for(r=n;r<this.connections.length&&this.connections[r].y===t;){if(this.connections[r]===e)return r;r++}return-1}calculateIndexForYPos(e){if(!this.connections.length)return 0;for(var t=0,n=this.connections.length;t<n;){let r=Math.floor((t+n)/2);if(this.connections[r].y<e)t=r+1;else if(this.connections[r].y>e)n=r;else{t=r;break}}return t}removeConnection(e,t){if(e=this.findIndexOfConnection(e,t),e===-1)throw Error(`Unable to find connection in connectionDB.`);this.connections.splice(e,1)}reorderConnection(e,t){this.bulkCounter===0&&(this.removeConnection(e,e.y),this.addConnection(e,t))}getNeighbours(e,t){function n(e){var n=i-r[e].x,o=a-r[e].y;return Math.sqrt(n*n+o*o)<=t&&c.push(r[e]),o<t}var r=this.connections,i=e.x,a=e.y;e=0;for(var o=r.length-2,s=o;e<s;)r[s].y<a?e=s:o=s,s=Math.floor((e+o)/2);var c=[];if(o=e=s,r.length){for(;e>=0&&n(e);)e--;do o++;while(o<r.length&&n(o))}return c}isInYRange(e,t,n){return Math.abs(this.connections[e].y-t)<=n}searchForClosest(e,t,n){if(!this.connections.length)return{connection:null,radius:t};var r=e.y,i=e.x;e.x=i+n.x,e.y=r+n.y;var a=this.calculateIndexForYPos(e.y);n=null;for(var o=t,s,c=a-1;c>=0&&this.isInYRange(c,e.y,t);)s=this.connections[c],this.connectionChecker.canConnect(e,s,!0,o)&&(n=s,o=s.distanceFrom(e)),c--;for(;a<this.connections.length&&this.isInYRange(a,e.y,t);)s=this.connections[a],this.connectionChecker.canConnect(e,s,!0,o)&&(n=s,o=s.distanceFrom(e)),a++;return e.x=i,e.y=r,{connection:n,radius:o}}beginBulkUpdates(){this.bulkCounter++}endBulkUpdates(){if(this.bulkCounter===0)throw Error(`Bulk updates are already ended.`);this.bulkCounter--,this.bulkCounter===0&&this.reorderConnections()}reorderConnections(){this.connections.sort((e,t)=>e.y-t.y)}static init(e){var t=[];return t[L.INPUT_VALUE]=new Fd(e),t[L.OUTPUT_VALUE]=new Fd(e),t[L.NEXT_STATEMENT]=new Fd(e),t[L.PREVIOUS_STATEMENT]=new Fd(e),t}},q=class{constructor(e,t){if(this.type=t,this.targetConnection=null,this.disposed=!1,this.shadowDom=this.check=null,this.y=this.x=0,this.shadowState=null,this.sourceBlock_=e,e.id.includes(`_connection`))throw Error(`Connection ID indicator is contained in block ID. This will cause problems with focus: ${e.id}.`);this.id=`${e.id}_connection_${He()}`}connect_(e){var t=L.INPUT_VALUE,n=this.getSourceBlock(),r=e.getSourceBlock();if(e.isConnected()&&e.disconnectInternal(!1),this.isConnected()){let e=this.stashShadowState(),t=this.targetBlock();if(t.isShadow())t.dispose(!1);else{this.disconnectInternal();var i=t}this.applyShadowState(e)}if(Je()){var a=new(x(E.BLOCK_MOVE))(r);a.setReason([`connect`])}if(!this||!e)throw Error(`Cannot connect null connections.`);this.targetConnection=e,e.targetConnection=this,r.setParent(n),a&&(a.recordNew(),b(a)),i&&(e=this.type===t?i.outputConnection:i.previousConnection)&&((r=q.getConnectionForOrphanedConnection(r,e))?e.connect(r):e.onFailedConnect(this))}dispose(){if(this.isConnected()){this.isSuperior()&&this.setShadowStateInternal();let e=this.targetBlock();e&&!e.isDeadOrDying()&&e.unplug()}this.disposed=!0}getSourceBlock(){return this.sourceBlock_}isSuperior(){return this.type===L.INPUT_VALUE||this.type===L.NEXT_STATEMENT}isConnected(){return!!this.targetConnection}getConnectionChecker(){return this.sourceBlock_.workspace.connectionChecker}onFailedConnect(){}connect(t){if(this.targetConnection===t)return!0;if(this.getConnectionChecker().canConnect(this,t,!1)){let n=e.gd;n||e.B(!0),this.isSuperior()?this.connect_(t):t.connect_(this),e.B(n)}return this.isConnected()}disconnect(){this.disconnectInternal()}disconnectInternal(t=!0){var{parentConnection:n,childConnection:r}=this.getParentAndChildConnections();if(!n||!r)throw Error(`Source connection not connected.`);var i=e.gd;if(i||e.B(!0),Je()){var a=new(x(E.BLOCK_MOVE))(r.getSourceBlock());a.setReason([`disconnect`])}var o=this.targetConnection;o&&(o.targetConnection=null),this.targetConnection=null,t&&r.getSourceBlock().setParent(null),a&&(a.recordNew(),b(a)),r.getSourceBlock().isShadow()||n.respawnShadow_(),e.B(i)}getParentAndChildConnections(){return this.targetConnection?this.isSuperior()?{parentConnection:this,childConnection:this.targetConnection}:{parentConnection:this.targetConnection,childConnection:this}:{}}respawnShadow_(){this.createShadowBlock(!0)}reconnect(e,t){if(this.getSourceBlock().isDeadOrDying())return!1;var n;return t=(n=e.getInput(t))==null?void 0:n.connection,n=this.targetBlock(),n&&n!==e||!t||t.targetConnection===this?!1:(t.isConnected()&&t.disconnect(),t.connect(this),!0)}targetBlock(){if(this.isConnected()){let e;return((e=this.targetConnection)==null?void 0:e.getSourceBlock())??null}return null}onCheckChanged_(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||(this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug()}setCheck(e){return e?(Array.isArray(e)||(e=[e]),this.check=e,this.onCheckChanged_()):this.check=null,this}getCheck(){return this.check}setShadowDom(e){this.setShadowStateInternal({shadowDom:e})}getShadowDom(e){return e&&this.targetBlock().isShadow()?$r(this.targetBlock()):this.shadowDom}setShadowState(e){this.setShadowStateInternal({shadowState:e})}getShadowState(e){return e&&this.targetBlock()&&this.targetBlock().isShadow()?dn(this.targetBlock()):this.shadowState}neighbours(){return[]}getParentInput(){var e=null,t=this.sourceBlock_.inputList;for(let n=0;n<t.length;n++)if(t[n].connection===this){e=t[n];break}return e}toString(){var e=this.sourceBlock_;if(!e)return`Orphan Connection`;if(e.outputConnection===this)var t=`Output Connection of `;else if(e.previousConnection===this)t=`Previous Connection of `;else if(e.nextConnection===this)t=`Next Connection of `;else{t=null;for(let n=0,r;r=e.inputList[n];n++)if(r.connection===this){t=r;break}if(t)t=`Input "`+t.name+`" connection on `;else return console.warn(`Connection not actually connected to sourceBlock_`),`Orphan Connection`}return t+e.toDevString()}stashShadowState(){var e=this.getShadowDom(!0),t=this.getShadowState(!0);return this.shadowState=this.shadowDom=null,{shadowDom:e,shadowState:t}}applyShadowState({shadowDom:e,shadowState:t}){this.shadowDom=e,this.shadowState=t}setShadowStateInternal({shadowDom:e=null,shadowState:t=null}={}){this.shadowDom=e,this.shadowState=t,this.getSourceBlock().isDeadOrDying()||((e=this.targetBlock())?e.isShadow()?(e.dispose(!1),this.respawnShadow_(),this.targetBlock()&&this.targetBlock().isShadow()&&this.serializeShadow(this.targetBlock())):(e=this.createShadowBlock(!1),this.serializeShadow(e),e&&e.dispose(!1)):(this.respawnShadow_(),this.targetBlock()&&this.targetBlock().isShadow()&&this.serializeShadow(this.targetBlock())))}createShadowBlock(e){var t=this.getSourceBlock(),n=this.getShadowState(),r=this.getShadowDom();if(t.isDeadOrDying()||!n&&!r)return null;if(n)return t=mn(n,t.workspace,{parentConnection:e?this:void 0,isShadow:!0,recordUndo:!1});if(r){if(t=ri(r,t.workspace),e){if(this.type===L.INPUT_VALUE){if(!t.outputConnection)throw Error(`Shadow block is missing an output connection`);if(!this.connect(t.outputConnection))throw Error(`Could not connect shadow block to connection`)}else if(this.type===L.NEXT_STATEMENT){if(!t.previousConnection)throw Error(`Shadow block is missing previous connection`);if(!this.connect(t.previousConnection))throw Error(`Could not connect shadow block to connection`)}else throw Error(`Cannot connect a shadow block to a previous/output connection`)}return t}return null}serializeShadow(e){e&&(this.shadowDom=$r(e),this.shadowState=dn(e))}static getConnectionForOrphanedConnection(e,t){if(t.type===L.OUTPUT_VALUE){a:{t=t.getSourceBlock();for(var n;n=Si(e,t);)if(e=n.targetBlock(),!e||e.isShadow()){t=n;break a}t=null}return t}return e=e.lastConnectionInStack(!0),n=t.getConnectionChecker(),e&&n.canConnect(t,e,!1)?e:null}};q.CAN_CONNECT=0,q.REASON_SELF_CONNECTION=1,q.REASON_WRONG_TYPE=2,q.REASON_TARGET_NULL=3,q.REASON_CHECKS_FAILED=4,q.REASON_DIFFERENT_WORKSPACES=5,q.REASON_SHADOW_PARENT=6,q.REASON_DRAG_CHECKS_FAILED=7,q.REASON_PREVIOUS_AND_OUTPUT=8;var Id=class extends Error{constructor(e){super(`Tried to append an icon of type ${e.getType()} when an icon of that type already exists on the block. Use getIcon to access the existing icon.`),this.icon=e}},Ld={};Ld.DuplicateIconType=Id;var Rd=e.En||={};Rd[Rd.LEFT=-1]=`LEFT`,Rd[Rd.CENTRE=0]=`CENTRE`,Rd[Rd.RIGHT=1]=`RIGHT`;var zd=[];zd[L.INPUT_VALUE]=L.OUTPUT_VALUE,zd[L.OUTPUT_VALUE]=L.INPUT_VALUE,zd[L.NEXT_STATEMENT]=L.PREVIOUS_STATEMENT,zd[L.PREVIOUS_STATEMENT]=L.NEXT_STATEMENT;var Bd=class extends q{constructor(e,t){super(e,t),this.highlighted=!1,this.targetConnection=null,this.db=e.workspace.connectionDBList[t],this.dbOpposite=e.workspace.connectionDBList[zd[t]],this.offsetInBlock=new N(0,0),this.trackedState=Bd.TrackedState.WILL_TRACK}dispose(){super.dispose(),this.trackedState===Bd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y);var e,t;(t=(e=this.sourceBlock_.pathObject).removeConnectionHighlight)==null||t.call(e,this)}getSourceBlock(){return super.getSourceBlock()}targetBlock(){return super.targetBlock()}distanceFrom(e){var t=this.x-e.x;return e=this.y-e.y,Math.sqrt(t*t+e*e)}bumpAwayFrom(t,n=!1){if(!this.sourceBlock_.workspace.isDragging()){var r=e.Og.snapRadius+Math.floor(Math.random()*10),i=e.Og.snapRadius+Math.floor(Math.random()*10),a=t.sourceBlock_.getRootBlock(),o=this.sourceBlock_.getRootBlock();if(!a.isInFlyout&&!o.isInFlyout){var s=!0;if(o.isMovable())a.isMovable()&&n&&(i=-i);else if(a.isMovable())s=!1,r=-r,i=-i;else return;n=s?t:this,t=s?this:t,a=s?o:a,a.RTL&&(r=-r),a.moveBy(n.x+r-t.x,n.y+i-t.y,[`bump`])}}}moveTo(e,t){var n=this.x!==e||this.y!==t,r=!1;return this.trackedState===Bd.TrackedState.WILL_TRACK?(this.db.addConnection(this,t),this.trackedState=Bd.TrackedState.TRACKED,r=!0):this.trackedState===Bd.TrackedState.TRACKED&&n&&(this.db.reorderConnection(this,t),r=!0),this.x=e,this.y=t,r}moveBy(e,t){return this.moveTo(this.x+e,this.y+t)}moveToOffset(e){return this.moveTo(e.x+this.offsetInBlock.x,e.y+this.offsetInBlock.y)}setOffsetInBlock(e,t){this.offsetInBlock.x=e,this.offsetInBlock.y=t}getOffsetInBlock(){return this.offsetInBlock}tightenEfficiently(){var e=this.targetConnection,t=this.targetBlock();e&&t&&(e=N.difference(this.offsetInBlock,e.offsetInBlock),this.insertionMarker&&(this.type===L.INPUT_VALUE?e.x+=this.insertionMarker.getHeightWidth().width:e.y+=this.insertionMarker.getHeightWidth().height),t.translate(e.x,e.y))}closest(e,t){return this.dbOpposite.searchForClosest(this,e,t)}setAriaRole(t){var n=this.type===L.INPUT_VALUE?e.C.INPUT_LABEL_VALUE:e.C.INPUT_LABEL_STATEMENT;p(t,O.FIGURE),m(t,k.ROLEDESCRIPTION,n)}recomputeAriaContext(t){this.setAriaRole(t);var n,r,i=this.getParentInput()??((n=this.getSourceBlock().getTopStackBlock().previousConnection)==null||(r=n.targetConnection)==null?void 0:r.getParentInput());i?(n=(i==null?void 0:i.getAriaLabelText())??An(i.getSourceBlock(),i,!0).join(`, `),this.type===L.NEXT_STATEMENT?m(t,k.LABEL,e.C.INPUT_LABEL_END_STATEMENT.replace(`%1`,n)):m(t,k.LABEL,n)):m(t,k.LABEL,e.C.INPUT_LABEL_EMPTY)}highlight(){this.highlighted=!0;var e=this.findHighlightSvg();e&&(g(e,`blocklyHighlightedConnectionPathVisible`),requestAnimationFrame(()=>{var t=e.parentElement;if(t)for(;e.nextSibling;)t.insertBefore(e.nextSibling,e)}),this.recomputeAriaContext(e))}unhighlight(){this.highlighted=!1;var e=this.findHighlightSvg();e&&_(e,`blocklyHighlightedConnectionPathVisible`)}isHighlighted(){return this.highlighted}setTracking(e){e&&this.trackedState===Bd.TrackedState.TRACKED||!e&&this.trackedState===Bd.TrackedState.UNTRACKED||this.sourceBlock_.isInFlyout||(e?(this.db.addConnection(this,this.y),this.trackedState=Bd.TrackedState.TRACKED):(this.trackedState===Bd.TrackedState.TRACKED&&this.db.removeConnection(this,this.y),this.trackedState=Bd.TrackedState.UNTRACKED))}stopTrackingAll(){if(this.setTracking(!1),this.targetConnection){let e=this.targetBlock().getDescendants(!1);for(let t=0;t<e.length;t++){let n=e[t],r=n.getConnections_(!0);for(let e=0;e<r.length;e++)r[e].setTracking(!1);for(let e of n.getIcons())Wt(e)&&e.setBubbleVisible(!1)}}}startTrackingAll(){this.setTracking(!0);var e=[];if(this.type!==L.INPUT_VALUE&&this.type!==L.NEXT_STATEMENT)return e;var t=this.targetBlock();if(t){let n;t.isCollapsed()?(n=[],t.outputConnection&&n.push(t.outputConnection),t.nextConnection&&n.push(t.nextConnection),t.previousConnection&&n.push(t.previousConnection)):n=t.getConnections_(!0);for(let t=0;t<n.length;t++)e.push(...n[t].startTrackingAll());e.length||(e=[t])}return e}onFailedConnect(t){var n=this.getSourceBlock();if(e.Qc){let r=e.gd;setTimeout(function(){n.isDisposed()||n.getParent()||(e.B(r),this.bumpAwayFrom(t),e.B(!1))}.bind(this),e.Og.bumpDelay)}}disconnectInternal(t=!0){var{parentConnection:n,childConnection:r}=this.getParentAndChildConnections();if(n&&r){var i=e.gd;i||e.B(!0);var a=n.getSourceBlock(),o=r.getSourceBlock();super.disconnectInternal(t),a.queueRender(),o.updateDisabled(),o.queueRender(),o.getSvgRoot().style.display=`block`,e.B(i)}}respawnShadow_(){super.respawnShadow_();var e=this.targetBlock();e&&(e.initSvg(),e.queueRender())}neighbours(e){return this.dbOpposite.getNeighbours(this,e)}connect_(e){super.connect_(e);var t=this.getSourceBlock();e=e.getSourceBlock(),t.updateDisabled(),e.updateDisabled(),e.queueRender(),(t=t.getInputWithBlock(e))&&(t=t.isVisible(),e.getSvgRoot().style.display=t?`block`:`none`)}onCheckChanged_(){!this.isConnected()||this.targetConnection&&this.getConnectionChecker().canConnect(this,this.targetConnection,!1)||(this.isSuperior()?this.targetBlock():this.sourceBlock_).unplug()}setCheck(e){return super.setCheck(e),this.sourceBlock_.queueRender(),this}showContextMenu(e){var t=H.registry.getContextMenuOptions({focusedNode:this},e);if(t.length){var n=this.getSourceBlock(),r=n.workspace;if(e instanceof PointerEvent)var i=new N(e.clientX,e.clientY);else i=new N(this.x,this.y),i=lt(r,i).translate(n.RTL?-5:5,5);Br(e,t,n.RTL,r,i)}}getFocusableElement(){var e=this.findHighlightSvg();if(e)return e;throw Error(`No highlight SVG found corresponding to this connection.`)}getFocusableTree(){return this.getSourceBlock().workspace}onNodeFocus(){this.highlight();var e=this.getSourceBlock();e.workspace.isFlyout||e.moveSvgRootToFront(),e.workspace.scrollBoundsIntoView(e.getBoundingRectangleWithoutChildren())}onNodeBlur(){this.unhighlight()}canBeFocused(){return this.findHighlightSvg()!==null}findHighlightSvg(){return this.getSourceBlock().getSvgRoot().getRootNode().getElementById(this.id)}attachInsertionMarker(e){this.insertionMarker=e}detachInsertionMarker(){this.insertionMarker=void 0}getInsertionMarker(){return this.insertionMarker}},Vd=Bd||={},Hd=Vd.TrackedState||={};Hd[Hd.WILL_TRACK=-1]=`WILL_TRACK`,Hd[Hd.UNTRACKED=0]=`UNTRACKED`,Hd[Hd.TRACKED=1]=`TRACKED`;var Ud=class{constructor(t,n){this.name=t,this.sourceBlock=n,this.fieldRow=[],this.align=e.En.LEFT,this.visible=!0,this.ariaLabelProvider=null,this.type=e.je.CUSTOM,this.connection=null}getSourceBlock(){return this.sourceBlock}appendField(e,t){return this.insertFieldAt(this.fieldRow.length,e,t),this}insertFieldAt(t,n,r){if(t<0||t>this.fieldRow.length)throw Error(`index `+t+` out of bounds.`);return n||n===``&&r?(typeof n==`string`&&(n=e.lh({type:`field_label`,text:n})),n.setSourceBlock(this.sourceBlock),this.sourceBlock.initialized&&this.initField(n),n.name=r,n.setVisible(this.isVisible()),n.prefixField&&(t=this.insertFieldAt(t,n.prefixField)),this.fieldRow.splice(t,0,n),t++,n.suffixField&&(t=this.insertFieldAt(t,n.suffixField)),this.sourceBlock.rendered&&this.sourceBlock.queueRender(),t):t}removeField(e,t){for(let t=0,n;n=this.fieldRow[t];t++)if(n.name===e)return n.dispose(),this.fieldRow.splice(t,1),this.sourceBlock.rendered&&this.sourceBlock.queueRender(),!0;if(t)return!1;throw Error(`Field "`+e+`" not found.`)}isVisible(){return this.visible}setVisible(e){var t=[];if(this.visible===e)return t;this.visible=e;for(let t=0,n;n=this.fieldRow[t];t++)n.setVisible(e);if(this.connection&&this.connection instanceof Bd){e?t=this.connection.startTrackingAll():this.connection.stopTrackingAll();let n=this.connection.targetBlock();n&&(n.getSvgRoot().style.display=e?`block`:`none`)}return t}markDirty(){for(let e=0,t;t=this.fieldRow[e];e++)t.markDirty()}setCheck(e){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.setCheck(e),this}setAlign(e){return this.align=e,this.sourceBlock.rendered&&this.sourceBlock.queueRender(),this}setShadowDom(e){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.setShadowDom(e),this}getShadowDom(){if(!this.connection)throw Error(`This input does not have a connection.`);return this.connection.getShadowDom()}init(){for(let e of this.fieldRow)e.init()}setAriaLabelProvider(e){return this.ariaLabelProvider=e,this}getAriaLabelText(){return this.ariaLabelProvider?typeof this.ariaLabelProvider==`string`?kr(this.ariaLabelProvider):this.ariaLabelProvider(this):null}initModel(){for(let e of this.fieldRow)e.initModel()}initField(e){this.sourceBlock.rendered?e.init():e.initModel()}dispose(){for(let e=0,t;t=this.fieldRow[e];e++)t.dispose();this.connection&&this.connection.dispose()}makeConnection(e){return this.sourceBlock.makeConnection_(e)}getRowId(){var e=this.getSourceBlock().inputList;if(this===e.find(e=>e.isVisible())||this===e[0])return this.getSourceBlock().getRowId();var t=e.indexOf(this),n,r=((n=e[t-1].connection)==null?void 0:n.type)===L.NEXT_STATEMENT,i;return((i=this.connection)==null?void 0:i.type)===L.NEXT_STATEMENT||r?`${this.getSourceBlock().id}-input${t}`:e[t-1].getRowId()}getLabel(e=ss.STANDARD,t=!0){if(!this.isVisible())return``;var n=wn(this,!1,e),r;return t&&((r=this.connection)==null?void 0:r.type)===L.INPUT_VALUE&&(t=this.connection.targetBlock())&&!t.isInsertionMarker()&&n.push(Dn(t,e).join(`, `)),n.join(`, `)}getIndex(){var t=[e.je.DUMMY,e.je.END_ROW];return this.getSourceBlock().inputList.filter(e=>!t.includes(e.type)).indexOf(this)}},Wd=class extends Ud{constructor(t,n){super(t,n),this.name=t,this.type=e.je.DUMMY}},Gd=class extends Ud{constructor(t,n){super(t,n),this.name=t,this.type=e.je.END_ROW}},Kd=class extends Ud{constructor(t,n){if(!t)throw Error(`Statement inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.je.STATEMENT,this.connection=this.makeConnection(L.NEXT_STATEMENT)}};e.Nn=class extends Ud{constructor(t,n){if(!t)throw Error(`Value inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.je.VALUE,this.connection=this.makeConnection(L.INPUT_VALUE)}};var qd=class{constructor(e,t,n){if(this.data=null,this.disposed=!1,this.hue=null,this.colour_=`#000000`,this.styleName_=``,this.suppressPrefixSuffix=!1,this.previousConnection=this.nextConnection=this.outputConnection=null,this.inputList=[],this.icons=[],this.disabledReasons=new Set,this.tooltip=``,this.contextMenu=!0,this.parentBlock_=null,this.childBlocks_=[],this.editable=this.movable=this.deletable=!0,this.collapsed_=this.shadow=!1,this.outputShape_=null,this.rendered=this.isInsertionMarker_=this.initialized=this.disposing=!1,this.onchangeWrapper=this.helpUrl=null,this.statementInputCount=0,this.workspace=e,this.id=n&&!e.getBlockById(n)?n:Ue(),e.setBlockById(this.id,this),this.xy=new N(0,0),this.isInFlyout=e.isFlyout,this.isInMutator=e.isMutator,this.RTL=e.RTL,t){if(this.type=t,n=$o[t],!n||typeof n!=`object`)throw TypeError(`Invalid block definition for type: `+t);Object.assign(this,n)}e.addTopBlock(this),e.addTypedBlock(this),new.target===qd&&this.doInit_()}doInit_(){var t=e.gd;t||e.B(!0);var n=e.Qc;try{typeof this.init==`function`&&(e.Qc=!1,this.init(),e.Qc=n),Je()&&b(new(x(E.BLOCK_CREATE))(this))}finally{e.B(t),e.Qc=n}this.inputsInlineDefault=this.inputsInline,typeof this.onchange==`function`&&this.setOnChange(this.onchange)}dispose(e=!1){this.disposing=!0,this.tooltip=``,this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.unplug(e),Je()&&b(new(x(E.BLOCK_DELETE))(this)),this.workspace.removeTopBlock(this),this.disposeInternal()}disposeInternal(){this.disposing=!0,this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.workspace.removeTypedBlock(this),this.workspace.removeBlockById(this.id),typeof this.destroy==`function`&&this.destroy(),this.childBlocks_.forEach(e=>e.disposeInternal()),this.inputList.forEach(e=>e.dispose()),this.inputList.length=0,this.getConnections_(!0).forEach(e=>e.dispose()),this.disposed=!0}isDeadOrDying(){return this.disposing||this.disposed}initModel(){if(!this.initialized){for(let e of this.inputList)e.initModel();this.initialized=!0}}unplug(e){this.outputConnection&&this.unplugFromRow(e),this.previousConnection&&this.unplugFromStack(e)}unplugFromRow(e){var t=null,n;(n=this.outputConnection)!=null&&n.isConnected()&&(t=this.outputConnection.targetConnection,this.outputConnection.disconnect()),t&&e&&(e=this.getOnlyValueConnection())&&e.isConnected()&&!e.targetBlock().isShadow()&&(e=e.targetConnection,e==null||e.disconnect(),this.workspace.connectionChecker.canConnect(e,t,!1)?t.connect(e):e==null||e.onFailedConnect(t))}getOnlyValueConnection(){var e=null;for(let t=0;t<this.inputList.length;t++){let n=this.inputList[t].connection;if(n&&n.type===L.INPUT_VALUE&&n.targetConnection){if(e)return null;e=n}}return e}unplugFromStack(e){var t=null,n;if((n=this.previousConnection)!=null&&n.isConnected()&&(t=this.previousConnection.targetConnection,this.previousConnection.disconnect()),e){for(e=this.getNextBlock();e&&(e.isShadow()||!e.isMovable());)e=e.getNextBlock();if(e){var r,i,a;e=((r=e.previousConnection)==null||(i=r.targetBlock())==null||(a=i.nextConnection)==null?void 0:a.targetConnection)??null,e==null||e.disconnect(),t&&this.workspace.connectionChecker.canConnect(t,e,!1)&&t.connect(e)}}}getConnections_(){var e=[];this.outputConnection&&e.push(this.outputConnection),this.previousConnection&&e.push(this.previousConnection),this.nextConnection&&e.push(this.nextConnection);for(let t=0,n;n=this.inputList[t];t++)n.connection&&e.push(n.connection);return e}lastConnectionInStack(e){for(var t=this.nextConnection;t;){let n=t.targetBlock();if(!n||e&&n.isShadow())return t;t=n.nextConnection}return null}bumpNeighbours(){}getParent(){return this.parentBlock_}getInputWithBlock(e){for(let t=0,n;n=this.inputList[t];t++)if(n.connection&&n.connection.targetBlock()===e)return n;return null}getSurroundParent(){var e=this;do{var t=e;if(e=e.getParent(),!e)return null}while(e.getNextBlock()===t);return e}getNextBlock(){return this.nextConnection&&this.nextConnection.targetBlock()}getPreviousBlock(){return this.previousConnection&&this.previousConnection.targetBlock()}getRootBlock(){var e=this;do{var t=e;e=t.parentBlock_}while(e);return t}getTopStackBlock(){var e=this;do var t=e.getPreviousBlock();while(t&&t.getNextBlock()===e&&(e=t));return e}getChildren(e){if(!e)return this.childBlocks_;e=[];for(let n=0,r;r=this.inputList[n];n++)if(r.connection){var t=r.connection.targetBlock();t&&e.push(t)}return(t=this.getNextBlock())&&e.push(t),e}setParent(e){if(e!==this.parentBlock_){var t=this.previousConnection&&this.previousConnection.targetBlock()||this.outputConnection&&this.outputConnection.targetBlock(),n=!!t;if(n&&e&&t!==e)throw Error(`Block connected to superior one that is not new parent.`);if(!n&&e)throw Error(`Block not connected to new parent.`);if(n&&!e)throw Error(`Cannot set parent to null while block is still connected to superior block.`);this.parentBlock_?f(this.parentBlock_.childBlocks_,this):this.workspace.removeTopBlock(this),(this.parentBlock_=e)?e.childBlocks_.push(this):this.workspace.addTopBlock(this)}}getDescendants(e){var t=[this],n=this.getChildren(e);for(let r,i=0;r=n[i];i++)t.push(...r.getDescendants(e));return t}isDeletable(){return this.deletable&&!this.isInFlyout&&!this.shadow&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnDeletable(){return this.deletable}setDeletable(e){this.deletable=e}isMovable(){return this.movable&&!this.isInFlyout&&!this.shadow&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnMovable(){return this.movable}setMovable(e){this.movable=e}isDuplicatable(){return!this.workspace.hasBlockLimits()||this.workspace.isCapacityAvailable(Me(this,!0))}isShadow(){return this.shadow}setShadow(e){this.shadow=e}isInsertionMarker(){return this.isInsertionMarker_}setInsertionMarker(e){this.isInsertionMarker_=e}isEditable(){return this.editable&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()}isOwnEditable(){return this.editable}setEditable(e){this.editable=e;for(let e of this.getFields())e.updateEditable()}isDisposed(){return this.disposed}getFullBlockField(){if(!this.isSimpleReporter())return null;var e,t=(e=this.inputList[0])==null?void 0:e.fieldRow[0];return t!=null&&t.isFullBlockField()?t:null}isSimpleReporter(){if(!this.outputConnection)return!1;for(let e of this.inputList)if(e.connection||e.fieldRow.length>1)return!1;return!0}getMatchingConnection(e,t){var n=this.getConnections_(!0);if(e=e.getConnections_(!0),n.length!==e.length)throw Error(`Connection lists did not match in length.`);for(let r=0;r<e.length;r++)if(e[r]===t)return n[r];return null}setHelpUrl(e){this.helpUrl=e}setTooltip(e){this.tooltip=e}getTooltip(){return cr(this)}getColour(){return this.colour_}getStyleName(){return this.styleName_}getHue(){return this.hue}setColour(e){e=Ar(e),this.hue=e.hue,this.colour_=e.hex}setStyle(e){this.styleName_=e}setOnChange(e){if(e&&typeof e!=`function`)throw Error(`onchange must be a function.`);this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.onchange=e,this.onchangeWrapper=e.bind(this),this.workspace.addChangeListener(this.onchangeWrapper)}getField(e){if(typeof e!=`string`)throw TypeError(`Block.prototype.getField expects a string with the field name but received `+(e===void 0?`nothing`:e+` of type `+typeof e)+` instead`);for(let t of this.getFields())if(t.name===e)return t;return null}*getFields(){for(let e of this.inputList)for(let t of e.fieldRow)yield t}getVarModels(){var e=[];for(let t of this.getFields())if(t.referencesVariables()){let n=this.workspace.getVariableMap().getVariableById(t.getValue());n&&e.push(n)}return e}updateVarName(e){for(let t of this.getFields())t.referencesVariables()&&e.getId()===t.getValue()&&t.refreshVariableName()}renameVarById(e,t){for(let n of this.getFields())n.referencesVariables()&&e===n.getValue()&&n.setValue(t)}getFieldValue(e){return(e=this.getField(e))?e.getValue():null}setFieldValue(e,t){var n=this.getField(t);if(!n)throw Error(`Field "`+t+`" not found.`);n.setValue(e)}setPreviousStatement(e,t){if(e)t===void 0&&(t=null),this.previousConnection||=this.makeConnection_(L.PREVIOUS_STATEMENT),this.previousConnection.setCheck(t);else if(this.previousConnection){if(this.previousConnection.isConnected())throw Error(`Must disconnect previous statement before removing connection.`);this.previousConnection.dispose(),this.previousConnection=null}}setNextStatement(e,t){if(e)t===void 0&&(t=null),this.nextConnection||=this.makeConnection_(L.NEXT_STATEMENT),this.nextConnection.setCheck(t);else if(this.nextConnection){if(this.nextConnection.isConnected())throw Error(`Must disconnect next statement before removing connection.`);this.nextConnection.dispose(),this.nextConnection=null}}setOutput(e,t){if(e)t===void 0&&(t=null),this.outputConnection||=this.makeConnection_(L.OUTPUT_VALUE),this.outputConnection.setCheck(t);else if(this.outputConnection){if(this.outputConnection.isConnected())throw Error(`Must disconnect output value before removing connection.`);this.outputConnection.dispose(),this.outputConnection=null}}setInputsInline(e){this.inputsInline!==e&&(b(new(x(E.BLOCK_CHANGE))(this,`inline`,null,this.inputsInline,e)),this.inputsInline=e)}getInputsInline(){if(this.inputsInline!==void 0)return this.inputsInline;for(var t=1;t<this.inputList.length;t++)if(this.inputList[t-1]instanceof Wd&&this.inputList[t]instanceof Wd)return!1;for(t=1;t<this.inputList.length;t++)if(this.inputList[t-1]instanceof e.Nn&&this.inputList[t]instanceof Wd)return!0;for(t=0;t<this.inputList.length;t++)if(this.inputList[t]instanceof Gd)return!0;return!1}setOutputShape(e){this.outputShape_=e}getOutputShape(){return this.outputShape_}isEnabled(){return this.disabledReasons.size===0}setDisabledReason(e,t){e||this.workspace.options.disable||!this.hasDisabledReason(`MANUALLY_DISABLED`)||t==`MANUALLY_DISABLED`||this.setDisabledReason(!1,`MANUALLY_DISABLED`),this.disabledReasons.has(t)!==e&&(e?this.disabledReasons.add(t):this.disabledReasons.delete(t),e=new(x(E.BLOCK_CHANGE))(this,`disabled`,null,!e,e),e.setDisabledReason(t),b(e))}getInheritedDisabled(){for(var e=this.getSurroundParent();e;){if(!e.isEnabled())return!0;e=e.getSurroundParent()}return!1}hasDisabledReason(e){return this.disabledReasons.has(e)}getDisabledReasons(){return this.disabledReasons}isCollapsed(){return this.collapsed_}setCollapsed(e){this.collapsed_!==e&&(b(new(x(E.BLOCK_CHANGE))(this,`collapsed`,null,this.collapsed_,e)),this.collapsed_=e)}setAriaRoleDescriptionProvider(e){this.ariaRoleDescriptionProvider=e}getAriaRoleDescription(){return this.ariaRoleDescriptionProvider?typeof this.ariaRoleDescriptionProvider==`function`?this.ariaRoleDescriptionProvider():kr(this.ariaRoleDescriptionProvider):this.statementInputCount?e.C.BLOCK_LABEL_CONTAINER:this.outputConnection?e.C.BLOCK_LABEL_VALUE:e.C.BLOCK_LABEL_STATEMENT}toString(e,t){t=this.toTokens(t);for(let e=2;e<t.length;e++)t[e-2]===`(`&&t[e]===`)`&&(t[e-2]=t[e-1],t.splice(e-1,2));var n=``;return t=t.reduce((e,t)=>(e=e+(n===`(`||t===`)`?``:` `)+t,n=t[t.length-1],e),``),t=t.trim()||`???`,e&&t.length>e&&(t=t.substring(0,e-3)+`...`),t}toTokens(e=`?`){var t=[];for(let r of this.inputList)if(r.name!=`_TEMP_COLLAPSED_INPUT`){for(let e of r.fieldRow)t.push(e.getText());if(r.connection){let i=r.connection.targetBlock();if(i){var n=r.connection;let a=n.getCheck();!a&&n.targetConnection&&(a=n.targetConnection.getCheck()),(n=!!a&&(a.includes(`Boolean`)||a.includes(`Number`)))&&t.push(`(`),t.push(...i.toTokens(e)),n&&t.push(`)`)}else t.push(e)}}return t}appendValueInput(t){return this.appendInput(new e.Nn(t,this))}appendStatementInput(e){return this.statementInputCount++,this.appendInput(new Kd(e,this))}appendDummyInput(e=``){return this.appendInput(new Wd(e,this))}appendEndRowInput(e=``){return this.appendInput(new Gd(e,this))}appendInput(e){return this.inputList.push(e),e}appendInputFromRegistry(e,t){return(e=Le(M.INPUT,e,!1))?this.appendInput(new e(t,this)):null}jsonInit(t){var n=t.type?`Block "`+t.type+`": `:``;if(t.output&&t.previousStatement)throw Error(n+`Must not have both an output and a previousStatement.`);for(var r=0;t[`args${r}`];){if(t[`message${r}`]===void 0)throw Error(n+`args${r} must have a corresponding message (message${r}).`);r++}if(t.style&&typeof t.style==`object`&&(this.hat=t.style.hat,t.style=null),t.style&&t.colour)throw Error(n+`Must not have both a colour and a style.`);for(t.style?this.jsonInitStyle(t,n):this.jsonInitColour(t,n),r=0;t[`message${r}`]!==void 0;)this.interpolate(t[`message${r}`]||``,t[`args${r}`]||[],t[`implicitAlign${r}`]||t[`lastDummyAlign${r}`],n),r++;if(t.inputsInline!==void 0&&(e.Ub++,this.setInputsInline(t.inputsInline),e.Ub--),t.output!==void 0&&this.setOutput(!0,t.output),t.outputShape!==void 0&&this.setOutputShape(t.outputShape),t.previousStatement!==void 0&&this.setPreviousStatement(!0,t.previousStatement),t.nextStatement!==void 0&&this.setNextStatement(!0,t.nextStatement),t.tooltip!==void 0&&(r=kr(t.tooltip),this.setTooltip(r)),t.enableContextMenu!==void 0&&(this.contextMenu=!!t.enableContextMenu),t.suppressPrefixSuffix!==void 0&&(this.suppressPrefixSuffix=!!t.suppressPrefixSuffix),t.helpUrl!==void 0&&(r=kr(t.helpUrl),this.setHelpUrl(r)),t.ariaRoleDescription!==void 0&&this.setAriaRoleDescriptionProvider(t.ariaRoleDescription),typeof t.extensions==`string`&&(console.warn(n+`JSON attribute 'extensions' should be an array of strings. Found raw string in JSON for '`+t.type+`' block.`),t.extensions=[t.extensions]),t.mutator!==void 0&&di(t.mutator,this,!0),t=t.extensions,Array.isArray(t))for(n=0;n<t.length;n++)di(t[n],this,!1)}jsonInitColour(e,t){if(`colour`in e){if(e.colour===void 0)console.warn(t+`Undefined colour value.`);else{e=e.colour;try{this.setColour(e)}catch{console.warn(t+`Illegal colour value: `,e)}}}}jsonInitStyle(e,t){e=e.style;try{this.setStyle(e)}catch{console.warn(t+`Style does not exist: `,e)}}mixin(e,t){if(t!==void 0&&typeof t!=`boolean`)throw Error(`opt_disableCheck must be a boolean if provided`);if(!t){t=[];for(let n in e)this[n]!==void 0&&t.push(n);if(t.length)throw Error(`Mixin will overwrite block members: `+JSON.stringify(t))}Object.assign(this,e)}interpolate(e,t,n,r){e=Or(e),this.validateTokens(e,t.length),t=this.interpolateArguments(e,t,n),n=[];for(let i=0,a;a=t[i];i++)if(this.isInputKeyword(a.type)){if(e=this.inputFromJson(a,r)){for(let t=0,r;r=n[t];t++)e.appendField(r[0],r[1]);n.length=0}}else(e=this.fieldFromJson(a))&&n.push([e,a.name])}validateTokens(e,t){var n=[],r=0;for(let i=0;i<e.length;i++){let a=e[i];if(typeof a==`number`){if(a<1||a>t)throw Error(`Block "`+this.type+`": Message index %`+a+` out of range.`);if(n[a])throw Error(`Block "`+this.type+`": Message index %`+a+` duplicated.`);n[a]=!0,r++}}if(r!==t)throw Error(`Block "`+this.type+`": Message does not reference all `+t+` arg(s).`)}interpolateArguments(e,t,n){var r=[];for(let a=0;a<e.length;a++){var i=e[a];if(typeof i==`number`&&(i=t[i-1]),typeof i==`string`){if(i===`
826
826
  `)i={type:`input_end_row`},n&&(i.align=n);else if(i=this.stringToFieldJson(i),!i)continue}r.push(i)}return(e=r.length)&&!this.isInputKeyword(r[e-1].type)&&(e={type:`input_dummy`},n&&(e.align=n),r.push(e)),r}fieldFromJson(t){var n=e.lh(t);return!n&&t.alt?typeof t.alt==`string`?(t=this.stringToFieldJson(t.alt))?this.fieldFromJson(t):null:this.fieldFromJson(t.alt):n}inputFromJson(t,n){var r={LEFT:e.En.LEFT,RIGHT:e.En.RIGHT,CENTRE:e.En.CENTRE,CENTER:e.En.CENTRE};switch(t.type){case`input_value`:var i=this.appendValueInput(t.name);break;case`input_statement`:i=this.appendStatementInput(t.name);break;case`input_dummy`:i=this.appendDummyInput(t.name);break;case`input_end_row`:i=this.appendEndRowInput(t.name);break;default:i=this.appendInputFromRegistry(t.type,t.name)}return i?(t.check&&i.setCheck(t.check),t.align&&(r=r[t.align.toUpperCase()],r===void 0?console.warn(n+`Illegal align value: `,t.align):i.setAlign(r)),t.ariaLabelText&&i.setAriaLabelProvider(t.ariaLabelText),i):null}isInputKeyword(e){return e===`input_value`||e===`input_statement`||e===`input_dummy`||e===`input_end_row`||Re(M.INPUT,e)}stringToFieldJson(e){return(e=e.trim())?{type:`field_label`,text:e}:null}moveInputBefore(e,t){if(e!==t){var n=-1,r=t?-1:this.inputList.length;for(let i=0,a;a=this.inputList[i];i++)if(a.name===e){if(n=i,r!==-1)break}else if(t&&a.name===t&&(r=i,n!==-1))break;if(n===-1)throw Error(`Named input "`+e+`" not found.`);if(r===-1)throw Error(`Reference input "`+t+`" not found.`);this.moveNumberedInputBefore(n,r)}}moveNumberedInputBefore(e,t){if(e===t)throw Error(`Can't move input to itself.`);if(e>=this.inputList.length)throw RangeError(`Input index `+e+` out of bounds.`);if(t>this.inputList.length)throw RangeError(`Reference input `+t+` out of bounds.`);var n=this.inputList[e];this.inputList.splice(e,1),e<t&&t--,this.inputList.splice(t,0,n)}removeInput(e,t){for(let t=0,n;n=this.inputList[t];t++)if(n.name===e)return n instanceof Kd&&this.statementInputCount--,n.dispose(),this.inputList.splice(t,1),!0;if(t)return!1;throw Error(`Input not found: `+e)}getInput(e){for(let t=0,n;n=this.inputList[t];t++)if(n.name===e)return n;return null}getInputTargetBlock(e){return(e=this.getInput(e))&&e.connection&&e.connection.targetBlock()}getCommentText(){var e;return((e=this.getIcon(Kc.COMMENT))==null?void 0:e.getText())??null}setCommentText(t){var n,r=((n=this.getIcon(Kc.COMMENT))==null?void 0:n.getText())??null;if(r!==t){if(t!==null){if(n=this.getIcon(Kc.COMMENT),!n){if(n=Le(M.ICON,Kc.COMMENT.toString(),!1),!n)throw Error(`No comment icon class is registered, so a comment cannot be set`);if(n=new n(this),!(Ci(n)&&Wt(n)&&Ot(n)&&typeof n.setText==`function`&&typeof n.getText==`function`&&typeof n.setBubbleSize==`function`&&typeof n.getBubbleSize==`function`&&typeof n.setBubbleLocation==`function`&&typeof n.getBubbleLocation==`function`&&n.getType()===Kc.COMMENT))throw Error(`The class registered as a comment icon does not conform to the ICommentIcon interface`);n=this.addIcon(n)}e.Ub++,n.setText(t),e.Ub--}else this.removeIcon(Kc.COMMENT);b(new(x(E.BLOCK_CHANGE))(this,`comment`,null,r,t))}}setWarningText(){}setMutator(){}addIcon(e){if(this.hasIcon(e.getType()))throw new Id(e);return this.icons.push(e),this.icons.sort((e,t)=>e.getWeight()-t.getWeight()),e}removeIcon(e){if(!this.hasIcon(e))return!1;var t;return(t=this.getIcon(e))==null||t.dispose(),this.icons=this.icons.filter(t=>!t.getType().equals(e)),!0}hasIcon(e){return this.icons.some(t=>t.getType().equals(e))}getIcon(e){return e instanceof Kc?this.icons.find(t=>t.getType().equals(e)):this.icons.find(t=>t.getType().toString()===e)}getIcons(){return[...this.icons]}getRelativeToSurfaceXY(){return this.xy.clone()}moveBy(e,t,n){if(this.parentBlock_)throw Error(`Block has parent`);var r=new(x(E.BLOCK_MOVE))(this);n&&r.setReason(n),this.xy.translate(e,t),r.recordNew(),b(r)}makeConnection_(e){return new q(this,e)}allInputsFilled(e){if(e===void 0&&(e=!0),!e&&this.isShadow())return!1;for(let n=0,r;r=this.inputList[n];n++)if(r.connection){var t=r.connection.targetBlock();if(!t||!t.allInputsFilled(e))return!1}return!(t=this.getNextBlock())||t.allInputsFilled(e)}toDevString(){var e=this.type?`"`+this.type+`" block`:`Block`;return this.id&&(e+=` (id="`+this.id+`")`),e}};qd.COLLAPSED_INPUT_NAME=`_TEMP_COLLAPSED_INPUT`,qd.COLLAPSED_FIELD_NAME=`_TEMP_COLLAPSED_FIELD`;var Jd=null,Yd=null,Xd={};Xd.connectionUiEffect=Ei,Xd.disconnectUiEffect=Di,Xd.disconnectUiStop=ki,Xd.disposeUiEffect=wi;var Zd=class{paste(t,n,r){if(!n.isCapacityAvailable(t.typeCounts))return null;r&&(t.blockState.x=r.x,t.blockState.y=r.y),r??=new N(t.blockState.x||0,t.blockState.y||0),e.Ub++;try{var i=pn(t.blockState,n);Ai(i,r)}finally{e.Ub--}if(!i)return i;Je()&&!i.isShadow()&&b(new(x(E.BLOCK_CREATE))(i));var a=i;return At().then(()=>e.t().focusNode(a)),i}};Zd.TYPE=`block`,Tt(Zd.TYPE,new Zd);var Qd={};Qd.bumpIntoBounds=Ni,Qd.bumpIntoBoundsHandler=Pi,Qd.bumpTopObjectsIntoBounds=Fi;var $d=null,ef=null,tf=void 0,nf={};nf.BlockPaster=Zd,nf.copy=Ii,nf.getLastCopiedData=function(){return $d},nf.getLastCopiedLocation=function(){return tf},nf.getLastCopiedWorkspace=function(){return ef},nf.paste=Li,nf.registry=xc,nf.setLastCopiedData=function(e){$d=e},nf.setLastCopiedLocation=function(e){tf=e},nf.setLastCopiedWorkspace=function(e){ef=e};var rf={};rf.CollapseCommentBarButton=ld,rf.CommentBarButton=cd,rf.CommentEditor=ud,rf.CommentView=fd,rf.DeleteCommentBarButton=dd,rf.RenderedWorkspaceComment=md,rf.WorkspaceComment=pd;var af=class{constructor(t,n,r,i){if(this.workspace=t,this.targetWorkspace=n,this.isFlyoutLabel=i,this.height=this.width=0,this.cursorSvg=this.svgText=null,this.text=r.text,this.position=new N(0,0),this.callbackKey=r.callbackKey||r.callbackkey,this.cssClass=r[`web-class`]||null,this.info=r,t=this.isFlyoutLabel?`blocklyFlyoutLabel`:`blocklyFlyoutButton`,this.cssClass&&(t+=` `+this.cssClass),this.id=He(),this.svgGroup=h(A.G,{id:this.id,class:t},this.workspace.getCanvas()),!this.isFlyoutLabel){var a=h(A.RECT,{class:`blocklyFlyoutButtonShadow`,rx:af.BORDER_RADIUS,ry:af.BORDER_RADIUS,x:1,y:1},this.svgGroup);p(a,O.NONE)}t=h(A.RECT,{class:this.isFlyoutLabel?`blocklyFlyoutLabelBackground`:`blocklyFlyoutButtonBackground`,rx:af.BORDER_RADIUS,ry:af.BORDER_RADIUS},this.svgGroup),p(t,O.NONE),n=h(A.TEXT,{class:this.isFlyoutLabel?`blocklyFlyoutLabelText`:`blocklyText`,x:0,y:0,"text-anchor":`middle`},this.svgGroup),r=kr(this.text),this.workspace.RTL&&(r+=`‏`),n.textContent=r,this.isFlyoutLabel&&(this.svgText=n,this.workspace.getThemeManager().subscribe(this.svgText,`flyoutForegroundColour`,`fill`)),p(n,O.NONE),i=`${r}, ${this.isFlyoutLabel?e.C.ARIA_LABEL_HEADING:e.C.ARIA_LABEL_BUTTON}`,m(this.getFocusableElement(),k.LABEL,i),p(this.getFocusableElement(),O.OPTION),i=Qe(n,`fontSize`);var s=Qe(n,`fontWeight`),c=Qe(n,`fontFamily`);if(this.width=he(n,i,s,c),r=ge(r,i,s,c),this.height=this.height||r.height,!this.isFlyoutLabel){this.width+=2*af.TEXT_MARGIN_X,this.height+=2*af.TEXT_MARGIN_Y;let e;(e=a)==null||e.setAttribute(`width`,String(this.width));let t;(t=a)==null||t.setAttribute(`height`,String(this.height))}t.setAttribute(`width`,String(this.width)),t.setAttribute(`height`,String(this.height)),n.setAttribute(`x`,String(this.width/2)),n.setAttribute(`y`,String(this.height/2-r.height/2+r.baseline)),this.updateTransform(),this.onMouseDownWrapper=o(this.svgGroup,`pointerdown`,this,this.onMouseDown),this.onMouseUpWrapper=o(this.svgGroup,`pointerup`,this,this.onMouseUp)}createDom(){return this.svgGroup}show(){this.updateTransform(),this.svgGroup.setAttribute(`display`,`block`)}updateTransform(){this.svgGroup.setAttribute(`transform`,`translate(`+this.position.x+`,`+this.position.y+`)`)}moveTo(e,t){this.position.x=e,this.position.y=t,this.updateTransform()}moveBy(e,t){this.moveTo(this.position.x+e,this.position.y+t)}isLabel(){return this.isFlyoutLabel}getPosition(){return this.position}getBoundingRectangle(){return new P(this.position.y,this.position.y+this.height,this.position.x,this.position.x+this.width)}getButtonText(){return this.text}getTargetWorkspace(){return this.targetWorkspace}getWorkspace(){return this.workspace}dispose(){c(this.onMouseDownWrapper),c(this.onMouseUpWrapper),this.svgGroup&&v(this.svgGroup),this.svgText&&this.workspace.getThemeManager().unsubscribe(this.svgText)}setCursorSvg(e){e?this.svgGroup&&(this.svgGroup.appendChild(e),this.cursorSvg=e):this.cursorSvg=null}onMouseUp(e){(e=this.targetWorkspace.getGesture(e))&&e.cancel(),this.isFlyoutLabel&&this.callbackKey?console.warn(`Labels should not have callbacks. Label text: `+this.text):this.isFlyoutLabel||this.callbackKey&&this.targetWorkspace.getButtonCallback(this.callbackKey)?this.isFlyoutLabel||(e=this.targetWorkspace.getButtonCallback(this.callbackKey))&&e(this):console.warn(`Buttons should have callbacks. Button text: `+this.text)}onMouseDown(e){var t=this.targetWorkspace.getGesture(e),n=this.targetWorkspace.getFlyout();t&&n&&t.handleFlyoutStart(e,n)}getSvgRoot(){return this.svgGroup}getFocusableElement(){return this.svgGroup}getFocusableTree(){return this.workspace}onNodeFocus(){var e=this.getPosition();e=new P(e.y,e.y+this.height,e.x,e.x+this.width),this.workspace.scrollBoundsIntoView(e)}onNodeBlur(){}canBeFocused(){return!0}getId(){return this.id}performAction(){if(this.isFlyoutLabel){var t=this.targetWorkspace;let n=e.C.KEYBOARD_NAV_FLYOUT_LABEL_HINT.replace(`%1`,vn(J.NEXT_HEADING));Pc.show(t,{message:n,id:`flyoutLabelHint`})}else(t=this.targetWorkspace.getButtonCallback(this.callbackKey))&&t(this)}};af.TEXT_MARGIN_X=5,af.TEXT_MARGIN_Y=2,af.BORDER_RADIUS=4,te(`
827
827
  .blocklyFlyoutButton {
828
828
  fill: #888;
@@ -852,7 +852,7 @@ children`),this.state=e}},au=class extends eu{constructor(e,t,n){super(`Cannot a
852
852
  }
853
853
  `);var of,sf=of||={};sf[sf.COMMIT=1]=`COMMIT`,sf[sf.DELETE=2]=`DELETE`,sf[sf.REVERT=3]=`REVERT`;var J,Y=J||={};Y.ESCAPE=`escape`,Y.DELETE=`delete`,Y.COPY=`copy`,Y.CUT=`cut`,Y.PASTE=`paste`,Y.UNDO=`undo`,Y.REDO=`redo`,Y.MENU=`menu`,Y.FOCUS_WORKSPACE=`focus_workspace`,Y.FOCUS_TOOLBOX=`focus_toolbox`,Y.START_MOVE=`start_move`,Y.START_MOVE_STACK=`start_move_stack`,Y.FINISH_MOVE=`finish_move`,Y.ABORT_MOVE=`abort_move`,Y.MOVE_UP=`move_up`,Y.MOVE_DOWN=`move_down`,Y.MOVE_LEFT=`move_left`,Y.MOVE_RIGHT=`move_right`,Y.NAVIGATE_RIGHT=`right`,Y.NAVIGATE_LEFT=`left`,Y.NAVIGATE_UP=`up`,Y.NAVIGATE_DOWN=`down`,Y.DISCONNECT=`disconnect`,Y.NEXT_STACK=`next_stack`,Y.PREVIOUS_STACK=`previous_stack`,Y.INFORMATION=`information`,Y.EXTENDED_INFORMATION=`extended_information`,Y.PERFORM_ACTION=`perform_action`,Y.DUPLICATE=`duplicate`,Y.CLEANUP=`cleanup`,Y.SHOW_TOOLTIP=`show_tooltip`,Y.NEXT_HEADING=`next_heading`,Y.PREVIOUS_HEADING=`previous_heading`,Y.TOGGLE_SCREENREADER=`toggle_screenreader`,Y.JUMP_TOP_STACK=`jump_to_top_of_stack`,Y.JUMP_BOTTOM_STACK=`jump_to_bottom_of_stack`,Y.JUMP_BLOCK_START=`jump_to_block_start`,Y.JUMP_BLOCK_END=`jump_to_block_end`,Y.JUMP_FIRST_BLOCK=`jump_to_first_block`,Y.JUMP_LAST_BLOCK=`jump_to_last_block`;var cf=e=>{if(e.isFlyout){let t=e.targetWorkspace;if(t)return cf(t)}return e.getRootWorkspace()??e},lf=(t,n)=>!t.isFlyout&&!!n.focusedNode&&!t.isDragging()&&!e.t().ephemeralFocusTaken()&&!!t.getNavigator().getSourceBlockFromNode(n.focusedNode);_a(),va(),ya();var X={};X.names=J,X.registerArrowNavigation=Qi,X.registerCleanup=ca,X.registerCopy=Gi,X.registerCut=Ki,X.registerDefaultShortcuts=_a,X.registerDelete=Ui,X.registerDisconnectBlock=ra,X.registerDuplicate=sa,X.registerEscape=Hi,X.registerFocusToolbox=ea,X.registerFocusWorkspace=$i,X.registerHeadingNavigation=aa,X.registerJumpBlockEnd=fa,X.registerJumpBlockStart=da,X.registerJumpBottomStack=ma,X.registerJumpFirstBlock=ha,X.registerJumpLastBlock=ga,X.registerJumpTopStack=pa,X.registerKeyboardNavigationShortcuts=va,X.registerMovementShortcuts=Xi,X.registerNavigationShortcuts=function(){da(),fa(),pa(),ma(),ha(),ga()},X.registerPaste=qi,X.registerPerformAction=oa,X.registerReadExtendedInformation=na,X.registerReadInformation=ta,X.registerRedo=Yi,X.registerScreenReaderShortcuts=ya,X.registerShowContextMenu=Zi,X.registerShowTooltip=la,X.registerStackNavigation=ia,X.registerToggleScreenreaderMode=ua,X.registerUndo=Ji;var uf,df=uf||={};df[df.CONSTRAINED=1]=`CONSTRAINED`,df[df.UNCONSTRAINED=2]=`UNCONSTRAINED`;var ff=class{constructor(e){this.block=e,this.connectionPreviewer=this.connectionCandidate=this.startLoc=this.startChildConn=this.startParentConn=null,this.dragging=!1,this.allConnectionPairs=[],this.moveMode=uf.UNCONSTRAINED,this.originalEventGroup=``,this.lastBlockDisabledReasons=new Map,this.WORKSPACE_MARGIN=this.BLOCK_CONNECTION_OFFSET=10,this.workspace=e.workspace}isMovable(){var e;return this.block.isOwnMovable()&&!this.block.isDeadOrDying()&&!this.workspace.isReadOnly()&&(!this.block.isInFlyout||this.block.isEnabled()&&!((e=this.block.workspace.targetWorkspace)!=null&&e.isReadOnly()))}positionNewBlock(t,n){if(t=lt(t.workspace,t.getRelativeToSurfaceXY()),t=ct(n.workspace,t),n.moveDuringDrag(t),this.moveMode===uf.CONSTRAINED){var r=n.workspace,i=this.WORKSPACE_MARGIN;t=this.WORKSPACE_MARGIN;var a=Math.max(e.Og.connectingSnapRadius,e.Og.snapRadius)+2,o=r.getTopBlocks(!0).filter(e=>e.id!==n.id).map(e=>(e=e.getBoundingRectangle(),new P(e.top-a,e.bottom+a,e.left-a,e.right+a))),s,c=(s=r.getToolbox())==null?void 0:s.getWidth();s=r.getParentSvg().clientWidth-(c??0),r.getParentSvg(),{width:c}=n.getHeightWidth();var l=function(e){for(let t of o)if(e.intersects(t))return t;return null},u=t;r=r.getRenderer().getConstants().MIN_BLOCK_HEIGHT;var d=n.getBoundingRectangle();n.moveBy(u-d.left,i-d.top,[`cleanup`]),d=n.getBoundingRectangle();for(var ee=l(d);ee!=null;)u=ee.left+ee.getWidth()+80,ee=ee.top+ee.getHeight()+r,u+c<=s||(i=ee,u=t),n.moveBy(u-d.left,i-d.top,[`cleanup`]),d=n.getBoundingRectangle(),ee=l(d)}}getTargetBlock(){if(this.block.isShadow()){var t=this.block.getParent();if(t)return t}else if(this.block.isInFlyout&&this.block.workspace.targetWorkspace&&(t=this.block.getRootBlock(),t=dn(t)))return t=mn(t,this.block.workspace.targetWorkspace,{recordUndo:!0}),e.Qc=!1,t.render(),this.positionNewBlock(this.block,t),e.Qc=!0,t;return this.block}announceMove(t=!1){if(this.connectionCandidate)t=Fn(this.connectionCandidate.local,this.connectionCandidate.neighbour,this.hasMultipleCompatibleConnections.bind(this),t);else{let n=t?this.block.getStackBlocksCountLabel():``;t=e.C.ANNOUNCE_MOVE_WORKSPACE,t=t.replace(`%1`,n)}se(t.replace(/\s+/g,` `))}hasMultipleCompatibleConnections(e=!0){var t=this.connectionCandidate;if(!t)return!1;var n=e?`local`:`neighbour`,r=e?`neighbour`:`local`;return this.allConnectionPairs.filter(e=>e[r]===t[r]&&e[n]!==t[n].getSourceBlock().nextConnection&&e[n].getSourceBlock().id===t[n].getSourceBlock().id).length>1}startDrag(e){this.updateMoveMode(e);var t=this.getTargetBlock();if(t!==this.block)return t.startDrag(e);this.block.workspace.recordDragTargets(),this.dragging=!0,this.fireDragStartEvent(),this.startLoc=this.block.getRelativeToSurfaceXY(),this.connectionCandidate=null,this.connectionPreviewer=new(Ve(M.CONNECTION_PREVIEWER,this.workspace.options))(this.block),fe(),this.workspace.setResizesEnabled(!1),ki(),t=this.shouldHealStack(e),this.storeInitialConnections(t),this.shouldDisconnect(t)&&this.disconnectBlock(t),this.block.setDragging(!0),this.enableAllDraggedBlocks(this.block),this.cacheAllConnectionPairs(),e instanceof KeyboardEvent?(e=this.getInitialCandidate()??void 0,this.updateConnectionPreview(this.block,new N(0,0),e)&&this.block.moveDuringDrag(this.determineConnectionOffset()),this.allConnectionPairs.length?xa(this.workspace):ba(this.workspace)):this.block.moveDuringDrag(this.startLoc);var n;return(n=this.workspace.getLayerManager())==null||n.moveToDragLayer(this.block),this.getVisibleBubbles(this.block).forEach(e=>{var t;(t=this.workspace.getLayerManager())==null||t.moveToDragLayer(e,!1)}),this.announceMove(!0),this.block}cacheAllConnectionPairs(){var e=this.block.workspace.connectionChecker,t=[];this.allConnectionPairs=[];var n=this.getLocalConnections(this.block);for(let e of this.block.workspace.getTopBlocks(!0))t.push(...this.getAllConnections(e));for(let r of t)for(let t of n){let n;!e.canConnect(t,r,!0,1/0)||(n=r.targetBlock())!=null&&n.isInsertionMarker()||this.allConnectionPairs.push({local:t,neighbour:r})}}getVisibleBubbles(e){return e.getDescendants(!1).flatMap(e=>e.getIcons()).filter(e=>Wt(e)&&e.bubbleIsVisible()).map(e=>e.getBubble()).filter(e=>!!e).sort((e,t)=>(e=e.getSvgRoot().compareDocumentPosition(t.getSvgRoot()),e&Node.DOCUMENT_POSITION_PRECEDING?1:e&Node.DOCUMENT_POSITION_FOLLOWING?-1:0))}shouldHealStack(e){return e instanceof PointerEvent?e.ctrlKey||e.metaKey:e instanceof KeyboardEvent&&!(e.shiftKey||!this.block.previousConnection)}shouldDisconnect(e){return!!(this.block.getParent()||e&&this.block.nextConnection&&this.block.nextConnection.targetBlock())}disconnectBlock(e){this.block.unplug(e),Di(this.block)}storeInitialConnections(e){var t=this.startChildConn=this.startParentConn=null,n=null,r;if((r=this.block.outputConnection)!=null&&r.isConnected())t=this.block.outputConnection,n=this.block.outputConnection.targetConnection;else{let e;(e=this.block.previousConnection)!=null&&e.isConnected()&&(t=this.block.previousConnection,n=this.block.previousConnection.targetConnection)}this.startParentConn=n,t&&n?this.connectionCandidate={local:t,neighbour:n,distance:0}:e&&(e=this.block.nextConnection,t=e==null?void 0:e.targetConnection,e&&t&&(this.connectionCandidate={local:e,neighbour:t,distance:0}),this.startChildConn=t??null)}fireDragStartEvent(){var e=new(x(E.BLOCK_DRAG))(this.block,!0,this.block.getDescendants(!1));b(e)}fireDragEndEvent(){var e=new(x(E.BLOCK_DRAG))(this.block,!1,this.block.getDescendants(!1));b(e)}fireMoveEvent(){if(!this.block.isDeadOrDying()){var e=new(x(E.BLOCK_MOVE))(this.block);e.setReason([`drag`]),e.oldCoordinate=this.startLoc,e.recordNew(),b(e)}}drag(e,t){if(this.updateMoveMode(t),this.moveMode===uf.UNCONSTRAINED&&this.block.moveDuringDrag(e),t=!!this.connectionCandidate,this.updateConnectionPreview(this.block,N.difference(e,this.startLoc)),this.connectionCandidate)this.moveMode===uf.CONSTRAINED&&this.block.moveDuringDrag(this.determineConnectionOffset());else if(this.moveMode===uf.CONSTRAINED&&(this.allConnectionPairs.length||ba(this.workspace,!0),!t)){this.workspace.getAudioManager().playErrorBeep();return}this.announceMove()}determineConnectionOffset(){var{local:e,neighbour:t}=this.connectionCandidate,n=e.getOffsetInBlock(),r=t.x-n.x;n=t.y-n.y;var i=this.BLOCK_CONNECTION_OFFSET;return e.type===L.PREVIOUS_STATEMENT||e.type===L.OUTPUT_VALUE?(r+=i,n+=i):(r-=i,n-=i),new N(r,n)}updateConnectionPreview(e,t,n){var r=this.connectionCandidate;if(n??=this.getConnectionCandidate(t),this.connectionCandidate=null,n){var i=r&&this.currCandidateIsBetter(r,t,n)?r:n;this.connectionCandidate=i;var{local:a,neighbour:o}=i;i=a.type===L.OUTPUT_VALUE||a.type===L.PREVIOUS_STATEMENT;var s;if(t=o.isConnected()&&!((s=o.targetBlock())!=null&&s.isInsertionMarker()),i&&t&&!this.orphanCanConnectAtEnd(e,o.targetBlock(),a.type)){var c;(c=this.connectionPreviewer)==null||c.previewReplacement(a,o,o.targetBlock())}else{let e;(e=this.connectionPreviewer)==null||e.previewConnection(a,o)}return o}if(this.moveMode===uf.CONSTRAINED){if(s=(r==null?void 0:r.neighbour.getSourceBlock())??null,c=(s==null?void 0:s.getRootBlock())??s,c===e&&(c=s),!c){let e;(e=this.connectionPreviewer)==null||e.hidePreview();return}if(s=e.workspace.getTopBlocks().filter(t=>t!==e.getRootBlock()).map(e=>e.getBoundingRectangle()),!s.length){let e;(e=this.connectionPreviewer)==null||e.hidePreview();return}var l;switch(r=(l=r==null?void 0:r.neighbour.x)??e.getRelativeToSurfaceXY().x,l=this.BLOCK_CONNECTION_OFFSET*2,this.getDirectionToNewLocation(N.sum(this.startLoc,t))){case bd.LEFT:case bd.UP:t=Math.min(...s.map(e=>e.top))-l-e.getHeightWidth().height;break;default:t=Math.max(...s.map(e=>e.bottom))+l}e.moveDuringDrag(new N(r,t))}(i=this.connectionPreviewer)==null||i.hidePreview()}orphanCanConnectAtEnd(e,t,n){return!!q.getConnectionForOrphanedConnection(e,n===L.OUTPUT_VALUE?t.outputConnection:t.previousConnection)}currCandidateIsBetter(t,n,r){if(this.moveMode===uf.CONSTRAINED)return!1;var{local:i,neighbour:a}=t;t=new N(i.x,i.y);var o=new N(a.x,a.y);return n=N.distance(N.sum(t,n),o),r.distance>n-e.Og.currentConnectionPreference}getConnectionCandidate(e){return this.moveMode===uf.CONSTRAINED?this.findTraversalCandidate(e):this.getClosestCandidate(this.block,e)}getClosestCandidate(e,t){var n=this.getSearchRadius();e=this.getLocalConnections(e);var r=null;for(let i of e){let{connection:e,radius:a}=i.closest(n,t);e&&(r={local:i,neighbour:e,distance:a},n=a)}return r}getSearchRadius(){return this.moveMode===uf.CONSTRAINED?1/0:this.connectionCandidate?e.Og.connectingSnapRadius:e.Og.snapRadius}getLocalConnections(e){var t=e.getConnections_(!1),n=e.lastConnectionInStack(!0);n&&n!==e.nextConnection&&t.push(n),e=[e.outputConnection,e.previousConnection,e.nextConnection].filter(e=>!!e),n=[];for(let r of t)e.includes(r)||n.push(r);return n.reverse(),[...e,...n]}endDrag(t,n){n===of.DELETE&&wi(this.block),this.originalEventGroup=e.gd,this.fireDragEndEvent(),this.fireMoveEvent(),pe(),ki();var r;if((r=this.connectionPreviewer)==null||r.hidePreview(),!this.block.isDeadOrDying()&&this.dragging){let e;(e=this.workspace.getLayerManager())==null||e.moveOffDragLayer(this.block,50),this.getVisibleBubbles(this.block).forEach(e=>{var t;return(t=this.workspace.getLayerManager())==null?void 0:t.moveOffDragLayer(e,100,!1)}),this.block.setDragging(!1),this.redisableAllDraggedBlocks(this.block)}this.connectionCandidate?(this.applyConnections(this.connectionCandidate),this.disposeStep()):(n!==of.DELETE&&this.workspace.getAudioManager().play(`drop`),this.block.queueRender().then(()=>this.disposeStep())),this.allConnectionPairs=[],this.connectionCandidate=this.startChildConn=this.startParentConn=null,this.dragging=!1}disposeStep(){var t=e.gd;e.B(this.originalEventGroup),this.block.snapToGrid();var n;(n=this.connectionPreviewer)==null||n.dispose(),this.workspace.setResizesEnabled(!0),e.B(t)}applyConnections(e){var{local:t,neighbour:n}=e;t.connect(n);var r=t.isSuperior()?n:t,i=this.block.getRootBlock();At().then(()=>{Ei(r.getSourceBlock()),setTimeout(()=>{i.bringToFront()},0)})}revertDrag(){var t;if((t=this.connectionPreviewer)==null||t.hidePreview(),this.connectionCandidate=null,this.block.nextConnection){let e;(e=this.startChildConn)==null||e.connect(this.block.nextConnection)}if(this.startParentConn)switch(this.startParentConn.type){case L.INPUT_VALUE:this.block.outputConnection&&this.startParentConn.connect(this.block.outputConnection);break;case L.NEXT_STATEMENT:this.block.previousConnection&&this.startParentConn.connect(this.block.previousConnection)}else{this.block.moveDuringDrag(this.startLoc);let e;(e=this.workspace.getLayerManager())==null||e.moveOffDragLayer(this.block,50),this.getVisibleBubbles(this.block).forEach(e=>{var t;return(t=this.workspace.getLayerManager())==null?void 0:t.moveOffDragLayer(e,100,!1)}),Ni(this.workspace,this.workspace.getMetricsManager().getScrollMetrics(!0),this.block)}this.startParentConn=this.startChildConn=null,this.block.setDragging(!1),this.redisableAllDraggedBlocks(this.block),this.dragging=!1,se(e.C.ANNOUNCE_MOVE_CANCELED)}findTraversalCandidate(e){var t=this.getDirectionToNewLocation(N.sum(this.startLoc,e)),n=this.allConnectionPairs;if(t===bd.NONE||!n.length)return this.connectionCandidate;t=t===bd.RIGHT||t===bd.DOWN;var r=n.findIndex(e=>{var t,n;return((t=this.connectionCandidate)==null?void 0:t.local)===e.local&&((n=this.connectionCandidate)==null?void 0:n.neighbour)===e.neighbour}),i=this.block.workspace.getNavigator();return t?r===-1?this.isInTerminalPosition(this.block,bd.DOWN)?i.getNavigationLoops()?this.pairToCandidate(n[0]):null:this.getClosestCandidate(this.block,e):r===n.length-1?null:this.pairToCandidate(n[r+1]):r===-1?this.isInTerminalPosition(this.block,bd.UP)?i.getNavigationLoops()?this.pairToCandidate(n[n.length-1]):null:this.getClosestCandidate(this.block,e):r===0?null:this.pairToCandidate(n[r-1])}isInTerminalPosition(e,t){if(e.getParent())return!1;var n=e.workspace.getTopBlocks(!0),r=e.getBoundingRectangle(),i=(t=t===bd.UP)?`top`:`bottom`,a=t?(e,t)=>e<=t:(e,t)=>e>=t;t=n.filter(t=>t.id!==e.id&&a(t.getBoundingRectangle()[i],r[i])),n=e.getConnections_(!1);for(let r of t){t=this.getAllConnections(r);for(let r of n)for(let n of t)if(e.workspace.connectionChecker.canConnect(r,n,!0,1/0))return!1}return!0}pairToCandidate(e){return Object.assign({},e,{distance:0})}getDirectionToNewLocation(e){var t=this.block.getRelativeToSurfaceXY();e=N.difference(e,t);var{x:n,y:r}=e;return Math.abs(n)>Math.abs(r)?n<0?bd.LEFT:bd.RIGHT:Math.abs(r)>0?r<0?bd.UP:bd.DOWN:bd.NONE}getAllConnections(e){if(e.isShadow())return[];var t=[];if(e.outputConnection&&t.push(e.outputConnection),e.previousConnection&&t.push(e.previousConnection),!e.isCollapsed()){for(let n of e.inputList)if(n.connection&&n.isVisible()){t.push(n.connection);let e=n.connection.targetBlock();e&&t.push(...this.getAllConnections(e))}}return e.nextConnection&&(t.push(e.nextConnection),(e=e.nextConnection.targetBlock())&&t.push(...this.getAllConnections(e))),t}getInitialCandidate(){var e=this.workspace.getSvgGroup().querySelector(`.${xs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME}`);if(!e||!e.id||e===this.block.getFocusableElement()||(e=this.workspace.lookUpFocusableNode(e.id),!e))return null;var t=this.workspace.getNavigator().getSourceBlockFromNode(e);if(!t)return null;var n=null;if(t.getConnections_(!1).includes(e)){n=e;let t=this.block.workspace.connectionChecker;if(e=this.block.getConnections_(!1).find(e=>t.canConnect(e,n,!0,1/0)))return{local:e,neighbour:n,distance:0}}if(e=this.allConnectionPairs.find(e=>e.neighbour.getSourceBlock()===t))return this.pairToCandidate(e);var r,i=(r=t.outputConnection)==null?void 0:r.targetConnection;if(r=this.allConnectionPairs.find(e=>e.neighbour===i))return this.pairToCandidate(r);for(var a=t.getSurroundParent();a;){if(r=this.allConnectionPairs.find(e=>e.neighbour.getSourceBlock()===a))return this.pairToCandidate(r);a=a.getSurroundParent()}return null}updateMoveMode(e){this.moveMode=e instanceof KeyboardEvent&&!e.ctrlKey&&!e.metaKey?uf.CONSTRAINED:uf.UNCONSTRAINED}enableAllDraggedBlocks(t){var n=e.Qc;e.Qc=!1,this.lastBlockDisabledReasons.clear(),t.getDescendants(!1).forEach(e=>{var t=new Set(e.getDisabledReasons());this.lastBlockDisabledReasons.set(e.id,t),t.forEach(t=>e.setDisabledReason(!1,t))}),e.Qc=n}redisableAllDraggedBlocks(t){var n=e.Qc;e.Qc=!1,t.getDescendants(!1).forEach(e=>{var t;(t=this.lastBlockDisabledReasons.get(e.id))==null||t.forEach(t=>{e.setDisabledReason(!0,t)})}),e.Qc=n}},pf=class extends V{isLabelField(){return!0}constructor(e,t,n){super(V.SKIP_SETUP),this.class=null,this.EDITABLE=!1,this.maxDisplayLength=1/0,e!==V.SKIP_SETUP&&(n?this.configure_(n):this.class=t||null,this.setValue(e))}configure_(e){super.configure_(e),e.class&&(this.class=e.class)}initView(){this.createTextElement_(),this.class&&g(this.getTextElement(),this.class),this.fieldGroup_&&(g(this.fieldGroup_,`blocklyLabelField`),m(this.fieldGroup_,k.HIDDEN,!0))}computeAriaLabel(e=!0){e=e?this.getAriaTypeName():null;var t=this.getAriaValue()??``;return e?`${e}: ${t}`:t}doClassValidation_(e){return e==null?null:`${e}`}setClass(e){this.textElement_&&(this.class&&_(this.textElement_,this.class),e&&g(this.textElement_,e)),this.class=e}static fromJson(e){return new this(kr(e.text),void 0,e)}};ci(`field_label`,pf),pf.prototype.DEFAULT_VALUE=``;var mf=class extends K{constructor(e,t,n,r,i){super(t,n,r,void 0,i),this.text=e,this.workspace=t,this.anchor=n,this.ownerRect=r,this.owner=i,this.paragraph=this.stringToSvg(e,this.contentContainer),this.updateBubbleSize(),g(this.svgRoot,`blocklyTextBubble`)}getText(){return this.text}setText(e){this.text=e,v(this.paragraph),this.paragraph=this.stringToSvg(e,this.contentContainer),this.updateBubbleSize()}stringToSvg(e,t){return t=this.createParagraph(t),e=this.createTextFragments(t,e),this.workspace.RTL&&this.rightAlignTextFragments(t.getBBox().width,e),t}createParagraph(e){return h(A.G,{class:`blocklyText blocklyBubbleText blocklyNoPointerEvents`,transform:`translate(0,${K.BORDER_WIDTH})`,style:`direction: ${this.workspace.RTL?`rtl`:`ltr`}`},e)}createTextFragments(e,t){var n=1;return t.split(`
854
854
  `).map(t=>{var r=h(A.TEXT,{y:`${n}em`,x:K.BORDER_WIDTH},e);return t=document.createTextNode(t),r.appendChild(t),n+=1,r})}rightAlignTextFragments(e,t){for(let n of t)n.setAttribute(`text-anchor`,`start`),n.setAttribute(`x`,`${e+K.BORDER_WIDTH}`)}updateBubbleSize(){var e=this.paragraph.getBBox();this.setSize(new F(e.width+K.BORDER_WIDTH*2,e.height+K.BORDER_WIDTH*2),!0)}},hf=class extends Od{constructor(e){super(e),this.sourceBlock=e,this.textMap=new Map,this.textBubble=null}getType(){return hf.TYPE}initView(e){this.svgRoot||(super.initView(e),h(A.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),h(A.PATH,{class:`blocklyIconSymbol`,d:`m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z`},this.svgRoot),h(A.RECT,{class:`blocklyIconSymbol`,x:`7`,y:`11`,height:`2`,width:`2`},this.svgRoot),g(this.svgRoot,`blocklyWarningIcon`))}dispose(){super.dispose();var e;(e=this.textBubble)==null||e.dispose()}getWeight(){return hf.WEIGHT}getSize(){return new F(17,17)}applyColour(){super.applyColour();var e;(e=this.textBubble)==null||e.setColour(this.sourceBlock.getColour())}updateCollapsed(){}isShownWhenCollapsed(){return!0}onLocationChange(e){super.onLocationChange(e);var t;(t=this.textBubble)==null||t.setAnchorLocation(this.getAnchorLocation())}addMessage(e,t){if(this.textMap.get(t)===e)return this;e?this.textMap.set(t,e):this.textMap.delete(t);var n;return(n=this.textBubble)==null||n.setText(this.getText()),this}getText(){return[...this.textMap.values()].join(`
855
- `)}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}bubbleIsVisible(){return!!this.textBubble}setBubbleVisible(t){var n=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){if(n.bubbleIsVisible()!==t){if(yield At(),t)n.textBubble=new mf(n.getText(),n.sourceBlock.workspace,n.getAnchorLocation(),n.getBubbleOwnerRect(),n),n.applyColour(),n.textBubble.setAriaLabelProvider(()=>e.C.BUBBLE_LABEL_WARNING.replace(`%1`,n.getText()));else{let e;(e=n.textBubble)==null||e.dispose(),n.textBubble=null}b(new(x(E.BUBBLE_OPEN))(n.sourceBlock,t,`warning`)),n.recomputeAriaContext()}})}getBubble(){return this.textBubble}getAnchorLocation(){return N.sum(this.workspaceLocation,new N(8.5,8.5))}getBubbleOwnerRect(){var e=this.sourceBlock.getSvgRoot().getBBox();return new P(e.y,e.y+e.height,e.x,e.x+e.width)}getAriaLabel(){return this.bubbleIsVisible()?e.C.ICON_LABEL_WARNING_OPEN:e.C.ICON_LABEL_WARNING_CLOSED}};hf.TYPE=Kc.WARNING,hf.WEIGHT=2;var gf=class extends qd{constructor(e,t,n){if(super(e,t,n),this.childlessWidth=this.width=this.height=0,this.warningTextDb=new Map,this.mutator=null,this.rendered=!0,this.visuallyDisabled=!1,this.previousConnection=this.nextConnection=this.outputConnection=null,this.translation=``,this.dragging=!1,this.relativeCoords=new N(0,0),this.dragStrategy=new ff(this),!e.rendered)throw TypeError(`Cannot create a rendered block in a headless workspace`);this.workspace=e,this.svgGroup=h(A.G,{}),t&&g(this.svgGroup,t),this.style=e.getRenderer().getConstants().getBlockStyle(null),this.pathObject=e.getRenderer().makePathObject(this.svgGroup,this.style),e=this.pathObject.svgPath,e.tooltip=this,dr(e),this.svgGroup.setAttribute(`data-id`,this.id),e.id=He(),this.doInit_()}initSvg(){if(!this.initialized){for(var e of this.inputList)e.init();for(let e of this.getIcons())e.initView(this.createIconPointerDownListener(e)),e.updateEditable();this.applyColour(),this.pathObject.updateMovable(this.isMovable()||this.isInFlyout),(e=this.getSvgRoot())&&o(e,`pointerdown`,this,this.onMouseDown),e.parentNode||this.workspace.getCanvas().appendChild(e),this.recomputeAriaContext(),this.initialized=!0}}getColourSecondary(){return this.style.colourSecondary}getColourTertiary(){return this.style.colourTertiary}select(){this.addSelect(),Oe(this)}unselect(){this.removeSelect(),Oe(null)}setParent(t){var n=this.parentBlock_;if(t!==n){fe(),super.setParent(t),pe();var r=this.getSvgRoot();if(!this.workspace.isClearing&&r){var i=this.getRelativeToSurfaceXY(),a=e.t().getFocusedNode(),o,s=this.getSvgRoot().contains((o=a==null?void 0:a.getFocusableElement())??null);t?(t.getSvgRoot().appendChild(r),s&&a&&e.t().focusNode(a)):n&&(t=this.workspace.getCanvas().querySelector(`.blocklyDragging`),n=t==null?void 0:t.parentElement,o=this.workspace.getCanvas(),n===o?o.insertBefore(r,t):(o.appendChild(r),s&&a&&e.t().focusNode(a)),this.translate(i.x,i.y)),this.applyColour(),this.recomputeAriaContext()}}}moveBy(e,t,n){if(this.parentBlock_)throw Error(`Block has parent`);var r=Je(),i=null;r&&(i=new(x(E.BLOCK_MOVE))(this),n&&i.setReason(n)),e=new N(e,t),t=this.getRelativeToSurfaceXY(),e=N.sum(t,e),this.translate(e.x,e.y),this.workspace.connectionDBList.forEach(e=>e==null?void 0:e.beginBulkUpdates()),this.updateComponentLocations(e),this.workspace.connectionDBList.forEach(e=>e==null?void 0:e.endBulkUpdates()),r&&i&&(i.recordNew(),b(i)),this.workspace.resizeContents()}translate(e,t){this.translation=`translate(${e}, ${t})`,this.relativeCoords=new N(e,t),this.getSvgRoot().setAttribute(`transform`,this.getTranslation())}getTranslation(){return this.translation}moveTo(e,t){var n=this.getRelativeToSurfaceXY();this.moveBy(e.x-n.x,e.y-n.y,t)}moveDuringDrag(e){this.translate(e.x,e.y),this.getSvgRoot().setAttribute(`transform`,this.getTranslation()),this.updateComponentLocations(e)}snapToGrid(){if(!this.isDeadOrDying()&&!this.getParent()&&!this.isInFlyout){var e=this.workspace.getGrid();if(e!=null&&e.shouldSnap()){var t=this.getRelativeToSurfaceXY();e=e.alignXY(t),e!==t&&this.moveTo(e,[`snap`])}}}getBoundingRectangle(){return this.getBoundingRectangleWithDimensions(this.getHeightWidth())}getBoundingRectangleWithoutChildren(){return this.getBoundingRectangleWithDimensions({height:this.height,width:this.childlessWidth})}getBoundingRectangleWithDimensions(e){var t=this.getRelativeToSurfaceXY();if(this.RTL)var n=t.x-e.width,r=t.x;else n=t.x,r=t.x+e.width;return new P(t.y,t.y+e.height,n,r)}markDirty(){this.pathObject.constants=this.workspace.getRenderer().getConstants();for(let e=0,t;t=this.inputList[e];e++)t.markDirty()}setCollapsed(e){this.collapsed_!==e&&(super.setCollapsed(e),this.updateCollapsed())}childHasWarning(){var e=this.getNextBlock();e=e?new Set(e.getDescendants(!1)):null;var t=this.getDescendants(!1);for(let n of t)if(n!==this&&(e==null||!e.has(n))&&n.getIcon(hf.TYPE))return!0;return!1}updateCollapsed(){var t=this.isCollapsed();for(let e=0,n;n=this.inputList[e];e++)n.name!==`_TEMP_COLLAPSED_INPUT`&&n.setVisible(!t);for(var n of this.getIcons())n.updateCollapsed();t?(g(this.svgGroup,`blocklyCollapsed`),this.childHasWarning()&&this.setWarningText(e.C.COLLAPSED_WARNINGS_WARNING,gf.COLLAPSED_WARNING_ID),t=this.toString(30),(n=this.getField(`_TEMP_COLLAPSED_FIELD`))?n.setValue(t):((this.getInput(`_TEMP_COLLAPSED_INPUT`)||this.appendDummyInput(`_TEMP_COLLAPSED_INPUT`)).appendField(new pf(t),`_TEMP_COLLAPSED_FIELD`),this.recomputeAriaContext())):(this.updateDisabled(),this.removeInput(`_TEMP_COLLAPSED_INPUT`),_(this.svgGroup,`blocklyCollapsed`),this.setWarningText(null,gf.COLLAPSED_WARNING_ID))}onMouseDown(e){if(!this.workspace.isReadOnly()){var t=this.workspace.getGesture(e);t&&t.handleBlockStart(e,this)}}showHelp(){var e=typeof this.helpUrl==`function`?this.helpUrl():this.helpUrl;e&&window.open(e)}generateContextMenu(e){return this.workspace.isReadOnly()||!this.contextMenu?null:(e=H.registry.getContextMenuOptions({block:this,focusedNode:this},e),this.customContextMenu&&this.customContextMenu(e),e)}calculateContextMenuLocation(e){if(e instanceof PointerEvent)return new N(e.clientX,e.clientY);e=lt(this.workspace,this.getRelativeToSurfaceXY());var t,n,r=(t=this.inputList.filter(e=>e.isVisible()).flatMap(e=>e.fieldRow).find(e=>e.isVisible()))==null||(n=t.getSvgRoot())==null?void 0:n.getBoundingClientRect();return new N(this.RTL?e.x-5:e.x+5,(r&&r.height?r.y+r.height:e.y+this.height)+5)}showContextMenu(t){if(this.isShadow()){for(var n=this.getParent();n&&n.isShadow();)n=n.getParent();n&&(e.t().focusNode(n),n.showContextMenu(t))}else{n=this.generateContextMenu(t);var r=this.calculateContextMenuLocation(t);n&&n.length&&(Br(t,n,this.RTL,this.workspace,r),$u=this)}}updateComponentLocations(e){this.xy.x=e.x,this.xy.y=e.y,this.dragging||this.updateConnectionLocations(e),this.updateIconLocations(e),this.updateFieldLocations(e);for(let t of this.getChildren(!1))t.updateComponentLocations(N.sum(e,t.relativeCoords))}updateConnectionLocations(e){for(let t of this.getConnections_(!1))t.moveToOffset(e)}updateIconLocations(e){for(let t of this.getIcons())t.onLocationChange(e)}updateFieldLocations(e){for(let t of this.inputList)for(let n of t.fieldRow)n.onLocationChange(e)}addClass(e){g(this.svgGroup,e)}removeClass(e){_(this.svgGroup,e)}setDragging(e){(this.dragging=e)?(this.translation=``,As.push(...this.getConnections_(!0)),this.addClass(`blocklyDragging`)):(As.length=0,this.removeClass(`blocklyDragging`),this.getFullBlockField()&&this.recomputeAriaContext());for(let t=0;t<this.childBlocks_.length;t++)this.childBlocks_[t].setDragging(e)}isDragging(){return this.dragging}setMovable(e){super.setMovable(e),this.pathObject.updateMovable(e)}setEditable(e){super.setEditable(e),e?_(this.svgGroup,`blocklyNotEditable`):g(this.svgGroup,`blocklyNotEditable`),e=this.getIcons();for(let t=0;t<e.length;t++)e[t].updateEditable()}setShadow(e){super.setShadow(e),this.applyColour(),this.recomputeAriaContext()}setInsertionMarker(e){this.isInsertionMarker_!==e&&(this.isInsertionMarker_=e)&&(this.setColour(this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR),this.pathObject.updateInsertionMarker(!0))}getSvgRoot(){return this.svgGroup}getNearestNeighbour(){if(!this.workspace.rendered)return null;var e=this.workspace.getAllBlocks(!1).filter(e=>!e.isDeadOrDying()),t=null,n=2**53-1,r=this.getRelativeToSurfaceXY();for(let i of e)e=i.getRelativeToSurfaceXY(),e=Math.sqrt((e.x-r.x)**2+(e.y-r.y)**2),e<n&&(t=i,n=e);return t}dispose(t,n){this.disposing=!0,fr(this.pathObject.svgPath),delete this.pathObject.svgPath.tooltip,gr(),Wr(),n&&(this.unplug(t),wi(this));var r=e.t(),i;if(n=((i=r.getFocusedNode())==null?void 0:i.getFocusableElement())??null,super.dispose(!!t),v(this.svgGroup),this.getSvgRoot().contains(n)){let e=this.getParent();if(!e&&(t=this.outputConnection??this.previousConnection)){let n;e=(n=t.closest(0,new N(0,0)).connection)==null?void 0:n.getSourceBlock()}setTimeout(()=>{if(this.workspace.rendered)if(e)r.focusNode(e);else{let e=this.getNearestNeighbour();e?r.focusNode(e):r.focusTree(this.workspace)}},0)}}disposeInternal(){this.disposing=!0,super.disposeInternal(),e.t().getFocusedNode()===this&&this.workspace.cancelCurrentGesture(),[...this.warningTextDb.values()].forEach(e=>clearTimeout(e)),this.warningTextDb.clear(),this.getIcons().forEach(e=>e.dispose())}checkAndDelete(){this.workspace.isFlyout||(e.B(!0),this.workspace.hideChaff(),this.outputConnection?this.dispose(!1,!0):this.dispose(!0,!0),e.B(!1))}toCopyData(e=!1){return this.isInsertionMarker_?null:{paster:Zd.TYPE,blockState:dn(this,{addCoordinates:!0,addNextBlocks:e,saveIds:!1}),typeCounts:Me(this,!0)}}applyColour(){var e,t;for((t=(e=this.pathObject).applyColour)==null||t.call(e,this),e=this.getIcons(),t=0;t<e.length;t++)e[t].applyColour();for(let e of this.getFields())e.applyColour()}updateDisabled(){var e=!this.isEnabled()||this.getInheritedDisabled();if(this.visuallyDisabled===e){let e;(e=this.getNextBlock())==null||e.updateDisabled()}else{this.applyColour(),this.visuallyDisabled=e;for(let e of this.getChildren(!1))e.updateDisabled();this.recomputeAriaContext()}}setWarningText(t,n=``){if(n)this.warningTextDb.has(n)&&(clearTimeout(this.warningTextDb.get(n)),this.warningTextDb.delete(n));else{for(var r of this.warningTextDb.values())clearTimeout(r);this.warningTextDb.clear()}if(this.workspace.isDragging())this.warningTextDb.set(n,setTimeout(()=>{this.isDeadOrDying()||(this.warningTextDb.delete(n),this.setWarningText(t,n))},100));else if(this.isInFlyout&&(t=null),r=this.getIcon(hf.TYPE),t){let i=this.getSurroundParent(),a=null;for(;i;)i.isCollapsed()&&(a=i),i=i.getSurroundParent();a&&a.setWarningText(e.C.COLLAPSED_WARNINGS_WARNING,gf.COLLAPSED_WARNING_ID),r?r.addMessage(t,n):this.addIcon(new hf(this).addMessage(t,n))}else r&&(n?(r.addMessage(``,n),r.getText()||this.removeIcon(hf.TYPE)):this.removeIcon(hf.TYPE))}setMutator(t){this.removeIcon(e.sh.TYPE),t&&this.addIcon(t)}addIcon(t){return super.addIcon(t),t instanceof e.sh&&(this.mutator=t),t.initView(this.createIconPointerDownListener(t)),t.applyColour(),t.updateEditable(),this.queueRender(),t}createIconPointerDownListener(t){return n=>{!this.isDeadOrDying()&&(n=this.workspace.getGesture(n))&&(this.bringToFront(),n.setStartIcon(t),e.t().focusNode(t))}}removeIcon(t){var n=super.removeIcon(t);return t.equals(e.sh.TYPE)&&(this.mutator=null),this.queueRender(),n}setDisabledReason(e,t){var n=this.isEnabled();super.setDisabledReason(e,t),this.isEnabled()===n||this.getInheritedDisabled()||this.updateDisabled()}setDeletable(e){super.setDeletable(e),e?_(this.svgGroup,`blocklyNotDeletable`):g(this.svgGroup,`blocklyNotDeletable`)}setHighlighted(e){this.pathObject.updateHighlighted(e)}addSelect(){this.pathObject.updateSelected(!0)}removeSelect(){this.pathObject.updateSelected(!1)}setDeleteStyle(e){this.pathObject.updateDraggingDelete(e)}getColour(){return this.style.colourPrimary}setColour(e){super.setColour(e),e=this.workspace.getRenderer().getConstants().getBlockStyleForColour(this.colour_);var t,n;(n=(t=this.pathObject).setStyle)==null||n.call(t,e.style),this.style=e.style,this.styleName_=e.name,this.applyColour()}setStyle(e){var t=this.workspace.getRenderer().getConstants().getBlockStyle(e);if(this.styleName_&&_(this.svgGroup,this.styleName_),t){this.hat=t.hat;let n,r;(r=(n=this.pathObject).setStyle)==null||r.call(n,t),this.colour_=t.colourPrimary,this.style=t,this.applyColour(),g(this.svgGroup,e),this.styleName_=e}else throw Error(`Invalid style name: `+e)}getStyle(){return this.style}bringToFront(t=!1){var n=e.t().getFocusedNode();this.moveSvgRootToFront(t),n&&e.t().focusNode(n)}moveSvgRootToFront(e=!1){this.isDeadOrDying()||requestAnimationFrame(()=>{if(!this.dragging){var t=this;do{if(t.isDeadOrDying())break;let n=t.getSvgRoot(),r=n.parentNode;if(!r)break;let i=r.childNodes;if(i[i.length-1]!==n)for(;n.nextSibling;)r.insertBefore(n.nextSibling,n);if(e)break;t=t.getParent()}while(t)}})}setPreviousStatement(e,t){super.setPreviousStatement(e,t),this.queueRender()}setNextStatement(e,t){super.setNextStatement(e,t),this.queueRender()}setOutput(e,t){super.setOutput(e,t),this.queueRender()}setInputsInline(e){super.setInputsInline(e),this.queueRender()}removeInput(e,t){return e=super.removeInput(e,t),this.queueRender(),e}moveNumberedInputBefore(e,t){super.moveNumberedInputBefore(e,t),this.queueRender()}appendInput(e){return super.appendInput(e),this.queueRender(),e}setConnectionTracking(e){if(this.previousConnection&&this.previousConnection.setTracking(e),this.outputConnection&&this.outputConnection.setTracking(e),this.nextConnection){this.nextConnection.setTracking(e);var t=this.nextConnection.targetBlock();t&&t.setConnectionTracking(e)}if(!this.collapsed_)for(t=0;t<this.inputList.length;t++){var n=this.inputList[t].connection;n&&(n.setTracking(e),(n=n.targetBlock())&&n.setConnectionTracking(e))}}getConnections_(e){var t=[];if(this.outputConnection&&t.push(this.outputConnection),this.previousConnection&&t.push(this.previousConnection),this.nextConnection&&t.push(this.nextConnection),e||!this.collapsed_)for(let e=0,n;n=this.inputList[e];e++)n.connection&&t.push(n.connection);return t}lastConnectionInStack(e){return super.lastConnectionInStack(e)}getMatchingConnection(e,t){return super.getMatchingConnection(e,t)}makeConnection_(e){return new Bd(this,e)}getNextBlock(){return super.getNextBlock()}getPreviousBlock(){return super.getPreviousBlock()}bumpNeighbours(){var t=this.getRootBlock();if(!(this.isDeadOrDying()||this.workspace.isDragging()||this.isDragging()||t.isInFlyout))for(let n of this.getConnections_(!1)){if(n.isSuperior()){let e;(e=n.targetBlock())==null||e.bumpNeighbours()}for(let r of n.neighbours(e.Og.snapRadius))r.getSourceBlock().getRootBlock()!==t&&(n.isConnected()&&r.isConnected()||(n.isSuperior()?r.bumpAwayFrom(n,!1):r.getSourceBlock().isDragging()||n.bumpAwayFrom(r,!0)))}}scheduleSnapAndBump(){this.snapToGrid(),this.bumpNeighbours()}positionNearConnection(e,t,n){if(e.type===L.NEXT_STATEMENT||e.type===L.INPUT_VALUE){let r=t.x;t=t.y,r+=n.x-e.getOffsetInBlock().x,t+=n.y-e.getOffsetInBlock().y,this.moveBy(r,t)}}getChildren(e){return super.getChildren(e)}queueRender(){return kt(this)}render(){this.queueRender(),jt()}renderEfficiently(){fe(),this.isCollapsed()&&this.updateCollapsed(),this.isEnabled()||this.updateDisabled(),this.workspace.getRenderer().render(this),this.tightenChildrenEfficiently(),pe()}tightenChildrenEfficiently(){for(let e of this.inputList){let t=e.connection;t&&t.tightenEfficiently()}this.nextConnection&&this.nextConnection.tightenEfficiently()}getHeightWidth(){var e=this.height,t=this.width,n=this.getNextBlock();if(n){n=n.getHeightWidth();let r=this.workspace.getRenderer().getConstants().NOTCH_HEIGHT;e+=n.height-r,t=Math.max(t,n.width)}return{height:e,width:t}}fadeForReplacement(e){var t,n;(n=(t=this.pathObject).updateReplacing)==null||n.call(t,e)}getDragStrategy(){return this.dragStrategy}setDragStrategy(e){this.dragStrategy=e}isCopyable(){return this.isOwnDeletable()&&this.isOwnMovable()}isMovable(){return this.dragStrategy.isMovable()}startDrag(e){return this.dragStrategy.startDrag(e)}drag(e,t){this.dragStrategy.drag(e,t)}endDrag(e,t){this.dragStrategy.endDrag(e,t)}revertDrag(){this.dragStrategy.revertDrag()}toFlyoutInfo(){function e(t){for(let r in t)n.has(r)?delete t[r]:typeof t[r]==`object`&&e(t[r])}var t=Object.assign({},{kind:`BLOCK`},dn(this)),n=new Set([`id`,`height`,`width`,`pinned`,`enabled`]);return e(t),[t]}jsonInit(e){super.jsonInit(e),e.classes&&this.addClass(Array.isArray(e.classes)?e.classes.join(` `):e.classes)}getNestingLevel(){var e=this.getSurroundParent();return e?e.getNestingLevel()+1:0}getFocusableElement(){var e=this.getFullBlockField();return e?e.getFocusableElement():this.pathObject.svgPath}getFocusableTree(){return this.workspace}onNodeFocus(){this.recomputeAriaContext(),this.select(),this.workspace.isFlyout||this.moveSvgRootToFront();var t=e.t().getFocusedNode();t&&t!==this&&At().then(()=>{this.workspace.scrollBoundsIntoView(this.getBoundingRectangleWithoutChildren())})}onNodeBlur(){this.unselect()}canBeFocused(){return!0}performAction(t){if(this.workspace.isFlyout)G.mover.startMove(this,t);else{if(this.isSimpleReporter()){for(var n of this.inputList)for(let e of n.fieldRow)if(e.isClickable()&&e.isFullBlockField()){e.showEditor();return}}this.workspace.getNavigator().getInNode(this)?(t=this.workspace,n=vn(t.RTL?J.NAVIGATE_LEFT:J.NAVIGATE_RIGHT),n=e.C.KEYBOARD_NAV_BLOCK_NAVIGATION_HINT.replace(`%1`,n),Pc.show(t,{message:n,id:`blockNavigationHint`})):(t=this.workspace,(n=vn(`list_shortcuts`))&&(n=e.C.HELP_PROMPT.replace(`%1`,n),Pc.show(t,{message:n,id:`helpHint`})))}}getParents(){for(var e=new Set,t=this.getParent();t;)e.add(t),t=t.getParent();return e}getOutputParents(){var e=new Set;e.add(this);for(var t,n=(t=this.outputConnection)==null?void 0:t.targetBlock();n;){e.add(n);let t;n=(t=n.outputConnection)==null?void 0:t.targetBlock()}return e}getRowId(){var e,t,n=(e=this.outputConnection)==null||(t=e.targetConnection)==null?void 0:t.getParentInput();return n?n.getRowId():this.id}recomputeAriaContext(){var e=this.getFullBlockField();e?e.recomputeAriaContext():(m(this.getFocusableElement(),k.LABEL,this.getAriaLabel(ss.STANDARD)),p(this.getSvgRoot(),O.NONE),e=this.getFocusableElement(),this.isInFlyout||p(e,O.FIGURE),m(e,k.ROLEDESCRIPTION,this.getAriaRoleDescription()))}getAriaLabel(e){return Cn(this,e)}getStackBlocksCountLabel(){for(var t=1,n=this.getNextBlock();n;)t++,n=n.getNextBlock();return t<=1?Cn(this,ss.TERSE):e.C.BLOCK_LABEL_STACK_BLOCKS.replace(`%1`,t.toString())}};gf.INLINE=-1,gf.COLLAPSED_WARNING_ID=`TEMP_COLLAPSED_WARNING_`;var _f=class{constructor(){}onDragEnter(){}onDragOver(){}onDragExit(){}onDrop(){}getClientRect(){return null}shouldPreventMove(){return!1}},vf=class extends _f{constructor(){super(),this.wouldDelete_=!1}wouldDelete(e){return G.mover.isMoving()?this.updateWouldDelete_(!1):e instanceof gf?(e=!e.getParent()&&e.isDeletable(),this.updateWouldDelete_(e)):this.updateWouldDelete_(Bi(e)&&e.isDeletable()),this.wouldDelete_}updateWouldDelete_(e){this.wouldDelete_=e}},yf=class{constructor(e,t){this.element=e,this.type=t}getElement(){return this.element}getType(){return this.type}},bf=class{constructor(e){this.workspace_=e}getDimensionsPx_(e){var t=0,n=0;return e&&(t=e.getWidth(),n=e.getHeight()),new F(t,n)}getFlyoutMetrics(e){return e=this.getDimensionsPx_(this.workspace_.getFlyout(e)),{width:e.width,height:e.height,position:this.workspace_.toolboxPosition}}getToolboxMetrics(){var e=this.getDimensionsPx_(this.workspace_.getToolbox());return{width:e.width,height:e.height,position:this.workspace_.toolboxPosition}}getSvgMetrics(){return this.workspace_.getCachedParentSvgSize()}getAbsoluteMetrics(){var e=0,t=0,n=this.getToolboxMetrics(),r=this.getFlyoutMetrics(),i=!!this.workspace_.getToolbox(),a,o=!((a=this.workspace_.getFlyout())!=null&&a.autoClose);a=i?n.position:r.position;var s=a===I.TOP;return a===I.LEFT&&(i&&(e+=n.width),o&&(e+=r.width)),s&&(i&&(t+=n.height),o&&(t+=r.height)),{top:t,left:e}}getViewMetrics(e){e=e?this.workspace_.scale:1;var t=this.getSvgMetrics(),n=this.getToolboxMetrics(),r=this.getFlyoutMetrics(),i=!!this.workspace_.getToolbox(),a,o=!((a=this.workspace_.getFlyout())!=null&&a.autoClose);a=i?n.position:r.position;var s=a===I.LEFT||a===I.RIGHT;return(a===I.TOP||a===I.BOTTOM)&&(i&&(t.height-=n.height),o&&(t.height-=r.height)),s&&(i&&(t.width-=n.width),o&&(t.width-=r.width)),{height:t.height/e,width:t.width/e,top:-this.workspace_.scrollY/e,left:-this.workspace_.scrollX/e}}getContentMetrics(e){e=e?1:this.workspace_.scale;var t=this.workspace_.getBlocksBoundingBox();return{height:(t.bottom-t.top)*e,width:(t.right-t.left)*e,top:t.top*e,left:t.left*e}}hasFixedEdges(){return!this.workspace_.isMovableHorizontally()||!this.workspace_.isMovableVertically()}getComputedFixedEdges_(e){if(!this.hasFixedEdges())return{};var t=this.workspace_.isMovableHorizontally(),n=this.workspace_.isMovableVertically();e||=this.getViewMetrics(!1);var r={};return n||(r.top=e.top,r.bottom=e.top+e.height),t||(r.left=e.left,r.right=e.left+e.width),r}getPaddedContent_(e,t){var n=t.top+t.height,r=t.left+t.width,i=e.width;e=e.height;var a=i/2,o=e/2;return{top:Math.min(t.top-o,n-e),bottom:Math.max(n+o,t.top+e),left:Math.min(t.left-a,r-i),right:Math.max(r+a,t.left+i)}}getScrollMetrics(e,t,n){e=e?this.workspace_.scale:1,t||=this.getViewMetrics(!1);var r=n||this.getContentMetrics();n=this.getComputedFixedEdges_(t),t=this.getPaddedContent_(t,r),r=n.top===void 0?t.top:n.top;var i=n.left===void 0?t.left:n.left;return{top:r/e,left:i/e,width:((n.right===void 0?t.right:n.right)-i)/e,height:((n.bottom===void 0?t.bottom:n.bottom)-r)/e}}getUiMetrics(){return{viewMetrics:this.getViewMetrics(),absoluteMetrics:this.getAbsoluteMetrics(),toolboxMetrics:this.getToolboxMetrics()}}getMetrics(){var e=this.getToolboxMetrics(),t=this.getFlyoutMetrics(!0),n=this.getSvgMetrics(),r=this.getAbsoluteMetrics(),i=this.getViewMetrics(),a=this.getContentMetrics(),o=this.getScrollMetrics(!1,i,a);return{contentHeight:a.height,contentWidth:a.width,contentTop:a.top,contentLeft:a.left,scrollHeight:o.height,scrollWidth:o.width,scrollTop:o.top,scrollLeft:o.left,viewHeight:i.height,viewWidth:i.width,viewTop:i.top,viewLeft:i.left,absoluteTop:r.top,absoluteLeft:r.left,svgHeight:n.height,svgWidth:n.width,toolboxWidth:e.width,toolboxHeight:e.height,toolboxPosition:e.position,flyoutWidth:t.width,flyoutHeight:t.height}}};y(M.METRICS_MANAGER,`default`,bf);var xf=class extends bf{constructor(e,t){super(e),this.flyout_=t}getBoundingBox(){try{var e=this.workspace_.getCanvas().getBBox()}catch{e={height:0,y:0,width:0,x:0}}return e}getContentMetrics(e){var t=this.getBoundingBox();return e=e?1:this.workspace_.scale,{height:t.height*e,width:t.width*e,top:t.y*e,left:t.x*e}}getScrollMetrics(e,t,n){return t=n||this.getContentMetrics(),n=this.flyout_.MARGIN*this.workspace_.scale,e=e?this.workspace_.scale:1,{height:(t.height+2*n)/e,width:(t.width+t.left+n)/e,top:0,left:0}}},Sf=class{constructor(e,t){this.gap=e,this.axis=t,this.y=this.x=0}getBoundingRectangle(){switch(this.axis){case`x`:return new P(this.y,this.y,this.x,this.x+this.gap);case`y`:return new P(this.y,this.y+this.gap,this.x,this.x)}}moveBy(e,t){this.x+=e,this.y+=t}isNavigable(){return!1}getFocusableElement(){throw Error(`Cannot be focused`)}getFocusableTree(){throw Error(`Cannot be focused`)}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!1}},Cf=class{getFirstChild(){return null}getParent(e){return e.getWorkspace()}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.getId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof af}},wf=class{getFirstChild(){return null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(){return`error`}isNavigable(){return!1}isApplicable(e){return e instanceof Sf}},Tf=class{getFirstChild(e){return Sa(e)[0]}getParent(e){var t;if((t=e.previousConnection)!=null&&t.targetBlock()){if(t=e.getSurroundParent())return t}else{let t;if((t=e.outputConnection)!=null&&t.targetBlock())return e.outputConnection.targetBlock()}return e.workspace}getNextSibling(e){if(e.nextConnection)return e.nextConnection.targetBlock()??e.nextConnection;var t;return(t=e.outputConnection)!=null&&t.targetConnection?(t=this.getParent(e),Ca(t,e,1)):null}getPreviousSibling(e){var t;if((t=e.previousConnection)!=null&&t.targetBlock())return e.previousConnection;var n;return(n=e.outputConnection)!=null&&n.targetBlock()?Ca(e.outputConnection.targetBlock(),e,-1):null}getRowId(e){return e.getRowId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof gf}},Ef=class{getFirstChild(){return null}getParent(e){return e.getOwner()??null}getNextSibling(e){var t;return Ca((t=e.getOwner())==null?void 0:t.getSourceBlock(),e,1)}getPreviousSibling(e){var t;return Ca((t=e.getOwner())==null?void 0:t.getSourceBlock(),e,-1)}getRowId(e){var t,n;return((t=e.getOwner())==null||(n=t.getSourceBlock())==null?void 0:n.getRowId())??``}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof K}},Df=class{getFirstChild(){return null}getParent(e){return e.getCommentView().workspace.getCommentById(e.getCommentView().commentId)}getNextSibling(e){var t=e.getCommentView().getCommentBarButtons();return e=t.indexOf(e),e>=0&&e+1<t.length?t[e+1]:null}getPreviousSibling(e){var t=e.getCommentView().getCommentBarButtons();return e=t.indexOf(e),e>0?t[e-1]:null}getRowId(e){return e.getCommentView().commentId}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof cd}},Of=class{getFirstChild(){return null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof ud}},kf=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){if(e.getParentInput())return Ca(e.getSourceBlock(),e,1);if(e.type===L.NEXT_STATEMENT&&e.getSourceBlock().getSurroundParent()&&!e.targetConnection)return Ca(e.getSourceBlock().getSurroundParent(),e,1);switch(e.type){case L.NEXT_STATEMENT:return e.targetConnection;case L.PREVIOUS_STATEMENT:case L.OUTPUT_VALUE:return e.getSourceBlock()}return null}getPreviousSibling(e){if(e.getParentInput())return Ca(e.getParentInput().getSourceBlock(),e,-1);switch(e.type){case L.NEXT_STATEMENT:return e.getSourceBlock();case L.PREVIOUS_STATEMENT:case L.OUTPUT_VALUE:return e.targetConnection}return null}getRowId(e){switch(e.type){case L.NEXT_STATEMENT:case L.PREVIOUS_STATEMENT:return e.id;case L.INPUT_VALUE:return e.getParentInput().getRowId();default:return e.getSourceBlock().getRowId()}}isNavigable(e){return e.canBeFocused()?e.type===L.NEXT_STATEMENT?!e.targetBlock()&&e!==(e.getSourceBlock().getRootBlock()??e.getSourceBlock()).lastConnectionInStack(!1):e.type===L.INPUT_VALUE&&!e.targetBlock():!1}isApplicable(e){return e instanceof Bd}},Af=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){return Ca(e.getSourceBlock(),e,1)}getPreviousSibling(e){return Ca(e.getSourceBlock(),e,-1)}getRowId(e){return e.getParentInput().getRowId()}isNavigable(e){var t;return e.canBeFocused()&&e.isVisible()&&(e.isClickable()||e.isCurrentlyEditable())&&!((t=e.getSourceBlock())!=null&&t.isSimpleReporter()&&e.isFullBlockField())&&e.getParentInput().isVisible()}isApplicable(e){return e instanceof V}},jf=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){return Ca(e.getSourceBlock(),e,1)}getPreviousSibling(e){return Ca(e.getSourceBlock(),e,-1)}getRowId(e){return e.getSourceBlock().getRowId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof Od}},Mf=class{getFirstChild(e){return e.view.getCommentBarButtons()[0]}getParent(e){return e.workspace}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof md}},Nf=class{getFirstChild(e){return e=e.getTopBlocks(!0),e.length?e[0]:null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()&&!e.isMutator}isApplicable(e){return e instanceof Mp}},Pf,Ff=Pf||={};Ff[Ff.NEXT=0]=`NEXT`,Ff[Ff.PREVIOUS=1]=`PREVIOUS`,Ff[Ff.IN=2]=`IN`,Ff[Ff.OUT=3]=`OUT`;var If=class{constructor(){this.rules=[new Tf,new Af,new kf,new Nf,new jf,new Mf,new Df,new Ef,new Of],this.navigationLoops=!0}addNavigationPolicy(e){this.rules.push(e)}get(e){return this.rules.find(t=>t.isApplicable(e))}getFirstChild(e){var t,n=(t=this.get(e))==null?void 0:t.getFirstChild(e);return n?this.isNavigable(n)?n:this.getFirstChild(n)||this.getNextSibling(n):null}getParent(e){var t,n=(t=this.get(e))==null?void 0:t.getParent(e);return n?this.isNavigable(n)?n:this.getParent(n):null}getNextSibling(e){var t,n=(t=this.get(e))==null?void 0:t.getNextSibling(e);return n?this.isNavigable(n)?n:this.getNextSibling(n):null}getPreviousSibling(e){var t,n=(t=this.get(e))==null?void 0:t.getPreviousSibling(e);return n?this.isNavigable(n)?n:this.getPreviousSibling(n):null}getPreviousNode(t=e.t().getFocusedNode()){if(!t)return null;var n=this.getPreviousNodeImpl(t,t,Pf.PREVIOUS);if(!n||n===t.getFocusableTree()){if(n=this.navigateStacks(t,-1),!n)return null;n=this.getLastNodeInStack(n,t)}return this.getLeftmostSibling(n)}getOutNode(t=e.t().getFocusedNode()){return this.getPreviousNodeImpl(t,t,Pf.OUT)}getNextNode(t=e.t().getFocusedNode()){var n=this.getNextNodeImpl(t,t,Pf.NEXT);return t&&n===null?this.navigateStacks(t,1):n}getInNode(t=e.t().getFocusedNode()){return this.getNextNodeImpl(t,t,Pf.IN)}getPreviousNodeImpl(e,t,n,r=new Set){if(!t||!e||r.has(t))return null;var i=this.getRightMostChild(this.getPreviousSibling(t),t)||this.getParent(t);return i&&this.transitionAllowed(e,i,n)?i:i?(r.add(t),this.getPreviousNodeImpl(e,i,n,r)):null}getNextNodeImpl(e,t,n,r=new Set){if(!t||!e||r.has(t))return null;for(var i=this.getFirstChild(t)||this.getNextSibling(t),a=t;a&&!i&&(a=this.getParent(a),a);)i=this.getNextSibling(a);return i&&this.transitionAllowed(e,i,n)?i:i?(r.add(t),this.getNextNodeImpl(e,i,n,r)):null}getRightMostChild(e,t){if(!e)return e;var n=this.getFirstChild(e);if(!n||n===t)return e;for(e=n;e&&e!==t;e=this.getNextSibling(n))n=e;return this.getRightMostChild(n,t)}setNavigationLoops(e){this.navigationLoops=e}getNavigationLoops(){return this.navigationLoops}getFirstNode(){var t,n=(t=e.t().getFocusedTree())==null?void 0:t.getRootFocusableNode();return n?this.getTopLevelItems(n)[0]:null}getLastNode(){var t,n=(t=e.t().getFocusedTree())==null?void 0:t.getRootFocusableNode();return n?this.getTopLevelItems(n).slice(-1)[0]:null}transitionAllowed(e,t,n){switch(n){case Pf.IN:case Pf.OUT:return this.getRowId(e)===this.getRowId(t);case Pf.NEXT:case Pf.PREVIOUS:return this.getRowId(e)!==this.getRowId(t)}}getLeftmostSibling(e){if(!e)return null;for(var t;t=this.getPreviousNodeImpl(e,e,Pf.OUT);)e=t;return e}getLastNodeInStack(e,t){for(var n;(n=this.getNextNodeImpl(e,e,Pf.NEXT))&&n!==t;)e=n;return e}getRowId(e){var t;return(t=this.get(e))==null?void 0:t.getRowId(e)}navigateStacks(e,t){var n=this.getTopLevelItems(e),r,i=((r=this.getSourceBlockFromNode(e))==null?void 0:r.getRootBlock())??e;return e=n.indexOf(i)+t,t=null,e>=0&&e<n.length?t=n[e]:e<0&&this.getNavigationLoops()?t=n[n.length-1]:e>=n.length&&this.getNavigationLoops()&&(t=n[0]),t}getTopLevelItems(e){return e.getFocusableTree().getTopBoundedElements(!0)}isNavigable(e){var t;return(t=this.get(e))==null?void 0:t.isNavigable(e)}getSourceBlockFromNode(e){return e instanceof gf?e:e instanceof V||e instanceof Bd||e instanceof Od?e.getSourceBlock():e instanceof ud?(e=e.getParent(),e instanceof gf?e:null):null}},Lf=class{getFirstChild(e){return wa(e)?e.getChildToolboxItems()[0]:null}getParent(e){return e.getParent()}getNextSibling(e){var t=e.getParentToolbox().getToolboxItems();return e=t.indexOf(e),t[e+1]??null}getPreviousSibling(e){var t=e.getParentToolbox().getToolboxItems();return e=t.indexOf(e),t[e-1]??null}getRowId(e){return e.getId()}isNavigable(e){return e.canBeFocused()&&this.allParentsExpanded(e)}allParentsExpanded(e){return(e=e.getParent())&&wa(e)?e.isExpanded()&&this.allParentsExpanded(e):!0}isApplicable(e){return xn(e)}},Rf=class extends If{constructor(e){super(),this.toolbox=e,this.rules=[new Lf]}getInNode(t=e.t().getFocusedNode(),n=!1){var r=Ta(this.toolbox.getWorkspace());if(!n)switch(r){case I.TOP:case I.BOTTOM:return this.getNextNode(t,!0);case I.RIGHT:return this.getOutNode(t,!0)}if(!Sn(t)||Sn(t)&&!t.getContents().length)return null;var i;return(t=(i=this.toolbox.getFlyout())==null?void 0:i.getWorkspace().getNavigator())?!this.toolbox.getWorkspace().RTL||r!==I.TOP&&r!==I.BOTTOM?t.getFirstNode():t.getLastNode():null}getOutNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:case I.BOTTOM:return this.getPreviousNode(e,!0);case I.RIGHT:return this.getInNode(e,!0)}return super.getOutNode(e)}getNextNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:return this.getInNode(e,!0);case I.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:return this.getOutNode(e,!0);case I.BOTTOM:return this.getInNode(e,!0)}return super.getPreviousNode(e)}getTopLevelItems(){return this.toolbox.getToolboxItems()}},zf=class extends If{constructor(e){super(),this.flyout=e,this.rules.push(new Cf,new wf)}getOutNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:case I.BOTTOM:return this.flyout.RTL?this.getNextNode(e,!0):this.getPreviousNode(e,!0);case I.RIGHT:return null}var n;return(e=(n=this.flyout.targetWorkspace)==null?void 0:n.getToolbox())?e.getSelectedItem():null}getInNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:case I.BOTTOM:return this.flyout.RTL?this.getPreviousNode(e,!0):this.getNextNode(e,!0);case I.RIGHT:return this.getOutNode(e,!0)}return super.getInNode(e)}getNextNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:return null;case I.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:return this.getOutNode(e,!0);case I.BOTTOM:return null}return super.getPreviousNode(e)}getTopLevelItems(){return this.flyout.getContents().map(e=>e.getElement()).filter(e=>this.isNavigable(e))}isNavigable(e){return super.isNavigable(e)&&this.flyout.getContents().map(e=>e.getElement()).includes(e)}},Bf=class{constructor(e,t,n,r,i){this.workspace=e,this.oldHostMetrics=this.corner_=this.vScroll=this.hScroll=null,t=t===void 0||t,n=n===void 0||n;var a=t&&n;t&&(this.hScroll=new Js(e,!0,a,r,i)),n&&(this.vScroll=new Js(e,!1,a,r,i)),a&&(this.corner_=h(A.RECT,{height:Js.scrollbarThickness,width:Js.scrollbarThickness,class:`blocklyScrollbarBackground`}),ue(this.corner_,e.getBubbleCanvas()))}dispose(){v(this.corner_),this.oldHostMetrics=this.corner_=null,this.hScroll&&=(this.hScroll.dispose(),null),this.vScroll&&=(this.vScroll.dispose(),null)}resize(){var t=this.workspace.getMetrics();if(t){var n=!1,r=!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||(n=!0),this.oldHostMetrics&&this.oldHostMetrics.scrollHeight===t.scrollHeight&&this.oldHostMetrics.viewTop===t.viewTop&&this.oldHostMetrics.scrollTop===t.scrollTop||(r=!0)):r=n=!0,n||r){try{e.Ub++,this.hScroll&&n&&this.hScroll.resize(t),this.vScroll&&r&&this.vScroll.resize(t)}finally{e.Ub--}this.workspace.maybeFireViewportChangeEvent()}if(this.hScroll&&this.vScroll){if(!this.oldHostMetrics||this.oldHostMetrics.viewWidth!==t.viewWidth||this.oldHostMetrics.absoluteLeft!==t.absoluteLeft){let e;(e=this.corner_)==null||e.setAttribute(`x`,String(this.vScroll.position.x))}if(!this.oldHostMetrics||this.oldHostMetrics.viewHeight!==t.viewHeight||this.oldHostMetrics.absoluteTop!==t.absoluteTop){let e;(e=this.corner_)==null||e.setAttribute(`y`,String(this.hScroll.position.y))}}this.oldHostMetrics=t}}canScrollHorizontally(){return!!this.hScroll}canScrollVertically(){return!!this.vScroll}setOrigin(e,t){this.hScroll&&this.hScroll.setOrigin(e,t),this.vScroll&&this.vScroll.setOrigin(e,t)}set(e,t,n){this.hScroll&&this.hScroll.set(e,!1),this.vScroll&&this.vScroll.set(t,!1),(n||n===void 0)&&(e={},this.hScroll&&(e.x=this.hScroll.getRatio_()),this.vScroll&&(e.y=this.vScroll.getRatio_()),this.workspace.setMetrics(e))}setX(e){this.hScroll&&this.hScroll.set(e,!0)}setY(e){this.vScroll&&this.vScroll.set(e,!0)}setContainerVisible(e){this.hScroll&&this.hScroll.setContainerVisible(e),this.vScroll&&this.vScroll.setContainerVisible(e)}isVisible(){var e=!1;return this.hScroll&&(e=this.hScroll.isVisible()),this.vScroll&&(e||=this.vScroll.isVisible()),e}setVisible(e){this.hScroll&&this.hScroll.setVisibleInternal(e),this.vScroll&&this.vScroll.setVisibleInternal(e)}resizeContent(e){this.hScroll&&this.hScroll.resizeContentHorizontal(e),this.vScroll&&this.vScroll.resizeContentVertical(e)}resizeView(e){this.hScroll&&this.hScroll.resizeViewHorizontal(e),this.vScroll&&this.vScroll.resizeViewVertical(e)}},Vf=class{load(e,t){return e=new Sf(0,t.horizontalLayout?`x`:`y`),new yf(e,`sep`)}gapForItem(e,t){return parseInt(String(e.gap))??t}disposeItem(){}getType(){return`sep`}};y(M.FLYOUT_INFLATER,`sep`,Vf);var Hf=class extends vf{constructor(e){super(),this.horizontalLayout=!1,this.boundEvents=[],this.reflowWrapper=null,this.inhibitReflowWrapper=!1,this.contents=[],this.autoClose=!0,this.visible=!1,this.containerVisible=!0,this.CORNER_RADIUS=8,this.SCROLLBAR_MARGIN=2.5,this.height_=this.width_=0,this.svgGroup_=this.svgBackground_=null,this.inflaters=new Map,e.setMetrics=this.setMetrics_.bind(this),this.workspace_=new Mp(e),this.workspace_.setMetricsManager(new xf(this.workspace_,this)),this.workspace_.internalIsFlyout=!0,this.workspace_.setVisible(this.visible),this.workspace_.setNavigator(new zf(this)),this.id=Ue(),this.RTL=!!e.RTL,this.toolboxPosition_=e.toolboxPosition,this.tabWidth_=this.workspace_.getRenderer().getConstants().TAB_WIDTH,this.MARGIN=this.CORNER_RADIUS,this.GAP_X=this.MARGIN*3,this.GAP_Y=this.MARGIN*3}createDom(t){return this.svgGroup_=h(t,{class:`blocklyFlyout`}),this.svgGroup_.style.display=`none`,this.svgBackground_=h(A.PATH,{class:`blocklyFlyoutBackground`},this.svgGroup_),this.svgGroup_.appendChild(this.workspace_.createDom()),this.workspace_.getThemeManager().subscribe(this.svgBackground_,`flyoutBackgroundColour`,`fill`),this.workspace_.getThemeManager().subscribe(this.svgBackground_,`flyoutOpacity`,`fill-opacity`),this.svgGroup_.addEventListener(`keydown`,t=>{t.key===`Escape`&&(e.t().focusTree(this.targetWorkspace),this.targetWorkspace.isMutator||this.autoHide(!1),t.preventDefault(),t.stopPropagation())}),this.svgGroup_}init(e){this.targetWorkspace=e,this.workspace_.targetWorkspace=e,this.workspace_.setInitialAriaContext(),this.workspace_.scrollbar=new Bf(this.workspace_,this.horizontalLayout,!this.horizontalLayout,`blocklyFlyoutScrollbar`,this.SCROLLBAR_MARGIN),this.hide(),this.boundEvents.push(o(this.svgGroup_,`wheel`,this,this.wheel_,!1,{passive:!1})),this.boundEvents.push(o(this.svgBackground_,`pointerdown`,this,this.onMouseDown)),this.workspace_.getGesture=this.targetWorkspace.getGesture.bind(this.targetWorkspace),this.workspace_.setVariableMap(this.targetWorkspace.getVariableMap()),this.workspace_.createPotentialVariableMap(),e.getComponentManager().addComponent({component:this,weight:T.ComponentWeight.FLYOUT_WEIGHT,capabilities:[T.Capability.AUTOHIDEABLE,T.Capability.DELETE_AREA,T.Capability.DRAG_TARGET]})}dispose(){this.hide(),this.targetWorkspace.getComponentManager().removeComponent(this.id);for(let e of this.boundEvents)c(e);this.boundEvents.length=0,this.workspace_&&(this.workspace_.getThemeManager().unsubscribe(this.svgBackground_),this.workspace_.dispose()),this.svgGroup_&&v(this.svgGroup_)}getWidth(){return this.width_}getHeight(){return this.height_}getFlyoutScale(){return this.targetWorkspace.scale}getWorkspace(){return this.workspace_}setAutoClose(e){this.autoClose=e,this.targetWorkspace.recordDragTargets(),this.targetWorkspace.resizeContents()}autoHide(e){!e&&this.targetWorkspace.getFlyout(!0)===this&&this.autoClose&&this.hide()}getTargetWorkspace(){return this.targetWorkspace}isVisible(){return this.visible}setVisible(e){var t=e!==this.isVisible();this.visible=e,t&&(this.autoClose||this.targetWorkspace.recordDragTargets(),this.updateDisplay())}setContainerVisible(e){var t=e!==this.containerVisible;this.containerVisible=e,t&&this.updateDisplay()}getContents(){return this.contents}setContents(e){this.contents=e}updateDisplay(){var e=this.containerVisible?this.isVisible():!1;this.svgGroup_&&(this.svgGroup_.style.display=e?`block`:`none`);var t;(t=this.workspace_.scrollbar)==null||t.setContainerVisible(e)}positionAt_(e,t,n,r){var i;(i=this.svgGroup_)==null||i.setAttribute(`width`,`${e}`);var a;(a=this.svgGroup_)==null||a.setAttribute(`height`,`${t}`),this.workspace_.setCachedParentSvgSize(e,t),this.svgGroup_&&de(this.svgGroup_,`translate(`+n+`px,`+r+`px)`),(e=this.workspace_.scrollbar)&&(e.setOrigin(n,r),e.resize(),e.hScroll&&e.hScroll.setPosition(e.hScroll.position.x,e.hScroll.position.y),e.vScroll&&e.vScroll.setPosition(e.vScroll.position.x,e.vScroll.position.y))}hide(){this.isVisible()&&(this.setVisible(!1),this.reflowWrapper&&=(this.workspace_.removeChangeListener(this.reflowWrapper),null))}show(t){e.t().getFocusedTree()===this.workspace_&&e.t().getFocusedNode()!==this.workspace_&&e.t().focusNode(this.workspace_),this.workspace_.setResizesEnabled(!1),e.Qc=!1,this.hide(),this.clearOldBlocks(),typeof t==`string`&&(t=this.getDynamicCategoryContents(t)),this.setVisible(!0),t=pt(t),t=this.createFlyoutInfo(t),jt(this.workspace_),this.setContents(t),this.layout_(t),this.horizontalLayout?this.height_=0:this.width_=0,this.reflow(),this.updateAriaContext(),e.Qc=!0,this.workspace_.setResizesEnabled(!0),this.reflowWrapper=e=>{this.inhibitReflowWrapper||e.type!==E.BLOCK_CHANGE&&e.type!==E.BLOCK_FIELD_INTERMEDIATE_CHANGE||this.reflow()},this.workspace_.addChangeListener(this.reflowWrapper)}updateAriaContext(){var t=this.getContents().map(e=>e.getElement()).filter(e=>e.canBeFocused()).map(e=>e.getFocusableElement().id);m(this.getWorkspace().getCanvas(),k.OWNS,t.join(` `)),this.targetWorkspace.isMutator||this.autoClose?p(this.getWorkspace().svgGroup_,O.NONE):p(this.getWorkspace().svgGroup_,O.REGION);var n=(t=(n=this.targetWorkspace.getToolbox())==null?void 0:n.getSelectedItem())&&Sn(t)?t.getName():``;n=e.C.WORKSPACE_LABEL_FLYOUT_WORKSPACE.replace(`%1`,n).trim(),m(this.getWorkspace().getCanvas(),k.LABEL,n),p(this.getWorkspace().getCanvas(),O.LISTBOX)}createFlyoutInfo(e){var t=[],n=this.horizontalLayout?this.GAP_X:this.GAP_Y;for(let r of e)`custom`in r&&(e=this.getDynamicCategoryContents(r.custom),e=pt(e),t.push(...this.createFlyoutInfo(e))),e=r.kind.toLowerCase(),(e=this.getInflaterForType(e))&&(t.push(e.load(r,this)),(e=e.gapForItem(r,n))&&t.push(new yf(new Sf(e,this.horizontalLayout?`x`:`y`),`sep`)));return this.normalizeSeparators(t)}normalizeSeparators(e){for(let t=e.length-1;t>0;t--){let n=e[t].getType().toLowerCase(),r=e[t-1].getType().toLowerCase();n===`sep`&&r===`sep`&&e.splice(t-1,1)}return e}getDynamicCategoryContents(e){if(e=this.workspace_.targetWorkspace.getToolboxCategoryCallback(e),typeof e!=`function`)throw TypeError(`Couldn't find a callback function when opening a toolbox category.`);return e(this.workspace_.targetWorkspace)}clearOldBlocks(){this.getContents().forEach(e=>{var t;(t=this.getInflaterForType(e.getType()))==null||t.disposeItem(e)});var e;(e=this.workspace_.getPotentialVariableMap())==null||e.clear()}onMouseDown(e){var t=this.targetWorkspace.getGesture(e);t&&t.handleFlyoutStart(e,this)}reflow(){this.inhibitReflowWrapper=!0,this.reflowInternal_(),this.inhibitReflowWrapper=!1}isScrollable(){return this.workspace_.scrollbar?this.workspace_.scrollbar.isVisible():!1}getInflaterForType(e){if(this.inflaters.has(e)){var t;return(t=this.inflaters.get(e))??null}return(t=Le(M.FLYOUT_INFLATER,e,void 0))?(t=new t,this.inflaters.set(e,t),t):null}},Uf=class{constructor(e){this.workspace=e,this.horizontalScrollEnabled=this.workspace.isMovableHorizontally(),this.verticalScrollEnabled=this.workspace.isMovableVertically(),this.startScrollXY_=new N(e.scrollX,e.scrollY)}startDrag(){}endDrag(e){this.drag(e)}drag(e){if(e=N.sum(this.startScrollXY_,e),this.horizontalScrollEnabled&&this.verticalScrollEnabled)this.workspace.scroll(e.x,e.y);else if(this.horizontalScrollEnabled)this.workspace.scroll(e.x,this.workspace.scrollY);else if(this.verticalScrollEnabled)this.workspace.scroll(this.workspace.scrollX,e.y);else throw TypeError(`Invalid state.`)}},Wf=class{constructor(e,t){this.creatorWorkspace=t,this.mouseDownXY=new N(0,0),this.startWorkspace_=this.targetBlock=this.startComment=this.startBlock=this.startIcon=this.startField=this.startBubble=null,this.hasExceededDragRadius=!1,this.boundEvents=[],this.workspaceDragger=this.dragger=null,this.dragging=!1,this.flyout=null,this.multiTouch=this.isEnding_=this.gestureHasStarted=this.calledUpdateIsDragging=!1,this.cachedPoints=new Map,this.startDistance=this.previousScale=0,this.currentDropdownOwner=this.isPinchZoomEnabled=null,this.mostRecentEvent=e,this.currentDragDeltaXY=new N(0,0)}dispose(){bo=null,Au=!1,this.creatorWorkspace.clearGesture();for(let e of this.boundEvents)c(e);this.boundEvents.length=0}updateFromEvent(e){var t=new N(e.clientX,e.clientY);this.updateDragDelta(t)&&(this.updateIsDragging(e),n()),this.mostRecentEvent=e}updateDragDelta(t){return this.currentDragDeltaXY=N.difference(t,this.mouseDownXY),this.hasExceededDragRadius?!1:this.hasExceededDragRadius=N.magnitude(this.currentDragDeltaXY)>(this.flyout?e.Og.flyoutDragRadius:e.Og.dragRadius)}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.dragging=!0,this.workspaceDragger=new Uf(this.startWorkspace_),this.workspaceDragger.startDrag())}updateIsDragging(e){if(!this.startWorkspace_)throw Error(`Cannot update dragging because the start workspace is undefined`);if(this.calledUpdateIsDragging)throw Error(`updateIsDragging_ should only be called once per gesture.`);this.calledUpdateIsDragging=!0;var t=De();t&&Vi(t)&&t.isMovable()?(this.dragging=!0,this.dragger=this.createDragger(t),this.dragger.onDragStart(e),this.dragger.onDrag(e,this.currentDragDeltaXY)):this.updateIsDraggingWorkspace()}createDragger(e){return new(Ve(M.BLOCK_DRAGGER,this.creatorWorkspace.options,!0))(e)}doStart(e){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,l(e)?this.cancel():(this.gestureHasStarted=!0,ki(),this.startWorkspace_.updateScreenCalculationsIfScrolled(),this.startWorkspace_.isMutator&&this.startWorkspace_.resize(),this.currentDropdownOwner=xu,this.startWorkspace_.hideChaff(!!this.flyout),this.startWorkspace_.markFocused(),this.mostRecentEvent=e,yr(),u(e)?this.handleRightClick(e):(e.type.toLowerCase()===`pointerdown`&&e.pointerType!==`mouse`&&t(e,this),this.mouseDownXY=new N(e.clientX,e.clientY),this.bindMouseEvents(e),this.isEnding_||this.handleTouchStart(e)))}bindMouseEvents(e){this.boundEvents.push(o(document,`pointerdown`,null,this.handleStart.bind(this),!0)),this.boundEvents.push(o(document,`pointermove`,null,this.handleMove.bind(this),!0)),this.boundEvents.push(o(document,`pointerup`,null,this.handleUp.bind(this),!0)),this.boundEvents.push(o(document,`pointercancel`,null,this.handleUp.bind(this),!0)),e.preventDefault(),e.stopPropagation()}handleStart(e){this.isDragging()||(this.handleTouchStart(e),this.isMultiTouch()&&n())}handleMove(e){this.isDragging()&&r(e)||!this.isMultiTouch()?(this.updateFromEvent(e),this.workspaceDragger?this.workspaceDragger.drag(this.currentDragDeltaXY):this.dragger&&this.dragger.onDrag(this.mostRecentEvent,this.currentDragDeltaXY),e.preventDefault(),e.stopPropagation()):this.isMultiTouch()&&(this.handleTouchMove(e),n())}handleUp(e){if(this.isDragging()||this.handleTouchEnd(e),!this.isMultiTouch()||this.isDragging()){if(!r(e))return;if(this.updateFromEvent(e),n(),this.isEnding_){console.log(`Trying to end a gesture recursively.`);return}this.isEnding_=!0,this.dragger?(z.setIsActive(!1),this.dragger.onDragEnd(e,this.currentDragDeltaXY)):this.workspaceDragger?(z.setIsActive(!1),this.workspaceDragger.endDrag(this.currentDragDeltaXY)):this.isBubbleClick()||this.isCommentClick()||(this.isFieldClick()?this.doFieldClick():this.isIconClick()?this.doIconClick():this.isBlockClick()?this.doBlockClick():this.isWorkspaceClick()&&this.doWorkspaceClick(e))}e.preventDefault(),e.stopPropagation(),this.dispose()}handleTouchStart(e){var t=i(e);this.cachedPoints.set(t,this.getTouchPoint(e));var n=Array.from(this.cachedPoints.keys());n.length===2&&(t=this.cachedPoints.get(n[0]),n=this.cachedPoints.get(n[1]),this.startDistance=N.distance(t,n),this.multiTouch=!0,e.preventDefault())}handleTouchMove(e){var t=i(e);this.cachedPoints.set(t,this.getTouchPoint(e)),this.isPinchZoomEnabled&&this.cachedPoints.size===2?this.handlePinch(e):(this.updateFromEvent(e),this.workspaceDragger?this.workspaceDragger.drag(this.currentDragDeltaXY):this.dragger&&this.dragger.onDrag(this.mostRecentEvent,this.currentDragDeltaXY),e.preventDefault(),e.stopPropagation())}handlePinch(e){var t=Array.from(this.cachedPoints.keys()),n=this.cachedPoints.get(t[0]);if(t=this.cachedPoints.get(t[1]),n=N.distance(n,t)/this.startDistance,this.previousScale>0&&this.previousScale<1/0){if(t=n-this.previousScale,t=t>0?t*5:t*6,!this.startWorkspace_)throw Error(`Cannot handle a pinch because the start workspace is undefined`);let r=this.startWorkspace_,i=d(e,r.getParentSvg(),r.getInverseScreenCTM());r.zoom(i.x,i.y,t)}this.previousScale=n,e.preventDefault()}handleTouchEnd(e){e=i(e),this.cachedPoints.has(e)&&this.cachedPoints.delete(e),this.cachedPoints.size<2&&(this.cachedPoints.clear(),this.previousScale=0)}getTouchPoint(e){return this.startWorkspace_?new N(e.pageX,e.pageY):null}isMultiTouch(){return this.multiTouch}cancel(){this.isEnding_||(n(),this.dragger?this.dragger.onDragEnd(this.mostRecentEvent,this.currentDragDeltaXY):this.workspaceDragger&&this.workspaceDragger.endDrag(this.currentDragDeltaXY),this.dispose())}handleRightClick(t){var n=e.t().getFocusedNode();if(n&&typeof n.showContextMenu==`function`){let e;(e=this.startWorkspace_)==null||e.hideChaff(!!this.flyout),n.showContextMenu(t)}t.preventDefault(),t.stopPropagation(),z.setIsActive(!1),this.dispose()}handleWsStart(t,n){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleWsStart, but the gesture had already been started.`);this.setStartWorkspace(n),this.mostRecentEvent=t,this.targetBlock||this.startBubble||this.startComment||this.startIcon||e.t().focusNode(n),this.doStart(t)}fireWorkspaceClick(e){b(new(x(E.CLICK))(null,e.id,`workspace`))}handleFlyoutStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleFlyoutStart, but the gesture had already been started.`);this.setStartFlyout(t),this.handleWsStart(e,t.getWorkspace())}handleBlockStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleBlockStart, but the gesture had already been started.`);this.setStartBlock(t),this.mostRecentEvent=e}handleBubbleStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleBubbleStart, but the gesture had already been started.`);this.setStartBubble(t),this.mostRecentEvent=e}handleCommentStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleCommentStart, but the gesture had already been started.`);this.setStartComment(t),this.mostRecentEvent=e}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)}doIconClick(){if(!this.startIcon)throw Error(`Cannot do an icon click because the start icon is undefined`);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`);var t=dn(this.targetBlock);let e=this.flyout.targetWorkspace;if(t&&e){var n=lt(this.flyout.getWorkspace(),this.targetBlock.getRelativeToSurfaceXY());n=ct(e,n),t.x=n.x,t.y=n.y,mn(t,e,{recordUndo:!0}),e.hideChaff(!1)}}else{if(!this.startWorkspace_)throw Error(`Cannot do a block click because the start workspace is undefined`);t=new(x(E.CLICK))(this.startBlock,this.startWorkspace_.id,`block`),b(t)}e.B(!1)}doWorkspaceClick(){this.fireWorkspaceClick(this.startWorkspace_||this.creatorWorkspace)}setStartField(e){if(this.gestureHasStarted)throw Error(`Tried to call gesture.setStartField, but the gesture had already been started.`);this.startField||=e}setStartIcon(e){if(this.gestureHasStarted)throw Error(`Tried to call gesture.setStartIcon, but the gesture had already been started.`);this.startIcon||=e}setStartBubble(e){this.startBubble||=e}setStartComment(e){this.startComment||=e}setStartBlock(e){var t,n,r;this.startBlock||this.startBubble||this.startIcon&&(!e.isInFlyout||(r=(n=this.startIcon).isClickableInFlyout)!=null&&r.call(n,!((t=e.workspace.getFlyout())==null||!t.autoClose)))||(this.startBlock=e,e.isInFlyout&&e!==e.getRootBlock()?this.setTargetBlock(e.getRootBlock()):this.setTargetBlock(e))}setTargetBlock(t){t.isShadow()?this.setTargetBlock(t.getParent()):(this.targetBlock=t,this.targetBlock.bringToFront(),e.t().focusNode(this.targetBlock))}setStartWorkspace(e){this.startWorkspace_||=e}setStartFlyout(e){this.flyout||=e}isBubbleClick(){return!!this.startBubble&&!this.hasExceededDragRadius}isCommentClick(){return!!this.startComment&&!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)):!1}isIconClick(){if(!this.startIcon)return!1;var e=!this.flyout||!this.startIcon.isClickableInFlyout||this.startIcon.isClickableInFlyout(this.flyout.autoClose);return!this.hasExceededDragRadius&&e}isWorkspaceClick(){return!this.startBlock&&!this.startBubble&&!this.startField&&!this.hasExceededDragRadius}getCurrentDragger(){return this.workspaceDragger??this.dragger??null}isDragging(){return this.dragging}hasStarted(){return this.gestureHasStarted}static inProgress(){var e=Se();for(let t=0,n;n=e[t];t++)if(n.currentGesture_)return!0;return!1}},Gf=class{constructor(e,t){this.pattern=e,this.scale=1,this.spacing=t.spacing??0,this.length=t.length??1,this.line2=(this.line1=e.firstChild)&&this.line1.nextSibling,this.snapToGrid=t.snap??!1}setSpacing(e){this.spacing=e,this.update(this.scale)}getSpacing(){return this.spacing}setLength(e){this.length=e,this.update(this.scale)}getLength(){return this.length}setSnapToGrid(e){this.snapToGrid=e}shouldSnap(){return this.snapToGrid}getPatternId(){return this.pattern.id}update(e){this.scale=e;var t=this.spacing*e;this.pattern.setAttribute(`width`,`${t}`),this.pattern.setAttribute(`height`,`${t}`),t=Math.floor(this.spacing/2)+.5;var n=t-this.length/2,r=t+this.length/2;t*=e,n*=e,r*=e,this.setLineAttributes(this.line1,e,n,r,t,t),this.setLineAttributes(this.line2,e,t,t,n,r)}setLineAttributes(e,t,n,r,i,a){e&&(e.setAttribute(`stroke-width`,`${t}`),e.setAttribute(`x1`,`${n}`),e.setAttribute(`y1`,`${i}`),e.setAttribute(`x2`,`${r}`),e.setAttribute(`y2`,`${a}`))}moveTo(e,t){this.pattern.setAttribute(`x`,`${e}`),this.pattern.setAttribute(`y`,`${t}`)}alignXY(e){var t=this.getSpacing(),n=t/2,r=Math.round(Math.round((e.x-n)/t)*t+n);return t=Math.round(Math.round((e.y-n)/t)*t+n),r===e.x&&t===e.y?e:new N(r,t)}static createDom(e,t,n,r){if(e=h(A.PATTERN,{id:`blocklyGridPattern`+e,patternUnits:`userSpaceOnUse`},n),(t.length??1)>0&&(t.spacing??0)>0){h(A.LINE,{stroke:t.colour},e);let n;(n=t.length)!=null&&n&&h(A.LINE,{stroke:t.colour},e)}else h(A.LINE,{},e);return r&&r.style.setProperty(`--blocklyGridPattern`,`url(#${e.id})`),e}},Kf=class{constructor(e){this.workspace=e,this.layers=new Map,(e=e.getInjectionDiv())&&(this.dragLayer=this.createDragLayer(e),this.animationLayer=this.createAnimationLayer(e)),e=this.createLayer(50),g(e,`blocklyBlockCanvas`),e=this.createLayer(100),g(e,`blocklyBubbleCanvas`)}createDragLayer(e){var t=h(A.SVG,{class:`blocklyBlockDragSurface`,xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`});return e.append(t),h(A.G,{},t)}createAnimationLayer(e){var t=h(A.SVG,{class:`blocklyAnimationLayer`,xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`});return e.append(t),h(A.G,{},t)}appendToAnimationLayer(e){var t,n=(t=this.dragLayer)==null?void 0:t.getAttribute(`transform`);if(n){let e;(e=this.animationLayer)==null||e.setAttribute(`transform`,n)}var r;(r=this.animationLayer)==null||r.appendChild(e.getSvgRoot())}translateLayers(e,t){e=`translate(${e.x}, ${e.y}) scale(${t})`;var n;(n=this.dragLayer)==null||n.setAttribute(`transform`,e);for(let[,t]of this.layers)t.setAttribute(`transform`,e)}moveToDragLayer(t,n=!0){var r;(r=this.dragLayer)==null||r.appendChild(t.getSvgRoot()),n&&t.canBeFocused()&&e.t().focusNode(t)}moveOffDragLayer(t,n,r=!0){this.append(t,n),r&&t.canBeFocused()&&e.t().focusNode(t)}append(e,t){this.layers.has(t)||this.createLayer(t),e=e.getSvgRoot();var n;if(((n=this.layers.get(t))==null?void 0:n.lastChild)!==e){let n;(n=this.layers.get(t))==null||n.appendChild(e)}}createLayer(e){var t=this.workspace.getSvgGroup(),n=h(A.G,{}),r=!1,i=[...this.layers].sort((e,t)=>e[0]-t[0]);for(let[a,o]of i)if(e<a){t.insertBefore(n,o),r=!0;break}return r||t.appendChild(n),this.layers.set(e,n),n}hasLayer(e){return e===this.dragLayer||new Set(this.layers.values()).has(e)}getBlockLayer(){return this.layers.get(50)}getBubbleLayer(){return this.layers.get(100)}getDragLayer(){return this.dragLayer}},qf={};qf.register=Ea,qf.unregister=function(e){Ie(M.ICON,e)};var Jf=class extends Od{constructor(e){super(e),this.sourceBlock=e,this.textInputBubble=null,this.text=``,this.bubbleSize=new F(160,80),this.bubbleVisiblity=!1}getType(){return Jf.TYPE}initView(e){this.svgRoot||(super.initView(e),h(A.CIRCLE,{class:`blocklyIconShape`,r:`8`,cx:`8`,cy:`8`},this.svgRoot),h(A.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),h(A.RECT,{class:`blocklyIconSymbol`,x:`6.8`,y:`10.78`,height:`2`,width:`2`},this.svgRoot),g(this.svgRoot,`blocklyCommentIcon`))}dispose(){super.dispose();var e;(e=this.textInputBubble)==null||e.dispose()}getWeight(){return Jf.WEIGHT}getSize(){return new F(17,17)}applyColour(){super.applyColour();var e=this.sourceBlock.getColour(),t;(t=this.textInputBubble)==null||t.setColour(e)}updateEditable(){var e=this,t=()=>super.updateEditable;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){t().call(e),e.bubbleIsVisible()&&(yield e.setBubbleVisible(!1),yield e.setBubbleVisible(!0))})}onLocationChange(e){var t=this.workspaceLocation;super.onLocationChange(e),this.bubbleLocation&&=(e=N.difference(this.workspaceLocation,t),N.sum(this.bubbleLocation,e)),e=this.getAnchorLocation();var n;(n=this.textInputBubble)==null||n.setAnchorLocation(e)}setText(e){var t=this.text;b(new(x(E.BLOCK_CHANGE))(this.sourceBlock,`comment`,null,t,e)),this.text=e;var n;(n=this.textInputBubble)==null||n.setText(this.text)}getText(){return this.text}setBubbleSize(e){this.bubbleSize=e;var t;(t=this.textInputBubble)==null||t.setSize(this.bubbleSize,!0)}getBubbleSize(){return this.bubbleSize}setBubbleLocation(e){this.bubbleLocation=e;var t;(t=this.textInputBubble)==null||t.moveDuringDrag(e)}getBubbleLocation(){return this.bubbleLocation}saveState(){if(this.text){let e={text:this.text,pinned:this.bubbleIsVisible(),height:this.bubbleSize.height,width:this.bubbleSize.width},t=this.getBubbleLocation();return t&&(e.x=this.sourceBlock.workspace.RTL?this.sourceBlock.workspace.getWidth()-(t.x+this.bubbleSize.width):t.x,e.y=t.y),e}return null}loadState(e){this.text=e.text??``,this.bubbleSize=new F(e.width??160,e.height??80),this.bubbleVisiblity=e.pinned??!1,this.setBubbleVisible(this.bubbleVisiblity);var t=e.x,n=e.y;At().then(()=>{t&&n&&(t=this.sourceBlock.workspace.RTL?this.sourceBlock.workspace.getWidth()-(t+this.bubbleSize.width):t,this.setBubbleLocation(new N(t,n)))})}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}onTextChange(){if(this.textInputBubble){var e=this.textInputBubble.getText();this.text!==e&&(b(new(x(E.BLOCK_CHANGE))(this.sourceBlock,`comment`,null,this.text,e)),this.text=e)}}onSizeChange(){this.textInputBubble&&(this.bubbleSize=this.textInputBubble.getSize())}onBubbleLocationChange(){this.textInputBubble&&(this.bubbleLocation=this.textInputBubble.getRelativeToSurfaceXY())}bubbleIsVisible(){return this.bubbleVisiblity}setBubbleVisible(e){var t=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){t.bubbleVisiblity!==e&&(t.bubbleVisiblity=e,yield At(),!t.sourceBlock.rendered||t.sourceBlock.isInFlyout||t.sourceBlock.isInsertionMarker()||(e?(t.sourceBlock.isEditable()?t.showEditableBubble():t.showNonEditableBubble(),t.applyColour()):t.hideBubble(),b(new(x(E.BUBBLE_OPEN))(t.sourceBlock,e,`comment`)),t.svgRoot&&t.recomputeAriaContext()))})}getBubble(){return this.textInputBubble}showEditableBubble(){this.createBubble();var e;(e=this.textInputBubble)==null||e.addTextChangeListener(()=>this.onTextChange());var t;(t=this.textInputBubble)==null||t.addSizeChangeListener(()=>this.onSizeChange())}showNonEditableBubble(){this.createBubble();var e;(e=this.textInputBubble)==null||e.setEditable(!1)}createBubble(){this.textInputBubble=new Pd(this.sourceBlock.workspace,this.getAnchorLocation(),this.getBubbleOwnerRect(),this),this.textInputBubble.getEditor().setParent(this.sourceBlock),this.textInputBubble.setText(this.getText()),this.textInputBubble.setSize(this.bubbleSize,!0),this.bubbleLocation&&this.textInputBubble.moveDuringDrag(this.bubbleLocation),this.textInputBubble.addTextChangeListener(()=>this.onTextChange()),this.textInputBubble.addSizeChangeListener(()=>this.onSizeChange()),this.textInputBubble.addLocationChangeListener(()=>this.onBubbleLocationChange()),this.textInputBubble.setAriaLabelProvider(()=>e.C.BUBBLE_LABEL_COMMENT.replace(`%1`,this.getText()))}hideBubble(){var e;(e=this.textInputBubble)==null||e.dispose(),this.textInputBubble=null}getAnchorLocation(){return N.sum(this.workspaceLocation,new N(8.5,8.5))}getBubbleOwnerRect(){return this.sourceBlock.getBoundingRectangleWithoutChildren()}getAriaLabel(){return this.bubbleIsVisible()?e.C.ICON_LABEL_COMMENT_OPEN:e.C.ICON_LABEL_COMMENT_CLOSED}};Jf.TYPE=Kc.COMMENT,Jf.WEIGHT=3,Ea(Jf.TYPE,Jf);var Yf={};Yf.CommentIcon=Jf,Yf.Icon=Od,Yf.IconType=Kc,Yf.MutatorIcon=e.sh,Yf.WarningIcon=hf,Yf.exceptions=Ld,Yf.registry=qf;var Xf,Zf;e.kj=class{constructor(e,t){this.db=new Map,this.dbReverse=new Set,this.variableMap=null,this.variablePrefix=t||``,this.reservedWords=new Set(e?e.split(`,`):[])}reset(){this.db.clear(),this.dbReverse.clear(),this.variableMap=null}setVariableMap(e){this.variableMap=e}getNameForUserVariable(e){return this.variableMap?(e=this.variableMap.getVariableById(e))?e.getName():null:(console.warn(`Deprecated call to Names.prototype.getName without defining a variable map. To fix, add the following code in your generator's init() function:
855
+ `)}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}bubbleIsVisible(){return!!this.textBubble}setBubbleVisible(t){var n=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){if(n.bubbleIsVisible()!==t){if(yield At(),t)n.textBubble=new mf(n.getText(),n.sourceBlock.workspace,n.getAnchorLocation(),n.getBubbleOwnerRect(),n),n.applyColour(),n.textBubble.setAriaLabelProvider(()=>e.C.BUBBLE_LABEL_WARNING.replace(`%1`,n.getText()));else{let e;(e=n.textBubble)==null||e.dispose(),n.textBubble=null}b(new(x(E.BUBBLE_OPEN))(n.sourceBlock,t,`warning`)),n.recomputeAriaContext()}})}getBubble(){return this.textBubble}getAnchorLocation(){return N.sum(this.workspaceLocation,new N(8.5,8.5))}getBubbleOwnerRect(){var e=this.sourceBlock.getSvgRoot().getBBox();return new P(e.y,e.y+e.height,e.x,e.x+e.width)}getAriaLabel(){return this.bubbleIsVisible()?e.C.ICON_LABEL_WARNING_OPEN:e.C.ICON_LABEL_WARNING_CLOSED}};hf.TYPE=Kc.WARNING,hf.WEIGHT=2;var gf=class extends qd{constructor(e,t,n){if(super(e,t,n),this.childlessWidth=this.width=this.height=0,this.warningTextDb=new Map,this.mutator=null,this.rendered=!0,this.visuallyDisabled=!1,this.previousConnection=this.nextConnection=this.outputConnection=null,this.translation=``,this.dragging=!1,this.relativeCoords=new N(0,0),this.dragStrategy=new ff(this),!e.rendered)throw TypeError(`Cannot create a rendered block in a headless workspace`);this.workspace=e,this.svgGroup=h(A.G,{}),t&&g(this.svgGroup,t),this.style=e.getRenderer().getConstants().getBlockStyle(null),this.pathObject=e.getRenderer().makePathObject(this.svgGroup,this.style),e=this.pathObject.svgPath,e.tooltip=this,dr(e),this.svgGroup.setAttribute(`data-id`,this.id),e.id=He(),this.doInit_()}initSvg(){if(!this.initialized){for(var e of this.inputList)e.init();for(let e of this.getIcons())e.initView(this.createIconPointerDownListener(e)),e.updateEditable();this.applyColour(),this.pathObject.updateMovable(this.isMovable()||this.isInFlyout),(e=this.getSvgRoot())&&o(e,`pointerdown`,this,this.onMouseDown),e.parentNode||this.workspace.getCanvas().appendChild(e),this.recomputeAriaContext(),this.initialized=!0}}getColourSecondary(){return this.style.colourSecondary}getColourTertiary(){return this.style.colourTertiary}select(){this.addSelect(),Oe(this)}unselect(){this.removeSelect(),Oe(null)}setParent(t){var n=this.parentBlock_;if(t!==n){fe(),super.setParent(t),pe();var r=this.getSvgRoot();if(!this.workspace.isClearing&&r){var i=this.getRelativeToSurfaceXY(),a=e.t().getFocusedNode(),o,s=this.getSvgRoot().contains((o=a==null?void 0:a.getFocusableElement())??null);t?(t.getSvgRoot().appendChild(r),s&&a&&e.t().focusNode(a)):n&&(t=this.workspace.getCanvas().querySelector(`.blocklyDragging`),n=t==null?void 0:t.parentElement,o=this.workspace.getCanvas(),n===o?o.insertBefore(r,t):(o.appendChild(r),s&&a&&e.t().focusNode(a)),this.translate(i.x,i.y)),this.applyColour(),this.recomputeAriaContext()}}}moveBy(e,t,n){if(this.parentBlock_)throw Error(`Block has parent`);var r=Je(),i=null;r&&(i=new(x(E.BLOCK_MOVE))(this),n&&i.setReason(n)),e=new N(e,t),t=this.getRelativeToSurfaceXY(),e=N.sum(t,e),this.translate(e.x,e.y),this.workspace.connectionDBList.forEach(e=>e==null?void 0:e.beginBulkUpdates()),this.updateComponentLocations(e),this.workspace.connectionDBList.forEach(e=>e==null?void 0:e.endBulkUpdates()),r&&i&&(i.recordNew(),b(i)),this.workspace.resizeContents()}translate(e,t){this.translation=`translate(${e}, ${t})`,this.relativeCoords=new N(e,t),this.getSvgRoot().setAttribute(`transform`,this.getTranslation())}getTranslation(){return this.translation}moveTo(e,t){var n=this.getRelativeToSurfaceXY();this.moveBy(e.x-n.x,e.y-n.y,t)}moveDuringDrag(e){this.translate(e.x,e.y),this.getSvgRoot().setAttribute(`transform`,this.getTranslation()),this.updateComponentLocations(e)}snapToGrid(){if(!this.isDeadOrDying()&&!this.getParent()&&!this.isInFlyout){var e=this.workspace.getGrid();if(e!=null&&e.shouldSnap()){var t=this.getRelativeToSurfaceXY();e=e.alignXY(t),e!==t&&this.moveTo(e,[`snap`])}}}getBoundingRectangle(){return this.getBoundingRectangleWithDimensions(this.getHeightWidth())}getBoundingRectangleWithoutChildren(){return this.getBoundingRectangleWithDimensions({height:this.height,width:this.childlessWidth})}getBoundingRectangleWithDimensions(e){var t=this.getRelativeToSurfaceXY();if(this.RTL)var n=t.x-e.width,r=t.x;else n=t.x,r=t.x+e.width;return new P(t.y,t.y+e.height,n,r)}markDirty(){this.pathObject.constants=this.workspace.getRenderer().getConstants();for(let e=0,t;t=this.inputList[e];e++)t.markDirty()}setCollapsed(e){this.collapsed_!==e&&(super.setCollapsed(e),this.updateCollapsed())}childHasWarning(){var e=this.getNextBlock();e=e?new Set(e.getDescendants(!1)):null;var t=this.getDescendants(!1);for(let n of t)if(n!==this&&(e==null||!e.has(n))&&n.getIcon(hf.TYPE))return!0;return!1}updateCollapsed(){var t=this.isCollapsed();for(let e=0,n;n=this.inputList[e];e++)n.name!==`_TEMP_COLLAPSED_INPUT`&&n.setVisible(!t);for(var n of this.getIcons())n.updateCollapsed();t?(g(this.svgGroup,`blocklyCollapsed`),this.childHasWarning()&&this.setWarningText(e.C.COLLAPSED_WARNINGS_WARNING,gf.COLLAPSED_WARNING_ID),t=this.toString(30),(n=this.getField(`_TEMP_COLLAPSED_FIELD`))?n.setValue(t):((this.getInput(`_TEMP_COLLAPSED_INPUT`)||this.appendDummyInput(`_TEMP_COLLAPSED_INPUT`)).appendField(new pf(t),`_TEMP_COLLAPSED_FIELD`),this.recomputeAriaContext())):(this.updateDisabled(),this.removeInput(`_TEMP_COLLAPSED_INPUT`),_(this.svgGroup,`blocklyCollapsed`),this.setWarningText(null,gf.COLLAPSED_WARNING_ID))}onMouseDown(e){if(!this.workspace.isReadOnly()){var t=this.workspace.getGesture(e);t&&t.handleBlockStart(e,this)}}showHelp(){var e=typeof this.helpUrl==`function`?this.helpUrl():this.helpUrl;e&&window.open(e)}generateContextMenu(e){return this.workspace.isReadOnly()||!this.contextMenu?null:(e=H.registry.getContextMenuOptions({block:this,focusedNode:this},e),this.customContextMenu&&this.customContextMenu(e),e)}calculateContextMenuLocation(e){if(e instanceof PointerEvent)return new N(e.clientX,e.clientY);e=lt(this.workspace,this.getRelativeToSurfaceXY());var t,n,r=(t=this.inputList.filter(e=>e.isVisible()).flatMap(e=>e.fieldRow).find(e=>e.isVisible()))==null||(n=t.getSvgRoot())==null?void 0:n.getBoundingClientRect();return new N(this.RTL?e.x-5:e.x+5,(r&&r.height?r.y+r.height:e.y+this.height)+5)}showContextMenu(t){if(this.isShadow()){for(var n=this.getParent();n&&n.isShadow();)n=n.getParent();n&&(e.t().focusNode(n),n.showContextMenu(t))}else{n=this.generateContextMenu(t);var r=this.calculateContextMenuLocation(t);n&&n.length&&(Br(t,n,this.RTL,this.workspace,r),$u=this)}}updateComponentLocations(e){this.xy.x=e.x,this.xy.y=e.y,this.dragging||this.updateConnectionLocations(e),this.updateIconLocations(e),this.updateFieldLocations(e);for(let t of this.getChildren(!1))t.updateComponentLocations(N.sum(e,t.relativeCoords))}updateConnectionLocations(e){for(let t of this.getConnections_(!1))t.moveToOffset(e)}updateIconLocations(e){for(let t of this.getIcons())t.onLocationChange(e)}updateFieldLocations(e){for(let t of this.inputList)for(let n of t.fieldRow)n.onLocationChange(e)}addClass(e){g(this.svgGroup,e)}removeClass(e){_(this.svgGroup,e)}setDragging(e){(this.dragging=e)?(this.translation=``,As.push(...this.getConnections_(!0)),this.addClass(`blocklyDragging`)):(As.length=0,this.removeClass(`blocklyDragging`),this.getFullBlockField()&&this.recomputeAriaContext());for(let t=0;t<this.childBlocks_.length;t++)this.childBlocks_[t].setDragging(e)}isDragging(){return this.dragging}setMovable(e){super.setMovable(e),this.pathObject.updateMovable(e)}setEditable(e){super.setEditable(e),e?_(this.svgGroup,`blocklyNotEditable`):g(this.svgGroup,`blocklyNotEditable`),e=this.getIcons();for(let t=0;t<e.length;t++)e[t].updateEditable()}setShadow(e){super.setShadow(e),this.applyColour(),this.recomputeAriaContext()}setInsertionMarker(e){this.isInsertionMarker_!==e&&(this.isInsertionMarker_=e)&&(this.setColour(this.workspace.getRenderer().getConstants().INSERTION_MARKER_COLOUR),this.pathObject.updateInsertionMarker(!0))}getSvgRoot(){return this.svgGroup}getNearestNeighbour(){if(!this.workspace.rendered)return null;var e=this.workspace.getAllBlocks(!1).filter(e=>!e.isDeadOrDying()),t=null,n=2**53-1,r=this.getRelativeToSurfaceXY();for(let i of e)e=i.getRelativeToSurfaceXY(),e=Math.sqrt((e.x-r.x)**2+(e.y-r.y)**2),e<n&&(t=i,n=e);return t}dispose(t,n){this.disposing=!0,fr(this.pathObject.svgPath),delete this.pathObject.svgPath.tooltip,gr(),Wr(),n&&(this.unplug(t),wi(this));var r=e.t(),i;if(n=((i=r.getFocusedNode())==null?void 0:i.getFocusableElement())??null,super.dispose(!!t),v(this.svgGroup),this.getSvgRoot().contains(n)){let e=this.getParent();if(!e&&(t=this.outputConnection??this.previousConnection)){let n;e=(n=t.closest(0,new N(0,0)).connection)==null?void 0:n.getSourceBlock()}setTimeout(()=>{if(this.workspace.rendered){if(e)r.focusNode(e);else{let e=this.getNearestNeighbour();e?r.focusNode(e):r.focusTree(this.workspace)}}},0)}}disposeInternal(){this.disposing=!0,super.disposeInternal(),e.t().getFocusedNode()===this&&this.workspace.cancelCurrentGesture(),[...this.warningTextDb.values()].forEach(e=>clearTimeout(e)),this.warningTextDb.clear(),this.getIcons().forEach(e=>e.dispose())}checkAndDelete(){this.workspace.isFlyout||(e.B(!0),this.workspace.hideChaff(),this.outputConnection?this.dispose(!1,!0):this.dispose(!0,!0),e.B(!1))}toCopyData(e=!1){return this.isInsertionMarker_?null:{paster:Zd.TYPE,blockState:dn(this,{addCoordinates:!0,addNextBlocks:e,saveIds:!1}),typeCounts:Me(this,!0)}}applyColour(){var e,t;for((t=(e=this.pathObject).applyColour)==null||t.call(e,this),e=this.getIcons(),t=0;t<e.length;t++)e[t].applyColour();for(let e of this.getFields())e.applyColour()}updateDisabled(){var e=!this.isEnabled()||this.getInheritedDisabled();if(this.visuallyDisabled===e){let e;(e=this.getNextBlock())==null||e.updateDisabled()}else{this.applyColour(),this.visuallyDisabled=e;for(let e of this.getChildren(!1))e.updateDisabled();this.recomputeAriaContext()}}setWarningText(t,n=``){if(n)this.warningTextDb.has(n)&&(clearTimeout(this.warningTextDb.get(n)),this.warningTextDb.delete(n));else{for(var r of this.warningTextDb.values())clearTimeout(r);this.warningTextDb.clear()}if(this.workspace.isDragging())this.warningTextDb.set(n,setTimeout(()=>{this.isDeadOrDying()||(this.warningTextDb.delete(n),this.setWarningText(t,n))},100));else if(this.isInFlyout&&(t=null),r=this.getIcon(hf.TYPE),t){let i=this.getSurroundParent(),a=null;for(;i;)i.isCollapsed()&&(a=i),i=i.getSurroundParent();a&&a.setWarningText(e.C.COLLAPSED_WARNINGS_WARNING,gf.COLLAPSED_WARNING_ID),r?r.addMessage(t,n):this.addIcon(new hf(this).addMessage(t,n))}else r&&(n?(r.addMessage(``,n),r.getText()||this.removeIcon(hf.TYPE)):this.removeIcon(hf.TYPE))}setMutator(t){this.removeIcon(e.sh.TYPE),t&&this.addIcon(t)}addIcon(t){return super.addIcon(t),t instanceof e.sh&&(this.mutator=t),t.initView(this.createIconPointerDownListener(t)),t.applyColour(),t.updateEditable(),this.queueRender(),t}createIconPointerDownListener(t){return n=>{!this.isDeadOrDying()&&(n=this.workspace.getGesture(n))&&(this.bringToFront(),n.setStartIcon(t),e.t().focusNode(t))}}removeIcon(t){var n=super.removeIcon(t);return t.equals(e.sh.TYPE)&&(this.mutator=null),this.queueRender(),n}setDisabledReason(e,t){var n=this.isEnabled();super.setDisabledReason(e,t),this.isEnabled()===n||this.getInheritedDisabled()||this.updateDisabled()}setDeletable(e){super.setDeletable(e),e?_(this.svgGroup,`blocklyNotDeletable`):g(this.svgGroup,`blocklyNotDeletable`)}setHighlighted(e){this.pathObject.updateHighlighted(e)}addSelect(){this.pathObject.updateSelected(!0)}removeSelect(){this.pathObject.updateSelected(!1)}setDeleteStyle(e){this.pathObject.updateDraggingDelete(e)}getColour(){return this.style.colourPrimary}setColour(e){super.setColour(e),e=this.workspace.getRenderer().getConstants().getBlockStyleForColour(this.colour_);var t,n;(n=(t=this.pathObject).setStyle)==null||n.call(t,e.style),this.style=e.style,this.styleName_=e.name,this.applyColour()}setStyle(e){var t=this.workspace.getRenderer().getConstants().getBlockStyle(e);if(this.styleName_&&_(this.svgGroup,this.styleName_),t){this.hat=t.hat;let n,r;(r=(n=this.pathObject).setStyle)==null||r.call(n,t),this.colour_=t.colourPrimary,this.style=t,this.applyColour(),g(this.svgGroup,e),this.styleName_=e}else throw Error(`Invalid style name: `+e)}getStyle(){return this.style}bringToFront(t=!1){var n=e.t().getFocusedNode();this.moveSvgRootToFront(t),n&&e.t().focusNode(n)}moveSvgRootToFront(e=!1){this.isDeadOrDying()||requestAnimationFrame(()=>{if(!this.dragging){var t=this;do{if(t.isDeadOrDying())break;let n=t.getSvgRoot(),r=n.parentNode;if(!r)break;let i=r.childNodes;if(i[i.length-1]!==n)for(;n.nextSibling;)r.insertBefore(n.nextSibling,n);if(e)break;t=t.getParent()}while(t)}})}setPreviousStatement(e,t){super.setPreviousStatement(e,t),this.queueRender()}setNextStatement(e,t){super.setNextStatement(e,t),this.queueRender()}setOutput(e,t){super.setOutput(e,t),this.queueRender()}setInputsInline(e){super.setInputsInline(e),this.queueRender()}removeInput(e,t){return e=super.removeInput(e,t),this.queueRender(),e}moveNumberedInputBefore(e,t){super.moveNumberedInputBefore(e,t),this.queueRender()}appendInput(e){return super.appendInput(e),this.queueRender(),e}setConnectionTracking(e){if(this.previousConnection&&this.previousConnection.setTracking(e),this.outputConnection&&this.outputConnection.setTracking(e),this.nextConnection){this.nextConnection.setTracking(e);var t=this.nextConnection.targetBlock();t&&t.setConnectionTracking(e)}if(!this.collapsed_)for(t=0;t<this.inputList.length;t++){var n=this.inputList[t].connection;n&&(n.setTracking(e),(n=n.targetBlock())&&n.setConnectionTracking(e))}}getConnections_(e){var t=[];if(this.outputConnection&&t.push(this.outputConnection),this.previousConnection&&t.push(this.previousConnection),this.nextConnection&&t.push(this.nextConnection),e||!this.collapsed_)for(let e=0,n;n=this.inputList[e];e++)n.connection&&t.push(n.connection);return t}lastConnectionInStack(e){return super.lastConnectionInStack(e)}getMatchingConnection(e,t){return super.getMatchingConnection(e,t)}makeConnection_(e){return new Bd(this,e)}getNextBlock(){return super.getNextBlock()}getPreviousBlock(){return super.getPreviousBlock()}bumpNeighbours(){var t=this.getRootBlock();if(!(this.isDeadOrDying()||this.workspace.isDragging()||this.isDragging()||t.isInFlyout))for(let n of this.getConnections_(!1)){if(n.isSuperior()){let e;(e=n.targetBlock())==null||e.bumpNeighbours()}for(let r of n.neighbours(e.Og.snapRadius))r.getSourceBlock().getRootBlock()!==t&&(n.isConnected()&&r.isConnected()||(n.isSuperior()?r.bumpAwayFrom(n,!1):r.getSourceBlock().isDragging()||n.bumpAwayFrom(r,!0)))}}scheduleSnapAndBump(){this.snapToGrid(),this.bumpNeighbours()}positionNearConnection(e,t,n){if(e.type===L.NEXT_STATEMENT||e.type===L.INPUT_VALUE){let r=t.x;t=t.y,r+=n.x-e.getOffsetInBlock().x,t+=n.y-e.getOffsetInBlock().y,this.moveBy(r,t)}}getChildren(e){return super.getChildren(e)}queueRender(){return kt(this)}render(){this.queueRender(),jt()}renderEfficiently(){fe(),this.isCollapsed()&&this.updateCollapsed(),this.isEnabled()||this.updateDisabled(),this.workspace.getRenderer().render(this),this.tightenChildrenEfficiently(),pe()}tightenChildrenEfficiently(){for(let e of this.inputList){let t=e.connection;t&&t.tightenEfficiently()}this.nextConnection&&this.nextConnection.tightenEfficiently()}getHeightWidth(){var e=this.height,t=this.width,n=this.getNextBlock();if(n){n=n.getHeightWidth();let r=this.workspace.getRenderer().getConstants().NOTCH_HEIGHT;e+=n.height-r,t=Math.max(t,n.width)}return{height:e,width:t}}fadeForReplacement(e){var t,n;(n=(t=this.pathObject).updateReplacing)==null||n.call(t,e)}getDragStrategy(){return this.dragStrategy}setDragStrategy(e){this.dragStrategy=e}isCopyable(){return this.isOwnDeletable()&&this.isOwnMovable()}isMovable(){return this.dragStrategy.isMovable()}startDrag(e){return this.dragStrategy.startDrag(e)}drag(e,t){this.dragStrategy.drag(e,t)}endDrag(e,t){this.dragStrategy.endDrag(e,t)}revertDrag(){this.dragStrategy.revertDrag()}toFlyoutInfo(){function e(t){for(let r in t)n.has(r)?delete t[r]:typeof t[r]==`object`&&e(t[r])}var t=Object.assign({},{kind:`BLOCK`},dn(this)),n=new Set([`id`,`height`,`width`,`pinned`,`enabled`]);return e(t),[t]}jsonInit(e){super.jsonInit(e),e.classes&&this.addClass(Array.isArray(e.classes)?e.classes.join(` `):e.classes)}getNestingLevel(){var e=this.getSurroundParent();return e?e.getNestingLevel()+1:0}getFocusableElement(){var e=this.getFullBlockField();return e?e.getFocusableElement():this.pathObject.svgPath}getFocusableTree(){return this.workspace}onNodeFocus(){this.recomputeAriaContext(),this.select(),this.workspace.isFlyout||this.moveSvgRootToFront();var t=e.t().getFocusedNode();t&&t!==this&&At().then(()=>{this.workspace.scrollBoundsIntoView(this.getBoundingRectangleWithoutChildren())})}onNodeBlur(){this.unselect()}canBeFocused(){return!0}performAction(t){if(this.workspace.isFlyout)G.mover.startMove(this,t);else{if(this.isSimpleReporter()){for(var n of this.inputList)for(let e of n.fieldRow)if(e.isClickable()&&e.isFullBlockField()){e.showEditor();return}}this.workspace.getNavigator().getInNode(this)?(t=this.workspace,n=vn(t.RTL?J.NAVIGATE_LEFT:J.NAVIGATE_RIGHT),n=e.C.KEYBOARD_NAV_BLOCK_NAVIGATION_HINT.replace(`%1`,n),Pc.show(t,{message:n,id:`blockNavigationHint`})):(t=this.workspace,(n=vn(`list_shortcuts`))&&(n=e.C.HELP_PROMPT.replace(`%1`,n),Pc.show(t,{message:n,id:`helpHint`})))}}getParents(){for(var e=new Set,t=this.getParent();t;)e.add(t),t=t.getParent();return e}getOutputParents(){var e=new Set;e.add(this);for(var t,n=(t=this.outputConnection)==null?void 0:t.targetBlock();n;){e.add(n);let t;n=(t=n.outputConnection)==null?void 0:t.targetBlock()}return e}getRowId(){var e,t,n=(e=this.outputConnection)==null||(t=e.targetConnection)==null?void 0:t.getParentInput();return n?n.getRowId():this.id}recomputeAriaContext(){var e=this.getFullBlockField();e?e.recomputeAriaContext():(m(this.getFocusableElement(),k.LABEL,this.getAriaLabel(ss.STANDARD)),p(this.getSvgRoot(),O.NONE),e=this.getFocusableElement(),this.isInFlyout||p(e,O.FIGURE),m(e,k.ROLEDESCRIPTION,this.getAriaRoleDescription()))}getAriaLabel(e){return Cn(this,e)}getStackBlocksCountLabel(){for(var t=1,n=this.getNextBlock();n;)t++,n=n.getNextBlock();return t<=1?Cn(this,ss.TERSE):e.C.BLOCK_LABEL_STACK_BLOCKS.replace(`%1`,t.toString())}};gf.INLINE=-1,gf.COLLAPSED_WARNING_ID=`TEMP_COLLAPSED_WARNING_`;var _f=class{constructor(){}onDragEnter(){}onDragOver(){}onDragExit(){}onDrop(){}getClientRect(){return null}shouldPreventMove(){return!1}},vf=class extends _f{constructor(){super(),this.wouldDelete_=!1}wouldDelete(e){return G.mover.isMoving()?this.updateWouldDelete_(!1):e instanceof gf?(e=!e.getParent()&&e.isDeletable(),this.updateWouldDelete_(e)):this.updateWouldDelete_(Bi(e)&&e.isDeletable()),this.wouldDelete_}updateWouldDelete_(e){this.wouldDelete_=e}},yf=class{constructor(e,t){this.element=e,this.type=t}getElement(){return this.element}getType(){return this.type}},bf=class{constructor(e){this.workspace_=e}getDimensionsPx_(e){var t=0,n=0;return e&&(t=e.getWidth(),n=e.getHeight()),new F(t,n)}getFlyoutMetrics(e){return e=this.getDimensionsPx_(this.workspace_.getFlyout(e)),{width:e.width,height:e.height,position:this.workspace_.toolboxPosition}}getToolboxMetrics(){var e=this.getDimensionsPx_(this.workspace_.getToolbox());return{width:e.width,height:e.height,position:this.workspace_.toolboxPosition}}getSvgMetrics(){return this.workspace_.getCachedParentSvgSize()}getAbsoluteMetrics(){var e=0,t=0,n=this.getToolboxMetrics(),r=this.getFlyoutMetrics(),i=!!this.workspace_.getToolbox(),a,o=!((a=this.workspace_.getFlyout())!=null&&a.autoClose);a=i?n.position:r.position;var s=a===I.TOP;return a===I.LEFT&&(i&&(e+=n.width),o&&(e+=r.width)),s&&(i&&(t+=n.height),o&&(t+=r.height)),{top:t,left:e}}getViewMetrics(e){e=e?this.workspace_.scale:1;var t=this.getSvgMetrics(),n=this.getToolboxMetrics(),r=this.getFlyoutMetrics(),i=!!this.workspace_.getToolbox(),a,o=!((a=this.workspace_.getFlyout())!=null&&a.autoClose);a=i?n.position:r.position;var s=a===I.LEFT||a===I.RIGHT;return(a===I.TOP||a===I.BOTTOM)&&(i&&(t.height-=n.height),o&&(t.height-=r.height)),s&&(i&&(t.width-=n.width),o&&(t.width-=r.width)),{height:t.height/e,width:t.width/e,top:-this.workspace_.scrollY/e,left:-this.workspace_.scrollX/e}}getContentMetrics(e){e=e?1:this.workspace_.scale;var t=this.workspace_.getBlocksBoundingBox();return{height:(t.bottom-t.top)*e,width:(t.right-t.left)*e,top:t.top*e,left:t.left*e}}hasFixedEdges(){return!this.workspace_.isMovableHorizontally()||!this.workspace_.isMovableVertically()}getComputedFixedEdges_(e){if(!this.hasFixedEdges())return{};var t=this.workspace_.isMovableHorizontally(),n=this.workspace_.isMovableVertically();e||=this.getViewMetrics(!1);var r={};return n||(r.top=e.top,r.bottom=e.top+e.height),t||(r.left=e.left,r.right=e.left+e.width),r}getPaddedContent_(e,t){var n=t.top+t.height,r=t.left+t.width,i=e.width;e=e.height;var a=i/2,o=e/2;return{top:Math.min(t.top-o,n-e),bottom:Math.max(n+o,t.top+e),left:Math.min(t.left-a,r-i),right:Math.max(r+a,t.left+i)}}getScrollMetrics(e,t,n){e=e?this.workspace_.scale:1,t||=this.getViewMetrics(!1);var r=n||this.getContentMetrics();n=this.getComputedFixedEdges_(t),t=this.getPaddedContent_(t,r),r=n.top===void 0?t.top:n.top;var i=n.left===void 0?t.left:n.left;return{top:r/e,left:i/e,width:((n.right===void 0?t.right:n.right)-i)/e,height:((n.bottom===void 0?t.bottom:n.bottom)-r)/e}}getUiMetrics(){return{viewMetrics:this.getViewMetrics(),absoluteMetrics:this.getAbsoluteMetrics(),toolboxMetrics:this.getToolboxMetrics()}}getMetrics(){var e=this.getToolboxMetrics(),t=this.getFlyoutMetrics(!0),n=this.getSvgMetrics(),r=this.getAbsoluteMetrics(),i=this.getViewMetrics(),a=this.getContentMetrics(),o=this.getScrollMetrics(!1,i,a);return{contentHeight:a.height,contentWidth:a.width,contentTop:a.top,contentLeft:a.left,scrollHeight:o.height,scrollWidth:o.width,scrollTop:o.top,scrollLeft:o.left,viewHeight:i.height,viewWidth:i.width,viewTop:i.top,viewLeft:i.left,absoluteTop:r.top,absoluteLeft:r.left,svgHeight:n.height,svgWidth:n.width,toolboxWidth:e.width,toolboxHeight:e.height,toolboxPosition:e.position,flyoutWidth:t.width,flyoutHeight:t.height}}};y(M.METRICS_MANAGER,`default`,bf);var xf=class extends bf{constructor(e,t){super(e),this.flyout_=t}getBoundingBox(){try{var e=this.workspace_.getCanvas().getBBox()}catch{e={height:0,y:0,width:0,x:0}}return e}getContentMetrics(e){var t=this.getBoundingBox();return e=e?1:this.workspace_.scale,{height:t.height*e,width:t.width*e,top:t.y*e,left:t.x*e}}getScrollMetrics(e,t,n){return t=n||this.getContentMetrics(),n=this.flyout_.MARGIN*this.workspace_.scale,e=e?this.workspace_.scale:1,{height:(t.height+2*n)/e,width:(t.width+t.left+n)/e,top:0,left:0}}},Sf=class{constructor(e,t){this.gap=e,this.axis=t,this.y=this.x=0}getBoundingRectangle(){switch(this.axis){case`x`:return new P(this.y,this.y,this.x,this.x+this.gap);case`y`:return new P(this.y,this.y+this.gap,this.x,this.x)}}moveBy(e,t){this.x+=e,this.y+=t}isNavigable(){return!1}getFocusableElement(){throw Error(`Cannot be focused`)}getFocusableTree(){throw Error(`Cannot be focused`)}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!1}},Cf=class{getFirstChild(){return null}getParent(e){return e.getWorkspace()}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.getId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof af}},wf=class{getFirstChild(){return null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(){return`error`}isNavigable(){return!1}isApplicable(e){return e instanceof Sf}},Tf=class{getFirstChild(e){return Sa(e)[0]}getParent(e){var t;if((t=e.previousConnection)!=null&&t.targetBlock()){if(t=e.getSurroundParent())return t}else{let t;if((t=e.outputConnection)!=null&&t.targetBlock())return e.outputConnection.targetBlock()}return e.workspace}getNextSibling(e){if(e.nextConnection)return e.nextConnection.targetBlock()??e.nextConnection;var t;return(t=e.outputConnection)!=null&&t.targetConnection?(t=this.getParent(e),Ca(t,e,1)):null}getPreviousSibling(e){var t;if((t=e.previousConnection)!=null&&t.targetBlock())return e.previousConnection;var n;return(n=e.outputConnection)!=null&&n.targetBlock()?Ca(e.outputConnection.targetBlock(),e,-1):null}getRowId(e){return e.getRowId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof gf}},Ef=class{getFirstChild(){return null}getParent(e){return e.getOwner()??null}getNextSibling(e){var t;return Ca((t=e.getOwner())==null?void 0:t.getSourceBlock(),e,1)}getPreviousSibling(e){var t;return Ca((t=e.getOwner())==null?void 0:t.getSourceBlock(),e,-1)}getRowId(e){var t,n;return((t=e.getOwner())==null||(n=t.getSourceBlock())==null?void 0:n.getRowId())??``}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof K}},Df=class{getFirstChild(){return null}getParent(e){return e.getCommentView().workspace.getCommentById(e.getCommentView().commentId)}getNextSibling(e){var t=e.getCommentView().getCommentBarButtons();return e=t.indexOf(e),e>=0&&e+1<t.length?t[e+1]:null}getPreviousSibling(e){var t=e.getCommentView().getCommentBarButtons();return e=t.indexOf(e),e>0?t[e-1]:null}getRowId(e){return e.getCommentView().commentId}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof cd}},Of=class{getFirstChild(){return null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof ud}},kf=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){if(e.getParentInput())return Ca(e.getSourceBlock(),e,1);if(e.type===L.NEXT_STATEMENT&&e.getSourceBlock().getSurroundParent()&&!e.targetConnection)return Ca(e.getSourceBlock().getSurroundParent(),e,1);switch(e.type){case L.NEXT_STATEMENT:return e.targetConnection;case L.PREVIOUS_STATEMENT:case L.OUTPUT_VALUE:return e.getSourceBlock()}return null}getPreviousSibling(e){if(e.getParentInput())return Ca(e.getParentInput().getSourceBlock(),e,-1);switch(e.type){case L.NEXT_STATEMENT:return e.getSourceBlock();case L.PREVIOUS_STATEMENT:case L.OUTPUT_VALUE:return e.targetConnection}return null}getRowId(e){switch(e.type){case L.NEXT_STATEMENT:case L.PREVIOUS_STATEMENT:return e.id;case L.INPUT_VALUE:return e.getParentInput().getRowId();default:return e.getSourceBlock().getRowId()}}isNavigable(e){return e.canBeFocused()?e.type===L.NEXT_STATEMENT?!e.targetBlock()&&e!==(e.getSourceBlock().getRootBlock()??e.getSourceBlock()).lastConnectionInStack(!1):e.type===L.INPUT_VALUE&&!e.targetBlock():!1}isApplicable(e){return e instanceof Bd}},Af=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){return Ca(e.getSourceBlock(),e,1)}getPreviousSibling(e){return Ca(e.getSourceBlock(),e,-1)}getRowId(e){return e.getParentInput().getRowId()}isNavigable(e){var t;return e.canBeFocused()&&e.isVisible()&&(e.isClickable()||e.isCurrentlyEditable())&&!((t=e.getSourceBlock())!=null&&t.isSimpleReporter()&&e.isFullBlockField())&&e.getParentInput().isVisible()}isApplicable(e){return e instanceof V}},jf=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){return Ca(e.getSourceBlock(),e,1)}getPreviousSibling(e){return Ca(e.getSourceBlock(),e,-1)}getRowId(e){return e.getSourceBlock().getRowId()}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof Od}},Mf=class{getFirstChild(e){return e.view.getCommentBarButtons()[0]}getParent(e){return e.workspace}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof md}},Nf=class{getFirstChild(e){return e=e.getTopBlocks(!0),e.length?e[0]:null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(e){return e.id}isNavigable(e){return e.canBeFocused()&&!e.isMutator}isApplicable(e){return e instanceof Mp}},Pf,Ff=Pf||={};Ff[Ff.NEXT=0]=`NEXT`,Ff[Ff.PREVIOUS=1]=`PREVIOUS`,Ff[Ff.IN=2]=`IN`,Ff[Ff.OUT=3]=`OUT`;var If=class{constructor(){this.rules=[new Tf,new Af,new kf,new Nf,new jf,new Mf,new Df,new Ef,new Of],this.navigationLoops=!0}addNavigationPolicy(e){this.rules.push(e)}get(e){return this.rules.find(t=>t.isApplicable(e))}getFirstChild(e){var t,n=(t=this.get(e))==null?void 0:t.getFirstChild(e);return n?this.isNavigable(n)?n:this.getFirstChild(n)||this.getNextSibling(n):null}getParent(e){var t,n=(t=this.get(e))==null?void 0:t.getParent(e);return n?this.isNavigable(n)?n:this.getParent(n):null}getNextSibling(e){var t,n=(t=this.get(e))==null?void 0:t.getNextSibling(e);return n?this.isNavigable(n)?n:this.getNextSibling(n):null}getPreviousSibling(e){var t,n=(t=this.get(e))==null?void 0:t.getPreviousSibling(e);return n?this.isNavigable(n)?n:this.getPreviousSibling(n):null}getPreviousNode(t=e.t().getFocusedNode()){if(!t)return null;var n=this.getPreviousNodeImpl(t,t,Pf.PREVIOUS);if(!n||n===t.getFocusableTree()){if(n=this.navigateStacks(t,-1),!n)return null;n=this.getLastNodeInStack(n,t)}return this.getLeftmostSibling(n)}getOutNode(t=e.t().getFocusedNode()){return this.getPreviousNodeImpl(t,t,Pf.OUT)}getNextNode(t=e.t().getFocusedNode()){var n=this.getNextNodeImpl(t,t,Pf.NEXT);return t&&n===null?this.navigateStacks(t,1):n}getInNode(t=e.t().getFocusedNode()){return this.getNextNodeImpl(t,t,Pf.IN)}getPreviousNodeImpl(e,t,n,r=new Set){if(!t||!e||r.has(t))return null;var i=this.getRightMostChild(this.getPreviousSibling(t),t)||this.getParent(t);return i&&this.transitionAllowed(e,i,n)?i:i?(r.add(t),this.getPreviousNodeImpl(e,i,n,r)):null}getNextNodeImpl(e,t,n,r=new Set){if(!t||!e||r.has(t))return null;for(var i=this.getFirstChild(t)||this.getNextSibling(t),a=t;a&&!i&&(a=this.getParent(a),a);)i=this.getNextSibling(a);return i&&this.transitionAllowed(e,i,n)?i:i?(r.add(t),this.getNextNodeImpl(e,i,n,r)):null}getRightMostChild(e,t){if(!e)return e;var n=this.getFirstChild(e);if(!n||n===t)return e;for(e=n;e&&e!==t;e=this.getNextSibling(n))n=e;return this.getRightMostChild(n,t)}setNavigationLoops(e){this.navigationLoops=e}getNavigationLoops(){return this.navigationLoops}getFirstNode(){var t,n=(t=e.t().getFocusedTree())==null?void 0:t.getRootFocusableNode();return n?this.getTopLevelItems(n)[0]:null}getLastNode(){var t,n=(t=e.t().getFocusedTree())==null?void 0:t.getRootFocusableNode();return n?this.getTopLevelItems(n).slice(-1)[0]:null}transitionAllowed(e,t,n){switch(n){case Pf.IN:case Pf.OUT:return this.getRowId(e)===this.getRowId(t);case Pf.NEXT:case Pf.PREVIOUS:return this.getRowId(e)!==this.getRowId(t)}}getLeftmostSibling(e){if(!e)return null;for(var t;t=this.getPreviousNodeImpl(e,e,Pf.OUT);)e=t;return e}getLastNodeInStack(e,t){for(var n;(n=this.getNextNodeImpl(e,e,Pf.NEXT))&&n!==t;)e=n;return e}getRowId(e){var t;return(t=this.get(e))==null?void 0:t.getRowId(e)}navigateStacks(e,t){var n=this.getTopLevelItems(e),r,i=((r=this.getSourceBlockFromNode(e))==null?void 0:r.getRootBlock())??e;return e=n.indexOf(i)+t,t=null,e>=0&&e<n.length?t=n[e]:e<0&&this.getNavigationLoops()?t=n[n.length-1]:e>=n.length&&this.getNavigationLoops()&&(t=n[0]),t}getTopLevelItems(e){return e.getFocusableTree().getTopBoundedElements(!0)}isNavigable(e){var t;return(t=this.get(e))==null?void 0:t.isNavigable(e)}getSourceBlockFromNode(e){return e instanceof gf?e:e instanceof V||e instanceof Bd||e instanceof Od?e.getSourceBlock():e instanceof ud?(e=e.getParent(),e instanceof gf?e:null):null}},Lf=class{getFirstChild(e){return wa(e)?e.getChildToolboxItems()[0]:null}getParent(e){return e.getParent()}getNextSibling(e){var t=e.getParentToolbox().getToolboxItems();return e=t.indexOf(e),t[e+1]??null}getPreviousSibling(e){var t=e.getParentToolbox().getToolboxItems();return e=t.indexOf(e),t[e-1]??null}getRowId(e){return e.getId()}isNavigable(e){return e.canBeFocused()&&this.allParentsExpanded(e)}allParentsExpanded(e){return(e=e.getParent())&&wa(e)?e.isExpanded()&&this.allParentsExpanded(e):!0}isApplicable(e){return xn(e)}},Rf=class extends If{constructor(e){super(),this.toolbox=e,this.rules=[new Lf]}getInNode(t=e.t().getFocusedNode(),n=!1){var r=Ta(this.toolbox.getWorkspace());if(!n)switch(r){case I.TOP:case I.BOTTOM:return this.getNextNode(t,!0);case I.RIGHT:return this.getOutNode(t,!0)}if(!Sn(t)||Sn(t)&&!t.getContents().length)return null;var i;return(t=(i=this.toolbox.getFlyout())==null?void 0:i.getWorkspace().getNavigator())?!this.toolbox.getWorkspace().RTL||r!==I.TOP&&r!==I.BOTTOM?t.getFirstNode():t.getLastNode():null}getOutNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:case I.BOTTOM:return this.getPreviousNode(e,!0);case I.RIGHT:return this.getInNode(e,!0)}return super.getOutNode(e)}getNextNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:return this.getInNode(e,!0);case I.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t)switch(Ta(this.toolbox.getWorkspace())){case I.TOP:return this.getOutNode(e,!0);case I.BOTTOM:return this.getInNode(e,!0)}return super.getPreviousNode(e)}getTopLevelItems(){return this.toolbox.getToolboxItems()}},zf=class extends If{constructor(e){super(),this.flyout=e,this.rules.push(new Cf,new wf)}getOutNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:case I.BOTTOM:return this.flyout.RTL?this.getNextNode(e,!0):this.getPreviousNode(e,!0);case I.RIGHT:return null}var n;return(e=(n=this.flyout.targetWorkspace)==null?void 0:n.getToolbox())?e.getSelectedItem():null}getInNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:case I.BOTTOM:return this.flyout.RTL?this.getPreviousNode(e,!0):this.getNextNode(e,!0);case I.RIGHT:return this.getOutNode(e,!0)}return super.getInNode(e)}getNextNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:return null;case I.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(Ta(this.flyout.targetWorkspace)){case I.TOP:return this.getOutNode(e,!0);case I.BOTTOM:return null}return super.getPreviousNode(e)}getTopLevelItems(){return this.flyout.getContents().map(e=>e.getElement()).filter(e=>this.isNavigable(e))}isNavigable(e){return super.isNavigable(e)&&this.flyout.getContents().map(e=>e.getElement()).includes(e)}},Bf=class{constructor(e,t,n,r,i){this.workspace=e,this.oldHostMetrics=this.corner_=this.vScroll=this.hScroll=null,t=t===void 0||t,n=n===void 0||n;var a=t&&n;t&&(this.hScroll=new Js(e,!0,a,r,i)),n&&(this.vScroll=new Js(e,!1,a,r,i)),a&&(this.corner_=h(A.RECT,{height:Js.scrollbarThickness,width:Js.scrollbarThickness,class:`blocklyScrollbarBackground`}),ue(this.corner_,e.getBubbleCanvas()))}dispose(){v(this.corner_),this.oldHostMetrics=this.corner_=null,this.hScroll&&=(this.hScroll.dispose(),null),this.vScroll&&=(this.vScroll.dispose(),null)}resize(){var t=this.workspace.getMetrics();if(t){var n=!1,r=!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||(n=!0),this.oldHostMetrics&&this.oldHostMetrics.scrollHeight===t.scrollHeight&&this.oldHostMetrics.viewTop===t.viewTop&&this.oldHostMetrics.scrollTop===t.scrollTop||(r=!0)):r=n=!0,n||r){try{e.Ub++,this.hScroll&&n&&this.hScroll.resize(t),this.vScroll&&r&&this.vScroll.resize(t)}finally{e.Ub--}this.workspace.maybeFireViewportChangeEvent()}if(this.hScroll&&this.vScroll){if(!this.oldHostMetrics||this.oldHostMetrics.viewWidth!==t.viewWidth||this.oldHostMetrics.absoluteLeft!==t.absoluteLeft){let e;(e=this.corner_)==null||e.setAttribute(`x`,String(this.vScroll.position.x))}if(!this.oldHostMetrics||this.oldHostMetrics.viewHeight!==t.viewHeight||this.oldHostMetrics.absoluteTop!==t.absoluteTop){let e;(e=this.corner_)==null||e.setAttribute(`y`,String(this.hScroll.position.y))}}this.oldHostMetrics=t}}canScrollHorizontally(){return!!this.hScroll}canScrollVertically(){return!!this.vScroll}setOrigin(e,t){this.hScroll&&this.hScroll.setOrigin(e,t),this.vScroll&&this.vScroll.setOrigin(e,t)}set(e,t,n){this.hScroll&&this.hScroll.set(e,!1),this.vScroll&&this.vScroll.set(t,!1),(n||n===void 0)&&(e={},this.hScroll&&(e.x=this.hScroll.getRatio_()),this.vScroll&&(e.y=this.vScroll.getRatio_()),this.workspace.setMetrics(e))}setX(e){this.hScroll&&this.hScroll.set(e,!0)}setY(e){this.vScroll&&this.vScroll.set(e,!0)}setContainerVisible(e){this.hScroll&&this.hScroll.setContainerVisible(e),this.vScroll&&this.vScroll.setContainerVisible(e)}isVisible(){var e=!1;return this.hScroll&&(e=this.hScroll.isVisible()),this.vScroll&&(e||=this.vScroll.isVisible()),e}setVisible(e){this.hScroll&&this.hScroll.setVisibleInternal(e),this.vScroll&&this.vScroll.setVisibleInternal(e)}resizeContent(e){this.hScroll&&this.hScroll.resizeContentHorizontal(e),this.vScroll&&this.vScroll.resizeContentVertical(e)}resizeView(e){this.hScroll&&this.hScroll.resizeViewHorizontal(e),this.vScroll&&this.vScroll.resizeViewVertical(e)}},Vf=class{load(e,t){return e=new Sf(0,t.horizontalLayout?`x`:`y`),new yf(e,`sep`)}gapForItem(e,t){return parseInt(String(e.gap))??t}disposeItem(){}getType(){return`sep`}};y(M.FLYOUT_INFLATER,`sep`,Vf);var Hf=class extends vf{constructor(e){super(),this.horizontalLayout=!1,this.boundEvents=[],this.reflowWrapper=null,this.inhibitReflowWrapper=!1,this.contents=[],this.autoClose=!0,this.visible=!1,this.containerVisible=!0,this.CORNER_RADIUS=8,this.SCROLLBAR_MARGIN=2.5,this.height_=this.width_=0,this.svgGroup_=this.svgBackground_=null,this.inflaters=new Map,e.setMetrics=this.setMetrics_.bind(this),this.workspace_=new Mp(e),this.workspace_.setMetricsManager(new xf(this.workspace_,this)),this.workspace_.internalIsFlyout=!0,this.workspace_.setVisible(this.visible),this.workspace_.setNavigator(new zf(this)),this.id=Ue(),this.RTL=!!e.RTL,this.toolboxPosition_=e.toolboxPosition,this.tabWidth_=this.workspace_.getRenderer().getConstants().TAB_WIDTH,this.MARGIN=this.CORNER_RADIUS,this.GAP_X=this.MARGIN*3,this.GAP_Y=this.MARGIN*3}createDom(t){return this.svgGroup_=h(t,{class:`blocklyFlyout`}),this.svgGroup_.style.display=`none`,this.svgBackground_=h(A.PATH,{class:`blocklyFlyoutBackground`},this.svgGroup_),this.svgGroup_.appendChild(this.workspace_.createDom()),this.workspace_.getThemeManager().subscribe(this.svgBackground_,`flyoutBackgroundColour`,`fill`),this.workspace_.getThemeManager().subscribe(this.svgBackground_,`flyoutOpacity`,`fill-opacity`),this.svgGroup_.addEventListener(`keydown`,t=>{t.key===`Escape`&&(e.t().focusTree(this.targetWorkspace),this.targetWorkspace.isMutator||this.autoHide(!1),t.preventDefault(),t.stopPropagation())}),this.svgGroup_}init(e){this.targetWorkspace=e,this.workspace_.targetWorkspace=e,this.workspace_.setInitialAriaContext(),this.workspace_.scrollbar=new Bf(this.workspace_,this.horizontalLayout,!this.horizontalLayout,`blocklyFlyoutScrollbar`,this.SCROLLBAR_MARGIN),this.hide(),this.boundEvents.push(o(this.svgGroup_,`wheel`,this,this.wheel_,!1,{passive:!1})),this.boundEvents.push(o(this.svgBackground_,`pointerdown`,this,this.onMouseDown)),this.workspace_.getGesture=this.targetWorkspace.getGesture.bind(this.targetWorkspace),this.workspace_.setVariableMap(this.targetWorkspace.getVariableMap()),this.workspace_.createPotentialVariableMap(),e.getComponentManager().addComponent({component:this,weight:T.ComponentWeight.FLYOUT_WEIGHT,capabilities:[T.Capability.AUTOHIDEABLE,T.Capability.DELETE_AREA,T.Capability.DRAG_TARGET]})}dispose(){this.hide(),this.targetWorkspace.getComponentManager().removeComponent(this.id);for(let e of this.boundEvents)c(e);this.boundEvents.length=0,this.workspace_&&(this.workspace_.getThemeManager().unsubscribe(this.svgBackground_),this.workspace_.dispose()),this.svgGroup_&&v(this.svgGroup_)}getWidth(){return this.width_}getHeight(){return this.height_}getFlyoutScale(){return this.targetWorkspace.scale}getWorkspace(){return this.workspace_}setAutoClose(e){this.autoClose=e,this.targetWorkspace.recordDragTargets(),this.targetWorkspace.resizeContents()}autoHide(e){!e&&this.targetWorkspace.getFlyout(!0)===this&&this.autoClose&&this.hide()}getTargetWorkspace(){return this.targetWorkspace}isVisible(){return this.visible}setVisible(e){var t=e!==this.isVisible();this.visible=e,t&&(this.autoClose||this.targetWorkspace.recordDragTargets(),this.updateDisplay())}setContainerVisible(e){var t=e!==this.containerVisible;this.containerVisible=e,t&&this.updateDisplay()}getContents(){return this.contents}setContents(e){this.contents=e}updateDisplay(){var e=this.containerVisible?this.isVisible():!1;this.svgGroup_&&(this.svgGroup_.style.display=e?`block`:`none`);var t;(t=this.workspace_.scrollbar)==null||t.setContainerVisible(e)}positionAt_(e,t,n,r){var i;(i=this.svgGroup_)==null||i.setAttribute(`width`,`${e}`);var a;(a=this.svgGroup_)==null||a.setAttribute(`height`,`${t}`),this.workspace_.setCachedParentSvgSize(e,t),this.svgGroup_&&de(this.svgGroup_,`translate(`+n+`px,`+r+`px)`),(e=this.workspace_.scrollbar)&&(e.setOrigin(n,r),e.resize(),e.hScroll&&e.hScroll.setPosition(e.hScroll.position.x,e.hScroll.position.y),e.vScroll&&e.vScroll.setPosition(e.vScroll.position.x,e.vScroll.position.y))}hide(){this.isVisible()&&(this.setVisible(!1),this.reflowWrapper&&=(this.workspace_.removeChangeListener(this.reflowWrapper),null))}show(t){e.t().getFocusedTree()===this.workspace_&&e.t().getFocusedNode()!==this.workspace_&&e.t().focusNode(this.workspace_),this.workspace_.setResizesEnabled(!1),e.Qc=!1,this.hide(),this.clearOldBlocks(),typeof t==`string`&&(t=this.getDynamicCategoryContents(t)),this.setVisible(!0),t=pt(t),t=this.createFlyoutInfo(t),jt(this.workspace_),this.setContents(t),this.layout_(t),this.horizontalLayout?this.height_=0:this.width_=0,this.reflow(),this.updateAriaContext(),e.Qc=!0,this.workspace_.setResizesEnabled(!0),this.reflowWrapper=e=>{this.inhibitReflowWrapper||e.type!==E.BLOCK_CHANGE&&e.type!==E.BLOCK_FIELD_INTERMEDIATE_CHANGE||this.reflow()},this.workspace_.addChangeListener(this.reflowWrapper)}updateAriaContext(){var t=this.getContents().map(e=>e.getElement()).filter(e=>e.canBeFocused()).map(e=>e.getFocusableElement().id);m(this.getWorkspace().getCanvas(),k.OWNS,t.join(` `)),this.targetWorkspace.isMutator||this.autoClose?p(this.getWorkspace().svgGroup_,O.NONE):p(this.getWorkspace().svgGroup_,O.REGION);var n=(t=(n=this.targetWorkspace.getToolbox())==null?void 0:n.getSelectedItem())&&Sn(t)?t.getName():``;n=e.C.WORKSPACE_LABEL_FLYOUT_WORKSPACE.replace(`%1`,n).trim(),m(this.getWorkspace().getCanvas(),k.LABEL,n),p(this.getWorkspace().getCanvas(),O.LISTBOX)}createFlyoutInfo(e){var t=[],n=this.horizontalLayout?this.GAP_X:this.GAP_Y;for(let r of e)`custom`in r&&(e=this.getDynamicCategoryContents(r.custom),e=pt(e),t.push(...this.createFlyoutInfo(e))),e=r.kind.toLowerCase(),(e=this.getInflaterForType(e))&&(t.push(e.load(r,this)),(e=e.gapForItem(r,n))&&t.push(new yf(new Sf(e,this.horizontalLayout?`x`:`y`),`sep`)));return this.normalizeSeparators(t)}normalizeSeparators(e){for(let t=e.length-1;t>0;t--){let n=e[t].getType().toLowerCase(),r=e[t-1].getType().toLowerCase();n===`sep`&&r===`sep`&&e.splice(t-1,1)}return e}getDynamicCategoryContents(e){if(e=this.workspace_.targetWorkspace.getToolboxCategoryCallback(e),typeof e!=`function`)throw TypeError(`Couldn't find a callback function when opening a toolbox category.`);return e(this.workspace_.targetWorkspace)}clearOldBlocks(){this.getContents().forEach(e=>{var t;(t=this.getInflaterForType(e.getType()))==null||t.disposeItem(e)});var e;(e=this.workspace_.getPotentialVariableMap())==null||e.clear()}onMouseDown(e){var t=this.targetWorkspace.getGesture(e);t&&t.handleFlyoutStart(e,this)}reflow(){this.inhibitReflowWrapper=!0,this.reflowInternal_(),this.inhibitReflowWrapper=!1}isScrollable(){return this.workspace_.scrollbar?this.workspace_.scrollbar.isVisible():!1}getInflaterForType(e){if(this.inflaters.has(e)){var t;return(t=this.inflaters.get(e))??null}return(t=Le(M.FLYOUT_INFLATER,e,void 0))?(t=new t,this.inflaters.set(e,t),t):null}},Uf=class{constructor(e){this.workspace=e,this.horizontalScrollEnabled=this.workspace.isMovableHorizontally(),this.verticalScrollEnabled=this.workspace.isMovableVertically(),this.startScrollXY_=new N(e.scrollX,e.scrollY)}startDrag(){}endDrag(e){this.drag(e)}drag(e){if(e=N.sum(this.startScrollXY_,e),this.horizontalScrollEnabled&&this.verticalScrollEnabled)this.workspace.scroll(e.x,e.y);else if(this.horizontalScrollEnabled)this.workspace.scroll(e.x,this.workspace.scrollY);else if(this.verticalScrollEnabled)this.workspace.scroll(this.workspace.scrollX,e.y);else throw TypeError(`Invalid state.`)}},Wf=class{constructor(e,t){this.creatorWorkspace=t,this.mouseDownXY=new N(0,0),this.startWorkspace_=this.targetBlock=this.startComment=this.startBlock=this.startIcon=this.startField=this.startBubble=null,this.hasExceededDragRadius=!1,this.boundEvents=[],this.workspaceDragger=this.dragger=null,this.dragging=!1,this.flyout=null,this.multiTouch=this.isEnding_=this.gestureHasStarted=this.calledUpdateIsDragging=!1,this.cachedPoints=new Map,this.startDistance=this.previousScale=0,this.currentDropdownOwner=this.isPinchZoomEnabled=null,this.mostRecentEvent=e,this.currentDragDeltaXY=new N(0,0)}dispose(){bo=null,Au=!1,this.creatorWorkspace.clearGesture();for(let e of this.boundEvents)c(e);this.boundEvents.length=0}updateFromEvent(e){var t=new N(e.clientX,e.clientY);this.updateDragDelta(t)&&(this.updateIsDragging(e),n()),this.mostRecentEvent=e}updateDragDelta(t){return this.currentDragDeltaXY=N.difference(t,this.mouseDownXY),this.hasExceededDragRadius?!1:this.hasExceededDragRadius=N.magnitude(this.currentDragDeltaXY)>(this.flyout?e.Og.flyoutDragRadius:e.Og.dragRadius)}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.dragging=!0,this.workspaceDragger=new Uf(this.startWorkspace_),this.workspaceDragger.startDrag())}updateIsDragging(e){if(!this.startWorkspace_)throw Error(`Cannot update dragging because the start workspace is undefined`);if(this.calledUpdateIsDragging)throw Error(`updateIsDragging_ should only be called once per gesture.`);this.calledUpdateIsDragging=!0;var t=De();t&&Vi(t)&&t.isMovable()?(this.dragging=!0,this.dragger=this.createDragger(t),this.dragger.onDragStart(e),this.dragger.onDrag(e,this.currentDragDeltaXY)):this.updateIsDraggingWorkspace()}createDragger(e){return new(Ve(M.BLOCK_DRAGGER,this.creatorWorkspace.options,!0))(e)}doStart(e){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,l(e)?this.cancel():(this.gestureHasStarted=!0,ki(),this.startWorkspace_.updateScreenCalculationsIfScrolled(),this.startWorkspace_.isMutator&&this.startWorkspace_.resize(),this.currentDropdownOwner=xu,this.startWorkspace_.hideChaff(!!this.flyout),this.startWorkspace_.markFocused(),this.mostRecentEvent=e,yr(),u(e)?this.handleRightClick(e):(e.type.toLowerCase()===`pointerdown`&&e.pointerType!==`mouse`&&t(e,this),this.mouseDownXY=new N(e.clientX,e.clientY),this.bindMouseEvents(e),this.isEnding_||this.handleTouchStart(e)))}bindMouseEvents(e){this.boundEvents.push(o(document,`pointerdown`,null,this.handleStart.bind(this),!0)),this.boundEvents.push(o(document,`pointermove`,null,this.handleMove.bind(this),!0)),this.boundEvents.push(o(document,`pointerup`,null,this.handleUp.bind(this),!0)),this.boundEvents.push(o(document,`pointercancel`,null,this.handleUp.bind(this),!0)),e.preventDefault(),e.stopPropagation()}handleStart(e){this.isDragging()||(this.handleTouchStart(e),this.isMultiTouch()&&n())}handleMove(e){this.isDragging()&&r(e)||!this.isMultiTouch()?(this.updateFromEvent(e),this.workspaceDragger?this.workspaceDragger.drag(this.currentDragDeltaXY):this.dragger&&this.dragger.onDrag(this.mostRecentEvent,this.currentDragDeltaXY),e.preventDefault(),e.stopPropagation()):this.isMultiTouch()&&(this.handleTouchMove(e),n())}handleUp(e){if(this.isDragging()||this.handleTouchEnd(e),!this.isMultiTouch()||this.isDragging()){if(!r(e))return;if(this.updateFromEvent(e),n(),this.isEnding_){console.log(`Trying to end a gesture recursively.`);return}this.isEnding_=!0,this.dragger?(z.setIsActive(!1),this.dragger.onDragEnd(e,this.currentDragDeltaXY)):this.workspaceDragger?(z.setIsActive(!1),this.workspaceDragger.endDrag(this.currentDragDeltaXY)):this.isBubbleClick()||this.isCommentClick()||(this.isFieldClick()?this.doFieldClick():this.isIconClick()?this.doIconClick():this.isBlockClick()?this.doBlockClick():this.isWorkspaceClick()&&this.doWorkspaceClick(e))}e.preventDefault(),e.stopPropagation(),this.dispose()}handleTouchStart(e){var t=i(e);this.cachedPoints.set(t,this.getTouchPoint(e));var n=Array.from(this.cachedPoints.keys());n.length===2&&(t=this.cachedPoints.get(n[0]),n=this.cachedPoints.get(n[1]),this.startDistance=N.distance(t,n),this.multiTouch=!0,e.preventDefault())}handleTouchMove(e){var t=i(e);this.cachedPoints.set(t,this.getTouchPoint(e)),this.isPinchZoomEnabled&&this.cachedPoints.size===2?this.handlePinch(e):(this.updateFromEvent(e),this.workspaceDragger?this.workspaceDragger.drag(this.currentDragDeltaXY):this.dragger&&this.dragger.onDrag(this.mostRecentEvent,this.currentDragDeltaXY),e.preventDefault(),e.stopPropagation())}handlePinch(e){var t=Array.from(this.cachedPoints.keys()),n=this.cachedPoints.get(t[0]);if(t=this.cachedPoints.get(t[1]),n=N.distance(n,t)/this.startDistance,this.previousScale>0&&this.previousScale<1/0){if(t=n-this.previousScale,t=t>0?t*5:t*6,!this.startWorkspace_)throw Error(`Cannot handle a pinch because the start workspace is undefined`);let r=this.startWorkspace_,i=d(e,r.getParentSvg(),r.getInverseScreenCTM());r.zoom(i.x,i.y,t)}this.previousScale=n,e.preventDefault()}handleTouchEnd(e){e=i(e),this.cachedPoints.has(e)&&this.cachedPoints.delete(e),this.cachedPoints.size<2&&(this.cachedPoints.clear(),this.previousScale=0)}getTouchPoint(e){return this.startWorkspace_?new N(e.pageX,e.pageY):null}isMultiTouch(){return this.multiTouch}cancel(){this.isEnding_||(n(),this.dragger?this.dragger.onDragEnd(this.mostRecentEvent,this.currentDragDeltaXY):this.workspaceDragger&&this.workspaceDragger.endDrag(this.currentDragDeltaXY),this.dispose())}handleRightClick(t){var n=e.t().getFocusedNode();if(n&&typeof n.showContextMenu==`function`){let e;(e=this.startWorkspace_)==null||e.hideChaff(!!this.flyout),n.showContextMenu(t)}t.preventDefault(),t.stopPropagation(),z.setIsActive(!1),this.dispose()}handleWsStart(t,n){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleWsStart, but the gesture had already been started.`);this.setStartWorkspace(n),this.mostRecentEvent=t,this.targetBlock||this.startBubble||this.startComment||this.startIcon||e.t().focusNode(n),this.doStart(t)}fireWorkspaceClick(e){b(new(x(E.CLICK))(null,e.id,`workspace`))}handleFlyoutStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleFlyoutStart, but the gesture had already been started.`);this.setStartFlyout(t),this.handleWsStart(e,t.getWorkspace())}handleBlockStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleBlockStart, but the gesture had already been started.`);this.setStartBlock(t),this.mostRecentEvent=e}handleBubbleStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleBubbleStart, but the gesture had already been started.`);this.setStartBubble(t),this.mostRecentEvent=e}handleCommentStart(e,t){if(this.gestureHasStarted)throw Error(`Tried to call gesture.handleCommentStart, but the gesture had already been started.`);this.setStartComment(t),this.mostRecentEvent=e}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)}doIconClick(){if(!this.startIcon)throw Error(`Cannot do an icon click because the start icon is undefined`);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`);var t=dn(this.targetBlock);let e=this.flyout.targetWorkspace;if(t&&e){var n=lt(this.flyout.getWorkspace(),this.targetBlock.getRelativeToSurfaceXY());n=ct(e,n),t.x=n.x,t.y=n.y,mn(t,e,{recordUndo:!0}),e.hideChaff(!1)}}else{if(!this.startWorkspace_)throw Error(`Cannot do a block click because the start workspace is undefined`);t=new(x(E.CLICK))(this.startBlock,this.startWorkspace_.id,`block`),b(t)}e.B(!1)}doWorkspaceClick(){this.fireWorkspaceClick(this.startWorkspace_||this.creatorWorkspace)}setStartField(e){if(this.gestureHasStarted)throw Error(`Tried to call gesture.setStartField, but the gesture had already been started.`);this.startField||=e}setStartIcon(e){if(this.gestureHasStarted)throw Error(`Tried to call gesture.setStartIcon, but the gesture had already been started.`);this.startIcon||=e}setStartBubble(e){this.startBubble||=e}setStartComment(e){this.startComment||=e}setStartBlock(e){var t,n,r;this.startBlock||this.startBubble||this.startIcon&&(!e.isInFlyout||(r=(n=this.startIcon).isClickableInFlyout)!=null&&r.call(n,!((t=e.workspace.getFlyout())==null||!t.autoClose)))||(this.startBlock=e,e.isInFlyout&&e!==e.getRootBlock()?this.setTargetBlock(e.getRootBlock()):this.setTargetBlock(e))}setTargetBlock(t){t.isShadow()?this.setTargetBlock(t.getParent()):(this.targetBlock=t,this.targetBlock.bringToFront(),e.t().focusNode(this.targetBlock))}setStartWorkspace(e){this.startWorkspace_||=e}setStartFlyout(e){this.flyout||=e}isBubbleClick(){return!!this.startBubble&&!this.hasExceededDragRadius}isCommentClick(){return!!this.startComment&&!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)):!1}isIconClick(){if(!this.startIcon)return!1;var e=!this.flyout||!this.startIcon.isClickableInFlyout||this.startIcon.isClickableInFlyout(this.flyout.autoClose);return!this.hasExceededDragRadius&&e}isWorkspaceClick(){return!this.startBlock&&!this.startBubble&&!this.startField&&!this.hasExceededDragRadius}getCurrentDragger(){return this.workspaceDragger??this.dragger??null}isDragging(){return this.dragging}hasStarted(){return this.gestureHasStarted}static inProgress(){var e=Se();for(let t=0,n;n=e[t];t++)if(n.currentGesture_)return!0;return!1}},Gf=class{constructor(e,t){this.pattern=e,this.scale=1,this.spacing=t.spacing??0,this.length=t.length??1,this.line2=(this.line1=e.firstChild)&&this.line1.nextSibling,this.snapToGrid=t.snap??!1}setSpacing(e){this.spacing=e,this.update(this.scale)}getSpacing(){return this.spacing}setLength(e){this.length=e,this.update(this.scale)}getLength(){return this.length}setSnapToGrid(e){this.snapToGrid=e}shouldSnap(){return this.snapToGrid}getPatternId(){return this.pattern.id}update(e){this.scale=e;var t=this.spacing*e;this.pattern.setAttribute(`width`,`${t}`),this.pattern.setAttribute(`height`,`${t}`),t=Math.floor(this.spacing/2)+.5;var n=t-this.length/2,r=t+this.length/2;t*=e,n*=e,r*=e,this.setLineAttributes(this.line1,e,n,r,t,t),this.setLineAttributes(this.line2,e,t,t,n,r)}setLineAttributes(e,t,n,r,i,a){e&&(e.setAttribute(`stroke-width`,`${t}`),e.setAttribute(`x1`,`${n}`),e.setAttribute(`y1`,`${i}`),e.setAttribute(`x2`,`${r}`),e.setAttribute(`y2`,`${a}`))}moveTo(e,t){this.pattern.setAttribute(`x`,`${e}`),this.pattern.setAttribute(`y`,`${t}`)}alignXY(e){var t=this.getSpacing(),n=t/2,r=Math.round(Math.round((e.x-n)/t)*t+n);return t=Math.round(Math.round((e.y-n)/t)*t+n),r===e.x&&t===e.y?e:new N(r,t)}static createDom(e,t,n,r){if(e=h(A.PATTERN,{id:`blocklyGridPattern`+e,patternUnits:`userSpaceOnUse`},n),(t.length??1)>0&&(t.spacing??0)>0){h(A.LINE,{stroke:t.colour},e);let n;(n=t.length)!=null&&n&&h(A.LINE,{stroke:t.colour},e)}else h(A.LINE,{},e);return r&&r.style.setProperty(`--blocklyGridPattern`,`url(#${e.id})`),e}},Kf=class{constructor(e){this.workspace=e,this.layers=new Map,(e=e.getInjectionDiv())&&(this.dragLayer=this.createDragLayer(e),this.animationLayer=this.createAnimationLayer(e)),e=this.createLayer(50),g(e,`blocklyBlockCanvas`),e=this.createLayer(100),g(e,`blocklyBubbleCanvas`)}createDragLayer(e){var t=h(A.SVG,{class:`blocklyBlockDragSurface`,xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`});return e.append(t),h(A.G,{},t)}createAnimationLayer(e){var t=h(A.SVG,{class:`blocklyAnimationLayer`,xmlns:`http://www.w3.org/2000/svg`,"xmlns:html":`http://www.w3.org/1999/xhtml`,"xmlns:xlink":`http://www.w3.org/1999/xlink`,version:`1.1`});return e.append(t),h(A.G,{},t)}appendToAnimationLayer(e){var t,n=(t=this.dragLayer)==null?void 0:t.getAttribute(`transform`);if(n){let e;(e=this.animationLayer)==null||e.setAttribute(`transform`,n)}var r;(r=this.animationLayer)==null||r.appendChild(e.getSvgRoot())}translateLayers(e,t){e=`translate(${e.x}, ${e.y}) scale(${t})`;var n;(n=this.dragLayer)==null||n.setAttribute(`transform`,e);for(let[,t]of this.layers)t.setAttribute(`transform`,e)}moveToDragLayer(t,n=!0){var r;(r=this.dragLayer)==null||r.appendChild(t.getSvgRoot()),n&&t.canBeFocused()&&e.t().focusNode(t)}moveOffDragLayer(t,n,r=!0){this.append(t,n),r&&t.canBeFocused()&&e.t().focusNode(t)}append(e,t){this.layers.has(t)||this.createLayer(t),e=e.getSvgRoot();var n;if(((n=this.layers.get(t))==null?void 0:n.lastChild)!==e){let n;(n=this.layers.get(t))==null||n.appendChild(e)}}createLayer(e){var t=this.workspace.getSvgGroup(),n=h(A.G,{}),r=!1,i=[...this.layers].sort((e,t)=>e[0]-t[0]);for(let[a,o]of i)if(e<a){t.insertBefore(n,o),r=!0;break}return r||t.appendChild(n),this.layers.set(e,n),n}hasLayer(e){return e===this.dragLayer||new Set(this.layers.values()).has(e)}getBlockLayer(){return this.layers.get(50)}getBubbleLayer(){return this.layers.get(100)}getDragLayer(){return this.dragLayer}},qf={};qf.register=Ea,qf.unregister=function(e){Ie(M.ICON,e)};var Jf=class extends Od{constructor(e){super(e),this.sourceBlock=e,this.textInputBubble=null,this.text=``,this.bubbleSize=new F(160,80),this.bubbleVisiblity=!1}getType(){return Jf.TYPE}initView(e){this.svgRoot||(super.initView(e),h(A.CIRCLE,{class:`blocklyIconShape`,r:`8`,cx:`8`,cy:`8`},this.svgRoot),h(A.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),h(A.RECT,{class:`blocklyIconSymbol`,x:`6.8`,y:`10.78`,height:`2`,width:`2`},this.svgRoot),g(this.svgRoot,`blocklyCommentIcon`))}dispose(){super.dispose();var e;(e=this.textInputBubble)==null||e.dispose()}getWeight(){return Jf.WEIGHT}getSize(){return new F(17,17)}applyColour(){super.applyColour();var e=this.sourceBlock.getColour(),t;(t=this.textInputBubble)==null||t.setColour(e)}updateEditable(){var e=this,t=()=>super.updateEditable;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){t().call(e),e.bubbleIsVisible()&&(yield e.setBubbleVisible(!1),yield e.setBubbleVisible(!0))})}onLocationChange(e){var t=this.workspaceLocation;super.onLocationChange(e),this.bubbleLocation&&=(e=N.difference(this.workspaceLocation,t),N.sum(this.bubbleLocation,e)),e=this.getAnchorLocation();var n;(n=this.textInputBubble)==null||n.setAnchorLocation(e)}setText(e){var t=this.text;b(new(x(E.BLOCK_CHANGE))(this.sourceBlock,`comment`,null,t,e)),this.text=e;var n;(n=this.textInputBubble)==null||n.setText(this.text)}getText(){return this.text}setBubbleSize(e){this.bubbleSize=e;var t;(t=this.textInputBubble)==null||t.setSize(this.bubbleSize,!0)}getBubbleSize(){return this.bubbleSize}setBubbleLocation(e){this.bubbleLocation=e;var t;(t=this.textInputBubble)==null||t.moveDuringDrag(e)}getBubbleLocation(){return this.bubbleLocation}saveState(){if(this.text){let e={text:this.text,pinned:this.bubbleIsVisible(),height:this.bubbleSize.height,width:this.bubbleSize.width},t=this.getBubbleLocation();return t&&(e.x=this.sourceBlock.workspace.RTL?this.sourceBlock.workspace.getWidth()-(t.x+this.bubbleSize.width):t.x,e.y=t.y),e}return null}loadState(e){this.text=e.text??``,this.bubbleSize=new F(e.width??160,e.height??80),this.bubbleVisiblity=e.pinned??!1,this.setBubbleVisible(this.bubbleVisiblity);var t=e.x,n=e.y;At().then(()=>{t&&n&&(t=this.sourceBlock.workspace.RTL?this.sourceBlock.workspace.getWidth()-(t+this.bubbleSize.width):t,this.setBubbleLocation(new N(t,n)))})}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}onTextChange(){if(this.textInputBubble){var e=this.textInputBubble.getText();this.text!==e&&(b(new(x(E.BLOCK_CHANGE))(this.sourceBlock,`comment`,null,this.text,e)),this.text=e)}}onSizeChange(){this.textInputBubble&&(this.bubbleSize=this.textInputBubble.getSize())}onBubbleLocationChange(){this.textInputBubble&&(this.bubbleLocation=this.textInputBubble.getRelativeToSurfaceXY())}bubbleIsVisible(){return this.bubbleVisiblity}setBubbleVisible(e){var t=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){t.bubbleVisiblity!==e&&(t.bubbleVisiblity=e,yield At(),!t.sourceBlock.rendered||t.sourceBlock.isInFlyout||t.sourceBlock.isInsertionMarker()||(e?(t.sourceBlock.isEditable()?t.showEditableBubble():t.showNonEditableBubble(),t.applyColour()):t.hideBubble(),b(new(x(E.BUBBLE_OPEN))(t.sourceBlock,e,`comment`)),t.svgRoot&&t.recomputeAriaContext()))})}getBubble(){return this.textInputBubble}showEditableBubble(){this.createBubble();var e;(e=this.textInputBubble)==null||e.addTextChangeListener(()=>this.onTextChange());var t;(t=this.textInputBubble)==null||t.addSizeChangeListener(()=>this.onSizeChange())}showNonEditableBubble(){this.createBubble();var e;(e=this.textInputBubble)==null||e.setEditable(!1)}createBubble(){this.textInputBubble=new Pd(this.sourceBlock.workspace,this.getAnchorLocation(),this.getBubbleOwnerRect(),this),this.textInputBubble.getEditor().setParent(this.sourceBlock),this.textInputBubble.setText(this.getText()),this.textInputBubble.setSize(this.bubbleSize,!0),this.bubbleLocation&&this.textInputBubble.moveDuringDrag(this.bubbleLocation),this.textInputBubble.addTextChangeListener(()=>this.onTextChange()),this.textInputBubble.addSizeChangeListener(()=>this.onSizeChange()),this.textInputBubble.addLocationChangeListener(()=>this.onBubbleLocationChange()),this.textInputBubble.setAriaLabelProvider(()=>e.C.BUBBLE_LABEL_COMMENT.replace(`%1`,this.getText()))}hideBubble(){var e;(e=this.textInputBubble)==null||e.dispose(),this.textInputBubble=null}getAnchorLocation(){return N.sum(this.workspaceLocation,new N(8.5,8.5))}getBubbleOwnerRect(){return this.sourceBlock.getBoundingRectangleWithoutChildren()}getAriaLabel(){return this.bubbleIsVisible()?e.C.ICON_LABEL_COMMENT_OPEN:e.C.ICON_LABEL_COMMENT_CLOSED}};Jf.TYPE=Kc.COMMENT,Jf.WEIGHT=3,Ea(Jf.TYPE,Jf);var Yf={};Yf.CommentIcon=Jf,Yf.Icon=Od,Yf.IconType=Kc,Yf.MutatorIcon=e.sh,Yf.WarningIcon=hf,Yf.exceptions=Ld,Yf.registry=qf;var Xf,Zf;e.kj=class{constructor(e,t){this.db=new Map,this.dbReverse=new Set,this.variableMap=null,this.variablePrefix=t||``,this.reservedWords=new Set(e?e.split(`,`):[])}reset(){this.db.clear(),this.dbReverse.clear(),this.variableMap=null}setVariableMap(e){this.variableMap=e}getNameForUserVariable(e){return this.variableMap?(e=this.variableMap.getVariableById(e))?e.getName():null:(console.warn(`Deprecated call to Names.prototype.getName without defining a variable map. To fix, add the following code in your generator's init() function:
856
856
  Blockly.YourGeneratorName.nameDB_.setVariableMap(workspace.getVariableMap());`),null)}populateVariables(t){t=e.Bd(t);for(let n=0;n<t.length;n++)this.getName(t[n].getId(),e.P.VARIABLE)}populateProcedures(){throw Error(`The implementation of populateProcedures should be monkey-patched in by blockly.ts`)}getName(t,n){var r=t;n===e.P.VARIABLE&&(t=this.getNameForUserVariable(t))&&(r=t),t=r.toLowerCase();var i=n===e.P.VARIABLE||n===e.P.DEVELOPER_VARIABLE?this.variablePrefix:``;this.db.has(n)||this.db.set(n,new Map);var a=this.db.get(n);return a.has(t)?i+a.get(t):(n=this.getDistinctName(r,n),a.set(t,n.substr(i.length)),n)}getUserNames(e){var t;return(e=(t=this.db.get(e))==null?void 0:t.keys())?Array.from(e):[]}getDistinctName(t,n){t=this.safeName(t);for(var r=null;this.dbReverse.has(t+(r??``))||this.reservedWords.has(t+(r??``));)r=r?r+1:2;return t+=r??``,this.dbReverse.add(t),(n===e.P.VARIABLE||n===e.P.DEVELOPER_VARIABLE?this.variablePrefix:``)+t}safeName(t){return t?(t=encodeURI(t.replace(/ /g,`_`)).replace(/[^\w]/g,`_`),`0123456789`.includes(t[0])&&(t=`my_`+t)):t=e.C.UNNAMED_KEY||`unnamed`,t}static equals(e,t){return e.toLowerCase()===t.toLowerCase()}},Xf=e.kj||={},Zf=Xf.NameType||(Xf.NameType={}),Zf.DEVELOPER_VARIABLE=`DEVELOPER_VARIABLE`,Zf.VARIABLE=`VARIABLE`,Zf.PROCEDURE=`PROCEDURE`,e.P=e.kj.NameType,e.kj.DEVELOPER_VARIABLE_TYPE=e.P.DEVELOPER_VARIABLE;var Qf=class extends Map{constructor(){super()}set(e,t){return this.get(e)===t?this:(super.set(e,t),Oa(t)&&t.startPublishing(),this)}delete(e){var t=this.get(e);return e=super.delete(e),e&&(Oa(t)&&t.stopPublishing(),e)}clear(){if(this.size)for(let e of this.keys())this.delete(e)}add(e){return this.set(e.getId(),e)}getProcedures(){return[...this.values()]}},$f={CATEGORY_NAME:`PROCEDURE`,DEFAULT_ARG:`x`};$f.ObservableProcedureMap=Qf,$f.allProcedures=ka,$f.findLegalName=e.jj,$f.flyoutCategory=Ma,$f.getCallers=Ia,$f.getDefinition=e.tj,$f.isNameUsed=ja,$f.isProcedureBlock=Da,$f.mutateCallers=e.sj,$f.mutatorOpenListener=Pa,$f.rename=e.mj;var Z=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(e){return Object.prototype.hasOwnProperty.call(this,e)||(this[e]=this.nextTypeValue_,this.nextTypeValue_<<=1),this[e]}isField(e){return(e.type&this.FIELD)>=1}isHat(e){return(e.type&this.HAT)>=1}isIcon(e){return(e.type&this.ICON)>=1}isSpacer(e){return(e.type&this.SPACER)>=1}isInRowSpacer(e){return(e.type&this.IN_ROW_SPACER)>=1}isSpacerRow(e){return(e.type&this.BETWEEN_ROW_SPACER)>=1}isInput(e){return(e.type&this.INPUT)>=1}isExternalInput(e){return(e.type&this.EXTERNAL_VALUE_INPUT)>=1}isInlineInput(e){return(e.type&this.INLINE_INPUT)>=1}isStatementInput(e){return(e.type&this.STATEMENT_INPUT)>=1}isPreviousConnection(e){return(e.type&this.PREVIOUS_CONNECTION)>=1}isNextConnection(e){return(e.type&this.NEXT_CONNECTION)>=1}isPreviousOrNextConnection(e){return this.isPreviousConnection(e)||this.isNextConnection(e)}isRoundCorner(e){return(e.type&this.LEFT_ROUND_CORNER)>=1||(e.type&this.RIGHT_ROUND_CORNER)>=1}isLeftRoundedCorner(e){return this.isRoundCorner(e)&&(e.type&this.LEFT_ROUND_CORNER)>=1}isRightRoundedCorner(e){return this.isRoundCorner(e)&&(e.type&this.RIGHT_ROUND_CORNER)>=1}isLeftSquareCorner(e){return(e.type&this.LEFT_SQUARE_CORNER)>=1}isRightSquareCorner(e){return(e.type&this.RIGHT_SQUARE_CORNER)>=1}isCorner(e){return(e.type&this.CORNER)>=1}isJaggedEdge(e){return(e.type&this.JAGGED_EDGE)>=1}isRow(e){return(e.type&this.ROW)>=1}isBetweenRowSpacer(e){return(e.type&this.BETWEEN_ROW_SPACER)>=1}isTopRow(e){return(e.type&this.TOP_ROW)>=1}isBottomRow(e){return(e.type&this.BOTTOM_ROW)>=1}isTopOrBottomRow(e){return this.isTopRow(e)||this.isBottomRow(e)}isInputRow(e){return(e.type&this.INPUT_ROW)>=1}},ep=class{constructor(e){this.centerline=this.xPos=this.height=this.width=0,this.constants_=e,this.type=Z.NONE,this.notchOffset=this.constants_.NOTCH_OFFSET_LEFT}},tp=class{constructor(e){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_=e,this.type=Z.ROW,this.notchOffset=this.constants_.NOTCH_OFFSET_LEFT}getLastInput(){for(let e=this.elements.length-1;e>=0;e--){let t=this.elements[e];if(Z.isInput(t))return t}return null}measure(){throw Error(`Unexpected attempt to measure a base Row.`)}startsWithElemSpacer(){return!0}endsWithElemSpacer(){return!0}getFirstSpacer(){for(let e=0;e<this.elements.length;e++){let t=this.elements[e];if(Z.isInRowSpacer(t))return t}return null}getLastSpacer(){for(let e=this.elements.length-1;e>=0;e--){let t=this.elements[e];if(Z.isInRowSpacer(t))return t}return null}},np=class extends tp{constructor(e){super(e),this.hasNextConnection=!1,this.connection=null,this.baseline=this.descenderHeight=0,this.type|=Z.BOTTOM_ROW}hasLeftSquareCorner(e){return!!e.outputConnection||!!e.getNextBlock()}hasRightSquareCorner(){return!0}measure(){var e=0,t=0,n=0;for(let r=0;r<this.elements.length;r++){let i=this.elements[r];t+=i.width,Z.isSpacer(i)||(Z.isNextConnection(i)?n=Math.max(n,i.height):e=Math.max(e,i.height))}this.width=Math.max(this.minWidth,t),this.height=Math.max(this.minHeight,e)+n,this.descenderHeight=n,this.widthWithConnectedBlocks=this.width}startsWithElemSpacer(){return!1}endsWithElemSpacer(){return!1}},rp=class extends ep{constructor(e,t){super(e),this.connectionModel=t,this.type|=Z.CONNECTION,this.shape=this.constants_.shapeFor(t),this.isDynamicShape=`isDynamic`in this.shape&&this.shape.isDynamic,this.highlighted=t.isHighlighted()}},ip=class extends rp{constructor(e,t){super(e,t.connection),this.input=t,this.connectionOffsetY=this.connectionOffsetX=0,this.type|=Z.INPUT,this.align=t.align,this.connectedBlock=t.connection&&t.connection.targetBlock()?t.connection.targetBlock():null,e=t.connection.getInsertionMarker(),this.connectedBlockHeight=this.connectedBlockWidth=0,this.connectedBlock&&(t=this.connectedBlock.getHeightWidth(),this.connectedBlockWidth=t.width,this.connectedBlockHeight=t.height),e&&(e=e.getHeightWidth(),this.connectedBlockWidth+=e.width,this.connectedBlockHeight+=e.height)}},ap=class extends ip{constructor(e,t){super(e,t),this.height=0,this.type|=Z.EXTERNAL_VALUE_INPUT,this.connectedBlockHeight?((e=this.connectionModel.getInsertionMarker())&&(this.connectedBlockHeight=e.getHeightWidth().height),this.height=this.connectedBlockHeight-this.constants_.TAB_OFFSET_FROM_TOP-this.constants_.MEDIUM_PADDING):this.height=this.shape.height,this.width=this.shape.width+this.constants_.EXTERNAL_VALUE_INPUT_PADDING,this.connectionOffsetY=this.constants_.TAB_OFFSET_FROM_TOP,this.connectionHeight=this.shape.height,this.connectionWidth=this.shape.width}},op=class extends ep{constructor(e,t,n){super(e),this.field=t,this.parentInput=n,this.isEditable=t.EDITABLE,this.flipRtl=t.getFlipRtl(),this.type|=Z.FIELD,e=this.field.getSize(),this.height=e.height,this.width=e.width}},sp=class extends ep{constructor(e){super(e),this.type|=Z.HAT,this.height=this.constants_.START_HAT.height,this.width=this.constants_.START_HAT.width,this.ascenderHeight=this.height}},cp=class extends ep{constructor(e,t){super(e),this.icon=t,this.flipRtl=!1,this.type|=Z.ICON,e=t.getSize(),this.height=e.height,this.width=e.width}},lp=class extends ep{constructor(e,t){super(e),this.type|=Z.SPACER|Z.IN_ROW_SPACER,this.width=t,this.height=this.constants_.SPACER_DEFAULT_HEIGHT}},up=class extends ip{constructor(e,t){super(e,t),this.type|=Z.INLINE_INPUT,this.connectedBlockWidth||this.connectedBlockHeight?(this.width=this.connectedBlockWidth,this.height=this.connectedBlockHeight):(this.height=this.constants_.EMPTY_INLINE_INPUT_HEIGHT,this.width=this.constants_.EMPTY_INLINE_INPUT_PADDING),this.connectionHeight=this.isDynamicShape?this.shape.height(this.height):this.shape.height,this.connectionWidth=this.isDynamicShape?this.shape.width(this.height):this.shape.width,this.connectedBlockHeight||(this.width+=this.connectionWidth*(this.isDynamicShape?2:1)),this.connectionOffsetY=`connectionOffsetY`in this.shape?this.shape.connectionOffsetY(this.connectionHeight):this.constants_.TAB_OFFSET_FROM_TOP,this.connectionOffsetX=`connectionOffsetX`in this.shape?this.shape.connectionOffsetX(this.connectionWidth):0}},dp=class extends tp{constructor(e){super(e),this.connectedBlockWidths=0,this.type|=Z.INPUT_ROW}measure(){this.width=this.minWidth,this.height=this.minHeight;var e=0;for(let t=0;t<this.elements.length;t++){let n=this.elements[t];this.width+=n.width,Z.isInput(n)&&(Z.isStatementInput(n)?e+=n.connectedBlockWidth:Z.isExternalInput(n)&&n.connectedBlockWidth!==0&&(e+=n.connectedBlockWidth-n.connectionWidth)),Z.isSpacer(n)||(this.height=Math.max(this.height,n.height))}this.connectedBlockWidths=e,this.widthWithConnectedBlocks=this.width+e}endsWithElemSpacer(){return!this.hasExternalInput&&!this.hasStatement}},fp=class extends ep{constructor(e){super(e),this.type|=Z.JAGGED_EDGE,this.height=this.constants_.JAGGED_TEETH.height,this.width=this.constants_.JAGGED_TEETH.width}},pp=class extends rp{constructor(e,t){super(e,t),this.type|=Z.NEXT_CONNECTION,this.height=this.shape.height,this.width=this.shape.width,(e=t.getInsertionMarker())&&(this.height+=e.getHeightWidth().height)}},mp=class extends rp{constructor(e,t){super(e,t),this.connectionOffsetX=0,this.type|=Z.OUTPUT_CONNECTION,this.height=this.isDynamicShape?0:this.shape.height,this.startX=this.width=this.isDynamicShape?0:this.shape.width,this.connectionOffsetY=this.constants_.TAB_OFFSET_FROM_TOP}},hp=class extends rp{constructor(e,t){super(e,t),this.type|=Z.PREVIOUS_CONNECTION,this.height=this.shape.height,this.width=this.shape.width}},gp=class extends ep{constructor(e,t){super(e),this.type=(t&&t!==`left`?Z.RIGHT_ROUND_CORNER:Z.LEFT_ROUND_CORNER)|Z.CORNER,this.width=this.constants_.CORNER_RADIUS,this.height=this.constants_.CORNER_RADIUS/2}},_p=class extends tp{constructor(e,t,n){super(e),this.height=t,this.width=n,this.precedesStatement=this.followsStatement=!1,this.widthWithConnectedBlocks=0,this.type|=Z.SPACER|Z.BETWEEN_ROW_SPACER,this.elements=[new lp(this.constants_,n)]}measure(){}},vp=class extends ep{constructor(e,t){super(e),this.type=(t&&t!==`left`?Z.RIGHT_SQUARE_CORNER:Z.LEFT_SQUARE_CORNER)|Z.CORNER,this.width=this.height=this.constants_.NO_PADDING}},yp=class extends ip{constructor(e,t){super(e,t),this.type|=Z.STATEMENT_INPUT,this.height=this.connectedBlockHeight?this.connectedBlockHeight+this.constants_.STATEMENT_BOTTOM_SPACER:this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT,this.width=this.constants_.STATEMENT_INPUT_NOTCH_OFFSET+this.shape.width}},bp=class extends tp{constructor(e){super(e),this.ascenderHeight=this.capline=0,this.hasPreviousConnection=!1,this.connection=null,this.type|=Z.TOP_ROW}hasLeftSquareCorner(e){var t=(e.hat?e.hat===`cap`:this.constants_.ADD_START_HATS)&&!e.outputConnection&&!e.previousConnection,n=e.getPreviousBlock();return!!e.outputConnection||t||(n?n.getNextBlock()===e:!1)}hasRightSquareCorner(){return!0}measure(){var e=0,t=0,n=0;for(let r=0;r<this.elements.length;r++){let i=this.elements[r];t+=i.width,Z.isSpacer(i)||(Z.isHat(i)?n=Math.max(n,i.ascenderHeight):e=Math.max(e,i.height))}this.width=Math.max(this.minWidth,t),this.height=Math.max(this.minHeight,e)+n,this.capline=this.ascenderHeight=n,this.widthWithConnectedBlocks=this.width}startsWithElemSpacer(){return!1}endsWithElemSpacer(){return!1}},xp=new Map,Sp=class{constructor(){this.NO_PADDING=0,this.SMALL_PADDING=3,this.MEDIUM_PADDING=5,this.MEDIUM_LARGE_PADDING=8,this.LARGE_PADDING=10,this.TAB_HEIGHT=15,this.TAB_OFFSET_FROM_TOP=5,this.TAB_VERTICAL_OVERLAP=2.5,this.TAB_WIDTH=8,this.NOTCH_WIDTH=15,this.NOTCH_HEIGHT=4,this.MIN_BLOCK_WIDTH=12,this.EMPTY_BLOCK_SPACER_HEIGHT=16,this.CORNER_RADIUS=8,this.NOTCH_OFFSET_LEFT=15,this.STATEMENT_BOTTOM_SPACER=0,this.STATEMENT_INPUT_PADDING_LEFT=20,this.BETWEEN_STATEMENT_PADDING_Y=4,this.ADD_START_HATS=!1,this.START_HAT_HEIGHT=15,this.START_HAT_WIDTH=100,this.SPACER_DEFAULT_HEIGHT=15,this.MIN_BLOCK_HEIGHT=24,this.EMPTY_INLINE_INPUT_PADDING=14.5,this.EXTERNAL_VALUE_INPUT_PADDING=2,this.JAGGED_TEETH_HEIGHT=12,this.JAGGED_TEETH_WIDTH=6,this.FIELD_TEXT_FONTSIZE=11,this.FIELD_TEXT_FONTWEIGHT=`normal`,this.FIELD_TEXT_FONTFAMILY=`sans-serif`,this.FIELD_TEXT_BASELINE=this.FIELD_TEXT_HEIGHT=-1,this.FIELD_BORDER_RECT_RADIUS=4,this.FIELD_BORDER_RECT_HEIGHT=16,this.FIELD_BORDER_RECT_X_PADDING=5,this.FIELD_BORDER_RECT_Y_PADDING=3,this.FIELD_BORDER_RECT_COLOUR=`#fff`,this.FIELD_DROPDOWN_SVG_ARROW=this.FIELD_DROPDOWN_COLOURED_DIV=this.FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW=!1,this.FIELD_DROPDOWN_SVG_ARROW_SIZE=12,this.FIELD_COLOUR_FULL_BLOCK=this.FIELD_TEXTINPUT_BOX_SHADOW=!1,this.FIELD_COLOUR_DEFAULT_WIDTH=26,this.defs=null,this.embossFilterId=``,this.embossFilter=null,this.disabledPatternId=``,this.disabledPattern=null,this.debugFilterId=``,this.debugFilter=null,this.CURSOR_COLOUR=`#cc0a0a`,this.MARKER_COLOUR=`#4286f4`,this.CURSOR_WS_WIDTH=100,this.WS_CURSOR_HEIGHT=5,this.CURSOR_STACK_PADDING=10,this.CURSOR_BLOCK_PADDING=2,this.CURSOR_STROKE_WIDTH=4,this.FULL_BLOCK_FIELDS=!1,this.INSERTION_MARKER_COLOUR=`#000000`,this.INSERTION_MARKER_OPACITY=.2,this.SHAPES={PUZZLE:1,NOTCH:2},this.TALL_INPUT_FIELD_OFFSET_Y=this.MEDIUM_PADDING,this.DUMMY_INPUT_SHADOW_MIN_HEIGHT=this.DUMMY_INPUT_MIN_HEIGHT=this.TAB_HEIGHT,this.STATEMENT_INPUT_NOTCH_OFFSET=this.NOTCH_OFFSET_LEFT,this.TOP_ROW_MIN_HEIGHT=this.MEDIUM_PADDING,this.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT=this.LARGE_PADDING,this.BOTTOM_ROW_MIN_HEIGHT=this.MEDIUM_PADDING,this.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT=this.LARGE_PADDING,this.EMPTY_INLINE_INPUT_HEIGHT=this.TAB_HEIGHT+11,this.EMPTY_STATEMENT_INPUT_HEIGHT=this.MIN_BLOCK_HEIGHT,this.START_POINT=vi(0,0),this.FIELD_TEXT_BASELINE_CENTER=!0,this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT=this.FIELD_BORDER_RECT_HEIGHT,this.FIELD_DROPDOWN_SVG_ARROW_PADDING=this.FIELD_BORDER_RECT_X_PADDING,this.FIELD_DROPDOWN_SVG_ARROW_DATAURI=`data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMi43MSIgaGVpZ2h0PSI4Ljc5IiB2aWV3Qm94PSIwIDAgMTIuNzEgOC43OSI+PHRpdGxlPmRyb3Bkb3duLWFycm93PC90aXRsZT48ZyBvcGFjaXR5PSIwLjEiPjxwYXRoIGQ9Ik0xMi43MSwyLjQ0QTIuNDEsMi40MSwwLDAsMSwxMiw0LjE2TDguMDgsOC4wOGEyLjQ1LDIuNDUsMCwwLDEtMy40NSwwTDAuNzIsNC4xNkEyLjQyLDIuNDIsMCwwLDEsMCwyLjQ0LDIuNDgsMi40OCwwLDAsMSwuNzEuNzFDMSwwLjQ3LDEuNDMsMCw2LjM2LDBTMTEuNzUsMC40NiwxMiwuNzFBMi40NCwyLjQ0LDAsMCwxLDEyLjcxLDIuNDRaIiBmaWxsPSIjMjMxZjIwIi8+PC9nPjxwYXRoIGQ9Ik02LjM2LDcuNzlhMS40MywxLjQzLDAsMCwxLTEtLjQyTDEuNDIsMy40NWExLjQ0LDEuNDQsMCwwLDEsMC0yYzAuNTYtLjU2LDkuMzEtMC41Niw5Ljg3LDBhMS40NCwxLjQ0LDAsMCwxLDAsMkw3LjM3LDcuMzdBMS40MywxLjQzLDAsMCwxLDYuMzYsNy43OVoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=`,this.FIELD_COLOUR_DEFAULT_HEIGHT=this.FIELD_BORDER_RECT_HEIGHT,this.FIELD_CHECKBOX_X_OFFSET=this.FIELD_BORDER_RECT_X_PADDING-3,this.randomIdentifier=String(Math.random()).substring(2)}init(){this.JAGGED_TEETH=this.makeJaggedTeeth(),this.NOTCH=this.makeNotch(),this.START_HAT=this.makeStartHat(),this.PUZZLE_TAB=this.makePuzzleTab(),this.INSIDE_CORNERS=this.makeInsideCorners(),this.OUTSIDE_CORNERS=this.makeOutsideCorners()}setTheme(e){this.blockStyles=Object.create(null);var t=e.blockStyles;for(let e in t)this.blockStyles[e]=this.validatedBlockStyle_(t[e]);this.setDynamicProperties_(e)}setDynamicProperties_(e){this.setFontConstants_(e),this.setComponentConstants_(e),this.ADD_START_HATS=e.startHats===void 0?this.ADD_START_HATS:e.startHats}setFontConstants_(e){e.fontStyle&&e.fontStyle.family&&(this.FIELD_TEXT_FONTFAMILY=e.fontStyle.family),e.fontStyle&&e.fontStyle.weight&&(this.FIELD_TEXT_FONTWEIGHT=e.fontStyle.weight),e.fontStyle&&e.fontStyle.size&&(this.FIELD_TEXT_FONTSIZE=e.fontStyle.size),e=ge(`Hg`,this.FIELD_TEXT_FONTSIZE+`pt`,this.FIELD_TEXT_FONTWEIGHT,this.FIELD_TEXT_FONTFAMILY),this.FIELD_TEXT_HEIGHT=e.height,this.FIELD_TEXT_BASELINE=e.baseline}setComponentConstants_(e){this.CURSOR_COLOUR=e.getComponentStyle(`cursorColour`)||this.CURSOR_COLOUR,this.MARKER_COLOUR=e.getComponentStyle(`markerColour`)||this.MARKER_COLOUR,this.INSERTION_MARKER_COLOUR=e.getComponentStyle(`insertionMarkerColour`)||this.INSERTION_MARKER_COLOUR,this.INSERTION_MARKER_OPACITY=Number(e.getComponentStyle(`insertionMarkerOpacity`))||this.INSERTION_MARKER_OPACITY}getBlockStyleForColour(e){var t=`auto_`+e;return this.blockStyles[t]||(this.blockStyles[t]=this.createBlockStyle_(e)),{style:this.blockStyles[t],name:t}}getBlockStyle(e){return this.blockStyles[e||``]||(e&&e.startsWith(`auto_`)?this.getBlockStyleForColour(e.substring(5)).style:this.createBlockStyle_(`#000000`))}createBlockStyle_(e){return this.validatedBlockStyle_({colourPrimary:e})}validatedBlockStyle_(e){var t={};return e&&Object.assign(t,e),e=Ar(t.colourPrimary||`#000`),t.colourPrimary=e.hex,t.colourSecondary=t.colourSecondary?Ar(t.colourSecondary).hex:this.generateSecondaryColour_(t.colourPrimary),t.colourTertiary=t.colourTertiary?Ar(t.colourTertiary).hex:this.generateTertiaryColour_(t.colourPrimary),t.hat=t.hat||``,t}generateSecondaryColour_(e){return Tr(`#fff`,e,.6)||e}generateTertiaryColour_(e){return Tr(`#fff`,e,.3)||e}dispose(){this.embossFilter&&v(this.embossFilter),this.disabledPattern&&v(this.disabledPattern),this.debugFilter&&v(this.debugFilter)}makeJaggedTeeth(){var e=this.JAGGED_TEETH_HEIGHT,t=this.JAGGED_TEETH_WIDTH;return{height:e,width:t,path:bi([S(t,e/4),S(-t*2,e/2),S(t,e/4)])}}makeStartHat(){var e=this.START_HAT_HEIGHT,t=this.START_HAT_WIDTH,n=gi(`c`,[S(30,-e),S(70,-e),S(t,0)]);return{height:e*.75,width:t,path:n}}makePuzzleTab(){function e(e){e=e?-1:1;var r=-e,i=n/2,a=i+2.5,o=i+.5,s=S(-t,e*i);return i=S(t,e*i),gi(`c`,[S(0,e*a),S(-t,r*o),s])+gi(`s`,[S(t,r*2.5),i])}var t=this.TAB_WIDTH,n=this.TAB_HEIGHT,r=e(!0),i=e(!1);return{type:this.SHAPES.PUZZLE,width:t,height:n,pathDown:i,pathUp:r}}makeNotch(){function e(e){return bi([S(e*r,n),S(e*3,0),S(e*r,-n)])}var t=this.NOTCH_WIDTH,n=this.NOTCH_HEIGHT,r=(t-3)/2,i=e(1),a=e(-1);return{type:this.SHAPES.NOTCH,width:t,height:n,pathLeft:i,pathRight:a}}makeInsideCorners(){var e=this.CORNER_RADIUS;return{width:e,height:e,pathTop:xi(`a`,`0 0,0`,e,S(-e,e)),pathBottom:xi(`a`,`0 0,0`,e,S(e,e))}}makeOutsideCorners(){var e=this.CORNER_RADIUS,t=vi(0,e)+xi(`a`,`0 0,1`,e,S(e,-e)),n=xi(`a`,`0 0,1`,e,S(e,e)),r=xi(`a`,`0 0,1`,e,S(-e,-e));return{topLeft:t,topRight:n,bottomRight:xi(`a`,`0 0,1`,e,S(-e,e)),bottomLeft:r,rightHeight:e}}shapeFor(e){switch(e.type){case L.INPUT_VALUE:case L.OUTPUT_VALUE:return this.PUZZLE_TAB;case L.PREVIOUS_STATEMENT:case L.NEXT_STATEMENT:return this.NOTCH;default:throw Error(`Unknown connection type`)}}createDom(e,t,n){if(n){let e=n.getRootNode();this.injectCSS_(e,t)}this.defs=h(A.DEFS,{},e),e=h(A.FILTER,{id:`blocklyEmbossFilter`+this.randomIdentifier},this.defs),h(A.FEGAUSSIANBLUR,{in:`SourceAlpha`,stdDeviation:1,result:`blur`},e),t=h(A.FESPECULARLIGHTING,{in:`blur`,surfaceScale:1,specularConstant:.5,specularExponent:10,"lighting-color":`white`,result:`specOut`},e),h(A.FEPOINTLIGHT,{x:-5e3,y:-1e4,z:2e4},t),h(A.FECOMPOSITE,{in:`specOut`,in2:`SourceAlpha`,operator:`in`,result:`specOut`},e),h(A.FECOMPOSITE,{in:`SourceGraphic`,in2:`specOut`,operator:`arithmetic`,k1:0,k2:1,k3:1,k4:0},e),this.embossFilterId=e.id,this.embossFilter=e,e=h(A.PATTERN,{id:`blocklyDisabledPattern`+this.randomIdentifier,patternUnits:`userSpaceOnUse`,width:10,height:10},this.defs),h(A.RECT,{width:10,height:10,fill:`#aaa`},e),h(A.PATH,{d:`M 0 0 L 10 10 M 10 0 L 0 10`,stroke:`#cc0`},e),this.disabledPatternId=e.id,this.disabledPattern=e,this.createDebugFilter(),n&&(n.style.setProperty(`--blocklyEmbossFilter`,`url(#${this.embossFilterId})`),n.style.setProperty(`--blocklyDisabledPattern`,`url(#${this.disabledPatternId})`),n.style.setProperty(`--blocklyDebugFilter`,`url(#${this.debugFilterId})`))}createDebugFilter(){if(!this.debugFilter){let e=h(A.FILTER,{id:`blocklyDebugFilter`+this.randomIdentifier,height:`160%`,width:`180%`,y:`-30%`,x:`-40%`},this.defs),t=h(A.FECOMPONENTTRANSFER,{result:`outBlur`},e);h(A.FEFUNCA,{type:`table`,tableValues:`0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1`},t),h(A.FEFLOOD,{"flood-color":`#ff0000`,"flood-opacity":.5,result:`outColor`},e),h(A.FECOMPOSITE,{in:`outColor`,in2:`outBlur`,operator:`in`,result:`outGlow`},e),this.debugFilterId=e.id,this.debugFilter=e}}injectCSS_(e,t){if(typeof window<`u`){var n;((n=xp.get(t))==null||!n.has(e))&&(n=document.createElement(`style`),n.className=`blockly-renderer-style`,n.textContent=this.getCSS_(t).join(`
857
857
  `),(globalThis.ShadowRoot!==void 0&&e instanceof ShadowRoot?e:document.head).prepend(n),n=xp.get(t)??new WeakSet,n.add(e),xp.set(t,n))}}getCSS_(e){return[`${e}.injectionDiv {`,`--blockly-active-node-color: #fc3;`,`}`,`${e} .blocklyText, `,`${e} .blocklyFlyoutLabelText {`,`font: ${this.FIELD_TEXT_FONTWEIGHT} ${this.FIELD_TEXT_FONTSIZE}pt ${this.FIELD_TEXT_FONTFAMILY};`,`}`,`${e} .blocklyText {`,`fill: #fff;`,`}`,`${e} .blocklyNonEditableField>rect,`,`${e} .blocklyEditableField>rect {`,`fill: ${this.FIELD_BORDER_RECT_COLOUR};`,`fill-opacity: .6;`,`stroke: none;`,`}`,`${e} .blocklyNonEditableField>text,`,`${e} .blocklyEditableField>text {`,`fill: #000;`,`}`,`${e} .blocklyFlyoutLabelText {`,`fill: #000;`,`}`,`${e} .blocklyText.blocklyBubbleText {`,`fill: #000;`,`}`,`${e} .blocklyEditableField:not(.blocklyEditing):hover>rect {`,`stroke: #fff;`,`stroke-width: 2;`,`}`,`${e} .blocklyHtmlInput {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,`font-weight: ${this.FIELD_TEXT_FONTWEIGHT};`,`}`,`${e} .blocklySelected>.blocklyPath {`,`stroke: #fc3;`,`stroke-width: 3px;`,`}`,`${e} .blocklyHighlightedConnectionPathVisible {`,`stroke: #fc3;`,`}`,`${e} .blocklyReplaceable .blocklyPath {`,`fill-opacity: .5;`,`}`,`${e} .blocklyReplaceable .blocklyPathLight,`,`${e} .blocklyReplaceable .blocklyPathDark {`,`display: none;`,`}`,`${e} .blocklyInsertionMarker>.blocklyPath {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,`stroke: none;`,`}`]}},Cp=class{constructor(e,t){this.inlinePath_=this.outlinePath_=``,this.block_=e,this.info_=t,this.topLeft_=e.getRelativeToSurfaceXY(),this.constants_=t.getRenderer().getConstants()}draw(){this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights(),this.block_.pathObject.setPath(this.outlinePath_+`
858
858
  `+this.inlinePath_),this.info_.RTL&&this.block_.pathObject.flipRTL(),this.recordSizeOnBlock_()}recordSizeOnBlock_(){this.block_.height=this.info_.height,this.block_.width=this.info_.widthWithChildren,this.block_.childlessWidth=this.info_.width}drawOutline_(){this.drawTop_();for(let e=1;e<this.info_.rows.length-1;e++){let t=this.info_.rows[e];t.hasJaggedEdge?this.drawJaggedEdge_(t):t.hasStatement?this.drawStatementInput_(t):t.hasExternalInput?this.drawValueInput_(t):this.drawRightSideRow_(t)}this.drawBottom_(),this.drawLeft_()}drawTop_(){var e=this.info_.topRow,t=e.elements;this.positionPreviousConnection_(),this.outlinePath_+=vi(e.xPos,this.info_.startY);for(let e=0,n;n=t[e];e++)Z.isLeftRoundedCorner(n)?this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.topLeft:Z.isRightRoundedCorner(n)?this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.topRight:Z.isPreviousConnection(n)?this.outlinePath_+=n.shape.pathLeft:Z.isHat(n)?this.outlinePath_+=this.constants_.START_HAT.path:Z.isSpacer(n)&&(this.outlinePath_+=C(`h`,n.width));this.outlinePath_+=C(`v`,e.height-e.ascenderHeight)}drawJaggedEdge_(e){this.outlinePath_+=this.constants_.JAGGED_TEETH.path+C(`v`,e.height-this.constants_.JAGGED_TEETH.height)}drawValueInput_(e){var t=e.getLastInput();this.positionExternalValueConnection_(e);var n=t.shape.isDynamic?t.shape.pathDown(t.height):t.shape.pathDown;this.outlinePath_+=C(`H`,t.xPos+t.width)+n+C(`v`,e.height-t.connectionHeight)}drawStatementInput_(e){var t=e.getLastInput();if(t){var n=t.xPos+t.notchOffset+t.shape.width;t=t.shape.pathRight+C(`h`,-(t.notchOffset-this.constants_.INSIDE_CORNERS.width))+this.constants_.INSIDE_CORNERS.pathTop;var r=e.height-2*this.constants_.INSIDE_CORNERS.height;this.outlinePath_+=C(`H`,n)+t+C(`v`,r)+this.constants_.INSIDE_CORNERS.pathBottom+C(`H`,e.xPos+e.width),this.positionStatementInputConnection_(e)}}drawRightSideRow_(e){this.outlinePath_+=C(`V`,e.yPos+e.height)}drawBottom_(){var e=this.info_.bottomRow,t=e.elements;this.positionNextConnection_();var n=0,r=``;for(let i=t.length-1,a;a=t[i];i--)Z.isNextConnection(a)?r+=a.shape.pathRight:Z.isLeftSquareCorner(a)?r+=C(`H`,e.xPos):Z.isLeftRoundedCorner(a)?r+=this.constants_.OUTSIDE_CORNERS.bottomLeft:Z.isRightRoundedCorner(a)?(r+=this.constants_.OUTSIDE_CORNERS.bottomRight,n=this.constants_.OUTSIDE_CORNERS.rightHeight):Z.isSpacer(a)&&(r+=C(`h`,a.width*-1));this.outlinePath_+=C(`V`,e.baseline-n),this.outlinePath_+=r}drawLeft_(){var e=this.info_.outputConnection;if(this.positionOutputConnection_(),e){let t=e.connectionOffsetY+e.height;e=e.shape.isDynamic?e.shape.pathUp(e.height):e.shape.pathUp,this.outlinePath_+=C(`V`,t)+e}this.outlinePath_+=`z`}drawInternals_(){for(let e=0,t;t=this.info_.rows[e];e++)for(let e=0,n;n=t.elements[e];e++)Z.isInlineInput(n)?this.drawInlineInput_(n):(Z.isIcon(n)||Z.isField(n))&&this.layoutField_(n)}layoutField_(e){var t=e.centerline-e.height/2,n=e.xPos,r=``;this.info_.RTL&&(n=-(n+e.width),e.flipRtl&&(n+=e.width,r=`scale(-1 1)`)),Z.isIcon(e)?(r=e.icon,r.setOffsetInBlock(new N(n,t)),this.info_.isInsertionMarker&&r.hideForInsertionMarker()):(e=e.field.getSvgRoot(),e.setAttribute(`transform`,`translate(`+n+`,`+t+`)`+r),this.info_.isInsertionMarker&&e.setAttribute(`display`,`none`))}drawInlineInput_(e){var t=e.width,n=e.height,r=e.connectionOffsetY,i=e.connectionHeight+r;this.inlinePath_+=_i(e.xPos+e.connectionWidth,e.centerline-n/2)+C(`v`,r)+e.shape.pathDown+C(`v`,n-i)+C(`h`,t-e.connectionWidth)+C(`v`,-n)+`z`,this.positionInlineInputConnection_(e)}positionInlineInputConnection_(e){var t=e.centerline-e.height/2;if(e.connectionModel){let n=e.xPos+e.connectionWidth+e.connectionOffsetX;this.info_.RTL&&(n*=-1),e.connectionModel.setOffsetInBlock(n,t+e.connectionOffsetY)}}positionStatementInputConnection_(e){var t=e.getLastInput();if(t!=null&&t.connectionModel){let n=e.xPos+e.statementEdge+t.notchOffset;this.info_.RTL&&(n*=-1),t.connectionModel.setOffsetInBlock(n,e.yPos)}}positionExternalValueConnection_(e){var t=e.getLastInput();if(t&&t.connectionModel){let n=e.xPos+e.width;this.info_.RTL&&(n*=-1),t.connectionModel.setOffsetInBlock(n,e.yPos)}}positionPreviousConnection_(){var e=this.info_.topRow;if(e.connection){let t=e.xPos+e.notchOffset;e.connection.connectionModel.setOffsetInBlock(this.info_.RTL?-t:t,0)}}positionNextConnection_(){var e=this.info_.bottomRow;if(e.connection){let t=e.connection,n=t.xPos;t.connectionModel.setOffsetInBlock(this.info_.RTL?-n:n,e.baseline)}}positionOutputConnection_(){if(this.info_.outputConnection){var e=this.info_.startX+this.info_.outputConnection.connectionOffsetX;e=this.info_.RTL?-e:e;let t;(t=this.block_.outputConnection)==null||t.setOffsetInBlock(e,this.info_.outputConnection.connectionOffsetY)}}updateConnectionHighlights(){for(let e of this.info_.rows)for(let t of e.elements){if(!(t instanceof rp))continue;let e=this.drawConnectionHighlightPath(t);e&&(t.connectionModel.setAriaRole(e),e.classList.toggle(`blocklyHighlightedConnectionPathVisible`,t.highlighted))}}drawConnectionHighlightPath(e){var t=e.connectionModel;e=t.type===L.INPUT_VALUE||t.type===L.OUTPUT_VALUE?this.getExpressionConnectionHighlightPath(e):this.getStatementConnectionHighlightPath(e);var n=t.getSourceBlock(),r,i;return(i=(r=n.pathObject).addConnectionHighlight)==null?void 0:i.call(r,t,e,t.getOffsetInBlock(),n.RTL)}getExpressionConnectionHighlightPath(e){var t=``;if(e.shape.isDynamic)t=e.shape.pathDown(e.height);else{var n=e.shape;n.pathDown!==void 0&&n.pathUp!==void 0&&(t=e.shape.pathDown)}return e=this.constants_.TAB_OFFSET_FROM_TOP,vi(0,-e)+C(`v`,e)+t+C(`v`,e)}getStatementConnectionHighlightPath(e){var t=e.shape;if(t.pathLeft===void 0||t.pathRight===void 0)throw Error(`Statement connections should have notch shapes`);return t=this.constants_.NOTCH_OFFSET_LEFT-this.constants_.CORNER_RADIUS,vi(-t,0)+C(`h`,t)+e.shape.pathLeft+C(`h`,t)}},wp=class{constructor(e,t){this.statementEdge=this.width=this.widthWithChildren=this.height=0,this.rows=[],this.inputRows=[],this.startY=this.startX=0,this.renderer_=e,this.block_=t,this.constants_=this.renderer_.getConstants(),this.outputConnection=t.outputConnection?new mp(this.constants_,t.outputConnection):null,this.isInline=t.getInputsInline()&&!t.isCollapsed(),this.isCollapsed=t.isCollapsed(),this.isInsertionMarker=t.isInsertionMarker(),this.RTL=t.RTL,this.topRow=new bp(this.constants_),this.bottomRow=new np(this.constants_)}getRenderer(){return this.renderer_}measure(){this.createRows_(),this.addElemSpacing_(),this.addRowSpacing_(),this.computeBounds_(),this.alignRowElements_(),this.finalize_()}createRows_(){this.populateTopRow_(),this.rows.push(this.topRow);var e=new dp(this.constants_);this.inputRows.push(e);var t=this.block_.getIcons();for(let n=0,r;r=t[n];n++){let t=new cp(this.constants_,r);this.isCollapsed&&!r.isShownWhenCollapsed()||e.elements.push(t)}t=void 0;for(let n=0,r;r=this.block_.inputList[n];n++)if(r.isVisible()){this.shouldStartNewRow_(r,t)&&(this.rows.push(e),e=new dp(this.constants_),this.inputRows.push(e));for(let t=0,n;n=r.fieldRow[t];t++)e.elements.push(new op(this.constants_,n,r));this.addInput_(r,e),t=r}this.isCollapsed&&(e.hasJaggedEdge=!0,e.elements.push(new fp(this.constants_))),(e.elements.length||e.hasDummyInput)&&this.rows.push(e),this.populateBottomRow_(),this.rows.push(this.bottomRow)}populateTopRow_(){var e=!!this.block_.previousConnection,t=(this.block_.hat?this.block_.hat===`cap`:this.constants_.ADD_START_HATS)&&!this.outputConnection&&!e,n=this.topRow.hasLeftSquareCorner(this.block_)?vp:gp;this.topRow.elements.push(new n(this.constants_)),t?(e=new sp(this.constants_),this.topRow.elements.push(e)):e&&(this.topRow.hasPreviousConnection=!0,this.topRow.connection=new hp(this.constants_,this.block_.previousConnection),this.topRow.elements.push(this.topRow.connection)),this.block_.inputList.length&&this.block_.inputList[0]instanceof Kd&&!this.block_.isCollapsed()?this.topRow.minHeight=this.constants_.TOP_ROW_PRECEDES_STATEMENT_MIN_HEIGHT:this.topRow.minHeight=this.constants_.TOP_ROW_MIN_HEIGHT,n=this.topRow.hasRightSquareCorner(this.block_)?vp:gp,this.topRow.elements.push(new n(this.constants_,`right`))}populateBottomRow_(){this.bottomRow.hasNextConnection=!!this.block_.nextConnection,this.bottomRow.minHeight=this.block_.inputList.length&&this.block_.inputList[this.block_.inputList.length-1]instanceof Kd?this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT:this.constants_.BOTTOM_ROW_MIN_HEIGHT,this.bottomRow.hasLeftSquareCorner(this.block_)?this.bottomRow.elements.push(new vp(this.constants_)):this.bottomRow.elements.push(new gp(this.constants_)),this.bottomRow.hasNextConnection&&(this.bottomRow.connection=new pp(this.constants_,this.block_.nextConnection),this.bottomRow.elements.push(this.bottomRow.connection)),this.bottomRow.hasRightSquareCorner(this.block_)?this.bottomRow.elements.push(new vp(this.constants_,`right`)):this.bottomRow.elements.push(new gp(this.constants_,`right`))}addInput_(t,n){this.isInline&&t instanceof e.Nn?(n.elements.push(new up(this.constants_,t)),n.hasInlineInput=!0):t instanceof Kd?(n.elements.push(new yp(this.constants_,t)),n.hasStatement=!0):t instanceof e.Nn?(n.elements.push(new ap(this.constants_,t)),n.hasExternalInput=!0):(t instanceof Wd||t instanceof Gd)&&(n.minHeight=Math.max(n.minHeight,t.getSourceBlock()&&t.getSourceBlock().isShadow()?this.constants_.DUMMY_INPUT_SHADOW_MIN_HEIGHT:this.constants_.DUMMY_INPUT_MIN_HEIGHT),n.hasDummyInput=!0),n.align===null&&(n.align=t.align)}shouldStartNewRow_(t,n){return n?n instanceof Gd||t instanceof Kd||n instanceof Kd?!0:t instanceof e.Nn||t instanceof Wd||n instanceof e.Nn?!this.isInline:!1:!1}addElemSpacing_(){for(let e=0,t;t=this.rows[e];e++){let e=t.elements;if(t.elements=[],t.startsWithElemSpacer()&&t.elements.push(new lp(this.constants_,this.getInRowSpacing_(null,e[0]))),e.length){for(let n=0;n<e.length-1;n++){t.elements.push(e[n]);let r=this.getInRowSpacing_(e[n],e[n+1]);t.elements.push(new lp(this.constants_,r))}t.elements.push(e[e.length-1]),t.endsWithElemSpacer()&&t.elements.push(new lp(this.constants_,this.getInRowSpacing_(e[e.length-1],null)))}}}getInRowSpacing_(e,t){if(!e&&t&&Z.isStatementInput(t))return this.constants_.STATEMENT_INPUT_PADDING_LEFT;if(e&&Z.isInput(e)&&!t){if(Z.isExternalInput(e))return this.constants_.NO_PADDING;if(Z.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Z.isStatementInput(e))return this.constants_.NO_PADDING}return e&&Z.isLeftSquareCorner(e)&&t&&(Z.isPreviousConnection(t)||Z.isNextConnection(t))?t.notchOffset:e&&Z.isLeftRoundedCorner(e)&&t&&(Z.isPreviousConnection(t)||Z.isNextConnection(t))?t.notchOffset-this.constants_.CORNER_RADIUS:e&&Z.isField(e)&&e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING}computeBounds_(){var e=0,t=0,n=0;for(let i=0,a;a=this.rows[i];i++){if(a.measure(),t=Math.max(t,a.width),a.hasStatement){var r=a.getLastInput();r=a.width-((r==null?void 0:r.width)??0),e=Math.max(e,r)}n=Math.max(n,a.widthWithConnectedBlocks)}this.statementEdge=e,this.width=t;for(let e=0,t;t=this.rows[e];e++)t.hasStatement&&(t.statementEdge=this.statementEdge);this.widthWithChildren=Math.max(t,n),this.outputConnection&&(this.startX=this.outputConnection.width,this.width+=this.outputConnection.width,this.widthWithChildren+=this.outputConnection.width)}alignRowElements_(){for(let t=0,n;n=this.rows[t];t++)if(n.hasStatement)this.alignStatementRow_(n);else{var e=n.width;e=this.getDesiredRowWidth_(n)-e,e>0&&this.addAlignmentPadding_(n,e),Z.isTopOrBottomRow(n)&&(n.widthWithConnectedBlocks=n.width)}}getDesiredRowWidth_(){return this.width-this.startX}addAlignmentPadding_(t,n){var r=t.getFirstSpacer(),i=t.getLastSpacer();if((t.hasExternalInput||t.hasStatement)&&(t.widthWithConnectedBlocks+=n),t.align===e.En.LEFT&&i)i.width+=n;else if(t.align===e.En.CENTRE&&r&&i)r.width+=n/2,i.width+=n/2;else if(t.align===e.En.RIGHT&&r)r.width+=n;else if(i)i.width+=n;else return;t.width+=n}alignStatementRow_(e){var t=e.getLastInput();if(t){var n=e.width-t.width,r=this.statementEdge;n=r-n,n>0&&this.addAlignmentPadding_(e,n),n=e.width,r=this.getDesiredRowWidth_(e),t.width+=r-n,t.height=Math.max(t.height,e.height),e.width+=r-n,e.widthWithConnectedBlocks=Math.max(e.width,this.statementEdge+e.connectedBlockWidths)}}addRowSpacing_(){var e=this.rows;this.rows=[];for(let t=0;t<e.length;t++)this.rows.push(e[t]),t!==e.length-1&&this.rows.push(this.makeSpacerRow_(e[t],e[t+1]))}makeSpacerRow_(e,t){var n=this.getSpacerRowHeight_(e,t),r=this.getSpacerRowWidth_(e,t);return n=new _p(this.constants_,n,r),e.hasStatement&&(n.followsStatement=!0),t.hasStatement&&(n.precedesStatement=!0),n}getSpacerRowWidth_(){return this.width-this.startX}getSpacerRowHeight_(){return this.constants_.MEDIUM_PADDING}getElemCenterline_(e,t){return Z.isSpacer(t)?e.yPos+t.height/2:Z.isBottomRow(e)?(e=e.yPos+e.height-e.descenderHeight,Z.isNextConnection(t)?e+t.height/2:e-t.height/2):Z.isTopRow(e)?Z.isHat(t)?e.capline-t.height/2:e.capline+t.height/2:e.yPos+e.height/2}recordElemPositions_(e){var t=e.xPos;for(let n=0,r;r=e.elements[n];n++)Z.isSpacer(r)&&(r.height=e.height),r.xPos=t,r.centerline=this.getElemCenterline_(e,r),t+=r.width}finalize_(){var e=0,t=0;for(let n=0,r;r=this.rows[n];n++)r.yPos=t,r.xPos=this.startX,t+=r.height,e=Math.max(e,r.widthWithConnectedBlocks),this.recordElemPositions_(r);if(this.outputConnection&&this.block_.nextConnection){let t=this.block_.nextConnection.targetBlock();t&&(e=Math.max(e,t.getHeightWidth().width))}this.widthWithChildren=e+this.startX,this.height=t,this.startY=this.topRow.capline,this.bottomRow.baseline=t-this.bottomRow.descenderHeight}getMeasureableForConnection(e){var t;if(((t=this.outputConnection)==null?void 0:t.connectionModel)===e)return this.outputConnection;for(let t of this.rows)for(let n of t.elements)if(n instanceof rp&&n.connectionModel===e)return n;return null}},Tp=class{constructor(e,t,n){this.connectionHighlights=new WeakMap,this.highlightOffsets=new WeakMap,this.constants=n,this.style=t,this.svgRoot=e,this.svgPath=h(A.PATH,{class:`blocklyPath`},this.svgRoot),this.setClass_(`blocklyBlock`,!0)}setPath(e){this.svgPath.setAttribute(`d`,e)}flipRTL(){this.svgPath.setAttribute(`transform`,`scale(-1 1)`)}applyColour(e){this.svgPath.setAttribute(`stroke`,this.style.colourTertiary),this.svgPath.setAttribute(`fill`,this.style.colourPrimary),this.updateShadow_(e.isShadow()),this.updateDisabled_(!e.isEnabled()||e.getInheritedDisabled())}setStyle(e){this.style=e}setClass_(e,t){e&&(t?g(this.svgRoot,e):_(this.svgRoot,e))}updateHighlighted(e){e?this.setClass_(`blocklyHighlighted`,!0):this.setClass_(`blocklyHighlighted`,!1)}updateShadow_(e){e?(this.setClass_(`blocklyShadow`,!0),this.svgPath.setAttribute(`stroke`,`none`),this.svgPath.setAttribute(`fill`,this.style.colourSecondary)):this.setClass_(`blocklyShadow`,!1)}updateDisabled_(e){this.setClass_(`blocklyDisabled`,e),this.setClass_(`blocklyDisabledPattern`,e)}updateSelected(e){this.setClass_(`blocklySelected`,e)}updateDraggingDelete(e){this.setClass_(`blocklyDraggingDelete`,e)}updateInsertionMarker(e){this.setClass_(`blocklyInsertionMarker`,e)}updateMovable(e){this.setClass_(`blocklyDraggable`,e)}updateReplacing(e){this.setClass_(`blocklyReplaceable`,e)}addConnectionHighlight(e,t,n,r){return n=`translate(${n.x}, ${n.y})`+(r?` scale(-1 1)`:``),(r=this.connectionHighlights.get(e))?(r.setAttribute(`d`,t),r.setAttribute(`transform`,n),r):(t=h(A.PATH,{id:e.id,class:`blocklyHighlightedConnectionPath`,d:t,transform:n},this.svgRoot),this.connectionHighlights.set(e,t),t)}removeConnectionHighlight(e){var t=this.connectionHighlights.get(e);t&&(v(t),this.connectionHighlights.delete(e))}},Ep=class{constructor(e){this.overrides=null,this.name=e}getClassName(){return this.name+`-renderer`}init(e,t){this.constants_=this.makeConstants_(),t&&(this.overrides=t,Object.assign(this.constants_,t)),this.constants_.setTheme(e),this.constants_.init()}createDom(e,t,n){this.constants_.createDom(e,`.`+this.getClassName()+`.`+t.getClassName(),n)}refreshDom(e,t,n){var r=this.getConstants();r.dispose(),this.constants_=this.makeConstants_(),this.overrides&&Object.assign(this.constants_,this.overrides),this.constants_.randomIdentifier=r.randomIdentifier,this.constants_.setTheme(t),this.constants_.init(),this.createDom(e,t,n)}dispose(){this.constants_&&this.constants_.dispose()}makeConstants_(){return new Sp}makeRenderInfo_(e){return new wp(this,e)}makeDrawer_(e,t){return new Cp(e,t)}makePathObject(e,t){return new Tp(e,t,this.constants_)}getConstants(){return this.constants_}shouldHighlightConnection(e){return!e.getSourceBlock().isDragging()}orphanCanConnectAtEnd(e,t,n){return!!q.getConnectionForOrphanedConnection(e,n===L.OUTPUT_VALUE?t.outputConnection:t.previousConnection)}render(e){var t=this.makeRenderInfo_(e);t.measure(),this.makeDrawer_(e,t).draw()}},Q={};Q.BottomRow=np,Q.Connection=rp,Q.ConstantProvider=Sp,Q.Drawer=Cp,Q.ExternalValueInput=ap,Q.Field=op,Q.Hat=sp,Q.Icon=cp,Q.InRowSpacer=lp,Q.InlineInput=up,Q.InputConnection=ip,Q.InputRow=dp,Q.JaggedEdge=fp,Q.Measurable=ep,Q.NextConnection=pp,Q.OutputConnection=mp,Q.PathObject=Tp,Q.PreviousConnection=hp,Q.RenderInfo=wp,Q.Renderer=Ep,Q.RoundCorner=gp,Q.Row=tp,Q.SpacerRow=_p,Q.SquareCorner=vp,Q.StatementInput=yp,Q.TopRow=bp,Q.Types=Z,Q.init=Ra,Q.register=La,Q.unregister=function(e){Ie(M.RENDERER,e)};var Dp=class{constructor(e,t){this.workspace=e,this.theme=t,this.subscribedWorkspaces=[],this.componentDB=new Map}getTheme(){return this.theme}setTheme(e){var t=this.theme;this.theme=e,(e=this.workspace.getInjectionDiv())&&((t&&=t.getClassName())&&_(e,t),(t=this.theme.getClassName())&&g(e,t));for(let e=0,t;t=this.subscribedWorkspaces[e];e++)t.refreshTheme();for(let[n,r]of this.componentDB)for(let i of r){e=i.element,t=i.propertyName;let r=this.theme&&this.theme.getComponentStyle(n);e.style.setProperty(t,r||``)}for(let e of this.subscribedWorkspaces)e.hideChaff()}subscribeWorkspace(e){this.subscribedWorkspaces.push(e)}unsubscribeWorkspace(e){if(!f(this.subscribedWorkspaces,e))throw Error(`Cannot unsubscribe a workspace that hasn't been subscribed.`)}subscribe(e,t,n){this.componentDB.has(t)||this.componentDB.set(t,[]),this.componentDB.get(t).push({element:e,propertyName:n}),t=this.theme&&this.theme.getComponentStyle(t),e.style.setProperty(n,t||``)}unsubscribe(e){if(e)for(let[t,n]of this.componentDB){for(let t=n.length-1;t>=0;t--)n[t].element===e&&n.splice(t,1);n.length||this.componentDB.delete(t)}}dispose(){this.subscribedWorkspaces.length=0,this.componentDB.clear()}},Op={CATEGORY_NAME:`VARIABLE_DYNAMIC`};Op.flyoutCategory=Ha,Op.flyoutCategoryBlocks=function(t){t=t.getVariableMap().getAllVariables();var n=[];if(t.length>0){if($o.variables_set_dynamic){var r=t[t.length-1];let i=e.rc(`block`);i.setAttribute(`type`,`variables_set_dynamic`),i.setAttribute(`gap`,`24`),i.appendChild(sn(r)),n.push(i)}if($o.variables_get_dynamic){t.sort(ln);for(let i=0,a;a=t[i];i++)r=e.rc(`block`),r.setAttribute(`type`,`variables_get_dynamic`),r.setAttribute(`gap`,`8`),r.appendChild(sn(a)),n.push(r)}}return n},Op.onCreateVariableButtonClick_Colour=Va,Op.onCreateVariableButtonClick_Number=Ba,Op.onCreateVariableButtonClick_String=za;var kp=class{get isFlyout(){return this.internalIsFlyout}get isMutator(){return this.internalIsMutator}constructor(e){this.isClearing=this.internalIsMutator=this.internalIsFlyout=this.rendered=!1,this.MAX_UNDO=1024,this.connectionDBList=[],this.topBlocks=[],this.topComments=[],this.commentDB=new Map,this.listeners=[],this.undoStack_=[],this.redoStack_=[],this.blockDB=new Map,this.typedBlocksDB=new Map,this.procedureMap=new Qf,this.readOnly=!1,this.potentialVariableMap=null,this.id=Ue(),Ce(this),this.options=e||new wd({}),this.RTL=!!this.options.RTL,this.horizontalLayout=!!this.options.horizontalLayout,this.toolboxPosition=this.options.toolboxPosition,this.connectionChecker=new(Ve(M.CONNECTION_CHECKER,this.options,!0))(this),this.variableMap=new(this.getVariableMapClass())(this),this.setIsReadOnly(this.options.readOnly)}dispose(){this.listeners.length=0,this.clear(),we(this)}sortObjects(e,t){var n=e=>({getBoundingRectangle:()=>{var t=e.getRelativeToSurfaceXY();return new P(t.y,t.y,t.x,t.x)},moveBy:()=>{}});return this.sortByOrigin(n(e),n(t))}sortByOrigin(e,t){var n=Math.sin(Rn(kp.SCAN_ANGLE))*(this.RTL?-1:1);return e=e.getBoundingRectangle().getOrigin(),t=t.getBoundingRectangle().getOrigin(),e.y+n*e.x-(t.y+n*t.x)}addTopBlock(e){this.topBlocks.push(e)}removeTopBlock(e){if(!f(this.topBlocks,e))throw Error(`Block not present in workspace's list of top-most blocks.`)}getTopBlocks(e=!1){var t=[].concat(this.topBlocks);return e&&t.length>1&&t.sort(this.sortObjects.bind(this)),t}addTypedBlock(e){this.typedBlocksDB.has(e.type)||this.typedBlocksDB.set(e.type,[]),this.typedBlocksDB.get(e.type).push(e)}removeTypedBlock(e){f(this.typedBlocksDB.get(e.type),e),this.typedBlocksDB.get(e.type).length||this.typedBlocksDB.delete(e.type)}getBlocksByType(e,t=!1){return this.typedBlocksDB.has(e)?(e=this.typedBlocksDB.get(e).slice(0),t&&e&&e.length>1&&e.sort(this.sortObjects.bind(this)),e.filter(e=>!e.isInsertionMarker())):[]}addTopComment(e){this.topComments.push(e),this.commentDB.has(e.id)&&console.warn(`Overriding an existing comment on this workspace, with id "`+e.id+`"`),this.commentDB.set(e.id,e)}removeTopComment(e){if(!f(this.topComments,e))throw Error(`Comment not present in workspace's list of top-most comments.`);this.commentDB.delete(e.id)}getTopComments(e=!1){var t=[].concat(this.topComments);return e&&t.length>1&&t.sort(this.sortObjects.bind(this)),t}getAllBlocks(e=!1){if(e){var t=this.getTopBlocks(!0);e=[];for(let n=0;n<t.length;n++)e.push(...t[n].getDescendants(!0))}else for(e=this.getTopBlocks(!1),t=0;t<e.length;t++)e.push(...e[t].getChildren(!1));return e.filter(e=>!e.isInsertionMarker())}clear(){this.isClearing=!0;try{let t=e.gd;for(t||e.B(!0);this.topBlocks.length;)this.topBlocks[0].dispose(!1);for(;this.topComments.length;)this.topComments[this.topComments.length-1].dispose();e.B(t),this.isFlyout||this.variableMap.clear(),this.potentialVariableMap&&this.potentialVariableMap.clear()}finally{this.isClearing=!1}}getWidth(){return 0}newBlock(){throw Error(`The implementation of newBlock should be monkey-patched in by blockly.ts`)}newComment(){throw Error(`The implementation of newComment should be monkey-patched in by blockly.ts`)}remainingCapacity(){return isNaN(this.options.maxBlocks)?1/0:this.options.maxBlocks-this.getAllBlocks(!1).length}remainingCapacityOfType(e){return this.options.maxInstances?(this.options.maxInstances[e]===void 0?1/0:this.options.maxInstances[e])-this.getBlocksByType(e,!1).length:1/0}isCapacityAvailable(e){if(!this.hasBlockLimits())return!0;var t=0;for(let n in e){if(e[n]>this.remainingCapacityOfType(n))return!1;t+=e[n]}return!(t>this.remainingCapacity())}hasBlockLimits(){return this.options.maxBlocks!==1/0||!!this.options.maxInstances}getUndoStack(){return this.undoStack_}getRedoStack(){return this.redoStack_}undo(t=!1){var n=t?this.redoStack_:this.undoStack_,r=t?this.undoStack_:this.redoStack_,i=n.pop();if(i){for(var a=[i];n.length&&i.group&&i.group===n[n.length-1].group;){let e=n.pop();e&&a.push(e)}for(n=0;n<a.length;n++)r.push(a[n]);e.Qc=!1;try{for(r=0;r<a.length;r++)a[r].run(t)}finally{e.Qc=!0}}}redo(){this.undo(!0)}clearUndo(){this.undoStack_.length=0,this.redoStack_.length=0,qe()}addChangeListener(e){return this.listeners.push(e),e}removeChangeListener(e){f(this.listeners,e)}fireChangeListener(e){if(e.recordUndo)for(this.undoStack_.push(e),this.redoStack_.length=0;this.undoStack_.length>this.MAX_UNDO&&this.MAX_UNDO>=0;)this.undoStack_.shift();for(let t=0;t<this.listeners.length;t++)(0,this.listeners[t])(e)}getBlockById(e){return this.blockDB.get(e)||null}setBlockById(e,t){this.blockDB.set(e,t)}removeBlockById(e){this.blockDB.delete(e)}getCommentById(e){return this.commentDB.get(e)??null}allInputsFilled(e){var t=this.getTopBlocks(!1);for(let n=0;n<t.length;n++)if(!t[n].allInputsFilled(e))return!1;return!0}getPotentialVariableMap(){return this.potentialVariableMap}createPotentialVariableMap(){this.potentialVariableMap=new(this.getVariableMapClass())(this,!0)}getVariableMap(){return this.variableMap}setVariableMap(e){this.variableMap=e}getProcedureMap(){return this.procedureMap}getRootWorkspace(){var e=null,t=this.options.parentWorkspace;return this.isFlyout?t&&t.options&&(e=t.options.parentWorkspace):t&&(e=t),e}static getById(e){return xe(e)}static getAll(){return Se()}getVariableMapClass(){var e=Ve(M.VARIABLE_MAP,this.options,!0);if(!e)throw Error(`No variable map is registered.`);return e}isReadOnly(){return this.readOnly}setIsReadOnly(e){this.readOnly=e,this.options.readOnly=e}};kp.SCAN_ANGLE=3;var Ap=class{constructor(e){this.parentWorkspace=e,this.sounds=new Map,this.lastSound=null,this.muted=!1,window.AudioContext&&(this.context=new AudioContext)}dispose(){this.sounds.clear();var e;(e=this.context)==null||e.close()}load(e,t){var n=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){if(e.length){var r=yield(yield fetch(e[0])).arrayBuffer(),i;(i=n.context)==null||i.decodeAudioData(r,e=>{n.sounds.set(t,e)})}})}play(e,t){var n=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){if(n.isPlayingAllowed()&&t!==0){var r=n.sounds.get(e);if(r){yield n.prepareToPlay();let e=n.context.createBufferSource(),i=n.context.createGain();i.gain.value=t??1,i.connect(n.context.destination),e.buffer=r,e.connect(i),e.addEventListener(`ended`,()=>{e.disconnect(),i.disconnect()}),e.start()}else n.parentWorkspace&&(r=n.parentWorkspace.getAudioManager(),r!==n&&r.play(e,t))}})}beep(e,t=.2){var n=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){if(n.isPlayingAllowed()){yield n.prepareToPlay();var r=n.context.createOscillator();r.type=`sine`,r.frequency.setValueAtTime(e,n.context.currentTime);var i=n.context.createGain();i.gain.setValueAtTime(0,n.context.currentTime),i.gain.linearRampToValueAtTime(.5,n.context.currentTime+.01),i.gain.linearRampToValueAtTime(0,n.context.currentTime+t),r.connect(i),i.connect(n.context.destination),r.start(n.context.currentTime),r.stop(n.context.currentTime+t)}})}playErrorBeep(){var e=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){return e.beep(260)})}maybePlayScopeChangeAudioCue(t){if(z.getScopeChangeAudioCuesEnabled()){var n=this.parentWorkspace.getNavigator(),r=n.getSourceBlockFromNode(e.t().getFocusedNode());t=n.getSourceBlockFromNode(t),n=0,r&&t&&r.getNestingLevel()!==(n=t.getNestingLevel())&&this.beep(400+n*60)}}isPlayingAllowed(){var e=new Date;return!(this.getMuted()||!this.context||this.lastSound!==null&&e.getTime()-this.lastSound.getTime()<100)}prepareToPlay(){var e=this;return(0,w.asyncExecutePromiseGeneratorFunction)(function*(){e.lastSound=new Date,e.context.state===`suspended`&&(yield e.context.resume())})}setMuted(e){this.muted=e}getMuted(){return this.muted}},jp=class{constructor(e,t){this.workspace=e,this.element=t}getFocusableElement(){return this.element}getFocusableTree(){return this.workspace}onNodeFocus(){this.workspace.handleWorkspaceFocusTargetFocus()}onNodeBlur(){}canBeFocused(){return!0}getWorkspace(){return this.workspace}},Mp=class extends kp{constructor(e){super(e),this.resizeHandlerWrapper=null,this.resizesEnabled=this.visible=this.rendered=!0,this.startScrollY=this.startScrollX=this.scrollY=this.scrollX=0,this.oldScale=this.scale=1,this.oldLeft=this.oldTop=0,this.inverseScreenCTM=this.targetWorkspace=this.dummyWheelListener=this.configureContextMenu=this.lastRecordedPageScroll=this.injectionDiv=this.currentGesture_=this.toolbox=this.flyout=this.scrollbar=this.trashcan=null,this.inverseScreenCTMDirty=!0,this.highlightedBlocks=[],this.toolboxCategoryCallbacks=new Map,this.flyoutButtonCallbacks=new Map,this.cachedParentSvg=null,this.topBoundedElements=[],this.dragTargetAreas=[],this.workspaceFocusTarget=this.workspaceFocusTargetElement=this.workspaceSelectionRing=this.workspaceFocusRing=this.zoomControls_=this.layerManager=null,this.navigator=new If,this.metricsManager=new(Ve(M.METRICS_MANAGER,e,!0))(this),this.getMetrics=e.getMetrics||this.metricsManager.getMetrics.bind(this.metricsManager),this.setMetrics=e.setMetrics||Mp.setTopLevelWorkspaceMetrics,this.componentManager=new T,this.connectionDBList=Fd.init(this.connectionChecker),this.audioManager=new Ap(e.parentWorkspace??this),this.grid=this.options.gridPattern?new Gf(this.options.gridPattern,e.gridOptions):null,$l&&Jt&&this.registerToolboxCategoryCallback(`VARIABLE`,Jt),Op&&Ha&&this.registerToolboxCategoryCallback(`VARIABLE_DYNAMIC`,Ha),$f&&Ma&&(this.registerToolboxCategoryCallback(`PROCEDURE`,Ma),this.addChangeListener(Pa)),this.addChangeListener(this.variableChangeCallback.bind(this)),this.themeManager_=this.options.parentWorkspace?this.options.parentWorkspace.getThemeManager():new Dp(this,this.options.theme||Cd),this.themeManager_.subscribeWorkspace(this),this.renderer=Ra(this.options.renderer||`geras`,this.getTheme(),this.options.rendererOverrides??void 0),this.cachedParentSvgSize=new F(0,0)}getMetricsManager(){return this.metricsManager}setMetricsManager(e){this.metricsManager=e,this.getMetrics=this.metricsManager.getMetrics.bind(this.metricsManager)}getComponentManager(){return this.componentManager}getRenderer(){return this.renderer}getThemeManager(){return this.themeManager_}getTheme(){return this.themeManager_.getTheme()}setTheme(e){e||=Cd,this.themeManager_.setTheme(e)}refreshTheme(){if(this.svgGroup_){var e=this.options.parentWorkspace===null;this.renderer.refreshDom(this.svgGroup_,this.getTheme(),e?this.getInjectionDiv():void 0)}this.updateBlockStyles(this.getAllBlocks(!1).filter(e=>!!e.getStyleName())),this.refreshToolboxSelection(),this.toolbox&&this.toolbox.refreshTheme(),this.isVisible()&&this.setVisible(!0),e=new(x(E.THEME_CHANGE))(this.getTheme().name,this.id),b(e)}updateBlockStyles(e){for(let t=0,n;n=e[t];t++){let e=n.getStyleName();e&&n.setStyle(e)}}getInverseScreenCTM(){if(this.inverseScreenCTMDirty){let e=this.getParentSvg().getScreenCTM();e&&(this.inverseScreenCTM=e.inverse(),this.inverseScreenCTMDirty=!1)}return this.inverseScreenCTM}updateInverseScreenCTM(){this.inverseScreenCTMDirty=!0}isVisible(){return this.visible}getSvgXY(e){var t=0,n=0,r=1;(this.getCanvas().contains(e)||this.getBubbleCanvas().contains(e))&&(r=this.scale);do{let i=it(e);(e===this.getCanvas()||e===this.getBubbleCanvas())&&(r=1),t+=i.x*r,n+=i.y*r,e=e.parentNode}while(e&&e!==this.getParentSvg()&&e!==this.getInjectionDiv());return new N(t,n)}getCachedParentSvgSize(){var e=this.cachedParentSvgSize;return new F(e.width,e.height)}getOriginOffsetInPixels(){return at(this.getCanvas())}getInjectionDiv(){if(!this.injectionDiv){let e=this.svgGroup_;for(;e;){if((` `+(e.getAttribute(`class`)||``)+` `).includes(` injectionDiv `)){this.injectionDiv=e;break}e=e.parentNode}}return this.injectionDiv}getSvgGroup(){return this.svgGroup_}getBlockCanvas(){return this.getCanvas()}setResizeHandlerWrapper(e){this.resizeHandlerWrapper=e}setInitialAriaContext(){if(!this.svgGroup_)throw Error("Must initialize svgGroup_ by calling `createDom` before calling setAriaContext");this.isFlyout||(p(this.svgGroup_,O.REGION),this.isMutator?m(this.svgGroup_,k.LABEL,e.C.WORKSPACE_LABEL_MUTATOR_WORKSPACE):(m(this.svgGroup_,k.LABEL,e.C.WORKSPACE_LABEL_PLAIN),this.workspaceFocusTargetElement&&(p(this.workspaceFocusTargetElement,O.FIGURE),m(this.workspaceFocusTargetElement,k.ROLEDESCRIPTION,e.C.WORKSPACE_ROLEDESCRIPTION),this.updateAriaLabel())))}updateAriaLabel(){if(this.workspaceFocusTargetElement){var t=this.getTopBlocks(!1).length;t==1?m(this.workspaceFocusTargetElement,k.LABEL,e.C.WORKSPACE_LABEL_1_STACK):m(this.workspaceFocusTargetElement,k.LABEL,e.C.WORKSPACE_LABEL_MANY_STACKS.replace(`%1`,String(t)))}}createDom(t,n){return this.injectionDiv||=n??null,this.svgGroup_=h(A.G,{class:`blocklyWorkspace`,id:this.id}),t&&(this.svgBackground_=h(A.RECT,{height:`100%`,width:`100%`,class:t},this.svgGroup_),t===`blocklyMainBackground`&&this.grid?this.svgBackground_.style.fill=`var(--blocklyGridPattern)`:this.themeManager_.subscribe(this.svgBackground_,`workspaceBackgroundColour`,`fill`)),this.workspaceSelectionRing=t=h(A.RECT,{fill:`none`,class:`blocklyWorkspaceSelectionRing`},this.svgGroup_),this.workspaceFocusRing=h(A.RECT,{fill:`none`,class:`blocklyWorkspaceFocusRing`},this.svgGroup_),this.isFlyout||this.isMutator||(t.id=`${this.id}_focusTarget`,this.workspaceFocusTargetElement=t,this.workspaceFocusTarget=new jp(this,t)),this.layerManager=new Kf(this),this.svgBlockCanvas_=this.layerManager.getBlockLayer(),this.svgBubbleCanvas_=this.layerManager.getBubbleLayer(),this.setInitialAriaContext(),this.isFlyout||(o(this.svgGroup_,`pointerdown`,this,this.onMouseDown,!1),this.dummyWheelListener=()=>{},document.body.addEventListener(`wheel`,this.dummyWheelListener,{passive:!0}),o(this.svgGroup_,`wheel`,this,this.onMouseWheel,!1,{passive:!1})),this.options.hasCategories&&(this.toolbox=new(Ve(M.TOOLBOX,this.options,!0))(this)),this.grid&&this.grid.update(this.scale),this.recordDragTargets(),t=this.options.parentWorkspace===null,this.renderer.createDom(this.svgGroup_,this.getTheme(),t?this.getInjectionDiv():void 0),e.t().registerTree(this,!!this.injectionDiv||this.isFlyout),this.svgGroup_}dispose(){if(this.rendered=!1,this.currentGesture_&&this.currentGesture_.cancel(),this.svgGroup_&&v(this.svgGroup_),this.toolbox&&=(this.toolbox.dispose(),null),this.flyout&&=(this.flyout.dispose(),null),this.trashcan&&=(this.trashcan.dispose(),null),this.scrollbar&&=(this.scrollbar.dispose(),null),this.zoomControls_&&this.zoomControls_.dispose(),this.audioManager&&this.audioManager.dispose(),this.grid&&=null,this.renderer.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){let e=this.getParentSvg();e&&e.parentNode&&v(e.parentNode)}this.resizeHandlerWrapper&&=(c(this.resizeHandlerWrapper),null),this.dummyWheelListener&&=(document.body.removeEventListener(`wheel`,this.dummyWheelListener),null);var t;(t=this.workspaceFocusRing)==null||t.remove();var n;(n=this.workspaceSelectionRing)==null||n.remove(),e.t().isRegistered(this)&&e.t().unregisterTree(this)}addTrashcan(){this.trashcan=Mp.newTrashcan(this);var e=this.trashcan.createDom();this.svgGroup_.insertBefore(e,this.getCanvas())}static newTrashcan(){throw Error(`The implementation of newTrashcan should be monkey-patched in by blockly.ts`)}addZoomControls(){this.zoomControls_=new _c(this);var e=this.zoomControls_.createDom();this.svgGroup_.appendChild(e)}copyOptionsForFlyout(){return new wd({parentWorkspace:this,rtl:this.RTL,oneBasedIndex:this.options.oneBasedIndex,horizontalLayout:this.horizontalLayout,renderer:this.options.renderer,rendererOverrides:this.options.rendererOverrides,plugins:this.options.plugins,modalInputs:this.options.modalInputs,move:{scrollbars:!0}})}addFlyout(e){var t=this.copyOptionsForFlyout();return t.toolboxPosition=this.options.toolboxPosition,this.flyout=this.horizontalLayout?new(Ve(M.FLYOUTS_HORIZONTAL_TOOLBOX,this.options,!0))(t):new(Ve(M.FLYOUTS_VERTICAL_TOOLBOX,this.options,!0))(t),this.flyout.autoClose=!1,this.flyout.getWorkspace().setVisible(!0),this.flyout.createDom(e)}getFlyout(e){return this.flyout||e?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();var e=this.componentManager.getComponents(T.Capability.POSITIONABLE,!0),t=this.getMetricsManager().getUiMetrics(),n=[];for(let r=0,i;i=e[r];r++){i.position(t,n);let e=i.getBoundingRectangle();e&&n.push(e)}this.scrollbar&&this.scrollbar.resize(),this.updateScreenCalculations(),this.workspaceFocusRing&&this.workspaceSelectionRing&&(this.resizeWorkspaceRing(this.workspaceSelectionRing,5),this.resizeWorkspaceRing(this.workspaceFocusRing,0))}resizeWorkspaceRing(e,t){var n=this.getMetrics();e.setAttribute(`x`,`${n.absoluteLeft+t}`),e.setAttribute(`y`,`${n.absoluteTop+t}`),e.setAttribute(`width`,`${Math.max(0,n.viewWidth-t*2)}`),e.setAttribute(`height`,`${Math.max(0,n.svgHeight-t*2)}`)}updateScreenCalculationsIfScrolled(){var e=st();N.equals(this.lastRecordedPageScroll,e)||(this.lastRecordedPageScroll=e,this.updateScreenCalculations())}getLayerManager(){return this.layerManager}getCanvas(){return this.layerManager.getBlockLayer()}setCachedParentSvgSize(e,t){var n=this.getParentSvg();e!=null&&(this.cachedParentSvgSize.width=e,n.setAttribute(`data-cached-width`,`${e}`)),t!=null&&(this.cachedParentSvgSize.height=t,n.setAttribute(`data-cached-height`,`${t}`))}getBubbleCanvas(){return this.layerManager.getBubbleLayer()}getParentSvg(){if(!this.cachedParentSvg){let e=this.svgGroup_;for(;e;){if(e.tagName===`svg`){this.cachedParentSvg=e;break}e=e.parentNode}}return this.cachedParentSvg}maybeFireViewportChangeEvent(){if(Je()){var e=this.scale,t=-this.scrollY,n=-this.scrollX;if(!(e===this.oldScale&&Math.abs(t-this.oldTop)<1&&Math.abs(n-this.oldLeft)<1)){var r=new(x(E.VIEWPORT_CHANGE))(t,n,e,this.id,this.oldScale);this.oldScale=e,this.oldTop=t,this.oldLeft=n,b(r)}}}translate(e,t){var n;(n=this.layerManager)==null||n.translateLayers(new N(e,t),this.scale);var r;(r=this.grid)==null||r.moveTo(e,t),this.maybeFireViewportChangeEvent()}getWidth(){var e=this.getMetrics();return e?e.viewWidth/this.scale:0}setVisible(e){this.visible=e,this.svgGroup_&&(this.scrollbar&&this.scrollbar.setContainerVisible(e),this.getFlyout()&&this.getFlyout().setContainerVisible(e),this.getParentSvg().style.display=e?`block`:`none`,this.toolbox&&this.toolbox.setVisible(e),e||this.hideChaff(!0))}render(){var e=this.getAllBlocks(!1);for(let t=e.length-1;t>=0;t--)e[t].queueRender();this.getTopBlocks().flatMap(e=>e.getDescendants(!1)).filter(e=>e.isInsertionMarker()).forEach(e=>e.queueRender())}highlightBlock(e,t){if(t===void 0){for(let e=0,t;t=this.highlightedBlocks[e];e++)t.setHighlighted(!1);this.highlightedBlocks.length=0}(e=e?this.getBlockById(e):null)&&((t=t===void 0||t)?this.highlightedBlocks.includes(e)||this.highlightedBlocks.push(e):f(this.highlightedBlocks,e),e.setHighlighted(t))}variableChangeCallback(e){switch(e.type){case E.VAR_CREATE:case E.VAR_DELETE:case E.VAR_RENAME:case E.VAR_TYPE_CHANGE:this.refreshToolboxSelection()}}refreshToolboxSelection(){var e=this.isFlyout?this.targetWorkspace:this;e&&!e.currentGesture_&&e.toolbox&&e.toolbox.getFlyout()&&e.toolbox.refreshSelection()}recordDragTargets(){var e=this.componentManager.getComponents(T.Capability.DRAG_TARGET,!0);this.dragTargetAreas=[];for(let t=0,n;n=e[t];t++){let e=n.getClientRect();e&&this.dragTargetAreas.push({component:n,clientRect:e})}}newBlock(){throw Error(`The implementation of newBlock should be monkey-patched in by blockly.ts`)}newComment(){throw Error(`The implementation of newComment should be monkey-patched in by blockly.ts`)}getDragTarget(e){e=e instanceof N?e:new N(e.clientX,e.clientY);for(let t=0,n;n=this.dragTargetAreas[t];t++)if(n.clientRect.contains(e.x,e.y))return n.component;return null}onMouseDown(e){var t=this.getGesture(e);t&&t.handleWsStart(e,this)}startDrag(e,t){Jr(this,e,t)}moveDrag(e){return Yr(this,e)}isDragging(){return G.mover.isMoving()||this.currentGesture_!==null&&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(){var e=!!this.scrollbar;return this.isMovable()&&(!e||e&&this.scrollbar.canScrollHorizontally())}isMovableVertically(){var e=!!this.scrollbar;return this.isMovable()&&(!e||e&&this.scrollbar.canScrollVertically())}onMouseWheel(e){if(Wf.inProgress())e.preventDefault(),e.stopPropagation();else{var t=this.options.zoomOptions&&this.options.zoomOptions.wheel,n=this.options.moveOptions&&this.options.moveOptions.wheel;if(t||n){var r=ee(e);if(zo)var i=e.metaKey;t&&(e.ctrlKey||i||!n)?(r=-r.y/50,t=d(e,this.getParentSvg(),this.getInverseScreenCTM()),this.zoom(t.x,t.y,r)):(t=this.scrollX-r.x,n=this.scrollY-r.y,e.shiftKey&&!r.x&&(t=this.scrollX-r.y,n=this.scrollY),this.scroll(t,n)),e.preventDefault()}}}getBlocksBoundingBox(){var e=this.getTopBoundedElements();if(!e.length)return new P(0,0,0,0);var t=e[0].getBoundingRectangle();for(let r=1;r<e.length;r++){var n=e[r];n.isInsertionMarker&&n.isInsertionMarker()||(n=n.getBoundingRectangle(),n.top<t.top&&(t.top=n.top),n.bottom>t.bottom&&(t.bottom=n.bottom),n.left<t.left&&(t.left=n.left),n.right>t.right&&(t.right=n.right))}return t}cleanUp(){function t(e){for(let t of a)if(e.intersects(t))return t;return null}this.setResizesEnabled(!1);var n=e.gd;n||e.B(!0);var r=this.getTopBlocks(!0),i=r.filter(e=>e.isMovable()),a=r.filter(e=>!e.isMovable()).map(e=>e.getBoundingRectangle()),o=0;r=this.renderer.getConstants().MIN_BLOCK_HEIGHT;for(let e of i){for(i=e.getBoundingRectangle(),e.moveBy(-i.left,o-i.top,[`cleanup`]),e.snapToGrid(),i=e.getBoundingRectangle(),o=t(i);o!=null;)o=o.top+o.getHeight()+r,e.moveBy(0,o-i.top,[`cleanup`]),e.snapToGrid(),i=e.getBoundingRectangle(),o=t(i);o=e.getRelativeToSurfaceXY().y+e.getHeightWidth().height+r}e.B(n),this.setResizesEnabled(!0)}showContextMenu(e){if(!this.isReadOnly()&&!this.isFlyout){var t=H.registry.getContextMenuOptions({workspace:this,focusedNode:this},e);if(this.configureContextMenu&&this.configureContextMenu(t,e),e instanceof PointerEvent)var n=new N(e.clientX,e.clientY);else n=this.RTL?this.getWidth()-5:5,n=lt(this,new N(n,5));Br(e,t,this.RTL,this,n)}}updateToolbox(e){if(e=ft(e)){if(!this.options.languageTree)throw Error(`Existing toolbox is null. Can't create new toolbox.`);if(mt(e)){if(!this.toolbox)throw Error(`Existing toolbox has no categories. Can't change mode.`);this.options.languageTree=e,this.toolbox.render(e)}else{if(!this.flyout)throw Error(`Existing toolbox has categories. Can't change mode.`);this.options.languageTree=e,this.flyout.show(e)}}else if(this.options.languageTree)throw Error(`Can't nullify an existing toolbox.`)}markFocused(){this.options.parentWorkspace?this.options.parentWorkspace.markFocused():(Ee(this),this.getParentSvg().focus({preventScroll:!0}))}zoom(e,t,n){n=this.options.zoomOptions.scaleSpeed**+n;var r=this.scale*n;if(this.scale!==r){r>this.options.zoomOptions.maxScale?n=this.options.zoomOptions.maxScale/this.scale:r<this.options.zoomOptions.minScale&&(n=this.options.zoomOptions.minScale/this.scale);var i=this.getCanvas().getCTM(),a=this.getParentSvg().createSVGPoint();a.x=e,a.y=t,a=a.matrixTransform(i.inverse()),e=a.x,t=a.y,i=i.translate(e*(1-n),t*(1-n)).scale(n),this.scrollX=i.e,this.scrollY=i.f,this.setScale(r)}}zoomCenter(e){var t=this.getMetrics();if(this.flyout){var n=t.svgWidth?t.svgWidth/2:0;t=t.svgHeight?t.svgHeight/2:0}else n=t.viewWidth/2+t.absoluteLeft,t=t.viewHeight/2+t.absoluteTop;this.zoom(n,t,e)}zoomToFit(){if(this.isMovable()){var t=this.getMetrics(),n=t.viewWidth;t=t.viewHeight;var r=this.getBlocksBoundingBox(),i=r.right-r.left+40;if(r=r.bottom-r.top+40,i){this.flyout&&(this.horizontalLayout?(t+=this.flyout.getHeight(),r+=this.flyout.getHeight()/this.scale):(n+=this.flyout.getWidth(),i+=this.flyout.getWidth()/this.scale)),e.Ub++;try{this.setScale(Math.min(n/i,t/r)),this.scrollCenter()}finally{e.Ub--}this.maybeFireViewportChangeEvent()}}else console.warn(`Tried to move a non-movable workspace. This could result in blocks becoming inaccessible.`)}beginCanvasTransition(){g(this.getCanvas(),`blocklyCanvasTransitioning`),g(this.getBubbleCanvas(),`blocklyCanvasTransitioning`)}endCanvasTransition(){_(this.getCanvas(),`blocklyCanvasTransitioning`),_(this.getBubbleCanvas(),`blocklyCanvasTransitioning`)}scrollCenter(){if(this.isMovable()){var e=this.getMetrics(),t=(e.scrollWidth-e.viewWidth)/2,n=(e.scrollHeight-e.viewHeight)/2;t=-t-e.scrollLeft,n=-n-e.scrollTop,this.scroll(t,n)}else console.warn(`Tried to move a non-movable workspace. This could result in blocks becoming inaccessible.`)}centerOnBlock(e,t){if(this.isMovable()){var n=e?this.getBlockById(e):null;if(n){e=n.getRelativeToSurfaceXY(),n=t?{height:n.height,width:n.width}:n.getHeightWidth();var r=this.scale;t=(e.x+(this.RTL?-1:1)*n.width/2)*r,e=(e.y+n.height/2)*r,n=this.getMetrics(),this.scroll(-(t-n.viewWidth/2),-(e-n.viewHeight/2))}}else console.warn(`Tried to move a non-movable workspace. This could result in blocks becoming inaccessible.`)}setScale(e){this.options.zoomOptions.maxScale&&e>this.options.zoomOptions.maxScale?e=this.options.zoomOptions.maxScale:this.options.zoomOptions.minScale&&e<this.options.zoomOptions.minScale&&(e=this.options.zoomOptions.minScale),this.scale=e,this.hideChaff(!1),(e=this.getFlyout(!1))&&e.isVisible()&&(e.reflow(),this.recordDragTargets()),this.grid&&this.grid.update(this.scale),e=this.getMetrics(),this.scrollX-=e.absoluteLeft,this.scrollY-=e.absoluteTop,e.viewLeft+=e.absoluteLeft,e.viewTop+=e.absoluteTop,this.scroll(this.scrollX,this.scrollY),this.scrollbar&&(this.flyout?this.scrollbar.resizeView(e):this.scrollbar.resizeContent(e))}getScale(){return this.scale}getAbsoluteScale(){var e=e=>{if(e.isFlyout){let t,n=(t=e.targetWorkspace)==null?void 0:t.getFlyout();if(n instanceof Hf)return n.getFlyoutScale()}return e.getScale()},t=(n,r)=>n.options.parentWorkspace&&n.options.parentWorkspace.getSvgGroup().contains(n.getSvgGroup())?t(n.options.parentWorkspace,r*e(n)):r*e(n);return t(this,1)}scroll(e,t){this.hideChaff(!0);var n=this.getMetrics();e=Math.min(e,-n.scrollLeft),t=Math.min(t,-n.scrollTop);var r=n.scrollTop+Math.max(0,n.scrollHeight-n.viewHeight);e=Math.max(e,-(n.scrollLeft+Math.max(0,n.scrollWidth-n.viewWidth))),t=Math.max(t,-r),this.scrollX=e,this.scrollY=t,this.scrollbar&&this.scrollbar.set(-(e+n.scrollLeft),-(t+n.scrollTop),!1),e+=n.absoluteLeft,t+=n.absoluteTop,this.translate(e,t)}getBlockById(e){return super.getBlockById(e)}getAllBlocks(e=!1){return super.getAllBlocks(e)}getTopBlocks(e=!1){return super.getTopBlocks(e)}addTopBlock(e){this.addTopBoundedElement(e),super.addTopBlock(e)}removeTopBlock(e){this.removeTopBoundedElement(e),super.removeTopBlock(e)}addTopComment(e){this.addTopBoundedElement(e),super.addTopComment(e)}removeTopComment(e){this.removeTopBoundedElement(e),super.removeTopComment(e)}getTopComments(e=!1){return super.getTopComments(e)}getCommentById(e){return super.getCommentById(e)}getRootWorkspace(){return super.getRootWorkspace()}addTopBoundedElement(e){this.topBoundedElements.push(e)}removeTopBoundedElement(e){f(this.topBoundedElements,e)}getTopBoundedElements(e=!1){var t=[].concat(this.topBoundedElements);return e&&t.sort(this.sortByOrigin.bind(this)),t}setResizesEnabled(e){var t=!this.resizesEnabled&&e;this.resizesEnabled=e,t&&this.resizeContents()}clear(){this.setResizesEnabled(!1),super.clear(),this.topBoundedElements=[],this.setResizesEnabled(!0)}registerButtonCallback(e,t){if(typeof t!=`function`)throw TypeError(`Button callbacks must be functions.`);this.flyoutButtonCallbacks.set(e,t)}getButtonCallback(e){return this.flyoutButtonCallbacks.get(e)??null}removeButtonCallback(e){this.flyoutButtonCallbacks.delete(e)}registerToolboxCategoryCallback(e,t){if(typeof t!=`function`)throw TypeError(`Toolbox category callbacks must be functions.`);this.toolboxCategoryCallbacks.set(e,t)}getToolboxCategoryCallback(e){return this.toolboxCategoryCallbacks.get(e)||null}removeToolboxCategoryCallback(e){this.toolboxCategoryCallbacks.delete(e)}getGesture(e){if(G.mover.isMoving())return e==null||e.preventDefault(),e==null||e.stopPropagation(),null;var t=(e==null?void 0:e.type)===`pointerdown`,n;return t&&(n=this.currentGesture_)!=null&&n.hasStarted()&&(console.warn(`Tried to start the same gesture twice.`),this.currentGesture_.cancel()),!this.currentGesture_&&t&&(this.currentGesture_=new Wf(e,this)),this.currentGesture_}clearGesture(){this.currentGesture_=null}cancelCurrentGesture(){this.currentGesture_&&this.currentGesture_.cancel()}getAudioManager(){return this.audioManager}getGrid(){return this.grid}hideChaff(e=!1){_r(),Ir(this),er(),this.hideComponents(e)}hideComponents(e=!1){this.getComponentManager().getComponents(T.Capability.AUTOHIDEABLE,!0).forEach(t=>t.autoHide(e))}static setTopLevelWorkspaceMetrics(e){var t=this.getMetrics();typeof e.x==`number`&&(this.scrollX=-(t.scrollLeft+(t.scrollWidth-t.viewWidth)*e.x)),typeof e.y==`number`&&(this.scrollY=-(t.scrollTop+(t.scrollHeight-t.viewHeight)*e.y)),this.translate(this.scrollX+t.absoluteLeft,this.scrollY+t.absoluteTop)}addClass(e){this.injectionDiv&&g(this.injectionDiv,e)}removeClass(e){this.injectionDiv&&_(this.injectionDiv,e)}setIsReadOnly(e){super.setIsReadOnly(e),e?this.addClass(`blocklyReadOnly`):this.removeClass(`blocklyReadOnly`)}scrollBoundsIntoView(e,t=10){if(!Wf.inProgress()){var n=this.getScale(),r=this.getMetricsManager().getViewMetrics(!0);if(r=new P(r.top,r.top+r.height,r.left,r.left+r.width),!(e.left>=r.left&&e.top>=r.top&&e.right<=r.right&&e.bottom<=r.bottom)){e=e.clone(),e.top-=t,e.bottom+=t,e.left-=t,e.right+=t;var i=t=0;e.left<r.left?t=this.RTL?Math.min(r.left-e.left,r.right-e.right):r.left-e.left:e.right>r.right&&(t=this.RTL?r.right-e.right:Math.max(r.right-e.right,r.left-e.left)),e.top<r.top?i=r.top-e.top:e.bottom>r.bottom&&(i=Math.max(r.bottom-e.bottom,r.top-e.top)),this.scroll(this.scrollX+t*n,this.scrollY+i*n)}}}getFocusableElement(){return this.svgGroup_}getFocusableTree(){return this}onNodeFocus(){this.maybeAnnounceScreenreaderHint()}handleWorkspaceFocusTargetFocus(){this.updateAriaLabel(),this.maybeAnnounceScreenreaderHint()}maybeAnnounceScreenreaderHint(){Mp.everFocused||this.options.parentWorkspace||(se(e.C.SCREENREADER_HINT.replace(`%1`,vn(J.TOGGLE_SCREENREADER))),Mp.everFocused=!0)}onNodeBlur(){}canBeFocused(){return!0}getRootFocusableNode(){return this}getRestoredFocusableNode(e){if(e)return e;var t;if(e=(t=this.targetWorkspace)==null?void 0:t.getFlyout(),this.isFlyout&&e){let t;return((t=e.getContents().find(e=>(e=e.getElement(),_e(e)&&e.canBeFocused())))==null?void 0:t.getElement())??null}return this.isMutator?this.getTopBlocks(!0)[0]??null:this.workspaceFocusTarget}getWorkspaceFocusTarget(){return this.workspaceFocusTarget}getNestedTrees(){var t=this.getAllBlocks().map(e=>e.getIcons()).flat().filter(t=>t instanceof e.sh&&t.bubbleIsVisible()).map(e=>{var t;return(t=e.getBubble())==null?void 0:t.getWorkspace()}).filter(e=>!!e),n=this.getFlyout(!0);return n&&t.push(n.getWorkspace()),t}searchForWorkspaceComment(e){for(let t of this.getTopComments())if(t instanceof md&&t.canBeFocused()&&t.getFocusableElement().id===e)return t}lookUpFocusableNode(e){if(this.workspaceFocusTargetElement&&this.workspaceFocusTargetElement.id===e)return this.workspaceFocusTarget;var t,n=(t=this.targetWorkspace)==null?void 0:t.getFlyout();if(this.isFlyout&&n){for(var r of n.getContents())if(t=r.getElement(),_e(t)&&t.canBeFocused()&&t.getFocusableElement().id===e)return t}if(r=e.indexOf(`_field_`),t=e.indexOf(`_connection_`),r!==-1){var i=e.substring(0,r);if(i=this.getBlockById(i)){for(var a of i.getFields())if(a.canBeFocused()&&a.getFocusableElement().id===e)return a}return null}if(t!==-1){if(i=e.substring(0,t),i=this.getBlockById(i)){for(let t of i.getConnections_(!0))if(t.id===e)return t}return null}if(a=Math.max(e.indexOf(`_comment_textarea_`),e.indexOf(`_collapse_bar_button`),e.indexOf(`_delete_bar_button`)),a!==-1&&(a=e.substring(0,a),a=this.searchForWorkspaceComment(a))){if(e.indexOf(`_comment_textarea_`)>-1)return a.getEditorFocusableNode();var o;return(o=a.view.getCommentBarButtons().find(t=>t.getFocusableElement().id.includes(e)))??null}if((o=this.getAllBlocks(!1).find(t=>t.getFocusableElement().id===e))||(o=this.searchForWorkspaceComment(e)))return o;o=this.getAllBlocks().map(e=>e.getIcons()).flat();for(var s of o){if(s.canBeFocused()&&s.getFocusableElement().id===e)return s;if(Wt(s)){if((o=s.getBubble())&&o.canBeFocused()&&o.getFocusableElement().id===e)return o;if(o instanceof Pd&&o.getEditor().getFocusableElement().id===e)return o.getEditor()}}s=this.getComponentManager().getComponents(T.Capability.FOCUSABLE,!1);for(i of s)if(i.getFocusableElement().getAttribute(`id`)===e)return i;return null}onTreeFocus(){this.updateAriaLabel()}onTreeBlur(t){if(this.isFlyout&&this.targetWorkspace&&!e.t().ephemeralFocusTaken()){var n=this.targetWorkspace.getToolbox();n&&t===n||n&&typeof n.autoHide==`function`&&n.autoHide(!1)}}performAction(){Pc.show(this,{message:e.C.KEYBOARD_NAV_WORKSPACE_NAVIGATION_HINT,id:`workspaceNavigationHint`})}getNavigator(){return this.navigator}setNavigator(e){this.navigator=e}};Mp.everFocused=!1;var Np=class{constructor(e,t,n,r){this.workspace=e,this.name=t,this.type=n||``,this.id=r||Ue()}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this}getType(){return this.type}setType(e){return this.type=e,this}getWorkspace(){return this.workspace}save(){var e={name:this.getName(),id:this.getId()},t=this.getType();return t&&(e.type=t),e}static load(e,t){e=new this(t,e.name,e.type,e.id),t.getVariableMap().addVariable(e),b(new(x(E.VAR_CREATE))(e))}};y(M.VARIABLE_MODEL,`default`,Np);var Pp=class{constructor(e,t=!1){this.workspace=e,this.potentialMap=t,this.variableMap=new Map}clear(){for(let e of this.variableMap.values())for(let t of e.values())this.deleteVariable(t);if(this.variableMap.size!==0)throw Error(`Non-empty variable map`)}renameVariable(t,n){if(t.getName()===n)return t;var r=t.getType();r=this.getVariable(n,r);var i=this.workspace.getAllBlocks(!1),a=``;this.potentialMap||(a=e.gd)||e.B(!0);try{r&&r.getId()!==t.getId()?this.renameVariableWithConflict(t,n,r,i):this.renameVariableAndUses(t,n,i)}finally{this.potentialMap||e.B(a)}return t}changeVariableType(e,t){var n=e.getType();if(n===t)return e;var r=this.variableMap.get(n);return r==null||r.delete(e.getId()),(r==null?void 0:r.size)===0&&this.variableMap.delete(n),e.setType(t),r=this.variableMap.get(t)??new Map,r.set(e.getId(),e),this.variableMap.has(t)||this.variableMap.set(t,r),b(new(x(E.VAR_TYPE_CHANGE))(e,n,t)),e}renameVariableAndUses(e,t,n){for(this.potentialMap||b(new(x(E.VAR_RENAME))(e,t)),e.setName(t),t=0;t<n.length;t++)n[t].updateVarName(e)}renameVariableWithConflict(e,t,n,r){var i=e.getType(),a=n.getName();for(t!==a&&this.renameVariableAndUses(n,t,r),t=0;t<r.length;t++)r[t].renameVarById(e.getId(),n.getId());this.potentialMap||b(new(x(E.VAR_DELETE))(e));var o;(o=this.variableMap.get(i))==null||o.delete(e.getId())}createVariable(e,t,n){var r=this.getVariable(e,t);if(r){if(n&&r.getId()!==n)throw Error(`Variable "`+e+`" is already in use and its id is "`+r.getId()+`" which conflicts with the passed in id, "`+n+`".`);return r}if(n&&this.getVariableById(n))throw Error(`Variable id, "`+n+`", is already in use.`);if(r=n||Ue(),t||=``,n=Ve(M.VARIABLE_MODEL,this.workspace.options,!0),!n)throw Error(`No variable model is registered.`);return r=new n(this.workspace,e,t,r),e=this.variableMap.get(t)??new Map,e.set(r.getId(),r),this.variableMap.has(t)||this.variableMap.set(t,e),this.potentialMap||b(new(x(E.VAR_CREATE))(r)),r}addVariable(e){var t=e.getType();this.variableMap.has(t)||this.variableMap.set(t,new Map);var n;(n=this.variableMap.get(t))==null||n.set(e.getId(),e)}deleteVariable(t){var n=un(this.workspace,t.getId()),r=``;this.potentialMap||(r=e.gd)||e.B(!0);try{for(let e=0;e<n.length;e++)n[e].isDeadOrDying()||n[e].dispose(!0);let e=this.variableMap.get(t.getType());e&&e.has(t.getId())&&(e.delete(t.getId()),this.potentialMap||b(new(x(E.VAR_DELETE))(t)),e.size===0&&this.variableMap.delete(t.getType()))}finally{this.potentialMap||e.B(r)}}getVariable(t,n){return n=this.variableMap.get(n||``),n?[...n.values()].find(n=>e.kj.equals(n.getName(),t))??null:null}getVariableById(e){for(let t of this.variableMap.values())if(t.has(e))return t.get(e)??null;return null}getVariablesOfType(e){return(e=this.variableMap.get(e||``))?[...e.values()]:[]}getTypes(){return[...this.variableMap.keys()]}getAllVariables(){var e=[];for(let t of this.variableMap.values())e=e.concat(...t.values());return e}};y(M.VARIABLE_MAP,`default`,Pp);var Fp=class extends vf{constructor(e){super(),this.workspace=e,this.id=`trashcan`,this.uniqueId=He(),this.contents=[],this.flyout=null,this.isLidOpen=!1,this.svgGroup=null,this.top=this.left=0,this.initialized=!1,this.workspace.options.maxTrashcanContents<=0||(e=this.workspace.copyOptionsForFlyout(),this.workspace.horizontalLayout?(e.toolboxPosition=this.workspace.toolboxPosition===I.TOP?I.BOTTOM:I.TOP,this.flyout=new(Ve(M.FLYOUTS_HORIZONTAL_TOOLBOX,this.workspace.options,!0))(e)):(e.toolboxPosition=this.workspace.toolboxPosition===I.RIGHT?I.LEFT:I.RIGHT,this.flyout=new(Ve(M.FLYOUTS_VERTICAL_TOOLBOX,this.workspace.options,!0))(e)),this.workspace.addChangeListener(this.onDelete.bind(this)))}createDom(){this.svgGroup=h(A.G,{class:`blocklyTrash`,tabindex:`0`,id:this.uniqueId}),h(A.RECT,{width:55,height:68,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},this.svgGroup),p(this.svgGroup,O.BUTTON),m(this.svgGroup,k.LABEL,e.C.ARIA_LABEL_TRASH_EMPTY),m(this.svgGroup,k.DISABLED,!0);var t=String(Math.random()).substring(2),n=h(A.CLIPPATH,{id:`blocklyTrashBodyClipPath`+t},this.svgGroup);return h(A.RECT,{width:47,height:44,y:16},n),h(A.IMAGE,{width:fc.width,x:-0,height:fc.height,y:-32,"clip-path":`url(#blocklyTrashBodyClipPath`+t+`)`},this.svgGroup).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.workspace.options.pathToMedia+fc.url),n=h(A.CLIPPATH,{id:`blocklyTrashLidClipPath`+t},this.svgGroup),h(A.RECT,{width:47,height:16},n),n=h(A.G,{class:`blocklyTrashLid`},this.svgGroup),n=h(A.SVG,{viewBox:`0 32 47 16`,width:47,height:16},n),h(A.IMAGE,{width:fc.width,height:fc.height,href:this.workspace.options.pathToMedia+fc.url},n),s(this.svgGroup,`pointerdown`,this,this.blockMouseDownWhenOpenable),s(this.svgGroup,`pointerup`,this,this.click),this.svgGroup}init(){if(this.workspace.options.maxTrashcanContents>0){let e=this.flyout.createDom(A.SVG);g(e,`blocklyTrashcanFlyout`),ue(e,this.workspace.getParentSvg()),this.flyout.init(this.workspace)}this.workspace.getComponentManager().addComponent({component:this,weight:T.ComponentWeight.TRASHCAN_WEIGHT,capabilities:[T.Capability.AUTOHIDEABLE,T.Capability.DELETE_AREA,T.Capability.DRAG_TARGET,T.Capability.POSITIONABLE,T.Capability.FOCUSABLE]}),this.initialized=!0,this.setLidOpen(!1)}dispose(){this.workspace.getComponentManager().removeComponent(`trashcan`),this.svgGroup&&v(this.svgGroup)}hasContents(){return!!this.contents.length}contentsIsOpen(){return!!this.flyout&&this.flyout.isVisible()}openFlyout(){if(!this.contentsIsOpen()){var t=this.contents.map(function(e){return JSON.parse(e)}),n=this.workspace.getParentSvg().style;n.cursor=`wait`,setTimeout(()=>{var r;(r=this.flyout)==null||r.show(t),n.cursor=``;var i;if((i=this.workspace.scrollbar)==null||i.setVisible(!1),z.getIsActive()){let t,n;(r=(n=(t=this.flyout)==null?void 0:t.getWorkspace())==null?void 0:n.getNavigator().getFirstNode())&&e.t().focusNode(r)}},10),this.fireUiEvent(!0)}}closeFlyout(){if(this.contentsIsOpen()){var e;(e=this.flyout)==null||e.hide();var t;(t=this.workspace.scrollbar)==null||t.setVisible(!0),this.fireUiEvent(!1),this.workspace.recordDragTargets()}}autoHide(e){!e&&this.flyout&&this.closeFlyout()}emptyContents(){this.hasContents()&&this.svgGroup&&(this.contents.length=0,this.svgGroup.classList.remove(`blocklyTrashFull`),m(this.svgGroup,k.LABEL,e.C.ARIA_LABEL_TRASH_EMPTY),m(this.svgGroup,k.DISABLED,!0),this.closeFlyout())}position(e,t){if(this.initialized){var n=bt(this.workspace,e);e=yt(n,new F(47,60),20,20,e,this.workspace),t=xt(e,20,n.vertical===ac.TOP?lc.DOWN:lc.UP,t),this.top=t.top,this.left=t.left;var r;(r=this.svgGroup)==null||r.setAttribute(`transform`,`translate(`+this.left+`,`+this.top+`)`);var i;(i=this.flyout)==null||i.position()}}getBoundingRectangle(){return new P(this.top,this.top+44+16,this.left,this.left+47)}getClientRect(){if(!this.svgGroup)return null;var e=this.svgGroup.getBoundingClientRect(),t=e.top+32-10;return e=e.left+0-10,new P(t,t+16+44+20,e,e+47+20)}onDragOver(){G.mover.isMoving()||this.setLidOpen(this.wouldDelete_)}onDragExit(){G.mover.isMoving()||this.setLidOpen(!1)}onDrop(){G.mover.isMoving()||setTimeout(this.setLidOpen.bind(this,!1),100)}setLidOpen(e){if(this.isLidOpen!==e){this.isLidOpen=e;var t;(t=this.svgGroup)==null||t.classList.toggle(`blocklyTrashOpen`,e)}}closeLid(){this.setLidOpen(!1)}click(){this.hasContents()&&!this.workspace.isDragging()&&this.openFlyout()}fireUiEvent(e){e=new(x(E.TRASHCAN_OPEN))(e,this.workspace.id),b(e)}blockMouseDownWhenOpenable(e){!this.contentsIsOpen()&&this.hasContents()&&e.stopPropagation()}onDelete(t){if(!(this.workspace.options.maxTrashcanContents<=0||t.type!==E.BLOCK_DELETE||t.wasShadow)&&this.svgGroup){if(!t.oldJson)throw Error(`Encountered a delete event without proper oldJson`);if(t=JSON.stringify(this.cleanBlockJson(t.oldJson)),!this.contents.includes(t)){for(this.contents.unshift(t);this.contents.length>this.workspace.options.maxTrashcanContents;)this.contents.pop();this.svgGroup.classList.add(`blocklyTrashFull`),m(this.svgGroup,k.LABEL,e.C.OPEN_TRASH),ie(this.svgGroup,k.DISABLED)}}}cleanBlockJson(e){function t(e){if(e){if(delete e.id,delete e.x,delete e.y,delete e.enabled,delete e.disabledReasons,e.icons&&e.icons.comment){var n=e.icons.comment;delete n.height,delete n.width,delete n.pinned}for(var r in n=e.inputs,n){var i=n[r];let e=i.block;i=i.shadow,e&&t(e),i&&t(i)}e.next&&(r=e.next,e=r.block,r=r.shadow,e&&t(e),r&&t(r))}}return e=JSON.parse(JSON.stringify(e)),t(e),Object.assign({},{kind:`BLOCK`},e)}getFocusableElement(){if(!this.svgGroup)throw Error(`Tried to focus uninitialized trashcan`);return this.svgGroup}getFocusableTree(){return this.workspace}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!!this.svgGroup}performAction(){this.click()}};te(`
@@ -898,9 +898,9 @@ Blockly.YourGeneratorName.nameDB_.setVariableMap(workspace.getVariableMap());`),
898
898
  rotate: -45deg;
899
899
  }
900
900
  `);var Ip=class{constructor(e,t){this.procedureModelClass=e,this.parameterModelClass=t,this.priority=75}save(e){return e=e.getProcedureMap().getProcedures().map(e=>Ua(e)),e.length?e:null}load(e,t){var n=t.getProcedureMap();for(let r of e)n.add(Wa(this.procedureModelClass,this.parameterModelClass,r,t))}clear(e){e.getProcedureMap().clear()}},Lp={};Lp.ProcedureSerializer=Ip,Lp.loadProcedure=Wa,Lp.saveProcedure=Ua;var Rp=class{constructor(){this.priority=100}save(e){return e=e.getVariableMap().getAllVariables().map(e=>e.save()),e.length?e:null}load(e,t){var n=Le(M.VARIABLE_MODEL,`default`,void 0);e.forEach(e=>{n==null||n.load(e,t)})}clear(e){e.getVariableMap().clear()}};St(`variables`,new Rp);var zp={};zp.VariableSerializer=Rp;var Bp={blocks:cu,exceptions:ou,priorities:{BLOCKS:50,PROCEDURES:75,VARIABLES:100,WORKSPACE_COMMENTS:25},procedures:Lp,registry:vc,variables:zp,workspaceComments:bc,workspaces:{load:function(t,n,{recordUndo:r=!1}={}){var i=Be(M.SERIALIZER,!0);if(i){i=Object.entries(i).sort((e,t)=>t[1].priority-e[1].priority);var a=e.Qc;e.Qc=r,(r=e.gd)||e.B(!0),fe(),n instanceof Mp&&n.setResizesEnabled(!1);for(let[,e]of i.reverse()){let t;(t=e)==null||t.clear(n)}for(let[e,r]of i.reverse())if(t[e]){let i;(i=r)==null||i.load(t[e],n)}n instanceof Mp&&n.setResizesEnabled(!0),pe(),b(new(x(E.FINISHED_LOADING))(n)),e.B(r),e.Qc=a}},save:function(e){var t=Object.create(null),n=Be(M.SERIALIZER,!0);for(let r in n){let i,a=(i=n[r])==null?void 0:i.save(e);a&&(t[r]=a)}return t}}};`Blockly`in globalThis||(globalThis.Blockly={Msg:Hs});var Vp=class{load(e,t){return e=new af(t.getWorkspace(),t.targetWorkspace,e,!0),e.show(),new yf(e,`label`)}gapForItem(e,t){return t}disposeItem(e){e=e.getElement(),e instanceof af&&e.dispose()}getType(){return`label`}};y(M.FLYOUT_INFLATER,`label`,Vp);var Hp=class{constructor(){this.size=new F(0,0)}getHeightWidth(){return this.size}show(e,t){this.parentConnection=e,this.parentConnection.attachInsertionMarker(this);var n=t.getSourceBlock(),r=new Map;for(var i of n.getConnections_(!1))r.set(i,i.targetConnection),i.targetConnection=null;t.targetConnection=e,n.workspace.getRenderer().render(n),this.partiallyTighten(n,t),this.marker=this.makeMarker(n),i=n.getBoundingRectangleWithoutChildren(),this.size=new F(i.getWidth(),i.getHeight()),i=e.getSourceBlock().getRelativeToSurfaceXY();var a=N.difference(e.getOffsetInBlock(),t.getOffsetInBlock());for(let[e,t]of r.entries())e.targetConnection=t;n.workspace.getRenderer().render(n),this.partiallyTighten(n,t),this.marker.setAttribute(`transform`,`${`translate(${i.x+a.x}, ${i.y+a.y})`} ${n.workspace.RTL?`scale(-1, 1)`:``}`),e.getSourceBlock().queueRender(),jt()}hide(){if(this.parentConnection){var e;(e=this.marker)==null||e.remove(),this.marker=void 0,this.parentConnection.detachInsertionMarker();var t;(t=this.parentConnection)==null||t.getSourceBlock().queueRender(),jt(),this.parentConnection=void 0}}makeMarker(e){var t=h(A.G,{transform:`translate(${e.relativeCoords.x}, ${e.relativeCoords.y})`,class:`blocklyInsertionMarker`});return h(A.PATH,{d:e.pathObject.svgPath.getAttribute(`d`)??``,class:`blocklyPath`},t),e.workspace.getCanvas().appendChild(t),t}partiallyTighten(e,t){for(let n of e.inputList){if(n===t.getParentInput())continue;let e=n.connection;e&&e.tightenEfficiently()}e.nextConnection&&e.nextConnection!==t&&e.nextConnection.tightenEfficiently()}},Up=class extends Sp{constructor(){super(),this.FIELD_TEXT_BASELINE_CENTER=!1,this.DARK_PATH_OFFSET=1,this.MAX_BOTTOM_WIDTH=30,this.STATEMENT_BOTTOM_SPACER=-this.NOTCH_HEIGHT/2}getCSS_(e){return super.getCSS_(e).concat([`${e} .blocklyInsertionMarker>.blocklyPathLight,`,`${e} .blocklyInsertionMarker>.blocklyPathDark {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,`stroke: none;`,`}`])}},Wp=class{constructor(e){this.inlineSteps_=this.steps_=``,this.info_=e,this.RTL_=this.info_.RTL,e=e.getRenderer(),this.constants_=e.getConstants(),this.highlightConstants_=e.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_+`
901
- `+this.inlineSteps_}drawTopCorner(e){this.steps_+=vi(e.xPos,this.info_.startY);for(let t=0,n;n=e.elements[t];t++)Z.isLeftSquareCorner(n)?this.steps_+=this.highlightConstants_.START_POINT:Z.isLeftRoundedCorner(n)?this.steps_+=this.outsideCornerPaths_.topLeft(this.RTL_):Z.isPreviousConnection(n)?this.steps_+=this.notchPaths_.pathLeft:Z.isHat(n)?this.steps_+=this.startPaths_.path(this.RTL_):Z.isSpacer(n)&&n.width!==0&&(this.steps_+=C(`H`,n.xPos+n.width-this.highlightOffset));this.steps_+=C(`H`,e.xPos+e.width-this.highlightOffset)}drawJaggedEdge_(e){this.info_.RTL&&(this.steps_+=this.jaggedTeethPaths_.pathLeft+C(`v`,e.height-this.jaggedTeethPaths_.height-this.highlightOffset))}drawValueInput(e){var t=e.getLastInput();if(this.RTL_){let n=e.height-t.connectionHeight;this.steps_+=_i(t.xPos+t.width-this.highlightOffset,e.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)+C(`v`,n)}else this.steps_+=_i(t.xPos+t.width,e.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)}drawStatementInput(e){var t=e.getLastInput();if(t)if(this.RTL_){let n=e.height-2*this.insideCornerPaths_.height;this.steps_+=_i(t.xPos,e.yPos)+this.insideCornerPaths_.pathTop(this.RTL_)+C(`v`,n)+this.insideCornerPaths_.pathBottom(this.RTL_)+yi(e.width-t.xPos-this.insideCornerPaths_.width,0)}else this.steps_+=_i(t.xPos,e.yPos+e.height)+this.insideCornerPaths_.pathBottom(this.RTL_)+yi(e.width-t.xPos-this.insideCornerPaths_.width,0)}drawRightSideRow(e){var t=e.xPos+e.width-this.highlightOffset;e instanceof _p&&e.followsStatement&&(this.steps_+=C(`H`,t)),this.RTL_&&(this.steps_+=C(`H`,t),e.height>this.highlightOffset&&(this.steps_+=C(`V`,e.yPos+e.height-this.highlightOffset)))}drawBottomRow(e){if(this.RTL_)this.steps_+=C(`V`,e.baseline-this.highlightOffset);else{let t=this.info_.bottomRow.elements[0];Z.isLeftSquareCorner(t)?this.steps_+=_i(e.xPos+this.highlightOffset,e.baseline-this.highlightOffset):Z.isLeftRoundedCorner(t)&&(this.steps_+=_i(e.xPos,e.baseline),this.steps_+=this.outsideCornerPaths_.bottomLeft())}}drawLeft(){var e=this.info_.outputConnection;e&&(e=e.connectionOffsetY+e.height,this.RTL_?this.steps_+=_i(this.info_.startX,e):(this.steps_+=_i(this.info_.startX+this.highlightOffset,this.info_.bottomRow.baseline-this.highlightOffset),this.steps_+=C(`V`,e)),this.steps_+=this.puzzleTabPaths_.pathUp(this.RTL_)),this.RTL_||(e=this.info_.topRow,Z.isLeftRoundedCorner(e.elements[0])?this.steps_+=C(`V`,this.outsideCornerPaths_.height):this.steps_+=C(`V`,e.capline+this.highlightOffset))}drawInlineInput(e){var t=this.highlightOffset,n=e.xPos+e.connectionWidth,r=e.centerline-e.height/2,i=e.width-e.connectionWidth,a=r+t;this.RTL_?(r=e.connectionOffsetY-t,e=e.height-(e.connectionOffsetY+e.connectionHeight)+t,this.inlineSteps_+=_i(n-t,a)+C(`v`,r)+this.puzzleTabPaths_.pathDown(this.RTL_)+C(`v`,e)+C(`h`,i)):this.inlineSteps_+=_i(e.xPos+e.width+t,a)+C(`v`,e.height)+C(`h`,-i)+_i(n,r+e.connectionOffsetY)+this.puzzleTabPaths_.pathDown(this.RTL_)}},Gp=class extends Cp{constructor(e,t){super(e,t),this.highlighter_=new Wp(t)}draw(){this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights();var e=this.block_.pathObject;e.setPath(this.outlinePath_+`
901
+ `+this.inlineSteps_}drawTopCorner(e){this.steps_+=vi(e.xPos,this.info_.startY);for(let t=0,n;n=e.elements[t];t++)Z.isLeftSquareCorner(n)?this.steps_+=this.highlightConstants_.START_POINT:Z.isLeftRoundedCorner(n)?this.steps_+=this.outsideCornerPaths_.topLeft(this.RTL_):Z.isPreviousConnection(n)?this.steps_+=this.notchPaths_.pathLeft:Z.isHat(n)?this.steps_+=this.startPaths_.path(this.RTL_):Z.isSpacer(n)&&n.width!==0&&(this.steps_+=C(`H`,n.xPos+n.width-this.highlightOffset));this.steps_+=C(`H`,e.xPos+e.width-this.highlightOffset)}drawJaggedEdge_(e){this.info_.RTL&&(this.steps_+=this.jaggedTeethPaths_.pathLeft+C(`v`,e.height-this.jaggedTeethPaths_.height-this.highlightOffset))}drawValueInput(e){var t=e.getLastInput();if(this.RTL_){let n=e.height-t.connectionHeight;this.steps_+=_i(t.xPos+t.width-this.highlightOffset,e.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)+C(`v`,n)}else this.steps_+=_i(t.xPos+t.width,e.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)}drawStatementInput(e){var t=e.getLastInput();if(t){if(this.RTL_){let n=e.height-2*this.insideCornerPaths_.height;this.steps_+=_i(t.xPos,e.yPos)+this.insideCornerPaths_.pathTop(this.RTL_)+C(`v`,n)+this.insideCornerPaths_.pathBottom(this.RTL_)+yi(e.width-t.xPos-this.insideCornerPaths_.width,0)}else this.steps_+=_i(t.xPos,e.yPos+e.height)+this.insideCornerPaths_.pathBottom(this.RTL_)+yi(e.width-t.xPos-this.insideCornerPaths_.width,0)}}drawRightSideRow(e){var t=e.xPos+e.width-this.highlightOffset;e instanceof _p&&e.followsStatement&&(this.steps_+=C(`H`,t)),this.RTL_&&(this.steps_+=C(`H`,t),e.height>this.highlightOffset&&(this.steps_+=C(`V`,e.yPos+e.height-this.highlightOffset)))}drawBottomRow(e){if(this.RTL_)this.steps_+=C(`V`,e.baseline-this.highlightOffset);else{let t=this.info_.bottomRow.elements[0];Z.isLeftSquareCorner(t)?this.steps_+=_i(e.xPos+this.highlightOffset,e.baseline-this.highlightOffset):Z.isLeftRoundedCorner(t)&&(this.steps_+=_i(e.xPos,e.baseline),this.steps_+=this.outsideCornerPaths_.bottomLeft())}}drawLeft(){var e=this.info_.outputConnection;e&&(e=e.connectionOffsetY+e.height,this.RTL_?this.steps_+=_i(this.info_.startX,e):(this.steps_+=_i(this.info_.startX+this.highlightOffset,this.info_.bottomRow.baseline-this.highlightOffset),this.steps_+=C(`V`,e)),this.steps_+=this.puzzleTabPaths_.pathUp(this.RTL_)),this.RTL_||(e=this.info_.topRow,Z.isLeftRoundedCorner(e.elements[0])?this.steps_+=C(`V`,this.outsideCornerPaths_.height):this.steps_+=C(`V`,e.capline+this.highlightOffset))}drawInlineInput(e){var t=this.highlightOffset,n=e.xPos+e.connectionWidth,r=e.centerline-e.height/2,i=e.width-e.connectionWidth,a=r+t;this.RTL_?(r=e.connectionOffsetY-t,e=e.height-(e.connectionOffsetY+e.connectionHeight)+t,this.inlineSteps_+=_i(n-t,a)+C(`v`,r)+this.puzzleTabPaths_.pathDown(this.RTL_)+C(`v`,e)+C(`h`,i)):this.inlineSteps_+=_i(e.xPos+e.width+t,a)+C(`v`,e.height)+C(`h`,-i)+_i(n,r+e.connectionOffsetY)+this.puzzleTabPaths_.pathDown(this.RTL_)}},Gp=class extends Cp{constructor(e,t){super(e,t),this.highlighter_=new Wp(t)}draw(){this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights();var e=this.block_.pathObject;e.setPath(this.outlinePath_+`
902
902
  `+this.inlinePath_),e.setHighlightPath(this.highlighter_.getPath()),this.info_.RTL&&e.flipRTL(),this.recordSizeOnBlock_()}drawTop_(){this.highlighter_.drawTopCorner(this.info_.topRow),this.highlighter_.drawRightSideRow(this.info_.topRow),super.drawTop_()}drawJaggedEdge_(e){this.highlighter_.drawJaggedEdge_(e),super.drawJaggedEdge_(e)}drawValueInput_(e){this.highlighter_.drawValueInput(e),super.drawValueInput_(e)}drawStatementInput_(e){this.highlighter_.drawStatementInput(e),super.drawStatementInput_(e)}drawRightSideRow_(e){this.highlighter_.drawRightSideRow(e),this.outlinePath_+=C(`H`,e.xPos+e.width)+C(`V`,e.yPos+e.height)}drawBottom_(){this.highlighter_.drawBottomRow(this.info_.bottomRow),super.drawBottom_()}drawLeft_(){this.highlighter_.drawLeft(),super.drawLeft_()}drawInlineInput_(e){this.highlighter_.drawInlineInput(e),super.drawInlineInput_(e)}positionInlineInputConnection_(e){var t=e.centerline-e.height/2;if(e.connectionModel){let n=e.xPos+e.connectionWidth+this.constants_.DARK_PATH_OFFSET;this.info_.RTL&&(n*=-1),e.connectionModel.setOffsetInBlock(n,t+e.connectionOffsetY+this.constants_.DARK_PATH_OFFSET)}}positionStatementInputConnection_(e){var t=e.getLastInput();if(t!=null&&t.connectionModel){let n=e.xPos+e.statementEdge+t.notchOffset;n=this.info_.RTL?n*-1:n+this.constants_.DARK_PATH_OFFSET,t.connectionModel.setOffsetInBlock(n,e.yPos+this.constants_.DARK_PATH_OFFSET)}}positionExternalValueConnection_(e){var t=e.getLastInput();if(t&&t.connectionModel){let n=e.xPos+e.width+this.constants_.DARK_PATH_OFFSET;this.info_.RTL&&(n*=-1),t.connectionModel.setOffsetInBlock(n,e.yPos)}}positionNextConnection_(){var e=this.info_.bottomRow;if(e.connection){let t=e.connection,n=t.xPos;t.connectionModel.setOffsetInBlock((this.info_.RTL?-n:n)+this.constants_.DARK_PATH_OFFSET/2,e.baseline+this.constants_.DARK_PATH_OFFSET)}}},Kp=class{constructor(e){this.OFFSET=.5,this.constantProvider=e,this.START_POINT=vi(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(){var e=this.constantProvider.CORNER_RADIUS,t=this.OFFSET,n=(1-Math.SQRT1_2)*(e+t)-t,r=vi(n,n)+xi(`a`,`0 0,0`,e,S(-n-t,e-n)),i=xi(`a`,`0 0,0`,e+t,S(e+t,e+t)),a=vi(n,-n)+xi(`a`,`0 0,0`,e+t,S(e-n,n+t));return{width:e+t,height:e,pathTop(e){return e?r:``},pathBottom(e){return e?i:a}}}makeOutsideCorner(){var e=this.constantProvider.CORNER_RADIUS,t=this.OFFSET,n=(1-Math.SQRT1_2)*(e-t)+t,r=vi(n,n)+xi(`a`,`0 0,1`,e-t,S(e-n,-n+t)),i=vi(t,e)+xi(`a`,`0 0,1`,e-t,S(e,-e+t)),a=-n,o=vi(n,a)+xi(`a`,`0 0,1`,e-t,S(-n+t,-a-e));return{height:e,topLeft(e){return e?r:i},bottomLeft(){return o}}}makePuzzleTab(){var e=this.constantProvider.TAB_WIDTH,t=this.constantProvider.TAB_HEIGHT,n=vi(-2,-t+2.5+.9)+yi(e*-.45,-2.1),r=C(`v`,2.5)+vi(-e*.97,2.5)+gi(`q`,[S(-e*.05,10),S(e*.3,9.5)])+vi(e*.67,-1.9)+C(`v`,2.5),i=C(`v`,-1.5)+vi(e*-.92,-.5)+gi(`q`,[S(e*-.19,-5.5),S(0,-11)])+vi(e*.92,1),a=vi(-5,t-.7)+yi(e*.46,-2.1);return{width:e,height:t,pathUp(e){return e?n:i},pathDown(e){return e?r:a}}}makeNotch(){return{pathLeft:C(`h`,this.OFFSET)+this.constantProvider.NOTCH.pathLeft}}makeJaggedTeeth(){return{pathLeft:yi(5.1,2.6)+vi(-10.2,6.8)+yi(5.1,2.6),height:12,width:10.2}}makeStartHat(){var e=this.constantProvider.START_HAT.height,t=vi(25,-8.7)+gi(`c`,[S(29.7,-6.2),S(57.2,-.5),S(75,8.7)]),n=gi(`c`,[S(17.8,-9.2),S(45.3,-14.9),S(75,-8.7)])+_i(100.5,e+.5);return{path(e){return e?t:n}}}},qp=class extends up{constructor(e,t){super(e,t),this.constants_=e,this.connectedBlock&&(this.width+=this.constants_.DARK_PATH_OFFSET,this.height+=this.constants_.DARK_PATH_OFFSET)}},Jp=class extends yp{constructor(e,t){super(e,t),this.constants_=e,this.connectedBlock&&(this.height+=this.constants_.DARK_PATH_OFFSET)}},Yp=class extends wp{constructor(e,t){super(e,t),this.renderer_=e}getRenderer(){return this.renderer_}populateBottomRow_(){super.populateBottomRow_(),this.block_.inputList.length&&this.block_.inputList[this.block_.inputList.length-1]instanceof Kd||(this.bottomRow.minHeight=this.constants_.MEDIUM_PADDING-this.constants_.DARK_PATH_OFFSET)}addInput_(t,n){this.isInline&&t instanceof e.Nn?(n.elements.push(new qp(this.constants_,t)),n.hasInlineInput=!0):t instanceof Kd?(n.elements.push(new Jp(this.constants_,t)),n.hasStatement=!0):t instanceof e.Nn?(n.elements.push(new ap(this.constants_,t)),n.hasExternalInput=!0):(t instanceof Wd||t instanceof Gd)&&(n.minHeight=Math.max(n.minHeight,this.constants_.DUMMY_INPUT_MIN_HEIGHT),n.hasDummyInput=!0),this.isInline||n.align!==null||(n.align=t.align)}addElemSpacing_(){var e=!1;for(let t=0,n;n=this.rows[t];t++)n.hasExternalInput&&(e=!0);for(let n=0,r;r=this.rows[n];n++){var t=r.elements;if(r.elements=[],r.startsWithElemSpacer()&&r.elements.push(new lp(this.constants_,this.getInRowSpacing_(null,t[0]))),t.length){for(let e=0;e<t.length-1;e++){r.elements.push(t[e]);let n=this.getInRowSpacing_(t[e],t[e+1]);r.elements.push(new lp(this.constants_,n))}r.elements.push(t[t.length-1]),r.endsWithElemSpacer()&&(t=this.getInRowSpacing_(t[t.length-1],null),e&&r.hasDummyInput&&(t+=this.constants_.TAB_WIDTH),r.elements.push(new lp(this.constants_,t)))}}}getInRowSpacing_(e,t){if(!e)return t&&Z.isField(t)&&t.isEditable?this.constants_.MEDIUM_PADDING:t&&Z.isInlineInput(t)?this.constants_.MEDIUM_LARGE_PADDING:t&&Z.isStatementInput(t)?this.constants_.STATEMENT_INPUT_PADDING_LEFT:this.constants_.LARGE_PADDING;if(!Z.isInput(e)&&(!t||Z.isStatementInput(t)))return Z.isField(e)&&e.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING:Z.isIcon(e)?this.constants_.LARGE_PADDING*2+1:Z.isHat(e)?this.constants_.NO_PADDING:Z.isPreviousOrNextConnection(e)?this.constants_.LARGE_PADDING:Z.isLeftRoundedCorner(e)?this.constants_.MIN_BLOCK_WIDTH:Z.isJaggedEdge(e)?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING;if(Z.isInput(e)&&!t){if(Z.isExternalInput(e))return this.constants_.NO_PADDING;if(Z.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Z.isStatementInput(e))return this.constants_.NO_PADDING}if(!Z.isInput(e)&&t&&Z.isInput(t)){if(Z.isField(e)&&e.isEditable){if(Z.isInlineInput(t)||Z.isExternalInput(t))return this.constants_.SMALL_PADDING}else{if(Z.isInlineInput(t)||Z.isExternalInput(t))return this.constants_.MEDIUM_LARGE_PADDING;if(Z.isStatementInput(t))return this.constants_.LARGE_PADDING}return this.constants_.LARGE_PADDING-1}if(Z.isIcon(e)&&t&&!Z.isInput(t))return this.constants_.LARGE_PADDING;if(Z.isInlineInput(e)&&t&&Z.isField(t))return t.isEditable?this.constants_.MEDIUM_PADDING:this.constants_.LARGE_PADDING;if(Z.isLeftSquareCorner(e)&&t){if(Z.isHat(t))return this.constants_.NO_PADDING;if(Z.isPreviousConnection(t))return t.notchOffset;if(Z.isNextConnection(t))return t.notchOffset+(this.RTL?1:-1)*this.constants_.DARK_PATH_OFFSET/2}if(Z.isLeftRoundedCorner(e)&&t){if(Z.isPreviousConnection(t))return t.notchOffset-this.constants_.CORNER_RADIUS;if(Z.isNextConnection(t))return t.notchOffset-this.constants_.CORNER_RADIUS+(this.RTL?1:-1)*this.constants_.DARK_PATH_OFFSET/2}return Z.isField(e)&&t&&Z.isField(t)&&e.isEditable===t.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING:t&&Z.isJaggedEdge(t)?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getSpacerRowHeight_(e,t){return Z.isTopRow(e)&&Z.isBottomRow(t)?this.constants_.EMPTY_BLOCK_SPACER_HEIGHT:Z.isTopRow(e)||Z.isBottomRow(t)?this.constants_.NO_PADDING:e.hasExternalInput&&t.hasExternalInput?this.constants_.LARGE_PADDING:!e.hasStatement&&t.hasStatement?this.constants_.BETWEEN_STATEMENT_PADDING_Y:e.hasStatement&&t.hasStatement||!e.hasStatement&&t.hasDummyInput||e.hasDummyInput?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getElemCenterline_(e,t){if(Z.isSpacer(t))return e.yPos+t.height/2;if(Z.isBottomRow(e))return e=e.yPos+e.height-e.descenderHeight,Z.isNextConnection(t)?e+t.height/2:e-t.height/2;if(Z.isTopRow(e))return Z.isHat(t)?e.capline-t.height/2:e.capline+t.height/2;var n=e.yPos;return Z.isField(t)||Z.isIcon(t)?(n+=t.height/2,(e.hasInlineInput||e.hasStatement)&&t.height+this.constants_.TALL_INPUT_FIELD_OFFSET_Y<=e.height&&(n+=this.constants_.TALL_INPUT_FIELD_OFFSET_Y)):n=Z.isInlineInput(t)?n+t.height/2:n+e.height/2,n}alignRowElements_(){if(this.isInline){var e=0,t=new WeakMap,n=null;for(let r=this.rows.length-1,i;i=this.rows[r];r--)t.set(i,e),Z.isInputRow(i)&&(i.hasStatement&&this.alignStatementRow_(i),n&&n.hasStatement&&i.width<n.width?t.set(i,n.width):e=i.hasStatement?i.width:Math.max(e,i.width),n=i);e=0;for(let r=0,i;i=this.rows[r];r++)i.hasStatement?e=this.getDesiredRowWidth_(i):Z.isSpacer(i)?i.width=Math.max(e,t.get(i)):(n=i.width,e=Math.max(e,t.get(i))-n,e>0&&this.addAlignmentPadding_(i,e),e=i.width)}else super.alignRowElements_()}getDesiredRowWidth_(e){return this.isInline&&e.hasStatement?this.statementEdge+this.constants_.MAX_BOTTOM_WIDTH+this.startX:super.getDesiredRowWidth_(e)}finalize_(){var e=0,t=0;for(let r=0,i;i=this.rows[r];r++){i.yPos=t,i.xPos=this.startX,t+=i.height,e=Math.max(e,i.widthWithConnectedBlocks);var n=t-this.topRow.ascenderHeight;i===this.bottomRow&&n<this.constants_.MIN_BLOCK_HEIGHT&&(n=this.constants_.MIN_BLOCK_HEIGHT-n,this.bottomRow.height+=n,t+=n),this.recordElemPositions_(i)}this.outputConnection&&this.block_.nextConnection&&this.block_.nextConnection.isConnected()&&(n=this.block_.nextConnection.targetBlock())&&(e=Math.max(e,n.getHeightWidth().width-this.constants_.DARK_PATH_OFFSET)),this.bottomRow.baseline=t-this.bottomRow.descenderHeight,this.widthWithChildren=e+this.startX+this.constants_.DARK_PATH_OFFSET,this.width+=this.constants_.DARK_PATH_OFFSET,this.height=t+this.constants_.DARK_PATH_OFFSET,this.startY=this.topRow.capline}},Xp=class extends Tp{constructor(e,t,n){super(e,t,n),this.constants=n,this.colourDark=`#000000`,this.svgPathDark=h(A.PATH,{class:`blocklyPathDark`,transform:`translate(1,1)`}),this.svgRoot.insertBefore(this.svgPathDark,this.svgPath),this.svgPathLight=h(A.PATH,{class:`blocklyPathLight`},this.svgRoot)}setPath(e){this.svgPath.setAttribute(`d`,e),this.svgPathDark.setAttribute(`d`,e)}setHighlightPath(e){this.svgPathLight.setAttribute(`d`,e)}flipRTL(){this.svgPath.setAttribute(`transform`,`scale(-1 1)`),this.svgPathLight.setAttribute(`transform`,`scale(-1 1)`),this.svgPathDark.setAttribute(`transform`,`translate(1,1) scale(-1 1)`)}applyColour(e){this.svgPathLight.style.display=``,this.svgPathDark.style.display=``,this.svgPathLight.setAttribute(`stroke`,this.style.colourTertiary),this.svgPathDark.setAttribute(`fill`,this.colourDark),super.applyColour(e),this.svgPath.setAttribute(`stroke`,`none`)}setStyle(e){this.style=e,this.colourDark=Tr(`#000`,this.style.colourPrimary,.2)||this.colourDark}updateHighlighted(e){super.updateHighlighted(e),this.svgPathLight.style.display=e?`none`:`inline`}updateShadow_(e){super.updateShadow_(e),e&&(this.svgPathLight.style.display=`none`,this.svgPathDark.setAttribute(`fill`,this.style.colourSecondary))}updateDisabled_(e){super.updateDisabled_(e),e&&this.svgPath.setAttribute(`stroke`,`none`)}},Zp=class extends Ep{constructor(e){super(e),this.highlightConstants=null}init(e,t){super.init(e,t),this.highlightConstants=this.makeHighlightConstants_(),this.highlightConstants.init()}refreshDom(e,t,n){super.refreshDom(e,t,n),this.getHighlightConstants().init()}makeConstants_(){return new Up}makeRenderInfo_(e){return new Yp(this,e)}makeDrawer_(e,t){return new Gp(e,t)}makePathObject(e,t){return new Xp(e,t,this.getConstants())}makeHighlightConstants_(){return new Kp(this.getConstants())}getHighlightConstants(){if(!this.highlightConstants)throw Error(`Cannot access the highlight constants because init has not been called`);return this.highlightConstants}};La(`geras`,Zp);var Qp=class extends wp{constructor(e,t){super(e,t)}getRenderer(){return this.renderer_}addElemSpacing_(){for(var e=!1,t=0;t<this.rows.length;t++)if(this.rows[t].hasExternalInput){e=!0;break}for(t=0;t<this.rows.length;t++){let r=this.rows[t];var n=r.elements;if(r.elements=[],r.startsWithElemSpacer()&&r.elements.push(new lp(this.constants_,this.getInRowSpacing_(null,n[0]))),n.length){for(let e=0;e<n.length-1;e++){r.elements.push(n[e]);let t=this.getInRowSpacing_(n[e],n[e+1]);r.elements.push(new lp(this.constants_,t))}r.elements.push(n[n.length-1]),r.endsWithElemSpacer()&&(n=this.getInRowSpacing_(n[n.length-1],null),e&&r.hasDummyInput&&(n+=this.constants_.TAB_WIDTH),r.elements.push(new lp(this.constants_,n)))}}}getInRowSpacing_(e,t){if(!e)return t&&Z.isField(t)&&t.isEditable?this.constants_.MEDIUM_PADDING:t&&Z.isInlineInput(t)?this.constants_.MEDIUM_LARGE_PADDING:t&&Z.isStatementInput(t)?this.constants_.STATEMENT_INPUT_PADDING_LEFT:this.constants_.LARGE_PADDING;if(!Z.isInput(e)&&!t)return Z.isField(e)&&e.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING:Z.isIcon(e)?this.constants_.LARGE_PADDING*2+1:Z.isHat(e)?this.constants_.NO_PADDING:Z.isPreviousOrNextConnection(e)?this.constants_.LARGE_PADDING:Z.isLeftRoundedCorner(e)?this.constants_.MIN_BLOCK_WIDTH:Z.isJaggedEdge(e)?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING;if(Z.isInput(e)&&!t){if(Z.isExternalInput(e))return this.constants_.NO_PADDING;if(Z.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Z.isStatementInput(e))return this.constants_.NO_PADDING}if(!Z.isInput(e)&&t&&Z.isInput(t)){if(Z.isField(e)&&e.isEditable){if(Z.isInlineInput(t)||Z.isExternalInput(t))return this.constants_.SMALL_PADDING}else{if(Z.isInlineInput(t)||Z.isExternalInput(t))return this.constants_.MEDIUM_LARGE_PADDING;if(Z.isStatementInput(t))return this.constants_.LARGE_PADDING}return this.constants_.LARGE_PADDING-1}if(Z.isIcon(e)&&t&&!Z.isInput(t))return this.constants_.LARGE_PADDING;if(Z.isInlineInput(e)&&t&&Z.isField(t))return t.isEditable?this.constants_.MEDIUM_PADDING:this.constants_.LARGE_PADDING;if(Z.isLeftSquareCorner(e)&&t){if(Z.isHat(t))return this.constants_.NO_PADDING;if(Z.isPreviousConnection(t)||Z.isNextConnection(t))return t.notchOffset}return Z.isLeftRoundedCorner(e)&&t?t.notchOffset-this.constants_.CORNER_RADIUS:Z.isField(e)&&t&&Z.isField(t)&&e.isEditable===t.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING:t&&Z.isJaggedEdge(t)?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getSpacerRowHeight_(e,t){return Z.isTopRow(e)&&Z.isBottomRow(t)?this.constants_.EMPTY_BLOCK_SPACER_HEIGHT:Z.isTopRow(e)||Z.isBottomRow(t)?this.constants_.NO_PADDING:e.hasExternalInput&&t.hasExternalInput?this.constants_.LARGE_PADDING:!e.hasStatement&&t.hasStatement?this.constants_.BETWEEN_STATEMENT_PADDING_Y:e.hasStatement&&t.hasStatement||e.hasDummyInput||t.hasDummyInput?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getElemCenterline_(e,t){if(Z.isSpacer(t))return e.yPos+t.height/2;if(Z.isBottomRow(e))return e=e.yPos+e.height-e.descenderHeight,Z.isNextConnection(t)?e+t.height/2:e-t.height/2;if(Z.isTopRow(e))return Z.isHat(t)?e.capline-t.height/2:e.capline+t.height/2;var n=e.yPos;return n=Z.isField(t)&&e.hasStatement?n+(this.constants_.TALL_INPUT_FIELD_OFFSET_Y+t.height/2):n+e.height/2}finalize_(){for(var e=0,t=0,n=0;n<this.rows.length;n++){let i=this.rows[n];i.yPos=t,i.xPos=this.startX,t+=i.height,e=Math.max(e,i.widthWithConnectedBlocks);var r=t-this.topRow.ascenderHeight;i===this.bottomRow&&r<this.constants_.MIN_BLOCK_HEIGHT&&(r=this.constants_.MIN_BLOCK_HEIGHT-r,this.bottomRow.height+=r,t+=r),this.recordElemPositions_(i)}this.outputConnection&&this.block_.nextConnection&&this.block_.nextConnection.isConnected()&&(n=this.block_.nextConnection.targetBlock())&&(e=Math.max(e,n.getHeightWidth().width)),this.bottomRow.baseline=t-this.bottomRow.descenderHeight,this.widthWithChildren=e+this.startX,this.height=t,this.startY=this.topRow.capline}},$p=class extends Ep{constructor(e){super(e)}makeRenderInfo_(e){return new Qp(this,e)}};La(`thrasos`,$p);var em=class extends Sp{constructor(e){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.selectedGlowFilterId=``,this.SQUARED=this.ROUNDED=this.HEXAGONAL=this.selectedGlowFilter=null,e&&(this.GRID_UNIT=e),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_(e){super.setFontConstants_(e),this.FIELD_DROPDOWN_BORDER_RECT_HEIGHT=this.FIELD_BORDER_RECT_HEIGHT=this.FIELD_TEXT_HEIGHT+this.FIELD_BORDER_RECT_Y_PADDING*2}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_(e){super.setDynamicProperties_(e),this.SELECTED_GLOW_COLOUR=e.getComponentStyle(`selectedGlowColour`)||this.SELECTED_GLOW_COLOUR,this.SELECTED_GLOW_SIZE=(e=Number(e.getComponentStyle(`selectedGlowSize`)))&&!isNaN(e)?e:this.SELECTED_GLOW_SIZE}dispose(){super.dispose(),this.selectedGlowFilter&&v(this.selectedGlowFilter)}makeStartHat(){var e=this.START_HAT_HEIGHT,t=this.START_HAT_WIDTH,n=gi(`c`,[S(25,-e),S(71,-e),S(t,0)]);return{height:e*.75,width:t,path:n}}makeHexagonal(){function e(e,n,r){var i=e/2;return i=i>t?t:i,r=r?-1:1,e=(n?-1:1)*e/2,yi(-r*i,e)+yi(r*i,e)}var t=this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH;return{type:this.SHAPES.HEXAGONAL,isDynamic:!0,width(e){return e/=2,e>t?t:e},height(e){return e},connectionOffsetY(e){return e/2},connectionOffsetX(e){return-e},pathDown(t){return e(t,!1,!1)},pathUp(t){return e(t,!0,!1)},pathRightDown(t){return e(t,!1,!0)},pathRightUp(t){return e(t,!1,!0)}}}makeRounded(){function e(e,t,r){var i=e>n?e-n:0;e=(e>n?n:e)/2;var a=r===t?`0`:`1`;return xi(`a`,`0 0,`+a,e,S((r?1:-1)*e,(t?-1:1)*e))+C(`v`,(t?-1:1)*i)+xi(`a`,`0 0,`+a,e,S((r?-1:1)*e,(t?-1:1)*e))}var t=this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH,n=t*2;return{type:this.SHAPES.ROUND,isDynamic:!0,width(e){return e/=2,e>t?t:e},height(e){return e},connectionOffsetY(e){return e/2},connectionOffsetX(e){return-e},pathDown(t){return e(t,!1,!1)},pathUp(t){return e(t,!0,!1)},pathRightDown(t){return e(t,!1,!0)},pathRightUp(t){return e(t,!1,!0)}}}makeSquared(){function e(e,n,r){e-=t*2;var i=r===n?`0`:`1`;return xi(`a`,`0 0,`+i,t,S((r?1:-1)*t,(n?-1:1)*t))+C(`v`,(n?-1:1)*e)+xi(`a`,`0 0,`+i,t,S((r?-1:1)*t,(n?-1:1)*t))}var t=this.CORNER_RADIUS;return{type:this.SHAPES.SQUARE,isDynamic:!0,width(){return t},height(e){return e},connectionOffsetY(e){return e/2},connectionOffsetX(e){return-e},pathDown(t){return e(t,!1,!1)},pathUp(t){return e(t,!0,!1)},pathRightDown(t){return e(t,!1,!0)},pathRightUp(t){return e(t,!1,!0)}}}shapeFor(e){var t=e.getCheck();switch(!t&&e.targetConnection&&(t=e.targetConnection.getCheck()),e.type){case L.INPUT_VALUE:case L.OUTPUT_VALUE:if(e=e.getSourceBlock().getOutputShape(),e!==null)switch(e){case this.SHAPES.HEXAGONAL:return this.HEXAGONAL;case this.SHAPES.ROUND:return this.ROUNDED;case this.SHAPES.SQUARE:return this.SQUARED}return t&&t.includes(`Boolean`)?this.HEXAGONAL:(t&&t.includes(`Number`)||t&&t.includes(`String`),this.ROUNDED);case L.PREVIOUS_STATEMENT:case L.NEXT_STATEMENT:return this.NOTCH;default:throw Error(`Unknown type`)}}makeNotch(){function e(e){return gi(`c`,[S(e*i/2,0),S(e*i*3/4,o/2),S(e*i,o)])+bi([S(e*i,a)])+gi(`c`,[S(e*i/4,o/2),S(e*i/2,o),S(e*i,o)])+C(`h`,e*r)+gi(`c`,[S(e*i/2,0),S(e*i*3/4,-(o/2)),S(e*i,-o)])+bi([S(e*i,-a)])+gi(`c`,[S(e*i/4,-(o/2)),S(e*i/2,-o),S(e*i,-o)])}var t=this.NOTCH_WIDTH,n=this.NOTCH_HEIGHT,r=t/3,i=r/3,a=n/2,o=a/2,s=e(1),c=e(-1);return{type:this.SHAPES.NOTCH,width:t,height:n,pathLeft:s,pathRight:c}}makeInsideCorners(){var e=this.CORNER_RADIUS,t=xi(`a`,`0 0,0`,e,S(-e,e)),n=xi(`a`,`0 0,1`,e,S(-e,e));return{width:e,height:e,pathTop:t,pathBottom:xi(`a`,`0 0,0`,e,S(e,e)),rightWidth:e,rightHeight:e,pathTopRight:n,pathBottomRight:xi(`a`,`0 0,1`,e,S(e,e))}}generateSecondaryColour_(e){return Tr(`#000`,e,.15)||e}generateTertiaryColour_(e){return Tr(`#000`,e,.25)||e}createDom(e,t,n){super.createDom(e,t,n),e=h(A.DEFS,{},e),e=h(A.FILTER,{id:`blocklySelectedGlowFilter`+this.randomIdentifier,height:`160%`,width:`180%`,y:`-30%`,x:`-40%`},e),h(A.FEGAUSSIANBLUR,{in:`SourceGraphic`,stdDeviation:this.SELECTED_GLOW_SIZE},e),t=h(A.FECOMPONENTTRANSFER,{result:`outBlur`},e),h(A.FEFUNCA,{type:`table`,tableValues:`0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1`},t),h(A.FEFLOOD,{"flood-color":this.SELECTED_GLOW_COLOUR,"flood-opacity":1,result:`outColor`},e),h(A.FECOMPOSITE,{in:`outColor`,in2:`outBlur`,operator:`in`,result:`outGlow`},e),this.selectedGlowFilterId=e.id,this.selectedGlowFilter=e,n&&n.style.setProperty(`--blocklySelectedGlowFilter`,`url(#${this.selectedGlowFilterId})`)}getCSS_(e){return[`${e} .blocklyText,`,`${e} .blocklyFlyoutLabelText {`,`font: ${this.FIELD_TEXT_FONTWEIGHT} ${this.FIELD_TEXT_FONTSIZE}pt ${this.FIELD_TEXT_FONTFAMILY};`,`}`,`${e} .blocklyTextInputBubble textarea {`,`font-weight: normal;`,`}`,`${e} .blocklyText {`,`fill: #fff;`,`}`,`${e} .blocklyNonEditableField>rect:not(.blocklyDropdownRect),`,`${e} .blocklyEditableField>rect:not(.blocklyDropdownRect) {`,`fill: ${this.FIELD_BORDER_RECT_COLOUR};`,`}`,`${e} .blocklyNonEditableField>text,`,`${e} .blocklyEditableField>text,`,`${e} .blocklyNonEditableField>g>text,`,`${e} .blocklyEditableField>g>text {`,`fill: #575E75;`,`}`,`${e} .blocklyFlyoutLabelText {`,`fill: #575E75;`,`}`,`${e} .blocklyText.blocklyBubbleText {`,`fill: #575E75;`,`}`,`${e} .blocklyDraggable:not(.blocklyDisabled)`,` .blocklyEditableField:not(.blocklyEditing):hover>rect,`,`${e} .blocklyDraggable:not(.blocklyDisabled)`,` .blocklyEditableField:not(.blocklyEditing):hover>.blocklyPath {`,`stroke: #fff;`,`stroke-width: 2;`,`}`,`${e} .blocklyHtmlInput {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,`font-weight: ${this.FIELD_TEXT_FONTWEIGHT};`,`color: #575E75;`,`}`,`${e} .blocklyDropdownText {`,`fill: #fff !important;`,`}`,`${e}.blocklyWidgetDiv .blocklyMenuItem,`,`${e}.blocklyDropDownDiv .blocklyMenuItem {`,`font-family: ${this.FIELD_TEXT_FONTFAMILY};`,`}`,`${e}.blocklyDropDownDiv .blocklyMenuItemContent {`,`color: #fff;`,`}`,`${e} .blocklyHighlightedConnectionPathVisible {`,`stroke: ${this.SELECTED_GLOW_COLOUR};`,`}`,`${e} .blocklyDisabledPattern > .blocklyOutlinePath {`,`fill: var(--blocklyDisabledPattern)`,`}`,`${e} .blocklyInsertionMarker>.blocklyPath {`,`fill-opacity: ${this.INSERTION_MARKER_OPACITY};`,`stroke: none;`,`}`,`${e} .blocklySelected>.blocklyPath.blocklyPathSelected {`,`fill: none;`,`filter: var(--blocklySelectedGlowFilter);`,`}`]}},tm=class extends Cp{constructor(e,t){super(e,t)}draw(){var e=this.block_.pathObject;e.beginDrawing(),this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights(),e.setPath(this.outlinePath_+`
903
- `+this.inlinePath_),this.info_.RTL&&e.flipRTL(),this.recordSizeOnBlock_(),this.info_.outputConnection&&(e.outputShapeType=this.info_.outputConnection.shape.type),e.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_(e){if(!(e.height<=0)){if(Z.isSpacer(e)){let r=e.precedesStatement;var t=e.followsStatement;if(r||t){let i=this.constants_.INSIDE_CORNERS;var n=i.rightHeight;n=e.height-(r?n:0),t=t?i.pathBottomRight:``,e=n>0?C(`V`,e.yPos+n):``,this.outlinePath_+=t+e+(r?i.pathTopRight:``);return}}this.outlinePath_+=C(`V`,e.yPos+e.height)}}drawRightDynamicConnection_(){if(!this.info_.outputConnection)throw Error(`Cannot draw the output connection of a block that doesn't have one`);this.outlinePath_+=this.info_.outputConnection.shape.pathRightDown(this.info_.outputConnection.height)}drawLeftDynamicConnection_(){if(!this.info_.outputConnection)throw Error(`Cannot draw the output connection of a block that doesn't have one`);this.positionOutputConnection_(),this.outlinePath_+=this.info_.outputConnection.shape.pathUp(this.info_.outputConnection.height),this.outlinePath_+=`z`}drawFlatTop_(){var e=this.info_.topRow;this.positionPreviousConnection_(),this.outlinePath_+=vi(e.xPos,this.info_.startY),this.outlinePath_+=C(`h`,e.width)}drawFlatBottom_(){var e=this.info_.bottomRow;this.positionNextConnection_(),this.outlinePath_+=C(`V`,e.baseline),this.outlinePath_+=C(`h`,-e.width)}drawInlineInput_(e){this.positionInlineInputConnection_(e);var t=e.input.name;e.connectedBlock||this.info_.isInsertionMarker||(e=_i(e.xPos+e.connectionWidth,e.centerline-e.height/2)+this.getInlineInputPath(e),this.block_.pathObject.setOutlinePath(t,e))}getInlineInputPath(e){var t=e.width-e.connectionWidth*2,n=e.height;return C(`h`,t)+e.shape.pathRightDown(n)+C(`h`,-t)+e.shape.pathUp(n)+`z`}drawStatementInput_(e){var t=e.getLastInput(),n=t.xPos+t.notchOffset+t.shape.width,r=this.constants_.INSIDE_CORNERS,i=t.shape.pathRight+C(`h`,-(t.notchOffset-r.width))+r.pathTop,a=e.height-2*r.height;t=r.pathBottom+C(`h`,t.notchOffset-r.width)+(t.connectedBottomNextConnection?``:t.shape.pathLeft),this.outlinePath_+=C(`H`,n)+i+C(`v`,a)+t+C(`H`,e.xPos+e.width),this.positionStatementInputConnection_(e)}drawConnectionHighlightPath(e){var t=e.connectionModel;if(t.type===L.NEXT_STATEMENT||t.type===L.PREVIOUS_STATEMENT||t.type===L.OUTPUT_VALUE&&!e.isDynamicShape)return super.drawConnectionHighlightPath(e);e=t.type===L.INPUT_VALUE?_i(e.connectionWidth,-e.height/2)+this.getInlineInputPath(e):_i(e.width,-e.height/2)+e.shape.pathDown(e.height);var n=t.getSourceBlock(),r,i;return(i=(r=n.pathObject).addConnectionHighlight)==null?void 0:i.call(r,t,e,t.getOffsetInBlock(),n.RTL)}},nm=class extends V{constructor(e,t,n,r,i,a,o){if(super(V.SKIP_SETUP),this.imageElement=this.clickHandler=null,this.flipRtl=this.isDirty_=this.EDITABLE=!1,this.altText=``,n=Number(kr(n)),t=Number(kr(t)),isNaN(n)||isNaN(t))throw Error(`Height and width values of an image field must cast to numbers.`);if(n<=0||t<=0)throw Error(`Height and width values of an image field must be greater than 0.`);this.size_=new F(t,n+nm.Y_PADDING),this.imageHeight=n,typeof i==`function`&&(this.clickHandler=i),e!==V.SKIP_SETUP&&(o?this.configure_(o):typeof r==`object`&&r&&!Array.isArray(r)&&(`alt`in r||`flipRtl`in r)?this.configure_(r):(this.flipRtl=!!a,this.altText=typeof r==`string`&&kr(r)||``),this.setValue(kr(e)))}configure_(e){super.configure_(e),e.flipRtl&&(this.flipRtl=e.flipRtl),e.alt&&(this.altText=kr(e.alt))}initView(){this.imageElement=h(A.IMAGE,{height:this.imageHeight+`px`,width:this.size_.width+`px`,alt:this.altText},this.fieldGroup_),this.imageElement.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.value_),this.fieldGroup_&&g(this.fieldGroup_,`blocklyImageField`),this.clickHandler&&(this.imageElement.style.cursor=`pointer`),this.recomputeAriaContext()}updateSize_(){}doClassValidation_(e){return typeof e==`string`?e:null}doValueUpdate_(e){this.value_=e,this.imageElement&&this.imageElement.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.value_),this.recomputeAriaContext()}getFlipRtl(){return this.flipRtl}setAlt(e){e!==this.altText&&(this.altText=e||``,this.imageElement&&this.imageElement.setAttribute(`alt`,this.altText))}isClickable(){return super.isClickable()&&!!this.clickHandler}showEditor_(){this.clickHandler&&this.clickHandler(this)}setOnClickHandler(e){this.clickHandler=e}getText_(){return this.altText}static fromJson(e){if(!e.src||!e.width||!e.height)throw Error(`src, width, and height values for an image field arerequired. The width and height must be non-zero.`);return new this(e.src,e.width,e.height,void 0,void 0,void 0,e)}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_IMAGE}getAriaValue(){return this.altText||null}computeAriaLabel(e){return this.isClickable()?``:super.computeAriaLabel(e)}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var e=this.getFocusableElement();if(!this.isClickable())return p(e,O.NONE),ie(e,k.LABEL),!1;var t=this.getAriaValue()||``;return m(e,k.LABEL,t),!0}};nm.Y_PADDING=1,ci(`field_image`,nm),nm.prototype.DEFAULT_VALUE=``;var rm=class extends V{set size_(e){super.size_=e}get size_(){var e=super.size_;return e.width<14&&(e.width=14),e}constructor(e,t,n){super(V.SKIP_SETUP),this.spellcheck_=!0,this.htmlInput_=null,this.isTextValid_=this.isBeingEdited_=!1,this.onInputWrapper=this.onKeyDownWrapper=this.valueWhenEditorWasOpened_=this.warningIcon=null,this.fullBlockClickTarget_=!1,this.workspace_=null,this.SERIALIZABLE=!0,e!==V.SKIP_SETUP&&(n&&this.configure_(n),this.setValue(e),t&&this.setValidator(t))}configure_(e){super.configure_(e),e.spellcheck!==void 0&&(this.spellcheck_=e.spellcheck)}initView(){if(!this.getSourceBlock())throw new Wu;this.isFullBlockField()||this.createBorderRect_(),this.createTextElement_(),this.fieldGroup_&&g(this.fieldGroup_,`blocklyField`),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot()),this.fieldGroup_&&g(this.fieldGroup_,`blocklyInputField`),this.recomputeAriaContext()}isFullBlockField(){var e=this.getSourceBlock();if(!e)throw new Wu;var t;return this.fullBlockClickTarget_=!((t=this.getConstants())==null||!t.FULL_BLOCK_FIELDS)&&e.isSimpleReporter()}createWarningIcon(){if(!this.sourceBlock_)return null;var e=this.getScaledBBox();return e=e.bottom-e.top,e=h(A.SVG,{class:`blocklyInputWarning`,viewBox:`-4 0 24 16`,x:`0`,y:`0`,height:`${e}px`,width:`${e}px`}),h(A.PATH,{class:`blocklyInputWarningIconShape`,d:`M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z`},e),h(A.PATH,{class:`blocklyInputWarningIconSymbol`,d:`m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z`},e),h(A.RECT,{class:`blocklyInputWarningIconSymbol`,x:`7`,y:`11`,height:`2`,width:`2`},e),e}doValueInvalid_(e,t=!0){this.isBeingEdited_&&(this.isDirty_=!0,this.isTextValid_=!1,e=this.value_,this.value_=this.valueWhenEditorWasOpened_,this.sourceBlock_&&Je()&&this.value_!==e&&t&&b(new(x(E.BLOCK_CHANGE))(this.sourceBlock_,`field`,this.name||null,e,this.value_))),this.recomputeAriaContext()}doValueUpdate_(e){this.isTextValid_=this.isDirty_=!0,this.value_=e,this.recomputeAriaContext()}applyColour(){var e=this.getSourceBlock();if(!e)throw new Wu;this.getConstants().FULL_BLOCK_FIELDS&&this.fieldGroup_&&(!this.isFullBlockField()&&this.borderRect_?(this.borderRect_.style.display=`block`,this.borderRect_.setAttribute(`stroke`,e.getColourTertiary())):e.pathObject.svgPath.setAttribute(`fill`,this.getConstants().FIELD_BORDER_RECT_COLOUR))}getSize(){var e;return(e=this.getConstants())!=null&&e.FULL_BLOCK_FIELDS&&(this.render_(),this.isDirty_=!1),super.getSize()}onLocationChange(){this.isBeingEdited_&&this.resizeEditor_()}render_(){super.render_();var e=this.getSourceBlock();if(!e)throw new Wu;if(this.isBeingEdited_){let t=this.htmlInput_;this.renderWarningIcon(e.RTL,this.isTextValid_),this.isTextValid_?(_(t,`blocklyInvalidInput`),m(t,k.INVALID,!1)):(g(t,`blocklyInvalidInput`),m(t,k.INVALID,!0))}this.getConstants().FULL_BLOCK_FIELDS&&e.applyColour()}renderWarningIcon(e,t){var n=this.htmlInput_;if(this.warningIcon)if(t)n.style.paddingRight=``,n.style.paddingLeft=``,_(this.warningIcon,`blocklyInputWarningInvalid`);else{t=this.getScaledBBox();var r=t.bottom-t.top;r=(t=!!this.borderRect_)?this.getConstants().FIELD_BORDER_RECT_X_PADDING:r/2,g(this.warningIcon,`blocklyInputWarningInvalid`);let i=this.warningIcon.getBoundingClientRect().width;n.setAttribute(`width`,`${n.offsetWidth+i}px`);let a=i/1.5;e?n.style.paddingRight=`${a}px`:n.style.paddingLeft=`${a}px`,this.size_.width=i,e=t?this.getConstants().FIELD_TEXT_HEIGHT-this.getConstants().FIELD_BORDER_RECT_X_PADDING:0,this.updateSize_(r+e)}}setSpellcheck(e){e!==this.spellcheck_&&(this.spellcheck_=e,this.htmlInput_&&this.htmlInput_.setAttribute(`spellcheck`,this.spellcheck_))}showEditor_(e,t=!1,n=!0){this.workspace_=this.sourceBlock_.workspace,!t&&this.workspace_.options.modalInputs&&(Bo||Io||Lo)?this.showPromptEditor():this.showInlineEditor(t,n)}showPromptEditor(){Ht(e.C.CHANGE_VALUE_TITLE,this.getText(),e=>{e!==null&&this.setValue(this.getValueFromEditorText_(e)),this.onFinishEditing_(this.value_)})}showInlineEditor(e,t){var n=this.getSourceBlock();if(!n)throw new Wu;Nr(this,n.RTL,this.widgetDispose_.bind(this),this.workspace_,t),this.htmlInput_=this.widgetCreate_(),this.isBeingEdited_=!0,this.valueWhenEditorWasOpened_=this.value_,e||(this.htmlInput_.focus({preventScroll:!0}),this.htmlInput_.select())}widgetCreate_(){var t=this.getSourceBlock();if(!t)throw new Wu;e.B(!0);var n=Xu,r=this.getClickTarget_();if(!r)throw Error(`A click target has not been set.`);g(r,`blocklyEditing`),r=document.createElement(`input`),r.className=`blocklyHtmlInput`,r.setAttribute(`spellcheck`,this.spellcheck_),this.warningIcon=this.createWarningIcon();var i=this.workspace_.getAbsoluteScale(),a=this.getConstants().FIELD_TEXT_FONTSIZE*i+`pt`;if(n.style.fontSize=a,r.style.fontSize=a,a=rm.BORDERRADIUS*i+`px`,this.isFullBlockField()){let e=this.getScaledBBox();a=(e.bottom-e.top)/2+`px`,t=t.getParent()?t.getParent().getColourTertiary():this.sourceBlock_.getColourTertiary(),r.style.border=1*i+`px solid `+t,n.style.borderRadius=a,n.style.transition=`box-shadow 0.25s ease 0s`,this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW&&(n.style.boxShadow=`rgba(255, 255, 255, 0.3) 0 0 0 `+4*i+`px`),t=(e.bottom-e.top)/4,this.warningIcon.style.paddingLeft=`${t}px`,this.warningIcon.style.paddingRight=`${t}px`}return r.style.borderRadius=a,this.warningIcon&&n.appendChild(this.warningIcon),n.appendChild(r),r.value=r.defaultValue=this.getEditorText_(this.value_),r.setAttribute(`data-untyped-default-value`,String(this.value_)),this.resizeEditor_(),this.bindInputEvents_(r),r}widgetDispose_(){this.isBeingEdited_=!1,this.isTextValid_=!0,this.forceRerender(),this.onFinishEditing_(this.value_),this.sourceBlock_&&Je()&&this.valueWhenEditorWasOpened_!==null&&this.valueWhenEditorWasOpened_!==this.value_&&(b(new(x(E.BLOCK_CHANGE))(this.sourceBlock_,`field`,this.name||null,this.valueWhenEditorWasOpened_,this.value_)),this.valueWhenEditorWasOpened_=null),e.B(!1),this.unbindInputEvents_();var t=Xu.style;if(t.width=`auto`,t.height=`auto`,t.fontSize=``,t.transition=``,t.boxShadow=``,this.htmlInput_=null,t=this.getClickTarget_(),!t)throw Error(`A click target has not been set.`);_(t,`blocklyEditing`),this.recomputeAriaContext()}onFinishEditing_(){}bindInputEvents_(e){this.onKeyDownWrapper=o(e,`keydown`,this,this.onHtmlInputKeyDown_),this.onInputWrapper=o(e,`input`,this,this.onHtmlInputChange)}unbindInputEvents_(){this.onKeyDownWrapper&&=(c(this.onKeyDownWrapper),null),this.onInputWrapper&&=(c(this.onInputWrapper),null)}onHtmlInputKeyDown_(t){if(t.key===`Enter`)Fr(this),er(),t.stopPropagation();else if(t.key===`Escape`)this.setValue(this.htmlInput_.getAttribute(`data-untyped-default-value`),!1),Fr(this),er();else if(t.key===`Tab`){t.preventDefault();var n;let r=(n=this.workspace_)==null?void 0:n.getNavigator(),i=e=>(e instanceof rm||e instanceof gf&&e.isSimpleReporter())&&e!==this.getSourceBlock();n=this;do n=t.shiftKey?r==null?void 0:r.getOutNode(n):r==null?void 0:r.getInNode(n);while(n&&!i(n));n=n instanceof gf&&n.isSimpleReporter()?n.getFields().next().value:n,n instanceof rm&&(Fr(this),er(),t=n.getSourceBlock(),n.isFullBlockField()&&t&&t instanceof gf?e.t().focusNode(t):e.t().focusNode(n),n.showEditor())}}onHtmlInputChange(){var e=this.value_;this.setValue(this.getValueFromEditorText_(this.htmlInput_.value),!1),this.sourceBlock_&&Je()&&this.value_!==e&&b(new(x(E.BLOCK_FIELD_INTERMEDIATE_CHANGE))(this.sourceBlock_,this.name||null,e,this.value_))}setEditorValue_(e,t=!0){this.isDirty_=!0,this.isBeingEdited_&&(this.htmlInput_.value=this.getEditorText_(e)),this.setValue(e,t)}resizeEditor_(){At().then(()=>{var e=this.getSourceBlock();if(!e)throw new Wu;var t=Xu,n=this.getScaledBBox();t.style.width=n.right-n.left+`px`,t.style.height=n.bottom-n.top+`px`,e=e.RTL?n.right-t.offsetWidth:n.left,n=n.top;var r=t==null?void 0:t.parentElement;r&&(r=r.getBoundingClientRect(),e-=r.left+window.scrollX,n-=r.top+window.scrollY),t.style.left=`${e}px`,t.style.top=`${n}px`})}repositionForWindowResize(){var e,t=(e=this.getSourceBlock())==null?void 0:e.getRootBlock();return t instanceof gf&&(Ni(this.workspace_,this.workspace_.getMetricsManager().getViewMetrics(!0),t)||this.resizeEditor_(),!0)}positionTextElement_(e,t){var n=e*2+t;super.positionTextElement_(e+(n<14?(14-n)/2:0),t)}getText_(){return this.isBeingEdited_&&this.htmlInput_?this.htmlInput_.value:null}getEditorText_(e){return`${e}`}getValueFromEditorText_(e){return e}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_INPUT}getAriaValue(){return this.getText()||e.C.FIELD_LABEL_EMPTY}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var t=this.getFocusableElement(),n=this.computeAriaLabel(!0),r,i=this.isCurrentlyEditable()&&!((r=this.getSourceBlock())!=null&&r.isInFlyout);return this.isFullBlockField()?(r=Cn(this.getSourceBlock(),ss.STANDARD,n),i&&(n=r.split(`, `),i=En(this.getSourceBlock()),i=i===void 0?-1:n.indexOf(i),i=i===-1?0:i+1,n[i]=e.C.FIELD_LABEL_EDIT_PREFIX.replace(`%1`,n[i]??``),n=n.join(`, `))):i&&(n=e.C.FIELD_LABEL_EDIT_PREFIX.replace(`%1`,n)),m(t,k.LABEL,n),!0}};rm.BORDERRADIUS=4,te(`
903
+ `+this.inlinePath_),this.info_.RTL&&e.flipRTL(),this.recordSizeOnBlock_(),this.info_.outputConnection&&(e.outputShapeType=this.info_.outputConnection.shape.type),e.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_(e){if(!(e.height<=0)){if(Z.isSpacer(e)){let r=e.precedesStatement;var t=e.followsStatement;if(r||t){let i=this.constants_.INSIDE_CORNERS;var n=i.rightHeight;n=e.height-(r?n:0),t=t?i.pathBottomRight:``,e=n>0?C(`V`,e.yPos+n):``,this.outlinePath_+=t+e+(r?i.pathTopRight:``);return}}this.outlinePath_+=C(`V`,e.yPos+e.height)}}drawRightDynamicConnection_(){if(!this.info_.outputConnection)throw Error(`Cannot draw the output connection of a block that doesn't have one`);this.outlinePath_+=this.info_.outputConnection.shape.pathRightDown(this.info_.outputConnection.height)}drawLeftDynamicConnection_(){if(!this.info_.outputConnection)throw Error(`Cannot draw the output connection of a block that doesn't have one`);this.positionOutputConnection_(),this.outlinePath_+=this.info_.outputConnection.shape.pathUp(this.info_.outputConnection.height),this.outlinePath_+=`z`}drawFlatTop_(){var e=this.info_.topRow;this.positionPreviousConnection_(),this.outlinePath_+=vi(e.xPos,this.info_.startY),this.outlinePath_+=C(`h`,e.width)}drawFlatBottom_(){var e=this.info_.bottomRow;this.positionNextConnection_(),this.outlinePath_+=C(`V`,e.baseline),this.outlinePath_+=C(`h`,-e.width)}drawInlineInput_(e){this.positionInlineInputConnection_(e);var t=e.input.name;e.connectedBlock||this.info_.isInsertionMarker||(e=_i(e.xPos+e.connectionWidth,e.centerline-e.height/2)+this.getInlineInputPath(e),this.block_.pathObject.setOutlinePath(t,e))}getInlineInputPath(e){var t=e.width-e.connectionWidth*2,n=e.height;return C(`h`,t)+e.shape.pathRightDown(n)+C(`h`,-t)+e.shape.pathUp(n)+`z`}drawStatementInput_(e){var t=e.getLastInput(),n=t.xPos+t.notchOffset+t.shape.width,r=this.constants_.INSIDE_CORNERS,i=t.shape.pathRight+C(`h`,-(t.notchOffset-r.width))+r.pathTop,a=e.height-2*r.height;t=r.pathBottom+C(`h`,t.notchOffset-r.width)+(t.connectedBottomNextConnection?``:t.shape.pathLeft),this.outlinePath_+=C(`H`,n)+i+C(`v`,a)+t+C(`H`,e.xPos+e.width),this.positionStatementInputConnection_(e)}drawConnectionHighlightPath(e){var t=e.connectionModel;if(t.type===L.NEXT_STATEMENT||t.type===L.PREVIOUS_STATEMENT||t.type===L.OUTPUT_VALUE&&!e.isDynamicShape)return super.drawConnectionHighlightPath(e);e=t.type===L.INPUT_VALUE?_i(e.connectionWidth,-e.height/2)+this.getInlineInputPath(e):_i(e.width,-e.height/2)+e.shape.pathDown(e.height);var n=t.getSourceBlock(),r,i;return(i=(r=n.pathObject).addConnectionHighlight)==null?void 0:i.call(r,t,e,t.getOffsetInBlock(),n.RTL)}},nm=class extends V{constructor(e,t,n,r,i,a,o){if(super(V.SKIP_SETUP),this.imageElement=this.clickHandler=null,this.flipRtl=this.isDirty_=this.EDITABLE=!1,this.altText=``,n=Number(kr(n)),t=Number(kr(t)),isNaN(n)||isNaN(t))throw Error(`Height and width values of an image field must cast to numbers.`);if(n<=0||t<=0)throw Error(`Height and width values of an image field must be greater than 0.`);this.size_=new F(t,n+nm.Y_PADDING),this.imageHeight=n,typeof i==`function`&&(this.clickHandler=i),e!==V.SKIP_SETUP&&(o?this.configure_(o):typeof r==`object`&&r&&!Array.isArray(r)&&(`alt`in r||`flipRtl`in r)?this.configure_(r):(this.flipRtl=!!a,this.altText=typeof r==`string`&&kr(r)||``),this.setValue(kr(e)))}configure_(e){super.configure_(e),e.flipRtl&&(this.flipRtl=e.flipRtl),e.alt&&(this.altText=kr(e.alt))}initView(){this.imageElement=h(A.IMAGE,{height:this.imageHeight+`px`,width:this.size_.width+`px`,alt:this.altText},this.fieldGroup_),this.imageElement.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.value_),this.fieldGroup_&&g(this.fieldGroup_,`blocklyImageField`),this.clickHandler&&(this.imageElement.style.cursor=`pointer`),this.recomputeAriaContext()}updateSize_(){}doClassValidation_(e){return typeof e==`string`?e:null}doValueUpdate_(e){this.value_=e,this.imageElement&&this.imageElement.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.value_),this.recomputeAriaContext()}getFlipRtl(){return this.flipRtl}setAlt(e){e!==this.altText&&(this.altText=e||``,this.imageElement&&this.imageElement.setAttribute(`alt`,this.altText))}isClickable(){return super.isClickable()&&!!this.clickHandler}showEditor_(){this.clickHandler&&this.clickHandler(this)}setOnClickHandler(e){this.clickHandler=e}getText_(){return this.altText}static fromJson(e){if(!e.src||!e.width||!e.height)throw Error(`src, width, and height values for an image field arerequired. The width and height must be non-zero.`);return new this(e.src,e.width,e.height,void 0,void 0,void 0,e)}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_IMAGE}getAriaValue(){return this.altText||null}computeAriaLabel(e){return this.isClickable()?``:super.computeAriaLabel(e)}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var e=this.getFocusableElement();if(!this.isClickable())return p(e,O.NONE),ie(e,k.LABEL),!1;var t=this.getAriaValue()||``;return m(e,k.LABEL,t),!0}};nm.Y_PADDING=1,ci(`field_image`,nm),nm.prototype.DEFAULT_VALUE=``;var rm=class extends V{set size_(e){super.size_=e}get size_(){var e=super.size_;return e.width<14&&(e.width=14),e}constructor(e,t,n){super(V.SKIP_SETUP),this.spellcheck_=!0,this.htmlInput_=null,this.isTextValid_=this.isBeingEdited_=!1,this.onInputWrapper=this.onKeyDownWrapper=this.valueWhenEditorWasOpened_=this.warningIcon=null,this.fullBlockClickTarget_=!1,this.workspace_=null,this.SERIALIZABLE=!0,e!==V.SKIP_SETUP&&(n&&this.configure_(n),this.setValue(e),t&&this.setValidator(t))}configure_(e){super.configure_(e),e.spellcheck!==void 0&&(this.spellcheck_=e.spellcheck)}initView(){if(!this.getSourceBlock())throw new Wu;this.isFullBlockField()||this.createBorderRect_(),this.createTextElement_(),this.fieldGroup_&&g(this.fieldGroup_,`blocklyField`),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot()),this.fieldGroup_&&g(this.fieldGroup_,`blocklyInputField`),this.recomputeAriaContext()}isFullBlockField(){var e=this.getSourceBlock();if(!e)throw new Wu;var t;return this.fullBlockClickTarget_=!((t=this.getConstants())==null||!t.FULL_BLOCK_FIELDS)&&e.isSimpleReporter()}createWarningIcon(){if(!this.sourceBlock_)return null;var e=this.getScaledBBox();return e=e.bottom-e.top,e=h(A.SVG,{class:`blocklyInputWarning`,viewBox:`-4 0 24 16`,x:`0`,y:`0`,height:`${e}px`,width:`${e}px`}),h(A.PATH,{class:`blocklyInputWarningIconShape`,d:`M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z`},e),h(A.PATH,{class:`blocklyInputWarningIconSymbol`,d:`m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z`},e),h(A.RECT,{class:`blocklyInputWarningIconSymbol`,x:`7`,y:`11`,height:`2`,width:`2`},e),e}doValueInvalid_(e,t=!0){this.isBeingEdited_&&(this.isDirty_=!0,this.isTextValid_=!1,e=this.value_,this.value_=this.valueWhenEditorWasOpened_,this.sourceBlock_&&Je()&&this.value_!==e&&t&&b(new(x(E.BLOCK_CHANGE))(this.sourceBlock_,`field`,this.name||null,e,this.value_))),this.recomputeAriaContext()}doValueUpdate_(e){this.isTextValid_=this.isDirty_=!0,this.value_=e,this.recomputeAriaContext()}applyColour(){var e=this.getSourceBlock();if(!e)throw new Wu;this.getConstants().FULL_BLOCK_FIELDS&&this.fieldGroup_&&(!this.isFullBlockField()&&this.borderRect_?(this.borderRect_.style.display=`block`,this.borderRect_.setAttribute(`stroke`,e.getColourTertiary())):e.pathObject.svgPath.setAttribute(`fill`,this.getConstants().FIELD_BORDER_RECT_COLOUR))}getSize(){var e;return(e=this.getConstants())!=null&&e.FULL_BLOCK_FIELDS&&(this.render_(),this.isDirty_=!1),super.getSize()}onLocationChange(){this.isBeingEdited_&&this.resizeEditor_()}render_(){super.render_();var e=this.getSourceBlock();if(!e)throw new Wu;if(this.isBeingEdited_){let t=this.htmlInput_;this.renderWarningIcon(e.RTL,this.isTextValid_),this.isTextValid_?(_(t,`blocklyInvalidInput`),m(t,k.INVALID,!1)):(g(t,`blocklyInvalidInput`),m(t,k.INVALID,!0))}this.getConstants().FULL_BLOCK_FIELDS&&e.applyColour()}renderWarningIcon(e,t){var n=this.htmlInput_;if(this.warningIcon){if(t)n.style.paddingRight=``,n.style.paddingLeft=``,_(this.warningIcon,`blocklyInputWarningInvalid`);else{t=this.getScaledBBox();var r=t.bottom-t.top;r=(t=!!this.borderRect_)?this.getConstants().FIELD_BORDER_RECT_X_PADDING:r/2,g(this.warningIcon,`blocklyInputWarningInvalid`);let i=this.warningIcon.getBoundingClientRect().width;n.setAttribute(`width`,`${n.offsetWidth+i}px`);let a=i/1.5;e?n.style.paddingRight=`${a}px`:n.style.paddingLeft=`${a}px`,this.size_.width=i,e=t?this.getConstants().FIELD_TEXT_HEIGHT-this.getConstants().FIELD_BORDER_RECT_X_PADDING:0,this.updateSize_(r+e)}}}setSpellcheck(e){e!==this.spellcheck_&&(this.spellcheck_=e,this.htmlInput_&&this.htmlInput_.setAttribute(`spellcheck`,this.spellcheck_))}showEditor_(e,t=!1,n=!0){this.workspace_=this.sourceBlock_.workspace,!t&&this.workspace_.options.modalInputs&&(Bo||Io||Lo)?this.showPromptEditor():this.showInlineEditor(t,n)}showPromptEditor(){Ht(e.C.CHANGE_VALUE_TITLE,this.getText(),e=>{e!==null&&this.setValue(this.getValueFromEditorText_(e)),this.onFinishEditing_(this.value_)})}showInlineEditor(e,t){var n=this.getSourceBlock();if(!n)throw new Wu;Nr(this,n.RTL,this.widgetDispose_.bind(this),this.workspace_,t),this.htmlInput_=this.widgetCreate_(),this.isBeingEdited_=!0,this.valueWhenEditorWasOpened_=this.value_,e||(this.htmlInput_.focus({preventScroll:!0}),this.htmlInput_.select())}widgetCreate_(){var t=this.getSourceBlock();if(!t)throw new Wu;e.B(!0);var n=Xu,r=this.getClickTarget_();if(!r)throw Error(`A click target has not been set.`);g(r,`blocklyEditing`),r=document.createElement(`input`),r.className=`blocklyHtmlInput`,r.setAttribute(`spellcheck`,this.spellcheck_),this.warningIcon=this.createWarningIcon();var i=this.workspace_.getAbsoluteScale(),a=this.getConstants().FIELD_TEXT_FONTSIZE*i+`pt`;if(n.style.fontSize=a,r.style.fontSize=a,a=rm.BORDERRADIUS*i+`px`,this.isFullBlockField()){let e=this.getScaledBBox();a=(e.bottom-e.top)/2+`px`,t=t.getParent()?t.getParent().getColourTertiary():this.sourceBlock_.getColourTertiary(),r.style.border=1*i+`px solid `+t,n.style.borderRadius=a,n.style.transition=`box-shadow 0.25s ease 0s`,this.getConstants().FIELD_TEXTINPUT_BOX_SHADOW&&(n.style.boxShadow=`rgba(255, 255, 255, 0.3) 0 0 0 `+4*i+`px`),t=(e.bottom-e.top)/4,this.warningIcon.style.paddingLeft=`${t}px`,this.warningIcon.style.paddingRight=`${t}px`}return r.style.borderRadius=a,this.warningIcon&&n.appendChild(this.warningIcon),n.appendChild(r),r.value=r.defaultValue=this.getEditorText_(this.value_),r.setAttribute(`data-untyped-default-value`,String(this.value_)),this.resizeEditor_(),this.bindInputEvents_(r),r}widgetDispose_(){this.isBeingEdited_=!1,this.isTextValid_=!0,this.forceRerender(),this.onFinishEditing_(this.value_),this.sourceBlock_&&Je()&&this.valueWhenEditorWasOpened_!==null&&this.valueWhenEditorWasOpened_!==this.value_&&(b(new(x(E.BLOCK_CHANGE))(this.sourceBlock_,`field`,this.name||null,this.valueWhenEditorWasOpened_,this.value_)),this.valueWhenEditorWasOpened_=null),e.B(!1),this.unbindInputEvents_();var t=Xu.style;if(t.width=`auto`,t.height=`auto`,t.fontSize=``,t.transition=``,t.boxShadow=``,this.htmlInput_=null,t=this.getClickTarget_(),!t)throw Error(`A click target has not been set.`);_(t,`blocklyEditing`),this.recomputeAriaContext()}onFinishEditing_(){}bindInputEvents_(e){this.onKeyDownWrapper=o(e,`keydown`,this,this.onHtmlInputKeyDown_),this.onInputWrapper=o(e,`input`,this,this.onHtmlInputChange)}unbindInputEvents_(){this.onKeyDownWrapper&&=(c(this.onKeyDownWrapper),null),this.onInputWrapper&&=(c(this.onInputWrapper),null)}onHtmlInputKeyDown_(t){if(t.key===`Enter`)Fr(this),er(),t.stopPropagation();else if(t.key===`Escape`)this.setValue(this.htmlInput_.getAttribute(`data-untyped-default-value`),!1),Fr(this),er();else if(t.key===`Tab`){t.preventDefault();var n;let r=(n=this.workspace_)==null?void 0:n.getNavigator(),i=e=>(e instanceof rm||e instanceof gf&&e.isSimpleReporter())&&e!==this.getSourceBlock();n=this;do n=t.shiftKey?r==null?void 0:r.getOutNode(n):r==null?void 0:r.getInNode(n);while(n&&!i(n));n=n instanceof gf&&n.isSimpleReporter()?n.getFields().next().value:n,n instanceof rm&&(Fr(this),er(),t=n.getSourceBlock(),n.isFullBlockField()&&t&&t instanceof gf?e.t().focusNode(t):e.t().focusNode(n),n.showEditor())}}onHtmlInputChange(){var e=this.value_;this.setValue(this.getValueFromEditorText_(this.htmlInput_.value),!1),this.sourceBlock_&&Je()&&this.value_!==e&&b(new(x(E.BLOCK_FIELD_INTERMEDIATE_CHANGE))(this.sourceBlock_,this.name||null,e,this.value_))}setEditorValue_(e,t=!0){this.isDirty_=!0,this.isBeingEdited_&&(this.htmlInput_.value=this.getEditorText_(e)),this.setValue(e,t)}resizeEditor_(){At().then(()=>{var e=this.getSourceBlock();if(!e)throw new Wu;var t=Xu,n=this.getScaledBBox();t.style.width=n.right-n.left+`px`,t.style.height=n.bottom-n.top+`px`,e=e.RTL?n.right-t.offsetWidth:n.left,n=n.top;var r=t==null?void 0:t.parentElement;r&&(r=r.getBoundingClientRect(),e-=r.left+window.scrollX,n-=r.top+window.scrollY),t.style.left=`${e}px`,t.style.top=`${n}px`})}repositionForWindowResize(){var e,t=(e=this.getSourceBlock())==null?void 0:e.getRootBlock();return t instanceof gf&&(Ni(this.workspace_,this.workspace_.getMetricsManager().getViewMetrics(!0),t)||this.resizeEditor_(),!0)}positionTextElement_(e,t){var n=e*2+t;super.positionTextElement_(e+(n<14?(14-n)/2:0),t)}getText_(){return this.isBeingEdited_&&this.htmlInput_?this.htmlInput_.value:null}getEditorText_(e){return`${e}`}getValueFromEditorText_(e){return e}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_INPUT}getAriaValue(){return this.getText()||e.C.FIELD_LABEL_EMPTY}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var t=this.getFocusableElement(),n=this.computeAriaLabel(!0),r,i=this.isCurrentlyEditable()&&!((r=this.getSourceBlock())!=null&&r.isInFlyout);return this.isFullBlockField()?(r=Cn(this.getSourceBlock(),ss.STANDARD,n),i&&(n=r.split(`, `),i=En(this.getSourceBlock()),i=i===void 0?-1:n.indexOf(i),i=i===-1?0:i+1,n[i]=e.C.FIELD_LABEL_EDIT_PREFIX.replace(`%1`,n[i]??``),n=n.join(`, `))):i&&(n=e.C.FIELD_LABEL_EDIT_PREFIX.replace(`%1`,n)),m(t,k.LABEL,n),!0}};rm.BORDERRADIUS=4,te(`
904
904
  .blocklyInputWarningIconShape {
905
905
  stroke: #1f1f1f;
906
906
  stroke-width: 1px;