var ZeroMd=function(t){"use strict";function e(t,e,n){return e=f(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return p(t)}(t,r()?Reflect.construct(e,n||[],f(t).constructor):e.apply(t,n))}function r(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(r=function(){return!!t})()}function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function o(t){for(var e=1;e=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),m}},e}function a(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function c(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function u(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){c(i,n,o,a,u,"next",t)}function u(t){c(i,n,o,a,u,"throw",t)}a(void 0)}))}}function s(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r
'))),i.constructor.ready||(i.constructor.ready=Promise.all([!!window.marked||i.loadScript(i.config.markedUrl),!!window.Prism||i.loadScript(i.config.prismUrl)])),i.clicked=i.clicked.bind(p(i)),i.manualRender||i.render().then((function(){return setTimeout((function(){return i.goto(location.hash)}),250)})),i.observer=new MutationObserver((function(){i.observeChanges(),i.manualRender||i.render()})),i.observer.observe(p(i),{childList:!0}),i.observeChanges(),i}var n,a,c,l,f,d,m;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&h(t,e)}(r,t),n=r,a=[{key:"src",get:function(){return this.getAttribute("src")},set:function(t){this.reflect("src",t)}},{key:"manualRender",get:function(){return this.hasAttribute("manual-render")},set:function(t){this.reflect("manual-render",t)}},{key:"reflect",value:function(t,e){!1===e?this.removeAttribute(t):this.setAttribute(t,!0===e?"":e)}},{key:"attributeChangedCallback",value:function(t,e,r){"src"===t&&this.connected&&!this.manualRender&&r!==e&&this.render()}},{key:"observeChanges",value:function(){var t=this;this.querySelectorAll('template,script[type="text/markdown"]').forEach((function(e){t.observer.observe(e.content||e,{childList:!0,subtree:!0,attributes:!0,characterData:!0})}))}},{key:"connectedCallback",value:function(){var t=this;this.connected=!0,this.fire("zero-md-connected",{},{bubbles:!1,composed:!1}),this.waitForReady().then((function(){t.fire("zero-md-ready")})),this.shadowRoot&&this.shadowRoot.addEventListener("click",this.clicked)}},{key:"disconnectedCallback",value:function(){this.connected=!1,this.shadowRoot&&this.shadowRoot.removeEventListener("click",this.clicked)}},{key:"waitForReady",value:function(){var t=this,e=this.connected||new Promise((function(e){t.addEventListener("zero-md-connected",(function t(){this.removeEventListener("zero-md-connected",t),e()}))}));return Promise.all([this.constructor.ready,e])}},{key:"fire",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{bubbles:!0,composed:!0};e.msg&&console.warn(e.msg),this.dispatchEvent(new CustomEvent(t,o({detail:o({node:this},e)},r)))}},{key:"tick",value:function(){return new Promise((function(t){return requestAnimationFrame(t)}))}},{key:"arrify",value:function(t){return t?Array.isArray(t)?t:[t]:[]}},{key:"onload",value:function(t){return new Promise((function(e,r){t.onload=e,t.onerror=function(t){return r(t.path?t.path[0]:t.composedPath()[0])}}))}},{key:"loadScript",value:function(t){var e=this;return Promise.all(this.arrify(t).map((function(t){var r=y(e.arrify(t)),n=r[0],o=r.slice(1),i=document.createElement("script");return i.src=n,i.async=!1,o.forEach((function(t){return i.setAttribute(t,"")})),e.onload(document.head.appendChild(i))})))}},{key:"goto",value:function(t){var e;try{e=this.root.querySelector(t)}catch(t){}e&&e.scrollIntoView()}},{key:"clicked",value:function(t){if(!(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey||t.defaultPrevented)){var e=t.target.closest("a");e&&e.hash&&e.host===location.host&&e.pathname===location.pathname&&this.goto(e.hash)}}},{key:"dedent",value:function(t){var e=(t=t.replace(/^\n/,"")).match(/^\s+/);return e?t.replace(new RegExp("^".concat(e[0]),"gm"),""):t}},{key:"getBaseUrl",value:function(t){var e=document.createElement("a");return e.href=t,e.href.substring(0,e.href.lastIndexOf("/")+1)}},{key:"highlight",value:function(t){return new Promise((function(e){t.querySelectorAll('pre>code:not([class*="language-"])').forEach((function(t){var e=t.innerText.match(/^\s*".concat(this.config.hostCss,"").concat(e('template[data-merge="prepend"]')).concat(e("template:not([data-merge])")||r.reduce((function(t,e){return"".concat(t,'')}),"")).concat(e('template[data-merge="append"]'))}},{key:"buildMd",value:(m=u(i().mark((function t(){var e,r,n,a=this,c=arguments;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=c.length>0&&void 0!==c[0]?c[0]:{},r=function(){var t=u(i().mark((function t(){var r,n;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(a.src){t.next=2;break}return t.abrupt("return","");case 2:return t.next=4,fetch(a.src);case 4:if(!(r=t.sent).ok){t.next=12;break}return t.next=8,r.text();case 8:return n=t.sent,t.abrupt("return",window.marked.parse(n,o({baseUrl:a.getBaseUrl(a.src)},e)));case 12:return a.fire("zero-md-error",{msg:"[zero-md] HTTP error ".concat(r.status," while fetching src"),status:r.status,src:a.src}),t.abrupt("return","");case 14:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),n=function(){var t=a.querySelector('script[type="text/markdown"]');if(!t)return"";var r=t.hasAttribute("data-dedent")?a.dedent(t.text):t.text;return window.marked.parse(r,e)},t.next=5,r();case 5:if(t.t0=t.sent,t.t0){t.next=8;break}t.t0=n();case 8:return t.abrupt("return",t.t0);case 9:case"end":return t.stop()}}),t)}))),function(){return m.apply(this,arguments)})},{key:"getHash",value:function(t){for(var e=5381,r=0;r>>0).toString(36)}},{key:"stampStyles",value:(d=u(i().mark((function t(e){var r,n,o,a,c=this;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.getHash(e),(n=this.root.querySelector(".markdown-styles")).getAttribute("data-hash")===r){t.next=11;break}return n.setAttribute("data-hash",r),o=this.makeNodes(e),a=v(o).filter((function(t){return"LINK"===t.tagName&&"stylesheet"===t.getAttribute("rel")})),n.innerHTML="",n.append.apply(n,v(o)),t.next=10,Promise.all(a.map((function(t){return c.onload(t)}))).catch((function(t){c.fire("zero-md-error",{msg:"[zero-md] An external stylesheet failed to load",status:void 0,src:t.href})}));case 10:return t.abrupt("return",!0);case 11:case"end":return t.stop()}}),t,this)}))),function(t){return d.apply(this,arguments)})},{key:"stampBody",value:(f=u(i().mark((function t(e,r){var n,o,a,c;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.arrify(r),o=this.getHash(e+JSON.stringify(n)),(a=this.root.querySelector(".markdown-body")).getAttribute("data-hash")===o){t.next=13;break}return a.setAttribute("data-hash",o),n.unshift("markdown-body"),a.setAttribute("class",n.join(" ")),c=this.makeNodes(e),a.innerHTML="",a.append.apply(a,v(c)),t.next=12,this.highlight(a);case 12:return t.abrupt("return",!0);case 13:case"end":return t.stop()}}),t,this)}))),function(t,e){return f.apply(this,arguments)})},{key:"render",value:(l=u(i().mark((function t(){var e,r,n,o,a=arguments;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=a.length>0&&void 0!==a[0]?a[0]:{},t.next=3,this.waitForReady();case 3:return r=this.buildMd(e),t.next=6,this.stampStyles(this.buildStyles());case 6:return n=t.sent,t.next=9,this.tick();case 9:return t.t0=this,t.next=12,r;case 12:return t.t1=t.sent,t.t2=e.classes,t.next=16,t.t0.stampBody.call(t.t0,t.t1,t.t2);case 16:o=t.sent,this.fire("zero-md-rendered",{node:this,stamped:{styles:n,body:o}});case 18:case"end":return t.stop()}}),t,this)}))),function(){return l.apply(this,arguments)})}],c=[{key:"observedAttributes",get:function(){return["src"]}}],a&&s(n.prototype,a),c&&s(n,c),Object.defineProperty(n,"prototype",{writable:!1}),r}(d(HTMLElement));return customElements.define("zero-md",w),t.ZeroMd=w,t}({}); //# sourceMappingURL=zero-md.legacy.min.js.map