-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsnuggsi.min.js
1 lines (1 loc) · 4.3 KB
/
snuggsi.min.js
1
var TokenList=function(t){for(var e=this,n=function(t){return/{(\w+|#)}/.test(t.textContent)&&(t.text=t.textContent).match(/[^{]+(?=})/g).map(function(n){return(e[n]||(e[n]=[])).push(t)})},r=document.createNodeIterator(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,function(t){return t.attributes&&[].slice.call(t.attributes).map(n)||n(t)},null);r.nextNode(););};TokenList.prototype.bind=function(t){var e=function(e){return function(n){return n.textContent=n.text.split("{"+e+"}").join(t[e])}};for(var n in this)console.log("context",n);for(var r in this)"bind"!=r&&this[r].map(e(r))},function(t){function e(t){var e=new XMLHttpRequest;e.link=t,e.onload=n,e.open("GET",t.href),e.responseType="document",e.send()}function n(){for(var t=this.link,e=this.response,n=t.nextChild,i=t.content=e.querySelector("template"),s=0,c=document.querySelectorAll(t.id);s<c.length;s+=1){var l=c[s];i&&o.call(l,i)}for(var a=0,u=e.querySelectorAll("style,link,script");a<u.length;a+=1){r(t,u[a],n)}}function r(t,e,n){var r=e.getAttribute("as"),o=document.createElement("script"==r?r:e.localName);["id","rel","href","src","textContent","as","defer","crossOrigin"].map(function(t){return e[t]&&t in o&&(o[t]=e[t])}),"style"==r&&(o.rel="stylesheet"),"script"==r&&(o.src=o.href),t.parentNode.insertBefore(o,n)}function o(t){var e,n=this;t=document.importNode(t,!0),[].slice.call(t.attributes).map(function(t){return!n.attributes[t.name]&&n.setAttribute(t.name,t.value)});for(var r=0,o=this.querySelectorAll("[slot]");r<o.length;r+=1){var i=o[r];(e=(t.content||t).querySelector("slot[name="+i.getAttribute("slot")+"]"))&&e.parentNode.replaceChild(i,e)}return this.innerHTML=t.innerHTML}new MutationObserver(function(t){for(var n=0,r=t;n<r.length;n+=1)for(var i=0,s=r[n].addedNodes;i<s.length;i+=1){var c=s[i];/^p/.test(c.rel)&&/\-/.test(c.id)&&e(c),/\-/.test(c.localName)&&(link=document.querySelector("#"+c.localName))&&link.content&&o.call(c,link.content)&&customElements.upgrade(c)}}).observe(document.documentElement,{childList:!0,subtree:!0}),[].slice.call(document.querySelectorAll('[rel^=pre][id~="-"]')).map(e)}();var Template=function(t){var e=document.createRange();t="string"==typeof t?document.querySelector("template[name="+t+"]"):t,e.selectNodeContents(t.content);var n=e.cloneContents(),r=function(t,e){var r=n.cloneNode(!0);return"object"!=typeof t&&(t={self:t}),t["#"]=e,new TokenList(r).bind(t),r};return e.setStartAfter(t),t.bind=function(t){e.deleteContents(),t&&[].concat(t).map(r).reverse().map(function(t){return e.insertNode(t)})},t};function ParentNode(t){return t.prototype.select=function(){var t;return(t=this).selectAll.apply(t,arguments)[0]},t.prototype.selectAll=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return t=[].concat(t),[].slice.call(this.querySelectorAll(e.reduce(function(e,n){return 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(var r=0,o=[].slice.call(t.attributes);r<o.length;r+=1){var i=o[r];/^on/.test(n=i.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){var e=this;return function(n){return!1!==t.call(e,n)&&n.defaultPrevented||e.render()}},t}function Custom(t){return(t=EventTarget(ParentNode(t))).prototype.render=function(){for(var t=0,e=this.templates;t<e.length;t+=1){var n=e[t];n.bind(this[n.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}var Element=function(t){return function(e){return customElements.define(t+"",Custom(e))}};