-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsnuggsi.min.es.js
1 lines (1 loc) · 3.8 KB
/
snuggsi.min.es.js
1
class TokenList{constructor(t){const e=t=>/{(\w+|#)}/.test(t.textContent)&&(t.text=t.textContent).match(/[^{]+(?=})/g).map(e=>(this[e]||(this[e]=[])).push(t)),n=document.createNodeIterator(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,t=>t.attributes&&[].slice.call(t.attributes).map(e)||e(t),null);for(;n.nextNode(););}bind(t){const e=e=>n=>n.textContent=n.text.split("{"+e+"}").join(t[e]);for(let n in this)console.log("context",n);for(let n in this)"bind"!=n&&this[n].map(e(n))}}(t=>{function e(t){let e=new XMLHttpRequest;e.link=t,e.onload=n,e.open("GET",t.href),e.responseType="document",e.send()}function n(){let t=this.link,e=this.response,n=t.nextChild,i=t.content=e.querySelector("template");for(let o of document.querySelectorAll(t.id))i&&s.call(o,i);for(let s of e.querySelectorAll("style,link,script"))o(t,s,n)}function o(t,e,n){let o=e.getAttribute("as"),s=document.createElement("script"==o?o:e.localName);["id","rel","href","src","textContent","as","defer","crossOrigin"].map(t=>e[t]&&t in s&&(s[t]=e[t])),"style"==o&&(s.rel="stylesheet"),"script"==o&&(s.src=s.href),t.parentNode.insertBefore(s,n)}function s(t){let e;t=document.importNode(t,!0),[].slice.call(t.attributes).map(t=>!this.attributes[t.name]&&this.setAttribute(t.name,t.value));for(let n of this.querySelectorAll("[slot]"))(e=(t.content||t).querySelector("slot[name="+n.getAttribute("slot")+"]"))&&e.parentNode.replaceChild(n,e);return this.innerHTML=t.innerHTML}new MutationObserver(t=>{for(let n of t)for(let t of n.addedNodes)/^p/.test(t.rel)&&/\-/.test(t.id)&&e(t),/\-/.test(t.localName)&&(link=document.querySelector("#"+t.localName))&&link.content&&s.call(t,link.content)&&customElements.upgrade(t)}).observe(document.documentElement,{childList:!0,subtree:!0}),[].slice.call(document.querySelectorAll('[rel^=pre][id~="-"]')).map(e)})();const Template=t=>{let e=document.createRange();t="string"==typeof t?document.querySelector("template[name="+t+"]"):t,e.selectNodeContents(t.content);let n=e.cloneContents(),o=(t,e)=>{let o=n.cloneNode(!0);return"object"!=typeof t&&(t={self:t}),t["#"]=e,new TokenList(o).bind(t),o};return e.setStartAfter(t),t.bind=(t=>{e.deleteContents(),t&&[].concat(t).map(o).reverse().map(t=>e.insertNode(t))}),t};function ParentNode(t){return t.prototype.select=function(){return this.selectAll(...arguments)[0]},t.prototype.selectAll=function(t,...e){return t=[].concat(t),[].slice.call(this.querySelectorAll(e.reduce((e,n)=>e+n+t.shift(),t.shift())))},t}function EventTarget(t){return t.prototype.dispatch=function(t){this.dispatchEvent(new Event(t))},t.prototype.register=function(t,e,n){for(let o of[].slice.call(t.attributes))/^on/.test(n=o.name)&&(e=(/{\s(\w+)\s}/.exec(t[n])||[])[1])&&(t[n]=this.renderable(this[e]))},t.prototype.on=function(t,e){this.addEventListener(t,this.renderable(e))},t.prototype.reflect=function(t){/^on/.test(t)&&t in HTMLElement.prototype&&this.on(t.substr(2),this[t])},t.prototype.renderable=function(t){return e=>!1!==t.call(this,e)&&e.defaultPrevented||this.render()},t}function Custom(t){return(t=EventTarget(ParentNode(t))).prototype.render=function(){for(let t of this.templates)t.bind(this[t.getAttribute("name")]);this.tokens.bind(this),this.register(this),this.selectAll("*").map(this.register,this),this.dispatch("idle")},t.prototype.connectedCallback||(t.prototype.connectedCallback=function(){this.context={},this.initialize&&this.initialize(),Object.getOwnPropertyNames(t.prototype).map(this.reflect,this),this.addEventListener("connect",this.onconnect),this.dispatch("connect"),this.templates=this.selectAll("template[name]").map(Template),this.tokens=new TokenList(this),this.addEventListener("idle",this.onidle),this.render()}),t.prototype.disconnectedCallback||(t.prototype.disconnectedCallback=function(){this.ondisconnect&&this.ondisconnect(),this.dispatch("disconnect")}),t}const Element=t=>e=>customElements.define(t+"",Custom(e));