0){o.textContent=Eo?Eo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Xt(this,e,n,0),s=!br(e)||e!==this._$AH&&e!==Je,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new xn(e.insertBefore(_r(),i),i,void 0,n??{})}return o._$AI(t),o};var ms=globalThis,X=class extends _t{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=bc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Je}};X._$litElement$=!0,X.finalized=!0,ms.litElementHydrateSupport?.({LitElement:X});var U_=ms.litElementPolyfillSupport;U_?.({LitElement:X});(ms.litElementVersions??=[]).push("4.2.2");var _s=t=>t.slice(0,t.indexOf(".")),Z_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},Q=t=>Z_[_s(t)]??null,bs=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var yc=new Set(["light","switch","fan"]),Rt=t=>t!==null&&t!=="scene"&&t!=="script",et=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var vc=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var wc=t=>Math.min(1,Math.max(0,t));function q_(t){let e=wc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function gs(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(wc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:q_(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function kc(t,e,n){let r=gs(t,n);if(r)return r;for(let o of e){let i=gs(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Io(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var Mc=[],Do=new Map,Y_=0,he=(t,e)=>`pack:${t}:${e}`,yt=t=>t.startsWith("pack:");function ys(t){Mc=t,Do=new Map;for(let e of t)for(let n of e.items)Do.set(he(e.id,n.id),n);Y_+=1}var wr=()=>Mc;var X_={};function U(t){if(!yt(t))return;let e=Do.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=X_[n];return o?Do.get(he(o,r.join(":"))):void 0}var Q_=.22;function xc(t,e,n,r){let o=Math.min(Q_,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function vr(t,e,n,r,o){return[xc(t*r,n*r,r,o)/o,xc(e*r,n*r,r,o)/o]}var $c=new WeakMap;function Rc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=$c.get(t),c=a?.get(l);if(c)return c;let u=t.parts.map(d=>{if(d.shape==="sweep")return d;let[p,h]=vr(d.x-d.w/2,d.x+d.w/2,-.5,o,e),[f,g]=vr(d.z-d.d/2,d.z+d.d/2,-.5,i,n),[y,b]=vr(d.y,d.y+d.h,0,s,r);if(d.rot)return{...d,x:(p+h)/2,z:(f+g)/2,w:d.w*o/e,d:d.d*i/n,y,h:b-y};let v={...d,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(d.shape==="loft"){let[w,x,k,S]=[d.tx??d.x,d.tz??d.z,d.tw??d.w,d.td??d.d],[E,T]=vr(w-k/2,w+k/2,-.5,o,e),[F,O]=vr(x-S/2,x+S/2,-.5,i,n);Object.assign(v,{tx:(E+T)/2,tz:(F+O)/2,tw:T-E,td:O-F})}return v});return a||$c.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,u),u}var vs=t=>!!t?.parts.some(e=>e.move);var Ec=t=>U(t)?.parts.find(e=>e.screen),Sc=.06;function Ac(t){let e=U(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=Sc&&s>=Sc})}function ut(t){return tt[t]??U(t)?.size??[.6,.6,.8]}function Et(t){let e=U(t);return Hc.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var Fc=t=>!!U(t)?.parts.some(e=>e.picture),$n=t=>!!U(t)?.climate;function Tc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var J_={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function zc(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&J_[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:tb(t,e)+(eb(e)?0:Dc(t,e.x,e.z))}var eb=t=>t.type==="led_strip"||U(t.type)?.mount==="ceiling";function tb(t,e){if(e.type==="lamp_wall")return Pc;if(e.type==="led_strip")return Math.max(0,dt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=U(e.type);if(!n)return Ic(e);switch(n.mount){case"surface":return Oc(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Oo(t,e)-e.h);default:return 0}}function ws(t){if(t==="plant")return"plant";let e=U(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Sn=["electricity","water","gas","heating","cooling"],Lc=["condition","temperature","humidity","pressure","wind_speed","wind_gust_speed","wind_bearing","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility","snow","fog","lightning"],Cc=["turn","slide","top"],Nc=["always","active","no_power","never"],Bc=1.3,Ho=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Wc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Vc=["brick","round","wide","steel"],Lo=["navigate","more_info","service","fire_dom_event"];function Co(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Kc=["rain","snow","fog","clouds","lightning","sky"],jc=["rain","snow","clouds","lightning","sky"],Gc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],ks={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function xs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Uc=["x","-x","z","-z"];function nb(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,u)=>o==="x"?c:o==="-x"?-c:o==="z"?u:-u,s=1/0,l=-1/0;for(let[c,u]of t.points){let d=i(c,u);s=Math.min(s,d),l=Math.max(l,d)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function rb(t,e,n,r){return Zc(t)+(e.offset??0)+ks[e.type]-nb(e,n,r)}function Zc(t){return t.elevation>.3?0:-.2}function qc(t,e,n){let r=(t.outdoor??[]).filter(i=>!xs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?rb(t,o,e,n):Zc(t)}var Yc=t=>t.cut??t.type==="pool",Xc=30,Qc={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Jc=["wood","oak","tiles","carpet","stone","concrete"],eu={type:"none",pitch:35,overhang:.4},No="#d6cfc2",Bo="#e8e3da",tu={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...eu}};function Ft(){return{version:1,floors:[],settings:{...tu},energy:{...Qc},presence:[]}}function Ce(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var ob=2.75;function nu(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*ob*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function ru(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,u=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,u],[c+4,u],[c+4,u+3],[c,u+3]],floor_material:"wood"}})}function ou(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,u=t.z-l*(t.w/2)*s-a*(t.d/2)*i,d=n[0]-c,p=n[1]-u,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((d*i+p*s)*l),g=h((-d*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(u+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Wo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],iu={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ne=["meter","inverter","home_battery","wallbox","grid_point"],su=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Pc=1.75;function Vo(t){return $s.has(t.type)||["stairwell","parking"].includes(t.type)?!1:U(t.type)?.mount!=="ceiling"}function ce(t){return su.has(t)||!!U(t)?.light}var ib=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function au(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Ic(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var $s=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function lu(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var Ss=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Dc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return Ss(r)}function dt(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Oo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:dt(t,e.x,e.z);function Oc(t,e,n){let r=0;for(let o of t.furniture)!(ib.has(o.type)||U(o.type)?.surface)||!N([e,n],As(o))||(r=Math.max(r,o.h));return r}var Hc=new Set([...su,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),tt={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var Ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],Rs=["standard","bars","glass_wall"],Ko=new Set(["interior","front"]);function Jt(t,e){return t.type==="door"?t.style&&Ms.includes(t.style)?t.style:e?"front":"interior":t.style&&Rs.includes(t.style)?t.style:"standard"}function cu(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let u=i-.5;if(a+c>u){let p=Math.max(0,u)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function Es(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var Rn={door:{type:"door",leaves:1,width:.9,sill:0,height:2.05,style:"interior"},front:{type:"door",leaves:1,width:1,sill:0,height:2.1,style:"front"},door_double:{type:"door",leaves:2,width:1.6,sill:0,height:2.05},window:{type:"window",leaves:1,width:1.2,sill:.9,height:1.3},window_double:{type:"window",leaves:2,width:1.6,sill:.9,height:1.3},terrace:{type:"window",leaves:1,width:1,sill:0,height:2.1},terrace_double:{type:"window",leaves:2,width:1.8,sill:0,height:2.1},lift_slide:{type:"window",leaves:1,width:2.4,sill:0,height:2.15,opens:"slide"},garage:{type:"garage",leaves:1,width:2.5,sill:0,height:2.1},glass_wall:{type:"window",leaves:1,width:2,sill:0,height:2.4,style:"glass_wall"}};function En(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&Es(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function Pe(t){t.energy={...Qc,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...tu,...t.settings,roof:{...eu,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Ce(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=tt[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),u=c,d=1;for(;e.furniture.some(p=>p.id===u);)u=`${c}_${d++}`;e.furniture.push({id:u,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return sb(t),t}function sb(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=I(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=I("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function I(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function _e(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function As(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var jo={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var Fs=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),Ts=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var lb=globalThis,du=lb.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},zs=du.plugins,uu=du.listeners;var cb=5;function hu(t,e){t.errors.lengthuu.delete(t)}var Ps=()=>[...zs.values()].map(t=>t.status),pu=()=>[...zs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Uo(t,e){for(let{plugin:n,status:r}of zs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){hu(r,s)}i&&(yield{device:o,status:r})}}function Zo(t,e){for(let{device:n}of Uo(t,e))return n.kind??"sensor";return null}function fu(t,e){let n=t.states[e];if(!n)return null;let r=ub({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function ub(t){let e=null;for(let{device:n,status:r}of Uo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){hu(r,o)}return e}function qo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function mu(t,e){let n=[];for(let{device:r,status:o}of Uo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function gu(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function _u(t,e){for(let{device:n}of Uo(t,e))if(n.floorWedge)return!0;return!1}var db=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),hb=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),pb=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),fb=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var yu=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Be=(t,e)=>Q(e)??Zo(e,t.states[e]);function bu(t,e){let n=t.states[e];if(!n||yu(t,e))return!1;if(Zo(e,n)!==null)return!0;let r=Q(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?db.has(o):hb.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?pb.has(o):!!t.entities?.[e]?.area_id:!0}function mb(t,e){let n=t.states[e];return Q(e)!=="sensor"||!n?.attributes.unit_of_measurement||yu(t,e)||fb.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||et(n)}var Xo=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",Is=null;Go(()=>Is=null);function Ds(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function gb(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=u=>{(bu(t,u)||mb(t,u))&&Rt(Be(t,u))&&i.push(u)};for(let[u,d]of Object.entries(t.entities??{})){let p=d.device_id;p&&d.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(d.area_id),p&&Xo(t,u)&&Ds(n,p).push(u),p&&!d.hidden&&!d.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(_s(u));let h=Tt(t,u);h===null?s(u):bu(t,u)&&Ds(e,h).push(u)}if(t.entities)for(let u of Object.keys(t.states))t.entities[u]||s(u);let l=bs.indexOf("binary")-.5,a=u=>{let d=Q(u),p=d?bs.indexOf(d):l;return p>l&&Zo(u,t.states[u])!==null?l:p};i.sort((u,d)=>a(u)-a(d)||W(t,u).localeCompare(W(t,d)));for(let[u,d]of e){let p=t.areas?.[u]?.name;d.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[u,d]of o)d.size>1&&c.add(u);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function Fn(t){let e=Is;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:Is=gb(t)}function ye(t,e){let n=Yo(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Yo(t,r))])]:n}function Yo(t,e){return!e||!t.entities?[]:Fn(t).byArea.get(e)??[]}function vu(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of Fn(t).byArea){let i=o.filter(s=>Rt(Be(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var wu=t=>t.entities?Fn(t).withoutArea:[],Os=(t,e)=>!!t.entities&&Fn(t).hubs.has(e),Qo=(t,e)=>t.entities?Fn(t).powerByDevice.get(e)??[]:[];function Tn(t,e){let n=new Map;for(let o of e)Ds(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Jo=(t,e)=>Tn(t,e).map(n=>n.primary),_b={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide",illuminance:"illuminance"};function Hs(t,e,n,r=!1){let o=t.states[e]?.attributes;if(!o)return!1;let i=(o.symcon_variable_type===1||o.symcon_variable_type===2)&&typeof o.symcon_id=="number";if(typeof o.symcon_id=="number"&&!i||!i&&!/^(sensor|input_number|number)\./.test(e))return!1;if(r&&i)return!0;let s=String(o.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(s)||n==="humidity"&&!o.device_class&&["%","%rh","%r.h.","%rf","%r.f."].includes(s)||n==="co2"&&s==="ppm"&&/co[₂2]/i.test(String(o.friendly_name??""))||n==="illuminance"&&["lx","lux"].includes(s)?!0:o.device_class===_b[n]}var bb=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),yb=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],vb=new RegExp(`(${yb.join("|")})`,"i");function Ls(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Os(t,n)?Fn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>bb.has(o))?!1:!vb.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function ku(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...ye(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&Hs(t,c,r)&&Ls(t,c))}function xu(t){let e=t.attributes;if(typeof e.symcon_numeric_value!="number")return null;let n=typeof e.symcon_min=="number"?e.symcon_min:0,r=typeof e.symcon_max=="number"&&e.symcon_max>n?e.symcon_max:100;return Math.max(0,Math.min(100,(e.symcon_numeric_value-n)/(r-n)*100))}function ei(t,e){let n=t?.states[e];if(!n)return!1;let r=n.attributes;return typeof r.symcon_id=="number"?r.symcon_variable_type===1||r.symcon_variable_type===2:typeof r.current_position=="number"||/^(sensor|number|input_number)\./.test(e)&&!!n.state.trim()&&Number.isFinite(Number(n.state))}function ti(t,e){let n=e?t.states[e]:void 0;if(!n||et(n))return null;let r=n.attributes;if(r.nf_cover_control&&typeof r.current_position=="number")return r.current_position;let o=xu(n);if(o!==null)return o;if(typeof r.current_position=="number")return Math.max(0,Math.min(100,r.current_position));if(!n.state.trim())return null;let i=Number(n.state);if(!Number.isFinite(i))return null;let s=r.unit_of_measurement==="%"||i>1||i<0?i:i*100;return Math.max(0,Math.min(100,s))}var wb=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),kb=new Set(["garage","gate"]),xb=new Set(["window","opening"]);function kr(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var $u=(t,e)=>t==="none"?null:t??e??null,zt=t=>t&&t!=="none"?t:null;function Pt(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=ye(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>Q(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),u=kr(c("window"),s.filter(g=>Q(g)==="cover"&&wb.has(l(g))),!0),d=kr(c("window"),a(g=>xb.has(g))),p=kr(c("door"),a(g=>g==="door")),h=kr(c("garage"),s.filter(g=>Q(g)==="cover"&&kb.has(l(g)??""))),f=kr(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?u:g.type==="garage"?h:null,b=g.type==="window"?d:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:$u(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:$u(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?zt(g.contact2):null,tilt2:v?zt(g.tilt2):null,position:zt(g.position),positionInverted:!!g.position_inverted,tiltAngle:zt(g.tilt_angle),tiltMax:g.tilt_max??null,tiltOffset:g.tilt_offset??null,tiltInvert:!!g.tilt_invert,shut:!!g.shut,angled:g.type==="door"&&!!g.open_angle,lock:g.type==="door"?zt(g.lock):null,cover2:g.type==="garage"?null:zt(g.cover2),coverTilt:zt(g.cover_tilt),cover2Tilt:zt(g.cover2_tilt),coverInverted:!!g.cover_inverted,coverTiltInverted:!!g.cover_tilt_inverted,cover2Inverted:!!g.cover2_inverted,cover2TiltInverted:!!g.cover2_tilt_inverted})}}return n}var $b=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Cs(t){if(!t||et(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&$b.find(([i])=>i.test(r));if(o)return o[1]}return null}var Su=new WeakMap,Mu=new WeakMap;function Ru(t,e){let n=Mu.get(t)??t,r=Su.get(n)??new WeakMap;Su.set(n,r);let o=r.get(e);if(o)return o;let i=new Map;for(let a of e)for(let c of a.placements)c.entity_id.startsWith("cover.")&&i.set(c.entity_id,{tilt:c.cover_tilt==="none"?null:c.cover_tilt,position:c.position});for(let a of Pt(n,e).values())a.cover&&!i.has(a.cover)&&i.set(a.cover,{tilt:a.coverTilt,position:a.position}),a.cover2&&!i.has(a.cover2)&&i.set(a.cover2,{tilt:a.cover2Tilt});let s={...n.states};for(let[a,c]of i){let u=n.states[a];if(!u)continue;let d={...u.attributes,nf_cover_control:!0},p=ti(n,c.position);p===null&&(p=typeof u.attributes.current_position=="number"?u.attributes.current_position:null),p!==null&&(d.current_position=p);let h=c.tilt?n.states[c.tilt]:u,f=typeof h?.attributes.current_tilt_position=="number"?h.attributes.current_tilt_position:c.tilt?ti(n,c.tilt):null;f!==null&&(d.current_tilt_position=f,d.supported_features=Number(d.supported_features??0)|128);let g=u.state;typeof d.current_position=="number"&&g!=="unavailable"&&g!=="unknown"&&g!=="opening"&&g!=="closing"&&(g=d.current_position>0?"open":"closed"),s[a]={...u,state:g,attributes:d}}let l={...n,states:s,callService:async(a,c,u={})=>{if(a!=="cover")return n.callService(a,c,u);let d=Array.isArray(u.entity_id)?u.entity_id:[u.entity_id],p=async h=>{let f=typeof h=="string"?i.get(h):void 0;if(!f)return n.callService(a,c,{...u,entity_id:h});let g={...u,entity_id:h},y=c;(y==="toggle"||y==="toggle_cover")&&(y=s[String(h)]?.state==="closed"?"open_cover":"close_cover");let b=y.includes("tilt");b&&f.tilt&&(g.entity_id=f.tilt);let v=f.tilt?n.states[f.tilt]:void 0;return b&&f.tilt&&!v?.attributes.symcon_id&&typeof v?.attributes.current_tilt_position!="number"&&(y==="set_cover_tilt_position"?(y="set_cover_position",g.position=g.tilt_position,delete g.tilt_position):y==="open_cover_tilt"?y="open_cover":y==="close_cover_tilt"&&(y="close_cover")),n.callService(a,y,g)};return Array.isArray(u.entity_id)?Promise.all(d.map(p)):p(d[0])}};return Mu.set(l,n),r.set(e,l),l}var ue=t=>t?.symconObjects!==void 0;function It(t,e,n=[0,1,2,3]){let r=t?.states[e]?.attributes;return!!r?.symcon_id&&!r.symcon_source_entity&&n.includes(Number(r.symcon_variable_type))}function zn(t){return!t||t.state==="unknown"||t.state==="unavailable"?null:t.attributes.symcon_value??t.attributes.symcon_numeric_value??t.state}function en(t){let e=zn(t);if(e===null||typeof e=="boolean"||e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}function xr(t){let e=zn(t);if(e===null)return null;if(typeof e=="boolean")return e;if(typeof e=="number")return e>0;let n=String(e).trim().toLowerCase();if(["on","true","1","home","open","an","ein","ja","regen","rain","wet","nass"].includes(n))return!0;if(["off","false","0","not_home","closed","aus","nein","trocken","dry"].includes(n))return!1;let r=Number(n);return n!==""&&Number.isFinite(r)?r>0:null}function Eu(t){return zn(t)===null?"\u2013":String(t?.attributes.symcon_formatted??zn(t))}function Au(t,e){switch(e){case"m/s":return t*3.6;case"mph":return t*1.609;case"kn":return t*1.852;case"ft/s":return t*1.097;default:return t}}var Fu="weather.nextfloor_symcon",zu={condition:"Wetterzustand",temperature:"Au\xDFentemperatur",humidity:"Au\xDFenluftfeuchte",pressure:"Luftdruck",wind_speed:"Windgeschwindigkeit",wind_gust_speed:"Windb\xF6en",wind_bearing:"Windrichtung",cloud_coverage:"Bew\xF6lkung",precipitation:"Niederschlagsrate",precipitation_total:"Niederschlagsmenge",illuminance:"Au\xDFenhelligkeit",uv_index:"UV-Index",visibility:"Sichtweite",snow:"Schnee",fog:"Nebel",lightning:"Gewitter"},Tu=new WeakMap;function Sb(t){let e=t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim();return["sunny","clear-night","partlycloudy","cloudy","fog","rainy","pouring","lightning-rainy","lightning","hail","snowy","snowy-rainy","windy","windy-variant"].includes(e)?e:/kein regen|trocken|wolkenlos|klar|sonnig/.test(e)?"sunny":/gewitter|blitz/.test(e)?"lightning-rainy":/schneeregen/.test(e)?"snowy-rainy":/schnee/.test(e)?"snowy":/hagel/.test(e)?"hail":/starkregen/.test(e)?"pouring":/regen|niesel/.test(e)?"rainy":/nebel/.test(e)?"fog":/teil.*wolk|heiter|leicht.*wolk/.test(e)?"partlycloudy":/wolk|bedeckt/.test(e)?"cloudy":/wind|sturm/.test(e)?"windy":null}function Pu(t,e){if(!ue(t))return t;let n=e.weather_variables??{};if(!e.rain_sensor&&!Object.values(n).some(h=>h&&h!=="none"))return t;let r=Tu.get(t)??new WeakMap;Tu.set(t,r);let o=r.get(e);if(o)return o;let i={friendly_name:"Wetter",nf_symcon_weather:!0},s=h=>n[h]&&n[h]!=="none"?t.states[n[h]]:void 0;for(let h of["temperature","humidity","pressure","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility"]){let f=s(h),g=en(f);g!==null&&(i[h]=h==="cloud_coverage"&&f?.attributes.symcon_max===1?g*100:g),f?.attributes.unit_of_measurement&&(i[`${h}_unit`]=f.attributes.unit_of_measurement)}for(let h of["wind_speed","wind_gust_speed"]){let f=s(h),g=en(f);g!==null&&(i[h]=Au(g,f?.attributes.unit_of_measurement))}i.wind_speed_unit="km/h";let l=zn(s("wind_bearing"));l!==null&&(i.wind_bearing=l);let a=Sb(Eu(s("condition"))),c=e.rain_sensor?t.states[e.rain_sensor]:void 0,u=xr(c);u!==null&&e.rain_sensor_inverted&&(u=!u),u===null&&typeof i.precipitation=="number"&&(u=i.precipitation>0),xr(s("lightning"))?a=u?"lightning-rainy":"lightning":xr(s("snow"))?a=u?"snowy-rainy":"snowy":xr(s("fog"))?a="fog":u===!0?a=Number(i.precipitation??0)>=8?"pouring":"rainy":u===!1&&a&&/rain|pouring/.test(a)&&(a=null),!a&&typeof i.cloud_coverage=="number"&&(a=i.cloud_coverage>70?"cloudy":i.cloud_coverage>20?"partlycloudy":"sunny"),!a&&u===!1&&(a="sunny");let d={entity_id:Fu,state:a??"unknown",attributes:i},p={...t,states:{...t.states,[Fu]:d}};return r.set(e,p),p}var Pn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},tn=t=>(...e)=>({_$litDirective$:t,values:e}),Dt=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var $r=class extends Dt{constructor(e){if(super(e),this.it=_,e.type!==Pn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Je)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};$r.directiveName="unsafeHTML",$r.resultType=1;var Iu=tn($r);var Du=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,Ou=/(kühl|fridge|gefrier|freezer)/i,Hu=/(spülmaschine|geschirrspül|dishwasher)/i,Mb=/(kochfeld|herd|induktion|cooktop)/i,Rb={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:Du,tv_wall:Du,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:Ou,fridge_smart:Ou,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:Hu,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:Mb,sink:Hu,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},Lu={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},Cu=new Set(["tv_board","tv_wall"]);var In=t=>Cu.has(t)||!!Ec(t),ni=t=>!!U(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),Mr=t=>In(t)||t==="desk"||t==="fridge_smart",Eb=t=>!!t&&t!=="none";function Ab(t,e){if(Xo(t,e))return e;let n=t.entities?.[e]?.device_id;return n?Qo(t,n).find(r=>r!==e)??null:null}var Fb=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Sr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function We(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(Eb));for(let i of r.furniture){let s=i.type in Lu,l=$n(i.type),a=s?Lu[i.type]:Rb[i.type];if(!a&&!l&&!ni(i.type)&&i.entity==null&&i.power==null)continue;let c=Fb(r,i.x,i.z),u=(c?Jo(t,ye(t,c)):[]).filter(y=>!o.has(y)),d=y=>`${y} ${W(t,y)}`,p=y=>u.filter(b=>Q(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?ye(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>Q(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>Q(v)==="light"&&b.has(t.entities?.[v]?.device_id))??Sr(p("light"),a,d,!1)}else if(s)h=Sr(p("light"),a,d,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=Sr(p("climate"),a,d,!0);else if(In(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??Sr(y,a,d,Cu.has(i.type))}else if(ni(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=Sr(y,a,d,!1)??(y.length===1?y[0]:null)}else a&&(h=u.find(y=>["switch","media","fan"].includes(Q(y)??"")&&a.test(d(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?Ab(t,h):null,!f&&a&&c&&!s&&(f=ye(t,c).find(y=>Xo(t,y)&&!o.has(y)&&a.test(d(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?ye(t,c):[]).filter(v=>Q(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var Nu=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function Bu(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=We(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Jo(t,Yo(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function Tb(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function Vu(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],u=Math.min(l-s,c-a),d=Math.max(.1,Math.min(.25,u/8)),p=Math.min(.35,u/5),h=Math.min(.7,u/4),f=be(r),g=[];for(let b=s+d/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=Q(b)==="light",w=g[0].at,x=-1/0;for(let{at:S,wallDistance:E}of g){let T=y.length?Math.min(...y.map(P=>Math.hypot(S[0]-P[0],S[1]-P[1]))):3,F=Math.hypot(S[0]-f[0],S[1]-f[1]),O=Math.min(T,3)*2;Fx+1e-9&&(x=O,w=S)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var Wu=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function Ku(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(Wu.test(i.translation_key??"")||Wu.test(i.entity_id.split(".")[1])))?.entity_id??null}var ve=ne`
+var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var So=globalThis,Mo=So.ShadowRoot&&(So.ShadyCSS===void 0||So.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,ss=Symbol(),oc=new WeakMap,mr=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==ss)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=n}get styleSheet(){let e=this.o,n=this.t;if(Mo&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=oc.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&oc.set(n,e))}return e}toString(){return this.cssText}},ic=t=>new mr(typeof t=="string"?t:t+"",void 0,ss),J=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,o,i)=>r+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(o)+t[i+1],t[0]);return new mr(n,t,ss)},sc=(t,e)=>{if(Mo)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),o=So.litNonce;o!==void 0&&r.setAttribute("nonce",o),r.textContent=n.cssText,t.appendChild(r)}},as=Mo?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return ic(n)})(t):t;var{is:W_,defineProperty:V_,getOwnPropertyDescriptor:K_,getOwnPropertyNames:j_,getOwnPropertySymbols:G_,getPrototypeOf:U_}=Object,Ro=globalThis,ac=Ro.trustedTypes,Z_=ac?ac.emptyScript:"",q_=Ro.reactiveElementPolyfillSupport,gr=(t,e)=>t,ls={toAttribute(t,e){switch(e){case Boolean:t=t?Z_:null;break;case Object:case Array:t=t==null?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=t!==null;break;case Number:n=t===null?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch{n=null}}return n}},cc=(t,e)=>!W_(t,e),lc={attribute:!0,type:String,converter:ls,reflect:!1,useDefault:!1,hasChanged:cc};Symbol.metadata??=Symbol("metadata"),Ro.litPropertyMetadata??=new WeakMap;var _t=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,n=lc){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(e,n),!n.noAccessor){let r=Symbol(),o=this.getPropertyDescriptor(e,r,n);o!==void 0&&V_(this.prototype,e,o)}}static getPropertyDescriptor(e,n,r){let{get:o,set:i}=K_(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:o,set(s){let l=o?.call(this);i?.call(this,s),this.requestUpdate(e,l,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??lc}static _$Ei(){if(this.hasOwnProperty(gr("elementProperties")))return;let e=U_(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(gr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(gr("properties"))){let n=this.properties,r=[...j_(n),...G_(n)];for(let o of r)this.createProperty(o,n[o])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,o]of n)this.elementProperties.set(r,o)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let o=this._$Eu(n,r);o!==void 0&&this._$Eh.set(o,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let n=[];if(Array.isArray(e)){let r=new Set(e.flat(1/0).reverse());for(let o of r)n.unshift(as(o))}else e!==void 0&&n.push(as(e));return n}static _$Eu(e,n){let r=n.attribute;return r===!1?void 0:typeof r=="string"?r:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,n=this.constructor.elementProperties;for(let r of n.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return sc(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,n,r){this._$AK(e,r)}_$ET(e,n){let r=this.constructor.elementProperties.get(e),o=this.constructor._$Eu(e,r);if(o!==void 0&&r.reflect===!0){let i=(r.converter?.toAttribute!==void 0?r.converter:ls).toAttribute(n,r.type);this._$Em=e,i==null?this.removeAttribute(o):this.setAttribute(o,i),this._$Em=null}}_$AK(e,n){let r=this.constructor,o=r._$Eh.get(e);if(o!==void 0&&this._$Em!==o){let i=r.getPropertyOptions(o),s=typeof i.converter=="function"?{fromAttribute:i.converter}:i.converter?.fromAttribute!==void 0?i.converter:ls;this._$Em=o;let l=s.fromAttribute(n,i.type);this[o]=l??this._$Ej?.get(o)??l,this._$Em=null}}requestUpdate(e,n,r,o=!1,i){if(e!==void 0){let s=this.constructor;if(o===!1&&(i=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??cc)(i,n)||r.useDefault&&r.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,n,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,n,{useDefault:r,reflect:o,wrapped:i},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),i!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),o===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[o,i]of this._$Ep)this[o]=i;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[o,i]of r){let{wrapped:s}=i,l=this[o];s!==!0||this._$AL.has(o)||l===void 0||this.C(o,void 0,i,l)}}let e=!1,n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(n)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(n)}willUpdate(e){}_$AE(e){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(e){}firstUpdated(e){}};_t.elementStyles=[],_t.shadowRootOptions={mode:"open"},_t[gr("elementProperties")]=new Map,_t[gr("finalized")]=new Map,q_?.({ReactiveElement:_t}),(Ro.reactiveElementVersions??=[]).push("2.1.2");var us=globalThis,uc=t=>t,Eo=us.trustedTypes,dc=Eo?Eo.createPolicy("lit-html",{createHTML:t=>t}):void 0,ds="$lit$",bt=`lit$${Math.random().toFixed(9).slice(2)}$`,hs="?"+bt,Y_=`<${hs}>`,Yt=document,br=()=>Yt.createComment(""),yr=t=>t===null||typeof t!="object"&&typeof t!="function",ps=Array.isArray,_c=t=>ps(t)||typeof t?.[Symbol.iterator]=="function",cs=`[
+\f\r]`,_r=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,hc=/-->/g,pc=/>/g,Zt=RegExp(`>|${cs}(?:([^\\s"'>=/]+)(${cs}*=${cs}*(?:[^
+\f\r"'\`<>=]|("|')|))|$)`,"g"),fc=/'/g,mc=/"/g,bc=/^(?:script|style|textarea|title)$/i,fs=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=fs(1),R=fs(2),Ex=fs(3),Je=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),gc=new WeakMap,qt=Yt.createTreeWalker(Yt,129);function yc(t,e){if(!ps(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return dc!==void 0?dc.createHTML(e):e}var vc=(t,e)=>{let n=t.length-1,r=[],o,i=e===2?"":e===3?"":"",s=_r;for(let l=0;l"?(s=o??_r,d=-1):u[1]===void 0?d=-2:(d=s.lastIndex-u[2].length,c=u[1],s=u[3]===void 0?Zt:u[3]==='"'?mc:fc):s===mc||s===fc?s=Zt:s===hc||s===pc?s=_r:(s=Zt,o=void 0);let h=s===Zt&&t[l+1].startsWith("/>")?" ":"";i+=s===_r?a+Y_:d>=0?(r.push(c),a.slice(0,d)+ds+a.slice(d)+bt+h):a+bt+(d===-2?l:h)}return[yc(t,i+(t[n]||">")+(e===2?" ":e===3?"":"")),r]},vr=class t{constructor({strings:e,_$litType$:n},r){let o;this.parts=[];let i=0,s=0,l=e.length-1,a=this.parts,[c,u]=vc(e,n);if(this.el=t.createElement(c,r),qt.currentNode=this.el.content,n===2||n===3){let d=this.el.content.firstChild;d.replaceWith(...d.childNodes)}for(;(o=qt.nextNode())!==null&&a.length0){o.textContent=Eo?Eo.emptyScript:"";for(let h=0;h2||r[0]!==""||r[1]!==""?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=_}_$AI(e,n=this,r,o){let i=this.strings,s=!1;if(i===void 0)e=Xt(this,e,n,0),s=!yr(e)||e!==this._$AH&&e!==Je,s&&(this._$AH=e);else{let l=e,a,c;for(e=i[0],a=0;a{let r=n?.renderBefore??e,o=r._$litPart$;if(o===void 0){let i=n?.renderBefore??null;r._$litPart$=o=new xn(e.insertBefore(br(),i),i,void 0,n??{})}return o._$AI(t),o};var ms=globalThis,Y=class extends _t{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=kc(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return Je}};Y._$litElement$=!0,Y.finalized=!0,ms.litElementHydrateSupport?.({LitElement:Y});var Q_=ms.litElementPolyfillSupport;Q_?.({LitElement:Y});(ms.litElementVersions??=[]).push("4.2.2");var _s=t=>t.slice(0,t.indexOf(".")),J_={light:"light",switch:"switch",input_boolean:"switch",valve:"switch",fan:"fan",cover:"cover",climate:"climate",media_player:"media",lock:"lock",sensor:"sensor",binary_sensor:"binary",event:"sensor",scene:"scene",script:"script"},Q=t=>J_[_s(t)]??null,bs=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var xc=new Set(["light","switch","fan"]),Rt=t=>t!==null&&t!=="scene"&&t!=="script",et=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function W(t,e,n){let r=String(t?.states[e]?.attributes.friendly_name??t?.entities?.[e]?.name??e);if(!n||r.length<=n.length+1||!r.toLowerCase().startsWith(`${n.toLowerCase()} `))return r;let o=r.slice(n.length+1);return o[0].toUpperCase()+o.slice(1)}var $c=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var Sc=t=>Math.min(1,Math.max(0,t));function eb(t){let e=Sc((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(o=>n[o]+(r[o]-n[o])*e)}function gs(t,e){if(!t||t.state!=="on")return null;let n=e&&!["unavailable","unknown"].includes(e.state)?e.attributes:t.attributes,r=typeof n.brightness=="number"?.2+.8*Math.sqrt(Sc(n.brightness/255)):1,o=n.rgb_color;return o&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[o[0]/255,o[1]/255,o[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:eb(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function Mc(t,e,n){let r=gs(t,n);if(r)return r;for(let o of e){let i=gs(o);if(i)return{color:i.color,level:i.level*.6}}return null}function Io(t,e,n=null){if(t==="light"&&n==="floor")return 1.95;if(t==="light"&&n==="table")return 1.25;if(t==="light"&&n==="wall")return 1.95;switch(t){case"light":return Math.max(.5,e-.25);case"cover":return Math.min(2,e-.3);case"climate":return .6;case"media":return .9;case"binary":case"sensor":return 1.4;default:return 1.05}}var Fc=[],Do=new Map,tb=0,he=(t,e)=>`pack:${t}:${e}`,yt=t=>t.startsWith("pack:");function ys(t){Fc=t,Do=new Map;for(let e of t)for(let n of e.items)Do.set(he(e.id,n.id),n);tb+=1}var kr=()=>Fc;var nb={};function U(t){if(!yt(t))return;let e=Do.get(t);if(e)return e;let[,n,...r]=t.split(":"),o=nb[n];return o?Do.get(he(o,r.join(":"))):void 0}var rb=.22;function Rc(t,e,n,r){let o=Math.min(rb,n/3);if(r<=o*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let i=e*(r/n),s=t-e;return s<=o?i+s:s>=n-o?i+r-(n-s):i+o+(s-o)*(r-2*o)/(n-2*o)}function wr(t,e,n,r,o){return[Rc(t*r,n*r,r,o)/o,Rc(e*r,n*r,r,o)/o]}var Ec=new WeakMap;function Tc(t,e,n,r){let[o,i,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-o)<1e-4&&Math.abs(n-i)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let l=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,a=Ec.get(t),c=a?.get(l);if(c)return c;let u=t.parts.map(d=>{if(d.shape==="sweep")return d;let[p,h]=wr(d.x-d.w/2,d.x+d.w/2,-.5,o,e),[f,g]=wr(d.z-d.d/2,d.z+d.d/2,-.5,i,n),[y,b]=wr(d.y,d.y+d.h,0,s,r);if(d.rot)return{...d,x:(p+h)/2,z:(f+g)/2,w:d.w*o/e,d:d.d*i/n,y,h:b-y};let v={...d,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y,h:b-y};if(d.shape==="loft"){let[w,x,k,S]=[d.tx??d.x,d.tz??d.z,d.tw??d.w,d.td??d.d],[E,T]=wr(w-k/2,w+k/2,-.5,o,e),[F,O]=wr(x-S/2,x+S/2,-.5,i,n);Object.assign(v,{tx:(E+T)/2,tz:(F+O)/2,tw:T-E,td:O-F})}return v});return a||Ec.set(t,a=new Map),a.size>32&&a.clear(),a.set(l,u),u}var vs=t=>!!t?.parts.some(e=>e.move);var zc=t=>U(t)?.parts.find(e=>e.screen),Ac=.06;function Pc(t){let e=U(t);if(!e)return!1;let[n,r,o]=e.size;return e.parts.filter(i=>i.screen).some(i=>{let[s,l]=[i.w*n,i.d*r,i.h*o].sort((a,c)=>c-a);return l>=Ac&&s>=Ac})}function ut(t){return tt[t]??U(t)?.size??[.6,.6,.8]}function Et(t){let e=U(t);return Bc.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var Ic=t=>!!U(t)?.parts.some(e=>e.picture),$n=t=>!!U(t)?.climate;function Dc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var ob={wohnen:"Living & Pets",kino:"Home Cinema & Gaming",kueche:"Kitchen Extras",bad:"Bathroom Extras",schlafen:"Bedroom & Kids",technik:"Office & Homelab",energie:"Energy & Building Services",garten:"Garden & Terrace (older)",fitness:"Fitness (older)",fahrzeuge:"Vehicles",ikea:"IKEA sizes",treppen:"Stairs & railings",ausbau:"Architecture & fit-out",werkstatt:"Garage & workshop",a_wohnzimmer:"Living room",a_schlafzimmer:"Bedroom",a_kueche:"Kitchen",a_bad:"Bathroom",a_kinderzimmer:"Kids' room",a_buero:"Office & gaming",a_fitness:"Fitness",a_haustiere:"Pets",a_garten:"Garden & patio",a_kino:"Home cinema & hi-fi",a_smart:"Smart home & tech",a_haustechnik:"Utility & building services",a_saison:"Season & decoration",a_smart2:"Smart home 2",a_haustechnik2:"Building services 2",a_wellness:"Wellness",a_garten2:"Garden 2",a_kueche2:"Kitchen 2",a_fahrzeuge2:"Vehicles 2",a_aussenkueche:"Outdoor kitchen & terrace",a_werkstatt2:"Workshop 2",a_japandi:"Japandi & Scandi",a_loft:"Loft & industrial",a_gruen:"Indoor greenery",a_musik:"Music & studio",a_bilder:"Pictures & frames"};function Oc(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&ob[n]||t.name}function At(t,e){return e.mount_y!=null?e.mount_y:sb(t,e)+(ib(e)?0:Cc(t,e.x,e.z))}var ib=t=>t.type==="led_strip"||U(t.type)?.mount==="ceiling";function sb(t,e){if(e.type==="lamp_wall")return Hc;if(e.type==="led_strip")return Math.max(0,dt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=U(e.type);if(!n)return Lc(e);switch(n.mount){case"surface":return Nc(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Oo(t,e)-e.h);default:return 0}}function ws(t){if(t==="plant")return"plant";let e=U(t);return e?e.household?e.household:/monstera|plant|herb_garden|flower_pots|bonsai|ficus|cactus|kaktus/.test(e.id)?"plant":null:null}var Sn=["electricity","water","gas","heating","cooling"],Wc=["condition","temperature","humidity","pressure","wind_speed","wind_gust_speed","wind_bearing","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility","snow","fog","lightning"],Vc=["turn","slide","top"],Kc=["always","active","no_power","never"],jc=1.3,Ho=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Gc=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Uc=["brick","round","wide","steel"],Lo=["navigate","more_info","service","fire_dom_event"];function Co(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Zc=["rain","snow","fog","clouds","lightning","sky"],qc=["rain","snow","clouds","lightning","sky"],Yc=["lawn","terrace","path","driveway","pool","bed","wild","hedge","fence","pergola"],ks={lawn:.012,terrace:.12,path:.02,driveway:.02,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function xs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Xc=["x","-x","z","-z"];function ab(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let o=t.slope_dir??"x",i=(c,u)=>o==="x"?c:o==="-x"?-c:o==="z"?u:-u,s=1/0,l=-1/0;for(let[c,u]of t.points){let d=i(c,u);s=Math.min(s,d),l=Math.max(l,d)}if(l-s<1e-6)return 0;let a=Math.min(1,Math.max(0,(i(e,n)-s)/(l-s)));return r*a}function lb(t,e,n,r){return Qc(t)+(e.offset??0)+ks[e.type]-ab(e,n,r)}function Qc(t){return t.elevation>.3?0:-.2}function Jc(t,e,n){let r=(t.outdoor??[]).filter(i=>!xs(i.type)&&i.type!=="pool"&&N([e,n],i.points)),o=[...r].reverse().find(i=>i.cut)??r[0];return o?lb(t,o,e,n):Qc(t)}var eu=t=>t.cut??t.type==="pool",tu=30,nu={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},ru=["wood","oak","tiles","carpet","stone","concrete"],ou={type:"none",pitch:35,overhang:.4},No="#d6cfc2",Bo="#e8e3da",iu={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...ou}};function Ft(){return{version:1,floors:[],settings:{...iu},energy:{...nu},presence:[]}}function Ce(t,e,n){return{id:t,name:e,elevation:n,height:2.5,cut_height:1.15,rooms:[],openings:[],furniture:[],placements:[],background:null,outdoor:[],walls:[],ha_floor:null}}var cb=2.75;function su(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*cb*100)/100;let n=t.reduce((r,o)=>!r||o.elevation>r.elevation?o:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function au(t,e,n){let r=t.rooms.flatMap(l=>l.points.map(a=>a[0])),o=t.rooms.flatMap(l=>l.points.map(a=>a[1])),i=r.length?Math.ceil(Math.max(...r))+1:0,s=o.length?Math.floor(Math.min(...o)):0;return e.map((l,a)=>{let c=i+a%3*4.5,u=s+Math.floor(a/3)*3.5;return{id:n(),name:l.name,area_id:l.area_id,points:[[c,u],[c+4,u],[c+4,u+3],[c,u+3]],floor_material:"wood"}})}function lu(t,e,n,r){let o=t.rotation*Math.PI/180,i=Math.cos(o),s=Math.sin(o),[l,a]=e,c=t.x-l*(t.w/2)*i+a*(t.d/2)*s,u=t.z-l*(t.w/2)*s-a*(t.d/2)*i,d=n[0]-c,p=n[1]-u,h=b=>Math.max(.1,Math.round(b/r)*r),f=h((d*i+p*s)*l),g=h((-d*s+p*i)*a),y=b=>Math.round(b*1e3)/1e3;return{x:y(c+l*(f/2)*i-a*(g/2)*s),z:y(u+l*(f/2)*s+a*(g/2)*i),w:y(f),d:y(g)}}var Wo=["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_table","lamp_wall","led_strip","lamp_uplight","lamp_bollard","lamp_garden","radiator","sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug","table","table_round","chair","bench","corner_bench","bar_stool","kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge","bed","bunk_bed","nightstand","wardrobe","dresser","bathtub","shower","wc","washbasin","washer","dryer","desk","office_chair","tall_cabinet","coat_rack","stairs","robot_vacuum","inverter","home_battery","wallbox","meter","grid_point","parking","fridge_smart","stairwell"],cu={lights:["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"],living:["sofa","armchair","stool","coffee_table","tv_board","tv_wall","sideboard","shelf","plant","rug"],dining:["table","table_round","chair","bench","corner_bench","bar_stool"],kitchen:["kitchen","kitchen_wall","kitchen_tall","island","worktop","sink","stove","dishwasher","fridge"],sleeping:["bed","bunk_bed","nightstand","wardrobe","dresser"],bath:["bathtub","shower","wc","washbasin","washer","dryer"],work:["desk","worktop","office_chair","tall_cabinet","coat_rack","radiator","stairs","robot_vacuum"],vehicles:["parking"]},Ne=["meter","inverter","home_battery","wallbox","grid_point"],uu=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan","lamp_floor","lamp_uplight","lamp_table","lamp_wall","led_strip","lamp_bollard","lamp_garden"]),Hc=1.75;function Vo(t){return $s.has(t.type)||["stairwell","parking"].includes(t.type)?!1:U(t.type)?.mount!=="ceiling"}function ue(t){return uu.has(t)||!!U(t)?.light}var ub=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function du(t,e,n,r=0){let o=de(t.points),i=o.x1-o.x0-2*r,s=o.z1-o.z0-2*r,l=[];for(let a=0;aMath.round(s*1e3)/1e3,[o,i]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+o*e),r(t[1]+i*e)]}function Lc(t){switch(t.type){case"home_battery":return t.variant==="wall"?.5:0;case"kitchen_wall":return 1.45;case"tv_wall":return Math.max(0,1.3-t.h/2);case"radiator":return .12;case"inverter":return 1.1;case"wallbox":return 1;case"meter":return .4;default:return 0}}var $s=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function hu(t,e){return t.filter(n=>n.elevationn.rooms.filter(r=>r.points.length>=3&&r.ceiling!=null&&r.ceiling>n.height+.005&&n.elevation+r.ceiling>e.elevation+.05)).map(n=>n.points)}var Ss=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function Cc(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&o.floor_offset&&N([e,n],o.points));return Ss(r)}function dt(t,e,n){let r=t.rooms.find(o=>o.points.length>=3&&N([e,n],o.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Oo=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:dt(t,e.x,e.z);function Nc(t,e,n){let r=0;for(let o of t.furniture)!(ub.has(o.type)||U(o.type)?.surface)||!N([e,n],As(o))||(r=Math.max(r,o.h));return r}var Bc=new Set([...uu,"radiator","robot_vacuum","inverter","home_battery","wallbox","meter","tv_board","tv_wall","desk","fridge","fridge_smart","stove","kitchen_tall","dishwasher","washer","dryer","kitchen","island","sink"]),tt={sofa:[2.2,.9,.82],armchair:[.85,.85,.8],table:[1.6,.9,.75],chair:[.46,.5,.9],bed:[1.6,2.05,.9],nightstand:[.45,.4,.5],wardrobe:[1.8,.6,2.1],shelf:[.9,.35,1.9],kitchen:[2.4,.62,.92],worktop:[1.2,.62,.91],inverter:[.5,.2,.65],home_battery:[.6,.25,1.1],wallbox:[.3,.15,.42],meter:[.55,.21,1.1],grid_point:[.4,.22,.6],fridge:[.6,.65,1.8],fridge_smart:[.91,.73,1.78],stairwell:[1,2.6,.02],stove:[.6,.62,.92],sink:[.9,.62,.92],bathtub:[1.7,.75,.58],shower:[.9,.9,2],wc:[.38,.6,.8],washbasin:[.6,.46,.85],desk:[1.4,.7,.75],tv_board:[1.8,.42,.5],plant:[.45,.45,1.1],rug:[2,1.4,.01],stairs:[1,3.2,2.75],stool:[.55,.55,.42],lamp_ceiling:[.4,.4,.08],lamp_downlight:[.1,.1,.02],lamp_spot:[.1,.1,.14],lamp_panel:[.6,.6,.03],lamp_uplight:[.35,.35,1.8],lamp_bollard:[.16,.16,.8],lamp_garden:[.12,.12,.3],radiator:[1,.1,.6],robot_vacuum:[.36,.5,.1],parking:[2.6,5.2,.02],lamp_pendant:[.4,.4,.8],ceiling_fan:[1.32,1.32,.32],lamp_floor:[.4,.4,1.7],lamp_table:[.28,.28,.45],lamp_wall:[.22,.12,.2],led_strip:[2,.04,.03],coffee_table:[1.1,.6,.42],tv_wall:[1.3,.08,.75],sideboard:[1.6,.45,.8],table_round:[1.1,1.1,.75],bench:[1.4,.45,.85],corner_bench:[2,1.6,.9],bar_stool:[.42,.42,.75],kitchen_wall:[.8,.35,.7],kitchen_tall:[.6,.62,2.1],island:[1.8,.9,.92],dishwasher:[.6,.62,.92],bunk_bed:[1,2.05,1.65],dresser:[1,.5,.9],washer:[.6,.6,.85],dryer:[.6,.6,.85],office_chair:[.65,.65,1.1],tall_cabinet:[.6,.6,2.1],coat_rack:[1,.35,1.9]};var Ms=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],Rs=["standard","bars","glass_wall"],Ko=new Set(["interior","front"]);function Jt(t,e){return t.type==="door"?t.style&&Ms.includes(t.style)?t.style:e?"front":"interior":t.style&&Rs.includes(t.style)?t.style:"standard"}function pu(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let o=e==="sidelights",i=t-.04,s=Math.min(1.05,Math.max(.6,i-(o?.6:.3))),l=(i-s)/(o?2:1),a=r.sidelight_width??l,c=o?r.sidelight_width2??r.sidelight_width??l:0;a=Math.max(.1,a),c=o?Math.max(.1,c):0;let u=i-.5;if(a+c>u){let p=Math.max(0,u)/(a+c);a*=p,c*=p}return o?{panels:[[.02,.02+a],[t-.02-c,t-.02]],x0:.02+a,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+a]],x0:.02+a,x1:t-.02}:{panels:[[t-.02-a,t-.02]],x0:.02,x1:t-.02-a}}function Es(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var Rn={door:{type:"door",leaves:1,width:.9,sill:0,height:2.05,style:"interior"},front:{type:"door",leaves:1,width:1,sill:0,height:2.1,style:"front"},door_double:{type:"door",leaves:2,width:1.6,sill:0,height:2.05},window:{type:"window",leaves:1,width:1.2,sill:.9,height:1.3},window_double:{type:"window",leaves:2,width:1.6,sill:.9,height:1.3},terrace:{type:"window",leaves:1,width:1,sill:0,height:2.1},terrace_double:{type:"window",leaves:2,width:1.8,sill:0,height:2.1},lift_slide:{type:"window",leaves:1,width:2.4,sill:0,height:2.15,opens:"slide"},garage:{type:"garage",leaves:1,width:2.5,sill:0,height:2.1},glass_wall:{type:"window",leaves:1,width:2,sill:0,height:2.4,style:"glass_wall"}};function En(t){if(t.type==="garage")return"garage";if(t.type==="window"&&t.style==="glass_wall")return"glass_wall";if(t.type==="window"&&t.opens==="slide"&&t.sill<.1)return"lift_slide";let e=t.leaves===2;return t.type==="door"?!e&&t.style&&Es(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function Pe(t){t.energy={...nu,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...iu,...t.settings,roof:{...ou,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Ce(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let o of Object.keys(r))e[o]===void 0&&(e[o]=r[o])});for(let e of t.floors){e.outdoor=e.outdoor??[],e.walls=e.walls??[],e.rooms=e.rooms.map(r=>({...r,name:r.name??"",area_id:r.area_id??null,floor_material:r.floor_material??"wood",panel:r.panel??[]})),e.ha_floor=e.ha_floor??null,e.placements=e.placements.map(r=>({...r,mount:r.mount??null,rotation:r.rotation??0})),e.furniture=e.furniture.map(r=>({...r,entity:r.entity??null,power:r.power??null}));let n=e.placements.filter(r=>r.entity_id.startsWith("light."));if(n.length){let r={ceiling:"lamp_ceiling",floor:"lamp_floor",table:"lamp_table",wall:"lamp_wall"};for(let o of n){let i=r[o.mount??"ceiling"],[s,l,a]=tt[i],c=`lamp_${o.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),u=c,d=1;for(;e.furniture.some(p=>p.id===u);)u=`${c}_${d++}`;e.furniture.push({id:u,type:i,x:o.x,z:o.z,rotation:0,w:s,d:l,h:a,variant:null,entity:o.entity_id,power:null,animations_enabled:o.animations_enabled,effect_animations:structuredClone(o.effect_animations)})}e.placements=e.placements.filter(o=>!o.entity_id.startsWith("light."))}e.openings=e.openings.map(r=>({...r,type:["door","window","garage"].includes(r.type)?r.type:"door",edge:Number.isInteger(r.edge)?r.edge:0,offset:Number.isFinite(r.offset)?r.offset:.5,width:Number.isFinite(r.width)&&r.width>0?r.width:r.type==="garage"?2.5:r.type==="window"?1.2:.9,height:Number.isFinite(r.height)&&r.height>0?r.height:r.type==="window"?1.3:r.type==="garage"?2.1:2.05,sill:Number.isFinite(r.sill)?r.sill:r.type==="window"?.9:0,hinge:r.hinge??"left",leaves:r.leaves??1,swing:r.swing??"in",style:r.style??null,cover:r.cover??null,contact:r.contact??null,contact2:r.contact2??null,tilt:r.tilt??null}))}return db(t),t}function db(t){let e=(n,r)=>{let o=new Set;for(let i of n)(typeof i.id!="string"||!i.id||o.has(i.id))&&(i.id=I(r)),o.add(i.id)};e(t.floors,"floor");for(let n of t.floors){for(let r of n.rooms)(typeof r.id!="string"||!r.id)&&(r.id=I("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function I(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function _e(t){let e=0;for(let n=0;ni+s[0],0)/o,t.reduce((i,s)=>i+s[1],0)/o]}let n=0,r=0;for(let o=0;o1e-6&&Math.abs(r-i)>1e-6)return!1}return!0}function de(t){let e=1/0,n=1/0,r=-1/0,o=-1/0;for(let[i,s]of t)e=Math.min(e,i),n=Math.min(n,s),r=Math.max(r,i),o=Math.max(o,s);return{x0:e,z0:n,x1:r,z1:o}}function As(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),o=t.w/2,i=t.d/2;return[[-o,-i],[o,-i],[o,i],[-o,i]].map(([s,l])=>[t.x+s*n-l*r,t.z+s*r+l*n])}function N(t,e){let n=!1;for(let r=0,o=e.length-1;rt[1]!=a>t[1]&&t[0]<(l-i)*(t[1]-s)/(a-s)+i&&(n=!n)}return n}var jo={lamp_ceiling:"ceiling",lamp_downlight:"downlight",lamp_spot:"spot",lamp_panel:"panel",lamp_uplight:"uplight",lamp_bollard:"bollard",lamp_garden:"garden",lamp_pendant:"pendant",ceiling_fan:"fan",lamp_floor:"floor",lamp_table:"table",lamp_wall:"wall",led_strip:"strip"};var Fs=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),Ts=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var pb=globalThis,mu=pb.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},zs=mu.plugins,fu=mu.listeners;var fb=5;function gu(t,e){t.errors.lengthfu.delete(t)}var Ps=()=>[...zs.values()].map(t=>t.status),_u=()=>[...zs.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*Uo(t,e){for(let{plugin:n,status:r}of zs.values())for(let o of n.devices??[]){let i=!1;try{i=o.match(t,e)}catch(s){gu(r,s)}i&&(yield{device:o,status:r})}}function Zo(t,e){for(let{device:n}of Uo(t,e))return n.kind??"sensor";return null}function bu(t,e){let n=t.states[e];if(!n)return null;let r=mb({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function mb(t){let e=null;for(let{device:n,status:r}of Uo(t.entityId,t.state))if(n.marker)try{let o=n.marker(t);if(!o)continue;e={...e??{}},typeof o.icon=="string"&&o.icon&&(e.icon=o.icon),typeof o.text=="string"&&(e.text=o.text.slice(0,60)),typeof o.active=="boolean"&&(e.active=o.active)}catch(o){gu(r,o)}return e}function qo(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function yu(t,e){let n=[];for(let{device:r,status:o}of Uo(t,e))r.settings?.length&&n.push({pluginId:o.id,name:o.name,settings:r.settings});return n}function vu(t,e){let n={};for(let r of t??[]){let o=e?.[r.key],i=r.type==="number"?typeof o=="number"&&Number.isFinite(o):r.type==="boolean"?typeof o=="boolean":typeof o=="string"&&(r.options??[]).some(([s])=>s===o);n[r.key]=i?o:r.default}return n}function wu(t,e){for(let{device:n}of Uo(t,e))if(n.floorWedge)return!0;return!1}var gb=new Set(["temperature","humidity","power","carbon_dioxide","energy","gas","water","volume","volume_storage","volume_flow_rate","illuminance","pressure","atmospheric_pressure","pm1","pm25","pm10","volatile_organic_compounds","volatile_organic_compounds_parts","carbon_monoxide","nitrogen_dioxide","moisture","sound_pressure"]),_b=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),bb=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),yb=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Tt(t,e){let n=t.entities?.[e];return n&&(n.area_id||(n.device_id?t.devices?.[n.device_id]?.area_id:null))||null}var xu=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Be=(t,e)=>Q(e)??Zo(e,t.states[e]);function ku(t,e){let n=t.states[e];if(!n||xu(t,e))return!1;if(Zo(e,n)!==null)return!0;let r=Q(e);if(!r)return!1;let o=n.attributes.device_class;return e.startsWith("event.")?!o||o==="button"||o==="doorbell":r==="sensor"?o?gb.has(o):_b.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?o?bb.has(o):!!t.entities?.[e]?.area_id:!0}function vb(t,e){let n=t.states[e];return Q(e)!=="sensor"||!n?.attributes.unit_of_measurement||xu(t,e)||yb.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||et(n)}var Xo=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",Is=null;Go(()=>Is=null);function Ds(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function wb(t){let e=new Map,n=new Map,r=new Map,o=new Map,i=[],s=u=>{(ku(t,u)||vb(t,u))&&Rt(Be(t,u))&&i.push(u)};for(let[u,d]of Object.entries(t.entities??{})){let p=d.device_id;p&&d.area_id&&(o.get(p)??o.set(p,new Set).get(p)).add(d.area_id),p&&Xo(t,u)&&Ds(n,p).push(u),p&&!d.hidden&&!d.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(_s(u));let h=Tt(t,u);h===null?s(u):ku(t,u)&&Ds(e,h).push(u)}if(t.entities)for(let u of Object.keys(t.states))t.entities[u]||s(u);let l=bs.indexOf("binary")-.5,a=u=>{let d=Q(u),p=d?bs.indexOf(d):l;return p>l&&Zo(u,t.states[u])!==null?l:p};i.sort((u,d)=>a(u)-a(d)||W(t,u).localeCompare(W(t,d)));for(let[u,d]of e){let p=t.areas?.[u]?.name;d.sort((h,f)=>a(h)-a(f)||W(t,h,p).localeCompare(W(t,f,p)))}let c=new Set;for(let[u,d]of o)d.size>1&&c.add(u);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:i,domainsByDevice:r,hubs:c}}function Fn(t){let e=Is;return e&&e.entities===t.entities&&e.devices===t.devices&&(e.states===t.states||(e.states=t.states,Object.keys(t.states).length===e.stateCount))?e:Is=wb(t)}function ye(t,e){let n=Yo(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>Yo(t,r))])]:n}function Yo(t,e){return!e||!t.entities?[]:Fn(t).byArea.get(e)??[]}function $u(t,e){if(!t.entities)return[];let n=[];for(let[r,o]of Fn(t).byArea){let i=o.filter(s=>Rt(Be(t,s)));r!==e&&i.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:i})}return n.sort((r,o)=>r.name.localeCompare(o.name))}var Su=t=>t.entities?Fn(t).withoutArea:[],Os=(t,e)=>!!t.entities&&Fn(t).hubs.has(e),Qo=(t,e)=>t.entities?Fn(t).powerByDevice.get(e)??[]:[];function Tn(t,e){let n=new Map;for(let o of e)Ds(n,t.entities?.[o]?.device_id??`entity:${o}`).push(o);let r=new Map(e.map((o,i)=>[o,i]));return[...n.values()].map(o=>{let i=o.find(s=>!t.entities?.[s]?.name)??o[0];return{primary:i,others:o.filter(s=>s!==i)}}).sort((o,i)=>r.get(o.primary)-r.get(i.primary))}var Jo=(t,e)=>Tn(t,e).map(n=>n.primary),kb={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide",illuminance:"illuminance"};function Hs(t,e,n,r=!1){let o=t.states[e]?.attributes;if(!o)return!1;let i=(o.symcon_variable_type===1||o.symcon_variable_type===2)&&typeof o.symcon_id=="number";if(typeof o.symcon_id=="number"&&!i||!i&&!/^(sensor|input_number|number)\./.test(e))return!1;if(r&&i)return!0;let s=String(o.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(s)||n==="humidity"&&!o.device_class&&["%","%rh","%r.h.","%rf","%r.f."].includes(s)||n==="co2"&&s==="ppm"&&/co[₂2]/i.test(String(o.friendly_name??""))||n==="illuminance"&&["lx","lux"].includes(s)?!0:o.device_class===kb[n]}var xb=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),$b=["vorlauf","r(\xFC|ue)cklauf","flow","return","d(\xFC|ue)se","nozzle","hotend","extruder","druckbett","heatbed","(^|[^a-z])bed($|[^a-z])","chamber","cpu","gpu","chip","soc","akku","batter","wasser","water","kessel","boiler","au(\xDF|ss)en","outdoor","outside","abgas","exhaust","sole","brine","verdampfer","kondensat","verdichter","compressor","motor","k(\xFC|ue)hl","freezer","fridge","gefrier"],Sb=new RegExp(`(${$b.join("|")})`,"i");function Ls(t,e){let n=t.entities?.[e]?.device_id,r=n&&!Os(t,n)?Fn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(o=>xb.has(o))?!1:!Sb.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function Mu(t,e,n,r){let o=n.climate?.[r];if(o==="none")return[];if(o)return[o].flat().filter(c=>t.states[c]);let i=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=i.filter(c=>N([c.x,c.z],n.points)).map(c=>c.entity_id),l=new Set(i.filter(c=>!N([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...ye(t,n).filter(c=>!l.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&Hs(t,c,r)&&Ls(t,c))}function Ru(t){let e=t.attributes;if(typeof e.symcon_numeric_value!="number")return null;let n=typeof e.symcon_min=="number"?e.symcon_min:0,r=typeof e.symcon_max=="number"&&e.symcon_max>n?e.symcon_max:100;return Math.max(0,Math.min(100,(e.symcon_numeric_value-n)/(r-n)*100))}function ei(t,e){let n=t?.states[e];if(!n)return!1;let r=n.attributes;return typeof r.symcon_id=="number"?r.symcon_variable_type===1||r.symcon_variable_type===2:typeof r.current_position=="number"||/^(sensor|number|input_number)\./.test(e)&&!!n.state.trim()&&Number.isFinite(Number(n.state))}function ti(t,e){let n=e?t.states[e]:void 0;if(!n||et(n))return null;let r=n.attributes;if(r.nf_cover_control&&typeof r.current_position=="number")return r.current_position;let o=Ru(n);if(o!==null)return o;if(typeof r.current_position=="number")return Math.max(0,Math.min(100,r.current_position));if(!n.state.trim())return null;let i=Number(n.state);if(!Number.isFinite(i))return null;let s=r.unit_of_measurement==="%"||i>1||i<0?i:i*100;return Math.max(0,Math.min(100,s))}var Mb=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),Rb=new Set(["garage","gate"]),Eb=new Set(["window","opening"]);function xr(t,e,n=!1){let r=new Map;return t.forEach((o,i)=>{let s=n&&e.length===1?e[0]:e[i];s&&r.set(o.id,s)}),r}var Eu=(t,e)=>t==="none"?null:t??e??null,zt=t=>t&&t!=="none"?t:null;function Pt(t,e){let n=new Map;for(let r of e)for(let o of r.rooms){let i=r.openings.filter(g=>g.room_id===o.id).sort((g,y)=>g.edge-y.edge||g.offset-y.offset);if(i.length===0)continue;let s=ye(t,o),l=g=>t.states[g]?.attributes.device_class,a=g=>s.filter(y=>Q(y)==="binary"&&g(l(y)??"")),c=g=>i.filter(y=>y.type===g),u=xr(c("window"),s.filter(g=>Q(g)==="cover"&&Mb.has(l(g))),!0),d=xr(c("window"),a(g=>Eb.has(g))),p=xr(c("door"),a(g=>g==="door")),h=xr(c("garage"),s.filter(g=>Q(g)==="cover"&&Rb.has(l(g)??""))),f=xr(c("garage"),a(g=>g==="garage_door"));for(let g of i){let y=g.type==="window"?u:g.type==="garage"?h:null,b=g.type==="window"?d:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:Eu(g.cover,y?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:Eu(g.contact,b.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?zt(g.contact2):null,tilt2:v?zt(g.tilt2):null,position:zt(g.position),positionInverted:!!g.position_inverted,tiltAngle:zt(g.tilt_angle),tiltMax:g.tilt_max??null,tiltOffset:g.tilt_offset??null,tiltInvert:!!g.tilt_invert,shut:!!g.shut,angled:g.type==="door"&&!!g.open_angle,lock:g.type==="door"?zt(g.lock):null,cover2:g.type==="garage"?null:zt(g.cover2),coverTilt:zt(g.cover_tilt),cover2Tilt:zt(g.cover2_tilt),coverInverted:!!g.cover_inverted,coverTiltInverted:!!g.cover_tilt_inverted,cover2Inverted:!!g.cover2_inverted,cover2TiltInverted:!!g.cover2_tilt_inverted})}}return n}var Ab=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function Cs(t){if(!t||et(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),o=r&&Ab.find(([i])=>i.test(r));if(o)return o[1]}return null}var Au=new WeakMap,Fu=new WeakMap;function Tu(t,e){let n=Fu.get(t)??t,r=Au.get(n)??new WeakMap;Au.set(n,r);let o=r.get(e);if(o)return o;let i=new Map;for(let a of e)for(let c of a.placements)c.entity_id.startsWith("cover.")&&i.set(c.entity_id,{tilt:c.cover_tilt==="none"?null:c.cover_tilt,position:c.position});for(let a of Pt(n,e).values())a.cover&&!i.has(a.cover)&&i.set(a.cover,{tilt:a.coverTilt,position:a.position}),a.cover2&&!i.has(a.cover2)&&i.set(a.cover2,{tilt:a.cover2Tilt});let s={...n.states};for(let[a,c]of i){let u=n.states[a];if(!u)continue;let d={...u.attributes,nf_cover_control:!0},p=ti(n,c.position);p===null&&(p=typeof u.attributes.current_position=="number"?u.attributes.current_position:null),p!==null&&(d.current_position=p);let h=c.tilt?n.states[c.tilt]:u,f=typeof h?.attributes.current_tilt_position=="number"?h.attributes.current_tilt_position:c.tilt?ti(n,c.tilt):null;f!==null&&(d.current_tilt_position=f,d.supported_features=Number(d.supported_features??0)|128);let g=u.state;typeof d.current_position=="number"&&g!=="unavailable"&&g!=="unknown"&&g!=="opening"&&g!=="closing"&&(g=d.current_position>0?"open":"closed"),s[a]={...u,state:g,attributes:d}}let l={...n,states:s,callService:async(a,c,u={})=>{if(a!=="cover")return n.callService(a,c,u);let d=Array.isArray(u.entity_id)?u.entity_id:[u.entity_id],p=async h=>{let f=typeof h=="string"?i.get(h):void 0;if(!f)return n.callService(a,c,{...u,entity_id:h});let g={...u,entity_id:h},y=c;(y==="toggle"||y==="toggle_cover")&&(y=s[String(h)]?.state==="closed"?"open_cover":"close_cover");let b=y.includes("tilt");b&&f.tilt&&(g.entity_id=f.tilt);let v=f.tilt?n.states[f.tilt]:void 0;return b&&f.tilt&&!v?.attributes.symcon_id&&typeof v?.attributes.current_tilt_position!="number"&&(y==="set_cover_tilt_position"?(y="set_cover_position",g.position=g.tilt_position,delete g.tilt_position):y==="open_cover_tilt"?y="open_cover":y==="close_cover_tilt"&&(y="close_cover")),n.callService(a,y,g)};return Array.isArray(u.entity_id)?Promise.all(d.map(p)):p(d[0])}};return Fu.set(l,n),r.set(e,l),l}var oe=t=>t?.symconObjects!==void 0;function It(t,e,n=[0,1,2,3]){let r=t?.states[e]?.attributes;return!!r?.symcon_id&&!r.symcon_source_entity&&n.includes(Number(r.symcon_variable_type))}function zn(t){return!t||t.state==="unknown"||t.state==="unavailable"?null:t.attributes.symcon_value??t.attributes.symcon_numeric_value??t.state}function en(t){let e=zn(t);if(e===null||typeof e=="boolean"||e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}function $r(t){let e=zn(t);if(e===null)return null;if(typeof e=="boolean")return e;if(typeof e=="number")return e>0;let n=String(e).trim().toLowerCase();if(["on","true","1","home","open","an","ein","ja","regen","rain","wet","nass"].includes(n))return!0;if(["off","false","0","not_home","closed","aus","nein","trocken","dry"].includes(n))return!1;let r=Number(n);return n!==""&&Number.isFinite(r)?r>0:null}function zu(t){return zn(t)===null?"\u2013":String(t?.attributes.symcon_formatted??zn(t))}function Pu(t,e){switch(e){case"m/s":return t*3.6;case"mph":return t*1.609;case"kn":return t*1.852;case"ft/s":return t*1.097;default:return t}}var Iu="weather.nextfloor_symcon",Ou={condition:"Wetterzustand",temperature:"Au\xDFentemperatur",humidity:"Au\xDFenluftfeuchte",pressure:"Luftdruck",wind_speed:"Windgeschwindigkeit",wind_gust_speed:"Windb\xF6en",wind_bearing:"Windrichtung",cloud_coverage:"Bew\xF6lkung",precipitation:"Niederschlagsrate",precipitation_total:"Niederschlagsmenge",illuminance:"Au\xDFenhelligkeit",uv_index:"UV-Index",visibility:"Sichtweite",snow:"Schnee",fog:"Nebel",lightning:"Gewitter"},Du=new WeakMap;function Fb(t){let e=t.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim();return["sunny","clear-night","partlycloudy","cloudy","fog","rainy","pouring","lightning-rainy","lightning","hail","snowy","snowy-rainy","windy","windy-variant"].includes(e)?e:/kein regen|trocken|wolkenlos|klar|sonnig/.test(e)?"sunny":/gewitter|blitz/.test(e)?"lightning-rainy":/schneeregen/.test(e)?"snowy-rainy":/schnee/.test(e)?"snowy":/hagel/.test(e)?"hail":/starkregen/.test(e)?"pouring":/regen|niesel/.test(e)?"rainy":/nebel/.test(e)?"fog":/teil.*wolk|heiter|leicht.*wolk/.test(e)?"partlycloudy":/wolk|bedeckt/.test(e)?"cloudy":/wind|sturm/.test(e)?"windy":null}function Hu(t,e){if(!oe(t))return t;let n=e.weather_variables??{};if(!e.rain_sensor&&!Object.values(n).some(h=>h&&h!=="none"))return t;let r=Du.get(t)??new WeakMap;Du.set(t,r);let o=r.get(e);if(o)return o;let i={friendly_name:"Wetter",nf_symcon_weather:!0},s=h=>n[h]&&n[h]!=="none"?t.states[n[h]]:void 0;for(let h of["temperature","humidity","pressure","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility"]){let f=s(h),g=en(f);g!==null&&(i[h]=h==="cloud_coverage"&&f?.attributes.symcon_max===1?g*100:g),f?.attributes.unit_of_measurement&&(i[`${h}_unit`]=f.attributes.unit_of_measurement)}for(let h of["wind_speed","wind_gust_speed"]){let f=s(h),g=en(f);g!==null&&(i[h]=Pu(g,f?.attributes.unit_of_measurement))}i.wind_speed_unit="km/h";let l=zn(s("wind_bearing"));l!==null&&(i.wind_bearing=l);let a=Fb(zu(s("condition"))),c=e.rain_sensor?t.states[e.rain_sensor]:void 0,u=$r(c);u!==null&&e.rain_sensor_inverted&&(u=!u),u===null&&typeof i.precipitation=="number"&&(u=i.precipitation>0),$r(s("lightning"))?a=u?"lightning-rainy":"lightning":$r(s("snow"))?a=u?"snowy-rainy":"snowy":$r(s("fog"))?a="fog":u===!0?a=Number(i.precipitation??0)>=8?"pouring":"rainy":u===!1&&a&&/rain|pouring/.test(a)&&(a=null),!a&&typeof i.cloud_coverage=="number"&&(a=i.cloud_coverage>70?"cloudy":i.cloud_coverage>20?"partlycloudy":"sunny"),!a&&u===!1&&(a="sunny");let d={entity_id:Iu,state:a??"unknown",attributes:i},p={...t,states:{...t.states,[Iu]:d}};return r.set(e,p),p}var Pn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},tn=t=>(...e)=>({_$litDirective$:t,values:e}),Dt=class{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,n,r){this._$Ct=e,this._$AM=n,this._$Ci=r}_$AS(e,n){return this.update(e,n)}update(e,n){return this.render(...n)}};var Sr=class extends Dt{constructor(e){if(super(e),this.it=_,e.type!==Pn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===_||e==null)return this._t=void 0,this.it=e;if(e===Je)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;let n=[e];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};Sr.directiveName="unsafeHTML",Sr.resultType=1;var Lu=tn(Sr);var Cu=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,Nu=/(kühl|fridge|gefrier|freezer)/i,Bu=/(spülmaschine|geschirrspül|dishwasher)/i,Tb=/(kochfeld|herd|induktion|cooktop)/i,zb={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:Cu,tv_wall:Cu,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:Nu,fridge_smart:Nu,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:Bu,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:Tb,sink:Bu,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},Wu={lamp_ceiling:/(decke|ceiling|haupt|main)/i,lamp_downlight:/(spot|strahler|downlight|einbau)/i,lamp_spot:/(spot|strahler)/i,lamp_panel:/(panel|decke|ceiling)/i,lamp_uplight:/(fluter|uplight|steh)/i,lamp_bollard:/(weg|garten|garden|path|poller|außen|aussen|outdoor)/i,lamp_garden:/(garten|garden|spot|außen|aussen|outdoor|baum|tree)/i,lamp_pendant:/(pendel|pendant|hänge|esstisch|dining)/i,ceiling_fan:/(ventilator|fan)/i,lamp_floor:/(steh|floor)/i,lamp_table:/(tisch|nacht|table|bedside|lese|reading)/i,lamp_wall:/(wand|wall)/i,led_strip:/(led|strip|streifen|leiste|band)/i},Vu=new Set(["tv_board","tv_wall"]);var In=t=>Vu.has(t)||!!zc(t),ni=t=>!!U(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),Rr=t=>In(t)||t==="desk"||t==="fridge_smart",Pb=t=>!!t&&t!=="none";function Ib(t,e){if(Xo(t,e))return e;let n=t.entities?.[e]?.device_id;return n?Qo(t,n).find(r=>r!==e)??null:null}var Db=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Mr(t,e,n,r){return t.find(o=>e?.test(n(o)))??(r?t[0]??null:null)}function We(t,e){let n=new Map;for(let r of e){let o=new Set([...r.furniture.flatMap(i=>[i.entity,i.power,i.fan_entity]),...r.placements.map(i=>i.entity_id)].filter(Pb));for(let i of r.furniture){let s=i.type in Wu,l=$n(i.type),a=s?Wu[i.type]:zb[i.type];if(!a&&!l&&!ni(i.type)&&i.entity==null&&i.power==null)continue;let c=Db(r,i.x,i.z),u=(c?Jo(t,ye(t,c)):[]).filter(y=>!o.has(y)),d=y=>`${y} ${W(t,y)}`,p=y=>u.filter(b=>Q(b)===y),h=i.entity==="none"?null:i.entity??null;if(i.entity==null){if(i.type==="ceiling_fan"){let y=(c?ye(t,c):[]).filter(v=>!o.has(v)),b=new Set(y.filter(v=>Q(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=y.find(v=>Q(v)==="light"&&b.has(t.entities?.[v]?.device_id))??Mr(p("light"),a,d,!1)}else if(s)h=Mr(p("light"),a,d,!0);else if(i.type==="robot_vacuum"){let y=c?.area_id??null;h=Object.keys(t.entities??{}).find(b=>b.startsWith("vacuum.")&&!o.has(b)&&Tt(t,b)===y)??null}else if(i.type==="radiator"||l)h=Mr(p("climate"),a,d,!0);else if(In(i.type)){let y=p("media");h=y.find(b=>t.states[b]?.attributes.device_class==="tv")??Mr(y,a,d,Vu.has(i.type))}else if(ni(i.type)){let y=p("media").filter(b=>t.states[b]?.attributes.device_class!=="tv");h=Mr(y,a,d,!1)??(y.length===1?y[0]:null)}else a&&(h=u.find(y=>["switch","media","fan"].includes(Q(y)??"")&&a.test(d(y)))??null);h&&o.add(h)}let f=i.power==="none"?null:i.power??null;i.power==null&&(f=h?Ib(t,h):null,!f&&a&&c&&!s&&(f=ye(t,c).find(y=>Xo(t,y)&&!o.has(y)&&a.test(d(y)))??null),f&&o.add(f));let g=null;if(i.type==="ceiling_fan"&&(g=i.fan_entity==="none"?null:i.fan_entity??null,i.fan_entity==null)){let y=(c?ye(t,c):[]).filter(v=>Q(v)==="fan"&&!o.has(v)),b=h?t.entities?.[h]?.device_id:void 0;g=(b?y.find(v=>t.entities?.[v]?.device_id===b):void 0)??y[0]??null,g&&o.add(g)}(h||f||g)&&n.set(i.id,{entity:h,power:f,...i.type==="ceiling_fan"?{fan:g}:{}})}}return n}var Ku=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function ju(t,e,n=[]){let r=[];for(let o of e){let i=(l,a)=>o.rooms.some(c=>c.points.length>=3&&N([l,a],c.points)),s=We(t,[o]);r.push(...o.placements.filter(l=>l.outside||!i(l.x,l.z)).map(l=>l.entity_id)),r.push(...o.furniture.filter(l=>!i(l.x,l.z)).flatMap(l=>[s.get(l.id)?.entity,s.get(l.id)?.power]));for(let l of o.outdoor??[])l.area_id&&r.push(...Jo(t,Yo(t,l.area_id))),r.push(l.pump_entity,l.temp_entity)}return[...new Set(r.filter(o=>!!o&&!!t.states[o]&&!n.includes(o)))]}function Ob(t,e){return Math.min(...e.map((n,r)=>{let o=e[(r+1)%e.length],[i,s]=[o[0]-n[0],o[1]-n[1]],l=Math.min(1,Math.max(0,((t[0]-n[0])*i+(t[1]-n[1])*s)/(i*i+s*s||1)));return Math.hypot(t[0]-n[0]-i*l,t[1]-n[1]-s*l)}))}function Uu(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let o=r.map(b=>b[0]),i=r.map(b=>b[1]),[s,l,a,c]=[Math.min(...o),Math.max(...o),Math.min(...i),Math.max(...i)],u=Math.min(l-s,c-a),d=Math.max(.1,Math.min(.25,u/8)),p=Math.min(.35,u/5),h=Math.min(.7,u/4),f=be(r),g=[];for(let b=s+d/2;b=p&&g.push({at:w,wallDistance:x})}g.length===0&&g.push({at:f,wallDistance:0});let y=[...n];return e.map(b=>{let v=Q(b)==="light",w=g[0].at,x=-1/0;for(let{at:S,wallDistance:E}of g){let T=y.length?Math.min(...y.map(P=>Math.hypot(S[0]-P[0],S[1]-P[1]))):3,F=Math.hypot(S[0]-f[0],S[1]-f[1]),O=Math.min(T,3)*2;Fx+1e-9&&(x=O,w=S)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return y.push(k),{entity_id:b,x:k[0],z:k[1],y:null,mount:null}})}var Gu=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function Zu(t,e,n){if(n==="none")return null;if(n)return n;let r=e?t.entities?.[e]?.device_id:null;return!r||!t.entities?null:Object.values(t.entities).find(i=>i.device_id===r&&i.entity_id.startsWith("sensor.")&&(Gu.test(i.translation_key??"")||Gu.test(i.entity_id.split(".")[1])))?.entity_id??null}var ve=J`
:host {
--nf-text: var(--primary-text-color, #e1e1e1);
--nf-muted: var(--secondary-text-color, #9b9b9b);
@@ -29,7 +29,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
font-family: var(--nf-font);
color: var(--nf-text);
}
-`,x$=ne`
+`,E$=J`
:host([readable]) {
--secondary-text-color: var(--primary-text-color, #e1e1e1);
--divider-color: color-mix(in srgb, var(--primary-text-color, #e1e1e1) 40%, transparent);
@@ -40,7 +40,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
:host([readable]) .nf-overlay {
zoom: 1.2;
}
-`,ht=ne`
+`,ht=J`
/* a group of switches: one rounded pill, the active one tinted with the accent */
.nf-seg {
display: inline-flex;
@@ -203,7 +203,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
min-height: 40px;
}
}
-`;var{I:zb}=_c,ju=t=>t;var Uu=t=>t.strings===void 0,Gu=()=>document.createComment(""),Dn=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(Gu(),o),s=r.insertBefore(Gu(),o);n=new zb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=ju(a).nextSibling;ju(r).insertBefore(a,o),a=c}}}return n},Ot=(t,e,n=t)=>(t._$AI(e,n),t),Pb={},Zu=(t,e=Pb)=>t._$AH=e,qu=t=>t._$AH,ri=t=>{t._$AR(),t._$AA.remove()};var Yu=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},Xu=tn(class extends Dt{constructor(t){if(super(t),t.type!==Pn.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=qu(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,u,d=0,p=o.length-1,h=0,f=i.length-1;for(;d<=p&&h<=f;)if(o[d]===null)d++;else if(o[p]===null)p--;else if(l[d]===s[h])a[h]=Ot(o[d],i[h]),d++,h++;else if(l[p]===s[f])a[f]=Ot(o[p],i[f]),p--,f--;else if(l[d]===s[f])a[f]=Ot(o[d],i[f]),Dn(t,a[f+1],o[d]),d++,f--;else if(l[p]===s[h])a[h]=Ot(o[p],i[h]),Dn(t,o[d],o[p]),p--,h++;else if(c===void 0&&(c=Yu(s,h,f),u=Yu(l,d,p)),c.has(l[d]))if(c.has(l[p])){let g=u.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Dn(t,o[d]);Ot(b,i[h]),a[h]=b}else a[h]=Ot(y,i[h]),Dn(t,o[d],y),o[g]=null;h++}else ri(o[p]),p--;else ri(o[d]),d++;for(;h<=f;){let g=Dn(t,a[f+1]);Ot(g,i[h]),a[h++]=g}for(;d<=p;){let g=o[d++];g!==null&&ri(g)}return this.ut=s,Zu(t,a),Je}});var Ib=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),Ns=-1,Ju=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],Qu=t=>t.object_type===1&&Ju.some(e=>e.type===t.module_type);function Db(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!Qu(a))return!1;let c=new Set([a.object_id]),u=e.get(a.parent_id);for(;u&&!c.has(u.object_id);){if(Qu(u))return!1;c.add(u.object_id),u=e.get(u.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,u,d,p)=>({object_id:a,parent_id:c,name:u,path:d,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(Ns,i(Ns,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,u)=>{if(s.has(a.object_id))return;s.add(a.object_id);let d={...a,parent_id:c,path:`${u} / ${a.name}`};r.set(a.object_id,d);for(let p of o.get(a.object_id)??[])l(p,a.object_id,d.path)};return Ju.forEach((a,c)=>{let u=n.filter(h=>h.module_type===a.type);if(!u.length)return;let d=-10-a.type,p=`System / ${a.name}`;r.set(d,i(d,Ns,a.name,p,c));for(let h of u)l(h,d,p)}),[...r.values()]}function Bs(t){let e=Db(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Ib.compare(i.name,s.name));return{nodes:n,children:r}}function Ws(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function Vs(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of Ws(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let u=(t.children.get(a)??[]).filter(d=>!o||o.has(d.object_id));u.forEach((d,p)=>{if(s.has(d.object_id))return;s.add(d.object_id);let h=(t.children.get(d.object_id)?.length??0)>0,f=h&&(!!o||e.has(d.object_id));i.push({node:d,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:u.length}),f&&l(d.object_id,c+1)})};return l(0,0),i}var Ob=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],Ks=class extends X{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=Bs([]);allowed=new Map;allowedSources=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=Bs(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])),this.allowedSources=new Map(this.options.filter(n=>n.sourceEntity).map(n=>[n.sourceEntity,n.id])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.allowed.get(e??"")?.sourceEntity??e,r=this.objects.find(o=>o.entity_id===n&&(o.object_type===2||o.object_type===4));return r?this.tree.nodes.get(r.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of Ws(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}clear(e){e.preventDefault(),e.stopPropagation(),!this.disabled&&(this.value=this.fixed.some(n=>n.id==="none")?"none":null,this._pending=this.value,this._selected=null,this._active=null,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id;let n=this.entityFor(e);n&&(this._pending=n,this._selected=e.object_id)}entityFor(e){if(e.entity_id)return this.allowed.has(e.entity_id)?e.entity_id:this.allowedSources.get(e.entity_id)}async onTreeKey(e){let n=Vs(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&this.entityFor(o.node)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R` `,R` `,R` `,R` `,R` `,R` `,R` `];return R`${n[e]??n[1]} `}renderRow(e){let{node:n}=e,r=this.entityFor(n),o=!!r;return m`t;var Xu=t=>t.strings===void 0,Yu=()=>document.createComment(""),Dn=(t,e,n)=>{let r=t._$AA.parentNode,o=e===void 0?t._$AB:e._$AA;if(n===void 0){let i=r.insertBefore(Yu(),o),s=r.insertBefore(Yu(),o);n=new Hb(i,s,t,t.options)}else{let i=n._$AB.nextSibling,s=n._$AM,l=s!==t;if(l){let a;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(a=t._$AU)!==s._$AU&&n._$AP(a)}if(i!==o||l){let a=n._$AA;for(;a!==i;){let c=qu(a).nextSibling;qu(r).insertBefore(a,o),a=c}}}return n},Ot=(t,e,n=t)=>(t._$AI(e,n),t),Lb={},Qu=(t,e=Lb)=>t._$AH=e,Ju=t=>t._$AH,ri=t=>{t._$AR(),t._$AA.remove()};var ed=(t,e,n)=>{let r=new Map;for(let o=e;o<=n;o++)r.set(t[o],o);return r},td=tn(class extends Dt{constructor(t){if(super(t),t.type!==Pn.CHILD)throw Error("repeat() can only be used in text expressions")}dt(t,e,n){let r;n===void 0?n=e:e!==void 0&&(r=e);let o=[],i=[],s=0;for(let l of t)o[s]=r?r(l,s):s,i[s]=n(l,s),s++;return{values:i,keys:o}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let o=Ju(t),{values:i,keys:s}=this.dt(e,n,r);if(!Array.isArray(o))return this.ut=s,i;let l=this.ut??=[],a=[],c,u,d=0,p=o.length-1,h=0,f=i.length-1;for(;d<=p&&h<=f;)if(o[d]===null)d++;else if(o[p]===null)p--;else if(l[d]===s[h])a[h]=Ot(o[d],i[h]),d++,h++;else if(l[p]===s[f])a[f]=Ot(o[p],i[f]),p--,f--;else if(l[d]===s[f])a[f]=Ot(o[d],i[f]),Dn(t,a[f+1],o[d]),d++,f--;else if(l[p]===s[h])a[h]=Ot(o[p],i[h]),Dn(t,o[d],o[p]),p--,h++;else if(c===void 0&&(c=ed(s,h,f),u=ed(l,d,p)),c.has(l[d]))if(c.has(l[p])){let g=u.get(s[h]),y=g!==void 0?o[g]:null;if(y===null){let b=Dn(t,o[d]);Ot(b,i[h]),a[h]=b}else a[h]=Ot(y,i[h]),Dn(t,o[d],y),o[g]=null;h++}else ri(o[p]),p--;else ri(o[d]),d++;for(;h<=f;){let g=Dn(t,a[f+1]);Ot(g,i[h]),a[h++]=g}for(;d<=p;){let g=o[d++];g!==null&&ri(g)}return this.ut=s,Qu(t,a),Je}});var Cb=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),Ns=-1,rd=[{type:1,name:"I/O"},{type:2,name:"Splitter"},{type:0,name:"Kerninstanzen"},{type:4,name:"Konfiguratoren"},{type:5,name:"Discovery"},{type:6,name:"Visualisierungen"}],nd=t=>t.object_type===1&&rd.some(e=>e.type===t.module_type);function Nb(t){let e=new Map(t.map(a=>[a.object_id,a])),n=t.filter(a=>{if(!nd(a))return!1;let c=new Set([a.object_id]),u=e.get(a.parent_id);for(;u&&!c.has(u.object_id);){if(nd(u))return!1;c.add(u.object_id),u=e.get(u.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),o=new Map;for(let a of t){let c=o.get(a.parent_id)??[];c.push(a),o.set(a.parent_id,c)}let i=(a,c,u,d,p)=>({object_id:a,parent_id:c,name:u,path:d,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(Ns,i(Ns,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,l=(a,c,u)=>{if(s.has(a.object_id))return;s.add(a.object_id);let d={...a,parent_id:c,path:`${u} / ${a.name}`};r.set(a.object_id,d);for(let p of o.get(a.object_id)??[])l(p,a.object_id,d.path)};return rd.forEach((a,c)=>{let u=n.filter(h=>h.module_type===a.type);if(!u.length)return;let d=-10-a.type,p=`System / ${a.name}`;r.set(d,i(d,Ns,a.name,p,c));for(let h of u)l(h,d,p)}),[...r.values()]}function Bs(t){let e=Nb(t),n=new Map(e.map(o=>[o.object_id,o])),r=new Map;for(let o of e){let i=n.has(o.parent_id)?o.parent_id:0,s=r.get(i)??[];s.push(o),r.set(i,s)}for(let o of r.values())o.sort((i,s)=>i.position-s.position||i.object_type-s.object_type||Cb.compare(i.name,s.name));return{nodes:n,children:r}}function Ws(t,e){let n=[],r=new Set([e]),o=t.nodes.get(e)?.parent_id;for(;o&&!r.has(o)&&t.nodes.has(o);)n.push(o),r.add(o),o=t.nodes.get(o)?.parent_id;return n}function Vs(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),o=r.length?new Set:null;if(o){for(let a of t.nodes.values())if(r.every(c=>`${a.name} ${a.path}`.toLocaleLowerCase("de").includes(c))){o.add(a.object_id);for(let c of Ws(t,a.object_id))o.add(c)}}let i=[],s=new Set,l=(a,c)=>{let u=(t.children.get(a)??[]).filter(d=>!o||o.has(d.object_id));u.forEach((d,p)=>{if(s.has(d.object_id))return;s.add(d.object_id);let h=(t.children.get(d.object_id)?.length??0)>0,f=h&&(!!o||e.has(d.object_id));i.push({node:d,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:u.length}),f&&l(d.object_id,c+1)})};return l(0,0),i}var Bb=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],Ks=class extends Y{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=Bs([]);allowed=new Map;allowedSources=new Map;constructor(){super(),this.objects=[],this.options=[],this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="Datenpunkt ausw\xE4hlen",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=Bs(this.objects)),(e.has("options")||e.has("fixed"))&&(this.allowed=new Map([...this.fixed,...this.options].map(n=>[n.id,n])),this.allowedSources=new Map(this.options.filter(n=>n.sourceEntity).map(n=>[n.sourceEntity,n.id])))}get dialog(){return this.renderRoot.querySelector("dialog")}variableNode(e){let n=this.allowed.get(e??"")?.sourceEntity??e,r=this.objects.find(o=>o.entity_id===n&&(o.object_type===2||o.object_type===4));return r?this.tree.nodes.get(r.object_id):void 0}async open(){if(this.disabled)return;this._pending=this.allowed.has(this.value??"")?this.value:null,this._query="";let e=this.variableNode(this.value)??this.objects.find(r=>r.entity_id===this.value);this._active=e?.object_id??null,this._selected=e?.object_id??null;let n=new Set(this._expanded);if(e)for(let r of Ws(this.tree,e.object_id))n.add(r);this._expanded=n,await this.updateComplete,this.isConnected&&(this.dialog?.open||this.dialog?.showModal(),this.renderRoot.querySelector(".search")?.focus(),this.renderRoot.querySelector("[aria-selected=true]")?.scrollIntoView({block:"nearest"}))}close(){this.dialog?.close()}clear(e){e.preventDefault(),e.stopPropagation(),!this.disabled&&(this.value=this.fixed.some(n=>n.id==="none")?"none":null,this._pending=this.value,this._selected=null,this._active=null,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}commit(){this.disabled||!this._pending||!this.allowed.has(this._pending)||(this.value=this._pending,this.close(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0,composed:!0})))}toggle(e){let n=new Set(this._expanded);n.has(e)?n.delete(e):n.add(e),this._expanded=n}select(e){this._active=e.object_id;let n=this.entityFor(e);n&&(this._pending=n,this._selected=e.object_id)}entityFor(e){if(e.entity_id)return this.allowed.has(e.entity_id)?e.entity_id:this.allowedSources.get(e.entity_id)}async onTreeKey(e){let n=Vs(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),o=n[r];if(!o)return;let i=r;if(e.key==="ArrowDown")i=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")i=Math.max(0,r-1);else if(e.key==="Home")i=0;else if(e.key==="End")i=n.length-1;else if(e.key==="ArrowRight")o.hasChildren&&!o.expanded?this.toggle(o.node.object_id):o.hasChildren&&(i=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")o.expanded&&!this._query?this.toggle(o.node.object_id):i=Math.max(0,n.findIndex(s=>s.node.object_id===o.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(o.node),e.key==="Enter"&&this.entityFor(o.node)&&this.commit();else return;e.preventDefault(),(i!==r||this._active===null)&&(this._active=n[i].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[R`
`,R`
`,R`
`,R`
`,R`
`,R`
`,R`
`];return R`
${n[e]??n[1]} `}renderRow(e){let{node:n}=e,r=this.entityFor(n),o=!!r;return m`
${this.icon(n.object_type)}${n.name||"(Ohne Namen)"}
- ${n.virtual?"Systembereich":Ob[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""}
+ ${n.virtual?"Systembereich":Bb[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""}
${o&&n.object_id===this._selected&&r===this._pending?m`✓ `:_}
`}render(){let e=this.allowed.get(this.value??""),n=this.variableNode(this.value),r=this.allowed.get(this._pending??""),o=this._selected===null?void 0:this.tree.nodes.get(this._selected),i=(o&&this.entityFor(o)===this._pending?o:void 0)??this.variableNode(this._pending),s=Vs(this.tree,this._expanded,this._query),l=s.find(c=>c.node.object_id===this._active),a=!!this.value&&!this.fixed.some(c=>c.id===this.value);return m`
${n?.name??e?.label??"Datenpunkt ausw\xE4hlen"}
@@ -234,7 +234,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
{this._pending=c.id,this._active=null,this._selected=null}}>${c.label} `)}
`:_}
- ${Xu(s,c=>c.node.object_id,c=>this.renderRow(c))}
+ ${td(s,c=>c.node.object_id,c=>this.renderRow(c))}
${s.length?_:m`
${this.objects.length?"Keine Objekte gefunden.":"Kein Objektbaum verf\xFCgbar. Bitte das Symcon-Modul aktualisieren und den Designer neu laden."}
`}
${i?.name??r?.label??"Noch kein Datenpunkt ausgew\xE4hlt"}
@@ -242,7 +242,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
Abbrechen
Übernehmen
- `}static styles=[ve,ne`
+ `}static styles=[ve,J`
:host { display:block; min-width:0; max-width:100%; font:inherit; color:var(--nf-text); }
button,input { font:inherit; box-sizing:border-box; }
button { cursor:pointer; color:var(--nf-text); border:1px solid var(--nf-line); background:var(--nf-chrome-solid); border-radius:9px; padding:8px 12px; }
@@ -292,7 +292,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
.tree { margin:0 8px; } .node { gap:6px; padding-left:calc(2px + var(--depth)*18px); }
.node small { display:none; } footer { padding:12px; flex-direction:column; align-items:stretch; } .actions { justify-content:flex-end; }
}
- `]};customElements.get("nf-symcon-object-picker")||customElements.define("nf-symcon-object-picker",Ks);var ed=40,js=class extends X{static properties={options:{attribute:!1},objectTree:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},_query:{state:!0},_open:{state:!0},_cursor:{state:!0}};blurTimer;constructor(){super(),this.options=[],this.objectTree=void 0,this.fixed=[],this.value=null,this.disabled=!1,this.placeholder="",this._query="",this._open=!1,this._cursor=0}get current(){return[...this.fixed,...this.options].find(e=>e.id===this.value)}get hits(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=s=>{let l=`${s.label} ${s.detail??s.id}`.toLowerCase();return n.every(a=>l.includes(a))},o=this.fixed.filter(s=>!e||r(s)),i=e?this.options.filter(r):this.options;return[...o,...i.slice(0,ed)]}get leftOut(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=e?this.options.filter(o=>n.every(i=>`${o.label} ${o.detail??o.id}`.toLowerCase().includes(i))).length:this.options.length;return Math.max(0,r-ed)}choose(e){this.value=e,this._query="",this._open=!1,this.dispatchEvent(new CustomEvent("change",{detail:{value:e},bubbles:!0,composed:!0}))}onKey(e){let n=this.hits;e.key==="ArrowDown"?(this._open=!0,this._cursor=Math.min(n.length-1,this._cursor+1),e.preventDefault()):e.key==="ArrowUp"?(this._cursor=Math.max(0,this._cursor-1),e.preventDefault()):e.key==="Enter"?(this._open&&n[this._cursor]&&this.choose(n[this._cursor].id),e.preventDefault()):e.key==="Escape"&&(this._open=!1,this._query="")}render(){if(this.objectTree!==void 0)return m`
e.id===this.value)}get hits(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=s=>{let l=`${s.label} ${s.detail??s.id}`.toLowerCase();return n.every(a=>l.includes(a))},o=this.fixed.filter(s=>!e||r(s)),i=e?this.options.filter(r):this.options;return[...o,...i.slice(0,od)]}get leftOut(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=e?this.options.filter(o=>n.every(i=>`${o.label} ${o.detail??o.id}`.toLowerCase().includes(i))).length:this.options.length;return Math.max(0,r-od)}choose(e){this.value=e,this._query="",this._open=!1,this.dispatchEvent(new CustomEvent("change",{detail:{value:e},bubbles:!0,composed:!0}))}onKey(e){let n=this.hits;e.key==="ArrowDown"?(this._open=!0,this._cursor=Math.min(n.length-1,this._cursor+1),e.preventDefault()):e.key==="ArrowUp"?(this._cursor=Math.max(0,this._cursor-1),e.preventDefault()):e.key==="Enter"?(this._open&&n[this._cursor]&&this.choose(n[this._cursor].id),e.preventDefault()):e.key==="Escape"&&(this._open=!1,this._query="")}render(){if(this.objectTree!==void 0)return m`{this.value=r.detail.value}}
@@ -322,7 +322,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
`)}
${this.leftOut>0?m`… +${this.leftOut} · ${this.placeholder} `:_}
`:_}
- `}static styles=[ve,ne`
+ `}static styles=[ve,J`
:host {
display: block;
position: relative;
@@ -390,11 +390,11 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
color: var(--nf-muted);
cursor: default;
}
- `]};customElements.get("nf-entity-picker")||customElements.define("nf-entity-picker",js);var Gs=class extends X{static properties={text:{attribute:!1}};constructor(){super(),this.text=""}get dialog(){return this.renderRoot.querySelector("dialog")}render(){return m`this.dialog?.showModal()}>ⓘ
+ `]};customElements.get("nf-entity-picker")||customElements.define("nf-entity-picker",js);var Gs=class extends Y{static properties={text:{attribute:!1}};constructor(){super(),this.text=""}get dialog(){return this.renderRoot.querySelector("dialog")}render(){return m`this.dialog?.showModal()}>ⓘ
e.stopPropagation()} @click=${e=>{if(e.target!==e.currentTarget)return;let n=this.dialog.getBoundingClientRect();(e.clientXn.right||e.clientYn.bottom)&&this.dialog?.close()}}>
Information this.dialog?.close()}>×
${this.text}
- `}static styles=[ve,ne`
+ `}static styles=[ve,J`
:host { display:inline-block; margin:4px 0; vertical-align:middle; }
button { font:inherit; cursor:pointer; color:var(--nf-muted); background:transparent; border:1px solid var(--nf-line); border-radius:50%; pointer-events:auto; }
.info { width:26px; height:26px; padding:0; font-size:18px; line-height:24px; }
@@ -405,21 +405,21 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
header { display:flex; align-items:center; justify-content:space-between; gap:20px; font-size:16px; }
.close { width:30px; height:30px; padding:0; font-size:23px; }
p { white-space:pre-wrap; overflow-wrap:anywhere; margin:16px 0 4px; }
- `]};customElements.get("nf-help-popup")||customElements.define("nf-help-popup",Gs);var nn=t=>t.target.value,Us=t=>Number.parseFloat(t.replace(",",".")),se=t=>Math.round(t*1e3)/1e3,td=t=>t.wide?"nf-field nf-wide":"nf-field";function A(t,e,n,r,o=.01,i){return m`t.target.value,Us=t=>Number.parseFloat(t.replace(",",".")),ae=t=>Math.round(t*1e3)/1e3,id=t=>t.wide?"nf-field nf-wide":"nf-field";function A(t,e,n,r,o=.01,i){return m`${e}
{let l=Us(nn(s));Number.isFinite(l)&&r(l)}}
/>
- `}function V(t,e,n,r,o={}){return m``}function V(t,e,n,r,o={}){return m`${e}
r(nn(i).trim())} />
- `}function L(t,e,n,r,o,i={}){return m``}function L(t,e,n,r,o,i={}){return m`${e}
o(nn(s))}>
${r.map(([s,l])=>m`${l} `)}
@@ -444,17 +444,17 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
?disabled=${!t.admin}
@change=${c=>{c.stopPropagation(),i(c.detail.value==="__auto"?null:c.detail.value)}}
>
- `}function On(t,e,n){return n?(n.startsWith("mdi:")?n:`mdi:${n}`).replace(/[^a-z0-9:-]/gi,""):t.hass?fu(t.hass,e):null}function Ht(t,e,n){let r=e?(e.startsWith("mdi:")?e:`mdi:${e}`).replace(/[^a-z0-9:-]/gi,""):"";return m``}function On(t,e,n){return n?(n.startsWith("mdi:")?n:`mdi:${n}`).replace(/[^a-z0-9:-]/gi,""):t.hass?bu(t.hass,e):null}function Ht(t,e,n){let r=e?(e.startsWith("mdi:")?e:`mdi:${e}`).replace(/[^a-z0-9:-]/gi,""):"";return m`${t.t("marker_icon")}
n(nn(o).trim().replace(/^mdi:/,"")||null)} />
- ${r?Iu(` `):_}
+ ${r?Lu(` `):_}
`}function Hn(t,e,n){return m`${t.t("marker_show")}
n(nn(r)||null)}>
${t.t("marker_show_auto")}
- ${Nc.map(r=>m`${t.t(`marker_show_${r}`)} `)}
+ ${Kc.map(r=>m`${t.t(`marker_show_${r}`)} `)}
`}function Ln(t,e,n){let r=e??{},o=i=>s=>{let l={...r,[i]:Math.round(Math.max(-5,Math.min(5,s))*100)/100};n(l.x||l.z||l.y?l:null)};return m`
${t.t("pin_shift")}
@@ -463,7 +463,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
${e?m`n(null)}>${t.t("height_auto")} `:_}
${M(t.t("pin_shift_hint"),"nf-wide")}
- `}var Y=(...t)=>m`${t}
`,M=(t,e="")=>m` `;function rn(t,e,n,r={}){let o=r.lowest??10;return m``}var X=(...t)=>m`${t}
`,M=(t,e="")=>m` `;function rn(t,e,n,r={}){let o=r.lowest??10;return m`${t.t(r.label??"glow_scale")}
{let s=Number(nn(i)),l=Math.min(150,Math.max(o,nn(i).trim()===""||Number.isNaN(s)?100:s))/100;n(Math.abs(l-1)<.001?null:l)}}
/>
- `}var nt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function oi(t,e){return(await nt(t,"image/get",{image_id:e})).data}async function Lt(t,e,n){await nt(t,"image/set",{image_id:e,data:n})}async function nd(t){return(await nt(t,"history/list")).snapshots}async function rd(t,e){return(await nt(t,"history/snapshot",e?{name:e}:{})).id}async function od(t,e){return(await nt(t,"history/get",{snapshot_id:e})).building}async function id(t,e){await nt(t,"history/delete",{snapshot_id:e})}async function sd(t,e){return(await nt(t,"history/restore",{snapshot_id:e})).revision}var Rr=(t,e)=>nt(t,"packs/import",{pack:e});async function ad(t,e){await nt(t,"packs/remove",{pack_id:e})}var ld=t=>nt(t,"backup/export"),cd=(t,e,n)=>nt(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],pt=(t,e)=>[t[0]+e[0],t[1]+e[1]],rt=(t,e)=>[t[0]*e,t[1]*e],J=(t,e)=>t[0]*e[0]+t[1]*e[1],Me=(t,e)=>t[0]*e[1]-t[1]*e[0],me=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=me(t)||1;return[t[0]/e,t[1]/e]},Zs=t=>[-t[1],t[0]],qs=t=>[t[1],-t[0]];var Hb=.05,Lb=.2,Cb=.12;function Nb(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=_e(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=me(G(a,s));if(c<.05)return;let u=[(a[0]-s[0])/c,(a[1]-s[1])/c],d=i?[u[1],-u[0]]:[-u[1],u[0]];(u[1]<-1e-9||Math.abs(u[1])<=1e-9&&u[0]<0)&&(u=[-u[0],-u[1]]);let p=[-u[1],u[0]],[h,f]=[J(s,u),J(a,u)];e.push({room:r,index:l,dir:u,normal:p,offset:J(s,p),outside:J(d,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function Bb(t,e,n){if(t.room===e.room||Math.abs(Me(t.dir,e.dir))>Hb||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Cb||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function ud(t,e=.6){let n=Nb(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ys(b)),s.add(g).add(y)}let u=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=u.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs(Me(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=u.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs(Me(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let d=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:d(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ys(w[0]),Ys(w[1])]})})),gaps:i}}function dd(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var Wb=.25,hd=t=>Math.round(t*1e3)/1e3,pd=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Qs(t,e,n,r,o){let i=pd(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function Vb(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(J(G(i,n),r))<.02&&Math.abs(J(G(l,n),r))<.02}))}var Xs=(t,e)=>Math.abs((t-e+540)%360-180);function Er(t,e,n,r=Wb){let o=pd(t,e.x,e.z);if(!o)return null;let i=o.points,s=_e(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let u=i[(c+1)%i.length],d=me(G(u,a));if(d<.3)return;let p=[(u[0]-a[0])/d,(u[1]-a[1])/d],h=[-p[1]*s,p[0]*s],f=J(G([e.x,e.z],a),p);if(f<0||f>d)return;let g=Vb(t,o,a,h)?n/2:0,y=J(G([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,S)=>Xs(e.rotation,S.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:hd(e.x-h[0]*x),z:hd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var Cn=Math.PI/180,it=t=>Math.tan(Math.min(80,Math.max(0,t))*Cn);function Fr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function fd(t){if(!t.rotation)return null;let e=t.rotation*Cn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function md(t,e){let n=fd(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Js(t,e,n){let r=fd(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function Tr(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=Fr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>md(t,s))}function xe(t){let{x0:e,x1:n,z0:r,z1:o}=Fr(t),i=s=>md(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function zr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=Fr(t),[l,a]=Js(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var Ar=Math.tan(30*Cn);function Pr(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+Ar*(t-s+i))/(2*Ar))),u=l+(c-i)*Ar;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:u,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*Ar:p<=t-s?a+(t-s-p)*Ar:n+(t-p)*o}}function Ie(t){let e=xe(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[it(t.pitch_a),it(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Pr(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var on=t=>Ie(t).rh;function gd(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function Kb(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function jb(t,e,n){if(t.a===e.b)return!1;let r=ot(G(n[t.b],n[t.a])),o=ot(G(n[e.b],n[e.a]));return Math.abs(Me(r,o))>1e-6||J(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function _d(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:gd(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:gd(r[l[1]]);if(!jb(a,c,e))continue;let u={...a,b:c.b,sources:Kb(a.sources,c.sources)};i=[...r.filter((d,p)=>p!==l[0]&&p!==l[1]),u];break}if(!i)return r;r=i}}function bd(t,e){let n=new Map;t.forEach((o,i)=>{let s=ot(G(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:rt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:pt(s,rt(Zs(a.d),a.left)),right:pt(s,rt(qs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let u=i[(c+1)%i.length],d=pt(s,rt(Zs(a.d),a.left)),p=pt(s,rt(qs(u.d),u.right)),h=Me(a.d,u.d);if(Math.abs(h)<1e-4)return;let f=pt(d,rt(a.d,Me(G(p,d),u.d)/h));me(G(f,s))>l||(r.get(a.key).left=f,r.get(u.key).right=f)})}return r}function yd(t,e){let n=t.filter((r,o)=>me(G(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[G(o,s),G(l,o)];return Math.abs(Me(ot(a),ot(c)))<1e-7&&J(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function Gb(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function Ub(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(_e(o))<1e-6)continue;let i=_e(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function Zb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=G(s,i),a=me(l),c=rt(l,1/a),u=e.map((p,h)=>({id:h,rel:G(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&J(h,c)>n&&J(h,c)({t:J(h,c),id:p})).sort((p,h)=>p.t-h.t),d=[{t:0,id:o.u},...u,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function qb(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,u)=>c-u))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,u]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof u!="number"||c<=0||u<=0)return null;let[d,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:u,length:Math.hypot(p[0]-d[0],p[1]-d[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let u=o(l);return typeof u=="number"&&u>0?[u,u]:[null,null]}let c=u=>a.from+(a.to-a.from)*u/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let d of l){let[p,h]=s(d),[f,g]=d===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let u=l.map(d=>n.get(d.room)?.ceiling);if(u.every(d=>typeof d=="number"&&d>0)){let d=Math.max(...u);a===1/0&&(a=d),c===1/0&&(c=d)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let u=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(u)?u[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:u}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function wd(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function Yb(t,e,n,r){let o=qb(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==u&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let d=u?[c,u]:[c];if(o.hasNoWall(d)){u&&l.push([c.room,u.room]);continue}if(u){let p=o.thicknessOf(d)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:u.room,sources:d.map(vd),...wd(o.heightsOf(d))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(d)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[vd(c)],...wd(o.heightsOf(d))})}return{drafts:s,open:l}}function Xb(t,e){let n=i=>ot(G(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(J(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let u of i){let d=u.left+u.right,p=J(n(u),s)>0,h=c==="left"===p;[u.left,u.right]=h?[0,d]:[d,0]}}}var Qb=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],S=G(v[(x+1)%v.length],k),E=me(S);for(let T of w)T>r&&T{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],S=t.find(T=>T.points.length>=3&&N(k,T.points))?.id??null,E=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:E,right:E,exterior:!1,roomLeft:S,roomRight:S,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=_d(h,i.points,c),g=bd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,S]=[g.get(`${v}:a`),g.get(`${v}:b`)],E=yd([k.right,S.left,x,S.right,k.left,w],1e-6);return{id:Qb(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:E,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function Nn(t,e,n){let r=t.points[e];return pt(r,rt(ot(G(t.points[(e+1)%t.points.length],r)),n))}function De(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=ot(G(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,pt(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeJ(G(e,t.a),ot(G(t.b,t.a)));function Ct(t,e,n){if(!e.wall)return Jb(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:kd(r,Nn(n.room,0,e.offset))}:null}function Jb(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:kd(o,Nn(e,n,r))};return null}function xd(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,u=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),d=i-o-a(h=>u(h,0,o))-a(h=>u(h,0,i)),p=l-s-a(h=>u(h,1,s))-a(h=>u(h,1,l));return[Math.round(d*1e3)/1e3,Math.round(p*1e3)/1e3]}var $d=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function ey(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Sd(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=ey(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=$d([o[0]-s[0],o[1]-s[1]]),[u,d]=$d([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[d*r,-u*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function Nt(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function ty(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(u=>!r.has(u));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(ke(s))>Math.abs(ke(o)))&&(o=s)}return o}function ea(t,e,n,r){let o=fe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?ty(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],u=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(u[1]-l[1])-(l[1]-c[1])*(u[0]-l[0]))>1e-6});return s.length>=3?Sd(s,n):null}function sn(t,e){let n=xe(t),r=Ie(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],u=c(l,-i),d=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[it(t.pitch_a),it(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,S=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,E=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],F=[[0,r.y(0)],[k,x],[S,x],[o,r.y(o)]],O=(j,Ut,$o)=>{if(j==="hip")return{upA:[],upB:[],ridge:y(Ut===l?n.u0+v*$o:n.u1-v*$o),profile:null};if(j==="halfhip"){let D_=y(Ut===l?n.u0+E:n.u1-E);return{upA:[[Ut,k,x]],upB:[[Ut,S,x]],ridge:D_,profile:F}}return{upA:[],upB:[],ridge:y(Ut),profile:T}},P=O(t.ends[0],l,1),C=O(t.ends[1],a,1),B=[[u,d,...C.upA,C.ridge,P.ridge,...[...P.upA].reverse()],[P.ridge,C.ridge,...[...C.upB].reverse(),p,h,...P.upB]],q=[[P.ridge,C.ridge]];for(let[j,Ut,$o]of[[P,u,h],[C,d,p]])j.profile===null?(B.push(j===P?[h,u,j.ridge]:[d,p,j.ridge]),q.push([Ut,j.ridge],[$o,j.ridge])):j.upA.length&&(B.push(j===P?[j.upB[0],j.upA[0],j.ridge]:[j.upA[0],j.upB[0],j.ridge]),q.push([j.upA[0],j.ridge],[j.upB[0],j.ridge]));let we=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Mt=[u,d,...we(C),p,h,...[...we(P)].reverse()];return{faces:B,rim:Mt,ridges:q,gable:T,endProfiles:[P.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[u,d,p,h]],rim:[u,d,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[u,d,w],[d,p,w],[p,h,w],[h,u,w]],rim:[u,d,p,h],ridges:[[u,w],[h,w],[d,w],[p,w]],gable:null}:{faces:[[u,d,x,w],[w,x,p,h],[h,u,w],[d,p,x]],rim:[u,d,p,h],ridges:[[w,x],[u,w],[h,w],[d,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),S=y(n.u0+k),E=y(n.u1-k),T=[l,w,v],F=[l,x,v],O=[a,w,v],P=[a,x,v];return{faces:[[u,d,O,E,S,T],[S,E,P,p,h,F],[F,T,S],[O,P,E]],rim:[u,d,O,P,p,h,F,T],ridges:[[S,E],[T,S],[F,S],[O,E],[P,E]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Pr(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],S=[l,b.vr,b.rh],E=[a,b.vr,b.rh];return{faces:[[u,d,w,v],[v,w,E,S],[S,E,k,x],[x,k,p,h]],rim:[u,d,w,E,k,p,h,x,S,v],ridges:[[S,E],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[u,d,v,b],[b,v,p,h]],rim:[u,d,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Ir(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],u=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(u[1])<1e-9)continue;let d=i[2]-(u[0]*(e-i[0])+u[2]*(n-i[1]))/u[1];r=r===null?d:Math.min(r,d)}return r}function Dr(t,e,n){let r=xe(e),o=t.floors.flatMap(d=>d.rooms.filter(p=>p.points.length>=3&&d.elevation+d.height>e.base+.05)),i=d=>d.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(d=>r.u0+(r.u1-r.u0)*d),a=[.15,.5,.85].map(d=>r.w*d),c=d=>d?0:n,u=(d,p)=>{let h=e.overhang_sides?.[d];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:u("a",c(i(l.map(d=>r.at(d,-s))))),b:u("b",c(i(l.map(d=>r.at(d,r.w+s))))),u0:u("u0",c(i(a.map(d=>r.at(r.u0-s,d))))),u1:u("u1",c(i(a.map(d=>r.at(r.u1+s,d)))))}}var ii=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Md=t=>t.shape==="flat"||t.shape==="parapet",an=t=>Math.round(t*100)/100;function si(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Md(i)||ii(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||ii(s){let[i,s]=e.at(o,e.w/2),[l,a]=zr(t,i,s);return Ir(n,l,a)??r.y(a)}}function na(t,e){if(Md(e))return e;let n=xe(e),r=Ie(e).rh,o=ry(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let u={...e},d=l===n.u1;return e.axis==="x"?u[d?"x1":"x0"]=c:u[d?"z1":"z0"]=c,u}var ra=.14,Rd=t=>t.shape==="flat"||t.shape==="parapet";function oa(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pu+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=zr(s,e,n),g=Math.max(0,s.overhang??r),y=Rd(s)?null:Ir(sn(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Ie(s).y(f))-ra)}return i.length?Math.max(...i):null}function ia(t,e,n){let r=[],o=e+n+ra;for(let i of t.settings.roof.sections??[]){if(i.open||Rd(i)||i.shape==="mansard")continue;let s=xe(i),l=Ie(i),[a,c]=[it(i.pitch_a),it(i.pitch_b)],u=[];a>1e-6&&u.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&u.push(s.w-(o-i.eave_b)/c);for(let d of u)d<=.01||d>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(d)-o)>1e-6||r.push([s.at(s.u0,d),s.at(s.u1,d)])}return r}function sa(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function aa(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationu.rooms.some(d=>d.points.length>=3&&a.some(p=>N(p,d.points))));if(c)return c}return r.at(-1)??n[0]}var vt=t=>Math.round(t*1e3)/1e3;function la(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(u=>N(c,u.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),u=[...new Set(c.flatMap(y=>y.points.map(b=>vt(b[0]))))].sort((y,b)=>y-b),d=[...new Set(c.flatMap(y=>y.points.map(b=>vt(b[1]))))].sort((y,b)=>y-b),p=d.slice(0,-1).map((y,b)=>u.slice(0,-1).map((v,w)=>{let x=[(u[w]+u[w+1])/2,(d[b]+d[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+F,w+1)).every(Boolean);)w++;for(let T=y;T<=w;T++)for(let F=b;F<=v;F++)h[T][F]=!0;let[x,k]=[u[b]-r,u[v+1]+r],[S,E]=[d[y]-r,d[w+1]+r];Math.min(k-x,E-S)<.8||i.push({id:e(i.length),x0:vt(x),z0:vt(S),x1:vt(k),z1:vt(E),shape:"gable",axis:k-x>=E-S?"x":"z",eave_a:vt(g),eave_b:vt(g),pitch_a:n,pitch_b:n,base:vt(g),overhang:null})}s.push(...c)}return i}var Re=Math.PI/180,Ke=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ln=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Bn=t=>Math.hypot(t[0],t[1],t[2]),cn=t=>{let e=Bn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},Ed=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],je=t=>Math.round(t*100)/100,Hr=([t,e],n)=>(Math.atan2(t,-e)/Re-n+720)%360;var Fd=.25;function Td(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function zd(t,e){let n=cn(Ed(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Pd=t=>{let e=cn([-t[0],0,-t[2]]);return[e[0],e[2]]};function wt(t,e,n,r,o,i,s,l){let a=cn(Ke(o,r)),c=cn(Ke(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:zd(a,c),lu:Bn(Ke(o,r)),ls:Bn(Ke(i,r)),pitch:s,span:l,facing:Pd(c)}}function Ad(t,e,n,r,o,i){let s=Bn(Ke(o,r));if(s<.3)return null;let l=cn(Ke(o,r)),a=Ke(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],u=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],d=Bn(u);if(d<.3)return null;let p=cn(u),h=f=>{let g=Math.min(1,Math.max(0,f/d));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:zd(l,p),lu:s,ls:d,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Re,span:h,facing:Pd(p)}}function oy(t,e){let n=xe(t),r=Ie(t),o=(v,w,x)=>{let[k,S]=n.at(v,w);return[k,x,S]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,u=r.y(-i),d=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[Td(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Fd)]}if(t.shape==="pent")return[wt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(l,n.w+s,d),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return iy(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-u);b.push(wt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-d);b.push(wt(`${t.id}:b`,t.id,"b",o(a,n.w+s,d),o(l,n.w+s,d),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Ad(`${t.id}:c`,t.id,"c",o(l,n.w+s,d),o(l,-i,u),o(n.u0+f,r.vr,r.rh)),w=Ad(`${t.id}:d`,t.id,"d",o(a,-i,u),o(a,n.w+s,d),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function iy(t,e,n,r,o,i){let s=Pr(e.w,t.eave_a,t.eave_b,it(t.pitch_a),it(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],u=(f,g)=>Math.atan2(f,g)/Re,d=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&d.push(wt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&d.push(wt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),u(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&d.push(wt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&d.push(wt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),u(s.rh-s.ylb,h-s.vr),c)),d}function ca(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function Z(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>oy(w,Dr(t,w,w.overhang??e.overhang)));let n=ca(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],u=n.elevation+n.height;if(e.type==="flat")return[Td("main",null,s,a,l,c,u+Fd)];let d=l-s>=c-a,p=e.ridge==="short"?!d:d,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Re),g=(w,x,k)=>p?[w,u+k,(a+c)/2+x]:[(s+l)/2+x,u+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[wt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),wt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ge(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=fe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,u]=[l/a,-s/a],d=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:d,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+u*i.right],[s/a,0,l/a],[c,0,u]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-u*i.left],[-s/a,0,-l/a],[-c,0,-u])}}return n}var Oe="ground";function ai(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function li(t,e){let n=(e.rotation??0)*Re,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=ai(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:qc(i,s,l)):e.base??0;return{key:Oe,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function $e(t,e,n=Z(t)){return e.face===Oe?li(t,e):e.face.startsWith("wall:")?Ge(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var ci=1.13,Cr=1.72,Ue=.025,st=.07;function un(t){let e=t.module_w||ci,n=t.module_h||Cr;return t.portrait===!1?[n,e]:[e,n]}function Nr(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function ua(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Re:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Re:Math.min(45,Math.max(0,e.tilt??0))*Re}function Br(t,e){let[,n]=un(e),r=ua(t,e);return t.wall?n*Math.cos(r)+Ue:!t.flat&&r<.001?n+Ue:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Wn(t,e){let[n,r]=un(e),o=Nr(e),i=Math.max(1,...o);return[i*n+(i-1)*Ue,(o.length-1)*Br(t,e)+r*Math.cos(ua(t,e))]}var sy=t=>t.flat&&!t.unbounded&&!t.wall;function Id(t,e){if(!sy(t)||!e.rotation)return null;let n=e.rotation*Re,[r,o]=Wn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function Ze(t,e,n=!1){let[r,o]=un(e),i=ua(t,e),s=o*Math.cos(i),l=Br(t,e),a=Nr(e),c=Math.max(1,...a),u=new Set(e.skip??[]),d=Id(t,e),p=(y,b)=>d?[d.u+(y-d.u)*d.cos-(b-d.s)*d.sin,d.s+(y-d.u)*d.sin+(b-d.s)*d.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[S,T],[E,T],[E,F],[S,F]].every(([O,P])=>f(O,P)))if(t.wall&&i>.001){let O=st+o*Math.sin(i),[P,C]=e.flip?[O,st]:[st,O],B=[h(S,T,P),h(E,T,P),h(E,F,C),h(S,F,C)],q=e.flip?T:F;g.push({corners:B,posts:[S+.05,E-.05].map(we=>[h(we,q,0),h(we,q,O)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let O=st+o*Math.sin(i),P=[h(S,T,st),h(E,T,st),h(E,F,O),h(S,F,O)];g.push({corners:P,posts:[S+.05,E-.05].map(C=>[h(C,F,0),h(C,F,O)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h(S,T,st),h(E,T,st),h(E,F,st),h(S,F,st)],posts:[],cell:x,skipped:k});else{let P=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[F,T]:[T,F],we=[h(S,B,.15),h(E,B,.15),h(E,q,P),h(S,q,P)],Mt=[S+.05,E-.05].flatMap(j=>[[h(j,B,0),h(j,B,.15)],[h(j,q,0),h(j,q,P)]]);g.push({corners:we,posts:Mt,cell:x,skipped:k})}}}),g}function ft(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Wn(t,e),o=Id(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(d,p,h)=>Math.floor(Math.max(p,Math.min(d,h-p))*100+1e-6)/100,[c,u]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(u,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Wr(t,e){let[n,r]=Wn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ui=.78,Vr=1.18,dn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ui,module_h:t.h||Vr});function da(t,e){let n=Ze(t,dn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Lr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function hn(t){let e=t.shape??"brick",n=Lr[e]??Lr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function kt(t,e){let{w:n,d:r}=hn(t),o=e&&!e.flat?Math.cos(e.pitch*Re):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function ha(t,e){let n=kt(e,t),[r,o]=[n.module_w,n.module_h],i=(u,d)=>[t.o[0]+t.eu[0]*u+t.es[0]*d,t.o[1]+t.eu[1]*u+t.es[1]*d,t.o[2]+t.eu[2]*u+t.es[2]*d],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=u=>{let d=Math.hypot(u[0],u[2])||1;return[u[0]/d,u[2]/d]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function pa(t,e){let[n]=un(e);return je((t.lu-(e.cols*n+(e.cols-1)*Ue))/2)}var Kr=.4;function Vn(t,e){let n={id:e,face:t.key,u:0,v:0,rows:1,cols:1,portrait:!0,tilt:t.flat?15:null,flip:!1,entity:null,look:"black"},[r]=un(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*Kr+Ue)/(r+Ue))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*Kr)/Br(t,n))));n.cols>1&&Ze(t,{...n,u:pa(t,n),v:Kr}).lengthl.lu*(1.3+Math.cos((Hr(l.facing,r)-180)*Math.PI/180)),i=Ge(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...Vn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ue)/(Cr+Ue))),s.u=je((i.lu-(s.cols*Cr+(s.cols-1)*Ue))/2),s.v=je(Math.max(0,i.ls-ci-.3)),s}function jr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:Oe,u:je(r),v:je(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Gr(t,e,n){let r=li(t,e),[o,i]=Wn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Re,u=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,d=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:je(u),v:je(d),rotation:(Math.round(n)%360+360)%360}}function Ur(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:je((n+r-ui)/2),v:je(Math.max(0,Math.min(t.ls-Vr,t.ls*.45-Vr/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function Zr(t,e){let n=Lr.brick,[r,o]=t.span(t.ls*.8),i=kt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:je((r+o-n.w)/2),v:je(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Kn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,u=(o*r-i*n)/a;if(u<0||u>t.ls)return null;let[d,p]=t.span(u);return c>=d&&c<=p?{u:c,s:u}:null}function ma(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],u=a>=0&&a<=r.lu;if(u&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};u&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=Kn(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function hi(t,e,n){let r=ln(n,t.n);if(Math.abs(r)<1e-6)return null;let o=ln(Ke(t.o,e),t.n)/r;if(o<=0)return null;let i=Ke([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:ln(i,t.eu),s:ln(i,t.es)}}function ga(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function _a(t,e,n,r){return Ze(t,e).some(i=>{let s=i.corners.map(c=>{let u=Ke(c,t.o);return[ln(u,t.eu),ln(u,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var ay=["n","ne","e","se","s","sw","w","nw"],ba=(t,e)=>ay[Math.round(Hr(t.facing,e)/45)%8];function qr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Hr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Ld=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Dd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Od=t=>typeof t=="string"?t:t[0],pi=t=>typeof t=="string"?tt[t]:t[1],jn=.05,ly=.02,Hd=t=>Math.round(t*1e3)/1e3;function cy(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function Cd(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,u,d,[p,h,f])=>{s.push({id:n(),type:a,x:Hd(c),z:Hd(u),rotation:d,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,u]of Dd[e].rows){let d=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of u){if(p+pi(g)[0]>d-.1)break;h.push(g),p+=pi(g)[0]}let f=c==="start"?jn:c==="end"?d-p-jn:(d-p)/2;for(let g of h){let y=pi(g),b=cy(r,a,f+y[0]/2,y[1]/2+ly);l(Od(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,u,d]of Dd[e].spots){let p=pi(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+jn,r.x1-p[0]/2-jn),g=h(r.z0+i*u,r.z0+p[1]/2+jn,r.z1-p[1]/2-jn);l(Od(a),f,g,d,p)}return s}var uy=30*Math.PI/180,Nd=.05;function ya(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Yr(t){return ya(t).reduce((e,n)=>e+n,0)}function dy(t,e){let n=ya(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let u=l-c,d=s,p=[];for(let h=0;h<=o&&d>1e-9;h++){let f=r[a]-u,g=Math.min(d,f);g>1e-9&&p.push({edge:a,t0:u,t1:u+g}),d-=g,u=0;let y=(a+1)%o;if(d>1e-9&&hy(t,a)>uy)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Gn(t,e){let n=e[0];return n?{from:dy(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function Bt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function wa(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sI("opening")){let s=va(e,r,o);if(!s)return null;let l=Bt(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,u=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),d=[],p=!1;for(let h of t){if(!a.has(h.id)){d.push(h);continue}p||(d.push(...u),p=!0)}return d}var $a=globalThis,ka=$a.__nextfloorBuiltin?.de??{},xa=$a.__nextfloorBuiltin?.en??{};$a.__nextfloorBuiltin??={de:ka,en:xa};var py=()=>typeof $=="object"&&$||{},fy=globalThis,my=fy.__nextfloorTexts??=new Map;function gy(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in py()?e:void 0}function Bd(t){let e=gy(t),n=e===void 0?void 0:my.get(e);return n instanceof Promise?void 0:n}function fi(t,e){return Bd(t)?.[e]}function Se(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:Bd(r)?.[e])??(o?ka:xa)[e]??xa[e]??ka[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var ge=t=>/^(sensor|input_number|number)\./.test(t),mi=t=>/^(binary_sensor|input_boolean)\./.test(t);function Un(t,e){if(!ge(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function _y(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function H(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=_y(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),typeof o?.attributes.symcon_source_entity=="string"&&(s.sourceEntity=o.attributes.symcon_source_entity),s}).sort((n,r)=>n.label.localeCompare(r.label))}function gi(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Wd=[{key:"supply_vsr",label:"Zuluft-VSR",types:[0,1,2],control:!0},{key:"extract_vsr",label:"Abluft-VSR",types:[0,1,2],control:!0},{key:"supply_temperature",label:"Zulufttemperatur",types:[1,2]},{key:"extract_temperature",label:"Ablufttemperatur",types:[1,2]},{key:"reheat",label:"NHR (Nachheizregister)",types:[0,1,2],control:!0},{key:"status",label:"Raumstatus",types:[1]}];function Vd(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),o=e.hvac?.schedules??[],i=H(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
+
`}var nt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function oi(t,e){return(await nt(t,"image/get",{image_id:e})).data}async function Lt(t,e,n){await nt(t,"image/set",{image_id:e,data:n})}async function sd(t){return(await nt(t,"history/list")).snapshots}async function ad(t,e){return(await nt(t,"history/snapshot",e?{name:e}:{})).id}async function ld(t,e){return(await nt(t,"history/get",{snapshot_id:e})).building}async function cd(t,e){await nt(t,"history/delete",{snapshot_id:e})}async function ud(t,e){return(await nt(t,"history/restore",{snapshot_id:e})).revision}var Er=(t,e)=>nt(t,"packs/import",{pack:e});async function dd(t,e){await nt(t,"packs/remove",{pack_id:e})}var hd=t=>nt(t,"backup/export"),pd=(t,e,n)=>nt(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],pt=(t,e)=>[t[0]+e[0],t[1]+e[1]],rt=(t,e)=>[t[0]*e,t[1]*e],ee=(t,e)=>t[0]*e[0]+t[1]*e[1],Me=(t,e)=>t[0]*e[1]-t[1]*e[0],me=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=me(t)||1;return[t[0]/e,t[1]/e]},Zs=t=>[-t[1],t[0]],qs=t=>[t[1],-t[0]];var Wb=.05,Vb=.2,Kb=.12;function jb(t){let e=[];return t.forEach((n,r)=>{let o=n.points;if(o.length<3)return;let i=_e(o)>=0;o.forEach((s,l)=>{let a=o[(l+1)%o.length],c=me(G(a,s));if(c<.05)return;let u=[(a[0]-s[0])/c,(a[1]-s[1])/c],d=i?[u[1],-u[0]]:[-u[1],u[0]];(u[1]<-1e-9||Math.abs(u[1])<=1e-9&&u[0]<0)&&(u=[-u[0],-u[1]]);let p=[-u[1],u[0]],[h,f]=[ee(s,u),ee(a,u)];e.push({room:r,index:l,dir:u,normal:p,offset:ee(s,p),outside:ee(d,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function Gb(t,e,n){if(t.room===e.room||Math.abs(Me(t.dir,e.dir))>Wb||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Kb||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function fd(t,e=.6){let n=jb(t),r=n.map((g,y)=>y),o=g=>r[g]===g?g:r[g]=o(r[g]),i=[],s=new Set,l=[];for(let g=0;gMath.abs(g[2])-Math.abs(y[2]));let a=new Map(n.map((g,y)=>[y,[y]])),c=(g,y)=>g.some(b=>y.some(v=>n[b].room===n[v].room&&Math.abs(n[b].offset-n[v].offset)>=.002));for(let[g,y,b]of l){let[v,w]=[o(g),o(y)];if(v!==w){if(c(a.get(v),a.get(w)))continue;r[v]=w,a.set(w,[...a.get(w),...a.get(v)]),a.delete(v)}i.push(Ys(b)),s.add(g).add(y)}let u=new Map(n.map((g,y)=>[`${g.room}:${g.index}`,y]));for(let g=s.size>0;g;)g=!1,n.forEach((y,b)=>{let v=u.get(`${y.room}:${(y.index+1)%t[y.room].points.length}`);if(v===void 0||v===b)return;let w=n[v];!(Math.abs(Me(y.dir,w.dir))<1e-6&&Math.abs(y.offset-w.offset)<.002&&y.outside===w.outside)||s.has(b)===s.has(v)||(s.add(b).add(v),g=!0)});n.forEach((g,y)=>{let b=u.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(b===void 0||b===y||!s.has(y)||!s.has(b))return;let v=n[b];Math.abs(Me(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[o(y)]=o(b))});let d=()=>t.map(g=>({...g,points:g.points.map(y=>[y[0],y[1]])}));if(i.length===0)return{rooms:d(),gaps:i};let p=new Map;for(let g of s)p.set(o(g),[...p.get(o(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,y]of p){let b=new Map(y.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...b.values()].reduce((w,x)=>w+x,0)/b.size;for(let w of y){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,y)=>({...g,points:g.points.map((b,v)=>{let w=[...h[y][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[b[0],b[1]]);return[Ys(w[0]),Ys(w[1])]})})),gaps:i}}function md(t){let e=t.filter(n=>n>.04).sort((n,r)=>n-r);return e.length===0?null:Math.min(.5,Math.max(.08,Math.round(e[Math.floor(e.length/2)]*100)/100))}var Ub=.25,gd=t=>Math.round(t*1e3)/1e3,_d=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&N([e,n],r.points));function Qs(t,e,n,r,o){let i=_d(t,e,n);if(!i)return[r,o];let s=(l,a)=>N([l,a],i.points);return s(r,o)?[r,o]:s(r,n)?[r,n]:s(e,o)?[e,o]:[e,n]}function Zb(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(ee(G(i,n),r))<.02&&Math.abs(ee(G(l,n),r))<.02}))}var Xs=(t,e)=>Math.abs((t-e+540)%360-180);function Ar(t,e,n,r=Ub){let o=_d(t,e.x,e.z);if(!o)return null;let i=o.points,s=_e(i)>=0?1:-1,l=null;return i.forEach((a,c)=>{let u=i[(c+1)%i.length],d=me(G(u,a));if(d<.3)return;let p=[(u[0]-a[0])/d,(u[1]-a[1])/d],h=[-p[1]*s,p[0]*s],f=ee(G([e.x,e.z],a),p);if(f<0||f>d)return;let g=Zb(t,o,a,h)?n/2:0,y=ee(G([e.x,e.z],a),h)-g,b=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:b,extent:e.d/2},{rotation:b+90,extent:e.w/2},{rotation:b-90,extent:e.w/2}].reduce((k,S)=>Xs(e.rotation,S.rotation)50)return;let x=y-w.extent;Math.abs(x)>r||l&&Math.abs(x)>=Math.abs(l.gap)||(l={x:gd(e.x-h[0]*x),z:gd(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),l&&{x:l.x,z:l.z,rotation:l.rotation}}var Cn=Math.PI/180,it=t=>Math.tan(Math.min(80,Math.max(0,t))*Cn);function Tr(t){return{x0:Math.min(t.x0,t.x1),x1:Math.max(t.x0,t.x1),z0:Math.min(t.z0,t.z1),z1:Math.max(t.z0,t.z1)}}function bd(t){if(!t.rotation)return null;let e=t.rotation*Cn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function yd(t,e){let n=bd(t);if(!n)return e;let[r,o]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-o*n.sn,n.cz+r*n.sn+o*n.c]}function Js(t,e,n){let r=bd(t);if(!r)return[e,n];let[o,i]=[e-r.cx,n-r.cz];return[r.cx+o*r.c+i*r.sn,r.cz-o*r.sn+i*r.c]}function zr(t,e=0){let{x0:n,x1:r,z0:o,z1:i}=Tr(t);return[[n-e,o-e],[r+e,o-e],[r+e,i+e],[n-e,i+e]].map(s=>yd(t,s))}function xe(t){let{x0:e,x1:n,z0:r,z1:o}=Tr(t),i=s=>yd(t,s);return t.axis==="x"?{u0:e,u1:n,w:o-r,at:(s,l)=>i([s,t.flip?o-l:r+l])}:{u0:r,u1:o,w:n-e,at:(s,l)=>i([t.flip?n-l:e+l,s])}}function Pr(t,e,n){let{x0:r,x1:o,z0:i,z1:s}=Tr(t),[l,a]=Js(t,e,n);return t.axis==="x"?[l,t.flip?s-a:a-i]:[a,t.flip?o-l:l-r]}var Fr=Math.tan(30*Cn);function Ir(t,e,n,r,o){let i=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,o>1e-6?2.4/o:t*.3),l=e+i*r,a=n+s*o,c=Math.min(t-s,Math.max(i,(a-l+Fr*(t-s+i))/(2*Fr))),u=l+(c-i)*Fr;return{vla:i,vlb:s,yla:l,ylb:a,vr:c,rh:u,y:p=>p<=i?e+p*r:p<=c?l+(p-i)*Fr:p<=t-s?a+(t-s-p)*Fr:n+(t-p)*o}}function Ie(t){let e=xe(t).w,[n,r]=[t.eave_a,t.eave_b],[o,i]=[it(t.pitch_a),it(t.pitch_b)];switch(t.shape){case"flat":case"parapet":return{vr:e/2,rh:n,y:()=>n};case"pent":return{vr:e,rh:n+e*o,y:s=>n+s*o};case"mansard":{let s=Ir(e,n,r,o,i);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=o+i>1e-6?Math.min(e,Math.max(0,(r-n+e*i)/(o+i))):e/2;return{vr:s,rh:n+s*o,y:l=>l<=s?n+l*o:r+(e-l)*i}}}}var on=t=>Ie(t).rh;function vd(t){let e=t.heightEnd!==void 0;return{...t,a:t.b,b:t.a,left:t.right,right:t.left,roomLeft:t.roomRight,roomRight:t.roomLeft,height:e?t.heightEnd:t.height,heightEnd:e?t.height:void 0}}function qb(t,e){let n=t.map(r=>({...r}));for(let r of e){let o=n.find(i=>i.room_id===r.room_id&&i.edge===r.edge&&(Math.abs(i.t1-r.t0)<1e-6||Math.abs(r.t1-i.t0)<1e-6));o?(o.t0=Math.min(o.t0,r.t0),o.t1=Math.max(o.t1,r.t1)):n.push({...r})}return n}function Yb(t,e,n){if(t.a===e.b)return!1;let r=ot(G(n[t.b],n[t.a])),o=ot(G(n[e.b],n[e.a]));return Math.abs(Me(r,o))>1e-6||ee(r,o)<=0||t.free||e.free||t.heightEnd!==void 0||e.heightEnd!==void 0?!1:t.height===e.height&&t.exterior===e.exterior&&t.roomLeft===e.roomLeft&&t.roomRight===e.roomRight&&Math.abs(t.left-e.left)<=1e-9&&Math.abs(t.right-e.right)<=1e-9}function wd(t,e,n=new Set){let r=t.slice();for(;;){let o=new Map;r.forEach((s,l)=>{for(let a of[s.a,s.b])o.set(a,[...o.get(a)??[],l])});let i=null;for(let[s,l]of o){if(l.length!==2||n.has(s))continue;let a=r[l[0]].b===s?r[l[0]]:vd(r[l[0]]),c=r[l[1]].a===s?r[l[1]]:vd(r[l[1]]);if(!Yb(a,c,e))continue;let u={...a,b:c.b,sources:qb(a.sources,c.sources)};i=[...r.filter((d,p)=>p!==l[0]&&p!==l[1]),u];break}if(!i)return r;r=i}}function kd(t,e){let n=new Map;t.forEach((o,i)=>{let s=ot(G(e[o.b],e[o.a])),l=[[o.a,{key:`${i}:a`,d:s,left:o.left,right:o.right,angle:Math.atan2(s[1],s[0])}],[o.b,{key:`${i}:b`,d:rt(s,-1),left:o.right,right:o.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[a,c]of l)n.set(a,[...n.get(a)??[],c])});let r=new Map;for(let[o,i]of n){let s=e[o];i.sort((a,c)=>a.angle-c.angle);for(let a of i)r.set(a.key,{left:pt(s,rt(Zs(a.d),a.left)),right:pt(s,rt(qs(a.d),a.right))});if(i.length<2)continue;let l=4*Math.max(...i.map(a=>Math.max(a.left,a.right)))+1e-9;i.forEach((a,c)=>{let u=i[(c+1)%i.length],d=pt(s,rt(Zs(a.d),a.left)),p=pt(s,rt(qs(u.d),u.right)),h=Me(a.d,u.d);if(Math.abs(h)<1e-4)return;let f=pt(d,rt(a.d,Me(G(p,d),u.d)/h));me(G(f,s))>l||(r.get(a.key).left=f,r.get(u.key).right=f)})}return r}function xd(t,e){let n=t.filter((r,o)=>me(G(r,t[(o+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((o,i)=>{let s=n[(i+n.length-1)%n.length],l=n[(i+1)%n.length],[a,c]=[G(o,s),G(l,o)];return Math.abs(Me(ot(a),ot(c)))<1e-7&&ee(a,c)>0});if(r===-1)return n;n=n.filter((o,i)=>i!==r)}}function Xb(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(o=>Math.abs(o[0]-n[0])<=t&&Math.abs(o[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function Qb(t,e){let n=[];for(let r of t){let o=r.points;if(o.length<3||Math.abs(_e(o))<1e-6)continue;let i=_e(o)>0,s=o.map(l=>e.idOf(l));s.forEach((l,a)=>{let c=s[(a+1)%s.length];l!==c&&n.push(i?{u:l,v:c,room:r.id,edge:a,forward:!0}:{u:c,v:l,room:r.id,edge:a,forward:!1})})}return n}function Jb(t,e,n){let r=[];for(let o of t){let[i,s]=[e[o.u],e[o.v]],l=G(s,i),a=me(l),c=rt(l,1/a),u=e.map((p,h)=>({id:h,rel:G(p,i)})).filter(({id:p,rel:h})=>p!==o.u&&p!==o.v&&ee(h,c)>n&&ee(h,c)({t:ee(h,c),id:p})).sort((p,h)=>p.t-h.t),d=[{t:0,id:o.u},...u,{t:a,id:o.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function ey(t,e){let n=new Map(t.map(l=>[l.id,l])),r=new Map;for(let l of e){let a=`${l.room}:${l.edge}`;r.set(a,[...r.get(a)??[],l.t0].sort((c,u)=>c-u))}let o=l=>{let a=n.get(l.room)?.wall_heights?.[l.edge];return Array.isArray(a)?a[(r.get(`${l.room}:${l.edge}`)??[]).indexOf(l.t0)]??null:a},i=l=>{let a=n.get(l.room),[c,u]=[a?.wall_heights?.[l.edge],a?.wall_slopes?.[l.edge]];if(!a||typeof c!="number"||typeof u!="number"||c<=0||u<=0)return null;let[d,p]=[a.points[l.edge],a.points[(l.edge+1)%a.points.length]];return{from:c,to:u,length:Math.hypot(p[0]-d[0],p[1]-d[1])}},s=l=>{let a=i(l);if(!a||a.length<1e-9){let u=o(l);return typeof u=="number"&&u>0?[u,u]:[null,null]}let c=u=>a.from+(a.to-a.from)*u/a.length;return l.forward?[c(l.t0),c(l.t1)]:[c(l.t1),c(l.t0)]};return{heightsOf(l){let[a,c]=[1/0,1/0];for(let d of l){let[p,h]=s(d),[f,g]=d===l[0]?[p,h]:[h,p];f!==null&&(a=Math.min(a,f)),g!==null&&(c=Math.min(c,g))}let u=l.map(d=>n.get(d.room)?.ceiling);if(u.every(d=>typeof d=="number"&&d>0)){let d=Math.max(...u);a===1/0&&(a=d),c===1/0&&(c=d)}return{...a<1/0?{a}:{},...c<1/0?{b:c}:{}}},thicknessOf(l){let a=l.map(c=>{let u=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(u)?u[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:u}).filter(c=>typeof c=="number"&&c>0);return a.length?Math.max(...a):void 0},hasNoWall:l=>l.some(a=>o(a)===0)}}function Sd(t){let e=n=>Math.round(n*1e6)/1e6;return t.a===void 0||t.b===void 0?t.a!==void 0?{height:e(t.a)}:t.b!==void 0?{height:e(t.b)}:{}:Math.abs(t.a-t.b)<1e-6?{height:e(t.a)}:{height:e(t.a),heightEnd:e(t.b)}}function ty(t,e,n,r){let o=ey(e,t),i=new Map;for(let a of t){let c=a.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of a)p!==c&&p!==u&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let d=u?[c,u]:[c];if(o.hasNoWall(d)){u&&l.push([c.room,u.room]);continue}if(u){let p=o.thicknessOf(d)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:u.room,sources:d.map($d),...Sd(o.heightsOf(d))})}else s.push({a:c.u,b:c.v,left:0,right:o.thicknessOf(d)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[$d(c)],...Sd(o.heightsOf(d))})}return{drafts:s,open:l}}function ny(t,e){let n=i=>ot(G(e[i.b],e[i.a])),r=t.filter(i=>!i.exterior&&!i.free),o=new Map;for(let i of r){if(o.has(i))continue;let s=[i];o.set(i,s);for(let l=0;l1e-6||a.add(ee(s,h)>0?"left":"right")}if(a.size!==1)continue;let c=[...a][0];for(let u of i){let d=u.left+u.right,p=ee(n(u),s)>0,h=c==="left"===p;[u.left,u.right]=h?[0,d]:[d,0]}}}var ry=(t,e)=>{let n=i=>Math.round(i*100),[r,o]=t[0]Math.hypot(b.b[0]-b.a[0],b.b[1]-b.a[1])>.05),a=l.map(b=>[i.idOf(b.a),i.idOf(b.b)]),c=new Set;for(let b of t){let v=b.points;v.length<3||(b.wall_splits??[]).forEach((w,x)=>{if(!w||x>=v.length)return;let k=v[x],S=G(v[(x+1)%v.length],k),E=me(S);for(let T of w)T>r&&T{let[w,x]=a[v];if(w===x)return;let k=[(b.a[0]+b.b[0])/2,(b.a[1]+b.b[1])/2],S=t.find(T=>T.points.length>=3&&N(k,T.points))?.id??null,E=(b.thickness??e.interior)/2;h.push({free:b.id,a:w,b:x,left:E,right:E,exterior:!1,roomLeft:S,roomRight:S,sources:[],height:typeof b.height=="number"&&b.height>0?b.height:void 0,...typeof b.height=="number"&&b.height>0&&typeof b.height_end=="number"&&b.height_end>0&&Math.abs(b.height_end-b.height)>1e-6?{heightEnd:b.height_end}:{}})});let f=wd(h,i.points,c),g=kd(f,i.points);return{walls:f.map((b,v)=>{let[w,x]=[i.points[b.a],i.points[b.b]],[k,S]=[g.get(`${v}:a`),g.get(`${v}:b`)],E=xd([k.right,S.left,x,S.right,k.left,w],1e-6);return{id:ry(w,x),a:[w[0],w[1]],b:[x[0],x[1]],left:b.left,right:b.right,exterior:b.exterior,roomLeft:b.roomLeft,roomRight:b.roomRight,sources:b.sources,footprint:E,...b.free?{free:b.free}:{},...b.height!==void 0?{height:b.height}:{},...b.heightEnd!==void 0?{heightEnd:b.heightEnd}:{}}}),warnings:[...new Set(o)],open:p}}function Nn(t,e,n){let r=t.points[e];return pt(r,rt(ot(G(t.points[(e+1)%t.points.length],r)),n))}function De(t,e,n){if(t.wall){let o=n.find(l=>l.id===t.wall);if(!o||Math.hypot(o.b[0]-o.a[0],o.b[1]-o.a[1])<.05)return null;let i=ot(G(o.b,o.a));return{room:{id:t.room_id,name:"",area_id:null,points:[o.a,o.b,pt(o.a,[-i[1],i[0]])]},edge:0}}let r=e.find(o=>o.id===t.room_id);return r&&t.edgeee(G(e,t.a),ot(G(t.b,t.a)));function Ct(t,e,n){if(!e.wall)return oy(t,n.room,n.edge,e.offset);let r=t.find(o=>o.free===e.wall);return r?{wall:r,s:Md(r,Nn(n.room,0,e.offset))}:null}function oy(t,e,n,r){for(let o of t)if(o.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:o,s:Md(o,Nn(e,n,r))};return null}function Rd(t,e){let n=t.points.map(h=>h[0]),r=t.points.map(h=>h[1]);if(t.points.length!==4||new Set(n.map(h=>h.toFixed(3))).size!==2||new Set(r.map(h=>h.toFixed(3))).size!==2)return null;let[o,i,s,l]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],a=h=>Math.max(0,...e.filter(f=>(f.roomLeft===t.id||f.roomRight===t.id)&&h(f)).map(f=>f.roomLeft===t.id?f.left:f.right)),c=(h,f)=>Math.abs(h-f)<.001,u=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),d=i-o-a(h=>u(h,0,o))-a(h=>u(h,0,i)),p=l-s-a(h=>u(h,1,s))-a(h=>u(h,1,l));return[Math.round(d*1e3)/1e3,Math.round(p*1e3)/1e3]}var Ed=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function iy(t){return t.reduce((e,n,r)=>e+(n[0]*t[(r+1)%t.length][1]-t[(r+1)%t.length][0]*n[1]),0)/2}function Ad(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([o,i])=>[o,i]);let r=iy(t)>=0?1:-1;return t.map((o,i)=>{let s=t[(i+n-1)%n],l=t[(i+1)%n],[a,c]=Ed([o[0]-s[0],o[1]-s[1]]),[u,d]=Ed([l[0]-o[0],l[1]-o[1]]),p=[c*r,-a*r],h=[d*r,-u*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[o[0]+p[0]*e,o[1]+p[1]*e];let y=(f[0]*p[0]+f[1]*p[1])/g,b=Math.min(4,1/Math.max(.25,y));return[o[0]+f[0]/g*e*b,o[1]+f[1]/g*e*b]})}function Nt(t){let e=t.map(r=>r[0]),n=t.map(r=>r[1]);return{x0:Math.min(...e),z0:Math.min(...n),x1:Math.max(...e),z1:Math.max(...n)}}function sy(t){let e=([i,s])=>`${Math.round(i*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let i of t)for(let s of[i.a,i.b])n.set(e(s),[...n.get(e(s))??[],i]);let r=new Set,o=null;for(let i of t){if(r.has(i))continue;r.add(i);let s=[i.a,i.b],l=i.b;for(;;){let c=(n.get(e(l))??[]).find(u=>!r.has(u));if(!c||(r.add(c),l=e(c.a)===e(l)?c.b:c.a,e(l)===e(s[0])))break;s.push(l)}s.length>=3&&e(l)===e(s[0])&&(!o||Math.abs(ke(s))>Math.abs(ke(o)))&&(o=s)}return o}function ea(t,e,n,r){let o=fe(t,{exterior:n,interior:r},e).walls.filter(l=>l.exterior&&!l.free),i=o.length?sy(o.map(l=>({a:l.a,b:l.b}))):null;if(!i)return null;let s=i.filter((l,a)=>{let c=i[(a+i.length-1)%i.length],u=i[(a+1)%i.length];return Math.abs((l[0]-c[0])*(u[1]-l[1])-(l[1]-c[1])*(u[0]-l[0]))>1e-6});return s.length>=3?Ad(s,n):null}function sn(t,e){let n=xe(t),r=Ie(t),o=n.w,[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=(b,v)=>[b,v,r.y(v)],u=c(l,-i),d=c(a,-i),p=c(a,o+s),h=c(l,o+s),[f,g]=[it(t.pitch_a),it(t.pitch_b)],y=b=>[b,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let b=(n.u1-n.u0)/2,v=Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=Math.min(r.y(0),r.y(o)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,S=g>1e-6?Math.max(r.vr,o-(x-t.eave_b)/g):r.vr,E=Math.min(b-.1,(r.rh-x)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]],F=[[0,r.y(0)],[k,x],[S,x],[o,r.y(o)]],O=(j,Ut,$o)=>{if(j==="hip")return{upA:[],upB:[],ridge:y(Ut===l?n.u0+v*$o:n.u1-v*$o),profile:null};if(j==="halfhip"){let N_=y(Ut===l?n.u0+E:n.u1-E);return{upA:[[Ut,k,x]],upB:[[Ut,S,x]],ridge:N_,profile:F}}return{upA:[],upB:[],ridge:y(Ut),profile:T}},P=O(t.ends[0],l,1),C=O(t.ends[1],a,1),B=[[u,d,...C.upA,C.ridge,P.ridge,...[...P.upA].reverse()],[P.ridge,C.ridge,...[...C.upB].reverse(),p,h,...P.upB]],q=[[P.ridge,C.ridge]];for(let[j,Ut,$o]of[[P,u,h],[C,d,p]])j.profile===null?(B.push(j===P?[h,u,j.ridge]:[d,p,j.ridge]),q.push([Ut,j.ridge],[$o,j.ridge])):j.upA.length&&(B.push(j===P?[j.upB[0],j.upA[0],j.ridge]:[j.upA[0],j.upB[0],j.ridge]),q.push([j.upA[0],j.ridge],[j.upB[0],j.ridge]));let we=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Mt=[u,d,...we(C),p,h,...[...we(P)].reverse()];return{faces:B,rim:Mt,ridges:q,gable:T,endProfiles:[P.profile,C.profile]}}switch(t.shape){case"pent":return{faces:[[u,d,p,h]],rim:[u,d,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[o,r.y(o)]]};case"hip":case"pyramid":{let b=(n.u1-n.u0)/2,v=t.shape==="pyramid"?b:Math.min(b,Math.min(r.vr,o-r.vr)||o/2),w=y(n.u0+v),x=y(n.u1-v);return t.shape==="pyramid"?{faces:[[u,d,w],[d,p,w],[p,h,w],[h,u,w]],rim:[u,d,p,h],ridges:[[u,w],[h,w],[d,w],[p,w]],gable:null}:{faces:[[u,d,x,w],[w,x,p,h],[h,u,w],[d,p,x]],rim:[u,d,p,h],ridges:[[w,x],[u,w],[h,w],[d,x],[p,x]],gable:null}}case"halfhip":{let b=Math.min(r.y(0),r.y(o)),v=b+(r.rh-b)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,x=g>1e-6?Math.max(r.vr,o-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),S=y(n.u0+k),E=y(n.u1-k),T=[l,w,v],F=[l,x,v],O=[a,w,v],P=[a,x,v];return{faces:[[u,d,O,E,S,T],[S,E,P,p,h,F],[F,T,S],[O,P,E]],rim:[u,d,O,P,p,h,F,T],ridges:[[S,E],[T,S],[F,S],[O,E],[P,E]],gable:[[0,r.y(0)],[w,v],[x,v],[o,r.y(o)]]}}case"mansard":{let b=Ir(o,t.eave_a,t.eave_b,f,g),v=[l,b.vla,b.yla],w=[a,b.vla,b.yla],x=[l,o-b.vlb,b.ylb],k=[a,o-b.vlb,b.ylb],S=[l,b.vr,b.rh],E=[a,b.vr,b.rh];return{faces:[[u,d,w,v],[v,w,E,S],[S,E,k,x],[x,k,p,h]],rim:[u,d,w,E,k,p,h,x,S,v],ridges:[[S,E],[v,w],[x,k]],gable:[[0,r.y(0)],[b.vla,b.yla],[b.vr,b.rh],[o-b.vlb,b.ylb],[o,r.y(o)]]}}default:{let b=y(l),v=y(a);return{faces:[[u,d,v,b],[b,v,p,h]],rim:[u,d,v,p,h,b],ridges:[[b,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[o,r.y(o)]]}}}}function Dr(t,e,n){let r=null;for(let o of t.faces){if(!N([e,n],o.map(([p,h])=>[p,h])))continue;let[i,s]=o,l=o.slice(2).find(p=>Math.abs((s[0]-i[0])*(p[1]-i[1])-(s[1]-i[1])*(p[0]-i[0]))>1e-9);if(!l)continue;let a=[s[0]-i[0],s[2]-i[2],s[1]-i[1]],c=[l[0]-i[0],l[2]-i[2],l[1]-i[1]],u=[a[1]*c[2]-a[2]*c[1],a[2]*c[0]-a[0]*c[2],a[0]*c[1]-a[1]*c[0]];if(Math.abs(u[1])<1e-9)continue;let d=i[2]-(u[0]*(e-i[0])+u[2]*(n-i[1]))/u[1];r=r===null?d:Math.min(r,d)}return r}function Or(t,e,n){let r=xe(e),o=t.floors.flatMap(d=>d.rooms.filter(p=>p.points.length>=3&&d.elevation+d.height>e.base+.05)),i=d=>d.some(p=>o.some(h=>N(p,h.points))),s=.35,l=[.15,.5,.85].map(d=>r.u0+(r.u1-r.u0)*d),a=[.15,.5,.85].map(d=>r.w*d),c=d=>d?0:n,u=(d,p)=>{let h=e.overhang_sides?.[d];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:u("a",c(i(l.map(d=>r.at(d,-s))))),b:u("b",c(i(l.map(d=>r.at(d,r.w+s))))),u0:u("u0",c(i(a.map(d=>r.at(r.u0-s,d))))),u1:u("u1",c(i(a.map(d=>r.at(r.u1+s,d)))))}}var ii=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),Fd=t=>t.shape==="flat"||t.shape==="parapet",an=t=>Math.round(t*100)/100;function si(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(i=>{if(i===e||i.dormer||i.open||Fd(i)||ii(i)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((i,s)=>i===null||ii(s){let[i,s]=e.at(o,e.w/2),[l,a]=Pr(t,i,s);return Dr(n,l,a)??r.y(a)}}function na(t,e){if(Fd(e))return e;let n=xe(e),r=Ie(e).rh,o=ly(t,n),i=o(n.u0)<=o(n.u1),[s,l]=i?[n.u0,n.u1]:[n.u1,n.u0],a=i?1:-1,c=l;for(let p=.5;p=r-.02){c=s+a*p;break}if(Math.abs(c-l)<.05)return e;let u={...e},d=l===n.u1;return e.axis==="x"?u[d?"x1":"x0"]=c:u[d?"z1":"z0"]=c,u}var ra=.14,Td=t=>t.shape==="flat"||t.shape==="parapet";function oa(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)a+o||pu+o||s.points&&s.points.length>=3&&!N([e,n],s.points))continue;let[h,f]=Pr(s,e,n),g=Math.max(0,s.overhang??r),y=Td(s)?null:Dr(sn(s,{u0:g,u1:g,a:g,b:g}),h,f);i.push((y??Ie(s).y(f))-ra)}return i.length?Math.max(...i):null}function ia(t,e,n){let r=[],o=e+n+ra;for(let i of t.settings.roof.sections??[]){if(i.open||Td(i)||i.shape==="mansard")continue;let s=xe(i),l=Ie(i),[a,c]=[it(i.pitch_a),it(i.pitch_b)],u=[];a>1e-6&&u.push((o-i.eave_a)/a),i.shape==="gable"&&c>1e-6&&u.push(s.w-(o-i.eave_b)/c);for(let d of u)d<=.01||d>=s.w-.01||i.shape==="gable"&&Math.abs(l.y(d)-o)>1e-6||r.push([s.at(s.u0,d),s.at(s.u1,d)])}return r}function sa(t,e,n,r,o){let i=[];for(let l of[.2,.5,.8])for(let a of[.2,.5,.8])i.push([e+(r-e)*l,n+(o-n)*a]);let s=t.floors.filter(l=>l.rooms.some(a=>a.points.length>=3&&i.some(c=>N(c,a.points)))).map(l=>l.elevation+l.height);return s.length?Math.max(...s):null}function aa(t,e){let n=t.floors.filter(a=>a.rooms.length>0).sort((a,c)=>a.elevation-c.elevation),r=n.filter(a=>a.elevationu.rooms.some(d=>d.points.length>=3&&a.some(p=>N(p,d.points))));if(c)return c}return r.at(-1)??n[0]}var vt=t=>Math.round(t*1e3)/1e3;function la(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,o=t.floors.filter(a=>a.rooms.some(c=>c.points.length>=3)).sort((a,c)=>c.elevation-a.elevation),i=[],s=[],l=(a,c)=>a.some(u=>N(c,u.points));for(let a of o){let c=a.rooms.filter(y=>y.points.length>=3),u=[...new Set(c.flatMap(y=>y.points.map(b=>vt(b[0]))))].sort((y,b)=>y-b),d=[...new Set(c.flatMap(y=>y.points.map(b=>vt(b[1]))))].sort((y,b)=>y-b),p=d.slice(0,-1).map((y,b)=>u.slice(0,-1).map((v,w)=>{let x=[(u[w]+u[w+1])/2,(d[b]+d[b+1])/2];return l(c,x)&&!l(s,x)})),h=p.map(y=>y.map(()=>!1)),f=(y,b)=>p[b][y]&&!h[b][y],g=a.elevation+a.height;for(let y=0;yf(b+F,w+1)).every(Boolean);)w++;for(let T=y;T<=w;T++)for(let F=b;F<=v;F++)h[T][F]=!0;let[x,k]=[u[b]-r,u[v+1]+r],[S,E]=[d[y]-r,d[w+1]+r];Math.min(k-x,E-S)<.8||i.push({id:e(i.length),x0:vt(x),z0:vt(S),x1:vt(k),z1:vt(E),shape:"gable",axis:k-x>=E-S?"x":"z",eave_a:vt(g),eave_b:vt(g),pitch_a:n,pitch_b:n,base:vt(g),overhang:null})}s.push(...c)}return i}var Re=Math.PI/180,Ke=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],ln=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Bn=t=>Math.hypot(t[0],t[1],t[2]),cn=t=>{let e=Bn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},zd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],je=t=>Math.round(t*100)/100,Lr=([t,e],n)=>(Math.atan2(t,-e)/Re-n+720)%360;var Id=.25;function Dd(t,e,n,r,o,i,s){let l=o-n>=i-r,a=l?o-n:i-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:l?[1,0,0]:[0,0,1],es:l?[0,0,1]:[1,0,0],n:[0,1,0],lu:a,ls:l?i-r:o-n,pitch:0,span:()=>[0,a],facing:l?[0,1]:[1,0]}}function Od(t,e){let n=cn(zd(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Hd=t=>{let e=cn([-t[0],0,-t[2]]);return[e[0],e[2]]};function wt(t,e,n,r,o,i,s,l){let a=cn(Ke(o,r)),c=cn(Ke(i,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:c,n:Od(a,c),lu:Bn(Ke(o,r)),ls:Bn(Ke(i,r)),pitch:s,span:l,facing:Hd(c)}}function Pd(t,e,n,r,o,i){let s=Bn(Ke(o,r));if(s<.3)return null;let l=cn(Ke(o,r)),a=Ke(i,r),c=a[0]*l[0]+a[1]*l[1]+a[2]*l[2],u=[a[0]-l[0]*c,a[1]-l[1]*c,a[2]-l[2]*c],d=Bn(u);if(d<.3)return null;let p=cn(u),h=f=>{let g=Math.min(1,Math.max(0,f/d));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:p,n:Od(l,p),lu:s,ls:d,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Re,span:h,facing:Hd(p)}}function cy(t,e){let n=xe(t),r=Ie(t),o=(v,w,x)=>{let[k,S]=n.at(v,w);return[k,x,S]},[i,s]=[Math.max(0,e.a),Math.max(0,e.b)],l=n.u0-Math.max(0,e.u0),a=n.u1+Math.max(0,e.u1),c=a-l,u=r.y(-i),d=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(l,-i),n.at(a,n.w+s)];return[Dd(t.id,t.id,Math.min(v[0],w[0]),Math.min(v[1],w[1]),Math.max(v[0],w[0]),Math.max(v[1],w[1]),t.eave_a+Id)]}if(t.shape==="pent")return[wt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(l,n.w+s,d),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return uy(t,n,l,a,i,s);let p=t.shape==="hip"||t.shape==="pyramid",h=(n.u1-n.u0)/2,f=t.shape==="pyramid"?h:p?Math.min(h,Math.min(r.vr,n.w-r.vr)||n.w/2):0,g=p?n.u0+f-l:0,y=p?a-(n.u1-f):0,b=[];if(r.vr>.3){let v=Math.hypot(r.vr+i,r.rh-u);b.push(wt(`${t.id}:a`,t.id,"a",o(l,-i,u),o(a,-i,u),o(l,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-y*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-d);b.push(wt(`${t.id}:b`,t.id,"b",o(a,n.w+s,d),o(l,n.w+s,d),o(a,r.vr,r.rh),t.pitch_b,w=>[y*(w/v),c-g*(w/v)]))}if(p){let v=Pd(`${t.id}:c`,t.id,"c",o(l,n.w+s,d),o(l,-i,u),o(n.u0+f,r.vr,r.rh)),w=Pd(`${t.id}:d`,t.id,"d",o(a,-i,u),o(a,n.w+s,d),o(n.u1-f,r.vr,r.rh));b.push(...[v,w].filter(x=>x!==null))}return b}function uy(t,e,n,r,o,i){let s=Ir(e.w,t.eave_a,t.eave_b,it(t.pitch_a),it(t.pitch_b)),l=(f,g)=>{let[y,b]=e.at(f,g);return[y,s.y(g),b]},a=r-n,c=()=>[0,a],u=(f,g)=>Math.atan2(f,g)/Re,d=[],[p,h]=[e.w+i,e.w-s.vlb];return s.vla+o>.3&&d.push(wt(`${t.id}:a`,t.id,"a",l(n,-o),l(r,-o),l(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&d.push(wt(`${t.id}:au`,t.id,"a",l(n,s.vla),l(r,s.vla),l(n,s.vr),u(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+i>.3&&d.push(wt(`${t.id}:b`,t.id,"b",l(r,p),l(n,p),l(r,h),t.pitch_b,c)),h-s.vr>.3&&d.push(wt(`${t.id}:bu`,t.id,"b",l(r,h),l(n,h),l(r,s.vr),u(s.rh-s.ylb,h-s.vr),c)),d}function ca(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function Z(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>cy(w,Or(t,w,w.overhang??e.overhang)));let n=ca(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),o=n.rooms.flatMap(w=>w.points.map(x=>x[1])),i=t.settings.wall_exterior+e.overhang,[s,l]=[Math.min(...r)-i,Math.max(...r)+i],[a,c]=[Math.min(...o)-i,Math.max(...o)+i],u=n.elevation+n.height;if(e.type==="flat")return[Dd("main",null,s,a,l,c,u+Id)];let d=l-s>=c-a,p=e.ridge==="short"?!d:d,h=(p?c-a:l-s)/2,f=h*Math.tan(e.pitch*Re),g=(w,x,k)=>p?[w,u+k,(a+c)/2+x]:[(s+l)/2+x,u+k,w],[y,b]=p?[s,l]:[a,c],v=()=>[0,b-y];return[wt("main:a",null,"a",g(y,-h,0),g(b,-h,0),g(y,0,f),e.pitch,v),wt("main:b",null,"b",g(y,h,0),g(b,h,0),g(y,0,f),e.pitch,v)]}function Ge(t,e){let n=[];for(let r of t.floors.filter(o=>!e||o.id===e)){let{walls:o}=fe(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let i of o){if(!i.exterior&&!i.free)continue;let[s,l]=[i.b[0]-i.a[0],i.b[1]-i.a[1]],a=Math.hypot(s,l);if(a<1.2)continue;let[c,u]=[l/a,-s/a],d=Math.min(r.height,i.height??r.height,i.heightEnd??1/0),p=(h,f,g,y)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:y,lu:a,ls:d,pitch:90,span:()=>[0,a],facing:[y[0],y[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${i.id}`,[i.a[0]+c*i.right,r.elevation,i.a[1]+u*i.right],[s/a,0,l/a],[c,0,u]),i.free&&p(`wall:${r.id}:${i.id}:back`,[i.b[0]-c*i.left,r.elevation,i.b[1]-u*i.left],[-s/a,0,-l/a],[-c,0,-u])}}return n}var Oe="ground";function ai(t){let e=t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>n.elevation-r.elevation);return e.find(n=>n.elevation>-.5)??e[0]??t.floors[0]??null}function li(t,e){let n=(e.rotation??0)*Re,r=[Math.cos(n),0,Math.sin(n)],o=[-Math.sin(n),0,Math.cos(n)],i=ai(t),s=r[0]*e.u+o[0]*e.v,l=r[2]*e.u+o[2]*e.v,a=i?i.elevation+(e.base!=null?e.base:Jc(i,s,l)):e.base??0;return{key:Oe,section:null,side:"top",flat:!0,o:[0,a,0],eu:r,es:o,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[o[0],o[2]],unbounded:!0}}function $e(t,e,n=Z(t)){return e.face===Oe?li(t,e):e.face.startsWith("wall:")?Ge(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var ci=1.13,Nr=1.72,Ue=.025,st=.07;function un(t){let e=t.module_w||ci,n=t.module_h||Nr;return t.portrait===!1?[n,e]:[e,n]}function Br(t){return t.layout?.length?t.layout.map(e=>Math.max(0,Math.min(60,Math.round(e)))):Array.from({length:Math.max(1,t.rows)},()=>Math.max(1,t.cols))}function ua(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Re:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Re:Math.min(45,Math.max(0,e.tilt??0))*Re}function Wr(t,e){let[,n]=un(e),r=ua(t,e);return t.wall?n*Math.cos(r)+Ue:!t.flat&&r<.001?n+Ue:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Wn(t,e){let[n,r]=un(e),o=Br(e),i=Math.max(1,...o);return[i*n+(i-1)*Ue,(o.length-1)*Wr(t,e)+r*Math.cos(ua(t,e))]}var dy=t=>t.flat&&!t.unbounded&&!t.wall;function Ld(t,e){if(!dy(t)||!e.rotation)return null;let n=e.rotation*Re,[r,o]=Wn(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+o/2}}function Ze(t,e,n=!1){let[r,o]=un(e),i=ua(t,e),s=o*Math.cos(i),l=Wr(t,e),a=Br(e),c=Math.max(1,...a),u=new Set(e.skip??[]),d=Ld(t,e),p=(y,b)=>d?[d.u+(y-d.u)*d.cos-(b-d.s)*d.sin,d.s+(y-d.u)*d.sin+(b-d.s)*d.cos]:[y,b],h=(y,b,v)=>{let[w,x]=p(y,b);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*v)},f=(y,b)=>{let[v,w]=p(y,b);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[x,k]=t.span(w);return v>=x-1e-6&&v<=k+1e-6},g=[];return a.forEach((y,b)=>{let v=e.align==="right"?c-y:e.align==="center"?(c-y)/2:0;for(let w=0;w.001?s:o);if([[S,T],[E,T],[E,F],[S,F]].every(([O,P])=>f(O,P)))if(t.wall&&i>.001){let O=st+o*Math.sin(i),[P,C]=e.flip?[O,st]:[st,O],B=[h(S,T,P),h(E,T,P),h(E,F,C),h(S,F,C)],q=e.flip?T:F;g.push({corners:B,posts:[S+.05,E-.05].map(we=>[h(we,q,0),h(we,q,O)]),cell:x,skipped:k})}else if(!t.flat&&i>.001){let O=st+o*Math.sin(i),P=[h(S,T,st),h(E,T,st),h(E,F,O),h(S,F,O)];g.push({corners:P,posts:[S+.05,E-.05].map(C=>[h(C,F,0),h(C,F,O)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h(S,T,st),h(E,T,st),h(E,F,st),h(S,F,st)],posts:[],cell:x,skipped:k});else{let P=.15+o*Math.sin(i),C=e.rack==="ew"&&b%2===1?!e.flip:!!e.flip,[B,q]=C?[F,T]:[T,F],we=[h(S,B,.15),h(E,B,.15),h(E,q,P),h(S,q,P)],Mt=[S+.05,E-.05].flatMap(j=>[[h(j,B,0),h(j,B,.15)],[h(j,q,0),h(j,q,P)]]);g.push({corners:we,posts:Mt,cell:x,skipped:k})}}}),g}function ft(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Wn(t,e),o=Ld(t,e);if(o){let[s,l]=[(n*Math.abs(o.cos)+r*Math.abs(o.sin))/2,(n*Math.abs(o.sin)+r*Math.abs(o.cos))/2],a=(d,p,h)=>Math.floor(Math.max(p,Math.min(d,h-p))*100+1e-6)/100,[c,u]=[e.u+n/2,e.v+r/2];return{u:Math.round((a(c,s,t.lu)-n/2)*100)/100,v:Math.round((a(u,l,t.ls)-r/2)*100)/100}}let i=s=>Math.floor(s*100+1e-6)/100;return{u:i(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:i(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function Vr(t,e){let[n,r]=Wn(t,e),[o,i]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*o+t.es[0]*i,t.o[2]+t.eu[2]*o+t.es[2]*i]}var ui=.78,Kr=1.18,dn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||ui,module_h:t.h||Kr});function da(t,e){let n=Ze(t,dn(e))[0];if(!n)return null;let r=o=>[o[0]-t.n[0]*.05,o[1]-t.n[1]*.05,o[2]-t.n[2]*.05];return n.corners.map(r)}var Cr={brick:{w:.5,d:.5,h:1},round:{w:.4,d:.4,h:1},wide:{w:1,d:.5,h:1},steel:{w:.2,d:.2,h:1.2}};function hn(t){let e=t.shape??"brick",n=Cr[e]??Cr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function kt(t,e){let{w:n,d:r}=hn(t),o=e&&!e.flat?Math.cos(e.pitch*Re):1;return{id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:n,module_h:r/Math.max(.2,o),tilt:0}}function ha(t,e){let n=kt(e,t),[r,o]=[n.module_w,n.module_h],i=(u,d)=>[t.o[0]+t.eu[0]*u+t.es[0]*d,t.o[1]+t.eu[1]*u+t.es[1]*d,t.o[2]+t.eu[2]*u+t.es[2]*d],[s,l]=[i(e.u+r/2,e.v),i(e.u+r/2,e.v+o)],a=i(e.u+r/2,e.v+o/2),c=u=>{let d=Math.hypot(u[0],u[2])||1;return[u[0]/d,u[2]/d]};return{center:[a[0],a[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],l[1]),high:Math.max(s[1],l[1])}}function pa(t,e){let[n]=un(e);return je((t.lu-(e.cols*n+(e.cols-1)*Ue))/2)}var jr=.4;function Vn(t,e){let n={id:e,face:t.key,u:0,v:0,rows:1,cols:1,portrait:!0,tilt:t.flat?15:null,flip:!1,entity:null,look:"black"},[r]=un(n),[o,i]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((i-o-2*jr+Ue)/(r+Ue))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*jr)/Wr(t,n))));n.cols>1&&Ze(t,{...n,u:pa(t,n),v:jr}).lengthl.lu*(1.3+Math.cos((Lr(l.facing,r)-180)*Math.PI/180)),i=Ge(t,n).sort((l,a)=>o(a)-o(l))[0];if(!i)return null;let s={...Vn(i,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((i.lu-.8+Ue)/(Nr+Ue))),s.u=je((i.lu-(s.cols*Nr+(s.cols-1)*Ue))/2),s.v=je(Math.max(0,i.ls-ci-.3)),s}function Gr(t,e){let n=t.floors.flatMap(i=>i.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(i=>i[0]))+3:0,o=n.length?Math.min(...n.map(i=>i[1])):0;return{id:e,face:Oe,u:je(r),v:je(o),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function Ur(t,e,n){let r=li(t,e),[o,i]=Wn(r,e),[s,l]=[e.u+o/2,e.v+i/2],a=[r.eu[0]*s+r.es[0]*l,r.eu[2]*s+r.es[2]*l],c=n*Re,u=a[0]*Math.cos(c)+a[1]*Math.sin(c)-o/2,d=a[0]*-Math.sin(c)+a[1]*Math.cos(c)-i/2;return{u:je(u),v:je(d),rotation:(Math.round(n)%360+360)%360}}function Zr(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:je((n+r-ui)/2),v:je(Math.max(0,Math.min(t.ls-Kr,t.ls*.45-Kr/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function qr(t,e){let n=Cr.brick,[r,o]=t.span(t.ls*.8),i=kt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:je((r+o-n.w)/2),v:je(Math.max(0,Math.min(t.ls-i,t.ls*.8-i/2))),shape:"brick",w:null,d:null,h:null}}function Kn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[o,i,s,l]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],a=o*l-i*s;if(Math.abs(a)<1e-9)return null;let c=(n*l-r*s)/a,u=(o*r-i*n)/a;if(u<0||u>t.ls)return null;let[d,p]=t.span(u);return c>=d&&c<=p?{u:c,s:u}:null}function ma(t,e){let n=null;for(let r of t){if(r.wall){let[s,l]=[e[0]-r.o[0],e[1]-r.o[2]],a=s*r.eu[0]+l*r.eu[2],c=s*r.n[0]+l*r.n[2],u=a>=0&&a<=r.lu;if(u&&c>=-.05&&c<=.35)return{face:r,u:a,s:Number.NaN};u&&c>.35&&c<=.8&&!n&&(n={face:r,u:a,s:Number.NaN,y:-1/0});continue}let o=Kn(r,e);if(!o)continue;let i=r.o[1]+r.es[1]*o.s;(!n||i>n.y)&&(n={face:r,...o,y:i})}return n&&{face:n.face,u:n.u,s:n.s}}function hi(t,e,n){let r=ln(n,t.n);if(Math.abs(r)<1e-6)return null;let o=ln(Ke(t.o,e),t.n)/r;if(o<=0)return null;let i=Ke([e[0]+n[0]*o,e[1]+n[1]*o,e[2]+n[2]*o],t.o);return{t:o,u:ln(i,t.eu),s:ln(i,t.es)}}function ga(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,o]=t.span(n);return e>=r&&e<=o}function _a(t,e,n,r){return Ze(t,e).some(i=>{let s=i.corners.map(c=>{let u=Ke(c,t.o);return[ln(u,t.eu),ln(u,t.es)]}),l=s.map(c=>c[0]),a=s.map(c=>c[1]);return n>=Math.min(...l)-.05&&n<=Math.max(...l)+.05&&r>=Math.min(...a)-.05&&r<=Math.max(...a)+.05})}var hy=["n","ne","e","se","s","sw","w","nw"],ba=(t,e)=>hy[Math.round(Lr(t.facing,e)/45)%8];function Yr(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let o=Math.cos((Lr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+o)};return[...t].sort((r,o)=>n(o)-n(r))[0]??null}var Wd=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Cd={kitchen_row:{rows:[["back","start",["fridge","kitchen_tall",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove",["kitchen",[.6,.62,.92]]]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[[["table",[1.2,.8,.75]],.5,.72,0],["lamp_pendant",.5,.72,0],["lamp_ceiling",.5,.3,0]]},kitchen_l:{rows:[["back","start",["fridge",["kitchen",[.9,.62,.92]],"sink","dishwasher","stove"]],["right","start",[["kitchen",[.9,.62,.92]],["kitchen",[.6,.62,.92]],"kitchen_tall"]],["back","start",[["kitchen_wall",[1.2,.35,.7]]]]],spots:[["table",.4,.68,0],["bar_stool",.72,.86,180],["lamp_ceiling",.5,.35,0]]},bath:{rows:[["back","center",["washbasin"]],["back","end",["wc"]],["front","start",["bathtub"]],["left","start",["washer"]]],spots:[["lamp_downlight",.5,.5,0]]},bedroom:{rows:[["back","center",["nightstand","bed","nightstand"]],["left","center",[["wardrobe",[2,.6,2.1]]]],["front","end",["dresser"]]],spots:[["lamp_ceiling",.5,.55,0]]},living:{rows:[["back","center",["tv_board"]],["right","start",["shelf"]]],spots:[["sofa",.5,.72,180],["coffee_table",.5,.52,0],[["rug",[2.2,1.6,.01]],.5,.55,0],["armchair",.14,.5,270],["lamp_floor",.86,.8,0],["plant",.9,.12,0],["lamp_ceiling",.5,.45,0]]},dining:{rows:[["back","center",["sideboard"]]],spots:[["table",.5,.55,0],["chair",.4,.35,0],["chair",.6,.35,0],["chair",.4,.75,180],["chair",.6,.75,180],["lamp_pendant",.5,.55,0]]},office:{rows:[["back","center",["desk"]],["left","center",["shelf","shelf"]]],spots:[["office_chair",.5,.38,180],["lamp_ceiling",.5,.55,0]]},kids:{rows:[["left","start",[["bed",[.9,2,.8]]]],["back","end",[["desk",[1.2,.6,.75]]]],["right","end",["shelf"]]],spots:[[["rug",[1.6,1.2,.01]],.55,.6,0],["lamp_ceiling",.5,.5,0]]},hall:{rows:[["left","start",["coat_rack"]]],spots:[["lamp_downlight",.5,.3,0],["lamp_downlight",.5,.7,0]]}},Nd=t=>typeof t=="string"?t:t[0],pi=t=>typeof t=="string"?tt[t]:t[1],jn=.05,py=.02,Bd=t=>Math.round(t*1e3)/1e3;function fy(t,e,n,r){switch(e){case"back":return{x:t.x0+n,z:t.z0+r,turn:0};case"right":return{x:t.x1-r,z:t.z0+n,turn:90};case"front":return{x:t.x1-n,z:t.z1-r,turn:180};case"left":return{x:t.x0+r,z:t.z1-n,turn:270}}}function Vd(t,e,n){let r=de(t.points),o=r.x1-r.x0,i=r.z1-r.z0,s=[],l=(a,c,u,d,[p,h,f])=>{s.push({id:n(),type:a,x:Bd(c),z:Bd(u),rotation:d,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[a,c,u]of Cd[e].rows){let d=a==="back"||a==="front"?o:i,p=0,h=[];for(let g of u){if(p+pi(g)[0]>d-.1)break;h.push(g),p+=pi(g)[0]}let f=c==="start"?jn:c==="end"?d-p-jn:(d-p)/2;for(let g of h){let y=pi(g),b=fy(r,a,f+y[0]/2,y[1]/2+py);l(Nd(g),b.x,b.z,b.turn,y),f+=y[0]}}for(let[a,c,u,d]of Cd[e].spots){let p=pi(a),h=(y,b,v)=>Math.min(v,Math.max(b,y)),f=h(r.x0+o*c,r.x0+p[0]/2+jn,r.x1-p[0]/2-jn),g=h(r.z0+i*u,r.z0+p[1]/2+jn,r.z1-p[1]/2-jn);l(Nd(a),f,g,d,p)}return s}var my=30*Math.PI/180,Kd=.05;function ya(t){let e=t.points.length;return t.points.map((n,r)=>{let o=t.points[(r+1)%e];return Math.hypot(o[0]-n[0],o[1]-n[1])})}function Xr(t){return ya(t).reduce((e,n)=>e+n,0)}function gy(t,e){let n=ya(t),r=0;for(let o=0;oh+f,0);if(o<3||!(i>0)||!(n>0))return null;let s=Math.min(n,i),l=(e%i+i)%i,a=0,c=0;for(;a=c+r[a];)c+=r[a],a++;let u=l-c,d=s,p=[];for(let h=0;h<=o&&d>1e-9;h++){let f=r[a]-u,g=Math.min(d,f);g>1e-9&&p.push({edge:a,t0:u,t1:u+g}),d-=g,u=0;let y=(a+1)%o;if(d>1e-9&&_y(t,a)>my)break;a=y}for(;p.length>1&&p[0].t1-p[0].t01&&p[p.length-1].t1-p[p.length-1].t0({edge:h.edge,offset:(h.t0+h.t1)/2,width:h.t1-h.t0})):null}function Gn(t,e){let n=e[0];return n?{from:gy(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,o)=>r+o.width,0)}:null}function Bt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function wa(t,e){let n=t.points.length,r=1/0,o=0,i=0;for(let s=0;sI("opening")){let s=va(e,r,o);if(!s)return null;let l=Bt(t,n),a=new Set(l.map(h=>h.id)),c=s.length>1?l[0].front??`front-${l[0].id}`:null,u=s.map((h,f)=>({...n,id:f===0?l[0].id:i(),edge:h.edge,offset:h.offset,width:h.width,front:c})),d=[],p=!1;for(let h of t){if(!a.has(h.id)){d.push(h);continue}p||(d.push(...u),p=!0)}return d}var $a=globalThis,ka=$a.__nextfloorBuiltin?.de??{},xa=$a.__nextfloorBuiltin?.en??{};$a.__nextfloorBuiltin??={de:ka,en:xa};var by=()=>typeof $=="object"&&$||{},yy=globalThis,vy=yy.__nextfloorTexts??=new Map;function wy(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in by()?e:void 0}function jd(t){let e=wy(t),n=e===void 0?void 0:vy.get(e);return n instanceof Promise?void 0:n}function fi(t,e){return jd(t)?.[e]}function Se(t,e,n={}){let r=t?.language??navigator.language,o=r.startsWith("de"),i=(o?void 0:jd(r)?.[e])??(o?ka:xa)[e]??xa[e]??ka[e]??e;for(let[s,l]of Object.entries(n))i=i.replace(`{${s}}`,String(l));return i}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var ge=t=>/^(sensor|input_number|number)\./.test(t),mi=t=>/^(binary_sensor|input_boolean)\./.test(t);function Un(t,e){if(!ge(e))return!1;let n=t?.states[e]?.attributes;return n?.device_class==="power"||n?.unit_of_measurement==="W"||n?.unit_of_measurement==="kW"}function ky(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function H(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=ky(t,n),o=t?.states[n],i=typeof o?.attributes.symcon_path=="string"?o.attributes.symcon_path:void 0,s={id:n,label:r?`${W(t,n)} \xB7 ${r}`:W(t,n)};return i&&(s.detail=`Objektbaum: ${i}`),typeof o?.attributes.symcon_source_entity=="string"&&(s.sourceEntity=o.attributes.symcon_source_entity),s}).sort((n,r)=>n.label.localeCompare(r.label))}function gi(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var Gd=[{key:"supply_vsr",label:"Zuluft-VSR",types:[0,1,2],control:!0},{key:"extract_vsr",label:"Abluft-VSR",types:[0,1,2],control:!0},{key:"supply_temperature",label:"Zulufttemperatur",types:[1,2]},{key:"extract_temperature",label:"Ablufttemperatur",types:[1,2]},{key:"reheat",label:"NHR (Nachheizregister)",types:[0,1,2],control:!0},{key:"status",label:"Raumstatus",types:[1]}];function Ud(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),o=e.hvac?.schedules??[],i=H(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,H(t.hass,s=>It(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}))}
- ${Wd.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,H(t.hass,l=>It(t.hass,l,s.types)),l=>r({[s.key]:l==="none"?null:l})))}
+ ${Gd.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,H(t.hass,l=>It(t.hass,l,s.types)),l=>r({[s.key]:l==="none"?null:l})))}
${M("Raumstatus zeigt den in Symcon hinterlegten Alias der Integer-Variable. Beschreibbare Heizungs- und L\xFCftungswerte k\xF6nnen im Raummen\xFC bedient werden.","nf-wide")}
${o.map((s,l)=>z(t,`Schaltuhr ${l+1}`,s,void 0,i.filter(a=>a.id===s||!o.includes(a.id)),a=>r({schedules:a&&a!=="none"?o.map((c,u)=>l===u?a:c):o.filter((c,u)=>l!==u)})))}
- ${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,i.filter(s=>!o.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...o,s]}))}`}function Kd(t,e,n){return m`Wettervariablen
- ${Lc.map(r=>z(t,zu[r],e.weather_variables?.[r]??null,void 0,H(t.hass,o=>It(t.hass,o,r==="condition"?[0,1,2,3]:r==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(r)?[0,1,2]:[1,2])),o=>n({weather_variables:{...e.weather_variables,[r]:o==="none"?null:o}})))}
+ ${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,i.filter(s=>!o.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...o,s]}))}`}function Zd(t,e,n){return m`
Wettervariablen
+ ${Wc.map(r=>z(t,Ou[r],e.weather_variables?.[r]??null,void 0,H(t.hass,o=>It(t.hass,o,r==="condition"?[0,1,2,3]:r==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(r)?[0,1,2]:[1,2])),o=>n({weather_variables:{...e.weather_variables,[r]:o==="none"?null:o}})))}
${z(t,t.t("rain_sensor"),e.rain_sensor??null,void 0,H(t.hass,r=>It(t.hass,r,[0,1,2])),r=>n({rain_sensor:r==="none"?null:r}))}
${e.rain_sensor?D(t,t.t("rain_sensor_inverted"),!!e.rain_sensor_inverted,r=>n({rain_sensor_inverted:r||void 0})):_}
${M("W\xE4hle die Wetterwerte einzeln aus dem Symcon-Objektbaum. Einheiten werden aus den Variablen \xFCbernommen. Der Regensensor kann Boolean oder eine numerische Regenrate sein.","nf-wide")}
-
`}function jd(t){let e=t.doc.presence,n=s=>t.replace({...structuredClone(t.doc),presence:s}),r=(s,l)=>n(e.map((a,c)=>c===s?{...a,...l,sensor:null}:a)),o=t.doc.floors.flatMap(s=>s.rooms.map(l=>({id:l.id,name:`${s.name} \xB7 ${l.name}`}))),i=H(t.hass,s=>It(t.hass,s,[0]));return m`
${t.t("presence")}
+ `}function qd(t){let e=t.doc.presence,n=s=>t.replace({...structuredClone(t.doc),presence:s}),r=(s,l)=>n(e.map((a,c)=>c===s?{...a,...l,sensor:null}:a)),o=t.doc.floors.flatMap(s=>s.rooms.map(l=>({id:l.id,name:`${s.name} \xB7 ${l.name}`}))),i=H(t.hass,s=>It(t.hass,s,[0]));return m`${t.t("presence")}
${e.map((s,l)=>m`
${V(t,"Person",s.name??W(t.hass,s.person),a=>r(l,{name:a}),{wide:!0,maxlength:100})}
${z(t,"Anwesenheit (Boolean)",s.person,void 0,i.filter(a=>a.id===s.person||!e.some(c=>c.person===a.id)),a=>a&&a!=="none"?r(l,{person:a}):n(e.filter((c,u)=>u!==l)))}
@@ -493,23 +493,23 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
`)}
${z(t,"Person hinzuf\xFCgen (Boolean)",null,void 0,i.filter(s=>!e.some(l=>l.person===s.id)),s=>s&&s!=="none"&&n([...e,{person:s,sensor:null}]))}
${M("Jede Person wird mit einer beliebigen Boolean-Variable verkn\xFCpft: true bedeutet anwesend, false abwesend. Ein Raum ist optional und bestimmt die Position der Person in 3D.")}
- `}function Gd(t,e,n){let r=t.find(a=>a.person===e),o="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,i="room"in n?n.room||null:r?.room??null,s=t.filter(a=>a.person!==e);if(!o&&!i)return s;let l=i?{person:e,sensor:o,room:i}:{person:e,sensor:o};return r?t.map(a=>a.person===e?l:a):[...s,l]}function Ud(t,e){let n=e.slice(e.indexOf(".")+1),r=o=>o.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(o.id);return[...t.filter(r),...t.filter(o=>!r(o))]}function Zd(t){let e=t.target?`, target: { x: ${t.target.x}, y: ${t.target.y}, z: ${t.target.z} }`:"";return`start_view: { theta: ${t.theta}, phi: ${t.phi}, radius: ${t.radius}${e} }`}function qd(t){let e=t.trim();if(!e)return{ok:!0,value:null};try{let n=JSON.parse(e);return n&&typeof n=="object"&&!Array.isArray(n)?{ok:!0,value:n}:{ok:!1}}catch{return{ok:!1}}}function _i(t,e,n){let r=[...t],[o]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,o),r}var Wt=(t,e)=>t.filter((n,r)=>r!==e),Qr=(t,e,n)=>t.map((r,o)=>o===e?{...r,...n}:r),mt=t=>t.length>0?t:void 0;var by=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],yy=40,vy=20,wy=30,ky=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],Sa={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},Jr=(t,e,n,r=!1)=>m`${e} `;function xy(t){let e=t.doc.settings.favorites??[],n=l=>t.change(a=>a.settings.favorites=mt(l)),r=t.doc.floors,o=t.doc.settings.favorite_floors??{},i=H(t.hass,l=>by.includes(l.split(".")[0])&&!e.includes(l)),s=(l,a)=>m`
+ `}function Yd(t,e,n){let r=t.find(a=>a.person===e),o="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,i="room"in n?n.room||null:r?.room??null,s=t.filter(a=>a.person!==e);if(!o&&!i)return s;let l=i?{person:e,sensor:o,room:i}:{person:e,sensor:o};return r?t.map(a=>a.person===e?l:a):[...s,l]}function Xd(t,e){let n=e.slice(e.indexOf(".")+1),r=o=>o.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(o.id);return[...t.filter(r),...t.filter(o=>!r(o))]}function Qd(t){let e=t.target?`, target: { x: ${t.target.x}, y: ${t.target.y}, z: ${t.target.z} }`:"";return`start_view: { theta: ${t.theta}, phi: ${t.phi}, radius: ${t.radius}${e} }`}function Jd(t){let e=t.trim();if(!e)return{ok:!0,value:null};try{let n=JSON.parse(e);return n&&typeof n=="object"&&!Array.isArray(n)?{ok:!0,value:n}:{ok:!1}}catch{return{ok:!1}}}function _i(t,e,n){let r=[...t],[o]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,o),r}var Wt=(t,e)=>t.filter((n,r)=>r!==e),Jr=(t,e,n)=>t.map((r,o)=>o===e?{...r,...n}:r),mt=t=>t.length>0?t:void 0;var xy=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],$y=40,Sy=20,My=30,Ry=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],Sa={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},eo=(t,e,n,r=!1)=>m`
${e} `;function Ey(t){let e=t.doc.settings.favorites??[],n=l=>t.change(a=>a.settings.favorites=mt(l)),r=t.doc.floors,o=t.doc.settings.favorite_floors??{},i=H(t.hass,l=>xy.includes(l.split(".")[0])&&!e.includes(l)),s=(l,a)=>m`
${W(t.hass,l)}
${r.length>1?m`{let u=c.target.value,d={...o};u?d[l]=u:delete d[l],t.change(p=>p.settings.favorite_floors=Object.keys(d).length?d:void 0)}}>
${t.t("favorite_all_floors")}
${r.map(c=>m`${c.name} `)}
`:_}
- ${Jr(t.t("move_up"),"\u2191",()=>n(_i(e,a,-1)),a===0)}
- ${Jr(t.t("move_down"),"\u2193",()=>n(_i(e,a,1)),a===e.length-1)}
- ${Jr(t.t("delete"),"\u2715",()=>n(Wt(e,a)))}
+ ${eo(t.t("move_up"),"\u2191",()=>n(_i(e,a,-1)),a===0)}
+ ${eo(t.t("move_down"),"\u2193",()=>n(_i(e,a,1)),a===e.length-1)}
+ ${eo(t.t("delete"),"\u2715",()=>n(Wt(e,a)))}
`;return m`
${t.t("favorites")}${e.length>0?m` ${e.length} `:_}
${M(t.t("favorites_hint"))} ${e.map(s)}
- ${e.length
${z(t,t.t("favorites_add"),null,void 0,i,l=>l&&l!=="none"&&!e.includes(l)&&n([...e,l]))} `:_}`}function $y(t,e){let n=t.doc.settings.outside_hidden??[],r=s=>t.change(l=>l.settings.outside_hidden=mt(s)),o=new Set(t.hass?Bu(t.hass,t.doc.floors):[]),i=H(t.hass,s=>!n.includes(s)&&o.has(s));return m`${e?Sy(t,e):_}
+ ${e.length<$y?m`${z(t,t.t("favorites_add"),null,void 0,i,l=>l&&l!=="none"&&!e.includes(l)&&n([...e,l]))}
`:_}`}function Ay(t,e){let n=t.doc.settings.outside_hidden??[],r=s=>t.change(l=>l.settings.outside_hidden=mt(s)),o=new Set(t.hass?ju(t.hass,t.doc.floors):[]),i=H(t.hass,s=>!n.includes(s)&&o.has(s));return m`${e?Fy(t,e):_}
${t.t("outside_hidden")}${n.length>0?m` ${n.length} `:_}
${M(t.t("outside_hidden_hint"))}
- ${n.map((s,l)=>m`${W(t.hass,s)} ${Jr(t.t("delete"),"\u2715",()=>r(Wt(n,l)))}
`)}
- ${z(t,t.t("outside_hidden_add"),null,void 0,i,s=>s&&s!=="none"&&!n.includes(s)&&r([...n,s]))}
`}function Sy(t,e){let n=t.doc.settings.outside_view??null,r=()=>{let o=e();o&&t.change(i=>i.settings.outside_view=o)};return m`${M(t.t("outside_view_hint"))}
- ${Y(m`${t.t("outside_view_set")} `,n?m`t.change(o=>o.settings.outside_view=null)}>${t.t("outside_view_reset")} `:_)}`}function My(t){let e=t.doc.settings.own_alerts??[],n=s=>t.change(l=>l.settings.own_alerts=mt(s)),r=(s,l)=>n(Qr(e,s,l)),o=[["",t.t("own_alert_house")],...t.doc.floors.flatMap(s=>s.rooms.map(l=>[l.id,`${l.name} \xB7 ${s.name}`]))],i=(s,l)=>m`
+ ${n.map((s,l)=>m`
${W(t.hass,s)} ${eo(t.t("delete"),"\u2715",()=>r(Wt(n,l)))}
`)}
+
${z(t,t.t("outside_hidden_add"),null,void 0,i,s=>s&&s!=="none"&&!n.includes(s)&&r([...n,s]))}
`}function Fy(t,e){let n=t.doc.settings.outside_view??null,r=()=>{let o=e();o&&t.change(i=>i.settings.outside_view=o)};return m`${M(t.t("outside_view_hint"))}
+ ${X(m`
${t.t("outside_view_set")} `,n?m`
t.change(o=>o.settings.outside_view=null)}>${t.t("outside_view_reset")} `:_)}`}function Ty(t){let e=t.doc.settings.own_alerts??[],n=s=>t.change(l=>l.settings.own_alerts=mt(s)),r=(s,l)=>n(Jr(e,s,l)),o=[["",t.t("own_alert_house")],...t.doc.floors.flatMap(s=>s.rooms.map(l=>[l.id,`${l.name} \xB7 ${s.name}`]))],i=(s,l)=>m`
`;return m`
⚠ ${t.t("own_alerts")}
${M(t.t("own_alerts_hint"))} ${e.map(i)}
- ${e.length<40?Y(m`
n([...e,{id:I("alert"),entity:"",state:null,text:t.t("own_alert_new")}])}>+ ${t.t("own_alert_add")} `):_}`}function Ry(t){let e=t.doc.settings.circuits??[],n=l=>t.change(a=>a.settings.circuits=mt(l)),r=(l,a)=>n(Qr(e,l,a)),o=t.doc.floors.flatMap(l=>l.rooms.map(a=>({id:a.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${l.name}`:a.name}))),i=l=>o.find(a=>a.id===l)?.label??l,s=(l,a)=>m`
+ ${e.length<40?X(m`
n([...e,{id:I("alert"),entity:"",state:null,text:t.t("own_alert_new")}])}>+ ${t.t("own_alert_add")} `):_}`}function zy(t){let e=t.doc.settings.circuits??[],n=l=>t.change(a=>a.settings.circuits=mt(l)),r=(l,a)=>n(Jr(e,l,a)),o=t.doc.floors.flatMap(l=>l.rooms.map(a=>({id:a.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${l.name}`:a.name}))),i=l=>o.find(a=>a.id===l)?.label??l,s=(l,a)=>m`
`;return m`
🔌 ${t.t("circuits")}
${M(t.t("circuits_hint"))} ${e.map(s)}
- ${e.length<120?Y(m`
n([...e,{id:I("circuit"),name:t.t("circuit_new"),rooms:[]}])}>+ ${t.t("circuit_add")} `):_}`}function Ey(t){let e=t.doc.settings.calendars??[],n=l=>t.change(a=>a.settings.calendars=mt(l)),r=H(t.hass,l=>l.startsWith("calendar.")&&!e.includes(l)),o=(l,a)=>m`
+ ${e.length<120?X(m`
n([...e,{id:I("circuit"),name:t.t("circuit_new"),rooms:[]}])}>+ ${t.t("circuit_add")} `):_}`}function Py(t){let e=t.doc.settings.calendars??[],n=l=>t.change(a=>a.settings.calendars=mt(l)),r=H(t.hass,l=>l.startsWith("calendar.")&&!e.includes(l)),o=(l,a)=>m`
${W(t.hass,l)}
- ${Jr(t.t("delete"),"\u2715",()=>n(Wt(e,a)))}
+ ${eo(t.t("delete"),"\u2715",()=>n(Wt(e,a)))}
`,i=t.t,s=t.doc.settings.today_days??1;return m`
📅 ${i("today_calendars")}
${M(i("today_calendars_hint"))} ${e.map(o)}
${e.length<12?m`
${z(t,i("favorites_add"),null,void 0,r,l=>l&&l!=="none"&&!e.includes(l)&&n([...e,l]))}
`:_}
${e.length?m`
${L(t,i("today_days"),String(s),[1,2,3,5,7].map(l=>[String(l),i(l===1?"today_days_one":"today_days_n",{n:l})]),l=>t.change(a=>a.settings.today_days=Number(l)>1?Number(l):void 0))}
`:_}
- ${Ay(t)}`}function Ay(t){let e=t.t,n=t.doc.settings.forecast??null,r=o=>t.change(i=>i.settings.forecast=o??void 0);return m`
🌦 ${e("forecast")}
+ ${Iy(t)}`}function Iy(t){let e=t.t,n=t.doc.settings.forecast??null,r=o=>t.change(i=>i.settings.forecast=o??void 0);return m`
🌦 ${e("forecast")}
${M(e("forecast_hint"))}
${L(t,e("forecast_days"),n?String(n.days):"0",[0,3,5,7].map(o=>[String(o),o?e("today_days_n",{n:o}):e("forecast_off")]),o=>r(Number(o)>0?{days:Number(o),corner:n?.corner??"top_right"}:null))}
${n?L(t,e("forecast_corner"),n.corner,[["top_right",e("clock_top_right")],["top_left",e("clock_top_left")]],o=>r({...n,corner:o==="top_left"?"top_left":"top_right"})):_}
-
`}function Fy(t){let e=t.doc.settings.media_presets??[],n=s=>t.change(l=>l.settings.media_presets=mt(s)),r=(s,l)=>n(Qr(e,s,l)),o=[...new Set(t.doc.floors.flatMap(s=>[...s.placements.map(l=>l.entity_id),...s.furniture.map(l=>l.entity??"")]).filter(s=>s.startsWith("media_player.")))],i=(s,l)=>m`
+
`}function Dy(t){let e=t.doc.settings.media_presets??[],n=s=>t.change(l=>l.settings.media_presets=mt(s)),r=(s,l)=>n(Jr(e,s,l)),o=[...new Set(t.doc.floors.flatMap(s=>[...s.placements.map(l=>l.entity_id),...s.furniture.map(l=>l.entity??"")]).filter(s=>s.startsWith("media_player.")))],i=(s,l)=>m`
`;return m`
${t.t("presets")}
${M(t.t("presets_hint"))}
-
${ky.map(s=>m` `)}
+
${Ry.map(s=>m` `)}
${e.map(i)}
- ${e.length
n([...e,{id:I("preset"),label:"Radio",type:"music",content:""}])}>+ ${t.t("preset_add")}`):_}`}function Ma(t,e,n){let r=e.action==="fire_dom_event"?'{"browser_mod": {"service": "browser_mod.popup", "data": {"title": "Rollos", "content": {"type": "custom:my-cover-card"}}}}':'{"entity_id": "script.party"}',o=i=>{let s=i.target;s.setCustomValidity("");let l=qd(s.value);if(l.ok)return n(l.value);s.setCustomValidity(t.t("own_data_bad")),s.reportValidity()};return m`n([...e,{id:I("preset"),label:"Radio",type:"music",content:""}])}>+ ${t.t("preset_add")}`):_}`}function Ma(t,e,n){let r=e.action==="fire_dom_event"?'{"browser_mod": {"service": "browser_mod.popup", "data": {"title": "Rollos", "content": {"type": "custom:my-cover-card"}}}}':'{"entity_id": "script.party"}',o=i=>{let s=i.target;s.setCustomValidity("");let l=Jd(s.value);if(l.ok)return n(l.value);s.setCustomValidity(t.t("own_data_bad")),s.reportValidity()};return m`${t.t("own_data")}
- `}function Ty(t){let e=t.doc.settings.buttons??[],n=s=>t.change(l=>l.settings.buttons=mt(s)),r=(s,l)=>n(Qr(e,s,l)),o=Lo.map(s=>[s,t.t(`own_action_${s}`)]),i=(s,l)=>m``;return m`${t.t("own_buttons")}
${M(t.t("own_buttons_hint"))} ${e.map(i)}
- ${e.lengthn([...e,{id:I("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function zy(t){let e=t.doc.settings.room_facts_off??[],n=["sun","comfort","air","circuits"].map(r=>D(t,t.t(`room_fact_${r}`),!e.includes(r),o=>t.change(i=>i.settings.room_facts_off=mt(o?e.filter(s=>s!==r):[...e,r]))));return m`${t.t("room_facts")} ${n}
`}function Yd(t){return m`${xy(t)} ${Ty(t)} ${My(t)} ${Ry(t)} ${Ey(t)} ${Fy(t)} ${zy(t)} `}function Xd(t,e){return m`
+ ${e.lengthn([...e,{id:I("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function Hy(t){let e=t.doc.settings.room_facts_off??[],n=["sun","comfort","air","circuits"].map(r=>D(t,t.t(`room_fact_${r}`),!e.includes(r),o=>t.change(i=>i.settings.room_facts_off=mt(o?e.filter(s=>s!==r):[...e,r]))));return m`${t.t("room_facts")} ${n}
`}function eh(t){return m`${Ey(t)} ${Oy(t)} ${Ty(t)} ${zy(t)} ${Py(t)} ${Dy(t)} ${Hy(t)} `}function th(t,e){return m`
🌳 ${t.t("outside_area")}
- ${$y(t,e)}
- `}function Qd(t,e){let n=t.doc.settings.start_view??null,r=()=>{let o=e();o&&t.change(i=>i.settings.start_view=o)};return m`
+ ${Ay(t,e)}
+ `}function nh(t,e){let n=t.doc.settings.start_view??null,r=()=>{let o=e();o&&t.change(i=>i.settings.start_view=o)};return m`
${t.t("start_view")}
${M(t.t("start_view_hint"))}
- ${Y(m`${t.t("start_view_set")} `,n?m`t.change(o=>o.settings.start_view=null)}>${t.t("start_view_reset")} `:_)}
- ${n?m`${M(t.t("start_view_saved"))} ${M(t.t("start_view_card"))}${Zd(n)}`:_}
- `}function Jd(t){if(ue(t.hass))return jd(t);let e=t.doc.presence.map(a=>a.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(a=>a.startsWith("person.")).sort(),...e])],r=H(t.hass,ge),o=t.doc.floors.flatMap(a=>a.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${c.name}`:c.name}))),i=(a,c)=>t.replace({...structuredClone(t.doc),presence:Gd(t.doc.presence,a,c)}),s=a=>{let c=t.doc.presence.find(d=>d.person===a),u=!a.startsWith("person.");return m`${z(t,`${W(t.hass,a)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,Ud(r,a),d=>i(a,{sensor:d}))}
+ ${X(m`${t.t("start_view_set")} `,n?m`t.change(o=>o.settings.start_view=null)}>${t.t("start_view_reset")} `:_)}
+ ${n?m`${M(t.t("start_view_saved"))} ${M(t.t("start_view_card"))}${Qd(n)}`:_}
+ `}function rh(t){if(oe(t.hass))return qd(t);let e=t.doc.presence.map(a=>a.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(a=>a.startsWith("person.")).sort(),...e])],r=H(t.hass,ge),o=t.doc.floors.flatMap(a=>a.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${a.name} \xB7 ${c.name}`:c.name}))),i=(a,c)=>t.replace({...structuredClone(t.doc),presence:Yd(t.doc.presence,a,c)}),s=a=>{let c=t.doc.presence.find(d=>d.person===a),u=!a.startsWith("person.");return m`${z(t,`${W(t.hass,a)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,Xd(r,a),d=>i(a,{sensor:d}))}
${t.t("presence_room")}
i(a,{room:d.target.value||null})}>
${t.t("presence_room_none")}
@@ -586,18 +586,18 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
${z(t,t.t("presence_add"),null,void 0,l,a=>a&&a!=="none"&&t.replace({...structuredClone(t.doc),presence:[...t.doc.presence,{person:a,sensor:null}]}))}
${M(t.t("presence_hint"))}
- `}function eh(t,e){return ue(t.hass)?m``:m`
+ `}function oh(t,e){return oe(t.hass)?m``:m`
${t.t("ble")}
${M(t.t("ble_hint"))}
- `}var eo=(t,e)=>{let n=t._$AN;if(n===void 0)return!1;for(let r of n)r._$AO?.(e,!1),eo(r,e);return!0},bi=t=>{let e,n;do{if((e=t._$AM)===void 0)break;n=e._$AN,n.delete(t),t=e}while(n?.size===0)},th=t=>{for(let e;e=t._$AM;t=e){let n=e._$AN;if(n===void 0)e._$AN=n=new Set;else if(n.has(t))break;n.add(t),Dy(e)}};function Py(t){this._$AN!==void 0?(bi(this),this._$AM=t,th(this)):this._$AM=t}function Iy(t,e=!1,n=0){let r=this._$AH,o=this._$AN;if(o!==void 0&&o.size!==0)if(e)if(Array.isArray(r))for(let i=n;i{t.type==Pn.CHILD&&(t._$AP??=Iy,t._$AQ??=Py)},yi=class extends Dt{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,n,r){super._$AT(e,n,r),th(this),this.isConnected=e._$AU}_$AO(e,n=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),n&&(eo(this,e),bi(this))}setValue(e){if(Uu(this._$Ct))this._$Ct._$AI(e,this);else{let n=[...this._$Ct._$AH];n[this._$Ci]=e,this._$Ct._$AI(n,this,0)}}disconnected(){}reconnected(){}};var Ra=new WeakMap,nh=tn(class extends yi{render(t){return _}update(t,[e]){let n=e!==this.G;return n&&this.rt(void 0),(n||this.lt!==this.ct)&&(this.G=e,this.ht=t.options?.host,this.rt(this.ct=t.element)),_}rt(t){if(this.G!==void 0)if(this.isConnected||(t=void 0),typeof this.G=="function"){let e=this.ht??globalThis,n=Ra.get(e);n===void 0&&(n=new WeakMap,Ra.set(e,n)),n.get(this.G)!==void 0&&this.G.call(this.ht,void 0),n.set(this.G,t),t!==void 0&&this.G.call(this.ht,t)}else this.G.value=t}get lt(){return typeof this.G=="function"?Ra.get(this.ht??globalThis)?.get(this.G):this.G?.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});var rh=t=>t.trim().toLowerCase().replace(/ä/g,"ae").replace(/ö/g,"oe").replace(/ü/g,"ue").replace(/ß/g,"ss").replace(/[^a-z0-9_-]+/g,"_").replace(/^_+|_+$/g,"").slice(0,40);function oh(t){let e=t.t,n=t.doc.settings.card_templates??{},r=Object.keys(n),o=l=>t.change(a=>{a.settings.card_templates=Object.keys(l).length?l:void 0});t.loadCardEditor?.();let i=l=>{t.hass?.callService("nextfloor","reload_screens",l?{template:l}:{})},s=l=>{let a=rh(l.value);!a||a in n||r.length>=20||(l.value="",o({...n,[a]:{}}))};return m`
+ `}var to=(t,e)=>{let n=t._$AN;if(n===void 0)return!1;for(let r of n)r._$AO?.(e,!1),to(r,e);return!0},bi=t=>{let e,n;do{if((e=t._$AM)===void 0)break;n=e._$AN,n.delete(t),t=e}while(n?.size===0)},ih=t=>{for(let e;e=t._$AM;t=e){let n=e._$AN;if(n===void 0)e._$AN=n=new Set;else if(n.has(t))break;n.add(t),Ny(e)}};function Ly(t){this._$AN!==void 0?(bi(this),this._$AM=t,ih(this)):this._$AM=t}function Cy(t,e=!1,n=0){let r=this._$AH,o=this._$AN;if(o!==void 0&&o.size!==0)if(e)if(Array.isArray(r))for(let i=n;i{t.type==Pn.CHILD&&(t._$AP??=Cy,t._$AQ??=Ly)},yi=class extends Dt{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,n,r){super._$AT(e,n,r),ih(this),this.isConnected=e._$AU}_$AO(e,n=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),n&&(to(this,e),bi(this))}setValue(e){if(Xu(this._$Ct))this._$Ct._$AI(e,this);else{let n=[...this._$Ct._$AH];n[this._$Ci]=e,this._$Ct._$AI(n,this,0)}}disconnected(){}reconnected(){}};var Ra=new WeakMap,sh=tn(class extends yi{render(t){return _}update(t,[e]){let n=e!==this.G;return n&&this.rt(void 0),(n||this.lt!==this.ct)&&(this.G=e,this.ht=t.options?.host,this.rt(this.ct=t.element)),_}rt(t){if(this.G!==void 0)if(this.isConnected||(t=void 0),typeof this.G=="function"){let e=this.ht??globalThis,n=Ra.get(e);n===void 0&&(n=new WeakMap,Ra.set(e,n)),n.get(this.G)!==void 0&&this.G.call(this.ht,void 0),n.set(this.G,t),t!==void 0&&this.G.call(this.ht,t)}else this.G.value=t}get lt(){return typeof this.G=="function"?Ra.get(this.ht??globalThis)?.get(this.G):this.G?.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}});var ah=t=>t.trim().toLowerCase().replace(/ä/g,"ae").replace(/ö/g,"oe").replace(/ü/g,"ue").replace(/ß/g,"ss").replace(/[^a-z0-9_-]+/g,"_").replace(/^_+|_+$/g,"").slice(0,40);function lh(t){let e=t.t,n=t.doc.settings.card_templates??{},r=Object.keys(n),o=l=>t.change(a=>{a.settings.card_templates=Object.keys(l).length?l:void 0});t.loadCardEditor?.();let i=l=>{t.hass?.callService("nextfloor","reload_screens",l?{template:l}:{})},s=l=>{let a=ah(l.value);!a||a in n||r.length>=20||(l.value="",o({...n,[a]:{}}))};return m`
${e("card_templates")}${r.length?m` ${r.length} `:_}
${M(e("card_templates_hint"))}
${r.map(l=>m`
${l}
a&&a.setConfig({type:"custom:nextfloor-card",...n[l]}))}
+ ${sh(a=>a&&a.setConfig({type:"custom:nextfloor-card",...n[l]}))}
@config-changed=${a=>{a.stopPropagation();let{type:c,template:u,...d}=a.detail.config;o({...n,[l]:d})}}
>
${t.admin?m`
@@ -613,7 +613,7 @@ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",f
s(l.target.closest("details")?.querySelector("input[type=text]")??document.createElement("input"))}>${e("template_add")}
i()}>${e("template_reload_all")}
`:_}
- `}var vi=.05,Oy=(t,e)=>t.length===e.length&&t.every((n,r)=>Math.abs(n[0]-e[r][0])<.001&&Math.abs(n[1]-e[r][1])<.001),pn=t=>new Map(t.map(e=>[e.id,e]));function Hy(t,e,n,r){let o=e.name,[i,s]=[pn(t.rooms),pn(e.rooms)];for(let h of e.rooms){let f=i.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:o,name:h.name,detail:f.name}),Oy(f.points,h.points)||n.push({kind:"room_reshaped",floor:o,name:h.name,detail:Math.round((ke(h.points)-ke(f.points))*10)/10})):n.push({kind:"room_added",floor:o,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:o,name:h.name});let[l,a]=[pn(t.openings),pn(e.openings)];for(let h of e.openings)l.has(h.id)||n.push({kind:"opening_added",floor:o,name:h.type,detail:r(h.room_id)});for(let h of t.openings)a.has(h.id)||n.push({kind:"opening_removed",floor:o,name:h.type,detail:r(h.room_id)});let[c,u]=[pn(t.furniture),pn(e.furniture)];for(let h of e.furniture){let f=c.get(h.id);f?(Math.hypot(h.x-f.x,h.z-f.z)>vi||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>vi||Math.abs(h.d-f.d)>vi)&&n.push({kind:"furniture_moved",floor:o,name:h.name||h.type}):n.push({kind:"furniture_added",floor:o,name:h.name||h.type})}for(let h of t.furniture)u.has(h.id)||n.push({kind:"furniture_removed",floor:o,name:h.name||h.type});let[d,p]=[new Map(t.placements.map(h=>[h.entity_id,h])),new Map(e.placements.map(h=>[h.entity_id,h]))];for(let h of e.placements){let f=d.get(h.entity_id);f?Math.hypot(h.x-f.x,h.z-f.z)>vi&&n.push({kind:"device_moved",floor:o,name:h.entity_id}):n.push({kind:"device_added",floor:o,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:o,name:h.entity_id})}function ih(t,e){let n=[],r=pn(t.floors),o=new Map([...t.floors,...e.floors].flatMap(l=>l.rooms.map(a=>[a.id,a.name]))),i=l=>o.get(l)??"";for(let l of e.floors){let a=r.get(l.id);a?Hy(a,l,n,i):n.push({kind:"floor_added",floor:l.name,name:l.name})}let s=new Set(e.floors.map(l=>l.id));for(let l of t.floors)s.has(l.id)||n.push({kind:"floor_removed",floor:l.name,name:l.name});return n}var fn=(t,e)=>t.getUint16(e,!0),to=(t,e)=>t.getUint32(e,!0);function sh(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=-1;for(let l=t.length-22;l>=Math.max(0,t.length-65557);l--)if(to(e,l)===101010256){n=l;break}if(n<0)throw new Error("not_zip");let r=fn(e,n+10),o=to(e,n+16),i=[],s=new TextDecoder;for(let l=0;l",quot:'"',apos:"'"},Cy=t=>t.replace(/&(#x?[0-9a-f]+|\w+);/gi,(e,n)=>n[0]==="#"?String.fromCodePoint(Number.parseInt(n.slice(n[1]==="x"?2:1),n[1]==="x"?16:10)):Ly[n]??e);function Ny(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=Cy(n[2]??n[3]);return e}function By(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,o,i,s,l]=r;if(o){i==="room"&&(n=null);continue}let a=Ny(s);if(i==="point"){n&&n.points.push([Number(a.x)/100,Number(a.y)/100]);continue}let c={name:i,attrs:a,...i==="room"?{points:[]}:{}};e.push(c),i==="room"&&!l&&(n=c)}return e}var oe=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Ee=t=>Math.round(t*1e3)/1e3;function lh(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.max(0,Math.min(i,((t[0]-e[0])*r+(t[1]-e[1])*o)/i)),l=[e[0]+r*s/i,e[1]+o*s/i];return{dist:Math.hypot(t[0]-l[0],t[1]-l[1]),along:s,length:i}}function Wy(t){let e=`${t.name??""} ${t.catalogId??""}`.toLowerCase();return/garage|sectional|rolltor/.test(e)?"garage":/door|tür|tuer|porte|puerta|deur|haustür/.test(e)&&!/window|fenster/.test(e)?"door":"window"}function Vy(t,e){let n=t.length,r=t.map((o,i)=>{let s=t[(i+1)%n],[l,a]=[s[0]-o[0],s[1]-o[1]],c=Math.hypot(l,a)||1e-9,u=[l/c,a/c],d=[(o[0]+s[0])/2,(o[1]+s[1])/2],p=[0,0];for(let h of e){let[f,g]=[h.b[0]-h.a[0],h.b[1]-h.a[1]],y=Math.hypot(f,g)||1e-9;if(Math.abs((u[0]*g-u[1]*f)/y)>.05)continue;let b=(h.a[0]-d[0])*-u[1]+(h.a[1]-d[1])*u[0],v=((d[0]-h.a[0])*f+(d[1]-h.a[1])*g)/y;if(!(Math.abs(b)>h.thickness/2+.06||v<-.05||v>y+.05)){p=[-u[1]*b,u[0]*b];break}}return{p:[o[0]+p[0],o[1]+p[1]],dir:u}});return r.map((o,i)=>{let s=r[(i-1+n)%n],l=s.dir[0]*o.dir[1]-s.dir[1]*o.dir[0];if(Math.abs(l)<1e-6)return o.p;let a=((o.p[0]-s.p[0])*o.dir[1]-(o.p[1]-s.p[1])*o.dir[0])/l;return[s.p[0]+s.dir[0]*a,s.p[1]+s.dir[1]*a]})}function Ky(t){let e=Ft(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(a=>a.name==="level"),o=r.length?r.map(a=>a.attrs.id??""):[""],i=t.filter(a=>a.name==="wall"),s=i.length?Math.max(...i.map(a=>oe(a.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((a,c)=>oe(a.attrs,"elevation",0)-oe(c.attrs,"elevation",0)||oe(a.attrs,"elevationIndex",0)-oe(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((a,c)=>{let u=a.attrs.id??"",d=y=>r.length?(y.attrs.level??o[0])===u:!0,p=Ce(I("floor"),a.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Ee(oe(a.attrs,"elevation",0)/100));p.height=Ee(oe(a.attrs,"height",s*100)/100);let h=i.filter(d).map(y=>({a:[oe(y.attrs,"xStart",0)/100,oe(y.attrs,"yStart",0)/100],b:[oe(y.attrs,"xEnd",0)/100,oe(y.attrs,"yEnd",0)/100],thickness:oe(y.attrs,"thickness",10)/100})),f=t.filter(y=>y.name==="room"&&d(y)&&(y.points?.length??0)>=3).map((y,b)=>({id:I("room"),name:y.attrs.name||`Raum ${b+1}`,area_id:null,points:Vy(y.points,h).map(([v,w])=>[Ee(v),Ee(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let y of t.filter(b=>b.name==="doorOrWindow"&&d(b))){let b=[oe(y.attrs,"x",0)/100,oe(y.attrs,"y",0)/100],v=Math.max(.6,oe(y.attrs,"depth",30)/100+.3),w=null;for(let O of f)O.points.forEach((P,C)=>{let B=lh(b,P,O.points[(C+1)%O.points.length]);B.dist<=v&&(!w||B.dist1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let y of i.filter(d)){let b=[oe(y.attrs,"xStart",0)/100,oe(y.attrs,"yStart",0)/100],v=[oe(y.attrs,"xEnd",0)/100,oe(y.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-b[0],v[1]-b[1])<.1)continue;let w=Math.max(.15,oe(y.attrs,"thickness",10)/100),x=F=>f.some(O=>O.points.some((P,C)=>lh(F,P,O.points[(C+1)%O.points.length]).dist[b[0]+(v[0]-b[0])*F/S,b[1]+(v[1]-b[1])*F/S],T=Array.from({length:S+1},(F,O)=>!x(E(O)));for(let F=0;F<=S;){if(!T[F]){F++;continue}let O=F;for(;O+1<=S&&T[O+1];)O++;let[P,C]=[E(Math.max(0,F-1)),E(Math.min(S,O+1))];Math.hypot(C[0]-P[0],C[1]-P[1])>=.3&&g.push({id:I("wall"),a:[Ee(P[0]),Ee(P[1])],b:[Ee(C[0]),Ee(C[1])],thickness:Ee(oe(y.attrs,"thickness",10)/100),height:y.attrs.height?Ee(oe(y.attrs,"height",250)/100):null}),F=O+1}}p.walls=g,n.rooms+=f.length,n.openings+=p.openings.length,n.walls+=g.length,(f.length||g.length)&&e.floors.push(p)}),n.floors=e.floors.length,n.furniture=t.filter(a=>a.name==="pieceOfFurniture").length,{building:Pe(e),report:n}}async function ch(t){let e=sh(t).find(o=>o.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await ah(t,e)),r=Ky(By(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function jy(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1r===9&&o==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function Uy(t){let e=jy(t),n=Gy(e),r=e.findIndex(([s,l],a)=>s===2&&l==="ENTITIES"&&e[a-1]?.[1]==="SECTION"),o=[];if(r<0)return{shapes:o,unit:n};let i=r+1;for(;iNumber(c.find(([h])=>h===p)?.[1]??NaN),d=[[u(10),u(20)],[u(11),u(21)]];d.every(([p,h])=>Number.isFinite(p)&&Number.isFinite(h))&&o.push({points:d,closed:!1})}else if(l==="LWPOLYLINE"){let u=c.filter(([f])=>f===10).map(([,f])=>Number(f)),d=c.filter(([f])=>f===20).map(([,f])=>Number(f)),p=Number(c.find(([f])=>f===70)?.[1]??0),h=u.map((f,g)=>[f,d[g]]).filter(([f,g])=>Number.isFinite(f)&&Number.isFinite(g));h.length>=2&&o.push({points:h,closed:(p&1)===1})}i=a}return{shapes:o,unit:n}}var uh=t=>Math.round(t*1e3)/1e3;function dh(t){let{shapes:e,unit:n}=Uy(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),o=Math.max(Math.max(...r.map(h=>h[0]))-Math.min(...r.map(h=>h[0])),Math.max(...r.map(h=>h[1]))-Math.min(...r.map(h=>h[1]))),i=n??(o>2e3?.001:o>200?.01:1),s=Math.min(...r.map(h=>h[0])),l=Math.max(...r.map(h=>h[1])),a=([h,f])=>[uh((h-s)*i),uh((l-f)*i)],c=Ce(I("floor"),"Erdgeschoss",0),u=[],d=[];for(let h of e){let f=h.points.map(a);if(h.closed&&f.length>=3)u.push({id:I("room"),name:`Raum ${u.length+1}`,area_id:null,points:f,floor_material:"wood",panel:[]});else for(let g=0;g+1.05&&d.push({id:I("wall"),a:f[g],b:f[g+1]})}c.rooms=u,c.walls=d;let p=Ft();return p.floors=[c],{building:Pe(p),report:{floors:1,rooms:u.length,openings:0,walls:d.length,furniture:0}}}var qe=t=>Math.round(t*100)/100;function Zy(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function qy(t,e){let n=t,r=n?.transform,o=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(o)||o.length<3)return null;let i=l=>Number(l),s=Math.hypot(i(r[0]),i(r[2]));return![...r.slice(0,16),...o.slice(0,3)].every(l=>Number.isFinite(i(l)))||s<1e-6?null:{centre:[i(r[12]),i(r[13]),i(r[14])],dir:[i(r[0])/s,i(r[2])/s],size:[i(o[0]),i(o[1]),i(o[2])],kind:Zy(n,e)}}var Zn=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>qy(r,n)).filter(r=>!!r);function Yy(t){if(t.length<3)return null;let e=t.map(a=>{let c=a.size[0]/2;return[[a.centre[0]-a.dir[0]*c,a.centre[2]-a.dir[1]*c],[a.centre[0]+a.dir[0]*c,a.centre[2]+a.dir[1]*c]]}),n=(a,c)=>Math.hypot(a[0]-c[0],a[1]-c[1]),r=.4,o=new Set([0]),i=[e[0][0]],s=[0],l=e[0][1];for(;o.sizer?null:(i[0]=[(l[0]+i[0][0])/2,(l[1]+i[0][1])/2],{points:i,edgeWall:s})}function hh(t){let e=[],n=[];for(let l of t){let a=l.size[0]/2;for(let c of[-1,1])e.push(l.centre[0]+c*l.dir[0]*a),n.push(l.centre[2]+c*l.dir[1]*a)}let[r,o,i,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,i],[o,i],[o,s],[r,s]]}function Xy(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.min(i,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*o)/i));return{dist:Math.hypot(t[0]-(e[0]+r/i*s),t[1]-(e[1]+o/i*s)),along:s,length:i}}var Qy={sofa:"sofa",bed:"bed",table:"table",chair:"chair",bathtub:"bathtub",toilet:"wc",sink:"sink",refrigerator:"fridge",stove:"stove",oven:"stove",dishwasher:"dishwasher",washerDryer:"washer",storage:"tall_cabinet",television:"tv_board"};function ph(t){let e=t;return!e||typeof e!="object"||"floors"in e||"settings"in e?!1:(Array.isArray(e.rooms)?e.rooms:[e]).some(r=>r&&Array.isArray(r.walls)&&Zn(r,"walls","wall").length>0)}function fh(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(y=>y&&typeof y=="object").map(y=>({walls:Zn(y,"walls","wall"),doors:[...Zn(y,"doors","door"),...Zn(y,"openings","opening")],windows:Zn(y,"windows","window"),objects:Zn(y,"objects","object")})).filter(y=>y.walls.length);if(!r.length)throw new Error("roomplan_empty");let o=r.flatMap(y=>y.walls),i=Math.min(...o.map(y=>y.centre[1]-y.size[1]/2)),s=r.map(y=>Yy(y.walls)),l=r.flatMap((y,b)=>s[b]?.points??hh(y.walls)),[a,c]=[Math.min(...l.map(y=>y[0]))-.5,Math.min(...l.map(y=>y[1]))-.5],u=([y,b])=>[qe(y-a),qe(b-c)],d=Ce(I("floor"),"Erdgeschoss",0);d.height=qe(Math.max(2.2,Math.min(4,Math.max(...o.map(y=>y.size[1])))));let p=[],h=[];r.forEach((y,b)=>{let w=(s[b]?.points??hh(y.walls)).map(u),x={id:I("room"),name:`Raum ${b+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(x);for(let k of[...y.doors.map(S=>({v:S,window:!1})),...y.windows.map(S=>({v:S,window:!0}))]){let S=[k.v.centre[0]-a,k.v.centre[2]-c],E=null;if(w.forEach((P,C)=>{let B=Xy(S,P,w[(C+1)%w.length]);B.dist<=.6&&(!E||B.dist1.4?2:1,swing:"in",...O?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let k of y.objects){let S=Qy[k.kind];if(!S)continue;let[E,T,F]=[k.size[0],k.size[2],k.size[1]];E<.1||T<.1||h.push({id:I("f"),type:S,x:qe(k.centre[0]-a),z:qe(k.centre[2]-c),rotation:Math.round((Math.atan2(k.dir[1],k.dir[0])*180/Math.PI+360)%360),w:qe(E),d:qe(T),h:qe(F),variant:null,entity:null,power:null})}}),d.rooms=p,d.furniture=h;let f=Ft();f.floors=[d];let g=r.reduce((y,b)=>y+b.objects.length,0)-h.length;return{building:Pe(f),report:{floors:1,rooms:p.length,openings:d.openings.length,walls:0,furniture:g}}}var no=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function Jy(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let o=t[e];if(o==="("){e++;let a=[];for(;eString.fromCharCode(...(n.match(/.{4}/g)??[]).map(r=>parseInt(r,16)))).replace(/\\S\\(.)/g,(e,n)=>String.fromCharCode(n.charCodeAt(0)+128))}function tv(t){let e=new Map,n=t.slice(Math.max(0,t.indexOf("DATA;")));for(let r of n.matchAll(/#(\d+)\s*=\s*([A-Z0-9_]+)\s*\(([\s\S]*?)\)\s*;(?=\s*(?:#|ENDSEC))/g))e.set(Number(r[1]),{type:r[2],args:Jy(r[3])});return e}var mh={x:0,y:0,z:0,c:1,s:0},gh=(t,e)=>({x:t.x+t.c*e.x-t.s*e.y,y:t.y+t.s*e.x+t.c*e.y,z:t.z+e.z,c:t.c*e.c-t.s*e.s,s:t.s*e.c+t.c*e.s});function _h(t){let e=tv(t);if(!e.size)throw new Error("ifc_empty");let n=k=>no(k)?e.get(k.ref):void 0,r=k=>typeof k=="number"?k:NaN,o=k=>(n(k)?.args[0]??[]).map(S=>r(S)),i=[...e.values()].find(k=>k.type==="IFCSIUNIT"&&k.args[1]===".LENGTHUNIT."),s=i?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(i.args[2])]??1:1,l=k=>{let S=n(k);if(!S)return mh;let[E=0,T=0,F=0]=o(S.args[0]),O=n(S.type==="IFCAXIS2PLACEMENT3D"?S.args[2]:S.args[1]),[P=1,C=0]=(O?.args[0]??[]).map(q=>r(q)),B=Math.hypot(P,C)||1;return{x:E||0,y:T||0,z:F||0,c:P/B,s:C/B}},a=(k,S=0)=>{let E=n(k);return!E||E.type!=="IFCLOCALPLACEMENT"||S>30?mh:gh(a(E.args[0],S+1),l(E.args[1]))},c=k=>{for(let S of n(k)?.args[2]??[])for(let E of n(S)?.args[3]??[]){let T=n(E);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),O=gh(l(T.args[1]),l(F?.args[2])),P=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[C,B]=[r(F.args[3])/2,r(F.args[4])/2];P=[[-C,-B],[C,-B],[C,B],[-C,B]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let C=n(F.args[2]);C?.type==="IFCPOLYLINE"&&(P=(C.args[0]??[]).map(B=>o(B)))}if(P=P.filter(C=>Number.isFinite(C[0])&&Number.isFinite(C[1])),P.length>3&&Math.hypot(P[0][0]-P[P.length-1][0],P[0][1]-P[P.length-1][1])<1e-6&&P.pop(),P.length>=3)return P.map(([C,B])=>[O.x+O.c*C-O.s*B,O.y+O.s*C+O.c*B])}return null},u=new Map;for(let[,k]of e){if(k.type==="IFCRELAGGREGATES"&&no(k.args[4]))for(let S of k.args[5]??[])no(S)&&u.set(S.ref,k.args[4].ref);if(k.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&no(k.args[5]))for(let S of k.args[4]??[])no(S)&&u.set(S.ref,k.args[5].ref)}let d=[...e].filter(([,k])=>k.type==="IFCBUILDINGSTOREY").map(([k,S])=>({id:k,name:String(S.args[7]||S.args[2]||"")||null,elevation:r(S.args[9])*s}));d.sort((k,S)=>(k.elevation||0)-(S.elevation||0));let p=[];for(let[k,S]of e){if(S.type!=="IFCSPACE")continue;let E=c(S.args[6]);if(!E)continue;let T=a(S.args[5]),F=E.map(([P,C])=>[(T.x+T.c*P-T.s*C)*s,(T.y+T.s*P+T.c*C)*s]),O=String(S.args[7]||S.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:u.get(k)??null,name:O,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(k=>k.ring),f=Math.min(...h.map(k=>k[0])),g=Math.max(...h.map(k=>k[1])),y=k=>Math.round(k*1e3)/1e3,b=[],v=new Map;if(d.filter(k=>p.some(S=>S.storey===k.id)).forEach((k,S)=>{let E=Ce(I("floor"),k.name??`Etage ${S+1}`,Number.isFinite(k.elevation)?y(k.elevation):S*2.8);b.push(E),v.set(k.id,E)}),p.some(k=>k.storey===null||!v.has(k.storey))){let k=Ce(I("floor"),b.length?"Weitere R\xE4ume":"Erdgeschoss",b.length?b[b.length-1].elevation+2.8:0);b.push(k),v.set(null,k)}b.forEach((k,S)=>{let E=b[S+1];E&&E.elevation-k.elevation>1.8&&(k.height=y(E.elevation-k.elevation-.2))});for(let k of p)v.get(k.storey!==null&&v.has(k.storey)?k.storey:null).rooms.push({id:I("room"),name:k.name,area_id:null,points:k.ring.map(([E,T])=>[y(E-f),y(g-T)]),floor_material:"wood",panel:[]});let x=Ft();return x.floors=b,{building:Pe(x),report:{floors:b.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var yh="nextfloor",nv="alarm_control_panel|automation|binary_sensor|button|calendar|camera|climate|conversation|cover|date|datetime|device_tracker|event|fan|group|humidifier|image|input_boolean|input_button|input_datetime|input_number|input_select|input_text|lawn_mower|light|lock|media_player|notify|number|person|remote|scene|script|select|sensor|siren|stt|sun|switch|text|time|timer|todo|tts|update|vacuum|valve|water_heater|weather|zone",bh=new RegExp(`^(?:${nv})\\.[a-z0-9_]+$`),rv=/^[0-9a-f]{32}$/,ov=new Set(["area_id","ha_floor"]),iv=new Set(["sub_areas"]),sv=new Set(["tap","show_when","pictures","moods"]);function Ea(t){if(typeof t=="string")return bh.test(t)||rv.test(t)?null:t;if(Array.isArray(t))return t.map(e=>Ea(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))bh.test(n)||sv.has(n)||(ov.has(n)||iv.has(n)?e[n]=null:e[n]=Ea(r));return e}return t}var av=["wall_exterior","wall_interior","wall_paint_outside","wall_paint_inside","grid","north","roof","weather_effects","rain_warning","sun_patches","lock_plan","start_view","units","motion_markers_active","room_double_tap"];function vh(t){let e=structuredClone(t),n={};for(let o of av)e.settings?.[o]!==void 0&&(n[o]=e.settings[o]);let r=e.settings?.backdrop;r&&(r.color||r.dim!=null)&&(n.backdrop={color:r.color??null,dim:r.dim??null}),e.settings=n,e.energy={...e.energy,grid:null,solar:null,battery:null,battery_soc:null,tariff:null,consumption:null,gas:null,water:null},e.presence=[];for(let o of e.floors){o.background=null,o.placements=[],o.power_entity=null,o.utility_meters=null,o.ha_floor=null;for(let i of o.rooms)Object.assign(i,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});o.furniture.forEach(i=>{Object.assign(i,{entity:null,power:null}),delete i.effect_animations,i.picture&&!(i.picture.startsWith("image:")||i.picture.startsWith("https://"))&&(i.picture=null)}),o.openings.forEach(i=>Object.assign(i,{cover:null,contact:null,tilt:null}))}return Ea(e)}function wh(t,e){return{format:yh,version:1,exported_at:new Date().toISOString(),building:e?vh(t):structuredClone(t)}}var lv=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),cv="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function kh(t,e,n,r,o=cv){let i=new Set(t.floors.flatMap(c=>c.furniture.map(u=>u.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:vh(t),packs:e.filter(c=>!c.builtin&&i.has(c.id))},l=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u]);return`
+ `}var vi=.05,By=(t,e)=>t.length===e.length&&t.every((n,r)=>Math.abs(n[0]-e[r][0])<.001&&Math.abs(n[1]-e[r][1])<.001),pn=t=>new Map(t.map(e=>[e.id,e]));function Wy(t,e,n,r){let o=e.name,[i,s]=[pn(t.rooms),pn(e.rooms)];for(let h of e.rooms){let f=i.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:o,name:h.name,detail:f.name}),By(f.points,h.points)||n.push({kind:"room_reshaped",floor:o,name:h.name,detail:Math.round((ke(h.points)-ke(f.points))*10)/10})):n.push({kind:"room_added",floor:o,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:o,name:h.name});let[l,a]=[pn(t.openings),pn(e.openings)];for(let h of e.openings)l.has(h.id)||n.push({kind:"opening_added",floor:o,name:h.type,detail:r(h.room_id)});for(let h of t.openings)a.has(h.id)||n.push({kind:"opening_removed",floor:o,name:h.type,detail:r(h.room_id)});let[c,u]=[pn(t.furniture),pn(e.furniture)];for(let h of e.furniture){let f=c.get(h.id);f?(Math.hypot(h.x-f.x,h.z-f.z)>vi||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>vi||Math.abs(h.d-f.d)>vi)&&n.push({kind:"furniture_moved",floor:o,name:h.name||h.type}):n.push({kind:"furniture_added",floor:o,name:h.name||h.type})}for(let h of t.furniture)u.has(h.id)||n.push({kind:"furniture_removed",floor:o,name:h.name||h.type});let[d,p]=[new Map(t.placements.map(h=>[h.entity_id,h])),new Map(e.placements.map(h=>[h.entity_id,h]))];for(let h of e.placements){let f=d.get(h.entity_id);f?Math.hypot(h.x-f.x,h.z-f.z)>vi&&n.push({kind:"device_moved",floor:o,name:h.entity_id}):n.push({kind:"device_added",floor:o,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:o,name:h.entity_id})}function ch(t,e){let n=[],r=pn(t.floors),o=new Map([...t.floors,...e.floors].flatMap(l=>l.rooms.map(a=>[a.id,a.name]))),i=l=>o.get(l)??"";for(let l of e.floors){let a=r.get(l.id);a?Wy(a,l,n,i):n.push({kind:"floor_added",floor:l.name,name:l.name})}let s=new Set(e.floors.map(l=>l.id));for(let l of t.floors)s.has(l.id)||n.push({kind:"floor_removed",floor:l.name,name:l.name});return n}var fn=(t,e)=>t.getUint16(e,!0),no=(t,e)=>t.getUint32(e,!0);function uh(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=-1;for(let l=t.length-22;l>=Math.max(0,t.length-65557);l--)if(no(e,l)===101010256){n=l;break}if(n<0)throw new Error("not_zip");let r=fn(e,n+10),o=no(e,n+16),i=[],s=new TextDecoder;for(let l=0;l",quot:'"',apos:"'"},Ky=t=>t.replace(/&(#x?[0-9a-f]+|\w+);/gi,(e,n)=>n[0]==="#"?String.fromCodePoint(Number.parseInt(n.slice(n[1]==="x"?2:1),n[1]==="x"?16:10)):Vy[n]??e);function jy(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=Ky(n[2]??n[3]);return e}function Gy(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,o,i,s,l]=r;if(o){i==="room"&&(n=null);continue}let a=jy(s);if(i==="point"){n&&n.points.push([Number(a.x)/100,Number(a.y)/100]);continue}let c={name:i,attrs:a,...i==="room"?{points:[]}:{}};e.push(c),i==="room"&&!l&&(n=c)}return e}var ie=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Ee=t=>Math.round(t*1e3)/1e3;function hh(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.max(0,Math.min(i,((t[0]-e[0])*r+(t[1]-e[1])*o)/i)),l=[e[0]+r*s/i,e[1]+o*s/i];return{dist:Math.hypot(t[0]-l[0],t[1]-l[1]),along:s,length:i}}function Uy(t){let e=`${t.name??""} ${t.catalogId??""}`.toLowerCase();return/garage|sectional|rolltor/.test(e)?"garage":/door|tür|tuer|porte|puerta|deur|haustür/.test(e)&&!/window|fenster/.test(e)?"door":"window"}function Zy(t,e){let n=t.length,r=t.map((o,i)=>{let s=t[(i+1)%n],[l,a]=[s[0]-o[0],s[1]-o[1]],c=Math.hypot(l,a)||1e-9,u=[l/c,a/c],d=[(o[0]+s[0])/2,(o[1]+s[1])/2],p=[0,0];for(let h of e){let[f,g]=[h.b[0]-h.a[0],h.b[1]-h.a[1]],y=Math.hypot(f,g)||1e-9;if(Math.abs((u[0]*g-u[1]*f)/y)>.05)continue;let b=(h.a[0]-d[0])*-u[1]+(h.a[1]-d[1])*u[0],v=((d[0]-h.a[0])*f+(d[1]-h.a[1])*g)/y;if(!(Math.abs(b)>h.thickness/2+.06||v<-.05||v>y+.05)){p=[-u[1]*b,u[0]*b];break}}return{p:[o[0]+p[0],o[1]+p[1]],dir:u}});return r.map((o,i)=>{let s=r[(i-1+n)%n],l=s.dir[0]*o.dir[1]-s.dir[1]*o.dir[0];if(Math.abs(l)<1e-6)return o.p;let a=((o.p[0]-s.p[0])*o.dir[1]-(o.p[1]-s.p[1])*o.dir[0])/l;return[s.p[0]+s.dir[0]*a,s.p[1]+s.dir[1]*a]})}function qy(t){let e=Ft(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(a=>a.name==="level"),o=r.length?r.map(a=>a.attrs.id??""):[""],i=t.filter(a=>a.name==="wall"),s=i.length?Math.max(...i.map(a=>ie(a.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((a,c)=>ie(a.attrs,"elevation",0)-ie(c.attrs,"elevation",0)||ie(a.attrs,"elevationIndex",0)-ie(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((a,c)=>{let u=a.attrs.id??"",d=y=>r.length?(y.attrs.level??o[0])===u:!0,p=Ce(I("floor"),a.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Ee(ie(a.attrs,"elevation",0)/100));p.height=Ee(ie(a.attrs,"height",s*100)/100);let h=i.filter(d).map(y=>({a:[ie(y.attrs,"xStart",0)/100,ie(y.attrs,"yStart",0)/100],b:[ie(y.attrs,"xEnd",0)/100,ie(y.attrs,"yEnd",0)/100],thickness:ie(y.attrs,"thickness",10)/100})),f=t.filter(y=>y.name==="room"&&d(y)&&(y.points?.length??0)>=3).map((y,b)=>({id:I("room"),name:y.attrs.name||`Raum ${b+1}`,area_id:null,points:Zy(y.points,h).map(([v,w])=>[Ee(v),Ee(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let y of t.filter(b=>b.name==="doorOrWindow"&&d(b))){let b=[ie(y.attrs,"x",0)/100,ie(y.attrs,"y",0)/100],v=Math.max(.6,ie(y.attrs,"depth",30)/100+.3),w=null;for(let O of f)O.points.forEach((P,C)=>{let B=hh(b,P,O.points[(C+1)%O.points.length]);B.dist<=v&&(!w||B.dist1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let y of i.filter(d)){let b=[ie(y.attrs,"xStart",0)/100,ie(y.attrs,"yStart",0)/100],v=[ie(y.attrs,"xEnd",0)/100,ie(y.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-b[0],v[1]-b[1])<.1)continue;let w=Math.max(.15,ie(y.attrs,"thickness",10)/100),x=F=>f.some(O=>O.points.some((P,C)=>hh(F,P,O.points[(C+1)%O.points.length]).dist[b[0]+(v[0]-b[0])*F/S,b[1]+(v[1]-b[1])*F/S],T=Array.from({length:S+1},(F,O)=>!x(E(O)));for(let F=0;F<=S;){if(!T[F]){F++;continue}let O=F;for(;O+1<=S&&T[O+1];)O++;let[P,C]=[E(Math.max(0,F-1)),E(Math.min(S,O+1))];Math.hypot(C[0]-P[0],C[1]-P[1])>=.3&&g.push({id:I("wall"),a:[Ee(P[0]),Ee(P[1])],b:[Ee(C[0]),Ee(C[1])],thickness:Ee(ie(y.attrs,"thickness",10)/100),height:y.attrs.height?Ee(ie(y.attrs,"height",250)/100):null}),F=O+1}}p.walls=g,n.rooms+=f.length,n.openings+=p.openings.length,n.walls+=g.length,(f.length||g.length)&&e.floors.push(p)}),n.floors=e.floors.length,n.furniture=t.filter(a=>a.name==="pieceOfFurniture").length,{building:Pe(e),report:n}}async function ph(t){let e=uh(t).find(o=>o.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await dh(t,e)),r=qy(Gy(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function Yy(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1r===9&&o==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function Qy(t){let e=Yy(t),n=Xy(e),r=e.findIndex(([s,l],a)=>s===2&&l==="ENTITIES"&&e[a-1]?.[1]==="SECTION"),o=[];if(r<0)return{shapes:o,unit:n};let i=r+1;for(;iNumber(c.find(([h])=>h===p)?.[1]??NaN),d=[[u(10),u(20)],[u(11),u(21)]];d.every(([p,h])=>Number.isFinite(p)&&Number.isFinite(h))&&o.push({points:d,closed:!1})}else if(l==="LWPOLYLINE"){let u=c.filter(([f])=>f===10).map(([,f])=>Number(f)),d=c.filter(([f])=>f===20).map(([,f])=>Number(f)),p=Number(c.find(([f])=>f===70)?.[1]??0),h=u.map((f,g)=>[f,d[g]]).filter(([f,g])=>Number.isFinite(f)&&Number.isFinite(g));h.length>=2&&o.push({points:h,closed:(p&1)===1})}i=a}return{shapes:o,unit:n}}var fh=t=>Math.round(t*1e3)/1e3;function mh(t){let{shapes:e,unit:n}=Qy(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),o=Math.max(Math.max(...r.map(h=>h[0]))-Math.min(...r.map(h=>h[0])),Math.max(...r.map(h=>h[1]))-Math.min(...r.map(h=>h[1]))),i=n??(o>2e3?.001:o>200?.01:1),s=Math.min(...r.map(h=>h[0])),l=Math.max(...r.map(h=>h[1])),a=([h,f])=>[fh((h-s)*i),fh((l-f)*i)],c=Ce(I("floor"),"Erdgeschoss",0),u=[],d=[];for(let h of e){let f=h.points.map(a);if(h.closed&&f.length>=3)u.push({id:I("room"),name:`Raum ${u.length+1}`,area_id:null,points:f,floor_material:"wood",panel:[]});else for(let g=0;g+1.05&&d.push({id:I("wall"),a:f[g],b:f[g+1]})}c.rooms=u,c.walls=d;let p=Ft();return p.floors=[c],{building:Pe(p),report:{floors:1,rooms:u.length,openings:0,walls:d.length,furniture:0}}}var qe=t=>Math.round(t*100)/100;function Jy(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function ev(t,e){let n=t,r=n?.transform,o=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(o)||o.length<3)return null;let i=l=>Number(l),s=Math.hypot(i(r[0]),i(r[2]));return![...r.slice(0,16),...o.slice(0,3)].every(l=>Number.isFinite(i(l)))||s<1e-6?null:{centre:[i(r[12]),i(r[13]),i(r[14])],dir:[i(r[0])/s,i(r[2])/s],size:[i(o[0]),i(o[1]),i(o[2])],kind:Jy(n,e)}}var Zn=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>ev(r,n)).filter(r=>!!r);function tv(t){if(t.length<3)return null;let e=t.map(a=>{let c=a.size[0]/2;return[[a.centre[0]-a.dir[0]*c,a.centre[2]-a.dir[1]*c],[a.centre[0]+a.dir[0]*c,a.centre[2]+a.dir[1]*c]]}),n=(a,c)=>Math.hypot(a[0]-c[0],a[1]-c[1]),r=.4,o=new Set([0]),i=[e[0][0]],s=[0],l=e[0][1];for(;o.sizer?null:(i[0]=[(l[0]+i[0][0])/2,(l[1]+i[0][1])/2],{points:i,edgeWall:s})}function gh(t){let e=[],n=[];for(let l of t){let a=l.size[0]/2;for(let c of[-1,1])e.push(l.centre[0]+c*l.dir[0]*a),n.push(l.centre[2]+c*l.dir[1]*a)}let[r,o,i,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,i],[o,i],[o,s],[r,s]]}function nv(t,e,n){let[r,o]=[n[0]-e[0],n[1]-e[1]],i=Math.hypot(r,o)||1e-9,s=Math.min(i,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*o)/i));return{dist:Math.hypot(t[0]-(e[0]+r/i*s),t[1]-(e[1]+o/i*s)),along:s,length:i}}var rv={sofa:"sofa",bed:"bed",table:"table",chair:"chair",bathtub:"bathtub",toilet:"wc",sink:"sink",refrigerator:"fridge",stove:"stove",oven:"stove",dishwasher:"dishwasher",washerDryer:"washer",storage:"tall_cabinet",television:"tv_board"};function _h(t){let e=t;return!e||typeof e!="object"||"floors"in e||"settings"in e?!1:(Array.isArray(e.rooms)?e.rooms:[e]).some(r=>r&&Array.isArray(r.walls)&&Zn(r,"walls","wall").length>0)}function bh(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(y=>y&&typeof y=="object").map(y=>({walls:Zn(y,"walls","wall"),doors:[...Zn(y,"doors","door"),...Zn(y,"openings","opening")],windows:Zn(y,"windows","window"),objects:Zn(y,"objects","object")})).filter(y=>y.walls.length);if(!r.length)throw new Error("roomplan_empty");let o=r.flatMap(y=>y.walls),i=Math.min(...o.map(y=>y.centre[1]-y.size[1]/2)),s=r.map(y=>tv(y.walls)),l=r.flatMap((y,b)=>s[b]?.points??gh(y.walls)),[a,c]=[Math.min(...l.map(y=>y[0]))-.5,Math.min(...l.map(y=>y[1]))-.5],u=([y,b])=>[qe(y-a),qe(b-c)],d=Ce(I("floor"),"Erdgeschoss",0);d.height=qe(Math.max(2.2,Math.min(4,Math.max(...o.map(y=>y.size[1])))));let p=[],h=[];r.forEach((y,b)=>{let w=(s[b]?.points??gh(y.walls)).map(u),x={id:I("room"),name:`Raum ${b+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(x);for(let k of[...y.doors.map(S=>({v:S,window:!1})),...y.windows.map(S=>({v:S,window:!0}))]){let S=[k.v.centre[0]-a,k.v.centre[2]-c],E=null;if(w.forEach((P,C)=>{let B=nv(S,P,w[(C+1)%w.length]);B.dist<=.6&&(!E||B.dist1.4?2:1,swing:"in",...O?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let k of y.objects){let S=rv[k.kind];if(!S)continue;let[E,T,F]=[k.size[0],k.size[2],k.size[1]];E<.1||T<.1||h.push({id:I("f"),type:S,x:qe(k.centre[0]-a),z:qe(k.centre[2]-c),rotation:Math.round((Math.atan2(k.dir[1],k.dir[0])*180/Math.PI+360)%360),w:qe(E),d:qe(T),h:qe(F),variant:null,entity:null,power:null})}}),d.rooms=p,d.furniture=h;let f=Ft();f.floors=[d];let g=r.reduce((y,b)=>y+b.objects.length,0)-h.length;return{building:Pe(f),report:{floors:1,rooms:p.length,openings:d.openings.length,walls:0,furniture:g}}}var ro=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function ov(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let o=t[e];if(o==="("){e++;let a=[];for(;eString.fromCharCode(...(n.match(/.{4}/g)??[]).map(r=>parseInt(r,16)))).replace(/\\S\\(.)/g,(e,n)=>String.fromCharCode(n.charCodeAt(0)+128))}function sv(t){let e=new Map,n=t.slice(Math.max(0,t.indexOf("DATA;")));for(let r of n.matchAll(/#(\d+)\s*=\s*([A-Z0-9_]+)\s*\(([\s\S]*?)\)\s*;(?=\s*(?:#|ENDSEC))/g))e.set(Number(r[1]),{type:r[2],args:ov(r[3])});return e}var yh={x:0,y:0,z:0,c:1,s:0},vh=(t,e)=>({x:t.x+t.c*e.x-t.s*e.y,y:t.y+t.s*e.x+t.c*e.y,z:t.z+e.z,c:t.c*e.c-t.s*e.s,s:t.s*e.c+t.c*e.s});function wh(t){let e=sv(t);if(!e.size)throw new Error("ifc_empty");let n=k=>ro(k)?e.get(k.ref):void 0,r=k=>typeof k=="number"?k:NaN,o=k=>(n(k)?.args[0]??[]).map(S=>r(S)),i=[...e.values()].find(k=>k.type==="IFCSIUNIT"&&k.args[1]===".LENGTHUNIT."),s=i?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(i.args[2])]??1:1,l=k=>{let S=n(k);if(!S)return yh;let[E=0,T=0,F=0]=o(S.args[0]),O=n(S.type==="IFCAXIS2PLACEMENT3D"?S.args[2]:S.args[1]),[P=1,C=0]=(O?.args[0]??[]).map(q=>r(q)),B=Math.hypot(P,C)||1;return{x:E||0,y:T||0,z:F||0,c:P/B,s:C/B}},a=(k,S=0)=>{let E=n(k);return!E||E.type!=="IFCLOCALPLACEMENT"||S>30?yh:vh(a(E.args[0],S+1),l(E.args[1]))},c=k=>{for(let S of n(k)?.args[2]??[])for(let E of n(S)?.args[3]??[]){let T=n(E);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),O=vh(l(T.args[1]),l(F?.args[2])),P=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[C,B]=[r(F.args[3])/2,r(F.args[4])/2];P=[[-C,-B],[C,-B],[C,B],[-C,B]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let C=n(F.args[2]);C?.type==="IFCPOLYLINE"&&(P=(C.args[0]??[]).map(B=>o(B)))}if(P=P.filter(C=>Number.isFinite(C[0])&&Number.isFinite(C[1])),P.length>3&&Math.hypot(P[0][0]-P[P.length-1][0],P[0][1]-P[P.length-1][1])<1e-6&&P.pop(),P.length>=3)return P.map(([C,B])=>[O.x+O.c*C-O.s*B,O.y+O.s*C+O.c*B])}return null},u=new Map;for(let[,k]of e){if(k.type==="IFCRELAGGREGATES"&&ro(k.args[4]))for(let S of k.args[5]??[])ro(S)&&u.set(S.ref,k.args[4].ref);if(k.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&ro(k.args[5]))for(let S of k.args[4]??[])ro(S)&&u.set(S.ref,k.args[5].ref)}let d=[...e].filter(([,k])=>k.type==="IFCBUILDINGSTOREY").map(([k,S])=>({id:k,name:String(S.args[7]||S.args[2]||"")||null,elevation:r(S.args[9])*s}));d.sort((k,S)=>(k.elevation||0)-(S.elevation||0));let p=[];for(let[k,S]of e){if(S.type!=="IFCSPACE")continue;let E=c(S.args[6]);if(!E)continue;let T=a(S.args[5]),F=E.map(([P,C])=>[(T.x+T.c*P-T.s*C)*s,(T.y+T.s*P+T.c*C)*s]),O=String(S.args[7]||S.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:u.get(k)??null,name:O,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(k=>k.ring),f=Math.min(...h.map(k=>k[0])),g=Math.max(...h.map(k=>k[1])),y=k=>Math.round(k*1e3)/1e3,b=[],v=new Map;if(d.filter(k=>p.some(S=>S.storey===k.id)).forEach((k,S)=>{let E=Ce(I("floor"),k.name??`Etage ${S+1}`,Number.isFinite(k.elevation)?y(k.elevation):S*2.8);b.push(E),v.set(k.id,E)}),p.some(k=>k.storey===null||!v.has(k.storey))){let k=Ce(I("floor"),b.length?"Weitere R\xE4ume":"Erdgeschoss",b.length?b[b.length-1].elevation+2.8:0);b.push(k),v.set(null,k)}b.forEach((k,S)=>{let E=b[S+1];E&&E.elevation-k.elevation>1.8&&(k.height=y(E.elevation-k.elevation-.2))});for(let k of p)v.get(k.storey!==null&&v.has(k.storey)?k.storey:null).rooms.push({id:I("room"),name:k.name,area_id:null,points:k.ring.map(([E,T])=>[y(E-f),y(g-T)]),floor_material:"wood",panel:[]});let x=Ft();return x.floors=b,{building:Pe(x),report:{floors:b.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var xh="nextfloor",av="alarm_control_panel|automation|binary_sensor|button|calendar|camera|climate|conversation|cover|date|datetime|device_tracker|event|fan|group|humidifier|image|input_boolean|input_button|input_datetime|input_number|input_select|input_text|lawn_mower|light|lock|media_player|notify|number|person|remote|scene|script|select|sensor|siren|stt|sun|switch|text|time|timer|todo|tts|update|vacuum|valve|water_heater|weather|zone",kh=new RegExp(`^(?:${av})\\.[a-z0-9_]+$`),lv=/^[0-9a-f]{32}$/,cv=new Set(["area_id","ha_floor"]),uv=new Set(["sub_areas"]),dv=new Set(["tap","show_when","pictures","moods"]);function Ea(t){if(typeof t=="string")return kh.test(t)||lv.test(t)?null:t;if(Array.isArray(t))return t.map(e=>Ea(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))kh.test(n)||dv.has(n)||(cv.has(n)||uv.has(n)?e[n]=null:e[n]=Ea(r));return e}return t}var hv=["wall_exterior","wall_interior","wall_paint_outside","wall_paint_inside","grid","north","roof","weather_effects","rain_warning","sun_patches","lock_plan","start_view","units","motion_markers_active","room_double_tap"];function $h(t){let e=structuredClone(t),n={};for(let o of hv)e.settings?.[o]!==void 0&&(n[o]=e.settings[o]);let r=e.settings?.backdrop;r&&(r.color||r.dim!=null)&&(n.backdrop={color:r.color??null,dim:r.dim??null}),e.settings=n,e.energy={...e.energy,grid:null,solar:null,battery:null,battery_soc:null,tariff:null,consumption:null,gas:null,water:null},e.presence=[];for(let o of e.floors){o.background=null,o.placements=[],o.power_entity=null,o.utility_meters=null,o.ha_floor=null;for(let i of o.rooms)Object.assign(i,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});o.furniture.forEach(i=>{Object.assign(i,{entity:null,power:null}),delete i.effect_animations,i.picture&&!(i.picture.startsWith("image:")||i.picture.startsWith("https://"))&&(i.picture=null)}),o.openings.forEach(i=>Object.assign(i,{cover:null,contact:null,tilt:null}))}return Ea(e)}function Sh(t,e){return{format:xh,version:1,exported_at:new Date().toISOString(),building:e?$h(t):structuredClone(t)}}var pv=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),fv="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function Mh(t,e,n,r,o=fv){let i=new Set(t.floors.flatMap(c=>c.furniture.map(u=>u.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:$h(t),packs:e.filter(c=>!c.builtin&&i.has(c.id))},l=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u]);return`
${a(n)}
@@ -626,27 +626,27 @@ addEventListener("message", (e) => {
if (e.source === frame.contentWindow && e.data && e.data.type === "nextfloor-share-ready") frame.contentWindow.postMessage({ type: "nextfloor-share", building: data.building, packs: data.packs }, "*");
});
<\/script>
-`}function xh(t){let e;try{e=JSON.parse(t)}catch{throw new Error("not_json")}let n=e,r=n?.format===yh?n.building:e;if(!lv(r))throw new Error("not_plan");return r.floors.forEach(o=>o.background=null),Pe(r)}var uv=t=>!/^https?:\/\//.test(t)&&!t.startsWith("camera:");function $h(t){let e=new Set;for(let n of t.floors){n.background?.image_id&&e.add(n.background.image_id);let r=n.furniture.flatMap(o=>o.pictures??[]);for(let{image:o}of r)o&&uv(o)&&e.add(o)}return[...e]}function Sh(t,e,n="application/json"){let r=document.createElement("a"),o=URL.createObjectURL(new Blob([e],{type:n}));Object.assign(r,{href:o,download:t}),r.click(),setTimeout(()=>URL.revokeObjectURL(o),1e3)}var dv={api:{listHistory:nd,restoreSnapshot:sd,takeSnapshot:rd,getSnapshot:od,deleteSnapshot:id,fetchBackup:ld,restoreBackup:cd,fetchImage:oi,storeImage:Lt},alert:t=>alert(t),confirm:t=>confirm(t),prompt:t=>prompt(t),download:Sh,today:()=>new Date().toISOString().slice(0,10)},hv=t=>String(t?.message??t),wi=class{host;deps;history=null;busy=!1;compare=null;constructor(e,n=dv){this.host=e,this.deps=n}async loadHistory(){let{hass:e}=this.host;e&&(this.history=await this.deps.api.listHistory(e).catch(()=>[]),this.host.refresh())}timeOf(e){return new Date(e.saved_at*1e3).toLocaleString(this.host.hass?.language,{dateStyle:"short",timeStyle:"short"})}async restorePoint(e){let{hass:n,t:r}=this.host;!n||!this.deps.confirm(r("backup_restore_confirm",{time:this.timeOf(e)}))||(await this.deps.api.restoreSnapshot(n,e.id),this.host.say(r("backup_restored")),await this.loadHistory())}async saveVersion(){let{hass:e,t:n}=this.host,r=e?this.deps.prompt?.(n("version_name_prompt"))?.trim():null;!e||!r||(await this.deps.api.takeSnapshot(e,r.slice(0,60)),this.host.say(n("version_saved",{name:r})),await this.loadHistory())}async compareWith(e){let{hass:n}=this.host,r=this.deps.api.getSnapshot;if(!n||!r)return;if(this.compare?.snapshot.id===e.id)return this.compare=null,this.host.refresh();let o=Pe(await r(n,e.id));this.compare={snapshot:e,entries:ih(o,this.host.doc)},this.host.refresh()}async deleteVersion(e){let{hass:n,t:r}=this.host,o=this.deps.api.deleteSnapshot;!n||!o||!this.deps.confirm(r("version_delete_confirm",{name:e.name??this.timeOf(e)}))||(await o(n,e.id),this.compare?.snapshot.id===e.id&&(this.compare=null),await this.loadHistory())}exportShareView(){let e=this.host.t,n=kh(this.host.doc,wr(),e("share_view_title"),e("share_view_needs_js"));this.deps.download(`nextfloor-${e("share_view_file")}-${this.deps.today()}.html`,n,"text/html"),this.host.say(e("share_view_done"))}exportPlan(e){let n=this.host.t(e?"export_name_template":"export_name_backup");this.deps.download(`nextfloor-${n}-${this.deps.today()}.json`,JSON.stringify(wh(this.host.doc,e),null,2))}async importPlan(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let o,i=r("backup_import_confirm");try{if(/\.sh3d$/i.test(e.name)){let s=await ch(new Uint8Array(await e.arrayBuffer()));o=s.building,i=`${r("import_sh3d_found",{...s.report})}
+`}function Rh(t){let e;try{e=JSON.parse(t)}catch{throw new Error("not_json")}let n=e,r=n?.format===xh?n.building:e;if(!pv(r))throw new Error("not_plan");return r.floors.forEach(o=>o.background=null),Pe(r)}var mv=t=>!/^https?:\/\//.test(t)&&!t.startsWith("camera:");function Eh(t){let e=new Set;for(let n of t.floors){n.background?.image_id&&e.add(n.background.image_id);let r=n.furniture.flatMap(o=>o.pictures??[]);for(let{image:o}of r)o&&mv(o)&&e.add(o)}return[...e]}function Ah(t,e,n="application/json"){let r=document.createElement("a"),o=URL.createObjectURL(new Blob([e],{type:n}));Object.assign(r,{href:o,download:t}),r.click(),setTimeout(()=>URL.revokeObjectURL(o),1e3)}var gv={api:{listHistory:sd,restoreSnapshot:ud,takeSnapshot:ad,getSnapshot:ld,deleteSnapshot:cd,fetchBackup:hd,restoreBackup:pd,fetchImage:oi,storeImage:Lt},alert:t=>alert(t),confirm:t=>confirm(t),prompt:t=>prompt(t),download:Ah,today:()=>new Date().toISOString().slice(0,10)},_v=t=>String(t?.message??t),wi=class{host;deps;history=null;busy=!1;compare=null;constructor(e,n=gv){this.host=e,this.deps=n}async loadHistory(){let{hass:e}=this.host;e&&(this.history=await this.deps.api.listHistory(e).catch(()=>[]),this.host.refresh())}timeOf(e){return new Date(e.saved_at*1e3).toLocaleString(this.host.hass?.language,{dateStyle:"short",timeStyle:"short"})}async restorePoint(e){let{hass:n,t:r}=this.host;!n||!this.deps.confirm(r("backup_restore_confirm",{time:this.timeOf(e)}))||(await this.deps.api.restoreSnapshot(n,e.id),this.host.say(r("backup_restored")),await this.loadHistory())}async saveVersion(){let{hass:e,t:n}=this.host,r=e?this.deps.prompt?.(n("version_name_prompt"))?.trim():null;!e||!r||(await this.deps.api.takeSnapshot(e,r.slice(0,60)),this.host.say(n("version_saved",{name:r})),await this.loadHistory())}async compareWith(e){let{hass:n}=this.host,r=this.deps.api.getSnapshot;if(!n||!r)return;if(this.compare?.snapshot.id===e.id)return this.compare=null,this.host.refresh();let o=Pe(await r(n,e.id));this.compare={snapshot:e,entries:ch(o,this.host.doc)},this.host.refresh()}async deleteVersion(e){let{hass:n,t:r}=this.host,o=this.deps.api.deleteSnapshot;!n||!o||!this.deps.confirm(r("version_delete_confirm",{name:e.name??this.timeOf(e)}))||(await o(n,e.id),this.compare?.snapshot.id===e.id&&(this.compare=null),await this.loadHistory())}exportShareView(){let e=this.host.t,n=Mh(this.host.doc,kr(),e("share_view_title"),e("share_view_needs_js"));this.deps.download(`nextfloor-${e("share_view_file")}-${this.deps.today()}.html`,n,"text/html"),this.host.say(e("share_view_done"))}exportPlan(e){let n=this.host.t(e?"export_name_template":"export_name_backup");this.deps.download(`nextfloor-${n}-${this.deps.today()}.json`,JSON.stringify(Sh(this.host.doc,e),null,2))}async importPlan(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let o,i=r("backup_import_confirm");try{if(/\.sh3d$/i.test(e.name)){let s=await ph(new Uint8Array(await e.arrayBuffer()));o=s.building,i=`${r("import_sh3d_found",{...s.report})}
-${i}`}else if(/\.ifc$/i.test(e.name)){let s=_h(await e.text());o=s.building,i=`${r("import_ifc_found",{floors:s.report.floors,rooms:s.report.rooms})}
+${i}`}else if(/\.ifc$/i.test(e.name)){let s=wh(await e.text());o=s.building,i=`${r("import_ifc_found",{floors:s.report.floors,rooms:s.report.rooms})}
-${i}`}else if(/\.dxf$/i.test(e.name)){let s=dh(await e.text());o=s.building,i=`${r("import_dxf_found",{rooms:s.report.rooms,walls:s.report.walls})}
+${i}`}else if(/\.dxf$/i.test(e.name)){let s=mh(await e.text());o=s.building,i=`${r("import_dxf_found",{rooms:s.report.rooms,walls:s.report.walls})}
-${i}`}else{let s=await e.text(),l=null;try{l=JSON.parse(s)}catch{}if(ph(l)){let a=fh(l);o=a.building,i=`${r("import_roomplan_found",{rooms:a.report.rooms,openings:a.report.openings,skipped:a.report.furniture})}
+${i}`}else{let s=await e.text(),l=null;try{l=JSON.parse(s)}catch{}if(_h(l)){let a=bh(l);o=a.building,i=`${r("import_roomplan_found",{rooms:a.report.rooms,openings:a.report.openings,skipped:a.report.furniture})}
-${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json",not_plan:"import_error_not_plan",not_zip:"import_error_sh3d",sh3d_no_xml:"import_error_sh3d",sh3d_empty:"import_error_sh3d_empty",dxf_empty:"import_error_dxf_empty",ifc_empty:"import_error_ifc_empty",roomplan_empty:"import_error_roomplan_empty"};this.deps.alert(a[l]?r(a[l]):r("backup_import_error",{error:l}));return}this.deps.confirm(i)&&(await this.deps.api.takeSnapshot(n).catch(()=>{}),this.host.adopt(o),this.host.say(r("backup_imported")))}async exportFull(){let{hass:e,t:n}=this.host;if(e){this.busy=!0,this.host.refresh();try{let r=await this.deps.api.fetchBackup(e),o={};for(let i of $h(r.building))await this.deps.api.fetchImage(e,i).then(s=>o[i]=s,()=>{});this.deps.download(`nextfloor-${n("export_name_full")}-${this.deps.today()}.json`,JSON.stringify({...r,exported_at:new Date().toISOString(),images:o}))}catch(r){this.deps.alert(n("backup_import_error",{error:hv(r)}))}finally{this.busy=!1,this.host.refresh()}}}async importFull(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let o;try{o=JSON.parse(await e.text())}catch{this.deps.alert(r("import_error_not_json"));return}if(o?.format!=="nextfloor-backup"||!o.building){this.deps.alert(r("backup_full_not_backup"));return}if(this.deps.confirm(r("backup_full_confirm"))){this.busy=!0,this.host.refresh();try{let i=await this.deps.api.restoreBackup(n,o.building,o.packs??[]),s=0;for(let[a,c]of Object.entries(o.images??{}))await this.deps.api.storeImage(n,a,c).then(()=>s++,()=>{});this.host.adopt(Pe(i.building)),this.host.packsChanged();let l=i.skipped.length>0?` ${r("backup_full_skipped",{packs:i.skipped.map(a=>a.id).join(", ")})}`:"";this.host.say(r("backup_full_restored",{packs:i.packs,pictures:s})+l)}catch(i){let{code:s,message:l}=i??{};this.deps.alert(r("backup_import_error",{error:l??s??String(i)}))}finally{this.busy=!1,this.host.refresh()}}}};function Ye(t,e){if(!yt(e))return Se(t,`furn_${e}`);let n=U(e);return n?Xe(n,e,t?.language??navigator.language):Se(t,"pack_missing_item")}function Xe(t,e,n){return t.name[n.split("-")[0]]??fi(n,e)??Tc(t,n)}function He(t,e){return fi(e,`packname:${t.id}`)??zc(t,e)}function Mh(t,e){return t.name[e.split("-")[0]]??fi(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var Rh=(t,e,n="application/json,.json")=>m`{}),this.host.adopt(o),this.host.say(r("backup_imported")))}async exportFull(){let{hass:e,t:n}=this.host;if(e){this.busy=!0,this.host.refresh();try{let r=await this.deps.api.fetchBackup(e),o={};for(let i of Eh(r.building))await this.deps.api.fetchImage(e,i).then(s=>o[i]=s,()=>{});this.deps.download(`nextfloor-${n("export_name_full")}-${this.deps.today()}.json`,JSON.stringify({...r,exported_at:new Date().toISOString(),images:o}))}catch(r){this.deps.alert(n("backup_import_error",{error:_v(r)}))}finally{this.busy=!1,this.host.refresh()}}}async importFull(e){let{hass:n,t:r}=this.host;if(!e||!n)return;let o;try{o=JSON.parse(await e.text())}catch{this.deps.alert(r("import_error_not_json"));return}if(o?.format!=="nextfloor-backup"||!o.building){this.deps.alert(r("backup_full_not_backup"));return}if(this.deps.confirm(r("backup_full_confirm"))){this.busy=!0,this.host.refresh();try{let i=await this.deps.api.restoreBackup(n,o.building,o.packs??[]),s=0;for(let[a,c]of Object.entries(o.images??{}))await this.deps.api.storeImage(n,a,c).then(()=>s++,()=>{});this.host.adopt(Pe(i.building)),this.host.packsChanged();let l=i.skipped.length>0?` ${r("backup_full_skipped",{packs:i.skipped.map(a=>a.id).join(", ")})}`:"";this.host.say(r("backup_full_restored",{packs:i.packs,pictures:s})+l)}catch(i){let{code:s,message:l}=i??{};this.deps.alert(r("backup_import_error",{error:l??s??String(i)}))}finally{this.busy=!1,this.host.refresh()}}}};function Ye(t,e){if(!yt(e))return Se(t,`furn_${e}`);let n=U(e);return n?Xe(n,e,t?.language??navigator.language):Se(t,"pack_missing_item")}function Xe(t,e,n){return t.name[n.split("-")[0]]??fi(n,e)??Dc(t,n)}function He(t,e){return fi(e,`packname:${t.id}`)??Oc(t,e)}function Fh(t,e){return t.name[e.split("-")[0]]??fi(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var Th=(t,e,n="application/json,.json")=>m`${t} {let o=r.target,i=o.files?.[0];o.value="",e(i)}}
/>
- `,pv={added:"\uFF0B",removed:"\u2212",renamed:"\u270E",reshaped:"\u2922",moved:"\u2194"};function fv(t,e){let n=t.t;if(!e.length)return m`${n("version_same")}
`;let r=i=>i.kind.startsWith("furniture")?Ye(t.hass,i.name)||i.name:i.kind.startsWith("device")?String(t.hass?.states[i.name]?.attributes.friendly_name??i.name):i.kind.startsWith("opening")?n(i.name==="door"?"opening_door":i.name==="garage"?"opening_garage":"opening_window"):i.name,o=[...new Set(e.map(i=>i.floor))];return m`
+`,bv={added:"\uFF0B",removed:"\u2212",renamed:"\u270E",reshaped:"\u2922",moved:"\u2194"};function yv(t,e){let n=t.t;if(!e.length)return m`
${n("version_same")}
`;let r=i=>i.kind.startsWith("furniture")?Ye(t.hass,i.name)||i.name:i.kind.startsWith("device")?String(t.hass?.states[i.name]?.attributes.friendly_name??i.name):i.kind.startsWith("opening")?n(i.name==="door"?"opening_door":i.name==="garage"?"opening_garage":"opening_window"):i.name,o=[...new Set(e.map(i=>i.floor))];return m`
${M(n("version_diff_n",{n:e.length}))}
${o.map(i=>m`
${i}
- ${e.filter(s=>s.floor===i).map(s=>{let l=s.kind.slice(s.kind.indexOf("_")+1),a=typeof s.detail=="number"?`${s.detail>0?"+":""}${K(t.hass,s.detail,1)}`:s.detail??"";return m`${pv[l]??"\u2022"} ${n(`diff_${s.kind}`,{name:r(s),detail:a})} `})}
+ ${e.filter(s=>s.floor===i).map(s=>{let l=s.kind.slice(s.kind.indexOf("_")+1),a=typeof s.detail=="number"?`${s.detail>0?"+":""}${K(t.hass,s.detail,1)}`:s.detail??"";return m`${bv[l]??"\u2022"} ${n(`diff_${s.kind}`,{name:r(s),detail:a})} `})}
`)}
-
`}function Eh(t,e){let n=t.t,r=e.history,o=r===null?M(n("loading")):r.length===0?M(n("backup_none")):m`
+
`}function zh(t,e){let n=t.t,r=e.history,o=r===null?M(n("loading")):r.length===0?M(n("backup_none")):m`
${r.map(i=>m`
${i.name?m`📌 ${i.name} · `:_}${e.timeOf(i)} · ${n("backup_summary",{rooms:i.rooms,furniture:i.furniture})}
@@ -655,19 +655,19 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${i.name?m`{e.deleteVersion(i)}}>✕ `:_}
- ${e.compare?.snapshot.id===i.id?fv(t,e.compare.entries):_}`)}
+ ${e.compare?.snapshot.id===i.id?yv(t,e.compare.entries):_}`)}
`;return m`
i.target.open&&void e.loadHistory()}>
${n("backup")}
${n("backup_history")}
- ${Y(m`{e.saveVersion()}}>📌 ${n("version_save")} `)}
+ ${X(m`{e.saveVersion()}}>📌 ${n("version_save")} `)}
${o}
${n("backup_file")}
- ${Y(m`e.exportPlan(!1)}>${n("backup_export")} `,m`e.exportPlan(!0)}>${n("backup_export_share")} `,m`e.exportShareView()}>🔗 ${n("share_view")} `,Rh(n("backup_import"),i=>{e.importPlan(i)},"application/json,.json,.sh3d,.dxf,.ifc"))}
+ ${X(m`e.exportPlan(!1)}>${n("backup_export")} `,m`e.exportPlan(!0)}>${n("backup_export_share")} `,m`e.exportShareView()}>🔗 ${n("share_view")} `,Th(n("backup_import"),i=>{e.importPlan(i)},"application/json,.json,.sh3d,.dxf,.ifc"))}
${M(n("backup_hint"))} ${M(n("import_other_hint"))}
${n("backup_full")}
- ${Y(m`e.exportFull()}>${e.busy?"\u2026":n("backup_full_export")} `,Rh(n("backup_full_import"),i=>{e.importFull(i)}))}
+ ${X(m`e.exportFull()}>${e.busy?"\u2026":n("backup_full_export")} `,Th(n("backup_full_import"),i=>{e.importFull(i)}))}
${M(n("backup_full_hint"))}
- `}function Ah(t,e){return t.states["weather.nextfloor_symcon"]?"weather.nextfloor_symcon":e&&t.states[e]?e:Object.keys(t.states).filter(n=>n.startsWith("weather.")).sort()[0]??null}var Fh=["body","wood","fabric","white","metal","dark"],Th={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var mn=(t,e,n)=>Math.min(n,Math.max(e,t)),mv=t=>(Math.round(t)%360+360)%360,Aa=(t,e)=>mv(t+e);function zh(t,e,n){return n?[...new Set([...t,e])]:t.filter(r=>r!==e)}function Ph(t,e,n){let r=t.t,o=s=>()=>n(Aa(e,s)),i=R`
+ `}function Ph(t,e){return t.states["weather.nextfloor_symcon"]?"weather.nextfloor_symcon":e&&t.states[e]?e:Object.keys(t.states).filter(n=>n.startsWith("weather.")).sort()[0]??null}var Ih=["body","wood","fabric","white","metal","dark"],Dh={body:"#172238",wood:"#19233c",fabric:"#1a2644",white:"#1d2946",metal:"#2a3a60",dark:"#0b111f"};var mn=(t,e,n)=>Math.min(n,Math.max(e,t)),vv=t=>(Math.round(t)%360+360)%360,Aa=(t,e)=>vv(t+e);function Oh(t,e,n){return n?[...new Set([...t,e])]:t.filter(r=>r!==e)}function Hh(t,e,n){let r=t.t,o=s=>()=>n(Aa(e,s)),i=R`
@@ -688,14 +688,14 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${M(r("compass_hint"))}
-
`}var gv="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var _v=40075016686e-3,Fa=Math.PI/180,ro=18,oo=.5,bv=160;function yv(t,e,n){let r=2**n,o=(e+180)/360*r,i=(1-Math.log(Math.tan(t*Fa)+1/Math.cos(t*Fa))/Math.PI)/2*r;return[o,i]}var vv=(t,e)=>_v*Math.cos(t*Fa)/2**e;function Ih(t,e,n,r=bv){let[o,i]=yv(t,e,n),s=vv(t,n),l=r/s,a=2**n-1,c=[];for(let u=Math.floor(i-l);u<=Math.floor(i+l);u++)for(let d=Math.floor(o-l);d<=Math.floor(o+l);d++){if(u<0||u>a)continue;let p=(d%(a+1)+a+1)%(a+1);c.push({x:p,y:u,z:n,east:(d-o)*s,north:-(u-i)*s,size:s})}return c}function Dh(t,e){return t.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var Oh=t=>t.url&&t.url.startsWith("https://")?t.url:gv;var ki=t=>!!t&&t.on===!0&&Number.isFinite(t.lat)&&Number.isFinite(t.lon),Hh=t=>({x:t.x??0,z:t.z??0,opacity:t.opacity??oo,zoom:t.zoom??ro});function wv(t){let e=[],n=[];for(let o of t.floors){for(let i of o.rooms)for(let[s,l]of i.points)e.push(s),n.push(l);for(let i of o.outdoor??[])for(let[s,l]of i.points)e.push(s),n.push(l)}if(!e.length)return[0,0];let r=o=>Math.round((Math.min(...o)+Math.max(...o))/2*100)/100;return[r(e),r(n)]}function Lh(t,e){let[n,r]=wv(t);return{on:!0,lat:e?.lat??0,lon:e?.lon??0,x:n,z:r,opacity:oo,zoom:ro,url:null}}function Ch(t,e,n){let r=o=>Math.round(o*100)/100;return{...t,x:r((t.x??0)+e),z:r((t.z??0)+n)}}function Nh(t){let e=t.trim();return e===""?null:/^https:\/\/\S+$/.test(e)&&["{z}","{x}","{y}"].every(n=>e.includes(n))?e:void 0}var kv=["15","16","17","18","19"],xv=["1","5","20"],xi="5";function Bh(t,e,n){let r=t.t,o=e.settings.map??null,i=t.hass?.config,s=ki(o),l=u=>{if(!u)return n(o?{...o,on:!1}:null);n(o?{...o,on:!0}:Lh(e,{lat:i?.latitude,lon:i?.longitude}))},a=u=>o&&n({...o,...u}),c=(u,d)=>()=>o&&n(Ch(o,u*Number(xi),d*Number(xi)));return m`
+
`}var wv="https://tile.openstreetmap.org/{z}/{x}/{y}.png";var kv=40075016686e-3,Fa=Math.PI/180,oo=18,io=.5,xv=160;function $v(t,e,n){let r=2**n,o=(e+180)/360*r,i=(1-Math.log(Math.tan(t*Fa)+1/Math.cos(t*Fa))/Math.PI)/2*r;return[o,i]}var Sv=(t,e)=>kv*Math.cos(t*Fa)/2**e;function Lh(t,e,n,r=xv){let[o,i]=$v(t,e,n),s=Sv(t,n),l=r/s,a=2**n-1,c=[];for(let u=Math.floor(i-l);u<=Math.floor(i+l);u++)for(let d=Math.floor(o-l);d<=Math.floor(o+l);d++){if(u<0||u>a)continue;let p=(d%(a+1)+a+1)%(a+1);c.push({x:p,y:u,z:n,east:(d-o)*s,north:-(u-i)*s,size:s})}return c}function Ch(t,e){return t.replace("{z}",String(e.z)).replace("{x}",String(e.x)).replace("{y}",String(e.y)).replace("{s}","abc"[(e.x+e.y)%3])}var Nh=t=>t.url&&t.url.startsWith("https://")?t.url:wv;var ki=t=>!!t&&t.on===!0&&Number.isFinite(t.lat)&&Number.isFinite(t.lon),Bh=t=>({x:t.x??0,z:t.z??0,opacity:t.opacity??io,zoom:t.zoom??oo});function Mv(t){let e=[],n=[];for(let o of t.floors){for(let i of o.rooms)for(let[s,l]of i.points)e.push(s),n.push(l);for(let i of o.outdoor??[])for(let[s,l]of i.points)e.push(s),n.push(l)}if(!e.length)return[0,0];let r=o=>Math.round((Math.min(...o)+Math.max(...o))/2*100)/100;return[r(e),r(n)]}function Wh(t,e){let[n,r]=Mv(t);return{on:!0,lat:e?.lat??0,lon:e?.lon??0,x:n,z:r,opacity:io,zoom:oo,url:null}}function Vh(t,e,n){let r=o=>Math.round(o*100)/100;return{...t,x:r((t.x??0)+e),z:r((t.z??0)+n)}}function Kh(t){let e=t.trim();return e===""?null:/^https:\/\/\S+$/.test(e)&&["{z}","{x}","{y}"].every(n=>e.includes(n))?e:void 0}var Rv=["15","16","17","18","19"],Ev=["1","5","20"],xi="5";function jh(t,e,n){let r=t.t,o=e.settings.map??null,i=t.hass?.config,s=ki(o),l=u=>{if(!u)return n(o?{...o,on:!1}:null);n(o?{...o,on:!0}:Wh(e,{lat:i?.latitude,lon:i?.longitude}))},a=u=>o&&n({...o,...u}),c=(u,d)=>()=>o&&n(Vh(o,u*Number(xi),d*Number(xi)));return m`
${D(t,r("map_on"),s,l,{title:r("map_hint")})}
${o&&o.on?m`
${A(t,r("map_lat"),o.lat,u=>a({lat:Math.max(-85,Math.min(85,u))}),1e-4)}
${A(t,r("map_lon"),o.lon,u=>a({lon:Math.max(-180,Math.min(180,u))}),1e-4)}
${i?.latitude!==void 0&&i.longitude!==void 0?m`
a({lat:i.latitude,lon:i.longitude})}>${r("map_use_ha")} `:_}
- ${A(t,r("map_opacity"),Math.round((o.opacity??oo)*100),u=>a({opacity:Math.max(5,Math.min(100,u))/100}),5,5)}
- ${L(t,r("map_zoom"),String(o.zoom??ro),kv.map(u=>[u,u==="15"?`${u} \xB7 ${r("map_zoom_coarse")}`:u==="19"?`${u} \xB7 ${r("map_zoom_fine")}`:u]),u=>a({zoom:Number(u)}))}
+ ${A(t,r("map_opacity"),Math.round((o.opacity??io)*100),u=>a({opacity:Math.max(5,Math.min(100,u))/100}),5,5)}
+ ${L(t,r("map_zoom"),String(o.zoom??oo),Rv.map(u=>[u,u==="15"?`${u} \xB7 ${r("map_zoom_coarse")}`:u==="19"?`${u} \xB7 ${r("map_zoom_fine")}`:u]),u=>a({zoom:Number(u)}))}
${r("map_move")}
@@ -704,12 +704,12 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
▶
▼
- ${L(t,r("map_step"),xi,xv.map(u=>[u,`${u} m`]),u=>xi=u,{wide:!1})}
+ ${L(t,r("map_step"),xi,Ev.map(u=>[u,`${u} m`]),u=>xi=u,{wide:!1})}
- ${V(t,r("map_url"),o.url??"",u=>{let d=Nh(u);d!==void 0&&a({url:d})},{wide:!0,placeholder:"https://\u2026/{z}/{x}/{y}.png",maxlength:300})}
+ ${V(t,r("map_url"),o.url??"",u=>{let d=Kh(u);d!==void 0&&a({url:d})},{wide:!0,placeholder:"https://\u2026/{z}/{x}/{y}.png",maxlength:300})}
${M(r("map_hint"),"nf-wide")}
`:_}
-
`}var $v=["none","flat","gable","custom"];function Sv(t,e,n){let r=t.t,o=!!e,i=s=>n({color:null,image:null,dim:.35,...e??{},...s});return m`
${r("backdrop")}
+
`}var Av=["none","flat","gable","custom"];function Fv(t,e,n){let r=t.t,o=!!e,i=s=>n({color:null,image:null,dim:.35,...e??{},...s});return m`${r("backdrop")}
${D(t,r("backdrop"),o,s=>n(s?{color:"#101828",image:null,dim:.35}:null))}
${o?m`${r("backdrop_color")}
@@ -717,14 +717,14 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
/>
${A(t,r("backdrop_dim"),Math.round((e?.dim??.35)*100),s=>i({dim:mn(s,0,80)/100}),5,0)}
${V(t,r("backdrop_image"),e?.image??"",s=>i({image:s||null}),{wide:!0,placeholder:"/local/hintergrund.jpg"})}
- ${M(r("backdrop_hint"),"nf-wide")}`:_}`}function Mv(t,e,n){let r=t.t,o=H(t.hass,i=>!e.includes(i)&&/^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(i));return m`${r("status_entities")}
+ ${M(r("backdrop_hint"),"nf-wide")}`:_}`}function Tv(t,e,n){let r=t.t,o=H(t.hass,i=>!e.includes(i)&&/^(sensor|binary_sensor|alarm_control_panel|weather|input_|counter|lock|climate|person|sun)\b/.test(i));return m`${r("status_entities")}
${e.length?m`
${e.map(i=>m`${W(t.hass,i)}
${t.admin?m`n(e.filter(s=>s!==i))}>× `:_} `)}
`:_}
${e.length<12?z(t,r("status_add"),null,void 0,o,i=>i&&i!=="none"&&n([...e,i])):_}
- ${M(r("status_entities_hint"),"nf-wide")}`}function Wh(t,e){let n=t.t,r=t.doc.settings,o=c=>t.replace({...structuredClone(t.doc),settings:{...structuredClone(t.doc.settings),...c}}),i=c=>o({roof:{...r.roof,...c}}),s=$v.map(c=>[c,n(`roof_${c}`)]),l=r.weather_effects??jc,a=r.roof.type==="gable";return m`
+ ${M(r("status_entities_hint"),"nf-wide")}`}function Gh(t,e){let n=t.t,r=t.doc.settings,o=c=>t.replace({...structuredClone(t.doc),settings:{...structuredClone(t.doc.settings),...c}}),i=c=>o({roof:{...r.roof,...c}}),s=Av.map(c=>[c,n(`roof_${c}`)]),l=r.weather_effects??qc,a=r.roof.type==="gable";return m`
${n("settings")}
${A(t,n("wall_exterior"),r.wall_exterior,c=>o({wall_exterior:mn(c,.02,1)}),.01,.02)}
@@ -732,30 +732,30 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${Ve(t,n("wall_paint_outside"),r.wall_paint_outside,No,c=>o({wall_paint_outside:c}))}
${Ve(t,n("wall_paint_inside"),r.wall_paint_inside,Bo,c=>o({wall_paint_inside:c}))}
${M(n("wall_paint_hint"),"nf-wide")}
- ${Fh.map(c=>Ve(t,n(`furn_color_${c}`),r.furniture_colors?.[c],Th[c],u=>{let d={...r.furniture_colors,[c]:u};u||delete d[c],o({furniture_colors:Object.keys(d).length?d:null})}))}
+ ${Ih.map(c=>Ve(t,n(`furn_color_${c}`),r.furniture_colors?.[c],Dh[c],u=>{let d={...r.furniture_colors,[c]:u};u||delete d[c],o({furniture_colors:Object.keys(d).length?d:null})}))}
${M(n("furn_color_hint"),"nf-wide")}
${A(t,n("grid"),r.grid,c=>o({grid:mn(c,.01,1)}),.01,.01)}
${L(t,n("units"),r.units==="imperial"?"imperial":"metric",[["metric",n("units_metric")],["imperial",n("units_imperial")]],c=>o({units:c==="imperial"?"imperial":null}),{title:n("units_hint")})}
- ${Ph(t,r.north,c=>o({north:c}))}
- ${Bh(t,t.doc,c=>o({map:c}))}
+ ${Hh(t,r.north,c=>o({north:c}))}
+ ${jh(t,t.doc,c=>o({map:c}))}
${L(t,n("roof"),r.roof.type,s,c=>c==="custom"?e.useRoofSections():i({type:c}),{wide:!0})}
${a?L(t,n("roof_ridge"),r.roof.ridge==="short"?"short":"long",[["long",n("roof_ridge_long")],["short",n("roof_ridge_short")]],c=>i({ridge:c==="short"?"short":null}),{wide:!0}):_}
${a?A(t,n("roof_pitch"),r.roof.pitch,c=>i({pitch:mn(c,5,60)}),1,5):_}
${r.roof.type!=="none"?A(t,n("roof_overhang"),r.roof.overhang,c=>i({overhang:mn(c,0,2)}),.05,0):_}
- ${ue(t.hass)?Kd(t,r,o):t.hass?z(t,n("weather_entity"),r.weather_entity??null,Ah(t.hass,null),H(t.hass,c=>c.startsWith("weather.")),c=>o({weather_entity:c})):_}
+ ${oe(t.hass)?Zd(t,r,o):t.hass?z(t,n("weather_entity"),r.weather_entity??null,Ph(t.hass,null),H(t.hass,c=>c.startsWith("weather.")),c=>o({weather_entity:c})):_}
${n("weather_effects")}
- ${Kc.map(c=>D(t,n(`weather_effect_${c}`),l.includes(c),u=>o({weather_effects:zh(l,c,u)}),{wide:!1}))}
+ ${Zc.map(c=>D(t,n(`weather_effect_${c}`),l.includes(c),u=>o({weather_effects:Oh(l,c,u)}),{wide:!1}))}
${D(t,n("rain_warning"),r.rain_warning!==!1,c=>o({rain_warning:c}))}
- ${t.hass&&!ue(t.hass)&&r.rain_warning!==!1?z(t,n("rain_sensor"),r.rain_sensor??null,void 0,H(t.hass,c=>/^(binary_sensor|sensor)\./.test(c)),c=>o({rain_sensor:c==="none"?null:c})):_}
- ${t.hass&&!ue(t.hass)&&r.rain_warning!==!1&&r.rain_sensor&&r.rain_sensor!=="none"?D(t,n("rain_sensor_inverted"),!!r.rain_sensor_inverted,c=>o({rain_sensor_inverted:c||void 0}),{title:n("rain_sensor_inverted_hint")}):_}
+ ${t.hass&&!oe(t.hass)&&r.rain_warning!==!1?z(t,n("rain_sensor"),r.rain_sensor??null,void 0,H(t.hass,c=>/^(binary_sensor|sensor)\./.test(c)),c=>o({rain_sensor:c==="none"?null:c})):_}
+ ${t.hass&&!oe(t.hass)&&r.rain_warning!==!1&&r.rain_sensor&&r.rain_sensor!=="none"?D(t,n("rain_sensor_inverted"),!!r.rain_sensor_inverted,c=>o({rain_sensor_inverted:c||void 0}),{title:n("rain_sensor_inverted_hint")}):_}
${t.hass?z(t,n("outage_sensor"),r.outage_sensor??null,void 0,H(t.hass,c=>/^(binary_sensor|sensor)\./.test(c)),c=>o({outage_sensor:c==="none"?null:c})):_}
${M(n("outage_hint"),"nf-wide")}
${D(t,n("contact_warning"),!!r.contact_warning,c=>o({contact_warning:c||void 0}),{title:n("contact_warning_hint")})}
${D(t,n("night_lock_warning"),!!r.night_lock_warning,c=>o({night_lock_warning:c||void 0}),{title:n("night_lock_warning_hint")})}
${L(t,n("room_double_tap"),r.room_double_tap??"area",[["area",n("room_double_tap_area")],["plan",n("room_double_tap_plan")],["off",n("room_double_tap_off")]],c=>o({room_double_tap:c==="plan"||c==="off"?c:null}),{title:n("room_double_tap_hint")})}
${D(t,n("motion_markers_active"),!!r.motion_markers_active,c=>o({motion_markers_active:c||void 0}),{title:n("motion_markers_active_hint")})}
- ${t.hass?Mv(t,r.status_entities??[],c=>o({status_entities:c.length?c:null})):_}
- ${ue(t.hass)?_:m`${t.hass?z(t,n("announce_tts"),r.announce_tts??null,void 0,H(t.hass,c=>c.startsWith("tts.")),c=>o({announce_tts:c==="none"?null:c})):_}
+ ${t.hass?Tv(t,r.status_entities??[],c=>o({status_entities:c.length?c:null})):_}
+ ${oe(t.hass)?_:m`${t.hass?z(t,n("announce_tts"),r.announce_tts??null,void 0,H(t.hass,c=>c.startsWith("tts.")),c=>o({announce_tts:c==="none"?null:c})):_}
${n("announce_phrases")}
- ${M(ue(t.hass)?n("north_hint"):`${n("north_hint")} ${n("weather_entity_hint")}`)}
- `}var io=t=>t&&t!=="none"?t:null,so=(t,e)=>{e&&!t.includes(e)&&t.push(e)},Ta=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function gn(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=Ta(t),r=new Set([e.id]);for(let o=n.get(e.parent_meter);o;o=n.get(o.parent_meter??"")){if(r.has(o.id))return null;r.add(o.id)}return n.has(e.parent_meter)?e.parent_meter:null}function qn(t){return new Set([...Ta(t).values()].filter(e=>gn(t,e)).map(e=>e.id))}function ao(t,e){return!t.energy.advanced||!e.parent_meter?null:qn(t).has(e.parent_meter)?e.parent_meter:null}function Vh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=Ta(t),o=new Set;for(let i=n;i&&!o.has(i.id);i=r.get(i.parent_meter??"")){if(i.id===e.id)return!1;o.add(i.id)}return!0}function Si(t,e=n=>io(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(o=>o.furniture)){let o=e(r),i=r.type==="meter"?gn(t,r):null;if(i)(n.subMeters??=[]).push({id:r.id,parent:i,power:o,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=o,n.gridExport??=io(r.export);else if(r.type==="inverter")so(n.solar,o);else if(r.type==="home_battery"){let s=io(r.charge);so(n.battery,o),so(n.charge,s),so(n.soc,io(r.soc)),(o||s)&&n.batteries.push({power:o,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(o=>o.furniture):[]){let o=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(l=>l.id===ao(t,r)):void 0,i=o?e(r):null;o&&r.type==="inverter"&&so(o.solar,i);let s=io(r.charge);o&&r.type==="home_battery"&&(i||s)&&o.batteries.push({power:i,charge:s})}return n}function Rv(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!gn(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var Ev=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,Av=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function $i(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let o=Object.keys(t.states).filter(l=>l.startsWith("sensor.")&&t.entities?.[l]?.device_id===r&&t.states[l]?.attributes.device_class===n);if(o.length<=1)return o[0]??null;let i=o.filter(l=>!Ev.test(l)),s=e.replace(/^sensor\./,"").replace(Av,"");return i.find(l=>s&&l.includes(s))??i[0]??o[0]}function Kh(t,e){let n={},r=(o,i)=>{i&&!n[o]&&(n[o]=i)};for(let o of e.energy_sources??[])if(o.type==="grid")r("grid",$i(t,o.flow_from?.[0]?.stat_energy_from??o.flow_to?.[0]?.stat_energy_to));else if(o.type==="solar")r("solar",$i(t,o.stat_energy_from));else if(o.type==="battery"){let i=o.stat_energy_from??o.stat_energy_to;r("battery",$i(t,i)),r("battery_soc",$i(t,i,"battery"))}return n}function Ae(t,e=!1){let n=t?.attributes.symcon_id?en(t):t?Number(t.state):null;if(n===null||!Number.isFinite(n))return null;let r={kW:1e3,MW:1e6}[String(t.attributes.unit_of_measurement??"W")]??1;return e?-n*r:n*r}var Fv=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function jh(t,e){if(Fv(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=Os(t,n),o=r?Tt(t,e):null,i=Qo(t,n).filter(s=>s!==e);return(r?i.find(s=>o!==null&&Tt(t,s)===o):i[0])??null}var Gh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Tv(t,e,n){let r=e.grid??n.grid,o=r?Ae(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let i=Math.max(0,Ae(t.states[n.gridExport])??0);return Math.max(0,o??0)-i}return o}function zv(t,e,n){return e.solar?Ae(t.states[e.solar]):n.solar.length?Gh(n.solar.map(r=>Ae(t.states[r]))):null}function za(t,e,n){return e.charge?(e.power?Math.max(0,Ae(t.states[e.power])??0):0)-Math.max(0,Ae(t.states[e.charge])??0):e.power?Ae(t.states[e.power],n):null}function Pv(t,e,n){return e.battery?Ae(t.states[e.battery],e.battery_invert):Gh(n.batteries.map(r=>za(t,r,e.battery_invert)))}function Pa(t,e,n,r=Si(e)){let o=e.energy,i=Tv(t,o,r),s=zv(t,o,r),l=Pv(t,o,r),a=(o.battery_soc?[o.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=a.length?a.reduce((f,g)=>f+g,0)/a.length:null,u=o.tariff?t.states[o.tariff]:void 0,d=Number(u?.state),p=o.consumption?Ae(t.states[o.consumption]):null;p===null&&(i!==null||s!==null||l!==null)&&(p=(i??0)+Math.max(0,s??0)+(l??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:i,solar:s===null?null:Math.max(0,s),battery:l,soc:c,tariff:u&&Number.isFinite(d)?{value:d,unit:String(u.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...Iv(t,r,h.consumption,o.battery_invert,n)}:h}function Iv(t,e,n,r,o){let i=e.subMeters??[],s=new Map;for(let p of i)for(let h of p.floors)s.has(h)||s.set(h,p.id);let l=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...i.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),a=p=>o.filter(h=>s.get(h.floorId)===p&&!l.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(i.map(p=>[p.id,p.power?Ae(t.states[p.power],p.invert):null])),u=i.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,Ae(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(za(t,w,r)??0),0),y=i.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),b=h===null?null:Math.max(0,h+f+g-y);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:b,unmetered:b===null?null:Math.max(0,b-a(p.id))}}),d=u.reduce((p,h)=>p+(h.use??0),0);return{subMeters:u,rest:n===null?null:Math.max(0,n-d)}}function Dv(t,e,n){let r=t.b[0]-t.a[0],o=t.b[1]-t.a[1],i=Math.hypot(r,o)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*o)/(i*i))),l=t.a[0]+r*s,a=t.a[1]+o*s,c=o/i*(l-n.x)+-r/i*(a-n.z)<0?-1:1;return{x:l,z:a,nx:c*o/i,nz:-c*r/i,distance:Math.hypot(e.x-l,e.z-a)}}function Uh(t){let e=Rv(t),n=e?t.floors.find(c=>c.id===e.floor_id):void 0;if(!e||!n)return null;let r={exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},o=fe(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),i=n.rooms.flatMap(c=>c.points);if(o.length===0||i.length===0)return null;let s={x:i.reduce((c,u)=>c+u[0],0)/i.length,z:i.reduce((c,u)=>c+u[1],0)/i.length},l=o.map(c=>Dv(c,e,s)).reduce((c,u)=>u.distancef.furniture.map(g=>({floor:f,item:g}))),r=f=>n.filter(g=>g.item.type===f),o=f=>!!gi(f.item,e),i=f=>({kind:"device",...f}),[s,l,a,c,u]=[t.settings.roof.solar??[],r("meter"),r("inverter"),r("home_battery"),r("grid_point")],d=!!t.energy.grid||l.some(o),p=!!t.energy.solar||a.length>0&&a.every(o),h=!!t.energy.battery||c.every(f=>o(f)&&f.item.soc&&f.item.soc!=="none");return[s.length>0?{state:"ok",label:"chk_solar",target:{kind:"solar-field",id:s[0].id}}:{state:"todo",label:"chk_solar_add",target:{kind:"add-solar-field"}},l.length>0?{state:d?"ok":"todo",label:d?"chk_meter":"chk_meter_sensor",target:i(l[0])}:{state:"todo",label:"chk_meter_add",target:{kind:"add-device",type:"meter"}},a.length>0?{state:p?"ok":"todo",label:p?"chk_inverter":"chk_inverter_sensor",target:i(a.find(f=>!o(f))??a[0])}:{state:"todo",label:"chk_inverter_add",target:{kind:"add-device",type:"inverter"}},c.length>0?{state:h?"ok":"todo",label:h?"chk_battery":"chk_battery_sensor",target:i(c[0])}:{state:"opt",label:"chk_battery_opt",target:{kind:"add-device",type:"home_battery"}},u.length>0?{state:"ok",label:"chk_grid",target:i(u[0])}:{state:"opt",label:"chk_grid_opt",target:{kind:"add-device",type:"grid_point"}}]}function lo(t,e){let n=[];for(let r of t.floors)for(let o of r.furniture)o.type===e&&n.push({id:o.id,floorId:r.id,x:o.x,z:o.z,y:Math.max(.4,Math.min(1.4,o.h*.8))});return n}function Ov(t){if(!t?.rooms.length)return null;let e=0,n=0,r=0;for(let o of t.rooms)for(let[i,s]of o.points)e+=i,n+=s,r++;return r?{floorId:t.id,x:e/r,z:n/r,y:1}:null}function Hv(t){let e=qn(t);return lo(t,"meter").find(n=>!e.has(n.id))??lo(t,"inverter")[0]??Ov(ai(t))}function Lv(t,e){let n=lo(t,"grid_point")[0];if(n)return n;let r=t.floors.find(l=>l.id===e.floorId);if(!r?.rooms.length)return null;let o=1/0,i=-1/0,s=-1/0;for(let l of r.rooms)for(let[a,c]of l.points)o=Math.min(o,a),i=Math.max(i,a),s=Math.max(s,c);return{floorId:e.floorId,x:Math.max(o,Math.min(i,e.x)),z:s+3,y:.2}}function qh(t){let e=[],n=Hv(t);if(!n)return e;let r=new Set(t.floors.flatMap(i=>i.furniture).filter(i=>ao(t,i)).map(i=>i.id)),o=lo(t,"inverter").find(i=>!r.has(i.id));for(let i of t.settings.roof.solar??[])e.push({key:`solar:${i.id}`,kind:"solar",id:i.id});lo(t,"home_battery").some(i=>!r.has(i.id))&&e.push({key:"battery",kind:"battery",id:null}),o&&(o.floorId!==n.floorId||o.x!==n.x||o.z!==n.z)&&e.push({key:"inverter",kind:"inverter",id:null}),Lv(t,n)&&e.push({key:"grid",kind:"grid",id:null});for(let i of t.floors.flatMap(s=>s.furniture))r.has(i.id)&&(i.type==="inverter"?e.push({key:`inverter:${i.id}`,kind:"inverter",id:i.id}):i.type==="home_battery"&&e.push({key:`battery:${i.id}`,kind:"battery",id:i.id}));for(let i of qn(t))e.push({key:`meter:${i}`,kind:"meter",id:i});return e}var Yh=(t,e)=>t.energy.routes?.find(n=>n.key===e&&n.points.length>0);var Cv={ok:"\u2713",todo:"\u25CB",opt:"\xB7"},Qh=t=>t.hass?We(t.hass,t.doc.floors):new Map,Nv=Ne,Jh=(t,e)=>e.name||t.t(`furn_${e.type}`);function ep(t,e){let n=Zh(t.doc,Qh(t)),r=n.filter(o=>o.state==="ok").length;return m`
+ ${M(oe(t.hass)?n("north_hint"):`${n("north_hint")} ${n("weather_entity_hint")}`)}
+ `}var so=t=>t&&t!=="none"?t:null,ao=(t,e)=>{e&&!t.includes(e)&&t.push(e)},Ta=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function gn(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=Ta(t),r=new Set([e.id]);for(let o=n.get(e.parent_meter);o;o=n.get(o.parent_meter??"")){if(r.has(o.id))return null;r.add(o.id)}return n.has(e.parent_meter)?e.parent_meter:null}function qn(t){return new Set([...Ta(t).values()].filter(e=>gn(t,e)).map(e=>e.id))}function lo(t,e){return!t.energy.advanced||!e.parent_meter?null:qn(t).has(e.parent_meter)?e.parent_meter:null}function Uh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=Ta(t),o=new Set;for(let i=n;i&&!o.has(i.id);i=r.get(i.parent_meter??"")){if(i.id===e.id)return!1;o.add(i.id)}return!0}function Si(t,e=n=>so(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(o=>o.furniture)){let o=e(r),i=r.type==="meter"?gn(t,r):null;if(i)(n.subMeters??=[]).push({id:r.id,parent:i,power:o,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=o,n.gridExport??=so(r.export);else if(r.type==="inverter")ao(n.solar,o);else if(r.type==="home_battery"){let s=so(r.charge);ao(n.battery,o),ao(n.charge,s),ao(n.soc,so(r.soc)),(o||s)&&n.batteries.push({power:o,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(o=>o.furniture):[]){let o=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(l=>l.id===lo(t,r)):void 0,i=o?e(r):null;o&&r.type==="inverter"&&ao(o.solar,i);let s=so(r.charge);o&&r.type==="home_battery"&&(i||s)&&o.batteries.push({power:i,charge:s})}return n}function zv(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!gn(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var Pv=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,Iv=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function $i(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let o=Object.keys(t.states).filter(l=>l.startsWith("sensor.")&&t.entities?.[l]?.device_id===r&&t.states[l]?.attributes.device_class===n);if(o.length<=1)return o[0]??null;let i=o.filter(l=>!Pv.test(l)),s=e.replace(/^sensor\./,"").replace(Iv,"");return i.find(l=>s&&l.includes(s))??i[0]??o[0]}function Zh(t,e){let n={},r=(o,i)=>{i&&!n[o]&&(n[o]=i)};for(let o of e.energy_sources??[])if(o.type==="grid")r("grid",$i(t,o.flow_from?.[0]?.stat_energy_from??o.flow_to?.[0]?.stat_energy_to));else if(o.type==="solar")r("solar",$i(t,o.stat_energy_from));else if(o.type==="battery"){let i=o.stat_energy_from??o.stat_energy_to;r("battery",$i(t,i)),r("battery_soc",$i(t,i,"battery"))}return n}function Ae(t,e=!1){let n=t?.attributes.symcon_id?en(t):t?Number(t.state):null;if(n===null||!Number.isFinite(n))return null;let r={kW:1e3,MW:1e6}[String(t.attributes.unit_of_measurement??"W")]??1;return e?-n*r:n*r}var Dv=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function qh(t,e){if(Dv(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=Os(t,n),o=r?Tt(t,e):null,i=Qo(t,n).filter(s=>s!==e);return(r?i.find(s=>o!==null&&Tt(t,s)===o):i[0])??null}var Yh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Ov(t,e,n){let r=e.grid??n.grid,o=r?Ae(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let i=Math.max(0,Ae(t.states[n.gridExport])??0);return Math.max(0,o??0)-i}return o}function Hv(t,e,n){return e.solar?Ae(t.states[e.solar]):n.solar.length?Yh(n.solar.map(r=>Ae(t.states[r]))):null}function za(t,e,n){return e.charge?(e.power?Math.max(0,Ae(t.states[e.power])??0):0)-Math.max(0,Ae(t.states[e.charge])??0):e.power?Ae(t.states[e.power],n):null}function Lv(t,e,n){return e.battery?Ae(t.states[e.battery],e.battery_invert):Yh(n.batteries.map(r=>za(t,r,e.battery_invert)))}function Pa(t,e,n,r=Si(e)){let o=e.energy,i=Ov(t,o,r),s=Hv(t,o,r),l=Lv(t,o,r),a=(o.battery_soc?[o.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=a.length?a.reduce((f,g)=>f+g,0)/a.length:null,u=o.tariff?t.states[o.tariff]:void 0,d=Number(u?.state),p=o.consumption?Ae(t.states[o.consumption]):null;p===null&&(i!==null||s!==null||l!==null)&&(p=(i??0)+Math.max(0,s??0)+(l??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:i,solar:s===null?null:Math.max(0,s),battery:l,soc:c,tariff:u&&Number.isFinite(d)?{value:d,unit:String(u.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...Cv(t,r,h.consumption,o.battery_invert,n)}:h}function Cv(t,e,n,r,o){let i=e.subMeters??[],s=new Map;for(let p of i)for(let h of p.floors)s.has(h)||s.set(h,p.id);let l=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...i.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),a=p=>o.filter(h=>s.get(h.floorId)===p&&!l.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(i.map(p=>[p.id,p.power?Ae(t.states[p.power],p.invert):null])),u=i.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,Ae(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(za(t,w,r)??0),0),y=i.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),b=h===null?null:Math.max(0,h+f+g-y);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:b,unmetered:b===null?null:Math.max(0,b-a(p.id))}}),d=u.reduce((p,h)=>p+(h.use??0),0);return{subMeters:u,rest:n===null?null:Math.max(0,n-d)}}function Nv(t,e,n){let r=t.b[0]-t.a[0],o=t.b[1]-t.a[1],i=Math.hypot(r,o)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*o)/(i*i))),l=t.a[0]+r*s,a=t.a[1]+o*s,c=o/i*(l-n.x)+-r/i*(a-n.z)<0?-1:1;return{x:l,z:a,nx:c*o/i,nz:-c*r/i,distance:Math.hypot(e.x-l,e.z-a)}}function Xh(t){let e=zv(t),n=e?t.floors.find(c=>c.id===e.floor_id):void 0;if(!e||!n)return null;let r={exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},o=fe(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),i=n.rooms.flatMap(c=>c.points);if(o.length===0||i.length===0)return null;let s={x:i.reduce((c,u)=>c+u[0],0)/i.length,z:i.reduce((c,u)=>c+u[1],0)/i.length},l=o.map(c=>Nv(c,e,s)).reduce((c,u)=>u.distancef.furniture.map(g=>({floor:f,item:g}))),r=f=>n.filter(g=>g.item.type===f),o=f=>!!gi(f.item,e),i=f=>({kind:"device",...f}),[s,l,a,c,u]=[t.settings.roof.solar??[],r("meter"),r("inverter"),r("home_battery"),r("grid_point")],d=!!t.energy.grid||l.some(o),p=!!t.energy.solar||a.length>0&&a.every(o),h=!!t.energy.battery||c.every(f=>o(f)&&f.item.soc&&f.item.soc!=="none");return[s.length>0?{state:"ok",label:"chk_solar",target:{kind:"solar-field",id:s[0].id}}:{state:"todo",label:"chk_solar_add",target:{kind:"add-solar-field"}},l.length>0?{state:d?"ok":"todo",label:d?"chk_meter":"chk_meter_sensor",target:i(l[0])}:{state:"todo",label:"chk_meter_add",target:{kind:"add-device",type:"meter"}},a.length>0?{state:p?"ok":"todo",label:p?"chk_inverter":"chk_inverter_sensor",target:i(a.find(f=>!o(f))??a[0])}:{state:"todo",label:"chk_inverter_add",target:{kind:"add-device",type:"inverter"}},c.length>0?{state:h?"ok":"todo",label:h?"chk_battery":"chk_battery_sensor",target:i(c[0])}:{state:"opt",label:"chk_battery_opt",target:{kind:"add-device",type:"home_battery"}},u.length>0?{state:"ok",label:"chk_grid",target:i(u[0])}:{state:"opt",label:"chk_grid_opt",target:{kind:"add-device",type:"grid_point"}}]}function co(t,e){let n=[];for(let r of t.floors)for(let o of r.furniture)o.type===e&&n.push({id:o.id,floorId:r.id,x:o.x,z:o.z,y:Math.max(.4,Math.min(1.4,o.h*.8))});return n}function Bv(t){if(!t?.rooms.length)return null;let e=0,n=0,r=0;for(let o of t.rooms)for(let[i,s]of o.points)e+=i,n+=s,r++;return r?{floorId:t.id,x:e/r,z:n/r,y:1}:null}function Wv(t){let e=qn(t);return co(t,"meter").find(n=>!e.has(n.id))??co(t,"inverter")[0]??Bv(ai(t))}function Vv(t,e){let n=co(t,"grid_point")[0];if(n)return n;let r=t.floors.find(l=>l.id===e.floorId);if(!r?.rooms.length)return null;let o=1/0,i=-1/0,s=-1/0;for(let l of r.rooms)for(let[a,c]of l.points)o=Math.min(o,a),i=Math.max(i,a),s=Math.max(s,c);return{floorId:e.floorId,x:Math.max(o,Math.min(i,e.x)),z:s+3,y:.2}}function Jh(t){let e=[],n=Wv(t);if(!n)return e;let r=new Set(t.floors.flatMap(i=>i.furniture).filter(i=>lo(t,i)).map(i=>i.id)),o=co(t,"inverter").find(i=>!r.has(i.id));for(let i of t.settings.roof.solar??[])e.push({key:`solar:${i.id}`,kind:"solar",id:i.id});co(t,"home_battery").some(i=>!r.has(i.id))&&e.push({key:"battery",kind:"battery",id:null}),o&&(o.floorId!==n.floorId||o.x!==n.x||o.z!==n.z)&&e.push({key:"inverter",kind:"inverter",id:null}),Vv(t,n)&&e.push({key:"grid",kind:"grid",id:null});for(let i of t.floors.flatMap(s=>s.furniture))r.has(i.id)&&(i.type==="inverter"?e.push({key:`inverter:${i.id}`,kind:"inverter",id:i.id}):i.type==="home_battery"&&e.push({key:`battery:${i.id}`,kind:"battery",id:i.id}));for(let i of qn(t))e.push({key:`meter:${i}`,kind:"meter",id:i});return e}var ep=(t,e)=>t.energy.routes?.find(n=>n.key===e&&n.points.length>0);var Kv={ok:"\u2713",todo:"\u25CB",opt:"\xB7"},np=t=>t.hass?We(t.hass,t.doc.floors):new Map,jv=Ne,rp=(t,e)=>e.name||t.t(`furn_${e.type}`);function op(t,e){let n=Qh(t.doc,np(t)),r=n.filter(o=>o.state==="ok").length;return m`
☑ ${t.t("chk_title")} ${r}/${n.length}
${M(t.t("chk_hint"))}
${n.map(o=>m`e.follow(o.target)}>
- ${Cv[o.state]} ${t.t(o.label)}
+ ${Kv[o.state]} ${t.t(o.label)}
`)}
- `}function tp(t,e){let n=t.doc.floors.flatMap(r=>r.furniture.filter(o=>Nv.includes(o.type)).map(o=>({floor:r,item:o})));return m``}function ip(t,e){let n=t.doc.floors.flatMap(r=>r.furniture.filter(o=>jv.includes(o.type)).map(o=>({floor:r,item:o})));return m`
⚡ ${t.t("energy_devices")}
${M(t.t("energy_devices_hint"))}
${n.length>0?m`
${n.map(({floor:r,item:o})=>m`
- e.openDevice(r,o)}>${Jh(t,o)} · ${r.name}
+ e.openDevice(r,o)}>${rp(t,o)} · ${r.name}
`)}
`:_}
${Ne.map(r=>m`e.addDevice(r)}>+ ${t.t(`furn_${r}`)} `)}
- `}var Xh=(t,e,n)=>m`${t.t(e)} ${t.t("energy_sign_flip")}
`;function np(t,e){let{energy:n}=t.doc,r=(b,v)=>t.hass?.states[b]?.attributes[v],o=H(t.hass,b=>Un(t.hass,b)),i=H(t.hass,b=>ge(b)&&r(b,"device_class")==="battery"),s=H(t.hass,b=>ge(b)&&(r(b,"device_class")==="monetary"||/\/(kWh|MWh)$/.test(r(b,"unit_of_measurement")??""))),l=Qh(t),a=Si(t.doc,b=>gi(b,l)),c=b=>t.replace({...structuredClone(t.doc),energy:{...t.doc.energy,...b}}),u=H(t.hass,b=>ge(b)&&["gas","water","volume_flow_rate"].includes(r(b,"device_class")??"")),d=b=>v=>c({[b]:v==="none"?null:v}),p=t.hass?Pa(t.hass,t.doc,[],a):null,h=!!p&&(p.solar??0)<20,f=h&&p.grid!==null&&p.grid<-50,g=h&&p.battery!==null&&p.battery<-50&&(p.grid??0)<=0,y=(b,v)=>D(t,t.t("energy_invert"),b,w=>c(v(w)));return m``}var tp=(t,e,n)=>m`${t.t(e)} ${t.t("energy_sign_flip")}
`;function sp(t,e){let{energy:n}=t.doc,r=(b,v)=>t.hass?.states[b]?.attributes[v],o=H(t.hass,b=>Un(t.hass,b)),i=H(t.hass,b=>ge(b)&&r(b,"device_class")==="battery"),s=H(t.hass,b=>ge(b)&&(r(b,"device_class")==="monetary"||/\/(kWh|MWh)$/.test(r(b,"unit_of_measurement")??""))),l=np(t),a=Si(t.doc,b=>gi(b,l)),c=b=>t.replace({...structuredClone(t.doc),energy:{...t.doc.energy,...b}}),u=H(t.hass,b=>ge(b)&&["gas","water","volume_flow_rate"].includes(r(b,"device_class")??"")),d=b=>v=>c({[b]:v==="none"?null:v}),p=t.hass?Pa(t.hass,t.doc,[],a):null,h=!!p&&(p.solar??0)<20,f=h&&p.grid!==null&&p.grid<-50,g=h&&p.battery!==null&&p.battery<-50&&(p.grid??0)<=0,y=(b,v)=>D(t,t.t("energy_invert"),b,w=>c(v(w)));return m`
⚖ ${t.t("energy_balance")}
${M(t.t("energy_balance_hint"))}
- ${f?Xh(t,"energy_sign_grid",()=>c({grid_invert:!n.grid_invert})):_}
- ${g?Xh(t,"energy_sign_battery",()=>c({battery_invert:!n.battery_invert})):_}
+ ${f?tp(t,"energy_sign_grid",()=>c({grid_invert:!n.grid_invert})):_}
+ ${g?tp(t,"energy_sign_battery",()=>c({battery_invert:!n.battery_invert})):_}
${z(t,t.t("energy_grid"),n.grid,a.grid,o,d("grid"))}
${y(n.grid_invert,b=>({grid_invert:b}))}
@@ -821,19 +821,19 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${n.advanced?D(t,t.t("energy_show_unmetered"),!!n.show_unmetered,b=>c({show_unmetered:b})):_}
${n.advanced?M(t.t("energy_show_unmetered_hint")):_}
- `}var rp=t=>m``}var ap=t=>m`
⚡ ${t.t("feature_name_energy")}
${M(t.t("feature_text_energy"))}
- `;function op(t){let e=(n,r,o)=>m`${r} ${t.t(o)} `;return m``;function lp(t){let e=(n,r,o)=>m`${r} ${t.t(o)} `;return m`
${t.t("help_title")}
${M(t.t("help_hint"))}
${e("issues/new/choose","\u{1F41E}","help_issue")}${e("discussions/categories/ideas","\u{1F4A1}","help_idea")}
- `}function Bv(t,e){let n=t.t,r=t.doc.floors.flatMap(i=>i.furniture).find(i=>i.id===e.id),o=r?Jh(t,r):"";switch(e.kind){case"solar":{let i=t.doc.settings.roof.solar??[],s=i.findIndex(l=>l.id===e.id);return n("route_conn_solar",{name:i[s]?.name||`${n("solar_field")} ${s+1}`})}case"battery":return e.id?n("route_conn_device",{name:o}):n("route_conn_battery");case"inverter":return e.id?n("route_conn_device",{name:o}):n("route_conn_inverter");case"grid":return n("route_conn_grid");case"meter":return n("route_conn_meter",{name:o})}}function ip(t,e){let n=qh(t.doc);if(!n.length)return _;let r=t.t,o=e.draft;return m``}function Gv(t,e){let n=t.t,r=t.doc.floors.flatMap(i=>i.furniture).find(i=>i.id===e.id),o=r?rp(t,r):"";switch(e.kind){case"solar":{let i=t.doc.settings.roof.solar??[],s=i.findIndex(l=>l.id===e.id);return n("route_conn_solar",{name:i[s]?.name||`${n("solar_field")} ${s+1}`})}case"battery":return e.id?n("route_conn_device",{name:o}):n("route_conn_battery");case"inverter":return e.id?n("route_conn_device",{name:o}):n("route_conn_inverter");case"grid":return n("route_conn_grid");case"meter":return n("route_conn_meter",{name:o})}}function cp(t,e){let n=Jh(t.doc);if(!n.length)return _;let r=t.t,o=e.draft;return m`
〰 ${r("energy_routes")}
${M(r("energy_routes_hint"))}
- ${n.map(i=>{let s=Yh(t.doc,i.key),l=o?.key===i.key;return m`
-
${Bv(t,i)} · ${s?r("route_points",{n:s.points.length}):r("route_none")}
+ ${n.map(i=>{let s=ep(t.doc,i.key),l=o?.key===i.key;return m`
+
${Gv(t,i)} · ${s?r("route_points",{n:s.points.length}):r("route_none")}
${l?m`
${r("route_drawing",{n:o.points.length})}
e.undoPoint()}>↶ ${r("route_undo")}
@@ -846,37 +846,37 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${s?D(t,r("route_cable"),!!s.cable,a=>e.setCable(i.key,a),{title:r("route_cable_hint")}):_}`}
`})}
- `}var at=(t,e)=>e.map(n=>t.toScreen(n).join(",")).join(" ");function Mi(t,e,n,r,o,i){let[[s,l],[a,c]]=[t.toScreen(e),t.toScreen(n)];if(Math.hypot(a-s,c-l)<=36)return _;let[u,d]=[(s+a)/2,(l+c)/2];return R`
`}var sp=(t,e)=>R`
`,Wv=(t,e,n)=>R`
${sp(...t.toScreen(e))} `,Vv=(t,e,n)=>R`
${sp(...t.toScreen(e))} `;function Kv(t,e,n,r){let{t:o,hass:i}=t.host,s=n.dormer?o("roof_dormer"):n.open?o("roof_open_short"):o(`roof_shape_${n.shape}`);return`${e.isFixed(n)?"\u{1F512} ":""}${r+1} \xB7 ${s} \xB7 ${K(i,on(n),1)} m`}function Ia(t,e){let n=t.host.doc.settings.roof,r=n.type==="custom"?n.sections??[]:[],o=t.host.admin,i=(s,l)=>{let a=s.id===e.sectionId,c=xe(s),u=(s.shape==="flat"||s.shape==="parapet")&&s.points&&s.points.length>=3?s.points:null,d=si(r,s),p=d?xe(na(d,s)):c,h=u??[p.at(p.u0,0),p.at(p.u1,0),p.at(p.u1,p.w),p.at(p.u0,p.w)],g=((s.shape==="flat"||s.shape==="parapet"?null:sn(s,{u0:0,u1:0,a:0,b:0}))?.ridges??[]).map(([C,B])=>{let[q,we]=t.toScreen(c.at(C[0],C[1])),[Mt,j]=t.toScreen(c.at(B[0],B[1]));return R`
`}),[y,b]=t.toScreen(c.at((c.u0+c.u1)/2,c.w/2)),v=a&&o&&!e.isFixed(s),w=[[0,0],[1,0],[1,1],[0,1]],x=s.shape==="flat"||s.shape==="parapet",[k,S,E,T]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],F=u??(s.rotation?Tr(s):[[k,E],[S,E],[S,T],[k,T]]),O=v&&x?F.map((C,B)=>Mi(t,C,F[(B+1)%F.length],"roof",s.id,B)):_,P=v?R`${O}${u?u.map((C,B)=>Wv(t,C,`${s.id}:${B}`)):w.map(([C,B])=>Vv(t,[C?S:k,B?T:E],`${s.id}:${C}:${B}`))}`:_;return R`
+ `}var at=(t,e)=>e.map(n=>t.toScreen(n).join(",")).join(" ");function Mi(t,e,n,r,o,i){let[[s,l],[a,c]]=[t.toScreen(e),t.toScreen(n)];if(Math.hypot(a-s,c-l)<=36)return _;let[u,d]=[(s+a)/2,(l+c)/2];return R` `}var up=(t,e)=>R` `,Uv=(t,e,n)=>R`${up(...t.toScreen(e))} `,Zv=(t,e,n)=>R`${up(...t.toScreen(e))} `;function qv(t,e,n,r){let{t:o,hass:i}=t.host,s=n.dormer?o("roof_dormer"):n.open?o("roof_open_short"):o(`roof_shape_${n.shape}`);return`${e.isFixed(n)?"\u{1F512} ":""}${r+1} \xB7 ${s} \xB7 ${K(i,on(n),1)} m`}function Ia(t,e){let n=t.host.doc.settings.roof,r=n.type==="custom"?n.sections??[]:[],o=t.host.admin,i=(s,l)=>{let a=s.id===e.sectionId,c=xe(s),u=(s.shape==="flat"||s.shape==="parapet")&&s.points&&s.points.length>=3?s.points:null,d=si(r,s),p=d?xe(na(d,s)):c,h=u??[p.at(p.u0,0),p.at(p.u1,0),p.at(p.u1,p.w),p.at(p.u0,p.w)],g=((s.shape==="flat"||s.shape==="parapet"?null:sn(s,{u0:0,u1:0,a:0,b:0}))?.ridges??[]).map(([C,B])=>{let[q,we]=t.toScreen(c.at(C[0],C[1])),[Mt,j]=t.toScreen(c.at(B[0],B[1]));return R` `}),[y,b]=t.toScreen(c.at((c.u0+c.u1)/2,c.w/2)),v=a&&o&&!e.isFixed(s),w=[[0,0],[1,0],[1,1],[0,1]],x=s.shape==="flat"||s.shape==="parapet",[k,S,E,T]=[Math.min(s.x0,s.x1),Math.max(s.x0,s.x1),Math.min(s.z0,s.z1),Math.max(s.z0,s.z1)],F=u??(s.rotation?zr(s):[[k,E],[S,E],[S,T],[k,T]]),O=v&&x?F.map((C,B)=>Mi(t,C,F[(B+1)%F.length],"roof",s.id,B)):_,P=v?R`${O}${u?u.map((C,B)=>Uv(t,C,`${s.id}:${B}`)):w.map(([C,B])=>Zv(t,[C?S:k,B?T:E],`${s.id}:${C}:${B}`))}`:_;return R`
${g}
- ${Kv(t,e,s,l)}
- ${P}`};return R`${r.map(i)} `}function jv(t,e,n,r,o){let i=r*Math.PI/180,[s,l]=t.toScreen(n),[a,c]=t.toScreen([n[0]+Math.sin(i)*o,n[1]-Math.cos(i)*o]);return R`
+ ${qv(t,e,s,l)}
+ ${P}`};return R`${r.map(i)} `}function Yv(t,e,n,r,o){let i=r*Math.PI/180,[s,l]=t.toScreen(n),[a,c]=t.toScreen([n[0]+Math.sin(i)*o,n[1]-Math.cos(i)*o]);return R`
- `}function ap(t,e){let{doc:n,admin:r}=t.host,o=n.settings.roof.solar??[];if(o.length===0)return _;let i=Z(n),s=l=>{let a=$e(n,l,i);if(!a||a.wall&&a.wall.floorId!==t.floorId)return _;let c=l.id===e.solarId,u=_;if(c&&a.unbounded&&r&&!l.locked){let h=Wr(a,l),f=Math.max(...Ze(a,l,!0).flatMap(g=>g.corners.map(y=>Math.hypot(y[0]-h[0],y[2]-h[1]))));u=jv(t,l.id,h,l.rotation??0,.9+f*.5)}let d=h=>{let f;if(a.wall){let g=Math.max(.3,...h.corners.map(w=>(w[0]-a.o[0])*a.n[0]+(w[2]-a.o[2])*a.n[2])),[y,b]=[h.corners[0],h.corners[1]],v=w=>[w[0]+a.n[0]*g,w[2]+a.n[2]*g];f=[[y[0],y[2]],v(y),v(b),[b[0],b[2]]]}else f=h.corners.map(g=>[g[0],g[2]]);return R` `},p=`nf-solar${c?" nf-solar-sel":""}${c&&e.picking?" nf-solar-pick":""}`;return R`${Ze(a,l,c).map(d)} ${u}`};return R`${o.map(s)} `}function lp(t,e){let n=t.host.doc.settings.roof.windows??[];if(n.length===0)return _;let r=new Map(Z(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face),l=s?da(s,i):null;return l?R`[a[0],a[2]]))} /> `:_};return R`${n.map(o)} `}var Gv={inverter:"\u26A1",home_battery:"\u{1F50B}",wallbox:"\u{1F50C}",meter:"\u{1F4DF}",grid_point:"\u{1F3C1}"};function cp(t,e,n){if(!e)return _;let r=e.furniture.filter(i=>Ne.includes(i.type)),o=i=>{let[s,l]=t.toScreen([i.x,i.z]),a=i.id===n,c=t.host.t(`furn_${i.type}`);return R`
+ `}function dp(t,e){let{doc:n,admin:r}=t.host,o=n.settings.roof.solar??[];if(o.length===0)return _;let i=Z(n),s=l=>{let a=$e(n,l,i);if(!a||a.wall&&a.wall.floorId!==t.floorId)return _;let c=l.id===e.solarId,u=_;if(c&&a.unbounded&&r&&!l.locked){let h=Vr(a,l),f=Math.max(...Ze(a,l,!0).flatMap(g=>g.corners.map(y=>Math.hypot(y[0]-h[0],y[2]-h[1]))));u=Yv(t,l.id,h,l.rotation??0,.9+f*.5)}let d=h=>{let f;if(a.wall){let g=Math.max(.3,...h.corners.map(w=>(w[0]-a.o[0])*a.n[0]+(w[2]-a.o[2])*a.n[2])),[y,b]=[h.corners[0],h.corners[1]],v=w=>[w[0]+a.n[0]*g,w[2]+a.n[2]*g];f=[[y[0],y[2]],v(y),v(b),[b[0],b[2]]]}else f=h.corners.map(g=>[g[0],g[2]]);return R` `},p=`nf-solar${c?" nf-solar-sel":""}${c&&e.picking?" nf-solar-pick":""}`;return R`${Ze(a,l,c).map(d)} ${u}`};return R`${o.map(s)} `}function hp(t,e){let n=t.host.doc.settings.roof.windows??[];if(n.length===0)return _;let r=new Map(Z(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face),l=s?da(s,i):null;return l?R`[a[0],a[2]]))} /> `:_};return R`${n.map(o)} `}var Xv={inverter:"\u26A1",home_battery:"\u{1F50B}",wallbox:"\u{1F50C}",meter:"\u{1F4DF}",grid_point:"\u{1F3C1}"};function pp(t,e,n){if(!e)return _;let r=e.furniture.filter(i=>Ne.includes(i.type)),o=i=>{let[s,l]=t.toScreen([i.x,i.z]),a=i.id===n,c=t.host.t(`furn_${i.type}`);return R`
- ${Gv[i.type]??"\u26A1"}
+ ${Xv[i.type]??"\u26A1"}
${a?R`${c} `:_}
${c}
- `};return R`${r.map(o)} `}function up(t,e){let{doc:n,hass:r}=t.host;if(!(n.settings.roof.sections??[]).some(s=>oa(s,e.elevation+e.height)))return _;let i=[1.5,2].flatMap(s=>ia({settings:n.settings},e.elevation,s).map(([l,a])=>{let[c,u]=t.toScreen(l),[d,p]=t.toScreen(a);return R`
- ${K(r,s,1)} m `}));return R`${i}`}function dp(t,e,n,r){if(!e)return _;let o=(i,s)=>{let l=[];return i.forEach((a,c)=>{if(a.floor_id!==e.id)return;let[u,d]=t.toScreen([a.x,a.z]),p=i[c+1];if(p?.floor_id===e.id){let[f,g]=t.toScreen([p.x,p.z]);l.push(R` `)}let h=p&&p.floor_id!==e.id||c>0&&i[c-1].floor_id!==e.id;l.push(R` `),s&&l.push(R`${c+1} `)}),R`${l} `};return R`${n.filter(i=>i.key!==r?.key).map(i=>o(i.points,!1))}${r?o(r.points,!0):_} `}function hp(t,e){let n=t.host.doc.settings.roof.chimneys??[];if(n.length===0)return _;let r=new Map(Z(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face);if(!s)return _;let{shape:l,w:a,d:c}=hn(i),{center:u,along:d,across:p}=ha(s,i),h=l==="round"||l==="steel"?Array.from({length:16},(f,g)=>[u[0]+Math.cos(g/16*2*Math.PI)*Math.min(a,c)/2,u[1]+Math.sin(g/16*2*Math.PI)*Math.min(a,c)/2]):[[-1,-1],[1,-1],[1,1],[-1,1]].map(([f,g])=>[u[0]+d[0]*a*f/2+p[0]*c*g/2,u[1]+d[1]*a*f/2+p[1]*c*g/2]);return R` `};return R`${n.map(o)} `}function Uv(t,e,n){let[r,o]=[t+n/2,e-30];return R`
+ `};return R`${r.map(o)} `}function fp(t,e){let{doc:n,hass:r}=t.host;if(!(n.settings.roof.sections??[]).some(s=>oa(s,e.elevation+e.height)))return _;let i=[1.5,2].flatMap(s=>ia({settings:n.settings},e.elevation,s).map(([l,a])=>{let[c,u]=t.toScreen(l),[d,p]=t.toScreen(a);return R`
+ ${K(r,s,1)} m `}));return R`${i}`}function mp(t,e,n,r){if(!e)return _;let o=(i,s)=>{let l=[];return i.forEach((a,c)=>{if(a.floor_id!==e.id)return;let[u,d]=t.toScreen([a.x,a.z]),p=i[c+1];if(p?.floor_id===e.id){let[f,g]=t.toScreen([p.x,p.z]);l.push(R` `)}let h=p&&p.floor_id!==e.id||c>0&&i[c-1].floor_id!==e.id;l.push(R` `),s&&l.push(R`${c+1} `)}),R`${l} `};return R`${n.filter(i=>i.key!==r?.key).map(i=>o(i.points,!1))}${r?o(r.points,!0):_} `}function gp(t,e){let n=t.host.doc.settings.roof.chimneys??[];if(n.length===0)return _;let r=new Map(Z(t.host.doc).map(i=>[i.key,i])),o=i=>{let s=r.get(i.face);if(!s)return _;let{shape:l,w:a,d:c}=hn(i),{center:u,along:d,across:p}=ha(s,i),h=l==="round"||l==="steel"?Array.from({length:16},(f,g)=>[u[0]+Math.cos(g/16*2*Math.PI)*Math.min(a,c)/2,u[1]+Math.sin(g/16*2*Math.PI)*Math.min(a,c)/2]):[[-1,-1],[1,-1],[1,1],[-1,1]].map(([f,g])=>[u[0]+d[0]*a*f/2+p[0]*c*g/2,u[1]+d[1]*a*f/2+p[1]*c*g/2]);return R` `};return R`${n.map(o)} `}function Qv(t,e,n){let[r,o]=[t+n/2,e-30];return R`
- `}function Zv(t,e){let n=e.level?.length?e.level:e.ruler;if(!n?.length)return _;let r=n.map(o=>t.toScreen(o));return R`
+ `}function Jv(t,e){let n=e.level?.length?e.level:e.ruler;if(!n?.length)return _;let r=n.map(o=>t.toScreen(o));return R`
${r.length===2?R` `:_}
${r.map(([o,i])=>R` `)}
- `}function pp(t,e,n){let r=n?.background,o=e.picture(r?.image_id);if(!r||!o)return _;let[i,s]=t.toScreen([r.x,r.z]),l=r.width*t.scale,a=l*o.aspect,c=e.handlesShown;return R`
+ `}function _p(t,e,n){let r=n?.background,o=e.picture(r?.image_id);if(!r||!o)return _;let[i,s]=t.toScreen([r.x,r.z]),l=r.width*t.scale,a=l*o.aspect,c=e.handlesShown;return R`
${c?R`
- ${Uv(i,s,l)}`:_}
- ${Zv(t,e)}`}var qv="strict-origin-when-cross-origin",Da=new Map,fp=new Map,Ri=new Map;function Yv(t){let e=Da.get(t);return e||(e=fetch(t,{referrerPolicy:qv,mode:"cors",credentials:"omit"}).then(async n=>n.ok&&(n.headers.get("content-type")??"").startsWith("image/")?await n.blob():null).catch(()=>null).then(n=>(n||setTimeout(()=>Da.delete(t),6e4),n)),Da.set(t,e)),e}function mp(t,e){let n=fp.get(t);if(n)return n;let r=Ri.get(t);return r||(r=new Set,Ri.set(t,r),Yv(t).then(o=>{o&&fp.set(t,URL.createObjectURL(o));let i=Ri.get(t)??new Set;if(Ri.delete(t),o)for(let s of i)s()})),r.add(e),null}function gp(t,e){let n=e.map;if(!ki(n))return _;let r=Hh(n),o=Oh(n),[i,s]=t.toScreen([r.x,r.z]),l=t.scale;return R`
- ${Ih(n.lat,n.lon,r.zoom).map(a=>({tile:a,href:mp(Dh(o,a),t.redraw)})).filter(a=>a.href).map(({tile:a,href:c})=>R` `)}
- `}var Oa=t=>Math.round(t*1e3)/1e3,Ha=(t,e)=>t.width*e,Yn=(t,e)=>[t.x+t.width/2,t.z+Ha(t,e)/2];function _p(t,e,n){let[r,o]=[t[0]-e[0],t[1]-e[1]];return[e[0]+r*Math.cos(n)-o*Math.sin(n),e[1]+r*Math.sin(n)+o*Math.cos(n)]}var bp=t=>((t+180)%360+360)%360-180;function yp(t,e,n){return{x:Oa(t[0]-e/2),z:Oa(t[1]-n/2)}}function vp(t,e,n,r){if(Math.hypot(r[0]-n[0],r[1]-n[1])<.05)return null;let o=Math.atan2(r[1]-n[1],r[0]-n[0]),i=Math.round(o/(Math.PI/2))*(Math.PI/2)-o;if(Math.abs(i)<1e-4)return null;let s=_p(Yn(t,e),n,i),l=Math.round(bp((t.rotation??0)+i*180/Math.PI)*100)/100;return{...t,rotation:l,...yp(s,t.width,Ha(t,e))}}function wp(t,e,n,r,o){let i=Math.hypot(r[0]-n[0],r[1]-n[1]);if(!(o>0)||i<1e-4)return null;let s=o/i,[l,a]=Yn(t,e),c=[n[0]+s*(l-n[0]),n[1]+s*(a-n[1])],u=t.width*s;return{...t,width:Oa(u),...yp(c,u,Ha(t,e)*s)}}function kp(t,e,n){let r=_p(n,Yn(t,e),-(t.rotation??0)*Math.PI/180);return[r[0]-t.x,r[1]-t.z]}function xp(t,e,n,r){let o=t+(n-e)*180/Math.PI;return bp(r?Math.round(o/15)*15:Math.round(o*10)/10)}var Xv=2048;async function Xn(t){let e=await createImageBitmap(t),n=Math.min(1,Xv/Math.max(e.width,e.height)),r=document.createElement("canvas");return r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext("2d").drawImage(e,0,0,r.width,r.height),{data:r.toDataURL("image/jpeg",.85),aspect:r.height/r.width}}var Ei=class{deps;editMode=!1;levelPoints=null;rulerPoints=null;rulerMetres=0;sectionOpen=!1;pictures={};loading=new Set;constructor(e){this.deps=e}get edit(){return this.editMode}set edit(e){this.editMode=e,this.deps.refresh()}get level(){return this.levelPoints}set level(e){this.levelPoints=e,this.deps.refresh()}get ruler(){return this.rulerPoints}set ruler(e){this.rulerPoints=e,this.deps.refresh()}get rulerLength(){return this.rulerMetres}set rulerLength(e){this.rulerMetres=e,this.deps.refresh()}get open(){return this.sectionOpen}set open(e){this.sectionOpen=e,this.deps.refresh()}get handlesShown(){let{host:e}=this.deps;return!!e.floor?.background&&e.admin&&this.deps.currentTool()==="select"&&this.editMode}picture(e){return e?this.pictures[e]:void 0}ensureLoaded(e){!this.pictures[e]&&!this.loading.has(e)&&this.load(e)}async load(e){let{host:n,api:r}=this.deps;if(n.hass){this.loading.add(e);try{let o=await r.fetchImage(n.hass,e),i=await this.aspectOf(o);this.pictures={...this.pictures,[e]:{url:o,aspect:i}},this.deps.refresh()}catch{}}}async aspectOf(e){let n=new Image;return n.src=e,await n.decode(),n.naturalHeight/n.naturalWidth}async upload(e){let{host:n,api:r}=this.deps;if(!e||!n.hass)return;let{data:o,aspect:i}=await this.deps.readPicture(e),s=I("img");await r.storeImage(n.hass,s,o),this.pictures={...this.pictures,[s]:{url:o,aspect:i}};let l=n.floor?.rooms??[],a=l.length>0?de(l.flatMap(u=>u.points)):null,c={image_id:s,x:a?a.x0:0,z:a?a.z0:0,width:a?Math.max(4,Math.round((a.x1-a.x0)*1e3)/1e3):12,opacity:.5};this.setBackground(c)}setBackground(e){this.deps.host.change((n,r)=>Object.assign(r,{background:e}))}toggleLevel(){this.levelPoints=this.levelPoints?null:[],this.rulerPoints=null,this.editMode=!1,this.deps.refresh()}toggleRuler(){this.rulerPoints=this.rulerPoints?null:[],this.levelPoints=null,this.editMode=!1,this.deps.refresh()}toggleEdit(){this.edit=!this.editMode,this.editMode&&this.deps.useSelectTool()}tapLevel(e){let n=[...this.levelPoints??[],e];if(n.length<2){this.level=n;return}this.level=null,this.straighten(n[0],n[1])}tapRuler(e){this.rulerPoints&&this.rulerPoints.length<2&&(this.ruler=[...this.rulerPoints,e])}straighten(e,n){let r=this.deps.host.floor?.background,o=this.picture(r?.image_id),i=r&&o?vp(r,o.aspect,e,n):null;i&&this.setBackground(i)}applyRuler(){let e=this.deps.host.floor?.background,n=this.picture(e?.image_id),r=this.rulerPoints;if(!e||!n||!r||r.length<2)return;let o=wp(e,n.aspect,r[0],r[1],this.rulerMetres);o&&(this.setBackground(o),this.rulerPoints=null,this.rulerMetres=0,this.deps.refresh())}};var $p=.1,La=(t,e,n)=>m`${e} `;function Qv(t,e){let n=e.ruler;if(!n)return _;if(n.length<2)return M(t.t(n.length>0?"bg_ruler_second":"bg_ruler_first"),"nf-wide");let r=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]),o=()=>e.applyRuler();return m`${M(t.t("bg_ruler_length_hint",{m:K(t.hass,r,2)}),"nf-wide")}
+ ${Qv(i,s,l)}`:_}
+ ${Jv(t,e)}`}var e0="strict-origin-when-cross-origin",Da=new Map,bp=new Map,Ri=new Map;function t0(t){let e=Da.get(t);return e||(e=fetch(t,{referrerPolicy:e0,mode:"cors",credentials:"omit"}).then(async n=>n.ok&&(n.headers.get("content-type")??"").startsWith("image/")?await n.blob():null).catch(()=>null).then(n=>(n||setTimeout(()=>Da.delete(t),6e4),n)),Da.set(t,e)),e}function yp(t,e){let n=bp.get(t);if(n)return n;let r=Ri.get(t);return r||(r=new Set,Ri.set(t,r),t0(t).then(o=>{o&&bp.set(t,URL.createObjectURL(o));let i=Ri.get(t)??new Set;if(Ri.delete(t),o)for(let s of i)s()})),r.add(e),null}function vp(t,e){let n=e.map;if(!ki(n))return _;let r=Bh(n),o=Nh(n),[i,s]=t.toScreen([r.x,r.z]),l=t.scale;return R`
+ ${Lh(n.lat,n.lon,r.zoom).map(a=>({tile:a,href:yp(Ch(o,a),t.redraw)})).filter(a=>a.href).map(({tile:a,href:c})=>R` `)}
+ `}var Oa=t=>Math.round(t*1e3)/1e3,Ha=(t,e)=>t.width*e,Yn=(t,e)=>[t.x+t.width/2,t.z+Ha(t,e)/2];function wp(t,e,n){let[r,o]=[t[0]-e[0],t[1]-e[1]];return[e[0]+r*Math.cos(n)-o*Math.sin(n),e[1]+r*Math.sin(n)+o*Math.cos(n)]}var kp=t=>((t+180)%360+360)%360-180;function xp(t,e,n){return{x:Oa(t[0]-e/2),z:Oa(t[1]-n/2)}}function $p(t,e,n,r){if(Math.hypot(r[0]-n[0],r[1]-n[1])<.05)return null;let o=Math.atan2(r[1]-n[1],r[0]-n[0]),i=Math.round(o/(Math.PI/2))*(Math.PI/2)-o;if(Math.abs(i)<1e-4)return null;let s=wp(Yn(t,e),n,i),l=Math.round(kp((t.rotation??0)+i*180/Math.PI)*100)/100;return{...t,rotation:l,...xp(s,t.width,Ha(t,e))}}function Sp(t,e,n,r,o){let i=Math.hypot(r[0]-n[0],r[1]-n[1]);if(!(o>0)||i<1e-4)return null;let s=o/i,[l,a]=Yn(t,e),c=[n[0]+s*(l-n[0]),n[1]+s*(a-n[1])],u=t.width*s;return{...t,width:Oa(u),...xp(c,u,Ha(t,e)*s)}}function Mp(t,e,n){let r=wp(n,Yn(t,e),-(t.rotation??0)*Math.PI/180);return[r[0]-t.x,r[1]-t.z]}function Rp(t,e,n,r){let o=t+(n-e)*180/Math.PI;return kp(r?Math.round(o/15)*15:Math.round(o*10)/10)}var n0=2048;async function Xn(t){let e=await createImageBitmap(t),n=Math.min(1,n0/Math.max(e.width,e.height)),r=document.createElement("canvas");return r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext("2d").drawImage(e,0,0,r.width,r.height),{data:r.toDataURL("image/jpeg",.85),aspect:r.height/r.width}}var Ei=class{deps;editMode=!1;levelPoints=null;rulerPoints=null;rulerMetres=0;sectionOpen=!1;pictures={};loading=new Set;constructor(e){this.deps=e}get edit(){return this.editMode}set edit(e){this.editMode=e,this.deps.refresh()}get level(){return this.levelPoints}set level(e){this.levelPoints=e,this.deps.refresh()}get ruler(){return this.rulerPoints}set ruler(e){this.rulerPoints=e,this.deps.refresh()}get rulerLength(){return this.rulerMetres}set rulerLength(e){this.rulerMetres=e,this.deps.refresh()}get open(){return this.sectionOpen}set open(e){this.sectionOpen=e,this.deps.refresh()}get handlesShown(){let{host:e}=this.deps;return!!e.floor?.background&&e.admin&&this.deps.currentTool()==="select"&&this.editMode}picture(e){return e?this.pictures[e]:void 0}ensureLoaded(e){!this.pictures[e]&&!this.loading.has(e)&&this.load(e)}async load(e){let{host:n,api:r}=this.deps;if(n.hass){this.loading.add(e);try{let o=await r.fetchImage(n.hass,e),i=await this.aspectOf(o);this.pictures={...this.pictures,[e]:{url:o,aspect:i}},this.deps.refresh()}catch{}}}async aspectOf(e){let n=new Image;return n.src=e,await n.decode(),n.naturalHeight/n.naturalWidth}async upload(e){let{host:n,api:r}=this.deps;if(!e||!n.hass)return;let{data:o,aspect:i}=await this.deps.readPicture(e),s=I("img");await r.storeImage(n.hass,s,o),this.pictures={...this.pictures,[s]:{url:o,aspect:i}};let l=n.floor?.rooms??[],a=l.length>0?de(l.flatMap(u=>u.points)):null,c={image_id:s,x:a?a.x0:0,z:a?a.z0:0,width:a?Math.max(4,Math.round((a.x1-a.x0)*1e3)/1e3):12,opacity:.5};this.setBackground(c)}setBackground(e){this.deps.host.change((n,r)=>Object.assign(r,{background:e}))}toggleLevel(){this.levelPoints=this.levelPoints?null:[],this.rulerPoints=null,this.editMode=!1,this.deps.refresh()}toggleRuler(){this.rulerPoints=this.rulerPoints?null:[],this.levelPoints=null,this.editMode=!1,this.deps.refresh()}toggleEdit(){this.edit=!this.editMode,this.editMode&&this.deps.useSelectTool()}tapLevel(e){let n=[...this.levelPoints??[],e];if(n.length<2){this.level=n;return}this.level=null,this.straighten(n[0],n[1])}tapRuler(e){this.rulerPoints&&this.rulerPoints.length<2&&(this.ruler=[...this.rulerPoints,e])}straighten(e,n){let r=this.deps.host.floor?.background,o=this.picture(r?.image_id),i=r&&o?$p(r,o.aspect,e,n):null;i&&this.setBackground(i)}applyRuler(){let e=this.deps.host.floor?.background,n=this.picture(e?.image_id),r=this.rulerPoints;if(!e||!n||!r||r.length<2)return;let o=Sp(e,n.aspect,r[0],r[1],this.rulerMetres);o&&(this.setBackground(o),this.rulerPoints=null,this.rulerMetres=0,this.deps.refresh())}};var Ep=.1,La=(t,e,n)=>m`
${e} `;function r0(t,e){let n=e.ruler;if(!n)return _;if(n.length<2)return M(t.t(n.length>0?"bg_ruler_second":"bg_ruler_first"),"nf-wide");let r=Math.hypot(n[1][0]-n[0][0],n[1][1]-n[0][1]),o=()=>e.applyRuler();return m`${M(t.t("bg_ruler_length_hint",{m:K(t.hass,r,2)}),"nf-wide")}
${t.t("bg_ruler_length")}
i.key==="Enter"&&o()}
/>
-
0)} @click=${o}>${t.t("bg_ruler_apply")} `}function Jv(t,e){if(!t.admin)return _;let n=t.t,r=e.level;return m`${La(e.edit,n(e.edit?"background_edit_done":"background_edit"),()=>e.toggleEdit())}
+
0)} @click=${o}>${t.t("bg_ruler_apply")} `}function o0(t,e){if(!t.admin)return _;let n=t.t,r=e.level;return m`${La(e.edit,n(e.edit?"background_edit_done":"background_edit"),()=>e.toggleEdit())}
${M(n(e.edit?"background_handles_hint":"background_fixed_hint"),"nf-wide")}
${La(!!r,`\u{1F4D0} ${n(r?"bg_level_cancel":"bg_level")}`,()=>e.toggleLevel())}
${r?M(n(r.length>0?"bg_level_second":"bg_level_first"),"nf-wide"):_}
${La(!!e.ruler,`\u{1F4CF} ${n(e.ruler?"bg_ruler_cancel":"bg_ruler")}`,()=>e.toggleRuler())}
- ${Qv(t,e)}`}function Sp(t,e,n){let r=n.background,o=t.t,i=s=>r&&e.setBackground({...r,...s});return m`
e.open=s.target.open}>
+ ${r0(t,e)}`}function Ap(t,e,n){let r=n.background,o=t.t,i=s=>r&&e.setBackground({...r,...s});return m`e.open=s.target.open}>
${o("background")}
${r?m`${A(t,o("x"),r.x,s=>i({x:s}))} ${A(t,o("z"),r.z,s=>i({z:s}))}
- ${A(t,o("background_width"),r.width,s=>i({width:Math.max($p,s)}),.01,$p)}
+ ${A(t,o("background_width"),r.width,s=>i({width:Math.max(Ep,s)}),.01,Ep)}
${A(t,o("background_rotation"),r.rotation??0,s=>i({rotation:Math.round(s*10)/10}),.5)}
- ${Jv(t,e)}
+ ${o0(t,e)}
${o("background_opacity")}
- i({opacity:Number.parseFloat(s.target.value)})} />
+ i({opacity:Number.parseFloat(s.target.value)})} />
e.setBackground(null)}>${o("background_remove")} `:_}
- `}var e0=t=>t.map((e,n)=>[e,t[(n+1)%t.length]]);function t0(t,e,n){let r=G(n,e),o=J(r,r),i=o?Math.max(0,Math.min(1,J(G(t,e),r)/o)):0;return me(G(t,[e[0]+r[0]*i,e[1]+r[1]*i]))}function Mp(t,e,n=.03){return t.every(r=>N(r,e)||e0(e).some(([o,i])=>t0(r,o,i)<=n))}var Ca=["straight","quarter","l","half","u","spiral"],Na=["solid","stringer","mono","cantilever"],Ba=["none","left","right","both"],Wa=["headroom","full","none"],gt={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null},Va={straight:[1,3.2],quarter:[2.2,2.6],l:[2.2,2.8],half:[2,2.6],u:[2.2,2.6],spiral:[1.6,1.6]},Tp=2,zp=40;var Ai=(t,e)=>typeof e=="string"&&t.includes(e);function po(t){let e=t.stair??{},n=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(zp,Math.max(Tp,e.steps))):null,r=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:Ai(Ca,e.shape)?e.shape:gt.shape,turn:e.turn==="left"?"left":"right",build:Ai(Na,e.build)?e.build:gt.build,risers:e.risers!==!1,steps:n,run_width:r,down:e.down===!0,rail:Ai(Ba,e.rail)?e.rail:gt.rail,opening:Ai(Wa,e.opening)?e.opening:gt.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var uo=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n],Rp=(t,e)=>Math.abs(t[0]-e[0])<1e-6&&Math.abs(t[1]-e[1])<1e-6;function Pp(t){let e=[];for(let n of t)(!e.length||!Rp(e[e.length-1],n))&&e.push(n);for(;e.length>1&&Rp(e[0],e[e.length-1]);)e.pop();return e}function ho(t,e,n=!1){return{poly:Pp([...t,...[...e].reverse()]),landing:n,left:t,right:e}}function co(t,e,n,r,o){let i=[];for(let s=0;se+1e-6&&ot.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Ap(t,e,n,r,o){let i=r0(t),s=[];for(let l=0;l=8?3:2),[p,h]=t.shape==="l"?Fp(t,r)??Fi(r-d,n-a,e-a):Fi(r-d,n-a,e-a),f=co([o,l],[o+a,l],[o,s+a],c,p),g=t.shape==="l"?[ho(u,[c],!0)]:Ap(u,c,c,c,d),y=co([o+a,s],c,[i,s],[i,s+a],h);return{treads:[...f,...g,...y],flight:a,column:0}}case"half":case"u":{let a=Math.min(t.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=s+a,u=[[o,c],[o,s],[i,s],[i,c]],[d,p]=[[o+a,c],[i-a,c]],h=t.shape==="u"?1:Math.min(r,r>=12?6:r>=8?4:2),[f,g]=t.shape==="u"?Fp(t,r)??Fi(r-h,n-a,n-a):Fi(r-h,n-a,n-a),y=co([o,l],[o+a,l],[o,c],d,f),b=t.shape==="u"?[ho(u,[d,p],!0)]:Ap(u,d,[0,c],p,h),v=co([i,c],p,[i,l],[i-a,l],g);return{treads:[...y,...b,...v],flight:a,column:0}}case"spiral":{let a=Math.min(e,n)/2,c=Math.min(.08,a*.12),u=Math.min(.75,Math.max(.3,.22/(a*.6))),d=(h,f)=>[Math.cos(f)*h,Math.sin(f)*h],p=[];for(let h=0;hd(a,f+(g-f)*b));p.push(ho(y,[d(c,f),d(c,g)]))}return{treads:p,flight:a-c,column:c}}default:return{treads:co([o,l],[i,l],[o,s],[i,s],r),flight:e,column:0}}}var i0=(t,e)=>t.steps??Math.min(zp,Math.max(Tp,Math.round(Math.abs(e)/.18)));function _n(t,e,n,r){let o=i0(t,r),i=Math.abs(r)/o,s=o0(t,Math.max(.3,e),Math.max(.3,n),o),l=c=>[-c[0],c[1]];return{treads:s.treads.map((c,u)=>{let d=t.down?-i*(u+1):i*(u+1);return t.turn==="right"?{...c,top:d}:{poly:c.poly.map(l).reverse(),top:d,landing:c.landing,left:c.right.map(l),right:c.left.map(l)}}),rise:i,steps:o,column:s.column,flight:s.flight}}function Ti(t){let e=t.poly.reduce((n,r)=>[n[0]+r[0],n[1]+r[1]],[0,0]);return[e[0]/t.poly.length,e[1]/t.poly.length]}var ee=t=>Math.round(t*1e3)/1e3,s0=(t,e)=>((t+e)%360+360)%360;function Ip(t,e){return{id:I("wall"),a:[ee(t[0]),ee(t[1])],b:[ee(e[0]),ee(e[1])],thickness:null}}function Dp(t,e){let n=Math.hypot(t.b[0]-t.a[0],t.b[1]-t.a[1])||1,r=Math.max(.1,e)/n;return[ee(t.a[0]+(t.b[0]-t.a[0])*r),ee(t.a[1]+(t.b[1]-t.a[1])*r)]}var Op=(t,e)=>({height:t>=e-.005?null:Math.max(.05,t)});function Hp(t,e){return{id:I("hole"),type:"stairwell",x:ee((t[0]+e[0])/2),z:ee((t[1]+e[1])/2),w:ee(e[0]-t[0]),d:ee(e[1]-t[1]),h:.02,rotation:0,variant:null}}var Lp=t=>({id:I("outdoor"),type:"lawn",points:t.map(([e,n])=>[ee(e),ee(n)])});function Cp(t,e,n){t.points.splice(e+1,0,[ee(n[0]),ee(n[1])])}function Np(t,e){return t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),!0)}var Bp=t=>({...t,id:I("outdoor"),points:t.points.map(([e,n])=>[ee(e+.5),ee(n+.5)])});function Ka(t,e,n,r){let[o,i,s]=ut(t),l=e.floors.filter(u=>u.elevation>n.elevation).sort((u,d)=>u.elevation-d.elevation)[0],a=t==="stairs"?ee(l?l.elevation-n.elevation:n.height+.25):s,c={id:I("furniture"),type:t,x:ee(r[0]),z:ee(r[1]),rotation:0,w:o,d:i,h:a,variant:null};return t==="stairs"&&(c.stair={...gt}),c}var Wp=t=>({...structuredClone(t),id:I("furniture"),x:ee(t.x+.3),z:ee(t.z+.3)}),Vp=(t,e)=>s0(t,e);function Kp(t){let[e,n,r]=ut("parking");return{id:I("furniture"),type:"parking",x:t.x,z:t.z,rotation:t.rotation,w:Math.max(e,ee(t.w+.5)),d:Math.max(n,ee(t.d+.4)),h:r,variant:null,vehicle:t.type,...t.name?{name:t.name}:{}}}function jp(t,e){let[n,r,o]=ut(e);return{id:I("furniture"),type:e,x:t.x,z:t.z,rotation:t.rotation??0,w:n,d:r,h:o,variant:null,entity:t.entity_id,name:t.name??null,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.locked?{locked:!0}:{}}}var Gp=(t,e)=>({entity_id:e,x:t.x,z:t.z,y:null,rotation:t.rotation,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.name?{name:t.name}:{}});function Up(t,e){for(let n of t.floors)n.placements=n.placements.filter(r=>r.entity_id!==e),n.furniture=n.furniture.filter(r=>!(ce(r.type)&&r.entity===e))}function ja(t,e,n,r){let o=new Set(r);for(let s of t.floors)s.placements=s.placements.filter(l=>!o.has(l.entity_id)),s.furniture=s.furniture.filter(l=>!(ce(l.type)&&l.entity&&o.has(l.entity)));let i=[...e.placements.map(s=>[s.x,s.z]),...e.furniture.filter(s=>ce(s.type)).map(s=>[s.x,s.z])];for(let s of Vu(n,r,i)){if(!s.entity_id.startsWith("light.")){e.placements.push(s);continue}let[l,a,c]=tt.lamp_ceiling;e.furniture.push({id:I("furniture"),type:"lamp_ceiling",x:s.x,z:s.z,rotation:0,w:l,d:a,h:c,variant:null,entity:s.entity_id,power:null})}}function Zp(t){let[e,n]=be(t.points);return[ee(e),ee(n)]}function qp(t,e,n,r){let o=Math.min(n,t)/2,i=r>0?Math.round(e/r)*r:e;return ee(Math.min(t-o,Math.max(o,i)))}function Yp(t,e){let n=Rn[e],r=En(t)===e?{}:{width:n.width};return{type:n.type,leaves:n.leaves,sill:n.sill,height:n.height,style:n.style??null,opens:n.opens??null,...r}}function Xp(t,e,n){let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:e==="w"?s=o+Math.max(.1,n):l=i+Math.max(.1,n),[[o,i],[s,i],[s,l],[o,l]].map(([a,c])=>[ee(a),ee(c)])}function Qp(t){return t.furniture.map((e,n)=>({item:e,index:n,base:At(t,e)})).sort((e,n)=>e.base-n.base||e.index-n.index).map(e=>e.item)}function zi(t,e,n){if(!t.admin)return _;let r=n.edit?.key===e;return m`n.setEdit(r?null:{key:e,bulge:.5,error:null})}>
+ `}var i0=t=>t.map((e,n)=>[e,t[(n+1)%t.length]]);function s0(t,e,n){let r=G(n,e),o=ee(r,r),i=o?Math.max(0,Math.min(1,ee(G(t,e),r)/o)):0;return me(G(t,[e[0]+r[0]*i,e[1]+r[1]*i]))}function Fp(t,e,n=.03){return t.every(r=>N(r,e)||i0(e).some(([o,i])=>s0(r,o,i)<=n))}var Ca=["straight","quarter","l","half","u","spiral"],Na=["solid","stringer","mono","cantilever"],Ba=["none","left","right","both"],Wa=["headroom","full","none"],gt={shape:"straight",turn:"right",build:"solid",risers:!0,steps:null,run_width:null,down:!1,rail:"none",opening:"headroom",landing_after:null},Va={straight:[1,3.2],quarter:[2.2,2.6],l:[2.2,2.8],half:[2,2.6],u:[2.2,2.6],spiral:[1.6,1.6]},Dp=2,Op=40;var Ai=(t,e)=>typeof e=="string"&&t.includes(e);function fo(t){let e=t.stair??{},n=typeof e.steps=="number"&&Number.isFinite(e.steps)?Math.round(Math.min(Op,Math.max(Dp,e.steps))):null,r=typeof e.run_width=="number"&&Number.isFinite(e.run_width)&&e.run_width>.2?e.run_width:null;return{shape:Ai(Ca,e.shape)?e.shape:gt.shape,turn:e.turn==="left"?"left":"right",build:Ai(Na,e.build)?e.build:gt.build,risers:e.risers!==!1,steps:n,run_width:r,down:e.down===!0,rail:Ai(Ba,e.rail)?e.rail:gt.rail,opening:Ai(Wa,e.opening)?e.opening:gt.opening,landing_after:typeof e.landing_after=="number"&&Number.isFinite(e.landing_after)?Math.max(1,Math.round(e.landing_after)):null}}var ho=(t,e,n)=>[t[0]+(e[0]-t[0])*n,t[1]+(e[1]-t[1])*n],Tp=(t,e)=>Math.abs(t[0]-e[0])<1e-6&&Math.abs(t[1]-e[1])<1e-6;function Hp(t){let e=[];for(let n of t)(!e.length||!Tp(e[e.length-1],n))&&e.push(n);for(;e.length>1&&Tp(e[0],e[e.length-1]);)e.pop();return e}function po(t,e,n=!1){return{poly:Hp([...t,...[...e].reverse()]),landing:n,left:t,right:e}}function uo(t,e,n,r,o){let i=[];for(let s=0;s
e+1e-6&&ot.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function Pp(t,e,n,r,o){let i=l0(t),s=[];for(let l=0;l=8?3:2),[p,h]=t.shape==="l"?Ip(t,r)??Fi(r-d,n-a,e-a):Fi(r-d,n-a,e-a),f=uo([o,l],[o+a,l],[o,s+a],c,p),g=t.shape==="l"?[po(u,[c],!0)]:Pp(u,c,c,c,d),y=uo([o+a,s],c,[i,s],[i,s+a],h);return{treads:[...f,...g,...y],flight:a,column:0}}case"half":case"u":{let a=Math.min(t.run_width??Math.min(1.1,(e-.1)/2),(e-.02)/2),c=s+a,u=[[o,c],[o,s],[i,s],[i,c]],[d,p]=[[o+a,c],[i-a,c]],h=t.shape==="u"?1:Math.min(r,r>=12?6:r>=8?4:2),[f,g]=t.shape==="u"?Ip(t,r)??Fi(r-h,n-a,n-a):Fi(r-h,n-a,n-a),y=uo([o,l],[o+a,l],[o,c],d,f),b=t.shape==="u"?[po(u,[d,p],!0)]:Pp(u,d,[0,c],p,h),v=uo([i,c],p,[i,l],[i-a,l],g);return{treads:[...y,...b,...v],flight:a,column:0}}case"spiral":{let a=Math.min(e,n)/2,c=Math.min(.08,a*.12),u=Math.min(.75,Math.max(.3,.22/(a*.6))),d=(h,f)=>[Math.cos(f)*h,Math.sin(f)*h],p=[];for(let h=0;hd(a,f+(g-f)*b));p.push(po(y,[d(c,f),d(c,g)]))}return{treads:p,flight:a-c,column:c}}default:return{treads:uo([o,l],[i,l],[o,s],[i,s],r),flight:e,column:0}}}var u0=(t,e)=>t.steps??Math.min(Op,Math.max(Dp,Math.round(Math.abs(e)/.18)));function _n(t,e,n,r){let o=u0(t,r),i=Math.abs(r)/o,s=c0(t,Math.max(.3,e),Math.max(.3,n),o),l=c=>[-c[0],c[1]];return{treads:s.treads.map((c,u)=>{let d=t.down?-i*(u+1):i*(u+1);return t.turn==="right"?{...c,top:d}:{poly:c.poly.map(l).reverse(),top:d,landing:c.landing,left:c.right.map(l),right:c.left.map(l)}}),rise:i,steps:o,column:s.column,flight:s.flight}}function Ti(t){let e=t.poly.reduce((n,r)=>[n[0]+r[0],n[1]+r[1]],[0,0]);return[e[0]/t.poly.length,e[1]/t.poly.length]}var te=t=>Math.round(t*1e3)/1e3,d0=(t,e)=>((t+e)%360+360)%360;function Lp(t,e){return{id:I("wall"),a:[te(t[0]),te(t[1])],b:[te(e[0]),te(e[1])],thickness:null}}function Cp(t,e){let n=Math.hypot(t.b[0]-t.a[0],t.b[1]-t.a[1])||1,r=Math.max(.1,e)/n;return[te(t.a[0]+(t.b[0]-t.a[0])*r),te(t.a[1]+(t.b[1]-t.a[1])*r)]}var Np=(t,e)=>({height:t>=e-.005?null:Math.max(.05,t)});function Bp(t,e){return{id:I("hole"),type:"stairwell",x:te((t[0]+e[0])/2),z:te((t[1]+e[1])/2),w:te(e[0]-t[0]),d:te(e[1]-t[1]),h:.02,rotation:0,variant:null}}var Wp=t=>({id:I("outdoor"),type:"lawn",points:t.map(([e,n])=>[te(e),te(n)])});function Vp(t,e,n){t.points.splice(e+1,0,[te(n[0]),te(n[1])])}function Kp(t,e){return t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),!0)}var jp=t=>({...t,id:I("outdoor"),points:t.points.map(([e,n])=>[te(e+.5),te(n+.5)])});function Ka(t,e,n,r){let[o,i,s]=ut(t),l=e.floors.filter(u=>u.elevation>n.elevation).sort((u,d)=>u.elevation-d.elevation)[0],a=t==="stairs"?te(l?l.elevation-n.elevation:n.height+.25):s,c={id:I("furniture"),type:t,x:te(r[0]),z:te(r[1]),rotation:0,w:o,d:i,h:a,variant:null};return t==="stairs"&&(c.stair={...gt}),c}var Gp=t=>({...structuredClone(t),id:I("furniture"),x:te(t.x+.3),z:te(t.z+.3)}),Up=(t,e)=>d0(t,e);function Zp(t){let[e,n,r]=ut("parking");return{id:I("furniture"),type:"parking",x:t.x,z:t.z,rotation:t.rotation,w:Math.max(e,te(t.w+.5)),d:Math.max(n,te(t.d+.4)),h:r,variant:null,vehicle:t.type,...t.name?{name:t.name}:{}}}function qp(t,e){let[n,r,o]=ut(e);return{id:I("furniture"),type:e,x:t.x,z:t.z,rotation:t.rotation??0,w:n,d:r,h:o,variant:null,entity:t.entity_id,name:t.name??null,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.locked?{locked:!0}:{}}}var Yp=(t,e)=>({entity_id:e,x:t.x,z:t.z,y:null,rotation:t.rotation,animations_enabled:t.animations_enabled,effect_animations:structuredClone(t.effect_animations),...t.name?{name:t.name}:{}});function Xp(t,e){for(let n of t.floors)n.placements=n.placements.filter(r=>r.entity_id!==e),n.furniture=n.furniture.filter(r=>!(ue(r.type)&&r.entity===e))}function ja(t,e,n,r){let o=new Set(r);for(let s of t.floors)s.placements=s.placements.filter(l=>!o.has(l.entity_id)),s.furniture=s.furniture.filter(l=>!(ue(l.type)&&l.entity&&o.has(l.entity)));let i=[...e.placements.map(s=>[s.x,s.z]),...e.furniture.filter(s=>ue(s.type)).map(s=>[s.x,s.z])];for(let s of Uu(n,r,i)){if(!s.entity_id.startsWith("light.")){e.placements.push(s);continue}let[l,a,c]=tt.lamp_ceiling;e.furniture.push({id:I("furniture"),type:"lamp_ceiling",x:s.x,z:s.z,rotation:0,w:l,d:a,h:c,variant:null,entity:s.entity_id,power:null})}}function Qp(t){let[e,n]=be(t.points);return[te(e),te(n)]}function Jp(t,e,n,r){let o=Math.min(n,t)/2,i=r>0?Math.round(e/r)*r:e;return te(Math.min(t-o,Math.max(o,i)))}function ef(t,e){let n=Rn[e],r=En(t)===e?{}:{width:n.width};return{type:n.type,leaves:n.leaves,sill:n.sill,height:n.height,style:n.style??null,opens:n.opens??null,...r}}function tf(t,e,n){let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:e==="w"?s=o+Math.max(.1,n):l=i+Math.max(.1,n),[[o,i],[s,i],[s,l],[o,l]].map(([a,c])=>[te(a),te(c)])}function nf(t){return t.furniture.map((e,n)=>({item:e,index:n,base:At(t,e)})).sort((e,n)=>e.base-n.base||e.index-n.index).map(e=>e.item)}function zi(t,e,n){if(!t.admin)return _;let r=n.edit?.key===e;return m`n.setEdit(r?null:{key:e,bulge:.5,error:null})}>
◠ ${t.t("arc")}
`}function Pi(t,e,n){let r=n.edit;if(!t.admin||r?.key!==e)return _;let o=t.t;return m`${A(t,o("arc_bulge"),r.bulge,i=>n.setEdit({...r,bulge:i,error:null}),.05)}
n.apply(r)}>${o("arc_apply")}
- ${r.error?m`${r.error}
`:_}`}var Ii=(t,e,n)=>Math.min(e,Math.max(t,se(n)));function Ga(t,e,n){let r=t.t,o=a=>n.update(a),i=de(e.points),s=Gc.map(a=>[a,r(`out_${a}`)]),l=Uc.map(a=>[a,r(`slope_${a.replace("-","n")}`)]);return m`
+ ${r.error?m`${r.error}
`:_}`}var Ii=(t,e,n)=>Math.min(e,Math.max(t,ae(n)));function Ga(t,e,n){let r=t.t,o=a=>n.update(a),i=de(e.points),s=Yc.map(a=>[a,r(`out_${a}`)]),l=Xc.map(a=>[a,r(`slope_${a.replace("-","n")}`)]);return m`
${r("outdoor")} ${n.lockButton}
${L(t,r("outdoor_type"),e.type,s,a=>o({type:a}),{wide:!0})}
@@ -936,33 +936,33 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${D(t,r("outdoor_outline"),e.outline!==!1,a=>o({outline:a?void 0:!1}),{title:r("outdoor_outline_hint")})}
${e.type==="fence"||e.type==="pergola"?D(t,r("outdoor_open"),!!e.open,a=>o({open:a||void 0}),{title:r("outdoor_open_hint")}):_}
${e.type==="pergola"?D(t,r("outdoor_bracing"),!!e.bracing,a=>o({bracing:a||void 0})):_}
- ${D(t,r("outdoor_cut"),Yc(e),a=>o({cut:a===(e.type==="pool")?void 0:a}),{title:r("outdoor_cut_hint")})}
+ ${D(t,r("outdoor_cut"),eu(e),a=>o({cut:a===(e.type==="pool")?void 0:a}),{title:r("outdoor_cut_hint")})}
- ${e.type==="fence"?a0(t,e,o):_}
+ ${e.type==="fence"?h0(t,e,o):_}
${t.admin?m`
${e.points.map((a,c)=>m`n.removeCorner(c)}>${c+1} × `)}
${M(r("outdoor_corners_hint"))}`:_}
${e.slope?M(r("outdoor_slope_hint")):_} ${M(r("outdoor_hint"))}
${t.admin?m`n.duplicate()}>${r("duplicate")} n.remove()}>${r("delete")}
`:_}
- `}function a0(t,e,n){let r=t.t,o=e.gates??[],i=h=>n({gates:h.length?h:void 0}),s=e.points.map((h,f)=>[String(f),`${f+1} \u2192 ${(f+1)%e.points.length+1}`]),l=h=>{let[f,g]=[e.points[h],e.points[(h+1)%e.points.length]];return f&&g?Math.hypot(g[0]-f[0],g[1]-f[1]):0},a=(h,f)=>i(o.map((g,y)=>y===h?{...g,...f}:g)),c=H(t.hass,h=>/^(cover|switch|input_boolean|lock)\./.test(h)),u=H(t.hass,h=>h.startsWith("binary_sensor.")),d=[["single",r("gate_single")],["double",r("gate_double")],["sliding",r("gate_sliding")]],p=()=>{let f=l(0);i([...o,{id:I("gate"),edge:0,offset:se(f/2),width:Math.min(1.2,Math.max(.5,se(f*.4))),kind:"single"}])};return m`${r("fence_gates")}
+ `}function h0(t,e,n){let r=t.t,o=e.gates??[],i=h=>n({gates:h.length?h:void 0}),s=e.points.map((h,f)=>[String(f),`${f+1} \u2192 ${(f+1)%e.points.length+1}`]),l=h=>{let[f,g]=[e.points[h],e.points[(h+1)%e.points.length]];return f&&g?Math.hypot(g[0]-f[0],g[1]-f[1]):0},a=(h,f)=>i(o.map((g,y)=>y===h?{...g,...f}:g)),c=H(t.hass,h=>/^(cover|switch|input_boolean|lock)\./.test(h)),u=H(t.hass,h=>h.startsWith("binary_sensor.")),d=[["single",r("gate_single")],["double",r("gate_double")],["sliding",r("gate_sliding")]],p=()=>{let f=l(0);i([...o,{id:I("gate"),edge:0,offset:ae(f/2),width:Math.min(1.2,Math.max(.5,ae(f*.4))),kind:"single"}])};return m`${r("fence_gates")}
${o.map((h,f)=>m`
${L(t,r("gate_edge"),String(h.edge),s,g=>a(f,{edge:Number(g)}))}
${L(t,r("gate_kind"),h.kind,d,g=>a(f,{kind:g,width:g==="single"&&h.width>1.6?1:h.width}))}
- ${A(t,r("gate_offset"),h.offset,g=>a(f,{offset:Math.max(0,Math.min(l(h.edge),se(g)))}),.05,0)}
- ${A(t,r("gate_width"),h.width,g=>a(f,{width:Math.max(.3,Math.min(12,se(g)))}),.05,.3)}
+ ${A(t,r("gate_offset"),h.offset,g=>a(f,{offset:Math.max(0,Math.min(l(h.edge),ae(g)))}),.05,0)}
+ ${A(t,r("gate_width"),h.width,g=>a(f,{width:Math.max(.3,Math.min(12,ae(g)))}),.05,.3)}
${z(t,r("gate_entity"),h.entity??null,void 0,c,g=>a(f,{entity:g&&g!=="none"?g:null}))}
${z(t,r("gate_contact"),h.contact??null,void 0,u,g=>a(f,{contact:g&&g!=="none"?g:null}))}
${t.admin?m`i(o.filter((g,y)=>y!==f))}>${r("delete")} `:_}
`)}
${t.admin&&o.length<20?m`${r("gate_add")} `:_}
- ${M(r("fence_gates_hint"))}`}var l0=[["up","\u2191"],["left","\u2190"],["right","\u2192"],["down","\u2193"]],c0={ArrowRight:"right",ArrowLeft:"left",ArrowUp:"up",ArrowDown:"down"};function Jp(t,e,n){let r=t.t,{draft:o}=e,i=d=>K(t.hass,d,2),[s,l]=[o[0],o[o.length-1]],a=s&&o.length>1?Math.hypot(l[0]-s[0],l[1]-s[1]):0,c=d=>{let p=c0[d.key];p?(d.preventDefault(),n.step(p)):d.key==="Enter"&&n.close()},u=s?m`${M(r("measure_from",{x:i(s[0]),z:i(s[1])}))}
+ ${M(r("fence_gates_hint"))}`}var p0=[["up","\u2191"],["left","\u2190"],["right","\u2192"],["down","\u2193"]],f0={ArrowRight:"right",ArrowLeft:"left",ArrowUp:"up",ArrowDown:"down"};function rf(t,e,n){let r=t.t,{draft:o}=e,i=d=>K(t.hass,d,2),[s,l]=[o[0],o[o.length-1]],a=s&&o.length>1?Math.hypot(l[0]-s[0],l[1]-s[1]):0,c=d=>{let p=f0[d.key];p?(d.preventDefault(),n.step(p)):d.key==="Enter"&&n.close()},u=s?m`${M(r("measure_from",{x:i(s[0]),z:i(s[1])}))}
${o.length>1?m`${o.slice(1).map((d,p)=>m`${i(Math.hypot(d[0]-o[p][0],d[1]-o[p][1]))} m `)} `:_}
@@ -982,16 +982,16 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
`}function Ua(t,e,n){let r=t.t,o=t.floor?.height??2.5,i=Math.hypot(e.b[0]-e.a[0],e.b[1]-e.a[1]);return m`
${r("free_wall")} ${n.lockButton}
- ${A(t,r("wall_length"),i,s=>n.update({b:Dp(e,s)}),.01,.1)}
+ ${A(t,r("wall_length"),i,s=>n.update({b:Cp(e,s)}),.01,.1)}
${A(t,r("wall_thickness"),e.thickness??t.doc.settings.wall_interior,s=>n.update({thickness:Ii(.02,1,s)}),.01,.02)}
- ${A(t,r("wall_height"),e.height??o,s=>n.update(Op(s,o)),.05,.05)}
+ ${A(t,r("wall_height"),e.height??o,s=>n.update(Np(s,o)),.05,.05)}
${D(t,r("free_wall_slope"),e.height_end!=null,s=>n.update(s?{height:e.height??o,height_end:Math.max(.2,(e.height??o)/2)}:{height_end:null}),{title:r("free_wall_slope_hint")})}
${e.height_end!=null?A(t,r("free_wall_height_end"),e.height_end,s=>n.update({height_end:Math.max(.05,s)}),.05,.05):_}
${t.admin?m`${zi(t,`wall:${e.id}`,n.arc)}n.remove()}>${r("delete")}
`:_}
${Pi(t,`wall:${e.id}`,n.arc)}
${M(r("free_wall_hint"))}
- `}var Vt=t=>Math.round(t*1e3)/1e3,u0=2.4;function ef(t,e,n){let r=sa(t,e[0],e[1],n[0],n[1]),o=r===null,i=Math.min(...t.floors.map(a=>a.elevation)),s=Vt(r??i+u0),l=o?6:t.settings.roof.pitch||35;return{id:I("roof"),x0:Vt(e[0]),z0:Vt(e[1]),x1:Vt(n[0]),z1:Vt(n[1]),shape:o?"pent":"gable",axis:n[0]-e[0]>=n[1]-e[1]?"x":"z",eave_a:s,eave_b:s,pitch_a:l,pitch_b:l,base:s,overhang:o?.15:null,...o?{open:!0}:{}}}function tf(t){let e=n=>Vt(n+1);return{...structuredClone(t),id:I("roof"),x0:e(t.x0),x1:e(t.x1),z0:e(t.z0),z1:e(t.z1)}}var nf=(t,e)=>t.findIndex(n=>n.id===e)+1;function Za(t){return t.points&&t.points.length>=3?t.points.map(([e,n])=>[e,n]):t.rotation?Tr(t):[[t.x0,t.z0],[t.x1,t.z0],[t.x1,t.z1],[t.x0,t.z1]]}function rf(t,e,n){let r=Za(t);r.splice(e+1,0,[Vt(n[0]),Vt(n[1])]),t.points=r,Object.assign(t,Nt(r))}function of(t,e){return!t.points||t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),Object.assign(t,Nt(t.points)),!0)}var d0={light:"M8.5 17.5h7M9.5 20.5h5M12 2.5a6.5 6.5 0 0 0-3.5 12v1.5h7V14.5A6.5 6.5 0 0 0 12 2.5z",switch:"M6 5h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM12 7.5v9M9 12h6",fan:"M12 11.5c-1-3.5 0-7 2.5-7s2 4-2.5 7zm.5.5c3.5-1 7 0 7 2.5s-4 2-7-2.5zm-.5.5c1 3.5 0 7-2.5 7s-2-4 2.5-7zm-.5-.5c-3.5 1-7 0-7-2.5s4-2 7 2.5z",cover:"M3.5 3.5h17v3h-17zM6 6.5v12M18 6.5v12M8.5 9.5h7M8.5 12.5h7M8.5 15.5h7",climate:"M12 15V5.5a2.5 2.5 0 0 0-5 0V15a4.5 4.5 0 1 0 5 0zM9.5 9v7M15 5.5h5M15 9.5h4",media:"M3.5 5.5h17v11h-17zM8 20.5h8M12 16.5v4M10 8.5v5l4.5-2.5z",lock:"M5.5 10.5h13v9.5h-13zM8 10.5V7.5a4 4 0 0 1 8 0v3M12 14v3",sensor:"M12 3.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17zM12 7.5v4.5l3.5 2",binary:"M5.5 20.5v-17h10v17M3.5 20.5h14M9 20.5v-13h4.5v13M12.5 14h.01",scene:"M5.5 18.5l8-8M14 3.5l1 2.5 2.5 1-2.5 1-1 2.5-1-2.5-2.5-1 2.5-1zM18.5 12l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7z",script:"M8.5 3.5h8.5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H7.5a2 2 0 0 1-2-2v-2h9M8.5 3.5a2 2 0 0 0-2 2v10M9.5 8.5h6M9.5 11.5h4"},Kt=t=>d0[t];function Di(t,e){let n=new Set;for(let r of t?.placements??[])N([r.x,r.z],e.points)&&n.add(r.entity_id);for(let r of t?.furniture??[])ce(r.type)&&r.entity&&N([r.x,r.z],e.points)&&n.add(r.entity);return n}function sf(t,e){let n=new Map;for(let r of t.floors){let o=[...r.placements.map(i=>[i.entity_id,i.x,i.z]),...r.furniture.filter(i=>ce(i.type)&&i.entity).map(i=>[i.entity,i.x,i.z])];for(let[i,s,l]of o){let a=r.rooms.find(c=>N([s,l],c.points));a&&a.id!==e.id&&n.set(i,a.name)}}return n}var af=(t,e)=>(t??[]).includes(e)?(t??[]).filter(n=>n!==e):[...t??[],e];function Oi(t,...e){let n=t.trim().toLowerCase();return!n||e.some(r=>(r??"").toLowerCase().includes(n))}function lf(t,e){return t.map(n=>({o:n,r:e(n.id)})).sort((n,r)=>n.r-r.r).map(({o:n})=>n)}function cf(t,e){let n=e,r=0;return{taken:t.map(i=>{let s=i.ids.slice(0,Math.max(0,n));return n-=s.length,r+=i.ids.length-s.length,[...s]}),left:r}}var qa=50;function Ya(t,e,n,r,o,i,s){let l=e.includes(n);return m`
s.patchRoom({[r]:af(e,n)})}>${l?o[0]:o[1]} `}function h0(t,e,n,r,o,i){let[s,l,a]=[e.hidden??[],e.no_state??[],e.panel??[]];return(c,u=!1,d=o)=>{let p=n.has(c),h=p?void 0:r.get(c),f=s.includes(c),g=On(t,c);return m`
+ `}var Vt=t=>Math.round(t*1e3)/1e3,m0=2.4;function of(t,e,n){let r=sa(t,e[0],e[1],n[0],n[1]),o=r===null,i=Math.min(...t.floors.map(a=>a.elevation)),s=Vt(r??i+m0),l=o?6:t.settings.roof.pitch||35;return{id:I("roof"),x0:Vt(e[0]),z0:Vt(e[1]),x1:Vt(n[0]),z1:Vt(n[1]),shape:o?"pent":"gable",axis:n[0]-e[0]>=n[1]-e[1]?"x":"z",eave_a:s,eave_b:s,pitch_a:l,pitch_b:l,base:s,overhang:o?.15:null,...o?{open:!0}:{}}}function sf(t){let e=n=>Vt(n+1);return{...structuredClone(t),id:I("roof"),x0:e(t.x0),x1:e(t.x1),z0:e(t.z0),z1:e(t.z1)}}var af=(t,e)=>t.findIndex(n=>n.id===e)+1;function Za(t){return t.points&&t.points.length>=3?t.points.map(([e,n])=>[e,n]):t.rotation?zr(t):[[t.x0,t.z0],[t.x1,t.z0],[t.x1,t.z1],[t.x0,t.z1]]}function lf(t,e,n){let r=Za(t);r.splice(e+1,0,[Vt(n[0]),Vt(n[1])]),t.points=r,Object.assign(t,Nt(r))}function cf(t,e){return!t.points||t.points.length<=3||e<0||e>=t.points.length?!1:(t.points.splice(e,1),Object.assign(t,Nt(t.points)),!0)}var g0={light:"M8.5 17.5h7M9.5 20.5h5M12 2.5a6.5 6.5 0 0 0-3.5 12v1.5h7V14.5A6.5 6.5 0 0 0 12 2.5z",switch:"M6 5h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2zM12 7.5v9M9 12h6",fan:"M12 11.5c-1-3.5 0-7 2.5-7s2 4-2.5 7zm.5.5c3.5-1 7 0 7 2.5s-4 2-7-2.5zm-.5.5c1 3.5 0 7-2.5 7s-2-4 2.5-7zm-.5-.5c-3.5 1-7 0-7-2.5s4-2 7 2.5z",cover:"M3.5 3.5h17v3h-17zM6 6.5v12M18 6.5v12M8.5 9.5h7M8.5 12.5h7M8.5 15.5h7",climate:"M12 15V5.5a2.5 2.5 0 0 0-5 0V15a4.5 4.5 0 1 0 5 0zM9.5 9v7M15 5.5h5M15 9.5h4",media:"M3.5 5.5h17v11h-17zM8 20.5h8M12 16.5v4M10 8.5v5l4.5-2.5z",lock:"M5.5 10.5h13v9.5h-13zM8 10.5V7.5a4 4 0 0 1 8 0v3M12 14v3",sensor:"M12 3.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17zM12 7.5v4.5l3.5 2",binary:"M5.5 20.5v-17h10v17M3.5 20.5h14M9 20.5v-13h4.5v13M12.5 14h.01",scene:"M5.5 18.5l8-8M14 3.5l1 2.5 2.5 1-2.5 1-1 2.5-1-2.5-2.5-1 2.5-1zM18.5 12l.7 1.8 1.8.7-1.8.7-.7 1.8-.7-1.8-1.8-.7 1.8-.7z",script:"M8.5 3.5h8.5a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H7.5a2 2 0 0 1-2-2v-2h9M8.5 3.5a2 2 0 0 0-2 2v10M9.5 8.5h6M9.5 11.5h4"},Kt=t=>g0[t];function Di(t,e){let n=new Set;for(let r of t?.placements??[])N([r.x,r.z],e.points)&&n.add(r.entity_id);for(let r of t?.furniture??[])ue(r.type)&&r.entity&&N([r.x,r.z],e.points)&&n.add(r.entity);return n}function uf(t,e){let n=new Map;for(let r of t.floors){let o=[...r.placements.map(i=>[i.entity_id,i.x,i.z]),...r.furniture.filter(i=>ue(i.type)&&i.entity).map(i=>[i.entity,i.x,i.z])];for(let[i,s,l]of o){let a=r.rooms.find(c=>N([s,l],c.points));a&&a.id!==e.id&&n.set(i,a.name)}}return n}var df=(t,e)=>(t??[]).includes(e)?(t??[]).filter(n=>n!==e):[...t??[],e];function Oi(t,...e){let n=t.trim().toLowerCase();return!n||e.some(r=>(r??"").toLowerCase().includes(n))}function hf(t,e){return t.map(n=>({o:n,r:e(n.id)})).sort((n,r)=>n.r-r.r).map(({o:n})=>n)}function pf(t,e){let n=e,r=0;return{taken:t.map(i=>{let s=i.ids.slice(0,Math.max(0,n));return n-=s.length,r+=i.ids.length-s.length,[...s]}),left:r}}var qa=50;function Ya(t,e,n,r,o,i,s){let l=e.includes(n);return m`
s.patchRoom({[r]:df(e,n)})}>${l?o[0]:o[1]} `}function _0(t,e,n,r,o,i){let[s,l,a]=[e.hidden??[],e.no_state??[],e.panel??[]];return(c,u=!1,d=o)=>{let p=n.has(c),h=p?void 0:r.get(c),f=s.includes(c),g=On(t,c);return m`
i.select(c)}>
${g?m` `:m` `}
${W(t.hass,c,d)}${h?m` · ${t.t("devices_placed_in",{room:h})} `:_}
@@ -1000,24 +1000,24 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${t.admin&&!f?Ya(t,l,c,"no_state",["\u2205","Aa"],["panel_state_show","panel_state_hide"],i):_}
${t.admin&&!p?Ya(t,a,c,"panel",["\u2605","\u2606"],["panel_unpin","panel_pin"],i):_}
${t.admin?p?m`i.remove(c)}>${t.t("devices_remove")} `:m`i.place([c])}>${t.t("devices_place")} `:_}
- `}}function p0(t,e,n,r,o){let{hass:i}=t;if(!i)return m``;let s=u=>u>0?M(t.t("devices_narrow",{n:u})):_,l=M(t.t("devices_none")),a=e.deviceQuery;if(o==="other"){let u=vu(i,n.area_id).map(f=>({...f,ids:f.ids.filter(g=>Oi(a,`${W(i,g,f.name)} ${g} ${f.name}`))})),{taken:d,left:p}=cf(u,qa),h=u.map((f,g)=>d[g].length>0?m`
${f.name}
${d[g].map(y=>r(y,!1,f.name))}`:_);return d.some(f=>f.length>0)?m`
${h}
${s(p)}`:l}let c=wu(i).filter(u=>Oi(a,`${W(i,u)} ${u} `));return c.length>0?m`
${c.slice(0,qa).map(u=>r(u))}
${s(c.length-Math.min(c.length,qa))}`:l}function f0(t,e,n,r,o,i,s){let{hass:l}=t,a=l?ye(l,n).filter(b=>Rt(Be(l,b))):[];if(!n.area_id)return M(t.t("devices_none_area"));if(a.length===0)return M(t.t("devices_none"));let c=l?Tn(l,a):[],u=c.map(b=>b.primary).filter(b=>!o.has(b)),d=e.deviceQuery,p=(t.floor?.placements??[]).filter(b=>Q(b.entity_id)==="light"&&(b.mount??"ceiling")==="ceiling"&&N([b.x,b.z],n.points)).length,h=m`
e.deviceQuery=b.target.value} />`,f=b=>Oi(d,W(l,b,i),b),g=b=>{let v=b.others.filter(f),w=e.isUnfolded(b.primary)||!!d.trim()&&v.length>0;return!f(b.primary)&&v.length===0?_:m`${r(b.primary)}
+
`}}function b0(t,e,n,r,o){let{hass:i}=t;if(!i)return m``;let s=u=>u>0?M(t.t("devices_narrow",{n:u})):_,l=M(t.t("devices_none")),a=e.deviceQuery;if(o==="other"){let u=$u(i,n.area_id).map(f=>({...f,ids:f.ids.filter(g=>Oi(a,`${W(i,g,f.name)} ${g} ${f.name}`))})),{taken:d,left:p}=pf(u,qa),h=u.map((f,g)=>d[g].length>0?m`
${f.name}
${d[g].map(y=>r(y,!1,f.name))}`:_);return d.some(f=>f.length>0)?m`
${h}
${s(p)}`:l}let c=Su(i).filter(u=>Oi(a,`${W(i,u)} ${u} `));return c.length>0?m`
${c.slice(0,qa).map(u=>r(u))}
${s(c.length-Math.min(c.length,qa))}`:l}function y0(t,e,n,r,o,i,s){let{hass:l}=t,a=l?ye(l,n).filter(b=>Rt(Be(l,b))):[];if(!n.area_id)return M(t.t("devices_none_area"));if(a.length===0)return M(t.t("devices_none"));let c=l?Tn(l,a):[],u=c.map(b=>b.primary).filter(b=>!o.has(b)),d=e.deviceQuery,p=(t.floor?.placements??[]).filter(b=>Q(b.entity_id)==="light"&&(b.mount??"ceiling")==="ceiling"&&N([b.x,b.z],n.points)).length,h=m`
e.deviceQuery=b.target.value} />`,f=b=>Oi(d,W(l,b,i),b),g=b=>{let v=b.others.filter(f),w=e.isUnfolded(b.primary)||!!d.trim()&&v.length>0;return!f(b.primary)&&v.length===0?_:m`${r(b.primary)}
${b.others.length>0?m`
e.toggleUnfolded(b.primary)}>${w?t.t("devices_less"):t.t("devices_more",{n:b.others.length})} `:_}
${w?(d.trim()?v:b.others).map(x=>r(x,!0)):_}`},y=()=>s.confirm(t.t("devices_place_all_confirm",{n:u.length}))&&s.place(u);return m`${t.admin&&p>=2?m`
s.spreadLights(n)}>${t.t("lights_spread")} `:_}
${a.length>8?h:_}
${c.map(g)}
${t.admin&&u.length>1?m`
${t.t("devices_place_all_n",{n:u.length})} `:_}
- ${M(t.t("devices_hint"))}`}function Xa(t,e,n,r){let{hass:o}=t,i=n.area_id?o?.areas?.[n.area_id]?.name:void 0,s=Di(t.floor,n),l=h0(t,n,s,sf(t.doc,n),i,r),a=t.admin?e.deviceSource:"area",c=o?Tn(o,ye(o,n).filter(p=>Rt(Be(o,p)))).length:0,u=[["area",`${t.t("devices_src_area")}${c>0?` (${c})`:""}`],["other",t.t("devices_src_other")],["none",t.t("devices_src_none")]],d=m`
e.deviceQuery=p.target.value} />`;return m`
+ ${M(t.t("devices_hint"))}`}function Xa(t,e,n,r){let{hass:o}=t,i=n.area_id?o?.areas?.[n.area_id]?.name:void 0,s=Di(t.floor,n),l=_0(t,n,s,uf(t.doc,n),i,r),a=t.admin?e.deviceSource:"area",c=o?Tn(o,ye(o,n).filter(p=>Rt(Be(o,p)))).length:0,u=[["area",`${t.t("devices_src_area")}${c>0?` (${c})`:""}`],["other",t.t("devices_src_other")],["none",t.t("devices_src_none")]],d=m` e.deviceQuery=p.target.value} />`;return m`
${t.t("devices")}
${M(t.t("devices_panel_hint"))}
${t.admin?m`${u.map(([p,h])=>m`e.deviceSource=p}>${h} `)}
`:_}
- ${a!=="area"?m`${d}${p0(t,e,n,l,a)}`:f0(t,e,n,l,s,i,r)}
- `}function uf(t,e,n){let{hass:r}=t;if(!r)return _;let o=!!e.floor_heating||!!e.hvac||!!e.climate&&Object.values(e.climate).some(l=>l!=null),i=(l,a)=>{let c={...e.climate??{},[l]:a};n({climate:Object.values(c).every(u=>u==null)?null:c})},s=(l,a)=>{let c=ku(r,t.floor??null,{...e,climate:null},l),u=[e.climate?.[l]??null].flat(),d=H(r,y=>Hs(r,y,l,!0)&&(!r.states[y]?.attributes.symcon_source_entity||u.includes(y))),p=lf(d,y=>(Tt(r,y)===e.area_id?0:1)+(Ls(r,y)?0:2)),h=y=>{let b=y.filter(v=>!!v&&v!=="none");i(l,b.length>1?b:b[0]??(y.includes("none")?"none":null))},g=u[0]&&u[0]!=="none"?[...u,null]:u;return g.map((y,b)=>z(t,b?t.t("climate_more"):a,y,b?void 0:c[0]??null,p,v=>h(g.map((w,x)=>x===b?v:w))))};return m`
+ ${a!=="area"?m`${d}${b0(t,e,n,l,a)}`:y0(t,e,n,l,s,i,r)}
+ `}function ff(t,e,n){let{hass:r}=t;if(!r)return _;let o=!!e.floor_heating||!!e.hvac||!!e.climate&&Object.values(e.climate).some(l=>l!=null),i=(l,a)=>{let c={...e.climate??{},[l]:a};n({climate:Object.values(c).every(u=>u==null)?null:c})},s=(l,a)=>{let c=Mu(r,t.floor??null,{...e,climate:null},l),u=[e.climate?.[l]??null].flat(),d=H(r,y=>Hs(r,y,l,!0)&&(!r.states[y]?.attributes.symcon_source_entity||u.includes(y))),p=hf(d,y=>(Tt(r,y)===e.area_id?0:1)+(Ls(r,y)?0:2)),h=y=>{let b=y.filter(v=>!!v&&v!=="none");i(l,b.length>1?b:b[0]??(y.includes("none")?"none":null))},g=u[0]&&u[0]!=="none"?[...u,null]:u;return g.map((y,b)=>z(t,b?t.t("climate_more"):a,y,b?void 0:c[0]??null,p,v=>h(g.map((w,x)=>x===b?v:w))))};return m`
${t.t("climate")}
- ${s("temperature",t.t("climate_temperature"))} ${s("humidity",t.t("climate_humidity"))} ${s("co2",t.t("climate_co2"))} ${s("illuminance",t.t("climate_illuminance"))}${ue(r)?Vd(t,e,n):_}
+ ${s("temperature",t.t("climate_temperature"))} ${s("humidity",t.t("climate_humidity"))} ${s("co2",t.t("climate_co2"))} ${s("illuminance",t.t("climate_illuminance"))}${oe(r)?Ud(t,e,n):_}
${D(t,t.t("climate_card"),!!e.climate_card,l=>n({climate_card:l||void 0}))}
${M(t.t("climate_card_hint"))}
${M(t.t("climate_hint"))}
- `}var Qa="metric",hf=t=>{Qa=t==="imperial"?"imperial":"metric"};var df=.3048;function pe(t,e,n=2,r=Qa){if(r==="metric")return`${K(t,e,n)} m`;let o=e<0?"\u2212":"",i=Math.round(Math.abs(e)/.0254*2),s=Math.floor(i/24),l=i-s*24,a=`${Math.floor(l/2)}${l%2?"\xBD":""}`;return s?`${o}${s}\u2032 ${a}\u2033`:`${o}${a}\u2033`}function Fe(t,e,n=Qa){return n==="metric"?`${K(t,e,1)} m\xB2`:`${K(t,e/(df*df),0)} ft\xB2`}var m0=.15,g0=(t,e)=>Math.abs((t-e+540)%360-180);function _0(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(J(G(i,n),r))<.02&&Math.abs(J(G(l,n),r))<.02}))}function el(t,e,n,r){let o=e.points,[i,s]=[o[n],o[(n+1)%o.length]],l=me(G(s,i)),a=_e(o)>=0?1:-1,c=[(s[0]-i[0])/l,(s[1]-i[1])/l],u=[-c[1]*a||0,c[0]*a||0],d=c[0]*u[1]-c[1]*u[0]>0,p=e.wall_heights?.[n],h=e.ceiling??t.height,f=typeof p=="number"?p:Array.isArray(p)?Math.max(...p.map(b=>b??h)):h,g=e.wall_slopes?.[n],y=typeof g=="number"&&typeof p=="number"?g:f;return{origin:d?i:s,along:d?c:[-c[0],-c[1]],normal:u,length:l,face:_0(t,e,i,u)?r/2:0,heightLeft:d?f:y,heightRight:d?y:f}}function Ja(t,e){let n=G(e,t.origin);return{u:J(n,t.along),depth:J(n,t.normal)-t.face}}function b0(t,e){let n=t.rooms.find(s=>s.id===e.room_id);if(!n||e.wall)return null;let[r,o]=[n.points[e.edge],n.points[(e.edge+1)%n.points.length]];if(!r||!o)return null;let i=me(G(o,r))||1;return[r[0]+(o[0]-r[0])*e.offset/i,r[1]+(o[1]-r[1])*e.offset/i]}var pf=t=>U(t.type)?.mount==="wall"||t.type==="lamp_wall"||t.mount_y!=null;function ff(t,e,n){let r=[];for(let i of t.openings){let s=b0(t,i);if(!s)continue;let{u:l,depth:a}=Ja(n,s);Math.abs(a+n.face)>.3||l<-.01||l>n.length+.01||r.push({id:i.id,kind:"opening",type:i.type,x0:l-i.width/2,x1:l+i.width/2,y0:i.sill,y1:i.sill+i.height,lifts:i.type==="window"})}let o=Math.atan2(-n.normal[0],n.normal[1])*180/Math.PI;for(let i of t.furniture){if(!N([i.x,i.z],e.points)||g0(i.rotation,o)>20)continue;let{u:s,depth:l}=Ja(n,[i.x,i.z]);if(l-i.d/2>m0||s<0||s>n.length)continue;let a=At(t,i);r.push({id:i.id,kind:"furniture",type:i.type,x0:s-i.w/2,x1:s+i.w/2,y0:a,y1:a+i.h,lifts:pf(i)})}return r.sort((i,s)=>+(i.kind==="furniture")-+(s.kind==="furniture")||i.x0-s.x0)}var fo=t=>Math.round(t*1e3)/1e3;function mf(t,e,n,r){let o=Ja(t,[e.x,e.z]).depth,i=Math.min(t.length-e.w/2,Math.max(e.w/2,n+e.w/2)),s=[t.origin[0]+t.along[0]*i+t.normal[0]*(o+t.face),t.origin[1]+t.along[1]*i+t.normal[1]*(o+t.face)];return{x:fo(s[0]),z:fo(s[1]),...r!==null&&pf(e)?{mount_y:fo(Math.max(0,r))}:{}}}function gf(t,e,n,r,o){let[i]=[e.points[n.edge]],s=Math.min(t.length-n.width/2,Math.max(n.width/2,r+n.width/2)),l=me(G(i,t.origin))<1e-6?s:t.length-s;return{offset:fo(l),...o!==null&&n.type==="window"?{sill:fo(Math.max(0,o))}:{}}}var _f=.01,bf=t=>Math.round(t/_f)*_f,tl=class extends X{static properties={host:{attribute:!1},doc:{attribute:!1},roomId:{},edge:{type:Number},_sel:{state:!0},_drag:{state:!0}};constructor(){super(),this._sel=null,this._drag=null}get room(){return this.host.floor?.rooms.find(e=>e.id===this.roomId)}frame(){let e=this.room;return e&&this.host.floor?el(this.host.floor,e,this.edge,this.host.doc.settings.wall_interior):null}boxes(){let e=this.room,n=this.frame();return e&&n&&this.host.floor?ff(this.host.floor,e,n):[]}place(e,n,r){let o=this.room,i=this.frame();!o||!i||this.host.change((s,l)=>{if(e.kind==="furniture"){let a=l.furniture.find(c=>c.id===e.id);a&&Object.assign(a,mf(i,a,n,e.lifts?r:null))}else{let a=l.openings.find(u=>u.id===e.id),c=l.rooms.find(u=>u.id===a?.room_id);a&&c&&Object.assign(a,gf(c.id===o.id?i:el(l,c,a.edge,this.host.doc.settings.wall_interior),c,a,n,e.lifts?r:null))}})}toWall(e){let r=this.renderRoot.querySelector("svg").getScreenCTM()?.inverse();if(!r)return[0,0];let o=new DOMPoint(e.clientX,e.clientY).matrixTransform(r);return[o.x,-o.y]}down(e,n){if(this._sel=n.id,!this.host.admin)return;e.currentTarget.setPointerCapture(e.pointerId);let[r,o]=this.toWall(e);this._drag={id:n.id,x0:n.x0,y0:n.y0,startU:r,startY:o,fromX:n.x0,fromY:n.y0}}move(e,n){let r=this._drag;if(!r||r.id!==n.id)return;let[o,i]=this.toWall(e),s=this.frame(),l=n.x1-n.x0,a=Math.min((s?.length??0)-l,Math.max(0,bf(r.fromX+o-r.startU))),c=n.lifts?Math.max(0,bf(r.fromY+i-r.startY)):r.fromY;this._drag={...r,x0:a,y0:c}}up(e){let n=this._drag;this._drag=null,!(!n||n.id!==e.id||Math.abs(n.x0-n.fromX)<1e-6&&Math.abs(n.y0-n.fromY)<1e-6)&&this.place(e,n.x0,n.y0)}nameOf(e){if(e.kind==="furniture")return this.host.floor?.furniture.find(o=>o.id===e.id)?.name||Ye(this.host.hass,e.type);let n=this.host.floor?.openings.find(r=>r.id===e.id);return n?this.host.t(`preset_${En(n)}`):e.type}updated(e){(e.has("edge")||e.has("roomId"))&&(this._sel=null)}render(){let e=this.host.t,n=this.room,r=this.frame();if(!n||!r)return _;let o=n.points.length,i=h=>pe(this.host.hass,h),s=this.boxes().map(h=>this._drag?.id===h.id?{...h,x1:this._drag.x0+(h.x1-h.x0),y1:this._drag.y0+(h.y1-h.y0),x0:this._drag.x0,y0:this._drag.y0}:h),l=Math.max(r.heightLeft,r.heightRight,...s.map(h=>h.y1)),a=.35,c=`${-a} ${-(l+a)} ${r.length+2*a} ${l+2*a+.25}`,u=s.find(h=>h.id===this._sel)??null,d=h=>{let f=Math.min(.14,Math.max(.07,(h.x1-h.x0)/7));return R`
${this.nameOf(h)} `},p=u?R`
+ `}var Qa="metric",gf=t=>{Qa=t==="imperial"?"imperial":"metric"};var mf=.3048;function pe(t,e,n=2,r=Qa){if(r==="metric")return`${K(t,e,n)} m`;let o=e<0?"\u2212":"",i=Math.round(Math.abs(e)/.0254*2),s=Math.floor(i/24),l=i-s*24,a=`${Math.floor(l/2)}${l%2?"\xBD":""}`;return s?`${o}${s}\u2032 ${a}\u2033`:`${o}${a}\u2033`}function Fe(t,e,n=Qa){return n==="metric"?`${K(t,e,1)} m\xB2`:`${K(t,e/(mf*mf),0)} ft\xB2`}var v0=.15,w0=(t,e)=>Math.abs((t-e+540)%360-180);function k0(t,e,n,r){return t.rooms.some(o=>o.id!==e.id&&o.points.some((i,s)=>{let l=o.points[(s+1)%o.points.length];return Math.abs(ee(G(i,n),r))<.02&&Math.abs(ee(G(l,n),r))<.02}))}function el(t,e,n,r){let o=e.points,[i,s]=[o[n],o[(n+1)%o.length]],l=me(G(s,i)),a=_e(o)>=0?1:-1,c=[(s[0]-i[0])/l,(s[1]-i[1])/l],u=[-c[1]*a||0,c[0]*a||0],d=c[0]*u[1]-c[1]*u[0]>0,p=e.wall_heights?.[n],h=e.ceiling??t.height,f=typeof p=="number"?p:Array.isArray(p)?Math.max(...p.map(b=>b??h)):h,g=e.wall_slopes?.[n],y=typeof g=="number"&&typeof p=="number"?g:f;return{origin:d?i:s,along:d?c:[-c[0],-c[1]],normal:u,length:l,face:k0(t,e,i,u)?r/2:0,heightLeft:d?f:y,heightRight:d?y:f}}function Ja(t,e){let n=G(e,t.origin);return{u:ee(n,t.along),depth:ee(n,t.normal)-t.face}}function x0(t,e){let n=t.rooms.find(s=>s.id===e.room_id);if(!n||e.wall)return null;let[r,o]=[n.points[e.edge],n.points[(e.edge+1)%n.points.length]];if(!r||!o)return null;let i=me(G(o,r))||1;return[r[0]+(o[0]-r[0])*e.offset/i,r[1]+(o[1]-r[1])*e.offset/i]}var _f=t=>U(t.type)?.mount==="wall"||t.type==="lamp_wall"||t.mount_y!=null;function bf(t,e,n){let r=[];for(let i of t.openings){let s=x0(t,i);if(!s)continue;let{u:l,depth:a}=Ja(n,s);Math.abs(a+n.face)>.3||l<-.01||l>n.length+.01||r.push({id:i.id,kind:"opening",type:i.type,x0:l-i.width/2,x1:l+i.width/2,y0:i.sill,y1:i.sill+i.height,lifts:i.type==="window"})}let o=Math.atan2(-n.normal[0],n.normal[1])*180/Math.PI;for(let i of t.furniture){if(!N([i.x,i.z],e.points)||w0(i.rotation,o)>20)continue;let{u:s,depth:l}=Ja(n,[i.x,i.z]);if(l-i.d/2>v0||s<0||s>n.length)continue;let a=At(t,i);r.push({id:i.id,kind:"furniture",type:i.type,x0:s-i.w/2,x1:s+i.w/2,y0:a,y1:a+i.h,lifts:_f(i)})}return r.sort((i,s)=>+(i.kind==="furniture")-+(s.kind==="furniture")||i.x0-s.x0)}var mo=t=>Math.round(t*1e3)/1e3;function yf(t,e,n,r){let o=Ja(t,[e.x,e.z]).depth,i=Math.min(t.length-e.w/2,Math.max(e.w/2,n+e.w/2)),s=[t.origin[0]+t.along[0]*i+t.normal[0]*(o+t.face),t.origin[1]+t.along[1]*i+t.normal[1]*(o+t.face)];return{x:mo(s[0]),z:mo(s[1]),...r!==null&&_f(e)?{mount_y:mo(Math.max(0,r))}:{}}}function vf(t,e,n,r,o){let[i]=[e.points[n.edge]],s=Math.min(t.length-n.width/2,Math.max(n.width/2,r+n.width/2)),l=me(G(i,t.origin))<1e-6?s:t.length-s;return{offset:mo(l),...o!==null&&n.type==="window"?{sill:mo(Math.max(0,o))}:{}}}var wf=.01,kf=t=>Math.round(t/wf)*wf,tl=class extends Y{static properties={host:{attribute:!1},doc:{attribute:!1},roomId:{},edge:{type:Number},_sel:{state:!0},_drag:{state:!0}};constructor(){super(),this._sel=null,this._drag=null}get room(){return this.host.floor?.rooms.find(e=>e.id===this.roomId)}frame(){let e=this.room;return e&&this.host.floor?el(this.host.floor,e,this.edge,this.host.doc.settings.wall_interior):null}boxes(){let e=this.room,n=this.frame();return e&&n&&this.host.floor?bf(this.host.floor,e,n):[]}place(e,n,r){let o=this.room,i=this.frame();!o||!i||this.host.change((s,l)=>{if(e.kind==="furniture"){let a=l.furniture.find(c=>c.id===e.id);a&&Object.assign(a,yf(i,a,n,e.lifts?r:null))}else{let a=l.openings.find(u=>u.id===e.id),c=l.rooms.find(u=>u.id===a?.room_id);a&&c&&Object.assign(a,vf(c.id===o.id?i:el(l,c,a.edge,this.host.doc.settings.wall_interior),c,a,n,e.lifts?r:null))}})}toWall(e){let r=this.renderRoot.querySelector("svg").getScreenCTM()?.inverse();if(!r)return[0,0];let o=new DOMPoint(e.clientX,e.clientY).matrixTransform(r);return[o.x,-o.y]}down(e,n){if(this._sel=n.id,!this.host.admin)return;e.currentTarget.setPointerCapture(e.pointerId);let[r,o]=this.toWall(e);this._drag={id:n.id,x0:n.x0,y0:n.y0,startU:r,startY:o,fromX:n.x0,fromY:n.y0}}move(e,n){let r=this._drag;if(!r||r.id!==n.id)return;let[o,i]=this.toWall(e),s=this.frame(),l=n.x1-n.x0,a=Math.min((s?.length??0)-l,Math.max(0,kf(r.fromX+o-r.startU))),c=n.lifts?Math.max(0,kf(r.fromY+i-r.startY)):r.fromY;this._drag={...r,x0:a,y0:c}}up(e){let n=this._drag;this._drag=null,!(!n||n.id!==e.id||Math.abs(n.x0-n.fromX)<1e-6&&Math.abs(n.y0-n.fromY)<1e-6)&&this.place(e,n.x0,n.y0)}nameOf(e){if(e.kind==="furniture")return this.host.floor?.furniture.find(o=>o.id===e.id)?.name||Ye(this.host.hass,e.type);let n=this.host.floor?.openings.find(r=>r.id===e.id);return n?this.host.t(`preset_${En(n)}`):e.type}updated(e){(e.has("edge")||e.has("roomId"))&&(this._sel=null)}render(){let e=this.host.t,n=this.room,r=this.frame();if(!n||!r)return _;let o=n.points.length,i=h=>pe(this.host.hass,h),s=this.boxes().map(h=>this._drag?.id===h.id?{...h,x1:this._drag.x0+(h.x1-h.x0),y1:this._drag.y0+(h.y1-h.y0),x0:this._drag.x0,y0:this._drag.y0}:h),l=Math.max(r.heightLeft,r.heightRight,...s.map(h=>h.y1)),a=.35,c=`${-a} ${-(l+a)} ${r.length+2*a} ${l+2*a+.25}`,u=s.find(h=>h.id===this._sel)??null,d=h=>{let f=Math.min(.14,Math.max(.07,(h.x1-h.x0)/7));return R`${this.nameOf(h)} `},p=u?R`
${i(u.x0)}
@@ -1058,7 +1058,7 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
/>`:_}`:M(e("wall_view_hint"))}
- `}close(){this.dispatchEvent(new CustomEvent("close"))}static styles=ne`
+
`}close(){this.dispatchEvent(new CustomEvent("close"))}static styles=J`
.backdrop {
position: fixed;
inset: 0;
@@ -1166,14 +1166,14 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
color: inherit;
font: inherit;
}
- `};customElements.get("nf-wall-view")||customElements.define("nf-wall-view",tl);function y0(t,e){let n=new Set([...Object.keys(t),...Object.keys(e)]);if(n.size===0)return 1/0;let r=0;for(let o of n)r+=Math.min(Math.abs((t[o]??-100)-(e[o]??-100)),40)**2;return Math.sqrt(r/n.size)}function yf(t,e){if(Object.keys(e).length===0)return{room:null,distance:1/0,margin:0};let n=new Map;for(let s of t){let l=y0(s.rssi,e);l<(n.get(s.room)??1/0)&&n.set(s.room,l)}let r=[...n].sort((s,l)=>s[1]-l[1]);if(r.length===0)return{room:null,distance:1/0,margin:0};let[o,i]=r[0];return i>18?{room:null,distance:i,margin:0}:{room:o,distance:i,margin:r.length>1?r[1][1]-i:18}}var v0=t=>{let e=[...t].sort((r,o)=>r-o),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2};function w0(t){let e={},n=new Set(t.flatMap(r=>Object.keys(r)));for(let r of n){let o=t.filter(i=>r in i).map(i=>i[r]);o.length*2>t.length&&(e[r]=Math.round(v0(o)*10)/10)}return e}function vf(t,e,n=3){let r=e.filter(s=>Object.keys(s).length>0);if(r.length===0)return[];let o=Math.max(1,Math.min(n,Math.floor(r.length/3))),i=[];for(let s=0;s0&&i.push({room:t,rssi:a})}return i}var wf=(t,e,n)=>[...t.filter(r=>r.room!==e),...n],kf=t=>Math.max(0,Math.min(1,(t+95)/50));var k0=1500,rl=class extends X{static properties={host:{attribute:!1},doc:{attribute:!1},_found:{state:!0},_pick:{state:!0},_name:{state:!0},_tag:{state:!0},_room:{state:!0},_scan:{state:!0},_samples:{state:!0},_error:{state:!0}};timer=0;recordStarted=0;constructor(){super(),this._found=null,this._pick="",this._name="",this._tag=null,this._room="",this._scan=null,this._samples=null,this._error=""}createRenderRoot(){return this}get tags(){return this.host.doc.settings.ble?.tags??[]}get rooms(){let e=this.host.doc.floors;return e.flatMap(n=>n.rooms.map(r=>({id:r.id,label:e.length>1?`${n.name} \xB7 ${r.name}`:r.name})))}connectedCallback(){super.connectedCallback(),this.loadDevices()}disconnectedCallback(){super.disconnectedCallback(),window.clearInterval(this.timer)}updated(e){e.has("_tag")&&this.restartPolling()}async loadDevices(){try{this._found=await this.host.hass.callWS({type:"nextfloor/ble/devices"})}catch(e){this._error=String(e?.message??e)}}restartPolling(){if(window.clearInterval(this.timer),this._scan=null,!this._tag)return;let e=()=>{this.pollOnce()};e(),this.timer=window.setInterval(e,k0)}async pollOnce(){let e=this.tags.find(n=>n.id===this._tag);if(!(!e||!this.host.hass))try{let n=await this.host.hass.callWS({type:"nextfloor/ble/scan",...e.entity?{entity:e.entity}:{address:e.address}});this._scan=n,this._error="",this._samples&&(this._samples=[...this._samples,Object.fromEntries(Object.entries(n.readings).map(([r,o])=>[r,o.rssi]))],Date.now()-this.recordStarted>=30*1e3&&this.finishRecording(e,n))}catch(n){this._error=String(n?.message??n)}}reading(){return Object.fromEntries(Object.entries(this._scan?.readings??{}).map(([e,n])=>[e,n.rssi]))}startRecording(){this._room&&(this.recordStarted=Date.now(),this._samples=[])}finishRecording(e,n){let r=this._samples??[];this._samples=null;let o=vf(this._room,r);if(o.length===0)return;let i=Object.fromEntries(Object.entries(n.readings).map(([s,l])=>[s,l.name]));this.update2(e.id,s=>{s.prints=wf(s.prints,this._room,o),s.scanners={...s.scanners??{},...i}})}update2(e,n){this.host.change(r=>{let o=r.settings.ble?.tags.find(i=>i.id===e);o&&n(o)})}addTag(){let e=this._pick;if(!e)return;let n=e.startsWith("device_tracker."),r=this._found?.devices.find(s=>s.address===e),o=this._name.trim()||r?.name||this.host.hass?.states[e]?.attributes.friendly_name||e,i={id:I("ble"),name:String(o).slice(0,60),prints:[],...n?{entity:e}:{address:e}};this.host.change(s=>{s.settings.ble={tags:[...s.settings.ble?.tags??[],i]}}),this._tag=i.id,this._pick="",this._name=""}removeTag(e){this.host.change(n=>{let r=(n.settings.ble?.tags??[]).filter(o=>o.id!==e);n.settings.ble=r.length?{tags:r}:null}),this._tag===e&&(this._tag=null)}bars(e){let n=this.host.t,r=this._scan,o=Object.entries(r?.readings??{}).sort((i,s)=>s[1].rssi-i[1].rssi);return m`
+ `};customElements.get("nf-wall-view")||customElements.define("nf-wall-view",tl);function $0(t,e){let n=new Set([...Object.keys(t),...Object.keys(e)]);if(n.size===0)return 1/0;let r=0;for(let o of n)r+=Math.min(Math.abs((t[o]??-100)-(e[o]??-100)),40)**2;return Math.sqrt(r/n.size)}function xf(t,e){if(Object.keys(e).length===0)return{room:null,distance:1/0,margin:0};let n=new Map;for(let s of t){let l=$0(s.rssi,e);l<(n.get(s.room)??1/0)&&n.set(s.room,l)}let r=[...n].sort((s,l)=>s[1]-l[1]);if(r.length===0)return{room:null,distance:1/0,margin:0};let[o,i]=r[0];return i>18?{room:null,distance:i,margin:0}:{room:o,distance:i,margin:r.length>1?r[1][1]-i:18}}var S0=t=>{let e=[...t].sort((r,o)=>r-o),n=e.length>>1;return e.length%2?e[n]:(e[n-1]+e[n])/2};function M0(t){let e={},n=new Set(t.flatMap(r=>Object.keys(r)));for(let r of n){let o=t.filter(i=>r in i).map(i=>i[r]);o.length*2>t.length&&(e[r]=Math.round(S0(o)*10)/10)}return e}function $f(t,e,n=3){let r=e.filter(s=>Object.keys(s).length>0);if(r.length===0)return[];let o=Math.max(1,Math.min(n,Math.floor(r.length/3))),i=[];for(let s=0;s
0&&i.push({room:t,rssi:a})}return i}var Sf=(t,e,n)=>[...t.filter(r=>r.room!==e),...n],Mf=t=>Math.max(0,Math.min(1,(t+95)/50));var R0=1500,rl=class extends Y{static properties={host:{attribute:!1},doc:{attribute:!1},_found:{state:!0},_pick:{state:!0},_name:{state:!0},_tag:{state:!0},_room:{state:!0},_scan:{state:!0},_samples:{state:!0},_error:{state:!0}};timer=0;recordStarted=0;constructor(){super(),this._found=null,this._pick="",this._name="",this._tag=null,this._room="",this._scan=null,this._samples=null,this._error=""}createRenderRoot(){return this}get tags(){return this.host.doc.settings.ble?.tags??[]}get rooms(){let e=this.host.doc.floors;return e.flatMap(n=>n.rooms.map(r=>({id:r.id,label:e.length>1?`${n.name} \xB7 ${r.name}`:r.name})))}connectedCallback(){super.connectedCallback(),this.loadDevices()}disconnectedCallback(){super.disconnectedCallback(),window.clearInterval(this.timer)}updated(e){e.has("_tag")&&this.restartPolling()}async loadDevices(){try{this._found=await this.host.hass.callWS({type:"nextfloor/ble/devices"})}catch(e){this._error=String(e?.message??e)}}restartPolling(){if(window.clearInterval(this.timer),this._scan=null,!this._tag)return;let e=()=>{this.pollOnce()};e(),this.timer=window.setInterval(e,R0)}async pollOnce(){let e=this.tags.find(n=>n.id===this._tag);if(!(!e||!this.host.hass))try{let n=await this.host.hass.callWS({type:"nextfloor/ble/scan",...e.entity?{entity:e.entity}:{address:e.address}});this._scan=n,this._error="",this._samples&&(this._samples=[...this._samples,Object.fromEntries(Object.entries(n.readings).map(([r,o])=>[r,o.rssi]))],Date.now()-this.recordStarted>=30*1e3&&this.finishRecording(e,n))}catch(n){this._error=String(n?.message??n)}}reading(){return Object.fromEntries(Object.entries(this._scan?.readings??{}).map(([e,n])=>[e,n.rssi]))}startRecording(){this._room&&(this.recordStarted=Date.now(),this._samples=[])}finishRecording(e,n){let r=this._samples??[];this._samples=null;let o=$f(this._room,r);if(o.length===0)return;let i=Object.fromEntries(Object.entries(n.readings).map(([s,l])=>[s,l.name]));this.update2(e.id,s=>{s.prints=Sf(s.prints,this._room,o),s.scanners={...s.scanners??{},...i}})}update2(e,n){this.host.change(r=>{let o=r.settings.ble?.tags.find(i=>i.id===e);o&&n(o)})}addTag(){let e=this._pick;if(!e)return;let n=e.startsWith("device_tracker."),r=this._found?.devices.find(s=>s.address===e),o=this._name.trim()||r?.name||this.host.hass?.states[e]?.attributes.friendly_name||e,i={id:I("ble"),name:String(o).slice(0,60),prints:[],...n?{entity:e}:{address:e}};this.host.change(s=>{s.settings.ble={tags:[...s.settings.ble?.tags??[],i]}}),this._tag=i.id,this._pick="",this._name=""}removeTag(e){this.host.change(n=>{let r=(n.settings.ble?.tags??[]).filter(o=>o.id!==e);n.settings.ble=r.length?{tags:r}:null}),this._tag===e&&(this._tag=null)}bars(e){let n=this.host.t,r=this._scan,o=Object.entries(r?.readings??{}).sort((i,s)=>s[1].rssi-i[1].rssi);return m`
${o.length===0?m`
${r&&!r.available?n("ble_unavailable"):r?.address===null&&e.entity?n("ble_no_address"):n("ble_none_heard")}
`:o.map(([i,s])=>m`
${s.name}
-
+
${Math.round(s.rssi)}
`)}
${o.length===1?M(n("ble_one_scanner")):_}
-
`}learn(e){let n=this.host.t,r=this.rooms,o=yf(e.prints,this.reading()),i=c=>r.find(u=>u.id===c)?.label??null,s=c=>e.prints.filter(u=>u.room===c).length,l=this._samples!==null,a=l?Math.max(0,30-Math.round((Date.now()-this.recordStarted)/1e3)):0;return m`${this.bars(e)}
+ `}learn(e){let n=this.host.t,r=this.rooms,o=xf(e.prints,this.reading()),i=c=>r.find(u=>u.id===c)?.label??null,s=c=>e.prints.filter(u=>u.room===c).length,l=this._samples!==null,a=l?Math.max(0,30-Math.round((Date.now()-this.recordStarted)/1e3)):0;return m`${this.bars(e)}
${n("ble_now")}: ${o.room?i(o.room):n("ble_unknown")}
`}};customElements.get("nf-ble-locate")||customElements.define("nf-ble-locate",rl);var E0=new URL(import.meta.url),A0=new URL("./nextfloor-3d.js?v=74227cd20cc3",E0).href,Rf;function bn(){return Rf??=import(A0),Rf}var Ef=["lights","seating","tables","storage","beds","kitchen","appliances","bath","media","office","tech","climate","energy","garden","plants","kids","fitness","pets","workshop","music","season","pictures","vehicles","building","decor"],F0={sofa:"seating",armchair:"seating",stool:"seating",chair:"seating",bench:"seating",corner_bench:"seating",bar_stool:"seating",office_chair:"office",coffee_table:"tables",table:"tables",table_round:"tables",desk:"office",worktop:"kitchen",tv_board:"media",tv_wall:"media",sideboard:"storage",shelf:"storage",tall_cabinet:"storage",wardrobe:"storage",dresser:"storage",nightstand:"beds",coat_rack:"storage",plant:"plants",rug:"decor",kitchen:"kitchen",kitchen_wall:"kitchen",kitchen_tall:"kitchen",island:"kitchen",sink:"kitchen",stove:"kitchen",dishwasher:"appliances",fridge:"appliances",washer:"appliances",dryer:"appliances",robot_vacuum:"appliances",bed:"beds",bunk_bed:"beds",bathtub:"bath",shower:"bath",wc:"bath",washbasin:"bath",radiator:"climate",stairs:"building",parking:"vehicles",ceiling_fan:"lights"},T0=[[/xmas|advent|window_star|candle_arch|reindeer|pumpkin|easter|snowman|gift_pile|lights_outdoor/,"season"],[/^frame_|^canvas$|^poster$|picture_ledge/,"pictures"],[/piano|drum_kit|guitar|synth|mic_stand|vinyl|easel|studio_monitor|mixing_desk/,"music"],[/lamp|pendant|light_pillar|light_bars|mood_spot|ceiling_panel|garden_spots|wall_light|light_cove|niche_led|shelf_led|monitor_light|workshop_light|painting_light|cabinet_light|moon_light|torch|lantern|ceiling_fan_light/,"lights"],[/cat_|dog_|pet_|litter|scratch|hamster|rabbit|bird_cage|small_animal|aquarium|terrarium/,"pets"],[/stairs|steps|landing|rail_|column|pilaster|beam|chimney|glass_wall|sliding_wall|half_wall|platform|niche_shelf|window_seat|divider_slats|gallery/,"building"],[/tree|shrub|conifer|hedge|brush|monstera|plant|herb_garden|herb_planter|flower|raised_bed|greenhouse|ficus|cactus|bonsai|living_wall|vertical_garden/,"plants"],[/kids|toy|teepee|(^|_)play_|rocking_horse|ball_pit|house_bed|cot\b|^cot|crib|changing_table|baby|loft_bed|star_projector|moon_light/,"kids"],[/treadmill|fitness|power_rack|rowing|rower|spin_bike|dumbbell|punching|yoga|elliptical|gym|exercise|wall_bars|bike_trainer|kettlebell|weight_bench|massage_chair/,"fitness"],[/heat_pump|boiler|buffer_tank|manifold|ventilation|radiator|towel_heater|thermostat|air_purifier|humidifier|dehumidifier|tower_fan|ceiling_fan|hot_water|water_softener|water_pump|fireplace|wood_stove|patio_heater|sauna|oil_|expansion_vessel|water_tank|infrared|cold_bath/,"climate"],[/wallbox|inverter|battery|solar|meter|fuse_box|grid/,"energy"],[/workbench|tool_|compressor|drill|tyre|paint_cabinet|heavy_shelf|shelf_rack|garage_opener|workshop|bike_stand|bike_holder|bike_rack|lawn_mower|mower|welder|ev_bike_charger|tool_chest|parts_cabinet/,"workshop"],[/speaker|subwoofer|soundbar|receiver|turntable|record|game_console|multiroom|hifi|cinema|acoustic|bass_trap|popcorn|projector|projection|screen|display_|smart_display|media|tv|arcade|star_ceiling|av_/,"media"],[/desk|office|filing|whiteboard|monitor|bookcase|phone_booth|sim_cockpit|chair_gaming|gaming/,"office"],[/server|nas|router|wifi|access_point|network|printer|filament|tower_pc|smoke_detector|siren|baby_monitor|sunrise_clock|light_switch|socket|co_detector|presence_|water_leak|air_quality|doorbell/,"tech"],[/grill|lounge|lounger|parasol|pergola|hot_tub|fire_bowl|torch|lantern|play_tower|garden|trampoline|sprinkler|valve|rain_barrel|outdoor|hammock|(^|_)pool|swing|bin_box|^bin_|mailbox|rotary_line|kamado|pizza_oven|fire_pit|sandbox|wood_pile|bird_house|cistern|pond|water_feature|beach_chair/,"garden"],[/vanity_\d|vanity_double|double_vanity|basin|bath|shower|toilet|bidet|towel|mirror_cabinet|mirror_round|mirror_80|mirror_led|whirlpool|washer_under|laundry|urinal|wt_\d|handtuch|seife|wc/,"bath"],[/fridge|freezer|dishwasher|washer|dryer|microwave|coffee_machine|kettle|toaster|mixer|oven|steam|vacuum|ironing|drying_rack|trash|water_cooler|drip_tray|espresso|air_fryer|water_bar|thermo_cooker/,"appliances"],[/base_|drawer_|sink|hob|cooker|hood|pantry|kitchen|island|breakfast_bar|wall_\d|wall_glass|wall_corner|row_|spice|cabinet_light|trolley|bar_cart|utility_sink/,"kitchen"],[/bed|boxspring|futon|nightstand|canopy|mattress/,"beds"],[/sofa|chair|armchair|stool|bench|pouf|bean_bag|recliner|wingback|chaise|seat|ektorp|poang|cosy_corner|swing_bench|hanging_chair|nook|floor_cushion|tatami/,"seating"],[/table|dining|coffee_|side_round|lack_|^console$|bekant|alex/,"tables"],[/wardrobe|closet|clothes_rail|chest|dresser|shelf|cabinet|sideboard|lowboard|highboard|kallax|billy|ivar|pax|besta|cube_|coat_stand|shoe_bench|divider|display_cabinet|wall_unit|malm_chest|locker/,"storage"]];function z0(t){if(t.vehicle)return"vehicles";if(t.climate)return"climate";if(!t.type.startsWith("pack:"))return t.lamp?"lights":F0[t.type]??"decor";let e=T0.find(([n])=>n.test(t.id));return e?e[1]:t.lamp?"lights":"decor"}var Af=[[/k(u|ü)che|kitchen|kochen/,["kitchen","appliances","tables","seating","storage","plants","decor"]],[/wohn|living|lounge|salon/,["seating","tables","storage","media","plants","decor","climate","tech"]],[/\bess|dining/,["tables","seating","storage","plants","decor","media"]],[/schlaf|bed|gast|guest/,["beds","storage","seating","tables","decor","plants","climate","media"]],[/kind|kids|child|baby|spiel|play|nursery/,["kids","beds","storage","seating","tables","decor"]],[/bad|bath|wc|toilet|dusch|shower|sauna/,["bath","appliances","storage","climate","plants"]],[/b(u|ü)ro|office|arbeit|study|work/,["office","tech","storage","seating","tables","plants"]],[/kino|cinema|media|game|gaming|hifi/,["media","seating","tables","storage","office"]],[/fitness|gym|sport|training/,["fitness","media","storage","climate"]],[/garage|carport|stellplatz|parking/,["vehicles","workshop","energy","storage","garden"]],[/werkstatt|workshop|hobby|keller|cellar|basement|lager|storage/,["workshop","storage","appliances","energy","climate","fitness","tech"]],[/hauswirtschaft|hwr|utility|laundry|wasch|technik|heiz|boiler/,["appliances","climate","energy","storage","tech","bath"]],[/flur|diele|hall|entr|eingang|corridor|treppe|stair/,["storage","seating","decor","plants","building"]],[/garten|garden|terrass|terrace|balkon|balcony|patio|hof|yard|pool/,["garden","plants","seating","tables","pets","kids"]]];function ol(t){let e=(t??"").toLowerCase(),n=Af.find(([r])=>r.test(e));return n?new Set(["lights",...n[1]]):null}function il(t){let e=(t??"").toLowerCase();return Af.find(([n])=>n.test(e))?.[1][0]??null}var Ff=t=>t==="garden"||t==="plants"||t==="vehicles",Tf=/_(\d+(?:x\d+)?)$/;function zf(t){let e=new Map;for(let n of t){let r=z0(n),o=n.type.startsWith("pack:")&&!n.vehicle?n.id.replace(Tf,""):n.id,i=`${n.source}:${o}`,s=e.get(i);s&&s.category===r?s.entries.push(n):e.set(s?`${i}:${n.id}`:i,{key:s?`${i}:${n.id}`:i,category:r,entries:[n]})}for(let n of e.values())n.entries.sort((r,o)=>r.size[0]-o.size[0]||r.size[1]-o.size[1]);return[...e.values()]}function Pf(t,e){let n=o=>Math.round(o*100);return e.some(o=>o!==t&&n(o.size[0])===n(t.size[0]))?Tf.exec(t.id)?.[1]??`${n(t.size[0])}\xD7${n(t.size[2])}`:`${n(t.size[0])}`}function If(t,e,n=12){return[e,...t.filter(r=>r!==e)].slice(0,n)}var Df=t=>t.toLowerCase().normalize("NFD").replace(new RegExp("\\p{M}","gu"),""),Of=t=>Df(t).split(/\s+/).filter(Boolean),Hf=(t,e)=>{let n=Df(e);return t.every(r=>n.includes(r))};function Lf(){let e=navigator.deviceMemory??8,n=navigator.hardwareConcurrency||8;return e<=3||n<=4||/Silk|KF[A-Z]{2,4}\b/.test(navigator.userAgent)}var Cf=112,P0="nextfloor-thumbs";function I0(t){let e=2166136261;for(let n=0;n>>0).toString(36)}function sl(t){let e=U(t);return`${t}|${e?I0(JSON.stringify(e)):"b"}|${Cf}`}function D0(){return new Promise(t=>{try{let e=indexedDB.open(P0,1);e.onupgradeneeded=()=>e.result.createObjectStore("thumbs"),e.onsuccess=()=>t(e.result),e.onerror=()=>t(null)}catch{t(null)}})}var al=class{enabled=!Lf();memory=new Map;waiting=new Map;queue=[];db=null;running=!1;packs=[];cached(e){return this.memory.get(sl(e))}get(e){let n=sl(e),r=this.memory.get(n);return r?Promise.resolve(r):new Promise(o=>{let i=this.waiting.get(n);if(i)return void i.push(o);this.waiting.set(n,[o]),this.lookUp(e,n)})}settle(e,n){n&&this.memory.set(e,n);for(let r of this.waiting.get(e)??[])r(n);this.waiting.delete(e)}async lookUp(e,n){this.db??=D0();let r=await this.db,o=r?await new Promise(i=>{try{let s=r.transaction("thumbs").objectStore("thumbs").get(n);s.onsuccess=()=>i(typeof s.result=="string"?s.result:null),s.onerror=()=>i(null)}catch{i(null)}}):null;if(o)return this.settle(n,o);this.queue.push(e),this.pump()}pump(){if(this.running)return;let e=this.queue.shift();if(!e)return;this.running=!0;let n=window.requestIdleCallback;(o=>n?n(o,{timeout:300}):setTimeout(o,16))(async()=>{let o=sl(e),i=null;try{let[s,l,a]=ut(e);i=(await bn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:jo[e]??null},Cf,[...this.packs]),this.keep(o,i)}catch{i=null}this.settle(o,i),this.running=!1,this.pump()})}async keep(e,n){let r=await this.db;try{r?.transaction("thumbs","readwrite").objectStore("thumbs").put(n,e)}catch{}}},jt=new al,go=null,O0=t=>{for(let e of t)e.isIntersecting&&e.target.visible()},ll=class extends Y{static properties={type:{},_url:{state:!0}};static styles=J`
:host {
display: block;
aspect-ratio: 4 / 3;
@@ -1227,7 +1227,7 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
height: 100%;
object-fit: contain;
}
- `;constructor(){super(),this.type="",this._url=null}connectedCallback(){super.connectedCallback(),jt.enabled&&(this._url=jt.cached(this.type)??null,!this._url&&(mo??=new IntersectionObserver(T0,{rootMargin:"120px"}),mo.observe(this)))}disconnectedCallback(){super.disconnectedCallback(),mo?.unobserve(this)}updated(e){e.has("type")&&e.get("type")!==void 0&&(this._url=jt.cached(this.type)??null,!this._url&&jt.enabled&&mo?.observe(this))}visible(){mo?.unobserve(this);let e=this.type;jt.get(e).then(n=>{this.type===e&&(this._url=n)})}render(){return this._url?m` `:_}};customElements.get("nf-thumb")||customElements.define("nf-thumb",ll);var Of="nextfloor.library2",z0={language:"en"},Hi=class{onChange;text="";saved;shown=null;picked=new Map;constructor(e){this.onChange=e,this.saved={folded:{},favourites:[],recent:[],flags:["room"]};try{let n=localStorage.getItem(Of);n&&(this.saved={...this.saved,...JSON.parse(n)})}catch{}}store(e){this.saved={...this.saved,...e},this.onChange();try{localStorage.setItem(Of,JSON.stringify(this.saved))}catch{}}get query(){return this.text}set query(e){this.text=e,this.onChange()}isOpen(e,n){return this.saved.folded[e]??n}toggle(e,n){this.store({folded:{...this.saved.folded,[e]:!this.isOpen(e,n)}})}has(e){return this.saved.flags.includes(e)}flip(e){this.store({flags:this.has(e)?this.saved.flags.filter(n=>n!==e):[...this.saved.flags,e]})}get favourites(){return this.saved.favourites}isFavourite(e){return this.saved.favourites.includes(e)}toggleFavourite(e){this.store({favourites:this.isFavourite(e)?this.saved.favourites.filter(n=>n!==e):[e,...this.saved.favourites]})}get recent(){return this.saved.recent}used(e){this.store({recent:Ff(this.saved.recent,e)})}pickedOf(e){let n=this.picked.get(e.key);return e.entries.find(r=>r.type===n)??e.entries[0]}pick(e,n){this.picked.set(e.key,n),this.onChange()}get preview(){return this.shown}hidePreview(){this.shown=null,this.onChange()}async showPreview(e,n,r){let o=n.getBoundingClientRect(),i={left:Math.max(8,o.left-196),top:Math.max(8,Math.min(window.innerHeight-200,o.top+o.height/2-95))};this.shown={type:e,url:null,...i},this.onChange();try{let[s,l,a]=ut(e),c=(await bn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:jo[e]??null},180,[...r]);this.shown?.type===e&&(this.shown={type:e,url:c,...i})}catch{this.shown=null}this.onChange()}};function P0(t,e){let n=t.hass?.language??"en",o=[...[...new Set(Object.values(iu).flat())].map(l=>({type:l,source:"builtin",id:l,size:tt[l],lamp:ce(l),electric:Et(l)})),...e.flatMap(l=>l.items.map(a=>({type:he(l.id,a.id),source:l.id,id:a.id,size:a.size,lamp:!!a.light,electric:!!a.electric,vehicle:!!a.vehicle,climate:!!a.climate})))],i=new Map(e.map(l=>[l.id,He(l,n)])),s=new Map(e.flatMap(l=>l.items.map(a=>[he(l.id,a.id),a])));return Ef(o).map(l=>{let a=l.entries[0],c=s.get(a.type),u=c?Xe(c,a.type,n):t.t(`furn_${a.type}`),d=l.entries.length>1&&u.replace(/\s*\(?\d+([.,]\d+)?\s*(cm|x\s*\d+|×\s*\d+)?\)?\s*$/i,"").trim()||u,p=l.entries.map(h=>{let f=s.get(h.type);return f?[...Object.values(f.name),Xe(f,h.type,n)].join(" "):Se(z0,`furn_${h.type}`)}).join(" ");return{card:l,label:d,search:`${p} ${t.t(`lib_cat_${l.category}`)}`,from:i.get(a.source)??"NextFloor"}})}var I0=(t,e)=>Pf(e,`${t.label} ${t.search} ${t.from} ${t.card.entries.map(n=>n.id.replace(/_/g," ")).join(" ")}`),D0=t=>t.lamp?"light":t.electric?"switch":null;function O0(t,e,n,r){let o=t.t,i=e.pickedOf(n.card),[s,l]=i.size,a=D0(i),c=p=>{e.showPreview(i.type,p.currentTarget,r.packs)},u=()=>{e.used(i.type),r.add(i.type)},d=e.isFavourite(i.type);return m`
+ `;constructor(){super(),this.type="",this._url=null}connectedCallback(){super.connectedCallback(),jt.enabled&&(this._url=jt.cached(this.type)??null,!this._url&&(go??=new IntersectionObserver(O0,{rootMargin:"120px"}),go.observe(this)))}disconnectedCallback(){super.disconnectedCallback(),go?.unobserve(this)}updated(e){e.has("type")&&e.get("type")!==void 0&&(this._url=jt.cached(this.type)??null,!this._url&&jt.enabled&&go?.observe(this))}visible(){go?.unobserve(this);let e=this.type;jt.get(e).then(n=>{this.type===e&&(this._url=n)})}render(){return this._url?m`
`:_}};customElements.get("nf-thumb")||customElements.define("nf-thumb",ll);var Nf="nextfloor.library2",H0={language:"en"},Hi=class{onChange;text="";saved;shown=null;picked=new Map;constructor(e){this.onChange=e,this.saved={folded:{},favourites:[],recent:[],flags:["room"]};try{let n=localStorage.getItem(Nf);n&&(this.saved={...this.saved,...JSON.parse(n)})}catch{}}store(e){this.saved={...this.saved,...e},this.onChange();try{localStorage.setItem(Nf,JSON.stringify(this.saved))}catch{}}get query(){return this.text}set query(e){this.text=e,this.onChange()}isOpen(e,n){return this.saved.folded[e]??n}toggle(e,n){this.store({folded:{...this.saved.folded,[e]:!this.isOpen(e,n)}})}has(e){return this.saved.flags.includes(e)}flip(e){this.store({flags:this.has(e)?this.saved.flags.filter(n=>n!==e):[...this.saved.flags,e]})}get favourites(){return this.saved.favourites}isFavourite(e){return this.saved.favourites.includes(e)}toggleFavourite(e){this.store({favourites:this.isFavourite(e)?this.saved.favourites.filter(n=>n!==e):[e,...this.saved.favourites]})}get recent(){return this.saved.recent}used(e){this.store({recent:If(this.saved.recent,e)})}pickedOf(e){let n=this.picked.get(e.key);return e.entries.find(r=>r.type===n)??e.entries[0]}pick(e,n){this.picked.set(e.key,n),this.onChange()}get preview(){return this.shown}hidePreview(){this.shown=null,this.onChange()}async showPreview(e,n,r){let o=n.getBoundingClientRect(),i={left:Math.max(8,o.left-196),top:Math.max(8,Math.min(window.innerHeight-200,o.top+o.height/2-95))};this.shown={type:e,url:null,...i},this.onChange();try{let[s,l,a]=ut(e),c=(await bn()).furniturePreview({type:e,w:s,d:l,h:a,variant:null,lamp:jo[e]??null},180,[...r]);this.shown?.type===e&&(this.shown={type:e,url:c,...i})}catch{this.shown=null}this.onChange()}};function L0(t,e){let n=t.hass?.language??"en",o=[...[...new Set(Object.values(cu).flat())].map(l=>({type:l,source:"builtin",id:l,size:tt[l],lamp:ue(l),electric:Et(l)})),...e.flatMap(l=>l.items.map(a=>({type:he(l.id,a.id),source:l.id,id:a.id,size:a.size,lamp:!!a.light,electric:!!a.electric,vehicle:!!a.vehicle,climate:!!a.climate})))],i=new Map(e.map(l=>[l.id,He(l,n)])),s=new Map(e.flatMap(l=>l.items.map(a=>[he(l.id,a.id),a])));return zf(o).map(l=>{let a=l.entries[0],c=s.get(a.type),u=c?Xe(c,a.type,n):t.t(`furn_${a.type}`),d=l.entries.length>1&&u.replace(/\s*\(?\d+([.,]\d+)?\s*(cm|x\s*\d+|×\s*\d+)?\)?\s*$/i,"").trim()||u,p=l.entries.map(h=>{let f=s.get(h.type);return f?[...Object.values(f.name),Xe(f,h.type,n)].join(" "):Se(H0,`furn_${h.type}`)}).join(" ");return{card:l,label:d,search:`${p} ${t.t(`lib_cat_${l.category}`)}`,from:i.get(a.source)??"NextFloor"}})}var C0=(t,e)=>Hf(e,`${t.label} ${t.search} ${t.from} ${t.card.entries.map(n=>n.id.replace(/_/g," ")).join(" ")}`),N0=t=>t.lamp?"light":t.electric?"switch":null;function B0(t,e,n,r){let o=t.t,i=e.pickedOf(n.card),[s,l]=i.size,a=N0(i),c=p=>{e.showPreview(i.type,p.currentTarget,r.packs)},u=()=>{e.used(i.type),r.add(i.type)},d=e.isFavourite(i.type);return m`
e.toggleFavourite(i.type)}>${d?"\u2605":"\u2606"}
${n.card.entries.length>1?m`
- ${n.card.entries.map(p=>m`e.pick(n.card,p.type)}>${Af(p,n.card.entries)} `)}
+ ${n.card.entries.map(p=>m`e.pick(n.card,p.type)}>${Pf(p,n.card.entries)} `)}
`:_}
- `}function Lf(t,e,n,r){return m`
${n.map(o=>O0(t,e,o,r))}
`}function cl(t,e,n,r,o,i,s){if(o.length===0)return _;let l=e.isOpen(n,s);return m`
e.toggle(n,s)}>
+ `}function Wf(t,e,n,r){return m`${n.map(o=>B0(t,e,o,r))}
`}function cl(t,e,n,r,o,i,s){if(o.length===0)return _;let l=e.isOpen(n,s);return m`e.toggle(n,s)}>
${l?"\u25BE":"\u25B8"} ${r} ${o.length}
- ${l?Lf(t,e,o,i):_}`}function Hf(t,e){return t.flatMap(n=>{let r=e.find(o=>o.card.entries.some(i=>i.type===n));return r?[{...r,card:{...r.card,key:`one:${n}`,entries:r.card.entries.filter(o=>o.type===n)}}]:[]})}function H0(t){let e=il(t),n=ol(t),r=o=>o===e?0:n?.has(o)?1:2;return[...$f].sort((o,i)=>r(o)-r(i))}function Cf(t,e,n,r){let o=t.t;jt.packs=r.packs;let i=P0(t,r.packs),s=zf(e.query),l=ol(n),a=!!l&&e.has("room")&&s.length===0,c=i.filter(p=>{let h=p.card.entries[0];return a&&!l.has(p.card.category)||e.has("linkable")&&!h.lamp&&!h.electric||e.has("lit")&&!h.lamp||e.has("outdoor")&&!Mf(p.card.category)?!1:s.length===0||I0(p,s)}),u=(p,h)=>m`e.flip(p)}>${h} `,d=s.length>0;return m`
+ ${l?Wf(t,e,o,i):_}`}function Bf(t,e){return t.flatMap(n=>{let r=e.find(o=>o.card.entries.some(i=>i.type===n));return r?[{...r,card:{...r.card,key:`one:${n}`,entries:r.card.entries.filter(o=>o.type===n)}}]:[]})}function W0(t){let e=il(t),n=ol(t),r=o=>o===e?0:n?.has(o)?1:2;return[...Ef].sort((o,i)=>r(o)-r(i))}function Vf(t,e,n,r){let o=t.t;jt.packs=r.packs;let i=L0(t,r.packs),s=Of(e.query),l=ol(n),a=!!l&&e.has("room")&&s.length===0,c=i.filter(p=>{let h=p.card.entries[0];return a&&!l.has(p.card.category)||e.has("linkable")&&!h.lamp&&!h.electric||e.has("lit")&&!h.lamp||e.has("outdoor")&&!Ff(p.card.category)?!1:s.length===0||C0(p,s)}),u=(p,h)=>m`e.flip(p)}>${h} `,d=s.length>0;return m`
${o("furniture_add")}
${n?o("furniture_into",{room:n}):o("furniture_pick_room")}
r.studio()}>🛠️ ${o("studio_new")}
@@ -1267,61 +1267,61 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${u("outdoor",`\u{1F333} ${o("lib_outdoor")}`)}
${d&&c.length===0?m`${o("furniture_search_none")}
`:_}
- ${d?Lf(t,e,c,r):m`${cl(t,e,"favourites",`\u2605 ${o("lib_favourites")}`,Hf(e.favourites,i),r,!0)}
- ${cl(t,e,"recent",`\u{1F558} ${o("lib_recent")}`,Hf(e.recent.slice(0,6),i),r,!1)}
- ${H0(n).map(p=>cl(t,e,p,o(`lib_cat_${p}`),c.filter(h=>h.card.category===p),r,p===(il(n)??"lights")))}
+ ${d?Wf(t,e,c,r):m`${cl(t,e,"favourites",`\u2605 ${o("lib_favourites")}`,Bf(e.favourites,i),r,!0)}
+ ${cl(t,e,"recent",`\u{1F558} ${o("lib_recent")}`,Bf(e.recent.slice(0,6),i),r,!1)}
+ ${W0(n).map(p=>cl(t,e,p,o(`lib_cat_${p}`),c.filter(h=>h.card.category===p),r,p===(il(n)??"lights")))}
${a?m`e.flip("room")}>${o("lib_all_rooms")} `:_}`}
- `}function Nf(t,e){return e?m`
+ `}function Kf(t,e){return e?m`
${e.url?m`
`:m`
`}
${Ye(t.hass,e.type)}
-
`:_}function ul(t,e,n,r=24){let o=Math.hypot(e[0]-t[0],e[1]-t[1]);if(o<1e-6||Math.abs(n)<1e-4)return[];let i=Math.max(-o*2,Math.min(o*2,n)),s=[(e[0]-t[0])/o,(e[1]-t[1])/o],l=[s[1],-s[0]],a=o*o/4/(2*Math.abs(i))+Math.abs(i)/2,c=2*Math.atan(2*Math.abs(i)/o),u=Math.max(2,Math.min(r,Math.ceil(2*c/Math.PI*180/11.25))),d=[l[0]*Math.sign(i),l[1]*Math.sign(i)],p=[(t[0]+e[0])/2,(t[1]+e[1])/2],h=[p[0]-d[0]*(a-Math.abs(i)),p[1]-d[1]*(a-Math.abs(i))],f=[];for(let g=1;g
t.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function hl(t,e){let n=Math.max(0,e);for(let r=0;r+1Math.round(t*1e3)/1e3,pl=t=>t.map(([e,n])=>[Te(e),Te(n)]);function Bf(t,e){return{id:I("room"),name:e,area_id:null,points:pl(t),floor_material:"wood"}}function Wf(t){return{...structuredClone(t),id:I("room"),points:pl(t.points.map(([e,n])=>[e+.5,n+.5]))}}function Vf(t,e){let n=t.rooms.find(r=>r.id===e);t.rooms=t.rooms.filter(r=>r.id!==e),t.openings=t.openings.filter(r=>r.room_id!==e||r.wall),n&&(t.placements=t.placements.filter(r=>!N([r.x,r.z],n.points)))}function Kf(t,e,n){let r=t.rooms.find(s=>s.id===e);if(!r||r.points.length<=3)return!1;let o=(n-1+r.points.length)%r.points.length;r.points.splice(n,1),r.wall_heights?.splice(n,1),r.wall_slopes?.splice(n,1),r.wall_thickness?.splice(n,1);let i=s=>s.room_id===e&&!s.wall;return t.openings=t.openings.filter(s=>!(i(s)&&(s.edge===n||s.edge===o))).map(s=>i(s)&&s.edge>n?{...s,edge:s.edge-1}:s),!0}function jf(t,e,n){if(!Number.isFinite(n))return null;let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:n>.05&&(e==="w"?s=o+n:l=i+n),pl([[o,i],[s,i],[s,l],[o,l]])}function Gf(t,e,n,r){return!Number.isFinite(r)||e<0||e>=t.points.length?null:t.points.map((o,i)=>i===e?n===0?[Te(r),o[1]]:[o[0],Te(r)]:[o[0],o[1]])}var L0=/^(Raum|Room) \d+$/;function fl(t,e,n){let r=e?n[e]:void 0,o=!t.name||L0.test(t.name)||Object.values(n).some(i=>i.name===t.name);return{area_id:e||null,...r&&o?{name:r.name}:{}}}function Uf(t,e){let n=e.filter(a=>Q(a.entity_id)==="light"&&(a.mount??"ceiling")==="ceiling"&&N([a.x,a.z],t.points));if(n.length<2)return[];let r=de(t.points),[o,i]=[r.x1-r.x0,r.z1-r.z0],s=Math.max(1,Math.round(Math.sqrt(n.length*o/Math.max(.1,i)))),l=Math.ceil(n.length/s);return n.map((a,c)=>{let u=Math.floor(c/s),d=u===l-1?n.length-s*(l-1):s,p=c-u*s;return{entityId:a.entity_id,x:Te(r.x0+o/d*(p+.5)),z:Te(r.z0+i/l*(u+.5))}})}function ml(t,e,n,r){let o=t.rooms.find(u=>u.id===e);if(!o)return;let i=o.points[n],s=o.points[(n+1)%o.points.length];o.points.splice(n+1,0,r);let[l,a]=[o.wall_heights?.[n],o.wall_slopes?.[n]];if(typeof l=="number"&&typeof a=="number"&&o.wall_slopes){let u=Math.hypot(s[0]-i[0],s[1]-i[1]),d=Te(l+(a-l)*Math.min(1,Math.hypot(r[0]-i[0],r[1]-i[1])/(u||1)));o.wall_slopes.splice(n,1,d,a),o.wall_heights.splice(n+1,0,d)}else o.wall_heights?.splice(n+1,0,o.wall_heights[n]??null),o.wall_slopes?.splice(n+1,0,null);o.wall_thickness?.splice(n+1,0,o.wall_thickness[n]??null);let c=Math.hypot(r[0]-i[0],r[1]-i[1]);for(let u of t.openings)u.room_id!==e||u.wall||(u.edge>n?u.edge+=1:u.edge===n&&u.offset>c&&(u.edge=n+1,u.offset=Te(u.offset-c)))}var C0=22.5;function Zf(t,e,n){let r=Math.min(Math.abs(e),t*2),o=t*(1+8/3*(r/Math.max(1e-6,t))**2),i=4*Math.atan(2*r/Math.max(1e-6,t))*180/Math.PI,s=Math.max(2,Math.ceil(i/C0));if(n<=0)return 24;let l=Math.floor(o/(n+.1));return l>=s?l:0}function N0(t,e,n,r){let o=dl(n);t.forEach((i,s)=>{let{piece:l,offset:a}=hl(n,e[s]*o),c=Math.hypot(n[l+1][0]-n[l][0],n[l+1][1]-n[l][1]);i.edge=r+l,i.offset=Te(c>i.width?Math.min(c-i.width/2,Math.max(i.width/2,a)):c/2)})}function qf(t,e,n,r){let o=t.rooms.find(v=>v.id===e);if(!o||n<0||n>=o.points.length||Math.abs(r)<.01)return!1;let i=o.points[n],s=o.points[(n+1)%o.points.length],l=Math.hypot(s[0]-i[0],s[1]-i[1]);if(l<.2)return!1;let[a,c]=[(s[0]-i[0])/l,(s[1]-i[1])/l],u=[(i[0]+s[0])/2+c*.02,(i[1]+s[1])/2-a*.02],p=N(u,o.points)?-r:r,h=(v,w)=>t.openings.filter(x=>x.room_id===v.id&&!x.wall&&x.edge===w),f=t.rooms.flatMap(v=>v.points.map((w,x)=>{let k=v.points[(x+1)%v.points.length],S=(E,T)=>Math.abs(E[0]-T[0])<.001&&Math.abs(E[1]-T[1])<.001;return S(w,i)&&S(k,s)?[v,x,!1]:S(w,s)&&S(k,i)?[v,x,!0]:null}).filter(w=>!!w)),g=Math.max(0,...f.flatMap(([v,w])=>h(v,w).map(x=>x.width))),y=Zf(l,r,g);if(!y)return!1;let b=ul(i,s,p,y).map(([v,w])=>[Te(v),Te(w)]);if(!b.length)return!1;for(let[v,w,x]of f){let k=x?[...b].reverse():b,S=h(v,w),E=v.points[w],T=S.map(F=>Math.min(1,Math.max(0,F.offset/l)));for(let F of S)F.edge=-1;k.forEach((F,O)=>ml(t,v.id,w+O,F)),v.wall_splits?.splice(w+1,0,...k.map(()=>null)),v.wall_splits?.[w]&&(v.wall_splits[w]=null),N0(S,T,[E,...k,v.points[(w+k.length+1)%v.points.length]],w)}return!0}function Yf(t,e,n){let r=t.walls??[],o=r.findIndex(f=>f.id===e);if(o<0||Math.abs(n)<.01)return[];let i=r[o],s=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1]),l=t.openings.filter(f=>f.wall===e),a=Math.max(0,...l.map(f=>f.width)),c=Zf(s,n,a);if(!c)return[];let u=ul(i.a,i.b,n,c).map(([f,g])=>[Te(f),Te(g)]);if(!u.length)return[];let d=[i.a,...u,i.b],p=d.slice(1).map((f,g)=>({...i,id:g===0?i.id:I("wall"),a:d[g],b:f}));r.splice(o,1,...p),t.walls=r;let h=dl(d);for(let f of l){let{piece:g,offset:y}=hl(d,f.offset/s*h),b=Math.hypot(d[g+1][0]-d[g][0],d[g+1][1]-d[g][1]);f.wall=p[g].id,f.offset=Te(b>f.width?Math.min(b-f.width/2,Math.max(f.width/2,y)):b/2)}return p.map(f=>f.id)}var Qn=t=>Math.round(t*1e3)/1e3;function Li(t,e,n){return[Math.round((e[0]-t[0])/n)*n,Math.round((e[1]-t[1])/n)*n]}var yn=(t,e)=>e?.01:t,Jn=(t,e,n=5)=>Math.hypot(t[0]-e[0],t[1]-e[1])>=n;function Xf(t,e,n){return n?Math.abs(e[0]-t[0])>Math.abs(e[1]-t[1])?[e[0],t[1]]:[t[0],e[1]]:e}var Qe=(t,e)=>[Qn(t[0]+e[0]),Qn(t[1]+e[1])];function gl(t,e,n,r){return[Qn(Math.round((t[0]+n[0]-e[0])/r)*r),Qn(Math.round((t[1]+n[1]-e[1])/r)*r)]}function _l(t,e,n){let r=Math.atan2(-(e[0]-t[0]),e[1]-t[1])*180/Math.PI;return(Math.round(r/n)*n%360+360)%360}function Qf(t,e,n){let r=Math.atan2(e[0]-t[0],-(e[1]-t[1]))*180/Math.PI;return Math.round(r/n)*n}function Jf(t,e,n){let r=An([...t]),o=t[e],i=[Qn(n[0]),Qn(n[1])];return t.map((s,l)=>l===e?i:r?[Math.abs(s[0]-o[0])<1e-6?i[0]:s[0],Math.abs(s[1]-o[1])<1e-6?i[1]:s[1]]:[s[0],s[1]])}var Ci=t=>Math.round(t*1e3)/1e3,em=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);function B0(t,e,n){let r=null,o=n;for(let i of t){let s=em(i,e);s{let a=i.points[(l+1)%i.points.length],[c,u]=[a[0]-s[0],a[1]-s[1]],d=c*c+u*u;if(d<1e-9)return;let p=((e[0]-s[0])*c+(e[1]-s[1])*u)/d;if(p<=0||p>=1)return;let h=[s[0]+p*c,s[1]+p*u],f=em(h,e),g=(y,b,v)=>Math.min(Math.max(y,Math.min(b,v)),Math.max(b,v));Math.abs(u)<1e-9&&(h[0]=g(Math.round(h[0]/n.grid)*n.grid,s[0],a[0])),Math.abs(c)<1e-9&&(h[1]=g(Math.round(h[1]/n.grid)*n.grid,s[1],a[1])),fi.points.filter((s,l)=>!(e.skip&&i.id===e.skip.roomId&&(e.skip.index===void 0||e.skip.index===l)))),r=B0(n,t,e.reach);if(r)return{point:[r[0],r[1]],guides:{point:r}};let o=W0(e.rooms,t,e);return o?{point:[Ci(o[0]),Ci(o[1])],guides:{point:o}}:V0(n,t,e)}var Ni=(t,e)=>pe(t.host.hass,e);function K0(t,e){let[n,r]=[t.toScreen(e.start),t.toScreen(e.end)];if(e.kind==="freewall"){let s=Math.hypot(e.end[0]-e.start[0],e.end[1]-e.start[1]);return R`
+ `:_}function ul(t,e,n,r=24){let o=Math.hypot(e[0]-t[0],e[1]-t[1]);if(o<1e-6||Math.abs(n)<1e-4)return[];let i=Math.max(-o*2,Math.min(o*2,n)),s=[(e[0]-t[0])/o,(e[1]-t[1])/o],l=[s[1],-s[0]],a=o*o/4/(2*Math.abs(i))+Math.abs(i)/2,c=2*Math.atan(2*Math.abs(i)/o),u=Math.max(2,Math.min(r,Math.ceil(2*c/Math.PI*180/11.25))),d=[l[0]*Math.sign(i),l[1]*Math.sign(i)],p=[(t[0]+e[0])/2,(t[1]+e[1])/2],h=[p[0]-d[0]*(a-Math.abs(i)),p[1]-d[1]*(a-Math.abs(i))],f=[];for(let g=1;gt.reduce((e,n,r)=>r?e+Math.hypot(n[0]-t[r-1][0],n[1]-t[r-1][1]):e,0);function hl(t,e){let n=Math.max(0,e);for(let r=0;r+1Math.round(t*1e3)/1e3,pl=t=>t.map(([e,n])=>[Te(e),Te(n)]);function jf(t,e){return{id:I("room"),name:e,area_id:null,points:pl(t),floor_material:"wood"}}function Gf(t){return{...structuredClone(t),id:I("room"),points:pl(t.points.map(([e,n])=>[e+.5,n+.5]))}}function Uf(t,e){let n=t.rooms.find(r=>r.id===e);t.rooms=t.rooms.filter(r=>r.id!==e),t.openings=t.openings.filter(r=>r.room_id!==e||r.wall),n&&(t.placements=t.placements.filter(r=>!N([r.x,r.z],n.points)))}function Zf(t,e,n){let r=t.rooms.find(s=>s.id===e);if(!r||r.points.length<=3)return!1;let o=(n-1+r.points.length)%r.points.length;r.points.splice(n,1),r.wall_heights?.splice(n,1),r.wall_slopes?.splice(n,1),r.wall_thickness?.splice(n,1);let i=s=>s.room_id===e&&!s.wall;return t.openings=t.openings.filter(s=>!(i(s)&&(s.edge===n||s.edge===o))).map(s=>i(s)&&s.edge>n?{...s,edge:s.edge-1}:s),!0}function qf(t,e,n){if(!Number.isFinite(n))return null;let r=de(t.points),{x0:o,z0:i,x1:s,z1:l}=r;return e==="x"?[o,s]=[n,n+(s-o)]:e==="z"?[i,l]=[n,n+(l-i)]:n>.05&&(e==="w"?s=o+n:l=i+n),pl([[o,i],[s,i],[s,l],[o,l]])}function Yf(t,e,n,r){return!Number.isFinite(r)||e<0||e>=t.points.length?null:t.points.map((o,i)=>i===e?n===0?[Te(r),o[1]]:[o[0],Te(r)]:[o[0],o[1]])}var V0=/^(Raum|Room) \d+$/;function fl(t,e,n,r=!0){let o=e?n[e]:void 0,i=!t.name||V0.test(t.name)||Object.values(n).some(s=>s.name===t.name);return{area_id:e||null,...r&&o&&i?{name:o.name}:{}}}function ml(t,e){let n=/^symcon-category-(\d+)$/.exec(e)?.[1];return(n?t?.symconObjects?.find(r=>r.object_id===Number(n))?.name:void 0)??t?.areas?.[e]?.name.split(" / ").at(-1)?.trim()??""}function Xf(t,e){let n=e.filter(a=>Q(a.entity_id)==="light"&&(a.mount??"ceiling")==="ceiling"&&N([a.x,a.z],t.points));if(n.length<2)return[];let r=de(t.points),[o,i]=[r.x1-r.x0,r.z1-r.z0],s=Math.max(1,Math.round(Math.sqrt(n.length*o/Math.max(.1,i)))),l=Math.ceil(n.length/s);return n.map((a,c)=>{let u=Math.floor(c/s),d=u===l-1?n.length-s*(l-1):s,p=c-u*s;return{entityId:a.entity_id,x:Te(r.x0+o/d*(p+.5)),z:Te(r.z0+i/l*(u+.5))}})}function gl(t,e,n,r){let o=t.rooms.find(u=>u.id===e);if(!o)return;let i=o.points[n],s=o.points[(n+1)%o.points.length];o.points.splice(n+1,0,r);let[l,a]=[o.wall_heights?.[n],o.wall_slopes?.[n]];if(typeof l=="number"&&typeof a=="number"&&o.wall_slopes){let u=Math.hypot(s[0]-i[0],s[1]-i[1]),d=Te(l+(a-l)*Math.min(1,Math.hypot(r[0]-i[0],r[1]-i[1])/(u||1)));o.wall_slopes.splice(n,1,d,a),o.wall_heights.splice(n+1,0,d)}else o.wall_heights?.splice(n+1,0,o.wall_heights[n]??null),o.wall_slopes?.splice(n+1,0,null);o.wall_thickness?.splice(n+1,0,o.wall_thickness[n]??null);let c=Math.hypot(r[0]-i[0],r[1]-i[1]);for(let u of t.openings)u.room_id!==e||u.wall||(u.edge>n?u.edge+=1:u.edge===n&&u.offset>c&&(u.edge=n+1,u.offset=Te(u.offset-c)))}var K0=22.5;function Qf(t,e,n){let r=Math.min(Math.abs(e),t*2),o=t*(1+8/3*(r/Math.max(1e-6,t))**2),i=4*Math.atan(2*r/Math.max(1e-6,t))*180/Math.PI,s=Math.max(2,Math.ceil(i/K0));if(n<=0)return 24;let l=Math.floor(o/(n+.1));return l>=s?l:0}function j0(t,e,n,r){let o=dl(n);t.forEach((i,s)=>{let{piece:l,offset:a}=hl(n,e[s]*o),c=Math.hypot(n[l+1][0]-n[l][0],n[l+1][1]-n[l][1]);i.edge=r+l,i.offset=Te(c>i.width?Math.min(c-i.width/2,Math.max(i.width/2,a)):c/2)})}function Jf(t,e,n,r){let o=t.rooms.find(v=>v.id===e);if(!o||n<0||n>=o.points.length||Math.abs(r)<.01)return!1;let i=o.points[n],s=o.points[(n+1)%o.points.length],l=Math.hypot(s[0]-i[0],s[1]-i[1]);if(l<.2)return!1;let[a,c]=[(s[0]-i[0])/l,(s[1]-i[1])/l],u=[(i[0]+s[0])/2+c*.02,(i[1]+s[1])/2-a*.02],p=N(u,o.points)?-r:r,h=(v,w)=>t.openings.filter(x=>x.room_id===v.id&&!x.wall&&x.edge===w),f=t.rooms.flatMap(v=>v.points.map((w,x)=>{let k=v.points[(x+1)%v.points.length],S=(E,T)=>Math.abs(E[0]-T[0])<.001&&Math.abs(E[1]-T[1])<.001;return S(w,i)&&S(k,s)?[v,x,!1]:S(w,s)&&S(k,i)?[v,x,!0]:null}).filter(w=>!!w)),g=Math.max(0,...f.flatMap(([v,w])=>h(v,w).map(x=>x.width))),y=Qf(l,r,g);if(!y)return!1;let b=ul(i,s,p,y).map(([v,w])=>[Te(v),Te(w)]);if(!b.length)return!1;for(let[v,w,x]of f){let k=x?[...b].reverse():b,S=h(v,w),E=v.points[w],T=S.map(F=>Math.min(1,Math.max(0,F.offset/l)));for(let F of S)F.edge=-1;k.forEach((F,O)=>gl(t,v.id,w+O,F)),v.wall_splits?.splice(w+1,0,...k.map(()=>null)),v.wall_splits?.[w]&&(v.wall_splits[w]=null),j0(S,T,[E,...k,v.points[(w+k.length+1)%v.points.length]],w)}return!0}function em(t,e,n){let r=t.walls??[],o=r.findIndex(f=>f.id===e);if(o<0||Math.abs(n)<.01)return[];let i=r[o],s=Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1]),l=t.openings.filter(f=>f.wall===e),a=Math.max(0,...l.map(f=>f.width)),c=Qf(s,n,a);if(!c)return[];let u=ul(i.a,i.b,n,c).map(([f,g])=>[Te(f),Te(g)]);if(!u.length)return[];let d=[i.a,...u,i.b],p=d.slice(1).map((f,g)=>({...i,id:g===0?i.id:I("wall"),a:d[g],b:f}));r.splice(o,1,...p),t.walls=r;let h=dl(d);for(let f of l){let{piece:g,offset:y}=hl(d,f.offset/s*h),b=Math.hypot(d[g+1][0]-d[g][0],d[g+1][1]-d[g][1]);f.wall=p[g].id,f.offset=Te(b>f.width?Math.min(b-f.width/2,Math.max(f.width/2,y)):b/2)}return p.map(f=>f.id)}var Qn=t=>Math.round(t*1e3)/1e3;function Li(t,e,n){return[Math.round((e[0]-t[0])/n)*n,Math.round((e[1]-t[1])/n)*n]}var yn=(t,e)=>e?.01:t,Jn=(t,e,n=5)=>Math.hypot(t[0]-e[0],t[1]-e[1])>=n;function tm(t,e,n){return n?Math.abs(e[0]-t[0])>Math.abs(e[1]-t[1])?[e[0],t[1]]:[t[0],e[1]]:e}var Qe=(t,e)=>[Qn(t[0]+e[0]),Qn(t[1]+e[1])];function _l(t,e,n,r){return[Qn(Math.round((t[0]+n[0]-e[0])/r)*r),Qn(Math.round((t[1]+n[1]-e[1])/r)*r)]}function bl(t,e,n){let r=Math.atan2(-(e[0]-t[0]),e[1]-t[1])*180/Math.PI;return(Math.round(r/n)*n%360+360)%360}function nm(t,e,n){let r=Math.atan2(e[0]-t[0],-(e[1]-t[1]))*180/Math.PI;return Math.round(r/n)*n}function rm(t,e,n){let r=An([...t]),o=t[e],i=[Qn(n[0]),Qn(n[1])];return t.map((s,l)=>l===e?i:r?[Math.abs(s[0]-o[0])<1e-6?i[0]:s[0],Math.abs(s[1]-o[1])<1e-6?i[1]:s[1]]:[s[0],s[1]])}var Ci=t=>Math.round(t*1e3)/1e3,om=(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]);function G0(t,e,n){let r=null,o=n;for(let i of t){let s=om(i,e);s{let a=i.points[(l+1)%i.points.length],[c,u]=[a[0]-s[0],a[1]-s[1]],d=c*c+u*u;if(d<1e-9)return;let p=((e[0]-s[0])*c+(e[1]-s[1])*u)/d;if(p<=0||p>=1)return;let h=[s[0]+p*c,s[1]+p*u],f=om(h,e),g=(y,b,v)=>Math.min(Math.max(y,Math.min(b,v)),Math.max(b,v));Math.abs(u)<1e-9&&(h[0]=g(Math.round(h[0]/n.grid)*n.grid,s[0],a[0])),Math.abs(c)<1e-9&&(h[1]=g(Math.round(h[1]/n.grid)*n.grid,s[1],a[1])),fi.points.filter((s,l)=>!(e.skip&&i.id===e.skip.roomId&&(e.skip.index===void 0||e.skip.index===l)))),r=G0(n,t,e.reach);if(r)return{point:[r[0],r[1]],guides:{point:r}};let o=U0(e.rooms,t,e);return o?{point:[Ci(o[0]),Ci(o[1])],guides:{point:o}}:Z0(n,t,e)}var Ni=(t,e)=>pe(t.host.hass,e);function q0(t,e){let[n,r]=[t.toScreen(e.start),t.toScreen(e.end)];if(e.kind==="freewall"){let s=Math.hypot(e.end[0]-e.start[0],e.end[1]-e.start[1]);return R`
${Ni(t,s)}
`}let[o,i]=[Math.abs(e.end[0]-e.start[0]),Math.abs(e.end[1]-e.start[1])];return R`
${Ni(t,o)} × ${Ni(t,i)}
- `}function j0(t,e,n,r){let o=[...e,...n?[n]:[]].map(u=>t.toScreen(u)),i=e.length>=3,s=r?e.slice(1).map((u,d)=>{let[p,h]=[t.toScreen(e[d]),t.toScreen(u)];return R`${Ni(t,Math.hypot(u[0]-e[d][0],u[1]-e[d][1]))} `}):_,l=e.map((u,d)=>{let[p,h]=t.toScreen(u),f=d===0&&i;return R` `}),[a,c]=n?t.toScreen(n):[0,0];return R`
+ `}function Y0(t,e,n,r){let o=[...e,...n?[n]:[]].map(u=>t.toScreen(u)),i=e.length>=3,s=r?e.slice(1).map((u,d)=>{let[p,h]=[t.toScreen(e[d]),t.toScreen(u)];return R`${Ni(t,Math.hypot(u[0]-e[d][0],u[1]-e[d][1]))} `}):_,l=e.map((u,d)=>{let[p,h]=t.toScreen(u),f=d===0&&i;return R` `}),[a,c]=n?t.toScreen(n):[0,0];return R`
${o.length>1?R`u.join(",")).join(" ")} />`:_}
${s}${l}
${n?R` `:_}
- `}function nm(t,e,n){let r=e.x!==void 0?t.toScreen([e.x,0])[0]:null,o=e.z!==void 0?t.toScreen([0,e.z])[1]:null,[i,s]=e.point?t.toScreen(e.point):[0,0];return R`
+ `}function sm(t,e,n){let r=e.x!==void 0?t.toScreen([e.x,0])[0]:null,o=e.z!==void 0?t.toScreen([0,e.z])[1]:null,[i,s]=e.point?t.toScreen(e.point):[0,0];return R`
${r!==null?R` `:_}
${o!==null?R` `:_}
${e.point?R` `:_}
- `}function rm(t,e,n,r,o){return e?K0(t,e):n!=="polygon"&&n!=="measure"?_:j0(t,r,o,n==="measure")}var ae=(t,e,n,r,o="")=>R` `,re=(t,e,n,r,o="")=>R` `,im=(t,e="")=>R`n.join(",")).join(" ")} />`,ie=(t,e,n,r="")=>R` `,bl=(t,e,n,r,o="")=>R` `;function yl(t,e,n){let r=[];for(let o=1;o1.2?2:1,i=(e-.2)/o,s=[ae(-e/2,-n/2,e/2,-n/2+.07,"nf-sym-fill"),re(-e/2,-n/2+(n-.1)*.36,e/2,-n/2+(n-.1)*.36)];for(let l=0;lim(a.poly,a.landing?`nf-sym-fill ${i}`:i));o.column>0&&s.push(ie(0,0,o.column,"nf-sym-fill"));let l=o.treads.map(Ti);for(let a=1;a=2){let[a,c]=[l[l.length-2],l[l.length-1]],u=Math.hypot(c[0]-a[0],c[1]-a[1])||1,[d,p]=[(c[0]-a[0])/u,(c[1]-a[1])/u],h=Math.min(.2,o.flight*.3);for(let f of[-1,1])s.push(re(c[0],c[1],c[0]-d*h+p*h*.6*f,c[1]-p*h-d*h*.6*f,"nf-sym-strong"))}return s}function U0(t,e,n){return t.symbol?.length?t.symbol.map(r=>r.shape==="rect"?ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n,r.fill?"nf-sym-fill":""):r.shape==="circle"?ie(r.x*e,r.z*n,r.r*Math.min(e,n)):re(r.x1*e,r.z1*n,r.x2*e,r.z2*n)):Rc(t,e,n,t.size[2]).filter(r=>r.shape==="sweep"||r.w<.98||r.d<.98).map(r=>r.shape==="sweep"&&r.stations?.length?im([...r.stations.map(o=>[(r.x+o[3]/2)*e,o[0]*n]),...[...r.stations].reverse().map(o=>[(r.x-o[3]/2)*e,o[0]*n])]):r.shape==="cyl"&&(r.axis??"y")==="y"?ie(r.x*e,r.z*n,Math.min(r.w*e,r.d*n)/2):ae((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n))}var vl=Math.PI/180,lm=(t,e,n,r)=>{let[o,i]=r,s=R` `,l=R` ${s}`;return t==="data-rotate"?R`${l} `:R`${l} `};function Z0(t,e){let n=e.rotation*vl;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([r,o])=>{let[i,s]=t.toScreen([e.x+r*e.w*Math.cos(n)/2-o*e.d*Math.sin(n)/2,e.z+r*e.w*Math.sin(n)/2+o*e.d*Math.cos(n)/2]);return R` `})}var am=new WeakMap;function q0(t,e){let n=am.get(e);if(n&&n.states===t.states)return n.links;let r=We(t,[e]);return am.set(e,{states:t.states,links:r}),r}function Y0(t,e,n){if(!t||!ce(n.type))return!1;let r=q0(t,e).get(n.id)?.entity;return!!kc(r?t.states[r]:void 0,(n.extra_lights??[]).map(o=>t.states[o]))}function cm(t,e,n){let{host:r,scale:o}=t,i=s=>{let l=s.id===n,a=l&&r.admin&&!s.locked,[c,u]=t.toScreen([s.x,s.z]),d=s.rotation*vl,p=Math.min(s.w,s.d)*o>44,h=Y0(r.hass,e,s),f=Ne.includes(s.type),g=`nf-furn${l?" nf-furn-sel":""}${h?" nf-furn-lit":""}${f?" nf-energy-item":""}`,y=s.d/2+Math.max(.3,26/o),b=t.toScreen([s.x-Math.sin(d)*y,s.z+Math.cos(d)*y]),v=t.toScreen([s.x-Math.sin(d)*(s.d/2),s.z+Math.cos(d)*(s.d/2)]),[w,x]=t.toScreen([s.x+Math.sin(d)*(s.d/2+18/o),s.z-Math.cos(d)*(s.d/2+18/o)]);return R`
+ `}function am(t,e,n,r,o){return e?q0(t,e):n!=="polygon"&&n!=="measure"?_:Y0(t,r,o,n==="measure")}var le=(t,e,n,r,o="")=>R` `,re=(t,e,n,r,o="")=>R` `,cm=(t,e="")=>R`n.join(",")).join(" ")} />`,se=(t,e,n,r="")=>R` `,yl=(t,e,n,r,o="")=>R` `;function vl(t,e,n){let r=[];for(let o=1;o1.2?2:1,i=(e-.2)/o,s=[le(-e/2,-n/2,e/2,-n/2+.07,"nf-sym-fill"),re(-e/2,-n/2+(n-.1)*.36,e/2,-n/2+(n-.1)*.36)];for(let l=0;lcm(a.poly,a.landing?`nf-sym-fill ${i}`:i));o.column>0&&s.push(se(0,0,o.column,"nf-sym-fill"));let l=o.treads.map(Ti);for(let a=1;a=2){let[a,c]=[l[l.length-2],l[l.length-1]],u=Math.hypot(c[0]-a[0],c[1]-a[1])||1,[d,p]=[(c[0]-a[0])/u,(c[1]-a[1])/u],h=Math.min(.2,o.flight*.3);for(let f of[-1,1])s.push(re(c[0],c[1],c[0]-d*h+p*h*.6*f,c[1]-p*h-d*h*.6*f,"nf-sym-strong"))}return s}function Q0(t,e,n){return t.symbol?.length?t.symbol.map(r=>r.shape==="rect"?le((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n,r.fill?"nf-sym-fill":""):r.shape==="circle"?se(r.x*e,r.z*n,r.r*Math.min(e,n)):re(r.x1*e,r.z1*n,r.x2*e,r.z2*n)):Tc(t,e,n,t.size[2]).filter(r=>r.shape==="sweep"||r.w<.98||r.d<.98).map(r=>r.shape==="sweep"&&r.stations?.length?cm([...r.stations.map(o=>[(r.x+o[3]/2)*e,o[0]*n]),...[...r.stations].reverse().map(o=>[(r.x-o[3]/2)*e,o[0]*n])]):r.shape==="cyl"&&(r.axis??"y")==="y"?se(r.x*e,r.z*n,Math.min(r.w*e,r.d*n)/2):le((r.x-r.w/2)*e,(r.z-r.d/2)*n,(r.x+r.w/2)*e,(r.z+r.d/2)*n))}var wl=Math.PI/180,hm=(t,e,n,r)=>{let[o,i]=r,s=R` `,l=R` ${s}`;return t==="data-rotate"?R`${l} `:R`${l} `};function J0(t,e){let n=e.rotation*wl;return[[-1,-1],[1,-1],[1,1],[-1,1]].map(([r,o])=>{let[i,s]=t.toScreen([e.x+r*e.w*Math.cos(n)/2-o*e.d*Math.sin(n)/2,e.z+r*e.w*Math.sin(n)/2+o*e.d*Math.cos(n)/2]);return R` `})}var dm=new WeakMap;function ew(t,e){let n=dm.get(e);if(n&&n.states===t.states)return n.links;let r=We(t,[e]);return dm.set(e,{states:t.states,links:r}),r}function tw(t,e,n){if(!t||!ue(n.type))return!1;let r=ew(t,e).get(n.id)?.entity;return!!Mc(r?t.states[r]:void 0,(n.extra_lights??[]).map(o=>t.states[o]))}function pm(t,e,n){let{host:r,scale:o}=t,i=s=>{let l=s.id===n,a=l&&r.admin&&!s.locked,[c,u]=t.toScreen([s.x,s.z]),d=s.rotation*wl,p=Math.min(s.w,s.d)*o>44,h=tw(r.hass,e,s),f=Ne.includes(s.type),g=`nf-furn${l?" nf-furn-sel":""}${h?" nf-furn-lit":""}${f?" nf-energy-item":""}`,y=s.d/2+Math.max(.3,26/o),b=t.toScreen([s.x-Math.sin(d)*y,s.z+Math.cos(d)*y]),v=t.toScreen([s.x-Math.sin(d)*(s.d/2),s.z+Math.cos(d)*(s.d/2)]),[w,x]=t.toScreen([s.x+Math.sin(d)*(s.d/2+18/o),s.z-Math.cos(d)*(s.d/2+18/o)]);return R`
- ${sm(s.type,s.w,s.d,s)}
+ ${um(s.type,s.w,s.d,s)}
${p?R`${Ye(r.hass,s.type)} `:_}
- ${a?Z0(t,s):_}
+ ${a?J0(t,s):_}
${l?R`${pe(r.hass,s.w)} × ${pe(r.hass,s.d)} `:_}
${l&&s.locked?R`🔒 `:_}
- ${a?lm("data-rotate",s.id,v,b):_}`};return R`${Qp(e).map(i)} `}function um(t,e,n){let{host:r}=t,o=i=>{let s=Q(i.entity_id)??(r.hass?Be(r.hass,i.entity_id):null);if(!s)return _;let[l,a]=t.toScreen([i.x,i.z]),c=r.hass?.states[i.entity_id]?.state==="on",u=i.entity_id===n,d=(i.rotation??0)*vl,p=u&&r.admin&&!i.locked&&_u(i.entity_id,r.hass?.states[i.entity_id]),h=[l-Math.sin(d)*46,a+Math.cos(d)*46],f=On(r,i.entity_id,i.icon);return R`${p?lm("data-aim",i.entity_id,[l,a],h):_}
+ ${a?hm("data-rotate",s.id,v,b):_}`};return R`${nf(e).map(i)} `}function fm(t,e,n){let{host:r}=t,o=i=>{let s=Q(i.entity_id)??(r.hass?Be(r.hass,i.entity_id):null);if(!s)return _;let[l,a]=t.toScreen([i.x,i.z]),c=r.hass?.states[i.entity_id]?.state==="on",u=i.entity_id===n,d=(i.rotation??0)*wl,p=u&&r.admin&&!i.locked&&wu(i.entity_id,r.hass?.states[i.entity_id]),h=[l-Math.sin(d)*46,a+Math.cos(d)*46],f=On(r,i.entity_id,i.icon);return R`${p?hm("data-aim",i.entity_id,[l,a],h):_}
${W(r.hass,i.entity_id)}
${f?R` `:R` `}
- ${u&&i.locked?R`🔒 `:_}`};return R`${e.placements.map(o)} `}function dm(t,e,n){return R`${(e.notes??[]).map(r=>{let[o,i]=t.toScreen([r.x,r.z]);return R`
+ ${u&&i.locked?R`🔒 `:_}`};return R`${e.placements.map(o)} `}function mm(t,e,n){return R`${(e.notes??[]).map(r=>{let[o,i]=t.toScreen([r.x,r.z]);return R`
${r.text}
✎
- `})}`}var Bi=(t,e,n=6)=>R` `;function hm(t,e){let{scale:n}=t,r=n>=90?.1:n>=30?.5:1,o=n>=20?1:5,i=t.toWorld(0,0),s=t.toWorld(e.w,e.h),l=[],a=(d,p)=>{for(let h=Math.ceil(i[0]/d)*d;h<=s[0];h+=d){let f=t.toScreen([h,0])[0];l.push(R` `)}for(let h=Math.ceil(i[1]/d)*d;h<=s[1];h+=d){let f=t.toScreen([0,h])[1];l.push(R` `)}};r `),R`${l} `}function pm(t){let e=t.host.doc.floors,n=e.findIndex(i=>i.id===t.floorId),r=n>0?e[n-1]:void 0;if(!r)return _;let o=lu(e,e[n]);return R`${r.rooms.map(i=>R` `)}${o.map(i=>R` `)} `}function fm(t,e){let n=t.host.floor?.height??2.5;return R`${e.map(r=>{let o=r.height!==void 0&&r.height `})} `}function mm(t,e,n){let r=o=>{let[i,s]=t.toScreen(be(o.points)),l=de(o.points),a=Math.min(l.x1-l.x0,l.z1-l.z0)*t.scale>40;return R`
+ `})}`}var Bi=(t,e,n=6)=>R` `;function gm(t,e){let{scale:n}=t,r=n>=90?.1:n>=30?.5:1,o=n>=20?1:5,i=t.toWorld(0,0),s=t.toWorld(e.w,e.h),l=[],a=(d,p)=>{for(let h=Math.ceil(i[0]/d)*d;h<=s[0];h+=d){let f=t.toScreen([h,0])[0];l.push(R` `)}for(let h=Math.ceil(i[1]/d)*d;h<=s[1];h+=d){let f=t.toScreen([0,h])[1];l.push(R` `)}};r `),R`${l} `}function _m(t){let e=t.host.doc.floors,n=e.findIndex(i=>i.id===t.floorId),r=n>0?e[n-1]:void 0;if(!r)return _;let o=hu(e,e[n]);return R`${r.rooms.map(i=>R` `)}${o.map(i=>R` `)} `}function bm(t,e){let n=t.host.floor?.height??2.5;return R`${e.map(r=>{let o=r.height!==void 0&&r.height `})} `}function ym(t,e,n){let r=o=>{let[i,s]=t.toScreen(be(o.points)),l=de(o.points),a=Math.min(l.x1-l.x0,l.z1-l.z0)*t.scale>40;return R`
${a?R`${t.host.t(`out_${o.type}`)} `:_}
- `};return R`${e.outdoor.map(r)} `}function gm(t,e,n){let{host:r}=t;if(!e||!r.admin||n!=="select"||r.doc.settings.lock_plan)return _;let o=e.points;return R`${o.map((i,s)=>Mi(t,i,o[(s+1)%o.length],"out",e.id,s))}${o.map((i,s)=>R`${Bi(...t.toScreen(i))} `)}`}function _m(t,e,n,r){let o=e.rooms.find(s=>s.id===n),i=o&&r!==null&&r${e.rooms.map(s=>R` `)}
+ `};return R`${e.outdoor.map(r)} `}function vm(t,e,n){let{host:r}=t;if(!e||!r.admin||n!=="select"||r.doc.settings.lock_plan)return _;let o=e.points;return R`${o.map((i,s)=>Mi(t,i,o[(s+1)%o.length],"out",e.id,s))}${o.map((i,s)=>R`${Bi(...t.toScreen(i))} `)}`}function wm(t,e,n,r){let o=e.rooms.find(s=>s.id===n),i=o&&r!==null&&r${e.rooms.map(s=>R` `)}
${i?R` `:_}
${e.rooms.map(s=>{let[l,a]=t.toScreen(be(s.points));return R`${s.name}
- ${Fe(t.host.hass,ke(s.points))} `})} `}function bm(t,e){let n=t.host.doc.energy?.meter;if(!n||n.floor_id!==e.id)return _;let[r,o]=t.toScreen([n.x,n.z]);return R`
+ ${Fe(t.host.hass,ke(s.points))} `})} `}function km(t,e){let n=t.host.doc.energy?.meter;if(!n||n.floor_id!==e.id)return _;let[r,o]=t.toScreen([n.x,n.z]);return R`
- `}function ym(t,e,n){let{host:r}=t,o=i=>{let[s,l]=[t.toScreen(i.a),t.toScreen(i.b)],a=i.id===n,c=a&&r.admin&&!Co(i,!0,r.doc.settings);return R`
+ `}function xm(t,e,n){let{host:r}=t,o=i=>{let[s,l]=[t.toScreen(i.a),t.toScreen(i.b)],a=i.id===n,c=a&&r.admin&&!Co(i,!0,r.doc.settings);return R`
- ${c?R`${Bi(s[0],s[1])} ${Bi(l[0],l[1])} `:_}`};return R`${(e.walls??[]).map(o)} `}function vm(t,e){let n=e.points,r=(e.wall_splits??[]).flatMap((o,i)=>{if(!o||i>=n.length)return[];let[s,l]=[n[i],n[(i+1)%n.length]],a=Math.hypot(l[0]-s[0],l[1]-s[1])||1,[c,u]=[(l[0]-s[0])/a,(l[1]-s[1])/a];return o.map(d=>{let[p,h]=t.toScreen([s[0]+c*d,s[1]+u*d]);return R` `})});return R`${r}`}function wm(t,e,n){let r=e.points,[o,i]=t.toScreen(be(r)),s=(a,c,u)=>{let[[d,p],[h,f]]=[t.toScreen(a),t.toScreen(c)],[g,y]=[(d+h)/2,(p+f)/2],b=Math.hypot(h-d,f-p),[v,w]=[-(f-p),h-d],x=Math.hypot(v,w)||1;return[v,w]=[v/x,w/x],v*(g-o)+w*(y-i)<0&&([v,w]=[-v,-w]),R`${b>50?R`${pe(t.host.hass,Math.hypot(c[0]-a[0],c[1]-a[1]))} `:_}
- ${b>36?R` `:_}`},l=(a,c)=>{let[u,d]=t.toScreen(a);return R`${Bi(u,d)} ${c+1} `};return R`${r.map((a,c)=>s(a,r[(c+1)%r.length],c))}${r.map(l)} `}function km(t,e){let n=e.rooms.flatMap(r=>{if(r.points.length<3)return[];let[o,i]=be(r.points);return r.points.map((s,l)=>{let a=r.points[(l+1)%r.points.length],c=Math.hypot(a[0]-s[0],a[1]-s[1]);if(c<.4)return _;let u=[(s[0]+a[0])/2,(s[1]+a[1])/2],d=Math.hypot(o-u[0],i-u[1])||1,p=Math.min(.35,d/2),h=[u[0]+(o-u[0])/d*p,u[1]+(i-u[1])/d*p],[f,g]=t.toScreen(h),y=Math.atan2(a[1]-s[1],a[0]-s[0])*180/Math.PI;return y>90&&(y-=180),y<-90&&(y+=180),R`${pe(t.host.hass,c)} `})});return R`${n} `}function xm(t,e,n){let r=t.t;return m`
+ ${c?R`${Bi(s[0],s[1])} ${Bi(l[0],l[1])} `:_}`};return R`${(e.walls??[]).map(o)} `}function $m(t,e){let n=e.points,r=(e.wall_splits??[]).flatMap((o,i)=>{if(!o||i>=n.length)return[];let[s,l]=[n[i],n[(i+1)%n.length]],a=Math.hypot(l[0]-s[0],l[1]-s[1])||1,[c,u]=[(l[0]-s[0])/a,(l[1]-s[1])/a];return o.map(d=>{let[p,h]=t.toScreen([s[0]+c*d,s[1]+u*d]);return R` `})});return R`${r}`}function Sm(t,e,n){let r=e.points,[o,i]=t.toScreen(be(r)),s=(a,c,u)=>{let[[d,p],[h,f]]=[t.toScreen(a),t.toScreen(c)],[g,y]=[(d+h)/2,(p+f)/2],b=Math.hypot(h-d,f-p),[v,w]=[-(f-p),h-d],x=Math.hypot(v,w)||1;return[v,w]=[v/x,w/x],v*(g-o)+w*(y-i)<0&&([v,w]=[-v,-w]),R`${b>50?R`${pe(t.host.hass,Math.hypot(c[0]-a[0],c[1]-a[1]))} `:_}
+ ${b>36?R` `:_}`},l=(a,c)=>{let[u,d]=t.toScreen(a);return R`${Bi(u,d)} ${c+1} `};return R`${r.map((a,c)=>s(a,r[(c+1)%r.length],c))}${r.map(l)} `}function Mm(t,e){let n=e.rooms.flatMap(r=>{if(r.points.length<3)return[];let[o,i]=be(r.points);return r.points.map((s,l)=>{let a=r.points[(l+1)%r.points.length],c=Math.hypot(a[0]-s[0],a[1]-s[1]);if(c<.4)return _;let u=[(s[0]+a[0])/2,(s[1]+a[1])/2],d=Math.hypot(o-u[0],i-u[1])||1,p=Math.min(.35,d/2),h=[u[0]+(o-u[0])/d*p,u[1]+(i-u[1])/d*p],[f,g]=t.toScreen(h),y=Math.atan2(a[1]-s[1],a[0]-s[0])*180/Math.PI;return y>90&&(y-=180),y<-90&&(y+=180),R`${pe(t.host.hass,c)} `})});return R`${n} `}function Rm(t,e,n){let r=t.t;return m`
✎ ${r("note")}
- ${Y(m`n.remove()}>${r("delete")} `)}
- `}function X0(t,e,n){let r=t.t,o=!!e.photo?.startsWith("image:"),i=async s=>{let l=s.target,a=l.files?.[0];if(l.value="",!a||!t.hass)return;let{data:c}=await Xn(a),u=I("img");await Lt(t.hass,u,c),n.patch({photo:`image:${u}`})};return m`${t.admin?m`📷 ${r(o?"picture_replace":"note_photo_upload")} `:_}
+ ${X(m`n.remove()}>${r("delete")} `)}
+ `}function nw(t,e,n){let r=t.t,o=!!e.photo?.startsWith("image:"),i=async s=>{let l=s.target,a=l.files?.[0];if(l.value="",!a||!t.hass)return;let{data:c}=await Xn(a),u=I("img");await Lt(t.hass,u,c),n.patch({photo:`image:${u}`})};return m`${t.admin?m`📷 ${r(o?"picture_replace":"note_photo_upload")} `:_}
${o?m`${r("picture_stored")} n.patch({photo:null})}>${r("delete")}
`:V(t,r("picture_url"),e.photo??"",s=>n.patch({photo:s.trim()||null}),{wide:!0,placeholder:"/local/valve.jpg"})}
- ${M(r("note_photo_hint"),"nf-wide")}`}function Q0(t,e,n,r){let o=De(e,n.rooms,n.walls??[]);if(!o)return null;let{room:i,edge:s}=o,l=Ct(r,e,o),a=Nn(i,s,e.offset-e.width/2),c=Nn(i,s,e.offset+e.width/2),u=[(c[0]-a[0])/(e.width||1),(c[1]-a[1])/(e.width||1)],d=_e(i.points)>=0?1:-1,p=[-u[1]*d,u[0]*d],h=[.06,.06];return l&&(h=l.wall.free||l.wall.roomLeft===i.id?[l.wall.left,l.wall.right]:[l.wall.right,l.wall.left]),{room:i,edge:s,p0:a,p1:c,inward:p,direction:d,across:h,exterior:l?.wall.exterior??!1,at:(f,g)=>t.toScreen([f[0]+p[0]*g,f[1]+p[1]*g])}}var xt=(t,e,n="")=>R` `;function J0(t,e){let n=t.across[0]-.04,r=t.across[0]+Math.min(2,e.height),[o,i,s,l]=[t.at(t.p0,n),t.at(t.p1,n),t.at(t.p0,r),t.at(t.p1,r)];return R`${xt(o,i)} `}function ew(t,e,n){let r=n.swing==="out",o=r?-e.across[1]:e.across[0],i=(e.across[0]-e.across[1])/2,s=n.hinge==="left"==e.direction>0,l=Jt(n,e.exterior),a=n.leaves===2,[c,u]=[e.p0,e.p1],d=[],p=cu(n.width,l,s,n);if(p){let v=w=>w<=.02?e.p0:w>=n.width-.02?e.p1:Nn(e.room,e.edge,n.offset-n.width/2+w);[c,u]=[v(p.x0),v(p.x1)],d=p.panels.map(([w,x])=>[v(w),v(x)])}let h=[(c[0]+u[0])/2,(c[1]+u[1])/2],f=(a?.5:1)*Math.hypot(u[0]-c[0],u[1]-c[1]),g=d.map(([v,w])=>R`${xt(e.at(v,i+.035),e.at(w,i+.035),"nf-open-pane")}${xt(e.at(v,i-.035),e.at(w,i-.035),"nf-open-pane")}`),y=(v,w)=>{let[x,k]=e.at(v,o),[S,E]=e.at(w,o),T=e.at(v,o+(r?-f:f)),F=f*t.scale,O=(T[0]-x)*(E-k)-(T[1]-k)*(S-x)>0?1:0;return R` `},b;return l==="passage"?b=xt(e.at(e.p0,i),e.at(e.p1,i),"nf-open-passage"):l==="sliding"?b=xt(e.at(c,o),e.at(u,o)):a?b=R`${y(c,h)}${y(u,h)}`:b=s?y(c,u):y(u,c),R`${g}${b}`}function tw(t,e){let n=(t.across[0]-t.across[1])/2;if(e.opens==="slide"){let o=e.leaves===2?4:2,i=l=>[t.p0[0]+(t.p1[0]-t.p0[0])*l,t.p0[1]+(t.p1[1]-t.p0[1])*l],s=Array.from({length:o},(l,a)=>{let c=e.leaves===2?a===1||a===2?.035:-.035:a===0?.035:-.035;return xt(t.at(i(Math.max(0,a/o-.03)),n+c),t.at(i(Math.min(1,(a+1)/o+.03)),n+c))});return R`${s}`}let r=e.leaves===2?xt(t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],t.across[0]),t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],-t.across[1])):_;return R`${xt(t.at(t.p0,n+.035),t.at(t.p1,n+.035))}${xt(t.at(t.p0,n-.035),t.at(t.p1,n-.035))}${r}`}function $m(t,e,n,r){let o=e.openings.find(s=>s.id===r)?.front??null,i=s=>{let l=Q0(t,s,e,n);if(!l)return _;let a=[l.at(l.p0,l.across[0]+.01),l.at(l.p1,l.across[0]+.01),l.at(l.p1,-l.across[1]-.01),l.at(l.p0,-l.across[1]-.01)],c=s.type==="door"&&Es(Jt(s,l.exterior)),u=s.id===r||!!s.front&&s.front===o,d=`nf-open nf-open-${s.type}${c?" nf-open-front":""}${u?" nf-open-sel":""}`,p=s.type==="garage"?J0(l,s):s.type==="door"?ew(t,l,s):tw(l,s);return R`h.join(",")).join(" ")} />${p} `};return R`${e.openings.map(i)} `}var Sm=t=>Math.round(t*1e3)/1e3,Mm=t=>Math.round(t*100)/100;function er(t,e){let n=[...t??[]].slice(0,e);for(;n.lengtht.every(e=>e===null);function go(t,e){let[n,r]=[t.points[e],t.points[(e+1)%t.points.length]];return Math.hypot(r[0]-n[0],r[1]-n[1])}function wl(t,e,n){let r=er(t.wall_heights,t.points.length);r[e]=n,t.wall_heights=Wi(r)?void 0:r,Vi(t,e,null)}function Vi(t,e,n){if(n===null&&!t.wall_slopes)return;let r=er(t.wall_slopes,t.points.length);r[e]=n,t.wall_slopes=Wi(r)?void 0:r}function Rm(t,e,n,r){let[o,i]=[n,r].map(l=>Math.min(30,Math.max(.05,Sm(l)))),s=er(t.wall_heights,t.points.length);s[e]=o,t.wall_heights=s,Vi(t,e,i)}function Em(t,e,n){let r=t.wall_heights?.[e];Vi(t,e,null),typeof r=="number"&&r>=n-.005&&wl(t,e,null)}function Am(t,e,n,r,o){let i=er(t.wall_heights,t.points.length),s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l,t.wall_heights=Wi(i)?void 0:i,Vi(t,e,null)}function Fm(t,e,n,r){let o=go(t,e),i=n===void 0?0:r[n],s=n===void 0?o:r[n+1]??o;if(s-i<.4)return!1;let l=Mm((i+s)/2),a=er(t.wall_splits,t.points.length);a[e]=[...a[e]??[],l].sort((u,d)=>u-d),t.wall_splits=a;let c=t.wall_heights?.[e];return Array.isArray(c)&&c.splice((n??0)+1,0,c[n??0]??null),!0}function Tm(t,e,n,r,o){let i=go(t,e),s=o.filter(u=>Math.abs(u-n)>.001&&u>0),l=Math.max(.1,Math.min(i-.1,Mm(r)));s.some(u=>Math.abs(u-l)<.1)&&(l=n);let a=t.wall_splits?.[e];if(!a)return;let c=a.findIndex(u=>Math.abs(u-n)<.001);c>=0&&(a[c]=l),a.sort((u,d)=>u-d)}function zm(t,e,n,r){let o=t.wall_splits;if(!o?.[e])return;let i=o[e].filter(l=>Math.abs(l-n)>.001);o[e]=i.length>0?i:null,o.every(l=>!l)&&(t.wall_splits=void 0);let s=t.wall_heights?.[e];Array.isArray(s)&&(s.splice(r,1),s.every(l=>l===s[0])&&(t.wall_heights[e]=s[0]??null))}function Pm(t,e,n,r,o=1){let i=er(t.wall_thickness,t.points.length);if(r===void 0||o<2)i[e]=n;else{let s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l}t.wall_thickness=Wi(i)?void 0:i}function Im(t,e){let n=Math.min(1.5,Math.max(.02,Sm(t)));return Math.abs(n-e)<5e-4?null:n}var Dm=.005,Om=(t,e)=>`room:${t.id}:${e}`;function Hm(t,e,n){let r=t.t,o=e.ceiling??t.floor.height,i=e.points.length,{wall_exterior:s,wall_interior:l}=t.doc.settings,a=c=>{let u=e.wall_heights?.[c]??null,d=n.partsOf(e,c);return(d.length>1?d.map((h,f)=>f):[void 0]).map(h=>{let f=Array.isArray(u)?u[h??0]??null:u,g=e.wall_thickness?.[c]??null,y=Array.isArray(g)?g[h??0]??null:g,b=h===void 0?go(e,c):(d[h+1]??go(e,c))-d[h],v=P=>n.setHeight(e,c,h,P),w=n.isOuter(e,c)?s:l,x=`${r("wall_n",{a:c+1,b:(c+1)%i+1})}${h===void 0?"":` \xB7 ${r("wall_part",{n:h+1})}`}`,k=h!==void 0&&h>0&&(e.wall_splits?.[c]??[]).some(P=>Math.abs(P-d[h])<.001),S=e.wall_slopes?.[c],E=h===void 0&&typeof S=="number"&&typeof u=="number",T=f??o,F=()=>n.light(c),O=()=>n.light(null);return m`
+ ${M(r("note_photo_hint"),"nf-wide")}`}function rw(t,e,n,r){let o=De(e,n.rooms,n.walls??[]);if(!o)return null;let{room:i,edge:s}=o,l=Ct(r,e,o),a=Nn(i,s,e.offset-e.width/2),c=Nn(i,s,e.offset+e.width/2),u=[(c[0]-a[0])/(e.width||1),(c[1]-a[1])/(e.width||1)],d=_e(i.points)>=0?1:-1,p=[-u[1]*d,u[0]*d],h=[.06,.06];return l&&(h=l.wall.free||l.wall.roomLeft===i.id?[l.wall.left,l.wall.right]:[l.wall.right,l.wall.left]),{room:i,edge:s,p0:a,p1:c,inward:p,direction:d,across:h,exterior:l?.wall.exterior??!1,at:(f,g)=>t.toScreen([f[0]+p[0]*g,f[1]+p[1]*g])}}var xt=(t,e,n="")=>R`
`;function ow(t,e){let n=t.across[0]-.04,r=t.across[0]+Math.min(2,e.height),[o,i,s,l]=[t.at(t.p0,n),t.at(t.p1,n),t.at(t.p0,r),t.at(t.p1,r)];return R`${xt(o,i)}
`}function iw(t,e,n){let r=n.swing==="out",o=r?-e.across[1]:e.across[0],i=(e.across[0]-e.across[1])/2,s=n.hinge==="left"==e.direction>0,l=Jt(n,e.exterior),a=n.leaves===2,[c,u]=[e.p0,e.p1],d=[],p=pu(n.width,l,s,n);if(p){let v=w=>w<=.02?e.p0:w>=n.width-.02?e.p1:Nn(e.room,e.edge,n.offset-n.width/2+w);[c,u]=[v(p.x0),v(p.x1)],d=p.panels.map(([w,x])=>[v(w),v(x)])}let h=[(c[0]+u[0])/2,(c[1]+u[1])/2],f=(a?.5:1)*Math.hypot(u[0]-c[0],u[1]-c[1]),g=d.map(([v,w])=>R`${xt(e.at(v,i+.035),e.at(w,i+.035),"nf-open-pane")}${xt(e.at(v,i-.035),e.at(w,i-.035),"nf-open-pane")}`),y=(v,w)=>{let[x,k]=e.at(v,o),[S,E]=e.at(w,o),T=e.at(v,o+(r?-f:f)),F=f*t.scale,O=(T[0]-x)*(E-k)-(T[1]-k)*(S-x)>0?1:0;return R`
`},b;return l==="passage"?b=xt(e.at(e.p0,i),e.at(e.p1,i),"nf-open-passage"):l==="sliding"?b=xt(e.at(c,o),e.at(u,o)):a?b=R`${y(c,h)}${y(u,h)}`:b=s?y(c,u):y(u,c),R`${g}${b}`}function sw(t,e){let n=(t.across[0]-t.across[1])/2;if(e.opens==="slide"){let o=e.leaves===2?4:2,i=l=>[t.p0[0]+(t.p1[0]-t.p0[0])*l,t.p0[1]+(t.p1[1]-t.p0[1])*l],s=Array.from({length:o},(l,a)=>{let c=e.leaves===2?a===1||a===2?.035:-.035:a===0?.035:-.035;return xt(t.at(i(Math.max(0,a/o-.03)),n+c),t.at(i(Math.min(1,(a+1)/o+.03)),n+c))});return R`${s}`}let r=e.leaves===2?xt(t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],t.across[0]),t.at([(t.p0[0]+t.p1[0])/2,(t.p0[1]+t.p1[1])/2],-t.across[1])):_;return R`${xt(t.at(t.p0,n+.035),t.at(t.p1,n+.035))}${xt(t.at(t.p0,n-.035),t.at(t.p1,n-.035))}${r}`}function Em(t,e,n,r){let o=e.openings.find(s=>s.id===r)?.front??null,i=s=>{let l=rw(t,s,e,n);if(!l)return _;let a=[l.at(l.p0,l.across[0]+.01),l.at(l.p1,l.across[0]+.01),l.at(l.p1,-l.across[1]-.01),l.at(l.p0,-l.across[1]-.01)],c=s.type==="door"&&Es(Jt(s,l.exterior)),u=s.id===r||!!s.front&&s.front===o,d=`nf-open nf-open-${s.type}${c?" nf-open-front":""}${u?" nf-open-sel":""}`,p=s.type==="garage"?ow(l,s):s.type==="door"?iw(t,l,s):sw(l,s);return R`
h.join(",")).join(" ")} />${p} `};return R`
${e.openings.map(i)} `}var Am=t=>Math.round(t*1e3)/1e3,Fm=t=>Math.round(t*100)/100;function er(t,e){let n=[...t??[]].slice(0,e);for(;n.length
t.every(e=>e===null);function _o(t,e){let[n,r]=[t.points[e],t.points[(e+1)%t.points.length]];return Math.hypot(r[0]-n[0],r[1]-n[1])}function kl(t,e,n){let r=er(t.wall_heights,t.points.length);r[e]=n,t.wall_heights=Wi(r)?void 0:r,Vi(t,e,null)}function Vi(t,e,n){if(n===null&&!t.wall_slopes)return;let r=er(t.wall_slopes,t.points.length);r[e]=n,t.wall_slopes=Wi(r)?void 0:r}function Tm(t,e,n,r){let[o,i]=[n,r].map(l=>Math.min(30,Math.max(.05,Am(l)))),s=er(t.wall_heights,t.points.length);s[e]=o,t.wall_heights=s,Vi(t,e,i)}function zm(t,e,n){let r=t.wall_heights?.[e];Vi(t,e,null),typeof r=="number"&&r>=n-.005&&kl(t,e,null)}function Pm(t,e,n,r,o){let i=er(t.wall_heights,t.points.length),s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l,t.wall_heights=Wi(i)?void 0:i,Vi(t,e,null)}function Im(t,e,n,r){let o=_o(t,e),i=n===void 0?0:r[n],s=n===void 0?o:r[n+1]??o;if(s-i<.4)return!1;let l=Fm((i+s)/2),a=er(t.wall_splits,t.points.length);a[e]=[...a[e]??[],l].sort((u,d)=>u-d),t.wall_splits=a;let c=t.wall_heights?.[e];return Array.isArray(c)&&c.splice((n??0)+1,0,c[n??0]??null),!0}function Dm(t,e,n,r,o){let i=_o(t,e),s=o.filter(u=>Math.abs(u-n)>.001&&u>0),l=Math.max(.1,Math.min(i-.1,Fm(r)));s.some(u=>Math.abs(u-l)<.1)&&(l=n);let a=t.wall_splits?.[e];if(!a)return;let c=a.findIndex(u=>Math.abs(u-n)<.001);c>=0&&(a[c]=l),a.sort((u,d)=>u-d)}function Om(t,e,n,r){let o=t.wall_splits;if(!o?.[e])return;let i=o[e].filter(l=>Math.abs(l-n)>.001);o[e]=i.length>0?i:null,o.every(l=>!l)&&(t.wall_splits=void 0);let s=t.wall_heights?.[e];Array.isArray(s)&&(s.splice(r,1),s.every(l=>l===s[0])&&(t.wall_heights[e]=s[0]??null))}function Hm(t,e,n,r,o=1){let i=er(t.wall_thickness,t.points.length);if(r===void 0||o<2)i[e]=n;else{let s=i[e],l=Array.isArray(s)?[...s]:new Array(o).fill(typeof s=="number"?s:null);for(;l.lengtha===l[0])?l[0]:l}t.wall_thickness=Wi(i)?void 0:i}function Lm(t,e){let n=Math.min(1.5,Math.max(.02,Am(t)));return Math.abs(n-e)<5e-4?null:n}var Cm=.005,Nm=(t,e)=>`room:${t.id}:${e}`;function Bm(t,e,n){let r=t.t,o=e.ceiling??t.floor.height,i=e.points.length,{wall_exterior:s,wall_interior:l}=t.doc.settings,a=c=>{let u=e.wall_heights?.[c]??null,d=n.partsOf(e,c);return(d.length>1?d.map((h,f)=>f):[void 0]).map(h=>{let f=Array.isArray(u)?u[h??0]??null:u,g=e.wall_thickness?.[c]??null,y=Array.isArray(g)?g[h??0]??null:g,b=h===void 0?_o(e,c):(d[h+1]??_o(e,c))-d[h],v=P=>n.setHeight(e,c,h,P),w=n.isOuter(e,c)?s:l,x=`${r("wall_n",{a:c+1,b:(c+1)%i+1})}${h===void 0?"":` \xB7 ${r("wall_part",{n:h+1})}`}`,k=h!==void 0&&h>0&&(e.wall_splits?.[c]??[]).some(P=>Math.abs(P-d[h])<.001),S=e.wall_slopes?.[c],E=h===void 0&&typeof S=="number"&&typeof u=="number",T=f??o,F=()=>n.light(c),O=()=>n.light(null);return m`
${x} ${pe(t.hass,b)}
${f===0?m`
${r("wall_none")} `:E?m`
${A(t,r("wall_slope_start"),u,P=>n.setSlope(e,c,P,S),.05,.05)}
${A(t,r("wall_slope_end"),S,P=>n.setSlope(e,c,u,P),.05,.05)} `:A(t,r("wall_height"),T,P=>v(P>=o-Dm?null:Math.max(.05,P)),.05,.05)}
+ >`:A(t,r("wall_height"),T,P=>v(P>=o-Cm?null:Math.max(.05,P)),.05,.05)}
${t.admin&&E?m`
n.clearSlope(e,c)}>▭ `:_}
${t.admin&&f!==null&&!E?m`
v(null)}>↥ `:_}
- ${t.admin&&h===void 0&&f!==0&&!E?m`
n.setSlope(e,c,T,T>=o-Dm?T+1:o)}>∠ ${r("wall_slope")} `:_}
+ ${t.admin&&h===void 0&&f!==0&&!E?m`
n.setSlope(e,c,T,T>=o-Cm?T+1:o)}>∠ ${r("wall_slope")} `:_}
${t.admin&&f!==0?m`
v(0)}>${r("wall_none")} `:_}
${t.admin&&b>=.4?m`
n.cut(e,c,h)}>✂ `:_}
- ${h===void 0&&b>=.4?zi(t,Om(e,c),n.arc):_}
+ ${h===void 0&&b>=.4?zi(t,Nm(e,c),n.arc):_}
${(h===void 0||h===0)&&f!==0?m`
n.openWall(e,c)}>▣ ${r("wall_view")} `:_}
${f!==0?m`
${A(t,r("edge_thickness"),y??w,P=>n.setThickness(e,c,Im(P,w),h,d.length),.01,.02)}
+ >${A(t,r("edge_thickness"),y??w,P=>n.setThickness(e,c,Lm(P,w),h,d.length),.01,.02)}
${t.admin&&y!=null?m`n.setThickness(e,c,null,h,d.length)}>↺ `:_} `:_}
- ${h===void 0?Pi(t,Om(e,c),n.arc):_}
+ ${h===void 0?Pi(t,Nm(e,c),n.arc):_}
${k?m`
${A(t,r("wall_split_at"),d[h],P=>n.moveCut(e,c,d[h],P),.05,.1)}
${t.admin?m`n.join(e,c,d[h],h)}>⨉ `:_} `})};return m`
${r("wall_heights")}
${e.points.flatMap((c,u)=>a(u))} ${M(r("room_wall_hint"))}
- `}function Lm(t){let e=t?.attributes;return{temperature:"\u{1F321}",humidity:"\u{1F4A7}",carbon_dioxide:"\u2601",illuminance:"\u2600",power:"\u26A1",energy:"\u26A1"}[String(e?.device_class)]??(e?.unit_of_measurement==="\xB0C"?"\u{1F321}":"\u25C9")}function Ki(t,e=[],n){let r=H(t.hass,i=>!t.hass?.states[i]?.attributes.symcon_source_entity||e.some(s=>s.entity===i)),o=(i,s)=>n(e.map(l=>l.id===i?{...l,...s}:l));return m`
+ `}function Wm(t){let e=t?.attributes;return{temperature:"\u{1F321}",humidity:"\u{1F4A7}",carbon_dioxide:"\u2601",illuminance:"\u2600",power:"\u26A1",energy:"\u26A1"}[String(e?.device_class)]??(e?.unit_of_measurement==="\xB0C"?"\u{1F321}":"\u25C9")}function Ki(t,e=[],n){let r=H(t.hass,i=>!t.hass?.states[i]?.attributes.symcon_source_entity||e.some(s=>s.entity===i)),o=(i,s)=>n(e.map(l=>l.id===i?{...l,...s}:l));return m`
${t.t("device_values")} n([...e,{id:I("value"),entity:null}])}>+
${e.map((i,s)=>m`
${z(t,`${t.t("device_value")} ${s+1}`,i.entity,void 0,r,l=>o(i.id,{entity:l==="none"?null:l}))}
- ${V(t,t.t("device_value_icon"),i.icon??"",l=>o(i.id,{icon:l||null}),{maxlength:16,placeholder:Lm(i.entity?t.hass?.states[i.entity]:void 0)})}
+ ${V(t,t.t("device_value_icon"),i.icon??"",l=>o(i.id,{icon:l||null}),{maxlength:16,placeholder:Wm(i.entity?t.hass?.states[i.entity]:void 0)})}
${V(t,t.t("device_value_label"),i.label??"",l=>o(i.id,{label:l||null}),{maxlength:60})}
{let l=e.filter(a=>a.id!==i.id);n(l.length?l:void 0)}}>× ${t.t("device_value_remove")}
`)}
${M(t.t("device_values_hint"))}
-
`}function Cm(t,e,n){let r=e.color_entity&&e.color_entity!=="none"?e.color_entity:n;return r?t.states[r]:void 0}var kl=["none","rainbow","pulse","flicker"];function ji(t,e,n,r){let o=e.effect_animations??{},i=pu(),s=c=>kl.includes(c)||i.includes(c),l=[...new Set([...Object.keys(o),...Array.isArray(n)?n.filter(c=>typeof c=="string"):[]])],a=(c,u,d,p=!1)=>{let h=Object.prototype.hasOwnProperty.call(o,c),f=Array.from(c).length,g=p&&h?"light_effect_exists":u!==""&&(f<1||f>255)?"light_effect_name_limit":u!==""&&!h&&Object.keys(o).length>=100?"light_effect_count_limit":void 0;if(d.setCustomValidity?.(g?t.t(g):""),g){let b=d.closest?.("details")?.querySelector("[data-effect-feedback]");return b&&(b.textContent=t.t(g)),d.reportValidity?.(),p||(d.value=h?o[c]:""),!1}let y={...o};return u===""?delete y[c]:Object.defineProperty(y,c,{value:u,enumerable:!0,configurable:!0,writable:!0}),r({effect_animations:y}),!0};return m`
+ `}function Vm(t,e,n){let r=e.color_entity&&e.color_entity!=="none"?e.color_entity:n;return r?t.states[r]:void 0}var xl=["none","rainbow","pulse","flicker"];function ji(t,e,n,r){let o=e.effect_animations??{},i=_u(),s=c=>xl.includes(c)||i.includes(c),l=[...new Set([...Object.keys(o),...Array.isArray(n)?n.filter(c=>typeof c=="string"):[]])],a=(c,u,d,p=!1)=>{let h=Object.prototype.hasOwnProperty.call(o,c),f=Array.from(c).length,g=p&&h?"light_effect_exists":u!==""&&(f<1||f>255)?"light_effect_name_limit":u!==""&&!h&&Object.keys(o).length>=100?"light_effect_count_limit":void 0;if(d.setCustomValidity?.(g?t.t(g):""),g){let b=d.closest?.("details")?.querySelector("[data-effect-feedback]");return b&&(b.textContent=t.t(g)),d.reportValidity?.(),p||(d.value=h?o[c]:""),!1}let y={...o};return u===""?delete y[c]:Object.defineProperty(y,c,{value:u,enumerable:!0,configurable:!0,writable:!0}),r({effect_animations:y}),!0};return m`
${t.t("light_effects")}
${M(t.t("light_effects_hint"))}
{let d=u.target;a(c,d.value,d)}}>
${t.t("light_effect_unmapped")}
${Object.prototype.hasOwnProperty.call(o,c)&&!s(o[c])?m`${o[c]} (${t.t("light_effect_unmapped")}) `:_}
- ${kl.map(u=>m`${t.t(`light_animation_${u}`)} `)}
+ ${xl.map(u=>m`${t.t(`light_animation_${u}`)} `)}
${i.map(u=>m`${u} (${t.t("plugin")}) `)}
`)}
${t.t("light_effect_add")} {let u=c.target;a(u.value,"none",u,!0)&&(u.value="")}} />
${M(`${t.t("light_effect_name_limit")} ${t.t("light_effect_count_limit")}`)}
- `}var nw=/speaker|sound|subwoofer|receiver|smart_|display|tv|media|turntable|projector|console/;function rw(t,e,n){let r=Q(e),o=t.hass?.language??"en",i=[...Wo.map(l=>({type:l,label:t.t(`furn_${l}`)})),...n.flatMap(l=>l.items.map(a=>({type:he(l.id,a.id),label:`${Xe(a,he(l.id,a.id),o)} \xB7 ${He(l,o)}`})))],s=l=>r==="light"?ce(l):r==="climate"?l==="radiator"||$n(l):e.startsWith("vacuum.")?l==="robot_vacuum"||yt(l)&&l.endsWith(":robot_vacuum"):r==="media"?Mr(l)||Et(l)&&nw.test(l):Et(l)&&!ce(l);return i.filter(l=>s(l.type)).sort((l,a)=>l.label.localeCompare(a.label))}function ow(t,e,n){if(!t.admin)return _;let r=rw(t,e.entity_id,n.packs);return r.length===0?_:m`
`}var aw=/speaker|sound|subwoofer|receiver|smart_|display|tv|media|turntable|projector|console/;function lw(t,e,n){let r=Q(e),o=t.hass?.language??"en",i=[...Wo.map(l=>({type:l,label:t.t(`furn_${l}`)})),...n.flatMap(l=>l.items.map(a=>({type:he(l.id,a.id),label:`${Xe(a,he(l.id,a.id),o)} \xB7 ${He(l,o)}`})))],s=l=>r==="light"?ue(l):r==="climate"?l==="radiator"||$n(l):e.startsWith("vacuum.")?l==="robot_vacuum"||yt(l)&&l.endsWith(":robot_vacuum"):r==="media"?Rr(l)||Et(l)&&aw.test(l):Et(l)&&!ue(l);return i.filter(l=>s(l.type)).sort((l,a)=>l.label.localeCompare(a.label))}function cw(t,e,n){if(!t.admin)return _;let r=lw(t,e.entity_id,n.packs);return r.length===0?_:m`${t.t("as_furniture")}
o.target.value&&n.asFurniture(e,o.target.value)}>
${t.t("as_furniture_pick")}
${r.map(o=>m`${o.label} `)}
- `}function iw(t,e,n){let r=t.hass?.language??"en";return mu(e.entity_id,t.hass?.states[e.entity_id]).map(({pluginId:o,name:i,settings:s})=>{let l=gu(s,e.plugin?.[o]),a=(u,d)=>n({plugin:{...e.plugin??{},[o]:{...e.plugin?.[o]??{},[u]:d}}}),c=s.map(u=>{let d=qo(u.label,r),p=u.hint?qo(u.hint,r):void 0;if(u.type==="boolean")return D(t,d,l[u.key]===!0,f=>a(u.key,f),{title:p});if(u.type==="select"){let f=(u.options??[]).map(([g,y])=>[g,qo(y,r)]);return L(t,d,String(l[u.key]),f,g=>a(u.key,g),{wide:!0,title:p})}let h=f=>Math.min(u.max??1/0,Math.max(u.min??-1/0,f));return A(t,d,Number(l[u.key]),f=>a(u.key,h(f)),u.step??1,u.min)});return m`🔌 ${i} ${c}`})}function xl(t,e,n){let r=t.t,o=Q(e.entity_id)??(t.hass?Be(t.hass,e.entity_id):null),i=o==="light",s=e.mount??"ceiling",l=o?Io(o,t.floor?dt(t.floor,e.x,e.z):2.5,i?s:null):1,a=p=>n.update(p),c=On(t,e.entity_id,e.icon),u=p=>a({mount:p,y:null}),d=["ceiling","floor","table","wall"].map(p=>[p,r(`lamp_${p}`)]);return m` `}function uw(t,e,n){let r=t.hass?.language??"en";return yu(e.entity_id,t.hass?.states[e.entity_id]).map(({pluginId:o,name:i,settings:s})=>{let l=vu(s,e.plugin?.[o]),a=(u,d)=>n({plugin:{...e.plugin??{},[o]:{...e.plugin?.[o]??{},[u]:d}}}),c=s.map(u=>{let d=qo(u.label,r),p=u.hint?qo(u.hint,r):void 0;if(u.type==="boolean")return D(t,d,l[u.key]===!0,f=>a(u.key,f),{title:p});if(u.type==="select"){let f=(u.options??[]).map(([g,y])=>[g,qo(y,r)]);return L(t,d,String(l[u.key]),f,g=>a(u.key,g),{wide:!0,title:p})}let h=f=>Math.min(u.max??1/0,Math.max(u.min??-1/0,f));return A(t,d,Number(l[u.key]),f=>a(u.key,h(f)),u.step??1,u.min)});return m`
🔌 ${i} ${c}`})}function $l(t,e,n){let r=t.t,o=Q(e.entity_id)??(t.hass?Be(t.hass,e.entity_id):null),i=o==="light",s=e.mount??"ceiling",l=o?Io(o,t.floor?dt(t.floor,e.x,e.z):2.5,i?s:null):1,a=p=>n.update(p),c=On(t,e.entity_id,e.icon),u=p=>a({mount:p,y:null}),d=["ceiling","floor","table","wall"].map(p=>[p,r(`lamp_${p}`)]);return m`
${r("device")} ${n.lockButton}
${c?m` `:m` `}
@@ -1419,87 +1419,87 @@ ${i}`}else o=xh(s)}}catch(s){let l=s.message,a={not_json:"import_error_not_json"
${A(t,r("marker_height"),e.y??l,p=>a({y:Math.max(0,p)}),.05,0)}
${A(t,r("rotation"),e.rotation??0,p=>a({rotation:(p%360+360)%360}),1)}
${i?D(t,r("device_simple"),!!e.simple,p=>a({simple:p||void 0}),{title:r("device_simple_hint")}):_}
- ${o&&yc.has(o)?D(t,r("device_confirm"),!!e.confirm,p=>a({confirm:p}),{title:r("device_confirm_hint")}):_}
+ ${o&&xc.has(o)?D(t,r("device_confirm"),!!e.confirm,p=>a({confirm:p}),{title:r("device_confirm_hint")}):_}
${D(t,r("device_outside"),!!e.outside,p=>a({outside:p||void 0}),{title:r("device_outside_hint")})}
${Hn(t,e.marker??null,p=>a({marker:p}))}
${Ln(t,e.pin_offset,p=>a({pin_offset:p}))}
${V(t,r("device_name"),e.name??"",p=>a({name:p||null}),{wide:!0,maxlength:60,title:r("device_name_hint"),placeholder:W(t.hass,e.entity_id)})}
${e.name?D(t,r("show_name"),!!e.show_name,p=>a({show_name:p||void 0})):_}
${Ht(t,e.icon,p=>a({icon:p}))}
- ${iw(t,e,a)}
+ ${uw(t,e,a)}
${Ki(t,e.values,p=>a({values:p}))}
${t.admin?m`
n.centre()}>${r("device_centre")}
${e.y!==null?m`a({y:null})}>${r("height_auto")} `:_}
- ${ow(t,e,n)}
+ ${cw(t,e,n)}
n.remove()}>${r("devices_remove")}
`:_}
- `}var _o=t=>Number(t);function Gi(t){if(Array.isArray(t)){let[i,s]=[_o(t[0]),_o(t[1])];return Number.isFinite(i)&&Number.isFinite(s)?[i,s]:null}if(!t||typeof t!="object")return null;let{x:e,y:n}=t,[r,o]=[_o(e),_o(n)];return Number.isFinite(r)&&Number.isFinite(o)?[r,o]:null}function Wm(t){return t?Gi(t.charger)??Gi(t.charger_position):null}function Ui(t){for(let[e,n]of Object.entries(t.states))if(e.startsWith("camera.")&&(Gi(n.attributes?.vacuum_position)??Wm(n.attributes)))return e;return null}var $l=(t,e)=>e?[t[0],-t[1]]:t;var Vm=5e-4,Km=2,sw=1.5;function Sl(t,e){let n=e?t.states[e]?.attributes:void 0;return{at:n?Gi(n.vacuum_position):null,dock:Wm(n)}}function jm(t,e,n=!1){let r=Math.hypot(e.plan[0]-t.plan[0],e.plan[1]-t.plan[1]),o=Math.hypot(e.grid[0]-t.grid[0],e.grid[1]-t.grid[1]);if(!(o>1e-6)||!(r>=sw))return{cal:null,reason:"close"};let i=r/o;return i>=Vm&&i<=Km?{cal:{a:t.plan,ga:t.grid,b:e.plan,gb:e.grid,mirror:n}}:{cal:null,reason:"scale"}}function Gm(t,e){let n=e?t.states[e]?.attributes?.rooms:void 0;if(!n||typeof n!="object")return[];let r=[];for(let o of Object.values(n)){if(!o||typeof o!="object")continue;let i=o,s=typeof i.name=="string"?i.name.trim():"",l=[i.x0,i.y0,i.x1,i.y1].map(_o);!s||!l.every(Number.isFinite)||r.push({name:s,center:[(l[0]+l[2])/2,(l[1]+l[3])/2]})}return r}var Nm=t=>t.toLocaleLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^\p{L}\p{N}]+/gu,"");function aw(t){let e=t.length,[n,r]=t.reduce((h,f)=>[h[0]+f.seen[0]/e,h[1]+f.seen[1]/e],[0,0]),[o,i]=t.reduce((h,f)=>[h[0]+f.plan[0]/e,h[1]+f.plan[1]/e],[0,0]),[s,l,a]=[0,0,0];for(let h of t){let[f,g]=[h.seen[0]-n,h.seen[1]-r],[y,b]=[h.plan[0]-o,h.plan[1]-i];s+=f*y+g*b,l+=f*b-g*y,a+=f*f+g*g}if(!(a>1e-9))return null;let[c,u]=[s/a,l/a],d=h=>{let[f,g]=[h[0]-n,h[1]-r];return[o+c*f-u*g,i+u*f+c*g]},p=Math.sqrt(t.reduce((h,f)=>h+Math.hypot(d(f.seen)[0]-f.plan[0],d(f.seen)[1]-f.plan[1])**2,0)/e);return{map:d,scale:Math.hypot(c,u),rms:p}}function Um(t,e,n=!1){let r=new Map(e.map(g=>[Nm(g.name),g])),o=[],i=new Set;for(let g of t){let y=Nm(g.name),b=r.get(y);if(!b||i.has(y)||g.points.length<3)continue;i.add(y);let v=g.points.map(x=>x[0]),w=g.points.map(x=>x[1]);o.push({name:g.name,plan:[(Math.min(...v)+Math.max(...v))/2,(Math.min(...w)+Math.max(...w))/2],grid:b.center})}let s=o.map(g=>g.name);if(o.length<2)return{cal:null,reason:"rooms",matched:s};let a=(o.length>=3?[!1,!0]:[n]).flatMap(g=>{let y=aw(o.map(b=>({plan:b.plan,seen:$l(b.grid,g)})));return y?[{mirror:g,...y}]:[]}).sort((g,y)=>g.rms-y.rms)[0];if(!a)return{cal:null,reason:"rooms",matched:s};if(!(a.scale>=Vm&&a.scale<=Km))return{cal:null,reason:"scale",matched:s};let c=Math.max(...o.map(g=>Math.hypot(g.plan[0]-o[0].plan[0],g.plan[1]-o[0].plan[1])));if(!(a.rms<=Math.max(1,c/4)))return{cal:null,reason:"fit",matched:s};let[u,d,p]=[0,1,-1];for(let g=0;gp&&([u,d,p]=[g,y,b])}let[h,f]=[o[u].grid,o[d].grid];return{cal:{a:a.map($l(h,a.mirror)),ga:h,b:a.map($l(f,a.mirror)),gb:f,mirror:a.mirror},matched:s,rms:a.rms}}function Zm(t,e){let[n,r]=[(t.a[0]+t.b[0])/2,(t.a[1]+t.b[1])/2],o=(e.turn??0)*Math.PI/180,[i,s,l]=[Math.cos(o),Math.sin(o),e.grow??1],[a,c]=e.move??[0,0],u=d=>{let[p,h]=[(d[0]-n)*l,(d[1]-r)*l];return[Bm(n+p*i-h*s+a),Bm(r+p*s+h*i+c)]};return{...t,a:u(t.a),b:u(t.b)}}var Bm=t=>Math.round(t*1e3)/1e3;var lw=/^(binary_sensor|switch|input_boolean|light|fan|person|device_tracker|sensor)\./,$t=t=>t==="none"?null:t;function Ml(t,e,n){let r=t.t,o=H(t.hass,a=>lw.test(a)),i=!!e.state_entity&&e.state_entity!=="none",s=i&&!!e.state_entity2&&e.state_entity2!=="none",l=[["left_right",r("furn_state_left_right")],["top_bottom",r("furn_state_top_bottom")]];return m`${z(t,r("furn_state_entity"),e.state_entity??null,void 0,o,a=>n.update({state_entity:$t(a)}))}
+ `}var bo=t=>Number(t);function Gi(t){if(Array.isArray(t)){let[i,s]=[bo(t[0]),bo(t[1])];return Number.isFinite(i)&&Number.isFinite(s)?[i,s]:null}if(!t||typeof t!="object")return null;let{x:e,y:n}=t,[r,o]=[bo(e),bo(n)];return Number.isFinite(r)&&Number.isFinite(o)?[r,o]:null}function Gm(t){return t?Gi(t.charger)??Gi(t.charger_position):null}function Ui(t){for(let[e,n]of Object.entries(t.states))if(e.startsWith("camera.")&&(Gi(n.attributes?.vacuum_position)??Gm(n.attributes)))return e;return null}var Sl=(t,e)=>e?[t[0],-t[1]]:t;var Um=5e-4,Zm=2,dw=1.5;function Ml(t,e){let n=e?t.states[e]?.attributes:void 0;return{at:n?Gi(n.vacuum_position):null,dock:Gm(n)}}function qm(t,e,n=!1){let r=Math.hypot(e.plan[0]-t.plan[0],e.plan[1]-t.plan[1]),o=Math.hypot(e.grid[0]-t.grid[0],e.grid[1]-t.grid[1]);if(!(o>1e-6)||!(r>=dw))return{cal:null,reason:"close"};let i=r/o;return i>=Um&&i<=Zm?{cal:{a:t.plan,ga:t.grid,b:e.plan,gb:e.grid,mirror:n}}:{cal:null,reason:"scale"}}function Ym(t,e){let n=e?t.states[e]?.attributes?.rooms:void 0;if(!n||typeof n!="object")return[];let r=[];for(let o of Object.values(n)){if(!o||typeof o!="object")continue;let i=o,s=typeof i.name=="string"?i.name.trim():"",l=[i.x0,i.y0,i.x1,i.y1].map(bo);!s||!l.every(Number.isFinite)||r.push({name:s,center:[(l[0]+l[2])/2,(l[1]+l[3])/2]})}return r}var Km=t=>t.toLocaleLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^\p{L}\p{N}]+/gu,"");function hw(t){let e=t.length,[n,r]=t.reduce((h,f)=>[h[0]+f.seen[0]/e,h[1]+f.seen[1]/e],[0,0]),[o,i]=t.reduce((h,f)=>[h[0]+f.plan[0]/e,h[1]+f.plan[1]/e],[0,0]),[s,l,a]=[0,0,0];for(let h of t){let[f,g]=[h.seen[0]-n,h.seen[1]-r],[y,b]=[h.plan[0]-o,h.plan[1]-i];s+=f*y+g*b,l+=f*b-g*y,a+=f*f+g*g}if(!(a>1e-9))return null;let[c,u]=[s/a,l/a],d=h=>{let[f,g]=[h[0]-n,h[1]-r];return[o+c*f-u*g,i+u*f+c*g]},p=Math.sqrt(t.reduce((h,f)=>h+Math.hypot(d(f.seen)[0]-f.plan[0],d(f.seen)[1]-f.plan[1])**2,0)/e);return{map:d,scale:Math.hypot(c,u),rms:p}}function Xm(t,e,n=!1){let r=new Map(e.map(g=>[Km(g.name),g])),o=[],i=new Set;for(let g of t){let y=Km(g.name),b=r.get(y);if(!b||i.has(y)||g.points.length<3)continue;i.add(y);let v=g.points.map(x=>x[0]),w=g.points.map(x=>x[1]);o.push({name:g.name,plan:[(Math.min(...v)+Math.max(...v))/2,(Math.min(...w)+Math.max(...w))/2],grid:b.center})}let s=o.map(g=>g.name);if(o.length<2)return{cal:null,reason:"rooms",matched:s};let a=(o.length>=3?[!1,!0]:[n]).flatMap(g=>{let y=hw(o.map(b=>({plan:b.plan,seen:Sl(b.grid,g)})));return y?[{mirror:g,...y}]:[]}).sort((g,y)=>g.rms-y.rms)[0];if(!a)return{cal:null,reason:"rooms",matched:s};if(!(a.scale>=Um&&a.scale<=Zm))return{cal:null,reason:"scale",matched:s};let c=Math.max(...o.map(g=>Math.hypot(g.plan[0]-o[0].plan[0],g.plan[1]-o[0].plan[1])));if(!(a.rms<=Math.max(1,c/4)))return{cal:null,reason:"fit",matched:s};let[u,d,p]=[0,1,-1];for(let g=0;gp&&([u,d,p]=[g,y,b])}let[h,f]=[o[u].grid,o[d].grid];return{cal:{a:a.map(Sl(h,a.mirror)),ga:h,b:a.map(Sl(f,a.mirror)),gb:f,mirror:a.mirror},matched:s,rms:a.rms}}function Qm(t,e){let[n,r]=[(t.a[0]+t.b[0])/2,(t.a[1]+t.b[1])/2],o=(e.turn??0)*Math.PI/180,[i,s,l]=[Math.cos(o),Math.sin(o),e.grow??1],[a,c]=e.move??[0,0],u=d=>{let[p,h]=[(d[0]-n)*l,(d[1]-r)*l];return[jm(n+p*i-h*s+a),jm(r+p*s+h*i+c)]};return{...t,a:u(t.a),b:u(t.b)}}var jm=t=>Math.round(t*1e3)/1e3;var pw=/^(binary_sensor|switch|input_boolean|light|fan|person|device_tracker|sensor)\./,$t=t=>t==="none"?null:t;function Rl(t,e,n){let r=t.t,o=H(t.hass,a=>pw.test(a)),i=!!e.state_entity&&e.state_entity!=="none",s=i&&!!e.state_entity2&&e.state_entity2!=="none",l=[["left_right",r("furn_state_left_right")],["top_bottom",r("furn_state_top_bottom")]];return m`${z(t,r("furn_state_entity"),e.state_entity??null,void 0,o,a=>n.update({state_entity:$t(a)}))}
${i?z(t,r("furn_state_entity2"),e.state_entity2??null,void 0,o,a=>n.update({state_entity2:$t(a)})):_}
${s?L(t,r("furn_state_split"),e.state_split==="top_bottom"?"top_bottom":"left_right",l,a=>n.update({state_split:a})):_}
- ${M(r("furn_state_hint"),"nf-wide")}`}function cw(t,e){let r=In(t.type)&&(!yt(t.type)||Ac(t.type));return ce(t.type)?{accept:o=>/^(light|switch|input_boolean)\./.test(o),label:"furn_entity_light"}:t.type==="radiator"||$n(t.type)?{accept:o=>o.startsWith("climate."),label:"furn_entity_climate"}:r?{accept:o=>/^(media_player|switch|input_boolean|light)\./.test(o),label:"furn_entity_tv"}:t.type==="robot_vacuum"?{accept:o=>o.startsWith("vacuum."),label:"furn_entity_vacuum"}:/:(robot_mower|mower_dock)$/.test(t.type)?{accept:o=>o.startsWith("lawn_mower."),label:"furn_entity_mower"}:/:(sprinkler|valve_box)$/.test(t.type)?{accept:o=>/^(valve|switch|input_boolean)\./.test(o),label:"furn_entity_water"}:{accept:o=>/^(switch|media_player|fan|input_boolean|climate|vacuum|cover|valve)\./.test(o)||vc(e?.states[o]),label:"furn_entity"}}function Zi(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let o of r)for(let i of o.furniture)i.id===e.id&&(i[n==="fan"?"fan_entity":n]=null);return We(t.hass,r).get(e.id)?.[n]??null}var uw=t=>t==="meter"?"energy_grid":t==="inverter"?"energy_solar_sensor":t==="home_battery"?"energy_battery_sensor":"furn_power",lt=(...t)=>m`${t}
`;async function dw(t){let e=t.hass?Ui(t.hass):null;if(!t.hass||!e)return{at:null,dock:null};let n=()=>{let o=t.hass?.states[e]?.attributes??{};return`${String(o.render_count??"")}|${JSON.stringify(o.vacuum_position??null)}`},r=n();try{await t.hass.fetchWithAuth?.(`/api/camera_proxy/${e}`)}catch{}for(let o=0;o<8&&n()===r;o++)await new Promise(i=>setTimeout(i,100));return Sl(t.hass,e)}function hw(t,e){let n=t.t,r=a=>t.change(c=>{c.settings.vacuum_map=Zm(e,a)}),o=(a,c,u)=>m`r(u)}>${a} `,[i,s,l]=[n("robot_cal_nudge_move"),n("robot_cal_nudge_turn"),n("robot_cal_nudge_grow")];return m`${M(n("robot_cal_nudge"),"nf-wide")}
+ ${M(r("furn_state_hint"),"nf-wide")}`}function fw(t,e){let r=In(t.type)&&(!yt(t.type)||Pc(t.type));return ue(t.type)?{accept:o=>/^(light|switch|input_boolean)\./.test(o),label:"furn_entity_light"}:t.type==="radiator"||$n(t.type)?{accept:o=>o.startsWith("climate."),label:"furn_entity_climate"}:r?{accept:o=>/^(media_player|switch|input_boolean|light)\./.test(o),label:"furn_entity_tv"}:t.type==="robot_vacuum"?{accept:o=>o.startsWith("vacuum."),label:"furn_entity_vacuum"}:/:(robot_mower|mower_dock)$/.test(t.type)?{accept:o=>o.startsWith("lawn_mower."),label:"furn_entity_mower"}:/:(sprinkler|valve_box)$/.test(t.type)?{accept:o=>/^(valve|switch|input_boolean)\./.test(o),label:"furn_entity_water"}:{accept:o=>/^(switch|media_player|fan|input_boolean|climate|vacuum|cover|valve)\./.test(o)||$c(e?.states[o]),label:"furn_entity"}}function Zi(t,e,n){if(!t.hass)return null;let r=structuredClone(t.doc.floors);for(let o of r)for(let i of o.furniture)i.id===e.id&&(i[n==="fan"?"fan_entity":n]=null);return We(t.hass,r).get(e.id)?.[n]??null}var mw=t=>t==="meter"?"energy_grid":t==="inverter"?"energy_solar_sensor":t==="home_battery"?"energy_battery_sensor":"furn_power",lt=(...t)=>m`${t}
`;async function gw(t){let e=t.hass?Ui(t.hass):null;if(!t.hass||!e)return{at:null,dock:null};let n=()=>{let o=t.hass?.states[e]?.attributes??{};return`${String(o.render_count??"")}|${JSON.stringify(o.vacuum_position??null)}`},r=n();try{await t.hass.fetchWithAuth?.(`/api/camera_proxy/${e}`)}catch{}for(let o=0;o<8&&n()===r;o++)await new Promise(i=>setTimeout(i,100));return Ml(t.hass,e)}function _w(t,e){let n=t.t,r=a=>t.change(c=>{c.settings.vacuum_map=Qm(e,a)}),o=(a,c,u)=>m`r(u)}>${a} `,[i,s,l]=[n("robot_cal_nudge_move"),n("robot_cal_nudge_turn"),n("robot_cal_nudge_grow")];return m`${M(n("robot_cal_nudge"),"nf-wide")}
${o("\u2190",i,{move:[-.1,0]})}${o("\u2192",i,{move:[.1,0]})}${o("\u2191",i,{move:[0,-.1]})}${o("\u2193",i,{move:[0,.1]})}
${o("\u27F2",s,{turn:-1})}${o("\u27F3",s,{turn:1})}${o("\u2212",l,{grow:.99})}${o("+",l,{grow:1.01})}
-
`}function pw(t,e){let n=t.t,r=t.doc.settings.vacuum_map??null,o=t.hass?Sl(t.hass,Ui(t.hass)):{at:null,dock:null},i=r?Math.hypot(r.gb[0]-r.ga[0],r.gb[1]-r.ga[1]):0,s=r&&i>0?Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])/i:0,l=()=>{t.pickPoint(p=>{p&&dw(t).then(h=>{if(!h.at||!h.dock)return;let f={plan:[e.x,e.z],grid:h.dock},g=jm(f,{plan:p,grid:h.at},r?.mirror??!1);g.cal&&t.change(y=>{y.settings.vacuum_map=g.cal})})})},a=t.hass?Ui(t.hass):null,c=t.hass?Gm(t.hass,a):[],u=t.doc.floors.find(p=>p.furniture.some(h=>h.id===e.id)),d=()=>{if(!u)return;let p=Um(u.rooms,c,r?.mirror??!1);if(p.cal){let h=p.cal;t.change(f=>{f.settings.vacuum_map=h})}else alert(n(p.reason==="rooms"?"robot_cal_rooms_none":"robot_cal_rooms_bad",{n:p.matched.length}))};return lt(M(o.at&&o.dock?r?n("robot_cal_done",{m:s.toFixed(2)}):n("robot_cal_none"):n("robot_cal_need"),"nf-wide"),c.length>=2?m`${n("robot_cal_rooms",{n:c.length})} `:_,m`${n("robot_cal_do")} `,r?D(t,n("robot_cal_mirror"),!!r.mirror,p=>t.change(h=>{h.settings.vacuum_map={...r,mirror:p}})):_,r?hw(t,r):_,r?m`t.change(p=>{p.settings.vacuum_map=null})}>${n("robot_cal_forget")} `:_,M(n("robot_cal_hint"),"nf-wide"))}function fw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=qn(o),s=o.floors.flatMap(l=>l.furniture.filter(a=>i.has(a.id)).map(a=>[a.id,`${a.name||r("furn_meter")} \xB7 ${l.name}`]));return lt(L(t,r("meter_parent"),ao(o,e)??"",[["",r("meter_main")],...s],l=>n.update({parent_meter:l||null}),{wide:!0}),M(r("meter_device_hint"),"nf-wide"))}function mw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=o.floors.flatMap(c=>c.furniture.filter(u=>Vh(o,e,u)).map(u=>[u.id,`${u.name||r("furn_meter")} \xB7 ${c.name}`])),s=!!gn(o,e),l=e.meter_floors??[],a=(c,u)=>n.update({meter_floors:u?[...l.filter(d=>d!==c),c]:l.filter(d=>d!==c)});return lt(L(t,r("meter_parent"),s?e.parent_meter:"",[["",r("meter_parent_none")],...i],c=>n.update({parent_meter:c||null}),{wide:!0}),s?D(t,r("energy_invert"),!!e.meter_invert,c=>n.update({meter_invert:c})):_,s?m`${r("meter_floors")}
${o.floors.map(c=>D(t,c.name,l.includes(c.id),u=>a(c.id,u)))}`:_,M(r("meter_sub_hint"),"nf-wide"))}function qm(t,e,n,r){let o=t.t,i=n==="mail"?s=>/^(binary_sensor|sensor|input_boolean)\./.test(s):s=>/^(sensor|binary_sensor|calendar)\./.test(s);return m`
+
`}function bw(t,e){let n=t.t,r=t.doc.settings.vacuum_map??null,o=t.hass?Ml(t.hass,Ui(t.hass)):{at:null,dock:null},i=r?Math.hypot(r.gb[0]-r.ga[0],r.gb[1]-r.ga[1]):0,s=r&&i>0?Math.hypot(r.b[0]-r.a[0],r.b[1]-r.a[1])/i:0,l=()=>{t.pickPoint(p=>{p&&gw(t).then(h=>{if(!h.at||!h.dock)return;let f={plan:[e.x,e.z],grid:h.dock},g=qm(f,{plan:p,grid:h.at},r?.mirror??!1);g.cal&&t.change(y=>{y.settings.vacuum_map=g.cal})})})},a=t.hass?Ui(t.hass):null,c=t.hass?Ym(t.hass,a):[],u=t.doc.floors.find(p=>p.furniture.some(h=>h.id===e.id)),d=()=>{if(!u)return;let p=Xm(u.rooms,c,r?.mirror??!1);if(p.cal){let h=p.cal;t.change(f=>{f.settings.vacuum_map=h})}else alert(n(p.reason==="rooms"?"robot_cal_rooms_none":"robot_cal_rooms_bad",{n:p.matched.length}))};return lt(M(o.at&&o.dock?r?n("robot_cal_done",{m:s.toFixed(2)}):n("robot_cal_none"):n("robot_cal_need"),"nf-wide"),c.length>=2?m`${n("robot_cal_rooms",{n:c.length})} `:_,m`${n("robot_cal_do")} `,r?D(t,n("robot_cal_mirror"),!!r.mirror,p=>t.change(h=>{h.settings.vacuum_map={...r,mirror:p}})):_,r?_w(t,r):_,r?m`t.change(p=>{p.settings.vacuum_map=null})}>${n("robot_cal_forget")} `:_,M(n("robot_cal_hint"),"nf-wide"))}function yw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=qn(o),s=o.floors.flatMap(l=>l.furniture.filter(a=>i.has(a.id)).map(a=>[a.id,`${a.name||r("furn_meter")} \xB7 ${l.name}`]));return lt(L(t,r("meter_parent"),lo(o,e)??"",[["",r("meter_main")],...s],l=>n.update({parent_meter:l||null}),{wide:!0}),M(r("meter_device_hint"),"nf-wide"))}function vw(t,e,n){let r=t.t,o=t.doc;if(!o.energy.advanced)return _;let i=o.floors.flatMap(c=>c.furniture.filter(u=>Uh(o,e,u)).map(u=>[u.id,`${u.name||r("furn_meter")} \xB7 ${c.name}`])),s=!!gn(o,e),l=e.meter_floors??[],a=(c,u)=>n.update({meter_floors:u?[...l.filter(d=>d!==c),c]:l.filter(d=>d!==c)});return lt(L(t,r("meter_parent"),s?e.parent_meter:"",[["",r("meter_parent_none")],...i],c=>n.update({parent_meter:c||null}),{wide:!0}),s?D(t,r("energy_invert"),!!e.meter_invert,c=>n.update({meter_invert:c})):_,s?m`${r("meter_floors")}
${o.floors.map(c=>D(t,c.name,l.includes(c.id),u=>a(c.id,u)))}`:_,M(r("meter_sub_hint"),"nf-wide"))}function Jm(t,e,n,r){let o=t.t,i=n==="mail"?s=>/^(binary_sensor|sensor|input_boolean)\./.test(s):s=>/^(sensor|binary_sensor|calendar)\./.test(s);return m`
${z(t,o(`care_entity_${n}`),e.care_entity??null,void 0,H(t.hass,i),s=>r.update({care_entity:$t(s)}))}
${n==="plant"?A(t,o("care_thirsty_below"),e.thirsty_below??20,s=>r.update({thirsty_below:Math.min(90,Math.max(1,Math.round(s)))}),1,1):_}
${M(o(`care_hint_${n}`),"nf-wide")}
-
`}function Ym(t,e,n){let r=t.t;return m`
+
`}function eg(t,e,n){let r=t.t;return m`
${z(t,r("furn_cover_entity"),e.cover_entity??null,void 0,H(t.hass,o=>o.startsWith("cover.")),o=>n.update({cover_entity:$t(o)}))}
${D(t,r("furn_cover_inverted"),!!e.cover_inverted,o=>n.update({cover_inverted:o||void 0}),{title:r("furn_cover_inverted_hint")})}
${M(r("furn_cover_hint"),"nf-wide")}
-
`}function Xm(t,e,n,r){let o=t.t,i=/socket/.test(e.type),s=H(t.hass,c=>/^(light|switch|input_boolean|fan)\./.test(c)),l=e.gang_entities??[],a=c=>u=>{let d=Array.from({length:n},(p,h)=>l[h]??null);d[c]=$t(u),r.update({gang_entities:d})};return m`
+
`}function tg(t,e,n,r){let o=t.t,i=/socket/.test(e.type),s=H(t.hass,c=>/^(light|switch|input_boolean|fan)\./.test(c)),l=e.gang_entities??[],a=c=>u=>{let d=Array.from({length:n},(p,h)=>l[h]??null);d[c]=$t(u),r.update({gang_entities:d})};return m`
${Array.from({length:n},(c,u)=>z(t,n===1?o(i?"gang_socket_one":"gang_switch_one"):o(i?"gang_socket":"gang_switch",{n:u+1}),l[u]??null,void 0,s,a(u)))}
${M(o(i?"gang_socket_hint":"gang_switch_hint"),"nf-wide")}
-
`}function gw(t,e,n){let r=t.t,o=H(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return lt(z(t,r("fridge_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:$t(i)})),z(t,r("freezer_temp"),e.temp_entity2??null,void 0,o,i=>n.update({temp_entity2:$t(i)})),M(r("fridge_temp_hint"),"nf-wide"))}function _w(t,e,n){let r=t.t,o=H(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return lt(z(t,r("device_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:$t(i)})),M(r("device_temp_hint"),"nf-wide"))}function bw(t,e,n){let r=t.t,o=e.extra_lights??[],i=H(t.hass,a=>a.startsWith("light.")&&a!==e.entity&&a!==e.color_entity),s=a=>c=>{let u=[...o];c&&c!=="none"?u[a]=c:u.splice(a,1),n.update({extra_lights:u.filter(Boolean).length?u.filter(Boolean):void 0})},l=Math.min(4,o.length+1);return m`${Array.from({length:l},(a,c)=>z(t,r("lamp_extra_light",{n:c+2}),o[c]??null,void 0,i,s(c)))}${M(r("lamp_extra_hint"),"nf-wide")}`}function Qm(t,e,n){let{hass:r}=t;if(!r)return _;let o=t.t,i=ce(e.type),s=cw(e,r),l=H(r,f=>Un(r,f)),a=f=>g=>n.update({[f]:$t(g)}),c=f=>H(r,f),u=(t.doc.settings.roof.strings??[]).filter(f=>f.inverter===e.id).map(f=>f.name),d=!!e.entity&&e.entity!=="none",p=e.type==="fridge_smart"?c(f=>f.startsWith("binary_sensor.")):[],h=e.type==="ceiling_fan"?"fan_hint":i?e.type==="lamp_pendant"?"lamp_hint_pendant":"lamp_hint":In(e.type)?"furn_links_hint_tv":e.type==="robot_vacuum"?"robot_hint":"furn_links_hint";return m`${lt(e.type==="grid_point"?M(o("grid_point_hint"),"nf-wide"):z(t,o(s.label),e.entity??null,Zi(t,e,"entity"),c(s.accept),f=>n.update({entity:f})),e.type==="ceiling_fan"?z(t,o("furn_fan_entity"),e.fan_entity??null,Zi(t,e,"fan"),c(f=>f.startsWith("fan.")),f=>n.update({fan_entity:f})):_,!i&&!Ne.includes(e.type)&&!Mr(e.type)?Ml(t,e,n):_,i&&d?m`${z(t,o("furn_color_entity"),e.color_entity??null,void 0,c(f=>f.startsWith("light.")&&f!==e.entity),a("color_entity"))}${M(o("furn_color_entity_hint"),"nf-wide")}`:_,i&&d?bw(t,e,n):_,i?rn(t,e.glow_scale,f=>n.update({glow_scale:f})):_,i?ji(t,e,Cm(r,e,e.entity&&e.entity!=="none"?e.entity:Zi(t,e,"entity"))?.attributes.effect_list,n.update):_,Mr(e.type)?rn(t,e.ambilight,f=>n.update({ambilight:f}),{label:"ambilight",hint:"ambilight_hint",lowest:0}):_,In(e.type)||ni(e.type)?rn(t,e.sound_rings,f=>n.update({sound_rings:f}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_,e.type==="grid_point"?_:z(t,o(gn(t.doc,e)?"meter_sub_power":uw(e.type)),e.power??null,Zi(t,e,"power"),l,f=>n.update({power:f})))}
- ${Nu(e.type)?gw(t,e,n):i||e.type==="grid_point"?_:_w(t,e,n)}
- ${e.type==="meter"?mw(t,e,n):_}
- ${e.type==="inverter"||e.type==="home_battery"?fw(t,e,n):_}
+ `}function ww(t,e,n){let r=t.t,o=H(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return lt(z(t,r("fridge_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:$t(i)})),z(t,r("freezer_temp"),e.temp_entity2??null,void 0,o,i=>n.update({temp_entity2:$t(i)})),M(r("fridge_temp_hint"),"nf-wide"))}function kw(t,e,n){let r=t.t,o=H(t.hass,i=>{let s=t.hass?.states[i]?.attributes;return i.startsWith("sensor.")&&(s?.device_class==="temperature"||s?.unit_of_measurement==="\xB0C"||s?.unit_of_measurement==="\xB0F")});return lt(z(t,r("device_temp"),e.temp_entity??null,void 0,o,i=>n.update({temp_entity:$t(i)})),M(r("device_temp_hint"),"nf-wide"))}function xw(t,e,n){let r=t.t,o=e.extra_lights??[],i=H(t.hass,a=>a.startsWith("light.")&&a!==e.entity&&a!==e.color_entity),s=a=>c=>{let u=[...o];c&&c!=="none"?u[a]=c:u.splice(a,1),n.update({extra_lights:u.filter(Boolean).length?u.filter(Boolean):void 0})},l=Math.min(4,o.length+1);return m`${Array.from({length:l},(a,c)=>z(t,r("lamp_extra_light",{n:c+2}),o[c]??null,void 0,i,s(c)))}${M(r("lamp_extra_hint"),"nf-wide")}`}function ng(t,e,n){let{hass:r}=t;if(!r)return _;let o=t.t,i=ue(e.type),s=fw(e,r),l=H(r,f=>Un(r,f)),a=f=>g=>n.update({[f]:$t(g)}),c=f=>H(r,f),u=(t.doc.settings.roof.strings??[]).filter(f=>f.inverter===e.id).map(f=>f.name),d=!!e.entity&&e.entity!=="none",p=e.type==="fridge_smart"?c(f=>f.startsWith("binary_sensor.")):[],h=e.type==="ceiling_fan"?"fan_hint":i?e.type==="lamp_pendant"?"lamp_hint_pendant":"lamp_hint":In(e.type)?"furn_links_hint_tv":e.type==="robot_vacuum"?"robot_hint":"furn_links_hint";return m`${lt(e.type==="grid_point"?M(o("grid_point_hint"),"nf-wide"):z(t,o(s.label),e.entity??null,Zi(t,e,"entity"),c(s.accept),f=>n.update({entity:f})),e.type==="ceiling_fan"?z(t,o("furn_fan_entity"),e.fan_entity??null,Zi(t,e,"fan"),c(f=>f.startsWith("fan.")),f=>n.update({fan_entity:f})):_,!i&&!Ne.includes(e.type)&&!Rr(e.type)?Rl(t,e,n):_,i&&d?m`${z(t,o("furn_color_entity"),e.color_entity??null,void 0,c(f=>f.startsWith("light.")&&f!==e.entity),a("color_entity"))}${M(o("furn_color_entity_hint"),"nf-wide")}`:_,i&&d?xw(t,e,n):_,i?rn(t,e.glow_scale,f=>n.update({glow_scale:f})):_,i?ji(t,e,Vm(r,e,e.entity&&e.entity!=="none"?e.entity:Zi(t,e,"entity"))?.attributes.effect_list,n.update):_,Rr(e.type)?rn(t,e.ambilight,f=>n.update({ambilight:f}),{label:"ambilight",hint:"ambilight_hint",lowest:0}):_,In(e.type)||ni(e.type)?rn(t,e.sound_rings,f=>n.update({sound_rings:f}),{label:"sound_rings",hint:"sound_rings_hint",lowest:0}):_,e.type==="grid_point"?_:z(t,o(gn(t.doc,e)?"meter_sub_power":mw(e.type)),e.power??null,Zi(t,e,"power"),l,f=>n.update({power:f})))}
+ ${Ku(e.type)?ww(t,e,n):i||e.type==="grid_point"?_:kw(t,e,n)}
+ ${e.type==="meter"?vw(t,e,n):_}
+ ${e.type==="inverter"||e.type==="home_battery"?yw(t,e,n):_}
${e.type==="meter"&&!gn(t.doc,e)?lt(z(t,o("furn_export"),e.export??null,void 0,l,a("export")),M(o("furn_export_hint"),"nf-wide")):_}
${e.type==="inverter"&&(t.doc.settings.roof.solar??[]).length>0?M(u.length>0?o("inverter_strings",{names:u.join(", ")}):o("inverter_strings_none"),"nf-wide"):_}
${e.type==="home_battery"?lt(z(t,o("furn_soc"),e.soc??null,void 0,c(f=>ge(f)&&(r.states[f]?.attributes.device_class==="battery"||r.states[f]?.attributes.unit_of_measurement==="%")),a("soc")),z(t,o("furn_charge"),e.charge??null,void 0,l,a("charge")),M(o("furn_charge_hint"),"nf-wide")):_}
${e.type==="wallbox"?lt(z(t,o("furn_wallbox_status"),e.status??null,void 0,c(f=>mi(f)||ge(f)),a("status"))):_}
${!i||e.entity?m`${D(t,o("device_confirm"),!!e.confirm,f=>n.update({confirm:f}),{title:o("device_confirm_hint")})}
${Hn(t,e.marker??null,f=>n.update({marker:f}))}${Ht(t,e.icon,f=>n.update({icon:f}))}${i?_:Ln(t,e.pin_offset,f=>n.update({pin_offset:f}))}
`:_}
- ${e.type==="robot_vacuum"?lt(z(t,o("furn_robot_room"),e.room_sensor??null,Ku(r,We(r,t.doc.floors).get(e.id)?.entity??null,null),c(ge),f=>n.update({room_sensor:f}))):_}
- ${e.type==="robot_vacuum"&&d?pw(t,e):_}
+ ${e.type==="robot_vacuum"?lt(z(t,o("furn_robot_room"),e.room_sensor??null,Zu(r,We(r,t.doc.floors).get(e.id)?.entity??null,null),c(ge),f=>n.update({room_sensor:f}))):_}
+ ${e.type==="robot_vacuum"&&d?bw(t,e):_}
${e.type==="fridge_smart"?m`${lt(z(t,o("furn_door_left"),e.door_left??null,void 0,p,f=>n.update({door_left:f})),z(t,o("furn_door_right"),e.door_right??null,void 0,p,f=>n.update({door_right:f})))}
${M(o("fridge_hint"))}`:_}
${Ki(t,e.values,f=>n.update({values:f}))}
- ${M(o(h))}`}var yw=/^(binary_sensor|device_tracker|input_boolean|switch|sensor)\./,vw=/^(sensor|input_select|select|input_text)\./,ww=/^(device_tracker|sensor|binary_sensor|lock|climate)\./,kw=(t,e)=>t.flatMap(n=>n.items.filter(r=>r.vehicle).map(r=>({id:he(n.id,r.id),label:`${Xe(r,he(n.id,r.id),e)} \xB7 ${He(n,e)}`})));function Jm(t,e){return e.startsWith("device_tracker.")?t.hass?.states[e]?.attributes.source_type==="router"?2:0:1}function eg(t,e,n,r){return m`r(o.target.value||null)}>
+ ${M(o(h))}`}var $w=/^(binary_sensor|device_tracker|input_boolean|switch|sensor)\./,Sw=/^(sensor|input_select|select|input_text)\./,Mw=/^(device_tracker|sensor|binary_sensor|lock|climate)\./,Rw=(t,e)=>t.flatMap(n=>n.items.filter(r=>r.vehicle).map(r=>({id:he(n.id,r.id),label:`${Xe(r,he(n.id,r.id),e)} \xB7 ${He(n,e)}`})));function rg(t,e){return e.startsWith("device_tracker.")?t.hass?.states[e]?.attributes.source_type==="router"?2:0:1}function og(t,e,n,r){return m`r(o.target.value||null)}>
${t.t("parking_vehicle_none")}
${e.map(o=>m`${o.label} `)}
- `}function xw(t,e,n,r){let o=t.t,i=e.type_entity?t.hass?.states[e.type_entity]:void 0,s=Array.isArray(i?.attributes.options)?i.attributes.options:[],l=e.types??[],a=u=>r.update({types:u}),c=(u,d)=>a(l.map((p,h)=>h===u?{...p,...d}:p));return m`
+ `}function Ew(t,e,n,r){let o=t.t,i=e.type_entity?t.hass?.states[e.type_entity]:void 0,s=Array.isArray(i?.attributes.options)?i.attributes.options:[],l=e.types??[],a=u=>r.update({types:u}),c=(u,d)=>a(l.map((p,h)=>h===u?{...p,...d}:p));return m`
${o("parking_types")}
${l.map((u,d)=>m`
c(d,{state:p.target.value})} />
- ${eg(t,n,u.vehicle,p=>c(d,{vehicle:p??""}))}
+ ${og(t,n,u.vehicle,p=>c(d,{vehicle:p??""}))}
a(l.filter((p,h)=>h!==d))}>✕
`)}
${s.map(u=>m` `)}
${t.admin?m`
a([...l,{state:s[l.length]??"",vehicle:n[0]?.id??""}])}>${o("parking_add_type")} `:_}
-
`}function tg(t,e,n,r){let o=t.t,i=kw(n,t.hass?.language??"en"),s=H(t.hass,f=>yw.test(f)).sort((f,g)=>Jm(t,f.id)-Jm(t,g.id)),l=H(t.hass,f=>vw.test(f)),a=e.car??{},c=t.floor,u=c?.rooms.find(f=>f.points.length>=3&&N([e.x,e.z],f.points)),d=e.vehicle?U(e.vehicle):void 0,p=d?d.size[2]*(e.scale??1):0,h=!!u&&!!c&&p>c.height+1e-6;return m`
+
`}function ig(t,e,n,r){let o=t.t,i=Rw(n,t.hass?.language??"en"),s=H(t.hass,f=>$w.test(f)).sort((f,g)=>rg(t,f.id)-rg(t,g.id)),l=H(t.hass,f=>Sw.test(f)),a=e.car??{},c=t.floor,u=c?.rooms.find(f=>f.points.length>=3&&N([e.x,e.z],f.points)),d=e.vehicle?U(e.vehicle):void 0,p=d?d.size[2]*(e.scale??1):0,h=!!u&&!!c&&p>c.height+1e-6;return m`
${z(t,o("parking_entity"),e.entity??null,void 0,s,f=>r.update({entity:f==="none"?null:f}))}
- ${o("parking_vehicle")} ${eg(t,i,e.vehicle??null,f=>r.update({vehicle:f}))}
+ ${o("parking_vehicle")} ${og(t,i,e.vehicle??null,f=>r.update({vehicle:f}))}
${i.length>0?_:M(o("parking_no_pack"),"nf-wide")}
${A(t,o("parking_scale"),Math.round((e.scale??1)*100),f=>r.update({scale:Math.min(150,Math.max(30,f))/100}),5,30)}
${z(t,o("parking_type_entity"),e.type_entity??null,void 0,l,f=>r.update({type_entity:f==="none"?null:f}))}
- ${e.type_entity?xw(t,e,i,r):_}
+ ${e.type_entity?Ew(t,e,i,r):_}
${h?m`
${o("parking_too_tall",{car:K(t.hass,p,2),room:K(t.hass,c.height,2)})}
`:_}
${M(o("parking_hint"))}
- ${t.hass?m`${z(t,o("live_car_device"),a.device??null,null,H(t.hass,f=>ww.test(f)),f=>r.update({car:{...a,device:f}}))}
+ ${t.hass?m`${z(t,o("live_car_device"),a.device??null,null,H(t.hass,f=>Mw.test(f)),f=>r.update({car:{...a,device:f}}))}
${M(o("live_car_device_hint"),"nf-wide")}
- ${z(t,o("live_car_departure_entity"),a.departure??null,void 0,H(t.hass,f=>/^(sensor|input_datetime|time|datetime)\./.test(f)),f=>r.update({car:{...a,departure:f==="none"?null:f}}))}`:_}`}function ng(t,e){let r=_n(t,e.w,e.d,e.h).treads.findIndex(o=>o.landing);return r>=0?r+1:1}function $w(t){let e=_n(po(t),t.w,t.d,t.h),n=e.treads.map(Ti),r=0;for(let i=1;i
1?r/(n.length-1):0;return{rise:e.rise,going:o,measure:2*e.rise+o,steps:e.steps}}function Sw(t){let[e,n]=Va[t],r=_n({...gt,shape:t},e,n,2.8),o=26/Math.max(e,n);return m`
+ ${z(t,o("live_car_departure_entity"),a.departure??null,void 0,H(t.hass,f=>/^(sensor|input_datetime|time|datetime)\./.test(f)),f=>r.update({car:{...a,departure:f==="none"?null:f}}))}`:_}`}function sg(t,e){let r=_n(t,e.w,e.d,e.h).treads.findIndex(o=>o.landing);return r>=0?r+1:1}function Aw(t){let e=_n(fo(t),t.w,t.d,t.h),n=e.treads.map(Ti),r=0;for(let i=1;i1?r/(n.length-1):0;return{rise:e.rise,going:o,measure:2*e.rise+o,steps:e.steps}}function Fw(t){let[e,n]=Va[t],r=_n({...gt,shape:t},e,n,2.8),o=26/Math.max(e,n);return m`
${r.treads.map(i=>R``${s*o},${l*o}`).join(" ")} fill=${i.landing?"currentColor":"none"} fill-opacity="0.25" stroke="currentColor" stroke-width="0.8" />`)}
- `}function rg(t,e,n){let r=t.t,o=po(e),i=f=>n.update({stair:{...o,...f}}),s=o.shape!=="straight",l=f=>{let[g,y]=Va[f];n.update({stair:{...o,shape:f,run_width:null},w:g,d:y})},a=t.floor?t.doc.floors.filter(f=>f.elevationg.elevation-f.elevation)[0]:void 0,c=t.floor?t.doc.floors.filter(f=>f.elevation>t.floor.elevation).sort((f,g)=>f.elevation-g.elevation)[0]:void 0,u=f=>{let g=f?a&&t.floor?t.floor.elevation-a.elevation:null:c&&t.floor?c.elevation-t.floor.elevation:null;n.update({stair:{...o,down:f},...g?{h:Math.round(g*1e3)/1e3}:{}})},d=$w(e),p=f=>K(t.hass,f*100,1),h=d.measure>=.59&&d.measure<=.65&&d.rise<=.21;return m`