iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
3 lines • 16 kB
JavaScript
/*! For license information please see 34172.bb32262e01909999.js.LICENSE.txt */
export const __webpack_ids__=["34172"];export const __webpack_modules__={53013:function(e,t,n){var o=n(44249),i=n(72621),r=(n(9359),n(56475),n(70104),n(48136),n(57243)),a=n(15093),s=n(94886),c=n.n(s),l=n(36522),d=(n(75656),n(50100),n(18084),n(75351));let h;const u=new(n(80262).L)(1e3),p={reType:/(?<input>(\[!(?<type>caution|important|note|tip|warning)\])(?:\s|\\n)?)/i,typeToHaAlert:{caution:"error",important:"info",note:"info",tip:"success",warning:"warning"}};(0,o.Z)([(0,a.Mo)("ha-markdown-element")],(function(e,t){class o extends t{constructor(...t){super(...t),e(this)}}return{F:o,d:[{kind:"field",decorators:[(0,a.Cb)()],key:"content",value:void 0},{kind:"field",decorators:[(0,a.Cb)({attribute:"allow-svg",type:Boolean})],key:"allowSvg",value:()=>!1},{kind:"field",decorators:[(0,a.Cb)({type:Boolean})],key:"breaks",value:()=>!1},{kind:"field",decorators:[(0,a.Cb)({type:Boolean,attribute:"lazy-images"})],key:"lazyImages",value:()=>!1},{kind:"field",decorators:[(0,a.Cb)({type:Boolean})],key:"cache",value:()=>!1},{kind:"method",key:"disconnectedCallback",value:function(){if((0,i.Z)(o,"disconnectedCallback",this,3)([]),this.cache){const e=this._computeCacheKey();u.set(e,this.innerHTML)}}},{kind:"method",key:"createRenderRoot",value:function(){return this}},{kind:"method",key:"update",value:function(e){(0,i.Z)(o,"update",this,3)([e]),void 0!==this.content&&this._render()}},{kind:"method",key:"willUpdate",value:function(e){if(!this.innerHTML&&this.cache){const e=this._computeCacheKey();u.has(e)&&(this.innerHTML=u.get(e),this._resize())}}},{kind:"method",key:"_computeCacheKey",value:function(){return c()({content:this.content,allowSvg:this.allowSvg,breaks:this.breaks})}},{kind:"method",key:"_render",value:async function(){this.innerHTML=await(async(e,t,o)=>(h||(h=(0,d.Ud)(new Worker(new URL(n.p+n.u("45845"),n.b)))),h.renderMarkdown(e,t,o)))(String(this.content),{breaks:this.breaks,gfm:!0},{allowSvg:this.allowSvg}),this._resize();const e=document.createTreeWalker(this,NodeFilter.SHOW_ELEMENT,null);for(;e.nextNode();){const t=e.currentNode;if(t instanceof HTMLAnchorElement&&t.host!==document.location.host)t.target="_blank",t.rel="noreferrer noopener";else if(t instanceof HTMLImageElement)this.lazyImages&&(t.loading="lazy"),t.addEventListener("load",this._resize);else if(t instanceof HTMLQuoteElement){const n=t.firstElementChild?.firstChild?.textContent&&p.reType.exec(t.firstElementChild.firstChild.textContent);if(n){const{type:o}=n.groups,i=document.createElement("ha-alert");i.alertType=p.typeToHaAlert[o.toLowerCase()],i.append(...Array.from(t.childNodes).map((e=>{const t=Array.from(e.childNodes);if(!this.breaks&&t.length){const e=t[0];e.nodeType===Node.TEXT_NODE&&e.textContent===n.input&&e.textContent?.includes("\n")&&(e.textContent=e.textContent.split("\n").slice(1).join("\n"))}return t})).reduce(((e,t)=>e.concat(t)),[]).filter((e=>e.textContent&&e.textContent!==n.input))),e.parentNode().replaceChild(i,t)}}else t instanceof HTMLElement&&["ha-alert","ha-qr-code","ha-icon","ha-svg-icon"].includes(t.localName)&&n(23265)(`./${t.localName}`)}}},{kind:"field",key:"_resize",value(){return()=>(0,l.B)(this,"content-resize")}}]}}),r.fl)},99254:function(e,t,n){var o=n(44249),i=n(57243),r=n(15093);n(53013);(0,o.Z)([(0,r.Mo)("ha-markdown")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[(0,r.Cb)()],key:"content",value:void 0},{kind:"field",decorators:[(0,r.Cb)({attribute:"allow-svg",type:Boolean})],key:"allowSvg",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)({type:Boolean})],key:"breaks",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)({type:Boolean,attribute:"lazy-images"})],key:"lazyImages",value:()=>!1},{kind:"field",decorators:[(0,r.Cb)({type:Boolean})],key:"cache",value:()=>!1},{kind:"method",key:"render",value:function(){return this.content?i.dy`<ha-markdown-element .content="${this.content}" .allowSvg="${this.allowSvg}" .breaks="${this.breaks}" .lazyImages="${this.lazyImages}" .cache="${this.cache}"></ha-markdown-element>`:i.Ld}},{kind:"field",static:!0,key:"styles",value:()=>i.iv`:host{display:block}ha-markdown-element{-ms-user-select:text;-webkit-user-select:text;-moz-user-select:text}ha-markdown-element>:first-child{margin-top:0}ha-markdown-element>:last-child{margin-bottom:0}ha-alert{display:block;margin:4px 0}a{color:var(--primary-color)}img{max-width:100%}code,pre{background-color:var(--markdown-code-background-color,none);border-radius:3px}svg{background-color:var(--markdown-svg-background-color,none);color:var(--markdown-svg-color,none)}code{font-size:85%;padding:.2em .4em}pre code{padding:0}pre{padding:16px;overflow:auto;line-height:1.45;font-family:var(--code-font-family, monospace)}h1,h2,h3,h4,h5,h6{line-height:initial}h2{font-size:1.5em;font-weight:700}hr{border-color:var(--divider-color);border-bottom:none;margin:16px 0}`}]}}),i.oi)},23575:function(e,t,n){n.d(t,{N:()=>o,Z:()=>i});const o=(e,t,n)=>e.subscribeMessage((e=>t(e)),{type:"render_template",...n}),i=(e,t,n,o,i)=>e.connection.subscribeMessage(i,{type:"template/start_preview",flow_id:t,flow_type:n,user_input:o})},91713:function(e,t,n){n.r(t),n.d(t,{HuiMarkdownCard:()=>m});var o=n(44249),i=n(72621),r=n(57243),a=n(15093),s=n(35359),c=n(94886),l=n.n(c),d=n(82393),h=n(36522),u=(n(99426),n(54977),n(99254),n(23575));const p=new(n(80262).L)(1e3);let m=(0,o.Z)([(0,a.Mo)("hui-markdown-card")],(function(e,t){class o extends t{constructor(...t){super(...t),e(this)}}return{F:o,d:[{kind:"method",static:!0,key:"getConfigElement",value:async function(){return await n.e("17497").then(n.bind(n,23006)),document.createElement("hui-markdown-card-editor")}},{kind:"method",static:!0,key:"getStubConfig",value:function(){return{type:"markdown",content:"The **Markdown** card allows you to write any text. You can style it **bold**, *italicized*, ~strikethrough~ etc. You can do images, links, and more.\n\nFor more information see the [Markdown Cheatsheet](https://commonmark.org/help)."}}},{kind:"field",decorators:[(0,a.Cb)({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[(0,a.Cb)({type:Boolean})],key:"preview",value:()=>!1},{kind:"field",decorators:[(0,a.SB)()],key:"_config",value:void 0},{kind:"field",decorators:[(0,a.SB)()],key:"_error",value:void 0},{kind:"field",decorators:[(0,a.SB)()],key:"_errorLevel",value:void 0},{kind:"field",decorators:[(0,a.SB)()],key:"_templateResult",value:void 0},{kind:"field",key:"_unsubRenderTemplate",value:void 0},{kind:"method",key:"getCardSize",value:function(){return void 0===this._config?3:void 0===this._config.card_size?Math.round(this._config.content.split("\n").length/2)+(this._config.title?1:0):this._config.card_size}},{kind:"method",key:"setConfig",value:function(e){if(!e.content)throw new Error("Content required");this._config?.content!==e.content&&this._tryDisconnect(),this._config=e}},{kind:"method",key:"connectedCallback",value:function(){(0,i.Z)(o,"connectedCallback",this,3)([]),this._tryConnect()}},{kind:"method",key:"_computeCacheKey",value:function(){return l()(this._config)}},{kind:"method",key:"disconnectedCallback",value:function(){if((0,i.Z)(o,"disconnectedCallback",this,3)([]),this._tryDisconnect(),this._config&&this._templateResult){const e=this._computeCacheKey();p.set(e,this._templateResult)}}},{kind:"method",key:"willUpdate",value:function(e){if((0,i.Z)(o,"willUpdate",this,3)([e]),this._config&&!this._templateResult){const e=this._computeCacheKey();p.has(e)&&(this._templateResult=p.get(e))}}},{kind:"method",key:"render",value:function(){return this._config?r.dy` ${this._error?r.dy` <ha-alert .alertType="${this._errorLevel?.toLowerCase()||"error"}"> ${this._error} </ha-alert> `:r.Ld} <ha-card .header="${this._config.text_only?void 0:this._config.title}" class="${(0,s.$)({"with-header":!!this._config.title,"text-only":this._config.text_only??!1})}"> <ha-markdown cache breaks .content="${this._templateResult?.result}"></ha-markdown> </ha-card> `:r.Ld}},{kind:"method",key:"updated",value:function(e){if((0,i.Z)(o,"updated",this,3)([e]),!this._config||!this.hass)return;e.has("_config")&&this._tryConnect();const t=!!this._templateResult&&!1===this._config.show_empty&&0===this._templateResult.result.length;t!==this.hidden&&(this.style.display=t?"none":"",this.toggleAttribute("hidden",t),(0,h.B)(this,"card-visibility-changed",{value:!t}));const n=e.get("hass"),r=e.get("_config");n&&r&&n.themes===this.hass.themes&&r.theme===this._config.theme||(0,d.R)(this,this.hass.themes,this._config.theme)}},{kind:"method",key:"_tryConnect",value:async function(){if(void 0===this._unsubRenderTemplate&&this.hass&&this._config){this._error=void 0,this._errorLevel=void 0;try{this._unsubRenderTemplate=(0,u.N)(this.hass.connection,(e=>{"error"in e?"ERROR"!==e.level&&"ERROR"===this._errorLevel||(this._error=e.error,this._errorLevel=e.level):this._templateResult=e}),{template:this._config.content,entity_ids:this._config.entity_id,variables:{config:this._config,user:this.hass.user.name},strict:!0,report_errors:this.preview}),await this._unsubRenderTemplate}catch(e){this.preview&&(this._error=e.message,this._errorLevel=void 0),this._templateResult={result:this._config.content,listeners:{all:!1,domains:[],entities:[],time:!1}},this._unsubRenderTemplate=void 0}}}},{kind:"method",key:"_tryDisconnect",value:async function(){this._unsubRenderTemplate&&(this._unsubRenderTemplate.then((e=>e())).catch(),this._unsubRenderTemplate=void 0,this._error=void 0,this._errorLevel=void 0)}},{kind:"field",static:!0,key:"styles",value:()=>r.iv`ha-card{height:100%}ha-alert{margin-bottom:8px}ha-markdown{padding:16px;word-wrap:break-word;text-align:var(--card-text-align,inherit)}.with-header ha-markdown{padding:0 16px 16px}.text-only{background:0 0;box-shadow:none;border:none}.text-only ha-markdown{padding:2px 4px}`}]}}),r.oi)},80262:function(e,t,n){n.d(t,{L:()=>o});class o{constructor(e){this._expiration=void 0,this._cache=new Map,this._expiration=e}get(e){return this._cache.get(e)}set(e,t){this._cache.set(e,t),this._expiration&&window.setTimeout((()=>this._cache.delete(e)),this._expiration)}has(e){return this._cache.has(e)}}},23265:function(e,t,n){var o={"./ha-icon":["65981","97406"],"./ha-icon-button-toggle":["79505","80175"],"./ha-svg-icon":["37583"],"./ha-icon-button-group":["45747","97792"],"./ha-svg-icon.ts":["37583"],"./ha-icon.ts":["65981","97406"],"./ha-icon-overflow-menu":["59959","91552","78456","56898","99287","35252"],"./ha-icon-next":["13928","99172"],"./ha-icon-picker":["21393","46379","66031","24199","27506","97077"],"./ha-qr-code.ts":["50634","53750","70472"],"./ha-icon-button-arrow-prev.ts":["54202","41069"],"./ha-icon-button-arrow-prev":["54202","41069"],"./ha-icon-overflow-menu.ts":["59959","91552","78456","56898","99287","35252"],"./ha-alert":["99426","4809"],"./ha-icon-button-next":["4635","51577"],"./ha-icon-button":["23334"],"./ha-icon-button-next.ts":["4635","51577"],"./ha-icon-picker.ts":["21393","46379","66031","24199","27506","97077"],"./ha-icon-button-group.ts":["45747","97792"],"./ha-icon-button-toggle.ts":["79505","80175"],"./ha-icon-button-arrow-next.ts":["54237","21559"],"./ha-icon-button-prev.ts":["5828","43537"],"./ha-icon-prev":["95499","87557"],"./ha-icon-prev.ts":["95499","87557"],"./ha-icon-button.ts":["23334"],"./ha-alert.ts":["99426","4809"],"./ha-icon-button-prev":["5828","43537"],"./ha-qr-code":["50634","53750","70472"],"./ha-icon-next.ts":["13928","99172"],"./ha-icon-button-arrow-next":["54237","21559"]};function i(e){if(!n.o(o,e))return Promise.resolve().then((function(){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}));var t=o[e],i=t[0];return Promise.all(t.slice(1).map(n.e)).then((function(){return n(i)}))}i.keys=()=>Object.keys(o),i.id=23265,e.exports=i},75351:function(e,t,n){n.d(t,{Ud:()=>u});n(9359),n(70104),n(48136);const o=Symbol("Comlink.proxy"),i=Symbol("Comlink.endpoint"),r=Symbol("Comlink.releaseProxy"),a=Symbol("Comlink.finalizer"),s=Symbol("Comlink.thrown"),c=e=>"object"==typeof e&&null!==e||"function"==typeof e,l=new Map([["proxy",{canHandle:e=>c(e)&&e[o],serialize(e){const{port1:t,port2:n}=new MessageChannel;return d(e,t),[n,[n]]},deserialize:e=>(e.start(),u(e))}],["throw",{canHandle:e=>c(e)&&s in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error(e.value.message),e.value);throw e.value}}]]);function d(e,t=globalThis,n=["*"]){t.addEventListener("message",(function i(r){if(!r||!r.data)return;if(!function(e,t){for(const n of e){if(t===n||"*"===n)return!0;if(n instanceof RegExp&&n.test(t))return!0}return!1}(n,r.origin))return void console.warn(`Invalid origin '${r.origin}' for comlink proxy`);const{id:c,type:l,path:u}=Object.assign({path:[]},r.data),p=(r.data.argumentList||[]).map(b);let m;try{const t=u.slice(0,-1).reduce(((e,t)=>e[t]),e),n=u.reduce(((e,t)=>e[t]),e);switch(l){case"GET":m=n;break;case"SET":t[u.slice(-1)[0]]=b(r.data.value),m=!0;break;case"APPLY":m=n.apply(t,p);break;case"CONSTRUCT":m=function(e){return Object.assign(e,{[o]:!0})}(new n(...p));break;case"ENDPOINT":{const{port1:t,port2:n}=new MessageChannel;d(e,n),m=function(e,t){return v.set(e,t),e}(t,[t])}break;case"RELEASE":m=void 0;break;default:return}}catch(e){m={value:e,[s]:0}}Promise.resolve(m).catch((e=>({value:e,[s]:0}))).then((n=>{const[o,r]=_(n);t.postMessage(Object.assign(Object.assign({},o),{id:c}),r),"RELEASE"===l&&(t.removeEventListener("message",i),h(t),a in e&&"function"==typeof e[a]&&e[a]())})).catch((e=>{const[n,o]=_({value:new TypeError("Unserializable return value"),[s]:0});t.postMessage(Object.assign(Object.assign({},n),{id:c}),o)}))})),t.start&&t.start()}function h(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function u(e,t){const n=new Map;return e.addEventListener("message",(function(e){const{data:t}=e;if(!t||!t.id)return;const o=n.get(t.id);if(o)try{o(t)}finally{n.delete(t.id)}})),k(e,n,[],t)}function p(e){if(e)throw new Error("Proxy has been released and is not useable")}function m(e){return w(e,new Map,{type:"RELEASE"}).then((()=>{h(e)}))}const f=new WeakMap,g="FinalizationRegistry"in globalThis&&new FinalizationRegistry((e=>{const t=(f.get(e)||0)-1;f.set(e,t),0===t&&m(e)}));function k(e,t,n=[],o=function(){}){let a=!1;const s=new Proxy(o,{get(o,i){if(p(a),i===r)return()=>{!function(e){g&&g.unregister(e)}(s),m(e),t.clear(),a=!0};if("then"===i){if(0===n.length)return{then:()=>s};const o=w(e,t,{type:"GET",path:n.map((e=>e.toString()))}).then(b);return o.then.bind(o)}return k(e,t,[...n,i])},set(o,i,r){p(a);const[s,c]=_(r);return w(e,t,{type:"SET",path:[...n,i].map((e=>e.toString())),value:s},c).then(b)},apply(o,r,s){p(a);const c=n[n.length-1];if(c===i)return w(e,t,{type:"ENDPOINT"}).then(b);if("bind"===c)return k(e,t,n.slice(0,-1));const[l,d]=y(s);return w(e,t,{type:"APPLY",path:n.map((e=>e.toString())),argumentList:l},d).then(b)},construct(o,i){p(a);const[r,s]=y(i);return w(e,t,{type:"CONSTRUCT",path:n.map((e=>e.toString())),argumentList:r},s).then(b)}});return function(e,t){const n=(f.get(t)||0)+1;f.set(t,n),g&&g.register(e,t,e)}(s,e),s}function y(e){const t=e.map(_);return[t.map((e=>e[0])),(n=t.map((e=>e[1])),Array.prototype.concat.apply([],n))];var n}const v=new WeakMap;function _(e){for(const[t,n]of l)if(n.canHandle(e)){const[o,i]=n.serialize(e);return[{type:"HANDLER",name:t,value:o},i]}return[{type:"RAW",value:e},v.get(e)||[]]}function b(e){switch(e.type){case"HANDLER":return l.get(e.name).deserialize(e.value);case"RAW":return e.value}}function w(e,t,n,o){return new Promise((i=>{const r=new Array(4).fill(0).map((()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16))).join("-");t.set(r,i),e.start&&e.start(),e.postMessage(Object.assign({id:r},n),o)}))}}};
//# sourceMappingURL=34172.bb32262e01909999.js.map