Astroport.ONE/templates/UPlanetRegion/zero-md.min.js.map

1 line
18 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"zero-md.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(`<div class=\"markdown-styles\"></div><div class=\"markdown-body\"></div>`)\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 re