You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
6.2 KiB

import{Y as j,S as I,i as E,s as x,C as N,D as W,E as P,F as U,g as R,d as T,W as D,o as A,I as M,X as O}from"./index.f09c780f.js";import{w,d as L}from"./index.faf1c53d.js";function J(r){let c;const u=r[1].default,n=N(u,r,r[0],null);return{c(){n&&n.c()},l(t){n&&n.l(t)},m(t,o){n&&n.m(t,o),c=!0},p(t,[o]){n&&n.p&&(!c||o&1)&&W(n,u,t,t[0],c?U(u,t[0],o,null):P(t[0]),null)},i(t){c||(R(n,t),c=!0)},o(t){T(n,t),c=!1},d(t){n&&n.d(t)}}}const K={ctx:"ModalContext"};function se(){return j(K)}function X(r,c,u){let{$$slots:n={},$$scope:t}=c;return D(K,{modal:w({kind:"closed"})}),r.$$set=o=>{"$$scope"in o&&u(0,t=o.$$scope)},[t,n]}class ne extends I{constructor(c){super(),E(this,c,X,J,x,{})}}async function F(r,c){var o;const u=({}.VITE_LUCIFER4_BACKEND_URL||"")+"/"+r,n=await fetch(u,c);if(n.status!==200)throw(o=n.headers.get("Content-Type"))!=null&&o.includes("application/json")?await n.json():await n.text();return await n.json()}async function Y(){return F("state")}async function ie(r){return F("command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})}function z(r){let c;const u=r[1].default,n=N(u,r,r[0],null);return{c(){n&&n.c()},l(t){n&&n.l(t)},m(t,o){n&&n.m(t,o),c=!0},p(t,[o]){n&&n.p&&(!c||o&1)&&W(n,u,t,t[0],c?U(u,t[0],o,null):P(t[0]),null)},i(t){c||(R(n,t),c=!0)},o(t){T(n,t),c=!1},d(t){n&&n.d(t)}}}const B={ctx:"StateContext"};function G(){return j(B)}function H(r,c,u){let{$$slots:n={},$$scope:t}=c;const o=w({assignments:{},devices:{},scripts:{},triggers:{}}),p=w(null);let g=null;const k=L(o,l=>l==null?[]:Object.keys(l.devices).map(a=>l.devices[a]).sort((a,f)=>a.name.localeCompare(f.name))),$=L(o,l=>Object.keys(l.devices).flatMap(a=>l.devices[a].aliases.filter(f=>["tag","room","role","name"].find(e=>f.startsWith(`lucifer:${e}:`)))).sort().filter((a,f,e)=>e[f-1]!==a)),v=L(o,l=>l==null?[]:Object.keys(l.assignments).map(a=>l.assignments[a]).sort((a,f)=>a.id.localeCompare(f.id))),_=L(o,l=>{const a={},f={};for(const e in l.devices){if(!l.devices.hasOwnProperty(e))continue;const i=l.devices[e].aliases.find(b=>b.startsWith("lucifer:room:")),s=l.devices[e].aliases.find(b=>b.startsWith("lucifer:group:")),d=(i==null?void 0:i.slice(13))||"Unroomed",m=(s==null?void 0:s.slice(14))||"";a[d]||(a[d]=[]),s&&(f[e]=m),a[d].push(l.devices[e])}return Object.keys(a).map(e=>({name:e,devices:a[e].filter(i=>!f[i.id]).sort((i,s)=>i.name.localeCompare(s.name)),groups:a[e].filter(i=>!!f[i.id]).reduce((i,s)=>{const d=i.find(m=>m.name===f[s.id]);return d==null?i.push({name:f[s.id],devices:[s]}):d.devices.push(s),i},[]).map(i=>({...i,devices:i.devices.sort((s,d)=>s.name.localeCompare(d.name))})).sort((i,s)=>i.name.localeCompare(s.name))})).sort((e,i)=>e.name.localeCompare(i.name))});async function C(){p.set(null);try{const l=await Y();o.set(l)}catch(l){p.set(l!=null&&l.toString?l.toString():String(l))}}async function y(){let l=`ws://${window.location.host}/subscribe-simple`;({}).VITE_LUCIFER4_BACKEND_URL!=null&&(l={}.VITE_LUCIFER4_BACKEND_URL.replace("http","ws")+"/subscribe-simple");const a=new WebSocket(l);a.onmessage=f=>{const e=JSON.parse(f.data);o.update(i=>{e.full!=null&&(i=e.full);for(const s in e.devices)e.devices.hasOwnProperty(s)&&(i.devices={...i.devices},e.devices[s]!==null?i.devices[s]=e.devices[s]:delete i.devices[s]);for(const s in e.assignments)e.assignments.hasOwnProperty(s)&&(i.assignments={...i.assignments},e.assignments[s]!=null?i.assignments[s]=e.assignments[s]:delete i.assignments[s]);for(const s in e.scripts)e.scripts.hasOwnProperty(s)&&(i.scripts={...i.scripts},e.scripts[s]!=null?i.scripts[s]=e.scripts[s]:delete i.scripts[s]);for(const s in e.triggers)e.triggers.hasOwnProperty(s)&&(i.triggers={...i.triggers},e.triggers[s]!=null?i.triggers[s]=e.triggers[s]:delete i.triggers[s]);return i})},a.onopen=()=>{g!==null&&g.close(),g=a},a.onerror=f=>{console.warn("Socket failed:",f),a.close(),setTimeout(()=>y(),3e3)},a.onclose=()=>{a===g&&(g=null)}}return A(()=>{y(),window.addEventListener("visibilitychange",()=>{document.visibilityState=="visible"?(console.log("Reconnecting"),y()):g!=null&&(console.log("Disconnecting"),g.close())})}),D(B,{reload:C,error:{subscribe:p.subscribe},state:{subscribe:o.subscribe},deviceList:k,assignmentList:v,roomList:_,maskList:$}),r.$$set=l=>{"$$scope"in l&&u(0,t=l.$$scope)},[t,n]}class oe extends I{constructor(c){super(),E(this,c,H,z,x,{})}}function Q(r){let c;const u=r[10].default,n=N(u,r,r[9],null);return{c(){n&&n.c()},l(t){n&&n.l(t)},m(t,o){n&&n.m(t,o),c=!0},p(t,[o]){n&&n.p&&(!c||o&512)&&W(n,u,t,t[9],c?U(u,t[9],o,null):P(t[9]),null)},i(t){c||(R(n,t),c=!0)},o(t){T(n,t),c=!1},d(t){n&&n.d(t)}}}const V={ctx:"SelectContext"};function ce(){return j(V)}function Z(r,c,u){let n,t,o,p,g,{$$slots:k={},$$scope:$}=c;const v=w([]);M(r,v,e=>u(6,o=e));const _=w({});M(r,_,e=>u(7,p=e));const C=w([]);M(r,C,e=>u(11,n=e));const{state:y,deviceList:l}=G();M(r,y,e=>u(5,t=e)),M(r,l,e=>u(8,g=e));function a(e){_.update(i=>({...i,[e]:!i[e]}))}function f(e){_.update(i=>e.find(s=>!i[s])?e.reduce((s,d)=>({...s,[d]:!0}),i):e.reduce((s,d)=>({...s,[d]:!1}),i))}return D(V,{selectedList:{subscribe:v.subscribe},selectedMap:{subscribe:_.subscribe},selectedMasks:{subscribe:C.subscribe},toggleSelection:a,toggleMultiSelection:f}),r.$$set=e=>{"$$scope"in e&&u(9,$=e.$$scope)},r.$$.update=()=>{if(r.$$.dirty&160){const e={...p};for(const i in e)Object.hasOwn(e,i)&&(t!=null&&t.devices[i]||delete e[i]);O(_,p=e,p)}if(r.$$.dirty&128&&O(v,o=Object.keys(p).filter(e=>!!p[e]),o),r.$$.dirty&480){const e=g.find(s=>p[s.id]),i=[];if(e!=null){for(const m of e.aliases){if(m.startsWith("lucifer:name")||m.startsWith("lucifer:icon:"))continue;let b=!0;for(const S of g){const h=p[S.id]||!1,q=S.aliases.includes(m);if(h!==q){b=!1;break}}b&&i.push(m)}let s=e.id,d=e.name;for(const m of g){if(!p[m.id])continue;let b=0;for(let h=1;h<=s.length;++h)m.id.startsWith(s.slice(0,h))&&(b=h);let S=0;for(let h=1;h<=d.length;++h)m.name.startsWith(d.slice(0,h))&&(S=h);s=s.substring(0,b),d=d.substring(0,S)}i.push(`${s}{${o.map(m=>m.substring(s.length)).sort().join(",")}}`),i.push(`lucifer:name:${d}{${o.map(m=>t.devices[m].name).map(m=>m.substring(d.length)).sort().join(",")}}`)}O(C,n=i.map(s=>s.endsWith("{}")?s.slice(0,-2):s),n)}},[v,_,C,y,l,t,o,p,g,$,k]}class re extends I{constructor(c){super(),E(this,c,Z,Q,x,{})}}export{ne as M,oe as S,re as a,se as b,G as c,ce as g,ie as r};