24 lines
28 KiB
JavaScript
24 lines
28 KiB
JavaScript
(function($){typeof define=="function"&&define.amd?define($):$()})(function(){"use strict";const $=(r,t)=>{document.createElement("ha-panel-custom").navigate(r,t)},X=async(r,t)=>{if(!customElements.get(r)){const e=[{url_path:"tmp",component_name:t}],n=document.createElement("partial-panel-resolver");await(n._getRoutes||n.getRoutes).call(n,e).routes.tmp.load()}},Se=async(r,t)=>{let e=null;try{e=await r.callWS({type:"supervisor/api",endpoint:`/addons/${t}/info`,method:"get"})}catch{}return e},Z=r=>(document.cookie=`ingress_session=${r};path=/api/hassio_ingress/;SameSite=Strict${location.protocol==="https:"?";Secure":""}`,r),K=async r=>{const t=await r.callWS({type:"supervisor/api",endpoint:"/ingress/session",method:"post"});return Z(t.session)},_e=async(r,t)=>{await r.callWS({type:"supervisor/api",endpoint:"/ingress/validate_session",method:"post",data:{session:t}}),Z(t)};let g=window.__ingressSession;if(!g){const r=()=>({session:"",refCount:0});let t=r();g=window.__ingressSession={get session(){return t.session},get refCount(){return t.refCount},async init(e){if(!e)return!1;if(t.hass=e,t.timer===void 0){try{t.session=await K(e)}catch{return!1}t.timer===void 0&&(t.timer=setInterval(async()=>{const n=t.hass;try{await _e(n,t.session)}catch{t.session=await K(n)}},6e4),t.refCount=0)}return++t.refCount,!0},fini(){t.timer!==void 0&&(--t.refCount,clearTimeout(t.finiTimer),t.finiTimer=setTimeout(()=>{delete t.finiTimer,t.refCount<=0&&t.timer!==void 0&&(clearInterval(t.timer),t=r())},6e4))}}}const N=r=>(document.cookie=`ha_ingress_session=${r};path=/api/ingress/;SameSite=Strict${location.protocol==="https:"?";Secure":""}`,r),ee=async r=>{const t=await r.callWS({type:"ha-ingress/session"});return N(t.session)},Ee=async(r,t)=>{await r.callWS({type:"ha-ingress/validate_session",session:t}),N(t)};let R=window.__haIngressSession;if(!R){let t={session:""};R=window.__haIngressSession={get session(){return t.session},async init(e){if(!e)return!1;if(t.hass=e,t.timer===void 0){try{t.session=await ee(e)}catch{return!1}t.timer===void 0&&(t.timer=setInterval(async()=>{const n=t.hass;try{await Ee(n,t.session)}catch{t.session=await ee(n)}},6e4))}return!0}}}var F=function(r,t){return F=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])},F(r,t)};function x(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");F(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function xe(r,t,e,n){function i(o){return o instanceof e?o:new e(function(s){s(o)})}return new(e||(e=Promise))(function(o,s){function a(f){try{u(n.next(f))}catch(d){s(d)}}function c(f){try{u(n.throw(f))}catch(d){s(d)}}function u(f){f.done?o(f.value):i(f.value).then(a,c)}u((n=n.apply(r,t||[])).next())})}function te(r,t){var e={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},n,i,o,s;return s={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function a(u){return function(f){return c([u,f])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,u[0]&&(e=0)),e;)try{if(n=1,i&&(o=u[0]&2?i.return:u[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,u[1])).done)return o;switch(i=0,o&&(u=[u[0]&2,o.value]),u[0]){case 0:case 1:o=u;break;case 4:return e.label++,{value:u[1],done:!1};case 5:e.label++,i=u[1],u=[0];continue;case 7:u=e.ops.pop(),e.trys.pop();continue;default:if(o=e.trys,!(o=o.length>0&&o[o.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!o||u[1]>o[0]&&u[1]<o[3])){e.label=u[1];break}if(u[0]===6&&e.label<o[1]){e.label=o[1],o=u;break}if(o&&e.label<o[2]){e.label=o[2],e.ops.push(u);break}o[2]&&e.ops.pop(),e.trys.pop();continue}u=t.call(r,e)}catch(f){u=[6,f],i=0}finally{n=o=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function S(r){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function T(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),i,o=[],s;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)o.push(i.value)}catch(a){s={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(s)throw s.error}}return o}function M(r,t,e){if(e||arguments.length===2)for(var n=0,i=t.length,o;n<i;n++)(o||!(n in t))&&(o||(o=Array.prototype.slice.call(t,0,n)),o[n]=t[n]);return r.concat(o||Array.prototype.slice.call(t))}function I(r){return this instanceof I?(this.v=r,this):new I(r)}function Ie(r,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(r,t||[]),i,o=[];return i={},a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(l){return function(h){return Promise.resolve(h).then(l,d)}}function a(l,h){n[l]&&(i[l]=function(p){return new Promise(function(P,E){o.push([l,p,P,E])>1||c(l,p)})},h&&(i[l]=h(i[l])))}function c(l,h){try{u(n[l](h))}catch(p){v(o[0][3],p)}}function u(l){l.value instanceof I?Promise.resolve(l.value.v).then(f,d):v(o[0][2],l)}function f(l){c("next",l)}function d(l){c("throw",l)}function v(l,h){l(h),o.shift(),o.length&&c(o[0][0],o[0][1])}}function Pe(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=r[Symbol.asyncIterator],e;return t?t.call(r):(r=typeof S=="function"?S(r):r[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=r[o]&&function(s){return new Promise(function(a,c){s=r[o](s),i(a,c,s.done,s.value)})}}function i(o,s,a,c){Promise.resolve(c).then(function(u){o({value:u,done:a})},s)}}typeof SuppressedError=="function"&&SuppressedError;function y(r){return typeof r=="function"}function re(r){var t=function(n){Error.call(n),n.stack=new Error().stack},e=r(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var B=re(function(r){return function(e){r(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
`+e.map(function(n,i){return i+1+") "+n.toString()}).join(`
|
|
`):"",this.name="UnsubscriptionError",this.errors=e}});function Y(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var j=function(){function r(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var t,e,n,i,o;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=S(s),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(p){t={error:p}}finally{try{c&&!c.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else s.remove(this);var f=this.initialTeardown;if(y(f))try{f()}catch(p){o=p instanceof B?p.errors:[p]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var v=S(d),l=v.next();!l.done;l=v.next()){var h=l.value;try{oe(h)}catch(p){o=o??[],p instanceof B?o=M(M([],T(o)),T(p.errors)):o.push(p)}}}catch(p){n={error:p}}finally{try{l&&!l.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}}if(o)throw new B(o)}},r.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)oe(t);else{if(t instanceof r){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},r.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},r.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},r.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Y(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&Y(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=function(){var t=new r;return t.closed=!0,t}(),r}(),ne=j.EMPTY;function ie(r){return r instanceof j||r&&"closed"in r&&y(r.remove)&&y(r.add)&&y(r.unsubscribe)}function oe(r){y(r)?r():r.unsubscribe()}var se={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},ae={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,M([r,t],T(e)))},clearTimeout:function(r){var t=ae.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(r)},delegate:void 0};function ue(r){ae.setTimeout(function(){throw r})}function q(){}function L(r){r()}var W=function(r){x(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,ie(e)&&e.add(n)):n.destination=Ae,n}return t.create=function(e,n,i){return new D(e,n,i)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(j),Te=Function.prototype.bind;function z(r,t){return Te.call(r,t)}var Oe=function(){function r(t){this.partialObserver=t}return r.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){U(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){U(n)}else U(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){U(e)}},r}(),D=function(r){x(t,r);function t(e,n,i){var o=r.call(this)||this,s;if(y(e)||!e)s={next:e??void 0,error:n??void 0,complete:i??void 0};else{var a;o&&se.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return o.unsubscribe()},s={next:e.next&&z(e.next,a),error:e.error&&z(e.error,a),complete:e.complete&&z(e.complete,a)}):s=e}return o.destination=new Oe(s),o}return t}(W);function U(r){ue(r)}function ke(r){throw r}var Ae={closed:!0,next:q,error:ke,complete:q},G=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function ce(r){return r}function Ce(r){return r.length===0?ce:r.length===1?r[0]:function(e){return r.reduce(function(n,i){return i(n)},e)}}var m=function(){function r(t){t&&(this._subscribe=t)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(t,e,n){var i=this,o=$e(t)?t:new D(t,e,n);return L(function(){var s=i,a=s.operator,c=s.source;o.add(a?a.call(o,c):c?i._subscribe(o):i._trySubscribe(o))}),o},r.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},r.prototype.forEach=function(t,e){var n=this;return e=le(e),new e(function(i,o){var s=new D({next:function(a){try{t(a)}catch(c){o(c),s.unsubscribe()}},error:o,complete:i});n.subscribe(s)})},r.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},r.prototype[G]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ce(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=le(t),new t(function(n,i){var o;e.subscribe(function(s){return o=s},function(s){return i(s)},function(){return n(o)})})},r.create=function(t){return new r(t)},r}();function le(r){var t;return(t=r??se.Promise)!==null&&t!==void 0?t:Promise}function He(r){return r&&y(r.next)&&y(r.error)&&y(r.complete)}function $e(r){return r&&r instanceof W||He(r)&&ie(r)}function Me(r){return y(r==null?void 0:r.lift)}function w(r){return function(t){if(Me(t))return t.lift(function(e){try{return r(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function b(r,t,e,n,i){return new je(r,t,e,n,i)}var je=function(r){x(t,r);function t(e,n,i,o,s,a){var c=r.call(this,e)||this;return c.onFinalize=s,c.shouldUnsubscribe=a,c._next=n?function(u){try{n(u)}catch(f){e.error(f)}}:r.prototype._next,c._error=o?function(u){try{o(u)}catch(f){e.error(f)}finally{this.unsubscribe()}}:r.prototype._error,c._complete=i?function(){try{i()}catch(u){e.error(u)}finally{this.unsubscribe()}}:r.prototype._complete,c}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(W),Le=re(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),fe=function(r){x(t,r);function t(){var e=r.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var n=new he(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new Le},t.prototype.next=function(e){var n=this;L(function(){var i,o;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=S(n.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(e)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var n=this;L(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var i=n.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;L(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var n=this,i=this,o=i.hasError,s=i.isStopped,a=i.observers;return o||s?ne:(this.currentObservers=null,a.push(e),new j(function(){n.currentObservers=null,Y(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,o=n.thrownError,s=n.isStopped;i?e.error(o):s&&e.complete()},t.prototype.asObservable=function(){var e=new m;return e.source=this,e},t.create=function(e,n){return new he(e,n)},t}(m),he=function(r){x(t,r);function t(e,n){var i=r.call(this)||this;return i.destination=e,i.source=n,i}return t.prototype.next=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,e)},t.prototype.error=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,e)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:ne},t}(fe),Ue=function(r){x(t,r);function t(e){var n=r.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=r.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,o=e._value;if(n)throw i;return this._throwIfClosed(),o},t.prototype.next=function(e){r.prototype.next.call(this,this._value=e)},t}(fe),de=new m(function(r){return r.complete()}),pe=function(r){return r&&typeof r.length=="number"&&typeof r!="function"};function Ve(r){return y(r==null?void 0:r.then)}function Re(r){return y(r[G])}function Fe(r){return Symbol.asyncIterator&&y(r==null?void 0:r[Symbol.asyncIterator])}function Be(r){return new TypeError("You provided "+(r!==null&&typeof r=="object"?"an invalid object":"'"+r+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Ye(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var qe=Ye();function We(r){return y(r==null?void 0:r[qe])}function ze(r){return Ie(this,arguments,function(){var e,n,i,o;return te(this,function(s){switch(s.label){case 0:e=r.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,I(e.read())];case 3:return n=s.sent(),i=n.value,o=n.done,o?[4,I(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,I(i)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function De(r){return y(r==null?void 0:r.getReader)}function O(r){if(r instanceof m)return r;if(r!=null){if(Re(r))return Ge(r);if(pe(r))return Qe(r);if(Ve(r))return Je(r);if(Fe(r))return ve(r);if(We(r))return Xe(r);if(De(r))return Ze(r)}throw Be(r)}function Ge(r){return new m(function(t){var e=r[G]();if(y(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Qe(r){return new m(function(t){for(var e=0;e<r.length&&!t.closed;e++)t.next(r[e]);t.complete()})}function Je(r){return new m(function(t){r.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,ue)})}function Xe(r){return new m(function(t){var e,n;try{for(var i=S(r),o=i.next();!o.done;o=i.next()){var s=o.value;if(t.next(s),t.closed)return}}catch(a){e={error:a}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function ve(r){return new m(function(t){Ke(r,t).catch(function(e){return t.error(e)})})}function Ze(r){return ve(ze(r))}function Ke(r,t){var e,n,i,o;return xe(this,void 0,void 0,function(){var s,a;return te(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),e=Pe(r),c.label=1;case 1:return[4,e.next()];case 2:if(n=c.sent(),!!n.done)return[3,4];if(s=n.value,t.next(s),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),n&&!n.done&&(o=e.return)?[4,o.call(e)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function gt(r,t,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var o=t.schedule(function(){e(),i?r.add(this.schedule(null,n)):this.unsubscribe()},n);if(r.add(o),!i)return o}function k(r,t){return w(function(e,n){var i=0;e.subscribe(b(n,function(o){n.next(r.call(t,o,i++))}))})}var Ne=Array.isArray;function et(r,t){return Ne(t)?r.apply(void 0,M([],T(t))):r(t)}function tt(r){return k(function(t){return et(r,t)})}function rt(r,t,e,n,i,o,s,a){var c=[],u=0,f=0,d=!1,v=function(){d&&!c.length&&!u&&t.complete()},l=function(p){return u<n?h(p):c.push(p)},h=function(p){u++;var P=!1;O(e(p,f++)).subscribe(b(t,function(E){t.next(E)},function(){P=!0},void 0,function(){if(P)try{u--;for(var E=function(){var H=c.shift();s||h(H)};c.length&&u<n;)E();v()}catch(H){t.error(H)}}))};return r.subscribe(b(t,l,function(){d=!0,v()})),function(){}}function ye(r,t,e){return e===void 0&&(e=1/0),y(t)?ye(function(n,i){return k(function(o,s){return t(n,o,i,s)})(O(r(n,i)))},e):(typeof t=="number"&&(e=t),w(function(n,i){return rt(n,i,r,e)}))}var nt=["addListener","removeListener"],it=["addEventListener","removeEventListener"],ot=["on","off"];function _(r,t,e,n){if(y(e)&&(n=e,e=void 0),n)return _(r,t,e).pipe(tt(n));var i=T(ut(r)?it.map(function(a){return function(c){return r[a](t,c,e)}}):st(r)?nt.map(me(r,t)):at(r)?ot.map(me(r,t)):[],2),o=i[0],s=i[1];if(!o&&pe(r))return ye(function(a){return _(a,t,e)})(O(r));if(!o)throw new TypeError("Invalid event target");return new m(function(a){var c=function(){for(var u=[],f=0;f<arguments.length;f++)u[f]=arguments[f];return a.next(1<u.length?u:u[0])};return o(c),function(){return s(c)}})}function me(r,t){return function(e){return function(n){return r[e](t,n)}}}function st(r){return y(r.addListener)&&y(r.removeListener)}function at(r){return y(r.on)&&y(r.off)}function ut(r){return y(r.addEventListener)&&y(r.removeEventListener)}function A(r,t){return w(function(e,n){var i=0;e.subscribe(b(n,function(o){return r.call(t,o,i++)&&n.next(o)}))})}function be(r){return r<=0?function(){return de}:w(function(t,e){var n=0;t.subscribe(b(e,function(i){++n<=r&&(e.next(i),r<=n&&e.complete())}))})}function ct(r){return r<=0?function(){return de}:w(function(t,e){var n=[];t.subscribe(b(e,function(i){n.push(i),r<n.length&&n.shift()},function(){var i,o;try{for(var s=S(n),a=s.next();!a.done;a=s.next()){var c=a.value;e.next(c)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}e.complete()},void 0,function(){n=null}))})}function Q(r,t){return w(function(e,n){var i=null,o=0,s=!1,a=function(){return s&&!i&&n.complete()};e.subscribe(b(n,function(c){i==null||i.unsubscribe();var u=0,f=o++;O(r(c,f)).subscribe(i=b(n,function(d){return n.next(t?t(c,d,f,u++):d)},function(){i=null,a()}))},function(){s=!0,a()}))})}function lt(r){return w(function(t,e){O(r).subscribe(b(e,function(){return e.complete()},q)),!e.closed&&t.subscribe(e)})}function V(r,t,e){var n=y(r)||t||e?{next:r,error:t,complete:e}:r;return n?w(function(i,o){var s;(s=n.subscribe)===null||s===void 0||s.call(n);var a=!0;i.subscribe(b(o,function(c){var u;(u=n.next)===null||u===void 0||u.call(n,c),o.next(c)},function(){var c;a=!1,(c=n.complete)===null||c===void 0||c.call(n),o.complete()},function(c){var u;a=!1,(u=n.error)===null||u===void 0||u.call(n,c),o.error(c)},function(){var c,u;a&&((c=n.unsubscribe)===null||c===void 0||c.call(n)),(u=n.finalize)===null||u===void 0||u.call(n)}))}):ce}function C(r,t=document){if(t===null)return null;const e=String(r).split(">>>");let n=t;return e.find((i,o)=>(o===0?n=t.querySelector(e[o]):n instanceof Element&&(n=((n==null?void 0:n.shadowRoot)??n).querySelector(e[o])),n===null)),n===t?null:n}function J(r){return r>1?r:window.innerWidth*r}const ft=(r,t)=>t.length&&r.composedPath().some(e=>e instanceof Element&&e.matches(t.join())),we={haPanelEnergy:{onLock:()=>{const r=C("home-assistant >>> home-assistant-main >>> ha-drawer ha-panel-energy >>> ha-top-app-bar-fixed >>> header");r&&(r.style.top="0px")}}};function ht(){Object.assign(document.body.style,{position:"fixed",inset:0,top:`-${document.documentElement.scrollTop}px`}),Object.values(we).forEach(({onLock:r})=>r==null?void 0:r())}function dt(){const r=Math.abs(parseInt(document.body.style.top))||document.documentElement.scrollTop;Object.assign(document.body.style,{position:"",inset:""}),window.scrollTo({top:r,left:0,behavior:"auto"}),Object.values(we).forEach(({onUnlock:t})=>t==null?void 0:t())}const pt=({startThreshold:r,endThreshold:t,preventOthers:e,lockVerticalScroll:n,exclusions:i})=>_(document,"touchstart",{capture:e}).pipe(A(o=>!ft(o,i)),A(({touches:[{clientX:o}]})=>o<J(r)),V(o=>{n&&ht(),e&&o.stopPropagation()}),Q(({touches:[{clientY:o}]})=>_(document,"touchmove",{capture:e}).pipe(A(({touches:s})=>s.length<2),V(s=>e&&(s==null?void 0:s.stopPropagation())),lt(_(document,"touchend",{capture:e}).pipe(V(s=>{n&&dt(),e&&(s==null||s.stopPropagation())}),be(1))),ct(1),k(({changedTouches:[{clientX:s,clientY:a}]})=>({x:s,y:a})),A(({x:s,y:a})=>s>Math.abs(a-o)&&s>J(t))))),vt=({preventOthers:r,threshold:t})=>_(document,"touchstart").pipe(V(e=>r&&e.stopPropagation()),Q(({touches:[{clientX:e}]})=>_(document,"touchend").pipe(A(({changedTouches:[{clientX:n}]})=>e-n>J(t)),be(1))));let ge=!1;const yt=r=>{var v,l;if(ge)return!0;const t=C("home-assistant >>> home-assistant-main >>> ha-drawer"),e=C("ha-sidebar",t);if(!e||getComputedStyle(e).display==="none")return!1;if(!r){const h=C("ha-panel-lovelace",t);r=((l=(v=h==null?void 0:h.lovelace)==null?void 0:v.config)==null?void 0:l.sidebar_swipe)||{}}const{start_threshold:n=.1,end_threshold:i=.13,back_threshold:o=50,prevent_others:s=!0,lock_vertical_scroll:a=!0,exclusions:c=[]}=r,u=new Ue(!1),f=vt({threshold:o,preventOthers:s}),d=pt({startThreshold:n,endThreshold:i,preventOthers:s,lockVerticalScroll:a,exclusions:c});return t&&new MutationObserver(h=>{u.next(h[0].oldValue===null)}).observe(t,{attributes:!0,attributeOldValue:!0,attributeFilter:["open"]}),u.pipe(Q(h=>h?f.pipe(k(()=>!1)):d.pipe(k(()=>!0)))).subscribe(h=>{var p;(p=C("home-assistant >>> home-assistant-main"))==null||p.dispatchEvent(new CustomEvent("hass-toggle-menu",{detail:{open:h}}))}),ge=!0,!0};var mt="M2,21V19H20V21H2M20,8V5H18V8H20M20,3A2,2 0 0,1 22,5V8A2,2 0 0,1 20,10H18V13A4,4 0 0,1 14,17H8A4,4 0 0,1 4,13V3H20M16,5H6V13A2,2 0 0,0 8,15H14A2,2 0 0,0 16,13V5Z";const bt=async(r,t,e,n)=>{const i=a=>{n||((r.shadowRoot||r).innerHTML=`<pre>${a}</pre>`)},o=await Se(t,e);if(!o)return i(`Unable to fetch add-on info of '${e}'`);if(!o.ingress_url)return i(`Add-on '${e}' does not support Ingress`);const s=o.ingress_url.replace(/\/+$/,"");return!n&&!await g.init(t)?i("Unable to create an Ingress session"):s};class wt extends HTMLElement{constructor(){super(),this._panelPath="",this.attachShadow({mode:"open"})}connectedCallback(){this._isHassio&&g.init(this._isHassio)}disconnectedCallback(){this._isHassio&&g.fini()}async setProperties(t){this._setProperties&&this._setProperties(t);const e=this._getPanelConfig(t);if(!e)return;const n=await this._getTargetUrl(e,t);n&&await this._createIngressView(n,e,t)}_getPanelConfig(t){var o,s,a;if(!t.panel&&t.route&&(t.panel=(s=(o=t.hass)==null?void 0:o.panels)==null?void 0:s[t.route.prefix.slice(1)]),!t.panel)return;const e=t.panel;let{config:n,url_path:i}=e;if(n.title=e.title,n.icon=e.icon,n.children){const c=(((a=t.route)==null?void 0:a.path)||"").split("/",2)[1];c&&c in n.children&&(n=n.children[c],i=`${i}/${c}`)}if(this._panelPath!==i)return this._panelPath=i,delete this._setProperties,n}async _getTargetUrl(t,e,n){let i="";const o=new URLSearchParams(window.location.search),{url:s,addon:a}=t,c=s===void 0;if(typeof s=="object"){const{match:d,replace:v}=s;if(i=s.default,d){const l=window.location.origin,h=l.replace(new RegExp(`^${d}$`,"i"),v);l!==h&&(i=h)}}else if(c){const d=t.token.value;if(a){const v=await bt(this,e.hass,a,n);if(!v)return;i=v}else await R.init(e.hass),i=`/api/ingress/${d}`}else i=s;n||(this._isHassio&&(g.fini(),delete this._isHassio),a&&(this._isHassio=e.hass,this.isConnected||g.fini()));let{index:u,ui_mode:f}=t;if(u!==void 0){const d=o.get("index");!n&&d&&!/(^|\/)\.\.\//.test(d)&&(u=d.replace(/^\/+/,"")),i=`${i}/${u}`}if(t.token&&!c){const d=new URL(i);d.searchParams.set(t.field,t.token.value),i=d.href}if(n||f==="custom")return i;if(o.has("replace"))a&&(i=`/files/ingress/iframe.html?ingress=${encodeURIComponent(i)}`),window.location.href=i;else if(f==="replace")i.indexOf("://")!==-1&&(window.location.href=i),$(i,{replace:!0});else return i}async _createIngressView(t,e,n){const i=(v,l)=>"setProperties"in v?h=>v.setProperties(h):h=>{for(const p of l)p in h&&(v[p]=h[p])},o=this.shadowRoot,{ui_mode:s,title:a,icon:c}=e;if(s==="custom"){const v={};for(const[l,h]of Object.entries(e.children||{})){const p=await this._getTargetUrl(h,n,!0);if(p){const{title:P,icon:E,ui_mode:H}=h;v[l]={url:p,title:P,icon:E,ui_mode:H}}}try{const{default:l}=await import(t),h=await l({url:t,title:a,icon:c,children:v,ensureHaElem:X});if(!(h instanceof HTMLElement))throw new Error("custom should export default async(config)=>HTMLElement");o.innerHTML="",o.appendChild(h),this._setProperties=i(h,["hass","narrow","route"]),this._setProperties(n)}catch(l){o.innerHTML=`<pre>custom url[${t}] is invalid:
|
|
${l}</pre>`}return}let u=`
|
|
<iframe ${a?`title="${a}"`:""} src="${t}" allow="fullscreen"></iframe>
|
|
`,f=`
|
|
iframe {
|
|
border: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
display: block;
|
|
background-color: var(--primary-background-color);
|
|
}
|
|
`;const d=s==="toolbar";if(yt()&&(u+='<div id="swipebar"></div>',f+=`
|
|
#swipebar {
|
|
position: fixed;
|
|
top: 0;
|
|
width: 20px;
|
|
height: 100%;
|
|
}
|
|
`),d&&(await X("hass-subpage","iframe"),u=`<hass-subpage main-page>${u}
|
|
<ha-icon-button slot="toolbar-icon"></ha-icon-button>
|
|
</hass-subpage>`),o.innerHTML=`<style>${f}</style>${u}`,d){const v=o.querySelector("hass-subpage");this._setButtons(v),v.header=a,this._setProperties=i(v,["hass","narrow"]),this._setProperties(n)}}_setButtons(t){for(const[e,n]of t.querySelectorAll("ha-icon-button").entries())switch(e){case 0:{n.label="Donate",n.path=mt,n.addEventListener("click",()=>{const i=document.createElement("a");i.href="https://buymeacoffee.com/lovelylain",i.target="_blank",i.rel="noreferrer",i.click()});break}}}}customElements.define("ha-panel-ingress",wt)});
|