mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-27 07:34:59 +05:00
1 line
16 KiB
Text
1 line
16 KiB
Text
|
{"version":3,"file":"zero-md.min.js","sources":["../src/index.js"],"sourcesContent":["export class ZeroMd extends HTMLElement {\n get src () { return this.getAttribute('src') }\n set src (val) { this.reflect('src', val) }\n get manualRender () { return this.hasAttribute('manual-render') }\n set manualRender (val) { this.reflect('manual-render', val) }\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@2/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: ':host{display:block;position:relative;contain:content;}:host([hidden]){display:none;}',\n ...defaults,\n ...window.ZeroMdConfig\n }\n this.cache = {}\n this.root = this.hasAttribute('no-shadow') ? this : this.attachShadow({ mode: 'open' })\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 on refresh.\n // 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(async () => {\n this.observeChanges()\n if (!this.manualRender) {\n await this.render()\n }\n })\n this.observeChanges()\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 = this.connected || 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(new CustomEvent(name, {\n detail: { node: this, ...detail },\n ...opts\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 <script> tags\n loadScript (urls) {\n return Promise.all(this.arrify(urls).map(item => {\n const [ur
|