UNPKG

homebridge-config-ui-x

Version:

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

2 lines (1 loc) • 13.3 kB
import{A as tt,C as et,F as it,I as st}from"./chunk-QCMOCU6Q.js";import{L as q,R as Q,X,aa as H,d as U}from"./chunk-ZMC752RO.js";import{a as J,e as ct,g as ht,h as P}from"./chunk-B4AJQJMI.js";var nt=ct((j,Y)=>{"use strict";(function(y,O){typeof j=="object"&&typeof Y<"u"?Y.exports=O():typeof define=="function"&&define.amd?define(O):(y=typeof globalThis<"u"?globalThis:y||self).dayjs=O()})(j,function(){"use strict";var y=1e3,O=6e4,s=36e5,u="millisecond",d="second",m="minute",L="hour",M="day",f="week",S="month",K="quarter",b="year",_="date",V="Invalid Date",rt=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,at=/\[([^\]]+)]|Y{1,4}|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,ot={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 i=["th","st","nd","rd"],t=r%100;return"["+r+(i[(t-20)%10]||i[t]||i[0])+"]"}},G=function(r,i,t){var n=String(r);return!n||n.length>=i?r:""+Array(i+1-n.length).join(t)+r},ut={s:G,z:function(r){var i=-r.utcOffset(),t=Math.abs(i),n=Math.floor(t/60),e=t%60;return(i<=0?"+":"-")+G(n,2,"0")+":"+G(e,2,"0")},m:function r(i,t){if(i.date()<t.date())return-r(t,i);var n=12*(t.year()-i.year())+(t.month()-i.month()),e=i.clone().add(n,S),a=t-e<0,o=i.clone().add(n+(a?-1:1),S);return+(-(n+(t-e)/(a?e-o:o-e))||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:M,D:_,h:L,m,s:d,ms:u,Q:K}[r]||String(r||"").toLowerCase().replace(/s$/,"")},u:function(r){return r===void 0}},A="en",D={};D[A]=ot;var Z="$isDayjsObject",W=function(r){return r instanceof x||!(!r||!r[Z])},C=function r(i,t,n){var e;if(!i)return A;if(typeof i=="string"){var a=i.toLowerCase();D[a]&&(e=a),t&&(D[a]=t,e=a);var o=i.split("-");if(!e&&o.length>1)return r(o[0])}else{var h=i.name;D[h]=i,e=h}return!n&&e&&(A=e),e||!n&&A},g=function(r,i){if(W(r))return r.clone();var t=typeof i=="object"?i:{};return t.date=r,t.args=arguments,new x(t)},c=ut;c.l=C,c.i=W,c.w=function(r,i){return g(r,{locale:i.$L,utc:i.$u,x:i.$x,$offset:i.$offset})};var x=(function(){function r(t){this.$L=C(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[Z]=!0}var i=r.prototype;return i.parse=function(t){this.$d=(function(n){var e=n.date,a=n.utc;if(e===null)return new Date(NaN);if(c.u(e))return new Date;if(e instanceof Date)return new Date(e);if(typeof e=="string"&&!/Z$/i.test(e)){var o=e.match(rt);if(o){var h=o[2]-1||0,l=(o[7]||"0").substring(0,3);return a?new Date(Date.UTC(o[1],h,o[3]||1,o[4]||0,o[5]||0,o[6]||0,l)):new Date(o[1],h,o[3]||1,o[4]||0,o[5]||0,o[6]||0,l)}}return new Date(e)})(t),this.init()},i.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()},i.$utils=function(){return c},i.isValid=function(){return this.$d.toString()!==V},i.isSame=function(t,n){var e=g(t);return this.startOf(n)<=e&&e<=this.endOf(n)},i.isAfter=function(t,n){return g(t)<this.startOf(n)},i.isBefore=function(t,n){return this.endOf(n)<g(t)},i.$g=function(t,n,e){return c.u(t)?this[n]:this.set(e,t)},i.unix=function(){return Math.floor(this.valueOf()/1e3)},i.valueOf=function(){return this.$d.getTime()},i.startOf=function(t,n){var e=this,a=!!c.u(n)||n,o=c.p(t),h=function(I,T){var w=c.w(e.$u?Date.UTC(e.$y,T,I):new Date(e.$y,T,I),e);return a?w:w.endOf(M)},l=function(I,T){return c.w(e.toDate()[I].apply(e.toDate("s"),(a?[0,0,0,0]:[23,59,59,999]).slice(T)),e)},$=this.$W,p=this.$M,v=this.$D,E="set"+(this.$u?"UTC":"");switch(o){case b:return a?h(1,0):h(31,11);case S:return a?h(1,p):h(0,p+1);case f:var k=this.$locale().weekStart||0,R=($<k?$+7:$)-k;return h(a?v-R:v+(6-R),p);case M:case _:return l(E+"Hours",0);case L:return l(E+"Minutes",1);case m:return l(E+"Seconds",2);case d:return l(E+"Milliseconds",3);default:return this.clone()}},i.endOf=function(t){return this.startOf(t,!1)},i.$set=function(t,n){var e,a=c.p(t),o="set"+(this.$u?"UTC":""),h=(e={},e[M]=o+"Date",e[_]=o+"Date",e[S]=o+"Month",e[b]=o+"FullYear",e[L]=o+"Hours",e[m]=o+"Minutes",e[d]=o+"Seconds",e[u]=o+"Milliseconds",e)[a],l=a===M?this.$D+(n-this.$W):n;if(a===S||a===b){var $=this.clone().set(_,1);$.$d[h](l),$.init(),this.$d=$.set(_,Math.min(this.$D,$.daysInMonth())).$d}else h&&this.$d[h](l);return this.init(),this},i.set=function(t,n){return this.clone().$set(t,n)},i.get=function(t){return this[c.p(t)]()},i.add=function(t,n){var e,a=this;t=Number(t);var o=c.p(n),h=function(p){var v=g(a);return c.w(v.date(v.date()+Math.round(p*t)),a)};if(o===S)return this.set(S,this.$M+t);if(o===b)return this.set(b,this.$y+t);if(o===M)return h(1);if(o===f)return h(7);var l=(e={},e[m]=O,e[L]=s,e[d]=y,e)[o]||1,$=this.$d.getTime()+t*l;return c.w($,this)},i.subtract=function(t,n){return this.add(-1*t,n)},i.format=function(t){var n=this,e=this.$locale();if(!this.isValid())return e.invalidDate||V;var a=t||"YYYY-MM-DDTHH:mm:ssZ",o=c.z(this),h=this.$H,l=this.$m,$=this.$M,p=e.weekdays,v=e.months,E=e.meridiem,k=function(T,w,N,F){return T&&(T[w]||T(n,a))||N[w].slice(0,F)},R=function(T){return c.s(h%12||12,T,"0")},I=E||function(T,w,N){var F=T<12?"AM":"PM";return N?F.toLowerCase():F};return a.replace(at,function(T,w){return w||(function(N){switch(N){case"YY":return String(n.$y).slice(-2);case"YYYY":return c.s(n.$y,4,"0");case"M":return $+1;case"MM":return c.s($+1,2,"0");case"MMM":return k(e.monthsShort,$,v,3);case"MMMM":return k(v,$);case"D":return n.$D;case"DD":return c.s(n.$D,2,"0");case"d":return String(n.$W);case"dd":return k(e.weekdaysMin,n.$W,p,2);case"ddd":return k(e.weekdaysShort,n.$W,p,3);case"dddd":return p[n.$W];case"H":return String(h);case"HH":return c.s(h,2,"0");case"h":return R(1);case"hh":return R(2);case"a":return I(h,l,!0);case"A":return I(h,l,!1);case"m":return String(l);case"mm":return c.s(l,2,"0");case"s":return String(n.$s);case"ss":return c.s(n.$s,2,"0");case"SSS":return c.s(n.$ms,3,"0");case"Z":return o}return null})(T)||o.replace(":","")})},i.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},i.diff=function(t,n,e){var a,o=this,h=c.p(n),l=g(t),$=(l.utcOffset()-this.utcOffset())*O,p=this-l,v=function(){return c.m(o,l)};switch(h){case b:a=v()/12;break;case S:a=v();break;case K:a=v()/3;break;case f:a=(p-$)/6048e5;break;case M:a=(p-$)/864e5;break;case L:a=p/s;break;case m:a=p/O;break;case d:a=p/y;break;default:a=p}return e?a:c.a(a)},i.daysInMonth=function(){return this.endOf(S).$D},i.$locale=function(){return D[this.$L]},i.locale=function(t,n){if(!t)return this.$L;var e=this.clone(),a=C(t,n,!0);return a&&(e.$L=a),e},i.clone=function(){return c.w(this.$d,this)},i.toDate=function(){return new Date(this.valueOf())},i.toJSON=function(){return this.isValid()?this.toISOString():null},i.toISOString=function(){return this.$d.toISOString()},i.toString=function(){return this.$d.toUTCString()},r})(),z=x.prototype;return g.prototype=z,[["$ms",u],["$s",d],["$m",m],["$H",L],["$W",M],["$M",S],["$y",b],["$D",_]].forEach(function(r){z[r[1]]=function(i){return this.$g(i,r[0],r[1])}}),g.extend=function(r,i){return r.$i||(r(i,x,g),r.$i=!0),g},g.locale=C,g.isDayjs=W,g.unix=function(r){return g(1e3*r)},g.en=D[A],g.Ls=D,g.p={},g})});var B=ht(nt(),1);var Mt=(()=>{class y{$api=H(st);$title=H(tt);$toastr=H(it);$translate=H(et);settingsLoadedSubject=new U;defaultTheme="deep-purple";forbiddenKeys=["__proto__","constructor","prototype"];serverTimeToastCleanup$=new U;restartToastRef=null;terminalSettingsChanged=new U;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(q());settingsLoaded=!1;themeList=["orange","red","pink","purple","deep-purple","indigo","blue","blue-grey","cyan","green","teal","grey","brown"];constructor(){this.getAppSettings()}getAppSettings(){return P(this,null,function*(){let s=yield this.$api.get("/auth/settings");this.formAuth=s.formAuth,this.sessionTimeout=s.sessionTimeout,this.sessionTimeoutInactivityBased=s.sessionTimeoutInactivityBased,this.env=s.env,this.host=s.host,this.proxyHost=s.proxyHost,this.lightingMode=s.lightingMode,this.wallpaper=s.wallpaper,this.setLightingMode(this.lightingMode,"user"),this.setTheme(s.theme),this.setMenuMode(s.menuMode),this.setKeepOrphans(s.keepOrphans),this.setTitle(this.env.homebridgeInstanceName),this.checkServerTime(s.serverTimestamp),this.setUiVersion(s.env.packageVersion),this.setLang(this.env.lang),this.settingsLoaded=!0,this.settingsLoadedSubject.next(void 0),this.browserLang=this.$translate.getBrowserCultureLang()})}setBrowserLightingMode(s){this.browserLightingMode=s,this.lightingMode==="auto"&&this.setLightingMode(s,"browser")}setLightingMode(s,u){u==="user"&&(this.lightingMode=s),this.currentLightingMode=s,this.actualLightingMode=this.currentLightingMode==="auto"?this.browserLightingMode:this.currentLightingMode,this.theme&&this.setTheme(this.theme)}setTheme(s){(!s||!this.themeList.includes(s))&&(s=this.defaultTheme,this.$api.put("/config-editor/ui",{key:"theme",value:s}).catch(m=>console.error("Error saving setTheme:",m)));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=s,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((m,L)=>{try{let M=m.contentDocument;if(M){let f=M.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"),m.contentWindow?.postMessage({type:"theme-update",isDark:this.actualLightingMode==="dark",theme:s},window.location.origin)}}catch(M){console.warn(`Iframe ${L}: Access denied (cross-origin?)`,{error:M,src:m.src})}})}setMenuMode(s){this.menuMode=s}setKeepOrphans(s){this.keepOrphans=s}setLang(s){s?this.$translate.use(s):s="auto",this.env.lang=s}setItem(s,u){this[s]=u}setEnvItem(s,u){if(s.includes(".")){let d=s.split("."),m=this.env;for(let L=0;L<d.length-1;L+=1){if(this.forbiddenKeys.includes(d[L]))return;m[d[L]]||(m[d[L]]={}),m=m[d[L]]}this.forbiddenKeys.includes(d.at(-1))||(m[d.at(-1)]=u)}else this.env[s]=u}checkServerTime(s){let d=(0,B.default)(s).diff((0,B.default)(),"hour");this.serverTimeOffset=d*60*60,(d>=8||d<=-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(Q(this.serverTimeToastCleanup$)).subscribe(()=>{window.open("https://homebridge.io/w/JqTFs","_blank")}))}setUiVersion(s){this.uiVersion||(this.uiVersion=s)}setTitle(s){this.$title.setTitle(s||"Homebridge")}setPageTitle(s){let u=this.env.homebridgeInstanceName||"Homebridge";s?this.$title.setTitle(`${u} \u2014 ${s}`):this.$title.setTitle(u)}isFeatureEnabled(s){return this.env.featureFlags?.[s]??!1}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(s=!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:s?this.TERMINAL_COLORS.DARK.WIDGET:this.TERMINAL_COLORS.DARK.FULL_PAGE},allowTransparency:!1}}getTerminalOptions(s,u=!1){let d=this.getTerminalThemeOptions(u);return J({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:d.theme,allowTransparency:d.allowTransparency,screenReaderMode:!0},s)}static \u0275fac=function(u){return new(u||y)};static \u0275prov=X({token:y,factory:y.\u0275fac,providedIn:"root"})}return y})();export{nt as a,Mt as b};