!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.postscribe=o():e.postscribe=o()}(this,function(){return function(e){function o(r){if(t[r])return t[r].exports;var n=t[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o,t){"use strict";var r=t(1),n=function(e){return e&&e.__esModule?e:{default:e}}(r);e.exports=n.default},function(e,o,t){"use strict";function r(){}function n(){var e=f.shift();if(e){var o=_.last(e);o.afterDequeue(),e.stream=i.apply(void 0,e),o.afterStreamStart()}}function i(e,o,t){function i(e){e=t.beforeWrite(e),u.write(e),t.afterWrite(e)}u=new c.default(e,t),u.id=g++,u.name=t.name||u.id,s.streams[u.name]=u;var d=e.ownerDocument,p={close:d.close,open:d.open,write:d.write,writeln:d.writeln};a(d,{close:r,open:r,write:function(){for(var e=arguments.length,o=Array(e),t=0;t2&&void 0!==arguments[2]?arguments[2]:null,r=_+o;p.existy(t)&&""!==t?e.setAttribute(r,t):e.removeAttribute(r)}o.__esModule=!0;var s=Object.assign||function(e){for(var o=1;o1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),this.root=o,this.options=t,this.doc=o.ownerDocument,this.win=this.doc.defaultView||this.doc.parentWindow,this.parser=new d.default("",{autoFix:t.autoFix}),this.actuals=[o],this.proxyHistory="",this.proxyRoot=this.doc.createElement(o.nodeName),this.scriptStack=[],this.writeQueue=[],i(this.proxyRoot,"proxyof",0)}return e.prototype.write=function(){var e;for((e=this.writeQueue).push.apply(e,arguments);!this.deferredRemote&&this.writeQueue.length;){var o=this.writeQueue.shift();p.isFunction(o)?this._callFunction(o):this._writeImpl(o)}},e.prototype._callFunction=function(e){var o={type:"function",value:e.name||e.toString()};this._onScriptStart(o),e.call(this.win,this.doc),this._onScriptDone(o)},e.prototype._writeImpl=function(e){this.parser.append(e);for(var o=void 0,t=void 0,r=void 0,n=[];(o=this.parser.readToken())&&!(t=p.isScript(o))&&!(r=p.isStyle(o));)(o=this.options.beforeWriteToken(o))&&n.push(o);n.length>0&&this._writeStaticTokens(n),t&&this._handleScriptToken(o),r&&this._handleStyleToken(o)},e.prototype._writeStaticTokens=function(e){var o=this._buildChunk(e);return o.actual?(o.html=this.proxyHistory+o.actual,this.proxyHistory+=o.proxy,this.proxyRoot.innerHTML=o.html,this._walkChunk(),o):null},e.prototype._buildChunk=function(e){for(var o=this.actuals.length,t=[],r=[],n=[],i=e.length,s=0;s)/," "+_+"id="+c+" $1")),a.attrs.id!==g&&a.attrs.id!==l&&n.push("atomicTag"===a.type?"":"<"+a.tagName+" "+_+"proxyof="+c+(a.unary?" />":">"))}}else r.push(d),n.push("endTag"===a.type?d:"")}return{tokens:e,raw:t.join(""),actual:r.join(""),proxy:n.join("")}},e.prototype._walkChunk=function(){for(var e=void 0,o=[this.proxyRoot];p.existy(e=o.shift());){var t=1===e.nodeType;if(!(t&&n(e,"proxyof"))){t&&(this.actuals[n(e,"id")]=e,i(e,"id"));var r=e.parentNode&&n(e.parentNode,"proxyof");r&&this.actuals[r].appendChild(e)}o.unshift.apply(o,p.toArray(e.childNodes))}},e.prototype._handleScriptToken=function(e){var o=this,t=this.parser.clear();t&&this.writeQueue.unshift(t),e.src=e.attrs.src||e.attrs.SRC,(e=this.options.beforeWriteToken(e))&&(e.src&&this.scriptStack.length?this.deferredRemote=e:this._onScriptStart(e),this._writeScriptToken(e,function(){o._onScriptDone(e)}))},e.prototype._handleStyleToken=function(e){var o=this.parser.clear();o&&this.writeQueue.unshift(o),e.type=e.attrs.type||e.attrs.TYPE||"text/css",e=this.options.beforeWriteToken(e),e&&this._writeStyleToken(e),o&&this.write()},e.prototype._writeStyleToken=function(e){var o=this._buildStyle(e);this._insertCursor(o,l),e.content&&(o.styleSheet&&!o.sheet?o.styleSheet.cssText=e.content:o.appendChild(this.doc.createTextNode(e.content)))},e.prototype._buildStyle=function(e){var o=this.doc.createElement(e.tagName);return o.setAttribute("type",e.type),p.eachKey(e.attrs,function(e,t){o.setAttribute(e,t)}),o},e.prototype._insertCursor=function(e,o){this._writeImpl('');var t=this.doc.getElementById(o);t&&t.parentNode.replaceChild(e,t)},e.prototype._onScriptStart=function(e){e.outerWrites=this.writeQueue,this.writeQueue=[],this.scriptStack.unshift(e)},e.prototype._onScriptDone=function(e){return e!==this.scriptStack[0]?void this.options.error({msg:"Bad script nesting or script finished twice"}):(this.scriptStack.shift(),this.write.apply(this,e.outerWrites),void(!this.scriptStack.length&&this.deferredRemote&&(this._onScriptStart(this.deferredRemote),this.deferredRemote=null)))},e.prototype._writeScriptToken=function(e,o){var t=this._buildScript(e),r=this._shouldRelease(t),n=this.options.afterAsync;e.src&&(t.src=e.src,this._scriptLoadHandler(t,r?n:function(){o(),n()}));try{this._insertCursor(t,g),t.src&&!r||o()}catch(e){this.options.error(e),o()}},e.prototype._buildScript=function(e){var o=this.doc.createElement(e.tagName);return p.eachKey(e.attrs,function(e,t){o.setAttribute(e,t)}),e.content&&(o.text=e.content),o},e.prototype._scriptLoadHandler=function(e,o){function t(){e=e.onload=e.onreadystatechange=e.onerror=null}function r(){t(),null!=o&&o(),o=null}function n(e){t(),a(e),null!=o&&o(),o=null}function i(e,o){var t=e["on"+o];null!=t&&(e["_on"+o]=t)}var a=this.options.error;i(e,"load"),i(e,"error"),s(e,{onload:function(){if(e._onload)try{e._onload.apply(this,Array.prototype.slice.call(arguments,0))}catch(o){n({msg:"onload handler failed "+o+" @ "+e.src})}r()},onerror:function(){if(e._onerror)try{e._onerror.apply(this,Array.prototype.slice.call(arguments,0))}catch(o){return void n({msg:"onerror handler failed "+o+" @ "+e.src})}n({msg:"remote script failed "+e.src})},onreadystatechange:function(){/^(loaded|complete)$/.test(e.readyState)&&r()}})},e.prototype._shouldRelease=function(e){return!/^script$/i.test(e.nodeName)||!!(this.options.releaseAsync&&e.src&&e.hasAttribute("async"))},e}();o.default=f},function(e,o,t){!function(o,t){e.exports=function(){return function(e){function o(r){if(t[r])return t[r].exports;var n=t[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o,t){"use strict";var r=t(1),n=function(e){return e&&e.__esModule?e:{default:e}}(r);e.exports=n.default},function(e,o,t){"use strict";function r(e){if(e&&e.__esModule)return e;var o={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t]);return o.default=e,o}function n(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}o.__esModule=!0;var i=t(2),s=r(i),a=t(3),d=r(a),c=t(6),p=function(e){return e&&e.__esModule?e:{default:e}}(c),_=t(5),l={comment:/^