UNPKG

smartdown

Version:

A library for translating, rendering and interacting with Smartdown documents. Smartdown is an extension of Markdown that provides richer media support and reactive programming capability.

2 lines 18.6 kB
/*! For license information please see webcomponents-ce.js.LICENSE.txt */ (function(){"use strict";var t=window.Document.prototype.createElement,e=window.Document.prototype.createElementNS,n=window.Document.prototype.importNode,o=window.Document.prototype.prepend,r=window.Document.prototype.append,i=window.DocumentFragment.prototype.prepend,l=window.DocumentFragment.prototype.append,a=window.Node.prototype.cloneNode,c=window.Node.prototype.appendChild,s=window.Node.prototype.insertBefore,u=window.Node.prototype.removeChild,h=window.Node.prototype.replaceChild,d=Object.getOwnPropertyDescriptor(window.Node.prototype,"textContent"),f=window.Element.prototype.attachShadow,p=Object.getOwnPropertyDescriptor(window.Element.prototype,"innerHTML"),m=window.Element.prototype.getAttribute,y=window.Element.prototype.setAttribute,w=window.Element.prototype.removeAttribute,g=window.Element.prototype.toggleAttribute,v=window.Element.prototype.getAttributeNS,E=window.Element.prototype.setAttributeNS,b=window.Element.prototype.removeAttributeNS,_=window.Element.prototype.insertAdjacentElement,C=window.Element.prototype.insertAdjacentHTML,N=window.Element.prototype.prepend,D=window.Element.prototype.append,T=window.Element.prototype.before,k=window.Element.prototype.after,S=window.Element.prototype.replaceWith,A=window.Element.prototype.remove,F=window.HTMLElement,M=Object.getOwnPropertyDescriptor(window.HTMLElement.prototype,"innerHTML"),L=window.HTMLElement.prototype.insertAdjacentElement,O=window.HTMLElement.prototype.insertAdjacentHTML,j=new Set;function H(t){var e=j.has(t);return t=/^[a-z][.0-9_a-z]*-[-.0-9_a-z]*$/.test(t),!e&&t}"annotation-xml color-profile font-face font-face-src font-face-uri font-face-format font-face-name missing-glyph".split(" ").forEach((function(t){return j.add(t)}));var x=document.contains?document.contains.bind(document):document.documentElement.contains.bind(document.documentElement);function P(t){var e=t.isConnected;if(void 0!==e)return e;if(x(t))return!0;for(;t&&!(t.__CE_isImportDocument||t instanceof Document);)t=t.parentNode||(window.ShadowRoot&&t instanceof ShadowRoot?t.host:void 0);return!(!t||!(t.__CE_isImportDocument||t instanceof Document))}function I(t){var e=t.children;if(e)return Array.prototype.slice.call(e);for(e=[],t=t.firstChild;t;t=t.nextSibling)t.nodeType===Node.ELEMENT_NODE&&e.push(t);return e}function R(t,e){for(;e&&e!==t&&!e.nextSibling;)e=e.parentNode;return e&&e!==t?e.nextSibling:null}function W(t,e,n){for(var o=t;o;){if(o.nodeType===Node.ELEMENT_NODE){var r=o;e(r);var i=r.localName;if("link"===i&&"import"===r.getAttribute("rel")){if(o=r.import,void 0===n&&(n=new Set),o instanceof Node&&!n.has(o))for(n.add(o),o=o.firstChild;o;o=o.nextSibling)W(o,e,n);o=R(t,r);continue}if("template"===i){o=R(t,r);continue}if(r=r.__CE_shadowRoot)for(r=r.firstChild;r;r=r.nextSibling)W(r,e,n)}o=o.firstChild?o.firstChild:R(t,o)}}function B(){var t=!(null==at||!at.noDocumentConstructionObserver),e=!(null==at||!at.shadyDomFastWalk);this.m=[],this.g=[],this.j=!1,this.shadyDomFastWalk=e,this.I=!t}function U(t,e,n,o){var r=window.ShadyDOM;if(t.shadyDomFastWalk&&r&&r.inUse){if(e.nodeType===Node.ELEMENT_NODE&&n(e),e.querySelectorAll)for(t=r.nativeMethods.querySelectorAll.call(e,"*"),e=0;e<t.length;e++)n(t[e])}else W(e,n,o)}function z(t,e){t.j&&U(t,e,(function(e){return q(t,e)}))}function q(t,e){if(t.j&&!e.__CE_patched){e.__CE_patched=!0;for(var n=0;n<t.m.length;n++)t.m[n](e);for(n=0;n<t.g.length;n++)t.g[n](e)}}function G(t,e){var n=[];for(U(t,e,(function(t){return n.push(t)})),e=0;e<n.length;e++){var o=n[e];1===o.__CE_state?t.connectedCallback(o):X(t,o)}}function J(t,e){var n=[];for(U(t,e,(function(t){return n.push(t)})),e=0;e<n.length;e++){var o=n[e];1===o.__CE_state&&t.disconnectedCallback(o)}}function V(t,e,n){var o=(n=void 0===n?{}:n).J,r=n.upgrade||function(e){return X(t,e)},i=[];for(U(t,e,(function(e){if(t.j&&q(t,e),"link"===e.localName&&"import"===e.getAttribute("rel")){var n=e.import;n instanceof Node&&(n.__CE_isImportDocument=!0,n.__CE_registry=document.__CE_registry),n&&"complete"===n.readyState?n.__CE_documentLoadHandled=!0:e.addEventListener("load",(function(){var n=e.import;if(!n.__CE_documentLoadHandled){n.__CE_documentLoadHandled=!0;var i=new Set;o&&(o.forEach((function(t){return i.add(t)})),i.delete(n)),V(t,n,{J:i,upgrade:r})}}))}else i.push(e)}),o),e=0;e<i.length;e++)r(i[e])}function X(t,e){try{var n=e.ownerDocument,o=n.__CE_registry,r=o&&(n.defaultView||n.__CE_isImportDocument)?rt(o,e.localName):void 0;if(r&&void 0===e.__CE_state){r.constructionStack.push(e);try{try{if(new r.constructorFunction!==e)throw Error("The custom element constructor did not produce the element being upgraded.")}finally{r.constructionStack.pop()}}catch(t){throw e.__CE_state=2,t}if(e.__CE_state=1,e.__CE_definition=r,r.attributeChangedCallback&&e.hasAttributes()){var i=r.observedAttributes;for(r=0;r<i.length;r++){var l=i[r],a=e.getAttribute(l);null!==a&&t.attributeChangedCallback(e,l,null,a,null)}}P(e)&&t.connectedCallback(e)}}catch(t){K(t)}}function $(n,o,r,i){var l=o.__CE_registry;if(l&&(null===i||"http://www.w3.org/1999/xhtml"===i)&&(l=rt(l,r)))try{var a=new l.constructorFunction;if(void 0===a.__CE_state||void 0===a.__CE_definition)throw Error("Failed to construct '"+r+"': The returned value was not constructed with the HTMLElement constructor.");if("http://www.w3.org/1999/xhtml"!==a.namespaceURI)throw Error("Failed to construct '"+r+"': The constructed element's namespace must be the HTML namespace.");if(a.hasAttributes())throw Error("Failed to construct '"+r+"': The constructed element must not have any attributes.");if(null!==a.firstChild)throw Error("Failed to construct '"+r+"': The constructed element must not have any children.");if(null!==a.parentNode)throw Error("Failed to construct '"+r+"': The constructed element must not have a parent node.");if(a.ownerDocument!==o)throw Error("Failed to construct '"+r+"': The constructed element's owner document is incorrect.");if(a.localName!==r)throw Error("Failed to construct '"+r+"': The constructed element's local name is incorrect.");return a}catch(l){return K(l),o=null===i?t.call(o,r):e.call(o,i,r),Object.setPrototypeOf(o,HTMLUnknownElement.prototype),o.__CE_state=2,o.__CE_definition=void 0,q(n,o),o}return q(n,o=null===i?t.call(o,r):e.call(o,i,r)),o}function K(t){var e="",n="",o=0,r=0;t instanceof Error?(e=t.message,n=t.sourceURL||t.fileName||"",o=t.line||t.lineNumber||0,r=t.column||t.columnNumber||0):e="Uncaught "+String(t);var i=void 0;void 0===ErrorEvent.prototype.initErrorEvent?i=new ErrorEvent("error",{cancelable:!0,message:e,filename:n,lineno:o,colno:r,error:t}):((i=document.createEvent("ErrorEvent")).initErrorEvent("error",!1,!0,e,n,o),i.preventDefault=function(){Object.defineProperty(this,"defaultPrevented",{configurable:!0,get:function(){return!0}})}),void 0===i.error&&Object.defineProperty(i,"error",{configurable:!0,enumerable:!0,get:function(){return t}}),window.dispatchEvent(i),i.defaultPrevented||console.error(t)}function Q(){var t=this;this.g=void 0,this.F=new Promise((function(e){t.l=e}))}function Y(t){var e=document;this.l=void 0,this.h=t,this.g=e,V(this.h,this.g),"loading"===this.g.readyState&&(this.l=new MutationObserver(this.G.bind(this)),this.l.observe(this.g,{childList:!0,subtree:!0}))}function Z(t){t.l&&t.l.disconnect()}function tt(t){this.s=new Map,this.u=new Map,this.C=new Map,this.A=!1,this.B=new Map,this.o=function(t){return t()},this.i=!1,this.v=[],this.h=t,this.D=t.I?new Y(t):void 0}function et(t,e){if(!H(e))throw new SyntaxError("The element name '"+e+"' is not valid.");if(rt(t,e))throw Error("A custom element with name '"+e+"' has already been defined.");if(t.A)throw Error("A custom element is already being defined.")}function nt(t,e,n){var o;t.A=!0;try{var r=n.prototype;if(!(r instanceof Object))throw new TypeError("The custom element constructor's prototype is not an object.");var i=function(t){var e=r[t];if(void 0!==e&&!(e instanceof Function))throw Error("The '"+t+"' callback must be a function.");return e},l=i("connectedCallback"),a=i("disconnectedCallback"),c=i("adoptedCallback"),s=(o=i("attributeChangedCallback"))&&n.observedAttributes||[]}catch(t){throw t}finally{t.A=!1}return n={localName:e,constructorFunction:n,connectedCallback:l,disconnectedCallback:a,adoptedCallback:c,attributeChangedCallback:o,observedAttributes:s,constructionStack:[]},t.u.set(e,n),t.C.set(n.constructorFunction,n),n}function ot(t){if(!1!==t.i){t.i=!1;for(var e=[],n=t.v,o=new Map,r=0;r<n.length;r++)o.set(n[r],[]);for(V(t.h,document,{upgrade:function(n){if(void 0===n.__CE_state){var r=n.localName,i=o.get(r);i?i.push(n):t.u.has(r)&&e.push(n)}}}),r=0;r<e.length;r++)X(t.h,e[r]);for(r=0;r<n.length;r++){for(var i=n[r],l=o.get(i),a=0;a<l.length;a++)X(t.h,l[a]);(i=t.B.get(i))&&i.resolve(void 0)}n.length=0}}function rt(t,e){var n=t.u.get(e);if(n)return n;if(n=t.s.get(e)){t.s.delete(e);try{return nt(t,e,n())}catch(t){K(t)}}}function it(t,e,n){function o(e){return function(n){for(var o=[],r=0;r<arguments.length;++r)o[r]=arguments[r];r=[];for(var i=[],l=0;l<o.length;l++){var a=o[l];if(a instanceof Element&&P(a)&&i.push(a),a instanceof DocumentFragment)for(a=a.firstChild;a;a=a.nextSibling)r.push(a);else r.push(a)}for(e.apply(this,o),o=0;o<i.length;o++)J(t,i[o]);if(P(this))for(o=0;o<r.length;o++)(i=r[o])instanceof Element&&G(t,i)}}void 0!==n.prepend&&(e.prepend=o(n.prepend)),void 0!==n.append&&(e.append=o(n.append))}B.prototype.connectedCallback=function(t){var e=t.__CE_definition;if(e.connectedCallback)try{e.connectedCallback.call(t)}catch(t){K(t)}},B.prototype.disconnectedCallback=function(t){var e=t.__CE_definition;if(e.disconnectedCallback)try{e.disconnectedCallback.call(t)}catch(t){K(t)}},B.prototype.attributeChangedCallback=function(t,e,n,o,r){var i=t.__CE_definition;if(i.attributeChangedCallback&&-1<i.observedAttributes.indexOf(e))try{i.attributeChangedCallback.call(t,e,n,o,r)}catch(t){K(t)}},Q.prototype.resolve=function(t){if(this.g)throw Error("Already resolved.");this.g=t,this.l(t)},Y.prototype.G=function(t){var e=this.g.readyState;for("interactive"!==e&&"complete"!==e||Z(this),e=0;e<t.length;e++)for(var n=t[e].addedNodes,o=0;o<n.length;o++)V(this.h,n[o])},tt.prototype.H=function(t,e){var n=this;if(!(e instanceof Function))throw new TypeError("Custom element constructor getters must be functions.");et(this,t),this.s.set(t,e),this.v.push(t),this.i||(this.i=!0,this.o((function(){return ot(n)})))},tt.prototype.define=function(t,e){var n=this;if(!(e instanceof Function))throw new TypeError("Custom element constructors must be functions.");et(this,t),nt(this,t,e),this.v.push(t),this.i||(this.i=!0,this.o((function(){return ot(n)})))},tt.prototype.upgrade=function(t){V(this.h,t)},tt.prototype.get=function(t){if(t=rt(this,t))return t.constructorFunction},tt.prototype.whenDefined=function(t){if(!H(t))return Promise.reject(new SyntaxError("'"+t+"' is not a valid custom element name."));var e=this.B.get(t);if(e)return e.F;e=new Q,this.B.set(t,e);var n=this.u.has(t)||this.s.has(t);return t=-1===this.v.indexOf(t),n&&t&&e.resolve(void 0),e.F},tt.prototype.polyfillWrapFlushCallback=function(t){this.D&&Z(this.D);var e=this.o;this.o=function(n){return t((function(){return e(n)}))}},tt.prototype.define=tt.prototype.define,tt.prototype.upgrade=tt.prototype.upgrade,tt.prototype.get=tt.prototype.get,tt.prototype.whenDefined=tt.prototype.whenDefined,tt.prototype.polyfillDefineLazy=tt.prototype.H,tt.prototype.polyfillWrapFlushCallback=tt.prototype.polyfillWrapFlushCallback;var lt={},at=window.customElements;function ct(){var j=new B;!function(e){function n(){var n=this.constructor,o=document.__CE_registry.C.get(n);if(!o)throw Error("Failed to construct a custom element: The constructor was not registered with `customElements`.");var r=o.constructionStack;if(0===r.length)return r=t.call(document,o.localName),Object.setPrototypeOf(r,n.prototype),r.__CE_state=1,r.__CE_definition=o,q(e,r),r;var i=r.length-1,l=r[i];if(l===lt)throw Error("Failed to construct '"+o.localName+"': This element was already constructed.");return r[i]=lt,Object.setPrototypeOf(l,n.prototype),q(e,l),l}n.prototype=F.prototype,Object.defineProperty(HTMLElement.prototype,"constructor",{writable:!0,configurable:!0,enumerable:!1,value:n}),window.HTMLElement=n}(j),function(t){Document.prototype.createElement=function(e){return $(t,this,e,null)},Document.prototype.importNode=function(e,o){return e=n.call(this,e,!!o),this.__CE_registry?V(t,e):z(t,e),e},Document.prototype.createElementNS=function(e,n){return $(t,this,n,e)},it(t,Document.prototype,{prepend:o,append:r})}(j),it(j,DocumentFragment.prototype,{prepend:i,append:l}),function(t){function e(e,n){Object.defineProperty(e,"textContent",{enumerable:n.enumerable,configurable:!0,get:n.get,set:function(e){if(this.nodeType===Node.TEXT_NODE)n.set.call(this,e);else{var o=void 0;if(this.firstChild){var r=this.childNodes,i=r.length;if(0<i&&P(this)){o=Array(i);for(var l=0;l<i;l++)o[l]=r[l]}}if(n.set.call(this,e),o)for(e=0;e<o.length;e++)J(t,o[e])}}})}Node.prototype.insertBefore=function(e,n){if(e instanceof DocumentFragment){var o=I(e);if(e=s.call(this,e,n),P(this))for(n=0;n<o.length;n++)G(t,o[n]);return e}return o=e instanceof Element&&P(e),n=s.call(this,e,n),o&&J(t,e),P(this)&&G(t,e),n},Node.prototype.appendChild=function(e){if(e instanceof DocumentFragment){var n=I(e);if(e=c.call(this,e),P(this))for(var o=0;o<n.length;o++)G(t,n[o]);return e}return n=e instanceof Element&&P(e),o=c.call(this,e),n&&J(t,e),P(this)&&G(t,e),o},Node.prototype.cloneNode=function(e){return e=a.call(this,!!e),this.ownerDocument.__CE_registry?V(t,e):z(t,e),e},Node.prototype.removeChild=function(e){var n=e instanceof Element&&P(e),o=u.call(this,e);return n&&J(t,e),o},Node.prototype.replaceChild=function(e,n){if(e instanceof DocumentFragment){var o=I(e);if(e=h.call(this,e,n),P(this))for(J(t,n),n=0;n<o.length;n++)G(t,o[n]);return e}o=e instanceof Element&&P(e);var r=h.call(this,e,n),i=P(this);return i&&J(t,n),o&&J(t,e),i&&G(t,e),r},d&&d.get?e(Node.prototype,d):function(t,e){t.j=!0,t.m.push(e)}(t,(function(t){e(t,{enumerable:!0,configurable:!0,get:function(){for(var t=[],e=this.firstChild;e;e=e.nextSibling)e.nodeType!==Node.COMMENT_NODE&&t.push(e.textContent);return t.join("")},set:function(t){for(;this.firstChild;)u.call(this,this.firstChild);null!=t&&""!==t&&c.call(this,document.createTextNode(t))}})}))}(j),function(t){function n(e,n){Object.defineProperty(e,"innerHTML",{enumerable:n.enumerable,configurable:!0,get:n.get,set:function(e){var o=this,r=void 0;if(P(this)&&(r=[],U(t,this,(function(t){t!==o&&r.push(t)}))),n.set.call(this,e),r)for(var i=0;i<r.length;i++){var l=r[i];1===l.__CE_state&&t.disconnectedCallback(l)}return this.ownerDocument.__CE_registry?V(t,this):z(t,this),e}})}function o(e,n){e.insertAdjacentElement=function(e,o){var r=P(o);return e=n.call(this,e,o),r&&J(t,o),P(e)&&G(t,o),e}}function r(e,n){function o(e,n){for(var o=[];e!==n;e=e.nextSibling)o.push(e);for(n=0;n<o.length;n++)V(t,o[n])}e.insertAdjacentHTML=function(t,e){if("beforebegin"===(t=t.toLowerCase())){var r=this.previousSibling;n.call(this,t,e),o(r||this.parentNode.firstChild,this)}else if("afterbegin"===t)r=this.firstChild,n.call(this,t,e),o(this.firstChild,r);else if("beforeend"===t)r=this.lastChild,n.call(this,t,e),o(r||this.firstChild,null);else{if("afterend"!==t)throw new SyntaxError("The value provided ("+String(t)+") is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'.");r=this.nextSibling,n.call(this,t,e),o(this.nextSibling,r)}}}f&&(Element.prototype.attachShadow=function(e){if(e=f.call(this,e),t.j&&!e.__CE_patched){e.__CE_patched=!0;for(var n=0;n<t.m.length;n++)t.m[n](e)}return this.__CE_shadowRoot=e}),p&&p.get?n(Element.prototype,p):M&&M.get?n(HTMLElement.prototype,M):function(t,e){t.j=!0,t.g.push(e)}(t,(function(t){n(t,{enumerable:!0,configurable:!0,get:function(){return a.call(this,!0).innerHTML},set:function(t){var n="template"===this.localName,o=n?this.content:this,r=e.call(document,this.namespaceURI,this.localName);for(r.innerHTML=t;0<o.childNodes.length;)u.call(o,o.childNodes[0]);for(t=n?r.content:r;0<t.childNodes.length;)c.call(o,t.childNodes[0])}})})),Element.prototype.setAttribute=function(e,n){if(1!==this.__CE_state)return y.call(this,e,n);var o=m.call(this,e);y.call(this,e,n),n=m.call(this,e),t.attributeChangedCallback(this,e,o,n,null)},Element.prototype.setAttributeNS=function(e,n,o){if(1!==this.__CE_state)return E.call(this,e,n,o);var r=v.call(this,e,n);E.call(this,e,n,o),o=v.call(this,e,n),t.attributeChangedCallback(this,n,r,o,e)},Element.prototype.removeAttribute=function(e){if(1!==this.__CE_state)return w.call(this,e);var n=m.call(this,e);w.call(this,e),null!==n&&t.attributeChangedCallback(this,e,n,null,null)},g&&(Element.prototype.toggleAttribute=function(e,n){if(1!==this.__CE_state)return g.call(this,e,n);var o=m.call(this,e);return null!==o!==(n=g.call(this,e,n))&&t.attributeChangedCallback(this,e,o,n?"":null,null),n}),Element.prototype.removeAttributeNS=function(e,n){if(1!==this.__CE_state)return b.call(this,e,n);var o=v.call(this,e,n);b.call(this,e,n);var r=v.call(this,e,n);o!==r&&t.attributeChangedCallback(this,n,o,r,e)},L?o(HTMLElement.prototype,L):_&&o(Element.prototype,_),O?r(HTMLElement.prototype,O):C&&r(Element.prototype,C),it(t,Element.prototype,{prepend:N,append:D}),function(t){function e(e){return function(n){for(var o=[],r=0;r<arguments.length;++r)o[r]=arguments[r];r=[];for(var i=[],l=0;l<o.length;l++){var a=o[l];if(a instanceof Element&&P(a)&&i.push(a),a instanceof DocumentFragment)for(a=a.firstChild;a;a=a.nextSibling)r.push(a);else r.push(a)}for(e.apply(this,o),o=0;o<i.length;o++)J(t,i[o]);if(P(this))for(o=0;o<r.length;o++)(i=r[o])instanceof Element&&G(t,i)}}var n=Element.prototype;void 0!==T&&(n.before=e(T)),void 0!==k&&(n.after=e(k)),void 0!==S&&(n.replaceWith=function(e){for(var n=[],o=0;o<arguments.length;++o)n[o]=arguments[o];o=[];for(var r=[],i=0;i<n.length;i++){var l=n[i];if(l instanceof Element&&P(l)&&r.push(l),l instanceof DocumentFragment)for(l=l.firstChild;l;l=l.nextSibling)o.push(l);else o.push(l)}for(i=P(this),S.apply(this,n),n=0;n<r.length;n++)J(t,r[n]);if(i)for(J(t,this),n=0;n<o.length;n++)(r=o[n])instanceof Element&&G(t,r)}),void 0!==A&&(n.remove=function(){var e=P(this);A.call(this),e&&J(t,this)})}(t)}(j),window.CustomElementRegistry=tt,j=new tt(j),document.__CE_registry=j,Object.defineProperty(window,"customElements",{configurable:!0,enumerable:!0,value:j})}at&&!at.forcePolyfill&&"function"==typeof at.define&&"function"==typeof at.get||ct(),window.__CE_installPolyfill=ct}).call(this);