x-block-lib 0.10.34 → 0.10.35

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.
@@ -0,0 +1,2373 @@
1
+ import{r as e,t}from"./rolldown-runtime.81faoggt.js";var n=t(((e,t)=>{(function(n,r){typeof define==`function`&&define.amd?define([],r):typeof e==`object`?t.exports=r():n.Blockly=r()})(e,function(){var e={},t=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=ro[e],o=ao[e];switch(a||(a=ro[e]=Object.create(null),o=ao[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},n=function(e,t){e=`${e}`.toLowerCase(),t=t.toLowerCase();var n=ro[e];n&&n[t]?(delete ro[e][t],delete ao[e][t]):console.warn(`Unable to unregister [`+t+`][`+e+`] from the registry.`)},r=function(e,t,n){e=`${e}`.toLowerCase(),t=t.toLowerCase();var r=ro[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]},i=function(e,t){return e=`${e}`.toLowerCase(),t=t.toLowerCase(),(e=ro[e])?!!e[t]:!1},a=function(e,t,n){return r(e,t,n)},o=function(e,t,n){e=`${e}`.toLowerCase();var r=ro[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=ao[e],n=Object.create(null);for(let t of Object.keys(r))n[e[t]]=r[t];return n},s=function(e,t,n){return t=t.plugins[String(e)]||`default`,typeof t==`function`?t:r(e,t,n)},c=function(e,t){l(),fo=setTimeout(function(){t&&t.handleRightClick(e)},750)},l=function(){fo&&=(clearTimeout(fo),0)},u=function(e){return!e.type.startsWith(`pointer`)||e instanceof PointerEvent&&f(e)},d=function(e){return`${e.pointerId}`},f=function(e){var t=d(e);return lo?lo===t:e.type===`pointerdown`?(lo=t,!0):!1},p=function(e,t,n,r,i,a){function o(e){(i||u(e))&&(n?r.call(n,e):r(e))}var s=[];if(t in uo)for(let n=0;n<uo[t].length;n++){let r=uo[t][n];e.addEventListener(r,o,Object.assign({},{capture:!1},a)),s.push([e,r,o])}else e.addEventListener(t,o,Object.assign({},{capture:!1},a)),s.push([e,t,o]);return s},m=function(e,t,n,r,i){function a(e){n?r.call(n,e):r(e)}var o=[];if(t in uo)for(let n=0;n<uo[t].length;n++){let r=uo[t][n];e.addEventListener(r,a,Object.assign({},{capture:!1},i)),o.push([e,r,a])}else e.addEventListener(t,a,Object.assign({},{capture:!1},i)),o.push([e,t,a]);return o},h=function(e){for(var t=e[e.length-1][2];e.length;){let[t,n,r]=e.pop();t.removeEventListener(n,r,!1)}return t},g=function(e){if(e.target instanceof HTMLElement){if(e.target.isContentEditable||e.target.getAttribute(`data-is-text-input`)===`true`)return!0;if(e.target instanceof HTMLInputElement)return e=e.target,e.type===`text`||e.type===`number`||e.type===`email`||e.type===`password`||e.type===`search`||e.type===`tel`||e.type===`url`;if(e.target instanceof HTMLTextAreaElement)return!0}return!1},_=function(e){return e.ctrlKey&&ko?!0:e.button===2},v=function(e,t,n){var r=t.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,n||=t.getScreenCTM().inverse(),r.matrixTransform(n)},ee=function(e){switch(e.deltaMode){default:return{x:e.deltaX,y:e.deltaY};case 1:return{x:e.deltaX*40,y:e.deltaY*40};case 2:return{x:e.deltaX*125,y:e.deltaY*125}}},y=function(){return`blockly-`+(Lo++).toString(36)},te=function(){return Io.genUid()},b=function(e){Bo.fireInternal(e)},ne=function(){var e=ie(zo);zo.length=0;for(let t of e){if(!t.workspaceId)continue;let e;(e=Ee(t.workspaceId))==null||e.fireChangeListener(t)}},re=function(e){if(e.type===N.BLOCK_CHANGE&&e.element===`mutation`){let t;for(t=zo.length;t>0;t--){let n=zo[t-1];if(n.group!==e.group||n.workspaceId!==e.workspaceId||n.type!==N.BLOCK_MOVE||n.newParentId!==e.blockId)break}zo.splice(t,0,e)}else zo.push(e)},ie=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?n.type===N.BLOCK_MOVE&&e.type===N.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===N.BLOCK_CHANGE&&e.type===N.BLOCK_CHANGE&&n.blockId===e.blockId&&n.element===e.element&&n.name===e.name?e.newValue=n.newValue:n.type===N.VIEWPORT_CHANGE&&e.type===N.VIEWPORT_CHANGE?(e.viewTop=n.viewTop,e.viewLeft=n.viewLeft,e.scale=n.scale,e.oldScale=n.oldScale):n.type===N.CLICK&&e.type===N.BUBBLE_OPEN||t.push(n):t.push(n));return e=t.filter(e=>!e.isNull())},ae=function(){for(let e=0,t;t=zo[e];e++)t.recordUndo=!1},oe=function(){return e.Ka===0},se,x,ce,S,C,le,ue,de,fe,w,T,pe,E,me,D,he,ge,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,De,Oe,ke,Ae,je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,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,O,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,k,Kr,qr,Jr,Yr,Xr,A,Zr,Qr,$r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,di,fi,pi,mi,hi,gi,_i,vi,yi,bi,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,j;e.r=function(e){Bo.setGroupInternal(e)},se=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=r(M.EVENT,e,void 0);if(!t)throw Error(`Event type ${e} not found in registry.`);return t},ce=function(e){e.removeAttribute(`role`)},S=function(e,t){t?e.setAttribute(`role`,t):ce(e)},C=function(e,t,n){Array.isArray(n)&&(n=n.join(` `)),e.setAttribute(`aria-`+t,`${n}`)},le=function(e,t){e.removeAttribute(`aria-`+t)},ue=function(e,t){return(e=e.getAttribute(`aria-`+t))?e:null},de=function(e){if(!Xo||!document.contains(Xo)){var t=document.createElement(`div`);t.textContent=``,t.id=`blocklyAriaAnnounce`,T(t,`hiddenForAria`),C(t,F.LIVE,Vo.POLITE),S(t,Ko),C(t,F.ATOMIC,!0),e.appendChild(t),Xo=t}},fe=function(e,t){if(!Xo)throw Error(`ARIA live region not initialized.`);var n=Xo,{assertiveness:r=Vo.POLITE,role:i=Ko}=t||{};Wo.push(e),Uo=r===Vo.ASSERTIVE||Uo===Vo.ASSERTIVE?Vo.ASSERTIVE:r===Vo.POLITE||Uo===Vo.POLITE?Vo.POLITE:Vo.OFF,clearTimeout(Zo),Zo=setTimeout(()=>{n.replaceChildren(),C(n,F.LIVE,Uo),S(n,i);var e=document.createElement(`span`);e.textContent=Wo.join(`
2
+ `)+(Qo?`\xA0`:``),Qo=!Qo,n.appendChild(e),Wo.length=0,Uo=Vo.OFF},10)},w=function(e,t,n){var r=document.createElementNS(`http://www.w3.org/2000/svg`,`${e}`);e!==I.SVG.toString()&&e!==I.G.toString()&&r.tagName!==I.SVG.toString()&&r.tagName!==I.G.toString()||S(r,P.PRESENTATION);for(let e in t)r.setAttribute(e,`${t[e]}`);return n&&n.appendChild(r),r},T=function(e,t){return t=t.split(` `),t.every(t=>e.classList.contains(t))?!1:(e.classList.add(...t),!0)},pe=function(e,t){e.classList.remove(...t.split(` `))},E=function(e,t){return t=t.split(` `),t.every(t=>!e.classList.contains(t))?!1:(e.classList.remove(...t),!0)},me=function(e,t){return e.classList.contains(t)},D=function(e){return e&&e.parentNode?e.parentNode.removeChild(e):null},he=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)},ge=function(e,t){e.style.transform=t,e.style[`-webkit-transform`]=t},_e=function(){rs++,ns||=Object.create(null)},ve=function(){rs--,rs||(ns=null)},ye=function(e){var t=e.textContent+`
3
+ `+e.className.baseVal,n;return ns&&(n=ns[t])?n:(n=window.getComputedStyle(e),n=be(e,n.fontSize,n.fontWeight,n.fontFamily),ns&&(ns[t]=n),n)},be=function(e,t,n,r){var i=e.textContent;e=i+`
4
+ `+e.className.baseVal;var a;return ns&&(a=ns[e])?a:(is||=(a=document.createElement(`canvas`),a.className=`blocklyComputeCanvas`,document.body.appendChild(a),a.getContext(`2d`)),i&&is?(is.font=n+` `+t+` `+r,a=is.measureText(i).width):a=0,ns&&(ns[e]=a),a)},xe=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.A=function(){return cs.getFocusManager()},Se=function(e){return e&&typeof e.getFocusableElement==`function`&&typeof e.getFocusableTree==`function`&&typeof e.onNodeFocus==`function`&&typeof e.onNodeBlur==`function`&&typeof e.canBeFocused==`function`},Ce=function(e){return Se(e)&&typeof e.id==`string`&&typeof e.workspace==`object`&&typeof e.select==`function`&&typeof e.unselect==`function`},we=function(e,t){for(let n in t)t[n]!==null&&Array.isArray(t[n])?e[n]=we(e[n]||[],t[n]):e[n]=t[n]!==null&&typeof t[n]==`object`?we(e[n]||Object.create(null),t[n]):t[n];return e},Te=function(e,t,n,r){e=e+` was deprecated in `+t+` and will be deleted in `+n+`.`,r&&(e+=`
5
+ Use `+r+` instead.`),fs.has(e)||(fs.add(e),console.warn(e))},Ee=function(e){return R[e]||null},De=function(){var e=[];for(let t in R)e.push(R[t]);return e},Oe=function(e){R[e.id]=e},ke=function(e){delete R[e.id]},Ae=function(){return ms},je=function(t){ms=t,t.rendered&&e.A().setPopoverFocusRoot(t.getInjectionDiv())},Me=function(){var t=e.A().getFocusedNode();return t&&Ce(t)?t:null},Ne=function(e){var t=Me();b(new(x(N.SELECTED))(t?.id??null,e?.id??null,e?.workspace.id??t?.workspace.id??``))},Pe=function(e=ms){return hs||(e&&e.rendered?e.getInjectionDiv():null)},Fe=function(e){hs=e},Ie=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()}},Le=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},Re=function(e){return function(){this.jsonInit(e)}},ze=function(e){_s.defineBlocksWithJsonArrayInternal(e)},e.Nb=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:Re(r)}:console.warn(`Block definition #${n} in JSON array is missing a type attribute. Skipping.`)}return t},e.Pb=function(e){for(let t of Object.keys(e)){let n=e[t];t in so&&console.warn(`Block definition "${t}" overwrites previous definition.`),so[t]=n}},Be=function(t){var n=ms,r=e.A().getFocusedTree();for(let e of De())if(r===e){n=e;break}!g(t)&&n&&(!n.rendered||n.isFlyout||n.isVisible())&&L.registry.onKeyDown(n,t)},Ve=function(e,t){return t=e.indexOf(t),t===-1?!1:(e.splice(t,1),!0)},He=function(e){As.push(e)},Ue=function(e,t,n){t&&typeof window<`u`&&(e=e.getRootNode(),ks.has(e)||(ks.add(e),n=n.replace(/[\\/]$/,``),n=[js,...As].join(`
6
+ `).replace(/<<<PATH>>>/g,n),t=document.createElement(`style`),t.id=`blockly-common-style`,t.textContent=n,(globalThis.ShadowRoot!==void 0&&e instanceof ShadowRoot?e:document.head).prepend(t)))},We=function(t){Object.keys(t).forEach(function(n){e.C[n]=t[n]})},Ge=function(e){return Ps.getSizeInternal(e)},Ke=function(e,t){return e=window.getComputedStyle(e),e[t]||e.getPropertyValue(t)},qe=function(e){var t=new z(0,0);e=e.getBoundingClientRect();var n=document.documentElement;return n=new z(window.pageXOffset||n.scrollLeft,window.pageYOffset||n.scrollTop),t.x=e.left+n.x,t.y=e.top+n.y,t},Je=function(){var e=document.body,t=document.documentElement;return new z(e.scrollLeft||t.scrollLeft,e.scrollTop||t.scrollTop)},Ye=function(e){var t=parseFloat(Ke(e,`borderLeftWidth`)),n=parseFloat(Ke(e,`borderRightWidth`)),r=parseFloat(Ke(e,`borderTopWidth`));return e=parseFloat(Ke(e,`borderBottomWidth`)),new B(r,e,t,n)},Xe=function(e,t,n){e=Ze(e,t,n),t.scrollLeft=e.x,t.scrollTop=e.y},Ze=function(e,t,n){var r=qe(e),i=qe(t),a=Ye(t),o=r.x-i.x-a.left;return r=r.y-i.y-a.top,i=new V(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 z(a,t)},Qe=function(e){var t=new z(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(Is))&&(t.x+=Number(n[1]),n[3]&&(t.y+=Number(n[3]))),(e=e.getAttribute(`style`))&&e.includes(`translate`)&&(e=e.match(Ls))&&(t.x+=Number(e[1]),e[3]&&(t.y+=Number(e[3]))),t},$e=function(e){for(var t=0,n=0;e;){let r=Qe(e);if(t+=r.x,n+=r.y,(` `+(e.getAttribute(`class`)||``)+` `).includes(` injectionDiv `))break;e=e.parentNode}return new z(t,n)},et=function(){var e=Je();return new B(e.y,document.documentElement.clientHeight+e.y,e.x,document.documentElement.clientWidth+e.x)},tt=function(){var e=document.documentElement,t=window;return new z(t.pageXOffset||e.scrollLeft,t.pageYOffset||e.scrollTop)},nt=function(e,t){var n=t.x;t=t.y;var r=e.getInjectionDiv().getBoundingClientRect();return n=new z(n-r.left,t-r.top),t=e.getOriginOffsetInPixels(),z.difference(n,t).scale(1/e.scale)},rt=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 z(t+r.left+e.x,n+r.top+e.y)},e.F=function(e){return Hs.createElementNS(`https://developers.google.com/blockly/xml`,e)},e.rc=function(e){return Hs.createTextNode(e)},e.tc=function(e){var t=Bs.parseFromString(e,`text/xml`);if(t&&t.documentElement&&!t.getElementsByTagName(`parsererror`).length)return t.documentElement;if((t=Bs.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}`)},it=function(e){return at(Vs.serializeToString(e))},at=function(e){return e.replace(Gs,e=>`&#${e.charCodeAt(0)};`)},ot=function(e){if(!e)return null;if(e instanceof Element||typeof e==`string`){e=ft(e);var t={contents:ut(e)};e instanceof Node&&dt(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},st=function(e){return e?e.contents?e.contents:Array.isArray(e)&&e.length>0&&!e[0].nodeType?e:ut(e):[]},ct=function(e){return Js.hasCategoriesInternal(e)},lt=function(e){return e&&e.contents?!!e.contents.filter(function(e){return e.kind.toUpperCase()===`CATEGORY`}).length:!1},ut=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=ut(i)),dt(i,e),t.push(e)}return t},dt=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}},ft=function(t){var n=null;if(t)if(typeof t==`string`){if(n=e.tc(t),n.nodeName.toLowerCase()!==`xml`)throw TypeError(`Toolbox should be an <xml> document.`)}else t instanceof Element&&(n=t);return n},pt=function(e,t,n,r,i,a){var o=a.scrollbar&&a.scrollbar.canScrollVertically();return e.horizontal===Qs.LEFT?(n=i.absoluteMetrics.left+n,o&&a.RTL&&(n+=zs.scrollbarThickness)):(n=i.absoluteMetrics.left+i.viewMetrics.width-t.width-n,o&&!a.RTL&&(n-=zs.scrollbarThickness)),e.vertical===Xs.TOP?e=i.absoluteMetrics.top+r:(e=i.absoluteMetrics.top+i.viewMetrics.height-t.height-r,a.scrollbar&&a.scrollbar.canScrollHorizontally()&&(e-=zs.scrollbarThickness)),new B(e,e+t.height,n,n+t.width)},mt=function(e,t){return{horizontal:t.toolboxMetrics.position===H.LEFT||e.horizontalLayout&&!e.RTL?Qs.RIGHT:Qs.LEFT,vertical:t.toolboxMetrics.position===H.BOTTOM?Xs.TOP:Xs.BOTTOM}},ht=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===ec.UP?c.top-o-t:c.bottom+t,e=new B(e,e+o,i,i+a),s=-1)}return e},gt=function(e,n){t(M.SERIALIZER,e,n)},_t=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},vt=function(t,n,{recordUndo:r=!1}={}){var i=e.Pc;if(e.Pc=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 z(i,n))}return(t.width!==void 0||t.height)&&(a=r.getSize(),r.setSize(new V(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.Pc=i,r},yt=function(e,n){t(M.PASTER,e,n)},bt=function(e){for(var t=e.workspace,n=e.getRelativeToSurfaceXY(),r=new z(0,0),i=t.getTopComments(!1).filter(t=>t.id!==e.id).map(e=>e.getRelativeToSurfaceXY());xt(z.sum(n,r),i);)r.translate(t.RTL?-30:30,30);e.moveTo(z.sum(n,r))},xt=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},St=function(e){return e&&typeof e.saveState==`function`&&typeof e.loadState==`function`},Ct=function(e){return Et(e),wo?(Dt(),Promise.resolve()):(xc||=new Promise(e=>{Sc=e,Cc=window.requestAnimationFrame(()=>{Dt(),e()})}),xc)},wt=function(){return xc||Promise.resolve()},Tt=function(e){e||window.cancelAnimationFrame(Cc),Dt(e),!e&&Sc&&Sc()},Et=function(t){yc.add(t),bc.set(t,e.fd);var n=t.getParent();n?Et(n):vc.add(t)},Dt=function(t){var n=t?new Set([t]):new Set([...vc].map(e=>e.workspace)),r=[...vc].filter(kt).filter(e=>n.has(e.workspace));for(var i of r)At(i);for(let e of n)e.resizeContents();for(var a of r)i=a.getRelativeToSurfaceXY(),a.updateComponentLocations(i);for(let t of r)a=e.fd,(i=bc.get(t))&&e.r(i),t.bumpNeighbours(),e.r(a);for(let e of r)Ot(e);t||(xc=null)},Ot=function(e){vc.delete(e),yc.delete(e),bc.delete(e);for(let t of e.getChildren(!1))Ot(t)},kt=function(e){return!e.isDisposed()&&!e.getParent()},At=function(e){if(yc.has(e)&&e.initialized){for(let t of e.getChildren(!1))At(t);e.renderEfficiently()}},jt=function(e,t){Lt(Ec.ALERT,e,t,void 0)},Mt=function(e,t){Lt(Ec.CONFIRM,e,t,void 0)},Nt=function(e,t,n){Lt(Ec.PROMPT,e,n,t)},Pt=function(e,t){kc(e,t)},Ft=function(e,t){Ac(e,t)},It=function(e,t,n){jc(e,t,n)},Lt=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===Ec.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===Ec.CONFIRM||t===Ec.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;Oc===0&&(d=e.A().takeEphemeralFocus(a)),Oc++,a.addEventListener(`close`,()=>{if(Oc--,!Oc){let e;(e=d)==null||e()}switch(a.remove(),t){case Ec.CONFIRM:r(a.returnValue===`ok`);break;case Ec.PROMPT:r(a.returnValue===`ok`?c.value:null);break;case Ec.ALERT:r?.()}}),document.body.appendChild(a),a.showModal()},Rt=function(e){return typeof e.bubbleIsVisible==`function`&&typeof e.setBubbleVisible==`function`&&typeof e.getBubble==`function`},zt=function(e,t){return t.map(t=>e.getBlockById(t)).filter(e=>e&&e.isShadow()).length===t.length},Bt=function(e){return e&&typeof e.getProcedureDef==`function`},Vt=function(e){return e.getVariableModel!==void 0},e.Ad=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.Bd=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())},Ht=function(e){return so.variables_set||so.variables_get||console.warn(`There are no variable blocks, but there is a variable category.`),e.registerButtonCallback(`CREATE_VARIABLE`,function(e){qt(e.getTargetWorkspace())}),[{kind:`button`,text:`%{BKY_NEW_VARIABLE}`,callbackkey:`CREATE_VARIABLE`},...Wt(e,e.getVariableMap().getVariablesOfType(``),!0)]},Ut=function(e){return{VAR:{name:e.getName(),type:e.getType()}}},Wt=function(e,t,n,r=`variables_get`,i=`variables_set`){n&&=so.math_change,e=[];var a=t.slice(-1)[0];return a&&(so[i]&&e.push({kind:`block`,type:i,gap:n?8:24,fields:Ut(a)}),n&&e.push({kind:`block`,type:`math_change`,gap:so[r]?20:8,fields:Ut(a),inputs:{DELTA:{shadow:{type:`math_number`,fields:{NUM:1}}}}})),so[r]&&e.push(...t.sort(nn).map(e=>({kind:`block`,type:r,gap:8,fields:Ut(e)}))),e},Gt=function(e){return Rl.generateUniqueNameInternal(e)},Kt=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},qt=function(t,n,r){function i(r){Jt(e.C.NEW_VARIABLE_TITLE,r,function(r){if(r){var o=Xt(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());Pt(s,function(){i(r)})}else{let i=t.getVariableMap().createVariable(r,a);n&&n(r);let o=(s=t.getFlyout())?.getWorkspace();if(o&&Ll.getIsActive()){var c=t=>{t.type===e.Nd&&(t=t.blockId)&&(t=o.getBlockById(t))&&t.type===`variables_set`&&t.getFieldValue(`VAR`)===i.getId()&&(e.A().focusNode(t),o.removeChangeListener(c))};o.addChangeListener(c)}}}else n&&n(null)})}var a=r||``;i(``)},e.Qd=function(t,n,r){function i(a){var o=e.C.RENAME_VARIABLE_TITLE.replace(`%1`,n.getName());Jt(o,a,function(a){if(a){var o=Yt(a,n.getType(),t),s=Zt(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)),Pt(c,function(){i(a)})}else t.getVariableMap().renameVariable(n,a),r&&r(a)}else r&&r(null)})}i(``)},Jt=function(t,n,r){It(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)})},Yt=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},Xt=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},Zt=function(e,t,n){return n.getProcedureMap().getProcedures().length?Qt(e,t,n):$t(e,t,n)},Qt=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getProcedureMap().getProcedures();for(let i of n){var r=i.getParameters().filter(Vt).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},$t=function(e,t,n){e=e.toLowerCase(),t=t.toLowerCase(),n=n.getAllBlocks(!1);for(let i of n){if(!Bt(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},en=function(t){var n=e.F(`field`);return n.setAttribute(`name`,`VAR`),n.setAttribute(`id`,t.getId()),n.setAttribute(`variabletype`,t.getType()),t=e.rc(t.getName()),n.appendChild(t),n},e.Vd=function(t,n,r,i){var a=e.Ud(t,n,r,i);if(!a){a=t.getVariableMap();let e=t.getPotentialVariableMap();r||=Gt(t.isFlyout?t.targetWorkspace:t),a=e?e.createVariable(r,i,n??void 0):a.createVariable(r,i,n)}return a},e.Ud=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},tn=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},nn=function(e,t){return e.getName().localeCompare(t.getName(),void 0,{sensitivity:`base`})},rn=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.Yd=function(t,n,r){var i=n.getName(),a=rn(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),kc(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),Ft(i,e=>{e&&n&&t.getVariableMap().deleteVariable(n)})):t.getVariableMap().deleteVariable(n)},an=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=jr(t).replace(` xmlns="https://developers.google.com/blockly/xml"`,``))),t=Object.create(null);for(var c of e.getIcons())St(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=on(c.connection,i,a))&&(n[c.name]=t);Object.keys(n).length&&(o.inputs=n)}return r&&e.nextConnection&&(e=on(e.nextConnection,i,a))&&(o.next=e),o},on=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=an(e,{doFullSerialization:t,saveIds:n})),i},sn=function(e,t,{recordUndo:n=!1}={}){return e=cn(e,t,{recordUndo:n}),t.rendered&&Tt(),e},cn=function(t,n,{parentConnection:r,isShadow:i=!1,recordUndo:a=!1}={}){var o=e.Pc;e.Pc=a,(a=e.fd)||e.r(!0),e.Ka++;var s=n.getVariableMap().getAllVariables();try{var c=ln(t,n,{parentConnection:r,isShadow:i})}finally{e.Ka--}if(un(n,s),oe()&&b(new(x(N.BLOCK_CREATE))(c)),e.r(a),e.Pc=o,n.rendered){let e=c;setTimeout(()=>{e.disposed||e.setConnectionTracking(!0)},1)}return c},ln=function(t,n,{parentConnection:i,isShadow:a=!1}={}){if(!t.type)throw new Vl(t);var o=n.newBlock(t.type,t.id);o.setShadow(a),a=t.x===void 0?0:t.x;var s=t.y===void 0?0:t.y,c=o.workspace;if(a=c.RTL?c.getWidth()-a:a,o.moveBy(a,s),t.collapsed&&o.setCollapsed(!0),t.deletable===!1&&o.setDeletable(!1),t.movable===!1&&o.setMovable(!1),t.editable===!1&&o.setEditable(!1),t.enabled===!1&&o.setDisabledReason(!0,`MANUALLY_DISABLED`),Array.isArray(t.disabledReasons))for(var l of t.disabledReasons)o.setDisabledReason(!0,l);if(t.inline!==void 0&&o.setInputsInline(t.inline),t.data!==void 0&&(o.data=t.data),t.extraState&&(o.loadExtraState?o.loadExtraState(t.extraState):o.domToMutation&&o.domToMutation(e.tc(t.extraState))),i){if(i.getSourceBlock().isShadow()&&!o.isShadow())throw new Wl(t);if(i.type===e.he.VALUE){if(l=o.outputConnection,!l)throw new Hl(`output`,o,t)}else if(l=o.previousConnection,!l)throw new Hl(`previous`,o,t);if(!i.connect(l))throw n=o.workspace.connectionChecker,new Ul(n.getErrorMessage(n.canConnectWithReason(l,i,!1),l,i),i.type===e.he.VALUE?`output connection`:`previous connection`,o,t)}if(t.icons){i=Object.keys(t.icons);for(var u of i){if(i=t.icons[u],l=o.getIcon(u),!l){if(l=r(M.ICON,u,!1),!l)throw new Gl(u,o,t);l=new l(o),o.addIcon(l)}St(l)&&l.loadState(i)}}if(t.fields)for(u=Object.keys(t.fields),i=0;i<u.length;i++)l=u[i],a=t.fields[l],(s=o.getField(l))?s.loadState(a):console.warn(`Ignoring non-existant field ${l} in block ${o.type}`);if(t.inputs)for(u=Object.keys(t.inputs),i=0;i<u.length;i++){if(l=u[i],a=o.getInput(l),!a||!a.connection)throw new Hl(l,o,t);dn(a.connection,t.inputs[l])}if(t.next){if(!o.nextConnection)throw new Hl(`next`,o,t);dn(o.nextConnection,t.next)}if(n.rendered){o.setConnectionTracking(!1),o.initSvg(),o.queueRender();for(let e of o.getIcons())e.onLocationChange(o.getRelativeToSurfaceXY())}else o.initModel();return o},un=function(e,t){if(oe())for(e=tn(e,t),t=0;t<e.length;t++){let n=e[t];b(new(x(N.VAR_CREATE))(n))}},dn=function(e,t){t.shadow&&e.setShadowState(t.shadow),t.block&&ln(t.block,e.getSourceBlock().workspace,{parentConnection:e})},fn=function(e){return e=pn(e,Yl),e.length?e[0].join(jo?` `:` + `):``},pn=function(t,n){if(t=L.registry.getKeyCodesByShortcutName(t),t.length===0)return[];t=t.map(e=>e.split(`+`)),t.forEach(e=>e.sort((e,t)=>(e=mn(e),t=mn(t),e-t))),t.sort((e,t)=>(e=+!!e.includes(`Meta`),+!!t.includes(`Meta`)-e));var r=t.filter(e=>e.includes(`Meta`)===jo);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)}))},mn=function(e){return e=Xl.indexOf(e),e===-1?Number.MAX_VALUE:e},hn=function(e){return e*Math.PI/180},gn=function(e,t,n){if(n<e){let t=n;n=e,e=t}return Math.max(e,Math.min(t,n))},_n=function(){document.querySelector(`.blocklyDropDownDiv`)||(nu=document.createElement(`div`),nu.className=`blocklyDropDownDiv`,nu.tabIndex=-1,nu.id=y(),(Pe()||document.body).appendChild(nu),ru=document.createElement(`div`),ru.className=`blocklyDropDownContent`,nu.appendChild(ru),lu=p(ru,`keydown`,null,Be),iu=document.createElement(`div`),iu.className=`blocklyDropDownArrow`,nu.appendChild(iu),nu.style.opacity=`0`,nu.style.transition=`transform 0.25s, opacity 0.25s`)},vn=function(){cu&&=(cu(!1),null),An()},yn=function(){lu&&=(h(lu),null),nu.remove(),_n()},bn=function(e,t){nu.style.backgroundColor=e,nu.style.borderColor=t},xn=function(e,t,n,r=!0){return su=!0,wn(Cn(e),e,r,t,n)},Sn=function(e){var t=e.getSvgRoot(),n=e.workspace.scale,r=e.height*n;return e=e.width*n,t=qe(t),new B(t.y,t.y+r,t.x,t.x+e)},Cn=function(e){return e=e.getScaledBBox(),new B(e.top,e.bottom,e.left,e.right)},wn=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 au=s.getParentSvg().parentNode,Tn(t,i.RTL,a,o,a,e,n,r)},Tn=function(t,n,r,i,a,o,s,c){e.A().registerPopoverFocusLossHandler(vn);var l;return(l=Pe())==null||l.appendChild(nu),ou=t,$l=c||null,nu.style.direction=n?`rtl`:`ltr`,t=ms,eu=t.getRenderer().getClassName(),tu=t.getTheme().getClassName(),T(nu,eu),T(nu,tu),n=ue(t.getFocusableElement(),F.OWNS),C(t.getFocusableElement(),F.OWNS,n?[n,nu.id]:nu.id),t.getFocusableElement().classList.add(`blocklyShowingDropDownDiv`),r=Mn(r,i,a,o),s&&(cu=e.A().takeEphemeralFocus(nu)),r},En=function(e,t,n,r){return e=On(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}},Dn=function(e,t,n,r){return e=On(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}},On=function(e,t,n,r){return t=gn(t,e-r/2,n-r),e=e-8-t,e=gn(12,e,r-12-16),{arrowX:e,divX:t}},kn=function(e,t){return ou===e?(t?jn():An(),!0):!1},An=function(){ou&&(e.A().unregisterPopoverFocusLossHandler(vn),nu.style.transform=`translate(0, 0)`,nu.style.opacity=`0`,Ql=setTimeout(function(){jn()},250),$l&&=($l(),null))},jn=function(){if(ou){Ql&&clearTimeout(Ql),$l&&=($l(),null),ou=null;var e=ms,t=ue(e.getFocusableElement(),F.OWNS)??``;C(e.getFocusableElement(),F.OWNS,t.replace(nu.id,``)),e.getFocusableElement().classList.remove(`blocklyShowingDropDownDiv`),e.markFocused(),cu&&=(cu(),null),yn()}},Mn=function(e,t,n,r){e=uu.getPositionMetrics(e,t,n,r),e.arrowVisible?(t=e.arrowX,n=e.arrowY,r=e.arrowAtTop?45:225,iu.style.display=``,iu.style.transform=`translate(${t}px, ${n}px) rotate(${r}deg)`,iu.setAttribute(`class`,`blocklyDropDownArrow`)):iu.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=nu.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),nu.style.left=t+`px`,nu.style.top=n+`px`,nu.style.visibility=`visible`,nu.style.opacity=`1`,nu.style.transform=`translate(`+(r-t)+`px,`+(i-n)+`px)`,!!e.arrowAtTop},Nn=function(){if(ou){var e=ou.getSourceBlock();e=su?Cn(ou):Sn(e);let t=e.left+(e.right-e.left)/2;Mn(t,e.bottom,t,e.top)}else An()},Pn=function(e){return e.length?e.reduce(function(e,t){return e.length<t.length?e:t}).length:0},Fn=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=Pn(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},In=function(e,t){if(!e.length)return 0;if(e.length===1)return e[0].length;var n=0;t||=Pn(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.cf=function(e,t){e=e.split(`
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=Rn(u,s,a),o=Ln(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
+ `:` `);i=c.join(``),d++}while(o>n);a=r}e[n]=a}return e.join(`
9
+ `)},Ln=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},Rn=function(e,t,n){var r=Ln(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=Ln(e,o,n);if(s>r){r=s;var i=o}}return i?Rn(e,i,n):t},e.df=function(e){return/^\s*-?\d+(\.\d+)?\s*$/.test(e)},zn=function(e){if(e=Bn(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``},Bn=function(e){for(;e&&e.tooltip;){if(typeof e.tooltip==`string`||typeof e.tooltip==`function`)return e;e=e.tooltip}return null},Vn=function(){document.querySelector(`.blocklyTooltipDiv`)||(Su=document.createElement(`div`),Su.className=`blocklyTooltipDiv`,(Pe()||document.body).appendChild(Su))},Hn=function(e){e.mouseOverWrapper_=m(e,`pointerover`,null,Wn),e.mouseOutWrapper_=m(e,`pointerout`,null,Gn),e.addEventListener(`pointermove`,Kn,!1)},Un=function(e){e&&(h(e.mouseOverWrapper_),h(e.mouseOutWrapper_),e.removeEventListener(`pointermove`,Kn))},Wn=function(e){hu||(e=Bn(e.currentTarget),bu!==e&&(Jn(),xu=null,bu=e),clearTimeout(gu))},Gn=function(){hu||(gu=setTimeout(function(){xu=bu=null,Jn()},1),clearTimeout(_u),_u=0)},Kn=function(e){if(bu&&bu.tooltip&&!hu)if(mu){let t=vu-e.pageX;e=yu-e.pageY,Math.sqrt(t*t+e*e)>10&&Jn()}else xu!==bu&&(clearTimeout(_u),vu=e.pageX,yu=e.pageY,_u=setTimeout(()=>{if(this instanceof Element)for(let t of De()){if(!t.rendered)continue;let n;if((n=t.getInjectionDiv())!=null&&n.contains(this)){var e=t;break}}Zn(e)},750))},qn=function(){xu=bu=null,Jn()},Jn=function(){mu&&(mu=!1,Su&&(Su.style.display=`none`)),_u&&=(clearTimeout(_u),0)},Yn=function(e,t){bu!==e&&(Jn(),xu=null,bu=e),bu&&bu.tooltip&&!hu&&(e=e.getFocusableElement().getBoundingClientRect(),vu=bu.RTL?e.x+e.width:e.x,yu=e.y+e.height,Zn(t))},Xn=function(){Jn(),hu=!0},Zn=function(t){if(!hu&&(xu=bu,Su)){var n;if((n=Pe(t))==null||n.appendChild(Su),Su.textContent=``,Su&&bu)if(typeof pu==`function`)pu(Su,bu);else for(t=zn(bu),t=e.cf(t,50),t=t.split(`
10
+ `),n=0;n<t.length;n++){var r=document.createElement(`div`);r.appendChild(document.createTextNode(t[n])),Su.appendChild(r)}t=bu.RTL,Su.style.direction=t?`rtl`:`ltr`,Su.style.display=`block`,mu=!0,n=document.documentElement.clientWidth,r=document.documentElement.clientHeight;var i=vu;i=t?i-(0+Su.offsetWidth):i+0;var a=yu+10,o,s=(o=Su)?.parentElement;s&&(o=s.getBoundingClientRect(),i-=o.left+window.scrollX,a-=o.top+window.scrollY),a+Su.offsetHeight>r+window.scrollY&&(a-=Su.offsetHeight+20),t?i=Math.max(5-window.scrollX,i):i+Su.offsetWidth>n+window.scrollX-10&&(i=n-Su.offsetWidth-10);var{x:c,y:l}={x:i,y:a};Su.style.left=c+`px`,Su.style.top=l+`px`}},Qn=function(e){e=`${e}`.toLowerCase().trim();var t=Eu[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)?$n(e,t,n):null},$n=function(e,t,n){return t=e<<16|t<<8|n,e<16?`#`+(16777216|t).toString(16).substr(1):`#`+t.toString(16)},er=function(e){return e=Qn(e),e?(e=parseInt(e.substr(1),16),[e>>16,e>>8&255,e&255]):[0,0,0]},tr=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 $n(Math.floor(r),Math.floor(i),Math.floor(a))},nr=function(e,t,n){return e=Qn(e),!e||(t=Qn(t),!t)?null:(e=er(e),t=er(t),$n(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]))))},rr=function(e){return tr(e,wu,Tu*255)},ir=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,ir(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},ar=function(e){return ir(e,!0,!0)},O=function(e){return typeof e==`string`?(e=ir(e,!1,!1),e.length?String(e[0]):``):e},or=function(e){var t=typeof e==`string`?O(e):e,n=Number(t);if(!isNaN(n)&&0<=n&&n<=360)return{hue:n,hex:tr(n,wu,Tu*255)};if(n=Qn(t))return{hue:null,hex:n};throw n=`Invalid colour: "`+t+`"`,e!==t&&(n+=` (from "`+e+`")`),Error(n)},sr=function(){Lu&&=(Lu(!1),null),ur()},cr=function(){var e=Pe()||document.body,t=document.querySelector(`div.blocklyWidgetDiv`);t?Iu=t:(Iu=document.createElement(`div`),Iu.id=y(),Iu.className=`blocklyWidgetDiv`,Iu.tabIndex=-1),p(Iu,`keydown`,null,Be),e.appendChild(Iu)},lr=function(t,n,r,i,a=!0){if(ur(),ju=t,Nu=r,r=Iu){Mu=i??ms;var o=ue(Mu.getFocusableElement(),F.OWNS);C(Mu.getFocusableElement(),F.OWNS,o?[o,r.id]:r.id),Mu.getFocusableElement().classList.add(`blocklyShowingWidgetDiv`);var s;(s=Pe())==null||s.appendChild(r),r.style.direction=n?`rtl`:`ltr`,r.style.display=`block`,!i&&t instanceof ku&&t.getSourceBlock(),Pu=Mu.getRenderer().getClassName(),Fu=Mu.getTheme().getClassName(),Pu&&T(r,Pu),Fu&&T(r,Fu),a&&(Lu=e.A().takeEphemeralFocus(r)),e.A().registerPopoverFocusLossHandler(sr)}},ur=function(){if(ju){ju=null;var t=Iu;if(t){e.A().unregisterPopoverFocusLossHandler(sr),t.style.display=`none`,t.style.left=``,t.style.top=``,Nu&&=(Nu(),null),t.textContent=``,Pu&&=(E(t,Pu),``),Fu&&=(E(t,Fu),``);var n;(n=Mu)==null||n.markFocused(),Lu&&=(Lu(),null),Mu&&Iu&&(t=ue(Mu.getFocusableElement(),F.OWNS)??``,C(Mu.getFocusableElement(),F.OWNS,t.replace(Iu.id,``)),Mu.getFocusableElement().classList.remove(`blocklyShowingWidgetDiv`))}}},dr=function(e){ju===e&&ur()},fr=function(e){for(var t=Mu===null,n=e;!t&&n;){if(n===e){t=!0;break}n=e.options.parentWorkspace}t&&ur()},pr=function(e,t,n){if(Iu){var r=Iu.parentElement;r&&(r=r.getBoundingClientRect(),e-=r.left+window.scrollX,t-=r.top+window.scrollY),Iu.style.left=e+`px`,Iu.style.top=t+`px`,Iu.style.height=n+`px`}},mr=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?pr(e,0,n.height+i):pr(e,i,n.height)},hr=function(){var e;(e=ju)!=null&&e.repositionForWindowResize&&ju.repositionForWindowResize()||ur()},gr=function(e,t,n,r,i){if(lr(Bu,n,xr,r),t.length){i||(e instanceof PointerEvent?i=new z(e.clientX,e.clientY):(console.warn(`Context menu opened with keyboard but no location given`),i=new z(0,0)));var a=_r(t,n,e,i);Vu=a,vr(a,n,i),setTimeout(function(){a.focus()},1),zu=null}else br()},_r=function(e,t,n,r){var i=new hc;i.setRole(P.MENU);for(let a=0;a<e.length;a++){let o=e[a];if(o.separator){i.addChild(new gc);continue}let s=new mc(Sr(o));s.setRightToLeft(t),s.setRole(P.MENUITEM),i.addChild(s),s.setEnabled(o.enabled),o.enabled&&s.onAction(function(e,t){br(),requestAnimationFrame(()=>{setTimeout(()=>{o.callback(o.scope,n,t,r)},0)})},{})}return i},vr=function(e,t,n){var r=et();n=new B(n.y+r.top,n.y+r.top,n.x+r.left,n.x+r.left);var i=Iu;if(!i)throw Error(`Attempting to create a context menu when widget div is null`);i=e.render(i),T(i,`blocklyContextMenu`),p(i,`contextmenu`,null,yr),e.focus(),i=e.getSize(),t&&(n.left+=i.width,n.right+=i.width,r.left+=i.width,r.right+=i.width),mr(r,n,i,t),e.focus()},yr=function(e){e.preventDefault(),e.stopPropagation()},br=function(){dr(Bu),zu=null;var e;(e=Vu)==null||e.dispose(),Vu=null},xr=function(){Vu&&=(Vu.dispose(),null)},e.ug=function(t,n){return()=>{e.Ka++;try{var r=n instanceof Element?Nr(n,t.workspace):cn(n,t.workspace);let i=t.getRelativeToSurfaceXY();i.x=t.RTL?i.x-e.tg.snapRadius:i.x+e.tg.snapRadius,i.y+=e.tg.snapRadius*2,r.moveBy(i.x,i.y)}finally{e.Ka--}return oe()&&!r.isShadow()&&b(new(x(N.BLOCK_CREATE))(r)),e.A().focusNode(r),r}},Sr=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?fn(e.associatedKeyboardShortcut):``,t.textContent=` ${e}`,n.appendChild(r),n.appendChild(t),n}return e.text},Cr=function(e,t){return t=v(t,e.getParentSvg(),e.getInverseScreenCTM()),t.x/=e.scale,t.y/=e.scale,t},wr=function(e,t,n){t=Cr(e,t),qu.set(e,z.difference(n,t))},Tr=function(e,t){if(t=Cr(e,t),e=qu.get(e),!e)throw Error(`Drag not initialized`);return z.sum(e,t)},Er=function(t,n=!1){var r=e.F(`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},Dr=function(t){var n=e.F(`variables`);for(let r=0;r<t.length;r++){let i=t[r],a=e.F(`variable`);a.appendChild(e.rc(i.getName())),i.getType()&&a.setAttribute(`type`,i.getType()),a.id=i.getId(),n.appendChild(a)}return n},Or=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=kr(e,t),t.nodeType===es.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},kr=function(t,n){if(t.isInsertionMarker())return(n=t.getChildren(!1)[0])?kr(n):new DocumentFragment;var r=e.F(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.F(`field`),i.setAttribute(`name`,a.name||``),i=a.toXml(i)):i=null,i&&r.appendChild(i);if(a=t.getCommentText()){var o=t.getIcon(Ic.COMMENT);i=o.getBubbleSize();var s=o.bubbleIsVisible();o=o.getBubbleLocation();var c=e.F(`comment`);c.appendChild(e.rc(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.F(`data`),a.appendChild(e.rc(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.he.DUMMY&&i.type!==e.he.END_ROW&&(o=i.connection.targetBlock(),i.type===e.he.VALUE?l=e.F(`value`):i.type===e.he.STATEMENT&&(l=e.F(`statement`)),c=i.connection.getShadowDom(),!c||o&&o.isShadow()||l.appendChild(Ar(c,n)),o&&(o=kr(o,n),o.nodeType===es.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=kr(l,n),a.nodeType===es.ELEMENT_NODE)){var u=e.F(`next`);u.appendChild(a),r.appendChild(u)}return t=t.nextConnection&&t.nextConnection.getShadowDom(),!t||l&&l.isShadow()||u.appendChild(Ar(t,n)),r},Ar=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,r.nodeType===es.TEXT_NODE&&r.data.trim()===``&&n?.firstChild!==r&&D(r);n&&(r=n,n=n.nextSibling,r.nodeType===es.TEXT_NODE&&r.data.trim()===``&&D(r))}return e},jr=function(e){return it(e).replace(/<(\w+)([^<]*)\/>/g,`<$1$2></$1>`)},e.Ig=function(t,n){var r=0;n.RTL&&(r=n.getWidth());var i=[];_e();var a=e.fd;a||e.r(!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.Pc){let e=Nr(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`)Mr(a,n);else if(t===`variables`){if(o)Pr(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.r(a),n.setResizesEnabled&&n.setResizesEnabled(!0),n.rendered&&Tt(),ve()}return b(new(x(N.FINISHED_LOADING))(n)),i},Mr=function(e,t){var n,r=(n=e.getAttribute(`id`))??void 0;n=t.rendered?new ed(t,r):new $u(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 z(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 V(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.Lg=function(e,t){return e=Nr(e,t),t.rendered&&Tt(),e},Nr=function(t,n){e.Ka++;var r=n.getVariableMap().getAllVariables();try{var i=Lr(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.Ka--}if(oe()){for(t=tn(n,r),n=0;n<t.length;n++)r=t[n],b(new(x(N.VAR_CREATE))(r));b(new(x(N.BLOCK_CREATE))(i))}return i},Pr=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)}},Fr=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(Ic.COMMENT);isNaN(o)||isNaN(s)||u.setBubbleSize(new V(o,s)),u.setBubbleVisible(a),setTimeout(()=>{isNaN(c)||isNaN(l)||(c=t.workspace.RTL?t.workspace.getWidth()-(c+o):c,u.setBubbleLocation(new z(c,l))),u.setBubbleVisible(a)},1)}},Ir=function(e){var t=null,n=null;for(let r=0;r<e.childNodes.length;r++){let i=e.childNodes[r];i.nodeType===es.ELEMENT_NODE&&(i.nodeName.toLowerCase()===`block`?t=i:i.nodeName.toLowerCase()===`shadow`&&(n=i))}return{childBlockElement:t,childShadowElement:n}},Lr=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 f=0;f<e.children.length;f++){var p=e.children[f];if(p.nodeType!==es.TEXT_NODE)switch(p.nodeName.toLowerCase()){case`mutation`:s.push(p);break;case`comment`:c.push(p);break;case`data`:l.push(p);break;case`title`:case`field`:u.push(p);break;case`value`:case`statement`:d.push(p);break;case`next`:o.push(p);break;default:console.warn(`Ignoring unknown tag: `+p.nodeName)}}for(f=!1,p=0;p<s.length;p++){let e=s[p];i.domToMutation&&(i.domToMutation(e),i.initSvg&&(f=!0))}for(s=f,Fr(c,i),c=l,l=0;l<c.length;l++)i.data=c[l].textContent;if(n)if(r)if(i.previousConnection)n.connect(i.previousConnection);else throw TypeError(`Next block does not have previous statement.`);else if(i.outputConnection)n.connect(i.outputConnection);else if(i.previousConnection)n.connect(i.previousConnection);else throw TypeError(`Child block does not have output or previous statement.`);for(n=u,u=0;u<n.length;u++)c=n[u],(l=c.getAttribute(`name`))?(r=i,(f=r.getField(l))?f.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=Ir(u),u.childBlockElement){if(!r.connection)throw TypeError(`Input connection does not exist.`);Lr(u.childBlockElement,t,r.connection,!1)}if(u.childShadowElement){var m=void 0;(m=r.connection)==null||m.setShadowDom(u.childShadowElement)}}for(a=o,m=0;m<a.length;m++){if(o=Ir(a[m]),o.childBlockElement){if(!i.nextConnection)throw TypeError(`Next statement does not exist.`);if(i.nextConnection.isConnected())throw TypeError(`Next statement is already connected.`);Lr(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 h of t.split(`,`))i.setDisabledReason(!0,decodeURIComponent(h));if((h=e.getAttribute(`deletable`))&&i.setDeletable(h===`true`),(h=e.getAttribute(`movable`))&&i.setMovable(h===`true`),(h=e.getAttribute(`editable`))&&i.setEditable(h===`true`),(h=e.getAttribute(`collapsed`))&&i.setCollapsed(h===`true`),e.nodeName.toLowerCase()===`shadow`){for(e=i.getChildren(!1),h=0;h<e.length;h++)if(!e[h].isShadow())throw TypeError(`Shadow block not allowed non-shadow child.`);i.setShadow(!0)}return i},Rr=function(e,n){t(M.FIELD,e,n,!0)},e.Rg=function(e){return nd.fromJsonInternal(e)},zr=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.Ug=function(e,t){if(typeof e!=`string`||e.trim()===``)throw Error(`Error: Invalid extension name "`+e+`"`);if(gd[e])throw Error(`Error: Extension "`+e+`" is already registered.`);if(typeof t!=`function`)throw Error(`Error: Extension "`+e+`" must be a function`);gd[e]=t},e.Vg=function(t,n){if(!n||typeof n!=`object`)throw Error(`Error: Mixin "`+t+`" must be a object`);e.Ug(t,function(){this.mixin(n)})},e.Zg=function(t,n,r,i){var a=`Error when registering mutator "`+t+`": `;Ur(a,n);var o=Hr(n.compose,n.decompose,a+` compose/decompose`);if(r&&typeof r!=`function`)throw Error(a+`Extension "`+t+`" is not a function`);e.Ug(t,function(){o&&this.setMutator(new e.Yg(i||[],this)),this.mixin(n),r&&r.apply(this)})},Br=function(e){return!!gd[e]},Vr=function(e,t,n){var r=gd[e];if(typeof r!=`function`)throw Error(`Error: Extension "`+e+`" not found.`);if(n){if(Wr(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=Wr(t);if(r.apply(t),n)Ur(`Error after applying mutator "`+e+`": `,t);else{a:if(n=i,t=Wr(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.`)}},Hr=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`)},Ur=function(e,t){var n=Hr(t.mutationToDom,t.domToMutation,e+` mutationToDom/domToMutation`),r=Hr(t.saveExtraState,t.loadExtraState,e+` saveExtraState/loadExtraState`);if(!n&&!r)throw Error(e+`Mutations must contain either XML hooks, or JSON hooks, or both`);Hr(t.compose,t.decompose,e+` compose/decompose`)},Wr=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.dh=function(e,t){var n=[];return function(){n.includes(this.type)||(Gr(this,e,t),n.push(this.type)),this.setTooltip(function(){var n=String(this.getFieldValue(e));return O(t[n])}.bind(this))}},Gr=function(e,t,n){var r=e.getField(t);if(r instanceof id&&!r.isOptionListDynamic()){r=r.getOptions();for(let i of r)i!==id.SEPARATOR&&([,r]=i,n[r]===void 0&&console.warn(`No tooltip mapping for value ${r} of field ${t} of block type ${e.type}.`))}},e.fh=function(e,t){return function(){this.setTooltip(function(){var n=this.getField(t);return O(e).replace(`%1`,n?n.getText():``)}.bind(this))}},k=function(e,t){return` `+e+`,`+t+` `},Kr=function(e,t){return` `+e+t.join(``)},qr=function(e,t){return` M `+e+`,`+t+` `},Jr=function(e,t){return` m `+e+`,`+t+` `},Yr=function(e,t){return` l `+e+`,`+t+` `},Xr=function(e){return` l`+e.join(``)},A=function(e,t){return` `+e+` `+t+` `},Zr=function(e,t,n,r){return e+` `+n+` `+n+` `+t+r},Qr=function(e,t){var n=null;t=t.outputConnection;var r=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},$r=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`},ei=function(e){return typeof e.getName==`function`&&typeof e.getContents==`function`&&typeof e.setSelected==`function`&&typeof e.onClick==`function`&&$r(e)&&e.isSelectable()},ti=function(t,n=Jo.STANDARD){if(t.isSimpleReporter()){let e=t.getFullBlockField();if(e)return e.computeAriaLabel(n>=Jo.STANDARD)}return[n>=Jo.STANDARD&&ii(t),ri(t),...ai(t,n),n===Jo.LOQUACIOUS&&ci(t),n>=Jo.STANDARD&&(t.isEnabled()?void 0:e.C.BLOCK_LABEL_DISABLED),n>=Jo.STANDARD&&(t.isCollapsed()?e.C.BLOCK_LABEL_COLLAPSED:void 0),n>=Jo.LOQUACIOUS&&(t.isShadow()?e.C.BLOCK_LABEL_REPLACEABLE:void 0),n>=Jo.STANDARD&&pi(t),n>=Jo.LOQUACIOUS&&t.getAriaRoleDescription()].filter(e=>!!e).join(`, `)},ni=function(t,n,r=Jo.STANDARD){var i=r>=Jo.LOQUACIOUS,a=[],o=t.fieldRow.filter(e=>e.isVisible()).flatMap((e,t,n)=>{if(e instanceof Ed){if(t<n.length-1&&n[t+1]instanceof Ed)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 ni(e[i-1],n,r)}return t.type===e.he.VALUE&&t.connection?.targetConnection===null&&r>=Jo.STANDARD&&o.push(e.C.INPUT_LABEL_EMPTY),o.filter(e=>!!e)},ri=function(t){var n,r=(n=t.outputConnection??t.previousConnection)?.targetConnection?.getParentInput();if(r&&(t=r.getSourceBlock(),!t.isInsertionMarker())){if(n=r.getAriaLabelText())t=n;else{if(!t.statementInputCount||(n=t.inputList.find(t=>t.type===e.he.STATEMENT),r===n)||(t=oi(t,r,!1),!t.length))return;t=t.join(`, `)}return r.type===e.he.STATEMENT?(r=Array.isArray(t)?t.join(` `):t,e.C.BLOCK_LABEL_BEGIN_PREFIX.replace(`%1`,r)):t}},ii=function(t){if(!t.isInFlyout&&!t.isDragging())return t.getRootBlock()===t?e.C.BLOCK_LABEL_BEGIN_STACK:void 0},ai=function(t,n=Jo.STANDARD){var r=t=t.inputList.filter(e=>e.isVisible());if(n<=Jo.STANDARD){let n=t.filter(t=>t.type===e.he.STATEMENT);n.length>1&&(r=t.slice(0,t.indexOf(n[0])+1))}return r.map(e=>e.getLabel(n))},oi=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.he.STATEMENT,o=a?si(t.inputList,i):i,s=t.inputList.slice(o,i+1).filter(e=>e.isVisible()),c=s.map(e=>e.getLabel(Jo.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.he.DUMMY||t.type===e.he.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)},si=function(t,n){for(--n;n>=0;n--)if(t[n].type===e.he.STATEMENT)return n+1;return 0},ci=function(t){var n=t.workspace.getToolbox();if(n){var r=void 0;for(let e of n.getToolboxItems())if(ei(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())}},li=function(t){switch(t){case Dd.BEFORE:return e.C.ANNOUNCE_MOVE_BEFORE;case Dd.AFTER:return e.C.ANNOUNCE_MOVE_AFTER;case Dd.INSIDE:return e.C.ANNOUNCE_MOVE_INSIDE;case Dd.AROUND:return e.C.ANNOUNCE_MOVE_AROUND;default:return e.C.ANNOUNCE_MOVE_TO}},ui=function(t,n){var r=t.getParentInput();if(!r)return n;var i=r.getAriaLabelText();if(!i){if(t=oi(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},di=function(e,t,n,r=!1){var i=fi(e,t),a=li(i),o=![Dd.BEFORE,Dd.AFTER].includes(i);return i=o&&n(!0),n=o&&n(!1),r=r?e.getSourceBlock().getStackBlocksCountLabel():``,o=t.getSourceBlock().getAriaLabel(Jo.TERSE),i&&(r=ui(e,r)),n&&(o=ui(t,o)),a.replace(`%1`,r).replace(`%2`,o)},fi=function(e,t){switch(e.type){case U.INPUT_VALUE:case U.OUTPUT_VALUE:return Dd.TO;case U.NEXT_STATEMENT:return e===e.getSourceBlock().nextConnection?Dd.BEFORE:Dd.AROUND;case U.PREVIOUS_STATEMENT:return t===t.getSourceBlock().nextConnection?Dd.AFTER:Dd.INSIDE}return Dd.UNKNOWN},pi=function(t){var n=t.inputList.filter(t=>t.type===e.he.STATEMENT).length;if(n>1)return e.C.BLOCK_LABEL_HAS_BRANCHES.replace(`%1`,n.toString());switch(t.inputList.reduce((e,t)=>t.fieldRow.reduce((e,t)=>t.EDITABLE&&!t.isFullBlockField()?++e:e,e)+ +(t.connection?.type===U.INPUT_VALUE),0)){case 0:break;case 1:return e.C.BLOCK_LABEL_HAS_INPUT;default:return e.C.BLOCK_LABEL_HAS_INPUTS}},mi=function(e){return Se(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`},hi=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}),gi(i,{x:r.x,y:r.y,width:e.width,height:e.height},t.RTL,new Date)}},gi=function(e,t,n,r){var i=(new Date().getTime()-r.getTime())/150;i>1?D(e):(e.setAttribute(`transform`,`translate(`+(t.x+(n?-1:1)*t.width/2*i)+`,`+(t.y+t.height/2*i)+`) scale(`+(1-i)+`)`),setTimeout(gi,10,e,t,n,r))},_i=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=w(I.CIRCLE,{cx:r.x,cy:r.y,r:0,fill:`none`,stroke:`#888`,"stroke-width":10},t.getParentSvg());e=w(I.ANIMATE,{id:`animationCircle`,begin:`indefinite`,attributeName:`r`,dur:`150ms`,from:0,to:25*n},i),t=w(I.ANIMATE,{id:`animationOpacity`,begin:`indefinite`,attributeName:`opacity`,dur:`150ms`,from:1,to:0},i),e.beginElement(),t.beginElement(),setTimeout(()=>void D(i),150)}},vi=function(e){if(bi(),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),zd=e,yi(e,t,new Date,0)}},yi=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)})`,Rd=setTimeout(yi,15,e,t,n,r+1)),e.getSvgRoot().setAttribute(`transform`,`${e.getTranslation()} ${a}`)},bi=function(){zd&&=(Rd&&=(clearTimeout(Rd),null),zd.getSvgRoot().setAttribute(`transform`,zd.getTranslation()),null)},xi=function(t,n){t.workspace.RTL&&(n.x=t.workspace.getWidth()-n.x);for(var r=t.workspace,i=e.tg.snapRadius,a=z.difference(n,t.getRelativeToSurfaceXY()),o=new z(0,0),s=r.getAllBlocks(!1).filter(e=>e.id!=t.id).map(e=>e.getRelativeToSurfaceXY());Si(z.sum(n,o),s)||Ci(t,z.sum(a,o),i);)r.RTL?o.translate(-i,i*2):o.translate(i,i*2);t.moveTo(z.sum(n,o))},Si=function(e,t){return t.some(t=>Math.abs(t.x-e.x)<=1&&Math.abs(t.y-e.y)<=1)},Ci=function(e,t,n){return e.getConnections_(!1).some(e=>!!e.closest(n,t).connection)},wi=function(e,t,n){var r=n.getBoundingRectangle(),i=r.right-r.left,a=gn(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=gn(o,r.left,t)-r.left)||a?(n.moveBy(e,a,[`inbounds`]),!0):!1},Ti=function(t){return n=>{var r=t.getMetricsManager();if(r.hasFixedEdges()&&!t.isDragging()){var i;if(Fo.includes((i=n.type)??``)){switch(r=r.getScrollMetrics(!0),i=null,n.type){case N.BLOCK_CREATE:case N.BLOCK_MOVE:(i=t.getBlockById(n.blockId))&&(i=i.getRootBlock());break;case N.COMMENT_CREATE:case N.COMMENT_MOVE:case N.COMMENT_RESIZE:i=t.getCommentById(n.commentId)}if(i){var a=e.fd||!1;e.r(n.group),wi(t,r,i)&&!n.group&&console.warn(`Moved object in bounds but there was no event group. This may break undo.`),e.r(a)}}else n.type===N.VIEWPORT_CHANGE&&n.scale&&n.oldScale&&n.scale>n.oldScale&&Ei(t)}}},Ei=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++)wi(e,t,i)}},Di=function(e,t){var n=e.toCopyData();return Ud=n,Wd=Ce(e)&&e.workspace instanceof Sp?e.workspace:null,Gd=t,n},Oi=function(e,t,n){return e&&t?ki(e,t,n):Ud&&Wd?ki(Ud,Wd,Gd):null},ki=function(e,t,n){return t=t.isMutator?t:t.options.parentWorkspace??t,r(M.PASTER,e.paster,!1)?.paste(e,t,n)??null},Ai=function(e){return e&&typeof e.toCopyData==`function`},ji=function(e){return e&&typeof e.isDeletable==`function`&&typeof e.dispose==`function`&&typeof e.setDeleteStyle==`function`},Mi=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`},Ni=function(){L.registry.register({name:X.ESCAPE,preconditionFn(e){return!e.isReadOnly()},callback(e){return e.hideChaff(),!0},keyCodes:[K.ESC],displayText:()=>e.C.SHORTCUTS_ESCAPE})},Pi=function(){L.registry.register({name:X.DELETE,preconditionFn(t,n){return n=n.focusedNode,(n=!t.isReadOnly()&&n!=null&&ji(n)&&n.isDeletable()&&!t.isDragging()&&!e.A().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),n=i.focusedNode,n instanceof af?n.checkAndDelete():ji(n)&&n.isDeletable()&&(e.r(!0),n.dispose(),e.r(!1),t.getAudioManager().play(`delete`)),!0},keyCodes:[K.DELETE,K.BACKSPACE],displayText:()=>e.C.SHORTCUTS_DELETE})},Fi=function(e){return Ai(e)&&ji(e)&&Mi(e)?e.isCopyable?e.isCopyable():e instanceof af||e instanceof ed?e.isOwnDeletable()&&e.isOwnMovable():e.isDeletable()&&e.isMovable():!1},Ii=function(){var t=L.registry.createSerializedKey(K.C,[K.CTRL_CMD]);L.registry.register({name:X.COPY,preconditionFn(t,n){n=n.focusedNode;var r=t.isFlyout?t.targetWorkspace:t;return(n=!!n&&!!r&&!r.isDragging()&&!e.A().ephemeralFocusTaken()&&Fi(n))||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return n.preventDefault(),r=i.focusedNode,!r||!Ai(r)||!Fi(r)||(i=t.isFlyout?t.targetWorkspace:t,!i)?!1:(r.workspace.isFlyout||i.hideChaff(),i=Mi(r)&&r.workspace==i?r.getRelativeToSurfaceXY():void 0,(r=!!Di(r,i))&&n instanceof KeyboardEvent&&Tc.show(t,{message:e.C.KEYBOARD_NAV_COPIED_HINT.replace(`%1`,fn(X.PASTE)),duration:7,id:`copiedHint`}),r)},keyCodes:[t],displayText:()=>e.C.COPY_SHORTCUT})},Li=function(){var t=L.registry.createSerializedKey(K.X,[K.CTRL_CMD]);L.registry.register({name:X.CUT,preconditionFn(t,n){return n=n.focusedNode,(n=!!n&&!t.isReadOnly()&&!t.isDragging()&&!e.A().ephemeralFocusTaken()&&Fi(n)&&ji(n)&&n.isDeletable())||t.getAudioManager().playErrorBeep(),n},callback(t,n,r,i){return r=i.focusedNode,r&&Fi(r)&&ji(r)&&r.isDeletable()&&Ai(r)?(i=Mi(r)?r.getRelativeToSurfaceXY():void 0,i=Di(r,i),r instanceof af?(r.checkAndDelete(),n.preventDefault()):ji(r)&&(e.r(!0),r.dispose(),e.r(!1),t.getAudioManager().play(`delete`),n.preventDefault()),i&&n instanceof KeyboardEvent&&Tc.show(t,{message:e.C.KEYBOARD_NAV_CUT_HINT.replace(`%1`,fn(X.PASTE)),duration:7,id:`cutHint`}),!!i):!1},keyCodes:[t],displayText:()=>e.C.CUT_SHORTCUT})},Ri=function(){var t=L.registry.createSerializedKey(K.V,[K.CTRL_CMD]);L.registry.register({name:X.PASTE,preconditionFn(){var t=Wd;if(!t||!t.rendered)return!1;var n=t.isFlyout?t.targetWorkspace:t;return(n=!!Ud&&!!n&&!n.isReadOnly()&&!n.isDragging()&&!e.A().ephemeralFocusTaken())||t.getAudioManager().playErrorBeep(),n},callback(e,t){var n=Ud;if(!n)return!1;var r=Wd;if(!r||(Tc.hide(e,`cutHint`),Tc.hide(e,`copiedHint`),e=r.isFlyout?r.targetWorkspace:r,!e||e.isReadOnly()))return!1;if(t instanceof PointerEvent)return t=nt(e,new z(t.clientX,t.clientY)),!!Oi(n,e,t);if(t=Gd,!t)return!!Oi(n,e);var{left:i,top:a,width:o,height:s}=e.getMetricsManager().getViewMetrics(!0);return new B(a,a+s,i,i+o).contains(t.x,t.y)?!!Oi(n,e):(t=new z(i+o/2,a+s/2),!!Oi(n,e,t))},keyCodes:[t],displayText:()=>e.C.PASTE_SHORTCUT})},zi=function(){var t=L.registry.createSerializedKey(K.Z,[K.CTRL_CMD]);L.registry.register({name:X.UNDO,preconditionFn(t){return!t.isReadOnly()&&!t.isDragging()&&!e.A().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.undo(),t.preventDefault(),!0},keyCodes:[t],displayText:()=>e.C.UNDO})},Bi=function(){var t=L.registry.createSerializedKey(K.Z,[K.CTRL_CMD,K.SHIFT]),n=L.registry.createSerializedKey(K.Y,[K.CTRL]);L.registry.register({name:X.REDO,preconditionFn(t){return!t.isDragging()&&!t.isReadOnly()&&!e.A().ephemeralFocusTaken()},callback(e,t){return e.hideChaff(),e.redo(),t.preventDefault(),!0},keyCodes:[t,n],displayText:()=>e.C.REDO})},Vi=function(){var t=t=>{var n=e.A().getFocusedNode();return Mi(n)?n:t.getNavigator().getSourceBlockFromNode(e.A().getFocusedNode())??void 0},n=L.registry.createSerializedKey(K.M,[K.SHIFT]),r={name:X.START_MOVE,preconditionFn:e=>(e=t(e),!!e&&cd.mover.canMove(e)),callback:(n,r)=>(Ll.setIsActive(!0),(n=t(n))&&e.A().focusNode(n),!!n&&cd.mover.startMove(n,r)),keyCodes:[K.M],displayText:()=>e.C.SHORTCUTS_START_MOVE};n=[r,Object.assign({},r,{name:X.START_MOVE_STACK,keyCodes:[n],displayText:()=>e.C.SHORTCUTS_START_MOVE_STACK}),{name:X.FINISH_MOVE,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>cd.mover.finishMove(t),keyCodes:[K.ENTER,K.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_FINISH_MOVE},{name:X.ABORT_MOVE,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>cd.mover.abortMove(t),keyCodes:[K.ESC],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_ABORT_MOVE},{name:X.MOVE_LEFT,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),cd.mover.move(od.LEFT,t)),keyCodes:[K.LEFT,L.registry.createSerializedKey(K.LEFT,[K.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_LEFT},{name:X.MOVE_RIGHT,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),cd.mover.move(od.RIGHT,t)),keyCodes:[K.RIGHT,L.registry.createSerializedKey(K.RIGHT,[K.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_RIGHT},{name:X.MOVE_UP,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),cd.mover.move(od.UP,t)),keyCodes:[K.UP,L.registry.createSerializedKey(K.UP,[K.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_UP},{name:X.MOVE_DOWN,preconditionFn:()=>cd.mover.isMoving(),callback:(e,t)=>(t.preventDefault(),cd.mover.move(od.DOWN,t)),keyCodes:[K.DOWN,L.registry.createSerializedKey(K.DOWN,[K.CTRL_CMD])],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_MOVE_DOWN}];for(let e of n)L.registry.register(e)},Hi=function(){var t=L.registry.createSerializedKey(K.ENTER,[K.CTRL_CMD]),n=L.registry.createSerializedKey(K.F10,[K.SHIFT]);L.registry.register({name:X.MENU,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{if(Ll.setIsActive(!0),(t=e.A().getFocusedNode())&&typeof t.showContextMenu==`function`){t.showContextMenu(n);let e;return(e=Vu)==null||e.highlightNext(),!0}return!1},keyCodes:[t,n,K.CONTEXT_MENU],displayText:()=>e.C.SHORTCUTS_SHOW_CONTEXT_MENU})},Ui=function(){var t={right:{name:X.NAVIGATE_RIGHT,preconditionFn:e=>!e.isDragging()&&!ou&&!ju,callback:(t,n)=>(n.preventDefault(),Ll.setIsActive(!0),n=t.RTL?e.A().getFocusedTree()?.getNavigator().getOutNode():e.A().getFocusedTree()?.getNavigator().getInNode(),n?(e.A().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)),keyCodes:[K.RIGHT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_RIGHT},left:{name:X.NAVIGATE_LEFT,preconditionFn:e=>!e.isDragging()&&!ou&&!ju,callback:(t,n)=>(n.preventDefault(),Ll.setIsActive(!0),n=t.RTL?e.A().getFocusedTree()?.getNavigator().getInNode():e.A().getFocusedTree()?.getNavigator().getOutNode(),n?(e.A().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)),keyCodes:[K.LEFT],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_LEFT},down:{name:X.NAVIGATE_DOWN,preconditionFn:e=>!e.isDragging()&&!ou&&!ju,callback:(t,n)=>(n.preventDefault(),Ll.setIsActive(!0),n=e.A().getFocusedTree()?.getNavigator().getNextNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.A().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)),keyCodes:[K.DOWN],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_DOWN},up:{name:X.NAVIGATE_UP,preconditionFn:e=>!e.isDragging()&&!ou&&!ju,callback:(t,n)=>(n.preventDefault(),Ll.setIsActive(!0),n=e.A().getFocusedTree()?.getNavigator().getPreviousNode(),n?(t.getAudioManager().maybePlayScopeChangeAudioCue(n),e.A().focusNode(n),!0):(t.getAudioManager().playErrorBeep(),!1)),keyCodes:[K.UP],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_NAVIGATE_UP}};for(let e of Object.values(t))L.registry.register(e)},Wi=function(){L.registry.register({name:X.FOCUS_WORKSPACE,preconditionFn:e=>!e.isDragging(),callback:t=>(Ll.setIsActive(!0),e.A().focusNode(Zd(t)),!0),keyCodes:[K.W],displayText:()=>e.C.SHORTCUTS_FOCUS_WORKSPACE})},Gi=function(){L.registry.register({name:X.FOCUS_TOOLBOX,preconditionFn:e=>!e.isDragging(),callback:(t,n)=>{var r=t.getToolbox();if(r)Ll.setIsActive(!0),e.A().focusTree(r);else{if(t=t.getFlyout(),!t)return!1;Ll.setIsActive(!0),e.A().focusTree(t.getWorkspace())}return n.preventDefault(),!0},keyCodes:[K.T],displayText:()=>e.C.SHORTCUTS_FOCUS_TOOLBOX})},Ki=function(){L.registry.register({name:X.INFORMATION,preconditionFn:()=>!0,callback:t=>{var n=e.A().getFocusedNode(),r=t.getNavigator().getSourceBlockFromNode(n);if(r)return t=ti(r,Jo.LOQUACIOUS),fe(t),!0;if(n===t){n=Zd(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),fe(t),!0}return!1},keyCodes:[K.I],displayText:()=>e.C.SHORTCUTS_INFORMATION})},qi=function(){var t=L.registry.createSerializedKey(K.I,[K.SHIFT]);L.registry.register({name:X.EXTENDED_INFORMATION,preconditionFn:()=>!0,callback:t=>{if(t=t.getNavigator().getSourceBlockFromNode(e.A().getFocusedNode()),!t)return!1;for(var n=[],r=t,i;(i=r.outputConnection)!=null&&i.isConnected();)r=r.getParent();for(r!==t&&n.push(ti(r,Jo.TERSE)),i=r.getParent();i;)n.push(ti(i,Jo.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`,ti(t,Jo.TERSE))),fe(e.C.PARENT_BLOCKS_ANNOUNCEMENT.replace(`%1`,n.join(`,`)))}else fe(e.C.NO_PARENT_ANNOUNCEMENT);return!0},keyCodes:[t],displayText:()=>e.C.SHORTCUTS_EXTENDED_INFORMATION})},Ji=function(){var t=L.registry.createSerializedKey(K.X,[K.SHIFT]);L.registry.register({name:X.DISCONNECT,preconditionFn:(e,t)=>(t=t.focusedNode,(t=!e.isDragging()&&!e.isReadOnly()&&t instanceof af&&!t.isShadow())||e.getAudioManager().playErrorBeep(),t),callback:(t,n)=>(Ll.setIsActive(!0),t=e.A().getFocusedNode(),t instanceof af?(n=!(n instanceof KeyboardEvent&&n.shiftKey),e.r(!0),t.unplug(n),e.r(!1),!0):!1),keyCodes:[K.X,t],displayText:()=>e.C.SHORTCUTS_DISCONNECT})},Yi=function(){var t=(t,n=e.A().getFocusedNode())=>{var r=t.getNavigator();for(let e=n;e&&e!==t;e=r.getParent(e))n=e;return Ce(n)?n:null},n={name:X.PREVIOUS_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!ou&&!ju,callback:n=>{Ll.setIsActive(!0);var r=t(n);return!r||(n=t(n,n.getNavigator().navigateStacks(r,-1)),!n)?!1:(e.A().focusNode(n),!0)},keyCodes:[K.B],displayText:()=>e.C.SHORTCUTS_PREVIOUS_STACK};L.registry.register({name:X.NEXT_STACK,preconditionFn:e=>!e.isDragging()&&!!t(e)&&!ou&&!ju,callback:n=>{Ll.setIsActive(!0);var r=t(n);return!r||(n=n.getNavigator().navigateStacks(r,1),!n)?!1:(e.A().focusNode(n),!0)},keyCodes:[K.N],displayText:()=>e.C.SHORTCUTS_NEXT_STACK}),L.registry.register(n)},Xi=function(){var t=()=>{var t=e.A().getFocusedTree();return t instanceof Sp&&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.A().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 Jd&&i.isLabel())return i}return null},i=L.registry.createSerializedKey(K.H,[K.SHIFT]);i={name:X.PREVIOUS_HEADING,preconditionFn:e=>!e.isDragging()&&!ou&&!ju&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,-1),!n)?!1:(Ll.setIsActive(!0),e.A().focusNode(n),!0)},keyCodes:[i],displayText:()=>e.C.SHORTCUTS_PREVIOUS_HEADING},L.registry.register({name:X.NEXT_HEADING,preconditionFn:e=>!e.isDragging()&&!ou&&!ju&&!!t(),callback:()=>{var n=t();return!n||(n=r(n,1),!n)?!1:(Ll.setIsActive(!0),e.A().focusNode(n),!0)},keyCodes:[K.H],displayText:()=>e.C.SHORTCUTS_NEXT_HEADING}),L.registry.register(i)},Zi=function(){L.registry.register({name:X.PERFORM_ACTION,preconditionFn:t=>!t.isDragging()&&!ou&&!ju&&!e.A().ephemeralFocusTaken(),callback:(t,n)=>{if(Ll.setIsActive(!0),(t=e.A().getFocusedNode())&&`performAction`in t){n.preventDefault();let e;return(e=t.performAction)==null||e.call(t,n),!0}return!1},keyCodes:[K.ENTER,K.SPACE],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_PERFORM_ACTION})},Qi=function(){L.registry.register({name:X.DUPLICATE,preconditionFn:(e,t)=>({focusedNode:t}=t,(t=!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout&&(t instanceof af?t.isDuplicatable():!0))||e.getAudioManager().playErrorBeep(),t),callback:(e,t,n,r)=>(Ll.setIsActive(!0),t=Ai(r.focusedNode)&&r.focusedNode,(t&&=t.toCopyData())?!!Oi(t,e):!1),keyCodes:[K.D],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_DUPLICATE})},$i=function(){L.registry.register({name:X.CLEANUP,preconditionFn:e=>!e.isDragging()&&!e.isReadOnly()&&!e.isFlyout,callback:e=>(Ll.setIsActive(!0),e.cleanUp(),!0),keyCodes:[K.C],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_CLEANUP})},ea=function(){var t=L.registry.createSerializedKey(K.J,[K.CTRL_CMD]);L.registry.register({name:X.SHOW_TOOLTIP,preconditionFn:e=>!e.isDragging(),callback:t=>{var n=e.A().getFocusedNode();return n!==null&&(Ll.setIsActive(!0),Yn(n,t)),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_SHOW_TOOLTIP})},ta=function(){var t=L.registry.createSerializedKey(K.Z,[K.CTRL_CMD,K.ALT]),n=!1;L.registry.register({name:X.TOGGLE_SCREENREADER,preconditionFn:()=>!0,callback:(t,r)=>{n=!n,Ll.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),Tc.show(t,{message:(n?e.C.SCREENREADER_MODE_ENABLED:e.C.SCREENREADER_MODE_DISABLED).replace(`%1`,fn(X.TOGGLE_SCREENREADER)),duration:7,id:`screenreaderHint`}),r.preventDefault(),!0},keyCodes:[t],allowCollision:!0,displayText:()=>e.C.SHORTCUTS_TOGGLE_SCREENREADER_MODE})},na=function(){Ni(),Pi(),Ii(),Li(),Ri(),zi(),Bi()},ra=function(){Hi(),Vi(),Wi(),Gi(),Ui(),Ji(),Yi(),Xi(),Zi(),Qi(),$i(),ea()},ia=function(){Ki(),qi(),ta()},aa=function(t,n=!1){var r=e.C.KEYBOARD_NAV_UNCONSTRAINED_MOVE_HINT.replace(`%1`,ko||Do||Oo?e.C.COMMAND_KEY:e.C.CONTROL_KEY).replace(`%2`,e.C.ENTER_KEY);Tc.show(t,{message:r,id:`unconstrainedMoveHint`,oncePerSession:!n})},oa=function(t){var n=e.C.KEYBOARD_NAV_CONSTRAINED_MOVE_HINT.replace(`%1`,e.C.ENTER_KEY);Tc.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;Rt(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)},la=function(e){return e&&typeof e.getChildToolboxItems==`function`&&typeof e.isExpanded==`function`&&typeof e.toggleExpanded==`function`&&ei(e)&&e.isCollapsible()},ua=function(e){var t=e.options.toolboxPosition;return e.options.RTL&&t!==H.TOP&&t!==H.BOTTOM?t===H.LEFT?H.RIGHT:H.LEFT:t},da=function(e,n){t(M.ICON,e.toString(),n)},fa=function(e){return typeof e.getProcedureModel==`function`&&typeof e.doProcedureUpdate==`function`&&typeof e.isProcedureDef==`function`},pa=function(e){return e&&typeof e.startPublishing==`function`&&typeof e.stopPublishing==`function`},ma=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=>{!fa(e)&&Bt(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=>{!fa(e)&&Bt(e)&&n.push(e.getProcedureDef())}),t.sort(ha),n.sort(ha),[t,n]},ha=function(e,t){return e[0].localeCompare(t[0],void 0,{sensitivity:`base`})},e.$i=function(t,n){if(n.isInFlyout)return t;for(t=t||e.C.UNNAMED_KEY||`unnamed`;ga(t,n.workspace,n);){let e=t.match(/^(.*?)(\d+)$/);t=e?e[1]+(parseInt(e[2])+1):t+`2`}return t},ga=function(t,n,r){for(let i of n.getAllBlocks(!1))if(i!==r&&Bt(i)&&e.aj.equals(i.getProcedureDef()[0],t))return!0;r=r&&fa(r)?r?.getProcedureModel():void 0;for(let i of n.getProcedureMap().getProcedures())if(i!==r&&e.aj.equals(i.getName(),t))return!0;return!1},e.cj=function(t){var n=this.getSourceBlock();if(!n)throw new Au;t=t.trim();var r=e.$i(t,n);fa(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},_a=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 so.procedures_defnoreturn&&r.push({kind:`block`,type:`procedures_defnoreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFNORETURN_PROCEDURE}}),so.procedures_defreturn&&r.push({kind:`block`,type:`procedures_defreturn`,gap:16,fields:{NAME:e.C.PROCEDURES_DEFRETURN_PROCEDURE}}),so.procedures_ifreturn&&r.push({kind:`block`,type:`procedures_ifreturn`,gap:16}),r.length&&(r[r.length-1].gap=24),t=ma(t),n(t[0],`procedures_callnoreturn`),n(t[1],`procedures_callreturn`),r},va=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.F(`xml`);var i=e.F(`block`);i.setAttribute(`type`,`procedures_mutatorarg`);var a=e.F(`field`);a.setAttribute(`name`,`NAME`),n=Kt(`x`,n),n=e.rc(n),a.appendChild(n),i.appendChild(a),r.appendChild(i),t.updateToolbox(r)},ya=function(t){if(t.type===N.BUBBLE_OPEN&&t.bubbleType===`mutator`&&t.isOpen&&t.blockId){t=Ee(t.workspaceId).getBlockById(t.blockId);var n=t.type;(n===`procedures_defnoreturn`||n===`procedures_defreturn`)&&(t=t.getIcon(e.Yg.TYPE).getWorkspace(),va(t),t.addChangeListener(ba))}},ba=function(e){(e.type===N.BLOCK_CREATE||e.type===N.BLOCK_DELETE||e.type===N.BLOCK_CHANGE||e.type===N.BLOCK_FIELD_INTERMEDIATE_CHANGE)&&(e=Ee(e.workspaceId),va(e))},xa=function(t,n){return n.getAllBlocks(!1).filter(n=>fa(n)&&!n.isProcedureDef()&&n.getProcedureModel()&&e.aj.equals(n.getProcedureModel().getName(),t)||n&&typeof n.getProcedureCall==`function`&&typeof n.renameProcedure==`function`&&e.aj.equals(n.getProcedureCall(),t))},e.ij=function(t){var n=e.Pc,r=t.getProcedureDef()[0],i=t.mutationToDom(!0);t=xa(r,t.workspace);for(let o=0,s;s=t[o];o++){r=(r=s.mutationToDom())&&it(r),s.domToMutation&&s.domToMutation(i);var a=s.mutationToDom();a&&=it(a),r!==a&&(e.Pc=!1,b(new(x(N.BLOCK_CHANGE))(s,`mutation`,null,r,a)),e.Pc=n)}},e.jj=function(t,n){for(let r of n.getAllBlocks(!1))if(fa(r)&&r.isProcedureDef()&&e.aj.equals(r.getProcedureModel().getName(),t)||Bt(r)&&e.aj.equals(r.getProcedureDef()[0],t))return r;return null},Sa=function(e,n){t(M.RENDERER,e,n)},Ca=function(e,t,n){return e=new(r(M.RENDERER,e,void 0))(e),e.init(t,n),e},wa=function(e){qt(e.getTargetWorkspace(),void 0,`String`)},Ta=function(e){qt(e.getTargetWorkspace(),void 0,`Number`)},Ea=function(e){qt(e.getTargetWorkspace(),void 0,`Colour`)},Da=function(t){return so.variables_set_dynamic||so.variables_get_dynamic||console.warn(`There are no dynamic variable blocks, but there is a dynamic variable category.`),t.registerButtonCallback(`CREATE_VARIABLE_STRING`,wa),t.registerButtonCallback(`CREATE_VARIABLE_NUMBER`,Ta),t.registerButtonCallback(`CREATE_VARIABLE_COLOUR`,Ea),[{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`},...Wt(t,t.getVariableMap().getAllVariables(),!1,`variables_get_dynamic`,`variables_set_dynamic`)]},Oa=function(e){var t=e.saveState();return e.getParameters().length&&(t.parameters=e.getParameters().map(e=>e.saveState())),t},ka=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},Aa=function(e,t){e.setAttribute(`dir`,`LTR`),Ue(e,t.hasCss,t.pathToMedia);var n=w(I.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=w(I.DEFS,{},n),i=String(Math.random()).substring(2);return t.gridPattern=Pf.createDom(i,t.gridOptions,r,e),n},ja=function(e,t,n){n.parentWorkspace=null,n=new Sp(n);var r=n.options;n.scale=r.zoomOptions.startScale,t.appendChild(n.createDom(`blocklyMainBackground`,e));var i=n.getRenderer().getClassName();return i&&T(e,i),(i=n.getTheme().getClassName())&&T(e,i),!r.hasCategories&&r.languageTree&&(i=n.addFlyout(I.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(Ti(n)),Ie(n),cr(),_n(),Vn(),n},Ma=function(e){var t=e.options,n=e.getParentSvg();if(p(n.parentNode,`contextmenu`,null,function(e){g(e)||e.preventDefault()}),n=p(window,`resize`,null,function(){Jn(),e.hideComponents(!0),Nn(),hr(),Ie(e),Ei(e)}),e.setResizeHandlerWrapper(n),Na(),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 kf(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&&Pa(t.pathToMedia,e)},Na=function(){Gp||(p(document,`scroll`,null,function(){var e=De();for(let t=0,n;n=e[t];t++)n instanceof Sp&&n.updateInverseScreenCTM()}),m(document,`touchend`,null,l),m(document,`touchcancel`,null,l),m(document,`keydown`,null,function(e){e.key===`Tab`&&Ll.setIsActive(!0)})),Gp=!0},Pa=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`)},Fa=function(){G.registry.register({displayText(){return e.C.UNDO},preconditionFn(e){return e.workspace.getUndoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.undo()},scopeType:G.ScopeType.WORKSPACE,id:`undoWorkspace`,weight:1,associatedKeyboardShortcut:`undo`})},Ia=function(){G.registry.register({displayText(){return e.C.REDO},preconditionFn(e){return e.workspace.getRedoStack().length>0?`enabled`:`disabled`},callback(e){e.workspace.redo()},scopeType:G.ScopeType.WORKSPACE,id:`redoWorkspace`,weight:2,associatedKeyboardShortcut:`redo`})},La=function(){G.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:G.ScopeType.WORKSPACE,id:`cleanWorkspace`,weight:3,associatedKeyboardShortcut:`cleanup`})},Ra=function(t,n){function r(n){a--,n.setCollapsed(t),a===0&&e.r(!1)}var i=0,a=0;e.r(!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}},za=function(){G.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){Ra(!0,e.workspace.getTopBlocks(!0))},scopeType:G.ScopeType.WORKSPACE,id:`collapseWorkspace`,weight:4})},Ba=function(){G.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){Ra(!1,e.workspace.getTopBlocks(!0))},scopeType:G.ScopeType.WORKSPACE,id:`expandWorkspace`,weight:5})},Va=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++)Va(e[n],t)}},Ha=function(e){var t=[];e=e.getTopBlocks(!0);for(let n=0;n<e.length;n++)Va(e[n],t);return t},Ua=function(t,n){n?e.r(n):(e.r(!0),n=e.fd);var r=t.shift();r&&(r.isDeadOrDying()?Ua(t,n):(r.dispose(!1,!0),setTimeout(Ua,10,t,n))),e.r(!1)},Wa=function(){G.registry.register({displayText(t){return t.workspace?(t=Ha(t.workspace).length,t===1?e.C.DELETE_BLOCK:e.C.DELETE_X_BLOCKS.replace(`%1`,`${t}`)):``},preconditionFn(e){return e.workspace&&Ha(e.workspace).length>0?`enabled`:`disabled`},callback(t){if(t.workspace){t.workspace.cancelCurrentGesture();var n=Ha(t.workspace);n.length<2?Ua(n):Ft(e.C.DELETE_ALL_BLOCKS.replace(`%1`,String(n.length)),function(e){e&&Ua(n)})}},scopeType:G.ScopeType.WORKSPACE,id:`workspaceDelete`,weight:6})},Ga=function(){G.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&&Oi(t,e.block.workspace)}},scopeType:G.ScopeType.BLOCK,id:`blockDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},Ka=function(){G.registry.register({displayText(t){return t.block.hasIcon(Lf.TYPE)?e.C.REMOVE_COMMENT:e.C.ADD_COMMENT},preconditionFn(e){e=e.block;var t;return(t=e&&!e.isInFlyout&&e.workspace.options.comments&&!e.isCollapsed()&&e.isEditable())&&!(t=e.hasIcon(Lf.TYPE))&&(e=e&&e.isSimpleReporter()?e.getFields().next().value?.isFullBlockField():!1,t=!e),t?`enabled`:`hidden`},callback(e){(e=e.block)&&e.hasIcon(Lf.TYPE)?e.setCommentText(null):e.setCommentText(``)},scopeType:G.ScopeType.BLOCK,id:`blockComment`,weight:2})},qa=function(){G.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 Lp||e.inputList[t]instanceof Lp))return`enabled`}return`hidden`},callback(e){e.block.setInputsInline(!e.block.getInputsInline())},scopeType:G.ScopeType.BLOCK,id:`blockInline`,weight:3})},Ja=function(){G.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:G.ScopeType.BLOCK,id:`blockCollapseExpand`,weight:4})},Ya=function(){G.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.fd;n||e.r(!0),t.setDisabledReason(!t.hasDisabledReason(`MANUALLY_DISABLED`),`MANUALLY_DISABLED`),e.r(n)},scopeType:G.ScopeType.BLOCK,id:`blockDisable`,weight:5})},Xa=function(){G.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.A().focusNode(t.block),t.block.checkAndDelete())},scopeType:G.ScopeType.BLOCK,id:`blockDelete`,weight:6,associatedKeyboardShortcut:`delete`})},Za=function(){G.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:G.ScopeType.BLOCK,id:`blockHelp`,weight:7})},Qa=function(){G.registry.register({displayText:()=>e.C.REMOVE_COMMENT,preconditionFn(e){var t;return(t=e.comment)!=null&&t.isDeletable()?`enabled`:`hidden`},callback(t){e.r(!0);var n;(n=t.comment)==null||n.dispose(),e.r(!1);var r;(r=t.comment)==null||r.workspace.getAudioManager().play(`delete`)},scopeType:G.ScopeType.COMMENT,id:`commentDelete`,weight:6,associatedKeyboardShortcut:`delete`})},$a=function(){G.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&&Oi(t,e.comment.workspace)}},scopeType:G.ScopeType.COMMENT,id:`commentDuplicate`,weight:1,associatedKeyboardShortcut:`duplicate`})},eo=function(){G.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.r(!0),n=new ed(t),n.moveTo(nt(t,new z(i.x,i.y))),e.A().focusNode(n),e.r(!1))},scopeType:G.ScopeType.WORKSPACE,id:`commentCreate`,weight:8})},to=function(){Fa(),Ia(),La(),za(),Ba(),Wa(),Ga(),Ka(),qa(),Ja(),Ya(),Xa(),Za()},j||={},j.scope={},j.ASSUME_ES5=!1,j.ASSUME_ES6=!1,j.ASSUME_ES2020=!1,j.ASSUME_NO_NATIVE_MAP=!1,j.ASSUME_NO_NATIVE_SET=!1,j.ISOLATE_POLYFILLS=!1,j.FORCE_POLYFILL_PROMISE=!1,j.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1,j.INSTRUMENT_ASYNC_CONTEXT=!0,j.objectCreate=j.ASSUME_ES5||typeof Object.create==`function`?Object.create:function(e){function t(){}return t.prototype=e,new t},j.defineProperty=j.ASSUME_ES5||typeof Object.defineProperties==`function`?Object.defineProperty:function(e,t,n){return e==Array.prototype||e==Object.prototype||(e[t]=n.value),e},j.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`)},j.global=j.ASSUME_ES2020?globalThis:j.getGlobal(this),j.IS_SYMBOL_NATIVE=typeof Symbol==`function`&&typeof Symbol(`x`)==`symbol`,j.TRUST_ES6_POLYFILLS=!j.ISOLATE_POLYFILLS||j.IS_SYMBOL_NATIVE,j.polyfills={},j.propertyToPolyfillSymbol={},j.POLYFILL_PREFIX=`$jscp$`;var no=`Int8 Uint8 Uint8Clamped Int16 Uint16 Int32 Uint32 Float32 Float64`.split(` `);j.global.BigInt64Array&&(no.push(`BigInt64`),no.push(`BigUint64`)),j.TYPED_ARRAY_CLASSES=no,j.polyfillTypedArrayMethod=function(e,t,n,r){if(t)for(var i=0;i<j.TYPED_ARRAY_CLASSES.length;i++){var a=j.TYPED_ARRAY_CLASSES[i]+`Array.prototype.`+e;j.ISOLATE_POLYFILLS?j.polyfillIsolated(a,t,n,r):j.polyfillUnisolated(a,t,n,r)}},j.polyfill=function(e,t,n,r){t&&(j.ISOLATE_POLYFILLS?j.polyfillIsolated(e,t,n,r):j.polyfillUnisolated(e,t,n,r))},j.polyfillUnisolated=function(e,t){var n=j.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&&j.defineProperty(n,e,{configurable:!0,writable:!0,value:t})},j.polyfillIsolated=function(e,t,n){var r=e.split(`.`);e=r.length===1;var i=r[0];i=!e&&i in j.polyfills?j.polyfills:j.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=j.IS_SYMBOL_NATIVE&&n===`es6`?i[r]:null,t=t(n),t!=null&&(e?j.defineProperty(j.polyfills,r,{configurable:!0,writable:!0,value:t}):t!==n&&(j.propertyToPolyfillSymbol[r]===void 0&&(e=Math.random()*1e9>>>0,j.propertyToPolyfillSymbol[r]=j.IS_SYMBOL_NATIVE?j.global.Symbol(r):j.POLYFILL_PREFIX+e+`$`+r),j.defineProperty(i,j.propertyToPolyfillSymbol[r],{configurable:!0,writable:!0,value:t})))},j.getConstructImplementation=function(){function e(){function e(){}return new e,Reflect.construct(e,[],function(){}),new e instanceof e}if(j.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=j.objectCreate(n.prototype||Object.prototype),Function.prototype.apply.call(e,n,t)||n}},j.construct={valueOf:j.getConstructImplementation}.valueOf(),j.underscoreProtoCanBeSet=function(){var e={a:!0},t={};try{return t.__proto__=e,t.a}catch{}return!1},j.setPrototypeOf=j.ASSUME_ES6||j.TRUST_ES6_POLYFILLS&&typeof Object.setPrototypeOf==`function`?Object.setPrototypeOf:j.underscoreProtoCanBeSet()?function(e,t){if(e.__proto__=t,e.__proto__!==t)throw TypeError(e+` is not extensible`);return e}:null,j.inherits=function(e,t){if(e.prototype=j.objectCreate(t.prototype),e.prototype.constructor=e,j.ASSUME_ES6||j.setPrototypeOf){var n=j.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},j.arrayIteratorImpl=function(e){var t=0;return function(){return t<e.length?{done:!1,value:e[t++]}:{done:!0}}},j.arrayIterator=function(e){return{next:j.arrayIteratorImpl(e)}},j.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 j.arrayIterator(e);throw Error(String(e)+` is not an iterable or ArrayLike`)},j.arrayFromIterator=function(e){for(var t,n=[];!(t=e.next()).done;)n.push(t.value);return n},j.arrayFromIterable=function(e){return e instanceof Array?e:j.arrayFromIterator(j.makeIterator(e))},j.generator={},j.generator.ensureIteratorResultIsObject_=function(e){if(!(e instanceof Object))throw TypeError(`Iterator result `+e+` is not an object`)},j.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},j.generator.Context.prototype.start_=function(){if(this.isRunning_)throw TypeError(`Generator is already running`);this.isRunning_=!0},j.generator.Context.prototype.stop_=function(){this.isRunning_=!1},j.generator.Context.prototype.jumpToErrorHandler_=function(){this.nextAddress=this.catchAddress_||this.finallyAddress_},j.generator.Context.prototype.next_=function(e){this.yieldResult=e},j.generator.Context.prototype.throw_=function(e){this.abruptCompletion_={exception:e,isException:!0},this.jumpToErrorHandler_()},j.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},j.generator.Context.prototype.getNextAddressJsc=function(){return this.nextAddress},j.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},j.generator.Context.prototype.getYieldResultJsc=function(){return this.yieldResult},j.generator.Context.prototype.return=function(e){this.abruptCompletion_={return:e},this.nextAddress=this.finallyAddress_},j.generator.Context.prototype.return=j.generator.Context.prototype.return,j.generator.Context.prototype.jumpThroughFinallyBlocks=function(e){this.abruptCompletion_={jumpTo:e},this.nextAddress=this.finallyAddress_},j.generator.Context.prototype.jumpThroughFinallyBlocks=j.generator.Context.prototype.jumpThroughFinallyBlocks,j.generator.Context.prototype.yield=function(e,t){return this.nextAddress=t,{value:e}},j.generator.Context.prototype.yield=j.generator.Context.prototype.yield,j.generator.Context.prototype.yieldAll=function(e,t){e=j.makeIterator(e);var n=e.next();if(j.generator.ensureIteratorResultIsObject_(n),n.done)this.yieldResult=n.value,this.nextAddress=t;else return this.yieldAllIterator_=e,this.yield(n.value,t)},j.generator.Context.prototype.yieldAll=j.generator.Context.prototype.yieldAll,j.generator.Context.prototype.jumpTo=function(e){this.nextAddress=e},j.generator.Context.prototype.jumpTo=j.generator.Context.prototype.jumpTo,j.generator.Context.prototype.jumpToEnd=function(){this.nextAddress=0},j.generator.Context.prototype.jumpToEnd=j.generator.Context.prototype.jumpToEnd,j.generator.Context.prototype.setCatchFinallyBlocks=function(e,t){this.catchAddress_=e,t!=null&&(this.finallyAddress_=t)},j.generator.Context.prototype.setCatchFinallyBlocks=j.generator.Context.prototype.setCatchFinallyBlocks,j.generator.Context.prototype.setFinallyBlock=function(e){this.catchAddress_=0,this.finallyAddress_=e||0},j.generator.Context.prototype.setFinallyBlock=j.generator.Context.prototype.setFinallyBlock,j.generator.Context.prototype.leaveTryBlock=function(e,t){this.nextAddress=e,this.catchAddress_=t||0},j.generator.Context.prototype.leaveTryBlock=j.generator.Context.prototype.leaveTryBlock,j.generator.Context.prototype.enterCatchBlock=function(e){return this.catchAddress_=e||0,e=this.abruptCompletion_.exception,this.abruptCompletion_=null,e},j.generator.Context.prototype.enterCatchBlock=j.generator.Context.prototype.enterCatchBlock,j.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},j.generator.Context.prototype.enterFinallyBlock=j.generator.Context.prototype.enterFinallyBlock,j.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},j.generator.Context.prototype.leaveFinallyBlock=j.generator.Context.prototype.leaveFinallyBlock,j.generator.Context.prototype.forIn=function(e){return new j.generator.Context.PropertyIterator(e)},j.generator.Context.prototype.forIn=j.generator.Context.prototype.forIn,j.generator.Context.PropertyIterator=function(e){for(var t in this.object_=e,this.properties_=[],e)this.properties_.push(t);this.properties_.reverse()},j.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},j.generator.Context.PropertyIterator.prototype.getNext=j.generator.Context.PropertyIterator.prototype.getNext,j.generator.Engine_=function(e){this.context_=new j.generator.Context,this.program_=e},j.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_())},j.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_())},j.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_())},j.generator.Engine_.prototype.yieldAllStep_=function(e,t,n){try{var r=e.call(this.context_.yieldAllIterator_,t);if(j.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_()},j.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}},j.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}},j.generator.createGenerator=function(e,t){return t=new j.generator.Generator_(new j.generator.Engine_(t)),j.setPrototypeOf&&e.prototype&&j.setPrototypeOf(t,e.prototype),t},j.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())})},j.asyncExecutePromiseGeneratorFunction=function(e){return j.asyncExecutePromiseGenerator(e())},j.asyncExecutePromiseGeneratorProgram=function(e){return j.asyncExecutePromiseGenerator(new j.generator.Generator_(new j.generator.Engine_(e)))},j.polyfill(`globalThis`,function(e){return e||j.global},`es_2020`,`es3`),j.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`),j.owns=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},j.polyfill(`Object.values`,function(e){return e||function(e){var t=[],n;for(n in e)j.owns(e,n)&&t.push(e[n]);return t}},`es8`,`es3`),j.checkEs6ConformanceViaProxy=function(){try{var e={},t=Object.create(new j.global.Proxy(e,{get:function(n,r,i){return n==e&&r==`q`&&i==t}}));return t.q===!0}catch{return!1}},j.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS=!1,j.ES6_CONFORMANCE=j.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS&&j.checkEs6ConformanceViaProxy(),j.initSymbol=function(){},j.iteratorPrototype=function(e){return e={next:e},e[Symbol.iterator]=function(){return this},e},j.MapEntry=function(){},j.polyfill(`Set.prototype.difference`,function(e){return e||function(e){j.checkIsSetInstance(this),j.checkIsSetLike(e);var t=j.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`),j.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`)},j.checkIsValidIterator=function(e){if(typeof e!=`object`||!e||typeof e.next!=`function`)throw TypeError(`Invalid iterator.`);return e},j.getSmallerAndLargerSets=function(e,t){return e.size<=t.size?{smallerSetIterator:e.keys(),largerSet:t}:{smallerSetIterator:j.checkIsValidIterator(t.keys()),largerSet:e}},j.checkIsSetInstance=function(e){if(!(e instanceof Set))throw TypeError(`Method must be called on an instance of Set.`)},j.iteratorFromArray=function(e,t){if(j.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},j.polyfill(`Array.prototype.values`,function(e){return e||function(){return j.iteratorFromArray(this,function(e,t){return t})}},`es8`,`es3`),j.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`),j.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`),j.polyfill(`Object.entries`,function(e){return e||function(e){var t=[],n;for(n in e)j.owns(e,n)&&t.push([n,e[n]]);return t}},`es8`,`es3`);var ro=Object.create(null),io={typeMap:ro},ao=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 oo={DEFAULT:`default`,TEST_ONLY:io};oo.Type=M,oo.getAllItems=o,oo.getClass=a,oo.getClassFromOptions=s,oo.getObject=function(e,t,n){return r(e,t,n)},oo.hasItem=i,oo.register=t,oo.unregister=n;var so=Object.create(null),co=`ontouchstart`in globalThis||!!(globalThis.document&&document.documentElement&&`ontouchstart`in document.documentElement)||!(!globalThis.navigator||!globalThis.navigator.maxTouchPoints&&!globalThis.navigator.msMaxTouchPoints),lo=null,uo={mousedown:[`pointerdown`],mouseenter:[`pointerenter`],mouseleave:[`pointerleave`],mousemove:[`pointermove`],mouseout:[`pointerout`],mouseover:[`pointerover`],mouseup:[`pointerup`,`pointercancel`],touchend:[`pointerup`],touchcancel:[`pointercancel`]},fo=0,po={TOUCH_ENABLED:co,TOUCH_MAP:uo};po.checkTouchIdentifier=f,po.clearTouchIdentifier=function(){lo=null},po.getTouchIdentifierFromEvent=d,po.longStart=c,po.longStop=l,po.shouldHandleEvent=u;var mo,ho,go,_o,vo,yo,bo,xo,So,Co;(function(e){function t(e){return n.includes(e.toUpperCase())}mo=e;var n=mo.toUpperCase();ho=t(`JavaFX`),go=t(`WebKit`),_o=t(`Gecko`)&&!go,vo=t(`Android`),e=globalThis.navigator&&globalThis.navigator.maxTouchPoints,yo=t(`iPad`)||t(`Macintosh`)&&e>0,bo=t(`iPhone`)&&!yo,xo=t(`Macintosh`),So=yo||vo&&!t(`Mobile`)||t(`Silk`),Co=!So&&(bo||vo)})(globalThis.navigator&&globalThis.navigator.userAgent||``);var wo=ho,To=_o,Eo=vo,Do=yo,Oo=bo,ko=xo,Ao=Co,jo=ko||Do||Oo,Mo={ANDROID:Eo,APPLE:jo,GECKO:To,IPAD:Do,IPHONE:Oo,JavaFx:wo,MAC:ko,MOBILE:Ao,raw:mo},No={};No.bind=m,No.conditionalBind=p,No.getScrollDeltaPixels=ee,No.isRightButton=_,No.isTargetInput=g,No.mouseToSvg=v,No.unbind=h;var N,Po=N||={};Po.BLOCK_CREATE=`create`,Po.BLOCK_DELETE=`delete`,Po.BLOCK_CHANGE=`change`,Po.BLOCK_FIELD_INTERMEDIATE_CHANGE=`block_field_intermediate_change`,Po.BLOCK_MOVE=`move`,Po.VAR_CREATE=`var_create`,Po.VAR_DELETE=`var_delete`,Po.VAR_RENAME=`var_rename`,Po.VAR_TYPE_CHANGE=`var_type_change`,Po.UI=`ui`,Po.BLOCK_DRAG=`drag`,Po.SELECTED=`selected`,Po.CLICK=`click`,Po.MARKER_MOVE=`marker_move`,Po.BUBBLE_OPEN=`bubble_open`,Po.TRASHCAN_OPEN=`trashcan_open`,Po.TOOLBOX_ITEM_SELECT=`toolbox_item_select`,Po.THEME_CHANGE=`theme_change`,Po.VIEWPORT_CHANGE=`viewport_change`,Po.COMMENT_CREATE=`comment_create`,Po.COMMENT_DELETE=`comment_delete`,Po.COMMENT_CHANGE=`comment_change`,Po.COMMENT_MOVE=`comment_move`,Po.COMMENT_RESIZE=`comment_resize`,Po.COMMENT_DRAG=`comment_drag`,Po.COMMENT_COLLAPSE=`comment_collapse`,Po.FINISHED_LOADING=`finished_loading`;var Fo=[N.BLOCK_CREATE,N.BLOCK_MOVE,N.COMMENT_CREATE,N.COMMENT_MOVE],Io={genUid:()=>{var e=[];for(let t=0;t<20;t++)e[t]="!#$%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.random()*88);return e.join(``)}},Lo=0,Ro={TEST_ONLY:Io};Ro.genUid=te,Ro.getNextUniqueId=y;var zo,Bo;e.fd=``,e.Pc=!0,e.Ka=0,zo=[],Bo={FIRE_QUEUE:zo,enqueueEvent:re,fireNow:ne,fireInternal:function(e){if(oe()){if(!zo.length)try{requestAnimationFrame(()=>{setTimeout(ne,0)})}catch{setTimeout(ne,0)}re(e)}},setGroupInternal:function(t){e.fd=typeof t==`boolean`?t?te():``:t}};var Vo,Ho=Vo||={};Ho.ASSERTIVE=`assertive`,Ho.OFF=`off`,Ho.POLITE=`polite`;var Uo=Vo.OFF,Wo=[],P,Go=P||={};Go.APPLICATION=`application`,Go.BUTTON=`button`,Go.CHECKBOX=`checkbox`,Go.DIALOG=`dialog`,Go.FIGURE=`figure`,Go.GENERIC=`generic`,Go.GRID=`grid`,Go.GRIDCELL=`gridcell`,Go.GROUP=`group`,Go.LIST=`list`,Go.LISTBOX=`listbox`,Go.LISTITEM=`listitem`,Go.MENU=`menu`,Go.MENUITEM=`menuitem`,Go.OPTION=`option`,Go.PRESENTATION=`presentation`,Go.REGION=`region`,Go.ROW=`row`,Go.SEPARATOR=`separator`,Go.STATUS=`status`,Go.TEXTBOX=`textbox`,Go.TREE=`tree`,Go.TREEITEM=`treeitem`;var Ko=P.STATUS,F,qo=F||={};qo.ACTIVEDESCENDANT=`activedescendant`,qo.ATOMIC=`atomic`,qo.CHECKED=`checked`,qo.CONTROLS=`controls`,qo.DISABLED=`disabled`,qo.EXPANDED=`expanded`,qo.HASPOPUP=`haspopup`,qo.HIDDEN=`hidden`,qo.INVALID=`invalid`,qo.LABEL=`label`,qo.LABELLEDBY=`labelledby`,qo.LEVEL=`level`,qo.LIVE=`live`,qo.ROLEDESCRIPTION=`roledescription`,qo.SELECTED=`selected`,qo.VALUEMAX=`valuemax`,qo.VALUEMIN=`valuemin`,qo.OWNS=`owns`;var Jo,Yo=Jo||={};Yo[Yo.TERSE=0]=`TERSE`,Yo[Yo.STANDARD=1]=`STANDARD`,Yo[Yo.LOQUACIOUS=2]=`LOQUACIOUS`;var Xo=null,Zo,Qo=!1,$o={};$o.LiveRegionAssertiveness=Vo,$o.Role=P,$o.State=F,$o.Verbosity=Jo,$o.announceDynamicAriaState=fe,$o.clearState=le,$o.getRole=function(e){return(e=e.getAttribute(`role`))&&Object.values(P).includes(e)?e:null},$o.getState=ue,$o.initializeGlobalAriaLiveRegion=de,$o.removeRole=ce,$o.setRole=S,$o.setState=C;var I=class{constructor(e){this.tagName=e}toString(){return this.tagName}};I.ANIMATE=new I(`animate`),I.CIRCLE=new I(`circle`),I.CLIPPATH=new I(`clipPath`),I.DEFS=new I(`defs`),I.FECOMPOSITE=new I(`feComposite`),I.FECOMPONENTTRANSFER=new I(`feComponentTransfer`),I.FEFLOOD=new I(`feFlood`),I.FEFUNCA=new I(`feFuncA`),I.FEGAUSSIANBLUR=new I(`feGaussianBlur`),I.FEPOINTLIGHT=new I(`fePointLight`),I.FESPECULARLIGHTING=new I(`feSpecularLighting`),I.FILTER=new I(`filter`),I.FOREIGNOBJECT=new I(`foreignObject`),I.G=new I(`g`),I.IMAGE=new I(`image`),I.LINE=new I(`line`),I.PATH=new I(`path`),I.PATTERN=new I(`pattern`),I.POLYGON=new I(`polygon`),I.RECT=new I(`rect`),I.SVG=new I(`svg`),I.TEXT=new I(`text`),I.TSPAN=new I(`tspan`);var es,ts=es||={};ts[ts.ELEMENT_NODE=1]=`ELEMENT_NODE`,ts[ts.TEXT_NODE=3]=`TEXT_NODE`,ts[ts.COMMENT_NODE=8]=`COMMENT_NODE`;var ns=null,rs=0,is=null,as={HTML_NS:`http://www.w3.org/1999/xhtml`};as.NodeType=es,as.SVG_NS=`http://www.w3.org/2000/svg`,as.XLINK_NS=`http://www.w3.org/1999/xlink`,as.addClass=T,as.createSvgElement=w,as.getFastTextWidth=function(e,t,n,r){return be(e,t+`pt`,n,r)},as.getFastTextWidthWithSizeString=be,as.getTextWidth=ye,as.hasClass=me,as.insertAfter=he,as.measureFontMetrics=xe,as.removeClass=E,as.removeClasses=pe,as.removeNode=D,as.setCssTransform=ge,as.startTextWidthCache=_e,as.stopTextWidthCache=ve;var os=class{static findFocusedNode(e){var t=e.getRootFocusableNode();if(!t.canBeFocused())return null;var n=t.getFocusableElement();return me(n,os.ACTIVE_CLASS_NAME)||me(n,os.PASSIVE_CSS_CLASS_NAME)||(t=n.querySelector(this.ACTIVE_FOCUS_NODE_CSS_SELECTOR),(t instanceof HTMLElement||t instanceof SVGElement)&&(t=os.findFocusableNodeFor(t,e)))?t:(n=n.querySelector(this.PASSIVE_FOCUS_NODE_CSS_SELECTOR),(n instanceof HTMLElement||n instanceof SVGElement)&&(e=os.findFocusableNodeFor(n,e))?e:null)}static findFocusableNodeFor(e,t){if(!e.id||e.id===`null`||t.getNestedTrees().map(t=>os.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?os.findFocusableNodeFor(r,t):null)}};os.ACTIVE_CLASS_NAME=`blocklyActiveFocus`,os.PASSIVE_CSS_CLASS_NAME=`blocklyPassiveFocus`,os.ACTIVE_FOCUS_NODE_CSS_SELECTOR=`.${os.ACTIVE_CLASS_NAME}`,os.PASSIVE_FOCUS_NODE_CSS_SELECTOR=`.${os.PASSIVE_CSS_CLASS_NAME}`;var ss=class{constructor(e,t){this.tree=e,this.rootShouldBeAutoTabbable=t}},cs=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=os.findFocusableNodeFor(e,n.tree))break}t&&t.canBeFocused()?(e=t.getFocusableTree(),n=this.focusedNode?.getFocusableTree(),t===e.getRootFocusableNode()&&e!==n?this.focusTree(e):this.focusNode(t)):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 ss(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=os.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(){return this.focusedNode?.getFocusableTree()??null}getFocusedNode(){return this.focusedNode}focusTree(e){if(this.ensureManagerIsUnlocked(),!this.isRegistered(e))throw Error(`Attempted to focus unregistered tree: ${e}.`);var t=os.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)?.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=os.findFocusableNodeFor(r,n);r=os.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?.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=this.lookUpRegistration(n)?.rootShouldBeAutoTabbable;n!==t&&(n.onTreeFocus(e,t),i&&(n.getRootFocusableNode().getFocusableElement().tabIndex=-1)),e.onNodeFocus(),this.lockFocusStateChanges=!1,i&&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(),T(e,cs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),E(e,cs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}setNodeToVisualPassiveFocus(e){e=e.getFocusableElement(),E(e,cs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),T(e,cs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}removeHighlight(e){e=e.getFocusableElement(),E(e,cs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME),E(e,cs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME)}static getFocusManager(){return cs.focusManager||=new cs(document.addEventListener),cs.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)}};cs.ACTIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyActiveFocus`,cs.PASSIVE_FOCUS_NODE_CSS_CLASS_NAME=`blocklyPassiveFocus`,cs.focusManager=null;var ls={};ls.deepMerge=we;var L=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 we(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.A().getFocusedNode()??void 0}))continue;let a;if((a=r.callback)!=null&&a.call(r,t,n,r,{focusedNode:e.A().getFocusedNode()??void 0}))return!0}return!1}getShortcutNamesByKeyCode(e){return this.keyMap.get(e)?.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 L.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 L.modifierKeys))throw Error(t+` is not a valid modifier key.`)}createSerializedKey(e,t){var n=``;if(t){this.checkModifiers(t);for(let e in L.modifierKeys)t.includes(L.modifierKeys[e])&&(n!==``&&(n+=`+`),n+=e)}return n!==``&&e?n+=`+`+e:e&&(n=`${e}`),n}};L.registry=new L;var us=L||={},ds=us.modifierKeys||={};ds[ds.Shift=16]=`Shift`,ds[ds.Control=17]=`Control`,ds[ds.Alt=18]=`Alt`,ds[ds.Meta=91]=`Meta`;var fs=new Set,ps={};ps.warn=Te;var R=Object.create(null),ms,hs,gs=[],_s={defineBlocksWithJsonArrayInternal:function(t){e.Pb(e.Nb(t))}},vs={TEST_ONLY:_s};vs.createBlockDefinitionsFromJsonArray=e.Nb,vs.defineBlocks=e.Pb,vs.defineBlocksWithJsonArray=ze,vs.draggingConnections=gs,vs.fireSelectedEvent=Ne,vs.getAllWorkspaces=De,vs.getBlockTypeCounts=Le,vs.getMainWorkspace=Ae,vs.getParentContainer=Pe,vs.getSelected=Me,vs.getWorkspaceById=Ee,vs.globalShortcutHandler=Be,vs.registerWorkspace=Oe,vs.setMainWorkspace=je,vs.setParentContainer=Fe,vs.setSelected=function(t){e.A().focusNode(t)},vs.svgResize=Ie,vs.unregisterWorkpace=function(e){Te(`Blockly.common.unregisterWorkpace`,`v13`,`v14`,`Blockly.common.unregisterWorkspace`),ke(e)},vs.unregisterWorkspace=ke;var ys=class{constructor(){this.workspaceId=void 0,this.isUiEvent=!1,this.type=``,this.group=e.fd,this.recordUndo=e.Pc}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=Ee(this.workspaceId)),!e)throw Error(`Workspace is null. Event must have been generated from real Blockly events.`);return e}},bs=class extends ys{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.isUiEvent=!0,this.isBlank=e===void 0,this.workspaceId=e||``}},xs=class extends bs{constructor(e,t,n){t=e?e.workspace.id:t,t===null&&(t=void 0),super(t),this.type=N.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=bs.fromJson(e,t,n??new xs),t.targetType=e.targetType,t.blockId=e.blockId,t}},Ss,Cs=Ss||={};Cs.BLOCK=`block`,Cs.WORKSPACE=`workspace`,Cs.ZOOM_CONTROLS=`zoom_controls`,t(M.EVENT,N.CLICK,xs);var ws={};ws.removeElem=Ve;var Ts=class{constructor(e){this.name=e}toString(){return this.name}};Ts.POSITIONABLE=new Ts(`positionable`),Ts.DRAG_TARGET=new Ts(`drag_target`),Ts.DELETE_AREA=new Ts(`delete_area`),Ts.AUTOHIDEABLE=new Ts(`autohideable`);var Es=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))?.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();Ve(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(),Ve(this.componentData.get(e).capabilities,t),Ve(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){return this.componentData.get(e)?.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}};Es.Capability=Ts;var Ds=Es||={},Os=Ds.ComponentWeight||={};Os[Os.TOOLBOX_WEIGHT=0]=`TOOLBOX_WEIGHT`,Os[Os.FLYOUT_WEIGHT=1]=`FLYOUT_WEIGHT`,Os[Os.TRASHCAN_WEIGHT=2]=`TRASHCAN_WEIGHT`,Os[Os.ZOOM_CONTROLS_WEIGHT=3]=`ZOOM_CONTROLS_WEIGHT`;var ks=new WeakSet,As=[],js=`
13
+ :is(
14
+ .injectionDiv,
15
+ .blocklyWidgetDiv,
16
+ .blocklyDropdownDiv,
17
+ .blocklyTooltipDiv,
18
+ ) * {
19
+ box-sizing: border-box;
20
+ }
21
+
22
+ .blocklySvg {
23
+ background-color: #fff;
24
+ outline: none;
25
+ overflow: hidden; /* IE overflows by default. */
26
+ position: absolute;
27
+ display: block;
28
+ }
29
+
30
+ .blocklyWidgetDiv {
31
+ display: none;
32
+ position: absolute;
33
+ z-index: 99999; /* big value for bootstrap3 compatibility */
34
+ }
35
+
36
+ .injectionDiv {
37
+ height: 100%;
38
+ position: relative;
39
+ overflow: hidden; /* So blocks in drag surface disappear at edges */
40
+ touch-action: none;
41
+ user-select: none;
42
+ -webkit-user-select: none;
43
+ }
44
+
45
+ .blocklyBlockCanvas.blocklyCanvasTransitioning,
46
+ .blocklyBubbleCanvas.blocklyCanvasTransitioning {
47
+ transition: transform .5s;
48
+ }
49
+
50
+ .blocklyEmboss {
51
+ filter: var(--blocklyEmbossFilter);
52
+ }
53
+
54
+ .blocklyTooltipDiv {
55
+ background-color: #ffffc7;
56
+ border: 1px solid #ddc;
57
+ box-shadow: 4px 4px 20px 1px rgba(0,0,0,.15);
58
+ color: #000;
59
+ display: none;
60
+ font: 9pt sans-serif;
61
+ opacity: .9;
62
+ padding: 2px;
63
+ position: absolute;
64
+ z-index: 100000; /* big value for bootstrap3 compatibility */
65
+ }
66
+
67
+ .blocklyDropDownDiv {
68
+ position: absolute;
69
+ left: 0;
70
+ top: 0;
71
+ z-index: 1000;
72
+ visibility: hidden;
73
+ border: 1px solid;
74
+ border-color: #dadce0;
75
+ background-color: #fff;
76
+ border-radius: 2px;
77
+ padding: 4px;
78
+ box-shadow: 0 0 3px 1px rgba(0,0,0,.3);
79
+ }
80
+
81
+ .blocklyDropDownDiv:focus {
82
+ box-shadow: 0 0 6px 1px rgba(0,0,0,.3);
83
+ }
84
+
85
+ .blocklyDropDownContent {
86
+ max-height: 300px; /* @todo: spec for maximum height. */
87
+ }
88
+
89
+ .blocklyDropDownArrow {
90
+ position: absolute;
91
+ left: 0;
92
+ top: 0;
93
+ width: 16px;
94
+ height: 16px;
95
+ z-index: -1;
96
+ background-color: inherit;
97
+ border-color: inherit;
98
+ border-top: 1px solid;
99
+ border-left: 1px solid;
100
+ border-top-left-radius: 4px;
101
+ border-color: inherit;
102
+ }
103
+
104
+ .blocklyHighlighted>.blocklyPath {
105
+ filter: var(--blocklyEmbossFilter);
106
+ }
107
+
108
+ .blocklyHighlightedConnectionPath {
109
+ fill: none;
110
+ stroke: #fc3;
111
+ stroke-width: 4px;
112
+ }
113
+
114
+ .blocklyPathLight {
115
+ fill: none;
116
+ stroke-linecap: round;
117
+ stroke-width: 1;
118
+ }
119
+
120
+ .blocklySelected>.blocklyPathLight {
121
+ display: none;
122
+ }
123
+
124
+ .blocklyDraggable {
125
+ cursor: grab;
126
+ cursor: -webkit-grab;
127
+ }
128
+
129
+ .blocklyDragging {
130
+ cursor: grabbing;
131
+ cursor: -webkit-grabbing;
132
+ /* Drag surface disables events to not block the toolbox, so we have to
133
+ * reenable them here for the cursor values to work. */
134
+ pointer-events: auto;
135
+ }
136
+
137
+ /* Changes cursor on mouse down. Not effective in Firefox because of
138
+ https://bugzilla.mozilla.org/show_bug.cgi?id=771241 */
139
+ .blocklyDraggable:active {
140
+ cursor: grabbing;
141
+ cursor: -webkit-grabbing;
142
+ }
143
+
144
+ .blocklyDragging.blocklyDraggingDelete,
145
+ .blocklyDragging.blocklyDraggingDelete .blocklyField {
146
+ cursor: url("<<<PATH>>>/handdelete.cur"), auto;
147
+ }
148
+
149
+ .blocklyDragging>.blocklyPath,
150
+ .blocklyDragging>.blocklyPathLight {
151
+ fill-opacity: .8;
152
+ stroke-opacity: .8;
153
+ }
154
+
155
+ .blocklyDragging>.blocklyPathDark {
156
+ display: none;
157
+ }
158
+
159
+ .blocklyDisabledPattern>.blocklyPath {
160
+ fill: var(--blocklyDisabledPattern);
161
+ fill-opacity: .5;
162
+ stroke-opacity: .5;
163
+ }
164
+
165
+ .blocklyDisabled>.blocklyPathLight,
166
+ .blocklyDisabled>.blocklyPathDark {
167
+ display: none;
168
+ }
169
+
170
+ .blocklyInsertionMarker>.blocklyPath,
171
+ .blocklyInsertionMarker>.blocklyPathLight,
172
+ .blocklyInsertionMarker>.blocklyPathDark {
173
+ fill-opacity: .2;
174
+ stroke: none;
175
+ }
176
+
177
+ .blocklyNonEditableField>text {
178
+ pointer-events: none;
179
+ }
180
+
181
+ .blocklyFlyout {
182
+ position: absolute;
183
+ z-index: 20;
184
+ }
185
+
186
+ .blocklyText text {
187
+ cursor: default;
188
+ }
189
+
190
+ /*
191
+ Don't allow users to select text. It gets annoying when trying to
192
+ drag a block and selected text moves instead.
193
+ */
194
+ .blocklySvg text {
195
+ user-select: none;
196
+ -ms-user-select: none;
197
+ -webkit-user-select: none;
198
+ cursor: inherit;
199
+ }
200
+
201
+ .blocklyIconGroup {
202
+ cursor: default;
203
+ }
204
+
205
+ .blocklyIconGroup:not(:hover):not(:focus),
206
+ .blocklyIconGroupReadonly {
207
+ opacity: .6;
208
+ }
209
+
210
+ .blocklyIconShape {
211
+ fill: #00f;
212
+ stroke: #fff;
213
+ stroke-width: 1px;
214
+ }
215
+
216
+ .blocklyIconSymbol {
217
+ fill: #fff;
218
+ }
219
+
220
+ .blocklyMinimalBody {
221
+ margin: 0;
222
+ padding: 0;
223
+ height: 100%;
224
+ }
225
+
226
+ .blocklyHtmlInput {
227
+ border: none;
228
+ border-radius: 4px;
229
+ height: 100%;
230
+ margin: 0;
231
+ outline: none;
232
+ padding: 0;
233
+ width: 100%;
234
+ text-align: center;
235
+ display: block;
236
+ box-sizing: border-box;
237
+ }
238
+
239
+ /* Remove the increase and decrease arrows on the field number editor */
240
+ input.blocklyHtmlInput[type=number]::-webkit-inner-spin-button,
241
+ input.blocklyHtmlInput[type=number]::-webkit-outer-spin-button {
242
+ -webkit-appearance: none;
243
+ margin: 0;
244
+ }
245
+
246
+ input[type=number] {
247
+ -moz-appearance: textfield;
248
+ }
249
+
250
+ .blocklyMainBackground {
251
+ stroke-width: 1;
252
+ stroke: #c6c6c6; /* Equates to #ddd due to border being off-pixel. */
253
+ }
254
+
255
+ .blocklyMutatorBackground {
256
+ fill: #fff;
257
+ stroke: #ddd;
258
+ stroke-width: 1;
259
+ }
260
+
261
+ .blocklyFlyoutBackground {
262
+ fill: #ddd;
263
+ fill-opacity: .8;
264
+ }
265
+
266
+ .blocklyMainWorkspaceScrollbar {
267
+ z-index: 20;
268
+ }
269
+
270
+ .blocklyFlyoutScrollbar {
271
+ z-index: 30;
272
+ }
273
+
274
+ .blocklyScrollbarHorizontal,
275
+ .blocklyScrollbarVertical {
276
+ position: absolute;
277
+ outline: none;
278
+ }
279
+
280
+ .blocklyScrollbarBackground {
281
+ opacity: 0;
282
+ pointer-events: none;
283
+ }
284
+
285
+ .blocklyScrollbarHandle {
286
+ fill: #ccc;
287
+ }
288
+
289
+ .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,
290
+ .blocklyScrollbarHandle:hover {
291
+ fill: #bbb;
292
+ }
293
+
294
+ /* Darken flyout scrollbars due to being on a grey background. */
295
+ /* By contrast, workspace scrollbars are on a white background. */
296
+ .blocklyFlyout .blocklyScrollbarHandle {
297
+ fill: #bbb;
298
+ }
299
+
300
+ .blocklyFlyout .blocklyScrollbarBackground:hover+.blocklyScrollbarHandle,
301
+ .blocklyFlyout .blocklyScrollbarHandle:hover {
302
+ fill: #aaa;
303
+ }
304
+
305
+ .blocklyInvalidInput {
306
+ background: #faa;
307
+ }
308
+
309
+ .blocklyVerticalMarker {
310
+ stroke-width: 3px;
311
+ fill: rgba(255,255,255,.5);
312
+ pointer-events: none;
313
+ }
314
+
315
+ .blocklyComputeCanvas {
316
+ position: absolute;
317
+ width: 0;
318
+ height: 0;
319
+ }
320
+
321
+ .blocklyNoPointerEvents {
322
+ pointer-events: none;
323
+ }
324
+
325
+ .blocklyContextMenu {
326
+ border-radius: 4px;
327
+ max-height: 100%;
328
+ box-sizing: content-box;
329
+ }
330
+
331
+ .blocklyDropdownMenu {
332
+ border-radius: 2px;
333
+ padding: 0 !important;
334
+ }
335
+
336
+ .blocklyDropdownMenu .blocklyMenuItem {
337
+ /* 28px on the left for icon or checkbox. */
338
+ padding-left: 28px;
339
+ }
340
+
341
+ /* BiDi override for the resting state. */
342
+ .blocklyDropdownMenu .blocklyMenuItemRtl {
343
+ /* Flip left/right padding for BiDi. */
344
+ padding-left: 5px;
345
+ padding-right: 28px;
346
+ }
347
+
348
+ .blocklyWidgetDiv .blocklyMenu {
349
+ user-select: none;
350
+ -ms-user-select: none;
351
+ -webkit-user-select: none;
352
+ background: #fff;
353
+ border: 1px solid transparent;
354
+ box-shadow: 0 0 3px 1px rgba(0,0,0,.3);
355
+ font: normal 13px Arial, sans-serif;
356
+ margin: 0;
357
+ outline: none;
358
+ padding: 4px 0;
359
+ position: absolute;
360
+ overflow-y: auto;
361
+ overflow-x: hidden;
362
+ max-height: 100%;
363
+ z-index: 20000; /* Arbitrary, but some apps depend on it... */
364
+ }
365
+
366
+ .blocklyWidgetDiv .blocklyMenu:focus {
367
+ box-shadow: 0 0 6px 1px rgba(0,0,0,.3);
368
+ }
369
+
370
+ .blocklyDropDownDiv .blocklyMenu {
371
+ user-select: none;
372
+ -ms-user-select: none;
373
+ -webkit-user-select: none;
374
+ background: inherit; /* Compatibility with gapi, reset from goog-menu */
375
+ border: inherit; /* Compatibility with gapi, reset from goog-menu */
376
+ font: normal 13px "Helvetica Neue", Helvetica, sans-serif;
377
+ outline: none;
378
+ overflow-y: auto;
379
+ overflow-x: hidden;
380
+ max-height: 100%;
381
+ z-index: 20000; /* Arbitrary, but some apps depend on it... */
382
+ }
383
+
384
+ /* State: resting. */
385
+ .blocklyMenuItem {
386
+ border: none;
387
+ color: #000;
388
+ cursor: pointer;
389
+ list-style: none;
390
+ margin: 0;
391
+ /* 7em on the right for shortcut. */
392
+ min-width: 7em;
393
+ padding: 6px 15px;
394
+ white-space: nowrap;
395
+ }
396
+
397
+ /* State: disabled. */
398
+ .blocklyMenuItemDisabled {
399
+ color: #ccc;
400
+ cursor: inherit;
401
+ }
402
+
403
+ /* State: hover. */
404
+ .blocklyMenuItemHighlight {
405
+ background-color: rgba(0,0,0,.1);
406
+ }
407
+
408
+ /* State: selected/checked. */
409
+ .blocklyMenuItemSelected .blocklyMenuItemCheckbox {
410
+ background: url(<<<PATH>>>/sprites.svg) no-repeat -48px -16px;
411
+ float: left;
412
+ margin-left: -24px;
413
+ width: 16px;
414
+ height: 16px;
415
+ position: static; /* Scroll with the menu. */
416
+ display: block;
417
+ }
418
+
419
+ .blocklyMenuItemRtl .blocklyMenuItemCheckbox {
420
+ float: right;
421
+ margin-right: -24px;
422
+ }
423
+
424
+ .blocklyMenuSeparator {
425
+ background-color: #ccc;
426
+ height: 1px;
427
+ border: 0;
428
+ margin-left: 4px;
429
+ margin-right: 4px;
430
+ }
431
+
432
+ .blocklyRTL .blocklyMenuItemContent .blocklyShortcutContainer {
433
+ flex-direction: row-reverse;
434
+ }
435
+ .blocklyMenuItemContent .blocklyShortcutContainer {
436
+ width: 100%;
437
+ display: flex;
438
+ justify-content: space-between;
439
+ gap: 16px;
440
+ }
441
+ .blocklyMenuItemContent .blocklyShortcutContainer .blocklyShortcut {
442
+ color: #ccc;
443
+ }
444
+
445
+ .blocklyBlockDragSurface, .blocklyAnimationLayer {
446
+ position: absolute;
447
+ top: 0;
448
+ left: 0;
449
+ right: 0;
450
+ bottom: 0;
451
+ overflow: visible !important;
452
+ z-index: 80;
453
+ pointer-events: none;
454
+ }
455
+
456
+ .blocklyField {
457
+ cursor: default;
458
+ }
459
+
460
+ .blocklyInputField {
461
+ cursor: text;
462
+ }
463
+
464
+ .blocklyDragging .blocklyField,
465
+ .blocklyDragging .blocklyIconGroup {
466
+ cursor: grabbing;
467
+ }
468
+
469
+ .blocklyActiveFocus:is(
470
+ .blocklyFlyout,
471
+ .blocklyWorkspace,
472
+ .blocklyField,
473
+ .blocklyPath,
474
+ .blocklyHighlightedConnectionPath,
475
+ .blocklyComment,
476
+ .blocklyBubble,
477
+ .blocklyIconGroup,
478
+ .blocklyTextarea,
479
+ .blocklyZoom,
480
+ .blocklyTrash,
481
+ ) {
482
+ outline: none;
483
+ }
484
+ .hiddenForAria {
485
+ position: absolute;
486
+ left: -9999px;
487
+ width: 1px;
488
+ height: 1px;
489
+ overflow: hidden;
490
+ }
491
+
492
+ .injectionDiv {
493
+ --blockly-active-node-color: #fff200;
494
+ --blockly-active-tree-color: #1379f6;
495
+ --blockly-selection-width: 3px;
496
+ }
497
+
498
+ /* Active focus cases: */
499
+ /* Blocks with active focus. */
500
+ .blocklyKeyboardNavigation
501
+ .blocklyActiveFocus:is(.blocklyPath, .blocklyHighlightedConnectionPath),
502
+ /* Fields with active focus, */
503
+ .blocklyKeyboardNavigation
504
+ .blocklyActiveFocus.blocklyField
505
+ > .blocklyFieldRect,
506
+ /* Icons with active focus. */
507
+ .blocklyKeyboardNavigation
508
+ .blocklyActiveFocus.blocklyIconGroup
509
+ > .blocklyIconShape:first-child,
510
+ .blocklyKeyboardNavigation
511
+ .blocklyActiveFocus
512
+ > .blocklyFocusRing {
513
+ stroke: var(--blockly-active-node-color);
514
+ stroke-width: var(--blockly-selection-width);
515
+ }
516
+
517
+ /* Passive focus cases: */
518
+ /* Blocks with passive focus except when widget/dropdown div in use. */
519
+ .blocklyPassiveFocus:is(
520
+ .blocklyPath:not(.blocklyFlyout .blocklyPath),
521
+ .blocklyHighlightedConnectionPath
522
+ ),
523
+ /* Fields with passive focus except when widget/dropdown div in use. */
524
+ .blocklyKeyboardNavigation:not(
525
+ :has(
526
+ .blocklyDropDownDiv:focus-within,
527
+ .blocklyWidgetDiv:focus-within
528
+ )
529
+ )
530
+ .blocklyPassiveFocus.blocklyField
531
+ > .blocklyFieldRect,
532
+ /* Icons with passive focus except when widget/dropdown div in use. */
533
+ .blocklyKeyboardNavigation:not(
534
+ :has(
535
+ .blocklyDropDownDiv:focus-within,
536
+ .blocklyWidgetDiv:focus-within
537
+ )
538
+ )
539
+ .blocklyPassiveFocus.blocklyIconGroup
540
+ > .blocklyIconShape:first-child {
541
+ stroke: var(--blockly-active-node-color);
542
+ stroke-dasharray: 5px 3px;
543
+ stroke-width: var(--blockly-selection-width);
544
+ }
545
+
546
+ /* Workaround for unexpectedly hidden connection path due to core style. */
547
+ .blocklyKeyboardNavigation
548
+ .blocklyPassiveFocus.blocklyHighlightedConnectionPath {
549
+ display: unset !important;
550
+ }
551
+
552
+ /* Different ways for toolbox/flyout to be the active tree: */
553
+ /* Active focus in the flyout. */
554
+ .blocklyKeyboardNavigation .blocklyFlyout:has(.blocklyActiveFocus),
555
+ /* Active focus in the toolbox. */
556
+ .blocklyKeyboardNavigation .blocklyToolbox:has(.blocklyActiveFocus),
557
+ /* Active focus on the toolbox/flyout. */
558
+ .blocklyKeyboardNavigation
559
+ .blocklyActiveFocus:is(.blocklyFlyout, .blocklyToolbox) {
560
+ outline-offset: calc(var(--blockly-selection-width) * -1);
561
+ outline: var(--blockly-selection-width) solid
562
+ var(--blockly-active-tree-color);
563
+ }
564
+
565
+ /* Suppress default outline. */
566
+ .blocklyKeyboardNavigation
567
+ .blocklyToolboxCategoryContainer:focus-visible {
568
+ outline: none;
569
+ }
570
+
571
+ /* Different ways for the workspace to be the active tree: */
572
+ /* Active focus within workspace. */
573
+ .blocklyKeyboardNavigation
574
+ .blocklyWorkspace:has(.blocklyActiveFocus)
575
+ .blocklyWorkspaceFocusRing,
576
+ /* Active focus within drag layer. */
577
+ .blocklyKeyboardNavigation
578
+ .blocklySvg:has(~ .blocklyBlockDragSurface .blocklyActiveFocus)
579
+ .blocklyWorkspaceFocusRing,
580
+ /* Active focus on workspace. */
581
+ .blocklyKeyboardNavigation
582
+ .blocklyWorkspace.blocklyActiveFocus
583
+ .blocklyWorkspaceFocusRing,
584
+ /* Focus in widget/dropdown div considered to be in workspace. */
585
+ .blocklyKeyboardNavigation
586
+ .blocklyWorkspace.blocklyShowingDropDownDiv
587
+ .blocklyWorkspaceFocusRing,
588
+ .blocklyKeyboardNavigation
589
+ .blocklyWorkspace.blocklyShowingWidgetDiv
590
+ .blocklyWorkspaceFocusRing {
591
+ stroke: var(--blockly-active-tree-color);
592
+ stroke-width: calc(var(--blockly-selection-width) * 2);
593
+ }
594
+
595
+ /* The workspace itself is the active node. */
596
+ .blocklyKeyboardNavigation
597
+ .blocklyWorkspace.blocklyActiveFocus
598
+ .blocklyWorkspaceSelectionRing {
599
+ stroke: var(--blockly-active-node-color);
600
+ stroke-width: var(--blockly-selection-width);
601
+ }
602
+
603
+ /* The workspace itself is the active node. */
604
+ .blocklyKeyboardNavigation
605
+ .blocklyBubble.blocklyActiveFocus
606
+ .blocklyEmboss .blocklyDraggable {
607
+ stroke: var(--blockly-active-node-color);
608
+ stroke-width: var(--blockly-selection-width);
609
+ }
610
+ /* Flyout buttons and labels */
611
+ .blocklyKeyboardNavigation .blocklyFlyout .blocklyFlyoutLabel.blocklyActiveFocus,
612
+ .blocklyKeyboardNavigation .blocklyFlyout .blocklyFlyoutButton.blocklyActiveFocus {
613
+ outline: none;
614
+ }
615
+ .blocklyKeyboardNavigation .blocklyFlyout .blocklyFlyoutLabel.blocklyActiveFocus > .blocklyFlyoutLabelText,
616
+ .blocklyKeyboardNavigation .blocklyFlyout .blocklyFlyoutButton.blocklyActiveFocus > .blocklyFlyoutButtonBackground {
617
+ outline-offset: 2px;
618
+ outline: var(--blockly-selection-width) solid var(--blockly-active-node-color);
619
+ border-radius: 2px;
620
+ }
621
+ .blocklyDialog {
622
+ min-width: 300px;
623
+ border-radius: 16px;
624
+ box-shadow: 0 8px 8px rgba(0, 0, 0, 0.2);
625
+ border: 1px solid #999;
626
+ }
627
+ .blocklyDialogForm {
628
+ display: flex;
629
+ flex-direction: column;
630
+ row-gap: 8px;
631
+ }
632
+ .blocklyDialogButtonRow {
633
+ display: flex;
634
+ flex-direction: ${Ao||jo?`row-reverse`:`row`};
635
+ column-gap: 8px;
636
+ }
637
+ `,Ms={};Ms.inject=Ue,Ms.register=He;var Ns;e.C=Object.create(null),Ns={Msg:e.C,setLocale:We};var z=class{constructor(e,t){this.x=e,this.y=t}clone(){return new z(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 z(e.x-t.x,e.y-t.y)}static sum(e,t){return new z(e.x+t.x,e.y+t.y)}},B=class{constructor(e,t,n,r){this.top=e,this.bottom=t,this.left=n,this.right=r}static from(e){return new B(e.y,e.y+e.height,e.x,e.x+e.width)}clone(){return new B(this.top,this.bottom,this.left,this.right)}getHeight(){return this.bottom-this.top}getWidth(){return this.right-this.left}getOrigin(){return new z(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 B(e,e+n,r,r+t)}},V=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 V(Math.max(e.width,t.width),Math.max(e.height,t.height))}static min(e,t){return new V(Math.min(e.width,t.width),Math.min(e.height,t.height))}},Ps={getSizeInternal:function(e){if(Ke(e,`display`)!==`none`)return new V(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 V(a,e)}},Fs={TEST_ONLY:Ps};Fs.getBorderBox=Ye,Fs.getComputedStyle=Ke,Fs.getContainerOffsetToScrollInto=Ze,Fs.getPageOffset=qe,Fs.getSize=Ge,Fs.getViewportPageOffset=Je,Fs.scrollIntoContainerView=Xe;var Is=/translate\(\s*([-+\d.e]+)([ ,]\s*([-+\d.e]+)\s*)?/,Ls=/transform:\s*translate(?:3d)?\(\s*([-+\d.e]+)\s*px([ ,]\s*([-+\d.e]+)\s*px)?/,Rs={TEST_ONLY:{XY_REGEX:Is,XY_STYLE_REGEX:Ls}};Rs.getDocumentScroll=tt,Rs.getInjectionDivXY=$e,Rs.getRelativeXY=Qe,Rs.getViewportBBox=et,Rs.screenToWsCoordinates=nt,Rs.wsToScreenCoordinates=rt;var zs=class{constructor(e,t,n,r,i){this.workspace=e,this.horizontal=t,this.oldHostMetrics=null,this.ratio=1,this.origin=new z(0,0),this.startDragHandle=this.handlePosition=this.handleLength=this.scrollbarLength=this.startDragMouse=0,this.containerVisible=this.isHandleVisible=!0,this.position=new z(0,0),this.onMouseMoveWrapper_=this.onMouseUpWrapper_=null,this.pair=n||!1,this.margin=i===void 0?zs.DEFAULT_SCROLLBAR_MARGIN:i,e=`blocklyScrollbar`+(this.horizontal?`Horizontal`:`Vertical`),r&&(e+=` `+r),this.outerSvg=w(I.SVG,{class:e}),r=w(I.G,{},this.outerSvg),this.svgBackground=w(I.RECT,{class:`blocklyScrollbarBackground`},r),e=Math.floor((zs.scrollbarThickness-5)/2),this.svgHandle=w(I.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`),he(this.outerSvg,this.workspace.getParentSvg()),this.setInitialThickness(),t?(this.lengthAttribute_=`width`,this.positionAttribute_=`x`):(this.lengthAttribute_=`height`,this.positionAttribute_=`y`),this.onMouseDownBarWrapper_=p(this.svgBackground,`pointerdown`,this,this.onMouseDownBar),this.onMouseDownHandleWrapper_=p(this.svgHandle,`pointerdown`,this,this.onMouseDownHandle)}setInitialThickness(){var e=zs.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(),h(this.onMouseDownBarWrapper_),h(this.onMouseDownHandleWrapper_),D(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,ge(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&&zs.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:!0}resizeHorizontal(e){this.requiresViewResize(e)?this.resizeViewHorizontal(e):this.resizeContentHorizontal(e)}resizeViewHorizontal(e){var t=e.viewWidth-this.margin*2;this.pair&&(t-=zs.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),t=e.absoluteLeft+this.margin,this.pair&&this.workspace.RTL&&(t+=zs.scrollbarThickness),this.setPosition(t,e.absoluteTop+e.viewHeight-zs.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-=zs.scrollbarThickness),this.setScrollbarLength(Math.max(0,t)),this.setPosition(this.workspace.RTL?e.absoluteLeft+this.margin:e.absoluteLeft+e.viewWidth-zs.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(),lo=null,this.cleanUp(),_(e))e.stopPropagation();else{var t=v(e,this.workspace.getParentSvg(),this.workspace.getInverseScreenCTM());t=this.horizontal?t.x:t.y;var n=$e(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(),_(e)?e.stopPropagation():(this.startDragHandle=this.handlePosition,this.startDragMouse=this.horizontal?e.clientX:e.clientY,this.onMouseUpWrapper_=p(document,`pointerup`,this,this.onMouseUpHandle),this.onMouseMoveWrapper_=p(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(){lo=null,this.cleanUp()}cleanUp(){this.workspace.hideChaff(!0),this.onMouseUpWrapper_&&=(h(this.onMouseUpWrapper_),null),this.onMouseMoveWrapper_&&=(h(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 z(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}};zs.scrollbarThickness=co?25:15,zs.DEFAULT_SCROLLBAR_MARGIN=.5;var Bs={parseFromString:function(){throw Error(`DOMParser was not found in the global scope and was not properly injected using injectDependencies`)}},Vs={serializeToString:function(){throw Error(`XMLSerializer was not foundin the global scope and was not properly injected using injectDependencies`)}},{document:Hs,DOMParser:Us,XMLSerializer:Ws}=globalThis;Us&&(Bs=new Us),Ws&&(Vs=new Ws);var Gs=/[\x00-\x09\x0B\x0C\x0E-\x1F]/g,Ks={NAME_SPACE:`https://developers.google.com/blockly/xml`};Ks.createElement=e.F,Ks.createTextNode=e.rc,Ks.domToText=it,Ks.injectDependencies=function(e){({document:Hs=Hs,DOMParser:Us=Us,XMLSerializer:Ws=Ws}=e),Bs=new Us,Vs=new Ws},Ks.textToDom=e.tc;var H,qs=H||={};qs[qs.TOP=0]=`TOP`,qs[qs.BOTTOM=1]=`BOTTOM`,qs[qs.LEFT=2]=`LEFT`,qs[qs.RIGHT=3]=`RIGHT`;var Js={hasCategoriesInternal:function(e){if(!e)return!1;var t=e.kind;return t?t===`categoryToolbox`:!!e.contents.filter(e=>e.kind.toUpperCase()===`CATEGORY`).length}},Ys={};Ys.Position=H,Ys.TEST_ONLY=Js,Ys.convertFlyoutDefToJsonArray=st,Ys.convertToolboxDefToJson=ot,Ys.hasCategories=ct,Ys.isCategoryCollapsible=lt,Ys.parseToolboxTree=ft;var Xs,Zs=Xs||={};Zs[Zs.TOP=0]=`TOP`,Zs[Zs.BOTTOM=1]=`BOTTOM`;var Qs,$s=Qs||={};$s[$s.LEFT=0]=`LEFT`,$s[$s.RIGHT=1]=`RIGHT`;var ec,tc=ec||={};tc[tc.UP=0]=`UP`,tc[tc.DOWN=1]=`DOWN`;var nc={};nc.bumpDirection=ec,nc.bumpPositionRect=ht,nc.getCornerOppositeToolbox=mt,nc.getStartPositionRect=pt,nc.horizontalPosition=Qs,nc.verticalPosition=Xs;var rc={width:96,height:124,url:`sprites.svg`},ic=class{constructor(e,t){this.workspace=e,this.group=t,this.pointerDownHandler=p(t,`pointerdown`,null,this.performAction.bind(this)),S(t,P.BUTTON),this.id=y(),this.group.id=this.id}getId(){return this.id}zoom(e,t){this.workspace.markFocused(),this.workspace.zoomCenter(e),this.fireZoomEvent(),lo=null,t.stopPropagation(),t.preventDefault()}fireZoomEvent(){b(new(x(N.CLICK))(null,this.workspace.id,`zoom_controls`))}getFocusableElement(){return this.group}getFocusableTree(){return this.workspace}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!0}dispose(){h(this.pointerDownHandler)}},ac=class extends ic{constructor(t,n){var r=String(Math.random()).substring(2);n=w(I.G,{class:`blocklyZoom blocklyZoomIn`,tabindex:`0`},n),C(n,F.LABEL,e.C.ZOOM_IN),w(I.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=w(I.CLIPPATH,{id:`blocklyZoominClipPath`+r},n);w(I.RECT,{width:32,height:32},i),w(I.IMAGE,{width:rc.width,height:rc.height,x:-32,y:-92,"clip-path":`url(#blocklyZoominClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+rc.url),super(t,n)}performAction(e){this.zoom(1,e)}},oc=class extends ic{constructor(t,n){var r=String(Math.random()).substring(2);n=w(I.G,{class:`blocklyZoom blocklyZoomOut`,tabindex:`0`},n),C(n,F.LABEL,e.C.ZOOM_OUT),w(I.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=w(I.CLIPPATH,{id:`blocklyZoomoutClipPath`+r},n);w(I.RECT,{width:32,height:32},i),w(I.IMAGE,{width:rc.width,height:rc.height,x:-64,y:-92,"clip-path":`url(#blocklyZoomoutClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+rc.url),super(t,n)}performAction(e){this.zoom(-1,e)}},sc=class extends ic{constructor(t,n){var r=String(Math.random()).substring(2);n=w(I.G,{class:`blocklyZoom blocklyZoomReset`,tabindex:`0`},n),C(n,F.LABEL,e.C.RESET_ZOOM),w(I.RECT,{width:40,height:40,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},n);var i=w(I.CLIPPATH,{id:`blocklyZoomresetClipPath`+r},n);w(I.RECT,{width:32,height:32},i),w(I.IMAGE,{width:rc.width,height:rc.height,y:-92,"clip-path":`url(#blocklyZoomresetClipPath`+r+`)`},n).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,t.options.pathToMedia+rc.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(),lo=null,e.stopPropagation(),e.preventDefault()}},cc=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(){return this.svgGroup=w(I.G,{}),this.zoomOutControl=new oc(this.workspace,this.svgGroup),this.zoomInControl=new ac(this.workspace,this.svgGroup),this.workspace.isMovable()&&(this.zoomResetControl=new sc(this.workspace,this.svgGroup)),this.svgGroup}init(){this.workspace.getComponentManager().addComponent({component:this,weight:Es.ComponentWeight.ZOOM_CONTROLS_WEIGHT,capabilities:[Es.Capability.POSITIONABLE]}),this.initialized=!0}dispose(){this.workspace.getComponentManager().removeComponent(`zoomControls`),this.svgGroup&&D(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 B(this.top,this.top+e,this.left,this.left+this.WIDTH)}position(e,t){if(this.initialized){var n=mt(this.workspace,e),r=this.SMALL_SPACING+2*this.HEIGHT;if(this.zoomResetControl&&(r+=this.LARGE_SPACING+this.HEIGHT),e=pt(n,new V(this.WIDTH,r),this.MARGIN_HORIZONTAL,this.MARGIN_VERTICAL,e,this.workspace),n=n.vertical,t=ht(e,this.MARGIN_VERTICAL,n===Xs.TOP?ec.DOWN:ec.UP,t),n===Xs.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+`)`)}}getControlWithId(e){for(let t of[this.zoomInControl,this.zoomOutControl,this.zoomResetControl])if(t?.getId()===e)return t}};He(`
638
+ .blocklyZoom>image, .blocklyZoom>svg>image {
639
+ opacity: .4;
640
+ }
641
+
642
+ .blocklyZoom>image:hover, .blocklyZoom>svg>image:hover, .blocklyZoom:focus>image {
643
+ opacity: .8;
644
+ }
645
+
646
+ .blocklyZoom>image:active, .blocklyZoom>svg>image:active {
647
+ opacity: 1;
648
+ }
649
+ `);var lc={};lc.register=gt,lc.unregister=function(e){n(M.SERIALIZER,e)};var uc=class{constructor(){this.priority=25}save(e){var t=[];for(let n of e.getTopComments())(e=_t(n,{addCoordinates:!0,saveIds:!0}))&&t.push(e);return t.length?t:null}load(t,n){for(let r of t)vt(r,n,{recordUndo:e.Pc})}clear(e){for(let t of e.getTopComments())t.dispose()}};gt(`workspaceComments`,new uc);var dc={};dc.WorkspaceCommentSerializer=uc,dc.append=vt,dc.save=_t;var fc={};fc.register=yt,fc.unregister=function(e){n(M.PASTER,e)};var pc=class{paste(t,n,r){t=t.commentState,r&&(t.x=r.x,t.y=r.y),e.Ka++;try{var i=vt(t,n);bt(i)}finally{e.Ka--}return i?(oe()&&b(new(x(N.COMMENT_CREATE))(i)),e.A().focusNode(i),i):null}};pc.TYPE=`workspace-comment`,yt(pc.TYPE,new pc),e.tg={dragRadius:5,flyoutDragRadius:10,snapRadius:28,connectingSnapRadius:28,currentConnectionPreference:8,bumpDelay:250};var mc=class{constructor(e,t,n){this.content=e,this.opt_value=t,this.ariaLabel=n,this.enabled=!0,this.element=null,this.rightToLeft=!1,this.roleName=null,this.highlight=this.checked=this.checkable=!1,this.actionHandler=null,this.id=y()}createDom(){var e=document.createElement(`div`);e.id=this.getId(),this.element=e,e.className=`blocklyMenuItem `+(this.enabled?``:`blocklyMenuItemDisabled `)+(this.checked?`blocklyMenuItemSelected `:``)+(this.highlight?`blocklyMenuItemHighlight `:``)+(this.rightToLeft?`blocklyMenuItemRtl `:``);var t=document.createElement(`div`);C(e,F.LABEL,this.getAriaLabel()),S(t,P.PRESENTATION),t.className=`blocklyMenuItemContent`;var n=this.content;return typeof this.content==`string`&&(n=document.createTextNode(this.content)),t.appendChild(n),e.appendChild(t),this.checkable&&this.toggleHasCheckbox(!0),this.roleName&&S(e,this.roleName),C(e,F.SELECTED,this.checkable&&this.checked||!1),C(e,F.DISABLED,!this.enabled),e}getAriaLabel(){return this.ariaLabel||(typeof this.content==`string`?this.content:this.content.textContent)}dispose(){this.element=null}getElement(){return this.element}getId(){return this.id}getValue(){return this.opt_value??null}setRightToLeft(e){this.rightToLeft=e;var t;(t=this.getElement())==null||t.classList.toggle(`blocklyMenuItemRtl`,this.rightToLeft)}setRole(e){this.roleName=e}setCheckable(e){(this.checkable=e)||this.setChecked(!1),this.toggleHasCheckbox(e)}setChecked(e){(!e||this.checkable)&&(this.checked=e,(e=this.getElement())&&(e.classList.toggle(`blocklyMenuItemSelected`,this.checked),C(e,F.SELECTED,this.checked)))}setHighlighted(e){if(this.highlight=e,this.isEnabled()){let e;(e=this.getElement())==null||e.classList.toggle(`blocklyMenuItemHighlight`,this.highlight)}}isEnabled(){return this.enabled}setEnabled(e){this.enabled=e,(e=this.getElement())&&(e.classList.toggle(`blocklyMenuItemDisabled`,!this.enabled),C(e,F.DISABLED,!this.enabled))}performAction(e){this.isEnabled()&&this.actionHandler&&this.actionHandler(this,e)}onAction(e,t){this.actionHandler=e.bind(t)}toggleHasCheckbox(e){if(e){let r;if((r=this.getElement())==null||!r.querySelector(`.blocklyMenuItemContent .blocklyMenuItemCheckbox`)){e=document.createElement(`div`),C(e,F.HIDDEN,!0),e.className=`blocklyMenuItemCheckbox `;var t,n;(t=this.getElement())==null||(n=t.querySelector(`.blocklyMenuItemContent`))==null||n.prepend(e)}}else{let e,t;(e=this.getElement())==null||(t=e.querySelector(`.blocklyMenuItemContent .blocklyMenuItemCheckbox`))==null||t.remove()}}},hc=class{constructor(){this.menuItems=[],this.roleName=this.element=this.onKeyDownHandler=this.pointerLeaveHandler=this.pointerEnterHandler=this.clickHandler=this.pointerMoveHandler=this.highlightedItem=this.openingCoords=null,this.id=y()}addChild(e){this.menuItems.push(e)}render(e){var t=document.createElement(`div`);t.className=`blocklyMenu`,t.tabIndex=0,t.id=this.getId(),this.roleName&&S(t,this.roleName),this.element=t;for(let e=0,n;n=this.menuItems[e];e++)t.appendChild(n.createDom());return this.pointerMoveHandler=p(t,`pointermove`,this,this.handlePointerMove,!0),this.clickHandler=p(t,`pointerup`,this,this.handleClick,!0),this.pointerEnterHandler=p(t,`pointerenter`,this,this.handlePointerEnter,!0),this.pointerLeaveHandler=p(t,`pointerleave`,this,this.handlePointerLeave,!0),this.onKeyDownHandler=p(t,`keydown`,this,this.handleKeyEvent),e.appendChild(t),t}getElement(){return this.element}focus(){var e=this.getElement();e&&e.focus({preventScroll:!0})}blur(){var e=this.getElement();e&&e.blur()}setRole(e){this.roleName=e}dispose(){this.pointerMoveHandler&&=(h(this.pointerMoveHandler),null),this.clickHandler&&=(h(this.clickHandler),null),this.pointerEnterHandler&&=(h(this.pointerEnterHandler),null),this.pointerLeaveHandler&&=(h(this.pointerLeaveHandler),null),this.onKeyDownHandler&&=(h(this.onKeyDownHandler),null);for(let e=0,t;t=this.menuItems[e];e++)t.dispose();this.element=null}getMenuItem(e){for(var t=this.getElement();e&&e!==t;){if(e.classList.contains(`blocklyMenuItem`)){let t=this.getMenuItems();for(let n=0,r;r=t[n];n++)if(r.getElement()===e)return r}e=e.parentElement}return null}setHighlighted(e){var t=this.highlightedItem;if(t&&(t.setHighlighted(!1),this.highlightedItem=null),e){e.setHighlighted(!0),this.highlightedItem=e,t=this.getElement();let n=e.getElement();t&&n&&(Xe(n,t),C(t,F.ACTIVEDESCENDANT,e.getId()))}}highlightNext(){var e=this.highlightedItem?this.getMenuItems().indexOf(this.highlightedItem):-1;this.highlightHelper(e,1)}highlightPrevious(){var e=this.highlightedItem?this.getMenuItems().indexOf(this.highlightedItem):-1;this.highlightHelper(e<0?this.menuItems.length:e,-1)}highlightFirst(){this.highlightHelper(-1,1)}highlightLast(){this.highlightHelper(this.menuItems.length,-1)}highlightHelper(e,t){e+=t;for(var n,r=this.getMenuItems();n=r[e];){if(n.isEnabled()){this.setHighlighted(n);break}e+=t}}handlePointerMove(e){Math.max(Math.abs(e.movementX),Math.abs(e.movementY))!==0&&(e=this.getMenuItem(e.target))&&(e.isEnabled()?this.highlightedItem!==e&&this.setHighlighted(e):this.setHighlighted(null))}handleClick(e){var t=this.openingCoords;if(this.openingCoords=null,t&&typeof e.clientX==`number`){let n=new z(e.clientX,e.clientY);if(z.distance(t,n)<1)return}(t=this.getMenuItem(e.target))&&t.performAction(e)}handlePointerEnter(){this.focus()}handlePointerLeave(){this.getElement()&&this.setHighlighted(null)}handleKeyEvent(e){if(this.menuItems.length&&!(e.shiftKey||e.ctrlKey||e.metaKey||e.altKey)){var t=this.highlightedItem;switch(e.key){case`Enter`:case` `:t&&t.performAction(e);break;case`ArrowUp`:this.highlightPrevious();break;case`ArrowDown`:this.highlightNext();break;case`PageUp`:case`Home`:this.highlightFirst();break;case`PageDown`:case`End`:this.highlightLast();break;default:return}e.preventDefault(),e.stopPropagation()}}getSize(){var e=this.getElement(),t=Ge(e);return t.height=e.scrollHeight,t}getMenuItems(){return this.menuItems.filter(e=>e instanceof mc)}getId(){return this.id}},gc=class{constructor(){this.element=null}createDom(){return this.element=document.createElement(`hr`),this.element.className=`blocklyMenuSeparator`,S(this.element,P.SEPARATOR),this.element}dispose(){var e;(e=this.element)==null||e.remove(),this.element=null}},_c=e.he||={};_c[_c.VALUE=1]=`VALUE`,_c[_c.STATEMENT=3]=`STATEMENT`,_c[_c.DUMMY=5]=`DUMMY`,_c[_c.CUSTOM=6]=`CUSTOM`,_c[_c.END_ROW=7]=`END_ROW`;var vc=new Set,yc=new WeakSet,bc=new WeakMap,xc=null,Sc=null,Cc=0,wc={};wc.finishQueuedRenders=wt,wc.queueRender=Ct,wc.triggerQueuedRenders=Tt;var Tc=class{static show(e,t){if(t.oncePerSession&&t.id){if(this.shownIds.has(t.id))return;this.shownIds.add(t.id)}this.hide(e);var n=this.createDom(e,t);requestAnimationFrame(()=>{n.style.bottom=`2rem`})}static createDom(t,n){var{message:r,duration:i=5,assertiveness:a=Vo.POLITE}=n,o=document.createElement(`div`);t.getInjectionDiv().appendChild(o),o.dataset.toastId=n.id,o.className=`blocklyToast`,n=o.appendChild(document.createElement(`div`)),n.className=`blocklyToastMessage`,n.innerText=r,n=o.appendChild(document.createElement(`button`)),n.className=`blocklyToastCloseButton`,C(n,F.LABEL,e.C.CLOSE);var s=w(I.SVG,{width:24,height:24,viewBox:`0 0 24 24`,fill:`none`},n);C(s,F.HIDDEN,!0),w(I.RECT,{x:19.7782,y:2.80762,width:2,height:24,transform:`rotate(45, 19.7782, 2.80762)`,fill:`black`},s),w(I.RECT,{x:2.80762,y:4.22183,width:2,height:24,transform:`rotate(-45, 2.80762, 4.22183)`,fill:`black`},s),n.addEventListener(`click`,()=>{o.remove(),t.markFocused()});var c;return n=()=>{c=setTimeout(()=>o.remove(),i*1e3)},s=()=>clearTimeout(c),o.addEventListener(`focusin`,s),o.addEventListener(`focusout`,n),o.addEventListener(`mouseenter`,s),o.addEventListener(`mousemove`,s),o.addEventListener(`mouseleave`,n),n(),fe(r,{assertiveness:a,role:P.STATUS}),o}static hide(e,t){e=e.getInjectionDiv().querySelector(`.blocklyToast`),e instanceof HTMLElement&&(!t||t===e.dataset.toastId)&&e.remove()}};Tc.shownIds=new Set,He(`
650
+ .blocklyToast {
651
+ font-size: 1.2rem;
652
+ position: absolute;
653
+ bottom: -10rem;
654
+ right: 2rem;
655
+ padding: 1rem;
656
+ color: black;
657
+ background-color: white;
658
+ border: 2px solid black;
659
+ border-radius: 0.4rem;
660
+ z-index: 999;
661
+ display: flex;
662
+ align-items: center;
663
+ gap: 0.8rem;
664
+ line-height: 1.5;
665
+ transition: bottom 0.3s ease-out;
666
+ }
667
+
668
+ .blocklyToast .blocklyToastMessage {
669
+ maxWidth: 18rem;
670
+ }
671
+
672
+ .blocklyToast .blocklyToastCloseButton {
673
+ margin: 0;
674
+ padding: 0.2rem;
675
+ background-color: transparent;
676
+ color: black;
677
+ border: none;
678
+ cursor: pointer;
679
+ }
680
+ `);var Ec,Dc=Ec||={};Dc[Dc.ALERT=1]=`ALERT`,Dc[Dc.CONFIRM=2]=`CONFIRM`,Dc[Dc.PROMPT=3]=`PROMPT`;var Oc=0,kc=jt,Ac=Mt,jc=Nt,Mc=Tc.show.bind(Tc),Nc=Mc,Pc={};Pc.alert=Pt,Pc.confirm=Ft,Pc.prompt=It,Pc.setAlert=function(e=jt){kc=e},Pc.setConfirm=function(e=Mt){Ac=e},Pc.setPrompt=function(e=Nt){jc=e},Pc.setToast=function(e=Mc){Nc=e},Pc.toast=function(e,t){Nc(e,t)};var Fc=class extends ys{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=ys.fromJson(e,t,n??new Fc),t.blockId=e.blockId,t}},Ic=class{constructor(e){this.name=e}toString(){return this.name}equals(e){return this.name===e.toString()}};Ic.MUTATOR=new Ic(`mutator`),Ic.WARNING=new Ic(`warning`),Ic.COMMENT=new Ic(`comment`);var Lc=class extends Fc{constructor(e,t,n,r,i){super(e),this.type=N.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=Fc.fromJson(e,t,n??new Lc),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(Ic.MUTATOR);switch(r&&Rt(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=Lc.getExtraBlockState_(n),n.loadExtraState?n.loadExtraState(JSON.parse(t||`{}`)):n.domToMutation&&n.domToMutation(e.tc(t||`<mutation/>`)),b(new Lc(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())?jr(e):``}};t(M.EVENT,N.BLOCK_CHANGE,Lc);var Rc=class extends Fc{constructor(e){super(e),this.type=N.BLOCK_CREATE,e&&(e.isShadow()&&(this.recordUndo=!1),this.ids=se(e),this.json=an(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=Fc.fromJson(e,t,n??new Rc),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(!zt(t,this.ids))if(e)sn(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)}}};t(M.EVENT,N.BLOCK_CREATE,Rc);var zc=class extends Fc{constructor(e){if(super(e),this.type=N.BLOCK_DELETE,e){if(e.getParent())throw Error(`Connected blocks cannot be deleted.`);e.isShadow()&&(this.recordUndo=!1),this.ids=se(e),this.wasShadow=e.isShadow(),this.oldJson=an(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=Fc.fromJson(e,t,n??new zc),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 sn(this.oldJson,t)}};t(M.EVENT,N.BLOCK_DELETE,zc);var Bc=class extends bs{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=N.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=bs.fromJson(e,t,n??new Bc),t.isStart=e.isStart,t.blockId=e.blockId,t.blocks=e.blocks,t}};t(M.EVENT,N.BLOCK_DRAG,Bc);var Vc=class extends Fc{constructor(e,t,n,r){super(e),this.type=N.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=Fc.fromJson(e,t,n??new Vc),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)}};t(M.EVENT,N.BLOCK_FIELD_INTERMEDIATE_CHANGE,Vc);var U,Hc=U||={};Hc[Hc.INPUT_VALUE=1]=`INPUT_VALUE`,Hc[Hc.OUTPUT_VALUE=2]=`OUTPUT_VALUE`,Hc[Hc.NEXT_STATEMENT=3]=`NEXT_STATEMENT`,Hc[Hc.PREVIOUS_STATEMENT=4]=`PREVIOUS_STATEMENT`;var Uc=class extends Fc{constructor(e){super(e),this.type=N.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=Fc.fromJson(e,t,n??new Uc),t.oldParentId=e.oldParentId,t.oldInputName=e.oldInputName,e.oldCoordinate&&(n=e.oldCoordinate.split(`,`),t.oldCoordinate=new z(Number(n[0]),Number(n[1]))),t.newParentId=e.newParentId,t.newInputName=e.newInputName,e.newCoordinate&&(n=e.newCoordinate.split(`,`),t.newCoordinate=new z(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&&z.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;n=t?.type,i?(n=a.getInput(i))&&(e=n.connection):n===U.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)}};t(M.EVENT,N.BLOCK_MOVE,Uc);var Wc=class extends bs{constructor(e,t,n){super(e?e.workspace.id:void 0),this.type=N.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=bs.fromJson(e,t,n??new Wc),t.isOpen=e.isOpen,t.bubbleType=e.bubbleType,t.blockId=e.blockId,t}},Gc,Kc=Gc||={};Kc.MUTATOR=`mutator`,Kc.COMMENT=`comment`,Kc.WARNING=`warning`,t(M.EVENT,N.BUBBLE_OPEN,Wc);var qc=class extends ys{constructor(t){super(),this.isBlank=!0,this.isBlank=!t,t&&(this.commentId=t.id,this.workspaceId=t.workspace.id,this.group=e.fd,this.recordUndo=e.Pc)}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=ys.fromJson(e,t,n??new qc),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`);vt(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)}}},Jc=class extends qc{constructor(e,t,n){super(e),this.type=N.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=qc.fromJson(e,t,n??new Jc),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)}};t(M.EVENT,N.COMMENT_CHANGE,Jc);var Yc=class extends qc{constructor(e,t){super(e),this.newCollapsed=t,this.type=N.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=qc.fromJson(e,t,n??new Yc),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)}};t(M.EVENT,N.COMMENT_COLLAPSE,Yc);var Xc=class extends qc{constructor(e){super(e),this.type=N.COMMENT_CREATE,e&&(this.json=_t(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=qc.fromJson(e,t,n??new Xc),t.json=e.json,t}run(e){qc.CommentCreateDeleteHelper(this,e)}};t(M.EVENT,N.COMMENT_CREATE,Xc);var Zc=class extends qc{constructor(e){super(e),this.type=N.COMMENT_DELETE,e&&(this.json=_t(e,{addCoordinates:!0}))}run(e){qc.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=qc.fromJson(e,t,n??new Zc),t.json=e.json,t}};t(M.EVENT,N.COMMENT_DELETE,Zc);var Qc=class extends bs{constructor(e,t){super(e?e.workspace.id:void 0),this.type=N.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=bs.fromJson(e,t,n??new Qc),t.isStart=e.isStart,t.commentId=e.commentId,t}};t(M.EVENT,N.COMMENT_DRAG,Qc);var $c=class extends qc{constructor(e){super(e),this.type=N.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=qc.fromJson(e,t,n??new $c),n=e.oldCoordinate.split(`,`),t.oldCoordinate_=new z(Number(n[0]),Number(n[1])),n=e.newCoordinate.split(`,`),t.newCoordinate_=new z(Number(n[0]),Number(n[1])),t}isNull(){return z.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)}};t(M.EVENT,N.COMMENT_MOVE,$c);var el=class extends qc{constructor(e){super(e),this.type=N.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=qc.fromJson(e,t,n??new el),t.oldSize=new V(e.oldWidth,e.oldHeight),t.newSize=new V(e.newWidth,e.newHeight),t}isNull(){return V.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)}};t(M.EVENT,N.COMMENT_RESIZE,el);var tl=class extends bs{constructor(e,t,n){super(n),this.type=N.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=bs.fromJson(e,t,n??new tl),t.oldElementId=e.oldElementId,t.newElementId=e.newElementId,t}};t(M.EVENT,N.SELECTED,tl);var nl=class extends bs{constructor(e,t){super(t),this.type=N.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=bs.fromJson(e,t,n??new nl),t.themeName=e.themeName,t}};t(M.EVENT,N.THEME_CHANGE,nl);var rl=class extends bs{constructor(e,t,n){super(n),this.type=N.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=bs.fromJson(e,t,n??new rl),t.oldItem=e.oldItem,t.newItem=e.newItem,t}};t(M.EVENT,N.TOOLBOX_ITEM_SELECT,rl);var il=class extends bs{constructor(e,t){super(t),this.type=N.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=bs.fromJson(e,t,n??new il),t.isOpen=e.isOpen,t}};t(M.EVENT,N.TRASHCAN_OPEN,il);var al=class extends ys{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=ys.fromJson(e,t,n??new al),t.varId=e.varId,t}},ol=class extends al{constructor(e){super(e),this.type=N.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=al.fromJson(e,t,n??new ol),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)}};t(M.EVENT,N.VAR_CREATE,ol);var sl=class extends al{constructor(e){super(e),this.type=N.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=al.fromJson(e,t,n??new sl),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)}};t(M.EVENT,N.VAR_DELETE,sl);var cl=class extends al{constructor(e,t){super(e),this.type=N.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=al.fromJson(e,t,n??new cl),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)}};t(M.EVENT,N.VAR_RENAME,cl);var ll=class extends al{constructor(e,t,n){super(e),this.oldType=t,this.newType=n,this.type=N.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=al.fromJson(e,t,n??new ll),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))}};t(M.EVENT,N.VAR_TYPE_CHANGE,ll);var ul=class extends bs{constructor(e,t,n,r,i){super(r),this.type=N.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=bs.fromJson(e,t,n??new ul),t.viewTop=e.viewTop,t.viewLeft=e.viewLeft,t.scale=e.scale,t.oldScale=e.oldScale,t}};t(M.EVENT,N.VIEWPORT_CHANGE,ul);var dl=class extends ys{constructor(e){super(),this.isBlank=!0,this.recordUndo=!1,this.type=N.FINISHED_LOADING,this.isBlank=!!e,e&&(this.workspaceId=e.id)}};t(M.EVENT,N.FINISHED_LOADING,dl);var fl,pl,ml,hl,gl,_l,vl,yl,bl,xl,Sl,Cl,wl,Tl,El,Dl,Ol,kl,Al,jl,Ml,Nl,Pl,Fl,W;e.am=N.BLOCK_CHANGE,e.Nd=N.BLOCK_CREATE,e.bm=N.BLOCK_DELETE,fl=N.BLOCK_DRAG,e.dm=N.BLOCK_MOVE,pl=N.BLOCK_FIELD_INTERMEDIATE_CHANGE,ml=N.BUBBLE_OPEN,hl=N.BLOCK_CHANGE,gl=N.CLICK,_l=N.COMMENT_CHANGE,vl=N.COMMENT_CREATE,yl=N.COMMENT_DELETE,bl=N.COMMENT_MOVE,xl=N.COMMENT_RESIZE,Sl=N.COMMENT_DRAG,Cl=N.BLOCK_CREATE,wl=N.BLOCK_DELETE,Tl=N.FINISHED_LOADING,El=N.BLOCK_MOVE,Dl=N.SELECTED,Ol=N.THEME_CHANGE,kl=N.TOOLBOX_ITEM_SELECT,Al=N.TRASHCAN_OPEN,jl=N.UI,Ml=N.VAR_CREATE,Nl=N.VAR_DELETE,Pl=N.VAR_RENAME,Fl=N.VIEWPORT_CHANGE,W={},W.Abstract=ys,W.BLOCK_CHANGE=e.am,W.BLOCK_CREATE=e.Nd,W.BLOCK_DELETE=e.bm,W.BLOCK_DRAG=fl,W.BLOCK_FIELD_INTERMEDIATE_CHANGE=pl,W.BLOCK_MOVE=e.dm,W.BUBBLE_OPEN=ml,W.BUMP_EVENTS=Fo,W.BlockBase=Fc,W.BlockChange=Lc,W.BlockCreate=Rc,W.BlockDelete=zc,W.BlockDrag=Bc,W.BlockFieldIntermediateChange=Vc,W.BlockMove=Uc,W.BubbleOpen=Wc,W.BubbleType=Gc,W.CHANGE=hl,W.CLICK=gl,W.COMMENT_CHANGE=_l,W.COMMENT_CREATE=vl,W.COMMENT_DELETE=yl,W.COMMENT_DRAG=Sl,W.COMMENT_MOVE=bl,W.COMMENT_RESIZE=xl,W.CREATE=Cl,W.Click=xs,W.ClickTarget=Ss,W.CommentBase=qc,W.CommentChange=Jc,W.CommentCollapse=Yc,W.CommentCreate=Xc,W.CommentDelete=Zc,W.CommentDrag=Qc,W.CommentMove=$c,W.CommentResize=el,W.DELETE=wl,W.FINISHED_LOADING=Tl,W.FinishedLoading=dl,W.MOVE=El,W.SELECTED=Dl,W.Selected=tl,W.THEME_CHANGE=Ol,W.TOOLBOX_ITEM_SELECT=kl,W.TRASHCAN_OPEN=Al,W.ThemeChange=nl,W.ToolboxItemSelect=rl,W.TrashcanOpen=il,W.UI=jl,W.UiBase=bs,W.VAR_CREATE=Ml,W.VAR_DELETE=Nl,W.VAR_RENAME=Pl,W.VIEWPORT_CHANGE=Fl,W.VarBase=al,W.VarCreate=ol,W.VarDelete=sl,W.VarRename=cl,W.VarTypeChange=ll,W.ViewportChange=ul,W.clearPendingUndo=ae,W.disable=function(){e.Ka++},W.disableOrphans=function(t){if((t.type===N.BLOCK_MOVE||t.type===N.BLOCK_CREATE)&&t.workspaceId){var n=Ee(t.workspaceId);if(!t.blockId)throw Error(`Encountered a blockEvent without a proper blockId`);if(t=n.getBlockById(t.blockId)){let r=e.Pc;try{e.Pc=!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.Pc=r}}}},W.enable=function(){e.Ka--},W.filter=ie,W.fire=b,W.fromJson=function(e,t){var n=x(e.type);if(!n)throw Error(`Unknown event type.`);return n.fromJson(e,t)},W.get=x,W.getDescendantIds=se,W.getGroup=function(){return e.fd},W.getRecordUndo=function(){return e.Pc},W.isEnabled=oe,W.setGroup=e.r,W.setRecordUndo=function(t){e.Pc=t};var Il=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=ms.getInjectionDiv().parentElement;this.isActive?e?.classList.add(this.activeClassName):e?.classList.remove(this.activeClassName)}},Ll=new Il,Rl={generateUniqueNameInternal:function(e){return Kt(`i`,e.getVariableMap().getAllVariables().map(e=>e.getName()))}},zl={CATEGORY_NAME:`VARIABLE`,TEST_ONLY:Rl,VAR_LETTER_OPTIONS:`ijkmnopqrstuvwxyzabcdefgh`};zl.allDeveloperVariables=e.Bd,zl.allUsedVarModels=e.Ad,zl.compareByName=nn,zl.createVariableButtonHandler=qt,zl.deleteVariable=e.Yd,zl.flyoutCategory=Ht,zl.flyoutCategoryBlocks=function(t){t=t.getVariableMap().getVariablesOfType(``);var n=[];if(t.length>0){var r=t[t.length-1];if(so.variables_set){var i=e.F(`block`);i.setAttribute(`type`,`variables_set`),i.setAttribute(`gap`,so.math_change?`8`:`24`),i.appendChild(en(r)),n.push(i)}if(so.math_change&&(i=e.F(`block`),i.setAttribute(`type`,`math_change`),i.setAttribute(`gap`,so.variables_get?`20`:`8`),i.appendChild(en(r)),r=e.tc(`<value name="DELTA"><shadow type="math_number"><field name="NUM">1</field></shadow></value>`),i.appendChild(r),n.push(i)),so.variables_get){t.sort(nn);for(let i=0,a;a=t[i];i++)r=e.F(`block`),r.setAttribute(`type`,`variables_get`),r.setAttribute(`gap`,`8`),r.appendChild(en(a)),n.push(r)}}return n},zl.generateUniqueName=Gt,zl.generateUniqueNameFromOptions=Kt,zl.generateVariableFieldDom=en,zl.getAddedVariables=tn,zl.getOrCreateVariablePackage=e.Vd,zl.getVariable=e.Ud,zl.getVariableUsesById=rn,zl.jsonFlyoutCategoryBlocks=Wt,zl.nameUsedWithAnyType=Xt,zl.nameUsedWithConflictingParam=Zt,zl.promptName=Jt,zl.renameVariable=e.Qd;var Bl=class extends Error{},Vl=class extends Bl{constructor(e){super(`Expected to find a 'type' property, defining the block type`),this.state=e}},Hl=class extends Bl{constructor(e,t,n){super(`The block ${t.toDevString()} is missing a(n) ${e}
681
+ connection`),this.block=t,this.state=n}},Ul=class extends Bl{constructor(e,t,n,r){super(`The block ${n.toDevString()} could not connect its
682
+ ${t} to its parent, because: ${e}`),this.childBlock=n,this.childState=r}},Wl=class extends Bl{constructor(e){super(`Encountered a real block which is defined as a child of a shadow
683
+ block. It is an invariant of Blockly that shadow blocks only have shadow
684
+ children`),this.state=e}},Gl=class extends Bl{constructor(e,t,n){super(`Cannot add an icon of type '${e}' to the block ${t.toDevString()}, because there is no icon registered with type '${e}'. Make sure that all of your icons have been registered.`),this.block=t,this.state=n}},Kl={};Kl.BadConnectionCheck=Ul,Kl.DeserializationError=Bl,Kl.MissingBlockType=Vl,Kl.MissingConnection=Hl,Kl.RealChildOfShadow=Wl,Kl.UnregisteredIcon=Gl;var ql=class{constructor(){this.priority=50}save(e){var t=[];for(let n of e.getTopBlocks(!1))(e=an(n,{addCoordinates:!0,doFullSerialization:!1}))&&t.push(e);return t.length?{languageVersion:0,blocks:t}:null}load(t,n){t=t.blocks;for(let r of t)sn(r,n,{recordUndo:e.Pc})}clear(e){for(let t of e.getTopBlocks(!1))t.dispose(!1)}};gt(`blocks`,new ql);var Jl={};Jl.BlockSerializer=ql,Jl.append=sn,Jl.appendInternal=cn,Jl.save=an;var Yl={Control:e.C.CONTROL_KEY,Meta:`⌘`,Alt:jo?`⌥`:e.C.ALT_KEY},Xl=[`Meta`,`Control`,`Alt`,`Shift`],Zl={};Zl.clamp=gn,Zl.toDegrees=function(e){return e*180/Math.PI},Zl.toRadians=hn;var Ql=null,$l=null,eu=``,tu=``,nu,ru,iu,au=null,ou=null,su=null,cu=null,lu=null,uu={getBoundsInfo:function(){var e=qe(au),t=Ge(au);return{left:e.x,right:e.x+t.width,top:e.y,bottom:e.y+t.height,width:t.width,height:t.height}},getPositionMetrics:function(e,t,n,r){var i=uu.getBoundsInfo(),a=Ge(nu);return t+a.height<i.bottom?En(e,t,i,a):r-a.height>i.top?Dn(n,r,i,a):t+a.height<document.documentElement.clientHeight?En(e,t,i,a):r-a.height>document.documentElement.clientTop?Dn(n,r,i,a):(e=On(e,i.left,i.right,a.width),{initialX:e.divX,initialY:0,finalX:e.divX,finalY:0,arrowAtTop:null,arrowX:null,arrowY:null,arrowVisible:!1})}},du={ANIMATION_TIME:.25,ARROW_HORIZONTAL_PADDING:12,ARROW_SIZE:16,BORDER_SIZE:1,PADDING_Y:16,TEST_ONLY:uu};du.clearContent=yn,du.createDom=_n,du.getContentDiv=function(){return ru},du.getOwner=function(){return ou},du.getPositionX=On,du.hide=An,du.hideIfOwner=kn,du.hideWithoutAnimation=jn,du.isVisible=function(){return!!ou},du.repositionForWindowResize=Nn,du.setBoundsElement=function(e){au=e},du.setColour=bn,du.show=Tn,du.showPositionedByBlock=function(e,t,n,r,i=!0){return wn(Sn(t),e,i,n,r)},du.showPositionedByField=xn;var fu={};fu.commonWordPrefix=Fn,fu.commonWordSuffix=In,fu.isNumber=e.df,fu.shortestStringLength=Pn,fu.wrap=e.cf;var pu=void 0,mu=!1,hu=!1,gu=0,_u=0,vu=0,yu=0,bu=null,xu=null,Su=null,Cu={HOVER_MS:750,LIMIT:50,MARGINS:5,OFFSET_X:0,OFFSET_Y:10,RADIUS_OK:10};Cu.bindMouseEvents=Hn,Cu.block=Xn,Cu.createDom=Vn,Cu.display=Yn,Cu.dispose=qn,Cu.getCustomTooltip=function(){return pu},Cu.getDiv=function(){return Su},Cu.getTooltipOfObject=zn,Cu.hide=Jn,Cu.isVisible=function(){return mu},Cu.setCustomTooltip=function(e){pu=e},Cu.unbindMouseEvents=Un,Cu.unblock=function(){hu=!1};var wu=.45,Tu=.65,Eu={aqua:`#00ffff`,black:`#000000`,blue:`#0000ff`,fuchsia:`#ff00ff`,gray:`#808080`,green:`#008000`,lime:`#00ff00`,maroon:`#800000`,navy:`#000080`,olive:`#808000`,purple:`#800080`,red:`#ff0000`,silver:`#c0c0c0`,teal:`#008080`,white:`#ffffff`,yellow:`#ffff00`},Du={};Du.blend=nr,Du.getHsvSaturation=function(){return wu},Du.getHsvValue=function(){return Tu},Du.hexToRgb=er,Du.hsvToHex=tr,Du.hueToHex=rr,Du.names=Eu,Du.parse=Qn,Du.rgbToHex=$n,Du.setHsvSaturation=function(e){wu=e},Du.setHsvValue=function(e){Tu=e};var Ou={checkMessageReferences:function(t){var n=!0,r=t.match(/%{BKY_[A-Z]\w*}/gi);if(r)for(let i=0;i<r.length;i++){let a=r[i].toUpperCase();e.C[a.slice(6,-1)]===void 0&&(console.warn(`No message string for `+r[i]+` in `+t),n=!1)}return n}};Ou.parseBlockColour=or,Ou.replaceMessageReferences=O,Ou.tokenizeInterpolation=ar;var ku=class{get size_(){return this.size}set size_(e){this.size=e}constructor(e,t,n){this.DEFAULT_VALUE=null,this.name=void 0,this.tooltip=this.ariaTypeName=this.validator_=null,this.size=new V(0,0),this.constants_=this.mouseDownWrapper=this.textContent_=this.textElement_=this.borderRect_=this.fieldGroup_=null,this.disposed=!1,this.maxDisplayLength=50,this.sourceBlock_=null,this.enabled_=this.visible_=this.isDirty_=!0,this.suffixField=this.prefixField=this.clickTarget_=null,this.EDITABLE=!0,this.SERIALIZABLE=!1,this.id_=null,this.value_=`DEFAULT_VALUE`in new.target.prototype?new.target.prototype.DEFAULT_VALUE:this.DEFAULT_VALUE,this.size_=new V(0,0),e!==ku.SKIP_SETUP&&(n&&this.configure_(n),this.setValue(e),t&&this.setValidator(t))}configure_(e){e.tooltip&&this.setTooltip(O(e.tooltip)),e.ariaTypeName&&(this.ariaTypeName=e.ariaTypeName)}setSourceBlock(e){if(this.sourceBlock_)throw Error(`Field already bound to a block`);if(this.sourceBlock_=e,e.id.includes(`_field`))throw Error(`Field ID indicator is contained in block ID. This may cause problems with focus: ${e.id}.`)}getConstants(){return!this.constants_&&this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()&&this.sourceBlock_.workspace.rendered&&(this.constants_=this.sourceBlock_.workspace.getRenderer().getConstants()),this.constants_}getSourceBlock(){return this.sourceBlock_}getAriaTypeName(){return this.ariaTypeName||null}getAriaValue(){return this.getValue()==null?null:this.getText()}computeAriaLabel(t=!0){t=t?this.getAriaTypeName():null;var n=this.getAriaValue();return(n===null||n===``)&&(n=e.C.FIELD_LABEL_EMPTY),t?`${t}: ${n}`:n}init(){if(!this.fieldGroup_){this.fieldGroup_=w(I.G,{}),this.isVisible()||(this.fieldGroup_.style.display=`none`);var e=this.sourceBlock_;e.getSvgRoot().appendChild(this.fieldGroup_),this.initView(),this.updateEditable(),this.setTooltip(this.tooltip),this.bindEvents_(),this.initModel(),this.applyColour(),this.isFullBlockField()?this.id_=y():this.id_=`${e.id}_field_${y()}`,this.fieldGroup_.setAttribute(`id`,this.id_)}}initView(){this.createBorderRect_(),this.createTextElement_(),this.fieldGroup_&&T(this.fieldGroup_,`blocklyField`)}initModel(){}isFullBlockField(){return!1}createBorderRect_(){this.borderRect_=w(I.RECT,{rx:this.getConstants().FIELD_BORDER_RECT_RADIUS,ry:this.getConstants().FIELD_BORDER_RECT_RADIUS,x:0,y:0,height:this.size_.height,width:this.size_.width,class:`blocklyFieldRect`},this.fieldGroup_)}createTextElement_(){this.textElement_=w(I.TEXT,{class:`blocklyText blocklyFieldText`,"aria-hidden":`true`},this.fieldGroup_),this.getConstants().FIELD_TEXT_BASELINE_CENTER&&this.textElement_.setAttribute(`dominant-baseline`,`central`),this.textContent_=document.createTextNode(``),this.textElement_.appendChild(this.textContent_)}bindEvents_(){var e=this.getClickTarget_();if(!e)throw Error(`A click target has not been set.`);Hn(e),this.mouseDownWrapper=p(e,`pointerdown`,this,this.onMouseDown_)}fromXml(e){this.setValue(e.textContent)}toXml(e){return e.textContent=this.getValue(),e}saveState(){var e=this.saveLegacyState(ku);return e===null?this.getValue():e}loadState(e){this.loadLegacyState(ku,e)||this.setValue(e)}saveLegacyState(t){return t.prototype.saveState===this.saveState&&t.prototype.toXml!==this.toXml?(t=e.F(`field`),t.setAttribute(`name`,this.name||``),it(this.toXml(t)).replace(` xmlns="https://developers.google.com/blockly/xml"`,``)):null}loadLegacyState(t,n){return t.prototype.loadState===this.loadState&&t.prototype.fromXml!==this.fromXml?(this.fromXml(e.tc(n)),!0):!1}dispose(){kn(this),dr(this);var e;(e=this.getSourceBlock())!=null&&e.isDeadOrDying()||D(this.fieldGroup_),this.disposed=!0}updateEditable(){var e=this.fieldGroup_,t=this.getSourceBlock();this.EDITABLE&&e&&t&&(this.enabled_&&t.isEditable()?(T(e,`blocklyEditableField`),E(e,`blocklyNonEditableField`)):(T(e,`blocklyNonEditableField`),E(e,`blocklyEditableField`)))}setEnabled(e){this.enabled_=e,this.updateEditable()}isEnabled(){return this.enabled_}isClickable(){return this.enabled_&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()&&this.showEditor_!==ku.prototype.showEditor_}isClickableInFlyout(e){return!e}isCurrentlyEditable(){return this.enabled_&&this.EDITABLE&&!!this.sourceBlock_&&this.sourceBlock_.isEditable()}isSerializable(){var e=!1;return this.name&&(this.SERIALIZABLE?e=!0:this.EDITABLE&&(console.warn(`Detected an editable field that was not serializable. Please define SERIALIZABLE property as true on all editable custom fields. Proceeding with serialization.`),e=!0)),e}isVisible(){return this.visible_}setVisible(e){if(this.visible_!==e){this.visible_=e;var t=this.fieldGroup_;t&&(t.style.display=e?`block`:`none`)}}setValidator(e){this.validator_=e}getValidator(){return this.validator_}getSvgRoot(){return this.fieldGroup_}getBorderRect(){if(!this.borderRect_)throw Error(`The border rectangle is ${this.borderRect_}.`);return this.borderRect_}getTextElement(){if(!this.textElement_)throw Error(`The text element is ${this.textElement_}.`);return this.textElement_}getTextContent(){if(!this.textContent_)throw Error(`The text content is ${this.textContent_}.`);return this.textContent_}applyColour(){}render_(){this.textContent_&&(this.textContent_.nodeValue=this.getDisplayText_()),this.updateSize_()}showEditor(e){this.isClickable()&&this.showEditor_(e)}showEditor_(){}repositionForWindowResize(){return!1}updateSize_(e){var t=this.getConstants();e=e===void 0?this.borderRect_?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0:e;var n=e*2,r=t.FIELD_TEXT_HEIGHT,i=0;this.textElement_&&(i=ye(this.textElement_),n+=i),this.borderRect_&&(r=Math.max(r,t.FIELD_BORDER_RECT_HEIGHT)),this.size_=new V(n,r),this.positionTextElement_(e,i),this.positionBorderRect_()}positionTextElement_(e,t){if(this.textElement_){var n=this.getConstants(),r=this.size_.height/2,i;this.textElement_.setAttribute(`x`,String((i=this.getSourceBlock())!=null&&i.RTL?this.size_.width-t-e:e)),this.textElement_.setAttribute(`y`,String(n.FIELD_TEXT_BASELINE_CENTER?r:r-n.FIELD_TEXT_HEIGHT/2+n.FIELD_TEXT_BASELINE))}}positionBorderRect_(){this.borderRect_&&(this.borderRect_.setAttribute(`width`,String(this.size_.width)),this.borderRect_.setAttribute(`height`,String(this.size_.height)),this.borderRect_.setAttribute(`rx`,String(this.getConstants().FIELD_BORDER_RECT_RADIUS)),this.borderRect_.setAttribute(`ry`,String(this.getConstants().FIELD_BORDER_RECT_RADIUS)))}getSize(){return this.isVisible()?(this.isDirty_&&=(this.render_(),!1),this.size_):new V(0,0)}getScaledBBox(){var e=this.getSourceBlock();if(!e)throw new Au;if(this.borderRect_){var t=this.borderRect_.getBoundingClientRect(),n=qe(this.borderRect_);e=t.width,t=t.height}else{t=this.sourceBlock_.getHeightWidth();let r=e.workspace.scale;n=this.getAbsoluteXY_(),e=(t.width+1)*r,t=(t.height+1)*r,To?(n.x+=1.5*r,n.y+=1.5*r):(n.x-=.5*r,n.y-=.5*r)}return new B(n.y,n.y+t,n.x,n.x+e)}onLocationChange(){}getDisplayText_(){var e=this.getText();return e.length>this.maxDisplayLength&&(e=e.substring(0,this.maxDisplayLength-2)+`…`),e=e.replace(/\s/g,ku.NBSP),this.sourceBlock_&&this.sourceBlock_.RTL&&(e+=`‏`),e}getText(){var e=this.getText_();return String(e===null?this.getValue():e)}getText_(){return null}markDirty(){this.isDirty_=!0,this.constants_=null}forceRerender(){this.isDirty_=!0,this.sourceBlock_&&this.sourceBlock_.rendered&&this.sourceBlock_.queueRender()}setValue(t,n=!0){if(t!==null){var r=e.fd;r||e.r(!0);try{let e=this.doClassValidation_(t),r=this.processValidation(t,e,n);if(!(r instanceof Error)){var i=this.getValidator()?.call(this,r),a=this.processValidation(r,i,n);if(!(a instanceof Error)){var o=this.sourceBlock_;if(!o||!o.disposed){var s=this.getValue();s===a?this.doValueUpdate_(a):(this.doValueUpdate_(a),n&&o&&oe()&&b(new(x(N.BLOCK_CHANGE))(o,`field`,this.name||null,s,a)),this.isDirty_&&this.forceRerender())}}}}finally{e.r(r)}}}processValidation(e,t,n){return t===null?(this.doValueInvalid_(e,n),this.isDirty_&&this.forceRerender(),Error()):t===void 0?e:t}getValue(){return this.value_}doClassValidation_(e){return e??null}doValueUpdate_(e){this.value_=e,this.isDirty_=!0}doValueInvalid_(){}onMouseDown_(e){this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()&&(e=this.sourceBlock_.workspace.getGesture(e))&&e.setStartField(this)}setTooltip(e){e||e===``||(e=this.sourceBlock_);var t=this.getClickTarget_();t?t.tooltip=e:this.tooltip=e}getTooltip(){var e=this.getClickTarget_();return zn(e||{tooltip:this.tooltip})}getClickTarget_(){return this.clickTarget_||this.getSvgRoot()}getAbsoluteXY_(){return qe(this.getClickTarget_())}referencesVariables(){return!1}refreshVariableName(){}getParentInput(){var e=null,t=this.getSourceBlock();if(!t)throw new Au;var n=t.inputList;for(let r=0;r<t.inputList.length;r++){let t=n[r],i=t.fieldRow;for(let n=0;n<i.length;n++)if(i[n]===this){e=t;break}}return e}getFlipRtl(){return!1}onShortcut(){return!1}getFocusableElement(){if(!this.fieldGroup_)throw Error(`This field currently has no representative DOM element.`);return this.fieldGroup_}getFocusableTree(){var e=this.getSourceBlock();if(!e)throw new Au;return e.workspace}onNodeFocus(){var e=this.getSourceBlock();e.workspace.scrollBoundsIntoView(e.getBoundingRectangleWithoutChildren())}onNodeBlur(){}canBeFocused(){return!0}performAction(){this.showEditor()}recomputeAriaContext(){try{var t=this.getFocusableElement()}catch{return!1}if(!t)return!1;var n;if((n=this.getSourceBlock())!=null&&n.isInFlyout){let i,a;if((i=this.getSourceBlock())==null||!i.getFullBlockField()||(a=this.getSourceBlock())!=null&&a.getParent())return C(t,F.HIDDEN,!0),!1;var r;n=(r=this.getSourceBlock())?.getAriaRoleDescription()||e.C.BLOCK_LABEL_VALUE,C(t,F.ROLEDESCRIPTION,n)}return le(t,F.HIDDEN),S(t,P.BUTTON),r=this.computeAriaLabel(!0),C(t,F.LABEL,r),!0}static fromJson(){throw Error(`Attempted to instantiate a field from the registry that hasn't defined a 'fromJson' method.`)}};ku.NBSP=`\xA0`,ku.SKIP_SETUP=Symbol(`SKIP_SETUP`);var Au=class extends Error{constructor(){super(`The field has not yet been attached to its input. Call appendField to attach it.`)}},ju=null,Mu=null,Nu=null,Pu=``,Fu=``,Iu,Lu=null,Ru={};Ru.createDom=cr,Ru.getDiv=function(){return Iu},Ru.hide=ur,Ru.hideIfOwner=dr,Ru.hideIfOwnerIsInWorkspace=fr,Ru.isVisible=function(){return!!ju},Ru.positionWithAnchor=mr,Ru.repositionForWindowResize=hr,Ru.show=lr,Ru.testOnly_setDiv=function(e){if(Iu=e,e===null){let e;(e=document.querySelector(`.blocklyWidgetDiv`))==null||e.remove()}};var zu=null,Bu={},Vu=null,Hu={};Hu.callbackFactory=e.ug,Hu.dispose=xr,Hu.getCurrentBlock=function(){return zu},Hu.getMenu=function(){return Vu},Hu.hide=br,Hu.setCurrentBlock=function(e){zu=e},Hu.show=gr;var G=class{constructor(){this.registeredItems=new Map,this.reset()}reset(){this.registeredItems.clear()}register(e){if(this.registeredItems.has(e.id))throw Error(`Menu item with ID "`+e.id+`" is already registered.`);this.registeredItems.set(e.id,e)}unregister(e){if(!this.registeredItems.has(e))throw Error(`Menu item with ID "`+e+`" not found.`);this.registeredItems.delete(e)}getItem(e){return this.registeredItems.get(e)??null}getContextMenuOptions(e,t){var n=[];for(let r of this.registeredItems.values()){if(r.scopeType&&(r.scopeType===Gu.BLOCK&&!e.block||r.scopeType===Gu.COMMENT&&!e.comment||r.scopeType===Gu.WORKSPACE&&!e.workspace))continue;let i;i={id:r.id,scope:e,weight:r.weight};let a,o=(a=r).preconditionFn?.call(a,e,t);if(o!==`hidden`){if(r.separator)i=Object.assign({},i,{separator:!0});else{let t=typeof r.displayText==`function`?r.displayText(e):r.displayText;i=Object.assign({},i,{text:t,callback:r.callback,enabled:o===`enabled`,associatedKeyboardShortcut:r.associatedKeyboardShortcut})}n.push(i)}}return n.sort(function(e,t){return e.weight-t.weight}),n}},Uu=G||={},Wu=Uu.ScopeType||={};Wu.BLOCK=`block`,Wu.WORKSPACE=`workspace`,Wu.COMMENT=`comment`,Uu.registry=new Uu;var Gu=G.ScopeType,Ku=class{constructor(e){this.comment=e,this.startLoc=null,this.workspace=e.workspace}isMovable(){return this.comment.isOwnMovable()&&!this.comment.isDeadOrDying()&&!this.workspace.isReadOnly()}startDrag(){this.fireDragStartEvent(),this.startLoc=this.comment.getRelativeToSurfaceXY(),this.workspace.setResizesEnabled(!1);var e;return(e=this.workspace.getLayerManager())==null||e.moveToDragLayer(this.comment),this.comment.setDragging(!0),this.comment}drag(e){this.comment.moveDuringDrag(e)}endDrag(){this.fireDragEndEvent(),this.fireMoveEvent();var e;(e=this.workspace.getLayerManager())==null||e.moveOffDragLayer(this.comment,50),this.workspace.getAudioManager().play(`drop`),this.comment.setDragging(!1),this.comment.snapToGrid(),this.workspace.setResizesEnabled(!0)}fireDragStartEvent(){b(new(x(N.COMMENT_DRAG))(this.comment,!0))}fireDragEndEvent(){b(new(x(N.COMMENT_DRAG))(this.comment,!1))}fireMoveEvent(){if(!this.comment.isDeadOrDying()){var e=new(x(N.COMMENT_MOVE))(this.comment);e.setReason([`drag`]),e.oldCoordinate_=this.startLoc,e.recordNew(),b(e)}}revertDrag(){this.startLoc&&this.comment.moveDuringDrag(this.startLoc)}},qu=new WeakMap,Ju=class{constructor(e,t,n,r){this.id=e,this.workspace=t,this.container=n,this.commentView=r}isVisible(){return this.icon.checkVisibility()}getCommentView(){return this.commentView}getSize(e=!1){var t=this.icon.getBBox();return t=B.from(t),e&&(e=this.getMargin(),t.left-=e,t.top-=e,t.bottom+=e,t.right+=e),t}getMargin(){return(this.container.getBBox().height-this.icon.getBBox().height)/2}getFocusableElement(){return this.icon}getFocusableTree(){return this.workspace}onNodeFocus(){var e=this.getCommentView(),t=e.getRelativeToSurfaceXY(),n=e.getSize();t=new B(t.y,t.y+n.height,t.x,t.x+n.width),e.workspace.scrollBoundsIntoView(t)}onNodeBlur(){}canBeFocused(){return this.isVisible()}recomputeAriaContext(){if(this.icon){S(this.icon,P.BUTTON);var t=this.getAriaLabel();C(this.icon,F.LABEL,t||e.C.ARIA_LABEL_BUTTON)}}getAriaLabel(){return null}},Yu=class extends Ju{constructor(e,t,n,r){super(e,t,n,r),this.id=e,this.workspace=t,this.container=n,this.commentView=r,this.icon=w(I.IMAGE,{class:`blocklyFoldoutIcon`,href:`${this.workspace.options.pathToMedia}foldout-icon.svg`,id:`${this.id}_collapse_bar_button`},this.container),this.recomputeAriaContext(),this.bindId=p(this.icon,`pointerdown`,this,this.performAction.bind(this))}dispose(){h(this.bindId)}reposition(){var e=this.getMargin();this.icon.setAttribute(`y`,`${e}`),this.icon.setAttribute(`x`,`${e}`)}performAction(e){lo=null,this.getCommentView().bringToFront(),e&&e instanceof PointerEvent&&_(e)?e.stopPropagation():(this.getCommentView().setCollapsed(!this.getCommentView().isCollapsed()),this.recomputeAriaContext(),this.workspace.hideChaff(),e?.stopPropagation())}getAriaLabel(){return this.getCommentView().isCollapsed()?e.C.ARIA_LABEL_COMMENT_EXPAND:e.C.ARIA_LABEL_COMMENT_COLLAPSE}},Xu=class{constructor(t,n,r){this.workspace=t,this.onFinishEditing=r,this.textChangeListeners=[],this.text=``,this.foreignObject=w(I.FOREIGNOBJECT,{class:`blocklyCommentForeignObject`}),t=document.createElementNS(`http://www.w3.org/1999/xhtml`,`body`),t.setAttribute(`xmlns`,`http://www.w3.org/1999/xhtml`),t.className=`blocklyMinimalBody`,this.textArea=document.createElementNS(`http://www.w3.org/1999/xhtml`,`textarea`),this.textArea.setAttribute(`tabindex`,`-1`),this.textArea.setAttribute(`dir`,this.workspace.RTL?`RTL`:`LTR`),S(this.textArea,P.TEXTBOX),this.textArea.setAttribute(`placeholder`,e.C.WORKSPACE_COMMENT_DEFAULT_TEXT),T(this.textArea,`blocklyCommentText`),T(this.textArea,`blocklyTextarea`),T(this.textArea,`blocklyText`),t.appendChild(this.textArea),this.foreignObject.appendChild(t),this.id=n+`_comment_textarea_`,this.textArea.setAttribute(`id`,this.id),p(this.textArea,`change`,this,this.onTextChange),p(this.textArea,`pointerdown`,this,t=>{t.stopPropagation(),e.A().focusNode(this),lo=null}),p(this.textArea,`wheel`,this,e=>{e.stopPropagation()},!1,{passive:!0}),p(this.textArea,`keydown`,this,this.handleKeyDown)}getDom(){return this.foreignObject}getText(){return this.text}setText(e){this.textArea.value=e,this.onTextChange()}setParent(e){this.parent=e}getParent(){return this.parent}onTextChange(){var e=this.text;this.text=this.textArea.value;for(let t=this.textChangeListeners.length-1;t>=0;t--)this.textChangeListeners[t](e,this.text)}handleKeyDown(e){(e.key===`Escape`||e.key===`Enter`&&(e.ctrlKey||e.metaKey))&&(this.onFinishEditing&&this.onFinishEditing(),e.stopPropagation())}addTextChangeListener(e){this.textChangeListeners.push(e)}removeTextChangeListener(e){this.textChangeListeners.splice(this.textChangeListeners.indexOf(e),1)}setPlaceholderText(e){this.textArea.placeholder=e}setEditable(e){e?this.textArea.removeAttribute(`readonly`):this.textArea.setAttribute(`readonly`,`true`)}updateSize(e,t){this.foreignObject.setAttribute(`height`,`${e.height-t.height}`),this.foreignObject.setAttribute(`width`,`${e.width}`),this.foreignObject.setAttribute(`y`,`${t.height}`),this.workspace.RTL&&this.foreignObject.setAttribute(`x`,`${-e.width}`)}getFocusableElement(){return this.textArea}getFocusableTree(){return this.workspace}onNodeFocus(){var e=B.from(this.foreignObject.getBoundingClientRect());this.workspace.scrollBoundsIntoView(B.createFromPoint(nt(this.workspace,e.getOrigin()),e.getWidth(),e.getHeight()))}onNodeBlur(){}canBeFocused(){return!!this.id}},Zu=class extends Ju{constructor(e,t,n,r){super(e,t,n,r),this.id=e,this.workspace=t,this.container=n,this.commentView=r,this.icon=w(I.IMAGE,{class:`blocklyDeleteIcon`,href:`${this.workspace.options.pathToMedia}delete-icon.svg`,id:`${this.id}_delete_bar_button`},n),this.recomputeAriaContext(),this.bindId=p(this.icon,`pointerdown`,this,this.performAction.bind(this))}dispose(){h(this.bindId)}reposition(){var e=this.getMargin();this.icon.setAttribute(`x`,`0`);var t=this.container.getBBox();this.icon.setAttribute(`y`,`${e}`),this.icon.setAttribute(`x`,`${t.width-this.getSize(!0).getWidth()}`)}performAction(t){lo=null,t&&t instanceof PointerEvent&&_(t)?t.stopPropagation():(this.getCommentView().dispose(),t?.stopPropagation(),e.A().focusNode(this.workspace),this.workspace.getAudioManager().play(`delete`))}getAriaLabel(){return e.C.REMOVE_COMMENT}},Qu=class{constructor(t,n){this.workspace=t,this.commentId=n,this.collapsed=!1,this.editable=!0,this.location=new z(0,0),this.sizeChangeListeners=[],this.disposeListeners=[],this.collapseChangeListeners=[],this.resizePointerMoveListener=this.resizePointerUpListener=null,this.disposed=this.disposing=!1,this.svgRoot=w(I.G,{class:`blocklyComment blocklyEditable blocklyDraggable`}),S(this.svgRoot,P.BUTTON),C(this.svgRoot,F.ROLEDESCRIPTION,e.C.ARIA_LABEL_COMMENT),this.highlightRect=this.createHighlightRect(this.svgRoot),{topBarGroup:this.topBarGroup,topBarBackground:this.topBarBackground,deleteButton:this.deleteButton,foldoutButton:this.foldoutButton,textPreview:this.textPreview,textPreviewNode:this.textPreviewNode}=this.createTopBar(this.svgRoot),this.commentEditor=this.createTextArea(),C(this.svgRoot,F.LABELLEDBY,this.commentEditor.getFocusableElement().id),this.resizeHandle=this.createResizeHandle(this.svgRoot,t);var r;(r=t.getLayerManager())==null||r.append(this,50),this.size=Qu.defaultCommentSize,this.setSizeWithoutFiringEvents(this.size),this.moveTo(new z(0,0))}createHighlightRect(e){return w(I.RECT,{class:`blocklyCommentHighlight`},e)}createTopBar(e){e=w(I.G,{class:`blocklyCommentTopbar`},e);var t=w(I.RECT,{class:`blocklyCommentTopbarBackground`},e),n=new Zu(this.commentId,this.workspace,e,this),r=new Yu(this.commentId,this.workspace,e,this);this.addDisposeListener(()=>{n.dispose(),r.dispose()});var i=w(I.TEXT,{class:`blocklyCommentPreview blocklyCommentText blocklyText`},e),a=document.createTextNode(``);return i.appendChild(a),{topBarGroup:e,topBarBackground:t,deleteButton:n,foldoutButton:r,textPreview:i,textPreviewNode:a}}createTextArea(){var e=new Xu(this.workspace,this.commentId,()=>this.svgRoot.focus());return this.svgRoot.appendChild(e.getDom()),e.addTextChangeListener((e,t)=>{this.updateTextPreview(t),this.setSize(this.size)}),e}getEditorFocusableNode(){return this.commentEditor}createResizeHandle(e,t){return e=w(I.IMAGE,{class:`blocklyResizeHandle`,href:`${t.options.pathToMedia}resize-handle.svg`},e),p(e,`pointerdown`,this,this.onResizePointerDown),e}getSvgRoot(){return this.svgRoot}getSize(){return this.collapsed?this.topBarBackground.getBBox():this.size}setSizeWithoutFiringEvents(e){var t=this.topBarBackground.getBBox(),n=this.textPreview.getBBox(),r=this.resizeHandle.getBBox();this.size=e=V.max(e,this.calcMinSize(t)),this.svgRoot.setAttribute(`height`,`${e.height}`),this.svgRoot.setAttribute(`width`,`${e.width}`),this.updateHighlightRect(e),this.updateTopBarSize(e),this.commentEditor.updateSize(e,t),this.deleteButton.reposition(),this.foldoutButton.reposition(),this.updateTextPreviewSize(e,t,n),this.updateResizeHandlePosition(e,r)}setSize(e){var t=this.preResizeSize||this.size;this.setSizeWithoutFiringEvents(e),this.onSizeChange(t,this.size)}calcMinSize(e){var t;this.updateTextPreview((t=this.commentEditor.getText())??``);var n=t=ye(this.textPreview);return this.foldoutButton.isVisible()?n+=this.foldoutButton.getSize(!0).getWidth():t&&(n+=4),this.deleteButton.isVisible()?n+=this.deleteButton.getSize(!0).getWidth():t&&(n+=4),new V(n,e.height+20)}updateHighlightRect(e){this.highlightRect.setAttribute(`height`,`${e.height}`),this.highlightRect.setAttribute(`width`,`${e.width}`),this.workspace.RTL&&this.highlightRect.setAttribute(`x`,`${-e.width}`)}updateTopBarSize(e){this.topBarBackground.setAttribute(`width`,`${e.width}`)}updateTextPreviewSize(e,t,n){t=(t.height-n.height)/2;var r=this.foldoutButton.getSize(!0),i=this.deleteButton.getSize(!0);e=e.width-r.getWidth()-i.getWidth(),this.textPreview.setAttribute(`x`,`${(this.workspace.RTL?-1:1)*r.getWidth()}`),this.textPreview.setAttribute(`y`,`${t+n.height/2}`),this.textPreview.setAttribute(`width`,`${e}`)}updateResizeHandlePosition(e,t){this.resizeHandle.setAttribute(`y`,`${e.height-t.height}`),this.resizeHandle.setAttribute(`x`,`${e.width-t.width}`)}onSizeChange(e,t){for(let n=this.sizeChangeListeners.length-1;n>=0;n--)this.sizeChangeListeners[n](e,t)}addSizeChangeListener(e){this.sizeChangeListeners.push(e)}removeSizeChangeListener(e){this.sizeChangeListeners.splice(this.sizeChangeListeners.indexOf(e),1)}onResizePointerDown(e){this.isEditable()&&(this.bringToFront(),_(e)||(this.preResizeSize=this.getSize(),wr(this.workspace,e,new z(this.workspace.RTL?-this.getSize().width:this.getSize().width,this.getSize().height)),this.resizePointerUpListener=p(document,`pointerup`,this,this.onResizePointerUp),this.resizePointerMoveListener=p(document,`pointermove`,this,this.onResizePointerMove),this.workspace.hideChaff()),e.stopPropagation())}onResizePointerUp(){lo=null,this.resizePointerUpListener&&=(h(this.resizePointerUpListener),null),this.resizePointerMoveListener&&=(h(this.resizePointerMoveListener),null),this.setSize(this.size),this.preResizeSize=void 0}onResizePointerMove(e){e=Tr(this.workspace,e),this.setSizeWithoutFiringEvents(new V(this.workspace.RTL?-e.x:e.x,e.y))}isCollapsed(){return this.collapsed}setCollapsed(e){(this.collapsed=e)?T(this.svgRoot,`blocklyCollapsed`):E(this.svgRoot,`blocklyCollapsed`),this.setSizeWithoutFiringEvents(this.size),this.onCollapse()}onCollapse(){for(let e=this.collapseChangeListeners.length-1;e>=0;e--)this.collapseChangeListeners[e](this.collapsed)}addOnCollapseListener(e){this.collapseChangeListeners.push(e)}removeOnCollapseListener(e){this.collapseChangeListeners.splice(this.collapseChangeListeners.indexOf(e),1)}isEditable(){return this.editable}setEditable(e){(this.editable=e)?(T(this.svgRoot,`blocklyEditable`),E(this.svgRoot,`blocklyReadonly`)):(E(this.svgRoot,`blocklyEditable`),T(this.svgRoot,`blocklyReadonly`)),this.commentEditor.setEditable(e)}getRelativeToSurfaceXY(){return this.location}moveTo(e){this.location=e,this.svgRoot.setAttribute(`transform`,`translate(${e.x}, ${e.y})`)}getText(){return this.commentEditor.getText()}setText(e){this.commentEditor.setText(e)}setPlaceholderText(e){this.commentEditor.setPlaceholderText(e)}addTextChangeListener(e){this.commentEditor.addTextChangeListener(e)}removeTextChangeListener(e){this.commentEditor.removeTextChangeListener(e)}updateTextPreview(e){this.textPreviewNode.textContent=this.truncateText(e)}truncateText(e){return e.length>=12?`${e.substring(0,9)}...`:e}bringToFront(){var e=this.svgRoot.parentNode,t=e.childNodes;t[t.length-1]!==this.svgRoot&&e.appendChild(this.svgRoot)}onDeleteDown(e){lo=null,_(e)||this.dispose(),e.stopPropagation()}dispose(){this.disposing=!0,D(this.svgRoot);for(let e=this.disposeListeners.length-1;e>=0;e--)this.disposeListeners[e]();this.disposeListeners.length=0,this.disposed=!0}isDisposed(){return this.disposed}isDeadOrDying(){return this.disposing||this.disposed}addDisposeListener(e){this.disposeListeners.push(e)}removeDisposeListener(e){this.disposeListeners.splice(this.disposeListeners.indexOf(e),1)}getCommentBarButtons(){return[this.foldoutButton,this.deleteButton]}};Qu.defaultCommentSize=new V(120,100),He(`
685
+ .injectionDiv {
686
+ --commentFillColour: #FFFCC7;
687
+ --commentBorderColour: #F2E49B;
688
+ }
689
+
690
+ .blocklyComment .blocklyTextarea {
691
+ background-color: var(--commentFillColour);
692
+ border: 1px solid var(--commentBorderColour);
693
+ box-sizing: border-box;
694
+ display: block;
695
+ outline: 0;
696
+ padding: 5px;
697
+ resize: none;
698
+ width: 100%;
699
+ height: 100%;
700
+ }
701
+
702
+ .blocklyReadonly.blocklyComment .blocklyTextarea {
703
+ cursor: inherit;
704
+ }
705
+
706
+ .blocklyDeleteIcon {
707
+ width: 20px;
708
+ height: 20px;
709
+ display: none;
710
+ cursor: pointer;
711
+ }
712
+
713
+ .blocklyFoldoutIcon {
714
+ width: 20px;
715
+ height: 20px;
716
+ transform-origin: 12px 12px;
717
+ cursor: pointer;
718
+ }
719
+ .blocklyResizeHandle {
720
+ width: 12px;
721
+ height: 12px;
722
+ cursor: se-resize;
723
+ }
724
+ .blocklyReadonly.blocklyComment .blocklyResizeHandle {
725
+ cursor: inherit;
726
+ }
727
+
728
+ .blocklyCommentTopbarBackground {
729
+ fill: var(--commentBorderColour);
730
+ height: 24px;
731
+ }
732
+
733
+ .blocklyComment .blocklyCommentPreview.blocklyText {
734
+ fill: #000;
735
+ dominant-baseline: middle;
736
+ visibility: hidden;
737
+ }
738
+
739
+ .blocklyCollapsed.blocklyComment .blocklyCommentPreview {
740
+ visibility: visible;
741
+ }
742
+
743
+ .blocklyCollapsed.blocklyComment .blocklyCommentForeignObject,
744
+ .blocklyCollapsed.blocklyComment .blocklyResizeHandle {
745
+ display: none;
746
+ }
747
+
748
+ .blocklyCollapsed.blocklyComment .blocklyFoldoutIcon {
749
+ transform: rotate(-90deg);
750
+ }
751
+
752
+ .blocklyRTL .blocklyCommentTopbar {
753
+ transform: scale(-1, 1);
754
+ }
755
+
756
+ .blocklyRTL .blocklyCommentForeignObject {
757
+ direction: rtl;
758
+ }
759
+
760
+ .blocklyRTL .blocklyCommentPreview {
761
+ /* Revert the scale and control RTL using direction instead. */
762
+ transform: scale(-1, 1);
763
+ direction: rtl;
764
+ }
765
+
766
+ .blocklyRTL .blocklyResizeHandle {
767
+ transform: scale(-1, 1);
768
+ cursor: sw-resize;
769
+ }
770
+
771
+ .blocklyCommentHighlight {
772
+ fill: none;
773
+ }
774
+
775
+ .blocklyCommentText.blocklyActiveFocus {
776
+ border-color: #fc3;
777
+ border-width: 2px;
778
+ }
779
+
780
+ .blocklySelected .blocklyCommentHighlight {
781
+ stroke: #fc3;
782
+ stroke-width: 3px;
783
+ }
784
+
785
+ .blocklyCollapsed.blocklySelected .blocklyCommentHighlight {
786
+ stroke: none;
787
+ }
788
+
789
+ .blocklyCollapsed.blocklySelected .blocklyCommentTopbarBackground {
790
+ stroke: #fc3;
791
+ stroke-width: 3px;
792
+ }
793
+ `);var $u=class{constructor(e,t){this.workspace=e,this.text=``,this.collapsed=!1,this.deletable=this.movable=this.editable=!0,this.location=new z(0,0),this.disposing=this.disposed=!1,this.id=t&&!e.getCommentById(t)?t:te(),this.size=Qu.defaultCommentSize,e.addTopComment(this),this.fireCreateEvent()}fireCreateEvent(){oe()&&b(new(x(N.COMMENT_CREATE))(this))}fireDeleteEvent(){oe()&&b(new(x(N.COMMENT_DELETE))(this))}fireChangeEvent(e,t){oe()&&b(new(x(N.COMMENT_CHANGE))(this,e,t))}fireCollapseEvent(e){oe()&&b(new(x(N.COMMENT_COLLAPSE))(this,e))}setText(e){var t=this.text;this.text=e,this.fireChangeEvent(t,e)}getText(){return this.text}setSize(e){var t=new(x(N.COMMENT_RESIZE))(this);this.size=e,t.recordCurrentSizeAsNewSize(),b(t)}getSize(){return this.size}setCollapsed(e){this.collapsed=e,this.fireCollapseEvent(e)}isCollapsed(){return this.collapsed}setEditable(e){this.editable=e}isEditable(){return this.isOwnEditable()&&!this.workspace.isReadOnly()}isOwnEditable(){return this.editable}setMovable(e){this.movable=e}isMovable(){return this.isOwnMovable()&&!this.workspace.isReadOnly()&&!this.workspace.isFlyout}isOwnMovable(){return this.movable}setDeletable(e){this.deletable=e}isDeletable(){return this.isOwnDeletable()&&!this.isDeadOrDying()&&!this.workspace.isReadOnly()&&!this.workspace.isFlyout}isOwnDeletable(){return this.deletable}moveTo(e,t){var n=new(x(N.COMMENT_MOVE))(this);t&&n.setReason(t),this.location=e,n.recordNew(),b(n)}getRelativeToSurfaceXY(){return this.location.clone()}dispose(){this.disposing=!0,this.fireDeleteEvent(),this.workspace.removeTopComment(this),this.disposed=!0}isDisposed(){return this.disposed}isDeadOrDying(){return this.disposing||this.disposed}},ed=class extends $u{constructor(e,t){super(e,t),this.dragStrategy=new Ku(this),this.workspace=e,this.view=new Qu(e,this.id),this.view.getEditorFocusableNode().setParent(this),this.view.setSize(this.getSize()),this.view.setEditable(this.isEditable()),this.view.getSvgRoot().setAttribute(`data-id`,this.id),this.view.getSvgRoot().setAttribute(`id`,this.id),this.addModelUpdateBindings(),p(this.view.getSvgRoot(),`pointerdown`,this,this.startGesture)}addModelUpdateBindings(){this.view.addTextChangeListener((e,t)=>void super.setText(t)),this.view.addSizeChangeListener((e,t)=>void super.setSize(t)),this.view.addOnCollapseListener(()=>void super.setCollapsed(this.view.isCollapsed())),this.view.addDisposeListener(()=>{this.isDeadOrDying()||this.dispose()})}setText(e){this.view.setText(e)}setPlaceholderText(e){this.view.setPlaceholderText(e)}setSize(e){this.view.setSize(e)}setCollapsed(e){this.view.setCollapsed(e)}setEditable(e){super.setEditable(e),this.view.setEditable(this.isEditable())}getSvgRoot(){return this.view.getSvgRoot()}getSize(){return super.getSize()}getBoundingRectangle(){var e=this.getRelativeToSurfaceXY(),t,n,r=(n=(t=this.view)?.getSize())??this.getSize();return this.workspace.RTL?(t=e.x-r.width,n=e.x):(t=e.x,n=e.x+r.width),new B(e.y,e.y+r.height,t,n)}moveBy(e,t,n){var r=this.getRelativeToSurfaceXY();e=new z(r.x+e,r.y+t),this.moveTo(e,n)}moveTo(e,t){super.moveTo(e,t),this.view.moveTo(e)}moveDuringDrag(e){this.location=e,this.view.moveTo(e)}setDragging(e){e?T(this.getSvgRoot(),`blocklyDragging`):E(this.getSvgRoot(),`blocklyDragging`)}dispose(){this.disposing=!0;var t=e.A();t.getFocusedNode()===this&&setTimeout(()=>t.focusTree(this.workspace),0),this.view.isDeadOrDying()||this.view.dispose(),super.dispose()}startGesture(t){var n=this.workspace.getGesture(t);n&&(n.handleCommentStart(t,this),e.A().focusNode(this))}setDeleteStyle(e){e?T(this.getSvgRoot(),`blocklyDraggingDelete`):E(this.getSvgRoot(),`blocklyDraggingDelete`)}isCopyable(){return this.isOwnMovable()&&this.isOwnDeletable()}isMovable(){return this.dragStrategy.isMovable()}startDrag(){return this.dragStrategy.startDrag()}drag(e){this.dragStrategy.drag(e)}endDrag(){this.dragStrategy.endDrag()}revertDrag(){this.dragStrategy.revertDrag()}select(){T(this.getSvgRoot(),`blocklySelected`),Ne(this)}unselect(){E(this.getSvgRoot(),`blocklySelected`),Ne(null)}toCopyData(){return{paster:pc.TYPE,commentState:_t(this,{addCoordinates:!0,saveIds:!1})}}showContextMenu(e){var t=G.registry.getContextMenuOptions({comment:this,focusedNode:this},e),n=e instanceof PointerEvent?new z(e.clientX,e.clientY):rt(this.workspace,this.getRelativeToSurfaceXY()).translate(10,10);gr(e,t,this.workspace.RTL,this.workspace,n)}snapToGrid(){if(!this.isDeadOrDying()){var e=this.workspace.getGrid();if(e!=null&&e.shouldSnap()){var t=this.getRelativeToSurfaceXY();e=e.alignXY(t),e!==t&&this.moveTo(e,[`snap`])}}}getEditorFocusableNode(){return this.view.getEditorFocusableNode()}getFocusableElement(){return this.getSvgRoot()}getFocusableTree(){return this.workspace}onNodeFocus(){this.select();var e;(e=this.getSvgRoot().parentElement)==null||e.appendChild(this.getSvgRoot()),this.workspace.scrollBoundsIntoView(this.getBoundingRectangle())}onNodeBlur(){this.unselect()}canBeFocused(){return!0}performAction(){this.setCollapsed(!1),e.A().focusNode(this.getEditorFocusableNode())}},td={appendDomToWorkspace:function(t,n){if(!n.getBlocksBoundingBox)return e.Ig(t,n);var r=n.getBlocksBoundingBox();if(t=e.Ig(t,n),r&&r.top!==r.bottom){var i=r.bottom;r=n.RTL?r.right:r.left;var a=1/0;let e=-1/0,o=1/0;for(let r=0;r<t.length;r++){let i=n.getBlockById(t[r]).getRelativeToSurfaceXY();i.y<o&&(o=i.y),i.x<a&&(a=i.x),i.x>e&&(e=i.x)}for(i=i-o+10,r=n.RTL?r-e:r-a,a=0;a<t.length;a++)n.getBlockById(t[a]).moveBy(r,i,[`create`])}return t}};td.blockToDom=kr,td.blockToDomWithXY=Or,td.clearWorkspaceAndLoadFromXml=function(t,n){return n.setResizesEnabled(!1),n.clear(),t=e.Ig(t,n),n.setResizesEnabled(!0),t},td.deleteNext=function(e){for(let t=0;t<e.childNodes.length;t++){let n=e.childNodes[t];if(n.nodeName.toLowerCase()===`next`){e.removeChild(n);break}}},td.domToBlock=e.Lg,td.domToBlockInternal=Nr,td.domToPrettyText=function(e){e=jr(e).split(`<`);var t=``;for(let n=1;n<e.length;n++){let r=e[n];r[0]===`/`&&(t=t.substring(2)),e[n]=t+`<`+r,r[0]!==`/`&&r.slice(-2)!==`/>`&&(t+=` `)}return e=e.join(`
794
+ `),e=e.replace(/(<(\w+)\b[^>]*>[^\n]*)\n *<\/\2>/g,`$1</$2>`),e.replace(/^\n/,``)},td.domToText=jr,td.domToVariables=Pr,td.domToWorkspace=e.Ig,td.loadWorkspaceComment=Mr,td.saveWorkspaceComment=Er,td.variablesToDom=Dr,td.workspaceToDom=function(t,n=!1){var r=e.F(`xml`),i=Dr(e.Ad(t));i.hasChildNodes()&&r.appendChild(i);for(let e of t.getTopComments())r.appendChild(Er(e,n));for(t=t.getTopBlocks(!0),i=0;i<t.length;i++)r.appendChild(Or(t[i],n));return r};var nd={fromJsonInternal:function(e){var t=r(M.FIELD,e.type,void 0);return t?t.fromJson(e):(console.warn(`Blockly could not create a field of type `+e.type+`. The field is probably not being registered. This could be because the file is not loaded, the field does not register itself (Issue #1584), or the registration is not being reached.`),null)}},rd={TEST_ONLY:nd};rd.fromJson=e.Rg,rd.register=Rr,rd.unregister=function(e){n(M.FIELD,e)};var id=class extends ku{constructor(e,t,n){super(ku.SKIP_SETUP),this.svgArrow=this.arrow=this.imageElement=this.menu_=this.selectedMenuItem=null,this.SERIALIZABLE=!0,this.clickTarget_=this.suffixField=this.prefixField=this.generatedOptions=null,this.isInitialized=!1,e!==ku.SKIP_SETUP&&(this.setOptions(e),n&&this.configure_(n),t&&this.setValidator(t))}fromXml(e){this.isOptionListDynamic()&&this.getOptions(!1),this.setValue(e.textContent)}loadState(e){this.loadLegacyState(id,e)||(this.isOptionListDynamic()&&this.getOptions(!1),this.setValue(e))}initView(){this.shouldAddBorderRect_()?this.createBorderRect_():this.clickTarget_=this.sourceBlock_.getSvgRoot(),this.createTextElement_(),this.imageElement=w(I.IMAGE,{},this.fieldGroup_),this.getConstants().FIELD_DROPDOWN_SVG_ARROW?this.createSVGArrow_():this.createTextArrow_(),this.borderRect_&&T(this.borderRect_,`blocklyDropdownRect`),this.fieldGroup_&&(T(this.fieldGroup_,`blocklyField`),T(this.fieldGroup_,`blocklyDropdownField`)),this.recomputeAriaContext(),this.isInitialized=!0}isFullBlockField(){var e;return!this.shouldAddBorderRect_()&&!((e=this.getSourceBlock())==null||!e.isSimpleReporter())}shouldAddBorderRect_(){var e;return!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW||this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW&&!((e=this.getSourceBlock())!=null&&e.isShadow())}createTextArrow_(){this.arrow=w(I.TSPAN,{},this.textElement_);var e;this.arrow.appendChild(document.createTextNode((e=this.getSourceBlock())!=null&&e.RTL?id.ARROW_CHAR+` `:` `+id.ARROW_CHAR)),this.getConstants().FIELD_TEXT_BASELINE_CENTER&&this.arrow.setAttribute(`dominant-baseline`,`central`);var t;(t=this.getSourceBlock())!=null&&t.RTL?this.getTextElement().insertBefore(this.arrow,this.textContent_):this.getTextElement().appendChild(this.arrow)}createSVGArrow_(){this.svgArrow=w(I.IMAGE,{height:this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE+`px`,width:this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE+`px`},this.fieldGroup_),this.svgArrow.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI)}showEditor_(e){var t=this.getSourceBlock();if(!t)throw new Au;this.dropdownCreate(),this.menu_&&(this.menu_.openingCoords=e&&typeof e.clientX==`number`?new z(e.clientX,e.clientY):null,yn(),e=this.menu_.render(ru),T(e,`blocklyDropdownMenu`),this.getConstants().FIELD_DROPDOWN_COLOURED_DIV&&(t=t.getColour(),e=this.sourceBlock_.getColourTertiary(),bn(t,e)),xn(this,this.dropdownDispose_.bind(this)),ru.style.height=`${this.menu_.getSize().height}px`,this.menu_.focus(),this.selectedMenuItem&&this.menu_.setHighlighted(this.selectedMenuItem),this.applyColour(),C(this.getFocusableElement(),F.EXPANDED,!0))}dropdownCreate(){var e=this.getSourceBlock();if(!e)throw new Au;var t=new hc;t.setRole(P.LISTBOX),this.menu_=t,C(this.getFocusableElement(),F.CONTROLS,this.menu_.getId());var n=this.getOptions(!1);this.selectedMenuItem=null;for(let a=0;a<n.length;a++){var r=n[a];if(r===id.SEPARATOR){t.addChild(new gc);continue}let[o,s]=r;if(r=this.computeOptionAriaLabel(r,a),zr(o)){var i=new Image(o.width,o.height);i.src=o.src,i.alt=o.alt}else i=o;r=new mc(i,s,r),r.setRole(P.OPTION),r.setRightToLeft(e.RTL),r.setCheckable(!0),t.addChild(r),r.setChecked(s===this.value_),s===this.value_&&(this.selectedMenuItem=r),r.onAction(this.handleMenuActionEvent,this)}}dropdownDispose_(){this.menu_&&this.menu_.dispose(),this.selectedMenuItem=this.menu_=null,this.applyColour(),C(this.getFocusableElement(),F.EXPANDED,!1)}handleMenuActionEvent(e){kn(this,!0),this.onItemSelected_(this.menu_,e)}onItemSelected_(e,t){this.setValue(t.getValue())}isOptionListDynamic(){return typeof this.menuGenerator_==`function`}getOptions(e){if(!this.menuGenerator_)throw TypeError(`A menu generator was never defined.`);return Array.isArray(this.menuGenerator_)?this.menuGenerator_:e&&this.generatedOptions?this.generatedOptions:(this.generatedOptions=this.menuGenerator_(),this.validateOptions(this.generatedOptions),this.generatedOptions)}setOptions(e){Array.isArray(e)?(this.validateOptions(e),e=this.trimOptions(e),this.menuGenerator_=e.options,this.prefixField=e.prefix||null,this.suffixField=e.suffix||null):this.menuGenerator_=e,this.selectedOption=this.getOptions(!1)[0],this.setValue(this.selectedOption[1])}doClassValidation_(e){return this.getOptions(!0).some(t=>t[1]===e)?e:(this.sourceBlock_&&console.warn(`Cannot set the dropdown's value to an unavailable option. Block type: `+this.sourceBlock_.type+`, Field name: `+this.name+`, Value: `+e),null)}doValueUpdate_(e){super.doValueUpdate_(e),e=this.getOptions(!0);for(let t=0,n;n=e[t];t++)n[1]===this.value_&&(this.selectedOption=n);this.isInitialized&&this.recomputeAriaContext()}applyColour(){var e=this.sourceBlock_;this.borderRect_&&(this.borderRect_.setAttribute(`stroke`,e.getColourTertiary()),this.menu_?this.borderRect_.setAttribute(`fill`,e.getColourTertiary()):this.borderRect_.setAttribute(`fill`,`transparent`)),e&&this.arrow&&(e.isShadow()?this.arrow.style.fill=e.getColourSecondary():this.arrow.style.fill=e.getColour())}render_(){this.getTextContent().nodeValue=``,this.imageElement.style.display=`none`;var e=this.selectedOption&&this.selectedOption[0];zr(e)?this.renderSelectedImage(e):this.renderSelectedText(),this.positionBorderRect_()}renderSelectedImage(e){var t=this.getSourceBlock();if(!t)throw new Au;this.imageElement.style.display=``,this.imageElement.setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,e.src),this.imageElement.setAttribute(`height`,String(e.height)),this.imageElement.setAttribute(`width`,String(e.width));var n=Number(e.height);e=Number(e.width);var r=!!this.borderRect_,i=Math.max(r?this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT:0,n+id.IMAGE_Y_PADDING);r=r?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0;var a=this.svgArrow?this.positionSVGArrow(e+r,i/2-this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE/2):ye(this.arrow);this.size_=new V(e+a+r*2,i);var o=0;t.RTL?this.imageElement.setAttribute(`x`,`${r+a}`):(o=e+a,this.getTextElement().setAttribute(`text-anchor`,`end`),this.imageElement.setAttribute(`x`,`${r}`)),this.imageElement.setAttribute(`y`,String(i/2-n/2)),this.positionTextElement_(o+r,e+a)}renderSelectedText(){this.getTextContent().nodeValue=this.getDisplayText_();var e=this.getTextElement();T(e,`blocklyDropdownText`),e.setAttribute(`text-anchor`,`start`);var t=!!this.borderRect_;e=Math.max(t?this.getConstants().FIELD_DROPDOWN_BORDER_RECT_HEIGHT:0,this.getConstants().FIELD_TEXT_HEIGHT);var n=ye(this.getTextElement());t=t?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0;var r=0;this.svgArrow&&(r=this.positionSVGArrow(n+t,e/2-this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE/2)),this.size_=new V(n+r+t*2,e),this.positionTextElement_(t,n)}positionSVGArrow(e,t){if(!this.svgArrow)return 0;var n=this.getSourceBlock();if(!n)throw new Au;var r=this.borderRect_?this.getConstants().FIELD_BORDER_RECT_X_PADDING:0,i=this.getConstants().FIELD_DROPDOWN_SVG_ARROW_PADDING,a=this.getConstants().FIELD_DROPDOWN_SVG_ARROW_SIZE;return this.svgArrow.setAttribute(`transform`,`translate(`+(n.RTL?r:e+i)+`,`+t+`)`),a+i}getText_(){if(!this.selectedOption)return null;var e=this.selectedOption[0];return zr(e)?e.alt:typeof HTMLElement<`u`&&e instanceof HTMLElement?e.title||(e.ariaLabel??e.innerText):typeof e==`string`?e:(console.warn(`Can't get text for existing dropdown option. If you're using HTMLElement dropdown options in node, ensure you're using jsdom-global or similar.`),null)}static fromJson(e){if(!e.options)throw Error(`options are required for the dropdown field. The options property must be assigned an array of [humanReadableValue, languageNeutralValue] tuples.`);return new this(e.options,void 0,e)}trimOptions(e){var t=!1,n=e.map(e=>{if(e===id.SEPARATOR)return t=!0,e;var[n,r,i]=e;return typeof n==`string`?(e=[O(n),r],i&&e.push(O(i)),e):(t=!0,e=[zr(n)?Object.assign({},n,{alt:O(n.alt)}):n,r],i&&e.push(O(i)),e)});if(t||e.length<2)return{options:n};var r=n.map(([e])=>e),i=Pn(r);e=Fn(r,i);var a=In(r,i);return!e&&!a||i<=e+a?{options:n}:(i=e?r[0].substring(0,e-1):void 0,r=a?r[0].substr(1-a):void 0,{options:this.applyTrim(n,e,a),prefix:i,suffix:r})}applyTrim(e,t,n){return e.map(([e,r,i])=>(e=e.substring(t,e.length-n),i===void 0?[e,r]:[e,r,i]))}validateOptions(e){if(!Array.isArray(e))throw TypeError(`FieldDropdown options must be an array.`);if(!e.length)throw TypeError(`FieldDropdown options must not be an empty array.`);var t=!1;for(let n=0;n<e.length;n++){let r=e[n];Array.isArray(r)||r===id.SEPARATOR?typeof r[1]==`string`?!r[0]||typeof r[0]==`string`||zr(r[0])||typeof HTMLElement<`u`&&r[0]instanceof HTMLElement?r[2]&&typeof r[2]!=`string`&&(t=!0,console.error(`Invalid option[${n}]: Each FieldDropdown option ARIA label must be a string.
795
+ Found ${r[2]} in: ${r}`)):(t=!0,console.error(`Invalid option[${n}]: Each FieldDropdown option must have a string
796
+ label, image description, or HTML element. Found ${r[0]} in: ${r}`)):(t=!0,console.error(`Invalid option[${n}]: Each FieldDropdown option id must be a string.
797
+ Found ${r[1]} in: ${r}`)):(t=!0,console.error(`Invalid option[${n}]: Each FieldDropdown option must be an array or
798
+ the string literal 'separator'. Found: ${r}`))}if(t)throw TypeError(`Found invalid FieldDropdown options.`)}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_DROPDOWN}getAriaValue(){return this.getSelectedAriaLabel()||this.getText()||e.C.FIELD_LABEL_EMPTY}getSelectedAriaLabel(){if(!this.selectedOption)return null;var e=this.selectedOption;return e=this.computeOptionAriaLabel(e,this.getOptions(!1).indexOf(e)),typeof e==`string`?e:null}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var e=this.getFocusableElement(),t=this.computeAriaLabel(!0);return C(e,F.LABEL,t),C(e,F.HASPOPUP,`listbox`),C(e,F.EXPANDED,!!this.menu_),!0}computeOptionAriaLabel(t,n){if(t===id.SEPARATOR)return``;var[r,,i]=t;return typeof i==`string`&&i.trim()?i:(t=null,zr(r)?t=r.ariaLabel??r.alt:typeof HTMLElement<`u`&&r instanceof HTMLElement?t=r.ariaLabel??(r.title||r.innerText):typeof r==`string`&&(t=r),t&&t.trim()?t:e.C.FIELD_LABEL_OPTION_INDEX.replace(`%1`,String(n+1)))}};id.SEPARATOR=`separator`,id.ARROW_CHAR=`▾`,id.IMAGE_Y_OFFSET=5,id.IMAGE_Y_PADDING=id.IMAGE_Y_OFFSET*2,Rr(`field_dropdown`,id);var K,q=K||={};q[q.WIN_KEY_FF_LINUX=0]=`WIN_KEY_FF_LINUX`,q[q.MAC_ENTER=3]=`MAC_ENTER`,q[q.BACKSPACE=8]=`BACKSPACE`,q[q.TAB=9]=`TAB`,q[q.NUM_CENTER=12]=`NUM_CENTER`,q[q.ENTER=13]=`ENTER`,q[q.SHIFT=16]=`SHIFT`,q[q.CTRL=17]=`CTRL`,q[q.ALT=18]=`ALT`,q[q.PAUSE=19]=`PAUSE`,q[q.CAPS_LOCK=20]=`CAPS_LOCK`,q[q.ESC=27]=`ESC`,q[q.SPACE=32]=`SPACE`,q[q.PAGE_UP=33]=`PAGE_UP`,q[q.PAGE_DOWN=34]=`PAGE_DOWN`,q[q.END=35]=`END`,q[q.HOME=36]=`HOME`,q[q.LEFT=37]=`LEFT`,q[q.UP=38]=`UP`,q[q.RIGHT=39]=`RIGHT`,q[q.DOWN=40]=`DOWN`,q[q.PLUS_SIGN=43]=`PLUS_SIGN`,q[q.PRINT_SCREEN=44]=`PRINT_SCREEN`,q[q.INSERT=45]=`INSERT`,q[q.DELETE=46]=`DELETE`,q[q.ZERO=48]=`ZERO`,q[q.ONE=49]=`ONE`,q[q.TWO=50]=`TWO`,q[q.THREE=51]=`THREE`,q[q.FOUR=52]=`FOUR`,q[q.FIVE=53]=`FIVE`,q[q.SIX=54]=`SIX`,q[q.SEVEN=55]=`SEVEN`,q[q.EIGHT=56]=`EIGHT`,q[q.NINE=57]=`NINE`,q[q.FF_SEMICOLON=59]=`FF_SEMICOLON`,q[q.FF_EQUALS=61]=`FF_EQUALS`,q[q.FF_DASH=173]=`FF_DASH`,q[q.FF_HASH=163]=`FF_HASH`,q[q.QUESTION_MARK=63]=`QUESTION_MARK`,q[q.AT_SIGN=64]=`AT_SIGN`,q[q.A=65]=`A`,q[q.B=66]=`B`,q[q.C=67]=`C`,q[q.D=68]=`D`,q[q.E=69]=`E`,q[q.F=70]=`F`,q[q.G=71]=`G`,q[q.H=72]=`H`,q[q.I=73]=`I`,q[q.J=74]=`J`,q[q.K=75]=`K`,q[q.L=76]=`L`,q[q.M=77]=`M`,q[q.N=78]=`N`,q[q.O=79]=`O`,q[q.P=80]=`P`,q[q.Q=81]=`Q`,q[q.R=82]=`R`,q[q.S=83]=`S`,q[q.T=84]=`T`,q[q.U=85]=`U`,q[q.V=86]=`V`,q[q.W=87]=`W`,q[q.X=88]=`X`,q[q.Y=89]=`Y`,q[q.Z=90]=`Z`,q[q.META=91]=`META`,q[q.WIN_KEY_RIGHT=92]=`WIN_KEY_RIGHT`,q[q.CONTEXT_MENU=93]=`CONTEXT_MENU`,q[q.NUM_ZERO=96]=`NUM_ZERO`,q[q.NUM_ONE=97]=`NUM_ONE`,q[q.NUM_TWO=98]=`NUM_TWO`,q[q.NUM_THREE=99]=`NUM_THREE`,q[q.NUM_FOUR=100]=`NUM_FOUR`,q[q.NUM_FIVE=101]=`NUM_FIVE`,q[q.NUM_SIX=102]=`NUM_SIX`,q[q.NUM_SEVEN=103]=`NUM_SEVEN`,q[q.NUM_EIGHT=104]=`NUM_EIGHT`,q[q.NUM_NINE=105]=`NUM_NINE`,q[q.NUM_MULTIPLY=106]=`NUM_MULTIPLY`,q[q.NUM_PLUS=107]=`NUM_PLUS`,q[q.NUM_MINUS=109]=`NUM_MINUS`,q[q.NUM_PERIOD=110]=`NUM_PERIOD`,q[q.NUM_DIVISION=111]=`NUM_DIVISION`,q[q.F1=112]=`F1`,q[q.F2=113]=`F2`,q[q.F3=114]=`F3`,q[q.F4=115]=`F4`,q[q.F5=116]=`F5`,q[q.F6=117]=`F6`,q[q.F7=118]=`F7`,q[q.F8=119]=`F8`,q[q.F9=120]=`F9`,q[q.F10=121]=`F10`,q[q.F11=122]=`F11`,q[q.F12=123]=`F12`,q[q.NUMLOCK=144]=`NUMLOCK`,q[q.SCROLL_LOCK=145]=`SCROLL_LOCK`,q[q.FIRST_MEDIA_KEY=166]=`FIRST_MEDIA_KEY`,q[q.LAST_MEDIA_KEY=183]=`LAST_MEDIA_KEY`,q[q.SEMICOLON=186]=`SEMICOLON`,q[q.DASH=189]=`DASH`,q[q.EQUALS=187]=`EQUALS`,q[q.COMMA=188]=`COMMA`,q[q.PERIOD=190]=`PERIOD`,q[q.SLASH=191]=`SLASH`,q[q.APOSTROPHE=192]=`APOSTROPHE`,q[q.TILDE=192]=`TILDE`,q[q.SINGLE_QUOTE=222]=`SINGLE_QUOTE`,q[q.OPEN_SQUARE_BRACKET=219]=`OPEN_SQUARE_BRACKET`,q[q.BACKSLASH=220]=`BACKSLASH`,q[q.CLOSE_SQUARE_BRACKET=221]=`CLOSE_SQUARE_BRACKET`,q[q.WIN_KEY=224]=`WIN_KEY`,q[q.MAC_FF_META=224]=`MAC_FF_META`,q[q.MAC_WK_CMD_LEFT=91]=`MAC_WK_CMD_LEFT`,q[q.MAC_WK_CMD_RIGHT=93]=`MAC_WK_CMD_RIGHT`,q[q.WIN_IME=229]=`WIN_IME`,q[q.VK_NONAME=252]=`VK_NONAME`,q[q.PHANTOM=255]=`PHANTOM`,q[q.CTRL_CMD=ko||Oo||Do?q.MAC_WK_CMD_LEFT:q.CTRL]=`CTRL_CMD`;var ad=class{constructor(e){this.workspace=e,this.svgRoot=w(I.G,{},e.getLayerManager()?.getDragLayer()??e.getLayerManager()?.getBlockLayer()),this.svgRoot.classList.add(`blocklyMoveIndicator`),e=e.RTL,w(I.CIRCLE,{fill:`white`,"fill-opacity":`0.8`,stroke:`grey`,"stroke-width":`1`,r:20,cx:20*(e?-1:1),cy:20},this.svgRoot),w(I.PATH,{fill:`none`,stroke:`black`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`m18 9l3 3l-3 3m-3-3h6M6 9l-3 3l3 3m-3-3h6m0 6l3 3l3-3m-3-3v6m3-15l-3-3l-3 3m3-3v6`,transform:`translate(${(e?-4:1)*8} 8)`},this.svgRoot)}moveTo(e,t){this.svgRoot.setAttribute(`transform`,`translate(${e+(this.workspace.RTL?20:-20)}, ${t-20})`)}dispose(){D(this.svgRoot)}},od,sd=od||={};sd[sd.NONE=0]=`NONE`,sd[sd.UP=1]=`UP`,sd[sd.DOWN=2]=`DOWN`,sd[sd.LEFT=3]=`LEFT`,sd[sd.RIGHT=4]=`RIGHT`;var cd=class{constructor(){this.totalDelta=new z(0,0),this.stepDistance=20,this.allowedShortcuts=[],this.blurListener=()=>{this.abortMove()}}canMove(e){return!e.workspace.isReadOnly()&&e.isMovable()}isMoving(){return!!this.draggable}startMove(e,t){if(!this.canMove(e)||this.isMoving())return!1;var n=s(M.BLOCK_DRAGGER,e.workspace.options,!0);if(!n)throw Error(`no Dragger registered`);return this.dragger=new n(e,e.workspace),this.draggable=this.dragger.onDragStart(t),this.startLocation=this.draggable.getRelativeToSurfaceXY(),this.updateTotalDelta(),this.draggable.getFocusableElement().addEventListener(`blur`,this.blurListener),e=Object.values(L.registry.getRegistry()).flatMap(e=>e.keyCodes).filter(e=>e&&![K.RIGHT,K.LEFT,K.UP,K.DOWN,K.ENTER,K.SPACE,K.ESC,K.M].includes(typeof e==`number`?e:parseInt(`${e.split(`+`).pop()}`))).filter(e=>!!e),L.registry.register({name:`commitMove`,preconditionFn:()=>this.isMoving(),callback:()=>(this.finishMove(),!1),keyCodes:e,allowCollision:!0},!0),this.scrollCurrentElementIntoView(),this.moveIndicator=new ad(this.draggable.workspace),this.repositionMoveIndicator(),!0}move(e,t){switch(e){case od.UP:this.totalDelta.y-=this.stepDistance;break;case od.DOWN:this.totalDelta.y+=this.stepDistance;break;case od.LEFT:this.totalDelta.x-=this.stepDistance;break;case od.RIGHT:this.totalDelta.x+=this.stepDistance}var n;return(n=this.dragger)==null||n.onDrag(t,this.totalPixelDelta()),this.updateTotalDelta(),this.scrollCurrentElementIntoView(),this.repositionMoveIndicator(),!0}finishMove(e){this.preDragEndCleanup();var t;return(t=this.dragger)==null||t.onDragEnd(e,this.totalPixelDelta()),this.postDragEndCleanup(),!0}abortMove(e){this.preDragEndCleanup();var t;return(t=this.dragger)==null||t.onDragRevert(e,this.totalPixelDelta()),this.postDragEndCleanup(),!0}setMoveDistance(e){this.stepDistance=e}getAllowedShortcuts(){return this.allowedShortcuts}setAllowedShortcuts(e){this.allowedShortcuts=e}repositionMoveIndicator(){wt().then(()=>{var e=this.draggable?.getBoundingRectangle();if(this.draggable&&`getBoundingRectangleWithoutChildren`in this.draggable&&(e=this.positionForBlockMoveIndicator(this.draggable)),e){var t,n;(n=this.moveIndicator)==null||n.moveTo((t=this.draggable)!=null&&t.workspace.RTL?e.left:e.right,e.top)}})}positionForBlockMoveIndicator(e){for(var t=e.workspace.getNavigator(),n=e,r;r=t.getInNode(n);)n=r;for(t=t.getSourceBlockFromNode(n),n=e.getBoundingRectangleWithoutChildren().getOrigin().y;t?.getBoundingRectangleWithoutChildren().getOrigin().y!==n;)t=t?.getParent()??null;return t?.getBoundingRectangleWithoutChildren()??e.getBoundingRectangleWithoutChildren()}preDragEndCleanup(){L.registry.unregister(`commitMove`);var e;(e=this.draggable)==null||e.getFocusableElement().removeEventListener(`blur`,this.blurListener)}postDragEndCleanup(){var e;(e=this.moveIndicator)==null||e.dispose(),this.startLocation=this.dragger=this.draggable=this.moveIndicator=void 0,this.totalDelta=new z(0,0)}totalPixelDelta(){var e=this.draggable?.workspace.scale??1;return new z(this.totalDelta.x*e,this.totalDelta.y*e)}scrollCurrentElementIntoView(){if(this.draggable){var e=this.draggable.getBoundingRectangle();this.draggable.workspace.scrollBoundsIntoView(e)}}updateTotalDelta(){this.draggable&&this.startLocation&&(this.totalDelta=new z(this.draggable.getRelativeToSurfaceXY().x-this.startLocation.x,this.draggable.getRelativeToSurfaceXY().y-this.startLocation.y))}};cd.mover=new cd;var ld=class{constructor(e,n,r,i){this.name=e,this.startHats=!1,this.blockStyles=n||Object.create(null),this.categoryStyles=r||Object.create(null),this.componentStyles=i||Object.create(null),this.fontStyle=Object.create(null),t(M.THEME,e,this,!0)}getClassName(){return this.name+`-theme`}setBlockStyle(e,t){this.blockStyles[e]=t}setCategoryStyle(e,t){this.categoryStyles[e]=t}getComponentStyle(e){if(e=this.componentStyles[e],!e)return null;if(typeof e==`string`){let t=this.getComponentStyle(e);if(t)return t}return`${e}`}setComponentStyle(e,t){this.componentStyles[e]=t}setFontStyle(e){this.fontStyle=e}setStartHats(e){this.startHats=e}static defineTheme(e,t){e=e.toLowerCase();var n=new ld(e),i=t.base;return i&&(typeof i==`string`&&(i=r(M.THEME,i,void 0)??void 0),i instanceof ld&&(we(n,i),n.name=e)),we(n.blockStyles,t.blockStyles),we(n.categoryStyles,t.categoryStyles),we(n.componentStyles,t.componentStyles),we(n.fontStyle,t.fontStyle),t.startHats!==null&&(n.startHats=t.startHats),n}},ud=new ld(`classic`,{colour_blocks:{colourPrimary:`20`},list_blocks:{colourPrimary:`260`},logic_blocks:{colourPrimary:`210`},loop_blocks:{colourPrimary:`120`},math_blocks:{colourPrimary:`230`},procedure_blocks:{colourPrimary:`290`},text_blocks:{colourPrimary:`160`},variable_blocks:{colourPrimary:`330`},variable_dynamic_blocks:{colourPrimary:`310`},hat_blocks:{colourPrimary:`330`,hat:`cap`}},{colour_category:{colour:`20`},list_category:{colour:`260`},logic_category:{colour:`210`},loop_category:{colour:`120`},math_category:{colour:`230`},procedure_category:{colour:`290`},text_category:{colour:`160`},variable_category:{colour:`330`},variable_dynamic_category:{colour:`310`}}),dd=class{constructor(e){this.gridPattern=null,this.getMetrics=this.setMetrics=void 0;var t=null,n=!1,r=!1,i=!1,a=!1,o=!1,s=!1,c=!!e.readOnly;if(!c){var l;t=ot((l=e.toolbox)??null),n=ct(t),r=e.trashcan,r=r===void 0?n:r,i=e.collapse,i=i===void 0?n:i,a=e.comments,a=a===void 0?n:a,o=e.disable,o=o===void 0?n:o,s=e.sounds,s=s===void 0?!0:s}l=e.maxTrashcanContents,r?l===void 0&&(l=32):l=0;var u=!!e.rtl,d=e.horizontalLayout;d===void 0&&(d=!1);var f=e.toolboxPosition!==`end`;f=d?f?H.TOP:H.BOTTOM:f===u?H.RIGHT:H.LEFT;var p=e.css;p===void 0&&(p=!0);var m=`https://static.blockly.com/media/`;e.media&&(m=e.media.endsWith(`/`)?e.media:e.media+`/`);var h=e.oneBasedIndex,g=e.renderer||`thrasos`,_=e.plugins||{},v=e.modalInputs;v===void 0&&(v=!0),this.RTL=u,this.oneBasedIndex=h===void 0?!0:h,this.collapse=i,this.comments=a,this.disable=o,this.readOnly=c,this.maxBlocks=e.maxBlocks||1/0,this.maxInstances=e.maxInstances??null,this.modalInputs=v,this.pathToMedia=m,this.hasCategories=n,this.moveOptions=dd.parseMoveOptions(e,n),this.hasScrollbars=!!this.moveOptions.scrollbars,this.hasTrashcan=r,this.maxTrashcanContents=l,this.hasSounds=s,this.hasCss=p,this.horizontalLayout=d,this.languageTree=t,this.gridOptions=dd.parseGridOptions(e),this.zoomOptions=dd.parseZoomOptions(e),this.toolboxPosition=f,this.theme=dd.parseThemeOptions(e),this.renderer=g,this.rendererOverrides=e.rendererOverrides??null,this.parentWorkspace=e.parentWorkspace??null,this.plugins=_}static parseMoveOptions(e,t){var n=e.move||{},r={};return n.scrollbars===void 0&&e.scrollbars===void 0?r.scrollbars=t:typeof n.scrollbars==`object`?(r.scrollbars={horizontal:!!n.scrollbars.horizontal,vertical:!!n.scrollbars.vertical},r.scrollbars.horizontal&&r.scrollbars.vertical?r.scrollbars=!0:r.scrollbars.horizontal||r.scrollbars.vertical||(r.scrollbars=!1)):r.scrollbars=!!n.scrollbars||!!e.scrollbars,r.wheel=r.scrollbars&&n.wheel!==void 0?!!n.wheel:typeof r.scrollbars==`object`,r.drag=r.scrollbars?n.drag===void 0?!0:!!n.drag:!1,r}static parseZoomOptions(e){e=e.zoom||{};var t={};return t.controls=e.controls===void 0?!1:!!e.controls,t.wheel=e.wheel===void 0?!1:!!e.wheel,t.startScale=e.startScale===void 0?1:Number(e.startScale),t.maxScale=e.maxScale===void 0?3:Number(e.maxScale),t.minScale=e.minScale===void 0?.3:Number(e.minScale),t.scaleSpeed=e.scaleSpeed===void 0?1.2:Number(e.scaleSpeed),t.pinch=e.pinch===void 0?t.wheel||t.controls:!!e.pinch,t}static parseGridOptions(e){e=e.grid||{};var t={};return t.spacing=Number(e.spacing)||0,t.colour=e.colour||`#888`,t.length=e.length===void 0?1:Number(e.length),t.snap=t.spacing>0&&!!e.snap,t}static parseThemeOptions(e){return e=e.theme||ud,typeof e==`string`?r(M.THEME,e,void 0):e instanceof ld?e:ld.defineTheme(e.name||`builtin`+y(),e)}},fd=class{constructor(e,t){this.bubble=e,this.workspace=t,this.startLoc=null}isMovable(){return!0}startDrag(){this.startLoc=this.bubble.getRelativeToSurfaceXY(),this.workspace.setResizesEnabled(!1);var e;return(e=this.workspace.getLayerManager())==null||e.moveToDragLayer(this.bubble),this.bubble.setDragging&&this.bubble.setDragging(!0),this.bubble}drag(e){this.bubble.moveDuringDrag(e)}endDrag(){this.workspace.setResizesEnabled(!0);var e;(e=this.workspace.getLayerManager())==null||e.moveOffDragLayer(this.bubble,100),this.bubble.setDragging(!1)}revertDrag(){this.startLoc&&this.bubble.moveDuringDrag(this.startLoc)}},pd,J=class{constructor(e,t,n,r,i){this.workspace=e,this.anchor=t,this.ownerRect=n,this.owner=i,this.size=new V(0,0),this.colour=`#ffffff`,this.disposed=!1,this.relativeLeft=this.relativeTop=0,this.dragStrategy=new fd(this,this.workspace),this.ariaLabelProvider=null,this.id=y(),this.svgRoot=w(I.G,{class:`blocklyBubble`},e.getBubbleCanvas()),e=w(I.G,{class:`blocklyEmboss`},this.svgRoot),this.tail=w(I.PATH,{class:`blocklyBubbleTail`},e),this.background=w(I.RECT,{class:`blocklyDraggable`,x:0,y:0,rx:pd.BORDER_WIDTH,ry:pd.BORDER_WIDTH},e),this.contentContainer=w(I.G,{},this.svgRoot),this.focusableElement=r??this.svgRoot,this.focusableElement.setAttribute(`id`,this.id),p(this.background,`pointerdown`,this,this.onMouseDown),p(this.focusableElement,`keydown`,this,this.onKeyDown),this.recomputeAriaContext()}dispose(){D(this.svgRoot),this.disposed=!0}setAnchorLocation(e,t=!1){this.anchor=e,t?this.positionByRect(this.ownerRect):this.positionRelativeToAnchor(),this.renderTail()}setPositionRelativeToAnchor(e,t){this.relativeLeft=e,this.relativeTop=t,this.positionRelativeToAnchor(),this.renderTail()}getSize(){return this.size}setSize(e,t=!1){e.width=Math.max(e.width,pd.MIN_SIZE),e.height=Math.max(e.height,pd.MIN_SIZE),this.size=e,this.background.setAttribute(`width`,`${e.width}`),this.background.setAttribute(`height`,`${e.height}`),t?this.positionByRect(this.ownerRect):this.positionRelativeToAnchor(),this.renderTail()}getColour(){return this.colour}setColour(e){this.colour=e,this.tail.setAttribute(`fill`,e),this.background.setAttribute(`fill`,e)}onMouseDown(t){var n;(n=this.workspace.getGesture(t))==null||n.handleBubbleStart(t,this),e.A().focusNode(this)}onKeyDown(t){t.key===`Escape`&&this.owner&&(this.owner.setBubbleVisible(!1),e.A().focusNode(this.owner))}positionRelativeToAnchor(){var e=this.anchor.x;e=this.workspace.RTL?e-(this.relativeLeft+this.size.width):e+this.relativeLeft,this.moveTo(e,this.relativeTop+this.anchor.y)}moveTo(e,t){this.svgRoot.setAttribute(`transform`,`translate(${e}, ${t})`)}moveBy(e,t){var n=this.getRelativeToSurfaceXY();this.moveTo(n.x+e,n.y+t)}positionByRect(e=new B(0,0,0,0)){var t=this.workspace.getMetricsManager().getViewMetrics(!0),n=this.getOptimalRelativeLeft(t),r=this.getOptimalRelativeTop(t),i={x:n,y:-this.size.height-this.workspace.getRenderer().getConstants().MIN_BLOCK_HEIGHT},a={x:-this.size.width-30,y:r};r={x:e.getWidth(),y:r};var o={x:n,y:e.getHeight()};n=e.getWidth()<e.getHeight()?r:o,e=e.getWidth()<e.getHeight()?o:r,r=this.getOverlap(i,t),o=this.getOverlap(a,t);var s=this.getOverlap(n,t);t=this.getOverlap(e,t),t=Math.max(r,o,s,t),r===t?(this.relativeLeft=i.x,this.relativeTop=i.y):o===t?(this.relativeLeft=a.x,this.relativeTop=a.y):s===t?(this.relativeLeft=n.x,this.relativeTop=n.y):(this.relativeLeft=e.x,this.relativeTop=e.y),this.positionRelativeToAnchor()}getOverlap(e,t){var n=this.workspace.RTL?this.anchor.x-e.x-this.size.width:e.x+this.anchor.x;return e=e.y+this.anchor.y,Math.max(0,Math.min(1,(Math.min(n+this.size.width,t.left+t.width)-Math.max(n,t.left))*(Math.min(e+this.size.height,t.top+t.height)-Math.max(e,t.top))/(this.size.width*this.size.height)))}getOptimalRelativeLeft(e){var t=-this.size.width/4;if(this.size.width>e.width)return t;if(e=this.getWorkspaceViewRect(e),this.workspace.RTL){var n=this.anchor.x-t;n-this.size.width<e.left?t=-(e.left-this.anchor.x+this.size.width):n>e.right&&(t=-(e.right-this.anchor.x))}else{n=t+this.anchor.x;let r=n+this.size.width;n<e.left?t=e.left-this.anchor.x:r>e.right&&(t=e.right-this.anchor.x-this.size.width)}return t}getOptimalRelativeTop(e){var t=-this.size.height/4;if(this.size.height>e.height)return t;var n=this.anchor.y+t,r=n+this.size.height;return e=this.getWorkspaceViewRect(e),n<e.top?t=e.top-this.anchor.y:r>e.bottom&&(t=e.bottom-this.anchor.y-this.size.height),t}getWorkspaceViewRect(e){var t=e.top,n=e.top+e.height,r=e.left;return e=e.left+e.width,n-=this.getScrollbarThickness(),this.workspace.RTL?r-=this.getScrollbarThickness():e-=this.getScrollbarThickness(),new B(t,n,r,e)}getScrollbarThickness(){return zs.scrollbarThickness/this.workspace.scale}renderTail(){var e=[],t=this.size.width/2,n=this.size.height/2,r=-this.relativeLeft,i=-this.relativeTop;if(t===r&&n===i)e.push(`M `+t+`,`+n);else{i-=n,r-=t,this.workspace.RTL&&(r*=-1);var a=Math.sqrt(i*i+r*r),o=Math.acos(r/a);i<0&&(o=2*Math.PI-o);var s=o+Math.PI/2;s>Math.PI*2&&(s-=Math.PI*2);var c=Math.sin(s);let l=Math.cos(s),u=(this.size.width+this.size.height)/pd.TAIL_THICKNESS;u=Math.min(u,this.size.width,this.size.height)/4,s=1-pd.ANCHOR_RADIUS/a,r=t+s*r,i=n+s*i,s=t+u*l;let d=n+u*c;t-=u*l,n-=u*c,c=hn(this.workspace.RTL?-pd.TAIL_ANGLE:pd.TAIL_ANGLE),c=o+c,c>Math.PI*2&&(c-=Math.PI*2),o=Math.sin(c)*a/pd.TAIL_BEND,a=Math.cos(c)*a/pd.TAIL_BEND,e.push(`M`+s+`,`+d),e.push(`C`+(s+a)+`,`+(d+o)+` `+r+`,`+i+` `+r+`,`+i),e.push(`C`+r+`,`+i+` `+(t+a)+`,`+(n+o)+` `+t+`,`+n)}e.push(`z`);var l;(l=this.tail)==null||l.setAttribute(`d`,e.join(` `))}bringToFront(){var e=this.svgRoot?.parentNode;return this.svgRoot&&e?.lastChild!==this.svgRoot?(e?.appendChild(this.svgRoot),!0):!1}getRelativeToSurfaceXY(){return new z(this.workspace.RTL?-this.relativeLeft+this.anchor.x-this.size.width:this.anchor.x+this.relativeLeft,this.anchor.y+this.relativeTop)}getBoundingRectangle(){var e=this.getRelativeToSurfaceXY();return new B(e.y,e.y+this.size.height,e.x,e.x+this.size.width)}getSvgRoot(){return this.svgRoot}moveDuringDrag(e){this.moveTo(e.x,e.y),this.relativeLeft=this.workspace.RTL?this.anchor.x-e.x-this.size.width:e.x-this.anchor.x,this.relativeTop=e.y-this.anchor.y,this.renderTail()}setDragging(){}setDeleteStyle(){}isDeletable(){return!1}showContextMenu(){}isMovable(){return!0}startDrag(){return this.dragStrategy.startDrag()}drag(e){this.dragStrategy.drag(e)}endDrag(){this.dragStrategy.endDrag()}revertDrag(){this.dragStrategy.revertDrag()}select(){Ne(this)}unselect(){Ne(null)}getFocusableElement(){return this.focusableElement}getFocusableTree(){return this.workspace}onNodeFocus(){this.select(),this.bringToFront();var e=this.getRelativeToSurfaceXY(),t=this.getSize();e=new B(e.y,e.y+t.height,e.x,e.x+t.width),this.workspace.scrollBoundsIntoView(e)}onNodeBlur(){this.unselect()}canBeFocused(){return!0}getOwner(){return this.owner}recomputeAriaContext(){var t=this.getFocusableElement();if(t){S(t,P.GROUP);var n=this.getAriaLabel()?.trim();C(t,F.LABEL,n||e.C.BUBBLE_LABEL_DEFAULT)}}setAriaLabelProvider(e){this.ariaLabelProvider=e,this.recomputeAriaContext()}getAriaLabel(){if(this.ariaLabelProvider){if(typeof this.ariaLabelProvider==`string`)return this.ariaLabelProvider;if(typeof this.ariaLabelProvider==`function`)return this.ariaLabelProvider(this)}return null}};pd=J,J.BORDER_WIDTH=6,J.DOUBLE_BORDER=pd.BORDER_WIDTH*2,J.MIN_SIZE=pd.DOUBLE_BORDER,J.TAIL_THICKNESS=1,J.TAIL_ANGLE=20,J.TAIL_BEND=4,J.ANCHOR_RADIUS=8;var md=class extends J{constructor(e,t,n,r,i){super(t,n,r,void 0,i),this.workspace=t,this.anchor=n,this.ownerRect=r,this.owner=i,this.autoLayout=!0,t=new dd(e),this.validateWorkspaceOptions(t),this.svgDialog=w(I.SVG,{x:J.BORDER_WIDTH,y:J.BORDER_WIDTH},this.contentContainer),e.parentWorkspace=this.workspace,this.miniWorkspace=this.newWorkspaceSvg(new dd(e)),this.miniWorkspace.internalIsMutator=!0,e=this.miniWorkspace.createDom(`blocklyMutatorBackground`),this.svgDialog.appendChild(e),t.languageTree&&(e.insertBefore(this.miniWorkspace.addFlyout(I.G),this.miniWorkspace.getCanvas()),e=this.miniWorkspace.getFlyout(),e?.init(this.miniWorkspace),e?.show(t.languageTree)),T(this.svgRoot,`blocklyMiniWorkspaceBubble`),this.miniWorkspace.addChangeListener(this.onWorkspaceChange.bind(this));var a,o;(a=this.miniWorkspace.getFlyout())==null||(o=a.getWorkspace())==null||o.addChangeListener(this.onWorkspaceChange.bind(this)),this.updateBubbleSize()}dispose(){this.miniWorkspace.dispose(),super.dispose()}getWorkspace(){return this.miniWorkspace}addWorkspaceChangeListener(e){this.miniWorkspace.addChangeListener(e)}validateWorkspaceOptions(e){if(e.hasCategories)throw Error(`The miniworkspace bubble does not support toolboxes with categories`);if(e.hasTrashcan)throw Error(`The miniworkspace bubble does not support trashcans`);if(e.zoomOptions.controls||e.zoomOptions.wheel||e.zoomOptions.pinch)throw Error(`The miniworkspace bubble does not support zooming`);if(e.moveOptions.scrollbars||e.moveOptions.wheel||e.moveOptions.drag)throw Error(`The miniworkspace bubble does not scrolling/moving the workspace`);if(e.horizontalLayout)throw Error(`The miniworkspace bubble does not support horizontal layouts`)}onWorkspaceChange(){this.bumpBlocksIntoBounds(),this.updateBubbleSize()}bumpBlocksIntoBounds(){if(!this.miniWorkspace.isDragging()||cd.mover.isMoving())for(let e of this.miniWorkspace.getTopBlocks(!1)){let t=e.getRelativeToSurfaceXY();if(t.y<20&&e.moveBy(0,20-t.y),e.RTL){let n=-20,r=this.miniWorkspace.getFlyout();r&&(n-=r.getWidth()),t.x>n&&e.moveBy(n-t.x,0)}else t.x<20&&e.moveBy(20-t.x,0)}}updateBubbleSize(){if(!this.miniWorkspace.isDragging()||cd.mover.isMoving()){this.autoLayout&&=!cd.mover.isMoving();var e=this.getSize(),t=this.calculateWorkspaceSize();Math.abs(e.width-t.width)<md.MINIMUM_VIEW_CHANGE&&Math.abs(e.height-t.height)<md.MINIMUM_VIEW_CHANGE||(this.svgDialog.setAttribute(`width`,`${t.width}px`),this.svgDialog.setAttribute(`height`,`${t.height}px`),this.miniWorkspace.setCachedParentSvgSize(t.width,t.height),this.miniWorkspace.RTL&&this.miniWorkspace.getCanvas().setAttribute(`transform`,`translate(${t.width}, 0)`),this.setSize(new V(t.width+J.DOUBLE_BORDER,t.height+J.DOUBLE_BORDER),this.autoLayout),this.miniWorkspace.resize(),this.miniWorkspace.recordDragTargets())}}calculateWorkspaceSize(){var e=this.miniWorkspace.getCanvas().getBBox(),t=e.width+md.MARGIN;e=e.height+md.MARGIN;var n=this.miniWorkspace.getFlyout();if(n){let r=n.getWorkspace().getMetricsManager().getScrollMetrics();e=Math.max(e,r.height+20),t+=n.getWidth()}return new V(t,e)}updateBlockStyles(){for(var e of this.miniWorkspace.getAllBlocks(!1))e.setStyle(e.getStyleName());if(e=this.miniWorkspace.getFlyout()?.getWorkspace())for(let t of e.getAllBlocks(!1))t.setStyle(t.getStyleName())}moveDuringDrag(e){super.moveDuringDrag(e),this.autoLayout=!1}moveTo(e,t){super.moveTo(e,t),this.miniWorkspace.recordDragTargets()}newWorkspaceSvg(){throw Error(`The implementation of newWorkspaceSvg should be monkey-patched in by blockly.ts`)}performAction(){e.A().focusTree(this.getWorkspace())}};md.MINIMUM_VIEW_CHANGE=10,md.MARGIN=J.DOUBLE_BORDER*3;var hd=class{constructor(e){this.sourceBlock=e,this.offsetInBlock=new z(0,0),this.workspaceLocation=new z(0,0),this.svgRoot=null,this.tooltip=e,this.id=y()}getType(){throw Error(`Icons must implement getType`)}initView(e){if(!this.svgRoot){var t=this.sourceBlock;this.svgRoot=w(I.G,{class:`blocklyIconGroup`,id:this.id}),t.getSvgRoot().appendChild(this.svgRoot),this.updateSvgRootOffset(),p(this.svgRoot,`pointerdown`,this,e),this.svgRoot.tooltip=this,Hn(this.svgRoot),this.recomputeAriaContext()}}dispose(){Un(this.svgRoot),D(this.svgRoot)}getWeight(){return-1}getSize(){return new V(0,0)}setTooltip(e){this.tooltip=e??this.sourceBlock}getTooltip(){return this.tooltip}applyColour(){}updateEditable(){}updateCollapsed(){this.svgRoot&&(this.sourceBlock.isCollapsed()?this.svgRoot.style.display=`none`:this.svgRoot.style.display=`block`,Rt(this)&&this.setBubbleVisible(!1))}hideForInsertionMarker(){this.svgRoot&&(this.svgRoot.style.display=`none`)}isShownWhenCollapsed(){return!1}setOffsetInBlock(e){this.offsetInBlock=e,this.updateSvgRootOffset()}updateSvgRootOffset(){var e;(e=this.svgRoot)==null||e.setAttribute(`transform`,`translate(${this.offsetInBlock.x}, ${this.offsetInBlock.y})`)}onLocationChange(e){this.workspaceLocation=z.sum(e,this.offsetInBlock)}onClick(){}isClickableInFlyout(){return!0}getFocusableElement(){var e=this.svgRoot;if(!e)throw Error(`Attempting to focus uninitialized icon.`);return e}getFocusableTree(){return this.sourceBlock.workspace}onNodeFocus(){var e=this.sourceBlock.getBoundingRectangle();e=new B(e.top+this.offsetInBlock.y,e.top+this.offsetInBlock.y+this.getSize().height,e.left+this.offsetInBlock.x,e.left+this.offsetInBlock.x+this.getSize().width),this.sourceBlock.workspace.scrollBoundsIntoView(e)}onNodeBlur(){}canBeFocused(){return!0}performAction(){this.onClick(),wt().then(()=>{if(Rt(this)&&this.bubbleIsVisible()){let t=this.getBubble();t&&e.A().focusNode(t)}})}getSourceBlock(){return this.sourceBlock}showContextMenu(e){this.getSourceBlock().showContextMenu(e)}recomputeAriaContext(){var t=this.getFocusableElement();if(t){S(t,P.BUTTON);var n=this.getAriaLabel()??e.C.ICON_LABEL_DEFAULT;C(t,F.LABEL,n)}}getAriaLabel(){return null}};e.Yg=class extends hd{constructor(e,t){super(t),this.flyoutBlockTypes=e,this.sourceBlock=t,this.saveConnectionsListener=this.updateWorkspacePid=this.rootBlock=this.miniWorkspaceBubble=null}getType(){return e.Yg.TYPE}initView(e){this.svgRoot||(super.initView(e),w(I.RECT,{class:`blocklyIconShape`,rx:`4`,ry:`4`,height:`16`,width:`16`},this.svgRoot),w(I.PATH,{class:`blocklyIconSymbol`,d:`m4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 -0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z`},this.svgRoot),w(I.CIRCLE,{class:`blocklyIconShape`,r:`2.7`,cx:`8`,cy:`8`},this.svgRoot),T(this.svgRoot,`blocklyMutatorIcon`))}dispose(){super.dispose();var e;(e=this.miniWorkspaceBubble)==null||e.dispose()}getWeight(){return e.Yg.WEIGHT}getSize(){return new V(17,17)}applyColour(){super.applyColour();var e;(e=this.miniWorkspaceBubble)==null||e.setColour(this.sourceBlock.getColour());var t;(t=this.miniWorkspaceBubble)==null||t.updateBlockStyles()}updateCollapsed(){super.updateCollapsed(),this.sourceBlock.isCollapsed()&&this.setBubbleVisible(!1)}onLocationChange(e){super.onLocationChange(e);var t;(t=this.miniWorkspaceBubble)==null||t.setAnchorLocation(this.getAnchorLocation())}onClick(){super.onClick(),this.sourceBlock.isEditable()&&this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}bubbleIsVisible(){return!!this.miniWorkspaceBubble}setBubbleVisible(t){var n=this;return(0,j.asyncExecutePromiseGeneratorFunction)(function*(){if(n.bubbleIsVisible()!==t){if(yield wt(),t){n.miniWorkspaceBubble=new md(n.getMiniWorkspaceConfig(),n.sourceBlock.workspace,n.getAnchorLocation(),n.getBubbleOwnerRect(),n),n.applyColour(),n.createRootBlock(),n.addSaveConnectionsListener();let t;(t=n.miniWorkspaceBubble)==null||t.addWorkspaceChangeListener(n.createMiniWorkspaceChangeListener()),n.miniWorkspaceBubble.setAriaLabelProvider(e.C.WORKSPACE_LABEL_MUTATOR_WORKSPACE)}else{let e;(e=n.miniWorkspaceBubble)==null||e.dispose(),n.miniWorkspaceBubble=null,n.saveConnectionsListener&&n.sourceBlock.workspace.removeChangeListener(n.saveConnectionsListener),n.saveConnectionsListener=null}b(new(x(N.BUBBLE_OPEN))(n.sourceBlock,t,`mutator`)),n.recomputeAriaContext()}})}getBubble(){return this.miniWorkspaceBubble}getMiniWorkspaceConfig(){var e={disable:!1,media:this.sourceBlock.workspace.options.pathToMedia,rtl:this.sourceBlock.RTL,renderer:this.sourceBlock.workspace.options.renderer,rendererOverrides:this.sourceBlock.workspace.options.rendererOverrides??void 0};return this.flyoutBlockTypes.length&&(e.toolbox={kind:`flyoutToolbox`,contents:this.flyoutBlockTypes.map(e=>({kind:`block`,type:e}))}),e}getAnchorLocation(){return z.sum(this.workspaceLocation,new z(8.5,8.5))}getBubbleOwnerRect(){var e=this.sourceBlock.getSvgRoot().getBBox();return new B(e.y,e.y+e.height,e.x,e.x+e.width)}createRootBlock(){if(!this.sourceBlock.decompose)throw Error(`Blocks with mutator icons must include a decompose method`);this.rootBlock=this.sourceBlock.decompose(this.miniWorkspaceBubble.getWorkspace());for(var e of this.rootBlock.getDescendants(!1))e.queueRender();this.rootBlock.setMovable(!1),this.rootBlock.setDeletable(!1);var t,n;e=((t=this.miniWorkspaceBubble)==null||(n=t.getWorkspace())==null?void 0:n.getFlyout()?.getWidth())??0,this.rootBlock.moveBy(this.rootBlock.RTL?-(e+16):16,16)}addSaveConnectionsListener(){this.sourceBlock.saveConnections&&this.rootBlock&&(this.saveConnectionsListener=()=>{this.sourceBlock.saveConnections&&this.rootBlock&&this.sourceBlock.saveConnections(this.rootBlock)},this.saveConnectionsListener(),this.sourceBlock.workspace.addChangeListener(this.saveConnectionsListener))}createMiniWorkspaceChangeListener(){return t=>{e.Yg.isIgnorableMutatorEvent(t)||this.updateWorkspacePid||(this.updateWorkspacePid=setTimeout(()=>{this.updateWorkspacePid=null,this.recomposeSourceBlock()},0))}}static isIgnorableMutatorEvent(e){return e.isUiEvent||e.type===N.BLOCK_CREATE||e.type===N.BLOCK_CHANGE&&e.element===`disabled`}recomposeSourceBlock(){if(this.rootBlock){if(!this.sourceBlock.compose)throw Error(`Blocks with mutator icons must include a compose method`);var t=e.fd;t||e.r(!0);var n=Lc.getExtraBlockState_(this.sourceBlock);this.sourceBlock.compose(this.rootBlock);var r=Lc.getExtraBlockState_(this.sourceBlock);n!==r&&b(new(x(N.BLOCK_CHANGE))(this.sourceBlock,`mutation`,null,n,r)),e.r(t)}}getWorkspace(){return this.miniWorkspaceBubble?.getWorkspace()}getAriaLabel(){return this.bubbleIsVisible()?e.C.ICON_LABEL_MUTATOR_OPEN:e.C.ICON_LABEL_MUTATOR_CLOSED}},e.Yg.TYPE=Ic.MUTATOR,e.Yg.WEIGHT=1;var gd=Object.create(null),_d={allExtensions:gd};e.Ug(`parent_tooltip_when_inline`,function(){var e=this.tooltip;this.setTooltip(function(){var t=this.getParent();return t&&t.getInputsInline()&&t.tooltip||e}.bind(this))});var vd={TEST_ONLY:_d};vd.apply=Vr,vd.buildTooltipForDropdown=e.dh,vd.buildTooltipWithFieldText=e.fh,vd.isRegistered=Br,vd.register=e.Ug,vd.registerMixin=e.Vg,vd.registerMutator=e.Zg,vd.runAfterPageLoad=function(e){if(typeof document!=`object`)throw Error(`runAfterPageLoad() requires browser document.`);if(document.readyState===`complete`)e();else{let t=setInterval(function(){document.readyState===`complete`&&(clearInterval(t),e())},10)}},vd.unregister=function(e){Br(e)?delete gd[e]:console.warn(`No extension mapping for name "`+e+`" found to unregister`)};var yd={};yd.arc=Zr,yd.curve=Kr,yd.line=Xr,yd.lineOnAxis=A,yd.lineTo=Yr,yd.moveBy=Jr,yd.moveTo=qr,yd.point=k;var bd={};bd.Coordinate=z,bd.KeyCodes=K,bd.Rect=B,bd.Size=V,bd.Svg=I,bd.aria=$o,bd.array=ws,bd.browserEvents=No,bd.colour=Du,bd.deprecation=ps,bd.dom=as,bd.extensions=vd,bd.idGenerator=Ro,bd.math=Zl,bd.object=ls,bd.parsing=Ou,bd.string=fu,bd.style=Fs,bd.svgMath=Rs,bd.svgPaths=yd,bd.toolbox=Ys,bd.userAgent=Mo,bd.xml=Ks;var xd=class extends J{constructor(t,n,r,i){super(t,n,r,void 0,i),this.workspace=t,this.anchor=n,this.ownerRect=r,this.owner=i,this.resizePointerMoveListener=this.resizePointerUpListener=null,this.sizeChangeListeners=[],this.locationChangeListeners=[],this.DEFAULT_SIZE=new V(160+J.DOUBLE_BORDER,80+J.DOUBLE_BORDER),this.MIN_SIZE=new V(45+J.DOUBLE_BORDER,20+J.DOUBLE_BORDER),this.editable=!0,this.textChangeListener=()=>{this.recomputeAriaContext()},T(this.svgRoot,`blocklyTextInputBubble`),this.editor=new Xu(t,this.id,()=>{e.A().focusNode(this)}),this.contentContainer.appendChild(this.editor.getDom()),this.resizeGroup=this.createResizeHandle(this.svgRoot,t),this.setSize(this.DEFAULT_SIZE,!0),this.addTextChangeListener(this.textChangeListener)}getText(){return this.editor.getText()}setText(e){this.editor.setText(e)}setEditable(e){this.editable=e,this.editor.setEditable(e)}isEditable(){return this.editable}addTextChangeListener(e){this.editor.addTextChangeListener(e)}addSizeChangeListener(e){this.sizeChangeListeners.push(e)}addLocationChangeListener(e){this.locationChangeListeners.push(e)}createResizeHandle(e,t){return e=w(I.IMAGE,{class:`blocklyResizeHandle`,href:`${t.options.pathToMedia}resize-handle.svg`},e),p(e,`pointerdown`,this,this.onResizePointerDown),e}setSize(e,t=!1){e.width=Math.max(e.width,this.MIN_SIZE.width),e.height=Math.max(e.height,this.MIN_SIZE.height);var n=e.width-J.DOUBLE_BORDER,r=e.height-J.DOUBLE_BORDER;this.editor.updateSize(new V(n,r),new V(0,0)),this.editor.getDom().setAttribute(`x`,`${J.DOUBLE_BORDER/2}`),this.editor.getDom().setAttribute(`y`,`${J.DOUBLE_BORDER/2}`),this.resizeGroup.setAttribute(`y`,`${r}`),this.workspace.RTL?this.resizeGroup.setAttribute(`x`,`${-J.DOUBLE_BORDER}`):this.resizeGroup.setAttribute(`x`,`${n}`),super.setSize(e,t),this.onSizeChange()}getSize(){return super.getSize()}moveDuringDrag(e){super.moveDuringDrag(e),this.onLocationChange()}setPositionRelativeToAnchor(e,t){super.setPositionRelativeToAnchor(e,t),this.onLocationChange()}positionByRect(e=new B(0,0,0,0)){super.positionByRect(e),this.onLocationChange()}onResizePointerDown(e){this.bringToFront(),_(e)||(wr(this.workspace,e,new z(this.workspace.RTL?-this.getSize().width:this.getSize().width,this.getSize().height)),this.resizePointerUpListener=p(document,`pointerup`,this,this.onResizePointerUp),this.resizePointerMoveListener=p(document,`pointermove`,this,this.onResizePointerMove),this.workspace.hideChaff()),e.stopPropagation()}onResizePointerUp(){lo=null,this.resizePointerUpListener&&=(h(this.resizePointerUpListener),null),this.resizePointerMoveListener&&=(h(this.resizePointerMoveListener),null)}onResizePointerMove(e){e=Tr(this.workspace,e),this.setSize(new V(this.workspace.RTL?-e.x:e.x,e.y),!1),this.onSizeChange()}onSizeChange(){for(let e of this.sizeChangeListeners)e()}onLocationChange(){for(let e of this.locationChangeListeners)e()}getEditor(){return this.editor}performAction(){e.A().focusNode(this.getEditor())}dispose(){super.dispose(),this.editor.removeTextChangeListener(this.textChangeListener)}};He(`
799
+ .blocklyTextInputBubble .blocklyTextarea {
800
+ background-color: var(--commentFillColour);
801
+ border: 0;
802
+ box-sizing: border-box;
803
+ display: block;
804
+ outline: 0;
805
+ padding: 5px;
806
+ resize: none;
807
+ width: 100%;
808
+ height: 100%;
809
+ }
810
+ `);var Sd=class{constructor(e){this.connectionChecker=e,this.connections=[]}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)}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}}static init(e){var t=[];return t[U.INPUT_VALUE]=new Sd(e),t[U.OUTPUT_VALUE]=new Sd(e),t[U.NEXT_STATEMENT]=new Sd(e),t[U.PREVIOUS_STATEMENT]=new Sd(e),t}},Y=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_${y()}`}connect_(e){var t=U.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(oe()){var a=new(x(N.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=Y.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===U.INPUT_VALUE||this.type===U.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.fd;n||e.r(!0),this.isSuperior()?this.connect_(t):t.connect_(this),e.r(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.fd;if(i||e.r(!0),oe()){var a=new(x(N.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.r(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))?.connection,n=this.targetBlock(),n&&n!==e||!t||t.targetConnection===this?!1:(t.isConnected()&&t.disconnect(),t.connect(this),!0)}targetBlock(){return this.isConnected()?this.targetConnection?.getSourceBlock()??null: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()?kr(this.targetBlock()):this.shadowDom}setShadowState(e){this.setShadowStateInternal({shadowState:e})}getShadowState(e){return e&&this.targetBlock()&&this.targetBlock().isShadow()?an(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=cn(n,t.workspace,{parentConnection:e?this:void 0,isShadow:!0,recordUndo:!1});if(r){if(t=Nr(r,t.workspace),e)if(this.type===U.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===U.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=kr(e),this.shadowState=an(e))}static getConnectionForOrphanedConnection(e,t){if(t.type===U.OUTPUT_VALUE){a:{t=t.getSourceBlock();for(var n;n=Qr(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}};Y.CAN_CONNECT=0,Y.REASON_SELF_CONNECTION=1,Y.REASON_WRONG_TYPE=2,Y.REASON_TARGET_NULL=3,Y.REASON_CHECKS_FAILED=4,Y.REASON_DIFFERENT_WORKSPACES=5,Y.REASON_SHADOW_PARENT=6,Y.REASON_DRAG_CHECKS_FAILED=7,Y.REASON_PREVIOUS_AND_OUTPUT=8;var Cd=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}},wd={};wd.DuplicateIconType=Cd;var Td=e.tn||={};Td[Td.LEFT=-1]=`LEFT`,Td[Td.CENTRE=0]=`CENTRE`,Td[Td.RIGHT=1]=`RIGHT`;var Ed=class extends ku{constructor(e,t,n){super(ku.SKIP_SETUP),this.class=null,this.EDITABLE=!1,this.maxDisplayLength=1/0,e!==ku.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&&T(this.getTextElement(),this.class),this.fieldGroup_&&(T(this.fieldGroup_,`blocklyLabelField`),C(this.fieldGroup_,F.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&&E(this.textElement_,this.class),e&&T(this.textElement_,e)),this.class=e}static fromJson(e){return new this(O(e.text),void 0,e)}};Rr(`field_label`,Ed),Ed.prototype.DEFAULT_VALUE=``;var Dd,Od=Dd||={};Od[Od.UNKNOWN=0]=`UNKNOWN`,Od[Od.BEFORE=1]=`BEFORE`,Od[Od.AFTER=2]=`AFTER`,Od[Od.AROUND=3]=`AROUND`,Od[Od.INSIDE=4]=`INSIDE`,Od[Od.TO=5]=`TO`;var kd=[];kd[U.INPUT_VALUE]=U.OUTPUT_VALUE,kd[U.OUTPUT_VALUE]=U.INPUT_VALUE,kd[U.NEXT_STATEMENT]=U.PREVIOUS_STATEMENT,kd[U.PREVIOUS_STATEMENT]=U.NEXT_STATEMENT;var Ad=class extends Y{constructor(e,t){super(e,t),this.highlighted=!1,this.targetConnection=null,this.db=e.workspace.connectionDBList[t],this.dbOpposite=e.workspace.connectionDBList[kd[t]],this.offsetInBlock=new z(0,0),this.trackedState=Ad.TrackedState.WILL_TRACK}dispose(){super.dispose(),this.trackedState===Ad.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.tg.snapRadius+Math.floor(Math.random()*10),i=e.tg.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=!1;return this.trackedState===Ad.TrackedState.WILL_TRACK?(this.db.addConnection(this,t),this.trackedState=Ad.TrackedState.TRACKED,n=!0):this.trackedState===Ad.TrackedState.TRACKED&&(this.db.removeConnection(this,this.y),this.db.addConnection(this,t),n=!0),this.x=e,this.y=t,n}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=z.difference(this.offsetInBlock,e.offsetInBlock),t.translate(e.x,e.y))}closest(e,t){return this.dbOpposite.searchForClosest(this,e,t)}recomputeAriaContext(t){var n=this.type===U.INPUT_VALUE?e.C.INPUT_LABEL_VALUE:e.C.INPUT_LABEL_STATEMENT;S(t,P.FIGURE),C(t,F.ROLEDESCRIPTION,n);var r;(n=this.getParentInput()??(r=this.getSourceBlock().getTopStackBlock().previousConnection)?.targetConnection?.getParentInput())?(r=n?.getAriaLabelText()??oi(n.getSourceBlock(),n,!0).join(`, `),this.type===U.NEXT_STATEMENT?C(t,F.LABEL,e.C.INPUT_LABEL_END_STATEMENT.replace(`%1`,r)):C(t,F.LABEL,r)):C(t,F.LABEL,e.C.INPUT_LABEL_EMPTY)}highlight(){this.highlighted=!0;var e=this.findHighlightSvg();if(e){e.style.display=``;let t;(t=e.parentElement)==null||t.appendChild(e),this.recomputeAriaContext(e)}}unhighlight(){this.highlighted=!1;var e=this.findHighlightSvg();e&&(e.style.display=`none`)}isHighlighted(){return this.highlighted}setTracking(e){e&&this.trackedState===Ad.TrackedState.TRACKED||!e&&this.trackedState===Ad.TrackedState.UNTRACKED||this.sourceBlock_.isInFlyout||(e?(this.db.addConnection(this,this.y),this.trackedState=Ad.TrackedState.TRACKED):(this.trackedState===Ad.TrackedState.TRACKED&&this.db.removeConnection(this,this.y),this.trackedState=Ad.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())Rt(e)&&e.setBubbleVisible(!1)}}}startTrackingAll(){this.setTracking(!0);var e=[];if(this.type!==U.INPUT_VALUE&&this.type!==U.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.Pc){let r=e.fd;setTimeout(function(){n.isDisposed()||n.getParent()||(e.r(r),this.bumpAwayFrom(t),e.r(!1))}.bind(this),e.tg.bumpDelay)}}disconnectInternal(t=!0){var{parentConnection:n,childConnection:r}=this.getParentAndChildConnections();if(n&&r){var i=e.fd;i||e.r(!0);var a=n.getSourceBlock(),o=r.getSourceBlock();super.disconnectInternal(t),a.queueRender(),o.updateDisabled(),o.queueRender(),o.getSvgRoot().style.display=`block`,e.r(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=G.registry.getContextMenuOptions({focusedNode:this},e);if(t.length){var n=this.getSourceBlock(),r=n.workspace;if(e instanceof PointerEvent)var i=new z(e.clientX,e.clientY);else i=new z(this.x,this.y),i=rt(r,i).translate(n.RTL?-5:5,5);gr(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(),this.getSourceBlock().workspace.scrollBoundsIntoView(this.getSourceBlock().getBoundingRectangleWithoutChildren())}onNodeBlur(){this.unhighlight()}canBeFocused(){return this.findHighlightSvg()!==null}findHighlightSvg(){return this.getSourceBlock().getSvgRoot().getRootNode().getElementById(this.id)}},jd=Ad||={},Md=jd.TrackedState||={};Md[Md.WILL_TRACK=-1]=`WILL_TRACK`,Md[Md.UNTRACKED=0]=`UNTRACKED`,Md[Md.TRACKED=1]=`TRACKED`;var Nd=class{constructor(t,n){this.name=t,this.sourceBlock=n,this.fieldRow=[],this.align=e.tn.LEFT,this.visible=!0,this.ariaLabelProvider=null,this.type=e.he.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.Rg({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 Ad){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`?O(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=e[t-1].connection?.type===U.NEXT_STATEMENT;return this.connection?.type===U.NEXT_STATEMENT||n?`${this.getSourceBlock().id}-input${t}`:e[t-1].getRowId()}getLabel(e=Jo.STANDARD,t=!0){if(!this.isVisible())return``;var n=ni(this,!1,e);return t&&this.connection?.type===U.INPUT_VALUE&&(t=this.connection.targetBlock())&&!t.isInsertionMarker()&&n.push(ai(t,e).join(`, `)),n.join(`, `)}getIndex(){var t=[e.he.DUMMY,e.he.END_ROW];return this.getSourceBlock().inputList.filter(e=>!t.includes(e.type)).indexOf(this)}},Pd=class extends Nd{constructor(t,n){super(t,n),this.name=t,this.type=e.he.DUMMY}},Fd=class extends Nd{constructor(t,n){super(t,n),this.name=t,this.type=e.he.END_ROW}},Id=class extends Nd{constructor(t,n){if(!t)throw Error(`Statement inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.he.STATEMENT,this.connection=this.makeConnection(U.NEXT_STATEMENT)}};e.En=class extends Nd{constructor(t,n){if(!t)throw Error(`Value inputs must have a non-empty name`);super(t,n),this.name=t,this.type=e.he.VALUE,this.connection=this.makeConnection(U.INPUT_VALUE)}};var Ld=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:te(),e.setBlockById(this.id,this),this.xy=new z(0,0),this.isInFlyout=e.isFlyout,this.isInMutator=e.isMutator,this.RTL=e.RTL,t){if(this.type=t,n=so[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===Ld&&this.doInit_()}doInit_(){var t=e.fd;t||e.r(!0);var n=e.Pc;try{typeof this.init==`function`&&(e.Pc=!1,this.init(),e.Pc=n),oe()&&b(new(x(N.BLOCK_CREATE))(this))}finally{e.r(t),e.Pc=n}this.inputsInlineDefault=this.inputsInline,typeof this.onchange==`function`&&this.setOnChange(this.onchange)}dispose(e=!1){this.disposing=!0,this.onchangeWrapper&&this.workspace.removeChangeListener(this.onchangeWrapper),this.unplug(e),oe()&&b(new(x(N.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?.disconnect(),this.workspace.connectionChecker.canConnect(e,t,!1)?t.connect(e):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===U.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;e=((r=e.previousConnection)==null||(i=r.targetBlock())==null?void 0:i.nextConnection?.targetConnection)??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_?Ve(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(Le(this,!0)):!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=this.inputList[0]?.fieldRow[0];return e!=null&&e.isFullBlockField()?e: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 zn(this)}getColour(){return this.colour_}getStyleName(){return this.styleName_}getHue(){return this.hue}setColour(e){e=or(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_(U.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_(U.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_(U.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(N.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 Pd&&this.inputList[t]instanceof Pd)return!1;for(t=1;t<this.inputList.length;t++)if(this.inputList[t-1]instanceof e.En&&this.inputList[t]instanceof Pd)return!0;for(t=0;t<this.inputList.length;t++)if(this.inputList[t]instanceof Fd)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(N.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(N.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():O(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.En(t,this))}appendStatementInput(e){return this.statementInputCount++,this.appendInput(new Id(e,this))}appendDummyInput(e=``){return this.appendInput(new Pd(e,this))}appendEndRowInput(e=``){return this.appendInput(new Fd(e,this))}appendInput(e){return this.inputList.push(e),e}appendInputFromRegistry(e,t){return(e=r(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.Ka++,this.setInputsInline(t.inputsInline),e.Ka--),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=O(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=O(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&&Vr(t.mutator,this,!0),t=t.extensions,Array.isArray(t))for(n=0;n<t.length;n++)Vr(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=ar(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===`
811
+ `)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.Rg(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.tn.LEFT,RIGHT:e.tn.RIGHT,CENTRE:e.tn.CENTRE,CENTER:e.tn.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`||i(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 Id&&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(){return this.getIcon(Ic.COMMENT)?.getText()??null}setCommentText(t){var n,i=(n=this.getIcon(Ic.COMMENT))?.getText()??null;if(i!==t){if(t!==null){if(n=this.getIcon(Ic.COMMENT),!n){if(n=r(M.ICON,Ic.COMMENT.toString(),!1),!n)throw Error(`No comment icon class is registered, so a comment cannot be set`);if(n=new n(this),!(mi(n)&&Rt(n)&&St(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()===Ic.COMMENT))throw Error(`The class registered as a comment icon does not conform to the ICommentIcon interface`);n=this.addIcon(n)}e.Ka++,n.setText(t),e.Ka--}else this.removeIcon(Ic.COMMENT);b(new(x(N.BLOCK_CHANGE))(this,`comment`,null,i,t))}}setWarningText(){}setMutator(){}addIcon(e){if(this.hasIcon(e.getType()))throw new Cd(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 Ic?this.icons.find(t=>t.getType().equals(e)):this.icons.find(t=>t.getType().toString()===e)}getIcons(){return[...this.icons]}getRelativeToSurfaceXY(){return this.xy}moveBy(e,t,n){if(this.parentBlock_)throw Error(`Block has parent`);var r=new(x(N.BLOCK_MOVE))(this);n&&r.setReason(n),this.xy.translate(e,t),r.recordNew(),b(r)}makeConnection_(e){return new Y(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):!0}toDevString(){var e=this.type?`"`+this.type+`" block`:`Block`;return this.id&&(e+=` (id="`+this.id+`")`),e}};Ld.COLLAPSED_INPUT_NAME=`_TEMP_COLLAPSED_INPUT`,Ld.COLLAPSED_FIELD_NAME=`_TEMP_COLLAPSED_FIELD`;var Rd=null,zd=null,Bd={};Bd.connectionUiEffect=_i,Bd.disconnectUiEffect=vi,Bd.disconnectUiStop=bi,Bd.disposeUiEffect=hi;var Vd=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 z(t.blockState.x||0,t.blockState.y||0),e.Ka++;try{var i=sn(t.blockState,n);xi(i,r)}finally{e.Ka--}if(!i)return i;oe()&&!i.isShadow()&&b(new(x(N.BLOCK_CREATE))(i));var a=i;return wt().then(()=>e.A().focusNode(a)),i}};Vd.TYPE=`block`,yt(Vd.TYPE,new Vd);var Hd={};Hd.bumpIntoBounds=wi,Hd.bumpIntoBoundsHandler=Ti,Hd.bumpTopObjectsIntoBounds=Ei;var Ud=null,Wd=null,Gd=void 0,Kd={};Kd.BlockPaster=Vd,Kd.copy=Di,Kd.getLastCopiedData=function(){return Ud},Kd.getLastCopiedLocation=function(){return Gd},Kd.getLastCopiedWorkspace=function(){return Wd},Kd.paste=Oi,Kd.registry=fc,Kd.setLastCopiedData=function(e){Ud=e},Kd.setLastCopiedLocation=function(e){Gd=e},Kd.setLastCopiedWorkspace=function(e){Wd=e};var qd={};qd.CollapseCommentBarButton=Yu,qd.CommentBarButton=Ju,qd.CommentEditor=Xu,qd.CommentView=Qu,qd.DeleteCommentBarButton=Zu,qd.RenderedWorkspaceComment=ed,qd.WorkspaceComment=$u;var Jd=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 z(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=y(),this.svgGroup=w(I.G,{id:this.id,class:t},this.workspace.getCanvas()),!this.isFlyoutLabel){var a=w(I.RECT,{class:`blocklyFlyoutButtonShadow`,rx:Jd.BORDER_RADIUS,ry:Jd.BORDER_RADIUS,x:1,y:1},this.svgGroup);S(a,P.PRESENTATION)}t=w(I.RECT,{class:this.isFlyoutLabel?`blocklyFlyoutLabelBackground`:`blocklyFlyoutButtonBackground`,rx:Jd.BORDER_RADIUS,ry:Jd.BORDER_RADIUS},this.svgGroup),S(t,P.PRESENTATION),n=w(I.TEXT,{class:this.isFlyoutLabel?`blocklyFlyoutLabelText`:`blocklyText`,x:0,y:0,"text-anchor":`middle`},this.svgGroup),r=O(this.text),this.workspace.RTL&&(r+=`‏`),n.textContent=r,this.isFlyoutLabel&&(this.svgText=n,this.workspace.getThemeManager().subscribe(this.svgText,`flyoutForegroundColour`,`fill`)),S(n,P.PRESENTATION),i=`${r}, ${this.isFlyoutLabel?e.C.ARIA_LABEL_HEADING:e.C.ARIA_LABEL_BUTTON}`,C(this.getFocusableElement(),F.LABEL,i),S(this.getFocusableElement(),P.LISTITEM),i=Ke(n,`fontSize`);var o=Ke(n,`fontWeight`),s=Ke(n,`fontFamily`);if(this.width=be(n,i,o,s),r=xe(r,i,o,s),this.height=this.height||r.height,!this.isFlyoutLabel){this.width+=2*Jd.TEXT_MARGIN_X,this.height+=2*Jd.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=p(this.svgGroup,`pointerdown`,this,this.onMouseDown),this.onMouseUpWrapper=p(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 B(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(){h(this.onMouseDownWrapper),h(this.onMouseUpWrapper),this.svgGroup&&D(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 B(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`,fn(X.NEXT_HEADING));Tc.show(t,{message:n,id:`flyoutLabelHint`})}else(t=this.targetWorkspace.getButtonCallback(this.callbackKey))&&t(this)}};Jd.TEXT_MARGIN_X=5,Jd.TEXT_MARGIN_Y=2,Jd.BORDER_RADIUS=4,He(`
812
+ .blocklyFlyoutButton {
813
+ fill: #888;
814
+ cursor: default;
815
+ }
816
+
817
+ .blocklyFlyoutButtonShadow {
818
+ fill: #666;
819
+ }
820
+
821
+ @media (hover: hover) {
822
+ .blocklyFlyoutButton:hover {
823
+ fill: #aaa;
824
+ }
825
+ }
826
+
827
+ .blocklyFlyoutButton:active {
828
+ fill: #aaa;
829
+ }
830
+
831
+ .blocklyFlyoutLabel {
832
+ cursor: default;
833
+ }
834
+
835
+ .blocklyFlyoutLabelBackground {
836
+ opacity: 0;
837
+ }
838
+ `);var Yd,Xd=Yd||={};Xd[Xd.COMMIT=1]=`COMMIT`,Xd[Xd.DELETE=2]=`DELETE`,Xd[Xd.REVERT=3]=`REVERT`;var X,Z=X||={};Z.ESCAPE=`escape`,Z.DELETE=`delete`,Z.COPY=`copy`,Z.CUT=`cut`,Z.PASTE=`paste`,Z.UNDO=`undo`,Z.REDO=`redo`,Z.MENU=`menu`,Z.FOCUS_WORKSPACE=`focus_workspace`,Z.FOCUS_TOOLBOX=`focus_toolbox`,Z.START_MOVE=`start_move`,Z.START_MOVE_STACK=`start_move_stack`,Z.FINISH_MOVE=`finish_move`,Z.ABORT_MOVE=`abort_move`,Z.MOVE_UP=`move_up`,Z.MOVE_DOWN=`move_down`,Z.MOVE_LEFT=`move_left`,Z.MOVE_RIGHT=`move_right`,Z.NAVIGATE_RIGHT=`right`,Z.NAVIGATE_LEFT=`left`,Z.NAVIGATE_UP=`up`,Z.NAVIGATE_DOWN=`down`,Z.DISCONNECT=`disconnect`,Z.NEXT_STACK=`next_stack`,Z.PREVIOUS_STACK=`previous_stack`,Z.INFORMATION=`information`,Z.EXTENDED_INFORMATION=`extended_information`,Z.PERFORM_ACTION=`perform_action`,Z.DUPLICATE=`duplicate`,Z.CLEANUP=`cleanup`,Z.SHOW_TOOLTIP=`show_tooltip`,Z.NEXT_HEADING=`next_heading`,Z.PREVIOUS_HEADING=`previous_heading`,Z.TOGGLE_SCREENREADER=`toggle_screenreader`;var Zd=e=>{if(e.isFlyout){let t=e.targetWorkspace;if(t)return Zd(t)}return e.getRootWorkspace()??e};na(),ra(),ia();var Qd={};Qd.names=X,Qd.registerArrowNavigation=Ui,Qd.registerCleanup=$i,Qd.registerCopy=Ii,Qd.registerCut=Li,Qd.registerDefaultShortcuts=na,Qd.registerDelete=Pi,Qd.registerDisconnectBlock=Ji,Qd.registerDuplicate=Qi,Qd.registerEscape=Ni,Qd.registerFocusToolbox=Gi,Qd.registerFocusWorkspace=Wi,Qd.registerHeadingNavigation=Xi,Qd.registerKeyboardNavigationShortcuts=ra,Qd.registerMovementShortcuts=Vi,Qd.registerPaste=Ri,Qd.registerPerformAction=Zi,Qd.registerReadExtendedInformation=qi,Qd.registerReadInformation=Ki,Qd.registerRedo=Bi,Qd.registerScreenReaderShortcuts=ia,Qd.registerShowContextMenu=Hi,Qd.registerShowTooltip=ea,Qd.registerStackNavigation=Yi,Qd.registerToggleScreenreaderMode=ta,Qd.registerUndo=zi;var $d,ef=$d||={};ef[ef.CONSTRAINED=1]=`CONSTRAINED`,ef[ef.UNCONSTRAINED=2]=`UNCONSTRAINED`;var tf=class{constructor(e){this.block=e,this.connectionPreviewer=this.connectionCandidate=this.startLoc=this.startChildConn=this.startParentConn=null,this.dragging=!1,this.allConnectionPairs=[],this.moveMode=$d.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=rt(t.workspace,t.getRelativeToSurfaceXY()),t=nt(n.workspace,t),n.moveDuringDrag(t),this.moveMode===$d.CONSTRAINED){var r=n.workspace,i=this.WORKSPACE_MARGIN;t=this.WORKSPACE_MARGIN;var a=Math.max(e.tg.connectingSnapRadius,e.tg.snapRadius)+2,o=r.getTopBlocks(!0).filter(e=>e.id!==n.id).map(e=>(e=e.getBoundingRectangle(),new B(e.top-a,e.bottom+a,e.left-a,e.right+a))),s,c=(s=r.getToolbox())?.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 f=l(d);f!=null;)u=f.left+f.getWidth()+80,f=f.top+f.getHeight()+r,u+c<=s||(i=f,u=t),n.moveBy(u-d.left,i-d.top,[`cleanup`]),d=n.getBoundingRectangle(),f=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=an(t)))return t=cn(t,this.block.workspace.targetWorkspace,{recordUndo:!0}),e.Pc=!1,this.positionNewBlock(this.block,t),e.Pc=!0,t;return this.block}announceMove(t=!1){if(this.connectionCandidate)t=di(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)}fe(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(s(M.CONNECTION_PREVIEWER,this.workspace.options))(this.block),_e(),this.workspace.setResizesEnabled(!1),bi(),t=this.shouldHealStack(e),this.storeInitialConnections(t),this.shouldDisconnect(t)&&this.disconnectBlock(t),this.block.setDragging(!0),this.enableAllDraggedBlocks(this.block),e instanceof KeyboardEvent?(this.cacheAllConnectionPairs(),this.updateConnectionPreview(this.block,new z(0,0))&&this.block.moveDuringDrag(this.determineConnectionOffset()),this.allConnectionPairs.length?oa(this.workspace):aa(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=>Rt(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):!1}shouldDisconnect(e){return!!(this.block.getParent()||e&&this.block.nextConnection&&this.block.nextConnection.targetBlock())}disconnectBlock(e){this.block.unplug(e),vi(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?.targetConnection,e&&t&&(this.connectionCandidate={local:e,neighbour:t,distance:0}),this.startChildConn=t??null)}fireDragStartEvent(){b(new(x(N.BLOCK_DRAG))(this.block,!0,this.block.getDescendants(!1)))}fireDragEndEvent(){b(new(x(N.BLOCK_DRAG))(this.block,!1,this.block.getDescendants(!1)))}fireMoveEvent(){if(!this.block.isDeadOrDying()){var e=new(x(N.BLOCK_MOVE))(this.block);e.setReason([`drag`]),e.oldCoordinate=this.startLoc,e.recordNew(),b(e)}}drag(e,t){if(this.updateMoveMode(t),this.moveMode===$d.UNCONSTRAINED&&this.block.moveDuringDrag(e),t=!!this.connectionCandidate,this.updateConnectionPreview(this.block,z.difference(e,this.startLoc)),this.connectionCandidate)this.moveMode===$d.CONSTRAINED&&this.block.moveDuringDrag(this.determineConnectionOffset());else if(this.moveMode===$d.CONSTRAINED&&(this.allConnectionPairs.length||aa(this.workspace,!0),!t)){this.workspace.getAudioManager().playErrorBeep();return}this.announceMove()}determineConnectionOffset(){var{local:e,neighbour:t}=this.connectionCandidate,n=this.startLoc.x+(t.x-e.x),r=this.startLoc.y+(t.y-e.y),i=this.BLOCK_CONNECTION_OFFSET;return e.type===U.PREVIOUS_STATEMENT||e.type===U.OUTPUT_VALUE?(n+=i,r+=i):(n-=i,r-=i),new z(n,r)}updateConnectionPreview(e,t){var n=this.connectionCandidate,r=this.getInitialCandidate()??this.getConnectionCandidate(t);if(r){var i=n&&this.currCandidateIsBetter(n,t,r)?n:r;this.connectionCandidate=i;var{local:a,neighbour:o}=i;i=a.type===U.OUTPUT_VALUE||a.type===U.PREVIOUS_STATEMENT;var s,c=o.isConnected()&&!((s=o.targetBlock())!=null&&s.isInsertionMarker());if(i&&c&&!this.orphanCanConnectAtEnd(e,o.targetBlock(),a.type)){var l;(l=this.connectionPreviewer)==null||l.previewReplacement(a,o,o.targetBlock())}else{var u;(u=this.connectionPreviewer)==null||u.previewConnection(a,o)}return o}if(this.moveMode===$d.CONSTRAINED){if(l=n?.neighbour.getSourceBlock(),s=l?.getRootBlock()??l,s===e&&(s=l),l=this.getDirectionToNewLocation(z.sum(this.startLoc,t)),(c=s)==null||!c.getBoundingRectangle())return;switch(u=e.workspace.getTopBlocks().map(e=>e.getBoundingRectangle()),s=Math.min(...u.map(e=>e.left)),l){case od.LEFT:case od.UP:l=Math.min(...u.map(e=>e.top)),s=new z(s,l-this.BLOCK_CONNECTION_OFFSET*2-e.getHeightWidth().height);break;default:l=Math.max(...u.map(e=>e.bottom)),s=new z(s,l+this.BLOCK_CONNECTION_OFFSET*2)}e.moveDuringDrag(s)}(i=this.connectionPreviewer)==null||i.hidePreview(),this.connectionCandidate=null}orphanCanConnectAtEnd(e,t,n){return!!Y.getConnectionForOrphanedConnection(e,n===U.OUTPUT_VALUE?t.outputConnection:t.previousConnection)}currCandidateIsBetter(t,n,r){if(this.moveMode===$d.CONSTRAINED)return!1;var{local:i,neighbour:a}=t;t=new z(i.x,i.y);var o=new z(a.x,a.y);return n=z.distance(z.sum(t,n),o),r.distance>n-e.tg.currentConnectionPreference}getConnectionCandidate(e){return this.moveMode===$d.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===$d.CONSTRAINED?1/0:this.connectionCandidate?e.tg.connectingSnapRadius:e.tg.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===Yd.DELETE&&hi(this.block),this.originalEventGroup=e.fd,this.fireDragEndEvent(),this.fireMoveEvent(),ve(),bi();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=>this.workspace.getLayerManager()?.moveOffDragLayer(e,100,!1)),this.block.setDragging(!1),this.redisableAllDraggedBlocks(this.block)}this.connectionCandidate?(this.applyConnections(this.connectionCandidate),this.disposeStep()):(n!==Yd.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.fd;e.r(this.originalEventGroup),this.block.snapToGrid();var n;(n=this.connectionPreviewer)==null||n.dispose(),this.workspace.setResizesEnabled(!0),e.r(t)}applyConnections(e){var{local:t,neighbour:n}=e;t.connect(n);var r=t.isSuperior()?n:t,i=this.block.getRootBlock();wt().then(()=>{_i(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 U.INPUT_VALUE:this.block.outputConnection&&this.startParentConn.connect(this.block.outputConnection);break;case U.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=>this.workspace.getLayerManager()?.moveOffDragLayer(e,100,!1)),wi(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,fe(e.C.ANNOUNCE_MOVE_CANCELED)}findTraversalCandidate(e){var t=this.getDirectionToNewLocation(z.sum(this.startLoc,e)),n=this.allConnectionPairs;if(t===od.NONE||!n.length)return this.connectionCandidate;t=t===od.RIGHT||t===od.DOWN;var r=n.findIndex(e=>this.connectionCandidate?.local===e.local&&this.connectionCandidate?.neighbour===e.neighbour),i=this.block.workspace.getNavigator();return t?r===-1?this.isInTerminalPosition(this.block,od.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,od.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===od.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=z.difference(e,t);var{x:n,y:r}=e;return n<0?od.LEFT:n>0?od.RIGHT:r<0?od.UP:r>0?od.DOWN:od.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(`.${cs.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)?.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?$d.CONSTRAINED:$d.UNCONSTRAINED}enableAllDraggedBlocks(t){var n=e.Pc;e.Pc=!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.Pc=n}redisableAllDraggedBlocks(t){var n=e.Pc;e.Pc=!1,t.getDescendants(!1).forEach(e=>{var t;(t=this.lastBlockDisabledReasons.get(e.id))==null||t.forEach(t=>{e.setDisabledReason(!0,t)})}),e.Pc=n}},nf=class extends J{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(),T(this.svgRoot,`blocklyTextBubble`)}getText(){return this.text}setText(e){this.text=e,D(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 w(I.G,{class:`blocklyText blocklyBubbleText blocklyNoPointerEvents`,transform:`translate(0,${J.BORDER_WIDTH})`,style:`direction: ${this.workspace.RTL?`rtl`:`ltr`}`},e)}createTextFragments(e,t){var n=1;return t.split(`
839
+ `).map(t=>{var r=w(I.TEXT,{y:`${n}em`,x:J.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+J.BORDER_WIDTH}`)}updateBubbleSize(){var e=this.paragraph.getBBox();this.setSize(new V(e.width+J.BORDER_WIDTH*2,e.height+J.BORDER_WIDTH*2),!0)}},rf=class extends hd{constructor(e){super(e),this.sourceBlock=e,this.textMap=new Map,this.textBubble=null}getType(){return rf.TYPE}initView(e){this.svgRoot||(super.initView(e),w(I.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),w(I.PATH,{class:`blocklyIconSymbol`,d:`m7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z`},this.svgRoot),w(I.RECT,{class:`blocklyIconSymbol`,x:`7`,y:`11`,height:`2`,width:`2`},this.svgRoot),T(this.svgRoot,`blocklyWarningIcon`))}dispose(){super.dispose();var e;(e=this.textBubble)==null||e.dispose()}getWeight(){return rf.WEIGHT}getSize(){return new V(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(`
840
+ `)}onClick(){super.onClick(),this.setBubbleVisible(!this.bubbleIsVisible())}isClickableInFlyout(){return!1}bubbleIsVisible(){return!!this.textBubble}setBubbleVisible(t){var n=this;return(0,j.asyncExecutePromiseGeneratorFunction)(function*(){if(n.bubbleIsVisible()!==t){if(yield wt(),t)n.textBubble=new nf(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(N.BUBBLE_OPEN))(n.sourceBlock,t,`warning`)),n.recomputeAriaContext()}})}getBubble(){return this.textBubble}getAnchorLocation(){return z.sum(this.workspaceLocation,new z(8.5,8.5))}getBubbleOwnerRect(){var e=this.sourceBlock.getSvgRoot().getBBox();return new B(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}};rf.TYPE=Ic.WARNING,rf.WEIGHT=2;var af=class extends Ld{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 z(0,0),this.dragStrategy=new tf(this),!e.rendered)throw TypeError(`Cannot create a rendered block in a headless workspace`);this.workspace=e,this.svgGroup=w(I.G,{}),t&&T(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,Hn(e),this.svgGroup.setAttribute(`data-id`,this.id),e.id=y(),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())&&p(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(),Ne(this)}unselect(){this.removeSelect(),Ne(null)}setParent(t){var n=this.parentBlock_;if(t!==n){_e(),super.setParent(t),ve();var r=this.getSvgRoot();if(!this.workspace.isClearing&&r){var i=this.getRelativeToSurfaceXY(),a=e.A().getFocusedNode(),o,s=this.getSvgRoot().contains((o=a?.getFocusableElement())??null);t?(t.getSvgRoot().appendChild(r),s&&a&&e.A().focusNode(a)):n&&(t=this.workspace.getCanvas().querySelector(`.blocklyDragging`),n=t?.parentElement,o=this.workspace.getCanvas(),n===o?o.insertBefore(r,t):(o.appendChild(r),s&&a&&e.A().focusNode(a)),this.translate(i.x,i.y)),this.applyColour()}}}getRelativeToSurfaceXY(){var e=this.workspace.getLayerManager();if(!e)throw Error(`Cannot calculate position because the workspace has not been appended`);var t=0,n=0,r=this.getSvgRoot();if(r)do{let e=Qe(r);t+=e.x,n+=e.y,r=r.parentNode}while(r&&!e.hasLayer(r));return new z(t,n)}moveBy(e,t,n){if(this.parentBlock_)throw Error(`Block has parent`);var r=oe(),i=null;r&&(i=new(x(N.BLOCK_MOVE))(this),n&&i.setReason(n)),e=new z(e,t),t=this.getRelativeToSurfaceXY(),e=z.sum(t,e),this.translate(e.x,e.y),this.updateComponentLocations(e),r&&i&&(i.recordNew(),b(i)),this.workspace.resizeContents()}translate(e,t){this.translation=`translate(${e}, ${t})`,this.relativeCoords=new z(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 B(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(rf.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?(T(this.svgGroup,`blocklyCollapsed`),this.childHasWarning()&&this.setWarningText(e.C.COLLAPSED_WARNINGS_WARNING,af.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 Ed(t),`_TEMP_COLLAPSED_FIELD`),this.recomputeAriaContext())):(this.updateDisabled(),this.removeInput(`_TEMP_COLLAPSED_INPUT`),E(this.svgGroup,`blocklyCollapsed`),this.setWarningText(null,af.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=G.registry.getContextMenuOptions({block:this,focusedNode:this},e),this.customContextMenu&&this.customContextMenu(e),e)}calculateContextMenuLocation(e){if(e instanceof PointerEvent)return new z(e.clientX,e.clientY);e=rt(this.workspace,this.getRelativeToSurfaceXY());var t=this.inputList.filter(e=>e.isVisible()).flatMap(e=>e.fieldRow).find(e=>e.isVisible())?.getSvgRoot()?.getBoundingClientRect();return new z(this.RTL?e.x-5:e.x+5,(t&&t.height?t.y+t.height:e.y+this.height)+5)}showContextMenu(e){var t=this.generateContextMenu(e),n=this.calculateContextMenuLocation(e);t&&t.length&&(gr(e,t,this.RTL,this.workspace,n),zu=this)}updateComponentLocations(e){this.dragging||this.updateConnectionLocations(e),this.updateIconLocations(e),this.updateFieldLocations(e);for(let t of this.getChildren(!1))t.updateComponentLocations(z.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){T(this.svgGroup,e)}removeClass(e){E(this.svgGroup,e)}setDragging(e){(this.dragging=e)?(this.translation=``,gs.push(...this.getConnections_(!0)),this.addClass(`blocklyDragging`)):(gs.length=0,this.removeClass(`blocklyDragging`));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?E(this.svgGroup,`blocklyNotEditable`):T(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,qn(),br(),n&&(this.unplug(t),hi(this));var r=e.A();if(n=r.getFocusedNode()?.getFocusableElement()??null,super.dispose(!!t),D(this.svgGroup),this.getSvgRoot().contains(n)){let e=this.getParent();e||(t=this.outputConnection??this.previousConnection)&&(e=t.closest(0,new z(0,0)).connection?.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.A().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.r(!0),this.workspace.hideChaff(),this.outputConnection?this.dispose(!1,!0):this.dispose(!0,!0),e.r(!1))}toCopyData(e=!1){return this.isInsertionMarker_?null:{paster:Vd.TYPE,blockState:an(this,{addCoordinates:!0,addNextBlocks:e,saveIds:!1}),typeCounts:Le(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(rf.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,af.COLLAPSED_WARNING_ID),r?r.addMessage(t,n):this.addIcon(new rf(this).addMessage(t,n))}else r&&(n?(r.addMessage(``,n),r.getText()||this.removeIcon(rf.TYPE)):this.removeIcon(rf.TYPE))}setMutator(t){this.removeIcon(e.Yg.TYPE),t&&this.addIcon(t)}addIcon(t){return super.addIcon(t),t instanceof e.Yg&&(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.A().focusNode(t))}}removeIcon(t){var n=super.removeIcon(t);return t.equals(e.Yg.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?E(this.svgGroup,`blocklyNotDeletable`):T(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_&&E(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(),T(this.svgGroup,e),this.styleName_=e}else throw Error(`Invalid style name: `+e)}getStyle(){return this.style}bringToFront(t=!1){var n=e.A().getFocusedNode(),r=this;if(!r.isDeadOrDying()){do{let e=r.getSvgRoot(),n=e.parentNode,i=n.childNodes;if(i[i.length-1]!==e&&n.appendChild(e),t)break;r=r.getParent()}while(r);n&&e.A().focusNode(n)}}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 Ad(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.tg.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===U.NEXT_STATEMENT||e.type===U.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 Ct(this)}render(){this.queueRender(),Tt()}renderEfficiently(){_e(),this.isCollapsed()&&this.updateCollapsed(),this.isEnabled()||this.updateDisabled(),this.workspace.getRenderer().render(this),this.tightenChildrenEfficiently(),ve()}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`},an(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();var t=e.A().getFocusedNode();t&&t!==this&&wt().then(()=>{this.workspace.scrollBoundsIntoView(this.getBoundingRectangleWithoutChildren())})}onNodeBlur(){this.unselect()}canBeFocused(){return!0}performAction(t){if(this.workspace.isFlyout)cd.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=fn(t.RTL?X.NAVIGATE_LEFT:X.NAVIGATE_RIGHT),n=e.C.KEYBOARD_NAV_BLOCK_NAVIGATION_HINT.replace(`%1`,n),Tc.show(t,{message:n,id:`blockNavigationHint`})):(t=this.workspace,(n=fn(`list_shortcuts`))&&(n=e.C.HELP_PROMPT.replace(`%1`,n),Tc.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=this.outputConnection?.targetBlock();t;)e.add(t),t=t.outputConnection?.targetBlock();return e}getRowId(){var e=this.outputConnection?.targetConnection?.getParentInput();return e?e.getRowId():this.id}recomputeAriaContext(){if(!this.getFullBlockField()){C(this.getFocusableElement(),F.LABEL,this.getAriaLabel(Jo.STANDARD)),S(this.getSvgRoot(),P.PRESENTATION);let e=this.getFocusableElement();this.isInFlyout||S(e,P.FIGURE),C(e,F.ROLEDESCRIPTION,this.getAriaRoleDescription())}}getAriaLabel(e){return ti(this,e)}getStackBlocksCountLabel(){for(var t=1,n=this.getNextBlock();n;)t++,n=n.getNextBlock();return t<=1?ti(this,Jo.TERSE):e.C.BLOCK_LABEL_STACK_BLOCKS.replace(`%1`,t.toString())}};af.INLINE=-1,af.COLLAPSED_WARNING_ID=`TEMP_COLLAPSED_WARNING_`;var of=class{constructor(){}onDragEnter(){}onDragOver(){}onDragExit(){}onDrop(){}getClientRect(){return null}shouldPreventMove(){return!1}},sf=class extends of{constructor(){super(),this.wouldDelete_=!1}wouldDelete(e){return cd.mover.isMoving()?this.updateWouldDelete_(!1):e instanceof af?(e=!e.getParent()&&e.isDeletable(),this.updateWouldDelete_(e)):this.updateWouldDelete_(ji(e)&&e.isDeletable()),this.wouldDelete_}updateWouldDelete_(e){this.wouldDelete_=e}},cf=class{constructor(e,t){this.element=e,this.type=t}getElement(){return this.element}getType(){return this.type}},lf=class{constructor(e){this.workspace_=e}getDimensionsPx_(e){var t=0,n=0;return e&&(t=e.getWidth(),n=e.getHeight()),new V(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===H.TOP;return a===H.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===H.LEFT||a===H.RIGHT;return(a===H.TOP||a===H.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}}};t(M.METRICS_MANAGER,`default`,lf);var uf=class extends lf{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}}},df=class{constructor(e,t){this.gap=e,this.axis=t,this.y=this.x=0}getBoundingRectangle(){switch(this.axis){case`x`:return new B(this.y,this.y,this.x,this.x+this.gap);case`y`:return new B(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}},ff=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 Jd}},pf=class{getFirstChild(){return null}getParent(){return null}getNextSibling(){return null}getPreviousSibling(){return null}getRowId(){return`error`}isNavigable(){return!1}isApplicable(e){return e instanceof df}},mf=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 af}},hf=class{getFirstChild(){return null}getParent(e){return e.getOwner()??null}getNextSibling(e){return ca(e.getOwner()?.getSourceBlock(),e,1)}getPreviousSibling(e){return ca(e.getOwner()?.getSourceBlock(),e,-1)}getRowId(e){return e.getOwner()?.getSourceBlock()?.getRowId()??``}isNavigable(e){return e.canBeFocused()}isApplicable(e){return e instanceof J}},gf=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 Ju}},_f=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 Xu}},vf=class{getFirstChild(){return null}getParent(e){return e.getSourceBlock()}getNextSibling(e){if(e.getParentInput())return ca(e.getSourceBlock(),e,1);if(e.type===U.NEXT_STATEMENT&&e.getSourceBlock().getSurroundParent()&&!e.targetConnection)return ca(e.getSourceBlock().getSurroundParent(),e,1);switch(e.type){case U.NEXT_STATEMENT:return e.targetConnection;case U.PREVIOUS_STATEMENT:case U.OUTPUT_VALUE:return e.getSourceBlock()}return null}getPreviousSibling(e){if(e.getParentInput())return ca(e.getParentInput().getSourceBlock(),e,-1);switch(e.type){case U.NEXT_STATEMENT:return e.getSourceBlock();case U.PREVIOUS_STATEMENT:case U.OUTPUT_VALUE:return e.targetConnection}return null}getRowId(e){switch(e.type){case U.NEXT_STATEMENT:case U.PREVIOUS_STATEMENT:return e.id;case U.INPUT_VALUE:return e.getParentInput().getRowId();default:return e.getSourceBlock().getRowId()}}isNavigable(e){return e.canBeFocused()?e.type===U.NEXT_STATEMENT?e.targetBlock()?!1:e!==(e.getSourceBlock().getRootBlock()??e.getSourceBlock()).lastConnectionInStack(!1):e.type===U.INPUT_VALUE&&!e.targetBlock():!1}isApplicable(e){return e instanceof Ad}},yf=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 ku}},bf=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 hd}},xf=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 ed}},Sf=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 Sp}},Cf,wf=Cf||={};wf[wf.NEXT=0]=`NEXT`,wf[wf.PREVIOUS=1]=`PREVIOUS`,wf[wf.IN=2]=`IN`,wf[wf.OUT=3]=`OUT`;var Tf=class{constructor(){this.rules=[new mf,new yf,new vf,new Sf,new bf,new xf,new gf,new hf,new _f],this.navigationLoops=!0}addNavigationPolicy(e){this.rules.push(e)}get(e){return this.rules.find(t=>t.isApplicable(e))}getFirstChild(e){var t=this.get(e)?.getFirstChild(e);return t?this.isNavigable(t)?t:this.getFirstChild(t)||this.getNextSibling(t):null}getParent(e){var t=this.get(e)?.getParent(e);return t?this.isNavigable(t)?t:this.getParent(t):null}getNextSibling(e){var t=this.get(e)?.getNextSibling(e);return t?this.isNavigable(t)?t:this.getNextSibling(t):null}getPreviousSibling(e){var t=this.get(e)?.getPreviousSibling(e);return t?this.isNavigable(t)?t:this.getPreviousSibling(t):null}getPreviousNode(t=e.A().getFocusedNode()){if(!t)return null;var n=this.getPreviousNodeImpl(t,t,Cf.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.A().getFocusedNode()){return this.getPreviousNodeImpl(t,t,Cf.OUT)}getNextNode(t=e.A().getFocusedNode()){var n=this.getNextNodeImpl(t,t,Cf.NEXT);return t&&n===null?this.navigateStacks(t,1):n}getInNode(t=e.A().getFocusedNode()){return this.getNextNodeImpl(t,t,Cf.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=e.A().getFocusedTree()?.getRootFocusableNode();return t?this.getTopLevelItems(t)[0]:null}getLastNode(){var t=e.A().getFocusedTree()?.getRootFocusableNode();return t?this.getTopLevelItems(t).slice(-1)[0]:null}transitionAllowed(e,t,n){switch(n){case Cf.IN:case Cf.OUT:return this.getRowId(e)===this.getRowId(t);case Cf.NEXT:case Cf.PREVIOUS:return this.getRowId(e)!==this.getRowId(t)}}getLeftmostSibling(e){if(!e)return null;for(var t;t=this.getPreviousNodeImpl(e,e,Cf.OUT);)e=t;return e}getLastNodeInStack(e,t){for(var n;(n=this.getNextNodeImpl(e,e,Cf.NEXT))&&n!==t;)e=n;return e}getRowId(e){return this.get(e)?.getRowId(e)}navigateStacks(e,t){var n=this.getTopLevelItems(e),r=this.getSourceBlockFromNode(e)?.getRootBlock()??e;return e=n.indexOf(r)+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){return this.get(e)?.isNavigable(e)}getSourceBlockFromNode(e){return e instanceof af?e:e instanceof ku||e instanceof Ad||e instanceof hd?e.getSourceBlock():null}},Ef=class{getFirstChild(e){return la(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())&&la(e)?e.isExpanded()&&this.allParentsExpanded(e):!0}isApplicable(e){return $r(e)}},Df=class extends Tf{constructor(e){super(),this.toolbox=e,this.rules=[new Ef]}getInNode(t=e.A().getFocusedNode(),n=!1){var r=ua(this.toolbox.getWorkspace());if(!n)switch(r){case H.TOP:case H.BOTTOM:return this.getNextNode(t,!0);case H.RIGHT:return this.getOutNode(t,!0)}return!ei(t)||ei(t)&&!t.getContents().length?null:(t=this.toolbox.getFlyout()?.getWorkspace().getNavigator())?!this.toolbox.getWorkspace().RTL||r!==H.TOP&&r!==H.BOTTOM?t.getFirstNode():t.getLastNode():null}getOutNode(e,t=!1){if(!t)switch(ua(this.toolbox.getWorkspace())){case H.TOP:case H.BOTTOM:return this.getPreviousNode(e,!0);case H.RIGHT:return this.getInNode(e,!0)}return super.getOutNode(e)}getNextNode(e,t=!1){if(!t)switch(ua(this.toolbox.getWorkspace())){case H.TOP:return this.getInNode(e,!0);case H.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t)switch(ua(this.toolbox.getWorkspace())){case H.TOP:return this.getOutNode(e,!0);case H.BOTTOM:return this.getInNode(e,!0)}return super.getPreviousNode(e)}getTopLevelItems(){return this.toolbox.getToolboxItems()}},Of=class extends Tf{constructor(e){super(),this.flyout=e,this.rules.push(new ff,new pf)}getOutNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(ua(this.flyout.targetWorkspace)){case H.TOP:case H.BOTTOM:return this.flyout.RTL?this.getNextNode(e,!0):this.getPreviousNode(e,!0);case H.RIGHT:return null}return(e=this.flyout.targetWorkspace?.getToolbox())?e.getSelectedItem():null}getInNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(ua(this.flyout.targetWorkspace)){case H.TOP:case H.BOTTOM:return this.flyout.RTL?this.getPreviousNode(e,!0):this.getNextNode(e,!0);case H.RIGHT:return this.getOutNode(e,!0)}return super.getInNode(e)}getNextNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(ua(this.flyout.targetWorkspace)){case H.TOP:return null;case H.BOTTOM:return this.getOutNode(e,!0)}return super.getNextNode(e)}getPreviousNode(e,t=!1){if(!t&&this.flyout.targetWorkspace)switch(ua(this.flyout.targetWorkspace)){case H.TOP:return this.getOutNode(e,!0);case H.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)}},kf=class{constructor(e,t,n,r,i){this.workspace=e,this.oldHostMetrics=this.corner_=this.vScroll=this.hScroll=null,t=t===void 0?!0:t,n=n===void 0?!0:n;var a=t&&n;t&&(this.hScroll=new zs(e,!0,a,r,i)),n&&(this.vScroll=new zs(e,!1,a,r,i)),a&&(this.corner_=w(I.RECT,{height:zs.scrollbarThickness,width:zs.scrollbarThickness,class:`blocklyScrollbarBackground`}),he(this.corner_,e.getBubbleCanvas()))}dispose(){D(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.Ka++,this.hScroll&&n&&this.hScroll.resize(t),this.vScroll&&r&&this.vScroll.resize(t)}finally{e.Ka--}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)}},Af=class{load(e,t){return e=new df(0,t.horizontalLayout?`x`:`y`),new cf(e,`sep`)}gapForItem(e,t){return parseInt(String(e.gap))??t}disposeItem(){}getType(){return`sep`}};t(M.FLYOUT_INFLATER,`sep`,Af);var jf=class extends sf{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 Sp(e),this.workspace_.setMetricsManager(new uf(this.workspace_,this)),this.workspace_.internalIsFlyout=!0,this.workspace_.setVisible(this.visible),this.workspace_.setNavigator(new Of(this)),this.id=te(),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_=w(t,{class:`blocklyFlyout`}),this.svgGroup_.style.display=`none`,this.svgBackground_=w(I.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.A().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 kf(this.workspace_,this.horizontalLayout,!this.horizontalLayout,`blocklyFlyoutScrollbar`,this.SCROLLBAR_MARGIN),this.hide(),this.boundEvents.push(p(this.svgGroup_,`wheel`,this,this.wheel_,!1,{passive:!1})),this.boundEvents.push(p(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:Es.ComponentWeight.FLYOUT_WEIGHT,capabilities:[Es.Capability.AUTOHIDEABLE,Es.Capability.DELETE_AREA,Es.Capability.DRAG_TARGET]})}dispose(){this.hide(),this.targetWorkspace.getComponentManager().removeComponent(this.id);for(let e of this.boundEvents)h(e);this.boundEvents.length=0,this.workspace_&&(this.workspace_.getThemeManager().unsubscribe(this.svgBackground_),this.workspace_.dispose()),this.svgGroup_&&D(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_&&ge(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.A().getFocusedTree()===this.workspace_&&e.A().getFocusedNode()!==this.workspace_&&e.A().focusNode(this.workspace_),this.workspace_.setResizesEnabled(!1),e.Pc=!1,this.hide(),this.clearOldBlocks(),typeof t==`string`&&(t=this.getDynamicCategoryContents(t)),this.setVisible(!0),t=st(t),t=this.createFlyoutInfo(t),Tt(this.workspace_),this.setContents(t),this.layout_(t),this.horizontalLayout?this.height_=0:this.width_=0,this.reflow(),this.updateAriaContext(),e.Pc=!0,this.workspace_.setResizesEnabled(!0),this.reflowWrapper=e=>{this.inhibitReflowWrapper||e.type!==N.BLOCK_CHANGE&&e.type!==N.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);C(this.getWorkspace().getCanvas(),F.OWNS,t.join(` `)),this.targetWorkspace.isMutator||this.autoClose?S(this.getWorkspace().svgGroup_,P.PRESENTATION):S(this.getWorkspace().svgGroup_,P.REGION);var n=(t=(n=this.targetWorkspace.getToolbox())?.getSelectedItem())&&ei(t)?t.getName():``;n=e.C.WORKSPACE_LABEL_FLYOUT_WORKSPACE.replace(`%1`,n).trim(),C(this.getWorkspace().getCanvas(),F.LABEL,n),S(this.getWorkspace().getCanvas(),P.LIST)}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=st(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 cf(new df(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=r(M.FLYOUT_INFLATER,e,void 0))?(t=new t,this.inflaters.set(e,t),t):null}},Mf=class{constructor(e){this.workspace=e,this.horizontalScrollEnabled=this.workspace.isMovableHorizontally(),this.verticalScrollEnabled=this.workspace.isMovableVertically(),this.startScrollXY_=new z(e.scrollX,e.scrollY)}startDrag(){}endDrag(e){this.drag(e)}drag(e){if(e=z.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.`)}},Nf=class{constructor(e,t){this.creatorWorkspace=t,this.mouseDownXY=new z(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 z(0,0)}dispose(){lo=null,hu=!1,this.creatorWorkspace.clearGesture();for(let e of this.boundEvents)h(e);this.boundEvents.length=0}updateFromEvent(e){var t=new z(e.clientX,e.clientY);this.updateDragDelta(t)&&(this.updateIsDragging(e),l()),this.mostRecentEvent=e}updateDragDelta(t){return this.currentDragDeltaXY=z.difference(t,this.mouseDownXY),this.hasExceededDragRadius?!1:this.hasExceededDragRadius=z.magnitude(this.currentDragDeltaXY)>(this.flyout?e.tg.flyoutDragRadius:e.tg.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 Mf(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=Me();t&&Mi(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(s(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,g(e)?this.cancel():(this.gestureHasStarted=!0,bi(),this.startWorkspace_.updateScreenCalculationsIfScrolled(),this.startWorkspace_.isMutator&&this.startWorkspace_.resize(),this.currentDropdownOwner=ou,this.startWorkspace_.hideChaff(!!this.flyout),this.startWorkspace_.markFocused(),this.mostRecentEvent=e,Xn(),_(e)?this.handleRightClick(e):(e.type.toLowerCase()===`pointerdown`&&e.pointerType!==`mouse`&&c(e,this),this.mouseDownXY=new z(e.clientX,e.clientY),this.bindMouseEvents(e),this.isEnding_||this.handleTouchStart(e)))}bindMouseEvents(e){this.boundEvents.push(p(document,`pointerdown`,null,this.handleStart.bind(this),!0)),this.boundEvents.push(p(document,`pointermove`,null,this.handleMove.bind(this),!0)),this.boundEvents.push(p(document,`pointerup`,null,this.handleUp.bind(this),!0)),this.boundEvents.push(p(document,`pointercancel`,null,this.handleUp.bind(this),!0)),e.preventDefault(),e.stopPropagation()}handleStart(e){this.isDragging()||(this.handleTouchStart(e),this.isMultiTouch()&&l())}handleMove(e){this.isDragging()&&u(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),l())}handleUp(e){if(this.isDragging()||this.handleTouchEnd(e),!this.isMultiTouch()||this.isDragging()){if(!u(e))return;if(this.updateFromEvent(e),l(),this.isEnding_){console.log(`Trying to end a gesture recursively.`);return}this.isEnding_=!0,this.dragger?(Ll.setIsActive(!1),this.dragger.onDragEnd(e,this.currentDragDeltaXY)):this.workspaceDragger?(Ll.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=d(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=z.distance(t,n),this.multiTouch=!0,e.preventDefault())}handleTouchMove(e){var t=d(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=z.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=v(e,r.getParentSvg(),r.getInverseScreenCTM());r.zoom(i.x,i.y,t)}this.previousScale=n,e.preventDefault()}handleTouchEnd(e){e=d(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 z(e.pageX,e.pageY):null}isMultiTouch(){return this.multiTouch}cancel(){this.isEnding_||(l(),this.dragger?this.dragger.onDragEnd(this.mostRecentEvent,this.currentDragDeltaXY):this.workspaceDragger&&this.workspaceDragger.endDrag(this.currentDragDeltaXY),this.dispose())}handleRightClick(t){var n=e.A().getFocusedNode();if(n&&typeof n.showContextMenu==`function`){let e;(e=this.startWorkspace_)==null||e.hideChaff(!!this.flyout),n.showContextMenu(t)}t.preventDefault(),t.stopPropagation(),Ll.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.A().focusNode(n),this.doStart(t)}fireWorkspaceClick(e){b(new(x(N.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=an(this.targetBlock);let e=this.flyout.targetWorkspace;if(t&&e){var n=rt(this.flyout.getWorkspace(),this.targetBlock.getRelativeToSurfaceXY());n=nt(e,n),t.x=n.x,t.y=n.y,cn(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(N.CLICK))(this.startBlock,this.startWorkspace_.id,`block`),b(t)}e.r(!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){this.startBlock||this.startBubble||this.startIcon||(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.A().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=De();for(let t=0,n;n=e[t];t++)if(n.currentGesture_)return!0;return!1}},Pf=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 z(r,t)}static createDom(e,t,n,r){if(e=w(I.PATTERN,{id:`blocklyGridPattern`+e,patternUnits:`userSpaceOnUse`},n),(t.length??1)>0&&(t.spacing??0)>0){w(I.LINE,{stroke:t.colour},e);let n;(n=t.length)!=null&&n&&w(I.LINE,{stroke:t.colour},e)}else w(I.LINE,{},e);return r&&r.style.setProperty(`--blocklyGridPattern`,`url(#${e.id})`),e}},Ff=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),T(e,`blocklyBlockCanvas`),e=this.createLayer(100),T(e,`blocklyBubbleCanvas`)}createDragLayer(e){var t=w(I.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),w(I.G,{},t)}createAnimationLayer(e){var t=w(I.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),w(I.G,{},t)}appendToAnimationLayer(e){var t=this.dragLayer?.getAttribute(`transform`);if(t){let e;(e=this.animationLayer)==null||e.setAttribute(`transform`,t)}var n;(n=this.animationLayer)==null||n.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.A().focusNode(t)}moveOffDragLayer(t,n,r=!0){this.append(t,n),r&&t.canBeFocused()&&e.A().focusNode(t)}append(e,t){if(this.layers.has(t)||this.createLayer(t),e=e.getSvgRoot(),this.layers.get(t)?.lastChild!==e){let n;(n=this.layers.get(t))==null||n.appendChild(e)}}createLayer(e){var t=this.workspace.getSvgGroup(),n=w(I.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}},If={};If.register=da,If.unregister=function(e){n(M.ICON,e)};var Lf=class extends hd{constructor(e){super(e),this.sourceBlock=e,this.textInputBubble=null,this.text=``,this.bubbleSize=new V(160,80),this.bubbleVisiblity=!1}getType(){return Lf.TYPE}initView(e){this.svgRoot||(super.initView(e),w(I.CIRCLE,{class:`blocklyIconShape`,r:`8`,cx:`8`,cy:`8`},this.svgRoot),w(I.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),w(I.RECT,{class:`blocklyIconSymbol`,x:`6.8`,y:`10.78`,height:`2`,width:`2`},this.svgRoot),T(this.svgRoot,`blocklyCommentIcon`))}dispose(){super.dispose();var e;(e=this.textInputBubble)==null||e.dispose()}getWeight(){return Lf.WEIGHT}getSize(){return new V(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,j.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=z.difference(this.workspaceLocation,t),z.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(N.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 V(e.width??160,e.height??80),this.bubbleVisiblity=e.pinned??!1,this.setBubbleVisible(this.bubbleVisiblity);var t=e.x,n=e.y;wt().then(()=>{t&&n&&(t=this.sourceBlock.workspace.RTL?this.sourceBlock.workspace.getWidth()-(t+this.bubbleSize.width):t,this.setBubbleLocation(new z(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(N.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,j.asyncExecutePromiseGeneratorFunction)(function*(){t.bubbleVisiblity!==e&&(t.bubbleVisiblity=e,yield wt(),!t.sourceBlock.rendered||t.sourceBlock.isInFlyout||t.sourceBlock.isInsertionMarker()||(e?(t.sourceBlock.isEditable()?t.showEditableBubble():t.showNonEditableBubble(),t.applyColour()):t.hideBubble(),b(new(x(N.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 xd(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 z.sum(this.workspaceLocation,new z(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}};Lf.TYPE=Ic.COMMENT,Lf.WEIGHT=3,da(Lf.TYPE,Lf);var Rf={};Rf.CommentIcon=Lf,Rf.Icon=hd,Rf.IconType=Ic,Rf.MutatorIcon=e.Yg,Rf.WarningIcon=rf,Rf.exceptions=wd,Rf.registry=If;var zf,Bf;e.aj=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:
841
+ Blockly.YourGeneratorName.nameDB_.setVariableMap(workspace.getVariableMap());`),null)}populateVariables(t){t=e.Ad(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){return(e=this.db.get(e)?.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()}},zf=e.aj||={},Bf=zf.NameType||={},Bf.DEVELOPER_VARIABLE=`DEVELOPER_VARIABLE`,Bf.VARIABLE=`VARIABLE`,Bf.PROCEDURE=`PROCEDURE`,e.P=e.aj.NameType,e.aj.DEVELOPER_VARIABLE_TYPE=e.P.DEVELOPER_VARIABLE;var Vf=class extends Map{constructor(){super()}set(e,t){return this.get(e)===t?this:(super.set(e,t),pa(t)&&t.startPublishing(),this)}delete(e){var t=this.get(e);return e=super.delete(e),e&&(pa(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()]}},Hf={CATEGORY_NAME:`PROCEDURE`,DEFAULT_ARG:`x`};Hf.ObservableProcedureMap=Vf,Hf.allProcedures=ma,Hf.findLegalName=e.$i,Hf.flyoutCategory=_a,Hf.getCallers=xa,Hf.getDefinition=e.jj,Hf.isNameUsed=ga,Hf.isProcedureBlock=fa,Hf.mutateCallers=e.ij,Hf.mutatorOpenListener=ya,Hf.rename=e.cj;var Q=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}},Uf=class{constructor(e){this.centerline=this.xPos=this.height=this.width=0,this.constants_=e,this.type=Q.NONE,this.notchOffset=this.constants_.NOTCH_OFFSET_LEFT}},Wf=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=Q.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(Q.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(Q.isInRowSpacer(t))return t}return null}getLastSpacer(){for(let e=this.elements.length-1;e>=0;e--){let t=this.elements[e];if(Q.isInRowSpacer(t))return t}return null}},Gf=class extends Wf{constructor(e){super(e),this.hasNextConnection=!1,this.connection=null,this.baseline=this.descenderHeight=0,this.type|=Q.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,Q.isSpacer(i)||(Q.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}},Kf=class extends Uf{constructor(e,t){super(e),this.connectionModel=t,this.type|=Q.CONNECTION,this.shape=this.constants_.shapeFor(t),this.isDynamicShape=`isDynamic`in this.shape&&this.shape.isDynamic,this.highlighted=t.isHighlighted()}},qf=class extends Kf{constructor(e,t){super(e,t.connection),this.input=t,this.connectionOffsetY=this.connectionOffsetX=0,this.type|=Q.INPUT,this.align=t.align,(this.connectedBlock=t.connection&&t.connection.targetBlock()?t.connection.targetBlock():null)?(e=this.connectedBlock.getHeightWidth(),this.connectedBlockWidth=e.width,this.connectedBlockHeight=e.height):this.connectedBlockHeight=this.connectedBlockWidth=0}},Jf=class extends qf{constructor(e,t){super(e,t),this.height=0,this.type|=Q.EXTERNAL_VALUE_INPUT,this.height=this.connectedBlock?this.connectedBlockHeight-this.constants_.TAB_OFFSET_FROM_TOP-this.constants_.MEDIUM_PADDING: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}},Yf=class extends Uf{constructor(e,t,n){super(e),this.field=t,this.parentInput=n,this.isEditable=t.EDITABLE,this.flipRtl=t.getFlipRtl(),this.type|=Q.FIELD,e=this.field.getSize(),this.height=e.height,this.width=e.width}},Xf=class extends Uf{constructor(e){super(e),this.type|=Q.HAT,this.height=this.constants_.START_HAT.height,this.width=this.constants_.START_HAT.width,this.ascenderHeight=this.height}},Zf=class extends Uf{constructor(e,t){super(e),this.icon=t,this.flipRtl=!1,this.type|=Q.ICON,e=t.getSize(),this.height=e.height,this.width=e.width}},Qf=class extends Uf{constructor(e,t){super(e),this.type|=Q.SPACER|Q.IN_ROW_SPACER,this.width=t,this.height=this.constants_.SPACER_DEFAULT_HEIGHT}},$f=class extends qf{constructor(e,t){super(e,t),this.type|=Q.INLINE_INPUT,this.connectedBlock?(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.connectedBlock||(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}},ep=class extends Wf{constructor(e){super(e),this.connectedBlockWidths=0,this.type|=Q.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,Q.isInput(n)&&(Q.isStatementInput(n)?e+=n.connectedBlockWidth:Q.isExternalInput(n)&&n.connectedBlockWidth!==0&&(e+=n.connectedBlockWidth-n.connectionWidth)),Q.isSpacer(n)||(this.height=Math.max(this.height,n.height))}this.connectedBlockWidths=e,this.widthWithConnectedBlocks=this.width+e}endsWithElemSpacer(){return!this.hasExternalInput&&!this.hasStatement}},tp=class extends Uf{constructor(e){super(e),this.type|=Q.JAGGED_EDGE,this.height=this.constants_.JAGGED_TEETH.height,this.width=this.constants_.JAGGED_TEETH.width}},np=class extends Kf{constructor(e,t){super(e,t),this.type|=Q.NEXT_CONNECTION,this.height=this.shape.height,this.width=this.shape.width}},rp=class extends Kf{constructor(e,t){super(e,t),this.connectionOffsetX=0,this.type|=Q.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}},ip=class extends Kf{constructor(e,t){super(e,t),this.type|=Q.PREVIOUS_CONNECTION,this.height=this.shape.height,this.width=this.shape.width}},ap=class extends Uf{constructor(e,t){super(e),this.type=(t&&t!==`left`?Q.RIGHT_ROUND_CORNER:Q.LEFT_ROUND_CORNER)|Q.CORNER,this.width=this.constants_.CORNER_RADIUS,this.height=this.constants_.CORNER_RADIUS/2}},op=class extends Wf{constructor(e,t,n){super(e),this.height=t,this.width=n,this.precedesStatement=this.followsStatement=!1,this.widthWithConnectedBlocks=0,this.type|=Q.SPACER|Q.BETWEEN_ROW_SPACER,this.elements=[new Qf(this.constants_,n)]}measure(){}},sp=class extends Uf{constructor(e,t){super(e),this.type=(t&&t!==`left`?Q.RIGHT_SQUARE_CORNER:Q.LEFT_SQUARE_CORNER)|Q.CORNER,this.width=this.height=this.constants_.NO_PADDING}},cp=class extends qf{constructor(e,t){super(e,t),this.type|=Q.STATEMENT_INPUT,this.height=this.connectedBlock?this.connectedBlockHeight+this.constants_.STATEMENT_BOTTOM_SPACER:this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT,this.width=this.constants_.STATEMENT_INPUT_NOTCH_OFFSET+this.shape.width}},lp=class extends Wf{constructor(e){super(e),this.ascenderHeight=this.capline=0,this.hasPreviousConnection=!1,this.connection=null,this.type|=Q.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,Q.isSpacer(i)||(Q.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}},up=new Map,dp=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=Jr(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=xe(`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=or(t.colourPrimary||`#000`),t.colourPrimary=e.hex,t.colourSecondary=t.colourSecondary?or(t.colourSecondary).hex:this.generateSecondaryColour_(t.colourPrimary),t.colourTertiary=t.colourTertiary?or(t.colourTertiary).hex:this.generateTertiaryColour_(t.colourPrimary),t.hat=t.hat||``,t}generateSecondaryColour_(e){return nr(`#fff`,e,.6)||e}generateTertiaryColour_(e){return nr(`#fff`,e,.3)||e}dispose(){this.embossFilter&&D(this.embossFilter),this.disabledPattern&&D(this.disabledPattern),this.debugFilter&&D(this.debugFilter)}makeJaggedTeeth(){var e=this.JAGGED_TEETH_HEIGHT,t=this.JAGGED_TEETH_WIDTH;return{height:e,width:t,path:Xr([k(t,e/4),k(-t*2,e/2),k(t,e/4)])}}makeStartHat(){var e=this.START_HAT_HEIGHT,t=this.START_HAT_WIDTH,n=Kr(`c`,[k(30,-e),k(70,-e),k(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=k(-t,e*i);return i=k(t,e*i),Kr(`c`,[k(0,e*a),k(-t,r*o),s])+Kr(`s`,[k(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 Xr([k(e*r,n),k(e*3,0),k(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:Zr(`a`,`0 0,0`,e,k(-e,e)),pathBottom:Zr(`a`,`0 0,0`,e,k(e,e))}}makeOutsideCorners(){var e=this.CORNER_RADIUS,t=Jr(0,e)+Zr(`a`,`0 0,1`,e,k(e,-e)),n=Zr(`a`,`0 0,1`,e,k(e,e)),r=Zr(`a`,`0 0,1`,e,k(-e,-e));return{topLeft:t,topRight:n,bottomRight:Zr(`a`,`0 0,1`,e,k(-e,e)),bottomLeft:r,rightHeight:e}}shapeFor(e){switch(e.type){case U.INPUT_VALUE:case U.OUTPUT_VALUE:return this.PUZZLE_TAB;case U.PREVIOUS_STATEMENT:case U.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=w(I.DEFS,{},e),e=w(I.FILTER,{id:`blocklyEmbossFilter`+this.randomIdentifier},this.defs),w(I.FEGAUSSIANBLUR,{in:`SourceAlpha`,stdDeviation:1,result:`blur`},e),t=w(I.FESPECULARLIGHTING,{in:`blur`,surfaceScale:1,specularConstant:.5,specularExponent:10,"lighting-color":`white`,result:`specOut`},e),w(I.FEPOINTLIGHT,{x:-5e3,y:-1e4,z:2e4},t),w(I.FECOMPOSITE,{in:`specOut`,in2:`SourceAlpha`,operator:`in`,result:`specOut`},e),w(I.FECOMPOSITE,{in:`SourceGraphic`,in2:`specOut`,operator:`arithmetic`,k1:0,k2:1,k3:1,k4:0},e),this.embossFilterId=e.id,this.embossFilter=e,e=w(I.PATTERN,{id:`blocklyDisabledPattern`+this.randomIdentifier,patternUnits:`userSpaceOnUse`,width:10,height:10},this.defs),w(I.RECT,{width:10,height:10,fill:`#aaa`},e),w(I.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=w(I.FILTER,{id:`blocklyDebugFilter`+this.randomIdentifier,height:`160%`,width:`180%`,y:`-30%`,x:`-40%`},this.defs),t=w(I.FECOMPONENTTRANSFER,{result:`outBlur`},e);w(I.FEFUNCA,{type:`table`,tableValues:`0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1`},t),w(I.FEFLOOD,{"flood-color":`#ff0000`,"flood-opacity":.5,result:`outColor`},e),w(I.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=up.get(t))==null||!n.has(e))&&(n=document.createElement(`style`),n.className=`blockly-renderer-style`,n.textContent=this.getCSS_(t).join(`
842
+ `),(globalThis.ShadowRoot!==void 0&&e instanceof ShadowRoot?e:document.head).prepend(n),n=up.get(t)??new WeakSet,n.add(e),up.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} .blocklyHighlightedConnectionPath {`,`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;`,`}`]}},fp=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_+`
843
+ `+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_+=Jr(e.xPos,this.info_.startY);for(let e=0,n;n=t[e];e++)Q.isLeftRoundedCorner(n)?this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.topLeft:Q.isRightRoundedCorner(n)?this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.topRight:Q.isPreviousConnection(n)?this.outlinePath_+=n.shape.pathLeft:Q.isHat(n)?this.outlinePath_+=this.constants_.START_HAT.path:Q.isSpacer(n)&&(this.outlinePath_+=A(`h`,n.width));this.outlinePath_+=A(`v`,e.height-e.ascenderHeight)}drawJaggedEdge_(e){this.outlinePath_+=this.constants_.JAGGED_TEETH.path+A(`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_+=A(`H`,t.xPos+t.width)+n+A(`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+A(`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_+=A(`H`,n)+t+A(`v`,r)+this.constants_.INSIDE_CORNERS.pathBottom+A(`H`,e.xPos+e.width),this.positionStatementInputConnection_(e)}}drawRightSideRow_(e){this.outlinePath_+=A(`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--)Q.isNextConnection(a)?r+=a.shape.pathRight:Q.isLeftSquareCorner(a)?r+=A(`H`,e.xPos):Q.isLeftRoundedCorner(a)?r+=this.constants_.OUTSIDE_CORNERS.bottomLeft:Q.isRightRoundedCorner(a)?(r+=this.constants_.OUTSIDE_CORNERS.bottomRight,n=this.constants_.OUTSIDE_CORNERS.rightHeight):Q.isSpacer(a)&&(r+=A(`h`,a.width*-1));this.outlinePath_+=A(`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_+=A(`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++)Q.isInlineInput(n)?this.drawInlineInput_(n):(Q.isIcon(n)||Q.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)`)),Q.isIcon(e)?(r=e.icon,r.setOffsetInBlock(new z(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_+=qr(e.xPos+e.connectionWidth,e.centerline-n/2)+A(`v`,r)+e.shape.pathDown+A(`v`,n-i)+A(`h`,t-e.connectionWidth)+A(`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 Kf))continue;let e=this.drawConnectionHighlightPath(t);e&&(e.style.display=t.highlighted?``:`none`)}}drawConnectionHighlightPath(e){var t=e.connectionModel;e=t.type===U.INPUT_VALUE||t.type===U.OUTPUT_VALUE?this.getExpressionConnectionHighlightPath(e):this.getStatementConnectionHighlightPath(e);var n=t.getSourceBlock(),r;return(r=n.pathObject).addConnectionHighlight?.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,Jr(0,-e)+A(`v`,e)+t+A(`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,Jr(-t,0)+A(`h`,t)+e.shape.pathLeft+A(`h`,t)}},pp=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 rp(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 lp(this.constants_),this.bottomRow=new Gf(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 ep(this.constants_);this.inputRows.push(e);var t=this.block_.getIcons();for(let n=0,r;r=t[n];n++){let t=new Zf(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 ep(this.constants_),this.inputRows.push(e));for(let t=0,n;n=r.fieldRow[t];t++)e.elements.push(new Yf(this.constants_,n,r));this.addInput_(r,e),t=r}this.isCollapsed&&(e.hasJaggedEdge=!0,e.elements.push(new tp(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_)?sp:ap;this.topRow.elements.push(new n(this.constants_)),t?(e=new Xf(this.constants_),this.topRow.elements.push(e)):e&&(this.topRow.hasPreviousConnection=!0,this.topRow.connection=new ip(this.constants_,this.block_.previousConnection),this.topRow.elements.push(this.topRow.connection)),this.block_.inputList.length&&this.block_.inputList[0]instanceof Id&&!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_)?sp:ap,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 Id?this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT:this.constants_.BOTTOM_ROW_MIN_HEIGHT,this.bottomRow.hasLeftSquareCorner(this.block_)?this.bottomRow.elements.push(new sp(this.constants_)):this.bottomRow.elements.push(new ap(this.constants_)),this.bottomRow.hasNextConnection&&(this.bottomRow.connection=new np(this.constants_,this.block_.nextConnection),this.bottomRow.elements.push(this.bottomRow.connection)),this.bottomRow.hasRightSquareCorner(this.block_)?this.bottomRow.elements.push(new sp(this.constants_,`right`)):this.bottomRow.elements.push(new ap(this.constants_,`right`))}addInput_(t,n){this.isInline&&t instanceof e.En?(n.elements.push(new $f(this.constants_,t)),n.hasInlineInput=!0):t instanceof Id?(n.elements.push(new cp(this.constants_,t)),n.hasStatement=!0):t instanceof e.En?(n.elements.push(new Jf(this.constants_,t)),n.hasExternalInput=!0):(t instanceof Pd||t instanceof Fd)&&(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 Fd||t instanceof Id||n instanceof Id?!0:t instanceof e.En||t instanceof Pd||n instanceof e.En?!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 Qf(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 Qf(this.constants_,r))}t.elements.push(e[e.length-1]),t.endsWithElemSpacer()&&t.elements.push(new Qf(this.constants_,this.getInRowSpacing_(e[e.length-1],null)))}}}getInRowSpacing_(e,t){if(!e&&t&&Q.isStatementInput(t))return this.constants_.STATEMENT_INPUT_PADDING_LEFT;if(e&&Q.isInput(e)&&!t){if(Q.isExternalInput(e))return this.constants_.NO_PADDING;if(Q.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Q.isStatementInput(e))return this.constants_.NO_PADDING}return e&&Q.isLeftSquareCorner(e)&&t&&(Q.isPreviousConnection(t)||Q.isNextConnection(t))?t.notchOffset:e&&Q.isLeftRoundedCorner(e)&&t&&(Q.isPreviousConnection(t)||Q.isNextConnection(t))?t.notchOffset-this.constants_.CORNER_RADIUS:e&&Q.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?.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),Q.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.tn.LEFT&&i)i.width+=n;else if(t.align===e.tn.CENTRE&&r&&i)r.width+=n/2,i.width+=n/2;else if(t.align===e.tn.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 op(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 Q.isSpacer(t)?e.yPos+t.height/2:Q.isBottomRow(e)?(e=e.yPos+e.height-e.descenderHeight,Q.isNextConnection(t)?e+t.height/2:e-t.height/2):Q.isTopRow(e)?Q.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++)Q.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){if(this.outputConnection?.connectionModel===e)return this.outputConnection;for(let t of this.rows)for(let n of t.elements)if(n instanceof Kf&&n.connectionModel===e)return n;return null}},mp=class{constructor(e,t,n){this.connectionHighlights=new WeakMap,this.highlightOffsets=new WeakMap,this.constants=n,this.style=t,this.svgRoot=e,this.svgPath=w(I.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?T(this.svgRoot,e):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=w(I.PATH,{id:e.id,class:`blocklyHighlightedConnectionPath`,style:`display: none;`,d:t,transform:n},this.svgRoot),this.connectionHighlights.set(e,t),t)}removeConnectionHighlight(e){var t=this.connectionHighlights.get(e);t&&(D(t),this.connectionHighlights.delete(e))}},hp=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 dp}makeRenderInfo_(e){return new pp(this,e)}makeDrawer_(e,t){return new fp(e,t)}makePathObject(e,t){return new mp(e,t,this.constants_)}getConstants(){return this.constants_}shouldHighlightConnection(e){return!e.getSourceBlock().isDragging()}orphanCanConnectAtEnd(e,t,n){return!!Y.getConnectionForOrphanedConnection(e,n===U.OUTPUT_VALUE?t.outputConnection:t.previousConnection)}render(e){var t=this.makeRenderInfo_(e);t.measure(),this.makeDrawer_(e,t).draw()}},gp={};gp.BottomRow=Gf,gp.Connection=Kf,gp.ConstantProvider=dp,gp.Drawer=fp,gp.ExternalValueInput=Jf,gp.Field=Yf,gp.Hat=Xf,gp.Icon=Zf,gp.InRowSpacer=Qf,gp.InlineInput=$f,gp.InputConnection=qf,gp.InputRow=ep,gp.JaggedEdge=tp,gp.Measurable=Uf,gp.NextConnection=np,gp.OutputConnection=rp,gp.PathObject=mp,gp.PreviousConnection=ip,gp.RenderInfo=pp,gp.Renderer=hp,gp.RoundCorner=ap,gp.Row=Wf,gp.SpacerRow=op,gp.SquareCorner=sp,gp.StatementInput=cp,gp.TopRow=lp,gp.Types=Q,gp.init=Ca,gp.register=Sa,gp.unregister=function(e){n(M.RENDERER,e)};var _p=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(e,t),(t=this.theme.getClassName())&&T(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(!Ve(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()}},vp={CATEGORY_NAME:`VARIABLE_DYNAMIC`};vp.flyoutCategory=Da,vp.flyoutCategoryBlocks=function(t){t=t.getVariableMap().getAllVariables();var n=[];if(t.length>0){if(so.variables_set_dynamic){var r=t[t.length-1];let i=e.F(`block`);i.setAttribute(`type`,`variables_set_dynamic`),i.setAttribute(`gap`,`24`),i.appendChild(en(r)),n.push(i)}if(so.variables_get_dynamic){t.sort(nn);for(let i=0,a;a=t[i];i++)r=e.F(`block`),r.setAttribute(`type`,`variables_get_dynamic`),r.setAttribute(`gap`,`8`),r.appendChild(en(a)),n.push(r)}}return n},vp.onCreateVariableButtonClick_Colour=Ea,vp.onCreateVariableButtonClick_Number=Ta,vp.onCreateVariableButtonClick_String=wa;var yp=class{canConnect(e,t,n,r){return this.canConnectWithReason(e,t,n,r)===Y.CAN_CONNECT}canConnectWithReason(e,t,n,r){var i=this.doSafetyChecks(e,t);return i===Y.CAN_CONNECT?this.doTypeChecks(e,t)?n&&!this.doDragChecks(e,t,r||0)?Y.REASON_DRAG_CHECKS_FAILED:Y.CAN_CONNECT:Y.REASON_CHECKS_FAILED:i}getErrorMessage(e,t,n){switch(e){case Y.REASON_SELF_CONNECTION:return`Attempted to connect a block to itself.`;case Y.REASON_DIFFERENT_WORKSPACES:return`Blocks not on same workspace.`;case Y.REASON_WRONG_TYPE:return`Attempt to connect incompatible types.`;case Y.REASON_TARGET_NULL:return`Target connection is null.`;case Y.REASON_CHECKS_FAILED:return`Connection checks failed. `+(t+` expected `+t.getCheck()+`, found `+n.getCheck());case Y.REASON_SHADOW_PARENT:return`Connecting non-shadow to shadow block.`;case Y.REASON_DRAG_CHECKS_FAILED:return`Drag checks failed.`;case Y.REASON_PREVIOUS_AND_OUTPUT:return`Block would have an output and a previous connection.`;default:return`Unknown connection failure: this should never happen!`}}doSafetyChecks(e,t){if(!e||!t)return Y.REASON_TARGET_NULL;if(e.isSuperior())var n=e.getSourceBlock(),r=t.getSourceBlock(),i=t;else r=e.getSourceBlock(),n=t.getSourceBlock(),i=e,e=t;return n===r?Y.REASON_SELF_CONNECTION:i.type===kd[e.type]?n.workspace===r.workspace?n.isShadow()&&!r.isShadow()?Y.REASON_SHADOW_PARENT:i.type===U.OUTPUT_VALUE&&r.previousConnection&&r.previousConnection.isConnected()||i.type===U.PREVIOUS_STATEMENT&&r.outputConnection&&r.outputConnection.isConnected()?Y.REASON_PREVIOUS_AND_OUTPUT:Y.CAN_CONNECT:Y.REASON_DIFFERENT_WORKSPACES:Y.REASON_WRONG_TYPE}doTypeChecks(e,t){if(e=e.getCheck(),t=t.getCheck(),!e||!t)return!0;for(let n=0;n<e.length;n++)if(t.includes(e[n]))return!0;return!1}doDragChecks(e,t,n){if(e.distanceFrom(t)>n||t.getSourceBlock().isInsertionMarker())return!1;switch(t.type){case U.PREVIOUS_STATEMENT:return this.canConnectToPrevious_(e,t);case U.OUTPUT_VALUE:if(t.isConnected()&&!t.targetBlock().isInsertionMarker()||e.isConnected())return!1;break;case U.INPUT_VALUE:if(t.isConnected()&&!t.targetBlock().isMovable()&&!t.targetBlock().isShadow())return!1;break;case U.NEXT_STATEMENT:if(t.isConnected()&&!e.getSourceBlock().nextConnection&&!t.targetBlock().isShadow()&&t.targetBlock().nextConnection||t.targetBlock()&&!t.targetBlock().isMovable()&&!t.targetBlock().isShadow())return!1;break;default:return!1}return!gs.includes(t)}canConnectToPrevious_(e,t){return e.targetConnection||gs.includes(t)?!1:t.targetConnection?(e=t.targetBlock(),e.isInsertionMarker()?!e.getPreviousBlock():!1):!0}};t(M.CONNECTION_CHECKER,`default`,yp);var bp=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 Vf,this.readOnly=!1,this.potentialVariableMap=null,this.id=te(),Oe(this),this.options=e||new dd({}),this.RTL=!!this.options.RTL,this.horizontalLayout=!!this.options.horizontalLayout,this.toolboxPosition=this.options.toolboxPosition,this.connectionChecker=new(s(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(),ke(this)}sortObjects(e,t){var n=e=>({getBoundingRectangle:()=>{var t=e.getRelativeToSurfaceXY();return new B(t.y,t.y,t.x,t.x)},moveBy:()=>{}});return this.sortByOrigin(n(e),n(t))}sortByOrigin(e,t){var n=Math.sin(hn(bp.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(!Ve(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){Ve(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(!Ve(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.fd;for(t||e.r(!0);this.topBlocks.length;)this.topBlocks[0].dispose(!1);for(;this.topComments.length;)this.topComments[this.topComments.length-1].dispose();e.r(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.Pc=!1;try{for(r=0;r<a.length;r++)a[r].run(t)}finally{e.Pc=!0}}}redo(){this.undo(!0)}clearUndo(){this.undoStack_.length=0,this.redoStack_.length=0,ae()}addChangeListener(e){return this.listeners.push(e),e}removeChangeListener(e){Ve(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 Ee(e)}static getAll(){return De()}getVariableMapClass(){var e=s(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}};bp.SCAN_ANGLE=3;var xp=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,j.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,j.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,j.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,j.asyncExecutePromiseGeneratorFunction)(function*(){return e.beep(260)})}maybePlayScopeChangeAudioCue(t){if(Ll.getScopeChangeAudioCuesEnabled()){var n=this.parentWorkspace.getNavigator(),r=n.getSourceBlockFromNode(e.A().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,j.asyncExecutePromiseGeneratorFunction)(function*(){e.lastSound=new Date,e.context.state===`suspended`&&(yield e.context.resume())})}setMuted(e){this.muted=e}getMuted(){return this.muted}},Sp=class extends bp{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.workspaceSelectionRing=this.workspaceFocusRing=this.zoomControls_=this.layerManager=null,this.navigator=new Tf,this.metricsManager=new(s(M.METRICS_MANAGER,e,!0))(this),this.getMetrics=e.getMetrics||this.metricsManager.getMetrics.bind(this.metricsManager),this.setMetrics=e.setMetrics||Sp.setTopLevelWorkspaceMetrics,this.componentManager=new Es,this.connectionDBList=Sd.init(this.connectionChecker),this.audioManager=new xp(e.parentWorkspace??this),this.grid=this.options.gridPattern?new Pf(this.options.gridPattern,e.gridOptions):null,zl&&Ht&&this.registerToolboxCategoryCallback(`VARIABLE`,Ht),vp&&Da&&this.registerToolboxCategoryCallback(`VARIABLE_DYNAMIC`,Da),Hf&&_a&&(this.registerToolboxCategoryCallback(`PROCEDURE`,_a),this.addChangeListener(ya)),this.addChangeListener(this.variableChangeCallback.bind(this)),this.themeManager_=this.options.parentWorkspace?this.options.parentWorkspace.getThemeManager():new _p(this,this.options.theme||ud),this.themeManager_.subscribeWorkspace(this),this.renderer=Ca(this.options.renderer||`geras`,this.getTheme(),this.options.rendererOverrides??void 0),this.cachedParentSvgSize=new V(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||=ud,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(N.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=Qe(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 z(t,n)}getCachedParentSvgSize(){var e=this.cachedParentSvgSize;return new V(e.width,e.height)}getOriginOffsetInPixels(){return $e(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||(S(this.svgGroup_,P.REGION),this.isMutator?C(this.svgGroup_,F.LABEL,e.C.WORKSPACE_LABEL_MUTATOR_WORKSPACE):this.updateAriaLabel())}updateAriaLabel(){if(jo)C(this.svgGroup_,F.LABEL,e.C.WORKSPACE_LABEL_PLAIN);else{var t=this.getTopBlocks(!1).length;t==1?C(this.svgGroup_,F.LABEL,e.C.WORKSPACE_LABEL_1_STACK):C(this.svgGroup_,F.LABEL,e.C.WORKSPACE_LABEL_MANY_STACKS.replace(`%1`,String(t)))}}createDom(t,n){return this.injectionDiv||=n??null,this.svgGroup_=w(I.G,{class:`blocklyWorkspace`,id:this.id}),t&&(this.svgBackground_=w(I.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=w(I.RECT,{fill:`none`,class:`blocklyWorkspaceSelectionRing`},this.svgGroup_),this.workspaceFocusRing=w(I.RECT,{fill:`none`,class:`blocklyWorkspaceFocusRing`},this.svgGroup_),this.layerManager=new Ff(this),this.svgBlockCanvas_=this.layerManager.getBlockLayer(),this.svgBubbleCanvas_=this.layerManager.getBubbleLayer(),this.setInitialAriaContext(),this.isFlyout||(p(this.svgGroup_,`pointerdown`,this,this.onMouseDown,!1),this.dummyWheelListener=()=>{},document.body.addEventListener(`wheel`,this.dummyWheelListener,{passive:!0}),p(this.svgGroup_,`wheel`,this,this.onMouseWheel,!1,{passive:!1})),this.options.hasCategories&&(this.toolbox=new(s(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.A().registerTree(this,!!this.injectionDiv||this.isFlyout),this.svgGroup_}dispose(){if(this.rendered=!1,this.currentGesture_&&this.currentGesture_.cancel(),this.svgGroup_&&D(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&&D(e.parentNode)}this.resizeHandlerWrapper&&=(h(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.A().isRegistered(this)&&e.A().unregisterTree(this)}addTrashcan(){this.trashcan=Sp.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 cc(this);var e=this.zoomControls_.createDom();this.svgGroup_.appendChild(e)}copyOptionsForFlyout(){return new dd({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(s(M.FLYOUTS_HORIZONTAL_TOOLBOX,this.options,!0))(t):new(s(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(Es.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=tt();z.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(oe()){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(N.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 z(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):Ve(this.highlightedBlocks,e),e.setHighlighted(t))}variableChangeCallback(e){switch(e.type){case N.VAR_CREATE:case N.VAR_DELETE:case N.VAR_RENAME:case N.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(Es.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 z?rt(this,e):new z(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){wr(this,e,t)}moveDrag(e){return Tr(this,e)}isDragging(){return cd.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(Nf.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(ko)var i=e.metaKey;t&&(e.ctrlKey||i||!n)?(r=-r.y/50,t=v(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 B(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.fd;n||e.r(!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.r(n),this.setResizesEnabled(!0)}showContextMenu(e){if(!this.isReadOnly()&&!this.isFlyout){var t=G.registry.getContextMenuOptions({workspace:this,focusedNode:this},e);if(this.configureContextMenu&&this.configureContextMenu(t,e),e instanceof PointerEvent)var n=new z(e.clientX,e.clientY);else n=this.RTL?this.getWidth()-5:5,n=rt(this,new z(n,5));gr(e,t,this.RTL,this,n)}}updateToolbox(e){if(e=ot(e)){if(!this.options.languageTree)throw Error(`Existing toolbox is null. Can't create new toolbox.`);if(ct(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():(je(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.Ka++;try{this.setScale(Math.min(n/i,t/r)),this.scrollCenter()}finally{e.Ka--}this.maybeFireViewportChangeEvent()}}else console.warn(`Tried to move a non-movable workspace. This could result in blocks becoming inaccessible.`)}beginCanvasTransition(){T(this.getCanvas(),`blocklyCanvasTransitioning`),T(this.getBubbleCanvas(),`blocklyCanvasTransitioning`)}endCanvasTransition(){E(this.getCanvas(),`blocklyCanvasTransitioning`),E(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=e.targetWorkspace?.getFlyout();if(t instanceof jf)return t.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){Ve(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(cd.mover.isMoving())return e?.preventDefault(),e?.stopPropagation(),null;var t=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 Nf(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){Jn(),fr(this),jn(),this.hideComponents(e)}hideComponents(e=!1){this.getComponentManager().getComponents(Es.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&&T(this.injectionDiv,e)}removeClass(e){this.injectionDiv&&E(this.injectionDiv,e)}setIsReadOnly(e){super.setIsReadOnly(e),e?this.addClass(`blocklyReadOnly`):this.removeClass(`blocklyReadOnly`)}scrollBoundsIntoView(e,t=10){if(!Nf.inProgress()){var n=this.getScale(),r=this.getMetricsManager().getViewMetrics(!0);if(r=new B(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.isFlyout||this.isMutator||this.updateAriaLabel(),Sp.everFocused||this.options.parentWorkspace||(fe(e.C.SCREENREADER_HINT.replace(`%1`,fn(X.TOGGLE_SCREENREADER))),Sp.everFocused=!0)}onNodeBlur(){}canBeFocused(){return!0}getRootFocusableNode(){return this}getRestoredFocusableNode(e){return e||(e=this.targetWorkspace?.getFlyout(),this.isFlyout&&e?e.getContents().find(e=>(e=e.getElement(),Se(e)&&e.canBeFocused()))?.getElement()??null:this.isMutator?this.getTopBlocks(!0)[0]??null:null)}getNestedTrees(){var t=this.getAllBlocks().map(e=>e.getIcons()).flat().filter(t=>t instanceof e.Yg&&t.bubbleIsVisible()).map(e=>e.getBubble()?.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 ed&&t.canBeFocused()&&t.getFocusableElement().id===e)return t}lookUpFocusableNode(e){var t,n=(t=this.targetWorkspace)?.getFlyout();if(this.isFlyout&&n){for(var r of n.getContents())if(t=r.getElement(),Se(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(let t of o){if(t.canBeFocused()&&t.getFocusableElement().id===e)return t;if(Rt(t)){if((o=t.getBubble())&&o.canBeFocused()&&o.getFocusableElement().id===e)return o;if(o instanceof xd&&o.getEditor().getFocusableElement().id===e)return o.getEditor()}}var s;return(s=this.trashcan)?.getGloballyUniqueId()===e?this.trashcan:(s=(i=this.zoomControls_)?.getControlWithId(e))?s:null}onTreeFocus(){}onTreeBlur(t){if(this.isFlyout&&this.targetWorkspace&&!e.A().ephemeralFocusTaken()){var n=this.targetWorkspace.getToolbox();n&&t===n||n&&typeof n.autoHide==`function`&&n.autoHide(!1)}}performAction(){Tc.show(this,{message:e.C.KEYBOARD_NAV_WORKSPACE_NAVIGATION_HINT,id:`workspaceNavigationHint`})}getNavigator(){return this.navigator}setNavigator(e){this.navigator=e}};Sp.everFocused=!1;var Cp=class{constructor(e,t,n,r){this.workspace=e,this.name=t,this.type=n||``,this.id=r||te()}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(N.VAR_CREATE))(e))}};t(M.VARIABLE_MODEL,`default`,Cp);var wp=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.fd)||e.r(!0);try{r&&r.getId()!==t.getId()?this.renameVariableWithConflict(t,n,r,i):this.renameVariableAndUses(t,n,i)}finally{this.potentialMap||e.r(a)}return t}changeVariableType(e,t){var n=e.getType();if(n===t)return e;var r=this.variableMap.get(n);return r?.delete(e.getId()),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(N.VAR_TYPE_CHANGE))(e,n,t)),e}renameVariableAndUses(e,t,n){for(this.potentialMap||b(new(x(N.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(N.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||te(),t||=``,n=s(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(N.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=rn(this.workspace,t.getId()),r=``;this.potentialMap||(r=e.fd)||e.r(!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(N.VAR_DELETE))(t)),e.size===0&&this.variableMap.delete(t.getType()))}finally{this.potentialMap||e.r(r)}}getVariable(t,n){return n=this.variableMap.get(n||``),n?[...n.values()].find(n=>e.aj.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}};t(M.VARIABLE_MAP,`default`,wp);var Tp=class extends sf{constructor(e){super(),this.workspace=e,this.id=`trashcan`,this.uniqueId=y(),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===H.TOP?H.BOTTOM:H.TOP,this.flyout=new(s(M.FLYOUTS_HORIZONTAL_TOOLBOX,this.workspace.options,!0))(e)):(e.toolboxPosition=this.workspace.toolboxPosition===H.RIGHT?H.LEFT:H.RIGHT,this.flyout=new(s(M.FLYOUTS_VERTICAL_TOOLBOX,this.workspace.options,!0))(e)),this.workspace.addChangeListener(this.onDelete.bind(this)))}createDom(){this.svgGroup=w(I.G,{class:`blocklyTrash`,tabindex:`0`,id:this.uniqueId}),w(I.RECT,{width:55,height:68,x:-4,y:-4,rx:2,ry:2,fill:`none`,class:`blocklyFocusRing`},this.svgGroup),S(this.svgGroup,P.BUTTON),C(this.svgGroup,F.LABEL,e.C.OPEN_TRASH);var t=String(Math.random()).substring(2),n=w(I.CLIPPATH,{id:`blocklyTrashBodyClipPath`+t},this.svgGroup);return w(I.RECT,{width:47,height:44,y:16},n),w(I.IMAGE,{width:rc.width,x:-0,height:rc.height,y:-32,"clip-path":`url(#blocklyTrashBodyClipPath`+t+`)`},this.svgGroup).setAttributeNS(`http://www.w3.org/1999/xlink`,`xlink:href`,this.workspace.options.pathToMedia+rc.url),n=w(I.CLIPPATH,{id:`blocklyTrashLidClipPath`+t},this.svgGroup),w(I.RECT,{width:47,height:16},n),n=w(I.G,{class:`blocklyTrashLid`},this.svgGroup),n=w(I.SVG,{viewBox:`0 32 47 16`,width:47,height:16},n),w(I.IMAGE,{width:rc.width,height:rc.height,href:this.workspace.options.pathToMedia+rc.url},n),m(this.svgGroup,`pointerdown`,this,this.blockMouseDownWhenOpenable),m(this.svgGroup,`pointerup`,this,this.click),this.svgGroup}init(){if(this.workspace.options.maxTrashcanContents>0){let e=this.flyout.createDom(I.SVG);T(e,`blocklyTrashcanFlyout`),he(e,this.workspace.getParentSvg()),this.flyout.init(this.workspace)}this.workspace.getComponentManager().addComponent({component:this,weight:Es.ComponentWeight.TRASHCAN_WEIGHT,capabilities:[Es.Capability.AUTOHIDEABLE,Es.Capability.DELETE_AREA,Es.Capability.DRAG_TARGET,Es.Capability.POSITIONABLE]}),this.initialized=!0,this.setLidOpen(!1)}dispose(){this.workspace.getComponentManager().removeComponent(`trashcan`),this.svgGroup&&D(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;(i=this.workspace.scrollbar)==null||i.setVisible(!1),Ll.getIsActive()&&(r=(this.flyout?.getWorkspace())?.getNavigator().getFirstNode())&&e.A().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(){if(this.hasContents()){this.contents.length=0;var e;(e=this.svgGroup)==null||e.classList.remove(`blocklyTrashFull`),this.closeFlyout()}}position(e,t){if(this.initialized){var n=mt(this.workspace,e);e=pt(n,new V(47,60),20,20,e,this.workspace),t=ht(e,20,n.vertical===Xs.TOP?ec.DOWN:ec.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 B(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 B(t,t+16+44+20,e,e+47+20)}onDragOver(){cd.mover.isMoving()||this.setLidOpen(this.wouldDelete_)}onDragExit(){cd.mover.isMoving()||this.setLidOpen(!1)}onDrop(){cd.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(N.TRASHCAN_OPEN))(e,this.workspace.id),b(e)}blockMouseDownWhenOpenable(e){!this.contentsIsOpen()&&this.hasContents()&&e.stopPropagation()}onDelete(e){if(!(this.workspace.options.maxTrashcanContents<=0||e.type!==N.BLOCK_DELETE||e.wasShadow)){if(!e.oldJson)throw Error(`Encountered a delete event without proper oldJson`);if(e=JSON.stringify(this.cleanBlockJson(e.oldJson)),!this.contents.includes(e)){for(this.contents.unshift(e);this.contents.length>this.workspace.options.maxTrashcanContents;)this.contents.pop();var t;(t=this.svgGroup)==null||t.classList.add(`blocklyTrashFull`)}}}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()}getGloballyUniqueId(){return this.uniqueId}};He(`
844
+ .blocklyTrash {
845
+ opacity: 0.4;
846
+ transition: opacity 0.08 ease-out;
847
+ }
848
+
849
+ .blocklyTrashLid {
850
+ transition: rotate 0.08s ease-out;
851
+ transform-origin: 46px 12px;
852
+ rotate: 0deg;
853
+ pointer-events: none;
854
+ }
855
+
856
+ .blocklyRTL .blocklyTrashLid {
857
+ transform-origin: 0px 12px;
858
+ }
859
+
860
+ .blocklyTrash.blocklyTrashFull .blocklyTrashLid {
861
+ rotate: 5deg;
862
+ }
863
+
864
+ .blocklyRTL .blocklyTrash.blocklyTrashFull .blocklyTrashLid {
865
+ rotate: -5deg;
866
+ }
867
+
868
+ .blocklyTrash.blocklyTrashOpen,
869
+ .blocklyTrash:hover,
870
+ .blocklyTrash:focus {
871
+ opacity: 0.8;
872
+ }
873
+
874
+ .blocklyTrash.blocklyTrashFull.blocklyTrashOpen .blocklyTrashLid,
875
+ .blocklyTrash.blocklyTrashFull:hover .blocklyTrashLid,
876
+ .blocklyTrash.blocklyTrashFull:focus .blocklyTrashLid {
877
+ rotate: 45deg;
878
+ }
879
+
880
+ .blocklyRTL .blocklyTrash.blocklyTrashFull.blocklyTrashOpen .blocklyTrashLid,
881
+ .blocklyRTL .blocklyTrash.blocklyTrashFull:hover .blocklyTrashLid,
882
+ .blocklyRTL .blocklyTrash.blocklyTrashFull:focus .blocklyTrashLid {
883
+ rotate: -45deg;
884
+ }
885
+ `);var Ep=class{constructor(e,t){this.procedureModelClass=e,this.parameterModelClass=t,this.priority=75}save(e){return e=e.getProcedureMap().getProcedures().map(e=>Oa(e)),e.length?e:null}load(e,t){var n=t.getProcedureMap();for(let r of e)n.add(ka(this.procedureModelClass,this.parameterModelClass,r,t))}clear(e){e.getProcedureMap().clear()}},Dp={};Dp.ProcedureSerializer=Ep,Dp.loadProcedure=ka,Dp.saveProcedure=Oa;var Op=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=r(M.VARIABLE_MODEL,`default`,void 0);e.forEach(e=>{n?.load(e,t)})}clear(e){e.getVariableMap().clear()}};gt(`variables`,new Op);var kp={};kp.VariableSerializer=Op;var Ap={blocks:Jl,exceptions:Kl,priorities:{BLOCKS:50,PROCEDURES:75,VARIABLES:100,WORKSPACE_COMMENTS:25},procedures:Dp,registry:lc,variables:kp,workspaceComments:dc,workspaces:{load:function(t,n,{recordUndo:r=!1}={}){var i=o(M.SERIALIZER,!0);if(i){i=Object.entries(i).sort((e,t)=>t[1].priority-e[1].priority);var a=e.Pc;e.Pc=r,(r=e.fd)||e.r(!0),_e(),n instanceof Sp&&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 Sp&&n.setResizesEnabled(!0),ve(),b(new(x(N.FINISHED_LOADING))(n)),e.r(r),e.Pc=a}},save:function(e){var t=Object.create(null),n=o(M.SERIALIZER,!0);for(let r in n){let i=n[r]?.save(e);i&&(t[r]=i)}return t}}};`Blockly`in globalThis||(globalThis.Blockly={Msg:Ns});var jp=class{load(e,t){return e=new Jd(t.getWorkspace(),t.targetWorkspace,e,!0),e.show(),new cf(e,`label`)}gapForItem(e,t){return t}disposeItem(e){e=e.getElement(),e instanceof Jd&&e.dispose()}getType(){return`label`}};t(M.FLYOUT_INFLATER,`label`,jp);var Mp=class extends dp{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&&D(this.selectedGlowFilter)}makeStartHat(){var e=this.START_HAT_HEIGHT,t=this.START_HAT_WIDTH,n=Kr(`c`,[k(25,-e),k(71,-e),k(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,Yr(-r*i,e)+Yr(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 Zr(`a`,`0 0,`+a,e,k((r?1:-1)*e,(t?-1:1)*e))+A(`v`,(t?-1:1)*i)+Zr(`a`,`0 0,`+a,e,k((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 Zr(`a`,`0 0,`+i,t,k((r?1:-1)*t,(n?-1:1)*t))+A(`v`,(n?-1:1)*e)+Zr(`a`,`0 0,`+i,t,k((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 U.INPUT_VALUE:case U.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 U.PREVIOUS_STATEMENT:case U.NEXT_STATEMENT:return this.NOTCH;default:throw Error(`Unknown type`)}}makeNotch(){function e(e){return Kr(`c`,[k(e*i/2,0),k(e*i*3/4,o/2),k(e*i,o)])+Xr([k(e*i,a)])+Kr(`c`,[k(e*i/4,o/2),k(e*i/2,o),k(e*i,o)])+A(`h`,e*r)+Kr(`c`,[k(e*i/2,0),k(e*i*3/4,-(o/2)),k(e*i,-o)])+Xr([k(e*i,-a)])+Kr(`c`,[k(e*i/4,-(o/2)),k(e*i/2,-o),k(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=Zr(`a`,`0 0,0`,e,k(-e,e)),n=Zr(`a`,`0 0,1`,e,k(-e,e));return{width:e,height:e,pathTop:t,pathBottom:Zr(`a`,`0 0,0`,e,k(e,e)),rightWidth:e,rightHeight:e,pathTopRight:n,pathBottomRight:Zr(`a`,`0 0,1`,e,k(e,e))}}generateSecondaryColour_(e){return nr(`#000`,e,.15)||e}generateTertiaryColour_(e){return nr(`#000`,e,.25)||e}createDom(e,t,n){super.createDom(e,t,n),e=w(I.DEFS,{},e),e=w(I.FILTER,{id:`blocklySelectedGlowFilter`+this.randomIdentifier,height:`160%`,width:`180%`,y:`-30%`,x:`-40%`},e),w(I.FEGAUSSIANBLUR,{in:`SourceGraphic`,stdDeviation:this.SELECTED_GLOW_SIZE},e),t=w(I.FECOMPONENTTRANSFER,{result:`outBlur`},e),w(I.FEFUNCA,{type:`table`,tableValues:`0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1`},t),w(I.FEFLOOD,{"flood-color":this.SELECTED_GLOW_COLOUR,"flood-opacity":1,result:`outColor`},e),w(I.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} .blocklyHighlightedConnectionPath {`,`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);`,`}`]}},Np=class extends fp{constructor(e,t){super(e,t)}draw(){var e=this.block_.pathObject;e.beginDrawing(),this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights(),e.setPath(this.outlinePath_+`
886
+ `+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(Q.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?A(`V`,e.yPos+n):``,this.outlinePath_+=t+e+(r?i.pathTopRight:``);return}}this.outlinePath_+=A(`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_+=Jr(e.xPos,this.info_.startY),this.outlinePath_+=A(`h`,e.width)}drawFlatBottom_(){var e=this.info_.bottomRow;this.positionNextConnection_(),this.outlinePath_+=A(`V`,e.baseline),this.outlinePath_+=A(`h`,-e.width)}drawInlineInput_(e){this.positionInlineInputConnection_(e);var t=e.input.name;e.connectedBlock||this.info_.isInsertionMarker||(e=qr(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 A(`h`,t)+e.shape.pathRightDown(n)+A(`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+A(`h`,-(t.notchOffset-r.width))+r.pathTop,a=e.height-2*r.height;t=r.pathBottom+A(`h`,t.notchOffset-r.width)+(t.connectedBottomNextConnection?``:t.shape.pathLeft),this.outlinePath_+=A(`H`,n)+i+A(`v`,a)+t+A(`H`,e.xPos+e.width),this.positionStatementInputConnection_(e)}drawConnectionHighlightPath(e){var t=e.connectionModel;if(t.type===U.NEXT_STATEMENT||t.type===U.PREVIOUS_STATEMENT||t.type===U.OUTPUT_VALUE&&!e.isDynamicShape)return super.drawConnectionHighlightPath(e);e=t.type===U.INPUT_VALUE?qr(e.connectionWidth,-e.height/2)+this.getInlineInputPath(e):qr(e.width,-e.height/2)+e.shape.pathDown(e.height);var n=t.getSourceBlock(),r;return(r=n.pathObject).addConnectionHighlight?.call(r,t,e,t.getOffsetInBlock(),n.RTL)}},Pp=class extends ku{constructor(e,t,n,r,i,a,o){if(super(ku.SKIP_SETUP),this.imageElement=this.clickHandler=null,this.flipRtl=this.isDirty_=this.EDITABLE=!1,this.altText=``,n=Number(O(n)),t=Number(O(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 V(t,n+Pp.Y_PADDING),this.imageHeight=n,typeof i==`function`&&(this.clickHandler=i),e!==ku.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`&&O(r)||``),this.setValue(O(e)))}configure_(e){super.configure_(e),e.flipRtl&&(this.flipRtl=e.flipRtl),e.alt&&(this.altText=O(e.alt))}initView(){this.imageElement=w(I.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_&&T(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 S(e,P.PRESENTATION),le(e,F.LABEL),!1;var t=this.getAriaValue()||``;return C(e,F.LABEL,t),!0}};Pp.Y_PADDING=1,Rr(`field_image`,Pp),Pp.prototype.DEFAULT_VALUE=``;var Fp=class extends ku{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(ku.SKIP_SETUP),this.spellcheck_=!0,this.htmlInput_=null,this.isTextValid_=this.isBeingEdited_=!1,this.onInputWrapper=this.onKeyDownWrapper=this.valueWhenEditorWasOpened_=null,this.fullBlockClickTarget_=!1,this.workspace_=null,this.SERIALIZABLE=!0,e!==ku.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 Au;this.isFullBlockField()||this.createBorderRect_(),this.createTextElement_(),this.fieldGroup_&&T(this.fieldGroup_,`blocklyField`),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot()),this.fieldGroup_&&T(this.fieldGroup_,`blocklyInputField`),this.recomputeAriaContext()}isFullBlockField(){var e=this.getSourceBlock();if(!e)throw new Au;var t;return this.fullBlockClickTarget_=!((t=this.getConstants())==null||!t.FULL_BLOCK_FIELDS)&&e.isSimpleReporter()}doValueInvalid_(e,t=!0){this.isBeingEdited_&&(this.isDirty_=!0,this.isTextValid_=!1,e=this.value_,this.value_=this.valueWhenEditorWasOpened_,this.sourceBlock_&&oe()&&this.value_!==e&&t&&b(new(x(N.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 Au;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_(){if(super.render_(),this.isBeingEdited_){var e=this.htmlInput_;this.isTextValid_?(E(e,`blocklyInvalidInput`),C(e,F.INVALID,!1)):(T(e,`blocklyInvalidInput`),C(e,F.INVALID,!0))}if(e=this.getSourceBlock(),!e)throw new Au;this.getConstants().FULL_BLOCK_FIELDS&&e.applyColour()}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&&(Ao||Eo||Do)?this.showPromptEditor():this.showInlineEditor(t,n)}showPromptEditor(){It(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 Au;lr(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 Au;e.r(!0);var n=Iu,r=this.getClickTarget_();if(!r)throw Error(`A click target has not been set.`);T(r,`blocklyEditing`),r=document.createElement(`input`),r.className=`blocklyHtmlInput`,r.setAttribute(`spellcheck`,this.spellcheck_);var i=this.workspace_.getAbsoluteScale(),a=this.getConstants().FIELD_TEXT_FONTSIZE*i+`pt`;return n.style.fontSize=a,r.style.fontSize=a,a=Fp.BORDERRADIUS*i+`px`,this.isFullBlockField()&&(a=this.getScaledBBox(),a=(a.bottom-a.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`)),r.style.borderRadius=a,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_&&oe()&&this.valueWhenEditorWasOpened_!==null&&this.valueWhenEditorWasOpened_!==this.value_&&(b(new(x(N.BLOCK_CHANGE))(this.sourceBlock_,`field`,this.name||null,this.valueWhenEditorWasOpened_,this.value_)),this.valueWhenEditorWasOpened_=null),e.r(!1),this.unbindInputEvents_();var t=Iu.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.`);E(t,`blocklyEditing`)}onFinishEditing_(){}bindInputEvents_(e){this.onKeyDownWrapper=p(e,`keydown`,this,this.onHtmlInputKeyDown_),this.onInputWrapper=p(e,`input`,this,this.onHtmlInputChange)}unbindInputEvents_(){this.onKeyDownWrapper&&=(h(this.onKeyDownWrapper),null),this.onInputWrapper&&=(h(this.onInputWrapper),null)}onHtmlInputKeyDown_(t){if(t.key===`Enter`)dr(this),jn(),t.stopPropagation();else if(t.key===`Escape`)this.setValue(this.htmlInput_.getAttribute(`data-untyped-default-value`),!1),dr(this),jn();else if(t.key===`Tab`){t.preventDefault();var n;let r=(n=this.workspace_)?.getNavigator(),i=e=>(e instanceof Fp||e instanceof af&&e.isSimpleReporter())&&e!==this.getSourceBlock();n=this;do n=t.shiftKey?r?.getOutNode(n):r?.getInNode(n);while(n&&!i(n));n=n instanceof af&&n.isSimpleReporter()?n.getFields().next().value:n,n instanceof Fp&&(dr(this),jn(),t=n.getSourceBlock(),n.isFullBlockField()&&t&&t instanceof af?e.A().focusNode(t):e.A().focusNode(n),n.showEditor())}}onHtmlInputChange(){var e=this.value_;this.setValue(this.getValueFromEditorText_(this.htmlInput_.value),!1),this.sourceBlock_&&oe()&&this.value_!==e&&b(new(x(N.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_(){wt().then(()=>{var e=this.getSourceBlock();if(!e)throw new Au;var t=Iu,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?.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=this.getSourceBlock()?.getRootBlock();return e instanceof af?(wi(this.workspace_,this.workspace_.getMetricsManager().getViewMetrics(!0),e)||this.resizeEditor_(),!0):!1}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;return!this.isCurrentlyEditable()||(r=this.getSourceBlock())!=null&&r.isInFlyout||(n=e.C.FIELD_LABEL_EDIT_PREFIX.replace(`%1`,n)),C(t,F.LABEL,n),!0}};Fp.BORDERRADIUS=4,e.zp=class extends Fp{constructor(e,t,n){super(e,t,n)}initView(){super.initView(),this.fieldGroup_&&T(this.fieldGroup_,`blocklyTextInputField`)}doClassValidation_(e){return e===void 0?null:`${e}`}static fromJson(e){return new this(O(e.text),void 0,e)}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_TEXT_INPUT}},Rr(`field_input`,e.zp),e.zp.prototype.DEFAULT_VALUE=``;var Ip=class extends Gf{constructor(e){super(e)}endsWithElemSpacer(){return!1}hasLeftSquareCorner(e){return!!e.outputConnection}hasRightSquareCorner(e){return!!e.outputConnection&&!e.statementInputCount&&!e.nextConnection}},Lp=class extends cp{constructor(e,t){if(super(e,t),this.connectedBottomNextConnection=!1,this.connectedBlock){for(e=this.connectedBlock;t=e.getNextBlock();)e=t;e.nextConnection||(this.height=this.connectedBlockHeight,this.connectedBottomNextConnection=!0)}}},Rp=class extends Uf{constructor(e){super(e),this.width=this.height=0,this.type|=Q.getType(`RIGHT_CONNECTION`)}},zp=class extends lp{constructor(e){super(e)}endsWithElemSpacer(){return!1}hasLeftSquareCorner(e){var t=(e.hat?e.hat===`cap`:this.constants_.ADD_START_HATS)&&!e.outputConnection&&!e.previousConnection;return!!e.outputConnection||t}hasRightSquareCorner(e){return!!e.outputConnection&&!e.statementInputCount&&!e.nextConnection}},Bp=class extends pp{constructor(e,t){super(e,t),this.isInline=!0,this.renderer_=e,this.constants_=this.renderer_.getConstants(),this.topRow=new zp(this.constants_),this.bottomRow=new Ip(this.constants_),this.isMultiRow=!t.getInputsInline()||t.isCollapsed(),this.hasStatementInput=t.statementInputCount>0,this.rightSide=this.outputConnection?new Rp(this.constants_):null,this.rightAlignedDummyInputs=new WeakMap}getRenderer(){return this.renderer_}measure(){this.createRows_(),this.addElemSpacing_(),this.addRowSpacing_(),this.adjustXPosition_(),this.computeBounds_(),this.alignRowElements_(),this.finalize_()}shouldStartNewRow_(t,n){return n?n instanceof Fd||t instanceof Id||n instanceof Id?!0:t instanceof e.En||t instanceof Pd||t instanceof Fd?!this.isInline||this.isMultiRow:!1:!1}getDesiredRowWidth_(e){return e.hasStatement?this.width-this.startX-(this.constants_.INSIDE_CORNERS.rightWidth||0):super.getDesiredRowWidth_(e)}getInRowSpacing_(e,t){return e&&t||!this.outputConnection||!this.outputConnection.isDynamicShape||this.hasStatementInput||this.bottomRow.hasNextConnection?!e&&t&&Q.isStatementInput(t)?this.constants_.STATEMENT_INPUT_PADDING_LEFT:e&&Q.isLeftRoundedCorner(e)&&t&&(Q.isPreviousConnection(t)||Q.isNextConnection(t))?t.notchOffset-this.constants_.CORNER_RADIUS:e&&Q.isLeftSquareCorner(e)&&t&&Q.isHat(t)||e&&Q.isField(e)&&e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING:this.constants_.NO_PADDING}getSpacerRowHeight_(e,t){if(Q.isTopRow(e)&&Q.isBottomRow(t))return this.constants_.EMPTY_BLOCK_SPACER_HEIGHT;var n=Q.isInputRow(e)&&e.hasStatement,r=Q.isInputRow(t)&&t.hasStatement;return r||n?(e=Math.max(this.constants_.NOTCH_HEIGHT,this.constants_.INSIDE_CORNERS.rightHeight||0),r&&n?Math.max(e,this.constants_.DUMMY_INPUT_MIN_HEIGHT):e):Q.isTopRow(e)?e.hasPreviousConnection||this.outputConnection&&!this.hasStatementInput?this.constants_.NO_PADDING:Math.abs(this.constants_.NOTCH_HEIGHT-this.constants_.CORNER_RADIUS):Q.isBottomRow(t)?this.outputConnection?!t.hasNextConnection&&this.hasStatementInput?Math.abs(this.constants_.NOTCH_HEIGHT-this.constants_.CORNER_RADIUS):this.constants_.NO_PADDING:Math.max(this.topRow.minHeight,Math.max(this.constants_.NOTCH_HEIGHT,this.constants_.CORNER_RADIUS))-this.constants_.CORNER_RADIUS:this.constants_.MEDIUM_PADDING}getSpacerRowWidth_(e,t){var n=this.width-this.startX;return Q.isInputRow(e)&&e.hasStatement||Q.isInputRow(t)&&t.hasStatement?Math.max(n,this.constants_.STATEMENT_INPUT_SPACER_MIN_WIDTH):n}getElemCenterline_(e,t){if(e.hasStatement&&!Q.isSpacer(t)&&!Q.isStatementInput(t))return e.yPos+this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT/2;if(Q.isInlineInput(t)){let n=t.connectedBlock;if(n&&n.outputConnection&&n.nextConnection)return e.yPos+n.height/2}return super.getElemCenterline_(e,t)}addInput_(t,n){if((t instanceof Pd||t instanceof Fd)&&n.hasDummyInput&&n.align===e.tn.LEFT&&t.align===e.tn.RIGHT)this.rightAlignedDummyInputs.set(n,t);else if(t instanceof Id){n.elements.push(new Lp(this.constants_,t)),n.hasStatement=!0,n.align===null&&(n.align=t.align);return}super.addInput_(t,n)}addAlignmentPadding_(e,t){if(this.rightAlignedDummyInputs.get(e)){let n;for(let t=0;t<e.elements.length;t++){let r=e.elements[t];if(Q.isSpacer(r)&&(n=r),Q.isField(r)&&r.parentInput===this.rightAlignedDummyInputs.get(e))break}if(n){n.width+=t,e.width+=t;return}}super.addAlignmentPadding_(e,t)}adjustXPosition_(){var e=this.constants_.NOTCH_OFFSET_LEFT+this.constants_.NOTCH_WIDTH,t=e;for(let i=2;i<this.rows.length-1;i+=2){var n=this.rows[i-1];let a=this.rows[i];var r=this.rows[i+1];if(n=i===2?!!this.topRow.hasPreviousConnection:!!n.followsStatement,r=i+2>=this.rows.length-1?!!this.bottomRow.hasNextConnection:!!r.precedesStatement,Q.isInputRow(a)&&a.hasStatement)a.measure(),t=a.width-(a.getLastInput()?.width??0)+e;else if(n&&(i===2||r)&&Q.isInputRow(a)&&!a.hasStatement){r=a.xPos,n=null;for(let e=0;e<a.elements.length;e++){let i=a.elements[e];Q.isSpacer(i)&&(n=i),!(n&&(Q.isField(i)||Q.isInput(i))&&r<t)||Q.isField(i)&&(i.field instanceof Ed||i.field instanceof Pp)||(n.width+=t-r),r+=i.width}}}}finalizeOutputConnection_(){if(this.outputConnection&&this.outputConnection.isDynamicShape){var e=this.outputConnection.shape;if(`isDynamic`in e&&e.isDynamic){for(var t=0,n=0;n<this.rows.length;n++){let e=this.rows[n];e.yPos=t,t+=e.height}this.height=t,n=this.bottomRow.hasNextConnection?this.height-this.bottomRow.descenderHeight:this.height,t=e.height(n),n=e.width(n),this.outputConnection.height=t,this.outputConnection.width=n,this.outputConnection.startX=n,this.outputConnection.connectionOffsetY=e.connectionOffsetY(t),this.outputConnection.connectionOffsetX=e.connectionOffsetX(n),e=0,this.hasStatementInput||this.bottomRow.hasNextConnection||(e=n,this.rightSide.height=t,this.rightSide.width=e,this.rightSide.centerline=t/2,this.rightSide.xPos=this.width+e),this.startX=n,this.width+=n+e,this.widthWithChildren+=n+e}}}finalizeHorizontalAlignment_(){if(this.outputConnection&&!this.hasStatementInput&&!this.bottomRow.hasNextConnection){for(var e=0,t=0;t<this.rows.length;t++){var n=this.rows[t];if(!Q.isInputRow(n))continue;e=n.elements[n.elements.length-2];let r=this.getNegativeSpacing_(n.elements[1]),i=this.getNegativeSpacing_(e);e=r+i;let a=this.constants_.MIN_BLOCK_WIDTH+this.outputConnection.width*2;this.width-e<a&&(e=this.width-a,r=e/2,i=e/2),n.elements.unshift(new Qf(this.constants_,-r)),n.elements.push(new Qf(this.constants_,-i))}if(e)for(this.width-=e,this.widthWithChildren-=e,this.rightSide.xPos-=e,t=0;t<this.rows.length;t++)n=this.rows[t],Q.isTopOrBottomRow(n)&&(n.elements[1].width-=e),n.width-=e,n.widthWithConnectedBlocks-=e}}getNegativeSpacing_(t){if(!t||!this.outputConnection)return 0;var n=this.outputConnection.width,r=this.outputConnection.shape.type,i=this.constants_;if(this.inputRows.length>1)switch(r){case i.SHAPES.ROUND:return r=this.constants_.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH,r=this.height/2>r?r:this.height/2,n-r*(1-Math.sin(Math.acos((r-this.constants_.SMALL_PADDING)/r)));default:return 0}if(Q.isInlineInput(t)){let e=t.connectedBlock;return t=e?e.pathObject.outputShapeType:t.shape.type,t==null||e&&e.outputConnection&&(e.statementInputCount||e.nextConnection)||r===i.SHAPES.HEXAGONAL&&r!==t?0:n-this.constants_.SHAPE_IN_SHAPE_PADDING[r][t]}return Q.isField(t)?r===i.SHAPES.ROUND&&t.field instanceof e.zp?n-2.75*i.GRID_UNIT:n-this.constants_.SHAPE_IN_SHAPE_PADDING[r][0]:Q.isIcon(t)?this.constants_.SMALL_PADDING:0}finalizeVerticalAlignment_(){if(!this.outputConnection)for(let r=2;r<this.rows.length-1;r+=2){let i=this.rows[r-1],a=this.rows[r],o=this.rows[r+1];var e=r===2,t=r+2>=this.rows.length-1?!!this.bottomRow.hasNextConnection:!!o.precedesStatement;if(e?this.topRow.hasPreviousConnection:i.followsStatement){var n=a.elements[1];if(n=a.elements.length===3&&n instanceof Yf&&(n.field instanceof Ed||n.field instanceof Pp),!e&&n)i.height-=this.constants_.SMALL_PADDING,o.height-=this.constants_.SMALL_PADDING,a.height-=this.constants_.MEDIUM_PADDING;else if(!e&&!t)i.height+=this.constants_.SMALL_PADDING;else if(t){for(e=!1,t=0;t<a.elements.length;t++)if(n=a.elements[t],Q.isInlineInput(n)&&n.connectedBlock&&!n.connectedBlock.isShadow()&&n.connectedBlock.getHeightWidth().height>=40){e=!0;break}e&&(i.height-=this.constants_.SMALL_PADDING,o.height-=this.constants_.SMALL_PADDING)}}}}finalize_(){this.finalizeOutputConnection_(),this.finalizeHorizontalAlignment_(),this.finalizeVerticalAlignment_(),super.finalize_(),this.rightSide&&(this.widthWithChildren+=this.rightSide.width)}},Vp=class extends mp{constructor(e,t,n){super(e,t,n),this.svgPathSelected=null,this.outlines=new Map,this.remainingOutlines=new Set,this.outputShapeType=null,this.constants=n}setPath(e){super.setPath(e),this.svgPathSelected&&this.svgPathSelected.setAttribute(`d`,e)}applyColour(e){super.applyColour(e);var t=e.getParent();e.isShadow()&&t&&this.svgPath.setAttribute(`stroke`,t.getColourTertiary());for(let e of this.outlines.values())e.setAttribute(`fill`,this.style.colourTertiary)}flipRTL(){super.flipRTL();for(let e of this.outlines.values())e.setAttribute(`transform`,`scale(-1 1)`)}updateSelected(e){this.setClass_(`blocklySelected`,e),e?this.svgPathSelected||(this.svgPathSelected=w(I.PATH,{class:`blocklyPath blocklyPathSelected`,stroke:this.svgPath.getAttribute(`stroke`)||``,fill:this.svgPath.getAttribute(`fill`)||``,d:this.svgPath.getAttribute(`d`)||``,transform:this.svgPath.getAttribute(`transform`)||``,role:P.PRESENTATION},this.svgRoot),this.svgRoot.appendChild(this.svgPathSelected)):this.svgPathSelected&&=(this.svgRoot.removeChild(this.svgPathSelected),null)}beginDrawing(){this.remainingOutlines.clear();for(let e of this.outlines.keys())this.remainingOutlines.add(e)}endDrawing(){if(this.remainingOutlines.size)for(let e of this.remainingOutlines)this.removeOutlinePath(e);this.remainingOutlines.clear()}setOutlinePath(e,t){e=this.getOutlinePath(e),e.setAttribute(`d`,t),e.setAttribute(`fill`,this.style.colourTertiary)}getOutlinePath(e){return this.outlines.has(e)||this.outlines.set(e,w(I.PATH,{class:`blocklyOutlinePath`,d:``},this.svgRoot)),this.remainingOutlines.delete(e),this.outlines.get(e)}removeOutlinePath(e){var t,n;(t=this.outlines.get(e))==null||(n=t.parentNode)==null||n.removeChild(this.outlines.get(e)),this.outlines.delete(e)}},Hp=class extends hp{constructor(e){super(e)}makeConstants_(){return new Mp}makeRenderInfo_(e){return new Bp(this,e)}makeDrawer_(e,t){return new Np(e,t)}makePathObject(e,t){return new Vp(e,t,this.getConstants())}getConstants(){return this.constants_}shouldHighlightConnection(e){return super.shouldHighlightConnection(e)||e.type===U.INPUT_VALUE}};Sa(`zelos`,Hp);var Up=class{constructor(e){this.staticConn=this.draggedConn=this.markerConn=this.fadedBlock=null,this.workspace=e.workspace}previewReplacement(t,n,r){e.Ka++;try{this.hidePreview(),this.fadedBlock=r,r.fadeForReplacement(!0),this.workspace.getRenderer().shouldHighlightConnection(n)&&(n.highlight(),this.staticConn=n)}finally{e.Ka--}}previewConnection(t,n){if(t!==this.draggedConn||n!==this.staticConn){e.Ka++;try{this.hidePreview(),this.shouldUseMarkerPreview(t,n)&&(this.markerConn=this.previewMarker(t,n)),this.workspace.getRenderer().shouldHighlightConnection(n)&&n.highlight(),this.workspace.getRenderer().shouldHighlightConnection(t)&&t.highlight(),this.draggedConn=t,this.staticConn=n}finally{e.Ka--}}}shouldUseMarkerPreview(e,t){return t.type===U.PREVIOUS_STATEMENT||t.type===U.NEXT_STATEMENT||!(this.workspace.getRenderer()instanceof Hp)}previewMarker(t,n){var r=t.getSourceBlock(),i=this.createInsertionMarker(r),a=this.getMatchingConnection(r,i,t);if(!a)return null;i.queueRender(),Tt(),a.connect(n);var o={x:n.x-a.x,y:n.y-a.y},s=a.getOffsetInBlock().clone();return wt().then(()=>{if(!i.isDeadOrDying()){e.Ka++;try{i?.positionNearConnection(a,o,s),i?.getSvgRoot().setAttribute(`visibility`,`visible`)}finally{e.Ka--}}}),a}serializeBlockToInsertionMarker(e){var t=an(e,{addCoordinates:!1,addInputBlocks:!1,addNextBlocks:!1,doFullSerialization:!1});if(!t)throw Error(`Failed to serialize source block. ${e.toDevString()}`);return t}createInsertionMarker(e){e=this.serializeBlockToInsertionMarker(e),e=sn(e,this.workspace);for(let t of e.getDescendants(!1))t.setInsertionMarker(!0);return e.initSvg(),e.getSvgRoot().setAttribute(`visibility`,`hidden`),e}getMatchingConnection(e,t,n){if(e=e.getConnections_(!0),t=t.getConnections_(!0),e.length!==t.length)return null;for(let r=0;r<e.length;r++)if(e[r]===n)return t[r];return null}hidePreview(){e.Ka++;try{this.staticConn&&=(this.staticConn.unhighlight(),null),this.draggedConn&&=(this.draggedConn.unhighlight(),null),this.fadedBlock&&=(this.fadedBlock.fadeForReplacement(!1),null),this.markerConn&&(this.hideInsertionMarker(this.markerConn),this.draggedConn=this.markerConn=null)}finally{e.Ka--}}hideInsertionMarker(e){var t=e.getSourceBlock(),n=t.outputConnection,r;if((r=t.previousConnection)!=null&&r.targetConnection||n!=null&&n.targetConnection)t.unplug(!0);else{let t;(t=e.targetBlock())==null||t.unplug(!1)}t.dispose()}dispose(){this.hidePreview()}};t(M.CONNECTION_PREVIEWER,`default`,Up);var Wp={};Wp.Align=e.tn,Wp.DummyInput=Pd,Wp.EndRowInput=Fd,Wp.Input=Nd,Wp.StatementInput=Id,Wp.ValueInput=e.En,Wp.inputTypes=e.he;var Gp=!1;e.Ip=class{constructor(e){this.forBlock=Object.create(null),this.FUNCTION_NAME_PLACEHOLDER_=`{leCUI8hutHZI4480Dc}`,this.STATEMENT_SUFFIX=this.STATEMENT_PREFIX=this.INFINITE_LOOP_TRAP=null,this.INDENT=` `,this.COMMENT_WRAP=60,this.ORDER_OVERRIDES=[],this.isInitialized=null,this.RESERVED_WORDS_=``,this.definitions_=Object.create(null),this.functionNames_=Object.create(null),this.nameDB_=void 0,this.name_=e,this.FUNCTION_NAME_PLACEHOLDER_REGEXP_=new RegExp(this.FUNCTION_NAME_PLACEHOLDER_,`g`)}workspaceToCode(e){e||=(console.warn(`No workspace specified in workspaceToCode call. Guessing.`),ms);var t=[];this.init(e),e=e.getTopBlocks(!0);for(let n=0,r;r=e[n];n++){let e=this.blockToCode(r);Array.isArray(e)&&(e=e[0]),e&&(r.outputConnection&&(e=this.scrubNakedValue(e),this.STATEMENT_PREFIX&&!r.suppressPrefixSuffix&&(e=this.injectId(this.STATEMENT_PREFIX,r)+e),this.STATEMENT_SUFFIX&&!r.suppressPrefixSuffix&&(e+=this.injectId(this.STATEMENT_SUFFIX,r))),t.push(e))}return t=t.join(`
887
+ `),t=this.finish(t),t=t.replace(/^\s+\n/,``),t=t.replace(/\n\s+$/,`
888
+ `),t=t.replace(/[ \t]+\n/g,`
889
+ `)}prefixLines(e,t){return t+e.replace(/(?!\n$)\n/g,`
890
+ `+t)}allNestedComments(e){var t=[];e=e.getDescendants(!0);for(let n=0;n<e.length;n++){let r=e[n].getCommentText();r&&t.push(r)}return t.length&&t.push(``),t.join(`
891
+ `)}blockToCode(e,t){if(this.isInitialized===!1&&console.warn(`CodeGenerator init was not called before blockToCode was called.`),!e)return``;if(!e.isEnabled())return t?``:this.blockToCode(e.getNextBlock());if(e.isInsertionMarker())return t?``:this.blockToCode(e.getChildren(!1)[0]);var n=this.forBlock[e.type];if(typeof n!=`function`)throw Error(`${this.name_} generator does not know how to generate code for block type "${e.type}".`);if(n=n.call(e,e,this),Array.isArray(n)){if(!e.outputConnection)throw TypeError(`Expecting string from statement block: `+e.type);return[this.scrub_(e,n[0],t),n[1]]}if(typeof n==`string`)return this.STATEMENT_PREFIX&&!e.suppressPrefixSuffix&&(n=this.injectId(this.STATEMENT_PREFIX,e)+n),this.STATEMENT_SUFFIX&&!e.suppressPrefixSuffix&&(n+=this.injectId(this.STATEMENT_SUFFIX,e)),this.scrub_(e,n,t);if(n===null)return``;throw SyntaxError(`Invalid code generated: `+n)}valueToCode(e,t,n){if(isNaN(n))throw TypeError(`Expecting valid order from block: `+e.type);var r=e.getInputTargetBlock(t);if(!r&&!e.getInput(t))throw ReferenceError(`Input "${t}" doesn't exist on "${e.type}"`);if(!r||(t=this.blockToCode(r),t===``))return``;if(!Array.isArray(t))throw TypeError(`Expecting tuple from value block: ${r.type} See developers.google.com/blockly/guides/create-custom-blocks/generating-code for more information`);if(e=t[0],t=t[1],isNaN(t))throw TypeError(`Expecting valid order from value block: `+r.type);if(!e)return``;r=!1;var i=Math.floor(n),a=Math.floor(t);if(i<=a&&(i!==a||i!==0&&i!==99)){for(r=!0,i=0;i<this.ORDER_OVERRIDES.length;i++)if(this.ORDER_OVERRIDES[i][0]===n&&this.ORDER_OVERRIDES[i][1]===t){r=!1;break}}return r&&(e=`(`+e+`)`),e}statementToCode(e,t){var n=e.getInputTargetBlock(t);if(!n&&!e.getInput(t))throw ReferenceError(`Input "${t}" doesn't exist on "${e.type}"`);if(e=this.blockToCode(n),typeof e!=`string`)throw TypeError(`Expecting code from statement block: `+(n&&n.type));return e&&=this.prefixLines(e,this.INDENT),e}addLoopTrap(e,t){return this.INFINITE_LOOP_TRAP&&(e=this.prefixLines(this.injectId(this.INFINITE_LOOP_TRAP,t),this.INDENT)+e),this.STATEMENT_SUFFIX&&!t.suppressPrefixSuffix&&(e=this.prefixLines(this.injectId(this.STATEMENT_SUFFIX,t),this.INDENT)+e),this.STATEMENT_PREFIX&&!t.suppressPrefixSuffix&&(e+=this.prefixLines(this.injectId(this.STATEMENT_PREFIX,t),this.INDENT)),e}injectId(e,t){return t=t.id.replace(/\$/g,`$$$$`),e.replace(/%1/g,`'`+t+`'`)}addReservedWords(e){this.RESERVED_WORDS_+=e+`,`}provideFunction_(t,n){if(!this.definitions_[t]){let r=this.nameDB_.getDistinctName(t,e.P.PROCEDURE);this.functionNames_[t]=r,Array.isArray(n)&&(n=n.join(`
892
+ `)),n=n.trim().replace(this.FUNCTION_NAME_PLACEHOLDER_REGEXP_,r);let i;for(;i!==n;)i=n,n=n.replace(/^(( {2})*) {2}/gm,`$1\0`);n=n.replace(/\0/g,this.INDENT),this.definitions_[t]=n}return this.functionNames_[t]}getVariableName(t){return this.getName(t,e.P.VARIABLE)}getProcedureName(t){return this.getName(t,e.P.PROCEDURE)}getName(e,t){if(!this.nameDB_)throw Error("Name database is not defined. You must initialize `nameDB_` in your generator class and call `init` first.");return this.nameDB_.getName(e,t)}init(){this.definitions_=Object.create(null),this.functionNames_=Object.create(null)}scrub_(e,t){return t}finish(e){return this.definitions_=Object.create(null),this.functionNames_=Object.create(null),e}scrubNakedValue(e){return e}};var Kp=class extends jf{constructor(e){super(e)}setMetrics_(e){if(this.isVisible()){var t=this.workspace_.getMetricsManager(),n=t.getScrollMetrics(),r=t.getViewMetrics();t=t.getAbsoluteMetrics(),typeof e.y==`number`&&(this.workspace_.scrollY=-(n.top+(n.height-r.height)*e.y)),this.workspace_.translate(this.workspace_.scrollX+t.left,this.workspace_.scrollY+t.top)}}getX(){if(!this.isVisible())return 0;var e=this.targetWorkspace.getMetricsManager(),t=e.getAbsoluteMetrics(),n=e.getViewMetrics();return e=e.getToolboxMetrics(),this.targetWorkspace.toolboxPosition===this.toolboxPosition_?this.targetWorkspace.getToolbox()?this.toolboxPosition_===H.LEFT?e.width:n.width-this.getWidth():this.toolboxPosition_===H.LEFT?0:n.width:this.toolboxPosition_===H.LEFT?0:n.width+t.left-this.getWidth()}getY(){return 0}position(){if(this.isVisible()&&this.targetWorkspace.isVisible()){var e=this.targetWorkspace.getMetricsManager().getViewMetrics();this.height_=e.height;var t=this.getWidth()-this.CORNER_RADIUS;this.setBackgroundPath(t,e.height-2*this.CORNER_RADIUS),e=this.getX(),t=this.getY(),this.positionAt_(this.getWidth(),this.getHeight(),e,t)}}setBackgroundPath(e,t){var n=this.toolboxPosition_===H.RIGHT,r=e+this.CORNER_RADIUS;r=[`M `+(n?r:0)+`,0`],r.push(`h`,n?-e:e),r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,+!n,n?-this.CORNER_RADIUS:this.CORNER_RADIUS,this.CORNER_RADIUS),r.push(`v`,Math.max(0,t)),r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,+!n,n?this.CORNER_RADIUS:-this.CORNER_RADIUS,this.CORNER_RADIUS),r.push(`h`,n?e:-e),r.push(`z`),this.svgBackground_.setAttribute(`d`,r.join(` `))}scrollToStart(){var e;(e=this.workspace_.scrollbar)==null||e.setY(0)}wheel_(e){var t=ee(e);if(t.y){let e=this.workspace_.getMetricsManager(),n=e.getScrollMetrics();t=e.getViewMetrics().top-n.top+t.y;let r;(r=this.workspace_.scrollbar)==null||r.setY(t),fr(this.workspace_),jn()}e.preventDefault(),e.stopPropagation()}layout_(e){this.workspace_.scale=this.targetWorkspace.scale;var t=this.MARGIN,n=this.RTL?t:t+this.tabWidth_;for(let r of e)r.getElement().moveBy(n,t),t+=r.getElement().getBoundingRectangle().getHeight()}getClientRect(){if(!this.svgGroup_||this.autoClose||!this.isVisible())return null;var e=this.svgGroup_.getBoundingClientRect(),t=e.left;return this.toolboxPosition_===H.LEFT?new B(-1e9,1e9,-1e9,t+e.width):new B(-1e9,1e9,t,1e9)}reflowInternal_(){this.workspace_.scale=this.getFlyoutScale();var e=this.getContents().reduce((e,t)=>Math.max(e,t.getElement().getBoundingRectangle().getWidth()),0);if(e+=this.MARGIN*1.5+this.tabWidth_,e*=this.workspace_.scale,e+=zs.scrollbarThickness,this.getWidth()!==e){if(this.RTL)for(let t of this.getContents()){let n=t.getElement().getBoundingRectangle().left,r=e/this.workspace_.scale-t.getElement().getBoundingRectangle().getWidth()-this.MARGIN-this.tabWidth_;t.getElement().moveBy(r-n,0)}this.targetWorkspace.scrollbar||this.autoClose||this.targetWorkspace.getFlyout()!==this||this.toolboxPosition_!==H.LEFT||this.targetWorkspace.translate(this.targetWorkspace.scrollX+e,this.targetWorkspace.scrollY),this.width_=e,this.position(),this.targetWorkspace.resizeContents(),this.targetWorkspace.recordDragTargets()}}};Kp.registryName=`verticalFlyout`,t(M.FLYOUTS_VERTICAL_TOOLBOX,`default`,Kp);var qp=class extends jf{constructor(e){super(e),this.horizontalLayout=!0}setMetrics_(e){if(this.isVisible()){var t=this.workspace_.getMetricsManager(),n=t.getScrollMetrics(),r=t.getViewMetrics();t=t.getAbsoluteMetrics(),typeof e.x==`number`&&(this.workspace_.scrollX=-(n.left+(n.width-r.width)*e.x)),this.workspace_.translate(this.workspace_.scrollX+t.left,this.workspace_.scrollY+t.top)}}getX(){return 0}getY(){if(!this.isVisible())return 0;var e=this.targetWorkspace.getMetricsManager(),t=e.getAbsoluteMetrics(),n=e.getViewMetrics();e=e.getToolboxMetrics();var r=this.toolboxPosition_===H.TOP;return this.targetWorkspace.toolboxPosition===this.toolboxPosition_?this.targetWorkspace.getToolbox()?r?e.height:n.height-this.getHeight():r?0:n.height:r?0:n.height+t.top-this.getHeight()}position(){if(this.isVisible()&&this.targetWorkspace.isVisible()){var e=this.targetWorkspace.getMetricsManager().getViewMetrics();this.width_=e.width,e=e.width-2*this.CORNER_RADIUS;var t=this.getHeight()-this.CORNER_RADIUS;this.setBackgroundPath(e,t),e=this.getX(),t=this.getY(),this.positionAt_(this.getWidth(),this.getHeight(),e,t)}}setBackgroundPath(e,t){var n=this.toolboxPosition_===H.TOP,r=[`M 0,`+(n?0:this.CORNER_RADIUS)];n?(r.push(`h`,e+2*this.CORNER_RADIUS),r.push(`v`,t),r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,1,-this.CORNER_RADIUS,this.CORNER_RADIUS),r.push(`h`,-e),r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,1,-this.CORNER_RADIUS,-this.CORNER_RADIUS)):(r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,1,this.CORNER_RADIUS,-this.CORNER_RADIUS),r.push(`h`,e),r.push(`a`,this.CORNER_RADIUS,this.CORNER_RADIUS,0,0,1,this.CORNER_RADIUS,this.CORNER_RADIUS),r.push(`v`,t),r.push(`h`,-e-2*this.CORNER_RADIUS)),r.push(`z`),this.svgBackground_.setAttribute(`d`,r.join(` `))}scrollToStart(){var e;(e=this.workspace_.scrollbar)==null||e.setX(this.RTL?1/0:0)}wheel_(e){var t=ee(e);if(t=t.x||t.y){let e=this.workspace_.getMetricsManager(),n=e.getScrollMetrics();t=e.getViewMetrics().left-n.left+t;let r;(r=this.workspace_.scrollbar)==null||r.setX(t),fr(this.workspace_),jn()}e.preventDefault(),e.stopPropagation()}layout_(e){this.workspace_.scale=this.targetWorkspace.scale;var t=this.MARGIN,n=t+this.tabWidth_;this.RTL&&(e=e.reverse());for(let r of e)e=r.getElement().getBoundingRectangle(),e=this.RTL?n+e.getWidth():n,r.getElement().moveBy(e,t),n+=r.getElement().getBoundingRectangle().getWidth()}getClientRect(){if(!this.svgGroup_||this.autoClose||!this.isVisible())return null;var e=this.svgGroup_.getBoundingClientRect(),t=e.top;return this.toolboxPosition_===H.TOP?new B(-1e9,t+e.height,-1e9,1e9):new B(t,1e9,-1e9,1e9)}reflowInternal_(){this.workspace_.scale=this.getFlyoutScale();var e=this.getContents().reduce((e,t)=>Math.max(e,t.getElement().getBoundingRectangle().getHeight()),0);e+=this.MARGIN*1.5,e*=this.workspace_.scale,e+=zs.scrollbarThickness,this.getHeight()!==e&&(this.targetWorkspace.scrollbar||this.autoClose||this.targetWorkspace.getFlyout()!==this||this.toolboxPosition_!==H.TOP||this.targetWorkspace.translate(this.targetWorkspace.scrollX,this.targetWorkspace.scrollY+e),this.height_=e,this.position(),this.targetWorkspace.resizeContents(),this.targetWorkspace.recordDragTargets())}};t(M.FLYOUTS_HORIZONTAL_TOOLBOX,`default`,qp);var Jp=class extends id{constructor(e,t,n,r,i){super(ku.SKIP_SETUP),this.defaultType=``,this.variableTypes=[],this.variable=null,this.SERIALIZABLE=!0,this.menuGenerator_=Jp.dropdownCreate,this.defaultVariableName=typeof e==`string`?e:``,this.size_=new V(0,0),e!==ku.SKIP_SETUP&&(i?this.configure_(i):this.setTypes(n,r),t&&this.setValidator(t))}configure_(e){super.configure_(e),this.setTypes(e.variableTypes,e.defaultType)}initModel(){var t=this.getSourceBlock();if(!t)throw new Au;this.variable||(t=e.Vd(t.workspace,null,this.defaultVariableName,this.defaultType),this.doValueUpdate_(t.getId()))}initView(){super.initView(),T(this.fieldGroup_,`blocklyVariableField`)}shouldAddBorderRect_(){var e=this.getSourceBlock();if(!e)throw new Au;return super.shouldAddBorderRect_()&&(!this.getConstants().FIELD_DROPDOWN_NO_BORDER_RECT_SHADOW||e.type!==`variables_get`)}fromXml(t){var n=this.getSourceBlock();if(!n)throw new Au;var r=t.getAttribute(`id`),i=t.textContent,a=t.getAttribute(`variabletype`)||t.getAttribute(`variableType`)||``;if(n=e.Vd(n.workspace,r,i,a),a!==null&&a!==n.getType())throw Error(`Serialized variable type with id '`+n.getId()+`' had type `+n.getType()+`, and does not match variable field that references it: `+jr(t)+`.`);this.setValue(n.getId())}toXml(e){return this.initModel(),e.id=this.variable.getId(),e.textContent=this.variable.getName(),this.variable.getType()&&e.setAttribute(`variabletype`,this.variable.getType()),e}saveState(e){var t=this.saveLegacyState(Jp);return t===null?(this.initModel(),t={id:this.variable.getId()},e&&(t.name=this.variable.getName(),t.type=this.variable.getType()),t):t}loadState(t){var n=this.getSourceBlock();if(!n)throw new Au;this.loadLegacyState(Jp,t)||(t=e.Vd(n.workspace,t.id||null,t.name,t.type||``),this.setValue(t.getId()))}setSourceBlock(e){if(e.isShadow())throw Error(`Variable fields are not allowed to exist on shadow blocks.`);super.setSourceBlock(e)}getValue(){return this.variable?this.variable.getId():null}getText(){return this.variable?this.variable.getName():``}getVariable(){return this.variable}getDefaultType(){return this.defaultType}getValidator(){return this.variable?this.validator_:null}doClassValidation_(t){if(t===null)return null;var n=this.getSourceBlock();if(!n)throw new Au;return n=e.Ud(n.workspace,t),n?(n=n.getType(),this.typeIsAllowed(n)?t:(console.warn(`Variable type doesn't match this field! Type was `+n),null)):(console.warn(`Variable id doesn't point to a real variable! ID was `+t),null)}doValueUpdate_(t){var n=this.getSourceBlock();if(!n)throw new Au;this.variable=e.Ud(n.workspace,t),super.doValueUpdate_(t)}typeIsAllowed(e){var t=this.getVariableTypes();if(!t)return!0;for(let n=0;n<t.length;n++)if(e===t[n])return!0;return!1}getVariableTypes(){if(this.variableTypes)return this.variableTypes;if(!this.sourceBlock_||this.sourceBlock_.isDeadOrDying())return[``];var e=this.sourceBlock_.workspace.getVariableMap().getTypes();if(this.sourceBlock_.isInFlyout){let t=this.sourceBlock_.workspace.getPotentialVariableMap();if(!t)return e;e=Array.from(new Set([...e,...t.getTypes()]))}return e}setTypes(e=null,t=``){var n=this.getText();if(Array.isArray(e)){if(e.length===0)throw Error(`'variableTypes' of field variable ${n} was an empty list. If you want to include all variable types, pass 'null' instead.`);n=!1;for(let r=0;r<e.length;r++)e[r]===t&&(n=!0);if(!n)throw Error(`Invalid default type '`+t+`' in the definition of a FieldVariable`)}else if(e!==null)throw Error(`'variableTypes' was not an array or null in the definition of FieldVariable ${n}`);this.defaultType=t,this.variableTypes=e}refreshVariableName(){this.forceRerender()}onItemSelected_(t,n){if(t=n.getValue(),this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()){if(t===`RENAME_VARIABLE_ID`&&this.variable){e.Qd(this.sourceBlock_.workspace,this.variable);return}if(t===`DELETE_VARIABLE_ID`&&this.variable){t=this.variable.getWorkspace(),e.Yd(t,this.variable,this.sourceBlock_);return}}this.setValue(t)}referencesVariables(){return!0}static fromJson(e){return new this(O(e.variable),void 0,void 0,void 0,e)}static dropdownCreate(){if(!this.variable)throw Error(`Tried to call dropdownCreate on a variable field with no variable selected.`);var t=this.getText(),n=[],r=this.getSourceBlock();if(r&&!r.isDeadOrDying()){r=r.workspace;let e=this.getVariableTypes();for(let t=0;t<e.length;t++){let o=e[t],s=r.getVariableMap().getVariablesOfType(o);if(n=n.concat(s),r.isFlyout){var i=void 0,a=void 0;n=n.concat((a=(i=r.getPotentialVariableMap())?.getVariablesOfType(o))??[])}}}for(n.sort(nn),i=[],a=0;a<n.length;a++)i[a]=[n[a].getName(),n[a].getId()];return i.push([e.C.RENAME_VARIABLE.replace(`%1`,t),`RENAME_VARIABLE_ID`]),e.C.DELETE_VARIABLE&&i.push([e.C.DELETE_VARIABLE.replace(`%1`,t),`DELETE_VARIABLE_ID`]),i}getAriaValue(){return e.C.FIELD_LABEL_VARIABLE.replace(`%1`,super.getAriaValue())}};Rr(`field_variable`,Jp);var Yp=class extends Fp{constructor(e,t,n,r,i,a){super(ku.SKIP_SETUP),this.min_=-1/0,this.max_=1/0,this.precision_=0,this.decimalPlaces=null,this.spellcheck_=!1,e!==ku.SKIP_SETUP&&(a?this.configure_(a):this.setConstraints(t,n,r),this.setValue(e),i&&this.setValidator(i))}configure_(e){super.configure_(e),this.setMinInternal(e.min),this.setMaxInternal(e.max),this.setPrecisionInternal(e.precision)}setConstraints(e,t,n){this.setMinInternal(e),this.setMaxInternal(t),this.setPrecisionInternal(n),this.setValue(this.getValue())}setMin(e){this.setMinInternal(e),this.setValue(this.getValue())}setMinInternal(e){e==null?this.min_=-1/0:(e=Number(e),isNaN(e)||(this.min_=e))}getMin(){return this.min_}setMax(e){this.setMaxInternal(e),this.setValue(this.getValue())}setMaxInternal(e){e==null?this.max_=1/0:(e=Number(e),isNaN(e)||(this.max_=e))}getMax(){return this.max_}setPrecision(e){this.setPrecisionInternal(e),this.setValue(this.getValue())}setPrecisionInternal(e){this.precision_=Number(e)||0;var t=String(this.precision_);t.includes(`e`)&&(t=this.precision_.toLocaleString(`en-US`,{maximumFractionDigits:20}));var n=t.indexOf(`.`);this.decimalPlaces=n===-1?e?0:null:t.length-n-1}getPrecision(){return this.precision_}doClassValidation_(e){return e===null||(e=`${e}`.replace(/O/gi,`0`),e=e.replace(/,/g,``),e=e.replace(/infinity/i,`Infinity`),e=Number(e||0),isNaN(e))?null:(e=Math.min(Math.max(e,this.min_),this.max_),this.precision_&&isFinite(e)&&(e=Math.round(e/this.precision_)*this.precision_),this.decimalPlaces!==null&&(e=Number(e.toFixed(this.decimalPlaces))),e)}widgetCreate_(){var e=super.widgetCreate_();return this.min_>-1/0&&(e.min=`${this.min_}`),this.max_<1/0&&(e.max=`${this.max_}`),e}initView(){super.initView(),this.fieldGroup_&&T(this.fieldGroup_,`blocklyNumberField`)}static fromJson(e){return new this(e.value,void 0,void 0,void 0,void 0,e)}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_NUMBER}};Rr(`field_number`,Yp),Yp.prototype.DEFAULT_VALUE=0;var Xp=class extends Ed{constructor(e,t,n){super(String(e??``),t,n),this.EDITABLE=!1,this.SERIALIZABLE=!0}static fromJson(e){return new this(O(e.text),void 0,e)}};Rr(`field_label_serializable`,Xp);var Zp=class extends ku{constructor(e,t,n){super(ku.SKIP_SETUP),this.SERIALIZABLE=!0,this.value_=this.value_,this.checkChar=Zp.CHECK_CHAR,e!==ku.SKIP_SETUP&&(n&&this.configure_(n),this.setValue(e),t&&this.setValidator(t))}configure_(e){super.configure_(e),e.checkCharacter&&(this.checkChar=e.checkCharacter)}saveState(){var e=this.saveLegacyState(Zp);return e===null?this.getValueBoolean():e}initView(){super.initView();var e=this.getTextElement();T(this.fieldGroup_,`blocklyCheckboxField`),e.style.display=this.value_?`block`:`none`,this.recomputeAriaContext()}render_(){this.textContent_&&(this.textContent_.nodeValue=this.getDisplayText_()),this.updateSize_(this.getConstants().FIELD_CHECKBOX_X_OFFSET)}getDisplayText_(){return this.checkChar}setCheckCharacter(e){this.checkChar=e||Zp.CHECK_CHAR,this.forceRerender()}showEditor_(){this.setValue(!this.value_)}doClassValidation_(e){return e===!0||e===`TRUE`?`TRUE`:e===!1||e===`FALSE`?`FALSE`:null}doValueUpdate_(e){this.value_=this.convertValueToBool(e),this.textElement_&&(this.textElement_.style.display=this.value_?`block`:`none`),this.recomputeAriaContext()}getValue(){return this.value_?`TRUE`:`FALSE`}getValueBoolean(){return this.value_}getText(){return String(this.convertValueToBool(this.value_))}convertValueToBool(e){return typeof e==`string`?e===`TRUE`:!!e}getAriaTypeName(){return this.ariaTypeName||e.C.ARIA_TYPE_FIELD_CHECKBOX}getAriaValue(){return this.convertValueToBool(this.value_)?e.C.FIELD_LABEL_CHECKBOX_CHECKED:e.C.FIELD_LABEL_CHECKBOX_UNCHECKED}static fromJson(e){return new this(e.checked,void 0,e)}recomputeAriaContext(){if(!super.recomputeAriaContext())return!1;var e=this.getFocusableElement();C(e,F.HIDDEN,!1),S(e,P.CHECKBOX);var t=this.convertValueToBool(this.value_);return C(e,F.CHECKED,t),t=this.getAriaTypeName(),C(e,F.LABEL,t),!0}};Zp.CHECK_CHAR=`✓`,Rr(`field_checkbox`,Zp),Zp.prototype.DEFAULT_VALUE=!1;var Qp=class{constructor(e){this.draggable=e,this.dragTarget=null,this.startLoc=e.getRelativeToSurfaceXY()}onDragStart(t){return e.fd||e.r(!0),this.draggable=this.draggable.startDrag(t),this.startLoc=this.draggable.getRelativeToSurfaceXY(),this.draggable}onDrag(e,t){this.moveDraggable(e,t),ji(this.draggable)&&this.draggable.setDeleteStyle(this.wouldDeleteDraggable(this.draggable.getRelativeToSurfaceXY(),this.draggable)),this.updateDragTarget(this.draggable.getRelativeToSurfaceXY())}updateDragTarget(e){if(e=this.draggable.workspace.getDragTarget(e),this.dragTarget!==e){let t;(t=this.dragTarget)==null||t.onDragExit(this.draggable),e?.onDragEnter(this.draggable)}e?.onDragOver(this.draggable),this.dragTarget=e}moveDraggable(e,t){t=this.pixelsToWorkspaceUnits(t),t=z.sum(this.startLoc,t),this.draggable.drag(t,e)}wouldDeleteDraggable(e,t){return(e=this.draggable.workspace.getDragTarget(e))&&this.draggable.workspace.getComponentManager().hasCapability(e.id,Es.Capability.DELETE_AREA)?e.wouldDelete(t):!1}onDragEnd(t){var n=e.fd;if(this.draggable.workspace.getDragTarget(this.draggable.getRelativeToSurfaceXY())){var r;(r=this.dragTarget)==null||r.onDrop(this.draggable)}r=!1,this.shouldReturnToStart(this.draggable.getRelativeToSurfaceXY(),this.draggable)&&(r=!0,this.draggable.revertDrag());var i=ji(this.draggable)&&this.wouldDeleteDraggable(this.draggable.getRelativeToSurfaceXY(),this.draggable);i&&ji(this.draggable)?(this.draggable.endDrag(t,Yd.DELETE),e.r(n),this.draggable.dispose()):this.draggable.endDrag(t,r?Yd.REVERT:Yd.COMMIT),e.r(!1),!i&&Se(this.draggable)&&e.A().focusNode(this.draggable)}onDragRevert(){this.draggable.revertDrag(),Se(this.draggable)&&e.A().focusNode(this.draggable)}shouldReturnToStart(e,t){return(e=this.draggable.workspace.getDragTarget(e))?e.shouldPreventMove(t):!1}pixelsToWorkspaceUnits(e){return e=new z(e.x/this.draggable.workspace.scale,e.y/this.draggable.workspace.scale),this.draggable.workspace.isMutator&&e.scale(1/this.draggable.workspace.options.parentWorkspace.scale),e}};t(M.BLOCK_DRAGGER,`default`,Qp);var $p={};$p.BlockDragStrategy=tf,$p.BubbleDragStrategy=fd,$p.CommentDragStrategy=Ku,$p.Dragger=Qp;var em={};em.BottomRow=Ip,em.ConstantProvider=Mp,em.Drawer=Np,em.PathObject=Vp,em.RenderInfo=Bp,em.Renderer=Hp,em.RightConnectionShape=Rp,em.StatementInput=Lp,em.TopRow=zp,to();var tm={};tm.registerCleanup=La,tm.registerCollapse=za,tm.registerCollapseExpandBlock=Ja,tm.registerComment=Ka,tm.registerCommentCreate=eo,tm.registerCommentDelete=Qa,tm.registerCommentDuplicate=$a,tm.registerCommentOptions=function(){$a(),Qa(),eo()},tm.registerDefaultOptions=to,tm.registerDelete=Xa,tm.registerDeleteAll=Wa,tm.registerDisable=Ya,tm.registerDuplicate=Ga,tm.registerExpand=Ba,tm.registerHelp=Za,tm.registerInline=qa,tm.registerRedo=Ia,tm.registerUndo=Fa;var nm=class{load(e,t){return e=new Jd(t.getWorkspace(),t.targetWorkspace,e,!1),e.show(),new cf(e,`button`)}gapForItem(e,t){return t}disposeItem(e){e=e.getElement(),e instanceof Jd&&e.dispose()}getType(){return`button`}};t(M.FLYOUT_INFLATER,`button`,nm);var rm={};rm.Bubble=J,rm.MiniWorkspaceBubble=md,rm.TextBubble=nf,rm.TextInputBubble=xd;var im=class{constructor(){this.permanentlyDisabledBlocks=new Set,this.listeners=new Map,this.capacityWrapper=this.filterFlyoutBasedOnCapacity.bind(this)}load(e,t){return this.setFlyout(t),e=this.createBlock(e,t.getWorkspace()),e.isEnabled()?this.updateStateBasedOnCapacity(e):this.permanentlyDisabledBlocks.add(e),e.getDescendants(!1).forEach(e=>{e.isInFlyout=!0,e=e.getFocusableElement(),C(e,F.HIDDEN,!0),S(e,P.PRESENTATION)}),t=e.getFocusableElement(),le(t,F.HIDDEN),S(t,P.LISTITEM),this.addBlockListeners(e),new cf(e,`block`)}createBlock(t,n){return t.blockxml?(t=typeof t.blockxml==`string`?e.tc(t.blockxml):t.blockxml,n=Nr(t,n)):(t.enabled===void 0&&(t.enabled=t.disabled!==`true`&&t.disabled!==!0),t.disabledReasons===void 0&&t.enabled===!1&&(t.disabledReasons=[`MANUALLY_DISABLED`]),`x`in t&&delete t.x,`y`in t&&delete t.y,n=cn(t,n)),n}gapForItem(t,n){if(t.gap)var r=parseInt(String(t.gap));else t.blockxml&&(t=typeof t.blockxml==`string`?e.tc(t.blockxml):t.blockxml,r=parseInt(t.getAttribute(`gap`)));return!r||isNaN(r)?n:r}disposeItem(e){e=e.getElement(),e instanceof af&&(this.removeListeners(e.id),e.dispose(!1,!1))}removeListeners(e){(this.listeners.get(e)??[]).forEach(e=>h(e)),this.listeners.delete(e)}setFlyout(e){if(this.flyout!==e){if(this.flyout){let e;(e=this.flyout.targetWorkspace)==null||e.removeChangeListener(this.capacityWrapper)}this.flyout=e;var t;(t=this.flyout.targetWorkspace)==null||t.addChangeListener(this.capacityWrapper)}}updateStateBasedOnCapacity(e){for(var t=this.flyout?.targetWorkspace?.isCapacityAvailable(Le(e));e;)e.setDisabledReason(!t,`WORKSPACE_AT_BLOCK_CAPACITY`),e=e.getNextBlock()}addBlockListeners(e){var t=[];t.push(p(e.getSvgRoot(),`pointerdown`,e,t=>{var n=this.flyout?.targetWorkspace?.getGesture(t);n&&this.flyout&&(n.setStartBlock(e),n.handleFlyoutStart(t,this.flyout))})),t.push(m(e.getSvgRoot(),`pointermove`,null,()=>{var t,n;(t=this.flyout)!=null&&(n=t.targetWorkspace)!=null&&n.isDragging()||e.addSelect()})),t.push(m(e.getSvgRoot(),`pointerleave`,null,()=>{var t,n;(t=this.flyout)!=null&&(n=t.targetWorkspace)!=null&&n.isDragging()||e.removeSelect()})),this.listeners.set(e.id,t)}filterFlyoutBasedOnCapacity(e){!this.flyout||e&&e.type!==N.BLOCK_CREATE&&e.type!==N.BLOCK_DELETE||this.flyout.getWorkspace().getTopBlocks(!1).forEach(e=>{this.permanentlyDisabledBlocks.has(e)||this.updateStateBasedOnCapacity(e)})}getType(){return`block`}};t(M.FLYOUT_INFLATER,`block`,im);var am=class extends dp{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;`,`}`])}},om=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_+`
893
+ `+this.inlineSteps_}drawTopCorner(e){this.steps_+=Jr(e.xPos,this.info_.startY);for(let t=0,n;n=e.elements[t];t++)Q.isLeftSquareCorner(n)?this.steps_+=this.highlightConstants_.START_POINT:Q.isLeftRoundedCorner(n)?this.steps_+=this.outsideCornerPaths_.topLeft(this.RTL_):Q.isPreviousConnection(n)?this.steps_+=this.notchPaths_.pathLeft:Q.isHat(n)?this.steps_+=this.startPaths_.path(this.RTL_):Q.isSpacer(n)&&n.width!==0&&(this.steps_+=A(`H`,n.xPos+n.width-this.highlightOffset));this.steps_+=A(`H`,e.xPos+e.width-this.highlightOffset)}drawJaggedEdge_(e){this.info_.RTL&&(this.steps_+=this.jaggedTeethPaths_.pathLeft+A(`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_+=qr(t.xPos+t.width-this.highlightOffset,e.yPos)+this.puzzleTabPaths_.pathDown(this.RTL_)+A(`v`,n)}else this.steps_+=qr(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_+=qr(t.xPos,e.yPos)+this.insideCornerPaths_.pathTop(this.RTL_)+A(`v`,n)+this.insideCornerPaths_.pathBottom(this.RTL_)+Yr(e.width-t.xPos-this.insideCornerPaths_.width,0)}else this.steps_+=qr(t.xPos,e.yPos+e.height)+this.insideCornerPaths_.pathBottom(this.RTL_)+Yr(e.width-t.xPos-this.insideCornerPaths_.width,0)}drawRightSideRow(e){var t=e.xPos+e.width-this.highlightOffset;e instanceof op&&e.followsStatement&&(this.steps_+=A(`H`,t)),this.RTL_&&(this.steps_+=A(`H`,t),e.height>this.highlightOffset&&(this.steps_+=A(`V`,e.yPos+e.height-this.highlightOffset)))}drawBottomRow(e){if(this.RTL_)this.steps_+=A(`V`,e.baseline-this.highlightOffset);else{let t=this.info_.bottomRow.elements[0];Q.isLeftSquareCorner(t)?this.steps_+=qr(e.xPos+this.highlightOffset,e.baseline-this.highlightOffset):Q.isLeftRoundedCorner(t)&&(this.steps_+=qr(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_+=qr(this.info_.startX,e):(this.steps_+=qr(this.info_.startX+this.highlightOffset,this.info_.bottomRow.baseline-this.highlightOffset),this.steps_+=A(`V`,e)),this.steps_+=this.puzzleTabPaths_.pathUp(this.RTL_)),this.RTL_||(e=this.info_.topRow,Q.isLeftRoundedCorner(e.elements[0])?this.steps_+=A(`V`,this.outsideCornerPaths_.height):this.steps_+=A(`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_+=qr(n-t,a)+A(`v`,r)+this.puzzleTabPaths_.pathDown(this.RTL_)+A(`v`,e)+A(`h`,i)):this.inlineSteps_+=qr(e.xPos+e.width+t,a)+A(`v`,e.height)+A(`h`,-i)+qr(n,r+e.connectionOffsetY)+this.puzzleTabPaths_.pathDown(this.RTL_)}},sm=class extends fp{constructor(e,t){super(e,t),this.highlighter_=new om(t)}draw(){this.drawOutline_(),this.drawInternals_(),this.updateConnectionHighlights();var e=this.block_.pathObject;e.setPath(this.outlinePath_+`
894
+ `+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_+=A(`H`,e.xPos+e.width)+A(`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)}}},cm=class{constructor(e){this.OFFSET=.5,this.constantProvider=e,this.START_POINT=Jr(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=Jr(n,n)+Zr(`a`,`0 0,0`,e,k(-n-t,e-n)),i=Zr(`a`,`0 0,0`,e+t,k(e+t,e+t)),a=Jr(n,-n)+Zr(`a`,`0 0,0`,e+t,k(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=Jr(n,n)+Zr(`a`,`0 0,1`,e-t,k(e-n,-n+t)),i=Jr(t,e)+Zr(`a`,`0 0,1`,e-t,k(e,-e+t)),a=-n,o=Jr(n,a)+Zr(`a`,`0 0,1`,e-t,k(-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=Jr(-2,-t+2.5+.9)+Yr(e*-.45,-2.1),r=A(`v`,2.5)+Jr(-e*.97,2.5)+Kr(`q`,[k(-e*.05,10),k(e*.3,9.5)])+Jr(e*.67,-1.9)+A(`v`,2.5),i=A(`v`,-1.5)+Jr(e*-.92,-.5)+Kr(`q`,[k(e*-.19,-5.5),k(0,-11)])+Jr(e*.92,1),a=Jr(-5,t-.7)+Yr(e*.46,-2.1);return{width:e,height:t,pathUp(e){return e?n:i},pathDown(e){return e?r:a}}}makeNotch(){return{pathLeft:A(`h`,this.OFFSET)+this.constantProvider.NOTCH.pathLeft}}makeJaggedTeeth(){return{pathLeft:Yr(5.1,2.6)+Jr(-10.2,6.8)+Yr(5.1,2.6),height:12,width:10.2}}makeStartHat(){var e=this.constantProvider.START_HAT.height,t=Jr(25,-8.7)+Kr(`c`,[k(29.7,-6.2),k(57.2,-.5),k(75,8.7)]),n=Kr(`c`,[k(17.8,-9.2),k(45.3,-14.9),k(75,-8.7)])+qr(100.5,e+.5);return{path(e){return e?t:n}}}},lm=class extends $f{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)}},um=class extends cp{constructor(e,t){super(e,t),this.constants_=e,this.connectedBlock&&(this.height+=this.constants_.DARK_PATH_OFFSET)}},dm=class extends pp{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 Id||(this.bottomRow.minHeight=this.constants_.MEDIUM_PADDING-this.constants_.DARK_PATH_OFFSET)}addInput_(t,n){this.isInline&&t instanceof e.En?(n.elements.push(new lm(this.constants_,t)),n.hasInlineInput=!0):t instanceof Id?(n.elements.push(new um(this.constants_,t)),n.hasStatement=!0):t instanceof e.En?(n.elements.push(new Jf(this.constants_,t)),n.hasExternalInput=!0):(t instanceof Pd||t instanceof Fd)&&(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 Qf(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 Qf(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 Qf(this.constants_,t)))}}}getInRowSpacing_(e,t){if(!e)return t&&Q.isField(t)&&t.isEditable?this.constants_.MEDIUM_PADDING:t&&Q.isInlineInput(t)?this.constants_.MEDIUM_LARGE_PADDING:t&&Q.isStatementInput(t)?this.constants_.STATEMENT_INPUT_PADDING_LEFT:this.constants_.LARGE_PADDING;if(!Q.isInput(e)&&(!t||Q.isStatementInput(t)))return Q.isField(e)&&e.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING:Q.isIcon(e)?this.constants_.LARGE_PADDING*2+1:Q.isHat(e)?this.constants_.NO_PADDING:Q.isPreviousOrNextConnection(e)?this.constants_.LARGE_PADDING:Q.isLeftRoundedCorner(e)?this.constants_.MIN_BLOCK_WIDTH:Q.isJaggedEdge(e)?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING;if(Q.isInput(e)&&!t){if(Q.isExternalInput(e))return this.constants_.NO_PADDING;if(Q.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Q.isStatementInput(e))return this.constants_.NO_PADDING}if(!Q.isInput(e)&&t&&Q.isInput(t)){if(Q.isField(e)&&e.isEditable){if(Q.isInlineInput(t)||Q.isExternalInput(t))return this.constants_.SMALL_PADDING}else{if(Q.isInlineInput(t)||Q.isExternalInput(t))return this.constants_.MEDIUM_LARGE_PADDING;if(Q.isStatementInput(t))return this.constants_.LARGE_PADDING}return this.constants_.LARGE_PADDING-1}if(Q.isIcon(e)&&t&&!Q.isInput(t))return this.constants_.LARGE_PADDING;if(Q.isInlineInput(e)&&t&&Q.isField(t))return t.isEditable?this.constants_.MEDIUM_PADDING:this.constants_.LARGE_PADDING;if(Q.isLeftSquareCorner(e)&&t){if(Q.isHat(t))return this.constants_.NO_PADDING;if(Q.isPreviousConnection(t))return t.notchOffset;if(Q.isNextConnection(t))return t.notchOffset+(this.RTL?1:-1)*this.constants_.DARK_PATH_OFFSET/2}if(Q.isLeftRoundedCorner(e)&&t){if(Q.isPreviousConnection(t))return t.notchOffset-this.constants_.CORNER_RADIUS;if(Q.isNextConnection(t))return t.notchOffset-this.constants_.CORNER_RADIUS+(this.RTL?1:-1)*this.constants_.DARK_PATH_OFFSET/2}return Q.isField(e)&&t&&Q.isField(t)&&e.isEditable===t.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING:t&&Q.isJaggedEdge(t)?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getSpacerRowHeight_(e,t){return Q.isTopRow(e)&&Q.isBottomRow(t)?this.constants_.EMPTY_BLOCK_SPACER_HEIGHT:Q.isTopRow(e)||Q.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(Q.isSpacer(t))return e.yPos+t.height/2;if(Q.isBottomRow(e))return e=e.yPos+e.height-e.descenderHeight,Q.isNextConnection(t)?e+t.height/2:e-t.height/2;if(Q.isTopRow(e))return Q.isHat(t)?e.capline-t.height/2:e.capline+t.height/2;var n=e.yPos;return Q.isField(t)||Q.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=Q.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),Q.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):Q.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}},fm=class extends mp{constructor(e,t,n){super(e,t,n),this.constants=n,this.colourDark=`#000000`,this.svgPathDark=w(I.PATH,{class:`blocklyPathDark`,transform:`translate(1,1)`}),this.svgRoot.insertBefore(this.svgPathDark,this.svgPath),this.svgPathLight=w(I.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=nr(`#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`)}},pm=class extends hp{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 am}makeRenderInfo_(e){return new dm(this,e)}makeDrawer_(e,t){return new sm(e,t)}makePathObject(e,t){return new fm(e,t,this.getConstants())}makeHighlightConstants_(){return new cm(this.getConstants())}getHighlightConstants(){if(!this.highlightConstants)throw Error(`Cannot access the highlight constants because init has not been called`);return this.highlightConstants}};Sa(`geras`,pm);var mm={};mm.ConstantProvider=am,mm.Drawer=sm,mm.HighlightConstantProvider=cm,mm.Highlighter=om,mm.InlineInput=lm,mm.PathObject=fm,mm.RenderInfo=dm,mm.Renderer=pm,mm.StatementInput=um;var hm=class extends pp{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 Qf(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 Qf(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 Qf(this.constants_,n)))}}}getInRowSpacing_(e,t){if(!e)return t&&Q.isField(t)&&t.isEditable?this.constants_.MEDIUM_PADDING:t&&Q.isInlineInput(t)?this.constants_.MEDIUM_LARGE_PADDING:t&&Q.isStatementInput(t)?this.constants_.STATEMENT_INPUT_PADDING_LEFT:this.constants_.LARGE_PADDING;if(!Q.isInput(e)&&!t)return Q.isField(e)&&e.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.MEDIUM_PADDING:Q.isIcon(e)?this.constants_.LARGE_PADDING*2+1:Q.isHat(e)?this.constants_.NO_PADDING:Q.isPreviousOrNextConnection(e)?this.constants_.LARGE_PADDING:Q.isLeftRoundedCorner(e)?this.constants_.MIN_BLOCK_WIDTH:Q.isJaggedEdge(e)?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING;if(Q.isInput(e)&&!t){if(Q.isExternalInput(e))return this.constants_.NO_PADDING;if(Q.isInlineInput(e))return this.constants_.LARGE_PADDING;if(Q.isStatementInput(e))return this.constants_.NO_PADDING}if(!Q.isInput(e)&&t&&Q.isInput(t)){if(Q.isField(e)&&e.isEditable){if(Q.isInlineInput(t)||Q.isExternalInput(t))return this.constants_.SMALL_PADDING}else{if(Q.isInlineInput(t)||Q.isExternalInput(t))return this.constants_.MEDIUM_LARGE_PADDING;if(Q.isStatementInput(t))return this.constants_.LARGE_PADDING}return this.constants_.LARGE_PADDING-1}if(Q.isIcon(e)&&t&&!Q.isInput(t))return this.constants_.LARGE_PADDING;if(Q.isInlineInput(e)&&t&&Q.isField(t))return t.isEditable?this.constants_.MEDIUM_PADDING:this.constants_.LARGE_PADDING;if(Q.isLeftSquareCorner(e)&&t){if(Q.isHat(t))return this.constants_.NO_PADDING;if(Q.isPreviousConnection(t)||Q.isNextConnection(t))return t.notchOffset}return Q.isLeftRoundedCorner(e)&&t?t.notchOffset-this.constants_.CORNER_RADIUS:Q.isField(e)&&t&&Q.isField(t)&&e.isEditable===t.isEditable?e.width===0?this.constants_.NO_PADDING:this.constants_.LARGE_PADDING:t&&Q.isJaggedEdge(t)?this.constants_.LARGE_PADDING:this.constants_.MEDIUM_PADDING}getSpacerRowHeight_(e,t){return Q.isTopRow(e)&&Q.isBottomRow(t)?this.constants_.EMPTY_BLOCK_SPACER_HEIGHT:Q.isTopRow(e)||Q.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(Q.isSpacer(t))return e.yPos+t.height/2;if(Q.isBottomRow(e))return e=e.yPos+e.height-e.descenderHeight,Q.isNextConnection(t)?e+t.height/2:e-t.height/2;if(Q.isTopRow(e))return Q.isHat(t)?e.capline-t.height/2:e.capline+t.height/2;var n=e.yPos;return n=Q.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}},gm=class extends hp{constructor(e){super(e)}makeRenderInfo_(e){return new hm(this,e)}};Sa(`thrasos`,gm);var _m={};_m.RenderInfo=hm,_m.Renderer=gm;var vm={Classic:ud,Zelos:new ld(`zelos`,{colour_blocks:{colourPrimary:`#CF63CF`,colourSecondary:`#C94FC9`,colourTertiary:`#BD42BD`},list_blocks:{colourPrimary:`#9966FF`,colourSecondary:`#855CD6`,colourTertiary:`#774DCB`},logic_blocks:{colourPrimary:`#4C97FF`,colourSecondary:`#4280D7`,colourTertiary:`#3373CC`},loop_blocks:{colourPrimary:`#0fBD8C`,colourSecondary:`#0DA57A`,colourTertiary:`#0B8E69`},math_blocks:{colourPrimary:`#59C059`,colourSecondary:`#46B946`,colourTertiary:`#389438`},procedure_blocks:{colourPrimary:`#FF6680`,colourSecondary:`#FF4D6A`,colourTertiary:`#FF3355`},text_blocks:{colourPrimary:`#FFBF00`,colourSecondary:`#E6AC00`,colourTertiary:`#CC9900`},variable_blocks:{colourPrimary:`#FF8C1A`,colourSecondary:`#FF8000`,colourTertiary:`#DB6E00`},variable_dynamic_blocks:{colourPrimary:`#FF8C1A`,colourSecondary:`#FF8000`,colourTertiary:`#DB6E00`},hat_blocks:{colourPrimary:`#4C97FF`,colourSecondary:`#4280D7`,colourTertiary:`#3373CC`,hat:`cap`}},{colour_category:{colour:`#CF63CF`},list_category:{colour:`#9966FF`},logic_category:{colour:`#4C97FF`},loop_category:{colour:`#0fBD8C`},math_category:{colour:`#59C059`},procedure_category:{colour:`#FF6680`},text_category:{colour:`#FFBF00`},variable_category:{colour:`#FF8C1A`},variable_dynamic_category:{colour:`#FF8C1A`}})},ym=class{constructor(e,t,n){this.id_=e.toolboxitemid||y(),this.level_=(this.parent_=n||null)?this.parent_.getLevel()+1:0,this.toolboxItemDef_=e,this.parentToolbox_=t,this.workspace_=this.parentToolbox_.getWorkspace()}init(){}getDiv(){return null}getClickTarget(){return null}getId(){return this.id_}getParent(){return null}getLevel(){return this.level_}isSelectable(){return!1}isCollapsible(){return!1}dispose(){}setVisible_(){}getFocusableElement(){var e=this.getDiv();if(!e)throw Error(`Trying to access toolbox item before DOM is initialized.`);if(!(e instanceof HTMLElement))throw Error(`Toolbox item div is unexpectedly not an HTML element.`);return e}getFocusableTree(){return this.parentToolbox_}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!0}getParentToolbox(){return this.parentToolbox_}},bm=class extends ym{constructor(e,t,n){super(e,t,n),this.colour_=this.name_=``,this.labelDom_=this.iconDom_=this.rowContents_=this.rowDiv_=this.htmlDiv_=null,this.isDisabled_=this.isHidden_=!1,this.flyoutItems_=[],this.cssConfig_=this.makeDefaultCssConfig_()}init(){this.parseCategoryDef_(this.toolboxItemDef_),this.parseContents_(this.toolboxItemDef_),this.createDom_(),this.toolboxItemDef_.hidden===`true`&&this.hide()}makeDefaultCssConfig_(){return{container:`blocklyToolboxCategoryContainer`,row:`blocklyToolboxCategory`,rowcontentcontainer:`blocklyTreeRowContentContainer`,icon:`blocklyToolboxCategoryIcon`,label:`blocklyToolboxCategoryLabel`,contents:`blocklyToolboxCategoryGroup`,selected:`blocklyToolboxSelected`,openicon:`blocklyToolboxCategoryIconOpen`,closedicon:`blocklyToolboxCategoryIconClosed`}}parseContents_(e){if(`custom`in e)this.flyoutItems_=e.custom;else if(e=e.contents)for(let t=0;t<e.length;t++){let n=e[t];Array.isArray(this.flyoutItems_)&&this.flyoutItems_.push(n)}}parseCategoryDef_(e){this.name_=`name`in e?O(e.name):``,this.colour_=this.getColour_(e),Object.assign(this.cssConfig_,e.cssconfig||e.cssConfig)}createDom_(){this.htmlDiv_=this.createContainer_(),S(this.htmlDiv_,P.TREEITEM),C(this.htmlDiv_,F.SELECTED,!1),C(this.htmlDiv_,F.LEVEL,this.level_+1),this.rowDiv_=this.createRowContainer_(),this.rowDiv_.style.pointerEvents=`auto`,this.htmlDiv_.appendChild(this.rowDiv_),this.rowContents_=this.createRowContentsContainer_(),this.rowContents_.style.pointerEvents=`none`,this.rowDiv_.appendChild(this.rowContents_),this.iconDom_=this.createIconDom_(),S(this.iconDom_,P.PRESENTATION),this.rowContents_.appendChild(this.iconDom_),this.labelDom_=this.createLabelDom_(this.name_),this.rowContents_.appendChild(this.labelDom_);var e=this.labelDom_.getAttribute(`id`);return e&&C(this.htmlDiv_,F.LABELLEDBY,e),this.addColourBorder_(this.colour_),this.htmlDiv_}createContainer_(){var e=document.createElement(`div`);e.tabIndex=-1,e.id=this.getId();var t=this.cssConfig_.container;return t&&T(e,t),e}createRowContainer_(){var e=document.createElement(`div`),t=this.cssConfig_.row;return t&&T(e,t),t=`${bm.nestedPadding*this.getLevel()}px`,this.workspace_.RTL?e.style.paddingRight=t:e.style.paddingLeft=t,e}createRowContentsContainer_(){var e=document.createElement(`div`),t=this.cssConfig_.rowcontentcontainer;return t&&T(e,t),e}createIconDom_(){var e=document.createElement(`span`);if(!this.parentToolbox_.isHorizontal()){let t=this.cssConfig_.icon;t&&T(e,t)}return e.style.display=`inline-block`,e}createLabelDom_(e){var t=document.createElement(`span`);return t.setAttribute(`id`,this.getId()+`.label`),t.textContent=e,(e=this.cssConfig_.label)&&T(t,e),t}refreshTheme(){this.colour_=this.getColour_(this.toolboxItemDef_),this.addColourBorder_(this.colour_)}addColourBorder_(e){e&&(e=bm.borderWidth+`px solid `+(e||`#ddd`),this.workspace_.RTL?this.rowDiv_.style.borderRight=e:this.rowDiv_.style.borderLeft=e)}getColour_(e){var t=e.categorystyle||e.categoryStyle;if((e=e.colour)&&t)console.warn(`Toolbox category "`+this.name_+`" must not have both a style and a colour`);else{if(t)return this.getColourfromStyle(t);if(e)return this.parseColour(e)}return``}getColour(){return this.colour_}getColourfromStyle(e){var t=this.workspace_.getTheme();if(e&&t){if((t=t.categoryStyles[e])&&t.colour)return this.parseColour(t.colour);console.warn(`Style "`+e+`" must exist and contain a colour value`)}return``}getClickTarget(){return this.rowDiv_}parseColour(e){if(e=O(e),e==null||e===``)return``;var t=Number(e);return isNaN(t)?(t=Qn(e))?t:(console.warn(`Toolbox category "`+this.name_+`" has unrecognized colour attribute: `+e),``):rr(t)}openIcon_(e){if(e){var t=this.cssConfig_.closedicon;t&&pe(e,t),(t=this.cssConfig_.openicon)&&T(e,t)}}closeIcon_(e){if(e){var t=this.cssConfig_.openicon;t&&pe(e,t),(t=this.cssConfig_.closedicon)&&T(e,t)}}setVisible_(e){this.htmlDiv_.style.display=e?`block`:`none`,this.isHidden_=!e,this.parentToolbox_.getSelectedItem()===this&&this.parentToolbox_.clearSelection()}hide(){this.setVisible_(!1)}show(){this.setVisible_(!0)}isVisible(){return!this.isHidden_&&this.allAncestorsExpanded_()}allAncestorsExpanded_(){for(var e=this;e.getParent();)if(e=e.getParent(),!e.isExpanded())return!1;return!0}isSelectable(){return this.isVisible()&&!this.isDisabled_}onClick(){}setSelected(e){if(this.rowDiv_){var t=this.cssConfig_.selected;if(e){let e=this.parseColour(bm.defaultBackgroundColour);this.rowDiv_.style.backgroundColor=this.colour_||e,t&&T(this.rowDiv_,t)}else this.rowDiv_.style.backgroundColor=``,t&&E(this.rowDiv_,t);C(this.htmlDiv_,F.SELECTED,e)}}setDisabled(e){this.isDisabled_=e,this.getDiv().setAttribute(`disabled`,`${e}`),e?this.getDiv().setAttribute(`disabled`,`true`):this.getDiv().removeAttribute(`disabled`)}getName(){return this.name_}getParent(){return this.parent_}getDiv(){return this.htmlDiv_}onNodeFocus(){this.getParentToolbox().getSelectedItem()!==this&&this.getParentToolbox().setSelectedItem(this)}getContents(){return this.flyoutItems_}updateFlyoutContents(e){this.flyoutItems_=[],this.toolboxItemDef_=typeof e==`string`?{kind:this.toolboxItemDef_.kind,custom:e,id:this.toolboxItemDef_.id,categorystyle:this.toolboxItemDef_.categorystyle,colour:this.toolboxItemDef_.colour,cssconfig:this.toolboxItemDef_.cssconfig,hidden:this.toolboxItemDef_.hidden}:{kind:this.toolboxItemDef_.kind,name:`name`in this.toolboxItemDef_?this.toolboxItemDef_.name:``,contents:st(e),id:this.toolboxItemDef_.id,categorystyle:this.toolboxItemDef_.categorystyle,colour:this.toolboxItemDef_.colour,cssconfig:this.toolboxItemDef_.cssconfig,hidden:this.toolboxItemDef_.hidden},this.parseContents_(this.toolboxItemDef_)}dispose(){D(this.htmlDiv_)}};bm.registrationName=`category`,bm.nestedPadding=19,bm.borderWidth=8,bm.defaultBackgroundColour=`#57e`,He(`
895
+ .blocklyToolboxCategory:not(.blocklyToolboxSelected):hover {
896
+ background-color: rgba(255, 255, 255, .2);
897
+ }
898
+
899
+ .blocklyToolbox[layout="h"] .blocklyToolboxCategoryContainer {
900
+ margin: 1px 5px 1px 0;
901
+ }
902
+
903
+ .blocklyToolbox[dir="RTL"][layout="h"] .blocklyToolboxCategoryContainer {
904
+ margin: 1px 0 1px 5px;
905
+ }
906
+
907
+ .blocklyToolboxCategory {
908
+ height: 22px;
909
+ line-height: 22px;
910
+ margin-bottom: 3px;
911
+ padding-right: 8px;
912
+ white-space: nowrap;
913
+ }
914
+
915
+ .blocklyToolbox[dir="RTL"] .blocklyToolboxCategory {
916
+ margin-left: 8px;
917
+ padding-right: 0;
918
+ }
919
+
920
+ .blocklyToolboxCategoryIcon {
921
+ background-image: url(<<<PATH>>>/sprites.svg);
922
+ height: 16px;
923
+ vertical-align: middle;
924
+ visibility: hidden;
925
+ width: 16px;
926
+ }
927
+
928
+ .blocklyToolboxCategoryIconClosed {
929
+ background-position: -32px -1px;
930
+ }
931
+
932
+ .blocklyToolbox[dir="RTL"] .blocklyToolboxCategoryIconClosed {
933
+ background-position: 0 -1px;
934
+ }
935
+
936
+ .blocklyToolboxSelected>.blocklyToolboxCategoryIconClosed {
937
+ background-position: -32px -17px;
938
+ }
939
+
940
+ .blocklyToolbox[dir="RTL"] .blocklyToolboxSelected>.blocklyToolboxCategoryIconClosed {
941
+ background-position: 0 -17px;
942
+ }
943
+
944
+ .blocklyToolboxCategoryIconOpen {
945
+ background-position: -16px -1px;
946
+ }
947
+
948
+ .blocklyToolboxSelected>.blocklyToolboxCategoryIconOpen {
949
+ background-position: -16px -17px;
950
+ }
951
+
952
+ .blocklyToolboxCategoryLabel {
953
+ cursor: default;
954
+ font: 16px sans-serif;
955
+ padding: 0 3px;
956
+ vertical-align: middle;
957
+ }
958
+
959
+ .blocklyToolboxDelete .blocklyToolboxCategoryLabel {
960
+ cursor: url("<<<PATH>>>/handdelete.cur"), auto;
961
+ }
962
+
963
+ .blocklyToolboxSelected .blocklyToolboxCategoryLabel {
964
+ color: #fff;
965
+ }
966
+ `),t(M.TOOLBOX_ITEM,bm.registrationName,bm);var xm=class extends ym{constructor(e,t){super(e,t),this.cssConfig_={container:`blocklyTreeSeparator`},this.htmlDiv=null,Object.assign(this.cssConfig_,e.cssconfig||e.cssConfig)}init(){this.createDom_()}createDom_(){var e=document.createElement(`div`);e.tabIndex=-1,e.id=this.getId();var t=this.cssConfig_.container;return t&&T(e,t),this.htmlDiv=e}getDiv(){return this.htmlDiv}dispose(){D(this.htmlDiv)}canBeFocused(){return!1}};xm.registrationName=`sep`,He(`
967
+ .blocklyTreeSeparator {
968
+ border-bottom: solid #e5e5e5 1px;
969
+ height: 0;
970
+ margin: 5px 0;
971
+ }
972
+
973
+ .blocklyToolbox[layout="h"] .blocklyTreeSeparator {
974
+ border-right: solid #e5e5e5 1px;
975
+ border-bottom: none;
976
+ height: auto;
977
+ margin: 0 5px 0 5px;
978
+ padding: 5px 0;
979
+ width: 0;
980
+ }
981
+ `),t(M.TOOLBOX_ITEM,xm.registrationName,xm);var Sm=class extends bm{constructor(e,t,n){super(e,t,n),this.subcategoriesDiv_=null,this.expanded_=!1,this.toolboxItems_=[]}makeDefaultCssConfig_(){var e=super.makeDefaultCssConfig_();return e.contents=`blocklyToolboxCategoryGroup`,e}parseContents_(e){if(`custom`in e)this.flyoutItems_=e.custom;else{let t=e.contents;if(t){this.flyoutItems_=[],e=!0;for(let n=0;n<t.length;n++){let r=t[n];!i(M.TOOLBOX_ITEM,r.kind)||r.kind.toLowerCase()===xm.registrationName&&e?(this.flyoutItems_.push(r),e=!0):(this.createToolboxItem(r),e=!1)}}}}createToolboxItem(e){var t=e.kind;t.toUpperCase()===`CATEGORY`&&lt(e)&&(t=Sm.registrationName),e=new(r(M.TOOLBOX_ITEM,t,void 0))(e,this.parentToolbox_,this),this.toolboxItems_.push(e)}init(){super.init(),this.setExpanded(this.toolboxItemDef_.expanded===`true`||this.toolboxItemDef_.expanded===!0)}createDom_(){super.createDom_();var e=this.getChildToolboxItems();return this.subcategoriesDiv_=this.createSubCategoriesDom_(e),S(this.subcategoriesDiv_,P.GROUP),this.htmlDiv_.appendChild(this.subcategoriesDiv_),this.closeIcon_(this.iconDom_),C(this.htmlDiv_,F.EXPANDED,!1),this.htmlDiv_}createIconDom_(){var e=document.createElement(`span`);if(!this.parentToolbox_.isHorizontal()){let t=this.cssConfig_.icon;t&&T(e,t),e.style.visibility=`visible`}return e.style.display=`inline-block`,e}createSubCategoriesDom_(e){var t=document.createElement(`div`);t.style.display=`none`;var n=this.cssConfig_.contents;for(n&&T(t,n),n=0;n<e.length;n++){let r=e[n];r.init();let i=r.getDiv();if(t.appendChild(i),r.getClickTarget){let e;(e=r.getClickTarget())==null||e.setAttribute(`id`,r.getId())}}return t}setExpanded(e){if(this.expanded_!==e){if(this.expanded_=e)this.subcategoriesDiv_.style.display=`block`,this.openIcon_(this.iconDom_);else{let e;(e=this.parentToolbox_.getFlyout())==null||e.setVisible(!1),this.subcategoriesDiv_.style.display=`none`,this.closeIcon_(this.iconDom_)}C(this.htmlDiv_,F.EXPANDED,e),this.parentToolbox_.handleToolboxItemResize()}}setVisible_(e){this.htmlDiv_.style.display=e?`block`:`none`;var t=this.getChildToolboxItems();for(let n=0;n<t.length;n++)t[n].setVisible_(e);this.isHidden_=!e,this.parentToolbox_.getSelectedItem()===this&&this.parentToolbox_.clearSelection()}isExpanded(){return this.expanded_}isCollapsible(){return!0}onClick(){this.toggleExpanded()}toggleExpanded(){this.setExpanded(!this.expanded_)}getDiv(){return this.htmlDiv_}getChildToolboxItems(){return this.toolboxItems_}};Sm.registrationName=`collapsibleCategory`,t(M.TOOLBOX_ITEM,Sm.registrationName,Sm);var Cm=class extends sf{constructor(e){super(),this.id=`toolbox`,this.contentsDiv_=this.HtmlDiv=null,this.isVisible_=!1,this.height_=this.width_=0,this.flyout=null,this.contents=new Map,this.previouslySelectedItem_=this.selectedItem_=null,this.boundEvents_=[],this.mouseDown=!1,this.navigator=new Df(this),this.workspace_=e,this.toolboxDef_=e.options.languageTree||{contents:[]},this.horizontalLayout=e.options.horizontalLayout,this.RTL=e.options.RTL,this.toolboxPosition=e.options.toolboxPosition}onShortcut(){return!1}init(){var t=this.workspace_,n=t.getParentSvg();this.flyout=this.createFlyout_(),this.HtmlDiv=this.createDom_(this.workspace_);var r=this.flyout.createDom(`svg`);t.getInjectionDiv().insertBefore(r,n),T(r,`blocklyToolboxFlyout`),this.setVisible(!0),this.flyout.init(t),this.render(this.toolboxDef_),t=t.getThemeManager(),t.subscribe(this.HtmlDiv,`toolboxBackgroundColour`,`background-color`),t.subscribe(this.HtmlDiv,`toolboxForegroundColour`,`color`),this.workspace_.getComponentManager().addComponent({component:this,weight:Es.ComponentWeight.TOOLBOX_WEIGHT,capabilities:[Es.Capability.AUTOHIDEABLE,Es.Capability.DELETE_AREA,Es.Capability.DRAG_TARGET]}),e.A().registerTree(this,!0)}createDom_(e){e=e.getParentSvg();var t=this.createContainer_();t.id=y(),this.contentsDiv_=this.createContentsContainer_(),S(this.contentsDiv_,P.TREE),t.appendChild(this.contentsDiv_);var n;return(n=e.parentNode)==null||n.insertBefore(t,e),this.attachEvents_(t,this.contentsDiv_),t}createContainer_(){var e=document.createElement(`div`);return e.setAttribute(`layout`,this.isHorizontal()?`h`:`v`),T(e,`blocklyToolbox`),e.setAttribute(`dir`,this.RTL?`RTL`:`LTR`),e}createContentsContainer_(){var e=document.createElement(`div`);return T(e,`blocklyToolboxCategoryGroup`),this.isHorizontal()&&(e.style.flexDirection=`row`),e}attachEvents_(e,t){var n=p(e,`pointerdown`,this,this.onClick_,!1);this.boundEvents_.push(n),e=m(e,`pointerup`,this,()=>{this.mouseDown=!1}),this.boundEvents_.push(e),t=p(t,`keydown`,this,this.onKeyDown_,!1),this.boundEvents_.push(t)}onClick_(t){var n=()=>{e.A().focusNode(this),this.clearSelection(),ms.hideChaff(!1),t.preventDefault()};if(this.mouseDown=!0,_(t)||t.target===this.HtmlDiv)n();else{var r=t.target.getAttribute(`id`);r&&(r=this.getToolboxItemById(r),r!=null&&r.isSelectable())&&(r.onClick(t),r===this.getSelectedItem()?n():(this.setSelectedItem(r),ms.hideChaff(!0)))}lo=null}onKeyDown_(t){var n=!1;switch(t.key){case`ArrowLeft`:n=this.toggleSelectedItem(!1);break;case`ArrowRight`:n=this.toggleSelectedItem(!0);break;case`Escape`:e.A().focusTree(this.getWorkspace()),n=!0}n&&(t.preventDefault(),t.stopPropagation())}createFlyout_(){var e=this.workspace_,t=e.copyOptionsForFlyout();return t.toolboxPosition=e.options.toolboxPosition,new(e.horizontalLayout?s(M.FLYOUTS_HORIZONTAL_TOOLBOX,e.options,!0):s(M.FLYOUTS_VERTICAL_TOOLBOX,e.options,!0))(t)}render(e){this.toolboxDef_=e,this.contents.forEach(e=>e.dispose()),this.contents.clear(),this.renderContents_(e.contents),this.position(),this.handleToolboxItemResize()}renderContents_(e){var t=document.createDocumentFragment();for(let n=0;n<e.length;n++)this.createToolboxItem(e[n],t);var n;(n=this.contentsDiv_)==null||n.appendChild(t)}createToolboxItem(e,t){var n=e.kind;if(n.toUpperCase()===`CATEGORY`&&lt(e)&&(n=Sm.registrationName),n=a(M.TOOLBOX_ITEM,n.toLowerCase())){e=new n(e,this),e.init(),this.addToolboxItem_(e),(n=e.getDiv())&&t.appendChild(n);let r;(r=e.getClickTarget())==null||r.setAttribute(`id`,e.getId())}}addToolboxItem_(e){if(this.contents.set(e.getId(),e),e.isCollapsible()){e=e.getChildToolboxItems();for(let t=0;t<e.length;t++)this.addToolboxItem_(e[t])}}getToolboxItems(){return[...this.contents.values()]}addStyle(e){e&&this.HtmlDiv&&T(this.HtmlDiv,e)}removeStyle(e){e&&this.HtmlDiv&&E(this.HtmlDiv,e)}getClientRect(){if(!this.HtmlDiv||!this.isVisible_)return null;var e=this.HtmlDiv.getBoundingClientRect(),t=e.top,n=t+e.height,r=e.left;return e=r+e.width,this.toolboxPosition===H.TOP?new B(-1e7,n,-1e7,1e7):this.toolboxPosition===H.BOTTOM?new B(t,1e7,-1e7,1e7):this.toolboxPosition===H.LEFT?new B(-1e7,1e7,-1e7,e):new B(-1e7,1e7,r,1e7)}onDragEnter(){cd.mover.isMoving()||this.updateCursorDeleteStyle_(!0)}onDragExit(){cd.mover.isMoving()||this.updateCursorDeleteStyle_(!1)}onDrop(){cd.mover.isMoving()||this.updateCursorDeleteStyle_(!1)}updateWouldDelete_(e){e!==this.wouldDelete_&&(this.updateCursorDeleteStyle_(!1),this.wouldDelete_=e,this.updateCursorDeleteStyle_(!0))}updateCursorDeleteStyle_(e){var t=this.wouldDelete_?`blocklyToolboxDelete`:`blocklyToolboxGrab`;e?this.addStyle(t):this.removeStyle(t)}getToolboxItemById(e){return this.contents.get(e)||null}getWidth(){return this.width_}getHeight(){return this.height_}getFlyout(){return this.flyout}getWorkspace(){return this.workspace_}getSelectedItem(){return this.selectedItem_}getPreviouslySelectedItem(){return this.previouslySelectedItem_}isHorizontal(){return this.horizontalLayout}position(){var e=this.workspace_.getMetrics(),t=this.HtmlDiv;if(t){this.horizontalLayout?(t.style.left=`0`,t.style.height=`auto`,t.style.width=`100%`,this.height_=t.offsetHeight,this.width_=e.viewWidth,this.toolboxPosition===H.TOP?t.style.top=`0`:t.style.bottom=`0`):(this.toolboxPosition===H.RIGHT?t.style.right=`0`:t.style.left=`0`,t.style.height=`100%`,this.width_=t.offsetWidth,this.height_=e.viewHeight);var n;(n=this.flyout)==null||n.position()}}handleToolboxItemResize(){if(this.HtmlDiv){var e=this.workspace_,t=this.HtmlDiv.getBoundingClientRect(),n=this.getFlyout(),r=this.toolboxPosition===H.LEFT?e.scrollX+t.width+(n!=null&&n.isVisible()?n.getWidth():0):e.scrollX;t=this.toolboxPosition===H.TOP?e.scrollY+t.height+(n!=null&&n.isVisible()?n.getHeight():0):e.scrollY,e.translate(r,t),Ie(e)}}clearSelection(){this.setSelectedItem(null)}refreshTheme(){this.contents.forEach(e=>{e.refreshTheme&&e.refreshTheme()})}refreshSelection(){if(this.selectedItem_&&this.selectedItem_.isSelectable()&&this.selectedItem_.getContents().length){let e;(e=this.flyout)==null||e.show(this.selectedItem_.getContents())}}setVisible(e){this.isVisible_!==e&&(this.HtmlDiv&&(this.HtmlDiv.style.display=e?`block`:`none`),this.isVisible_=e,this.workspace_.recordDragTargets())}autoHide(e){!e&&this.flyout&&this.flyout.autoClose&&this.clearSelection()}setSelectedItem(e){var t=this.selectedItem_;!e&&!t||e&&!ei(e)||(this.shouldDeselectItem_(t,e)&&t!==null&&this.deselectItem_(t),this.shouldSelectItem_(t,e)&&e!==null&&this.selectItem_(t,e),this.updateFlyout_(t,e),this.fireSelectEvent(t,e))}shouldDeselectItem_(e,t){return e!==null&&(!e.isCollapsible()||e!==t)}shouldSelectItem_(e,t){return t!==null&&t!==e}deselectItem_(e){this.selectedItem_=null,this.previouslySelectedItem_=e,e.setSelected(!1),C(this.contentsDiv_,F.ACTIVEDESCENDANT,``)}selectItem_(e,t){this.selectedItem_=t,this.previouslySelectedItem_=e,t.setSelected(!0),C(this.contentsDiv_,F.ACTIVEDESCENDANT,t.getId())}selectItemByPosition(e){(e=this.getToolboxItems()[e])&&this.setSelectedItem(e)}updateFlyout_(e,t){if(t&&(e!==t||t.isCollapsible())&&t.getContents().length){let e;(e=this.flyout)==null||e.show(t.getContents());let n;(n=this.flyout)==null||n.scrollToStart()}else{let e;(e=this.flyout)==null||e.hide()}}fireSelectEvent(e,t){var n=e&&e.getName(),r=t&&t.getName();e===t&&(r=null),e=new(x(N.TOOLBOX_ITEM_SELECT))(n,r,this.workspace_.id),b(e)}toggleSelectedItem(e){var t;return la(this.selectedItem_)&&(t=this.selectedItem_)!=null&&t.isCollapsible()&&this.selectedItem_?.isExpanded()!==e?(this.selectedItem_.toggleExpanded(),!0):!1}dispose(){this.workspace_.getComponentManager().removeComponent(`toolbox`);var t;for((t=this.flyout)==null||t.dispose(),this.contents.forEach(e=>e.dispose()),t=0;t<this.boundEvents_.length;t++)h(this.boundEvents_[t]);this.boundEvents_=[],this.contents.clear(),this.HtmlDiv&&(this.workspace_.getThemeManager().unsubscribe(this.HtmlDiv),D(this.HtmlDiv)),e.A().unregisterTree(this)}getFocusableElement(){if(!this.HtmlDiv)throw Error(`Toolbox DOM has not yet been created.`);return this.HtmlDiv}getFocusableTree(){return this}onNodeFocus(){}onNodeBlur(){}canBeFocused(){return!0}getRootFocusableNode(){return this}getRestoredFocusableNode(e){return!e||e===this?this.getToolboxItems().find(e=>e.isSelectable())??null:null}getNestedTrees(){return[]}lookUpFocusableNode(e){return this.getToolboxItemById(e)}onTreeFocus(e){e===this?this.clearSelection():this.getSelectedItem()===e||this.mouseDown||this.setSelectedItem(e)}onTreeBlur(e){e&&e===this.flyout?.getWorkspace()||this.autoHide(!1)}getNavigator(){return this.navigator}};He(`
982
+ .blocklyToolboxDelete {
983
+ cursor: url("<<<PATH>>>/handdelete.cur"), auto;
984
+ }
985
+
986
+ .blocklyToolboxGrab {
987
+ cursor: url("<<<PATH>>>/handclosed.cur"), auto;
988
+ cursor: grabbing;
989
+ cursor: -webkit-grabbing;
990
+ }
991
+
992
+ /* Category tree in Toolbox. */
993
+ .blocklyToolbox {
994
+ box-sizing: border-box;
995
+ user-select: none;
996
+ -ms-user-select: none;
997
+ -webkit-user-select: none;
998
+ background-color: #ddd;
999
+ overflow-x: visible;
1000
+ overflow-y: auto;
1001
+ padding: 4px 0 4px 0;
1002
+ position: absolute;
1003
+ z-index: 70; /* so blocks go under toolbox when dragging */
1004
+ -webkit-tap-highlight-color: transparent; /* issue #1345 */
1005
+ }
1006
+
1007
+ .blocklyToolboxCategoryGroup {
1008
+ display: flex;
1009
+ flex-wrap: wrap;
1010
+ flex-direction: column;
1011
+ }
1012
+
1013
+ .blocklyToolboxCategoryGroup:focus {
1014
+ outline: none;
1015
+ }
1016
+ `),t(M.TOOLBOX,`default`,Cm);var wm=U.INPUT_VALUE,Tm=U.OUTPUT_VALUE,Em=U.NEXT_STATEMENT,Dm=U.PREVIOUS_STATEMENT,Om=H.TOP,km=H.BOTTOM,Am=H.LEFT,jm=H.RIGHT;bp.prototype.newBlock=function(e,t){return new Ld(this,e,t)},Sp.prototype.newBlock=function(e,t){return new af(this,e,t)},bp.prototype.newComment=function(e){return new $u(this,e)},Sp.prototype.newComment=function(e){return new ed(this,e)},Sp.newTrashcan=function(e){return new Tp(e)},md.prototype.newWorkspaceSvg=function(e){return new Sp(e)},e.aj.prototype.populateProcedures=function(t){t=ma(t),t=t[0].concat(t[1]);for(let n=0;n<t.length;n++)this.getName(t[n][0],e.aj.NameType.PROCEDURE)};var $={};return $.Block=Ld,$.BlockFlyoutInflater=im,$.BlockNavigationPolicy=mf,$.BlockSvg=af,$.Blocks=so,$.BubbleNavigationPolicy=hf,$.ButtonFlyoutInflater=nm,$.COLLAPSED_FIELD_NAME=`_TEMP_COLLAPSED_FIELD`,$.COLLAPSED_INPUT_NAME=`_TEMP_COLLAPSED_INPUT`,$.COLLAPSE_CHARS=30,$.CodeGenerator=e.Ip,$.CollapsibleToolboxCategory=Sm,$.CommentBarButtonNavigationPolicy=gf,$.CommentEditorNavigationPolicy=_f,$.ComponentManager=Es,$.Connection=Y,$.ConnectionChecker=yp,$.ConnectionDB=Sd,$.ConnectionNavigationPolicy=vf,$.ConnectionType=U,$.ContextMenu=Hu,$.ContextMenuItems=tm,$.ContextMenuRegistry=G,$.Css=Ms,$.DELETE_VARIABLE_ID=`DELETE_VARIABLE_ID`,$.DeleteArea=sf,$.Direction=od,$.DragDisposition=Yd,$.DragTarget=of,$.DropDownDiv=du,$.Events=W,$.Extensions=vd,$.Field=ku,$.FieldCheckbox=Zp,$.FieldDropdown=id,$.FieldImage=Pp,$.FieldLabel=Ed,$.FieldLabelSerializable=Xp,$.FieldNavigationPolicy=yf,$.FieldNumber=Yp,$.FieldTextInput=e.zp,$.FieldVariable=Jp,$.Flyout=jf,$.FlyoutButton=Jd,$.FlyoutButtonNavigationPolicy=ff,$.FlyoutItem=cf,$.FlyoutMetricsManager=uf,$.FlyoutNavigator=Of,$.FlyoutSeparator=df,$.FlyoutSeparatorNavigationPolicy=pf,$.FocusManager=cs,$.FocusableTreeTraverser=os,$.Generator=e.Ip,$.Gesture=Nf,$.Grid=Pf,$.HorizontalFlyout=qp,$.INPUT_VALUE=wm,$.IconNavigationPolicy=bf,$.Input=Nd,$.InsertionMarkerPreviewer=Up,$.KeyboardMover=cd,$.KeyboardNavigationController=Il,$.LabelFlyoutInflater=jp,$.Menu=hc,$.MenuItem=mc,$.MetricsManager=lf,$.MoveIndicator=ad,$.Msg=e.C,$.NEXT_STATEMENT=Em,$.Names=e.aj,$.NavigationDirection=Cf,$.Navigator=Tf,$.OPPOSITE_TYPE=kd,$.OUTPUT_VALUE=Tm,$.Options=dd,$.PREVIOUS_STATEMENT=Dm,$.PROCEDURE_CATEGORY_NAME=`PROCEDURE`,$.Procedures=Hf,$.RENAME_VARIABLE_ID=`RENAME_VARIABLE_ID`,$.RenderedConnection=Ad,$.Scrollbar=zs,$.ScrollbarPair=kf,$.SeparatorFlyoutInflater=Af,$.ShortcutItems=Qd,$.ShortcutRegistry=L,$.TOOLBOX_AT_BOTTOM=km,$.TOOLBOX_AT_LEFT=Am,$.TOOLBOX_AT_RIGHT=jm,$.TOOLBOX_AT_TOP=Om,$.Theme=ld,$.ThemeManager=_p,$.Themes=vm,$.Toast=Tc,$.Toolbox=Cm,$.ToolboxCategory=bm,$.ToolboxItem=ym,$.ToolboxItemNavigationPolicy=Ef,$.ToolboxNavigator=Df,$.ToolboxSeparator=xm,$.Tooltip=Cu,$.Touch=po,$.Trashcan=Tp,$.UnattachedFieldError=Au,$.VARIABLE_CATEGORY_NAME=`VARIABLE`,$.VARIABLE_DYNAMIC_CATEGORY_NAME=`VARIABLE_DYNAMIC`,$.VERSION=`13.0.0`,$.VariableMap=wp,$.VariableModel=Cp,$.Variables=zl,$.VariablesDynamic=vp,$.VerticalFlyout=Kp,$.WidgetDiv=Ru,$.Workspace=bp,$.WorkspaceAudio=xp,$.WorkspaceCommentNavigationPolicy=xf,$.WorkspaceDragger=Mf,$.WorkspaceNavigationPolicy=Sf,$.WorkspaceSvg=Sp,$.Xml=td,$.ZoomControls=cc,$.blockAnimations=Bd,$.blockRendering=gp,$.browserEvents=No,$.bubbles=rm,$.bumpObjects=Hd,$.clipboard=Kd,$.comments=qd,$.common=vs,$.config=e.tg,$.constants={COLLAPSED_FIELD_NAME:`_TEMP_COLLAPSED_FIELD`,COLLAPSED_INPUT_NAME:`_TEMP_COLLAPSED_INPUT`,MANUALLY_DISABLED:`MANUALLY_DISABLED`},$.defineBlocksWithJsonArray=ze,$.dialog=Pc,$.dragging=$p,$.fieldRegistry=rd,$.geras=mm,$.getFocusManager=e.A,$.getMainWorkspace=Ae,$.getSelected=Me,$.hasBubble=Rt,$.hideChaff=function(e){ms.hideChaff(e)},$.icons=Rf,$.inject=function(e,t){var n=null;n=typeof e==`string`?document.getElementById(e)||document.querySelector(e):e;var r;if(!document.contains(n)&&document!==(r=n)?.ownerDocument)throw Error(`Error: container is not in current document`);e=new dd(t||{}),r=document.createElement(`div`),T(r,`injectionDiv`),t!=null&&t.rtl&&T(r,`blocklyRTL`),S(r,P.APPLICATION),n.appendChild(r),t=Aa(r,e);var i=ja(r,t,e);return Ma(i),je(i),Ie(i),r.addEventListener(`focusin`,function(){je(i)}),p(r,`keydown`,null,Be),de(r),i},$.inputs=Wp,$.isBoundedElement=function(e){return typeof e.getBoundingRectangle==`function`&&typeof e.moveBy==`function`},$.isCopyable=Ai,$.isDeletable=ji,$.isDraggable=Mi,$.isIcon=mi,$.isObservable=pa,$.isPaster=function(e){return e&&typeof e.paste==`function`},$.isRenderedElement=function(e){return e&&typeof e.getSvgRoot==`function`},$.isSelectable=Ce,$.isSerializable=St,$.isVariableBackedParameterModel=Vt,$.keyboardNavigationController=Ll,$.layers={BLOCK:50,BUBBLE:100},$.navigateBlock=ca,$.procedures=Hf,$.registry=oo,$.renderManagement=wc,$.serialization=Ap,$.setLocale=We,$.setParentContainer=Fe,$.svgResize=Ie,$.thrasos=_m,$.uiPosition=nc,$.utils=bd,$.zelos=em,e.__chunk_blockly=$,e.__chunk_blockly.__namespace__=e,e.__chunk_blockly})}));const{Block:r,BlockFlyoutInflater:i,BlockNavigationPolicy:a,BlockSvg:o,Blocks:s,BubbleNavigationPolicy:c,ButtonFlyoutInflater:l,COLLAPSED_FIELD_NAME:u,COLLAPSED_INPUT_NAME:d,COLLAPSE_CHARS:f,CodeGenerator:p,CollapsibleToolboxCategory:m,CommentBarButtonNavigationPolicy:h,CommentEditorNavigationPolicy:g,ComponentManager:_,Connection:v,ConnectionChecker:ee,ConnectionDB:y,ConnectionNavigationPolicy:te,ConnectionType:b,ContextMenu:ne,ContextMenuItems:re,ContextMenuRegistry:ie,Css:ae,DELETE_VARIABLE_ID:oe,DeleteArea:se,Direction:x,DragDisposition:ce,DragTarget:S,DropDownDiv:C,Events:le,Extensions:ue,Field:de,FieldCheckbox:fe,FieldDropdown:w,FieldImage:T,FieldLabel:pe,FieldLabelSerializable:E,FieldNavigationPolicy:me,FieldNumber:D,FieldTextInput:he,FieldVariable:ge,Flyout:_e,FlyoutButton:ve,FlyoutButtonNavigationPolicy:ye,FlyoutItem:be,FlyoutMetricsManager:xe,FlyoutNavigator:Se,FlyoutSeparator:Ce,FlyoutSeparatorNavigationPolicy:we,FocusManager:Te,FocusableTreeTraverser:Ee,Generator:De,Gesture:Oe,Grid:ke,HorizontalFlyout:Ae,INPUT_VALUE:je,IconNavigationPolicy:Me,Input:Ne,InsertionMarkerPreviewer:Pe,KeyboardMover:Fe,KeyboardNavigationController:Ie,LabelFlyoutInflater:Le,Menu:Re,MenuItem:ze,MetricsManager:Be,MoveIndicator:Ve,Msg:He,NEXT_STATEMENT:Ue,Names:We,NavigationDirection:Ge,Navigator:Ke,OPPOSITE_TYPE:qe,OUTPUT_VALUE:Je,Options:Ye,PREVIOUS_STATEMENT:Xe,PROCEDURE_CATEGORY_NAME:Ze,Procedures:Qe,RENAME_VARIABLE_ID:$e,RenderedConnection:et,Scrollbar:tt,ScrollbarPair:nt,SeparatorFlyoutInflater:rt,ShortcutItems:it,ShortcutRegistry:at,TOOLBOX_AT_BOTTOM:ot,TOOLBOX_AT_LEFT:st,TOOLBOX_AT_RIGHT:ct,TOOLBOX_AT_TOP:lt,Theme:ut,ThemeManager:dt,Themes:ft,Toast:pt,Toolbox:mt,ToolboxCategory:ht,ToolboxItem:gt,ToolboxItemNavigationPolicy:_t,ToolboxNavigator:vt,ToolboxSeparator:yt,Tooltip:bt,Touch:xt,Trashcan:St,UnattachedFieldError:Ct,VARIABLE_CATEGORY_NAME:wt,VARIABLE_DYNAMIC_CATEGORY_NAME:Tt,VERSION:Et,VariableMap:Dt,VariableModel:Ot,Variables:kt,VariablesDynamic:At,VerticalFlyout:jt,WidgetDiv:Mt,Workspace:Nt,WorkspaceAudio:Pt,WorkspaceCommentNavigationPolicy:Ft,WorkspaceDragger:It,WorkspaceNavigationPolicy:Lt,WorkspaceSvg:Rt,Xml:zt,ZoomControls:Bt,blockAnimations:Vt,blockRendering:Ht,browserEvents:Ut,bubbles:Wt,bumpObjects:Gt,clipboard:Kt,comments:qt,common:Jt,config:Yt,constants:Xt,defineBlocksWithJsonArray:Zt,dialog:Qt,dragging:$t,fieldRegistry:en,geras:tn,getFocusManager:nn,getMainWorkspace:rn,getSelected:an,hasBubble:on,hideChaff:sn,icons:cn,inject:ln,inputs:un,isBoundedElement:dn,isCopyable:fn,isDeletable:pn,isDraggable:mn,isIcon:hn,isObservable:gn,isPaster:_n,isRenderedElement:vn,isSelectable:yn,isSerializable:bn,isVariableBackedParameterModel:xn,keyboardNavigationController:Sn,layers:Cn,navigateBlock:wn,procedures:Tn,registry:En,renderManagement:Dn,serialization:On,setLocale:kn,setParentContainer:An,svgResize:jn,thrasos:Mn,uiPosition:Nn,utils:Pn,zelos:Fn}=e(n(),1).default;var In=t(((e,t)=>{(function(r,i){typeof define==`function`&&define.amd?define([`./blockly_compressed.js`],i):typeof e==`object`?t.exports=i(n()):(r.javascript=i(r.Blockly),r.Blockly.JavaScript=r.javascript.javascriptGenerator)})(e,function(e){var t=e.__namespace__,n=function(e,t,n){return t===`FIRST`?`0`:t===`FROM_END`?e+`.length - 1 - `+n:t===`LAST`?e+`.length - 1`:n},r=function(e,t){var n=0,r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e));do{let i=t.valueToCode(e,`IF`+n,f.NONE)||`false`,a=t.statementToCode(e,`DO`+n);t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=(n>0?` else `:``)+`if (`+i+`) {
1017
+ `+a+`}`,n++}while(e.getInput(`IF`+n));return(e.getInput(`ELSE`)||t.STATEMENT_SUFFIX)&&(n=e.getInput(`ELSE`)?t.statementToCode(e,`ELSE`):``,t.STATEMENT_SUFFIX&&(n=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+n),r+=` else {
1018
+ `+n+`}`),r+`
1019
+ `},i=function(e,n){var r=e.getField(`TIMES`)?String(Number(e.getFieldValue(`TIMES`))):n.valueToCode(e,`TIMES`,f.ASSIGNMENT)||`0`,i=n.statementToCode(e,`DO`);i=n.addLoopTrap(i,e),e=``;var a=n.nameDB_.getDistinctName(`count`,t.P.VARIABLE),o=r;return r.match(/^\w+$/)||t.df(r)||(o=n.nameDB_.getDistinctName(`repeat_end`,t.P.VARIABLE),e+=`var `+o+` = `+r+`;
1020
+ `),e+(`for (var `+a+` = 0; `+a+` < `+o+`; `+a+`++) {
1021
+ `+i+`}
1022
+ `)},a=function(e,t){var n=e.getFieldValue(`OP`);if(n===`NEG`)return e=t.valueToCode(e,`NUM`,f.UNARY_NEGATION)||`0`,e[0]===`-`&&(e=` `+e),[`-`+e,f.UNARY_NEGATION];switch(e=n===`SIN`||n===`COS`||n===`TAN`?t.valueToCode(e,`NUM`,f.DIVISION)||`0`:t.valueToCode(e,`NUM`,f.NONE)||`0`,n){case`ABS`:var r=`Math.abs(`+e+`)`;break;case`ROOT`:r=`Math.sqrt(`+e+`)`;break;case`LN`:r=`Math.log(`+e+`)`;break;case`EXP`:r=`Math.exp(`+e+`)`;break;case`POW10`:r=`Math.pow(10,`+e+`)`;break;case`ROUND`:r=`Math.round(`+e+`)`;break;case`ROUNDUP`:r=`Math.ceil(`+e+`)`;break;case`ROUNDDOWN`:r=`Math.floor(`+e+`)`;break;case`SIN`:r=`Math.sin(`+e+` / 180 * Math.PI)`;break;case`COS`:r=`Math.cos(`+e+` / 180 * Math.PI)`;break;case`TAN`:r=`Math.tan(`+e+` / 180 * Math.PI)`}if(r)return[r,f.FUNCTION_CALL];switch(n){case`LOG10`:r=`Math.log(`+e+`) / Math.log(10)`;break;case`ASIN`:r=`Math.asin(`+e+`) / Math.PI * 180`;break;case`ACOS`:r=`Math.acos(`+e+`) / Math.PI * 180`;break;case`ATAN`:r=`Math.atan(`+e+`) / Math.PI * 180`;break;default:throw Error(`Unknown math operator: `+n)}return[r,f.DIVISION]},o=function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(r+=t.injectId(t.STATEMENT_SUFFIX,e)),r&&=t.prefixLines(r,t.INDENT);var i=``;t.INFINITE_LOOP_TRAP&&(i=t.prefixLines(t.injectId(t.INFINITE_LOOP_TRAP,e),t.INDENT));var a=``;e.getInput(`STACK`)&&(a=t.statementToCode(e,`STACK`));var o=``;e.getInput(`RETURN`)&&(o=t.valueToCode(e,`RETURN`,f.NONE)||``);var s=``;a&&o&&(s=r),o&&=t.INDENT+`return `+o+`;
1023
+ `;var c=[],l=e.getVarModels();for(let e=0;e<l.length;e++)c[e]=t.getVariableName(l[e].getId());return r=`function `+n+`(`+c.join(`, `)+`) {
1024
+ `+r+i+a+s+o+`}`,r=t.scrub_(e,r),t.definitions_[`%`+n]=r,null},s=function(e){return ee.test(e)?[e,f.ATOMIC]:[`String(`+e+`)`,f.FUNCTION_CALL]},c=function(e,t,n){return t===`FIRST`?`0`:t===`FROM_END`?e+`.length - 1 - `+n:t===`LAST`?e+`.length - 1`:n},l=function(e,t){return t=`window.prompt(`+(e.getField(`TEXT`)?t.quote_(e.getFieldValue(`TEXT`)):t.valueToCode(e,`TEXT`,f.NONE)||`''`)+`)`,e.getFieldValue(`TYPE`)===`NUMBER`&&(t=`Number(`+t+`)`),[t,f.FUNCTION_CALL]},u=function(e,t){return[t.getVariableName(e.getFieldValue(`VAR`)),f.ATOMIC]},d=function(e,t){var n=t.valueToCode(e,`VALUE`,f.ASSIGNMENT)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` = `+n+`;
1025
+ `},f,p=f||={};p[p.ATOMIC=0]=`ATOMIC`,p[p.NEW=1.1]=`NEW`,p[p.MEMBER=1.2]=`MEMBER`,p[p.FUNCTION_CALL=2]=`FUNCTION_CALL`,p[p.INCREMENT=3]=`INCREMENT`,p[p.DECREMENT=3]=`DECREMENT`,p[p.BITWISE_NOT=4.1]=`BITWISE_NOT`,p[p.UNARY_PLUS=4.2]=`UNARY_PLUS`,p[p.UNARY_NEGATION=4.3]=`UNARY_NEGATION`,p[p.LOGICAL_NOT=4.4]=`LOGICAL_NOT`,p[p.TYPEOF=4.5]=`TYPEOF`,p[p.VOID=4.6]=`VOID`,p[p.DELETE=4.7]=`DELETE`,p[p.AWAIT=4.8]=`AWAIT`,p[p.EXPONENTIATION=5]=`EXPONENTIATION`,p[p.MULTIPLICATION=5.1]=`MULTIPLICATION`,p[p.DIVISION=5.2]=`DIVISION`,p[p.MODULUS=5.3]=`MODULUS`,p[p.SUBTRACTION=6.1]=`SUBTRACTION`,p[p.ADDITION=6.2]=`ADDITION`,p[p.BITWISE_SHIFT=7]=`BITWISE_SHIFT`,p[p.RELATIONAL=8]=`RELATIONAL`,p[p.IN=8]=`IN`,p[p.INSTANCEOF=8]=`INSTANCEOF`,p[p.EQUALITY=9]=`EQUALITY`,p[p.BITWISE_AND=10]=`BITWISE_AND`,p[p.BITWISE_XOR=11]=`BITWISE_XOR`,p[p.BITWISE_OR=12]=`BITWISE_OR`,p[p.LOGICAL_AND=13]=`LOGICAL_AND`,p[p.LOGICAL_OR=14]=`LOGICAL_OR`,p[p.CONDITIONAL=15]=`CONDITIONAL`,p[p.ASSIGNMENT=16]=`ASSIGNMENT`,p[p.YIELD=17]=`YIELD`,p[p.COMMA=18]=`COMMA`,p[p.NONE=99]=`NONE`;var m=class extends t.Ip{constructor(e=`JavaScript`){super(e),this.ORDER_OVERRIDES=[[f.FUNCTION_CALL,f.MEMBER],[f.FUNCTION_CALL,f.FUNCTION_CALL],[f.MEMBER,f.MEMBER],[f.MEMBER,f.FUNCTION_CALL],[f.LOGICAL_NOT,f.LOGICAL_NOT],[f.MULTIPLICATION,f.MULTIPLICATION],[f.ADDITION,f.ADDITION],[f.LOGICAL_AND,f.LOGICAL_AND],[f.LOGICAL_OR,f.LOGICAL_OR]],this.isInitialized=!1;for(let t in f)e=f[t],typeof e!=`string`&&(this[`ORDER_`+t]=e);this.addReservedWords(`break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,in,instanceof,new,return,super,switch,this,throw,try,typeof,var,void,while,with,yield,enum,implements,interface,let,package,private,protected,public,static,await,null,true,false,arguments,`+Object.getOwnPropertyNames(globalThis).join(`,`))}init(e){super.init(e),this.nameDB_?this.nameDB_.reset():this.nameDB_=new t.aj(this.RESERVED_WORDS_),this.nameDB_.setVariableMap(e.getVariableMap()),this.nameDB_.populateVariables(e),this.nameDB_.populateProcedures(e);var n=[],r=t.Bd(e);for(let e=0;e<r.length;e++)n.push(this.nameDB_.getName(r[e],t.P.DEVELOPER_VARIABLE));for(e=t.Ad(e),r=0;r<e.length;r++)n.push(this.nameDB_.getName(e[r].getId(),t.P.VARIABLE));n.length&&(this.definitions_.variables=`var `+n.join(`, `)+`;`),this.isInitialized=!0}finish(e){var t=Object.values(this.definitions_);return super.finish(e),this.isInitialized=!1,this.nameDB_.reset(),t.join(`
1026
+
1027
+ `)+`
1028
+
1029
+
1030
+ `+e}scrubNakedValue(e){return e+`;
1031
+ `}quote_(e){return e=e.replace(/\\/g,`\\\\`).replace(/\n/g,`\\
1032
+ `).replace(/'/g,`\\'`),`'`+e+`'`}multiline_quote_(e){return e.split(/\n/g).map(this.quote_).join(` + '\\n' +
1033
+ `)}scrub_(e,n,r=!1){var i=``;if(!e.outputConnection||!e.outputConnection.targetConnection){var a=e.getCommentText();a&&(a=t.cf(a,this.COMMENT_WRAP-3),i+=this.prefixLines(a+`
1034
+ `,`// `));for(let n=0;n<e.inputList.length;n++)e.inputList[n].type===t.he.VALUE&&(a=e.inputList[n].connection.targetBlock())&&(a=this.allNestedComments(a))&&(i+=this.prefixLines(a,`// `))}return e=e.nextConnection&&e.nextConnection.targetBlock(),r=r?``:this.blockToCode(e),i+n+r}getAdjusted(e,n,r=0,i=!1,a=f.NONE){e.workspace.options.oneBasedIndex&&r--;var o=e.workspace.options.oneBasedIndex?`1`:`0`,s=a;return r>0?s=f.ADDITION:r<0?s=f.SUBTRACTION:i&&(s=f.UNARY_NEGATION),e=this.valueToCode(e,n,s)||o,r===0&&!i?e:t.df(e)?(e=String(Number(e)+r),i&&(e=String(-Number(e))),e):(r>0?e=`${e} + ${r}`:r<0&&(e=`${e} - ${-r}`),i&&(e=r?`-(${e})`:`-${e}`),Math.floor(a)>=Math.floor(s)&&(e=`(${e})`),e)}},h={};h.controls_if=r,h.controls_ifelse=r,h.logic_boolean=function(e){return[e.getFieldValue(`BOOL`)===`TRUE`?`true`:`false`,f.ATOMIC]},h.logic_compare=function(e,t){var n={EQ:`==`,NEQ:`!=`,LT:`<`,LTE:`<=`,GT:`>`,GTE:`>=`}[e.getFieldValue(`OP`)],r=n===`==`||n===`!=`?f.EQUALITY:f.RELATIONAL,i=t.valueToCode(e,`A`,r)||`0`;return e=t.valueToCode(e,`B`,r)||`0`,[i+` `+n+` `+e,r]},h.logic_negate=function(e,t){var n=f.LOGICAL_NOT;return[`!`+(t.valueToCode(e,`BOOL`,n)||`true`),n]},h.logic_null=function(){return[`null`,f.ATOMIC]},h.logic_operation=function(e,t){var n=e.getFieldValue(`OP`)===`AND`?`&&`:`||`,r=n===`&&`?f.LOGICAL_AND:f.LOGICAL_OR,i=t.valueToCode(e,`A`,r);return e=t.valueToCode(e,`B`,r),i||e?(t=n===`&&`?`true`:`false`,i||=t,e||=t):e=i=`false`,[i+` `+n+` `+e,r]},h.logic_ternary=function(e,t){var n=t.valueToCode(e,`IF`,f.CONDITIONAL)||`false`,r=t.valueToCode(e,`THEN`,f.CONDITIONAL)||`null`;return e=t.valueToCode(e,`ELSE`,f.CONDITIONAL)||`null`,[n+` ? `+r+` : `+e,f.CONDITIONAL]};var g={controls_flow_statements:function(e,t){var n=``;if(t.STATEMENT_PREFIX&&(n+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(n+=t.injectId(t.STATEMENT_SUFFIX,e)),t.STATEMENT_PREFIX){let r=e.getSurroundLoop();r&&!r.suppressPrefixSuffix&&(n+=t.injectId(t.STATEMENT_PREFIX,r))}switch(e.getFieldValue(`FLOW`)){case`BREAK`:return n+`break;
1035
+ `;case`CONTINUE`:return n+`continue;
1036
+ `}throw Error(`Unknown flow statement.`)},controls_for:function(e,n){var r=n.getVariableName(e.getFieldValue(`VAR`)),i=n.valueToCode(e,`FROM`,f.ASSIGNMENT)||`0`,a=n.valueToCode(e,`TO`,f.ASSIGNMENT)||`0`,o=n.valueToCode(e,`BY`,f.ASSIGNMENT)||`1`,s=n.statementToCode(e,`DO`);if(s=n.addLoopTrap(s,e),t.df(i)&&t.df(a)&&t.df(o))n=Number(i)<=Number(a),e=`for (`+r+` = `+i+`; `+r+(n?` <= `:` >= `)+a+`; `+r,r=Math.abs(Number(o)),e=r===1?e+(n?`++`:`--`):e+((n?` += `:` -= `)+r),e+=`) {
1037
+ `+s+`}
1038
+ `;else{e=``;let c=i;i.match(/^\w+$/)||t.df(i)||(c=n.nameDB_.getDistinctName(r+`_start`,t.P.VARIABLE),e+=`var `+c+` = `+i+`;
1039
+ `),i=a,a.match(/^\w+$/)||t.df(a)||(i=n.nameDB_.getDistinctName(r+`_end`,t.P.VARIABLE),e+=`var `+i+` = `+a+`;
1040
+ `),a=n.nameDB_.getDistinctName(r+`_inc`,t.P.VARIABLE),e+=`var `+a+` = `,e=t.df(o)?e+(Math.abs(Number(o))+`;
1041
+ `):e+(`Math.abs(`+o+`);
1042
+ `),e+=`if (`+c+` > `+i+`) {
1043
+ `,e+=n.INDENT+a+` = -`+a+`;
1044
+ `,e=e+`}
1045
+ for (`+(r+` = `+c+`; `+a+` >= 0 ? `+r+` <= `+i+` : `+r+` >= `+i+`; `+r+` += `+a+`) {
1046
+ `+s+`}
1047
+ `)}return e},controls_forEach:function(e,n){var r=n.getVariableName(e.getFieldValue(`VAR`)),i=n.valueToCode(e,`LIST`,f.ASSIGNMENT)||`[]`,a=n.statementToCode(e,`DO`);a=n.addLoopTrap(a,e),e=``;var o=i;return i.match(/^\w+$/)||(o=n.nameDB_.getDistinctName(r+`_list`,t.P.VARIABLE),e+=`var `+o+` = `+i+`;
1048
+ `),i=n.nameDB_.getDistinctName(r+`_index`,t.P.VARIABLE),a=n.INDENT+r+` = `+o+`[`+i+`];
1049
+ `+a,e+(`for (var `+i+` in `+o+`) {
1050
+ `+a+`}
1051
+ `)}};g.controls_repeat=i,g.controls_repeat_ext=i,g.controls_whileUntil=function(e,t){var n=e.getFieldValue(`MODE`)===`UNTIL`,r=t.valueToCode(e,`BOOL`,n?f.LOGICAL_NOT:f.NONE)||`false`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e),n&&(r=`!`+r),`while (`+r+`) {
1052
+ `+i+`}
1053
+ `};var _={math_arithmetic:function(e,t){var n={ADD:[` + `,f.ADDITION],MINUS:[` - `,f.SUBTRACTION],MULTIPLY:[` * `,f.MULTIPLICATION],DIVIDE:[` / `,f.DIVISION],POWER:[null,f.NONE]}[e.getFieldValue(`OP`)],r=n[0];n=n[1];var i=t.valueToCode(e,`A`,n)||`0`;return e=t.valueToCode(e,`B`,n)||`0`,r?[i+r+e,n]:[`Math.pow(`+i+`, `+e+`)`,f.FUNCTION_CALL]},math_atan2:function(e,t){var n=t.valueToCode(e,`X`,f.NONE)||`0`;return[`Math.atan2(`+(t.valueToCode(e,`Y`,f.NONE)||`0`)+`, `+n+`) / Math.PI * 180`,f.DIVISION]},math_change:function(e,t){var n=t.valueToCode(e,`DELTA`,f.ADDITION)||`0`;return e=t.getVariableName(e.getFieldValue(`VAR`)),e+` = (typeof `+e+` === 'number' ? `+e+` : 0) + `+n+`;
1054
+ `},math_constant:function(e){return{PI:[`Math.PI`,f.MEMBER],E:[`Math.E`,f.MEMBER],GOLDEN_RATIO:[`(1 + Math.sqrt(5)) / 2`,f.DIVISION],SQRT2:[`Math.SQRT2`,f.MEMBER],SQRT1_2:[`Math.SQRT1_2`,f.MEMBER],INFINITY:[`Infinity`,f.ATOMIC]}[e.getFieldValue(`CONSTANT`)]},math_constrain:function(e,t){var n=t.valueToCode(e,`VALUE`,f.NONE)||`0`,r=t.valueToCode(e,`LOW`,f.NONE)||`0`;return e=t.valueToCode(e,`HIGH`,f.NONE)||`Infinity`,[`Math.min(Math.max(`+n+`, `+r+`), `+e+`)`,f.FUNCTION_CALL]},math_modulo:function(e,t){var n=t.valueToCode(e,`DIVIDEND`,f.MODULUS)||`0`;return e=t.valueToCode(e,`DIVISOR`,f.MODULUS)||`0`,[n+` % `+e,f.MODULUS]},math_number:function(e){return e=Number(e.getFieldValue(`NUM`)),[String(e),e>=0?f.ATOMIC:f.UNARY_NEGATION]},math_number_property:function(e,t){var n={EVEN:[` % 2 === 0`,f.MODULUS,f.EQUALITY],ODD:[` % 2 === 1`,f.MODULUS,f.EQUALITY],WHOLE:[` % 1 === 0`,f.MODULUS,f.EQUALITY],POSITIVE:[` > 0`,f.RELATIONAL,f.RELATIONAL],NEGATIVE:[` < 0`,f.RELATIONAL,f.RELATIONAL],DIVISIBLE_BY:[null,f.MODULUS,f.EQUALITY],PRIME:[null,f.NONE,f.FUNCTION_CALL]},r=e.getFieldValue(`PROPERTY`),[i,a,o]=n[r];return n=t.valueToCode(e,`NUMBER_TO_CHECK`,a)||`0`,r===`PRIME`?e=t.provideFunction_(`mathIsPrime`,`
1055
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(n) {
1056
+ // https://en.wikipedia.org/wiki/Primality_test#Naive_methods
1057
+ if (n == 2 || n == 3) {
1058
+ return true;
1059
+ }
1060
+ // False if n is NaN, negative, is 1, or not whole.
1061
+ // And false if n is divisible by 2 or 3.
1062
+ if (isNaN(n) || n <= 1 || n % 1 !== 0 || n % 2 === 0 || n % 3 === 0) {
1063
+ return false;
1064
+ }
1065
+ // Check all the numbers of form 6k +/- 1, up to sqrt(n).
1066
+ for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {
1067
+ if (n % (x - 1) === 0 || n % (x + 1) === 0) {
1068
+ return false;
1069
+ }
1070
+ }
1071
+ return true;
1072
+ }
1073
+ `)+`(`+n+`)`:r===`DIVISIBLE_BY`?(e=t.valueToCode(e,`DIVISOR`,f.MODULUS)||`0`,e=n+` % `+e+` === 0`):e=n+i,[e,o]},math_on_list:function(e,t){var n=e.getFieldValue(`OP`);switch(n){case`SUM`:e=t.valueToCode(e,`LIST`,f.MEMBER)||`[]`,e+=`.reduce(function(x, y) {return x + y;}, 0)`;break;case`MIN`:e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=`Math.min.apply(null, `+e+`)`;break;case`MAX`:e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=`Math.max.apply(null, `+e+`)`;break;case`AVERAGE`:n=t.provideFunction_(`mathMean`,`
1074
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(myList) {
1075
+ return myList.reduce(function(x, y) {return x + y;}, 0) / myList.length;
1076
+ }
1077
+ `),e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=n+`(`+e+`)`;break;case`MEDIAN`:n=t.provideFunction_(`mathMedian`,`
1078
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(myList) {
1079
+ var localList = myList.filter(function (x) {return typeof x === 'number';});
1080
+ if (!localList.length) return null;
1081
+ localList.sort(function(a, b) {return b - a;});
1082
+ if (localList.length % 2 === 0) {
1083
+ return (localList[localList.length / 2 - 1] + localList[localList.length / 2]) / 2;
1084
+ } else {
1085
+ return localList[(localList.length - 1) / 2];
1086
+ }
1087
+ }
1088
+ `),e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=n+`(`+e+`)`;break;case`MODE`:n=t.provideFunction_(`mathModes`,`
1089
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(values) {
1090
+ var modes = [];
1091
+ var counts = [];
1092
+ var maxCount = 0;
1093
+ for (var i = 0; i < values.length; i++) {
1094
+ var value = values[i];
1095
+ var found = false;
1096
+ var thisCount;
1097
+ for (var j = 0; j < counts.length; j++) {
1098
+ if (counts[j][0] === value) {
1099
+ thisCount = ++counts[j][1];
1100
+ found = true;
1101
+ break;
1102
+ }
1103
+ }
1104
+ if (!found) {
1105
+ counts.push([value, 1]);
1106
+ thisCount = 1;
1107
+ }
1108
+ maxCount = Math.max(thisCount, maxCount);
1109
+ }
1110
+ for (var j = 0; j < counts.length; j++) {
1111
+ if (counts[j][1] === maxCount) {
1112
+ modes.push(counts[j][0]);
1113
+ }
1114
+ }
1115
+ return modes;
1116
+ }
1117
+ `),e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=n+`(`+e+`)`;break;case`STD_DEV`:n=t.provideFunction_(`mathStandardDeviation`,`
1118
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(numbers) {
1119
+ var n = numbers.length;
1120
+ if (!n) return null;
1121
+ var mean = numbers.reduce(function(x, y) {return x + y;}) / n;
1122
+ var variance = 0;
1123
+ for (var j = 0; j < n; j++) {
1124
+ variance += Math.pow(numbers[j] - mean, 2);
1125
+ }
1126
+ variance /= n;
1127
+ return Math.sqrt(variance);
1128
+ }
1129
+ `),e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=n+`(`+e+`)`;break;case`RANDOM`:n=t.provideFunction_(`mathRandomList`,`
1130
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(list) {
1131
+ var x = Math.floor(Math.random() * list.length);
1132
+ return list[x];
1133
+ }
1134
+ `),e=t.valueToCode(e,`LIST`,f.NONE)||`[]`,e=n+`(`+e+`)`;break;default:throw Error(`Unknown operator: `+n)}return[e,f.FUNCTION_CALL]},math_random_float:function(){return[`Math.random()`,f.FUNCTION_CALL]},math_random_int:function(e,t){var n=t.valueToCode(e,`FROM`,f.NONE)||`0`;return e=t.valueToCode(e,`TO`,f.NONE)||`0`,[t.provideFunction_(`mathRandomInt`,`
1135
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(a, b) {
1136
+ if (a > b) {
1137
+ // Swap a and b to ensure a is smaller.
1138
+ var c = a;
1139
+ a = b;
1140
+ b = c;
1141
+ }
1142
+ return Math.floor(Math.random() * (b - a + 1) + a);
1143
+ }
1144
+ `)+`(`+n+`, `+e+`)`,f.FUNCTION_CALL]}};_.math_round=a,_.math_single=a,_.math_trig=a;var v={procedures_callnoreturn:function(e,t){return t.forBlock.procedures_callreturn(e,t)[0]+`;
1145
+ `},procedures_callreturn:function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=[],i=e.getVarModels();for(let n=0;n<i.length;n++)r[n]=t.valueToCode(e,`ARG`+n,f.NONE)||`null`;return[n+`(`+r.join(`, `)+`)`,f.FUNCTION_CALL]}};v.procedures_defnoreturn=o,v.procedures_defreturn=o,v.procedures_ifreturn=function(e,t){var n=`if (`+(t.valueToCode(e,`CONDITION`,f.NONE)||`false`)+`) {
1146
+ `;return t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_?(e=t.valueToCode(e,`VALUE`,f.NONE)||`null`,n+=t.INDENT+`return `+e+`;
1147
+ `):n+=t.INDENT+`return;
1148
+ `,n+`}
1149
+ `};var ee=/^\s*'([^']|\\')*'\s*$/,y={text:function(e,t){return[t.quote_(e.getFieldValue(`TEXT`)),f.ATOMIC]},text_append:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`));return e=t.valueToCode(e,`TEXT`,f.NONE)||`''`,n+` += `+s(e)[0]+`;
1150
+ `},text_changeCase:function(e,t){var n={UPPERCASE:`.toUpperCase()`,LOWERCASE:`.toLowerCase()`,TITLECASE:null}[e.getFieldValue(`CASE`)];return e=t.valueToCode(e,`TEXT`,n?f.MEMBER:f.NONE)||`''`,[n?e+n:t.provideFunction_(`textToTitleCase`,`
1151
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str) {
1152
+ return str.replace(/\\S+/g,
1153
+ function(txt) {return txt[0].toUpperCase() + txt.substring(1).toLowerCase();});
1154
+ }
1155
+ `)+`(`+e+`)`,f.FUNCTION_CALL]},text_charAt:function(e,t){var n=e.getFieldValue(`WHERE`)||`FROM_START`,r=t.valueToCode(e,`VALUE`,n===`RANDOM`?f.NONE:f.MEMBER)||`''`;switch(n){case`FIRST`:return[r+`.charAt(0)`,f.FUNCTION_CALL];case`LAST`:return[r+`.slice(-1)`,f.FUNCTION_CALL];case`FROM_START`:return e=t.getAdjusted(e,`AT`),[r+`.charAt(`+e+`)`,f.FUNCTION_CALL];case`FROM_END`:return e=t.getAdjusted(e,`AT`,1,!0),[r+`.slice(`+e+`).charAt(0)`,f.FUNCTION_CALL];case`RANDOM`:return[t.provideFunction_(`textRandomLetter`,`
1156
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(text) {
1157
+ var x = Math.floor(Math.random() * text.length);
1158
+ return text[x];
1159
+ }
1160
+ `)+`(`+r+`)`,f.FUNCTION_CALL]}throw Error(`Unhandled option (text_charAt).`)},text_count:function(e,t){var n=t.valueToCode(e,`TEXT`,f.NONE)||`''`;return e=t.valueToCode(e,`SUB`,f.NONE)||`''`,[t.provideFunction_(`textCount`,`
1161
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle) {
1162
+ if (needle.length === 0) {
1163
+ return haystack.length + 1;
1164
+ } else {
1165
+ return haystack.split(needle).length - 1;
1166
+ }
1167
+ }
1168
+ `)+`(`+n+`, `+e+`)`,f.FUNCTION_CALL]},text_getSubstring:function(e,t){var n={FIRST:`First`,LAST:`Last`,FROM_START:`FromStart`,FROM_END:`FromEnd`},r=e.getFieldValue(`WHERE1`),i=e.getFieldValue(`WHERE2`),a=r!==`FROM_END`&&r!==`LAST`&&i!==`FROM_END`&&i!==`LAST`,o=t.valueToCode(e,`STRING`,a?f.MEMBER:f.NONE)||`''`;if(r===`FIRST`&&i===`LAST`)return[o,f.NONE];if(o.match(/^'?\w+'?$/)||a){switch(r){case`FROM_START`:n=t.getAdjusted(e,`AT1`);break;case`FROM_END`:n=t.getAdjusted(e,`AT1`,1,!1,f.SUBTRACTION),n=o+`.length - `+n;break;case`FIRST`:n=`0`;break;default:throw Error(`Unhandled option (text_getSubstring).`)}switch(i){case`FROM_START`:t=t.getAdjusted(e,`AT2`,1);break;case`FROM_END`:t=t.getAdjusted(e,`AT2`,0,!1,f.SUBTRACTION),t=o+`.length - `+t;break;case`LAST`:t=o+`.length`;break;default:throw Error(`Unhandled option (text_getSubstring).`)}o=o+`.slice(`+n+`, `+t+`)`}else a=t.getAdjusted(e,`AT1`),e=t.getAdjusted(e,`AT2`),o=t.provideFunction_(`subsequence`+n[r]+n[i],`
1169
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(sequence${r===`FROM_END`||r===`FROM_START`?`, at1`:``}${i===`FROM_END`||i===`FROM_START`?`, at2`:``}) {
1170
+ var start = ${c(`sequence`,r,`at1`)};
1171
+ var end = ${c(`sequence`,i,`at2`)} + 1;
1172
+ return sequence.slice(start, end);
1173
+ }
1174
+ `)+`(`+o+(r===`FROM_END`||r===`FROM_START`?`, `+a:``)+(i===`FROM_END`||i===`FROM_START`?`, `+e:``)+`)`;return[o,f.FUNCTION_CALL]},text_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`indexOf`:`lastIndexOf`,r=t.valueToCode(e,`FIND`,f.NONE)||`''`;return t=(t.valueToCode(e,`VALUE`,f.MEMBER)||`''`)+`.`+n+`(`+r+`)`,e.workspace.options.oneBasedIndex?[t+` + 1`,f.ADDITION]:[t,f.FUNCTION_CALL]},text_isEmpty:function(e,t){return[`!`+(t.valueToCode(e,`VALUE`,f.MEMBER)||`''`)+`.length`,f.LOGICAL_NOT]},text_join:function(e,t){switch(e.itemCount_){case 0:return[`''`,f.ATOMIC];case 1:return e=t.valueToCode(e,`ADD0`,f.NONE)||`''`,s(e);case 2:var n=t.valueToCode(e,`ADD0`,f.NONE)||`''`;return e=t.valueToCode(e,`ADD1`,f.NONE)||`''`,[s(n)[0]+` + `+s(e)[0],f.ADDITION];default:n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,f.NONE)||`''`;return[`[`+n.join(`,`)+`].join('')`,f.FUNCTION_CALL]}},text_length:function(e,t){return[(t.valueToCode(e,`VALUE`,f.MEMBER)||`''`)+`.length`,f.MEMBER]},text_print:function(e,t){return`window.alert(`+(t.valueToCode(e,`TEXT`,f.NONE)||`''`)+`);
1175
+ `}};y.text_prompt=l,y.text_prompt_ext=l,y.text_replace=function(e,t){var n=t.valueToCode(e,`TEXT`,f.NONE)||`''`,r=t.valueToCode(e,`FROM`,f.NONE)||`''`;return e=t.valueToCode(e,`TO`,f.NONE)||`''`,[t.provideFunction_(`textReplace`,`
1176
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle, replacement) {
1177
+ needle = needle.replace(/([-()\\[\\]{}+?*.$\\^|,:#<!\\\\])/g, '\\\\$1')
1178
+ .replace(/\\x08/g, '\\\\x08');
1179
+ return haystack.replace(new RegExp(needle, 'g'), replacement);
1180
+ }
1181
+ `)+`(`+n+`, `+r+`, `+e+`)`,f.FUNCTION_CALL]},y.text_reverse=function(e,t){return[(t.valueToCode(e,`TEXT`,f.MEMBER)||`''`)+`.split('').reverse().join('')`,f.FUNCTION_CALL]},y.text_trim=function(e,t){var n={LEFT:`.replace(/^[\\s\\xa0]+/, '')`,RIGHT:`.replace(/[\\s\\xa0]+$/, '')`,BOTH:`.trim()`}[e.getFieldValue(`MODE`)];return[(t.valueToCode(e,`TEXT`,f.MEMBER)||`''`)+n,f.FUNCTION_CALL]};var te={};te.variables_get=u,te.variables_set=d;var b={};b.variables_get_dynamic=u,b.variables_set_dynamic=d;var ne=new m,re=Object.assign({},{lists_create_empty:function(){return[`[]`,f.ATOMIC]},lists_create_with:function(e,t){var n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,f.NONE)||`null`;return[`[`+n.join(`, `)+`]`,f.ATOMIC]},lists_getIndex:function(e,t){var n=e.getFieldValue(`MODE`)||`GET`,r=e.getFieldValue(`WHERE`)||`FROM_START`,i=t.valueToCode(e,`VALUE`,r===`RANDOM`?f.NONE:f.MEMBER)||`[]`;switch(r){case`FIRST`:if(n===`GET`)return[i+`[0]`,f.MEMBER];if(n===`GET_REMOVE`)return[i+`.shift()`,f.MEMBER];if(n===`REMOVE`)return i+`.shift();
1182
+ `;break;case`LAST`:if(n===`GET`)return[i+`.slice(-1)[0]`,f.MEMBER];if(n===`GET_REMOVE`)return[i+`.pop()`,f.MEMBER];if(n===`REMOVE`)return i+`.pop();
1183
+ `;break;case`FROM_START`:if(e=t.getAdjusted(e,`AT`),n===`GET`)return[i+`[`+e+`]`,f.MEMBER];if(n===`GET_REMOVE`)return[i+`.splice(`+e+`, 1)[0]`,f.FUNCTION_CALL];if(n===`REMOVE`)return i+`.splice(`+e+`, 1);
1184
+ `;break;case`FROM_END`:if(e=t.getAdjusted(e,`AT`,1,!0),n===`GET`)return[i+`.slice(`+e+`)[0]`,f.FUNCTION_CALL];if(n===`GET_REMOVE`)return[i+`.splice(`+e+`, 1)[0]`,f.FUNCTION_CALL];if(n===`REMOVE`)return i+`.splice(`+e+`, 1);`;break;case`RANDOM`:if(i=t.provideFunction_(`listsGetRandomItem`,`
1185
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(list, remove) {
1186
+ var x = Math.floor(Math.random() * list.length);
1187
+ if (remove) {
1188
+ return list.splice(x, 1)[0];
1189
+ } else {
1190
+ return list[x];
1191
+ }
1192
+ }
1193
+ `)+`(`+i+`, `+(n!==`GET`)+`)`,n===`GET`||n===`GET_REMOVE`)return[i,f.FUNCTION_CALL];if(n===`REMOVE`)return i+`;
1194
+ `}throw Error(`Unhandled combination (lists_getIndex).`)},lists_getSublist:function(e,t){var r={FIRST:`First`,LAST:`Last`,FROM_START:`FromStart`,FROM_END:`FromEnd`},i=t.valueToCode(e,`LIST`,f.MEMBER)||`[]`,a=e.getFieldValue(`WHERE1`),o=e.getFieldValue(`WHERE2`);if(a===`FIRST`&&o===`LAST`)i+=`.slice(0)`;else if(i.match(/^\w+$/)||a!==`FROM_END`&&o===`FROM_START`){switch(a){case`FROM_START`:r=t.getAdjusted(e,`AT1`);break;case`FROM_END`:r=t.getAdjusted(e,`AT1`,1,!1,f.SUBTRACTION),r=i+`.length - `+r;break;case`FIRST`:r=`0`;break;default:throw Error(`Unhandled option (lists_getSublist).`)}switch(o){case`FROM_START`:t=t.getAdjusted(e,`AT2`,1);break;case`FROM_END`:t=t.getAdjusted(e,`AT2`,0,!1,f.SUBTRACTION),t=i+`.length - `+t;break;case`LAST`:t=i+`.length`;break;default:throw Error(`Unhandled option (lists_getSublist).`)}i=i+`.slice(`+r+`, `+t+`)`}else{let s=t.getAdjusted(e,`AT1`);e=t.getAdjusted(e,`AT2`),i=t.provideFunction_(`subsequence`+r[a]+r[o],`
1195
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(sequence${a===`FROM_END`||a===`FROM_START`?`, at1`:``}${o===`FROM_END`||o===`FROM_START`?`, at2`:``}) {
1196
+ var start = ${n(`sequence`,a,`at1`)};
1197
+ var end = ${n(`sequence`,o,`at2`)} + 1;
1198
+ return sequence.slice(start, end);
1199
+ }
1200
+ `)+`(`+i+(a===`FROM_END`||a===`FROM_START`?`, `+s:``)+(o===`FROM_END`||o===`FROM_START`?`, `+e:``)+`)`}return[i,f.FUNCTION_CALL]},lists_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`indexOf`:`lastIndexOf`,r=t.valueToCode(e,`FIND`,f.NONE)||`''`;return t=(t.valueToCode(e,`VALUE`,f.MEMBER)||`[]`)+`.`+n+`(`+r+`)`,e.workspace.options.oneBasedIndex?[t+` + 1`,f.ADDITION]:[t,f.FUNCTION_CALL]},lists_isEmpty:function(e,t){return[`!`+(t.valueToCode(e,`VALUE`,f.MEMBER)||`[]`)+`.length`,f.LOGICAL_NOT]},lists_length:function(e,t){return[(t.valueToCode(e,`VALUE`,f.MEMBER)||`[]`)+`.length`,f.MEMBER]},lists_repeat:function(e,t){var n=t.provideFunction_(`listsRepeat`,`
1201
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(value, n) {
1202
+ var array = [];
1203
+ for (var i = 0; i < n; i++) {
1204
+ array[i] = value;
1205
+ }
1206
+ return array;
1207
+ }
1208
+ `),r=t.valueToCode(e,`ITEM`,f.NONE)||`null`;return e=t.valueToCode(e,`NUM`,f.NONE)||`0`,[n+`(`+r+`, `+e+`)`,f.FUNCTION_CALL]},lists_reverse:function(e,t){return[(t.valueToCode(e,`LIST`,f.FUNCTION_CALL)||`[]`)+`.slice().reverse()`,f.FUNCTION_CALL]},lists_setIndex:function(e,n){function r(){if(i.match(/^\w+$/))return``;var e=n.nameDB_.getDistinctName(`tmpList`,t.P.VARIABLE),r=`var `+e+` = `+i+`;
1209
+ `;return i=e,r}var i=n.valueToCode(e,`LIST`,f.MEMBER)||`[]`,a=e.getFieldValue(`MODE`)||`GET`,o=e.getFieldValue(`WHERE`)||`FROM_START`,s=n.valueToCode(e,`TO`,f.ASSIGNMENT)||`null`;switch(o){case`FIRST`:if(a===`SET`)return i+`[0] = `+s+`;
1210
+ `;if(a===`INSERT`)return i+`.unshift(`+s+`);
1211
+ `;break;case`LAST`:if(a===`SET`)return r()+(i+`[`+i+`.length - 1] = `+s+`;
1212
+ `);if(a===`INSERT`)return i+`.push(`+s+`);
1213
+ `;break;case`FROM_START`:if(e=n.getAdjusted(e,`AT`),a===`SET`)return i+`[`+e+`] = `+s+`;
1214
+ `;if(a===`INSERT`)return i+`.splice(`+e+`, 0, `+s+`);
1215
+ `;break;case`FROM_END`:if(e=n.getAdjusted(e,`AT`,1,!1,f.SUBTRACTION),o=r(),a===`SET`)return o+(i+`[`+i+`.length - `+e+`] = `+s+`;
1216
+ `);if(a===`INSERT`)return o+(i+`.splice(`+i+`.length - `+e+`, 0, `+s+`);
1217
+ `);break;case`RANDOM`:if(e=r(),o=n.nameDB_.getDistinctName(`tmpX`,t.P.VARIABLE),e+=`var `+o+` = Math.floor(Math.random() * `+i+`.length);
1218
+ `,a===`SET`)return e+(i+`[`+o+`] = `+s+`;
1219
+ `);if(a===`INSERT`)return e+(i+`.splice(`+o+`, 0, `+s+`);
1220
+ `)}throw Error(`Unhandled combination (lists_setIndex).`)},lists_sort:function(e,t){var n=t.valueToCode(e,`LIST`,f.FUNCTION_CALL)||`[]`,r=e.getFieldValue(`DIRECTION`)===`1`?1:-1;return e=e.getFieldValue(`TYPE`),t=t.provideFunction_(`listsGetSortCompare`,`
1221
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(type, direction) {
1222
+ var compareFuncs = {
1223
+ 'NUMERIC': function(a, b) {
1224
+ return Number(a) - Number(b); },
1225
+ 'TEXT': function(a, b) {
1226
+ return String(a) > String(b) ? 1 : -1; },
1227
+ 'IGNORE_CASE': function(a, b) {
1228
+ return String(a).toLowerCase() > String(b).toLowerCase() ? 1 : -1; },
1229
+ };
1230
+ var compare = compareFuncs[type];
1231
+ return function(a, b) { return compare(a, b) * direction; };
1232
+ }
1233
+ `),[n+`.slice().sort(`+t+`("`+e+`", `+r+`))`,f.FUNCTION_CALL]},lists_split:function(e,t){var n=t.valueToCode(e,`INPUT`,f.MEMBER);if(t=t.valueToCode(e,`DELIM`,f.NONE)||`''`,e=e.getFieldValue(`MODE`),e===`SPLIT`)n||=`''`,e=`split`;else if(e===`JOIN`)n||=`[]`,e=`join`;else throw Error(`Unknown mode: `+e);return[n+`.`+e+`(`+t+`)`,f.FUNCTION_CALL]}},h,g,_,v,y,te,b);for(let e in re)ne.forBlock[e]=re[e];var ie={};return ie.JavascriptGenerator=m,ie.Order=f,ie.javascriptGenerator=ne,t.__chunk_javascript=ie,t.__chunk_javascript.__namespace__=t,t.__chunk_javascript})}));const{JavascriptGenerator:Ln,Order:Rn,javascriptGenerator:zn}=e(In(),1).default;function Bn(){this.__data__=[],this.size=0}function Vn(e,t){return e===t||e!==e&&t!==t}function Hn(e,t){for(var n=e.length;n--;)if(Vn(e[n][0],t))return n;return-1}var Un=Array.prototype.splice;function Wn(e){var t=this.__data__,n=Hn(t,e);return n<0?!1:(n==t.length-1?t.pop():Un.call(t,n,1),--this.size,!0)}function Gn(e){var t=this.__data__,n=Hn(t,e);return n<0?void 0:t[n][1]}function Kn(e){return Hn(this.__data__,e)>-1}function qn(e,t){var n=this.__data__,r=Hn(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function Jn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Jn.prototype.clear=Bn,Jn.prototype.delete=Wn,Jn.prototype.get=Gn,Jn.prototype.has=Kn,Jn.prototype.set=qn;function Yn(){this.__data__=new Jn,this.size=0}function Xn(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Zn(e){return this.__data__.get(e)}function Qn(e){return this.__data__.has(e)}var $n=typeof global==`object`&&global&&global.Object===Object&&global,er=typeof self==`object`&&self&&self.Object===Object&&self,tr=$n||er||Function(`return this`)(),nr=tr.Symbol,rr=Object.prototype,ir=rr.hasOwnProperty,ar=rr.toString,O=nr?nr.toStringTag:void 0;function or(e){var t=ir.call(e,O),n=e[O];try{e[O]=void 0;var r=!0}catch{}var i=ar.call(e);return r&&(t?e[O]=n:delete e[O]),i}var sr=Object.prototype.toString;function cr(e){return sr.call(e)}var lr=`[object Null]`,ur=`[object Undefined]`,dr=nr?nr.toStringTag:void 0;function fr(e){return e==null?e===void 0?ur:lr:dr&&dr in Object(e)?or(e):cr(e)}function pr(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var mr=`[object AsyncFunction]`,hr=`[object Function]`,gr=`[object GeneratorFunction]`,_r=`[object Proxy]`;function vr(e){if(!pr(e))return!1;var t=fr(e);return t==hr||t==gr||t==mr||t==_r}var yr=tr[`__core-js_shared__`],br=function(){var e=/[^.]+$/.exec(yr&&yr.keys&&yr.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function xr(e){return!!br&&br in e}var Sr=Function.prototype.toString;function Cr(e){if(e!=null){try{return Sr.call(e)}catch{}try{return e+``}catch{}}return``}var wr=/[\\^$.*+?()[\]{}|]/g,Tr=/^\[object .+?Constructor\]$/,Er=Function.prototype,Dr=Object.prototype,Or=Er.toString,kr=Dr.hasOwnProperty,Ar=RegExp(`^`+Or.call(kr).replace(wr,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function jr(e){return!pr(e)||xr(e)?!1:(vr(e)?Ar:Tr).test(Cr(e))}function Mr(e,t){return e?.[t]}function Nr(e,t){var n=Mr(e,t);return jr(n)?n:void 0}var Pr=Nr(tr,`Map`),Fr=Nr(Object,`create`);function Ir(){this.__data__=Fr?Fr(null):{},this.size=0}function Lr(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=+!!t,t}var Rr=`__lodash_hash_undefined__`,zr=Object.prototype.hasOwnProperty;function Br(e){var t=this.__data__;if(Fr){var n=t[e];return n===Rr?void 0:n}return zr.call(t,e)?t[e]:void 0}var Vr=Object.prototype.hasOwnProperty;function Hr(e){var t=this.__data__;return Fr?t[e]!==void 0:Vr.call(t,e)}var Ur=`__lodash_hash_undefined__`;function Wr(e,t){var n=this.__data__;return this.size+=+!this.has(e),n[e]=Fr&&t===void 0?Ur:t,this}function Gr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Gr.prototype.clear=Ir,Gr.prototype.delete=Lr,Gr.prototype.get=Br,Gr.prototype.has=Hr,Gr.prototype.set=Wr;function k(){this.size=0,this.__data__={hash:new Gr,map:new(Pr||Jn),string:new Gr}}function Kr(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}function qr(e,t){var n=e.__data__;return Kr(t)?n[typeof t==`string`?`string`:`hash`]:n.map}function Jr(e){var t=qr(this,e).delete(e);return this.size-=+!!t,t}function Yr(e){return qr(this,e).get(e)}function Xr(e){return qr(this,e).has(e)}function A(e,t){var n=qr(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function Zr(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Zr.prototype.clear=k,Zr.prototype.delete=Jr,Zr.prototype.get=Yr,Zr.prototype.has=Xr,Zr.prototype.set=A;var Qr=200;function $r(e,t){var n=this.__data__;if(n instanceof Jn){var r=n.__data__;if(!Pr||r.length<Qr-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Zr(r)}return n.set(e,t),this.size=n.size,this}function ei(e){var t=this.__data__=new Jn(e);this.size=t.size}ei.prototype.clear=Yn,ei.prototype.delete=Xn,ei.prototype.get=Zn,ei.prototype.has=Qn,ei.prototype.set=$r;function ti(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}var ni=function(){try{var e=Nr(Object,`defineProperty`);return e({},``,{}),e}catch{}}();function ri(e,t,n){t==`__proto__`&&ni?ni(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var ii=Object.prototype.hasOwnProperty;function ai(e,t,n){var r=e[t];(!(ii.call(e,t)&&Vn(r,n))||n===void 0&&!(t in e))&&ri(e,t,n)}function oi(e,t,n,r){var i=!n;n||={};for(var a=-1,o=t.length;++a<o;){var s=t[a],c=r?r(n[s],e[s],s,n,e):void 0;c===void 0&&(c=e[s]),i?ri(n,s,c):ai(n,s,c)}return n}function si(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}function ci(e){return typeof e==`object`&&!!e}var li=`[object Arguments]`;function ui(e){return ci(e)&&fr(e)==li}var di=Object.prototype,fi=di.hasOwnProperty,pi=di.propertyIsEnumerable,mi=ui(function(){return arguments}())?ui:function(e){return ci(e)&&fi.call(e,`callee`)&&!pi.call(e,`callee`)},hi=Array.isArray;function gi(){return!1}var _i=typeof exports==`object`&&exports&&!exports.nodeType&&exports,vi=_i&&typeof module==`object`&&module&&!module.nodeType&&module,yi=vi&&vi.exports===_i?tr.Buffer:void 0,bi=(yi?yi.isBuffer:void 0)||gi,xi=9007199254740991,Si=/^(?:0|[1-9]\d*)$/;function Ci(e,t){var n=typeof e;return t??=xi,!!t&&(n==`number`||n!=`symbol`&&Si.test(e))&&e>-1&&e%1==0&&e<t}var wi=9007199254740991;function Ti(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=wi}var Ei=`[object Arguments]`,Di=`[object Array]`,Oi=`[object Boolean]`,ki=`[object Date]`,Ai=`[object Error]`,ji=`[object Function]`,Mi=`[object Map]`,Ni=`[object Number]`,Pi=`[object Object]`,Fi=`[object RegExp]`,Ii=`[object Set]`,Li=`[object String]`,Ri=`[object WeakMap]`,zi=`[object ArrayBuffer]`,Bi=`[object DataView]`,Vi=`[object Float32Array]`,Hi=`[object Float64Array]`,Ui=`[object Int8Array]`,Wi=`[object Int16Array]`,Gi=`[object Int32Array]`,Ki=`[object Uint8Array]`,qi=`[object Uint8ClampedArray]`,Ji=`[object Uint16Array]`,Yi=`[object Uint32Array]`,Xi={};Xi[Vi]=Xi[Hi]=Xi[Ui]=Xi[Wi]=Xi[Gi]=Xi[Ki]=Xi[qi]=Xi[Ji]=Xi[Yi]=!0,Xi[Ei]=Xi[Di]=Xi[zi]=Xi[Oi]=Xi[Bi]=Xi[ki]=Xi[Ai]=Xi[ji]=Xi[Mi]=Xi[Ni]=Xi[Pi]=Xi[Fi]=Xi[Ii]=Xi[Li]=Xi[Ri]=!1;function Zi(e){return ci(e)&&Ti(e.length)&&!!Xi[fr(e)]}function Qi(e){return function(t){return e(t)}}var $i=typeof exports==`object`&&exports&&!exports.nodeType&&exports,ea=$i&&typeof module==`object`&&module&&!module.nodeType&&module,ta=ea&&ea.exports===$i&&$n.process,na=function(){try{return ea&&ea.require&&ea.require(`util`).types||ta&&ta.binding&&ta.binding(`util`)}catch{}}(),ra=na&&na.isTypedArray,ia=ra?Qi(ra):Zi,aa=Object.prototype.hasOwnProperty;function oa(e,t){var n=hi(e),r=!n&&mi(e),i=!n&&!r&&bi(e),a=!n&&!r&&!i&&ia(e),o=n||r||i||a,s=o?si(e.length,String):[],c=s.length;for(var l in e)(t||aa.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||Ci(l,c)))&&s.push(l);return s}var sa=Object.prototype;function ca(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||sa)}function la(e,t){return function(n){return e(t(n))}}var ua=la(Object.keys,Object),da=Object.prototype.hasOwnProperty;function fa(e){if(!ca(e))return ua(e);var t=[];for(var n in Object(e))da.call(e,n)&&n!=`constructor`&&t.push(n);return t}function pa(e){return e!=null&&Ti(e.length)&&!vr(e)}function ma(e){return pa(e)?oa(e):fa(e)}function ha(e,t){return e&&oi(t,ma(t),e)}function ga(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var _a=Object.prototype.hasOwnProperty;function va(e){if(!pr(e))return ga(e);var t=ca(e),n=[];for(var r in e)r==`constructor`&&(t||!_a.call(e,r))||n.push(r);return n}function ya(e){return pa(e)?oa(e,!0):va(e)}function ba(e,t){return e&&oi(t,ya(t),e)}var xa=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Sa=xa&&typeof module==`object`&&module&&!module.nodeType&&module,Ca=Sa&&Sa.exports===xa?tr.Buffer:void 0,wa=Ca?Ca.allocUnsafe:void 0;function Ta(e,t){if(t)return e.slice();var n=e.length,r=wa?wa(n):new e.constructor(n);return e.copy(r),r}function Ea(e,t){var n=-1,r=e.length;for(t||=Array(r);++n<r;)t[n]=e[n];return t}function Da(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}function Oa(){return[]}var ka=Object.prototype.propertyIsEnumerable,Aa=Object.getOwnPropertySymbols,ja=Aa?function(e){return e==null?[]:(e=Object(e),Da(Aa(e),function(t){return ka.call(e,t)}))}:Oa;function Ma(e,t){return oi(e,ja(e),t)}function Na(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Pa=la(Object.getPrototypeOf,Object),Fa=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)Na(t,ja(e)),e=Pa(e);return t}:Oa;function Ia(e,t){return oi(e,Fa(e),t)}function La(e,t,n){var r=t(e);return hi(e)?r:Na(r,n(e))}function Ra(e){return La(e,ma,ja)}function za(e){return La(e,ya,Fa)}var Ba=Nr(tr,`DataView`),Va=Nr(tr,`Promise`),Ha=Nr(tr,`Set`),Ua=Nr(tr,`WeakMap`),Wa=`[object Map]`,Ga=`[object Object]`,Ka=`[object Promise]`,qa=`[object Set]`,Ja=`[object WeakMap]`,Ya=`[object DataView]`,Xa=Cr(Ba),Za=Cr(Pr),Qa=Cr(Va),$a=Cr(Ha),eo=Cr(Ua),to=fr;(Ba&&to(new Ba(new ArrayBuffer(1)))!=Ya||Pr&&to(new Pr)!=Wa||Va&&to(Va.resolve())!=Ka||Ha&&to(new Ha)!=qa||Ua&&to(new Ua)!=Ja)&&(to=function(e){var t=fr(e),n=t==Ga?e.constructor:void 0,r=n?Cr(n):``;if(r)switch(r){case Xa:return Ya;case Za:return Wa;case Qa:return Ka;case $a:return qa;case eo:return Ja}return t});var j=to,no=Object.prototype.hasOwnProperty;function ro(e){var t=e.length,n=new e.constructor(t);return t&&typeof e[0]==`string`&&no.call(e,`index`)&&(n.index=e.index,n.input=e.input),n}var io=tr.Uint8Array;function ao(e){var t=new e.constructor(e.byteLength);return new io(t).set(new io(e)),t}function M(e,t){var n=t?ao(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}var oo=/\w*$/;function so(e){var t=new e.constructor(e.source,oo.exec(e));return t.lastIndex=e.lastIndex,t}var co=nr?nr.prototype:void 0,lo=co?co.valueOf:void 0;function uo(e){return lo?Object(lo.call(e)):{}}function fo(e,t){var n=t?ao(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}var po=`[object Boolean]`,mo=`[object Date]`,ho=`[object Map]`,go=`[object Number]`,_o=`[object RegExp]`,vo=`[object Set]`,yo=`[object String]`,bo=`[object Symbol]`,xo=`[object ArrayBuffer]`,So=`[object DataView]`,Co=`[object Float32Array]`,wo=`[object Float64Array]`,To=`[object Int8Array]`,Eo=`[object Int16Array]`,Do=`[object Int32Array]`,Oo=`[object Uint8Array]`,ko=`[object Uint8ClampedArray]`,Ao=`[object Uint16Array]`,jo=`[object Uint32Array]`;function Mo(e,t,n){var r=e.constructor;switch(t){case xo:return ao(e);case po:case mo:return new r(+e);case So:return M(e,n);case Co:case wo:case To:case Eo:case Do:case Oo:case ko:case Ao:case jo:return fo(e,n);case ho:return new r;case go:case yo:return new r(e);case _o:return so(e);case vo:return new r;case bo:return uo(e)}}var No=Object.create,N=function(){function e(){}return function(t){if(!pr(t))return{};if(No)return No(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();function Po(e){return typeof e.constructor==`function`&&!ca(e)?N(Pa(e)):{}}var Fo=`[object Map]`;function Io(e){return ci(e)&&j(e)==Fo}var Lo=na&&na.isMap,Ro=Lo?Qi(Lo):Io,zo=`[object Set]`;function Bo(e){return ci(e)&&j(e)==zo}var Vo=na&&na.isSet,Ho=Vo?Qi(Vo):Bo,Uo=1,Wo=2,P=4,Go=`[object Arguments]`,Ko=`[object Array]`,F=`[object Boolean]`,qo=`[object Date]`,Jo=`[object Error]`,Yo=`[object Function]`,Xo=`[object GeneratorFunction]`,Zo=`[object Map]`,Qo=`[object Number]`,$o=`[object Object]`,I=`[object RegExp]`,es=`[object Set]`,ts=`[object String]`,ns=`[object Symbol]`,rs=`[object WeakMap]`,is=`[object ArrayBuffer]`,as=`[object DataView]`,os=`[object Float32Array]`,ss=`[object Float64Array]`,cs=`[object Int8Array]`,ls=`[object Int16Array]`,L=`[object Int32Array]`,us=`[object Uint8Array]`,ds=`[object Uint8ClampedArray]`,fs=`[object Uint16Array]`,ps=`[object Uint32Array]`,R={};R[Go]=R[Ko]=R[is]=R[as]=R[F]=R[qo]=R[os]=R[ss]=R[cs]=R[ls]=R[L]=R[Zo]=R[Qo]=R[$o]=R[I]=R[es]=R[ts]=R[ns]=R[us]=R[ds]=R[fs]=R[ps]=!0,R[Jo]=R[Yo]=R[rs]=!1;function ms(e,t,n,r,i,a){var o,s=t&Uo,c=t&Wo,l=t&P;if(n&&(o=i?n(e,r,i,a):n(e)),o!==void 0)return o;if(!pr(e))return e;var u=hi(e);if(u){if(o=ro(e),!s)return Ea(e,o)}else{var d=j(e),f=d==Yo||d==Xo;if(bi(e))return Ta(e,s);if(d==$o||d==Go||f&&!i){if(o=c||f?{}:Po(e),!s)return c?Ia(e,ba(o,e)):Ma(e,ha(o,e))}else{if(!R[d])return i?e:{};o=Mo(e,d,s)}}a||=new ei;var p=a.get(e);if(p)return p;a.set(e,o),Ho(e)?e.forEach(function(r){o.add(ms(r,t,n,r,e,a))}):Ro(e)&&e.forEach(function(r,i){o.set(i,ms(r,t,n,i,e,a))});var m=u?void 0:(l?c?za:Ra:c?ya:ma)(e);return ti(m||e,function(r,i){m&&(i=r,r=e[i]),ai(o,i,ms(r,t,n,i,e,a))}),o}var hs=1,gs=4;function _s(e){return ms(e,hs|gs)}var vs=function(){return tr.Date.now()},ys=/\s/;function bs(e){for(var t=e.length;t--&&ys.test(e.charAt(t)););return t}var xs=/^\s+/;function Ss(e){return e&&e.slice(0,bs(e)+1).replace(xs,``)}var Cs=`[object Symbol]`;function ws(e){return typeof e==`symbol`||ci(e)&&fr(e)==Cs}var Ts=NaN,Es=/^[-+]0x[0-9a-f]+$/i,Ds=/^0b[01]+$/i,Os=/^0o[0-7]+$/i,ks=parseInt;function As(e){if(typeof e==`number`)return e;if(ws(e))return Ts;if(pr(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=pr(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Ss(e);var n=Ds.test(e);return n||Os.test(e)?ks(e.slice(2),n?2:8):Es.test(e)?Ts:+e}var js=`Expected a function`,Ms=Math.max,Ns=Math.min;function z(e,t,n){var r,i,a,o,s,c,l=0,u=!1,d=!1,f=!0;if(typeof e!=`function`)throw TypeError(js);t=As(t)||0,pr(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?Ms(As(n.maxWait)||0,t):a,f=`trailing`in n?!!n.trailing:f);function p(t){var n=r,a=i;return r=i=void 0,l=t,o=e.apply(a,n),o}function m(e){return l=e,s=setTimeout(_,t),u?p(e):o}function h(e){var n=e-c,r=e-l,i=t-n;return d?Ns(i,a-r):i}function g(e){var n=e-c,r=e-l;return c===void 0||n>=t||n<0||d&&r>=a}function _(){var e=vs();if(g(e))return v(e);s=setTimeout(_,h(e))}function v(e){return s=void 0,f&&r?p(e):(r=i=void 0,o)}function ee(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function y(){return s===void 0?o:v(vs())}function te(){var e=vs(),n=g(e);if(r=arguments,i=this,c=e,n){if(s===void 0)return m(c);if(d)return clearTimeout(s),s=setTimeout(_,t),p(c)}return s===void 0&&(s=setTimeout(_,t)),o}return te.cancel=ee,te.flush=y,te}var B=`__lodash_hash_undefined__`;function V(e){return this.__data__.set(e,B),this}function Ps(e){return this.__data__.has(e)}function Fs(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Zr;++t<n;)this.add(e[t])}Fs.prototype.add=Fs.prototype.push=V,Fs.prototype.has=Ps;function Is(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}function Ls(e,t){return e.has(t)}var Rs=1,zs=2;function Bs(e,t,n,r,i,a){var o=n&Rs,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&zs?new Fs:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var g=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(g!==void 0){if(g)continue;f=!1;break}if(p){if(!Is(t,function(e,t){if(!Ls(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}function Vs(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}function Hs(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Us=1,Ws=2,Gs=`[object Boolean]`,Ks=`[object Date]`,H=`[object Error]`,qs=`[object Map]`,Js=`[object Number]`,Ys=`[object RegExp]`,Xs=`[object Set]`,Zs=`[object String]`,Qs=`[object Symbol]`,$s=`[object ArrayBuffer]`,ec=`[object DataView]`,tc=nr?nr.prototype:void 0,nc=tc?tc.valueOf:void 0;function rc(e,t,n,r,i,a,o){switch(n){case ec:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case $s:return!(e.byteLength!=t.byteLength||!a(new io(e),new io(t)));case Gs:case Ks:case Js:return Vn(+e,+t);case H:return e.name==t.name&&e.message==t.message;case Ys:case Zs:return e==t+``;case qs:var s=Vs;case Xs:var c=r&Us;if(s||=Hs,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Ws,o.set(e,t);var u=Bs(s(e),s(t),r,i,a,o);return o.delete(e),u;case Qs:if(nc)return nc.call(e)==nc.call(t)}return!1}var ic=1,ac=Object.prototype.hasOwnProperty;function oc(e,t,n,r,i,a){var o=n&ic,s=Ra(e),c=s.length;if(c!=Ra(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:ac.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],g=t[u];if(r)var _=o?r(g,h,u,t,e,a):r(h,g,u,e,t,a);if(!(_===void 0?h===g||i(h,g,n,r,a):_)){p=!1;break}m||=u==`constructor`}if(p&&!m){var v=e.constructor,ee=t.constructor;v!=ee&&`constructor`in e&&`constructor`in t&&!(typeof v==`function`&&v instanceof v&&typeof ee==`function`&&ee instanceof ee)&&(p=!1)}return a.delete(e),a.delete(t),p}var sc=1,cc=`[object Arguments]`,lc=`[object Array]`,uc=`[object Object]`,dc=Object.prototype.hasOwnProperty;function fc(e,t,n,r,i,a){var o=hi(e),s=hi(t),c=o?lc:j(e),l=s?lc:j(t);c=c==cc?uc:c,l=l==cc?uc:l;var u=c==uc,d=l==uc,f=c==l;if(f&&bi(e)){if(!bi(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new ei,o||ia(e)?Bs(e,t,n,r,i,a):rc(e,t,c,n,r,i,a);if(!(n&sc)){var p=u&&dc.call(e,`__wrapped__`),m=d&&dc.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,g=m?t.value():t;return a||=new ei,i(h,g,n,r,a)}}return f?(a||=new ei,oc(e,t,n,r,i,a)):!1}function pc(e,t,n,r,i){return e===t?!0:e==null||t==null||!ci(e)&&!ci(t)?e!==e&&t!==t:fc(e,t,n,r,pc,i)}function mc(e,t){return pc(e,t)}function hc(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var gc=1/0,_c=nr?nr.prototype:void 0,vc=_c?_c.toString:void 0;function yc(e){if(typeof e==`string`)return e;if(hi(e))return hc(e,yc)+``;if(ws(e))return vc?vc.call(e):``;var t=e+``;return t==`0`&&1/e==-gc?`-0`:t}function bc(e){return e==null?``:yc(e)}var xc=/^\s+/,Sc=tr.parseInt;function Cc(e,t,n){return n||t==null?t=0:t&&=+t,Sc(bc(e).replace(xc,``),t||0)}function wc(e,t,n,r){var i=-1,a=e==null?0:e.length;for(r&&a&&(n=e[++i]);++i<a;)n=t(n,e[i],i,e);return n}function Tc(e){return function(t){return e?.[t]}}var Ec=Tc({À:`A`,Á:`A`,Â:`A`,Ã:`A`,Ä:`A`,Å:`A`,à:`a`,á:`a`,â:`a`,ã:`a`,ä:`a`,å:`a`,Ç:`C`,ç:`c`,Ð:`D`,ð:`d`,È:`E`,É:`E`,Ê:`E`,Ë:`E`,è:`e`,é:`e`,ê:`e`,ë:`e`,Ì:`I`,Í:`I`,Î:`I`,Ï:`I`,ì:`i`,í:`i`,î:`i`,ï:`i`,Ñ:`N`,ñ:`n`,Ò:`O`,Ó:`O`,Ô:`O`,Õ:`O`,Ö:`O`,Ø:`O`,ò:`o`,ó:`o`,ô:`o`,õ:`o`,ö:`o`,ø:`o`,Ù:`U`,Ú:`U`,Û:`U`,Ü:`U`,ù:`u`,ú:`u`,û:`u`,ü:`u`,Ý:`Y`,ý:`y`,ÿ:`y`,Æ:`Ae`,æ:`ae`,Þ:`Th`,þ:`th`,ß:`ss`,Ā:`A`,Ă:`A`,Ą:`A`,ā:`a`,ă:`a`,ą:`a`,Ć:`C`,Ĉ:`C`,Ċ:`C`,Č:`C`,ć:`c`,ĉ:`c`,ċ:`c`,č:`c`,Ď:`D`,Đ:`D`,ď:`d`,đ:`d`,Ē:`E`,Ĕ:`E`,Ė:`E`,Ę:`E`,Ě:`E`,ē:`e`,ĕ:`e`,ė:`e`,ę:`e`,ě:`e`,Ĝ:`G`,Ğ:`G`,Ġ:`G`,Ģ:`G`,ĝ:`g`,ğ:`g`,ġ:`g`,ģ:`g`,Ĥ:`H`,Ħ:`H`,ĥ:`h`,ħ:`h`,Ĩ:`I`,Ī:`I`,Ĭ:`I`,Į:`I`,İ:`I`,ĩ:`i`,ī:`i`,ĭ:`i`,į:`i`,ı:`i`,Ĵ:`J`,ĵ:`j`,Ķ:`K`,ķ:`k`,ĸ:`k`,Ĺ:`L`,Ļ:`L`,Ľ:`L`,Ŀ:`L`,Ł:`L`,ĺ:`l`,ļ:`l`,ľ:`l`,ŀ:`l`,ł:`l`,Ń:`N`,Ņ:`N`,Ň:`N`,Ŋ:`N`,ń:`n`,ņ:`n`,ň:`n`,ŋ:`n`,Ō:`O`,Ŏ:`O`,Ő:`O`,ō:`o`,ŏ:`o`,ő:`o`,Ŕ:`R`,Ŗ:`R`,Ř:`R`,ŕ:`r`,ŗ:`r`,ř:`r`,Ś:`S`,Ŝ:`S`,Ş:`S`,Š:`S`,ś:`s`,ŝ:`s`,ş:`s`,š:`s`,Ţ:`T`,Ť:`T`,Ŧ:`T`,ţ:`t`,ť:`t`,ŧ:`t`,Ũ:`U`,Ū:`U`,Ŭ:`U`,Ů:`U`,Ű:`U`,Ų:`U`,ũ:`u`,ū:`u`,ŭ:`u`,ů:`u`,ű:`u`,ų:`u`,Ŵ:`W`,ŵ:`w`,Ŷ:`Y`,ŷ:`y`,Ÿ:`Y`,Ź:`Z`,Ż:`Z`,Ž:`Z`,ź:`z`,ż:`z`,ž:`z`,IJ:`IJ`,ij:`ij`,Œ:`Oe`,œ:`oe`,ʼn:`'n`,ſ:`s`}),Dc=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Oc=RegExp(`[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]`,`g`);function kc(e){return e=bc(e),e&&e.replace(Dc,Ec).replace(Oc,``)}var Ac=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;function jc(e){return e.match(Ac)||[]}var Mc=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;function Nc(e){return Mc.test(e)}var Pc=`\\ud800-\\udfff`,Fc=`\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff`,Ic=`\\u2700-\\u27bf`,Lc=`a-z\\xdf-\\xf6\\xf8-\\xff`,Rc=`\\xac\\xb1\\xd7\\xf7`,zc=`\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf`,Bc=`\\u2000-\\u206f`,Vc=` \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000`,U=`A-Z\\xc0-\\xd6\\xd8-\\xde`,Hc=`\\ufe0e\\ufe0f`,Uc=Rc+zc+Bc+Vc,Wc=`['’]`,Gc=`[`+Uc+`]`,Kc=`[`+Fc+`]`,qc=`\\d+`,Jc=`[`+Ic+`]`,Yc=`[`+Lc+`]`,Xc=`[^`+Pc+Uc+qc+Ic+Lc+U+`]`,Zc=`(?:`+Kc+`|\\ud83c[\\udffb-\\udfff])`,Qc=`[^`+Pc+`]`,$c=`(?:\\ud83c[\\udde6-\\uddff]){2}`,el=`[\\ud800-\\udbff][\\udc00-\\udfff]`,tl=`[`+U+`]`,nl=`\\u200d`,rl=`(?:`+Yc+`|`+Xc+`)`,il=`(?:`+tl+`|`+Xc+`)`,al=`(?:`+Wc+`(?:d|ll|m|re|s|t|ve))?`,ol=`(?:`+Wc+`(?:D|LL|M|RE|S|T|VE))?`,sl=Zc+`?`,cl=`[`+Hc+`]?`,ll=`(?:`+nl+`(?:`+[Qc,$c,el].join(`|`)+`)`+cl+sl+`)*`,ul=`\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])`,dl=`\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])`,fl=cl+sl+ll,pl=`(?:`+[Jc,$c,el].join(`|`)+`)`+fl,ml=RegExp([tl+`?`+Yc+`+`+al+`(?=`+[Gc,tl,`$`].join(`|`)+`)`,il+`+`+ol+`(?=`+[Gc,tl+rl,`$`].join(`|`)+`)`,tl+`?`+rl+`+`+al,tl+`+`+ol,dl,ul,qc,pl].join(`|`),`g`);function hl(e){return e.match(ml)||[]}function gl(e,t,n){return e=bc(e),t=n?void 0:t,t===void 0?Nc(e)?hl(e):jc(e):e.match(t)||[]}var _l=RegExp(`['’]`,`g`);function vl(e){return function(t){return wc(gl(kc(t).replace(_l,``)),e,``)}}var yl=vl(function(e,t,n){return e+(n?`_`:``)+t.toLowerCase()}),bl=vl(function(e,t,n){return e+(n?` `:``)+t.toUpperCase()}),xl=t(((e,t)=>{(function(r,i){typeof define==`function`&&define.amd?define([`./blockly_compressed.js`],i):typeof e==`object`?t.exports=i(n()):(r.dart=i(r.Blockly),r.Blockly.Dart=r.dart.dartGenerator)})(e,function(e){var t=e.__namespace__,n=function(e,t){var n=0,r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e));do{var i=t.valueToCode(e,`IF`+n,l.NONE)||`false`,a=t.statementToCode(e,`DO`+n);t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=(n>0?`else `:``)+`if (`+i+`) {
1234
+ `+a+`}`,n++}while(e.getInput(`IF`+n));return(e.getInput(`ELSE`)||t.STATEMENT_SUFFIX)&&(a=e.getInput(`ELSE`)?t.statementToCode(e,`ELSE`):``,t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=` else {
1235
+ `+a+`}`),r+`
1236
+ `},r=function(e,n){var r=e.getField(`TIMES`)?String(Number(e.getFieldValue(`TIMES`))):n.valueToCode(e,`TIMES`,l.ASSIGNMENT)||`0`,i=n.statementToCode(e,`DO`);i=n.addLoopTrap(i,e),e=``;var a=n.nameDB_.getDistinctName(`count`,t.P.VARIABLE),o=r;return r.match(/^\w+$/)||t.df(r)||(o=n.nameDB_.getDistinctName(`repeat_end`,t.P.VARIABLE),e+=`var `+o+` = `+r+`;
1237
+ `),e+(`for (int `+a+` = 0; `+a+` < `+o+`; `+a+`++) {
1238
+ `+i+`}
1239
+ `)},i=function(e,t){var n=e.getFieldValue(`OP`);if(n===`NEG`)return e=t.valueToCode(e,`NUM`,l.UNARY_PREFIX)||`0`,e[0]===`-`&&(e=` `+e),[`-`+e,l.UNARY_PREFIX];switch(t.definitions_.import_dart_math=`import 'dart:math' as Math;`,e=n===`ABS`||n.substring(0,5)===`ROUND`?t.valueToCode(e,`NUM`,l.UNARY_POSTFIX)||`0`:n===`SIN`||n===`COS`||n===`TAN`?t.valueToCode(e,`NUM`,l.MULTIPLICATIVE)||`0`:t.valueToCode(e,`NUM`,l.NONE)||`0`,n){case`ABS`:var r=e+`.abs()`;break;case`ROOT`:r=`Math.sqrt(`+e+`)`;break;case`LN`:r=`Math.log(`+e+`)`;break;case`EXP`:r=`Math.exp(`+e+`)`;break;case`POW10`:r=`Math.pow(10,`+e+`)`;break;case`ROUND`:r=e+`.round()`;break;case`ROUNDUP`:r=e+`.ceil()`;break;case`ROUNDDOWN`:r=e+`.floor()`;break;case`SIN`:r=`Math.sin(`+e+` / 180 * Math.pi)`;break;case`COS`:r=`Math.cos(`+e+` / 180 * Math.pi)`;break;case`TAN`:r=`Math.tan(`+e+` / 180 * Math.pi)`}if(r)return[r,l.UNARY_POSTFIX];switch(n){case`LOG10`:r=`Math.log(`+e+`) / Math.log(10)`;break;case`ASIN`:r=`Math.asin(`+e+`) / Math.pi * 180`;break;case`ACOS`:r=`Math.acos(`+e+`) / Math.pi * 180`;break;case`ATAN`:r=`Math.atan(`+e+`) / Math.pi * 180`;break;default:throw Error(`Unknown math operator: `+n)}return[r,l.MULTIPLICATIVE]},a=function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(r+=t.injectId(t.STATEMENT_SUFFIX,e)),r&&=t.prefixLines(r,t.INDENT);var i=``;t.INFINITE_LOOP_TRAP&&(i=t.prefixLines(t.injectId(t.INFINITE_LOOP_TRAP,e),t.INDENT));var a=``;e.getInput(`STACK`)&&(a=t.statementToCode(e,`STACK`));var o=``;e.getInput(`RETURN`)&&(o=t.valueToCode(e,`RETURN`,l.NONE)||``);var s=``;a&&o&&(s=r),o&&=t.INDENT+`return `+o+`;
1240
+ `;var c=o?`dynamic`:`void`,u=[],d=e.getVarModels();for(let e=0;e<d.length;e++)u[e]=t.getVariableName(d[e].getId());return r=c+` `+n+`(`+u.join(`, `)+`) {
1241
+ `+r+i+a+s+o+`}`,r=t.scrub_(e,r),t.definitions_[`%`+n]=r,null},o=function(e,t){t.definitions_.import_dart_html=`import 'dart:html' as Html;`;var n=`Html.window.prompt(`+(e.getField(`TEXT`)?t.quote_(e.getFieldValue(`TEXT`)):t.valueToCode(e,`TEXT`,l.NONE)||`''`)+`, '')`;return e.getFieldValue(`TYPE`)===`NUMBER`&&(t.definitions_.import_dart_math=`import 'dart:math' as Math;`,n=`Math.parseDouble(`+n+`)`),[n,l.UNARY_POSTFIX]},s=function(e,t){return[t.getVariableName(e.getFieldValue(`VAR`)),l.ATOMIC]},c=function(e,t){var n=t.valueToCode(e,`VALUE`,l.ASSIGNMENT)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` = `+n+`;
1242
+ `},l,u=l||={};u[u.ATOMIC=0]=`ATOMIC`,u[u.UNARY_POSTFIX=1]=`UNARY_POSTFIX`,u[u.UNARY_PREFIX=2]=`UNARY_PREFIX`,u[u.MULTIPLICATIVE=3]=`MULTIPLICATIVE`,u[u.ADDITIVE=4]=`ADDITIVE`,u[u.SHIFT=5]=`SHIFT`,u[u.BITWISE_AND=6]=`BITWISE_AND`,u[u.BITWISE_XOR=7]=`BITWISE_XOR`,u[u.BITWISE_OR=8]=`BITWISE_OR`,u[u.RELATIONAL=9]=`RELATIONAL`,u[u.EQUALITY=10]=`EQUALITY`,u[u.LOGICAL_AND=11]=`LOGICAL_AND`,u[u.LOGICAL_OR=12]=`LOGICAL_OR`,u[u.IF_NULL=13]=`IF_NULL`,u[u.CONDITIONAL=14]=`CONDITIONAL`,u[u.CASCADE=15]=`CASCADE`,u[u.ASSIGNMENT=16]=`ASSIGNMENT`,u[u.NONE=99]=`NONE`;var d=class extends t.Ip{constructor(e=`Dart`){super(e),this.isInitialized=!1;for(let t in l)e=l[t],typeof e!=`string`&&(this[`ORDER_`+t]=e);this.addReservedWords(`assert,break,case,catch,class,const,continue,default,do,else,enum,extends,false,final,finally,for,if,in,is,new,null,rethrow,return,super,switch,this,throw,true,try,var,void,while,with,print,identityHashCode,identical,BidirectionalIterator,Comparable,double,Function,int,Invocation,Iterable,Iterator,List,Map,Match,num,Pattern,RegExp,Set,StackTrace,String,StringSink,Type,bool,DateTime,Deprecated,Duration,Expando,Null,Object,RuneIterator,Runes,Stopwatch,StringBuffer,Symbol,Uri,Comparator,AbstractClassInstantiationError,ArgumentError,AssertionError,CastError,ConcurrentModificationError,CyclicInitializationError,Error,Exception,FallThroughError,FormatException,IntegerDivisionByZeroException,NoSuchMethodError,NullThrownError,OutOfMemoryError,RangeError,StackOverflowError,StateError,TypeError,UnimplementedError,UnsupportedError`)}init(e){super.init(e),this.nameDB_?this.nameDB_.reset():this.nameDB_=new t.aj(this.RESERVED_WORDS_),this.nameDB_.setVariableMap(e.getVariableMap()),this.nameDB_.populateVariables(e),this.nameDB_.populateProcedures(e);var n=[],r=t.Bd(e);for(let e=0;e<r.length;e++)n.push(this.nameDB_.getName(r[e],t.P.DEVELOPER_VARIABLE));for(e=t.Ad(e),r=0;r<e.length;r++)n.push(this.nameDB_.getName(e[r].getId(),t.P.VARIABLE));n.length&&(this.definitions_.variables=`var `+n.join(`, `)+`;`),this.isInitialized=!0}finish(e){e&&=this.prefixLines(e,this.INDENT),e=`main() {
1243
+ `+e+`}`;var t=[],n=[];for(let e in this.definitions_){let r=this.definitions_[e];r.match(/^import\s/)?t.push(r):n.push(r)}return e=super.finish(e),this.isInitialized=!1,this.nameDB_.reset(),(t.join(`
1244
+ `)+`
1245
+
1246
+ `+n.join(`
1247
+
1248
+ `)).replace(/\n\n+/g,`
1249
+
1250
+ `).replace(/\n*$/,`
1251
+
1252
+
1253
+ `)+e}scrubNakedValue(e){return e+`;
1254
+ `}quote_(e){return e=e.replace(/\\/g,`\\\\`).replace(/\n/g,`\\
1255
+ `).replace(/\$/g,`\\$`).replace(/'/g,`\\'`),`'`+e+`'`}multiline_quote_(e){return e.split(/\n/g).map(this.quote_).join(` + '\\n' +
1256
+ `)}scrub_(e,n,r=!1){var i=``;if(!e.outputConnection||!e.outputConnection.targetConnection){var a=e.getCommentText();a&&(a=t.cf(a,this.COMMENT_WRAP-3),i=`getProcedureDef`in e?i+this.prefixLines(a+`
1257
+ `,`/// `):i+this.prefixLines(a+`
1258
+ `,`// `));for(let n=0;n<e.inputList.length;n++)e.inputList[n].type===t.he.VALUE&&(a=e.inputList[n].connection.targetBlock())&&(a=this.allNestedComments(a))&&(i+=this.prefixLines(a,`// `))}return e=e.nextConnection&&e.nextConnection.targetBlock(),r=r?``:this.blockToCode(e),i+n+r}getAdjusted(e,n,r=0,i=!1,a=l.NONE){e.workspace.options.oneBasedIndex&&r--;var o=e.workspace.options.oneBasedIndex?`1`:`0`,s=a;return r?s=l.ADDITIVE:i&&(s=l.UNARY_PREFIX),e=this.valueToCode(e,n,s)||o,r===0&&!i?e:t.df(e)?(e=String(Number(e)+r),i&&(e=String(-Number(e))),e):(r>0?e=`${e} + ${r}`:r<0&&(e=`${e} - ${-r}`),i&&(e=r?`-(${e})`:`-${e}`),Math.floor(a)>=Math.floor(s)&&(e=`(${e})`),e)}},f={};f.controls_if=n,f.controls_ifelse=n,f.logic_boolean=function(e){return[e.getFieldValue(`BOOL`)===`TRUE`?`true`:`false`,l.ATOMIC]},f.logic_compare=function(e,t){var n={EQ:`==`,NEQ:`!=`,LT:`<`,LTE:`<=`,GT:`>`,GTE:`>=`}[e.getFieldValue(`OP`)],r=n===`==`||n===`!=`?l.EQUALITY:l.RELATIONAL,i=t.valueToCode(e,`A`,r)||`0`;return e=t.valueToCode(e,`B`,r)||`0`,[i+` `+n+` `+e,r]},f.logic_negate=function(e,t){var n=l.UNARY_PREFIX;return[`!`+(t.valueToCode(e,`BOOL`,n)||`true`),n]},f.logic_null=function(){return[`null`,l.ATOMIC]},f.logic_operation=function(e,t){var n=e.getFieldValue(`OP`)===`AND`?`&&`:`||`,r=n===`&&`?l.LOGICAL_AND:l.LOGICAL_OR,i=t.valueToCode(e,`A`,r);return e=t.valueToCode(e,`B`,r),i||e?(t=n===`&&`?`true`:`false`,i||=t,e||=t):e=i=`false`,[i+` `+n+` `+e,r]},f.logic_ternary=function(e,t){var n=t.valueToCode(e,`IF`,l.CONDITIONAL)||`false`,r=t.valueToCode(e,`THEN`,l.CONDITIONAL)||`null`;return e=t.valueToCode(e,`ELSE`,l.CONDITIONAL)||`null`,[n+` ? `+r+` : `+e,l.CONDITIONAL]};var p={controls_flow_statements:function(e,t){var n=``;if(t.STATEMENT_PREFIX&&(n+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(n+=t.injectId(t.STATEMENT_SUFFIX,e)),t.STATEMENT_PREFIX){let r=e.getSurroundLoop();r&&!r.suppressPrefixSuffix&&(n+=t.injectId(t.STATEMENT_PREFIX,r))}switch(e.getFieldValue(`FLOW`)){case`BREAK`:return n+`break;
1259
+ `;case`CONTINUE`:return n+`continue;
1260
+ `}throw Error(`Unknown flow statement.`)},controls_for:function(e,n){var r=n.getVariableName(e.getFieldValue(`VAR`)),i=n.valueToCode(e,`FROM`,l.ASSIGNMENT)||`0`,a=n.valueToCode(e,`TO`,l.ASSIGNMENT)||`0`,o=n.valueToCode(e,`BY`,l.ASSIGNMENT)||`1`,s=n.statementToCode(e,`DO`);if(s=n.addLoopTrap(s,e),t.df(i)&&t.df(a)&&t.df(o))n=Number(i)<=Number(a),e=`for (`+r+` = `+i+`; `+r+(n?` <= `:` >= `)+a+`; `+r,r=Math.abs(Number(o)),e=r===1?e+(n?`++`:`--`):e+((n?` += `:` -= `)+r),e+=`) {
1261
+ `+s+`}
1262
+ `;else{e=``;let c=i;i.match(/^\w+$/)||t.df(i)||(c=n.nameDB_.getDistinctName(r+`_start`,t.P.VARIABLE),e+=`var `+c+` = `+i+`;
1263
+ `),i=a,a.match(/^\w+$/)||t.df(a)||(i=n.nameDB_.getDistinctName(r+`_end`,t.P.VARIABLE),e+=`var `+i+` = `+a+`;
1264
+ `),a=n.nameDB_.getDistinctName(r+`_inc`,t.P.VARIABLE),e+=`num `+a+` = `,e=t.df(o)?e+(Math.abs(Number(o))+`;
1265
+ `):e+(`(`+o+`).abs();
1266
+ `),e+=`if (`+c+` > `+i+`) {
1267
+ `,e+=n.INDENT+a+` = -`+a+`;
1268
+ `,e=e+`}
1269
+ for (`+(r+` = `+c+`; `+a+` >= 0 ? `+r+` <= `+i+` : `+r+` >= `+i+`; `+r+` += `+a+`) {
1270
+ `+s+`}
1271
+ `)}return e},controls_forEach:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`)),r=t.valueToCode(e,`LIST`,l.ASSIGNMENT)||`[]`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e),`for (var `+n+` in `+r+`) {
1272
+ `+i+`}
1273
+ `}};p.controls_repeat=r,p.controls_repeat_ext=r,p.controls_whileUntil=function(e,t){var n=e.getFieldValue(`MODE`)===`UNTIL`,r=t.valueToCode(e,`BOOL`,n?l.UNARY_PREFIX:l.NONE)||`false`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e),n&&(r=`!`+r),`while (`+r+`) {
1274
+ `+i+`}
1275
+ `};var m={math_arithmetic:function(e,t){var n={ADD:[` + `,l.ADDITIVE],MINUS:[` - `,l.ADDITIVE],MULTIPLY:[` * `,l.MULTIPLICATIVE],DIVIDE:[` / `,l.MULTIPLICATIVE],POWER:[null,l.NONE]}[e.getFieldValue(`OP`)],r=n[0];n=n[1];var i=t.valueToCode(e,`A`,n)||`0`;return e=t.valueToCode(e,`B`,n)||`0`,r?[i+r+e,n]:(t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[`Math.pow(`+i+`, `+e+`)`,l.UNARY_POSTFIX])},math_atan2:function(e,t){t.definitions_.import_dart_math=`import 'dart:math' as Math;`;var n=t.valueToCode(e,`X`,l.NONE)||`0`;return[`Math.atan2(`+(t.valueToCode(e,`Y`,l.NONE)||`0`)+`, `+n+`) / Math.pi * 180`,l.MULTIPLICATIVE]},math_change:function(e,t){var n=t.valueToCode(e,`DELTA`,l.ADDITIVE)||`0`;return e=t.getVariableName(e.getFieldValue(`VAR`)),e+` = (`+e+` is num ? `+e+` : 0) + `+n+`;
1276
+ `},math_constant:function(e,t){var n={PI:[`Math.pi`,l.UNARY_POSTFIX],E:[`Math.e`,l.UNARY_POSTFIX],GOLDEN_RATIO:[`(1 + Math.sqrt(5)) / 2`,l.MULTIPLICATIVE],SQRT2:[`Math.sqrt2`,l.UNARY_POSTFIX],SQRT1_2:[`Math.sqrt1_2`,l.UNARY_POSTFIX],INFINITY:[`double.infinity`,l.ATOMIC]};return e=e.getFieldValue(`CONSTANT`),e!==`INFINITY`&&(t.definitions_.import_dart_math=`import 'dart:math' as Math;`),n[e]},math_constrain:function(e,t){t.definitions_.import_dart_math=`import 'dart:math' as Math;`;var n=t.valueToCode(e,`VALUE`,l.NONE)||`0`,r=t.valueToCode(e,`LOW`,l.NONE)||`0`;return e=t.valueToCode(e,`HIGH`,l.NONE)||`double.infinity`,[`Math.min(Math.max(`+n+`, `+r+`), `+e+`)`,l.UNARY_POSTFIX]},math_modulo:function(e,t){var n=t.valueToCode(e,`DIVIDEND`,l.MULTIPLICATIVE)||`0`;return e=t.valueToCode(e,`DIVISOR`,l.MULTIPLICATIVE)||`0`,[n+` % `+e,l.MULTIPLICATIVE]},math_number:function(e){return e=Number(e.getFieldValue(`NUM`)),e===1/0?[`double.infinity`,l.UNARY_POSTFIX]:e===-1/0?[`-double.infinity`,l.UNARY_PREFIX]:[String(e),e<0?l.UNARY_PREFIX:l.ATOMIC]},math_number_property:function(e,t){var n={EVEN:[` % 2 == 0`,l.MULTIPLICATIVE,l.EQUALITY],ODD:[` % 2 == 1`,l.MULTIPLICATIVE,l.EQUALITY],WHOLE:[` % 1 == 0`,l.MULTIPLICATIVE,l.EQUALITY],POSITIVE:[` > 0`,l.RELATIONAL,l.RELATIONAL],NEGATIVE:[` < 0`,l.RELATIONAL,l.RELATIONAL],DIVISIBLE_BY:[null,l.MULTIPLICATIVE,l.EQUALITY],PRIME:[null,l.NONE,l.UNARY_POSTFIX]},r=e.getFieldValue(`PROPERTY`),[i,a,o]=n[r];if(n=t.valueToCode(e,`NUMBER_TO_CHECK`,a)||`0`,r===`PRIME`)t.definitions_.import_dart_math=`import 'dart:math' as Math;`,e=t.provideFunction_(`math_isPrime`,`
1277
+ bool ${t.FUNCTION_NAME_PLACEHOLDER_}(n) {
1278
+ // https://en.wikipedia.org/wiki/Primality_test#Naive_methods
1279
+ if (n == 2 || n == 3) {
1280
+ return true;
1281
+ }
1282
+ // False if n is null, negative, is 1, or not whole.
1283
+ // And false if n is divisible by 2 or 3.
1284
+ if (n == null || n <= 1 || n % 1 != 0 || n % 2 == 0 || n % 3 == 0) {
1285
+ return false;
1286
+ }
1287
+ // Check all the numbers of form 6k +/- 1, up to sqrt(n).
1288
+ for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {
1289
+ if (n % (x - 1) == 0 || n % (x + 1) == 0) {
1290
+ return false;
1291
+ }
1292
+ }
1293
+ return true;
1294
+ }
1295
+ `)+`(`+n+`)`;else if(r===`DIVISIBLE_BY`){if(e=t.valueToCode(e,`DIVISOR`,l.MULTIPLICATIVE)||`0`,e===`0`)return[`false`,l.ATOMIC];e=n+` % `+e+` == 0`}else e=n+i;return[e,o]},math_on_list:function(e,t){var n=e.getFieldValue(`OP`);switch(e=t.valueToCode(e,`LIST`,l.NONE)||`[]`,n){case`SUM`:t=t.provideFunction_(`math_sum`,`
1296
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List<num> myList) {
1297
+ num sumVal = 0;
1298
+ myList.forEach((num entry) {sumVal += entry;});
1299
+ return sumVal;
1300
+ }
1301
+ `)+`(`+e+`)`;break;case`MIN`:t.definitions_.import_dart_math=`import 'dart:math' as Math;`,t=t.provideFunction_(`math_min`,`
1302
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List<num> myList) {
1303
+ if (myList.isEmpty) return null;
1304
+ num minVal = myList[0];
1305
+ myList.forEach((num entry) {minVal = Math.min(minVal, entry);});
1306
+ return minVal;
1307
+ }
1308
+ `)+`(`+e+`)`;break;case`MAX`:t.definitions_.import_dart_math=`import 'dart:math' as Math;`,t=t.provideFunction_(`math_max`,`
1309
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List<num> myList) {
1310
+ if (myList.isEmpty) return null;
1311
+ num maxVal = myList[0];
1312
+ myList.forEach((num entry) {maxVal = Math.max(maxVal, entry);});
1313
+ return maxVal;
1314
+ }
1315
+ `)+`(`+e+`)`;break;case`AVERAGE`:t=t.provideFunction_(`math_mean`,`
1316
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List myList) {
1317
+ // First filter list for numbers only.
1318
+ List localList = new List.from(myList);
1319
+ localList.removeWhere((a) => a is! num);
1320
+ if (localList.isEmpty) return null;
1321
+ num sumVal = 0;
1322
+ localList.forEach((var entry) {sumVal += entry;});
1323
+ return sumVal / localList.length;
1324
+ }
1325
+ `)+`(`+e+`)`;break;case`MEDIAN`:t=t.provideFunction_(`math_median`,`
1326
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List myList) {
1327
+ // First filter list for numbers only, then sort, then return middle value
1328
+ // or the average of two middle values if list has an even number of elements.
1329
+ List localList = new List.from(myList);
1330
+ localList.removeWhere((a) => a is! num);
1331
+ if (localList.isEmpty) return null;
1332
+ localList.sort((a, b) => (a - b));
1333
+ int index = localList.length ~/ 2;
1334
+ if (localList.length % 2 == 1) {
1335
+ return localList[index];
1336
+ } else {
1337
+ return (localList[index - 1] + localList[index]) / 2;
1338
+ }
1339
+ }
1340
+ `)+`(`+e+`)`;break;case`MODE`:t.definitions_.import_dart_math=`import 'dart:math' as Math;`,t=t.provideFunction_(`math_modes`,`
1341
+ List ${t.FUNCTION_NAME_PLACEHOLDER_}(List values) {
1342
+ List modes = [];
1343
+ List counts = [];
1344
+ int maxCount = 0;
1345
+ for (int i = 0; i < values.length; i++) {
1346
+ var value = values[i];
1347
+ bool found = false;
1348
+ int thisCount;
1349
+ for (int j = 0; j < counts.length; j++) {
1350
+ if (counts[j][0] == value) {
1351
+ thisCount = ++counts[j][1];
1352
+ found = true;
1353
+ break;
1354
+ }
1355
+ }
1356
+ if (!found) {
1357
+ counts.add([value, 1]);
1358
+ thisCount = 1;
1359
+ }
1360
+ maxCount = Math.max(thisCount, maxCount);
1361
+ }
1362
+ for (int j = 0; j < counts.length; j++) {
1363
+ if (counts[j][1] == maxCount) {
1364
+ modes.add(counts[j][0]);
1365
+ }
1366
+ }
1367
+ return modes;
1368
+ }
1369
+ `)+`(`+e+`)`;break;case`STD_DEV`:t.definitions_.import_dart_math=`import 'dart:math' as Math;`,t=t.provideFunction_(`math_standard_deviation`,`
1370
+ num ${t.FUNCTION_NAME_PLACEHOLDER_}(List myList) {
1371
+ // First filter list for numbers only.
1372
+ List numbers = new List.from(myList);
1373
+ numbers.removeWhere((a) => a is! num);
1374
+ if (numbers.isEmpty) return null;
1375
+ num n = numbers.length;
1376
+ num sum = 0;
1377
+ numbers.forEach((x) => sum += x);
1378
+ num mean = sum / n;
1379
+ num sumSquare = 0;
1380
+ numbers.forEach((x) => sumSquare += Math.pow(x - mean, 2));
1381
+ return Math.sqrt(sumSquare / n);
1382
+ }
1383
+ `)+`(`+e+`)`;break;case`RANDOM`:t.definitions_.import_dart_math=`import 'dart:math' as Math;`,t=t.provideFunction_(`math_random_item`,`
1384
+ dynamic ${t.FUNCTION_NAME_PLACEHOLDER_}(List myList) {
1385
+ int x = new Math.Random().nextInt(myList.length);
1386
+ return myList[x];
1387
+ }
1388
+ `)+`(`+e+`)`;break;default:throw Error(`Unknown operator: `+n)}return[t,l.UNARY_POSTFIX]},math_random_float:function(e,t){return t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[`new Math.Random().nextDouble()`,l.UNARY_POSTFIX]},math_random_int:function(e,t){t.definitions_.import_dart_math=`import 'dart:math' as Math;`;var n=t.valueToCode(e,`FROM`,l.NONE)||`0`;return e=t.valueToCode(e,`TO`,l.NONE)||`0`,[t.provideFunction_(`math_random_int`,`
1389
+ int ${t.FUNCTION_NAME_PLACEHOLDER_}(num a, num b) {
1390
+ if (a > b) {
1391
+ // Swap a and b to ensure a is smaller.
1392
+ num c = a;
1393
+ a = b;
1394
+ b = c;
1395
+ }
1396
+ return new Math.Random().nextInt(b - a + 1) + a;
1397
+ }
1398
+ `)+`(`+n+`, `+e+`)`,l.UNARY_POSTFIX]}};m.math_round=i,m.math_single=i,m.math_trig=i;var h={procedures_callnoreturn:function(e,t){return t.forBlock.procedures_callreturn(e,t)[0]+`;
1399
+ `},procedures_callreturn:function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=[],i=e.getVarModels();for(let n=0;n<i.length;n++)r[n]=t.valueToCode(e,`ARG`+n,l.NONE)||`null`;return[n+`(`+r.join(`, `)+`)`,l.UNARY_POSTFIX]}};h.procedures_defnoreturn=a,h.procedures_defreturn=a,h.procedures_ifreturn=function(e,t){var n=`if (`+(t.valueToCode(e,`CONDITION`,l.NONE)||`false`)+`) {
1400
+ `;return t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_?(e=t.valueToCode(e,`VALUE`,l.NONE)||`null`,n+=t.INDENT+`return `+e+`;
1401
+ `):n+=t.INDENT+`return;
1402
+ `,n+`}
1403
+ `};var g={text:function(e,t){return[t.quote_(e.getFieldValue(`TEXT`)),l.ATOMIC]},text_append:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`));return e=t.valueToCode(e,`TEXT`,l.NONE)||`''`,n+` = [`+n+`, `+e+`].join();
1404
+ `},text_changeCase:function(e,t){var n={UPPERCASE:`.toUpperCase()`,LOWERCASE:`.toLowerCase()`,TITLECASE:null}[e.getFieldValue(`CASE`)];return e=t.valueToCode(e,`TEXT`,n?l.UNARY_POSTFIX:l.NONE)||`''`,[n?e+n:t.provideFunction_(`text_toTitleCase`,`
1405
+ String ${t.FUNCTION_NAME_PLACEHOLDER_}(String str) {
1406
+ RegExp exp = new RegExp(r'\\b');
1407
+ List<String> list = str.split(exp);
1408
+ final title = new StringBuffer();
1409
+ for (String part in list) {
1410
+ if (part.length > 0) {
1411
+ title.write(part[0].toUpperCase());
1412
+ if (part.length > 0) {
1413
+ title.write(part.substring(1).toLowerCase());
1414
+ }
1415
+ }
1416
+ }
1417
+ return title.toString();
1418
+ }
1419
+ `)+`(`+e+`)`,l.UNARY_POSTFIX]},text_charAt:function(e,t){var n=e.getFieldValue(`WHERE`)||`FROM_START`,r=t.valueToCode(e,`VALUE`,n===`FIRST`||n===`FROM_START`?l.UNARY_POSTFIX:l.NONE)||`''`;switch(n){case`FIRST`:return[r+`[0]`,l.UNARY_POSTFIX];case`FROM_START`:return e=t.getAdjusted(e,`AT`),[r+`[`+e+`]`,l.UNARY_POSTFIX];case`LAST`:case`FROM_END`:return e=n===`LAST`?1:t.getAdjusted(e,`AT`,1),[`${t.provideFunction_(`text_get_from_end`,`
1420
+ String ${t.FUNCTION_NAME_PLACEHOLDER_}(String text, num x) {
1421
+ return text[text.length - x];
1422
+ }
1423
+ `)}(${r}, ${e})`,l.UNARY_POSTFIX];case`RANDOM`:return t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[t.provideFunction_(`text_random_letter`,`
1424
+ String ${t.FUNCTION_NAME_PLACEHOLDER_}(String text) {
1425
+ int x = new Math.Random().nextInt(text.length);
1426
+ return text[x];
1427
+ }
1428
+ `)+`(`+r+`)`,l.UNARY_POSTFIX]}throw Error(`Unhandled option (text_charAt).`)},text_count:function(e,t){var n=t.valueToCode(e,`TEXT`,l.NONE)||`''`;return e=t.valueToCode(e,`SUB`,l.NONE)||`''`,[t.provideFunction_(`text_count`,`
1429
+ int ${t.FUNCTION_NAME_PLACEHOLDER_}(String haystack, String needle) {
1430
+ if (needle.length == 0) {
1431
+ return haystack.length + 1;
1432
+ }
1433
+ int index = 0;
1434
+ int count = 0;
1435
+ while (index != -1) {
1436
+ index = haystack.indexOf(needle, index);
1437
+ if (index != -1) {
1438
+ count++;
1439
+ index += needle.length;
1440
+ }
1441
+ }
1442
+ return count;
1443
+ }
1444
+ `)+`(`+n+`, `+e+`)`,l.UNARY_POSTFIX]},text_getSubstring:function(e,t){var n=e.getFieldValue(`WHERE1`),r=e.getFieldValue(`WHERE2`),i=n!==`FROM_END`&&r===`FROM_START`,a=t.valueToCode(e,`STRING`,i?l.UNARY_POSTFIX:l.NONE)||`''`;if(n===`FIRST`&&r===`LAST`)return[a,l.NONE];if(a.match(/^'?\w+'?$/)||i){switch(n){case`FROM_START`:n=t.getAdjusted(e,`AT1`);break;case`FROM_END`:n=t.getAdjusted(e,`AT1`,1,!1,l.ADDITIVE),n=a+`.length - `+n;break;case`FIRST`:n=`0`;break;default:throw Error(`Unhandled option (text_getSubstring).`)}switch(r){case`FROM_START`:var o=t.getAdjusted(e,`AT2`,1);break;case`FROM_END`:o=t.getAdjusted(e,`AT2`,0,!1,l.ADDITIVE),o=a+`.length - `+o;break;case`LAST`:break;default:throw Error(`Unhandled option (text_getSubstring).`)}t=r===`LAST`?a+`.substring(`+n+`)`:a+`.substring(`+n+`, `+o+`)`}else o=t.getAdjusted(e,`AT1`),e=t.getAdjusted(e,`AT2`),t=t.provideFunction_(`text_get_substring`,`
1445
+ String ${t.FUNCTION_NAME_PLACEHOLDER_}(String text, String where1, num at1, String where2, num at2) {
1446
+ int getAt(String where, num at) {
1447
+ if (where == 'FROM_END') {
1448
+ at = text.length - 1 - at;
1449
+ } else if (where == 'FIRST') {
1450
+ at = 0;
1451
+ } else if (where == 'LAST') {
1452
+ at = text.length - 1;
1453
+ } else if (where != 'FROM_START') {
1454
+ throw 'Unhandled option (text_getSubstring).';
1455
+ }
1456
+ return at;
1457
+ }
1458
+ at1 = getAt(where1, at1);
1459
+ at2 = getAt(where2, at2) + 1;
1460
+ return text.substring(at1, at2);
1461
+ }
1462
+ `)+`(`+a+`, '`+n+`', `+o+`, '`+r+`', `+e+`)`;return[t,l.UNARY_POSTFIX]},text_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`indexOf`:`lastIndexOf`,r=t.valueToCode(e,`FIND`,l.NONE)||`''`;return t=(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`''`)+`.`+n+`(`+r+`)`,e.workspace.options.oneBasedIndex?[t+` + 1`,l.ADDITIVE]:[t,l.UNARY_POSTFIX]},text_isEmpty:function(e,t){return[(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`''`)+`.isEmpty`,l.UNARY_POSTFIX]},text_join:function(e,t){switch(e.itemCount_){case 0:return[`''`,l.ATOMIC];case 1:return[(t.valueToCode(e,`ADD0`,l.UNARY_POSTFIX)||`''`)+`.toString()`,l.UNARY_POSTFIX];default:let n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,l.NONE)||`''`;return[`[`+n.join(`,`)+`].join()`,l.UNARY_POSTFIX]}},text_length:function(e,t){return[(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`''`)+`.length`,l.UNARY_POSTFIX]},text_print:function(e,t){return`print(`+(t.valueToCode(e,`TEXT`,l.NONE)||`''`)+`);
1463
+ `}};g.text_prompt=o,g.text_prompt_ext=o,g.text_replace=function(e,t){var n=t.valueToCode(e,`TEXT`,l.UNARY_POSTFIX)||`''`,r=t.valueToCode(e,`FROM`,l.NONE)||`''`;return e=t.valueToCode(e,`TO`,l.NONE)||`''`,[n+`.replaceAll(`+r+`, `+e+`)`,l.UNARY_POSTFIX]},g.text_reverse=function(e,t){return[`new String.fromCharCodes(`+(t.valueToCode(e,`TEXT`,l.UNARY_POSTFIX)||`''`)+`.runes.toList().reversed)`,l.UNARY_PREFIX]},g.text_trim=function(e,t){var n={LEFT:`.replaceFirst(new RegExp(r'^\\s+'), '')`,RIGHT:`.replaceFirst(new RegExp(r'\\s+$'), '')`,BOTH:`.trim()`}[e.getFieldValue(`MODE`)];return[(t.valueToCode(e,`TEXT`,l.UNARY_POSTFIX)||`''`)+n,l.UNARY_POSTFIX]};var _={};_.variables_get=s,_.variables_set=c;var v={};v.variables_get_dynamic=s,v.variables_set_dynamic=c;var ee=new d;ee.addReservedWords(`Html,Math`);var y=Object.assign({},{lists_create_empty:function(){return[`[]`,l.ATOMIC]},lists_create_with:function(e,t){var n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,l.NONE)||`null`;return[`[`+n.join(`, `)+`]`,l.ATOMIC]},lists_getIndex:function(e,n){function r(){var e=n.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE),r=`List `+e+` = `+o+`;
1464
+ `;return o=e,r}var i=e.getFieldValue(`MODE`)||`GET`,a=e.getFieldValue(`WHERE`)||`FROM_START`,o=n.valueToCode(e,`VALUE`,a===`RANDOM`||a===`FROM_END`?l.NONE:l.UNARY_POSTFIX)||`[]`;if((a!==`RANDOM`||i!==`REMOVE`)&&a!==`FROM_END`||o.match(/^\w+$/))switch(a){case`FIRST`:if(i===`GET`)return[o+`.first`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`)return[o+`.removeAt(0)`,l.UNARY_POSTFIX];if(i===`REMOVE`)return o+`.removeAt(0);
1465
+ `;break;case`LAST`:if(i===`GET`)return[o+`.last`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`)return[o+`.removeLast()`,l.UNARY_POSTFIX];if(i===`REMOVE`)return o+`.removeLast();
1466
+ `;break;case`FROM_START`:if(e=n.getAdjusted(e,`AT`),i===`GET`)return[o+`[`+e+`]`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`)return[o+`.removeAt(`+e+`)`,l.UNARY_POSTFIX];if(i===`REMOVE`)return o+`.removeAt(`+e+`);
1467
+ `;break;case`FROM_END`:if(e=n.getAdjusted(e,`AT`,1,!1,l.ADDITIVE),i===`GET`)return[o+`[`+o+`.length - `+e+`]`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`||i===`REMOVE`){if(e=o+`.removeAt(`+o+`.length - `+e+`)`,i===`GET_REMOVE`)return[e,l.UNARY_POSTFIX];if(i===`REMOVE`)return e+`;
1468
+ `}break;case`RANDOM`:if(n.definitions_.import_dart_math=`import 'dart:math' as Math;`,i===`REMOVE`)return i=n.nameDB_.getDistinctName(`tmp_x`,t.P.VARIABLE),`int `+i+` = new Math.Random().nextInt(`+o+`.length);
1469
+ `+(o+`.removeAt(`+i+`);
1470
+ `);if(i===`GET`)return[n.provideFunction_(`lists_get_random_item`,`
1471
+ dynamic ${n.FUNCTION_NAME_PLACEHOLDER_}(List my_list) {
1472
+ int x = new Math.Random().nextInt(my_list.length);
1473
+ return my_list[x];
1474
+ }
1475
+ `)+`(`+o+`)`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`)return[n.provideFunction_(`lists_remove_random_item`,`
1476
+ dynamic ${n.FUNCTION_NAME_PLACEHOLDER_}(List my_list) {
1477
+ int x = new Math.Random().nextInt(my_list.length);
1478
+ return my_list.removeAt(x);
1479
+ }
1480
+ `)+`(`+o+`)`,l.UNARY_POSTFIX]}else{if(a===`RANDOM`)return n.definitions_.import_dart_math=`import 'dart:math' as Math;`,i=r(),e=n.nameDB_.getDistinctName(`tmp_x`,t.P.VARIABLE),i+(`int `+e+` = new Math.Random().nextInt(`+o+`.length);
1481
+ `)+(o+`.removeAt(`+e+`);
1482
+ `);if(i===`REMOVE`)return i=n.getAdjusted(e,`AT`,1,!1,l.ADDITIVE),r()+(o+`.removeAt(`+o+`.length - `+i+`);
1483
+ `);if(i===`GET`)return i=n.getAdjusted(e,`AT`,1),[n.provideFunction_(`lists_get_from_end`,`
1484
+ dynamic ${n.FUNCTION_NAME_PLACEHOLDER_}(List my_list, num x) {
1485
+ x = my_list.length - x;
1486
+ return my_list[x];
1487
+ }
1488
+ `)+`(`+o+`, `+i+`)`,l.UNARY_POSTFIX];if(i===`GET_REMOVE`)return i=n.getAdjusted(e,`AT`,1),[n.provideFunction_(`lists_remove_from_end`,`
1489
+ dynamic ${n.FUNCTION_NAME_PLACEHOLDER_}(List my_list, num x) {
1490
+ x = my_list.length - x;
1491
+ return my_list.removeAt(x);
1492
+ }
1493
+ `)+`(`+o+`, `+i+`)`,l.UNARY_POSTFIX]}throw Error(`Unhandled combination (lists_getIndex).`)},lists_getSublist:function(e,t){var n=t.valueToCode(e,`LIST`,l.UNARY_POSTFIX)||`[]`,r=e.getFieldValue(`WHERE1`),i=e.getFieldValue(`WHERE2`);if(n.match(/^\w+$/)||r!==`FROM_END`&&i===`FROM_START`){switch(r){case`FROM_START`:r=t.getAdjusted(e,`AT1`);break;case`FROM_END`:r=t.getAdjusted(e,`AT1`,1,!1,l.ADDITIVE),r=n+`.length - `+r;break;case`FIRST`:r=`0`;break;default:throw Error(`Unhandled option (lists_getSublist).`)}switch(i){case`FROM_START`:var a=t.getAdjusted(e,`AT2`,1);break;case`FROM_END`:a=t.getAdjusted(e,`AT2`,0,!1,l.ADDITIVE),a=n+`.length - `+a;break;case`LAST`:break;default:throw Error(`Unhandled option (lists_getSublist).`)}t=i===`LAST`?n+`.sublist(`+r+`)`:n+`.sublist(`+r+`, `+a+`)`}else a=t.getAdjusted(e,`AT1`),e=t.getAdjusted(e,`AT2`),t=t.provideFunction_(`lists_get_sublist`,`
1494
+ List ${t.FUNCTION_NAME_PLACEHOLDER_}(List list, String where1, num at1, String where2, num at2) {
1495
+ int getAt(String where, num at) {
1496
+ if (where == 'FROM_END') {
1497
+ at = list.length - 1 - at;
1498
+ } else if (where == 'FIRST') {
1499
+ at = 0;
1500
+ } else if (where == 'LAST') {
1501
+ at = list.length - 1;
1502
+ } else if (where != 'FROM_START') {
1503
+ throw 'Unhandled option (lists_getSublist).';
1504
+ }
1505
+ return at;
1506
+ }
1507
+ at1 = getAt(where1, at1);
1508
+ at2 = getAt(where2, at2) + 1;
1509
+ return list.sublist(at1, at2);
1510
+ }
1511
+ `)+`(`+n+`, '`+r+`', `+a+`, '`+i+`', `+e+`)`;return[t,l.UNARY_POSTFIX]},lists_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`indexOf`:`lastIndexOf`,r=t.valueToCode(e,`FIND`,l.NONE)||`''`;return t=(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`[]`)+`.`+n+`(`+r+`)`,e.workspace.options.oneBasedIndex?[t+` + 1`,l.ADDITIVE]:[t,l.UNARY_POSTFIX]},lists_isEmpty:function(e,t){return[(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`[]`)+`.isEmpty`,l.UNARY_POSTFIX]},lists_length:function(e,t){return[(t.valueToCode(e,`VALUE`,l.UNARY_POSTFIX)||`[]`)+`.length`,l.UNARY_POSTFIX]},lists_repeat:function(e,t){var n=t.valueToCode(e,`ITEM`,l.NONE)||`null`;return[`new List.filled(`+(t.valueToCode(e,`NUM`,l.NONE)||`0`)+`, `+n+`)`,l.UNARY_POSTFIX]},lists_reverse:function(e,t){return[`new List.from(`+(t.valueToCode(e,`LIST`,l.NONE)||`[]`)+`.reversed)`,l.UNARY_POSTFIX]},lists_setIndex:function(e,n){function r(){if(o.match(/^\w+$/))return``;var e=n.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE),r=`List `+e+` = `+o+`;
1512
+ `;return o=e,r}var i=e.getFieldValue(`MODE`)||`GET`,a=e.getFieldValue(`WHERE`)||`FROM_START`,o=n.valueToCode(e,`LIST`,l.UNARY_POSTFIX)||`[]`,s=n.valueToCode(e,`TO`,l.ASSIGNMENT)||`null`;switch(a){case`FIRST`:if(i===`SET`)return o+`[0] = `+s+`;
1513
+ `;if(i===`INSERT`)return o+`.insert(0, `+s+`);
1514
+ `;break;case`LAST`:if(i===`SET`)return r()+(o+`[`+o+`.length - 1] = `+s+`;
1515
+ `);if(i===`INSERT`)return o+`.add(`+s+`);
1516
+ `;break;case`FROM_START`:if(e=n.getAdjusted(e,`AT`),i===`SET`)return o+`[`+e+`] = `+s+`;
1517
+ `;if(i===`INSERT`)return o+`.insert(`+e+`, `+s+`);
1518
+ `;break;case`FROM_END`:if(e=n.getAdjusted(e,`AT`,1,!1,l.ADDITIVE),a=r(),i===`SET`)return a+(o+`[`+o+`.length - `+e+`] = `+s+`;
1519
+ `);if(i===`INSERT`)return a+(o+`.insert(`+o+`.length - `+e+`, `+s+`);
1520
+ `);break;case`RANDOM`:if(n.definitions_.import_dart_math=`import 'dart:math' as Math;`,e=r(),a=n.nameDB_.getDistinctName(`tmp_x`,t.P.VARIABLE),e+=`int `+a+` = new Math.Random().nextInt(`+o+`.length);
1521
+ `,i===`SET`)return e+(o+`[`+a+`] = `+s+`;
1522
+ `);if(i===`INSERT`)return e+(o+`.insert(`+a+`, `+s+`);
1523
+ `)}throw Error(`Unhandled combination (lists_setIndex).`)},lists_sort:function(e,t){var n=t.valueToCode(e,`LIST`,l.NONE)||`[]`,r=e.getFieldValue(`DIRECTION`)===`1`?1:-1;return e=e.getFieldValue(`TYPE`),[t.provideFunction_(`lists_sort`,`
1524
+ List ${t.FUNCTION_NAME_PLACEHOLDER_}(List list, String type, int direction) {
1525
+ var compareFuncs = {
1526
+ 'NUMERIC': (a, b) => (direction * a.compareTo(b)).toInt(),
1527
+ 'TEXT': (a, b) => direction * a.toString().compareTo(b.toString()),
1528
+ 'IGNORE_CASE':
1529
+ (a, b) => direction *
1530
+ a.toString().toLowerCase().compareTo(b.toString().toLowerCase())
1531
+ };
1532
+ list = new List.from(list);
1533
+ var compare = compareFuncs[type];
1534
+ list.sort(compare);
1535
+ return list;
1536
+ }
1537
+ `)+`(`+n+`, "`+e+`", `+r+`)`,l.UNARY_POSTFIX]},lists_split:function(e,t){var n=t.valueToCode(e,`INPUT`,l.UNARY_POSTFIX);if(t=t.valueToCode(e,`DELIM`,l.NONE)||`''`,e=e.getFieldValue(`MODE`),e===`SPLIT`)n||=`''`,e=`split`;else if(e===`JOIN`)n||=`[]`,e=`join`;else throw Error(`Unknown mode: `+e);return[n+`.`+e+`(`+t+`)`,l.UNARY_POSTFIX]}},f,p,m,h,g,_,v);for(let e in y)ee.forBlock[e]=y[e];var te={};return te.DartGenerator=d,te.Order=l,te.dartGenerator=ee,t.__chunk_dart=te,t.__chunk_dart.__namespace__=t,t.__chunk_dart})})),Sl=t(((e,t)=>{(function(r,i){typeof define==`function`&&define.amd?define([`./blockly_compressed.js`],i):typeof e==`object`?t.exports=i(n()):(r.lua=i(r.Blockly),r.Blockly.Lua=r.lua.luaGenerator)})(e,function(e){var t=e.__namespace__,n=function(e,t,n){return t===`FIRST`?`1`:t===`FROM_END`?`#`+e+` + 1 - `+n:t===`LAST`?`#`+e:t===`RANDOM`?`math.random(#`+e+`)`:n},r=function(e,t){var n=0,r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e));do{let i=t.valueToCode(e,`IF`+n,d.NONE)||`false`,a=t.statementToCode(e,`DO`+n);t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=(n>0?`else`:``)+`if `+i+` then
1538
+ `+a,n++}while(e.getInput(`IF`+n));return(e.getInput(`ELSE`)||t.STATEMENT_SUFFIX)&&(n=e.getInput(`ELSE`)?t.statementToCode(e,`ELSE`):``,t.STATEMENT_SUFFIX&&(n=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+n),r+=`else
1539
+ `+n),r+`end
1540
+ `},i=function(e,t){return e.includes(`goto continue
1541
+ `)?e+t+`::continue::
1542
+ `:e},a=function(e,n){var r=e.getField(`TIMES`)?String(Number(e.getFieldValue(`TIMES`))):n.valueToCode(e,`TIMES`,d.NONE)||`0`;r=t.df(r)?parseInt(r,10):`math.floor(`+r+`)`;var a=n.statementToCode(e,`DO`);return a=n.addLoopTrap(a,e),a=i(a,n.INDENT),`for `+n.nameDB_.getDistinctName(`count`,t.P.VARIABLE)+` = 1, `+r+` do
1543
+ `+a+`end
1544
+ `},o=function(e,t){var n=e.getFieldValue(`OP`);if(n===`NEG`)return e=t.valueToCode(e,`NUM`,d.UNARY)||`0`,[`-`+e,d.UNARY];if(n===`POW10`)return e=t.valueToCode(e,`NUM`,d.EXPONENTIATION)||`0`,[`10 ^ `+e,d.EXPONENTIATION];switch(e=n===`ROUND`?t.valueToCode(e,`NUM`,d.ADDITIVE)||`0`:t.valueToCode(e,`NUM`,d.NONE)||`0`,n){case`ABS`:n=`math.abs(`+e+`)`;break;case`ROOT`:n=`math.sqrt(`+e+`)`;break;case`LN`:n=`math.log(`+e+`)`;break;case`LOG10`:n=`math.log(`+e+`, 10)`;break;case`EXP`:n=`math.exp(`+e+`)`;break;case`ROUND`:n=`math.floor(`+e+` + .5)`;break;case`ROUNDUP`:n=`math.ceil(`+e+`)`;break;case`ROUNDDOWN`:n=`math.floor(`+e+`)`;break;case`SIN`:n=`math.sin(math.rad(`+e+`))`;break;case`COS`:n=`math.cos(math.rad(`+e+`))`;break;case`TAN`:n=`math.tan(math.rad(`+e+`))`;break;case`ASIN`:n=`math.deg(math.asin(`+e+`))`;break;case`ACOS`:n=`math.deg(math.acos(`+e+`))`;break;case`ATAN`:n=`math.deg(math.atan(`+e+`))`;break;default:throw Error(`Unknown math operator: `+n)}return[n,d.HIGH]},s=function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(r+=t.injectId(t.STATEMENT_SUFFIX,e)),r&&=t.prefixLines(r,t.INDENT);var i=``;t.INFINITE_LOOP_TRAP&&(i=t.prefixLines(t.injectId(t.INFINITE_LOOP_TRAP,e),t.INDENT));var a=``;e.getInput(`STACK`)&&(a=t.statementToCode(e,`STACK`));var o=``;e.getInput(`RETURN`)&&(o=t.valueToCode(e,`RETURN`,d.NONE)||``);var s=``;a&&o&&(s=r),o?o=t.INDENT+`return `+o+`
1545
+ `:a||=``;var c=[],l=e.getVarModels();for(let e=0;e<l.length;e++)c[e]=t.getVariableName(l[e].getId());return r=`function `+n+`(`+c.join(`, `)+`)
1546
+ `+r+i+a+s+o+`end
1547
+ `,r=t.scrub_(e,r),t.definitions_[`%`+n]=r,null},c=function(e,t){var n=e.getField(`TEXT`)?t.quote_(e.getFieldValue(`TEXT`)):t.valueToCode(e,`TEXT`,d.NONE)||`''`;return t=t.provideFunction_(`text_prompt`,`
1548
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(msg)
1549
+ io.write(msg)
1550
+ io.flush()
1551
+ return io.read()
1552
+ end
1553
+ `)+`(`+n+`)`,e.getFieldValue(`TYPE`)===`NUMBER`&&(t=`tonumber(`+t+`, 10)`),[t,d.HIGH]},l=function(e,t){return[t.getVariableName(e.getFieldValue(`VAR`)),d.ATOMIC]},u=function(e,t){var n=t.valueToCode(e,`VALUE`,d.NONE)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` = `+n+`
1554
+ `},d,f=d||={};f[f.ATOMIC=0]=`ATOMIC`,f[f.HIGH=1]=`HIGH`,f[f.EXPONENTIATION=2]=`EXPONENTIATION`,f[f.UNARY=3]=`UNARY`,f[f.MULTIPLICATIVE=4]=`MULTIPLICATIVE`,f[f.ADDITIVE=5]=`ADDITIVE`,f[f.CONCATENATION=6]=`CONCATENATION`,f[f.RELATIONAL=7]=`RELATIONAL`,f[f.AND=8]=`AND`,f[f.OR=9]=`OR`,f[f.NONE=99]=`NONE`;var p=class extends t.Ip{constructor(e=`Lua`){super(e),this.isInitialized=!1;for(let t in d)e=d[t],typeof e!=`string`&&(this[`ORDER_`+t]=e);this.addReservedWords(`_,__inext,assert,bit,colors,colours,coroutine,disk,dofile,error,fs,fetfenv,getmetatable,gps,help,io,ipairs,keys,loadfile,loadstring,math,native,next,os,paintutils,pairs,parallel,pcall,peripheral,print,printError,rawequal,rawget,rawset,read,rednet,redstone,rs,select,setfenv,setmetatable,sleep,string,table,term,textutils,tonumber,tostring,turtle,type,unpack,vector,write,xpcall,_VERSION,__indext,HTTP,and,break,do,else,elseif,end,false,for,function,if,in,local,nil,not,or,repeat,return,then,true,until,while,add,sub,mul,div,mod,pow,unm,concat,len,eq,lt,le,index,newindex,call,assert,collectgarbage,dofile,error,_G,getmetatable,inpairs,load,loadfile,next,pairs,pcall,print,rawequal,rawget,rawlen,rawset,select,setmetatable,tonumber,tostring,type,_VERSION,xpcall,require,package,string,table,math,bit32,io,file,os,debug`)}init(e){super.init(e),this.nameDB_?this.nameDB_.reset():this.nameDB_=new t.aj(this.RESERVED_WORDS_),this.nameDB_.setVariableMap(e.getVariableMap()),this.nameDB_.populateVariables(e),this.nameDB_.populateProcedures(e),this.isInitialized=!0}finish(e){var t=Object.values(this.definitions_);return e=super.finish(e),this.isInitialized=!1,this.nameDB_.reset(),t.join(`
1555
+
1556
+ `)+`
1557
+
1558
+
1559
+ `+e}scrubNakedValue(e){return`local _ = `+e+`
1560
+ `}quote_(e){return e=e.replace(/\\/g,`\\\\`).replace(/\n/g,`\\
1561
+ `).replace(/'/g,`\\'`),`'`+e+`'`}multiline_quote_(e){return e.split(/\n/g).map(this.quote_).join(` .. '\\n' ..
1562
+ `)}scrub_(e,n,r=!1){var i=``;if(!e.outputConnection||!e.outputConnection.targetConnection){var a=e.getCommentText();a&&(a=t.cf(a,this.COMMENT_WRAP-3),i+=this.prefixLines(a,`-- `)+`
1563
+ `);for(let n=0;n<e.inputList.length;n++)e.inputList[n].type===t.he.VALUE&&(a=e.inputList[n].connection.targetBlock())&&(a=this.allNestedComments(a))&&(i+=this.prefixLines(a,`-- `))}return e=e.nextConnection&&e.nextConnection.targetBlock(),r=r?``:this.blockToCode(e),i+n+r}},m={};m.controls_if=r,m.controls_ifelse=r,m.logic_boolean=function(e){return[e.getFieldValue(`BOOL`)===`TRUE`?`true`:`false`,d.ATOMIC]},m.logic_compare=function(e,t){var n={EQ:`==`,NEQ:`~=`,LT:`<`,LTE:`<=`,GT:`>`,GTE:`>=`}[e.getFieldValue(`OP`)],r=t.valueToCode(e,`A`,d.RELATIONAL)||`0`;return e=t.valueToCode(e,`B`,d.RELATIONAL)||`0`,[r+` `+n+` `+e,d.RELATIONAL]},m.logic_negate=function(e,t){return[`not `+(t.valueToCode(e,`BOOL`,d.UNARY)||`true`),d.UNARY]},m.logic_null=function(){return[`nil`,d.ATOMIC]},m.logic_operation=function(e,t){var n=e.getFieldValue(`OP`)===`AND`?`and`:`or`,r=n===`and`?d.AND:d.OR,i=t.valueToCode(e,`A`,r);return e=t.valueToCode(e,`B`,r),i||e?(t=n===`and`?`true`:`false`,i||=t,e||=t):e=i=`false`,[i+` `+n+` `+e,r]},m.logic_ternary=function(e,t){var n=t.valueToCode(e,`IF`,d.AND)||`false`,r=t.valueToCode(e,`THEN`,d.AND)||`nil`;return e=t.valueToCode(e,`ELSE`,d.OR)||`nil`,[n+` and `+r+` or `+e,d.OR]};var h={controls_flow_statements:function(e,t){var n=``;if(t.STATEMENT_PREFIX&&(n+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(n+=t.injectId(t.STATEMENT_SUFFIX,e)),t.STATEMENT_PREFIX){let r=e.getSurroundLoop();r&&!r.suppressPrefixSuffix&&(n+=t.injectId(t.STATEMENT_PREFIX,r))}switch(e.getFieldValue(`FLOW`)){case`BREAK`:return n+`break
1564
+ `;case`CONTINUE`:return n+`goto continue
1565
+ `}throw Error(`Unknown flow statement.`)},controls_for:function(e,n){var r=n.getVariableName(e.getFieldValue(`VAR`)),a=n.valueToCode(e,`FROM`,d.NONE)||`0`,o=n.valueToCode(e,`TO`,d.NONE)||`0`,s=n.valueToCode(e,`BY`,d.NONE)||`1`,c=n.statementToCode(e,`DO`);if(c=n.addLoopTrap(c,e),c=i(c,n.INDENT),e=``,t.df(a)&&t.df(o)&&t.df(s))var l=(Number(a)<=Number(o)?``:`-`)+Math.abs(Number(s));else e=``,l=n.nameDB_.getDistinctName(r+`_inc`,t.P.VARIABLE),e+=l+` = `,e=t.df(s)?e+(Math.abs(s)+`
1566
+ `):e+(`math.abs(`+s+`)
1567
+ `),e=e+(`if (`+a+`) > (`+o+`) then
1568
+ `)+(n.INDENT+l+` = -`+l+`
1569
+ `),e+=`end
1570
+ `;return e+(`for `+r+` = `+a+`, `+o+`, `+l)+(` do
1571
+ `+c+`end
1572
+ `)},controls_forEach:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`)),r=t.valueToCode(e,`LIST`,d.NONE)||`{}`,a=t.statementToCode(e,`DO`);return a=t.addLoopTrap(a,e),a=i(a,t.INDENT),`for _, `+n+` in ipairs(`+r+`) do
1573
+ `+a+`end
1574
+ `}};h.controls_repeat=a,h.controls_repeat_ext=a,h.controls_whileUntil=function(e,t){var n=e.getFieldValue(`MODE`)===`UNTIL`,r=t.valueToCode(e,`BOOL`,n?d.UNARY:d.NONE)||`false`,a=t.statementToCode(e,`DO`);return a=t.addLoopTrap(a,e),a=i(a,t.INDENT),n&&(r=`not `+r),`while `+r+` do
1575
+ `+a+`end
1576
+ `};var g={math_arithmetic:function(e,t){var n={ADD:[` + `,d.ADDITIVE],MINUS:[` - `,d.ADDITIVE],MULTIPLY:[` * `,d.MULTIPLICATIVE],DIVIDE:[` / `,d.MULTIPLICATIVE],POWER:[` ^ `,d.EXPONENTIATION]}[e.getFieldValue(`OP`)],r=n[0];n=n[1];var i=t.valueToCode(e,`A`,n)||`0`;return e=t.valueToCode(e,`B`,n)||`0`,[i+r+e,n]},math_atan2:function(e,t){var n=t.valueToCode(e,`X`,d.NONE)||`0`;return[`math.deg(math.atan2(`+(t.valueToCode(e,`Y`,d.NONE)||`0`)+`, `+n+`))`,d.HIGH]},math_change:function(e,t){var n=t.valueToCode(e,`DELTA`,d.ADDITIVE)||`0`;return e=t.getVariableName(e.getFieldValue(`VAR`)),e+` = `+e+` + `+n+`
1577
+ `},math_constant:function(e){return{PI:[`math.pi`,d.HIGH],E:[`math.exp(1)`,d.HIGH],GOLDEN_RATIO:[`(1 + math.sqrt(5)) / 2`,d.MULTIPLICATIVE],SQRT2:[`math.sqrt(2)`,d.HIGH],SQRT1_2:[`math.sqrt(1 / 2)`,d.HIGH],INFINITY:[`math.huge`,d.HIGH]}[e.getFieldValue(`CONSTANT`)]},math_constrain:function(e,t){var n=t.valueToCode(e,`VALUE`,d.NONE)||`0`,r=t.valueToCode(e,`LOW`,d.NONE)||`-math.huge`;return e=t.valueToCode(e,`HIGH`,d.NONE)||`math.huge`,[`math.min(math.max(`+n+`, `+r+`), `+e+`)`,d.HIGH]},math_modulo:function(e,t){var n=t.valueToCode(e,`DIVIDEND`,d.MULTIPLICATIVE)||`0`;return e=t.valueToCode(e,`DIVISOR`,d.MULTIPLICATIVE)||`0`,[n+` % `+e,d.MULTIPLICATIVE]},math_number:function(e){return e=Number(e.getFieldValue(`NUM`)),[String(e),e<0?d.UNARY:d.ATOMIC]},math_number_property:function(e,t){var n={EVEN:[` % 2 == 0`,d.MULTIPLICATIVE,d.RELATIONAL],ODD:[` % 2 == 1`,d.MULTIPLICATIVE,d.RELATIONAL],WHOLE:[` % 1 == 0`,d.MULTIPLICATIVE,d.RELATIONAL],POSITIVE:[` > 0`,d.RELATIONAL,d.RELATIONAL],NEGATIVE:[` < 0`,d.RELATIONAL,d.RELATIONAL],DIVISIBLE_BY:[null,d.MULTIPLICATIVE,d.RELATIONAL],PRIME:[null,d.NONE,d.HIGH]},r=e.getFieldValue(`PROPERTY`),[i,a,o]=n[r];if(n=t.valueToCode(e,`NUMBER_TO_CHECK`,a)||`0`,r===`PRIME`)e=t.provideFunction_(`math_isPrime`,`
1578
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(n)
1579
+ -- https://en.wikipedia.org/wiki/Primality_test#Naive_methods
1580
+ if n == 2 or n == 3 then
1581
+ return true
1582
+ end
1583
+ -- False if n is NaN, negative, is 1, or not whole.
1584
+ -- And false if n is divisible by 2 or 3.
1585
+ if not(n > 1) or n % 1 ~= 0 or n % 2 == 0 or n % 3 == 0 then
1586
+ return false
1587
+ end
1588
+ -- Check all the numbers of form 6k +/- 1, up to sqrt(n).
1589
+ for x = 6, math.sqrt(n) + 1.5, 6 do
1590
+ if n % (x - 1) == 0 or n % (x + 1) == 0 then
1591
+ return false
1592
+ end
1593
+ end
1594
+ return true
1595
+ end
1596
+ `)+`(`+n+`)`;else if(r===`DIVISIBLE_BY`){if(e=t.valueToCode(e,`DIVISOR`,d.MULTIPLICATIVE)||`0`,e===`0`)return[`nil`,d.ATOMIC];e=n+` % `+e+` == 0`}else e=n+i;return[e,o]},math_on_list:function(e,t){function n(){return t.provideFunction_(`math_sum`,`
1597
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1598
+ local result = 0
1599
+ for _, v in ipairs(t) do
1600
+ result = result + v
1601
+ end
1602
+ return result
1603
+ end
1604
+ `)}var r=e.getFieldValue(`OP`);switch(e=t.valueToCode(e,`LIST`,d.NONE)||`{}`,r){case`SUM`:r=n();break;case`MIN`:r=t.provideFunction_(`math_min`,`
1605
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1606
+ if #t == 0 then
1607
+ return 0
1608
+ end
1609
+ local result = math.huge
1610
+ for _, v in ipairs(t) do
1611
+ if v < result then
1612
+ result = v
1613
+ end
1614
+ end
1615
+ return result
1616
+ end
1617
+ `);break;case`AVERAGE`:r=t.provideFunction_(`math_average`,`
1618
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1619
+ if #t == 0 then
1620
+ return 0
1621
+ end
1622
+ return ${n()}(t) / #t
1623
+ end
1624
+ `);break;case`MAX`:r=t.provideFunction_(`math_max`,`
1625
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1626
+ if #t == 0 then
1627
+ return 0
1628
+ end
1629
+ local result = -math.huge
1630
+ for _, v in ipairs(t) do
1631
+ if v > result then
1632
+ result = v
1633
+ end
1634
+ end
1635
+ return result
1636
+ end
1637
+ `);break;case`MEDIAN`:r=t.provideFunction_(`math_median`,`
1638
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1639
+ -- Source: http://lua-users.org/wiki/SimpleStats
1640
+ if #t == 0 then
1641
+ return 0
1642
+ end
1643
+ local temp = {}
1644
+ for _, v in ipairs(t) do
1645
+ if type(v) == 'number' then
1646
+ table.insert(temp, v)
1647
+ end
1648
+ end
1649
+ table.sort(temp)
1650
+ if #temp % 2 == 0 then
1651
+ return (temp[#temp / 2] + temp[(#temp / 2) + 1]) / 2
1652
+ else
1653
+ return temp[math.ceil(#temp / 2)]
1654
+ end
1655
+ end
1656
+ `);break;case`MODE`:r=t.provideFunction_(`math_modes`,`
1657
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1658
+ -- Source: http://lua-users.org/wiki/SimpleStats
1659
+ local counts = {}
1660
+ for _, v in ipairs(t) do
1661
+ if counts[v] == nil then
1662
+ counts[v] = 1
1663
+ else
1664
+ counts[v] = counts[v] + 1
1665
+ end
1666
+ end
1667
+ local biggestCount = 0
1668
+ for _, v in pairs(counts) do
1669
+ if v > biggestCount then
1670
+ biggestCount = v
1671
+ end
1672
+ end
1673
+ local temp = {}
1674
+ for k, v in pairs(counts) do
1675
+ if v == biggestCount then
1676
+ table.insert(temp, k)
1677
+ end
1678
+ end
1679
+ return temp
1680
+ end
1681
+ `);break;case`STD_DEV`:r=t.provideFunction_(`math_standard_deviation`,`
1682
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1683
+ local m
1684
+ local vm
1685
+ local total = 0
1686
+ local count = 0
1687
+ local result
1688
+ m = #t == 0 and 0 or ${n()}(t) / #t
1689
+ for _, v in ipairs(t) do
1690
+ if type(v) == 'number' then
1691
+ vm = v - m
1692
+ total = total + (vm * vm)
1693
+ count = count + 1
1694
+ end
1695
+ end
1696
+ result = math.sqrt(total / (count-1))
1697
+ return result
1698
+ end
1699
+ `);break;case`RANDOM`:r=t.provideFunction_(`math_random_list`,`
1700
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t)
1701
+ if #t == 0 then
1702
+ return nil
1703
+ end
1704
+ return t[math.random(#t)]
1705
+ end
1706
+ `);break;default:throw Error(`Unknown operator: `+r)}return[r+`(`+e+`)`,d.HIGH]},math_random_float:function(){return[`math.random()`,d.HIGH]},math_random_int:function(e,t){var n=t.valueToCode(e,`FROM`,d.NONE)||`0`;return e=t.valueToCode(e,`TO`,d.NONE)||`0`,[`math.random(`+n+`, `+e+`)`,d.HIGH]}};g.math_round=o,g.math_single=o,g.math_trig=o;var _={procedures_callnoreturn:function(e,t){return t.forBlock.procedures_callreturn(e,t)[0]+`
1707
+ `},procedures_callreturn:function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=[],i=e.getVarModels();for(let n=0;n<i.length;n++)r[n]=t.valueToCode(e,`ARG`+n,d.NONE)||`nil`;return[n+`(`+r.join(`, `)+`)`,d.HIGH]}};_.procedures_defnoreturn=s,_.procedures_defreturn=s,_.procedures_ifreturn=function(e,t){var n=`if `+(t.valueToCode(e,`CONDITION`,d.NONE)||`false`)+` then
1708
+ `;return t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_?(e=t.valueToCode(e,`VALUE`,d.NONE)||`nil`,n+=t.INDENT+`return `+e+`
1709
+ `):n+=t.INDENT+`return
1710
+ `,n+`end
1711
+ `};var v={text:function(e,t){return[t.quote_(e.getFieldValue(`TEXT`)),d.ATOMIC]},text_append:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`));return e=t.valueToCode(e,`TEXT`,d.CONCATENATION)||`''`,n+` = `+n+` .. `+e+`
1712
+ `},text_changeCase:function(e,t){var n=e.getFieldValue(`CASE`);e=t.valueToCode(e,`TEXT`,d.NONE)||`''`;var r;return n===`UPPERCASE`?r=`string.upper`:n===`LOWERCASE`?r=`string.lower`:n===`TITLECASE`&&(r=t.provideFunction_(`text_titlecase`,`
1713
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str)
1714
+ local buf = {}
1715
+ local inWord = false
1716
+ for i = 1, #str do
1717
+ local c = string.sub(str, i, i)
1718
+ if inWord then
1719
+ table.insert(buf, string.lower(c))
1720
+ if string.find(c, "%s") then
1721
+ inWord = false
1722
+ end
1723
+ else
1724
+ table.insert(buf, string.upper(c))
1725
+ inWord = true
1726
+ end
1727
+ end
1728
+ return table.concat(buf)
1729
+ end
1730
+ `)),[r+`(`+e+`)`,d.HIGH]},text_charAt:function(e,t){var n=e.getFieldValue(`WHERE`)||`FROM_START`,r=t.valueToCode(e,`VALUE`,d.NONE)||`''`;if(n===`RANDOM`)t=t.provideFunction_(`text_random_letter`,`
1731
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str)
1732
+ local index = math.random(string.len(str))
1733
+ return string.sub(str, index, index)
1734
+ end
1735
+ `)+`(`+r+`)`;else{if(n===`FIRST`)n=`1`;else if(n===`LAST`)n=`-1`;else if(e=t.valueToCode(e,`AT`,n===`FROM_END`?d.UNARY:d.NONE)||`1`,n===`FROM_START`)n=e;else if(n===`FROM_END`)n=`-`+e;else throw Error(`Unhandled option (text_charAt).`);t=n.match(/^-?\w*$/)?`string.sub(`+r+`, `+n+`, `+n+`)`:t.provideFunction_(`text_char_at`,`
1736
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str, index)
1737
+ return string.sub(str, index, index)
1738
+ end
1739
+ `)+`(`+r+`, `+n+`)`}return[t,d.HIGH]},text_count:function(e,t){var n=t.valueToCode(e,`TEXT`,d.NONE)||`''`;return e=t.valueToCode(e,`SUB`,d.NONE)||`''`,[t.provideFunction_(`text_count`,`
1740
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle)
1741
+ if #needle == 0 then
1742
+ return #haystack + 1
1743
+ end
1744
+ local i = 1
1745
+ local count = 0
1746
+ while true do
1747
+ i = string.find(haystack, needle, i, true)
1748
+ if i == nil then
1749
+ break
1750
+ end
1751
+ count = count + 1
1752
+ i = i + #needle
1753
+ end
1754
+ return count
1755
+ end
1756
+ `)+`(`+n+`, `+e+`)`,d.HIGH]},text_getSubstring:function(e,t){var n=t.valueToCode(e,`STRING`,d.NONE)||`''`,r=e.getFieldValue(`WHERE1`),i=t.valueToCode(e,`AT1`,r===`FROM_END`?d.UNARY:d.NONE)||`1`;if(r===`FIRST`)r=1;else if(r===`FROM_START`)r=i;else if(r===`FROM_END`)r=`-`+i;else throw Error(`Unhandled option (text_getSubstring)`);if(i=e.getFieldValue(`WHERE2`),e=t.valueToCode(e,`AT2`,i===`FROM_END`?d.UNARY:d.NONE)||`1`,i===`LAST`)e=-1;else if(i!==`FROM_START`)if(i===`FROM_END`)e=`-`+e;else throw Error(`Unhandled option (text_getSubstring)`);return[`string.sub(`+n+`, `+r+`, `+e+`)`,d.HIGH]},text_indexOf:function(e,t){var n=t.valueToCode(e,`FIND`,d.NONE)||`''`,r=t.valueToCode(e,`VALUE`,d.NONE)||`''`;return[(e.getFieldValue(`END`)===`FIRST`?t.provideFunction_(`firstIndexOf`,`
1757
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str, substr)
1758
+ local i = string.find(str, substr, 1, true)
1759
+ if i == nil then
1760
+ return 0
1761
+ end
1762
+ return i
1763
+ end
1764
+ `):t.provideFunction_(`lastIndexOf`,`
1765
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(str, substr)
1766
+ local i = string.find(string.reverse(str), string.reverse(substr), 1, true)
1767
+ if i then
1768
+ return #str + 2 - i - #substr
1769
+ end
1770
+ return 0
1771
+ end
1772
+ `))+`(`+r+`, `+n+`)`,d.HIGH]},text_isEmpty:function(e,t){return[`#`+(t.valueToCode(e,`VALUE`,d.UNARY)||`''`)+` == 0`,d.RELATIONAL]},text_join:function(e,t){if(e.itemCount_===0)return[`''`,d.ATOMIC];if(e.itemCount_===1)return[`tostring(`+(t.valueToCode(e,`ADD0`,d.NONE)||`''`)+`)`,d.HIGH];if(e.itemCount_===2){var n=t.valueToCode(e,`ADD0`,d.CONCATENATION)||`''`;return e=t.valueToCode(e,`ADD1`,d.CONCATENATION)||`''`,[n+` .. `+e,d.CONCATENATION]}n=[];for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,d.NONE)||`''`;return[`table.concat({`+n.join(`, `)+`})`,d.HIGH]},text_length:function(e,t){return[`#`+(t.valueToCode(e,`VALUE`,d.UNARY)||`''`),d.UNARY]},text_print:function(e,t){return`print(`+(t.valueToCode(e,`TEXT`,d.NONE)||`''`)+`)
1773
+ `}};v.text_prompt=c,v.text_prompt_ext=c,v.text_replace=function(e,t){var n=t.valueToCode(e,`TEXT`,d.NONE)||`''`,r=t.valueToCode(e,`FROM`,d.NONE)||`''`;return e=t.valueToCode(e,`TO`,d.NONE)||`''`,[t.provideFunction_(`text_replace`,`
1774
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(haystack, needle, replacement)
1775
+ local buf = {}
1776
+ local i = 1
1777
+ while i <= #haystack do
1778
+ if string.sub(haystack, i, i + #needle - 1) == needle then
1779
+ for j = 1, #replacement do
1780
+ table.insert(buf, string.sub(replacement, j, j))
1781
+ end
1782
+ i = i + #needle
1783
+ else
1784
+ table.insert(buf, string.sub(haystack, i, i))
1785
+ i = i + 1
1786
+ end
1787
+ end
1788
+ return table.concat(buf)
1789
+ end
1790
+ `)+`(`+n+`, `+r+`, `+e+`)`,d.HIGH]},v.text_reverse=function(e,t){return[`string.reverse(`+(t.valueToCode(e,`TEXT`,d.NONE)||`''`)+`)`,d.HIGH]},v.text_trim=function(e,t){var n={LEFT:`^%s*(,-)`,RIGHT:`(.-)%s*$`,BOTH:`^%s*(.-)%s*$`}[e.getFieldValue(`MODE`)];return[`string.gsub(`+(t.valueToCode(e,`TEXT`,d.NONE)||`''`)+`, "`+n+`", "%1")`,d.HIGH]};var ee={};ee.variables_get=l,ee.variables_set=u;var y={};y.variables_get_dynamic=l,y.variables_set_dynamic=u;var te=new p,b=Object.assign({},{lists_create_empty:function(){return[`{}`,d.HIGH]},lists_create_with:function(e,t){var n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,d.NONE)||`nil`;return[`{`+n.join(`, `)+`}`,d.HIGH]},lists_getIndex:function(e,r){var i=e.getFieldValue(`MODE`)||`GET`,a=e.getFieldValue(`WHERE`)||`FROM_START`,o=r.valueToCode(e,`VALUE`,d.HIGH)||`({})`;return a!==`LAST`&&a!==`FROM_END`&&a!==`RANDOM`||o.match(/^\w+$/)?(r=r.valueToCode(e,`AT`,i===`GET`&&a===`FROM_END`?d.ADDITIVE:d.NONE)||`1`,r=n(o,a,r),i===`GET`?[o+`[`+r+`]`,d.HIGH]:(a=`table.remove(`+o+`, `+r+`)`,i===`GET_REMOVE`?[a,d.HIGH]:a+`
1791
+ `)):i===`REMOVE`?(i=r.valueToCode(e,`AT`,a===`FROM_END`?d.ADDITIVE:d.NONE)||`1`,r=r.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE),i=n(r,a,i),r+` = `+o+`
1792
+ table.remove(`+r+`, `+i+`)
1793
+ `):(e=r.valueToCode(e,`AT`,d.NONE)||`1`,[(i===`GET`?r.provideFunction_(`list_get_`+a.toLowerCase(),[`function `+r.FUNCTION_NAME_PLACEHOLDER_+`(t`+(a===`FROM_END`||a===`FROM_START`?`, at)`:`)`),` return t[`+n(`t`,a,`at`)+`]`,`end`]):r.provideFunction_(`list_remove_`+a.toLowerCase(),[`function `+r.FUNCTION_NAME_PLACEHOLDER_+`(t`+(a===`FROM_END`||a===`FROM_START`?`, at)`:`)`),` return table.remove(t, `+n(`t`,a,`at`)+`)`,`end`]))+`(`+o+(a===`FROM_END`||a===`FROM_START`?`, `+e:``)+`)`,d.HIGH])},lists_getSublist:function(e,t){var r=t.valueToCode(e,`LIST`,d.NONE)||`{}`,i=e.getFieldValue(`WHERE1`),a=e.getFieldValue(`WHERE2`),o=t.valueToCode(e,`AT1`,d.NONE)||`1`;e=t.valueToCode(e,`AT2`,d.NONE)||`1`;var s=i===`FROM_END`||i===`FROM_START`?`, at1`:``,c=a===`FROM_END`||a===`FROM_START`?`, at2`:``;return[t.provideFunction_(`list_sublist_`+i.toLowerCase()+`_`+a.toLowerCase(),`
1794
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(source${s}${c})
1795
+ local t = {}
1796
+ local start = ${n(`source`,i,`at1`)}
1797
+ local finish = ${n(`source`,a,`at2`)}
1798
+ for i = start, finish do
1799
+ table.insert(t, source[i])
1800
+ end
1801
+ return t
1802
+ end
1803
+ `)+`(`+r+(i===`FROM_END`||i===`FROM_START`?`, `+o:``)+(a===`FROM_END`||a===`FROM_START`?`, `+e:``)+`)`,d.HIGH]},lists_indexOf:function(e,t){var n=t.valueToCode(e,`FIND`,d.NONE)||`''`,r=t.valueToCode(e,`VALUE`,d.NONE)||`{}`;return[(e.getFieldValue(`END`)===`FIRST`?t.provideFunction_(`first_index`,`
1804
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t, elem)
1805
+ for k, v in ipairs(t) do
1806
+ if v == elem then
1807
+ return k
1808
+ end
1809
+ end
1810
+ return 0
1811
+ end
1812
+ `):t.provideFunction_(`last_index`,`
1813
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(t, elem)
1814
+ for i = #t, 1, -1 do
1815
+ if t[i] == elem then
1816
+ return i
1817
+ end
1818
+ end
1819
+ return 0
1820
+ end
1821
+ `))+`(`+r+`, `+n+`)`,d.HIGH]},lists_isEmpty:function(e,t){return[`#`+(t.valueToCode(e,`VALUE`,d.UNARY)||`{}`)+` == 0`,d.RELATIONAL]},lists_length:function(e,t){return[`#`+(t.valueToCode(e,`VALUE`,d.UNARY)||`{}`),d.UNARY]},lists_repeat:function(e,t){var n=t.provideFunction_(`create_list_repeated`,`
1822
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(item, count)
1823
+ local t = {}
1824
+ for i = 1, count do
1825
+ table.insert(t, item)
1826
+ end
1827
+ return t
1828
+ end
1829
+ `),r=t.valueToCode(e,`ITEM`,d.NONE)||`nil`;return e=t.valueToCode(e,`NUM`,d.NONE)||`0`,[n+`(`+r+`, `+e+`)`,d.HIGH]},lists_reverse:function(e,t){return e=t.valueToCode(e,`LIST`,d.NONE)||`{}`,[t.provideFunction_(`list_reverse`,`
1830
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(input)
1831
+ local reversed = {}
1832
+ for i = #input, 1, -1 do
1833
+ table.insert(reversed, input[i])
1834
+ end
1835
+ return reversed
1836
+ end
1837
+ `)+`(`+e+`)`,d.HIGH]},lists_setIndex:function(e,r){var i=r.valueToCode(e,`LIST`,d.HIGH)||`{}`,a=e.getFieldValue(`MODE`)||`SET`,o=e.getFieldValue(`WHERE`)||`FROM_START`,s=r.valueToCode(e,`AT`,d.ADDITIVE)||`1`;e=r.valueToCode(e,`TO`,d.NONE)||`Nil`;var c=``;return o!==`LAST`&&o!==`FROM_END`&&o!==`RANDOM`||i.match(/^\w+$/)||(r=r.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE),c=r+` = `+i+`
1838
+ `,i=r),c=a===`SET`?c+(i+`[`+n(i,o,s)+`] = `+e):c+(`table.insert(`+i+`, `+(n(i,o,s)+(o===`LAST`?` + 1`:``))+`, `+e+`)`),c+`
1839
+ `},lists_sort:function(e,t){var n=t.valueToCode(e,`LIST`,d.NONE)||`{}`,r=e.getFieldValue(`DIRECTION`)===`1`?1:-1;return e=e.getFieldValue(`TYPE`),[t.provideFunction_(`list_sort`,`
1840
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(list, typev, direction)
1841
+ local t = {}
1842
+ for n,v in pairs(list) do table.insert(t, v) end
1843
+ local compareFuncs = {
1844
+ NUMERIC = function(a, b)
1845
+ return (tonumber(tostring(a)) or 0)
1846
+ < (tonumber(tostring(b)) or 0) end,
1847
+ TEXT = function(a, b)
1848
+ return tostring(a) < tostring(b) end,
1849
+ IGNORE_CASE = function(a, b)
1850
+ return string.lower(tostring(a)) < string.lower(tostring(b)) end
1851
+ }
1852
+ local compareTemp = compareFuncs[typev]
1853
+ local compare = compareTemp
1854
+ if direction == -1
1855
+ then compare = function(a, b) return compareTemp(b, a) end
1856
+ end
1857
+ table.sort(t, compare)
1858
+ return t
1859
+ end
1860
+ `)+`(`+n+`,"`+e+`", `+r+`)`,d.HIGH]},lists_split:function(e,t){var n=t.valueToCode(e,`INPUT`,d.NONE),r=t.valueToCode(e,`DELIM`,d.NONE)||`''`;if(e=e.getFieldValue(`MODE`),e===`SPLIT`)n||=`''`,t=t.provideFunction_(`list_string_split`,`
1861
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(input, delim)
1862
+ local t = {}
1863
+ local pos = 1
1864
+ while true do
1865
+ next_delim = string.find(input, delim, pos)
1866
+ if next_delim == nil then
1867
+ table.insert(t, string.sub(input, pos))
1868
+ break
1869
+ else
1870
+ table.insert(t, string.sub(input, pos, next_delim-1))
1871
+ pos = next_delim + #delim
1872
+ end
1873
+ end
1874
+ return t
1875
+ end
1876
+ `);else if(e===`JOIN`)n||=`{}`,t=`table.concat`;else throw Error(`Unknown mode: `+e);return[t+`(`+n+`, `+r+`)`,d.HIGH]}},m,h,g,_,v,ee,y);for(let e in b)te.forBlock[e]=b[e];var ne={};return ne.LuaGenerator=p,ne.Order=d,ne.luaGenerator=te,t.__chunk_lua=ne,t.__chunk_lua.__namespace__=t,t.__chunk_lua})})),Cl=t(((e,t)=>{(function(r,i){typeof define==`function`&&define.amd?define([`./blockly_compressed.js`],i):typeof e==`object`?t.exports=i(n()):(r.php=i(r.Blockly),r.Blockly.PHP=r.php.phpGenerator)})(e,function(e){var t=e.__namespace__,n=function(e,t){var n=0,r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e));do{var i=t.valueToCode(e,`IF`+n,l.NONE)||`false`,a=t.statementToCode(e,`DO`+n);t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=(n>0?` else `:``)+`if (`+i+`) {
1877
+ `+a+`}`,n++}while(e.getInput(`IF`+n));return(e.getInput(`ELSE`)||t.STATEMENT_SUFFIX)&&(a=e.getInput(`ELSE`)?t.statementToCode(e,`ELSE`):``,t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=` else {
1878
+ `+a+`}`),r+`
1879
+ `},r=function(e,n){var r=e.getField(`TIMES`)?String(Number(e.getFieldValue(`TIMES`))):n.valueToCode(e,`TIMES`,l.ASSIGNMENT)||`0`,i=n.statementToCode(e,`DO`);i=n.addLoopTrap(i,e),e=``;var a=n.nameDB_.getDistinctName(`count`,t.P.VARIABLE),o=r;return r.match(/^\w+$/)||t.df(r)||(o=n.nameDB_.getDistinctName(`repeat_end`,t.P.VARIABLE),e+=o+` = `+r+`;
1880
+ `),e+(`for (`+a+` = 0; `+a+` < `+o+`; `+a+`++) {
1881
+ `+i+`}
1882
+ `)},i=function(e,t){var n=e.getFieldValue(`OP`);if(n===`NEG`)return e=t.valueToCode(e,`NUM`,l.UNARY_NEGATION)||`0`,e[0]===`-`&&(e=` `+e),[`-`+e,l.UNARY_NEGATION];switch(e=n===`SIN`||n===`COS`||n===`TAN`?t.valueToCode(e,`NUM`,l.DIVISION)||`0`:t.valueToCode(e,`NUM`,l.NONE)||`0`,n){case`ABS`:var r=`abs(`+e+`)`;break;case`ROOT`:r=`sqrt(`+e+`)`;break;case`LN`:r=`log(`+e+`)`;break;case`EXP`:r=`exp(`+e+`)`;break;case`POW10`:r=`pow(10,`+e+`)`;break;case`ROUND`:r=`round(`+e+`)`;break;case`ROUNDUP`:r=`ceil(`+e+`)`;break;case`ROUNDDOWN`:r=`floor(`+e+`)`;break;case`SIN`:r=`sin(`+e+` / 180 * pi())`;break;case`COS`:r=`cos(`+e+` / 180 * pi())`;break;case`TAN`:r=`tan(`+e+` / 180 * pi())`}if(r)return[r,l.FUNCTION_CALL];switch(n){case`LOG10`:r=`log(`+e+`) / log(10)`;break;case`ASIN`:r=`asin(`+e+`) / pi() * 180`;break;case`ACOS`:r=`acos(`+e+`) / pi() * 180`;break;case`ATAN`:r=`atan(`+e+`) / pi() * 180`;break;default:throw Error(`Unknown math operator: `+n)}return[r,l.DIVISION]},a=function(e,n){var r=[],i=e.workspace,a=t.Ad(i)||[];for(var o of a)a=o.getName(),e.getVarModels().includes(o)||r.push(n.getVariableName(a));for(i=t.Bd(i),o=0;o<i.length;o++)r.push(n.nameDB_.getName(i[o],t.P.DEVELOPER_VARIABLE));i=r.length?n.INDENT+`global `+r.join(`, `)+`;
1883
+ `:``,r=n.getProcedureName(e.getFieldValue(`NAME`)),o=``,n.STATEMENT_PREFIX&&(o+=n.injectId(n.STATEMENT_PREFIX,e)),n.STATEMENT_SUFFIX&&(o+=n.injectId(n.STATEMENT_SUFFIX,e)),o&&=n.prefixLines(o,n.INDENT),a=``,n.INFINITE_LOOP_TRAP&&(a=n.prefixLines(n.injectId(n.INFINITE_LOOP_TRAP,e),n.INDENT));var s=``;e.getInput(`STACK`)&&(s=n.statementToCode(e,`STACK`));var c=``;e.getInput(`RETURN`)&&(c=n.valueToCode(e,`RETURN`,l.NONE)||``);var u=``;s&&c&&(u=o),c&&=n.INDENT+`return `+c+`;
1884
+ `;var d=[],f=e.getVarModels();for(let e=0;e<f.length;e++)d[e]=n.getVariableName(f[e].getId());return i=`function `+r+`(`+d.join(`, `)+`) {
1885
+ `+i+o+a+s+u+c+`}`,i=n.scrub_(e,i),n.definitions_[`%`+r]=i,null},o=function(e,t){return t=`readline(`+(e.getField(`TEXT`)?t.quote_(e.getFieldValue(`TEXT`)):t.valueToCode(e,`TEXT`,l.NONE)||`''`)+`)`,e.getFieldValue(`TYPE`)===`NUMBER`&&(t=`floatval(`+t+`)`),[t,l.FUNCTION_CALL]},s=function(e,t){return[t.getVariableName(e.getFieldValue(`VAR`)),l.ATOMIC]},c=function(e,t){var n=t.valueToCode(e,`VALUE`,l.ASSIGNMENT)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` = `+n+`;
1886
+ `},l,u=l||={};u[u.ATOMIC=0]=`ATOMIC`,u[u.CLONE=1]=`CLONE`,u[u.NEW=1]=`NEW`,u[u.MEMBER=2.1]=`MEMBER`,u[u.FUNCTION_CALL=2.2]=`FUNCTION_CALL`,u[u.POWER=3]=`POWER`,u[u.INCREMENT=4]=`INCREMENT`,u[u.DECREMENT=4]=`DECREMENT`,u[u.BITWISE_NOT=4]=`BITWISE_NOT`,u[u.CAST=4]=`CAST`,u[u.SUPPRESS_ERROR=4]=`SUPPRESS_ERROR`,u[u.INSTANCEOF=5]=`INSTANCEOF`,u[u.LOGICAL_NOT=6]=`LOGICAL_NOT`,u[u.UNARY_PLUS=7.1]=`UNARY_PLUS`,u[u.UNARY_NEGATION=7.2]=`UNARY_NEGATION`,u[u.MULTIPLICATION=8.1]=`MULTIPLICATION`,u[u.DIVISION=8.2]=`DIVISION`,u[u.MODULUS=8.3]=`MODULUS`,u[u.ADDITION=9.1]=`ADDITION`,u[u.SUBTRACTION=9.2]=`SUBTRACTION`,u[u.STRING_CONCAT=9.3]=`STRING_CONCAT`,u[u.BITWISE_SHIFT=10]=`BITWISE_SHIFT`,u[u.RELATIONAL=11]=`RELATIONAL`,u[u.EQUALITY=12]=`EQUALITY`,u[u.REFERENCE=13]=`REFERENCE`,u[u.BITWISE_AND=13]=`BITWISE_AND`,u[u.BITWISE_XOR=14]=`BITWISE_XOR`,u[u.BITWISE_OR=15]=`BITWISE_OR`,u[u.LOGICAL_AND=16]=`LOGICAL_AND`,u[u.LOGICAL_OR=17]=`LOGICAL_OR`,u[u.IF_NULL=18]=`IF_NULL`,u[u.CONDITIONAL=19]=`CONDITIONAL`,u[u.ASSIGNMENT=20]=`ASSIGNMENT`,u[u.LOGICAL_AND_WEAK=21]=`LOGICAL_AND_WEAK`,u[u.LOGICAL_XOR=22]=`LOGICAL_XOR`,u[u.LOGICAL_OR_WEAK=23]=`LOGICAL_OR_WEAK`,u[u.NONE=99]=`NONE`;var d=class extends t.Ip{constructor(e=`PHP`){super(e),this.ORDER_OVERRIDES=[[l.MEMBER,l.FUNCTION_CALL],[l.MEMBER,l.MEMBER],[l.LOGICAL_NOT,l.LOGICAL_NOT],[l.MULTIPLICATION,l.MULTIPLICATION],[l.ADDITION,l.ADDITION],[l.LOGICAL_AND,l.LOGICAL_AND],[l.LOGICAL_OR,l.LOGICAL_OR]],this.isInitialized=!1;for(let t in l)e=l[t],typeof e!=`string`&&(this[`ORDER_`+t]=e);this.addReservedWords(`__halt_compiler,abstract,and,array,as,break,callable,case,catch,class,clone,const,continue,declare,default,die,do,echo,else,elseif,empty,enddeclare,endfor,endforeach,endif,endswitch,endwhile,eval,exit,extends,final,for,foreach,function,global,goto,if,implements,include,include_once,instanceof,insteadof,interface,isset,list,namespace,new,or,print,private,protected,public,require,require_once,return,static,switch,throw,trait,try,unset,use,var,while,xor,PHP_VERSION,PHP_MAJOR_VERSION,PHP_MINOR_VERSION,PHP_RELEASE_VERSION,PHP_VERSION_ID,PHP_EXTRA_VERSION,PHP_ZTS,PHP_DEBUG,PHP_MAXPATHLEN,PHP_OS,PHP_SAPI,PHP_EOL,PHP_INT_MAX,PHP_INT_SIZE,DEFAULT_INCLUDE_PATH,PEAR_INSTALL_DIR,PEAR_EXTENSION_DIR,PHP_EXTENSION_DIR,PHP_PREFIX,PHP_BINDIR,PHP_BINARY,PHP_MANDIR,PHP_LIBDIR,PHP_DATADIR,PHP_SYSCONFDIR,PHP_LOCALSTATEDIR,PHP_CONFIG_FILE_PATH,PHP_CONFIG_FILE_SCAN_DIR,PHP_SHLIB_SUFFIX,E_ERROR,E_WARNING,E_PARSE,E_NOTICE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,E_USER_ERROR,E_USER_WARNING,E_USER_NOTICE,E_DEPRECATED,E_USER_DEPRECATED,E_ALL,E_STRICT,__COMPILER_HALT_OFFSET__,TRUE,FALSE,NULL,__CLASS__,__DIR__,__FILE__,__FUNCTION__,__LINE__,__METHOD__,__NAMESPACE__,__TRAIT__`)}init(e){super.init(e),this.nameDB_?this.nameDB_.reset():this.nameDB_=new t.aj(this.RESERVED_WORDS_,`$`),this.nameDB_.setVariableMap(e.getVariableMap()),this.nameDB_.populateVariables(e),this.nameDB_.populateProcedures(e),this.isInitialized=!0}finish(e){var t=Object.values(this.definitions_);return e=super.finish(e),this.isInitialized=!1,this.nameDB_.reset(),t.join(`
1887
+
1888
+ `)+`
1889
+
1890
+
1891
+ `+e}scrubNakedValue(e){return e+`;
1892
+ `}quote_(e){return e=e.replace(/\\/g,`\\\\`).replace(/\n/g,`\\
1893
+ `).replace(/'/g,`\\'`),`'`+e+`'`}multiline_quote_(e){return e.split(/\n/g).map(this.quote_).join(` . "\\n" .
1894
+ `)}scrub_(e,n,r=!1){var i=``;if(!e.outputConnection||!e.outputConnection.targetConnection){var a=e.getCommentText();a&&(a=t.cf(a,this.COMMENT_WRAP-3),i+=this.prefixLines(a,`// `)+`
1895
+ `);for(let n=0;n<e.inputList.length;n++)e.inputList[n].type===t.he.VALUE&&(a=e.inputList[n].connection.targetBlock())&&(a=this.allNestedComments(a))&&(i+=this.prefixLines(a,`// `))}return e=e.nextConnection&&e.nextConnection.targetBlock(),r=r?``:this.blockToCode(e),i+n+r}getAdjusted(e,n,r=0,i=!1,a=l.NONE){e.workspace.options.oneBasedIndex&&r--;var o=e.workspace.options.oneBasedIndex?`1`:`0`,s=a;return r>0?s=l.ADDITION:r<0?s=l.SUBTRACTION:i&&(s=l.UNARY_NEGATION),e=this.valueToCode(e,n,s)||o,r===0&&!i?e:t.df(e)?(e=String(Number(e)+r),i&&(e=String(-Number(e))),e):(r>0?e=`${e} + ${r}`:r<0&&(e=`${e} - ${-r}`),i&&(e=r?`-(${e})`:`-${e}`),Math.floor(a)>=Math.floor(s)&&(e=`(${e})`),e)}},f={};f.controls_if=n,f.controls_ifelse=n,f.logic_boolean=function(e){return[e.getFieldValue(`BOOL`)===`TRUE`?`true`:`false`,l.ATOMIC]},f.logic_compare=function(e,t){var n={EQ:`==`,NEQ:`!=`,LT:`<`,LTE:`<=`,GT:`>`,GTE:`>=`}[e.getFieldValue(`OP`)],r=n===`==`||n===`!=`?l.EQUALITY:l.RELATIONAL,i=t.valueToCode(e,`A`,r)||`0`;return e=t.valueToCode(e,`B`,r)||`0`,[i+` `+n+` `+e,r]},f.logic_negate=function(e,t){var n=l.LOGICAL_NOT;return[`!`+(t.valueToCode(e,`BOOL`,n)||`true`),n]},f.logic_null=function(){return[`null`,l.ATOMIC]},f.logic_operation=function(e,t){var n=e.getFieldValue(`OP`)===`AND`?`&&`:`||`,r=n===`&&`?l.LOGICAL_AND:l.LOGICAL_OR,i=t.valueToCode(e,`A`,r);return e=t.valueToCode(e,`B`,r),i||e?(t=n===`&&`?`true`:`false`,i||=t,e||=t):e=i=`false`,[i+` `+n+` `+e,r]},f.logic_ternary=function(e,t){var n=t.valueToCode(e,`IF`,l.CONDITIONAL)||`false`,r=t.valueToCode(e,`THEN`,l.CONDITIONAL)||`null`;return e=t.valueToCode(e,`ELSE`,l.CONDITIONAL)||`null`,[n+` ? `+r+` : `+e,l.CONDITIONAL]};var p={controls_flow_statements:function(e,t){var n=``;if(t.STATEMENT_PREFIX&&(n+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(n+=t.injectId(t.STATEMENT_SUFFIX,e)),t.STATEMENT_PREFIX){let r=e.getSurroundLoop();r&&!r.suppressPrefixSuffix&&(n+=t.injectId(t.STATEMENT_PREFIX,r))}switch(e.getFieldValue(`FLOW`)){case`BREAK`:return n+`break;
1896
+ `;case`CONTINUE`:return n+`continue;
1897
+ `}throw Error(`Unknown flow statement.`)},controls_for:function(e,n){var r=n.getVariableName(e.getFieldValue(`VAR`)),i=n.valueToCode(e,`FROM`,l.ASSIGNMENT)||`0`,a=n.valueToCode(e,`TO`,l.ASSIGNMENT)||`0`,o=n.valueToCode(e,`BY`,l.ASSIGNMENT)||`1`,s=n.statementToCode(e,`DO`);if(s=n.addLoopTrap(s,e),t.df(i)&&t.df(a)&&t.df(o))n=Number(i)<=Number(a),e=`for (`+r+` = `+i+`; `+r+(n?` <= `:` >= `)+a+`; `+r,r=Math.abs(Number(o)),e=r===1?e+(n?`++`:`--`):e+((n?` += `:` -= `)+r),e+=`) {
1898
+ `+s+`}
1899
+ `;else{e=``;let c=i;i.match(/^\w+$/)||t.df(i)||(c=n.nameDB_.getDistinctName(r+`_start`,t.P.VARIABLE),e+=c+` = `+i+`;
1900
+ `),i=a,a.match(/^\w+$/)||t.df(a)||(i=n.nameDB_.getDistinctName(r+`_end`,t.P.VARIABLE),e+=i+` = `+a+`;
1901
+ `),a=n.nameDB_.getDistinctName(r+`_inc`,t.P.VARIABLE),e+=a+` = `,e=t.df(o)?e+(Math.abs(Number(o))+`;
1902
+ `):e+(`abs(`+o+`);
1903
+ `),e+=`if (`+c+` > `+i+`) {
1904
+ `,e+=n.INDENT+a+` = -`+a+`;
1905
+ `,e=e+`}
1906
+ for (`+(r+` = `+c+`; `+a+` >= 0 ? `+r+` <= `+i+` : `+r+` >= `+i+`; `+r+` += `+a+`) {
1907
+ `+s+`}
1908
+ `)}return e},controls_forEach:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`)),r=t.valueToCode(e,`LIST`,l.ASSIGNMENT)||`[]`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e),`foreach (`+r+` as `+n+`) {
1909
+ `+i+`}
1910
+ `}};p.controls_repeat=r,p.controls_repeat_ext=r,p.controls_whileUntil=function(e,t){var n=e.getFieldValue(`MODE`)===`UNTIL`,r=t.valueToCode(e,`BOOL`,n?l.LOGICAL_NOT:l.NONE)||`false`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e),n&&(r=`!`+r),`while (`+r+`) {
1911
+ `+i+`}
1912
+ `};var m={math_arithmetic:function(e,t){var n={ADD:[` + `,l.ADDITION],MINUS:[` - `,l.SUBTRACTION],MULTIPLY:[` * `,l.MULTIPLICATION],DIVIDE:[` / `,l.DIVISION],POWER:[` ** `,l.POWER]}[e.getFieldValue(`OP`)],r=n[0];n=n[1];var i=t.valueToCode(e,`A`,n)||`0`;return e=t.valueToCode(e,`B`,n)||`0`,[i+r+e,n]},math_atan2:function(e,t){var n=t.valueToCode(e,`X`,l.NONE)||`0`;return[`atan2(`+(t.valueToCode(e,`Y`,l.NONE)||`0`)+`, `+n+`) / pi() * 180`,l.DIVISION]},math_change:function(e,t){var n=t.valueToCode(e,`DELTA`,l.ADDITION)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` += `+n+`;
1913
+ `},math_constant:function(e){return{PI:[`M_PI`,l.ATOMIC],E:[`M_E`,l.ATOMIC],GOLDEN_RATIO:[`(1 + sqrt(5)) / 2`,l.DIVISION],SQRT2:[`M_SQRT2`,l.ATOMIC],SQRT1_2:[`M_SQRT1_2`,l.ATOMIC],INFINITY:[`INF`,l.ATOMIC]}[e.getFieldValue(`CONSTANT`)]},math_constrain:function(e,t){var n=t.valueToCode(e,`VALUE`,l.NONE)||`0`,r=t.valueToCode(e,`LOW`,l.NONE)||`0`;return e=t.valueToCode(e,`HIGH`,l.NONE)||`Infinity`,[`min(max(`+n+`, `+r+`), `+e+`)`,l.FUNCTION_CALL]},math_modulo:function(e,t){var n=t.valueToCode(e,`DIVIDEND`,l.MODULUS)||`0`;return e=t.valueToCode(e,`DIVISOR`,l.MODULUS)||`0`,[n+` % `+e,l.MODULUS]},math_number:function(e){return e=Number(e.getFieldValue(`NUM`)),e===1/0?[`INF`,l.ATOMIC]:e===-1/0?[`-INF`,l.UNARY_NEGATION]:[String(e),e>=0?l.ATOMIC:l.UNARY_NEGATION]},math_number_property:function(e,t){var n={EVEN:[``,` % 2 == 0`,l.MODULUS,l.EQUALITY],ODD:[``,` % 2 == 1`,l.MODULUS,l.EQUALITY],WHOLE:[`is_int(`,`)`,l.NONE,l.FUNCTION_CALL],POSITIVE:[``,` > 0`,l.RELATIONAL,l.RELATIONAL],NEGATIVE:[``,` < 0`,l.RELATIONAL,l.RELATIONAL],DIVISIBLE_BY:[null,null,l.MODULUS,l.EQUALITY],PRIME:[null,null,l.NONE,l.FUNCTION_CALL]},r=e.getFieldValue(`PROPERTY`),[i,a,o,s]=n[r];if(n=t.valueToCode(e,`NUMBER_TO_CHECK`,o)||`0`,r===`PRIME`)e=t.provideFunction_(`math_isPrime`,`
1914
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($n) {
1915
+ // https://en.wikipedia.org/wiki/Primality_test#Naive_methods
1916
+ if ($n == 2 || $n == 3) {
1917
+ return true;
1918
+ }
1919
+ // False if n is NaN, negative, is 1, or not whole.
1920
+ // And false if n is divisible by 2 or 3.
1921
+ if (!is_numeric($n) || $n <= 1 || $n % 1 != 0 || $n % 2 == 0 || $n % 3 == 0) {
1922
+ return false;
1923
+ }
1924
+ // Check all the numbers of form 6k +/- 1, up to sqrt(n).
1925
+ for ($x = 6; $x <= sqrt($n) + 1; $x += 6) {
1926
+ if ($n % ($x - 1) == 0 || $n % ($x + 1) == 0) {
1927
+ return false;
1928
+ }
1929
+ }
1930
+ return true;
1931
+ }
1932
+ `)+`(`+n+`)`;else if(r===`DIVISIBLE_BY`){if(e=t.valueToCode(e,`DIVISOR`,l.MODULUS)||`0`,e===`0`)return[`false`,l.ATOMIC];e=n+` % `+e+` == 0`}else e=i+n+a;return[e,s]},math_on_list:function(e,t){var n=e.getFieldValue(`OP`);switch(n){case`SUM`:e=t.valueToCode(e,`LIST`,l.FUNCTION_CALL)||`array()`,e=`array_sum(`+e+`)`;break;case`MIN`:e=t.valueToCode(e,`LIST`,l.FUNCTION_CALL)||`array()`,e=`min(`+e+`)`;break;case`MAX`:e=t.valueToCode(e,`LIST`,l.FUNCTION_CALL)||`array()`,e=`max(`+e+`)`;break;case`AVERAGE`:n=t.provideFunction_(`math_mean`,`
1933
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($myList) {
1934
+ return array_sum($myList) / count($myList);
1935
+ }
1936
+ `),e=t.valueToCode(e,`LIST`,l.NONE)||`array()`,e=n+`(`+e+`)`;break;case`MEDIAN`:n=t.provideFunction_(`math_median`,`
1937
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($arr) {
1938
+ sort($arr,SORT_NUMERIC);
1939
+ return (count($arr) % 2) ? $arr[floor(count($arr) / 2)] :
1940
+ ($arr[floor(count($arr) / 2)] + $arr[floor(count($arr) / 2) - 1]) / 2;
1941
+ }
1942
+ `),e=t.valueToCode(e,`LIST`,l.NONE)||`[]`,e=n+`(`+e+`)`;break;case`MODE`:n=t.provideFunction_(`math_modes`,`
1943
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($values) {
1944
+ if (empty($values)) return array();
1945
+ $counts = array_count_values($values);
1946
+ arsort($counts); // Sort counts in descending order
1947
+ $modes = array_keys($counts, current($counts), true);
1948
+ return $modes;
1949
+ }
1950
+ `),e=t.valueToCode(e,`LIST`,l.NONE)||`[]`,e=n+`(`+e+`)`;break;case`STD_DEV`:n=t.provideFunction_(`math_standard_deviation`,`
1951
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($numbers) {
1952
+ $n = count($numbers);
1953
+ if (!$n) return null;
1954
+ $mean = array_sum($numbers) / count($numbers);
1955
+ foreach($numbers as $key => $num) $devs[$key] = pow($num - $mean, 2);
1956
+ return sqrt(array_sum($devs) / (count($devs) - 1));
1957
+ }
1958
+ `),e=t.valueToCode(e,`LIST`,l.NONE)||`[]`,e=n+`(`+e+`)`;break;case`RANDOM`:n=t.provideFunction_(`math_random_list`,`
1959
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($list) {
1960
+ $x = rand(0, count($list)-1);
1961
+ return $list[$x];
1962
+ }
1963
+ `),e=t.valueToCode(e,`LIST`,l.NONE)||`[]`,e=n+`(`+e+`)`;break;default:throw Error(`Unknown operator: `+n)}return[e,l.FUNCTION_CALL]},math_random_float:function(){return[`(float)rand()/(float)getrandmax()`,l.FUNCTION_CALL]},math_random_int:function(e,t){var n=t.valueToCode(e,`FROM`,l.NONE)||`0`;return e=t.valueToCode(e,`TO`,l.NONE)||`0`,[t.provideFunction_(`math_random_int`,`
1964
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($a, $b) {
1965
+ if ($a > $b) {
1966
+ return rand($b, $a);
1967
+ }
1968
+ return rand($a, $b);
1969
+ }
1970
+ `)+`(`+n+`, `+e+`)`,l.FUNCTION_CALL]}};m.math_round=i,m.math_single=i,m.math_trig=i;var h={procedures_callnoreturn:function(e,t){return t.forBlock.procedures_callreturn(e,t)[0]+`;
1971
+ `},procedures_callreturn:function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=[],i=e.getVarModels();for(let n=0;n<i.length;n++)r[n]=t.valueToCode(e,`ARG`+n,l.NONE)||`null`;return[n+`(`+r.join(`, `)+`)`,l.FUNCTION_CALL]}};h.procedures_defnoreturn=a,h.procedures_defreturn=a,h.procedures_ifreturn=function(e,t){var n=`if (`+(t.valueToCode(e,`CONDITION`,l.NONE)||`false`)+`) {
1972
+ `;return t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_?(e=t.valueToCode(e,`VALUE`,l.NONE)||`null`,n+=t.INDENT+`return `+e+`;
1973
+ `):n+=t.INDENT+`return;
1974
+ `,n+`}
1975
+ `};var g={text:function(e,t){return[t.quote_(e.getFieldValue(`TEXT`)),l.ATOMIC]},text_append:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`));return e=t.valueToCode(e,`TEXT`,l.ASSIGNMENT)||`''`,n+` .= `+e+`;
1976
+ `},text_changeCase:function(e,t){t=t.valueToCode(e,`TEXT`,l.NONE)||`''`;var n;return e.getFieldValue(`CASE`)===`UPPERCASE`?n=`strtoupper(`+t+`)`:e.getFieldValue(`CASE`)===`LOWERCASE`?n=`strtolower(`+t+`)`:e.getFieldValue(`CASE`)===`TITLECASE`&&(n=`ucwords(strtolower(`+t+`))`),[n,l.FUNCTION_CALL]},text_charAt:function(e,t){var n=e.getFieldValue(`WHERE`)||`FROM_START`,r=t.valueToCode(e,`VALUE`,l.NONE)||`''`;switch(n){case`FIRST`:return[`substr(`+r+`, 0, 1)`,l.FUNCTION_CALL];case`LAST`:return[`substr(`+r+`, -1)`,l.FUNCTION_CALL];case`FROM_START`:return e=t.getAdjusted(e,`AT`),[`substr(`+r+`, `+e+`, 1)`,l.FUNCTION_CALL];case`FROM_END`:return e=t.getAdjusted(e,`AT`,1,!0),[`substr(`+r+`, `+e+`, 1)`,l.FUNCTION_CALL];case`RANDOM`:return[t.provideFunction_(`text_random_letter`,`
1977
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($text) {
1978
+ return $text[rand(0, strlen($text) - 1)];
1979
+ }
1980
+ `)+`(`+r+`)`,l.FUNCTION_CALL]}throw Error(`Unhandled option (text_charAt).`)},text_count:function(e,t){var n=t.valueToCode(e,`TEXT`,l.NONE)||`''`;return e=t.valueToCode(e,`SUB`,l.NONE)||`''`,[`strlen(`+e+`) === 0 ? strlen(`+n+`) + 1 : substr_count(`+n+`, `+e+`)`,l.CONDITIONAL]},text_getSubstring:function(e,t){var n=e.getFieldValue(`WHERE1`),r=e.getFieldValue(`WHERE2`),i=t.valueToCode(e,`STRING`,l.NONE)||`''`;if(n===`FIRST`&&r===`LAST`)return[i,l.NONE];var a=t.getAdjusted(e,`AT1`);return e=t.getAdjusted(e,`AT2`),[t.provideFunction_(`text_get_substring`,`
1981
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($text, $where1, $at1, $where2, $at2) {
1982
+ if ($where1 == 'FROM_END') {
1983
+ $at1 = strlen($text) - 1 - $at1;
1984
+ } else if ($where1 == 'FIRST') {
1985
+ $at1 = 0;
1986
+ } else if ($where1 != 'FROM_START') {
1987
+ throw new Exception('Unhandled option (text_get_substring).');
1988
+ }
1989
+ $length = 0;
1990
+ if ($where2 == 'FROM_START') {
1991
+ $length = $at2 - $at1 + 1;
1992
+ } else if ($where2 == 'FROM_END') {
1993
+ $length = strlen($text) - $at1 - $at2;
1994
+ } else if ($where2 == 'LAST') {
1995
+ $length = strlen($text) - $at1;
1996
+ } else {
1997
+ throw new Exception('Unhandled option (text_get_substring).');
1998
+ }
1999
+ return substr($text, $at1, $length);
2000
+ }
2001
+ `)+`(`+i+`, '`+n+`', `+a+`, '`+r+`', `+e+`)`,l.FUNCTION_CALL]},text_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`strpos`:`strrpos`,r=t.valueToCode(e,`FIND`,l.NONE)||`''`,i=t.valueToCode(e,`VALUE`,l.NONE)||`''`,a=` -1`,o=``;return e.workspace.options.oneBasedIndex&&(a=` 0`,o=` + 1`),[t.provideFunction_(e.getFieldValue(`END`)===`FIRST`?`text_indexOf`:`text_lastIndexOf`,`
2002
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($text, $search) {
2003
+ $pos = ${n}($text, $search);
2004
+ return $pos === false ? ${a} : $pos${o};
2005
+ }
2006
+ `)+`(`+i+`, `+r+`)`,l.FUNCTION_CALL]},text_isEmpty:function(e,t){return[`empty(`+(t.valueToCode(e,`VALUE`,l.NONE)||`''`)+`)`,l.FUNCTION_CALL]},text_join:function(e,t){if(e.itemCount_===0)return[`''`,l.ATOMIC];if(e.itemCount_===1)return[t.valueToCode(e,`ADD0`,l.NONE)||`''`,l.NONE];if(e.itemCount_===2){var n=t.valueToCode(e,`ADD0`,l.STRING_CONCAT)||`''`;return e=t.valueToCode(e,`ADD1`,l.STRING_CONCAT)||`''`,[n+` . `+e,l.STRING_CONCAT]}n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,l.NONE)||`''`;return[`implode('', array(`+n.join(`,`)+`))`,l.FUNCTION_CALL]},text_length:function(e,t){var n=t.provideFunction_(`length`,`
2007
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($value) {
2008
+ if (is_string($value)) {
2009
+ return strlen($value);
2010
+ }
2011
+ return count($value);
2012
+ }
2013
+ `);return e=t.valueToCode(e,`VALUE`,l.NONE)||`''`,[n+`(`+e+`)`,l.FUNCTION_CALL]},text_print:function(e,t){return`print(`+(t.valueToCode(e,`TEXT`,l.NONE)||`''`)+`);
2014
+ `}};g.text_prompt=o,g.text_prompt_ext=o,g.text_replace=function(e,t){var n=t.valueToCode(e,`TEXT`,l.NONE)||`''`,r=t.valueToCode(e,`FROM`,l.NONE)||`''`;return e=t.valueToCode(e,`TO`,l.NONE)||`''`,[`str_replace(`+r+`, `+e+`, `+n+`)`,l.FUNCTION_CALL]},g.text_reverse=function(e,t){return[`strrev(`+(t.valueToCode(e,`TEXT`,l.NONE)||`''`)+`)`,l.FUNCTION_CALL]},g.text_trim=function(e,t){var n={LEFT:`ltrim`,RIGHT:`rtrim`,BOTH:`trim`}[e.getFieldValue(`MODE`)];return e=t.valueToCode(e,`TEXT`,l.NONE)||`''`,[n+`(`+e+`)`,l.FUNCTION_CALL]};var _={};_.variables_get=s,_.variables_set=c;var v={};v.variables_get_dynamic=s,v.variables_set_dynamic=c;var ee=new d,y=Object.assign({},{lists_create_empty:function(){return[`array()`,l.FUNCTION_CALL]},lists_create_with:function(e,t){var n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,l.NONE)||`null`;return[`array(`+n.join(`, `)+`)`,l.FUNCTION_CALL]},lists_getIndex:function(e,t){var n=e.getFieldValue(`MODE`)||`GET`;switch(e.getFieldValue(`WHERE`)||`FROM_START`){case`FIRST`:if(n===`GET`)return[(t.valueToCode(e,`VALUE`,l.MEMBER)||`array()`)+`[0]`,l.MEMBER];if(n===`GET_REMOVE`)return[`array_shift(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`)`,l.FUNCTION_CALL];if(n===`REMOVE`)return`array_shift(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`);
2015
+ `;break;case`LAST`:if(n===`GET`)return[`end(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`)`,l.FUNCTION_CALL];if(n===`GET_REMOVE`)return[`array_pop(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`)`,l.FUNCTION_CALL];if(n===`REMOVE`)return`array_pop(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`);
2016
+ `;break;case`FROM_START`:var r=t.getAdjusted(e,`AT`);if(n===`GET`)return[(t.valueToCode(e,`VALUE`,l.MEMBER)||`array()`)+`[`+r+`]`,l.MEMBER];if(n===`GET_REMOVE`)return[`array_splice(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`, `+r+`, 1)[0]`,l.FUNCTION_CALL];if(n===`REMOVE`)return`array_splice(`+(t.valueToCode(e,`VALUE`,l.NONE)||`array()`)+`, `+r+`, 1);
2017
+ `;break;case`FROM_END`:if(n===`GET`)return n=t.valueToCode(e,`VALUE`,l.NONE)||`array()`,t=t.getAdjusted(e,`AT`,1,!0),[`array_slice(`+n+`, `+t+`, 1)[0]`,l.FUNCTION_CALL];if(n===`GET_REMOVE`||n===`REMOVE`){if(r=t.valueToCode(e,`VALUE`,l.NONE)||`array()`,t=t.getAdjusted(e,`AT`,1,!1,l.SUBTRACTION),t=`array_splice(`+r+`, count(`+r+`) - `+t+`, 1)[0]`,n===`GET_REMOVE`)return[t,l.FUNCTION_CALL];if(n===`REMOVE`)return t+`;
2018
+ `}break;case`RANDOM`:if(e=t.valueToCode(e,`VALUE`,l.NONE)||`array()`,n===`GET`)return[t.provideFunction_(`lists_get_random_item`,`
2019
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($list) {
2020
+ return $list[rand(0,count($list)-1)];
2021
+ }
2022
+ `)+`(`+e+`)`,l.FUNCTION_CALL];if(n===`GET_REMOVE`)return[t.provideFunction_(`lists_get_remove_random_item`,`
2023
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(&$list) {
2024
+ $x = rand(0,count($list)-1);
2025
+ unset($list[$x]);
2026
+ return array_values($list);
2027
+ }
2028
+ `)+`(`+e+`)`,l.FUNCTION_CALL];if(n===`REMOVE`)return t.provideFunction_(`lists_remove_random_item`,`
2029
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}(&$list) {
2030
+ unset($list[rand(0,count($list)-1)]);
2031
+ }
2032
+ `)+`(`+e+`);
2033
+ `}throw Error(`Unhandled combination (lists_getIndex).`)},lists_getSublist:function(e,n){var r=n.valueToCode(e,`LIST`,l.NONE)||`array()`,i=e.getFieldValue(`WHERE1`),a=e.getFieldValue(`WHERE2`);if(i!==`FIRST`||a!==`LAST`)if(r.match(/^\$\w+$/)||i!==`FROM_END`&&a===`FROM_START`){switch(i){case`FROM_START`:i=n.getAdjusted(e,`AT1`);break;case`FROM_END`:i=n.getAdjusted(e,`AT1`,1,!1,l.SUBTRACTION),i=`count(`+r+`) - `+i;break;case`FIRST`:i=`0`;break;default:throw Error(`Unhandled option (lists_getSublist).`)}switch(a){case`FROM_START`:n=n.getAdjusted(e,`AT2`,0,!1,l.SUBTRACTION),n+=` - `,n=t.df(String(i))||String(i).match(/^\(.+\)$/)?n+i:n+(`(`+i+`)`),n+=` + 1`;break;case`FROM_END`:n=n.getAdjusted(e,`AT2`,0,!1,l.SUBTRACTION),n=`count(`+r+`) - `+n+` - `,n=t.df(String(i))||String(i).match(/^\(.+\)$/)?n+i:n+(`(`+i+`)`);break;case`LAST`:n=`count(`+r+`) - `,n=t.df(String(i))||String(i).match(/^\(.+\)$/)?n+i:n+(`(`+i+`)`);break;default:throw Error(`Unhandled option (lists_getSublist).`)}r=`array_slice(`+r+`, `+i+`, `+n+`)`}else{let t=n.getAdjusted(e,`AT1`);e=n.getAdjusted(e,`AT2`),r=n.provideFunction_(`lists_get_sublist`,`
2034
+ function ${n.FUNCTION_NAME_PLACEHOLDER_}($list, $where1, $at1, $where2, $at2) {
2035
+ if ($where1 == 'FROM_END') {
2036
+ $at1 = count($list) - 1 - $at1;
2037
+ } else if ($where1 == 'FIRST') {
2038
+ $at1 = 0;
2039
+ } else if ($where1 != 'FROM_START') {
2040
+ throw new Exception('Unhandled option (lists_get_sublist).');
2041
+ }
2042
+ $length = 0;
2043
+ if ($where2 == 'FROM_START') {
2044
+ $length = $at2 - $at1 + 1;
2045
+ } else if ($where2 == 'FROM_END') {
2046
+ $length = count($list) - $at1 - $at2;
2047
+ } else if ($where2 == 'LAST') {
2048
+ $length = count($list) - $at1;
2049
+ } else {
2050
+ throw new Exception('Unhandled option (lists_get_sublist).');
2051
+ }
2052
+ return array_slice($list, $at1, $length);
2053
+ }
2054
+ `)+`(`+r+`, '`+i+`', `+t+`, '`+a+`', `+e+`)`}return[r,l.FUNCTION_CALL]},lists_indexOf:function(e,t){var n=t.valueToCode(e,`FIND`,l.NONE)||`''`,r=t.valueToCode(e,`VALUE`,l.MEMBER)||`[]`,i=` -1`,a=``;return e.workspace.options.oneBasedIndex&&(i=` 0`,a=` + 1`),[(e.getFieldValue(`END`)===`FIRST`?t.provideFunction_(`indexOf`,`
2055
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($haystack, $needle) {
2056
+ for ($index = 0; $index < count($haystack); $index++) {
2057
+ if ($haystack[$index] == $needle) return $index${a};
2058
+ }
2059
+ return ${i};
2060
+ }
2061
+ `):t.provideFunction_(`lastIndexOf`,`
2062
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($haystack, $needle) {
2063
+ $last = ${i};
2064
+ for ($index = 0; $index < count($haystack); $index++) {
2065
+ if ($haystack[$index] == $needle) $last = $index${a};
2066
+ }
2067
+ return $last;
2068
+ }
2069
+ `))+`(`+r+`, `+n+`)`,l.FUNCTION_CALL]},lists_isEmpty:function(e,t){return[`empty(`+(t.valueToCode(e,`VALUE`,l.FUNCTION_CALL)||`array()`)+`)`,l.FUNCTION_CALL]},lists_length:function(e,t){var n=t.provideFunction_(`length`,`
2070
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($value) {
2071
+ if (is_string($value)) {
2072
+ return strlen($value);
2073
+ } else {
2074
+ return count($value);
2075
+ }
2076
+ }
2077
+ `);return e=t.valueToCode(e,`VALUE`,l.NONE)||`''`,[n+`(`+e+`)`,l.FUNCTION_CALL]},lists_repeat:function(e,t){var n=t.provideFunction_(`lists_repeat`,`
2078
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($value, $count) {
2079
+ $array = array();
2080
+ for ($index = 0; $index < $count; $index++) {
2081
+ $array[] = $value;
2082
+ }
2083
+ return $array;
2084
+ }
2085
+ `),r=t.valueToCode(e,`ITEM`,l.NONE)||`null`;return e=t.valueToCode(e,`NUM`,l.NONE)||`0`,[n+`(`+r+`, `+e+`)`,l.FUNCTION_CALL]},lists_reverse:function(e,t){return[`array_reverse(`+(t.valueToCode(e,`LIST`,l.NONE)||`[]`)+`)`,l.FUNCTION_CALL]},lists_setIndex:function(e,n){var r=e.getFieldValue(`MODE`)||`GET`,i=e.getFieldValue(`WHERE`)||`FROM_START`,a=n.valueToCode(e,`TO`,l.ASSIGNMENT)||`null`;switch(i){case`FIRST`:if(r===`SET`)return(n.valueToCode(e,`LIST`,l.MEMBER)||`array()`)+`[0] = `+a+`;
2086
+ `;if(r===`INSERT`)return`array_unshift(`+(n.valueToCode(e,`LIST`,l.NONE)||`array()`)+`, `+a+`);
2087
+ `;break;case`LAST`:if(e=n.valueToCode(e,`LIST`,l.NONE)||`array()`,r===`SET`)return n.provideFunction_(`lists_set_last_item`,`
2088
+ function ${n.FUNCTION_NAME_PLACEHOLDER_}(&$list, $value) {
2089
+ $list[count($list) - 1] = $value;
2090
+ }
2091
+ `)+`(`+e+`, `+a+`);
2092
+ `;if(r===`INSERT`)return`array_push(`+e+`, `+a+`);
2093
+ `;break;case`FROM_START`:if(i=n.getAdjusted(e,`AT`),r===`SET`)return(n.valueToCode(e,`LIST`,l.MEMBER)||`array()`)+`[`+i+`] = `+a+`;
2094
+ `;if(r===`INSERT`)return`array_splice(`+(n.valueToCode(e,`LIST`,l.NONE)||`array()`)+`, `+i+`, 0, `+a+`);
2095
+ `;break;case`FROM_END`:if(i=n.valueToCode(e,`LIST`,l.NONE)||`array()`,e=n.getAdjusted(e,`AT`,1),r===`SET`)return n.provideFunction_(`lists_set_from_end`,`
2096
+ function ${n.FUNCTION_NAME_PLACEHOLDER_}(&$list, $at, $value) {
2097
+ $list[count($list) - $at] = $value;
2098
+ }
2099
+ `)+`(`+i+`, `+e+`, `+a+`);
2100
+ `;if(r===`INSERT`)return n.provideFunction_(`lists_insert_from_end`,`
2101
+ function ${n.FUNCTION_NAME_PLACEHOLDER_}(&$list, $at, $value) {
2102
+ return array_splice($list, count($list) - $at, 0, $value);
2103
+ }
2104
+ `)+`(`+i+`, `+e+`, `+a+`);
2105
+ `;break;case`RANDOM`:if(e=n.valueToCode(e,`LIST`,l.REFERENCE)||`array()`,e.match(/^\$\w+$/))i=``;else{i=n.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE);var o=i+` = &`+e+`;
2106
+ `;e=i,i=o}if(n=n.nameDB_.getDistinctName(`tmp_x`,t.P.VARIABLE),i+=n+` = rand(0, count(`+e+`)-1);
2107
+ `,r===`SET`)return i+(e+`[`+n+`] = `+a+`;
2108
+ `);if(r===`INSERT`)return i+(`array_splice(`+e+`, `+n+`, 0, `+a+`);
2109
+ `)}throw Error(`Unhandled combination (lists_setIndex).`)},lists_sort:function(e,t){var n=t.valueToCode(e,`LIST`,l.NONE)||`array()`,r=e.getFieldValue(`DIRECTION`)===`1`?1:-1;return e=e.getFieldValue(`TYPE`),[t.provideFunction_(`lists_sort`,`
2110
+ function ${t.FUNCTION_NAME_PLACEHOLDER_}($list, $type, $direction) {
2111
+ $sortCmpFuncs = array(
2112
+ 'NUMERIC' => 'strnatcasecmp',
2113
+ 'TEXT' => 'strcmp',
2114
+ 'IGNORE_CASE' => 'strcasecmp'
2115
+ );
2116
+ $sortCmp = $sortCmpFuncs[$type];
2117
+ $list2 = $list;
2118
+ usort($list2, $sortCmp);
2119
+ if ($direction == -1) {
2120
+ $list2 = array_reverse($list2);
2121
+ }
2122
+ return $list2;
2123
+ }
2124
+ `)+`(`+n+`, "`+e+`", `+r+`)`,l.FUNCTION_CALL]},lists_split:function(e,t){var n=t.valueToCode(e,`INPUT`,l.NONE);if(t=t.valueToCode(e,`DELIM`,l.NONE)||`''`,e=e.getFieldValue(`MODE`),e===`SPLIT`)n||=`''`,e=`explode`;else if(e===`JOIN`)n||=`array()`,e=`implode`;else throw Error(`Unknown mode: `+e);return[e+`(`+t+`, `+n+`)`,l.FUNCTION_CALL]}},f,p,m,h,g,_,v);for(let e in y)ee.forBlock[e]=y[e];var te={};return te.Order=l,te.PhpGenerator=d,te.phpGenerator=ee,t.__chunk_php=te,t.__chunk_php.__namespace__=t,t.__chunk_php})})),wl=t(((e,t)=>{(function(r,i){typeof define==`function`&&define.amd?define([`./blockly_compressed.js`],i):typeof e==`object`?t.exports=i(n()):(r.python=i(r.Blockly),r.Blockly.Python=r.python.pythonGenerator)})(e,function(e){var t=e.__namespace__,n=function(e,t){var n=0,r=``;t.STATEMENT_PREFIX&&(r+=t.injectId(t.STATEMENT_PREFIX,e));do{var i=t.valueToCode(e,`IF`+n,u.NONE)||`False`,a=t.statementToCode(e,`DO`+n)||t.PASS;t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=(n===0?`if `:`elif `)+i+`:
2125
+ `+a,n++}while(e.getInput(`IF`+n));return(e.getInput(`ELSE`)||t.STATEMENT_SUFFIX)&&(a=e.getInput(`ELSE`)&&t.statementToCode(e,`ELSE`)||t.PASS,t.STATEMENT_SUFFIX&&(a=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)+a),r+=`else:
2126
+ `+a),r},r=function(e,n){var r=e.getField(`TIMES`)?String(parseInt(e.getFieldValue(`TIMES`),10)):n.valueToCode(e,`TIMES`,u.NONE)||`0`;r=t.df(r)?parseInt(r,10):`int(`+r+`)`;var i=n.statementToCode(e,`DO`);return i=n.addLoopTrap(i,e)||n.PASS,`for `+n.nameDB_.getDistinctName(`count`,t.P.VARIABLE)+` in range(`+r+`):
2127
+ `+i},i=function(e,t){var n=e.getFieldValue(`OP`);if(n===`NEG`){var r=t.valueToCode(e,`NUM`,u.UNARY_SIGN)||`0`;return[`-`+r,u.UNARY_SIGN]}switch(t.definitions_.import_math=`import math`,e=n===`SIN`||n===`COS`||n===`TAN`?t.valueToCode(e,`NUM`,u.MULTIPLICATIVE)||`0`:t.valueToCode(e,`NUM`,u.NONE)||`0`,n){case`ABS`:r=`math.fabs(`+e+`)`;break;case`ROOT`:r=`math.sqrt(`+e+`)`;break;case`LN`:r=`math.log(`+e+`)`;break;case`LOG10`:r=`math.log10(`+e+`)`;break;case`EXP`:r=`math.exp(`+e+`)`;break;case`POW10`:r=`math.pow(10,`+e+`)`;break;case`ROUND`:r=`round(`+e+`)`;break;case`ROUNDUP`:r=`math.ceil(`+e+`)`;break;case`ROUNDDOWN`:r=`math.floor(`+e+`)`;break;case`SIN`:r=`math.sin(`+e+` / 180.0 * math.pi)`;break;case`COS`:r=`math.cos(`+e+` / 180.0 * math.pi)`;break;case`TAN`:r=`math.tan(`+e+` / 180.0 * math.pi)`}if(r)return[r,u.FUNCTION_CALL];switch(n){case`ASIN`:r=`math.asin(`+e+`) / math.pi * 180`;break;case`ACOS`:r=`math.acos(`+e+`) / math.pi * 180`;break;case`ATAN`:r=`math.atan(`+e+`) / math.pi * 180`;break;default:throw Error(`Unknown math operator: `+n)}return[r,u.MULTIPLICATIVE]},a=function(e,n){var r=[],i=e.workspace,a=t.Ad(i)||[];for(var o of a)a=o.getName(),e.getVarModels().includes(o)||r.push(n.getVariableName(a));for(i=t.Bd(i),o=0;o<i.length;o++)r.push(n.nameDB_.getName(i[o],t.P.DEVELOPER_VARIABLE));i=r.length?n.INDENT+`global `+r.join(`, `)+`
2128
+ `:``,r=n.getProcedureName(e.getFieldValue(`NAME`)),o=``,n.STATEMENT_PREFIX&&(o+=n.injectId(n.STATEMENT_PREFIX,e)),n.STATEMENT_SUFFIX&&(o+=n.injectId(n.STATEMENT_SUFFIX,e)),o&&=n.prefixLines(o,n.INDENT),a=``,n.INFINITE_LOOP_TRAP&&(a=n.prefixLines(n.injectId(n.INFINITE_LOOP_TRAP,e),n.INDENT));var s=``;e.getInput(`STACK`)&&(s=n.statementToCode(e,`STACK`));var c=``;e.getInput(`RETURN`)&&(c=n.valueToCode(e,`RETURN`,u.NONE)||``);var l=``;s&&c&&(l=o),c?c=n.INDENT+`return `+c+`
2129
+ `:s||=n.PASS;var d=[],f=e.getVarModels();for(let e=0;e<f.length;e++)d[e]=n.getVariableName(f[e].getId());return i=`def `+r+`(`+d.join(`, `)+`):
2130
+ `+i+o+a+s+l+c,i=n.scrub_(e,i),n.definitions_[`%`+r]=i,null},o=function(e){return _.test(e)?[e,u.ATOMIC]:[`str(`+e+`)`,u.FUNCTION_CALL]},s=function(e,t){var n=t.provideFunction_(`text_prompt`,`
2131
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(msg):
2132
+ try:
2133
+ return raw_input(msg)
2134
+ except NameError:
2135
+ return input(msg)
2136
+ `);return t=e.getField(`TEXT`)?t.quote_(e.getFieldValue(`TEXT`)):t.valueToCode(e,`TEXT`,u.NONE)||`''`,n=n+`(`+t+`)`,e.getFieldValue(`TYPE`)===`NUMBER`&&(n=`float(`+n+`)`),[n,u.FUNCTION_CALL]},c=function(e,t){return[t.getVariableName(e.getFieldValue(`VAR`)),u.ATOMIC]},l=function(e,t){var n=t.valueToCode(e,`VALUE`,u.NONE)||`0`;return t.getVariableName(e.getFieldValue(`VAR`))+` = `+n+`
2137
+ `},u,d=u||={};d[d.ATOMIC=0]=`ATOMIC`,d[d.COLLECTION=1]=`COLLECTION`,d[d.STRING_CONVERSION=1]=`STRING_CONVERSION`,d[d.MEMBER=2.1]=`MEMBER`,d[d.FUNCTION_CALL=2.2]=`FUNCTION_CALL`,d[d.EXPONENTIATION=3]=`EXPONENTIATION`,d[d.UNARY_SIGN=4]=`UNARY_SIGN`,d[d.BITWISE_NOT=4]=`BITWISE_NOT`,d[d.MULTIPLICATIVE=5]=`MULTIPLICATIVE`,d[d.ADDITIVE=6]=`ADDITIVE`,d[d.BITWISE_SHIFT=7]=`BITWISE_SHIFT`,d[d.BITWISE_AND=8]=`BITWISE_AND`,d[d.BITWISE_XOR=9]=`BITWISE_XOR`,d[d.BITWISE_OR=10]=`BITWISE_OR`,d[d.RELATIONAL=11]=`RELATIONAL`,d[d.LOGICAL_NOT=12]=`LOGICAL_NOT`,d[d.LOGICAL_AND=13]=`LOGICAL_AND`,d[d.LOGICAL_OR=14]=`LOGICAL_OR`,d[d.CONDITIONAL=15]=`CONDITIONAL`,d[d.LAMBDA=16]=`LAMBDA`,d[d.NONE=99]=`NONE`;var f=class extends t.Ip{constructor(e=`Python`){super(e),this.ORDER_OVERRIDES=[[u.FUNCTION_CALL,u.MEMBER],[u.FUNCTION_CALL,u.FUNCTION_CALL],[u.MEMBER,u.MEMBER],[u.MEMBER,u.FUNCTION_CALL],[u.LOGICAL_NOT,u.LOGICAL_NOT],[u.LOGICAL_AND,u.LOGICAL_AND],[u.LOGICAL_OR,u.LOGICAL_OR]],this.PASS=``,this.isInitialized=!1;for(let t in u)e=u[t],typeof e!=`string`&&(this[`ORDER_`+t]=e);this.addReservedWords(`False,None,True,and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,nonlocal,not,or,pass,print,raise,return,try,while,with,yield,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,ArithmeticError,AssertionError,AttributeError,BaseException,BlockingIOError,BrokenPipeError,BufferError,BytesWarning,ChildProcessError,ConnectionAbortedError,ConnectionError,ConnectionRefusedError,ConnectionResetError,DeprecationWarning,EOFError,Ellipsis,EnvironmentError,Exception,FileExistsError,FileNotFoundError,FloatingPointError,FutureWarning,GeneratorExit,IOError,ImportError,ImportWarning,IndentationError,IndexError,InterruptedError,IsADirectoryError,KeyError,KeyboardInterrupt,LookupError,MemoryError,ModuleNotFoundError,NameError,NotADirectoryError,NotImplemented,NotImplementedError,OSError,OverflowError,PendingDeprecationWarning,PermissionError,ProcessLookupError,RecursionError,ReferenceError,ResourceWarning,RuntimeError,RuntimeWarning,StandardError,StopAsyncIteration,StopIteration,SyntaxError,SyntaxWarning,SystemError,SystemExit,TabError,TimeoutError,TypeError,UnboundLocalError,UnicodeDecodeError,UnicodeEncodeError,UnicodeError,UnicodeTranslateError,UnicodeWarning,UserWarning,ValueError,Warning,ZeroDivisionError,_,__build_class__,__debug__,__doc__,__import__,__loader__,__name__,__package__,__spec__,abs,all,any,apply,ascii,basestring,bin,bool,buffer,bytearray,bytes,callable,chr,classmethod,cmp,coerce,compile,complex,copyright,credits,delattr,dict,dir,divmod,enumerate,eval,exec,execfile,exit,file,filter,float,format,frozenset,getattr,globals,hasattr,hash,help,hex,id,input,int,intern,isinstance,issubclass,iter,len,license,list,locals,long,map,max,memoryview,min,next,object,oct,open,ord,pow,print,property,quit,range,raw_input,reduce,reload,repr,reversed,round,set,setattr,slice,sorted,staticmethod,str,sum,super,tuple,type,unichr,unicode,vars,xrange,zip`)}init(e){super.init(e),this.PASS=this.INDENT+`pass
2138
+ `,this.nameDB_?this.nameDB_.reset():this.nameDB_=new t.aj(this.RESERVED_WORDS_),this.nameDB_.setVariableMap(e.getVariableMap()),this.nameDB_.populateVariables(e),this.nameDB_.populateProcedures(e);var n=[],r=t.Bd(e);for(let e=0;e<r.length;e++)n.push(this.nameDB_.getName(r[e],t.aj.DEVELOPER_VARIABLE_TYPE)+` = None`);for(e=t.Ad(e),r=0;r<e.length;r++)n.push(this.getVariableName(e[r].getId())+` = None`);this.definitions_.variables=n.join(`
2139
+ `),this.isInitialized=!0}finish(e){var t=[],n=[];for(let e in this.definitions_){let r=this.definitions_[e];r.match(/^(from\s+\S+\s+)?import\s+\S+/)?t.push(r):n.push(r)}return e=super.finish(e),this.isInitialized=!1,this.nameDB_.reset(),(t.join(`
2140
+ `)+`
2141
+
2142
+ `+n.join(`
2143
+
2144
+ `)).replace(/\n\n+/g,`
2145
+
2146
+ `).replace(/\n*$/,`
2147
+
2148
+
2149
+ `)+e}scrubNakedValue(e){return e+`
2150
+ `}quote_(e){e=e.replace(/\\/g,`\\\\`).replace(/\n/g,`\\
2151
+ `);var t=`'`;return e.includes(`'`)&&(e.includes(`"`)?e=e.replace(/'/g,`\\'`):t=`"`),t+e+t}multiline_quote_(e){return e.split(/\n/g).map(this.quote_).join(` + '\\n' +
2152
+ `)}scrub_(e,n,r=!1){var i=``;if(!e.outputConnection||!e.outputConnection.targetConnection){var a=e.getCommentText();a&&(a=t.cf(a,this.COMMENT_WRAP-3),i+=this.prefixLines(a+`
2153
+ `,`# `));for(let n=0;n<e.inputList.length;n++)e.inputList[n].type===t.he.VALUE&&(a=e.inputList[n].connection.targetBlock())&&(a=this.allNestedComments(a))&&(i+=this.prefixLines(a,`# `))}return e=e.nextConnection&&e.nextConnection.targetBlock(),r=r?``:this.blockToCode(e),i+n+r}getAdjustedInt(e,n,r=0,i=!1){e.workspace.options.oneBasedIndex&&r--;var a=e.workspace.options.oneBasedIndex?`1`:`0`;return e=this.valueToCode(e,n,r?u.ADDITIVE:u.NONE)||a,t.df(e)?(e=parseInt(e,10)+r,i&&(e=-e)):(e=r>0?`int(`+e+` + `+r+`)`:r<0?`int(`+e+` - `+-r+`)`:`int(`+e+`)`,i&&(e=`-`+e)),e}},p={};p.controls_if=n,p.controls_ifelse=n,p.logic_boolean=function(e){return[e.getFieldValue(`BOOL`)===`TRUE`?`True`:`False`,u.ATOMIC]},p.logic_compare=function(e,t){var n={EQ:`==`,NEQ:`!=`,LT:`<`,LTE:`<=`,GT:`>`,GTE:`>=`}[e.getFieldValue(`OP`)],r=u.RELATIONAL,i=t.valueToCode(e,`A`,r)||`0`;return e=t.valueToCode(e,`B`,r)||`0`,[i+` `+n+` `+e,r]},p.logic_negate=function(e,t){return[`not `+(t.valueToCode(e,`BOOL`,u.LOGICAL_NOT)||`True`),u.LOGICAL_NOT]},p.logic_null=function(){return[`None`,u.ATOMIC]},p.logic_operation=function(e,t){var n=e.getFieldValue(`OP`)===`AND`?`and`:`or`,r=n===`and`?u.LOGICAL_AND:u.LOGICAL_OR,i=t.valueToCode(e,`A`,r);return e=t.valueToCode(e,`B`,r),i||e?(t=n===`and`?`True`:`False`,i||=t,e||=t):e=i=`False`,[i+` `+n+` `+e,r]},p.logic_ternary=function(e,t){var n=t.valueToCode(e,`IF`,u.CONDITIONAL)||`False`,r=t.valueToCode(e,`THEN`,u.CONDITIONAL)||`None`;return e=t.valueToCode(e,`ELSE`,u.CONDITIONAL)||`None`,[r+` if `+n+` else `+e,u.CONDITIONAL]};var m={controls_flow_statements:function(e,t){var n=``;if(t.STATEMENT_PREFIX&&(n+=t.injectId(t.STATEMENT_PREFIX,e)),t.STATEMENT_SUFFIX&&(n+=t.injectId(t.STATEMENT_SUFFIX,e)),t.STATEMENT_PREFIX){let r=e.getSurroundLoop();r&&!r.suppressPrefixSuffix&&(n+=t.injectId(t.STATEMENT_PREFIX,r))}switch(e.getFieldValue(`FLOW`)){case`BREAK`:return n+`break
2154
+ `;case`CONTINUE`:return n+`continue
2155
+ `}throw Error(`Unknown flow statement.`)},controls_for:function(e,n){function r(){return n.provideFunction_(`downRange`,`
2156
+ def ${n.FUNCTION_NAME_PLACEHOLDER_}(start, stop, step):
2157
+ while start >= stop:
2158
+ yield start
2159
+ start -= abs(step)
2160
+ `)}function i(){return n.provideFunction_(`upRange`,`
2161
+ def ${n.FUNCTION_NAME_PLACEHOLDER_}(start, stop, step):
2162
+ while start <= stop:
2163
+ yield start
2164
+ start += abs(step)
2165
+ `)}var a=n.getVariableName(e.getFieldValue(`VAR`)),o=n.valueToCode(e,`FROM`,u.NONE)||`0`,s=n.valueToCode(e,`TO`,u.NONE)||`0`,c=n.valueToCode(e,`BY`,u.NONE)||`1`,l=n.statementToCode(e,`DO`);l=n.addLoopTrap(l,e)||n.PASS;var d=``;return t.df(o)&&t.df(s)&&t.df(c)?(o=Number(o),s=Number(s),c=Math.abs(Number(c)),o%1==0&&s%1==0&&c%1==0?(o<=s?(s++,e=o===0&&c===1?s:o+`, `+s,c!==1&&(e+=`, `+c)):(s--,e=o+`, `+s+`, -`+c),e=`range(`+e+`)`):(e=o<s?i():r(),e+=`(`+o+`, `+s+`, `+c+`)`)):(e=function(e,r){return t.df(e)?e=String(Number(e)):e.match(/^\w+$/)||(r=n.nameDB_.getDistinctName(a+r,t.P.VARIABLE),d+=r+` = `+e+`
2166
+ `,e=r),e},o=e(o,`_start`),s=e(s,`_end`),c=e(c,`_inc`),typeof o==`number`&&typeof s==`number`?(e=o<s?i():r(),e+=`(`+o+`, `+s+`, `+c+`)`):e=`(`+o+` <= `+s+`) and `+i()+`(`+o+`, `+s+`, `+c+`) or `+r()+`(`+o+`, `+s+`, `+c+`)`),d+=`for `+a+` in `+e+`:
2167
+ `+l},controls_forEach:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`)),r=t.valueToCode(e,`LIST`,u.RELATIONAL)||`[]`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e)||t.PASS,`for `+n+` in `+r+`:
2168
+ `+i}};m.controls_repeat=r,m.controls_repeat_ext=r,m.controls_whileUntil=function(e,t){var n=e.getFieldValue(`MODE`)===`UNTIL`,r=t.valueToCode(e,`BOOL`,n?u.LOGICAL_NOT:u.NONE)||`False`,i=t.statementToCode(e,`DO`);return i=t.addLoopTrap(i,e)||t.PASS,n&&(r=`not `+r),`while `+r+`:
2169
+ `+i};var h={math_arithmetic:function(e,t){var n={ADD:[` + `,u.ADDITIVE],MINUS:[` - `,u.ADDITIVE],MULTIPLY:[` * `,u.MULTIPLICATIVE],DIVIDE:[` / `,u.MULTIPLICATIVE],POWER:[` ** `,u.EXPONENTIATION]}[e.getFieldValue(`OP`)],r=n[0];n=n[1];var i=t.valueToCode(e,`A`,n)||`0`;return e=t.valueToCode(e,`B`,n)||`0`,[i+r+e,n]},math_atan2:function(e,t){t.definitions_.import_math=`import math`;var n=t.valueToCode(e,`X`,u.NONE)||`0`;return[`math.atan2(`+(t.valueToCode(e,`Y`,u.NONE)||`0`)+`, `+n+`) / math.pi * 180`,u.MULTIPLICATIVE]},math_change:function(e,t){t.definitions_.from_numbers_import_Number=`from numbers import Number`;var n=t.valueToCode(e,`DELTA`,u.ADDITIVE)||`0`;return e=t.getVariableName(e.getFieldValue(`VAR`)),e+` = (`+e+` if isinstance(`+e+`, Number) else 0) + `+n+`
2170
+ `},math_constant:function(e,t){var n={PI:[`math.pi`,u.MEMBER],E:[`math.e`,u.MEMBER],GOLDEN_RATIO:[`(1 + math.sqrt(5)) / 2`,u.MULTIPLICATIVE],SQRT2:[`math.sqrt(2)`,u.MEMBER],SQRT1_2:[`math.sqrt(1.0 / 2)`,u.MEMBER],INFINITY:[`float('inf')`,u.ATOMIC]};return e=e.getFieldValue(`CONSTANT`),e!==`INFINITY`&&(t.definitions_.import_math=`import math`),n[e]},math_constrain:function(e,t){var n=t.valueToCode(e,`VALUE`,u.NONE)||`0`,r=t.valueToCode(e,`LOW`,u.NONE)||`0`;return e=t.valueToCode(e,`HIGH`,u.NONE)||`float('inf')`,[`min(max(`+n+`, `+r+`), `+e+`)`,u.FUNCTION_CALL]},math_modulo:function(e,t){var n=t.valueToCode(e,`DIVIDEND`,u.MULTIPLICATIVE)||`0`;return e=t.valueToCode(e,`DIVISOR`,u.MULTIPLICATIVE)||`0`,[n+` % `+e,u.MULTIPLICATIVE]},math_number:function(e){return e=Number(e.getFieldValue(`NUM`)),e===1/0?[`float("inf")`,u.FUNCTION_CALL]:e===-1/0?[`-float("inf")`,u.UNARY_SIGN]:[String(e),e<0?u.UNARY_SIGN:u.ATOMIC]},math_number_property:function(e,t){var n={EVEN:[` % 2 == 0`,u.MULTIPLICATIVE,u.RELATIONAL],ODD:[` % 2 == 1`,u.MULTIPLICATIVE,u.RELATIONAL],WHOLE:[` % 1 == 0`,u.MULTIPLICATIVE,u.RELATIONAL],POSITIVE:[` > 0`,u.RELATIONAL,u.RELATIONAL],NEGATIVE:[` < 0`,u.RELATIONAL,u.RELATIONAL],DIVISIBLE_BY:[null,u.MULTIPLICATIVE,u.RELATIONAL],PRIME:[null,u.NONE,u.FUNCTION_CALL]},r=e.getFieldValue(`PROPERTY`),[i,a,o]=n[r];if(n=t.valueToCode(e,`NUMBER_TO_CHECK`,a)||`0`,r===`PRIME`)t.definitions_.import_math=`import math`,t.definitions_.from_numbers_import_Number=`from numbers import Number`,e=t.provideFunction_(`math_isPrime`,`
2171
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(n):
2172
+ # https://en.wikipedia.org/wiki/Primality_test#Naive_methods
2173
+ # If n is not a number but a string, try parsing it.
2174
+ if not isinstance(n, Number):
2175
+ try:
2176
+ n = float(n)
2177
+ except:
2178
+ return False
2179
+ if n == 2 or n == 3:
2180
+ return True
2181
+ # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3.
2182
+ if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:
2183
+ return False
2184
+ # Check all the numbers of form 6k +/- 1, up to sqrt(n).
2185
+ for x in range(6, int(math.sqrt(n)) + 2, 6):
2186
+ if n % (x - 1) == 0 or n % (x + 1) == 0:
2187
+ return False
2188
+ return True
2189
+ `)+`(`+n+`)`;else if(r===`DIVISIBLE_BY`){if(e=t.valueToCode(e,`DIVISOR`,u.MULTIPLICATIVE)||`0`,e===`0`)return[`False`,u.ATOMIC];e=n+` % `+e+` == 0`}else e=n+i;return[e,o]},math_on_list:function(e,t){var n=e.getFieldValue(`OP`);switch(e=t.valueToCode(e,`LIST`,u.NONE)||`[]`,n){case`SUM`:t=`sum(`+e+`)`;break;case`MIN`:t=`min(`+e+`)`;break;case`MAX`:t=`max(`+e+`)`;break;case`AVERAGE`:t.definitions_.from_numbers_import_Number=`from numbers import Number`,t=t.provideFunction_(`math_mean`,`
2190
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(myList):
2191
+ localList = [e for e in myList if isinstance(e, Number)]
2192
+ if not localList: return
2193
+ return float(sum(localList)) / len(localList)
2194
+ `)+`(`+e+`)`;break;case`MEDIAN`:t.definitions_.from_numbers_import_Number=`from numbers import Number`,t=t.provideFunction_(`math_median`,`
2195
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(myList):
2196
+ localList = sorted([e for e in myList if isinstance(e, Number)])
2197
+ if not localList: return
2198
+ if len(localList) % 2 == 0:
2199
+ return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0
2200
+ else:
2201
+ return localList[(len(localList) - 1) // 2]
2202
+ `)+`(`+e+`)`;break;case`MODE`:t=t.provideFunction_(`math_modes`,`
2203
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(some_list):
2204
+ modes = []
2205
+ # Using a lists of [item, count] to keep count rather than dict
2206
+ # to avoid "unhashable" errors when the counted item is itself a list or dict.
2207
+ counts = []
2208
+ maxCount = 1
2209
+ for item in some_list:
2210
+ found = False
2211
+ for count in counts:
2212
+ if count[0] == item:
2213
+ count[1] += 1
2214
+ maxCount = max(maxCount, count[1])
2215
+ found = True
2216
+ if not found:
2217
+ counts.append([item, 1])
2218
+ for counted_item, item_count in counts:
2219
+ if item_count == maxCount:
2220
+ modes.append(counted_item)
2221
+ return modes
2222
+ `)+`(`+e+`)`;break;case`STD_DEV`:t.definitions_.import_math=`import math`,t=t.provideFunction_(`math_standard_deviation`,`
2223
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(numbers):
2224
+ n = len(numbers)
2225
+ if n == 0: return
2226
+ mean = float(sum(numbers)) / n
2227
+ variance = sum((x - mean) ** 2 for x in numbers) / n
2228
+ return math.sqrt(variance)
2229
+ `)+`(`+e+`)`;break;case`RANDOM`:t.definitions_.import_random=`import random`,t=`random.choice(`+e+`)`;break;default:throw Error(`Unknown operator: `+n)}return[t,u.FUNCTION_CALL]},math_random_float:function(e,t){return t.definitions_.import_random=`import random`,[`random.random()`,u.FUNCTION_CALL]},math_random_int:function(e,t){t.definitions_.import_random=`import random`;var n=t.valueToCode(e,`FROM`,u.NONE)||`0`;return e=t.valueToCode(e,`TO`,u.NONE)||`0`,[`random.randint(`+n+`, `+e+`)`,u.FUNCTION_CALL]}};h.math_round=i,h.math_single=i,h.math_trig=i;var g={procedures_callnoreturn:function(e,t){return t.forBlock.procedures_callreturn(e,t)[0]+`
2230
+ `},procedures_callreturn:function(e,t){var n=t.getProcedureName(e.getFieldValue(`NAME`)),r=[],i=e.getVarModels();for(let n=0;n<i.length;n++)r[n]=t.valueToCode(e,`ARG`+n,u.NONE)||`None`;return[n+`(`+r.join(`, `)+`)`,u.FUNCTION_CALL]}};g.procedures_defnoreturn=a,g.procedures_defreturn=a,g.procedures_ifreturn=function(e,t){var n=`if `+(t.valueToCode(e,`CONDITION`,u.NONE)||`False`)+`:
2231
+ `;return t.STATEMENT_SUFFIX&&(n+=t.prefixLines(t.injectId(t.STATEMENT_SUFFIX,e),t.INDENT)),e.hasReturnValue_?(e=t.valueToCode(e,`VALUE`,u.NONE)||`None`,n+=t.INDENT+`return `+e+`
2232
+ `):n+=t.INDENT+`return
2233
+ `,n};var _=/^\s*'([^']|\\')*'\s*$/,v={text:function(e,t){return[t.quote_(e.getFieldValue(`TEXT`)),u.ATOMIC]},text_append:function(e,t){var n=t.getVariableName(e.getFieldValue(`VAR`));return e=t.valueToCode(e,`TEXT`,u.NONE)||`''`,n+` = str(`+n+`) + `+o(e)[0]+`
2234
+ `},text_changeCase:function(e,t){var n={UPPERCASE:`.upper()`,LOWERCASE:`.lower()`,TITLECASE:`.title()`}[e.getFieldValue(`CASE`)];return[(t.valueToCode(e,`TEXT`,u.MEMBER)||`''`)+n,u.FUNCTION_CALL]},text_charAt:function(e,t){var n=e.getFieldValue(`WHERE`)||`FROM_START`,r=t.valueToCode(e,`VALUE`,n===`RANDOM`?u.NONE:u.MEMBER)||`''`;switch(n){case`FIRST`:return[r+`[0]`,u.MEMBER];case`LAST`:return[r+`[-1]`,u.MEMBER];case`FROM_START`:return e=t.getAdjustedInt(e,`AT`),[r+`[`+e+`]`,u.MEMBER];case`FROM_END`:return e=t.getAdjustedInt(e,`AT`,1,!0),[r+`[`+e+`]`,u.MEMBER];case`RANDOM`:return t.definitions_.import_random=`import random`,[t.provideFunction_(`text_random_letter`,`
2235
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(text):
2236
+ x = int(random.random() * len(text))
2237
+ return text[x]
2238
+ `)+`(`+r+`)`,u.FUNCTION_CALL]}throw Error(`Unhandled option (text_charAt).`)},text_count:function(e,t){var n=t.valueToCode(e,`TEXT`,u.MEMBER)||`''`;return e=t.valueToCode(e,`SUB`,u.NONE)||`''`,[n+`.count(`+e+`)`,u.FUNCTION_CALL]},text_getSubstring:function(e,n){var r=e.getFieldValue(`WHERE1`),i=e.getFieldValue(`WHERE2`),a=n.valueToCode(e,`STRING`,u.MEMBER)||`''`;switch(r){case`FROM_START`:r=n.getAdjustedInt(e,`AT1`),r===0&&(r=``);break;case`FROM_END`:r=n.getAdjustedInt(e,`AT1`,1,!0);break;case`FIRST`:r=``;break;default:throw Error(`Unhandled option (text_getSubstring)`)}switch(i){case`FROM_START`:e=n.getAdjustedInt(e,`AT2`,1);break;case`FROM_END`:e=n.getAdjustedInt(e,`AT2`,0,!0),t.df(String(e))?e===0&&(e=``):(n.definitions_.import_sys=`import sys`,e+=` or sys.maxsize`);break;case`LAST`:e=``;break;default:throw Error(`Unhandled option (text_getSubstring)`)}return[a+`[`+r+` : `+e+`]`,u.MEMBER]},text_indexOf:function(e,t){var n=e.getFieldValue(`END`)===`FIRST`?`find`:`rfind`,r=t.valueToCode(e,`FIND`,u.NONE)||`''`;return t=(t.valueToCode(e,`VALUE`,u.MEMBER)||`''`)+`.`+n+`(`+r+`)`,e.workspace.options.oneBasedIndex?[t+` + 1`,u.ADDITIVE]:[t,u.FUNCTION_CALL]},text_isEmpty:function(e,t){return[`not len(`+(t.valueToCode(e,`VALUE`,u.NONE)||`''`)+`)`,u.LOGICAL_NOT]},text_join:function(e,n){switch(e.itemCount_){case 0:return[`''`,u.ATOMIC];case 1:return e=n.valueToCode(e,`ADD0`,u.NONE)||`''`,o(e);case 2:var r=n.valueToCode(e,`ADD0`,u.NONE)||`''`;return e=n.valueToCode(e,`ADD1`,u.NONE)||`''`,[o(r)[0]+` + `+o(e)[0],u.ADDITIVE];default:r=[];for(let t=0;t<e.itemCount_;t++)r[t]=n.valueToCode(e,`ADD`+t,u.NONE)||`''`;return e=n.nameDB_.getDistinctName(`x`,t.P.VARIABLE),[`''.join([str(`+e+`) for `+e+` in [`+r.join(`, `)+`]])`,u.FUNCTION_CALL]}},text_length:function(e,t){return[`len(`+(t.valueToCode(e,`VALUE`,u.NONE)||`''`)+`)`,u.FUNCTION_CALL]},text_print:function(e,t){return`print(`+(t.valueToCode(e,`TEXT`,u.NONE)||`''`)+`)
2239
+ `}};v.text_prompt=s,v.text_prompt_ext=s,v.text_replace=function(e,t){var n=t.valueToCode(e,`TEXT`,u.MEMBER)||`''`,r=t.valueToCode(e,`FROM`,u.NONE)||`''`;return e=t.valueToCode(e,`TO`,u.NONE)||`''`,[n+`.replace(`+r+`, `+e+`)`,u.MEMBER]},v.text_reverse=function(e,t){return[(t.valueToCode(e,`TEXT`,u.MEMBER)||`''`)+`[::-1]`,u.MEMBER]},v.text_trim=function(e,t){var n={LEFT:`.lstrip()`,RIGHT:`.rstrip()`,BOTH:`.strip()`}[e.getFieldValue(`MODE`)];return[(t.valueToCode(e,`TEXT`,u.MEMBER)||`''`)+n,u.FUNCTION_CALL]};var ee={};ee.variables_get=c,ee.variables_set=l;var y={};y.variables_get_dynamic=c,y.variables_set_dynamic=l;var te=new f;te.addReservedWords(`math,random,Number`);var b=Object.assign({},{lists_create_empty:function(){return[`[]`,u.ATOMIC]},lists_create_with:function(e,t){var n=Array(e.itemCount_);for(let r=0;r<e.itemCount_;r++)n[r]=t.valueToCode(e,`ADD`+r,u.NONE)||`None`;return[`[`+n.join(`, `)+`]`,u.ATOMIC]},lists_getIndex:function(e,t){var n=e.getFieldValue(`MODE`)||`GET`,r=e.getFieldValue(`WHERE`)||`FROM_START`,i=t.valueToCode(e,`VALUE`,r===`RANDOM`?u.NONE:u.MEMBER)||`[]`;switch(r){case`FIRST`:if(n===`GET`)return[i+`[0]`,u.MEMBER];if(n===`GET_REMOVE`)return[i+`.pop(0)`,u.FUNCTION_CALL];if(n===`REMOVE`)return i+`.pop(0)
2240
+ `;break;case`LAST`:if(n===`GET`)return[i+`[-1]`,u.MEMBER];if(n===`GET_REMOVE`)return[i+`.pop()`,u.FUNCTION_CALL];if(n===`REMOVE`)return i+`.pop()
2241
+ `;break;case`FROM_START`:if(e=t.getAdjustedInt(e,`AT`),n===`GET`)return[i+`[`+e+`]`,u.MEMBER];if(n===`GET_REMOVE`)return[i+`.pop(`+e+`)`,u.FUNCTION_CALL];if(n===`REMOVE`)return i+`.pop(`+e+`)
2242
+ `;break;case`FROM_END`:if(e=t.getAdjustedInt(e,`AT`,1,!0),n===`GET`)return[i+`[`+e+`]`,u.MEMBER];if(n===`GET_REMOVE`)return[i+`.pop(`+e+`)`,u.FUNCTION_CALL];if(n===`REMOVE`)return i+`.pop(`+e+`)
2243
+ `;break;case`RANDOM`:if(t.definitions_.import_random=`import random`,n===`GET`)return[`random.choice(`+i+`)`,u.FUNCTION_CALL];if(i=t.provideFunction_(`lists_remove_random_item`,`
2244
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(myList):
2245
+ x = int(random.random() * len(myList))
2246
+ return myList.pop(x)
2247
+ `)+`(`+i+`)`,n===`GET_REMOVE`)return[i,u.FUNCTION_CALL];if(n===`REMOVE`)return i+`
2248
+ `}throw Error(`Unhandled combination (lists_getIndex).`)},lists_getSublist:function(e,n){var r=n.valueToCode(e,`LIST`,u.MEMBER)||`[]`,i=e.getFieldValue(`WHERE1`),a=e.getFieldValue(`WHERE2`);switch(i){case`FROM_START`:i=n.getAdjustedInt(e,`AT1`),i===0&&(i=``);break;case`FROM_END`:i=n.getAdjustedInt(e,`AT1`,1,!0);break;case`FIRST`:i=``;break;default:throw Error(`Unhandled option (lists_getSublist)`)}switch(a){case`FROM_START`:e=n.getAdjustedInt(e,`AT2`,1);break;case`FROM_END`:e=n.getAdjustedInt(e,`AT2`,0,!0),t.df(String(e))?e===0&&(e=``):(n.definitions_.import_sys=`import sys`,e+=` or sys.maxsize`);break;case`LAST`:e=``;break;default:throw Error(`Unhandled option (lists_getSublist)`)}return[r+`[`+i+` : `+e+`]`,u.MEMBER]},lists_indexOf:function(e,t){var n=t.valueToCode(e,`FIND`,u.NONE)||`[]`,r=t.valueToCode(e,`VALUE`,u.NONE)||`''`,i=` -1`,a=``,o=` - 1`;return e.workspace.options.oneBasedIndex&&(i=` 0`,a=` + 1`,o=``),[(e.getFieldValue(`END`)===`FIRST`?t.provideFunction_(`first_index`,`
2249
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(my_list, elem):
2250
+ try: index = my_list.index(elem)${a}
2251
+ except: index =${i}
2252
+ return index
2253
+ `):t.provideFunction_(`last_index`,`
2254
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(my_list, elem):
2255
+ try: index = len(my_list) - my_list[::-1].index(elem)${o}
2256
+ except: index =${i}
2257
+ return index
2258
+ `))+`(`+r+`, `+n+`)`,u.FUNCTION_CALL]},lists_isEmpty:function(e,t){return[`not len(`+(t.valueToCode(e,`VALUE`,u.NONE)||`[]`)+`)`,u.LOGICAL_NOT]},lists_length:function(e,t){return[`len(`+(t.valueToCode(e,`VALUE`,u.NONE)||`[]`)+`)`,u.FUNCTION_CALL]},lists_repeat:function(e,t){var n=t.valueToCode(e,`ITEM`,u.NONE)||`None`;return e=t.valueToCode(e,`NUM`,u.MULTIPLICATIVE)||`0`,[`[`+n+`] * `+e,u.MULTIPLICATIVE]},lists_reverse:function(e,t){return[`list(reversed(`+(t.valueToCode(e,`LIST`,u.NONE)||`[]`)+`))`,u.FUNCTION_CALL]},lists_setIndex:function(e,n){var r=n.valueToCode(e,`LIST`,u.MEMBER)||`[]`,i=e.getFieldValue(`MODE`)||`GET`,a=e.getFieldValue(`WHERE`)||`FROM_START`,o=n.valueToCode(e,`TO`,u.NONE)||`None`;switch(a){case`FIRST`:if(i===`SET`)return r+`[0] = `+o+`
2259
+ `;if(i===`INSERT`)return r+`.insert(0, `+o+`)
2260
+ `;break;case`LAST`:if(i===`SET`)return r+`[-1] = `+o+`
2261
+ `;if(i===`INSERT`)return r+`.append(`+o+`)
2262
+ `;break;case`FROM_START`:if(n=n.getAdjustedInt(e,`AT`),i===`SET`)return r+`[`+n+`] = `+o+`
2263
+ `;if(i===`INSERT`)return r+`.insert(`+n+`, `+o+`)
2264
+ `;break;case`FROM_END`:if(n=n.getAdjustedInt(e,`AT`,1,!0),i===`SET`)return r+`[`+n+`] = `+o+`
2265
+ `;if(i===`INSERT`)return r+`.insert(`+n+`, `+o+`)
2266
+ `;break;case`RANDOM`:if(n.definitions_.import_random=`import random`,r.match(/^\w+$/)?e=``:(e=n.nameDB_.getDistinctName(`tmp_list`,t.P.VARIABLE),a=e+` = `+r+`
2267
+ `,r=e,e=a),n=n.nameDB_.getDistinctName(`tmp_x`,t.P.VARIABLE),e+=n+` = int(random.random() * len(`+r+`))
2268
+ `,i===`SET`)return e+(r+`[`+n+`] = `+o+`
2269
+ `);if(i===`INSERT`)return e+(r+`.insert(`+n+`, `+o+`)
2270
+ `)}throw Error(`Unhandled combination (lists_setIndex).`)},lists_sort:function(e,t){var n=t.valueToCode(e,`LIST`,u.NONE)||`[]`,r=e.getFieldValue(`TYPE`);return e=e.getFieldValue(`DIRECTION`)===`1`?`False`:`True`,[t.provideFunction_(`lists_sort`,`
2271
+ def ${t.FUNCTION_NAME_PLACEHOLDER_}(my_list, type, reverse):
2272
+ def try_float(s):
2273
+ try:
2274
+ return float(s)
2275
+ except:
2276
+ return 0
2277
+ key_funcs = {
2278
+ "NUMERIC": try_float,
2279
+ "TEXT": str,
2280
+ "IGNORE_CASE": lambda s: str(s).lower()
2281
+ }
2282
+ key_func = key_funcs[type]
2283
+ list_cpy = list(my_list)
2284
+ return sorted(list_cpy, key=key_func, reverse=reverse)
2285
+ `)+`(`+n+`, "`+r+`", `+e+`)`,u.FUNCTION_CALL]},lists_split:function(e,t){var n=e.getFieldValue(`MODE`);if(n===`SPLIT`)n=t.valueToCode(e,`INPUT`,u.MEMBER)||`''`,e=t.valueToCode(e,`DELIM`,u.NONE),e=n+`.split(`+e+`)`;else if(n===`JOIN`)n=t.valueToCode(e,`INPUT`,u.NONE)||`[]`,e=(t.valueToCode(e,`DELIM`,u.MEMBER)||`''`)+`.join(`+n+`)`;else throw Error(`Unknown mode: `+n);return[e,u.FUNCTION_CALL]}},p,m,h,g,v,ee,y);for(let e in b)te.forBlock[e]=b[e];var ne={};return ne.Order=u,ne.PythonGenerator=f,ne.pythonGenerator=te,t.__chunk_python=ne,t.__chunk_python.__namespace__=t,t.__chunk_python})})),Tl=t(((e,t)=>{
2286
+ /*! For license information please see index.js.LICENSE.txt */
2287
+ (function(r,i){if(typeof e==`object`&&typeof t==`object`)t.exports=i(n(),In(),xl(),Sl(),Cl(),wl());else if(typeof define==`function`&&define.amd)define([`blockly/core`,`blockly/javascript`,`blockly/dart`,`blockly/lua`,`blockly/php`,`blockly/python`],i);else{var a=typeof e==`object`?i(n(),In(),xl(),Sl(),Cl(),wl()):i(r.Blockly,r[`Blockly.JavaScript`],r[`Blockly.Dart`],r[`Blockly.Lua`],r[`Blockly.PHP`],r[`Blockly.Python`]);for(var o in a)(typeof e==`object`?e:r)[o]=a[o]}})(e,(e,t,n,r,i,a)=>(()=>{var o={127:e=>{e.exports=t},157:e=>{e.exports=r},370:t=>{t.exports=e},379:e=>{e.exports=n},462:function(e,t,n){e.exports=(e=>(()=>{var t={370:t=>{t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{FieldGridDropdown:()=>c});var a=r(370);class o{constructor(e,t,n,r){this.value=n,this.selected=!1,this.selectionCallback=r,this.element=document.createElement(`button`),this.element.id=a.utils.idGenerator.getNextUniqueId(),this.element.className=`blocklyFieldGridItem`,this.clickHandler=a.browserEvents.conditionalBind(this.element,`click`,this,this.onClick,!0),e.appendChild(this.element);let i=typeof t==`string`?document.createTextNode(t):t;this.element.appendChild(i),a.utils.aria.setRole(this.element,a.utils.aria.Role.GRIDCELL)}dispose(){this.selectionCallback=null,this.element.remove(),this.clickHandler&&=(a.browserEvents.unbind(this.clickHandler),null)}getId(){return this.element.id}getValue(){return this.value}isSelected(){return this.selected}setSelected(e){this.selected=e,a.utils.aria.setState(this.element,a.utils.aria.State.SELECTED,this.selected),this.element.classList.toggle(`blocklyFieldGridItemSelected`,this.selected),this.isSelected()&&this.focus()}onClick(){var e;this.setSelected(!0),(e=this.selectionCallback)==null||e.call(this,this)}focus(){this.element.focus({preventScroll:!0});let e=this.element.offsetParent;if(!e)return;let t=this.element.offsetTop,n=e.scrollTop,r=this.getInterItemSpacing();t<n?e.scrollTo(0,t-r):t+this.element.offsetHeight>n+e.clientHeight&&e.scrollBy(0,t+this.element.clientHeight-(n+e.clientHeight)+r)}getInterItemSpacing(){let e=this.element.closest(`.blocklyFieldGrid`);if(!e)return 0;let t=[...e.querySelectorAll(`.blocklyFieldGridItem`)];if(!t.length)return 0;let n=t[0].offsetTop,r=t[0].offsetHeight;for(let e of t)if(e.offsetTop!==n)return e.offsetTop-r-n;return 0}}class s{constructor(e,t,n,r,i){if(this.columns=n,this.rtl=r,this.itemIndices=new Map,this.items=[],this.keyDownHandler=null,this.pointerMoveHandler=null,this.selectionCallback=i,this.root=document.createElement(`div`),this.root.className=`blocklyFieldGrid`,this.root.tabIndex=0,a.utils.aria.setRole(this.root,a.utils.aria.Role.GRID),e.appendChild(this.root),this.populateItems(t),this.keyDownHandler=a.browserEvents.conditionalBind(this.root,`keydown`,this,this.onKeyDown),this.pointerMoveHandler=a.browserEvents.conditionalBind(this.root,`pointermove`,this,this.onPointerMove,!0),!(n>=1))throw Error(`Number of columns must be >= 1; got ${n}`);this.columns=n,this.root.style.setProperty(`--grid-columns`,`${this.columns}`)}populateItems(e){let t=document.createElement(`div`);for(let[n,r]of e.entries()){if(r===a.FieldDropdown.SEPARATOR)continue;n%this.columns===0&&(t=document.createElement(`div`),t.className=`blocklyFieldGridRow`,a.utils.aria.setRole(t,a.utils.aria.Role.ROW),this.root.appendChild(t));let[e,i]=r,s=(()=>{if((t=e)&&typeof t==`object`&&`src`in t&&typeof t.src==`string`&&`alt`in t&&typeof t.alt==`string`&&`width`in t&&typeof t.width==`number`&&`height`in t&&typeof t.height==`number`){let t=new Image(e.width,e.height);return t.src=e.src,t.alt=e.alt||``,t}var t;return e})(),c=new o(t,s,i,e=>{var t;this.setSelectedValue(e.getValue()),(t=this.selectionCallback)==null||t.call(this,e)});this.itemIndices.set(c.getId(),this.itemIndices.size),this.items.push(c)}}dispose(){this.selectionCallback=void 0;for(let e of this.items)e.dispose();this.itemIndices.clear(),this.items.length=0,this.keyDownHandler&&=(a.browserEvents.unbind(this.keyDownHandler),null),this.pointerMoveHandler&&=(a.browserEvents.unbind(this.pointerMoveHandler),null),this.root.remove()}onKeyDown(e){if(!(!this.items.length||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey)){switch(e.key){case`ArrowUp`:this.moveFocus(-1*this.columns,!0);break;case`ArrowDown`:this.moveFocus(this.columns,!0);break;case`ArrowLeft`:this.moveFocus(-1*(this.rtl?-1:1),!0);break;case`ArrowRight`:this.moveFocus(1*(this.rtl?-1:1),!0);break;case`PageUp`:case`Home`:this.moveFocus(0,!1);break;case`PageDown`:case`End`:this.moveFocus(this.items.length-1,!1);break;case`Enter`:case`Space`:e.stopPropagation();return;default:return}e.preventDefault(),e.stopPropagation()}}onPointerMove(e){if(!e.movementX&&!e.movementY||!(e.target instanceof Element))return;let t=e.target.closest(`.blocklyFieldGridItem`);if(!t)return;let n=t.id,r=this.itemIndices.get(n);r!==void 0&&this.moveFocus(r,!1)}setSelectedValue(e){for(let[t,n]of this.items.entries()){let r=n.getValue()===e;n.setSelected(r),r&&this.moveFocus(t,!1)}}moveFocus(e,t){let n=e;if(t){let e=this.getFocusedItem();if(!e)return;n+=this.indexOfItem(e)}let r=this.itemAtIndex(n);r&&(r.focus(),a.utils.aria.setState(this.root,a.utils.aria.State.ACTIVEDESCENDANT,r.getId()))}indexOfItem(e){return this.itemIndices.get(e.getId())??-1}itemAtIndex(e){return this.items[e]}getFocusedItem(){let e=this.root.querySelector(`.blocklyFieldGridItem:focus`)??this.root.querySelector(`.blocklyFieldGridItem`);if(!e||!e.id)return;let t=this.itemIndices.get(e.id);return t===void 0?void 0:this.itemAtIndex(t)}}class c extends a.FieldDropdown{constructor(e,t,n){super(e,t,n),this.columns=3,n!=null&&n.columns&&this.setColumns(parseInt(`${n.columns}`)),n&&n.primaryColour&&(this.primaryColour=n.primaryColour),n&&n.borderColour&&(this.borderColour=n.borderColour)}static fromJson(e){if(!e.options)throw Error(`options are required for the dropdown field. The options property must be assigned an array of [humanReadableValue, languageNeutralValue] tuples.`);return new this(e.options,void 0,e)}setColumns(e){var t;!isNaN(e)&&e>=1&&(this.columns=e,a.DropDownDiv.getOwner()===this&&a.DropDownDiv.isVisible()&&((t=this.grid)==null||t.dispose(),this.showEditor_()))}showEditor_(e){a.DropDownDiv.clearContent();let t=!!this.getSourceBlock()?.workspace.RTL;this.grid=new s(a.DropDownDiv.getContentDiv(),this.getOptions(!1),this.columns,t,e=>{a.DropDownDiv.hideIfOwner(this),this.setValue(e.getValue())}),a.DropDownDiv.getContentDiv().classList.add(`blocklyFieldGridContainer`);let n=this.getColours();n&&n.border&&a.DropDownDiv.setColour(n.primary,n.border),a.DropDownDiv.showPositionedByField(this,this.dropdownDispose_.bind(this));let r=this.getValue();r&&this.grid.setSelectedValue(r)}doValueUpdate_(e){var t;super.doValueUpdate_(e),(t=this.grid)==null||t.setSelectedValue(e)}getColours(){if(this.primaryColour&&this.borderColour)return{primary:this.primaryColour,border:this.borderColour};let e=this.getSourceBlock();if(!(e instanceof a.BlockSvg))return;let t=e.isShadow()?e.getParent():e;return t?{primary:this.primaryColour??t.getColour(),border:this.borderColour??t.getColourTertiary()}:void 0}}return a.fieldRegistry.register(`field_grid_dropdown`,c),a.Css.register(`
2288
+ .blocklyFieldGridContainer {
2289
+ padding: 7px;
2290
+ overflow: auto;
2291
+ }
2292
+
2293
+ .blocklyFieldGrid {
2294
+ display: grid;
2295
+ grid-gap: 7px;
2296
+ grid-template-columns: repeat(var(--grid-columns), min-content);
2297
+ }
2298
+
2299
+ .blocklyFieldGrid .blocklyFieldGridItem {
2300
+ border: 1px solid rgba(1, 1, 1, 0.5);
2301
+ border-radius: 4px;
2302
+ color: white;
2303
+ min-width: auto;
2304
+ background: none;
2305
+ white-space: nowrap;
2306
+ cursor: pointer;
2307
+ padding: 6px 15px;
2308
+ }
2309
+
2310
+ .blocklyFieldGrid .blocklyFieldGridRow {
2311
+ display: contents;
2312
+ }
2313
+
2314
+ .blocklyFieldGrid .blocklyFieldGridItem.blocklyFieldGridItemSelected {
2315
+ background-color: rgba(1, 1, 1, 0.25);
2316
+ }
2317
+
2318
+ .blocklyFieldGrid .blocklyFieldGridItem:focus {
2319
+ box-shadow: 0 0 0 4px hsla(0, 0%, 100%, .2);
2320
+ outline: none;
2321
+ }
2322
+ `),i})())(n(370))},537:e=>{e.exports=i},557:e=>{e.exports=a}},s={};function c(e){var t=s[e];if(t!==void 0)return t.exports;var n=s[e]={exports:{}};return o[e].call(n.exports,n,n.exports,c),n.exports}c.d=(e,t)=>{for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),c.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var l={};return(()=>{c.r(l),c.d(l,{FieldColour:()=>s,colourBlend:()=>r,colourPicker:()=>e,colourRandom:()=>t,colourRgb:()=>n,installAllBlocks:()=>ke,registerFieldColour:()=>d});var e={};c.r(e),c.d(e,{BLOCK_NAME:()=>_,blockDefinition:()=>ie,installBlock:()=>ae,toDart:()=>y,toJavascript:()=>ee,toLua:()=>te,toPhp:()=>b,toPython:()=>ne});var t={};c.r(t),c.d(t,{BLOCK_NAME:()=>oe,blockDefinition:()=>de,installBlock:()=>fe,toDart:()=>ce,toJavascript:()=>x,toLua:()=>S,toPhp:()=>C,toPython:()=>le});var n={};c.r(n),c.d(n,{BLOCK_NAME:()=>w,blockDefinition:()=>_e,installBlock:()=>ve,toDart:()=>E,toJavascript:()=>pe,toLua:()=>me,toPhp:()=>D,toPython:()=>he});var r={};c.r(r),c.d(r,{BLOCK_NAME:()=>ye,blockDefinition:()=>De,installBlock:()=>Oe,toDart:()=>Se,toJavascript:()=>xe,toLua:()=>Ce,toPhp:()=>we,toPython:()=>Te});var i=c(370),a=c(462);let o=`#ffffff.#cccccc.#c0c0c0.#999999.#666666.#333333.#000000.#ffcccc.#ff6666.#ff0000.#cc0000.#990000.#660000.#330000.#ffcc99.#ff9966.#ff9900.#ff6600.#cc6600.#993300.#663300.#ffff99.#ffff66.#ffcc66.#ffcc33.#cc9933.#996633.#663333.#ffffcc.#ffff33.#ffff00.#ffcc00.#999900.#666600.#333300.#99ff99.#66ff99.#33ff33.#33cc00.#009900.#006600.#003300.#99ffff.#33ffff.#66cccc.#00cccc.#339999.#336666.#003333.#ccffff.#66ffff.#33ccff.#3366ff.#3333ff.#000099.#000066.#ccccff.#9999ff.#6666cc.#6633ff.#6600cc.#333399.#330099.#ffccff.#ff99ff.#cc66cc.#cc33cc.#993399.#663366.#330033`.split(`.`);class s extends a.FieldGridDropdown{constructor(e,t,n){super(u(n?.colourOptions??o),t,Object.assign(Object.assign({},n),{columns:n?.columns??7})),this.isDirty_=!1,e!==i.Field.SKIP_SETUP&&this.setValue(e)}trimOptions(e){return{options:e}}configure_(e){super.configure_(e),e.colourOptions&&this.setColours(e.colourOptions,e.colourTitles)}initView(){let e=this.getConstants();if(!e)throw Error(`Constants not found`);this.size_=new i.utils.Size(e.FIELD_COLOUR_DEFAULT_WIDTH,e.FIELD_COLOUR_DEFAULT_HEIGHT),this.createBorderRect_(),this.getBorderRect().style.fillOpacity=`1`,this.getBorderRect().setAttribute(`stroke`,`#fff`),this.isFullBlockField()&&(this.clickTarget_=this.sourceBlock_.getSvgRoot())}showEditor_(e){super.showEditor_(e),i.DropDownDiv.getContentDiv().classList.add(`blocklyFieldColour`),i.DropDownDiv.repositionForWindowResize()}isFullBlockField(){if(!this.getSourceBlock())throw new i.UnattachedFieldError;let e=this.getConstants();return this.blockIsSimpleReporter()&&!!e?.FIELD_COLOUR_FULL_BLOCK}blockIsSimpleReporter(){let e=this.getSourceBlock();if(!e)throw new i.UnattachedFieldError;if(!e.outputConnection)return!1;for(let t of e.inputList)if(t.connection||t.fieldRow.length>1)return!1;return!0}applyColour(){let e=this.getSourceBlock();if(!e)throw new i.UnattachedFieldError;if(!this.fieldGroup_)return;let t=this.borderRect_;if(!t)throw Error(`The border rect has not been initialized`);this.isFullBlockField()?(t.style.display=`none`,e.pathObject.svgPath.setAttribute(`fill`,this.getValue()),e.pathObject.svgPath.setAttribute(`stroke`,`#fff`)):(t.style.display=`block`,t.style.fill=this.getValue())}getSize(){var e;return(e=this.getConstants())!=null&&e.FIELD_COLOUR_FULL_BLOCK&&(this.render_(),this.isDirty_=!1),super.getSize()}render_(){this.updateSize_();let e=this.getSourceBlock();if(!e)throw new i.UnattachedFieldError;e.applyColour()}updateSize_(e){let t=this.getConstants();if(!t)return;let n,r;this.isFullBlockField()?(n=2*(e??0),r=t.FIELD_TEXT_HEIGHT):(n=t.FIELD_COLOUR_DEFAULT_WIDTH,r=t.FIELD_COLOUR_DEFAULT_HEIGHT),this.size_.height=r,this.size_.width=n,this.positionBorderRect_()}doClassValidation_(e){return typeof e==`string`?i.utils.colour.parse(e):null}getText(){let e=this.value_;return/^#(.)\1(.)\2(.)\3$/.test(e)&&(e=`#`+e[1]+e[3]+e[5]),e}setColours(e,t){let n=u(e,t);return this.setOptions(n),this}static fromJson(e){return new this(e.colour,void 0,e)}}function u(e,t){return e.map((e,n)=>{let r=document.createElement(`div`);return r.className=`blocklyColourSwatch`,r.style.backgroundColor=e,t&&n<t.length&&(r.title=t[n]),[r,e]})}function d(){i.fieldRegistry.register(`field_colour`,s)}s.prototype.DEFAULT_VALUE=`#ffffff`,i.Css.register(`
2323
+ .blocklyFieldColour .blocklyFieldGridItemSelected,
2324
+ .blocklyFieldGridItemSelected:hover {
2325
+ border-color: #eee !important;
2326
+ outline: 1px solid #333;
2327
+ position: relative;
2328
+ }
2329
+
2330
+ .blocklyColourSwatch {
2331
+ width: 20px;
2332
+ height: 20px;
2333
+ }
2334
+
2335
+ .blocklyGridContainer {
2336
+ padding: 0px;
2337
+ }
2338
+
2339
+ .blocklyFieldColour .blocklyFieldGrid {
2340
+ grid-gap: 0px;
2341
+ row-gap: 4px;
2342
+ }
2343
+
2344
+ .blocklyFieldColour .blocklyFieldGrid .blocklyGridItem {
2345
+ border-radius: 0;
2346
+ padding: 0;
2347
+ border: 0.5px solid #888;
2348
+ cursor: pointer;
2349
+ }
2350
+
2351
+ .blocklyFieldColour .blocklyFieldGrid .blocklyFieldGridItem {
2352
+ border: 0.5px solid #888;
2353
+ padding: 0;
2354
+ margin: 0;
2355
+ border-radius: 0;
2356
+ }
2357
+
2358
+ .blocklyFieldColour .blocklyFieldGrid .blocklyFieldGridItem:focus {
2359
+ border-color: #eee;
2360
+ box-shadow: 2px 2px 7px 2px rgba(0, 0, 0, 0.3);
2361
+ position: relative;
2362
+ border-radius: 0;
2363
+ outline: none;
2364
+ }
2365
+ `);var f=c(127),p=c(379),m=c(157),h=c(537),g=c(557);let _=`colour_picker`,v={type:_,message0:`%1`,args0:[{type:`field_colour`,name:`COLOUR`,colour:`#ff0000`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_PICKER_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_PICKER_TOOLTIP}`,extensions:[`parent_tooltip_when_inline`]};function ee(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),f.Order.ATOMIC]}function y(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),p.Order.ATOMIC]}function te(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),m.Order.ATOMIC]}function b(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),h.Order.ATOMIC]}function ne(e,t){return[t.quote_(e.getFieldValue(`COLOUR`)),g.Order.ATOMIC]}let re=i.common.createBlockDefinitionsFromJsonArray([v]),ie=re[_];function ae(e={}){d(),i.common.defineBlocks(re),e.javascript&&(e.javascript.forBlock[_]=ee),e.dart&&(e.dart.forBlock[_]=y),e.lua&&(e.lua.forBlock[_]=te),e.php&&(e.php.forBlock[_]=b),e.python&&(e.python.forBlock[_]=ne)}let oe=`colour_random`,se={type:oe,message0:`%{BKY_COLOUR_RANDOM_TITLE}`,output:`Colour`,helpUrl:`%{BKY_COLOUR_RANDOM_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RANDOM_TOOLTIP}`};function x(e,t){return[t.provideFunction_(`colourRandom`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}() {\n var num = Math.floor(Math.random() * 0x1000000);\n return '#' + ('00000' + num.toString(16)).substr(-6);\n}\n`)+`()`,f.Order.FUNCTION_CALL]}function ce(e,t){return t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[t.provideFunction_(`colour_random`,`\nString ${t.FUNCTION_NAME_PLACEHOLDER_}() {\n String hex = '0123456789abcdef';\n var rnd = new Math.Random();\n return '#\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'\n '\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}'\n '\${hex[rnd.nextInt(16)]}\${hex[rnd.nextInt(16)]}';\n}\n`)+`()`,p.Order.UNARY_POSTFIX]}function S(e,t){return[`string.format("#%06x", math.random(0, 2^24 - 1))`,m.Order.HIGH]}function C(e,t){return[t.provideFunction_(`colour_random`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}() {\n return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);\n}\n`)+`()`,h.Order.FUNCTION_CALL]}function le(e,t){return t.definitions_.import_random=`import random`,[`'#%06x' % random.randint(0, 2**24 - 1)`,g.Order.FUNCTION_CALL]}let ue=i.common.createBlockDefinitionsFromJsonArray([se]),de=ue[oe];function fe(e={}){d(),i.common.defineBlocks(ue),e.javascript&&(e.javascript.forBlock[oe]=x),e.dart&&(e.dart.forBlock[oe]=ce),e.lua&&(e.lua.forBlock[oe]=S),e.php&&(e.php.forBlock[oe]=C),e.python&&(e.python.forBlock[oe]=le)}let w=`colour_rgb`,T={type:w,message0:`%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3`,args0:[{type:`input_value`,name:`RED`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`GREEN`,check:`Number`,align:`RIGHT`},{type:`input_value`,name:`BLUE`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_RGB_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_RGB_TOOLTIP}`};function pe(e,t){let n=t.valueToCode(e,`RED`,f.Order.NONE)||0,r=t.valueToCode(e,`GREEN`,f.Order.NONE)||0,i=t.valueToCode(e,`BLUE`,f.Order.NONE)||0;return[`${t.provideFunction_(`colourRgb`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}(r, g, b) {\n r = Math.max(Math.min(Number(r), 100), 0) * 2.55;\n g = Math.max(Math.min(Number(g), 100), 0) * 2.55;\n b = Math.max(Math.min(Number(b), 100), 0) * 2.55;\n r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2);\n g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2);\n b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2);\n return '#' + r + g + b;\n}\n`)}(${n}, ${r}, ${i})`,f.Order.FUNCTION_CALL]}function E(e,t){let n=t.valueToCode(e,`RED`,p.Order.NONE)||0,r=t.valueToCode(e,`GREEN`,p.Order.NONE)||0,i=t.valueToCode(e,`BLUE`,p.Order.NONE)||0;return t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[`${t.provideFunction_(`colour_rgb`,`\nString ${t.FUNCTION_NAME_PLACEHOLDER_}(num r, num g, num b) {\n num rn = (Math.max(Math.min(r, 100), 0) * 2.55).round();\n String rs = rn.toInt().toRadixString(16);\n rs = '0$rs';\n rs = rs.substring(rs.length - 2);\n num gn = (Math.max(Math.min(g, 100), 0) * 2.55).round();\n String gs = gn.toInt().toRadixString(16);\n gs = '0$gs';\n gs = gs.substring(gs.length - 2);\n num bn = (Math.max(Math.min(b, 100), 0) * 2.55).round();\n String bs = bn.toInt().toRadixString(16);\n bs = '0$bs';\n bs = bs.substring(bs.length - 2);\n return '#$rs$gs$bs';\n}\n`)}(${n}, ${r}, ${i})`,p.Order.UNARY_POSTFIX]}function me(e,t){return[`${t.provideFunction_(`colour_rgb`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}(r, g, b)\n r = math.floor(math.min(100, math.max(0, r)) * 2.55 + .5)\n g = math.floor(math.min(100, math.max(0, g)) * 2.55 + .5)\n b = math.floor(math.min(100, math.max(0, b)) * 2.55 + .5)\n return string.format("#%02x%02x%02x", r, g, b)\nend\n`)}(${t.valueToCode(e,`RED`,m.Order.NONE)||0}, ${t.valueToCode(e,`GREEN`,m.Order.NONE)||0}, ${t.valueToCode(e,`BLUE`,m.Order.NONE)||0})`,m.Order.HIGH]}function D(e,t){let n=t.valueToCode(e,`RED`,h.Order.NONE)||0,r=t.valueToCode(e,`GREEN`,h.Order.NONE)||0,i=t.valueToCode(e,`BLUE`,h.Order.NONE)||0;return[`${t.provideFunction_(`colour_rgb`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}($r, $g, $b) {\n $r = round(max(min($r, 100), 0) * 2.55);\n $g = round(max(min($g, 100), 0) * 2.55);\n $b = round(max(min($b, 100), 0) * 2.55);\n $hex = '#';\n $hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);\n return $hex;\n}\n`)}(${n}, ${r}, ${i})`,h.Order.FUNCTION_CALL]}function he(e,t){return[t.provideFunction_(`colour_rgb`,`\ndef ${t.FUNCTION_NAME_PLACEHOLDER_}(r, g, b):\n r = round(min(100, max(0, r)) * 2.55)\n g = round(min(100, max(0, g)) * 2.55)\n b = round(min(100, max(0, b)) * 2.55)\n return '#%02x%02x%02x' % (r, g, b)\n`)+`(`+(t.valueToCode(e,`RED`,g.Order.NONE)||0)+`, `+(t.valueToCode(e,`GREEN`,g.Order.NONE)||0)+`, `+(t.valueToCode(e,`BLUE`,g.Order.NONE)||0)+`)`,g.Order.FUNCTION_CALL]}let ge=i.common.createBlockDefinitionsFromJsonArray([T]),_e=ge[w];function ve(e={}){d(),i.common.defineBlocks(ge),e.javascript&&(e.javascript.forBlock[w]=pe),e.dart&&(e.dart.forBlock[w]=E,e.dart.addReservedWords(`Math`)),e.lua&&(e.lua.forBlock[w]=me),e.php&&(e.php.forBlock[w]=D),e.python&&(e.python.forBlock[w]=he)}let ye=`colour_blend`,be={type:ye,message0:`%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} %1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3`,args0:[{type:`input_value`,name:`COLOUR1`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`COLOUR2`,check:`Colour`,align:`RIGHT`},{type:`input_value`,name:`RATIO`,check:`Number`,align:`RIGHT`}],output:`Colour`,helpUrl:`%{BKY_COLOUR_BLEND_HELPURL}`,style:`colour_blocks`,tooltip:`%{BKY_COLOUR_BLEND_TOOLTIP}`};function xe(e,t){let n=t.valueToCode(e,`COLOUR1`,f.Order.NONE)||`'#000000'`,r=t.valueToCode(e,`COLOUR2`,f.Order.NONE)||`'#000000'`,i=t.valueToCode(e,`RATIO`,f.Order.NONE)||.5;return[`${t.provideFunction_(`colourBlend`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}(c1, c2, ratio) {\n ratio = Math.max(Math.min(Number(ratio), 1), 0);\n var r1 = parseInt(c1.substring(1, 3), 16);\n var g1 = parseInt(c1.substring(3, 5), 16);\n var b1 = parseInt(c1.substring(5, 7), 16);\n var r2 = parseInt(c2.substring(1, 3), 16);\n var g2 = parseInt(c2.substring(3, 5), 16);\n var b2 = parseInt(c2.substring(5, 7), 16);\n var r = Math.round(r1 * (1 - ratio) + r2 * ratio);\n var g = Math.round(g1 * (1 - ratio) + g2 * ratio);\n var b = Math.round(b1 * (1 - ratio) + b2 * ratio);\n r = ('0' + (r || 0).toString(16)).slice(-2);\n g = ('0' + (g || 0).toString(16)).slice(-2);\n b = ('0' + (b || 0).toString(16)).slice(-2);\n return '#' + r + g + b;\n}\n`)}(${n}, ${r}, ${i})`,f.Order.FUNCTION_CALL]}function Se(e,t){let n=t.valueToCode(e,`COLOUR1`,p.Order.NONE)||`'#000000'`,r=t.valueToCode(e,`COLOUR2`,p.Order.NONE)||`'#000000'`,i=t.valueToCode(e,`RATIO`,p.Order.NONE)||.5;return t.definitions_.import_dart_math=`import 'dart:math' as Math;`,[`${t.provideFunction_(`colour_blend`,`\nString ${t.FUNCTION_NAME_PLACEHOLDER_}(String c1, String c2, num ratio) {\n ratio = Math.max(Math.min(ratio, 1), 0);\n int r1 = int.parse('0x\${c1.substring(1, 3)}');\n int g1 = int.parse('0x\${c1.substring(3, 5)}');\n int b1 = int.parse('0x\${c1.substring(5, 7)}');\n int r2 = int.parse('0x\${c2.substring(1, 3)}');\n int g2 = int.parse('0x\${c2.substring(3, 5)}');\n int b2 = int.parse('0x\${c2.substring(5, 7)}');\n num rn = (r1 * (1 - ratio) + r2 * ratio).round();\n String rs = rn.toInt().toRadixString(16);\n num gn = (g1 * (1 - ratio) + g2 * ratio).round();\n String gs = gn.toInt().toRadixString(16);\n num bn = (b1 * (1 - ratio) + b2 * ratio).round();\n String bs = bn.toInt().toRadixString(16);\n rs = '0$rs';\n rs = rs.substring(rs.length - 2);\n gs = '0$gs';\n gs = gs.substring(gs.length - 2);\n bs = '0$bs';\n bs = bs.substring(bs.length - 2);\n return '#$rs$gs$bs';\n}\n`)}(${n}, ${r}, ${i})`,p.Order.UNARY_POSTFIX]}function Ce(e,t){return[`${t.provideFunction_(`colour_blend`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}(colour1, colour2, ratio)\n local r1 = tonumber(string.sub(colour1, 2, 3), 16)\n local r2 = tonumber(string.sub(colour2, 2, 3), 16)\n local g1 = tonumber(string.sub(colour1, 4, 5), 16)\n local g2 = tonumber(string.sub(colour2, 4, 5), 16)\n local b1 = tonumber(string.sub(colour1, 6, 7), 16)\n local b2 = tonumber(string.sub(colour2, 6, 7), 16)\n local ratio = math.min(1, math.max(0, ratio))\n local r = math.floor(r1 * (1 - ratio) + r2 * ratio + .5)\n local g = math.floor(g1 * (1 - ratio) + g2 * ratio + .5)\n local b = math.floor(b1 * (1 - ratio) + b2 * ratio + .5)\n return string.format("#%02x%02x%02x", r, g, b)\nend\n`)}(${t.valueToCode(e,`COLOUR1`,m.Order.NONE)||`'#000000'`}, ${t.valueToCode(e,`COLOUR2`,m.Order.NONE)||`'#000000'`}, ${t.valueToCode(e,`RATIO`,m.Order.NONE)||0})`,m.Order.HIGH]}function we(e,t){let n=t.valueToCode(e,`COLOUR1`,h.Order.NONE)||`'#000000'`,r=t.valueToCode(e,`COLOUR2`,h.Order.NONE)||`'#000000'`,i=t.valueToCode(e,`RATIO`,h.Order.NONE)||.5;return[`${t.provideFunction_(`colour_blend`,`\nfunction ${t.FUNCTION_NAME_PLACEHOLDER_}($c1, $c2, $ratio) {\n $ratio = max(min($ratio, 1), 0);\n $r1 = hexdec(substr($c1, 1, 2));\n $g1 = hexdec(substr($c1, 3, 2));\n $b1 = hexdec(substr($c1, 5, 2));\n $r2 = hexdec(substr($c2, 1, 2));\n $g2 = hexdec(substr($c2, 3, 2));\n $b2 = hexdec(substr($c2, 5, 2));\n $r = round($r1 * (1 - $ratio) + $r2 * $ratio);\n $g = round($g1 * (1 - $ratio) + $g2 * $ratio);\n $b = round($b1 * (1 - $ratio) + $b2 * $ratio);\n $hex = '#';\n $hex .= str_pad(dechex($r), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($g), 2, '0', STR_PAD_LEFT);\n $hex .= str_pad(dechex($b), 2, '0', STR_PAD_LEFT);\n return $hex;\n}\n`)}(${n}, ${r}, ${i})`,h.Order.FUNCTION_CALL]}function Te(e,t){return[`${t.provideFunction_(`colour_blend`,`\ndef ${t.FUNCTION_NAME_PLACEHOLDER_}(colour1, colour2, ratio):\n r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)\n g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)\n b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)\n ratio = min(1, max(0, ratio))\n r = round(r1 * (1 - ratio) + r2 * ratio)\n g = round(g1 * (1 - ratio) + g2 * ratio)\n b = round(b1 * (1 - ratio) + b2 * ratio)\n return '#%02x%02x%02x' % (r, g, b)\n`)}(${t.valueToCode(e,`COLOUR1`,g.Order.NONE)||`'#000000'`}, ${t.valueToCode(e,`COLOUR2`,g.Order.NONE)||`'#000000'`}, ${t.valueToCode(e,`RATIO`,g.Order.NONE)||0})`,g.Order.FUNCTION_CALL]}let Ee=i.common.createBlockDefinitionsFromJsonArray([be]),De=Ee[ye];function Oe(e={}){d(),i.common.defineBlocks(Ee),e.javascript&&(e.javascript.forBlock[ye]=xe),e.dart&&(e.dart.forBlock[ye]=Se,e.dart.addReservedWords(`Math`)),e.lua&&(e.lua.forBlock[ye]=Ce),e.php&&(e.php.forBlock[ye]=we),e.python&&(e.python.forBlock[ye]=Te)}function ke(e={}){ae(e),ve(e),fe(e),Oe(e)}})(),l})())})),El=t(((e,t)=>{(function(r,i){if(typeof e==`object`&&typeof t==`object`)t.exports=i(n());else if(typeof define==`function`&&define.amd)define([`blockly/core`],i);else{var a=i(typeof e==`object`?n():r.Blockly);for(var o in a)(typeof e==`object`?e:r)[o]=a[o]}})(e,e=>(()=>{var t={370:t=>{t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{CrossTabCopyPaste:()=>l});var a,o=r(370);function s(e){return!!(o.isCopyable(e)&&o.isDeletable(e)&&o.isDraggable(e))&&(e.isCopyable?e.isCopyable():e instanceof o.BlockSvg||e instanceof o.comments.RenderedWorkspaceComment?e.isOwnDeletable()&&e.isOwnMovable():e.isDeletable()&&e.isMovable())}function c(e){return s(e)&&o.isDeletable(e)&&e.isDeletable()}(function(e){e.ENABLED=`enabled`,e.DISABLED=`disabled`,e.HIDDEN=`hidden`})(a||={});class l{constructor(){this.localStorageKey=`blocklyStash`}init({contextMenu:e=!0,shortcut:t=!0}={contextMenu:!0,shortcut:!0},n,r){r&&(this.localStorageKey=r),e&&(this.blockCopyToStorageContextMenu(),this.blockPasteFromStorageContextMenu(n)),t&&(o.ShortcutRegistry.registry.unregister(o.ShortcutItems.names.COPY),o.ShortcutRegistry.registry.unregister(o.ShortcutItems.names.CUT),o.ShortcutRegistry.registry.unregister(o.ShortcutItems.names.PASTE),this.blockCopyToStorageShortcut(),this.blockCutToStorageShortcut(),this.blockPasteFromStorageShortcut(n))}getCopyData(){let e=localStorage.getItem(this.localStorageKey);if(e)return JSON.parse(e)}copyPrecondition(e,t){let n=e.focusedNode;if(!n||!o.isCopyable(n)||(t||=n.workspace,!(t instanceof o.WorkspaceSvg)))return a.HIDDEN;let r=t.isFlyout?t.targetWorkspace:t;return n&&r&&!r.isDragging()&&!o.getFocusManager().ephemeralFocusTaken()&&s(n)?a.ENABLED:a.DISABLED}copyCallback(e,t){let n=e.focusedNode;if(!n||!o.isCopyable(n)||!s(n)||!(t instanceof o.WorkspaceSvg))return!1;let r=t.isFlyout?t.targetWorkspace:t;if(!r)return!1;n.workspace.isFlyout||r.hideChaff();let i=n.toCopyData();return!!i&&(localStorage.setItem(this.localStorageKey,JSON.stringify(i)),!0)}pastePrecondition(e){let t=this.getCopyData();return t?`typeCounts`in t&&!e?.isCapacityAvailable(t.typeCounts)||!e||e.isReadOnly()||e.isDragging()||o.getFocusManager().ephemeralFocusTaken()?a.DISABLED:a.ENABLED:a.DISABLED}getContextMenuText(e){return e.indexOf(`)`)===e.length-1&&(e=e.split(` (`)[0]),e}blockCopyToStorageContextMenu(){o.ContextMenuRegistry.registry.register({displayText:()=>o.Msg.CROSS_TAB_COPY?o.Msg.CROSS_TAB_COPY:this.getContextMenuText(o.Msg.COPY_SHORTCUT),preconditionFn:e=>this.copyPrecondition(e),callback:e=>{let t=e.focusedNode;if(!t||!o.isCopyable(t))return!1;let n=t.workspace;return this.copyCallback(e,n)},id:`blockCopyToStorage`,weight:0})}blockPasteFromStorageContextMenu(e){o.ContextMenuRegistry.registry.register({displayText:()=>o.Msg.CROSS_TAB_PASTE?o.Msg.CROSS_TAB_PASTE:this.getContextMenuText(o.Msg.PASTE_SHORTCUT),preconditionFn:e=>{if(!(e.focusedNode instanceof o.WorkspaceSvg)||e.focusedNode.isFlyout)return a.HIDDEN;let t=e.focusedNode;return this.pastePrecondition(t)},callback:(t,n,r,i)=>{let a=this.getCopyData();if(!a)return!1;let s=t.focusedNode;if(!(s instanceof o.WorkspaceSvg))return!1;let c=o.utils.svgMath.screenToWsCoordinates(s,i);try{return!!o.clipboard.paste(a,s,c)}catch(t){if(!(t instanceof TypeError&&e))throw t;e()}},id:`blockPasteFromStorage`,weight:0})}blockCopyToStorageShortcut(){let e=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.C,[o.utils.KeyCodes.CTRL]),t=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.C,[o.utils.KeyCodes.META]),n={name:o.ShortcutItems.names.COPY,keyCodes:[e,t],preconditionFn:(e,t)=>this.copyPrecondition(t,e)===a.ENABLED,callback:(e,t,n,r)=>(t.preventDefault(),this.copyCallback(r,e))};o.ShortcutRegistry.registry.register(n)}blockCutToStorageShortcut(){let e=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.X,[o.utils.KeyCodes.CTRL]),t=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.X,[o.utils.KeyCodes.META]),n={name:o.ShortcutItems.names.CUT,keyCodes:[e,t],preconditionFn:(e,t)=>{let n=t.focusedNode;return!!n&&!e.isReadOnly()&&!e.isDragging()&&!o.getFocusManager().ephemeralFocusTaken()&&c(n)},callback:(e,t,n,r)=>{t.preventDefault();let i=r.focusedNode;if(!i||!c(i)||!o.isCopyable(i))return!1;let a=i.toCopyData();if(!a)return!1;if(i instanceof o.BlockSvg)i.checkAndDelete();else if(o.isDeletable(i)){let e=o.Events.getGroup();o.Events.setGroup(!0),i.dispose(),o.Events.setGroup(e)}return localStorage.setItem(this.localStorageKey,JSON.stringify(a)),!0}};o.ShortcutRegistry.registry.register(n)}blockPasteFromStorageShortcut(e){let t=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.V,[o.utils.KeyCodes.CTRL]),n=o.ShortcutRegistry.registry.createSerializedKey(o.utils.KeyCodes.V,[o.utils.KeyCodes.META]),r={name:o.ShortcutItems.names.PASTE,keyCodes:[t,n],preconditionFn:e=>{let t=e.isFlyout?e.targetWorkspace:e;return!!t&&this.pastePrecondition(t)===a.ENABLED},callback:(t,n)=>{n.preventDefault();let r=this.getCopyData();if(!r)return!1;let i=t.isFlyout?t.targetWorkspace:t;if(!i)return!1;try{if(n instanceof PointerEvent){let e=o.utils.svgMath.screenToWsCoordinates(i,new o.utils.Coordinate(n.clientX,n.clientY));return!!o.clipboard.paste(r,i,e)}return!!o.clipboard.paste(r,i)}catch(t){if(!(t instanceof TypeError&&e))throw t;e()}return!0}};o.ShortcutRegistry.registry.register(r)}}return i})())})),Dl=t(((e,t)=>{
2366
+ /*! For license information please see index.js.LICENSE.txt */
2367
+ (function(r,i){if(typeof e==`object`&&typeof t==`object`)t.exports=i(n());else if(typeof define==`function`&&define.amd)define([`blockly/core`],i);else{var a=i(typeof e==`object`?n():r.Blockly);for(var o in a)(typeof e==`object`?e:r)[o]=a[o]}})(e,e=>(()=>{var t={370:t=>{t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};r.r(i),r.d(i,{BlockShadowStateChange:()=>o,shadowBlockConversionChangeListener:()=>c});var a=r(370);class o extends a.Events.BlockBase{constructor(e,t,n){super(e),this.type=o.EVENT_TYPE,this.inputIndexInParent=t,this.shadowState=n}toJson(){let e=super.toJson();return e.inputIndexInParent=this.inputIndexInParent,e.shadowState=this.shadowState,e}static fromJson(e,t,n){let r=super.fromJson(e,t,n);return r.inputIndexInParent=e.inputIndexInParent,r.shadowState=e.shadowState,n}isNull(){return!1}run(e){let t=this.getEventWorkspace_();if(!this.blockId)throw Error(`The block ID is undefined. Either pass a block to the constructor, or call fromJson`);let n=t.getBlockById(this.blockId);if(!n)throw Error(`The associated block is undefined. Either pass a block to the constructor, or call fromJson`);let r=n.getConnections_(!0),i;if(this.inputIndexInParent===null)i=n.nextConnection;else{if(typeof this.inputIndexInParent!=`number`||this.inputIndexInParent<0||this.inputIndexInParent>=r.length)throw Error(`inputIndexInParent was invalid.`);i=n.inputList[this.inputIndexInParent].connection}if(i===null)throw Error(`No matching connection was found.`);e&&i.setShadowState(this.shadowState||null),a.getFocusManager().focusNode(n)}}function s(e,t=!1){var n;let r=null,i=!1;if(e.previousConnection?.isConnected()?r=e.previousConnection.targetConnection:(n=e.outputConnection)!=null&&n.isConnected()&&(r=e.outputConnection.targetConnection,i=!0),r===null)return e;let c=r.getSourceBlock(),l=r.getParentInput(),u=l?c.inputList.indexOf(l):null,d=r.getShadowState(!1),f=a.serialization.blocks.save(e,{addCoordinates:!1,addInputBlocks:!0,addNextBlocks:!0,doFullSerialization:!1});if(d===null||f===null)return e;if(c.isShadow()){let e=s(c);if(e===null)throw Error(`No parent block was created, so we can't recreate the current block either.`);if(c=e,u===null)r=c.nextConnection;else{if(u<0||u>=c.inputList.length)throw Error(`inputIndexInParent is invalid.`);r=c.inputList[u].connection}if(r===null)throw Error(`Couldn't find the corresponding connection on the new version of the parent block.`)}f.id=void 0;let p=a.serialization.blocks.append(f,c.workspace,{recordUndo:!0}),m=i?p.outputConnection:p.previousConnection;return m&&r.connect(m),r.setShadowState(d),a.Events.fire(new o(c,u,d)),t&&a.getFocusManager().focusNode(p),p}function c(e){if(!e.recordUndo||e.type!=a.Events.BLOCK_CHANGE)return;let t=e;if(!t.workspaceId||!t.blockId)return;let n=a.Workspace.getById(t.workspaceId);if(!n)return;let r=n.getBlockById(t.blockId);if(!r||!r.isShadow())return;let i=a.Events.getGroup();t.group?a.Events.setGroup(t.group):a.Events.setGroup(!0),s(r,!0),a.Events.setGroup(i)}return o.EVENT_TYPE=`block_shadow_state_change`,a.registry.register(a.registry.Type.EVENT,o.EVENT_TYPE,o),i})())})),Ol=[706,()=>[kl,kl],[``,``,``,``]],kl=[707,()=>[Ol,Ol],[``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``,``]]
2368
+ /**
2369
+ * @license
2370
+ * Copyright 2021 Google LLC
2371
+ * SPDX-License-Identifier: Apache-2.0
2372
+ */
2373
+ ;export{ft as A,ln as B,he as C,it as D,Qe as E,Zt as F,An as G,En as H,Qt as I,jn as K,rn as L,Rt as M,zt as N,at as O,Jt as P,an as R,D as S,We as T,On as U,un as V,kn as W,ue as _,bl as a,T as b,mc as c,Rn as d,zn as f,le as g,ie as h,Tl as i,kt as j,ut as k,z as l,ne as m,Dl as n,yl as o,s as p,Pn as q,El as r,Cc as s,kl as t,_s as u,fe as v,He as w,pe as x,w as y,cn as z};