/*! NextFloor, MIT licence. Includes three.js (MIT) and Lit (BSD-3-Clause); see LICENSE and THIRD_PARTY_NOTICES.md */ var $={cs:"4be67fcd522e",da:"0fe66a82bf2a",es:"bd89dffd1355",fi:"9a17bc084f56",fr:"6312d0f61ebf",hu:"27ba348531dc",it:"1b705e76dd00",nb:"c5ea24fb9ef6",nl:"b64142c67c2e",pl:"8527a4930402",pt:"31857a2d2277",ro:"e3cb5f449f0f",sk:"320611594db0",sl:"8071691ceda3",sv:"711b911ec8da",tr:"7c83ce1c3372",zh:"50518d9f494e"};var Zc=[],Gi=new Map,Vb=0,pe=(t,e)=>`pack:${t}:${e}`,vt=t=>t.startsWith("pack:");function Ls(t){Zc=t,Gi=new Map;for(let e of t)for(let n of e.items)Gi.set(pe(e.id,n.id),n);Vb+=1}var zr=()=>Zc;var Wb={};function U(t){if(!vt(t))return;let e=Gi.get(t);if(e)return e;let[,n,...r]=t.split(":"),i=Wb[n];return i?Gi.get(pe(i,r.join(":"))):void 0}var Kb=.22;function jc(t,e,n,r){let i=Math.min(Kb,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[jc(t*r,n*r,r,i)/i,jc(e*r,n*r,r,i)/i]}var Gc=new WeakMap;function qc(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=Gc.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,x,k,M]=[u.tx??u.x,u.tz??u.z,u.tw??u.w,u.td??u.d],[A,E]=Tr(w-k/2,w+k/2,-.5,i,e),[F,O]=Tr(x-M/2,x+M/2,-.5,o,n);Object.assign(v,{tx:(A+E)/2,tz:(F+O)/2,tw:E-A,td:O-F})}return v});return l||Gc.set(t,l=new Map),l.size>32&&l.clear(),l.set(a,d),d}var Cs=t=>!!t?.parts.some(e=>e.move);var Yc=t=>U(t)?.parts.find(e=>e.screen),Uc=.06;function Xc(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>=Uc&&s>=Uc})}function ht(t){return rt[t]??U(t)?.size??[.6,.6,.8]}function It(t){let e=U(t);return od.has(t)||!!e?.electric||!!e?.light||!!e?.climate}var Jc=t=>!!U(t)?.parts.some(e=>e.picture),Dn=t=>!!U(t)?.climate;function Qc(t,e){return t.name[e.split("-")[0]]??t.name.en??Object.values(t.name)[0]??t.id}var jb={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 ed(t,e){if(e.split("-")[0]==="de")return t.name;let n=/^nextfloor\.(.+)$/.exec(t.id)?.[1];return n&&jb[n]||t.name}function Dt(t,e){return e.mount_y!=null?e.mount_y:Ub(t,e)+(Gb(e)?0:rd(t,e.x,e.z))}var Gb=t=>t.type==="led_strip"||U(t.type)?.mount==="ceiling";function Ub(t,e){if(e.type==="lamp_wall")return td;if(e.type==="led_strip")return Math.max(0,pt(t,e.x,e.z)-.04-Math.max(.02,e.h));let n=U(e.type);if(!n)return nd(e);switch(n.mount){case"surface":return id(t,e.x,e.z);case"wall":return n.wall_y??1;case"ceiling":return Math.max(0,Ui(t,e)-e.h);default:return 0}}function Ns(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 wt=["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"],ad=["turn","slide","top"],ld=["always","active","no_power","never"],cd=1.3,Zi=(t,e=new Date().toISOString().slice(0,10))=>!!t.due&&t.due<=e,dd=["gable","hip","halfhip","pyramid","mansard","pent","flat","parapet"],ud=["brick","round","wide","steel"],qi=["navigate","more_info","service","fire_dom_event"];function Yi(t,e,n){return t?e?!!n.lock_plan:!!t.locked:!1}var hd=["rain","snow","fog","clouds","lightning","sky"],pd=["rain","snow","clouds","lightning","sky"],fd=["lawn","terrace","path","driveway","pavers","stepping_stones","natural_stone","street","sidewalk","gravel","river","stream","pool","bed","wild","hedge","fence","pergola"],Bs={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 Vs(t){return t==="hedge"||t==="fence"||t==="pergola"}var md=["x","-x","z","-z"];function Zb(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 gd(t)+(e.offset??0)+Bs[e.type]-Zb(e,n,r)}function gd(t){return t.elevation>.3?0:-.2}function _d(t,e,n){let r=(t.outdoor??[]).filter(o=>!Vs(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):gd(t)}var Ws=t=>t.cut??(t.type==="pool"||t.type==="river"||t.type==="stream");function Xi(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 bd=30,yd={meter:null,grid:null,grid_invert:!1,solar:null,battery:null,battery_invert:!1,battery_soc:null,consumption:null,tariff:null},vd=["wood","oak","tiles","carpet","stone","concrete"],wd={type:"none",pitch:35,overhang:.4},Ji="#d6cfc2",Qi="#e8e3da",kd={wall_exterior:.24,wall_interior:.12,grid:.05,north:0,roof:{...wd}};function Ot(){return{version:1,floors:[],settings:{...kd},energy:{...yd},presence:[]}}function Re(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 Yb=2.75;function xd(t,e){if(e!=null&&Number.isFinite(e))return Math.round(e*Yb*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 $d(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 Sd(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 eo=["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"],Md={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"]},je=["meter","inverter","home_battery","wallbox","grid_point"],Ed=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"]),td=1.75;function to(t){return Ks.has(t.type)||["stairwell","parking"].includes(t.type)?!1:U(t.type)?.mount!=="ceiling"}function he(t){return Ed.has(t)||!!U(t)?.light}var Xb=new Set(["table","table_round","coffee_table","desk","nightstand","sideboard","dresser","kitchen","island","worktop","tv_board","dishwasher","washer","dryer"]);function Rd(t,e,n,r=0){let i=le(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 nd(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 Ks=new Set(["lamp_ceiling","lamp_downlight","lamp_spot","lamp_panel","lamp_pendant","ceiling_fan"]);function Ad(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 js=t=>t?.floor_offset&&Number.isFinite(t.floor_offset)?t.floor_offset:0;function rd(t,e,n){let r=t.rooms.find(i=>i.points.length>=3&&i.floor_offset&&C([e,n],i.points));return js(r)}function pt(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 Ui=(t,e)=>e.ceiling_y!=null&&e.ceiling_y>0?e.ceiling_y:pt(t,e.x,e.z);function id(t,e,n){let r=0;for(let i of t.furniture)!(Xb.has(i.type)||U(i.type)?.surface)||!C([e,n],qs(i))||(r=Math.max(r,i.h));return r}var od=new Set([...Ed,"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"]),rt={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 Gs=["interior","front","front_glass","sidelight","sidelights","glass","sliding","passage"],Us=["standard","bars","glass_wall"],no=new Set(["interior","front"]);function rn(t,e){return t.type==="door"?t.style&&Gs.includes(t.style)?t.style:e?"front":"interior":t.style&&Us.includes(t.style)?t.style:"standard"}function Fd(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 Zs(t){return t==="front"||t==="front_glass"||t==="sidelight"||t==="sidelights"}var Hn={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 Ln(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&&Zs(t.style)?"front":e?"door_double":"door":t.sill<.1?e?"terrace_double":"terrace":e?"window_double":"window"}function He(t){t.energy={...yd,...t.energy??{}},t.presence=t.presence??[],t.version=1,t.settings={...kd,...t.settings,roof:{...wd,...t.settings?.roof??{}}},t.floors.forEach((e,n)=>{let r=Re(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]=rt[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 Jb(t),t.topology&&io(t),t}function Jb(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=I(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=I("room"));e(n.openings,"op"),e(n.furniture,"furn"),e(n.outdoor,"out")}}function I(t){return`${t}_${Math.random().toString(36).slice(2,10)}`}function ve(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 le(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 qs(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 ro={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 Ht=t=>[t.kind,t.ownerKind,t.floorId,t.id].filter(Boolean).join(":");function xt(t){return t?.outdoor_building_id?{kind:"building",id:t.outdoor_building_id}:t?.outdoor_branch_id?{kind:"branch",id:t.outdoor_branch_id}:t?.outdoor_location_id?{kind:"location",id:t.outdoor_location_id}:null}var ce=t=>!!xt(t),kt=t=>({kind:"outside",id:t.id,...t.kind!=="location"?{ownerKind:t.kind}:{}});function Nn(t,e){return e.kind==="outside"?t.floors.find(n=>{let r=xt(n);return r?.kind===(e.ownerKind??"location")&&r.id===e.id}):void 0}function Td(t,e="Geb\xE4ude 1"){if(t.topology)return;let n=I("location"),r=I("branch"),i=I("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 io(t){let e=t.topology;e.locations??=[],e.branches??=[],e.buildings??=[];let n=o=>(o||=e.locations[0]?.id||I("location"),e.locations.some(s=>s.id===o)||e.locations.push({id:o,name:"Ort"}),o),r=o=>(o||=e.branches[0]?.id||I("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||I("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){let s=xt(o);if(s){let a=s.kind==="building"?i(s.id):s.kind==="branch"?r(s.id):n(s.id);o.outdoor_location_id=s.kind==="location"?a:null,o.outdoor_branch_id=s.kind==="branch"?a:null,o.outdoor_building_id=s.kind==="building"?a:null,o.building_id=null}else o.building_id=i(o.building_id)}}function zd(t,e){let n=Nn(t,kt(e));if(n)return n;let r={...Re(I("outside"),"Au\xDFen",0),[e.kind==="building"?"outdoor_building_id":e.kind==="branch"?"outdoor_branch_id":"outdoor_location_id"]:e.id,building_id:null};return t.floors.push(r),r}function Ys(t,e,n){let r=t.floors.find(o=>o.id===e),i=xt(r);return n?{kind:"room",id:n,floorId:e}:i?kt(i):{kind:"floor",id:e}}function Qb(t){let e=(a,l,c,d=[],u=d.flatMap(h=>h.floorIds),p)=>{let h={kind:a,...l?{id:l}:{},...p?{floorId:p.floorId}:{}};return{key:Ht(h),name:c,selection:h,floorIds:[...new Set(u)],children:d,...p?{room:p}:{}}},n=a=>e("floor",a.id,a.name,a.rooms.map(l=>e("room",l.id,l.name,[],[a.id],{floorId:a.id,roomId:l.id})),[a.id]);if(!t.topology)return e("all",void 0,"Alle Etagen",[...t.floors].sort((a,l)=>l.elevation-a.elevation).map(n));let r=t.topology,i=(a,l)=>{let c=Nn(t,kt(a));if(!c)return l;let d=e("outside",a.id,"Au\xDFen",c.rooms.map(u=>e("room",u.id,u.name,[],[c.id],{floorId:c.id,roomId:u.id})),[c.id]);return d.selection=kt(a),d.key=Ht(d.selection),[...l,d]},o=a=>{let l=t.floors.filter(c=>!ce(c)&&c.building_id===a.id).sort((c,d)=>d.elevation-c.elevation);return e("building",a.id,a.name,i({kind:"building",id:a.id},l.map(n)))},s=a=>e("branch",a.id,a.name,i({kind:"branch",id:a.id},r.buildings.filter(l=>l.branch_id===a.id).map(o)));return e("all",void 0,"Alle Orte",r.locations.map(a=>e("location",a.id,a.name,i({kind:"location",id:a.id},r.branches.filter(l=>l.location_id===a.id).map(s)))))}function Pr(t,e){let n=Qb(t),r=Ht(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 Xs(t,e){let n=Pr(t,e),r=n.at(-1);return r.selection.kind==="room"?n.at(-2).children:!r.children.length&&["floor","outside"].includes(r.selection.kind)?[r]:r.children}function oo(t,e,n=!1){if(!t.topology||e.kind==="all")return t.floors;let r=Pr(t,e),i=(n&&(e.kind==="floor"||e.kind==="room")?r.find(s=>s.selection.kind==="outside")??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 Bn(t,e){return t.topology?Pr(t,Ys(t,e.id)).slice(1).map(n=>n.name).join(" / "):e.name}var on=t=>t?Ht(t):"";function so(t){if(!t)return null;let e=xt(t);return e?kt(e):t.building_id?{kind:"building",id:t.building_id}:null}function Js(t,e){return!e||!t.topology?!1:e.kind==="outside"?!!Nn(t,e):t.topology[e.kind==="building"?"buildings":e.kind==="branch"?"branches":"locations"].some(n=>n.id===e.id)}function sn(t,e){return t.topology?Js(t,e)?oo(t,e).filter(n=>e.kind!=="building"||!ce(n)):[]:t.floors}function Pd(t,e){return{scope:e,floorId:e.kind==="branch"||e.kind==="location"?null:sn(t,e)[0]?.id??null}}function Id(t,e){if(!t.topology)return{scope:null,floorId:t.floors.some(i=>i.id===e.floorId)?e.floorId:t.floors[0]?.id??null};let n=Js(t,e.scope)?e.scope:so(t.floors.find(i=>i.id===e.floorId)??t.floors[0])??(t.topology.buildings[0]?{kind:"building",id:t.topology.buildings[0].id}:null),r=sn(t,n);return n?.kind==="branch"||n?.kind==="location"?{scope:n,floorId:null}:{scope:n,floorId:r.some(i=>i.id===e.floorId)?e.floorId:r[0]?.id??null}}function ao(t){let e=t.topology;return e?[...e.locations.map(r=>({kind:"location",id:r.id})),...e.branches.map(r=>({kind:"branch",id:r.id})),...e.buildings.map(r=>({kind:"building",id:r.id})),...t.floors.filter(ce).map(r=>so(r))].map(r=>[on(r),Pr(t,r).slice(1).map(i=>i.name).join(" / ")]):[]}function Qs(t,e){let[n,...r]=e.split(":"),i=n==="outside"&&r.length>1?r.shift():void 0,o=r.join(":"),s=["building","branch","location","outside"].includes(n)?{kind:n,id:o,...i?{ownerKind:i}:{}}:null;return Js(t,s)?s:null}function Dd(t,e,n,r){let i=t.floors.find(o=>o.id===n);return e!==n||!i||ce(i)||!t.topology?.buildings.some(o=>o.id===r)||i.building_id===r?!1:(i.building_id=r,!0)}var lo=globalThis,co=lo.ShadowRoot&&(lo.ShadyCSS===void 0||lo.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,ea=Symbol(),Od=new WeakMap,Ir=class{constructor(e,n,r){if(this._$cssResult$=!0,r!==ea)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=n}get styleSheet(){let e=this.o,n=this.t;if(co&&e===void 0){let r=n!==void 0&&n.length===1;r&&(e=Od.get(n)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&Od.set(n,e))}return e}toString(){return this.cssText}},Hd=t=>new Ir(typeof t=="string"?t:t+"",void 0,ea),J=(t,...e)=>{let n=t.length===1?t[0]:e.reduce((r,i,o)=>r+(s=>{if(s._$cssResult$===!0)return s.cssText;if(typeof s=="number")return s;throw Error("Value passed to 'css' function must be a 'css' function result: "+s+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[o+1],t[0]);return new Ir(n,t,ea)},Ld=(t,e)=>{if(co)t.adoptedStyleSheets=e.map(n=>n instanceof CSSStyleSheet?n:n.styleSheet);else for(let n of e){let r=document.createElement("style"),i=lo.litNonce;i!==void 0&&r.setAttribute("nonce",i),r.textContent=n.cssText,t.appendChild(r)}},ta=co?t=>t:t=>t instanceof CSSStyleSheet?(e=>{let n="";for(let r of e.cssRules)n+=r.cssText;return Hd(n)})(t):t;var{is:ey,defineProperty:ty,getOwnPropertyDescriptor:ny,getOwnPropertyNames:ry,getOwnPropertySymbols:iy,getPrototypeOf:oy}=Object,uo=globalThis,Cd=uo.trustedTypes,sy=Cd?Cd.emptyScript:"",ay=uo.reactiveElementPolyfillSupport,Dr=(t,e)=>t,na={toAttribute(t,e){switch(e){case Boolean:t=t?sy:null;break;case Object:case Array:t=t==null?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=t!==null;break;case Number:n=t===null?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch{n=null}}return n}},Bd=(t,e)=>!ey(t,e),Nd={attribute:!0,type:String,converter:na,reflect:!1,useDefault:!1,hasChanged:Bd};Symbol.metadata??=Symbol("metadata"),uo.litPropertyMetadata??=new WeakMap;var $t=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,n=Nd){if(n.state&&(n.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((n=Object.create(n)).wrapped=!0),this.elementProperties.set(e,n),!n.noAccessor){let r=Symbol(),i=this.getPropertyDescriptor(e,r,n);i!==void 0&&ty(this.prototype,e,i)}}static getPropertyDescriptor(e,n,r){let{get:i,set:o}=ny(this.prototype,e)??{get(){return this[n]},set(s){this[n]=s}};return{get:i,set(s){let a=i?.call(this);o?.call(this,s),this.requestUpdate(e,a,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??Nd}static _$Ei(){if(this.hasOwnProperty(Dr("elementProperties")))return;let e=oy(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(Dr("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(Dr("properties"))){let n=this.properties,r=[...ry(n),...iy(n)];for(let i of r)this.createProperty(i,n[i])}let e=this[Symbol.metadata];if(e!==null){let n=litPropertyMetadata.get(e);if(n!==void 0)for(let[r,i]of n)this.elementProperties.set(r,i)}this._$Eh=new Map;for(let[n,r]of this.elementProperties){let i=this._$Eu(n,r);i!==void 0&&this._$Eh.set(i,n)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){let n=[];if(Array.isArray(e)){let r=new Set(e.flat(1/0).reverse());for(let i of r)n.unshift(ta(i))}else e!==void 0&&n.push(ta(e));return n}static _$Eu(e,n){let r=n.attribute;return r===!1?void 0:typeof r=="string"?r:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),this.renderRoot!==void 0&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){let e=new Map,n=this.constructor.elementProperties;for(let r of n.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){let e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Ld(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,n,r){this._$AK(e,r)}_$ET(e,n){let r=this.constructor.elementProperties.get(e),i=this.constructor._$Eu(e,r);if(i!==void 0&&r.reflect===!0){let o=(r.converter?.toAttribute!==void 0?r.converter:na).toAttribute(n,r.type);this._$Em=e,o==null?this.removeAttribute(i):this.setAttribute(i,o),this._$Em=null}}_$AK(e,n){let r=this.constructor,i=r._$Eh.get(e);if(i!==void 0&&this._$Em!==i){let o=r.getPropertyOptions(i),s=typeof o.converter=="function"?{fromAttribute:o.converter}:o.converter?.fromAttribute!==void 0?o.converter:na;this._$Em=i;let a=s.fromAttribute(n,o.type);this[i]=a??this._$Ej?.get(i)??a,this._$Em=null}}requestUpdate(e,n,r,i=!1,o){if(e!==void 0){let s=this.constructor;if(i===!1&&(o=this[e]),r??=s.getPropertyOptions(e),!((r.hasChanged??Bd)(o,n)||r.useDefault&&r.reflect&&o===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,n,r)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,n,{useDefault:r,reflect:i,wrapped:o},s){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??n??this[e]),o!==!0||s!==void 0)||(this._$AL.has(e)||(this.hasUpdated||r||(n=void 0),this._$AL.set(e,n)),i===!0&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(n){Promise.reject(n)}let e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(let[i,o]of this._$Ep)this[i]=o;this._$Ep=void 0}let r=this.constructor.elementProperties;if(r.size>0)for(let[i,o]of r){let{wrapped:s}=o,a=this[i];s!==!0||this._$AL.has(i)||a===void 0||this.C(i,void 0,o,a)}}let e=!1,n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),this._$EO?.forEach(r=>r.hostUpdate?.()),this.update(n)):this._$EM()}catch(r){throw e=!1,this._$EM(),r}e&&this._$AE(n)}willUpdate(e){}_$AE(e){this._$EO?.forEach(n=>n.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(n=>this._$ET(n,this[n])),this._$EM()}updated(e){}firstUpdated(e){}};$t.elementStyles=[],$t.shadowRootOptions={mode:"open"},$t[Dr("elementProperties")]=new Map,$t[Dr("finalized")]=new Map,ay?.({ReactiveElement:$t}),(uo.reactiveElementVersions??=[]).push("2.1.2");var ia=globalThis,Vd=t=>t,ho=ia.trustedTypes,Wd=ho?ho.createPolicy("lit-html",{createHTML:t=>t}):void 0,oa="$lit$",St=`lit$${Math.random().toFixed(9).slice(2)}$`,sa="?"+St,ly=`<${sa}>`,cn=document,Hr=()=>cn.createComment(""),Lr=t=>t===null||typeof t!="object"&&typeof t!="function",aa=Array.isArray,qd=t=>aa(t)||typeof t?.[Symbol.iterator]=="function",ra=`[ \f\r]`,Or=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Kd=/-->/g,jd=/>/g,an=RegExp(`>|${ra}(?:([^\\s"'>=/]+)(${ra}*=${ra}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),Gd=/'/g,Ud=/"/g,Yd=/^(?:script|style|textarea|title)$/i,la=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),m=la(1),R=la(2),G1=la(3),it=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Zd=new WeakMap,ln=cn.createTreeWalker(cn,129);function Xd(t,e){if(!aa(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return Wd!==void 0?Wd.createHTML(e):e}var Jd=(t,e)=>{let n=t.length-1,r=[],i,o=e===2?"":e===3?"":"",s=Or;for(let a=0;a"?(s=i??Or,u=-1):d[1]===void 0?u=-2:(u=s.lastIndex-d[2].length,c=d[1],s=d[3]===void 0?an:d[3]==='"'?Ud:Gd):s===Ud||s===Gd?s=an:s===Kd||s===jd?s=Or:(s=an,i=void 0);let h=s===an&&t[a+1].startsWith("/>")?" ":"";o+=s===Or?l+ly:u>=0?(r.push(c),l.slice(0,u)+oa+l.slice(u)+St+h):l+St+(u===-2?a:h)}return[Xd(t,o+(t[n]||"")+(e===2?"":e===3?"":"")),r]},Cr=class t{constructor({strings:e,_$litType$:n},r){let i;this.parts=[];let o=0,s=0,a=e.length-1,l=this.parts,[c,d]=Jd(e,n);if(this.el=t.createElement(c,r),ln.currentNode=this.el.content,n===2||n===3){let u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(i=ln.nextNode())!==null&&l.length0){i.textContent=ho?ho.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=dn(this,e,n,0),s=!Lr(e)||e!==this._$AH&&e!==it,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 Vn(e.insertBefore(Hr(),o),o,void 0,n??{})}return i._$AI(t),i};var ca=globalThis,q=class extends $t{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){let e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){let n=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=eu(n,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return it}};q._$litElement$=!0,q.finalized=!0,ca.litElementHydrateSupport?.({LitElement:q});var dy=ca.litElementPolyfillSupport;dy?.({LitElement:q});(ca.litElementVersions??=[]).push("4.2.2");var me=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); } `,d$=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; } `,ft=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 Wn={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},hn=t=>(...e)=>({_$litDirective$:t,values:e}),Lt=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 Nr=class extends Lt{constructor(e){if(super(e),this.it=_,e.type!==Wn.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===it)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:[]}}};Nr.directiveName="unsafeHTML",Nr.resultType=1;var tu=hn(Nr);var ua=t=>t.slice(0,t.indexOf(".")),uy={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=>uy[ua(t)]??null,ha=["light","cover","climate","media","switch","fan","lock","binary","sensor","scene","script"];var nu=new Set(["light","switch","fan"]),Ct=t=>t!==null&&t!=="scene"&&t!=="script",Le=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 ru=t=>!!t&&t.entity_id.startsWith("sensor.")&&t.attributes.device_class==="enum";var iu=t=>Math.min(1,Math.max(0,t));function hy(t){let e=iu((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 da(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(iu(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:hy(n.color_temp_kelvin),level:r}:{color:[1,.71,.28],level:r}}function ou(t,e,n){let r=da(t,n);if(r)return r;for(let i of e){let o=da(i);if(o)return{color:o.color,level:o.level*.6}}return null}function bo(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 pa=t=>t.trim().replace(/^\/local\/www\//i,"/local/"),fa=t=>/^(https:\/\/|\/local\/|\/hacsfiles\/)\S+\.m?js(\?\S*)?$/i.test(t.trim());var fy=globalThis,au=fy.__nextfloorPluginStore??={plugins:new Map,listeners:new Set},ma=au.plugins,su=au.listeners;var my=5;function lu(t,e){t.errors.lengthsu.delete(t)}var ga=()=>[...ma.values()].map(t=>t.status),cu=()=>[...ma.values()].flatMap(t=>Object.keys(t.plugin.lightAnimations??{}));function*vo(t,e){for(let{plugin:n,status:r}of ma.values())for(let i of n.devices??[]){let o=!1;try{o=i.match(t,e)}catch(s){lu(r,s)}o&&(yield{device:i,status:r})}}function wo(t,e){for(let{device:n}of vo(t,e))return n.kind??"sensor";return null}function du(t,e){let n=t.states[e];if(!n)return null;let r=gy({hass:t,entityId:e,state:n})?.icon?.trim();return r&&/^mdi:[a-z0-9-]+$/i.test(r)?r:null}function gy(t){let e=null;for(let{device:n,status:r}of vo(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){lu(r,i)}return e}function ko(t,e){return t?typeof t=="string"?t:t[e]??t[e.split("-")[0]]??t.en??Object.values(t)[0]??"":""}function uu(t,e){let n=[];for(let{device:r,status:i}of vo(t,e))r.settings?.length&&n.push({pluginId:i.id,name:i.name,settings:r.settings});return n}function hu(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 pu(t,e){for(let{device:n}of vo(t,e))if(n.floorWedge)return!0;return!1}var _y=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"]),by=new Set(["m\xB3","m3","L","l","kWh","Wh","MWh","lx"]),yy=new Set(["door","window","opening","garage_door","motion","occupancy","presence","smoke","moisture","gas","carbon_monoxide"]),vy=new Set(["battery","signal_strength","timestamp","date","duration","data_rate","data_size","frequency","enum"]);function Nt(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 mu=(t,e)=>{let n=t.entities?.[e];return!!(n?.hidden||n?.entity_category)},Ge=(t,e)=>ee(e)??wo(e,t.states[e]);function fu(t,e){let n=t.states[e];if(!n||mu(t,e))return!1;if(wo(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?_y.has(i):by.has(String(n.attributes.unit_of_measurement??"")):r==="binary"?i?yy.has(i):!!t.entities?.[e]?.area_id:!0}function wy(t,e){let n=t.states[e];return ee(e)!=="sensor"||!n?.attributes.unit_of_measurement||mu(t,e)||vy.has(String(n.attributes.device_class??""))?!1:Number.isFinite(Number(n.state))||Le(n)}var $o=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power",_a=null;yo(()=>_a=null);function ba(t,e){let n=t.get(e);return n||t.set(e,n=[]),n}function ky(t){let e=new Map,n=new Map,r=new Map,i=new Map,o=[],s=d=>{(fu(t,d)||wy(t,d))&&Ct(Ge(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&&$o(t,d)&&ba(n,p).push(d),p&&!u.hidden&&!u.entity_category&&(r.get(p)??r.set(p,new Set).get(p)).add(ua(d));let h=Nt(t,d);h===null?s(d):fu(t,d)&&ba(e,h).push(d)}if(t.entities)for(let d of Object.keys(t.states))t.entities[d]||s(d);let a=ha.indexOf("binary")-.5,l=d=>{let u=ee(d),p=u?ha.indexOf(u):a;return p>a&&wo(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 Kn(t){let e=_a;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:_a=ky(t)}function ke(t,e){let n=xo(t,e.area_id);return e.sub_areas?.length?[...new Set([...n,...e.sub_areas.flatMap(r=>xo(t,r))])]:n}function xo(t,e){return!e||!t.entities?[]:Kn(t).byArea.get(e)??[]}function gu(t,e){if(!t.entities)return[];let n=[];for(let[r,i]of Kn(t).byArea){let o=i.filter(s=>Ct(Ge(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 _u=t=>t.entities?Kn(t).withoutArea:[],ya=(t,e)=>!!t.entities&&Kn(t).hubs.has(e),So=(t,e)=>t.entities?Kn(t).powerByDevice.get(e)??[]:[];function jn(t,e){let n=new Map;for(let i of e)ba(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 Mo=(t,e)=>jn(t,e).map(n=>n.primary),xy={temperature:"temperature",humidity:"humidity",co2:"carbon_dioxide",illuminance:"illuminance"};function va(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===xy[n]}var $y=new Set(["climate","water_heater","switch","button","camera","media_player","vacuum","light","fan","lawn_mower"]),Sy=["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"],My=new RegExp(`(${Sy.join("|")})`,"i");function wa(t,e){let n=t.entities?.[e]?.device_id,r=n&&!ya(t,n)?Kn(t).domainsByDevice.get(n):void 0;return r&&[...r].some(i=>$y.has(i))?!1:!My.test(`${e} ${t.states[e]?.attributes.friendly_name??""}`)}function bu(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([...ke(t,n).filter(c=>!a.has(c)),...s])].filter(c=>c.startsWith("sensor.")&&va(t,c,r)&&wa(t,c))}function yu(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 Eo(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 Ro(t,e){let n=e?t.states[e]:void 0;if(!n||Le(n))return null;let r=n.attributes;if(r.nf_cover_control&&typeof r.current_position=="number")return r.current_position;let i=yu(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 Ey=new Set([void 0,"shutter","blind","awning","shade","curtain","window"]),Ry=new Set(["garage","gate"]),Ay=new Set(["window","opening"]);function Br(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 vu=(t,e)=>t==="none"?null:t??e??null,Bt=t=>t&&t!=="none"?t:null;function Vt(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=ke(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=Br(c("window"),s.filter(g=>ee(g)==="cover"&&Ey.has(a(g))),!0),u=Br(c("window"),l(g=>Ay.has(g))),p=Br(c("door"),l(g=>g==="door")),h=Br(c("garage"),s.filter(g=>ee(g)==="cover"&&Ry.has(a(g)??""))),f=Br(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:vu(g.cover,b?.get(g.id)),contact:g.sensor==="handle"&&g.contact==null?null:vu(g.contact,y.get(g.id)),tilt:g.tilt==="none"?null:g.tilt,contact2:v?Bt(g.contact2):null,tilt2:v?Bt(g.tilt2):null,position:Bt(g.position),positionInverted:!!g.position_inverted,tiltAngle:Bt(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"?Bt(g.lock):null,cover2:g.type==="garage"?null:Bt(g.cover2),coverTilt:Bt(g.cover_tilt),cover2Tilt:Bt(g.cover2_tilt),coverInverted:!!g.cover_inverted,coverTiltInverted:!!g.cover_tilt_inverted,cover2Inverted:!!g.cover2_inverted,cover2TiltInverted:!!g.cover2_tilt_inverted})}}return n}var Fy=[[/^(tilted|tilt|gekippt|kipp)/i,"tilted"],[/^(open|opened|offen|geöffnet|on)$/i,"open"],[/^(closed|close|geschlossen|zu|off)$/i,"closed"]];function ka(t){if(!t||Le(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&&Fy.find(([o])=>o.test(r));if(i)return i[1]}return null}var wu=/\b(tv|fernseh|television|fire ?tv|apple ?tv|chromecast|shield)/i,ku=/(kühl|fridge|gefrier|freezer)/i,xu=/(spülmaschine|geschirrspül|dishwasher)/i,Ty=/(kochfeld|herd|induktion|cooktop)/i,zy={robot_vacuum:/(saug|vacuum|robo|roomba|roborock|dreame|ecovacs|deebot)/i,tv_board:wu,tv_wall:wu,desk:/\b(pc|computer|rechner|desktop|monitor|workstation)/i,fridge:ku,fridge_smart:ku,stove:/(herd|kochfeld|cooktop|stove|induktion)/i,kitchen_tall:/(backofen|oven|ofen)/i,dishwasher:xu,washer:/(waschmaschine|washer|washing)/i,dryer:/(trockner|dryer)/i,kitchen:/(kaffee|coffee|wasserkocher|kettle)/i,island:Ty,sink:xu,radiator:/(heiz|radiator|thermostat|climate|hk|trv)/i},$u={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},Su=new Set(["tv_board","tv_wall"]);var Gn=t=>Su.has(t)||!!Yc(t),Ao=t=>!!U(t)?.electric&&/speaker|multiroom|soundbar/.test(t.split(":").pop()??t),Wr=t=>Gn(t)||t==="desk"||t==="fridge_smart",Py=t=>!!t&&t!=="none";function Iy(t,e){if($o(t,e))return e;let n=t.entities?.[e]?.device_id;return n?So(t,n).find(r=>r!==e)??null:null}var Dy=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Vr(t,e,n,r){return t.find(i=>e?.test(n(i)))??(r?t[0]??null:null)}function Ae(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(Py));for(let o of r.furniture){let s=o.type in $u,a=Dn(o.type),l=s?$u[o.type]:zy[o.type];if(!l&&!a&&!Ao(o.type)&&o.entity==null&&o.power==null)continue;let c=Dy(r,o.x,o.z),d=(c?Mo(t,ke(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?ke(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))??Vr(p("light"),l,u,!1)}else if(s)h=Vr(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)&&Nt(t,y)===b)??null}else if(o.type==="radiator"||a)h=Vr(p("climate"),l,u,!0);else if(Gn(o.type)){let b=p("media");h=b.find(y=>t.states[y]?.attributes.device_class==="tv")??Vr(b,l,u,Su.has(o.type))}else if(Ao(o.type)){let b=p("media").filter(y=>t.states[y]?.attributes.device_class!=="tv");h=Vr(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?Iy(t,h):null,!f&&l&&c&&!s&&(f=ke(t,c).find(b=>$o(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?ke(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 Mu=t=>t==="fridge"||t==="fridge_smart"||/(fridge|freezer|kuehl|gefrier|chest_freezer)/.test(t.slice(t.lastIndexOf(":")+1));function Eu(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=Ae(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(...Mo(t,xo(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 Oy(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 Au(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=_e(r),g=[];for(let y=s+u/2;y=p&&g.push({at:w,wallDistance:x})}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,x=-1/0;for(let{at:M,wallDistance:A}of g){let E=b.length?Math.min(...b.map(P=>Math.hypot(M[0]-P[0],M[1]-P[1]))):3,F=Math.hypot(M[0]-f[0],M[1]-f[1]),O=Math.min(E,3)*2;Fx+1e-9&&(x=O,w=M)}let k=[Math.round(w[0]*100)/100,Math.round(w[1]*100)/100];return b.push(k),{entity_id:y,x:k[0],z:k[1],y:null,mount:null}})}var Ru=/(^|_)(current_room|current_segment|aktueller_raum|current_area)($|_)/;function Fu(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.")&&(Ru.test(o.translation_key??"")||Ru.test(o.entity_id.split(".")[1])))?.entity_id??null}var Z=t=>t?.symconObjects!==void 0;function Ce(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 pn(t){return!t||t.state==="unknown"||t.state==="unavailable"?null:t.attributes.symcon_value??t.attributes.symcon_numeric_value??t.state}function Wt(t){let e=pn(t);if(e===null||typeof e=="boolean"||e==="")return null;let n=Number(e);return Number.isFinite(n)?n:null}function Kr(t){let e=pn(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 xa(t){return pn(t)===null?"\u2013":String(t?.attributes.symcon_formatted??pn(t))}var be=t=>/^(sensor|input_number|number)\./.test(t),Fo=t=>/^(binary_sensor|input_boolean)\./.test(t);function Un(t,e){if(!be(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 Hy(t,e){let n=t?.entities?.[e],r=n?.area_id??(n?.device_id?t?.devices?.[n.device_id]?.area_id:null);return r?t?.areas?.[r]?.name:void 0}function H(t,e){return Object.keys(t?.states??{}).filter(e).map(n=>{let r=Hy(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 Tu(t,e,n){return e.unsupported?[]:H(t,r=>Ce(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 To(t,e){return t.power&&t.power!=="none"?t.power:e.get(t.id)?.power??null}var{I:Ly}=Qd,zu=t=>t;var Iu=t=>t.strings===void 0,Pu=()=>document.createComment(""),Zn=(t,e,n)=>{let r=t._$AA.parentNode,i=e===void 0?t._$AB:e._$AA;if(n===void 0){let o=r.insertBefore(Pu(),i),s=r.insertBefore(Pu(),i);n=new Ly(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=zu(l).nextSibling;zu(r).insertBefore(l,i),l=c}}}return n},Kt=(t,e,n=t)=>(t._$AI(e,n),t),Cy={},Du=(t,e=Cy)=>t._$AH=e,Ou=t=>t._$AH,zo=t=>{t._$AR(),t._$AA.remove()};var Hu=(t,e,n)=>{let r=new Map;for(let i=e;i<=n;i++)r.set(t[i],i);return r},fn=hn(class extends Lt{constructor(t){if(super(t),t.type!==Wn.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=Ou(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]=Kt(i[u],o[h]),u++,h++;else if(a[p]===s[f])l[f]=Kt(i[p],o[f]),p--,f--;else if(a[u]===s[f])l[f]=Kt(i[u],o[f]),Zn(t,l[f+1],i[u]),u++,f--;else if(a[p]===s[h])l[h]=Kt(i[p],o[h]),Zn(t,i[u],i[p]),p--,h++;else if(c===void 0&&(c=Hu(s,h,f),d=Hu(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=Zn(t,i[u]);Kt(y,o[h]),l[h]=y}else l[h]=Kt(b,o[h]),Zn(t,i[u],b),i[g]=null;h++}else zo(i[p]),p--;else zo(i[u]),u++;for(;h<=f;){let g=Zn(t,l[f+1]);Kt(g,o[h]),l[h++]=g}for(;u<=p;){let g=i[u++];g!==null&&zo(g)}return this.ut=s,Du(t,l),it}});var Ny=new Intl.Collator("de",{numeric:!0,sensitivity:"base"}),$a=-1,Cu=[{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"}],Lu=t=>t.object_type===1&&Cu.some(e=>e.type===t.module_type);function By(t){let e=new Map(t.map(l=>[l.object_id,l])),n=t.filter(l=>{if(!Lu(l))return!1;let c=new Set([l.object_id]),d=e.get(l.parent_id);for(;d&&!c.has(d.object_id);){if(Lu(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($a,o($a,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 Cu.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,$a,l.name,p,c));for(let h of d)a(h,u,p)}),[...r.values()]}function Sa(t){let e=By(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||Ny.compare(o.name,s.name));return{nodes:n,children:r}}function Ma(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 Ea(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 Ma(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 Nu=["Boolean","Integer","Float","String"],Vy={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 Bu(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:Nu[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=>Nu[c]).join(" oder ")} ben\xF6tigt.`;let o=e.excluded?.(t.entity_id);if(o)return o;let s=Vy[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 Wy=["Kategorie","Instanz","Variable","Skript","Ereignis","Medium","Link"],Ra=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=Sa([]);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=Sa(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 Ma(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=Bu(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=Ea(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=[R``,R``,R``,R``,R``,R``,R``];return R``}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":Wy[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=Ea(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``:_}
{if(c.stopPropagation(),c.target===this.dialog){let d=this.dialog.getBoundingClientRect();(c.clientXd.right||c.clientYd.bottom)&&this.close()}}} @keydown=${c=>c.stopPropagation()} @change=${c=>c.stopPropagation()}>

Datenpunkt auswählen

IP-Symcon · ${this.context?.label||"Objektbaum"}

${this.fixed.length?m`
${this.fixed.map(c=>m` `)}
`:_}
${fn(s,c=>c.node.object_id,c=>this.renderRow(c))} ${s.length?_:m`

${this.objects.length?"Keine Objekte gefunden.":"Kein Objektbaum verf\xFCgbar. Bitte das Symcon-Modul aktualisieren und den Designer neu laden."}

`}
${this._notice?m`
${this._notice}
`:_}
${o?.name??r?.label??"Noch kein Datenpunkt ausgew\xE4hlt"} ${o?.path??"Nur passende Datenpunkte k\xF6nnen ausgew\xE4hlt werden."}
`}static styles=[me,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",Ra);var Vu=40,Aa=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,Vu)]}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-Vu)}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`
{clearTimeout(this.blurTimer),this._open=!0,this._query="",this._cursor=0}} @blur=${()=>{this.blurTimer=setTimeout(()=>this._open=!1,150)}} @input=${r=>{this._query=r.target.value,this._cursor=0,this._open=!0}} @keydown=${this.onKey} /> ${this._open?m`
    ${n.length?_:m`
  • –
  • `} ${n.map((r,i)=>m`
  • o.preventDefault()} @click=${()=>this.choose(r.id)} > ${r.label}${r.detail||r.id.includes(".")?m`${r.detail??r.id}`:_}
  • `)} ${this.leftOut>0?m`
  • … +${this.leftOut} · ${this.placeholder}
  • `:_}
`:_}
`}static styles=[me,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",Aa);var Fa=class extends q{static properties={text:{attribute:!1}};constructor(){super(),this.text=""}get dialog(){return this.renderRoot.querySelector("dialog")}render(){return m` e.stopPropagation()} @click=${e=>{if(e.target!==e.currentTarget)return;let n=this.dialog.getBoundingClientRect();(e.clientXn.right||e.clientYn.bottom)&&this.dialog?.close()}}>
Information

${this.text}

`}static styles=[me,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",Fa);var mn=t=>t.target.value,Ta=t=>Number.parseFloat(t.replace(",",".")),ae=t=>Math.round(t*1e3)/1e3,Wu=t=>t.wide?"nf-field nf-wide":"nf-field";function T(t,e,n,r,i=.01,o){return m``}function W(t,e,n,r,i={}){return m``}function L(t,e,n,r,i,o={}){return m``}function D(t,e,n,r,i={}){return m``}function Ue(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?Tu(t.hass,s,n):i;return m``}function qn(t,e,n){return n?(n.startsWith("mdi:")?n:`mdi:${n}`).replace(/[^a-z0-9:-]/gi,""):t.hass?du(t.hass,e):null}function jt(t,e,n){let r=e?(e.startsWith("mdi:")?e:`mdi:${e}`).replace(/[^a-z0-9:-]/gi,""):"";return m``}function Yn(t,e,n){return m``}function Gt(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")}
${T(t,"\u2194 x",r.x??0,i("x"),.05)} ${T(t,"\u2195 z",r.z??0,i("z"),.05)} ${T(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 gn(t,e,n,r={}){let i=r.lowest??10;return m``}var za=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}))}outsideButton(e){let n=!!Nn(this.doc,kt(e));return m``}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})})} ${this.outsideButton({kind:"location",id:n.id})}
`:_}

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})})} ${this.outsideButton({kind:"branch",id:r.id})}
`:_}

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})})} ${this.outsideButton({kind:"building",id:i.id})}
`:_}
`}static styles=[me,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",za);var Ku=new WeakMap,ju=new WeakMap;function Gu(t,e){let n=ju.get(t)??t,r=Ku.get(n)??new WeakMap;Ku.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 Vt(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=Ro(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?Ro(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 ju.set(a,n),r.set(e,a),a}function Uu(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 Zu="weather.nextfloor_symcon",Yu={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"},qu=new WeakMap;function Ky(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 Xu(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=qu.get(t)??new WeakMap;qu.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=Wt(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=Wt(f);g!==null&&(o[h]=Uu(g,f?.attributes.unit_of_measurement))}o.wind_speed_unit="km/h";let a=pn(s("wind_bearing"));a!==null&&(o.wind_bearing=a);let l=Ky(xa(s("condition"))),c=e.rain_sensor?t.states[e.rain_sensor]:void 0,d=Kr(c);d!==null&&e.rain_sensor_inverted&&(d=!d),d===null&&typeof o.precipitation=="number"&&(d=o.precipitation>0),Kr(s("lightning"))?l=d?"lightning-rainy":"lightning":Kr(s("snow"))?l=d?"snowy-rainy":"snowy":Kr(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:Zu,state:l??"unknown",attributes:o},p={...t,states:{...t.states,[Zu]:u}};return r.set(e,p),p}var ot=(t,e,n={})=>t.callWS({type:`nextfloor/${e}`,...n});async function Po(t,e){return(await ot(t,"image/get",{image_id:e})).data}async function Ut(t,e,n){await ot(t,"image/set",{image_id:e,data:n})}async function Ju(t){return(await ot(t,"history/list")).snapshots}async function Qu(t,e){return(await ot(t,"history/snapshot",e?{name:e}:{})).id}async function eh(t,e){return(await ot(t,"history/get",{snapshot_id:e})).building}async function th(t,e){await ot(t,"history/delete",{snapshot_id:e})}async function nh(t,e){return(await ot(t,"history/restore",{snapshot_id:e})).revision}var jr=(t,e)=>ot(t,"packs/import",{pack:e});async function rh(t,e){await ot(t,"packs/remove",{pack_id:e})}var ih=t=>ot(t,"backup/export"),oh=(t,e,n)=>ot(t,"backup/import",{building:e,packs:n});var G=(t,e)=>[t[0]-e[0],t[1]-e[1]],mt=(t,e)=>[t[0]+e[0],t[1]+e[1]],st=(t,e)=>[t[0]*e,t[1]*e],te=(t,e)=>t[0]*e[0]+t[1]*e[1],Fe=(t,e)=>t[0]*e[1]-t[1]*e[0],ye=t=>Math.hypot(t[0],t[1]),at=t=>{let e=ye(t)||1;return[t[0]/e,t[1]/e]},Pa=t=>[-t[1],t[0]],Ia=t=>[t[1],-t[0]];var jy=.05,Gy=.2,Uy=.12;function Zy(t){let e=[];return t.forEach((n,r)=>{let i=n.points;if(i.length<3)return;let o=ve(i)>=0;i.forEach((s,a)=>{let l=i[(a+1)%i.length],c=ye(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 qy(t,e,n){if(t.room===e.room||Math.abs(Fe(t.dir,e.dir))>jy||t.outside===e.outside)return null;let r=(e.offset-t.offset)*t.outside;return r>n||r<-Uy||Math.abs(r)<1e-4||Math.min(t.to,e.to)-Math.max(t.from,e.from)Math.round(t*1e3)/1e3;function sh(t,e=.6){let n=Zy(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(Da(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(Fe(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(Fe(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,x)=>w+x,0)/y.size;for(let w of b){let x=n[w],k=[x.normal[0]*(v-x.offset),x.normal[1]*(v-x.offset)];h[x.room][x.index].set(g,k),h[x.room][(x.index+1)%t[x.room].points.length].set(g,k)}}return{rooms:t.map((g,b)=>({...g,points:g.points.map((y,v)=>{let w=[...h[b][v].values()].reduce((x,k)=>[x[0]+k[0],x[1]+k[1]],[y[0],y[1]]);return[Da(w[0]),Da(w[1])]})})),gaps:o}}function ah(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 Yy=.25,lh=t=>Math.round(t*1e3)/1e3,ch=(t,e,n)=>t.rooms.find(r=>r.points.length>=3&&C([e,n],r.points));function Ha(t,e,n,r,i){let o=ch(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 Xy(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 Oa=(t,e)=>Math.abs((t-e+540)%360-180);function Gr(t,e,n,r=Yy){let i=ch(t,e.x,e.z);if(!i)return null;let o=i.points,s=ve(o)>=0?1:-1,a=null;return o.forEach((l,c)=>{let d=o[(c+1)%o.length],u=ye(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=Xy(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((k,M)=>Oa(e.rotation,M.rotation)50)return;let x=b-w.extent;Math.abs(x)>r||a&&Math.abs(x)>=Math.abs(a.gap)||(a={x:lh(e.x-h[0]*x),z:lh(e.z-h[1]*x),rotation:(Math.round(w.rotation)%360+360)%360,gap:x})}),a&&{x:a.x,z:a.z,rotation:a.rotation}}var Xn=Math.PI/180,lt=t=>Math.tan(Math.min(80,Math.max(0,t))*Xn);function Zr(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 dh(t){if(!t.rotation)return null;let e=t.rotation*Xn;return{cx:(t.x0+t.x1)/2,cz:(t.z0+t.z1)/2,c:Math.cos(e),sn:Math.sin(e)}}function uh(t,e){let n=dh(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 La(t,e,n){let r=dh(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 qr(t,e=0){let{x0:n,x1:r,z0:i,z1:o}=Zr(t);return[[n-e,i-e],[r+e,i-e],[r+e,o+e],[n-e,o+e]].map(s=>uh(t,s))}function Se(t){let{x0:e,x1:n,z0:r,z1:i}=Zr(t),o=s=>uh(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 Yr(t,e,n){let{x0:r,x1:i,z0:o,z1:s}=Zr(t),[a,l]=La(t,e,n);return t.axis==="x"?[a,t.flip?s-l:l-o]:[l,t.flip?i-a:a-r]}var Ur=Math.tan(30*Xn);function Xr(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+Ur*(t-s+o))/(2*Ur))),d=a+(c-o)*Ur;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)*Ur:p<=t-s?l+(t-s-p)*Ur:n+(t-p)*i}}function Ne(t){let e=Se(t).w,[n,r]=[t.eave_a,t.eave_b],[i,o]=[lt(t.pitch_a),lt(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=Xr(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 _n=t=>Ne(t).rh;function hh(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 Jy(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 Qy(t,e,n){if(t.a===e.b)return!1;let r=at(G(n[t.b],n[t.a])),i=at(G(n[e.b],n[e.a]));return Math.abs(Fe(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 ph(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]]:hh(r[a[0]]),c=r[a[1]].a===s?r[a[1]]:hh(r[a[1]]);if(!Qy(l,c,e))continue;let d={...l,b:c.b,sources:Jy(l.sources,c.sources)};o=[...r.filter((u,p)=>p!==a[0]&&p!==a[1]),d];break}if(!o)return r;r=o}}function fh(t,e){let n=new Map;t.forEach((i,o)=>{let s=at(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:st(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:mt(s,st(Pa(l.d),l.left)),right:mt(s,st(Ia(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=mt(s,st(Pa(l.d),l.left)),p=mt(s,st(Ia(d.d),d.right)),h=Fe(l.d,d.d);if(Math.abs(h)<1e-4)return;let f=mt(u,st(l.d,Fe(G(p,u),d.d)/h));ye(G(f,s))>a||(r.get(l.key).left=f,r.get(d.key).right=f)})}return r}function mh(t,e){let n=t.filter((r,i)=>ye(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(Fe(at(l),at(c)))<1e-7&&te(l,c)>0});if(r===-1)return n;n=n.filter((i,o)=>o!==r)}}function ev(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 tv(t,e){let n=[];for(let r of t){let i=r.points;if(i.length<3||Math.abs(ve(i))<1e-6)continue;let o=ve(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 nv(t,e,n){let r=[];for(let i of t){let[o,s]=[e[i.u],e[i.v]],a=G(s,o),l=ye(a),c=st(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 rv(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 _h(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 iv(t,e,n,r){let i=rv(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(gh),..._h(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:[gh(c)],..._h(i.heightsOf(u))})}return{drafts:s,open:a}}function ov(t,e){let n=o=>at(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 sv=(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,x)=>{if(!w||x>=v.length)return;let k=v[x],M=G(v[(x+1)%v.length],k),A=ye(M);for(let E of w)E>r&&E{let[w,x]=l[v];if(w===x)return;let k=[(y.a[0]+y.b[0])/2,(y.a[1]+y.b[1])/2],M=t.find(E=>E.points.length>=3&&C(k,E.points))?.id??null,A=(y.thickness??e.interior)/2;h.push({free:y.id,a:w,b:x,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=ph(h,o.points,c),g=fh(f,o.points);return{walls:f.map((y,v)=>{let[w,x]=[o.points[y.a],o.points[y.b]],[k,M]=[g.get(`${v}:a`),g.get(`${v}:b`)],A=mh([k.right,M.left,x,M.right,k.left,w],1e-6);return{id:sv(w,x),a:[w[0],w[1]],b:[x[0],x[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 mt(r,st(at(G(t.points[(e+1)%t.points.length],r)),n))}function Be(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=at(G(i.b,i.a));return{room:{id:t.room_id,name:"",area_id:null,points:[i.a,i.b,mt(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),at(G(t.b,t.a)));function Zt(t,e,n){if(!e.wall)return av(t,n.room,n.edge,e.offset);let r=t.find(i=>i.free===e.wall);return r?{wall:r,s:bh(r,Jn(n.room,0,e.offset))}:null}function av(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:bh(i,Jn(e,n,r))};return null}function yh(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 vh=([t,e])=>{let n=Math.hypot(t,e)||1;return[t/n,e/n]};function lv(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 wh(t,e){let n=t.length;if(n<3||Math.abs(e)<1e-9)return t.map(([i,o])=>[i,o]);let r=lv(t)>=0?1:-1;return t.map((i,o)=>{let s=t[(o+n-1)%n],a=t[(o+1)%n],[l,c]=vh([i[0]-s[0],i[1]-s[1]]),[d,u]=vh([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 qt(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 cv(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(we(s))>Math.abs(we(i)))&&(i=s)}return i}function Ca(t,e,n,r){let i=ge(t,{exterior:n,interior:r},e).walls.filter(a=>a.exterior&&!a.free),o=i.length?cv(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?wh(s,n):null}function bn(t,e){let n=Se(t),r=Ne(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]=[lt(t.pitch_a),lt(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)),x=w+(r.rh-w)*Math.min(.9,Math.max(.2,t.halfhip??.55)),k=f>1e-6?Math.min(r.vr,(x-t.eave_a)/f):r.vr,M=g>1e-6?Math.max(r.vr,i-(x-t.eave_b)/g):r.vr,A=Math.min(y-.1,(r.rh-x)/Math.max(.2,f)),E=[[0,r.y(0)],[r.vr,r.rh],[i,r.y(i)]],F=[[0,r.y(0)],[k,x],[M,x],[i,r.y(i)]],O=(j,nn,ji)=>{if(j==="hip")return{upA:[],upB:[],ridge:b(nn===a?n.u0+v*ji:n.u1-v*ji),profile:null};if(j==="halfhip"){let Nb=b(nn===a?n.u0+A:n.u1-A);return{upA:[[nn,k,x]],upB:[[nn,M,x]],ridge:Nb,profile:F}}return{upA:[],upB:[],ridge:b(nn),profile:E}},P=O(t.ends[0],a,1),N=O(t.ends[1],l,1),V=[[d,u,...N.upA,N.ridge,P.ridge,...[...P.upA].reverse()],[P.ridge,N.ridge,...[...N.upB].reverse(),p,h,...P.upB]],X=[[P.ridge,N.ridge]];for(let[j,nn,ji]of[[P,d,h],[N,u,p]])j.profile===null?(V.push(j===P?[h,d,j.ridge]:[u,p,j.ridge]),X.push([nn,j.ridge],[ji,j.ridge])):j.upA.length&&(V.push(j===P?[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 $e=j=>j.profile===null?[]:j.upA.length?[j.upA[0],j.upB[0]]:[j.ridge],Pt=[d,u,...$e(N),p,h,...[...$e(P)].reverse()];return{faces:V,rim:Pt,ridges:X,gable:E,endProfiles:[P.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),x=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,x,w],[w,x,p,h],[h,d,w],[u,p,x]],rim:[d,u,p,h],ridges:[[w,x],[d,w],[h,w],[u,x],[p,x]],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,x=g>1e-6?Math.max(r.vr,i-(v-t.eave_b)/g):r.vr,k=Math.min((n.u1-n.u0)/2-.1,(r.rh-v)/Math.max(.2,f)),M=b(n.u0+k),A=b(n.u1-k),E=[a,w,v],F=[a,x,v],O=[l,w,v],P=[l,x,v];return{faces:[[d,u,O,A,M,E],[M,A,P,p,h,F],[F,E,M],[O,P,A]],rim:[d,u,O,P,p,h,F,E],ridges:[[M,A],[E,M],[F,M],[O,A],[P,A]],gable:[[0,r.y(0)],[w,v],[x,v],[i,r.y(i)]]}}case"mansard":{let y=Xr(i,t.eave_a,t.eave_b,f,g),v=[a,y.vla,y.yla],w=[l,y.vla,y.yla],x=[a,i-y.vlb,y.ylb],k=[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,k,x],[x,k,p,h]],rim:[d,u,w,A,k,p,h,x,M,v],ridges:[[M,A],[v,w],[x,k]],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 Jr(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 Qr(t,e,n){let r=Se(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 Io=t=>Math.abs((t.x1-t.x0)*(t.z1-t.z0)),kh=t=>t.shape==="flat"||t.shape==="parapet",yn=t=>Math.round(t*100)/100;function Do(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||kh(o)||Io(o)=s.x0&&n<=s.x1&&r>=s.z0&&r<=s.z1}).reduce((o,s)=>o===null||Io(s){let[o,s]=e.at(i,e.w/2),[a,l]=Yr(t,o,s);return Jr(n,a,l)??r.y(l)}}function Ba(t,e){if(kh(e))return e;let n=Se(e),r=Ne(e).rh,i=uv(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 Va=.14,xh=t=>t.shape==="flat"||t.shape==="parapet";function Wa(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]=Yr(s,e,n),g=Math.max(0,s.overhang??r),b=xh(s)?null:Jr(bn(s,{u0:g,u1:g,a:g,b:g}),h,f);o.push((b??Ne(s).y(f))-Va)}return o.length?Math.max(...o):null}function Ka(t,e,n){let r=[],i=e+n+Va;for(let o of t.settings.roof.sections??[]){if(o.open||xh(o)||o.shape==="mansard")continue;let s=Se(o),a=Ne(o),[l,c]=[lt(o.pitch_a),lt(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 ja(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 Ga(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 Mt=t=>Math.round(t*1e3)/1e3;function Ua(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=>Mt(y[0]))))].sort((b,y)=>b-y),u=[...new Set(c.flatMap(b=>b.points.map(y=>Mt(y[1]))))].sort((b,y)=>b-y),p=u.slice(0,-1).map((b,y)=>d.slice(0,-1).map((v,w)=>{let x=[(d[w]+d[w+1])/2,(u[y]+u[y+1])/2];return a(c,x)&&!a(s,x)})),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 E=b;E<=w;E++)for(let F=y;F<=v;F++)h[E][F]=!0;let[x,k]=[d[y]-r,d[v+1]+r],[M,A]=[u[b]-r,u[w+1]+r];Math.min(k-x,A-M)<.8||o.push({id:e(o.length),x0:Mt(x),z0:Mt(M),x1:Mt(k),z1:Mt(A),shape:"gable",axis:k-x>=A-M?"x":"z",eave_a:Mt(g),eave_b:Mt(g),pitch_a:n,pitch_b:n,base:Mt(g),overhang:null})}s.push(...c)}return o}var Te=Math.PI/180,Ze=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],vn=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Qn=t=>Math.hypot(t[0],t[1],t[2]),wn=t=>{let e=Qn(t)||1;return[t[0]/e,t[1]/e,t[2]/e]},$h=(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]],qe=t=>Math.round(t*100)/100,ti=([t,e],n)=>(Math.atan2(t,-e)/Te-n+720)%360;var Mh=.25;function Eh(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 Rh(t,e){let n=wn($h(t,e));return n[1]<0?[-n[0],-n[1],-n[2]]:n}var Ah=t=>{let e=wn([-t[0],0,-t[2]]);return[e[0],e[2]]};function Et(t,e,n,r,i,o,s,a){let l=wn(Ze(i,r)),c=wn(Ze(o,r));return{key:t,section:e,side:n,flat:!1,o:r,eu:l,es:c,n:Rh(l,c),lu:Qn(Ze(i,r)),ls:Qn(Ze(o,r)),pitch:s,span:a,facing:Ah(c)}}function Sh(t,e,n,r,i,o){let s=Qn(Ze(i,r));if(s<.3)return null;let a=wn(Ze(i,r)),l=Ze(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=Qn(d);if(u<.3)return null;let p=wn(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:Rh(a,p),lu:s,ls:u,pitch:Math.atan2(p[1],Math.hypot(p[0],p[2]))/Te,span:h,facing:Ah(p)}}function hv(t,e){let n=Se(t),r=Ne(t),i=(v,w,x)=>{let[k,M]=n.at(v,w);return[k,x,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[Eh(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+Mh)]}if(t.shape==="pent")return[Et(`${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 pv(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(Et(`${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(Et(`${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=Sh(`${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=Sh(`${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(x=>x!==null))}return y}function pv(t,e,n,r,i,o){let s=Xr(e.w,t.eave_a,t.eave_b,lt(t.pitch_a),lt(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)/Te,u=[],[p,h]=[e.w+o,e.w-s.vlb];return s.vla+i>.3&&u.push(Et(`${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(Et(`${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(Et(`${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(Et(`${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 Za(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=>hv(w,Qr(t,w,w.overhang??e.overhang)));let n=Za(t);if(!n)return[];let r=n.rooms.flatMap(w=>w.points.map(x=>x[0])),i=n.rooms.flatMap(w=>w.points.map(x=>x[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[Eh("main",null,s,l,a,c,d+Mh)];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*Te),g=(w,x,k)=>p?[w,d+k,(l+c)/2+x]:[(s+a)/2+x,d+k,w],[b,y]=p?[s,a]:[l,c],v=()=>[0,y-b];return[Et("main:a",null,"a",g(b,-h,0),g(y,-h,0),g(b,0,f),e.pitch,v),Et("main:b",null,"b",g(b,h,0),g(y,h,0),g(b,0,f),e.pitch,v)]}function Ye(t,e){let n=[];for(let r of t.floors.filter(i=>!e||i.id===e)){let{walls:i}=ge(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 Ve="ground";function Oo(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 Ho(t,e){let n=(e.rotation??0)*Te,r=[Math.cos(n),0,Math.sin(n)],i=[-Math.sin(n),0,Math.cos(n)],o=Oo(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:_d(o,s,a)):e.base??0;return{key:Ve,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 Me(t,e,n=Y(t)){return e.face===Ve?Ho(t,e):e.face.startsWith("wall:")?Ye(t,e.face.split(":")[1]).find(r=>r.key===e.face)??null:n.find(r=>r.key===e.face)??null}var Lo=1.13,ri=1.72,Xe=.025,ct=.07;function kn(t){let e=t.module_w||Lo,n=t.module_h||ri;return t.portrait===!1?[n,e]:[e,n]}function ii(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 qa(t,e){return t.flat?Math.min(45,Math.max(0,e.tilt??15))*Te:t.wall?Math.min(90,Math.max(0,e.tilt??0))*Te:Math.min(45,Math.max(0,e.tilt??0))*Te}function oi(t,e){let[,n]=kn(e),r=qa(t,e);return t.wall?n*Math.cos(r)+Xe:!t.flat&&r<.001?n+Xe:t.flat&&e.rack==="ew"?n*Math.cos(r)+.08:n*Math.cos(r)+Math.max(.3,2*n*Math.sin(r))}function er(t,e){let[n,r]=kn(e),i=ii(e),o=Math.max(1,...i);return[o*n+(o-1)*Xe,(i.length-1)*oi(t,e)+r*Math.cos(qa(t,e))]}var fv=t=>t.flat&&!t.unbounded&&!t.wall;function Fh(t,e){if(!fv(t)||!e.rotation)return null;let n=e.rotation*Te,[r,i]=er(t,e);return{cos:Math.cos(n),sin:Math.sin(n),u:e.u+r/2,s:e.v+i/2}}function Je(t,e,n=!1){let[r,i]=kn(e),o=qa(t,e),s=i*Math.cos(o),a=oi(t,e),l=ii(e),c=Math.max(1,...l),d=new Set(e.skip??[]),u=Fh(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,x]=p(b,y);return[0,1,2].map(k=>t.o[k]+t.eu[k]*w+t.es[k]*x+t.n[k]*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[x,k]=t.span(w);return v>=x-1e-6&&v<=k+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,E],[A,E],[A,F],[M,F]].every(([O,P])=>f(O,P)))if(t.wall&&o>.001){let O=ct+i*Math.sin(o),[P,N]=e.flip?[O,ct]:[ct,O],V=[h(M,E,P),h(A,E,P),h(A,F,N),h(M,F,N)],X=e.flip?E:F;g.push({corners:V,posts:[M+.05,A-.05].map($e=>[h($e,X,0),h($e,X,O)]),cell:x,skipped:k})}else if(!t.flat&&o>.001){let O=ct+i*Math.sin(o),P=[h(M,E,ct),h(A,E,ct),h(A,F,O),h(M,F,O)];g.push({corners:P,posts:[M+.05,A-.05].map(N=>[h(N,F,0),h(N,F,O)]),cell:x,skipped:k})}else if(!t.flat)g.push({corners:[h(M,E,ct),h(A,E,ct),h(A,F,ct),h(M,F,ct)],posts:[],cell:x,skipped:k});else{let P=.15+i*Math.sin(o),N=e.rack==="ew"&&y%2===1?!e.flip:!!e.flip,[V,X]=N?[F,E]:[E,F],$e=[h(M,V,.15),h(A,V,.15),h(A,X,P),h(M,X,P)],Pt=[M+.05,A-.05].flatMap(j=>[[h(j,V,0),h(j,V,.15)],[h(j,X,0),h(j,X,P)]]);g.push({corners:$e,posts:Pt,cell:x,skipped:k})}}}),g}function gt(t,e){if(t.unbounded)return{u:e.u,v:e.v};let[n,r]=er(t,e),i=Fh(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 si(t,e){let[n,r]=er(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 Co=.78,ai=1.18,xn=t=>({id:t.id,face:t.face,u:t.u,v:t.v,rows:1,cols:1,portrait:!0,module_w:t.w||Co,module_h:t.h||ai});function Ya(t,e){let n=Je(t,xn(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 ni={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 $n(t){let e=t.shape??"brick",n=ni[e]??ni.brick;return{shape:e,w:t.w||n.w,d:t.d||n.d,h:t.h||n.h}}function Rt(t,e){let{w:n,d:r}=$n(t),i=e&&!e.flat?Math.cos(e.pitch*Te):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 Xa(t,e){let n=Rt(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 Ja(t,e){let[n]=kn(e);return qe((t.lu-(e.cols*n+(e.cols-1)*Xe))/2)}var li=.4;function tr(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]=kn(n),[i,o]=t.span(t.ls/2);for(n.cols=Math.max(1,Math.floor((o-i-2*li+Xe)/(r+Xe))),n.rows=Math.max(1,Math.min(4,Math.floor((t.ls-2*li)/oi(t,n))));n.cols>1&&Je(t,{...n,u:Ja(t,n),v:li}).lengtha.lu*(1.3+Math.cos((ti(a.facing,r)-180)*Math.PI/180)),o=Ye(t,n).sort((a,l)=>i(l)-i(a))[0];if(!o)return null;let s={...tr(o,e),portrait:!1,rows:1};return s.cols=Math.max(1,Math.floor((o.lu-.8+Xe)/(ri+Xe))),s.u=qe((o.lu-(s.cols*ri+(s.cols-1)*Xe))/2),s.v=qe(Math.max(0,o.ls-Lo-.3)),s}function ci(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:Ve,u:qe(r),v:qe(i),rows:2,cols:4,portrait:!0,tilt:25,flip:!0,rotation:(t.settings.north??0)||0,look:"black",entity:null}}function di(t,e,n){let r=Ho(t,e),[i,o]=er(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*Te,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:qe(d),v:qe(u),rotation:(Math.round(n)%360+360)%360}}function ui(t,e){let[n,r]=t.span(t.ls/2);return{id:e,face:t.key,u:qe((n+r-Co)/2),v:qe(Math.max(0,Math.min(t.ls-ai,t.ls*.45-ai/2))),w:null,h:null,cover:null,contact:null,tilt:null}}function hi(t,e){let n=ni.brick,[r,i]=t.span(t.ls*.8),o=Rt({id:e,face:t.key,u:0,v:0},t).module_h;return{id:e,face:t.key,u:qe((r+i-n.w)/2),v:qe(Math.max(0,Math.min(t.ls-o,t.ls*.8-o/2))),shape:"brick",w:null,d:null,h:null}}function nr(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 el(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=nr(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 Bo(t,e,n){let r=vn(n,t.n);if(Math.abs(r)<1e-6)return null;let i=vn(Ze(t.o,e),t.n)/r;if(i<=0)return null;let o=Ze([e[0]+n[0]*i,e[1]+n[1]*i,e[2]+n[2]*i],t.o);return{t:i,u:vn(o,t.eu),s:vn(o,t.es)}}function tl(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 nl(t,e,n,r){return Je(t,e).some(o=>{let s=o.corners.map(c=>{let d=Ze(c,t.o);return[vn(d,t.eu),vn(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 mv=["n","ne","e","se","s","sw","w","nw"],rl=(t,e)=>mv[Math.round(ti(t.facing,e)/45)%8];function pi(t,e){let n=r=>{if(r.flat)return r.lu*r.ls*.8;let i=Math.cos((ti(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 Ih=["kitchen_row","kitchen_l","bath","bedroom","living","dining","office","kids","hall"],Th={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]]}},zh=t=>typeof t=="string"?t:t[0],Vo=t=>typeof t=="string"?rt[t]:t[1],rr=.05,gv=.02,Ph=t=>Math.round(t*1e3)/1e3;function _v(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 Dh(t,e,n){let r=le(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:Ph(c),z:Ph(d),rotation:u,w:p,d:h,h:f,variant:null,entity:null,power:null})};for(let[l,c,d]of Th[e].rows){let u=l==="back"||l==="front"?i:o,p=0,h=[];for(let g of d){if(p+Vo(g)[0]>u-.1)break;h.push(g),p+=Vo(g)[0]}let f=c==="start"?rr:c==="end"?u-p-rr:(u-p)/2;for(let g of h){let b=Vo(g),y=_v(r,l,f+b[0]/2,b[1]/2+gv);a(zh(g),y.x,y.z,y.turn,b),f+=b[0]}}for(let[l,c,d,u]of Th[e].spots){let p=Vo(l),h=(b,y,v)=>Math.min(v,Math.max(y,b)),f=h(r.x0+i*c,r.x0+p[0]/2+rr,r.x1-p[0]/2-rr),g=h(r.z0+o*d,r.z0+p[1]/2+rr,r.z1-p[1]/2-rr);a(zh(l),f,g,u,p)}return s}var bv=30*Math.PI/180,Oh=.05;function il(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 fi(t){return il(t).reduce((e,n)=>e+n,0)}function yv(t,e){let n=il(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&&vv(t,l)>bv)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 ir(t,e){let n=e[0];return n?{from:yv(t,n.edge)+n.offset-n.width/2,width:e.reduce((r,i)=>r+i.width,0)}:null}function Yt(t,e){return e.front?t.filter(n=>n.front===e.front):[e]}function sl(t,e){let n=t.points.length,r=1/0,i=0,o=0;for(let s=0;sI("opening")){let s=ol(e,r,i);if(!s)return null;let a=Yt(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 cl=globalThis,al=cl.__nextfloorBuiltin?.de??{},ll=cl.__nextfloorBuiltin?.en??{};cl.__nextfloorBuiltin??={de:al,en:ll};var wv=()=>typeof $=="object"&&$||{},kv=globalThis,xv=kv.__nextfloorTexts??=new Map;function $v(t){let e=t.toLowerCase().split("-")[0];return e!=="de"&&e!=="en"&&e in wv()?e:void 0}function Hh(t){let e=$v(t),n=e===void 0?void 0:xv.get(e);return n instanceof Promise?void 0:n}function Wo(t,e){return Hh(t)?.[e]}function xe(t,e,n={}){let r=t?.language??navigator.language,i=r.startsWith("de"),o=(i?void 0:Hh(r)?.[e])??(i?al:ll)[e]??ll[e]??al[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 Sv=new Set(["on","home","open","true","active","playing","heat","heating"]);function Lh(t,e){let n=e.show_when;if(!n?.entity||!t)return!0;let r=t.states[n.entity];if(!r||Le(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):Sv.has(i)||Number.isFinite(Number(i))&&Number(i)>0;return n.invert?!s:s}function ze(t,e){if(!vt(e))return xe(t,`furn_${e}`);let n=U(e);return n?Qe(n,e,t?.language??navigator.language):xe(t,"pack_missing_item")}function Qe(t,e,n){return t.name[n.split("-")[0]]??Wo(n,e)??Qc(t,n)}function We(t,e){return Wo(e,`packname:${t.id}`)??ed(t,e)}function Ch(t,e){return t.name[e.split("-")[0]]??Wo(e,`color:${t.id}`)??t.name.en??Object.values(t.name)[0]}var gi=t=>t&&t!=="none"?t:null,_i=(t,e)=>{e&&!t.includes(e)&&t.push(e)},dl=t=>new Map(t.floors.flatMap(e=>e.furniture.filter(n=>n.type==="meter").map(n=>[n.id,n])));function Sn(t,e){if(!t.energy.advanced||e.type!=="meter"||!e.parent_meter)return null;let n=dl(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 or(t){return new Set([...dl(t).values()].filter(e=>Sn(t,e)).map(e=>e.id))}function bi(t,e){return!t.energy.advanced||!e.parent_meter?null:or(t).has(e.parent_meter)?e.parent_meter:null}function Nh(t,e,n){if(n.type!=="meter"||n.id===e.id)return!1;let r=dl(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 jo(t,e=n=>gi(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"?Sn(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??=gi(r.export);else if(r.type==="inverter")_i(n.solar,i);else if(r.type==="home_battery"){let s=gi(r.charge);_i(n.battery,i),_i(n.charge,s),_i(n.soc,gi(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===bi(t,r)):void 0,o=i?e(r):null;i&&r.type==="inverter"&&_i(i.solar,o);let s=gi(r.charge);i&&r.type==="home_battery"&&(o||s)&&i.batteries.push({power:o,charge:s})}return n}function Mv(t){for(let e of t.floors){let n=e.furniture.find(r=>r.type==="meter"&&!Sn(t,r));if(n)return{floor_id:e.id,x:n.x,z:n.z}}return t.energy.meter}var Ev=/(phase|_l[123]\b|_[abc]$|today|daily|heute)/,Rv=/_?(energy|energie|total|today|daily|kwh|import|export|consumption|production)/g;function Ko(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=>!Ev.test(a)),s=e.replace(/^sensor\./,"").replace(Rv,"");return o.find(a=>s&&a.includes(s))??o[0]??i[0]}function Bh(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",Ko(t,i.flow_from?.[0]?.stat_energy_from??i.flow_to?.[0]?.stat_energy_to));else if(i.type==="solar")r("solar",Ko(t,i.stat_energy_from));else if(i.type==="battery"){let o=i.stat_energy_from??i.stat_energy_to;r("battery",Ko(t,o)),r("battery_soc",Ko(t,o,"battery"))}return n}function Pe(t,e=!1){let n=t?.attributes.symcon_id?Wt(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 Av=(t,e)=>e.startsWith("sensor.")&&t.states[e]?.attributes.device_class==="power";function yi(t,e){if(Av(t,e))return e;let n=t.entities?.[e]?.device_id;if(!n)return null;let r=ya(t,n),i=r?Nt(t,e):null,o=So(t,n).filter(s=>s!==e);return(r?o.find(s=>i!==null&&Nt(t,s)===i):o[0])??null}var Vh=t=>{let e=t.filter(n=>n!==null);return e.length?e.reduce((n,r)=>n+r,0):null};function Fv(t,e,n){let r=e.grid??n.grid,i=r?Pe(t.states[r],e.grid_invert):null;if(!e.grid&&n.gridExport){let o=Math.max(0,Pe(t.states[n.gridExport])??0);return Math.max(0,i??0)-o}return i}function Tv(t,e,n){return e.solar?Pe(t.states[e.solar]):n.solar.length?Vh(n.solar.map(r=>Pe(t.states[r]))):null}function ul(t,e,n){return e.charge?(e.power?Math.max(0,Pe(t.states[e.power])??0):0)-Math.max(0,Pe(t.states[e.charge])??0):e.power?Pe(t.states[e.power],n):null}function zv(t,e,n){return e.battery?Pe(t.states[e.battery],e.battery_invert):Vh(n.batteries.map(r=>ul(t,r,e.battery_invert)))}function hl(t,e,n,r=jo(e)){let i=e.energy,o=Fv(t,i,r),s=Tv(t,i,r),a=zv(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?Pe(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,...Pv(t,r,h.consumption,i.battery_invert,n)}:h}function Pv(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?Pe(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,Pe(t.states[w])??0),0),g=p.batteries.reduce((v,w)=>v+(ul(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 Iv(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 Wh(t){let e=Mv(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=ge(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=>Iv(c,e,s)).reduce((c,d)=>d.distance({id:t,name:e,has_valve:!0}),Go=t=>t.has_valve!==!1;function vi(t){let e=t.hydronic??{};return e.stations?.length?e.stations.slice(0,16):[{...pl("station-1"),flow:e.flow,return:e.return,hot_water:e.hot_water,cold_water:e.cold_water,pump:e.pump}]}function Kh(t,e){let n={...t,stations:e};for(let r of["flow","return","hot_water","cold_water","pump"])delete n[r];return n}var Dv=["heating_manifold","buffer_tank","freshwater_station"],sr=t=>Dv.includes(t),fl=(t,e="Heizkreis")=>({id:t,name:e,kind:"heating",has_pump:!0,has_valve:!0});function ml(t){return{card:!0,...t==="heating_manifold"?{circuits:[fl("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 ar(t){return{...ml(t.type),...t.hydronic}}var lr=t=>t.has_pump!==!1,Uo=t=>t.kind!=="pump"&&t.has_valve!==!1;var wi=t=>!!t&&t!=="none";var qo=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Zo(t,e){let n=t.states[qo(t,e)]?.attributes;return n?.device_class==="power"||/^[km]?w$/i.test(String(n?.unit_of_measurement??"").trim())}function jh(t,e){let n=new Map;if(!Z(t))return n;let r=Ae(t,[e]),i=(o,s,a,l,c)=>{if(!wi(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:qo(t,c)}),n.set(d.id,u)};for(let o of e.furniture){if(!Lh(t,o))continue;let s=o.name||ze(t,o.type),a=(o.values??[]).find(d=>wi(d.entity)&&Zo(t,d.entity)),l=r.get(o.id)?.entity,c=o.power==="none"?null:o.power||r.get(o.id)?.power||(l&&Zo(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(!wi(u))continue;let p=yi(t,u);!p||d.has(qo(t,p))||(d.add(qo(t,p)),i(`furniture:${o.id}:${u}`,`${s} \xB7 ${B(t,u)}`,o.x,o.z,p))}}if(sr(o.type))for(let d of ar(o).circuits??[])lr(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 vi(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=>wi(l.entity)&&Zo(t,l.entity)),a=Zo(t,o.entity_id)?o.entity_id:yi(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 At={electricity:"Strom",water:"Wasser",gas:"Gas",heating:"Heizen",cooling:"K\xFChlen"},cr={electricity:"\u26A1",water:"\u{1F4A7}",gas:"\u{1F525}",heating:"\u2668",cooling:"\u2744"},Xo=t=>t.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/ß/g,"ss").replace(/[^a-z0-9]+/g," ").trim(),Ov="{485D0419-BE97-4548-AA9C-C083EB82E61E}",Hv=t=>t.object_type!==0&&!(t.object_type===1&&t.module_id?.toUpperCase()===Ov)?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"}[Xo(t.name)]??null,Yo=t=>/^symcon-category-(\d+)$/.exec(t??"")?.[1],_l=t=>/\b(heute|tag|tagesverbrauch|today|daily)\b/.test(t)?"day":/monat|month/.test(t)?"month":/jahr|year/.test(t)?"year":"total",Jo=(t,e)=>String(t.states[e]?.attributes.symcon_source_entity||e);function Zh(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 Lv(t,e){if(!e.entity_id||e.object_type!==2&&e.object_type!==6)return null;let n=Jo(t,e.entity_id),r=t.states[n];if(!r||![1,2].includes(Number(r.attributes.symcon_variable_type)))return null;let i=Xo(e.name),o=Zh(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"?_l(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 Gh=new WeakMap,Uh=new WeakMap;function qh(t){let e=Gh.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 Gh.set(t,n),n}function Cv(t,e,n){if(!Z(t))return[];let r=[e.area_id,...e.sub_areas??[]].map(Yo).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(Yo).filter(p=>!!p&&!r.includes(p))),o=`${r.join(",")}|${[...i].sort().join(",")}`,s=Uh.get(t)??new Map;Uh.set(t,s);let a=s.get(o);if(a)return a;let l=qh(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=Hv(g),y=b??h,v=new Set(b&&b!==h?[]:f),w=l.children.get(p)??[];if(y){let x=w.map(k=>Lv(t,k)).filter(k=>k!==null);for(let k of new Set(x.map(M=>M.group))){if(v.has(k))continue;let M=x.filter(F=>F.group===k),A=Math.max(...M.map(F=>F.score)),E=M.filter(F=>F.score===A);for(let F of A>=100?E.slice(0,1):E)c.push({kind:y,metric:F.metric,id:F.source,period:F.period});v.add(k)}}for(let x of w)(x.object_type===0||x.object_type===1)&&u(x.object_id,y,v)};for(let p of r)u(Number(p),null,new Set);return s.set(o,c),c}function ki(t,e,n=!1){let r=new Map,i=new Set;for(let o of e){let s=Jo(t,o.id),a=`${o.kind}|${o.metric}|${s}`;if(i.has(a))continue;i.add(a);let l=t.states[s],c=Zh(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=Wt(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 gl(t,e){return wt.flatMap(n=>["power","energy"].flatMap(r=>{let i=e.utility_meters?.[n]?.[r];if(!i||i==="none")return[];let o=Jo(t,i);return[{kind:n,metric:r,id:o,period:r==="energy"?_l(Xo(String(t.states[o]?.attributes.friendly_name??""))):"total"}]}))}function Nv(t,e){return Z(t)?ki(t,gl(t,e),!0):[]}function Bv(t,e,n=e.rooms,r=!1){if(!Z(t))return[];let i=r?jh(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=>!!Yo(c)))];!l.length&&(gl(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=qh(t.symconObjects).nodes;return[...o].map(([a,l])=>{let c=s.get(Number(Yo(a))),d=a==="unassigned"?[]:ki(t,Cv(t,{...l.seed,area_id:a,sub_areas:null},n)),u=ki(t,l.members.flatMap(f=>gl(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:Nv(t,f),devices:(i.get(f.id)??[]).map(g=>({id:g.id,name:g.name,readings:ki(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 bl(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"?Jo(t,o):null}function Yh(t,e,n=e.rooms){let r=Bv(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 wt)for(let s of["power","energy"]){let a=bl(t,e,o,s);i.push(...ki(t,a?[{kind:o,metric:s,id:a,period:s==="energy"?_l(Xo(String(t.states[a]?.attributes.friendly_name??""))):"total"}]:r.filter(l=>l.kind===o&&l.metric===s),!!a))}return i}function yl(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 Xh(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 Jh=[{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 Qh(t,e,n){let r=H(t.hass,i=>Ce(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")} ${wt.map(i=>m`${cr[i]} ${At[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 ep(t,e,n){let r=s=>n({hvac:{...e.hvac,...s}}),i=e.hvac?.schedules??[],o=H(t.hass,s=>!!t.hass?.states[s]?.attributes.symcon_schedule);return m` ${z(t,t.t("floor_heating"),e.floor_heating??null,void 0,H(t.hass,s=>Ce(t.hass,s,[0,1,2])),s=>n({floor_heating:s==="none"?null:s}),{types:[0,1,2]})} ${Jh.map(s=>z(t,s.label,e.hvac?.[s.key]??null,void 0,H(t.hass,a=>Ce(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 tp(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,Yu[i],e.weather_variables?.[i]??null,void 0,H(t.hass,o=>Ce(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,H(t.hass,i=>Ce(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 np(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=H(t.hass,s=>Ce(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 rp(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 ip(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 op(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 sp(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 Qo(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 Xt=(t,e)=>t.filter((n,r)=>r!==e),xi=(t,e,n)=>t.map((r,i)=>i===e?{...r,...n}:r),_t=t=>t.length>0?t:void 0;var Vv=["scene","script","automation","button","input_button","switch","input_boolean","light","fan","cover","lock"],Wv=40,Kv=20,jv=30,Gv=["music","url","playlist","SPOTIFY","AMAZON_MUSIC","TUNEIN","APPLE_MUSIC"],vl={navigate:"/lovelace/rollos",more_info:"cover.wohnzimmer",service:"script.turn_on",fire_dom_event:""},$i=(t,e,n,r=!1)=>m``;function Uv(t){let e=t.doc.settings.favorites??[],n=a=>t.change(l=>l.settings.favorites=_t(a)),r=t.doc.floors,i=t.doc.settings.favorite_floors??{},o=H(t.hass,a=>Vv.includes(a.split(".")[0])&&!e.includes(a)),s=(a,l)=>m`
${B(t.hass,a)} ${r.length>1?m``:_} ${$i(t.t("move_up"),"\u2191",()=>n(Qo(e,l,-1)),l===0)} ${$i(t.t("move_down"),"\u2193",()=>n(Qo(e,l,1)),l===e.length-1)} ${$i(t.t("delete"),"\u2715",()=>n(Xt(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 Zv(t,e){let n=t.doc.settings.outside_hidden??[],r=s=>t.change(a=>a.settings.outside_hidden=_t(s)),i=new Set(t.hass?Eu(t.hass,t.doc.floors):[]),o=H(t.hass,s=>!n.includes(s)&&i.has(s));return m`${e?qv(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)}${$i(t.t("delete"),"\u2715",()=>r(Xt(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 qv(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 Yv(t){let e=t.doc.settings.own_alerts??[],n=s=>t.change(a=>a.settings.own_alerts=_t(s)),r=(s,a)=>n(xi(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,H(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})} ${L(t,t.t("room"),s.room_id??"",i,l=>r(a,{room_id:l||null}),{wide:!0})} ${Ue(t,t.t("own_alert_color"),s.color??null,"#ffb547",l=>r(a,{color:l}))} ${L(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 Xv(t){let e=t.doc.settings.circuits??[],n=a=>t.change(l=>l.settings.circuits=_t(a)),r=(a,l)=>n(xi(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`
${W(t,t.t("circuit_name"),a.name,c=>r(l,{name:c||t.t("circuit_new")}),{wide:!0,maxlength:80})}
${a.rooms.map(c=>m`${o(c)} `)}
${L(t,t.t("circuit_add_room"),"",[["","\u2013"],...i.filter(c=>!a.rooms.includes(c.id)).map(c=>[c.id,c.label])],c=>c&&r(l,{rooms:[...a.rooms,c]}),{wide:!0})}
`;return m`

🔌 ${t.t("circuits")}

${S(t.t("circuits_hint"))} ${e.map(s)} ${e.length<120?Q(m``):_}`}function Jv(t){let e=t.doc.settings.calendars??[],n=a=>t.change(l=>l.settings.calendars=_t(a)),r=H(t.hass,a=>a.startsWith("calendar.")&&!e.includes(a)),i=(a,l)=>m`
${B(t.hass,a)} ${$i(t.t("delete"),"\u2715",()=>n(Xt(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`
${L(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))}
`:_} ${Qv(t)}`}function Qv(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"))}
${L(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?L(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 ew(t){let e=t.doc.settings.media_presets??[],n=s=>t.change(a=>a.settings.media_presets=_t(s)),r=(s,a)=>n(xi(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`
${W(t,t.t("own_button_label"),s.label,l=>r(a,{label:l||"Radio"}),{maxlength:60})} ${W(t,t.t("preset_type"),s.type,l=>r(a,{type:l||"music"}),{title:t.t("preset_type_hint")})} ${W(t,t.t("preset_content"),s.content,l=>r(a,{content:l}),{wide:!0,title:t.t("preset_content_hint"),placeholder:"https://\u2026 \xB7 spotify:playlist:\u2026 \xB7 Rock Antenne"})} ${i.length>1?m`
${t.t("preset_speakers")}
${i.map(l=>D(t,B(t.hass,l),!!s.speakers?.includes(l),c=>r(a,{speakers:_t(c?[...s.speakers??[],l]:(s.speakers??[]).filter(d=>d!==l))}),{wide:!1}))}`:_}
`;return m`

${t.t("presets")}

${S(t.t("presets_hint"))} ${Gv.map(s=>m``)} ${e.map(o)} ${e.lengthn([...e,{id:I("preset"),label:"Radio",type:"music",content:""}])}>+ ${t.t("preset_add")}`):_}`}function wl(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=sp(s.value);if(a.ok)return n(a.value);s.setCustomValidity(t.t("own_data_bad")),s.reportValidity()};return m``}function tw(t){let e=t.doc.settings.buttons??[],n=s=>t.change(a=>a.settings.buttons=_t(s)),r=(s,a)=>n(xi(e,s,a)),i=qi.map(s=>[s,t.t(`own_action_${s}`)]),o=(s,a)=>m`
${W(t,t.t("own_button_label"),s.label,l=>r(a,{label:l||t.t("own_button_new")}),{maxlength:60})} ${L(t,t.t("own_button_action"),s.action,i,l=>r(a,{action:l}))} ${jt(t,s.icon??null,l=>r(a,{icon:l}))} ${s.action!=="fire_dom_event"?W(t,t.t(`own_target_${s.action}`),s.target??"",l=>r(a,{target:l||null}),{wide:!0,placeholder:vl[s.action]}):_} ${s.action==="service"||s.action==="fire_dom_event"?wl(t,s,l=>r(a,{data:l})):_} ${z(t,t.t("own_button_state"),s.state_entity??null,void 0,H(t.hass,l=>/^(switch|light|input_boolean|binary_sensor|fan|cover|media_player|climate|lock|person|device_tracker)\./.test(l)),l=>r(a,{state_entity:l&&l!=="none"?l:null}))}
`;return m`

${t.t("own_buttons")}

${S(t.t("own_buttons_hint"))} ${e.map(o)} ${e.lengthn([...e,{id:I("btn"),label:t.t("own_button_new"),action:"navigate",target:null}])}>+ ${t.t("own_button_add")}`):_}`}function nw(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=_t(i?e.filter(s=>s!==r):[...e,r]))));return m`

${t.t("room_facts")}

${n}
`}function ap(t){return m`
${Uv(t)} ${tw(t)} ${Yv(t)} ${Xv(t)} ${Jv(t)} ${ew(t)} ${nw(t)}
`}function lp(t,e){return m`
🌳 ${t.t("outside_area")} ${Zv(t,e)}
`}function cp(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"))}${op(n)}`:_}
`}function dp(t){if(Z(t.hass))return np(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=H(t.hass,be),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:rp(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,ip(r,l),u=>o(l,{sensor:u}))} ${d?m``:_}`},a=H(t.hass,l=>/^(input_boolean|binary_sensor|device_tracker)\./.test(l)&&!n.includes(l));return m`
${t.t("presence")}
${n.length>0?n.map(s):m`

${t.t("no_persons")}

`}
${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 up(t,e){return Z(t.hass)?m``:m`
${t.t("ble")} ${S(t.t("ble_hint"))}
`}var Si=(t,e)=>{let n=t._$AN;if(n===void 0)return!1;for(let r of n)r._$AO?.(e,!1),Si(r,e);return!0},es=t=>{let e,n;do{if((e=t._$AM)===void 0)break;n=e._$AN,n.delete(t),t=e}while(n?.size===0)},hp=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),ow(e)}};function rw(t){this._$AN!==void 0?(es(this),this._$AM=t,hp(this)):this._$AM=t}function iw(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==Wn.CHILD&&(t._$AP??=iw,t._$AQ??=rw)},ts=class extends Lt{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,n,r){super._$AT(e,n,r),hp(this),this.isConnected=e._$AU}_$AO(e,n=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),n&&(Si(this,e),es(this))}setValue(e){if(Iu(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 kl=new WeakMap,pp=hn(class extends ts{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=kl.get(e);n===void 0&&(n=new WeakMap,kl.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"?kl.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 fp=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 mp(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=fp(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 ns=.05,sw=(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),Mn=t=>new Map(t.map(e=>[e.id,e]));function aw(t,e,n,r){let i=e.name,[o,s]=[Mn(t.rooms),Mn(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}),sw(f.points,h.points)||n.push({kind:"room_reshaped",floor:i,name:h.name,detail:Math.round((we(h.points)-we(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]=[Mn(t.openings),Mn(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]=[Mn(t.furniture),Mn(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)>ns||Math.abs(h.rotation-f.rotation)>1||Math.abs(h.w-f.w)>ns||Math.abs(h.d-f.d)>ns)&&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)>ns&&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 gp(t,e){let n=[],r=Mn(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?aw(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 En=(t,e)=>t.getUint16(e,!0),Mi=(t,e)=>t.getUint32(e,!0);function _p(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(Mi(e,a)===101010256){n=a;break}if(n<0)throw new Error("not_zip");let r=En(e,n+10),i=Mi(e,n+16),o=[],s=new TextDecoder;for(let a=0;a",quot:'"',apos:"'"},cw=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)):lw[n]??e);function dw(t){let e={};for(let n of t.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))e[n[1]]=cw(n[2]??n[3]);return e}function uw(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=dw(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,Ie=t=>Math.round(t*1e3)/1e3;function yp(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 hw(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 pw(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 fw(t){let e=Ot(),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=Re(I("floor"),l.attrs.name||(c===0?"Erdgeschoss":`Etage ${c+1}`),Ie(oe(l.attrs,"elevation",0)/100));p.height=Ie(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:I("room"),name:b.attrs.name||`Raum ${y+1}`,area_id:null,points:pw(b.points,h).map(([v,w])=>[Ie(v),Ie(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 O of f)O.points.forEach((P,N)=>{let V=yp(y,P,O.points[(N+1)%O.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),x=F=>f.some(O=>O.points.some((P,N)=>yp(F,P,O.points[(N+1)%O.points.length]).dist[y[0]+(v[0]-y[0])*F/M,y[1]+(v[1]-y[1])*F/M],E=Array.from({length:M+1},(F,O)=>!x(A(O)));for(let F=0;F<=M;){if(!E[F]){F++;continue}let O=F;for(;O+1<=M&&E[O+1];)O++;let[P,N]=[A(Math.max(0,F-1)),A(Math.min(M,O+1))];Math.hypot(N[0]-P[0],N[1]-P[1])>=.3&&g.push({id:I("wall"),a:[Ie(P[0]),Ie(P[1])],b:[Ie(N[0]),Ie(N[1])],thickness:Ie(oe(b.attrs,"thickness",10)/100),height:b.attrs.height?Ie(oe(b.attrs,"height",250)/100):null}),F=O+1}}p.walls=g,n.rooms+=f.length,n.openings+=p.openings.length,n.walls+=g.length,(f.length||g.length)&&e.floors.push(p)}),n.floors=e.floors.length,n.furniture=t.filter(l=>l.name==="pieceOfFurniture").length,{building:He(e),report:n}}async function vp(t){let e=_p(t).find(i=>i.name==="Home.xml");if(!e)throw new Error("sh3d_no_xml");let n=new TextDecoder().decode(await bp(t,e)),r=fw(uw(n));if(r.report.rooms===0&&r.report.walls===0)throw new Error("sh3d_empty");return r}function mw(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 _w(t){let e=mw(t),n=gw(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 wp=t=>Math.round(t*1e3)/1e3;function kp(t){let{shapes:e,unit:n}=_w(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])=>[wp((h-s)*o),wp((a-f)*o)],c=Re(I("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:I("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:I("wall"),a:f[g],b:f[g+1]})}c.rooms=d,c.walls=u;let p=Ot();return p.floors=[c],{building:He(p),report:{floors:1,rooms:d.length,openings:0,walls:u.length,furniture:0}}}var et=t=>Math.round(t*100)/100;function bw(t,e){let n=t.category;return typeof n=="string"?n:n&&typeof n=="object"?Object.keys(n)[0]??e:e}function yw(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:bw(n,e)}}var dr=(t,e,n)=>(Array.isArray(t[e])?t[e]:[]).map(r=>yw(r,n)).filter(r=>!!r);function vw(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 xp(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 ww(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 kw={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 $p(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)&&dr(r,"walls","wall").length>0)}function Sp(t){let e=t,r=(Array.isArray(e.rooms)?e.rooms:[e]).filter(b=>b&&typeof b=="object").map(b=>({walls:dr(b,"walls","wall"),doors:[...dr(b,"doors","door"),...dr(b,"openings","opening")],windows:dr(b,"windows","window"),objects:dr(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=>vw(b.walls)),a=r.flatMap((b,y)=>s[y]?.points??xp(b.walls)),[l,c]=[Math.min(...a.map(b=>b[0]))-.5,Math.min(...a.map(b=>b[1]))-.5],d=([b,y])=>[et(b-l),et(y-c)],u=Re(I("floor"),"Erdgeschoss",0);u.height=et(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??xp(b.walls)).map(d),x={id:I("room"),name:`Raum ${y+1}`,area_id:null,points:w,floor_material:"wood",panel:[]};p.push(x);for(let k of[...b.doors.map(M=>({v:M,window:!1})),...b.windows.map(M=>({v:M,window:!0}))]){let M=[k.v.centre[0]-l,k.v.centre[2]-c],A=null;if(w.forEach((P,N)=>{let V=ww(M,P,w[(N+1)%w.length]);V.dist<=.6&&(!A||V.dist1.4?2:1,swing:"in",...O?{style:"passage"}:{},cover:null,contact:null,contact2:null,tilt:null})}for(let k of b.objects){let M=kw[k.kind];if(!M)continue;let[A,E,F]=[k.size[0],k.size[2],k.size[1]];A<.1||E<.1||h.push({id:I("f"),type:M,x:et(k.centre[0]-l),z:et(k.centre[2]-c),rotation:Math.round((Math.atan2(k.dir[1],k.dir[0])*180/Math.PI+360)%360),w:et(A),d:et(E),h:et(F),variant:null,entity:null,power:null})}}),u.rooms=p,u.furniture=h;let f=Ot();f.floors=[u];let g=r.reduce((b,y)=>b+y.objects.length,0)-h.length;return{building:He(f),report:{floors:1,rooms:p.length,openings:u.openings.length,walls:0,furniture:g}}}var Ei=t=>typeof t=="object"&&t!==null&&!Array.isArray(t)&&"ref"in t;function xw(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 Sw(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:xw(r[3])});return e}var Mp={x:0,y:0,z:0,c:1,s:0},Ep=(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 Rp(t){let e=Sw(t);if(!e.size)throw new Error("ifc_empty");let n=k=>Ei(k)?e.get(k.ref):void 0,r=k=>typeof k=="number"?k:NaN,i=k=>(n(k)?.args[0]??[]).map(M=>r(M)),o=[...e.values()].find(k=>k.type==="IFCSIUNIT"&&k.args[1]===".LENGTHUNIT."),s=o?{".MILLI.":.001,".CENTI.":.01,".DECI.":.1}[String(o.args[2])]??1:1,a=k=>{let M=n(k);if(!M)return Mp;let[A=0,E=0,F=0]=i(M.args[0]),O=n(M.type==="IFCAXIS2PLACEMENT3D"?M.args[2]:M.args[1]),[P=1,N=0]=(O?.args[0]??[]).map(X=>r(X)),V=Math.hypot(P,N)||1;return{x:A||0,y:E||0,z:F||0,c:P/V,s:N/V}},l=(k,M=0)=>{let A=n(k);return!A||A.type!=="IFCLOCALPLACEMENT"||M>30?Mp:Ep(l(A.args[0],M+1),a(A.args[1]))},c=k=>{for(let M of n(k)?.args[2]??[])for(let A of n(M)?.args[3]??[]){let E=n(A);if(E?.type!=="IFCEXTRUDEDAREASOLID")continue;let F=n(E.args[0]),O=Ep(a(E.args[1]),a(F?.args[2])),P=[];if(F?.type==="IFCRECTANGLEPROFILEDEF"){let[N,V]=[r(F.args[3])/2,r(F.args[4])/2];P=[[-N,-V],[N,-V],[N,V],[-N,V]]}else if(F?.type==="IFCARBITRARYCLOSEDPROFILEDEF"){let N=n(F.args[2]);N?.type==="IFCPOLYLINE"&&(P=(N.args[0]??[]).map(V=>i(V)))}if(P=P.filter(N=>Number.isFinite(N[0])&&Number.isFinite(N[1])),P.length>3&&Math.hypot(P[0][0]-P[P.length-1][0],P[0][1]-P[P.length-1][1])<1e-6&&P.pop(),P.length>=3)return P.map(([N,V])=>[O.x+O.c*N-O.s*V,O.y+O.s*N+O.c*V])}return null},d=new Map;for(let[,k]of e){if(k.type==="IFCRELAGGREGATES"&&Ei(k.args[4]))for(let M of k.args[5]??[])Ei(M)&&d.set(M.ref,k.args[4].ref);if(k.type==="IFCRELCONTAINEDINSPATIALSTRUCTURE"&&Ei(k.args[5]))for(let M of k.args[4]??[])Ei(M)&&d.set(M.ref,k.args[5].ref)}let u=[...e].filter(([,k])=>k.type==="IFCBUILDINGSTOREY").map(([k,M])=>({id:k,name:String(M.args[7]||M.args[2]||"")||null,elevation:r(M.args[9])*s}));u.sort((k,M)=>(k.elevation||0)-(M.elevation||0));let p=[];for(let[k,M]of e){if(M.type!=="IFCSPACE")continue;let A=c(M.args[6]);if(!A)continue;let E=l(M.args[5]),F=A.map(([P,N])=>[(E.x+E.c*P-E.s*N)*s,(E.y+E.s*P+E.c*N)*s]),O=String(M.args[7]||M.args[2]||"")||`Raum ${p.length+1}`;p.push({storey:d.get(k)??null,name:O,ring:F})}if(!p.length)throw new Error("ifc_empty");let h=p.flatMap(k=>k.ring),f=Math.min(...h.map(k=>k[0])),g=Math.max(...h.map(k=>k[1])),b=k=>Math.round(k*1e3)/1e3,y=[],v=new Map;if(u.filter(k=>p.some(M=>M.storey===k.id)).forEach((k,M)=>{let A=Re(I("floor"),k.name??`Etage ${M+1}`,Number.isFinite(k.elevation)?b(k.elevation):M*2.8);y.push(A),v.set(k.id,A)}),p.some(k=>k.storey===null||!v.has(k.storey))){let k=Re(I("floor"),y.length?"Weitere R\xE4ume":"Erdgeschoss",y.length?y[y.length-1].elevation+2.8:0);y.push(k),v.set(null,k)}y.forEach((k,M)=>{let A=y[M+1];A&&A.elevation-k.elevation>1.8&&(k.height=b(A.elevation-k.elevation-.2))});for(let k of p)v.get(k.storey!==null&&v.has(k.storey)?k.storey:null).rooms.push({id:I("room"),name:k.name,area_id:null,points:k.ring.map(([A,E])=>[b(A-f),b(g-E)]),floor_material:"wood",panel:[]});let x=Ot();return x.floors=y,{building:He(x),report:{floors:y.length,rooms:p.length,openings:0,walls:0,furniture:0}}}var Fp="nextfloor",Mw="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",Ap=new RegExp(`^(?:${Mw})\\.[a-z0-9_]+$`),Ew=/^[0-9a-f]{32}$/,Rw=new Set(["area_id","ha_floor"]),Aw=new Set(["sub_areas"]),Fw=new Set(["tap","show_when","pictures","moods"]);function xl(t){if(typeof t=="string")return Ap.test(t)||Ew.test(t)?null:t;if(Array.isArray(t))return t.map(e=>xl(e)).filter(e=>e!==null);if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))Ap.test(n)||Fw.has(n)||(Rw.has(n)||Aw.has(n)?e[n]=null:e[n]=xl(r));return e}return t}var Tw=["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 Tp(t){let e=structuredClone(t),n={};for(let i of Tw)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 xl(e)}function zp(t,e){return{format:Fp,version:1,exported_at:new Date().toISOString(),building:e?Tp(t):structuredClone(t)}}var zw=t=>!!t&&(t.version===1||t.version===void 0)&&Array.isArray(t.floors)&&t.floors.every(e=>!!e&&typeof e=="object"),Pw="https://therealmrbk.github.io/NextFloor/preview/?shared&noshowcase";function Pp(t,e,n,r,i=Pw){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:Tp(t),packs:e.filter(c=>!c.builtin&&o.has(c.id))},a=JSON.stringify(s).replace(/c.replace(/[&<>"]/g,d=>({"&":"&","<":"<",">":">",'"':"""})[d]);return` ${l(n)}