0){i.textContent=Wi?Wi.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,i){let o=this.strings,s=!1;if(o===void 0)e=nn(this,e,n,0),s=!Ar(e)||e!==this._$AH&&e!==tt,s&&(this._$AH=e);else{let a=e,l,c;for(e=o[0],l=0;l{let r=n?.renderBefore??e,i=r._$litPart$;if(i===void 0){let o=n?.renderBefore??null;r._$litPart$=i=new Fn(e.insertBefore(Rr(),o),o,void 0,n??{})}return i._$AI(t),i};var Vs=globalThis,q=class extends yt{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=id(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return tt}};q._$litElement$=!0,q.finalized=!0,Vs.litElementHydrateSupport?.({LitElement:q});var Kb=Vs.litElementPolyfillSupport;Kb?.({LitElement:q});(Vs.litElementVersions??=[]).push("4.2.2");var ld=[],qi=new Map,jb=0,he=(t,e)=>`pack:${t}:${e}`,wt=t=>t.startsWith("pack:");function Ws(t){ld=t,qi=new Map;for(let e of t)for(let n of e.items)qi.set(he(e.id,n.id),n);jb+=1}var zr=()=>ld;var Gb={};function U(t){if(!wt(t))return;let e=qi.get(t);if(e)return e;let[,n,...r]=t.split(":"),i=Gb[n];return i?qi.get(he(i,r.join(":"))):void 0}var Ub=.22;function od(t,e,n,r){let i=Math.min(Ub,n/3);if(r<=i*2.4||Math.abs(r-n)<1e-6)return e*(r/n)+(t-e)*(r/n);let o=e*(r/n),s=t-e;return s<=i?o+s:s>=n-i?o+r-(n-s):o+i+(s-i)*(r-2*i)/(n-2*i)}function Tr(t,e,n,r,i){return[od(t*r,n*r,r,i)/i,od(e*r,n*r,r,i)/i]}var sd=new WeakMap;function cd(t,e,n,r){let[i,o,s]=t.size;if(t.vehicle||t.stretch||Math.abs(e-i)<1e-4&&Math.abs(n-o)<1e-4&&Math.abs(r-s)<1e-4)return t.parts;let a=`${e.toFixed(4)}|${n.toFixed(4)}|${r.toFixed(4)}`,l=sd.get(t),c=l?.get(a);if(c)return c;let d=t.parts.map(u=>{if(u.shape==="sweep")return u;let[p,h]=Tr(u.x-u.w/2,u.x+u.w/2,-.5,i,e),[f,g]=Tr(u.z-u.d/2,u.z+u.d/2,-.5,o,n),[b,y]=Tr(u.y,u.y+u.h,0,s,r);if(u.rot)return{...u,x:(p+h)/2,z:(f+g)/2,w:u.w*i/e,d:u.d*o/n,y:b,h:y-b};let v={...u,x:(p+h)/2,z:(f+g)/2,w:h-p,d:g-f,y:b,h:y-b};if(u.shape==="loft"){let[w,k,x,M]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,T]=Tr(w-x/2,w+x/2,-.5,i,e),[F,L]=Tr(k-M/2,k+M/2,-.5,o,n);Object.assign(v,{tx:(A+T)/2,tz:(F+L)/2,tw:T-A,td:L-F})}return v});return l||sd.set(t,l=new Map),l.size>32&&l.clear(),l.set(a,d),d}var Ks=t=>!!t?.parts.some(e=>e.move);var dd=t=>U(t)?.parts.find(e=>e.screen),ad=.06;function ud(t){let e=U(t);if(!e)return!1;let[n,r,i]=e.size;return e.parts.filter(o=>o.screen).some(o=>{let[s,a]=[o.w*n,o.d*r,o.h*i].sort((l,c)=>c-l);return a>=ad&&s>=ad})}function ut(t){return nt[t]??U(t)?.size??[.6,.6,.8]}function Tt(t){let e=U(t);return yd.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var hd=t=>!!U(t)?.parts.some(e=>e.picture),Tn=t=>!!U(t)?.climate;function pd(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var Zb={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 fd(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&Zb[n]||t.name}function zt(t,e){return e.mount_y!=null?e.mount_y:Yb(t,e)+(qb(e)?0:_d(t,e.x,e.z))}var qb=t=>t.type==="led_strip"||U(t.type)?.mount==="ceiling";function Yb(t,e){if(e.type==="lamp_wall")return md;if(e.type==="led_strip")return Math.max(0,ht(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=U(e.type);if(!n)return gd(e);switch(n.mount){case"surface":return bd(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Yi(t,e)-e.h);default:return 0}}function js(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 vd=t=>[t.kind,t.floorId,t.id].filter(Boolean).join(":");function wd(t,e="Geb\xE4ude 1"){if(t.topology)return;let n=P("location"),r=P("branch"),i=P("building");t.topology={locations:[{id:n,name:"Ort 1"}],branches:[{id:r,name:"Niederlassung 1",location_id:n}],buildings:[{id:i,name:e,branch_id:r}]};for(let o of t.floors)o.building_id=i}function Xi(t){let e=t.topology;e.locations??=[],e.branches??=[],e.buildings??=[];let n=o=>(o||=e.locations[0]?.id||P("location"),e.locations.some(s=>s.id===o)||e.locations.push({id:o,name:"Ort"}),o),r=o=>(o||=e.branches[0]?.id||P("branch"),e.branches.some(s=>s.id===o)||e.branches.push({id:o,name:"Niederlassung",location_id:n()}),o),i=o=>(o||=e.buildings[0]?.id||P("building"),e.buildings.some(s=>s.id===o)||e.buildings.push({id:o,name:"Geb\xE4ude",branch_id:r()}),o);for(let o of e.branches)o.location_id=n(o.location_id);for(let o of e.buildings)o.branch_id=r(o.branch_id);for(let o of t.floors)o.outdoor_location_id?(o.outdoor_location_id=n(o.outdoor_location_id),o.building_id=null):o.building_id=i(o.building_id)}function xd(t,e){let n=t.floors.find(i=>i.outdoor_location_id===e);if(n)return n;let r={...Ee(P("outside"),"Au\xDFen",0),outdoor_location_id:e,building_id:null};return t.floors.push(r),r}function Gs(t,e,n){let r=t.floors.find(i=>i.id===e);return n?{kind:"room",id:n,floorId:e}:r?.outdoor_location_id?{kind:"outside",id:r.outdoor_location_id}:{kind:"floor",id:e}}function Xb(t){let e=(i,o,s,a=[],l=a.flatMap(d=>d.floorIds),c)=>{let d={kind:i,...o?{id:o}:{},...c?{floorId:c.floorId}:{}};return{key:vd(d),name:s,selection:d,floorIds:[...new Set(l)],children:a,...c?{room:c}:{}}},n=i=>e("floor",i.id,i.name,i.rooms.map(o=>e("room",o.id,o.name,[],[i.id],{floorId:i.id,roomId:o.id})),[i.id]);if(!t.topology)return e("all",void 0,"Alle Etagen",[...t.floors].sort((i,o)=>o.elevation-i.elevation).map(n));let r=t.topology;return e("all",void 0,"Alle Orte",r.locations.map(i=>{let o=r.branches.filter(a=>a.location_id===i.id).map(a=>e("branch",a.id,a.name,r.buildings.filter(l=>l.branch_id===a.id).map(l=>e("building",l.id,l.name,t.floors.filter(c=>!c.outdoor_location_id&&c.building_id===l.id).sort((c,d)=>d.elevation-c.elevation).map(n))))),s=t.floors.filter(a=>a.outdoor_location_id===i.id);return s.length&&o.push(e("outside",i.id,"Au\xDFen",s.flatMap(a=>a.rooms.map(l=>e("room",l.id,l.name,[],[a.id],{floorId:a.id,roomId:l.id}))),s.map(a=>a.id))),e("location",i.id,i.name,o)}))}function kd(t,e){let n=Xb(t),r=vd(e),i=o=>{if(o.key===r)return[o];for(let s of o.children){let a=i(s);if(a)return[o,...a]}return null};return i(n)??[n]}function $d(t,e,n=!1){if(!t.topology||e.kind==="all")return t.floors;let r=kd(t,e),i=(n&&(e.kind==="floor"||e.kind==="room")?r.find(s=>s.selection.kind==="building"):null)??r.at(-1),o=new Set(i.floorIds);return t.floors.filter(s=>o.has(s.id))}function Pr(t,e){return t.topology?kd(t,Gs(t,e.id)).slice(1).map(n=>n.name).join(" / "):e.name}var xt=["electricity","water","gas","heating","cooling"],Sd=["condition","temperature","humidity","pressure","wind_speed","wind_gust_speed","wind_bearing","cloud_coverage","precipitation","precipitation_total","illuminance","uv_index","visibility","snow","fog","lightning"],Md=["turn","slide","top"],Ed=["always","active","no_power","never"],Rd=1.3,Ji=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,Ad=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],Fd=["brick","round","wide","steel"],Qi=["navigate","more_info","service","fire_dom_event"];function eo(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var Td=["rain","snow","fog","clouds","lightning","sky"],zd=["rain","snow","clouds","lightning","sky"],Pd=["lawn","terrace","path","driveway","pavers","stepping_stones","natural_stone","street","sidewalk","gravel","river","stream","pool","bed","wild","hedge","fence","pergola"],Us={lawn:.012,terrace:.12,path:.02,driveway:.02,pavers:.025,stepping_stones:.025,natural_stone:.03,street:.02,sidewalk:.12,gravel:.018,river:.008,stream:.006,pool:-.25,bed:.15,wild:.03,hedge:1.2,fence:1,pergola:2.2};function Zs(t){return t==="hedge"||t==="fence"||t==="pergola"}var Id=["x","-x","z","-z"];function Jb(t,e,n){let r=t.slope??0;if(!r||t.type==="pool")return 0;let i=t.slope_dir??"x",o=(c,d)=>i==="x"?c:i==="-x"?-c:i==="z"?d:-d,s=1/0,a=-1/0;for(let[c,d]of t.points){let u=o(c,d);s=Math.min(s,u),a=Math.max(a,u)}if(a-s<1e-6)return 0;let l=Math.min(1,Math.max(0,(o(e,n)-s)/(a-s)));return r*l}function Qb(t,e,n,r){return Dd(t)+(e.offset??0)+Us[e.type]-Jb(e,n,r)}function Dd(t){return t.elevation>.3?0:-.2}function Od(t,e,n){let r=(t.outdoor??[]).filter(o=>!Zs(o.type)&&o.type!=="pool"&&C([e,n],o.points)),i=[...r].reverse().find(o=>o.cut)??r[0];return i?Qb(t,i,e,n):Dd(t)}var qs=t=>t.cut??(t.type==="pool"||t.type==="river"||t.type==="stream");function to(t){let e=Number.isFinite(t.texture_scale)?Math.max(.05,Math.min(20,t.texture_scale)):1,n=Number.isFinite(t.texture_rotation)?(t.texture_rotation%360+360)%360:0;return{scale:e,rotation:n}}var Hd=30,Ld={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},Cd=["wood","oak","tiles","carpet","stone","concrete"],Nd={type:"none",pitch:35,overhang:.4},no="#d6cfc2",ro="#e8e3da",Bd={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...Nd}};function Pt(){return{version:1,floors:[],settings:{...Bd},energy:{...Ld},presence:[]}}function Ee(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 ey=2.75;function Vd(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*ey*100)/100;let n=t.reduce((r,i)=>!r||i.elevation>r.elevation?i:r,null);return n?Math.round((n.elevation+n.height+.25)*100)/100:0}function Wd(t,e,n){let r=t.rooms.flatMap(a=>a.points.map(l=>l[0])),i=t.rooms.flatMap(a=>a.points.map(l=>l[1])),o=r.length?Math.ceil(Math.max(...r))+1:0,s=i.length?Math.floor(Math.min(...i)):0;return e.map((a,l)=>{let c=o+l%3*4.5,d=s+Math.floor(l/3)*3.5;return{id:n(),name:a.name,area_id:a.area_id,points:[[c,d],[c+4,d],[c+4,d+3],[c,d+3]],floor_material:"wood"}})}function Kd(t,e,n,r){let i=t.rotation*Math.PI/180,o=Math.cos(i),s=Math.sin(i),[a,l]=e,c=t.x-a*(t.w/2)*o+l*(t.d/2)*s,d=t.z-a*(t.w/2)*s-l*(t.d/2)*o,u=n[0]-c,p=n[1]-d,h=y=>Math.max(.1,Math.round(y/r)*r),f=h((u*o+p*s)*a),g=h((-u*s+p*o)*l),b=y=>Math.round(y*1e3)/1e3;return{x:b(c+a*(f/2)*o-l*(g/2)*s),z:b(d+a*(f/2)*s+l*(g/2)*o),w:b(f),d:b(g)}}var io=["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","heating_manifold","buffer_tank","freshwater_station","stairwell"],jd={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","heating_manifold","buffer_tank","freshwater_station"],vehicles:["parking"]},Ke=["meter","inverter","home_battery","wallbox","grid_point"],Gd=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"]),md=1.75;function oo(t){return Ys.has(t.type)||["stairwell","parking"].includes(t.type)?!1:U(t.type)?.mount!=="ceiling"}function de(t){return Gd.has(t)||!!U(t)?.light}var ty=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Ud(t,e,n,r=0){let i=ue(t.points),o=i.x1-i.x0-2*r,s=i.z1-i.z0-2*r,a=[];for(let l=0;lMath.round(s*1e3)/1e3,[i,o]={right:[1,0],down:[0,1],left:[-1,0],up:[0,-1]}[n];return[r(t[0]+i*e),r(t[1]+o*e)]}function gd(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 Ys=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Zd(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 Xs=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function _d(t,e,n){let r=t.rooms.find(i=>i.points.length>=3&&i.floor_offset&&C([e,n],i.points));return Xs(r)}function ht(t,e,n){let r=t.rooms.find(i=>i.points.length>=3&&C([e,n],i.points));return r?.ceiling!=null&&r.ceiling>0?r.ceiling:t.height}var Yi=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:ht(t,e.x,e.z);function bd(t,e,n){let r=0;for(let i of t.furniture)!(ty.has(i.type)||U(i.type)?.surface)||!C([e,n],ta(i))||(r=Math.max(r,i.h));return r}var yd=new Set([...Gd,"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"]),nt={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],heating_manifold:[1.5,.35,1.1],buffer_tank:[.85,.85,1.85],freshwater_station:[.65,.28,.9],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 Js=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],Qs=["standard","bars","glass_wall"],so=new Set(["interior","front"]);function on(t,e){return t.type==="door"?t.style&&Js.includes(t.style)?t.style:e?"front":"interior":t.style&&Qs.includes(t.style)?t.style:"standard"}function qd(t,e,n,r){if(e!=="sidelight"&&e!=="sidelights")return null;let i=e==="sidelights",o=t-.04,s=Math.min(1.05,Math.max(.6,o-(i?.6:.3))),a=(o-s)/(i?2:1),l=r.sidelight_width??a,c=i?r.sidelight_width2??r.sidelight_width??a:0;l=Math.max(.1,l),c=i?Math.max(.1,c):0;let d=o-.5;if(l+c>d){let p=Math.max(0,d)/(l+c);l*=p,c*=p}return i?{panels:[[.02,.02+l],[t-.02-c,t-.02]],x0:.02+l,x1:t-.02-c}:(n?!!r.sidelight_hinge:!r.sidelight_hinge)?{panels:[[.02,.02+l]],x0:.02+l,x1:t-.02}:{panels:[[t-.02-l,t-.02]],x0:.02,x1:t-.02-l}}function ea(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var Pn={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 In(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&&ea(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function Oe(t){t.energy={...Ld,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...Bd,...t.settings,roof:{...Nd,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Ee(e.id,e.name??`Floor ${n+1}`,e.elevation??n*2.8);for(let i of Object.keys(r))e[i]===void 0&&(e[i]=r[i])});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 i of n){let o=r[i.mount??"ceiling"],[s,a,l]=nt[o],c=`lamp_${i.entity_id.slice(6).replace(/[^A-Za-z0-9_\-.]/g,"_")}`.slice(0,54),d=c,u=1;for(;e.furniture.some(p=>p.id===d);)d=`${c}_${u++}`;e.furniture.push({id:d,type:o,x:i.x,z:i.z,rotation:0,w:s,d:a,h:l,variant:null,entity:i.entity_id,power:null,animations_enabled:i.animations_enabled,effect_animations:structuredClone(i.effect_animations)})}e.placements=e.placements.filter(i=>!i.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 ny(t),t.topology&&Xi(t),t}function ny(t){let e=(n,r)=>{let i=new Set;for(let o of n)(typeof o.id!="string"||!o.id||i.has(o.id))&&(o.id=P(r)),i.add(o.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=P("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function P(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function be(t){let e=0;for(let n=0;no+s[0],0)/i,t.reduce((o,s)=>o+s[1],0)/i]}let n=0,r=0;for(let i=0;i1e-6&&Math.abs(r-o)>1e-6)return!1}return!0}function ue(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(let[o,s]of t)e=Math.min(e,o),n=Math.min(n,s),r=Math.max(r,o),i=Math.max(i,s);return{x0:e,z0:n,x1:r,z1:i}}function ta(t){let e=t.rotation*Math.PI/180,n=Math.cos(e),r=Math.sin(e),i=t.w/2,o=t.d/2;return[[-i,-o],[i,-o],[i,o],[-i,o]].map(([s,a])=>[t.x+s*n-a*r,t.z+s*r+a*n])}function C(t,e){let n=!1;for(let r=0,i=e.length-1;rt[1]!=l>t[1]&&t[0]<(a-o)*(t[1]-s)/(l-s)+o&&(n=!n)}return n}var ao={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 fe=J`
:host {
--nf-text: var(--primary-text-color, #e1e1e1);
--nf-muted: var(--secondary-text-color, #9b9b9b);
--nf-accent: var(--primary-color, #03a9f4);
--nf-accent-text: var(--text-primary-color, #ffffff);
--nf-surface: var(--ha-card-background, var(--card-background-color, #1c1c1c));
--nf-bg: var(--primary-background-color, #111111);
--nf-bg2: var(--secondary-background-color, #1c1c1c);
/* floating bars and cards over the 3D view: the card colour, a little see-through */
--nf-chrome: color-mix(in srgb, var(--nf-surface) var(--nf-chrome-mix, 84%), transparent);
--nf-chrome-solid: var(--nf-surface);
--nf-line: var(--divider-color, rgba(255, 255, 255, 0.12));
/* quiet fills for buttons and fields, and the tonal accent of an active control */
--nf-fill: color-mix(in srgb, var(--nf-text) 7%, transparent);
--nf-fill-strong: color-mix(in srgb, var(--nf-text) 13%, transparent);
--nf-tonal: color-mix(in srgb, var(--nf-accent) 20%, transparent);
--nf-soft: var(--info-color, #4a90e2);
--nf-warm: var(--state-light-active-color, #ffa726);
--nf-danger: var(--error-color, #db4437);
--nf-good: var(--success-color, #43a047);
--nf-radius: var(--ha-card-border-radius, 12px);
--nf-shadow: var(--ha-card-box-shadow, 0 1px 2px rgba(0, 0, 0, 0.18), 0 6px 20px rgba(0, 0, 0, 0.2));
--nf-font: var(--primary-font-family, Roboto, "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif);
--nf-title-font: var(--nf-font);
font-family: var(--nf-font);
color: var(--nf-text);
}
`,t$=J`
:host([readable]) {
--secondary-text-color: var(--primary-text-color, #e1e1e1);
--divider-color: color-mix(in srgb, var(--primary-text-color, #e1e1e1) 40%, transparent);
--nf-chrome-mix: 97%;
}
:host([readable]) nf-room-panel,
:host([readable]) .nf-nav,
:host([readable]) .nf-overlay {
zoom: 1.2;
}
`,pt=J`
/* a group of switches: one rounded pill, the active one tinted with the accent */
.nf-seg {
display: inline-flex;
padding: 4px;
gap: 2px;
border-radius: 999px;
background: var(--nf-chrome);
box-shadow: var(--nf-shadow);
backdrop-filter: blur(10px);
}
.nf-seg button,
.nf-chip {
font: inherit;
font-size: 14px;
font-weight: 500;
border: none;
background: none;
color: var(--nf-muted);
padding: 7px 14px;
border-radius: 999px;
cursor: pointer;
white-space: nowrap;
min-height: 36px;
transition:
background 0.15s,
color 0.15s;
}
.nf-seg button:hover:not(:disabled),
.nf-chip:hover {
background: var(--nf-fill);
color: var(--nf-text);
}
/* on a small stage (a small window, a zoomed browser, a dashboard column) the switches at the bottom take less room */
@container nf ((max-width: 1360px) or (max-height: 640px)) {
:is(.nf-overlay, .nf-card-controls) .nf-seg {
padding: 3px;
}
:is(.nf-overlay, .nf-card-controls) :is(.nf-seg button, .nf-chip) {
font-size: 12.5px;
padding: 5px 10px;
}
}
.nf-time-slider {
display: inline-flex;
align-items: center;
padding: 4px 10px;
}
.nf-time-slider input {
width: 160px;
accent-color: var(--nf-accent);
}
.nf-seg button[aria-pressed="true"],
.nf-chip[aria-pressed="true"] {
background: color-mix(in srgb, var(--nf-accent) 24%, var(--nf-chrome-solid));
color: var(--nf-accent);
font-weight: 600;
}
.nf-seg button:disabled {
opacity: 0.4;
cursor: default;
}
/* a single pill, like the chips of the Mushroom cards */
.nf-chip {
background: var(--nf-chrome);
color: var(--nf-text);
box-shadow: var(--nf-shadow);
backdrop-filter: blur(10px);
}
button:focus-visible,
input:focus-visible,
select:focus-visible {
outline: 2px solid var(--nf-accent);
outline-offset: 2px;
}
/* the round icon badge every row and card starts with */
.nf-ico {
display: inline-flex;
align-items: center;
justify-content: center;
flex: none;
width: 38px;
height: 38px;
border-radius: 50%;
background: var(--nf-tonal);
color: var(--nf-accent);
--mdc-icon-size: 20px;
}
.nf-ico.nf-warm {
background: color-mix(in srgb, var(--nf-warm) 22%, transparent);
color: var(--nf-warm);
}
.nf-ico.nf-off {
background: var(--nf-fill);
color: var(--nf-muted);
}
.nf-btn {
font: inherit;
font-size: 14px;
font-weight: 500;
border: none;
background: var(--nf-fill);
color: var(--nf-text);
border-radius: var(--nf-radius);
padding: 7px 14px;
cursor: pointer;
min-height: 36px;
transition: background 0.15s;
}
.nf-btn:hover {
background: var(--nf-fill-strong);
}
.nf-btn.nf-danger {
color: var(--nf-danger);
}
.nf-btn.nf-primary {
background: var(--nf-accent);
color: var(--nf-accent-text);
}
.nf-btn.nf-primary:hover {
background: color-mix(in srgb, var(--nf-accent) 88%, var(--nf-text));
}
.nf-field {
display: grid;
gap: 4px;
font-size: 12px;
color: var(--nf-muted);
}
.nf-field input,
.nf-field select,
.nf-field textarea {
font: inherit;
font-size: 14px;
color: var(--nf-text);
background: var(--nf-fill);
border: none;
border-bottom: 1px solid var(--nf-line);
border-radius: 10px 10px 4px 4px;
padding: 8px 10px;
min-width: 0;
}
.nf-field input:focus,
.nf-field select:focus,
.nf-field textarea:focus {
border-bottom-color: var(--nf-accent);
}
.nf-field input[type="range"] {
padding: 0;
accent-color: var(--nf-accent);
}
.nf-field select option {
background: var(--nf-chrome-solid);
color: var(--nf-text);
}
/* fingers need 40 px */
@media (pointer: coarse) {
.nf-seg button,
.nf-chip,
.nf-btn {
min-height: 40px;
}
}
`;var On={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},sn=t=>(...e)=>({_$litDirective$:t,values:e}),It=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 Ir=class extends It{constructor(e){if(super(e),this.it=_,e.type!==On.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===tt)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:[]}}};Ir.directiveName="unsafeHTML",Ir.resultType=1;var Yd=sn(Ir);var ra=t=>t.slice(0,t.indexOf(".")),ry={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"},ee=t=>ry[ra(t)]??null,ia=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var Xd=new Set(["light","switch","fan"]),Dt=t=>t!==null&&t!=="scene"&&t!=="script",He=t=>!t||t.state==="unavailable"||t.state==="unknown"&&!t.entity_id.startsWith("event.");function B(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 i=r.slice(n.length+1);return i[0].toUpperCase()+i.slice(1)}var Jd=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var Qd=t=>Math.min(1,Math.max(0,t));function iy(t){let e=Qd((t-2200)/4300),n=[1,.66,.26],r=[.78,.9,1];return[0,1,2].map(i=>n[i]+(r[i]-n[i])*e)}function na(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(Qd(n.brightness/255)):1,i=n.rgb_color;return i&&!["color_temp","brightness","onoff"].includes(String(n.color_mode))?{color:[i[0]/255,i[1]/255,i[2]/255],level:r}:typeof n.color_temp_kelvin=="number"?{color:iy(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function eu(t,e,n){let r=na(t,n);if(r)return r;for(let i of e){let o=na(i);if(o)return{color:o.color,level:o.level*.6}}return null}function lo(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 oa=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),sa=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var sy=globalThis,nu=sy.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},aa=nu.plugins,tu=nu.listeners;var ay=5;function ru(t,e){t.errors.lengthtu.delete(t)}var la=()=>[...aa.values()].map(t=>t.status),iu=()=>[...aa.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*uo(t,e){for(let{plugin:n,status:r}of aa.values())for(let i of n.devices??[]){let o=!1;try{o=i.match(t,e)}catch(s){ru(r,s)}o&&(yield{device:i,status:r})}}function ho(t,e){for(let{device:n}of uo(t,e))return n.kind??"sensor";return null}function ou(t,e){let n=t.states[e];if(!n)return null;let r=ly({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function ly(t){let e=null;for(let{device:n,status:r}of uo(t.entityId,t.state))if(n.marker)try{let i=n.marker(t);if(!i)continue;e={...e??{}},typeof i.icon=="string"&&i.icon&&(e.icon=i.icon),typeof i.text=="string"&&(e.text=i.text.slice(0,60)),typeof i.active=="boolean"&&(e.active=i.active)}catch(i){ru(r,i)}return e}function po(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function su(t,e){let n=[];for(let{device:r,status:i}of uo(t,e))r.settings?.length&&n.push({pluginId:i.id,name:i.name,settings:r.settings});return n}function au(t,e){let n={};for(let r of t??[]){let i=e?.[r.key],o=r.type==="number"?typeof i=="number"&&Number.isFinite(i):r.type==="boolean"?typeof i=="boolean":typeof i=="string"&&(r.options??[]).some(([s])=>s===i);n[r.key]=o?i:r.default}return n}function lu(t,e){for(let{device:n}of uo(t,e))if(n.floorWedge)return!0;return!1}var cy=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"]),dy=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),uy=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),hy=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Ot(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 du=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},je=(t,e)=>ee(e)??ho(e,t.states[e]);function cu(t,e){let n=t.states[e];if(!n||du(t,e))return!1;if(ho(e,n)!==null)return!0;let r=ee(e);if(!r)return!1;let i=n.attributes.device_class;return e.startsWith("event.")?!i||i==="button"||i==="doorbell":r==="sensor"?i?cy.has(i):dy.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?i?uy.has(i):!!t.entities?.[e]?.area_id:!0}function py(t,e){let n=t.states[e];return ee(e)!=="sensor"||!n?.attributes.unit_of_measurement||du(t,e)||hy.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||He(n)}var mo=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",ca=null;co(()=>ca=null);function da(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function fy(t){let e=new Map,n=new Map,r=new Map,i=new Map,o=[],s=d=>{(cu(t,d)||py(t,d))&&Dt(je(t,d))&&o.push(d)};for(let[d,u]of Object.entries(t.entities??{})){let p=u.device_id;p&&u.area_id&&(i.get(p)??i.set(p,new Set).get(p)).add(u.area_id),p&&mo(t,d)&&da(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ra(d));let h=Ot(t,d);h===null?s(d):cu(t,d)&&da(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let a=ia.indexOf("binary")-.5,l=d=>{let u=ee(d),p=u?ia.indexOf(u):a;return p>a&&ho(d,t.states[d])!==null?a:p};o.sort((d,u)=>l(d)-l(u)||B(t,d).localeCompare(B(t,u)));for(let[d,u]of e){let p=t.areas?.[d]?.name;u.sort((h,f)=>l(h)-l(f)||B(t,h,p).localeCompare(B(t,f,p)))}let c=new Set;for(let[d,u]of i)u.size>1&&c.add(d);return{entities:t.entities,devices:t.devices,states:t.states,stateCount:Object.keys(t.states).length,byArea:e,powerByDevice:n,withoutArea:o,domainsByDevice:r,hubs:c}}function Hn(t){let e=ca;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:ca=fy(t)}function we(t,e){let n=fo(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>fo(t,r))])]:n}function fo(t,e){return!e||!t.entities?[]:Hn(t).byArea.get(e)??[]}function uu(t,e){if(!t.entities)return[];let n=[];for(let[r,i]of Hn(t).byArea){let o=i.filter(s=>Dt(je(t,s)));r!==e&&o.length>0&&n.push({areaId:r,name:t.areas?.[r]?.name??r,ids:o})}return n.sort((r,i)=>r.name.localeCompare(i.name))}var hu=t=>t.entities?Hn(t).withoutArea:[],ua=(t,e)=>!!t.entities&&Hn(t).hubs.has(e),go=(t,e)=>t.entities?Hn(t).powerByDevice.get(e)??[]:[];function Ln(t,e){let n=new Map;for(let i of e)da(n,t.entities?.[i]?.device_id??`entity:${i}`).push(i);let r=new Map(e.map((i,o)=>[i,o]));return[...n.values()].map(i=>{let o=i.find(s=>!t.entities?.[s]?.name)??i[0];return{primary:o,others:i.filter(s=>s!==o)}}).sort((i,o)=>r.get(i.primary)-r.get(o.primary))}var _o=(t,e)=>Ln(t,e).map(n=>n.primary),my={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide",illuminance:"illuminance"};function ha(t,e,n,r=!1){let i=t.states[e]?.attributes;if(!i)return!1;let o=(i.symcon_variable_type===1||i.symcon_variable_type===2)&&typeof i.symcon_id=="number";if(typeof i.symcon_id=="number"&&!o||!o&&!/^(sensor|input_number|number)\./.test(e))return!1;if(r&&o)return!0;let s=String(i.unit_of_measurement??"").replace(/\s/g,"").toLowerCase();return n==="temperature"&&["\xB0c","\xB0f","\u2103","\u2109","k"].includes(s)||n==="humidity"&&!i.device_class&&["%","%rh","%r.h.","%rf","%r.f."].includes(s)||n==="co2"&&s==="ppm"&&/co[₂2]/i.test(String(i.friendly_name??""))||n==="illuminance"&&["lx","lux"].includes(s)?!0:i.device_class===my[n]}var gy=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),_y=["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"],by=new RegExp(`(${_y.join("|")})`,"i");function pa(t,e){let n=t.entities?.[e]?.device_id,r=n&&!ua(t,n)?Hn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(i=>gy.has(i))?!1:!by.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function pu(t,e,n,r){let i=n.climate?.[r];if(i==="none")return[];if(i)return[i].flat().filter(c=>t.states[c]);let o=(e?.placements??[]).filter(c=>c.entity_id.startsWith("sensor.")),s=o.filter(c=>C([c.x,c.z],n.points)).map(c=>c.entity_id),a=new Set(o.filter(c=>!C([c.x,c.z],n.points)).map(c=>c.entity_id));return[...new Set([...we(t,n).filter(c=>!a.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&ha(t,c,r)&&pa(t,c))}function fu(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 bo(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 yo(t,e){let n=e?t.states[e]:void 0;if(!n||He(n))return null;let r=n.attributes;if(r.nf_cover_control&&typeof r.current_position=="number")return r.current_position;let i=fu(n);if(i!==null)return i;if(typeof r.current_position=="number")return Math.max(0,Math.min(100,r.current_position));if(!n.state.trim())return null;let o=Number(n.state);if(!Number.isFinite(o))return null;let s=r.unit_of_measurement==="%"||o>1||o<0?o:o*100;return Math.max(0,Math.min(100,s))}var yy=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),vy=new Set(["garage","gate"]),wy=new Set(["window","opening"]);function Dr(t,e,n=!1){let r=new Map;return t.forEach((i,o)=>{let s=n&&e.length===1?e[0]:e[o];s&&r.set(i.id,s)}),r}var mu=(t,e)=>t==="none"?null:t??e??null,Ht=t=>t&&t!=="none"?t:null;function Lt(t,e){let n=new Map;for(let r of e)for(let i of r.rooms){let o=r.openings.filter(g=>g.room_id===i.id).sort((g,b)=>g.edge-b.edge||g.offset-b.offset);if(o.length===0)continue;let s=we(t,i),a=g=>t.states[g]?.attributes.device_class,l=g=>s.filter(b=>ee(b)==="binary"&&g(a(b)??"")),c=g=>o.filter(b=>b.type===g),d=Dr(c("window"),s.filter(g=>ee(g)==="cover"&&yy.has(a(g))),!0),u=Dr(c("window"),l(g=>wy.has(g))),p=Dr(c("door"),l(g=>g==="door")),h=Dr(c("garage"),s.filter(g=>ee(g)==="cover"&&vy.has(a(g)??""))),f=Dr(c("garage"),l(g=>g==="garage_door"));for(let g of o){let b=g.type==="window"?d:g.type==="garage"?h:null,y=g.type==="window"?u:g.type==="garage"?f:p,v=g.leaves===2;n.set(g.id,{cover:mu(g.cover,b?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:mu(g.contact,y.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Ht(g.contact2):null,tilt2:v?Ht(g.tilt2):null,position:Ht(g.position),positionInverted:!!g.position_inverted,tiltAngle:Ht(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"?Ht(g.lock):null,cover2:g.type==="garage"?null:Ht(g.cover2),coverTilt:Ht(g.cover_tilt),cover2Tilt:Ht(g.cover2_tilt),coverInverted:!!g.cover_inverted,coverTiltInverted:!!g.cover_tilt_inverted,cover2Inverted:!!g.cover2_inverted,cover2TiltInverted:!!g.cover2_tilt_inverted})}}return n}var xy=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function fa(t){if(!t||He(t))return null;let e=t.attributes.window_state;for(let n of[typeof e=="string"?e:"",t.state]){let r=n.trim(),i=r&&xy.find(([o])=>o.test(r));if(i)return i[1]}return null}var gu=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,_u=/(kühl|fridge|gefrier|freezer)/i,bu=/(spülmaschine|geschirrspül|dishwasher)/i,ky=/(kochfeld|herd|induktion|cooktop)/i,$y={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:gu,tv_wall:gu,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:_u,fridge_smart:_u,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:ky,sink:bu,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},yu={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 Cn=t=>vu.has(t)||!!dd(t),vo=t=>!!U(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),Hr=t=>Cn(t)||t==="desk"||t==="fridge_smart",Sy=t=>!!t&&t!=="none";function My(t,e){if(mo(t,e))return e;let n=t.entities?.[e]?.device_id;return n?go(t,n).find(r=>r!==e)??null:null}var Ey=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Or(t,e,n,r){return t.find(i=>e?.test(n(i)))??(r?t[0]??null:null)}function Re(t,e){let n=new Map;for(let r of e){let i=new Set([...r.furniture.flatMap(o=>[o.entity,o.power,o.fan_entity]),...r.placements.map(o=>o.entity_id)].filter(Sy));for(let o of r.furniture){let s=o.type in yu,a=Tn(o.type),l=s?yu[o.type]:$y[o.type];if(!l&&!a&&!vo(o.type)&&o.entity==null&&o.power==null)continue;let c=Ey(r,o.x,o.z),d=(c?_o(t,we(t,c)):[]).filter(b=>!i.has(b)),u=b=>`${b} ${B(t,b)}`,p=b=>d.filter(y=>ee(y)===b),h=o.entity==="none"?null:o.entity??null;if(o.entity==null){if(o.type==="ceiling_fan"){let b=(c?we(t,c):[]).filter(v=>!i.has(v)),y=new Set(b.filter(v=>ee(v)==="fan").map(v=>t.entities?.[v]?.device_id).filter(Boolean));h=b.find(v=>ee(v)==="light"&&y.has(t.entities?.[v]?.device_id))??Or(p("light"),l,u,!1)}else if(s)h=Or(p("light"),l,u,!0);else if(o.type==="robot_vacuum"){let b=c?.area_id??null;h=Object.keys(t.entities??{}).find(y=>y.startsWith("vacuum.")&&!i.has(y)&&Ot(t,y)===b)??null}else if(o.type==="radiator"||a)h=Or(p("climate"),l,u,!0);else if(Cn(o.type)){let b=p("media");h=b.find(y=>t.states[y]?.attributes.device_class==="tv")??Or(b,l,u,vu.has(o.type))}else if(vo(o.type)){let b=p("media").filter(y=>t.states[y]?.attributes.device_class!=="tv");h=Or(b,l,u,!1)??(b.length===1?b[0]:null)}else l&&(h=d.find(b=>["switch","media","fan"].includes(ee(b)??"")&&l.test(u(b)))??null);h&&i.add(h)}let f=o.power==="none"?null:o.power??null;o.power==null&&(f=h?My(t,h):null,!f&&l&&c&&!s&&(f=we(t,c).find(b=>mo(t,b)&&!i.has(b)&&l.test(u(b)))??null),f&&i.add(f));let g=null;if(o.type==="ceiling_fan"&&(g=o.fan_entity==="none"?null:o.fan_entity??null,o.fan_entity==null)){let b=(c?we(t,c):[]).filter(v=>ee(v)==="fan"&&!i.has(v)),y=h?t.entities?.[h]?.device_id:void 0;g=(y?b.find(v=>t.entities?.[v]?.device_id===y):void 0)??b[0]??null,g&&i.add(g)}(h||f||g)&&n.set(o.id,{entity:h,power:f,...o.type==="ceiling_fan"?{fan:g}:{}})}}return n}var wu=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function xu(t,e,n=[]){let r=[];for(let i of e){let o=(a,l)=>i.rooms.some(c=>c.points.length>=3&&C([a,l],c.points)),s=Re(t,[i]);r.push(...i.placements.filter(a=>a.outside||!o(a.x,a.z)).map(a=>a.entity_id)),r.push(...i.furniture.filter(a=>!o(a.x,a.z)).flatMap(a=>[s.get(a.id)?.entity,s.get(a.id)?.power]));for(let a of i.outdoor??[])a.area_id&&r.push(..._o(t,fo(t,a.area_id))),r.push(a.pump_entity,a.temp_entity)}return[...new Set(r.filter(i=>!!i&&!!t.states[i]&&!n.includes(i)))]}function Ry(t,e){return Math.min(...e.map((n,r)=>{let i=e[(r+1)%e.length],[o,s]=[i[0]-n[0],i[1]-n[1]],a=Math.min(1,Math.max(0,((t[0]-n[0])*o+(t[1]-n[1])*s)/(o*o+s*s||1)));return Math.hypot(t[0]-n[0]-o*a,t[1]-n[1]-s*a)}))}function $u(t,e,n=[]){let r=t.points;if(r.length<3||e.length===0)return[];let i=r.map(y=>y[0]),o=r.map(y=>y[1]),[s,a,l,c]=[Math.min(...i),Math.max(...i),Math.min(...o),Math.max(...o)],d=Math.min(a-s,c-l),u=Math.max(.1,Math.min(.25,d/8)),p=Math.min(.35,d/5),h=Math.min(.7,d/4),f=ve(r),g=[];for(let y=s+u/2;y=p&&g.push({at:w,wallDistance:k})}g.length===0&&g.push({at:f,wallDistance:0});let b=[...n];return e.map(y=>{let v=ee(y)==="light",w=g[0].at,k=-1/0;for(let{at:M,wallDistance:A}of g){let T=b.length?Math.min(...b.map(I=>Math.hypot(M[0]-I[0],M[1]-I[1]))):3,F=Math.hypot(M[0]-f[0],M[1]-f[1]),L=Math.min(T,3)*2;Fk+1e-9&&(k=L,w=M)}let x=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return b.push(x),{entity_id:y,x:x[0],z:x[1],y:null,mount:null}})}var ku=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function Su(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(o=>o.device_id===r&&o.entity_id.startsWith("sensor.")&&(ku.test(o.translation_key??"")||ku.test(o.entity_id.split(".")[1])))?.entity_id??null}var Z=t=>t?.symconObjects!==void 0;function Le(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 an(t){return!t||t.state==="unknown"||t.state==="unavailable"?null:t.attributes.symcon_value??t.attributes.symcon_numeric_value??t.state}function Ct(t){let e=an(t);if(e===null||typeof e=="boolean"||e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}function Lr(t){let e=an(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 ma(t){return an(t)===null?"\u2013":String(t?.attributes.symcon_formatted??an(t))}var ge=t=>/^(sensor|input_number|number)\./.test(t),wo=t=>/^(binary_sensor|input_boolean)\./.test(t);function Nn(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 Ay(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 O(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Ay(t,n),i=t?.states[n],o=typeof i?.attributes.symcon_path=="string"?i.attributes.symcon_path:void 0,s={id:n,label:r?`${B(t,n)} \xB7 ${r}`:B(t,n)};return o&&(s.detail=`Objektbaum: ${o}`),typeof i?.attributes.symcon_source_entity=="string"&&(s.sourceEntity=i.attributes.symcon_source_entity),s}).sort((n,r)=>n.label.localeCompare(r.label))}function Mu(t,e,n){return e.unsupported?[]:O(t,r=>Le(t,r,e.types)&&!e.excluded?.(r)).map(r=>{if(!e.role)return r;let i=t.states[r.id],o=`${e.role}.${i.attributes.symcon_id}`,s=n?t.states[n]:void 0,a=n&&(n===r.id||s?.attributes.symcon_source_entity===r.id)?n:t.states[o]?o:r.id;return a===r.id?r:{...r,id:a,sourceEntity:r.id}})}function xo(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var{I:Fy}=rd,Eu=t=>t;var Au=t=>t.strings===void 0,Ru=()=>document.createComment(""),Bn=(t,e,n)=>{let r=t._$AA.parentNode,i=e===void 0?t._$AB:e._$AA;if(n===void 0){let o=r.insertBefore(Ru(),i),s=r.insertBefore(Ru(),i);n=new Fy(o,s,t,t.options)}else{let o=n._$AB.nextSibling,s=n._$AM,a=s!==t;if(a){let l;n._$AQ?.(t),n._$AM=t,n._$AP!==void 0&&(l=t._$AU)!==s._$AU&&n._$AP(l)}if(o!==i||a){let l=n._$AA;for(;l!==o;){let c=Eu(l).nextSibling;Eu(r).insertBefore(l,i),l=c}}}return n},Nt=(t,e,n=t)=>(t._$AI(e,n),t),Ty={},Fu=(t,e=Ty)=>t._$AH=e,Tu=t=>t._$AH,ko=t=>{t._$AR(),t._$AA.remove()};var zu=(t,e,n)=>{let r=new Map;for(let i=e;i<=n;i++)r.set(t[i],i);return r},ln=sn(class extends It{constructor(t){if(super(t),t.type!==On.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 i=[],o=[],s=0;for(let a of t)i[s]=r?r(a,s):s,o[s]=n(a,s),s++;return{values:o,keys:i}}render(t,e,n){return this.dt(t,e,n).values}update(t,[e,n,r]){let i=Tu(t),{values:o,keys:s}=this.dt(e,n,r);if(!Array.isArray(i))return this.ut=s,o;let a=this.ut??=[],l=[],c,d,u=0,p=i.length-1,h=0,f=o.length-1;for(;u<=p&&h<=f;)if(i[u]===null)u++;else if(i[p]===null)p--;else if(a[u]===s[h])l[h]=Nt(i[u],o[h]),u++,h++;else if(a[p]===s[f])l[f]=Nt(i[p],o[f]),p--,f--;else if(a[u]===s[f])l[f]=Nt(i[u],o[f]),Bn(t,l[f+1],i[u]),u++,f--;else if(a[p]===s[h])l[h]=Nt(i[p],o[h]),Bn(t,i[u],i[p]),p--,h++;else if(c===void 0&&(c=zu(s,h,f),d=zu(a,u,p)),c.has(a[u]))if(c.has(a[p])){let g=d.get(s[h]),b=g!==void 0?i[g]:null;if(b===null){let y=Bn(t,i[u]);Nt(y,o[h]),l[h]=y}else l[h]=Nt(b,o[h]),Bn(t,i[u],b),i[g]=null;h++}else ko(i[p]),p--;else ko(i[u]),u++;for(;h<=f;){let g=Bn(t,l[f+1]);Nt(g,o[h]),l[h++]=g}for(;u<=p;){let g=i[u++];g!==null&&ko(g)}return this.ut=s,Fu(t,l),tt}});var zy=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),ga=-1,Iu=[{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"}],Pu=t=>t.object_type===1&&Iu.some(e=>e.type===t.module_type);function Py(t){let e=new Map(t.map(l=>[l.object_id,l])),n=t.filter(l=>{if(!Pu(l))return!1;let c=new Set([l.object_id]),d=e.get(l.parent_id);for(;d&&!c.has(d.object_id);){if(Pu(d))return!1;c.add(d.object_id),d=e.get(d.parent_id)}return!0});if(!n.length)return t;let r=new Map(e),i=new Map;for(let l of t){let c=i.get(l.parent_id)??[];c.push(l),i.set(l.parent_id,c)}let o=(l,c,d,u,p)=>({object_id:l,parent_id:c,name:d,path:u,position:p,object_type:0,hidden:!1,icon:"",virtual:!0});r.set(ga,o(ga,0,"System","System",Number.MAX_SAFE_INTEGER));let s=new Set,a=(l,c,d)=>{if(s.has(l.object_id))return;s.add(l.object_id);let u={...l,parent_id:c,path:`${d} / ${l.name}`};r.set(l.object_id,u);for(let p of i.get(l.object_id)??[])a(p,l.object_id,u.path)};return Iu.forEach((l,c)=>{let d=n.filter(h=>h.module_type===l.type);if(!d.length)return;let u=-10-l.type,p=`System / ${l.name}`;r.set(u,o(u,ga,l.name,p,c));for(let h of d)a(h,u,p)}),[...r.values()]}function _a(t){let e=Py(t),n=new Map(e.map(i=>[i.object_id,i])),r=new Map;for(let i of e){let o=n.has(i.parent_id)?i.parent_id:0,s=r.get(o)??[];s.push(i),r.set(o,s)}for(let i of r.values())i.sort((o,s)=>o.position-s.position||o.object_type-s.object_type||zy.compare(o.name,s.name));return{nodes:n,children:r}}function ba(t,e){let n=[],r=new Set([e]),i=t.nodes.get(e)?.parent_id;for(;i&&!r.has(i)&&t.nodes.has(i);)n.push(i),r.add(i),i=t.nodes.get(i)?.parent_id;return n}function ya(t,e,n=""){let r=n.trim().toLocaleLowerCase("de").split(/\s+/).filter(Boolean),i=r.length?new Set:null;if(i){for(let l of t.nodes.values())if(r.every(c=>`${l.name} ${l.path}`.toLocaleLowerCase("de").includes(c))){i.add(l.object_id);for(let c of ba(t,l.object_id))i.add(c)}}let o=[],s=new Set,a=(l,c)=>{let d=(t.children.get(l)??[]).filter(u=>!i||i.has(u.object_id));d.forEach((u,p)=>{if(s.has(u.object_id))return;s.add(u.object_id);let h=(t.children.get(u.object_id)?.length??0)>0,f=h&&(!!i||e.has(u.object_id));o.push({node:u,depth:c,hasChildren:h,expanded:f,index:p+1,siblings:d.length}),f&&a(u.object_id,c+1)})};return a(0,0),o}var Du=["Boolean","Integer","Float","String"],Iy={light:"Licht",cover:"Jalousie/Tor",switch:"Schalter",binary_sensor:"Bin\xE4rsensor",sensor:"Sensor",climate:"Heizung",lock:"Schloss",script:"Skript",schedule:"Schaltuhr",media_player:"Medienger\xE4t",fan:"L\xFCfter"};function Ou(t,e={}){if(t.virtual||t.object_type===0)return"Das ist eine Kategorie. Klappe sie auf und w\xE4hle den Datenpunkt darunter aus.";if(t.object_type===1)return"Das ist eine Instanz. Klappe sie auf und w\xE4hle ihre Variable aus, zum Beispiel \u201EValue\u201C.";if(e.schedule&&t.object_type!==4)return"Hier wird eine klassische Symcon-Schaltuhr (Wochenplan-Ereignis) erwartet, keine Variable.";if(e.unsupported)return e.unsupported;if(!t.entity_id)return t.object_type===2?"Diese Variable wurde noch nicht geladen. Lade die Variablen oben in der Titelleiste neu und \xF6ffne die Auswahl erneut.":t.object_type===6?"Dieser Link verweist auf keinen unterst\xFCtzten Datenpunkt. W\xE4hle die Variable direkt im Objektbaum aus.":t.object_type===4?"Dieses Ereignis ist keine unterst\xFCtzte klassische Symcon-Schaltuhr (Wochenplan).":"Dieser Objekttyp kann in diesem Feld nicht verkn\xFCpft werden. W\xE4hle eine passende Variable aus.";let n=e.states?.[t.entity_id];if(e.states&&!n)return"Diese Variable ist im aktuellen Datenbestand nicht mehr vorhanden. Lade die Variablen oben in der Titelleiste neu.";let r=n?.attributes.symcon_variable_type,i=r===void 0?void 0:Du[Number(r)];if(n&&!n.attributes.symcon_schedule&&!i)return"Der native Datentyp dieser Variable ist nicht verf\xFCgbar. Lade die Variablen oben in der Titelleiste neu.";if(i&&e.types&&!e.types.includes(Number(r)))return`Datentyp ${i} passt hier nicht. F\xFCr \u201E${e.label||"dieses Feld"}\u201C wird ${e.types.map(c=>Du[c]).join(" oder ")} ben\xF6tigt.`;let o=e.excluded?.(t.entity_id);if(o)return o;let s=Iy[t.entity_id.split(".")[0]],a=n?.attributes.unit_of_measurement,l=[i&&`Datentyp: ${i}`,a&&`Einheit: ${a}`,s&&`erkannte Funktion: ${s}`].filter(Boolean).join(" \xB7 ");return`Dieser Datenpunkt erf\xFCllt den Filter${e.label?` f\xFCr \u201E${e.label}\u201C`:" dieses Feldes"} nicht.${l?` ${l}.`:""}`}var Dy=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],va=class extends q{static properties={objects:{attribute:!1},options:{attribute:!1},fixed:{attribute:!1},value:{attribute:!1},disabled:{type:Boolean},placeholder:{attribute:!1},context:{attribute:!1},_notice:{state:!0},_query:{state:!0},_expanded:{state:!0},_pending:{state:!0},_active:{state:!0},_selected:{state:!0}};tree=_a([]);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._notice="",this._query="",this._expanded=new Set,this._pending=null,this._active=null,this._selected=null}willUpdate(e){e.has("objects")&&(this.tree=_a(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(i=>i.entity_id===n&&(i.object_type===2||i.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="",this._notice="";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 ba(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,this._notice=""):(this._pending=null,this._selected=null,this._notice=Ou(e,this.context))}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=ya(this.tree,this._expanded,this._query),r=Math.max(0,n.findIndex(s=>s.node.object_id===this._active)),i=n[r];if(!i)return;let o=r;if(e.key==="ArrowDown")o=Math.min(n.length-1,r+1);else if(e.key==="ArrowUp")o=Math.max(0,r-1);else if(e.key==="Home")o=0;else if(e.key==="End")o=n.length-1;else if(e.key==="ArrowRight")i.hasChildren&&!i.expanded?this.toggle(i.node.object_id):i.hasChildren&&(o=Math.min(n.length-1,r+1));else if(e.key==="ArrowLeft")i.expanded&&!this._query?this.toggle(i.node.object_id):o=Math.max(0,n.findIndex(s=>s.node.object_id===i.node.parent_id));else if(e.key===" "||e.key==="Enter")this.select(i.node),e.key==="Enter"&&this.entityFor(i.node)&&this.commit();else return;e.preventDefault(),(o!==r||this._active===null)&&(this._active=n[o].node.object_id),await this.updateComplete,this.renderRoot.querySelector(`#object-${this._active}`)?.scrollIntoView({block:"nearest"})}icon(e){let n=[E``,E``,E``,E``,E``,E``,E``];return E``}renderRow(e){let{node:n}=e,r=this.entityFor(n),i=!!r;return m`{this.select(n),this.renderRoot.querySelector(".tree")?.focus()}}
@dblclick=${()=>{i?(this.select(n),this.commit()):e.hasChildren&&this.toggle(n.object_id)}}>
${this.icon(n.object_type)}${n.name||"(Ohne Namen)"}
${n.virtual?"Systembereich":Dy[n.object_type]??"Objekt"}${n.hidden?" \xB7 ausgeblendet":""}
${i&&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??""),i=this._selected===null?void 0:this.tree.nodes.get(this._selected),o=(i&&this.entityFor(i)===this._pending?i:void 0)??this.variableNode(this._pending),s=ya(this.tree,this._expanded,this._query),a=s.find(c=>c.node.object_id===this._active),l=!!this.value&&!this.fixed.some(c=>c.id===this.value);return m`${l?m``:_}
`}static styles=[fe,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; }
button:disabled { opacity:.45; cursor:default; }
button:focus-visible,input:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
.field { display:flex; gap:6px; min-width:0; }
.trigger { flex:1; min-width:0; width:100%; display:flex; align-items:center; justify-content:space-between; text-align:left; gap:12px; padding:9px 11px; }
.trigger-text { flex:1; min-width:0; overflow:hidden; }
.trigger strong { display:block; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.picker-icon { flex:none; }
.clear { flex:none; width:32px; padding:0; font-size:22px; }
strong { font-weight:500; } small { display:block; color:var(--nf-muted); font-size:11px; }
.trigger small { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-top:3px; }
dialog { width:min(780px,calc(100vw - 32px)); max-width:none; height:min(690px,calc(100dvh - 32px)); max-height:none; box-sizing:border-box; padding:0; border:1px solid var(--nf-line); border-radius:16px; color:var(--nf-text); background:var(--nf-chrome-solid); box-shadow:0 24px 80px #0008; font:14px system-ui,sans-serif; }
dialog[open] { display:flex; flex-direction:column; }
dialog::backdrop { background:#050b16a6; backdrop-filter:blur(3px); }
header { display:flex; align-items:center; justify-content:space-between; padding:20px 22px 16px; border-bottom:1px solid var(--nf-line); }
h2 { font-size:18px; font-weight:600; margin:0 0 4px; } header p { margin:0; color:var(--nf-muted); font-size:12px; }
.close { font-size:25px; padding:0; width:32px; height:32px; border-color:transparent; }
.search-bar { display:flex; align-items:center; gap:12px; padding:16px 20px 10px; }
.search { flex:1; min-width:0; border:1px solid var(--nf-line); border-radius:9px; padding:10px 12px; background:var(--nf-bg); color:var(--nf-text); }
.text-button { border:0; background:transparent; color:var(--nf-muted); font-size:12px; padding:6px 0; white-space:nowrap; }
.fixed { display:flex; flex-wrap:wrap; gap:6px; padding:0 20px 10px; }
.fixed button { padding:5px 10px; font-size:12px; }
.fixed [aria-pressed=true] { color:var(--nf-accent); border-color:var(--nf-accent); }
.tree { flex:1; min-height:80px; overflow:auto; overscroll-behavior:contain; margin:0 12px; padding:4px 0 12px; outline-offset:-2px; }
.node { display:flex; align-items:center; gap:8px; min-height:34px; border-radius:6px; padding:2px 10px 2px calc(4px + var(--depth)*22px); box-sizing:border-box; width:max-content; min-width:100%; }
.node:hover { background:color-mix(in srgb,var(--nf-accent) 8%,transparent); }
.node.active { outline:1px solid color-mix(in srgb,var(--nf-accent) 40%,transparent); outline-offset:-1px; }
.node[aria-selected=true] { background:color-mix(in srgb,var(--nf-accent) 16%,transparent); color:var(--nf-accent); }
.node.selectable { cursor:pointer; }
.node[aria-disabled=true] .node-name { color:var(--nf-muted); }
.node.hidden-object .node-name { font-style:italic; }
.node-name { flex:1; white-space:nowrap; }
.node small { margin-left:20px; white-space:nowrap; }
.twisty { border:0; background:transparent; border-radius:4px; padding:0; width:20px; height:26px; flex:none; font-size:18px; }
.icon { flex:none; width:17px; height:17px; color:#8796a9; } .type-0 { color:#c69a42; } .type-1 { color:#8d9ac6; } .type-2 { color:#55a58c; }
.selected-mark { margin-left:8px; }
.empty { padding:20px; color:var(--nf-muted); }
.rejection { flex:none; margin:0 20px 12px; padding:8px 10px; border-left:2px solid #e5b56d; border-radius:4px; background:#e5b56d0c; color:var(--nf-text); font-size:12px; line-height:1.4; overflow-wrap:anywhere; }
footer { display:flex; align-items:center; justify-content:space-between; gap:16px; border-top:1px solid var(--nf-line); padding:15px 20px; }
.selection { min-width:0; } .selection small { margin-top:4px; overflow-wrap:anywhere; }
.actions { display:flex; gap:8px; flex-shrink:0; }
.apply { color:white; background:var(--nf-accent); border-color:transparent; }
@media(max-width:580px) {
dialog { width:calc(100vw - 16px); height:calc(100dvh - 32px); border-radius:12px; }
header { padding:16px; } .search-bar { padding:12px; gap:8px; } .fixed { padding:0 12px 8px; }
.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",va);var Hu=40,wa=class extends q{static properties={options:{attribute:!1},objectTree:{attribute:!1},context:{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 a=`${s.label} ${s.detail??s.id}`.toLowerCase();return n.every(l=>a.includes(l))},i=this.fixed.filter(s=>!e||r(s)),o=e?this.options.filter(r):this.options;return[...i,...o.slice(0,Hu)]}get leftOut(){let e=this._query.trim().toLowerCase(),n=e.split(/\s+/).filter(Boolean),r=e?this.options.filter(i=>n.every(o=>`${i.label} ${i.detail??i.id}`.toLowerCase().includes(o))).length:this.options.length;return Math.max(0,r-Hu)}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}}
>`;let e=this.current,n=this._open?this.hits:[];return m``}static styles=[fe,J`
:host {
display: block;
position: relative;
min-width: 0;
max-width: 100%;
}
input {
width: 100%;
box-sizing: border-box;
font: inherit;
color: var(--nf-text);
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 10px;
padding: 8px 10px;
}
input::placeholder {
color: var(--nf-text);
opacity: 0.9;
}
input:focus::placeholder {
color: var(--nf-muted);
}
input:focus {
outline: 2px solid var(--nf-accent);
outline-offset: -1px;
}
.list {
position: absolute;
left: 0;
right: 0;
top: calc(100% + 4px);
z-index: 20;
margin: 0;
padding: 4px;
list-style: none;
max-height: 280px;
overflow-y: auto;
background: var(--nf-chrome-solid);
border: 1px solid var(--nf-line);
border-radius: 10px;
box-shadow: var(--nf-shadow);
}
li {
display: flex;
flex-direction: column;
gap: 1px;
padding: 6px 8px;
border-radius: 6px;
cursor: pointer;
font-size: 13.5px;
}
li small {
color: var(--nf-muted);
font-size: 11px;
}
li.cursor,
li:hover {
background: color-mix(in srgb, var(--nf-accent) 18%, transparent);
}
li.chosen {
color: var(--nf-accent);
}
li.empty {
color: var(--nf-muted);
cursor: default;
}
`]};customElements.get("nf-entity-picker")||customElements.define("nf-entity-picker",wa);var xa=class extends q{static properties={text:{attribute:!1}};constructor(){super(),this.text=""}get dialog(){return this.renderRoot.querySelector("dialog")}render(){return m`
`}static styles=[fe,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; }
button:hover { color:var(--nf-accent); }
button:focus-visible { outline:2px solid var(--nf-accent); outline-offset:2px; }
dialog { box-sizing:border-box; width:min(560px,calc(100vw - 32px)); max-height:80vh; max-height:80dvh; overflow:auto; padding:18px 22px; border:1px solid var(--nf-line); border-radius:14px; background:var(--nf-chrome-solid); color:var(--nf-text); font:14px/1.5 system-ui,sans-serif; box-shadow:var(--nf-shadow); pointer-events:auto; }
dialog::backdrop { background:#050b16a6; }
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",xa);var cn=t=>t.target.value,ka=t=>Number.parseFloat(t.replace(",",".")),ae=t=>Math.round(t*1e3)/1e3,Lu=t=>t.wide?"nf-field nf-wide":"nf-field";function R(t,e,n,r,i=.01,o){return m``}function W(t,e,n,r,i={}){return m``}function H(t,e,n,r,i,o={}){return m``}function D(t,e,n,r,i={}){return m``}function Ge(t,e,n,r,i){return m``}function z(t,e,n,r,i,o,s={}){let a=r===void 0?null:r?t.t("entity_auto",{name:B(t.hass,r)}):t.t("entity_auto_none"),l=[...a!==null?[{id:"__auto",label:a}]:[],{id:"none",label:t.t("entity_none")}],c=n??(a!==null?"__auto":"none"),d=t.hass?.symconObjects!==void 0&&!s.schedule?Mu(t.hass,s,n):i;return m``}function Vn(t,e,n){return n?(n.startsWith("mdi:")?n:`mdi:${n}`).replace(/[^a-z0-9:-]/gi,""):t.hass?ou(t.hass,e):null}function Bt(t,e,n){let r=e?(e.startsWith("mdi:")?e:`mdi:${e}`).replace(/[^a-z0-9:-]/gi,""):"";return m``}function Wn(t,e,n){return m``}function Vt(t,e,n){let r=e??{},i=o=>s=>{let a={...r,[o]:Math.round(Math.max(-5,Math.min(5,s))*100)/100};n(a.x||a.z||a.y?a:null)};return m`
${t.t("pin_shift")}
${R(t,"\u2194 x",r.x??0,i("x"),.05)} ${R(t,"\u2195 z",r.z??0,i("z"),.05)} ${R(t,t.t("pin_shift_up"),r.y??0,i("y"),.05)}
${e?m``:_}
${S(t.t("pin_shift_hint"),"nf-wide")}
`}var Q=(...t)=>m`${t}
`,S=(t,e="")=>m``;function dn(t,e,n,r={}){let i=r.lowest??10;return m``}var $a=class extends q{static properties={doc:{attribute:!1},admin:{type:Boolean},suggestedName:{attribute:!1},locationId:{state:!0},branchId:{state:!0},buildingId:{state:!0}};constructor(){super(),this.admin=!1,this.suggestedName="Geb\xE4ude 1",this.locationId="",this.branchId="",this.buildingId=""}willUpdate(e){let n=this.doc?.topology;if(!n)return;n.locations.some(o=>o.id===this.locationId)||(this.locationId=n.locations[0]?.id??"");let r=n.branches.filter(o=>o.location_id===this.locationId);r.some(o=>o.id===this.branchId)||(this.branchId=r[0]?.id??"");let i=n.buildings.filter(o=>o.branch_id===this.branchId);i.some(o=>o.id===this.buildingId)||(this.buildingId=i[0]?.id??"")}edit(e){if(!this.admin||!this.doc?.topology)return;let n=structuredClone(this.doc);e(n,n.topology),this.publish(n)}publish(e){this.doc=e,this.dispatchEvent(new CustomEvent("hierarchy-change",{detail:{building:e},bubbles:!0,composed:!0}))}open(e){this.dispatchEvent(new CustomEvent("hierarchy-open",{detail:e,bubbles:!0,composed:!0}))}name(e,n,r){return m``}render(){let e=this.doc?.topology;if(!e)return m`${S("Vorhandene Etagen werden einem ersten Ort, einer Niederlassung und einem Geb\xE4ude zugeordnet. Geometrie, Raumverkn\xFCpfungen und Benutzerrechte bleiben erhalten.")}
`;let n=e.locations.find(o=>o.id===this.locationId),r=e.branches.find(o=>o.id===this.branchId),i=e.buildings.find(o=>o.id===this.buildingId);return m`${S("Hier pflegst du Ort, Niederlassung und Geb\xE4ude. Die Listen wechseln nur die Auswahl. Etagen legst du anschlie\xDFend oben im Editor im gew\xE4hlten Geb\xE4ude an. R\xE4ume und ihre Symcon-Bereichskategorie bearbeitest du rechts auf der ausgew\xE4hlten Etage.")}
Orte
${e.locations.map(o=>m``)}
${n?m`${this.name("Name des Ortes",n.name,o=>{this.locationId===n.id&&this.edit((s,a)=>{a.locations.find(l=>l.id===n.id).name=o})})}
`:_}
Niederlassungen
${e.branches.filter(o=>o.location_id===this.locationId).map(o=>m``)}
${r?m`${this.name("Name der Niederlassung",r.name,o=>{this.branchId===r.id&&this.edit((s,a)=>{a.branches.find(l=>l.id===r.id).name=o})})}
`:_}
Gebäude
${e.buildings.filter(o=>o.branch_id===this.branchId).map(o=>m``)}
${i?m`${this.name("Name des Geb\xE4udes",i.name,o=>{this.buildingId===i.id&&this.edit((s,a)=>{a.buildings.find(l=>l.id===i.id).name=o})})}
`:_}
`}static styles=[fe,J`
:host{display:block;font:13px/1.4 system-ui;color:var(--nf-text)}button,input,select{box-sizing:border-box;font:inherit;color:inherit;background:var(--nf-fill,#ffffff08);border:1px solid var(--nf-line);border-radius:8px;padding:8px 10px;min-width:0}button{cursor:pointer}button:disabled,input:disabled,select:disabled{opacity:.45;cursor:default}button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--nf-accent);outline-offset:2px}.columns{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}.help{margin-bottom:8px}section{min-width:0;border:1px solid var(--nf-line);border-radius:12px;padding:12px}h3{font-size:14px;margin:0 0 10px}.items{display:grid;align-content:start;gap:5px;min-height:100px;max-height:240px;overflow:auto;margin-bottom:10px}.pick{text-align:left;display:flex;justify-content:space-between;gap:8px;overflow-wrap:anywhere}.pick[aria-pressed=true]{border-color:var(--nf-accent);background:color-mix(in srgb,var(--nf-accent) 15%,transparent)}small{white-space:nowrap;color:var(--nf-muted)}.details{display:grid;gap:10px;margin-top:18px;padding-top:12px;border-top:1px solid var(--nf-line)}label{display:grid;gap:5px;font-size:12px;color:var(--nf-muted)}input,select{width:100%;color:var(--nf-text)}.delete{color:var(--nf-muted)}.primary{border-color:var(--nf-accent)}.setup{display:flex;gap:10px;align-items:center}@media(max-width:720px){.columns{grid-template-columns:1fr}.items{min-height:0;max-height:140px}.details{margin-top:10px}section{padding:10px}}
`]};customElements.get("nf-hierarchy-manager")||customElements.define("nf-hierarchy-manager",$a);var Cu=new WeakMap,Nu=new WeakMap;function Bu(t,e){let n=Nu.get(t)??t,r=Cu.get(n)??new WeakMap;Cu.set(n,r);let i=r.get(e);if(i)return i;let o=new Map;for(let l of e)for(let c of l.placements)c.entity_id.startsWith("cover.")&&o.set(c.entity_id,{tilt:c.cover_tilt==="none"?null:c.cover_tilt,position:c.position});for(let l of Lt(n,e).values())l.cover&&!o.has(l.cover)&&o.set(l.cover,{tilt:l.coverTilt,position:l.position}),l.cover2&&!o.has(l.cover2)&&o.set(l.cover2,{tilt:l.cover2Tilt});let s={...n.states};for(let[l,c]of o){let d=n.states[l];if(!d)continue;let u={...d.attributes,nf_cover_control:!0},p=yo(n,c.position);p===null&&(p=typeof d.attributes.current_position=="number"?d.attributes.current_position:null),p!==null&&(u.current_position=p);let h=c.tilt?n.states[c.tilt]:d,f=typeof h?.attributes.current_tilt_position=="number"?h.attributes.current_tilt_position:c.tilt?yo(n,c.tilt):null;f!==null&&(u.current_tilt_position=f,u.supported_features=Number(u.supported_features??0)|128);let g=d.state;typeof u.current_position=="number"&&g!=="unavailable"&&g!=="unknown"&&g!=="opening"&&g!=="closing"&&(g=u.current_position>0?"open":"closed"),s[l]={...d,state:g,attributes:u}}let a={...n,states:s,callService:async(l,c,d={})=>{if(l!=="cover")return n.callService(l,c,d);let u=Array.isArray(d.entity_id)?d.entity_id:[d.entity_id],p=async h=>{let f=typeof h=="string"?o.get(h):void 0;if(!f)return n.callService(l,c,{...d,entity_id:h});let g={...d,entity_id:h},b=c;(b==="toggle"||b==="toggle_cover")&&(b=s[String(h)]?.state==="closed"?"open_cover":"close_cover");let y=b.includes("tilt");y&&f.tilt&&(g.entity_id=f.tilt);let v=f.tilt?n.states[f.tilt]:void 0;return y&&f.tilt&&!v?.attributes.symcon_id&&typeof v?.attributes.current_tilt_position!="number"&&(b==="set_cover_tilt_position"?(b="set_cover_position",g.position=g.tilt_position,delete g.tilt_position):b==="open_cover_tilt"?b="open_cover":b==="close_cover_tilt"&&(b="close_cover")),n.callService(l,b,g)};return Array.isArray(d.entity_id)?Promise.all(u.map(p)):p(u[0])}};return Nu.set(a,n),r.set(e,a),a}function Vu(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 Wu="weather.nextfloor_symcon",ju={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"},Ku=new WeakMap;function Oy(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 Gu(t,e){if(!Z(t))return t;let n=e.weather_variables??{};if(!e.rain_sensor&&!Object.values(n).some(h=>h&&h!=="none"))return t;let r=Ku.get(t)??new WeakMap;Ku.set(t,r);let i=r.get(e);if(i)return i;let o={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=Ct(f);g!==null&&(o[h]=h==="cloud_coverage"&&f?.attributes.symcon_max===1?g*100:g),f?.attributes.unit_of_measurement&&(o[`${h}_unit`]=f.attributes.unit_of_measurement)}for(let h of["wind_speed","wind_gust_speed"]){let f=s(h),g=Ct(f);g!==null&&(o[h]=Vu(g,f?.attributes.unit_of_measurement))}o.wind_speed_unit="km/h";let a=an(s("wind_bearing"));a!==null&&(o.wind_bearing=a);let l=Oy(ma(s("condition"))),c=e.rain_sensor?t.states[e.rain_sensor]:void 0,d=Lr(c);d!==null&&e.rain_sensor_inverted&&(d=!d),d===null&&typeof o.precipitation=="number"&&(d=o.precipitation>0),Lr(s("lightning"))?l=d?"lightning-rainy":"lightning":Lr(s("snow"))?l=d?"snowy-rainy":"snowy":Lr(s("fog"))?l="fog":d===!0?l=Number(o.precipitation??0)>=8?"pouring":"rainy":d===!1&&l&&/rain|pouring/.test(l)&&(l=null),!l&&typeof o.cloud_coverage=="number"&&(l=o.cloud_coverage>70?"cloudy":o.cloud_coverage>20?"partlycloudy":"sunny"),!l&&d===!1&&(l="sunny");let u={entity_id:Wu,state:l??"unknown",attributes:o},p={...t,states:{...t.states,[Wu]:u}};return r.set(e,p),p}var rt=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function $o(t,e){return(await rt(t,"image/get",{image_id:e})).data}async function Wt(t,e,n){await rt(t,"image/set",{image_id:e,data:n})}async function Uu(t){return(await rt(t,"history/list")).snapshots}async function Zu(t,e){return(await rt(t,"history/snapshot",e?{name:e}:{})).id}async function qu(t,e){return(await rt(t,"history/get",{snapshot_id:e})).building}async function Yu(t,e){await rt(t,"history/delete",{snapshot_id:e})}async function Xu(t,e){return(await rt(t,"history/restore",{snapshot_id:e})).revision}var Cr=(t,e)=>rt(t,"packs/import",{pack:e});async function Ju(t,e){await rt(t,"packs/remove",{pack_id:e})}var Qu=t=>rt(t,"backup/export"),eh=(t,e,n)=>rt(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],ft=(t,e)=>[t[0]+e[0],t[1]+e[1]],it=(t,e)=>[t[0]*e,t[1]*e],te=(t,e)=>t[0]*e[0]+t[1]*e[1],Ae=(t,e)=>t[0]*e[1]-t[1]*e[0],_e=t=>Math.hypot(t[0],t[1]),ot=t=>{let e=_e(t)||1;return[t[0]/e,t[1]/e]},Sa=t=>[-t[1],t[0]],Ma=t=>[t[1],-t[0]];var Hy=.05,Ly=.2,Cy=.12;function Ny(t){let e=[];return t.forEach((n,r)=>{let i=n.points;if(i.length<3)return;let o=be(i)>=0;i.forEach((s,a)=>{let l=i[(a+1)%i.length],c=_e(G(l,s));if(c<.05)return;let d=[(l[0]-s[0])/c,(l[1]-s[1])/c],u=o?[d[1],-d[0]]:[-d[1],d[0]];(d[1]<-1e-9||Math.abs(d[1])<=1e-9&&d[0]<0)&&(d=[-d[0],-d[1]]);let p=[-d[1],d[0]],[h,f]=[te(s,d),te(l,d)];e.push({room:r,index:a,dir:d,normal:p,offset:te(s,p),outside:te(u,p)>0?1:-1,from:Math.min(h,f),to:Math.max(h,f)})})}),e}function By(t,e,n){if(t.room===e.room||Math.abs(Ae(t.dir,e.dir))>Hy||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Cy||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function th(t,e=.6){let n=Ny(t),r=n.map((g,b)=>b),i=g=>r[g]===g?g:r[g]=i(r[g]),o=[],s=new Set,a=[];for(let g=0;gMath.abs(g[2])-Math.abs(b[2]));let l=new Map(n.map((g,b)=>[b,[b]])),c=(g,b)=>g.some(y=>b.some(v=>n[y].room===n[v].room&&Math.abs(n[y].offset-n[v].offset)>=.002));for(let[g,b,y]of a){let[v,w]=[i(g),i(b)];if(v!==w){if(c(l.get(v),l.get(w)))continue;r[v]=w,l.set(w,[...l.get(w),...l.get(v)]),l.delete(v)}o.push(Ea(y)),s.add(g).add(b)}let d=new Map(n.map((g,b)=>[`${g.room}:${g.index}`,b]));for(let g=s.size>0;g;)g=!1,n.forEach((b,y)=>{let v=d.get(`${b.room}:${(b.index+1)%t[b.room].points.length}`);if(v===void 0||v===y)return;let w=n[v];!(Math.abs(Ae(b.dir,w.dir))<1e-6&&Math.abs(b.offset-w.offset)<.002&&b.outside===w.outside)||s.has(y)===s.has(v)||(s.add(y).add(v),g=!0)});n.forEach((g,b)=>{let y=d.get(`${g.room}:${(g.index+1)%t[g.room].points.length}`);if(y===void 0||y===b||!s.has(b)||!s.has(y))return;let v=n[y];Math.abs(Ae(g.dir,v.dir))<1e-6&&Math.abs(g.offset-v.offset)<.002&&g.outside===v.outside&&(r[i(b)]=i(y))});let u=()=>t.map(g=>({...g,points:g.points.map(b=>[b[0],b[1]])}));if(o.length===0)return{rooms:u(),gaps:o};let p=new Map;for(let g of s)p.set(i(g),[...p.get(i(g))??[],g]);let h=t.map(g=>g.points.map(()=>new Map));for(let[g,b]of p){let y=new Map(b.map(w=>[`${n[w].room}:${Math.round(n[w].offset*500)}`,n[w].offset])),v=[...y.values()].reduce((w,k)=>w+k,0)/y.size;for(let w of b){let k=n[w],x=[k.normal[0]*(v-k.offset),k.normal[1]*(v-k.offset)];h[k.room][k.index].set(g,x),h[k.room][(k.index+1)%t[k.room].points.length].set(g,x)}}return{rooms:t.map((g,b)=>({...g,points:g.points.map((y,v)=>{let w=[...h[b][v].values()].reduce((k,x)=>[k[0]+x[0],k[1]+x[1]],[y[0],y[1]]);return[Ea(w[0]),Ea(w[1])]})})),gaps:o}}function nh(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 Vy=.25,rh=t=>Math.round(t*1e3)/1e3,ih=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Aa(t,e,n,r,i){let o=ih(t,e,n);if(!o)return[r,i];let s=(a,l)=>C([a,l],o.points);return s(r,i)?[r,i]:s(r,n)?[r,n]:s(e,i)?[e,i]:[e,n]}function Wy(t,e,n,r){return t.rooms.some(i=>i.id!==e.id&&i.points.some((o,s)=>{let a=i.points[(s+1)%i.points.length];return Math.abs(te(G(o,n),r))<.02&&Math.abs(te(G(a,n),r))<.02}))}var Ra=(t,e)=>Math.abs((t-e+540)%360-180);function Nr(t,e,n,r=Vy){let i=ih(t,e.x,e.z);if(!i)return null;let o=i.points,s=be(o)>=0?1:-1,a=null;return o.forEach((l,c)=>{let d=o[(c+1)%o.length],u=_e(G(d,l));if(u<.3)return;let p=[(d[0]-l[0])/u,(d[1]-l[1])/u],h=[-p[1]*s,p[0]*s],f=te(G([e.x,e.z],l),p);if(f<0||f>u)return;let g=Wy(t,i,l,h)?n/2:0,b=te(G([e.x,e.z],l),h)-g,y=Math.atan2(-h[0],h[1])*180/Math.PI,w=[{rotation:y,extent:e.d/2},{rotation:y+90,extent:e.w/2},{rotation:y-90,extent:e.w/2}].reduce((x,M)=>Ra(e.rotation,M.rotation)50)return;let k=b-w.extent;Math.abs(k)>r||a&&Math.abs(k)>=Math.abs(a.gap)||(a={x:rh(e.x-h[0]*k),z:rh(e.z-h[1]*k),rotation:(Math.round(w.rotation)%360+360)%360,gap:k})}),a&&{x:a.x,z:a.z,rotation:a.rotation}}var Kn=Math.PI/180,st=t=>Math.tan(Math.min(80,Math.max(0,t))*Kn);function Vr(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 oh(t){if(!t.rotation)return null;let e=t.rotation*Kn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function sh(t,e){let n=oh(t);if(!n)return e;let[r,i]=[e[0]-n.cx,e[1]-n.cz];return[n.cx+r*n.c-i*n.sn,n.cz+r*n.sn+i*n.c]}function Fa(t,e,n){let r=oh(t);if(!r)return[e,n];let[i,o]=[e-r.cx,n-r.cz];return[r.cx+i*r.c+o*r.sn,r.cz-i*r.sn+o*r.c]}function Wr(t,e=0){let{x0:n,x1:r,z0:i,z1:o}=Vr(t);return[[n-e,i-e],[r+e,i-e],[r+e,o+e],[n-e,o+e]].map(s=>sh(t,s))}function $e(t){let{x0:e,x1:n,z0:r,z1:i}=Vr(t),o=s=>sh(t,s);return t.axis==="x"?{u0:e,u1:n,w:i-r,at:(s,a)=>o([s,t.flip?i-a:r+a])}:{u0:r,u1:i,w:n-e,at:(s,a)=>o([t.flip?n-a:e+a,s])}}function Kr(t,e,n){let{x0:r,x1:i,z0:o,z1:s}=Vr(t),[a,l]=Fa(t,e,n);return t.axis==="x"?[a,t.flip?s-l:l-o]:[l,t.flip?i-a:a-r]}var Br=Math.tan(30*Kn);function jr(t,e,n,r,i){let o=Math.min(t*.3,r>1e-6?2.4/r:t*.3),s=Math.min(t*.3,i>1e-6?2.4/i:t*.3),a=e+o*r,l=n+s*i,c=Math.min(t-s,Math.max(o,(l-a+Br*(t-s+o))/(2*Br))),d=a+(c-o)*Br;return{vla:o,vlb:s,yla:a,ylb:l,vr:c,rh:d,y:p=>p<=o?e+p*r:p<=c?a+(p-o)*Br:p<=t-s?l+(t-s-p)*Br:n+(t-p)*i}}function Ce(t){let e=$e(t).w,[n,r]=[t.eave_a,t.eave_b],[i,o]=[st(t.pitch_a),st(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*i,y:s=>n+s*i};case"mansard":{let s=jr(e,n,r,i,o);return{vr:s.vr,rh:s.rh,y:s.y}}default:{let s=i+o>1e-6?Math.min(e,Math.max(0,(r-n+e*o)/(i+o))):e/2;return{vr:s,rh:n+s*i,y:a=>a<=s?n+a*i:r+(e-a)*o}}}}var un=t=>Ce(t).rh;function ah(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 Ky(t,e){let n=t.map(r=>({...r}));for(let r of e){let i=n.find(o=>o.room_id===r.room_id&&o.edge===r.edge&&(Math.abs(o.t1-r.t0)<1e-6||Math.abs(r.t1-o.t0)<1e-6));i?(i.t0=Math.min(i.t0,r.t0),i.t1=Math.max(i.t1,r.t1)):n.push({...r})}return n}function jy(t,e,n){if(t.a===e.b)return!1;let r=ot(G(n[t.b],n[t.a])),i=ot(G(n[e.b],n[e.a]));return Math.abs(Ae(r,i))>1e-6||te(r,i)<=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 lh(t,e,n=new Set){let r=t.slice();for(;;){let i=new Map;r.forEach((s,a)=>{for(let l of[s.a,s.b])i.set(l,[...i.get(l)??[],a])});let o=null;for(let[s,a]of i){if(a.length!==2||n.has(s))continue;let l=r[a[0]].b===s?r[a[0]]:ah(r[a[0]]),c=r[a[1]].a===s?r[a[1]]:ah(r[a[1]]);if(!jy(l,c,e))continue;let d={...l,b:c.b,sources:Ky(l.sources,c.sources)};o=[...r.filter((u,p)=>p!==a[0]&&p!==a[1]),d];break}if(!o)return r;r=o}}function ch(t,e){let n=new Map;t.forEach((i,o)=>{let s=ot(G(e[i.b],e[i.a])),a=[[i.a,{key:`${o}:a`,d:s,left:i.left,right:i.right,angle:Math.atan2(s[1],s[0])}],[i.b,{key:`${o}:b`,d:it(s,-1),left:i.right,right:i.left,angle:Math.atan2(-s[1],-s[0])}]];for(let[l,c]of a)n.set(l,[...n.get(l)??[],c])});let r=new Map;for(let[i,o]of n){let s=e[i];o.sort((l,c)=>l.angle-c.angle);for(let l of o)r.set(l.key,{left:ft(s,it(Sa(l.d),l.left)),right:ft(s,it(Ma(l.d),l.right))});if(o.length<2)continue;let a=4*Math.max(...o.map(l=>Math.max(l.left,l.right)))+1e-9;o.forEach((l,c)=>{let d=o[(c+1)%o.length],u=ft(s,it(Sa(l.d),l.left)),p=ft(s,it(Ma(d.d),d.right)),h=Ae(l.d,d.d);if(Math.abs(h)<1e-4)return;let f=ft(u,it(l.d,Ae(G(p,u),d.d)/h));_e(G(f,s))>a||(r.get(l.key).left=f,r.get(d.key).right=f)})}return r}function dh(t,e){let n=t.filter((r,i)=>_e(G(r,t[(i+1)%t.length]))>e);for(;;){if(n.length<=3)return n;let r=n.findIndex((i,o)=>{let s=n[(o+n.length-1)%n.length],a=n[(o+1)%n.length],[l,c]=[G(i,s),G(a,i)];return Math.abs(Ae(ot(l),ot(c)))<1e-7&&te(l,c)>0});if(r===-1)return n;n=n.filter((i,o)=>o!==r)}}function Gy(t){let e=[];return{points:e,idOf(n){let r=e.findIndex(i=>Math.abs(i[0]-n[0])<=t&&Math.abs(i[1]-n[1])<=t);return r>=0?r:(e.push([n[0],n[1]]),e.length-1)}}}function Uy(t,e){let n=[];for(let r of t){let i=r.points;if(i.length<3||Math.abs(be(i))<1e-6)continue;let o=be(i)>0,s=i.map(a=>e.idOf(a));s.forEach((a,l)=>{let c=s[(l+1)%s.length];a!==c&&n.push(o?{u:a,v:c,room:r.id,edge:l,forward:!0}:{u:c,v:a,room:r.id,edge:l,forward:!1})})}return n}function Zy(t,e,n){let r=[];for(let i of t){let[o,s]=[e[i.u],e[i.v]],a=G(s,o),l=_e(a),c=it(a,1/l),d=e.map((p,h)=>({id:h,rel:G(p,o)})).filter(({id:p,rel:h})=>p!==i.u&&p!==i.v&&te(h,c)>n&&te(h,c)({t:te(h,c),id:p})).sort((p,h)=>p.t-h.t),u=[{t:0,id:i.u},...d,{t:l,id:i.v}];for(let p=0;p+1({room_id:t.room,edge:t.edge,t0:t.t0,t1:t.t1});function qy(t,e){let n=new Map(t.map(a=>[a.id,a])),r=new Map;for(let a of e){let l=`${a.room}:${a.edge}`;r.set(l,[...r.get(l)??[],a.t0].sort((c,d)=>c-d))}let i=a=>{let l=n.get(a.room)?.wall_heights?.[a.edge];return Array.isArray(l)?l[(r.get(`${a.room}:${a.edge}`)??[]).indexOf(a.t0)]??null:l},o=a=>{let l=n.get(a.room),[c,d]=[l?.wall_heights?.[a.edge],l?.wall_slopes?.[a.edge]];if(!l||typeof c!="number"||typeof d!="number"||c<=0||d<=0)return null;let[u,p]=[l.points[a.edge],l.points[(a.edge+1)%l.points.length]];return{from:c,to:d,length:Math.hypot(p[0]-u[0],p[1]-u[1])}},s=a=>{let l=o(a);if(!l||l.length<1e-9){let d=i(a);return typeof d=="number"&&d>0?[d,d]:[null,null]}let c=d=>l.from+(l.to-l.from)*d/l.length;return a.forward?[c(a.t0),c(a.t1)]:[c(a.t1),c(a.t0)]};return{heightsOf(a){let[l,c]=[1/0,1/0];for(let u of a){let[p,h]=s(u),[f,g]=u===a[0]?[p,h]:[h,p];f!==null&&(l=Math.min(l,f)),g!==null&&(c=Math.min(c,g))}let d=a.map(u=>n.get(u.room)?.ceiling);if(d.every(u=>typeof u=="number"&&u>0)){let u=Math.max(...d);l===1/0&&(l=u),c===1/0&&(c=u)}return{...l<1/0?{a:l}:{},...c<1/0?{b:c}:{}}},thicknessOf(a){let l=a.map(c=>{let d=n.get(c.room)?.wall_thickness?.[c.edge];return Array.isArray(d)?d[(r.get(`${c.room}:${c.edge}`)??[]).indexOf(c.t0)]:d}).filter(c=>typeof c=="number"&&c>0);return l.length?Math.max(...l):void 0},hasNoWall:a=>a.some(l=>i(l)===0)}}function hh(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 Yy(t,e,n,r){let i=qy(e,t),o=new Map;for(let l of t){let c=l.up!==c&&p.u===c.v&&p.v===c.u&&p.room!==c.room);for(let p of l)p!==c&&p!==d&&p.room!==c.room&&r.push(`overlap:${c.room}:${p.room}`);let u=d?[c,d]:[c];if(i.hasNoWall(u)){d&&a.push([c.room,d.room]);continue}if(d){let p=i.thicknessOf(u)??n.interior;s.push({a:c.u,b:c.v,left:p/2,right:p/2,exterior:!1,roomLeft:c.room,roomRight:d.room,sources:u.map(uh),...hh(i.heightsOf(u))})}else s.push({a:c.u,b:c.v,left:0,right:i.thicknessOf(u)??n.exterior,exterior:!0,roomLeft:c.room,roomRight:null,sources:[uh(c)],...hh(i.heightsOf(u))})}return{drafts:s,open:a}}function Xy(t,e){let n=o=>ot(G(e[o.b],e[o.a])),r=t.filter(o=>!o.exterior&&!o.free),i=new Map;for(let o of r){if(i.has(o))continue;let s=[o];i.set(o,s);for(let a=0;a1e-6||l.add(te(s,h)>0?"left":"right")}if(l.size!==1)continue;let c=[...l][0];for(let d of o){let u=d.left+d.right,p=te(n(d),s)>0,h=c==="left"===p;[d.left,d.right]=h?[0,u]:[u,0]}}}var Jy=(t,e)=>{let n=o=>Math.round(o*100),[r,i]=t[0]Math.hypot(y.b[0]-y.a[0],y.b[1]-y.a[1])>.05),l=a.map(y=>[o.idOf(y.a),o.idOf(y.b)]),c=new Set;for(let y of t){let v=y.points;v.length<3||(y.wall_splits??[]).forEach((w,k)=>{if(!w||k>=v.length)return;let x=v[k],M=G(v[(k+1)%v.length],x),A=_e(M);for(let T of w)T>r&&T{let[w,k]=l[v];if(w===k)return;let x=[(y.a[0]+y.b[0])/2,(y.a[1]+y.b[1])/2],M=t.find(T=>T.points.length>=3&&C(x,T.points))?.id??null,A=(y.thickness??e.interior)/2;h.push({free:y.id,a:w,b:k,left:A,right:A,exterior:!1,roomLeft:M,roomRight:M,sources:[],height:typeof y.height=="number"&&y.height>0?y.height:void 0,...typeof y.height=="number"&&y.height>0&&typeof y.height_end=="number"&&y.height_end>0&&Math.abs(y.height_end-y.height)>1e-6?{heightEnd:y.height_end}:{}})});let f=lh(h,o.points,c),g=ch(f,o.points);return{walls:f.map((y,v)=>{let[w,k]=[o.points[y.a],o.points[y.b]],[x,M]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=dh([x.right,M.left,k,M.right,x.left,w],1e-6);return{id:Jy(w,k),a:[w[0],w[1]],b:[k[0],k[1]],left:y.left,right:y.right,exterior:y.exterior,roomLeft:y.roomLeft,roomRight:y.roomRight,sources:y.sources,footprint:A,...y.free?{free:y.free}:{},...y.height!==void 0?{height:y.height}:{},...y.heightEnd!==void 0?{heightEnd:y.heightEnd}:{}}}),warnings:[...new Set(i)],open:p}}function jn(t,e,n){let r=t.points[e];return ft(r,it(ot(G(t.points[(e+1)%t.points.length],r)),n))}function Ne(t,e,n){if(t.wall){let i=n.find(a=>a.id===t.wall);if(!i||Math.hypot(i.b[0]-i.a[0],i.b[1]-i.a[1])<.05)return null;let o=ot(G(i.b,i.a));return{room:{id:t.room_id,name:"",area_id:null,points:[i.a,i.b,ft(i.a,[-o[1],o[0]])]},edge:0}}let r=e.find(i=>i.id===t.room_id);return r&&t.edgete(G(e,t.a),ot(G(t.b,t.a)));function Kt(t,e,n){if(!e.wall)return Qy(t,n.room,n.edge,e.offset);let r=t.find(i=>i.free===e.wall);return r?{wall:r,s:ph(r,jn(n.room,0,e.offset))}:null}function Qy(t,e,n,r){for(let i of t)if(i.sources.some(s=>s.room_id===e.id&&s.edge===n&&r>=s.t0-1e-6&&r<=s.t1+1e-6))return{wall:i,s:ph(i,jn(e,n,r))};return null}function fh(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[i,o,s,a]=[Math.min(...n),Math.max(...n),Math.min(...r),Math.max(...r)],l=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,d=(h,f,g)=>c(h.a[f],g)&&c(h.b[f],g),u=o-i-l(h=>d(h,0,i))-l(h=>d(h,0,o)),p=a-s-l(h=>d(h,1,s))-l(h=>d(h,1,a));return[Math.round(u*1e3)/1e3,Math.round(p*1e3)/1e3]}var mh=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function ev(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 gh(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([i,o])=>[i,o]);let r=ev(t)>=0?1:-1;return t.map((i,o)=>{let s=t[(o+n-1)%n],a=t[(o+1)%n],[l,c]=mh([i[0]-s[0],i[1]-s[1]]),[d,u]=mh([a[0]-i[0],a[1]-i[1]]),p=[c*r,-l*r],h=[u*r,-d*r],f=[p[0]+h[0],p[1]+h[1]],g=Math.hypot(f[0],f[1]);if(g<1e-6)return[i[0]+p[0]*e,i[1]+p[1]*e];let b=(f[0]*p[0]+f[1]*p[1])/g,y=Math.min(4,1/Math.max(.25,b));return[i[0]+f[0]/g*e*y,i[1]+f[1]/g*e*y]})}function jt(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 tv(t){let e=([o,s])=>`${Math.round(o*1e3)}:${Math.round(s*1e3)}`,n=new Map;for(let o of t)for(let s of[o.a,o.b])n.set(e(s),[...n.get(e(s))??[],o]);let r=new Set,i=null;for(let o of t){if(r.has(o))continue;r.add(o);let s=[o.a,o.b],a=o.b;for(;;){let c=(n.get(e(a))??[]).find(d=>!r.has(d));if(!c||(r.add(c),a=e(c.a)===e(a)?c.b:c.a,e(a)===e(s[0])))break;s.push(a)}s.length>=3&&e(a)===e(s[0])&&(!i||Math.abs(ye(s))>Math.abs(ye(i)))&&(i=s)}return i}function Ta(t,e,n,r){let i=me(t,{exterior:n,interior:r},e).walls.filter(a=>a.exterior&&!a.free),o=i.length?tv(i.map(a=>({a:a.a,b:a.b}))):null;if(!o)return null;let s=o.filter((a,l)=>{let c=o[(l+o.length-1)%o.length],d=o[(l+1)%o.length];return Math.abs((a[0]-c[0])*(d[1]-a[1])-(a[1]-c[1])*(d[0]-a[0]))>1e-6});return s.length>=3?gh(s,n):null}function hn(t,e){let n=$e(t),r=Ce(t),i=n.w,[o,s]=[Math.max(0,e.a),Math.max(0,e.b)],a=n.u0-Math.max(0,e.u0),l=n.u1+Math.max(0,e.u1),c=(y,v)=>[y,v,r.y(v)],d=c(a,-o),u=c(l,-o),p=c(l,i+s),h=c(a,i+s),[f,g]=[st(t.pitch_a),st(t.pitch_b)],b=y=>[y,r.vr,r.rh];if(t.ends&&(t.shape==="gable"||t.shape==="hip"||t.shape==="halfhip")){let y=(n.u1-n.u0)/2,v=Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=Math.min(r.y(0),r.y(i)),k=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),x=f>1e-6?Math.min(r.vr,(k-t.eave_a)/f):r.vr,M=g>1e-6?Math.max(r.vr,i-(k-t.eave_b)/g):r.vr,A=Math.min(y-.1,(r.rh-k)/Math.max(.2,f)),T=[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]],F=[[0,r.y(0)],[x,k],[M,k],[i,r.y(i)]],L=(j,Jt,Ci)=>{if(j==="hip")return{upA:[],upB:[],ridge:b(Jt===a?n.u0+v*Ci:n.u1-v*Ci),profile:null};if(j==="halfhip"){let zb=b(Jt===a?n.u0+A:n.u1-A);return{upA:[[Jt,x,k]],upB:[[Jt,M,k]],ridge:zb,profile:F}}return{upA:[],upB:[],ridge:b(Jt),profile:T}},I=L(t.ends[0],a,1),N=L(t.ends[1],l,1),V=[[d,u,...N.upA,N.ridge,I.ridge,...[...I.upA].reverse()],[I.ridge,N.ridge,...[...N.upB].reverse(),p,h,...I.upB]],X=[[I.ridge,N.ridge]];for(let[j,Jt,Ci]of[[I,d,h],[N,u,p]])j.profile===null?(V.push(j===I?[h,d,j.ridge]:[u,p,j.ridge]),X.push([Jt,j.ridge],[Ci,j.ridge])):j.upA.length&&(V.push(j===I?[j.upB[0],j.upA[0],j.ridge]:[j.upA[0],j.upB[0],j.ridge]),X.push([j.upA[0],j.ridge],[j.upB[0],j.ridge]));let ke=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Ft=[d,u,...ke(N),p,h,...[...ke(I)].reverse()];return{faces:V,rim:Ft,ridges:X,gable:T,endProfiles:[I.profile,N.profile]}}switch(t.shape){case"pent":return{faces:[[d,u,p,h]],rim:[d,u,p,h],ridges:[[p,h]],gable:[[0,r.y(0)],[i,r.y(i)]]};case"hip":case"pyramid":{let y=(n.u1-n.u0)/2,v=t.shape==="pyramid"?y:Math.min(y,Math.min(r.vr,i-r.vr)||i/2),w=b(n.u0+v),k=b(n.u1-v);return t.shape==="pyramid"?{faces:[[d,u,w],[u,p,w],[p,h,w],[h,d,w]],rim:[d,u,p,h],ridges:[[d,w],[h,w],[u,w],[p,w]],gable:null}:{faces:[[d,u,k,w],[w,k,p,h],[h,d,w],[u,p,k]],rim:[d,u,p,h],ridges:[[w,k],[d,w],[h,w],[u,k],[p,k]],gable:null}}case"halfhip":{let y=Math.min(r.y(0),r.y(i)),v=y+(r.rh-y)*Math.min(.9,Math.max(.2,t.halfhip??.55)),w=f>1e-6?Math.min(r.vr,(v-t.eave_a)/f):r.vr,k=g>1e-6?Math.max(r.vr,i-(v-t.eave_b)/g):r.vr,x=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),M=b(n.u0+x),A=b(n.u1-x),T=[a,w,v],F=[a,k,v],L=[l,w,v],I=[l,k,v];return{faces:[[d,u,L,A,M,T],[M,A,I,p,h,F],[F,T,M],[L,I,A]],rim:[d,u,L,I,p,h,F,T],ridges:[[M,A],[T,M],[F,M],[L,A],[I,A]],gable:[[0,r.y(0)],[w,v],[k,v],[i,r.y(i)]]}}case"mansard":{let y=jr(i,t.eave_a,t.eave_b,f,g),v=[a,y.vla,y.yla],w=[l,y.vla,y.yla],k=[a,i-y.vlb,y.ylb],x=[l,i-y.vlb,y.ylb],M=[a,y.vr,y.rh],A=[l,y.vr,y.rh];return{faces:[[d,u,w,v],[v,w,A,M],[M,A,x,k],[k,x,p,h]],rim:[d,u,w,A,x,p,h,k,M,v],ridges:[[M,A],[v,w],[k,x]],gable:[[0,r.y(0)],[y.vla,y.yla],[y.vr,y.rh],[i-y.vlb,y.ylb],[i,r.y(i)]]}}default:{let y=b(a),v=b(l);return{faces:[[d,u,v,y],[y,v,p,h]],rim:[d,u,v,p,h,y],ridges:[[y,v]],gable:[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]]}}}}function Gr(t,e,n){let r=null;for(let i of t.faces){if(!C([e,n],i.map(([p,h])=>[p,h])))continue;let[o,s]=i,a=i.slice(2).find(p=>Math.abs((s[0]-o[0])*(p[1]-o[1])-(s[1]-o[1])*(p[0]-o[0]))>1e-9);if(!a)continue;let l=[s[0]-o[0],s[2]-o[2],s[1]-o[1]],c=[a[0]-o[0],a[2]-o[2],a[1]-o[1]],d=[l[1]*c[2]-l[2]*c[1],l[2]*c[0]-l[0]*c[2],l[0]*c[1]-l[1]*c[0]];if(Math.abs(d[1])<1e-9)continue;let u=o[2]-(d[0]*(e-o[0])+d[2]*(n-o[1]))/d[1];r=r===null?u:Math.min(r,u)}return r}function Ur(t,e,n){let r=$e(e),i=t.floors.flatMap(u=>u.rooms.filter(p=>p.points.length>=3&&u.elevation+u.height>e.base+.05)),o=u=>u.some(p=>i.some(h=>C(p,h.points))),s=.35,a=[.15,.5,.85].map(u=>r.u0+(r.u1-r.u0)*u),l=[.15,.5,.85].map(u=>r.w*u),c=u=>u?0:n,d=(u,p)=>{let h=e.overhang_sides?.[u];return typeof h=="number"&&Number.isFinite(h)?Math.min(2,Math.max(0,h)):p};return{a:d("a",c(o(a.map(u=>r.at(u,-s))))),b:d("b",c(o(a.map(u=>r.at(u,r.w+s))))),u0:d("u0",c(o(l.map(u=>r.at(r.u0-s,u))))),u1:d("u1",c(o(l.map(u=>r.at(r.u1+s,u)))))}}var So=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),_h=t=>t.shape==="flat"||t.shape==="parapet",pn=t=>Math.round(t*100)/100;function Mo(t,e){let[n,r]=[(e.x0+e.x1)/2,(e.z0+e.z1)/2];return t.filter(o=>{if(o===e||o.dormer||o.open||_h(o)||So(o)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((o,s)=>o===null||So(s){let[o,s]=e.at(i,e.w/2),[a,l]=Kr(t,o,s);return Gr(n,a,l)??r.y(l)}}function Pa(t,e){if(_h(e))return e;let n=$e(e),r=Ce(e).rh,i=rv(t,n),o=i(n.u0)<=i(n.u1),[s,a]=o?[n.u0,n.u1]:[n.u1,n.u0],l=o?1:-1,c=a;for(let p=.5;p=r-.02){c=s+l*p;break}if(Math.abs(c-a)<.05)return e;let d={...e},u=a===n.u1;return e.axis==="x"?d[u?"x1":"x0"]=c:d[u?"z1":"z0"]=c,d}var Ia=.14,bh=t=>t.shape==="flat"||t.shape==="parapet";function Da(t,e){return!t.open&&Math.min(t.base,t.eave_a,t.eave_b)l+i||pd+i||s.points&&s.points.length>=3&&!C([e,n],s.points))continue;let[h,f]=Kr(s,e,n),g=Math.max(0,s.overhang??r),b=bh(s)?null:Gr(hn(s,{u0:g,u1:g,a:g,b:g}),h,f);o.push((b??Ce(s).y(f))-Ia)}return o.length?Math.max(...o):null}function Oa(t,e,n){let r=[],i=e+n+Ia;for(let o of t.settings.roof.sections??[]){if(o.open||bh(o)||o.shape==="mansard")continue;let s=$e(o),a=Ce(o),[l,c]=[st(o.pitch_a),st(o.pitch_b)],d=[];l>1e-6&&d.push((i-o.eave_a)/l),o.shape==="gable"&&c>1e-6&&d.push(s.w-(i-o.eave_b)/c);for(let u of d)u<=.01||u>=s.w-.01||o.shape==="gable"&&Math.abs(a.y(u)-i)>1e-6||r.push([s.at(s.u0,u),s.at(s.u1,u)])}return r}function Ha(t,e,n,r,i){let o=[];for(let a of[.2,.5,.8])for(let l of[.2,.5,.8])o.push([e+(r-e)*a,n+(i-n)*l]);let s=t.floors.filter(a=>a.rooms.some(l=>l.points.length>=3&&o.some(c=>C(c,l.points)))).map(a=>a.elevation+a.height);return s.length?Math.max(...s):null}function La(t,e){let n=t.floors.filter(l=>l.rooms.length>0).sort((l,c)=>l.elevation-c.elevation),r=n.filter(l=>l.elevationd.rooms.some(u=>u.points.length>=3&&l.some(p=>C(p,u.points))));if(c)return c}return r.at(-1)??n[0]}var kt=t=>Math.round(t*1e3)/1e3;function Ca(t,e=n=>`roof_${n+1}`){let n=t.settings.roof?.pitch??35,r=t.settings.wall_exterior,i=t.floors.filter(l=>l.rooms.some(c=>c.points.length>=3)).sort((l,c)=>c.elevation-l.elevation),o=[],s=[],a=(l,c)=>l.some(d=>C(c,d.points));for(let l of i){let c=l.rooms.filter(b=>b.points.length>=3),d=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[0]))))].sort((b,y)=>b-y),u=[...new Set(c.flatMap(b=>b.points.map(y=>kt(y[1]))))].sort((b,y)=>b-y),p=u.slice(0,-1).map((b,y)=>d.slice(0,-1).map((v,w)=>{let k=[(d[w]+d[w+1])/2,(u[y]+u[y+1])/2];return a(c,k)&&!a(s,k)})),h=p.map(b=>b.map(()=>!1)),f=(b,y)=>p[y][b]&&!h[y][b],g=l.elevation+l.height;for(let b=0;bf(y+F,w+1)).every(Boolean);)w++;for(let T=b;T<=w;T++)for(let F=y;F<=v;F++)h[T][F]=!0;let[k,x]=[d[y]-r,d[v+1]+r],[M,A]=[u[b]-r,u[w+1]+r];Math.min(x-k,A-M)<.8||o.push({id:e(o.length),x0:kt(k),z0:kt(M),x1:kt(x),z1:kt(A),shape:"gable",axis:x-k>=A-M?"x":"z",eave_a:kt(g),eave_b:kt(g),pitch_a:n,pitch_b:n,base:kt(g),overhang:null})}s.push(...c)}return o}var Fe=Math.PI/180,Ue=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],fn=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Gn=t=>Math.hypot(t[0],t[1],t[2]),mn=t=>{let e=Gn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},yh=(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]],Ze=t=>Math.round(t*100)/100,qr=([t,e],n)=>(Math.atan2(t,-e)/Fe-n+720)%360;var wh=.25;function xh(t,e,n,r,i,o,s){let a=i-n>=o-r,l=a?i-n:o-r;return{key:`${t}:top`,section:e,side:"top",flat:!0,o:[n,s,r],eu:a?[1,0,0]:[0,0,1],es:a?[0,0,1]:[1,0,0],n:[0,1,0],lu:l,ls:a?o-r:i-n,pitch:0,span:()=>[0,l],facing:a?[0,1]:[1,0]}}function kh(t,e){let n=mn(yh(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var $h=t=>{let e=mn([-t[0],0,-t[2]]);return[e[0],e[2]]};function $t(t,e,n,r,i,o,s,a){let l=mn(Ue(i,r)),c=mn(Ue(o,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:c,n:kh(l,c),lu:Gn(Ue(i,r)),ls:Gn(Ue(o,r)),pitch:s,span:a,facing:$h(c)}}function vh(t,e,n,r,i,o){let s=Gn(Ue(i,r));if(s<.3)return null;let a=mn(Ue(i,r)),l=Ue(o,r),c=l[0]*a[0]+l[1]*a[1]+l[2]*a[2],d=[l[0]-a[0]*c,l[1]-a[1]*c,l[2]-a[2]*c],u=Gn(d);if(u<.3)return null;let p=mn(d),h=f=>{let g=Math.min(1,Math.max(0,f/u));return[c*g,s-(s-c)*g]};return{key:t,section:e,side:n,flat:!1,o:r,eu:a,es:p,n:kh(a,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Fe,span:h,facing:$h(p)}}function iv(t,e){let n=$e(t),r=Ce(t),i=(v,w,k)=>{let[x,M]=n.at(v,w);return[x,k,M]},[o,s]=[Math.max(0,e.a),Math.max(0,e.b)],a=n.u0-Math.max(0,e.u0),l=n.u1+Math.max(0,e.u1),c=l-a,d=r.y(-o),u=r.y(n.w+s);if(t.shape==="flat"||t.shape==="parapet"){let[v,w]=[n.at(a,-o),n.at(l,n.w+s)];return[xh(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+wh)]}if(t.shape==="pent")return[$t(`${t.id}:a`,t.id,"a",i(a,-o,d),i(l,-o,d),i(a,n.w+s,u),t.pitch_a,()=>[0,c])];if(t.shape==="mansard")return ov(t,n,a,l,o,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-a:0,b=p?l-(n.u1-f):0,y=[];if(r.vr>.3){let v=Math.hypot(r.vr+o,r.rh-d);y.push($t(`${t.id}:a`,t.id,"a",i(a,-o,d),i(l,-o,d),i(a,r.vr,r.rh),t.pitch_a,w=>[g*(w/v),c-b*(w/v)]))}if(n.w-r.vr>.3){let v=Math.hypot(n.w+s-r.vr,r.rh-u);y.push($t(`${t.id}:b`,t.id,"b",i(l,n.w+s,u),i(a,n.w+s,u),i(l,r.vr,r.rh),t.pitch_b,w=>[b*(w/v),c-g*(w/v)]))}if(p){let v=vh(`${t.id}:c`,t.id,"c",i(a,n.w+s,u),i(a,-o,d),i(n.u0+f,r.vr,r.rh)),w=vh(`${t.id}:d`,t.id,"d",i(l,-o,d),i(l,n.w+s,u),i(n.u1-f,r.vr,r.rh));y.push(...[v,w].filter(k=>k!==null))}return y}function ov(t,e,n,r,i,o){let s=jr(e.w,t.eave_a,t.eave_b,st(t.pitch_a),st(t.pitch_b)),a=(f,g)=>{let[b,y]=e.at(f,g);return[b,s.y(g),y]},l=r-n,c=()=>[0,l],d=(f,g)=>Math.atan2(f,g)/Fe,u=[],[p,h]=[e.w+o,e.w-s.vlb];return s.vla+i>.3&&u.push($t(`${t.id}:a`,t.id,"a",a(n,-i),a(r,-i),a(n,s.vla),t.pitch_a,c)),s.vr-s.vla>.3&&u.push($t(`${t.id}:au`,t.id,"a",a(n,s.vla),a(r,s.vla),a(n,s.vr),d(s.rh-s.yla,s.vr-s.vla),c)),s.vlb+o>.3&&u.push($t(`${t.id}:b`,t.id,"b",a(r,p),a(n,p),a(r,h),t.pitch_b,c)),h-s.vr>.3&&u.push($t(`${t.id}:bu`,t.id,"b",a(r,h),a(n,h),a(r,s.vr),d(s.rh-s.ylb,h-s.vr),c)),u}function Na(t){return t.floors.filter(n=>n.rooms.some(r=>r.points.length>=3)).sort((n,r)=>r.elevation-n.elevation)[0]??null}function Y(t){let e=t.settings.roof;if(!e||e.type==="none")return[];if(e.type==="custom")return(e.sections??[]).flatMap(w=>iv(w,Ur(t,w,w.overhang??e.overhang)));let n=Na(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(k=>k[0])),i=n.rooms.flatMap(w=>w.points.map(k=>k[1])),o=t.settings.wall_exterior+e.overhang,[s,a]=[Math.min(...r)-o,Math.max(...r)+o],[l,c]=[Math.min(...i)-o,Math.max(...i)+o],d=n.elevation+n.height;if(e.type==="flat")return[xh("main",null,s,l,a,c,d+wh)];let u=a-s>=c-l,p=e.ridge==="short"?!u:u,h=(p?c-l:a-s)/2,f=h*Math.tan(e.pitch*Fe),g=(w,k,x)=>p?[w,d+x,(l+c)/2+k]:[(s+a)/2+k,d+x,w],[b,y]=p?[s,a]:[l,c],v=()=>[0,y-b];return[$t("main:a",null,"a",g(b,-h,0),g(y,-h,0),g(b,0,f),e.pitch,v),$t("main:b",null,"b",g(b,h,0),g(y,h,0),g(b,0,f),e.pitch,v)]}function qe(t,e){let n=[];for(let r of t.floors.filter(i=>!e||i.id===e)){let{walls:i}=me(r.rooms,{exterior:t.settings.wall_exterior,interior:t.settings.wall_interior},r.walls??[]);for(let o of i){if(!o.exterior&&!o.free)continue;let[s,a]=[o.b[0]-o.a[0],o.b[1]-o.a[1]],l=Math.hypot(s,a);if(l<1.2)continue;let[c,d]=[a/l,-s/l],u=Math.min(r.height,o.height??r.height,o.heightEnd??1/0),p=(h,f,g,b)=>n.push({key:h,section:null,side:"top",flat:!1,o:f,eu:g,es:[0,1,0],n:b,lu:l,ls:u,pitch:90,span:()=>[0,l],facing:[b[0],b[2]],wall:{floorId:r.id}});p(`wall:${r.id}:${o.id}`,[o.a[0]+c*o.right,r.elevation,o.a[1]+d*o.right],[s/l,0,a/l],[c,0,d]),o.free&&p(`wall:${r.id}:${o.id}:back`,[o.b[0]-c*o.left,r.elevation,o.b[1]-d*o.left],[-s/l,0,-a/l],[-c,0,-d])}}return n}var Be="ground";function Eo(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 Ro(t,e){let n=(e.rotation??0)*Fe,r=[Math.cos(n),0,Math.sin(n)],i=[-Math.sin(n),0,Math.cos(n)],o=Eo(t),s=r[0]*e.u+i[0]*e.v,a=r[2]*e.u+i[2]*e.v,l=o?o.elevation+(e.base!=null?e.base:Od(o,s,a)):e.base??0;return{key:Be,section:null,side:"top",flat:!0,o:[0,l,0],eu:r,es:i,n:[0,1,0],lu:1e4,ls:1e4,pitch:0,span:()=>[-1e4,1e4],facing:[i[0],i[2]],unbounded:!0}}function Se(t,e,n=Y(t)){return e.face===Be?Ro(t,e):e.face.startsWith("wall:")?qe(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Ao=1.13,Xr=1.72,Ye=.025,at=.07;function gn(t){let e=t.module_w||Ao,n=t.module_h||Xr;return t.portrait===!1?[n,e]:[e,n]}function Jr(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 Ba(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Fe:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Fe:Math.min(45,Math.max(0,e.tilt??0))*Fe}function Qr(t,e){let[,n]=gn(e),r=Ba(t,e);return t.wall?n*Math.cos(r)+Ye:!t.flat&&r<.001?n+Ye:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function Un(t,e){let[n,r]=gn(e),i=Jr(e),o=Math.max(1,...i);return[o*n+(o-1)*Ye,(i.length-1)*Qr(t,e)+r*Math.cos(Ba(t,e))]}var sv=t=>t.flat&&!t.unbounded&&!t.wall;function Sh(t,e){if(!sv(t)||!e.rotation)return null;let n=e.rotation*Fe,[r,i]=Un(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+i/2}}function Xe(t,e,n=!1){let[r,i]=gn(e),o=Ba(t,e),s=i*Math.cos(o),a=Qr(t,e),l=Jr(e),c=Math.max(1,...l),d=new Set(e.skip??[]),u=Sh(t,e),p=(b,y)=>u?[u.u+(b-u.u)*u.cos-(y-u.s)*u.sin,u.s+(b-u.u)*u.sin+(y-u.s)*u.cos]:[b,y],h=(b,y,v)=>{let[w,k]=p(b,y);return[0,1,2].map(x=>t.o[x]+t.eu[x]*w+t.es[x]*k+t.n[x]*v)},f=(b,y)=>{let[v,w]=p(b,y);if(t.unbounded)return!0;if(w<-1e-6||w>t.ls+1e-6)return!1;let[k,x]=t.span(w);return v>=k-1e-6&&v<=x+1e-6},g=[];return l.forEach((b,y)=>{let v=e.align==="right"?c-b:e.align==="center"?(c-b)/2:0;for(let w=0;w.001?s:i);if([[M,T],[A,T],[A,F],[M,F]].every(([L,I])=>f(L,I)))if(t.wall&&o>.001){let L=at+i*Math.sin(o),[I,N]=e.flip?[L,at]:[at,L],V=[h(M,T,I),h(A,T,I),h(A,F,N),h(M,F,N)],X=e.flip?T:F;g.push({corners:V,posts:[M+.05,A-.05].map(ke=>[h(ke,X,0),h(ke,X,L)]),cell:k,skipped:x})}else if(!t.flat&&o>.001){let L=at+i*Math.sin(o),I=[h(M,T,at),h(A,T,at),h(A,F,L),h(M,F,L)];g.push({corners:I,posts:[M+.05,A-.05].map(N=>[h(N,F,0),h(N,F,L)]),cell:k,skipped:x})}else if(!t.flat)g.push({corners:[h(M,T,at),h(A,T,at),h(A,F,at),h(M,F,at)],posts:[],cell:k,skipped:x});else{let I=.15+i*Math.sin(o),N=e.rack==="ew"&&y%2===1?!e.flip:!!e.flip,[V,X]=N?[F,T]:[T,F],ke=[h(M,V,.15),h(A,V,.15),h(A,X,I),h(M,X,I)],Ft=[M+.05,A-.05].flatMap(j=>[[h(j,V,0),h(j,V,.15)],[h(j,X,0),h(j,X,I)]]);g.push({corners:ke,posts:Ft,cell:k,skipped:x})}}}),g}function mt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=Un(t,e),i=Sh(t,e);if(i){let[s,a]=[(n*Math.abs(i.cos)+r*Math.abs(i.sin))/2,(n*Math.abs(i.sin)+r*Math.abs(i.cos))/2],l=(u,p,h)=>Math.floor(Math.max(p,Math.min(u,h-p))*100+1e-6)/100,[c,d]=[e.u+n/2,e.v+r/2];return{u:Math.round((l(c,s,t.lu)-n/2)*100)/100,v:Math.round((l(d,a,t.ls)-r/2)*100)/100}}let o=s=>Math.floor(s*100+1e-6)/100;return{u:o(Math.min(Math.max(0,e.u),Math.max(0,t.lu-n))),v:o(Math.min(Math.max(0,e.v),Math.max(0,t.ls-r)))}}function ei(t,e){let[n,r]=Un(t,e),[i,o]=[e.u+n/2,e.v+r/2];return[t.o[0]+t.eu[0]*i+t.es[0]*o,t.o[2]+t.eu[2]*i+t.es[2]*o]}var Fo=.78,ti=1.18,_n=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||Fo,module_h:t.h||ti});function Va(t,e){let n=Xe(t,_n(e))[0];if(!n)return null;let r=i=>[i[0]-t.n[0]*.05,i[1]-t.n[1]*.05,i[2]-t.n[2]*.05];return n.corners.map(r)}var Yr={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 bn(t){let e=t.shape??"brick",n=Yr[e]??Yr.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function St(t,e){let{w:n,d:r}=bn(t),i=e&&!e.flat?Math.cos(e.pitch*Fe):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,i),tilt:0}}function Wa(t,e){let n=St(e,t),[r,i]=[n.module_w,n.module_h],o=(d,u)=>[t.o[0]+t.eu[0]*d+t.es[0]*u,t.o[1]+t.eu[1]*d+t.es[1]*u,t.o[2]+t.eu[2]*d+t.es[2]*u],[s,a]=[o(e.u+r/2,e.v),o(e.u+r/2,e.v+i)],l=o(e.u+r/2,e.v+i/2),c=d=>{let u=Math.hypot(d[0],d[2])||1;return[d[0]/u,d[2]/u]};return{center:[l[0],l[2]],along:c(t.eu),across:c(t.es),low:Math.min(s[1],a[1]),high:Math.max(s[1],a[1])}}function Ka(t,e){let[n]=gn(e);return Ze((t.lu-(e.cols*n+(e.cols-1)*Ye))/2)}var ni=.4;function Zn(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]=gn(n),[i,o]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((o-i-2*ni+Ye)/(r+Ye))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*ni)/Qr(t,n))));n.cols>1&&Xe(t,{...n,u:Ka(t,n),v:ni}).lengtha.lu*(1.3+Math.cos((qr(a.facing,r)-180)*Math.PI/180)),o=qe(t,n).sort((a,l)=>i(l)-i(a))[0];if(!o)return null;let s={...Zn(o,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((o.lu-.8+Ye)/(Xr+Ye))),s.u=Ze((o.lu-(s.cols*Xr+(s.cols-1)*Ye))/2),s.v=Ze(Math.max(0,o.ls-Ao-.3)),s}function ri(t,e){let n=t.floors.flatMap(o=>o.rooms.flatMap(s=>s.points)),r=n.length?Math.max(...n.map(o=>o[0]))+3:0,i=n.length?Math.min(...n.map(o=>o[1])):0;return{id:e,face:Be,u:Ze(r),v:Ze(i),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function ii(t,e,n){let r=Ro(t,e),[i,o]=Un(r,e),[s,a]=[e.u+i/2,e.v+o/2],l=[r.eu[0]*s+r.es[0]*a,r.eu[2]*s+r.es[2]*a],c=n*Fe,d=l[0]*Math.cos(c)+l[1]*Math.sin(c)-i/2,u=l[0]*-Math.sin(c)+l[1]*Math.cos(c)-o/2;return{u:Ze(d),v:Ze(u),rotation:(Math.round(n)%360+360)%360}}function oi(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:Ze((n+r-Fo)/2),v:Ze(Math.max(0,Math.min(t.ls-ti,t.ls*.45-ti/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function si(t,e){let n=Yr.brick,[r,i]=t.span(t.ls*.8),o=St({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:Ze((r+i-n.w)/2),v:Ze(Math.max(0,Math.min(t.ls-o,t.ls*.8-o/2))),shape:"brick",w:null,d:null,h:null}}function qn(t,e){let[n,r]=[e[0]-t.o[0],e[1]-t.o[2]],[i,o,s,a]=[t.eu[0],t.eu[2],t.es[0],t.es[2]],l=i*a-o*s;if(Math.abs(l)<1e-9)return null;let c=(n*a-r*s)/l,d=(i*r-o*n)/l;if(d<0||d>t.ls)return null;let[u,p]=t.span(d);return c>=u&&c<=p?{u:c,s:d}:null}function Ga(t,e){let n=null;for(let r of t){if(r.wall){let[s,a]=[e[0]-r.o[0],e[1]-r.o[2]],l=s*r.eu[0]+a*r.eu[2],c=s*r.n[0]+a*r.n[2],d=l>=0&&l<=r.lu;if(d&&c>=-.05&&c<=.35)return{face:r,u:l,s:Number.NaN};d&&c>.35&&c<=.8&&!n&&(n={face:r,u:l,s:Number.NaN,y:-1/0});continue}let i=qn(r,e);if(!i)continue;let o=r.o[1]+r.es[1]*i.s;(!n||o>n.y)&&(n={face:r,...i,y:o})}return n&&{face:n.face,u:n.u,s:n.s}}function zo(t,e,n){let r=fn(n,t.n);if(Math.abs(r)<1e-6)return null;let i=fn(Ue(t.o,e),t.n)/r;if(i<=0)return null;let o=Ue([e[0]+n[0]*i,e[1]+n[1]*i,e[2]+n[2]*i],t.o);return{t:i,u:fn(o,t.eu),s:fn(o,t.es)}}function Ua(t,e,n){if(t.unbounded)return!0;if(n<0||n>t.ls)return!1;let[r,i]=t.span(n);return e>=r&&e<=i}function Za(t,e,n,r){return Xe(t,e).some(o=>{let s=o.corners.map(c=>{let d=Ue(c,t.o);return[fn(d,t.eu),fn(d,t.es)]}),a=s.map(c=>c[0]),l=s.map(c=>c[1]);return n>=Math.min(...a)-.05&&n<=Math.max(...a)+.05&&r>=Math.min(...l)-.05&&r<=Math.max(...l)+.05})}var av=["n","ne","e","se","s","sw","w","nw"],qa=(t,e)=>av[Math.round(qr(t.facing,e)/45)%8];function ai(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let i=Math.cos((qr(r.facing,e)-180)*Math.PI/180);return r.lu*r.ls*(1.2+i)};return[...t].sort((r,i)=>n(i)-n(r))[0]??null}var Ah=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Mh={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]]}},Eh=t=>typeof t=="string"?t:t[0],Po=t=>typeof t=="string"?nt[t]:t[1],Yn=.05,lv=.02,Rh=t=>Math.round(t*1e3)/1e3;function cv(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 Fh(t,e,n){let r=ue(t.points),i=r.x1-r.x0,o=r.z1-r.z0,s=[],a=(l,c,d,u,[p,h,f])=>{s.push({id:n(),type:l,x:Rh(c),z:Rh(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[l,c,d]of Mh[e].rows){let u=l==="back"||l==="front"?i:o,p=0,h=[];for(let g of d){if(p+Po(g)[0]>u-.1)break;h.push(g),p+=Po(g)[0]}let f=c==="start"?Yn:c==="end"?u-p-Yn:(u-p)/2;for(let g of h){let b=Po(g),y=cv(r,l,f+b[0]/2,b[1]/2+lv);a(Eh(g),y.x,y.z,y.turn,b),f+=b[0]}}for(let[l,c,d,u]of Mh[e].spots){let p=Po(l),h=(b,y,v)=>Math.min(v,Math.max(y,b)),f=h(r.x0+i*c,r.x0+p[0]/2+Yn,r.x1-p[0]/2-Yn),g=h(r.z0+o*d,r.z0+p[1]/2+Yn,r.z1-p[1]/2-Yn);a(Eh(l),f,g,u,p)}return s}var dv=30*Math.PI/180,Th=.05;function Ya(t){let e=t.points.length;return t.points.map((n,r)=>{let i=t.points[(r+1)%e];return Math.hypot(i[0]-n[0],i[1]-n[1])})}function li(t){return Ya(t).reduce((e,n)=>e+n,0)}function uv(t,e){let n=Ya(t),r=0;for(let i=0;ih+f,0);if(i<3||!(o>0)||!(n>0))return null;let s=Math.min(n,o),a=(e%o+o)%o,l=0,c=0;for(;l=c+r[l];)c+=r[l],l++;let d=a-c,u=s,p=[];for(let h=0;h<=i&&u>1e-9;h++){let f=r[l]-d,g=Math.min(u,f);g>1e-9&&p.push({edge:l,t0:d,t1:d+g}),u-=g,d=0;let b=(l+1)%i;if(u>1e-9&&hv(t,l)>dv)break;l=b}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 Xn(t,e){let n=e[0];return n?{from:uv(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,i)=>r+i.width,0)}:null}function Gt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function Ja(t,e){let n=t.points.length,r=1/0,i=0,o=0;for(let s=0;sP("opening")){let s=Xa(e,r,i);if(!s)return null;let a=Gt(t,n),l=new Set(a.map(h=>h.id)),c=s.length>1?a[0].front??`front-${a[0].id}`:null,d=s.map((h,f)=>({...n,id:f===0?a[0].id:o(),edge:h.edge,offset:h.offset,width:h.width,front:c})),u=[],p=!1;for(let h of t){if(!l.has(h.id)){u.push(h);continue}p||(u.push(...d),p=!0)}return u}var tl=globalThis,Qa=tl.__nextfloorBuiltin?.de??{},el=tl.__nextfloorBuiltin?.en??{};tl.__nextfloorBuiltin??={de:Qa,en:el};var pv=()=>typeof $=="object"&&$||{},fv=globalThis,mv=fv.__nextfloorTexts??=new Map;function gv(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in pv()?e:void 0}function zh(t){let e=gv(t),n=e===void 0?void 0:mv.get(e);return n instanceof Promise?void 0:n}function Io(t,e){return zh(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,i=r.startsWith("de"),o=(i?void 0:zh(r)?.[e])??(i?Qa:el)[e]??el[e]??Qa[e]??e;for(let[s,a]of Object.entries(n))o=o.replace(`{${s}}`,String(a));return o}function K(t,e,n=2){return e.toLocaleString(t?.language??void 0,{maximumFractionDigits:n})}var _v=new Set(["on","home","open","true","active","playing","heat","heating"]);function Ph(t,e){let n=e.show_when;if(!n?.entity||!t)return!0;let r=t.states[n.entity];if(!r||He(r))return!0;let i=String(r.state).toLowerCase(),o=(n.state??"").split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),s=o.length?o.includes(i):_v.has(i)||Number.isFinite(Number(i))&&Number(i)>0;return n.invert?!s:s}function Te(t,e){if(!wt(e))return xe(t,`furn_${e}`);let n=U(e);return n?Je(n,e,t?.language??navigator.language):xe(t,"pack_missing_item")}function Je(t,e,n){return t.name[n.split("-")[0]]??Io(n,e)??pd(t,n)}function Ve(t,e){return Io(e,`packname:${t.id}`)??fd(t,e)}function Ih(t,e){return t.name[e.split("-")[0]]??Io(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var di=t=>t&&t!=="none"?t:null,ui=(t,e)=>{e&&!t.includes(e)&&t.push(e)},nl=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function yn(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=nl(t),r=new Set([e.id]);for(let i=n.get(e.parent_meter);i;i=n.get(i.parent_meter??"")){if(r.has(i.id))return null;r.add(i.id)}return n.has(e.parent_meter)?e.parent_meter:null}function Jn(t){return new Set([...nl(t).values()].filter(e=>yn(t,e)).map(e=>e.id))}function hi(t,e){return!t.energy.advanced||!e.parent_meter?null:Jn(t).has(e.parent_meter)?e.parent_meter:null}function Dh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=nl(t),i=new Set;for(let o=n;o&&!i.has(o.id);o=r.get(o.parent_meter??"")){if(o.id===e.id)return!1;i.add(o.id)}return!0}function Oo(t,e=n=>di(n.power)){let n={grid:null,gridExport:null,solar:[],battery:[],charge:[],batteries:[],soc:[]};for(let r of t.floors.flatMap(i=>i.furniture)){let i=e(r),o=r.type==="meter"?yn(t,r):null;if(o)(n.subMeters??=[]).push({id:r.id,parent:o,power:i,invert:!!r.meter_invert,floors:r.meter_floors??[],solar:[],batteries:[]});else if(r.type==="meter")n.grid??=i,n.gridExport??=di(r.export);else if(r.type==="inverter")ui(n.solar,i);else if(r.type==="home_battery"){let s=di(r.charge);ui(n.battery,i),ui(n.charge,s),ui(n.soc,di(r.soc)),(i||s)&&n.batteries.push({power:i,charge:s})}}for(let r of n.subMeters?t.floors.flatMap(i=>i.furniture):[]){let i=r.type==="inverter"||r.type==="home_battery"?n.subMeters?.find(a=>a.id===hi(t,r)):void 0,o=i?e(r):null;i&&r.type==="inverter"&&ui(i.solar,o);let s=di(r.charge);i&&r.type==="home_battery"&&(o||s)&&i.batteries.push({power:o,charge:s})}return n}function bv(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!yn(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var yv=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,vv=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function Do(t,e,n="power"){let r=e?t.entities?.[e]?.device_id:void 0;if(!e||!r)return null;let i=Object.keys(t.states).filter(a=>a.startsWith("sensor.")&&t.entities?.[a]?.device_id===r&&t.states[a]?.attributes.device_class===n);if(i.length<=1)return i[0]??null;let o=i.filter(a=>!yv.test(a)),s=e.replace(/^sensor\./,"").replace(vv,"");return o.find(a=>s&&a.includes(s))??o[0]??i[0]}function Oh(t,e){let n={},r=(i,o)=>{o&&!n[i]&&(n[i]=o)};for(let i of e.energy_sources??[])if(i.type==="grid")r("grid",Do(t,i.flow_from?.[0]?.stat_energy_from??i.flow_to?.[0]?.stat_energy_to));else if(i.type==="solar")r("solar",Do(t,i.stat_energy_from));else if(i.type==="battery"){let o=i.stat_energy_from??i.stat_energy_to;r("battery",Do(t,o)),r("battery_soc",Do(t,o,"battery"))}return n}function ze(t,e=!1){let n=t?.attributes.symcon_id?Ct(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 wv=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function pi(t,e){if(wv(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=ua(t,n),i=r?Ot(t,e):null,o=go(t,n).filter(s=>s!==e);return(r?o.find(s=>i!==null&&Ot(t,s)===i):o[0])??null}var Hh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function xv(t,e,n){let r=e.grid??n.grid,i=r?ze(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let o=Math.max(0,ze(t.states[n.gridExport])??0);return Math.max(0,i??0)-o}return i}function kv(t,e,n){return e.solar?ze(t.states[e.solar]):n.solar.length?Hh(n.solar.map(r=>ze(t.states[r]))):null}function rl(t,e,n){return e.charge?(e.power?Math.max(0,ze(t.states[e.power])??0):0)-Math.max(0,ze(t.states[e.charge])??0):e.power?ze(t.states[e.power],n):null}function $v(t,e,n){return e.battery?ze(t.states[e.battery],e.battery_invert):Hh(n.batteries.map(r=>rl(t,r,e.battery_invert)))}function il(t,e,n,r=Oo(e)){let i=e.energy,o=xv(t,i,r),s=kv(t,i,r),a=$v(t,i,r),l=(i.battery_soc?[i.battery_soc]:r.soc).map(f=>Number(t.states[f]?.state)).filter(Number.isFinite),c=l.length?l.reduce((f,g)=>f+g,0)/l.length:null,d=i.tariff?t.states[i.tariff]:void 0,u=Number(d?.state),p=i.consumption?ze(t.states[i.consumption]):null;p===null&&(o!==null||s!==null||a!==null)&&(p=(o??0)+Math.max(0,s??0)+(a??0)),p===null&&n.length>0&&(p=n.reduce((f,g)=>f+g.power,0));let h={grid:o,solar:s===null?null:Math.max(0,s),battery:a,soc:c,tariff:d&&Number.isFinite(u)?{value:u,unit:String(d.attributes.unit_of_measurement??"")}:null,consumption:p===null?null:Math.max(0,p)};return r.subMeters?{...h,...Sv(t,r,h.consumption,i.battery_invert,n)}:h}function Sv(t,e,n,r,i){let o=e.subMeters??[],s=new Map;for(let p of o)for(let h of p.floors)s.has(h)||s.set(h,p.id);let a=new Set([e.grid,e.gridExport,...e.solar,...e.battery,...e.charge,...o.flatMap(p=>[p.power,...p.solar,...p.batteries.flatMap(h=>[h.power,h.charge])])]),l=p=>i.filter(h=>s.get(h.floorId)===p&&!a.has(h.powerEntity)).reduce((h,f)=>h+f.power,0),c=new Map(o.map(p=>[p.id,p.power?ze(t.states[p.power],p.invert):null])),d=o.map(p=>{let h=c.get(p.id)??null,f=p.solar.reduce((v,w)=>v+Math.max(0,ze(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(rl(t,w,r)??0),0),b=o.filter(v=>v.parent===p.id).reduce((v,w)=>v+(c.get(w.id)??0),0),y=h===null?null:Math.max(0,h+f+g-b);return{id:p.id,parent:p.parent,power:h,solar:f,battery:g,use:y,unmetered:y===null?null:Math.max(0,y-l(p.id))}}),u=d.reduce((p,h)=>p+(h.use??0),0);return{subMeters:d,rest:n===null?null:Math.max(0,n-u)}}function Mv(t,e,n){let r=t.b[0]-t.a[0],i=t.b[1]-t.a[1],o=Math.hypot(r,i)||1,s=Math.min(1,Math.max(0,((e.x-t.a[0])*r+(e.z-t.a[1])*i)/(o*o))),a=t.a[0]+r*s,l=t.a[1]+i*s,c=i/o*(a-n.x)+-r/o*(l-n.z)<0?-1:1;return{x:a,z:l,nx:c*i/o,nz:-c*r/o,distance:Math.hypot(e.x-a,e.z-l)}}function Lh(t){let e=bv(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},i=me(n.rooms,r,n.walls??[]).walls.filter(c=>c.exterior),o=n.rooms.flatMap(c=>c.points);if(i.length===0||o.length===0)return null;let s={x:o.reduce((c,d)=>c+d[0],0)/o.length,z:o.reduce((c,d)=>c+d[1],0)/o.length},a=i.map(c=>Mv(c,e,s)).reduce((c,d)=>d.distance({id:t,name:e,has_valve:!0}),Ho=t=>t.has_valve!==!1;function fi(t){let e=t.hydronic??{};return e.stations?.length?e.stations.slice(0,16):[{...ol("station-1"),flow:e.flow,return:e.return,hot_water:e.hot_water,cold_water:e.cold_water,pump:e.pump}]}function Ch(t,e){let n={...t,stations:e};for(let r of["flow","return","hot_water","cold_water","pump"])delete n[r];return n}var Ev=["heating_manifold","buffer_tank","freshwater_station"],Qn=t=>Ev.includes(t),sl=(t,e="Heizkreis")=>({id:t,name:e,kind:"heating",has_pump:!0,has_valve:!0});function al(t){return{card:!0,...t==="heating_manifold"?{circuits:[sl("c1","Heizkreis 1")]}:{},...t==="buffer_tank"?{sensors:Array.from({length:7},(e,n)=>({id:`s${n+1}`,name:`F\xFChler ${n+1}`,entity:null,level:1-n/6}))}:{}}}function er(t){return{...al(t.type),...t.hydronic}}var tr=t=>t.has_pump!==!1,Lo=t=>t.kind!=="pump"&&t.has_valve!==!1;var mi=t=>!!t&&t!=="none";var No=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Co(t,e){let n=t.states[No(t,e)]?.attributes;return n?.device_class==="power"||/^[km]?w$/i.test(String(n?.unit_of_measurement??"").trim())}function Nh(t,e){let n=new Map;if(!Z(t))return n;let r=Re(t,[e]),i=(o,s,a,l,c)=>{if(!mi(c))return;let d=e.rooms.find(p=>p.points.length>=3&&C([a,l],p.points));if(!d)return;let u=n.get(d.id)??[];u.push({id:o,name:s,source:No(t,c)}),n.set(d.id,u)};for(let o of e.furniture){if(!Ph(t,o))continue;let s=o.name||Te(t,o.type),a=(o.values??[]).find(d=>mi(d.entity)&&Co(t,d.entity)),l=r.get(o.id)?.entity,c=o.power==="none"?null:o.power||r.get(o.id)?.power||(l&&Co(t,l)?l:null);if(i(`furniture:${o.id}`,s,o.x,o.z,c||a?.entity),!c&&!a){let d=new Set;for(let u of o.gang_entities??[]){if(!mi(u))continue;let p=pi(t,u);!p||d.has(No(t,p))||(d.add(No(t,p)),i(`furniture:${o.id}:${u}`,`${s} \xB7 ${B(t,u)}`,o.x,o.z,p))}}if(Qn(o.type))for(let d of er(o).circuits??[])tr(d)&&i(`furniture:${o.id}:${d.id}`,`${s} \xB7 ${d.name||"Pumpe"}`,o.x,o.z,d.power);if(o.type==="freshwater_station")for(let d of fi(o))i(`furniture:${o.id}:station:${d.id}`,`${s} \xB7 ${d.name}`,o.x,o.z,d.power)}for(let o of e.placements){if(o.outside)continue;let s=(o.values??[]).find(l=>mi(l.entity)&&Co(t,l.entity)),a=Co(t,o.entity_id)?o.entity_id:pi(t,o.entity_id);i(`device:${o.entity_id}`,o.name||B(t,o.entity_id),o.x,o.z,a||s?.entity)}return n}var Mt={electricity:"Strom",water:"Wasser",gas:"Gas",heating:"Heizen",cooling:"K\xFChlen"},nr={electricity:"\u26A1",water:"\u{1F4A7}",gas:"\u{1F525}",heating:"\u2668",cooling:"\u2744"},Vo=t=>t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/ß/g,"ss").replace(/[^a-z0-9]+/g," ").trim(),Rv="{485D0419-BE97-4548-AA9C-C083EB82E61E}",Av=t=>t.object_type!==0&&!(t.object_type===1&&t.module_id?.toUpperCase()===Rv)?null:{elektro:"electricity",strom:"electricity","elektro strom":"electricity","strom elektro":"electricity",wasser:"water",gas:"gas",heizen:"heating",heizung:"heating",warme:"heating",waerme:"heating",kuhlen:"cooling",kuehlen:"cooling",kuhlung:"cooling",kuehlung:"cooling",kalte:"cooling",kaelte:"cooling"}[Vo(t.name)]??null,Bo=t=>/^symcon-category-(\d+)$/.exec(t??"")?.[1],cl=t=>/\b(heute|tag|tagesverbrauch|today|daily)\b/.test(t)?"day":/monat|month/.test(t)?"month":/jahr|year/.test(t)?"year":"total",Wo=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Wh(t){let e=String(t?.attributes.unit_of_measurement??"").trim(),n=e.replace(/[³]/g,"3").replace(/[²]/g,"2").replace(/\s+/g,"").toLowerCase();return["w","kw","mw"].includes(n)?{metric:"power",unit:"W",factor:e==="mW"?.001:n==="kw"?1e3:n==="mw"?1e6:1}:["wh","kwh","mwh","j","kj","mj","gj"].includes(n)?{metric:"energy",unit:"kWh",factor:{wh:.001,kwh:1,mwh:1e3,j:1/36e5,kj:1/3600,mj:1/3.6,gj:1e3/3.6}[n]}:["m3/h","m3h","m3/min","m3/s","l/h","l/min","l/s","liter/h","liter/min"].includes(n)?{metric:"power",unit:"m\xB3/h",factor:{"m3/h":1,m3h:1,"m3/min":60,"m3/s":3600,"l/h":.001,"l/min":.06,"l/s":3.6,"liter/h":.001,"liter/min":.06}[n]}:["m3","l","liter"].includes(n)?{metric:"energy",unit:"m\xB3",factor:n==="m3"?1:.001}:null}function Fv(t,e){if(!e.entity_id||e.object_type!==2&&e.object_type!==6)return null;let n=Wo(t,e.entity_id),r=t.states[n];if(!r||![1,2].includes(Number(r.attributes.symcon_variable_type)))return null;let i=Vo(e.name),o=Wh(r),s=/^(leistung|wirkleistung|gesamtleistung|aktuelle leistung|durchfluss|volumenstrom)(\b|$)/.test(i),a=/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)(\b|$)/.test(i),l=o?.metric??(s?"power":a?"energy":null);if(!l)return null;let c=l==="power"?/^(leistung|wirkleistung|gesamtleistung|durchfluss|volumenstrom)$/.test(i):/^(verbrauch|energie|energieverbrauch|gesamtverbrauch|gesamtenergie|zahlerstand|zaehlerstand|arbeit)$/.test(i),d=l==="energy"?cl(i):"total";return{metric:l,source:n,period:d,group:`${l}|${o?.unit??String(r.attributes.unit_of_measurement??"")}|${d}`,score:/^gesamt(leistung|verbrauch|energie)$/.test(i)?110:c?100:(l==="power"?s:a)?70:20}}var Bh=new WeakMap,Vh=new WeakMap;function Kh(t){let e=Bh.get(t);if(e)return e;let n={nodes:new Map(t.map(r=>[r.object_id,r])),children:new Map};for(let r of t){let i=n.children.get(r.parent_id)??[];i.push(r),n.children.set(r.parent_id,i)}return Bh.set(t,n),n}function Tv(t,e,n){if(!Z(t))return[];let r=[e.area_id,...e.sub_areas??[]].map(Bo).filter(p=>!!p);if(!r.length)return[];let i=new Set(n.filter(p=>p.id!==e.id).flatMap(p=>[p.area_id,...p.sub_areas??[]]).map(Bo).filter(p=>!!p&&!r.includes(p))),o=`${r.join(",")}|${[...i].sort().join(",")}`,s=Vh.get(t)??new Map;Vh.set(t,s);let a=s.get(o);if(a)return a;let l=Kh(t.symconObjects),c=[],d=new Set,u=(p,h,f)=>{if(d.has(p)||i.has(String(p)))return;d.add(p);let g=l.nodes.get(p);if(!g)return;let b=Av(g),y=b??h,v=new Set(b&&b!==h?[]:f),w=l.children.get(p)??[];if(y){let k=w.map(x=>Fv(t,x)).filter(x=>x!==null);for(let x of new Set(k.map(M=>M.group))){if(v.has(x))continue;let M=k.filter(F=>F.group===x),A=Math.max(...M.map(F=>F.score)),T=M.filter(F=>F.score===A);for(let F of A>=100?T.slice(0,1):T)c.push({kind:y,metric:F.metric,id:F.source,period:F.period});v.add(x)}}for(let k of w)(k.object_type===0||k.object_type===1)&&u(k.object_id,y,v)};for(let p of r)u(Number(p),null,new Set);return s.set(o,c),c}function gi(t,e,n=!1){let r=new Map,i=new Set;for(let o of e){let s=Wo(t,o.id),a=`${o.kind}|${o.metric}|${s}`;if(i.has(a))continue;i.add(a);let l=t.states[s],c=Wh(l),d=c?.metric===o.metric?c.unit:String(l?.attributes.unit_of_measurement??"").trim(),u=`${o.kind}|${o.metric}|${d}|${o.period}`,p=r.get(u)??{kind:o.kind,metric:o.metric,unit:d,value:null,period:o.period,sources:[],manual:n,incomplete:!1},h=Ct(l);h===null?p.incomplete=!0:p.value=(p.value??0)+h*(c?.metric===o.metric?c.factor:1),p.sources.push(s),r.set(u,p)}return[...r.values()]}function ll(t,e){return xt.flatMap(n=>["power","energy"].flatMap(r=>{let i=e.utility_meters?.[n]?.[r];if(!i||i==="none")return[];let o=Wo(t,i);return[{kind:n,metric:r,id:o,period:r==="energy"?cl(Vo(String(t.states[o]?.attributes.friendly_name??""))):"total"}]}))}function zv(t,e){return Z(t)?gi(t,ll(t,e),!0):[]}function Pv(t,e,n=e.rooms,r=!1){if(!Z(t))return[];let i=r?Nh(t,e):new Map,o=new Map;for(let a of e.rooms){let l=[...new Set([a.area_id,...a.sub_areas??[]].filter(c=>!!Bo(c)))];!l.length&&(ll(t,a).length||i.get(a.id)?.length)&&l.push("unassigned");for(let c of l){let d=o.get(c)??{seed:a,members:[]};c===l[0]&&d.members.push(a),o.set(c,d)}}let s=Kh(t.symconObjects).nodes;return[...o].map(([a,l])=>{let c=s.get(Number(Bo(a))),d=a==="unassigned"?[]:gi(t,Tv(t,{...l.seed,area_id:a,sub_areas:null},n)),u=gi(t,l.members.flatMap(f=>ll(t,f)),!0),p=f=>d.some(g=>g.kind===f.kind&&g.metric===f.metric&&g.unit===f.unit&&g.period===f.period),h=l.members.map(f=>({id:f.id,name:f.name,readings:zv(t,f),devices:(i.get(f.id)??[]).map(g=>({id:g.id,name:g.name,readings:gi(t,[{kind:"electricity",metric:"power",id:g.source,period:"total"}],!0)}))})).filter(f=>f.readings.length||f.devices.length);return{id:a,name:a==="unassigned"?"Nicht zugeordnet":c?.name||t.areas?.[a]?.name||"Bereich nicht verf\xFCgbar",path:c?.path||"",readings:[...d,...u.filter(f=>!p(f))],rooms:h}}).filter(a=>a.readings.length||a.rooms.length)}function dl(t,e,n,r){let i=e.utility_meters?.[n],o=i&&Object.prototype.hasOwnProperty.call(i,r)?i[r]:n==="electricity"&&r==="power"?e.power_entity:null;return o&&o!=="none"?Wo(t,o):null}function jh(t,e,n=e.rooms){let r=Pv(t,e,n).flatMap(o=>o.readings.flatMap(s=>s.sources.map(a=>({kind:s.kind,metric:s.metric,period:s.period,id:a})))),i=[];for(let o of xt)for(let s of["power","energy"]){let a=dl(t,e,o,s);i.push(...gi(t,a?[{kind:o,metric:s,id:a,period:s==="energy"?cl(Vo(String(t.states[a]?.attributes.friendly_name??""))):"total"}]:r.filter(l=>l.kind===o&&l.metric===s),!!a))}return i}function ul(t){return t.metric==="power"?t.unit==="m\xB3/h"?"Durchfluss":"Leistung":{total:"Verbrauch",day:"Verbrauch heute",month:"Verbrauch Monat",year:"Verbrauch Jahr"}[t.period]}function Gh(t,e){let n=e.incomplete?"Err: ":"";if(e.value===null)return`${n}\u2013`;let r=e.unit==="W"&&Math.abs(e.value)>=1e3?e.value/1e3:e.value,i=e.unit==="W"&&Math.abs(e.value)>=1e3?"kW":e.unit,o=Number.isInteger(r)?0:Math.min(6,Math.max(2,1-Math.floor(Math.log10(Math.abs(r)))));return`${n}${K(t,r,o)}${i?` ${i}`:""}`}var Uh=[{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 Zh(t,e,n){let r=O(t.hass,i=>Le(t.hass,i,[1,2]));return m`Eigene Raumzähler
${S("Nur direkt zugewiesene Raumz\xE4hler erscheinen als einger\xFCckte Raumzeile unter dem verkn\xFCpften Bereich. Die Bereichswerte stehen einmal beim Bereich; vorhandene Bereichssummen enthalten die Raumwerte bereits. Fehlt dem Bereich ein passender Z\xE4hler, werden daf\xFCr die eigenen Raumz\xE4hler summiert.","nf-wide")}
${xt.map(i=>m`${nr[i]} ${Mt[i]}${["power","energy"].map(o=>z(t,o==="power"?"Leistung / Durchfluss":"Energie / Verbrauch",e.utility_meters?.[i]?.[o]??null,void 0,r,s=>{let a={...e.utility_meters,[i]:{...e.utility_meters?.[i],[o]:s==="none"?null:s}};Object.values(a[i]).some(l=>l&&l!=="none")||delete a[i],n({utility_meters:Object.keys(a).length?a:null})},{types:[1,2]}))}`)}
`}function qh(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),i=e.hvac?.schedules??[],o=O(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m`
${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,O(t.hass,s=>Le(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}),{types:[0,1,2]})}
${Uh.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,O(t.hass,a=>Le(t.hass,a,s.types)),a=>r({[s.key]:a==="none"?null:a}),{types:s.types}))}
${S("Raumstatus zeigt den in Symcon hinterlegten Alias der Integer-Variable. Beschreibbare Heizungs- und L\xFCftungswerte k\xF6nnen im Raummen\xFC bedient werden.","nf-wide")}
${i.map((s,a)=>z(t,`Schaltuhr ${a+1}`,s,void 0,o.filter(l=>l.id===s||!i.includes(l.id)),l=>r({schedules:l&&l!=="none"?i.map((c,d)=>a===d?l:c):i.filter((c,d)=>a!==d)}),{schedule:!0,excluded:l=>i.includes(l)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0}))}
${z(t,"Schaltuhr hinzuf\xFCgen",null,void 0,o.filter(s=>!i.includes(s.id)),s=>s&&s!=="none"&&r({schedules:[...i,s]}),{schedule:!0,excluded:s=>i.includes(s)?"Diese Schaltuhr ist in diesem Raum bereits verkn\xFCpft.":void 0})}`}function Yh(t,e,n){let r=i=>i==="condition"?[0,1,2,3]:i==="wind_bearing"?[1,2,3]:["snow","fog","lightning"].includes(i)?[0,1,2]:[1,2];return m`Wettervariablen
${Sd.map(i=>z(t,ju[i],e.weather_variables?.[i]??null,void 0,O(t.hass,o=>Le(t.hass,o,r(i))),o=>n({weather_variables:{...e.weather_variables,[i]:o==="none"?null:o}}),{types:r(i)}))}
${z(t,t.t("rain_sensor"),e.rain_sensor??null,void 0,O(t.hass,i=>Le(t.hass,i,[0,1,2])),i=>n({rain_sensor:i==="none"?null:i}),{types:[0,1,2]})}
${e.rain_sensor?D(t,t.t("rain_sensor_inverted"),!!e.rain_sensor_inverted,i=>n({rain_sensor_inverted:i||void 0})):_}
${S("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 Xh(t){let e=t.doc.presence,n=s=>t.replace({...structuredClone(t.doc),presence:s}),r=(s,a)=>n(e.map((l,c)=>c===s?{...l,...a,sensor:null}:l)),i=t.doc.floors.flatMap(s=>s.rooms.map(a=>({id:a.id,name:`${s.name} \xB7 ${a.name}`}))),o=O(t.hass,s=>Le(t.hass,s,[0]));return m`${t.t("presence")}
${e.map((s,a)=>m`
${W(t,"Person",s.name??B(t.hass,s.person),l=>r(a,{name:l}),{wide:!0,maxlength:100})}
${z(t,"Anwesenheit (Boolean)",s.person,void 0,o.filter(l=>l.id===s.person||!e.some(c=>c.person===l.id)),l=>l&&l!=="none"?r(a,{person:l}):n(e.filter((c,d)=>d!==a)),{types:[0],excluded:l=>e.some(c=>c.person===l)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}
`)}
${z(t,"Person hinzuf\xFCgen (Boolean)",null,void 0,o.filter(s=>!e.some(a=>a.person===s.id)),s=>s&&s!=="none"&&n([...e,{person:s,sensor:null}]),{types:[0],excluded:s=>e.some(a=>a.person===s)?"Diese Anwesenheitsvariable ist bereits mit einer Person verkn\xFCpft.":void 0})}
${S("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 Jh(t,e,n){let r=t.find(l=>l.person===e),i="sensor"in n?n.sensor&&n.sensor!=="none"?n.sensor:null:r?.sensor??null,o="room"in n?n.room||null:r?.room??null,s=t.filter(l=>l.person!==e);if(!i&&!o)return s;let a=o?{person:e,sensor:i,room:o}:{person:e,sensor:i};return r?t.map(l=>l.person===e?a:l):[...s,a]}function Qh(t,e){let n=e.slice(e.indexOf(".")+1),r=i=>i.id.includes(n)&&/(area|room|raum|bermuda|espresense)/.test(i.id);return[...t.filter(r),...t.filter(i=>!r(i))]}function ep(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 tp(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 Ko(t,e,n){let r=[...t],[i]=r.splice(e,1);return r.splice(Math.max(0,Math.min(r.length,e+n)),0,i),r}var Ut=(t,e)=>t.filter((n,r)=>r!==e),_i=(t,e,n)=>t.map((r,i)=>i===e?{...r,...n}:r),gt=t=>t.length>0?t:void 0;var Iv=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],Dv=40,Ov=20,Hv=30,Lv=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],hl={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},bi=(t,e,n,r=!1)=>m``;function Cv(t){let e=t.doc.settings.favorites??[],n=a=>t.change(l=>l.settings.favorites=gt(a)),r=t.doc.floors,i=t.doc.settings.favorite_floors??{},o=O(t.hass,a=>Iv.includes(a.split(".")[0])&&!e.includes(a)),s=(a,l)=>m`
${B(t.hass,a)}
${r.length>1?m``:_}
${bi(t.t("move_up"),"\u2191",()=>n(Ko(e,l,-1)),l===0)}
${bi(t.t("move_down"),"\u2193",()=>n(Ko(e,l,1)),l===e.length-1)}
${bi(t.t("delete"),"\u2715",()=>n(Ut(e,l)))}
`;return m`${t.t("favorites")}${e.length>0?m` ${e.length}`:_}
${S(t.t("favorites_hint"))} ${e.map(s)}
${e.length${z(t,t.t("favorites_add"),null,void 0,o,a=>a&&a!=="none"&&!e.includes(a)&&n([...e,a]),{excluded:a=>e.includes(a)?"Diese Variable ist bereits als Favorit verkn\xFCpft.":void 0})}`:_}`}function Nv(t,e){let n=t.doc.settings.outside_hidden??[],r=s=>t.change(a=>a.settings.outside_hidden=gt(s)),i=new Set(t.hass?xu(t.hass,t.doc.floors):[]),o=O(t.hass,s=>!n.includes(s)&&i.has(s));return m`${e?Bv(t,e):_}
${t.t("outside_hidden")}${n.length>0?m` ${n.length}`:_}
${S(t.t("outside_hidden_hint"))}
${n.map((s,a)=>m`${B(t.hass,s)}${bi(t.t("delete"),"\u2715",()=>r(Ut(n,a)))} `)}
${z(t,t.t("outside_hidden_add"),null,void 0,o,s=>s&&s!=="none"&&!n.includes(s)&&r([...n,s]),{excluded:s=>n.includes(s)?"Diese Variable ist hier bereits eingetragen.":void 0})} `}function Bv(t,e){let n=t.doc.settings.outside_view??null,r=()=>{let i=e();i&&t.change(o=>o.settings.outside_view=i)};return m`${S(t.t("outside_view_hint"))}
${Q(m``,n?m``:_)}`}function Vv(t){let e=t.doc.settings.own_alerts??[],n=s=>t.change(a=>a.settings.own_alerts=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=[["",t.t("own_alert_house")],...t.doc.floors.flatMap(s=>s.rooms.map(a=>[a.id,`${a.name} \xB7 ${s.name}`]))],o=(s,a)=>m`
${z(t,t.t("own_alert_entity"),s.entity||null,void 0,O(t.hass,()=>!0),l=>r(a,{entity:l&&l!=="none"?l:""}))}
${W(t,t.t("own_alert_state"),s.state??"",l=>r(a,{state:l||null}),{placeholder:t.hass?.states[s.entity]?.state??"on \xB7 <20 \xB7 >80"})}
${W(t,t.t("own_alert_text"),s.text,l=>r(a,{text:l||t.t("own_alert_new")}),{wide:!0,maxlength:120})}
${H(t,t.t("room"),s.room_id??"",i,l=>r(a,{room_id:l||null}),{wide:!0})}
${Ge(t,t.t("own_alert_color"),s.color??null,"#ffb547",l=>r(a,{color:l}))}
${H(t,t.t("own_alert_tap"),s.tap??"",[["",t.t("own_alert_tap_info")],["toggle",t.t("own_alert_tap_toggle")],["room",t.t("own_alert_tap_room")]],l=>r(a,{tap:l||null}))}
`;return m`⚠ ${t.t("own_alerts")}
${S(t.t("own_alerts_hint"))} ${e.map(o)}
${e.length<40?Q(m``):_}`}function Wv(t){let e=t.doc.settings.circuits??[],n=a=>t.change(l=>l.settings.circuits=gt(a)),r=(a,l)=>n(_i(e,a,l)),i=t.doc.floors.flatMap(a=>a.rooms.map(l=>({id:l.id,label:t.doc.floors.length>1?`${l.name} \xB7 ${a.name}`:l.name}))),o=a=>i.find(l=>l.id===a)?.label??a,s=(a,l)=>m``;return m`🔌 ${t.t("circuits")}
${S(t.t("circuits_hint"))} ${e.map(s)}
${e.length<120?Q(m``):_}`}function Kv(t){let e=t.doc.settings.calendars??[],n=a=>t.change(l=>l.settings.calendars=gt(a)),r=O(t.hass,a=>a.startsWith("calendar.")&&!e.includes(a)),i=(a,l)=>m`
${B(t.hass,a)}
${bi(t.t("delete"),"\u2715",()=>n(Ut(e,l)))}
`,o=t.t,s=t.doc.settings.today_days??1;return m`📅 ${o("today_calendars")}
${S(o("today_calendars_hint"))} ${e.map(i)}
${e.length<12?m`${z(t,o("favorites_add"),null,void 0,r,a=>a&&a!=="none"&&!e.includes(a)&&n([...e,a]),{unsupported:"Dieses Feld ben\xF6tigt eine Kalenderquelle mit Terminen. Eine Symcon-Variable ist kein Kalender; Kalenderquellen werden vom Symcon-Modul derzeit nicht bereitgestellt."})} `:_}
${e.length?m`
${H(t,o("today_days"),String(s),[1,2,3,5,7].map(a=>[String(a),o(a===1?"today_days_one":"today_days_n",{n:a})]),a=>t.change(l=>l.settings.today_days=Number(a)>1?Number(a):void 0))}
`:_}
${jv(t)}`}function jv(t){let e=t.t,n=t.doc.settings.forecast??null,r=i=>t.change(o=>o.settings.forecast=i??void 0);return m`🌦 ${e("forecast")}
${S(e("forecast_hint"))}
${H(t,e("forecast_days"),n?String(n.days):"0",[0,3,5,7].map(i=>[String(i),i?e("today_days_n",{n:i}):e("forecast_off")]),i=>r(Number(i)>0?{days:Number(i),corner:n?.corner??"top_right"}:null))}
${n?H(t,e("forecast_corner"),n.corner,[["top_right",e("clock_top_right")],["top_left",e("clock_top_left")]],i=>r({...n,corner:i==="top_left"?"top_left":"top_right"})):_}
`}function Gv(t){let e=t.doc.settings.media_presets??[],n=s=>t.change(a=>a.settings.media_presets=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=[...new Set(t.doc.floors.flatMap(s=>[...s.placements.map(a=>a.entity_id),...s.furniture.map(a=>a.entity??"")]).filter(s=>s.startsWith("media_player.")))],o=(s,a)=>m``;return m`${t.t("presets")}
${S(t.t("presets_hint"))}
${e.map(o)}
${e.lengthn([...e,{id:P("preset"),label:"Radio",type:"music",content:""}])}>+ ${t.t("preset_add")}`):_}`}function pl(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"}',i=o=>{let s=o.target;s.setCustomValidity("");let a=tp(s.value);if(a.ok)return n(a.value);s.setCustomValidity(t.t("own_data_bad")),s.reportValidity()};return m``}function Uv(t){let e=t.doc.settings.buttons??[],n=s=>t.change(a=>a.settings.buttons=gt(s)),r=(s,a)=>n(_i(e,s,a)),i=Qi.map(s=>[s,t.t(`own_action_${s}`)]),o=(s,a)=>m``;return m`${t.t("own_buttons")}
${S(t.t("own_buttons_hint"))} ${e.map(o)}
${e.lengthn([...e,{id:P("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function Zv(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),i=>t.change(o=>o.settings.room_facts_off=gt(i?e.filter(s=>s!==r):[...e,r]))));return m`${t.t("room_facts")}${n} `}function np(t){return m`${Cv(t)} ${Uv(t)} ${Vv(t)} ${Wv(t)} ${Kv(t)} ${Gv(t)} ${Zv(t)} `}function rp(t,e){return m`
🌳 ${t.t("outside_area")}
${Nv(t,e)}
`}function ip(t,e){let n=t.doc.settings.start_view??null,r=()=>{let i=e();i&&t.change(o=>o.settings.start_view=i)};return m`
${t.t("start_view")}
${S(t.t("start_view_hint"))}
${Q(m``,n?m``:_)}
${n?m`${S(t.t("start_view_saved"))} ${S(t.t("start_view_card"))}${ep(n)}`:_}
`}function op(t){if(Z(t.hass))return Xh(t);let e=t.doc.presence.map(l=>l.person),n=[...new Set([...Object.keys(t.hass?.states??{}).filter(l=>l.startsWith("person.")).sort(),...e])],r=O(t.hass,ge),i=t.doc.floors.flatMap(l=>l.rooms.map(c=>({id:c.id,label:t.doc.floors.length>1?`${l.name} \xB7 ${c.name}`:c.name}))),o=(l,c)=>t.replace({...structuredClone(t.doc),presence:Jh(t.doc.presence,l,c)}),s=l=>{let c=t.doc.presence.find(u=>u.person===l),d=!l.startsWith("person.");return m`${z(t,`${B(t.hass,l)} \xB7 ${t.t("presence_sensor")}`,c?.sensor??null,void 0,Qh(r,l),u=>o(l,{sensor:u}))}
${d?m``:_}`},a=O(t.hass,l=>/^(input_boolean|binary_sensor|device_tracker)\./.test(l)&&!n.includes(l));return m`
${t.t("presence")}
${z(t,t.t("presence_add"),null,void 0,a,l=>l&&l!=="none"&&t.replace({...structuredClone(t.doc),presence:[...t.doc.presence,{person:l,sensor:null}]}))}
${S(t.t("presence_hint"))}
`}function sp(t,e){return Z(t.hass)?m``:m`
${t.t("ble")}
${S(t.t("ble_hint"))}
`}var yi=(t,e)=>{let n=t._$AN;if(n===void 0)return!1;for(let r of n)r._$AO?.(e,!1),yi(r,e);return!0},jo=t=>{let e,n;do{if((e=t._$AM)===void 0)break;n=e._$AN,n.delete(t),t=e}while(n?.size===0)},ap=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),Xv(e)}};function qv(t){this._$AN!==void 0?(jo(this),this._$AM=t,ap(this)):this._$AM=t}function Yv(t,e=!1,n=0){let r=this._$AH,i=this._$AN;if(i!==void 0&&i.size!==0)if(e)if(Array.isArray(r))for(let o=n;o{t.type==On.CHILD&&(t._$AP??=Yv,t._$AQ??=qv)},Go=class extends It{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,n,r){super._$AT(e,n,r),ap(this),this.isConnected=e._$AU}_$AO(e,n=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),n&&(yi(this,e),jo(this))}setValue(e){if(Au(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 fl=new WeakMap,lp=sn(class extends Go{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=fl.get(e);n===void 0&&(n=new WeakMap,fl.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"?fl.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 cp=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 dp(t){let e=t.t,n=t.doc.settings.card_templates??{},r=Object.keys(n),i=a=>t.change(l=>{l.settings.card_templates=Object.keys(a).length?a:void 0});t.loadCardEditor?.();let o=a=>{t.hass?.callService("nextfloor","reload_screens",a?{template:a}:{})},s=a=>{let l=cp(a.value);!l||l in n||r.length>=20||(a.value="",i({...n,[l]:{}}))};return m`
${e("card_templates")}${r.length?m` ${r.length}`:_}
${S(e("card_templates_hint"))}
${r.map(a=>m`
${a}
l&&l.setConfig({type:"custom:nextfloor-card",...n[a]}))}
@config-changed=${l=>{l.stopPropagation();let{type:c,template:d,...u}=l.detail.config;i({...n,[a]:u})}}
>
${t.admin?m`
`:_}
${S(e("template_use",{name:a}))}
`)}
${t.admin?m`
`:_}
`}var Uo=.05,Jv=(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),vn=t=>new Map(t.map(e=>[e.id,e]));function Qv(t,e,n,r){let i=e.name,[o,s]=[vn(t.rooms),vn(e.rooms)];for(let h of e.rooms){let f=o.get(h.id);f?(f.name!==h.name&&n.push({kind:"room_renamed",floor:i,name:h.name,detail:f.name}),Jv(f.points,h.points)||n.push({kind:"room_reshaped",floor:i,name:h.name,detail:Math.round((ye(h.points)-ye(f.points))*10)/10})):n.push({kind:"room_added",floor:i,name:h.name})}for(let h of t.rooms)s.has(h.id)||n.push({kind:"room_removed",floor:i,name:h.name});let[a,l]=[vn(t.openings),vn(e.openings)];for(let h of e.openings)a.has(h.id)||n.push({kind:"opening_added",floor:i,name:h.type,detail:r(h.room_id)});for(let h of t.openings)l.has(h.id)||n.push({kind:"opening_removed",floor:i,name:h.type,detail:r(h.room_id)});let[c,d]=[vn(t.furniture),vn(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)>Uo||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>Uo||Math.abs(h.d-f.d)>Uo)&&n.push({kind:"furniture_moved",floor:i,name:h.name||h.type}):n.push({kind:"furniture_added",floor:i,name:h.name||h.type})}for(let h of t.furniture)d.has(h.id)||n.push({kind:"furniture_removed",floor:i,name:h.name||h.type});let[u,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=u.get(h.entity_id);f?Math.hypot(h.x-f.x,h.z-f.z)>Uo&&n.push({kind:"device_moved",floor:i,name:h.entity_id}):n.push({kind:"device_added",floor:i,name:h.entity_id})}for(let h of t.placements)p.has(h.entity_id)||n.push({kind:"device_removed",floor:i,name:h.entity_id})}function up(t,e){let n=[],r=vn(t.floors),i=new Map([...t.floors,...e.floors].flatMap(a=>a.rooms.map(l=>[l.id,l.name]))),o=a=>i.get(a)??"";for(let a of e.floors){let l=r.get(a.id);l?Qv(l,a,n,o):n.push({kind:"floor_added",floor:a.name,name:a.name})}let s=new Set(e.floors.map(a=>a.id));for(let a of t.floors)s.has(a.id)||n.push({kind:"floor_removed",floor:a.name,name:a.name});return n}var wn=(t,e)=>t.getUint16(e,!0),vi=(t,e)=>t.getUint32(e,!0);function hp(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=-1;for(let a=t.length-22;a>=Math.max(0,t.length-65557);a--)if(vi(e,a)===101010256){n=a;break}if(n<0)throw new Error("not_zip");let r=wn(e,n+10),i=vi(e,n+16),o=[],s=new TextDecoder;for(let a=0;a",quot:'"',apos:"'"},tw=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)):ew[n]??e);function nw(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=tw(n[2]??n[3]);return e}function rw(t){let e=[],n=null;for(let r of t.matchAll(/<(\/?)(level|room|point|wall|doorOrWindow|pieceOfFurniture)\b([^>]*?)(\/?)>/g)){let[,i,o,s,a]=r;if(i){o==="room"&&(n=null);continue}let l=nw(s);if(o==="point"){n&&n.points.push([Number(l.x)/100,Number(l.y)/100]);continue}let c={name:o,attrs:l,...o==="room"?{points:[]}:{}};e.push(c),o==="room"&&!a&&(n=c)}return e}var oe=(t,e,n)=>Number.isFinite(Number(t[e]))&&t[e]!==void 0?Number(t[e]):n,Pe=t=>Math.round(t*1e3)/1e3;function fp(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.max(0,Math.min(o,((t[0]-e[0])*r+(t[1]-e[1])*i)/o)),a=[e[0]+r*s/o,e[1]+i*s/o];return{dist:Math.hypot(t[0]-a[0],t[1]-a[1]),along:s,length:o}}function iw(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 ow(t,e){let n=t.length,r=t.map((i,o)=>{let s=t[(o+1)%n],[a,l]=[s[0]-i[0],s[1]-i[1]],c=Math.hypot(a,l)||1e-9,d=[a/c,l/c],u=[(i[0]+s[0])/2,(i[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]],b=Math.hypot(f,g)||1e-9;if(Math.abs((d[0]*g-d[1]*f)/b)>.05)continue;let y=(h.a[0]-u[0])*-d[1]+(h.a[1]-u[1])*d[0],v=((u[0]-h.a[0])*f+(u[1]-h.a[1])*g)/b;if(!(Math.abs(y)>h.thickness/2+.06||v<-.05||v>b+.05)){p=[-d[1]*y,d[0]*y];break}}return{p:[i[0]+p[0],i[1]+p[1]],dir:d}});return r.map((i,o)=>{let s=r[(o-1+n)%n],a=s.dir[0]*i.dir[1]-s.dir[1]*i.dir[0];if(Math.abs(a)<1e-6)return i.p;let l=((i.p[0]-s.p[0])*i.dir[1]-(i.p[1]-s.p[1])*i.dir[0])/a;return[s.p[0]+s.dir[0]*l,s.p[1]+s.dir[1]*l]})}function sw(t){let e=Pt(),n={floors:0,rooms:0,openings:0,walls:0,furniture:0},r=t.filter(l=>l.name==="level"),i=r.length?r.map(l=>l.attrs.id??""):[""],o=t.filter(l=>l.name==="wall"),s=o.length?Math.max(...o.map(l=>oe(l.attrs,"height",250)))/100:2.5;return(r.length?[...r].sort((l,c)=>oe(l.attrs,"elevation",0)-oe(c.attrs,"elevation",0)||oe(l.attrs,"elevationIndex",0)-oe(c.attrs,"elevationIndex",0)):[{name:"level",attrs:{id:""}}]).forEach((l,c)=>{let d=l.attrs.id??"",u=b=>r.length?(b.attrs.level??i[0])===d:!0,p=Ee(P("floor"),l.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Pe(oe(l.attrs,"elevation",0)/100));p.height=Pe(oe(l.attrs,"height",s*100)/100);let h=o.filter(u).map(b=>({a:[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],b:[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100],thickness:oe(b.attrs,"thickness",10)/100})),f=t.filter(b=>b.name==="room"&&u(b)&&(b.points?.length??0)>=3).map((b,y)=>({id:P("room"),name:b.attrs.name||`Raum ${y+1}`,area_id:null,points:ow(b.points,h).map(([v,w])=>[Pe(v),Pe(w)]),floor_material:"wood",panel:[]}));p.rooms=f;for(let b of t.filter(y=>y.name==="doorOrWindow"&&u(y))){let y=[oe(b.attrs,"x",0)/100,oe(b.attrs,"y",0)/100],v=Math.max(.6,oe(b.attrs,"depth",30)/100+.3),w=null;for(let L of f)L.points.forEach((I,N)=>{let V=fp(y,I,L.points[(N+1)%L.points.length]);V.dist<=v&&(!w||V.dist1.4?2:1,swing:"in",cover:null,contact:null,contact2:null,tilt:null})}let g=[];for(let b of o.filter(u)){let y=[oe(b.attrs,"xStart",0)/100,oe(b.attrs,"yStart",0)/100],v=[oe(b.attrs,"xEnd",0)/100,oe(b.attrs,"yEnd",0)/100];if(Math.hypot(v[0]-y[0],v[1]-y[1])<.1)continue;let w=Math.max(.15,oe(b.attrs,"thickness",10)/100),k=F=>f.some(L=>L.points.some((I,N)=>fp(F,I,L.points[(N+1)%L.points.length]).dist[y[0]+(v[0]-y[0])*F/M,y[1]+(v[1]-y[1])*F/M],T=Array.from({length:M+1},(F,L)=>!k(A(L)));for(let F=0;F<=M;){if(!T[F]){F++;continue}let L=F;for(;L+1<=M&&T[L+1];)L++;let[I,N]=[A(Math.max(0,F-1)),A(Math.min(M,L+1))];Math.hypot(N[0]-I[0],N[1]-I[1])>=.3&&g.push({id:P("wall"),a:[Pe(I[0]),Pe(I[1])],b:[Pe(N[0]),Pe(N[1])],thickness:Pe(oe(b.attrs,"thickness",10)/100),height:b.attrs.height?Pe(oe(b.attrs,"height",250)/100):null}),F=L+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(l=>l.name==="pieceOfFurniture").length,{building:Oe(e),report:n}}async function mp(t){let e=hp(t).find(i=>i.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await pp(t,e)),r=sw(rw(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function aw(t){let e=t.split(/\r?\n/),n=[];for(let r=0;r+1r===9&&i==="$INSUNITS"),n=e>=0?Number(t[e+1]?.[1]):NaN;return{1:.0254,2:.3048,4:.001,5:.01,6:1}[n]??null}function cw(t){let e=aw(t),n=lw(e),r=e.findIndex(([s,a],l)=>s===2&&a==="ENTITIES"&&e[l-1]?.[1]==="SECTION"),i=[];if(r<0)return{shapes:i,unit:n};let o=r+1;for(;oNumber(c.find(([h])=>h===p)?.[1]??NaN),u=[[d(10),d(20)],[d(11),d(21)]];u.every(([p,h])=>Number.isFinite(p)&&Number.isFinite(h))&&i.push({points:u,closed:!1})}else if(a==="LWPOLYLINE"){let d=c.filter(([f])=>f===10).map(([,f])=>Number(f)),u=c.filter(([f])=>f===20).map(([,f])=>Number(f)),p=Number(c.find(([f])=>f===70)?.[1]??0),h=d.map((f,g)=>[f,u[g]]).filter(([f,g])=>Number.isFinite(f)&&Number.isFinite(g));h.length>=2&&i.push({points:h,closed:(p&1)===1})}o=l}return{shapes:i,unit:n}}var gp=t=>Math.round(t*1e3)/1e3;function _p(t){let{shapes:e,unit:n}=cw(t);if(!e.length)throw new Error("dxf_empty");let r=e.flatMap(h=>h.points),i=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]))),o=n??(i>2e3?.001:i>200?.01:1),s=Math.min(...r.map(h=>h[0])),a=Math.max(...r.map(h=>h[1])),l=([h,f])=>[gp((h-s)*o),gp((a-f)*o)],c=Ee(P("floor"),"Erdgeschoss",0),d=[],u=[];for(let h of e){let f=h.points.map(l);if(h.closed&&f.length>=3)d.push({id:P("room"),name:`Raum ${d.length+1}`,area_id:null,points:f,floor_material:"wood",panel:[]});else for(let g=0;g+1.05&&u.push({id:P("wall"),a:f[g],b:f[g+1]})}c.rooms=d,c.walls=u;let p=Pt();return p.floors=[c],{building:Oe(p),report:{floors:1,rooms:d.length,openings:0,walls:u.length,furniture:0}}}var Qe=t=>Math.round(t*100)/100;function dw(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function uw(t,e){let n=t,r=n?.transform,i=n?.dimensions;if(!n||!Array.isArray(r)||r.length<16||!Array.isArray(i)||i.length<3)return null;let o=a=>Number(a),s=Math.hypot(o(r[0]),o(r[2]));return![...r.slice(0,16),...i.slice(0,3)].every(a=>Number.isFinite(o(a)))||s<1e-6?null:{centre:[o(r[12]),o(r[13]),o(r[14])],dir:[o(r[0])/s,o(r[2])/s],size:[o(i[0]),o(i[1]),o(i[2])],kind:dw(n,e)}}var rr=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>uw(r,n)).filter(r=>!!r);function hw(t){if(t.length<3)return null;let e=t.map(l=>{let c=l.size[0]/2;return[[l.centre[0]-l.dir[0]*c,l.centre[2]-l.dir[1]*c],[l.centre[0]+l.dir[0]*c,l.centre[2]+l.dir[1]*c]]}),n=(l,c)=>Math.hypot(l[0]-c[0],l[1]-c[1]),r=.4,i=new Set([0]),o=[e[0][0]],s=[0],a=e[0][1];for(;i.sizer?null:(o[0]=[(a[0]+o[0][0])/2,(a[1]+o[0][1])/2],{points:o,edgeWall:s})}function bp(t){let e=[],n=[];for(let a of t){let l=a.size[0]/2;for(let c of[-1,1])e.push(a.centre[0]+c*a.dir[0]*l),n.push(a.centre[2]+c*a.dir[1]*l)}let[r,i,o,s]=[Math.min(...e),Math.max(...e),Math.min(...n),Math.max(...n)];return[[r,o],[i,o],[i,s],[r,s]]}function pw(t,e,n){let[r,i]=[n[0]-e[0],n[1]-e[1]],o=Math.hypot(r,i)||1e-9,s=Math.min(o,Math.max(0,((t[0]-e[0])*r+(t[1]-e[1])*i)/o));return{dist:Math.hypot(t[0]-(e[0]+r/o*s),t[1]-(e[1]+i/o*s)),along:s,length:o}}var fw={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 yp(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)&&rr(r,"walls","wall").length>0)}function vp(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(b=>b&&typeof b=="object").map(b=>({walls:rr(b,"walls","wall"),doors:[...rr(b,"doors","door"),...rr(b,"openings","opening")],windows:rr(b,"windows","window"),objects:rr(b,"objects","object")})).filter(b=>b.walls.length);if(!r.length)throw new Error("roomplan_empty");let i=r.flatMap(b=>b.walls),o=Math.min(...i.map(b=>b.centre[1]-b.size[1]/2)),s=r.map(b=>hw(b.walls)),a=r.flatMap((b,y)=>s[y]?.points??bp(b.walls)),[l,c]=[Math.min(...a.map(b=>b[0]))-.5,Math.min(...a.map(b=>b[1]))-.5],d=([b,y])=>[Qe(b-l),Qe(y-c)],u=Ee(P("floor"),"Erdgeschoss",0);u.height=Qe(Math.max(2.2,Math.min(4,Math.max(...i.map(b=>b.size[1])))));let p=[],h=[];r.forEach((b,y)=>{let w=(s[y]?.points??bp(b.walls)).map(d),k={id:P("room"),name:`Raum ${y+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(k);for(let x of[...b.doors.map(M=>({v:M,window:!1})),...b.windows.map(M=>({v:M,window:!0}))]){let M=[x.v.centre[0]-l,x.v.centre[2]-c],A=null;if(w.forEach((I,N)=>{let V=pw(M,I,w[(N+1)%w.length]);V.dist<=.6&&(!A||V.dist1.4?2:1,swing:"in",...L?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let x of b.objects){let M=fw[x.kind];if(!M)continue;let[A,T,F]=[x.size[0],x.size[2],x.size[1]];A<.1||T<.1||h.push({id:P("f"),type:M,x:Qe(x.centre[0]-l),z:Qe(x.centre[2]-c),rotation:Math.round((Math.atan2(x.dir[1],x.dir[0])*180/Math.PI+360)%360),w:Qe(A),d:Qe(T),h:Qe(F),variant:null,entity:null,power:null})}}),u.rooms=p,u.furniture=h;let f=Pt();f.floors=[u];let g=r.reduce((b,y)=>b+y.objects.length,0)-h.length;return{building:Oe(f),report:{floors:1,rooms:p.length,openings:u.openings.length,walls:0,furniture:g}}}var wi=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function mw(t){let e=0,n=()=>{for(;t[e]===" ";)e++;let i=t[e];if(i==="("){e++;let l=[];for(;eString.fromCharCode(...(n.match(/.{4}/g)??[]).map(r=>parseInt(r,16)))).replace(/\\S\\(.)/g,(e,n)=>String.fromCharCode(n.charCodeAt(0)+128))}function _w(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:mw(r[3])});return e}var wp={x:0,y:0,z:0,c:1,s:0},xp=(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 kp(t){let e=_w(t);if(!e.size)throw new Error("ifc_empty");let n=x=>wi(x)?e.get(x.ref):void 0,r=x=>typeof x=="number"?x:NaN,i=x=>(n(x)?.args[0]??[]).map(M=>r(M)),o=[...e.values()].find(x=>x.type==="IFCSIUNIT"&&x.args[1]===".LENGTHUNIT."),s=o?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(o.args[2])]??1:1,a=x=>{let M=n(x);if(!M)return wp;let[A=0,T=0,F=0]=i(M.args[0]),L=n(M.type==="IFCAXIS2PLACEMENT3D"?M.args[2]:M.args[1]),[I=1,N=0]=(L?.args[0]??[]).map(X=>r(X)),V=Math.hypot(I,N)||1;return{x:A||0,y:T||0,z:F||0,c:I/V,s:N/V}},l=(x,M=0)=>{let A=n(x);return!A||A.type!=="IFCLOCALPLACEMENT"||M>30?wp:xp(l(A.args[0],M+1),a(A.args[1]))},c=x=>{for(let M of n(x)?.args[2]??[])for(let A of n(M)?.args[3]??[]){let T=n(A);if(T?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(T.args[0]),L=xp(a(T.args[1]),a(F?.args[2])),I=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[N,V]=[r(F.args[3])/2,r(F.args[4])/2];I=[[-N,-V],[N,-V],[N,V],[-N,V]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let N=n(F.args[2]);N?.type==="IFCPOLYLINE"&&(I=(N.args[0]??[]).map(V=>i(V)))}if(I=I.filter(N=>Number.isFinite(N[0])&&Number.isFinite(N[1])),I.length>3&&Math.hypot(I[0][0]-I[I.length-1][0],I[0][1]-I[I.length-1][1])<1e-6&&I.pop(),I.length>=3)return I.map(([N,V])=>[L.x+L.c*N-L.s*V,L.y+L.s*N+L.c*V])}return null},d=new Map;for(let[,x]of e){if(x.type==="IFCRELAGGREGATES"&&wi(x.args[4]))for(let M of x.args[5]??[])wi(M)&&d.set(M.ref,x.args[4].ref);if(x.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&wi(x.args[5]))for(let M of x.args[4]??[])wi(M)&&d.set(M.ref,x.args[5].ref)}let u=[...e].filter(([,x])=>x.type==="IFCBUILDINGSTOREY").map(([x,M])=>({id:x,name:String(M.args[7]||M.args[2]||"")||null,elevation:r(M.args[9])*s}));u.sort((x,M)=>(x.elevation||0)-(M.elevation||0));let p=[];for(let[x,M]of e){if(M.type!=="IFCSPACE")continue;let A=c(M.args[6]);if(!A)continue;let T=l(M.args[5]),F=A.map(([I,N])=>[(T.x+T.c*I-T.s*N)*s,(T.y+T.s*I+T.c*N)*s]),L=String(M.args[7]||M.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:d.get(x)??null,name:L,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(x=>x.ring),f=Math.min(...h.map(x=>x[0])),g=Math.max(...h.map(x=>x[1])),b=x=>Math.round(x*1e3)/1e3,y=[],v=new Map;if(u.filter(x=>p.some(M=>M.storey===x.id)).forEach((x,M)=>{let A=Ee(P("floor"),x.name??`Etage ${M+1}`,Number.isFinite(x.elevation)?b(x.elevation):M*2.8);y.push(A),v.set(x.id,A)}),p.some(x=>x.storey===null||!v.has(x.storey))){let x=Ee(P("floor"),y.length?"Weitere R\xE4ume":"Erdgeschoss",y.length?y[y.length-1].elevation+2.8:0);y.push(x),v.set(null,x)}y.forEach((x,M)=>{let A=y[M+1];A&&A.elevation-x.elevation>1.8&&(x.height=b(A.elevation-x.elevation-.2))});for(let x of p)v.get(x.storey!==null&&v.has(x.storey)?x.storey:null).rooms.push({id:P("room"),name:x.name,area_id:null,points:x.ring.map(([A,T])=>[b(A-f),b(g-T)]),floor_material:"wood",panel:[]});let k=Pt();return k.floors=y,{building:Oe(k),report:{floors:y.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var Sp="nextfloor",bw="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",$p=new RegExp(`^(?:${bw})\\.[a-z0-9_]+$`),yw=/^[0-9a-f]{32}$/,vw=new Set(["area_id","ha_floor"]),ww=new Set(["sub_areas"]),xw=new Set(["tap","show_when","pictures","moods"]);function ml(t){if(typeof t=="string")return $p.test(t)||yw.test(t)?null:t;if(Array.isArray(t))return t.map(e=>ml(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))$p.test(n)||xw.has(n)||(vw.has(n)||ww.has(n)?e[n]=null:e[n]=ml(r));return e}return t}var kw=["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 Mp(t){let e=structuredClone(t),n={};for(let i of kw)e.settings?.[i]!==void 0&&(n[i]=e.settings[i]);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 i of e.floors){i.background=null,i.placements=[],i.power_entity=null,i.utility_meters=null,i.ha_floor=null;for(let o of i.rooms)Object.assign(o,{area_id:null,sub_areas:null,panel:[],hidden:[],no_state:[]});i.furniture.forEach(o=>{Object.assign(o,{entity:null,power:null}),delete o.effect_animations,o.picture&&!(o.picture.startsWith("image:")||o.picture.startsWith("https://"))&&(o.picture=null)}),i.openings.forEach(o=>Object.assign(o,{cover:null,contact:null,tilt:null}))}return ml(e)}function Ep(t,e){return{format:Sp,version:1,exported_at:new Date().toISOString(),building:e?Mp(t):structuredClone(t)}}var $w=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),Sw="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function Rp(t,e,n,r,i=Sw){let o=new Set(t.floors.flatMap(c=>c.furniture.map(d=>d.type)).filter(c=>c.startsWith("pack:")).map(c=>c.split(":")[1])),s={building:Mp(t),packs:e.filter(c=>!c.builtin&&o.has(c.id))},a=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,d=>({"&":"&","<":"<",">":">",'"':"""})[d]);return`
${l(n)}
|