@glance-networks/agent-plugin
Version:
Glance Networks Agent Plugin
2 lines (1 loc) • 3.25 kB
JavaScript
(function(t,s){typeof exports=="object"&&typeof module<"u"?module.exports=s():typeof define=="function"&&define.amd?define(s):(t=typeof globalThis<"u"?globalThis:t||self,t.wrapper=s())})(this,function(){"use strict";var y=t=>{throw TypeError(t)};var A=(t,s,c)=>s.has(t)||y("Cannot "+c);var E=(t,s,c)=>(A(t,s,"read from private field"),c?c.call(t):s.get(t)),R=(t,s,c)=>s.has(t)?y("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,c),C=(t,s,c,h)=>(A(t,s,"write to private field"),h?h.call(t,c):s.set(t,c),c);const t=new Set(["string","number","boolean"]),s=h=>{let p;return{c(){p=document.createElement("slot"),h&&p.setAttribute("name",h)},m(u,a){u.insertBefore(p,a||null)},p(){},d(u){u&&p.parentNode&&p.parentNode.removeChild(p)}}};function c(h,{name:p,mode:u,styles:a}){var d;if(!globalThis.customElements){console.log(`Component ${p} not registered as there is no customElements in this environment. Perhaps this is an SSR compile, which is not supported for Leo components yet.`);return}if(customElements.get(p)){console.log(`Attempted to register ${p} component multiple times.`);return}const b=new h({target:document.createElement("div")}),g=Object.keys(b.$$.props),S=g.reduce((m,$)=>(m.set($.toLowerCase(),$),m),new Map),x=Array.from(S.keys()),v=new Set(g.filter(m=>typeof b.$$.ctx[b.$$.props[m]]=="boolean"));class L extends HTMLElement{constructor(){super();R(this,d);this.listenerRemovers=new Map;const o=this.shadowRoot??this.attachShadow({mode:u});if(a){const e=new CSSStyleSheet;e.replaceSync((a==null?void 0:a.default)||a),o.adoptedStyleSheets&&(o.adoptedStyleSheets=[e])}o.replaceChildren();let r=new Set;const n=()=>{var w;const e=Array.from(this.children).map(l=>l.getAttribute("slot"));if(this.childNodes.length&&e.push(void 0),this.component&&r.size===e.length&&e.every(l=>r.has(l)))return;r=new Set(e);const i=e.reduce((l,f)=>({...l,[f??"default"]:[()=>s(f)]}),{}),M=Object.keys(((w=this.component)==null?void 0:w.$$.props)??{}).map(l=>[l,this[l]]).reduce((l,[f,O])=>({...l,[f]:O}),{});this.component&&this.component.$destroy(),this.component=new h({target:o,props:{...M,$$slots:i,$$scope:{ctx:[]}}})};new MutationObserver(n).observe(this,{childList:!0,attributes:!1,attributeOldValue:!1,subtree:!1,characterData:!1,characterDataOldValue:!1}),n();for(const e of g)Object.defineProperty(this,e,{enumerable:!0,get(){const i=this.component.$$.props[e];return this.component.$$.ctx[i]},set(i){t.has(typeof i)&&(v.has(e)?i?this.setAttribute(e,""):this.removeAttribute(e):this.setAttribute(e,i)),this.component.$set({[e]:i})}})}get component(){return E(this,d)}set component(o){C(this,d,o);for(const[r,n]of this.listenerRemovers.entries())for(const[e,i]of n.entries())i(),this.addEventListener(r,e)}static get observedAttributes(){return x}attributeChangedCallback(o,r,n){const e=S.get(o);e&&r!==n&&(this[e]=v.has(e)?n!==null:n)}addEventListener(o,r){this.listenerRemovers.has(o)||this.listenerRemovers.set(o,new Map);const n=this.component.$on(o,r);this.listenerRemovers.get(o).set(r,n)}removeEventListener(o,r){var n,e,i;(e=(n=this.listenerRemovers.get(o))==null?void 0:n.get(r))==null||e(),(i=this.listenerRemovers.get(o))==null||i.delete(r)}}d=new WeakMap,customElements.define(p,L)}return c});