UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

2 lines (1 loc) • 15.6 kB
import{f as Tt}from"./chunk-3APJQTJL.js";import{$c as Lt,Ea as P,Jb as dt,Lb as lt,M as it,Mb as x,Nb as ft,Ob as mt,R as st,Ra as at,Wa as ot,X as nt,Xc as $t,Yc as vt,Zc as Mt,aa as E,ab as ut,ad as yt,bb as ct,d as G,dc as gt,dd as bt,ec as pt,mb as R,nb as j,ta as rt,xb as ht,yb as K}from"./chunk-LTGI3NYM.js";import{a as tt,e as Et,g as It,h as et}from"./chunk-B4AJQJMI.js";var St=Et((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",b="month",J="quarter",S="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,b),a=t-i<0,o=s.clone().add(n+(a?-1:1),b);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:b,y:S,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 S:return a?d(1,0):d(31,11);case b:return a?d(1,T):d(0,T+1);case f:var D=this.$locale().weekStart||0,H=(p<D?p+7:p)-D;return d(a?y-H:y+(6-H),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[b]=o+"Month",i[S]=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===b||a===S){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===b)return this.set(b,this.$M+t);if(o===S)return this.set(S,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,N,Y){return M&&(M[O]||M(n,a))||N[O].slice(0,Y)},H=function(M){return h.s(d%12||12,M,"0")},k=C||function(M,O,N){var Y=M<12?"AM":"PM";return N?Y.toLowerCase():Y};return a.replace(_t,function(M,O){return O||(function(N){switch(N){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 H(1);case"hh":return H(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 S:a=y()/12;break;case b: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(b).$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",b],["$y",S],["$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=It(St(),1);var Rt=["restart-toast-component",""],Ot=(()=>{class $ extends yt{$router=E(Tt);restart(){this.$router.navigate(["/restart"]),this.remove()}dismiss(){this.remove()}static \u0275fac=(()=>{let e;return function(c){return(e||(e=rt($)))(c||$)}})();static \u0275cmp=at({type:$,selectors:[["","restart-toast-component",""]],hostVars:8,hostBindings:function(u,c){u&1&&(ht("mouseenter",function(){return c.stickAround()})("mouseleave",function(){return c.delayedHideToast()}),ct("toast-in")),u&2&&(lt(c.toastClasses()),dt("--animation-easing",c.params.easing)("--animation-duration",c.params.easeTime+"ms")("display",c.displayStyle()))},features:[ot],attrs:Rt,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&&(R(0,"button",0),gt(1,"translate"),K("click",function(){return c.dismiss()}),R(2,"span",1),x(3,"\xD7"),j()(),R(4,"div",2),x(5),j(),R(6,"button",3),K("click",function(){return c.restart()}),x(7),R(8,"span",1),x(9," \u2192"),j()()),u&2&&(ut("aria-label",pt(1,3,"form.button_close")),P(5),ft(c.message()),P(2),mt(" ",c.title()))},dependencies:[Mt],styles:[".toast-in[_nghost-%COMP%]{animation:_ngcontent-%COMP%_toast-animation var(--animation-duration) var(--animation-easing)}.toast-out[_nghost-%COMP%]{animation:_ngcontent-%COMP%_toast-animation var(--animation-duration) var(--animation-easing) reverse forwards}@keyframes _ngcontent-%COMP%_toast-animation{0%{opacity:0}to{opacity:1}}"],changeDetection:0})}return $})();var Jt=(()=>{class ${$api=E(bt);$title=E($t);$toastr=E(Lt);$translate=E(vt);settingsLoadedSubject=new G;defaultTheme="deep-purple";forbiddenKeys=["__proto__","constructor","prototype"];serverTimeToastCleanup$=new G;restartToastRef=null;terminalSettingsChanged=new G;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(it());settingsLoaded=!1;themeList=["orange","red","pink","purple","deep-purple","indigo","blue","blue-grey","cyan","green","teal","grey","brown"];constructor(){this.getAppSettings()}getAppSettings(){return et(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(st(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 tt({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 \u0275fac=function(u){return new(u||$)};static \u0275prov=nt({token:$,factory:$.\u0275fac,providedIn:"root"})}return $})();export{St as a,Jt as b};