From eafb72ec2d675e9a112b5657e1fb071f95bd50ca Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Sun, 25 Feb 2024 15:38:06 +0800 Subject: [PATCH] Build `dist` --- dist/zero-md.legacy.min.js | 2 +- dist/zero-md.legacy.min.js.map | 2 +- dist/zero-md.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/zero-md.legacy.min.js b/dist/zero-md.legacy.min.js index 5e90614..5113707 100644 --- a/dist/zero-md.legacy.min.js +++ b/dist/zero-md.legacy.min.js @@ -1,2 +1,2 @@ -var ZeroMd=function(t){"use strict";function e(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 r(t){for(var r=1;r=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),h}},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;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function o(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 i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r
'))),n.constructor.ready||(n.constructor.ready=Promise.all([!!window.marked||n.loadScript(n.config.markedUrl),!!window.Prism||n.loadScript(n.config.prismUrl)])),n.clicked=n.clicked.bind(d(n)),n.manualRender||n.render().then((function(){return setTimeout((function(){return n.goto(location.hash)}),250)})),n.observer=new MutationObserver((function(){n.observeChanges(),n.manualRender||n.render()})),n.observer.observe(d(n),{childList:!0}),n.observeChanges(),n}return e=b,o=[{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]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{bubbles:!0,composed:!0};e.msg&&console.warn(e.msg),this.dispatchEvent(new CustomEvent(t,r({detail:r({node:this},e)},n)))}},{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:(h=i(n().mark((function t(){var e,o,a,c=this,u=arguments;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=u.length>0&&void 0!==u[0]?u[0]:{},o=function(){var t=i(n().mark((function t(){var o,i;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(c.src){t.next=2;break}return t.abrupt("return","");case 2:return t.next=4,fetch(c.src);case 4:if(!(o=t.sent).ok){t.next=12;break}return t.next=8,o.text();case 8:return i=t.sent,t.abrupt("return",window.marked.parse(i,r({baseUrl:c.getBaseUrl(c.src)},e)));case 12:return c.fire("zero-md-error",{msg:"[zero-md] HTTP error ".concat(o.status," while fetching src"),status:o.status,src:c.src}),t.abrupt("return","");case 14:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),a=function(){var t=c.querySelector('script[type="text/markdown"]');if(!t)return"";var r=t.hasAttribute("data-dedent")?c.dedent(t.text):t.text;return window.marked.parse(r,e)},t.next=5,o();case 5:if(t.t0=t.sent,t.t0){t.next=8;break}t.t0=a();case 8:return t.abrupt("return",t.t0);case 9:case"end":return t.stop()}}),t)}))),function(){return h.apply(this,arguments)})},{key:"getHash",value:function(t){for(var e=5381,r=0;r>>0).toString(36)}},{key:"stampStyles",value:(f=i(n().mark((function t(e){var r,o,i,a,c=this;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.getHash(e),(o=this.root.querySelector(".markdown-styles")).getAttribute("data-hash")===r){t.next=11;break}return o.setAttribute("data-hash",r),i=this.makeNodes(e),a=v(i).filter((function(t){return"LINK"===t.tagName&&"stylesheet"===t.getAttribute("rel")})),o.innerHTML="",o.append.apply(o,v(i)),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 f.apply(this,arguments)})},{key:"stampBody",value:(l=i(n().mark((function t(e,r){var o,i,a,c;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=this.arrify(r),i=this.getHash(e+JSON.stringify(o)),(a=this.root.querySelector(".markdown-body")).getAttribute("data-hash")===i){t.next=13;break}return a.setAttribute("data-hash",i),o.unshift("markdown-body"),a.setAttribute("class",o.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 l.apply(this,arguments)})},{key:"render",value:(u=i(n().mark((function t(){var e,r,o,i,a=arguments;return n().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 o=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:i=t.sent,this.fire("zero-md-rendered",{node:this,stamped:{styles:o,body:i}});case 18:case"end":return t.stop()}}),t,this)}))),function(){return u.apply(this,arguments)})}],c=[{key:"observedAttributes",get:function(){return["src"]}}],o&&a(e.prototype,o),c&&a(e,c),Object.defineProperty(e,"prototype",{writable:!1}),b}(h(HTMLElement));return customElements.define("zero-md",k),t.ZeroMd=k,t}({}); +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 diff --git a/dist/zero-md.legacy.min.js.map b/dist/zero-md.legacy.min.js.map index b5cac32..70ba702 100644 --- a/dist/zero-md.legacy.min.js.map +++ b/dist/zero-md.legacy.min.js.map @@ -1 +1 @@ -{"version":3,"file":"zero-md.legacy.min.js","sources":["../src/index.js"],"sourcesContent":["export class ZeroMd extends HTMLElement {\n get src() {\n return this.getAttribute('src')\n }\n\n set src(val) {\n this.reflect('src', val)\n }\n\n get manualRender() {\n return this.hasAttribute('manual-render')\n }\n\n set manualRender(val) {\n this.reflect('manual-render', val)\n }\n\n reflect(name, val) {\n if (val === false) {\n this.removeAttribute(name)\n } else {\n this.setAttribute(name, val === true ? '' : val)\n }\n }\n\n static get observedAttributes() {\n return ['src']\n }\n\n attributeChangedCallback(name, old, val) {\n if (name === 'src' && this.connected && !this.manualRender && val !== old) {\n this.render()\n }\n }\n\n constructor(defaults) {\n super()\n this.version = '$VERSION'\n this.config = {\n markedUrl: 'https://cdn.jsdelivr.net/gh/markedjs/marked@4/marked.min.js',\n prismUrl: [\n ['https://cdn.jsdelivr.net/gh/PrismJS/prism@1/prism.min.js', 'data-manual'],\n 'https://cdn.jsdelivr.net/gh/PrismJS/prism@1/plugins/autoloader/prism-autoloader.min.js'\n ],\n cssUrls: [\n 'https://cdn.jsdelivr.net/gh/sindresorhus/github-markdown-css@4/github-markdown.min.css',\n 'https://cdn.jsdelivr.net/gh/PrismJS/prism@1/themes/prism.min.css'\n ],\n hostCss:\n ':host{display:block;position:relative;contain:content;}:host([hidden]){display:none;}',\n ...defaults,\n ...window.ZeroMdConfig\n }\n this.root = this.hasAttribute('no-shadow') ? this : this.attachShadow({ mode: 'open' })\n this.root.prepend(\n ...this.makeNodes(`
`)\n )\n if (!this.constructor.ready) {\n this.constructor.ready = Promise.all([\n !!window.marked || this.loadScript(this.config.markedUrl),\n !!window.Prism || this.loadScript(this.config.prismUrl)\n ])\n }\n this.clicked = this.clicked.bind(this)\n if (!this.manualRender) {\n // Scroll to hash id after first render. However, `history.scrollRestoration` inteferes with this\n // on refresh. It's much better to use a `setTimeout` rather than to alter the browser's behaviour.\n this.render().then(() => setTimeout(() => this.goto(location.hash), 250))\n }\n this.observer = new MutationObserver(() => {\n this.observeChanges()\n if (!this.manualRender) this.render()\n })\n this.observer.observe(this, { childList: true })\n this.observeChanges()\n }\n\n /**\n * Start observing changes, if not already so, in `template` and `script`.\n */\n observeChanges() {\n this.querySelectorAll('template,script[type=\"text/markdown\"]').forEach((n) => {\n this.observer.observe(n.content || n, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true\n })\n })\n }\n\n connectedCallback() {\n this.connected = true\n this.fire('zero-md-connected', {}, { bubbles: false, composed: false })\n this.waitForReady().then(() => {\n this.fire('zero-md-ready')\n })\n if (this.shadowRoot) {\n this.shadowRoot.addEventListener('click', this.clicked)\n }\n }\n\n disconnectedCallback() {\n this.connected = false\n if (this.shadowRoot) {\n this.shadowRoot.removeEventListener('click', this.clicked)\n }\n }\n\n waitForReady() {\n const ready =\n this.connected ||\n new Promise((resolve) => {\n this.addEventListener('zero-md-connected', function handler() {\n this.removeEventListener('zero-md-connected', handler)\n resolve()\n })\n })\n return Promise.all([this.constructor.ready, ready])\n }\n\n fire(name, detail = {}, opts = { bubbles: true, composed: true }) {\n if (detail.msg) {\n console.warn(detail.msg)\n }\n this.dispatchEvent(\n new CustomEvent(name, {\n detail: { node: this, ...detail },\n ...opts\n })\n )\n }\n\n tick() {\n return new Promise((resolve) => requestAnimationFrame(resolve))\n }\n\n // Coerce anything into an array\n arrify(any) {\n return any ? (Array.isArray(any) ? any : [any]) : []\n }\n\n // Promisify an element's onload callback\n onload(node) {\n return new Promise((resolve, reject) => {\n node.onload = resolve\n node.onerror = (err) => reject(err.path ? err.path[0] : err.composedPath()[0])\n })\n }\n\n // Load a url or load (in order) an array of urls via