homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge.
1 lines • 15.6 kB
JavaScript
import{a as E,i as D,n as B,o as w}from"./chunk-D39XL-zh.js";import{Fr as se,Ir as so,Kr as v3,Nt as Sn,Or as rc,Tn as ac,Un as g,Vt as U3,X as Jt,Y as Je,ai as xi,cn as Xt,dt as Nf,en as W0,gt as Pe,hr as nc,in as X8,jt as S_,mt as P,pt as Ot$1,sr as kt,ui as z0,ur as mE,ut as N_,v as C,vt as Py,x as Cr,zt as Ts}from"./chunk-D96TCRAL.js";import{l as le}from"./chunk-DZYp0NQB.js";var bt=B((V,Z)=>{"use strict";(function($,w){typeof V==`object`&&typeof Z<`u`?Z.exports=w():typeof define==`function`&&define.amd?define(w):($=typeof globalThis<`u`?globalThis:$||self).dayjs=w()})(V,(function(){"use strict";var $=1e3,w=6e4,e=36e5,u=`millisecond`,c=`second`,l=`minute`,v=`hour`,L=`day`,f=`week`,S=`month`,J=`quarter`,b=`year`,I=`date`,q=`Invalid Date`,wt=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,_t=/\[([^\]]+)]|YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,Dt={name:`en`,weekdays:`Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday`.split(`_`),months:`January_February_March_April_May_June_July_August_September_October_November_December`.split(`_`),ordinal:function(r){var s=[`th`,`st`,`nd`,`rd`],t=r%100;return`[`+r+(s[(t-20)%10]||s[t]||s[0])+`]`}},B=function(r,s,t){var n=String(r);return!n||n.length>=s?r:``+Array(s+1-n.length).join(t)+r},kt={s:B,z:function(r){var s=-r.utcOffset(),t=Math.abs(s),n=Math.floor(t/60),i=t%60;return(s<=0?`+`:`-`)+B(n,2,`0`)+`:`+B(i,2,`0`)},m:function r(s,t){if(s.date()<t.date())return-r(t,s);var n=12*(t.year()-s.year())+(t.month()-s.month()),i=s.clone().add(n,S),a=t-i<0,o=s.clone().add(n+(a?-1:1),S);return+(-(n+(t-i)/(a?i-o:o-i))||0)},a:function(r){return r<0?Math.ceil(r)||0:Math.floor(r)},p:function(r){return{M:S,y:b,w:f,d:L,D:I,h:v,m:l,s:c,ms:u,Q:J}[r]||String(r||``).toLowerCase().replace(/s$/,``)},u:function(r){return r===void 0}},A=`en`,_={};_[A]=Dt;var Q=`$isDayjsObject`,W=function(r){return r instanceof U||!(!r||!r[Q])},F=function r(s,t,n){var i;if(!s)return A;if(typeof s==`string`){var a=s.toLowerCase();_[a]&&(i=a),t&&(_[a]=t,i=a);var o=s.split(`-`);if(!i&&o.length>1)return r(o[0])}else{var d=s.name;_[d]=s,i=d}return!n&&i&&(A=i),i||!n&&A},g=function(r,s){if(W(r))return r.clone();var t=typeof s==`object`?s:{};return t.date=r,t.args=arguments,new U(t)},h=kt;h.l=F,h.i=W,h.w=function(r,s){return g(r,{locale:s.$L,utc:s.$u,x:s.$x,$offset:s.$offset})};var U=(function(){function r(t){this.$L=F(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[Q]=!0}var s=r.prototype;return s.parse=function(t){this.$d=(function(n){var i=n.date,a=n.utc;if(i===null)return new Date(NaN);if(h.u(i))return new Date;if(i instanceof Date)return new Date(i);if(typeof i==`string`&&!/Z$/i.test(i)){var o=i.match(wt);if(o){var d=o[2]-1||0,m=(o[7]||`0`).substring(0,3);return a?new Date(Date.UTC(o[1],d,o[3]||1,o[4]||0,o[5]||0,o[6]||0,m)):new Date(o[1],d,o[3]||1,o[4]||0,o[5]||0,o[6]||0,m)}}return new Date(i)})(t),this.init()},s.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},s.$utils=function(){return h},s.isValid=function(){return this.$d.toString()!==q},s.isSame=function(t,n){var i=g(t);return this.startOf(n)<=i&&i<=this.endOf(n)},s.isAfter=function(t,n){return g(t)<this.startOf(n)},s.isBefore=function(t,n){return this.endOf(n)<g(t)},s.$g=function(t,n,i){return h.u(t)?this[n]:this.set(i,t)},s.unix=function(){return Math.floor(this.valueOf()/1e3)},s.valueOf=function(){return this.$d.getTime()},s.startOf=function(t,n){var i=this,a=!!h.u(n)||n,o=h.p(t),d=function(k,M){var O=h.w(i.$u?Date.UTC(i.$y,M,k):new Date(i.$y,M,k),i);return a?O:O.endOf(L)},m=function(k,M){return h.w(i.toDate()[k].apply(i.toDate(`s`),(a?[0,0,0,0]:[23,59,59,999]).slice(M)),i)},p=this.$W,T=this.$M,y=this.$D,C=`set`+(this.$u?`UTC`:``);switch(o){case b:return a?d(1,0):d(31,11);case S:return a?d(1,T):d(0,T+1);case f:var D=this.$locale().weekStart||0,N=(p<D?p+7:p)-D;return d(a?y-N:y+(6-N),T);case L:case I:return m(C+`Hours`,0);case v:return m(C+`Minutes`,1);case l:return m(C+`Seconds`,2);case c:return m(C+`Milliseconds`,3);default:return this.clone()}},s.endOf=function(t){return this.startOf(t,!1)},s.$set=function(t,n){var i,a=h.p(t),o=`set`+(this.$u?`UTC`:``),d=(i={},i[L]=o+`Date`,i[I]=o+`Date`,i[S]=o+`Month`,i[b]=o+`FullYear`,i[v]=o+`Hours`,i[l]=o+`Minutes`,i[c]=o+`Seconds`,i[u]=o+`Milliseconds`,i)[a],m=a===L?this.$D+(n-this.$W):n;if(a===S||a===b){var p=this.clone().set(I,1);p.$d[d](m),p.init(),this.$d=p.set(I,Math.min(this.$D,p.daysInMonth())).$d}else d&&this.$d[d](m);return this.init(),this},s.set=function(t,n){return this.clone().$set(t,n)},s.get=function(t){return this[h.p(t)]()},s.add=function(t,n){var i,a=this;t=Number(t);var o=h.p(n),d=function(T){var y=g(a);return h.w(y.date(y.date()+Math.round(T*t)),a)};if(o===S)return this.set(S,this.$M+t);if(o===b)return this.set(b,this.$y+t);if(o===L)return d(1);if(o===f)return d(7);var m=(i={},i[l]=w,i[v]=e,i[c]=$,i)[o]||1,p=this.$d.getTime()+t*m;return h.w(p,this)},s.subtract=function(t,n){return this.add(-1*t,n)},s.format=function(t){var n=this,i=this.$locale();if(!this.isValid())return i.invalidDate||q;var a=t||`YYYY-MM-DDTHH:mm:ssZ`,o=h.z(this),d=this.$H,m=this.$m,p=this.$M,T=i.weekdays,y=i.months,C=i.meridiem,D=function(M,O,H,Y){return M&&(M[O]||M(n,a))||H[O].slice(0,Y)},N=function(M){return h.s(d%12||12,M,`0`)},k=C||function(M,O,H){var Y=M<12?`AM`:`PM`;return H?Y.toLowerCase():Y};return a.replace(_t,(function(M,O){return O||(function(H){switch(H){case`YY`:return String(n.$y).slice(-2);case`YYYY`:return h.s(n.$y,4,`0`);case`M`:return p+1;case`MM`:return h.s(p+1,2,`0`);case`MMM`:return D(i.monthsShort,p,y,3);case`MMMM`:return D(y,p);case`D`:return n.$D;case`DD`:return h.s(n.$D,2,`0`);case`d`:return String(n.$W);case`dd`:return D(i.weekdaysMin,n.$W,T,2);case`ddd`:return D(i.weekdaysShort,n.$W,T,3);case`dddd`:return T[n.$W];case`H`:return String(d);case`HH`:return h.s(d,2,`0`);case`h`:return N(1);case`hh`:return N(2);case`a`:return k(d,m,!0);case`A`:return k(d,m,!1);case`m`:return String(m);case`mm`:return h.s(m,2,`0`);case`s`:return String(n.$s);case`ss`:return h.s(n.$s,2,`0`);case`SSS`:return h.s(n.$ms,3,`0`);case`Z`:return o}return null})(M)||o.replace(`:`,``)}))},s.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},s.diff=function(t,n,i){var a,o=this,d=h.p(n),m=g(t),p=(m.utcOffset()-this.utcOffset())*w,T=this-m,y=function(){return h.m(o,m)};switch(d){case b:a=y()/12;break;case S:a=y();break;case J:a=y()/3;break;case f:a=(T-p)/6048e5;break;case L:a=(T-p)/864e5;break;case v:a=T/e;break;case l:a=T/w;break;case c:a=T/$;break;default:a=T}return i?a:h.a(a)},s.daysInMonth=function(){return this.endOf(S).$D},s.$locale=function(){return _[this.$L]},s.locale=function(t,n){if(!t)return this.$L;var i=this.clone(),a=F(t,n,!0);return a&&(i.$L=a),i},s.clone=function(){return h.w(this.$d,this)},s.toDate=function(){return new Date(this.valueOf())},s.toJSON=function(){return this.isValid()?this.toISOString():null},s.toISOString=function(){return this.$d.toISOString()},s.toString=function(){return this.$d.toUTCString()},r})(),X=U.prototype;return g.prototype=X,[[`$ms`,u],[`$s`,c],[`$m`,l],[`$H`,v],[`$W`,L],[`$M`,S],[`$y`,b],[`$D`,I]].forEach((function(r){X[r[1]]=function(s){return this.$g(s,r[0],r[1])}})),g.extend=function(r,s){return r.$i||(r(s,U,g),r.$i=!0),g},g.locale=F,g.isDayjs=W,g.unix=function(r){return g(1e3*r)},g.en=_[A],g.Ls=_,g.p={},g}))});var z=D(bt(),1);var Ot=(()=>{class $ extends W0{$router=g(le);restart(){this.$router.navigate([`/restart`]),this.remove()}dismiss(){this.remove()}static ɵfac=(()=>{let e;return function(c){return(e||(e=Sn($)))(c||$)}})();static ɵcmp=nc({type:$,selectors:[[``,`restart-toast-component`,``]],hostVars:8,hostBindings:function(u,c){u&1&&(ac(`mouseenter`,function(){return c.stickAround()})(`mouseleave`,function(){return c.delayedHideToast()}),so(`toast-in`)),u&2&&(Jt(c.toastClasses()),Xt(`--%NS%animation-easing`,c.params.easing)(`--%NS%animation-duration`,c.params.easeTime+`ms`)(`display`,c.displayStyle()))},features:[rc],decls:10,vars:5,consts:[[`type`,`button`,1,`toast-close-button`,3,`click`],[`aria-hidden`,`true`],[`role`,`alert`,1,`toast-message`],[`type`,`button`,1,`hb-restart-toast-action`,3,`click`]],template:function(u,c){u&1&&(Pe(0,`button`,0),S_(1,`translate`),xi(`click`,function(){return c.dismiss()}),Pe(2,`span`,1),Ot$1(3,`×`),Je()(),Pe(4,`div`,2),Ot$1(5),Je(),Pe(6,`button`,3),xi(`click`,function(){return c.restart()}),Ot$1(7),Pe(8,`span`,1),Ot$1(9,` →`),Je()()),u&2&&(Cr(`aria-label`,N_(1,3,`form.button_close`)),se(5),Py(c.message()),se(2),kt(` `,c.title()))},dependencies:[v3],styles:[`.toast-in[_nghost-%COMP%]{animation:_ngcontent-%COMP%_toast-animation var(--%NS%animation-duration) var(--%NS%animation-easing)}.toast-out[_nghost-%COMP%]{animation:_ngcontent-%COMP%_toast-animation var(--%NS%animation-duration) var(--%NS%animation-easing) reverse forwards} _ngcontent-%COMP%_toast-animation{0%{opacity:0}to{opacity:1}}`]})}return $})();var zt=(()=>{class ${$api=g(U3);$title=g(X8);$toastr=g(z0);$translate=g(Nf);settingsLoadedSubject=new P;defaultTheme=`deep-purple`;forbiddenKeys=[`__proto__`,`constructor`,`prototype`];serverTimeToastCleanup$=new P;restartToastRef=null;terminalSettingsChanged=new P;env={};host;proxyHost;formAuth=!0;sessionTimeout=28800;sessionTimeoutInactivityBased=!1;uiVersion;theme;lightingMode;currentLightingMode;actualLightingMode;browserLightingMode;menuMode;keepOrphans;wallpaper;serverTimeOffset=0;rtl=!1;browserLang;onSettingsLoaded=this.settingsLoadedSubject.pipe(mE());settingsLoaded=!1;themeList=[`orange`,`red`,`pink`,`purple`,`deep-purple`,`indigo`,`blue`,`blue-grey`,`cyan`,`green`,`teal`,`grey`,`brown`];constructor(){this.getAppSettings()}getAppSettings(){return E(this,null,function*(){let e=yield this.$api.get(`/auth/settings`);this.formAuth=e.formAuth,this.sessionTimeout=e.sessionTimeout,this.sessionTimeoutInactivityBased=e.sessionTimeoutInactivityBased,this.env=e.env,this.host=e.host,this.proxyHost=e.proxyHost,this.lightingMode=e.lightingMode,this.wallpaper=e.wallpaper,this.setLightingMode(this.lightingMode,`user`),this.setTheme(e.theme),this.setMenuMode(e.menuMode),this.setKeepOrphans(e.keepOrphans),this.setTitle(this.env.homebridgeInstanceName),this.checkServerTime(e.serverTimestamp),this.setUiVersion(e.env.packageVersion),this.setLang(this.env.lang),this.settingsLoaded=!0,this.settingsLoadedSubject.next(void 0),this.browserLang=this.$translate.getBrowserCultureLang()})}setBrowserLightingMode(e){this.browserLightingMode=e,this.lightingMode===`auto`&&this.setLightingMode(e,`browser`)}setLightingMode(e,u){u===`user`&&(this.lightingMode=e),this.currentLightingMode=e,this.actualLightingMode=this.currentLightingMode===`auto`?this.browserLightingMode:this.currentLightingMode,this.theme&&this.setTheme(this.theme)}setTheme(e){(!e||!this.themeList.includes(e))&&(e=this.defaultTheme,this.$api.patch(`/config-editor/ui`,{theme:e}).catch(l=>console.error(`Error saving setTheme:`,l)));let u=window.document.querySelector(`body`);u.classList.remove(`config-ui-x-${this.theme}`),u.classList.remove(`config-ui-x-dark-mode-${this.theme}`),this.theme=e,this.actualLightingMode===`dark`?(u.classList.add(`config-ui-x-dark-mode-${this.theme}`),u.classList.contains(`dark-mode`)||u.classList.add(`dark-mode`)):(u.classList.add(`config-ui-x-${this.theme}`),u.classList.contains(`dark-mode`)&&u.classList.remove(`dark-mode`)),window.document.querySelectorAll(`iframe`).forEach((l,v)=>{try{let L=l.contentDocument;if(L){let f=L.body;this.actualLightingMode===`dark`?(f.classList.contains(`config-ui-x-${this.theme}`)&&f.classList.remove(`config-ui-x-${this.theme}`),f.classList.contains(`config-ui-x-dark-mode-${this.theme}`)||f.classList.add(`config-ui-x-dark-mode-${this.theme}`),f.classList.contains(`dark-mode`)||f.classList.add(`dark-mode`),f.style.backgroundColor=`#242424 !important`,f.style.color=`#ffffff !important`):(f.classList.contains(`config-ui-x-${this.theme}`)||f.classList.add(`config-ui-x-${this.theme}`),f.classList.contains(`config-ui-x-dark-mode-${this.theme}`)&&f.classList.remove(`config-ui-x-dark-mode-${this.theme}`),f.classList.contains(`dark-mode`)&&f.classList.remove(`dark-mode`),f.style.backgroundColor=`#ffffff !important`,f.style.color=`#000000 !important`),l.contentWindow?.postMessage({type:`theme-update`,isDark:this.actualLightingMode===`dark`,theme:e},`*`)}}catch(L){console.warn(`Iframe ${v}: Access denied (cross-origin?)`,{error:L,src:l.src})}})}setMenuMode(e){this.menuMode=e}setKeepOrphans(e){this.keepOrphans=e}setLang(e){if(e){this.$translate.use(e);try{window.localStorage.setItem(`uix.lang`,e)}catch(u){}}else{e=`auto`;try{window.localStorage.removeItem(`uix.lang`)}catch(u){}}this.env.lang=e}setItem(e,u){this.forbiddenKeys.includes(e)||(this[e]=u)}setEnvItem(e,u){if(e.includes(`.`)){let c=e.split(`.`),l=this.env;for(let v=0;v<c.length-1;v+=1){if(this.forbiddenKeys.includes(c[v]))return;l[c[v]]||(l[c[v]]={}),l=l[c[v]]}this.forbiddenKeys.includes(c.at(-1))||(l[c.at(-1)]=u)}else this.env[e]=u}checkServerTime(e){let c=(0,z.default)(e).diff((0,z.default)(),`hour`);this.serverTimeOffset=c*60*60,(c>=8||c<=-8)&&(this.serverTimeToastCleanup$.next(),this.$toastr.warning(this.$translate.instant(`settings.datetime.incorrect`),this.$translate.instant(`toast.title_warning`),{timeOut:2e4,tapToDismiss:!1}).onTap.pipe(Ts(this.serverTimeToastCleanup$)).subscribe(()=>{window.open(`https://homebridge.io/w/JqTFs`,`_blank`)}))}setUiVersion(e){this.uiVersion||(this.uiVersion=e)}setTitle(e){this.$title.setTitle(e||`Homebridge`)}setPageTitle(e){let u=this.env.homebridgeInstanceName||`Homebridge`;e?this.$title.setTitle(`${u} \u2014 ${e}`):this.$title.setTitle(u)}isFeatureEnabled(e){return this.env.featureFlags?.[e]??!1}showRestartToast(){this.restartToastRef||(this.restartToastRef=this.$toastr.info(this.$translate.instant(`settings.changes.saved`),this.$translate.instant(`menu.hbrestart.title`),{toastComponent:Ot,toastClass:`ngx-toastr hb-restart-toast`,timeOut:0,tapToDismiss:!1,disableTimeOut:!0,positionClass:`toast-bottom-right`}),this.restartToastRef.onHidden?.subscribe(()=>{this.restartToastRef=null}))}TERMINAL_DEFAULTS={FONT_SIZE:13,FONT_WEIGHT:`400`,LINE_HEIGHT:1.2};TERMINAL_COLORS={DARK:{FULL_PAGE:`#000000`,WIDGET:`#2b2b2b`},LIGHT:{BACKGROUND:`#00000000`,FOREGROUND:`#2b2b2b`,CURSOR:`#d2d2d2`,SELECTION:`#d2d2d2`}};getEffectiveTerminalLightingMode(){return this.actualLightingMode===`dark`?`dark`:this.env.terminal?.lightingMode||`dark`}getTerminalThemeOptions(e=!1){return this.getEffectiveTerminalLightingMode()===`light`?{theme:{background:this.TERMINAL_COLORS.LIGHT.BACKGROUND,foreground:this.TERMINAL_COLORS.LIGHT.FOREGROUND,cursor:this.TERMINAL_COLORS.LIGHT.CURSOR,selectionBackground:this.TERMINAL_COLORS.LIGHT.SELECTION},allowTransparency:!0}:{theme:{background:e?this.TERMINAL_COLORS.DARK.WIDGET:this.TERMINAL_COLORS.DARK.FULL_PAGE},allowTransparency:!1}}getTerminalOptions(e,u=!1){let c=this.getTerminalThemeOptions(u);return w({fontSize:this.env.terminal?.fontSize||this.TERMINAL_DEFAULTS.FONT_SIZE,fontWeight:this.env.terminal?.fontWeight||this.TERMINAL_DEFAULTS.FONT_WEIGHT,lineHeight:this.TERMINAL_DEFAULTS.LINE_HEIGHT,allowProposedApi:!0,theme:c.theme,allowTransparency:c.allowTransparency,screenReaderMode:!0},e)}static ɵfac=function(u){return new(u||$)};static ɵprov=C({token:$,factory:$.ɵfac,providedIn:`root`})}return $})();export{zt as n,bt as t};