-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeph.min.js
1 lines (1 loc) · 23.4 KB
/
zeph.min.js
1
window.customElements&&window.ShadowRoot||console.error("ZephJS is not supported by this browser. Please consult the Browser Support section of the ZephJS documentation for more details.");const $COMPONENTS=Symbol("components"),$CONTEXT=Symbol("context"),$CODE=Symbol("code"),$ELEMENT=Symbol("element"),$ATTRIBUTES=Symbol("attributes"),$SHADOW=Symbol("shadow"),$OBSERVER=Symbol("observer"),$LISTENERS=Symbol("listeners"),$PROXY=Symbol("proxy");let CODE_CONTEXT=null,DEFINITION_METHODS=null,PENDING={},FIREREADY=null,READY=!1;const IDENTITY_FUNCTION=t=>t,check={not:{undefined:(t,e)=>{if(void 0===t)throw new Error("Undefined "+e+".")},null:(t,e)=>{if(null===t)throw new Error("Null "+e+".")},uon:(t,e)=>{check.not.undefined(t,e),check.not.null(t,e)},empty:(t,e)=>{if("string"==typeof t&&""===t)throw new Error("Empty "+e+".")}},type:(t,e,n)=>{if(typeof t!==e)throw new Error("Invalid "+n+"; must be a "+e+".")},string:(t,e)=>{check.type(t,"string",e)},posstr:(t,e)=>{check.not.uon(t,e),check.string(t,e),check.not.empty(t,e)},number:(t,e)=>{check.type(t,"number",e)},boolean:(t,e)=>{check.type(t,"boolean",e)},function:(t,e,n)=>{if(!(t instanceof Function))throw new Error("Invalid "+n+"; must be a Function.")},array:(t,e,n)=>{if(!(t instanceof Array))throw new Error("Invalid "+n+"; must be an Array.")}},utils={ready:()=>READY,tryprom:t=>(check.not.uon(t,"argument"),check.function(t,"argument"),new Promise((e,n)=>{try{t(e,n)}catch(t){return n(t)}})),exists:(t,e={})=>null==t||""===t?Promise.resolve(!1):(e=Object.assign({},e,{method:"HEAD"}),utils.tryprom(async n=>{(await fetch(t,e)).ok?n(!0):n(!1)})),fetch:(t,e={})=>(check.not.uon(t,"url"),check.not.empty(t,"url"),utils.tryprom(async n=>{let o=await fetch(t,e);if(o.ok)return n(o);n(void 0)})),fetchText:(t,e={})=>(check.not.uon(t,"url"),check.not.empty(t,"url"),utils.tryprom(async n=>{let o=await utils.fetch(t,e);o||n(void 0),n(await o.text())})),fetchBinary:(t,e={})=>(check.not.uon(t,"url"),check.not.empty(t,"url"),utils.tryprom(async n=>{let o=await utils.fetch(t,e);o||n(void 0);let i=o.headers&&o.headers.get("Content-Type")||null;n({data:await o.arrayBuffer(),contentType:i})})),resolve:(t,e=document.URL)=>{if(check.not.uon(t,"url"),check.not.empty(t,"url"),!(t instanceof URL)&&"string"!=typeof t)throw new Error("Invalid url; must be a string or URL.");try{return"string"==typeof t&&t.startsWith("data:")?new URL(t):new URL(t,e)}catch(t){return null}},resolveName(t,e=document.URL,n=".js"){let o=""+t;return o.match(/^data:/)?Promise.resolve(new URL(t)):o.match(/^http:\/\/|^https:\/\/|^ftp:\/\/|^\.\/|^\.\.\//)?utils.tryprom(async o=>{let i=utils.resolve(t,e);if(await utils.exists(i))return o(i);if(await utils.exists(t))return o(t);if(n){let i=t+n,r=utils.resolve(i,e);if(await utils.exists(r))return o(r);if(await utils.exists(i))return o(i)}o(void 0)}):Promise.resolve(void 0)},parseDataURL(t){if(check.not.uon(t,"url"),!(t instanceof URL))throw new Error("Invalid url.");if("data:"!==t.protocol)return null;if(!t.href)return null;let e=t.href.match(/^data:([^;]+)(([^;]+;)?;base64)?,(.*)$/);return{contentType:e&&e[1]||"",data:e&&e[4]||null}}};class ZephComponent{constructor(t,e,n){check.posstr(t,"name"),check.posstr(t,"origin"),check.not.uon(n,"code"),check.function(n,"code");let o={};o.name=t,o.origin=e,this[$CODE]=n,this[$CONTEXT]=o,this[$ELEMENT]=null}get context(){return this[$CONTEXT]}get name(){return this.context.name}get origin(){return this.context.origin}get code(){return this[$CODE]}get defined(){return!!this[$ELEMENT]}get customElementClass(){return this[$ELEMENT]}define(){return utils.tryprom(async t=>{let e=new ZephComponentExecution(this.context,this.code);if(await e.run(),await Promise.all(this.context.pending||[]),this.context.from){let t=ZephComponents.get(this.context.from);if(!t)throw new Error("Component '"+this.context.from+"' not found; inheritance by '"+this.context.name+"' is not possible.");await Promise.all(t.context.pending||[]),this[$CONTEXT]=extend({},t.context,this.context)}this[$ELEMENT]=ZephElementClass.generateClass(this.context),customElements.define(this.name,this[$ELEMENT]),(this.context.aliases||[]).forEach(t=>{customElements.define(t,class extends this[$ELEMENT]{constructor(){super()}})}),fire(this.context&&this.context.lifecycle&&this.context.lifecycle.init||[],this.name,this),t()})}}class ZephComponentExecution{constructor(t,e){check.not.uon(t,"context"),check.not.uon(e,"code"),check.function(e,"code"),this[$CONTEXT]=t,this[$CODE]=e}run(){return utils.tryprom(async t=>{CODE_CONTEXT=this,await this[$CODE].bind(this)(DEFINITION_METHODS),CODE_CONTEXT=null,t()})}get context(){return this[$CONTEXT]}from(t){check.posstr(t,"fromTagName"),this.context.pending=this.context.pending||[],this.context.pending.push(ZephComponents.waitFor(t)),this.context.from=t}inline(t=!0){check.boolean(t),this.context.disableShadowRoot=t}alias(t){check.posstr(t,"aliasName"),this.context.aliases=this.context.aliases||new Set,this.context.aliases.add(t)}html(t,e={}){e=Object.assign({overwrite:!1,noRemote:!1},e||{});let n=utils.tryprom(async n=>{if(!e.noRemote){let e=await utils.resolveName(t,this.context.origin||document.URL.toString(),".html");e&&(t=await utils.fetchText(e))}let o=document.createElement("template");o.innerHTML=t,this.context.html=this.context.html||[],this.context.html.push({template:o,options:e}),n()});this.context.pending=this.context.pending||[],this.context.pending.push(n)}css(t,e={}){e=Object.assign({overwrite:!1,noRemote:!1},e||{});let n=utils.tryprom(async n=>{if(!e.noRemote){let e=await utils.resolveName(t,this.context.origin,".css");e&&(t=await utils.fetchText(e))}let o=document.createElement("template");o.innerHTML="<style>\n"+t+"\n</style>",this.context.css=this.context.css||[],this.context.css.push({template:o,options:e}),n()});this.context.pending=this.context.pending||[],this.context.pending.push(n)}asset(t,e,n={}){if(check.not.uon(t,"selector"),check.string(t,"selector"),check.not.empty(t,"selector"),check.not.uon(e,"content"),!(""+e).match(/^data:|^http:\/\/|^https:\/\/|^ftp:\/\/|^\.\/|^\.\.\//))throw new Error("Url must be a valid url (http, https, ftp), or a relative filename, or a data url.");n=Object.assign({target:"src"},n||{});let o=utils.tryprom(async o=>{let i;(e=await utils.resolveName(e,this.context.origin,""))&&"data:"===e.protocol?i=utils.parseDataURL(e):(i=await utils.fetchBinary(e)).data=btoa([].reduce.call(new Uint8Array(i.data),(t,e)=>t+String.fromCharCode(e),"")),this.context.assets=this.context.assets||[],this.context.assets.push({selector:t,contentType:i&&i.contentType||null,data:i&&i.data||null,options:n}),o()});this.context.pending=this.context.pending||[],this.context.pending.push(o)}attribute(t,e){if(check.not.uon(t,"attributeName"),check.string(t),this.context.attributes=this.context.attributes||{},this.context.attributes[t])throw new Error("Attribute '"+t+"' already defined for custom element; cannot have multiple definitions.");this.context.attributes[t]={attributeName:t,initialValue:e}}property(t,e,n){if(check.not.uon(t,"propertyName"),check.string(t),this.context.properties=this.context.properties||{},this.context.properties[t])throw new Error("Property '"+t+"' already defined for custom element; cannot have multiple definitions.");this.context.properties[t]=Object.assign(this.context.properties[t]||{},{propertyName:t,initialValue:e,transformFunction:n,changes:[]})}method(t,e){if(check.not.uon(t,"methodName"),check.string(t),this.context.methods=this.context.methods||{},this.context.methods[t])throw new Error("Method '"+t+"' already defined for custom element; cannot have multiple definitions.");this.context.methods[t]=Object.assign(this.context.methods[t]||{},{methodName:t,methodFunction:e})}binding(t,e,n,o){return this.bindingAt(".",t,e,n,o)}bindingAt(t,e,n,o,i){if(t&&e&&n&&void 0===o&&(o=e),check.not.uon(t,"sourceElement"),"string"!=typeof t&&!(t instanceof HTMLElement))throw new Error("Invalid sourceElement; must be a string or an instance of HTMLElement.");if(check.not.uon(e,"sourceName"),check.string(e,"sourceName"),!e.startsWith("$")&&!e.startsWith("@")&&!e.startsWith("."))throw new Error("Invalid sourceName; must start with a '$' or a '@' or a '.'.");if(check.not.uon(n,"targetElement"),"string"!=typeof n&&!(n instanceof HTMLElement))throw new Error("Invalid targetElement; must be a string or an instance of HTMLElement.");if(check.not.uon(o,"targetName"),check.string(o,"targetName"),!o.startsWith("$")&&!o.startsWith("@")&&!o.startsWith("."))throw new Error("Invalid targetName; must start with a '$' or a '@' or a '.'.");null==i&&(i=IDENTITY_FUNCTION),check.not.uon(i,"transformFunction"),check.function(i,"transformFunction");let r=t+":"+e+">"+n+":"+o;this.context.bindings=this.context.bindings||{},this.context.bindings[r]={source:{element:t,name:e},target:{element:n,name:o},transform:i}}onInit(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.init=this.context.lifecycle.init||[],this.context.lifecycle.init.push(t)}onCreate(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.create=this.context.lifecycle.create||[],this.context.lifecycle.create.push(t)}onAdd(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.add=this.context.lifecycle.add||[],this.context.lifecycle.add.push(t)}onRemove(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.remove=this.context.lifecycle.remove||[],this.context.lifecycle.remove.push(t)}onAdopt(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.adopt=this.context.lifecycle.adopt||[],this.context.lifecycle.adopt.push(t)}onContent(t){check.not.uon(t,"listener"),check.function(t,"listener"),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.content=this.context.lifecycle.content||[],this.context.lifecycle.content.push(t)}onAttribute(t,e){check.not.uon(t,"attribute"),check.string(t,"attribute"),check.not.uon(e,"listener"),check.function(e,"listener"),this.context.observed=this.context.observed||[],this.context.observed.push(t),this.context.lifecycle=this.context.lifecycle||{},this.context.lifecycle.attributes=this.context.lifecycle.attributes||{},this.context.lifecycle.attributes[t]=this.context.lifecycle.attributes[t]||[],this.context.lifecycle.attributes[t].push(e)}onProperty(t,e){check.not.uon(t,"attribute"),check.string(t,"attribute"),check.not.uon(e,"listener"),check.function(e,"listener"),this.context.properties=this.context.properties||{},this.context.properties[t]||this.property(t,void 0),this.context.properties[t].changes.push(e)}onEvent(t,e){check.not.uon(t,"eventName"),check.string(t,"eventName"),check.not.uon(e,"listener"),check.function(e,"listener"),this.context.events=this.context.events||[],this.context.events.push({eventName:t,listener:e})}onEventAt(t,e,n){check.not.uon(e,"eventName"),check.string(e,"eventName"),check.not.uon(n,"listener"),check.function(n,"listener"),this.context.eventsAt=this.context.eventsAt||[],this.context.eventsAt.push({selector:t,eventName:e,listener:n})}}class ZephElementClass{static generateClass(t){let e=null,n=[];return class extends HTMLElement{static get observedAttributes(){return t&&t.observed||[]}constructor(){super();let o=this;this[$ELEMENT]=o,this[$ATTRIBUTES]=null;let i=this.setAttribute,r=this.getAttribute;this.setAttribute=((t,e)=>(check.string(t),check.not.empty(t),this[$ATTRIBUTES]=this[$ATTRIBUTES]||{},this[$ATTRIBUTES][t]=e,i.call(o,t,e))),this.getAttribute=((t,e=!1)=>(check.string(t),check.not.empty(t),e&&this[$ATTRIBUTES]&&void 0!==this[$ATTRIBUTES][t]?this[$ATTRIBUTES][t]:r.call(o,t)));let s=null;t.disableShadowRoot||(s=this.shadowRoot||this.attachShadow({mode:"open"})),this[$SHADOW]=s,(t.html||[]).forEach(e=>{let n=e.template,i=e.options,r=document.importNode(n.content,!0);s?(i.overwrite&&(s.innerHTML=""),s.appendChild(r)):(i.overwrite&&(o.innerHTML=""),t.defer=t.defer||[],t.defer.push(()=>{o.appendChild(r)}))});let c=[];(t.css||[]).forEach(t=>{let e=t.template;t.options.overwrite&&c.forEach(t=>{[...t.children].forEach(t=>{t.remove()})});let n=document.importNode(e.content,!0);if(c.push(n),s)s.appendChild(n);else{n[$CONTEXT]=t;let e=document.head;[...e.querySelectorAll("style")].find(e=>e[$CONTEXT]===t)||e.appendChild(n)}}),t.assets&&t.assets.forEach(t=>{let e=t.data,n=t.contentType,i="."===t.selector&&[o]||s&&[...s.querySelectorAll(t.selector)]||[],r="data:"+n+";base64,"+e,c="url('"+r+"')",l=t.options&&t.options.target||"src",a=n.replace(/^([^/]+)\/.*$/g,"$1");i.forEach(t=>{let e=t.tagName.toLowerCase();"image"===a&&"img"!==e?t.style.backgroundImage=c:t.setAttribute(l,r)})}),n.push({element:o,shadow:s,context:t}),e||(e=setTimeout(()=>{let t=n;n=[],e=null,t.forEach(({element:t,shadow:e,context:n})=>{zephPopulateElement(t,e,n)})},0))}get element(){return this[$ELEMENT]}get content(){return this[$SHADOW]}connectedCallback(){fire(t&&t.lifecycle&&t.lifecycle.add||[],this,this.shadowRoot)}disconnectedCallback(){fire(t&&t.lifecycle&&t.lifecycle.remove||[],this,this.shadowRoot)}adoptedCallback(){fire(t&&t.lifecycle&&t.lifecycle.adopt||[],this,this.shadowRoot)}attributeChangedCallback(e,n,o){fire(t&&t.lifecycle&&t.lifecycle.attributes&&t.lifecycle.attributes[e]||[],n,o,this,this.shadowRoot)}}}}const zephPopulateElement=function(t,e,n){if(n.defer&&n.defer.forEach(t=>t()),n.attributes&&Object.values(n.attributes).forEach(e=>{let n=t.hasAttribute(e.attributeName)?t.getAttribute(e.attributeName):e.initialValue;null==n?t.removeAttribute(e.attributeName):t.setAttribute(e.attributeName,e.transformFunction?e.transformFunction(n):n)}),n.properties&&Object.values(n.properties).forEach(n=>{let o=void 0!==t[n.propertyName]?t[n.propertyName]:n.initialValue;propetize(t,n.propertyName,{get:t=>t?t():o,set:(i,r)=>{i=n.transformFunction?n.transformFunction(i):i,r&&(i=r(i)),o=i,(n.changes||[]).forEach(o=>{o(n.propertyName,i,t,e)})}}),t[n.propertyName]=void 0===t[n.propertyName]?n.initialValue:t[n.propertyName]}),n.methods&&Object.values(n.methods).forEach(n=>{n&&n.methodName&&n.methodFunction&&(t[n.methodName]=n.methodFunction.bind(t,t,e))}),n.lifecycle&&n.lifecycle.content&&n.lifecycle.content.length>0){t[$OBSERVER]||(t[$OBSERVER]=new ZephObserver(t),t[$OBSERVER].start()),t[$OBSERVER].addContentObserver(()=>{fire(n&&n.lifecycle&&n.lifecycle.content||[],t,e)})}fireImmediately(n&&n.lifecycle&&n.lifecycle.create||[],t,e),n.bindings&&Object.keys(n.bindings).forEach(o=>{let i=n.bindings[o];if(!i)return;let r=i.source.element;"."===r?r=[t]:"string"==typeof r?r=[...e.querySelectorAll(r)]:r instanceof HTMLElement&&(r=[r]);let s=i.source.name,c=i.target.element;"."===c&&(c=t);let l=i.target.name,a=i.transform;r.forEach(o=>{let i;if(l.startsWith("@"))i=(o=>{let i=l.slice(1);o=a(o),(c instanceof HTMLElement&&[c]||n.disableShadowRoot&&[...t.querySelectorAll(c)]||[...e.querySelectorAll(c)]||[]).forEach(t=>{void 0===o?t.removeAttribute(i):t.getAttribute(i)!==o&&t.setAttribute(i,o)})});else if(l.startsWith("."))i=(o=>{let i=l.slice(1);o=a(o),(c instanceof HTMLElement&&[c]||n.disableShadowRoot&&[...t.querySelectorAll(c)]||[...e.querySelectorAll(c)]||[]).forEach(t=>{void 0===o?delete t[i]:t[i]!==o&&(t[i]=o)})});else{if("$"!==l)return void console.warn("Unable to handle binding to '"+l+"'; Must start with '@' or '$' or '.'.");i=(o=>{if(void 0===(o=a(o)))return;(c instanceof HTMLElement&&[c]||n.disableShadowRoot&&[...t.querySelectorAll(c)]||[...e.querySelectorAll(c)]||[]).forEach(t=>{t.textContent!==o&&(t.textContent=null==o?"":o)})})}o[$OBSERVER]||(o[$OBSERVER]=new ZephObserver(o),o[$OBSERVER].start());let r=o[$OBSERVER];if(s.startsWith("@")){let t=s.slice(1);if(o.hasAttribute(t)){let e=o.getAttribute(t);i(e,t,o)}r.addAttributeObserver(t,i)}else if(s.startsWith(".")){let o=s.slice(1);if(n.properties=n.properties||{},!n.properties[o]){n.properties[o]={propertyName:o,changes:[],value:t[o]};let i=n.properties[o];propetize(t,o,{get:t=>t?t():i.value,set:(n,o)=>{let r=i.transformFunction?i.transformFunction(n):n;o&&o(r),i.value=r,(i.changes||[]).forEach(n=>{n(i.propertyName,r,t,e)})}})}let r=n.properties[o];r.changes=r.changes||[],r.changes.push((t,e)=>{i(e)})}else{if("$"!==s)return void console.warn("Unable to handle binding to '"+l+"'; Must start with '@' or '$' or '.'.");{let t=o.textContent;i(t,null,o),r.addContentObserver(i)}}})}),n.events&&n.events.forEach(n=>{t.addEventListener(n.eventName,o=>{n.listener.call(t,o,t,e)})}),n.eventsAt&&n.eventsAt.forEach(o=>{(n.disableShadowRoot&&[...t.querySelectorAll(o.selector)]||[...e.querySelectorAll(o.selector)]||[]).forEach(n=>{n.addEventListener(o.eventName,i=>{o.listener.call(n,i,n,t,e)})})})};class ZephObserver{constructor(t){if(!t)throw new Error("Missing element.");if(!(t instanceof HTMLElement))throw new Error("Invalid element; must be an instance of HTMLElement.");this.element=t,this.attributes={},this.content=[],this.observer=new MutationObserver(this.handleMutation.bind(this))}addAttributeObserver(t,e){check.not.uon(t,"attribute"),check.string(t,"attribute"),check.not.uon(e,"handler"),check.function(e,"handler"),this.attributes[t]=this.attributes[t]||[],this.attributes[t].push(e)}removeAttributeObserver(t,e){check.not.uon(t,"attribute"),check.string(t,"attribute"),check.not.uon(e,"handler"),check.function(e,"handler"),this.attributes[t]&&(this.attributes[t]=this.attributes[t].filter(t=>t!==e),this.attributes[t].length<1&&delete this.attributes[t])}removeAllAttributeObservers(t){if(t&&"string"!=typeof t)throw new Error("Invalid attribute; must be a string.");t?delete this.attributes[t]:this.attributes={}}addContentObserver(t){check.not.uon(t,"handler"),check.function(t,"handler"),this.content.push(t)}removeContentObserver(t){check.not.uon(t,"handler"),check.function(t,"handler"),this.content=this.content.filter(e=>e!==t)}removeAllContentObservers(){this.content=[]}start(){this.observer.observe(this.element,{attributes:!0,characterData:!0,childList:!0})}stop(){this.observer.disconnect()}handleMutation(t){t.forEach(t=>{"attributes"===t.type?this.handleAttributeMutation(t):this.handleContentMutation(t)})}handleAttributeMutation(t){let e=t.attributeName;if(!this.attributes[e]||this.attributes[e].length<1)return;let n=this.element.hasAttribute(e)?this.element.getAttribute(e):void 0;this.attributes[e]&&this.attributes[e].forEach(t=>{t(n,e,this.element)}),this.attributes["*"]&&this.attributes["*"].forEach(t=>{t(n,e,this.element)})}handleContentMutation(){if(this.content.length<1)return;let t=this.element.textContent;this.content.forEach(e=>{e(t,this.element)})}}class ZephComponentsClass{constructor(){this[$COMPONENTS]={},this[$PROXY]=new Proxy(this[$COMPONENTS],{has:(t,e)=>!!t[e],get:(t,e)=>t[e]||void 0,ownKeys:t=>Object.keys(t)}),this[$OBSERVER]=[]}get components(){return this[$PROXY]}get names(){return Object.keys(this[$COMPONENTS])}has(t){return check.posstr(t,"name"),!!this[$COMPONENTS][t]}get(t){return check.posstr(t,"name"),this[$COMPONENTS][t]}waitFor(t){return check.posstr(t,"name"),this[$COMPONENTS][t]?Promise.resolve():new Promise((e,n)=>{this[$OBSERVER].push({name:t,resolve:e,reject:n})})}define(t,e){if(check.posstr(t,"name"),check.not.uon(e,"code"),check.function(e,"code"),this[$COMPONENTS][t])throw new Error("Component already defined.");let n=document.URL.toString(),o=new Error;if(o.fileName&&(n=o.filename),o.stack){for(o=(o=o.stack.split(/\r\n|\n/g)).reverse();o.length>0;){let t=o.shift();if(t&&t.match(/\w+:/g)){o=t=(t=t.trim().replace(/^.*?(?=\w+:)/,"")).replace(/:\d+$|:\d+\)$|:\d+:\d+$|:\d+:\d+\)$/,"");break}}n=o}return PENDING["component:"+n]=!0,document.dispatchEvent(new CustomEvent("zeph:component:loading",{bubbles:!1,detail:t})),utils.tryprom(async o=>{let i=new ZephComponent(t,n,e);this[$COMPONENTS][t]=i,await i.define(),this[$OBSERVER]=this[$OBSERVER].filter(e=>(e.name===t&&e.resolve(),e.name!==t)),delete PENDING["component:"+n],document.dispatchEvent(new CustomEvent("zeph:component:defined",{bubbles:!1,detail:{name:t,component:i}})),fireZephReady(),o(i)})}undefine(t){check.posstr(t,"name");let e=this[$COMPONENTS][t];e&&(delete this[$COMPONENTS][t],document.dispatchEvent(new CustomEvent("zeph:component:undefined",{bubbles:!1,detail:{name:t,component:e}})))}}class ZephService{constructor(){this[$LISTENERS]=new Map}fire(t,...e){(this[$LISTENERS].get(t)||[]).forEach(n=>{setTimeout(()=>{n.apply(n,[t,...e])},0)})}addEventListener(t,e){let n=this[$LISTENERS].get(t)||[];n.push(e),this[$LISTENERS].set(t,n)}removeEventListener(t,e){let n=this[$LISTENERS].get(t)||[];n=n.filter(t=>t!==e),this[$LISTENERS].set(t,n)}on(t,e){return this.addEventListener(t,e)}once(t,e){return this.addEventListner(t,(t,...n)=>{this.removeEventListener(t,e),e.apply(e,n)})}off(t,e){return this.removeEventListener(t,e)}}const extend=function t(e,...n){return null==e&&(e={}),n.forEach(n=>{Object.keys(n).forEach(o=>{let i=n[o],r=e[o];void 0!==i&&(null===i?e[o]=null:i instanceof Promise?e[o]=i:i instanceof Function?e[o]=i:i instanceof RegExp?e[o]=i:i instanceof Date?e[o]=new Date(i):i instanceof Array?e[o]=[].concat(r||[],i):e[o]="object"==typeof i?t(r,i):i)})}),e},fire=function(t,...e){(t=t&&!(t instanceof Array)&&[t]||t||[]).forEach(t=>{setTimeout(()=>t.apply(t,e),0)})},fireImmediately=function(t,...e){(t=t&&!(t instanceof Array)&&[t]||t||[]).forEach(t=>t.apply(t,e))},fireZephReady=function(){FIREREADY&&clearTimeout(FIREREADY),FIREREADY=setTimeout(()=>{Object.keys(PENDING).length<1&&(READY=!0,document.dispatchEvent(new CustomEvent("zeph:ready",{bubbles:!1})))},10)},getPropertyDescriptor=function(t,e){for(;;){if(null===t)return null;let n=Object.getOwnPropertyDescriptor(t,e);if(n)return n;t=Object.getPrototypeOf(t)}},propetize=function(t,e,n){check.not.uon(t,"object"),check.not.uon(e,"propertyName"),check.string(e,"propertyName"),check.not.uon(n,"descriptor");let o=getPropertyDescriptor(t,e),i=Object.assign({},o||{},n);return o&&n.get&&(delete i.value,delete i.writable,i.get=(()=>{let t=o.get||null;return n.get(t)})),o&&n.set&&(delete i.writable,i.set=(t=>{let e=o.set||null;return n.set(t,e)})),Object.defineProperty(t,e,i),i},contextCall=function(t){return check.posstr(t,"name"),{[t]:function(){if(!CODE_CONTEXT)throw new Error(t+"() may only be used within the ZephComponent.define() method.");return CODE_CONTEXT[t].apply(CODE_CONTEXT,arguments)}}[t]},from=contextCall("from"),inline=contextCall("inline"),alias=contextCall("alias"),html=contextCall("html"),css=contextCall("css"),asset=contextCall("asset"),attribute=contextCall("attribute"),property=contextCall("property"),method=contextCall("method"),bind=contextCall("binding"),bindAt=contextCall("bindingAt"),onInit=contextCall("onInit"),onCreate=contextCall("onCreate"),onAdd=contextCall("onAdd"),onRemove=contextCall("onRemove"),onAdopt=contextCall("onAdopt"),onContent=contextCall("onContent"),onAttribute=contextCall("onAttribute"),onProperty=contextCall("onProperty"),onEvent=contextCall("onEvent"),onEventAt=contextCall("onEventAt"),ZephComponents=new ZephComponentsClass;export{ZephComponents,ZephObserver,ZephService,utils as ZephUtils};export{from,inline,alias,html,css,asset,attribute,property,method,bind,bindAt,onInit,onCreate,onAdd,onRemove,onAdopt,onContent,onAttribute,onProperty,onEvent,onEventAt};window.Zeph={ZephComponents:ZephComponents,ZephObserver:ZephObserver,ZephService:ZephService,ZephUtils:utils},DEFINITION_METHODS={inline:inline,from:from,alias:alias,html:html,css:css,asset:asset,attribute:attribute,property:property,method:method,bind:bind,bindAt:bindAt,onInit:onInit,onCreate:onCreate,onAdd:onAdd,onRemove:onRemove,onAdopt:onAdopt,onContent:onContent,onAttribute:onAttribute,onProperty:onProperty,onEvent:onEvent,onEventAt:onEventAt};