pxt-core 13.2.0 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/cli.js +20 -10
- package/built/pxt.js +74 -11
- package/built/pxtlib.d.ts +19 -0
- package/built/pxtlib.js +54 -1
- package/built/pxtsim.d.ts +5 -1
- package/built/react-common/components/controls/Card.d.ts +1 -0
- package/built/react-common/components/controls/Modal.d.ts +1 -0
- package/built/react-common/components/share/Share.d.ts +2 -1
- package/built/react-common/components/share/ShareInfo.d.ts +2 -1
- package/built/react-common/components/theming/SimulatorThemePickerModal.d.ts +15 -0
- package/built/react-common/components/theming/ThemeCard.d.ts +2 -1
- package/built/react-common/components/theming/ThemePickerModal.d.ts +10 -1
- package/built/react-common/components/theming/simulatorThemeDefaults.d.ts +5 -0
- package/built/target.js +1 -1
- package/built/targetlight.js +1 -1
- package/built/web/main.js +30 -30
- package/built/web/multiplayer/js/{main.db72096c.js → main.d98f7e21.js} +2 -2
- package/built/web/pxtapp.js +1 -1
- package/built/web/pxtasseteditor.js +1 -1
- package/built/web/pxtembed.js +2 -2
- package/built/web/pxtlib.js +1 -1
- package/built/web/pxtworker.js +1 -1
- package/built/web/react-common-authcode.css +1 -1
- package/built/web/react-common-multiplayer.css +1 -1
- package/built/web/react-common-skillmap.css +1 -1
- package/built/web/rtlreact-common-authcode.css +1 -1
- package/built/web/rtlreact-common-multiplayer.css +1 -1
- package/built/web/rtlreact-common-skillmap.css +1 -1
- package/built/web/rtlsemantic.css +1 -1
- package/built/web/runnerembed.js +1 -1
- package/built/web/semantic.css +1 -1
- package/built/web/skillmap/js/main.6352b119.js +2 -0
- package/built/web/teachertool/js/{main.168add6b.js → main.138b6a8e.js} +2 -2
- package/built/web/tutorialtool/js/{main.16de6eb5.js → main.9b70fa5a.js} +2 -2
- package/localtypings/pxtarget.d.ts +25 -0
- package/localtypings/pxteditor.d.ts +11 -2
- package/package.json +1 -1
- package/react-common/components/controls/Card.tsx +3 -0
- package/react-common/components/controls/Modal.tsx +4 -2
- package/react-common/components/share/Share.tsx +4 -1
- package/react-common/components/share/ShareInfo.tsx +21 -4
- package/react-common/components/theming/SimulatorThemePickerModal.tsx +207 -0
- package/react-common/components/theming/ThemeCard.tsx +6 -4
- package/react-common/components/theming/ThemePickerModal.tsx +65 -4
- package/react-common/components/theming/simulatorThemeDefaults.ts +77 -0
- package/react-common/styles/controls/Modal.less +6 -6
- package/react-common/styles/theming/ThemePickerModal.less +193 -4
- package/theme/pxtjson.less +12 -0
- package/webapp/public/multiplayer.html +1 -1
- package/webapp/public/skillmap.html +1 -1
- package/webapp/public/teachertool.html +1 -1
- package/webapp/public/tutorialtool.html +1 -1
- package/built/web/skillmap/js/main.fb626575.js +0 -2
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2024 Google LLC
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
*/Object.defineProperty(i,"__esModule",{value:!0}),i.setDuplicateOnDragStrategy=i.DuplicateOnDragStrategy=void 0;const n=e("blockly"),s=e("./duplicateOnDrag");class o extends n.dragging.BlockDragStrategy{getTargetBlock(){const e=this;return e.block.isShadow()&&(0,s.isAllowlistedShadow)(e.block)?e.block:super.getTargetBlock()}drag(e,t){if(super.drag(e,t),!t||t instanceof PointerEvent){this.block.moveDuringDrag(e)}}disconnectBlock(e){var t;const i=this;let o,r,a;const l=i.block.isShadow();if(l&&i.block.setShadow(!1),(0,s.shouldDuplicateOnDrag)(i.block)){const e=i.block.outputConnection;if(!(null==e?void 0:e.targetConnection))return;a=n.Xml.blockToDom(i.block,!0),l||(o=n.Xml.domToBlock(a,i.block.workspace)),r=e.targetConnection}e&&(i.startChildConn=null===(t=i.block.nextConnection)||void 0===t?void 0:t.targetConnection),r&&l&&r.setShadowDom(a),i.block.unplug(e),n.blockAnimations.disconnectUiEffect(i.block),(0,s.updateDuplicateOnDragState)(i.block),r&&o&&r.connect(o.outputConnection)}}i.DuplicateOnDragStrategy=o,i.setDuplicateOnDragStrategy=function(e){var t,i;null===(i=(t=e).setDragStrategy)||void 0===i||i.call(t,new o(e))}},{"./duplicateOnDrag":106,blockly:256}],106:[function(e,t,i){"use strict";let n,s;function o(e){return!(!n||-1===n.indexOf(e.type))}function r(e){var t,i;if(e.isShadow()&&o(e))return!0;if(s){const n=null===(t=e.outputConnection)||void 0===t?void 0:t.targetBlock();if(n){const t=s.filter(e=>e.parentBlockType===n.type);for(const n of t)if(n&&(!n.childBlockType||n.childBlockType===e.type)){if(!n.inputName)return!0;if((null===(i=e.outputConnection.targetConnection.getParentInput())||void 0===i?void 0:i.name)===n.inputName)return!0}}}return!1}Object.defineProperty(i,"__esModule",{value:!0}),i.updateDuplicateOnDragState=i.shouldDuplicateOnDrag=i.isAllowlistedShadow=i.setDuplicateOnDrag=i.setDraggableShadowBlocks=void 0,i.setDraggableShadowBlocks=function(e){n=e},i.setDuplicateOnDrag=function(e,t,i){s||(s=[]),s.some(n=>n.parentBlockType===e&&n.inputName===t&&n.childBlockType===i)||s.push({parentBlockType:e,inputName:t,childBlockType:i})},i.isAllowlistedShadow=o,i.shouldDuplicateOnDrag=r,i.updateDuplicateOnDragState=function(e){setTimeout(()=>{const t=r(e);e.pathObject&&e.pathObject.setHasDottedOutlineOnHover(t),e.setDeletable(!t)})}},{}],107:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./duplicateOnDrag"),i),s(e("./variablesGetReporter"),i),s(e("./connectionChecker"),i),s(e("./dragStrategy"),i)},{"./connectionChecker":104,"./dragStrategy":105,"./duplicateOnDrag":106,"./variablesGetReporter":108}],108:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("./duplicateOnDrag");n.Blocks.variables_get_reporter={init:function(){this.jsonInit({type:"variables_get_reporter",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}",variableTypes:[""]}],output:null,colour:"%{BKY_VARIABLES_HUE}",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableReporter"]}),(0,s.updateDuplicateOnDragState)(this)}}},{"./duplicateOnDrag":106,blockly:256}],109:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MultiFlyoutRecyclableBlockInflater=i.HIDDEN_CLASS_NAME=void 0;const n=e("blockly");i.HIDDEN_CLASS_NAME="pxtFlyoutHidden";class s extends n.BlockFlyoutInflater{constructor(){super(...arguments),this.keyToBlock=new Map,this.blockToKey=new Map}static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,"block",s,!0)}isBlockRecycleable(e){switch(e.type){case"variables_get":case"variables_set":case"variables_change":return!1}return!0}createBlock(e,t){const s=function(e){if(e.blockxml)return"string"==typeof e.blockxml?e.blockxml:n.Xml.domToText(e.blockxml);return e.type}(e);if(!s)return super.createBlock(e,t);let o;return this.keyToBlock.has(s)&&(o=this.keyToBlock.get(s),this.keyToBlock.delete(s),t.getCanvas().appendChild(o.getSvgRoot())),o=null!=o?o:super.createBlock(e,t),this.blockToKey.set(o,s),o.removeClass(i.HIDDEN_CLASS_NAME),o.getFocusableElement().ariaHidden="false",o.setDisabledReason(!1,i.HIDDEN_CLASS_NAME),o}disposeItem(e){const t=e.getElement();if(t instanceof n.BlockSvg&&this.blockToKey.has(t)){if(this.isBlockRecycleable(t))return void this.recycleBlock(t);this.blockToKey.delete(t)}super.disposeItem(e)}clearCache(){this.blockToKey=new Map,this.keyToBlock=new Map}recycleBlock(e){const t=e.getRelativeToSurfaceXY();e.moveBy(-t.x,-t.y),e.addClass(i.HIDDEN_CLASS_NAME),e.getFocusableElement().ariaHidden="true",e.setDisabledReason(!0,i.HIDDEN_CLASS_NAME),e.getSvgRoot().remove();const n=this.blockToKey.get(e);this.keyToBlock.set(n,e),this.removeListeners(e.id)}}i.MultiFlyoutRecyclableBlockInflater=s,n.Css.register(`\n.${i.HIDDEN_CLASS_NAME} {\n display: none;\n}\n`)},{blockly:256}],110:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ButtonFlyoutInflater=void 0;const n=e("blockly"),s=e("./flyoutButton"),o="button";class r extends n.ButtonFlyoutInflater{static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,o,r,!0)}load(e,t){const i=new s.FlyoutButton(t.getWorkspace(),t.targetWorkspace,e,!1);return i.show(),new n.FlyoutItem(i,o)}}i.ButtonFlyoutInflater=r},{"./flyoutButton":112,blockly:256}],111:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CachingFlyout=void 0;const n=e("blockly"),s=e("./blockInflater");class o extends n.VerticalFlyout{constructor(){super(...arguments),this.forceOpen=!1}clearBlockCache(){const e=this.getInflaterForType("block");e instanceof s.MultiFlyoutRecyclableBlockInflater&&e.clearCache()}getFlyoutElement(){return this.svgGroup_}setForceOpen(e){this.forceOpen=e}}i.CachingFlyout=o},{"./blockInflater":109,blockly:256}],112:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FlyoutButton=void 0;const n=e("blockly"),s={"":"usb","":"accessible-icon","":"adn","":"pied-piper-pp","":"steam","":"bluetooth-b","":"rebel","":"maxcdn","":"joomla","":"sellsy","":"connectdevelop","":"github-alt"};class o extends n.FlyoutButton{constructor(e,t,i,o){super(e,t,i,o);const r=this.getSvgRoot();if(!o){const e=17.5,t=14,i=this.height;this.width+=2*(e-n.FlyoutButton.TEXT_MARGIN_X),this.height+=2*(t-n.FlyoutButton.TEXT_MARGIN_Y);const s=r.getElementsByClassName("blocklyFlyoutButtonShadow").item(0),o=r.getElementsByClassName("blocklyFlyoutButtonBackground").item(0),a=r.getElementsByTagName("text").item(0);return s.setAttribute("width",String(this.width)),s.setAttribute("height",String(this.height)),o.setAttribute("width",String(this.width)),o.setAttribute("height",String(this.height)),a.setAttribute("x",String(this.width/2)),void a.setAttribute("y",String(parseFloat(a.getAttribute("y"))-i/2+this.height/2))}const a=i;a["web-class"]&&r.classList.add(a["web-class"]);const l=a["web-icon"],c=a["web-icon-class"],u=a["web-icon-color"],h=a["web-icon-image"];if(h){const e=20,t=this.getTargetWorkspace(),i=n.utils.dom.createSvgElement("image",{height:String(e),width:String(e),x:String(t.RTL?this.width+n.FlyoutButton.TEXT_MARGIN_X:n.FlyoutButton.TEXT_MARGIN_X),y:String(this.height/2+n.FlyoutButton.TEXT_MARGIN_Y-e/2)},r);i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",h);const s=e+2*n.FlyoutButton.TEXT_MARGIN_X;this.width+=s;const o=r.getElementsByClassName("blocklyFlyoutLabelBackground").item(0);o.setAttribute("width",String(this.width));for(let e=0;e<r.children.length;e++){const t=r.children.item(e);if(t!==i&&t!==o){const e=Number(t.getAttribute("x"));t.setAttribute("x",e+s+"")}}}else if(l||c){const e=Object.keys(s).includes(l)?"brandIcon":"",t=n.utils.dom.createSvgElement("text",{class:`blocklyFlyoutLabelIcon${c?" "+c:""}${e?" "+e:""}`,x:0,y:0,"text-anchor":"start"},r);l&&(t.textContent=l),u&&t.setAttribute("style","fill: "+u);const i=this.getTargetWorkspace();t.setAttribute("dominant-baseline","central"),t.setAttribute("dy","0"),t.setAttribute("x",(i.RTL?this.width+n.FlyoutButton.TEXT_MARGIN_X:0)+""),t.setAttribute("y",this.height/2+n.FlyoutButton.TEXT_MARGIN_Y+"");const o=n.utils.dom.getTextWidth(t)+2*n.FlyoutButton.TEXT_MARGIN_X;this.width+=o;const a=r.getElementsByClassName("blocklyFlyoutLabelBackground").item(0);a.setAttribute("width",String(this.width));for(let e=0;e<r.children.length;e++){const i=r.children.item(e);if(i!==t&&i!==a){const e=Number(i.getAttribute("x"));i.setAttribute("x",e+o+"")}}}const d=a["web-line"],p=a["web-line-width"];if(d){const e=n.utils.dom.createSvgElement("line",{class:"blocklyFlyoutLine","stroke-dasharray":d,"text-anchor":"middle"},r);e.setAttribute("x1","0"),e.setAttribute("x2",null!=p?p:this.width+""),e.setAttribute("y1",this.height+10+""),e.setAttribute("y2",this.height+10+"")}}isDisposed(){return null===this.getSvgRoot().parentNode}}i.FlyoutButton=o},{blockly:256}],113:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),i.registerFlyoutInflaters=i.MultiFlyoutRecyclableBlockInflater=i.LabelFlyoutInflater=i.ButtonFlyoutInflater=void 0;const o=e("./buttonFlyoutInflater");Object.defineProperty(i,"ButtonFlyoutInflater",{enumerable:!0,get:function(){return o.ButtonFlyoutInflater}});const r=e("./labelFlyoutInflater");Object.defineProperty(i,"LabelFlyoutInflater",{enumerable:!0,get:function(){return r.LabelFlyoutInflater}});const a=e("./blockInflater");Object.defineProperty(i,"MultiFlyoutRecyclableBlockInflater",{enumerable:!0,get:function(){return a.MultiFlyoutRecyclableBlockInflater}}),s(e("./cachingFlyout"),i),i.registerFlyoutInflaters=function(){o.ButtonFlyoutInflater.register(),r.LabelFlyoutInflater.register(),a.MultiFlyoutRecyclableBlockInflater.register()}},{"./blockInflater":109,"./buttonFlyoutInflater":110,"./cachingFlyout":111,"./labelFlyoutInflater":114}],114:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.LabelFlyoutInflater=void 0;const n=e("blockly"),s=e("./flyoutButton"),o="label";class r extends n.LabelFlyoutInflater{static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,o,r,!0)}load(e,t){const i=new s.FlyoutButton(t.getWorkspace(),t.targetWorkspace,e,!0);return i.show(),new n.FlyoutItem(i,o)}}i.LabelFlyoutInflater=r},{"./flyoutButton":112,blockly:256}],115:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../constants"),o={typeName_:"",getTypeName(){return this.typeName_},removeFieldCallback(e){const t=this.getParent();(null==t?void 0:t.removeFieldCallback)&&t.removeFieldCallback(e)}};n.Blocks[s.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"bool"}],extensions:["output_boolean","text_field_color"]}),this.typeName_="boolean"}}),n.Blocks[s.ARGUMENT_EDITOR_STRING_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"text"}],extensions:["output_string","text_field_color"]}),this.typeName_="string"}}),n.Blocks[s.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"num"}],extensions:["output_number","text_field_color"]}),this.typeName_="number"}}),n.Blocks[s.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"list"}],extensions:["output_array","text_field_color"]}),this.typeName_="Array"}}),n.Blocks[s.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"arg"}],outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,extensions:["text_field_color"]}),this.typeName_="any"},mutationToDom(){const e=n.utils.xml.createElement("mutation");return e.setAttribute("typename",this.typeName_),e},domToMutation(e){this.typeName_=e.getAttribute("typename"),this.setOutput(!0,this.typeName_)}})},{"../constants":121,blockly:256}],116:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.LOCALIZATION_NAME_MUTATION_KEY=void 0;const n=e("blockly"),s=e("../constants"),o=e("../msg"),r=e("../../duplicateOnDrag");i.LOCALIZATION_NAME_MUTATION_KEY="localizationname";const a={typeName_:"",localizationName_:"",getTypeName(){return this.typeName_},getLocalizationName(){return this.localizationName_||this.getFieldValue("VALUE")},mutationToDom(){const e=n.utils.xml.createElement("mutation");return this.localizationName_&&e.setAttribute(i.LOCALIZATION_NAME_MUTATION_KEY,this.localizationName_),e},domToMutation(e){e.hasAttribute(i.LOCALIZATION_NAME_MUTATION_KEY)&&(this.localizationName_=e.getAttribute(i.LOCALIZATION_NAME_MUTATION_KEY))}};function l(e){(0,r.setDuplicateOnDragStrategy)(e),(0,r.updateDuplicateOnDragState)(e)}n.Blocks[s.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_boolean"]}),this.typeName_="boolean",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_STRING_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_string"]}),this.typeName_="string",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_number"]}),this.typeName_="number",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_array"]}),this.typeName_="Array",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],inputsInline:!0,outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,output:null}),this.typeName_="",l(this)},mutationToDom(){const e=a.mutationToDom.call(this);return e.setAttribute("typename",this.typeName_),e},domToMutation(e){this.typeName_=e.getAttribute("typename"),this.setOutput(!0,this.typeName_),a.domToMutation.call(this,e)}})},{"../../duplicateOnDrag":107,"../constants":121,"../msg":128,blockly:256}],117:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../msg"),l=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){let s=null,o=null;if(t&&e.id in t){const i=t[e.id];s=i.block,o=i.shadow}const r=null==s?void 0:s.workspace.connectionChecker;n.Events.disable();try{if(s&&!s.isDisposed()&&t&&(null==r?void 0:r.canConnectWithReason(null==s?void 0:s.outputConnection,i.connection,!1))===n.Connection.CAN_CONNECT){let r;s.outputConnection.connect(i.connection),r=s.isShadow()?n.Xml.blockToDom(s):o||this.buildShadowDom_(e.type),"variables_get"!==r.getAttribute("type")&&i.connection.setShadowDom(r),delete t[i.name]}else this.attachShadow_(i,e.type)}finally{n.Events.enable()}},afterWorkspaceLoad:function(){var e;for(const t of this.inputList){if(t.type!==n.inputs.inputTypes.VALUE)continue;const i=null===(e=t.connection)||void 0===e?void 0:e.targetBlock();i&&i.isShadow()&&i.getVarModels().length&&i.setShadow(!1);const s=t.connection&&t.getShadowDom();(0,r.isVariableBlockType)(null==s?void 0:s.getAttribute("type"))&&t.setShadowDom(null)}},addFunctionLabel_:function(e){this.appendDummyInput("function_name").appendField(new n.FieldLabel(e,"functionNameText"),"function_name")},updateFunctionLabel_:function(e){this.getField("function_name").setValue(e)},attachShadow_(e,t){const i=(0,r.getShadowBlockInfoFromType_)(t,this.workspace),s=i[0],o=i[1],a=i[2];n.Events.disable();let l=null;try{l=this.workspace.newBlock(s),l.setFieldValue(a,o),l.setShadow("variables_get"!==s),!this.isInsertionMarker()&&l instanceof n.BlockSvg&&(l.initSvg(),l.queueRender())}finally{n.Events.enable()}l&&(l.setShadow(!0),l.outputConnection.connect(e.connection))},buildShadowDom_(e){const t=n.utils.xml.createElement("shadow"),i=(0,r.getShadowBlockInfoFromType_)(e,this.workspace),s=i[0],o=i[1],a=i[2],l="variables_get"===s;t.setAttribute("type",s);const c=n.utils.xml.createElement("field");if(c.textContent=a,l){c.setAttribute("id",a);const e=this.workspace.getVariableMap().getVariableById(a);c.textContent=e?e.getName():""}return c.setAttribute("name",o),t.appendChild(c),t},onchange(e){var t;if(this.workspace&&!this.workspace.isFlyout)if(e.type==n.Events.BLOCK_CREATE&&-1!=(null===(t=e.ids)||void 0===t?void 0:t.indexOf(this.id))){const t=this.getName(),i=(0,r.getDefinition)(t,this.workspace);if(i){const e=i.getArguments().slice(),t=this.arguments_.slice();JSON.stringify(t)!==JSON.stringify(e)&&(0,r.mutateCallersAndDefinition)(i.getName(),this.workspace,i.mutationToDom()),this.functionId_=i.functionId_}else{n.Events.setGroup(e.group);const t=n.utils.xml.createElement("xml"),i=n.utils.xml.createElement("block");i.setAttribute("type",o.FUNCTION_DEFINITION_BLOCK_TYPE);const s=this.getRelativeToSurfaceXY(),r=s.x+n.config.snapRadius*(this.RTL?-1:1),a=s.y+2*n.config.snapRadius;i.setAttribute("x",r+""),i.setAttribute("y",a+"");const l=this.mutationToDom();i.appendChild(l),t.appendChild(i),n.Xml.domToWorkspace(t,this.workspace),n.Events.setGroup(!1)}}else if(e.type==n.Events.BLOCK_DELETE){const t=this.getName();(0,r.getDefinition)(t,this.workspace)||(n.Events.setGroup(e.group),this.dispose(!0),n.Events.setGroup(!1))}},serializeChangedInputs(e){const t=[],i=(0,r.getArgMap)(e,!0);for(const e of this.arguments_){if(i[e.id])continue;const n=this.getInput(e.id).connection,s=n.targetBlock();s.isShadow()?t.push({inputName:e.id,connectedShadow:n.getShadowState(!0)}):t.push({inputName:e.id,connectedBlock:s.id})}return t}});n.Blocks[o.FUNCTION_CALL_BLOCK_TYPE]=Object.assign(Object.assign({},l),{init:function(){this.jsonInit({extensions:["function_contextmenu_edit"]}),this.name_="",this.arguments_=[],this.functionId_="",this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(n.Msg[a.MsgKey.PROCEDURES_HUE]),this.setHelpUrl(n.Msg[a.MsgKey.PROCEDURES_CALLNORETURN_HELPURL]),this.setTooltip(n.Msg[a.MsgKey.FUNCTION_CALL_TOOLTIP]),this.setInputsInline(!0)}}),n.Blocks[o.FUNCTION_CALL_OUTPUT_BLOCK_TYPE]=Object.assign(Object.assign({},l),{init:function(){this.jsonInit({extensions:["function_contextmenu_edit"]}),this.name_="",this.arguments_=[],this.functionId_="",this.setPreviousStatement(!1),this.setNextStatement(!1),this.setOutput(!0,null),this.setOutputShape((new n.zelos.ConstantProvider).SHAPES.ROUND),this.setColour(n.Msg[a.MsgKey.PROCEDURES_HUE]),this.setHelpUrl(n.Msg[a.MsgKey.PROCEDURES_CALLNORETURN_HELPURL]),this.setTooltip(n.Msg[a.MsgKey.FUNCTION_CALL_TOOLTIP]),this.setInputsInline(!0)}})},{"../commonFunctionMixin":120,"../constants":121,"../msg":128,"../utils":130,blockly:256}],118:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.newFunctionMutation=void 0;const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../fields/fieldAutocapitalizeTextInput"),l=e("../functionManager"),c=e("../msg"),u=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){const n=this.createArgumentEditor_(e.type,e.name);i.connection.connect(n.outputConnection)},addFunctionLabel_:function(e){const t=new a.FieldAutocapitalizeTextInput(e||"",void 0,{spellcheck:!1,disableAutocapitalize:!0});this.appendDummyInput("function_name").appendField(t,"function_name")},updateFunctionLabel_:function(e){n.Events.disable(),this.getField("function_name").setValue(e),n.Events.enable()},createArgumentEditor_:function(e,t){let i;n.Events.disable();try{let s="";switch(e){case"boolean":s=o.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE;break;case"number":s=o.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE;break;case"string":s=o.ARGUMENT_EDITOR_STRING_BLOCK_TYPE;break;case"Array":s=o.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE;break;default:s=o.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE}i=s==o.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE?(0,r.createCustomArgumentEditor)(e,this.workspace):this.workspace.newBlock(s),i.setFieldValue(t,"TEXT"),i.setShadow(!0),!this.isInsertionMarker()&&i instanceof n.BlockSvg&&(i.initSvg(),i.queueRender())}finally{n.Events.enable()}return i},async focusLastEditorAsync_(){if(await n.renderManagement.finishQueuedRenders(),this.inputList.length>0){let e=this.inputList[this.inputList.length-2];if(e.type==n.inputs.inputTypes.DUMMY){const t=this.workspace;t instanceof n.WorkspaceSvg&&t.centerOnBlock(this.id,!0),e.fieldRow[0].showEditor()}else if(e.type==n.inputs.inputTypes.VALUE){const t=e.connection.targetBlock(),i=t.workspace;i instanceof n.WorkspaceSvg&&i.centerOnBlock(t.id,!0),t.getField("TEXT").showEditor()}}},removeFieldCallback(e){let t=null;for(let i=0;i<this.inputList.length&&!t;i++){let n=this.inputList[i];if(n.connection){let i=n.connection.targetBlock();if(!i)continue;i.getField(e.name)===e&&(t=n.name)}else for(let i=0;i<n.fieldRow.length;i++)n.fieldRow[i]==e&&(t=n.name)}t&&(n.WidgetDiv.hide(),this.removeInput(t),this.updateFunctionSignature(),this.updateDisplay_())},addParam_(e,t){n.WidgetDiv.hide();const i=(0,r.findUniqueParamName)(t,this.arguments_.map(e=>e.name));this.arguments_.push({id:n.utils.idGenerator.genUid(),name:i,type:e}),this.updateDisplay_(),this.focusLastEditorAsync_()},addBooleanExternal(){this.addParam_("boolean",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME])},addStringExternal(){this.addParam_("string",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_STRING_ARG_NAME])},addNumberExternal(){this.addParam_("number",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME])},addArrayExternal(){this.addParam_("Array",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME])},addCustomExternal(e){this.addParam_(e,l.FunctionManager.getInstance().getArgumentNameForType(e))},updateFunctionSignature(){this.arguments_=[];for(let e=1;e<this.inputList.length;e++){const t=this.inputList[e];switch(t.type){case n.inputs.inputTypes.STATEMENT:break;case n.inputs.inputTypes.DUMMY:this.name_=t.fieldRow[0].getValue()||t.fieldRow[0].getText();break;case n.inputs.inputTypes.VALUE:const e=t.connection.targetBlock();this.arguments_.push({id:t.name,name:e.getFieldValue("TEXT"),type:e.getTypeName()});break;default:pxt.warn("Unexpected input type on a function mutator root: "+t.type)}}}});i.newFunctionMutation=function(e){const t=(0,r.findLegalName)(n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_FUNCTION_NAME],e),i=n.utils.xml.createElement("mutation");return i.setAttribute("name",t),i.setAttribute("functionid",n.utils.idGenerator.genUid()),i},n.Blocks[o.FUNCTION_DECLARATION_BLOCK_TYPE]=Object.assign(Object.assign({},u),{init:function(){this.jsonInit({style:{hat:"cap"}}),this.name_="",this.arguments_=[],this.functionId_="",this.createAllInputs_(),this.setColour(n.Msg[c.MsgKey.PROCEDURES_HUE]),this.setStatements_(!0),this.setDeletable(!1),this.setMovable(!1),this.contextMenu=!1,this.setInputsInline(!0)}})},{"../commonFunctionMixin":120,"../constants":121,"../fields/fieldAutocapitalizeTextInput":125,"../functionManager":126,"../msg":128,"../utils":130,blockly:256}],119:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../fields/fieldAutocapitalizeTextInput"),l=e("../msg"),c=e("../functionManager"),u=e("../svgs"),h=e("../../duplicateOnDrag"),d=e("../../../fields/field_imagenotext"),p=e("../../../utils"),g=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){let n,s=null;if(null==t?void 0:t[e.id]){s=t[e.id].block}t&&s&&!s.isDisposed()?(n=s,n.setFieldValue(e.name,"VALUE"),delete t[i.name]):n=this.createArgumentReporter_(e),i.connection.connect(n.outputConnection)},afterWorkspaceLoad:function(){for(const e of this.inputList){if(e.type!==n.inputs.inputTypes.VALUE)continue;const t=this.arguments_.find(t=>t.id===e.name);if(!t)continue;let i=e.connection.targetBlock();i||(this.populateArgument_(t,null,e),i=e.connection.targetBlock()),i.setFieldValue(t.name,"VALUE"),i.isShadow()&&i.setShadow(!1),e.setShadowDom(null)}},addFunctionLabel_:function(e){const t=new a.FieldAutocapitalizeTextInput(e||"",r.rename,{spellcheck:!1,disableAutocapitalize:!0});this.appendDummyInput("function_name").appendField(t,"function_name")},updateFunctionLabel_:function(e){n.Events.disable(),this.getField("function_name").setValue(e),n.Events.enable()},createArgumentReporter_:function(e){let t,i="";switch(e.type){case"boolean":i=o.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE;break;case"number":i=o.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE;break;case"string":i=o.ARGUMENT_REPORTER_STRING_BLOCK_TYPE;break;case"Array":i=o.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE;break;default:i=o.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE}n.Events.disable();try{t=i==o.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE?(0,r.createCustomArgumentReporter)(e.type,this.workspace):this.workspace.newBlock(i),t.setFieldValue(e.name,"VALUE"),t.setShadow(!0),!this.isInsertionMarker()&&t instanceof n.BlockSvg&&(t.initSvg(),t.queueRender())}finally{n.Events.enable()}return t},customContextMenu:function(e){var t,i;this.isInFlyout||(null===(i=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===i?void 0:i.readOnly)||(e.push(this.makeEditOption()),e.push(this.makeCallOption()))},makeEditOption:function(){var e,t;return{enabled:!(null===(t=null===(e=this.workspace)||void 0===e?void 0:e.options)||void 0===t?void 0:t.readOnly),text:n.Msg.FUNCTIONS_EDIT_OPTION,callback:()=>{!function(e){if(e.type==o.FUNCTION_CALL_BLOCK_TYPE||e.type==o.FUNCTION_CALL_OUTPUT_BLOCK_TYPE){const t=e.workspace;e=(0,r.getDefinition)(e.getName(),t)}n.hideChaff(),n.getSelected()&&n.getSelected().unselect();c.FunctionManager.getInstance().editFunctionExternal(e.mutationToDom(),t=>{t&&((0,r.mutateCallersAndDefinition)(e.getName(),e.workspace,t),e.updateDisplay_()),setTimeout(()=>{e.afterWorkspaceLoad&&e.afterWorkspaceLoad()})})}(this)}}},makeCallOption:function(){var e,t;const i=this.getName(),s=n.utils.xml.createElement("mutation");s.setAttribute("name",i);const r=n.utils.xml.createElement("block");return r.appendChild(s),r.setAttribute("type",o.FUNCTION_CALL_BLOCK_TYPE),{enabled:this.workspace.remainingCapacity()>0&&!(null===(t=null===(e=this.workspace)||void 0===e?void 0:e.options)||void 0===t?void 0:t.readOnly),text:n.Msg.FUNCTIONS_CREATE_CALL_OPTION.replace("%1",i),callback:n.ContextMenu.callbackFactory(this,r)}}});n.Blocks[o.FUNCTION_DEFINITION_BLOCK_TYPE]=Object.assign(Object.assign({},g),{init:function(){if(this.jsonInit({style:{hat:"cap"}}),this.name_="",this.arguments_=[],this.functionId_="",this.createAllInputs_(),this.setColour(n.Msg[l.MsgKey.PROCEDURES_HUE]),this.setTooltip(n.Msg[l.MsgKey.PROCEDURES_DEFNORETURN_TOOLTIP]),this.setHelpUrl(n.Msg[l.MsgKey.PROCEDURES_DEFNORETURN_HELPURL]),this.setStatements_(!0),this.setInputsInline(!0),this.workspace.options.collapse){const e=u.COLLAPSE_IMAGE_DATAURI;this.appendDummyInput("function_collapse").appendField(new d.FieldImageNoText(e,24,24,lf("Collapse block"),()=>{var e;this.setCollapsed(!0);const t=null===(e=this.inputList.find(e=>e.name===n.constants.COLLAPSED_INPUT_NAME))||void 0===e?void 0:e.fieldRow[1];(0,p.maybeMoveFocusFromButton)(t)},!1))}}}),(0,h.setDuplicateOnDrag)(o.FUNCTION_DEFINITION_BLOCK_TYPE)},{"../../../fields/field_imagenotext":38,"../../../utils":155,"../../duplicateOnDrag":107,"../commonFunctionMixin":120,"../constants":121,"../fields/fieldAutocapitalizeTextInput":125,"../functionManager":126,"../msg":128,"../svgs":129,"../utils":130,blockly:256}],120:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.COMMON_FUNCTION_MIXIN=void 0;const n=e("blockly"),s=e("./constants"),o=e("./utils"),r=e("./msg");i.COMMON_FUNCTION_MIXIN={name_:"",functionId_:"",arguments_:[],mutationToDom:function(){this.ensureIds_();const e=n.utils.xml.createElement("mutation");return e.setAttribute("name",this.name_),e.setAttribute("functionid",this.functionId_),this.arguments_.forEach(function(t){const i=n.utils.xml.createElement("arg");i.setAttribute("name",t.name),i.setAttribute("id",t.id),i.setAttribute("type",t.type),e.appendChild(i)}),e},domToMutation:function(e){const t=[];for(let i=0;i<e.childNodes.length;++i){const n=e.childNodes[i];"arg"==n.nodeName.toLowerCase()&&t.push({id:n.getAttribute("id"),name:n.getAttribute("name"),type:n.getAttribute("type")})}this.arguments_=t,this.name_=e.getAttribute("name"),this.restoreSavedFunctionId(e.getAttribute("functionid"))},saveExtraState:function(){return{name:this.name_,functionid:this.functionId_,arguments:this.arguments_.slice()}},loadExtraState:function(e){this.arguments_=e.arguments.slice(),this.name_=e.name,this.restoreSavedFunctionId(e.functionid)},restoreSavedFunctionId:function(e){(0,o.idsInUse)(this.workspace).indexOf(e)<0&&(this.functionId_=e),this.ensureIds_();let t=null;this instanceof n.BlockSvg&&(t=this.getHeightWidth()),this.type!==s.FUNCTION_DEFINITION_BLOCK_TYPE||t&&!t.height&&!t.width?this.updateDisplay_():!this.getFieldValue("function_name")&&this.name_&&(this.setFieldValue(this.name_,"function_name"),this.updateDisplay_())},getName:function(){return this.name_},getFunctionId:function(){return this.functionId_},getArguments:function(){return this.arguments_},removeValueInputs_:function(){const e=[];for(let t,i=0;t=this.inputList[i];i++)t.type==n.inputs.inputTypes.VALUE?t.dispose():e.push(t);this.inputList=e},createAllInputs_:function(){let e=!1,t=!1;if(this.inputList.forEach(function(i){"function_title"==i.name?e=!0:"function_name"==i.name&&(t=!0)}),!e){let e="";switch(this.type){case s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE:case s.FUNCTION_CALL_BLOCK_TYPE:e=n.Msg[r.MsgKey.FUNCTIONS_CALL_TITLE];break;case s.FUNCTION_DEFINITION_BLOCK_TYPE:case s.FUNCTION_DECLARATION_BLOCK_TYPE:e=n.Msg[r.MsgKey.FUNCTIONS_DEFNORETURN_TITLE]}this.appendDummyInput("function_title").appendField(e,"function_title")}t?this.updateFunctionLabel_(this.getName()):this.addFunctionLabel_(this.getName()),this.updateArgumentInputs_()},updateArgumentInputs_(){var e;for(const e of this.inputList)if(e.type===n.inputs.inputTypes.VALUE&&!this.arguments_.some(t=>t.id===e.name)){if(this.type===s.FUNCTION_DEFINITION_BLOCK_TYPE){const t=e.connection.targetBlock();t&&t.dispose()}this.removeInput(e.name)}let t=this.inputList.findIndex(e=>e.type===n.inputs.inputTypes.VALUE);-1===t&&(t=this.inputList.length);for(const i of this.arguments_){let n=this.inputList.find(e=>e.name===i.id);const s=!n;s&&(n=this.appendValueInput(i.id)),this.inputList.indexOf(n)!==t&&this.moveInputBefore(n.name,null===(e=this.inputList[t+1])||void 0===e?void 0:e.name),(0,o.isCustomType)(i.type)?n.setCheck(i.type):n.setCheck(i.type.charAt(0).toUpperCase()+i.type.slice(1)),!this.isInsertionMarker()&&s&&this.populateArgument_(i,void 0,n),t++}this.inputList.some(e=>"function_collapse"===e.name)&&this.moveInputBefore("function_collapse",null),this.hasStatements_&&this.moveInputBefore("STACK",null)},updateDisplay_:function(){let e=this.rendered;this.createAllInputs_(),e&&!this.isInsertionMarker()&&this instanceof n.BlockSvg&&(this.initSvg(),this.queueRender())},setStatements_:function(e){this.hasStatements_!==e&&(e?this.appendStatementInput("STACK"):this.removeInput("STACK",!0),this.hasStatements_=e)},ensureIds_:function(){switch(this.type){case s.FUNCTION_DEFINITION_BLOCK_TYPE:this.functionId_&&"null"!=this.functionId_||(this.functionId_=n.utils.idGenerator.genUid());for(let e=0;e<this.arguments_.length;++e)this.arguments_[e].id||(this.arguments_[e].id=n.utils.idGenerator.genUid());break;case s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE:case s.FUNCTION_CALL_BLOCK_TYPE:const e=(0,o.getDefinition)(this.name_,this.workspace);if(e){this.functionId_=e.getFunctionId();const t=e.getArguments();for(let e=0;e<this.arguments_.length;++e)for(let i=0;i<t.length;++i)if(t[i].name==this.arguments_[e].name){this.arguments_[e].id=t[i].id;break}}}}}},{"./constants":121,"./msg":128,"./utils":130,blockly:256}],121:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE=i.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE=i.ARGUMENT_EDITOR_STRING_BLOCK_TYPE=i.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE=i.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE=i.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE=i.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE=i.ARGUMENT_REPORTER_STRING_BLOCK_TYPE=i.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE=i.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE=i.FUNCTION_CALL_OUTPUT_BLOCK_TYPE=i.FUNCTION_CALL_BLOCK_TYPE=i.FUNCTION_DECLARATION_BLOCK_TYPE=i.FUNCTION_DEFINITION_BLOCK_TYPE=void 0,i.FUNCTION_DEFINITION_BLOCK_TYPE="function_definition",i.FUNCTION_DECLARATION_BLOCK_TYPE="function_declaration",i.FUNCTION_CALL_BLOCK_TYPE="function_call",i.FUNCTION_CALL_OUTPUT_BLOCK_TYPE="function_call_output",i.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE="argument_reporter_boolean",i.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE="argument_reporter_number",i.ARGUMENT_REPORTER_STRING_BLOCK_TYPE="argument_reporter_string",i.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE="argument_reporter_array",i.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE="argument_reporter_custom",i.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE="argument_editor_boolean",i.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE="argument_editor_number",i.ARGUMENT_EDITOR_STRING_BLOCK_TYPE="argument_editor_string",i.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE="argument_editor_array",i.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE="argument_editor_custom"},{}],122:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("./utils"),o=e("./msg"),r=e("./svgs"),a=new n.zelos.ConstantProvider;const l={customContextMenu:function(e){var t,i;const r={enabled:!(null===(i=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===i?void 0:i.readOnly),text:n.Msg[o.MsgKey.FUNCTIONS_GO_TO_DEFINITION_OPTION],callback:()=>{const e=this.getField("function_name").getText(),t=(0,s.getDefinition)(e,this.workspace);t&&this.workspace instanceof n.WorkspaceSvg&&this.workspace.centerOnBlock(t.id,!0)}};e.push(r)}},c={customContextMenu:function(e){if(this.isCollapsed())return;const t={text:n.Msg.RENAME_VARIABLE,enabled:!this.workspace.options.readOnly,callback:()=>{const e=this.workspace,t=this.getField("VAR").getVariable();n.Variables.renameVariable(e,t)}};if(e.unshift(t),!this.isInFlyout){const t=this.workspace.getVariableMap().getVariablesOfType("");for(const i of t){const t={enabled:!this.workspace.options.readOnly,text:i.getName(),callback:()=>{let e=this.getField("VAR");e||pxt.log("Tried to get a variable field on the wrong type of block."),e.setValue(i.getId())}};e.unshift(t)}}}};n.Extensions.registerMixin("function_contextmenu_edit",l),n.Extensions.registerMixin("contextMenu_variableReporter",c),n.Extensions.register("output_number",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"Number")}),n.Extensions.register("output_string",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"String")}),n.Extensions.register("output_boolean",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.HEXAGONAL),this.setOutput(!0,"Boolean")}),n.Extensions.register("output_array",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"Array")}),n.Extensions.register("text_field_color",function(){if(this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer().getConstants();this.setColour(e.FIELD_BORDER_RECT_COLOUR)}else this.setColour("#fff")}),n.Extensions.register("inline-svgs",function(){this.ADD_IMAGE_DATAURI=r.ADD_IMAGE_DATAURI,this.REMOVE_IMAGE_DATAURI=r.REMOVE_IMAGE_DATAURI})},{"./msg":128,"./svgs":129,"./utils":130,blockly:256}],123:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldArgumentEditor=void 0;const n=e("blockly"),s=e("../functionManager"),o=e("../../../external"),r=e("../msg");class a extends n.FieldTextInput{constructor(e,t,i){super(e,t,i)}showEditor(e){var t,i;super.showEditor(e);const o=n.WidgetDiv.getDiv();o.className+=" argumentEditorInput";const r=document.createElement("img");r.setAttribute("class","argumentEditorRemoveIcon"),r.setAttribute("src",a.REMOVE_ARG_URI),this.removeButtonMouseWrapper_=n.browserEvents.conditionalBind(r,"mousedown",this,this.removeCallback),o.appendChild(r);const l=null===(t=this.sourceBlock_)||void 0===t?void 0:t.getTypeName();if(l&&(null===(i=this.sourceBlock_)||void 0===i?void 0:i.workspace)){const e=s.FunctionManager.getInstance().getIconForType(l);if(e){const t=e+" icon argumentEditorTypeIcon",i=document.createElement("i");i.className=t,o.appendChild(i)}}}showEditor_(e,t=!1,i=!0){this.workspace_=this.sourceBlock_.workspace,!t&&this.workspace_.options.modalInputs&&(n.utils.userAgent.MOBILE||n.utils.userAgent.ANDROID||n.utils.userAgent.IPAD)?this.showPromptEditorModal():super.showEditor_(e,t,i)}showPromptEditorModal(){(0,o.prompt)(n.Msg.CHANGE_VALUE_TITLE,this.getText(),e=>{null!==e&&this.setValue(this.getValueFromEditorText_(e)),this.onFinishEditing_(this.value_)},{placeholder:void 0,buttons:[{label:n.Msg[r.MsgKey.FUNCTIONS_DELETE_PARAMETER_BUTTON],className:"red",icon:"trash",onclick:()=>{this.removeCallback()}}]})}removeCallback(){var e,t;const i=null===(e=this.sourceBlock_)||void 0===e?void 0:e.getParent();if(!i)return;let s;for(const e of i.inputList){if((null===(t=e.connection)||void 0===t?void 0:t.targetBlock())===this.sourceBlock_){s=e.name;break}}s&&(n.WidgetDiv.hide(),i.removeInput(s))}}i.FieldArgumentEditor=a,a.REMOVE_ARG_URI="data:image/svg+xml;charset=UTF-8,%3c?xml version='1.0' encoding='UTF-8' standalone='no'?%3e%3csvg width='20px' height='20px' viewBox='0 0 20 20' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3c!-- Generator: Sketch 48.1 (47250) - http://www.bohemiancoding.com/sketch --%3e%3ctitle%3edelete-argument v2%3c/title%3e%3cdesc%3eCreated with Sketch.%3c/desc%3e%3cdefs%3e%3c/defs%3e%3cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3e%3cg id='delete-argument-v2' stroke='%23FF661A'%3e%3cg id='Group' transform='translate(3.000000, 2.500000)'%3e%3cpath d='M1,3 L13,3 L11.8900496,14.0995037 C11.8389294,14.6107055 11.4087639,15 10.8950124,15 L3.10498756,15 C2.59123611,15 2.16107055,14.6107055 2.10995037,14.0995037 L1,3 Z' id='Rectangle' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M7,11 L7,6' id='Line' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M9.5,11 L9.5,6' id='Line-Copy' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M4.5,11 L4.5,6' id='Line-Copy-2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3crect id='Rectangle-2' fill='%23FF661A' x='0' y='2.5' width='14' height='1' rx='0.5'%3e%3c/rect%3e%3cpath d='M6,0 L8,0 C8.55228475,-1.01453063e-16 9,0.44771525 9,1 L9,3 L5,3 L5,1 C5,0.44771525 5.44771525,1.01453063e-16 6,0 Z' id='Rectangle-3' stroke-width='1.5'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e",n.fieldRegistry.register("field_argument_editor",a),n.Css.register("\n\n.argumentEditorInput {\n overflow: visible;\n}\n\n.functioneditor i.argumentEditorTypeIcon {\n color: var(--pxt-target-foreground1);\n position: absolute;\n width: 24px;\n height: 24px;\n top: 40px;\n left: 50%;\n margin-left: -12px;\n}\n\n.argumentEditorRemoveIcon {\n position: absolute;\n width: 24px;\n height: 24px;\n top: -40px;\n left: 50%;\n margin-left: -12px;\n cursor: pointer;\n}\n\n")},{"../../../external":25,"../functionManager":126,"../msg":128,blockly:256}],124:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.setArgumentReporterLocalizeFunction=i.FieldArgumentReporter=void 0;const n=e("blockly"),s=e("../utils");let o;class r extends n.FieldLabelSerializable{getDisplayText_(){const e=this.getSourceBlock();if(e&&(0,s.isFunctionArgumentReporter)(e)&&o){const t=o(this,e);if(t)return t}return super.getDisplayText_()}}i.FieldArgumentReporter=r,i.setArgumentReporterLocalizeFunction=function(e){o=e},n.registry.register(n.registry.Type.FIELD,"field_argument_reporter",r)},{"../utils":130,blockly:256}],125:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldAutocapitalizeTextInput=void 0;const n=e("blockly");class s extends n.FieldTextInput{constructor(e,t,i){super(e,t,i),this.disableAutocapitalize=!1}setAutocapitalize(e){this.disableAutocapitalize=!e,this.htmlInput_&&(this.disableAutocapitalize?this.htmlInput_.setAttribute("autocapitalize","none"):this.htmlInput_.removeAttribute("autocapitalize"))}configure_(e){super.configure_(e),void 0!==e.disableAutocapitalize&&(this.disableAutocapitalize=e.disableAutocapitalize)}widgetCreate_(){const e=super.widgetCreate_();return this.disableAutocapitalize&&e.setAttribute("autocapitalize","none"),e}}i.FieldAutocapitalizeTextInput=s,n.fieldRegistry.register("field_autocapitalize_text_input",s)},{blockly:256}],126:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FunctionManager=void 0;const n=e("blockly"),s=e("./msg");class o{constructor(){this.typeIcons={},this.typeArgumentNames={}}static getInstance(){return o.instance}getIconForType(e){return this.typeIcons[e]}setIconForType(e,t){this.typeIcons[e]=t}setArgumentNameForType(e,t){this.typeArgumentNames[e]=t}getArgumentNameForType(e){return this.typeArgumentNames[e]?this.typeArgumentNames[e]:n.Msg[s.MsgKey.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME]}setEditFunctionExternal(e){this._editFunctionExternal=e}editFunctionExternal(e,t){this._editFunctionExternal?this._editFunctionExternal(e,t):pxt.warn("External function editor must be overriden: Blockly.Functions.editFunctionExternalHandler",e,t)}}i.FunctionManager=o,o.instance=new o},{"./msg":128,blockly:256}],127:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),i.validateFunctionExternal=i.getAllFunctionDefinitionBlocks=i.getDefinition=i.flyoutCategory=void 0,s(e("./msg"),i),s(e("./extensions"),i),s(e("./fields/fieldArgumentEditor"),i),s(e("./fields/fieldArgumentReporter"),i),s(e("./fields/fieldAutocapitalizeTextInput"),i),s(e("./blocks/argumentEditorBlocks"),i),s(e("./blocks/argumentReporterBlocks"),i),s(e("./blocks/functionDeclarationBlock"),i),s(e("./blocks/functionDefinitionBlock"),i),s(e("./blocks/functionCallBlocks"),i),s(e("./functionManager"),i);var o=e("./utils");Object.defineProperty(i,"flyoutCategory",{enumerable:!0,get:function(){return o.flyoutCategory}}),Object.defineProperty(i,"getDefinition",{enumerable:!0,get:function(){return o.getDefinition}}),Object.defineProperty(i,"getAllFunctionDefinitionBlocks",{enumerable:!0,get:function(){return o.getAllFunctionDefinitionBlocks}}),Object.defineProperty(i,"validateFunctionExternal",{enumerable:!0,get:function(){return o.validateFunctionExternal}})},{"./blocks/argumentEditorBlocks":115,"./blocks/argumentReporterBlocks":116,"./blocks/functionCallBlocks":117,"./blocks/functionDeclarationBlock":118,"./blocks/functionDefinitionBlock":119,"./extensions":122,"./fields/fieldArgumentEditor":123,"./fields/fieldArgumentReporter":124,"./fields/fieldAutocapitalizeTextInput":125,"./functionManager":126,"./msg":128,"./utils":130}],128:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MsgKey=void 0;const n=e("blockly");var s;function o(e,t){n.Msg[e]||(n.Msg[e]=t)}!function(e){e.REPORTERS_HUE="REPORTERS_HUE",e.FUNCTIONS_CALL_TITLE="FUNCTIONS_CALL_TITLE",e.FUNCTIONS_DEFNORETURN_TITLE="FUNCTIONS_DEFNORETURN_TITLE",e.FUNCTIONS_GO_TO_DEFINITION_OPTION="FUNCTIONS_GO_TO_DEFINITION_OPTION",e.FUNCTION_CALL_TOOLTIP="FUNCTION_CALL_TOOLTIP",e.PROCEDURES_HUE="PROCEDURES_HUE",e.PROCEDURES_CALLNORETURN_HELPURL="PROCEDURES_CALLNORETURN_HELPURL",e.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME="FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME",e.FUNCTIONS_DEFAULT_STRING_ARG_NAME="FUNCTIONS_DEFAULT_STRING_ARG_NAME",e.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME="FUNCTIONS_DEFAULT_NUMBER_ARG_NAME",e.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME="FUNCTIONS_DEFAULT_ARRAY_ARG_NAME",e.PROCEDURES_DEFNORETURN_TOOLTIP="PROCEDURES_DEFNORETURN_TOOLTIP",e.PROCEDURES_DEFNORETURN_HELPURL="PROCEDURES_DEFNORETURN_HELPURL",e.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME="FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME",e.FUNCTIONS_DEFAULT_FUNCTION_NAME="FUNCTIONS_DEFAULT_FUNCTION_NAME",e.FUNCTION_CREATE_NEW="FUNCTION_CREATE_NEW",e.FUNCTION_FLYOUT_LABEL="FUNCTION_FLYOUT_LABEL",e.FUNCTIONS_EDIT_OPTION="FUNCTIONS_EDIT_OPTION",e.FUNCTIONS_CREATE_CALL_OPTION="FUNCTIONS_CREATE_CALL_OPTION",e.FUNCTIONS_DELETE_PARAMETER_BUTTON="FUNCTIONS_DELETE_PARAMETER_BUTTON"}(s=i.MsgKey||(i.MsgKey={})),o(s.REPORTERS_HUE,"#A80000"),o(s.FUNCTIONS_CALL_TITLE,"call"),o(s.FUNCTIONS_DEFNORETURN_TITLE,"function"),o(s.FUNCTIONS_GO_TO_DEFINITION_OPTION,"Go to Definition"),o(s.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME,"bool"),o(s.FUNCTIONS_DEFAULT_STRING_ARG_NAME,"text"),o(s.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME,"num"),o(s.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME,"array"),o(s.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME,"value"),o(s.FUNCTIONS_DEFAULT_FUNCTION_NAME,"doSomething"),o(s.FUNCTION_CREATE_NEW,"Make a Function"),o(s.FUNCTION_FLYOUT_LABEL,"Your Functions"),o(s.FUNCTIONS_EDIT_OPTION,"Edit Function"),o(s.FUNCTIONS_CREATE_CALL_OPTION,"Create 'call %1'"),o(s.FUNCTIONS_DELETE_PARAMETER_BUTTON,"Delete")},{blockly:256}],129:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.REMOVE_IMAGE_DATAURI=i.ADD_IMAGE_DATAURI=i.COLLAPSE_IMAGE_DATAURI=void 0,i.COLLAPSE_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.354)'%3E%3Cpath d='m1611 367.42q0 53-37 90l-651 651q-38 38-91 38-54 0-90-38l-651-651q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l486 486 486-486q37-37 90-37 52 0 91 37l75 75q37 39 37 91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A",i.ADD_IMAGE_DATAURI="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4KCjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0icmVwZWF0IgogICB4PSIwcHgiCiAgIHk9IjBweCIKICAgdmlld0JveD0iMCAwIDI0IDI0IgogICBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNCAyNDsiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlua3NjYXBlOnZlcnNpb249IjAuOTEgcjEzNzI1IgogICBzb2RpcG9kaTpkb2NuYW1lPSJhZGQuc3ZnIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGExNSI+PHJkZjpSREY+PGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPjxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PjxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz48ZGM6dGl0bGU+cmVwZWF0PC9kYzp0aXRsZT48L2NjOldvcms+PC9yZGY6UkRGPjwvbWV0YWRhdGE+PGRlZnMKICAgICBpZD0iZGVmczEzIiAvPjxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBwYWdlY29sb3I9IiNmZjQ4MjEiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMSIKICAgICBvYmplY3R0b2xlcmFuY2U9IjEwIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwIgogICAgIGd1aWRldG9sZXJhbmNlPSIxMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTY4MCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI5NjkiCiAgICAgaWQ9Im5hbWVkdmlldzExIgogICAgIHNob3dncmlkPSJmYWxzZSIKICAgICBpbmtzY2FwZTp6b29tPSIxOS42NjY2NjciCiAgICAgaW5rc2NhcGU6Y3g9IjEyLjkxNTI1NCIKICAgICBpbmtzY2FwZTpjeT0iMTYuMDY3Nzk2IgogICAgIGlua3NjYXBlOndpbmRvdy14PSIwIgogICAgIGlua3NjYXBlOndpbmRvdy15PSIwIgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjAiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0icmVwZWF0IiAvPjxzdHlsZQogICAgIHR5cGU9InRleHQvY3NzIgogICAgIGlkPSJzdHlsZTMiPgoJLnN0MHtmaWxsOiNDRjhCMTc7fQoJLnN0MXtmaWxsOiNGRkZGRkY7fQo8L3N0eWxlPjx0aXRsZQogICAgIGlkPSJ0aXRsZTUiPnJlcGVhdDwvdGl0bGU+PHJlY3QKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6I2ZmZmZmZjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MTtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MC4wNzg0MzEzNyIKICAgICBpZD0icmVjdDQxNDMiCiAgICAgd2lkdGg9IjQuMDUwMDAwMiIKICAgICBoZWlnaHQ9IjEyLjM5NzA1IgogICAgIHg9IjkuOTc1MDAwNCIKICAgICB5PSItMTguMTk4NTI2IgogICAgIHJ4PSIwLjgxIgogICAgIHJ5PSIwLjgxIgogICAgIHRyYW5zZm9ybT0ic2NhbGUoMSwtMSkiIC8+PHJlY3QKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6I2ZmZmZmZjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MTtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MC4wNzg0MzEzNyIKICAgICBpZD0icmVjdDQxNDMtMSIKICAgICB3aWR0aD0iNC4wNTAwMDAyIgogICAgIGhlaWdodD0iMTIuMzk3MTE5IgogICAgIHg9IjkuOTc1MDAwNCIKICAgICB5PSI1LjgwMTQ0MDciCiAgICAgcng9IjAuODEiCiAgICAgcnk9IjAuODEiCiAgICAgdHJhbnNmb3JtPSJtYXRyaXgoMCwxLDEsMCwwLDApIiAvPjxjaXJjbGUKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6bm9uZTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6I2ZmZmZmZjtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICBpZD0icGF0aDQxMzYiCiAgICAgY3g9IjEyIgogICAgIGN5PSIxMiIKICAgICByPSIxMC41MDMxOTEiIC8+PC9zdmc+",i.REMOVE_IMAGE_DATAURI="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4KCjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0icmVwZWF0IgogICB4PSIwcHgiCiAgIHk9IjBweCIKICAgdmlld0JveD0iMCAwIDI0IDI0IgogICBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNCAyNDsiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlua3NjYXBlOnZlcnNpb249IjAuOTEgcjEzNzI1IgogICBzb2RpcG9kaTpkb2NuYW1lPSJyZW1vdmUuc3ZnIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGExNSI+PHJkZjpSREY+PGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPjxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PjxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz48ZGM6dGl0bGU+cmVwZWF0PC9kYzp0aXRsZT48L2NjOldvcms+PC9yZGY6UkRGPjwvbWV0YWRhdGE+PGRlZnMKICAgICBpZD0iZGVmczEzIiAvPjxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBwYWdlY29sb3I9IiNmZjFhZmYiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMSIKICAgICBvYmplY3R0b2xlcmFuY2U9IjEwIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwIgogICAgIGd1aWRldG9sZXJhbmNlPSIxMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTY4MCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI5NTAiCiAgICAgaWQ9Im5hbWVkdmlldzExIgogICAgIHNob3dncmlkPSJmYWxzZSIKICAgICBpbmtzY2FwZTp6b29tPSIxOS42NjY2NjciCiAgICAgaW5rc2NhcGU6Y3g9IjAuMDUwODQ3NTIxIgogICAgIGlua3NjYXBlOmN5PSI5Ljk2NjEwMTciCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LW1heGltaXplZD0iMCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJyZXBlYXQiIC8+PHN0eWxlCiAgICAgdHlwZT0idGV4dC9jc3MiCiAgICAgaWQ9InN0eWxlMyI+Cgkuc3Qwe2ZpbGw6I0NGOEIxNzt9Cgkuc3Qxe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU+PHRpdGxlCiAgICAgaWQ9InRpdGxlNSI+cmVwZWF0PC90aXRsZT48cmVjdAogICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDojZmZmZmZmO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lO3N0cm9rZS13aWR0aDoxO3N0cm9rZS1saW5lY2FwOnNxdWFyZTtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eTowLjA3ODQzMTM3IgogICAgIGlkPSJyZWN0NDE0My0xIgogICAgIHdpZHRoPSI0LjA1MDAwMDIiCiAgICAgaGVpZ2h0PSIxMi4zOTcxMTkiCiAgICAgeD0iOS45NzUwMDA0IgogICAgIHk9IjUuODAxNDQwNyIKICAgICByeD0iMC44MSIKICAgICByeT0iMC44MSIKICAgICB0cmFuc2Zvcm09Im1hdHJpeCgwLDEsMSwwLDAsMCkiIC8+PGNpcmNsZQogICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDpub25lO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTojZmZmZmZmO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOnNxdWFyZTtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxIgogICAgIGlkPSJwYXRoNDEzNiIKICAgICBjeD0iMTIiCiAgICAgY3k9IjEyIgogICAgIHI9IjEwLjUwMzE5MSIgLz48L3N2Zz4="},{}],130:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isVariableBlockType=i.validateFunctionExternal=i.flyoutCategory=i.getShadowBlockInfoFromType_=i.findUniqueParamName=i.getArgumentReporterParent=i.doArgumentReporterDragChecks=i.isFunctionArgumentReporter=i.getArgMap=i.mutateCallersAndDefinition=i.idsInUse=i.findLegalName=i.createCustomArgumentEditor=i.createCustomArgumentReporter=i.isCustomType=i.getAllFunctionDefinitionBlocks=i.getDefinition=i.rename=void 0;const n=e("blockly"),s=e("./constants"),o=e("./functionManager"),r=e("./msg"),a=e("./blocks/functionDeclarationBlock"),l=e("../../compiler/util"),c=e("../../loader");function u(e,t){for(const i of t.getTopBlocks(!1))if(i.type===s.FUNCTION_DEFINITION_BLOCK_TYPE){const t=i;if(t.getName()===e)return t}return null}function h(e){return e.getTopBlocks(!1).filter(e=>e.type===s.FUNCTION_DEFINITION_BLOCK_TYPE)}function d(e,t,i){const s=i.newBlock(e),o=n.utils.xml.createElement("mutation");return o.setAttribute("typename",t),s.domToMutation(o),s}function p(e,t,i){if(null==i?void 0:i.isInFlyout)return e;const n=g(t,i);for(;n[e];)e=f(e);return e}function g(e,t,i){const n={};return e.getVariableMap().getAllVariables().forEach(function(e){n[e.getName()]=!0}),e.getAllBlocks(!1).forEach(function(e){const o=e;o==t||i&&o.getFunctionId&&o.getFunctionId()==i||(o.type==s.FUNCTION_DEFINITION_BLOCK_TYPE?n[o.getName()]=!0:"procedures_defreturn"==e.type||e.type)}),n}function f(e){const t=e.match(/^(.*?)(\d+)$/);return t?e=t[1]+(parseInt(t[2],10)+1):e+="2",e}function m(e,t,i){const o=u(e,t);if(o){const r=o.mutationToDom(),a=_(r,!1),l=_(i,!0),c=[];for(const e of o.getDescendants(!1)){if(!b(e))continue;const t=T(e,e);if(t&&t!==o)continue;const i=e.getFieldValue("VALUE"),n=l[a[i]];if(i===n)continue;const s=e.outputConnection.targetBlock().id,r=e.outputConnection.targetConnection.getParentInput().name;c.push({id:e.id,type:e.type,oldName:i,newName:n,targetBlockId:s,targetInputName:r})}const u=function(e,t){const i=[];for(const n of t.getAllBlocks(!1))if(n.type===s.FUNCTION_CALL_BLOCK_TYPE||n.type===s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE){const t=n;t.getName()===e&&i.push(t)}return i}(e,o.workspace).map(e=>({id:e.id,oldMutation:n.utils.xml.domToText(e.mutationToDom()),shadows:e.serializeChangedInputs(i)})),h=new v(o.id,u,n.Xml.domToText(r),n.Xml.domToText(i),c);h.workspaceId=t.id,h.run(!0),n.Events.fire(h)}else pxt.warn("Attempted to change function "+e+", but no definition block was found on the workspace")}function _(e,t){const i={};for(let n=0;n<e.childNodes.length;++n){const s=e.childNodes[n],o=t?s.getAttribute("id"):s.getAttribute("name"),r=t?s.getAttribute("name"):s.getAttribute("id");i[o]=r}return i}function b(e){return e.type==s.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_STRING_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE}function T(e,t){pxt.U.assert(b(e));const i=e.getFieldValue("VALUE"),n=e.getTypeName();for(;t.getSurroundParent();){t=t.getSurroundParent();for(const e of t.inputList){if(!e.connection||!e.name.startsWith(c.DRAGGABLE_PARAM_INPUT_PREFIX))continue;if(e.name.slice(c.DRAGGABLE_PARAM_INPUT_PREFIX.length)!==i)continue;let s=n;return"string"!==s&&"number"!==s&&"boolean"!==s||(s=s.charAt(0).toUpperCase()+s.slice(1)),-1!==e.connection.getCheck().indexOf(s)?t:void 0}}if(!t.isEnabled())return t;if((0,l.isFunctionDefinition)(t)){if(t.getArguments().some(e=>e.name===i&&e.type===n))return t}}function E(e,t){return!t||-1==t.indexOf(e)}i.rename=function(e){e=e.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"");const t=this.sourceBlock_,i=p(e,t.workspace,t),n=this.getValue();if(!e)return n;if(!i)return e;if(!n)return t.name_=i,i;if(n!=e&&n!=i){t.name_=i;const e=t.mutationToDom();t.name_=n,m(n,t.workspace,e)}return i},i.getDefinition=u,i.getAllFunctionDefinitionBlocks=h,i.isCustomType=function(e){return!("boolean"==e||"string"==e||"number"==e)},i.createCustomArgumentReporter=function(e,t){return d(s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE,e,t)},i.createCustomArgumentEditor=function(e,t){return d(s.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE,e,t)},i.findLegalName=p,i.idsInUse=function(e){const t=[];return e.getAllBlocks(!1).forEach(function(e){e.type==s.FUNCTION_DEFINITION_BLOCK_TYPE&&t.push(e.getFunctionId())}),t},i.mutateCallersAndDefinition=m,i.getArgMap=_,i.isFunctionArgumentReporter=b,i.doArgumentReporterDragChecks=function(e,t,i){const n=e.getSourceBlock();if(!b(n))return!0;const s=t.getSourceBlock();return!s||!!T(n,s)},i.getArgumentReporterParent=T,i.findUniqueParamName=function(e,t){for(;!E(e,t);)e=f(e);return e},i.getShadowBlockInfoFromType_=function(e,t){let i="",s="",r="";switch(e){case"boolean":i="logic_boolean",s="BOOL",r="TRUE";break;case"number":i="math_number",s="NUM",r="1";break;case"string":i="text",s="TEXT",r="abc";break;case"Array":i="variables_get",s="VAR",r=n.Variables.getOrCreateVariablePackage(t,null,"list","").getId();break;default:i="variables_get",s="VAR",r=n.Variables.getOrCreateVariablePackage(t,null,o.FunctionManager.getInstance().getArgumentNameForType(e),"").getId()}return[i,s,r]},i.flyoutCategory=function(e){const t=[],i=document.createElement("button"),l=n.Msg[r.MsgKey.FUNCTION_CREATE_NEW],c="CREATE_FUNCTION";i.setAttribute("text",l),i.setAttribute("callbackKey",c),e.registerButtonCallback(c,()=>{!function(e){n.hideChaff(),n.getSelected()&&n.getSelected().unselect();o.FunctionManager.getInstance().editFunctionExternal((0,a.newFunctionMutation)(e),function(e){return function(t){if(t){const i='<xml><block type="'+s.FUNCTION_DEFINITION_BLOCK_TYPE+'">'+n.Xml.domToText(t)+"</block></xml>",o=n.utils.xml.textToDom(i);n.Events.setGroup(!0);const r=n.Xml.domToBlock(o.firstChild,e);if(r.updateDisplay_(),e.getMetrics){const t=e.getMetrics(),i=r.getHeightWidth();r.moveBy(t.viewLeft+t.viewWidth/2-i.width/2,t.viewTop+t.viewHeight/2-i.height/2),r.scheduleSnapAndBump()}e.centerOnBlock(r.id,!0),n.Events.setGroup(!1),setTimeout(()=>{r.afterWorkspaceLoad&&r.afterWorkspaceLoad(),n.getFocusManager().focusNode(r)})}}}(e))}(e)}),t.push(i);for(const i of h(e)){const e=i.getName(),s=i.getArguments(),o=n.utils.xml.createElement("block");o.setAttribute("type","function_call"),o.setAttribute("gap","16");const r=n.utils.xml.createElement("mutation");r.setAttribute("name",e),o.appendChild(r);for(let e=0;e<s.length;e++){const t=n.utils.xml.createElement("arg");t.setAttribute("name",s[e].name),t.setAttribute("type",s[e].type),t.setAttribute("id",s[e].id),r.appendChild(t)}t.push(o)}return t},i.validateFunctionExternal=function(e,t){const i=e.getAttribute("name");if(!i)return n.dialog.alert(n.Msg.FUNCTION_WARNING_EMPTY_NAME),!1;const s={};for(let t=0;t<e.childNodes.length;++t){const i=e.childNodes[t].getAttribute("name");if(!i)return n.dialog.alert(n.Msg.FUNCTION_WARNING_EMPTY_NAME),!1;if(s[i])return n.dialog.alert(n.Msg.FUNCTION_WARNING_DUPLICATE_ARG),!1;s[i]=!0}return s[i]?(n.dialog.alert(n.Msg.FUNCTION_WARNING_ARG_NAME_IS_FUNCTION_NAME),!1):!g(t,null,e.getAttribute("functionid"))[i]||(n.dialog.alert(n.Msg.VARIABLE_ALREADY_EXISTS.replace("%1",i)),!1)},i.isVariableBlockType=function(e){switch(e){case"argument_reporter_boolean":case"argument_reporter_number":case"argument_reporter_string":case"argument_reporter_array":case"argument_reporter_custom":case"variables_get_reporter":case"variables_get":return!0}return!1};class v extends n.Events.Abstract{constructor(e,t,i,n,s){super(),this.definition=e,this.callers=t,this.oldMutation=i,this.newMutation=n,this.descendantChanges=s,this.type="pxt_mutate_function"}static fromJson(e,t,i){const n=i=super.fromJson(e,t,i||new v(e.definition,e.callers,e.oldMutation,e.newMutation,e.descendantChanges));return n.definition=e.definition,n.callers=e.callers,n.oldMutation=e.oldMutation,n.newMutation=e.newMutation,n.descendantChanges=e.descendantChanges,i}toJson(){return{type:this.type,group:this.group,definition:this.definition,callers:this.callers,oldMutation:this.oldMutation,newMutation:this.newMutation,descendantChanges:this.descendantChanges}}run(e){const t=this.getEventWorkspace_(),i=n.utils.xml.textToDom(e?this.newMutation:this.oldMutation),s=t.getBlockById(this.definition);n.Events.disable(),s.domToMutation(i),s.updateArgumentInputs_(),s.afterWorkspaceLoad();for(const s of this.callers){const o=t.getBlockById(s.id);if(e)o.domToMutation(i);else{o.domToMutation(n.utils.xml.textToDom(s.oldMutation));for(const e of s.shadows)if(e.connectedBlock){const i=t.getBlockById(e.connectedBlock);o.getInput(e.inputName).connection.connect(i.outputConnection)}else o.getInput(e.inputName).connection.setShadowState(e.connectedShadow)}}for(const i of this.descendantChanges)if(i.newName){t.getBlockById(i.id).setFieldValue(e?i.newName:i.oldName,"VALUE")}else if(e){const e=t.getBlockById(i.id);e&&e.dispose()}else{const e=t.newBlock(i.type,i.id);e.setFieldValue(i.oldName,"VALUE"),e.initSvg();const n=t.getBlockById(i.targetBlockId).getInput(i.targetInputName).connection,s=n.targetBlock();s&&(s.isShadow()||s.dispose()),n.connect(e.outputConnection)}n.Events.enable()}}},{"../../compiler/util":15,"../../loader":79,"./blocks/functionDeclarationBlock":118,"./constants":121,"./functionManager":126,"./msg":128,blockly:256}],131:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly");n.Extensions.unregister("logic_compare"),n.Extensions.register("logic_compare",function(){})},{blockly:256}],132:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../../fields/field_imagenotext"),o=e("../../utils"),r={elseifCount_:0,elseCount_:0,valueConnections_:[],statementConnections_:[],elseStatementConnection_:null,mutationToDom:function(){if(!this.elseifCount_&&!this.elseCount_)return null;const e=n.utils.xml.createElement("mutation");return this.elseifCount_&&e.setAttribute("elseif",this.elseifCount_+""),this.elseCount_&&e.setAttribute("else","1"),e},domToMutation:function(e){e&&(this.elseifCount_=parseInt(e.getAttribute("elseif"),10)||0,this.elseCount_=parseInt(e.getAttribute("else"),10)||0,this.rebuildShape_())},storeConnections_:function(e){e||(e=0),this.valueConnections_=[null],this.statementConnections_=[null],this.elseStatementConnection_=null;for(let t=1;t<=this.elseifCount_;t++)e!=t&&(this.valueConnections_.push(this.getInput("IF"+t).connection.targetConnection),this.statementConnections_.push(this.getInput("DO"+t).connection.targetConnection));this.getInput("ELSE")&&(this.elseStatementConnection_=this.getInput("ELSE").connection.targetConnection)},restoreConnections_:function(){var e,t;for(let t=1;t<=this.elseifCount_;t++)this.reconnectValueConnection_(t,this.valueConnections_),null===(e=this.statementConnections_[t])||void 0===e||e.reconnect(this,"DO"+t);this.getInput("ELSE")&&(null===(t=this.elseStatementConnection_)||void 0===t||t.reconnect(this,"ELSE"))},addElse_:function(){n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else branch added."));this.update_(()=>{this.elseCount_++})},removeElse_:function(){var e,t;n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else branch removed."));this.update_(()=>{this.elseCount_--});const i="IF"+this.elseifCount_;(0,o.maybeMoveFocusFromButton)(null===(t=null===(e=this.getInput(i))||void 0===e?void 0:e.connection)||void 0===t?void 0:t.targetBlock())},addElseIf_:function(){n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else if branch added."));this.update_(()=>{this.elseifCount_++})},removeElseIf_:function(e){var t,i;n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else if branch removed."));this.update_(()=>{this.elseifCount_--},e);const s="IF"+(e-1);(0,o.maybeMoveFocusFromButton)(null===(i=null===(t=this.getInput(s))||void 0===t?void 0:t.connection)||void 0===i?void 0:i.targetBlock())},update_:function(e,t){n.Events.setGroup(!0),this.storeConnections_(t);const i=this,s=i.mutationToDom(),o=s&&n.Xml.domToText(s);e&&e.call(this),this.updateShape_(),i instanceof n.BlockSvg&&i.initSvg();const r=n.Events.getGroup(),a=i.mutationToDom(),l=a&&n.Xml.domToText(a);o!=l&&(n.Events.fire(new n.Events.BlockChange(i,"mutation",null,o,l)),setTimeout(function(){n.Events.setGroup(r),i.bumpNeighbours(),n.Events.setGroup(!1)},n.config.bumpDelay)),i.rendered&&i instanceof n.BlockSvg&&i.queueRender(),this.restoreConnections_(),n.Events.setGroup(!1)},updateShape_:function(){this.getInput("ELSE")&&(this.removeInput("ELSE"),this.removeInput("ELSETITLE"),this.removeInput("ELSEBUTTONS"));let e=1;for(;this.getInput("IF"+e);)this.removeInput("IF"+e),this.removeInput("IFTITLE"+e),this.removeInput("IFBUTTONS"+e),this.removeInput("DO"+e),e++;for(let e=1;e<=this.elseifCount_;e++){const i=function(e){return function(){t.removeElseIf_(e)}}(e);this.appendValueInput("IF"+e).setCheck("Boolean").appendField(n.Msg.CONTROLS_IF_MSG_ELSEIF).setShadowDom(a()),this.appendDummyInput("IFTITLE"+e).appendField(n.Msg.CONTROLS_IF_MSG_THEN),this.appendDummyInput("IFBUTTONS"+e).appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,pxt.Util.lf("remove else if branch"),i,!1)).setAlign(n.inputs.Align.RIGHT),this.appendStatementInput("DO"+e)}this.elseCount_&&(this.appendDummyInput("ELSETITLE").appendField(n.Msg.CONTROLS_IF_MSG_ELSE),this.appendDummyInput("ELSEBUTTONS").setAlign(n.inputs.Align.RIGHT).appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,pxt.Util.lf("remove else branch"),this.removeElse_.bind(this),!1)),this.appendStatementInput("ELSE")),this.getInput("ADDBUTTON")&&this.removeInput("ADDBUTTON");const t=this,i=function(){var e,i,s;if(0==t.elseCount_)t.addElse_(),(0,o.maybeMoveFocusFromButton)(null===(e=t.getInput("ELSEBUTTONS"))||void 0===e?void 0:e.fieldRow[0]);else{t.elseifCount_||(t.elseifCount_=0),t.addElseIf_();const e=n.getFocusManager(),o=null===(s=null===(i=t.getInput("IF"+t.elseifCount_))||void 0===i?void 0:i.connection)||void 0===s?void 0:s.targetBlock();e.focusNode(o)}};this.appendDummyInput("ADDBUTTON").appendField(new s.FieldImageNoText(this.ADD_IMAGE_DATAURI,24,24,this.elseCount_?pxt.Util.lf("add else if branch"):pxt.Util.lf("add else branch"),i,!1))},rebuildShape_:function(){const e=[null],t=[null];let i=null;this.getInput("ELSE")&&(i=this.getInput("ELSE").connection.targetConnection);let n=1;for(;this.getInput("IF"+n);){const i=this.getInput("IF"+n),s=this.getInput("DO"+n);e.push(i.connection.targetConnection),t.push(s.connection.targetConnection),n++}this.updateShape_(),this.reconnectChildBlocks_(e,t,i)},reconnectChildBlocks_:function(e,t,i){var n;for(let i=1;i<=this.elseifCount_;i++)this.reconnectValueConnection_(i,e),null===(n=t[i])||void 0===n||n.reconnect(this,"DO"+i);null==i||i.reconnect(this,"ELSE")},reconnectValueConnection_:function(e,t){var i;const n=null===(i=this.getInput("IF"+e))||void 0===i?void 0:i.connection.targetBlock();t[e]&&(t[e].reconnect(this,"IF"+e),n&&!n.getParent()&&n.dispose())}};function a(){const e=document.createElement("shadow");e.setAttribute("type","logic_boolean");const t=document.createElement("field");return t.setAttribute("name","BOOL"),t.textContent="FALSE",e.appendChild(t),e}n.Blocks.controls_if=Object.assign(Object.assign({},r),{init(){if(n.Extensions.apply("inline-svgs",this,!1),this.elseifCount_=0,this.elseCount_=0,this.setHelpUrl(n.Msg.CONTROLS_IF_HELPURL),this.appendValueInput("IF0").setCheck("Boolean").appendField(n.Msg.CONTROLS_IF_MSG_IF),this.appendDummyInput("THEN0").appendField(n.Msg.CONTROLS_IF_MSG_THEN),this.appendStatementInput("DO0"),this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer();this.setOutputShape(e.getConstants().SHAPES.HEXAGONAL)}this.updateShape_(),this.setInputsInline(!0),this.setColour(n.Msg.LOGIC_HUE),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setTooltip(()=>this.elseifCount_||this.elseCount_?!this.elseifCount_&&this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_2:this.elseifCount_&&!this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_3:this.elseifCount_&&this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_4:"":n.Msg.CONTROLS_IF_TOOLTIP_1)}})},{"../../fields/field_imagenotext":38,"../../utils":155,blockly:256}],133:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./extensions"),i),s(e("./ifElse"),i)},{"./extensions":131,"./ifElse":132}],134:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldSlider=void 0;const n=e("blockly");class s extends n.FieldNumber{constructor(e,t,i,n,s,o,r,a){super(e,t,i,n,r,a),this.keyboardControlActive=!1,"string"==typeof s?this.step_=parseFloat(s):"number"==typeof s&&(this.step_=s),this.labelText_=o}hasMin(){return this.getMin()>-1/0}hasMax(){return this.getMax()<1/0}getStep(){return this.step_}getLabel(){return this.labelText_}setLabel(e){this.labelText_=e}setOptions(e,t,i,n){this.setConstraints(e,t,n),this.step_=parseFloat(i)||void 0}getFieldDescription(){return this.getValue()+""}doClassValidation_(e){if(null===e)return null;e=(e=(e=(e=`${e}`).replace(/O/gi,"0")).replace(/,/g,"")).replace(/infinity/i,"Infinity");let t=Number(e||0);if(isNaN(t))return null;this.precision_&&isFinite(t)&&(t=Math.round(t/this.precision_)*this.precision_);let i=String(this.precision_);-1!==i.indexOf("e")&&(i=this.precision_.toLocaleString("en-US",{maximumFractionDigits:20}));const n=i.indexOf(".");let s;return s=-1===n?this.precision_?0:null:i.length-n-1,null!==s&&(t=Number(t.toFixed(s))),t}widgetDispose_(){this.removeEventListeners(),super.widgetDispose_()}addEventListeners(){this.inputKeydownHandler=this.inputKeydownListener.bind(this),this.htmlInput_.addEventListener("keydown",this.inputKeydownHandler),this.sliderKeydownHandler=this.sliderKeydownListener.bind(this),this.slider_.addEventListener("keydown",this.sliderKeydownHandler),this.sliderBlurHandler=this.sliderBlurListener.bind(this),this.slider_.addEventListener("blur",this.sliderBlurHandler),this.sliderPointerdownHandler=this.sliderPointerdownListener.bind(this),this.slider_.addEventListener("pointerdown",this.sliderPointerdownHandler)}removeEventListeners(){this.htmlInput_.removeEventListener("keydown",this.inputKeydownHandler),this.slider_.removeEventListener("keydown",this.sliderKeydownHandler),this.slider_.removeEventListener("blur",this.sliderBlurHandler),this.slider_.removeEventListener("pointerdown",this.sliderPointerdownHandler)}inputKeydownListener(e){"ArrowDown"===e.key&&(e.preventDefault(),this.keyboardControlActive=!0,this.slider_.focus())}sliderPointerdownListener(e){this.keyboardControlActive=!1}sliderKeydownListener(e){switch(e.key){case"ArrowUp":e.preventDefault(),this.htmlInput_.focus();break;case"Enter":case" ":e.preventDefault(),e.stopPropagation(),n.hideChaff();break;case"ArrowDown":e.preventDefault(),e.stopPropagation()}}sliderBlurListener(e){this.keyboardControlActive=!1}showEditor_(e,t){super.showEditor_(e,!0),"number"==typeof this.min_&&"number"==typeof this.max_&&(this.htmlInput_.ariaLabel=lf("Enter a value between {0} and {1}",this.min_,this.max_)),n.DropDownDiv.hideWithoutAnimation(),n.DropDownDiv.clearContent();const i=n.DropDownDiv.getContentDiv();i.style.height="",i.parentElement.classList.add("blocklyFieldSliderDropdown"),this.addSlider_(i),n.DropDownDiv.setColour("#ffffff","#dddddd"),n.DropDownDiv.showPositionedByBlock(this,this.sourceBlock_,void 0,void 0,!1),this.addEventListeners(),t||(this.htmlInput_.focus(),this.htmlInput_.select())}addSlider_(e){if(this.labelText_){let t=this.createLabelDom_(this.labelText_);e.appendChild(t[0]),this.readout_=t[1],this.setReadout(this.value_)}this.slider_=this.createSlider(),e.appendChild(this.slider_);const t=()=>{pxt.BrowserUtils.isFirefox()||this.keyboardControlActive||this.htmlInput_.focus()};n.browserEvents.bind(this.slider_,"input",this,e=>{const i=parseFloat(this.slider_.value)||0;if(null!==i){this.setValue(i);const e=this.htmlInput_;e&&(e.value=i+"",t())}}),n.browserEvents.bind(this.slider_,"focus",this,e=>{t()})}setValue(e,t){super.setValue(e,t),this.updateDom(),this.slider_&&(this.slider_.value=this.getValue()+"")}createSlider(){const e=document.createElement("input");let t;return e.setAttribute("class","blocklyFieldSlider"),e.type="range",e.min=this.getMin()+"",e.max=this.getMax()+"",e.value=this.getValue()+"",this.sourceBlock_ instanceof n.BlockSvg&&("#ffffff"===this.sourceBlock_.getColour()?this.sourceBlock_.getParent()&&(t=this.sourceBlock_.getParent().getColourTertiary()):t=this.sourceBlock_.getColourTertiary()),t&&e.setAttribute("style",`--blocklyFieldSliderBackgroundColor: ${t}`),Number.isNaN(this.step_)||(e.step=this.step_+""),e}updateDom(){this.setReadout(this.getValue())}setReadout(e){this.readout_&&(this.readout_.innerText=e+"")}createLabelDom_(e){const t=document.createElement("div");t.setAttribute("class","blocklyFieldSliderLabel");const i=document.createElement("span");i.setAttribute("class","blocklyFieldSliderReadout");const n=document.createElement("span");return n.setAttribute("class","blocklyFieldSliderLabelText"),n.innerText=e,t.appendChild(n),t.appendChild(i),[t,i]}}i.FieldSlider=s,n.fieldRegistry.register("field_slider",s),n.Css.register('\n:root {\n --blocklyFieldSliderBackgroundColor: #547AB2;\n --blocklyFieldSliderThumbColor: #ffffff;\n --blocklyFieldSliderThumbBorderColor: rgba(0, 0, 0, 0.15);\n}\n.blocklyFieldSliderLabel {\n font-family: "Helvetica Neue", "Segoe UI", Helvetica, sans-serif;\n font-size: 0.65rem;\n color: #000000;\n margin: 8px;\n}\n.blocklyFieldSliderLabelText {\n font-weight: bold;\n}\n.blocklyFieldSliderReadout {\n margin-left: 10px;\n}\n\ninput[type=range].blocklyFieldSlider {\n -webkit-appearance: none;\n width: 100%;\n}\ninput[type=range].blocklyFieldSlider:focus {\n outline: none;\n}\ninput[type=range].blocklyFieldSlider::-webkit-slider-runnable-track {\n -webkit-appearance: none;\n margin: 8px;\n height: 22px;\n width: 150px;\n outline: none;\n border-radius: 11px;\n margin-bottom: 20px;\n background: var(--blocklyFieldSliderBackgroundColor);\n}\ninput[type=range].blocklyFieldSlider::-webkit-slider-thumb {\n -webkit-appearance: none;\n width: 26px;\n height: 26px;\n margin-top: -1px;\n background-color: var(--blocklyFieldSliderThumbColor);\n border-radius: 100%;\n -webkit-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n -moz-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n cursor: pointer;\n}\ninput[type=range].blocklyFieldSlider:focus-visible::-webkit-slider-thumb {\n outline: 2px solid white;\n outline-offset: 3px;\n -webkit-box-shadow: 0 0 0 3px var(--pxt-focus-border);\n -moz-box-shadow: 0 0 0 3px var(--pxt-focus-border);\n box-shadow: 0 0 0 3px var(--pxt-focus-border);\n}\ninput[type=range].blocklyFieldSlider::-moz-range-track {\n margin: 8px;\n height: 22px;\n width: 95%;\n outline: none;\n border-radius: 11px;\n margin-bottom: 20px;\n background: var(--blocklyFieldSliderBackgroundColor);\n}\ninput[type=range].blocklyFieldSlider::-moz-range-thumb {\n width: 26px;\n height: 26px;\n margin-top: -1px;\n background-color: var(--blocklyFieldSliderThumbColor);\n border-radius: 100%;\n -webkit-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n -moz-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n cursor: pointer;\n}\n')},{blockly:256}],135:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldSlider"),i),s(e("./numberBlocks"),i)},{"./fieldSlider":134,"./numberBlocks":136}],136:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=new n.zelos.ConstantProvider;n.defineBlocksWithJsonArray([{type:"math_integer",message0:"%1",args0:[{type:"field_number",name:"NUM",precision:1,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_whole_number",message0:"%1",args0:[{type:"field_number",name:"NUM",min:0,precision:1,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_positive_number",message0:"%1",args0:[{type:"field_number",name:"NUM",min:0,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_number_minmax",message0:"%1",args0:[{type:"field_slider",name:"SLIDER",value:0,step:1,labelText:"Number"}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",mutator:"math_number_minmax_mutator",extensions:["parent_tooltip_when_inline"]}]);const o={mutationToDom:function(){const e=this.inputList[0].fieldRow[0];let t=n.utils.xml.createElement("mutation");return e.hasMin()&&t.setAttribute("min",e.getMin()+""),e.hasMax()&&t.setAttribute("max",e.getMax()+""),null!=e.getLabel()&&t.setAttribute("label",e.getLabel()),null!=e.getStep()&&t.setAttribute("step",e.getStep()+""),null!=e.getPrecision()&&t.setAttribute("precision",e.getPrecision()+""),t},domToMutation:function(e){const t=this.inputList[0].fieldRow[0],i=e.getAttribute("min"),n=e.getAttribute("max"),s=e.getAttribute("step"),o=e.getAttribute("label"),r=e.getAttribute("precision");t.setLabel(o),t.setOptions(i,n,s,r)}};n.Extensions.registerMutator("math_number_minmax_mutator",o)},{blockly:256}],137:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldVariable=void 0;const n=e("blockly");class s extends n.FieldVariable{constructor(e,t,i,n,o){super(e,t,i,n,o),this.svgRootBinding=null,this.fieldRootBinding=null,this.menuGenerator_=s.dropdownCreate}static dropdownCreate(){const e=n.FieldVariable.dropdownCreate.call(this),t=e.findIndex(e=>"RENAME_VARIABLE_ID"===e[1]);return e.splice(t,0,[n.Msg.NEW_VARIABLE_DROPDOWN,s.CREATE_VARIABLE_ID],n.FieldDropdown.SEPARATOR),e}onItemSelected_(e,t){if(this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()){if(t.getValue()===s.CREATE_VARIABLE_ID)return void n.Variables.createVariableButtonHandler(this.sourceBlock_.workspace,e=>{const t=this.sourceBlock_.workspace.getVariableMap().getVariable(e);t&&this.setValue(t.getId())})}super.onItemSelected_(e,t)}initView(){super.initView(),this.shouldAddBorderRect_()||(this.createBorderRect_(),this.clickTargetRect=this.borderRect_,this.clickTargetRect.setAttribute("stroke-opacity","0"),this.clickTargetRect.setAttribute("fill-opacity","0"),this.borderRect_=void 0)}shouldAddBorderRect_(){if("variables_get"===this.sourceBlock_.type)return!1;for(const e of this.sourceBlock_.inputList)for(const t of e.fieldRow)if(t!==this&&t.EDITABLE)return!0;return!this.sourceBlock_.getInputsInline()||super.shouldAddBorderRect_()}bindEvents_(){this.shouldAddBorderRect_()?super.bindEvents_():(this.svgRootBinding=n.browserEvents.conditionalBind(this.sourceBlock_.getSvgRoot(),"pointerdown",this,e=>{this.sourceBlock_.icons.length||this.onMouseDown_(e)},!1),this.fieldRootBinding=n.browserEvents.conditionalBind(this.getSvgRoot(),"pointerdown",this,e=>{this.sourceBlock_.icons.length&&this.onMouseDown_(e)},!1))}dispose(){super.dispose(),this.svgRootBinding&&(n.browserEvents.unbind(this.svgRootBinding),n.browserEvents.unbind(this.fieldRootBinding))}positionBorderRect_(){super.positionBorderRect_(),this.clickTargetRect&&(this.clickTargetRect.setAttribute("width",String(this.size_.width)),this.clickTargetRect.setAttribute("height",String(this.size_.height)),this.clickTargetRect.setAttribute("rx",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)),this.clickTargetRect.setAttribute("ry",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)))}getValue(){var e,t;const i=super.getValue();if(null===(e=this.sourceBlock_)||void 0===e?void 0:e.isInFlyout){if((null===(t=this.sourceBlock_.workspace)||void 0===t?void 0:t.getPotentialVariableMap()).getVariableById(i))return"potential_"+i}return i}}i.FieldVariable=s,s.CREATE_VARIABLE_ID="CREATE_VARIABLE",n.fieldRegistry.unregister("field_variable"),n.fieldRegistry.register("field_variable",s)},{blockly:256}],138:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldVariable"),i)},{"./fieldVariable":137}],139:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isCollapsedInputRow=i.CollapsedInputRow=void 0;const n=e("blockly");class s extends n.blockRendering.InputRow{constructor(e){super(e),this.type|=n.blockRendering.Types.INPUT_ROW|n.blockRendering.Types.getType("COLLAPSED_INPUT_ROW")}measure(){this.width=this.minWidth,this.height=this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT}}i.CollapsedInputRow=s,i.isCollapsedInputRow=function(e){return!!(e.type&n.blockRendering.Types.getType("COLLAPSED_INPUT_ROW"))}},{blockly:256}],140:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ConnectionPreviewer=void 0;const n=e("blockly");class s extends n.InsertionMarkerPreviewer{previewConnection(e,t){super.previewConnection(e,t),t.type!==n.ConnectionType.INPUT_VALUE&&t.type!==n.ConnectionType.OUTPUT_VALUE||this.showDraggedIndicatorWithLine(e,t)}previewReplacement(e,t,i){super.previewReplacement(e,t,i),this.showDraggedIndicatorWithLine(e,t)}showDraggedIndicatorWithLine(e,t){if(!this.connectionLine){this.connectionLine=n.utils.dom.createSvgElement("line",{class:"blocklyConnectionLine",x1:0,y1:0,x2:0,y2:0},e.sourceBlock_.getSvgRoot()),this.draggedConnectionIndicator=this.createConnectionIndicator(e.sourceBlock_.getSvgRoot(),e);const i=t.sourceBlock_.getSvgRoot().querySelector(":scope>.blocklyConnectionIndicatorParent");this.staticConnectionIndicator=this.createConnectionIndicator(i,t)}this.raiseIndicators(),this.updateLineCoords(e,t),n.renderManagement.finishQueuedRenders().then(()=>{this.connectionLine&&(this.raiseIndicators(),this.updateLineCoords(e,t))})}raiseIndicators(){var e,t;null===(e=this.draggedConnectionIndicator.parentElement)||void 0===e||e.appendChild(this.draggedConnectionIndicator);const i=this.staticConnectionIndicator.parentElement;i.appendChild(this.staticConnectionIndicator),null===(t=i.parentElement)||void 0===t||t.appendChild(i)}updateLineCoords(e,t){const i=s.CONNECTION_INDICATOR_RADIUS,o=e.getOffsetInBlock(),r=t.getOffsetInBlock();this.draggedConnectionIndicator.setAttribute("transform",`translate(${o.x}, ${o.y})`),this.staticConnectionIndicator.setAttribute("transform",`translate(${r.x}, ${r.y})`);const a=n.utils.Coordinate.sum(e.sourceBlock_.getRelativeToSurfaceXY(),o),l=n.utils.Coordinate.sum(t.sourceBlock_.getRelativeToSurfaceXY(),r),c=l.x-a.x,u=l.y-a.y;if(Math.sqrt(c*c+u*u)<2*i+1)return void n.utils.dom.addClass(this.connectionLine,"hidden");n.utils.dom.removeClass(this.connectionLine,"hidden");const h=Math.atan2(u,c);this.connectionLine.setAttribute("x1",String(o.x+Math.cos(h)*i)),this.connectionLine.setAttribute("y1",String(o.y+Math.sin(h)*i)),this.connectionLine.setAttribute("x2",String(o.x+c-Math.cos(h)*i)),this.connectionLine.setAttribute("y2",String(o.y+u-Math.sin(h)*i))}hidePreview(){super.hidePreview(),this.connectionLine&&(this.connectionLine.remove(),this.connectionLine=null,this.draggedConnectionIndicator.remove(),this.draggedConnectionIndicator=null,this.staticConnectionIndicator.remove(),this.staticConnectionIndicator=null,this.staticConnection=null)}createConnectionIndicator(e,t){const i=n.utils.dom.createSvgElement("g",{class:"blocklyInputConnectionIndicator"},e);n.utils.dom.createSvgElement("circle",{r:s.CONNECTION_INDICATOR_RADIUS},i);const o=t.getOffsetInBlock();return i.setAttribute("transform","translate("+o.x+","+o.y+")"),i}}i.ConnectionPreviewer=s,s.CONNECTION_INDICATOR_RADIUS=9},{blockly:256}],141:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ConstantProvider=void 0;const n=e("blockly");class s extends n.zelos.ConstantProvider{constructor(){super(...arguments),this.FIELD_TEXT_FONTFAMILY='"Consolas", "Monaco", "Menlo", "Ubuntu Mono", "source-code-pro", monospace',this.FIELD_TEXT_FONTWEIGHT="600",this.HIGHLIGHT_GLOW_COLOUR="#FFF200",this.ERROR_HIGHLIGHT_GLOW_COLOR="#FF0000",this.HIGHLIGHT_GLOW_SIZE=1.1,this.ELLIPSES_RADIUS=6,this.ELLIPSES_SPACING=8,this.ellipses=this.makeEllipses()}createDom(e,t,i){super.createDom(e,t,i);const s=n.utils.dom.createSvgElement(n.utils.Svg.DEFS,{},e);this.highlightOutlineFilter=this.createHighlight(s,"blocklyHighlightedGlowFilter",this.HIGHLIGHT_GLOW_COLOUR),this.highlightOutlineFilterId=this.highlightOutlineFilter.id,this.errorOutlineFilter=this.createHighlight(s,"blocklyErrorHighlightedGlowFilter",this.ERROR_HIGHLIGHT_GLOW_COLOR),this.errorOutlineFilterId=this.errorOutlineFilter.id,this.embossFilterOverride=this.createOutline(s,"blocklyBubbleEmbossGlowFilter"),this.embossFilterId=this.embossFilterOverride.id}dispose(){super.dispose(),this.highlightOutlineFilter&&n.utils.dom.removeNode(this.highlightOutlineFilter)}makeEllipses(){const e=this.ELLIPSES_RADIUS,t=this.ELLIPSES_SPACING;let i="";for(let s=0;s<3;s++)i+=n.utils.svgPaths.moveBy(t,0)+n.utils.svgPaths.arc("a","180 1,1",e,n.utils.svgPaths.point(2*e,0));for(let s=0;s<3;s++)i+=n.utils.svgPaths.arc("a","180 1,1",e,n.utils.svgPaths.point(2*-e,0))+n.utils.svgPaths.moveBy(-t,0);return i}getCSS_(e){return super.getCSS_(e).concat([e+" .blocklyConnectionIndicator, "+e+" .blocklyInputConnectionIndicator {","fill: #ff0000;","stroke: #ffff00;","stroke-width: 3px;","}",e+" .blocklyConnectionIndicator {","display: none;","}",e+" .blocklyBlockDragSurface > g > .blocklyDraggable > .blocklyConnectionIndicator {","display: block;","}",e+" .blocklyConnectionLine {","stroke: #ffff00;","stroke-width: 4px;","}",e+" .blocklyConnectionLine.hidden {","display: none;","}",e+" .blocklyFlyoutHeading .blocklyFlyoutLabelText {font-size: 1.5rem;","}",`${e} .blocklyText::selection {`,"fill: #fff;","}",`${e} .blocklyNonEditableField>text::selection,`,`${e} .blocklyEditableField>text::selection,`,`${e} .blocklyNonEditableField>g>text::selection,`,`${e} .blocklyEditableField>g>text::selection {`,"fill: #575E75;","}",`${e} .blocklyDropdownText::selection {`,"fill: #fff !important;","}"])}createHighlight(e,t,i){const s=n.utils.dom.createSvgElement(n.utils.Svg.FILTER,{id:t+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},e);n.utils.dom.createSvgElement(n.utils.Svg.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:this.HIGHLIGHT_GLOW_SIZE},s);const o=n.utils.dom.createSvgElement(n.utils.Svg.FECOMPONENTTRANSFER,{result:"outBlur"},s);return n.utils.dom.createSvgElement(n.utils.Svg.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},o),n.utils.dom.createSvgElement(n.utils.Svg.FEFLOOD,{"flood-color":i,"flood-opacity":1,result:"outColor"},s),n.utils.dom.createSvgElement(n.utils.Svg.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},s),s}createOutline(e,t){const i=n.utils.dom.createSvgElement(n.utils.Svg.FILTER,{id:t+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},e);n.utils.dom.createSvgElement(n.utils.Svg.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:.92},i);const s=n.utils.dom.createSvgElement(n.utils.Svg.FECOMPONENTTRANSFER,{result:"outBlur"},i);n.utils.dom.createSvgElement(n.utils.Svg.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},s),n.utils.dom.createSvgElement(n.utils.Svg.FEFLOOD,{"flood-color":"#000000","flood-opacity":.5,result:"outColor"},i),n.utils.dom.createSvgElement(n.utils.Svg.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},i);const o=n.utils.dom.createSvgElement("feMerge",{},i);return n.utils.dom.createSvgElement("feMergeNode",{in:"outBlur"},o),n.utils.dom.createSvgElement("feMergeNode",{in:"outGlow"},o),n.utils.dom.createSvgElement("feMergeNode",{in:"SourceGraphic"},o),i}shapeFor(e){let t=e.getCheck();switch(!t&&e.targetConnection&&(t=e.targetConnection.getCheck()),e.type){case n.ConnectionType.INPUT_VALUE:case n.ConnectionType.OUTPUT_VALUE:return t&&t.includes("Boolean")?this.HEXAGONAL:(t&&t.includes("Number")||t&&t.includes("String"),this.ROUNDED);case n.ConnectionType.PREVIOUS_STATEMENT:case n.ConnectionType.NEXT_STATEMENT:return this.NOTCH;default:throw Error("Unknown type")}}}i.ConstantProvider=s,s.COLLAPSE_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.354)'%3E%3Cpath d='m1611 367.42q0 53-37 90l-651 651q-38 38-91 38-54 0-90-38l-651-651q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l486 486 486-486q37-37 90-37 52 0 91 37l75 75q37 39 37 91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A",s.EXPAND_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.654)'%3E%3Cpath d='m1611 832q0-53-37-90l-651-651q-38-38-91-38-54 0-90 38l-651 651q-38 36-38 90 0 53 38 91l74 75q39 37 91 37 53 0 90-37l486-486 486 486q37 37 90 37 52 0 91-37l75-75q37-39 37-91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A"},{blockly:256}],142:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});e("blockly").Css.register("\n.blocklyDropdownMenu .blocklyMenuItemCheckbox {\n filter: contrast(0) brightness(100);\n}\n\n.blocklyVerticalMarker {\n fill: none;\n}\n")},{blockly:256}],143:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Drawer=void 0;const n=e("blockly"),s=e("./collapsedInputRow");class o extends n.zelos.Drawer{drawCollapsedStack_(e){const t=this.constants_.STATEMENT_INPUT_NOTCH_OFFSET+this.constants_.INSIDE_CORNERS.width,i=this.constants_.STATEMENT_INPUT_PADDING_LEFT+2*this.constants_.INSIDE_CORNERS.width+n.utils.svgPaths.lineOnAxis("h",-this.constants_.INSIDE_CORNERS.width)+this.constants_.INSIDE_CORNERS.pathTop,s=e.height-2*this.constants_.INSIDE_CORNERS.height,o=this.constants_.INSIDE_CORNERS.pathBottom+n.utils.svgPaths.lineOnAxis("h",this.constants_.INSIDE_CORNERS.width),r=this.constants_.ellipses;this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.bottomRight+n.utils.svgPaths.lineOnAxis("H",t)+i+n.utils.svgPaths.lineOnAxis("v",s/2)+r+n.utils.svgPaths.lineOnAxis("v",s/2)+o+n.utils.svgPaths.lineOnAxis("H",e.xPos+e.width-this.constants_.OUTSIDE_CORNERS.rightHeight)+this.constants_.OUTSIDE_CORNERS.topRight}drawOutline_(){if(this.info_.outputConnection&&this.info_.outputConnection.isDynamicShape&&!this.info_.hasStatementInput&&!this.info_.bottomRow.hasNextConnection)this.drawFlatTop_(),this.drawRightDynamicConnection_(),this.drawFlatBottom_(),this.drawLeftDynamicConnection_();else{this.drawTop_();for(let e=1;e<this.info_.rows.length-1;e++){const t=this.info_.rows[e];t.hasJaggedEdge?this.drawJaggedEdge_(t):(0,s.isCollapsedInputRow)(t)?this.drawCollapsedStack_(t):t.hasStatement?this.drawStatementInput_(t):t.hasExternalInput?this.drawValueInput_(t):this.drawRightSideRow_(t)}this.drawBottom_(),this.drawLeft_()}}drawLeft_(){super.drawLeft_();if(this.info_.rows.find(function(e){return(0,s.isCollapsedInputRow)(e)})){let e=this.info_.startY;n.blockRendering.Types.isLeftRoundedCorner(this.info_.topRow.elements[0])&&(e+=this.constants_.OUTSIDE_CORNERS.rightHeight),this.outlinePath_=this.outlinePath_.slice(0,-1),this.outlinePath_+=n.utils.svgPaths.lineOnAxis("V",e)}}}i.Drawer=o},{"./collapsedInputRow":139,blockly:256}],144:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./renderer"),i),s(e("./connectionPreviewer"),i),s(e("./css"),i)},{"./connectionPreviewer":140,"./css":142,"./renderer":147}],145:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.RenderInfo=void 0;const n=e("blockly"),s=e("./collapsedInputRow");class o extends n.zelos.RenderInfo{measure(){if(this.block_)for(const e of this.block_.inputList)e.init();super.measure()}createRows_(){this.populateTopRow_(),this.rows.push(this.topRow);let e=new n.blockRendering.InputRow(this.constants_);this.inputRows.push(e);const t=this.block_.getIcons();for(let i,s=0;i=t[s];s++){const t=new n.blockRendering.Icon(this.constants_,i);this.isCollapsed&&!i.isShownWhenCollapsed()||e.elements.push(t)}let i;for(let t,s=0;t=this.block_.inputList[s];s++)if(t.isVisible()){this.shouldStartNewRow_(t,i)&&(this.rows.push(e),e=new n.blockRendering.InputRow(this.constants_),this.inputRows.push(e));for(let i,s=0;i=t.fieldRow[s];s++)e.elements.push(new n.blockRendering.Field(this.constants_,i,t));this.addInput_(t,e),i=t}if(this.isCollapsed){this.block_.inputList.find(function(e){return e.type==n.inputs.inputTypes.STATEMENT})?e=this.addCollapsedRow_(e):(e.hasJaggedEdge=!0,e.elements.push(new n.blockRendering.JaggedEdge(this.constants_)))}(e.elements.length||e.hasDummyInput)&&this.rows.push(e),this.populateBottomRow_(),this.rows.push(this.bottomRow)}populateBottomRow_(){this.bottomRow.hasNextConnection=!!this.block_.nextConnection;const e=this.block_.inputList.length&&this.block_.inputList[this.block_.inputList.length-1]instanceof n.inputs.StatementInput||this.rows.some(e=>(0,s.isCollapsedInputRow)(e));this.bottomRow.minHeight=e?this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT:this.constants_.BOTTOM_ROW_MIN_HEIGHT;this.bottomRow.hasLeftSquareCorner(this.block_)?this.bottomRow.elements.push(new n.blockRendering.SquareCorner(this.constants_)):this.bottomRow.elements.push(new n.blockRendering.RoundCorner(this.constants_)),this.bottomRow.hasNextConnection&&(this.bottomRow.connection=new n.blockRendering.NextConnection(this.constants_,this.block_.nextConnection),this.bottomRow.elements.push(this.bottomRow.connection));this.bottomRow.hasRightSquareCorner(this.block_)?this.bottomRow.elements.push(new n.blockRendering.SquareCorner(this.constants_,"right")):this.bottomRow.elements.push(new n.blockRendering.RoundCorner(this.constants_,"right"))}addCollapsedRow_(e){this.rows.push(e);const t=new s.CollapsedInputRow(this.constants_);return t.hasDummyInput=!0,t}}i.RenderInfo=o},{"./collapsedInputRow":139,blockly:256}],146:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PathObject=void 0;const n=e("blockly"),s="blockly-dotted-outline-on-hover",o="hover";class r extends n.zelos.PathObject{constructor(){super(...arguments),this.connectionPointIndicators=new WeakMap}setPath(e){super.setPath(e),this.svgPathHighlighted&&this.svgPathHighlighted.setAttribute("d",e)}updateHighlighted(e){if(e){if(!this.svgPathHighlighted){const e=this.constants,t=this.hasError?e.errorOutlineFilterId:e.highlightOutlineFilterId;this.svgPathHighlighted=this.svgPath.cloneNode(!0),this.svgPathHighlighted.classList.add("pxtRendererHighlight"),this.svgPathHighlighted.setAttribute("fill","none"),this.svgPathHighlighted.setAttribute("filter","url(#"+t+")"),this.svgRoot.appendChild(this.svgPathHighlighted)}}else this.svgPathHighlighted&&(this.svgRoot.removeChild(this.svgPathHighlighted),this.svgPathHighlighted=null)}updateSelected(e){e&&this.svgPath.classList.remove(o),super.updateSelected(e)}addConnectionHighlight(e,t,i,s){const o=super.addConnectionHighlight(e,t,i,s);return this.staticConnectionIndicatorParentGroup?this.svgRoot.appendChild(this.staticConnectionIndicatorParentGroup):this.staticConnectionIndicatorParentGroup=n.utils.dom.createSvgElement("g",{class:"blocklyConnectionIndicatorParent"},this.svgRoot),o}removeConnectionHighlight(e){var t;null===(t=this.staticConnectionIndicatorParentGroup)||void 0===t||t.remove(),super.removeConnectionHighlight(e)}applyColour(e){if(super.applyColour(e),e.outputConnection){let t=!1;const i=e.getParent();if(i)if(e.isShadow()){const e=i.style.colourTertiary,s=function(e){return(.2126*e[0]+.7152*e[1]+.0722*e[2])/255}(n.utils.colour.hexToRgb(e));s<.15&&(this.svgPath.setAttribute("stroke",n.utils.colour.blend("#ffffff",e,.3)),t=!0)}else{const s=i.style.colourPrimary,o=e.style.colourPrimary;if(s===o){const e=.6,i=n.utils.colour.blend("#0000000",o,e),r=n.utils.colour.blend("#ffffff",o,e);pxt.contrastRatio(i,s)>pxt.contrastRatio(r,s)?this.svgPath.setAttribute("stroke",i):this.svgPath.setAttribute("stroke",r),t=!0}}t||this.svgPath.setAttribute("stroke",e.style.colourTertiary)}}setHasDottedOutlineOnHover(e){this.hasDottedOutlineOnHover=e,e?(this.svgPath.classList.add(s),this.mouseOverData||(this.mouseOverData=n.browserEvents.bind(this.svgRoot,"mouseover",this,()=>{this.svgPath.classList.add(o)}),this.mouseLeaveData=n.browserEvents.bind(this.svgRoot,"mouseleave",this,()=>{this.svgPath.classList.remove(o)}))):(this.svgPath.classList.remove(s),this.mouseOverData&&(n.browserEvents.unbind(this.mouseOverData),n.browserEvents.unbind(this.mouseLeaveData),this.mouseOverData=void 0,this.mouseLeaveData=void 0),this.svgPath.classList.remove(s))}setHasError(e){this.hasError=e}isHighlighted(){return!!this.svgPathHighlighted}}i.PathObject=r,r.CONNECTION_INDICATOR_RADIUS=9,n.Css.register("\n.blockly-dotted-outline-on-hover {\n transition: stroke .4s;\n}\n.blockly-dotted-outline-on-hover.hover {\n stroke-dasharray: 2;\n stroke: white;\n stroke-width: 2;\n}\n.blocklyDisabledPattern>.blocklyPath.pxtRendererHighlight {\n fill: none;\n}\n")},{blockly:256}],147:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Renderer=void 0;const n=e("blockly"),s=e("./pathObject"),o=e("./constants"),r=e("./info"),a=e("./drawer");class l extends n.zelos.Renderer{makePathObject(e,t){return new s.PathObject(e,t,this.getConstants())}makeConstants_(){return new o.ConstantProvider}makeRenderInfo_(e){return new r.RenderInfo(this,e)}makeDrawer_(e,t){return new a.Drawer(e,t)}render(e){e.updateBeforeRender&&e.updateBeforeRender(),super.render(e)}}i.Renderer=l,n.blockRendering.register("pxt",l)},{"./constants":141,"./drawer":143,"./info":145,"./pathObject":146,blockly:256}],148:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldString=void 0;const n=e("blockly");class s extends n.FieldTextInput{initView(){this.quoteSize_=16,this.quoteWidth_=8,this.quoteLeftX_=0,this.quoteRightX_=0,this.quoteY_=10,this.quoteLeft_&&this.quoteLeft_.parentNode.removeChild(this.quoteLeft_),this.quoteLeft_=n.utils.dom.createSvgElement("text",{"font-size":this.quoteSize_+"px",class:"field-text-quote","aria-hidden":"true"},this.fieldGroup_),super.initView(),this.quoteRight_&&this.quoteRight_.parentNode.removeChild(this.quoteRight_),this.quoteRight_=n.utils.dom.createSvgElement("text",{"font-size":this.quoteSize_+"px",class:"field-text-quote","aria-hidden":"true"},this.fieldGroup_),this.quoteLeft_.appendChild(document.createTextNode('"')),this.quoteRight_.appendChild(document.createTextNode('"'))}updateSize_(e){super.updateSize_(e);const t=this.value_?this.size_.width:1;let i=this.positionLeft(t+3);this.textElement_.setAttribute("x",i+""),i+=this.positionRight(i+t+3),this.size_.width=t+i}positionLeft(e){if(!this.quoteLeft_)return 0;let t=0;return this.sourceBlock_.RTL?(this.quoteLeftX_=e+this.quoteWidth_+2*s.quotePadding,t=this.quoteWidth_+s.quotePadding):(this.quoteLeftX_=0,t=this.quoteWidth_+s.quotePadding),this.quoteLeft_.setAttribute("transform","translate("+this.quoteLeftX_+","+this.quoteY_+")"),t}positionRight(e){if(!this.quoteRight_)return 0;let t=0;return this.sourceBlock_.RTL?(this.quoteRightX_=s.quotePadding,t=this.quoteWidth_+s.quotePadding):(this.quoteRightX_=e+s.quotePadding,t=this.quoteWidth_+s.quotePadding),this.quoteRight_.setAttribute("transform","translate("+this.quoteRightX_+","+this.quoteY_+")"),t}}i.FieldString=s,s.quotePadding=0,n.Css.register("\n.field-text-quote {\n fill: #a31515 !important;\n}\n"),n.fieldRegistry.register("field_string",s)},{blockly:256}],149:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldString"),i),s(e("./text"),i),s(e("./join"),i)},{"./fieldString":148,"./join":150,"./text":151}],150:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../../fields/field_imagenotext"),o=e("../../utils"),r={itemCount_:0,valueConnections_:[],buttons:null,delta:0,mutationToDom:function(){const e=n.utils.xml.createElement("mutation");return e.setAttribute("items",this.itemCount_+""),e},domToMutation:function(e){this.itemCount_=parseInt(e.getAttribute("items"),10),this.updateShape_()},storeValueConnections_:function(){this.valueConnections_=[];for(let e=0;e<this.itemCount_;e++)this.valueConnections_.push(this.getInput("ADD"+e).connection.targetConnection)},restoreValueConnections_:function(){var e;for(let t=0;t<this.itemCount_;t++)null===(e=this.valueConnections_[t])||void 0===e||e.reconnect(this,"ADD"+t)},addItem_:function(){this.storeValueConnections_();if(this.delta=1,this.update_(()=>{this.itemCount_++}),this.restoreValueConnections_(),this.itemCount_>1){const e=this.getInput("ADD0");if(e&&e.connection.targetConnection){const t=this.getInput("ADD"+(this.itemCount_-1)),i=e.connection.getShadowDom();if(i){const e=n.utils.xml.createElement("shadow"),s=i.getAttribute("type");e.setAttribute("type",s),e&&(e.setAttribute("id",n.utils.idGenerator.genUid()),t.connection.setShadowDom(e))}}}},removeItem_:function(){this.storeValueConnections_();this.delta=-1,this.update_(()=>{this.itemCount_--}),this.restoreValueConnections_()},update_:function(e){n.Events.setGroup(!0);const t=this,i=t.mutationToDom(),s=i&&n.Xml.domToText(i);e&&e.call(this),this.updateShape_(),t instanceof n.BlockSvg&&t.initSvg();const r=n.Events.getGroup(),a=t.mutationToDom(),l=a&&n.Xml.domToText(a);s!=l&&(n.Events.fire(new n.Events.BlockChange(t,"mutation",null,s,l)),setTimeout(function(){n.Events.setGroup(r),t.bumpNeighbours(),n.Events.setGroup(!1)},n.config.bumpDelay)),t.rendered&&t instanceof n.BlockSvg&&t.queueRender().then(()=>{if(this.buttons){let e=this.buttons.fieldRow[0];this.buttons.fieldRow.length>1&&(e=this.delta<0?e:this.buttons.fieldRow[1]),(0,o.maybeMoveFocusFromButton)(e),this.buttons=null,this.delta=0}}),n.Events.setGroup(!1)},updateShape_:function(){const e=this,t=function(){e.removeItem_()};let i;for(this.getInput("EMPTY")&&this.removeInput("EMPTY"),this.getInput("TITLE")||this.appendDummyInput("TITLE").appendField(n.Msg.TEXT_JOIN_TITLE_CREATEWITH),i=0;i<this.itemCount_;i++)if(!this.getInput("ADD"+i)){this.appendValueInput("ADD"+i).setAlign(n.inputs.Align.LEFT).setAriaLabelProvider(n.Msg.INPUT_LABEL_TEXT_JOIN_ITEM.replace("%1",(i+1).toString()))}for(;this.getInput("ADD"+i);)this.removeInput("ADD"+i),i++;this.getInput("BUTTONS")&&this.removeInput("BUTTONS"),this.buttons=this.appendDummyInput("BUTTONS"),this.itemCount_>1&&this.buttons.appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,lf("remove argument"),t,!1)),this.buttons.appendField(new s.FieldImageNoText(this.ADD_IMAGE_DATAURI,24,24,lf("add argument"),function(){e.addItem_()},!1));const o=this.itemCount_<=4;if(this.setInputsInline(o),this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer();this.setOutputShape(o?e.getConstants().SHAPES.ROUND:e.getConstants().SHAPES.SQUARE)}}};n.Extensions.registerMutator("pxt_text_join_mutator",r,function(){n.Extensions.apply("inline-svgs",this,!1),this.itemCount_=2,this.updateShape_()}),n.defineBlocksWithJsonArray([{type:"text_join",message0:"",output:"String",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,style:"text_blocks",helpUrl:"%{BKY_TEXT_JOIN_HELPURL}",tooltip:"%{BKY_TEXT_JOIN_TOOLTIP}",mutator:"pxt_text_join_mutator"}])},{"../../fields/field_imagenotext":38,"../../utils":155,blockly:256}],151:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly");n.defineBlocksWithJsonArray([{type:"text",message0:"%1",args0:[{type:"field_string",name:"TEXT",text:""}],output:"String",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_TEXT_TEXT_HELPURL}",tooltip:"%{BKY_TEXT_TEXT_TOOLTIP}",extensions:["parent_tooltip_when_inline"]}])},{blockly:256}],152:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.blocksMetrics=i.render=i.renderWorkspace=i.cleanRenderingWorkspace=i.initRenderingWorkspace=void 0;const n=e("blockly"),s=e("./layout"),o=e("./importer");let r,a;function l(){return r||(a=document.createElement("div"),a.style.position="absolute",a.style.top="0",a.style.left="0",a.style.width="1px",a.style.height="1px",document.body.appendChild(a),r=n.inject(a,{move:{scrollbars:!1},readOnly:!0,sounds:!1,media:pxt.webConfig.commitCdnUrl+"blockly/media/",rtl:pxt.Util.isUserLanguageRtl(),renderer:"pxt"})),(0,o.clearWithoutEvents)(r),r}function c(){r&&r.dispose(),r=void 0}function u(e={emPixels:18,layout:1}){switch(e.splitSvg?1:e.layout||4){case 1:(0,s.verticalAlign)(r,e.emPixels||18);break;case 4:(0,s.flow)(r,{ratio:e.aspectRatio,useViewWidth:e.useViewWidth});break;case 3:r.cleanUp_&&r.cleanUp_()}let t=r.getMetrics();const i=a.querySelectorAll("svg")[0],n=i.cloneNode(!0);return(0,s.cleanUpBlocklySvg)(n,i),pxt.U.toArray(n.querySelectorAll(".blocklyBlockCanvas,.blocklyBubbleCanvas")).forEach(e=>e.setAttribute("transform",`translate(${-t.contentLeft}, ${-t.contentTop}) scale(1)`)),n.setAttribute("viewBox",`0 0 ${t.contentWidth} ${t.contentHeight}`),e.emPixels&&(n.style.width=t.contentWidth/e.emPixels+"em",n.style.height=t.contentHeight/e.emPixels+"em"),e.splitSvg?(0,s.splitSvg)(n,r,e.emPixels):n}i.initRenderingWorkspace=l,i.cleanRenderingWorkspace=c,i.renderWorkspace=u,i.render=function(e,t={emPixels:18,layout:1}){l();try{let i=e||'<xml xmlns="http://www.w3.org/1999/xhtml"></xml>',s=n.utils.xml.textToDom(i);return(0,o.domToWorkspaceNoEvents)(s,r,{applyHideMetaComment:!0}),u(t)}catch(e){return void pxt.reportException(e)}finally{c()}},i.blocksMetrics=function(e){const t=e.getTopBlocks(!1);if(!t.length)return{width:0,height:0};let i;return t.forEach(e=>{const t=e.getBoundingRectangle();i?(i.l=Math.min(i.l,t.left),i.r=Math.max(i.r,t.right),i.t=Math.min(i.t,t.top),i.b=Math.min(i.b,t.bottom)):i={l:t.left,r:t.right,t:t.top,b:t.bottom}}),{width:i.r-i.l,height:i.b-i.t}}},{"./importer":75,"./layout":77,blockly:256}],153:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.findBlockIdByLine=i.findBlockIdByPosition=void 0,i.findBlockIdByPosition=function(e,t){if(!t)return;let i,n;for(let s=0;s<e.length;++s){let o=e[s];o.startPos<=t.start&&o.endPos>=t.start+t.length&&(!i||n>o.endPos-o.startPos)&&(i=o,n=o.endPos-o.startPos)}return i?i.id:void 0},i.findBlockIdByLine=function(e,t){if(!t)return;let i,n;for(let s=0;s<e.length;++s){let o=e[s];o.startLine<=t.start&&o.endLine>t.start+t.length&&(!i||n>o.endLine-o.startLine)&&(i=o,n=o.endLine-o.startLine)}return i?i.id:void 0}},{}],154:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createFunctionsFlyoutCategory=i.mkReturnStatementBlock=i.mkVariableFieldBlock=i.mkFieldBlock=i.mkPredicateBlock=i.createToolboxBlock=i.createFlyoutGap=i.createFlyoutButton=i.createFlyoutGroupLabel=i.createFlyoutHeadingLabel=i.createShadowValue=i.isArrayType=void 0;const n=e("blockly"),s=e("./plugins/functions"),o=e("./loader"),r=/^(string|number|boolean)$/,a={string:{field:"TEXT",block:"text",defaultValue:""},number:{field:"NUM",block:"math_number",defaultValue:"0"},boolean:{field:"BOOL",block:"logic_boolean",defaultValue:"false"},Array:{field:"VAR",block:"variables_get",defaultValue:"list"}};function l(e){let t=/^(?:Array<(.+)>)|(?:(.+)\[\])|(?:\[.+\])$/.exec(e);return t?t[1]?t[1]:t[2]:void 0}function c(e,t,i,n,s,o=0){let r;if(n=n||t.defaultValue,!(i=i||t.shadowBlockId)&&t.range&&(i="math_number_minmax"),r=n&&'"'==n.slice(0,1)?JSON.parse(n):n,"number"==t.type&&"value"==i){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode("0")),e}if(t.fieldEditor){if(t.defaultValue){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode(t.defaultValue)),e}return}let c=pxt.Util.lookup(e.apis.byQName,t.type),h=6==(null==c?void 0:c.kind),d=c&&!!c.attributes.fixedInstances&&!t.shadowBlockId,p="@combined@"==t.type;if(!i&&(h||d||p)){if(n){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode(n)),e}return}const f="variables_get"==i,m="text"==i,_=document.createElement("value");_.setAttribute("name",t.definitionName);const b="lists_create_with"!==i&&i?void 0:l(t.type),T=document.createElement(!f&&!b||s?"shadow":"block");_.appendChild(T);const E=a[b||t.type];if(T.setAttribute("type",i||(b?"lists_create_with":E&&E.block||t.type)),T.setAttribute("colour","#fff"),b){if(E&&!i){let e;switch(b){case"number":e=["0","1"];break;case"string":e=["a","b","c"];break;case"boolean":e=["FALSE","FALSE","FALSE"]}return u(T,E.block,E.field,e),_}if(i&&r)return u(T,r),_}if(!E||i&&E.block!==i&&"math_number_minmax"!==i){if(r){const n=document.createElement("field");if(n.textContent=r,f)n.setAttribute("name","VAR"),T.appendChild(n);else if(m)n.setAttribute("name","TEXT"),T.appendChild(n);else if(i){const t=e.blocksById[i];if(t&&t.attributes._def&&t.attributes._def.parameters.length){const e=t.attributes._def.parameters[0];n.setAttribute("name",e.name),T.appendChild(n)}}else n.setAttribute("name",t.definitionName),T.appendChild(n)}}else{const e=document.createElement("field");let n,s;switch(T.appendChild(e),i){case"variables_get":n="VAR";break;case"math_number_minmax":n="SLIDER";break;default:n=E.field}e.setAttribute("name",n),s="boolean"==t.type?document.createTextNode((r||E.defaultValue).toUpperCase()):document.createTextNode(r||E.defaultValue),e.appendChild(s)}let v;if(t.range&&(v=document.createElement("mutation"),v.setAttribute("min",t.range.min.toString()),v.setAttribute("max",t.range.max.toString()),v.setAttribute("label",t.actualName.charAt(0).toUpperCase()+t.actualName.slice(1)),t.fieldOptions&&(t.fieldOptions.step&&v.setAttribute("step",t.fieldOptions.step),t.fieldOptions.color&&v.setAttribute("color",t.fieldOptions.color),t.fieldOptions.precision&&v.setAttribute("precision",t.fieldOptions.precision))),t.fieldOptions&&(v||(v=document.createElement("mutation")),v.setAttribute("customfield",JSON.stringify(t.fieldOptions))),v&&T.appendChild(v),o){const t=pxt.Util.toArray(_.getElementsByTagName("shadow"));for(const i of t)if(!i.innerHTML){const t=e.blocks.find(e=>e.attributes.blockId===i.getAttribute("type"));if(t){const n=g(e,t,pxt.blocks.compileInfo(t),!0,o-1);for(;n.firstChild;)i.appendChild(n.firstChild.cloneNode(!0)),n.firstChild.remove();t.attributes.builtinBlockId&&i.setAttribute("type",t.attributes.builtinBlockId)}}}return _}function u(e,t,i,n){const s=n?n.length:2,o=document.createElement("mutation");o.setAttribute("items",""+s),o.setAttribute("horizontalafter",""+s),e.appendChild(o);for(let o=0;o<s;o++){const s=document.createElement("value");s.setAttribute("name","ADD"+o);const r=document.createElement("shadow");if(r.setAttribute("type",t),i){const e=document.createElement("field");e.setAttribute("name",i),n&&e.appendChild(document.createTextNode(n[o])),r.appendChild(e)}s.appendChild(r),e.appendChild(s)}}function h(e,t,i,n){const s=p(e,pxt.toolbox.convertColor(t),i,n);return s.setAttribute("web-class","blocklyFlyoutHeading"),s}function d(e,t,i,n){const s=p(e,void 0,t);return s.setAttribute("web-class","blocklyFlyoutGroup"),s.setAttribute("web-line","1.5"),i&&s.setAttribute("web-line-width",i),n&&(s.setAttribute("web-help-button","true"),s.setAttribute("callbackKey",n)),s}function p(e,t,i,s){let o=n.utils.xml.createElement("label");return o.setAttribute("text",e),t&&o.setAttribute("web-icon-color",pxt.toolbox.convertColor(t)),i&&(1===i.length?(o.setAttribute("web-icon",i),s&&o.setAttribute("web-icon-class",s)):(o.setAttribute("web-icon-class",`blocklyFlyoutIcon${e}`),pxt.toolbox.isImageIcon(i)&&o.setAttribute("web-icon-image",pxt.Util.pathJoin(pxt.webConfig.commitCdnUrl,encodeURI(i))))),o}function g(e,t,i,n=!1,a=0){var u,h;let d,p;if(t.attributes.builtinBlockId)return function(e){const t=e.attributes.builtinBlockId,i=e.attributes.color;if("makecode_color_picker"===t){const e=document.createElement("block");e.setAttribute("type","makecode_color_picker");const t=document.createElement("field");t.setAttribute("name","FORMAT"),t.textContent="rgb",e.appendChild(t);for(let t=0;t<3;t++){const i=document.createElement("value");i.setAttribute("name",`INPUT${t}`);const n=document.createElement("shadow");n.setAttribute("type","makecode_color_picker_number");const s=document.createElement("field");s.setAttribute("name","NUM"),s.textContent="0",n.appendChild(s),i.appendChild(n),e.appendChild(i)}if(i){const t=document.createElement("mutation");t.setAttribute("color",i),e.appendChild(t)}return e}return void pxt.warn(`Unsupported builtin block id: ${t}`)}(t);if(t.attributes.toolboxParent){const i=e.blocksById[t.attributes.toolboxParent];if(i){const s=pxt.blocks.compileInfo(i);if(d=g(e,i,s,n),t.attributes.toolboxParentArgument)p=d.querySelector(`value[name=${t.attributes.toolboxParentArgument}]`),!p&&s.parameters.some(e=>e.definitionName===t.attributes.toolboxParentArgument)&&(p=document.createElement("value"),p.setAttribute("name",t.attributes.toolboxParentArgument),d.appendChild(p));else if(p=d.querySelector("value"),!p)for(const e of s.parameters)if(!d.querySelector(`field[name=${e.definitionName}]`)){p=document.createElement("value"),p.setAttribute("name",e.definitionName),d.appendChild(p);break}if(p)for(;p.firstChild;)p.removeChild(p.firstChild);else d=void 0}}let f=document.createElement(d||n?"shadow":"block");if(f.setAttribute("type",t.attributes.blockId),t.attributes.blockGap?f.setAttribute("gap",t.attributes.blockGap):pxt.appTarget.appTheme&&pxt.appTarget.appTheme.defaultBlockGap&&f.setAttribute("gap",pxt.appTarget.appTheme.defaultBlockGap.toString()),i.thisParameter){const t=i.thisParameter,s=!!(null===(u=e.apis.byQName[t.type])||void 0===u?void 0:u.attributes.fixedInstances);let o=t.shadowBlockId,r=t.defaultValue;s||o&&"variables_get"!==o||(o="variables_get",r=r||t.definitionName);const l=c(e,t,o,r,n,a);l&&f.appendChild(l)}if("ENUM_GET"===t.attributes.shim||"KIND_GET"===t.attributes.shim){if(null===(h=t.parameters)||void 0===h?void 0:h.length){const e=t.parameters[0].default;if(e){const t=document.createElement("field");t.setAttribute("name","MEMBER"),t.textContent=e,f.appendChild(t)}}}else t.parameters&&(i.parameters.filter(e=>r.test(e.type)||r.test(l(e.type))||e.shadowBlockId||e.defaultValue).forEach(t=>{const i=c(e,t,void 0,void 0,n,a);i&&f.appendChild(i)}),t.attributes.draggableParameters?i.handlerArgs.forEach(e=>{const i="reporter"===t.attributes.draggableParameters,n=document.createElement("value");n.setAttribute("name",o.DRAGGABLE_PARAM_INPUT_PREFIX+e.name);const r=i?pxt.blocks.reporterTypeForArgType(e.type):"variables_get_reporter",a=document.createElement("block");a.setAttribute("type",r);const l=document.createElement("mutation");a.appendChild(l),i&&"argument_reporter_custom"===r&&l.setAttribute("typename",e.type),l.setAttribute(s.LOCALIZATION_NAME_MUTATION_KEY,e.localizationKey);const c=document.createElement("field");c.setAttribute("name",i?"VALUE":"VAR"),c.textContent=pxt.Util.htmlEscape(e.name),a.appendChild(c),n.appendChild(a),f.appendChild(n)}):i.handlerArgs.forEach(e=>{const t=document.createElement("field");t.setAttribute("name","HANDLER_"+e.name),t.textContent=e.name,f.appendChild(t)}));if(t.attributes.expandArgumentsInToolbox){let e;for(const t of f.children)if("mutation"===t.tagName){e=t;break}e||(e=document.createElement("mutation"),f.appendChild(e)),e.setAttribute("_expanded",""+t.attributes._expandedDef.parameters.length)}return d?(p.appendChild(f),d):f}function f(e,t,i,n){const s=document.createElement(n?"shadow":"block");s.setAttribute("type",pxt.Util.htmlEscape(e));const o=document.createElement("field");return o.setAttribute("name",pxt.Util.htmlEscape(t)),o.textContent=pxt.Util.htmlEscape(i),s.appendChild(o),s}function m(){const e=document.createElement("block");e.setAttribute("type","function_return");const t=document.createElement("value");t.setAttribute("name","RETURN_VALUE"),e.appendChild(t);const i=f("math_number","NUM","0",!0);return t.appendChild(i),e}i.isArrayType=l,i.createShadowValue=c,i.createFlyoutHeadingLabel=h,i.createFlyoutGroupLabel=d,i.createFlyoutButton=function(e,t){let i=n.utils.xml.createElement("button");return i.setAttribute("text",t),i.setAttribute("callbackKey",e),i},i.createFlyoutGap=function(e){const t=n.utils.xml.createElement("sep");return t.setAttribute("gap",e+""),t},i.createToolboxBlock=g,i.mkPredicateBlock=function(e){const t=document.createElement("block");t.setAttribute("type",e);const i=document.createElement("value");i.setAttribute("name","PREDICATE"),t.appendChild(i);const n=f("logic_boolean","BOOL","TRUE",!0);return i.appendChild(n),t},i.mkFieldBlock=f,i.mkVariableFieldBlock=function(e,t,i,n,s){const o=document.createElement(s?"shadow":"block");o.setAttribute("type",pxt.Util.htmlEscape(e));const r=document.createElement("field");return r.setAttribute("name","VAR"),r.id=t,r.setAttribute("variabletype",pxt.Util.htmlEscape(i)),r.textContent=pxt.Util.htmlEscape(n),o.appendChild(r),o},i.mkReturnStatementBlock=m,i.createFunctionsFlyoutCategory=function(e){const t=(0,s.flyoutCategory)(e);if(t.length>1){let e=m();t.splice(1,0,d(lf("Your Functions"))),t.splice(1,0,e)}const i=(0,s.getAllFunctionDefinitionBlocks)(e).filter(e=>e.getDescendants(!1).some(e=>"function_return"===e.type&&e.getInputTargetBlock("RETURN_VALUE"))).map(e=>e.getField("function_name").getText()),n=h(lf("Functions"),pxt.toolbox.getNamespaceColor("functions"),pxt.toolbox.getNamespaceIcon("functions"),"blocklyFlyoutIconfunctions");t.unshift(n);const o=[];for(const e of t)if(o.push(e),"function_call"===e.getAttribute("type")){const t=e.children.item(0);if(t){const n=t.getAttribute("name");if(i.some(e=>e===n)){const t=e.cloneNode(!0);t.setAttribute("type","function_call_output"),o.push(t)}}}return o}},{"./loader":79,"./plugins/functions":127,blockly:256}],155:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.maybeMoveFocusFromButton=void 0;const n=e("blockly"),s=e("./fields/field_imagenotext");i.maybeMoveFocusFromButton=e=>{const t=n.getFocusManager(),i=t.getFocusedNode();e&&(i instanceof s.FieldImageNoText||!i)&&t.focusNode(e)}},{"./fields/field_imagenotext":38,blockly:256}],156:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PxtWorkspaceSearch=void 0;const n=e("blockly"),s=e("@blockly/plugin-workspace-search");class o extends s.WorkspaceSearch{constructor(e){super(e),this.injectionDiv=e.getInjectionDiv()}highlightSearchGroup(e){e.forEach(e=>{const t=e.pathObject.svgPath;n.utils.dom.addClass(t,"blockly-ws-search-highlight-pxt")})}unhighlightSearchGroup(e){e.forEach(e=>{const t=e.pathObject.svgPath;n.utils.dom.removeClass(t,"blockly-ws-search-highlight-pxt")})}open(){super.open(),n.utils.dom.addClass(this.injectionDiv,"blockly-ws-searching")}close(){super.close(),n.utils.dom.removeClass(this.injectionDiv,"blockly-ws-searching")}}i.PxtWorkspaceSearch=o,n.Css.register("\n.blockly-ws-search {\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n border: solid var(--pxt-neutral-alpha50) 1px;\n border-top: none;\n border-right: none;\n box-shadow: 0px 2px 15px var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input {\n -webkit-tap-highlight-color: transparent;\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n border: none;\n}\n\n.blockly-ws-search input::-webkit-input-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input::-moz-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input::-ms-input-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input:active,\n.blockly-ws-search input:focus {\n border-color: var(--pxt-neutral-alpha50);\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n}\n\n.blockly-ws-search input::selection {\n color: var(--pxt-neutral-foreground1);\n}\n\n.blockly-ws-search button {\n padding-left: 6px;\n padding-right: 6px;\n color: var(--pxt-neutral-foreground1);\n}")},{"@blockly/plugin-workspace-search":251,blockly:256}],157:[function(e,t,i){"use strict";function n(e,t,i,n){return pxt.Util.toArray(e.getElementsByTagName(t)).filter(e=>e.getAttribute(i)===n)}Object.defineProperty(i,"__esModule",{value:!0}),i.cleanOuterHTML=i.getDirectChildren=i.getFirstChildWithAttr=i.getChildrenWithAttr=i.getBlocksWithType=void 0,i.getBlocksWithType=function(e,t){return n(e,"block","type",t).concat(n(e,"shadow","type",t))},i.getChildrenWithAttr=n,i.getFirstChildWithAttr=function(e,t,i,s){const o=n(e,t,i,s);return o.length?o[0]:void 0},i.getDirectChildren=function(e,t){const i=[];for(let n=0;n<e.childNodes.length;n++){const s=e.childNodes.item(n);s.tagName===t&&i.push(s)}return i},i.cleanOuterHTML=function(e){return e.outerHTML.replace(/^<\?[^>]*>/,"")}},{}],158:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.IFrameEmbeddedClient=void 0;i.IFrameEmbeddedClient=class{constructor(e){this.messageHandler=e,this.onMessageReceived=e=>{const t=e.data;if(t){if("iframeclientsetmessageport"===t.type)return this.port=e.ports[0],this.port.onmessage=this.onMessageReceived,void this.postMessage({type:"iframeclientsetmessageport"});if("iframeclientready"===t.type)return void this.sendReadyMessage()}this.messageHandler(e)},this.frameId=function(){const e=/frameid=([a-zA-Z0-9\-]+)/i.exec(window.location.href);if(e)return e[1];return}(),window.addEventListener("message",this.onMessageReceived),this.sendReadyMessage()}dispose(){window.removeEventListener("message",this.onMessageReceived),this.port&&this.port.close()}postMessage(e){this.postMessageCore(e)}postMessageCore(e){this.frameId&&(e.frameId=this.frameId),this.port?this.port.postMessage(e):window.acquireVsCodeApi?window.acquireVsCodeApi().postMessage(e):window.parent&&window.parent!==window&&window.parent.postMessage(e,"*")}sendReadyMessage(){this.postMessage({type:"iframeclientready"})}}},{}],159:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.inflateButtonViewProps=i.inflateButtonProps=i.ButtonBody=i.Button=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.Button=e=>{const t=o(e);return(0,n.jsx)("button",Object.assign({},t,{children:(0,n.jsx)(i.ButtonBody,Object.assign({},e))}))};function o(e){const{onClick:t,onClickEvent:i,onRightClick:n,onKeydown:o,onBlur:a,onFocus:l,onMouseDown:c,buttonRef:u,target:h,href:d,hardDisabled:p}=e;let{disabled:g}=e;g=g||p;return Object.assign(Object.assign({},r(e)),{ref:u,onClick:g?void 0:e=>{i&&i(e),t&&t(),d&&window.open(d,h||"_blank","noopener,noreferrer"),e.stopPropagation(),e.preventDefault()},onContextMenu:e=>{n&&(n(),e.stopPropagation(),e.preventDefault())},onKeyDown:o||s.fireClickOnEnter,onBlur:a,onFocus:l,onMouseDown:c})}function r(e){const{id:t,className:i,style:n,ariaLabel:o,ariaHidden:r,ariaDescribedBy:a,ariaControls:l,ariaExpanded:c,ariaHasPopup:u,ariaPosInSet:h,ariaSetSize:d,ariaSelected:p,ariaPressed:g,role:f,title:m,hardDisabled:_,tabIndex:b,autoFocus:T}=e;let{disabled:E}=e;E=E||_;return{id:t,className:(0,s.classList)("common-button",i,E&&"disabled"),style:n,title:m,role:f||"button",tabIndex:b||(E?-1:0),autoFocus:T,disabled:_,"aria-label":o,"aria-hidden":r,"aria-controls":l,"aria-expanded":c,"aria-haspopup":u,"aria-posinset":h,"aria-setsize":d,"aria-describedby":a,"aria-selected":p,"aria-pressed":g}}i.ButtonBody=e=>{const{label:t,labelClassName:i,leftIcon:o,rightIcon:r,children:a}=e;return(0,n.jsxs)(n.Fragment,{children:[(o||r||t)&&(0,n.jsxs)("span",Object.assign({className:"common-button-flex"},{children:[o&&(0,n.jsx)("i",{className:o,"aria-hidden":!0}),(0,n.jsx)("span",Object.assign({className:(0,s.classList)("common-button-label",i)},{children:t})),r&&(0,n.jsx)("i",{className:"right "+r,"aria-hidden":!0})]})),a]})},i.inflateButtonProps=o,i.inflateButtonViewProps=r},{"../util":171,"react/jsx-runtime":305}],160:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CarouselNav=void 0;const n=e("react/jsx-runtime"),s=e("../util"),o=e("./Button");i.CarouselNav=e=>{const{pages:t,selected:i,maxDisplayed:r,onPageSelected:a}=e,l=[];let c=0,u=t;r&&(c=Math.min(Math.max(0,i-(r>>1)),Math.max(0,c+t-r)),u=Math.min(c+r,t));for(let e=c;e<u;e++)l.push(e);return(0,n.jsxs)("div",Object.assign({className:"common-carousel-nav"},{children:[(0,n.jsx)(o.Button,{className:"common-carousel-nav-arrow",title:lf("Previous page"),leftIcon:"fas fa-chevron-circle-left",onClick:()=>a(i-1),disabled:0===i}),(0,n.jsx)("ul",Object.assign({className:"common-carousel-nav"},{children:l.map(e=>(0,n.jsx)("li",Object.assign({onClick:()=>a(e)},{children:(0,n.jsx)(o.Button,{className:(0,s.classList)(i===e&&"selected"),title:lf("Jump to page {0}",e+1),onClick:()=>a(e),label:(0,n.jsx)("span",{className:"common-carousel-nav-button-handle"})})}),e))})),(0,n.jsx)(o.Button,{className:"common-carousel-nav-arrow",title:lf("Next page"),leftIcon:"fas fa-chevron-circle-right",onClick:()=>a(i+1),disabled:i===t-1})]}))}},{"../util":171,"./Button":159,"react/jsx-runtime":305}],161:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CheckboxIcon=i.Checkbox=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.Checkbox=e=>{const{id:t,className:i,ariaHidden:o,ariaLabel:r,role:a,isChecked:l,onChange:c,label:u,style:h,tabIndex:d}=e;return(0,n.jsxs)("div",Object.assign({className:(0,s.classList)("common-checkbox",i,"toggle"===h&&"toggle")},{children:[(0,n.jsx)("input",{id:t,tabIndex:null!=d?d:0,type:"checkbox",checked:l,onChange:()=>{c(!l)},onKeyDown:s.fireClickOnEnter,role:a,"aria-hidden":o,"aria-label":r}),u&&(0,n.jsx)("label",Object.assign({htmlFor:t},{children:u}))]}))};i.CheckboxIcon=e=>{const{isChecked:t}=e;return(0,n.jsx)("span",Object.assign({className:(0,s.classList)("common-checkbox-icon",t&&"checked")},{children:t&&(0,n.jsx)("i",{className:"fas fa-check"})}))}},{"../util":171,"react/jsx-runtime":305}],162:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Dropdown=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util"),r=e("./Button"),a=e("./FocusList");i.Dropdown=e=>{var t;const{id:i,className:l,ariaHidden:c,ariaLabel:u,getAriaLabel:h,role:d,items:p,tabIndex:g,selectedId:f,onItemSelected:m}=e,[_,b]=s.useState(!1),T=s.useRef(),E=s.useRef(),v=s.useRef({});s.useEffect(()=>{_&&Object.keys(v.current).length&&v.current[null!=f?f:0].focus()},[_]);const y=(0,o.classList)("common-dropdown",l),k=p.find(e=>e.id===f)||p[0];return(0,n.jsxs)("div",Object.assign({className:y,ref:T,onBlur:e=>{T.current&&_&&!T.current.contains(e.relatedTarget)&&b(!1)}},{children:[(0,n.jsx)(r.Button,Object.assign({},k,{id:i,buttonRef:e=>E.current=e,tabIndex:g,rightIcon:_?"fas fa-chevron-up":"fas fa-chevron-down",role:d,className:(0,o.classList)("common-dropdown-button",_&&"expanded",k.className),onClick:()=>{b(!_)},onKeydown:e=>{const t=p.indexOf(k);"ArrowDown"===e.key?(_?t<p.length-1&&m(p[t+1].id):b(!0),e.preventDefault(),e.stopPropagation()):"ArrowUp"===e.key?t>0&&(m(p[t-1].id),e.preventDefault(),e.stopPropagation()):"Enter"===e.key&&(b(!0),e.preventDefault(),e.stopPropagation())},ariaHasPopup:"listbox",ariaExpanded:_,ariaLabel:null!==(t=null!=u?u:null==h?void 0:h(k.title))&&void 0!==t?t:k.title,ariaHidden:c})),_&&(0,n.jsx)(a.FocusList,Object.assign({role:"listbox",className:"common-menu-dropdown-pane common-dropdown-shadow",childTabStopId:f,"aria-labelledby":i,useUpAndDownArrowKeys:!0,onClose:()=>{b(!1),E.current.focus()},onItemReceivedFocus:e=>{e.id&&p.some(t=>t.id===e.id)&&m(e.id)}},{children:(0,n.jsx)("ul",Object.assign({role:"presentation"},{children:p.map(e=>(0,n.jsx)("li",Object.assign({role:"presentation"},{children:(0,n.jsx)(r.Button,Object.assign({},e,{buttonRef:t=>v.current[e.id]=t,className:(0,o.classList)("common-dropdown-item",e.className),onClick:()=>{var t;b(!1),m(e.id),null===(t=E.current)||void 0===t||t.focus()},ariaSelected:e.id===f,role:"option"}))}),e.id))}))}))]}))}},{"../util":171,"./Button":159,"./FocusList":164,react:304,"react/jsx-runtime":305}],163:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.EditorToggle=void 0;const n=e("react/jsx-runtime"),s=e("../util"),o=e("./Button"),r=e("./FocusList"),a=e("./MenuDropdown"),l=e("react");i.EditorToggle=e=>{const{id:t,className:i,ariaHidden:o,ariaLabel:r,role:d,items:p,selected:g}=e,[f,m]=(0,l.useState)(!1),_=p.some(e=>h(e)),b=e=>{},T=(0,s.classList)("common-editor-toggle",_&&"has-dropdown",f&&"focused",i);return(0,n.jsxs)("div",Object.assign({className:"common-editor-toggle-outer"},{children:[(0,n.jsx)(u,Object.assign({setIsFocused:m},e)),(0,n.jsxs)("div",Object.assign({id:t,className:T,role:d||"tablist","aria-hidden":!0,"aria-label":r},{children:[p.map((e,t)=>{const i=g===t;return(0,n.jsxs)("div",Object.assign({className:(0,s.classList)("common-editor-toggle-item",i&&"selected",h(e)&&"common-editor-toggle-item-dropdown")},{children:[(0,n.jsx)(c,{item:e,isSelected:i,onKeydown:b}),h(e)&&(0,n.jsx)(a.MenuDropdown,{id:"toggle-dropdown",className:"toggle-dropdown",icon:"fas fa-chevron-down",title:lf("More options"),tabIndex:-1,ariaHidden:!0,items:e.items.map(e=>({role:"menuitem",title:e.title,label:e.label,onClick:e.onClick,leftIcon:e.icon}))})]}),t)}),(0,n.jsx)("div",{className:"common-editor-toggle-handle","aria-hidden":!0})]}))]}))};const c=e=>{const{item:t,isSelected:i,onKeydown:s}=e,{label:r,title:a,onClick:l,icon:c,focusable:u}=t;return(0,n.jsx)(o.Button,{className:c?void 0:"no-icon",role:u?"tab":void 0,tabIndex:-1,onKeydown:s,label:r,title:a,onClick:l,leftIcon:c,ariaHidden:!0})},u=e=>{const{items:t,id:i,selected:s,ariaHidden:a,setIsFocused:l}=e;let c;const u=t.reduce((e,t,i)=>{const n=[...e];return n.push(Object.assign({},t)),s===i?(n[n.length-1].selected=!0,c=i):n[n.length-1].selected=!1,h(t)&&n.push(...t.items.filter(e=>e.focusable)),n},[]),d=`${i}-option-`;return(0,n.jsx)(r.FocusList,Object.assign({id:i,role:"tablist",className:"common-toggle-accessibility",childTabStopId:`${d}${c}`,focusSelectsItem:!0},{children:u.map((e,t)=>(0,n.jsx)(o.Button,{className:e.selected?"selected":void 0,id:`${d}${t}`,role:"tab",title:e.title,label:e.label,onClick:e.onClick,onFocus:()=>l(!0),onBlur:()=>l(!1),ariaSelected:e.selected,ariaHidden:a},t))}))};function h(e){var t;return!!(null===(t=e.items)||void 0===t?void 0:t.length)}},{"../util":171,"./Button":159,"./FocusList":164,"./MenuDropdown":169,react:304,"react/jsx-runtime":305}],164:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FocusList=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.FocusList=e=>{const{id:t,className:i,role:o,ariaHidden:r,ariaLabel:a,ariaLabelledby:l,ariaDescribedBy:c,childTabStopId:u,children:h,focusSelectsItem:d,onItemReceivedFocus:p,useUpAndDownArrowKeys:g,title:f,onClose:m}=e;let _,b;const T=e=>"true"===e.getAttribute("data-isfocusable")&&null!==e.offsetParent;return(0,n.jsx)("div",Object.assign({id:t,className:i,role:o,tabIndex:u?void 0:0,onKeyDown:e=>{if(!(null==_?void 0:_.length))return;const t=document.activeElement,i=_.indexOf(t),n=e=>{e.click?e.click():e.dispatchEvent(new Event("click"))},o=e=>{e.focus(),p&&p(e),d&&n(e)};if(-1===i&&t!==b)return;let r,a;g?(r="ArrowUp",a="ArrowDown"):pxt.Util.isUserLanguageRtl()?(r="ArrowRight",a="ArrowLeft"):(r="ArrowLeft",a="ArrowRight"),d||"Enter"!==e.key&&" "!==e.key?e.key===a?(i===_.length-1||t===b?o((0,s.findNextFocusableElement)(_,i,0,!0,T)):o((0,s.findNextFocusableElement)(_,i,i+1,!0,T)),e.preventDefault(),e.stopPropagation()):e.key===r?(o(0===i||t===b?(0,s.findNextFocusableElement)(_,i,_.length-1,!1,T):(0,s.findNextFocusableElement)(_,i,i-1,!1,T)),e.preventDefault(),e.stopPropagation()):"Home"===e.key?(o((0,s.findNextFocusableElement)(_,i,0,!0,T)),e.preventDefault(),e.stopPropagation()):"End"===e.key?(o((0,s.findNextFocusableElement)(_,i,_.length-1,!0,T)),e.preventDefault(),e.stopPropagation()):"Escape"===e.key&&m&&(m(),e.preventDefault(),e.stopPropagation()):(e.preventDefault(),e.stopPropagation(),n(t))},ref:e=>{if(!e||b)return;b=e;const t=e.querySelectorAll('[tabindex]:not([tabindex="-1"]),[data-isfocusable]');_=[];for(const e of t.values())_.push(e),e.setAttribute("tabindex","-1"),e.setAttribute("data-isfocusable","true");if(u){const e=b.querySelector("#"+u);e&&e.setAttribute("tabindex","0")}},"aria-hidden":r,"aria-label":a,"aria-labelledby":l,"aria-describedby":c,title:f},{children:h}))}},{"../util":171,"react/jsx-runtime":305}],165:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FocusTrapRegion=i.FocusTrap=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../util"),r=e("./context"),a=e("../../../hooks/useId");i.FocusTrap=e=>(0,n.jsx)(r.FocusTrapProvider,{children:(0,n.jsx)(l,Object.assign({},e))});const l=e=>{const{children:t,id:i,className:n,onEscape:a,arrowKeyNavigation:l,dontStealFocus:c,includeOutsideTabOrder:u,dontRestoreFocus:h,dontTrapFocus:d,focusFirstItem:p,tagName:g,role:f,ariaLabelledby:m,ariaLabel:_,ariaHidden:b}=e,T=s.useRef(null),E=s.useRef(document.activeElement),[v,y]=s.useState(!1),k=s.useRef(null),{regions:C}=(0,r.useFocusTrapState)();s.useEffect(()=>()=>{!h&&E.current&&(0,o.focusLastActive)(E.current)},[]);const I=s.useCallback(()=>{var e;let t=u?(0,o.getFocusableDescendants)(T.current):(0,o.getTabbableDescendants)(T.current);if(C.length){const i={};for(const t of C){const n=null===(e=T.current)||void 0===e?void 0:e.querySelector(`[data-focus-trap-region="${t.id}"]`);n&&(i[t.id]=n)}for(const e of C){const n=i[e.id];!e.enabled&&n&&(t=t.filter(e=>!n.contains(e)))}const n=t.slice();t.sort((e,t)=>{const s=C.find(t=>{var n;return t.enabled&&(null===(n=i[t.id])||void 0===n?void 0:n.contains(e))}),o=C.find(e=>{var n;return e.enabled&&(null===(n=i[e.id])||void 0===n?void 0:n.contains(t))});if((null==s?void 0:s.order)===(null==o?void 0:o.order)){return n.indexOf(e)-n.indexOf(t)}return s?o?s.order-o.order:-1:1})}return t},[C,u]),S=s.useCallback(e=>{if(!e)return;T.current=e;const t=I();c||v||e.contains(document.activeElement)||!t.length||(T.current.focus(),p&&(0,o.findNextFocusableElement)(t,-1,0,!0).focus(),y(!0))},[I,c,v,p]),A=s.useCallback(e=>{var t;if(!T.current)return;const i=(t,i)=>{const n=I();if(!n.length)return;let s,r=n.indexOf(e.target);r<0&&(r=n.indexOf(k.current)),s=t?i?(0,o.findNextFocusableElement)(n,r,n.length-1,t):r===n.length-1?(0,o.findNextFocusableElement)(n,r,0,t):(0,o.findNextFocusableElement)(n,r,r+1,t):i?(0,o.findNextFocusableElement)(n,r,0,t):0===r?(0,o.findNextFocusableElement)(n,r,n.length-1,t):(0,o.findNextFocusableElement)(n,r,Math.max(r-1,0),t),k.current=s,s.focus(),e.preventDefault(),e.stopPropagation()};if("Escape"===e.key){let i=!1;if(C.length)for(const e of C){if(!e.onEscape)continue;const n=null===(t=T.current)||void 0===t?void 0:t.querySelector(`[data-focus-trap-region="${e.id}"]`);if(null==n?void 0:n.contains(document.activeElement)){i=!0,e.onEscape();break}}i||a(),e.preventDefault(),e.stopPropagation()}else"Tab"===e.key?d?a():e.shiftKey?i(!1,!1):i(!0,!1):l&&("ArrowDown"===e.key?i(!0,!1):"ArrowUp"===e.key?i(!1,!1):"Home"===e.key?i(!1,!0):"End"===e.key&&i(!0,!0))},[I,a,l,C,d]);return s.createElement(g||"div",{id:i,className:(0,o.classList)("common-focus-trap",n),ref:S,onKeyDown:A,role:f,tabIndex:-1,"aria-labelledby":m,"aria-label":_,"aria-hidden":b},t)};i.FocusTrapRegion=e=>{const{className:t,id:i,onEscape:o,order:l,enabled:c,children:u,divRef:h}=e,d=(0,a.useId)(),p=(0,r.useFocusTrapDispatch)();return s.useEffect(()=>(p((0,r.addRegion)(d,l,c,o)),()=>p((0,r.removeRegion)(d))),[d,c,l]),(0,n.jsx)("div",Object.assign({id:i,className:t,"data-focus-trap-region":d,tabIndex:-1,ref:h},{children:u}))}},{"../../../hooks/useId":172,"../../util":171,"./context":166,react:304,"react/jsx-runtime":305}],166:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useFocusTrapDispatch=i.useFocusTrapState=i.removeRegion=i.addRegion=i.FocusTrapProvider=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=s.createContext(null),r=s.createContext(null);i.FocusTrapProvider=({children:e})=>{const[t,i]=s.useReducer(a,{regions:[]});return(0,n.jsx)(o.Provider,Object.assign({value:t},{children:(0,n.jsx)(r.Provider,Object.assign({value:i},{children:e}))}))};i.addRegion=(e,t,i,n)=>({type:"ADD_REGION",id:e,order:t,enabled:i,onEscape:n});function a(e,t){let i=e.regions.slice();switch(t.type){case"ADD_REGION":const n={id:t.id,enabled:t.enabled,order:t.order,onEscape:t.onEscape},s=i.findIndex(e=>e.id===t.id);-1!==s?i.splice(s,1,n):i.push(n);break;case"REMOVE_REGION":const o=e.regions.findIndex(e=>e.id===t.id);-1!==o&&i.splice(o,1)}return{regions:i}}i.removeRegion=e=>({type:"REMOVE_REGION",id:e}),i.useFocusTrapState=function(){return s.useContext(o)},i.useFocusTrapDispatch=function(){return s.useContext(r)}},{react:304,"react/jsx-runtime":305}],167:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./FocusTrap"),i)},{"./FocusTrap":165}],168:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Input=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util"),r=e("./Button"),a=e("./FocusList");i.Input=e=>{var t;const{id:i,className:l,inputClassName:c,groupClassName:u,role:h,ariaHidden:d,ariaLabel:p,initialValue:g,label:f,title:m,placeholder:_,icon:b,iconTitle:T,disabled:E,type:v,readOnly:y,autoFocus:k,autoComplete:C,selectOnClick:I,onChange:S,onEnterKey:A,onIconClick:O,onFocus:w,onBlur:N,onOptionSelected:R,handleInputRef:x,preserveValueOnBlur:L=!0,options:D,validator:M}=e,[B,P]=s.useState(g||""),[F,U]=s.useState(!1),[H]=s.useState(e.filter?new RegExp(e.filter):void 0),G=s.useMemo(()=>D?Object.values(D):[],[D]);let V;s.useEffect(()=>{P(g||"")},[g]);const j=()=>{D&&U(!F)},W=e=>{if(!G.length)return;const t=G.indexOf(e);if(-1===t)return;var i;return`dropdown-item-${t}-${(i=e)?i.replace(/[^a-zA-Z0-9_-]/g,"-")||"option":""}`};return(0,n.jsxs)("div",Object.assign({className:(0,o.classList)("common-input-wrapper",E&&"disabled",l),onBlur:e=>{F&&!V.contains(e.relatedTarget)&&U(!1)},ref:e=>{e&&(V=e)}},{children:[f&&(0,n.jsx)("label",Object.assign({className:"common-input-label",htmlFor:i},{children:f})),(0,n.jsxs)("div",Object.assign({className:(0,o.classList)("common-input-group",u)},{children:[(0,n.jsx)("input",{id:i,className:(0,o.classList)("common-input",b&&"has-icon",c),title:m,role:h||"textbox",tabIndex:E?-1:0,"aria-label":p,"aria-hidden":d,type:v||"text",placeholder:_,value:B,readOnly:!!y,autoFocus:k,onClick:e=>{I&&e.target.select(),D&&!F&&U(!0)},onChange:e=>{var t;let i=e.target.value;i&&H&&(i=(null===(t=i.match(H))||void 0===t?void 0:t.join(""))||""),y||B===i||P(i),S&&S(i)},onKeyDown:t=>{var i,n;const s="number"==typeof t.which?t.which:t.keyCode;if(13===s||e.treatSpaceAsEnter&&32===s){let e=B;M&&(e=M(B,g||""),P(e)),A&&(t.preventDefault(),A(e))}else D&&"ArrowDown"===t.key?(F?null===(i=document.getElementById(W(G[0])))||void 0===i||i.focus():(j(),setTimeout(()=>{var e;null===(e=document.getElementById(W(G[0])))||void 0===e||e.focus()},0)),t.preventDefault(),t.stopPropagation()):D&&F&&"ArrowUp"===t.key&&(null===(n=document.getElementById(W(G[G.length-1])))||void 0===n||n.focus(),t.preventDefault(),t.stopPropagation())},onBlur:()=>{let e=B;M&&(e=M(B,g||""),P(e)),N&&N(e),L||P("")},onFocus:()=>{w&&w(B)},autoComplete:C?"":"off",autoCorrect:C?"":"off",autoCapitalize:C?"":"off",spellCheck:C,disabled:E,ref:x}),b&&(O?(0,n.jsx)(r.Button,{leftIcon:b,title:T,disabled:E,onClick:()=>{O&&O(B)}}):(0,n.jsx)("i",{className:b,"aria-hidden":!0})),D&&(0,n.jsx)(r.Button,{leftIcon:F?"fas fa-chevron-up":"fas fa-chevron-down",title:T,disabled:E,ariaHasPopup:"listbox",ariaExpanded:F,ariaLabel:p,tabIndex:-1,onClick:j})]})),F&&(0,n.jsx)(a.FocusList,Object.assign({role:"listbox",className:"common-menu-dropdown-pane common-dropdown-shadow",childTabStopId:null!==(t=W(B))&&void 0!==t?t:W(G[0]),"aria-labelledby":i,useUpAndDownArrowKeys:!0},{children:(0,n.jsx)("ul",Object.assign({role:"presentation",onKeyDown:e=>{var t;"Escape"===e.code&&(e.target.blur(),j(),null===(t=document.getElementById(i))||void 0===t||t.focus(),e.stopPropagation(),e.preventDefault())}},{children:Object.keys(D).map(e=>(0,n.jsx)("li",Object.assign({role:"presentation"},{children:(0,n.jsx)(r.Button,{title:e,label:e,id:W(D[e]),className:(0,o.classList)("common-dropdown-item"),onClick:()=>(e=>{var t;U(!1);const n=D[e];P(n),R&&R(n),null===(t=document.getElementById(i))||void 0===t||t.focus()})(e),ariaSelected:W(D[e])===W(null!=B?B:g),role:"option"})}),e))}))}))]}))}},{"../util":171,"./Button":159,"./FocusList":164,react:304,"react/jsx-runtime":305}],169:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MenuLinkItemImpl=i.MenuCheckboxItemImpl=i.MenuDropdownItemImpl=i.MenuDropdown=void 0;const n=e("react"),s=e("react/jsx-runtime"),o=e("react"),r=e("../util"),a=e("./Button"),l=e("./FocusTrap"),c=e("./Checkbox");i.MenuDropdown=e=>{const{id:t,className:c,ariaHidden:u,ariaLabel:h,role:d,items:p,label:g,title:f,icon:m,tabIndex:_,disabled:b}=e,[T,E]=o.useState(!1),v=o.useRef(!1);let y,k;o.useEffect(()=>{if(T&&y&&v.current){const e=y.querySelector("[role=menu]");if(!e)return;const t=e.querySelectorAll("[role=menuitem], [role=menuitemcheckbox], [role=menuitemradio]");for(const e of t){const t=e;if(null!==t.offsetParent){t.focus();break}}}},[T]);const C=()=>{E(!1),k&&k.focus()},I=(0,r.classList)("common-menu-dropdown",c),S=t+"-menu",A=function(e){const t=[];let i={items:[]};for(const n of e)"separator"===n.role?(i.className=n.className,i.items.length>0&&(t.push(i),i={items:[]})):i.items.push(n);i.items.length>0&&t.push(i);return t}(p);return(0,s.jsxs)("div",Object.assign({className:I,ref:e=>{e&&(y=e)},onBlur:e=>{y&&T&&!y.contains(e.relatedTarget)&&E(!1)}},{children:[(0,s.jsx)(a.Button,{id:t,label:g,tabIndex:_,buttonRef:e=>{e&&(k=e)},title:f,leftIcon:m,role:d||"button",className:(0,r.classList)("menu-button",T&&"expanded"),onClick:null,onClickEvent:e=>{v.current=0===e.detail,E(!T)},ariaHasPopup:"true",ariaExpanded:T,ariaControls:T?S:void 0,ariaLabel:h,ariaHidden:u,disabled:b,onKeydown:e=>{"ArrowDown"!==e.key||T||(v.current=!0,E(!0))}}),T&&(0,s.jsx)(l.FocusTrap,Object.assign({role:"menu",className:"common-menu-dropdown-pane",id:S,arrowKeyNavigation:!0,onEscape:()=>{E(!1),k&&k.focus()},includeOutsideTabOrder:!0,dontTrapFocus:!0,dontRestoreFocus:!0,focusFirstItem:!1,ariaLabelledby:t,tagName:"ul"},{children:A.map((e,t)=>(0,s.jsxs)(o.Fragment,{children:[e.items.map((e,s)=>{const o=`${t}-${s}`;return"menuitem"===e.role?(0,n.createElement)(i.MenuDropdownItemImpl,Object.assign({},e,{key:o,onClick:()=>{var t;C(),null===(t=e.onClick)||void 0===t||t.call(e)}})):"link"===e.role?(0,n.createElement)(i.MenuLinkItemImpl,Object.assign({},e,{key:o,onClick:()=>{var t;C(),null===(t=e.onClick)||void 0===t||t.call(e)}})):(0,n.createElement)(i.MenuCheckboxItemImpl,Object.assign({},e,{key:o,onChange:t=>{var i;C(),null===(i=e.onChange)||void 0===i||i.call(e,t)}}))}),t<A.length-1&&(0,s.jsx)("li",{role:"separator",className:(0,r.classList)("common-menu-dropdown-separator",e.className)})]},t))}))]}))};i.MenuDropdownItemImpl=e=>{const t=(0,a.inflateButtonProps)(e);return(0,s.jsx)("li",Object.assign({},t,{className:(0,r.classList)("common-menu-dropdown-item",t.className),role:"menuitem",tabIndex:-1},{children:(0,s.jsx)(a.ButtonBody,Object.assign({},e))}))};i.MenuCheckboxItemImpl=e=>{const{label:t,isChecked:i,onChange:n,id:o,className:a,ariaLabel:l,ariaHidden:u,ariaDescribedBy:h}=e;return(0,s.jsxs)("li",Object.assign({role:"menuitemcheckbox",tabIndex:-1,className:(0,r.classList)("common-menu-dropdown-item","common-menu-dropdown-checkbox-item",a),"aria-label":l,"aria-hidden":u,"aria-describedby":h,"aria-checked":i?"true":"false",onClick:()=>n(!i),onKeyDown:r.fireClickOnEnter,id:o},{children:[(0,s.jsx)(c.CheckboxIcon,{isChecked:i}),(0,s.jsx)("span",{children:t})]}))};i.MenuLinkItemImpl=e=>{const{href:t,label:i,id:n,className:o,ariaLabel:a,ariaHidden:l,ariaDescribedBy:c,onClick:u}=e;return(0,s.jsx)("li",Object.assign({role:"none"},{children:(0,s.jsx)("a",Object.assign({role:"menuitem",className:(0,r.classList)("common-menu-dropdown-item","common-menu-dropdown-link-item",o),"aria-label":a,"aria-hidden":l,"aria-describedby":c,id:n,tabIndex:-1,href:t,target:"_blank",rel:"noopener noreferrer",onClick:u,onKeyDown:r.fireClickOnEnter},{children:i}))}))}},{"../util":171,"./Button":159,"./Checkbox":161,"./FocusTrap":167,react:304,"react/jsx-runtime":305}],170:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Modal=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-dom"),r=e("../util"),a=e("./Button"),l=e("./FocusTrap");i.Modal=e=>{const{children:t,id:i,className:c,ariaLabel:u,ariaHidden:h,ariaDescribedBy:d,role:p,title:g,leftIcon:f,actions:m,onClose:_,parentElement:b,fullscreen:T,hideDismissButton:E,rightHeader:v}=e,y=e=>{_&&_()},k=(0,r.classList)("common-modal-container",T&&"fullscreen",c),C=s.useRef(null);return s.useEffect(()=>{var e;const t=b||document.body,i=null===(e=C.current)||void 0===e?void 0:e.parentElement,n=[];for(const e of t.children)e!==i&&(e.hasAttribute("aria-hidden")&&"false"!==e.getAttribute("aria-hidden")||(e.setAttribute("aria-hidden","true"),n.push(e)));return()=>{for(const e of n)e.removeAttribute("aria-hidden")}},[b]),o.createPortal((0,n.jsx)(l.FocusTrap,Object.assign({className:k,onEscape:y},{children:(0,n.jsxs)("div",Object.assign({id:i,className:"common-modal",ref:C,role:p||"dialog","aria-hidden":h,"aria-label":u,"aria-describedby":d,"aria-labelledby":"modal-title"},{children:[(0,n.jsxs)("div",Object.assign({className:"common-modal-header"},{children:[T&&!E&&(0,n.jsx)("div",Object.assign({className:"common-modal-back"},{children:(0,n.jsx)(a.Button,{className:"menu-button",onClick:y,title:lf("Go Back"),label:lf("Go Back"),leftIcon:"fas fa-arrow-left"})})),(0,n.jsxs)("div",Object.assign({id:"modal-title",className:"common-modal-title"},{children:[f&&(0,n.jsx)("i",{className:f,"aria-hidden":!0}),g]})),T&&v&&(0,n.jsx)("div",Object.assign({className:"common-modal-right-menu"},{children:v})),!T&&!E&&(0,n.jsx)("div",Object.assign({className:"common-modal-close"},{children:(0,n.jsx)(a.Button,{className:"menu-button",onClick:y,title:lf("Close"),rightIcon:"fas fa-times-circle"})}))]})),(0,n.jsx)("div",Object.assign({className:"common-modal-body"},{children:t})),(null==m?void 0:m.length)&&(0,n.jsx)("div",Object.assign({className:"common-modal-footer"},{children:m.map((e,t)=>{var i;return(0,n.jsx)(a.Button,{className:null!==(i=e.className)&&void 0!==i?i:"primary inverted",disabled:e.disabled,onClick:e.onClick,href:e.url,label:e.label,title:e.label,rightIcon:(e.xicon?"xicon ":"")+e.icon,leftIcon:e.leftIcon},t)})}))]}))})),b||document.body)}},{"../util":171,"./Button":159,"./FocusTrap":167,react:304,"react-dom":268,"react/jsx-runtime":305}],171:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.focusLastActive=i.isTabbable=i.isDisabled=i.isFocusable=i.getVisibleDescendants=i.getTabbableDescendants=i.getFocusableDescendants=i.findNextFocusableElement=i.screenToSVGCoord=i.clientCoord=i.CheckboxStatus=i.nodeListToArray=i.classList=i.fireClickOnEnter=i.jsxLF=void 0;const n=e("react/jsx-runtime");function s(e,t){if(!o(e))return[];const i=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,e=>o(e,!1)?t(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT),n=[];let s=i.nextNode();for(;s;)n.push(s),s=i.nextNode();return n}function o(e,t=!0){if(e.checkVisibility)return e.checkVisibility({visibilityProperty:!0});const i=getComputedStyle(e);return"none"!==i.display&&"hidden"!==i.visibility&&(!t||!e.parentElement||o(e.parentElement,t))}function r(e){return a(e)&&o(e)}function a(e){return!l(e)&&!!(e.hasAttribute("tabindex")||"A"===e.tagName&&(e.hasAttribute("href")||e.hasAttributeNS("xlink","href"))||"BUTTON"===e.tagName||"INPUT"===e.tagName||"SELECT"===e.tagName||"TEXTAREA"===e.tagName||"IFRAME"===e.tagName||"EMBED"===e.tagName||"OBJECT"===e.tagName||"DIV"===e.tagName&&e.hasAttribute("contenteditable")&&"false"!==e.getAttribute("contenteditable")||("AUDIO"===e.tagName||"VIDEO"===e.tagName)&&e.hasAttribute("controls"))}function l(e){return!(!e||!e.hasAttribute("disabled"))}function c(e){return!!a(e)&&(!e.hasAttribute("tabindex")||parseInt(e.getAttribute("tabindex"))>=0)}i.jsxLF=function(e,...t){const i=[];e.replace(/\{\d\}/g,e=>(i.push(parseInt(e.substr(1,1))),e));const s=[];let o,r=0;for(const a of i)o=e.split(`{${a}}`),pxt.U.assert(2===o.length),s.push((0,n.jsx)("span",{children:o[0]},r++)),s.push((0,n.jsx)("span",{children:t[a]},r++)),e=o[1];return s.push((0,n.jsx)("span",{children:e},r++)),s},i.fireClickOnEnter=function(e){const t="number"==typeof e.which?e.which:e.keyCode;13!==t&&32!==t||(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())},i.classList=function(...e){return e.filter(e=>"string"==typeof e).reduce((e,t)=>e.concat(t.split(" ")),[]).map(e=>e.trim()).filter(e=>!!e).join(" ")},i.nodeListToArray=function(e){const t=[];for(const i of e)t.push(i);return t},function(e){e[e.Selected=0]="Selected",e[e.Unselected=1]="Unselected",e[e.Waiting=2]="Waiting"}(i.CheckboxStatus||(i.CheckboxStatus={})),i.clientCoord=function(e){if(e.touches){const t=e;return t.touches.length?t.touches[0]:t.changedTouches[0]}return e},i.screenToSVGCoord=function(e,t){const i=e.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,i.matrixTransform(e.getScreenCTM().inverse())},i.findNextFocusableElement=function e(t,i,n,s,r,a=!0){const l=s?1:-1,c=t[n=Math.max(0,Math.min(t.length-1,n))];if(i===n)return c;if(r?r(c):o(c))return c;if(n+l>=t.length){if(!a)return c;n=0}else if(n+l<0){if(!a)return c;n=t.length-1}else n+=l;return e(t,i,n,s,r,a)},i.getFocusableDescendants=function(e){return s(e,a)},i.getTabbableDescendants=function(e){return s(e,c)},i.getVisibleDescendants=s,i.isFocusable=r,i.isDisabled=l,i.isTabbable=function(e){return c(e)&&o(e)},i.focusLastActive=function(e){for(;e&&!r(e);){const t=e.parentElement;if(!t)break;e=t}e.focus()}},{"react/jsx-runtime":305}],172:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useId=void 0;const n=e("react");i.useId=function(){return n.useMemo(()=>pxt.Util.guidGen(),[])}},{react:304}],173:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-dom"),r=e("./components/ImageFieldEditor"),a=e("./components/ImageEditor/store/imageReducer"),l=e("../../pxtservices/iframeEmbeddedClient");document.addEventListener("DOMContentLoaded",()=>{!function(){const e=document.getElementById("asset-editor-field-div");o.render((0,n.jsx)(c,{}),e)}()});class c extends s.Component{constructor(e){super(e),this.handleMessage=e=>{const t=e.data;switch(t.type){case"create":this.setPalette(t.palette),this.initTilemapProject(t.files);const e=this.getEmptyAsset(t.assetType,t.displayName);this.setState({editing:e,isEmptyAsset:!0}),this.sendResponse({id:t.id,type:t.type});break;case"open":this.setPalette(t.palette),this.initTilemapProject(t.files);const i=this.lookupAsset(t.assetType,t.assetId);"tilemap"===i.type&&pxt.sprite.addMissingTilemapTilesAndReferences(this.editorProject,i),this.setState({editing:i}),this.sendResponse({id:t.id,type:t.type});break;case"duplicate":this.setPalette(t.palette),this.initTilemapProject(t.files);const n=this.lookupAsset(t.assetType,t.assetId);this.setState({editing:this.editorProject.duplicateAsset(n)}),this.sendResponse({id:t.id,type:t.type});break;case"save":this.sendResponse({id:t.id,type:t.type,files:this.saveProjectFiles()})}},this.refHandler=e=>{e&&(this.editor=e,this.editor.init(this.state.editing,()=>{},{galleryTiles:this.galleryTiles,hideMyAssets:!0,hideCloseButton:!0}))},this.handleKeydown=e=>{!e.ctrlKey||"s"!==e.key&&"S"!==e.key||this.sendSaveRequest()},this.pollForUpdates=()=>{this.state.editing&&this.updateAsset()},this.sendSaveRequest=()=>{this.sendEvent({type:"event",kind:"done-clicked"})},this.state={},pxt.react.getTilemapProject=()=>this.editorProject,(0,a.setTelemetryFunction)(u)}componentDidMount(){this.iframeClient=new l.IFrameEmbeddedClient(this.handleMessage),window.addEventListener("keydown",this.handleKeydown,null),this.sendEvent({type:"event",kind:"ready"}),u("asset-editor-shown"),this.pollingInterval=setInterval(this.pollForUpdates,200)}componentWillUnmount(){window.removeEventListener("message",this.handleMessage,null),window.removeEventListener("keydown",this.handleKeydown,null),window.clearInterval(this.pollingInterval)}componentDidUpdate(e,t,i){var n;(null==t?void 0:t.editing)&&t.editing!==this.state.editing&&this.saveProject.removeChangeListener(t.editing.type,this.sendSaveRequest),(null===(n=this.state)||void 0===n?void 0:n.editing)&&this.saveProject.addChangeListener(this.state.editing,this.sendSaveRequest)}render(){if(this.state.editing){const e="song"===this.state.editing.type?"music":"image";return(0,n.jsx)(r.ImageFieldEditor,{ref:this.refHandler,singleFrame:"animation"!==this.state.editing.type,editorType:e,doneButtonCallback:this.sendSaveRequest,hideDoneButton:!0,includeSpecialTagsInFilter:!0})}return(0,n.jsx)("div",{})}sendResponse(e){this.postMessage(e)}sendEvent(e){this.postMessage(e)}postMessage(e){this.iframeClient.postMessage(e)}updateAsset(){var e,t,i,n,s;const o=this.editor.getValue(),r=pxt.cloneAsset(o);if(!this.lastValue||!pxt.assetEquals(this.lastValue,r)){if(this.lastValue=pxt.cloneAsset(o),"tilemap"===r.type&&o.type===r.type&&(r.data.deletedTiles=null===(e=o.data.deletedTiles)||void 0===e?void 0:e.slice(),r.data.editedTiles=null===(t=o.data.editedTiles)||void 0===t?void 0:t.slice(),r.data.projectReferences=null===(i=o.data.projectReferences)||void 0===i?void 0:i.slice(),r.data.tileOrder=null===(n=o.data.tileOrder)||void 0===n?void 0:n.slice()),this.saveProject=this.editorProject.clone(),this.state.isEmptyAsset){const e=null===(s=r.meta)||void 0===s?void 0:s.displayName;let t;switch(r.type){case"image":t=this.saveProject.createNewProjectImage(r.bitmap,e);break;case"tile":t=this.saveProject.createNewTile(r.bitmap,null,e);break;case"tilemap":pxt.sprite.updateTilemapReferencesFromResult(this.saveProject,r);const[i,n]=this.saveProject.createNewTilemapFromData(r.data,e);t=this.saveProject.lookupAssetByName("tilemap",i);break;case"animation":t=this.saveProject.createNewAnimationFromData(r.frames,r.interval,e);break;case"song":t=this.saveProject.createNewSong(r.song,e)}}else"tilemap"===r.type&&pxt.sprite.updateTilemapReferencesFromResult(this.saveProject,r),this.saveProject.updateAsset(r);this.sendSaveRequest()}}saveProjectFiles(){this.updateAsset();const e=pxt.inflateJRes(this.saveProject.getProjectAssetsJRes()),t=pxt.inflateJRes(this.saveProject.getProjectTilesetJRes()),i={};for(const t of Object.keys(e)){const n=this.locateFileForAsset(t)||pxt.IMAGES_JRES;i[n]||(i[n]={}),i[n][t]=e[t]}for(const e of Object.keys(t)){const n=this.locateFileForAsset(e)||pxt.TILEMAP_JRES;i[n]||(i[n]={}),i[n][e]=t[e]}const n=Object.assign({},this.files);for(const e of Object.keys(i)){n[e]=JSON.stringify(i[e],null,4);const t=e.substring(0,e.length-4)+"ts";(n[t]||e===pxt.IMAGES_JRES||e===pxt.TILEMAP_JRES)&&(n[t]=pxt.emitProjectImages(i[e])+"\n"+pxt.emitTilemapsFromJRes(i[e]))}return n}setPalette(e){e&&Array.isArray(e)&&e.length&&(pxt.appTarget.runtime.palette=e.slice())}initTilemapProject(e){var t;const i={},n={},s={},o={};this.editorProject=new pxt.TilemapProject,this.inflatedJres={},this.commentAttrs={};for(const t of Object.keys(e).filter(e=>!e.endsWith(".jres"))){const i=h(e[t]);for(const e of Object.keys(i))this.commentAttrs[e]=i[e]}for(const r of Object.keys(e).filter(e=>e.endsWith(".jres"))){const a=-1!==r.indexOf("pxt_modules")||-1!==r.indexOf("node_modules"),l=pxt.inflateJRes(JSON.parse(e[r]));this.inflatedJres[r]=l;for(const e of Object.keys(l)){if(null===(t=this.commentAttrs[e])||void 0===t?void 0:t.tags){const t=this.commentAttrs[e].tags.split(" ").filter(e=>!!e);t.length&&(l[e].tags=t)}l[e].mimeType===pxt.TILEMAP_MIME_TYPE||l[e].tilemapTile?a?n[e]=l[e]:i[e]=l[e]:a?o[e]=l[e]:s[e]=l[e]}}this.editorProject.loadAssetsJRes(o,!0),this.editorProject.loadAssetsJRes(s),this.editorProject.loadTilemapJRes(n,!1,!0),this.editorProject.loadTilemapJRes(i),this.galleryTiles=this.editorProject.getGalleryAssets("tile").map(e=>{var t;if(!this.commentAttrs[e.id])return;const i=null===(t=e.meta.tags)||void 0===t?void 0:t.map(e=>pxt.Util.startsWith(e,"category-")?e:e.toLowerCase());return i&&-1!==i.indexOf("tile")?{qName:e.id,bitmap:e.bitmap,alt:e.id,tags:i}:void 0}).filter(e=>!!e),this.saveProject=this.editorProject.clone()}locateFileForAsset(e){for(const t of Object.keys(this.inflatedJres))if(this.inflatedJres[t][e])return t}getEmptyAsset(e,t){const i=pxt.react.getTilemapProject(),n={type:e,id:"",internalID:0,meta:{displayName:i.generateNewName(e,t)}};switch(e){case"image":case"tile":n.bitmap=new pxt.sprite.Bitmap(16,16).data();break;case"tilemap":const e=n;e.data=i.blankTilemap(16,16,16),pxt.sprite.addMissingTilemapTilesAndReferences(i,e);break;case"animation":const t=n;t.frames=[new pxt.sprite.Bitmap(16,16).data()],t.interval=200;break;case"song":n.song=pxt.assets.music.getEmptySong(2)}return n}lookupAsset(e,t){const i=this.saveProject.lookupAsset(e,t);if(i)return i;const n=t.split(".");return this.saveProject.lookupAsset(e,n[n.length-1])}}function u(e){pxt.tickEvent("asset.editor",{action:e})}function h(e){const t=e.split("\n"),i={};let n,s="";for(const e of t){const t=/^namespace\s+([^\}]+)\s+\{$/.exec(e);if(t){n=t[1],s="";continue}if(/^\s+\/\/%\s/.test(e)){s+=e+"\n";continue}const o=/^\s*export\s+const\s+([^\s]+)\s*=/.exec(e);if(o){i[n+"."+o[1]]=pxtc.parseCommentString(s),s=""}}return i}i.AssetEditor=c},{"../../pxtservices/iframeEmbeddedClient":158,"./components/ImageEditor/store/imageReducer":191,"./components/ImageFieldEditor":197,react:304,"react-dom":268,"react/jsx-runtime":305}],174:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getLabelForAssetType=i.getIconClassForAssetType=i.assetToGalleryItem=i.getAssets=i.getNewInternalID=i.lookupAsset=i.createTile=i.createProjectImage=i.createNewImageAsset=i.isNameTaken=void 0;const n=e("../../pxtblocks");function s(e,t=new pxt.ImageConverter){var i;switch(e.type){case"image":case"tile":return e.previewURI=t.convert("data:image/x-mkcd-f,"+e.jresData),e;case"tilemap":let s=e.data.tilemap;return e.previewURI=n.tilemapToImageURI(e.data,Math.max(s.width,s.height),!1),e;case"animation":return(null===(i=e.frames)||void 0===i?void 0:i.length)<=0?null:(e.framePreviewURIs=e.frames.map(e=>t.convert("data:image/x-mkcd-f,"+pxt.sprite.base64EncodeBitmap(e))),e.previewURI=e.framePreviewURIs[0],e);case"song":return e.previewURI=n.songToDataURI(e.song,32,32,!1,1),e;case"json":return e}}function o(e){return function(t,i){const n=-1===e.indexOf(t.meta.package)?0:1,s=-1===e.indexOf(i.meta.package)?0:1;return n===s?function(e,t){return e.internalID-t.internalID}(t,i):n-s}}i.isNameTaken=function(e){return pxt.react.getTilemapProject().isNameTaken("image",e)},i.createNewImageAsset=function(e,t,i,n){const s=pxt.react.getTilemapProject();switch(e){case"tile":return s.createNewTile(new pxt.sprite.Bitmap(t,i).data(),null,n);case"image":return s.createNewImage(t,i)}return null},i.createProjectImage=function(e){return pxt.react.getTilemapProject().createNewProjectImage(e)},i.createTile=function(e,t,i){return pxt.react.getTilemapProject().createNewTile(e,t,i)},i.lookupAsset=function(e,t){return pxt.react.getTilemapProject().lookupAsset(e,t)},i.getNewInternalID=function(){return pxt.react.getTilemapProject().getNewInternalId()},i.getAssets=function(e=!1,t="image",i=[]){const n=pxt.react.getTilemapProject(),r=new pxt.ImageConverter,a=e=>s(e,r),l=e?n.getGalleryAssets.bind(n):n.getAssets.bind(n),c=function(){var e;const t=null===(e=pxt.appTarget.blocksprj)||void 0===e?void 0:e.config;if(t){return Object.keys(t.dependencies)}return[]}(),u=l("image").map(a).sort(o(c)),h=l("tile").map(a).filter(e=>!e.id.match(/^myTiles.transparency(8|16|32)$/gi)).sort(o(c)),d=l("tilemap").map(a).sort(o(c)),p=l("animation").map(a).sort(o(c)),g=l("song").map(a).sort(o(c)),f=l("json").map(a).sort(o(c));for(const e of i)switch(e.type){case"image":u.push(a(e));break;case"tile":h.push(a(e));break;case"animation":p.push(a(e));break;case"tilemap":d.push(a(e));break;case"song":g.push(a(e));break;case"json":f.push(a(e))}let m=[];switch(t){case"image":m=u.concat(h).concat(p).concat(d).concat(g).concat(f);break;case"tile":m=h.concat(u).concat(p).concat(d).concat(g).concat(f);break;case"animation":m=p.concat(u).concat(h).concat(d).concat(g).concat(f);break;case"tilemap":m=d.concat(h).concat(u).concat(p).concat(g).concat(f);break;case"song":m=g.concat(u).concat(h).concat(p).concat(d).concat(f);break;case"json":m=f.concat(u).concat(h).concat(p).concat(d).concat(g)}return pxt.tickEvent(e?"assets.gallery":"assets.update",{count:m.length}),m},i.assetToGalleryItem=s,i.getIconClassForAssetType=function(e){var t;if("object"==typeof(null===(t=pxt.appTarget.appTheme)||void 0===t?void 0:t.assetEditor)){const t=pxt.appTarget.appTheme.assetEditor[e];if("object"==typeof t&&t.iconClass)return t.iconClass}switch(e){case"tile":return"clone";case"animation":return"video";case"tilemap":return"map";case"song":return"music";case"json":return"file code";default:return null}},i.getLabelForAssetType=function(e){var t;if("object"==typeof(null===(t=pxt.appTarget.appTheme)||void 0===t?void 0:t.assetEditor)){const t=pxt.appTarget.appTheme.assetEditor[e];if("object"==typeof t&&t.label)return pxt.U.rlf(`{id:assetType}${t.label}`)}switch(e){case"image":return lf("Image");case"tile":return lf("Tile");case"animation":return lf("Animation");case"tilemap":return lf("Tilemap");case"song":return lf("Song");case"json":return lf("File")}}},{"../../pxtblocks":76}],175:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FilterPanel=i.FilterPanelSubheading=i.FilterTag=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util");class r extends s.Component{constructor(e){super(e),this.clickHandler=this.clickHandler.bind(this)}render(){return(0,n.jsxs)("div",Object.assign({className:"filter-tag"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-tag-box",role:"checkbox",onClick:this.clickHandler,onKeyDown:o.fireClickOnEnter,"aria-checked":this.props.selected},{children:(0,n.jsx)("i",{className:"icon square outline "+(this.props.selected?"check":"")})})),(0,n.jsx)("div",Object.assign({className:"filter-tag-name",role:"button",onClick:this.clickHandler,onKeyDown:o.fireClickOnEnter},{children:pxtc.U.rlf(this.props.tag)}))]}))}clickHandler(){this.props.onClickHandler(this.props.tag)}}i.FilterTag=r;class a extends s.Component{render(){return(0,n.jsxs)("div",Object.assign({className:"filter-subheading-row"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-subheading-title"},{children:`${this.props.subheading}:`})),this.props.buttonText&&(0,n.jsx)("div",Object.assign({className:"filter-subheading-button",role:"button",style:this.props.buttonStyle,onClick:this.props.buttonAction,onKeyDown:o.fireClickOnEnter},{children:this.props.buttonText}))]}))}}i.FilterPanelSubheading=a;class l extends s.Component{isTagSelected(e){return this.props.enabledTags.indexOf(e.toLowerCase())>=0}render(){const e=this.props.tagOptions;return(0,n.jsxs)("div",Object.assign({className:"filter-panel"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-title"},{children:lf("Filter")})),(0,n.jsx)(a,{subheading:lf("Categories"),buttonText:lf("Clear"),buttonAction:this.props.clearTags,buttonStyle:this.props.enabledTags.length>0?{color:"white"}:{}}),(0,n.jsx)("div",Object.assign({className:"filter-tag-list"},{children:e.map(e=>(0,n.jsx)(r,{tag:e,selected:this.isTagSelected(e),onClickHandler:this.props.tagClickHandler},e))}))]}))}}i.FilterPanel=l},{"../util":240,react:304,"react/jsx-runtime":305}],176:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Alert=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch");class a extends s.Component{constructor(e){super(e)}render(){const{title:e,text:t,options:i,dispatchHideAlert:s}=this.props;return(0,n.jsx)("div",Object.assign({className:"image-editor-alert-container",role:"region",onClick:s},{children:(0,n.jsxs)("div",Object.assign({className:"image-editor-alert",role:"dialog"},{children:[(0,n.jsxs)("div",Object.assign({className:"title"},{children:[(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Warning"}),(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Cancel",role:"button",onClick:s})]})),(0,n.jsx)("div",Object.assign({className:"text"},{children:t})),i&&(0,n.jsx)("div",Object.assign({className:"options"},{children:i.map((e,t)=>(0,n.jsx)("div",Object.assign({className:"button",role:"button",onClick:e.onClick},{children:e.label}),t))}))]}))}))}}const l={dispatchHideAlert:r.dispatchHideAlert};i.Alert=(0,o.connect)(function({editor:e},t){return e?t:{}},l)(a)},{"./actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],177:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.BottomBar=i.BottomBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("../../assets"),l=e("./keyboardShortcuts"),c=e("../../../../react-common/components/util"),u=e("../../../../react-common/components/controls/Button");class h extends s.Component{constructor(e){super(e),this.disableShortcutsOnFocus=()=>{this.setShortcutsEnabled(!1)},this.handleWidthChange=e=>{const t=e.target.value,i=parseInt(t),{aspectRatioLocked:n,imageDimensions:s}=this.props;!isNaN(i)&&n?this.setState({width:i+"",height:Math.floor(i*(s[1]/s[0]))+""}):this.setState({width:t})},this.handleHeightChange=e=>{const t=e.target.value,i=parseInt(t),{aspectRatioLocked:n,imageDimensions:s}=this.props;!isNaN(i)&&n?this.setState({height:i+"",width:Math.floor(i*(s[0]/s[1]))+""}):this.setState({height:t})},this.handleDimensionalBlur=()=>{const{imageDimensions:e,isTilemap:t,dispatchChangeImageDimensions:i}=this.props,n=parseInt(this.state.width),s=parseInt(this.state.height),o=t?255:512,r=isNaN(n)?e[0]:Math.min(Math.max(n,1),o),a=isNaN(s)?e[1]:Math.min(Math.max(s,1),o);r===e[0]&&a===e[1]||i([r,a]),this.setState({width:null,height:null}),this.setShortcutsEnabled(!0)},this.handleDimensionalKeydown=e=>{13===("number"==typeof e.which?e.which:e.keyCode)&&e.currentTarget.blur()},this.handleAssetNameChange=e=>{let t=null;const i=e.target.value||"",n=i.trim();pxt.validateAssetName(n)?(0,a.isNameTaken)(n)&&n!==this.props.assetName&&(t=lf("This name is already used elsewhere in your project")):t=lf("Names may only contain letters, numbers, '-', '_', and space"),this.setState({assetName:i,assetNameMessage:t})},this.handleAssetNameBlur=()=>{const{dispatchChangeAssetName:e,assetName:t}=this.props;if(this.state.assetName){let i=this.state.assetName.trim();i!==t&&pxt.validateAssetName(i)&&!(0,a.isNameTaken)(i)&&e(i)}this.setState({assetName:null,assetNameMessage:null}),this.setShortcutsEnabled(!0)},this.zoomIn=()=>{this.props.dispatchChangeZoom(1)},this.zoomOut=()=>{this.props.dispatchChangeZoom(-1)},this.state={}}render(){const{imageDimensions:e,cursorLocation:t,hasUndo:i,hasRedo:s,dispatchUndoImageEdit:o,dispatchRedoImageEdit:r,aspectRatioLocked:a,onionSkinEnabled:l,dispatchToggleAspectRatioLocked:h,dispatchToggleOnionSkinEnabled:d,resizeDisabled:p,singleFrame:g,onDoneClick:f,assetName:m,hideDoneButton:_,hideAssetName:b}=this.props,{assetNameMessage:T}=this.state,E=null==this.state.width?e[0]:this.state.width,v=null==this.state.height?e[1]:this.state.height,y=null==this.state.assetName?m||"":this.state.assetName;return(0,n.jsxs)("div",Object.assign({className:"image-editor-bottombar"},{children:[!p&&(0,n.jsxs)("div",Object.assign({className:"image-editor-resize"},{children:[(0,n.jsx)("input",{className:"image-editor-input",title:lf("Image Width"),value:E,tabIndex:0,onChange:this.handleWidthChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleDimensionalBlur,onKeyDown:this.handleDimensionalKeydown}),(0,n.jsx)(u.Button,{className:(0,c.classList)("image-editor-button",!a&&"toggle"),onClick:h,leftIcon:a?"ms-Icon ms-Icon--Lock":"ms-Icon ms-Icon--Unlock",title:a?lf("Unlock Aspect Ratio"):lf("Lock Aspect Ratio")}),(0,n.jsx)("input",{className:"image-editor-input",title:lf("Image Height"),value:v,tabIndex:0,onChange:this.handleHeightChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleDimensionalBlur,onKeyDown:this.handleDimensionalKeydown})]})),!g&&(0,n.jsx)("div",{className:"image-editor-seperator"}),!g&&(0,n.jsx)("div",{children:(0,n.jsx)(u.Button,{onClick:d,className:(0,c.classList)("image-editor-button",!l&&"toggle"),leftIcon:"ms-Icon ms-Icon--MapLayers",title:l?lf("Hide Previous Frame"):lf("Show Previous Frame")})}),!p&&(0,n.jsx)("div",{className:(0,c.classList)("image-editor-seperator",!t&&"transparent")}),(0,n.jsx)("div",Object.assign({className:"image-editor-coordinate-preview"},{children:t&&`${t[0]}, ${t[1]}`})),(0,n.jsx)("div",Object.assign({className:"image-editor-change-name"},{children:!b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{className:"image-editor-input",title:lf("Asset Name"),value:y,placeholder:lf("Asset Name"),tabIndex:0,onChange:this.handleAssetNameChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleAssetNameBlur,onKeyDown:this.handleDimensionalKeydown}),T&&(0,n.jsx)("div",Object.assign({className:"ui pointing below red basic label"},{children:T}))]})})),(0,n.jsxs)("div",Object.assign({className:"image-editor-undo-redo"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button",title:lf("Undo"),leftIcon:"ms-Icon ms-Icon--Undo",onClick:i?o:null,disabled:!i}),(0,n.jsx)(u.Button,{className:"image-editor-button",title:lf("Redo"),leftIcon:"ms-Icon ms-Icon--Redo",onClick:s?r:null,disabled:!s})]})),(0,n.jsx)("div",{className:"image-editor-seperator"}),(0,n.jsxs)("div",Object.assign({className:"image-editor-zoom-controls"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button toggle",onClick:this.zoomOut,leftIcon:"ms-Icon ms-Icon--ZoomOut",title:lf("Zoom Out")}),(0,n.jsx)(u.Button,{className:"image-editor-button toggle",onClick:this.zoomIn,leftIcon:"ms-Icon ms-Icon--ZoomIn",title:lf("Zoom In")})]})),!_&&(0,n.jsx)(u.Button,{className:"image-editor-confirm",title:lf("Done"),label:lf("Done"),onClick:f})]}))}setShortcutsEnabled(e){e&&this.shortcutLock?((0,l.releaseShortcutLock)(this.shortcutLock),this.shortcutLock=void 0):e||this.shortcutLock||(this.shortcutLock=(0,l.obtainShortcutLock)())}}i.BottomBarImpl=h;const d={dispatchChangeImageDimensions:r.dispatchChangeImageDimensions,dispatchUndoImageEdit:r.dispatchUndoImageEdit,dispatchRedoImageEdit:r.dispatchRedoImageEdit,dispatchToggleAspectRatioLocked:r.dispatchToggleAspectRatioLocked,dispatchToggleOnionSkinEnabled:r.dispatchToggleOnionSkinEnabled,dispatchChangeZoom:r.dispatchChangeZoom,dispatchChangeAssetName:r.dispatchChangeAssetName};i.BottomBar=(0,o.connect)(function({store:{present:e,past:t,future:i},editor:n},s){var o,r,a;if(!e)return{};const l=n.isTilemap?e.tilemap.bitmap:e.frames[e.currentFrame].bitmap;return{imageDimensions:[l.width,l.height],aspectRatioLocked:e.aspectRatioLocked,onionSkinEnabled:n.onionSkinEnabled,cursorLocation:n.cursorLocation,resizeDisabled:"tile"===(null===(o=e.asset)||void 0===o?void 0:o.type),assetName:null===(a=null===(r=e.asset)||void 0===r?void 0:r.meta)||void 0===a?void 0:a.displayName,hasUndo:!!t.length,hasRedo:!!i.length,isTilemap:n.isTilemap}},d)(h)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"../../assets":174,"./actions/dispatch":187,"./keyboardShortcuts":189,react:304,"react-redux":287,"react/jsx-runtime":305}],178:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CursorSizes=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./actions/dispatch"),r=e("react-redux"),a=e("../../../../react-common/components/controls/Button"),l=e("../../../../react-common/components/util");class c extends s.Component{constructor(){super(...arguments),this.handlers=[]}render(){const{selected:e}=this.props;return(0,n.jsxs)("div",Object.assign({className:"cursor-buttons"},{children:[(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",1!==e&&"toggle"),title:lf("Small Cursor (1px)"),label:(0,n.jsx)("div",{className:"cursor-button small"}),onClick:this.clickHandler(1)}),(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",3!==e&&"toggle"),title:lf("Small Cursor (3px)"),label:(0,n.jsx)("div",{className:"cursor-button medium"}),onClick:this.clickHandler(3)}),(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",5!==e&&"toggle"),title:lf("Small Cursor (5px)"),label:(0,n.jsx)("div",{className:"cursor-button large"}),onClick:this.clickHandler(5)})]}))}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>{const{dispatchChangeCursorSize:t}=this.props;t(e)}),this.handlers[e]}}const u={dispatchChangeCursorSize:o.dispatchChangeCursorSize};i.CursorSizes=(0,r.connect)(function({editor:e},t){return e?{selected:e.cursorSize}:{}},u)(c)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"./actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],179:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageCanvas=i.ImageCanvasImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/imageReducer"),a=e("./actions/dispatch"),l=e("./util"),c=e("./toolDefinitions"),u=e("../../assets"),h=e("./keyboardShortcuts"),d=e("./ImageEditor"),p="image/x-mkcd-f4",g=[r.TileDrawingMode.Wall];class f extends s.Component{constructor(){super(...arguments),this.cursor=c.ToolCursor.Crosshair,this.zoom=2.5,this.panX=0,this.panY=0,this.hasInteracted=!1,this.tileCache={},this.onKeyDown=e=>{var t,i;if((0,h.areShortcutsEnabled)()&&(this.hasInteracted=!0,!e.repeat)){switch(!e.ctrlKey&&!e.metaKey||"c"!==e.key&&"v"!==e.key||e.stopPropagation(),(e.ctrlKey||e.metaKey)&&"a"===e.key&&this.shouldHandleCanvasShortcut()&&(this.selectAll(),e.preventDefault()),"Escape"==e.key&&(null===(i=null===(t=this.editState)||void 0===t?void 0:t.floating)||void 0===i?void 0:i.image)&&this.shouldHandleCanvasShortcut()&&(this.cancelSelection(),e.preventDefault()),this.lastTool=this.props.tool,e.keyCode){case 18:this.props.dispatchChangeImageTool(r.ImageEditorTool.ColorSelect),e.preventDefault();break;case 32:this.props.dispatchChangeImageTool(r.ImageEditorTool.Pan);break;default:this.lastTool=null}this.updateCursor(!1,!1)}},this.onKeyUp=e=>{null!=this.lastTool&&(this.props.dispatchChangeImageTool(this.lastTool),this.lastTool=null,this.updateCursor(!1,!1))},this.onCopy=e=>{var t,i;if(this.props.tool===r.ImageEditorTool.Marquee&&(null===(i=null===(t=this.editState)||void 0===t?void 0:t.floating)||void 0===i?void 0:i.image))if(e.preventDefault(),this.props.isTilemap)e.clipboardData.setData("application/makecode-tilemap",JSON.stringify((0,l.createTilemapPatchFromFloatingLayer)(this.editState,this.props.tilemapState.tileset)));else{const t=pxt.sprite.bitmapToImageLiteral(this.editState.floating.image,"typescript");e.clipboardData.setData("application/makecode-image",t),e.clipboardData.setData("text/plain",t)}},this.onPaste=e=>{if(this.props.isTilemap){const t=e.clipboardData.getData("application/makecode-tilemap");let i;try{i=JSON.parse(t)}catch(e){}if(!(i&&i.map&&i.layers&&i.tiles))return;return e.preventDefault(),void this.applyTilemapPatch(i)}let t=e.clipboardData.getData("application/makecode-image");if(!t){const i=e.clipboardData.getData("text/plain"),n=/img(`|\(""")[\s\da-f.#tngrpoyw]+(`|"""\))/im.exec(i);n&&(t=n[0])}const i=t&&pxt.sprite.imageLiteralToBitmap(t);i&&i.width&&i.height&&(e.preventDefault(),this.props.tool!==r.ImageEditorTool.Marquee&&this.props.dispatchChangeImageTool(r.ImageEditorTool.Marquee),this.editState.mergeFloatingLayer(),this.editState.setFloatingLayer(i),this.props.dispatchImageEdit(this.editState.toImageState()))},this.preventContextMenu=e=>e.preventDefault()}render(){const e=this.getImageState(),t=!e||e.bitmap.height>e.bitmap.width,i=!this.props.isTilemap&&this.props.tool==r.ImageEditorTool.Marquee;return(0,n.jsx)("div",Object.assign({ref:"canvas-bounds",className:"image-editor-canvas "+(t?"portrait":"landscape"),onContextMenu:this.preventContextMenu,tabIndex:0},{children:(0,n.jsxs)("div",Object.assign({className:"paint-container"},{children:[!this.props.lightMode&&(0,n.jsx)("canvas",{ref:"paint-surface-bg",className:"paint-surface"}),(0,n.jsx)("canvas",{ref:"paint-surface",className:"paint-surface main"}),g.map((e,t)=>(0,n.jsx)("canvas",{ref:`paint-surface-${e.toString()}`,className:"paint-surface overlay "+(this.props.overlayEnabled?"":"hide")},t)),(0,n.jsx)("div",{ref:"floating-layer-border",className:"image-editor-floating-layer"}),i&&(0,n.jsx)("div",{ref:"floating-layer-nw-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-ne-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-se-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-sw-corner",className:"image-editor-floating-layer-corner"})]}))}))}componentDidMount(){document.activeElement instanceof HTMLElement&&document.activeElement.blur(),this.tileCache={},this.cellWidth=this.props.isTilemap?this.props.tilemapState.tileset.tileWidth:1,this.canvas=this.refs["paint-surface"],this.background=this.refs["paint-surface-bg"],this.floatingLayer=this.refs["floating-layer-border"],this.canvasLayers=g.map(e=>this.refs[`paint-surface-${e.toString()}`]),(0,l.bindGestureEvents)(this.refs["canvas-bounds"],this);const e=this.refs["canvas-bounds"];e.addEventListener("wheel",e=>{this.hasInteracted=!0,this.updateZoom(e.deltaY/30,e.clientX,e.clientY),e.preventDefault()}),e.addEventListener("mousemove",e=>{e.button||(this.hasHover=!0),this.edit||this.updateCursorLocation(e)}),e.addEventListener("mouseout",e=>{this.edit||this.updateCursorLocation(null)}),document.addEventListener("keydown",this.onKeyDown,!0),document.addEventListener("keyup",this.onKeyUp),document.addEventListener("copy",this.onCopy),document.addEventListener("paste",this.onPaste);const t=this.getImageState();this.editState=(0,c.getEditState)(t,this.props.isTilemap,this.props.drawingMode),this.redraw(),this.updateBackground()}componentDidUpdate(){if(!this.edit||!this.editState){const e=this.getImageState();this.editState=(0,c.getEditState)(e,this.props.isTilemap,this.props.drawingMode)}if(this.props.isTilemap||(this.tileCache={}),this.cellWidth=this.props.isTilemap?this.props.tilemapState.tileset.tileWidth:1,this.props.zoomDelta||0===this.props.zoomDelta)return 0===this.props.zoomDelta?this.hasInteracted||this.zoomToCanvas():(this.hasInteracted=!0,this.updateZoom(this.props.zoomDelta)),void this.props.dispatchChangeZoom(null);this.redraw(),this.updateBackground()}componentWillUnmount(){this.tileCache={},document.removeEventListener("keydown",this.onKeyDown,!0),document.removeEventListener("keyup",this.onKeyUp),document.removeEventListener("copy",this.onCopy),document.removeEventListener("paste",this.onPaste)}onClick(e,t){var i,n;this.hasInteracted=!0,this.isPanning()||(document.activeElement instanceof HTMLElement&&document.activeElement!==this.refs["canvas-bounds"]&&document.activeElement.blur(),this.focus(),this.isColorSelect()?this.selectCanvasColor(e,t):(this.updateCursorLocation(e),this.inBounds(this.cursorLocation[0],this.cursorLocation[1])?(this.touchesResize(e.clientX,e.clientY)&&(this.isResizing=!0),this.startEdit(!!t),this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit()):(null===(n=null===(i=this.editState)||void 0===i?void 0:i.floating)||void 0===n?void 0:n.image)&&(this.editState.mergeFloatingLayer(),this.props.dispatchImageEdit(this.editState.toImageState()))))}onDragStart(e,t){this.hasInteracted=!0,this.focus(),this.touchesResize(e.clientX,e.clientY)&&(this.isResizing=!0),this.isPanning()?(this.lastPanX=e.clientX,this.lastPanY=e.clientY,this.updateCursor(!0,!1)):this.isColorSelect()?this.selectCanvasColor(e,t):(this.updateCursorLocation(e),this.startEdit(!!t),this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]))}onDragMove(e){if(this.focus(),this.isPanning()&&null!=this.lastPanX&&null!=this.lastPanY)this.panX+=this.lastPanX-e.clientX,this.panY+=this.lastPanY-e.clientY,this.lastPanX=e.clientX,this.lastPanY=e.clientY,this.updateCursor(!0,!1);else{if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1])}}onDragEnd(e){if(this.isPanning()&&null!=this.lastPanX&&null!=this.lastPanY)this.panX+=this.lastPanX-e.clientX,this.panY+=this.lastPanY-e.clientY,this.lastPanX=void 0,this.lastPanY=void 0,this.updateCursor(!1,!1);else if(this.isResizing){if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit(!1),this.updateCursor(!1,!1)}else{if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit()}this.isResizing=!1}updateCursorLocation(e){if(!e)return this.cursorLocation&&(this.cursorLocation=null,this.props.dispatchChangeCursorLocation(null),this.edit||this.redraw()),!1;if(this.canvas){const t=this.canvas.getBoundingClientRect(),i=Math.floor((e.clientX-t.left)/t.width*this.imageWidth),n=Math.floor((e.clientY-t.top)/t.height*this.imageHeight);return(!this.cursorLocation||i!==this.cursorLocation[0]||n!==this.cursorLocation[1])&&(this.cursorLocation=[i,n,e.clientX,e.clientY],this.hasHover&&this.props.dispatchChangeCursorLocation(this.cursorLocation),this.edit||this.redraw(),this.updateCursor(!!this.edit,this.editState.inFloatingLayer(i,n)),!0)}return this.cursorLocation=[0,0,e.clientX,e.clientY],!1}updateCursor(e,t){const{tool:i}=this.props,n=c.tools.find(e=>e.tool===i);n?t?e?this.updateCursorCore(n.downLayerCursor||n.hoverLayerCursor||n.downCursor||n.hoverCursor):this.updateCursorCore(n.hoverLayerCursor||n.hoverCursor):e?this.updateCursorCore(n.downCursor||n.hoverCursor):this.updateCursorCore(n.hoverCursor):this.updateCursorCore(c.ToolCursor.Default)}updateCursorCore(e){this.cursor=e||c.ToolCursor.Default,this.updateBackground()}startEdit(e){const{tool:t,toolWidth:i,selectedColor:n,backgroundColor:s,drawingMode:o}=this.props,[a,l]=this.cursorLocation;if(this.inBounds(a,l)||this.isResizing){let a=o==r.TileDrawingMode.Wall?2:e?s:n;this.edit=(0,c.getEdit)(t,this.editState,a,i),this.edit.originalImage=this.originalImage,this.edit.start(this.cursorLocation[0],this.cursorLocation[1],this.cursorLocation[2],this.cursorLocation[3],this.editState)}}updateEdit(e,t){this.edit&&(this.edit.inBounds(e,t)||this.isResizing)&&(this.edit.update(e,t),this.redraw())}commitEdit(e=!0){const{dispatchImageEdit:t}=this.props,i=this.getImageState();this.edit&&(this.editState=(0,c.getEditState)(i,this.props.isTilemap,this.props.drawingMode),this.edit.doEdit(this.editState),this.originalImage=e?void 0:this.edit.originalImage,this.edit=void 0,t(this.editState.toImageState()))}redraw(){const{prevFrame:e,onionSkinEnabled:t,selectedColor:i,toolWidth:n,drawingMode:s,tool:o}=this.props,a=this.getImageState(),l=s==r.TileDrawingMode.Wall?2:i;let u=!1;if(this.canvas){if(this.imageWidth=a.bitmap.width,this.imageHeight=a.bitmap.height,u=this.canvas.width!=a.bitmap.width*this.cellWidth||this.canvas.height!=a.bitmap.height*this.cellWidth,this.canvas.width=a.bitmap.width*this.cellWidth,this.canvas.height=a.bitmap.height*this.cellWidth,this.canvasLayers.forEach(e=>{e.width=this.canvas.width/this.cellWidth,e.height=this.canvas.height/this.cellWidth}),t&&e){const t=(0,c.getEditState)(e,this.props.isTilemap,s),i=this.canvas.getContext("2d");i.globalAlpha=.5,this.drawImage(t.image),t.floating&&t.floating.image&&this.drawImage(t.floating.image,t.layerOffsetX,t.layerOffsetY,!0),i.globalAlpha=1}if(this.edit){const i=this.editState.copy();i.setActiveLayer(s),this.edit.doEdit(i),this.drawImage(i.image,0,0,!(!t||!e)),this.drawOverlayLayers(i.overlayLayers),this.redrawFloatingLayer(i)}else if(this.drawImage(this.editState.image,0,0,!(!t||!e)),this.drawOverlayLayers(this.editState.overlayLayers),this.redrawFloatingLayer(this.editState),this.cursorLocation&&this.shouldDrawCursor()){const e=o===r.ImageEditorTool.Erase?0:l;this.drawCursor(this.cursorLocation[0]-(n>>1),this.cursorLocation[1]-(n>>1),n,e)}if(this.background&&(this.background.width!=this.canvas.width<<1||this.background.height!=this.canvas.height<<1)){this.background.width=this.canvas.width<<1,this.background.height=this.canvas.height<<1;const e=this.background.getContext("2d");e.imageSmoothingEnabled=!1,e.fillStyle="#aeaeae",e.fillRect(0,0,this.background.width,this.background.height),e.fillStyle="#dedede";const t=this.imageHeight<<1,i=this.imageWidth<<1;for(let n=0;n<i;n++)for(let i=0;i<t;i++)n+i&1&&e.fillRect(n*this.cellWidth,i*this.cellWidth,this.cellWidth,this.cellWidth)}}u&&this.zoomToCanvas()}drawImage(e,t=0,i=0,n=!1,s=!this.props.lightMode){this.props.isTilemap?this.drawTilemap(e,t,i,n,s):this.drawBitmap(e,t,i,n,s)}redrawFloatingLayer(e,t=!1){const i=this.refs["floating-layer-border"],n=this.refs["floating-layer-nw-corner"],s=this.refs["floating-layer-ne-corner"],o=this.refs["floating-layer-se-corner"],r=this.refs["floating-layer-sw-corner"],a=[n,s,o,r];if(e.floating&&e.floating.image){t||(this.drawImage(e.floating.image,e.layerOffsetX,e.layerOffsetY,!0),e.floating.overlayLayers&&this.drawOverlayLayers(e.floating.overlayLayers,e.layerOffsetX,e.layerOffsetY));const l=this.canvas.getBoundingClientRect(),c=Math.max(e.layerOffsetX,0),u=Math.max(e.layerOffsetY,0),h=Math.min(e.layerOffsetX+e.floating.image.width,e.width),d=Math.min(e.layerOffsetY+e.floating.image.height,e.height),p=l.width/e.width,g=l.height/e.height;i.style.display="",(h-c<1||d-u<1)&&(i.style.display="none");const f=-this.panX+p*c,m=-this.panY+g*u,_=p*(h-c),b=g*(d-u);i.style.left=f+"px",i.style.top=m+"px",i.style.width=_+"px",i.style.height=b+"px",i.style.borderLeft=e.layerOffsetX>=0?"":"none",i.style.borderTop=e.layerOffsetY>=0?"":"none",i.style.borderRight=e.layerOffsetX+e.floating.image.width<=e.width?"":"none",i.style.borderBottom=e.layerOffsetY+e.floating.image.height<=e.height?"":"none";if(null!=n){const e=16,t=3;this.props.isTilemap||(a.forEach(i=>{i.style.display="",i.style.width=e+"px",i.style.height=e+"px",i.style.border=t+"px solid black",i.style.position="absolute",i.style.backgroundColor="white"}),n.style.left=f-e+"px",n.style.top=m-e+"px",n.style.cursor="nw-resize",s.style.left=f+_+"px",s.style.top=m-e+"px",s.style.cursor="ne-resize",o.style.left=f+_+"px",o.style.top=m+b+"px",o.style.cursor="se-resize",r.style.left=f-e+"px",r.style.top=m+b+"px",r.style.cursor="sw-resize")}}else i.style.display="none",a.forEach(e=>{e&&(e.style.display="none")})}drawOverlayLayers(e,t=0,i=0,n=!this.props.lightMode){e&&e.forEach((e,s)=>{this.drawBitmap(e,t,i,!0,n,this.canvasLayers[s])})}drawBitmap(e,t=0,i=0,n=!1,s=!this.props.lightMode,o=this.canvas){const{colors:r}=this.props,a=o.getContext("2d");a.imageSmoothingEnabled=!1;for(let s=0;s<e.width;s++)for(let o=0;o<e.height;o++){const l=e.get(s,o);l?(a.fillStyle=r[l],a.fillRect(s+t,o+i,1,1)):n||a.clearRect(s+t,o+i,1,1)}}generateTile(e,t){if(!t.tiles[e])return null;const i=document.createElement("canvas");return i.width=t.tileWidth,i.height=t.tileWidth,this.drawBitmap(pxt.sprite.Bitmap.fromData(t.tiles[e].bitmap),0,0,!1,!this.props.lightMode,i),this.tileCache[t.tiles[e].id]=i,i}drawTilemap(e,t=0,i=0,n=!1,s=!this.props.lightMode,o=this.canvas){const{tilemapState:{tileset:r}}=this.props,a=o.getContext("2d");let l,c;this.tileCacheRevision!==this.props.tilesetRevision&&(this.tileCache={},this.tileCacheRevision=this.props.tilesetRevision),a.imageSmoothingEnabled=!1,a.fillStyle=d.LIGHT_MODE_TRANSPARENT;for(let o=0;o<e.width;o++)for(let u=0;u<e.height;u++)if(l=e.get(o,u),l&&l<r.tiles.length){if(c=this.tileCache[r.tiles[l].id],c||(c=this.generateTile(l,r)),!c)continue;a.drawImage(c,(o+t)*this.cellWidth,(u+i)*this.cellWidth)}else n||(s?a.clearRect((o+t)*this.cellWidth,(u+i)*this.cellWidth,this.cellWidth,this.cellWidth):a.fillRect((o+t)*this.cellWidth,(u+i)*this.cellWidth,this.cellWidth,this.cellWidth))}drawCursor(e,t,i,n){const s=this.props.isTilemap&&this.props.drawingMode===r.TileDrawingMode.Wall,o=(s?this.canvasLayers[0]:this.canvas).getContext("2d");if(o.imageSmoothingEnabled=!1,n&&-1!==n)if(this.props.isTilemap&&!s){if(n>=this.props.tilemapState.tileset.tiles.length)return;let s=this.tileCache[this.props.tilemapState.tileset.tiles[n].id];if(s||(s=this.generateTile(n,this.props.tilemapState.tileset)),!s)return;for(let n=0;n<i;n++)for(let r=0;r<i;r++)o.drawImage(s,(e+n)*this.cellWidth,(t+r)*this.cellWidth)}else s?(o.fillStyle=this.props.colors[n],o.fillRect(e,t,1,1)):(o.fillStyle=this.props.colors[n],o.fillRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth));else this.props.lightMode?(o.fillStyle=d.LIGHT_MODE_TRANSPARENT,o.fillRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth)):o.clearRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth)}updateBackground(){this.refs["canvas-bounds"].style.cursor=this.cursor,this.canvas.style.cursor=this.cursor,this.updateZoom(0)}updateZoom(e,t,i){const n=this.refs["canvas-bounds"];if(this.canvas&&n){const s=n.getBoundingClientRect();t=void 0===t?s.left+(s.width>>1):t,i=void 0===i?s.top+(s.height>>1):i;const{canvasX:o,canvasY:r}=this.clientToCanvas(t,i,s);this.zoom=Math.max(this.zoom+e,2.5);const a=this.getCanvasUnit(s);if(a){const{canvasX:e,canvasY:n}=this.clientToCanvas(t,i,s);if(isNaN(e)||isNaN(n)||isNaN(o)||isNaN(r))return;this.panX+=(o-e)*a,this.panY+=(r-n)*a}this.applyZoom()}}getCenteredPan(){let[e,t]=[0,0];const i=this.refs["canvas-bounds"].getBoundingClientRect(),n=this.canvas.getBoundingClientRect();return n.width<i.width&&(e=-((i.width>>1)-(n.width>>1))),n.height<i.height&&(t=-((i.height>>1)-(n.height>>1))),[e,t]}zoomToCanvas(){this.zoom=10;const e=this.refs["canvas-bounds"];this.applyZoom(),this.canvas&&e&&([this.panX,this.panY]=this.getCenteredPan()),this.applyZoom()}applyZoom(e){const t=this.refs["canvas-bounds"];if(this.canvas&&t){e=e||t.getBoundingClientRect();const i=this.getCanvasUnit(e);if(0===i){if(this.waitingToZoom)return;return this.waitingToZoom=!0,void requestAnimationFrame(()=>{this.waitingToZoom&&(this.waitingToZoom=!1,this.applyZoom())})}this.waitingToZoom=!1;const n=i*this.imageWidth,s=i*this.imageHeight,o=this.imageWidth>1&&this.imageHeight>1?2*i:i>>1;this.hasInteracted||([this.panX,this.panY]=this.getCenteredPan()),this.panX=Math.max(Math.min(this.panX,n-o),-(e.width-o)),this.panY=Math.max(Math.min(this.panY,s-o),-(e.height-o)),this.canvas.style.position="fixed",this.canvas.style.width=`${n}px`,this.canvas.style.height=`${s}px`,this.canvas.style.left=-this.panX+"px",this.canvas.style.top=-this.panY+"px",this.canvas.style.clipPath=`polygon(${this.panX}px ${this.panY}px, ${this.panX+e.width}px ${this.panY}px, ${this.panX+e.width}px ${this.panY+e.height}px, ${this.panX}px ${this.panY+e.height}px)`,this.background&&this.cloneCanvasStyle(this.canvas,this.background),this.canvasLayers.forEach(e=>this.cloneCanvasStyle(this.canvas,e)),this.redrawFloatingLayer(this.editState,!0)}}selectCanvasColor(e,t){const i=this.refs["canvas-bounds"].getBoundingClientRect();let n,{canvasX:s,canvasY:o}=this.clientToCanvas(e.clientX,e.clientY,i);s=Math.floor(s),o=Math.floor(o),this.editState.inFloatingLayer(s,o)&&(n=this.editState.floating.image.get(s-this.editState.layerOffsetX,o-this.editState.layerOffsetY)),n||(n=this.editState.image.get(s,o)),t?this.props.dispatchChangeBackgroundColor(n):this.props.dispatchChangeSelectedColor(n)}selectAll(){this.props.tool!==r.ImageEditorTool.Marquee&&this.props.dispatchChangeImageTool(r.ImageEditorTool.Marquee),this.editState.mergeFloatingLayer(),this.editState.copyToLayer(0,0,this.imageWidth,this.imageHeight,!0),this.props.dispatchImageEdit(this.editState.toImageState())}cancelSelection(){this.editState.mergeFloatingLayer(),this.props.dispatchImageEdit(this.editState.toImageState())}cloneCanvasStyle(e,t){t.style.position=e.style.position,t.style.width=e.style.width,t.style.height=e.style.height,t.style.left=e.style.left,t.style.top=e.style.top,t.style.clipPath=e.style.clipPath}clientToCanvas(e,t,i){const n=this.getCanvasUnit(i);return{canvasX:(e-i.left+this.panX)/n,canvasY:(t-i.top+this.panY)/n}}getCanvasUnit(e){const t=e.width/e.height,i=this.imageWidth/this.imageHeight,n=Math.pow(this.zoom/10,2);return t>i?n*(e.height/this.imageHeight):n*(e.width/this.imageWidth)}inBounds(e,t){return e>=0&&e<this.imageWidth&&t>=0&&t<this.imageHeight}isPanning(){return this.props.tool===r.ImageEditorTool.Pan}touchesResize(e,t){const i=document.querySelectorAll(":hover");for(let e=0;e<i.length;e++)if("image-editor-floating-layer-corner"==i[e].className)return!0;return!1}isColorSelect(){return this.props.tool===r.ImageEditorTool.ColorSelect}shouldHandleCanvasShortcut(){return!(this.props.suppressShortcuts||document.activeElement instanceof HTMLInputElement)}shouldDrawCursor(){if(!this.hasHover)return!1;switch(this.props.tool){case r.ImageEditorTool.Fill:case r.ImageEditorTool.Marquee:case r.ImageEditorTool.Pan:case r.ImageEditorTool.ColorSelect:return!1;default:return!0}}getImageState(){return this.props.isTilemap?this.props.tilemapState.tilemap:this.props.imageState}applyTilemapPatch(e){const{tilemapState:t,dispatchCreateNewTile:i,gallery:n,backgroundColor:s}=this.props,{tileset:o}=t,r=pxt.sprite.tilemapLiteralToTilemap(e.map);if(!r||!r.width||!r.height)return;const a=e.tiles.map(e=>pxt.sprite.getBitmapFromJResURL(`data:${p};base64,${e}`)),l=e.layers.map(e=>pxt.sprite.getBitmapFromJResURL(`data:${p};base64,${e}`)),c=[];let h=o.tiles.length;for(const e of a){const t=o.tiles.findIndex(t=>e.equals(pxt.sprite.Bitmap.fromData(t.bitmap)));if(t>=0)c.push(t);else{if(n){const t=n.find(t=>e.equals(pxt.sprite.Bitmap.fromData(t.bitmap)));if(t){i(null,o.tiles.length,s,t.qualifiedName),c.push(h),h++;continue}}i((0,u.createTile)(e.data()),o.tiles.length,s),c.push(h),h++}}this.editState.mergeFloatingLayer();const d=new pxt.sprite.Tilemap(r.width,r.height);for(let e=0;e<d.width;e++)for(let t=0;t<d.height;t++)d.set(e,t,c[r.get(e,t)]);this.editState.floating={image:d,overlayLayers:l},this.editState.layerOffsetX=0,this.editState.layerOffsetY=0,this.props.dispatchImageEdit(this.editState.toImageState())}focus(){this.refs["canvas-bounds"].focus()}}i.ImageCanvasImpl=f;const m={dispatchImageEdit:a.dispatchImageEdit,dispatchChangeCursorLocation:a.dispatchChangeCursorLocation,dispatchChangeZoom:a.dispatchChangeZoom,dispatchChangeImageTool:a.dispatchChangeImageTool,dispatchChangeSelectedColor:a.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:a.dispatchChangeBackgroundColor,dispatchCreateNewTile:a.dispatchCreateNewTile};i.ImageCanvas=(0,o.connect)(function({store:{present:e},editor:t},i){if(t.isTilemap){let i=e;return i?{selectedColor:t.selectedColor,tilemapState:i,tool:t.tool,toolWidth:t.cursorSize,zoomDelta:t.zoomDelta,onionSkinEnabled:!1,overlayEnabled:t.overlayEnabled,backgroundColor:t.backgroundColor,colors:i.colors,isTilemap:t.isTilemap,drawingMode:t.drawingMode,gallery:t.tileGallery,tilesetRevision:t.tilesetRevision}:{}}let n=e;return n?{selectedColor:t.selectedColor,colors:n.colors,imageState:n.frames[n.currentFrame],tool:t.tool,toolWidth:t.cursorSize,zoomDelta:t.zoomDelta,onionSkinEnabled:t.onionSkinEnabled,backgroundColor:t.backgroundColor,prevFrame:n.frames[n.currentFrame-1],isTilemap:t.isTilemap,tilesetRevision:t.tilesetRevision}:{}},m)(f)},{"../../assets":174,"./ImageEditor":180,"./actions/dispatch":187,"./keyboardShortcuts":189,"./store/imageReducer":191,"./toolDefinitions":195,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],180:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageEditor=i.LIGHT_MODE_TRANSPARENT=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/imageStore"),a=e("./SideBar"),l=e("./BottomBar"),c=e("./TopBar"),u=e("./ImageCanvas"),h=e("./Alert"),d=e("./Timeline"),p=e("./keyboardShortcuts"),g=e("./actions/dispatch"),f=e("./util"),m=e("../../assets"),_=e("../../../../react-common/components/util"),b=e("./tilemap/TilePalette");i.LIGHT_MODE_TRANSPARENT="#dedede";class T extends s.Component{constructor(e){super(e),this.onStoreChange=()=>{this.props.onChange&&this.props.onChange(this.props.singleFrame?pxt.sprite.bitmapToImageLiteral(this.getCurrentFrame(),"typescript"):"");const e=this.getStore(),t=e.getState();if((0,p.setStore)(e),t.editor&&this.setState({alert:t.editor.alert}),!!t.editor.editingTile!=!!this.state.editingTile)if(t.editor.editingTile){const e=t.editor.editingTile.tilesetIndex;if(e){const i=t.store.present.tileset.tiles[e];this.setState({editingTile:!0,tileToEdit:i})}else{const e=t.store.present.tileset.tileWidth,i=(0,m.createNewImageAsset)("tile",e,e,lf("myTile"));this.setState({editingTile:!0,tileToEdit:i})}this.props.onTileEditorOpenClose&&this.props.onTileEditorOpenClose(!0)}else this.setState({editingTile:!1}),this.props.onTileEditorOpenClose&&this.props.onTileEditorOpenClose(!1)},this.onDoneClick=()=>{this.props.onDoneClicked&&this.props.onDoneClicked(this.getAsset())},this.onTileEditorFinished=e=>{const t=this.getStore().getState().editor.editingTile;e.isProjectTile=!0,this.dispatchOnStore((0,g.dispatchCloseTileEditor)(e,t.tilesetIndex))},this.state={editingTile:!1}}componentDidMount(){(0,p.addKeyListener)(),this.props.asset&&this.openAsset(this.props.asset),this.unsubscribeChangeListener=this.getStore().subscribe(this.onStoreChange),this.onResize()}componentWillUnmount(){this.props.nested||(0,p.removeKeyListener)(),this.unsubscribeChangeListener&&this.unsubscribeChangeListener()}render(){const{singleFrame:e,lightMode:t,hideDoneButton:i,hideAssetName:s}=this.props,p=this.getStore(),{tileToEdit:g,editingTile:f,alert:m}=this.state,b="Animation"===p.getState().store.present.kind;return(0,n.jsxs)("div",Object.assign({className:"image-editor-outer"},{children:[(0,n.jsx)(o.Provider,Object.assign({store:p},{children:(0,n.jsxs)("div",Object.assign({className:(0,_.classList)("image-editor",f&&"editing-tile",i&&"hide-done-button")},{children:[(0,n.jsx)(c.TopBar,{singleFrame:e}),(0,n.jsxs)("div",Object.assign({className:"image-editor-content"},{children:[(0,n.jsx)(a.SideBar,{lightMode:t}),(0,n.jsx)(u.ImageCanvas,{suppressShortcuts:f,lightMode:t}),b&&!e?(0,n.jsx)(d.Timeline,{}):void 0]})),(0,n.jsx)(l.BottomBar,{singleFrame:e,onDoneClick:this.onDoneClick,hideDoneButton:!!i,hideAssetName:!!s}),m&&m.title&&(0,n.jsx)(h.Alert,{title:m.title,text:m.text,options:m.options})]}))})),f&&(0,n.jsx)(T,{store:r.tileEditorStore,ref:"nested-image-editor",onDoneClicked:this.onTileEditorFinished,asset:g,singleFrame:!0,nested:!0,hideAssetName:s})]}))}openAsset(e,t,i=!1){this.dispatchOnStore((0,g.dispatchOpenAsset)(e,i,t)),e.meta.displayName?this.dispatchOnStore((0,g.dispatchChangeAssetName)(e.meta.displayName)):i&&this.dispatchOnStore((0,g.dispatchChangeAssetName)(""))}openGalleryAsset(e){const t=this.getAsset(),i=this.getStore().getState().store.present.frames;switch(t.type){case"animation":switch(e.type){case"image":case"tile":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.bitmap),1===i.length);break;case"animation":this.dispatchOnStore((0,g.dispatchSetFrames)(e.frames.map(e=>({bitmap:e}))))}break;case"image":case"tile":switch(e.type){case"image":case"tile":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.bitmap),!0);break;case"animation":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.frames[0]),!0)}break;case"tilemap":if("tilemap"===e.type){const i=t,n=pxt.cloneAsset(e),s=pxt.react.getTilemapProject();pxt.sprite.updateTilemapReferencesFromResult(s,i),this.prepareGalleryTilemapTemplate(s,i,n),n.id=i.id,n.internalID=i.internalID,n.meta=Object.assign({},i.meta);const{tileGallery:o}=this.getStore().getState().editor;this.openAsset(n,o,!1)}}}prepareGalleryTilemapTemplate(e,t,i){this.mergeTilemapTilesIntoProject(e,i),this.mergeCurrentTilemapCustomTilesIntoTileset(e,t,i)}mergeCurrentTilemapCustomTilesIntoTileset(e,t,i){var n,s,o,r,a,l,c,u;const h=null===(s=null===(n=null==t?void 0:t.data)||void 0===n?void 0:n.tileset)||void 0===s?void 0:s.tiles,d=null===(r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.tileset)||void 0===r?void 0:r.tiles,p=null===(l=null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.tileset)||void 0===l?void 0:l.tileWidth;if(!(null==h?void 0:h.length)||!d||!p)return;const g=`myTiles.transparency${p}`;for(const t of h){if(!(null==t?void 0:t.isProjectTile))continue;if(t.id===g)continue;if((null===(c=t.bitmap)||void 0===c?void 0:c.width)!==p||(null===(u=t.bitmap)||void 0===u?void 0:u.height)!==p)continue;const i=e.resolveTile(t.id);i&&(d.some(e=>(null==e?void 0:e.id)===i.id)||d.push(i))}}mergeTilemapTilesIntoProject(e,t){var i,n,s,o;const r=null===(n=null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.tileset)||void 0===n?void 0:n.tiles;if(!(null==r?void 0:r.length))return;const a=e=>{var t;const i=(null===(t=null==e?void 0:e.meta)||void 0===t?void 0:t.displayName)||pxt.getShortIDForAsset(e)||(null==e?void 0:e.id);return i?i.split(".").pop():void 0},l={};for(let t=0;t<r.length;t++){let i=r[t];if(!i)continue;const n=i.jresData||(i.bitmap?pxt.sprite.base64EncodeBitmap(i.bitmap):"");if(n&&l[n]){r[t]=l[n];continue}const c=i.bitmap&&e.lookupAssetByValue("tile",i);if(c){if(r[t]=c,n&&(l[n]=c),!(null===(s=c.meta)||void 0===s?void 0:s.displayName)){const t=a(i);if(t){const i=e.generateNewName("tile",t);e.updateTile(Object.assign(Object.assign({},c),{meta:Object.assign(Object.assign({},c.meta),{displayName:i})}))}}continue}const u=e.lookupAsset("tile",i.id);if(u&&(i=u),i.bitmap){if(null===(o=i.meta.tags)||void 0===o?void 0:o.some(e=>e.startsWith("category-")||b.BUILTIN_CATEGORIES.some(t=>t.id===e)))continue;const s=a(i),c=s?e.generateNewName("tile",s):void 0,u=e.createNewTile(i.bitmap,void 0,c);r[t]=u,n&&(l[n]=u)}}}onResize(){this.dispatchOnStore((0,g.dispatchChangeZoom)(0))}getCurrentFrame(){const e=this.getStore().getState().store.present,t=e.frames[e.currentFrame];return(0,f.imageStateToBitmap)(t)}getAsset(){switch(this.getStore().getState().store.present.asset.type){case"tile":return this.getTile();case"animation":return this.getAnimation();case"tilemap":return this.getTilemap();default:return this.getImage()}}getImage(){var e;const t=this.getStore().getState().store.present,i=this.getCurrentFrame().data(),n=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),type:"image",bitmap:i,jresData:pxt.sprite.base64EncodeBitmap(i),meta:n}}getTile(){var e;const t=this.getStore().getState().store.present,i=this.getCurrentFrame().data(),n=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),isProjectTile:!0,type:"tile",bitmap:i,jresData:pxt.sprite.base64EncodeBitmap(i),meta:n}}getAnimation(){var e;const t=this.getStore().getState().store.present,i=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),type:"animation",interval:t.interval,frames:t.frames.map(e=>(0,f.imageStateToBitmap)(e).data()),meta:i}}getTilemap(){var e;const t=this.getStore().getState(),i=t.store.present,{floating:n,overlayLayers:s,layerOffsetX:o,layerOffsetY:r}=i.tilemap,a=(0,f.applyBitmapData)(pxt.sprite.Bitmap.fromData(s[0]).copy().data(),n&&n.overlayLayers&&n.overlayLayers[0],o,r),l=new pxt.sprite.TilemapData((0,f.imageStateToTilemap)(i.tilemap),i.tileset,a);l.deletedTiles=t.editor.deletedTiles,l.editedTiles=t.editor.editedTiles;const c=i.asset?Object.assign({},i.asset.meta):{};return{id:null===(e=i.asset)||void 0===e?void 0:e.id,internalID:i.asset?i.asset.internalID:(0,m.getNewInternalID)(),type:"tilemap",data:l,meta:c}}getPersistentData(){const e=this.getStore().getState();return{editor:e.editor,past:e.store.past}}restorePersistentData(e){e&&this.dispatchOnStore((0,g.dispatchSetInitialState)(e.editor,e.past))}setCurrentFrame(e,t){if(!t){const t=this.getStore().getState().store.present.frames[0];if(e.width!==t.bitmap.width||e.height!==t.bitmap.height){const i=[Math.max(e.width,t.bitmap.width),Math.max(e.height,t.bitmap.height)];t.bitmap.width===i[0]&&t.bitmap.height===i[1]||this.dispatchOnStore((0,g.dispatchChangeImageDimensions)(i)),e=(e=e.copy()).resize(i[0],i[1])}}this.dispatchOnStore((0,g.dispatchImageEdit)({bitmap:e.data()}))}openInTileEditor(e){this.refs["nested-image-editor"].setCurrentFrame(e,!1)}disableResize(){this.dispatchOnStore((0,g.dispatchDisableResize)())}closeNestedEditor(){var e;this.state.editingTile&&(null===(e=this.refs["nested-image-editor"])||void 0===e||e.onDoneClick())}getJres(){if(this.props.singleFrame){const e=this.getCurrentFrame().data();return pxt.sprite.base64EncodeBitmap(e)}return""}loadJres(e){if(e)try{this.setCurrentFrame(pxt.sprite.getBitmapFromJResURL(e),!0)}catch(e){}}getStore(){return this.props.store||r.mainStore}dispatchOnStore(e){this.getStore().dispatch(e)}}i.ImageEditor=T},{"../../../../react-common/components/util":171,"../../assets":174,"./Alert":176,"./BottomBar":177,"./ImageCanvas":179,"./SideBar":182,"./Timeline":183,"./TopBar":186,"./actions/dispatch":187,"./keyboardShortcuts":189,"./store/imageStore":192,"./tilemap/TilePalette":194,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],181:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Pivot=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./util");class r extends s.Component{constructor(e){super(e),this.handlers=[],this.state={open:!1}}componentWillUnmount(){this.handlers=null}render(){const{options:e,selected:t}=this.props,i=e[t];return(0,n.jsx)("div",Object.assign({className:"image-editor-pivot-outer"},{children:e.map((e,t)=>(0,n.jsx)("div",Object.assign({role:"tab",className:"image-editor-pivot-option "+(e===i?"selected":""),tabIndex:0,onClick:this.clickHandler(t),onKeyDown:o.fireClickOnlyOnEnter},{children:e.text}),e.id))}))}clickHandler(e){if(!this.handlers[e]){const{onChange:t,options:i}=this.props;this.handlers[e]=()=>{this.setState({open:!1}),t(i[e],e)}}return this.handlers[e]}}i.Pivot=r},{"./util":196,react:304,"react/jsx-runtime":305}],182:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SideBar=i.SideBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./toolDefinitions"),a=e("./actions/dispatch"),l=e("./sprite/Palette"),c=e("./tilemap/TilePalette"),u=e("./tilemap/Minimap"),h=e("../../../../react-common/components/controls/Button"),d=e("../../../../react-common/components/util");class p extends s.Component{constructor(){super(...arguments),this.handlers=[]}render(){const{selectedTool:e,isTilemap:t,lightMode:i}=this.props;return(0,n.jsxs)("div",Object.assign({className:"image-editor-sidebar "+(t?"tilemap":"")},{children:[t&&(0,n.jsx)("div",Object.assign({className:"image-editor-tilemap-minimap"},{children:(0,n.jsx)(u.Minimap,{lightMode:i})})),(0,n.jsx)("div",Object.assign({className:"image-editor-tool-buttons"},{children:r.tools.filter(e=>!e.hiddenTool).map(t=>(0,n.jsx)(h.Button,{className:(0,d.classList)("image-editor-button",e!==t.tool&&"toggle"),leftIcon:t.iconClass,title:t.title,onClick:this.clickHandler(t.tool)},t.tool))})),(0,n.jsx)("div",Object.assign({className:"image-editor-palette"},{children:t?(0,n.jsx)(c.TilePalette,{}):(0,n.jsx)(l.Palette,{})}))]}))}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>this.props.dispatchChangeImageTool(e)),this.handlers[e]}}i.SideBarImpl=p;const g={dispatchChangeImageTool:a.dispatchChangeImageTool};i.SideBar=(0,o.connect)(function({editor:e},t){return e?{isTilemap:e.isTilemap,selectedTool:e.tool}:{}},g)(p)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"./actions/dispatch":187,"./sprite/Palette":190,"./tilemap/Minimap":193,"./tilemap/TilePalette":194,"./toolDefinitions":195,react:304,"react-redux":287,"react/jsx-runtime":305}],183:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Timeline=i.TimelineImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("./TimelineFrame"),l=e("./util"),c=e("../../../../react-common/components/controls/Button");class u extends s.Component{constructor(e){super(e),this.handlers=[],this.scrollOffset=0,this.dragEnd=!1,this.duplicateFrame=()=>{const{currentFrame:e,dispatchDuplicateFrame:t}=this.props;t(e)},this.deleteFrame=()=>{const{currentFrame:e,dispatchDeleteFrame:t}=this.props;t(e)},this.newFrame=()=>{const{dispatchNewFrame:e}=this.props;this.dragEnd?this.dragEnd=!1:e()},this.state={}}render(){const{frames:e,colors:t,currentFrame:i,interval:s,previewAnimating:o}=this.props,{isMovingFrame:r,dropPreviewIndex:l}=this.state;let u,h=e.slice();return r&&(u=e[i],h.splice(i,1),h.splice(l,0,null)),(0,n.jsxs)("div",Object.assign({className:"image-editor-timeline "+(pxt.BrowserUtils.isEdge()?"edge":"")},{children:[(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-preview"},{children:(0,n.jsx)(a.TimelineFrame,{frames:o?e:[e[i]],colors:t,interval:s,animating:!0})})),(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-frames-outer"},{children:(0,n.jsxs)("div",Object.assign({className:"image-editor-timeline-frames",ref:"frame-scroller-ref"},{children:[h.map((e,s)=>{const o=!r&&s===i;return e?(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-frame "+(o?"active":""),role:"button",onClick:this.clickHandler(s)},{children:(0,n.jsx)(a.TimelineFrame,{frames:[e],colors:t,showActions:o,duplicateFrame:this.duplicateFrame,deleteFrame:this.deleteFrame})}),s):(0,n.jsx)("div",{className:"image-editor-timeline-frame drop-marker"},s)}),u&&(0,n.jsx)("div",Object.assign({ref:"floating-frame",className:"image-editor-timeline-frame dragging"},{children:(0,n.jsx)(a.TimelineFrame,{frames:[u],colors:t,duplicateFrame:this.duplicateFrame,deleteFrame:this.deleteFrame})})),(0,n.jsx)(c.Button,{className:"image-editor-button add-frame-button toggle",title:lf("Add new frame"),onClick:this.newFrame,leftIcon:"ms-Icon ms-Icon--Add"})]}))}))]}))}componentDidMount(){let e;this.frameScroller=this.refs["frame-scroller-ref"];let t=!1,i=0;(0,l.bindGestureEvents)(this.frameScroller,{onClick:e=>{this.dragEnd=!1},onDragStart:n=>{e=n.clientY,pxt.BrowserUtils.addClass(this.frameScroller,"scrolling");let s=-1;for(let e=0;e<this.frameScroller.childElementCount;e++){const t=this.frameScroller.children.item(e).getBoundingClientRect();if(n.clientY>=t.top&&n.clientY<=t.bottom){s=e,i=n.clientY-t.top;break}}t=s!==this.props.currentFrame},onDragMove:n=>{if(t){this.scrollOffset-=e-n.clientY,e=n.clientY;try{const e=this.frameScroller.getBoundingClientRect(),t=this.frameScroller.parentElement.getBoundingClientRect();e.height>t.height?this.scrollOffset=Math.max(Math.min(this.scrollOffset,0),t.height-e.height-15):this.scrollOffset=0,this.frameScroller.parentElement.scrollTop=-this.scrollOffset}catch(e){}}else this.updateDragDrop(n,i)},onDragEnd:()=>{if(e=null,pxt.BrowserUtils.removeClass(this.frameScroller,"scrolling"),this.dragEnd=!0,this.state.isMovingFrame){const{dispatchMoveFrame:e,currentFrame:t}=this.props;e(t,this.state.dropPreviewIndex),this.setState({isMovingFrame:!1})}}}),this.frameScroller.addEventListener("wheel",e=>{this.scrollOffset-=e.deltaY;try{const e=this.frameScroller.getBoundingClientRect(),t=this.frameScroller.parentElement.getBoundingClientRect();e.height>t.height?this.scrollOffset=Math.max(Math.min(this.scrollOffset,0),t.height-e.height-15):this.scrollOffset=0,this.frameScroller.parentElement.scrollTop=-this.scrollOffset}catch(e){}})}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>{const{currentFrame:t,dispatchChangeCurrentFrame:i}=this.props;this.dragEnd?this.dragEnd=!1:e!=t&&i(e)}),this.handlers[e]}updateDragDrop(e,t){this.animHandler?(cancelAnimationFrame(this.animHandler),this.animHandler=void 0):this.lastTimestamp=void 0;const i=this.frameScroller.getBoundingClientRect(),n=e.clientY-i.top-t,s=this.frameScroller.lastElementChild.getBoundingClientRect().height,o=(i.height-s)/this.props.frames.length,r=Math.floor(n/o),a=100,l=this.frameScroller.parentElement.getBoundingClientRect(),c=i.height-l.height;if(c>0&&(Math.abs(l.top-e.clientY)<80?this.animHandler=requestAnimationFrame(i=>{if(!this.state.isMovingFrame||this.frameScroller.parentElement.scrollTop<=0)return;const n=i-(this.lastTimestamp||i);this.lastTimestamp=i;const s=1-Math.abs(l.top-e.clientY)/80,o=(a+400*s)*(n/1e3);this.frameScroller.parentElement.scrollTop=Math.max(0,this.frameScroller.parentElement.scrollTop-o),this.updateDragDrop(e,t)}):Math.abs(l.bottom-e.clientY)<80&&(this.animHandler=requestAnimationFrame(i=>{if(!this.state.isMovingFrame||this.frameScroller.parentElement.scrollTop>=c)return;const n=i-(this.lastTimestamp||i);this.lastTimestamp=i;const s=1-Math.abs(l.bottom-e.clientY)/80,o=(a+400*s)*(n/1e3);this.frameScroller.parentElement.scrollTop=Math.min(c,this.frameScroller.parentElement.scrollTop+o),this.updateDragDrop(e,t)}))),this.state.isMovingFrame){if(this.refs["floating-frame"]){this.refs["floating-frame"].style.top=n+"px",this.state.dropPreviewIndex!==r&&this.setState({dropPreviewIndex:r})}}else this.setState({isMovingFrame:!0,dropPreviewIndex:this.props.currentFrame})}}i.TimelineImpl=u;const h={dispatchDuplicateFrame:r.dispatchDuplicateFrame,dispatchDeleteFrame:r.dispatchDeleteFrame,dispatchChangeCurrentFrame:r.dispatchChangeCurrentFrame,dispatchNewFrame:r.dispatchNewFrame,dispatchMoveFrame:r.dispatchMoveFrame};i.Timeline=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{frames:n.frames,currentFrame:n.currentFrame,colors:n.colors,interval:n.interval,previewAnimating:t.previewAnimating}:{}},h)(u)},{"../../../../react-common/components/controls/Button":159,"./TimelineFrame":184,"./actions/dispatch":187,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],184:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TimelineFrame=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=pxt.BrowserUtils.isEdge()?25:1;class a extends s.Component{constructor(e){super(e),this.state={index:0}}render(){const{frames:e,animating:t,showActions:i,duplicateFrame:s,deleteFrame:r}=this.props,a=e[t?Math.min(Math.max(0,this.state.index),e.length-1):0],l=a.bitmap.height>a.bitmap.width;return(0,n.jsxs)("div",Object.assign({className:"timeline-frame-outer "+(l?"portrait":"landscape")},{children:[(0,n.jsx)("div",{className:"timeline-frame-spacer"}),(0,n.jsx)("canvas",{ref:"preview-canvas"}),(0,n.jsx)("div",{className:"timeline-frame-spacer"}),i&&(0,n.jsxs)("div",Object.assign({className:"timeline-frame-actions"},{children:[(0,n.jsx)(o.Button,{className:"image-editor-button",leftIcon:"ms-Icon ms-Icon--Copy",title:lf("Duplicate Current Frame"),onClick:s}),(0,n.jsx)(o.Button,{className:"image-editor-button",leftIcon:"ms-Icon ms-Icon--Delete",title:lf("Delete Current Frame"),onClick:r})]}))]}))}componentDidMount(){this.canvas=this.refs["preview-canvas"],this.redraw(),this.updateAnimation()}componentDidUpdate(){this.redraw(),this.updateAnimation()}componentWillUnmount(){this.intervalId&&clearInterval(this.intervalId),this.intervalId=void 0}redraw(){if(!this.canvas)return;const{animating:e,frames:t}=this.props,i=t[e?Math.min(Math.max(0,this.state.index),t.length-1):0];this.canvas.height=i.bitmap.height*r,this.canvas.width=i.bitmap.width*r;const n=pxt.sprite.Bitmap.fromData(i.bitmap);if(this.drawBitmap(n),i.floating&&i.floating.bitmap){const e=pxt.sprite.Bitmap.fromData(i.floating.bitmap);this.drawBitmap(e,i.layerOffsetX,i.layerOffsetY,!0)}}updateAnimation(){const{animating:e,interval:t,frames:i}=this.props,n=e&&t>5&&i.length>1;n&&t!==this.intervalcurrent?(this.intervalId&&clearInterval(this.intervalId),this.intervalId=setInterval(()=>this.setState({index:(this.state.index+1)%this.props.frames.length}),t),this.intervalcurrent=t):!n&&this.intervalId&&(clearInterval(this.intervalId),this.intervalId=void 0,this.intervalcurrent=void 0)}drawBitmap(e,t=0,i=0,n=!1){const{colors:s}=this.props,o=this.canvas.getContext("2d");for(let a=0;a<e.width;a++)for(let l=0;l<e.height;l++){const c=e.get(a,l);c?(o.fillStyle=s[c],o.fillRect((a+t)*r,(l+i)*r,r,r)):n||o.clearRect((a+t)*r,(l+i)*r,r,r)}}}i.TimelineFrame=a},{"../../../../react-common/components/controls/Button":159,react:304,"react/jsx-runtime":305}],185:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Toggle=void 0;const n=e("react/jsx-runtime"),s=e("react");class o extends s.Component{constructor(e){super(e),this.checked=!1,this.handleToggleClick=e=>{this.checked=!this.checked,this.props.onChange&&this.props.onChange(e.target.checked)},this.checked=e.initialValue}render(){const{initialValue:e,label:t}=this.props;return(0,n.jsxs)("div",Object.assign({className:"image-editor-toggle-container"},{children:[t&&(0,n.jsx)("span",{children:t}),(0,n.jsxs)("label",Object.assign({className:"image-editor-toggle"},{children:[(0,n.jsx)("input",{type:"checkbox",onClick:this.handleToggleClick,defaultChecked:e,"aria-checked":this.checked}),(0,n.jsx)("span",{className:"image-editor-toggle-switch"})]}))]}))}}i.Toggle=o},{react:304,"react/jsx-runtime":305}],186:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TopBar=i.TopBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("./CursorSizes"),l=e("./Toggle"),c=e("./keyboardShortcuts"),u=e("../../../../react-common/components/controls/Button");class h extends s.Component{constructor(e){super(e),this.togglePreviewAnimating=()=>this.props.dispatchChangePreviewAnimating(!this.props.previewAnimating),this.flipVertical=()=>(0,c.flip)(!0),this.flipHorizontal=()=>(0,c.flip)(!1),this.rotateClockwise=()=>(0,c.rotate)(!0),this.rotateCounterclockwise=()=>(0,c.rotate)(!1),this.handleIntervalChange=e=>{this.setState({interval:e.target.value})},this.handleIntervalBlur=()=>{const{dispatchChangeInterval:e}=this.props,t=parseInt(this.state.interval);isNaN(t)||e(Math.min(Math.max(t,50),1e6)),this.setState({interval:null})},this.state={}}render(){const{interval:e,previewAnimating:t,singleFrame:i,isTilemap:s,dispatchChangeOverlayEnabled:o}=this.props,r=null==this.state.interval?e:this.state.interval;return(0,n.jsxs)("div",Object.assign({className:"image-editor-topbar"},{children:[(0,n.jsx)("div",Object.assign({className:"cursor-group"},{children:(0,n.jsx)(a.CursorSizes,{})})),(0,n.jsx)("div",{className:"image-editor-seperator"}),(0,n.jsxs)("div",Object.assign({className:"image-transform-group"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon flipvertical",title:lf("Flip vertical"),onClick:this.flipVertical}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon fliphorizontal",title:lf("Flip horizontal"),onClick:this.flipHorizontal}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon rotateright",title:lf("Rotate clockwise"),onClick:this.rotateClockwise}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon rotateleft",title:lf("Rotate counterclockwise"),onClick:this.rotateCounterclockwise})]})),(0,n.jsx)("div",{className:"spacer"}),!i&&(0,n.jsx)("div",{className:"image-editor-seperator"}),!i&&(0,n.jsxs)("div",Object.assign({className:"timeline-controls"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button TOGGLE",onClick:this.togglePreviewAnimating,leftIcon:t?"ms-Icon ms-Icon--Stop":"ms-Icon ms-Icon--Play",title:t?lf("Stop Animation Preview"):lf("Play Animation Preview")}),(0,n.jsx)("div",Object.assign({className:"image-editor-interval-label image-editor-label"},{children:(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Clock"})})),(0,n.jsx)("div",Object.assign({className:"image-editor-interval"},{children:(0,n.jsx)("input",{className:"image-editor-input",title:lf("Interval Between Frames (ms)"),value:r,onChange:this.handleIntervalChange,onBlur:this.handleIntervalBlur})}))]})),s&&(0,n.jsx)(l.Toggle,{initialValue:!0,label:lf("Show walls"),onChange:o})]}))}}i.TopBarImpl=h;const d={dispatchChangeInterval:r.dispatchChangeInterval,dispatchChangePreviewAnimating:r.dispatchChangePreviewAnimating,dispatchChangeOverlayEnabled:r.dispatchChangeOverlayEnabled};i.TopBar=(0,o.connect)(function({store:{present:e},editor:t},i){return e?{interval:e.interval,previewAnimating:t.previewAnimating,isTilemap:t.isTilemap}:{}},d)(h)},{"../../../../react-common/components/controls/Button":159,"./CursorSizes":178,"./Toggle":185,"./actions/dispatch":187,"./keyboardShortcuts":189,react:304,"react-redux":287,"react/jsx-runtime":305}],187:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.dispatchSetFrames=i.dispatchOpenAsset=i.dispatchChangeAssetName=i.dispatchDisableResize=i.dispatchDeleteTile=i.dispatchCloseTileEditor=i.dispatchOpenTileEditor=i.dispatchSetGalleryOpen=i.dispatchCreateNewTile=i.dispatchChangeDrawingMode=i.dispatchChangeTilePalettePage=i.dispatchChangeTilePaletteCategory=i.dispatchSetInitialState=i.dispatchChangeBackgroundColor=i.dispatchSwapBackgroundForeground=i.dispatchHideAlert=i.dispatchShowAlert=i.dispatchChangeZoom=i.dispatchChangeOverlayEnabled=i.dispatchToggleOnionSkinEnabled=i.dispatchChangePreviewAnimating=i.dispatchChangeInterval=i.dispatchMoveFrame=i.dispatchChangeCurrentFrame=i.dispatchDuplicateFrame=i.dispatchDeleteFrame=i.dispatchNewFrame=i.dispatchToggleAspectRatioLocked=i.dispatchRedoImageEdit=i.dispatchUndoImageEdit=i.dispatchImageEdit=i.dispatchChangeCursorLocation=i.dispatchChangeKeyModifiers=i.dispatchChangeImageDimensions=i.dispatchChangeSelectedColor=i.dispatchChangeCursorSize=i.dispatchChangeImageTool=void 0;const n=e("./types");i.dispatchChangeImageTool=e=>({type:n.CHANGE_IMAGE_TOOL,tool:e});i.dispatchChangeCursorSize=e=>({type:n.CHANGE_CURSOR_SIZE,cursorSize:e});i.dispatchChangeSelectedColor=e=>({type:n.CHANGE_SELECTED_COLOR,selectedColor:e});i.dispatchChangeImageDimensions=e=>({type:n.CHANGE_IMAGE_DIMENSIONS,imageDimensions:e});i.dispatchChangeKeyModifiers=e=>({type:n.CHANGE_KEY_MODIFIERS,keyModifiers:e});i.dispatchChangeCursorLocation=e=>({type:n.CHANGE_CURSOR_LOCATION,cursorLocation:e});i.dispatchImageEdit=e=>({type:n.IMAGE_EDIT,newState:e});i.dispatchUndoImageEdit=()=>({type:n.UNDO_IMAGE_EDIT});i.dispatchRedoImageEdit=()=>({type:n.REDO_IMAGE_EDIT});i.dispatchToggleAspectRatioLocked=()=>({type:n.TOGGLE_ASPECT_RATIO});i.dispatchNewFrame=e=>({type:n.NEW_FRAME,index:e});i.dispatchDeleteFrame=e=>({type:n.DELETE_FRAME,index:e});i.dispatchDuplicateFrame=e=>({type:n.DUPLICATE_FRAME,index:e});i.dispatchChangeCurrentFrame=e=>({type:n.CHANGE_CURRENT_FRAME,index:e});i.dispatchMoveFrame=(e,t)=>({type:n.MOVE_FRAME,oldIndex:e,newIndex:t});i.dispatchChangeInterval=e=>({type:n.CHANGE_INTERVAL,newInterval:e});i.dispatchChangePreviewAnimating=e=>({type:n.CHANGE_PREVIEW_ANIMATING,animating:e});i.dispatchToggleOnionSkinEnabled=()=>({type:n.TOGGLE_ONION_SKIN_ENABLED});i.dispatchChangeOverlayEnabled=e=>({type:n.CHANGE_OVERLAY_ENABLED,enabled:e});i.dispatchChangeZoom=e=>({type:n.CHANGE_CANVAS_ZOOM,zoom:e});i.dispatchShowAlert=(e,t,i)=>({type:n.SHOW_ALERT,title:e,text:t,options:i});i.dispatchHideAlert=()=>({type:n.HIDE_ALERT});i.dispatchSwapBackgroundForeground=()=>({type:n.SWAP_FOREGROUND_BACKGROUND});i.dispatchChangeBackgroundColor=e=>({type:n.CHANGE_BACKGROUND_COLOR,backgroundColor:e});i.dispatchSetInitialState=(e,t)=>({type:n.SET_INITIAL_STATE,state:e,past:t});i.dispatchChangeTilePaletteCategory=e=>({type:n.CHANGE_TILE_PALETTE_CATEGORY,category:e});i.dispatchChangeTilePalettePage=e=>({type:n.CHANGE_TILE_PALETTE_PAGE,page:e});i.dispatchChangeDrawingMode=e=>({type:n.CHANGE_DRAWING_MODE,drawingMode:e});i.dispatchCreateNewTile=(e,t,i,s)=>({type:n.CREATE_NEW_TILE,tile:e,foreground:t,background:i,qualifiedName:s});i.dispatchSetGalleryOpen=e=>({type:n.SET_GALLERY_OPEN,open:e});i.dispatchOpenTileEditor=(e,t)=>({type:n.OPEN_TILE_EDITOR,index:e,id:t});i.dispatchCloseTileEditor=(e,t)=>({type:n.CLOSE_TILE_EDITOR,result:e,index:t});i.dispatchDeleteTile=(e,t)=>({type:n.DELETE_TILE,id:t,index:e});i.dispatchDisableResize=()=>({type:n.DISABLE_RESIZE});i.dispatchChangeAssetName=e=>({type:n.CHANGE_ASSET_NAME,name:e});i.dispatchOpenAsset=(e,t,i)=>({type:n.OPEN_ASSET,asset:e,keepPast:t,gallery:i});i.dispatchSetFrames=(e,t)=>({type:n.SET_FRAMES,frames:e,currentFrame:t})},{"./types":188}],188:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.OPEN_ASSET=i.CHANGE_ASSET_NAME=i.DISABLE_RESIZE=i.DELETE_TILE=i.CLOSE_TILE_EDITOR=i.OPEN_TILE_EDITOR=i.CREATE_NEW_TILE=i.CHANGE_DRAWING_MODE=i.CHANGE_TILE_PALETTE_CATEGORY=i.CHANGE_TILE_PALETTE_PAGE=i.CHANGE_BACKGROUND_COLOR=i.SWAP_FOREGROUND_BACKGROUND=i.HIDE_ALERT=i.SHOW_ALERT=i.CHANGE_CANVAS_ZOOM=i.CHANGE_OVERLAY_ENABLED=i.TOGGLE_ONION_SKIN_ENABLED=i.CHANGE_PREVIEW_ANIMATING=i.CHANGE_INTERVAL=i.CHANGE_CURRENT_FRAME=i.MOVE_FRAME=i.DUPLICATE_FRAME=i.DELETE_FRAME=i.NEW_FRAME=i.SET_GALLERY_OPEN=i.TOGGLE_ASPECT_RATIO=i.REDO_IMAGE_EDIT=i.UNDO_IMAGE_EDIT=i.IMAGE_EDIT=i.CHANGE_CURSOR_LOCATION=i.CHANGE_KEY_MODIFIERS=i.CHANGE_IMAGE_DIMENSIONS=i.CHANGE_SELECTED_COLOR=i.CHANGE_CURSOR_SIZE=i.CHANGE_IMAGE_TOOL=i.SET_FRAMES=i.SET_INITIAL_STATE=void 0,i.SET_INITIAL_STATE="SET_INITIAL_STATE",i.SET_FRAMES="SET_FRAMES",i.CHANGE_IMAGE_TOOL="CHANGE_IMAGE_TOOL",i.CHANGE_CURSOR_SIZE="CHANGE_CURSOR_SIZE",i.CHANGE_SELECTED_COLOR="CHANGE_SELECTED_COLOR",i.CHANGE_IMAGE_DIMENSIONS="CHANGE_IMAGE_DIMENSIONS",i.CHANGE_KEY_MODIFIERS="CHANGE_KEY_MODIFIERS",i.CHANGE_CURSOR_LOCATION="CHANGE_CURSOR_LOCATION",i.IMAGE_EDIT="IMAGE_EDIT",i.UNDO_IMAGE_EDIT="UNDO_IMAGE_EDIT",i.REDO_IMAGE_EDIT="REDO_IMAGE_EDIT",i.TOGGLE_ASPECT_RATIO="TOGGLE_ASPECT_RATIO",i.SET_GALLERY_OPEN="SET_GALLERY_OPEN",i.NEW_FRAME="NEW_FRAME",i.DELETE_FRAME="DELETE_FRAME",i.DUPLICATE_FRAME="DUPLICATE_FRAME",i.MOVE_FRAME="MOVE_FRAME",i.CHANGE_CURRENT_FRAME="CHANGE_CURRENT_FRAME",i.CHANGE_INTERVAL="CHANGE_INTERVAL",i.CHANGE_PREVIEW_ANIMATING="CHANGE_PREVIEW_ANIMATING",i.TOGGLE_ONION_SKIN_ENABLED="TOGGLE_ONION_SKIN_ENABLED",i.CHANGE_OVERLAY_ENABLED="CHANGE_OVERLAY_ENABLED",i.CHANGE_CANVAS_ZOOM="CHANGE_CANVAS_ZOOM",i.SHOW_ALERT="SHOW_ALERT",i.HIDE_ALERT="HIDE_ALERT",i.SWAP_FOREGROUND_BACKGROUND="SWAP_FOREGROUND_BACKGROUND",i.CHANGE_BACKGROUND_COLOR="CHANGE_BACKGROUND_COLOR",i.CHANGE_TILE_PALETTE_PAGE="CHANGE_TILE_PALETTE_PAGE",i.CHANGE_TILE_PALETTE_CATEGORY="CHANGE_TILE_PALETTE_CATEGORY",i.CHANGE_DRAWING_MODE="CHANGE_DRAWING_MODE",i.CREATE_NEW_TILE="CREATE_NEW_TILE",i.OPEN_TILE_EDITOR="OPEN_TILE_EDITOR",i.CLOSE_TILE_EDITOR="CLOSE_TILE_EDITOR",i.DELETE_TILE="DELETE_TILE",i.DISABLE_RESIZE="DISABLE_RESIZE",i.CHANGE_ASSET_NAME="CHANGE_ASSET_NAME",i.OPEN_ASSET="OPEN_ASSET"},{}],189:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.moveFrame=i.advanceFrame=i.replaceColor=i.outline=i.rotateAllFrames=i.rotate=i.flipAllFrames=i.flip=i.setStore=i.areShortcutsEnabled=i.releaseShortcutLock=i.obtainShortcutLock=i.removeKeyListener=i.addKeyListener=void 0;const n=e("./store/imageReducer"),s=e("./actions/dispatch"),o=e("./store/imageStore"),r=e("./toolDefinitions");let a=o.mainStore,l=[];function c(){return!l.length}function u(e){const t=e.ctrlKey||e.metaKey;"Undo"===e.key||t&&"z"===e.key&&!e.shiftKey?(m((0,s.dispatchUndoImageEdit)()),e.preventDefault(),e.stopPropagation()):("Redo"===e.key||t&&"y"===e.key||t&&"Z"===e.key&&e.shiftKey)&&(m((0,s.dispatchRedoImageEdit)()),e.preventDefault(),e.stopPropagation())}function h(e){"Backspace"!==e.key&&"Delete"!==e.key||(d(e),e.stopPropagation())}function d(e){if(!c())return;if(e.shiftKey&&/^(?:Digit[1-9])|(?:Key[A-F])$/.test(e.code))return void(0==e.code.indexOf("Digit")?y(parseInt(e.code.substring(5))):y(parseInt(e.code.substring(3),16)));switch(e.key){case"e":g(n.ImageEditorTool.Erase);break;case"q":g(n.ImageEditorTool.Pan);break;case"b":case"p":g(n.ImageEditorTool.Paint);break;case"g":g(n.ImageEditorTool.Fill);break;case"m":g(n.ImageEditorTool.Marquee);break;case"u":g(n.ImageEditorTool.Rect);break;case"l":g(n.ImageEditorTool.Line);break;case"c":g(n.ImageEditorTool.Circle);break;case"-":case"_":f(-1);break;case"=":case"+":f(1);break;case"x":m((0,s.dispatchSwapBackgroundForeground)());break;case"h":b(!1);break;case"v":b(!0);break;case"H":T(!1);break;case"V":T(!0);break;case"[":E(!1);break;case"]":E(!0);break;case"{":v(!1);break;case"}":v(!0);break;case">":_(!0);break;case"<":_(!1);break;case".":C(!0);break;case",":C(!1);break;case"PageDown":I(!0,e.shiftKey);break;case"PageUp":I(!1,e.shiftKey);break;case"r":k();break;case"R":!function(){const e=a.getState(),t=e.editor.backgroundColor,i=e.editor.selectedColor;if(t===i)return;S(k,e=>(0,r.replaceColorEdit)(e,t,i))}();break;case"ArrowLeft":A(-1,0,e.shiftKey);break;case"ArrowRight":A(1,0,e.shiftKey);break;case"ArrowUp":A(0,-1,e.shiftKey);break;case"ArrowDown":A(0,1,e.shiftKey);break;case"Backspace":case"Delete":O(e.shiftKey)}if(!a.getState().editor.isTilemap&&/^Digit\d$/.test(e.code)){const i=+e.code.slice(-1)+(e.shiftKey?9:0);i>=0&&i<16&&(t=i,m((0,s.dispatchChangeSelectedColor)(t)))}var t}function p(){const e=a.getState();if(e.editor.isTilemap){const t=e.store.present;return[(0,r.getEditState)(t.tilemap,!0,e.editor.drawingMode),"tilemap"]}{const t=e.store.present;return[(0,r.getEditState)(t.frames[t.currentFrame],!1,e.editor.drawingMode),t.frames.length>1?"animation":"image"]}}function g(e){m((0,s.dispatchChangeImageTool)(e))}function f(e){m((0,s.dispatchChangeZoom)(e))}function m(e){a.dispatch(e)}function _(e){let t;const i=a.getState().editor.cursorSize;switch(i){case 1:t=e?3:1;break;case 3:t=e?5:1;break;case 5:t=e?5:3}i!==t&&m((0,s.dispatchChangeCursorSize)(t))}function b(e){const[t,i]=p(),n=(0,r.flipEdit)(t,e,"tilemap"===i);m((0,s.dispatchImageEdit)(n.toImageState()))}function T(e){S(()=>b(e),t=>(0,r.flipEdit)(t,e,!1))}function E(e){const[t,i]=p(),n=(0,r.rotateEdit)(t,e,"tilemap"===i,"animation"===i);m((0,s.dispatchImageEdit)(n.toImageState()))}function v(e){S(()=>E(e),t=>(0,r.rotateEdit)(t,e,!1,!0))}function y(e){const[t,i]=p();if("tilemap"===i)return;const n=(0,r.outlineEdit)(t,e);m((0,s.dispatchImageEdit)(n.toImageState()))}function k(){const e=a.getState(),t=e.editor.backgroundColor,i=e.editor.selectedColor;if(t===i)return;const[n]=p(),o=(0,r.replaceColorEdit)(n,t,i);m((0,s.dispatchImageEdit)(o.toImageState()))}function C(e){const t=a.getState();if(t.editor.isTilemap)return;const i=t.store.present;if(i.frames.length<=1)return;let n;n=e?(i.currentFrame+1)%i.frames.length:(i.currentFrame+i.frames.length-1)%i.frames.length,m((0,s.dispatchChangeCurrentFrame)(n))}function I(e,t=!1){const i=a.getState();if(i.editor.isTilemap)return;const n=i.store.present;if(n.frames.length<=1)return;let o;o=e?(n.currentFrame+1)%n.frames.length:(n.currentFrame+n.frames.length-1)%n.frames.length;const r=n.frames.slice();if(t)e?r.unshift(r.pop()):r.push(r.shift());else{const e=r[n.currentFrame];r.splice(n.currentFrame,1),r.splice(o,0,e)}m((0,s.dispatchSetFrames)(r,o))}function S(e,t){var i,n,o;const l=a.getState();if(l.editor.isTilemap)return void e();const c=l.store.present;if(1===c.frames.length)return void e();const u=c.frames[c.currentFrame],h=!!u.floating,d=null===(i=u.floating)||void 0===i?void 0:i.bitmap.width,p=null===(n=u.floating)||void 0===n?void 0:n.bitmap.height,g=u.layerOffsetX,f=u.layerOffsetY,_=[];for(const e of c.frames){const i=(0,r.getEditState)(e,!1);h?(null===(o=i.floating)||void 0===o?void 0:o.image)?i.layerOffsetX===g&&i.layerOffsetY===f&&i.floating.image.width===d&&i.floating.image.height===p||(i.mergeFloatingLayer(),i.copyToLayer(g,f,d,p,!0)):i.copyToLayer(g,f,d,p,!0):i.mergeFloatingLayer();const n=t(i);_.push(n.toImageState())}m((0,s.dispatchSetFrames)(_,c.currentFrame))}function A(e,t,i=!1){var n;const[o]=p();if(!(null===(n=o.floating)||void 0===n?void 0:n.image))return;const r=i=>(i.layerOffsetX+=e,i.layerOffsetY+=t,i);i?S(()=>A(e,t),r):m((0,s.dispatchImageEdit)(r(o).toImageState()))}function O(e=!1){var t;const[i]=p();if(!(null===(t=i.floating)||void 0===t?void 0:t.image))return;const n=e=>(e.floating=null,e);e?S(()=>O(),n):m((0,s.dispatchImageEdit)(n(i).toImageState()))}i.addKeyListener=function(){l=[],document.addEventListener("keydown",d),document.addEventListener("keydown",u,!0),document.addEventListener("keydown",h,!0)},i.removeKeyListener=function(){document.removeEventListener("keydown",d),document.removeEventListener("keydown",u,!0),document.removeEventListener("keydown",h,!0)},i.obtainShortcutLock=function(){let e=0;for(;!e;)e=Math.random()*Number.MAX_SAFE_INTEGER;return l.push(e),e},i.releaseShortcutLock=function(e){const t=l.indexOf(e);-1!==t&&l.splice(t,1)},i.areShortcutsEnabled=c,i.setStore=function(e){a=e||o.mainStore},i.flip=b,i.flipAllFrames=T,i.rotate=E,i.rotateAllFrames=v,i.outline=y,i.replaceColor=function(e,t){const[i,n]=p(),o=(0,r.replaceColorEdit)(i,e,t);m((0,s.dispatchImageEdit)(o.toImageState()))},i.advanceFrame=C,i.moveFrame=I},{"./actions/dispatch":187,"./store/imageReducer":191,"./store/imageStore":192,"./toolDefinitions":195}],190:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Palette=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../actions/dispatch"),a=e("../../../../../react-common/components/controls/Button"),l=e("../../../../../react-common/components/util");class c extends s.Component{constructor(){super(...arguments),this.preventContextMenu=e=>e.preventDefault()}render(){const{colors:e,selected:t,backgroundColor:i,dispatchSwapBackgroundForeground:s}=this.props,o=10;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",className:"image-editor-colors",viewBox:"0 0 23 15",onClick:s},{children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("pattern",Object.assign({id:"alpha-background",width:"6",height:"6",patternUnits:"userSpaceOnUse"},{children:[(0,n.jsx)("rect",{x:"0",y:"0",width:"6px",height:"6px",fill:"#aeaeae"}),(0,n.jsx)("rect",{x:"0",y:"0",width:"3px",height:"3px",fill:"#dedede"}),(0,n.jsx)("rect",{x:"3",y:"3",width:"3px",height:"3px",fill:"#dedede"})]}))}),(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",Object.assign({fill:i?e[i]:"url(#alpha-background)",x:6,y:4,width:15,height:o,stroke:"#3c3c3c",strokeWidth:"0.5"},{children:(0,n.jsx)("title",{children:u(i,e[i])})})),(0,n.jsx)("rect",Object.assign({fill:t?e[t]:"url(#alpha-background)",x:2,y:1,width:15,height:o,stroke:"#3c3c3c",strokeWidth:"0.5"},{children:(0,n.jsx)("title",{children:u(t,e[t])})}))]})]})),(0,n.jsx)("div",Object.assign({className:"image-editor-color-buttons",onContextMenu:this.preventContextMenu},{children:this.props.colors.map((e,t)=>(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",0===t&&"checkerboard"),title:u(t,e),style:0===t?null:{"--preview-color":e},onClick:()=>this.props.dispatchChangeSelectedColor(t),onRightClick:()=>this.props.dispatchChangeBackgroundColor(t)},t))}))]})}}function u(e,t){const i=0===e?lf("transparency"):function(e){switch(null==e?void 0:e.toLowerCase()){case"#ffffff":return lf("white");case"#ff2121":return lf("red");case"#ff93c4":return lf("pink");case"#ff8135":return lf("orange");case"#fff609":return lf("yellow");case"#249ca3":return lf("teal");case"#78dc52":return lf("green");case"#003fad":return lf("blue");case"#87f2ff":return lf("light blue");case"#8e2ec4":return lf("purple");case"#a4839f":return lf("light purple");case"#5c406c":return lf("dark purple");case"#e5cdc4":return lf("tan");case"#91463d":return lf("brown");case"#000000":return lf("black");default:return}}(t);return i?lf("Color {0} ({1})",e,i):lf("Color {0}",e)}const h={dispatchChangeSelectedColor:r.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:r.dispatchChangeBackgroundColor,dispatchSwapBackgroundForeground:r.dispatchSwapBackgroundForeground};i.Palette=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{selected:t.selectedColor,backgroundColor:t.backgroundColor,colors:n.colors}:{}},h)(c)},{"../../../../../react-common/components/controls/Button":159,"../../../../../react-common/components/util":171,"../actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],191:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.setTelemetryFunction=i.TileDrawingMode=i.TileCategory=i.KeyModifiers=i.CursorSize=i.ImageEditorTool=void 0;const n=e("../../../assets"),s=e("../actions/types");var o,r,a;!function(e){e[e.Paint=0]="Paint",e[e.Fill=1]="Fill",e[e.Line=2]="Line",e[e.Erase=3]="Erase",e[e.Circle=4]="Circle",e[e.Rect=5]="Rect",e[e.ColorSelect=6]="ColorSelect",e[e.Marquee=7]="Marquee",e[e.Pan=8]="Pan"}(o=i.ImageEditorTool||(i.ImageEditorTool={})),function(e){e[e.One=1]="One",e[e.Three=3]="Three",e[e.Five=5]="Five"}(i.CursorSize||(i.CursorSize={})),function(e){e[e.Alt=1]="Alt",e[e.Shift=2]="Shift"}(i.KeyModifiers||(i.KeyModifiers={})),function(e){e[e.Forest=0]="Forest",e[e.Aquatic=1]="Aquatic",e[e.Dungeon=2]="Dungeon",e[e.Misc=3]="Misc"}(r=i.TileCategory||(i.TileCategory={})),function(e){e.Default="default",e.Wall="wall"}(a=i.TileDrawingMode||(i.TileDrawingMode={}));const l={kind:"Animation",visible:!0,colors:["#000000","#ffffff","#ff2121","#ff93c4","#ff8135","#fff609","#249ca3","#78dc52","#003fad","#87f2ff","#8e2ec4","#a4839f","#5c406c","#e5cdc4","#91463d","#000000"],aspectRatioLocked:!1,currentFrame:0,frames:[f(16,16)],interval:200};let c=1;const u={store:{present:l,past:[],future:[]},editor:{selectedColor:3,tool:o.Paint,cursorSize:1,backgroundColor:1,previewAnimating:!1,onionSkinEnabled:!1,overlayEnabled:!0,tilesetRevision:0,isTilemap:!1}},h=(e,t)=>{switch(t.type){case s.TOGGLE_ASPECT_RATIO:return _("toggle-aspect-ratio-lock"),Object.assign(Object.assign({},e),{aspectRatioLocked:!e.aspectRatioLocked});case s.CHANGE_CURRENT_FRAME:return _("change-frame"),Object.assign(Object.assign({},e),{currentFrame:t.index});case s.CHANGE_INTERVAL:return _("change-interval"),Object.assign(Object.assign({},e),{interval:t.newInterval});case s.CHANGE_IMAGE_DIMENSIONS:_("change-dimensions");const[i,n]=t.imageDimensions;return Object.assign(Object.assign({},e),{frames:e.frames.map((e,t)=>Object.assign(Object.assign({},e),{bitmap:pxt.sprite.Bitmap.fromData(e.bitmap).resize(i,n).data()}))});case s.IMAGE_EDIT:return _("image-edit"),Object.assign(Object.assign({},e),{frames:e.frames.map((i,n)=>n===e.currentFrame?t.newState:i)});case s.DELETE_FRAME:if(1===e.frames.length)return e;_("delete-frame");const o=e.frames.slice();o.splice(t.index,1);let r=e.currentFrame;return e.currentFrame>=t.index&&e.currentFrame>0&&r--,Object.assign(Object.assign({},e),{currentFrame:r,frames:o});case s.DUPLICATE_FRAME:_("duplicate-frame");const a=e.frames.slice();return a.splice(t.index,0,function(e){let t,i,n;e.floating&&(e.floating.bitmap&&(i=pxt.sprite.Bitmap.fromData(e.floating.bitmap).copy().data()),e.floating.overlayLayers&&(n=e.floating.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy().data())),t={bitmap:i,overlayLayers:n});return Object.assign(Object.assign({},e),{bitmap:pxt.sprite.Bitmap.fromData(e.bitmap).copy().data(),overlayLayers:e.overlayLayers&&e.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy().data()),floating:t})}(e.frames[t.index])),Object.assign(Object.assign({},e),{frames:a,currentFrame:t.index+1});case s.NEW_FRAME:return _("new-frame"),Object.assign(Object.assign({},e),{frames:[...e.frames,f(e.frames[0].bitmap.width,e.frames[0].bitmap.height)],currentFrame:e.frames.length});case s.MOVE_FRAME:if(t.newIndex<0||t.newIndex>=e.frames.length||t.newIndex<0||t.newIndex>=e.frames.length)return e;_("move-frame");const l=e.frames.slice(),c=l.splice(t.oldIndex,1)[0];return l.splice(t.newIndex,0,c),Object.assign(Object.assign({},e),{frames:l,currentFrame:t.oldIndex===e.currentFrame?t.newIndex:e.currentFrame});case s.SET_FRAMES:return _("set-frames"),Object.assign(Object.assign({},e),{frames:t.frames,currentFrame:t.currentFrame||0});default:return e}},d=(e,t,i)=>{let n;switch(t.type){case s.CHANGE_PREVIEW_ANIMATING:return _("preview-animate-"+(t.animating?"on":"off")),Object.assign(Object.assign({},e),{previewAnimating:t.animating});case s.CHANGE_CANVAS_ZOOM:return(t.zoom>0||t.zoom<0)&&_("zoom-"+(t.zoom>0?"in":"out")),Object.assign(Object.assign({},e),{zoomDelta:t.zoom});case s.CHANGE_IMAGE_TOOL:return _(`change-tool-${o[t.tool]}`),Object.assign(Object.assign({},e),{tool:t.tool});case s.CHANGE_CURSOR_SIZE:return _(`change-cursor-size-${t.cursorSize}`),Object.assign(Object.assign({},e),{cursorSize:t.cursorSize});case s.CHANGE_SELECTED_COLOR:return _(`foreground-color-${t.selectedColor}`),Object.assign(Object.assign({},e),{selectedColor:t.selectedColor,tool:e.tool===o.Erase?o.Paint:e.tool});case s.CHANGE_CURSOR_LOCATION:return Object.assign(Object.assign({},e),{cursorLocation:t.cursorLocation});case s.CHANGE_BACKGROUND_COLOR:return _(`background-color-${t.backgroundColor}`),Object.assign(Object.assign({},e),{backgroundColor:t.backgroundColor});case s.SWAP_FOREGROUND_BACKGROUND:return _("swap-foreground-background"),Object.assign(Object.assign({},e),{backgroundColor:e.selectedColor,selectedColor:e.backgroundColor});case s.TOGGLE_ONION_SKIN_ENABLED:return _("toggle-onion-skin"),Object.assign(Object.assign({},e),{onionSkinEnabled:!e.onionSkinEnabled});case s.CHANGE_TILE_PALETTE_CATEGORY:return _(`change-tile-category-${r[t.category]}`),Object.assign(Object.assign({},e),{tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{category:t.category,page:0})});case s.CHANGE_TILE_PALETTE_PAGE:return _("change-tile-page"),Object.assign(Object.assign({},e),{tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{page:t.page})});case s.CHANGE_DRAWING_MODE:return _("change-drawing-mode"),Object.assign(Object.assign({},e),{drawingMode:t.drawingMode||a.Default});case s.CHANGE_OVERLAY_ENABLED:return _("change-overlay-enabled"),Object.assign(Object.assign({},e),{overlayEnabled:t.enabled});case s.CREATE_NEW_TILE:return n=e.editedTiles,!t.tile||n&&-1!==n.indexOf(t.tile.id)||(n=(n||[]).concat([t.tile.id])),Object.assign(Object.assign({},e),{editedTiles:n,selectedColor:t.foreground,backgroundColor:t.background});case s.SET_GALLERY_OPEN:return _(`set-gallery-open-${t.open}`),Object.assign(Object.assign({},e),{tileGalleryOpen:t.open,tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{page:0})});case s.DELETE_TILE:return Object.assign(Object.assign({},e),{deletedTiles:(e.deletedTiles||[]).concat([t.id]),selectedColor:t.index===e.selectedColor?0:e.selectedColor,backgroundColor:t.index===e.backgroundColor?0:e.backgroundColor,tilesetRevision:c++});case s.OPEN_TILE_EDITOR:const l=t.index?"edit":"new";return _(`open-tile-editor-${l}`),Object.assign(Object.assign({},e),{editingTile:{type:l,tilesetIndex:t.index}});case s.CLOSE_TILE_EDITOR:return n=e.editedTiles,!t.result||n&&-1!==n.indexOf(t.result.id)||(n=(n||[]).concat([t.result.id])),Object.assign(Object.assign({},e),{editedTiles:n,selectedColor:t.index||i.present.tileset.tiles.length,editingTile:void 0,tilesetRevision:c++});case s.SHOW_ALERT:return _("show-alert"),Object.assign(Object.assign({},e),{alert:{title:t.title,text:t.text,options:t.options}});case s.HIDE_ALERT:return _("hide-alert"),Object.assign(Object.assign({},e),{alert:null});case s.DISABLE_RESIZE:return Object.assign(Object.assign({},e),{resizeDisabled:!0})}return e},p=(e,t)=>{switch(t.type){case s.TOGGLE_ASPECT_RATIO:return _("toggle-aspect-ratio-lock"),Object.assign(Object.assign({},e),{aspectRatioLocked:!e.aspectRatioLocked});case s.CHANGE_IMAGE_DIMENSIONS:_("change-dimensions");const[a,l]=t.imageDimensions;return Object.assign(Object.assign({},e),{tilemap:Object.assign(Object.assign({},e.tilemap),{bitmap:(i=e.tilemap.bitmap,o=a,r=l,pxt.sprite.Tilemap.fromData(i).resize(o,r).data()),overlayLayers:e.tilemap.overlayLayers&&e.tilemap.overlayLayers.map(e=>function(e,t,i){return pxt.sprite.Bitmap.fromData(e).resize(t,i).data()}(e,a,l))})});case s.CREATE_NEW_TILE:const c=!t.qualifiedName;let u;return _(c?"new-tile":`used-tile-${t.qualifiedName}`),c?(u=t.tile,u.isProjectTile=!0):u=(0,n.lookupAsset)("tile",t.qualifiedName),Object.assign(Object.assign({},e),{tileset:Object.assign(Object.assign({},e.tileset),{tiles:e.tileset.tiles.concat([u])}),nextId:c?e.nextId+1:e.nextId});case s.CLOSE_TILE_EDITOR:return _("close-tile-editor"),t.result?t.index?Object.assign(Object.assign({},e),{tileset:g(e.tileset,t.index,t.result)}):Object.assign(Object.assign({},e),{tileset:Object.assign(Object.assign({},e.tileset),{tiles:e.tileset.tiles.concat([t.result])}),nextId:e.nextId+1}):e;case s.DELETE_TILE:_("delete-tile");const h=e.tileset.tiles.slice();return h.splice(t.index,1),Object.assign(Object.assign({},e),{tilemap:Object.assign(Object.assign({},e.tilemap),{bitmap:T(t.index,pxt.sprite.Tilemap.fromData(e.tilemap.bitmap)).data()}),tileset:Object.assign(Object.assign({},e.tileset),{tiles:h})});case s.IMAGE_EDIT:return _("image-edit"),Object.assign(Object.assign({},e),{tilemap:t.newState});default:return e}var i,o,r};function g(e,t,i){return Object.assign(Object.assign({},e),{tiles:e.tiles.map((e,n)=>n===t?i:e)})}function f(e,t){return{bitmap:new pxt.sprite.Bitmap(e,t).data()}}let m;function _(e){m&&m(e)}function b(e,t){for(const i of e.tiles)if(!i.jresData&&!i.isProjectTile)for(const e of t)if(e.qualifiedName===i.id){i.bitmap=e.bitmap;break}return e}function T(e,t){const i=t.copy();for(let t=0;t<i.width;t++)for(let n=0;n<i.height;n++){const s=i.get(t,n);s===e?i.set(t,n,0):s>e&&i.set(t,n,s-1)}return i}function E(e,t){return"tilemap"===e.type?function(e,t){return{kind:"Tilemap",asset:e,colors:pxt.appTarget.runtime.palette.slice(),aspectRatioLocked:!1,tilemap:{bitmap:e.data.tilemap.data(),overlayLayers:[e.data.layers]},tileset:b(e.data.tileset,t),nextId:e.data.nextId}}(e,t):function(e){return{kind:"Animation",asset:e,visible:!0,colors:pxt.appTarget.runtime.palette.slice(),aspectRatioLocked:"tile"===e.type,currentFrame:0,frames:"animation"===e.type?e.frames.map(e=>({bitmap:e})):[{bitmap:e.bitmap}],interval:"animation"===e.type?e.interval:100}}(e)}function v(e,t){return!(e.layerOffsetX!==t.layerOffsetX||e.layerOffsetY!==t.layerOffsetY||!!e.floating!=!!t.floating||!pxt.sprite.bitmapEquals(e.bitmap,t.bitmap)||!pxt.U.arrayEquals(e.overlayLayers,t.overlayLayers,pxt.sprite.bitmapEquals))&&!!(!e.floating||pxt.sprite.bitmapEquals(e.floating.bitmap,t.floating.bitmap)&&pxt.U.arrayEquals(e.floating.overlayLayers,t.floating.overlayLayers,pxt.sprite.bitmapEquals))}i.setTelemetryFunction=function(e){m=e},i.default=(e=u,t)=>{var i,o,l;switch(t.type){case s.OPEN_TILE_EDITOR:case s.CHANGE_PREVIEW_ANIMATING:case s.CHANGE_CANVAS_ZOOM:case s.CHANGE_IMAGE_TOOL:case s.CHANGE_CURSOR_SIZE:case s.CHANGE_SELECTED_COLOR:case s.CHANGE_CURSOR_LOCATION:case s.CHANGE_BACKGROUND_COLOR:case s.SWAP_FOREGROUND_BACKGROUND:case s.TOGGLE_ONION_SKIN_ENABLED:case s.CHANGE_OVERLAY_ENABLED:case s.CHANGE_TILE_PALETTE_PAGE:case s.CHANGE_TILE_PALETTE_CATEGORY:case s.CHANGE_DRAWING_MODE:case s.SET_GALLERY_OPEN:case s.SHOW_ALERT:case s.HIDE_ALERT:case s.DISABLE_RESIZE:return Object.assign(Object.assign({},e),{editor:d(e.editor,t,e.store)});case s.SET_INITIAL_STATE:const g=t.state;return Object.assign(Object.assign({},e),{editor:Object.assign(Object.assign({},u.editor),{selectedColor:g.selectedColor,backgroundColor:g.backgroundColor,tilemapPalette:g.tilemapPalette,tileGalleryOpen:g.tileGalleryOpen,tileGallery:g.tileGallery,isTilemap:g.isTilemap,referencedTiles:e.editor.referencedTiles}),store:Object.assign(Object.assign({},e.store),{past:t.past||e.store.past,future:t.past?[]:e.store.future})});case s.OPEN_ASSET:const f=t.asset,m=t.gallery||(t.keepPast?e.editor.tileGallery:[]);let b=-1;if("tilemap"===f.type){const e=t.asset.data;if(pxt.sprite.isEmptyTilemap(e)){const t=e.tileset.tiles||[],s=null===(i=m.find(e=>-1!==e.tags.indexOf("forest")))||void 0===i?void 0:i.qualifiedName,o=(0,n.lookupAsset)("tile",s);o&&!t.find(e=>e.id===s)&&t.push(o),b=t.indexOf(o)}}return Object.assign(Object.assign({},e),{editor:"tilemap"===f.type?{selectedColor:b,backgroundColor:-1,isTilemap:!0,tilemapPalette:{category:r.Forest,page:0},drawingMode:a.Default,overlayEnabled:!0,tileGallery:m,tileGalleryOpen:!!m,referencedTiles:f.data.projectReferences,previewAnimating:!1,onionSkinEnabled:!1,tilesetRevision:c++,tool:t.keepPast?e.editor.tool:u.editor.tool,cursorSize:t.keepPast?e.editor.cursorSize:u.editor.cursorSize,editedTiles:t.keepPast?e.editor.editedTiles:void 0,deletedTiles:t.keepPast?e.editor.deletedTiles:void 0}:{isTilemap:!1,tilesetRevision:c++,selectedColor:t.keepPast?e.editor.selectedColor:u.editor.selectedColor,backgroundColor:t.keepPast?e.editor.backgroundColor:u.editor.backgroundColor,previewAnimating:t.keepPast?e.editor.previewAnimating:u.editor.previewAnimating,tool:t.keepPast?e.editor.tool:u.editor.tool,onionSkinEnabled:t.keepPast?e.editor.onionSkinEnabled:u.editor.onionSkinEnabled,cursorSize:t.keepPast?e.editor.cursorSize:u.editor.cursorSize,resizeDisabled:t.keepPast?e.editor.resizeDisabled:u.editor.resizeDisabled},store:Object.assign(Object.assign({},e.store),{past:t.keepPast?e.store.past:[],present:E(t.asset,m),future:[]})});case s.CHANGE_ASSET_NAME:return _("change-asset-name"),Object.assign(Object.assign({},e),{store:{past:[...e.store.past,e.store.present],present:Object.assign(Object.assign({},e.store.present),{asset:Object.assign(Object.assign({},e.store.present.asset),{meta:Object.assign(Object.assign({},e.store.present.asset.meta||{}),{displayName:t.name})})}),future:[]}});case s.UNDO_IMAGE_EDIT:return e.store.past.length?(_("undo"),Object.assign(Object.assign({},e),{store:Object.assign(Object.assign({},e.store),{past:e.store.past.slice(0,e.store.past.length-1),present:e.store.past[e.store.past.length-1],future:[...e.store.future,e.store.present]}),editor:Object.assign(Object.assign({},e.editor),{tilesetRevision:c++})})):e;case s.REDO_IMAGE_EDIT:return e.store.future.length?(_("redo"),Object.assign(Object.assign({},e),{store:Object.assign(Object.assign({},e.store),{past:[...e.store.past,e.store.present],present:e.store.future[e.store.future.length-1],future:e.store.future.slice(0,e.store.future.length-1)}),editor:Object.assign(Object.assign({},e.editor),{tilesetRevision:c++})})):e;default:const T=e.store.present,y=e.editor.isTilemap?p(e.store.present,t):h(e.store.present,t);let k=T.kind!==y.kind;k||("Animation"===T.kind?(l=y,k=!((o=T).visible===l.visible&&o.aspectRatioLocked===l.aspectRatioLocked&&o.currentFrame===l.currentFrame&&o.interval===l.interval&&pxt.assetEquals(o.asset,l.asset)&&pxt.U.arrayEquals(o.colors,l.colors,(e,t)=>e===t)&&pxt.U.arrayEquals(o.frames,l.frames,(e,t)=>v(e,t)))):k=!function(e,t){return e.aspectRatioLocked===t.aspectRatioLocked&&e.nextId===t.nextId&&v(e.tilemap,t.tilemap)&&pxt.assetEquals(e.asset,t.asset)&&pxt.U.arrayEquals(e.colors,t.colors,(e,t)=>e===t)&&pxt.sprite.tilesetEquals(e.tileset,t.tileset)}(T,y));const C=k?Object.assign(Object.assign({},e.store),{past:[...e.store.past,T],present:y,future:[]}):e.store;return Object.assign(Object.assign({},e),{editor:d(e.editor,t,e.store),store:C})}}},{"../../../assets":174,"../actions/types":188}],192:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.mainStore=i.tileEditorStore=void 0;const n=e("redux"),s=e("./imageReducer"),o=(0,n.createStore)(s.default);i.default=o,i.tileEditorStore=(0,n.createStore)(s.default),i.mainStore=o},{"./imageReducer":191,redux:306}],193:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Minimap=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../ImageEditor"),a=pxt.BrowserUtils.isEdge()?25:1;class l extends s.Component{constructor(){super(...arguments),this.tileColors=[]}componentDidMount(){this.canvas=this.refs["minimap-canvas"],this.redrawCanvas()}componentDidUpdate(){this.redrawCanvas()}render(){return(0,n.jsx)("div",Object.assign({className:"minimap-outer"},{children:(0,n.jsx)("canvas",{ref:"minimap-canvas",className:"paint-surface"})}))}redrawCanvas(){const{tilemap:e,lightMode:t}=this.props;let{bitmap:i,floating:n,layerOffsetX:s,layerOffsetY:o}=e;const l=this.canvas.getContext("2d"),c=pxt.sprite.Tilemap.fromData(i),u=n&&n.bitmap?pxt.sprite.Tilemap.fromData(n.bitmap):null;this.canvas.width=c.width*a,this.canvas.height=c.height*a,this.tileColors=[];for(let e=0;e<c.width;e++)for(let i=0;i<c.height;i++){const n=u?u.get(e-s,i-o):null,h=c.get(e,i);n?(l.fillStyle=this.getColor(n),l.fillRect(e*a,i*a,a,a)):h?(l.fillStyle=this.getColor(h),l.fillRect(e*a,i*a,a,a)):t?(l.fillStyle=r.LIGHT_MODE_TRANSPARENT,l.fillRect(e*a,i*a,a,a)):l.clearRect(e*a,i*a,a,a)}}getColor(e){if(!this.tileColors[e]){const{tileset:t,colors:i}=this.props;if(e>=t.tiles.length)return"#ffffff";const n=pxt.sprite.Bitmap.fromData(t.tiles[e].bitmap);this.tileColors[e]=pxt.sprite.computeAverageColor(n,i)}return this.tileColors[e]}}i.Minimap=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{tilemap:n.tilemap,tileset:n.tileset,colors:n.colors}:{}},{})(l)},{"../ImageEditor":180,react:304,"react-redux":287,"react/jsx-runtime":305}],194:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TilePalette=i.BUILTIN_CATEGORIES=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../store/imageReducer"),a=e("../actions/dispatch"),l=e("../TimelineFrame"),c=e("../Pivot"),u=e("../../../assets"),h=e("../../../../../react-common/components/controls/CarouselNav"),d=e("../../../../../react-common/components/controls/Dropdown"),p=e("../../../../../react-common/components/controls/Button"),g=e("../../../../../react-common/components/util");pxt.BrowserUtils.isEdge();i.BUILTIN_CATEGORIES=[{id:"forest",text:lf("Forest"),tiles:[]},{id:"aquatic",text:lf("Aquatic"),tiles:[]},{id:"dungeon",text:lf("Dungeon"),tiles:[]},{id:"misc",text:lf("Miscellaneous"),tiles:[]}];const f=[{id:"custom",text:lf("My Tiles")},{id:"gallery",text:lf("Gallery")}],m=new pxt.sprite.Bitmap(16,16);class _ extends s.Component{constructor(e){super(e),this.dropdownHandler=e=>{this.props.dispatchChangeTilePaletteCategory(this.categories.filter(e=>!!e.tiles.length).findIndex(t=>t.id===e))},this.pivotHandler=(e,t)=>{this.props.dispatchSetGalleryOpen(1===t)},this.pageHandler=e=>{this.props.dispatchChangeTilePalettePage(e)},this.tileCreateHandler=()=>{this.props.dispatchOpenTileEditor()},this.tileEditHandler=()=>{const{tileset:e,selected:t,dispatchOpenTileEditor:i}=this.props,n=e.tiles[t];(null==n?void 0:n.isProjectTile)&&0!==t&&i(t,n.id)},this.tileDuplicateHandler=()=>{var e;const{tileset:t,selected:i,backgroundColor:n,dispatchCreateNewTile:s}=this.props;if(!t.tiles[i]||!t.tiles[i].isProjectTile||0===i)return;const o=t.tiles[i];s((0,u.createTile)(o.bitmap,null,null===(e=o.meta)||void 0===e?void 0:e.displayName),t.tiles.length,n)},this.tileDeleteAlertHandler=()=>{const{tileset:e,selected:t,dispatchShowAlert:i,dispatchHideAlert:n,referencedTiles:s}=this.props,o=e.tiles[t];t&&o&&o.isProjectTile&&(s&&-1!==s.indexOf(o.id)?i(lf("Unable to delete"),lf("This tile is used in your game. Remove all blocks using the tile before deleting."),[{label:lf("Cancel"),onClick:n}]):i(lf("Are you sure?"),lf("Deleting this tile will remove it from all other tile maps in your game."),[{label:lf("Yes"),onClick:this.deleteTile},{label:lf("No"),onClick:n}]))},this.deleteTile=()=>{const e=this.props.tileset.tiles[this.props.selected];e&&this.props.dispatchDeleteTile(this.props.selected,e.id)},this.foregroundBackgroundClickHandler=()=>{this.props.drawingMode!=r.TileDrawingMode.Default?this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default):this.props.dispatchSwapBackgroundForeground()},this.wallClickHandler=()=>{this.props.drawingMode===r.TileDrawingMode.Wall?this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default):this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Wall)},this.preventContextMenu=e=>e.preventDefault();const{gallery:t}=e;if(this.refreshGallery(e),t){const e={};for(const i of t){const t=i.tags.find(e=>pxt.Util.startsWith(e,"category-"));t&&(e[t]||(e[t]={id:t,text:pxt.Util.rlf(`{id:tilecategory}${t.substr(9)}`),tiles:[]}),e[t].tiles.push(i))}this.categories=i.BUILTIN_CATEGORIES.concat(Object.keys(e).map(t=>e[t]))}else this.categories=[]}componentDidMount(){this.updateGalleryTiles()}UNSAFE_componentWillReceiveProps(e){this.props.selected!=e.selected?this.jumpToPageContaining(e.selected):this.props.backgroundColor!=e.backgroundColor&&this.jumpToPageContaining(e.backgroundColor),this.refreshGallery(e)}componentDidUpdate(){this.updateGalleryTiles()}render(){const{colors:e,selected:t,backgroundColor:i,tileset:s,category:o,page:a,drawingMode:u,galleryOpen:_}=this.props,E=s.tiles[t]?s.tiles[t].bitmap:m.data(),v=s.tiles[i]?s.tiles[i].bitmap:m.data();m.data();this.updateGalleryTiles();let y=Math.ceil(this.categoryTiles.length/16);_||this.categoryTiles.length%16!=0||y++;const k=!_&&(1===y||a===y-1),C=_||!this.renderedTiles.some(e=>!T(e)&&e.index===t),I=4*a*4,S=this.categoryTiles.slice(I,I+16),A=this.categories.filter(e=>!!e.tiles.length).map(e=>({id:e.id,title:e.text,label:e.text}));return(0,n.jsxs)("div",Object.assign({className:"tile-palette"},{children:[(0,n.jsxs)("div",Object.assign({className:"tile-palette-fg-bg"},{children:[(0,n.jsx)("div",Object.assign({className:"tile-palette-swatch fg "+(u==r.TileDrawingMode.Default?"selected":""),onClick:this.foregroundBackgroundClickHandler,role:"button"},{children:(0,n.jsx)(l.TimelineFrame,{frames:[{bitmap:E}],colors:e})})),(0,n.jsxs)("div",Object.assign({className:"tile-palette-swatch bg",onClick:this.foregroundBackgroundClickHandler,role:"button"},{children:[(0,n.jsx)(l.TimelineFrame,{frames:[{bitmap:v}],colors:e}),(0,n.jsx)(p.Button,{className:"image-editor-button toggle",leftIcon:"ms-Icon ms-Icon--ReturnKey",title:lf("Swap the background and foreground colors."),onClick:this.foregroundBackgroundClickHandler})]})),(0,n.jsx)("div",Object.assign({className:"tile-palette-swatch wall "+(u==r.TileDrawingMode.Wall?"selected":""),onClick:this.wallClickHandler,title:lf("Draw walls"),role:"button"},{children:(0,n.jsx)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1000 1000",width:"1000",height:"1000"},{children:(0,n.jsx)("path",{d:"M 968.49289,108.05443 771.30518,3.7581533 183.65231,166.0694 l 2.58963,202.62638 -156.247366,54.4148 0.872799,492.65563 179.544267,81.08212 758.08125,-222.4989 z M 765.6275,42.836761 916.79721,122.02922 412.26526,262.35026 250.08966,187.43643 Z M 934.62189,739.077 234.56171,946.92199 233.81426,554.79578 422.38222,493.25053 423.42046,300.4059 934.62189,157.54989 Z M 204.96854,402.33519 361.49056,473.98651 222.88861,518.46222 75.008408,444.5191 Z"})}))}))]})),(0,n.jsx)(c.Pivot,{options:f,selected:_?1:0,onChange:this.pivotHandler}),(0,n.jsxs)("div",Object.assign({className:"tile-palette-controls-outer"},{children:[_&&(0,n.jsx)(d.Dropdown,{id:"tile-palette-gallery",className:"tile-palette-dropdown",items:A,onItemSelected:this.dropdownHandler,selectedId:A[o].id}),!_&&(0,n.jsxs)("div",Object.assign({className:"tile-palette-controls"},{children:[(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileEditHandler,leftIcon:"ms-Icon ms-Icon--SingleColumnEdit",title:lf("Edit the selected tile"),disabled:C}),(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileDuplicateHandler,leftIcon:"ms-Icon ms-Icon--Copy",title:lf("Duplicate the selected tile"),disabled:C}),(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileDeleteAlertHandler,leftIcon:"ms-Icon ms-Icon--Delete",title:lf("Delete the selected tile"),disabled:C})]}))]})),(0,n.jsxs)("div",Object.assign({className:"tile-canvas-outer",onContextMenu:this.preventContextMenu},{children:[(0,n.jsxs)("div",Object.assign({className:"tile-canvas"},{children:[S.map((t,i)=>(0,n.jsx)(b,{tile:t.bitmap,title:this.getTileTooltip(t),colors:e,onClick:()=>this.handleTileClick(i,!1),onRightClick:()=>this.handleTileClick(i,!0)},i)),k&&(0,n.jsx)("div",Object.assign({className:"tile-button-outer"},{children:(0,n.jsx)(p.Button,{className:"image-editor-button add-tile-button toggle",onClick:this.tileCreateHandler,leftIcon:"ms-Icon ms-Icon--Add",title:lf("Create a new tile")})}))]})),(0,n.jsx)("div",Object.assign({className:"tile-canvas-controls"},{children:(0,n.jsx)(h.CarouselNav,{selected:a,pages:y,onPageSelected:this.pageHandler,maxDisplayed:5})}))]}))]}))}getTileTooltip(e){const t=(()=>{var t,i,n,s;if(T(e))return null===(t=e.qualifiedName)||void 0===t?void 0:t.split(".").pop();const o=null===(n=null===(i=this.props.tileset)||void 0===i?void 0:i.tiles)||void 0===n?void 0:n[e.index];return(null===(s=null==o?void 0:o.meta)||void 0===s?void 0:s.displayName)||(o?pxt.getShortIDForAsset(o):void 0)||(null==o?void 0:o.id)})(),i=null==t?void 0:t.split(".").pop();return i?lf("Tile {0}",i):lf("Tile")}updateGalleryTiles(){const{page:e,category:t,galleryOpen:i}=this.props;this.categoryTiles=i?this.categories[t].tiles:this.getCustomTiles().map(([e,t])=>({index:t,bitmap:e.bitmap}));const n=16*e;this.renderedTiles=this.categoryTiles.slice(n,n+16)}jumpToPageContaining(e){const{tileset:t,dispatchSetGalleryOpen:i,dispatchChangeTilePaletteCategory:n,dispatchChangeTilePalettePage:s}=this.props;if(!e||e<0||e>=t.tiles.length)return;const o=t.tiles[e];if(o.isProjectTile){const e=this.getCustomTiles().map(([e,t])=>e);if(!e)return;const t=Math.max(Math.floor(e.findIndex(e=>e.id==o.id)/16),0);i(!1),s(t)}else{const e=this.categories.find(e=>-1!==e.tiles.findIndex(e=>e.qualifiedName==o.id));if(!e||!e.tiles)return;const t=Math.max(Math.floor(e.tiles.findIndex(e=>e.qualifiedName==o.id)/16),0);i(!0),n(this.categories.indexOf(e)),s(t)}}handleTileClick(e,t){const i=this.renderedTiles[e];if(i){let e,n;if(T(i)?(e=this.getTileIndex(i),n=i.qualifiedName):e=i.index,e>=0)t?this.props.dispatchChangeBackgroundColor(e):this.props.dispatchChangeSelectedColor(e);else{const{selected:e,backgroundColor:i,tileset:s}=this.props,o=s.tiles.length||1;this.props.dispatchCreateNewTile(null,t?e:o,t?o:i,n)}this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default)}}refreshGallery(e){const{gallery:t,tileset:n}=e;t&&i.BUILTIN_CATEGORIES.forEach(e=>{e.tiles=t.filter(t=>-1!==t.tags.indexOf(e.id)&&t.tileWidth===n.tileWidth)})}getCustomTiles(){return this.props.tileset.tiles.map((e,t)=>[e,t]).filter(([e])=>e.isProjectTile).sort(([e],[t])=>{const i="myTiles.transparency"+this.props.tileset.tileWidth;return e.id==i?-1:t.id==i?1:e.internalID-t.internalID})}getTileIndex(e){const{tileset:t}=this.props;for(let i=0;i<t.tiles.length;i++)if(t.tiles[i].id===e.qualifiedName)return i;return-1}}const b=e=>{const{tile:t,title:i,onClick:o,onRightClick:r,colors:a}=e,l=s.useRef();return s.useEffect(()=>{const e=l.current;e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.clearRect(0,0,e.width,e.height);const n=pxt.sprite.Bitmap.fromData(t);for(let e=0;e<t.width;e++)for(let s=0;s<t.height;s++){const t=n.get(e,s);t&&(i.fillStyle=a[t],i.fillRect(e,s,1,1))}},[t,a]),(0,n.jsx)("div",Object.assign({className:"tile-button-outer"},{children:(0,n.jsx)(p.Button,{className:"image-editor-button tile-button",title:i,onClick:o,onRightClick:r,label:(0,n.jsx)("canvas",{ref:l})})}))};function T(e){return!!e.qualifiedName}const E={dispatchChangeSelectedColor:a.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:a.dispatchChangeBackgroundColor,dispatchSwapBackgroundForeground:a.dispatchSwapBackgroundForeground,dispatchChangeTilePalettePage:a.dispatchChangeTilePalettePage,dispatchChangeTilePaletteCategory:a.dispatchChangeTilePaletteCategory,dispatchChangeDrawingMode:a.dispatchChangeDrawingMode,dispatchCreateNewTile:a.dispatchCreateNewTile,dispatchSetGalleryOpen:a.dispatchSetGalleryOpen,dispatchOpenTileEditor:a.dispatchOpenTileEditor,dispatchDeleteTile:a.dispatchDeleteTile,dispatchShowAlert:a.dispatchShowAlert,dispatchHideAlert:a.dispatchHideAlert};i.TilePalette=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{selected:t.selectedColor,tileset:n.tileset,backgroundColor:t.backgroundColor,category:t.tilemapPalette.category,page:t.tilemapPalette.page,colors:n.colors,drawingMode:t.drawingMode,gallery:t.tileGallery,galleryOpen:t.tileGalleryOpen,referencedTiles:t.referencedTiles}:{}},E)(_)},{"../../../../../react-common/components/controls/Button":159,"../../../../../react-common/components/controls/CarouselNav":160,"../../../../../react-common/components/controls/Dropdown":162,"../../../../../react-common/components/util":171,"../../../assets":174,"../Pivot":181,"../TimelineFrame":184,"../actions/dispatch":187,"../store/imageReducer":191,react:304,"react-redux":287,"react/jsx-runtime":305}],195:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.replaceColorEdit=i.outlineEdit=i.flipEdit=i.rotateEdit=i.MarqueeEdit=i.FillEdit=i.CircleEdit=i.LineEdit=i.OutlineEdit=i.RectangleEdit=i.PaintEdit=i.SelectionEdit=i.Edit=i.EditState=i.getEditState=i.getEdit=i.tools=i.ToolCursor=void 0;const n=e("./store/imageReducer");var s;!function(e){e.None="none",e.Default="default",e.Pointer="pointer",e.Crosshair="crosshair",e.Grab="grab",e.Grabbing="grabbing",e.EyeDropper="var(--eyedropper)"}(s=i.ToolCursor||(i.ToolCursor={})),i.tools=[{tool:n.ImageEditorTool.Paint,iconClass:"ms-Icon ms-Icon--Edit",title:lf("Paint Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Erase,iconClass:"ms-Icon ms-Icon--EraseTool",title:lf("Erase Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Rect,iconClass:"ms-Icon ms-Icon--RectangleShape",title:lf("Rectangle Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Fill,iconClass:"ms-Icon ms-Icon--BucketColor",title:lf("Fill Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Circle,iconClass:"ms-Icon ms-Icon--CircleRing",title:lf("Circle Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Line,iconClass:"ms-Icon ms-Icon--Line",title:lf("Line Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Marquee,iconClass:"ms-Icon ms-Icon--SelectAll",title:lf("Marquee Tool"),hoverCursor:s.Crosshair,hoverLayerCursor:s.Grab,downLayerCursor:s.Grabbing},{tool:n.ImageEditorTool.Pan,iconClass:"ms-Icon ms-Icon--HandsFree",title:lf("Canvas Pan Tool"),hoverCursor:s.Grab,downCursor:s.Grabbing},{tool:n.ImageEditorTool.ColorSelect,hiddenTool:!0,iconClass:"ms-Icon ms-Icon--Edit",title:lf("Color Select Tool"),hoverCursor:s.EyeDropper}],i.getEdit=function(e,t,i,s){switch(e){case n.ImageEditorTool.Paint:return new l(t.width,t.height,i,s);case n.ImageEditorTool.Rect:return new c(t.width,t.height,i,s);case n.ImageEditorTool.Fill:return new d(t.width,t.height,i,s);case n.ImageEditorTool.Line:return new u(t.width,t.height,i,s);case n.ImageEditorTool.Marquee:return new p(t.width,t.height,i,s);case n.ImageEditorTool.Circle:return new h(t.width,t.height,i,s);case n.ImageEditorTool.Erase:return new l(t.width,t.height,0,s);case n.ImageEditorTool.ColorSelect:default:return}},i.getEditState=function(e,t,i=n.TileDrawingMode.Default){const s=new o(t?pxt.sprite.Tilemap.fromData(e.bitmap).copy():pxt.sprite.Bitmap.fromData(e.bitmap).copy());let r,a,l;return e.overlayLayers&&(s.overlayLayers=e.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy())),s.layerOffsetX=e.layerOffsetX,s.layerOffsetY=e.layerOffsetY,e.floating&&(e.floating.bitmap&&(a=t?pxt.sprite.Tilemap.fromData(e.floating.bitmap).copy():pxt.sprite.Bitmap.fromData(e.floating.bitmap).copy()),e.floating.overlayLayers&&(l=e.floating.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy())),r={image:a,overlayLayers:l}),s.floating=r,s.setActiveLayer(i),s};class o{constructor(e){this.activeLayerIndex=-1,this.image=e,this.layerOffsetX=0,this.layerOffsetY=0}get width(){return this.image.width}get height(){return this.image.height}get activeLayer(){return this.activeLayerIndex<0?this.image:this.overlayLayers[this.activeLayerIndex]}setActiveLayer(e){if(e===n.TileDrawingMode.Wall)this.activeLayerIndex=0;else this.activeLayerIndex=-1}copy(){const e=new o;if(e.image=this.image.copy(),e.overlayLayers=this.overlayLayers&&this.overlayLayers.map(e=>e.copy()),this.floating){let t,i;this.floating.image&&(t=this.floating.image.copy()),this.floating.overlayLayers&&(i=this.floating.overlayLayers.map(e=>e.copy())),e.floating={image:t,overlayLayers:i}}return e.layerOffsetX=this.layerOffsetX,e.layerOffsetY=this.layerOffsetY,e}equals(e){return!(!this.image.equals(e.image)||this.floating&&!e.floating||!this.floating&&e.floating)&&(!this.floating||!this.floating.image||this.floating.image.equals(e.floating.image)&&this.layerOffsetX===e.layerOffsetX&&this.layerOffsetY===e.layerOffsetY)}mergeFloatingLayer(){this.floating&&(this.floating.image||this.floating.overlayLayers)&&(this.floating.image&&(this.floating.image.x0=this.layerOffsetX,this.floating.image.y0=this.layerOffsetY,this.image.apply(this.floating.image,!0),this.floating.image=void 0),this.floating.overlayLayers&&(this.floating.overlayLayers.forEach((e,t)=>{e.x0=this.layerOffsetX,e.y0=this.layerOffsetY,this.overlayLayers[t].apply(e,!0)}),this.floating.overlayLayers=void 0))}copyToLayer(e,t,i,n,s=!1){if(0===i||0===n)return;i<0&&(e+=i,i=-i),n<0&&(t+=n,n=-n);let o,r=this.image.copy(e,t,i,n);if(this.layerOffsetX=r.x0,this.layerOffsetY=r.y0,r.x0=void 0,r.y0=void 0,this.overlayLayers&&(o=this.overlayLayers.map(s=>s.copy(e,t,i,n))),s)for(let s=0;s<i;s++)for(let i=0;i<n;i++)this.image.set(e+s,t+i,0),this.overlayLayers&&this.overlayLayers.forEach(n=>n.set(e+s,t+i,0));this.floating={image:r,overlayLayers:o}}inFloatingLayer(e,t){return!(!this.floating||!this.floating.image)&&(e-=this.layerOffsetX,t-=this.layerOffsetY,e>=0&&e<this.floating.image.width&&t>=0&&t<this.floating.image.height)}setFloatingLayer(e,t,i){var n,s;i&&this.mergeFloatingLayer(),this.floating={image:e},this.layerOffsetX=null!==(n=null==t?void 0:t.layerOffsetX)&&void 0!==n?n:0,this.layerOffsetY=null!==(s=null==t?void 0:t.layerOffsetY)&&void 0!==s?s:0}toImageState(){return{bitmap:this.image.data(),layerOffsetX:this.layerOffsetX,layerOffsetY:this.layerOffsetY,floating:this.floating&&{bitmap:this.floating.image?this.floating.image.data():void 0,overlayLayers:this.floating.overlayLayers?this.floating.overlayLayers.map(e=>e.data()):void 0},overlayLayers:this.overlayLayers?this.overlayLayers.map(e=>e.data()):void 0}}}i.EditState=o;class r{constructor(e,t,i,n){this.canvasWidth=e,this.canvasHeight=t,this.color=i,this.toolWidth=n}doEdit(e){this.isStarted&&this.doEditCore(e)}inBounds(e,t){return e>=0&&e<this.canvasWidth&&t>=0&&t<this.canvasHeight}start(e,t,i,n,s){this.isStarted=!0,this.startCol=e,this.startRow=t,this.startX=i,this.startY=n}drawCursor(e,t,i){i(e,t)}}i.Edit=r;class a extends r{update(e,t){this.endCol=e,this.endRow=t,this.isDragged||e==this.startCol&&t==this.startRow||(this.isDragged=!0)}topLeft(){return{x:Math.min(this.startCol,this.endCol),y:Math.min(this.startRow,this.endRow)}}bottomRight(){return{x:Math.max(this.startCol,this.endCol),y:Math.max(this.startRow,this.endRow)}}}i.SelectionEdit=a;class l extends r{constructor(e,t,i,n){super(e,t,i,n),this.showPreview=!0,this.mask=new pxt.sprite.Bitmask(e,t)}update(e,t){this.interpolate(this.startCol,this.startRow,e,t),this.startCol=e,this.startRow=t}interpolate(e,t,i,n){const s=(e,t)=>this.mask.set(e,t);pxt.Util.bresenhamLine(e,t,i,n,(e,t)=>this.drawCore(e,t,s))}doEditCore(e){e.mergeFloatingLayer();for(let t=0;t<e.width;t++)for(let i=0;i<e.height;i++)this.mask.get(t,i)&&e.activeLayer.set(t,i,this.color)}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){const o=e+n,r=t+s;o>=0&&o<this.canvasWidth&&r>=0&&r<this.canvasHeight&&i(e+n,t+s)}}}i.PaintEdit=l;i.RectangleEdit=class extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();const t=this.topLeft(),i=this.bottomRight();for(let n=t.x;n<=i.x;n++)for(let s=t.y;s<=i.y;s++)e.activeLayer.set(n,s,this.color)}};class c extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();let t=this.topLeft();t.x-=this.toolWidth>>1,t.y-=this.toolWidth>>1;let i=this.bottomRight();i.x+=this.toolWidth>>1,i.y+=this.toolWidth>>1;for(let n=0;n<this.toolWidth;n++)this.drawRectangle(e,{x:t.x+n,y:t.y+n},{x:i.x-n,y:i.y-n})}drawRectangle(e,t,i){if(!(t.x>i.x||t.y>i.y)){for(let n=t.x;n<=i.x;n++)e.activeLayer.set(n,t.y,this.color),e.activeLayer.set(n,i.y,this.color);for(let n=t.y;n<=i.y;n++)e.activeLayer.set(t.x,n,this.color),e.activeLayer.set(i.x,n,this.color)}}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){const o=e+n,r=t+s;o>=0&&o<this.canvasWidth&&r>=0&&r<this.canvasHeight&&i(e+n,t+s)}}}i.OutlineEdit=c;class u extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer(),this.bresenham(this.startCol,this.startRow,this.endCol,this.endRow,e)}bresenham(e,t,i,n,s){const o=(e,t)=>s.activeLayer.set(e,t,this.color);pxt.Util.bresenhamLine(e,t,i,n,(e,t)=>this.drawCore(e,t,o))}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){i(e+n,t+s)}}}i.LineEdit=u;class h extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();const t=this.topLeft(),i=this.bottomRight(),n=i.x-t.x,s=i.y-t.y,o=Math.floor(Math.hypot(n,s)),r=this.startCol,a=this.startRow;this.midpoint(r,a,o,e)}midpoint(e,t,i,n){let s=i-1,o=0,r=1,a=1,l=r-2*i;for(;s>=o;)n.activeLayer.set(e+s,t+o,this.color),n.activeLayer.set(e+s,t-o,this.color),n.activeLayer.set(e+o,t+s,this.color),n.activeLayer.set(e+o,t-s,this.color),n.activeLayer.set(e-o,t+s,this.color),n.activeLayer.set(e-o,t-s,this.color),n.activeLayer.set(e-s,t+o,this.color),n.activeLayer.set(e-s,t-o,this.color),l<=0&&(o++,l+=a,a+=2),l>0&&(s--,r+=2,l+=r-2*i)}}i.CircleEdit=h;class d extends r{constructor(){super(...arguments),this.showPreview=!0}start(e,t,i,n,s){this.isStarted=!0,this.col=e,this.row=t}update(e,t){this.col=e,this.row=t}doEditCore(e){const t=e.activeLayer!==e.image,i=(i,n)=>(t?e.activeLayer.get(i,n)+1<<8:0)+e.image.get(i,n),n=i(this.col,this.row);if(n===this.color)return;e.mergeFloatingLayer();const s=new pxt.sprite.Bitmask(e.width,e.height);s.set(this.col,this.row);const o=[{x:this.col,y:this.row}];for(;o.length;){const t=o.pop();i(t.x,t.y)===n&&(e.activeLayer.set(t.x,t.y,this.color),r(t.x+1,t.y),r(t.x-1,t.y),r(t.x,t.y+1),r(t.x,t.y-1))}function r(e,t){e>=0&&e<s.width&&t>=0&&t<s.height&&!s.get(e,t)&&(s.set(e,t),o.push({x:e,y:t}))}}}i.FillEdit=d;class p extends a{constructor(){super(...arguments),this.isMove=!1,this.isResize=!1,this.showPreview=!1}start(e,t,i,n,s){this.isStarted=!0,this.startCol=e,this.startRow=t;const o=document.elementFromPoint(i,n);if(s.floating&&s.floating.image)if(o&&"image-editor-floating-layer-corner"==o.className){let e;this.isResize=!0,this.startOffsetX=s.layerOffsetX,this.startOffsetY=s.layerOffsetY;let t=0;const o=document.getElementsByClassName("image-editor-floating-layer-corner");for(let s=0;s<o.length;s++){let r=Math.sqrt(Math.pow(o[s].getBoundingClientRect().x-i,2)+Math.pow(o[s].getBoundingClientRect().y-n,2));r>t&&(t=r,e=o[s])}const r=document.getElementsByClassName("paint-surface");let a;for(let e=0;e<r.length;e++)r[e].className.includes("main")&&(a=r[e]);const l=a.getBoundingClientRect().left,c=a.getBoundingClientRect().top,u=a.getBoundingClientRect().width,h=a.getBoundingClientRect().height;this.anchorCol=(e.getBoundingClientRect().x-l)/u*this.canvasWidth,this.anchorRow=(e.getBoundingClientRect().y-c)/h*this.canvasHeight,this.originalImage||(this.originalImage=s.floating.image.copy())}else s.inFloatingLayer(e,t)&&(this.isMove=!0,this.startOffsetX=s.layerOffsetX,this.startOffsetY=s.layerOffsetY)}inBounds(e,t){return this.isMove||super.inBounds(e,t)}doEditCore(e){const t=this.topLeft(),i=this.bottomRight();if(this.isDragged)if(this.isMove)e.layerOffsetX=this.startOffsetX+this.endCol-this.startCol,e.layerOffsetY=this.startOffsetY+this.endRow-this.startRow;else if(this.isResize){const t=Math.round(Math.abs(this.anchorCol-this.endCol)),i=Math.round(Math.abs(this.anchorRow-this.endRow)),n=function(e,t,i){const n=new pxt.sprite.Bitmap(t,i,0,0);for(let s=0;s<t;s++)for(let o=0;o<i;o++){const r=Math.floor(s/t*e.width),a=Math.floor(o/i*e.height),l=e.get(r,a);n.set(s,o,l)}return n}(this.originalImage,t,i);e.setFloatingLayer(n,{layerOffsetX:Math.round(Math.min(this.anchorCol,this.endCol)),layerOffsetY:Math.round(Math.min(this.anchorRow,this.endRow))},!1)}else e.mergeFloatingLayer(),e.copyToLayer(t.x,t.y,i.x-t.x+1,i.y-t.y+1,!0);else this.isMove||e.mergeFloatingLayer()}}i.MarqueeEdit=p,i.rotateEdit=function(e,t,i,n){var s;const r=!!(null===(s=e.floating)||void 0===s?void 0:s.image),a=r?e.floating:e,l=i?new pxt.sprite.Tilemap(a.image.height,a.image.width):new pxt.sprite.Bitmap(a.image.height,a.image.width),c=a.overlayLayers?a.overlayLayers.map(e=>new pxt.sprite.Bitmap(e.height,e.width)):void 0;for(let e=0;e<a.image.width;e++)for(let t=0;t<a.image.height;t++)h(a.image,l,e,t),c&&c.forEach((i,n)=>h(a.overlayLayers[n],i,e,t));const u=l.width===l.height&&l.width===e.image.width&&e.image.width===e.image.height;if(!n&&!r||u){const e=new o(l);return e.overlayLayers=c,e}if(!r)for(let t=0;t<e.width;t++)for(let i=0;i<e.height;i++)e.image.set(t,i,0),e.overlayLayers&&e.overlayLayers.forEach(e=>null==e?void 0:e.set(t,i,0));return(l.width===e.image.height&&l.height===e.image.width||l.width===e.image.width&&l.height===e.image.height)&&(e.layerOffsetX=(e.width>>1)-(l.width>>1),e.layerOffsetY=(e.height>>1)-(l.height>>1)),e.floating={image:l,overlayLayers:c},e;function h(e,i,n,s){t?i.set(s,n,e.get(n,e.height-s-1)):i.set(s,n,e.get(e.width-n-1,s))}},i.flipEdit=function(e,t,i){var n,s;const r=(null===(n=e.floating)||void 0===n?void 0:n.image)?e.floating:e,a=i?new pxt.sprite.Tilemap(r.image.width,r.image.height):new pxt.sprite.Bitmap(r.image.width,r.image.height),l=r.overlayLayers?r.overlayLayers.map(e=>new pxt.sprite.Bitmap(e.width,e.height)):void 0;for(let e=0;e<r.image.width;e++)for(let t=0;t<r.image.height;t++)c(r.image,a,e,t),l&&l.forEach((i,n)=>c(r.overlayLayers[n],i,e,t));if(null===(s=e.floating)||void 0===s?void 0:s.image)return e.floating={image:a,overlayLayers:l},e;{const e=new o(a);return e.overlayLayers=l,e}function c(e,i,n,s){t?i.set(n,s,e.get(n,e.height-s-1)):i.set(n,s,e.get(e.width-n-1,s))}},i.outlineEdit=function(e,t){var i,n;const s=(null===(i=e.floating)||void 0===i?void 0:i.image)?e.floating:e,o=e.copy(),r=(null===(n=null==e?void 0:e.floating)||void 0===n?void 0:n.image)?o.floating.image:o.image;for(let e=0;e<s.image.width;e++)for(let i=0;i<s.image.height;i++)0===s.image.get(e,i)&&(0===s.image.get(e-1,i)&&0===s.image.get(e,i-1)&&0===s.image.get(e+1,i)&&0===s.image.get(e,i+1)||r.set(e,i,t));return o},i.replaceColorEdit=function(e,t,i){var n,s;const o=(null===(n=e.floating)||void 0===n?void 0:n.image)?e.floating:e,r=e.copy(),a=(null===(s=null==e?void 0:e.floating)||void 0===s?void 0:s.image)?r.floating.image:r.image;for(let e=0;e<o.image.width;e++)for(let n=0;n<o.image.height;n++)o.image.get(e,n)===t&&a.set(e,n,i);return r}},{"./store/imageReducer":191}],196:[function(e,t,i){"use strict";function n(){return"undefined"!=typeof window&&!!window.PointerEvent}function s(){return"undefined"!=typeof window&&("ontouchstart"in window||navigator&&navigator.maxTouchPoints>0)}Object.defineProperty(i,"__esModule",{value:!0}),i.createTilemapPatchFromFloatingLayer=i.applyBitmapData=i.imageStateToTilemap=i.imageStateToBitmap=i.bindGestureEvents=i.GestureState=i.fireClickOnlyOnEnter=i.clientCoord=i.pointerEvents=i.Bitmask=i.MapTools=i.isBitmapSupported=i.isTouchEnabled=i.hasPointerEvents=i.DRAG_RADIUS=void 0,i.DRAG_RADIUS=3,i.hasPointerEvents=n,i.isTouchEnabled=s,i.isBitmapSupported=function(){return!!window.createImageBitmap},function(e){e[e.Pan=0]="Pan",e[e.Stamp=1]="Stamp",e[e.Object=2]="Object",e[e.Erase=3]="Erase"}(i.MapTools||(i.MapTools={}));function o(e){if(e.touches){const t=e;return t.touches.length?t.touches[0]:t.changedTouches[0]}return e}i.Bitmask=class{constructor(e,t){this.width=e,this.height=t,this.mask=new Uint8Array(Math.ceil(e*t/8))}set(e,t){const i=e+this.width*t,n=i>>3,s=7&i;this.mask[n]|=1<<s}get(e,t){const i=e+this.width*t,n=i>>3,s=7&i;return this.mask[n]>>s&1}},i.pointerEvents=n()?{up:"pointerup",down:["pointerdown"],move:"pointermove",enter:"pointerenter",leave:"pointerleave"}:s()?{up:"mouseup",down:["mousedown","touchstart"],move:"touchmove",enter:"touchenter",leave:"touchend"}:{up:"mouseup",down:["mousedown"],move:"mousemove",enter:"mouseenter",leave:"mouseleave"},i.clientCoord=o,i.fireClickOnlyOnEnter=function(e){13===("number"==typeof e.which?e.which:e.keyCode)&&(e.preventDefault(),e.currentTarget.click())};class r{constructor(e,t,i){this.target=e,this.isRightClick=i,this.startX=t.clientX,this.startY=t.clientY,this.currentX=t.clientX,this.currentY=t.clientY}update(e){this.currentX=e.clientX,this.currentY=e.clientY,!this.isDrag&&this.distance()>i.DRAG_RADIUS?(this.isDrag=!0,this.target.onDragStart(e,this.isRightClick)):this.isDrag&&this.target.onDragMove(e)}end(e){e&&this.update(e),e=e||{clientX:this.currentX,clientY:this.currentY},this.isDrag?this.target.onDragEnd(e):this.target.onClick(e,this.isRightClick)}distance(){return Math.sqrt(Math.pow(this.currentX-this.startX,2)+Math.pow(this.currentY-this.startY,2))}}function a(e,t){for(let i=0;i<e.changedTouches.length;i++)if(e.changedTouches[i].identifier===t)return e.changedTouches[i]}function l(e){return e.button>0}i.GestureState=r,i.bindGestureEvents=function(e,t){n()?function(e,t){let i;e.addEventListener("pointerup",e=>{i&&(i.end(o(e)),e.preventDefault()),i=void 0}),e.addEventListener("pointerdown",e=>{i&&i.end(),i=new r(t,o(e),l(e)),e.preventDefault()}),e.addEventListener("pointermove",e=>{i&&(i.update(o(e)),e.preventDefault())}),e.addEventListener("pointerleave",e=>{i&&(i.end(o(e)),e.preventDefault()),i=void 0})}(e,t):s()?function(e,t){let i,n;e.addEventListener("touchend",e=>{if(i&&n){const t=a(e,n);t&&(i.end(t),i=void 0,e.preventDefault())}}),e.addEventListener("touchstart",e=>{i&&i.end(),n=e.changedTouches[0].identifier,i=new r(t,e.changedTouches[0],l(e))}),e.addEventListener("touchmove",e=>{if(i&&n){const t=a(e,n);t&&(i.update(t),e.preventDefault())}}),e.addEventListener("touchcancel",e=>{if(i&&n){const t=a(e,n);t&&(i.end(t),i=void 0,e.preventDefault())}})}(e,t):function(e,t){let i;e.addEventListener("mouseup",e=>{i&&i.end(o(e)),i=void 0}),e.addEventListener("mousedown",e=>{i&&i.end(),i=new r(t,o(e),l(e))}),e.addEventListener("mousemove",e=>{i&&i.update(o(e))}),e.addEventListener("mouseleave",e=>{i&&i.end(o(e)),i=void 0})}(e,t)},i.imageStateToBitmap=function(e){const t=pxt.sprite.Bitmap.fromData(e.bitmap).copy();if(e.floating&&e.floating.bitmap){const i=pxt.sprite.Bitmap.fromData(e.floating.bitmap);i.x0=e.layerOffsetX||0,i.y0=e.layerOffsetY||0,t.apply(i,!0)}return t},i.imageStateToTilemap=function(e){const t=pxt.sprite.Tilemap.fromData(e.bitmap).copy();if(e.floating&&e.floating.bitmap){const i=pxt.sprite.Tilemap.fromData(e.floating.bitmap);i.x0=e.layerOffsetX||0,i.y0=e.layerOffsetY||0,t.apply(i,!0)}return t},i.applyBitmapData=function(e,t,i=0,n=0){if(!e||!t)return e;const s=pxt.sprite.Bitmap.fromData(e),o=pxt.sprite.Bitmap.fromData(t);return o.x0=i,o.y0=n,s.apply(o,!0),s.data()},i.createTilemapPatchFromFloatingLayer=function(e,t){if(!e.floating)return;const i=pxt.sprite.Tilemap.fromData(e.floating.image.data()),n=new pxt.sprite.Tilemap(i.width,i.height),s=e.floating.overlayLayers?e.floating.overlayLayers.map(e=>pxt.sprite.base64EncodeBitmap(e.data())):[];let o=[];for(let e=0;e<i.width;e++)for(let s=0;s<i.height;s++){const r=t.tiles[i.get(e,s)],a=o.indexOf(r);-1===a?(n.set(e,s,o.length),o.push(r)):n.set(e,s,a)}return{map:pxt.sprite.hexEncodeTilemap(n),layers:s,tiles:o.map(e=>pxt.sprite.base64EncodeBitmap(e.bitmap))}}},{}],197:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageFieldEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./assetEditor/assetCard"),r=e("../assets"),a=e("./ImageEditor/ImageEditor"),l=e("./ImageEditor/keyboardShortcuts"),c=e("./ImageEditor/store/imageReducer"),u=e("./FilterPanel"),h=e("../util"),d=e("../../../react-common/components/controls/EditorToggle"),p=e("./MusicFieldEditor"),g=e("../../../react-common/components/util"),f=e("../../../react-common/components/controls/FocusTrap"),m=e("./PianoRollFieldEditor"),_=e("./SongGallery"),b=e("./musicEditor/playback");class T extends s.Component{constructor(e){super(e),this.tagClickHandler=e=>{let t=this.state.gallerySelectedTags;const i=e.toLowerCase(),n=t.indexOf(i);n<0?t.push(i):t.splice(n,1),this.setState({gallerySelectedTags:t})},this.clearFilterTags=()=>{this.setState({gallerySelectedTags:[]})},this.toggleFilter=()=>{this.setState({filterOpen:!this.state.filterOpen})},this.showEditor=()=>{(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!0),v("gallery-editor"),this.setState({currentView:"editor",tileGalleryVisible:!1})},this.showGallery=()=>{(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!1),v("gallery-builtin"),this.setState({currentView:"gallery",tileGalleryVisible:!1})},this.showMyAssets=()=>{var e,t;(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!1),v("gallery-my-assets"),this.userAssets=(0,r.getAssets)(void 0,void 0,null===(t=null===(e=this.state)||void 0===e?void 0:e.options)||void 0===t?void 0:t.temporaryAssets),this.setState({currentView:"my-assets",tileGalleryVisible:!1})},this.toggleTileGallery=()=>{this.state.tileGalleryVisible?this.setState({tileGalleryVisible:!1}):this.setState({tileGalleryVisible:!0,currentView:"editor"})},this.onAssetSelected=e=>{var t,i;if(this.ref&&e.id!==(null===(t=this.asset)||void 0===t?void 0:t.id))if(this.state.editingTile)this.ref.openInTileEditor(pxt.sprite.Bitmap.fromData(e.bitmap));else if("gallery"===this.state.currentView)this.ref.openGalleryAsset(e);else{const t=pxt.react.getTilemapProject();"tilemap"===(null===(i=this.asset)||void 0===i?void 0:i.type)&&pxt.sprite.updateTilemapReferencesFromResult(t,this.asset),this.asset.meta.displayName?t.updateAsset(this.asset):e.meta.displayName||(e=Object.assign(Object.assign({},pxt.cloneAsset(e)),{id:this.asset.id,meta:this.asset.meta})),"tilemap"===e.type&&pxt.sprite.addMissingTilemapTilesAndReferences(t,e),this.ref.openAsset(e,void 0,!0)}v("gallery-selection"),this.setState({currentView:"editor",tileGalleryVisible:!1}),this.setImageEditorShortcutsEnabled(!0)},this.onTileEditorOpenClose=e=>{this.setState({editingTile:e})},this.onDoneClick=()=>{this.closeEditor&&this.closeEditor(),this.props.doneButtonCallback&&this.props.doneButtonCallback()},this.handleImageEditorRegionRef=e=>{e&&(this.imageEditorRegion=e)},this.onEscapeFromGallery=()=>{this.setState({currentView:"editor"},()=>{this.imageEditorRegion&&this.imageEditorRegion.focus()})},this.state={currentView:"editor",headerVisible:!0,filterOpen:!1,gallerySelectedTags:[],galleryFilter:""},(0,c.setTelemetryFunction)(v)}get asset(){var e;return null===(e=this.ref)||void 0===e?void 0:e.getAsset()}render(){var e,t,i,s,o,r,l;const{currentView:c,headerVisible:b,editingTile:T,hideMyAssets:v,filterOpen:y,hideCloseButton:k}=this.state,C="gallery"===this.state.currentView&&y;let I=b,S=!0;const A=!v&&!T&&!!(null===(e=pxt.appTarget)||void 0===e?void 0:e.appTheme.assetEditor);this.asset&&!this.galleryAssets&&S&&this.updateGalleryAssets(),(null===(t=this.galleryAssets)||void 0===t?void 0:t.length)||(S=!1);const O=this.props.includeSpecialTagsInFilter?[]:["tile","dialog","background"];let w=[],N=[];switch(c){case"my-assets":N=this.filterAssetsByType(this.userAssets,T?"tile":null===(i=this.asset)||void 0===i?void 0:i.type),w=this.getAvailableTags(N,O);break;case"gallery":N=this.filterAssetsByType(this.galleryAssets,T?"tile":null===(s=this.asset)||void 0===s?void 0:s.type,!0,!0),w=this.getAvailableTags(N,O),N=this.filterAssetsByTag(N)}const R=[{label:lf("Editor"),title:lf("Editor"),focusable:!0,icon:"fas fa-paint-brush",onClick:this.showEditor,view:"editor"},{label:lf("Gallery"),title:lf("Gallery"),focusable:!0,icon:"fas fa-image",onClick:this.showGallery,view:"gallery"},{label:lf("My Assets"),title:lf("My Assets"),focusable:!0,icon:"fas fa-folder",onClick:this.showMyAssets,view:"my-assets"}];return S||A?S?A||R.splice(2,1):R.splice(1,1):I=!1,(0,n.jsxs)(f.FocusTrap,Object.assign({onEscape:this.onDoneClick,className:(0,g.classList)("image-editor-wrapper",this.isSongEditor()&&"music-asset-editor")},{children:[I&&(0,n.jsxs)("div",Object.assign({className:"gallery-editor-header"},{children:[(0,n.jsx)("div",{className:"image-editor-header-left"}),(0,n.jsx)("div",Object.assign({className:"image-editor-header-center"},{children:(0,n.jsx)(d.EditorToggle,{id:"image-editor-toggle",className:"slim tablet-compact",items:R,selected:R.findIndex(e=>e.view===c)})})),(0,n.jsxs)("div",Object.assign({className:"image-editor-header-right"},{children:[(0,n.jsxs)("div",Object.assign({className:"gallery-filter-button "+("gallery"===this.state.currentView?"":"hidden"),role:"button",onClick:this.toggleFilter,onKeyDown:h.fireClickOnEnter},{children:[(0,n.jsx)("div",Object.assign({className:"gallery-filter-button-icon"},{children:(0,n.jsx)("i",{className:"icon filter"})})),(0,n.jsx)("div",Object.assign({className:"gallery-filter-button-label"},{children:lf("Filter")}))]})),!T&&!k&&(0,n.jsx)("div",Object.assign({className:"image-editor-close-button",role:"button",onClick:this.onDoneClick},{children:(0,n.jsx)("i",{className:"ui icon close"})}))]}))]})),(0,n.jsxs)("div",Object.assign({className:"image-editor-gallery-window"},{children:[(0,n.jsxs)("div",Object.assign({className:"image-editor-gallery-content"},{children:[(0,n.jsx)(f.FocusTrapRegion,Object.assign({divRef:this.handleImageEditorRegionRef,className:"image-editor-region",enabled:"editor"===c},{children:"music"===this.props.editorType?(0,n.jsx)(p.MusicFieldEditor,{ref:"image-editor",onDoneClicked:this.onDoneClick,hideDoneButton:this.props.hideDoneButton}):"piano-roll"===this.props.editorType?(0,n.jsx)(m.PianoRollAssetEditor,{ref:"image-editor",onDoneClicked:this.onDoneClick,hideDoneButton:this.props.hideDoneButton,fieldEditorParams:this.state.options}):(0,n.jsx)(a.ImageEditor,{ref:"image-editor",singleFrame:this.props.singleFrame,onDoneClicked:this.onDoneClick,onTileEditorOpenClose:this.onTileEditorOpenClose,lightMode:this.lightMode,hideDoneButton:this.props.hideDoneButton,hideAssetName:!(null===(r=null===(o=pxt.appTarget)||void 0===o?void 0:o.appTheme)||void 0===r?void 0:r.assetEditor)})})),"song"===(null===(l=this.asset)||void 0===l?void 0:l.type)?(0,n.jsx)(_.SongGallery,{items:N,hidden:"editor"===c,onAssetSelected:this.onAssetSelected,onEscape:this.onEscapeFromGallery}):(0,n.jsx)(E,{items:N,hidden:"editor"===c,onAssetSelected:this.onAssetSelected,onEscape:this.onEscapeFromGallery})]})),(0,n.jsx)("div",Object.assign({className:"filter-panel-gutter "+(C?"":"hidden")},{children:(0,n.jsx)("div",Object.assign({className:"filter-panel-container"},{children:(0,n.jsx)(u.FilterPanel,{enabledTags:this.state.gallerySelectedTags,tagClickHandler:this.tagClickHandler,clearTags:this.clearFilterTags,tagOptions:w})}))}))]}))]}))}componentDidMount(){this.ref=this.refs["image-editor"],v("image-editor-shown")}componentWillUnmount(){v("image-editor-hidden"),this.galleryAssets=void 0,this.userAssets=void 0}init(e,t,i){switch(this.closeEditor=t,this.setState({options:i}),this.lightMode=i.lightMode,e.type){case"image":this.initSingleFrame(e,i);break;case"tile":i.disableResize=!0,this.initSingleFrame(e,i);break;case"animation":this.initAnimation(e,i);break;case"tilemap":this.initTilemap(e,i);break;case"song":this.ref.openAsset(e)}this.editID=e.id;let n=!1;if(i){this.blocksInfo=i.blocksInfo;const t="tilemap"===e.type?i.tilemapFilter:i.filter;t&&(this.setState({galleryFilter:t}),n=!0),null!=i.headerVisible&&(this.setState({headerVisible:i.headerVisible}),n=!0),null!=i.hideMyAssets&&(this.setState({hideMyAssets:i.hideMyAssets}),n=!0),null!=i.hideCloseButton&&(this.setState({hideCloseButton:i.hideCloseButton}),n=!0)}n||this.forceUpdate()}getValue(){return this.ref?this.ref.getAsset():null}getJres(){return this.ref?this.ref.getJres():""}getPersistentData(){return this.ref?this.ref.getPersistentData():null}restorePersistentData(e){var t,i;this.ref&&(this.ref.restorePersistentData(e),(null===(i=null===(t=this.state)||void 0===t?void 0:t.options)||void 0===i?void 0:i.disableResize)&&this.ref.disableResize())}onResize(){this.ref&&this.ref.onResize()}updateGalleryAssets(){this.galleryAssets=(0,r.getAssets)(!0,this.asset.type)}getAvailableTags(e,t){let i=[];return this.galleryAssets?(e.forEach(e=>{var n;null===(n=e.meta.tags)||void 0===n||n.forEach(e=>{const n=function(e){let t=0===e.indexOf("?")&&e.length>1?e.substring(1):e;return t=t.toLowerCase(),t}(e);t.indexOf(n)<0&&i.indexOf(n)<0&&i.push(n)})}),i):[]}filterAssetsByTag(e){return this.state.gallerySelectedTags.length>0&&this.state.filterOpen&&(e=e.filter(e=>{var t;return!!(null===(t=e.meta.tags)||void 0===t?void 0:t.find(e=>this.state.gallerySelectedTags.indexOf(e)>=0))})),e}filterAssetsByType(e,t,i=!1,n){var s,o,a,l;if(void 0===t&&(t=null===(s=this.asset)||void 0===s?void 0:s.type),void 0===t)return e;if(this.asset&&!i&&(e=e.map(e=>e.type!==this.asset.type||e.id!==this.asset.id?e:(0,r.assetToGalleryItem)(this.getValue())),this.state.editingTile)){const t=this.ref.getAsset();e=e.map(e=>{var i;return(null===(i=t.data.editedTiles)||void 0===i?void 0:i.indexOf(e.id))>=0?(0,r.assetToGalleryItem)(t.data.tileset.tiles.find(t=>t.id===e.id)):e})}if(n){e.forEach(e=>{var t,i,n,s;!e.meta.tags&&(null===(t=this.state)||void 0===t?void 0:t.options)&&(e.meta.tags=(null===(s=null===(n=null===(i=this.blocksInfo)||void 0===i?void 0:i.apis.byQName[e.id])||void 0===n?void 0:n.attributes.tags)||void 0===s?void 0:s.split(" "))||[])});const t=this.state.galleryFilter.split(" ").filter(e=>!!e).map(e=>e.toLowerCase()),i=t.filter(e=>0!==e.indexOf("!")),n=t.filter(e=>0===e.indexOf("!")&&e.length>1).map(e=>e.substring(1));e=e.filter(e=>function(e,t){const i=e.meta.tags?e.meta.tags:[];return t.every(e=>{const t=`?${e}`;return i.some(i=>i===e||i===t)})}(e,i)&&function(e,t){const i=e.meta.tags?e.meta.tags:[];return t.every(e=>!i.some(t=>t===e))}(e,n))}if(i)switch(t){case"animation":return e.filter(e=>"animation"===e.type||"tile"===e.type||"image"===e.type);case"image":return e.filter(e=>"tile"===e.type||"image"===e.type);case"tile":return e.filter(e=>"tile"===e.type);case"tilemap":const t=null===(l=null===(a=null===(o=this.asset)||void 0===o?void 0:o.data)||void 0===a?void 0:a.tileset)||void 0===l?void 0:l.tileWidth;return e.filter(e=>{var i,n;return"tilemap"===e.type&&(!t||(null===(n=null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.tileset)||void 0===n?void 0:n.tileWidth)===t)});case"song":return e.filter(e=>"song"===e.type);case"json":return e.filter(e=>"json"===e.type)}else switch(t){case"animation":return e.filter(e=>"animation"===e.type);case"image":return e.filter(e=>"image"===e.type);case"tile":return e.filter(e=>"tile"===e.type);case"tilemap":return e.filter(e=>"tilemap"===e.type);case"song":return e.filter(e=>"song"===e.type);case"json":return e.filter(e=>"json"===e.type)}}initSingleFrame(e,t){this.ref.openAsset(e),t.disableResize&&this.ref.disableResize()}initAnimation(e,t){this.ref.openAsset(e),t.disableResize&&this.ref.disableResize()}initTilemap(e,t){let i;(null==t?void 0:t.blocksInfo)&&(this.blocksInfo=t.blocksInfo,i=pxt.sprite.filterItems(pxt.sprite.getGalleryItems(this.blocksInfo,"Image"),["tile"]).map(e=>({bitmap:pxt.sprite.getBitmap(this.blocksInfo,e.qName).data(),tags:e.tags,qualifiedName:e.qName,tileWidth:16}))),(null==t?void 0:t.galleryTiles)&&(i=t.galleryTiles.map(e=>({bitmap:e.bitmap,tags:e.tags,qualifiedName:e.qName,tileWidth:16}))),this.ref.openAsset(e,i)}loadJres(e){this.ref&&this.ref.loadJres(e)}setImageEditorShortcutsEnabled(e){e&&this.shortcutLock?((0,l.releaseShortcutLock)(this.shortcutLock),this.shortcutLock=void 0):e||this.shortcutLock||(this.shortcutLock=(0,l.obtainShortcutLock)())}isSongEditor(){return"music"===this.props.editorType||"piano-roll"===this.props.editorType}}i.ImageFieldEditor=T;class E extends s.Component{constructor(){super(...arguments),this.clickHandler=e=>{this.props.onAssetSelected(e)}}render(){let{items:e,hidden:t,onEscape:i}=this.props;return(0,n.jsx)(f.FocusTrapRegion,Object.assign({className:(0,g.classList)("image-editor-gallery",e&&!t&&"visible"),enabled:!t,onEscape:i},{children:!t&&(null==e?void 0:e.map((e,t)=>(0,n.jsx)(o.AssetCardView,{asset:e,selected:!1,onClick:this.clickHandler},t)))}))}}s.Component;function v(e){pxt.tickEvent("image.editor",{action:e})}},{"../../../react-common/components/controls/EditorToggle":163,"../../../react-common/components/controls/FocusTrap":167,"../../../react-common/components/util":171,"../assets":174,"../util":240,"./FilterPanel":175,"./ImageEditor/ImageEditor":180,"./ImageEditor/keyboardShortcuts":189,"./ImageEditor/store/imageReducer":191,"./MusicFieldEditor":198,"./PianoRollFieldEditor":199,"./SongGallery":200,"./assetEditor/assetCard":203,"./musicEditor/playback":219,react:304,"react/jsx-runtime":305}],198:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MusicFieldEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./musicEditor/AssetModel"),r=e("./musicEditor/MusicEditor");class a extends s.Component{constructor(e){super(e),this.onAssetNameChanged=e=>{var t;const i=null===(t=this.state.model)||void 0===t?void 0:t.getCurrentValue();i&&(i.meta.displayName=e,this.state.model.updateValue(i))},this.state={}}render(){const{onDoneClicked:e}=this.props,{model:t}=this.state;return(0,n.jsx)("div",Object.assign({className:"music-field-editor"},{children:t&&(0,n.jsx)(r.MusicEditor,{model:t,onAssetNameChanged:this.onAssetNameChanged,onDoneClicked:e,hideDoneButton:this.props.hideDoneButton})}))}getAsset(){var e;return(null===(e=this.state.model)||void 0===e?void 0:e.getCurrentValue())||this.openedAsset}openAsset(e){pxt.assets.music.inflateSong(e.song),this.openedAsset=e,this.state.model?this.state.model.updateValue(e):this.setState({model:new o.SongModel(e)})}openGalleryAsset(e){const t=pxt.cloneAsset(e);pxt.assets.music.inflateSong(t.song),this.state.model.updateValue(t)}getJres(){return""}loadJres(e){}disableResize(){}onResize(){}getPersistentData(){if(this.state.model)return this.state.model.getState()}restorePersistentData(e){if(e){let t=this.state.model;t||(t=new o.SongModel,this.setState({model:t})),t.restoreState(e)}}}i.MusicFieldEditor=a},{"./musicEditor/AssetModel":206,"./musicEditor/MusicEditor":208,react:304,"react/jsx-runtime":305}],199:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoRollAssetEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./pianoRoll/PianoRoll"),r=e("./pianoRoll/types");class a extends s.Component{constructor(e){super(e),this.state={}}render(){const{fieldEditorParams:e,onDoneClicked:t}=this.props,{model:i}=this.state;return(0,n.jsx)(n.Fragment,{children:i&&(0,n.jsx)(o.PianoRoll,{model:i,onDoneClicked:t,fieldEditorParams:e,showEditControls:!0})})}getAsset(){var e,t;if(this.state.model){const{song:i,assetName:n}=this.state.model.getCurrentValue(),s=(0,r.toPXTSong)(i),o=Object.assign(Object.assign({},this.openedAsset),{song:s});return((null===(e=this.openedAsset)||void 0===e?void 0:e.meta)||n)&&(o.meta=Object.assign(Object.assign({},(null===(t=this.openedAsset)||void 0===t?void 0:t.meta)||{}),{displayName:n})),o}return this.openedAsset}openAsset(e){var t;this.openedAsset=e;const i={song:(0,r.fromPXTSong)(e.song),assetName:null===(t=e.meta)||void 0===t?void 0:t.displayName,selectedTrackIndex:0};this.state.model?this.state.model.updateValue(i,{preserveUndo:!1}):this.setState({model:new o.PianoRollModel(i)})}openGalleryAsset(e){const t=pxt.cloneAsset(e);pxt.assets.music.inflateSong(t.song);const i=(0,r.fromPXTSong)(t.song);for(let e=0;e<i.tracks.length;e++){i.tracks[e].id=e+1}const n=this.state.model.getCurrentValue();this.state.model.updateValue(Object.assign(Object.assign({},n),{song:i,selectedTrackIndex:0}),{preserveUndo:!0,pushUndo:!0})}getJres(){return""}loadJres(e){}disableResize(){}onResize(){}getPersistentData(){var e;return null===(e=this.state.model)||void 0===e?void 0:e.getState()}restorePersistentData(e){if(e){let t=this.state.model;t||(t=new o.PianoRollModel,this.setState({model:t})),t.restoreState(e)}}}i.PianoRollAssetEditor=a},{"./pianoRoll/PianoRoll":230,"./pianoRoll/types":237,react:304,"react/jsx-runtime":305}],200:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SongGallery=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../pxtblocks"),r=e("../../../react-common/components/controls/Button"),a=e("../../../react-common/components/controls/FocusTrap"),l=e("../../../react-common/components/util"),c=e("./musicEditor/playback");i.SongGallery=e=>{const{items:t,hidden:i,onAssetSelected:o,onEscape:r}=e,[h,d]=(0,s.useState)(null);(0,s.useEffect)(()=>{const e=e=>{"stop"===e&&d(null)};return(0,c.addPlaybackStateListener)(e),()=>{(0,c.removePlaybackStateListener)(e)}},[]);const p=e=>{h===e?((0,c.stopPlayback)(),d(null)):((0,c.startPlaybackAsync)(e,!1),d(e))};return(0,n.jsx)(a.FocusTrapRegion,Object.assign({className:(0,l.classList)("image-editor-gallery song",t&&!i&&"visible"),enabled:!i,onEscape:r},{children:!i&&(null==t?void 0:t.map((e,t)=>(0,n.jsx)(u,{asset:e,selected:!1,isPlaying:h===e.song,onPlayClick:p,onClick:()=>o(e)},e.id)))}))};const u=e=>{var t;const{asset:i,selected:a,isPlaying:c,onClick:u,onPlayClick:h}=e,d=i.song,p=(0,s.useMemo)(()=>(0,o.songToDataURI)(i.song,100,32,!1),[i.id]),g=!!i.meta.temporaryInfo?lf("{id:song}Untitled"):(null===(t=i.meta)||void 0===t?void 0:t.displayName)||i.id.split(".").pop()||i.id;return(0,n.jsxs)("div",Object.assign({className:(0,l.classList)("song-gallery-item",a&&"selected")},{children:[(0,n.jsx)(r.Button,{className:"song-gallery-item-button",title:lf("Select {0}",g),label:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",Object.assign({className:"song-gallery-item-name"},{children:g})),(0,n.jsx)("div",Object.assign({className:"song-gallery-item-preview"},{children:(0,n.jsx)("img",{src:p,alt:lf("Preview of {0}",g)})}))]}),onClick:u}),(0,n.jsx)(r.Button,{className:"play-button",leftIcon:(0,l.classList)("fas",c?"fa-stop":"fa-play"),title:c?lf("Stop"):lf("Play"),onClick:()=>{h(d)}})]}))}},{"../../../pxtblocks":76,"../../../react-common/components/controls/Button":159,"../../../react-common/components/controls/FocusTrap":167,"../../../react-common/components/util":171,"./musicEditor/playback":219,react:304,"react/jsx-runtime":305}],201:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.dispatchUpdateGalleryAssets=i.dispatchUpdateUserAssets=i.dispatchChangeGalleryView=i.dispatchChangeSelectedAsset=void 0;const n=e("./types");i.dispatchChangeSelectedAsset=(e,t)=>({type:n.CHANGE_SELECTED_ASSET,assetType:e,assetId:t});i.dispatchChangeGalleryView=(e,t,i)=>({type:n.CHANGE_GALLERY_VIEW,view:e,assetType:t,assetId:i});i.dispatchUpdateUserAssets=()=>({type:n.UPDATE_USER_ASSETS});i.dispatchUpdateGalleryAssets=()=>({type:n.UPDATE_GALLERY_ASSETS})},{"./types":202}],202:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.UPDATE_GALLERY_ASSETS=i.UPDATE_USER_ASSETS=i.CHANGE_GALLERY_VIEW=i.CHANGE_SELECTED_ASSET=void 0,i.CHANGE_SELECTED_ASSET="CHANGE_SELECTED_ASSET",i.CHANGE_GALLERY_VIEW="CHANGE_GALLERY_VIEW",i.UPDATE_USER_ASSETS="UPDATE_USER_ASSETS",i.UPDATE_GALLERY_ASSETS="UPDATE_GALLERY_ASSETS"},{}],203:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetCard=i.AssetCardView=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/assetEditorReducerState"),a=e("./actions/dispatch"),l=e("./assetPreview"),c=e("../../util"),u=e("../../assets");class h extends s.Component{constructor(){super(...arguments),this.clickHandler=()=>{const{type:e,id:t}=this.props.asset;this.props.dispatchChangeSelectedAsset(e,t)}}render(){const{asset:e,selected:t}=this.props;return(0,n.jsx)(d,{asset:e,selected:t,onClick:this.clickHandler})}}class d extends s.Component{constructor(){super(...arguments),this.clickHandler=()=>{this.props.onClick(this.props.asset)}}render(){var e,t;const{asset:i,selected:s}=this.props,o=(0,r.isGalleryAsset)(i),a=(0,u.getIconClassForAssetType)(i.type),h=a||!(null===(e=i.meta)||void 0===e?void 0:e.displayName);return(0,n.jsxs)("div",Object.assign({className:"asset-editor-card "+(s?"selected":""),onClick:this.clickHandler,role:"listitem",tabIndex:0,onKeyDown:c.fireClickOnEnter},{children:[(0,n.jsx)(l.AssetPreview,{asset:i}),h&&(0,n.jsxs)("div",Object.assign({className:"asset-editor-card-label"},{children:[a&&(0,n.jsx)("div",Object.assign({className:"asset-editor-card-icon"},{children:(0,n.jsx)("i",{className:`icon ${a}`})})),!(null===(t=i.meta)||void 0===t?void 0:t.displayName)&&!o&&(0,n.jsx)("div",Object.assign({className:"asset-editor-card-icon warning"},{children:(0,n.jsx)("i",{className:"icon exclamation triangle"})}))]}))]}))}}i.AssetCardView=d;const p={dispatchChangeSelectedAsset:a.dispatchChangeSelectedAsset};i.AssetCard=(0,o.connect)(function(e,t){return e?{selected:e.selectedAsset&&t.asset.id==e.selectedAsset.id}:{}},p)(h)},{"../../assets":174,"../../util":240,"./actions/dispatch":201,"./assetPreview":204,"./store/assetEditorReducerState":205,react:304,"react-redux":287,"react/jsx-runtime":305}],204:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetPreview=void 0;const n=e("react/jsx-runtime"),s=e("react");i.AssetPreview=e=>{const{asset:t}=e,i=t.meta.displayName||(t.meta.temporaryInfo?lf("Temporary Asset"):t.id);return(0,n.jsx)("div",Object.assign({className:"asset-editor-preview",title:i},{children:"json"===t.type?(0,n.jsx)(r,Object.assign({},e)):(0,n.jsx)(o,Object.assign({},e))}))};const o=e=>{var t;const{asset:i}=e,o=s.useRef(null),r="animation"===i.type&&(null===(t=i.framePreviewURIs)||void 0===t?void 0:t.length)>1;return s.useEffect(()=>{if(!r||!o.current)return;let e,t=0;const n=()=>{e=setInterval(()=>{o.current&&(o.current.src=i.framePreviewURIs[t]),t=(t+1)%i.framePreviewURIs.length},Math.max(i.interval,100))},s=()=>{clearInterval(e)};return o.current.addEventListener("mouseenter",n),o.current.addEventListener("mouseleave",s),()=>{var t,i;e&&clearInterval(e),null===(t=o.current)||void 0===t||t.removeEventListener("mouseenter",n),null===(i=o.current)||void 0===i||i.removeEventListener("mouseleave",s)}},[i,r]),(0,n.jsx)("img",{src:i.previewURI,alt:lf("A preview of your asset (eg image, tile, animation)"),ref:o,loading:"lazy"})},r=e=>{const{asset:t}=e,i=t.meta.displayName||lf("Untitled");return(0,n.jsx)("div",Object.assign({className:"json-asset-preview"},{children:(0,n.jsx)("div",{children:i})}))}},{react:304,"react/jsx-runtime":305}],205:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isGalleryAsset=i.GalleryView=void 0,function(e){e[e.User=0]="User",e[e.Gallery=1]="Gallery"}(i.GalleryView||(i.GalleryView={})),i.isGalleryAsset=function(e){var t;return!!((null==e?void 0:e.id.startsWith("sprites."))||(null===(t=null==e?void 0:e.meta)||void 0===t?void 0:t.package)&&"this"!==e.meta.package)}},{}],206:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useModelValue=i.SongModel=i.AssetModel=void 0;const n=e("react");class s{constructor(e){this.undoStack=[],this.redoStack=[],this.listeners=[],void 0!==e&&(this.currentValue=this.cloneValue(e))}addChangeListener(e){this.listeners.push(e)}removeChangeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}notifyChange(){this.listeners.forEach(e=>e())}updateValue(e,t={}){const{preserveUndo:i=!0,pushUndo:n=!0}=t;i?n&&void 0!==this.currentValue&&this.undoStack.push(this.currentValue):this.undoStack=[],this.redoStack=[],this.currentValue=this.cloneValue(e),this.notifyChange()}updateExtraState(e){this.extraState=this.cloneExtraState(e),this.notifyChange()}undo(){this.undoStack.length>0&&(this.redoStack.push(this.currentValue),this.currentValue=this.undoStack.pop(),this.notifyChange())}redo(){this.redoStack.length>0&&(this.undoStack.push(this.currentValue),this.currentValue=this.redoStack.pop(),this.notifyChange())}getCurrentValue(){return this.cloneValue(this.currentValue)}getExtraState(){return this.cloneExtraState(this.extraState)}getState(){return{currentValue:this.cloneValue(this.currentValue),undoStack:this.undoStack.map(e=>this.cloneValue(e)),redoStack:this.redoStack.map(e=>this.cloneValue(e)),extraState:this.cloneExtraState(this.extraState)}}restoreState(e,t={}){t.overwriteValue&&(this.currentValue=this.cloneValue(e.currentValue)),t.includeRedoStack&&(this.redoStack=e.redoStack.map(e=>this.cloneValue(e))),this.undoStack=e.undoStack.map(e=>this.cloneValue(e)),this.extraState=this.cloneExtraState(e.extraState),this.notifyChange()}hasUndo(){return this.undoStack.length>0}hasRedo(){return this.redoStack.length>0}}i.AssetModel=s;i.SongModel=class extends s{cloneValue(e){return pxt.cloneAsset(e)}cloneExtraState(e){return e}};i.useModelValue=e=>{const[t,i]=n.useState(e.getCurrentValue());return n.useEffect(()=>{const t=()=>{i(e.getCurrentValue())};return e.addChangeListener(t),()=>{e.removeChangeListener(t)}},[e]),{value:t,hasUndo:e.hasUndo(),hasRedo:e.hasRedo(),extraState:e.getExtraState()}}},{react:304}],207:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.EditControls=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=e("../../../../react-common/components/controls/Input"),a=e("../../assets");i.EditControls=e=>{var t;const{onAssetNameChanged:i,onDoneClicked:l,assetName:c,hideDoneButton:u}=e,[h,d]=s.useState(),[p,g]=s.useState(),f=e=>{let t=null;const n=e.trim();if(!n)return d(void 0),void g(void 0);pxt.validateAssetName(n)?(0,a.isNameTaken)(n)&&n!==c&&(t=lf("This name is already used elsewhere in your project")):t=lf("Names may only contain letters, numbers, '-', '_', and space"),t?(d(n),g(t)):(i(n),d(void 0),g(void 0))},m=!!(null===(t=pxt.appTarget)||void 0===t?void 0:t.appTheme.assetEditor);return(0,n.jsxs)("div",Object.assign({className:"music-editor-edit-controls"},{children:[p&&(0,n.jsx)("div",Object.assign({className:"music-editor-name-error"},{children:p})),m&&(0,n.jsx)(r.Input,{placeholder:lf("Asset Name"),initialValue:c||h,onBlur:f,onEnterKey:f}),!u&&(0,n.jsx)(o.Button,{className:"green",title:lf("Done"),label:lf("Done"),onClick:l})]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Input":168,"../../assets":174,react:304,"react/jsx-runtime":305}],208:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MusicEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./AssetModel"),r=e("./EditControls"),a=e("./keyboardNavigation"),l=e("./playback"),c=e("./PlaybackControls"),u=e("./ScrollableWorkspace"),h=e("./TrackSelector"),d=e("./utils");i.MusicEditor=e=>{const{model:t,onAssetNameChanged:i,onDoneClicked:p,hideDoneButton:g}=e,{value:f,hasUndo:m,hasRedo:_}=(0,o.useModelValue)(t),b=f.song,[T,E]=s.useState(0),[v,y]=s.useState("1/8"),[k,C]=s.useState(!1),[I,S]=s.useState(!1),[A,O]=s.useState(),[w,N]=s.useState(),[R,x]=s.useState(!1),[L,D]=s.useState((0,d.doesSongUseBassClef)(b));s.useEffect(()=>()=>{(0,l.stopPlayback)()},[]),s.useEffect(()=>{const e=e=>{A&&(e.preventDefault(),e.stopPropagation(),e.clipboardData.setData("application/makecode-song",JSON.stringify(A)))},t=e=>{if(A){e.preventDefault(),e.stopPropagation(),e.clipboardData.setData("application/makecode-song",JSON.stringify(A));const t=(0,d.applySelection)(A,I?T:void 0);F((0,d.deleteSelectedNotes)(t),!0)}},i=e=>{const t=e.clipboardData.getData("application/makecode-song");if(t){const e=JSON.parse(t);let i;i=A?{originalSong:(0,d.unselectAllNotes)((0,d.applySelection)(A,I?T:void 0)),pastedContent:e,startTick:A.startTick,endTick:A.startTick+(e.endTick-e.startTick),deltaTick:0,transpose:0}:{originalSong:b,pastedContent:e,startTick:0,endTick:e.endTick-e.startTick,deltaTick:0,transpose:0},F((0,d.applySelection)(i,I?T:void 0),!1),O(i)}};return document.addEventListener("copy",e),document.addEventListener("cut",t),document.addEventListener("paste",i),()=>{document.removeEventListener("copy",e),document.removeEventListener("cut",t),document.removeEventListener("paste",i)}},[A,I,b]);const M=s.useRef(),B=k?1:function(e,t){switch(e){case"1/4":return t;case"1/8":return t/2;case"1/16":return t/4;case"1/32":return t/8}}(v,b.ticksPerBeat),P=!!b.tracks[T].drums,F=(e,i)=>{(0,l.isPlaying)()&&(0,l.updatePlaybackSongAsync)(e);const n=t.getCurrentValue();t.updateValue(Object.assign(Object.assign({},n),{song:e}),{preserveUndo:!0,pushUndo:i}),M.current&&(M.current.editing=e)},U=()=>{var e,t;let i;return O(void 0),"move"===(null===(e=null==M?void 0:M.current)||void 0===e?void 0:e.dragType)?i=(0,d.unselectAllNotes)(M.current.editing):(0,d.findSelectedRange)(b)&&(i=(0,d.unselectAllNotes)(b)),i&&(F(i,!0),"move"===(null===(t=null==M?void 0:M.current)||void 0===t?void 0:t.dragType)&&(M.current=void 0)),i},H=e=>{N(w?Object.assign(Object.assign({},w),{tick:e}):{tick:e,gridTicks:B,track:T,bassClef:!1,hideTracksActive:I,selection:A})};return(0,n.jsxs)("div",Object.assign({className:"music-editor"},{children:[(0,n.jsx)(h.TrackSelector,{song:b,selected:T,onTrackSelected:e=>{U(),x(!1);const t=b.tracks[e];t.drums?pxsim.music.playDrumAsync(t.drums[0]):pxsim.music.playNoteAsync((0,d.rowToNote)(t.instrument.octave,6,!1,!!t.drums).note,t.instrument,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,b.ticksPerBeat/2)),E(e),w&&N(Object.assign(Object.assign({},w),{track:e})),k&&C(!1)},eraserActive:k,onEraserClick:()=>{U(),x(!1),C(!k)},hideTracksActive:I,onHideTracksClick:()=>{U(),x(!1),S(!I)},selectedResolution:v,onResolutionSelected:y}),(0,n.jsx)(u.ScrollableWorkspace,{song:b,selectedTrack:T,eraserActive:k,onWorkspaceClick:(e,t)=>{x(!1);const i=b.tracks[T],n=i.instrument,s=(0,d.findPreviousNoteEvent)(b,T,e.tick),o=(0,d.findPreviousNoteEvent)(b,T,e.exactTick);U(),H(e.tick);const r=t=>(0,d.isBassClefNote)(n.octave,t,P)===e.isBassClef&&(0,d.noteToRow)(n.octave,t,P)===e.row;let a,l;if((null==o?void 0:o.startTick)===e.exactTick&&o.notes.some(r)?(a=e.exactTick,l=o):(null==s?void 0:s.startTick)===e.tick&&s.notes.some(r)&&(a=e.tick,l=s),l){const i=(0,d.unselectAllNotes)(b);if(t&&!P){const t=l.notes.find(r),s=12*n.octave-20,o=12*n.octave+20,c=(0,d.removeNoteAtRowFromTrack)(i,T,e.row,e.isBassClef,a);let u;u="normal"===t.enharmonicSpelling&&t.note<o?"sharp":"sharp"===t.enharmonicSpelling&&t.note>s||t.note===o?"flat":"normal";const h=(0,d.rowToNote)(n.octave,e.row,e.isBassClef,P,u);F((0,d.addNoteToTrack)(c,T,h,l.startTick,l.endTick),!0),pxsim.music.playNoteAsync(h.note,n,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,l.endTick-l.startTick))}else F((0,d.removeNoteAtRowFromTrack)(i,T,e.row,e.isBassClef,a),!0)}else{if(k){let t=b,i=!1;for(let n=0;n<b.tracks.length;n++){if(I&&n!==T)continue;const s=b.tracks[n],o=s.instrument,r=!!s.drums,a=t=>(0,d.isBassClefNote)(o.octave,t,r)===e.isBassClef&&(0,d.noteToRow)(o.octave,t,r)===e.row;for(const s of(0,d.findNoteEventsOverlappingRange)(b,n,e.exactTick-1,e.exactTick+1))s.notes.some(a)&&(t=(0,d.removeNoteAtRowFromTrack)(t,n,e.row,e.isBassClef,s.startTick),i=!0)}return void(i&&F(t,!1))}{const t=(0,d.rowToNote)(n.octave,e.row,e.isBassClef,P),s=b.beatsPerMeasure*b.ticksPerBeat*b.measures;if(e.tick===s)return;const o=P?1:B;F((0,d.unselectAllNotes)((0,d.addNoteToTrack)(b,T,t,e.tick,e.tick+o)),!0),P?pxsim.music.playDrumAsync(i.drums[t.note]):pxsim.music.playNoteAsync(t.note,n,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,B))}}},onWorkspaceDragStart:()=>{if(x(!1),M.current)return M.current.editing=b,M.current.original=b,void(M.current.selectionAtDragStart=A&&Object.assign({},A));M.current={editing:b,original:b,selectionAtDragStart:A&&Object.assign({},A)}},onWorkspaceDragEnd:()=>{if("move"===M.current.dragType){const e=M.current.dragEnd.tick-M.current.dragStart.tick,t=M.current.dragEnd.row-(M.current.dragEnd.isBassClef?12:0)-(M.current.dragStart.row-(M.current.dragStart.isBassClef?12:0));return O(Object.assign(Object.assign({},M.current.selectionAtDragStart),{deltaTick:M.current.selectionAtDragStart.deltaTick+e,transpose:M.current.selectionAtDragStart.transpose+t})),M.current.dragStart=void 0,M.current.dragEnd=void 0,void(M.current.selectionAtDragStart=void 0)}if("note-length"===M.current.dragType&&U(),pxt.assets.music.songEquals(M.current.editing,M.current.original)||F(M.current.editing,!0),"marquee"===M.current.dragType){const e=(0,d.findSelectedRange)(M.current.editing,B);O(e?{startTick:e.start,endTick:e.end,deltaTick:0,transpose:0,originalSong:M.current.editing}:void 0)}M.current=void 0},onWorkspaceDrag:(e,t)=>{if(H(t.tick),k){if(t.row>11||t.row<0)return;const e=M.current.dragEnd||t;M.current.dragEnd=t;let i=b,n=!1;const s=11-e.row+(e.isBassClef?12:0),o=11-t.row+(t.isBassClef?12:0);return pxt.Util.bresenhamLine(e.tick,s,t.tick,o,(e,t)=>{const s={tick:e,exactTick:e,isBassClef:t>=12,row:11-t%12};for(let e=0;e<b.tracks.length;e++){if(I&&e!==T)continue;const t=b.tracks[e],o=t.instrument,r=!!t.drums,a=e=>(0,d.isBassClefNote)(o.octave,e,r)===s.isBassClef&&(0,d.noteToRow)(o.octave,e,r)===s.row;for(const t of(0,d.findNoteEventsOverlappingRange)(b,e,s.exactTick-1,s.exactTick+1))t.notes.some(a)&&(i=(0,d.removeNoteAtRowFromTrack)(i,e,s.row,s.isBassClef,t.startTick),n=!0)}}),void(n&&F(i,!1))}if(M.current.dragType=void 0,M.current.dragStart=e,M.current.dragEnd=t,M.current.original.tracks[T].drums)return void F((0,d.fillDrums)(M.current.original,T,e.row,e.isBassClef,e.tick,t.tick,B),!1);if(M.current.selectionAtDragStart){const i=(0,d.findNoteEventAtPosition)(M.current.original,e,I?T:void 0);if(null==i?void 0:i.selected){M.current.dragType="move";const i=t.tick-e.tick,n=t.row-(t.isBassClef?12:0)-(e.row-(e.isBassClef?12:0)),s=Object.assign(Object.assign({},M.current.selectionAtDragStart),{deltaTick:i+M.current.selectionAtDragStart.deltaTick,transpose:n+M.current.selectionAtDragStart.transpose}),o=(0,d.applySelection)(s,I?T:void 0);return F(o,!1),void O(s)}}const i=(0,d.findPreviousNoteEvent)(M.current.original,T,e.exactTick);if(!P&&i&&e.exactTick>=i.startTick&&e.exactTick<i.endTick){let n=!1;for(const t of i.notes)if((0,d.noteToRow)(b.tracks[T].instrument.octave,t,!1)===e.row){n=!0;break}if(n){if(t.tick<i.startTick+1)return;return O(void 0),M.current.dragType="note-length",void F((0,d.editNoteEventLength)(M.current.original,T,i.startTick,t.tick),!1)}}O({startTick:e.tick,endTick:t.tick,deltaTick:0,transpose:0,originalSong:M.current.editing}),F((0,d.selectNoteEventsInRange)(M.current.original,e.tick,t.tick,I?T:void 0),!1),M.current.dragType="marquee"},gridTicks:B,hideUnselectedTracks:I,showBassClef:L,selection:A,cursor:R?w:void 0,onKeydown:e=>{x(!0);let t=w;t||(t={tick:0,gridTicks:B,track:T,bassClef:!1,hideTracksActive:I,selection:A}),t.gridTicks=B,t.track=T,t.selection=A,t.hideTracksActive=I;const[i,n]=(0,a.handleKeyboardEvent)(b,t,e);pxt.assets.music.songEquals(i,b)||F(i,!n.selection),n.selection?O(n.selection):O(void 0),N(n)}}),(0,n.jsx)(c.PlaybackControls,{beatsPerMinute:b.beatsPerMinute,measures:b.measures,onControlsClick:e=>{"play"===e?(0,l.startPlaybackAsync)(b,!1,0):"loop"===e?(0,l.startPlaybackAsync)(b,!0,0):(0,l.stopPlayback)()},onTempoChange:e=>{U(),x(!1),F(Object.assign(Object.assign({},b),{beatsPerMinute:e}),!0)},onMeasuresChanged:e=>{U(),x(!1),F((0,d.changeSongLength)(b,e),!0)},onUndoClick:()=>{t.undo()},onRedoClick:()=>{t.redo()},showBassClef:L,onBassClefCheckboxClick:D,hasUndo:m,hasRedo:_}),(0,n.jsx)(r.EditControls,{assetName:f.meta.displayName,onAssetNameChanged:i,onDoneClicked:p,hideDoneButton:g})]}))}},{"./AssetModel":206,"./EditControls":207,"./PlaybackControls":211,"./ScrollableWorkspace":212,"./TrackSelector":215,"./keyboardNavigation":218,"./playback":219,"./utils":221,react:304,"react/jsx-runtime":305}],209:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Note=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/util"),o=e("./svgConstants"),r=e("./utils");i.Note=e=>{const{row:t,iconURI:i,length:a,opacity:l,enharmonicSpelling:c,isBassClef:u,selected:h,cursorHighlighted:d}=e;return(0,n.jsxs)("g",Object.assign({className:(0,s.classList)("music-staff-note",h&&"selected",d&&"cursor-highlighted"),transform:`translate(${-o.NOTE_ICON_WIDTH/2}, ${(0,o.rowY)(t,u)-o.NOTE_ICON_WIDTH/2})`},{children:[0===t&&(0,n.jsx)("line",{className:"music-staff-row",x1:-o.NOTE_ICON_WIDTH/2,y1:o.NOTE_ICON_WIDTH/2,x2:3*o.NOTE_ICON_WIDTH/2,y2:o.NOTE_ICON_WIDTH/2,opacity:l}),!!a&&(0,n.jsx)("rect",{x:o.NOTE_ICON_WIDTH/2,y:o.NOTE_ICON_WIDTH/2-o.NOTE_DURATION_HEIGHT/2,width:a,height:o.NOTE_DURATION_HEIGHT}),(0,n.jsx)("image",Object.assign({x:0,y:0,width:o.NOTE_ICON_WIDTH,height:o.NOTE_ICON_WIDTH,href:(0,r.resolveImageURL)(i),opacity:l},{children:(0,n.jsx)("animate",{attributeName:"y",values:"0;-7;-10;-7;0",dur:"0.25s",repeatCount:"1",begin:"indefinite"})})),c&&"normal"!==c&&(0,n.jsx)("text",Object.assign({x:o.NOTE_ICON_WIDTH,y:0,fontSize:o.NOTE_ICON_WIDTH/2},{children:"sharp"===c?"♯":"♭"}))]}))}},{"../../../../react-common/components/util":171,"./svgConstants":220,"./utils":221,"react/jsx-runtime":305}],210:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.NoteGroup=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./Note"),r=e("./playback"),a=e("./svgConstants"),l=e("./utils");i.NoteGroup=e=>{const{song:t,noteEvent:i,octave:c,iconURI:u,isDrumTrack:h,cursor:d}=e;let p;const g="music-note-playing";s.useEffect(()=>{let e=!1;const t=t=>{if(t>=i.startTick&&t<i.endTick){if(!e){e=!0,p.classList.add(g);const t=p.querySelectorAll("animate");for(let e=0;e<t.length;e++)t.item(e).beginElement()}}else e&&(e=!1,p.classList.remove(g))},n=()=>{e&&(e=!1,p.classList.remove(g))};return(0,r.addTickListener)(t),(0,r.addPlaybackStateListener)(n),()=>{(0,r.removeTickListener)(t),(0,r.removePlaybackStateListener)(n),p.classList.remove(g)}},[i]);const f=(0,a.tickToX)(t.ticksPerBeat,i.startTick),m=h?0:(0,a.tickToX)(t.ticksPerBeat,i.endTick)-f,_=(null==d?void 0:d.tick)===i.startTick;return(0,n.jsx)("g",Object.assign({className:"music-staff-note-group",transform:`translate(${f}, 0)`,ref:e=>{e&&(p=e)}},{children:i.notes.map((e,t)=>{const s=(0,l.isBassClefNote)(c,e,h),r=(0,l.noteToRow)(c,e,h);return(0,n.jsx)(o.Note,{isBassClef:s,row:r,enharmonicSpelling:e.enharmonicSpelling,iconURI:u,length:m,selected:i.selected,cursorHighlighted:_&&d.noteGroupIndex===t},t)})}))}},{"./Note":209,"./playback":219,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],211:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PlaybackControls=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=e("../../../../react-common/components/controls/Checkbox"),a=e("../../../../react-common/components/controls/Input"),l=e("../../../../react-common/components/util"),c=e("./playback");function u(e,t){if(!e)return e;const i=parseFloat(e);return isNaN(i)?t:Math.min(500,Math.max(20,Math.floor(i))).toString()}function h(e,t){if(!e)return e;const i=parseInt(e);return isNaN(i)?t:Math.max(1,Math.min(i,50)).toString()}i.PlaybackControls=e=>{const{measures:t,beatsPerMinute:i,onControlsClick:d,onTempoChange:p,onMeasuresChanged:g,onUndoClick:f,onRedoClick:m,hasUndo:_,hasRedo:b,showBassClef:T,hideBassClefOption:E,onBassClefCheckboxClick:v,singlePlayButton:y}=e,[k,C]=s.useState("stop");s.useEffect(()=>{const e=e=>{C(e)};return(0,c.addPlaybackStateListener)(e),()=>(0,c.removePlaybackStateListener)(e)},[]);const I=()=>{d("stop"),C("stop")},S=()=>{(0,c.isLooping)()||((0,c.isPlaying)()?(0,c.setLooping)(!0):d("loop"),C("loop"))},A=e=>{let t=parseFloat(e);Number.isNaN(t)||(t=Math.min(500,Math.max(20,Math.floor(t))),p(t))},O=e=>{let t=parseInt(e);isNaN(t)||t<1||t>50||g(t)};return(0,n.jsxs)("div",Object.assign({className:"music-playback-controls"},{children:[(0,n.jsxs)("div",Object.assign({className:"music-playback-buttons"},{children:[!y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(o.Button,{className:"square-button",title:lf("Stop"),leftIcon:"fas fa-stop",onClick:I}),(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","play"===k&&"green"),title:lf("Play"),leftIcon:"fas fa-play",onClick:()=>{d("play"),C("play")}}),(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","loop"===k&&"green"),title:lf("Loop"),leftIcon:"fas fa-retweet",onClick:S})]}),y&&(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","stop"!==k&&"green"),title:lf("Play"),leftIcon:"stop"===k?"fas fa-play":"fas fa-stop",onClick:"stop"===k?S:I})]})),(0,n.jsx)(a.Input,{id:"music-playback-tempo-input music-editor-label",label:lf("Tempo:"),initialValue:i.toString(),onBlur:A,onEnterKey:A,validator:u}),(0,n.jsx)("div",{className:"spacer"}),!E&&(0,n.jsx)(r.Checkbox,{className:"music-editor-label",id:"show-bass-clef",label:lf("Show bass clef"),isChecked:T,onChange:v}),(0,n.jsxs)("div",Object.assign({className:"music-undo-redo common-button-group"},{children:[(0,n.jsx)(o.Button,{className:"square-button purple",title:lf("Undo"),leftIcon:"xicon undo",disabled:!_,onClick:f}),(0,n.jsx)(o.Button,{className:"square-button purple",title:lf("Redo"),leftIcon:"xicon redo",disabled:!b,onClick:m})]})),(0,n.jsxs)("div",Object.assign({className:"music-playback-measures"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:lf("Measures:")})),(0,n.jsx)(o.Button,{className:"menu-button",title:lf("Remove measure"),leftIcon:"fas fa-minus-circle",onClick:()=>{t>1&&g(t-1)}}),(0,n.jsx)(a.Input,{id:"music-playback-measures-input",initialValue:t.toString(),onBlur:O,onEnterKey:O,validator:h}),(0,n.jsx)(o.Button,{className:"menu-button",title:lf("Add measure"),leftIcon:"fas fa-plus-circle",onClick:()=>{t<50&&g(t+1)}})]}))]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Input":168,"../../../../react-common/components/util":171,"./playback":219,react:304,"react/jsx-runtime":305}],212:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ScrollableWorkspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./svgConstants"),r=e("./utils"),a=e("./Workspace");i.ScrollableWorkspace=e=>{const{cursor:t,song:i}=e,l=s.useRef(null);return s.useEffect(()=>{if(!t)return;const e=(0,o.tickToX)(i.ticksPerBeat,t.tick),n=l.current.querySelector("svg"),s=e=>{const t=n.createSVGPoint();return t.x=e,t.y=0,t.matrixTransform(n.getScreenCTM()).x},a=s(e),c=(0,r.findNoteEventAtTick)(i,t.track,t.tick),u=s(e+o.BEAT_WIDTH)-a;let h;h=c?s((0,o.tickToX)(i.ticksPerBeat,c.endTick+i.ticksPerBeat/2))-a:u;const d=l.current.getBoundingClientRect(),p=a-d.x,g=p+h;p<u?l.current.scrollLeft+=p-u:h<d.width&&g>d.width&&(l.current.scrollLeft+=g-d.width)},[null==t?void 0:t.tick,i.ticksPerBeat]),(0,n.jsx)("div",Object.assign({ref:l,className:"music-scrollable-workspace"},{children:(0,n.jsx)("div",Object.assign({className:"music-scroller"},{children:(0,n.jsx)(a.Workspace,Object.assign({},e))}))}))}},{"./Workspace":216,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],213:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Staff=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("./playback"),a=e("./svgConstants"),l=e("./utils");i.Staff=e=>{const{top:t,isBassClef:i,gridTicks:c,ticksPerBeat:u,beatsPerMeasure:h,beatsPerMinute:d,measures:p}=e;let g;s.useEffect(()=>{const e=pxsim.music.tickToMs(d,u,1),t=(0,a.tickToX)(u,2)-(0,a.tickToX)(u,1);let i,n,s=0,o=!1;const l=e=>{s=(0,a.tickToX)(u,e),n=Date.now(),o||(o=!0,g.style.display="unset",i=requestAnimationFrame(h))},c=()=>{o=!1,g.style.display="none",i&&cancelAnimationFrame(i)},h=()=>{const r=s+t*(Date.now()-n)/e;g.setAttribute("transform",`translate(${r}, 0)`),o&&(i=requestAnimationFrame(h))};return(0,r.addTickListener)(l),(0,r.addPlaybackStateListener)(c),()=>{(0,r.removeTickListener)(l),(0,r.removePlaybackStateListener)(c),i&&cancelAnimationFrame(i)}},[u,d]);const f=(0,a.workspaceWidth)(p,h),m=[];for(let e=0;e<5;e++)m.push((0,n.jsx)("line",{className:"music-staff-row",x1:0,y1:(0,a.rowY)(2*e+2,!1),x2:f,y2:(0,a.rowY)(2*e+2,!1)},e));const _=[],b=c;for(let e=0;e<p*h*u;e+=b){const t=e%u===0,s=e%(h*u)===0,r=!t&&!s;_.push((0,n.jsxs)("g",{children:[s&&!i&&(0,n.jsx)("text",Object.assign({x:(0,a.tickToX)(u,e),y:a.STAFF_HEADER_HEIGHT-a.STAFF_HEADER_OFFSET,textAnchor:"middle",fontSize:a.STAFF_HEADER_FONT_SIZE},{children:Math.floor(e/(h*u))+1})),(0,n.jsx)("line",{className:"music-staff-column",x1:(0,a.tickToX)(u,e),y1:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,x2:(0,a.tickToX)(u,e),y2:a.STAFF_HEADER_HEIGHT}),!r&&(0,n.jsx)("line",{className:(0,o.classList)("music-staff-column",t&&"beat-start",s&&"measure-start"),x1:(0,a.tickToX)(u,e),y1:i&&s?0:a.STAFF_HEADER_HEIGHT,x2:(0,a.tickToX)(u,e),y2:a.WORKSPACE_HEIGHT})]},e))}return(0,n.jsxs)("g",Object.assign({className:"music-staff",transform:`translate(0 ${t})`},{children:[(0,n.jsx)("rect",{className:"music-staff-background",x:0,y:a.STAFF_HEADER_HEIGHT,width:f,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("image",{className:"music-staff-clef",href:(0,l.resolveImageURL)(i?"music-editor/bass-clef.svg":"music-editor/treble-clef.svg"),height:i?a.BASS_CLEF_HEIGHT:a.CLEF_HEIGHT,x:0,y:i?a.BASS_CLEF_TOP:a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{fill:"#000",x:0,y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,width:f,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("rect",{fill:"#dedede",x:a.CLEF_WIDTH,y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,width:f-a.CLEF_WIDTH-a.STAFF_END_WIDTH,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("g",Object.assign({className:"music-staff-rows"},{children:m})),(0,n.jsx)("g",Object.assign({className:"music-staff-beats"},{children:_})),(0,n.jsxs)("g",Object.assign({className:"music-staff-end"},{children:[(0,n.jsx)("rect",{x:f-a.STAFF_END_WIDTH,y:a.STAFF_HEADER_HEIGHT,width:3,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{x:f-12,y:a.STAFF_HEADER_HEIGHT,width:12,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT})]})),(0,n.jsx)("g",Object.assign({className:"music-playback-head",ref:e=>{e&&(g=e)}},{children:(0,n.jsx)("line",{className:"music-playback-line",x1:0,y1:a.STAFF_HEADER_HEIGHT,x2:0,y2:a.WORKSPACE_HEIGHT})}))]}))}},{"../../../../react-common/components/util":171,"./playback":219,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],214:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Track=void 0;const n=e("react/jsx-runtime"),s=e("./NoteGroup"),o=e("./svgConstants");i.Track=e=>{const{song:t,track:i,keyboardCursor:a}=e;return(0,n.jsxs)("g",Object.assign({className:"music-staff-track"},{children:[a&&(0,n.jsx)("g",{children:(0,n.jsx)("rect",{x:(0,o.tickToX)(t.ticksPerBeat,a.tick),y:a.bassClef?o.BASS_STAFF_TOP+o.STAFF_HEADER_HEIGHT:o.STAFF_HEADER_HEIGHT,width:5,height:o.WORKSPACE_HEIGHT-o.STAFF_HEADER_HEIGHT,fill:"purple"})}),i.notes.map(e=>(0,n.jsx)(s.NoteGroup,{noteEvent:e,octave:i.instrument.octave,song:t,iconURI:i.iconURI,isDrumTrack:!!i.drums,cursor:a},r(e)))]}))};const r=e=>`${e.startTick}-${e.endTick}-${e.notes.map(e=>e.note+e.enharmonicSpelling).join("-")}`},{"./NoteGroup":210,"./svgConstants":220,"react/jsx-runtime":305}],215:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TrackSelector=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Button"),o=e("../../../../react-common/components/controls/Checkbox"),r=e("../../../../react-common/components/controls/Dropdown"),a=e("../../../../react-common/components/controls/FocusList"),l=e("../../../../react-common/components/util"),c=e("./utils"),u={four:"1/4",eight:"1/8",sixteen:"1/16",thirtytwo:"1/32"};i.TrackSelector=e=>{const{song:t,selected:i,onTrackSelected:h,selectedResolution:d,onResolutionSelected:p,eraserActive:g,onEraserClick:f,hideTracksActive:m,onHideTracksClick:_}=e,b=[{title:lf("1/4 Note"),label:lf("1/4"),id:"four"},{title:lf("1/8 Note"),label:lf("1/8"),id:"eight"},{title:lf("1/16 Note"),label:lf("1/16"),id:"sixteen"},{title:lf("1/32 Note"),label:lf("1/32"),id:"thirtytwo"}];return(0,n.jsxs)("div",Object.assign({className:"music-track-selector"},{children:[(0,n.jsxs)(a.FocusList,Object.assign({role:"radiogroup",ariaLabel:lf("Track selection")},{children:[t.tracks.map((e,o)=>(0,n.jsx)(s.Button,{role:"radio",ariaSelected:i===o&&!g,ariaPosInSet:o+1,ariaSetSize:t.tracks.length+1,title:e.name,className:(0,l.classList)("music-track-button square-button pixellated",i===o&&!g&&"selected"),label:(0,n.jsx)("img",{src:(0,c.resolveImageURL)(e.iconURI),alt:e.name}),onClick:()=>(e=>{h(e)})(o)},e.name)),(0,n.jsx)(s.Button,{className:(0,l.classList)("music-track-button square-button",g&&"selected"),title:g?lf("Turn off eraser tool"):lf("Turn on eraser tool"),leftIcon:"fas fa-eraser",ariaSelected:g,ariaPosInSet:t.tracks.length,ariaSetSize:t.tracks.length+1,onClick:f})]})),(0,n.jsx)(o.Checkbox,{className:"music-editor-label",id:"hide-tracks",label:lf("Only show selected instrument"),isChecked:m,onChange:_}),(0,n.jsxs)("div",Object.assign({className:"music-track-grid"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:lf("Grid:")})),(0,n.jsx)(r.Dropdown,{id:"grid-resolution",ariaLabel:lf("Staff grid resolution"),items:b,selectedId:Object.keys(u).find(e=>u[e]===d),onItemSelected:e=>{p(u[e])}})]}))]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Dropdown":162,"../../../../react-common/components/controls/FocusList":164,"../../../../react-common/components/util":171,"./utils":221,"react/jsx-runtime":305}],216:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Workspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("./Staff"),a=e("./svgConstants"),l=e("./Track"),c=e("./utils"),u=e("./WorkspaceSelection");function h(e,t,i,n){const s=(0,o.screenToSVGCoord)(t,(0,o.clientCoord)(e)),r=s.y>a.BASS_STAFF_TOP,l=(0,a.closestTick)(i.ticksPerBeat,s.x+a.BEAT_WIDTH/i.ticksPerBeat,n);return{isBassClef:r,row:(0,a.closestRow)(s.y),tick:l,exactTick:(0,a.closestTick)(i.ticksPerBeat,s.x,1)}}i.Workspace=e=>{const{song:t,onWorkspaceClick:i,gridTicks:d,selectedTrack:p,onWorkspaceDrag:g,onWorkspaceDragStart:f,onWorkspaceDragEnd:m,onKeydown:_,cursor:b,hideUnselectedTracks:T,eraserActive:E,showBassClef:v,selection:y}=e,[k,C]=s.useState(null),[I,S]=s.useState(!1);let A;const O=s.useRef(null),w=s.useRef(null),N=s.useRef(null),R=s.useRef(null);s.useEffect(()=>{const e=e=>{O.current=e;const i=O.current;let n,s,o=I||E?void 0:i;const r=i&&(0,c.findNoteEventAtTick)(t,p,i.tick),l=k&&(0,c.findNoteEventAtTick)(t,p,k.tick);y?(n=y.startTick+y.deltaTick,s=y.endTick+y.deltaTick):!E&&l&&(null==i?void 0:i.tick)>=l.startTick?(n=l.startTick,s=l.endTick):!E&&I&&i&&k?(n=Math.min(i.tick,k.tick),s=Math.max(i.tick,k.tick)):r?(n=r.startTick,s=r.endTick):i&&(n=i.tick,s=i.tick+d),r&&o&&(o=Object.assign(Object.assign({},o),{tick:r.startTick})),w.current&&(w.current.setAttribute("x",`${void 0!==n?(0,a.tickToX)(t.ticksPerBeat,n):-1e3}`),w.current.setAttribute("width",""+(void 0!==s?(0,a.tickToX)(t.ticksPerBeat,s)-(0,a.tickToX)(t.ticksPerBeat,n):0))),N.current&&(N.current.setAttribute("x",`${void 0!==n?(0,a.tickToX)(t.ticksPerBeat,n):-1e3}`),N.current.setAttribute("width",""+(void 0!==s?(0,a.tickToX)(t.ticksPerBeat,s)-(0,a.tickToX)(t.ticksPerBeat,n):0))),R.current&&(o?(R.current.setAttribute("x",""+((0,a.tickToX)(t.ticksPerBeat,o.tick)-a.NOTE_ICON_WIDTH/2)),R.current.setAttribute("y",""+((0,a.rowY)(o.row,o.isBassClef)-a.NOTE_ICON_WIDTH/2)),R.current.style.display="block"):R.current.style.display="none")};e(O.current),A.onpointerdown=e=>{e.preventDefault(),A.focus();const i=h(e,A,t,d);(E||i.tick>=0&&i.row>=0&&i.row<12)&&C(i)},A.onpointermove=i=>{const n=h(i,A,t,d),s=O.current;if(s&&s.exactTick===n.exactTick&&s.row===n.row)return;const o=t.beatsPerMeasure*t.ticksPerBeat*t.measures;n.tick>=0&&n.row>=0&&n.row<12&&n.tick<=o?(k&&(I||(S(!0),f(),g(k,k)),g(k,n)),n.tick<o?e(n):e(null)):e(null)},A.onpointerleave=t=>{e(null),I&&(m(),S(!1))},A.onpointerup=e=>{C(null);const n=h(e,A,t,d),s=n.tick>=0&&n.row>=0&&n.row<12;I?(s&&g(k,n),m(),S(!1)):s&&i(n,e.ctrlKey)}},[k,I,g,m,f,t,p,d,E,b]);const x=t.tracks.filter((e,t)=>t!==p),L=v?2*a.WORKSPACE_HEIGHT:a.WORKSPACE_HEIGHT,D=pxt.assets.music.getSongInfo(t),M=(0,a.workspaceWidth)(t.measures,t.beatsPerMeasure)+20;return(0,n.jsxs)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",className:(0,o.classList)("music-workspace",E&&"erasing"),viewBox:`0 0 ${M} ${L}`,"aria-label":lf("Music Workspace"),tabIndex:0,onKeyDown:_,ref:e=>{e&&(A=e)}},{children:[(0,n.jsxs)("filter",Object.assign({id:"selection-outline"},{children:[(0,n.jsx)("feMorphology",{in:"SourceAlpha",result:"DILATED",operator:"dilate",radius:"4"}),(0,n.jsx)("feFlood",{floodColor:"yellow",floodOpacity:"1",result:"FLOODED"}),(0,n.jsx)("feComposite",{in:"FLOODED",in2:"DILATED",operator:"in",result:"OUTLINE"}),(0,n.jsxs)("feMerge",{children:[(0,n.jsx)("feMergeNode",{in:"OUTLINE"}),(0,n.jsx)("feMergeNode",{in:"SourceGraphic"})]})]})),(0,n.jsxs)("filter",Object.assign({id:"cursor-outline"},{children:[(0,n.jsx)("feMorphology",{in:"SourceAlpha",result:"DILATED",operator:"dilate",radius:"4"}),(0,n.jsx)("feFlood",{floodColor:"purple",floodOpacity:"1",result:"FLOODED"}),(0,n.jsx)("feComposite",{in:"FLOODED",in2:"DILATED",operator:"in",result:"OUTLINE"}),(0,n.jsxs)("feMerge",{children:[(0,n.jsx)("feMergeNode",{in:"OUTLINE"}),(0,n.jsx)("feMergeNode",{in:"SourceGraphic"})]})]})),(0,n.jsx)("rect",{x:"0",y:"0",width:M,height:L,fill:"#FFFFFF",opacity:0}),(0,n.jsx)(r.Staff,Object.assign({},D,{top:0,gridTicks:d})),v&&(0,n.jsx)(r.Staff,Object.assign({},D,{top:a.BASS_STAFF_TOP,isBassClef:!0,gridTicks:d})),(0,n.jsx)("rect",{ref:w,fill:"#03adfc",y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("rect",{ref:N,fill:"#03adfc",y:a.BASS_STAFF_TOP+a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,height:a.STAFF_GRID_TICK_HEIGHT}),y&&(0,n.jsx)(u.WorkspaceSelection,Object.assign({},D,{range:y})),!T&&x.map((e,i)=>(0,n.jsx)(l.Track,{track:e,song:t},i)),(0,n.jsx)(l.Track,{track:t.tracks[p],song:t,keyboardCursor:b}),(0,n.jsx)("g",Object.assign({className:"music-staff-note"},{children:(0,n.jsx)("image",{ref:R,width:a.NOTE_ICON_WIDTH,height:a.NOTE_ICON_WIDTH,href:(0,c.resolveImageURL)(t.tracks[p].iconURI),style:{display:"none"},opacity:.5})}))]}))}},{"../../../../react-common/components/util":171,"./Staff":213,"./Track":214,"./WorkspaceSelection":217,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],217:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.WorkspaceSelection=void 0;const n=e("react/jsx-runtime"),s=e("./svgConstants");i.WorkspaceSelection=e=>{const{range:t,ticksPerBeat:i}=e,o=(0,s.tickToX)(i,t.startTick+t.deltaTick),r=(0,s.tickToX)(i,t.endTick+t.deltaTick);return(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",{className:"music-workspace-selection",fill:"#03adfc",opacity:.5,x:Math.min(o,r),y:s.STAFF_HEADER_HEIGHT,width:Math.max(o,r)-Math.min(o,r),height:s.WORKSPACE_HEIGHT-s.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{className:"music-workspace-selection",fill:"#03adfc",opacity:.5,x:Math.min(o,r),y:s.BASS_STAFF_TOP+s.STAFF_HEADER_HEIGHT,width:Math.max(o,r)-Math.min(o,r),height:s.WORKSPACE_HEIGHT-s.STAFF_HEADER_HEIGHT})]})}},{"./svgConstants":220,"react/jsx-runtime":305}],218:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.handleKeyboardEvent=void 0;const n=e("./playback"),s=e("./utils");i.handleKeyboardEvent=function(e,t,i){const o=i.ctrlKey||i.metaKey,r=i.shiftKey,a=i.altKey,l=t.selection?void 0:(0,s.findNoteEventAtTick)(e,t.track,t.tick);(null==l?void 0:l.startTick)===t.tick&&void 0===t.noteGroupIndex&&(t.noteGroupIndex=0);let c=e,u=Object.assign(Object.assign({},t),{selection:t.selection&&Object.assign({},t.selection)});const h=e.tracks[t.track].instrument,d=h.octave,p=e.ticksPerBeat*e.beatsPerMeasure,g=p*e.measures,f=!!t.selection,m=!!e.tracks[t.track].drums,_=e=>{u.selection&&(c=(0,s.applySelection)(u.selection,t.hideTracksActive?t.track:void 0),e&&(c=(0,s.unselectAllNotes)(c)),delete u.selection)},b=t=>{for(const i of t.notes)pxsim.music.playNoteAsync(i.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,t.endTick-t.startTick))};switch(i.key){case"ArrowUp":case"Up":if(i.preventDefault(),r){u.bassClef=!1;break}if(u.selection){u.selection.transpose++,c=(0,s.applySelection)(u.selection);break}if(!l)break;if(a&&o)u.noteGroupIndex=l.notes.length-1;else if(a)u.noteGroupIndex=Math.min(t.noteGroupIndex+1,l.notes.length-1);else{let i=l.notes[t.noteGroupIndex],n=(0,s.isBassClefNote)(d,i,m);const r=(0,s.noteToRow)(d,i,m);let a=r;const p=o?12:1;for(;l.notes.some(e=>(0,s.isBassClefNote)(d,e,m)===n&&a===(0,s.noteToRow)(d,e,m));)if(a+=p,a>=12){if(!n)break;n=!1,a-=12}if(a>=12||a<0)break;const g=(0,s.rowToNote)(d,a,n,m,i.enharmonicSpelling);c=(0,s.removeNoteAtRowFromTrack)(c,t.track,r,(0,s.isBassClefNote)(d,i,m),l.startTick),c=(0,s.addNoteToTrack)(c,t.track,g,l.startTick,l.endTick);const f=(0,s.findNoteEventAtTick)(c,t.track,t.tick);u.noteGroupIndex=f.notes.findIndex(e=>e.note===g.note),pxsim.music.playNoteAsync(g.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,f.endTick-f.startTick))}break;case"ArrowDown":case"Down":if(i.preventDefault(),r){u.bassClef=!0;break}if(u.selection){u.selection.transpose--,c=(0,s.applySelection)(u.selection);break}if(!l)break;if(a&&o)u.noteGroupIndex=0;else if(a)u.noteGroupIndex=Math.max(t.noteGroupIndex-1,0);else{let i=l.notes[t.noteGroupIndex];const n=c.tracks[t.track];let r=(0,s.isBassClefNote)(d,i,!!n.drums);const a=(0,s.noteToRow)(d,i,!!n.drums);let p=a;const g=o?-12:-1;for(;l.notes.some(e=>(0,s.isBassClefNote)(d,e,!!n.drums)===r&&p===(0,s.noteToRow)(d,e,!!n.drums));)if(p+=g,p<0){if(r)break;r=!0,p+=12}if(p>=12||p<0)break;const f=(0,s.rowToNote)(d,p,r,!!n.drums,i.enharmonicSpelling);c=(0,s.removeNoteAtRowFromTrack)(c,t.track,a,(0,s.isBassClefNote)(d,i,!!n.drums),l.startTick),c=(0,s.addNoteToTrack)(c,t.track,f,l.startTick,l.endTick);const m=(0,s.findNoteEventAtTick)(c,t.track,t.tick);u.noteGroupIndex=m.notes.findIndex(e=>e.note===f.note),pxsim.music.playNoteAsync(f.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,m.endTick-m.startTick))}break;case"ArrowLeft":case"Left":if(i.preventDefault(),r&&f&&(u.selection.deltaTick||u.selection.transpose)&&_(!0),o){u.tick%p===0?u.tick=Math.max(u.tick-p,0):u.tick=Math.floor(u.tick/p)*p;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);(null==e?void 0:e.startTick)===u.tick?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0;break}const T=t.tick%t.gridTicks!==0?Math.floor(u.tick/t.gridTicks)*t.gridTicks:t.tick-t.gridTicks,E=(0,s.findPreviousNoteEvent)(c,t.track,t.tick-1);if((null==E?void 0:E.endTick)>T){u.tick=E.startTick,u.noteGroupIndex=0;break}u.tick=Math.max(T,0),u.noteGroupIndex=void 0;break;case"ArrowRight":case"Right":if(i.preventDefault(),r&&f&&(u.selection.deltaTick||u.selection.transpose)&&_(!0),o){u.tick%p===0?u.tick=Math.min(u.tick+p,g-p):(u.tick=Math.min(Math.ceil(u.tick/p)*p,g-p),u.tick>=g&&(u.tick-=p));const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);(null==e?void 0:e.startTick)===u.tick?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0;break}const v=l?Math.ceil(l.endTick/t.gridTicks)*t.gridTicks:t.tick+t.gridTicks,y=(0,s.findNextNoteEvent)(c,t.track,t.tick);if((null==y?void 0:y.startTick)<=v){u.tick=y.startTick,u.noteGroupIndex=0;break}u.tick=Math.min(Math.ceil(v/t.gridTicks)*t.gridTicks,g-t.gridTicks),u.noteGroupIndex=void 0;break;case"End":if(i.preventDefault(),o){u.tick=g-t.gridTicks;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);e?(u.tick=e.startTick,u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0}break;case"Home":if(i.preventDefault(),o){u.tick=0;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);e?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0}break;case"Backspace":if(i.preventDefault(),t.selection)_(),c=(0,s.deleteSelectedNotes)(c);else if(void 0!==t.noteGroupIndex){if(o){c=(0,s.removeNoteEventFromTrack)(c,t.track,t.tick),u.noteGroupIndex=void 0;break}c=(0,s.removeNoteFromTrack)(c,t.track,l.notes[t.noteGroupIndex],l.startTick),1===l.notes.length?u.noteGroupIndex=void 0:u.noteGroupIndex=Math.min(u.noteGroupIndex,l.notes.length-2)}break;case"Enter":f&&_(!0);break;case"Spacebar":case" ":i.preventDefault(),(0,n.isPlaying)()?(0,n.stopPlayback)():r?(0,n.startPlaybackAsync)(e,o,null==t?void 0:t.tick):(0,n.startPlaybackAsync)(e,o,0);break;case"j":case"J":if(e.tracks[t.track].drums)break;if(l){i.preventDefault();const e=l.notes[u.noteGroupIndex],n=12*h.octave-20,o=12*h.octave+20,r=(0,s.noteToRow)(d,e,!1),a=l.startTick,p=(0,s.isBassClefNote)(d,e,!1);let g;c=(0,s.removeNoteAtRowFromTrack)(c,u.track,r,p,a),g="normal"===e.enharmonicSpelling&&e.note<o?"sharp":"sharp"===e.enharmonicSpelling&&e.note>n||e.note===o?"flat":"normal";const f=(0,s.rowToNote)(h.octave,r,p,!1,g);c=(0,s.addNoteToTrack)(c,u.track,f,l.startTick,l.endTick),pxsim.music.playNoteAsync(f.note,h,pxsim.music.tickToMs(c.beatsPerMinute,c.ticksPerBeat,t.gridTicks))}break;default:if(o&&"a"===i.key||"A"===i.key){i.preventDefault(),u.selection&&_(!0),u.selection={startTick:0,endTick:g,originalSong:c,transpose:0,deltaTick:0};break}if(/^[a-g]$/i.test(i.key)){if(o)break;let e;if(i.preventDefault(),_(!0),e=t.bassClef?(0,s.rowToNote)(d,3+"abcdefg".indexOf(i.key.toLowerCase()),!0,m):(0,s.rowToNote)(d,5+"abcdefg".indexOf(i.key.toLowerCase()),!1,m),l){if(-1===l.notes.indexOf(e)){c=(0,s.addNoteToTrack)(c,t.track,e,l.startTick,l.endTick);b((0,s.findNoteEventAtTick)(c,t.track,l.startTick))}}else{c=(0,s.addNoteToTrack)(c,t.track,e,t.tick,t.tick+t.gridTicks),u.noteGroupIndex=0;b((0,s.findNoteEventAtTick)(c,t.track,t.tick))}break}if(/^[1-9]$/.test(i.key)){if(i.preventDefault(),_(!0),l){c=(0,s.editNoteEventLength)(c,t.track,l.startTick,l.startTick+parseInt(i.key)*t.gridTicks);b((0,s.findNoteEventAtTick)(c,t.track,l.startTick))}break}}if(u.tick!==t.tick)if(r)u.selection?u.selection.endTick=u.tick:u.selection={originalSong:e,startTick:t.tick,endTick:u.tick,transpose:0,deltaTick:0},c=(0,s.applySelection)(u.selection,u.hideTracksActive?u.track:void 0);else if(u.selection){const e=(0,s.selectNoteEventsInRange)(u.selection.originalSong,u.selection.startTick,u.selection.endTick,u.hideTracksActive?u.track:void 0),i=(0,s.findSelectedRange)(e,u.gridTicks);i&&(u.selection.startTick=i.start,u.selection.endTick=i.end),u.selection.deltaTick+=u.tick-t.tick,c=(0,s.applySelection)(u.selection,u.hideTracksActive?u.track:void 0),u.selection.startTick+u.selection.deltaTick>0&&(u.tick=u.selection.startTick+u.selection.deltaTick)}return[c,u]}},{"./playback":219,"./utils":221}],219:[function(e,t,i){"use strict";let n;Object.defineProperty(i,"__esModule",{value:!0}),i.NoteTracker=i.removeNoteChangeListener=i.addNoteChangeListener=i.removePlaybackStateListener=i.addPlaybackStateListener=i.removeTickListener=i.addTickListener=i.stopPlayback=i.updatePlaybackSongAsync=i.setLooping=i.isLooping=i.isPlaying=i.startPlaybackAsync=void 0;let s,o,r=[],a=[];function l(){return!!n&&"stop"!==n.state()}function c(e){a.push(e)}function u(e){a=a.filter(t=>e!==t)}function h(e){r.push(e)}function d(e){r=r.filter(t=>e!==t)}i.startPlaybackAsync=async function(e,t,i){s=e,n||(n=new pxsim.music.Sequencer,await n.initAsync(),n.addEventListener("state-change",()=>{for(const e of r)e(n.state())}),n.addEventListener("tick",()=>{for(const e of a)e(n.currentTick())}),n.setVolume(100)),n.startFrom(e,t,i)},i.isPlaying=l,i.isLooping=function(){return l()&&"loop"===n.state()},i.setLooping=function(e){n&&n.setLooping(e)},i.updatePlaybackSongAsync=async function(e){n&&n.updateSong(e),s=e},i.stopPlayback=function(){n&&n.stop()},i.addTickListener=c,i.removeTickListener=u,i.addPlaybackStateListener=h,i.removePlaybackStateListener=d,i.addNoteChangeListener=function(e){o||(o=new p),o.addNoteChangeListener(e)},i.removeNoteChangeListener=function(e){o&&o.removeNoteChangeListener(e)};class p{constructor(){this.activeNotes={},this.noteChangeListeners=[],this.onTick=e=>{var t;const i={};for(let t=0;t<s.tracks.length;t++){i[t]=[];const n=s.tracks[t];for(const s of n.notes){if(s.startTick>e)break;if(s.startTick<=e&&s.endTick>e)for(const e of s.notes)i[t].push(e.note)}}for(let e=0;e<s.tracks.length;e++){const n=this.activeNotes[e]||[],o=i[e]||[],r=null===(t=s.tracks[e])||void 0===t?void 0:t.id;for(const e of n)if(!o.includes(e))for(const t of this.noteChangeListeners)t(r,e,!1);for(const e of o)if(!n.includes(e))for(const t of this.noteChangeListeners)t(r,e,!0)}this.activeNotes=i},this.onPlaybackStateChange=e=>{if("stop"===e){for(const e in this.activeNotes)for(const t of this.activeNotes[e])for(const i of this.noteChangeListeners)i(parseInt(e),t,!1);this.activeNotes={}}},c(this.onTick),h(this.onPlaybackStateChange)}addNoteChangeListener(e){this.noteChangeListeners.push(e)}removeNoteChangeListener(e){this.noteChangeListeners=this.noteChangeListeners.filter(t=>e!==t)}dispose(){u(this.onTick),d(this.onPlaybackStateChange)}getActiveNotes(e){return this.activeNotes[e]||[]}}i.NoteTracker=p},{}],220:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.rowY=i.closestRow=i.closestTick=i.beatToX=i.tickToX=i.workspaceWidth=i.BASS_CLEF_HEIGHT=i.BASS_CLEF_TOP=i.BASS_STAFF_HEADER_HEIGHT=i.BASS_STAFF_TOP=i.NOTE_DURATION_HEIGHT=i.NOTE_ICON_WIDTH=i.WORKSPACE_HEIGHT=i.STAFF_GRID_TICK_HEIGHT=i.STAFF_END_WIDTH=i.STAFF_HEADER_OFFSET=i.STAFF_HEADER_FONT_SIZE=i.STAFF_HEADER_HEIGHT=i.CLEF_HEIGHT=i.CLEF_WIDTH=i.STAFF_ROW_HEIGHT=i.BEAT_WIDTH=void 0,i.BEAT_WIDTH=150,i.STAFF_ROW_HEIGHT=50,i.CLEF_WIDTH=250,i.CLEF_HEIGHT=320,i.STAFF_HEADER_HEIGHT=i.STAFF_ROW_HEIGHT,i.STAFF_HEADER_FONT_SIZE=40,i.STAFF_HEADER_OFFSET=11,i.STAFF_END_WIDTH=25,i.STAFF_GRID_TICK_HEIGHT=7,i.WORKSPACE_HEIGHT=i.STAFF_HEADER_HEIGHT+7*i.STAFF_ROW_HEIGHT,i.NOTE_ICON_WIDTH=45,i.NOTE_DURATION_HEIGHT=i.NOTE_ICON_WIDTH/3,i.BASS_STAFF_TOP=i.WORKSPACE_HEIGHT,i.BASS_STAFF_HEADER_HEIGHT=i.STAFF_ROW_HEIGHT/2,i.BASS_CLEF_TOP=90,i.BASS_CLEF_HEIGHT=230,i.workspaceWidth=function(e,t){return i.CLEF_WIDTH+e*t*i.BEAT_WIDTH+i.STAFF_END_WIDTH},i.tickToX=function(e,t){return i.CLEF_WIDTH+i.BEAT_WIDTH/e*t},i.beatToX=function(e){return i.CLEF_WIDTH+i.BEAT_WIDTH*e},i.closestTick=function(e,t,n){const s=Math.floor((t-i.CLEF_WIDTH)*(e/i.BEAT_WIDTH));return Math.floor(s/n)*n},i.closestRow=function(e){const t=e>i.BASS_STAFF_TOP;return 12-Math.round((e-i.STAFF_HEADER_HEIGHT-(t?i.BASS_STAFF_TOP:0))/(i.STAFF_ROW_HEIGHT/2))},i.rowY=function(e,t){return t?i.BASS_STAFF_TOP+i.STAFF_HEADER_HEIGHT+(12-e%12)*i.STAFF_ROW_HEIGHT/2:i.STAFF_HEADER_HEIGHT+(12-e%12)*i.STAFF_ROW_HEIGHT/2}},{}],221:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.doesSongUseBassClef=i.applySelection=i.moveSelectedNotes=i.deleteSelectedNotes=i.unselectAllNotes=i.selectNoteEventsInRange=i.findSelectedRange=i.changeSongLength=i.findNoteEventAtPosition=i.findNextNoteEvent=i.findNoteEventsOverlappingRange=i.findPreviousNoteEvent=i.findNoteEventAtTick=i.fillDrums=i.editNoteEventLength=i.removeNoteEventFromTrack=i.removeNoteAtRowFromTrack=i.removeNoteFromTrack=i.addNoteToTrack=i.isBassClefNote=i.noteToRow=i.resolveImageURL=i.rowToNote=void 0;const n=[0,2,4,5,7,9,11,12,14,16,17,19],s=[0,1,3,5,7,8,10,12,13,15,17,19];function o(e,t,i,o,r){if(o)return{note:t+(i?12:0),enharmonicSpelling:"normal"};let a;return a=i?s[t]+12*e-19:n[t]+12*e+1,r&&"normal"!==r?"sharp"===r?{note:a+1,enharmonicSpelling:r}:{note:a-1,enharmonicSpelling:r}:{note:a,enharmonicSpelling:"normal"}}function r(e,t,i){if(i)return t.note>=12?t.note-12:t.note;const o=a(e,t,!1),r=t.note-1-12*e+(o?20:0),l=o?s:n;for(let e=0;e<l.length;e++){if(l[e]===r)return"normal"===t.enharmonicSpelling?e:"sharp"===t.enharmonicSpelling?e-1:e+1;if(l[e]>r){if("sharp"===t.enharmonicSpelling)return e-1;if("flat"===t.enharmonicSpelling)return e}}return"sharp"===t.enharmonicSpelling&&r===l[l.length-1]+1?l.length-1:-1}function a(e,t,i){return i?t.note>=12:"flat"===t.enharmonicSpelling?t.note<12*e:"sharp"===t.enharmonicSpelling?t.note<=12*e+1:t.note<12*e+1}function l(e,t,i,n,s){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:c(e.notes,i,n,s,e.instrument.octave,!!e.drums).filter(e=>(e.startTick<=n||e.startTick>=s)&&(e.endTick>=s||e.endTick<=n))}))})}function c(e,t,i,n,s,o){const l={notes:[t],startTick:i,endTick:n};for(let n=0;n<e.length;n++){if(e[n].startTick>i)return e.slice(0,n).concat([l]).concat(e.slice(n));if(e[n].endTick>i)return e[n].notes.some(e=>e.note===t.note&&e.enharmonicSpelling===t.enharmonicSpelling)?e.slice():e.map((e,i)=>i!==n?e:Object.assign(Object.assign({},e),{notes:e.notes.concat([t]).sort((e,t)=>{const i=a(s,e,o);return i===a(s,t,o)?r(s,e,o)-r(s,t,o):i?-1:1})}))}return e.slice().concat([l])}function u(e,t,i){const n=e.slice();for(let e=0;e<n.length;e++)if(n[e].startTick==i){n[e]=Object.assign(Object.assign({},n[e]),{notes:n[e].notes.filter(e=>e.note!==t.note)});break}return n.filter(e=>e.notes.length)}function h(e,t,i,n,s,o){const l=e.slice();for(let e=0;e<l.length;e++)if(l[e].startTick==s){l[e]=Object.assign(Object.assign({},l[e]),{notes:l[e].notes.filter(e=>a(n,e,o)!==i||r(n,e,o)!==t)});break}return l.filter(e=>e.notes.length)}function d(e,t,i){const n=e.slice();if(t>=i)return n;let s;for(let e=0;e<n.length;e++)n[e].startTick===t?(s=Object.assign(Object.assign({},n[e]),{endTick:i}),n[e]=s):s&&n[e].startTick<s.endTick&&(n[e]=void 0);return n.filter(e=>!!e)}function p(e,t,i){const n=e.tracks[t];for(const e of n.notes)if(e.startTick<=i&&e.endTick>i)return e}function g(e,t){let i=e.measures*e.beatsPerMeasure*e.ticksPerBeat+1,n=-1;for(const t of e.tracks)for(const e of t.notes)e.selected&&(i=Math.min(e.startTick,i),n=Math.max(e.endTick,n));if(-1!==n)return void 0!==t&&(i=Math.floor(i/t)*t,n=Math.ceil(n/t)*t),{start:i,end:n}}function f(e,t,i,n){return void 0!==n?Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>s!==n?e:m(e,Math.min(t,i),Math.max(t,i)))}):Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>m(e,Math.min(t,i),Math.max(t,i)))})}function m(e,t,i){return Object.assign(Object.assign({},e),{notes:e.notes.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.slice(),selected:!(e.startTick>=i||e.endTick<=t)}))})}function _(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.map(e=>Object.assign(Object.assign({},e),{selected:!1}))}))})}function b(e,t,i,n){const s=g(e);if(!s)return e;const{start:o,end:r}=s,a=o+t,l=r+t,c=e.beatsPerMeasure*e.ticksPerBeat*e.measures;return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>void 0!==n&&n!=s?e:Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>e.selected||e.endTick<=a||e.startTick>=l).map(n=>n.selected?E(n,e.instrument.octave,t,i,!!e.drums):n).map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,c)})).filter(e=>e.notes.length>0&&e.startTick>=0&&e.startTick<c).sort((e,t)=>e.startTick-t.startTick)}))})}function T(e,t){if(e.pastedContent)return function(e,t){const i=T(e.pastedContent,t),n=g(i,t),s=e.startTick+e.deltaTick,o=s+(n.end-n.start),r=_(e.originalSong),a=r.beatsPerMeasure*r.ticksPerBeat*r.measures;return Object.assign(Object.assign({},r),{tracks:r.tracks.map((r,l)=>void 0!==t&&t!=l?r:Object.assign(Object.assign({},r),{notes:r.notes.filter(e=>e.endTick<=s||e.startTick>=o).concat(i.tracks[l].notes.filter(e=>e.selected).map(t=>Object.assign(Object.assign({},t),{startTick:t.startTick-n.start+e.startTick,endTick:t.endTick-n.start+e.startTick}))).map(t=>t.selected?E(t,r.instrument.octave,e.deltaTick,e.transpose,!!r.drums):t).map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,a)})).filter(e=>e.notes.length>0&&e.startTick>=0&&e.startTick<a).sort((e,t)=>e.startTick-t.startTick)}))})}(e,t);return b(f(e.originalSong,e.startTick,e.endTick,t),e.deltaTick,e.transpose,t)}function E(e,t,i,s,l){const c=Object.assign(Object.assign({},e),{startTick:e.startTick+i,endTick:e.endTick+i,notes:[]});if(l)c.notes=e.notes.slice();else for(const i of e.notes){let e=a(t,i,l),u=r(t,i,l);u+s>=n.length?e&&(u-=12,e=!1):u+s<0&&(e||(u+=12,e=!0));const h=u+s;h<0||h>=n.length||c.notes.push(o(t,h,e,l,i.enharmonicSpelling))}return c}i.rowToNote=o,i.resolveImageURL=function(e){return window.MonacoPaths&&window.MonacoPaths[e]||e},i.noteToRow=r,i.isBassClefNote=a,i.addNoteToTrack=l,i.removeNoteFromTrack=function(e,t,i,n){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>s!==t?e:Object.assign(Object.assign({},e),{notes:u(e.notes,i,n)}))})},i.removeNoteAtRowFromTrack=function(e,t,i,n,s){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:h(e.notes,i,n,e.instrument.octave,s,!!e.drums)}))})},i.removeNoteEventFromTrack=function(e,t,i){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,n)=>n!==t?e:Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>e.startTick!==i)}))})},i.editNoteEventLength=function(e,t,i,n){const s=e.beatsPerMeasure*e.ticksPerBeat*e.measures;return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:d(e.notes,i,Math.min(n,s))}))})},i.fillDrums=function(e,t,i,n,s,r,a){const c=o(0,i,n,!0);for(let i=s;i<r;i+=a)e=l(e,t,{note:c.note,enharmonicSpelling:"normal"},i,i+1);return e},i.findNoteEventAtTick=p,i.findPreviousNoteEvent=function(e,t,i){const n=e.tracks[t];let s;for(const e of n.notes){if(e.startTick>i)return s;s=e}return s},i.findNoteEventsOverlappingRange=function(e,t,i,n){const s=e.tracks[t],o=[];for(const e of s.notes)if(e.endTick<i||e.startTick>n){if(e.startTick>n)break}else o.push(e);return o},i.findNextNoteEvent=function(e,t,i){const n=e.tracks[t];for(const e of n.notes)if(e.startTick>i)return e},i.findNoteEventAtPosition=function(e,t,i){if(void 0!==i){const n=p(e,i,t.tick),s=e.tracks[i];return(null==n?void 0:n.notes.some(e=>r(s.instrument.octave,e,!!s.drums)===t.row))?n:void 0}for(let i=0;i<e.tracks.length;i++){const n=p(e,i,t.tick),s=e.tracks[i];if(null==n?void 0:n.notes.some(e=>r(s.instrument.octave,e,!!s.drums)===t.row))return n}},i.changeSongLength=function(e,t){const i=t*e.beatsPerMeasure*e.ticksPerBeat;return Object.assign(Object.assign({},e),{measures:t,tracks:e.tracks.map(e=>{const t=Object.assign(Object.assign({},e),{notes:e.notes.slice()});return t.notes=t.notes.filter(e=>e.startTick<i),t.notes=t.notes.map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,i)})),t})})},i.findSelectedRange=g,i.selectNoteEventsInRange=f,i.unselectAllNotes=_,i.deleteSelectedNotes=function(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>!e.selected)}))})},i.moveSelectedNotes=b,i.applySelection=T,i.doesSongUseBassClef=function(e){return e.tracks.some(e=>e.notes.some(t=>t.notes.some(t=>a(e.instrument.octave,t,!!e.drums))))}},{}],222:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DeleteErrorModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DeleteErrorModal=e=>{const{onClose:t}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Cannot Delete"),onClose:t,actions:[{label:(0,o.lf)("Okay"),onClick:t}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Songs must have at least one track.")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],223:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DeleteTrackModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DeleteTrackModal=e=>{const{trackId:t,onClose:i,onDelete:r}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Delete Track"),onClose:i,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:i},{label:(0,o.lf)("Delete"),className:"red",onClick:()=>{r(t),i()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Are you sure you want to delete this track?")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],224:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DrumWarningModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DrumWarningModal=e=>{const{trackId:t,instrumentId:i,onClose:r,onConfirm:a}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Change Track Instrument"),onClose:r,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:r},{label:(0,o.lf)("Confirm"),className:"red",onClick:()=>{a(t,i),r()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Switching between instruments and drums will cause all existing notes to be deleted. Are you sure you want to continue?")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],225:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Header=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Checkbox"),o=e("../../../../react-common/components/controls/Dropdown"),r=e("./types");function a(e){return`track-${e}`}function l(e){return`instrument-${e}`}function c(e){var t;const i=r.SNAP_OPTIONS.find(t=>t.ticksPerSnap===e);return null!==(t=null==i?void 0:i.id)&&void 0!==t?t:"sixteenth"}i.Header=e=>{var t;const{song:i,selectedTrackId:u,velocityEditorVisible:h,snapTicks:d,showSnapControls:p,onVelocityEditorToggle:g,onTrackSelected:f,onInstrumentSelected:m,onTrackCreated:_,onTrackDeleted:b,onOctavesChanged:T,onSnapChanged:E}=e,v=i.tracks.find(e=>e.id===u),y=i.instruments.find(e=>e.id===(null==v?void 0:v.instrumentId)),k=(0,r.isDrumInstrument)(y),C=i.tracks.map(e=>{const t=(0,r.lf)("Track {0}",e.id);return{label:t,title:t,id:a(e.id)}});C.push({label:(0,r.lf)("New Track..."),title:(0,r.lf)("New Track..."),id:"new-track"}),i.tracks.length>1&&C.push({label:(0,r.lf)("Delete Track"),title:(0,r.lf)("Delete Track"),id:"delete-track"});const I=r.NOTE_RANGES.map(e=>({label:e.name,title:e.name,id:e.id}));let S="full";const A=r.NOTE_RANGES.find(e=>e.minOctave===(null==v?void 0:v.minOctave)&&e.maxOctave===(null==v?void 0:v.maxOctave));A&&(S=A.id);const O=r.SNAP_OPTIONS.map(e=>({label:e.name,title:e.name,id:e.id}));return(0,n.jsxs)("div",Object.assign({className:"header"},{children:[(0,n.jsx)(o.Dropdown,{id:"track-select",items:C,selectedId:a(u),onItemSelected:e=>{if("new-track"===e)_();else if("delete-track"===e)b(u);else{const t=function(e){return parseInt(e.replace("track-",""))}(e);f(t)}}}),(0,n.jsx)(o.Dropdown,{id:"instrument-select",items:i.instruments.map(e=>({label:e.name,title:e.name,id:l(e.id)})),selectedId:l(null!==(t=null==v?void 0:v.instrumentId)&&void 0!==t?t:0),onItemSelected:e=>{const t=function(e){return parseInt(e.replace("instrument-",""))}(e);m(u,t)}}),!k&&(0,n.jsxs)("div",Object.assign({className:"octave-controls"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:(0,r.lf)("Range:")})),(0,n.jsx)(o.Dropdown,{id:"range-select",items:I,selectedId:S,onItemSelected:e=>{const t=r.NOTE_RANGES.find(t=>t.id===e);t&&T(t.minOctave,t.maxOctave)}})]})),(0,n.jsx)(s.Checkbox,{id:"velocity-editor-toggle",label:(0,r.lf)("Show Velocity Editor"),isChecked:h,onChange:g}),(0,n.jsx)("div",{className:"spacer"}),p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:(0,r.lf)("Snap:")})),(0,n.jsx)(o.Dropdown,{id:"snap-select",items:O,selectedId:c(d),onItemSelected:e=>E(function(e){var t;const i=r.SNAP_OPTIONS.find(t=>t.id===e);return null!==(t=null==i?void 0:i.ticksPerSnap)&&void 0!==t?t:1}(e))})]})]}))}},{"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Dropdown":162,"./types":237,"react/jsx-runtime":305}],226:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MeasureHeader=void 0;const n=e("react/jsx-runtime"),s=e("./utils"),o=e("./context"),r=e("react");i.MeasureHeader=({selection:e,onSelectionChange:t,addEventListeners:i,snapTicks:a})=>{const{measures:l,tickWidth:c,ticksPerBeat:u,beatsPerMeasure:h}=(0,o.usePianoRollTheme)(),d=(0,r.useRef)(null),p=(0,o.usePianoRollTheme)(),[g,f]=(0,r.useState)(void 0);(0,r.useEffect)(()=>{if(!d.current)return;const e=d.current;let i,n,o=!1;const r=(e,t)=>{f({startTick:Math.floor(Math.min(e,t)/a)*a,endTick:Math.ceil(Math.max(e,t)/a)*a})},l=t=>{const i=e.getBoundingClientRect();return(0,s.xToTick)(p,t-i.left+e.scrollLeft)},c=e=>{if(!o)return;const t=l(e.clientX);n=t,r(i,n)},u=e=>{o=!1;const s=Math.min(i,n),r=Math.max(i,n);s===r||void 0===r||Number.isNaN(s)||Number.isNaN(r)?t(void 0):t({startTick:s,endTick:r}),f(void 0),i=void 0,n=void 0,document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",u)},h=e=>{var t;e.preventDefault(),i=l(e.clientX),o=!0,document.addEventListener("pointermove",c),document.addEventListener("pointerup",u),r(i,i),null===(t=document.getElementById("piano-roll-workspace"))||void 0===t||t.focus()};return e.addEventListener("pointerdown",h),()=>{e.removeEventListener("pointerdown",h),document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",u)}},[t,p]),(0,r.useEffect)(()=>{if(d.current)return i(d.current)},[i]);const m=g||e;return(0,n.jsxs)("div",Object.assign({className:"measure-header",id:"measure-header",ref:d},{children:[(0,s.range)(0,l).map(e=>(0,n.jsx)("div",Object.assign({className:"measure",style:{width:c*u*h}},{children:e+1}),e+1)),m&&(0,n.jsx)("div",{id:"measure-header-selection",className:"selection",style:{left:(0,s.noteLeft)(p,m.startTick),width:(0,s.noteWidth)(p,m.endTick-m.startTick)}})]}))}},{"./context":236,"./utils":238,react:304,"react/jsx-runtime":305}],227:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.NoteEventView=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/util"),o=e("./context"),r=e("./utils");i.NoteEventView=e=>{const{event:t,isDrumTrack:i,type:a}=e,{duration:l,note:c,start:u,id:h}=t,d=(0,o.usePianoRollTheme)();return(0,n.jsx)("div",Object.assign({id:`note-${h}`,className:(0,s.classList)("note-event",a),style:{width:`${(0,r.noteWidth)(d,l)}px`,left:`${(0,r.noteLeft)(d,u)}px`,top:`${(0,r.noteTop)(d,c)}px`},"data-tick":u,"data-note":c},{children:i||l<=1?void 0:(0,r.getNoteName)(c)}))}},{"../../../../react-common/components/util":171,"./context":236,"./utils":238,"react/jsx-runtime":305}],228:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.OctaveWarningModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.OctaveWarningModal=e=>{const{trackId:t,onClose:i,onPaste:r}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Octave Warning"),onClose:i,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:i},{label:(0,o.lf)("Paste Anyway"),className:"red",onClick:()=>{r(t),i()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("The copied notes are outside the current track's octave range. If you paste, it will change the octave range of this track.")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],229:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoOctave=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("../musicEditor/playback"),a=e("./types"),l=e("./utils");i.PianoOctave=e=>{const{octave:t,selectedTrack:i,instrument:c}=e,u=(0,s.useRef)(null),h=(0,a.isDrumInstrument)(c);(0,s.useEffect)(()=>{const e=u.current;if(!e)return;const n=(n,s,o)=>{if(n!==i)return;if(h||s--,s<12*t||s>=12*(t+1))return;const r=e.querySelector(`#key-${s}`);r&&r.classList.toggle("active",o)};for(let i=0;i<12;i++){const n=11-i+12*t,s=e.querySelector(`#key-${n}`);s&&s.classList.toggle("active",!1)}return(0,r.addNoteChangeListener)(n),()=>{(0,r.removeNoteChangeListener)(n)}},[t,i,h]);const d=(0,s.useCallback)(async e=>{var t;const i=null===(t=u.current)||void 0===t?void 0:t.querySelector(`#key-${e}`);if(i&&i.classList.add("playing"),(0,a.isDrumInstrument)(c)){const t=c.drums[e];t&&await pxsim.music.playDrumAsync(t)}else await pxsim.music.playNoteAsync(e+1,c.instrument,300);i&&i.classList.remove("playing")},[c]);return(0,n.jsx)("div",Object.assign({className:"octave-sidebar",ref:u},{children:(0,l.range)(0,12).map(e=>{const i=11-e+12*t,s=(0,l.isBlackKey)(i),r=h?c.drums[i].name:(0,l.getNoteName)(i),a=(0,o.classList)(h?"drum":"key",s?"black":"white",(0,l.getNoteName)(i,!1).replace("#","sharp")),u=i%12&&!h?void 0:r;return(0,n.jsx)("div",Object.assign({id:`key-${i}`,className:a,title:r,onClick:()=>{d(i)}},{children:u}),i)})}))}},{"../../../../react-common/components/util":171,"../musicEditor/playback":219,"./types":237,"./utils":238,react:304,"react/jsx-runtime":305}],230:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoRollModel=i.PianoRoll=void 0;const n=e("react/jsx-runtime"),s=e("./context"),o=e("./Workspace"),r=e("./Sidebar"),a=e("react"),l=e("./types"),c=e("./Header"),u=e("./DeleteTrackModal"),h=e("./DeleteErrorModal"),d=e("./DrumWarningModal"),p=e("../musicEditor/playback"),g=e("../musicEditor/PlaybackControls"),f=e("./MeasureHeader"),m=e("./VelocityEditor"),_=e("../musicEditor/EditControls"),b=e("../../../../react-common/components/controls/Dropdown"),T=e("./Scrollbar"),E=e("../../../../react-common/components/util"),v=e("./clipboard"),y=e("./utils"),k=e("./OctaveWarningModal"),C=e("../musicEditor/AssetModel");i.PianoRoll=e=>((0,a.useEffect)(()=>()=>{(0,p.stopPlayback)()},[]),(0,n.jsx)(s.PianoRollThemeProvider,{children:(0,n.jsx)(S,Object.assign({},e))}));class I extends C.AssetModel{cloneValue(e){return{song:(0,l.cloneSong)(e.song),selectedTrackIndex:e.selectedTrackIndex,assetName:e.assetName}}cloneExtraState(e){return{velocityEditorVisible:null==e?void 0:e.velocityEditorVisible}}}i.PianoRollModel=I;const S=e=>{const{model:t,showEditControls:i,onDoneClicked:I,fieldEditorParams:S}=e,{state:A,dispatch:O}=(0,s.usePianoRollThemeContext)(),{value:w,hasUndo:N,hasRedo:R,extraState:x}=(0,C.useModelValue)(t),{song:L,selectedTrackIndex:D,assetName:M}=w,{velocityEditorVisible:B}=x,[P,F]=(0,a.useState)(null),[U,H]=(0,a.useState)(4),G=(0,a.useRef)(null);(0,a.useEffect)(()=>{const e={};(null==S?void 0:S.maxPolyphony)&&(e.maxPolyphony=S.maxPolyphony),(null==S?void 0:S.borderColor)&&(e.borderColor=S.borderColor),O(e)},[S,O]);const V=(e,i,n)=>{t.updateValue({song:e,selectedTrackIndex:null!=i?i:D,assetName:M},{pushUndo:null==n||n}),(0,p.isPlaying)()&&(0,p.updatePlaybackSongAsync)((0,l.toPXTSong)(e))},j=(0,a.useCallback)(e=>{const t=e=>{if("Escape"===e.key)L.floatingLayer&&(V((0,l.applyFloatingLayer)(L)),e.preventDefault(),e.stopPropagation());else if("Delete"===e.key||"Backspace"===e.key)L.floatingLayer&&(V((0,l.deleteFloatingLayer)(L)),e.preventDefault(),e.stopPropagation());else if("ArrowUp"===e.key||"ArrowDown"===e.key)L.floatingLayer&&(V((0,l.transposeFloatingLayer)(L,"ArrowUp"===e.key?1:-1)),e.preventDefault(),e.stopPropagation());else if(("ArrowLeft"===e.key||"ArrowRight"===e.key)&&L.floatingLayer){const t="ArrowLeft"===e.key?-1:1;V((0,l.moveFloatingLayer)(L,t)),e.preventDefault(),e.stopPropagation()}},i=e=>{if(L.floatingLayer){const t=L.floatingLayer,i=L.tracks.find(e=>e.id===L.floatingLayer.trackId);(0,v.setCopiedData)({events:t.events,startTick:t.startTick,endTick:t.endTick,isDrumTrack:(0,l.isDrumInstrument)(L.instruments.find(e=>e.id===i.instrumentId)),minOctave:i.minOctave,maxOctave:i.maxOctave}),e.preventDefault(),e.stopPropagation()}},n=e=>{if(L.floatingLayer){const t=L.floatingLayer,i=L.tracks.find(e=>e.id===L.floatingLayer.trackId);(0,v.setCopiedData)({events:t.events,startTick:t.startTick,endTick:t.endTick,isDrumTrack:(0,l.isDrumInstrument)(L.instruments.find(e=>e.id===i.instrumentId)),minOctave:i.minOctave,maxOctave:i.maxOctave}),e.preventDefault(),e.stopPropagation(),V((0,l.deleteFloatingLayer)(L))}},s=e=>{const t=L.tracks[D],i=L.instruments.find(e=>e.id===t.instrumentId),n=(0,v.getCopiedData)(void 0!==t.instrumentId&&(0,l.isDrumInstrument)(i));if(!n)return;const s=G.current;if(!s)return;const o=(0,y.xToTick)(A,s.scrollLeft),r=L.beatsPerMeasure*L.ticksPerBeat,a=Math.ceil(o/r)*r;if(!n.isDrumTrack){const i=Math.floor(n.events.reduce((e,t)=>Math.min(e,t.note),1/0)/12),s=Math.floor(n.events.reduce((e,t)=>Math.max(e,t.note),-1/0)/12);if(i<t.minOctave){if(!(i+2<=t.maxOctave&&i+2>=t.minOctave&&s+2<=t.maxOctave))return F({type:"octave-paste-warning",trackId:t.id}),e.preventDefault(),void e.stopPropagation();for(const e of n.events)e.note+=24}else if(s>t.maxOctave){if(!(s-2>=t.minOctave&&s-2<=t.maxOctave&&i-2>=t.minOctave))return F({type:"octave-paste-warning",trackId:t.id}),e.preventDefault(),void e.stopPropagation();for(const e of n.events)e.note-=24}}const c={trackId:t.id,startTick:a,endTick:a+(n.endTick-n.startTick),events:n.events.map(e=>Object.assign(Object.assign({},e),{id:t.nextId++,start:a+(e.start-n.startTick)}))};let u=(0,l.applyFloatingLayer)(L);u.floatingLayer=c,V(u)};return e.addEventListener("keydown",t),e.addEventListener("copy",i),e.addEventListener("paste",s),e.addEventListener("cut",n),()=>{e.removeEventListener("keydown",t),e.removeEventListener("copy",i),e.removeEventListener("paste",s),e.removeEventListener("cut",n)}},[V,L,D]),W=(e,t)=>{let i=(0,l.applyFloatingLayer)(L);V((0,l.changeTrackInstrument)(e,t,i))},K=(0,a.useCallback)(e=>{let t=L;if(L.floatingLayer&&(t=(0,l.applyFloatingLayer)(L)),!e)return void V(t,void 0,!1);const i=Object.assign({},e);(null==S?void 0:S.showSnapControls)&&(i.startTick=Math.floor(e.startTick/U)*U,i.endTick=Math.ceil(e.endTick/U)*U),V((0,l.selectionToFloatingLayer)(t,D,i),void 0,!1)},[U,null==S?void 0:S.showSnapControls,L]),Y=l.TIME_SIGNATURES.map(e=>({label:e.name,title:e.name,id:e.id})),z=l.TIME_SIGNATURES.find(e=>e.beatsPerMeasure===L.beatsPerMeasure&&e.ticksPerBeat===L.ticksPerBeat),X=()=>F(null),$=L.tracks[D],q=L.instruments.find(e=>e.id===$.instrumentId);let J,Z;J=void 0!==(null==S?void 0:S.minOctave)?S.minOctave:(0,l.isDrumInstrument)(q)?0:$.minOctave,Z=void 0!==(null==S?void 0:S.maxOctave)?S.maxOctave:(0,l.isDrumInstrument)(q)?1:$.maxOctave,(0,a.useEffect)(()=>{A.minOctave===J&&A.maxOctave===Z&&A.measures===L.measures&&A.beatsPerMeasure===L.beatsPerMeasure&&A.ticksPerBeat===L.ticksPerBeat||O({minOctave:J,maxOctave:Z,measures:L.measures,beatsPerMeasure:L.beatsPerMeasure,ticksPerBeat:L.ticksPerBeat})},[J,Z,A.minOctave,A.maxOctave,O,L.measures,L.beatsPerMeasure,L.ticksPerBeat]);const Q=(0,a.useCallback)(()=>{V((0,l.applyFloatingLayer)(L))},[L,V]),ee=(0,a.useCallback)((e,t)=>{L.floatingLayer&&V((0,l.moveFloatingLayer)((0,l.transposeFloatingLayer)(L,t),e))},[L,V]),te=!(null==S?void 0:S.hideHeader);return(0,n.jsxs)("div",Object.assign({className:(0,E.classList)("piano-roll",te?"show-header":"hide-header",B?"show-velocity-editor":"hide-velocity-editor")},{children:["delete-track"===(null==P?void 0:P.type)&&(0,n.jsx)(u.DeleteTrackModal,{trackId:P.trackId,onClose:X,onDelete:e=>{let t=(0,l.applyFloatingLayer)(L);V(Object.assign(Object.assign({},t),{tracks:t.tracks.filter(t=>t.id!==e)}),0)}}),"delete-error"===(null==P?void 0:P.type)&&(0,n.jsx)(h.DeleteErrorModal,{onClose:X}),"drum-warning"===(null==P?void 0:P.type)&&(0,n.jsx)(d.DrumWarningModal,{trackId:P.trackId,instrumentId:P.instrumentId,onClose:X,onConfirm:W}),"octave-paste-warning"===(null==P?void 0:P.type)&&(0,n.jsx)(k.OctaveWarningModal,{trackId:P.trackId,onClose:X,onPaste:e=>{const t=L.tracks.find(t=>t.id===e),i=L.instruments.find(e=>e.id===t.instrumentId),n=(0,v.getCopiedData)((0,l.isDrumInstrument)(i));if(!n||n.isDrumTrack)return;const s=G.current;if(!s)return;const o=(0,y.xToTick)(A,s.scrollLeft),r=L.beatsPerMeasure*L.ticksPerBeat,a=Math.ceil(o/r)*r,c=l.NOTE_RANGES.find(e=>"full"===e.id),u={trackId:e,startTick:a,endTick:a+(n.endTick-n.startTick),events:n.events.map(e=>Object.assign(Object.assign({},e),{id:t.nextId++,start:a+(e.start-n.startTick)}))};let h=(0,l.applyFloatingLayer)(L);h=(0,l.changeOctaves)(e,c.minOctave,c.maxOctave,h),h.floatingLayer=u,V(h)}}),te&&(0,n.jsx)("div",Object.assign({className:"header-container"},{children:(0,n.jsx)(c.Header,{song:L,selectedTrackId:$.id,velocityEditorVisible:B,snapTicks:U,showSnapControls:null==S?void 0:S.showSnapControls,onVelocityEditorToggle:()=>{t.updateExtraState({velocityEditorVisible:!x.velocityEditorVisible})},onTrackSelected:e=>{const t=L.tracks.findIndex(t=>t.id===e);L.floatingLayer?V((0,l.applyFloatingLayer)(L),t):V(L,t,!1)},onInstrumentSelected:(e,t)=>{const i=L.tracks.find(t=>t.id===e),n=L.instruments.find(e=>e.id===i.instrumentId),s=L.instruments.find(e=>e.id===t);(0,l.isDrumInstrument)(n)!==(0,l.isDrumInstrument)(s)&&i.events.length?F({type:"drum-warning",trackId:e,instrumentId:t}):W(e,t)},onTrackCreated:()=>{const e=(0,l.newTrack)(L.instruments[0].id,(0,l.applyFloatingLayer)(L)),t=e.tracks.length-1;V(e,t)},onTrackDeleted:e=>{const t=L.tracks.find(t=>t.id===e);1===L.tracks.length?F({type:"delete-error"}):(null==t?void 0:t.events.length)?F({type:"delete-track",trackId:e}):V(Object.assign(Object.assign({},L),{tracks:L.tracks.filter(t=>t.id!==e)}),0)},onOctavesChanged:(e,t)=>{let i=(0,l.applyFloatingLayer)(L);const n=i.tracks[D];n.minOctave===e&&n.maxOctave===t||(0,l.isDrumInstrument)(i.instruments.find(e=>e.id===n.instrumentId))||(O({minOctave:e,maxOctave:t}),V((0,l.changeOctaves)(n.id,e,t,i)))},onSnapChanged:H})})),(0,n.jsx)(f.MeasureHeader,{selection:L.floatingLayer,onSelectionChange:K,snapTicks:(null==S?void 0:S.showSnapControls)?U:1,addEventListeners:j}),(0,n.jsxs)("div",Object.assign({className:"scroll-container"},{children:[(0,n.jsxs)("div",Object.assign({className:"content-container"},{children:[(0,n.jsx)("div",Object.assign({className:"sidebar-container"},{children:(0,n.jsx)(r.Sidebar,{instrument:q,selectedTrackId:$.id,minOctave:J,maxOctave:Z})})),(0,n.jsxs)("div",Object.assign({ref:G,className:"workspace-container"},{children:[(0,n.jsx)(o.Workspace,{track:$,onEdit:e=>{V((0,l.updateTrack)(e,(0,l.applyFloatingLayer)(L)))},isDrumTrack:(0,l.isDrumInstrument)(q),playNote:e=>{const t=L.tracks[D],i=L.instruments.find(e=>e.id===t.instrumentId);if((0,l.isDrumInstrument)(i)){const t=i.drums[e];pxsim.music.playDrumAsync(t)}else pxsim.music.playNoteAsync(e+1,i.instrument,300)},maxTicks:L.measures*L.beatsPerMeasure*L.ticksPerBeat,snapTicks:(null==S?void 0:S.showSnapControls)?U:1,newNoteDuration:(null==S?void 0:S.showSnapControls)?U:1,bpm:L.tempo,floatingLayer:L.floatingLayer,updateFloatingLayer:ee,applyFloatingLayer:Q,addEventListeners:j}),(0,n.jsx)(T.Scrollbar,{horizontal:!0})]}))]})),(0,n.jsx)(T.Scrollbar,{})]})),B&&(0,n.jsx)(m.VelocityEditor,{notes:$.events,onNotesChange:e=>{let t=(0,l.applyFloatingLayer)(L);V((0,l.updateNoteEvents)(t,t.tracks[D].id,e))}}),(0,n.jsxs)("div",Object.assign({className:"footer"},{children:[(0,n.jsx)(g.PlaybackControls,{beatsPerMinute:L.tempo,measures:L.measures,onControlsClick:e=>{"play"===e?(0,p.startPlaybackAsync)((0,l.toPXTSong)(L),!1):"loop"===e?(0,p.startPlaybackAsync)((0,l.toPXTSong)(L),!0):(0,p.stopPlayback)()},onTempoChange:e=>{V(Object.assign(Object.assign({},L),{tempo:e}))},onMeasuresChanged:e=>{let t=(0,l.applyFloatingLayer)(L);V((0,l.changeMeasures)(e,t)),O({measures:e})},hasUndo:N,hasRedo:R,onUndoClick:()=>{t.undo()},onRedoClick:()=>{t.redo()},hideBassClefOption:!0,singlePlayButton:!0}),(null==S?void 0:S.showTimeSignature)&&(0,n.jsx)(b.Dropdown,{id:"time-signature-dropdown",items:Y,selectedId:null==z?void 0:z.id,onItemSelected:e=>{const t=l.TIME_SIGNATURES.find(t=>t.id===e);if(!t)return;const{beatsPerMeasure:i,ticksPerBeat:n}=t;let s=(0,l.applyFloatingLayer)(L);V((0,l.changeTimeSignature)(i,n,s)),O({beatsPerMeasure:i,ticksPerBeat:n})}}),(0,n.jsx)("div",{className:"spacer"}),i&&(0,n.jsx)(_.EditControls,{assetName:M,onAssetNameChanged:e=>{t.updateValue({song:L,selectedTrackIndex:D,assetName:e})},hideDoneButton:!I,onDoneClicked:I})]}))]}))}},{"../../../../react-common/components/controls/Dropdown":162,"../../../../react-common/components/util":171,"../musicEditor/AssetModel":206,"../musicEditor/EditControls":207,"../musicEditor/PlaybackControls":211,"../musicEditor/playback":219,"./DeleteErrorModal":222,"./DeleteTrackModal":223,"./DrumWarningModal":224,"./Header":225,"./MeasureHeader":226,"./OctaveWarningModal":228,"./Scrollbar":231,"./Sidebar":232,"./VelocityEditor":233,"./Workspace":234,"./clipboard":235,"./context":236,"./types":237,"./utils":238,react:304,"react/jsx-runtime":305}],231:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Scrollbar=void 0;const n=e("react/jsx-runtime"),s=e("react");i.Scrollbar=e=>{const{horizontal:t}=e,i=s.useRef(null),o=s.useRef(null);s.useEffect(()=>{const e=i.current,n=e.parentElement,s=o.current;if(!e||!n||!s)return()=>{};let r=()=>{const i=t?n.clientWidth:n.clientHeight,o=t?n.scrollWidth:n.scrollHeight;if(o<=i)return void(e.style.display="none");e.style.display="block";const r=Math.max(i/o*i,20),a=(t?n.scrollLeft:n.scrollTop)/(o-i)*(i-r-16)+8;t?(s.style.width=`${r}px`,s.style.transform=`translateX(${a}px)`):(s.style.height=`${r}px`,s.style.transform=`translateY(${a}px)`)};r(),requestAnimationFrame(r),n.addEventListener("scroll",r),window.addEventListener("resize",r);let a=!1,l=0,c=0;const u=e=>{e.preventDefault(),a=!0,l=t?e.clientX:e.clientY,c=t?n.scrollLeft:n.scrollTop,document.addEventListener("pointermove",h),document.addEventListener("pointerup",d)},h=e=>{if(!a)return;e.preventDefault();const i=(t?e.clientX:e.clientY)-l,o=t?n.clientWidth:n.clientHeight,r=i*((t?n.scrollWidth:n.scrollHeight)-o)/(o-(t?s.offsetWidth:s.offsetHeight)-16);t?n.scrollLeft=c+r:n.scrollTop=c+r},d=e=>{a=!1,document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",d)};s.addEventListener("pointerdown",u);const p=i=>{i.preventDefault();const o=e.getBoundingClientRect(),r=t?i.clientX-o.left:i.clientY-o.top,a=t?n.clientWidth:n.clientHeight,l=t?n.scrollWidth:n.scrollHeight,c=t?s.offsetWidth:s.offsetHeight,h=(t?n.scrollLeft:n.scrollTop)/(l-a)*(a-c-16)+8;r<h?t?n.scrollLeft-=a:n.scrollTop-=a:r>h+c&&(t?n.scrollLeft+=a:n.scrollTop+=a),u(i)};e.addEventListener("pointerdown",p);const g=new MutationObserver(r);g.observe(n,{childList:!0,subtree:!0});const f=new ResizeObserver(r);return f.observe(n),()=>{e.removeEventListener("pointerdown",p),s.removeEventListener("pointerdown",u),document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",d),n.removeEventListener("scroll",r),window.removeEventListener("resize",r),g.disconnect(),f.disconnect()}},[t]);return(0,n.jsx)("div",Object.assign({ref:i,className:"scrollbar "+(t?"horizontal":"vertical")},{children:(0,n.jsx)("div",{ref:o,className:"scrollbar-thumb"})}))}},{react:304,"react/jsx-runtime":305}],232:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Sidebar=void 0;const n=e("react/jsx-runtime"),s=e("./PianoOctave"),o=e("./utils");i.Sidebar=e=>{const{selectedTrackId:t,instrument:i,minOctave:r,maxOctave:a}=e,l=(0,o.range)(r,a+1);return l.reverse(),(0,n.jsx)("div",Object.assign({className:"sidebar"},{children:l.map(e=>(0,n.jsx)(s.PianoOctave,{octave:e,selectedTrack:t,instrument:i},e))}))}},{"./PianoOctave":229,"./utils":238,"react/jsx-runtime":305}],233:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.VelocityEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react"),r=e("../../../../react-common/components/util"),a=e("./context"),l=e("./utils");i.VelocityEditor=e=>{var t;const{notes:i,onNotesChange:r}=e,l=(0,a.usePianoRollTheme)(),{tickWidth:u,ticksPerBeat:h,beatsPerMeasure:d,measures:p}=l,[g,f]=(0,o.useState)(void 0),m=u*h*d*p,_=[],b=(0,o.useRef)(null);s.useEffect(()=>{if(!b.current)return;const e=document.getElementById("piano-roll-workspace");e&&(b.current.scrollLeft=e.parentElement.scrollLeft)},[]);for(const e of i){const i=_.find(t=>t.start===e.start);i?i.events.push(e):_.push({start:e.start,events:[e],velocity:null!==(t=e.velocity)&&void 0!==t?t:128})}const T=e=>{if(e!==g){if(g){const e=_.find(e=>e.start===g);if(e)for(const t of e.events){const e=document.getElementById(`note-${t.id}`);e&&e.classList.remove("highlighted")}}f(e);const t=_.find(t=>t.start===e);if(t)for(const e of t.events){const t=document.getElementById(`note-${e.id}`);t&&t.classList.add("highlighted")}}},E=e=>{if(g===e){const t=_.find(t=>t.start===e);if(t)for(const e of t.events){const t=document.getElementById(`note-${e.id}`);t&&t.classList.remove("highlighted")}f(void 0)}};return(0,n.jsxs)("div",Object.assign({id:"velocity-editor",className:"velocity-editor",ref:b},{children:[(0,n.jsx)("div",{className:"velocity-editor-sidebar"}),(0,n.jsx)("div",Object.assign({className:"velocity-sliders",style:{width:`${m}px`}},{children:_.map((e,t)=>(0,n.jsx)(c,{velocity:e.velocity,tick:e.start,highlighted:g===e.start,onHighlight:T,onHighlightEnd:E,onChange:t=>{r(e.events.map(e=>Object.assign(Object.assign({},e),{velocity:t})))}},e.start))}))]}))};const c=e=>{const{velocity:t,onChange:i,tick:s,onHighlight:c,onHighlightEnd:u,highlighted:h}=e,d=(0,a.usePianoRollTheme)(),p=lf("Change velocity for notes at tick {0}",s),g=t/128*100+"%",f=(0,o.useRef)(null);return(0,o.useEffect)(()=>{var e,t;const i=e=>{c(s)},n=e=>{u(s)};return null===(e=f.current)||void 0===e||e.addEventListener("pointerenter",i),null===(t=f.current)||void 0===t||t.addEventListener("pointerleave",n),()=>{var e,t;null===(e=f.current)||void 0===e||e.removeEventListener("pointerenter",i),null===(t=f.current)||void 0===t||t.removeEventListener("pointerleave",n)}},[c,u,s]),(0,n.jsx)("div",Object.assign({id:`velocity-slider-${s}`,className:(0,r.classList)("velocity-slider",h&&"highlighted"),style:{left:(0,l.noteLeft)(d,s)},ref:f},{children:(0,n.jsxs)("div",Object.assign({className:"velocity-slider-inner"},{children:[(0,n.jsx)("div",{className:"velocity-slider-view",style:{height:g}}),(0,n.jsx)("input",{type:"range","aria-orientation":"vertical","aria-label":p,min:0,step:8,max:128,value:t,onChange:e=>i(parseInt(e.target.value))})]}))}))}},{"../../../../react-common/components/util":171,"./context":236,"./utils":238,react:304,"react/jsx-runtime":305}],234:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Workspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../musicEditor/playback"),r=e("./context"),a=e("./NoteEvent"),l=e("./types"),c=e("./utils"),u=e("./workspaceBackground");i.Workspace=e=>{var t;const{track:i,onEdit:h,isDrumTrack:d,playNote:p,maxTicks:g,bpm:f,snapTicks:m,newNoteDuration:_,floatingLayer:b,updateFloatingLayer:T,applyFloatingLayer:E,addEventListeners:v}=e,y=(0,u.useWorkspaceBackground)(),k=(0,r.usePianoRollTheme)(),C=(0,s.useRef)(null),I=(0,s.useRef)(null),S=(0,s.useRef)(null),[A,O]=(0,s.useState)(0);return(0,s.useEffect)(()=>{var e,t,n,s,o,r,a,u;const f=null===(e=C.current)||void 0===e?void 0:e.parentElement,v=null===(t=null==f?void 0:f.parentElement)||void 0===t?void 0:t.parentElement,y=document.getElementById("measure-header"),I=document.getElementById("velocity-editor"),A=document.createElement("div");A.className="cursor",A.style.position="absolute",A.style.display="none",null===(n=C.current)||void 0===n||n.appendChild(A);const w=()=>{const e=(null==f?void 0:f.scrollLeft)||0;y&&(y.scrollLeft=e),I&&(I.scrollLeft=e)};null==f||f.addEventListener("scroll",w);const N=(e,t)=>{var i;const n=null===(i=C.current)||void 0===i?void 0:i.getBoundingClientRect();if(!n)return null;const s=e-n.left,o=t-n.top;return{note:(0,c.yToNote)(k,o),time:(0,c.xToTick)(k,s)}},R=(e,t)=>{const n=S.current.noteEvent,s=N(e,t);if(!s)return 1;const o=Math.ceil((s.time+1)/m)*m,r=(0,l.getMaxDuration)(n.note,n.start,i,g,k.maxPolyphony);return Math.max(1,Math.min(r,o-n.start))},x=(e,t)=>{const{note:n,time:s}=N(e,t)||{};if(void 0!==n&&void 0!==s)return i.events.find(e=>e.note===n&&e.start<=s&&s<e.start+e.duration)},L=e=>{if(!S.current){if(x(e.clientX,e.clientY))A.style.display="none";else{A.style.display="block";const t=N(e.clientX,e.clientY);if(t){const e=m>1?Math.floor(t.time/m)*m:t.time;t.time=e;const n=d?1:Math.min((0,l.getMaxDuration)(t.note,t.time,i,g,k.maxPolyphony),_);A.style.left=`${(0,c.noteLeft)(k,t.time)}px`,A.style.top=`${(0,c.noteTop)(k,t.note)}px`,A.style.width=`${(0,c.noteWidth)(k,n)}px`}}return}A.style.display="none";const t=e.clientX-S.current.startX,n=e.clientY-S.current.startY;if(S.current.isScrolling||(Math.abs(t)>10||Math.abs(n)>10)&&(S.current.isScrolling=!0),S.current.isScrolling)if(S.current.isMove){(e=>{if(!b)return;const t=document.getElementById("measure-header-selection"),i=b.startTick+e;t&&(t.style.left=`${(0,c.noteLeft)(k,i)}px`),O(e)})(Math.round(t/(0,c.noteWidth)(k,1)))}else if(!S.current.noteEvent||d)(e=>{const t=S.current.startScrollX-e;f&&(f.scrollLeft=t)})(t),(e=>{const t=S.current.startScrollY-e;v&&(v.scrollTop=t)})(n);else{const t=S.current.noteEvent;S.current.noteElement||(S.current.noteElement=document.getElementById(`note-${t.id}`)),S.current.noteElement&&(S.current.noteElement.style.width=`${(0,c.noteWidth)(k,R(e.clientX,e.clientY))}px`)}},D=e=>{const{time:t}=N(e.clientX,e.clientY)||{};S.current={startX:e.clientX,startY:e.clientY,startScrollX:(null==f?void 0:f.scrollLeft)||0,startScrollY:(null==v?void 0:v.scrollTop)||0,noteEvent:x(e.clientX,e.clientY),isMove:b&&t>b.startTick&&t<b.endTick},b&&!S.current.isMove&&E(),L(e)},M=e=>{L(e)},B=e=>{if(O(0),S.current){if(L(e),S.current.isScrolling)S.current.isMove?T(Math.round((e.clientX-S.current.startX)/(0,c.noteWidth)(k,1)),0):S.current.noteEvent&&!d&&h((0,l.changeNoteEventDuration)(S.current.noteEvent.id,R(e.clientX,e.clientY),i,g,k.maxPolyphony));else if(S.current.isMove)E();else if(S.current.noteEvent)h(Object.assign(Object.assign({},i),{events:i.events.filter(e=>{var t;return e!==(null===(t=S.current)||void 0===t?void 0:t.noteEvent)})}));else{const e=N(S.current.startX,S.current.startY);if(e){const t=m>1?Math.floor(e.time/m)*m:e.time;e.time=t,h((0,l.newNoteEvent)(e.note,e.time,_,i,d,g,k.maxPolyphony)),p(e.note)}}S.current=null}else A.style.display="none"};return null===(s=C.current)||void 0===s||s.addEventListener("pointerdown",D),null===(o=C.current)||void 0===o||o.addEventListener("pointermove",M),null===(r=C.current)||void 0===r||r.addEventListener("pointerup",B),null===(a=C.current)||void 0===a||a.addEventListener("pointercancel",B),null===(u=C.current)||void 0===u||u.addEventListener("pointerleave",B),()=>{var e,t,i,n,s,o;null===(e=C.current)||void 0===e||e.removeEventListener("pointerdown",D),null===(t=C.current)||void 0===t||t.removeEventListener("pointermove",M),null===(i=C.current)||void 0===i||i.removeEventListener("pointerup",B),null===(n=C.current)||void 0===n||n.removeEventListener("pointercancel",B),null===(s=C.current)||void 0===s||s.removeEventListener("pointerleave",B),null===(o=C.current)||void 0===o||o.removeChild(A),null==f||f.removeEventListener("scroll",w)}},[i,h,k.minOctave,k.maxOctave,d,m,g,b,T,E]),(0,s.useEffect)(()=>{const e=pxsim.music.tickToMs(f,k.ticksPerBeat,1),t=(0,c.noteWidth)(k,1);let i,n,s=0,r=!1;const a=e=>{s=(0,c.noteWidth)(k,e),n=Date.now(),r||(r=!0,I.current&&(I.current.style.left=`${s}px`,I.current.style.display="unset"),i=requestAnimationFrame(u))},l=()=>{r=!1,I.current&&(I.current.style.display="none"),i&&cancelAnimationFrame(i)},u=()=>{const o=s+t*(Date.now()-n)/e;I.current&&(I.current.style.left=`${o}px`),r&&(i=requestAnimationFrame(u))};return(0,o.addTickListener)(a),(0,o.addPlaybackStateListener)(l),()=>{(0,o.removeTickListener)(a),(0,o.removePlaybackStateListener)(l),i&&cancelAnimationFrame(i)}},[k,f]),(0,s.useEffect)(()=>{O(0)},[b]),(0,s.useEffect)(()=>{if(C.current)return v(C.current)},[v]),(0,n.jsxs)("div",Object.assign({className:"workspace",id:"piano-roll-workspace",style:{backgroundImage:y,backgroundSize:`${k.tickWidth*k.ticksPerBeat}px ${7*k.whiteKeyHeight}px`,width:(0,c.workspaceWidth)(k),height:(0,c.workspaceHeight)(k)},ref:C,tabIndex:0},{children:[(0,n.jsx)("div",{className:"playhead",ref:I}),i.events.map((e,t)=>(0,n.jsx)(a.NoteEventView,{event:e,isDrumTrack:d},t)),null===(t=null==b?void 0:b.events)||void 0===t?void 0:t.map((e,t)=>(0,n.jsx)(a.NoteEventView,{event:Object.assign(Object.assign({},e),{start:e.start+A}),isDrumTrack:d,type:"floating"},`floating-${t}`)),b&&(0,n.jsx)("div",{id:"workspace-selection",className:"selection",style:{left:(0,c.noteLeft)(k,b.startTick+A),width:(0,c.noteWidth)(k,b.endTick-b.startTick)}})]}))}},{"../musicEditor/playback":219,"./NoteEvent":227,"./context":236,"./types":237,"./utils":238,"./workspaceBackground":239,react:304,"react/jsx-runtime":305}],235:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getCopiedData=i.setCopiedData=void 0,i.setCopiedData=function(e){const t=JSON.stringify(e);e.isDrumTrack?localStorage.setItem("piano-roll-drum-copy",t):localStorage.setItem("piano-roll-copy",t)},i.getCopiedData=function(e){const t=e?localStorage.getItem("piano-roll-drum-copy"):localStorage.getItem("piano-roll-copy");if(t)try{return JSON.parse(t)}catch(e){return void console.error("Failed to parse copied data",e)}}},{}],236:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.usePianoRollThemeContext=i.usePianoRollTheme=i.PianoRollThemeProvider=i.PianoRollContext=void 0;const n=e("react/jsx-runtime"),s=e("react"),o={tickWidth:15,whiteKeyHeight:40,ticksPerBeat:4,beatsPerMeasure:4,measures:4,minOctave:3,maxOctave:5,maxPolyphony:1/0,gridLineColor:"#283547",whiteKeyWorkspaceColor:"#405470",blackKeyWorkspaceColor:"#36475f"};function r(e,t){return Object.assign(Object.assign({},e),t)}i.PianoRollContext=(0,s.createContext)({state:void 0,dispatch:void 0}),i.PianoRollThemeProvider=function(e){const[t,a]=(0,s.useReducer)(r,o),l={state:t,dispatch:a},c=(0,s.useRef)(null);return(0,s.useEffect)(()=>{const e=getComputedStyle(c.current),t=e.getPropertyValue("--workspace-grid-line-color"),i=e.getPropertyValue("--workspace-white-key-color"),n=e.getPropertyValue("--workspace-black-key-color");t===l.state.gridLineColor&&i===l.state.whiteKeyWorkspaceColor&&n===l.state.blackKeyWorkspaceColor||a({gridLineColor:t,whiteKeyWorkspaceColor:i,blackKeyWorkspaceColor:n})},[]),(0,s.useEffect)(()=>{const e=[`--tick-width: ${l.state.tickWidth}px`,`--white-key-height: ${l.state.whiteKeyHeight}px`];l.state.borderColor&&e.push(`--piano-roll-border-color: ${l.state.borderColor}`),c.current.setAttribute("style",e.join("; "))},[l.state.tickWidth,l.state.whiteKeyHeight,l.state.borderColor]),(0,n.jsx)(i.PianoRollContext.Provider,Object.assign({value:l},{children:(0,n.jsx)("div",Object.assign({className:"piano-roll-root",ref:c},{children:e.children}))}))},i.usePianoRollTheme=function(){return(0,s.useContext)(i.PianoRollContext).state},i.usePianoRollThemeContext=function(){return(0,s.useContext)(i.PianoRollContext)}},{react:304,"react/jsx-runtime":305}],237:[function(e,t,i){"use strict";function n(){const e=pxt.assets.music.getEmptySong(4);let t=0;const i=e.tracks.map(e=>(t=Math.max(t,e.id+1),e.drums?{id:e.id,name:e.name,minOctave:0,maxOctave:1,drums:e.drums}:{id:e.id,name:e.name,instrument:e.instrument,minOctave:3,maxOctave:5}));return{nextInstrumentId:t,instruments:i,beatsPerMeasure:4,ticksPerBeat:8,tracks:[{instrumentId:0,events:[],nextId:0,id:0,minOctave:3,maxOctave:5}],measures:2,tempo:120}}function s(e,t,i,n,s){let o=[];for(const n of i.events)if(n.start!==t||n.note!==e){if(o.push(n),n.start>=t&&(n.note===e||o.length>=s))return n.start-t;o=o.filter(e=>e.start+e.duration<n.start)}return n-t}function o(e){let t=0;for(;e.tracks.some(e=>e.id===t);)t++;return t}function r(e,t){const i=t.tracks.findIndex(t=>t.id===e.id);return-1===i?t:Object.assign(Object.assign({},t),{tracks:[...t.tracks.slice(0,i),e,...t.tracks.slice(i+1)]})}function a(e){return void 0!==e.drums}function l(e,t){var i,n;if(a(t))return[{id:e.id,name:t.name,notes:e.events.map(e=>({startTick:e.start,endTick:e.start+e.duration,notes:[{note:e.note,enharmonicSpelling:"normal"}],velocity:e.velocity})),instrument:void 0,drums:t.drums}];let s=(null===(i=e.events[0])||void 0===i?void 0:i.note)||0,o=(null===(n=e.events[0])||void 0===n?void 0:n.note)||0;for(const t of e.events)s=Math.min(s,t.note),o=Math.max(o,t.note);s++,o++;const r=[],c=Math.floor(s/12);if(o-12*c>=64)return r.push(...l(Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.note<64)}),t)),r.push(...l(Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.note>=64)}),t)),r;const u=c+2;return[{id:e.id,name:t.name,notes:e.events.map(e=>({startTick:e.start,endTick:e.start+e.duration,notes:[{note:e.note+1,enharmonicSpelling:"normal"}],velocity:e.velocity})),instrument:Object.assign(Object.assign({},t.instrument),{octave:u}),drums:void 0}]}function c(e,t){return e.waveform===t.waveform&&(!!u(e.ampEnvelope,t.ampEnvelope)&&(!!u(e.pitchEnvelope,t.pitchEnvelope)&&(!!h(e.ampLFO,t.ampLFO)&&!!h(e.pitchLFO,t.pitchLFO))))}function u(e,t){return e===t||(e?t?e.attack===t.attack&&(e.decay===t.decay&&(e.sustain===t.sustain&&(e.release===t.release&&e.amplitude===t.amplitude))):0===e.amplitude:!t||0===t.amplitude)}function h(e,t){return e===t||(e?t?e.frequency===t.frequency&&e.amplitude===t.amplitude:0===e.amplitude:!t||0===t.amplitude)}function d(e){if(!e.floatingLayer)return e;const t=e.tracks.find(t=>t.id===e.floatingLayer.trackId);if(!t)return e;const i={startTick:e.floatingLayer.startTick,endTick:e.floatingLayer.endTick,events:e.floatingLayer.events,isDrumTrack:a(e.instruments.find(e=>e.id===t.instrumentId))},n=m(e,e.floatingLayer.trackId,i,e.floatingLayer.startTick);return n.floatingLayer=void 0,n}function p(e,t){return e.start>=t.startTick&&e.start+e.duration<=t.endTick}function g(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n];return r(Object.assign(Object.assign({},s),{events:s.events.filter(e=>!p(e,i))}),e)}function f(e,t,i){const n=e.tracks.find(e=>e.id===t);if(!n)return;const s=n.events.filter(e=>p(e,i)).map(e=>Object.assign({},e));return{startTick:i.startTick,endTick:i.endTick,events:s,isDrumTrack:a(e.instruments.find(e=>e.id===n.instrumentId)),minOctave:n.minOctave,maxOctave:n.maxOctave}}function m(e,t,i,n){const s=e.tracks.findIndex(e=>e.id===t);if(-1===s)return e;const o=e.tracks[s],a=e.measures*e.beatsPerMeasure*e.ticksPerBeat,l=n-i.startTick;let c=i.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+l,id:o.nextId++}));for(const e of c)e.duration=Math.min(e.duration,a-e.start),e.start=Math.max(0,e.start);c=c.filter(e=>e.start<a&&e.start+e.duration>0);const u=Object.assign(Object.assign({},e.tracks[s]),{events:o.events.map(e=>Object.assign({},e))});for(const e of c)for(const t of u.events)if(t.note===e.note&&!(t.start+t.duration<=e.start)){if(t.start>=e.start+e.duration)break;t.start<=e.start&&t.start+t.duration>e.start?t.duration=e.start-t.start:t.start>e.start&&(t.duration=t.start+t.duration-(e.start+e.duration),t.start=e.start+e.duration)}u.events=u.events.filter(e=>e.duration>0);let h=0;for(let e=0;e<u.events.length;e++){const t=c[h];if(!t)break;t.start<u.events[e].start&&(u.events.splice(e,0,t),h++,e++)}return h<c.length&&u.events.push(...c.slice(h)),r(u,e)}function _(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{events:e.events.map(e=>Object.assign({},e))})),floatingLayer:e.floatingLayer?Object.assign(Object.assign({},e.floatingLayer),{events:e.floatingLayer.events.map(e=>Object.assign({},e))}):void 0})}Object.defineProperty(i,"__esModule",{value:!0}),i.cloneSong=i.pasteToFloatingLayer=i.pasteCopyData=i.getCopyData=i.moveSelection=i.transposeSelection=i.deleteSelection=i.isInSelection=i.moveFloatingLayer=i.transposeFloatingLayer=i.selectionToFloatingLayer=i.deleteFloatingLayer=i.applyFloatingLayer=i.changeTimeSignature=i.fromPXTSong=i.toPXTSong=i.isMelodicInstrument=i.isDrumInstrument=i.changeOctaves=i.changeMeasures=i.changeTrackInstrument=i.updateNoteEvents=i.updateNoteEvent=i.updateTrack=i.newTrack=i.changeNoteEventDuration=i.newNoteEvent=i.getMaxDuration=i.getNextNoteEvent=i.getEmptySong=i.NOTE_RANGES=i.SNAP_OPTIONS=i.TIME_SIGNATURES=i.lf=void 0,i.lf=pxt.U.lf,i.TIME_SIGNATURES=[{name:(0,i.lf)("4/4"),id:"ts4-4",beatsPerMeasure:4,ticksPerBeat:8},{name:(0,i.lf)("3/4"),id:"ts3-4",beatsPerMeasure:3,ticksPerBeat:8},{name:(0,i.lf)("2/4"),id:"ts2-4",beatsPerMeasure:2,ticksPerBeat:8},{name:(0,i.lf)("3/8"),id:"ts3-8",beatsPerMeasure:3,ticksPerBeat:4},{name:(0,i.lf)("6/8"),id:"ts6-8",beatsPerMeasure:6,ticksPerBeat:4},{name:(0,i.lf)("12/8"),id:"ts12-8",beatsPerMeasure:12,ticksPerBeat:4}],i.SNAP_OPTIONS=[{name:(0,i.lf)("1/4"),id:"quarter",ticksPerSnap:8},{name:(0,i.lf)("1/8"),id:"eighth",ticksPerSnap:4},{name:(0,i.lf)("1/16"),id:"sixteenth",ticksPerSnap:2},{name:(0,i.lf)("1/32"),id:"thirty-second",ticksPerSnap:1}],i.NOTE_RANGES=[{name:(0,i.lf)("Treble"),id:"treble",minOctave:3,maxOctave:5},{name:(0,i.lf)("Bass"),id:"bass",minOctave:0,maxOctave:3},{name:(0,i.lf)("Full"),id:"full",minOctave:0,maxOctave:7}],i.getEmptySong=n,i.getNextNoteEvent=function(e,t,i,n){return i.events.find(i=>i.note===e&&i.start>t)},i.getMaxDuration=s,i.newNoteEvent=function(e,t,i,n,o,r,a){return function(e,t){for(let i=0;i<t.events.length;i++)if(t.events[i].start>e.start)return Object.assign(Object.assign({},t),{events:[...t.events.slice(0,i),e,...t.events.slice(i)]});return Object.assign(Object.assign({},t),{events:[...t.events,e]})}({id:(n=function(e,t,i){if(i===1/0)return t;const n=t.events.filter(t=>t.start<=e&&t.start+t.duration>e);if(n.length<i)return t;const s=n.reduce((e,t)=>e.start>t.start?e:t);return Object.assign(Object.assign({},t),{events:t.events.filter(e=>e.id!==s.id)})}(t,n,a)).nextId++,note:e,start:t,duration:o?1:Math.min(i,s(e,t,n,r,a)),velocity:128},n)},i.changeNoteEventDuration=function(e,t,i,n,o){const r=i.events.findIndex(t=>t.id===e);if(-1===r)return i;const a=i.events[r],l=s(a.note,a.start,i,n,o),c=Object.assign(Object.assign({},a),{duration:Math.max(1,Math.min(t,l))});return Object.assign(Object.assign({},i),{events:[...i.events.slice(0,r),c,...i.events.slice(r+1)]})},i.newTrack=function(e,t){const n=i.NOTE_RANGES.find(e=>"treble"===e.id),s={instrumentId:e,events:[],id:o(t),nextId:0,minOctave:n.minOctave,maxOctave:n.maxOctave};return Object.assign(Object.assign({},t),{tracks:[...t.tracks,s]})},i.updateTrack=r,i.updateNoteEvent=function(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n],o=s.events.findIndex(e=>e.id===i.id);return-1===o?e:r(Object.assign(Object.assign({},s),{events:[...s.events.slice(0,o),i,...s.events.slice(o+1)]}),e)},i.updateNoteEvents=function(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n];return r(Object.assign(Object.assign({},s),{events:s.events.map(e=>{const t=i.find(t=>t.id===e.id);return t||e})}),e)},i.changeTrackInstrument=function(e,t,i){const n=i.tracks.findIndex(t=>t.id===e),s=Object.assign({},i.tracks[n]),o=i.instruments.find(e=>e.id===s.instrumentId),l=i.instruments.find(e=>e.id===t);return a(o)!==a(l)&&(s.events=[]),s.instrumentId=t,r(s,i)},i.changeMeasures=function(e,t){const i=e*t.beatsPerMeasure*t.ticksPerBeat;return Object.assign(Object.assign({},t),{measures:e,tracks:t.tracks.map(e=>Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.start<i).map(e=>Object.assign(Object.assign({},e),{duration:Math.min(e.duration,i-e.start)}))}))})},i.changeOctaves=function(e,t,i,n){const s=n.tracks.findIndex(t=>t.id===e),o=n.tracks[s];return Object.assign(Object.assign({},n),{tracks:[...n.tracks.slice(0,s),Object.assign(Object.assign({},o),{minOctave:t,maxOctave:i,events:o.events.filter(e=>e.note>=12*t&&e.note<12*i)}),...n.tracks.slice(s+1)]})},i.isDrumInstrument=a,i.isMelodicInstrument=function(e){return void 0!==e.instrument},i.toPXTSong=function(e){return{ticksPerBeat:(e=d(e)).ticksPerBeat,beatsPerMeasure:e.beatsPerMeasure,beatsPerMinute:e.tempo,measures:e.measures,tracks:e.tracks.reduce((t,i)=>{const n=e.instruments.find(e=>e.id===i.instrumentId);return t.push(...l(i,n)),t},[])}},i.fromPXTSong=function(e){var t;const s=n();s.measures=e.measures,s.tempo=e.beatsPerMinute,s.tracks=[],s.beatsPerMeasure=e.beatsPerMeasure,s.ticksPerBeat=e.ticksPerBeat;let o=0;for(const n of e.tracks.filter(e=>e.notes.length>0)){const e=s.tracks.find(e=>e.id===n.id),r=e||{id:n.id,instrumentId:0,events:[],nextId:0,minOctave:7,maxOctave:0},l=(e,t,i,s)=>{var o;const a={id:r.nextId++,note:(null===(o=n.drums)||void 0===o?void 0:o.length)?e:Math.max(e-1,0),start:t,duration:i-t,velocity:null!=s?s:128};r.events.push(a);const l=Math.floor(a.note/12);r.minOctave=Math.min(r.minOctave,l),r.maxOctave=Math.max(r.maxOctave,l)};if(null===(t=n.drums)||void 0===t?void 0:t.length)r.instrumentId=s.instruments.find(e=>a(e)).id;else{const e=s.instruments.find(e=>!a(e)&&c(e.instrument,n.instrument));if(e)r.instrumentId=e.id;else{const e={id:s.nextInstrumentId++,name:(0,i.lf)("Instrument {0}",o++),instrument:n.instrument};s.instruments.push(e),r.instrumentId=e.id}}for(const e of n.notes)for(const t of e.notes)l(t.note,e.startTick,e.endTick,e.velocity);const u=i.NOTE_RANGES.find(e=>e.minOctave<=r.minOctave&&e.maxOctave>=r.maxOctave);u&&(r.minOctave=u.minOctave,r.maxOctave=u.maxOctave),(!e&&r.events.length>0||0===s.tracks.length)&&s.tracks.push(r)}return 0===s.tracks.length&&s.tracks.push({id:0,instrumentId:s.instruments[0].id,events:[],nextId:0,minOctave:i.NOTE_RANGES[0].minOctave,maxOctave:i.NOTE_RANGES[0].maxOctave}),s},i.changeTimeSignature=function(e,t,i){const n=i.measures*i.beatsPerMeasure*i.ticksPerBeat,s=Math.ceil(n/(e*t));return Object.assign(Object.assign({},i),{measures:s,beatsPerMeasure:e,ticksPerBeat:t})},i.applyFloatingLayer=d,i.deleteFloatingLayer=function(e){if(!e.floatingLayer)return e;const t=_(e);return t.floatingLayer=void 0,t},i.selectionToFloatingLayer=function(e,t,i){const n=d(e),s=f(n,t,i);return n.floatingLayer={events:s.events,startTick:s.startTick,endTick:s.endTick,trackId:t},g(n,t,i)},i.transposeFloatingLayer=function(e,t){if(!e.floatingLayer||!t)return e;const i=_(e);return i.floatingLayer.events=i.floatingLayer.events.map(e=>Object.assign(Object.assign({},e),{note:e.note+t})),i},i.moveFloatingLayer=function(e,t){if(!e.floatingLayer||!t)return e;const i=_(e);return i.floatingLayer.startTick+=t,i.floatingLayer.endTick+=t,i.floatingLayer.events=i.floatingLayer.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+t})),i},i.isInSelection=p,i.deleteSelection=g,i.transposeSelection=function(e,t,i,n){const s=e.tracks.findIndex(e=>e.id===t);if(-1===s)return e;const o=e.tracks[s];return r(Object.assign(Object.assign({},o),{events:o.events.map(e=>p(e,i)?Object.assign(Object.assign({},e),{note:e.note+n}):e)}),e)},i.moveSelection=function(e,t,i,n){if(-1===e.tracks.findIndex(e=>e.id===t))return e;const s=f(e,t,i);return m(g(e,t,i),t,s,i.startTick+n)},i.getCopyData=f,i.pasteCopyData=m,i.pasteToFloatingLayer=function(e,t,i,n){const s=_(e),o=n-i.startTick,r=i.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+o}));return s.floatingLayer={events:r,startTick:n,endTick:n+(i.endTick-i.startTick),trackId:t},s},i.cloneSong=_},{}],238:[function(e,t,i){"use strict";function n(e){return s(e)/12}function s(e){return 7*e.whiteKeyHeight}function o(e){return 12*(e.maxOctave+1)-1}Object.defineProperty(i,"__esModule",{value:!0}),i.minNote=i.maxNote=i.yToNote=i.xToTick=i.workspaceWidth=i.workspaceHeight=i.octaveHeight=i.noteHeight=i.noteTop=i.noteLeft=i.noteWidth=i.range=i.getNoteName=i.isBlackKey=void 0,i.isBlackKey=function(e){return[1,3,6,8,10].includes(e%12)},i.getNoteName=function(e,t=!0){const i=e%12,n=Math.floor(e/12)+1,s=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];return t?`${s[i]}${n}`:s[i]},i.range=function(e,t){return Array.from({length:t-e},(t,i)=>e+i)},i.noteWidth=function(e,t){return e.tickWidth*t+1},i.noteLeft=function(e,t){return e.tickWidth*t},i.noteTop=function(e,t){return(o(e)-t)*n(e)},i.noteHeight=n,i.octaveHeight=s,i.workspaceHeight=function(e){return(e.maxOctave-e.minOctave+1)*s(e)},i.workspaceWidth=function(e){return e.measures*e.ticksPerBeat*e.beatsPerMeasure*e.tickWidth},i.xToTick=function(e,t){return Math.floor(t/e.tickWidth)},i.yToNote=function(e,t){return o(e)-Math.floor(t/n(e))},i.maxNote=o,i.minNote=function(e){return 12*e.minOctave}},{}],239:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useWorkspaceBackground=void 0;const n=e("react"),s=e("./context");function o(e){return`url("data:image/svg+xml,${encodeURIComponent(function(e,t,i,n="#1e343d",s="#2e4c58",o="#36535f"){return`\n<svg xmlns="http://www.w3.org/2000/svg" width="${e*t}" height="${i}">\n <defs>\n <pattern id="grid" width="${2*e}" height="${i/12}" patternUnits="userSpaceOnUse">\n <rect width="1" height="${i/12}" fill="${n}" />\n <rect width="${2*e}" height="1" fill="${n}" />\n </pattern>\n <pattern id="grid2" width="${e*t}" height="${i/12}" patternUnits="userSpaceOnUse">\n <rect width="2" height="${i/12}" fill="${n}" />\n </pattern>\n </defs>\n <rect width="100%" height="100%" fill="${o}" />\n ${[1,3,5,8,10].map(e=>`<rect x="0" y="${i/12*e}" width="100%" height="${i/12}" fill="${s}" />`).join("")}\n <rect width="100%" height="100%" fill="url(#grid)" />\n <rect width="100%" height="100%" fill="url(#grid2)" />\n <rect x="0" y="0" width="4" height="100%" fill="${n}" />\n</svg>\n`.trim().replace(/\s+/g," ")}(e.tickWidth,e.ticksPerBeat,7*e.whiteKeyHeight,e.gridLineColor,e.blackKeyWorkspaceColor,e.whiteKeyWorkspaceColor))}")`}i.useWorkspaceBackground=function(){const e=(0,s.usePianoRollTheme)(),[t,i]=(0,n.useState)(o(e));return(0,n.useEffect)(()=>{i(o(e))},[e.tickWidth,e.ticksPerBeat,e.whiteKeyHeight,e.gridLineColor,e.blackKeyWorkspaceColor,e.whiteKeyWorkspaceColor]),t}},{"./context":236,react:304}],240:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ariaAnnounce=i.fireClickOnEnter=void 0,i.fireClickOnEnter=function(e){const t="number"==typeof e.which?e.which:e.keyCode;13!==t&&32!==t||(e.preventDefault(),e.currentTarget.click())};let n=!1;i.ariaAnnounce=function(e,t,i){const s=document.getElementById("pxt-aria-live");s&&e&&(s.textContent=`${e}${n?"":""}`,n=!n,s.ariaLive=null!=t?t:"polite",s.setAttribute("role",null!=i?i:null))}},{}],241:[function(e,t,i){var n=e("./toPropertyKey.js");t.exports=function(e,t,i){return(t=n(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e},t.exports.__esModule=!0,t.exports.default=t.exports},{"./toPropertyKey.js":248}],242:[function(e,t,i){function n(){return t.exports=n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)({}).hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,n.apply(null,arguments)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports},{}],243:[function(e,t,i){t.exports=function(e){return e&&e.__esModule?e:{default:e}},t.exports.__esModule=!0,t.exports.default=t.exports},{}],244:[function(e,t,i){var n=e("./typeof.js").default;function s(e,i){if("function"==typeof WeakMap)var o=new WeakMap,r=new WeakMap;return(t.exports=s=function(e,t){if(!t&&e&&e.__esModule)return e;var i,s,a={__proto__:null,default:e};if(null===e||"object"!=n(e)&&"function"!=typeof e)return a;if(i=t?r:o){if(i.has(e))return i.get(e);i.set(e,a)}for(var l in e)"default"!==l&&{}.hasOwnProperty.call(e,l)&&((s=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,l))&&(s.get||s.set)?i(a,l,s):a[l]=e[l]);return a},t.exports.__esModule=!0,t.exports.default=t.exports)(e,i)}t.exports=s,t.exports.__esModule=!0,t.exports.default=t.exports},{"./typeof.js":249}],245:[function(e,t,i){var n=e("./defineProperty.js");function s(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)}return i}t.exports=function(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?s(Object(i),!0).forEach(function(t){n(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e},t.exports.__esModule=!0,t.exports.default=t.exports},{"./defineProperty.js":241}],246:[function(e,t,i){t.exports=function(e,t){if(null==e)return{};var i={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;i[n]=e[n]}return i},t.exports.__esModule=!0,t.exports.default=t.exports},{}],247:[function(e,t,i){var n=e("./typeof.js").default;t.exports=function(e,t){if("object"!=n(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var s=i.call(e,t||"default");if("object"!=n(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},t.exports.__esModule=!0,t.exports.default=t.exports},{"./typeof.js":249}],248:[function(e,t,i){var n=e("./typeof.js").default,s=e("./toPrimitive.js");t.exports=function(e){var t=s(e,"string");return"symbol"==n(t)?t:t+""},t.exports.__esModule=!0,t.exports.default=t.exports},{"./toPrimitive.js":247,"./typeof.js":249}],249:[function(e,t,i){function n(e){return t.exports=n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,n(e)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports},{}],250:[function(e,t,i){
|
|
6
|
+
*/Object.defineProperty(i,"__esModule",{value:!0}),i.setDuplicateOnDragStrategy=i.DuplicateOnDragStrategy=void 0;const n=e("blockly"),s=e("./duplicateOnDrag");class o extends n.dragging.BlockDragStrategy{getTargetBlock(){const e=this;return e.block.isShadow()&&(0,s.isAllowlistedShadow)(e.block)?e.block:super.getTargetBlock()}drag(e,t){if(super.drag(e,t),!t||t instanceof PointerEvent){this.block.moveDuringDrag(e)}}disconnectBlock(e){var t;const i=this;let o,r,a;const l=i.block.isShadow();if(l&&i.block.setShadow(!1),(0,s.shouldDuplicateOnDrag)(i.block)){const e=i.block.outputConnection;if(!(null==e?void 0:e.targetConnection))return;a=n.Xml.blockToDom(i.block,!0),l||(o=n.Xml.domToBlock(a,i.block.workspace)),r=e.targetConnection}e&&(i.startChildConn=null===(t=i.block.nextConnection)||void 0===t?void 0:t.targetConnection),r&&l&&r.setShadowDom(a),i.block.unplug(e),n.blockAnimations.disconnectUiEffect(i.block),(0,s.updateDuplicateOnDragState)(i.block),r&&o&&r.connect(o.outputConnection)}}i.DuplicateOnDragStrategy=o,i.setDuplicateOnDragStrategy=function(e){var t,i;null===(i=(t=e).setDragStrategy)||void 0===i||i.call(t,new o(e))}},{"./duplicateOnDrag":106,blockly:256}],106:[function(e,t,i){"use strict";let n,s;function o(e){return!(!n||-1===n.indexOf(e.type))}function r(e){var t,i;if(e.isShadow()&&o(e))return!0;if(s){const n=null===(t=e.outputConnection)||void 0===t?void 0:t.targetBlock();if(n){const t=s.filter(e=>e.parentBlockType===n.type);for(const n of t)if(n&&(!n.childBlockType||n.childBlockType===e.type)){if(!n.inputName)return!0;if((null===(i=e.outputConnection.targetConnection.getParentInput())||void 0===i?void 0:i.name)===n.inputName)return!0}}}return!1}Object.defineProperty(i,"__esModule",{value:!0}),i.updateDuplicateOnDragState=i.shouldDuplicateOnDrag=i.isAllowlistedShadow=i.setDuplicateOnDrag=i.setDraggableShadowBlocks=void 0,i.setDraggableShadowBlocks=function(e){n=e},i.setDuplicateOnDrag=function(e,t,i){s||(s=[]),s.some(n=>n.parentBlockType===e&&n.inputName===t&&n.childBlockType===i)||s.push({parentBlockType:e,inputName:t,childBlockType:i})},i.isAllowlistedShadow=o,i.shouldDuplicateOnDrag=r,i.updateDuplicateOnDragState=function(e){setTimeout(()=>{const t=r(e);e.pathObject&&e.pathObject.setHasDottedOutlineOnHover(t),e.setDeletable(!t)})}},{}],107:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./duplicateOnDrag"),i),s(e("./variablesGetReporter"),i),s(e("./connectionChecker"),i),s(e("./dragStrategy"),i)},{"./connectionChecker":104,"./dragStrategy":105,"./duplicateOnDrag":106,"./variablesGetReporter":108}],108:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("./duplicateOnDrag");n.Blocks.variables_get_reporter={init:function(){this.jsonInit({type:"variables_get_reporter",message0:"%1",args0:[{type:"field_variable",name:"VAR",variable:"%{BKY_VARIABLES_DEFAULT_NAME}",variableTypes:[""]}],output:null,colour:"%{BKY_VARIABLES_HUE}",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,helpUrl:"%{BKY_VARIABLES_GET_HELPURL}",tooltip:"%{BKY_VARIABLES_GET_TOOLTIP}",extensions:["contextMenu_variableReporter"]}),(0,s.updateDuplicateOnDragState)(this)}}},{"./duplicateOnDrag":106,blockly:256}],109:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MultiFlyoutRecyclableBlockInflater=i.HIDDEN_CLASS_NAME=void 0;const n=e("blockly");i.HIDDEN_CLASS_NAME="pxtFlyoutHidden";class s extends n.BlockFlyoutInflater{constructor(){super(...arguments),this.keyToBlock=new Map,this.blockToKey=new Map}static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,"block",s,!0)}isBlockRecycleable(e){switch(e.type){case"variables_get":case"variables_set":case"variables_change":return!1}return!0}createBlock(e,t){const s=function(e){if(e.blockxml)return"string"==typeof e.blockxml?e.blockxml:n.Xml.domToText(e.blockxml);return e.type}(e);if(!s)return super.createBlock(e,t);let o;return this.keyToBlock.has(s)&&(o=this.keyToBlock.get(s),this.keyToBlock.delete(s),t.getCanvas().appendChild(o.getSvgRoot())),o=null!=o?o:super.createBlock(e,t),this.blockToKey.set(o,s),o.removeClass(i.HIDDEN_CLASS_NAME),o.getFocusableElement().ariaHidden="false",o.setDisabledReason(!1,i.HIDDEN_CLASS_NAME),o}disposeItem(e){const t=e.getElement();if(t instanceof n.BlockSvg&&this.blockToKey.has(t)){if(this.isBlockRecycleable(t))return void this.recycleBlock(t);this.blockToKey.delete(t)}super.disposeItem(e)}clearCache(){this.blockToKey=new Map,this.keyToBlock=new Map}recycleBlock(e){const t=e.getRelativeToSurfaceXY();e.moveBy(-t.x,-t.y),e.addClass(i.HIDDEN_CLASS_NAME),e.getFocusableElement().ariaHidden="true",e.setDisabledReason(!0,i.HIDDEN_CLASS_NAME),e.getSvgRoot().remove();const n=this.blockToKey.get(e);this.keyToBlock.set(n,e),this.removeListeners(e.id)}}i.MultiFlyoutRecyclableBlockInflater=s,n.Css.register(`\n.${i.HIDDEN_CLASS_NAME} {\n display: none;\n}\n`)},{blockly:256}],110:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ButtonFlyoutInflater=void 0;const n=e("blockly"),s=e("./flyoutButton"),o="button";class r extends n.ButtonFlyoutInflater{static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,o,r,!0)}load(e,t){const i=new s.FlyoutButton(t.getWorkspace(),t.targetWorkspace,e,!1);return i.show(),new n.FlyoutItem(i,o)}}i.ButtonFlyoutInflater=r},{"./flyoutButton":112,blockly:256}],111:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CachingFlyout=void 0;const n=e("blockly"),s=e("./blockInflater");class o extends n.VerticalFlyout{constructor(){super(...arguments),this.forceOpen=!1}clearBlockCache(){const e=this.getInflaterForType("block");e instanceof s.MultiFlyoutRecyclableBlockInflater&&e.clearCache()}getFlyoutElement(){return this.svgGroup_}setForceOpen(e){this.forceOpen=e}}i.CachingFlyout=o},{"./blockInflater":109,blockly:256}],112:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FlyoutButton=void 0;const n=e("blockly"),s={"":"usb","":"accessible-icon","":"adn","":"pied-piper-pp","":"steam","":"bluetooth-b","":"rebel","":"maxcdn","":"joomla","":"sellsy","":"connectdevelop","":"github-alt"};class o extends n.FlyoutButton{constructor(e,t,i,o){super(e,t,i,o);const r=this.getSvgRoot();if(!o){const e=17.5,t=14,i=this.height;this.width+=2*(e-n.FlyoutButton.TEXT_MARGIN_X),this.height+=2*(t-n.FlyoutButton.TEXT_MARGIN_Y);const s=r.getElementsByClassName("blocklyFlyoutButtonShadow").item(0),o=r.getElementsByClassName("blocklyFlyoutButtonBackground").item(0),a=r.getElementsByTagName("text").item(0);return s.setAttribute("width",String(this.width)),s.setAttribute("height",String(this.height)),o.setAttribute("width",String(this.width)),o.setAttribute("height",String(this.height)),a.setAttribute("x",String(this.width/2)),void a.setAttribute("y",String(parseFloat(a.getAttribute("y"))-i/2+this.height/2))}const a=i;a["web-class"]&&r.classList.add(a["web-class"]);const l=a["web-icon"],c=a["web-icon-class"],u=a["web-icon-color"],h=a["web-icon-image"];if(h){const e=20,t=this.getTargetWorkspace(),i=n.utils.dom.createSvgElement("image",{height:String(e),width:String(e),x:String(t.RTL?this.width+n.FlyoutButton.TEXT_MARGIN_X:n.FlyoutButton.TEXT_MARGIN_X),y:String(this.height/2+n.FlyoutButton.TEXT_MARGIN_Y-e/2)},r);i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",h);const s=e+2*n.FlyoutButton.TEXT_MARGIN_X;this.width+=s;const o=r.getElementsByClassName("blocklyFlyoutLabelBackground").item(0);o.setAttribute("width",String(this.width));for(let e=0;e<r.children.length;e++){const t=r.children.item(e);if(t!==i&&t!==o){const e=Number(t.getAttribute("x"));t.setAttribute("x",e+s+"")}}}else if(l||c){const e=Object.keys(s).includes(l)?"brandIcon":"",t=n.utils.dom.createSvgElement("text",{class:`blocklyFlyoutLabelIcon${c?" "+c:""}${e?" "+e:""}`,x:0,y:0,"text-anchor":"start"},r);l&&(t.textContent=l),u&&t.setAttribute("style","fill: "+u);const i=this.getTargetWorkspace();t.setAttribute("dominant-baseline","central"),t.setAttribute("dy","0"),t.setAttribute("x",(i.RTL?this.width+n.FlyoutButton.TEXT_MARGIN_X:0)+""),t.setAttribute("y",this.height/2+n.FlyoutButton.TEXT_MARGIN_Y+"");const o=n.utils.dom.getTextWidth(t)+2*n.FlyoutButton.TEXT_MARGIN_X;this.width+=o;const a=r.getElementsByClassName("blocklyFlyoutLabelBackground").item(0);a.setAttribute("width",String(this.width));for(let e=0;e<r.children.length;e++){const i=r.children.item(e);if(i!==t&&i!==a){const e=Number(i.getAttribute("x"));i.setAttribute("x",e+o+"")}}}const d=a["web-line"],p=a["web-line-width"];if(d){const e=n.utils.dom.createSvgElement("line",{class:"blocklyFlyoutLine","stroke-dasharray":d,"text-anchor":"middle"},r);e.setAttribute("x1","0"),e.setAttribute("x2",null!=p?p:this.width+""),e.setAttribute("y1",this.height+10+""),e.setAttribute("y2",this.height+10+"")}}isDisposed(){return null===this.getSvgRoot().parentNode}}i.FlyoutButton=o},{blockly:256}],113:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),i.registerFlyoutInflaters=i.MultiFlyoutRecyclableBlockInflater=i.LabelFlyoutInflater=i.ButtonFlyoutInflater=void 0;const o=e("./buttonFlyoutInflater");Object.defineProperty(i,"ButtonFlyoutInflater",{enumerable:!0,get:function(){return o.ButtonFlyoutInflater}});const r=e("./labelFlyoutInflater");Object.defineProperty(i,"LabelFlyoutInflater",{enumerable:!0,get:function(){return r.LabelFlyoutInflater}});const a=e("./blockInflater");Object.defineProperty(i,"MultiFlyoutRecyclableBlockInflater",{enumerable:!0,get:function(){return a.MultiFlyoutRecyclableBlockInflater}}),s(e("./cachingFlyout"),i),i.registerFlyoutInflaters=function(){o.ButtonFlyoutInflater.register(),r.LabelFlyoutInflater.register(),a.MultiFlyoutRecyclableBlockInflater.register()}},{"./blockInflater":109,"./buttonFlyoutInflater":110,"./cachingFlyout":111,"./labelFlyoutInflater":114}],114:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.LabelFlyoutInflater=void 0;const n=e("blockly"),s=e("./flyoutButton"),o="label";class r extends n.LabelFlyoutInflater{static register(){n.registry.register(n.registry.Type.FLYOUT_INFLATER,o,r,!0)}load(e,t){const i=new s.FlyoutButton(t.getWorkspace(),t.targetWorkspace,e,!0);return i.show(),new n.FlyoutItem(i,o)}}i.LabelFlyoutInflater=r},{"./flyoutButton":112,blockly:256}],115:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../constants"),o={typeName_:"",getTypeName(){return this.typeName_},removeFieldCallback(e){const t=this.getParent();(null==t?void 0:t.removeFieldCallback)&&t.removeFieldCallback(e)}};n.Blocks[s.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"bool"}],extensions:["output_boolean","text_field_color"]}),this.typeName_="boolean"}}),n.Blocks[s.ARGUMENT_EDITOR_STRING_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"text"}],extensions:["output_string","text_field_color"]}),this.typeName_="string"}}),n.Blocks[s.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"num"}],extensions:["output_number","text_field_color"]}),this.typeName_="number"}}),n.Blocks[s.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"list"}],extensions:["output_array","text_field_color"]}),this.typeName_="Array"}}),n.Blocks[s.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE]=Object.assign(Object.assign({},o),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_editor",name:"TEXT",text:"arg"}],outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,extensions:["text_field_color"]}),this.typeName_="any"},mutationToDom(){const e=n.utils.xml.createElement("mutation");return e.setAttribute("typename",this.typeName_),e},domToMutation(e){this.typeName_=e.getAttribute("typename"),this.setOutput(!0,this.typeName_)}})},{"../constants":121,blockly:256}],116:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.LOCALIZATION_NAME_MUTATION_KEY=void 0;const n=e("blockly"),s=e("../constants"),o=e("../msg"),r=e("../../duplicateOnDrag");i.LOCALIZATION_NAME_MUTATION_KEY="localizationname";const a={typeName_:"",localizationName_:"",getTypeName(){return this.typeName_},getLocalizationName(){return this.localizationName_||this.getFieldValue("VALUE")},mutationToDom(){const e=n.utils.xml.createElement("mutation");return this.localizationName_&&e.setAttribute(i.LOCALIZATION_NAME_MUTATION_KEY,this.localizationName_),e},domToMutation(e){e.hasAttribute(i.LOCALIZATION_NAME_MUTATION_KEY)&&(this.localizationName_=e.getAttribute(i.LOCALIZATION_NAME_MUTATION_KEY))}};function l(e){(0,r.setDuplicateOnDragStrategy)(e),(0,r.updateDuplicateOnDragState)(e)}n.Blocks[s.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_boolean"]}),this.typeName_="boolean",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_STRING_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_string"]}),this.typeName_="string",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_number"]}),this.typeName_="number",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],extensions:["output_array"]}),this.typeName_="Array",l(this)}}),n.Blocks[s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE]=Object.assign(Object.assign({},a),{init:function(){this.jsonInit({message0:" %1",args0:[{type:"field_argument_reporter",name:"VALUE",text:""}],colour:n.Msg[o.MsgKey.REPORTERS_HUE],inputsInline:!0,outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,output:null}),this.typeName_="",l(this)},mutationToDom(){const e=a.mutationToDom.call(this);return e.setAttribute("typename",this.typeName_),e},domToMutation(e){this.typeName_=e.getAttribute("typename"),this.setOutput(!0,this.typeName_),a.domToMutation.call(this,e)}})},{"../../duplicateOnDrag":107,"../constants":121,"../msg":128,blockly:256}],117:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../msg"),l=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){let s=null,o=null;if(t&&e.id in t){const i=t[e.id];s=i.block,o=i.shadow}const r=null==s?void 0:s.workspace.connectionChecker;n.Events.disable();try{if(s&&!s.isDisposed()&&t&&(null==r?void 0:r.canConnectWithReason(null==s?void 0:s.outputConnection,i.connection,!1))===n.Connection.CAN_CONNECT){let r;s.outputConnection.connect(i.connection),r=s.isShadow()?n.Xml.blockToDom(s):o||this.buildShadowDom_(e.type),"variables_get"!==r.getAttribute("type")&&i.connection.setShadowDom(r),delete t[i.name]}else this.attachShadow_(i,e.type)}finally{n.Events.enable()}},afterWorkspaceLoad:function(){var e;for(const t of this.inputList){if(t.type!==n.inputs.inputTypes.VALUE)continue;const i=null===(e=t.connection)||void 0===e?void 0:e.targetBlock();i&&i.isShadow()&&i.getVarModels().length&&i.setShadow(!1);const s=t.connection&&t.getShadowDom();(0,r.isVariableBlockType)(null==s?void 0:s.getAttribute("type"))&&t.setShadowDom(null)}},addFunctionLabel_:function(e){this.appendDummyInput("function_name").appendField(new n.FieldLabel(e,"functionNameText"),"function_name")},updateFunctionLabel_:function(e){this.getField("function_name").setValue(e)},attachShadow_(e,t){const i=(0,r.getShadowBlockInfoFromType_)(t,this.workspace),s=i[0],o=i[1],a=i[2];n.Events.disable();let l=null;try{l=this.workspace.newBlock(s),l.setFieldValue(a,o),l.setShadow("variables_get"!==s),!this.isInsertionMarker()&&l instanceof n.BlockSvg&&(l.initSvg(),l.queueRender())}finally{n.Events.enable()}l&&(l.setShadow(!0),l.outputConnection.connect(e.connection))},buildShadowDom_(e){const t=n.utils.xml.createElement("shadow"),i=(0,r.getShadowBlockInfoFromType_)(e,this.workspace),s=i[0],o=i[1],a=i[2],l="variables_get"===s;t.setAttribute("type",s);const c=n.utils.xml.createElement("field");if(c.textContent=a,l){c.setAttribute("id",a);const e=this.workspace.getVariableMap().getVariableById(a);c.textContent=e?e.getName():""}return c.setAttribute("name",o),t.appendChild(c),t},onchange(e){var t;if(this.workspace&&!this.workspace.isFlyout)if(e.type==n.Events.BLOCK_CREATE&&-1!=(null===(t=e.ids)||void 0===t?void 0:t.indexOf(this.id))){const t=this.getName(),i=(0,r.getDefinition)(t,this.workspace);if(i){const e=i.getArguments().slice(),t=this.arguments_.slice();JSON.stringify(t)!==JSON.stringify(e)&&(0,r.mutateCallersAndDefinition)(i.getName(),this.workspace,i.mutationToDom()),this.functionId_=i.functionId_}else{n.Events.setGroup(e.group);const t=n.utils.xml.createElement("xml"),i=n.utils.xml.createElement("block");i.setAttribute("type",o.FUNCTION_DEFINITION_BLOCK_TYPE);const s=this.getRelativeToSurfaceXY(),r=s.x+n.config.snapRadius*(this.RTL?-1:1),a=s.y+2*n.config.snapRadius;i.setAttribute("x",r+""),i.setAttribute("y",a+"");const l=this.mutationToDom();i.appendChild(l),t.appendChild(i),n.Xml.domToWorkspace(t,this.workspace),n.Events.setGroup(!1)}}else if(e.type==n.Events.BLOCK_DELETE){const t=this.getName();(0,r.getDefinition)(t,this.workspace)||(n.Events.setGroup(e.group),this.dispose(!0),n.Events.setGroup(!1))}},serializeChangedInputs(e){const t=[],i=(0,r.getArgMap)(e,!0);for(const e of this.arguments_){if(i[e.id])continue;const n=this.getInput(e.id).connection,s=n.targetBlock();s.isShadow()?t.push({inputName:e.id,connectedShadow:n.getShadowState(!0)}):t.push({inputName:e.id,connectedBlock:s.id})}return t}});n.Blocks[o.FUNCTION_CALL_BLOCK_TYPE]=Object.assign(Object.assign({},l),{init:function(){this.jsonInit({extensions:["function_contextmenu_edit"]}),this.name_="",this.arguments_=[],this.functionId_="",this.setPreviousStatement(!0),this.setNextStatement(!0),this.setColour(n.Msg[a.MsgKey.PROCEDURES_HUE]),this.setHelpUrl(n.Msg[a.MsgKey.PROCEDURES_CALLNORETURN_HELPURL]),this.setTooltip(n.Msg[a.MsgKey.FUNCTION_CALL_TOOLTIP]),this.setInputsInline(!0)}}),n.Blocks[o.FUNCTION_CALL_OUTPUT_BLOCK_TYPE]=Object.assign(Object.assign({},l),{init:function(){this.jsonInit({extensions:["function_contextmenu_edit"]}),this.name_="",this.arguments_=[],this.functionId_="",this.setPreviousStatement(!1),this.setNextStatement(!1),this.setOutput(!0,null),this.setOutputShape((new n.zelos.ConstantProvider).SHAPES.ROUND),this.setColour(n.Msg[a.MsgKey.PROCEDURES_HUE]),this.setHelpUrl(n.Msg[a.MsgKey.PROCEDURES_CALLNORETURN_HELPURL]),this.setTooltip(n.Msg[a.MsgKey.FUNCTION_CALL_TOOLTIP]),this.setInputsInline(!0)}})},{"../commonFunctionMixin":120,"../constants":121,"../msg":128,"../utils":130,blockly:256}],118:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.newFunctionMutation=void 0;const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../fields/fieldAutocapitalizeTextInput"),l=e("../functionManager"),c=e("../msg"),u=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){const n=this.createArgumentEditor_(e.type,e.name);i.connection.connect(n.outputConnection)},addFunctionLabel_:function(e){const t=new a.FieldAutocapitalizeTextInput(e||"",void 0,{spellcheck:!1,disableAutocapitalize:!0});this.appendDummyInput("function_name").appendField(t,"function_name")},updateFunctionLabel_:function(e){n.Events.disable(),this.getField("function_name").setValue(e),n.Events.enable()},createArgumentEditor_:function(e,t){let i;n.Events.disable();try{let s="";switch(e){case"boolean":s=o.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE;break;case"number":s=o.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE;break;case"string":s=o.ARGUMENT_EDITOR_STRING_BLOCK_TYPE;break;case"Array":s=o.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE;break;default:s=o.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE}i=s==o.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE?(0,r.createCustomArgumentEditor)(e,this.workspace):this.workspace.newBlock(s),i.setFieldValue(t,"TEXT"),i.setShadow(!0),!this.isInsertionMarker()&&i instanceof n.BlockSvg&&(i.initSvg(),i.queueRender())}finally{n.Events.enable()}return i},async focusLastEditorAsync_(){if(await n.renderManagement.finishQueuedRenders(),this.inputList.length>0){let e=this.inputList[this.inputList.length-2];if(e.type==n.inputs.inputTypes.DUMMY){const t=this.workspace;t instanceof n.WorkspaceSvg&&t.centerOnBlock(this.id,!0),e.fieldRow[0].showEditor()}else if(e.type==n.inputs.inputTypes.VALUE){const t=e.connection.targetBlock(),i=t.workspace;i instanceof n.WorkspaceSvg&&i.centerOnBlock(t.id,!0),t.getField("TEXT").showEditor()}}},removeFieldCallback(e){let t=null;for(let i=0;i<this.inputList.length&&!t;i++){let n=this.inputList[i];if(n.connection){let i=n.connection.targetBlock();if(!i)continue;i.getField(e.name)===e&&(t=n.name)}else for(let i=0;i<n.fieldRow.length;i++)n.fieldRow[i]==e&&(t=n.name)}t&&(n.WidgetDiv.hide(),this.removeInput(t),this.updateFunctionSignature(),this.updateDisplay_())},addParam_(e,t){n.WidgetDiv.hide();const i=(0,r.findUniqueParamName)(t,this.arguments_.map(e=>e.name));this.arguments_.push({id:n.utils.idGenerator.genUid(),name:i,type:e}),this.updateDisplay_(),this.focusLastEditorAsync_()},addBooleanExternal(){this.addParam_("boolean",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME])},addStringExternal(){this.addParam_("string",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_STRING_ARG_NAME])},addNumberExternal(){this.addParam_("number",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME])},addArrayExternal(){this.addParam_("Array",n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME])},addCustomExternal(e){this.addParam_(e,l.FunctionManager.getInstance().getArgumentNameForType(e))},updateFunctionSignature(){this.arguments_=[];for(let e=1;e<this.inputList.length;e++){const t=this.inputList[e];switch(t.type){case n.inputs.inputTypes.STATEMENT:break;case n.inputs.inputTypes.DUMMY:this.name_=t.fieldRow[0].getValue()||t.fieldRow[0].getText();break;case n.inputs.inputTypes.VALUE:const e=t.connection.targetBlock();this.arguments_.push({id:t.name,name:e.getFieldValue("TEXT"),type:e.getTypeName()});break;default:pxt.warn("Unexpected input type on a function mutator root: "+t.type)}}}});i.newFunctionMutation=function(e){const t=(0,r.findLegalName)(n.Msg[c.MsgKey.FUNCTIONS_DEFAULT_FUNCTION_NAME],e),i=n.utils.xml.createElement("mutation");return i.setAttribute("name",t),i.setAttribute("functionid",n.utils.idGenerator.genUid()),i},n.Blocks[o.FUNCTION_DECLARATION_BLOCK_TYPE]=Object.assign(Object.assign({},u),{init:function(){this.jsonInit({style:{hat:"cap"}}),this.name_="",this.arguments_=[],this.functionId_="",this.createAllInputs_(),this.setColour(n.Msg[c.MsgKey.PROCEDURES_HUE]),this.setStatements_(!0),this.setDeletable(!1),this.setMovable(!1),this.contextMenu=!1,this.setInputsInline(!0)}})},{"../commonFunctionMixin":120,"../constants":121,"../fields/fieldAutocapitalizeTextInput":125,"../functionManager":126,"../msg":128,"../utils":130,blockly:256}],119:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../commonFunctionMixin"),o=e("../constants"),r=e("../utils"),a=e("../fields/fieldAutocapitalizeTextInput"),l=e("../msg"),c=e("../functionManager"),u=e("../svgs"),h=e("../../duplicateOnDrag"),d=e("../../../fields/field_imagenotext"),p=e("../../../utils"),g=Object.assign(Object.assign({},s.COMMON_FUNCTION_MIXIN),{populateArgument_:function(e,t,i){let n,s=null;if(null==t?void 0:t[e.id]){s=t[e.id].block}t&&s&&!s.isDisposed()?(n=s,n.setFieldValue(e.name,"VALUE"),delete t[i.name]):n=this.createArgumentReporter_(e),i.connection.connect(n.outputConnection)},afterWorkspaceLoad:function(){for(const e of this.inputList){if(e.type!==n.inputs.inputTypes.VALUE)continue;const t=this.arguments_.find(t=>t.id===e.name);if(!t)continue;let i=e.connection.targetBlock();i||(this.populateArgument_(t,null,e),i=e.connection.targetBlock()),i.setFieldValue(t.name,"VALUE"),i.isShadow()&&i.setShadow(!1),e.setShadowDom(null)}},addFunctionLabel_:function(e){const t=new a.FieldAutocapitalizeTextInput(e||"",r.rename,{spellcheck:!1,disableAutocapitalize:!0});this.appendDummyInput("function_name").appendField(t,"function_name")},updateFunctionLabel_:function(e){n.Events.disable(),this.getField("function_name").setValue(e),n.Events.enable()},createArgumentReporter_:function(e){let t,i="";switch(e.type){case"boolean":i=o.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE;break;case"number":i=o.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE;break;case"string":i=o.ARGUMENT_REPORTER_STRING_BLOCK_TYPE;break;case"Array":i=o.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE;break;default:i=o.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE}n.Events.disable();try{t=i==o.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE?(0,r.createCustomArgumentReporter)(e.type,this.workspace):this.workspace.newBlock(i),t.setFieldValue(e.name,"VALUE"),t.setShadow(!0),!this.isInsertionMarker()&&t instanceof n.BlockSvg&&(t.initSvg(),t.queueRender())}finally{n.Events.enable()}return t},customContextMenu:function(e){var t,i;this.isInFlyout||(null===(i=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===i?void 0:i.readOnly)||(e.push(this.makeEditOption()),e.push(this.makeCallOption()))},makeEditOption:function(){var e,t;return{enabled:!(null===(t=null===(e=this.workspace)||void 0===e?void 0:e.options)||void 0===t?void 0:t.readOnly),text:n.Msg.FUNCTIONS_EDIT_OPTION,callback:()=>{!function(e){if(e.type==o.FUNCTION_CALL_BLOCK_TYPE||e.type==o.FUNCTION_CALL_OUTPUT_BLOCK_TYPE){const t=e.workspace;e=(0,r.getDefinition)(e.getName(),t)}n.hideChaff(),n.getSelected()&&n.getSelected().unselect();c.FunctionManager.getInstance().editFunctionExternal(e.mutationToDom(),t=>{t&&((0,r.mutateCallersAndDefinition)(e.getName(),e.workspace,t),e.updateDisplay_()),setTimeout(()=>{e.afterWorkspaceLoad&&e.afterWorkspaceLoad()})})}(this)}}},makeCallOption:function(){var e,t;const i=this.getName(),s=n.utils.xml.createElement("mutation");s.setAttribute("name",i);const r=n.utils.xml.createElement("block");return r.appendChild(s),r.setAttribute("type",o.FUNCTION_CALL_BLOCK_TYPE),{enabled:this.workspace.remainingCapacity()>0&&!(null===(t=null===(e=this.workspace)||void 0===e?void 0:e.options)||void 0===t?void 0:t.readOnly),text:n.Msg.FUNCTIONS_CREATE_CALL_OPTION.replace("%1",i),callback:n.ContextMenu.callbackFactory(this,r)}}});n.Blocks[o.FUNCTION_DEFINITION_BLOCK_TYPE]=Object.assign(Object.assign({},g),{init:function(){if(this.jsonInit({style:{hat:"cap"}}),this.name_="",this.arguments_=[],this.functionId_="",this.createAllInputs_(),this.setColour(n.Msg[l.MsgKey.PROCEDURES_HUE]),this.setTooltip(n.Msg[l.MsgKey.PROCEDURES_DEFNORETURN_TOOLTIP]),this.setHelpUrl(n.Msg[l.MsgKey.PROCEDURES_DEFNORETURN_HELPURL]),this.setStatements_(!0),this.setInputsInline(!0),this.workspace.options.collapse){const e=u.COLLAPSE_IMAGE_DATAURI;this.appendDummyInput("function_collapse").appendField(new d.FieldImageNoText(e,24,24,lf("Collapse block"),()=>{var e;this.setCollapsed(!0);const t=null===(e=this.inputList.find(e=>e.name===n.constants.COLLAPSED_INPUT_NAME))||void 0===e?void 0:e.fieldRow[1];(0,p.maybeMoveFocusFromButton)(t)},!1))}}}),(0,h.setDuplicateOnDrag)(o.FUNCTION_DEFINITION_BLOCK_TYPE)},{"../../../fields/field_imagenotext":38,"../../../utils":155,"../../duplicateOnDrag":107,"../commonFunctionMixin":120,"../constants":121,"../fields/fieldAutocapitalizeTextInput":125,"../functionManager":126,"../msg":128,"../svgs":129,"../utils":130,blockly:256}],120:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.COMMON_FUNCTION_MIXIN=void 0;const n=e("blockly"),s=e("./constants"),o=e("./utils"),r=e("./msg");i.COMMON_FUNCTION_MIXIN={name_:"",functionId_:"",arguments_:[],mutationToDom:function(){this.ensureIds_();const e=n.utils.xml.createElement("mutation");return e.setAttribute("name",this.name_),e.setAttribute("functionid",this.functionId_),this.arguments_.forEach(function(t){const i=n.utils.xml.createElement("arg");i.setAttribute("name",t.name),i.setAttribute("id",t.id),i.setAttribute("type",t.type),e.appendChild(i)}),e},domToMutation:function(e){const t=[];for(let i=0;i<e.childNodes.length;++i){const n=e.childNodes[i];"arg"==n.nodeName.toLowerCase()&&t.push({id:n.getAttribute("id"),name:n.getAttribute("name"),type:n.getAttribute("type")})}this.arguments_=t,this.name_=e.getAttribute("name"),this.restoreSavedFunctionId(e.getAttribute("functionid"))},saveExtraState:function(){return{name:this.name_,functionid:this.functionId_,arguments:this.arguments_.slice()}},loadExtraState:function(e){this.arguments_=e.arguments.slice(),this.name_=e.name,this.restoreSavedFunctionId(e.functionid)},restoreSavedFunctionId:function(e){(0,o.idsInUse)(this.workspace).indexOf(e)<0&&(this.functionId_=e),this.ensureIds_();let t=null;this instanceof n.BlockSvg&&(t=this.getHeightWidth()),this.type!==s.FUNCTION_DEFINITION_BLOCK_TYPE||t&&!t.height&&!t.width?this.updateDisplay_():!this.getFieldValue("function_name")&&this.name_&&(this.setFieldValue(this.name_,"function_name"),this.updateDisplay_())},getName:function(){return this.name_},getFunctionId:function(){return this.functionId_},getArguments:function(){return this.arguments_},removeValueInputs_:function(){const e=[];for(let t,i=0;t=this.inputList[i];i++)t.type==n.inputs.inputTypes.VALUE?t.dispose():e.push(t);this.inputList=e},createAllInputs_:function(){let e=!1,t=!1;if(this.inputList.forEach(function(i){"function_title"==i.name?e=!0:"function_name"==i.name&&(t=!0)}),!e){let e="";switch(this.type){case s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE:case s.FUNCTION_CALL_BLOCK_TYPE:e=n.Msg[r.MsgKey.FUNCTIONS_CALL_TITLE];break;case s.FUNCTION_DEFINITION_BLOCK_TYPE:case s.FUNCTION_DECLARATION_BLOCK_TYPE:e=n.Msg[r.MsgKey.FUNCTIONS_DEFNORETURN_TITLE]}this.appendDummyInput("function_title").appendField(e,"function_title")}t?this.updateFunctionLabel_(this.getName()):this.addFunctionLabel_(this.getName()),this.updateArgumentInputs_()},updateArgumentInputs_(){var e;for(const e of this.inputList)if(e.type===n.inputs.inputTypes.VALUE&&!this.arguments_.some(t=>t.id===e.name)){if(this.type===s.FUNCTION_DEFINITION_BLOCK_TYPE){const t=e.connection.targetBlock();t&&t.dispose()}this.removeInput(e.name)}let t=this.inputList.findIndex(e=>e.type===n.inputs.inputTypes.VALUE);-1===t&&(t=this.inputList.length);for(const i of this.arguments_){let n=this.inputList.find(e=>e.name===i.id);const s=!n;s&&(n=this.appendValueInput(i.id)),this.inputList.indexOf(n)!==t&&this.moveInputBefore(n.name,null===(e=this.inputList[t+1])||void 0===e?void 0:e.name),(0,o.isCustomType)(i.type)?n.setCheck(i.type):n.setCheck(i.type.charAt(0).toUpperCase()+i.type.slice(1)),!this.isInsertionMarker()&&s&&this.populateArgument_(i,void 0,n),t++}this.inputList.some(e=>"function_collapse"===e.name)&&this.moveInputBefore("function_collapse",null),this.hasStatements_&&this.moveInputBefore("STACK",null)},updateDisplay_:function(){let e=this.rendered;this.createAllInputs_(),e&&!this.isInsertionMarker()&&this instanceof n.BlockSvg&&(this.initSvg(),this.queueRender())},setStatements_:function(e){this.hasStatements_!==e&&(e?this.appendStatementInput("STACK"):this.removeInput("STACK",!0),this.hasStatements_=e)},ensureIds_:function(){switch(this.type){case s.FUNCTION_DEFINITION_BLOCK_TYPE:this.functionId_&&"null"!=this.functionId_||(this.functionId_=n.utils.idGenerator.genUid());for(let e=0;e<this.arguments_.length;++e)this.arguments_[e].id||(this.arguments_[e].id=n.utils.idGenerator.genUid());break;case s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE:case s.FUNCTION_CALL_BLOCK_TYPE:const e=(0,o.getDefinition)(this.name_,this.workspace);if(e){this.functionId_=e.getFunctionId();const t=e.getArguments();for(let e=0;e<this.arguments_.length;++e)for(let i=0;i<t.length;++i)if(t[i].name==this.arguments_[e].name){this.arguments_[e].id=t[i].id;break}}}}}},{"./constants":121,"./msg":128,"./utils":130,blockly:256}],121:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE=i.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE=i.ARGUMENT_EDITOR_STRING_BLOCK_TYPE=i.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE=i.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE=i.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE=i.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE=i.ARGUMENT_REPORTER_STRING_BLOCK_TYPE=i.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE=i.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE=i.FUNCTION_CALL_OUTPUT_BLOCK_TYPE=i.FUNCTION_CALL_BLOCK_TYPE=i.FUNCTION_DECLARATION_BLOCK_TYPE=i.FUNCTION_DEFINITION_BLOCK_TYPE=void 0,i.FUNCTION_DEFINITION_BLOCK_TYPE="function_definition",i.FUNCTION_DECLARATION_BLOCK_TYPE="function_declaration",i.FUNCTION_CALL_BLOCK_TYPE="function_call",i.FUNCTION_CALL_OUTPUT_BLOCK_TYPE="function_call_output",i.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE="argument_reporter_boolean",i.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE="argument_reporter_number",i.ARGUMENT_REPORTER_STRING_BLOCK_TYPE="argument_reporter_string",i.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE="argument_reporter_array",i.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE="argument_reporter_custom",i.ARGUMENT_EDITOR_BOOLEAN_BLOCK_TYPE="argument_editor_boolean",i.ARGUMENT_EDITOR_NUMBER_BLOCK_TYPE="argument_editor_number",i.ARGUMENT_EDITOR_STRING_BLOCK_TYPE="argument_editor_string",i.ARGUMENT_EDITOR_ARRAY_BLOCK_TYPE="argument_editor_array",i.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE="argument_editor_custom"},{}],122:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("./utils"),o=e("./msg"),r=e("./svgs"),a=new n.zelos.ConstantProvider;const l={customContextMenu:function(e){var t,i;const r={enabled:!(null===(i=null===(t=this.workspace)||void 0===t?void 0:t.options)||void 0===i?void 0:i.readOnly),text:n.Msg[o.MsgKey.FUNCTIONS_GO_TO_DEFINITION_OPTION],callback:()=>{const e=this.getField("function_name").getText(),t=(0,s.getDefinition)(e,this.workspace);t&&this.workspace instanceof n.WorkspaceSvg&&this.workspace.centerOnBlock(t.id,!0)}};e.push(r)}},c={customContextMenu:function(e){if(this.isCollapsed())return;const t={text:n.Msg.RENAME_VARIABLE,enabled:!this.workspace.options.readOnly,callback:()=>{const e=this.workspace,t=this.getField("VAR").getVariable();n.Variables.renameVariable(e,t)}};if(e.unshift(t),!this.isInFlyout){const t=this.workspace.getVariableMap().getVariablesOfType("");for(const i of t){const t={enabled:!this.workspace.options.readOnly,text:i.getName(),callback:()=>{let e=this.getField("VAR");e||pxt.log("Tried to get a variable field on the wrong type of block."),e.setValue(i.getId())}};e.unshift(t)}}}};n.Extensions.registerMixin("function_contextmenu_edit",l),n.Extensions.registerMixin("contextMenu_variableReporter",c),n.Extensions.register("output_number",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"Number")}),n.Extensions.register("output_string",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"String")}),n.Extensions.register("output_boolean",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.HEXAGONAL),this.setOutput(!0,"Boolean")}),n.Extensions.register("output_array",function(){this.setInputsInline(!0),this.setOutputShape(a.SHAPES.ROUND),this.setOutput(!0,"Array")}),n.Extensions.register("text_field_color",function(){if(this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer().getConstants();this.setColour(e.FIELD_BORDER_RECT_COLOUR)}else this.setColour("#fff")}),n.Extensions.register("inline-svgs",function(){this.ADD_IMAGE_DATAURI=r.ADD_IMAGE_DATAURI,this.REMOVE_IMAGE_DATAURI=r.REMOVE_IMAGE_DATAURI})},{"./msg":128,"./svgs":129,"./utils":130,blockly:256}],123:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldArgumentEditor=void 0;const n=e("blockly"),s=e("../functionManager"),o=e("../../../external"),r=e("../msg");class a extends n.FieldTextInput{constructor(e,t,i){super(e,t,i)}showEditor(e){var t,i;super.showEditor(e);const o=n.WidgetDiv.getDiv();o.className+=" argumentEditorInput";const r=document.createElement("img");r.setAttribute("class","argumentEditorRemoveIcon"),r.setAttribute("src",a.REMOVE_ARG_URI),this.removeButtonMouseWrapper_=n.browserEvents.conditionalBind(r,"mousedown",this,this.removeCallback),o.appendChild(r);const l=null===(t=this.sourceBlock_)||void 0===t?void 0:t.getTypeName();if(l&&(null===(i=this.sourceBlock_)||void 0===i?void 0:i.workspace)){const e=s.FunctionManager.getInstance().getIconForType(l);if(e){const t=e+" icon argumentEditorTypeIcon",i=document.createElement("i");i.className=t,o.appendChild(i)}}}showEditor_(e,t=!1,i=!0){this.workspace_=this.sourceBlock_.workspace,!t&&this.workspace_.options.modalInputs&&(n.utils.userAgent.MOBILE||n.utils.userAgent.ANDROID||n.utils.userAgent.IPAD)?this.showPromptEditorModal():super.showEditor_(e,t,i)}showPromptEditorModal(){(0,o.prompt)(n.Msg.CHANGE_VALUE_TITLE,this.getText(),e=>{null!==e&&this.setValue(this.getValueFromEditorText_(e)),this.onFinishEditing_(this.value_)},{placeholder:void 0,buttons:[{label:n.Msg[r.MsgKey.FUNCTIONS_DELETE_PARAMETER_BUTTON],className:"red",icon:"trash",onclick:()=>{this.removeCallback()}}]})}removeCallback(){var e,t;const i=null===(e=this.sourceBlock_)||void 0===e?void 0:e.getParent();if(!i)return;let s;for(const e of i.inputList){if((null===(t=e.connection)||void 0===t?void 0:t.targetBlock())===this.sourceBlock_){s=e.name;break}}s&&(n.WidgetDiv.hide(),i.removeInput(s))}}i.FieldArgumentEditor=a,a.REMOVE_ARG_URI="data:image/svg+xml;charset=UTF-8,%3c?xml version='1.0' encoding='UTF-8' standalone='no'?%3e%3csvg width='20px' height='20px' viewBox='0 0 20 20' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3c!-- Generator: Sketch 48.1 (47250) - http://www.bohemiancoding.com/sketch --%3e%3ctitle%3edelete-argument v2%3c/title%3e%3cdesc%3eCreated with Sketch.%3c/desc%3e%3cdefs%3e%3c/defs%3e%3cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3e%3cg id='delete-argument-v2' stroke='%23FF661A'%3e%3cg id='Group' transform='translate(3.000000, 2.500000)'%3e%3cpath d='M1,3 L13,3 L11.8900496,14.0995037 C11.8389294,14.6107055 11.4087639,15 10.8950124,15 L3.10498756,15 C2.59123611,15 2.16107055,14.6107055 2.10995037,14.0995037 L1,3 Z' id='Rectangle' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M7,11 L7,6' id='Line' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M9.5,11 L9.5,6' id='Line-Copy' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3cpath d='M4.5,11 L4.5,6' id='Line-Copy-2' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3e%3c/path%3e%3crect id='Rectangle-2' fill='%23FF661A' x='0' y='2.5' width='14' height='1' rx='0.5'%3e%3c/rect%3e%3cpath d='M6,0 L8,0 C8.55228475,-1.01453063e-16 9,0.44771525 9,1 L9,3 L5,3 L5,1 C5,0.44771525 5.44771525,1.01453063e-16 6,0 Z' id='Rectangle-3' stroke-width='1.5'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e",n.fieldRegistry.register("field_argument_editor",a),n.Css.register("\n\n.argumentEditorInput {\n overflow: visible;\n}\n\n.functioneditor i.argumentEditorTypeIcon {\n color: var(--pxt-target-foreground1);\n position: absolute;\n width: 24px;\n height: 24px;\n top: 40px;\n left: 50%;\n margin-left: -12px;\n}\n\n.argumentEditorRemoveIcon {\n position: absolute;\n width: 24px;\n height: 24px;\n top: -40px;\n left: 50%;\n margin-left: -12px;\n cursor: pointer;\n}\n\n")},{"../../../external":25,"../functionManager":126,"../msg":128,blockly:256}],124:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.setArgumentReporterLocalizeFunction=i.FieldArgumentReporter=void 0;const n=e("blockly"),s=e("../utils");let o;class r extends n.FieldLabelSerializable{getDisplayText_(){const e=this.getSourceBlock();if(e&&(0,s.isFunctionArgumentReporter)(e)&&o){const t=o(this,e);if(t)return t}return super.getDisplayText_()}}i.FieldArgumentReporter=r,i.setArgumentReporterLocalizeFunction=function(e){o=e},n.registry.register(n.registry.Type.FIELD,"field_argument_reporter",r)},{"../utils":130,blockly:256}],125:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldAutocapitalizeTextInput=void 0;const n=e("blockly");class s extends n.FieldTextInput{constructor(e,t,i){super(e,t,i),this.disableAutocapitalize=!1}setAutocapitalize(e){this.disableAutocapitalize=!e,this.htmlInput_&&(this.disableAutocapitalize?this.htmlInput_.setAttribute("autocapitalize","none"):this.htmlInput_.removeAttribute("autocapitalize"))}configure_(e){super.configure_(e),void 0!==e.disableAutocapitalize&&(this.disableAutocapitalize=e.disableAutocapitalize)}widgetCreate_(){const e=super.widgetCreate_();return this.disableAutocapitalize&&e.setAttribute("autocapitalize","none"),e}}i.FieldAutocapitalizeTextInput=s,n.fieldRegistry.register("field_autocapitalize_text_input",s)},{blockly:256}],126:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FunctionManager=void 0;const n=e("blockly"),s=e("./msg");class o{constructor(){this.typeIcons={},this.typeArgumentNames={}}static getInstance(){return o.instance}getIconForType(e){return this.typeIcons[e]}setIconForType(e,t){this.typeIcons[e]=t}setArgumentNameForType(e,t){this.typeArgumentNames[e]=t}getArgumentNameForType(e){return this.typeArgumentNames[e]?this.typeArgumentNames[e]:n.Msg[s.MsgKey.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME]}setEditFunctionExternal(e){this._editFunctionExternal=e}editFunctionExternal(e,t){this._editFunctionExternal?this._editFunctionExternal(e,t):pxt.warn("External function editor must be overriden: Blockly.Functions.editFunctionExternalHandler",e,t)}}i.FunctionManager=o,o.instance=new o},{"./msg":128,blockly:256}],127:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),i.validateFunctionExternal=i.getAllFunctionDefinitionBlocks=i.getDefinition=i.flyoutCategory=void 0,s(e("./msg"),i),s(e("./extensions"),i),s(e("./fields/fieldArgumentEditor"),i),s(e("./fields/fieldArgumentReporter"),i),s(e("./fields/fieldAutocapitalizeTextInput"),i),s(e("./blocks/argumentEditorBlocks"),i),s(e("./blocks/argumentReporterBlocks"),i),s(e("./blocks/functionDeclarationBlock"),i),s(e("./blocks/functionDefinitionBlock"),i),s(e("./blocks/functionCallBlocks"),i),s(e("./functionManager"),i);var o=e("./utils");Object.defineProperty(i,"flyoutCategory",{enumerable:!0,get:function(){return o.flyoutCategory}}),Object.defineProperty(i,"getDefinition",{enumerable:!0,get:function(){return o.getDefinition}}),Object.defineProperty(i,"getAllFunctionDefinitionBlocks",{enumerable:!0,get:function(){return o.getAllFunctionDefinitionBlocks}}),Object.defineProperty(i,"validateFunctionExternal",{enumerable:!0,get:function(){return o.validateFunctionExternal}})},{"./blocks/argumentEditorBlocks":115,"./blocks/argumentReporterBlocks":116,"./blocks/functionCallBlocks":117,"./blocks/functionDeclarationBlock":118,"./blocks/functionDefinitionBlock":119,"./extensions":122,"./fields/fieldArgumentEditor":123,"./fields/fieldArgumentReporter":124,"./fields/fieldAutocapitalizeTextInput":125,"./functionManager":126,"./msg":128,"./utils":130}],128:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MsgKey=void 0;const n=e("blockly");var s;function o(e,t){n.Msg[e]||(n.Msg[e]=t)}!function(e){e.REPORTERS_HUE="REPORTERS_HUE",e.FUNCTIONS_CALL_TITLE="FUNCTIONS_CALL_TITLE",e.FUNCTIONS_DEFNORETURN_TITLE="FUNCTIONS_DEFNORETURN_TITLE",e.FUNCTIONS_GO_TO_DEFINITION_OPTION="FUNCTIONS_GO_TO_DEFINITION_OPTION",e.FUNCTION_CALL_TOOLTIP="FUNCTION_CALL_TOOLTIP",e.PROCEDURES_HUE="PROCEDURES_HUE",e.PROCEDURES_CALLNORETURN_HELPURL="PROCEDURES_CALLNORETURN_HELPURL",e.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME="FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME",e.FUNCTIONS_DEFAULT_STRING_ARG_NAME="FUNCTIONS_DEFAULT_STRING_ARG_NAME",e.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME="FUNCTIONS_DEFAULT_NUMBER_ARG_NAME",e.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME="FUNCTIONS_DEFAULT_ARRAY_ARG_NAME",e.PROCEDURES_DEFNORETURN_TOOLTIP="PROCEDURES_DEFNORETURN_TOOLTIP",e.PROCEDURES_DEFNORETURN_HELPURL="PROCEDURES_DEFNORETURN_HELPURL",e.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME="FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME",e.FUNCTIONS_DEFAULT_FUNCTION_NAME="FUNCTIONS_DEFAULT_FUNCTION_NAME",e.FUNCTION_CREATE_NEW="FUNCTION_CREATE_NEW",e.FUNCTION_FLYOUT_LABEL="FUNCTION_FLYOUT_LABEL",e.FUNCTIONS_EDIT_OPTION="FUNCTIONS_EDIT_OPTION",e.FUNCTIONS_CREATE_CALL_OPTION="FUNCTIONS_CREATE_CALL_OPTION",e.FUNCTIONS_DELETE_PARAMETER_BUTTON="FUNCTIONS_DELETE_PARAMETER_BUTTON"}(s=i.MsgKey||(i.MsgKey={})),o(s.REPORTERS_HUE,"#A80000"),o(s.FUNCTIONS_CALL_TITLE,"call"),o(s.FUNCTIONS_DEFNORETURN_TITLE,"function"),o(s.FUNCTIONS_GO_TO_DEFINITION_OPTION,"Go to Definition"),o(s.FUNCTIONS_DEFAULT_BOOLEAN_ARG_NAME,"bool"),o(s.FUNCTIONS_DEFAULT_STRING_ARG_NAME,"text"),o(s.FUNCTIONS_DEFAULT_NUMBER_ARG_NAME,"num"),o(s.FUNCTIONS_DEFAULT_ARRAY_ARG_NAME,"array"),o(s.FUNCTIONS_DEFAULT_CUSTOM_ARG_NAME,"value"),o(s.FUNCTIONS_DEFAULT_FUNCTION_NAME,"doSomething"),o(s.FUNCTION_CREATE_NEW,"Make a Function"),o(s.FUNCTION_FLYOUT_LABEL,"Your Functions"),o(s.FUNCTIONS_EDIT_OPTION,"Edit Function"),o(s.FUNCTIONS_CREATE_CALL_OPTION,"Create 'call %1'"),o(s.FUNCTIONS_DELETE_PARAMETER_BUTTON,"Delete")},{blockly:256}],129:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.REMOVE_IMAGE_DATAURI=i.ADD_IMAGE_DATAURI=i.COLLAPSE_IMAGE_DATAURI=void 0,i.COLLAPSE_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.354)'%3E%3Cpath d='m1611 367.42q0 53-37 90l-651 651q-38 38-91 38-54 0-90-38l-651-651q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l486 486 486-486q37-37 90-37 52 0 91 37l75 75q37 39 37 91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A",i.ADD_IMAGE_DATAURI="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4KCjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0icmVwZWF0IgogICB4PSIwcHgiCiAgIHk9IjBweCIKICAgdmlld0JveD0iMCAwIDI0IDI0IgogICBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNCAyNDsiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlua3NjYXBlOnZlcnNpb249IjAuOTEgcjEzNzI1IgogICBzb2RpcG9kaTpkb2NuYW1lPSJhZGQuc3ZnIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGExNSI+PHJkZjpSREY+PGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPjxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PjxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz48ZGM6dGl0bGU+cmVwZWF0PC9kYzp0aXRsZT48L2NjOldvcms+PC9yZGY6UkRGPjwvbWV0YWRhdGE+PGRlZnMKICAgICBpZD0iZGVmczEzIiAvPjxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBwYWdlY29sb3I9IiNmZjQ4MjEiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMSIKICAgICBvYmplY3R0b2xlcmFuY2U9IjEwIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwIgogICAgIGd1aWRldG9sZXJhbmNlPSIxMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTY4MCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI5NjkiCiAgICAgaWQ9Im5hbWVkdmlldzExIgogICAgIHNob3dncmlkPSJmYWxzZSIKICAgICBpbmtzY2FwZTp6b29tPSIxOS42NjY2NjciCiAgICAgaW5rc2NhcGU6Y3g9IjEyLjkxNTI1NCIKICAgICBpbmtzY2FwZTpjeT0iMTYuMDY3Nzk2IgogICAgIGlua3NjYXBlOndpbmRvdy14PSIwIgogICAgIGlua3NjYXBlOndpbmRvdy15PSIwIgogICAgIGlua3NjYXBlOndpbmRvdy1tYXhpbWl6ZWQ9IjAiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0icmVwZWF0IiAvPjxzdHlsZQogICAgIHR5cGU9InRleHQvY3NzIgogICAgIGlkPSJzdHlsZTMiPgoJLnN0MHtmaWxsOiNDRjhCMTc7fQoJLnN0MXtmaWxsOiNGRkZGRkY7fQo8L3N0eWxlPjx0aXRsZQogICAgIGlkPSJ0aXRsZTUiPnJlcGVhdDwvdGl0bGU+PHJlY3QKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6I2ZmZmZmZjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MTtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MC4wNzg0MzEzNyIKICAgICBpZD0icmVjdDQxNDMiCiAgICAgd2lkdGg9IjQuMDUwMDAwMiIKICAgICBoZWlnaHQ9IjEyLjM5NzA1IgogICAgIHg9IjkuOTc1MDAwNCIKICAgICB5PSItMTguMTk4NTI2IgogICAgIHJ4PSIwLjgxIgogICAgIHJ5PSIwLjgxIgogICAgIHRyYW5zZm9ybT0ic2NhbGUoMSwtMSkiIC8+PHJlY3QKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6I2ZmZmZmZjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MTtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MC4wNzg0MzEzNyIKICAgICBpZD0icmVjdDQxNDMtMSIKICAgICB3aWR0aD0iNC4wNTAwMDAyIgogICAgIGhlaWdodD0iMTIuMzk3MTE5IgogICAgIHg9IjkuOTc1MDAwNCIKICAgICB5PSI1LjgwMTQ0MDciCiAgICAgcng9IjAuODEiCiAgICAgcnk9IjAuODEiCiAgICAgdHJhbnNmb3JtPSJtYXRyaXgoMCwxLDEsMCwwLDApIiAvPjxjaXJjbGUKICAgICBzdHlsZT0ib3BhY2l0eToxO2ZpbGw6bm9uZTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6I2ZmZmZmZjtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpzcXVhcmU7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1kYXNob2Zmc2V0OjA7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICBpZD0icGF0aDQxMzYiCiAgICAgY3g9IjEyIgogICAgIGN5PSIxMiIKICAgICByPSIxMC41MDMxOTEiIC8+PC9zdmc+",i.REMOVE_IMAGE_DATAURI="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4KCjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG9kaS5zb3VyY2Vmb3JnZS5uZXQvRFREL3NvZGlwb2RpLTAuZHRkIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICBpZD0icmVwZWF0IgogICB4PSIwcHgiCiAgIHk9IjBweCIKICAgdmlld0JveD0iMCAwIDI0IDI0IgogICBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyNCAyNDsiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiCiAgIGlua3NjYXBlOnZlcnNpb249IjAuOTEgcjEzNzI1IgogICBzb2RpcG9kaTpkb2NuYW1lPSJyZW1vdmUuc3ZnIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGExNSI+PHJkZjpSREY+PGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPjxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PjxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz48ZGM6dGl0bGU+cmVwZWF0PC9kYzp0aXRsZT48L2NjOldvcms+PC9yZGY6UkRGPjwvbWV0YWRhdGE+PGRlZnMKICAgICBpZD0iZGVmczEzIiAvPjxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBwYWdlY29sb3I9IiNmZjFhZmYiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMSIKICAgICBvYmplY3R0b2xlcmFuY2U9IjEwIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwIgogICAgIGd1aWRldG9sZXJhbmNlPSIxMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTY4MCIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI5NTAiCiAgICAgaWQ9Im5hbWVkdmlldzExIgogICAgIHNob3dncmlkPSJmYWxzZSIKICAgICBpbmtzY2FwZTp6b29tPSIxOS42NjY2NjciCiAgICAgaW5rc2NhcGU6Y3g9IjAuMDUwODQ3NTIxIgogICAgIGlua3NjYXBlOmN5PSI5Ljk2NjEwMTciCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LXk9IjAiCiAgICAgaW5rc2NhcGU6d2luZG93LW1heGltaXplZD0iMCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJyZXBlYXQiIC8+PHN0eWxlCiAgICAgdHlwZT0idGV4dC9jc3MiCiAgICAgaWQ9InN0eWxlMyI+Cgkuc3Qwe2ZpbGw6I0NGOEIxNzt9Cgkuc3Qxe2ZpbGw6I0ZGRkZGRjt9Cjwvc3R5bGU+PHRpdGxlCiAgICAgaWQ9InRpdGxlNSI+cmVwZWF0PC90aXRsZT48cmVjdAogICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDojZmZmZmZmO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lO3N0cm9rZS13aWR0aDoxO3N0cm9rZS1saW5lY2FwOnNxdWFyZTtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eTowLjA3ODQzMTM3IgogICAgIGlkPSJyZWN0NDE0My0xIgogICAgIHdpZHRoPSI0LjA1MDAwMDIiCiAgICAgaGVpZ2h0PSIxMi4zOTcxMTkiCiAgICAgeD0iOS45NzUwMDA0IgogICAgIHk9IjUuODAxNDQwNyIKICAgICByeD0iMC44MSIKICAgICByeT0iMC44MSIKICAgICB0cmFuc2Zvcm09Im1hdHJpeCgwLDEsMSwwLDAsMCkiIC8+PGNpcmNsZQogICAgIHN0eWxlPSJvcGFjaXR5OjE7ZmlsbDpub25lO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTojZmZmZmZmO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOnNxdWFyZTtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLW1pdGVybGltaXQ6NDtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLWRhc2hvZmZzZXQ6MDtzdHJva2Utb3BhY2l0eToxIgogICAgIGlkPSJwYXRoNDEzNiIKICAgICBjeD0iMTIiCiAgICAgY3k9IjEyIgogICAgIHI9IjEwLjUwMzE5MSIgLz48L3N2Zz4="},{}],130:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isVariableBlockType=i.validateFunctionExternal=i.flyoutCategory=i.getShadowBlockInfoFromType_=i.findUniqueParamName=i.getArgumentReporterParent=i.doArgumentReporterDragChecks=i.isFunctionArgumentReporter=i.getArgMap=i.mutateCallersAndDefinition=i.idsInUse=i.findLegalName=i.createCustomArgumentEditor=i.createCustomArgumentReporter=i.isCustomType=i.getAllFunctionDefinitionBlocks=i.getDefinition=i.rename=void 0;const n=e("blockly"),s=e("./constants"),o=e("./functionManager"),r=e("./msg"),a=e("./blocks/functionDeclarationBlock"),l=e("../../compiler/util"),c=e("../../loader");function u(e,t){for(const i of t.getTopBlocks(!1))if(i.type===s.FUNCTION_DEFINITION_BLOCK_TYPE){const t=i;if(t.getName()===e)return t}return null}function h(e){return e.getTopBlocks(!1).filter(e=>e.type===s.FUNCTION_DEFINITION_BLOCK_TYPE)}function d(e,t,i){const s=i.newBlock(e),o=n.utils.xml.createElement("mutation");return o.setAttribute("typename",t),s.domToMutation(o),s}function p(e,t,i){if(null==i?void 0:i.isInFlyout)return e;const n=g(t,i);for(;n[e];)e=f(e);return e}function g(e,t,i){const n={};return e.getVariableMap().getAllVariables().forEach(function(e){n[e.getName()]=!0}),e.getAllBlocks(!1).forEach(function(e){const o=e;o==t||i&&o.getFunctionId&&o.getFunctionId()==i||(o.type==s.FUNCTION_DEFINITION_BLOCK_TYPE?n[o.getName()]=!0:"procedures_defreturn"==e.type||e.type)}),n}function f(e){const t=e.match(/^(.*?)(\d+)$/);return t?e=t[1]+(parseInt(t[2],10)+1):e+="2",e}function m(e,t,i){const o=u(e,t);if(o){const r=o.mutationToDom(),a=_(r,!1),l=_(i,!0),c=[];for(const e of o.getDescendants(!1)){if(!b(e))continue;const t=T(e,e);if(t&&t!==o)continue;const i=e.getFieldValue("VALUE"),n=l[a[i]];if(i===n)continue;const s=e.outputConnection.targetBlock().id,r=e.outputConnection.targetConnection.getParentInput().name;c.push({id:e.id,type:e.type,oldName:i,newName:n,targetBlockId:s,targetInputName:r})}const u=function(e,t){const i=[];for(const n of t.getAllBlocks(!1))if(n.type===s.FUNCTION_CALL_BLOCK_TYPE||n.type===s.FUNCTION_CALL_OUTPUT_BLOCK_TYPE){const t=n;t.getName()===e&&i.push(t)}return i}(e,o.workspace).map(e=>({id:e.id,oldMutation:n.utils.xml.domToText(e.mutationToDom()),shadows:e.serializeChangedInputs(i)})),h=new v(o.id,u,n.Xml.domToText(r),n.Xml.domToText(i),c);h.workspaceId=t.id,h.run(!0),n.Events.fire(h)}else pxt.warn("Attempted to change function "+e+", but no definition block was found on the workspace")}function _(e,t){const i={};for(let n=0;n<e.childNodes.length;++n){const s=e.childNodes[n],o=t?s.getAttribute("id"):s.getAttribute("name"),r=t?s.getAttribute("name"):s.getAttribute("id");i[o]=r}return i}function b(e){return e.type==s.ARGUMENT_REPORTER_BOOLEAN_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_NUMBER_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_STRING_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_ARRAY_BLOCK_TYPE||e.type==s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE}function T(e,t){pxt.U.assert(b(e));const i=e.getFieldValue("VALUE"),n=e.getTypeName();for(;t.getSurroundParent();){t=t.getSurroundParent();for(const e of t.inputList){if(!e.connection||!e.name.startsWith(c.DRAGGABLE_PARAM_INPUT_PREFIX))continue;if(e.name.slice(c.DRAGGABLE_PARAM_INPUT_PREFIX.length)!==i)continue;let s=n;return"string"!==s&&"number"!==s&&"boolean"!==s||(s=s.charAt(0).toUpperCase()+s.slice(1)),-1!==e.connection.getCheck().indexOf(s)?t:void 0}}if(!t.isEnabled())return t;if((0,l.isFunctionDefinition)(t)){if(t.getArguments().some(e=>e.name===i&&e.type===n))return t}}function E(e,t){return!t||-1==t.indexOf(e)}i.rename=function(e){e=e.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"");const t=this.sourceBlock_,i=p(e,t.workspace,t),n=this.getValue();if(!e)return n;if(!i)return e;if(!n)return t.name_=i,i;if(n!=e&&n!=i){t.name_=i;const e=t.mutationToDom();t.name_=n,m(n,t.workspace,e)}return i},i.getDefinition=u,i.getAllFunctionDefinitionBlocks=h,i.isCustomType=function(e){return!("boolean"==e||"string"==e||"number"==e)},i.createCustomArgumentReporter=function(e,t){return d(s.ARGUMENT_REPORTER_CUSTOM_BLOCK_TYPE,e,t)},i.createCustomArgumentEditor=function(e,t){return d(s.ARGUMENT_EDITOR_CUSTOM_BLOCK_TYPE,e,t)},i.findLegalName=p,i.idsInUse=function(e){const t=[];return e.getAllBlocks(!1).forEach(function(e){e.type==s.FUNCTION_DEFINITION_BLOCK_TYPE&&t.push(e.getFunctionId())}),t},i.mutateCallersAndDefinition=m,i.getArgMap=_,i.isFunctionArgumentReporter=b,i.doArgumentReporterDragChecks=function(e,t,i){const n=e.getSourceBlock();if(!b(n))return!0;const s=t.getSourceBlock();return!s||!!T(n,s)},i.getArgumentReporterParent=T,i.findUniqueParamName=function(e,t){for(;!E(e,t);)e=f(e);return e},i.getShadowBlockInfoFromType_=function(e,t){let i="",s="",r="";switch(e){case"boolean":i="logic_boolean",s="BOOL",r="TRUE";break;case"number":i="math_number",s="NUM",r="1";break;case"string":i="text",s="TEXT",r="abc";break;case"Array":i="variables_get",s="VAR",r=n.Variables.getOrCreateVariablePackage(t,null,"list","").getId();break;default:i="variables_get",s="VAR",r=n.Variables.getOrCreateVariablePackage(t,null,o.FunctionManager.getInstance().getArgumentNameForType(e),"").getId()}return[i,s,r]},i.flyoutCategory=function(e){const t=[],i=document.createElement("button"),l=n.Msg[r.MsgKey.FUNCTION_CREATE_NEW],c="CREATE_FUNCTION";i.setAttribute("text",l),i.setAttribute("callbackKey",c),e.registerButtonCallback(c,()=>{!function(e){n.hideChaff(),n.getSelected()&&n.getSelected().unselect();o.FunctionManager.getInstance().editFunctionExternal((0,a.newFunctionMutation)(e),function(e){return function(t){if(t){const i='<xml><block type="'+s.FUNCTION_DEFINITION_BLOCK_TYPE+'">'+n.Xml.domToText(t)+"</block></xml>",o=n.utils.xml.textToDom(i);n.Events.setGroup(!0);const r=n.Xml.domToBlock(o.firstChild,e);if(r.updateDisplay_(),e.getMetrics){const t=e.getMetrics(),i=r.getHeightWidth();r.moveBy(t.viewLeft+t.viewWidth/2-i.width/2,t.viewTop+t.viewHeight/2-i.height/2),r.scheduleSnapAndBump()}e.centerOnBlock(r.id,!0),n.Events.setGroup(!1),setTimeout(()=>{r.afterWorkspaceLoad&&r.afterWorkspaceLoad(),n.getFocusManager().focusNode(r)})}}}(e))}(e)}),t.push(i);for(const i of h(e)){const e=i.getName(),s=i.getArguments(),o=n.utils.xml.createElement("block");o.setAttribute("type","function_call"),o.setAttribute("gap","16");const r=n.utils.xml.createElement("mutation");r.setAttribute("name",e),o.appendChild(r);for(let e=0;e<s.length;e++){const t=n.utils.xml.createElement("arg");t.setAttribute("name",s[e].name),t.setAttribute("type",s[e].type),t.setAttribute("id",s[e].id),r.appendChild(t)}t.push(o)}return t},i.validateFunctionExternal=function(e,t){const i=e.getAttribute("name");if(!i)return n.dialog.alert(n.Msg.FUNCTION_WARNING_EMPTY_NAME),!1;const s={};for(let t=0;t<e.childNodes.length;++t){const i=e.childNodes[t].getAttribute("name");if(!i)return n.dialog.alert(n.Msg.FUNCTION_WARNING_EMPTY_NAME),!1;if(s[i])return n.dialog.alert(n.Msg.FUNCTION_WARNING_DUPLICATE_ARG),!1;s[i]=!0}return s[i]?(n.dialog.alert(n.Msg.FUNCTION_WARNING_ARG_NAME_IS_FUNCTION_NAME),!1):!g(t,null,e.getAttribute("functionid"))[i]||(n.dialog.alert(n.Msg.VARIABLE_ALREADY_EXISTS.replace("%1",i)),!1)},i.isVariableBlockType=function(e){switch(e){case"argument_reporter_boolean":case"argument_reporter_number":case"argument_reporter_string":case"argument_reporter_array":case"argument_reporter_custom":case"variables_get_reporter":case"variables_get":return!0}return!1};class v extends n.Events.Abstract{constructor(e,t,i,n,s){super(),this.definition=e,this.callers=t,this.oldMutation=i,this.newMutation=n,this.descendantChanges=s,this.type="pxt_mutate_function"}static fromJson(e,t,i){const n=i=super.fromJson(e,t,i||new v(e.definition,e.callers,e.oldMutation,e.newMutation,e.descendantChanges));return n.definition=e.definition,n.callers=e.callers,n.oldMutation=e.oldMutation,n.newMutation=e.newMutation,n.descendantChanges=e.descendantChanges,i}toJson(){return{type:this.type,group:this.group,definition:this.definition,callers:this.callers,oldMutation:this.oldMutation,newMutation:this.newMutation,descendantChanges:this.descendantChanges}}run(e){const t=this.getEventWorkspace_(),i=n.utils.xml.textToDom(e?this.newMutation:this.oldMutation),s=t.getBlockById(this.definition);n.Events.disable(),s.domToMutation(i),s.updateArgumentInputs_(),s.afterWorkspaceLoad();for(const s of this.callers){const o=t.getBlockById(s.id);if(e)o.domToMutation(i);else{o.domToMutation(n.utils.xml.textToDom(s.oldMutation));for(const e of s.shadows)if(e.connectedBlock){const i=t.getBlockById(e.connectedBlock);o.getInput(e.inputName).connection.connect(i.outputConnection)}else o.getInput(e.inputName).connection.setShadowState(e.connectedShadow)}}for(const i of this.descendantChanges)if(i.newName){t.getBlockById(i.id).setFieldValue(e?i.newName:i.oldName,"VALUE")}else if(e){const e=t.getBlockById(i.id);e&&e.dispose()}else{const e=t.newBlock(i.type,i.id);e.setFieldValue(i.oldName,"VALUE"),e.initSvg();const n=t.getBlockById(i.targetBlockId).getInput(i.targetInputName).connection,s=n.targetBlock();s&&(s.isShadow()||s.dispose()),n.connect(e.outputConnection)}n.Events.enable()}}},{"../../compiler/util":15,"../../loader":79,"./blocks/functionDeclarationBlock":118,"./constants":121,"./functionManager":126,"./msg":128,blockly:256}],131:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly");n.Extensions.unregister("logic_compare"),n.Extensions.register("logic_compare",function(){})},{blockly:256}],132:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../../fields/field_imagenotext"),o=e("../../utils"),r={elseifCount_:0,elseCount_:0,valueConnections_:[],statementConnections_:[],elseStatementConnection_:null,mutationToDom:function(){if(!this.elseifCount_&&!this.elseCount_)return null;const e=n.utils.xml.createElement("mutation");return this.elseifCount_&&e.setAttribute("elseif",this.elseifCount_+""),this.elseCount_&&e.setAttribute("else","1"),e},domToMutation:function(e){e&&(this.elseifCount_=parseInt(e.getAttribute("elseif"),10)||0,this.elseCount_=parseInt(e.getAttribute("else"),10)||0,this.rebuildShape_())},storeConnections_:function(e){e||(e=0),this.valueConnections_=[null],this.statementConnections_=[null],this.elseStatementConnection_=null;for(let t=1;t<=this.elseifCount_;t++)e!=t&&(this.valueConnections_.push(this.getInput("IF"+t).connection.targetConnection),this.statementConnections_.push(this.getInput("DO"+t).connection.targetConnection));this.getInput("ELSE")&&(this.elseStatementConnection_=this.getInput("ELSE").connection.targetConnection)},restoreConnections_:function(){var e,t;for(let t=1;t<=this.elseifCount_;t++)this.reconnectValueConnection_(t,this.valueConnections_),null===(e=this.statementConnections_[t])||void 0===e||e.reconnect(this,"DO"+t);this.getInput("ELSE")&&(null===(t=this.elseStatementConnection_)||void 0===t||t.reconnect(this,"ELSE"))},addElse_:function(){n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else branch added."));this.update_(()=>{this.elseCount_++})},removeElse_:function(){var e,t;n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else branch removed."));this.update_(()=>{this.elseCount_--});const i="IF"+this.elseifCount_;(0,o.maybeMoveFocusFromButton)(null===(t=null===(e=this.getInput(i))||void 0===e?void 0:e.connection)||void 0===t?void 0:t.targetBlock())},addElseIf_:function(){n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else if branch added."));this.update_(()=>{this.elseifCount_++})},removeElseIf_:function(e){var t,i;n.utils.aria.announceDynamicAriaState(pxt.Util.lf("Else if branch removed."));this.update_(()=>{this.elseifCount_--},e);const s="IF"+(e-1);(0,o.maybeMoveFocusFromButton)(null===(i=null===(t=this.getInput(s))||void 0===t?void 0:t.connection)||void 0===i?void 0:i.targetBlock())},update_:function(e,t){n.Events.setGroup(!0),this.storeConnections_(t);const i=this,s=i.mutationToDom(),o=s&&n.Xml.domToText(s);e&&e.call(this),this.updateShape_(),i instanceof n.BlockSvg&&i.initSvg();const r=n.Events.getGroup(),a=i.mutationToDom(),l=a&&n.Xml.domToText(a);o!=l&&(n.Events.fire(new n.Events.BlockChange(i,"mutation",null,o,l)),setTimeout(function(){n.Events.setGroup(r),i.bumpNeighbours(),n.Events.setGroup(!1)},n.config.bumpDelay)),i.rendered&&i instanceof n.BlockSvg&&i.queueRender(),this.restoreConnections_(),n.Events.setGroup(!1)},updateShape_:function(){this.getInput("ELSE")&&(this.removeInput("ELSE"),this.removeInput("ELSETITLE"),this.removeInput("ELSEBUTTONS"));let e=1;for(;this.getInput("IF"+e);)this.removeInput("IF"+e),this.removeInput("IFTITLE"+e),this.removeInput("IFBUTTONS"+e),this.removeInput("DO"+e),e++;for(let e=1;e<=this.elseifCount_;e++){const i=function(e){return function(){t.removeElseIf_(e)}}(e);this.appendValueInput("IF"+e).setCheck("Boolean").appendField(n.Msg.CONTROLS_IF_MSG_ELSEIF).setShadowDom(a()),this.appendDummyInput("IFTITLE"+e).appendField(n.Msg.CONTROLS_IF_MSG_THEN),this.appendDummyInput("IFBUTTONS"+e).appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,pxt.Util.lf("remove else if branch"),i,!1)).setAlign(n.inputs.Align.RIGHT),this.appendStatementInput("DO"+e)}this.elseCount_&&(this.appendDummyInput("ELSETITLE").appendField(n.Msg.CONTROLS_IF_MSG_ELSE),this.appendDummyInput("ELSEBUTTONS").setAlign(n.inputs.Align.RIGHT).appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,pxt.Util.lf("remove else branch"),this.removeElse_.bind(this),!1)),this.appendStatementInput("ELSE")),this.getInput("ADDBUTTON")&&this.removeInput("ADDBUTTON");const t=this,i=function(){var e,i,s;if(0==t.elseCount_)t.addElse_(),(0,o.maybeMoveFocusFromButton)(null===(e=t.getInput("ELSEBUTTONS"))||void 0===e?void 0:e.fieldRow[0]);else{t.elseifCount_||(t.elseifCount_=0),t.addElseIf_();const e=n.getFocusManager(),o=null===(s=null===(i=t.getInput("IF"+t.elseifCount_))||void 0===i?void 0:i.connection)||void 0===s?void 0:s.targetBlock();e.focusNode(o)}};this.appendDummyInput("ADDBUTTON").appendField(new s.FieldImageNoText(this.ADD_IMAGE_DATAURI,24,24,this.elseCount_?pxt.Util.lf("add else if branch"):pxt.Util.lf("add else branch"),i,!1))},rebuildShape_:function(){const e=[null],t=[null];let i=null;this.getInput("ELSE")&&(i=this.getInput("ELSE").connection.targetConnection);let n=1;for(;this.getInput("IF"+n);){const i=this.getInput("IF"+n),s=this.getInput("DO"+n);e.push(i.connection.targetConnection),t.push(s.connection.targetConnection),n++}this.updateShape_(),this.reconnectChildBlocks_(e,t,i)},reconnectChildBlocks_:function(e,t,i){var n;for(let i=1;i<=this.elseifCount_;i++)this.reconnectValueConnection_(i,e),null===(n=t[i])||void 0===n||n.reconnect(this,"DO"+i);null==i||i.reconnect(this,"ELSE")},reconnectValueConnection_:function(e,t){var i;const n=null===(i=this.getInput("IF"+e))||void 0===i?void 0:i.connection.targetBlock();t[e]&&(t[e].reconnect(this,"IF"+e),n&&!n.getParent()&&n.dispose())}};function a(){const e=document.createElement("shadow");e.setAttribute("type","logic_boolean");const t=document.createElement("field");return t.setAttribute("name","BOOL"),t.textContent="FALSE",e.appendChild(t),e}n.Blocks.controls_if=Object.assign(Object.assign({},r),{init(){if(n.Extensions.apply("inline-svgs",this,!1),this.elseifCount_=0,this.elseCount_=0,this.setHelpUrl(n.Msg.CONTROLS_IF_HELPURL),this.appendValueInput("IF0").setCheck("Boolean").appendField(n.Msg.CONTROLS_IF_MSG_IF),this.appendDummyInput("THEN0").appendField(n.Msg.CONTROLS_IF_MSG_THEN),this.appendStatementInput("DO0"),this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer();this.setOutputShape(e.getConstants().SHAPES.HEXAGONAL)}this.updateShape_(),this.setInputsInline(!0),this.setColour(n.Msg.LOGIC_HUE),this.setPreviousStatement(!0),this.setNextStatement(!0),this.setTooltip(()=>this.elseifCount_||this.elseCount_?!this.elseifCount_&&this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_2:this.elseifCount_&&!this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_3:this.elseifCount_&&this.elseCount_?n.Msg.CONTROLS_IF_TOOLTIP_4:"":n.Msg.CONTROLS_IF_TOOLTIP_1)}})},{"../../fields/field_imagenotext":38,"../../utils":155,blockly:256}],133:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./extensions"),i),s(e("./ifElse"),i)},{"./extensions":131,"./ifElse":132}],134:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldSlider=void 0;const n=e("blockly");class s extends n.FieldNumber{constructor(e,t,i,n,s,o,r,a){super(e,t,i,n,r,a),this.keyboardControlActive=!1,"string"==typeof s?this.step_=parseFloat(s):"number"==typeof s&&(this.step_=s),this.labelText_=o}hasMin(){return this.getMin()>-1/0}hasMax(){return this.getMax()<1/0}getStep(){return this.step_}getLabel(){return this.labelText_}setLabel(e){this.labelText_=e}setOptions(e,t,i,n){this.setConstraints(e,t,n),this.step_=parseFloat(i)||void 0}getFieldDescription(){return this.getValue()+""}doClassValidation_(e){if(null===e)return null;e=(e=(e=(e=`${e}`).replace(/O/gi,"0")).replace(/,/g,"")).replace(/infinity/i,"Infinity");let t=Number(e||0);if(isNaN(t))return null;this.precision_&&isFinite(t)&&(t=Math.round(t/this.precision_)*this.precision_);let i=String(this.precision_);-1!==i.indexOf("e")&&(i=this.precision_.toLocaleString("en-US",{maximumFractionDigits:20}));const n=i.indexOf(".");let s;return s=-1===n?this.precision_?0:null:i.length-n-1,null!==s&&(t=Number(t.toFixed(s))),t}widgetDispose_(){this.removeEventListeners(),super.widgetDispose_()}addEventListeners(){this.inputKeydownHandler=this.inputKeydownListener.bind(this),this.htmlInput_.addEventListener("keydown",this.inputKeydownHandler),this.sliderKeydownHandler=this.sliderKeydownListener.bind(this),this.slider_.addEventListener("keydown",this.sliderKeydownHandler),this.sliderBlurHandler=this.sliderBlurListener.bind(this),this.slider_.addEventListener("blur",this.sliderBlurHandler),this.sliderPointerdownHandler=this.sliderPointerdownListener.bind(this),this.slider_.addEventListener("pointerdown",this.sliderPointerdownHandler)}removeEventListeners(){this.htmlInput_.removeEventListener("keydown",this.inputKeydownHandler),this.slider_.removeEventListener("keydown",this.sliderKeydownHandler),this.slider_.removeEventListener("blur",this.sliderBlurHandler),this.slider_.removeEventListener("pointerdown",this.sliderPointerdownHandler)}inputKeydownListener(e){"ArrowDown"===e.key&&(e.preventDefault(),this.keyboardControlActive=!0,this.slider_.focus())}sliderPointerdownListener(e){this.keyboardControlActive=!1}sliderKeydownListener(e){switch(e.key){case"ArrowUp":e.preventDefault(),this.htmlInput_.focus();break;case"Enter":case" ":e.preventDefault(),e.stopPropagation(),n.hideChaff();break;case"ArrowDown":e.preventDefault(),e.stopPropagation()}}sliderBlurListener(e){this.keyboardControlActive=!1}showEditor_(e,t){super.showEditor_(e,!0),"number"==typeof this.min_&&"number"==typeof this.max_&&(this.htmlInput_.ariaLabel=lf("Enter a value between {0} and {1}",this.min_,this.max_)),n.DropDownDiv.hideWithoutAnimation(),n.DropDownDiv.clearContent();const i=n.DropDownDiv.getContentDiv();i.style.height="",i.parentElement.classList.add("blocklyFieldSliderDropdown"),this.addSlider_(i),n.DropDownDiv.setColour("#ffffff","#dddddd"),n.DropDownDiv.showPositionedByBlock(this,this.sourceBlock_,void 0,void 0,!1),this.addEventListeners(),t||(this.htmlInput_.focus(),this.htmlInput_.select())}addSlider_(e){if(this.labelText_){let t=this.createLabelDom_(this.labelText_);e.appendChild(t[0]),this.readout_=t[1],this.setReadout(this.value_)}this.slider_=this.createSlider(),e.appendChild(this.slider_);const t=()=>{pxt.BrowserUtils.isFirefox()||this.keyboardControlActive||this.htmlInput_.focus()};n.browserEvents.bind(this.slider_,"input",this,e=>{const i=parseFloat(this.slider_.value)||0;if(null!==i){this.setValue(i);const e=this.htmlInput_;e&&(e.value=i+"",t())}}),n.browserEvents.bind(this.slider_,"focus",this,e=>{t()})}setValue(e,t){super.setValue(e,t),this.updateDom(),this.slider_&&(this.slider_.value=this.getValue()+"")}createSlider(){const e=document.createElement("input");let t;return e.setAttribute("class","blocklyFieldSlider"),e.type="range",e.min=this.getMin()+"",e.max=this.getMax()+"",e.value=this.getValue()+"",this.sourceBlock_ instanceof n.BlockSvg&&("#ffffff"===this.sourceBlock_.getColour()?this.sourceBlock_.getParent()&&(t=this.sourceBlock_.getParent().getColourTertiary()):t=this.sourceBlock_.getColourTertiary()),t&&e.setAttribute("style",`--blocklyFieldSliderBackgroundColor: ${t}`),Number.isNaN(this.step_)||(e.step=this.step_+""),e}updateDom(){this.setReadout(this.getValue())}setReadout(e){this.readout_&&(this.readout_.innerText=e+"")}createLabelDom_(e){const t=document.createElement("div");t.setAttribute("class","blocklyFieldSliderLabel");const i=document.createElement("span");i.setAttribute("class","blocklyFieldSliderReadout");const n=document.createElement("span");return n.setAttribute("class","blocklyFieldSliderLabelText"),n.innerText=e,t.appendChild(n),t.appendChild(i),[t,i]}}i.FieldSlider=s,n.fieldRegistry.register("field_slider",s),n.Css.register('\n:root {\n --blocklyFieldSliderBackgroundColor: #547AB2;\n --blocklyFieldSliderThumbColor: #ffffff;\n --blocklyFieldSliderThumbBorderColor: rgba(0, 0, 0, 0.15);\n}\n.blocklyFieldSliderLabel {\n font-family: "Helvetica Neue", "Segoe UI", Helvetica, sans-serif;\n font-size: 0.65rem;\n color: #000000;\n margin: 8px;\n}\n.blocklyFieldSliderLabelText {\n font-weight: bold;\n}\n.blocklyFieldSliderReadout {\n margin-left: 10px;\n}\n\ninput[type=range].blocklyFieldSlider {\n -webkit-appearance: none;\n width: 100%;\n}\ninput[type=range].blocklyFieldSlider:focus {\n outline: none;\n}\ninput[type=range].blocklyFieldSlider::-webkit-slider-runnable-track {\n -webkit-appearance: none;\n margin: 8px;\n height: 22px;\n width: 150px;\n outline: none;\n border-radius: 11px;\n margin-bottom: 20px;\n background: var(--blocklyFieldSliderBackgroundColor);\n}\ninput[type=range].blocklyFieldSlider::-webkit-slider-thumb {\n -webkit-appearance: none;\n width: 26px;\n height: 26px;\n margin-top: -1px;\n background-color: var(--blocklyFieldSliderThumbColor);\n border-radius: 100%;\n -webkit-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n -moz-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n cursor: pointer;\n}\ninput[type=range].blocklyFieldSlider:focus-visible::-webkit-slider-thumb {\n outline: 2px solid white;\n outline-offset: 3px;\n -webkit-box-shadow: 0 0 0 3px var(--pxt-focus-border);\n -moz-box-shadow: 0 0 0 3px var(--pxt-focus-border);\n box-shadow: 0 0 0 3px var(--pxt-focus-border);\n}\ninput[type=range].blocklyFieldSlider::-moz-range-track {\n margin: 8px;\n height: 22px;\n width: 95%;\n outline: none;\n border-radius: 11px;\n margin-bottom: 20px;\n background: var(--blocklyFieldSliderBackgroundColor);\n}\ninput[type=range].blocklyFieldSlider::-moz-range-thumb {\n width: 26px;\n height: 26px;\n margin-top: -1px;\n background-color: var(--blocklyFieldSliderThumbColor);\n border-radius: 100%;\n -webkit-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n -moz-box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n box-shadow: 0 0 0 4px var(--blocklyFieldSliderThumbBorderColor);\n cursor: pointer;\n}\n')},{blockly:256}],135:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldSlider"),i),s(e("./numberBlocks"),i)},{"./fieldSlider":134,"./numberBlocks":136}],136:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=new n.zelos.ConstantProvider;n.defineBlocksWithJsonArray([{type:"math_integer",message0:"%1",args0:[{type:"field_number",name:"NUM",precision:1,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_whole_number",message0:"%1",args0:[{type:"field_number",name:"NUM",min:0,precision:1,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_positive_number",message0:"%1",args0:[{type:"field_number",name:"NUM",min:0,ariaTypeName:lf("value")}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"math_number_minmax",message0:"%1",args0:[{type:"field_slider",name:"SLIDER",value:0,step:1,labelText:"Number"}],output:"Number",outputShape:s.SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_MATH_NUMBER_HELPURL}",tooltip:"%{BKY_MATH_NUMBER_TOOLTIP}",mutator:"math_number_minmax_mutator",extensions:["parent_tooltip_when_inline"]}]);const o={mutationToDom:function(){const e=this.inputList[0].fieldRow[0];let t=n.utils.xml.createElement("mutation");return e.hasMin()&&t.setAttribute("min",e.getMin()+""),e.hasMax()&&t.setAttribute("max",e.getMax()+""),null!=e.getLabel()&&t.setAttribute("label",e.getLabel()),null!=e.getStep()&&t.setAttribute("step",e.getStep()+""),null!=e.getPrecision()&&t.setAttribute("precision",e.getPrecision()+""),t},domToMutation:function(e){const t=this.inputList[0].fieldRow[0],i=e.getAttribute("min"),n=e.getAttribute("max"),s=e.getAttribute("step"),o=e.getAttribute("label"),r=e.getAttribute("precision");t.setLabel(o),t.setOptions(i,n,s,r)}};n.Extensions.registerMutator("math_number_minmax_mutator",o)},{blockly:256}],137:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldVariable=void 0;const n=e("blockly");class s extends n.FieldVariable{constructor(e,t,i,n,o){super(e,t,i,n,o),this.svgRootBinding=null,this.fieldRootBinding=null,this.menuGenerator_=s.dropdownCreate}static dropdownCreate(){const e=n.FieldVariable.dropdownCreate.call(this),t=e.findIndex(e=>"RENAME_VARIABLE_ID"===e[1]);return e.splice(t,0,[n.Msg.NEW_VARIABLE_DROPDOWN,s.CREATE_VARIABLE_ID],n.FieldDropdown.SEPARATOR),e}onItemSelected_(e,t){if(this.sourceBlock_&&!this.sourceBlock_.isDeadOrDying()){if(t.getValue()===s.CREATE_VARIABLE_ID)return void n.Variables.createVariableButtonHandler(this.sourceBlock_.workspace,e=>{const t=this.sourceBlock_.workspace.getVariableMap().getVariable(e);t&&this.setValue(t.getId())})}super.onItemSelected_(e,t)}initView(){super.initView(),this.shouldAddBorderRect_()||(this.createBorderRect_(),this.clickTargetRect=this.borderRect_,this.clickTargetRect.setAttribute("stroke-opacity","0"),this.clickTargetRect.setAttribute("fill-opacity","0"),this.borderRect_=void 0)}shouldAddBorderRect_(){if("variables_get"===this.sourceBlock_.type)return!1;for(const e of this.sourceBlock_.inputList)for(const t of e.fieldRow)if(t!==this&&t.EDITABLE)return!0;return!this.sourceBlock_.getInputsInline()||super.shouldAddBorderRect_()}bindEvents_(){this.shouldAddBorderRect_()?super.bindEvents_():(this.svgRootBinding=n.browserEvents.conditionalBind(this.sourceBlock_.getSvgRoot(),"pointerdown",this,e=>{this.sourceBlock_.icons.length||this.onMouseDown_(e)},!1),this.fieldRootBinding=n.browserEvents.conditionalBind(this.getSvgRoot(),"pointerdown",this,e=>{this.sourceBlock_.icons.length&&this.onMouseDown_(e)},!1))}dispose(){super.dispose(),this.svgRootBinding&&(n.browserEvents.unbind(this.svgRootBinding),n.browserEvents.unbind(this.fieldRootBinding))}positionBorderRect_(){super.positionBorderRect_(),this.clickTargetRect&&(this.clickTargetRect.setAttribute("width",String(this.size_.width)),this.clickTargetRect.setAttribute("height",String(this.size_.height)),this.clickTargetRect.setAttribute("rx",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)),this.clickTargetRect.setAttribute("ry",String(this.getConstants().FIELD_BORDER_RECT_RADIUS)))}getValue(){var e,t;const i=super.getValue();if(null===(e=this.sourceBlock_)||void 0===e?void 0:e.isInFlyout){if((null===(t=this.sourceBlock_.workspace)||void 0===t?void 0:t.getPotentialVariableMap()).getVariableById(i))return"potential_"+i}return i}}i.FieldVariable=s,s.CREATE_VARIABLE_ID="CREATE_VARIABLE",n.fieldRegistry.unregister("field_variable"),n.fieldRegistry.register("field_variable",s)},{blockly:256}],138:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldVariable"),i)},{"./fieldVariable":137}],139:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isCollapsedInputRow=i.CollapsedInputRow=void 0;const n=e("blockly");class s extends n.blockRendering.InputRow{constructor(e){super(e),this.type|=n.blockRendering.Types.INPUT_ROW|n.blockRendering.Types.getType("COLLAPSED_INPUT_ROW")}measure(){this.width=this.minWidth,this.height=this.constants_.EMPTY_STATEMENT_INPUT_HEIGHT}}i.CollapsedInputRow=s,i.isCollapsedInputRow=function(e){return!!(e.type&n.blockRendering.Types.getType("COLLAPSED_INPUT_ROW"))}},{blockly:256}],140:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ConnectionPreviewer=void 0;const n=e("blockly");class s extends n.InsertionMarkerPreviewer{previewConnection(e,t){super.previewConnection(e,t),t.type!==n.ConnectionType.INPUT_VALUE&&t.type!==n.ConnectionType.OUTPUT_VALUE||this.showDraggedIndicatorWithLine(e,t)}previewReplacement(e,t,i){super.previewReplacement(e,t,i),this.showDraggedIndicatorWithLine(e,t)}showDraggedIndicatorWithLine(e,t){if(!this.connectionLine){this.connectionLine=n.utils.dom.createSvgElement("line",{class:"blocklyConnectionLine",x1:0,y1:0,x2:0,y2:0},e.sourceBlock_.getSvgRoot()),this.draggedConnectionIndicator=this.createConnectionIndicator(e.sourceBlock_.getSvgRoot(),e);const i=t.sourceBlock_.getSvgRoot().querySelector(":scope>.blocklyConnectionIndicatorParent");this.staticConnectionIndicator=this.createConnectionIndicator(i,t)}this.raiseIndicators(),this.updateLineCoords(e,t),n.renderManagement.finishQueuedRenders().then(()=>{this.connectionLine&&(this.raiseIndicators(),this.updateLineCoords(e,t))})}raiseIndicators(){var e,t;null===(e=this.draggedConnectionIndicator.parentElement)||void 0===e||e.appendChild(this.draggedConnectionIndicator);const i=this.staticConnectionIndicator.parentElement;i.appendChild(this.staticConnectionIndicator),null===(t=i.parentElement)||void 0===t||t.appendChild(i)}updateLineCoords(e,t){const i=s.CONNECTION_INDICATOR_RADIUS,o=e.getOffsetInBlock(),r=t.getOffsetInBlock();this.draggedConnectionIndicator.setAttribute("transform",`translate(${o.x}, ${o.y})`),this.staticConnectionIndicator.setAttribute("transform",`translate(${r.x}, ${r.y})`);const a=n.utils.Coordinate.sum(e.sourceBlock_.getRelativeToSurfaceXY(),o),l=n.utils.Coordinate.sum(t.sourceBlock_.getRelativeToSurfaceXY(),r),c=l.x-a.x,u=l.y-a.y;if(Math.sqrt(c*c+u*u)<2*i+1)return void n.utils.dom.addClass(this.connectionLine,"hidden");n.utils.dom.removeClass(this.connectionLine,"hidden");const h=Math.atan2(u,c);this.connectionLine.setAttribute("x1",String(o.x+Math.cos(h)*i)),this.connectionLine.setAttribute("y1",String(o.y+Math.sin(h)*i)),this.connectionLine.setAttribute("x2",String(o.x+c-Math.cos(h)*i)),this.connectionLine.setAttribute("y2",String(o.y+u-Math.sin(h)*i))}hidePreview(){super.hidePreview(),this.connectionLine&&(this.connectionLine.remove(),this.connectionLine=null,this.draggedConnectionIndicator.remove(),this.draggedConnectionIndicator=null,this.staticConnectionIndicator.remove(),this.staticConnectionIndicator=null,this.staticConnection=null)}createConnectionIndicator(e,t){const i=n.utils.dom.createSvgElement("g",{class:"blocklyInputConnectionIndicator"},e);n.utils.dom.createSvgElement("circle",{r:s.CONNECTION_INDICATOR_RADIUS},i);const o=t.getOffsetInBlock();return i.setAttribute("transform","translate("+o.x+","+o.y+")"),i}}i.ConnectionPreviewer=s,s.CONNECTION_INDICATOR_RADIUS=9},{blockly:256}],141:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ConstantProvider=void 0;const n=e("blockly");class s extends n.zelos.ConstantProvider{constructor(){super(...arguments),this.FIELD_TEXT_FONTFAMILY='"Consolas", "Monaco", "Menlo", "Ubuntu Mono", "source-code-pro", monospace',this.FIELD_TEXT_FONTWEIGHT="600",this.HIGHLIGHT_GLOW_COLOUR="#FFF200",this.ERROR_HIGHLIGHT_GLOW_COLOR="#FF0000",this.HIGHLIGHT_GLOW_SIZE=1.1,this.ELLIPSES_RADIUS=6,this.ELLIPSES_SPACING=8,this.ellipses=this.makeEllipses()}createDom(e,t,i){super.createDom(e,t,i);const s=n.utils.dom.createSvgElement(n.utils.Svg.DEFS,{},e);this.highlightOutlineFilter=this.createHighlight(s,"blocklyHighlightedGlowFilter",this.HIGHLIGHT_GLOW_COLOUR),this.highlightOutlineFilterId=this.highlightOutlineFilter.id,this.errorOutlineFilter=this.createHighlight(s,"blocklyErrorHighlightedGlowFilter",this.ERROR_HIGHLIGHT_GLOW_COLOR),this.errorOutlineFilterId=this.errorOutlineFilter.id,this.embossFilterOverride=this.createOutline(s,"blocklyBubbleEmbossGlowFilter"),this.embossFilterId=this.embossFilterOverride.id}dispose(){super.dispose(),this.highlightOutlineFilter&&n.utils.dom.removeNode(this.highlightOutlineFilter)}makeEllipses(){const e=this.ELLIPSES_RADIUS,t=this.ELLIPSES_SPACING;let i="";for(let s=0;s<3;s++)i+=n.utils.svgPaths.moveBy(t,0)+n.utils.svgPaths.arc("a","180 1,1",e,n.utils.svgPaths.point(2*e,0));for(let s=0;s<3;s++)i+=n.utils.svgPaths.arc("a","180 1,1",e,n.utils.svgPaths.point(2*-e,0))+n.utils.svgPaths.moveBy(-t,0);return i}getCSS_(e){return super.getCSS_(e).concat([e+" .blocklyConnectionIndicator, "+e+" .blocklyInputConnectionIndicator {","fill: #ff0000;","stroke: #ffff00;","stroke-width: 3px;","}",e+" .blocklyConnectionIndicator {","display: none;","}",e+" .blocklyBlockDragSurface > g > .blocklyDraggable > .blocklyConnectionIndicator {","display: block;","}",e+" .blocklyConnectionLine {","stroke: #ffff00;","stroke-width: 4px;","}",e+" .blocklyConnectionLine.hidden {","display: none;","}",e+" .blocklyFlyoutHeading .blocklyFlyoutLabelText {font-size: 1.5rem;","}",`${e} .blocklyText::selection {`,"fill: #fff;","}",`${e} .blocklyNonEditableField>text::selection,`,`${e} .blocklyEditableField>text::selection,`,`${e} .blocklyNonEditableField>g>text::selection,`,`${e} .blocklyEditableField>g>text::selection {`,"fill: #575E75;","}",`${e} .blocklyDropdownText::selection {`,"fill: #fff !important;","}"])}createHighlight(e,t,i){const s=n.utils.dom.createSvgElement(n.utils.Svg.FILTER,{id:t+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},e);n.utils.dom.createSvgElement(n.utils.Svg.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:this.HIGHLIGHT_GLOW_SIZE},s);const o=n.utils.dom.createSvgElement(n.utils.Svg.FECOMPONENTTRANSFER,{result:"outBlur"},s);return n.utils.dom.createSvgElement(n.utils.Svg.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},o),n.utils.dom.createSvgElement(n.utils.Svg.FEFLOOD,{"flood-color":i,"flood-opacity":1,result:"outColor"},s),n.utils.dom.createSvgElement(n.utils.Svg.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},s),s}createOutline(e,t){const i=n.utils.dom.createSvgElement(n.utils.Svg.FILTER,{id:t+this.randomIdentifier,height:"160%",width:"180%",y:"-30%",x:"-40%"},e);n.utils.dom.createSvgElement(n.utils.Svg.FEGAUSSIANBLUR,{in:"SourceGraphic",stdDeviation:.92},i);const s=n.utils.dom.createSvgElement(n.utils.Svg.FECOMPONENTTRANSFER,{result:"outBlur"},i);n.utils.dom.createSvgElement(n.utils.Svg.FEFUNCA,{type:"table",tableValues:"0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1"},s),n.utils.dom.createSvgElement(n.utils.Svg.FEFLOOD,{"flood-color":"#000000","flood-opacity":.5,result:"outColor"},i),n.utils.dom.createSvgElement(n.utils.Svg.FECOMPOSITE,{in:"outColor",in2:"outBlur",operator:"in",result:"outGlow"},i);const o=n.utils.dom.createSvgElement("feMerge",{},i);return n.utils.dom.createSvgElement("feMergeNode",{in:"outBlur"},o),n.utils.dom.createSvgElement("feMergeNode",{in:"outGlow"},o),n.utils.dom.createSvgElement("feMergeNode",{in:"SourceGraphic"},o),i}shapeFor(e){let t=e.getCheck();switch(!t&&e.targetConnection&&(t=e.targetConnection.getCheck()),e.type){case n.ConnectionType.INPUT_VALUE:case n.ConnectionType.OUTPUT_VALUE:return t&&t.includes("Boolean")?this.HEXAGONAL:(t&&t.includes("Number")||t&&t.includes("String"),this.ROUNDED);case n.ConnectionType.PREVIOUS_STATEMENT:case n.ConnectionType.NEXT_STATEMENT:return this.NOTCH;default:throw Error("Unknown type")}}}i.ConstantProvider=s,s.COLLAPSE_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.354)'%3E%3Cpath d='m1611 367.42q0 53-37 90l-651 651q-38 38-91 38-54 0-90-38l-651-651q-38-36-38-90 0-53 38-91l74-75q39-37 91-37 53 0 90 37l486 486 486-486q37-37 90-37 52 0 91 37l75 75q37 39 37 91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A",s.EXPAND_IMAGE_DATAURI="data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg enable-background='new 0 0 24 24' version='1.1' viewBox='0 0 24 24' xml:space='preserve' xmlns='http://www.w3.org/2000/svg'%3E%3Cstyle type='text/css'%3E .st0%7Bfill:%23CF8B17;%7D .st1%7Bfill:%23FFFFFF;%7D%0A%3C/style%3E%3Ctitle%3Erepeat%3C/title%3E%3Ccircle cx='12' cy='12' r='10.503' fill='none' stroke='%23fff' stroke-linecap='square' stroke-linejoin='round' stroke-width='2'/%3E%3Cg transform='matrix(.0086269 0 0 -.0086269 4.8224 17.654)'%3E%3Cpath d='m1611 832q0-53-37-90l-651-651q-38-38-91-38-54 0-90 38l-651 651q-38 36-38 90 0 53 38 91l74 75q39 37 91 37 53 0 90-37l486-486 486 486q37 37 90 37 52 0 91-37l75-75q37-39 37-91z' fill='%23fff'/%3E%3C/g%3E%3C/svg%3E%0A"},{blockly:256}],142:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});e("blockly").Css.register("\n.blocklyDropdownMenu .blocklyMenuItemCheckbox {\n filter: contrast(0) brightness(100);\n}\n\n.blocklyVerticalMarker {\n fill: none;\n}\n")},{blockly:256}],143:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Drawer=void 0;const n=e("blockly"),s=e("./collapsedInputRow");class o extends n.zelos.Drawer{drawCollapsedStack_(e){const t=this.constants_.STATEMENT_INPUT_NOTCH_OFFSET+this.constants_.INSIDE_CORNERS.width,i=this.constants_.STATEMENT_INPUT_PADDING_LEFT+2*this.constants_.INSIDE_CORNERS.width+n.utils.svgPaths.lineOnAxis("h",-this.constants_.INSIDE_CORNERS.width)+this.constants_.INSIDE_CORNERS.pathTop,s=e.height-2*this.constants_.INSIDE_CORNERS.height,o=this.constants_.INSIDE_CORNERS.pathBottom+n.utils.svgPaths.lineOnAxis("h",this.constants_.INSIDE_CORNERS.width),r=this.constants_.ellipses;this.outlinePath_+=this.constants_.OUTSIDE_CORNERS.bottomRight+n.utils.svgPaths.lineOnAxis("H",t)+i+n.utils.svgPaths.lineOnAxis("v",s/2)+r+n.utils.svgPaths.lineOnAxis("v",s/2)+o+n.utils.svgPaths.lineOnAxis("H",e.xPos+e.width-this.constants_.OUTSIDE_CORNERS.rightHeight)+this.constants_.OUTSIDE_CORNERS.topRight}drawOutline_(){if(this.info_.outputConnection&&this.info_.outputConnection.isDynamicShape&&!this.info_.hasStatementInput&&!this.info_.bottomRow.hasNextConnection)this.drawFlatTop_(),this.drawRightDynamicConnection_(),this.drawFlatBottom_(),this.drawLeftDynamicConnection_();else{this.drawTop_();for(let e=1;e<this.info_.rows.length-1;e++){const t=this.info_.rows[e];t.hasJaggedEdge?this.drawJaggedEdge_(t):(0,s.isCollapsedInputRow)(t)?this.drawCollapsedStack_(t):t.hasStatement?this.drawStatementInput_(t):t.hasExternalInput?this.drawValueInput_(t):this.drawRightSideRow_(t)}this.drawBottom_(),this.drawLeft_()}}drawLeft_(){super.drawLeft_();if(this.info_.rows.find(function(e){return(0,s.isCollapsedInputRow)(e)})){let e=this.info_.startY;n.blockRendering.Types.isLeftRoundedCorner(this.info_.topRow.elements[0])&&(e+=this.constants_.OUTSIDE_CORNERS.rightHeight),this.outlinePath_=this.outlinePath_.slice(0,-1),this.outlinePath_+=n.utils.svgPaths.lineOnAxis("V",e)}}}i.Drawer=o},{"./collapsedInputRow":139,blockly:256}],144:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./renderer"),i),s(e("./connectionPreviewer"),i),s(e("./css"),i)},{"./connectionPreviewer":140,"./css":142,"./renderer":147}],145:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.RenderInfo=void 0;const n=e("blockly"),s=e("./collapsedInputRow");class o extends n.zelos.RenderInfo{measure(){if(this.block_)for(const e of this.block_.inputList)e.init();super.measure()}createRows_(){this.populateTopRow_(),this.rows.push(this.topRow);let e=new n.blockRendering.InputRow(this.constants_);this.inputRows.push(e);const t=this.block_.getIcons();for(let i,s=0;i=t[s];s++){const t=new n.blockRendering.Icon(this.constants_,i);this.isCollapsed&&!i.isShownWhenCollapsed()||e.elements.push(t)}let i;for(let t,s=0;t=this.block_.inputList[s];s++)if(t.isVisible()){this.shouldStartNewRow_(t,i)&&(this.rows.push(e),e=new n.blockRendering.InputRow(this.constants_),this.inputRows.push(e));for(let i,s=0;i=t.fieldRow[s];s++)e.elements.push(new n.blockRendering.Field(this.constants_,i,t));this.addInput_(t,e),i=t}if(this.isCollapsed){this.block_.inputList.find(function(e){return e.type==n.inputs.inputTypes.STATEMENT})?e=this.addCollapsedRow_(e):(e.hasJaggedEdge=!0,e.elements.push(new n.blockRendering.JaggedEdge(this.constants_)))}(e.elements.length||e.hasDummyInput)&&this.rows.push(e),this.populateBottomRow_(),this.rows.push(this.bottomRow)}populateBottomRow_(){this.bottomRow.hasNextConnection=!!this.block_.nextConnection;const e=this.block_.inputList.length&&this.block_.inputList[this.block_.inputList.length-1]instanceof n.inputs.StatementInput||this.rows.some(e=>(0,s.isCollapsedInputRow)(e));this.bottomRow.minHeight=e?this.constants_.BOTTOM_ROW_AFTER_STATEMENT_MIN_HEIGHT:this.constants_.BOTTOM_ROW_MIN_HEIGHT;this.bottomRow.hasLeftSquareCorner(this.block_)?this.bottomRow.elements.push(new n.blockRendering.SquareCorner(this.constants_)):this.bottomRow.elements.push(new n.blockRendering.RoundCorner(this.constants_)),this.bottomRow.hasNextConnection&&(this.bottomRow.connection=new n.blockRendering.NextConnection(this.constants_,this.block_.nextConnection),this.bottomRow.elements.push(this.bottomRow.connection));this.bottomRow.hasRightSquareCorner(this.block_)?this.bottomRow.elements.push(new n.blockRendering.SquareCorner(this.constants_,"right")):this.bottomRow.elements.push(new n.blockRendering.RoundCorner(this.constants_,"right"))}addCollapsedRow_(e){this.rows.push(e);const t=new s.CollapsedInputRow(this.constants_);return t.hasDummyInput=!0,t}}i.RenderInfo=o},{"./collapsedInputRow":139,blockly:256}],146:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PathObject=void 0;const n=e("blockly"),s="blockly-dotted-outline-on-hover",o="hover";class r extends n.zelos.PathObject{constructor(){super(...arguments),this.connectionPointIndicators=new WeakMap}setPath(e){super.setPath(e),this.svgPathHighlighted&&this.svgPathHighlighted.setAttribute("d",e)}updateHighlighted(e){if(e){if(!this.svgPathHighlighted){const e=this.constants,t=this.hasError?e.errorOutlineFilterId:e.highlightOutlineFilterId;this.svgPathHighlighted=this.svgPath.cloneNode(!0),this.svgPathHighlighted.classList.add("pxtRendererHighlight"),this.svgPathHighlighted.setAttribute("fill","none"),this.svgPathHighlighted.setAttribute("filter","url(#"+t+")"),this.svgRoot.appendChild(this.svgPathHighlighted)}}else this.svgPathHighlighted&&(this.svgRoot.removeChild(this.svgPathHighlighted),this.svgPathHighlighted=null)}updateSelected(e){e&&this.svgPath.classList.remove(o),super.updateSelected(e)}addConnectionHighlight(e,t,i,s){const o=super.addConnectionHighlight(e,t,i,s);return this.staticConnectionIndicatorParentGroup?this.svgRoot.appendChild(this.staticConnectionIndicatorParentGroup):this.staticConnectionIndicatorParentGroup=n.utils.dom.createSvgElement("g",{class:"blocklyConnectionIndicatorParent"},this.svgRoot),o}removeConnectionHighlight(e){var t;null===(t=this.staticConnectionIndicatorParentGroup)||void 0===t||t.remove(),super.removeConnectionHighlight(e)}applyColour(e){if(super.applyColour(e),e.outputConnection){let t=!1;const i=e.getParent();if(i)if(e.isShadow()){const e=i.style.colourTertiary,s=function(e){return(.2126*e[0]+.7152*e[1]+.0722*e[2])/255}(n.utils.colour.hexToRgb(e));s<.15&&(this.svgPath.setAttribute("stroke",n.utils.colour.blend("#ffffff",e,.3)),t=!0)}else{const s=i.style.colourPrimary,o=e.style.colourPrimary;if(s===o){const e=.6,i=n.utils.colour.blend("#0000000",o,e),r=n.utils.colour.blend("#ffffff",o,e);pxt.contrastRatio(i,s)>pxt.contrastRatio(r,s)?this.svgPath.setAttribute("stroke",i):this.svgPath.setAttribute("stroke",r),t=!0}}t||this.svgPath.setAttribute("stroke",e.style.colourTertiary)}}setHasDottedOutlineOnHover(e){this.hasDottedOutlineOnHover=e,e?(this.svgPath.classList.add(s),this.mouseOverData||(this.mouseOverData=n.browserEvents.bind(this.svgRoot,"mouseover",this,()=>{this.svgPath.classList.add(o)}),this.mouseLeaveData=n.browserEvents.bind(this.svgRoot,"mouseleave",this,()=>{this.svgPath.classList.remove(o)}))):(this.svgPath.classList.remove(s),this.mouseOverData&&(n.browserEvents.unbind(this.mouseOverData),n.browserEvents.unbind(this.mouseLeaveData),this.mouseOverData=void 0,this.mouseLeaveData=void 0),this.svgPath.classList.remove(s))}setHasError(e){this.hasError=e}isHighlighted(){return!!this.svgPathHighlighted}}i.PathObject=r,r.CONNECTION_INDICATOR_RADIUS=9,n.Css.register("\n.blockly-dotted-outline-on-hover {\n transition: stroke .4s;\n}\n.blockly-dotted-outline-on-hover.hover {\n stroke-dasharray: 2;\n stroke: white;\n stroke-width: 2;\n}\n.blocklyDisabledPattern>.blocklyPath.pxtRendererHighlight {\n fill: none;\n}\n")},{blockly:256}],147:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Renderer=void 0;const n=e("blockly"),s=e("./pathObject"),o=e("./constants"),r=e("./info"),a=e("./drawer");class l extends n.zelos.Renderer{makePathObject(e,t){return new s.PathObject(e,t,this.getConstants())}makeConstants_(){return new o.ConstantProvider}makeRenderInfo_(e){return new r.RenderInfo(this,e)}makeDrawer_(e,t){return new a.Drawer(e,t)}render(e){e.updateBeforeRender&&e.updateBeforeRender(),super.render(e)}}i.Renderer=l,n.blockRendering.register("pxt",l)},{"./constants":141,"./drawer":143,"./info":145,"./pathObject":146,blockly:256}],148:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FieldString=void 0;const n=e("blockly");class s extends n.FieldTextInput{initView(){this.quoteSize_=16,this.quoteWidth_=8,this.quoteLeftX_=0,this.quoteRightX_=0,this.quoteY_=10,this.quoteLeft_&&this.quoteLeft_.parentNode.removeChild(this.quoteLeft_),this.quoteLeft_=n.utils.dom.createSvgElement("text",{"font-size":this.quoteSize_+"px",class:"field-text-quote","aria-hidden":"true"},this.fieldGroup_),super.initView(),this.quoteRight_&&this.quoteRight_.parentNode.removeChild(this.quoteRight_),this.quoteRight_=n.utils.dom.createSvgElement("text",{"font-size":this.quoteSize_+"px",class:"field-text-quote","aria-hidden":"true"},this.fieldGroup_),this.quoteLeft_.appendChild(document.createTextNode('"')),this.quoteRight_.appendChild(document.createTextNode('"'))}updateSize_(e){super.updateSize_(e);const t=this.value_?this.size_.width:1;let i=this.positionLeft(t+3);this.textElement_.setAttribute("x",i+""),i+=this.positionRight(i+t+3),this.size_.width=t+i}positionLeft(e){if(!this.quoteLeft_)return 0;let t=0;return this.sourceBlock_.RTL?(this.quoteLeftX_=e+this.quoteWidth_+2*s.quotePadding,t=this.quoteWidth_+s.quotePadding):(this.quoteLeftX_=0,t=this.quoteWidth_+s.quotePadding),this.quoteLeft_.setAttribute("transform","translate("+this.quoteLeftX_+","+this.quoteY_+")"),t}positionRight(e){if(!this.quoteRight_)return 0;let t=0;return this.sourceBlock_.RTL?(this.quoteRightX_=s.quotePadding,t=this.quoteWidth_+s.quotePadding):(this.quoteRightX_=e+s.quotePadding,t=this.quoteWidth_+s.quotePadding),this.quoteRight_.setAttribute("transform","translate("+this.quoteRightX_+","+this.quoteY_+")"),t}}i.FieldString=s,s.quotePadding=0,n.Css.register("\n.field-text-quote {\n fill: #a31515 !important;\n}\n"),n.fieldRegistry.register("field_string",s)},{blockly:256}],149:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./fieldString"),i),s(e("./text"),i),s(e("./join"),i)},{"./fieldString":148,"./join":150,"./text":151}],150:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly"),s=e("../../fields/field_imagenotext"),o=e("../../utils"),r={itemCount_:0,valueConnections_:[],buttons:null,delta:0,mutationToDom:function(){const e=n.utils.xml.createElement("mutation");return e.setAttribute("items",this.itemCount_+""),e},domToMutation:function(e){this.itemCount_=parseInt(e.getAttribute("items"),10),this.updateShape_()},storeValueConnections_:function(){this.valueConnections_=[];for(let e=0;e<this.itemCount_;e++)this.valueConnections_.push(this.getInput("ADD"+e).connection.targetConnection)},restoreValueConnections_:function(){var e;for(let t=0;t<this.itemCount_;t++)null===(e=this.valueConnections_[t])||void 0===e||e.reconnect(this,"ADD"+t)},addItem_:function(){this.storeValueConnections_();if(this.delta=1,this.update_(()=>{this.itemCount_++}),this.restoreValueConnections_(),this.itemCount_>1){const e=this.getInput("ADD0");if(e&&e.connection.targetConnection){const t=this.getInput("ADD"+(this.itemCount_-1)),i=e.connection.getShadowDom();if(i){const e=n.utils.xml.createElement("shadow"),s=i.getAttribute("type");e.setAttribute("type",s),e&&(e.setAttribute("id",n.utils.idGenerator.genUid()),t.connection.setShadowDom(e))}}}},removeItem_:function(){this.storeValueConnections_();this.delta=-1,this.update_(()=>{this.itemCount_--}),this.restoreValueConnections_()},update_:function(e){n.Events.setGroup(!0);const t=this,i=t.mutationToDom(),s=i&&n.Xml.domToText(i);e&&e.call(this),this.updateShape_(),t instanceof n.BlockSvg&&t.initSvg();const r=n.Events.getGroup(),a=t.mutationToDom(),l=a&&n.Xml.domToText(a);s!=l&&(n.Events.fire(new n.Events.BlockChange(t,"mutation",null,s,l)),setTimeout(function(){n.Events.setGroup(r),t.bumpNeighbours(),n.Events.setGroup(!1)},n.config.bumpDelay)),t.rendered&&t instanceof n.BlockSvg&&t.queueRender().then(()=>{if(this.buttons){let e=this.buttons.fieldRow[0];this.buttons.fieldRow.length>1&&(e=this.delta<0?e:this.buttons.fieldRow[1]),(0,o.maybeMoveFocusFromButton)(e),this.buttons=null,this.delta=0}}),n.Events.setGroup(!1)},updateShape_:function(){const e=this,t=function(){e.removeItem_()};let i;for(this.getInput("EMPTY")&&this.removeInput("EMPTY"),this.getInput("TITLE")||this.appendDummyInput("TITLE").appendField(n.Msg.TEXT_JOIN_TITLE_CREATEWITH),i=0;i<this.itemCount_;i++)if(!this.getInput("ADD"+i)){this.appendValueInput("ADD"+i).setAlign(n.inputs.Align.LEFT).setAriaLabelProvider(n.Msg.INPUT_LABEL_TEXT_JOIN_ITEM.replace("%1",(i+1).toString()))}for(;this.getInput("ADD"+i);)this.removeInput("ADD"+i),i++;this.getInput("BUTTONS")&&this.removeInput("BUTTONS"),this.buttons=this.appendDummyInput("BUTTONS"),this.itemCount_>1&&this.buttons.appendField(new s.FieldImageNoText(this.REMOVE_IMAGE_DATAURI,24,24,lf("remove argument"),t,!1)),this.buttons.appendField(new s.FieldImageNoText(this.ADD_IMAGE_DATAURI,24,24,lf("add argument"),function(){e.addItem_()},!1));const o=this.itemCount_<=4;if(this.setInputsInline(o),this.workspace instanceof n.WorkspaceSvg){const e=this.workspace.getRenderer();this.setOutputShape(o?e.getConstants().SHAPES.ROUND:e.getConstants().SHAPES.SQUARE)}}};n.Extensions.registerMutator("pxt_text_join_mutator",r,function(){n.Extensions.apply("inline-svgs",this,!1),this.itemCount_=2,this.updateShape_()}),n.defineBlocksWithJsonArray([{type:"text_join",message0:"",output:"String",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,style:"text_blocks",helpUrl:"%{BKY_TEXT_JOIN_HELPURL}",tooltip:"%{BKY_TEXT_JOIN_TOOLTIP}",mutator:"pxt_text_join_mutator"}])},{"../../fields/field_imagenotext":38,"../../utils":155,blockly:256}],151:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});const n=e("blockly");n.defineBlocksWithJsonArray([{type:"text",message0:"%1",args0:[{type:"field_string",name:"TEXT",text:""}],output:"String",outputShape:(new n.zelos.ConstantProvider).SHAPES.ROUND,style:"field_blocks",helpUrl:"%{BKY_TEXT_TEXT_HELPURL}",tooltip:"%{BKY_TEXT_TEXT_TOOLTIP}",extensions:["parent_tooltip_when_inline"]}])},{blockly:256}],152:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.blocksMetrics=i.render=i.renderWorkspace=i.cleanRenderingWorkspace=i.initRenderingWorkspace=void 0;const n=e("blockly"),s=e("./layout"),o=e("./importer");let r,a;function l(){return r||(a=document.createElement("div"),a.style.position="absolute",a.style.top="0",a.style.left="0",a.style.width="1px",a.style.height="1px",document.body.appendChild(a),r=n.inject(a,{move:{scrollbars:!1},readOnly:!0,sounds:!1,media:pxt.webConfig.commitCdnUrl+"blockly/media/",rtl:pxt.Util.isUserLanguageRtl(),renderer:"pxt"})),(0,o.clearWithoutEvents)(r),r}function c(){r&&r.dispose(),r=void 0}function u(e={emPixels:18,layout:1}){switch(e.splitSvg?1:e.layout||4){case 1:(0,s.verticalAlign)(r,e.emPixels||18);break;case 4:(0,s.flow)(r,{ratio:e.aspectRatio,useViewWidth:e.useViewWidth});break;case 3:r.cleanUp_&&r.cleanUp_()}let t=r.getMetrics();const i=a.querySelectorAll("svg")[0],n=i.cloneNode(!0);return(0,s.cleanUpBlocklySvg)(n,i),pxt.U.toArray(n.querySelectorAll(".blocklyBlockCanvas,.blocklyBubbleCanvas")).forEach(e=>e.setAttribute("transform",`translate(${-t.contentLeft}, ${-t.contentTop}) scale(1)`)),n.setAttribute("viewBox",`0 0 ${t.contentWidth} ${t.contentHeight}`),e.emPixels&&(n.style.width=t.contentWidth/e.emPixels+"em",n.style.height=t.contentHeight/e.emPixels+"em"),e.splitSvg?(0,s.splitSvg)(n,r,e.emPixels):n}i.initRenderingWorkspace=l,i.cleanRenderingWorkspace=c,i.renderWorkspace=u,i.render=function(e,t={emPixels:18,layout:1}){l();try{let i=e||'<xml xmlns="http://www.w3.org/1999/xhtml"></xml>',s=n.utils.xml.textToDom(i);return(0,o.domToWorkspaceNoEvents)(s,r,{applyHideMetaComment:!0}),u(t)}catch(e){return void pxt.reportException(e)}finally{c()}},i.blocksMetrics=function(e){const t=e.getTopBlocks(!1);if(!t.length)return{width:0,height:0};let i;return t.forEach(e=>{const t=e.getBoundingRectangle();i?(i.l=Math.min(i.l,t.left),i.r=Math.max(i.r,t.right),i.t=Math.min(i.t,t.top),i.b=Math.min(i.b,t.bottom)):i={l:t.left,r:t.right,t:t.top,b:t.bottom}}),{width:i.r-i.l,height:i.b-i.t}}},{"./importer":75,"./layout":77,blockly:256}],153:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.findBlockIdByLine=i.findBlockIdByPosition=void 0,i.findBlockIdByPosition=function(e,t){if(!t)return;let i,n;for(let s=0;s<e.length;++s){let o=e[s];o.startPos<=t.start&&o.endPos>=t.start+t.length&&(!i||n>o.endPos-o.startPos)&&(i=o,n=o.endPos-o.startPos)}return i?i.id:void 0},i.findBlockIdByLine=function(e,t){if(!t)return;let i,n;for(let s=0;s<e.length;++s){let o=e[s];o.startLine<=t.start&&o.endLine>t.start+t.length&&(!i||n>o.endLine-o.startLine)&&(i=o,n=o.endLine-o.startLine)}return i?i.id:void 0}},{}],154:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createFunctionsFlyoutCategory=i.mkReturnStatementBlock=i.mkVariableFieldBlock=i.mkFieldBlock=i.mkPredicateBlock=i.createToolboxBlock=i.createFlyoutGap=i.createFlyoutButton=i.createFlyoutGroupLabel=i.createFlyoutHeadingLabel=i.createShadowValue=i.isArrayType=void 0;const n=e("blockly"),s=e("./plugins/functions"),o=e("./loader"),r=/^(string|number|boolean)$/,a={string:{field:"TEXT",block:"text",defaultValue:""},number:{field:"NUM",block:"math_number",defaultValue:"0"},boolean:{field:"BOOL",block:"logic_boolean",defaultValue:"false"},Array:{field:"VAR",block:"variables_get",defaultValue:"list"}};function l(e){let t=/^(?:Array<(.+)>)|(?:(.+)\[\])|(?:\[.+\])$/.exec(e);return t?t[1]?t[1]:t[2]:void 0}function c(e,t,i,n,s,o=0){let r;if(n=n||t.defaultValue,!(i=i||t.shadowBlockId)&&t.range&&(i="math_number_minmax"),r=n&&'"'==n.slice(0,1)?JSON.parse(n):n,"number"==t.type&&"value"==i){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode("0")),e}if(t.fieldEditor){if(t.defaultValue){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode(t.defaultValue)),e}return}let c=pxt.Util.lookup(e.apis.byQName,t.type),h=6==(null==c?void 0:c.kind),d=c&&!!c.attributes.fixedInstances&&!t.shadowBlockId,p="@combined@"==t.type;if(!i&&(h||d||p)){if(n){const e=document.createElement("field");return e.setAttribute("name",t.definitionName),e.appendChild(document.createTextNode(n)),e}return}const f="variables_get"==i,m="text"==i,_=document.createElement("value");_.setAttribute("name",t.definitionName);const b="lists_create_with"!==i&&i?void 0:l(t.type),T=document.createElement(!f&&!b||s?"shadow":"block");_.appendChild(T);const E=a[b||t.type];if(T.setAttribute("type",i||(b?"lists_create_with":E&&E.block||t.type)),T.setAttribute("colour","#fff"),b){if(E&&!i){let e;switch(b){case"number":e=["0","1"];break;case"string":e=["a","b","c"];break;case"boolean":e=["FALSE","FALSE","FALSE"]}return u(T,E.block,E.field,e),_}if(i&&r)return u(T,r),_}if(!E||i&&E.block!==i&&"math_number_minmax"!==i){if(r){const n=document.createElement("field");if(n.textContent=r,f)n.setAttribute("name","VAR"),T.appendChild(n);else if(m)n.setAttribute("name","TEXT"),T.appendChild(n);else if(i){const t=e.blocksById[i];if(t&&t.attributes._def&&t.attributes._def.parameters.length){const e=t.attributes._def.parameters[0];n.setAttribute("name",e.name),T.appendChild(n)}}else n.setAttribute("name",t.definitionName),T.appendChild(n)}}else{const e=document.createElement("field");let n,s;switch(T.appendChild(e),i){case"variables_get":n="VAR";break;case"math_number_minmax":n="SLIDER";break;default:n=E.field}e.setAttribute("name",n),s="boolean"==t.type?document.createTextNode((r||E.defaultValue).toUpperCase()):document.createTextNode(r||E.defaultValue),e.appendChild(s)}let v;if(t.range&&(v=document.createElement("mutation"),v.setAttribute("min",t.range.min.toString()),v.setAttribute("max",t.range.max.toString()),v.setAttribute("label",t.actualName.charAt(0).toUpperCase()+t.actualName.slice(1)),t.fieldOptions&&(t.fieldOptions.step&&v.setAttribute("step",t.fieldOptions.step),t.fieldOptions.color&&v.setAttribute("color",t.fieldOptions.color),t.fieldOptions.precision&&v.setAttribute("precision",t.fieldOptions.precision))),t.fieldOptions&&(v||(v=document.createElement("mutation")),v.setAttribute("customfield",JSON.stringify(t.fieldOptions))),v&&T.appendChild(v),o){const t=pxt.Util.toArray(_.getElementsByTagName("shadow"));for(const i of t)if(!i.innerHTML){const t=e.blocks.find(e=>e.attributes.blockId===i.getAttribute("type"));if(t){const n=g(e,t,pxt.blocks.compileInfo(t),!0,o-1);for(;n.firstChild;)i.appendChild(n.firstChild.cloneNode(!0)),n.firstChild.remove();t.attributes.builtinBlockId&&i.setAttribute("type",t.attributes.builtinBlockId)}}}return _}function u(e,t,i,n){const s=n?n.length:2,o=document.createElement("mutation");o.setAttribute("items",""+s),o.setAttribute("horizontalafter",""+s),e.appendChild(o);for(let o=0;o<s;o++){const s=document.createElement("value");s.setAttribute("name","ADD"+o);const r=document.createElement("shadow");if(r.setAttribute("type",t),i){const e=document.createElement("field");e.setAttribute("name",i),n&&e.appendChild(document.createTextNode(n[o])),r.appendChild(e)}s.appendChild(r),e.appendChild(s)}}function h(e,t,i,n){const s=p(e,pxt.toolbox.convertColor(t),i,n);return s.setAttribute("web-class","blocklyFlyoutHeading"),s}function d(e,t,i,n){const s=p(e,void 0,t);return s.setAttribute("web-class","blocklyFlyoutGroup"),s.setAttribute("web-line","1.5"),i&&s.setAttribute("web-line-width",i),n&&(s.setAttribute("web-help-button","true"),s.setAttribute("callbackKey",n)),s}function p(e,t,i,s){let o=n.utils.xml.createElement("label");return o.setAttribute("text",e),t&&o.setAttribute("web-icon-color",pxt.toolbox.convertColor(t)),i&&(1===i.length?(o.setAttribute("web-icon",i),s&&o.setAttribute("web-icon-class",s)):(o.setAttribute("web-icon-class",`blocklyFlyoutIcon${e}`),pxt.toolbox.isImageIcon(i)&&o.setAttribute("web-icon-image",pxt.Util.pathJoin(pxt.webConfig.commitCdnUrl,encodeURI(i))))),o}function g(e,t,i,n=!1,a=0){var u,h;let d,p;if(t.attributes.builtinBlockId)return function(e){const t=e.attributes.builtinBlockId,i=e.attributes.color;if("makecode_color_picker"===t){const e=document.createElement("block");e.setAttribute("type","makecode_color_picker");const t=document.createElement("field");t.setAttribute("name","FORMAT"),t.textContent="rgb",e.appendChild(t);for(let t=0;t<3;t++){const i=document.createElement("value");i.setAttribute("name",`INPUT${t}`);const n=document.createElement("shadow");n.setAttribute("type","makecode_color_picker_number");const s=document.createElement("field");s.setAttribute("name","NUM"),s.textContent="0",n.appendChild(s),i.appendChild(n),e.appendChild(i)}if(i){const t=document.createElement("mutation");t.setAttribute("color",i),e.appendChild(t)}return e}return void pxt.warn(`Unsupported builtin block id: ${t}`)}(t);if(t.attributes.toolboxParent){const i=e.blocksById[t.attributes.toolboxParent];if(i){const s=pxt.blocks.compileInfo(i);if(d=g(e,i,s,n),t.attributes.toolboxParentArgument)p=d.querySelector(`value[name=${t.attributes.toolboxParentArgument}]`),!p&&s.parameters.some(e=>e.definitionName===t.attributes.toolboxParentArgument)&&(p=document.createElement("value"),p.setAttribute("name",t.attributes.toolboxParentArgument),d.appendChild(p));else if(p=d.querySelector("value"),!p)for(const e of s.parameters)if(!d.querySelector(`field[name=${e.definitionName}]`)){p=document.createElement("value"),p.setAttribute("name",e.definitionName),d.appendChild(p);break}if(p)for(;p.firstChild;)p.removeChild(p.firstChild);else d=void 0}}let f=document.createElement(d||n?"shadow":"block");if(f.setAttribute("type",t.attributes.blockId),t.attributes.blockGap?f.setAttribute("gap",t.attributes.blockGap):pxt.appTarget.appTheme&&pxt.appTarget.appTheme.defaultBlockGap&&f.setAttribute("gap",pxt.appTarget.appTheme.defaultBlockGap.toString()),i.thisParameter){const t=i.thisParameter,s=!!(null===(u=e.apis.byQName[t.type])||void 0===u?void 0:u.attributes.fixedInstances);let o=t.shadowBlockId,r=t.defaultValue;s||o&&"variables_get"!==o||(o="variables_get",r=r||t.definitionName);const l=c(e,t,o,r,n,a);l&&f.appendChild(l)}if("ENUM_GET"===t.attributes.shim||"KIND_GET"===t.attributes.shim){if(null===(h=t.parameters)||void 0===h?void 0:h.length){const e=t.parameters[0].default;if(e){const t=document.createElement("field");t.setAttribute("name","MEMBER"),t.textContent=e,f.appendChild(t)}}}else t.parameters&&(i.parameters.filter(e=>r.test(e.type)||r.test(l(e.type))||e.shadowBlockId||e.defaultValue).forEach(t=>{const i=c(e,t,void 0,void 0,n,a);i&&f.appendChild(i)}),t.attributes.draggableParameters?i.handlerArgs.forEach(e=>{const i="reporter"===t.attributes.draggableParameters,n=document.createElement("value");n.setAttribute("name",o.DRAGGABLE_PARAM_INPUT_PREFIX+e.name);const r=i?pxt.blocks.reporterTypeForArgType(e.type):"variables_get_reporter",a=document.createElement("block");a.setAttribute("type",r);const l=document.createElement("mutation");a.appendChild(l),i&&"argument_reporter_custom"===r&&l.setAttribute("typename",e.type),l.setAttribute(s.LOCALIZATION_NAME_MUTATION_KEY,e.localizationKey);const c=document.createElement("field");c.setAttribute("name",i?"VALUE":"VAR"),c.textContent=pxt.Util.htmlEscape(e.name),a.appendChild(c),n.appendChild(a),f.appendChild(n)}):i.handlerArgs.forEach(e=>{const t=document.createElement("field");t.setAttribute("name","HANDLER_"+e.name),t.textContent=e.name,f.appendChild(t)}));if(t.attributes.expandArgumentsInToolbox){let e;for(const t of f.children)if("mutation"===t.tagName){e=t;break}e||(e=document.createElement("mutation"),f.appendChild(e)),e.setAttribute("_expanded",""+t.attributes._expandedDef.parameters.length)}return d?(p.appendChild(f),d):f}function f(e,t,i,n){const s=document.createElement(n?"shadow":"block");s.setAttribute("type",pxt.Util.htmlEscape(e));const o=document.createElement("field");return o.setAttribute("name",pxt.Util.htmlEscape(t)),o.textContent=pxt.Util.htmlEscape(i),s.appendChild(o),s}function m(){const e=document.createElement("block");e.setAttribute("type","function_return");const t=document.createElement("value");t.setAttribute("name","RETURN_VALUE"),e.appendChild(t);const i=f("math_number","NUM","0",!0);return t.appendChild(i),e}i.isArrayType=l,i.createShadowValue=c,i.createFlyoutHeadingLabel=h,i.createFlyoutGroupLabel=d,i.createFlyoutButton=function(e,t){let i=n.utils.xml.createElement("button");return i.setAttribute("text",t),i.setAttribute("callbackKey",e),i},i.createFlyoutGap=function(e){const t=n.utils.xml.createElement("sep");return t.setAttribute("gap",e+""),t},i.createToolboxBlock=g,i.mkPredicateBlock=function(e){const t=document.createElement("block");t.setAttribute("type",e);const i=document.createElement("value");i.setAttribute("name","PREDICATE"),t.appendChild(i);const n=f("logic_boolean","BOOL","TRUE",!0);return i.appendChild(n),t},i.mkFieldBlock=f,i.mkVariableFieldBlock=function(e,t,i,n,s){const o=document.createElement(s?"shadow":"block");o.setAttribute("type",pxt.Util.htmlEscape(e));const r=document.createElement("field");return r.setAttribute("name","VAR"),r.id=t,r.setAttribute("variabletype",pxt.Util.htmlEscape(i)),r.textContent=pxt.Util.htmlEscape(n),o.appendChild(r),o},i.mkReturnStatementBlock=m,i.createFunctionsFlyoutCategory=function(e){const t=(0,s.flyoutCategory)(e);if(t.length>1){let e=m();t.splice(1,0,d(lf("Your Functions"))),t.splice(1,0,e)}const i=(0,s.getAllFunctionDefinitionBlocks)(e).filter(e=>e.getDescendants(!1).some(e=>"function_return"===e.type&&e.getInputTargetBlock("RETURN_VALUE"))).map(e=>e.getField("function_name").getText()),n=h(lf("Functions"),pxt.toolbox.getNamespaceColor("functions"),pxt.toolbox.getNamespaceIcon("functions"),"blocklyFlyoutIconfunctions");t.unshift(n);const o=[];for(const e of t)if(o.push(e),"function_call"===e.getAttribute("type")){const t=e.children.item(0);if(t){const n=t.getAttribute("name");if(i.some(e=>e===n)){const t=e.cloneNode(!0);t.setAttribute("type","function_call_output"),o.push(t)}}}return o}},{"./loader":79,"./plugins/functions":127,blockly:256}],155:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.maybeMoveFocusFromButton=void 0;const n=e("blockly"),s=e("./fields/field_imagenotext");i.maybeMoveFocusFromButton=e=>{const t=n.getFocusManager(),i=t.getFocusedNode();e&&(i instanceof s.FieldImageNoText||!i)&&t.focusNode(e)}},{"./fields/field_imagenotext":38,blockly:256}],156:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PxtWorkspaceSearch=void 0;const n=e("blockly"),s=e("@blockly/plugin-workspace-search");class o extends s.WorkspaceSearch{constructor(e){super(e),this.injectionDiv=e.getInjectionDiv()}highlightSearchGroup(e){e.forEach(e=>{const t=e.pathObject.svgPath;n.utils.dom.addClass(t,"blockly-ws-search-highlight-pxt")})}unhighlightSearchGroup(e){e.forEach(e=>{const t=e.pathObject.svgPath;n.utils.dom.removeClass(t,"blockly-ws-search-highlight-pxt")})}open(){super.open(),n.utils.dom.addClass(this.injectionDiv,"blockly-ws-searching")}close(){super.close(),n.utils.dom.removeClass(this.injectionDiv,"blockly-ws-searching")}}i.PxtWorkspaceSearch=o,n.Css.register("\n.blockly-ws-search {\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n border: solid var(--pxt-neutral-alpha50) 1px;\n border-top: none;\n border-right: none;\n box-shadow: 0px 2px 15px var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input {\n -webkit-tap-highlight-color: transparent;\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n border: none;\n}\n\n.blockly-ws-search input::-webkit-input-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input::-moz-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input::-ms-input-placeholder {\n color: var(--pxt-neutral-alpha50);\n}\n\n.blockly-ws-search input:active,\n.blockly-ws-search input:focus {\n border-color: var(--pxt-neutral-alpha50);\n background: var(--pxt-neutral-background1);\n color: var(--pxt-neutral-foreground1);\n}\n\n.blockly-ws-search input::selection {\n color: var(--pxt-neutral-foreground1);\n}\n\n.blockly-ws-search button {\n padding-left: 6px;\n padding-right: 6px;\n color: var(--pxt-neutral-foreground1);\n}")},{"@blockly/plugin-workspace-search":251,blockly:256}],157:[function(e,t,i){"use strict";function n(e,t,i,n){return pxt.Util.toArray(e.getElementsByTagName(t)).filter(e=>e.getAttribute(i)===n)}Object.defineProperty(i,"__esModule",{value:!0}),i.cleanOuterHTML=i.getDirectChildren=i.getFirstChildWithAttr=i.getChildrenWithAttr=i.getBlocksWithType=void 0,i.getBlocksWithType=function(e,t){return n(e,"block","type",t).concat(n(e,"shadow","type",t))},i.getChildrenWithAttr=n,i.getFirstChildWithAttr=function(e,t,i,s){const o=n(e,t,i,s);return o.length?o[0]:void 0},i.getDirectChildren=function(e,t){const i=[];for(let n=0;n<e.childNodes.length;n++){const s=e.childNodes.item(n);s.tagName===t&&i.push(s)}return i},i.cleanOuterHTML=function(e){return e.outerHTML.replace(/^<\?[^>]*>/,"")}},{}],158:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.IFrameEmbeddedClient=void 0;i.IFrameEmbeddedClient=class{constructor(e){this.messageHandler=e,this.onMessageReceived=e=>{const t=e.data;if(t){if("iframeclientsetmessageport"===t.type)return this.port=e.ports[0],this.port.onmessage=this.onMessageReceived,void this.postMessage({type:"iframeclientsetmessageport"});if("iframeclientready"===t.type)return void this.sendReadyMessage()}this.messageHandler(e)},this.frameId=function(){const e=/frameid=([a-zA-Z0-9\-]+)/i.exec(window.location.href);if(e)return e[1];return}(),window.addEventListener("message",this.onMessageReceived),this.sendReadyMessage()}dispose(){window.removeEventListener("message",this.onMessageReceived),this.port&&this.port.close()}postMessage(e){this.postMessageCore(e)}postMessageCore(e){this.frameId&&(e.frameId=this.frameId),this.port?this.port.postMessage(e):window.acquireVsCodeApi?window.acquireVsCodeApi().postMessage(e):window.parent&&window.parent!==window&&window.parent.postMessage(e,"*")}sendReadyMessage(){this.postMessage({type:"iframeclientready"})}}},{}],159:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.inflateButtonViewProps=i.inflateButtonProps=i.ButtonBody=i.Button=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.Button=e=>{const t=o(e);return(0,n.jsx)("button",Object.assign({},t,{children:(0,n.jsx)(i.ButtonBody,Object.assign({},e))}))};function o(e){const{onClick:t,onClickEvent:i,onRightClick:n,onKeydown:o,onBlur:a,onFocus:l,onMouseDown:c,buttonRef:u,target:h,href:d,hardDisabled:p}=e;let{disabled:g}=e;g=g||p;return Object.assign(Object.assign({},r(e)),{ref:u,onClick:g?void 0:e=>{i&&i(e),t&&t(),d&&window.open(d,h||"_blank","noopener,noreferrer"),e.stopPropagation(),e.preventDefault()},onContextMenu:e=>{n&&(n(),e.stopPropagation(),e.preventDefault())},onKeyDown:o||s.fireClickOnEnter,onBlur:a,onFocus:l,onMouseDown:c})}function r(e){const{id:t,className:i,style:n,ariaLabel:o,ariaHidden:r,ariaDescribedBy:a,ariaControls:l,ariaExpanded:c,ariaHasPopup:u,ariaPosInSet:h,ariaSetSize:d,ariaSelected:p,ariaPressed:g,role:f,title:m,hardDisabled:_,tabIndex:b,autoFocus:T}=e;let{disabled:E}=e;E=E||_;return{id:t,className:(0,s.classList)("common-button",i,E&&"disabled"),style:n,title:m,role:f||"button",tabIndex:b||(E?-1:0),autoFocus:T,disabled:_,"aria-label":o,"aria-hidden":r,"aria-controls":l,"aria-expanded":c,"aria-haspopup":u,"aria-posinset":h,"aria-setsize":d,"aria-describedby":a,"aria-selected":p,"aria-pressed":g}}i.ButtonBody=e=>{const{label:t,labelClassName:i,leftIcon:o,rightIcon:r,children:a}=e;return(0,n.jsxs)(n.Fragment,{children:[(o||r||t)&&(0,n.jsxs)("span",Object.assign({className:"common-button-flex"},{children:[o&&(0,n.jsx)("i",{className:o,"aria-hidden":!0}),(0,n.jsx)("span",Object.assign({className:(0,s.classList)("common-button-label",i)},{children:t})),r&&(0,n.jsx)("i",{className:"right "+r,"aria-hidden":!0})]})),a]})},i.inflateButtonProps=o,i.inflateButtonViewProps=r},{"../util":171,"react/jsx-runtime":305}],160:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CarouselNav=void 0;const n=e("react/jsx-runtime"),s=e("../util"),o=e("./Button");i.CarouselNav=e=>{const{pages:t,selected:i,maxDisplayed:r,onPageSelected:a}=e,l=[];let c=0,u=t;r&&(c=Math.min(Math.max(0,i-(r>>1)),Math.max(0,c+t-r)),u=Math.min(c+r,t));for(let e=c;e<u;e++)l.push(e);return(0,n.jsxs)("div",Object.assign({className:"common-carousel-nav"},{children:[(0,n.jsx)(o.Button,{className:"common-carousel-nav-arrow",title:lf("Previous page"),leftIcon:"fas fa-chevron-circle-left",onClick:()=>a(i-1),disabled:0===i}),(0,n.jsx)("ul",Object.assign({className:"common-carousel-nav"},{children:l.map(e=>(0,n.jsx)("li",Object.assign({onClick:()=>a(e)},{children:(0,n.jsx)(o.Button,{className:(0,s.classList)(i===e&&"selected"),title:lf("Jump to page {0}",e+1),onClick:()=>a(e),label:(0,n.jsx)("span",{className:"common-carousel-nav-button-handle"})})}),e))})),(0,n.jsx)(o.Button,{className:"common-carousel-nav-arrow",title:lf("Next page"),leftIcon:"fas fa-chevron-circle-right",onClick:()=>a(i+1),disabled:i===t-1})]}))}},{"../util":171,"./Button":159,"react/jsx-runtime":305}],161:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CheckboxIcon=i.Checkbox=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.Checkbox=e=>{const{id:t,className:i,ariaHidden:o,ariaLabel:r,role:a,isChecked:l,onChange:c,label:u,style:h,tabIndex:d}=e;return(0,n.jsxs)("div",Object.assign({className:(0,s.classList)("common-checkbox",i,"toggle"===h&&"toggle")},{children:[(0,n.jsx)("input",{id:t,tabIndex:null!=d?d:0,type:"checkbox",checked:l,onChange:()=>{c(!l)},onKeyDown:s.fireClickOnEnter,role:a,"aria-hidden":o,"aria-label":r}),u&&(0,n.jsx)("label",Object.assign({htmlFor:t},{children:u}))]}))};i.CheckboxIcon=e=>{const{isChecked:t}=e;return(0,n.jsx)("span",Object.assign({className:(0,s.classList)("common-checkbox-icon",t&&"checked")},{children:t&&(0,n.jsx)("i",{className:"fas fa-check"})}))}},{"../util":171,"react/jsx-runtime":305}],162:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Dropdown=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util"),r=e("./Button"),a=e("./FocusList");i.Dropdown=e=>{var t;const{id:i,className:l,ariaHidden:c,ariaLabel:u,getAriaLabel:h,role:d,items:p,tabIndex:g,selectedId:f,onItemSelected:m}=e,[_,b]=s.useState(!1),T=s.useRef(),E=s.useRef(),v=s.useRef({});s.useEffect(()=>{_&&Object.keys(v.current).length&&v.current[null!=f?f:0].focus()},[_]);const y=(0,o.classList)("common-dropdown",l),k=p.find(e=>e.id===f)||p[0];return(0,n.jsxs)("div",Object.assign({className:y,ref:T,onBlur:e=>{T.current&&_&&!T.current.contains(e.relatedTarget)&&b(!1)}},{children:[(0,n.jsx)(r.Button,Object.assign({},k,{id:i,buttonRef:e=>E.current=e,tabIndex:g,rightIcon:_?"fas fa-chevron-up":"fas fa-chevron-down",role:d,className:(0,o.classList)("common-dropdown-button",_&&"expanded",k.className),onClick:()=>{b(!_)},onKeydown:e=>{const t=p.indexOf(k);"ArrowDown"===e.key?(_?t<p.length-1&&m(p[t+1].id):b(!0),e.preventDefault(),e.stopPropagation()):"ArrowUp"===e.key?t>0&&(m(p[t-1].id),e.preventDefault(),e.stopPropagation()):"Enter"===e.key&&(b(!0),e.preventDefault(),e.stopPropagation())},ariaHasPopup:"listbox",ariaExpanded:_,ariaLabel:null!==(t=null!=u?u:null==h?void 0:h(k.title))&&void 0!==t?t:k.title,ariaHidden:c})),_&&(0,n.jsx)(a.FocusList,Object.assign({role:"listbox",className:"common-menu-dropdown-pane common-dropdown-shadow",childTabStopId:f,"aria-labelledby":i,useUpAndDownArrowKeys:!0,onClose:()=>{b(!1),E.current.focus()},onItemReceivedFocus:e=>{e.id&&p.some(t=>t.id===e.id)&&m(e.id)}},{children:(0,n.jsx)("ul",Object.assign({role:"presentation"},{children:p.map(e=>(0,n.jsx)("li",Object.assign({role:"presentation"},{children:(0,n.jsx)(r.Button,Object.assign({},e,{buttonRef:t=>v.current[e.id]=t,className:(0,o.classList)("common-dropdown-item",e.className),onClick:()=>{var t;b(!1),m(e.id),null===(t=E.current)||void 0===t||t.focus()},ariaSelected:e.id===f,role:"option"}))}),e.id))}))}))]}))}},{"../util":171,"./Button":159,"./FocusList":164,react:304,"react/jsx-runtime":305}],163:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.EditorToggle=void 0;const n=e("react/jsx-runtime"),s=e("../util"),o=e("./Button"),r=e("./FocusList"),a=e("./MenuDropdown"),l=e("react");i.EditorToggle=e=>{const{id:t,className:i,ariaHidden:o,ariaLabel:r,role:d,items:p,selected:g}=e,[f,m]=(0,l.useState)(!1),_=p.some(e=>h(e)),b=e=>{},T=(0,s.classList)("common-editor-toggle",_&&"has-dropdown",f&&"focused",i);return(0,n.jsxs)("div",Object.assign({className:"common-editor-toggle-outer"},{children:[(0,n.jsx)(u,Object.assign({setIsFocused:m},e)),(0,n.jsxs)("div",Object.assign({id:t,className:T,role:d||"tablist","aria-hidden":!0,"aria-label":r},{children:[p.map((e,t)=>{const i=g===t;return(0,n.jsxs)("div",Object.assign({className:(0,s.classList)("common-editor-toggle-item",i&&"selected",h(e)&&"common-editor-toggle-item-dropdown")},{children:[(0,n.jsx)(c,{item:e,isSelected:i,onKeydown:b}),h(e)&&(0,n.jsx)(a.MenuDropdown,{id:"toggle-dropdown",className:"toggle-dropdown",icon:"fas fa-chevron-down",title:lf("More options"),tabIndex:-1,ariaHidden:!0,items:e.items.map(e=>({role:"menuitem",title:e.title,label:e.label,onClick:e.onClick,leftIcon:e.icon}))})]}),t)}),(0,n.jsx)("div",{className:"common-editor-toggle-handle","aria-hidden":!0})]}))]}))};const c=e=>{const{item:t,isSelected:i,onKeydown:s}=e,{label:r,title:a,onClick:l,icon:c,focusable:u}=t;return(0,n.jsx)(o.Button,{className:c?void 0:"no-icon",role:u?"tab":void 0,tabIndex:-1,onKeydown:s,label:r,title:a,onClick:l,leftIcon:c,ariaHidden:!0})},u=e=>{const{items:t,id:i,selected:s,ariaHidden:a,setIsFocused:l}=e;let c;const u=t.reduce((e,t,i)=>{const n=[...e];return n.push(Object.assign({},t)),s===i?(n[n.length-1].selected=!0,c=i):n[n.length-1].selected=!1,h(t)&&n.push(...t.items.filter(e=>e.focusable)),n},[]),d=`${i}-option-`;return(0,n.jsx)(r.FocusList,Object.assign({id:i,role:"tablist",className:"common-toggle-accessibility",childTabStopId:`${d}${c}`,focusSelectsItem:!0},{children:u.map((e,t)=>(0,n.jsx)(o.Button,{className:e.selected?"selected":void 0,id:`${d}${t}`,role:"tab",title:e.title,label:e.label,onClick:e.onClick,onFocus:()=>l(!0),onBlur:()=>l(!1),ariaSelected:e.selected,ariaHidden:a},t))}))};function h(e){var t;return!!(null===(t=e.items)||void 0===t?void 0:t.length)}},{"../util":171,"./Button":159,"./FocusList":164,"./MenuDropdown":169,react:304,"react/jsx-runtime":305}],164:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FocusList=void 0;const n=e("react/jsx-runtime"),s=e("../util");i.FocusList=e=>{const{id:t,className:i,role:o,ariaHidden:r,ariaLabel:a,ariaLabelledby:l,ariaDescribedBy:c,childTabStopId:u,children:h,focusSelectsItem:d,onItemReceivedFocus:p,useUpAndDownArrowKeys:g,title:f,onClose:m}=e;let _,b;const T=e=>"true"===e.getAttribute("data-isfocusable")&&null!==e.offsetParent;return(0,n.jsx)("div",Object.assign({id:t,className:i,role:o,tabIndex:u?void 0:0,onKeyDown:e=>{if(!(null==_?void 0:_.length))return;const t=document.activeElement,i=_.indexOf(t),n=e=>{e.click?e.click():e.dispatchEvent(new Event("click"))},o=e=>{e.focus(),p&&p(e),d&&n(e)};if(-1===i&&t!==b)return;let r,a;g?(r="ArrowUp",a="ArrowDown"):pxt.Util.isUserLanguageRtl()?(r="ArrowRight",a="ArrowLeft"):(r="ArrowLeft",a="ArrowRight"),d||"Enter"!==e.key&&" "!==e.key?e.key===a?(i===_.length-1||t===b?o((0,s.findNextFocusableElement)(_,i,0,!0,T)):o((0,s.findNextFocusableElement)(_,i,i+1,!0,T)),e.preventDefault(),e.stopPropagation()):e.key===r?(o(0===i||t===b?(0,s.findNextFocusableElement)(_,i,_.length-1,!1,T):(0,s.findNextFocusableElement)(_,i,i-1,!1,T)),e.preventDefault(),e.stopPropagation()):"Home"===e.key?(o((0,s.findNextFocusableElement)(_,i,0,!0,T)),e.preventDefault(),e.stopPropagation()):"End"===e.key?(o((0,s.findNextFocusableElement)(_,i,_.length-1,!0,T)),e.preventDefault(),e.stopPropagation()):"Escape"===e.key&&m&&(m(),e.preventDefault(),e.stopPropagation()):(e.preventDefault(),e.stopPropagation(),n(t))},ref:e=>{if(!e||b)return;b=e;const t=e.querySelectorAll('[tabindex]:not([tabindex="-1"]),[data-isfocusable]');_=[];for(const e of t.values())_.push(e),e.setAttribute("tabindex","-1"),e.setAttribute("data-isfocusable","true");if(u){const e=b.querySelector("#"+u);e&&e.setAttribute("tabindex","0")}},"aria-hidden":r,"aria-label":a,"aria-labelledby":l,"aria-describedby":c,title:f},{children:h}))}},{"../util":171,"react/jsx-runtime":305}],165:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FocusTrapRegion=i.FocusTrap=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../util"),r=e("./context"),a=e("../../../hooks/useId");i.FocusTrap=e=>(0,n.jsx)(r.FocusTrapProvider,{children:(0,n.jsx)(l,Object.assign({},e))});const l=e=>{const{children:t,id:i,className:n,onEscape:a,arrowKeyNavigation:l,dontStealFocus:c,includeOutsideTabOrder:u,dontRestoreFocus:h,dontTrapFocus:d,focusFirstItem:p,tagName:g,role:f,ariaLabelledby:m,ariaLabel:_,ariaHidden:b}=e,T=s.useRef(null),E=s.useRef(document.activeElement),[v,y]=s.useState(!1),k=s.useRef(null),{regions:C}=(0,r.useFocusTrapState)();s.useEffect(()=>()=>{!h&&E.current&&(0,o.focusLastActive)(E.current)},[]);const I=s.useCallback(()=>{var e;let t=u?(0,o.getFocusableDescendants)(T.current):(0,o.getTabbableDescendants)(T.current);if(C.length){const i={};for(const t of C){const n=null===(e=T.current)||void 0===e?void 0:e.querySelector(`[data-focus-trap-region="${t.id}"]`);n&&(i[t.id]=n)}for(const e of C){const n=i[e.id];!e.enabled&&n&&(t=t.filter(e=>!n.contains(e)))}const n=t.slice();t.sort((e,t)=>{const s=C.find(t=>{var n;return t.enabled&&(null===(n=i[t.id])||void 0===n?void 0:n.contains(e))}),o=C.find(e=>{var n;return e.enabled&&(null===(n=i[e.id])||void 0===n?void 0:n.contains(t))});if((null==s?void 0:s.order)===(null==o?void 0:o.order)){return n.indexOf(e)-n.indexOf(t)}return s?o?s.order-o.order:-1:1})}return t},[C,u]),S=s.useCallback(e=>{if(!e)return;T.current=e;const t=I();c||v||e.contains(document.activeElement)||!t.length||(T.current.focus(),p&&(0,o.findNextFocusableElement)(t,-1,0,!0).focus(),y(!0))},[I,c,v,p]),A=s.useCallback(e=>{var t;if(!T.current)return;const i=(t,i)=>{const n=I();if(!n.length)return;let s,r=n.indexOf(e.target);r<0&&(r=n.indexOf(k.current)),s=t?i?(0,o.findNextFocusableElement)(n,r,n.length-1,t):r===n.length-1?(0,o.findNextFocusableElement)(n,r,0,t):(0,o.findNextFocusableElement)(n,r,r+1,t):i?(0,o.findNextFocusableElement)(n,r,0,t):0===r?(0,o.findNextFocusableElement)(n,r,n.length-1,t):(0,o.findNextFocusableElement)(n,r,Math.max(r-1,0),t),k.current=s,s.focus(),e.preventDefault(),e.stopPropagation()};if("Escape"===e.key){let i=!1;if(C.length)for(const e of C){if(!e.onEscape)continue;const n=null===(t=T.current)||void 0===t?void 0:t.querySelector(`[data-focus-trap-region="${e.id}"]`);if(null==n?void 0:n.contains(document.activeElement)){i=!0,e.onEscape();break}}i||a(),e.preventDefault(),e.stopPropagation()}else"Tab"===e.key?d?a():e.shiftKey?i(!1,!1):i(!0,!1):l&&("ArrowDown"===e.key?i(!0,!1):"ArrowUp"===e.key?i(!1,!1):"Home"===e.key?i(!1,!0):"End"===e.key&&i(!0,!0))},[I,a,l,C,d]);return s.createElement(g||"div",{id:i,className:(0,o.classList)("common-focus-trap",n),ref:S,onKeyDown:A,role:f,tabIndex:-1,"aria-labelledby":m,"aria-label":_,"aria-hidden":b},t)};i.FocusTrapRegion=e=>{const{className:t,id:i,onEscape:o,order:l,enabled:c,children:u,divRef:h}=e,d=(0,a.useId)(),p=(0,r.useFocusTrapDispatch)();return s.useEffect(()=>(p((0,r.addRegion)(d,l,c,o)),()=>p((0,r.removeRegion)(d))),[d,c,l]),(0,n.jsx)("div",Object.assign({id:i,className:t,"data-focus-trap-region":d,tabIndex:-1,ref:h},{children:u}))}},{"../../../hooks/useId":172,"../../util":171,"./context":166,react:304,"react/jsx-runtime":305}],166:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useFocusTrapDispatch=i.useFocusTrapState=i.removeRegion=i.addRegion=i.FocusTrapProvider=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=s.createContext(null),r=s.createContext(null);i.FocusTrapProvider=({children:e})=>{const[t,i]=s.useReducer(a,{regions:[]});return(0,n.jsx)(o.Provider,Object.assign({value:t},{children:(0,n.jsx)(r.Provider,Object.assign({value:i},{children:e}))}))};i.addRegion=(e,t,i,n)=>({type:"ADD_REGION",id:e,order:t,enabled:i,onEscape:n});function a(e,t){let i=e.regions.slice();switch(t.type){case"ADD_REGION":const n={id:t.id,enabled:t.enabled,order:t.order,onEscape:t.onEscape},s=i.findIndex(e=>e.id===t.id);-1!==s?i.splice(s,1,n):i.push(n);break;case"REMOVE_REGION":const o=e.regions.findIndex(e=>e.id===t.id);-1!==o&&i.splice(o,1)}return{regions:i}}i.removeRegion=e=>({type:"REMOVE_REGION",id:e}),i.useFocusTrapState=function(){return s.useContext(o)},i.useFocusTrapDispatch=function(){return s.useContext(r)}},{react:304,"react/jsx-runtime":305}],167:[function(e,t,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,s)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),s=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(i,"__esModule",{value:!0}),s(e("./FocusTrap"),i)},{"./FocusTrap":165}],168:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Input=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util"),r=e("./Button"),a=e("./FocusList");i.Input=e=>{var t;const{id:i,className:l,inputClassName:c,groupClassName:u,role:h,ariaHidden:d,ariaLabel:p,initialValue:g,label:f,title:m,placeholder:_,icon:b,iconTitle:T,disabled:E,type:v,readOnly:y,autoFocus:k,autoComplete:C,selectOnClick:I,onChange:S,onEnterKey:A,onIconClick:O,onFocus:w,onBlur:N,onOptionSelected:R,handleInputRef:x,preserveValueOnBlur:L=!0,options:D,validator:M}=e,[B,P]=s.useState(g||""),[F,U]=s.useState(!1),[H]=s.useState(e.filter?new RegExp(e.filter):void 0),G=s.useMemo(()=>D?Object.values(D):[],[D]);let V;s.useEffect(()=>{P(g||"")},[g]);const j=()=>{D&&U(!F)},W=e=>{if(!G.length)return;const t=G.indexOf(e);if(-1===t)return;var i;return`dropdown-item-${t}-${(i=e)?i.replace(/[^a-zA-Z0-9_-]/g,"-")||"option":""}`};return(0,n.jsxs)("div",Object.assign({className:(0,o.classList)("common-input-wrapper",E&&"disabled",l),onBlur:e=>{F&&!V.contains(e.relatedTarget)&&U(!1)},ref:e=>{e&&(V=e)}},{children:[f&&(0,n.jsx)("label",Object.assign({className:"common-input-label",htmlFor:i},{children:f})),(0,n.jsxs)("div",Object.assign({className:(0,o.classList)("common-input-group",u)},{children:[(0,n.jsx)("input",{id:i,className:(0,o.classList)("common-input",b&&"has-icon",c),title:m,role:h||"textbox",tabIndex:E?-1:0,"aria-label":p,"aria-hidden":d,type:v||"text",placeholder:_,value:B,readOnly:!!y,autoFocus:k,onClick:e=>{I&&e.target.select(),D&&!F&&U(!0)},onChange:e=>{var t;let i=e.target.value;i&&H&&(i=(null===(t=i.match(H))||void 0===t?void 0:t.join(""))||""),y||B===i||P(i),S&&S(i)},onKeyDown:t=>{var i,n;const s="number"==typeof t.which?t.which:t.keyCode;if(13===s||e.treatSpaceAsEnter&&32===s){let e=B;M&&(e=M(B,g||""),P(e)),A&&(t.preventDefault(),A(e))}else D&&"ArrowDown"===t.key?(F?null===(i=document.getElementById(W(G[0])))||void 0===i||i.focus():(j(),setTimeout(()=>{var e;null===(e=document.getElementById(W(G[0])))||void 0===e||e.focus()},0)),t.preventDefault(),t.stopPropagation()):D&&F&&"ArrowUp"===t.key&&(null===(n=document.getElementById(W(G[G.length-1])))||void 0===n||n.focus(),t.preventDefault(),t.stopPropagation())},onBlur:()=>{let e=B;M&&(e=M(B,g||""),P(e)),N&&N(e),L||P("")},onFocus:()=>{w&&w(B)},autoComplete:C?"":"off",autoCorrect:C?"":"off",autoCapitalize:C?"":"off",spellCheck:C,disabled:E,ref:x}),b&&(O?(0,n.jsx)(r.Button,{leftIcon:b,title:T,disabled:E,onClick:()=>{O&&O(B)}}):(0,n.jsx)("i",{className:b,"aria-hidden":!0})),D&&(0,n.jsx)(r.Button,{leftIcon:F?"fas fa-chevron-up":"fas fa-chevron-down",title:T,disabled:E,ariaHasPopup:"listbox",ariaExpanded:F,ariaLabel:p,tabIndex:-1,onClick:j})]})),F&&(0,n.jsx)(a.FocusList,Object.assign({role:"listbox",className:"common-menu-dropdown-pane common-dropdown-shadow",childTabStopId:null!==(t=W(B))&&void 0!==t?t:W(G[0]),"aria-labelledby":i,useUpAndDownArrowKeys:!0},{children:(0,n.jsx)("ul",Object.assign({role:"presentation",onKeyDown:e=>{var t;"Escape"===e.code&&(e.target.blur(),j(),null===(t=document.getElementById(i))||void 0===t||t.focus(),e.stopPropagation(),e.preventDefault())}},{children:Object.keys(D).map(e=>(0,n.jsx)("li",Object.assign({role:"presentation"},{children:(0,n.jsx)(r.Button,{title:e,label:e,id:W(D[e]),className:(0,o.classList)("common-dropdown-item"),onClick:()=>(e=>{var t;U(!1);const n=D[e];P(n),R&&R(n),null===(t=document.getElementById(i))||void 0===t||t.focus()})(e),ariaSelected:W(D[e])===W(null!=B?B:g),role:"option"})}),e))}))}))]}))}},{"../util":171,"./Button":159,"./FocusList":164,react:304,"react/jsx-runtime":305}],169:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MenuLinkItemImpl=i.MenuCheckboxItemImpl=i.MenuDropdownItemImpl=i.MenuDropdown=void 0;const n=e("react"),s=e("react/jsx-runtime"),o=e("react"),r=e("../util"),a=e("./Button"),l=e("./FocusTrap"),c=e("./Checkbox");i.MenuDropdown=e=>{const{id:t,className:c,ariaHidden:u,ariaLabel:h,role:d,items:p,label:g,title:f,icon:m,tabIndex:_,disabled:b}=e,[T,E]=o.useState(!1),v=o.useRef(!1);let y,k;o.useEffect(()=>{if(T&&y&&v.current){const e=y.querySelector("[role=menu]");if(!e)return;const t=e.querySelectorAll("[role=menuitem], [role=menuitemcheckbox], [role=menuitemradio]");for(const e of t){const t=e;if(null!==t.offsetParent){t.focus();break}}}},[T]);const C=()=>{E(!1),k&&k.focus()},I=(0,r.classList)("common-menu-dropdown",c),S=t+"-menu",A=function(e){const t=[];let i={items:[]};for(const n of e)"separator"===n.role?(i.className=n.className,i.items.length>0&&(t.push(i),i={items:[]})):i.items.push(n);i.items.length>0&&t.push(i);return t}(p);return(0,s.jsxs)("div",Object.assign({className:I,ref:e=>{e&&(y=e)},onBlur:e=>{y&&T&&!y.contains(e.relatedTarget)&&E(!1)}},{children:[(0,s.jsx)(a.Button,{id:t,label:g,tabIndex:_,buttonRef:e=>{e&&(k=e)},title:f,leftIcon:m,role:d||"button",className:(0,r.classList)("menu-button",T&&"expanded"),onClick:null,onClickEvent:e=>{v.current=0===e.detail,E(!T)},ariaHasPopup:"true",ariaExpanded:T,ariaControls:T?S:void 0,ariaLabel:h,ariaHidden:u,disabled:b,onKeydown:e=>{"ArrowDown"!==e.key||T||(v.current=!0,E(!0))}}),T&&(0,s.jsx)(l.FocusTrap,Object.assign({role:"menu",className:"common-menu-dropdown-pane",id:S,arrowKeyNavigation:!0,onEscape:()=>{E(!1),k&&k.focus()},includeOutsideTabOrder:!0,dontTrapFocus:!0,dontRestoreFocus:!0,focusFirstItem:!1,ariaLabelledby:t,tagName:"ul"},{children:A.map((e,t)=>(0,s.jsxs)(o.Fragment,{children:[e.items.map((e,s)=>{const o=`${t}-${s}`;return"menuitem"===e.role?(0,n.createElement)(i.MenuDropdownItemImpl,Object.assign({},e,{key:o,onClick:()=>{var t;C(),null===(t=e.onClick)||void 0===t||t.call(e)}})):"link"===e.role?(0,n.createElement)(i.MenuLinkItemImpl,Object.assign({},e,{key:o,onClick:()=>{var t;C(),null===(t=e.onClick)||void 0===t||t.call(e)}})):(0,n.createElement)(i.MenuCheckboxItemImpl,Object.assign({},e,{key:o,onChange:t=>{var i;C(),null===(i=e.onChange)||void 0===i||i.call(e,t)}}))}),t<A.length-1&&(0,s.jsx)("li",{role:"separator",className:(0,r.classList)("common-menu-dropdown-separator",e.className)})]},t))}))]}))};i.MenuDropdownItemImpl=e=>{const t=(0,a.inflateButtonProps)(e);return(0,s.jsx)("li",Object.assign({},t,{className:(0,r.classList)("common-menu-dropdown-item",t.className),role:"menuitem",tabIndex:-1},{children:(0,s.jsx)(a.ButtonBody,Object.assign({},e))}))};i.MenuCheckboxItemImpl=e=>{const{label:t,isChecked:i,onChange:n,id:o,className:a,ariaLabel:l,ariaHidden:u,ariaDescribedBy:h}=e;return(0,s.jsxs)("li",Object.assign({role:"menuitemcheckbox",tabIndex:-1,className:(0,r.classList)("common-menu-dropdown-item","common-menu-dropdown-checkbox-item",a),"aria-label":l,"aria-hidden":u,"aria-describedby":h,"aria-checked":i?"true":"false",onClick:()=>n(!i),onKeyDown:r.fireClickOnEnter,id:o},{children:[(0,s.jsx)(c.CheckboxIcon,{isChecked:i}),(0,s.jsx)("span",{children:t})]}))};i.MenuLinkItemImpl=e=>{const{href:t,label:i,id:n,className:o,ariaLabel:a,ariaHidden:l,ariaDescribedBy:c,onClick:u}=e;return(0,s.jsx)("li",Object.assign({role:"none"},{children:(0,s.jsx)("a",Object.assign({role:"menuitem",className:(0,r.classList)("common-menu-dropdown-item","common-menu-dropdown-link-item",o),"aria-label":a,"aria-hidden":l,"aria-describedby":c,id:n,tabIndex:-1,href:t,target:"_blank",rel:"noopener noreferrer",onClick:u,onKeyDown:r.fireClickOnEnter},{children:i}))}))}},{"../util":171,"./Button":159,"./Checkbox":161,"./FocusTrap":167,react:304,"react/jsx-runtime":305}],170:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Modal=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-dom"),r=e("../util"),a=e("./Button"),l=e("./FocusTrap");i.Modal=e=>{const{children:t,id:i,className:c,ariaLabel:u,ariaHidden:h,ariaDescribedBy:d,role:p,title:g,hideTitle:f,leftIcon:m,actions:_,onClose:b,parentElement:T,fullscreen:E,hideDismissButton:v,rightHeader:y}=e,k=e=>{b&&b()},C=(0,r.classList)("common-modal-container",E&&"fullscreen",c),I=s.useRef(null);return s.useEffect(()=>{var e;const t=T||document.body,i=null===(e=I.current)||void 0===e?void 0:e.parentElement,n=[];for(const e of t.children)e!==i&&(e.hasAttribute("aria-hidden")&&"false"!==e.getAttribute("aria-hidden")||(e.setAttribute("aria-hidden","true"),n.push(e)));return()=>{for(const e of n)e.removeAttribute("aria-hidden")}},[T]),o.createPortal((0,n.jsx)(l.FocusTrap,Object.assign({className:C,onEscape:k},{children:(0,n.jsxs)("div",Object.assign({id:i,className:"common-modal",ref:I,role:p||"dialog","aria-hidden":h,"aria-label":u,"aria-describedby":d,"aria-labelledby":"modal-title"},{children:[(0,n.jsxs)("div",Object.assign({className:"common-modal-header"},{children:[E&&!v&&(0,n.jsx)("div",Object.assign({className:"common-modal-back"},{children:(0,n.jsx)(a.Button,{className:"menu-button",onClick:k,title:lf("Go Back"),label:lf("Go Back"),leftIcon:"fas fa-arrow-left"})})),(0,n.jsxs)("div",Object.assign({id:"modal-title",className:(0,r.classList)("common-modal-title",f&&"sr-only")},{children:[m&&(0,n.jsx)("i",{className:m,"aria-hidden":!0}),g]})),y&&(0,n.jsx)("div",Object.assign({className:"common-modal-right-menu"},{children:y})),!E&&!v&&(0,n.jsx)("div",Object.assign({className:"common-modal-close"},{children:(0,n.jsx)(a.Button,{className:"menu-button",onClick:k,title:lf("Close"),rightIcon:"fas fa-times-circle"})}))]})),(0,n.jsx)("div",Object.assign({className:"common-modal-body"},{children:t})),(null==_?void 0:_.length)&&(0,n.jsx)("div",Object.assign({className:"common-modal-footer"},{children:_.map((e,t)=>{var i;return(0,n.jsx)(a.Button,{className:null!==(i=e.className)&&void 0!==i?i:"primary inverted",disabled:e.disabled,onClick:e.onClick,href:e.url,label:e.label,title:e.label,rightIcon:(e.xicon?"xicon ":"")+e.icon,leftIcon:e.leftIcon},t)})}))]}))})),T||document.body)}},{"../util":171,"./Button":159,"./FocusTrap":167,react:304,"react-dom":268,"react/jsx-runtime":305}],171:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.focusLastActive=i.isTabbable=i.isDisabled=i.isFocusable=i.getVisibleDescendants=i.getTabbableDescendants=i.getFocusableDescendants=i.findNextFocusableElement=i.screenToSVGCoord=i.clientCoord=i.CheckboxStatus=i.nodeListToArray=i.classList=i.fireClickOnEnter=i.jsxLF=void 0;const n=e("react/jsx-runtime");function s(e,t){if(!o(e))return[];const i=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,e=>o(e,!1)?t(e)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT),n=[];let s=i.nextNode();for(;s;)n.push(s),s=i.nextNode();return n}function o(e,t=!0){if(e.checkVisibility)return e.checkVisibility({visibilityProperty:!0});const i=getComputedStyle(e);return"none"!==i.display&&"hidden"!==i.visibility&&(!t||!e.parentElement||o(e.parentElement,t))}function r(e){return a(e)&&o(e)}function a(e){return!l(e)&&!!(e.hasAttribute("tabindex")||"A"===e.tagName&&(e.hasAttribute("href")||e.hasAttributeNS("xlink","href"))||"BUTTON"===e.tagName||"INPUT"===e.tagName||"SELECT"===e.tagName||"TEXTAREA"===e.tagName||"IFRAME"===e.tagName||"EMBED"===e.tagName||"OBJECT"===e.tagName||"DIV"===e.tagName&&e.hasAttribute("contenteditable")&&"false"!==e.getAttribute("contenteditable")||("AUDIO"===e.tagName||"VIDEO"===e.tagName)&&e.hasAttribute("controls"))}function l(e){return!(!e||!e.hasAttribute("disabled"))}function c(e){return!!a(e)&&(!e.hasAttribute("tabindex")||parseInt(e.getAttribute("tabindex"))>=0)}i.jsxLF=function(e,...t){const i=[];e.replace(/\{\d\}/g,e=>(i.push(parseInt(e.substr(1,1))),e));const s=[];let o,r=0;for(const a of i)o=e.split(`{${a}}`),pxt.U.assert(2===o.length),s.push((0,n.jsx)("span",{children:o[0]},r++)),s.push((0,n.jsx)("span",{children:t[a]},r++)),e=o[1];return s.push((0,n.jsx)("span",{children:e},r++)),s},i.fireClickOnEnter=function(e){const t="number"==typeof e.which?e.which:e.keyCode;13!==t&&32!==t||(e.preventDefault(),e.stopPropagation(),e.currentTarget.click())},i.classList=function(...e){return e.filter(e=>"string"==typeof e).reduce((e,t)=>e.concat(t.split(" ")),[]).map(e=>e.trim()).filter(e=>!!e).join(" ")},i.nodeListToArray=function(e){const t=[];for(const i of e)t.push(i);return t},function(e){e[e.Selected=0]="Selected",e[e.Unselected=1]="Unselected",e[e.Waiting=2]="Waiting"}(i.CheckboxStatus||(i.CheckboxStatus={})),i.clientCoord=function(e){if(e.touches){const t=e;return t.touches.length?t.touches[0]:t.changedTouches[0]}return e},i.screenToSVGCoord=function(e,t){const i=e.createSVGPoint();return i.x=t.clientX,i.y=t.clientY,i.matrixTransform(e.getScreenCTM().inverse())},i.findNextFocusableElement=function e(t,i,n,s,r,a=!0){const l=s?1:-1,c=t[n=Math.max(0,Math.min(t.length-1,n))];if(i===n)return c;if(r?r(c):o(c))return c;if(n+l>=t.length){if(!a)return c;n=0}else if(n+l<0){if(!a)return c;n=t.length-1}else n+=l;return e(t,i,n,s,r,a)},i.getFocusableDescendants=function(e){return s(e,a)},i.getTabbableDescendants=function(e){return s(e,c)},i.getVisibleDescendants=s,i.isFocusable=r,i.isDisabled=l,i.isTabbable=function(e){return c(e)&&o(e)},i.focusLastActive=function(e){for(;e&&!r(e);){const t=e.parentElement;if(!t)break;e=t}e.focus()}},{"react/jsx-runtime":305}],172:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useId=void 0;const n=e("react");i.useId=function(){return n.useMemo(()=>pxt.Util.guidGen(),[])}},{react:304}],173:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-dom"),r=e("./components/ImageFieldEditor"),a=e("./components/ImageEditor/store/imageReducer"),l=e("../../pxtservices/iframeEmbeddedClient");document.addEventListener("DOMContentLoaded",()=>{!function(){const e=document.getElementById("asset-editor-field-div");o.render((0,n.jsx)(c,{}),e)}()});class c extends s.Component{constructor(e){super(e),this.handleMessage=e=>{const t=e.data;switch(t.type){case"create":this.setPalette(t.palette),this.initTilemapProject(t.files);const e=this.getEmptyAsset(t.assetType,t.displayName);this.setState({editing:e,isEmptyAsset:!0}),this.sendResponse({id:t.id,type:t.type});break;case"open":this.setPalette(t.palette),this.initTilemapProject(t.files);const i=this.lookupAsset(t.assetType,t.assetId);"tilemap"===i.type&&pxt.sprite.addMissingTilemapTilesAndReferences(this.editorProject,i),this.setState({editing:i}),this.sendResponse({id:t.id,type:t.type});break;case"duplicate":this.setPalette(t.palette),this.initTilemapProject(t.files);const n=this.lookupAsset(t.assetType,t.assetId);this.setState({editing:this.editorProject.duplicateAsset(n)}),this.sendResponse({id:t.id,type:t.type});break;case"save":this.sendResponse({id:t.id,type:t.type,files:this.saveProjectFiles()})}},this.refHandler=e=>{e&&(this.editor=e,this.editor.init(this.state.editing,()=>{},{galleryTiles:this.galleryTiles,hideMyAssets:!0,hideCloseButton:!0}))},this.handleKeydown=e=>{!e.ctrlKey||"s"!==e.key&&"S"!==e.key||this.sendSaveRequest()},this.pollForUpdates=()=>{this.state.editing&&this.updateAsset()},this.sendSaveRequest=()=>{this.sendEvent({type:"event",kind:"done-clicked"})},this.state={},pxt.react.getTilemapProject=()=>this.editorProject,(0,a.setTelemetryFunction)(u)}componentDidMount(){this.iframeClient=new l.IFrameEmbeddedClient(this.handleMessage),window.addEventListener("keydown",this.handleKeydown,null),this.sendEvent({type:"event",kind:"ready"}),u("asset-editor-shown"),this.pollingInterval=setInterval(this.pollForUpdates,200)}componentWillUnmount(){window.removeEventListener("message",this.handleMessage,null),window.removeEventListener("keydown",this.handleKeydown,null),window.clearInterval(this.pollingInterval)}componentDidUpdate(e,t,i){var n;(null==t?void 0:t.editing)&&t.editing!==this.state.editing&&this.saveProject.removeChangeListener(t.editing.type,this.sendSaveRequest),(null===(n=this.state)||void 0===n?void 0:n.editing)&&this.saveProject.addChangeListener(this.state.editing,this.sendSaveRequest)}render(){if(this.state.editing){const e="song"===this.state.editing.type?"music":"image";return(0,n.jsx)(r.ImageFieldEditor,{ref:this.refHandler,singleFrame:"animation"!==this.state.editing.type,editorType:e,doneButtonCallback:this.sendSaveRequest,hideDoneButton:!0,includeSpecialTagsInFilter:!0})}return(0,n.jsx)("div",{})}sendResponse(e){this.postMessage(e)}sendEvent(e){this.postMessage(e)}postMessage(e){this.iframeClient.postMessage(e)}updateAsset(){var e,t,i,n,s;const o=this.editor.getValue(),r=pxt.cloneAsset(o);if(!this.lastValue||!pxt.assetEquals(this.lastValue,r)){if(this.lastValue=pxt.cloneAsset(o),"tilemap"===r.type&&o.type===r.type&&(r.data.deletedTiles=null===(e=o.data.deletedTiles)||void 0===e?void 0:e.slice(),r.data.editedTiles=null===(t=o.data.editedTiles)||void 0===t?void 0:t.slice(),r.data.projectReferences=null===(i=o.data.projectReferences)||void 0===i?void 0:i.slice(),r.data.tileOrder=null===(n=o.data.tileOrder)||void 0===n?void 0:n.slice()),this.saveProject=this.editorProject.clone(),this.state.isEmptyAsset){const e=null===(s=r.meta)||void 0===s?void 0:s.displayName;let t;switch(r.type){case"image":t=this.saveProject.createNewProjectImage(r.bitmap,e);break;case"tile":t=this.saveProject.createNewTile(r.bitmap,null,e);break;case"tilemap":pxt.sprite.updateTilemapReferencesFromResult(this.saveProject,r);const[i,n]=this.saveProject.createNewTilemapFromData(r.data,e);t=this.saveProject.lookupAssetByName("tilemap",i);break;case"animation":t=this.saveProject.createNewAnimationFromData(r.frames,r.interval,e);break;case"song":t=this.saveProject.createNewSong(r.song,e)}}else"tilemap"===r.type&&pxt.sprite.updateTilemapReferencesFromResult(this.saveProject,r),this.saveProject.updateAsset(r);this.sendSaveRequest()}}saveProjectFiles(){this.updateAsset();const e=pxt.inflateJRes(this.saveProject.getProjectAssetsJRes()),t=pxt.inflateJRes(this.saveProject.getProjectTilesetJRes()),i={};for(const t of Object.keys(e)){const n=this.locateFileForAsset(t)||pxt.IMAGES_JRES;i[n]||(i[n]={}),i[n][t]=e[t]}for(const e of Object.keys(t)){const n=this.locateFileForAsset(e)||pxt.TILEMAP_JRES;i[n]||(i[n]={}),i[n][e]=t[e]}const n=Object.assign({},this.files);for(const e of Object.keys(i)){n[e]=JSON.stringify(i[e],null,4);const t=e.substring(0,e.length-4)+"ts";(n[t]||e===pxt.IMAGES_JRES||e===pxt.TILEMAP_JRES)&&(n[t]=pxt.emitProjectImages(i[e])+"\n"+pxt.emitTilemapsFromJRes(i[e]))}return n}setPalette(e){e&&Array.isArray(e)&&e.length&&(pxt.appTarget.runtime.palette=e.slice())}initTilemapProject(e){var t;const i={},n={},s={},o={};this.editorProject=new pxt.TilemapProject,this.inflatedJres={},this.commentAttrs={};for(const t of Object.keys(e).filter(e=>!e.endsWith(".jres"))){const i=h(e[t]);for(const e of Object.keys(i))this.commentAttrs[e]=i[e]}for(const r of Object.keys(e).filter(e=>e.endsWith(".jres"))){const a=-1!==r.indexOf("pxt_modules")||-1!==r.indexOf("node_modules"),l=pxt.inflateJRes(JSON.parse(e[r]));this.inflatedJres[r]=l;for(const e of Object.keys(l)){if(null===(t=this.commentAttrs[e])||void 0===t?void 0:t.tags){const t=this.commentAttrs[e].tags.split(" ").filter(e=>!!e);t.length&&(l[e].tags=t)}l[e].mimeType===pxt.TILEMAP_MIME_TYPE||l[e].tilemapTile?a?n[e]=l[e]:i[e]=l[e]:a?o[e]=l[e]:s[e]=l[e]}}this.editorProject.loadAssetsJRes(o,!0),this.editorProject.loadAssetsJRes(s),this.editorProject.loadTilemapJRes(n,!1,!0),this.editorProject.loadTilemapJRes(i),this.galleryTiles=this.editorProject.getGalleryAssets("tile").map(e=>{var t;if(!this.commentAttrs[e.id])return;const i=null===(t=e.meta.tags)||void 0===t?void 0:t.map(e=>pxt.Util.startsWith(e,"category-")?e:e.toLowerCase());return i&&-1!==i.indexOf("tile")?{qName:e.id,bitmap:e.bitmap,alt:e.id,tags:i}:void 0}).filter(e=>!!e),this.saveProject=this.editorProject.clone()}locateFileForAsset(e){for(const t of Object.keys(this.inflatedJres))if(this.inflatedJres[t][e])return t}getEmptyAsset(e,t){const i=pxt.react.getTilemapProject(),n={type:e,id:"",internalID:0,meta:{displayName:i.generateNewName(e,t)}};switch(e){case"image":case"tile":n.bitmap=new pxt.sprite.Bitmap(16,16).data();break;case"tilemap":const e=n;e.data=i.blankTilemap(16,16,16),pxt.sprite.addMissingTilemapTilesAndReferences(i,e);break;case"animation":const t=n;t.frames=[new pxt.sprite.Bitmap(16,16).data()],t.interval=200;break;case"song":n.song=pxt.assets.music.getEmptySong(2)}return n}lookupAsset(e,t){const i=this.saveProject.lookupAsset(e,t);if(i)return i;const n=t.split(".");return this.saveProject.lookupAsset(e,n[n.length-1])}}function u(e){pxt.tickEvent("asset.editor",{action:e})}function h(e){const t=e.split("\n"),i={};let n,s="";for(const e of t){const t=/^namespace\s+([^\}]+)\s+\{$/.exec(e);if(t){n=t[1],s="";continue}if(/^\s+\/\/%\s/.test(e)){s+=e+"\n";continue}const o=/^\s*export\s+const\s+([^\s]+)\s*=/.exec(e);if(o){i[n+"."+o[1]]=pxtc.parseCommentString(s),s=""}}return i}i.AssetEditor=c},{"../../pxtservices/iframeEmbeddedClient":158,"./components/ImageEditor/store/imageReducer":191,"./components/ImageFieldEditor":197,react:304,"react-dom":268,"react/jsx-runtime":305}],174:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getLabelForAssetType=i.getIconClassForAssetType=i.assetToGalleryItem=i.getAssets=i.getNewInternalID=i.lookupAsset=i.createTile=i.createProjectImage=i.createNewImageAsset=i.isNameTaken=void 0;const n=e("../../pxtblocks");function s(e,t=new pxt.ImageConverter){var i;switch(e.type){case"image":case"tile":return e.previewURI=t.convert("data:image/x-mkcd-f,"+e.jresData),e;case"tilemap":let s=e.data.tilemap;return e.previewURI=n.tilemapToImageURI(e.data,Math.max(s.width,s.height),!1),e;case"animation":return(null===(i=e.frames)||void 0===i?void 0:i.length)<=0?null:(e.framePreviewURIs=e.frames.map(e=>t.convert("data:image/x-mkcd-f,"+pxt.sprite.base64EncodeBitmap(e))),e.previewURI=e.framePreviewURIs[0],e);case"song":return e.previewURI=n.songToDataURI(e.song,32,32,!1,1),e;case"json":return e}}function o(e){return function(t,i){const n=-1===e.indexOf(t.meta.package)?0:1,s=-1===e.indexOf(i.meta.package)?0:1;return n===s?function(e,t){return e.internalID-t.internalID}(t,i):n-s}}i.isNameTaken=function(e){return pxt.react.getTilemapProject().isNameTaken("image",e)},i.createNewImageAsset=function(e,t,i,n){const s=pxt.react.getTilemapProject();switch(e){case"tile":return s.createNewTile(new pxt.sprite.Bitmap(t,i).data(),null,n);case"image":return s.createNewImage(t,i)}return null},i.createProjectImage=function(e){return pxt.react.getTilemapProject().createNewProjectImage(e)},i.createTile=function(e,t,i){return pxt.react.getTilemapProject().createNewTile(e,t,i)},i.lookupAsset=function(e,t){return pxt.react.getTilemapProject().lookupAsset(e,t)},i.getNewInternalID=function(){return pxt.react.getTilemapProject().getNewInternalId()},i.getAssets=function(e=!1,t="image",i=[]){const n=pxt.react.getTilemapProject(),r=new pxt.ImageConverter,a=e=>s(e,r),l=e?n.getGalleryAssets.bind(n):n.getAssets.bind(n),c=function(){var e;const t=null===(e=pxt.appTarget.blocksprj)||void 0===e?void 0:e.config;if(t){return Object.keys(t.dependencies)}return[]}(),u=l("image").map(a).sort(o(c)),h=l("tile").map(a).filter(e=>!e.id.match(/^myTiles.transparency(8|16|32)$/gi)).sort(o(c)),d=l("tilemap").map(a).sort(o(c)),p=l("animation").map(a).sort(o(c)),g=l("song").map(a).sort(o(c)),f=l("json").map(a).sort(o(c));for(const e of i)switch(e.type){case"image":u.push(a(e));break;case"tile":h.push(a(e));break;case"animation":p.push(a(e));break;case"tilemap":d.push(a(e));break;case"song":g.push(a(e));break;case"json":f.push(a(e))}let m=[];switch(t){case"image":m=u.concat(h).concat(p).concat(d).concat(g).concat(f);break;case"tile":m=h.concat(u).concat(p).concat(d).concat(g).concat(f);break;case"animation":m=p.concat(u).concat(h).concat(d).concat(g).concat(f);break;case"tilemap":m=d.concat(h).concat(u).concat(p).concat(g).concat(f);break;case"song":m=g.concat(u).concat(h).concat(p).concat(d).concat(f);break;case"json":m=f.concat(u).concat(h).concat(p).concat(d).concat(g)}return pxt.tickEvent(e?"assets.gallery":"assets.update",{count:m.length}),m},i.assetToGalleryItem=s,i.getIconClassForAssetType=function(e){var t;if("object"==typeof(null===(t=pxt.appTarget.appTheme)||void 0===t?void 0:t.assetEditor)){const t=pxt.appTarget.appTheme.assetEditor[e];if("object"==typeof t&&t.iconClass)return t.iconClass}switch(e){case"tile":return"clone";case"animation":return"video";case"tilemap":return"map";case"song":return"music";case"json":return"file code";default:return null}},i.getLabelForAssetType=function(e){var t;if("object"==typeof(null===(t=pxt.appTarget.appTheme)||void 0===t?void 0:t.assetEditor)){const t=pxt.appTarget.appTheme.assetEditor[e];if("object"==typeof t&&t.label)return pxt.U.rlf(`{id:assetType}${t.label}`)}switch(e){case"image":return lf("Image");case"tile":return lf("Tile");case"animation":return lf("Animation");case"tilemap":return lf("Tilemap");case"song":return lf("Song");case"json":return lf("File")}}},{"../../pxtblocks":76}],175:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.FilterPanel=i.FilterPanelSubheading=i.FilterTag=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../util");class r extends s.Component{constructor(e){super(e),this.clickHandler=this.clickHandler.bind(this)}render(){return(0,n.jsxs)("div",Object.assign({className:"filter-tag"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-tag-box",role:"checkbox",onClick:this.clickHandler,onKeyDown:o.fireClickOnEnter,"aria-checked":this.props.selected},{children:(0,n.jsx)("i",{className:"icon square outline "+(this.props.selected?"check":"")})})),(0,n.jsx)("div",Object.assign({className:"filter-tag-name",role:"button",onClick:this.clickHandler,onKeyDown:o.fireClickOnEnter},{children:pxtc.U.rlf(this.props.tag)}))]}))}clickHandler(){this.props.onClickHandler(this.props.tag)}}i.FilterTag=r;class a extends s.Component{render(){return(0,n.jsxs)("div",Object.assign({className:"filter-subheading-row"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-subheading-title"},{children:`${this.props.subheading}:`})),this.props.buttonText&&(0,n.jsx)("div",Object.assign({className:"filter-subheading-button",role:"button",style:this.props.buttonStyle,onClick:this.props.buttonAction,onKeyDown:o.fireClickOnEnter},{children:this.props.buttonText}))]}))}}i.FilterPanelSubheading=a;class l extends s.Component{isTagSelected(e){return this.props.enabledTags.indexOf(e.toLowerCase())>=0}render(){const e=this.props.tagOptions;return(0,n.jsxs)("div",Object.assign({className:"filter-panel"},{children:[(0,n.jsx)("div",Object.assign({className:"filter-title"},{children:lf("Filter")})),(0,n.jsx)(a,{subheading:lf("Categories"),buttonText:lf("Clear"),buttonAction:this.props.clearTags,buttonStyle:this.props.enabledTags.length>0?{color:"white"}:{}}),(0,n.jsx)("div",Object.assign({className:"filter-tag-list"},{children:e.map(e=>(0,n.jsx)(r,{tag:e,selected:this.isTagSelected(e),onClickHandler:this.props.tagClickHandler},e))}))]}))}}i.FilterPanel=l},{"../util":240,react:304,"react/jsx-runtime":305}],176:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Alert=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch");class a extends s.Component{constructor(e){super(e)}render(){const{title:e,text:t,options:i,dispatchHideAlert:s}=this.props;return(0,n.jsx)("div",Object.assign({className:"image-editor-alert-container",role:"region",onClick:s},{children:(0,n.jsxs)("div",Object.assign({className:"image-editor-alert",role:"dialog"},{children:[(0,n.jsxs)("div",Object.assign({className:"title"},{children:[(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Warning"}),(0,n.jsx)("span",{children:e}),(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Cancel",role:"button",onClick:s})]})),(0,n.jsx)("div",Object.assign({className:"text"},{children:t})),i&&(0,n.jsx)("div",Object.assign({className:"options"},{children:i.map((e,t)=>(0,n.jsx)("div",Object.assign({className:"button",role:"button",onClick:e.onClick},{children:e.label}),t))}))]}))}))}}const l={dispatchHideAlert:r.dispatchHideAlert};i.Alert=(0,o.connect)(function({editor:e},t){return e?t:{}},l)(a)},{"./actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],177:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.BottomBar=i.BottomBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("../../assets"),l=e("./keyboardShortcuts"),c=e("../../../../react-common/components/util"),u=e("../../../../react-common/components/controls/Button");class h extends s.Component{constructor(e){super(e),this.disableShortcutsOnFocus=()=>{this.setShortcutsEnabled(!1)},this.handleWidthChange=e=>{const t=e.target.value,i=parseInt(t),{aspectRatioLocked:n,imageDimensions:s}=this.props;!isNaN(i)&&n?this.setState({width:i+"",height:Math.floor(i*(s[1]/s[0]))+""}):this.setState({width:t})},this.handleHeightChange=e=>{const t=e.target.value,i=parseInt(t),{aspectRatioLocked:n,imageDimensions:s}=this.props;!isNaN(i)&&n?this.setState({height:i+"",width:Math.floor(i*(s[0]/s[1]))+""}):this.setState({height:t})},this.handleDimensionalBlur=()=>{const{imageDimensions:e,isTilemap:t,dispatchChangeImageDimensions:i}=this.props,n=parseInt(this.state.width),s=parseInt(this.state.height),o=t?255:512,r=isNaN(n)?e[0]:Math.min(Math.max(n,1),o),a=isNaN(s)?e[1]:Math.min(Math.max(s,1),o);r===e[0]&&a===e[1]||i([r,a]),this.setState({width:null,height:null}),this.setShortcutsEnabled(!0)},this.handleDimensionalKeydown=e=>{13===("number"==typeof e.which?e.which:e.keyCode)&&e.currentTarget.blur()},this.handleAssetNameChange=e=>{let t=null;const i=e.target.value||"",n=i.trim();pxt.validateAssetName(n)?(0,a.isNameTaken)(n)&&n!==this.props.assetName&&(t=lf("This name is already used elsewhere in your project")):t=lf("Names may only contain letters, numbers, '-', '_', and space"),this.setState({assetName:i,assetNameMessage:t})},this.handleAssetNameBlur=()=>{const{dispatchChangeAssetName:e,assetName:t}=this.props;if(this.state.assetName){let i=this.state.assetName.trim();i!==t&&pxt.validateAssetName(i)&&!(0,a.isNameTaken)(i)&&e(i)}this.setState({assetName:null,assetNameMessage:null}),this.setShortcutsEnabled(!0)},this.zoomIn=()=>{this.props.dispatchChangeZoom(1)},this.zoomOut=()=>{this.props.dispatchChangeZoom(-1)},this.state={}}render(){const{imageDimensions:e,cursorLocation:t,hasUndo:i,hasRedo:s,dispatchUndoImageEdit:o,dispatchRedoImageEdit:r,aspectRatioLocked:a,onionSkinEnabled:l,dispatchToggleAspectRatioLocked:h,dispatchToggleOnionSkinEnabled:d,resizeDisabled:p,singleFrame:g,onDoneClick:f,assetName:m,hideDoneButton:_,hideAssetName:b}=this.props,{assetNameMessage:T}=this.state,E=null==this.state.width?e[0]:this.state.width,v=null==this.state.height?e[1]:this.state.height,y=null==this.state.assetName?m||"":this.state.assetName;return(0,n.jsxs)("div",Object.assign({className:"image-editor-bottombar"},{children:[!p&&(0,n.jsxs)("div",Object.assign({className:"image-editor-resize"},{children:[(0,n.jsx)("input",{className:"image-editor-input",title:lf("Image Width"),value:E,tabIndex:0,onChange:this.handleWidthChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleDimensionalBlur,onKeyDown:this.handleDimensionalKeydown}),(0,n.jsx)(u.Button,{className:(0,c.classList)("image-editor-button",!a&&"toggle"),onClick:h,leftIcon:a?"ms-Icon ms-Icon--Lock":"ms-Icon ms-Icon--Unlock",title:a?lf("Unlock Aspect Ratio"):lf("Lock Aspect Ratio")}),(0,n.jsx)("input",{className:"image-editor-input",title:lf("Image Height"),value:v,tabIndex:0,onChange:this.handleHeightChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleDimensionalBlur,onKeyDown:this.handleDimensionalKeydown})]})),!g&&(0,n.jsx)("div",{className:"image-editor-seperator"}),!g&&(0,n.jsx)("div",{children:(0,n.jsx)(u.Button,{onClick:d,className:(0,c.classList)("image-editor-button",!l&&"toggle"),leftIcon:"ms-Icon ms-Icon--MapLayers",title:l?lf("Hide Previous Frame"):lf("Show Previous Frame")})}),!p&&(0,n.jsx)("div",{className:(0,c.classList)("image-editor-seperator",!t&&"transparent")}),(0,n.jsx)("div",Object.assign({className:"image-editor-coordinate-preview"},{children:t&&`${t[0]}, ${t[1]}`})),(0,n.jsx)("div",Object.assign({className:"image-editor-change-name"},{children:!b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{className:"image-editor-input",title:lf("Asset Name"),value:y,placeholder:lf("Asset Name"),tabIndex:0,onChange:this.handleAssetNameChange,onFocus:this.disableShortcutsOnFocus,onBlur:this.handleAssetNameBlur,onKeyDown:this.handleDimensionalKeydown}),T&&(0,n.jsx)("div",Object.assign({className:"ui pointing below red basic label"},{children:T}))]})})),(0,n.jsxs)("div",Object.assign({className:"image-editor-undo-redo"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button",title:lf("Undo"),leftIcon:"ms-Icon ms-Icon--Undo",onClick:i?o:null,disabled:!i}),(0,n.jsx)(u.Button,{className:"image-editor-button",title:lf("Redo"),leftIcon:"ms-Icon ms-Icon--Redo",onClick:s?r:null,disabled:!s})]})),(0,n.jsx)("div",{className:"image-editor-seperator"}),(0,n.jsxs)("div",Object.assign({className:"image-editor-zoom-controls"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button toggle",onClick:this.zoomOut,leftIcon:"ms-Icon ms-Icon--ZoomOut",title:lf("Zoom Out")}),(0,n.jsx)(u.Button,{className:"image-editor-button toggle",onClick:this.zoomIn,leftIcon:"ms-Icon ms-Icon--ZoomIn",title:lf("Zoom In")})]})),!_&&(0,n.jsx)(u.Button,{className:"image-editor-confirm",title:lf("Done"),label:lf("Done"),onClick:f})]}))}setShortcutsEnabled(e){e&&this.shortcutLock?((0,l.releaseShortcutLock)(this.shortcutLock),this.shortcutLock=void 0):e||this.shortcutLock||(this.shortcutLock=(0,l.obtainShortcutLock)())}}i.BottomBarImpl=h;const d={dispatchChangeImageDimensions:r.dispatchChangeImageDimensions,dispatchUndoImageEdit:r.dispatchUndoImageEdit,dispatchRedoImageEdit:r.dispatchRedoImageEdit,dispatchToggleAspectRatioLocked:r.dispatchToggleAspectRatioLocked,dispatchToggleOnionSkinEnabled:r.dispatchToggleOnionSkinEnabled,dispatchChangeZoom:r.dispatchChangeZoom,dispatchChangeAssetName:r.dispatchChangeAssetName};i.BottomBar=(0,o.connect)(function({store:{present:e,past:t,future:i},editor:n},s){var o,r,a;if(!e)return{};const l=n.isTilemap?e.tilemap.bitmap:e.frames[e.currentFrame].bitmap;return{imageDimensions:[l.width,l.height],aspectRatioLocked:e.aspectRatioLocked,onionSkinEnabled:n.onionSkinEnabled,cursorLocation:n.cursorLocation,resizeDisabled:"tile"===(null===(o=e.asset)||void 0===o?void 0:o.type),assetName:null===(a=null===(r=e.asset)||void 0===r?void 0:r.meta)||void 0===a?void 0:a.displayName,hasUndo:!!t.length,hasRedo:!!i.length,isTilemap:n.isTilemap}},d)(h)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"../../assets":174,"./actions/dispatch":187,"./keyboardShortcuts":189,react:304,"react-redux":287,"react/jsx-runtime":305}],178:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CursorSizes=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./actions/dispatch"),r=e("react-redux"),a=e("../../../../react-common/components/controls/Button"),l=e("../../../../react-common/components/util");class c extends s.Component{constructor(){super(...arguments),this.handlers=[]}render(){const{selected:e}=this.props;return(0,n.jsxs)("div",Object.assign({className:"cursor-buttons"},{children:[(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",1!==e&&"toggle"),title:lf("Small Cursor (1px)"),label:(0,n.jsx)("div",{className:"cursor-button small"}),onClick:this.clickHandler(1)}),(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",3!==e&&"toggle"),title:lf("Small Cursor (3px)"),label:(0,n.jsx)("div",{className:"cursor-button medium"}),onClick:this.clickHandler(3)}),(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",5!==e&&"toggle"),title:lf("Small Cursor (5px)"),label:(0,n.jsx)("div",{className:"cursor-button large"}),onClick:this.clickHandler(5)})]}))}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>{const{dispatchChangeCursorSize:t}=this.props;t(e)}),this.handlers[e]}}const u={dispatchChangeCursorSize:o.dispatchChangeCursorSize};i.CursorSizes=(0,r.connect)(function({editor:e},t){return e?{selected:e.cursorSize}:{}},u)(c)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"./actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],179:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageCanvas=i.ImageCanvasImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/imageReducer"),a=e("./actions/dispatch"),l=e("./util"),c=e("./toolDefinitions"),u=e("../../assets"),h=e("./keyboardShortcuts"),d=e("./ImageEditor"),p="image/x-mkcd-f4",g=[r.TileDrawingMode.Wall];class f extends s.Component{constructor(){super(...arguments),this.cursor=c.ToolCursor.Crosshair,this.zoom=2.5,this.panX=0,this.panY=0,this.hasInteracted=!1,this.tileCache={},this.onKeyDown=e=>{var t,i;if((0,h.areShortcutsEnabled)()&&(this.hasInteracted=!0,!e.repeat)){switch(!e.ctrlKey&&!e.metaKey||"c"!==e.key&&"v"!==e.key||e.stopPropagation(),(e.ctrlKey||e.metaKey)&&"a"===e.key&&this.shouldHandleCanvasShortcut()&&(this.selectAll(),e.preventDefault()),"Escape"==e.key&&(null===(i=null===(t=this.editState)||void 0===t?void 0:t.floating)||void 0===i?void 0:i.image)&&this.shouldHandleCanvasShortcut()&&(this.cancelSelection(),e.preventDefault()),this.lastTool=this.props.tool,e.keyCode){case 18:this.props.dispatchChangeImageTool(r.ImageEditorTool.ColorSelect),e.preventDefault();break;case 32:this.props.dispatchChangeImageTool(r.ImageEditorTool.Pan);break;default:this.lastTool=null}this.updateCursor(!1,!1)}},this.onKeyUp=e=>{null!=this.lastTool&&(this.props.dispatchChangeImageTool(this.lastTool),this.lastTool=null,this.updateCursor(!1,!1))},this.onCopy=e=>{var t,i;if(this.props.tool===r.ImageEditorTool.Marquee&&(null===(i=null===(t=this.editState)||void 0===t?void 0:t.floating)||void 0===i?void 0:i.image))if(e.preventDefault(),this.props.isTilemap)e.clipboardData.setData("application/makecode-tilemap",JSON.stringify((0,l.createTilemapPatchFromFloatingLayer)(this.editState,this.props.tilemapState.tileset)));else{const t=pxt.sprite.bitmapToImageLiteral(this.editState.floating.image,"typescript");e.clipboardData.setData("application/makecode-image",t),e.clipboardData.setData("text/plain",t)}},this.onPaste=e=>{if(this.props.isTilemap){const t=e.clipboardData.getData("application/makecode-tilemap");let i;try{i=JSON.parse(t)}catch(e){}if(!(i&&i.map&&i.layers&&i.tiles))return;return e.preventDefault(),void this.applyTilemapPatch(i)}let t=e.clipboardData.getData("application/makecode-image");if(!t){const i=e.clipboardData.getData("text/plain"),n=/img(`|\(""")[\s\da-f.#tngrpoyw]+(`|"""\))/im.exec(i);n&&(t=n[0])}const i=t&&pxt.sprite.imageLiteralToBitmap(t);i&&i.width&&i.height&&(e.preventDefault(),this.props.tool!==r.ImageEditorTool.Marquee&&this.props.dispatchChangeImageTool(r.ImageEditorTool.Marquee),this.editState.mergeFloatingLayer(),this.editState.setFloatingLayer(i),this.props.dispatchImageEdit(this.editState.toImageState()))},this.preventContextMenu=e=>e.preventDefault()}render(){const e=this.getImageState(),t=!e||e.bitmap.height>e.bitmap.width,i=!this.props.isTilemap&&this.props.tool==r.ImageEditorTool.Marquee;return(0,n.jsx)("div",Object.assign({ref:"canvas-bounds",className:"image-editor-canvas "+(t?"portrait":"landscape"),onContextMenu:this.preventContextMenu,tabIndex:0},{children:(0,n.jsxs)("div",Object.assign({className:"paint-container"},{children:[!this.props.lightMode&&(0,n.jsx)("canvas",{ref:"paint-surface-bg",className:"paint-surface"}),(0,n.jsx)("canvas",{ref:"paint-surface",className:"paint-surface main"}),g.map((e,t)=>(0,n.jsx)("canvas",{ref:`paint-surface-${e.toString()}`,className:"paint-surface overlay "+(this.props.overlayEnabled?"":"hide")},t)),(0,n.jsx)("div",{ref:"floating-layer-border",className:"image-editor-floating-layer"}),i&&(0,n.jsx)("div",{ref:"floating-layer-nw-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-ne-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-se-corner",className:"image-editor-floating-layer-corner"}),i&&(0,n.jsx)("div",{ref:"floating-layer-sw-corner",className:"image-editor-floating-layer-corner"})]}))}))}componentDidMount(){document.activeElement instanceof HTMLElement&&document.activeElement.blur(),this.tileCache={},this.cellWidth=this.props.isTilemap?this.props.tilemapState.tileset.tileWidth:1,this.canvas=this.refs["paint-surface"],this.background=this.refs["paint-surface-bg"],this.floatingLayer=this.refs["floating-layer-border"],this.canvasLayers=g.map(e=>this.refs[`paint-surface-${e.toString()}`]),(0,l.bindGestureEvents)(this.refs["canvas-bounds"],this);const e=this.refs["canvas-bounds"];e.addEventListener("wheel",e=>{this.hasInteracted=!0,this.updateZoom(e.deltaY/30,e.clientX,e.clientY),e.preventDefault()}),e.addEventListener("mousemove",e=>{e.button||(this.hasHover=!0),this.edit||this.updateCursorLocation(e)}),e.addEventListener("mouseout",e=>{this.edit||this.updateCursorLocation(null)}),document.addEventListener("keydown",this.onKeyDown,!0),document.addEventListener("keyup",this.onKeyUp),document.addEventListener("copy",this.onCopy),document.addEventListener("paste",this.onPaste);const t=this.getImageState();this.editState=(0,c.getEditState)(t,this.props.isTilemap,this.props.drawingMode),this.redraw(),this.updateBackground()}componentDidUpdate(){if(!this.edit||!this.editState){const e=this.getImageState();this.editState=(0,c.getEditState)(e,this.props.isTilemap,this.props.drawingMode)}if(this.props.isTilemap||(this.tileCache={}),this.cellWidth=this.props.isTilemap?this.props.tilemapState.tileset.tileWidth:1,this.props.zoomDelta||0===this.props.zoomDelta)return 0===this.props.zoomDelta?this.hasInteracted||this.zoomToCanvas():(this.hasInteracted=!0,this.updateZoom(this.props.zoomDelta)),void this.props.dispatchChangeZoom(null);this.redraw(),this.updateBackground()}componentWillUnmount(){this.tileCache={},document.removeEventListener("keydown",this.onKeyDown,!0),document.removeEventListener("keyup",this.onKeyUp),document.removeEventListener("copy",this.onCopy),document.removeEventListener("paste",this.onPaste)}onClick(e,t){var i,n;this.hasInteracted=!0,this.isPanning()||(document.activeElement instanceof HTMLElement&&document.activeElement!==this.refs["canvas-bounds"]&&document.activeElement.blur(),this.focus(),this.isColorSelect()?this.selectCanvasColor(e,t):(this.updateCursorLocation(e),this.inBounds(this.cursorLocation[0],this.cursorLocation[1])?(this.touchesResize(e.clientX,e.clientY)&&(this.isResizing=!0),this.startEdit(!!t),this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit()):(null===(n=null===(i=this.editState)||void 0===i?void 0:i.floating)||void 0===n?void 0:n.image)&&(this.editState.mergeFloatingLayer(),this.props.dispatchImageEdit(this.editState.toImageState()))))}onDragStart(e,t){this.hasInteracted=!0,this.focus(),this.touchesResize(e.clientX,e.clientY)&&(this.isResizing=!0),this.isPanning()?(this.lastPanX=e.clientX,this.lastPanY=e.clientY,this.updateCursor(!0,!1)):this.isColorSelect()?this.selectCanvasColor(e,t):(this.updateCursorLocation(e),this.startEdit(!!t),this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]))}onDragMove(e){if(this.focus(),this.isPanning()&&null!=this.lastPanX&&null!=this.lastPanY)this.panX+=this.lastPanX-e.clientX,this.panY+=this.lastPanY-e.clientY,this.lastPanX=e.clientX,this.lastPanY=e.clientY,this.updateCursor(!0,!1);else{if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1])}}onDragEnd(e){if(this.isPanning()&&null!=this.lastPanX&&null!=this.lastPanY)this.panX+=this.lastPanX-e.clientX,this.panY+=this.lastPanY-e.clientY,this.lastPanX=void 0,this.lastPanY=void 0,this.updateCursor(!1,!1);else if(this.isResizing){if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit(!1),this.updateCursor(!1,!1)}else{if(!this.edit)return;this.updateCursorLocation(e)&&this.updateEdit(this.cursorLocation[0],this.cursorLocation[1]),this.commitEdit()}this.isResizing=!1}updateCursorLocation(e){if(!e)return this.cursorLocation&&(this.cursorLocation=null,this.props.dispatchChangeCursorLocation(null),this.edit||this.redraw()),!1;if(this.canvas){const t=this.canvas.getBoundingClientRect(),i=Math.floor((e.clientX-t.left)/t.width*this.imageWidth),n=Math.floor((e.clientY-t.top)/t.height*this.imageHeight);return(!this.cursorLocation||i!==this.cursorLocation[0]||n!==this.cursorLocation[1])&&(this.cursorLocation=[i,n,e.clientX,e.clientY],this.hasHover&&this.props.dispatchChangeCursorLocation(this.cursorLocation),this.edit||this.redraw(),this.updateCursor(!!this.edit,this.editState.inFloatingLayer(i,n)),!0)}return this.cursorLocation=[0,0,e.clientX,e.clientY],!1}updateCursor(e,t){const{tool:i}=this.props,n=c.tools.find(e=>e.tool===i);n?t?e?this.updateCursorCore(n.downLayerCursor||n.hoverLayerCursor||n.downCursor||n.hoverCursor):this.updateCursorCore(n.hoverLayerCursor||n.hoverCursor):e?this.updateCursorCore(n.downCursor||n.hoverCursor):this.updateCursorCore(n.hoverCursor):this.updateCursorCore(c.ToolCursor.Default)}updateCursorCore(e){this.cursor=e||c.ToolCursor.Default,this.updateBackground()}startEdit(e){const{tool:t,toolWidth:i,selectedColor:n,backgroundColor:s,drawingMode:o}=this.props,[a,l]=this.cursorLocation;if(this.inBounds(a,l)||this.isResizing){let a=o==r.TileDrawingMode.Wall?2:e?s:n;this.edit=(0,c.getEdit)(t,this.editState,a,i),this.edit.originalImage=this.originalImage,this.edit.start(this.cursorLocation[0],this.cursorLocation[1],this.cursorLocation[2],this.cursorLocation[3],this.editState)}}updateEdit(e,t){this.edit&&(this.edit.inBounds(e,t)||this.isResizing)&&(this.edit.update(e,t),this.redraw())}commitEdit(e=!0){const{dispatchImageEdit:t}=this.props,i=this.getImageState();this.edit&&(this.editState=(0,c.getEditState)(i,this.props.isTilemap,this.props.drawingMode),this.edit.doEdit(this.editState),this.originalImage=e?void 0:this.edit.originalImage,this.edit=void 0,t(this.editState.toImageState()))}redraw(){const{prevFrame:e,onionSkinEnabled:t,selectedColor:i,toolWidth:n,drawingMode:s,tool:o}=this.props,a=this.getImageState(),l=s==r.TileDrawingMode.Wall?2:i;let u=!1;if(this.canvas){if(this.imageWidth=a.bitmap.width,this.imageHeight=a.bitmap.height,u=this.canvas.width!=a.bitmap.width*this.cellWidth||this.canvas.height!=a.bitmap.height*this.cellWidth,this.canvas.width=a.bitmap.width*this.cellWidth,this.canvas.height=a.bitmap.height*this.cellWidth,this.canvasLayers.forEach(e=>{e.width=this.canvas.width/this.cellWidth,e.height=this.canvas.height/this.cellWidth}),t&&e){const t=(0,c.getEditState)(e,this.props.isTilemap,s),i=this.canvas.getContext("2d");i.globalAlpha=.5,this.drawImage(t.image),t.floating&&t.floating.image&&this.drawImage(t.floating.image,t.layerOffsetX,t.layerOffsetY,!0),i.globalAlpha=1}if(this.edit){const i=this.editState.copy();i.setActiveLayer(s),this.edit.doEdit(i),this.drawImage(i.image,0,0,!(!t||!e)),this.drawOverlayLayers(i.overlayLayers),this.redrawFloatingLayer(i)}else if(this.drawImage(this.editState.image,0,0,!(!t||!e)),this.drawOverlayLayers(this.editState.overlayLayers),this.redrawFloatingLayer(this.editState),this.cursorLocation&&this.shouldDrawCursor()){const e=o===r.ImageEditorTool.Erase?0:l;this.drawCursor(this.cursorLocation[0]-(n>>1),this.cursorLocation[1]-(n>>1),n,e)}if(this.background&&(this.background.width!=this.canvas.width<<1||this.background.height!=this.canvas.height<<1)){this.background.width=this.canvas.width<<1,this.background.height=this.canvas.height<<1;const e=this.background.getContext("2d");e.imageSmoothingEnabled=!1,e.fillStyle="#aeaeae",e.fillRect(0,0,this.background.width,this.background.height),e.fillStyle="#dedede";const t=this.imageHeight<<1,i=this.imageWidth<<1;for(let n=0;n<i;n++)for(let i=0;i<t;i++)n+i&1&&e.fillRect(n*this.cellWidth,i*this.cellWidth,this.cellWidth,this.cellWidth)}}u&&this.zoomToCanvas()}drawImage(e,t=0,i=0,n=!1,s=!this.props.lightMode){this.props.isTilemap?this.drawTilemap(e,t,i,n,s):this.drawBitmap(e,t,i,n,s)}redrawFloatingLayer(e,t=!1){const i=this.refs["floating-layer-border"],n=this.refs["floating-layer-nw-corner"],s=this.refs["floating-layer-ne-corner"],o=this.refs["floating-layer-se-corner"],r=this.refs["floating-layer-sw-corner"],a=[n,s,o,r];if(e.floating&&e.floating.image){t||(this.drawImage(e.floating.image,e.layerOffsetX,e.layerOffsetY,!0),e.floating.overlayLayers&&this.drawOverlayLayers(e.floating.overlayLayers,e.layerOffsetX,e.layerOffsetY));const l=this.canvas.getBoundingClientRect(),c=Math.max(e.layerOffsetX,0),u=Math.max(e.layerOffsetY,0),h=Math.min(e.layerOffsetX+e.floating.image.width,e.width),d=Math.min(e.layerOffsetY+e.floating.image.height,e.height),p=l.width/e.width,g=l.height/e.height;i.style.display="",(h-c<1||d-u<1)&&(i.style.display="none");const f=-this.panX+p*c,m=-this.panY+g*u,_=p*(h-c),b=g*(d-u);i.style.left=f+"px",i.style.top=m+"px",i.style.width=_+"px",i.style.height=b+"px",i.style.borderLeft=e.layerOffsetX>=0?"":"none",i.style.borderTop=e.layerOffsetY>=0?"":"none",i.style.borderRight=e.layerOffsetX+e.floating.image.width<=e.width?"":"none",i.style.borderBottom=e.layerOffsetY+e.floating.image.height<=e.height?"":"none";if(null!=n){const e=16,t=3;this.props.isTilemap||(a.forEach(i=>{i.style.display="",i.style.width=e+"px",i.style.height=e+"px",i.style.border=t+"px solid black",i.style.position="absolute",i.style.backgroundColor="white"}),n.style.left=f-e+"px",n.style.top=m-e+"px",n.style.cursor="nw-resize",s.style.left=f+_+"px",s.style.top=m-e+"px",s.style.cursor="ne-resize",o.style.left=f+_+"px",o.style.top=m+b+"px",o.style.cursor="se-resize",r.style.left=f-e+"px",r.style.top=m+b+"px",r.style.cursor="sw-resize")}}else i.style.display="none",a.forEach(e=>{e&&(e.style.display="none")})}drawOverlayLayers(e,t=0,i=0,n=!this.props.lightMode){e&&e.forEach((e,s)=>{this.drawBitmap(e,t,i,!0,n,this.canvasLayers[s])})}drawBitmap(e,t=0,i=0,n=!1,s=!this.props.lightMode,o=this.canvas){const{colors:r}=this.props,a=o.getContext("2d");a.imageSmoothingEnabled=!1;for(let s=0;s<e.width;s++)for(let o=0;o<e.height;o++){const l=e.get(s,o);l?(a.fillStyle=r[l],a.fillRect(s+t,o+i,1,1)):n||a.clearRect(s+t,o+i,1,1)}}generateTile(e,t){if(!t.tiles[e])return null;const i=document.createElement("canvas");return i.width=t.tileWidth,i.height=t.tileWidth,this.drawBitmap(pxt.sprite.Bitmap.fromData(t.tiles[e].bitmap),0,0,!1,!this.props.lightMode,i),this.tileCache[t.tiles[e].id]=i,i}drawTilemap(e,t=0,i=0,n=!1,s=!this.props.lightMode,o=this.canvas){const{tilemapState:{tileset:r}}=this.props,a=o.getContext("2d");let l,c;this.tileCacheRevision!==this.props.tilesetRevision&&(this.tileCache={},this.tileCacheRevision=this.props.tilesetRevision),a.imageSmoothingEnabled=!1,a.fillStyle=d.LIGHT_MODE_TRANSPARENT;for(let o=0;o<e.width;o++)for(let u=0;u<e.height;u++)if(l=e.get(o,u),l&&l<r.tiles.length){if(c=this.tileCache[r.tiles[l].id],c||(c=this.generateTile(l,r)),!c)continue;a.drawImage(c,(o+t)*this.cellWidth,(u+i)*this.cellWidth)}else n||(s?a.clearRect((o+t)*this.cellWidth,(u+i)*this.cellWidth,this.cellWidth,this.cellWidth):a.fillRect((o+t)*this.cellWidth,(u+i)*this.cellWidth,this.cellWidth,this.cellWidth))}drawCursor(e,t,i,n){const s=this.props.isTilemap&&this.props.drawingMode===r.TileDrawingMode.Wall,o=(s?this.canvasLayers[0]:this.canvas).getContext("2d");if(o.imageSmoothingEnabled=!1,n&&-1!==n)if(this.props.isTilemap&&!s){if(n>=this.props.tilemapState.tileset.tiles.length)return;let s=this.tileCache[this.props.tilemapState.tileset.tiles[n].id];if(s||(s=this.generateTile(n,this.props.tilemapState.tileset)),!s)return;for(let n=0;n<i;n++)for(let r=0;r<i;r++)o.drawImage(s,(e+n)*this.cellWidth,(t+r)*this.cellWidth)}else s?(o.fillStyle=this.props.colors[n],o.fillRect(e,t,1,1)):(o.fillStyle=this.props.colors[n],o.fillRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth));else this.props.lightMode?(o.fillStyle=d.LIGHT_MODE_TRANSPARENT,o.fillRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth)):o.clearRect(e*this.cellWidth,t*this.cellWidth,i*this.cellWidth,i*this.cellWidth)}updateBackground(){this.refs["canvas-bounds"].style.cursor=this.cursor,this.canvas.style.cursor=this.cursor,this.updateZoom(0)}updateZoom(e,t,i){const n=this.refs["canvas-bounds"];if(this.canvas&&n){const s=n.getBoundingClientRect();t=void 0===t?s.left+(s.width>>1):t,i=void 0===i?s.top+(s.height>>1):i;const{canvasX:o,canvasY:r}=this.clientToCanvas(t,i,s);this.zoom=Math.max(this.zoom+e,2.5);const a=this.getCanvasUnit(s);if(a){const{canvasX:e,canvasY:n}=this.clientToCanvas(t,i,s);if(isNaN(e)||isNaN(n)||isNaN(o)||isNaN(r))return;this.panX+=(o-e)*a,this.panY+=(r-n)*a}this.applyZoom()}}getCenteredPan(){let[e,t]=[0,0];const i=this.refs["canvas-bounds"].getBoundingClientRect(),n=this.canvas.getBoundingClientRect();return n.width<i.width&&(e=-((i.width>>1)-(n.width>>1))),n.height<i.height&&(t=-((i.height>>1)-(n.height>>1))),[e,t]}zoomToCanvas(){this.zoom=10;const e=this.refs["canvas-bounds"];this.applyZoom(),this.canvas&&e&&([this.panX,this.panY]=this.getCenteredPan()),this.applyZoom()}applyZoom(e){const t=this.refs["canvas-bounds"];if(this.canvas&&t){e=e||t.getBoundingClientRect();const i=this.getCanvasUnit(e);if(0===i){if(this.waitingToZoom)return;return this.waitingToZoom=!0,void requestAnimationFrame(()=>{this.waitingToZoom&&(this.waitingToZoom=!1,this.applyZoom())})}this.waitingToZoom=!1;const n=i*this.imageWidth,s=i*this.imageHeight,o=this.imageWidth>1&&this.imageHeight>1?2*i:i>>1;this.hasInteracted||([this.panX,this.panY]=this.getCenteredPan()),this.panX=Math.max(Math.min(this.panX,n-o),-(e.width-o)),this.panY=Math.max(Math.min(this.panY,s-o),-(e.height-o)),this.canvas.style.position="fixed",this.canvas.style.width=`${n}px`,this.canvas.style.height=`${s}px`,this.canvas.style.left=-this.panX+"px",this.canvas.style.top=-this.panY+"px",this.canvas.style.clipPath=`polygon(${this.panX}px ${this.panY}px, ${this.panX+e.width}px ${this.panY}px, ${this.panX+e.width}px ${this.panY+e.height}px, ${this.panX}px ${this.panY+e.height}px)`,this.background&&this.cloneCanvasStyle(this.canvas,this.background),this.canvasLayers.forEach(e=>this.cloneCanvasStyle(this.canvas,e)),this.redrawFloatingLayer(this.editState,!0)}}selectCanvasColor(e,t){const i=this.refs["canvas-bounds"].getBoundingClientRect();let n,{canvasX:s,canvasY:o}=this.clientToCanvas(e.clientX,e.clientY,i);s=Math.floor(s),o=Math.floor(o),this.editState.inFloatingLayer(s,o)&&(n=this.editState.floating.image.get(s-this.editState.layerOffsetX,o-this.editState.layerOffsetY)),n||(n=this.editState.image.get(s,o)),t?this.props.dispatchChangeBackgroundColor(n):this.props.dispatchChangeSelectedColor(n)}selectAll(){this.props.tool!==r.ImageEditorTool.Marquee&&this.props.dispatchChangeImageTool(r.ImageEditorTool.Marquee),this.editState.mergeFloatingLayer(),this.editState.copyToLayer(0,0,this.imageWidth,this.imageHeight,!0),this.props.dispatchImageEdit(this.editState.toImageState())}cancelSelection(){this.editState.mergeFloatingLayer(),this.props.dispatchImageEdit(this.editState.toImageState())}cloneCanvasStyle(e,t){t.style.position=e.style.position,t.style.width=e.style.width,t.style.height=e.style.height,t.style.left=e.style.left,t.style.top=e.style.top,t.style.clipPath=e.style.clipPath}clientToCanvas(e,t,i){const n=this.getCanvasUnit(i);return{canvasX:(e-i.left+this.panX)/n,canvasY:(t-i.top+this.panY)/n}}getCanvasUnit(e){const t=e.width/e.height,i=this.imageWidth/this.imageHeight,n=Math.pow(this.zoom/10,2);return t>i?n*(e.height/this.imageHeight):n*(e.width/this.imageWidth)}inBounds(e,t){return e>=0&&e<this.imageWidth&&t>=0&&t<this.imageHeight}isPanning(){return this.props.tool===r.ImageEditorTool.Pan}touchesResize(e,t){const i=document.querySelectorAll(":hover");for(let e=0;e<i.length;e++)if("image-editor-floating-layer-corner"==i[e].className)return!0;return!1}isColorSelect(){return this.props.tool===r.ImageEditorTool.ColorSelect}shouldHandleCanvasShortcut(){return!(this.props.suppressShortcuts||document.activeElement instanceof HTMLInputElement)}shouldDrawCursor(){if(!this.hasHover)return!1;switch(this.props.tool){case r.ImageEditorTool.Fill:case r.ImageEditorTool.Marquee:case r.ImageEditorTool.Pan:case r.ImageEditorTool.ColorSelect:return!1;default:return!0}}getImageState(){return this.props.isTilemap?this.props.tilemapState.tilemap:this.props.imageState}applyTilemapPatch(e){const{tilemapState:t,dispatchCreateNewTile:i,gallery:n,backgroundColor:s}=this.props,{tileset:o}=t,r=pxt.sprite.tilemapLiteralToTilemap(e.map);if(!r||!r.width||!r.height)return;const a=e.tiles.map(e=>pxt.sprite.getBitmapFromJResURL(`data:${p};base64,${e}`)),l=e.layers.map(e=>pxt.sprite.getBitmapFromJResURL(`data:${p};base64,${e}`)),c=[];let h=o.tiles.length;for(const e of a){const t=o.tiles.findIndex(t=>e.equals(pxt.sprite.Bitmap.fromData(t.bitmap)));if(t>=0)c.push(t);else{if(n){const t=n.find(t=>e.equals(pxt.sprite.Bitmap.fromData(t.bitmap)));if(t){i(null,o.tiles.length,s,t.qualifiedName),c.push(h),h++;continue}}i((0,u.createTile)(e.data()),o.tiles.length,s),c.push(h),h++}}this.editState.mergeFloatingLayer();const d=new pxt.sprite.Tilemap(r.width,r.height);for(let e=0;e<d.width;e++)for(let t=0;t<d.height;t++)d.set(e,t,c[r.get(e,t)]);this.editState.floating={image:d,overlayLayers:l},this.editState.layerOffsetX=0,this.editState.layerOffsetY=0,this.props.dispatchImageEdit(this.editState.toImageState())}focus(){this.refs["canvas-bounds"].focus()}}i.ImageCanvasImpl=f;const m={dispatchImageEdit:a.dispatchImageEdit,dispatchChangeCursorLocation:a.dispatchChangeCursorLocation,dispatchChangeZoom:a.dispatchChangeZoom,dispatchChangeImageTool:a.dispatchChangeImageTool,dispatchChangeSelectedColor:a.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:a.dispatchChangeBackgroundColor,dispatchCreateNewTile:a.dispatchCreateNewTile};i.ImageCanvas=(0,o.connect)(function({store:{present:e},editor:t},i){if(t.isTilemap){let i=e;return i?{selectedColor:t.selectedColor,tilemapState:i,tool:t.tool,toolWidth:t.cursorSize,zoomDelta:t.zoomDelta,onionSkinEnabled:!1,overlayEnabled:t.overlayEnabled,backgroundColor:t.backgroundColor,colors:i.colors,isTilemap:t.isTilemap,drawingMode:t.drawingMode,gallery:t.tileGallery,tilesetRevision:t.tilesetRevision}:{}}let n=e;return n?{selectedColor:t.selectedColor,colors:n.colors,imageState:n.frames[n.currentFrame],tool:t.tool,toolWidth:t.cursorSize,zoomDelta:t.zoomDelta,onionSkinEnabled:t.onionSkinEnabled,backgroundColor:t.backgroundColor,prevFrame:n.frames[n.currentFrame-1],isTilemap:t.isTilemap,tilesetRevision:t.tilesetRevision}:{}},m)(f)},{"../../assets":174,"./ImageEditor":180,"./actions/dispatch":187,"./keyboardShortcuts":189,"./store/imageReducer":191,"./toolDefinitions":195,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],180:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageEditor=i.LIGHT_MODE_TRANSPARENT=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/imageStore"),a=e("./SideBar"),l=e("./BottomBar"),c=e("./TopBar"),u=e("./ImageCanvas"),h=e("./Alert"),d=e("./Timeline"),p=e("./keyboardShortcuts"),g=e("./actions/dispatch"),f=e("./util"),m=e("../../assets"),_=e("../../../../react-common/components/util"),b=e("./tilemap/TilePalette");i.LIGHT_MODE_TRANSPARENT="#dedede";class T extends s.Component{constructor(e){super(e),this.onStoreChange=()=>{this.props.onChange&&this.props.onChange(this.props.singleFrame?pxt.sprite.bitmapToImageLiteral(this.getCurrentFrame(),"typescript"):"");const e=this.getStore(),t=e.getState();if((0,p.setStore)(e),t.editor&&this.setState({alert:t.editor.alert}),!!t.editor.editingTile!=!!this.state.editingTile)if(t.editor.editingTile){const e=t.editor.editingTile.tilesetIndex;if(e){const i=t.store.present.tileset.tiles[e];this.setState({editingTile:!0,tileToEdit:i})}else{const e=t.store.present.tileset.tileWidth,i=(0,m.createNewImageAsset)("tile",e,e,lf("myTile"));this.setState({editingTile:!0,tileToEdit:i})}this.props.onTileEditorOpenClose&&this.props.onTileEditorOpenClose(!0)}else this.setState({editingTile:!1}),this.props.onTileEditorOpenClose&&this.props.onTileEditorOpenClose(!1)},this.onDoneClick=()=>{this.props.onDoneClicked&&this.props.onDoneClicked(this.getAsset())},this.onTileEditorFinished=e=>{const t=this.getStore().getState().editor.editingTile;e.isProjectTile=!0,this.dispatchOnStore((0,g.dispatchCloseTileEditor)(e,t.tilesetIndex))},this.state={editingTile:!1}}componentDidMount(){(0,p.addKeyListener)(),this.props.asset&&this.openAsset(this.props.asset),this.unsubscribeChangeListener=this.getStore().subscribe(this.onStoreChange),this.onResize()}componentWillUnmount(){this.props.nested||(0,p.removeKeyListener)(),this.unsubscribeChangeListener&&this.unsubscribeChangeListener()}render(){const{singleFrame:e,lightMode:t,hideDoneButton:i,hideAssetName:s}=this.props,p=this.getStore(),{tileToEdit:g,editingTile:f,alert:m}=this.state,b="Animation"===p.getState().store.present.kind;return(0,n.jsxs)("div",Object.assign({className:"image-editor-outer"},{children:[(0,n.jsx)(o.Provider,Object.assign({store:p},{children:(0,n.jsxs)("div",Object.assign({className:(0,_.classList)("image-editor",f&&"editing-tile",i&&"hide-done-button")},{children:[(0,n.jsx)(c.TopBar,{singleFrame:e}),(0,n.jsxs)("div",Object.assign({className:"image-editor-content"},{children:[(0,n.jsx)(a.SideBar,{lightMode:t}),(0,n.jsx)(u.ImageCanvas,{suppressShortcuts:f,lightMode:t}),b&&!e?(0,n.jsx)(d.Timeline,{}):void 0]})),(0,n.jsx)(l.BottomBar,{singleFrame:e,onDoneClick:this.onDoneClick,hideDoneButton:!!i,hideAssetName:!!s}),m&&m.title&&(0,n.jsx)(h.Alert,{title:m.title,text:m.text,options:m.options})]}))})),f&&(0,n.jsx)(T,{store:r.tileEditorStore,ref:"nested-image-editor",onDoneClicked:this.onTileEditorFinished,asset:g,singleFrame:!0,nested:!0,hideAssetName:s})]}))}openAsset(e,t,i=!1){this.dispatchOnStore((0,g.dispatchOpenAsset)(e,i,t)),e.meta.displayName?this.dispatchOnStore((0,g.dispatchChangeAssetName)(e.meta.displayName)):i&&this.dispatchOnStore((0,g.dispatchChangeAssetName)(""))}openGalleryAsset(e){const t=this.getAsset(),i=this.getStore().getState().store.present.frames;switch(t.type){case"animation":switch(e.type){case"image":case"tile":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.bitmap),1===i.length);break;case"animation":this.dispatchOnStore((0,g.dispatchSetFrames)(e.frames.map(e=>({bitmap:e}))))}break;case"image":case"tile":switch(e.type){case"image":case"tile":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.bitmap),!0);break;case"animation":this.setCurrentFrame(pxt.sprite.Bitmap.fromData(e.frames[0]),!0)}break;case"tilemap":if("tilemap"===e.type){const i=t,n=pxt.cloneAsset(e),s=pxt.react.getTilemapProject();pxt.sprite.updateTilemapReferencesFromResult(s,i),this.prepareGalleryTilemapTemplate(s,i,n),n.id=i.id,n.internalID=i.internalID,n.meta=Object.assign({},i.meta);const{tileGallery:o}=this.getStore().getState().editor;this.openAsset(n,o,!1)}}}prepareGalleryTilemapTemplate(e,t,i){this.mergeTilemapTilesIntoProject(e,i),this.mergeCurrentTilemapCustomTilesIntoTileset(e,t,i)}mergeCurrentTilemapCustomTilesIntoTileset(e,t,i){var n,s,o,r,a,l,c,u;const h=null===(s=null===(n=null==t?void 0:t.data)||void 0===n?void 0:n.tileset)||void 0===s?void 0:s.tiles,d=null===(r=null===(o=null==i?void 0:i.data)||void 0===o?void 0:o.tileset)||void 0===r?void 0:r.tiles,p=null===(l=null===(a=null==i?void 0:i.data)||void 0===a?void 0:a.tileset)||void 0===l?void 0:l.tileWidth;if(!(null==h?void 0:h.length)||!d||!p)return;const g=`myTiles.transparency${p}`;for(const t of h){if(!(null==t?void 0:t.isProjectTile))continue;if(t.id===g)continue;if((null===(c=t.bitmap)||void 0===c?void 0:c.width)!==p||(null===(u=t.bitmap)||void 0===u?void 0:u.height)!==p)continue;const i=e.resolveTile(t.id);i&&(d.some(e=>(null==e?void 0:e.id)===i.id)||d.push(i))}}mergeTilemapTilesIntoProject(e,t){var i,n,s,o;const r=null===(n=null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.tileset)||void 0===n?void 0:n.tiles;if(!(null==r?void 0:r.length))return;const a=e=>{var t;const i=(null===(t=null==e?void 0:e.meta)||void 0===t?void 0:t.displayName)||pxt.getShortIDForAsset(e)||(null==e?void 0:e.id);return i?i.split(".").pop():void 0},l={};for(let t=0;t<r.length;t++){let i=r[t];if(!i)continue;const n=i.jresData||(i.bitmap?pxt.sprite.base64EncodeBitmap(i.bitmap):"");if(n&&l[n]){r[t]=l[n];continue}const c=i.bitmap&&e.lookupAssetByValue("tile",i);if(c){if(r[t]=c,n&&(l[n]=c),!(null===(s=c.meta)||void 0===s?void 0:s.displayName)){const t=a(i);if(t){const i=e.generateNewName("tile",t);e.updateTile(Object.assign(Object.assign({},c),{meta:Object.assign(Object.assign({},c.meta),{displayName:i})}))}}continue}const u=e.lookupAsset("tile",i.id);if(u&&(i=u),i.bitmap){if(null===(o=i.meta.tags)||void 0===o?void 0:o.some(e=>e.startsWith("category-")||b.BUILTIN_CATEGORIES.some(t=>t.id===e)))continue;const s=a(i),c=s?e.generateNewName("tile",s):void 0,u=e.createNewTile(i.bitmap,void 0,c);r[t]=u,n&&(l[n]=u)}}}onResize(){this.dispatchOnStore((0,g.dispatchChangeZoom)(0))}getCurrentFrame(){const e=this.getStore().getState().store.present,t=e.frames[e.currentFrame];return(0,f.imageStateToBitmap)(t)}getAsset(){switch(this.getStore().getState().store.present.asset.type){case"tile":return this.getTile();case"animation":return this.getAnimation();case"tilemap":return this.getTilemap();default:return this.getImage()}}getImage(){var e;const t=this.getStore().getState().store.present,i=this.getCurrentFrame().data(),n=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),type:"image",bitmap:i,jresData:pxt.sprite.base64EncodeBitmap(i),meta:n}}getTile(){var e;const t=this.getStore().getState().store.present,i=this.getCurrentFrame().data(),n=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),isProjectTile:!0,type:"tile",bitmap:i,jresData:pxt.sprite.base64EncodeBitmap(i),meta:n}}getAnimation(){var e;const t=this.getStore().getState().store.present,i=t.asset?Object.assign({},t.asset.meta):{};return{id:null===(e=t.asset)||void 0===e?void 0:e.id,internalID:t.asset?t.asset.internalID:(0,m.getNewInternalID)(),type:"animation",interval:t.interval,frames:t.frames.map(e=>(0,f.imageStateToBitmap)(e).data()),meta:i}}getTilemap(){var e;const t=this.getStore().getState(),i=t.store.present,{floating:n,overlayLayers:s,layerOffsetX:o,layerOffsetY:r}=i.tilemap,a=(0,f.applyBitmapData)(pxt.sprite.Bitmap.fromData(s[0]).copy().data(),n&&n.overlayLayers&&n.overlayLayers[0],o,r),l=new pxt.sprite.TilemapData((0,f.imageStateToTilemap)(i.tilemap),i.tileset,a);l.deletedTiles=t.editor.deletedTiles,l.editedTiles=t.editor.editedTiles;const c=i.asset?Object.assign({},i.asset.meta):{};return{id:null===(e=i.asset)||void 0===e?void 0:e.id,internalID:i.asset?i.asset.internalID:(0,m.getNewInternalID)(),type:"tilemap",data:l,meta:c}}getPersistentData(){const e=this.getStore().getState();return{editor:e.editor,past:e.store.past}}restorePersistentData(e){e&&this.dispatchOnStore((0,g.dispatchSetInitialState)(e.editor,e.past))}setCurrentFrame(e,t){if(!t){const t=this.getStore().getState().store.present.frames[0];if(e.width!==t.bitmap.width||e.height!==t.bitmap.height){const i=[Math.max(e.width,t.bitmap.width),Math.max(e.height,t.bitmap.height)];t.bitmap.width===i[0]&&t.bitmap.height===i[1]||this.dispatchOnStore((0,g.dispatchChangeImageDimensions)(i)),e=(e=e.copy()).resize(i[0],i[1])}}this.dispatchOnStore((0,g.dispatchImageEdit)({bitmap:e.data()}))}openInTileEditor(e){this.refs["nested-image-editor"].setCurrentFrame(e,!1)}disableResize(){this.dispatchOnStore((0,g.dispatchDisableResize)())}closeNestedEditor(){var e;this.state.editingTile&&(null===(e=this.refs["nested-image-editor"])||void 0===e||e.onDoneClick())}getJres(){if(this.props.singleFrame){const e=this.getCurrentFrame().data();return pxt.sprite.base64EncodeBitmap(e)}return""}loadJres(e){if(e)try{this.setCurrentFrame(pxt.sprite.getBitmapFromJResURL(e),!0)}catch(e){}}getStore(){return this.props.store||r.mainStore}dispatchOnStore(e){this.getStore().dispatch(e)}}i.ImageEditor=T},{"../../../../react-common/components/util":171,"../../assets":174,"./Alert":176,"./BottomBar":177,"./ImageCanvas":179,"./SideBar":182,"./Timeline":183,"./TopBar":186,"./actions/dispatch":187,"./keyboardShortcuts":189,"./store/imageStore":192,"./tilemap/TilePalette":194,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],181:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Pivot=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./util");class r extends s.Component{constructor(e){super(e),this.handlers=[],this.state={open:!1}}componentWillUnmount(){this.handlers=null}render(){const{options:e,selected:t}=this.props,i=e[t];return(0,n.jsx)("div",Object.assign({className:"image-editor-pivot-outer"},{children:e.map((e,t)=>(0,n.jsx)("div",Object.assign({role:"tab",className:"image-editor-pivot-option "+(e===i?"selected":""),tabIndex:0,onClick:this.clickHandler(t),onKeyDown:o.fireClickOnlyOnEnter},{children:e.text}),e.id))}))}clickHandler(e){if(!this.handlers[e]){const{onChange:t,options:i}=this.props;this.handlers[e]=()=>{this.setState({open:!1}),t(i[e],e)}}return this.handlers[e]}}i.Pivot=r},{"./util":196,react:304,"react/jsx-runtime":305}],182:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SideBar=i.SideBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./toolDefinitions"),a=e("./actions/dispatch"),l=e("./sprite/Palette"),c=e("./tilemap/TilePalette"),u=e("./tilemap/Minimap"),h=e("../../../../react-common/components/controls/Button"),d=e("../../../../react-common/components/util");class p extends s.Component{constructor(){super(...arguments),this.handlers=[]}render(){const{selectedTool:e,isTilemap:t,lightMode:i}=this.props;return(0,n.jsxs)("div",Object.assign({className:"image-editor-sidebar "+(t?"tilemap":"")},{children:[t&&(0,n.jsx)("div",Object.assign({className:"image-editor-tilemap-minimap"},{children:(0,n.jsx)(u.Minimap,{lightMode:i})})),(0,n.jsx)("div",Object.assign({className:"image-editor-tool-buttons"},{children:r.tools.filter(e=>!e.hiddenTool).map(t=>(0,n.jsx)(h.Button,{className:(0,d.classList)("image-editor-button",e!==t.tool&&"toggle"),leftIcon:t.iconClass,title:t.title,onClick:this.clickHandler(t.tool)},t.tool))})),(0,n.jsx)("div",Object.assign({className:"image-editor-palette"},{children:t?(0,n.jsx)(c.TilePalette,{}):(0,n.jsx)(l.Palette,{})}))]}))}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>this.props.dispatchChangeImageTool(e)),this.handlers[e]}}i.SideBarImpl=p;const g={dispatchChangeImageTool:a.dispatchChangeImageTool};i.SideBar=(0,o.connect)(function({editor:e},t){return e?{isTilemap:e.isTilemap,selectedTool:e.tool}:{}},g)(p)},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/util":171,"./actions/dispatch":187,"./sprite/Palette":190,"./tilemap/Minimap":193,"./tilemap/TilePalette":194,"./toolDefinitions":195,react:304,"react-redux":287,"react/jsx-runtime":305}],183:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Timeline=i.TimelineImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("./TimelineFrame"),l=e("./util"),c=e("../../../../react-common/components/controls/Button");class u extends s.Component{constructor(e){super(e),this.handlers=[],this.scrollOffset=0,this.dragEnd=!1,this.duplicateFrame=()=>{const{currentFrame:e,dispatchDuplicateFrame:t}=this.props;t(e)},this.deleteFrame=()=>{const{currentFrame:e,dispatchDeleteFrame:t}=this.props;t(e)},this.newFrame=()=>{const{dispatchNewFrame:e}=this.props;this.dragEnd?this.dragEnd=!1:e()},this.state={}}render(){const{frames:e,colors:t,currentFrame:i,interval:s,previewAnimating:o}=this.props,{isMovingFrame:r,dropPreviewIndex:l}=this.state;let u,h=e.slice();return r&&(u=e[i],h.splice(i,1),h.splice(l,0,null)),(0,n.jsxs)("div",Object.assign({className:"image-editor-timeline "+(pxt.BrowserUtils.isEdge()?"edge":"")},{children:[(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-preview"},{children:(0,n.jsx)(a.TimelineFrame,{frames:o?e:[e[i]],colors:t,interval:s,animating:!0})})),(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-frames-outer"},{children:(0,n.jsxs)("div",Object.assign({className:"image-editor-timeline-frames",ref:"frame-scroller-ref"},{children:[h.map((e,s)=>{const o=!r&&s===i;return e?(0,n.jsx)("div",Object.assign({className:"image-editor-timeline-frame "+(o?"active":""),role:"button",onClick:this.clickHandler(s)},{children:(0,n.jsx)(a.TimelineFrame,{frames:[e],colors:t,showActions:o,duplicateFrame:this.duplicateFrame,deleteFrame:this.deleteFrame})}),s):(0,n.jsx)("div",{className:"image-editor-timeline-frame drop-marker"},s)}),u&&(0,n.jsx)("div",Object.assign({ref:"floating-frame",className:"image-editor-timeline-frame dragging"},{children:(0,n.jsx)(a.TimelineFrame,{frames:[u],colors:t,duplicateFrame:this.duplicateFrame,deleteFrame:this.deleteFrame})})),(0,n.jsx)(c.Button,{className:"image-editor-button add-frame-button toggle",title:lf("Add new frame"),onClick:this.newFrame,leftIcon:"ms-Icon ms-Icon--Add"})]}))}))]}))}componentDidMount(){let e;this.frameScroller=this.refs["frame-scroller-ref"];let t=!1,i=0;(0,l.bindGestureEvents)(this.frameScroller,{onClick:e=>{this.dragEnd=!1},onDragStart:n=>{e=n.clientY,pxt.BrowserUtils.addClass(this.frameScroller,"scrolling");let s=-1;for(let e=0;e<this.frameScroller.childElementCount;e++){const t=this.frameScroller.children.item(e).getBoundingClientRect();if(n.clientY>=t.top&&n.clientY<=t.bottom){s=e,i=n.clientY-t.top;break}}t=s!==this.props.currentFrame},onDragMove:n=>{if(t){this.scrollOffset-=e-n.clientY,e=n.clientY;try{const e=this.frameScroller.getBoundingClientRect(),t=this.frameScroller.parentElement.getBoundingClientRect();e.height>t.height?this.scrollOffset=Math.max(Math.min(this.scrollOffset,0),t.height-e.height-15):this.scrollOffset=0,this.frameScroller.parentElement.scrollTop=-this.scrollOffset}catch(e){}}else this.updateDragDrop(n,i)},onDragEnd:()=>{if(e=null,pxt.BrowserUtils.removeClass(this.frameScroller,"scrolling"),this.dragEnd=!0,this.state.isMovingFrame){const{dispatchMoveFrame:e,currentFrame:t}=this.props;e(t,this.state.dropPreviewIndex),this.setState({isMovingFrame:!1})}}}),this.frameScroller.addEventListener("wheel",e=>{this.scrollOffset-=e.deltaY;try{const e=this.frameScroller.getBoundingClientRect(),t=this.frameScroller.parentElement.getBoundingClientRect();e.height>t.height?this.scrollOffset=Math.max(Math.min(this.scrollOffset,0),t.height-e.height-15):this.scrollOffset=0,this.frameScroller.parentElement.scrollTop=-this.scrollOffset}catch(e){}})}clickHandler(e){return this.handlers[e]||(this.handlers[e]=()=>{const{currentFrame:t,dispatchChangeCurrentFrame:i}=this.props;this.dragEnd?this.dragEnd=!1:e!=t&&i(e)}),this.handlers[e]}updateDragDrop(e,t){this.animHandler?(cancelAnimationFrame(this.animHandler),this.animHandler=void 0):this.lastTimestamp=void 0;const i=this.frameScroller.getBoundingClientRect(),n=e.clientY-i.top-t,s=this.frameScroller.lastElementChild.getBoundingClientRect().height,o=(i.height-s)/this.props.frames.length,r=Math.floor(n/o),a=100,l=this.frameScroller.parentElement.getBoundingClientRect(),c=i.height-l.height;if(c>0&&(Math.abs(l.top-e.clientY)<80?this.animHandler=requestAnimationFrame(i=>{if(!this.state.isMovingFrame||this.frameScroller.parentElement.scrollTop<=0)return;const n=i-(this.lastTimestamp||i);this.lastTimestamp=i;const s=1-Math.abs(l.top-e.clientY)/80,o=(a+400*s)*(n/1e3);this.frameScroller.parentElement.scrollTop=Math.max(0,this.frameScroller.parentElement.scrollTop-o),this.updateDragDrop(e,t)}):Math.abs(l.bottom-e.clientY)<80&&(this.animHandler=requestAnimationFrame(i=>{if(!this.state.isMovingFrame||this.frameScroller.parentElement.scrollTop>=c)return;const n=i-(this.lastTimestamp||i);this.lastTimestamp=i;const s=1-Math.abs(l.bottom-e.clientY)/80,o=(a+400*s)*(n/1e3);this.frameScroller.parentElement.scrollTop=Math.min(c,this.frameScroller.parentElement.scrollTop+o),this.updateDragDrop(e,t)}))),this.state.isMovingFrame){if(this.refs["floating-frame"]){this.refs["floating-frame"].style.top=n+"px",this.state.dropPreviewIndex!==r&&this.setState({dropPreviewIndex:r})}}else this.setState({isMovingFrame:!0,dropPreviewIndex:this.props.currentFrame})}}i.TimelineImpl=u;const h={dispatchDuplicateFrame:r.dispatchDuplicateFrame,dispatchDeleteFrame:r.dispatchDeleteFrame,dispatchChangeCurrentFrame:r.dispatchChangeCurrentFrame,dispatchNewFrame:r.dispatchNewFrame,dispatchMoveFrame:r.dispatchMoveFrame};i.Timeline=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{frames:n.frames,currentFrame:n.currentFrame,colors:n.colors,interval:n.interval,previewAnimating:t.previewAnimating}:{}},h)(u)},{"../../../../react-common/components/controls/Button":159,"./TimelineFrame":184,"./actions/dispatch":187,"./util":196,react:304,"react-redux":287,"react/jsx-runtime":305}],184:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TimelineFrame=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=pxt.BrowserUtils.isEdge()?25:1;class a extends s.Component{constructor(e){super(e),this.state={index:0}}render(){const{frames:e,animating:t,showActions:i,duplicateFrame:s,deleteFrame:r}=this.props,a=e[t?Math.min(Math.max(0,this.state.index),e.length-1):0],l=a.bitmap.height>a.bitmap.width;return(0,n.jsxs)("div",Object.assign({className:"timeline-frame-outer "+(l?"portrait":"landscape")},{children:[(0,n.jsx)("div",{className:"timeline-frame-spacer"}),(0,n.jsx)("canvas",{ref:"preview-canvas"}),(0,n.jsx)("div",{className:"timeline-frame-spacer"}),i&&(0,n.jsxs)("div",Object.assign({className:"timeline-frame-actions"},{children:[(0,n.jsx)(o.Button,{className:"image-editor-button",leftIcon:"ms-Icon ms-Icon--Copy",title:lf("Duplicate Current Frame"),onClick:s}),(0,n.jsx)(o.Button,{className:"image-editor-button",leftIcon:"ms-Icon ms-Icon--Delete",title:lf("Delete Current Frame"),onClick:r})]}))]}))}componentDidMount(){this.canvas=this.refs["preview-canvas"],this.redraw(),this.updateAnimation()}componentDidUpdate(){this.redraw(),this.updateAnimation()}componentWillUnmount(){this.intervalId&&clearInterval(this.intervalId),this.intervalId=void 0}redraw(){if(!this.canvas)return;const{animating:e,frames:t}=this.props,i=t[e?Math.min(Math.max(0,this.state.index),t.length-1):0];this.canvas.height=i.bitmap.height*r,this.canvas.width=i.bitmap.width*r;const n=pxt.sprite.Bitmap.fromData(i.bitmap);if(this.drawBitmap(n),i.floating&&i.floating.bitmap){const e=pxt.sprite.Bitmap.fromData(i.floating.bitmap);this.drawBitmap(e,i.layerOffsetX,i.layerOffsetY,!0)}}updateAnimation(){const{animating:e,interval:t,frames:i}=this.props,n=e&&t>5&&i.length>1;n&&t!==this.intervalcurrent?(this.intervalId&&clearInterval(this.intervalId),this.intervalId=setInterval(()=>this.setState({index:(this.state.index+1)%this.props.frames.length}),t),this.intervalcurrent=t):!n&&this.intervalId&&(clearInterval(this.intervalId),this.intervalId=void 0,this.intervalcurrent=void 0)}drawBitmap(e,t=0,i=0,n=!1){const{colors:s}=this.props,o=this.canvas.getContext("2d");for(let a=0;a<e.width;a++)for(let l=0;l<e.height;l++){const c=e.get(a,l);c?(o.fillStyle=s[c],o.fillRect((a+t)*r,(l+i)*r,r,r)):n||o.clearRect((a+t)*r,(l+i)*r,r,r)}}}i.TimelineFrame=a},{"../../../../react-common/components/controls/Button":159,react:304,"react/jsx-runtime":305}],185:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Toggle=void 0;const n=e("react/jsx-runtime"),s=e("react");class o extends s.Component{constructor(e){super(e),this.checked=!1,this.handleToggleClick=e=>{this.checked=!this.checked,this.props.onChange&&this.props.onChange(e.target.checked)},this.checked=e.initialValue}render(){const{initialValue:e,label:t}=this.props;return(0,n.jsxs)("div",Object.assign({className:"image-editor-toggle-container"},{children:[t&&(0,n.jsx)("span",{children:t}),(0,n.jsxs)("label",Object.assign({className:"image-editor-toggle"},{children:[(0,n.jsx)("input",{type:"checkbox",onClick:this.handleToggleClick,defaultChecked:e,"aria-checked":this.checked}),(0,n.jsx)("span",{className:"image-editor-toggle-switch"})]}))]}))}}i.Toggle=o},{react:304,"react/jsx-runtime":305}],186:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TopBar=i.TopBarImpl=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./actions/dispatch"),a=e("./CursorSizes"),l=e("./Toggle"),c=e("./keyboardShortcuts"),u=e("../../../../react-common/components/controls/Button");class h extends s.Component{constructor(e){super(e),this.togglePreviewAnimating=()=>this.props.dispatchChangePreviewAnimating(!this.props.previewAnimating),this.flipVertical=()=>(0,c.flip)(!0),this.flipHorizontal=()=>(0,c.flip)(!1),this.rotateClockwise=()=>(0,c.rotate)(!0),this.rotateCounterclockwise=()=>(0,c.rotate)(!1),this.handleIntervalChange=e=>{this.setState({interval:e.target.value})},this.handleIntervalBlur=()=>{const{dispatchChangeInterval:e}=this.props,t=parseInt(this.state.interval);isNaN(t)||e(Math.min(Math.max(t,50),1e6)),this.setState({interval:null})},this.state={}}render(){const{interval:e,previewAnimating:t,singleFrame:i,isTilemap:s,dispatchChangeOverlayEnabled:o}=this.props,r=null==this.state.interval?e:this.state.interval;return(0,n.jsxs)("div",Object.assign({className:"image-editor-topbar"},{children:[(0,n.jsx)("div",Object.assign({className:"cursor-group"},{children:(0,n.jsx)(a.CursorSizes,{})})),(0,n.jsx)("div",{className:"image-editor-seperator"}),(0,n.jsxs)("div",Object.assign({className:"image-transform-group"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon flipvertical",title:lf("Flip vertical"),onClick:this.flipVertical}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon fliphorizontal",title:lf("Flip horizontal"),onClick:this.flipHorizontal}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon rotateright",title:lf("Rotate clockwise"),onClick:this.rotateClockwise}),(0,n.jsx)(u.Button,{className:"image-editor-button",leftIcon:"xicon rotateleft",title:lf("Rotate counterclockwise"),onClick:this.rotateCounterclockwise})]})),(0,n.jsx)("div",{className:"spacer"}),!i&&(0,n.jsx)("div",{className:"image-editor-seperator"}),!i&&(0,n.jsxs)("div",Object.assign({className:"timeline-controls"},{children:[(0,n.jsx)(u.Button,{className:"image-editor-button TOGGLE",onClick:this.togglePreviewAnimating,leftIcon:t?"ms-Icon ms-Icon--Stop":"ms-Icon ms-Icon--Play",title:t?lf("Stop Animation Preview"):lf("Play Animation Preview")}),(0,n.jsx)("div",Object.assign({className:"image-editor-interval-label image-editor-label"},{children:(0,n.jsx)("span",{className:"ms-Icon ms-Icon--Clock"})})),(0,n.jsx)("div",Object.assign({className:"image-editor-interval"},{children:(0,n.jsx)("input",{className:"image-editor-input",title:lf("Interval Between Frames (ms)"),value:r,onChange:this.handleIntervalChange,onBlur:this.handleIntervalBlur})}))]})),s&&(0,n.jsx)(l.Toggle,{initialValue:!0,label:lf("Show walls"),onChange:o})]}))}}i.TopBarImpl=h;const d={dispatchChangeInterval:r.dispatchChangeInterval,dispatchChangePreviewAnimating:r.dispatchChangePreviewAnimating,dispatchChangeOverlayEnabled:r.dispatchChangeOverlayEnabled};i.TopBar=(0,o.connect)(function({store:{present:e},editor:t},i){return e?{interval:e.interval,previewAnimating:t.previewAnimating,isTilemap:t.isTilemap}:{}},d)(h)},{"../../../../react-common/components/controls/Button":159,"./CursorSizes":178,"./Toggle":185,"./actions/dispatch":187,"./keyboardShortcuts":189,react:304,"react-redux":287,"react/jsx-runtime":305}],187:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.dispatchSetFrames=i.dispatchOpenAsset=i.dispatchChangeAssetName=i.dispatchDisableResize=i.dispatchDeleteTile=i.dispatchCloseTileEditor=i.dispatchOpenTileEditor=i.dispatchSetGalleryOpen=i.dispatchCreateNewTile=i.dispatchChangeDrawingMode=i.dispatchChangeTilePalettePage=i.dispatchChangeTilePaletteCategory=i.dispatchSetInitialState=i.dispatchChangeBackgroundColor=i.dispatchSwapBackgroundForeground=i.dispatchHideAlert=i.dispatchShowAlert=i.dispatchChangeZoom=i.dispatchChangeOverlayEnabled=i.dispatchToggleOnionSkinEnabled=i.dispatchChangePreviewAnimating=i.dispatchChangeInterval=i.dispatchMoveFrame=i.dispatchChangeCurrentFrame=i.dispatchDuplicateFrame=i.dispatchDeleteFrame=i.dispatchNewFrame=i.dispatchToggleAspectRatioLocked=i.dispatchRedoImageEdit=i.dispatchUndoImageEdit=i.dispatchImageEdit=i.dispatchChangeCursorLocation=i.dispatchChangeKeyModifiers=i.dispatchChangeImageDimensions=i.dispatchChangeSelectedColor=i.dispatchChangeCursorSize=i.dispatchChangeImageTool=void 0;const n=e("./types");i.dispatchChangeImageTool=e=>({type:n.CHANGE_IMAGE_TOOL,tool:e});i.dispatchChangeCursorSize=e=>({type:n.CHANGE_CURSOR_SIZE,cursorSize:e});i.dispatchChangeSelectedColor=e=>({type:n.CHANGE_SELECTED_COLOR,selectedColor:e});i.dispatchChangeImageDimensions=e=>({type:n.CHANGE_IMAGE_DIMENSIONS,imageDimensions:e});i.dispatchChangeKeyModifiers=e=>({type:n.CHANGE_KEY_MODIFIERS,keyModifiers:e});i.dispatchChangeCursorLocation=e=>({type:n.CHANGE_CURSOR_LOCATION,cursorLocation:e});i.dispatchImageEdit=e=>({type:n.IMAGE_EDIT,newState:e});i.dispatchUndoImageEdit=()=>({type:n.UNDO_IMAGE_EDIT});i.dispatchRedoImageEdit=()=>({type:n.REDO_IMAGE_EDIT});i.dispatchToggleAspectRatioLocked=()=>({type:n.TOGGLE_ASPECT_RATIO});i.dispatchNewFrame=e=>({type:n.NEW_FRAME,index:e});i.dispatchDeleteFrame=e=>({type:n.DELETE_FRAME,index:e});i.dispatchDuplicateFrame=e=>({type:n.DUPLICATE_FRAME,index:e});i.dispatchChangeCurrentFrame=e=>({type:n.CHANGE_CURRENT_FRAME,index:e});i.dispatchMoveFrame=(e,t)=>({type:n.MOVE_FRAME,oldIndex:e,newIndex:t});i.dispatchChangeInterval=e=>({type:n.CHANGE_INTERVAL,newInterval:e});i.dispatchChangePreviewAnimating=e=>({type:n.CHANGE_PREVIEW_ANIMATING,animating:e});i.dispatchToggleOnionSkinEnabled=()=>({type:n.TOGGLE_ONION_SKIN_ENABLED});i.dispatchChangeOverlayEnabled=e=>({type:n.CHANGE_OVERLAY_ENABLED,enabled:e});i.dispatchChangeZoom=e=>({type:n.CHANGE_CANVAS_ZOOM,zoom:e});i.dispatchShowAlert=(e,t,i)=>({type:n.SHOW_ALERT,title:e,text:t,options:i});i.dispatchHideAlert=()=>({type:n.HIDE_ALERT});i.dispatchSwapBackgroundForeground=()=>({type:n.SWAP_FOREGROUND_BACKGROUND});i.dispatchChangeBackgroundColor=e=>({type:n.CHANGE_BACKGROUND_COLOR,backgroundColor:e});i.dispatchSetInitialState=(e,t)=>({type:n.SET_INITIAL_STATE,state:e,past:t});i.dispatchChangeTilePaletteCategory=e=>({type:n.CHANGE_TILE_PALETTE_CATEGORY,category:e});i.dispatchChangeTilePalettePage=e=>({type:n.CHANGE_TILE_PALETTE_PAGE,page:e});i.dispatchChangeDrawingMode=e=>({type:n.CHANGE_DRAWING_MODE,drawingMode:e});i.dispatchCreateNewTile=(e,t,i,s)=>({type:n.CREATE_NEW_TILE,tile:e,foreground:t,background:i,qualifiedName:s});i.dispatchSetGalleryOpen=e=>({type:n.SET_GALLERY_OPEN,open:e});i.dispatchOpenTileEditor=(e,t)=>({type:n.OPEN_TILE_EDITOR,index:e,id:t});i.dispatchCloseTileEditor=(e,t)=>({type:n.CLOSE_TILE_EDITOR,result:e,index:t});i.dispatchDeleteTile=(e,t)=>({type:n.DELETE_TILE,id:t,index:e});i.dispatchDisableResize=()=>({type:n.DISABLE_RESIZE});i.dispatchChangeAssetName=e=>({type:n.CHANGE_ASSET_NAME,name:e});i.dispatchOpenAsset=(e,t,i)=>({type:n.OPEN_ASSET,asset:e,keepPast:t,gallery:i});i.dispatchSetFrames=(e,t)=>({type:n.SET_FRAMES,frames:e,currentFrame:t})},{"./types":188}],188:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.OPEN_ASSET=i.CHANGE_ASSET_NAME=i.DISABLE_RESIZE=i.DELETE_TILE=i.CLOSE_TILE_EDITOR=i.OPEN_TILE_EDITOR=i.CREATE_NEW_TILE=i.CHANGE_DRAWING_MODE=i.CHANGE_TILE_PALETTE_CATEGORY=i.CHANGE_TILE_PALETTE_PAGE=i.CHANGE_BACKGROUND_COLOR=i.SWAP_FOREGROUND_BACKGROUND=i.HIDE_ALERT=i.SHOW_ALERT=i.CHANGE_CANVAS_ZOOM=i.CHANGE_OVERLAY_ENABLED=i.TOGGLE_ONION_SKIN_ENABLED=i.CHANGE_PREVIEW_ANIMATING=i.CHANGE_INTERVAL=i.CHANGE_CURRENT_FRAME=i.MOVE_FRAME=i.DUPLICATE_FRAME=i.DELETE_FRAME=i.NEW_FRAME=i.SET_GALLERY_OPEN=i.TOGGLE_ASPECT_RATIO=i.REDO_IMAGE_EDIT=i.UNDO_IMAGE_EDIT=i.IMAGE_EDIT=i.CHANGE_CURSOR_LOCATION=i.CHANGE_KEY_MODIFIERS=i.CHANGE_IMAGE_DIMENSIONS=i.CHANGE_SELECTED_COLOR=i.CHANGE_CURSOR_SIZE=i.CHANGE_IMAGE_TOOL=i.SET_FRAMES=i.SET_INITIAL_STATE=void 0,i.SET_INITIAL_STATE="SET_INITIAL_STATE",i.SET_FRAMES="SET_FRAMES",i.CHANGE_IMAGE_TOOL="CHANGE_IMAGE_TOOL",i.CHANGE_CURSOR_SIZE="CHANGE_CURSOR_SIZE",i.CHANGE_SELECTED_COLOR="CHANGE_SELECTED_COLOR",i.CHANGE_IMAGE_DIMENSIONS="CHANGE_IMAGE_DIMENSIONS",i.CHANGE_KEY_MODIFIERS="CHANGE_KEY_MODIFIERS",i.CHANGE_CURSOR_LOCATION="CHANGE_CURSOR_LOCATION",i.IMAGE_EDIT="IMAGE_EDIT",i.UNDO_IMAGE_EDIT="UNDO_IMAGE_EDIT",i.REDO_IMAGE_EDIT="REDO_IMAGE_EDIT",i.TOGGLE_ASPECT_RATIO="TOGGLE_ASPECT_RATIO",i.SET_GALLERY_OPEN="SET_GALLERY_OPEN",i.NEW_FRAME="NEW_FRAME",i.DELETE_FRAME="DELETE_FRAME",i.DUPLICATE_FRAME="DUPLICATE_FRAME",i.MOVE_FRAME="MOVE_FRAME",i.CHANGE_CURRENT_FRAME="CHANGE_CURRENT_FRAME",i.CHANGE_INTERVAL="CHANGE_INTERVAL",i.CHANGE_PREVIEW_ANIMATING="CHANGE_PREVIEW_ANIMATING",i.TOGGLE_ONION_SKIN_ENABLED="TOGGLE_ONION_SKIN_ENABLED",i.CHANGE_OVERLAY_ENABLED="CHANGE_OVERLAY_ENABLED",i.CHANGE_CANVAS_ZOOM="CHANGE_CANVAS_ZOOM",i.SHOW_ALERT="SHOW_ALERT",i.HIDE_ALERT="HIDE_ALERT",i.SWAP_FOREGROUND_BACKGROUND="SWAP_FOREGROUND_BACKGROUND",i.CHANGE_BACKGROUND_COLOR="CHANGE_BACKGROUND_COLOR",i.CHANGE_TILE_PALETTE_PAGE="CHANGE_TILE_PALETTE_PAGE",i.CHANGE_TILE_PALETTE_CATEGORY="CHANGE_TILE_PALETTE_CATEGORY",i.CHANGE_DRAWING_MODE="CHANGE_DRAWING_MODE",i.CREATE_NEW_TILE="CREATE_NEW_TILE",i.OPEN_TILE_EDITOR="OPEN_TILE_EDITOR",i.CLOSE_TILE_EDITOR="CLOSE_TILE_EDITOR",i.DELETE_TILE="DELETE_TILE",i.DISABLE_RESIZE="DISABLE_RESIZE",i.CHANGE_ASSET_NAME="CHANGE_ASSET_NAME",i.OPEN_ASSET="OPEN_ASSET"},{}],189:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.moveFrame=i.advanceFrame=i.replaceColor=i.outline=i.rotateAllFrames=i.rotate=i.flipAllFrames=i.flip=i.setStore=i.areShortcutsEnabled=i.releaseShortcutLock=i.obtainShortcutLock=i.removeKeyListener=i.addKeyListener=void 0;const n=e("./store/imageReducer"),s=e("./actions/dispatch"),o=e("./store/imageStore"),r=e("./toolDefinitions");let a=o.mainStore,l=[];function c(){return!l.length}function u(e){const t=e.ctrlKey||e.metaKey;"Undo"===e.key||t&&"z"===e.key&&!e.shiftKey?(m((0,s.dispatchUndoImageEdit)()),e.preventDefault(),e.stopPropagation()):("Redo"===e.key||t&&"y"===e.key||t&&"Z"===e.key&&e.shiftKey)&&(m((0,s.dispatchRedoImageEdit)()),e.preventDefault(),e.stopPropagation())}function h(e){"Backspace"!==e.key&&"Delete"!==e.key||(d(e),e.stopPropagation())}function d(e){if(!c())return;if(e.shiftKey&&/^(?:Digit[1-9])|(?:Key[A-F])$/.test(e.code))return void(0==e.code.indexOf("Digit")?y(parseInt(e.code.substring(5))):y(parseInt(e.code.substring(3),16)));switch(e.key){case"e":g(n.ImageEditorTool.Erase);break;case"q":g(n.ImageEditorTool.Pan);break;case"b":case"p":g(n.ImageEditorTool.Paint);break;case"g":g(n.ImageEditorTool.Fill);break;case"m":g(n.ImageEditorTool.Marquee);break;case"u":g(n.ImageEditorTool.Rect);break;case"l":g(n.ImageEditorTool.Line);break;case"c":g(n.ImageEditorTool.Circle);break;case"-":case"_":f(-1);break;case"=":case"+":f(1);break;case"x":m((0,s.dispatchSwapBackgroundForeground)());break;case"h":b(!1);break;case"v":b(!0);break;case"H":T(!1);break;case"V":T(!0);break;case"[":E(!1);break;case"]":E(!0);break;case"{":v(!1);break;case"}":v(!0);break;case">":_(!0);break;case"<":_(!1);break;case".":C(!0);break;case",":C(!1);break;case"PageDown":I(!0,e.shiftKey);break;case"PageUp":I(!1,e.shiftKey);break;case"r":k();break;case"R":!function(){const e=a.getState(),t=e.editor.backgroundColor,i=e.editor.selectedColor;if(t===i)return;S(k,e=>(0,r.replaceColorEdit)(e,t,i))}();break;case"ArrowLeft":A(-1,0,e.shiftKey);break;case"ArrowRight":A(1,0,e.shiftKey);break;case"ArrowUp":A(0,-1,e.shiftKey);break;case"ArrowDown":A(0,1,e.shiftKey);break;case"Backspace":case"Delete":O(e.shiftKey)}if(!a.getState().editor.isTilemap&&/^Digit\d$/.test(e.code)){const i=+e.code.slice(-1)+(e.shiftKey?9:0);i>=0&&i<16&&(t=i,m((0,s.dispatchChangeSelectedColor)(t)))}var t}function p(){const e=a.getState();if(e.editor.isTilemap){const t=e.store.present;return[(0,r.getEditState)(t.tilemap,!0,e.editor.drawingMode),"tilemap"]}{const t=e.store.present;return[(0,r.getEditState)(t.frames[t.currentFrame],!1,e.editor.drawingMode),t.frames.length>1?"animation":"image"]}}function g(e){m((0,s.dispatchChangeImageTool)(e))}function f(e){m((0,s.dispatchChangeZoom)(e))}function m(e){a.dispatch(e)}function _(e){let t;const i=a.getState().editor.cursorSize;switch(i){case 1:t=e?3:1;break;case 3:t=e?5:1;break;case 5:t=e?5:3}i!==t&&m((0,s.dispatchChangeCursorSize)(t))}function b(e){const[t,i]=p(),n=(0,r.flipEdit)(t,e,"tilemap"===i);m((0,s.dispatchImageEdit)(n.toImageState()))}function T(e){S(()=>b(e),t=>(0,r.flipEdit)(t,e,!1))}function E(e){const[t,i]=p(),n=(0,r.rotateEdit)(t,e,"tilemap"===i,"animation"===i);m((0,s.dispatchImageEdit)(n.toImageState()))}function v(e){S(()=>E(e),t=>(0,r.rotateEdit)(t,e,!1,!0))}function y(e){const[t,i]=p();if("tilemap"===i)return;const n=(0,r.outlineEdit)(t,e);m((0,s.dispatchImageEdit)(n.toImageState()))}function k(){const e=a.getState(),t=e.editor.backgroundColor,i=e.editor.selectedColor;if(t===i)return;const[n]=p(),o=(0,r.replaceColorEdit)(n,t,i);m((0,s.dispatchImageEdit)(o.toImageState()))}function C(e){const t=a.getState();if(t.editor.isTilemap)return;const i=t.store.present;if(i.frames.length<=1)return;let n;n=e?(i.currentFrame+1)%i.frames.length:(i.currentFrame+i.frames.length-1)%i.frames.length,m((0,s.dispatchChangeCurrentFrame)(n))}function I(e,t=!1){const i=a.getState();if(i.editor.isTilemap)return;const n=i.store.present;if(n.frames.length<=1)return;let o;o=e?(n.currentFrame+1)%n.frames.length:(n.currentFrame+n.frames.length-1)%n.frames.length;const r=n.frames.slice();if(t)e?r.unshift(r.pop()):r.push(r.shift());else{const e=r[n.currentFrame];r.splice(n.currentFrame,1),r.splice(o,0,e)}m((0,s.dispatchSetFrames)(r,o))}function S(e,t){var i,n,o;const l=a.getState();if(l.editor.isTilemap)return void e();const c=l.store.present;if(1===c.frames.length)return void e();const u=c.frames[c.currentFrame],h=!!u.floating,d=null===(i=u.floating)||void 0===i?void 0:i.bitmap.width,p=null===(n=u.floating)||void 0===n?void 0:n.bitmap.height,g=u.layerOffsetX,f=u.layerOffsetY,_=[];for(const e of c.frames){const i=(0,r.getEditState)(e,!1);h?(null===(o=i.floating)||void 0===o?void 0:o.image)?i.layerOffsetX===g&&i.layerOffsetY===f&&i.floating.image.width===d&&i.floating.image.height===p||(i.mergeFloatingLayer(),i.copyToLayer(g,f,d,p,!0)):i.copyToLayer(g,f,d,p,!0):i.mergeFloatingLayer();const n=t(i);_.push(n.toImageState())}m((0,s.dispatchSetFrames)(_,c.currentFrame))}function A(e,t,i=!1){var n;const[o]=p();if(!(null===(n=o.floating)||void 0===n?void 0:n.image))return;const r=i=>(i.layerOffsetX+=e,i.layerOffsetY+=t,i);i?S(()=>A(e,t),r):m((0,s.dispatchImageEdit)(r(o).toImageState()))}function O(e=!1){var t;const[i]=p();if(!(null===(t=i.floating)||void 0===t?void 0:t.image))return;const n=e=>(e.floating=null,e);e?S(()=>O(),n):m((0,s.dispatchImageEdit)(n(i).toImageState()))}i.addKeyListener=function(){l=[],document.addEventListener("keydown",d),document.addEventListener("keydown",u,!0),document.addEventListener("keydown",h,!0)},i.removeKeyListener=function(){document.removeEventListener("keydown",d),document.removeEventListener("keydown",u,!0),document.removeEventListener("keydown",h,!0)},i.obtainShortcutLock=function(){let e=0;for(;!e;)e=Math.random()*Number.MAX_SAFE_INTEGER;return l.push(e),e},i.releaseShortcutLock=function(e){const t=l.indexOf(e);-1!==t&&l.splice(t,1)},i.areShortcutsEnabled=c,i.setStore=function(e){a=e||o.mainStore},i.flip=b,i.flipAllFrames=T,i.rotate=E,i.rotateAllFrames=v,i.outline=y,i.replaceColor=function(e,t){const[i,n]=p(),o=(0,r.replaceColorEdit)(i,e,t);m((0,s.dispatchImageEdit)(o.toImageState()))},i.advanceFrame=C,i.moveFrame=I},{"./actions/dispatch":187,"./store/imageReducer":191,"./store/imageStore":192,"./toolDefinitions":195}],190:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Palette=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../actions/dispatch"),a=e("../../../../../react-common/components/controls/Button"),l=e("../../../../../react-common/components/util");class c extends s.Component{constructor(){super(...arguments),this.preventContextMenu=e=>e.preventDefault()}render(){const{colors:e,selected:t,backgroundColor:i,dispatchSwapBackgroundForeground:s}=this.props,o=10;return(0,n.jsxs)("div",{children:[(0,n.jsxs)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",className:"image-editor-colors",viewBox:"0 0 23 15",onClick:s},{children:[(0,n.jsx)("defs",{children:(0,n.jsxs)("pattern",Object.assign({id:"alpha-background",width:"6",height:"6",patternUnits:"userSpaceOnUse"},{children:[(0,n.jsx)("rect",{x:"0",y:"0",width:"6px",height:"6px",fill:"#aeaeae"}),(0,n.jsx)("rect",{x:"0",y:"0",width:"3px",height:"3px",fill:"#dedede"}),(0,n.jsx)("rect",{x:"3",y:"3",width:"3px",height:"3px",fill:"#dedede"})]}))}),(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",Object.assign({fill:i?e[i]:"url(#alpha-background)",x:6,y:4,width:15,height:o,stroke:"#3c3c3c",strokeWidth:"0.5"},{children:(0,n.jsx)("title",{children:u(i,e[i])})})),(0,n.jsx)("rect",Object.assign({fill:t?e[t]:"url(#alpha-background)",x:2,y:1,width:15,height:o,stroke:"#3c3c3c",strokeWidth:"0.5"},{children:(0,n.jsx)("title",{children:u(t,e[t])})}))]})]})),(0,n.jsx)("div",Object.assign({className:"image-editor-color-buttons",onContextMenu:this.preventContextMenu},{children:this.props.colors.map((e,t)=>(0,n.jsx)(a.Button,{className:(0,l.classList)("image-editor-button",0===t&&"checkerboard"),title:u(t,e),style:0===t?null:{"--preview-color":e},onClick:()=>this.props.dispatchChangeSelectedColor(t),onRightClick:()=>this.props.dispatchChangeBackgroundColor(t)},t))}))]})}}function u(e,t){const i=0===e?lf("transparency"):function(e){switch(null==e?void 0:e.toLowerCase()){case"#ffffff":return lf("white");case"#ff2121":return lf("red");case"#ff93c4":return lf("pink");case"#ff8135":return lf("orange");case"#fff609":return lf("yellow");case"#249ca3":return lf("teal");case"#78dc52":return lf("green");case"#003fad":return lf("blue");case"#87f2ff":return lf("light blue");case"#8e2ec4":return lf("purple");case"#a4839f":return lf("light purple");case"#5c406c":return lf("dark purple");case"#e5cdc4":return lf("tan");case"#91463d":return lf("brown");case"#000000":return lf("black");default:return}}(t);return i?lf("Color {0} ({1})",e,i):lf("Color {0}",e)}const h={dispatchChangeSelectedColor:r.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:r.dispatchChangeBackgroundColor,dispatchSwapBackgroundForeground:r.dispatchSwapBackgroundForeground};i.Palette=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{selected:t.selectedColor,backgroundColor:t.backgroundColor,colors:n.colors}:{}},h)(c)},{"../../../../../react-common/components/controls/Button":159,"../../../../../react-common/components/util":171,"../actions/dispatch":187,react:304,"react-redux":287,"react/jsx-runtime":305}],191:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.setTelemetryFunction=i.TileDrawingMode=i.TileCategory=i.KeyModifiers=i.CursorSize=i.ImageEditorTool=void 0;const n=e("../../../assets"),s=e("../actions/types");var o,r,a;!function(e){e[e.Paint=0]="Paint",e[e.Fill=1]="Fill",e[e.Line=2]="Line",e[e.Erase=3]="Erase",e[e.Circle=4]="Circle",e[e.Rect=5]="Rect",e[e.ColorSelect=6]="ColorSelect",e[e.Marquee=7]="Marquee",e[e.Pan=8]="Pan"}(o=i.ImageEditorTool||(i.ImageEditorTool={})),function(e){e[e.One=1]="One",e[e.Three=3]="Three",e[e.Five=5]="Five"}(i.CursorSize||(i.CursorSize={})),function(e){e[e.Alt=1]="Alt",e[e.Shift=2]="Shift"}(i.KeyModifiers||(i.KeyModifiers={})),function(e){e[e.Forest=0]="Forest",e[e.Aquatic=1]="Aquatic",e[e.Dungeon=2]="Dungeon",e[e.Misc=3]="Misc"}(r=i.TileCategory||(i.TileCategory={})),function(e){e.Default="default",e.Wall="wall"}(a=i.TileDrawingMode||(i.TileDrawingMode={}));const l={kind:"Animation",visible:!0,colors:["#000000","#ffffff","#ff2121","#ff93c4","#ff8135","#fff609","#249ca3","#78dc52","#003fad","#87f2ff","#8e2ec4","#a4839f","#5c406c","#e5cdc4","#91463d","#000000"],aspectRatioLocked:!1,currentFrame:0,frames:[f(16,16)],interval:200};let c=1;const u={store:{present:l,past:[],future:[]},editor:{selectedColor:3,tool:o.Paint,cursorSize:1,backgroundColor:1,previewAnimating:!1,onionSkinEnabled:!1,overlayEnabled:!0,tilesetRevision:0,isTilemap:!1}},h=(e,t)=>{switch(t.type){case s.TOGGLE_ASPECT_RATIO:return _("toggle-aspect-ratio-lock"),Object.assign(Object.assign({},e),{aspectRatioLocked:!e.aspectRatioLocked});case s.CHANGE_CURRENT_FRAME:return _("change-frame"),Object.assign(Object.assign({},e),{currentFrame:t.index});case s.CHANGE_INTERVAL:return _("change-interval"),Object.assign(Object.assign({},e),{interval:t.newInterval});case s.CHANGE_IMAGE_DIMENSIONS:_("change-dimensions");const[i,n]=t.imageDimensions;return Object.assign(Object.assign({},e),{frames:e.frames.map((e,t)=>Object.assign(Object.assign({},e),{bitmap:pxt.sprite.Bitmap.fromData(e.bitmap).resize(i,n).data()}))});case s.IMAGE_EDIT:return _("image-edit"),Object.assign(Object.assign({},e),{frames:e.frames.map((i,n)=>n===e.currentFrame?t.newState:i)});case s.DELETE_FRAME:if(1===e.frames.length)return e;_("delete-frame");const o=e.frames.slice();o.splice(t.index,1);let r=e.currentFrame;return e.currentFrame>=t.index&&e.currentFrame>0&&r--,Object.assign(Object.assign({},e),{currentFrame:r,frames:o});case s.DUPLICATE_FRAME:_("duplicate-frame");const a=e.frames.slice();return a.splice(t.index,0,function(e){let t,i,n;e.floating&&(e.floating.bitmap&&(i=pxt.sprite.Bitmap.fromData(e.floating.bitmap).copy().data()),e.floating.overlayLayers&&(n=e.floating.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy().data())),t={bitmap:i,overlayLayers:n});return Object.assign(Object.assign({},e),{bitmap:pxt.sprite.Bitmap.fromData(e.bitmap).copy().data(),overlayLayers:e.overlayLayers&&e.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy().data()),floating:t})}(e.frames[t.index])),Object.assign(Object.assign({},e),{frames:a,currentFrame:t.index+1});case s.NEW_FRAME:return _("new-frame"),Object.assign(Object.assign({},e),{frames:[...e.frames,f(e.frames[0].bitmap.width,e.frames[0].bitmap.height)],currentFrame:e.frames.length});case s.MOVE_FRAME:if(t.newIndex<0||t.newIndex>=e.frames.length||t.newIndex<0||t.newIndex>=e.frames.length)return e;_("move-frame");const l=e.frames.slice(),c=l.splice(t.oldIndex,1)[0];return l.splice(t.newIndex,0,c),Object.assign(Object.assign({},e),{frames:l,currentFrame:t.oldIndex===e.currentFrame?t.newIndex:e.currentFrame});case s.SET_FRAMES:return _("set-frames"),Object.assign(Object.assign({},e),{frames:t.frames,currentFrame:t.currentFrame||0});default:return e}},d=(e,t,i)=>{let n;switch(t.type){case s.CHANGE_PREVIEW_ANIMATING:return _("preview-animate-"+(t.animating?"on":"off")),Object.assign(Object.assign({},e),{previewAnimating:t.animating});case s.CHANGE_CANVAS_ZOOM:return(t.zoom>0||t.zoom<0)&&_("zoom-"+(t.zoom>0?"in":"out")),Object.assign(Object.assign({},e),{zoomDelta:t.zoom});case s.CHANGE_IMAGE_TOOL:return _(`change-tool-${o[t.tool]}`),Object.assign(Object.assign({},e),{tool:t.tool});case s.CHANGE_CURSOR_SIZE:return _(`change-cursor-size-${t.cursorSize}`),Object.assign(Object.assign({},e),{cursorSize:t.cursorSize});case s.CHANGE_SELECTED_COLOR:return _(`foreground-color-${t.selectedColor}`),Object.assign(Object.assign({},e),{selectedColor:t.selectedColor,tool:e.tool===o.Erase?o.Paint:e.tool});case s.CHANGE_CURSOR_LOCATION:return Object.assign(Object.assign({},e),{cursorLocation:t.cursorLocation});case s.CHANGE_BACKGROUND_COLOR:return _(`background-color-${t.backgroundColor}`),Object.assign(Object.assign({},e),{backgroundColor:t.backgroundColor});case s.SWAP_FOREGROUND_BACKGROUND:return _("swap-foreground-background"),Object.assign(Object.assign({},e),{backgroundColor:e.selectedColor,selectedColor:e.backgroundColor});case s.TOGGLE_ONION_SKIN_ENABLED:return _("toggle-onion-skin"),Object.assign(Object.assign({},e),{onionSkinEnabled:!e.onionSkinEnabled});case s.CHANGE_TILE_PALETTE_CATEGORY:return _(`change-tile-category-${r[t.category]}`),Object.assign(Object.assign({},e),{tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{category:t.category,page:0})});case s.CHANGE_TILE_PALETTE_PAGE:return _("change-tile-page"),Object.assign(Object.assign({},e),{tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{page:t.page})});case s.CHANGE_DRAWING_MODE:return _("change-drawing-mode"),Object.assign(Object.assign({},e),{drawingMode:t.drawingMode||a.Default});case s.CHANGE_OVERLAY_ENABLED:return _("change-overlay-enabled"),Object.assign(Object.assign({},e),{overlayEnabled:t.enabled});case s.CREATE_NEW_TILE:return n=e.editedTiles,!t.tile||n&&-1!==n.indexOf(t.tile.id)||(n=(n||[]).concat([t.tile.id])),Object.assign(Object.assign({},e),{editedTiles:n,selectedColor:t.foreground,backgroundColor:t.background});case s.SET_GALLERY_OPEN:return _(`set-gallery-open-${t.open}`),Object.assign(Object.assign({},e),{tileGalleryOpen:t.open,tilemapPalette:Object.assign(Object.assign({},e.tilemapPalette),{page:0})});case s.DELETE_TILE:return Object.assign(Object.assign({},e),{deletedTiles:(e.deletedTiles||[]).concat([t.id]),selectedColor:t.index===e.selectedColor?0:e.selectedColor,backgroundColor:t.index===e.backgroundColor?0:e.backgroundColor,tilesetRevision:c++});case s.OPEN_TILE_EDITOR:const l=t.index?"edit":"new";return _(`open-tile-editor-${l}`),Object.assign(Object.assign({},e),{editingTile:{type:l,tilesetIndex:t.index}});case s.CLOSE_TILE_EDITOR:return n=e.editedTiles,!t.result||n&&-1!==n.indexOf(t.result.id)||(n=(n||[]).concat([t.result.id])),Object.assign(Object.assign({},e),{editedTiles:n,selectedColor:t.index||i.present.tileset.tiles.length,editingTile:void 0,tilesetRevision:c++});case s.SHOW_ALERT:return _("show-alert"),Object.assign(Object.assign({},e),{alert:{title:t.title,text:t.text,options:t.options}});case s.HIDE_ALERT:return _("hide-alert"),Object.assign(Object.assign({},e),{alert:null});case s.DISABLE_RESIZE:return Object.assign(Object.assign({},e),{resizeDisabled:!0})}return e},p=(e,t)=>{switch(t.type){case s.TOGGLE_ASPECT_RATIO:return _("toggle-aspect-ratio-lock"),Object.assign(Object.assign({},e),{aspectRatioLocked:!e.aspectRatioLocked});case s.CHANGE_IMAGE_DIMENSIONS:_("change-dimensions");const[a,l]=t.imageDimensions;return Object.assign(Object.assign({},e),{tilemap:Object.assign(Object.assign({},e.tilemap),{bitmap:(i=e.tilemap.bitmap,o=a,r=l,pxt.sprite.Tilemap.fromData(i).resize(o,r).data()),overlayLayers:e.tilemap.overlayLayers&&e.tilemap.overlayLayers.map(e=>function(e,t,i){return pxt.sprite.Bitmap.fromData(e).resize(t,i).data()}(e,a,l))})});case s.CREATE_NEW_TILE:const c=!t.qualifiedName;let u;return _(c?"new-tile":`used-tile-${t.qualifiedName}`),c?(u=t.tile,u.isProjectTile=!0):u=(0,n.lookupAsset)("tile",t.qualifiedName),Object.assign(Object.assign({},e),{tileset:Object.assign(Object.assign({},e.tileset),{tiles:e.tileset.tiles.concat([u])}),nextId:c?e.nextId+1:e.nextId});case s.CLOSE_TILE_EDITOR:return _("close-tile-editor"),t.result?t.index?Object.assign(Object.assign({},e),{tileset:g(e.tileset,t.index,t.result)}):Object.assign(Object.assign({},e),{tileset:Object.assign(Object.assign({},e.tileset),{tiles:e.tileset.tiles.concat([t.result])}),nextId:e.nextId+1}):e;case s.DELETE_TILE:_("delete-tile");const h=e.tileset.tiles.slice();return h.splice(t.index,1),Object.assign(Object.assign({},e),{tilemap:Object.assign(Object.assign({},e.tilemap),{bitmap:T(t.index,pxt.sprite.Tilemap.fromData(e.tilemap.bitmap)).data()}),tileset:Object.assign(Object.assign({},e.tileset),{tiles:h})});case s.IMAGE_EDIT:return _("image-edit"),Object.assign(Object.assign({},e),{tilemap:t.newState});default:return e}var i,o,r};function g(e,t,i){return Object.assign(Object.assign({},e),{tiles:e.tiles.map((e,n)=>n===t?i:e)})}function f(e,t){return{bitmap:new pxt.sprite.Bitmap(e,t).data()}}let m;function _(e){m&&m(e)}function b(e,t){for(const i of e.tiles)if(!i.jresData&&!i.isProjectTile)for(const e of t)if(e.qualifiedName===i.id){i.bitmap=e.bitmap;break}return e}function T(e,t){const i=t.copy();for(let t=0;t<i.width;t++)for(let n=0;n<i.height;n++){const s=i.get(t,n);s===e?i.set(t,n,0):s>e&&i.set(t,n,s-1)}return i}function E(e,t){return"tilemap"===e.type?function(e,t){return{kind:"Tilemap",asset:e,colors:pxt.appTarget.runtime.palette.slice(),aspectRatioLocked:!1,tilemap:{bitmap:e.data.tilemap.data(),overlayLayers:[e.data.layers]},tileset:b(e.data.tileset,t),nextId:e.data.nextId}}(e,t):function(e){return{kind:"Animation",asset:e,visible:!0,colors:pxt.appTarget.runtime.palette.slice(),aspectRatioLocked:"tile"===e.type,currentFrame:0,frames:"animation"===e.type?e.frames.map(e=>({bitmap:e})):[{bitmap:e.bitmap}],interval:"animation"===e.type?e.interval:100}}(e)}function v(e,t){return!(e.layerOffsetX!==t.layerOffsetX||e.layerOffsetY!==t.layerOffsetY||!!e.floating!=!!t.floating||!pxt.sprite.bitmapEquals(e.bitmap,t.bitmap)||!pxt.U.arrayEquals(e.overlayLayers,t.overlayLayers,pxt.sprite.bitmapEquals))&&!!(!e.floating||pxt.sprite.bitmapEquals(e.floating.bitmap,t.floating.bitmap)&&pxt.U.arrayEquals(e.floating.overlayLayers,t.floating.overlayLayers,pxt.sprite.bitmapEquals))}i.setTelemetryFunction=function(e){m=e},i.default=(e=u,t)=>{var i,o,l;switch(t.type){case s.OPEN_TILE_EDITOR:case s.CHANGE_PREVIEW_ANIMATING:case s.CHANGE_CANVAS_ZOOM:case s.CHANGE_IMAGE_TOOL:case s.CHANGE_CURSOR_SIZE:case s.CHANGE_SELECTED_COLOR:case s.CHANGE_CURSOR_LOCATION:case s.CHANGE_BACKGROUND_COLOR:case s.SWAP_FOREGROUND_BACKGROUND:case s.TOGGLE_ONION_SKIN_ENABLED:case s.CHANGE_OVERLAY_ENABLED:case s.CHANGE_TILE_PALETTE_PAGE:case s.CHANGE_TILE_PALETTE_CATEGORY:case s.CHANGE_DRAWING_MODE:case s.SET_GALLERY_OPEN:case s.SHOW_ALERT:case s.HIDE_ALERT:case s.DISABLE_RESIZE:return Object.assign(Object.assign({},e),{editor:d(e.editor,t,e.store)});case s.SET_INITIAL_STATE:const g=t.state;return Object.assign(Object.assign({},e),{editor:Object.assign(Object.assign({},u.editor),{selectedColor:g.selectedColor,backgroundColor:g.backgroundColor,tilemapPalette:g.tilemapPalette,tileGalleryOpen:g.tileGalleryOpen,tileGallery:g.tileGallery,isTilemap:g.isTilemap,referencedTiles:e.editor.referencedTiles}),store:Object.assign(Object.assign({},e.store),{past:t.past||e.store.past,future:t.past?[]:e.store.future})});case s.OPEN_ASSET:const f=t.asset,m=t.gallery||(t.keepPast?e.editor.tileGallery:[]);let b=-1;if("tilemap"===f.type){const e=t.asset.data;if(pxt.sprite.isEmptyTilemap(e)){const t=e.tileset.tiles||[],s=null===(i=m.find(e=>-1!==e.tags.indexOf("forest")))||void 0===i?void 0:i.qualifiedName,o=(0,n.lookupAsset)("tile",s);o&&!t.find(e=>e.id===s)&&t.push(o),b=t.indexOf(o)}}return Object.assign(Object.assign({},e),{editor:"tilemap"===f.type?{selectedColor:b,backgroundColor:-1,isTilemap:!0,tilemapPalette:{category:r.Forest,page:0},drawingMode:a.Default,overlayEnabled:!0,tileGallery:m,tileGalleryOpen:!!m,referencedTiles:f.data.projectReferences,previewAnimating:!1,onionSkinEnabled:!1,tilesetRevision:c++,tool:t.keepPast?e.editor.tool:u.editor.tool,cursorSize:t.keepPast?e.editor.cursorSize:u.editor.cursorSize,editedTiles:t.keepPast?e.editor.editedTiles:void 0,deletedTiles:t.keepPast?e.editor.deletedTiles:void 0}:{isTilemap:!1,tilesetRevision:c++,selectedColor:t.keepPast?e.editor.selectedColor:u.editor.selectedColor,backgroundColor:t.keepPast?e.editor.backgroundColor:u.editor.backgroundColor,previewAnimating:t.keepPast?e.editor.previewAnimating:u.editor.previewAnimating,tool:t.keepPast?e.editor.tool:u.editor.tool,onionSkinEnabled:t.keepPast?e.editor.onionSkinEnabled:u.editor.onionSkinEnabled,cursorSize:t.keepPast?e.editor.cursorSize:u.editor.cursorSize,resizeDisabled:t.keepPast?e.editor.resizeDisabled:u.editor.resizeDisabled},store:Object.assign(Object.assign({},e.store),{past:t.keepPast?e.store.past:[],present:E(t.asset,m),future:[]})});case s.CHANGE_ASSET_NAME:return _("change-asset-name"),Object.assign(Object.assign({},e),{store:{past:[...e.store.past,e.store.present],present:Object.assign(Object.assign({},e.store.present),{asset:Object.assign(Object.assign({},e.store.present.asset),{meta:Object.assign(Object.assign({},e.store.present.asset.meta||{}),{displayName:t.name})})}),future:[]}});case s.UNDO_IMAGE_EDIT:return e.store.past.length?(_("undo"),Object.assign(Object.assign({},e),{store:Object.assign(Object.assign({},e.store),{past:e.store.past.slice(0,e.store.past.length-1),present:e.store.past[e.store.past.length-1],future:[...e.store.future,e.store.present]}),editor:Object.assign(Object.assign({},e.editor),{tilesetRevision:c++})})):e;case s.REDO_IMAGE_EDIT:return e.store.future.length?(_("redo"),Object.assign(Object.assign({},e),{store:Object.assign(Object.assign({},e.store),{past:[...e.store.past,e.store.present],present:e.store.future[e.store.future.length-1],future:e.store.future.slice(0,e.store.future.length-1)}),editor:Object.assign(Object.assign({},e.editor),{tilesetRevision:c++})})):e;default:const T=e.store.present,y=e.editor.isTilemap?p(e.store.present,t):h(e.store.present,t);let k=T.kind!==y.kind;k||("Animation"===T.kind?(l=y,k=!((o=T).visible===l.visible&&o.aspectRatioLocked===l.aspectRatioLocked&&o.currentFrame===l.currentFrame&&o.interval===l.interval&&pxt.assetEquals(o.asset,l.asset)&&pxt.U.arrayEquals(o.colors,l.colors,(e,t)=>e===t)&&pxt.U.arrayEquals(o.frames,l.frames,(e,t)=>v(e,t)))):k=!function(e,t){return e.aspectRatioLocked===t.aspectRatioLocked&&e.nextId===t.nextId&&v(e.tilemap,t.tilemap)&&pxt.assetEquals(e.asset,t.asset)&&pxt.U.arrayEquals(e.colors,t.colors,(e,t)=>e===t)&&pxt.sprite.tilesetEquals(e.tileset,t.tileset)}(T,y));const C=k?Object.assign(Object.assign({},e.store),{past:[...e.store.past,T],present:y,future:[]}):e.store;return Object.assign(Object.assign({},e),{editor:d(e.editor,t,e.store),store:C})}}},{"../../../assets":174,"../actions/types":188}],192:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.mainStore=i.tileEditorStore=void 0;const n=e("redux"),s=e("./imageReducer"),o=(0,n.createStore)(s.default);i.default=o,i.tileEditorStore=(0,n.createStore)(s.default),i.mainStore=o},{"./imageReducer":191,redux:306}],193:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Minimap=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../ImageEditor"),a=pxt.BrowserUtils.isEdge()?25:1;class l extends s.Component{constructor(){super(...arguments),this.tileColors=[]}componentDidMount(){this.canvas=this.refs["minimap-canvas"],this.redrawCanvas()}componentDidUpdate(){this.redrawCanvas()}render(){return(0,n.jsx)("div",Object.assign({className:"minimap-outer"},{children:(0,n.jsx)("canvas",{ref:"minimap-canvas",className:"paint-surface"})}))}redrawCanvas(){const{tilemap:e,lightMode:t}=this.props;let{bitmap:i,floating:n,layerOffsetX:s,layerOffsetY:o}=e;const l=this.canvas.getContext("2d"),c=pxt.sprite.Tilemap.fromData(i),u=n&&n.bitmap?pxt.sprite.Tilemap.fromData(n.bitmap):null;this.canvas.width=c.width*a,this.canvas.height=c.height*a,this.tileColors=[];for(let e=0;e<c.width;e++)for(let i=0;i<c.height;i++){const n=u?u.get(e-s,i-o):null,h=c.get(e,i);n?(l.fillStyle=this.getColor(n),l.fillRect(e*a,i*a,a,a)):h?(l.fillStyle=this.getColor(h),l.fillRect(e*a,i*a,a,a)):t?(l.fillStyle=r.LIGHT_MODE_TRANSPARENT,l.fillRect(e*a,i*a,a,a)):l.clearRect(e*a,i*a,a,a)}}getColor(e){if(!this.tileColors[e]){const{tileset:t,colors:i}=this.props;if(e>=t.tiles.length)return"#ffffff";const n=pxt.sprite.Bitmap.fromData(t.tiles[e].bitmap);this.tileColors[e]=pxt.sprite.computeAverageColor(n,i)}return this.tileColors[e]}}i.Minimap=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{tilemap:n.tilemap,tileset:n.tileset,colors:n.colors}:{}},{})(l)},{"../ImageEditor":180,react:304,"react-redux":287,"react/jsx-runtime":305}],194:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TilePalette=i.BUILTIN_CATEGORIES=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("../store/imageReducer"),a=e("../actions/dispatch"),l=e("../TimelineFrame"),c=e("../Pivot"),u=e("../../../assets"),h=e("../../../../../react-common/components/controls/CarouselNav"),d=e("../../../../../react-common/components/controls/Dropdown"),p=e("../../../../../react-common/components/controls/Button"),g=e("../../../../../react-common/components/util");pxt.BrowserUtils.isEdge();i.BUILTIN_CATEGORIES=[{id:"forest",text:lf("Forest"),tiles:[]},{id:"aquatic",text:lf("Aquatic"),tiles:[]},{id:"dungeon",text:lf("Dungeon"),tiles:[]},{id:"misc",text:lf("Miscellaneous"),tiles:[]}];const f=[{id:"custom",text:lf("My Tiles")},{id:"gallery",text:lf("Gallery")}],m=new pxt.sprite.Bitmap(16,16);class _ extends s.Component{constructor(e){super(e),this.dropdownHandler=e=>{this.props.dispatchChangeTilePaletteCategory(this.categories.filter(e=>!!e.tiles.length).findIndex(t=>t.id===e))},this.pivotHandler=(e,t)=>{this.props.dispatchSetGalleryOpen(1===t)},this.pageHandler=e=>{this.props.dispatchChangeTilePalettePage(e)},this.tileCreateHandler=()=>{this.props.dispatchOpenTileEditor()},this.tileEditHandler=()=>{const{tileset:e,selected:t,dispatchOpenTileEditor:i}=this.props,n=e.tiles[t];(null==n?void 0:n.isProjectTile)&&0!==t&&i(t,n.id)},this.tileDuplicateHandler=()=>{var e;const{tileset:t,selected:i,backgroundColor:n,dispatchCreateNewTile:s}=this.props;if(!t.tiles[i]||!t.tiles[i].isProjectTile||0===i)return;const o=t.tiles[i];s((0,u.createTile)(o.bitmap,null,null===(e=o.meta)||void 0===e?void 0:e.displayName),t.tiles.length,n)},this.tileDeleteAlertHandler=()=>{const{tileset:e,selected:t,dispatchShowAlert:i,dispatchHideAlert:n,referencedTiles:s}=this.props,o=e.tiles[t];t&&o&&o.isProjectTile&&(s&&-1!==s.indexOf(o.id)?i(lf("Unable to delete"),lf("This tile is used in your game. Remove all blocks using the tile before deleting."),[{label:lf("Cancel"),onClick:n}]):i(lf("Are you sure?"),lf("Deleting this tile will remove it from all other tile maps in your game."),[{label:lf("Yes"),onClick:this.deleteTile},{label:lf("No"),onClick:n}]))},this.deleteTile=()=>{const e=this.props.tileset.tiles[this.props.selected];e&&this.props.dispatchDeleteTile(this.props.selected,e.id)},this.foregroundBackgroundClickHandler=()=>{this.props.drawingMode!=r.TileDrawingMode.Default?this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default):this.props.dispatchSwapBackgroundForeground()},this.wallClickHandler=()=>{this.props.drawingMode===r.TileDrawingMode.Wall?this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default):this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Wall)},this.preventContextMenu=e=>e.preventDefault();const{gallery:t}=e;if(this.refreshGallery(e),t){const e={};for(const i of t){const t=i.tags.find(e=>pxt.Util.startsWith(e,"category-"));t&&(e[t]||(e[t]={id:t,text:pxt.Util.rlf(`{id:tilecategory}${t.substr(9)}`),tiles:[]}),e[t].tiles.push(i))}this.categories=i.BUILTIN_CATEGORIES.concat(Object.keys(e).map(t=>e[t]))}else this.categories=[]}componentDidMount(){this.updateGalleryTiles()}UNSAFE_componentWillReceiveProps(e){this.props.selected!=e.selected?this.jumpToPageContaining(e.selected):this.props.backgroundColor!=e.backgroundColor&&this.jumpToPageContaining(e.backgroundColor),this.refreshGallery(e)}componentDidUpdate(){this.updateGalleryTiles()}render(){const{colors:e,selected:t,backgroundColor:i,tileset:s,category:o,page:a,drawingMode:u,galleryOpen:_}=this.props,E=s.tiles[t]?s.tiles[t].bitmap:m.data(),v=s.tiles[i]?s.tiles[i].bitmap:m.data();m.data();this.updateGalleryTiles();let y=Math.ceil(this.categoryTiles.length/16);_||this.categoryTiles.length%16!=0||y++;const k=!_&&(1===y||a===y-1),C=_||!this.renderedTiles.some(e=>!T(e)&&e.index===t),I=4*a*4,S=this.categoryTiles.slice(I,I+16),A=this.categories.filter(e=>!!e.tiles.length).map(e=>({id:e.id,title:e.text,label:e.text}));return(0,n.jsxs)("div",Object.assign({className:"tile-palette"},{children:[(0,n.jsxs)("div",Object.assign({className:"tile-palette-fg-bg"},{children:[(0,n.jsx)("div",Object.assign({className:"tile-palette-swatch fg "+(u==r.TileDrawingMode.Default?"selected":""),onClick:this.foregroundBackgroundClickHandler,role:"button"},{children:(0,n.jsx)(l.TimelineFrame,{frames:[{bitmap:E}],colors:e})})),(0,n.jsxs)("div",Object.assign({className:"tile-palette-swatch bg",onClick:this.foregroundBackgroundClickHandler,role:"button"},{children:[(0,n.jsx)(l.TimelineFrame,{frames:[{bitmap:v}],colors:e}),(0,n.jsx)(p.Button,{className:"image-editor-button toggle",leftIcon:"ms-Icon ms-Icon--ReturnKey",title:lf("Swap the background and foreground colors."),onClick:this.foregroundBackgroundClickHandler})]})),(0,n.jsx)("div",Object.assign({className:"tile-palette-swatch wall "+(u==r.TileDrawingMode.Wall?"selected":""),onClick:this.wallClickHandler,title:lf("Draw walls"),role:"button"},{children:(0,n.jsx)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1000 1000",width:"1000",height:"1000"},{children:(0,n.jsx)("path",{d:"M 968.49289,108.05443 771.30518,3.7581533 183.65231,166.0694 l 2.58963,202.62638 -156.247366,54.4148 0.872799,492.65563 179.544267,81.08212 758.08125,-222.4989 z M 765.6275,42.836761 916.79721,122.02922 412.26526,262.35026 250.08966,187.43643 Z M 934.62189,739.077 234.56171,946.92199 233.81426,554.79578 422.38222,493.25053 423.42046,300.4059 934.62189,157.54989 Z M 204.96854,402.33519 361.49056,473.98651 222.88861,518.46222 75.008408,444.5191 Z"})}))}))]})),(0,n.jsx)(c.Pivot,{options:f,selected:_?1:0,onChange:this.pivotHandler}),(0,n.jsxs)("div",Object.assign({className:"tile-palette-controls-outer"},{children:[_&&(0,n.jsx)(d.Dropdown,{id:"tile-palette-gallery",className:"tile-palette-dropdown",items:A,onItemSelected:this.dropdownHandler,selectedId:A[o].id}),!_&&(0,n.jsxs)("div",Object.assign({className:"tile-palette-controls"},{children:[(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileEditHandler,leftIcon:"ms-Icon ms-Icon--SingleColumnEdit",title:lf("Edit the selected tile"),disabled:C}),(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileDuplicateHandler,leftIcon:"ms-Icon ms-Icon--Copy",title:lf("Duplicate the selected tile"),disabled:C}),(0,n.jsx)(p.Button,{className:(0,g.classList)("image-editor-button",!C&&"toggle"),onClick:this.tileDeleteAlertHandler,leftIcon:"ms-Icon ms-Icon--Delete",title:lf("Delete the selected tile"),disabled:C})]}))]})),(0,n.jsxs)("div",Object.assign({className:"tile-canvas-outer",onContextMenu:this.preventContextMenu},{children:[(0,n.jsxs)("div",Object.assign({className:"tile-canvas"},{children:[S.map((t,i)=>(0,n.jsx)(b,{tile:t.bitmap,title:this.getTileTooltip(t),colors:e,onClick:()=>this.handleTileClick(i,!1),onRightClick:()=>this.handleTileClick(i,!0)},i)),k&&(0,n.jsx)("div",Object.assign({className:"tile-button-outer"},{children:(0,n.jsx)(p.Button,{className:"image-editor-button add-tile-button toggle",onClick:this.tileCreateHandler,leftIcon:"ms-Icon ms-Icon--Add",title:lf("Create a new tile")})}))]})),(0,n.jsx)("div",Object.assign({className:"tile-canvas-controls"},{children:(0,n.jsx)(h.CarouselNav,{selected:a,pages:y,onPageSelected:this.pageHandler,maxDisplayed:5})}))]}))]}))}getTileTooltip(e){const t=(()=>{var t,i,n,s;if(T(e))return null===(t=e.qualifiedName)||void 0===t?void 0:t.split(".").pop();const o=null===(n=null===(i=this.props.tileset)||void 0===i?void 0:i.tiles)||void 0===n?void 0:n[e.index];return(null===(s=null==o?void 0:o.meta)||void 0===s?void 0:s.displayName)||(o?pxt.getShortIDForAsset(o):void 0)||(null==o?void 0:o.id)})(),i=null==t?void 0:t.split(".").pop();return i?lf("Tile {0}",i):lf("Tile")}updateGalleryTiles(){const{page:e,category:t,galleryOpen:i}=this.props;this.categoryTiles=i?this.categories[t].tiles:this.getCustomTiles().map(([e,t])=>({index:t,bitmap:e.bitmap}));const n=16*e;this.renderedTiles=this.categoryTiles.slice(n,n+16)}jumpToPageContaining(e){const{tileset:t,dispatchSetGalleryOpen:i,dispatchChangeTilePaletteCategory:n,dispatchChangeTilePalettePage:s}=this.props;if(!e||e<0||e>=t.tiles.length)return;const o=t.tiles[e];if(o.isProjectTile){const e=this.getCustomTiles().map(([e,t])=>e);if(!e)return;const t=Math.max(Math.floor(e.findIndex(e=>e.id==o.id)/16),0);i(!1),s(t)}else{const e=this.categories.find(e=>-1!==e.tiles.findIndex(e=>e.qualifiedName==o.id));if(!e||!e.tiles)return;const t=Math.max(Math.floor(e.tiles.findIndex(e=>e.qualifiedName==o.id)/16),0);i(!0),n(this.categories.indexOf(e)),s(t)}}handleTileClick(e,t){const i=this.renderedTiles[e];if(i){let e,n;if(T(i)?(e=this.getTileIndex(i),n=i.qualifiedName):e=i.index,e>=0)t?this.props.dispatchChangeBackgroundColor(e):this.props.dispatchChangeSelectedColor(e);else{const{selected:e,backgroundColor:i,tileset:s}=this.props,o=s.tiles.length||1;this.props.dispatchCreateNewTile(null,t?e:o,t?o:i,n)}this.props.dispatchChangeDrawingMode(r.TileDrawingMode.Default)}}refreshGallery(e){const{gallery:t,tileset:n}=e;t&&i.BUILTIN_CATEGORIES.forEach(e=>{e.tiles=t.filter(t=>-1!==t.tags.indexOf(e.id)&&t.tileWidth===n.tileWidth)})}getCustomTiles(){return this.props.tileset.tiles.map((e,t)=>[e,t]).filter(([e])=>e.isProjectTile).sort(([e],[t])=>{const i="myTiles.transparency"+this.props.tileset.tileWidth;return e.id==i?-1:t.id==i?1:e.internalID-t.internalID})}getTileIndex(e){const{tileset:t}=this.props;for(let i=0;i<t.tiles.length;i++)if(t.tiles[i].id===e.qualifiedName)return i;return-1}}const b=e=>{const{tile:t,title:i,onClick:o,onRightClick:r,colors:a}=e,l=s.useRef();return s.useEffect(()=>{const e=l.current;e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.clearRect(0,0,e.width,e.height);const n=pxt.sprite.Bitmap.fromData(t);for(let e=0;e<t.width;e++)for(let s=0;s<t.height;s++){const t=n.get(e,s);t&&(i.fillStyle=a[t],i.fillRect(e,s,1,1))}},[t,a]),(0,n.jsx)("div",Object.assign({className:"tile-button-outer"},{children:(0,n.jsx)(p.Button,{className:"image-editor-button tile-button",title:i,onClick:o,onRightClick:r,label:(0,n.jsx)("canvas",{ref:l})})}))};function T(e){return!!e.qualifiedName}const E={dispatchChangeSelectedColor:a.dispatchChangeSelectedColor,dispatchChangeBackgroundColor:a.dispatchChangeBackgroundColor,dispatchSwapBackgroundForeground:a.dispatchSwapBackgroundForeground,dispatchChangeTilePalettePage:a.dispatchChangeTilePalettePage,dispatchChangeTilePaletteCategory:a.dispatchChangeTilePaletteCategory,dispatchChangeDrawingMode:a.dispatchChangeDrawingMode,dispatchCreateNewTile:a.dispatchCreateNewTile,dispatchSetGalleryOpen:a.dispatchSetGalleryOpen,dispatchOpenTileEditor:a.dispatchOpenTileEditor,dispatchDeleteTile:a.dispatchDeleteTile,dispatchShowAlert:a.dispatchShowAlert,dispatchHideAlert:a.dispatchHideAlert};i.TilePalette=(0,o.connect)(function({store:{present:e},editor:t},i){let n=e;return n?{selected:t.selectedColor,tileset:n.tileset,backgroundColor:t.backgroundColor,category:t.tilemapPalette.category,page:t.tilemapPalette.page,colors:n.colors,drawingMode:t.drawingMode,gallery:t.tileGallery,galleryOpen:t.tileGalleryOpen,referencedTiles:t.referencedTiles}:{}},E)(_)},{"../../../../../react-common/components/controls/Button":159,"../../../../../react-common/components/controls/CarouselNav":160,"../../../../../react-common/components/controls/Dropdown":162,"../../../../../react-common/components/util":171,"../../../assets":174,"../Pivot":181,"../TimelineFrame":184,"../actions/dispatch":187,"../store/imageReducer":191,react:304,"react-redux":287,"react/jsx-runtime":305}],195:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.replaceColorEdit=i.outlineEdit=i.flipEdit=i.rotateEdit=i.MarqueeEdit=i.FillEdit=i.CircleEdit=i.LineEdit=i.OutlineEdit=i.RectangleEdit=i.PaintEdit=i.SelectionEdit=i.Edit=i.EditState=i.getEditState=i.getEdit=i.tools=i.ToolCursor=void 0;const n=e("./store/imageReducer");var s;!function(e){e.None="none",e.Default="default",e.Pointer="pointer",e.Crosshair="crosshair",e.Grab="grab",e.Grabbing="grabbing",e.EyeDropper="var(--eyedropper)"}(s=i.ToolCursor||(i.ToolCursor={})),i.tools=[{tool:n.ImageEditorTool.Paint,iconClass:"ms-Icon ms-Icon--Edit",title:lf("Paint Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Erase,iconClass:"ms-Icon ms-Icon--EraseTool",title:lf("Erase Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Rect,iconClass:"ms-Icon ms-Icon--RectangleShape",title:lf("Rectangle Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Fill,iconClass:"ms-Icon ms-Icon--BucketColor",title:lf("Fill Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Circle,iconClass:"ms-Icon ms-Icon--CircleRing",title:lf("Circle Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Line,iconClass:"ms-Icon ms-Icon--Line",title:lf("Line Tool"),hoverCursor:s.Crosshair},{tool:n.ImageEditorTool.Marquee,iconClass:"ms-Icon ms-Icon--SelectAll",title:lf("Marquee Tool"),hoverCursor:s.Crosshair,hoverLayerCursor:s.Grab,downLayerCursor:s.Grabbing},{tool:n.ImageEditorTool.Pan,iconClass:"ms-Icon ms-Icon--HandsFree",title:lf("Canvas Pan Tool"),hoverCursor:s.Grab,downCursor:s.Grabbing},{tool:n.ImageEditorTool.ColorSelect,hiddenTool:!0,iconClass:"ms-Icon ms-Icon--Edit",title:lf("Color Select Tool"),hoverCursor:s.EyeDropper}],i.getEdit=function(e,t,i,s){switch(e){case n.ImageEditorTool.Paint:return new l(t.width,t.height,i,s);case n.ImageEditorTool.Rect:return new c(t.width,t.height,i,s);case n.ImageEditorTool.Fill:return new d(t.width,t.height,i,s);case n.ImageEditorTool.Line:return new u(t.width,t.height,i,s);case n.ImageEditorTool.Marquee:return new p(t.width,t.height,i,s);case n.ImageEditorTool.Circle:return new h(t.width,t.height,i,s);case n.ImageEditorTool.Erase:return new l(t.width,t.height,0,s);case n.ImageEditorTool.ColorSelect:default:return}},i.getEditState=function(e,t,i=n.TileDrawingMode.Default){const s=new o(t?pxt.sprite.Tilemap.fromData(e.bitmap).copy():pxt.sprite.Bitmap.fromData(e.bitmap).copy());let r,a,l;return e.overlayLayers&&(s.overlayLayers=e.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy())),s.layerOffsetX=e.layerOffsetX,s.layerOffsetY=e.layerOffsetY,e.floating&&(e.floating.bitmap&&(a=t?pxt.sprite.Tilemap.fromData(e.floating.bitmap).copy():pxt.sprite.Bitmap.fromData(e.floating.bitmap).copy()),e.floating.overlayLayers&&(l=e.floating.overlayLayers.map(e=>pxt.sprite.Bitmap.fromData(e).copy())),r={image:a,overlayLayers:l}),s.floating=r,s.setActiveLayer(i),s};class o{constructor(e){this.activeLayerIndex=-1,this.image=e,this.layerOffsetX=0,this.layerOffsetY=0}get width(){return this.image.width}get height(){return this.image.height}get activeLayer(){return this.activeLayerIndex<0?this.image:this.overlayLayers[this.activeLayerIndex]}setActiveLayer(e){if(e===n.TileDrawingMode.Wall)this.activeLayerIndex=0;else this.activeLayerIndex=-1}copy(){const e=new o;if(e.image=this.image.copy(),e.overlayLayers=this.overlayLayers&&this.overlayLayers.map(e=>e.copy()),this.floating){let t,i;this.floating.image&&(t=this.floating.image.copy()),this.floating.overlayLayers&&(i=this.floating.overlayLayers.map(e=>e.copy())),e.floating={image:t,overlayLayers:i}}return e.layerOffsetX=this.layerOffsetX,e.layerOffsetY=this.layerOffsetY,e}equals(e){return!(!this.image.equals(e.image)||this.floating&&!e.floating||!this.floating&&e.floating)&&(!this.floating||!this.floating.image||this.floating.image.equals(e.floating.image)&&this.layerOffsetX===e.layerOffsetX&&this.layerOffsetY===e.layerOffsetY)}mergeFloatingLayer(){this.floating&&(this.floating.image||this.floating.overlayLayers)&&(this.floating.image&&(this.floating.image.x0=this.layerOffsetX,this.floating.image.y0=this.layerOffsetY,this.image.apply(this.floating.image,!0),this.floating.image=void 0),this.floating.overlayLayers&&(this.floating.overlayLayers.forEach((e,t)=>{e.x0=this.layerOffsetX,e.y0=this.layerOffsetY,this.overlayLayers[t].apply(e,!0)}),this.floating.overlayLayers=void 0))}copyToLayer(e,t,i,n,s=!1){if(0===i||0===n)return;i<0&&(e+=i,i=-i),n<0&&(t+=n,n=-n);let o,r=this.image.copy(e,t,i,n);if(this.layerOffsetX=r.x0,this.layerOffsetY=r.y0,r.x0=void 0,r.y0=void 0,this.overlayLayers&&(o=this.overlayLayers.map(s=>s.copy(e,t,i,n))),s)for(let s=0;s<i;s++)for(let i=0;i<n;i++)this.image.set(e+s,t+i,0),this.overlayLayers&&this.overlayLayers.forEach(n=>n.set(e+s,t+i,0));this.floating={image:r,overlayLayers:o}}inFloatingLayer(e,t){return!(!this.floating||!this.floating.image)&&(e-=this.layerOffsetX,t-=this.layerOffsetY,e>=0&&e<this.floating.image.width&&t>=0&&t<this.floating.image.height)}setFloatingLayer(e,t,i){var n,s;i&&this.mergeFloatingLayer(),this.floating={image:e},this.layerOffsetX=null!==(n=null==t?void 0:t.layerOffsetX)&&void 0!==n?n:0,this.layerOffsetY=null!==(s=null==t?void 0:t.layerOffsetY)&&void 0!==s?s:0}toImageState(){return{bitmap:this.image.data(),layerOffsetX:this.layerOffsetX,layerOffsetY:this.layerOffsetY,floating:this.floating&&{bitmap:this.floating.image?this.floating.image.data():void 0,overlayLayers:this.floating.overlayLayers?this.floating.overlayLayers.map(e=>e.data()):void 0},overlayLayers:this.overlayLayers?this.overlayLayers.map(e=>e.data()):void 0}}}i.EditState=o;class r{constructor(e,t,i,n){this.canvasWidth=e,this.canvasHeight=t,this.color=i,this.toolWidth=n}doEdit(e){this.isStarted&&this.doEditCore(e)}inBounds(e,t){return e>=0&&e<this.canvasWidth&&t>=0&&t<this.canvasHeight}start(e,t,i,n,s){this.isStarted=!0,this.startCol=e,this.startRow=t,this.startX=i,this.startY=n}drawCursor(e,t,i){i(e,t)}}i.Edit=r;class a extends r{update(e,t){this.endCol=e,this.endRow=t,this.isDragged||e==this.startCol&&t==this.startRow||(this.isDragged=!0)}topLeft(){return{x:Math.min(this.startCol,this.endCol),y:Math.min(this.startRow,this.endRow)}}bottomRight(){return{x:Math.max(this.startCol,this.endCol),y:Math.max(this.startRow,this.endRow)}}}i.SelectionEdit=a;class l extends r{constructor(e,t,i,n){super(e,t,i,n),this.showPreview=!0,this.mask=new pxt.sprite.Bitmask(e,t)}update(e,t){this.interpolate(this.startCol,this.startRow,e,t),this.startCol=e,this.startRow=t}interpolate(e,t,i,n){const s=(e,t)=>this.mask.set(e,t);pxt.Util.bresenhamLine(e,t,i,n,(e,t)=>this.drawCore(e,t,s))}doEditCore(e){e.mergeFloatingLayer();for(let t=0;t<e.width;t++)for(let i=0;i<e.height;i++)this.mask.get(t,i)&&e.activeLayer.set(t,i,this.color)}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){const o=e+n,r=t+s;o>=0&&o<this.canvasWidth&&r>=0&&r<this.canvasHeight&&i(e+n,t+s)}}}i.PaintEdit=l;i.RectangleEdit=class extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();const t=this.topLeft(),i=this.bottomRight();for(let n=t.x;n<=i.x;n++)for(let s=t.y;s<=i.y;s++)e.activeLayer.set(n,s,this.color)}};class c extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();let t=this.topLeft();t.x-=this.toolWidth>>1,t.y-=this.toolWidth>>1;let i=this.bottomRight();i.x+=this.toolWidth>>1,i.y+=this.toolWidth>>1;for(let n=0;n<this.toolWidth;n++)this.drawRectangle(e,{x:t.x+n,y:t.y+n},{x:i.x-n,y:i.y-n})}drawRectangle(e,t,i){if(!(t.x>i.x||t.y>i.y)){for(let n=t.x;n<=i.x;n++)e.activeLayer.set(n,t.y,this.color),e.activeLayer.set(n,i.y,this.color);for(let n=t.y;n<=i.y;n++)e.activeLayer.set(t.x,n,this.color),e.activeLayer.set(i.x,n,this.color)}}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){const o=e+n,r=t+s;o>=0&&o<this.canvasWidth&&r>=0&&r<this.canvasHeight&&i(e+n,t+s)}}}i.OutlineEdit=c;class u extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer(),this.bresenham(this.startCol,this.startRow,this.endCol,this.endRow,e)}bresenham(e,t,i,n,s){const o=(e,t)=>s.activeLayer.set(e,t,this.color);pxt.Util.bresenhamLine(e,t,i,n,(e,t)=>this.drawCore(e,t,o))}drawCursor(e,t,i){this.drawCore(e,t,i)}drawCore(e,t,i){e-=Math.floor(this.toolWidth/2),t-=Math.floor(this.toolWidth/2);for(let n=0;n<this.toolWidth;n++)for(let s=0;s<this.toolWidth;s++){i(e+n,t+s)}}}i.LineEdit=u;class h extends a{constructor(){super(...arguments),this.showPreview=!0}doEditCore(e){e.mergeFloatingLayer();const t=this.topLeft(),i=this.bottomRight(),n=i.x-t.x,s=i.y-t.y,o=Math.floor(Math.hypot(n,s)),r=this.startCol,a=this.startRow;this.midpoint(r,a,o,e)}midpoint(e,t,i,n){let s=i-1,o=0,r=1,a=1,l=r-2*i;for(;s>=o;)n.activeLayer.set(e+s,t+o,this.color),n.activeLayer.set(e+s,t-o,this.color),n.activeLayer.set(e+o,t+s,this.color),n.activeLayer.set(e+o,t-s,this.color),n.activeLayer.set(e-o,t+s,this.color),n.activeLayer.set(e-o,t-s,this.color),n.activeLayer.set(e-s,t+o,this.color),n.activeLayer.set(e-s,t-o,this.color),l<=0&&(o++,l+=a,a+=2),l>0&&(s--,r+=2,l+=r-2*i)}}i.CircleEdit=h;class d extends r{constructor(){super(...arguments),this.showPreview=!0}start(e,t,i,n,s){this.isStarted=!0,this.col=e,this.row=t}update(e,t){this.col=e,this.row=t}doEditCore(e){const t=e.activeLayer!==e.image,i=(i,n)=>(t?e.activeLayer.get(i,n)+1<<8:0)+e.image.get(i,n),n=i(this.col,this.row);if(n===this.color)return;e.mergeFloatingLayer();const s=new pxt.sprite.Bitmask(e.width,e.height);s.set(this.col,this.row);const o=[{x:this.col,y:this.row}];for(;o.length;){const t=o.pop();i(t.x,t.y)===n&&(e.activeLayer.set(t.x,t.y,this.color),r(t.x+1,t.y),r(t.x-1,t.y),r(t.x,t.y+1),r(t.x,t.y-1))}function r(e,t){e>=0&&e<s.width&&t>=0&&t<s.height&&!s.get(e,t)&&(s.set(e,t),o.push({x:e,y:t}))}}}i.FillEdit=d;class p extends a{constructor(){super(...arguments),this.isMove=!1,this.isResize=!1,this.showPreview=!1}start(e,t,i,n,s){this.isStarted=!0,this.startCol=e,this.startRow=t;const o=document.elementFromPoint(i,n);if(s.floating&&s.floating.image)if(o&&"image-editor-floating-layer-corner"==o.className){let e;this.isResize=!0,this.startOffsetX=s.layerOffsetX,this.startOffsetY=s.layerOffsetY;let t=0;const o=document.getElementsByClassName("image-editor-floating-layer-corner");for(let s=0;s<o.length;s++){let r=Math.sqrt(Math.pow(o[s].getBoundingClientRect().x-i,2)+Math.pow(o[s].getBoundingClientRect().y-n,2));r>t&&(t=r,e=o[s])}const r=document.getElementsByClassName("paint-surface");let a;for(let e=0;e<r.length;e++)r[e].className.includes("main")&&(a=r[e]);const l=a.getBoundingClientRect().left,c=a.getBoundingClientRect().top,u=a.getBoundingClientRect().width,h=a.getBoundingClientRect().height;this.anchorCol=(e.getBoundingClientRect().x-l)/u*this.canvasWidth,this.anchorRow=(e.getBoundingClientRect().y-c)/h*this.canvasHeight,this.originalImage||(this.originalImage=s.floating.image.copy())}else s.inFloatingLayer(e,t)&&(this.isMove=!0,this.startOffsetX=s.layerOffsetX,this.startOffsetY=s.layerOffsetY)}inBounds(e,t){return this.isMove||super.inBounds(e,t)}doEditCore(e){const t=this.topLeft(),i=this.bottomRight();if(this.isDragged)if(this.isMove)e.layerOffsetX=this.startOffsetX+this.endCol-this.startCol,e.layerOffsetY=this.startOffsetY+this.endRow-this.startRow;else if(this.isResize){const t=Math.round(Math.abs(this.anchorCol-this.endCol)),i=Math.round(Math.abs(this.anchorRow-this.endRow)),n=function(e,t,i){const n=new pxt.sprite.Bitmap(t,i,0,0);for(let s=0;s<t;s++)for(let o=0;o<i;o++){const r=Math.floor(s/t*e.width),a=Math.floor(o/i*e.height),l=e.get(r,a);n.set(s,o,l)}return n}(this.originalImage,t,i);e.setFloatingLayer(n,{layerOffsetX:Math.round(Math.min(this.anchorCol,this.endCol)),layerOffsetY:Math.round(Math.min(this.anchorRow,this.endRow))},!1)}else e.mergeFloatingLayer(),e.copyToLayer(t.x,t.y,i.x-t.x+1,i.y-t.y+1,!0);else this.isMove||e.mergeFloatingLayer()}}i.MarqueeEdit=p,i.rotateEdit=function(e,t,i,n){var s;const r=!!(null===(s=e.floating)||void 0===s?void 0:s.image),a=r?e.floating:e,l=i?new pxt.sprite.Tilemap(a.image.height,a.image.width):new pxt.sprite.Bitmap(a.image.height,a.image.width),c=a.overlayLayers?a.overlayLayers.map(e=>new pxt.sprite.Bitmap(e.height,e.width)):void 0;for(let e=0;e<a.image.width;e++)for(let t=0;t<a.image.height;t++)h(a.image,l,e,t),c&&c.forEach((i,n)=>h(a.overlayLayers[n],i,e,t));const u=l.width===l.height&&l.width===e.image.width&&e.image.width===e.image.height;if(!n&&!r||u){const e=new o(l);return e.overlayLayers=c,e}if(!r)for(let t=0;t<e.width;t++)for(let i=0;i<e.height;i++)e.image.set(t,i,0),e.overlayLayers&&e.overlayLayers.forEach(e=>null==e?void 0:e.set(t,i,0));return(l.width===e.image.height&&l.height===e.image.width||l.width===e.image.width&&l.height===e.image.height)&&(e.layerOffsetX=(e.width>>1)-(l.width>>1),e.layerOffsetY=(e.height>>1)-(l.height>>1)),e.floating={image:l,overlayLayers:c},e;function h(e,i,n,s){t?i.set(s,n,e.get(n,e.height-s-1)):i.set(s,n,e.get(e.width-n-1,s))}},i.flipEdit=function(e,t,i){var n,s;const r=(null===(n=e.floating)||void 0===n?void 0:n.image)?e.floating:e,a=i?new pxt.sprite.Tilemap(r.image.width,r.image.height):new pxt.sprite.Bitmap(r.image.width,r.image.height),l=r.overlayLayers?r.overlayLayers.map(e=>new pxt.sprite.Bitmap(e.width,e.height)):void 0;for(let e=0;e<r.image.width;e++)for(let t=0;t<r.image.height;t++)c(r.image,a,e,t),l&&l.forEach((i,n)=>c(r.overlayLayers[n],i,e,t));if(null===(s=e.floating)||void 0===s?void 0:s.image)return e.floating={image:a,overlayLayers:l},e;{const e=new o(a);return e.overlayLayers=l,e}function c(e,i,n,s){t?i.set(n,s,e.get(n,e.height-s-1)):i.set(n,s,e.get(e.width-n-1,s))}},i.outlineEdit=function(e,t){var i,n;const s=(null===(i=e.floating)||void 0===i?void 0:i.image)?e.floating:e,o=e.copy(),r=(null===(n=null==e?void 0:e.floating)||void 0===n?void 0:n.image)?o.floating.image:o.image;for(let e=0;e<s.image.width;e++)for(let i=0;i<s.image.height;i++)0===s.image.get(e,i)&&(0===s.image.get(e-1,i)&&0===s.image.get(e,i-1)&&0===s.image.get(e+1,i)&&0===s.image.get(e,i+1)||r.set(e,i,t));return o},i.replaceColorEdit=function(e,t,i){var n,s;const o=(null===(n=e.floating)||void 0===n?void 0:n.image)?e.floating:e,r=e.copy(),a=(null===(s=null==e?void 0:e.floating)||void 0===s?void 0:s.image)?r.floating.image:r.image;for(let e=0;e<o.image.width;e++)for(let n=0;n<o.image.height;n++)o.image.get(e,n)===t&&a.set(e,n,i);return r}},{"./store/imageReducer":191}],196:[function(e,t,i){"use strict";function n(){return"undefined"!=typeof window&&!!window.PointerEvent}function s(){return"undefined"!=typeof window&&("ontouchstart"in window||navigator&&navigator.maxTouchPoints>0)}Object.defineProperty(i,"__esModule",{value:!0}),i.createTilemapPatchFromFloatingLayer=i.applyBitmapData=i.imageStateToTilemap=i.imageStateToBitmap=i.bindGestureEvents=i.GestureState=i.fireClickOnlyOnEnter=i.clientCoord=i.pointerEvents=i.Bitmask=i.MapTools=i.isBitmapSupported=i.isTouchEnabled=i.hasPointerEvents=i.DRAG_RADIUS=void 0,i.DRAG_RADIUS=3,i.hasPointerEvents=n,i.isTouchEnabled=s,i.isBitmapSupported=function(){return!!window.createImageBitmap},function(e){e[e.Pan=0]="Pan",e[e.Stamp=1]="Stamp",e[e.Object=2]="Object",e[e.Erase=3]="Erase"}(i.MapTools||(i.MapTools={}));function o(e){if(e.touches){const t=e;return t.touches.length?t.touches[0]:t.changedTouches[0]}return e}i.Bitmask=class{constructor(e,t){this.width=e,this.height=t,this.mask=new Uint8Array(Math.ceil(e*t/8))}set(e,t){const i=e+this.width*t,n=i>>3,s=7&i;this.mask[n]|=1<<s}get(e,t){const i=e+this.width*t,n=i>>3,s=7&i;return this.mask[n]>>s&1}},i.pointerEvents=n()?{up:"pointerup",down:["pointerdown"],move:"pointermove",enter:"pointerenter",leave:"pointerleave"}:s()?{up:"mouseup",down:["mousedown","touchstart"],move:"touchmove",enter:"touchenter",leave:"touchend"}:{up:"mouseup",down:["mousedown"],move:"mousemove",enter:"mouseenter",leave:"mouseleave"},i.clientCoord=o,i.fireClickOnlyOnEnter=function(e){13===("number"==typeof e.which?e.which:e.keyCode)&&(e.preventDefault(),e.currentTarget.click())};class r{constructor(e,t,i){this.target=e,this.isRightClick=i,this.startX=t.clientX,this.startY=t.clientY,this.currentX=t.clientX,this.currentY=t.clientY}update(e){this.currentX=e.clientX,this.currentY=e.clientY,!this.isDrag&&this.distance()>i.DRAG_RADIUS?(this.isDrag=!0,this.target.onDragStart(e,this.isRightClick)):this.isDrag&&this.target.onDragMove(e)}end(e){e&&this.update(e),e=e||{clientX:this.currentX,clientY:this.currentY},this.isDrag?this.target.onDragEnd(e):this.target.onClick(e,this.isRightClick)}distance(){return Math.sqrt(Math.pow(this.currentX-this.startX,2)+Math.pow(this.currentY-this.startY,2))}}function a(e,t){for(let i=0;i<e.changedTouches.length;i++)if(e.changedTouches[i].identifier===t)return e.changedTouches[i]}function l(e){return e.button>0}i.GestureState=r,i.bindGestureEvents=function(e,t){n()?function(e,t){let i;e.addEventListener("pointerup",e=>{i&&(i.end(o(e)),e.preventDefault()),i=void 0}),e.addEventListener("pointerdown",e=>{i&&i.end(),i=new r(t,o(e),l(e)),e.preventDefault()}),e.addEventListener("pointermove",e=>{i&&(i.update(o(e)),e.preventDefault())}),e.addEventListener("pointerleave",e=>{i&&(i.end(o(e)),e.preventDefault()),i=void 0})}(e,t):s()?function(e,t){let i,n;e.addEventListener("touchend",e=>{if(i&&n){const t=a(e,n);t&&(i.end(t),i=void 0,e.preventDefault())}}),e.addEventListener("touchstart",e=>{i&&i.end(),n=e.changedTouches[0].identifier,i=new r(t,e.changedTouches[0],l(e))}),e.addEventListener("touchmove",e=>{if(i&&n){const t=a(e,n);t&&(i.update(t),e.preventDefault())}}),e.addEventListener("touchcancel",e=>{if(i&&n){const t=a(e,n);t&&(i.end(t),i=void 0,e.preventDefault())}})}(e,t):function(e,t){let i;e.addEventListener("mouseup",e=>{i&&i.end(o(e)),i=void 0}),e.addEventListener("mousedown",e=>{i&&i.end(),i=new r(t,o(e),l(e))}),e.addEventListener("mousemove",e=>{i&&i.update(o(e))}),e.addEventListener("mouseleave",e=>{i&&i.end(o(e)),i=void 0})}(e,t)},i.imageStateToBitmap=function(e){const t=pxt.sprite.Bitmap.fromData(e.bitmap).copy();if(e.floating&&e.floating.bitmap){const i=pxt.sprite.Bitmap.fromData(e.floating.bitmap);i.x0=e.layerOffsetX||0,i.y0=e.layerOffsetY||0,t.apply(i,!0)}return t},i.imageStateToTilemap=function(e){const t=pxt.sprite.Tilemap.fromData(e.bitmap).copy();if(e.floating&&e.floating.bitmap){const i=pxt.sprite.Tilemap.fromData(e.floating.bitmap);i.x0=e.layerOffsetX||0,i.y0=e.layerOffsetY||0,t.apply(i,!0)}return t},i.applyBitmapData=function(e,t,i=0,n=0){if(!e||!t)return e;const s=pxt.sprite.Bitmap.fromData(e),o=pxt.sprite.Bitmap.fromData(t);return o.x0=i,o.y0=n,s.apply(o,!0),s.data()},i.createTilemapPatchFromFloatingLayer=function(e,t){if(!e.floating)return;const i=pxt.sprite.Tilemap.fromData(e.floating.image.data()),n=new pxt.sprite.Tilemap(i.width,i.height),s=e.floating.overlayLayers?e.floating.overlayLayers.map(e=>pxt.sprite.base64EncodeBitmap(e.data())):[];let o=[];for(let e=0;e<i.width;e++)for(let s=0;s<i.height;s++){const r=t.tiles[i.get(e,s)],a=o.indexOf(r);-1===a?(n.set(e,s,o.length),o.push(r)):n.set(e,s,a)}return{map:pxt.sprite.hexEncodeTilemap(n),layers:s,tiles:o.map(e=>pxt.sprite.base64EncodeBitmap(e.bitmap))}}},{}],197:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ImageFieldEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./assetEditor/assetCard"),r=e("../assets"),a=e("./ImageEditor/ImageEditor"),l=e("./ImageEditor/keyboardShortcuts"),c=e("./ImageEditor/store/imageReducer"),u=e("./FilterPanel"),h=e("../util"),d=e("../../../react-common/components/controls/EditorToggle"),p=e("./MusicFieldEditor"),g=e("../../../react-common/components/util"),f=e("../../../react-common/components/controls/FocusTrap"),m=e("./PianoRollFieldEditor"),_=e("./SongGallery"),b=e("./musicEditor/playback");class T extends s.Component{constructor(e){super(e),this.tagClickHandler=e=>{let t=this.state.gallerySelectedTags;const i=e.toLowerCase(),n=t.indexOf(i);n<0?t.push(i):t.splice(n,1),this.setState({gallerySelectedTags:t})},this.clearFilterTags=()=>{this.setState({gallerySelectedTags:[]})},this.toggleFilter=()=>{this.setState({filterOpen:!this.state.filterOpen})},this.showEditor=()=>{(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!0),v("gallery-editor"),this.setState({currentView:"editor",tileGalleryVisible:!1})},this.showGallery=()=>{(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!1),v("gallery-builtin"),this.setState({currentView:"gallery",tileGalleryVisible:!1})},this.showMyAssets=()=>{var e,t;(0,b.stopPlayback)(),this.setImageEditorShortcutsEnabled(!1),v("gallery-my-assets"),this.userAssets=(0,r.getAssets)(void 0,void 0,null===(t=null===(e=this.state)||void 0===e?void 0:e.options)||void 0===t?void 0:t.temporaryAssets),this.setState({currentView:"my-assets",tileGalleryVisible:!1})},this.toggleTileGallery=()=>{this.state.tileGalleryVisible?this.setState({tileGalleryVisible:!1}):this.setState({tileGalleryVisible:!0,currentView:"editor"})},this.onAssetSelected=e=>{var t,i;if(this.ref&&e.id!==(null===(t=this.asset)||void 0===t?void 0:t.id))if(this.state.editingTile)this.ref.openInTileEditor(pxt.sprite.Bitmap.fromData(e.bitmap));else if("gallery"===this.state.currentView)this.ref.openGalleryAsset(e);else{const t=pxt.react.getTilemapProject();"tilemap"===(null===(i=this.asset)||void 0===i?void 0:i.type)&&pxt.sprite.updateTilemapReferencesFromResult(t,this.asset),this.asset.meta.displayName?t.updateAsset(this.asset):e.meta.displayName||(e=Object.assign(Object.assign({},pxt.cloneAsset(e)),{id:this.asset.id,meta:this.asset.meta})),"tilemap"===e.type&&pxt.sprite.addMissingTilemapTilesAndReferences(t,e),this.ref.openAsset(e,void 0,!0)}v("gallery-selection"),this.setState({currentView:"editor",tileGalleryVisible:!1}),this.setImageEditorShortcutsEnabled(!0)},this.onTileEditorOpenClose=e=>{this.setState({editingTile:e})},this.onDoneClick=()=>{this.closeEditor&&this.closeEditor(),this.props.doneButtonCallback&&this.props.doneButtonCallback()},this.handleImageEditorRegionRef=e=>{e&&(this.imageEditorRegion=e)},this.onEscapeFromGallery=()=>{this.setState({currentView:"editor"},()=>{this.imageEditorRegion&&this.imageEditorRegion.focus()})},this.state={currentView:"editor",headerVisible:!0,filterOpen:!1,gallerySelectedTags:[],galleryFilter:""},(0,c.setTelemetryFunction)(v)}get asset(){var e;return null===(e=this.ref)||void 0===e?void 0:e.getAsset()}render(){var e,t,i,s,o,r,l;const{currentView:c,headerVisible:b,editingTile:T,hideMyAssets:v,filterOpen:y,hideCloseButton:k}=this.state,C="gallery"===this.state.currentView&&y;let I=b,S=!0;const A=!v&&!T&&!!(null===(e=pxt.appTarget)||void 0===e?void 0:e.appTheme.assetEditor);this.asset&&!this.galleryAssets&&S&&this.updateGalleryAssets(),(null===(t=this.galleryAssets)||void 0===t?void 0:t.length)||(S=!1);const O=this.props.includeSpecialTagsInFilter?[]:["tile","dialog","background"];let w=[],N=[];switch(c){case"my-assets":N=this.filterAssetsByType(this.userAssets,T?"tile":null===(i=this.asset)||void 0===i?void 0:i.type),w=this.getAvailableTags(N,O);break;case"gallery":N=this.filterAssetsByType(this.galleryAssets,T?"tile":null===(s=this.asset)||void 0===s?void 0:s.type,!0,!0),w=this.getAvailableTags(N,O),N=this.filterAssetsByTag(N)}const R=[{label:lf("Editor"),title:lf("Editor"),focusable:!0,icon:"fas fa-paint-brush",onClick:this.showEditor,view:"editor"},{label:lf("Gallery"),title:lf("Gallery"),focusable:!0,icon:"fas fa-image",onClick:this.showGallery,view:"gallery"},{label:lf("My Assets"),title:lf("My Assets"),focusable:!0,icon:"fas fa-folder",onClick:this.showMyAssets,view:"my-assets"}];return S||A?S?A||R.splice(2,1):R.splice(1,1):I=!1,(0,n.jsxs)(f.FocusTrap,Object.assign({onEscape:this.onDoneClick,className:(0,g.classList)("image-editor-wrapper",this.isSongEditor()&&"music-asset-editor")},{children:[I&&(0,n.jsxs)("div",Object.assign({className:"gallery-editor-header"},{children:[(0,n.jsx)("div",{className:"image-editor-header-left"}),(0,n.jsx)("div",Object.assign({className:"image-editor-header-center"},{children:(0,n.jsx)(d.EditorToggle,{id:"image-editor-toggle",className:"slim tablet-compact",items:R,selected:R.findIndex(e=>e.view===c)})})),(0,n.jsxs)("div",Object.assign({className:"image-editor-header-right"},{children:[(0,n.jsxs)("div",Object.assign({className:"gallery-filter-button "+("gallery"===this.state.currentView?"":"hidden"),role:"button",onClick:this.toggleFilter,onKeyDown:h.fireClickOnEnter},{children:[(0,n.jsx)("div",Object.assign({className:"gallery-filter-button-icon"},{children:(0,n.jsx)("i",{className:"icon filter"})})),(0,n.jsx)("div",Object.assign({className:"gallery-filter-button-label"},{children:lf("Filter")}))]})),!T&&!k&&(0,n.jsx)("div",Object.assign({className:"image-editor-close-button",role:"button",onClick:this.onDoneClick},{children:(0,n.jsx)("i",{className:"ui icon close"})}))]}))]})),(0,n.jsxs)("div",Object.assign({className:"image-editor-gallery-window"},{children:[(0,n.jsxs)("div",Object.assign({className:"image-editor-gallery-content"},{children:[(0,n.jsx)(f.FocusTrapRegion,Object.assign({divRef:this.handleImageEditorRegionRef,className:"image-editor-region",enabled:"editor"===c},{children:"music"===this.props.editorType?(0,n.jsx)(p.MusicFieldEditor,{ref:"image-editor",onDoneClicked:this.onDoneClick,hideDoneButton:this.props.hideDoneButton}):"piano-roll"===this.props.editorType?(0,n.jsx)(m.PianoRollAssetEditor,{ref:"image-editor",onDoneClicked:this.onDoneClick,hideDoneButton:this.props.hideDoneButton,fieldEditorParams:this.state.options}):(0,n.jsx)(a.ImageEditor,{ref:"image-editor",singleFrame:this.props.singleFrame,onDoneClicked:this.onDoneClick,onTileEditorOpenClose:this.onTileEditorOpenClose,lightMode:this.lightMode,hideDoneButton:this.props.hideDoneButton,hideAssetName:!(null===(r=null===(o=pxt.appTarget)||void 0===o?void 0:o.appTheme)||void 0===r?void 0:r.assetEditor)})})),"song"===(null===(l=this.asset)||void 0===l?void 0:l.type)?(0,n.jsx)(_.SongGallery,{items:N,hidden:"editor"===c,onAssetSelected:this.onAssetSelected,onEscape:this.onEscapeFromGallery}):(0,n.jsx)(E,{items:N,hidden:"editor"===c,onAssetSelected:this.onAssetSelected,onEscape:this.onEscapeFromGallery})]})),(0,n.jsx)("div",Object.assign({className:"filter-panel-gutter "+(C?"":"hidden")},{children:(0,n.jsx)("div",Object.assign({className:"filter-panel-container"},{children:(0,n.jsx)(u.FilterPanel,{enabledTags:this.state.gallerySelectedTags,tagClickHandler:this.tagClickHandler,clearTags:this.clearFilterTags,tagOptions:w})}))}))]}))]}))}componentDidMount(){this.ref=this.refs["image-editor"],v("image-editor-shown")}componentWillUnmount(){v("image-editor-hidden"),this.galleryAssets=void 0,this.userAssets=void 0}init(e,t,i){switch(this.closeEditor=t,this.setState({options:i}),this.lightMode=i.lightMode,e.type){case"image":this.initSingleFrame(e,i);break;case"tile":i.disableResize=!0,this.initSingleFrame(e,i);break;case"animation":this.initAnimation(e,i);break;case"tilemap":this.initTilemap(e,i);break;case"song":this.ref.openAsset(e)}this.editID=e.id;let n=!1;if(i){this.blocksInfo=i.blocksInfo;const t="tilemap"===e.type?i.tilemapFilter:i.filter;t&&(this.setState({galleryFilter:t}),n=!0),null!=i.headerVisible&&(this.setState({headerVisible:i.headerVisible}),n=!0),null!=i.hideMyAssets&&(this.setState({hideMyAssets:i.hideMyAssets}),n=!0),null!=i.hideCloseButton&&(this.setState({hideCloseButton:i.hideCloseButton}),n=!0)}n||this.forceUpdate()}getValue(){return this.ref?this.ref.getAsset():null}getJres(){return this.ref?this.ref.getJres():""}getPersistentData(){return this.ref?this.ref.getPersistentData():null}restorePersistentData(e){var t,i;this.ref&&(this.ref.restorePersistentData(e),(null===(i=null===(t=this.state)||void 0===t?void 0:t.options)||void 0===i?void 0:i.disableResize)&&this.ref.disableResize())}onResize(){this.ref&&this.ref.onResize()}updateGalleryAssets(){this.galleryAssets=(0,r.getAssets)(!0,this.asset.type)}getAvailableTags(e,t){let i=[];return this.galleryAssets?(e.forEach(e=>{var n;null===(n=e.meta.tags)||void 0===n||n.forEach(e=>{const n=function(e){let t=0===e.indexOf("?")&&e.length>1?e.substring(1):e;return t=t.toLowerCase(),t}(e);t.indexOf(n)<0&&i.indexOf(n)<0&&i.push(n)})}),i):[]}filterAssetsByTag(e){return this.state.gallerySelectedTags.length>0&&this.state.filterOpen&&(e=e.filter(e=>{var t;return!!(null===(t=e.meta.tags)||void 0===t?void 0:t.find(e=>this.state.gallerySelectedTags.indexOf(e)>=0))})),e}filterAssetsByType(e,t,i=!1,n){var s,o,a,l;if(void 0===t&&(t=null===(s=this.asset)||void 0===s?void 0:s.type),void 0===t)return e;if(this.asset&&!i&&(e=e.map(e=>e.type!==this.asset.type||e.id!==this.asset.id?e:(0,r.assetToGalleryItem)(this.getValue())),this.state.editingTile)){const t=this.ref.getAsset();e=e.map(e=>{var i;return(null===(i=t.data.editedTiles)||void 0===i?void 0:i.indexOf(e.id))>=0?(0,r.assetToGalleryItem)(t.data.tileset.tiles.find(t=>t.id===e.id)):e})}if(n){e.forEach(e=>{var t,i,n,s;!e.meta.tags&&(null===(t=this.state)||void 0===t?void 0:t.options)&&(e.meta.tags=(null===(s=null===(n=null===(i=this.blocksInfo)||void 0===i?void 0:i.apis.byQName[e.id])||void 0===n?void 0:n.attributes.tags)||void 0===s?void 0:s.split(" "))||[])});const t=this.state.galleryFilter.split(" ").filter(e=>!!e).map(e=>e.toLowerCase()),i=t.filter(e=>0!==e.indexOf("!")),n=t.filter(e=>0===e.indexOf("!")&&e.length>1).map(e=>e.substring(1));e=e.filter(e=>function(e,t){const i=e.meta.tags?e.meta.tags:[];return t.every(e=>{const t=`?${e}`;return i.some(i=>i===e||i===t)})}(e,i)&&function(e,t){const i=e.meta.tags?e.meta.tags:[];return t.every(e=>!i.some(t=>t===e))}(e,n))}if(i)switch(t){case"animation":return e.filter(e=>"animation"===e.type||"tile"===e.type||"image"===e.type);case"image":return e.filter(e=>"tile"===e.type||"image"===e.type);case"tile":return e.filter(e=>"tile"===e.type);case"tilemap":const t=null===(l=null===(a=null===(o=this.asset)||void 0===o?void 0:o.data)||void 0===a?void 0:a.tileset)||void 0===l?void 0:l.tileWidth;return e.filter(e=>{var i,n;return"tilemap"===e.type&&(!t||(null===(n=null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.tileset)||void 0===n?void 0:n.tileWidth)===t)});case"song":return e.filter(e=>"song"===e.type);case"json":return e.filter(e=>"json"===e.type)}else switch(t){case"animation":return e.filter(e=>"animation"===e.type);case"image":return e.filter(e=>"image"===e.type);case"tile":return e.filter(e=>"tile"===e.type);case"tilemap":return e.filter(e=>"tilemap"===e.type);case"song":return e.filter(e=>"song"===e.type);case"json":return e.filter(e=>"json"===e.type)}}initSingleFrame(e,t){this.ref.openAsset(e),t.disableResize&&this.ref.disableResize()}initAnimation(e,t){this.ref.openAsset(e),t.disableResize&&this.ref.disableResize()}initTilemap(e,t){let i;(null==t?void 0:t.blocksInfo)&&(this.blocksInfo=t.blocksInfo,i=pxt.sprite.filterItems(pxt.sprite.getGalleryItems(this.blocksInfo,"Image"),["tile"]).map(e=>({bitmap:pxt.sprite.getBitmap(this.blocksInfo,e.qName).data(),tags:e.tags,qualifiedName:e.qName,tileWidth:16}))),(null==t?void 0:t.galleryTiles)&&(i=t.galleryTiles.map(e=>({bitmap:e.bitmap,tags:e.tags,qualifiedName:e.qName,tileWidth:16}))),this.ref.openAsset(e,i)}loadJres(e){this.ref&&this.ref.loadJres(e)}setImageEditorShortcutsEnabled(e){e&&this.shortcutLock?((0,l.releaseShortcutLock)(this.shortcutLock),this.shortcutLock=void 0):e||this.shortcutLock||(this.shortcutLock=(0,l.obtainShortcutLock)())}isSongEditor(){return"music"===this.props.editorType||"piano-roll"===this.props.editorType}}i.ImageFieldEditor=T;class E extends s.Component{constructor(){super(...arguments),this.clickHandler=e=>{this.props.onAssetSelected(e)}}render(){let{items:e,hidden:t,onEscape:i}=this.props;return(0,n.jsx)(f.FocusTrapRegion,Object.assign({className:(0,g.classList)("image-editor-gallery",e&&!t&&"visible"),enabled:!t,onEscape:i},{children:!t&&(null==e?void 0:e.map((e,t)=>(0,n.jsx)(o.AssetCardView,{asset:e,selected:!1,onClick:this.clickHandler},t)))}))}}s.Component;function v(e){pxt.tickEvent("image.editor",{action:e})}},{"../../../react-common/components/controls/EditorToggle":163,"../../../react-common/components/controls/FocusTrap":167,"../../../react-common/components/util":171,"../assets":174,"../util":240,"./FilterPanel":175,"./ImageEditor/ImageEditor":180,"./ImageEditor/keyboardShortcuts":189,"./ImageEditor/store/imageReducer":191,"./MusicFieldEditor":198,"./PianoRollFieldEditor":199,"./SongGallery":200,"./assetEditor/assetCard":203,"./musicEditor/playback":219,react:304,"react/jsx-runtime":305}],198:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MusicFieldEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./musicEditor/AssetModel"),r=e("./musicEditor/MusicEditor");class a extends s.Component{constructor(e){super(e),this.onAssetNameChanged=e=>{var t;const i=null===(t=this.state.model)||void 0===t?void 0:t.getCurrentValue();i&&(i.meta.displayName=e,this.state.model.updateValue(i))},this.state={}}render(){const{onDoneClicked:e}=this.props,{model:t}=this.state;return(0,n.jsx)("div",Object.assign({className:"music-field-editor"},{children:t&&(0,n.jsx)(r.MusicEditor,{model:t,onAssetNameChanged:this.onAssetNameChanged,onDoneClicked:e,hideDoneButton:this.props.hideDoneButton})}))}getAsset(){var e;return(null===(e=this.state.model)||void 0===e?void 0:e.getCurrentValue())||this.openedAsset}openAsset(e){pxt.assets.music.inflateSong(e.song),this.openedAsset=e,this.state.model?this.state.model.updateValue(e):this.setState({model:new o.SongModel(e)})}openGalleryAsset(e){const t=pxt.cloneAsset(e);pxt.assets.music.inflateSong(t.song),this.state.model.updateValue(t)}getJres(){return""}loadJres(e){}disableResize(){}onResize(){}getPersistentData(){if(this.state.model)return this.state.model.getState()}restorePersistentData(e){if(e){let t=this.state.model;t||(t=new o.SongModel,this.setState({model:t})),t.restoreState(e)}}}i.MusicFieldEditor=a},{"./musicEditor/AssetModel":206,"./musicEditor/MusicEditor":208,react:304,"react/jsx-runtime":305}],199:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoRollAssetEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./pianoRoll/PianoRoll"),r=e("./pianoRoll/types");class a extends s.Component{constructor(e){super(e),this.state={}}render(){const{fieldEditorParams:e,onDoneClicked:t}=this.props,{model:i}=this.state;return(0,n.jsx)(n.Fragment,{children:i&&(0,n.jsx)(o.PianoRoll,{model:i,onDoneClicked:t,fieldEditorParams:e,showEditControls:!0})})}getAsset(){var e,t;if(this.state.model){const{song:i,assetName:n}=this.state.model.getCurrentValue(),s=(0,r.toPXTSong)(i),o=Object.assign(Object.assign({},this.openedAsset),{song:s});return((null===(e=this.openedAsset)||void 0===e?void 0:e.meta)||n)&&(o.meta=Object.assign(Object.assign({},(null===(t=this.openedAsset)||void 0===t?void 0:t.meta)||{}),{displayName:n})),o}return this.openedAsset}openAsset(e){var t;this.openedAsset=e;const i={song:(0,r.fromPXTSong)(e.song),assetName:null===(t=e.meta)||void 0===t?void 0:t.displayName,selectedTrackIndex:0};this.state.model?this.state.model.updateValue(i,{preserveUndo:!1}):this.setState({model:new o.PianoRollModel(i)})}openGalleryAsset(e){const t=pxt.cloneAsset(e);pxt.assets.music.inflateSong(t.song);const i=(0,r.fromPXTSong)(t.song);for(let e=0;e<i.tracks.length;e++){i.tracks[e].id=e+1}const n=this.state.model.getCurrentValue();this.state.model.updateValue(Object.assign(Object.assign({},n),{song:i,selectedTrackIndex:0}),{preserveUndo:!0,pushUndo:!0})}getJres(){return""}loadJres(e){}disableResize(){}onResize(){}getPersistentData(){var e;return null===(e=this.state.model)||void 0===e?void 0:e.getState()}restorePersistentData(e){if(e){let t=this.state.model;t||(t=new o.PianoRollModel,this.setState({model:t})),t.restoreState(e)}}}i.PianoRollAssetEditor=a},{"./pianoRoll/PianoRoll":230,"./pianoRoll/types":237,react:304,"react/jsx-runtime":305}],200:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SongGallery=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../pxtblocks"),r=e("../../../react-common/components/controls/Button"),a=e("../../../react-common/components/controls/FocusTrap"),l=e("../../../react-common/components/util"),c=e("./musicEditor/playback");i.SongGallery=e=>{const{items:t,hidden:i,onAssetSelected:o,onEscape:r}=e,[h,d]=(0,s.useState)(null);(0,s.useEffect)(()=>{const e=e=>{"stop"===e&&d(null)};return(0,c.addPlaybackStateListener)(e),()=>{(0,c.removePlaybackStateListener)(e)}},[]);const p=e=>{h===e?((0,c.stopPlayback)(),d(null)):((0,c.startPlaybackAsync)(e,!1),d(e))};return(0,n.jsx)(a.FocusTrapRegion,Object.assign({className:(0,l.classList)("image-editor-gallery song",t&&!i&&"visible"),enabled:!i,onEscape:r},{children:!i&&(null==t?void 0:t.map((e,t)=>(0,n.jsx)(u,{asset:e,selected:!1,isPlaying:h===e.song,onPlayClick:p,onClick:()=>o(e)},e.id)))}))};const u=e=>{var t;const{asset:i,selected:a,isPlaying:c,onClick:u,onPlayClick:h}=e,d=i.song,p=(0,s.useMemo)(()=>(0,o.songToDataURI)(i.song,100,32,!1),[i.id]),g=!!i.meta.temporaryInfo?lf("{id:song}Untitled"):(null===(t=i.meta)||void 0===t?void 0:t.displayName)||i.id.split(".").pop()||i.id;return(0,n.jsxs)("div",Object.assign({className:(0,l.classList)("song-gallery-item",a&&"selected")},{children:[(0,n.jsx)(r.Button,{className:"song-gallery-item-button",title:lf("Select {0}",g),label:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",Object.assign({className:"song-gallery-item-name"},{children:g})),(0,n.jsx)("div",Object.assign({className:"song-gallery-item-preview"},{children:(0,n.jsx)("img",{src:p,alt:lf("Preview of {0}",g)})}))]}),onClick:u}),(0,n.jsx)(r.Button,{className:"play-button",leftIcon:(0,l.classList)("fas",c?"fa-stop":"fa-play"),title:c?lf("Stop"):lf("Play"),onClick:()=>{h(d)}})]}))}},{"../../../pxtblocks":76,"../../../react-common/components/controls/Button":159,"../../../react-common/components/controls/FocusTrap":167,"../../../react-common/components/util":171,"./musicEditor/playback":219,react:304,"react/jsx-runtime":305}],201:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.dispatchUpdateGalleryAssets=i.dispatchUpdateUserAssets=i.dispatchChangeGalleryView=i.dispatchChangeSelectedAsset=void 0;const n=e("./types");i.dispatchChangeSelectedAsset=(e,t)=>({type:n.CHANGE_SELECTED_ASSET,assetType:e,assetId:t});i.dispatchChangeGalleryView=(e,t,i)=>({type:n.CHANGE_GALLERY_VIEW,view:e,assetType:t,assetId:i});i.dispatchUpdateUserAssets=()=>({type:n.UPDATE_USER_ASSETS});i.dispatchUpdateGalleryAssets=()=>({type:n.UPDATE_GALLERY_ASSETS})},{"./types":202}],202:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.UPDATE_GALLERY_ASSETS=i.UPDATE_USER_ASSETS=i.CHANGE_GALLERY_VIEW=i.CHANGE_SELECTED_ASSET=void 0,i.CHANGE_SELECTED_ASSET="CHANGE_SELECTED_ASSET",i.CHANGE_GALLERY_VIEW="CHANGE_GALLERY_VIEW",i.UPDATE_USER_ASSETS="UPDATE_USER_ASSETS",i.UPDATE_GALLERY_ASSETS="UPDATE_GALLERY_ASSETS"},{}],203:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetCard=i.AssetCardView=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react-redux"),r=e("./store/assetEditorReducerState"),a=e("./actions/dispatch"),l=e("./assetPreview"),c=e("../../util"),u=e("../../assets");class h extends s.Component{constructor(){super(...arguments),this.clickHandler=()=>{const{type:e,id:t}=this.props.asset;this.props.dispatchChangeSelectedAsset(e,t)}}render(){const{asset:e,selected:t}=this.props;return(0,n.jsx)(d,{asset:e,selected:t,onClick:this.clickHandler})}}class d extends s.Component{constructor(){super(...arguments),this.clickHandler=()=>{this.props.onClick(this.props.asset)}}render(){var e,t;const{asset:i,selected:s}=this.props,o=(0,r.isGalleryAsset)(i),a=(0,u.getIconClassForAssetType)(i.type),h=a||!(null===(e=i.meta)||void 0===e?void 0:e.displayName);return(0,n.jsxs)("div",Object.assign({className:"asset-editor-card "+(s?"selected":""),onClick:this.clickHandler,role:"listitem",tabIndex:0,onKeyDown:c.fireClickOnEnter},{children:[(0,n.jsx)(l.AssetPreview,{asset:i}),h&&(0,n.jsxs)("div",Object.assign({className:"asset-editor-card-label"},{children:[a&&(0,n.jsx)("div",Object.assign({className:"asset-editor-card-icon"},{children:(0,n.jsx)("i",{className:`icon ${a}`})})),!(null===(t=i.meta)||void 0===t?void 0:t.displayName)&&!o&&(0,n.jsx)("div",Object.assign({className:"asset-editor-card-icon warning"},{children:(0,n.jsx)("i",{className:"icon exclamation triangle"})}))]}))]}))}}i.AssetCardView=d;const p={dispatchChangeSelectedAsset:a.dispatchChangeSelectedAsset};i.AssetCard=(0,o.connect)(function(e,t){return e?{selected:e.selectedAsset&&t.asset.id==e.selectedAsset.id}:{}},p)(h)},{"../../assets":174,"../../util":240,"./actions/dispatch":201,"./assetPreview":204,"./store/assetEditorReducerState":205,react:304,"react-redux":287,"react/jsx-runtime":305}],204:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AssetPreview=void 0;const n=e("react/jsx-runtime"),s=e("react");i.AssetPreview=e=>{const{asset:t}=e,i=t.meta.displayName||(t.meta.temporaryInfo?lf("Temporary Asset"):t.id);return(0,n.jsx)("div",Object.assign({className:"asset-editor-preview",title:i},{children:"json"===t.type?(0,n.jsx)(r,Object.assign({},e)):(0,n.jsx)(o,Object.assign({},e))}))};const o=e=>{var t;const{asset:i}=e,o=s.useRef(null),r="animation"===i.type&&(null===(t=i.framePreviewURIs)||void 0===t?void 0:t.length)>1;return s.useEffect(()=>{if(!r||!o.current)return;let e,t=0;const n=()=>{e=setInterval(()=>{o.current&&(o.current.src=i.framePreviewURIs[t]),t=(t+1)%i.framePreviewURIs.length},Math.max(i.interval,100))},s=()=>{clearInterval(e)};return o.current.addEventListener("mouseenter",n),o.current.addEventListener("mouseleave",s),()=>{var t,i;e&&clearInterval(e),null===(t=o.current)||void 0===t||t.removeEventListener("mouseenter",n),null===(i=o.current)||void 0===i||i.removeEventListener("mouseleave",s)}},[i,r]),(0,n.jsx)("img",{src:i.previewURI,alt:lf("A preview of your asset (eg image, tile, animation)"),ref:o,loading:"lazy"})},r=e=>{const{asset:t}=e,i=t.meta.displayName||lf("Untitled");return(0,n.jsx)("div",Object.assign({className:"json-asset-preview"},{children:(0,n.jsx)("div",{children:i})}))}},{react:304,"react/jsx-runtime":305}],205:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.isGalleryAsset=i.GalleryView=void 0,function(e){e[e.User=0]="User",e[e.Gallery=1]="Gallery"}(i.GalleryView||(i.GalleryView={})),i.isGalleryAsset=function(e){var t;return!!((null==e?void 0:e.id.startsWith("sprites."))||(null===(t=null==e?void 0:e.meta)||void 0===t?void 0:t.package)&&"this"!==e.meta.package)}},{}],206:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useModelValue=i.SongModel=i.AssetModel=void 0;const n=e("react");class s{constructor(e){this.undoStack=[],this.redoStack=[],this.listeners=[],void 0!==e&&(this.currentValue=this.cloneValue(e))}addChangeListener(e){this.listeners.push(e)}removeChangeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}notifyChange(){this.listeners.forEach(e=>e())}updateValue(e,t={}){const{preserveUndo:i=!0,pushUndo:n=!0}=t;i?n&&void 0!==this.currentValue&&this.undoStack.push(this.currentValue):this.undoStack=[],this.redoStack=[],this.currentValue=this.cloneValue(e),this.notifyChange()}updateExtraState(e){this.extraState=this.cloneExtraState(e),this.notifyChange()}undo(){this.undoStack.length>0&&(this.redoStack.push(this.currentValue),this.currentValue=this.undoStack.pop(),this.notifyChange())}redo(){this.redoStack.length>0&&(this.undoStack.push(this.currentValue),this.currentValue=this.redoStack.pop(),this.notifyChange())}getCurrentValue(){return this.cloneValue(this.currentValue)}getExtraState(){return this.cloneExtraState(this.extraState)}getState(){return{currentValue:this.cloneValue(this.currentValue),undoStack:this.undoStack.map(e=>this.cloneValue(e)),redoStack:this.redoStack.map(e=>this.cloneValue(e)),extraState:this.cloneExtraState(this.extraState)}}restoreState(e,t={}){t.overwriteValue&&(this.currentValue=this.cloneValue(e.currentValue)),t.includeRedoStack&&(this.redoStack=e.redoStack.map(e=>this.cloneValue(e))),this.undoStack=e.undoStack.map(e=>this.cloneValue(e)),this.extraState=this.cloneExtraState(e.extraState),this.notifyChange()}hasUndo(){return this.undoStack.length>0}hasRedo(){return this.redoStack.length>0}}i.AssetModel=s;i.SongModel=class extends s{cloneValue(e){return pxt.cloneAsset(e)}cloneExtraState(e){return e}};i.useModelValue=e=>{const[t,i]=n.useState(e.getCurrentValue());return n.useEffect(()=>{const t=()=>{i(e.getCurrentValue())};return e.addChangeListener(t),()=>{e.removeChangeListener(t)}},[e]),{value:t,hasUndo:e.hasUndo(),hasRedo:e.hasRedo(),extraState:e.getExtraState()}}},{react:304}],207:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.EditControls=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=e("../../../../react-common/components/controls/Input"),a=e("../../assets");i.EditControls=e=>{var t;const{onAssetNameChanged:i,onDoneClicked:l,assetName:c,hideDoneButton:u}=e,[h,d]=s.useState(),[p,g]=s.useState(),f=e=>{let t=null;const n=e.trim();if(!n)return d(void 0),void g(void 0);pxt.validateAssetName(n)?(0,a.isNameTaken)(n)&&n!==c&&(t=lf("This name is already used elsewhere in your project")):t=lf("Names may only contain letters, numbers, '-', '_', and space"),t?(d(n),g(t)):(i(n),d(void 0),g(void 0))},m=!!(null===(t=pxt.appTarget)||void 0===t?void 0:t.appTheme.assetEditor);return(0,n.jsxs)("div",Object.assign({className:"music-editor-edit-controls"},{children:[p&&(0,n.jsx)("div",Object.assign({className:"music-editor-name-error"},{children:p})),m&&(0,n.jsx)(r.Input,{placeholder:lf("Asset Name"),initialValue:c||h,onBlur:f,onEnterKey:f}),!u&&(0,n.jsx)(o.Button,{className:"green",title:lf("Done"),label:lf("Done"),onClick:l})]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Input":168,"../../assets":174,react:304,"react/jsx-runtime":305}],208:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MusicEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./AssetModel"),r=e("./EditControls"),a=e("./keyboardNavigation"),l=e("./playback"),c=e("./PlaybackControls"),u=e("./ScrollableWorkspace"),h=e("./TrackSelector"),d=e("./utils");i.MusicEditor=e=>{const{model:t,onAssetNameChanged:i,onDoneClicked:p,hideDoneButton:g}=e,{value:f,hasUndo:m,hasRedo:_}=(0,o.useModelValue)(t),b=f.song,[T,E]=s.useState(0),[v,y]=s.useState("1/8"),[k,C]=s.useState(!1),[I,S]=s.useState(!1),[A,O]=s.useState(),[w,N]=s.useState(),[R,x]=s.useState(!1),[L,D]=s.useState((0,d.doesSongUseBassClef)(b));s.useEffect(()=>()=>{(0,l.stopPlayback)()},[]),s.useEffect(()=>{const e=e=>{A&&(e.preventDefault(),e.stopPropagation(),e.clipboardData.setData("application/makecode-song",JSON.stringify(A)))},t=e=>{if(A){e.preventDefault(),e.stopPropagation(),e.clipboardData.setData("application/makecode-song",JSON.stringify(A));const t=(0,d.applySelection)(A,I?T:void 0);F((0,d.deleteSelectedNotes)(t),!0)}},i=e=>{const t=e.clipboardData.getData("application/makecode-song");if(t){const e=JSON.parse(t);let i;i=A?{originalSong:(0,d.unselectAllNotes)((0,d.applySelection)(A,I?T:void 0)),pastedContent:e,startTick:A.startTick,endTick:A.startTick+(e.endTick-e.startTick),deltaTick:0,transpose:0}:{originalSong:b,pastedContent:e,startTick:0,endTick:e.endTick-e.startTick,deltaTick:0,transpose:0},F((0,d.applySelection)(i,I?T:void 0),!1),O(i)}};return document.addEventListener("copy",e),document.addEventListener("cut",t),document.addEventListener("paste",i),()=>{document.removeEventListener("copy",e),document.removeEventListener("cut",t),document.removeEventListener("paste",i)}},[A,I,b]);const M=s.useRef(),B=k?1:function(e,t){switch(e){case"1/4":return t;case"1/8":return t/2;case"1/16":return t/4;case"1/32":return t/8}}(v,b.ticksPerBeat),P=!!b.tracks[T].drums,F=(e,i)=>{(0,l.isPlaying)()&&(0,l.updatePlaybackSongAsync)(e);const n=t.getCurrentValue();t.updateValue(Object.assign(Object.assign({},n),{song:e}),{preserveUndo:!0,pushUndo:i}),M.current&&(M.current.editing=e)},U=()=>{var e,t;let i;return O(void 0),"move"===(null===(e=null==M?void 0:M.current)||void 0===e?void 0:e.dragType)?i=(0,d.unselectAllNotes)(M.current.editing):(0,d.findSelectedRange)(b)&&(i=(0,d.unselectAllNotes)(b)),i&&(F(i,!0),"move"===(null===(t=null==M?void 0:M.current)||void 0===t?void 0:t.dragType)&&(M.current=void 0)),i},H=e=>{N(w?Object.assign(Object.assign({},w),{tick:e}):{tick:e,gridTicks:B,track:T,bassClef:!1,hideTracksActive:I,selection:A})};return(0,n.jsxs)("div",Object.assign({className:"music-editor"},{children:[(0,n.jsx)(h.TrackSelector,{song:b,selected:T,onTrackSelected:e=>{U(),x(!1);const t=b.tracks[e];t.drums?pxsim.music.playDrumAsync(t.drums[0]):pxsim.music.playNoteAsync((0,d.rowToNote)(t.instrument.octave,6,!1,!!t.drums).note,t.instrument,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,b.ticksPerBeat/2)),E(e),w&&N(Object.assign(Object.assign({},w),{track:e})),k&&C(!1)},eraserActive:k,onEraserClick:()=>{U(),x(!1),C(!k)},hideTracksActive:I,onHideTracksClick:()=>{U(),x(!1),S(!I)},selectedResolution:v,onResolutionSelected:y}),(0,n.jsx)(u.ScrollableWorkspace,{song:b,selectedTrack:T,eraserActive:k,onWorkspaceClick:(e,t)=>{x(!1);const i=b.tracks[T],n=i.instrument,s=(0,d.findPreviousNoteEvent)(b,T,e.tick),o=(0,d.findPreviousNoteEvent)(b,T,e.exactTick);U(),H(e.tick);const r=t=>(0,d.isBassClefNote)(n.octave,t,P)===e.isBassClef&&(0,d.noteToRow)(n.octave,t,P)===e.row;let a,l;if((null==o?void 0:o.startTick)===e.exactTick&&o.notes.some(r)?(a=e.exactTick,l=o):(null==s?void 0:s.startTick)===e.tick&&s.notes.some(r)&&(a=e.tick,l=s),l){const i=(0,d.unselectAllNotes)(b);if(t&&!P){const t=l.notes.find(r),s=12*n.octave-20,o=12*n.octave+20,c=(0,d.removeNoteAtRowFromTrack)(i,T,e.row,e.isBassClef,a);let u;u="normal"===t.enharmonicSpelling&&t.note<o?"sharp":"sharp"===t.enharmonicSpelling&&t.note>s||t.note===o?"flat":"normal";const h=(0,d.rowToNote)(n.octave,e.row,e.isBassClef,P,u);F((0,d.addNoteToTrack)(c,T,h,l.startTick,l.endTick),!0),pxsim.music.playNoteAsync(h.note,n,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,l.endTick-l.startTick))}else F((0,d.removeNoteAtRowFromTrack)(i,T,e.row,e.isBassClef,a),!0)}else{if(k){let t=b,i=!1;for(let n=0;n<b.tracks.length;n++){if(I&&n!==T)continue;const s=b.tracks[n],o=s.instrument,r=!!s.drums,a=t=>(0,d.isBassClefNote)(o.octave,t,r)===e.isBassClef&&(0,d.noteToRow)(o.octave,t,r)===e.row;for(const s of(0,d.findNoteEventsOverlappingRange)(b,n,e.exactTick-1,e.exactTick+1))s.notes.some(a)&&(t=(0,d.removeNoteAtRowFromTrack)(t,n,e.row,e.isBassClef,s.startTick),i=!0)}return void(i&&F(t,!1))}{const t=(0,d.rowToNote)(n.octave,e.row,e.isBassClef,P),s=b.beatsPerMeasure*b.ticksPerBeat*b.measures;if(e.tick===s)return;const o=P?1:B;F((0,d.unselectAllNotes)((0,d.addNoteToTrack)(b,T,t,e.tick,e.tick+o)),!0),P?pxsim.music.playDrumAsync(i.drums[t.note]):pxsim.music.playNoteAsync(t.note,n,pxsim.music.tickToMs(b.beatsPerMinute,b.ticksPerBeat,B))}}},onWorkspaceDragStart:()=>{if(x(!1),M.current)return M.current.editing=b,M.current.original=b,void(M.current.selectionAtDragStart=A&&Object.assign({},A));M.current={editing:b,original:b,selectionAtDragStart:A&&Object.assign({},A)}},onWorkspaceDragEnd:()=>{if("move"===M.current.dragType){const e=M.current.dragEnd.tick-M.current.dragStart.tick,t=M.current.dragEnd.row-(M.current.dragEnd.isBassClef?12:0)-(M.current.dragStart.row-(M.current.dragStart.isBassClef?12:0));return O(Object.assign(Object.assign({},M.current.selectionAtDragStart),{deltaTick:M.current.selectionAtDragStart.deltaTick+e,transpose:M.current.selectionAtDragStart.transpose+t})),M.current.dragStart=void 0,M.current.dragEnd=void 0,void(M.current.selectionAtDragStart=void 0)}if("note-length"===M.current.dragType&&U(),pxt.assets.music.songEquals(M.current.editing,M.current.original)||F(M.current.editing,!0),"marquee"===M.current.dragType){const e=(0,d.findSelectedRange)(M.current.editing,B);O(e?{startTick:e.start,endTick:e.end,deltaTick:0,transpose:0,originalSong:M.current.editing}:void 0)}M.current=void 0},onWorkspaceDrag:(e,t)=>{if(H(t.tick),k){if(t.row>11||t.row<0)return;const e=M.current.dragEnd||t;M.current.dragEnd=t;let i=b,n=!1;const s=11-e.row+(e.isBassClef?12:0),o=11-t.row+(t.isBassClef?12:0);return pxt.Util.bresenhamLine(e.tick,s,t.tick,o,(e,t)=>{const s={tick:e,exactTick:e,isBassClef:t>=12,row:11-t%12};for(let e=0;e<b.tracks.length;e++){if(I&&e!==T)continue;const t=b.tracks[e],o=t.instrument,r=!!t.drums,a=e=>(0,d.isBassClefNote)(o.octave,e,r)===s.isBassClef&&(0,d.noteToRow)(o.octave,e,r)===s.row;for(const t of(0,d.findNoteEventsOverlappingRange)(b,e,s.exactTick-1,s.exactTick+1))t.notes.some(a)&&(i=(0,d.removeNoteAtRowFromTrack)(i,e,s.row,s.isBassClef,t.startTick),n=!0)}}),void(n&&F(i,!1))}if(M.current.dragType=void 0,M.current.dragStart=e,M.current.dragEnd=t,M.current.original.tracks[T].drums)return void F((0,d.fillDrums)(M.current.original,T,e.row,e.isBassClef,e.tick,t.tick,B),!1);if(M.current.selectionAtDragStart){const i=(0,d.findNoteEventAtPosition)(M.current.original,e,I?T:void 0);if(null==i?void 0:i.selected){M.current.dragType="move";const i=t.tick-e.tick,n=t.row-(t.isBassClef?12:0)-(e.row-(e.isBassClef?12:0)),s=Object.assign(Object.assign({},M.current.selectionAtDragStart),{deltaTick:i+M.current.selectionAtDragStart.deltaTick,transpose:n+M.current.selectionAtDragStart.transpose}),o=(0,d.applySelection)(s,I?T:void 0);return F(o,!1),void O(s)}}const i=(0,d.findPreviousNoteEvent)(M.current.original,T,e.exactTick);if(!P&&i&&e.exactTick>=i.startTick&&e.exactTick<i.endTick){let n=!1;for(const t of i.notes)if((0,d.noteToRow)(b.tracks[T].instrument.octave,t,!1)===e.row){n=!0;break}if(n){if(t.tick<i.startTick+1)return;return O(void 0),M.current.dragType="note-length",void F((0,d.editNoteEventLength)(M.current.original,T,i.startTick,t.tick),!1)}}O({startTick:e.tick,endTick:t.tick,deltaTick:0,transpose:0,originalSong:M.current.editing}),F((0,d.selectNoteEventsInRange)(M.current.original,e.tick,t.tick,I?T:void 0),!1),M.current.dragType="marquee"},gridTicks:B,hideUnselectedTracks:I,showBassClef:L,selection:A,cursor:R?w:void 0,onKeydown:e=>{x(!0);let t=w;t||(t={tick:0,gridTicks:B,track:T,bassClef:!1,hideTracksActive:I,selection:A}),t.gridTicks=B,t.track=T,t.selection=A,t.hideTracksActive=I;const[i,n]=(0,a.handleKeyboardEvent)(b,t,e);pxt.assets.music.songEquals(i,b)||F(i,!n.selection),n.selection?O(n.selection):O(void 0),N(n)}}),(0,n.jsx)(c.PlaybackControls,{beatsPerMinute:b.beatsPerMinute,measures:b.measures,onControlsClick:e=>{"play"===e?(0,l.startPlaybackAsync)(b,!1,0):"loop"===e?(0,l.startPlaybackAsync)(b,!0,0):(0,l.stopPlayback)()},onTempoChange:e=>{U(),x(!1),F(Object.assign(Object.assign({},b),{beatsPerMinute:e}),!0)},onMeasuresChanged:e=>{U(),x(!1),F((0,d.changeSongLength)(b,e),!0)},onUndoClick:()=>{t.undo()},onRedoClick:()=>{t.redo()},showBassClef:L,onBassClefCheckboxClick:D,hasUndo:m,hasRedo:_}),(0,n.jsx)(r.EditControls,{assetName:f.meta.displayName,onAssetNameChanged:i,onDoneClicked:p,hideDoneButton:g})]}))}},{"./AssetModel":206,"./EditControls":207,"./PlaybackControls":211,"./ScrollableWorkspace":212,"./TrackSelector":215,"./keyboardNavigation":218,"./playback":219,"./utils":221,react:304,"react/jsx-runtime":305}],209:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Note=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/util"),o=e("./svgConstants"),r=e("./utils");i.Note=e=>{const{row:t,iconURI:i,length:a,opacity:l,enharmonicSpelling:c,isBassClef:u,selected:h,cursorHighlighted:d}=e;return(0,n.jsxs)("g",Object.assign({className:(0,s.classList)("music-staff-note",h&&"selected",d&&"cursor-highlighted"),transform:`translate(${-o.NOTE_ICON_WIDTH/2}, ${(0,o.rowY)(t,u)-o.NOTE_ICON_WIDTH/2})`},{children:[0===t&&(0,n.jsx)("line",{className:"music-staff-row",x1:-o.NOTE_ICON_WIDTH/2,y1:o.NOTE_ICON_WIDTH/2,x2:3*o.NOTE_ICON_WIDTH/2,y2:o.NOTE_ICON_WIDTH/2,opacity:l}),!!a&&(0,n.jsx)("rect",{x:o.NOTE_ICON_WIDTH/2,y:o.NOTE_ICON_WIDTH/2-o.NOTE_DURATION_HEIGHT/2,width:a,height:o.NOTE_DURATION_HEIGHT}),(0,n.jsx)("image",Object.assign({x:0,y:0,width:o.NOTE_ICON_WIDTH,height:o.NOTE_ICON_WIDTH,href:(0,r.resolveImageURL)(i),opacity:l},{children:(0,n.jsx)("animate",{attributeName:"y",values:"0;-7;-10;-7;0",dur:"0.25s",repeatCount:"1",begin:"indefinite"})})),c&&"normal"!==c&&(0,n.jsx)("text",Object.assign({x:o.NOTE_ICON_WIDTH,y:0,fontSize:o.NOTE_ICON_WIDTH/2},{children:"sharp"===c?"♯":"♭"}))]}))}},{"../../../../react-common/components/util":171,"./svgConstants":220,"./utils":221,"react/jsx-runtime":305}],210:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.NoteGroup=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./Note"),r=e("./playback"),a=e("./svgConstants"),l=e("./utils");i.NoteGroup=e=>{const{song:t,noteEvent:i,octave:c,iconURI:u,isDrumTrack:h,cursor:d}=e;let p;const g="music-note-playing";s.useEffect(()=>{let e=!1;const t=t=>{if(t>=i.startTick&&t<i.endTick){if(!e){e=!0,p.classList.add(g);const t=p.querySelectorAll("animate");for(let e=0;e<t.length;e++)t.item(e).beginElement()}}else e&&(e=!1,p.classList.remove(g))},n=()=>{e&&(e=!1,p.classList.remove(g))};return(0,r.addTickListener)(t),(0,r.addPlaybackStateListener)(n),()=>{(0,r.removeTickListener)(t),(0,r.removePlaybackStateListener)(n),p.classList.remove(g)}},[i]);const f=(0,a.tickToX)(t.ticksPerBeat,i.startTick),m=h?0:(0,a.tickToX)(t.ticksPerBeat,i.endTick)-f,_=(null==d?void 0:d.tick)===i.startTick;return(0,n.jsx)("g",Object.assign({className:"music-staff-note-group",transform:`translate(${f}, 0)`,ref:e=>{e&&(p=e)}},{children:i.notes.map((e,t)=>{const s=(0,l.isBassClefNote)(c,e,h),r=(0,l.noteToRow)(c,e,h);return(0,n.jsx)(o.Note,{isBassClef:s,row:r,enharmonicSpelling:e.enharmonicSpelling,iconURI:u,length:m,selected:i.selected,cursorHighlighted:_&&d.noteGroupIndex===t},t)})}))}},{"./Note":209,"./playback":219,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],211:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PlaybackControls=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/controls/Button"),r=e("../../../../react-common/components/controls/Checkbox"),a=e("../../../../react-common/components/controls/Input"),l=e("../../../../react-common/components/util"),c=e("./playback");function u(e,t){if(!e)return e;const i=parseFloat(e);return isNaN(i)?t:Math.min(500,Math.max(20,Math.floor(i))).toString()}function h(e,t){if(!e)return e;const i=parseInt(e);return isNaN(i)?t:Math.max(1,Math.min(i,50)).toString()}i.PlaybackControls=e=>{const{measures:t,beatsPerMinute:i,onControlsClick:d,onTempoChange:p,onMeasuresChanged:g,onUndoClick:f,onRedoClick:m,hasUndo:_,hasRedo:b,showBassClef:T,hideBassClefOption:E,onBassClefCheckboxClick:v,singlePlayButton:y}=e,[k,C]=s.useState("stop");s.useEffect(()=>{const e=e=>{C(e)};return(0,c.addPlaybackStateListener)(e),()=>(0,c.removePlaybackStateListener)(e)},[]);const I=()=>{d("stop"),C("stop")},S=()=>{(0,c.isLooping)()||((0,c.isPlaying)()?(0,c.setLooping)(!0):d("loop"),C("loop"))},A=e=>{let t=parseFloat(e);Number.isNaN(t)||(t=Math.min(500,Math.max(20,Math.floor(t))),p(t))},O=e=>{let t=parseInt(e);isNaN(t)||t<1||t>50||g(t)};return(0,n.jsxs)("div",Object.assign({className:"music-playback-controls"},{children:[(0,n.jsxs)("div",Object.assign({className:"music-playback-buttons"},{children:[!y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(o.Button,{className:"square-button",title:lf("Stop"),leftIcon:"fas fa-stop",onClick:I}),(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","play"===k&&"green"),title:lf("Play"),leftIcon:"fas fa-play",onClick:()=>{d("play"),C("play")}}),(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","loop"===k&&"green"),title:lf("Loop"),leftIcon:"fas fa-retweet",onClick:S})]}),y&&(0,n.jsx)(o.Button,{className:(0,l.classList)("square-button","stop"!==k&&"green"),title:lf("Play"),leftIcon:"stop"===k?"fas fa-play":"fas fa-stop",onClick:"stop"===k?S:I})]})),(0,n.jsx)(a.Input,{id:"music-playback-tempo-input music-editor-label",label:lf("Tempo:"),initialValue:i.toString(),onBlur:A,onEnterKey:A,validator:u}),(0,n.jsx)("div",{className:"spacer"}),!E&&(0,n.jsx)(r.Checkbox,{className:"music-editor-label",id:"show-bass-clef",label:lf("Show bass clef"),isChecked:T,onChange:v}),(0,n.jsxs)("div",Object.assign({className:"music-undo-redo common-button-group"},{children:[(0,n.jsx)(o.Button,{className:"square-button purple",title:lf("Undo"),leftIcon:"xicon undo",disabled:!_,onClick:f}),(0,n.jsx)(o.Button,{className:"square-button purple",title:lf("Redo"),leftIcon:"xicon redo",disabled:!b,onClick:m})]})),(0,n.jsxs)("div",Object.assign({className:"music-playback-measures"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:lf("Measures:")})),(0,n.jsx)(o.Button,{className:"menu-button",title:lf("Remove measure"),leftIcon:"fas fa-minus-circle",onClick:()=>{t>1&&g(t-1)}}),(0,n.jsx)(a.Input,{id:"music-playback-measures-input",initialValue:t.toString(),onBlur:O,onEnterKey:O,validator:h}),(0,n.jsx)(o.Button,{className:"menu-button",title:lf("Add measure"),leftIcon:"fas fa-plus-circle",onClick:()=>{t<50&&g(t+1)}})]}))]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Input":168,"../../../../react-common/components/util":171,"./playback":219,react:304,"react/jsx-runtime":305}],212:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ScrollableWorkspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("./svgConstants"),r=e("./utils"),a=e("./Workspace");i.ScrollableWorkspace=e=>{const{cursor:t,song:i}=e,l=s.useRef(null);return s.useEffect(()=>{if(!t)return;const e=(0,o.tickToX)(i.ticksPerBeat,t.tick),n=l.current.querySelector("svg"),s=e=>{const t=n.createSVGPoint();return t.x=e,t.y=0,t.matrixTransform(n.getScreenCTM()).x},a=s(e),c=(0,r.findNoteEventAtTick)(i,t.track,t.tick),u=s(e+o.BEAT_WIDTH)-a;let h;h=c?s((0,o.tickToX)(i.ticksPerBeat,c.endTick+i.ticksPerBeat/2))-a:u;const d=l.current.getBoundingClientRect(),p=a-d.x,g=p+h;p<u?l.current.scrollLeft+=p-u:h<d.width&&g>d.width&&(l.current.scrollLeft+=g-d.width)},[null==t?void 0:t.tick,i.ticksPerBeat]),(0,n.jsx)("div",Object.assign({ref:l,className:"music-scrollable-workspace"},{children:(0,n.jsx)("div",Object.assign({className:"music-scroller"},{children:(0,n.jsx)(a.Workspace,Object.assign({},e))}))}))}},{"./Workspace":216,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],213:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Staff=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("./playback"),a=e("./svgConstants"),l=e("./utils");i.Staff=e=>{const{top:t,isBassClef:i,gridTicks:c,ticksPerBeat:u,beatsPerMeasure:h,beatsPerMinute:d,measures:p}=e;let g;s.useEffect(()=>{const e=pxsim.music.tickToMs(d,u,1),t=(0,a.tickToX)(u,2)-(0,a.tickToX)(u,1);let i,n,s=0,o=!1;const l=e=>{s=(0,a.tickToX)(u,e),n=Date.now(),o||(o=!0,g.style.display="unset",i=requestAnimationFrame(h))},c=()=>{o=!1,g.style.display="none",i&&cancelAnimationFrame(i)},h=()=>{const r=s+t*(Date.now()-n)/e;g.setAttribute("transform",`translate(${r}, 0)`),o&&(i=requestAnimationFrame(h))};return(0,r.addTickListener)(l),(0,r.addPlaybackStateListener)(c),()=>{(0,r.removeTickListener)(l),(0,r.removePlaybackStateListener)(c),i&&cancelAnimationFrame(i)}},[u,d]);const f=(0,a.workspaceWidth)(p,h),m=[];for(let e=0;e<5;e++)m.push((0,n.jsx)("line",{className:"music-staff-row",x1:0,y1:(0,a.rowY)(2*e+2,!1),x2:f,y2:(0,a.rowY)(2*e+2,!1)},e));const _=[],b=c;for(let e=0;e<p*h*u;e+=b){const t=e%u===0,s=e%(h*u)===0,r=!t&&!s;_.push((0,n.jsxs)("g",{children:[s&&!i&&(0,n.jsx)("text",Object.assign({x:(0,a.tickToX)(u,e),y:a.STAFF_HEADER_HEIGHT-a.STAFF_HEADER_OFFSET,textAnchor:"middle",fontSize:a.STAFF_HEADER_FONT_SIZE},{children:Math.floor(e/(h*u))+1})),(0,n.jsx)("line",{className:"music-staff-column",x1:(0,a.tickToX)(u,e),y1:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,x2:(0,a.tickToX)(u,e),y2:a.STAFF_HEADER_HEIGHT}),!r&&(0,n.jsx)("line",{className:(0,o.classList)("music-staff-column",t&&"beat-start",s&&"measure-start"),x1:(0,a.tickToX)(u,e),y1:i&&s?0:a.STAFF_HEADER_HEIGHT,x2:(0,a.tickToX)(u,e),y2:a.WORKSPACE_HEIGHT})]},e))}return(0,n.jsxs)("g",Object.assign({className:"music-staff",transform:`translate(0 ${t})`},{children:[(0,n.jsx)("rect",{className:"music-staff-background",x:0,y:a.STAFF_HEADER_HEIGHT,width:f,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("image",{className:"music-staff-clef",href:(0,l.resolveImageURL)(i?"music-editor/bass-clef.svg":"music-editor/treble-clef.svg"),height:i?a.BASS_CLEF_HEIGHT:a.CLEF_HEIGHT,x:0,y:i?a.BASS_CLEF_TOP:a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{fill:"#000",x:0,y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,width:f,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("rect",{fill:"#dedede",x:a.CLEF_WIDTH,y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,width:f-a.CLEF_WIDTH-a.STAFF_END_WIDTH,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("g",Object.assign({className:"music-staff-rows"},{children:m})),(0,n.jsx)("g",Object.assign({className:"music-staff-beats"},{children:_})),(0,n.jsxs)("g",Object.assign({className:"music-staff-end"},{children:[(0,n.jsx)("rect",{x:f-a.STAFF_END_WIDTH,y:a.STAFF_HEADER_HEIGHT,width:3,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{x:f-12,y:a.STAFF_HEADER_HEIGHT,width:12,height:a.WORKSPACE_HEIGHT-a.STAFF_HEADER_HEIGHT})]})),(0,n.jsx)("g",Object.assign({className:"music-playback-head",ref:e=>{e&&(g=e)}},{children:(0,n.jsx)("line",{className:"music-playback-line",x1:0,y1:a.STAFF_HEADER_HEIGHT,x2:0,y2:a.WORKSPACE_HEIGHT})}))]}))}},{"../../../../react-common/components/util":171,"./playback":219,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],214:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Track=void 0;const n=e("react/jsx-runtime"),s=e("./NoteGroup"),o=e("./svgConstants");i.Track=e=>{const{song:t,track:i,keyboardCursor:a}=e;return(0,n.jsxs)("g",Object.assign({className:"music-staff-track"},{children:[a&&(0,n.jsx)("g",{children:(0,n.jsx)("rect",{x:(0,o.tickToX)(t.ticksPerBeat,a.tick),y:a.bassClef?o.BASS_STAFF_TOP+o.STAFF_HEADER_HEIGHT:o.STAFF_HEADER_HEIGHT,width:5,height:o.WORKSPACE_HEIGHT-o.STAFF_HEADER_HEIGHT,fill:"purple"})}),i.notes.map(e=>(0,n.jsx)(s.NoteGroup,{noteEvent:e,octave:i.instrument.octave,song:t,iconURI:i.iconURI,isDrumTrack:!!i.drums,cursor:a},r(e)))]}))};const r=e=>`${e.startTick}-${e.endTick}-${e.notes.map(e=>e.note+e.enharmonicSpelling).join("-")}`},{"./NoteGroup":210,"./svgConstants":220,"react/jsx-runtime":305}],215:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TrackSelector=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Button"),o=e("../../../../react-common/components/controls/Checkbox"),r=e("../../../../react-common/components/controls/Dropdown"),a=e("../../../../react-common/components/controls/FocusList"),l=e("../../../../react-common/components/util"),c=e("./utils"),u={four:"1/4",eight:"1/8",sixteen:"1/16",thirtytwo:"1/32"};i.TrackSelector=e=>{const{song:t,selected:i,onTrackSelected:h,selectedResolution:d,onResolutionSelected:p,eraserActive:g,onEraserClick:f,hideTracksActive:m,onHideTracksClick:_}=e,b=[{title:lf("1/4 Note"),label:lf("1/4"),id:"four"},{title:lf("1/8 Note"),label:lf("1/8"),id:"eight"},{title:lf("1/16 Note"),label:lf("1/16"),id:"sixteen"},{title:lf("1/32 Note"),label:lf("1/32"),id:"thirtytwo"}];return(0,n.jsxs)("div",Object.assign({className:"music-track-selector"},{children:[(0,n.jsxs)(a.FocusList,Object.assign({role:"radiogroup",ariaLabel:lf("Track selection")},{children:[t.tracks.map((e,o)=>(0,n.jsx)(s.Button,{role:"radio",ariaSelected:i===o&&!g,ariaPosInSet:o+1,ariaSetSize:t.tracks.length+1,title:e.name,className:(0,l.classList)("music-track-button square-button pixellated",i===o&&!g&&"selected"),label:(0,n.jsx)("img",{src:(0,c.resolveImageURL)(e.iconURI),alt:e.name}),onClick:()=>(e=>{h(e)})(o)},e.name)),(0,n.jsx)(s.Button,{className:(0,l.classList)("music-track-button square-button",g&&"selected"),title:g?lf("Turn off eraser tool"):lf("Turn on eraser tool"),leftIcon:"fas fa-eraser",ariaSelected:g,ariaPosInSet:t.tracks.length,ariaSetSize:t.tracks.length+1,onClick:f})]})),(0,n.jsx)(o.Checkbox,{className:"music-editor-label",id:"hide-tracks",label:lf("Only show selected instrument"),isChecked:m,onChange:_}),(0,n.jsxs)("div",Object.assign({className:"music-track-grid"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:lf("Grid:")})),(0,n.jsx)(r.Dropdown,{id:"grid-resolution",ariaLabel:lf("Staff grid resolution"),items:b,selectedId:Object.keys(u).find(e=>u[e]===d),onItemSelected:e=>{p(u[e])}})]}))]}))}},{"../../../../react-common/components/controls/Button":159,"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Dropdown":162,"../../../../react-common/components/controls/FocusList":164,"../../../../react-common/components/util":171,"./utils":221,"react/jsx-runtime":305}],216:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Workspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("./Staff"),a=e("./svgConstants"),l=e("./Track"),c=e("./utils"),u=e("./WorkspaceSelection");function h(e,t,i,n){const s=(0,o.screenToSVGCoord)(t,(0,o.clientCoord)(e)),r=s.y>a.BASS_STAFF_TOP,l=(0,a.closestTick)(i.ticksPerBeat,s.x+a.BEAT_WIDTH/i.ticksPerBeat,n);return{isBassClef:r,row:(0,a.closestRow)(s.y),tick:l,exactTick:(0,a.closestTick)(i.ticksPerBeat,s.x,1)}}i.Workspace=e=>{const{song:t,onWorkspaceClick:i,gridTicks:d,selectedTrack:p,onWorkspaceDrag:g,onWorkspaceDragStart:f,onWorkspaceDragEnd:m,onKeydown:_,cursor:b,hideUnselectedTracks:T,eraserActive:E,showBassClef:v,selection:y}=e,[k,C]=s.useState(null),[I,S]=s.useState(!1);let A;const O=s.useRef(null),w=s.useRef(null),N=s.useRef(null),R=s.useRef(null);s.useEffect(()=>{const e=e=>{O.current=e;const i=O.current;let n,s,o=I||E?void 0:i;const r=i&&(0,c.findNoteEventAtTick)(t,p,i.tick),l=k&&(0,c.findNoteEventAtTick)(t,p,k.tick);y?(n=y.startTick+y.deltaTick,s=y.endTick+y.deltaTick):!E&&l&&(null==i?void 0:i.tick)>=l.startTick?(n=l.startTick,s=l.endTick):!E&&I&&i&&k?(n=Math.min(i.tick,k.tick),s=Math.max(i.tick,k.tick)):r?(n=r.startTick,s=r.endTick):i&&(n=i.tick,s=i.tick+d),r&&o&&(o=Object.assign(Object.assign({},o),{tick:r.startTick})),w.current&&(w.current.setAttribute("x",`${void 0!==n?(0,a.tickToX)(t.ticksPerBeat,n):-1e3}`),w.current.setAttribute("width",""+(void 0!==s?(0,a.tickToX)(t.ticksPerBeat,s)-(0,a.tickToX)(t.ticksPerBeat,n):0))),N.current&&(N.current.setAttribute("x",`${void 0!==n?(0,a.tickToX)(t.ticksPerBeat,n):-1e3}`),N.current.setAttribute("width",""+(void 0!==s?(0,a.tickToX)(t.ticksPerBeat,s)-(0,a.tickToX)(t.ticksPerBeat,n):0))),R.current&&(o?(R.current.setAttribute("x",""+((0,a.tickToX)(t.ticksPerBeat,o.tick)-a.NOTE_ICON_WIDTH/2)),R.current.setAttribute("y",""+((0,a.rowY)(o.row,o.isBassClef)-a.NOTE_ICON_WIDTH/2)),R.current.style.display="block"):R.current.style.display="none")};e(O.current),A.onpointerdown=e=>{e.preventDefault(),A.focus();const i=h(e,A,t,d);(E||i.tick>=0&&i.row>=0&&i.row<12)&&C(i)},A.onpointermove=i=>{const n=h(i,A,t,d),s=O.current;if(s&&s.exactTick===n.exactTick&&s.row===n.row)return;const o=t.beatsPerMeasure*t.ticksPerBeat*t.measures;n.tick>=0&&n.row>=0&&n.row<12&&n.tick<=o?(k&&(I||(S(!0),f(),g(k,k)),g(k,n)),n.tick<o?e(n):e(null)):e(null)},A.onpointerleave=t=>{e(null),I&&(m(),S(!1))},A.onpointerup=e=>{C(null);const n=h(e,A,t,d),s=n.tick>=0&&n.row>=0&&n.row<12;I?(s&&g(k,n),m(),S(!1)):s&&i(n,e.ctrlKey)}},[k,I,g,m,f,t,p,d,E,b]);const x=t.tracks.filter((e,t)=>t!==p),L=v?2*a.WORKSPACE_HEIGHT:a.WORKSPACE_HEIGHT,D=pxt.assets.music.getSongInfo(t),M=(0,a.workspaceWidth)(t.measures,t.beatsPerMeasure)+20;return(0,n.jsxs)("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",className:(0,o.classList)("music-workspace",E&&"erasing"),viewBox:`0 0 ${M} ${L}`,"aria-label":lf("Music Workspace"),tabIndex:0,onKeyDown:_,ref:e=>{e&&(A=e)}},{children:[(0,n.jsxs)("filter",Object.assign({id:"selection-outline"},{children:[(0,n.jsx)("feMorphology",{in:"SourceAlpha",result:"DILATED",operator:"dilate",radius:"4"}),(0,n.jsx)("feFlood",{floodColor:"yellow",floodOpacity:"1",result:"FLOODED"}),(0,n.jsx)("feComposite",{in:"FLOODED",in2:"DILATED",operator:"in",result:"OUTLINE"}),(0,n.jsxs)("feMerge",{children:[(0,n.jsx)("feMergeNode",{in:"OUTLINE"}),(0,n.jsx)("feMergeNode",{in:"SourceGraphic"})]})]})),(0,n.jsxs)("filter",Object.assign({id:"cursor-outline"},{children:[(0,n.jsx)("feMorphology",{in:"SourceAlpha",result:"DILATED",operator:"dilate",radius:"4"}),(0,n.jsx)("feFlood",{floodColor:"purple",floodOpacity:"1",result:"FLOODED"}),(0,n.jsx)("feComposite",{in:"FLOODED",in2:"DILATED",operator:"in",result:"OUTLINE"}),(0,n.jsxs)("feMerge",{children:[(0,n.jsx)("feMergeNode",{in:"OUTLINE"}),(0,n.jsx)("feMergeNode",{in:"SourceGraphic"})]})]})),(0,n.jsx)("rect",{x:"0",y:"0",width:M,height:L,fill:"#FFFFFF",opacity:0}),(0,n.jsx)(r.Staff,Object.assign({},D,{top:0,gridTicks:d})),v&&(0,n.jsx)(r.Staff,Object.assign({},D,{top:a.BASS_STAFF_TOP,isBassClef:!0,gridTicks:d})),(0,n.jsx)("rect",{ref:w,fill:"#03adfc",y:a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,height:a.STAFF_GRID_TICK_HEIGHT}),(0,n.jsx)("rect",{ref:N,fill:"#03adfc",y:a.BASS_STAFF_TOP+a.STAFF_HEADER_HEIGHT-a.STAFF_GRID_TICK_HEIGHT,height:a.STAFF_GRID_TICK_HEIGHT}),y&&(0,n.jsx)(u.WorkspaceSelection,Object.assign({},D,{range:y})),!T&&x.map((e,i)=>(0,n.jsx)(l.Track,{track:e,song:t},i)),(0,n.jsx)(l.Track,{track:t.tracks[p],song:t,keyboardCursor:b}),(0,n.jsx)("g",Object.assign({className:"music-staff-note"},{children:(0,n.jsx)("image",{ref:R,width:a.NOTE_ICON_WIDTH,height:a.NOTE_ICON_WIDTH,href:(0,c.resolveImageURL)(t.tracks[p].iconURI),style:{display:"none"},opacity:.5})}))]}))}},{"../../../../react-common/components/util":171,"./Staff":213,"./Track":214,"./WorkspaceSelection":217,"./svgConstants":220,"./utils":221,react:304,"react/jsx-runtime":305}],217:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.WorkspaceSelection=void 0;const n=e("react/jsx-runtime"),s=e("./svgConstants");i.WorkspaceSelection=e=>{const{range:t,ticksPerBeat:i}=e,o=(0,s.tickToX)(i,t.startTick+t.deltaTick),r=(0,s.tickToX)(i,t.endTick+t.deltaTick);return(0,n.jsxs)("g",{children:[(0,n.jsx)("rect",{className:"music-workspace-selection",fill:"#03adfc",opacity:.5,x:Math.min(o,r),y:s.STAFF_HEADER_HEIGHT,width:Math.max(o,r)-Math.min(o,r),height:s.WORKSPACE_HEIGHT-s.STAFF_HEADER_HEIGHT}),(0,n.jsx)("rect",{className:"music-workspace-selection",fill:"#03adfc",opacity:.5,x:Math.min(o,r),y:s.BASS_STAFF_TOP+s.STAFF_HEADER_HEIGHT,width:Math.max(o,r)-Math.min(o,r),height:s.WORKSPACE_HEIGHT-s.STAFF_HEADER_HEIGHT})]})}},{"./svgConstants":220,"react/jsx-runtime":305}],218:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.handleKeyboardEvent=void 0;const n=e("./playback"),s=e("./utils");i.handleKeyboardEvent=function(e,t,i){const o=i.ctrlKey||i.metaKey,r=i.shiftKey,a=i.altKey,l=t.selection?void 0:(0,s.findNoteEventAtTick)(e,t.track,t.tick);(null==l?void 0:l.startTick)===t.tick&&void 0===t.noteGroupIndex&&(t.noteGroupIndex=0);let c=e,u=Object.assign(Object.assign({},t),{selection:t.selection&&Object.assign({},t.selection)});const h=e.tracks[t.track].instrument,d=h.octave,p=e.ticksPerBeat*e.beatsPerMeasure,g=p*e.measures,f=!!t.selection,m=!!e.tracks[t.track].drums,_=e=>{u.selection&&(c=(0,s.applySelection)(u.selection,t.hideTracksActive?t.track:void 0),e&&(c=(0,s.unselectAllNotes)(c)),delete u.selection)},b=t=>{for(const i of t.notes)pxsim.music.playNoteAsync(i.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,t.endTick-t.startTick))};switch(i.key){case"ArrowUp":case"Up":if(i.preventDefault(),r){u.bassClef=!1;break}if(u.selection){u.selection.transpose++,c=(0,s.applySelection)(u.selection);break}if(!l)break;if(a&&o)u.noteGroupIndex=l.notes.length-1;else if(a)u.noteGroupIndex=Math.min(t.noteGroupIndex+1,l.notes.length-1);else{let i=l.notes[t.noteGroupIndex],n=(0,s.isBassClefNote)(d,i,m);const r=(0,s.noteToRow)(d,i,m);let a=r;const p=o?12:1;for(;l.notes.some(e=>(0,s.isBassClefNote)(d,e,m)===n&&a===(0,s.noteToRow)(d,e,m));)if(a+=p,a>=12){if(!n)break;n=!1,a-=12}if(a>=12||a<0)break;const g=(0,s.rowToNote)(d,a,n,m,i.enharmonicSpelling);c=(0,s.removeNoteAtRowFromTrack)(c,t.track,r,(0,s.isBassClefNote)(d,i,m),l.startTick),c=(0,s.addNoteToTrack)(c,t.track,g,l.startTick,l.endTick);const f=(0,s.findNoteEventAtTick)(c,t.track,t.tick);u.noteGroupIndex=f.notes.findIndex(e=>e.note===g.note),pxsim.music.playNoteAsync(g.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,f.endTick-f.startTick))}break;case"ArrowDown":case"Down":if(i.preventDefault(),r){u.bassClef=!0;break}if(u.selection){u.selection.transpose--,c=(0,s.applySelection)(u.selection);break}if(!l)break;if(a&&o)u.noteGroupIndex=0;else if(a)u.noteGroupIndex=Math.max(t.noteGroupIndex-1,0);else{let i=l.notes[t.noteGroupIndex];const n=c.tracks[t.track];let r=(0,s.isBassClefNote)(d,i,!!n.drums);const a=(0,s.noteToRow)(d,i,!!n.drums);let p=a;const g=o?-12:-1;for(;l.notes.some(e=>(0,s.isBassClefNote)(d,e,!!n.drums)===r&&p===(0,s.noteToRow)(d,e,!!n.drums));)if(p+=g,p<0){if(r)break;r=!0,p+=12}if(p>=12||p<0)break;const f=(0,s.rowToNote)(d,p,r,!!n.drums,i.enharmonicSpelling);c=(0,s.removeNoteAtRowFromTrack)(c,t.track,a,(0,s.isBassClefNote)(d,i,!!n.drums),l.startTick),c=(0,s.addNoteToTrack)(c,t.track,f,l.startTick,l.endTick);const m=(0,s.findNoteEventAtTick)(c,t.track,t.tick);u.noteGroupIndex=m.notes.findIndex(e=>e.note===f.note),pxsim.music.playNoteAsync(f.note,h,pxsim.music.tickToMs(c.beatsPerMinute,e.ticksPerBeat,m.endTick-m.startTick))}break;case"ArrowLeft":case"Left":if(i.preventDefault(),r&&f&&(u.selection.deltaTick||u.selection.transpose)&&_(!0),o){u.tick%p===0?u.tick=Math.max(u.tick-p,0):u.tick=Math.floor(u.tick/p)*p;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);(null==e?void 0:e.startTick)===u.tick?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0;break}const T=t.tick%t.gridTicks!==0?Math.floor(u.tick/t.gridTicks)*t.gridTicks:t.tick-t.gridTicks,E=(0,s.findPreviousNoteEvent)(c,t.track,t.tick-1);if((null==E?void 0:E.endTick)>T){u.tick=E.startTick,u.noteGroupIndex=0;break}u.tick=Math.max(T,0),u.noteGroupIndex=void 0;break;case"ArrowRight":case"Right":if(i.preventDefault(),r&&f&&(u.selection.deltaTick||u.selection.transpose)&&_(!0),o){u.tick%p===0?u.tick=Math.min(u.tick+p,g-p):(u.tick=Math.min(Math.ceil(u.tick/p)*p,g-p),u.tick>=g&&(u.tick-=p));const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);(null==e?void 0:e.startTick)===u.tick?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0;break}const v=l?Math.ceil(l.endTick/t.gridTicks)*t.gridTicks:t.tick+t.gridTicks,y=(0,s.findNextNoteEvent)(c,t.track,t.tick);if((null==y?void 0:y.startTick)<=v){u.tick=y.startTick,u.noteGroupIndex=0;break}u.tick=Math.min(Math.ceil(v/t.gridTicks)*t.gridTicks,g-t.gridTicks),u.noteGroupIndex=void 0;break;case"End":if(i.preventDefault(),o){u.tick=g-t.gridTicks;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);e?(u.tick=e.startTick,u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0}break;case"Home":if(i.preventDefault(),o){u.tick=0;const e=(0,s.findNoteEventAtTick)(c,t.track,u.tick);e?(u.noteGroupIndex=0,b(e)):u.noteGroupIndex=void 0}break;case"Backspace":if(i.preventDefault(),t.selection)_(),c=(0,s.deleteSelectedNotes)(c);else if(void 0!==t.noteGroupIndex){if(o){c=(0,s.removeNoteEventFromTrack)(c,t.track,t.tick),u.noteGroupIndex=void 0;break}c=(0,s.removeNoteFromTrack)(c,t.track,l.notes[t.noteGroupIndex],l.startTick),1===l.notes.length?u.noteGroupIndex=void 0:u.noteGroupIndex=Math.min(u.noteGroupIndex,l.notes.length-2)}break;case"Enter":f&&_(!0);break;case"Spacebar":case" ":i.preventDefault(),(0,n.isPlaying)()?(0,n.stopPlayback)():r?(0,n.startPlaybackAsync)(e,o,null==t?void 0:t.tick):(0,n.startPlaybackAsync)(e,o,0);break;case"j":case"J":if(e.tracks[t.track].drums)break;if(l){i.preventDefault();const e=l.notes[u.noteGroupIndex],n=12*h.octave-20,o=12*h.octave+20,r=(0,s.noteToRow)(d,e,!1),a=l.startTick,p=(0,s.isBassClefNote)(d,e,!1);let g;c=(0,s.removeNoteAtRowFromTrack)(c,u.track,r,p,a),g="normal"===e.enharmonicSpelling&&e.note<o?"sharp":"sharp"===e.enharmonicSpelling&&e.note>n||e.note===o?"flat":"normal";const f=(0,s.rowToNote)(h.octave,r,p,!1,g);c=(0,s.addNoteToTrack)(c,u.track,f,l.startTick,l.endTick),pxsim.music.playNoteAsync(f.note,h,pxsim.music.tickToMs(c.beatsPerMinute,c.ticksPerBeat,t.gridTicks))}break;default:if(o&&"a"===i.key||"A"===i.key){i.preventDefault(),u.selection&&_(!0),u.selection={startTick:0,endTick:g,originalSong:c,transpose:0,deltaTick:0};break}if(/^[a-g]$/i.test(i.key)){if(o)break;let e;if(i.preventDefault(),_(!0),e=t.bassClef?(0,s.rowToNote)(d,3+"abcdefg".indexOf(i.key.toLowerCase()),!0,m):(0,s.rowToNote)(d,5+"abcdefg".indexOf(i.key.toLowerCase()),!1,m),l){if(-1===l.notes.indexOf(e)){c=(0,s.addNoteToTrack)(c,t.track,e,l.startTick,l.endTick);b((0,s.findNoteEventAtTick)(c,t.track,l.startTick))}}else{c=(0,s.addNoteToTrack)(c,t.track,e,t.tick,t.tick+t.gridTicks),u.noteGroupIndex=0;b((0,s.findNoteEventAtTick)(c,t.track,t.tick))}break}if(/^[1-9]$/.test(i.key)){if(i.preventDefault(),_(!0),l){c=(0,s.editNoteEventLength)(c,t.track,l.startTick,l.startTick+parseInt(i.key)*t.gridTicks);b((0,s.findNoteEventAtTick)(c,t.track,l.startTick))}break}}if(u.tick!==t.tick)if(r)u.selection?u.selection.endTick=u.tick:u.selection={originalSong:e,startTick:t.tick,endTick:u.tick,transpose:0,deltaTick:0},c=(0,s.applySelection)(u.selection,u.hideTracksActive?u.track:void 0);else if(u.selection){const e=(0,s.selectNoteEventsInRange)(u.selection.originalSong,u.selection.startTick,u.selection.endTick,u.hideTracksActive?u.track:void 0),i=(0,s.findSelectedRange)(e,u.gridTicks);i&&(u.selection.startTick=i.start,u.selection.endTick=i.end),u.selection.deltaTick+=u.tick-t.tick,c=(0,s.applySelection)(u.selection,u.hideTracksActive?u.track:void 0),u.selection.startTick+u.selection.deltaTick>0&&(u.tick=u.selection.startTick+u.selection.deltaTick)}return[c,u]}},{"./playback":219,"./utils":221}],219:[function(e,t,i){"use strict";let n;Object.defineProperty(i,"__esModule",{value:!0}),i.NoteTracker=i.removeNoteChangeListener=i.addNoteChangeListener=i.removePlaybackStateListener=i.addPlaybackStateListener=i.removeTickListener=i.addTickListener=i.stopPlayback=i.updatePlaybackSongAsync=i.setLooping=i.isLooping=i.isPlaying=i.startPlaybackAsync=void 0;let s,o,r=[],a=[];function l(){return!!n&&"stop"!==n.state()}function c(e){a.push(e)}function u(e){a=a.filter(t=>e!==t)}function h(e){r.push(e)}function d(e){r=r.filter(t=>e!==t)}i.startPlaybackAsync=async function(e,t,i){s=e,n||(n=new pxsim.music.Sequencer,await n.initAsync(),n.addEventListener("state-change",()=>{for(const e of r)e(n.state())}),n.addEventListener("tick",()=>{for(const e of a)e(n.currentTick())}),n.setVolume(100)),n.startFrom(e,t,i)},i.isPlaying=l,i.isLooping=function(){return l()&&"loop"===n.state()},i.setLooping=function(e){n&&n.setLooping(e)},i.updatePlaybackSongAsync=async function(e){n&&n.updateSong(e),s=e},i.stopPlayback=function(){n&&n.stop()},i.addTickListener=c,i.removeTickListener=u,i.addPlaybackStateListener=h,i.removePlaybackStateListener=d,i.addNoteChangeListener=function(e){o||(o=new p),o.addNoteChangeListener(e)},i.removeNoteChangeListener=function(e){o&&o.removeNoteChangeListener(e)};class p{constructor(){this.activeNotes={},this.noteChangeListeners=[],this.onTick=e=>{var t;const i={};for(let t=0;t<s.tracks.length;t++){i[t]=[];const n=s.tracks[t];for(const s of n.notes){if(s.startTick>e)break;if(s.startTick<=e&&s.endTick>e)for(const e of s.notes)i[t].push(e.note)}}for(let e=0;e<s.tracks.length;e++){const n=this.activeNotes[e]||[],o=i[e]||[],r=null===(t=s.tracks[e])||void 0===t?void 0:t.id;for(const e of n)if(!o.includes(e))for(const t of this.noteChangeListeners)t(r,e,!1);for(const e of o)if(!n.includes(e))for(const t of this.noteChangeListeners)t(r,e,!0)}this.activeNotes=i},this.onPlaybackStateChange=e=>{if("stop"===e){for(const e in this.activeNotes)for(const t of this.activeNotes[e])for(const i of this.noteChangeListeners)i(parseInt(e),t,!1);this.activeNotes={}}},c(this.onTick),h(this.onPlaybackStateChange)}addNoteChangeListener(e){this.noteChangeListeners.push(e)}removeNoteChangeListener(e){this.noteChangeListeners=this.noteChangeListeners.filter(t=>e!==t)}dispose(){u(this.onTick),d(this.onPlaybackStateChange)}getActiveNotes(e){return this.activeNotes[e]||[]}}i.NoteTracker=p},{}],220:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.rowY=i.closestRow=i.closestTick=i.beatToX=i.tickToX=i.workspaceWidth=i.BASS_CLEF_HEIGHT=i.BASS_CLEF_TOP=i.BASS_STAFF_HEADER_HEIGHT=i.BASS_STAFF_TOP=i.NOTE_DURATION_HEIGHT=i.NOTE_ICON_WIDTH=i.WORKSPACE_HEIGHT=i.STAFF_GRID_TICK_HEIGHT=i.STAFF_END_WIDTH=i.STAFF_HEADER_OFFSET=i.STAFF_HEADER_FONT_SIZE=i.STAFF_HEADER_HEIGHT=i.CLEF_HEIGHT=i.CLEF_WIDTH=i.STAFF_ROW_HEIGHT=i.BEAT_WIDTH=void 0,i.BEAT_WIDTH=150,i.STAFF_ROW_HEIGHT=50,i.CLEF_WIDTH=250,i.CLEF_HEIGHT=320,i.STAFF_HEADER_HEIGHT=i.STAFF_ROW_HEIGHT,i.STAFF_HEADER_FONT_SIZE=40,i.STAFF_HEADER_OFFSET=11,i.STAFF_END_WIDTH=25,i.STAFF_GRID_TICK_HEIGHT=7,i.WORKSPACE_HEIGHT=i.STAFF_HEADER_HEIGHT+7*i.STAFF_ROW_HEIGHT,i.NOTE_ICON_WIDTH=45,i.NOTE_DURATION_HEIGHT=i.NOTE_ICON_WIDTH/3,i.BASS_STAFF_TOP=i.WORKSPACE_HEIGHT,i.BASS_STAFF_HEADER_HEIGHT=i.STAFF_ROW_HEIGHT/2,i.BASS_CLEF_TOP=90,i.BASS_CLEF_HEIGHT=230,i.workspaceWidth=function(e,t){return i.CLEF_WIDTH+e*t*i.BEAT_WIDTH+i.STAFF_END_WIDTH},i.tickToX=function(e,t){return i.CLEF_WIDTH+i.BEAT_WIDTH/e*t},i.beatToX=function(e){return i.CLEF_WIDTH+i.BEAT_WIDTH*e},i.closestTick=function(e,t,n){const s=Math.floor((t-i.CLEF_WIDTH)*(e/i.BEAT_WIDTH));return Math.floor(s/n)*n},i.closestRow=function(e){const t=e>i.BASS_STAFF_TOP;return 12-Math.round((e-i.STAFF_HEADER_HEIGHT-(t?i.BASS_STAFF_TOP:0))/(i.STAFF_ROW_HEIGHT/2))},i.rowY=function(e,t){return t?i.BASS_STAFF_TOP+i.STAFF_HEADER_HEIGHT+(12-e%12)*i.STAFF_ROW_HEIGHT/2:i.STAFF_HEADER_HEIGHT+(12-e%12)*i.STAFF_ROW_HEIGHT/2}},{}],221:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.doesSongUseBassClef=i.applySelection=i.moveSelectedNotes=i.deleteSelectedNotes=i.unselectAllNotes=i.selectNoteEventsInRange=i.findSelectedRange=i.changeSongLength=i.findNoteEventAtPosition=i.findNextNoteEvent=i.findNoteEventsOverlappingRange=i.findPreviousNoteEvent=i.findNoteEventAtTick=i.fillDrums=i.editNoteEventLength=i.removeNoteEventFromTrack=i.removeNoteAtRowFromTrack=i.removeNoteFromTrack=i.addNoteToTrack=i.isBassClefNote=i.noteToRow=i.resolveImageURL=i.rowToNote=void 0;const n=[0,2,4,5,7,9,11,12,14,16,17,19],s=[0,1,3,5,7,8,10,12,13,15,17,19];function o(e,t,i,o,r){if(o)return{note:t+(i?12:0),enharmonicSpelling:"normal"};let a;return a=i?s[t]+12*e-19:n[t]+12*e+1,r&&"normal"!==r?"sharp"===r?{note:a+1,enharmonicSpelling:r}:{note:a-1,enharmonicSpelling:r}:{note:a,enharmonicSpelling:"normal"}}function r(e,t,i){if(i)return t.note>=12?t.note-12:t.note;const o=a(e,t,!1),r=t.note-1-12*e+(o?20:0),l=o?s:n;for(let e=0;e<l.length;e++){if(l[e]===r)return"normal"===t.enharmonicSpelling?e:"sharp"===t.enharmonicSpelling?e-1:e+1;if(l[e]>r){if("sharp"===t.enharmonicSpelling)return e-1;if("flat"===t.enharmonicSpelling)return e}}return"sharp"===t.enharmonicSpelling&&r===l[l.length-1]+1?l.length-1:-1}function a(e,t,i){return i?t.note>=12:"flat"===t.enharmonicSpelling?t.note<12*e:"sharp"===t.enharmonicSpelling?t.note<=12*e+1:t.note<12*e+1}function l(e,t,i,n,s){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:c(e.notes,i,n,s,e.instrument.octave,!!e.drums).filter(e=>(e.startTick<=n||e.startTick>=s)&&(e.endTick>=s||e.endTick<=n))}))})}function c(e,t,i,n,s,o){const l={notes:[t],startTick:i,endTick:n};for(let n=0;n<e.length;n++){if(e[n].startTick>i)return e.slice(0,n).concat([l]).concat(e.slice(n));if(e[n].endTick>i)return e[n].notes.some(e=>e.note===t.note&&e.enharmonicSpelling===t.enharmonicSpelling)?e.slice():e.map((e,i)=>i!==n?e:Object.assign(Object.assign({},e),{notes:e.notes.concat([t]).sort((e,t)=>{const i=a(s,e,o);return i===a(s,t,o)?r(s,e,o)-r(s,t,o):i?-1:1})}))}return e.slice().concat([l])}function u(e,t,i){const n=e.slice();for(let e=0;e<n.length;e++)if(n[e].startTick==i){n[e]=Object.assign(Object.assign({},n[e]),{notes:n[e].notes.filter(e=>e.note!==t.note)});break}return n.filter(e=>e.notes.length)}function h(e,t,i,n,s,o){const l=e.slice();for(let e=0;e<l.length;e++)if(l[e].startTick==s){l[e]=Object.assign(Object.assign({},l[e]),{notes:l[e].notes.filter(e=>a(n,e,o)!==i||r(n,e,o)!==t)});break}return l.filter(e=>e.notes.length)}function d(e,t,i){const n=e.slice();if(t>=i)return n;let s;for(let e=0;e<n.length;e++)n[e].startTick===t?(s=Object.assign(Object.assign({},n[e]),{endTick:i}),n[e]=s):s&&n[e].startTick<s.endTick&&(n[e]=void 0);return n.filter(e=>!!e)}function p(e,t,i){const n=e.tracks[t];for(const e of n.notes)if(e.startTick<=i&&e.endTick>i)return e}function g(e,t){let i=e.measures*e.beatsPerMeasure*e.ticksPerBeat+1,n=-1;for(const t of e.tracks)for(const e of t.notes)e.selected&&(i=Math.min(e.startTick,i),n=Math.max(e.endTick,n));if(-1!==n)return void 0!==t&&(i=Math.floor(i/t)*t,n=Math.ceil(n/t)*t),{start:i,end:n}}function f(e,t,i,n){return void 0!==n?Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>s!==n?e:m(e,Math.min(t,i),Math.max(t,i)))}):Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>m(e,Math.min(t,i),Math.max(t,i)))})}function m(e,t,i){return Object.assign(Object.assign({},e),{notes:e.notes.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.slice(),selected:!(e.startTick>=i||e.endTick<=t)}))})}function _(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.map(e=>Object.assign(Object.assign({},e),{selected:!1}))}))})}function b(e,t,i,n){const s=g(e);if(!s)return e;const{start:o,end:r}=s,a=o+t,l=r+t,c=e.beatsPerMeasure*e.ticksPerBeat*e.measures;return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>void 0!==n&&n!=s?e:Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>e.selected||e.endTick<=a||e.startTick>=l).map(n=>n.selected?E(n,e.instrument.octave,t,i,!!e.drums):n).map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,c)})).filter(e=>e.notes.length>0&&e.startTick>=0&&e.startTick<c).sort((e,t)=>e.startTick-t.startTick)}))})}function T(e,t){if(e.pastedContent)return function(e,t){const i=T(e.pastedContent,t),n=g(i,t),s=e.startTick+e.deltaTick,o=s+(n.end-n.start),r=_(e.originalSong),a=r.beatsPerMeasure*r.ticksPerBeat*r.measures;return Object.assign(Object.assign({},r),{tracks:r.tracks.map((r,l)=>void 0!==t&&t!=l?r:Object.assign(Object.assign({},r),{notes:r.notes.filter(e=>e.endTick<=s||e.startTick>=o).concat(i.tracks[l].notes.filter(e=>e.selected).map(t=>Object.assign(Object.assign({},t),{startTick:t.startTick-n.start+e.startTick,endTick:t.endTick-n.start+e.startTick}))).map(t=>t.selected?E(t,r.instrument.octave,e.deltaTick,e.transpose,!!r.drums):t).map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,a)})).filter(e=>e.notes.length>0&&e.startTick>=0&&e.startTick<a).sort((e,t)=>e.startTick-t.startTick)}))})}(e,t);return b(f(e.originalSong,e.startTick,e.endTick,t),e.deltaTick,e.transpose,t)}function E(e,t,i,s,l){const c=Object.assign(Object.assign({},e),{startTick:e.startTick+i,endTick:e.endTick+i,notes:[]});if(l)c.notes=e.notes.slice();else for(const i of e.notes){let e=a(t,i,l),u=r(t,i,l);u+s>=n.length?e&&(u-=12,e=!1):u+s<0&&(e||(u+=12,e=!0));const h=u+s;h<0||h>=n.length||c.notes.push(o(t,h,e,l,i.enharmonicSpelling))}return c}i.rowToNote=o,i.resolveImageURL=function(e){return window.MonacoPaths&&window.MonacoPaths[e]||e},i.noteToRow=r,i.isBassClefNote=a,i.addNoteToTrack=l,i.removeNoteFromTrack=function(e,t,i,n){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,s)=>s!==t?e:Object.assign(Object.assign({},e),{notes:u(e.notes,i,n)}))})},i.removeNoteAtRowFromTrack=function(e,t,i,n,s){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:h(e.notes,i,n,e.instrument.octave,s,!!e.drums)}))})},i.removeNoteEventFromTrack=function(e,t,i){return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,n)=>n!==t?e:Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>e.startTick!==i)}))})},i.editNoteEventLength=function(e,t,i,n){const s=e.beatsPerMeasure*e.ticksPerBeat*e.measures;return Object.assign(Object.assign({},e),{tracks:e.tracks.map((e,o)=>o!==t?e:Object.assign(Object.assign({},e),{notes:d(e.notes,i,Math.min(n,s))}))})},i.fillDrums=function(e,t,i,n,s,r,a){const c=o(0,i,n,!0);for(let i=s;i<r;i+=a)e=l(e,t,{note:c.note,enharmonicSpelling:"normal"},i,i+1);return e},i.findNoteEventAtTick=p,i.findPreviousNoteEvent=function(e,t,i){const n=e.tracks[t];let s;for(const e of n.notes){if(e.startTick>i)return s;s=e}return s},i.findNoteEventsOverlappingRange=function(e,t,i,n){const s=e.tracks[t],o=[];for(const e of s.notes)if(e.endTick<i||e.startTick>n){if(e.startTick>n)break}else o.push(e);return o},i.findNextNoteEvent=function(e,t,i){const n=e.tracks[t];for(const e of n.notes)if(e.startTick>i)return e},i.findNoteEventAtPosition=function(e,t,i){if(void 0!==i){const n=p(e,i,t.tick),s=e.tracks[i];return(null==n?void 0:n.notes.some(e=>r(s.instrument.octave,e,!!s.drums)===t.row))?n:void 0}for(let i=0;i<e.tracks.length;i++){const n=p(e,i,t.tick),s=e.tracks[i];if(null==n?void 0:n.notes.some(e=>r(s.instrument.octave,e,!!s.drums)===t.row))return n}},i.changeSongLength=function(e,t){const i=t*e.beatsPerMeasure*e.ticksPerBeat;return Object.assign(Object.assign({},e),{measures:t,tracks:e.tracks.map(e=>{const t=Object.assign(Object.assign({},e),{notes:e.notes.slice()});return t.notes=t.notes.filter(e=>e.startTick<i),t.notes=t.notes.map(e=>Object.assign(Object.assign({},e),{endTick:Math.min(e.endTick,i)})),t})})},i.findSelectedRange=g,i.selectNoteEventsInRange=f,i.unselectAllNotes=_,i.deleteSelectedNotes=function(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{notes:e.notes.filter(e=>!e.selected)}))})},i.moveSelectedNotes=b,i.applySelection=T,i.doesSongUseBassClef=function(e){return e.tracks.some(e=>e.notes.some(t=>t.notes.some(t=>a(e.instrument.octave,t,!!e.drums))))}},{}],222:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DeleteErrorModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DeleteErrorModal=e=>{const{onClose:t}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Cannot Delete"),onClose:t,actions:[{label:(0,o.lf)("Okay"),onClick:t}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Songs must have at least one track.")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],223:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DeleteTrackModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DeleteTrackModal=e=>{const{trackId:t,onClose:i,onDelete:r}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Delete Track"),onClose:i,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:i},{label:(0,o.lf)("Delete"),className:"red",onClick:()=>{r(t),i()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Are you sure you want to delete this track?")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],224:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.DrumWarningModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.DrumWarningModal=e=>{const{trackId:t,instrumentId:i,onClose:r,onConfirm:a}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Change Track Instrument"),onClose:r,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:r},{label:(0,o.lf)("Confirm"),className:"red",onClick:()=>{a(t,i),r()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("Switching between instruments and drums will cause all existing notes to be deleted. Are you sure you want to continue?")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],225:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Header=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Checkbox"),o=e("../../../../react-common/components/controls/Dropdown"),r=e("./types");function a(e){return`track-${e}`}function l(e){return`instrument-${e}`}function c(e){var t;const i=r.SNAP_OPTIONS.find(t=>t.ticksPerSnap===e);return null!==(t=null==i?void 0:i.id)&&void 0!==t?t:"sixteenth"}i.Header=e=>{var t;const{song:i,selectedTrackId:u,velocityEditorVisible:h,snapTicks:d,showSnapControls:p,onVelocityEditorToggle:g,onTrackSelected:f,onInstrumentSelected:m,onTrackCreated:_,onTrackDeleted:b,onOctavesChanged:T,onSnapChanged:E}=e,v=i.tracks.find(e=>e.id===u),y=i.instruments.find(e=>e.id===(null==v?void 0:v.instrumentId)),k=(0,r.isDrumInstrument)(y),C=i.tracks.map(e=>{const t=(0,r.lf)("Track {0}",e.id);return{label:t,title:t,id:a(e.id)}});C.push({label:(0,r.lf)("New Track..."),title:(0,r.lf)("New Track..."),id:"new-track"}),i.tracks.length>1&&C.push({label:(0,r.lf)("Delete Track"),title:(0,r.lf)("Delete Track"),id:"delete-track"});const I=r.NOTE_RANGES.map(e=>({label:e.name,title:e.name,id:e.id}));let S="full";const A=r.NOTE_RANGES.find(e=>e.minOctave===(null==v?void 0:v.minOctave)&&e.maxOctave===(null==v?void 0:v.maxOctave));A&&(S=A.id);const O=r.SNAP_OPTIONS.map(e=>({label:e.name,title:e.name,id:e.id}));return(0,n.jsxs)("div",Object.assign({className:"header"},{children:[(0,n.jsx)(o.Dropdown,{id:"track-select",items:C,selectedId:a(u),onItemSelected:e=>{if("new-track"===e)_();else if("delete-track"===e)b(u);else{const t=function(e){return parseInt(e.replace("track-",""))}(e);f(t)}}}),(0,n.jsx)(o.Dropdown,{id:"instrument-select",items:i.instruments.map(e=>({label:e.name,title:e.name,id:l(e.id)})),selectedId:l(null!==(t=null==v?void 0:v.instrumentId)&&void 0!==t?t:0),onItemSelected:e=>{const t=function(e){return parseInt(e.replace("instrument-",""))}(e);m(u,t)}}),!k&&(0,n.jsxs)("div",Object.assign({className:"octave-controls"},{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:(0,r.lf)("Range:")})),(0,n.jsx)(o.Dropdown,{id:"range-select",items:I,selectedId:S,onItemSelected:e=>{const t=r.NOTE_RANGES.find(t=>t.id===e);t&&T(t.minOctave,t.maxOctave)}})]})),(0,n.jsx)(s.Checkbox,{id:"velocity-editor-toggle",label:(0,r.lf)("Show Velocity Editor"),isChecked:h,onChange:g}),(0,n.jsx)("div",{className:"spacer"}),p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",Object.assign({className:"music-editor-label"},{children:(0,r.lf)("Snap:")})),(0,n.jsx)(o.Dropdown,{id:"snap-select",items:O,selectedId:c(d),onItemSelected:e=>E(function(e){var t;const i=r.SNAP_OPTIONS.find(t=>t.id===e);return null!==(t=null==i?void 0:i.ticksPerSnap)&&void 0!==t?t:1}(e))})]})]}))}},{"../../../../react-common/components/controls/Checkbox":161,"../../../../react-common/components/controls/Dropdown":162,"./types":237,"react/jsx-runtime":305}],226:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.MeasureHeader=void 0;const n=e("react/jsx-runtime"),s=e("./utils"),o=e("./context"),r=e("react");i.MeasureHeader=({selection:e,onSelectionChange:t,addEventListeners:i,snapTicks:a})=>{const{measures:l,tickWidth:c,ticksPerBeat:u,beatsPerMeasure:h}=(0,o.usePianoRollTheme)(),d=(0,r.useRef)(null),p=(0,o.usePianoRollTheme)(),[g,f]=(0,r.useState)(void 0);(0,r.useEffect)(()=>{if(!d.current)return;const e=d.current;let i,n,o=!1;const r=(e,t)=>{f({startTick:Math.floor(Math.min(e,t)/a)*a,endTick:Math.ceil(Math.max(e,t)/a)*a})},l=t=>{const i=e.getBoundingClientRect();return(0,s.xToTick)(p,t-i.left+e.scrollLeft)},c=e=>{if(!o)return;const t=l(e.clientX);n=t,r(i,n)},u=e=>{o=!1;const s=Math.min(i,n),r=Math.max(i,n);s===r||void 0===r||Number.isNaN(s)||Number.isNaN(r)?t(void 0):t({startTick:s,endTick:r}),f(void 0),i=void 0,n=void 0,document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",u)},h=e=>{var t;e.preventDefault(),i=l(e.clientX),o=!0,document.addEventListener("pointermove",c),document.addEventListener("pointerup",u),r(i,i),null===(t=document.getElementById("piano-roll-workspace"))||void 0===t||t.focus()};return e.addEventListener("pointerdown",h),()=>{e.removeEventListener("pointerdown",h),document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",u)}},[t,p]),(0,r.useEffect)(()=>{if(d.current)return i(d.current)},[i]);const m=g||e;return(0,n.jsxs)("div",Object.assign({className:"measure-header",id:"measure-header",ref:d},{children:[(0,s.range)(0,l).map(e=>(0,n.jsx)("div",Object.assign({className:"measure",style:{width:c*u*h}},{children:e+1}),e+1)),m&&(0,n.jsx)("div",{id:"measure-header-selection",className:"selection",style:{left:(0,s.noteLeft)(p,m.startTick),width:(0,s.noteWidth)(p,m.endTick-m.startTick)}})]}))}},{"./context":236,"./utils":238,react:304,"react/jsx-runtime":305}],227:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.NoteEventView=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/util"),o=e("./context"),r=e("./utils");i.NoteEventView=e=>{const{event:t,isDrumTrack:i,type:a}=e,{duration:l,note:c,start:u,id:h}=t,d=(0,o.usePianoRollTheme)();return(0,n.jsx)("div",Object.assign({id:`note-${h}`,className:(0,s.classList)("note-event",a),style:{width:`${(0,r.noteWidth)(d,l)}px`,left:`${(0,r.noteLeft)(d,u)}px`,top:`${(0,r.noteTop)(d,c)}px`},"data-tick":u,"data-note":c},{children:i||l<=1?void 0:(0,r.getNoteName)(c)}))}},{"../../../../react-common/components/util":171,"./context":236,"./utils":238,"react/jsx-runtime":305}],228:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.OctaveWarningModal=void 0;const n=e("react/jsx-runtime"),s=e("../../../../react-common/components/controls/Modal"),o=e("./types");i.OctaveWarningModal=e=>{const{trackId:t,onClose:i,onPaste:r}=e;return(0,n.jsx)(s.Modal,Object.assign({title:(0,o.lf)("Octave Warning"),onClose:i,actions:[{label:(0,o.lf)("Cancel"),className:"neutral",onClick:i},{label:(0,o.lf)("Paste Anyway"),className:"red",onClick:()=>{r(t),i()}}]},{children:(0,n.jsx)("p",{children:(0,o.lf)("The copied notes are outside the current track's octave range. If you paste, it will change the octave range of this track.")})}))}},{"../../../../react-common/components/controls/Modal":170,"./types":237,"react/jsx-runtime":305}],229:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoOctave=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../../../../react-common/components/util"),r=e("../musicEditor/playback"),a=e("./types"),l=e("./utils");i.PianoOctave=e=>{const{octave:t,selectedTrack:i,instrument:c}=e,u=(0,s.useRef)(null),h=(0,a.isDrumInstrument)(c);(0,s.useEffect)(()=>{const e=u.current;if(!e)return;const n=(n,s,o)=>{if(n!==i)return;if(h||s--,s<12*t||s>=12*(t+1))return;const r=e.querySelector(`#key-${s}`);r&&r.classList.toggle("active",o)};for(let i=0;i<12;i++){const n=11-i+12*t,s=e.querySelector(`#key-${n}`);s&&s.classList.toggle("active",!1)}return(0,r.addNoteChangeListener)(n),()=>{(0,r.removeNoteChangeListener)(n)}},[t,i,h]);const d=(0,s.useCallback)(async e=>{var t;const i=null===(t=u.current)||void 0===t?void 0:t.querySelector(`#key-${e}`);if(i&&i.classList.add("playing"),(0,a.isDrumInstrument)(c)){const t=c.drums[e];t&&await pxsim.music.playDrumAsync(t)}else await pxsim.music.playNoteAsync(e+1,c.instrument,300);i&&i.classList.remove("playing")},[c]);return(0,n.jsx)("div",Object.assign({className:"octave-sidebar",ref:u},{children:(0,l.range)(0,12).map(e=>{const i=11-e+12*t,s=(0,l.isBlackKey)(i),r=h?c.drums[i].name:(0,l.getNoteName)(i),a=(0,o.classList)(h?"drum":"key",s?"black":"white",(0,l.getNoteName)(i,!1).replace("#","sharp")),u=i%12&&!h?void 0:r;return(0,n.jsx)("div",Object.assign({id:`key-${i}`,className:a,title:r,onClick:()=>{d(i)}},{children:u}),i)})}))}},{"../../../../react-common/components/util":171,"../musicEditor/playback":219,"./types":237,"./utils":238,react:304,"react/jsx-runtime":305}],230:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.PianoRollModel=i.PianoRoll=void 0;const n=e("react/jsx-runtime"),s=e("./context"),o=e("./Workspace"),r=e("./Sidebar"),a=e("react"),l=e("./types"),c=e("./Header"),u=e("./DeleteTrackModal"),h=e("./DeleteErrorModal"),d=e("./DrumWarningModal"),p=e("../musicEditor/playback"),g=e("../musicEditor/PlaybackControls"),f=e("./MeasureHeader"),m=e("./VelocityEditor"),_=e("../musicEditor/EditControls"),b=e("../../../../react-common/components/controls/Dropdown"),T=e("./Scrollbar"),E=e("../../../../react-common/components/util"),v=e("./clipboard"),y=e("./utils"),k=e("./OctaveWarningModal"),C=e("../musicEditor/AssetModel");i.PianoRoll=e=>((0,a.useEffect)(()=>()=>{(0,p.stopPlayback)()},[]),(0,n.jsx)(s.PianoRollThemeProvider,{children:(0,n.jsx)(S,Object.assign({},e))}));class I extends C.AssetModel{cloneValue(e){return{song:(0,l.cloneSong)(e.song),selectedTrackIndex:e.selectedTrackIndex,assetName:e.assetName}}cloneExtraState(e){return{velocityEditorVisible:null==e?void 0:e.velocityEditorVisible}}}i.PianoRollModel=I;const S=e=>{const{model:t,showEditControls:i,onDoneClicked:I,fieldEditorParams:S}=e,{state:A,dispatch:O}=(0,s.usePianoRollThemeContext)(),{value:w,hasUndo:N,hasRedo:R,extraState:x}=(0,C.useModelValue)(t),{song:L,selectedTrackIndex:D,assetName:M}=w,{velocityEditorVisible:B}=x,[P,F]=(0,a.useState)(null),[U,H]=(0,a.useState)(4),G=(0,a.useRef)(null);(0,a.useEffect)(()=>{const e={};(null==S?void 0:S.maxPolyphony)&&(e.maxPolyphony=S.maxPolyphony),(null==S?void 0:S.borderColor)&&(e.borderColor=S.borderColor),O(e)},[S,O]);const V=(e,i,n)=>{t.updateValue({song:e,selectedTrackIndex:null!=i?i:D,assetName:M},{pushUndo:null==n||n}),(0,p.isPlaying)()&&(0,p.updatePlaybackSongAsync)((0,l.toPXTSong)(e))},j=(0,a.useCallback)(e=>{const t=e=>{if("Escape"===e.key)L.floatingLayer&&(V((0,l.applyFloatingLayer)(L)),e.preventDefault(),e.stopPropagation());else if("Delete"===e.key||"Backspace"===e.key)L.floatingLayer&&(V((0,l.deleteFloatingLayer)(L)),e.preventDefault(),e.stopPropagation());else if("ArrowUp"===e.key||"ArrowDown"===e.key)L.floatingLayer&&(V((0,l.transposeFloatingLayer)(L,"ArrowUp"===e.key?1:-1)),e.preventDefault(),e.stopPropagation());else if(("ArrowLeft"===e.key||"ArrowRight"===e.key)&&L.floatingLayer){const t="ArrowLeft"===e.key?-1:1;V((0,l.moveFloatingLayer)(L,t)),e.preventDefault(),e.stopPropagation()}},i=e=>{if(L.floatingLayer){const t=L.floatingLayer,i=L.tracks.find(e=>e.id===L.floatingLayer.trackId);(0,v.setCopiedData)({events:t.events,startTick:t.startTick,endTick:t.endTick,isDrumTrack:(0,l.isDrumInstrument)(L.instruments.find(e=>e.id===i.instrumentId)),minOctave:i.minOctave,maxOctave:i.maxOctave}),e.preventDefault(),e.stopPropagation()}},n=e=>{if(L.floatingLayer){const t=L.floatingLayer,i=L.tracks.find(e=>e.id===L.floatingLayer.trackId);(0,v.setCopiedData)({events:t.events,startTick:t.startTick,endTick:t.endTick,isDrumTrack:(0,l.isDrumInstrument)(L.instruments.find(e=>e.id===i.instrumentId)),minOctave:i.minOctave,maxOctave:i.maxOctave}),e.preventDefault(),e.stopPropagation(),V((0,l.deleteFloatingLayer)(L))}},s=e=>{const t=L.tracks[D],i=L.instruments.find(e=>e.id===t.instrumentId),n=(0,v.getCopiedData)(void 0!==t.instrumentId&&(0,l.isDrumInstrument)(i));if(!n)return;const s=G.current;if(!s)return;const o=(0,y.xToTick)(A,s.scrollLeft),r=L.beatsPerMeasure*L.ticksPerBeat,a=Math.ceil(o/r)*r;if(!n.isDrumTrack){const i=Math.floor(n.events.reduce((e,t)=>Math.min(e,t.note),1/0)/12),s=Math.floor(n.events.reduce((e,t)=>Math.max(e,t.note),-1/0)/12);if(i<t.minOctave){if(!(i+2<=t.maxOctave&&i+2>=t.minOctave&&s+2<=t.maxOctave))return F({type:"octave-paste-warning",trackId:t.id}),e.preventDefault(),void e.stopPropagation();for(const e of n.events)e.note+=24}else if(s>t.maxOctave){if(!(s-2>=t.minOctave&&s-2<=t.maxOctave&&i-2>=t.minOctave))return F({type:"octave-paste-warning",trackId:t.id}),e.preventDefault(),void e.stopPropagation();for(const e of n.events)e.note-=24}}const c={trackId:t.id,startTick:a,endTick:a+(n.endTick-n.startTick),events:n.events.map(e=>Object.assign(Object.assign({},e),{id:t.nextId++,start:a+(e.start-n.startTick)}))};let u=(0,l.applyFloatingLayer)(L);u.floatingLayer=c,V(u)};return e.addEventListener("keydown",t),e.addEventListener("copy",i),e.addEventListener("paste",s),e.addEventListener("cut",n),()=>{e.removeEventListener("keydown",t),e.removeEventListener("copy",i),e.removeEventListener("paste",s),e.removeEventListener("cut",n)}},[V,L,D]),W=(e,t)=>{let i=(0,l.applyFloatingLayer)(L);V((0,l.changeTrackInstrument)(e,t,i))},K=(0,a.useCallback)(e=>{let t=L;if(L.floatingLayer&&(t=(0,l.applyFloatingLayer)(L)),!e)return void V(t,void 0,!1);const i=Object.assign({},e);(null==S?void 0:S.showSnapControls)&&(i.startTick=Math.floor(e.startTick/U)*U,i.endTick=Math.ceil(e.endTick/U)*U),V((0,l.selectionToFloatingLayer)(t,D,i),void 0,!1)},[U,null==S?void 0:S.showSnapControls,L]),Y=l.TIME_SIGNATURES.map(e=>({label:e.name,title:e.name,id:e.id})),z=l.TIME_SIGNATURES.find(e=>e.beatsPerMeasure===L.beatsPerMeasure&&e.ticksPerBeat===L.ticksPerBeat),X=()=>F(null),$=L.tracks[D],q=L.instruments.find(e=>e.id===$.instrumentId);let J,Z;J=void 0!==(null==S?void 0:S.minOctave)?S.minOctave:(0,l.isDrumInstrument)(q)?0:$.minOctave,Z=void 0!==(null==S?void 0:S.maxOctave)?S.maxOctave:(0,l.isDrumInstrument)(q)?1:$.maxOctave,(0,a.useEffect)(()=>{A.minOctave===J&&A.maxOctave===Z&&A.measures===L.measures&&A.beatsPerMeasure===L.beatsPerMeasure&&A.ticksPerBeat===L.ticksPerBeat||O({minOctave:J,maxOctave:Z,measures:L.measures,beatsPerMeasure:L.beatsPerMeasure,ticksPerBeat:L.ticksPerBeat})},[J,Z,A.minOctave,A.maxOctave,O,L.measures,L.beatsPerMeasure,L.ticksPerBeat]);const Q=(0,a.useCallback)(()=>{V((0,l.applyFloatingLayer)(L))},[L,V]),ee=(0,a.useCallback)((e,t)=>{L.floatingLayer&&V((0,l.moveFloatingLayer)((0,l.transposeFloatingLayer)(L,t),e))},[L,V]),te=!(null==S?void 0:S.hideHeader);return(0,n.jsxs)("div",Object.assign({className:(0,E.classList)("piano-roll",te?"show-header":"hide-header",B?"show-velocity-editor":"hide-velocity-editor")},{children:["delete-track"===(null==P?void 0:P.type)&&(0,n.jsx)(u.DeleteTrackModal,{trackId:P.trackId,onClose:X,onDelete:e=>{let t=(0,l.applyFloatingLayer)(L);V(Object.assign(Object.assign({},t),{tracks:t.tracks.filter(t=>t.id!==e)}),0)}}),"delete-error"===(null==P?void 0:P.type)&&(0,n.jsx)(h.DeleteErrorModal,{onClose:X}),"drum-warning"===(null==P?void 0:P.type)&&(0,n.jsx)(d.DrumWarningModal,{trackId:P.trackId,instrumentId:P.instrumentId,onClose:X,onConfirm:W}),"octave-paste-warning"===(null==P?void 0:P.type)&&(0,n.jsx)(k.OctaveWarningModal,{trackId:P.trackId,onClose:X,onPaste:e=>{const t=L.tracks.find(t=>t.id===e),i=L.instruments.find(e=>e.id===t.instrumentId),n=(0,v.getCopiedData)((0,l.isDrumInstrument)(i));if(!n||n.isDrumTrack)return;const s=G.current;if(!s)return;const o=(0,y.xToTick)(A,s.scrollLeft),r=L.beatsPerMeasure*L.ticksPerBeat,a=Math.ceil(o/r)*r,c=l.NOTE_RANGES.find(e=>"full"===e.id),u={trackId:e,startTick:a,endTick:a+(n.endTick-n.startTick),events:n.events.map(e=>Object.assign(Object.assign({},e),{id:t.nextId++,start:a+(e.start-n.startTick)}))};let h=(0,l.applyFloatingLayer)(L);h=(0,l.changeOctaves)(e,c.minOctave,c.maxOctave,h),h.floatingLayer=u,V(h)}}),te&&(0,n.jsx)("div",Object.assign({className:"header-container"},{children:(0,n.jsx)(c.Header,{song:L,selectedTrackId:$.id,velocityEditorVisible:B,snapTicks:U,showSnapControls:null==S?void 0:S.showSnapControls,onVelocityEditorToggle:()=>{t.updateExtraState({velocityEditorVisible:!x.velocityEditorVisible})},onTrackSelected:e=>{const t=L.tracks.findIndex(t=>t.id===e);L.floatingLayer?V((0,l.applyFloatingLayer)(L),t):V(L,t,!1)},onInstrumentSelected:(e,t)=>{const i=L.tracks.find(t=>t.id===e),n=L.instruments.find(e=>e.id===i.instrumentId),s=L.instruments.find(e=>e.id===t);(0,l.isDrumInstrument)(n)!==(0,l.isDrumInstrument)(s)&&i.events.length?F({type:"drum-warning",trackId:e,instrumentId:t}):W(e,t)},onTrackCreated:()=>{const e=(0,l.newTrack)(L.instruments[0].id,(0,l.applyFloatingLayer)(L)),t=e.tracks.length-1;V(e,t)},onTrackDeleted:e=>{const t=L.tracks.find(t=>t.id===e);1===L.tracks.length?F({type:"delete-error"}):(null==t?void 0:t.events.length)?F({type:"delete-track",trackId:e}):V(Object.assign(Object.assign({},L),{tracks:L.tracks.filter(t=>t.id!==e)}),0)},onOctavesChanged:(e,t)=>{let i=(0,l.applyFloatingLayer)(L);const n=i.tracks[D];n.minOctave===e&&n.maxOctave===t||(0,l.isDrumInstrument)(i.instruments.find(e=>e.id===n.instrumentId))||(O({minOctave:e,maxOctave:t}),V((0,l.changeOctaves)(n.id,e,t,i)))},onSnapChanged:H})})),(0,n.jsx)(f.MeasureHeader,{selection:L.floatingLayer,onSelectionChange:K,snapTicks:(null==S?void 0:S.showSnapControls)?U:1,addEventListeners:j}),(0,n.jsxs)("div",Object.assign({className:"scroll-container"},{children:[(0,n.jsxs)("div",Object.assign({className:"content-container"},{children:[(0,n.jsx)("div",Object.assign({className:"sidebar-container"},{children:(0,n.jsx)(r.Sidebar,{instrument:q,selectedTrackId:$.id,minOctave:J,maxOctave:Z})})),(0,n.jsxs)("div",Object.assign({ref:G,className:"workspace-container"},{children:[(0,n.jsx)(o.Workspace,{track:$,onEdit:e=>{V((0,l.updateTrack)(e,(0,l.applyFloatingLayer)(L)))},isDrumTrack:(0,l.isDrumInstrument)(q),playNote:e=>{const t=L.tracks[D],i=L.instruments.find(e=>e.id===t.instrumentId);if((0,l.isDrumInstrument)(i)){const t=i.drums[e];pxsim.music.playDrumAsync(t)}else pxsim.music.playNoteAsync(e+1,i.instrument,300)},maxTicks:L.measures*L.beatsPerMeasure*L.ticksPerBeat,snapTicks:(null==S?void 0:S.showSnapControls)?U:1,newNoteDuration:(null==S?void 0:S.showSnapControls)?U:1,bpm:L.tempo,floatingLayer:L.floatingLayer,updateFloatingLayer:ee,applyFloatingLayer:Q,addEventListeners:j}),(0,n.jsx)(T.Scrollbar,{horizontal:!0})]}))]})),(0,n.jsx)(T.Scrollbar,{})]})),B&&(0,n.jsx)(m.VelocityEditor,{notes:$.events,onNotesChange:e=>{let t=(0,l.applyFloatingLayer)(L);V((0,l.updateNoteEvents)(t,t.tracks[D].id,e))}}),(0,n.jsxs)("div",Object.assign({className:"footer"},{children:[(0,n.jsx)(g.PlaybackControls,{beatsPerMinute:L.tempo,measures:L.measures,onControlsClick:e=>{"play"===e?(0,p.startPlaybackAsync)((0,l.toPXTSong)(L),!1):"loop"===e?(0,p.startPlaybackAsync)((0,l.toPXTSong)(L),!0):(0,p.stopPlayback)()},onTempoChange:e=>{V(Object.assign(Object.assign({},L),{tempo:e}))},onMeasuresChanged:e=>{let t=(0,l.applyFloatingLayer)(L);V((0,l.changeMeasures)(e,t)),O({measures:e})},hasUndo:N,hasRedo:R,onUndoClick:()=>{t.undo()},onRedoClick:()=>{t.redo()},hideBassClefOption:!0,singlePlayButton:!0}),(null==S?void 0:S.showTimeSignature)&&(0,n.jsx)(b.Dropdown,{id:"time-signature-dropdown",items:Y,selectedId:null==z?void 0:z.id,onItemSelected:e=>{const t=l.TIME_SIGNATURES.find(t=>t.id===e);if(!t)return;const{beatsPerMeasure:i,ticksPerBeat:n}=t;let s=(0,l.applyFloatingLayer)(L);V((0,l.changeTimeSignature)(i,n,s)),O({beatsPerMeasure:i,ticksPerBeat:n})}}),(0,n.jsx)("div",{className:"spacer"}),i&&(0,n.jsx)(_.EditControls,{assetName:M,onAssetNameChanged:e=>{t.updateValue({song:L,selectedTrackIndex:D,assetName:e})},hideDoneButton:!I,onDoneClicked:I})]}))]}))}},{"../../../../react-common/components/controls/Dropdown":162,"../../../../react-common/components/util":171,"../musicEditor/AssetModel":206,"../musicEditor/EditControls":207,"../musicEditor/PlaybackControls":211,"../musicEditor/playback":219,"./DeleteErrorModal":222,"./DeleteTrackModal":223,"./DrumWarningModal":224,"./Header":225,"./MeasureHeader":226,"./OctaveWarningModal":228,"./Scrollbar":231,"./Sidebar":232,"./VelocityEditor":233,"./Workspace":234,"./clipboard":235,"./context":236,"./types":237,"./utils":238,react:304,"react/jsx-runtime":305}],231:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Scrollbar=void 0;const n=e("react/jsx-runtime"),s=e("react");i.Scrollbar=e=>{const{horizontal:t}=e,i=s.useRef(null),o=s.useRef(null);s.useEffect(()=>{const e=i.current,n=e.parentElement,s=o.current;if(!e||!n||!s)return()=>{};let r=()=>{const i=t?n.clientWidth:n.clientHeight,o=t?n.scrollWidth:n.scrollHeight;if(o<=i)return void(e.style.display="none");e.style.display="block";const r=Math.max(i/o*i,20),a=(t?n.scrollLeft:n.scrollTop)/(o-i)*(i-r-16)+8;t?(s.style.width=`${r}px`,s.style.transform=`translateX(${a}px)`):(s.style.height=`${r}px`,s.style.transform=`translateY(${a}px)`)};r(),requestAnimationFrame(r),n.addEventListener("scroll",r),window.addEventListener("resize",r);let a=!1,l=0,c=0;const u=e=>{e.preventDefault(),a=!0,l=t?e.clientX:e.clientY,c=t?n.scrollLeft:n.scrollTop,document.addEventListener("pointermove",h),document.addEventListener("pointerup",d)},h=e=>{if(!a)return;e.preventDefault();const i=(t?e.clientX:e.clientY)-l,o=t?n.clientWidth:n.clientHeight,r=i*((t?n.scrollWidth:n.scrollHeight)-o)/(o-(t?s.offsetWidth:s.offsetHeight)-16);t?n.scrollLeft=c+r:n.scrollTop=c+r},d=e=>{a=!1,document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",d)};s.addEventListener("pointerdown",u);const p=i=>{i.preventDefault();const o=e.getBoundingClientRect(),r=t?i.clientX-o.left:i.clientY-o.top,a=t?n.clientWidth:n.clientHeight,l=t?n.scrollWidth:n.scrollHeight,c=t?s.offsetWidth:s.offsetHeight,h=(t?n.scrollLeft:n.scrollTop)/(l-a)*(a-c-16)+8;r<h?t?n.scrollLeft-=a:n.scrollTop-=a:r>h+c&&(t?n.scrollLeft+=a:n.scrollTop+=a),u(i)};e.addEventListener("pointerdown",p);const g=new MutationObserver(r);g.observe(n,{childList:!0,subtree:!0});const f=new ResizeObserver(r);return f.observe(n),()=>{e.removeEventListener("pointerdown",p),s.removeEventListener("pointerdown",u),document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",d),n.removeEventListener("scroll",r),window.removeEventListener("resize",r),g.disconnect(),f.disconnect()}},[t]);return(0,n.jsx)("div",Object.assign({ref:i,className:"scrollbar "+(t?"horizontal":"vertical")},{children:(0,n.jsx)("div",{ref:o,className:"scrollbar-thumb"})}))}},{react:304,"react/jsx-runtime":305}],232:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Sidebar=void 0;const n=e("react/jsx-runtime"),s=e("./PianoOctave"),o=e("./utils");i.Sidebar=e=>{const{selectedTrackId:t,instrument:i,minOctave:r,maxOctave:a}=e,l=(0,o.range)(r,a+1);return l.reverse(),(0,n.jsx)("div",Object.assign({className:"sidebar"},{children:l.map(e=>(0,n.jsx)(s.PianoOctave,{octave:e,selectedTrack:t,instrument:i},e))}))}},{"./PianoOctave":229,"./utils":238,"react/jsx-runtime":305}],233:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.VelocityEditor=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("react"),r=e("../../../../react-common/components/util"),a=e("./context"),l=e("./utils");i.VelocityEditor=e=>{var t;const{notes:i,onNotesChange:r}=e,l=(0,a.usePianoRollTheme)(),{tickWidth:u,ticksPerBeat:h,beatsPerMeasure:d,measures:p}=l,[g,f]=(0,o.useState)(void 0),m=u*h*d*p,_=[],b=(0,o.useRef)(null);s.useEffect(()=>{if(!b.current)return;const e=document.getElementById("piano-roll-workspace");e&&(b.current.scrollLeft=e.parentElement.scrollLeft)},[]);for(const e of i){const i=_.find(t=>t.start===e.start);i?i.events.push(e):_.push({start:e.start,events:[e],velocity:null!==(t=e.velocity)&&void 0!==t?t:128})}const T=e=>{if(e!==g){if(g){const e=_.find(e=>e.start===g);if(e)for(const t of e.events){const e=document.getElementById(`note-${t.id}`);e&&e.classList.remove("highlighted")}}f(e);const t=_.find(t=>t.start===e);if(t)for(const e of t.events){const t=document.getElementById(`note-${e.id}`);t&&t.classList.add("highlighted")}}},E=e=>{if(g===e){const t=_.find(t=>t.start===e);if(t)for(const e of t.events){const t=document.getElementById(`note-${e.id}`);t&&t.classList.remove("highlighted")}f(void 0)}};return(0,n.jsxs)("div",Object.assign({id:"velocity-editor",className:"velocity-editor",ref:b},{children:[(0,n.jsx)("div",{className:"velocity-editor-sidebar"}),(0,n.jsx)("div",Object.assign({className:"velocity-sliders",style:{width:`${m}px`}},{children:_.map((e,t)=>(0,n.jsx)(c,{velocity:e.velocity,tick:e.start,highlighted:g===e.start,onHighlight:T,onHighlightEnd:E,onChange:t=>{r(e.events.map(e=>Object.assign(Object.assign({},e),{velocity:t})))}},e.start))}))]}))};const c=e=>{const{velocity:t,onChange:i,tick:s,onHighlight:c,onHighlightEnd:u,highlighted:h}=e,d=(0,a.usePianoRollTheme)(),p=lf("Change velocity for notes at tick {0}",s),g=t/128*100+"%",f=(0,o.useRef)(null);return(0,o.useEffect)(()=>{var e,t;const i=e=>{c(s)},n=e=>{u(s)};return null===(e=f.current)||void 0===e||e.addEventListener("pointerenter",i),null===(t=f.current)||void 0===t||t.addEventListener("pointerleave",n),()=>{var e,t;null===(e=f.current)||void 0===e||e.removeEventListener("pointerenter",i),null===(t=f.current)||void 0===t||t.removeEventListener("pointerleave",n)}},[c,u,s]),(0,n.jsx)("div",Object.assign({id:`velocity-slider-${s}`,className:(0,r.classList)("velocity-slider",h&&"highlighted"),style:{left:(0,l.noteLeft)(d,s)},ref:f},{children:(0,n.jsxs)("div",Object.assign({className:"velocity-slider-inner"},{children:[(0,n.jsx)("div",{className:"velocity-slider-view",style:{height:g}}),(0,n.jsx)("input",{type:"range","aria-orientation":"vertical","aria-label":p,min:0,step:8,max:128,value:t,onChange:e=>i(parseInt(e.target.value))})]}))}))}},{"../../../../react-common/components/util":171,"./context":236,"./utils":238,react:304,"react/jsx-runtime":305}],234:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Workspace=void 0;const n=e("react/jsx-runtime"),s=e("react"),o=e("../musicEditor/playback"),r=e("./context"),a=e("./NoteEvent"),l=e("./types"),c=e("./utils"),u=e("./workspaceBackground");i.Workspace=e=>{var t;const{track:i,onEdit:h,isDrumTrack:d,playNote:p,maxTicks:g,bpm:f,snapTicks:m,newNoteDuration:_,floatingLayer:b,updateFloatingLayer:T,applyFloatingLayer:E,addEventListeners:v}=e,y=(0,u.useWorkspaceBackground)(),k=(0,r.usePianoRollTheme)(),C=(0,s.useRef)(null),I=(0,s.useRef)(null),S=(0,s.useRef)(null),[A,O]=(0,s.useState)(0);return(0,s.useEffect)(()=>{var e,t,n,s,o,r,a,u;const f=null===(e=C.current)||void 0===e?void 0:e.parentElement,v=null===(t=null==f?void 0:f.parentElement)||void 0===t?void 0:t.parentElement,y=document.getElementById("measure-header"),I=document.getElementById("velocity-editor"),A=document.createElement("div");A.className="cursor",A.style.position="absolute",A.style.display="none",null===(n=C.current)||void 0===n||n.appendChild(A);const w=()=>{const e=(null==f?void 0:f.scrollLeft)||0;y&&(y.scrollLeft=e),I&&(I.scrollLeft=e)};null==f||f.addEventListener("scroll",w);const N=(e,t)=>{var i;const n=null===(i=C.current)||void 0===i?void 0:i.getBoundingClientRect();if(!n)return null;const s=e-n.left,o=t-n.top;return{note:(0,c.yToNote)(k,o),time:(0,c.xToTick)(k,s)}},R=(e,t)=>{const n=S.current.noteEvent,s=N(e,t);if(!s)return 1;const o=Math.ceil((s.time+1)/m)*m,r=(0,l.getMaxDuration)(n.note,n.start,i,g,k.maxPolyphony);return Math.max(1,Math.min(r,o-n.start))},x=(e,t)=>{const{note:n,time:s}=N(e,t)||{};if(void 0!==n&&void 0!==s)return i.events.find(e=>e.note===n&&e.start<=s&&s<e.start+e.duration)},L=e=>{if(!S.current){if(x(e.clientX,e.clientY))A.style.display="none";else{A.style.display="block";const t=N(e.clientX,e.clientY);if(t){const e=m>1?Math.floor(t.time/m)*m:t.time;t.time=e;const n=d?1:Math.min((0,l.getMaxDuration)(t.note,t.time,i,g,k.maxPolyphony),_);A.style.left=`${(0,c.noteLeft)(k,t.time)}px`,A.style.top=`${(0,c.noteTop)(k,t.note)}px`,A.style.width=`${(0,c.noteWidth)(k,n)}px`}}return}A.style.display="none";const t=e.clientX-S.current.startX,n=e.clientY-S.current.startY;if(S.current.isScrolling||(Math.abs(t)>10||Math.abs(n)>10)&&(S.current.isScrolling=!0),S.current.isScrolling)if(S.current.isMove){(e=>{if(!b)return;const t=document.getElementById("measure-header-selection"),i=b.startTick+e;t&&(t.style.left=`${(0,c.noteLeft)(k,i)}px`),O(e)})(Math.round(t/(0,c.noteWidth)(k,1)))}else if(!S.current.noteEvent||d)(e=>{const t=S.current.startScrollX-e;f&&(f.scrollLeft=t)})(t),(e=>{const t=S.current.startScrollY-e;v&&(v.scrollTop=t)})(n);else{const t=S.current.noteEvent;S.current.noteElement||(S.current.noteElement=document.getElementById(`note-${t.id}`)),S.current.noteElement&&(S.current.noteElement.style.width=`${(0,c.noteWidth)(k,R(e.clientX,e.clientY))}px`)}},D=e=>{const{time:t}=N(e.clientX,e.clientY)||{};S.current={startX:e.clientX,startY:e.clientY,startScrollX:(null==f?void 0:f.scrollLeft)||0,startScrollY:(null==v?void 0:v.scrollTop)||0,noteEvent:x(e.clientX,e.clientY),isMove:b&&t>b.startTick&&t<b.endTick},b&&!S.current.isMove&&E(),L(e)},M=e=>{L(e)},B=e=>{if(O(0),S.current){if(L(e),S.current.isScrolling)S.current.isMove?T(Math.round((e.clientX-S.current.startX)/(0,c.noteWidth)(k,1)),0):S.current.noteEvent&&!d&&h((0,l.changeNoteEventDuration)(S.current.noteEvent.id,R(e.clientX,e.clientY),i,g,k.maxPolyphony));else if(S.current.isMove)E();else if(S.current.noteEvent)h(Object.assign(Object.assign({},i),{events:i.events.filter(e=>{var t;return e!==(null===(t=S.current)||void 0===t?void 0:t.noteEvent)})}));else{const e=N(S.current.startX,S.current.startY);if(e){const t=m>1?Math.floor(e.time/m)*m:e.time;e.time=t,h((0,l.newNoteEvent)(e.note,e.time,_,i,d,g,k.maxPolyphony)),p(e.note)}}S.current=null}else A.style.display="none"};return null===(s=C.current)||void 0===s||s.addEventListener("pointerdown",D),null===(o=C.current)||void 0===o||o.addEventListener("pointermove",M),null===(r=C.current)||void 0===r||r.addEventListener("pointerup",B),null===(a=C.current)||void 0===a||a.addEventListener("pointercancel",B),null===(u=C.current)||void 0===u||u.addEventListener("pointerleave",B),()=>{var e,t,i,n,s,o;null===(e=C.current)||void 0===e||e.removeEventListener("pointerdown",D),null===(t=C.current)||void 0===t||t.removeEventListener("pointermove",M),null===(i=C.current)||void 0===i||i.removeEventListener("pointerup",B),null===(n=C.current)||void 0===n||n.removeEventListener("pointercancel",B),null===(s=C.current)||void 0===s||s.removeEventListener("pointerleave",B),null===(o=C.current)||void 0===o||o.removeChild(A),null==f||f.removeEventListener("scroll",w)}},[i,h,k.minOctave,k.maxOctave,d,m,g,b,T,E]),(0,s.useEffect)(()=>{const e=pxsim.music.tickToMs(f,k.ticksPerBeat,1),t=(0,c.noteWidth)(k,1);let i,n,s=0,r=!1;const a=e=>{s=(0,c.noteWidth)(k,e),n=Date.now(),r||(r=!0,I.current&&(I.current.style.left=`${s}px`,I.current.style.display="unset"),i=requestAnimationFrame(u))},l=()=>{r=!1,I.current&&(I.current.style.display="none"),i&&cancelAnimationFrame(i)},u=()=>{const o=s+t*(Date.now()-n)/e;I.current&&(I.current.style.left=`${o}px`),r&&(i=requestAnimationFrame(u))};return(0,o.addTickListener)(a),(0,o.addPlaybackStateListener)(l),()=>{(0,o.removeTickListener)(a),(0,o.removePlaybackStateListener)(l),i&&cancelAnimationFrame(i)}},[k,f]),(0,s.useEffect)(()=>{O(0)},[b]),(0,s.useEffect)(()=>{if(C.current)return v(C.current)},[v]),(0,n.jsxs)("div",Object.assign({className:"workspace",id:"piano-roll-workspace",style:{backgroundImage:y,backgroundSize:`${k.tickWidth*k.ticksPerBeat}px ${7*k.whiteKeyHeight}px`,width:(0,c.workspaceWidth)(k),height:(0,c.workspaceHeight)(k)},ref:C,tabIndex:0},{children:[(0,n.jsx)("div",{className:"playhead",ref:I}),i.events.map((e,t)=>(0,n.jsx)(a.NoteEventView,{event:e,isDrumTrack:d},t)),null===(t=null==b?void 0:b.events)||void 0===t?void 0:t.map((e,t)=>(0,n.jsx)(a.NoteEventView,{event:Object.assign(Object.assign({},e),{start:e.start+A}),isDrumTrack:d,type:"floating"},`floating-${t}`)),b&&(0,n.jsx)("div",{id:"workspace-selection",className:"selection",style:{left:(0,c.noteLeft)(k,b.startTick+A),width:(0,c.noteWidth)(k,b.endTick-b.startTick)}})]}))}},{"../musicEditor/playback":219,"./NoteEvent":227,"./context":236,"./types":237,"./utils":238,"./workspaceBackground":239,react:304,"react/jsx-runtime":305}],235:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.getCopiedData=i.setCopiedData=void 0,i.setCopiedData=function(e){const t=JSON.stringify(e);e.isDrumTrack?localStorage.setItem("piano-roll-drum-copy",t):localStorage.setItem("piano-roll-copy",t)},i.getCopiedData=function(e){const t=e?localStorage.getItem("piano-roll-drum-copy"):localStorage.getItem("piano-roll-copy");if(t)try{return JSON.parse(t)}catch(e){return void console.error("Failed to parse copied data",e)}}},{}],236:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.usePianoRollThemeContext=i.usePianoRollTheme=i.PianoRollThemeProvider=i.PianoRollContext=void 0;const n=e("react/jsx-runtime"),s=e("react"),o={tickWidth:15,whiteKeyHeight:40,ticksPerBeat:4,beatsPerMeasure:4,measures:4,minOctave:3,maxOctave:5,maxPolyphony:1/0,gridLineColor:"#283547",whiteKeyWorkspaceColor:"#405470",blackKeyWorkspaceColor:"#36475f"};function r(e,t){return Object.assign(Object.assign({},e),t)}i.PianoRollContext=(0,s.createContext)({state:void 0,dispatch:void 0}),i.PianoRollThemeProvider=function(e){const[t,a]=(0,s.useReducer)(r,o),l={state:t,dispatch:a},c=(0,s.useRef)(null);return(0,s.useEffect)(()=>{const e=getComputedStyle(c.current),t=e.getPropertyValue("--workspace-grid-line-color"),i=e.getPropertyValue("--workspace-white-key-color"),n=e.getPropertyValue("--workspace-black-key-color");t===l.state.gridLineColor&&i===l.state.whiteKeyWorkspaceColor&&n===l.state.blackKeyWorkspaceColor||a({gridLineColor:t,whiteKeyWorkspaceColor:i,blackKeyWorkspaceColor:n})},[]),(0,s.useEffect)(()=>{const e=[`--tick-width: ${l.state.tickWidth}px`,`--white-key-height: ${l.state.whiteKeyHeight}px`];l.state.borderColor&&e.push(`--piano-roll-border-color: ${l.state.borderColor}`),c.current.setAttribute("style",e.join("; "))},[l.state.tickWidth,l.state.whiteKeyHeight,l.state.borderColor]),(0,n.jsx)(i.PianoRollContext.Provider,Object.assign({value:l},{children:(0,n.jsx)("div",Object.assign({className:"piano-roll-root",ref:c},{children:e.children}))}))},i.usePianoRollTheme=function(){return(0,s.useContext)(i.PianoRollContext).state},i.usePianoRollThemeContext=function(){return(0,s.useContext)(i.PianoRollContext)}},{react:304,"react/jsx-runtime":305}],237:[function(e,t,i){"use strict";function n(){const e=pxt.assets.music.getEmptySong(4);let t=0;const i=e.tracks.map(e=>(t=Math.max(t,e.id+1),e.drums?{id:e.id,name:e.name,minOctave:0,maxOctave:1,drums:e.drums}:{id:e.id,name:e.name,instrument:e.instrument,minOctave:3,maxOctave:5}));return{nextInstrumentId:t,instruments:i,beatsPerMeasure:4,ticksPerBeat:8,tracks:[{instrumentId:0,events:[],nextId:0,id:0,minOctave:3,maxOctave:5}],measures:2,tempo:120}}function s(e,t,i,n,s){let o=[];for(const n of i.events)if(n.start!==t||n.note!==e){if(o.push(n),n.start>=t&&(n.note===e||o.length>=s))return n.start-t;o=o.filter(e=>e.start+e.duration<n.start)}return n-t}function o(e){let t=0;for(;e.tracks.some(e=>e.id===t);)t++;return t}function r(e,t){const i=t.tracks.findIndex(t=>t.id===e.id);return-1===i?t:Object.assign(Object.assign({},t),{tracks:[...t.tracks.slice(0,i),e,...t.tracks.slice(i+1)]})}function a(e){return void 0!==e.drums}function l(e,t){var i,n;if(a(t))return[{id:e.id,name:t.name,notes:e.events.map(e=>({startTick:e.start,endTick:e.start+e.duration,notes:[{note:e.note,enharmonicSpelling:"normal"}],velocity:e.velocity})),instrument:void 0,drums:t.drums}];let s=(null===(i=e.events[0])||void 0===i?void 0:i.note)||0,o=(null===(n=e.events[0])||void 0===n?void 0:n.note)||0;for(const t of e.events)s=Math.min(s,t.note),o=Math.max(o,t.note);s++,o++;const r=[],c=Math.floor(s/12);if(o-12*c>=64)return r.push(...l(Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.note<64)}),t)),r.push(...l(Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.note>=64)}),t)),r;const u=c+2;return[{id:e.id,name:t.name,notes:e.events.map(e=>({startTick:e.start,endTick:e.start+e.duration,notes:[{note:e.note+1,enharmonicSpelling:"normal"}],velocity:e.velocity})),instrument:Object.assign(Object.assign({},t.instrument),{octave:u}),drums:void 0}]}function c(e,t){return e.waveform===t.waveform&&(!!u(e.ampEnvelope,t.ampEnvelope)&&(!!u(e.pitchEnvelope,t.pitchEnvelope)&&(!!h(e.ampLFO,t.ampLFO)&&!!h(e.pitchLFO,t.pitchLFO))))}function u(e,t){return e===t||(e?t?e.attack===t.attack&&(e.decay===t.decay&&(e.sustain===t.sustain&&(e.release===t.release&&e.amplitude===t.amplitude))):0===e.amplitude:!t||0===t.amplitude)}function h(e,t){return e===t||(e?t?e.frequency===t.frequency&&e.amplitude===t.amplitude:0===e.amplitude:!t||0===t.amplitude)}function d(e){if(!e.floatingLayer)return e;const t=e.tracks.find(t=>t.id===e.floatingLayer.trackId);if(!t)return e;const i={startTick:e.floatingLayer.startTick,endTick:e.floatingLayer.endTick,events:e.floatingLayer.events,isDrumTrack:a(e.instruments.find(e=>e.id===t.instrumentId))},n=m(e,e.floatingLayer.trackId,i,e.floatingLayer.startTick);return n.floatingLayer=void 0,n}function p(e,t){return e.start>=t.startTick&&e.start+e.duration<=t.endTick}function g(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n];return r(Object.assign(Object.assign({},s),{events:s.events.filter(e=>!p(e,i))}),e)}function f(e,t,i){const n=e.tracks.find(e=>e.id===t);if(!n)return;const s=n.events.filter(e=>p(e,i)).map(e=>Object.assign({},e));return{startTick:i.startTick,endTick:i.endTick,events:s,isDrumTrack:a(e.instruments.find(e=>e.id===n.instrumentId)),minOctave:n.minOctave,maxOctave:n.maxOctave}}function m(e,t,i,n){const s=e.tracks.findIndex(e=>e.id===t);if(-1===s)return e;const o=e.tracks[s],a=e.measures*e.beatsPerMeasure*e.ticksPerBeat,l=n-i.startTick;let c=i.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+l,id:o.nextId++}));for(const e of c)e.duration=Math.min(e.duration,a-e.start),e.start=Math.max(0,e.start);c=c.filter(e=>e.start<a&&e.start+e.duration>0);const u=Object.assign(Object.assign({},e.tracks[s]),{events:o.events.map(e=>Object.assign({},e))});for(const e of c)for(const t of u.events)if(t.note===e.note&&!(t.start+t.duration<=e.start)){if(t.start>=e.start+e.duration)break;t.start<=e.start&&t.start+t.duration>e.start?t.duration=e.start-t.start:t.start>e.start&&(t.duration=t.start+t.duration-(e.start+e.duration),t.start=e.start+e.duration)}u.events=u.events.filter(e=>e.duration>0);let h=0;for(let e=0;e<u.events.length;e++){const t=c[h];if(!t)break;t.start<u.events[e].start&&(u.events.splice(e,0,t),h++,e++)}return h<c.length&&u.events.push(...c.slice(h)),r(u,e)}function _(e){return Object.assign(Object.assign({},e),{tracks:e.tracks.map(e=>Object.assign(Object.assign({},e),{events:e.events.map(e=>Object.assign({},e))})),floatingLayer:e.floatingLayer?Object.assign(Object.assign({},e.floatingLayer),{events:e.floatingLayer.events.map(e=>Object.assign({},e))}):void 0})}Object.defineProperty(i,"__esModule",{value:!0}),i.cloneSong=i.pasteToFloatingLayer=i.pasteCopyData=i.getCopyData=i.moveSelection=i.transposeSelection=i.deleteSelection=i.isInSelection=i.moveFloatingLayer=i.transposeFloatingLayer=i.selectionToFloatingLayer=i.deleteFloatingLayer=i.applyFloatingLayer=i.changeTimeSignature=i.fromPXTSong=i.toPXTSong=i.isMelodicInstrument=i.isDrumInstrument=i.changeOctaves=i.changeMeasures=i.changeTrackInstrument=i.updateNoteEvents=i.updateNoteEvent=i.updateTrack=i.newTrack=i.changeNoteEventDuration=i.newNoteEvent=i.getMaxDuration=i.getNextNoteEvent=i.getEmptySong=i.NOTE_RANGES=i.SNAP_OPTIONS=i.TIME_SIGNATURES=i.lf=void 0,i.lf=pxt.U.lf,i.TIME_SIGNATURES=[{name:(0,i.lf)("4/4"),id:"ts4-4",beatsPerMeasure:4,ticksPerBeat:8},{name:(0,i.lf)("3/4"),id:"ts3-4",beatsPerMeasure:3,ticksPerBeat:8},{name:(0,i.lf)("2/4"),id:"ts2-4",beatsPerMeasure:2,ticksPerBeat:8},{name:(0,i.lf)("3/8"),id:"ts3-8",beatsPerMeasure:3,ticksPerBeat:4},{name:(0,i.lf)("6/8"),id:"ts6-8",beatsPerMeasure:6,ticksPerBeat:4},{name:(0,i.lf)("12/8"),id:"ts12-8",beatsPerMeasure:12,ticksPerBeat:4}],i.SNAP_OPTIONS=[{name:(0,i.lf)("1/4"),id:"quarter",ticksPerSnap:8},{name:(0,i.lf)("1/8"),id:"eighth",ticksPerSnap:4},{name:(0,i.lf)("1/16"),id:"sixteenth",ticksPerSnap:2},{name:(0,i.lf)("1/32"),id:"thirty-second",ticksPerSnap:1}],i.NOTE_RANGES=[{name:(0,i.lf)("Treble"),id:"treble",minOctave:3,maxOctave:5},{name:(0,i.lf)("Bass"),id:"bass",minOctave:0,maxOctave:3},{name:(0,i.lf)("Full"),id:"full",minOctave:0,maxOctave:7}],i.getEmptySong=n,i.getNextNoteEvent=function(e,t,i,n){return i.events.find(i=>i.note===e&&i.start>t)},i.getMaxDuration=s,i.newNoteEvent=function(e,t,i,n,o,r,a){return function(e,t){for(let i=0;i<t.events.length;i++)if(t.events[i].start>e.start)return Object.assign(Object.assign({},t),{events:[...t.events.slice(0,i),e,...t.events.slice(i)]});return Object.assign(Object.assign({},t),{events:[...t.events,e]})}({id:(n=function(e,t,i){if(i===1/0)return t;const n=t.events.filter(t=>t.start<=e&&t.start+t.duration>e);if(n.length<i)return t;const s=n.reduce((e,t)=>e.start>t.start?e:t);return Object.assign(Object.assign({},t),{events:t.events.filter(e=>e.id!==s.id)})}(t,n,a)).nextId++,note:e,start:t,duration:o?1:Math.min(i,s(e,t,n,r,a)),velocity:128},n)},i.changeNoteEventDuration=function(e,t,i,n,o){const r=i.events.findIndex(t=>t.id===e);if(-1===r)return i;const a=i.events[r],l=s(a.note,a.start,i,n,o),c=Object.assign(Object.assign({},a),{duration:Math.max(1,Math.min(t,l))});return Object.assign(Object.assign({},i),{events:[...i.events.slice(0,r),c,...i.events.slice(r+1)]})},i.newTrack=function(e,t){const n=i.NOTE_RANGES.find(e=>"treble"===e.id),s={instrumentId:e,events:[],id:o(t),nextId:0,minOctave:n.minOctave,maxOctave:n.maxOctave};return Object.assign(Object.assign({},t),{tracks:[...t.tracks,s]})},i.updateTrack=r,i.updateNoteEvent=function(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n],o=s.events.findIndex(e=>e.id===i.id);return-1===o?e:r(Object.assign(Object.assign({},s),{events:[...s.events.slice(0,o),i,...s.events.slice(o+1)]}),e)},i.updateNoteEvents=function(e,t,i){const n=e.tracks.findIndex(e=>e.id===t);if(-1===n)return e;const s=e.tracks[n];return r(Object.assign(Object.assign({},s),{events:s.events.map(e=>{const t=i.find(t=>t.id===e.id);return t||e})}),e)},i.changeTrackInstrument=function(e,t,i){const n=i.tracks.findIndex(t=>t.id===e),s=Object.assign({},i.tracks[n]),o=i.instruments.find(e=>e.id===s.instrumentId),l=i.instruments.find(e=>e.id===t);return a(o)!==a(l)&&(s.events=[]),s.instrumentId=t,r(s,i)},i.changeMeasures=function(e,t){const i=e*t.beatsPerMeasure*t.ticksPerBeat;return Object.assign(Object.assign({},t),{measures:e,tracks:t.tracks.map(e=>Object.assign(Object.assign({},e),{events:e.events.filter(e=>e.start<i).map(e=>Object.assign(Object.assign({},e),{duration:Math.min(e.duration,i-e.start)}))}))})},i.changeOctaves=function(e,t,i,n){const s=n.tracks.findIndex(t=>t.id===e),o=n.tracks[s];return Object.assign(Object.assign({},n),{tracks:[...n.tracks.slice(0,s),Object.assign(Object.assign({},o),{minOctave:t,maxOctave:i,events:o.events.filter(e=>e.note>=12*t&&e.note<12*i)}),...n.tracks.slice(s+1)]})},i.isDrumInstrument=a,i.isMelodicInstrument=function(e){return void 0!==e.instrument},i.toPXTSong=function(e){return{ticksPerBeat:(e=d(e)).ticksPerBeat,beatsPerMeasure:e.beatsPerMeasure,beatsPerMinute:e.tempo,measures:e.measures,tracks:e.tracks.reduce((t,i)=>{const n=e.instruments.find(e=>e.id===i.instrumentId);return t.push(...l(i,n)),t},[])}},i.fromPXTSong=function(e){var t;const s=n();s.measures=e.measures,s.tempo=e.beatsPerMinute,s.tracks=[],s.beatsPerMeasure=e.beatsPerMeasure,s.ticksPerBeat=e.ticksPerBeat;let o=0;for(const n of e.tracks.filter(e=>e.notes.length>0)){const e=s.tracks.find(e=>e.id===n.id),r=e||{id:n.id,instrumentId:0,events:[],nextId:0,minOctave:7,maxOctave:0},l=(e,t,i,s)=>{var o;const a={id:r.nextId++,note:(null===(o=n.drums)||void 0===o?void 0:o.length)?e:Math.max(e-1,0),start:t,duration:i-t,velocity:null!=s?s:128};r.events.push(a);const l=Math.floor(a.note/12);r.minOctave=Math.min(r.minOctave,l),r.maxOctave=Math.max(r.maxOctave,l)};if(null===(t=n.drums)||void 0===t?void 0:t.length)r.instrumentId=s.instruments.find(e=>a(e)).id;else{const e=s.instruments.find(e=>!a(e)&&c(e.instrument,n.instrument));if(e)r.instrumentId=e.id;else{const e={id:s.nextInstrumentId++,name:(0,i.lf)("Instrument {0}",o++),instrument:n.instrument};s.instruments.push(e),r.instrumentId=e.id}}for(const e of n.notes)for(const t of e.notes)l(t.note,e.startTick,e.endTick,e.velocity);const u=i.NOTE_RANGES.find(e=>e.minOctave<=r.minOctave&&e.maxOctave>=r.maxOctave);u&&(r.minOctave=u.minOctave,r.maxOctave=u.maxOctave),(!e&&r.events.length>0||0===s.tracks.length)&&s.tracks.push(r)}return 0===s.tracks.length&&s.tracks.push({id:0,instrumentId:s.instruments[0].id,events:[],nextId:0,minOctave:i.NOTE_RANGES[0].minOctave,maxOctave:i.NOTE_RANGES[0].maxOctave}),s},i.changeTimeSignature=function(e,t,i){const n=i.measures*i.beatsPerMeasure*i.ticksPerBeat,s=Math.ceil(n/(e*t));return Object.assign(Object.assign({},i),{measures:s,beatsPerMeasure:e,ticksPerBeat:t})},i.applyFloatingLayer=d,i.deleteFloatingLayer=function(e){if(!e.floatingLayer)return e;const t=_(e);return t.floatingLayer=void 0,t},i.selectionToFloatingLayer=function(e,t,i){const n=d(e),s=f(n,t,i);return n.floatingLayer={events:s.events,startTick:s.startTick,endTick:s.endTick,trackId:t},g(n,t,i)},i.transposeFloatingLayer=function(e,t){if(!e.floatingLayer||!t)return e;const i=_(e);return i.floatingLayer.events=i.floatingLayer.events.map(e=>Object.assign(Object.assign({},e),{note:e.note+t})),i},i.moveFloatingLayer=function(e,t){if(!e.floatingLayer||!t)return e;const i=_(e);return i.floatingLayer.startTick+=t,i.floatingLayer.endTick+=t,i.floatingLayer.events=i.floatingLayer.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+t})),i},i.isInSelection=p,i.deleteSelection=g,i.transposeSelection=function(e,t,i,n){const s=e.tracks.findIndex(e=>e.id===t);if(-1===s)return e;const o=e.tracks[s];return r(Object.assign(Object.assign({},o),{events:o.events.map(e=>p(e,i)?Object.assign(Object.assign({},e),{note:e.note+n}):e)}),e)},i.moveSelection=function(e,t,i,n){if(-1===e.tracks.findIndex(e=>e.id===t))return e;const s=f(e,t,i);return m(g(e,t,i),t,s,i.startTick+n)},i.getCopyData=f,i.pasteCopyData=m,i.pasteToFloatingLayer=function(e,t,i,n){const s=_(e),o=n-i.startTick,r=i.events.map(e=>Object.assign(Object.assign({},e),{start:e.start+o}));return s.floatingLayer={events:r,startTick:n,endTick:n+(i.endTick-i.startTick),trackId:t},s},i.cloneSong=_},{}],238:[function(e,t,i){"use strict";function n(e){return s(e)/12}function s(e){return 7*e.whiteKeyHeight}function o(e){return 12*(e.maxOctave+1)-1}Object.defineProperty(i,"__esModule",{value:!0}),i.minNote=i.maxNote=i.yToNote=i.xToTick=i.workspaceWidth=i.workspaceHeight=i.octaveHeight=i.noteHeight=i.noteTop=i.noteLeft=i.noteWidth=i.range=i.getNoteName=i.isBlackKey=void 0,i.isBlackKey=function(e){return[1,3,6,8,10].includes(e%12)},i.getNoteName=function(e,t=!0){const i=e%12,n=Math.floor(e/12)+1,s=["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"];return t?`${s[i]}${n}`:s[i]},i.range=function(e,t){return Array.from({length:t-e},(t,i)=>e+i)},i.noteWidth=function(e,t){return e.tickWidth*t+1},i.noteLeft=function(e,t){return e.tickWidth*t},i.noteTop=function(e,t){return(o(e)-t)*n(e)},i.noteHeight=n,i.octaveHeight=s,i.workspaceHeight=function(e){return(e.maxOctave-e.minOctave+1)*s(e)},i.workspaceWidth=function(e){return e.measures*e.ticksPerBeat*e.beatsPerMeasure*e.tickWidth},i.xToTick=function(e,t){return Math.floor(t/e.tickWidth)},i.yToNote=function(e,t){return o(e)-Math.floor(t/n(e))},i.maxNote=o,i.minNote=function(e){return 12*e.minOctave}},{}],239:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.useWorkspaceBackground=void 0;const n=e("react"),s=e("./context");function o(e){return`url("data:image/svg+xml,${encodeURIComponent(function(e,t,i,n="#1e343d",s="#2e4c58",o="#36535f"){return`\n<svg xmlns="http://www.w3.org/2000/svg" width="${e*t}" height="${i}">\n <defs>\n <pattern id="grid" width="${2*e}" height="${i/12}" patternUnits="userSpaceOnUse">\n <rect width="1" height="${i/12}" fill="${n}" />\n <rect width="${2*e}" height="1" fill="${n}" />\n </pattern>\n <pattern id="grid2" width="${e*t}" height="${i/12}" patternUnits="userSpaceOnUse">\n <rect width="2" height="${i/12}" fill="${n}" />\n </pattern>\n </defs>\n <rect width="100%" height="100%" fill="${o}" />\n ${[1,3,5,8,10].map(e=>`<rect x="0" y="${i/12*e}" width="100%" height="${i/12}" fill="${s}" />`).join("")}\n <rect width="100%" height="100%" fill="url(#grid)" />\n <rect width="100%" height="100%" fill="url(#grid2)" />\n <rect x="0" y="0" width="4" height="100%" fill="${n}" />\n</svg>\n`.trim().replace(/\s+/g," ")}(e.tickWidth,e.ticksPerBeat,7*e.whiteKeyHeight,e.gridLineColor,e.blackKeyWorkspaceColor,e.whiteKeyWorkspaceColor))}")`}i.useWorkspaceBackground=function(){const e=(0,s.usePianoRollTheme)(),[t,i]=(0,n.useState)(o(e));return(0,n.useEffect)(()=>{i(o(e))},[e.tickWidth,e.ticksPerBeat,e.whiteKeyHeight,e.gridLineColor,e.blackKeyWorkspaceColor,e.whiteKeyWorkspaceColor]),t}},{"./context":236,react:304}],240:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ariaAnnounce=i.fireClickOnEnter=void 0,i.fireClickOnEnter=function(e){const t="number"==typeof e.which?e.which:e.keyCode;13!==t&&32!==t||(e.preventDefault(),e.currentTarget.click())};let n=!1;i.ariaAnnounce=function(e,t,i){const s=document.getElementById("pxt-aria-live");s&&e&&(s.textContent=`${e}${n?"":""}`,n=!n,s.ariaLive=null!=t?t:"polite",s.setAttribute("role",null!=i?i:null))}},{}],241:[function(e,t,i){var n=e("./toPropertyKey.js");t.exports=function(e,t,i){return(t=n(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e},t.exports.__esModule=!0,t.exports.default=t.exports},{"./toPropertyKey.js":248}],242:[function(e,t,i){function n(){return t.exports=n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)({}).hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},t.exports.__esModule=!0,t.exports.default=t.exports,n.apply(null,arguments)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports},{}],243:[function(e,t,i){t.exports=function(e){return e&&e.__esModule?e:{default:e}},t.exports.__esModule=!0,t.exports.default=t.exports},{}],244:[function(e,t,i){var n=e("./typeof.js").default;function s(e,i){if("function"==typeof WeakMap)var o=new WeakMap,r=new WeakMap;return(t.exports=s=function(e,t){if(!t&&e&&e.__esModule)return e;var i,s,a={__proto__:null,default:e};if(null===e||"object"!=n(e)&&"function"!=typeof e)return a;if(i=t?r:o){if(i.has(e))return i.get(e);i.set(e,a)}for(var l in e)"default"!==l&&{}.hasOwnProperty.call(e,l)&&((s=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,l))&&(s.get||s.set)?i(a,l,s):a[l]=e[l]);return a},t.exports.__esModule=!0,t.exports.default=t.exports)(e,i)}t.exports=s,t.exports.__esModule=!0,t.exports.default=t.exports},{"./typeof.js":249}],245:[function(e,t,i){var n=e("./defineProperty.js");function s(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)}return i}t.exports=function(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?s(Object(i),!0).forEach(function(t){n(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):s(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e},t.exports.__esModule=!0,t.exports.default=t.exports},{"./defineProperty.js":241}],246:[function(e,t,i){t.exports=function(e,t){if(null==e)return{};var i={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;i[n]=e[n]}return i},t.exports.__esModule=!0,t.exports.default=t.exports},{}],247:[function(e,t,i){var n=e("./typeof.js").default;t.exports=function(e,t){if("object"!=n(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var s=i.call(e,t||"default");if("object"!=n(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},t.exports.__esModule=!0,t.exports.default=t.exports},{"./typeof.js":249}],248:[function(e,t,i){var n=e("./typeof.js").default,s=e("./toPrimitive.js");t.exports=function(e){var t=s(e,"string");return"symbol"==n(t)?t:t+""},t.exports.__esModule=!0,t.exports.default=t.exports},{"./toPrimitive.js":247,"./typeof.js":249}],249:[function(e,t,i){function n(e){return t.exports=n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,n(e)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports},{}],250:[function(e,t,i){
|
|
7
7
|
/*! For license information please see index.js.LICENSE.txt */
|
|
8
8
|
!function(n,s){if("object"==typeof i&&"object"==typeof t)t.exports=s(e("blockly/core"));else if("function"==typeof define&&define.amd)define(["blockly/core"],s);else{var o=s("object"==typeof i?e("blockly/core"):n.Blockly);for(var r in o)("object"==typeof i?i:n)[r]=o[r]}}(this,e=>(()=>{"use strict";var t={370:t=>{t.exports=e}},i={};function n(e){var s=i[e];if(void 0!==s)return s.exports;var o=i[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};n.r(s),n.d(s,{FieldGridDropdown:()=>l});var o=n(370);class r{constructor(e,t,i,n){this.value=i,this.selected=!1,this.selectionCallback=n,this.element=document.createElement("button"),this.element.id=o.utils.idGenerator.getNextUniqueId(),this.element.className="blocklyFieldGridItem",this.clickHandler=o.browserEvents.conditionalBind(this.element,"click",this,this.onClick,!0),e.appendChild(this.element);const s="string"==typeof t?document.createTextNode(t):t;this.element.appendChild(s),o.utils.aria.setRole(this.element,o.utils.aria.Role.GRIDCELL)}dispose(){this.selectionCallback=null,this.element.remove(),this.clickHandler&&(o.browserEvents.unbind(this.clickHandler),this.clickHandler=null)}getId(){return this.element.id}getValue(){return this.value}isSelected(){return this.selected}setSelected(e){this.selected=e,o.utils.aria.setState(this.element,o.utils.aria.State.SELECTED,this.selected),this.element.classList.toggle("blocklyFieldGridItemSelected",this.selected),this.isSelected()&&this.focus()}onClick(){var e;this.setSelected(!0),null===(e=this.selectionCallback)||void 0===e||e.call(this,this)}focus(){this.element.focus({preventScroll:!0});const e=this.element.offsetParent;if(!e)return;const t=this.element.offsetTop,i=e.scrollTop,n=this.getInterItemSpacing();t<i?e.scrollTo(0,t-n):t+this.element.offsetHeight>i+e.clientHeight&&e.scrollBy(0,t+this.element.clientHeight-(i+e.clientHeight)+n)}getInterItemSpacing(){const e=this.element.closest(".blocklyFieldGrid");if(!e)return 0;const t=[...e.querySelectorAll(".blocklyFieldGridItem")];if(!t.length)return 0;const i=t[0].offsetTop,n=t[0].offsetHeight;for(const e of t)if(e.offsetTop!==i)return e.offsetTop-n-i;return 0}}class a{constructor(e,t,i,n,s){if(this.columns=i,this.rtl=n,this.itemIndices=new Map,this.items=new Array,this.keyDownHandler=null,this.pointerMoveHandler=null,this.selectionCallback=s,this.root=document.createElement("div"),this.root.className="blocklyFieldGrid",this.root.tabIndex=0,o.utils.aria.setRole(this.root,o.utils.aria.Role.GRID),e.appendChild(this.root),this.populateItems(t),this.keyDownHandler=o.browserEvents.conditionalBind(this.root,"keydown",this,this.onKeyDown),this.pointerMoveHandler=o.browserEvents.conditionalBind(this.root,"pointermove",this,this.onPointerMove,!0),!(i>=1))throw new Error(`Number of columns must be >= 1; got ${i}`);this.columns=i,this.root.style.setProperty("--grid-columns",`${this.columns}`)}populateItems(e){let t=document.createElement("div");for(const[i,n]of e.entries()){if(n===o.FieldDropdown.SEPARATOR)continue;i%this.columns===0&&(t=document.createElement("div"),t.className="blocklyFieldGridRow",o.utils.aria.setRole(t,o.utils.aria.Role.ROW),this.root.appendChild(t));const[e,s]=n,a=(()=>{if((t=e)&&"object"==typeof t&&"src"in t&&"string"==typeof t.src&&"alt"in t&&"string"==typeof t.alt&&"width"in t&&"number"==typeof t.width&&"height"in t&&"number"==typeof t.height){const t=new Image(e.width,e.height);return t.src=e.src,t.alt=e.alt||"",t}var t;return e})(),l=new r(t,a,s,e=>{var t;this.setSelectedValue(e.getValue()),null===(t=this.selectionCallback)||void 0===t||t.call(this,e)});this.itemIndices.set(l.getId(),this.itemIndices.size),this.items.push(l)}}dispose(){this.selectionCallback=void 0;for(const e of this.items)e.dispose();this.itemIndices.clear(),this.items.length=0,this.keyDownHandler&&(o.browserEvents.unbind(this.keyDownHandler),this.keyDownHandler=null),this.pointerMoveHandler&&(o.browserEvents.unbind(this.pointerMoveHandler),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":return void e.stopPropagation();default:return}e.preventDefault(),e.stopPropagation()}}onPointerMove(e){if(!e.movementX&&!e.movementY||!(e.target instanceof Element))return;const t=e.target.closest(".blocklyFieldGridItem");if(!t)return;const i=t.id,n=this.itemIndices.get(i);void 0!==n&&this.moveFocus(n,!1)}setSelectedValue(e){for(const[t,i]of this.items.entries()){const n=i.getValue()===e;i.setSelected(n),n&&this.moveFocus(t,!1)}}moveFocus(e,t){let i=e;if(t){const e=this.getFocusedItem();if(!e)return;i+=this.indexOfItem(e)}const n=this.itemAtIndex(i);n&&(n.focus(),o.utils.aria.setState(this.root,o.utils.aria.State.ACTIVEDESCENDANT,n.getId()))}indexOfItem(e){var t;return null!==(t=this.itemIndices.get(e.getId()))&&void 0!==t?t:-1}itemAtIndex(e){return this.items[e]}getFocusedItem(){var e;const t=null!==(e=this.root.querySelector(".blocklyFieldGridItem:focus"))&&void 0!==e?e:this.root.querySelector(".blocklyFieldGridItem");if(!t||!t.id)return;const i=this.itemIndices.get(t.id);return void 0!==i?this.itemAtIndex(i):void 0}}class l extends o.FieldDropdown{constructor(e,t,i){super(e,t,i),this.columns=3,(null==i?void 0:i.columns)&&this.setColumns(parseInt(`${i.columns}`)),i&&i.primaryColour&&(this.primaryColour=i.primaryColour),i&&i.borderColour&&(this.borderColour=i.borderColour)}static fromJson(e){if(!e.options)throw new 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,o.DropDownDiv.getOwner()===this&&o.DropDownDiv.isVisible()&&(null===(t=this.grid)||void 0===t||t.dispose(),this.showEditor_()))}showEditor_(e){var t;o.DropDownDiv.clearContent();const i=!!(null===(t=this.getSourceBlock())||void 0===t?void 0:t.workspace.RTL);this.grid=new a(o.DropDownDiv.getContentDiv(),this.getOptions(!1),this.columns,i,e=>{o.DropDownDiv.hideIfOwner(this),this.setValue(e.getValue())}),o.DropDownDiv.getContentDiv().classList.add("blocklyFieldGridContainer");const n=this.getColours();n&&n.border&&o.DropDownDiv.setColour(n.primary,n.border),o.DropDownDiv.showPositionedByField(this,this.dropdownDispose_.bind(this));const s=this.getValue();s&&this.grid.setSelectedValue(s)}doValueUpdate_(e){var t;super.doValueUpdate_(e),null===(t=this.grid)||void 0===t||t.setSelectedValue(e)}getColours(){var e,t;if(this.primaryColour&&this.borderColour)return{primary:this.primaryColour,border:this.borderColour};const i=this.getSourceBlock();if(!(i instanceof o.BlockSvg))return;const n=i.isShadow()?i.getParent():i;return n?{primary:null!==(e=this.primaryColour)&&void 0!==e?e:n.getColour(),border:null!==(t=this.borderColour)&&void 0!==t?t:n.getColourTertiary()}:void 0}}return o.fieldRegistry.register("field_grid_dropdown",l),o.Css.register("\n .blocklyFieldGridContainer {\n padding: 7px;\n overflow: auto;\n }\n \n .blocklyFieldGrid {\n display: grid;\n grid-gap: 7px;\n grid-template-columns: repeat(var(--grid-columns), min-content);\n }\n\n .blocklyFieldGrid .blocklyFieldGridItem {\n border: 1px solid rgba(1, 1, 1, 0.5);\n border-radius: 4px;\n color: white;\n min-width: auto;\n background: none;\n white-space: nowrap;\n cursor: pointer;\n padding: 6px 15px;\n }\n \n .blocklyFieldGrid .blocklyFieldGridRow {\n display: contents;\n }\n \n .blocklyFieldGrid .blocklyFieldGridItem.blocklyFieldGridItemSelected {\n background-color: rgba(1, 1, 1, 0.25);\n }\n\n .blocklyFieldGrid .blocklyFieldGridItem:focus {\n box-shadow: 0 0 0 4px hsla(0, 0%, 100%, .2);\n outline: none;\n }\n "),s})())},{"blockly/core":255}],251:[function(e,t,i){
|
|
9
9
|
/*! For license information please see index.js.LICENSE.txt */
|