@@ -1220,7 +1220,7 @@ var ve,ge,he;function fe(e){return e.substr(0,e.indexOf("."))}null===(ve=window.
icon="${t.icon}"
style="position: absolute; transform: scale(0.5) translate(15px, -20px)">
- `),e):[]}_getContext(){return new Vl((()=>this.mapScale),(()=>this.realScale),(e=>this._getMousePosition(e)),(()=>this.requestUpdate()),(()=>this._selectionChanged()),(()=>this.coordinatesConverter),(()=>this.selectedManualRectangles),(()=>this.selectedPredefinedRectangles),(()=>this.selectedRooms),(()=>this.selectedPredefinedPoint),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.coordinatesRounding)&&void 0!==t&&t}),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.coordinatesToMetersDivider)&&void 0!==t?t:1}),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.maxSelections)&&void 0!==t?t:0}),(e=>this._getCssProperty(e)),(()=>this._runImmediately()),(e=>this._localize(e)))}_getMousePosition(e){return al(e,this._getSvgWrapper(),this.mapScale)}_setCurrentMode(e,t=!0){const i=this.modes[e];switch(this.selectedManualRectangles=[],this.selectedManualPoint=void 0,this.selectedManualPath.clear(),this.selectedPredefinedRectangles=[],this.selectedRooms=[],this.selectedPredefinedPoint=[],this.selectablePredefinedRectangles=[],this.selectableRooms=[],this.selectablePredefinedPoints=[],null==i?void 0:i.selectionType){case tr.PREDEFINED_RECTANGLE:const e=Xl.getFromEntities(i,this.hass,(()=>this._getContext())),t=i.predefinedSelections.map((e=>e)).filter((e=>"string"!=typeof e.zones)).map((e=>new Xl(e,this._getContext())));this.selectablePredefinedRectangles=e.concat(t);break;case tr.ROOM:this.selectableRooms=i.predefinedSelections.map((e=>new Gl(e,this._getContext())));break;case tr.PREDEFINED_POINT:const a=Kl.getFromEntities(i,this.hass,(()=>this._getContext())),n=i.predefinedSelections.map((e=>e)).filter((e=>"string"!=typeof e.position)).map((e=>new Kl(e,this._getContext())));this.selectablePredefinedPoints=a.concat(n)}this.selectedMode!=e&&t&&ke("selection"),this.selectedMode=e,this._selectionChanged()}_getCurrentMode(){return this.modes[this.selectedMode]}_getSelection(e){var t,i,a,n,o,r,s;if(!e)return{selection:[],variables:{}};const l=e.repeatsType===ir.INTERNAL?this.repeats:null;let c=[],d={};const u=e=>{var t,i;return Object.assign(Object.assign({},null!==(i=null===(t=e[0])||void 0===t?void 0:t.variables)&&void 0!==i?i:{}),{variables:e.map((e=>{var t;return null!==(t=null==e?void 0:e.variables)&&void 0!==t?t:{}}))})};switch(e.selectionType){case tr.MANUAL_RECTANGLE:c=this.selectedManualRectangles.map((e=>e.toVacuum(l))),d=u(this.selectedManualRectangles);break;case tr.PREDEFINED_RECTANGLE:c=this.selectedPredefinedRectangles.map((e=>e.toVacuum(l))).reduce(((e,t)=>e.concat(t)),[]),d=null!==(i=null===(t=this.selectedPredefinedRectangles[0])||void 0===t?void 0:t.variables)&&void 0!==i?i:{},d=u(this.selectedPredefinedRectangles);break;case tr.ROOM:const m=this.selectedRooms.map((e=>e.toVacuum())).map((t=>zc.adjustRoomId(t,e)));c=[...m,...l&&m.length>0?[l]:[]],d=null!==(n=null===(a=this.selectedRooms[0])||void 0===a?void 0:a.variables)&&void 0!==n?n:{},d=u(this.selectedRooms);break;case tr.MANUAL_PATH:c=this.selectedManualPath.toVacuum(l),d=null!==(o=this.selectedManualPath.variables)&&void 0!==o?o:{},d=u([this.selectedManualPath]);break;case tr.MANUAL_POINT:c=null!==(s=null===(r=this.selectedManualPoint)||void 0===r?void 0:r.toVacuum(l))&&void 0!==s?s:[],d=u([this.selectedManualPoint]);break;case tr.PREDEFINED_POINT:c=this.selectedPredefinedPoint.map((e=>e.toVacuum(l))).reduce(((e,t)=>e.concat(t)),[]),d=u(this.selectedPredefinedPoint)}return e.repeatsType===ir.REPEAT&&(c=Array(this.repeats).fill(0).flatMap((()=>c))),{selection:c,variables:d}}async _runImmediately(){var e,t;return!(null===(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.runImmediately)||void 0===t||!t)&&(await this._run(!1),!0)}_selectionChanged(){const e=this._getCurrentMode(),{selection:t}=this._getSelection(e);if(this.isInEditor){const e=new Event(Cs);e.selection=null!=t?t:"[]",window.dispatchEvent(e)}}_isInEditor(){return function e(t){var i,a,n,o,r,s,l;return"hui-card"===(null===(a=null===(i=t.parentElement)||void 0===i?void 0:i.tagName)||void 0===a?void 0:a.toLowerCase())&&"preview"in(null!==(o=null===(n=t.parentElement)||void 0===n?void 0:n.attributes)&&void 0!==o?o:[])||"hui-card-preview"===(null===(s=null===(r=t.parentElement)||void 0===r?void 0:r.tagName)||void 0===s?void 0:s.toLowerCase())||null!=t.parentElement&&e(t.parentElement)||"[object ShadowRoot]"==(null===(l=t.parentNode)||void 0===l?void 0:l.toString())&&e(t.getRootNode().host)}(this)}async _handleAutogeneratedConfigGet(){var e;const t=new Event(Ns),i=await Promise.all((null!==(e=this.config.additional_presets)&&void 0!==e?e:[]).map((async e=>await this._getConfigOfPreset(e))));t.presetConfig=Object.assign(Object.assign(Object.assign({},this.config),await this._getConfigOfPreset(this.config)),{additional_presets:i}),window.dispatchEvent(t)}async _getConfigOfPreset(e){const t=this._getInternalVariables(e),[i,a]=await this._getIconsAndTiles(e,t);return Object.assign(Object.assign({},e),{icons:JSON.parse(JSON.stringify(i)),tiles:JSON.parse(JSON.stringify(a)),map_modes:this._getModes(e).map((e=>e.toMapModeConfig()))})}_handleRoomsConfigGet(){const e=new Event($s);e.roomConfig=this._getRoomsConfig(),window.dispatchEvent(e)}async _handleServiceCallGet(){const e=this._getCurrentPreset(),t=this._getCurrentMode(),{selection:i,variables:a}=this._getSelection(t);if(0!=i.length&&t){const n=await t.getServiceCall(this.hass,e.entity,i,this.repeats,Object.assign(Object.assign({},this.internalVariables),a)),o=new Event(Ls);o.serviceCall=JSON.stringify(n,null,2),window.dispatchEvent(o)}else this._showToast("popups.no_selection","mdi:close",!1),ke("failure")}async _handleLovelaceDomEvent(e){var t;const i=e;if(Ds in i.detail&&"action_handler_id"in i.detail[Ds]&&i.detail[Ds].action_handler_id===(null!==(t=this.config.action_handler_id)&&void 0!==t?t:"this")){const e=i.detail[Ds];if(void 0===e.action)return;const t=e.action,a=e.data,n=this._getCurrentMode();switch(t){case ml.CLEANING_START:await this._run(!1);break;case ml.INTERNAL_VARIABLE_SET:this._setInternalVariable(a.variable,a.value);break;case ml.MAP_MODE_NEXT:this._setCurrentMode((this.selectedMode+1)%this.modes.length,!1);break;case ml.MAP_MODE_PREVIOUS:this._setCurrentMode((this.selectedMode-1+this.modes.length)%this.modes.length,!1);break;case ml.MAP_MODE_SET:this._setCurrentMode(a.index%this.modes.length,!1);break;case ml.REPEATS_DECREMENT:n&&(this.repeats=(this.repeats+n.maxRepeats-2)%n.maxRepeats+1);break;case ml.REPEATS_INCREMENT:n&&(this.repeats=this.repeats%n.maxRepeats+1);break;case ml.REPEATS_SET:n&&(this.repeats=(a.value+n.maxRepeats-1)%n.maxRepeats+1);break;case ml.SELECTION_CLEAR:this._setCurrentMode(this.selectedMode)}}}_setInternalVariable(e,t){const i=Object.assign({},this.internalVariables);i[e]=t,this.internalVariables=i,this.requestUpdate()}_getRoomsConfig(){var e,t,i,a,n,o,r,s,l,c;const d=this._getCurrentPreset(),u=null===(i=this.hass.states[null!==(t=null===(e=d.map_source)||void 0===e?void 0:e.camera)&&void 0!==t?t:""])||void 0===i?void 0:i.attributes.rooms,m=new Array;if(u){const e=this.modes.filter((e=>e.selectionType===tr.ROOM)).reverse()[0],t=e?this.modes.indexOf(e):-1;for(const e in u){if(!u.hasOwnProperty(e))continue;const t=u[e];if(!(t.outline||t.x0||t.y0||t.x1||t.y1))continue;const i=null!==(a=t.outline)&&void 0!==a?a:[[t.x0,t.y0],[t.x1,t.y0],[t.x1,t.y1],[t.x0,t.y1]],d=i.toString().includes("."),p=(e,t=1)=>d?e/t:Math.round(e/t),_=i.reduce(((e,t)=>{var i;return e+(null!==(i=t[0])&&void 0!==i?i:0)}),0),v=i.reduce(((e,t)=>{var i;return e+(null!==(i=t[1])&&void 0!==i?i:0)}),0),g={id:e,icon:{name:null!==(n=t.icon)&&void 0!==n?n:"mdi:broom",x:null!==(o=t.x)&&void 0!==o?o:p(_,i.length),y:null!==(r=t.y)&&void 0!==r?r:p(v,i.length)},label:{text:null!==(s=t.name)&&void 0!==s?s:`Room ${e}`,x:null!==(l=t.x)&&void 0!==l?l:p(_,i.length),y:null!==(c=t.y)&&void 0!==c?c:p(v,i.length),offset_y:35},outline:i};m.push(g)}return{modeIndex:t,rooms:m}}}static adjustRoomId(e,t){return"number"===t.idType?+e:e}async _run(e){var t,i;const a=this._getCurrentPreset(),n=this._getCurrentMode(),{selection:o,variables:r}=this._getSelection(n);if(0!=o.length&&n){const i=this.repeats,s=await n.getServiceCall(this.hass,a.entity,o,i,Object.assign(Object.assign({},this.internalVariables),r));if(e||null!==(t=this.config.debug)&&void 0!==t&&t){const e=JSON.stringify(s,null,2);this._showToast("popups.success","mdi:check",!0),console.log(e),window.alert(e),ke("success")}else this.hass.callService(s.domain,s.service,s.serviceData,s.target).then((()=>{this._showToast("popups.success","mdi:check",!0),ke("success")}),(e=>{this._showToast("popups.failed","mdi:close",!1,e.message),ke("failure")}))}else this._showToast("popups.no_selection","mdi:close",!1),ke("failure");(null===(i=a.clean_selection_on_start)||void 0===i||i)&&this._setCurrentMode(this.selectedMode),this._selectionChanged()}_updateElements(){var e,t;const i=null===(t=null===(e=this._modesDropdownMenu)||void 0===e?void 0:e.shadowRoot)||void 0===t?void 0:t.querySelector(".dropdown-content");i&&(i.style.borderRadius=this._getCssProperty("--map-card-internal-big-radius")),ol(100).then((()=>this._calculateBasicScale()))}_drawSelection(){var e,t,i;switch(null===(e=this._getCurrentMode())||void 0===e?void 0:e.selectionType){case tr.MANUAL_RECTANGLE:return V`${this.selectedManualRectangles.map((e=>e.render()))}`;case tr.PREDEFINED_RECTANGLE:return V`${this.selectablePredefinedRectangles.map((e=>e.render()))}`;case tr.ROOM:return V`${this.selectableRooms.map((e=>e.render()))}`;case tr.MANUAL_PATH:return V`${null===(t=this.selectedManualPath)||void 0===t?void 0:t.render()}`;case tr.MANUAL_POINT:return V`${null===(i=this.selectedManualPoint)||void 0===i?void 0:i.render()}`;case tr.PREDEFINED_POINT:return V`${this.selectablePredefinedPoints.map((e=>e.render()))}`;default:return null}}_toggleLock(){this.mapLocked=!this.mapLocked,ke("selection"),ol(500).then((()=>this.requestUpdate()))}_addRectangle(){var e,t,i,a,n,o,r,s;const l=this._getCurrentPreset(),c=this._getCurrentMode(),d=null!==(t=null===(e=l.map_source.crop)||void 0===e?void 0:e.top)&&void 0!==t?t:0,u=null!==(a=null===(i=l.map_source.crop)||void 0===i?void 0:i.bottom)&&void 0!==a?a:0,m=null!==(o=null===(n=l.map_source.crop)||void 0===n?void 0:n.left)&&void 0!==o?o:0,p=null!==(s=null===(r=l.map_source.crop)||void 0===r?void 0:r.right)&&void 0!==s?s:0;if(this._calculateBasicScale(),!c||this.selectedManualRectangles.length>=c.maxSelections)return void ke("failure");const _=this.realImageHeight*this.realScale-d-u,v=this.realImageWidth*this.realScale-m-p,g=(this.selectedManualRectangles.length+1).toString(),h=(v/3+m-this.mapX)/this.mapScale,f=(_/3+d-this.mapY)/this.mapScale,b=v/3/this.mapScale,y=_/3/this.mapScale;this.selectedManualRectangles.push(new Dl(h,f,b,y,g,this._getContext())),this._selectionChanged(),ke("selection"),this.requestUpdate()}_mouseDown(e){e instanceof MouseEvent&&0!=e.button||(this.shouldHandleMouseUp=!0)}_mouseMove(e){e.target.classList.contains("draggable")||(this.selectedManualRectangles.filter((e=>e.isSelected())).forEach((t=>t.externalDrag(e))),this.shouldHandleMouseUp=!1)}_mouseUp(e){const t=this._getCurrentMode();if(!(e instanceof MouseEvent&&0!=e.button)&&this.shouldHandleMouseUp&&t){const{x:i,y:a}=al(e,this._getSvgWrapper(),1);switch(t.selectionType){case tr.MANUAL_PATH:ke("selection"),this.selectedManualPath.addPoint(i,a),this._selectionChanged();break;case tr.MANUAL_POINT:ke("selection"),this.selectedManualPoint=new Ul(i,a,this._getContext()),this._selectionChanged();break;default:return}Zs(e),this.requestUpdate()}this.shouldHandleMouseUp=!1}_handleRunAction(){return async e=>{var t;if(this.hass&&(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.action))switch(e.detail.action){case"tap":await this._run(!1);break;case"hold":await this._run(!0);break;case"double_tap":console.log(JSON.stringify(Object.assign(Object.assign({},this._getCurrentPreset()),{additional_presets:void 0,title:void 0,type:void 0}),null,2)),window.alert("Configuration available in browser's console"),ke("success")}}}_restoreMap(){const e=this._getMapZoomerContent();e.style.transitionDuration=this._getCssProperty("--map-card-internal-transitions-duration"),this._getPinchZoom().setTransform({scale:1,x:0,y:0,allowChangeEvent:!0}),this.mapScale=1,ke("selection"),ol(300).then((()=>e.style.transitionDuration="0s"))}_getCssProperty(e){return getComputedStyle(this._getMapImage()).getPropertyValue(e)}_zoomIn(){ke("selection"),this._updateScale(1.5)}_zoomOut(){ke("selection"),this._updateScale(1/1.5)}_updateScale(e){const t=this._getMapZoomerContent(),i=this._getPinchZoom(),a=this._getPinchZoom().getBoundingClientRect();this.mapScale=Math.max(this.mapScale*e,.5),t.style.transitionDuration="200ms",i.scaleTo(this.mapScale,{originX:a.left+a.width/2,originY:a.top+a.height/2,relativeTo:"container",allowChangeEvent:!0}),ol(300).then((()=>t.style.transitionDuration="0s"))}_calculateBasicScale(){const e=this._getMapImage();e&&e.naturalWidth>0&&(this.realImageWidth=e.naturalWidth,this.realImageHeight=e.naturalHeight,this.realScale=e.width/e.naturalWidth)}_calculateScale(){const e=this._getPinchZoom();this.mapScale=e.scale,this.mapX=e.x,this.mapY=e.y}_getPinchZoom(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-zoomer")}_getMapImage(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-image")}_getMapZoomerContent(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-zoomer-content")}_getSvgWrapper(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("#svg-wrapper")}_showConfigErrors(e){e.forEach((e=>console.error(e)));const t=document.createElement("hui-error-card");return t.setConfig({type:"error",error:e[0],origConfig:this.config}),D` ${t} `}_showOldConfig(){return D`
+ `),e):[]}_getContext(){return new Vl((()=>this.mapScale),(()=>this.realScale),(e=>this._getMousePosition(e)),(()=>this.requestUpdate()),(()=>this._selectionChanged()),(()=>this.coordinatesConverter),(()=>this.selectedManualRectangles),(()=>this.selectedPredefinedRectangles),(()=>this.selectedRooms),(()=>this.selectedPredefinedPoint),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.coordinatesRounding)&&void 0!==t&&t}),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.coordinatesToMetersDivider)&&void 0!==t?t:1}),(()=>{var e,t;return null!==(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.maxSelections)&&void 0!==t?t:0}),(e=>this._getCssProperty(e)),(()=>this._runImmediately()),(e=>this._localize(e)))}_getMousePosition(e){return al(e,this._getSvgWrapper(),this.mapScale)}_setCurrentMode(e,t=!0){const i=this.modes[e];switch(this.selectedManualRectangles=[],this.selectedManualPoint=void 0,this.selectedManualPath.clear(),this.selectedPredefinedRectangles=[],this.selectedRooms=[],this.selectedPredefinedPoint=[],this.selectablePredefinedRectangles=[],this.selectableRooms=[],this.selectablePredefinedPoints=[],null==i?void 0:i.selectionType){case tr.PREDEFINED_RECTANGLE:const e=Xl.getFromEntities(i,this.hass,(()=>this._getContext())),t=i.predefinedSelections.map((e=>e)).filter((e=>"string"!=typeof e.zones)).map((e=>new Xl(e,this._getContext())));this.selectablePredefinedRectangles=e.concat(t);break;case tr.ROOM:this.selectableRooms=i.predefinedSelections.map((e=>new Gl(e,this._getContext())));break;case tr.PREDEFINED_POINT:const a=Kl.getFromEntities(i,this.hass,(()=>this._getContext())),n=i.predefinedSelections.map((e=>e)).filter((e=>"string"!=typeof e.position)).map((e=>new Kl(e,this._getContext())));this.selectablePredefinedPoints=a.concat(n)}this.selectedMode!=e&&t&&ke("selection"),this.selectedMode=e,this._selectionChanged()}_getCurrentMode(){return this.modes[this.selectedMode]}_getSelection(e){var t,i,a,n,o,r,s;if(!e)return{selection:[],variables:{}};const l=e.repeatsType===ir.INTERNAL?this.repeats:null;let c=[],d={};const u=e=>{var t,i;return Object.assign(Object.assign({},null!==(i=null===(t=e[0])||void 0===t?void 0:t.variables)&&void 0!==i?i:{}),{variables:e.map((e=>{var t;return null!==(t=null==e?void 0:e.variables)&&void 0!==t?t:{}}))})};switch(e.selectionType){case tr.MANUAL_RECTANGLE:c=this.selectedManualRectangles.map((e=>e.toVacuum(l))),d=u(this.selectedManualRectangles);break;case tr.PREDEFINED_RECTANGLE:c=this.selectedPredefinedRectangles.map((e=>e.toVacuum(l))).reduce(((e,t)=>e.concat(t)),[]),d=null!==(i=null===(t=this.selectedPredefinedRectangles[0])||void 0===t?void 0:t.variables)&&void 0!==i?i:{},d=u(this.selectedPredefinedRectangles);break;case tr.ROOM:const m=this.selectedRooms.map((e=>e.toVacuum())).map((t=>zc.adjustRoomId(t,e)));c=[...m,...l&&m.length>0?[l]:[]],d=null!==(n=null===(a=this.selectedRooms[0])||void 0===a?void 0:a.variables)&&void 0!==n?n:{},d=u(this.selectedRooms);break;case tr.MANUAL_PATH:c=this.selectedManualPath.toVacuum(l),d=null!==(o=this.selectedManualPath.variables)&&void 0!==o?o:{},d=u([this.selectedManualPath]);break;case tr.MANUAL_POINT:c=null!==(s=null===(r=this.selectedManualPoint)||void 0===r?void 0:r.toVacuum(l))&&void 0!==s?s:[],d=u([this.selectedManualPoint]);break;case tr.PREDEFINED_POINT:c=this.selectedPredefinedPoint.map((e=>e.toVacuum(l))).reduce(((e,t)=>e.concat(t)),[]),d=u(this.selectedPredefinedPoint)}return e.repeatsType===ir.REPEAT&&(c=Array(this.repeats).fill(0).flatMap((()=>c))),{selection:c,variables:d}}async _runImmediately(){var e,t;return!(null===(t=null===(e=this._getCurrentMode())||void 0===e?void 0:e.runImmediately)||void 0===t||!t)&&(await this._run(!1),!0)}_selectionChanged(){const e=this._getCurrentMode(),{selection:t}=this._getSelection(e);if(this.isInEditor){const e=new Event(Cs);e.selection=null!=t?t:"[]",window.dispatchEvent(e)}}_isInEditor(){return function e(t){var i,a,n,o,r,s,l,c,d,u,m;return"hui-card"===(null===(a=null===(i=t.parentElement)||void 0===i?void 0:i.tagName)||void 0===a?void 0:a.toLowerCase())&&"preview"in(null!==(o=null===(n=t.parentElement)||void 0===n?void 0:n.attributes)&&void 0!==o?o:[])||"hui-section"===(null===(s=null===(r=t.parentElement)||void 0===r?void 0:r.tagName)||void 0===s?void 0:s.toLowerCase())&&"preview"in(null!==(c=null===(l=t.parentElement)||void 0===l?void 0:l.attributes)&&void 0!==c?c:[])||"hui-card-preview"===(null===(u=null===(d=t.parentElement)||void 0===d?void 0:d.tagName)||void 0===u?void 0:u.toLowerCase())||null!=t.parentElement&&e(t.parentElement)||"[object ShadowRoot]"==(null===(m=t.parentNode)||void 0===m?void 0:m.toString())&&e(t.getRootNode().host)}(this)}async _handleAutogeneratedConfigGet(){var e;const t=new Event(Ns),i=await Promise.all((null!==(e=this.config.additional_presets)&&void 0!==e?e:[]).map((async e=>await this._getConfigOfPreset(e))));t.presetConfig=Object.assign(Object.assign(Object.assign({},this.config),await this._getConfigOfPreset(this.config)),{additional_presets:i}),window.dispatchEvent(t)}async _getConfigOfPreset(e){const t=this._getInternalVariables(e),[i,a]=await this._getIconsAndTiles(e,t);return Object.assign(Object.assign({},e),{icons:JSON.parse(JSON.stringify(i)),tiles:JSON.parse(JSON.stringify(a)),map_modes:this._getModes(e).map((e=>e.toMapModeConfig()))})}_handleRoomsConfigGet(){const e=new Event($s);e.roomConfig=this._getRoomsConfig(),window.dispatchEvent(e)}async _handleServiceCallGet(){const e=this._getCurrentPreset(),t=this._getCurrentMode(),{selection:i,variables:a}=this._getSelection(t);if(0!=i.length&&t){const n=await t.getServiceCall(this.hass,e.entity,i,this.repeats,Object.assign(Object.assign({},this.internalVariables),a)),o=new Event(Ls);o.serviceCall=JSON.stringify(n,null,2),window.dispatchEvent(o)}else this._showToast("popups.no_selection","mdi:close",!1),ke("failure")}async _handleLovelaceDomEvent(e){var t;const i=e;if(Ds in i.detail&&"action_handler_id"in i.detail[Ds]&&i.detail[Ds].action_handler_id===(null!==(t=this.config.action_handler_id)&&void 0!==t?t:"this")){const e=i.detail[Ds];if(void 0===e.action)return;const t=e.action,a=e.data,n=this._getCurrentMode();switch(t){case ml.CLEANING_START:await this._run(!1);break;case ml.INTERNAL_VARIABLE_SET:this._setInternalVariable(a.variable,a.value);break;case ml.MAP_MODE_NEXT:this._setCurrentMode((this.selectedMode+1)%this.modes.length,!1);break;case ml.MAP_MODE_PREVIOUS:this._setCurrentMode((this.selectedMode-1+this.modes.length)%this.modes.length,!1);break;case ml.MAP_MODE_SET:this._setCurrentMode(a.index%this.modes.length,!1);break;case ml.REPEATS_DECREMENT:n&&(this.repeats=(this.repeats+n.maxRepeats-2)%n.maxRepeats+1);break;case ml.REPEATS_INCREMENT:n&&(this.repeats=this.repeats%n.maxRepeats+1);break;case ml.REPEATS_SET:n&&(this.repeats=(a.value+n.maxRepeats-1)%n.maxRepeats+1);break;case ml.SELECTION_CLEAR:this._setCurrentMode(this.selectedMode)}}}_setInternalVariable(e,t){const i=Object.assign({},this.internalVariables);i[e]=t,this.internalVariables=i,this.requestUpdate()}_getRoomsConfig(){var e,t,i,a,n,o,r,s,l,c;const d=this._getCurrentPreset(),u=null===(i=this.hass.states[null!==(t=null===(e=d.map_source)||void 0===e?void 0:e.camera)&&void 0!==t?t:""])||void 0===i?void 0:i.attributes.rooms,m=new Array;if(u){const e=this.modes.filter((e=>e.selectionType===tr.ROOM)).reverse()[0],t=e?this.modes.indexOf(e):-1;for(const e in u){if(!u.hasOwnProperty(e))continue;const t=u[e];if(!(t.outline||t.x0||t.y0||t.x1||t.y1))continue;const i=null!==(a=t.outline)&&void 0!==a?a:[[t.x0,t.y0],[t.x1,t.y0],[t.x1,t.y1],[t.x0,t.y1]],d=i.toString().includes("."),p=(e,t=1)=>d?e/t:Math.round(e/t),_=i.reduce(((e,t)=>{var i;return e+(null!==(i=t[0])&&void 0!==i?i:0)}),0),v=i.reduce(((e,t)=>{var i;return e+(null!==(i=t[1])&&void 0!==i?i:0)}),0),g={id:e,icon:{name:null!==(n=t.icon)&&void 0!==n?n:"mdi:broom",x:null!==(o=t.x)&&void 0!==o?o:p(_,i.length),y:null!==(r=t.y)&&void 0!==r?r:p(v,i.length)},label:{text:null!==(s=t.name)&&void 0!==s?s:`Room ${e}`,x:null!==(l=t.x)&&void 0!==l?l:p(_,i.length),y:null!==(c=t.y)&&void 0!==c?c:p(v,i.length),offset_y:35},outline:i};m.push(g)}return{modeIndex:t,rooms:m}}}static adjustRoomId(e,t){return"number"===t.idType?+e:e}async _run(e){var t,i;const a=this._getCurrentPreset(),n=this._getCurrentMode(),{selection:o,variables:r}=this._getSelection(n);if(0!=o.length&&n){const i=this.repeats,s=await n.getServiceCall(this.hass,a.entity,o,i,Object.assign(Object.assign({},this.internalVariables),r));if(e||null!==(t=this.config.debug)&&void 0!==t&&t){const e=JSON.stringify(s,null,2);this._showToast("popups.success","mdi:check",!0),console.log(e),window.alert(e),ke("success")}else this.hass.callService(s.domain,s.service,s.serviceData,s.target).then((()=>{this._showToast("popups.success","mdi:check",!0),ke("success")}),(e=>{this._showToast("popups.failed","mdi:close",!1,e.message),ke("failure")}))}else this._showToast("popups.no_selection","mdi:close",!1),ke("failure");(null===(i=a.clean_selection_on_start)||void 0===i||i)&&this._setCurrentMode(this.selectedMode),this._selectionChanged()}_updateElements(){var e,t;const i=null===(t=null===(e=this._modesDropdownMenu)||void 0===e?void 0:e.shadowRoot)||void 0===t?void 0:t.querySelector(".dropdown-content");i&&(i.style.borderRadius=this._getCssProperty("--map-card-internal-big-radius")),ol(100).then((()=>this._calculateBasicScale()))}_drawSelection(){var e,t,i;switch(null===(e=this._getCurrentMode())||void 0===e?void 0:e.selectionType){case tr.MANUAL_RECTANGLE:return V`${this.selectedManualRectangles.map((e=>e.render()))}`;case tr.PREDEFINED_RECTANGLE:return V`${this.selectablePredefinedRectangles.map((e=>e.render()))}`;case tr.ROOM:return V`${this.selectableRooms.map((e=>e.render()))}`;case tr.MANUAL_PATH:return V`${null===(t=this.selectedManualPath)||void 0===t?void 0:t.render()}`;case tr.MANUAL_POINT:return V`${null===(i=this.selectedManualPoint)||void 0===i?void 0:i.render()}`;case tr.PREDEFINED_POINT:return V`${this.selectablePredefinedPoints.map((e=>e.render()))}`;default:return null}}_toggleLock(){this.mapLocked=!this.mapLocked,ke("selection"),ol(500).then((()=>this.requestUpdate()))}_addRectangle(){var e,t,i,a,n,o,r,s;const l=this._getCurrentPreset(),c=this._getCurrentMode(),d=null!==(t=null===(e=l.map_source.crop)||void 0===e?void 0:e.top)&&void 0!==t?t:0,u=null!==(a=null===(i=l.map_source.crop)||void 0===i?void 0:i.bottom)&&void 0!==a?a:0,m=null!==(o=null===(n=l.map_source.crop)||void 0===n?void 0:n.left)&&void 0!==o?o:0,p=null!==(s=null===(r=l.map_source.crop)||void 0===r?void 0:r.right)&&void 0!==s?s:0;if(this._calculateBasicScale(),!c||this.selectedManualRectangles.length>=c.maxSelections)return void ke("failure");const _=this.realImageHeight*this.realScale-d-u,v=this.realImageWidth*this.realScale-m-p,g=(this.selectedManualRectangles.length+1).toString(),h=(v/3+m-this.mapX)/this.mapScale,f=(_/3+d-this.mapY)/this.mapScale,b=v/3/this.mapScale,y=_/3/this.mapScale;this.selectedManualRectangles.push(new Dl(h,f,b,y,g,this._getContext())),this._selectionChanged(),ke("selection"),this.requestUpdate()}_mouseDown(e){e instanceof MouseEvent&&0!=e.button||(this.shouldHandleMouseUp=!0)}_mouseMove(e){e.target.classList.contains("draggable")||(this.selectedManualRectangles.filter((e=>e.isSelected())).forEach((t=>t.externalDrag(e))),this.shouldHandleMouseUp=!1)}_mouseUp(e){const t=this._getCurrentMode();if(!(e instanceof MouseEvent&&0!=e.button)&&this.shouldHandleMouseUp&&t){const{x:i,y:a}=al(e,this._getSvgWrapper(),1);switch(t.selectionType){case tr.MANUAL_PATH:ke("selection"),this.selectedManualPath.addPoint(i,a),this._selectionChanged();break;case tr.MANUAL_POINT:ke("selection"),this.selectedManualPoint=new Ul(i,a,this._getContext()),this._selectionChanged();break;default:return}Zs(e),this.requestUpdate()}this.shouldHandleMouseUp=!1}_handleRunAction(){return async e=>{var t;if(this.hass&&(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.action))switch(e.detail.action){case"tap":await this._run(!1);break;case"hold":await this._run(!0);break;case"double_tap":console.log(JSON.stringify(Object.assign(Object.assign({},this._getCurrentPreset()),{additional_presets:void 0,title:void 0,type:void 0}),null,2)),window.alert("Configuration available in browser's console"),ke("success")}}}_restoreMap(){const e=this._getMapZoomerContent();e.style.transitionDuration=this._getCssProperty("--map-card-internal-transitions-duration"),this._getPinchZoom().setTransform({scale:1,x:0,y:0,allowChangeEvent:!0}),this.mapScale=1,ke("selection"),ol(300).then((()=>e.style.transitionDuration="0s"))}_getCssProperty(e){return getComputedStyle(this._getMapImage()).getPropertyValue(e)}_zoomIn(){ke("selection"),this._updateScale(1.5)}_zoomOut(){ke("selection"),this._updateScale(1/1.5)}_updateScale(e){const t=this._getMapZoomerContent(),i=this._getPinchZoom(),a=this._getPinchZoom().getBoundingClientRect();this.mapScale=Math.max(this.mapScale*e,.5),t.style.transitionDuration="200ms",i.scaleTo(this.mapScale,{originX:a.left+a.width/2,originY:a.top+a.height/2,relativeTo:"container",allowChangeEvent:!0}),ol(300).then((()=>t.style.transitionDuration="0s"))}_calculateBasicScale(){const e=this._getMapImage();e&&e.naturalWidth>0&&(this.realImageWidth=e.naturalWidth,this.realImageHeight=e.naturalHeight,this.realScale=e.width/e.naturalWidth)}_calculateScale(){const e=this._getPinchZoom();this.mapScale=e.scale,this.mapX=e.x,this.mapY=e.y}_getPinchZoom(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-zoomer")}_getMapImage(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-image")}_getMapZoomerContent(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("map-zoomer-content")}_getSvgWrapper(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("#svg-wrapper")}_showConfigErrors(e){e.forEach((e=>console.error(e)));const t=document.createElement("hui-error-card");return t.setConfig({type:"error",error:e[0],origConfig:this.config}),D` ${t} `}_showOldConfig(){return D`
Xiaomi Vacuum Map Card ${zs}
${this._localize("common.old_configuration")}
diff --git a/www/community/lovelace-xiaomi-vacuum-map-card/xiaomi-vacuum-map-card.js.gz b/www/community/lovelace-xiaomi-vacuum-map-card/xiaomi-vacuum-map-card.js.gz
index ef2dd7a2..10915ba1 100644
Binary files a/www/community/lovelace-xiaomi-vacuum-map-card/xiaomi-vacuum-map-card.js.gz and b/www/community/lovelace-xiaomi-vacuum-map-card/xiaomi-vacuum-map-card.js.gz differ