| 12 |
- /*! For license information please see lsplugin.core.js.LICENSE.txt */
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.LSPlugin=t():e.LSPlugin=t()}(self,(function(){return(()=>{var e={227:(e,t,n)=>{var r=n(155);t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(i=r))})),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(447)(t);const{formatters:i}=e.exports;i.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:(e,t,n)=>{e.exports=function(e){function t(e){let n,i,o,s=null;function a(...e){if(!a.enabled)return;const r=a,i=Number(new Date),o=i-(n||i);r.diff=o,r.prev=n,r.curr=i,n=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,i)=>{if("%%"===n)return"%";s++;const o=t.formatters[i];if("function"==typeof o){const t=e[s];n=o.call(r,t),e.splice(s,1),s--}return n})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(i!==t.namespaces&&(i=t.namespaces,o=t.enabled(e)),o),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function i(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(i),...t.skips.map(i).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),i=r.length;for(n=0;n<i;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.substr(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=n(824),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}},856:function(e){e.exports=function(){"use strict";var e=Object.hasOwnProperty,t=Object.setPrototypeOf,n=Object.isFrozen,r=Object.getPrototypeOf,i=Object.getOwnPropertyDescriptor,o=Object.freeze,s=Object.seal,a=Object.create,l="undefined"!=typeof Reflect&&Reflect,c=l.apply,u=l.construct;c||(c=function(e,t,n){return e.apply(t,n)}),o||(o=function(e){return e}),s||(s=function(e){return e}),u||(u=function(e,t){return new(Function.prototype.bind.apply(e,[null].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(t))))});var d,h=C(Array.prototype.forEach),p=C(Array.prototype.pop),f=C(Array.prototype.push),g=C(String.prototype.toLowerCase),m=C(String.prototype.match),y=C(String.prototype.replace),v=C(String.prototype.indexOf),_=C(String.prototype.trim),b=C(RegExp.prototype.test),w=(d=TypeError,function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return u(d,t)});function C(e){return function(t){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return c(e,t,r)}}function x(e,r){t&&t(e,null);for(var i=r.length;i--;){var o=r[i];if("string"==typeof o){var s=g(o);s!==o&&(n(r)||(r[i]=s),o=s)}e[o]=!0}return e}function S(t){var n=a(null),r=void 0;for(r in t)c(e,t,[r])&&(n[r]=t[r]);return n}function A(e,t){for(;null!==e;){var n=i(e,t);if(n){if(n.get)return C(n.get);if("function"==typeof n.value)return C(n.value)}e=r(e)}return function(e){return console.warn("fallback value for",e),null}}var E=o(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),T=o(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),O=o(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),L=o(["animate","color-profile","cursor","discard","fedropshadow","feimage","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),k=o(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover"]),I=o(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),F=o(["#text"]),R=o(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","xmlns","slot"]),M=o(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),j=o(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),P=o(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),D=s(/\{\{[\s\S]*|[\s\S]*\}\}/gm),N=s(/<%[\s\S]*|[\s\S]*%>/gm),U=s(/^data-[\-\w.\u00B7-\uFFFF]/),z=s(/^aria-[\-\w]+$/),$=s(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),H=s(/^(?:\w+script|data):/i),W=s(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function q(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}var G=function(){return"undefined"==typeof window?null:window},J=function(e,t){if("object"!==(void 0===e?"undefined":B(e))||"function"!=typeof e.createPolicy)return null;var n=null,r="data-tt-policy-suffix";t.currentScript&&t.currentScript.hasAttribute(r)&&(n=t.currentScript.getAttribute(r));var i="dompurify"+(n?"#"+n:"");try{return e.createPolicy(i,{createHTML:function(e){return e}})}catch(e){return console.warn("TrustedTypes policy "+i+" could not be created."),null}};return function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:G(),n=function(t){return e(t)};if(n.version="2.3.1",n.removed=[],!t||!t.document||9!==t.document.nodeType)return n.isSupported=!1,n;var r=t.document,i=t.document,s=t.DocumentFragment,a=t.HTMLTemplateElement,l=t.Node,c=t.Element,u=t.NodeFilter,d=t.NamedNodeMap,C=void 0===d?t.NamedNodeMap||t.MozNamedAttrMap:d,Z=t.Text,K=t.Comment,V=t.DOMParser,Y=t.trustedTypes,X=c.prototype,Q=A(X,"cloneNode"),ee=A(X,"nextSibling"),te=A(X,"childNodes"),ne=A(X,"parentNode");if("function"==typeof a){var re=i.createElement("template");re.content&&re.content.ownerDocument&&(i=re.content.ownerDocument)}var ie=J(Y,r),oe=ie&&De?ie.createHTML(""):"",se=i,ae=se.implementation,le=se.createNodeIterator,ce=se.createDocumentFragment,ue=se.getElementsByTagName,de=r.importNode,he={};try{he=S(i).documentMode?i.documentMode:{}}catch(e){}var pe={};n.isSupported="function"==typeof ne&&ae&&void 0!==ae.createHTMLDocument&&9!==he;var fe=D,ge=N,me=U,ye=z,ve=H,_e=W,be=$,we=null,Ce=x({},[].concat(q(E),q(T),q(O),q(k),q(F))),xe=null,Se=x({},[].concat(q(R),q(M),q(j),q(P))),Ae=null,Ee=null,Te=!0,Oe=!0,Le=!1,ke=!1,Ie=!1,Fe=!1,Re=!1,Me=!1,je=!1,Pe=!0,De=!1,Ne=!0,Ue=!0,ze=!1,$e={},He=null,We=x({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),Be=null,qe=x({},["audio","video","img","source","image","track"]),Ge=null,Je=x({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Ze="http://www.w3.org/1998/Math/MathML",Ke="http://www.w3.org/2000/svg",Ve="http://www.w3.org/1999/xhtml",Ye=Ve,Xe=!1,Qe=null,et=i.createElement("form"),tt=function(e){Qe&&Qe===e||(e&&"object"===(void 0===e?"undefined":B(e))||(e={}),e=S(e),we="ALLOWED_TAGS"in e?x({},e.ALLOWED_TAGS):Ce,xe="ALLOWED_ATTR"in e?x({},e.ALLOWED_ATTR):Se,Ge="ADD_URI_SAFE_ATTR"in e?x(S(Je),e.ADD_URI_SAFE_ATTR):Je,Be="ADD_DATA_URI_TAGS"in e?x(S(qe),e.ADD_DATA_URI_TAGS):qe,He="FORBID_CONTENTS"in e?x({},e.FORBID_CONTENTS):We,Ae="FORBID_TAGS"in e?x({},e.FORBID_TAGS):{},Ee="FORBID_ATTR"in e?x({},e.FORBID_ATTR):{},$e="USE_PROFILES"in e&&e.USE_PROFILES,Te=!1!==e.ALLOW_ARIA_ATTR,Oe=!1!==e.ALLOW_DATA_ATTR,Le=e.ALLOW_UNKNOWN_PROTOCOLS||!1,ke=e.SAFE_FOR_TEMPLATES||!1,Ie=e.WHOLE_DOCUMENT||!1,Me=e.RETURN_DOM||!1,je=e.RETURN_DOM_FRAGMENT||!1,Pe=!1!==e.RETURN_DOM_IMPORT,De=e.RETURN_TRUSTED_TYPE||!1,Re=e.FORCE_BODY||!1,Ne=!1!==e.SANITIZE_DOM,Ue=!1!==e.KEEP_CONTENT,ze=e.IN_PLACE||!1,be=e.ALLOWED_URI_REGEXP||be,Ye=e.NAMESPACE||Ve,ke&&(Oe=!1),je&&(Me=!0),$e&&(we=x({},[].concat(q(F))),xe=[],!0===$e.html&&(x(we,E),x(xe,R)),!0===$e.svg&&(x(we,T),x(xe,M),x(xe,P)),!0===$e.svgFilters&&(x(we,O),x(xe,M),x(xe,P)),!0===$e.mathMl&&(x(we,k),x(xe,j),x(xe,P))),e.ADD_TAGS&&(we===Ce&&(we=S(we)),x(we,e.ADD_TAGS)),e.ADD_ATTR&&(xe===Se&&(xe=S(xe)),x(xe,e.ADD_ATTR)),e.ADD_URI_SAFE_ATTR&&x(Ge,e.ADD_URI_SAFE_ATTR),e.FORBID_CONTENTS&&(He===We&&(He=S(He)),x(He,e.FORBID_CONTENTS)),Ue&&(we["#text"]=!0),Ie&&x(we,["html","head","body"]),we.table&&(x(we,["tbody"]),delete Ae.tbody),o&&o(e),Qe=e)},nt=x({},["mi","mo","mn","ms","mtext"]),rt=x({},["foreignobject","desc","title","annotation-xml"]),it=x({},T);x(it,O),x(it,L);var ot=x({},k);x(ot,I);var st=function(e){var t=ne(e);t&&t.tagName||(t={namespaceURI:Ve,tagName:"template"});var n=g(e.tagName),r=g(t.tagName);if(e.namespaceURI===Ke)return t.namespaceURI===Ve?"svg"===n:t.namespaceURI===Ze?"svg"===n&&("annotation-xml"===r||nt[r]):Boolean(it[n]);if(e.namespaceURI===Ze)return t.namespaceURI===Ve?"math"===n:t.namespaceURI===Ke?"math"===n&&rt[r]:Boolean(ot[n]);if(e.namespaceURI===Ve){if(t.namespaceURI===Ke&&!rt[r])return!1;if(t.namespaceURI===Ze&&!nt[r])return!1;var i=x({},["title","style","font","a","script"]);return!ot[n]&&(i[n]||!it[n])}return!1},at=function(e){f(n.removed,{element:e});try{e.parentNode.removeChild(e)}catch(t){try{e.outerHTML=oe}catch(t){e.remove()}}},lt=function(e,t){try{f(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){f(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!xe[e])if(Me||je)try{at(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},ct=function(e){var t=void 0,n=void 0;if(Re)e="<remove></remove>"+e;else{var r=m(e,/^[\r\n\t ]+/);n=r&&r[0]}var o=ie?ie.createHTML(e):e;if(Ye===Ve)try{t=(new V).parseFromString(o,"text/html")}catch(e){}if(!t||!t.documentElement){t=ae.createDocument(Ye,"template",null);try{t.documentElement.innerHTML=Xe?"":o}catch(e){}}var s=t.body||t.documentElement;return e&&n&&s.insertBefore(i.createTextNode(n),s.childNodes[0]||null),Ye===Ve?ue.call(t,Ie?"html":"body")[0]:Ie?t.documentElement:s},ut=function(e){return le.call(e.ownerDocument||e,e,u.SHOW_ELEMENT|u.SHOW_COMMENT|u.SHOW_TEXT,null,!1)},dt=function(e){return!(e instanceof Z||e instanceof K||"string"==typeof e.nodeName&&"string"==typeof e.textContent&&"function"==typeof e.removeChild&&e.attributes instanceof C&&"function"==typeof e.removeAttribute&&"function"==typeof e.setAttribute&&"string"==typeof e.namespaceURI&&"function"==typeof e.insertBefore)},ht=function(e){return"object"===(void 0===l?"undefined":B(l))?e instanceof l:e&&"object"===(void 0===e?"undefined":B(e))&&"number"==typeof e.nodeType&&"string"==typeof e.nodeName},pt=function(e,t,r){pe[e]&&h(pe[e],(function(e){e.call(n,t,r,Qe)}))},ft=function(e){var t=void 0;if(pt("beforeSanitizeElements",e,null),dt(e))return at(e),!0;if(m(e.nodeName,/[\u0080-\uFFFF]/))return at(e),!0;var r=g(e.nodeName);if(pt("uponSanitizeElement",e,{tagName:r,allowedTags:we}),!ht(e.firstElementChild)&&(!ht(e.content)||!ht(e.content.firstElementChild))&&b(/<[/\w]/g,e.innerHTML)&&b(/<[/\w]/g,e.textContent))return at(e),!0;if("select"===r&&b(/<template/i,e.innerHTML))return at(e),!0;if(!we[r]||Ae[r]){if(Ue&&!He[r]){var i=ne(e)||e.parentNode,o=te(e)||e.childNodes;if(o&&i)for(var s=o.length-1;s>=0;--s)i.insertBefore(Q(o[s],!0),ee(e))}return at(e),!0}return e instanceof c&&!st(e)?(at(e),!0):"noscript"!==r&&"noembed"!==r||!b(/<\/no(script|embed)/i,e.innerHTML)?(ke&&3===e.nodeType&&(t=e.textContent,t=y(t,fe," "),t=y(t,ge," "),e.textContent!==t&&(f(n.removed,{element:e.cloneNode()}),e.textContent=t)),pt("afterSanitizeElements",e,null),!1):(at(e),!0)},gt=function(e,t,n){if(Ne&&("id"===t||"name"===t)&&(n in i||n in et))return!1;if(Oe&&!Ee[t]&&b(me,t));else if(Te&&b(ye,t));else{if(!xe[t]||Ee[t])return!1;if(Ge[t]);else if(b(be,y(n,_e,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==v(n,"data:")||!Be[e])if(Le&&!b(ve,y(n,_e,"")));else if(n)return!1}return!0},mt=function(e){var t=void 0,r=void 0,i=void 0,o=void 0;pt("beforeSanitizeAttributes",e,null);var s=e.attributes;if(s){var a={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:xe};for(o=s.length;o--;){var l=t=s[o],c=l.name,u=l.namespaceURI;if(r=_(t.value),i=g(c),a.attrName=i,a.attrValue=r,a.keepAttr=!0,a.forceKeepAttr=void 0,pt("uponSanitizeAttribute",e,a),r=a.attrValue,!a.forceKeepAttr&&(lt(c,e),a.keepAttr))if(b(/\/>/i,r))lt(c,e);else{ke&&(r=y(r,fe," "),r=y(r,ge," "));var d=e.nodeName.toLowerCase();if(gt(d,i,r))try{u?e.setAttributeNS(u,c,r):e.setAttribute(c,r),p(n.removed)}catch(e){}}}pt("afterSanitizeAttributes",e,null)}},yt=function e(t){var n=void 0,r=ut(t);for(pt("beforeSanitizeShadowDOM",t,null);n=r.nextNode();)pt("uponSanitizeShadowNode",n,null),ft(n)||(n.content instanceof s&&e(n.content),mt(n));pt("afterSanitizeShadowDOM",t,null)};return n.sanitize=function(e,i){var o=void 0,a=void 0,c=void 0,u=void 0,d=void 0;if((Xe=!e)&&(e="\x3c!--\x3e"),"string"!=typeof e&&!ht(e)){if("function"!=typeof e.toString)throw w("toString is not a function");if("string"!=typeof(e=e.toString()))throw w("dirty is not a string, aborting")}if(!n.isSupported){if("object"===B(t.toStaticHTML)||"function"==typeof t.toStaticHTML){if("string"==typeof e)return t.toStaticHTML(e);if(ht(e))return t.toStaticHTML(e.outerHTML)}return e}if(Fe||tt(i),n.removed=[],"string"==typeof e&&(ze=!1),ze);else if(e instanceof l)1===(a=(o=ct("\x3c!----\x3e")).ownerDocument.importNode(e,!0)).nodeType&&"BODY"===a.nodeName||"HTML"===a.nodeName?o=a:o.appendChild(a);else{if(!Me&&!ke&&!Ie&&-1===e.indexOf("<"))return ie&&De?ie.createHTML(e):e;if(!(o=ct(e)))return Me?null:oe}o&&Re&&at(o.firstChild);for(var h=ut(ze?e:o);c=h.nextNode();)3===c.nodeType&&c===u||ft(c)||(c.content instanceof s&&yt(c.content),mt(c),u=c);if(u=null,ze)return e;if(Me){if(je)for(d=ce.call(o.ownerDocument);o.firstChild;)d.appendChild(o.firstChild);else d=o;return Pe&&(d=de.call(r,d,!0)),d}var p=Ie?o.outerHTML:o.innerHTML;return ke&&(p=y(p,fe," "),p=y(p,ge," ")),ie&&De?ie.createHTML(p):p},n.setConfig=function(e){tt(e),Fe=!0},n.clearConfig=function(){Qe=null,Fe=!1},n.isValidAttribute=function(e,t,n){Qe||tt({});var r=g(e),i=g(t);return gt(r,i,n)},n.addHook=function(e,t){"function"==typeof t&&(pe[e]=pe[e]||[],f(pe[e],t))},n.removeHook=function(e){pe[e]&&p(pe[e])},n.removeHooks=function(e){pe[e]&&(pe[e]=[])},n.removeAllHooks=function(){pe={}},n}()}()},729:e=>{"use strict";var t=Object.prototype.hasOwnProperty,n="~";function r(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,r,o,s){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new i(r,o||e,s),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],a]:e._events[l].push(a):(e._events[l]=a,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,i=[];if(0===this._eventsCount)return i;for(r in e=this._events)t.call(e,r)&&i.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,o=r.length,s=new Array(o);i<o;i++)s[i]=r[i].fn;return s},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,i,o,s){var a=n?n+e:e;if(!this._events[a])return!1;var l,c,u=this._events[a],d=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),d){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,i),!0;case 5:return u.fn.call(u.context,t,r,i,o),!0;case 6:return u.fn.call(u.context,t,r,i,o,s),!0}for(c=1,l=new Array(d-1);c<d;c++)l[c-1]=arguments[c];u.fn.apply(u.context,l)}else{var h,p=u.length;for(c=0;c<p;c++)switch(u[c].once&&this.removeListener(e,u[c].fn,void 0,!0),d){case 1:u[c].fn.call(u[c].context);break;case 2:u[c].fn.call(u[c].context,t);break;case 3:u[c].fn.call(u[c].context,t,r);break;case 4:u[c].fn.call(u[c].context,t,r,i);break;default:if(!l)for(h=1,l=new Array(d-1);h<d;h++)l[h-1]=arguments[h];u[c].fn.apply(u[c].context,l)}}return!0},a.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,i){var o=n?n+e:e;if(!this._events[o])return this;if(!t)return s(this,o),this;var a=this._events[o];if(a.fn)a.fn!==t||i&&!a.once||r&&a.context!==r||s(this,o);else{for(var l=0,c=[],u=a.length;l<u;l++)(a[l].fn!==t||i&&!a[l].once||r&&a[l].context!==r)&&c.push(a[l]);c.length?this._events[o]=1===c.length?c[0]:c:s(this,o)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a},717:e=>{"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},824:e=>{var t=1e3,n=60*t,r=60*n,i=24*r;function o(e,t,n,r){var i=t>=1.5*n;return Math.round(e/n)+" "+r+(i?"s":"")}e.exports=function(e,s){s=s||{};var a,l,c=typeof e;if("string"===c&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var o=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(o){var s=parseFloat(o[1]);switch((o[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*s;case"weeks":case"week":case"w":return 6048e5*s;case"days":case"day":case"d":return s*i;case"hours":case"hour":case"hrs":case"hr":case"h":return s*r;case"minutes":case"minute":case"mins":case"min":case"m":return s*n;case"seconds":case"second":case"secs":case"sec":case"s":return s*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return s;default:return}}}}(e);if("number"===c&&isFinite(e))return s.long?(a=e,(l=Math.abs(a))>=i?o(a,l,i,"day"):l>=r?o(a,l,r,"hour"):l>=n?o(a,l,n,"minute"):l>=t?o(a,l,t,"second"):a+" ms"):function(e){var o=Math.abs(e);return o>=i?Math.round(e/i)+"d":o>=r?Math.round(e/r)+"h":o>=n?Math.round(e/n)+"m":o>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},520:(e,t,n)=>{"use strict";var r=n(155),i="win32"===r.platform,o=n(539);function s(e,t){for(var n=[],r=0;r<e.length;r++){var i=e[r];i&&"."!==i&&(".."===i?n.length&&".."!==n[n.length-1]?n.pop():t&&n.push(".."):n.push(i))}return n}function a(e){for(var t=e.length-1,n=0;n<=t&&!e[n];n++);for(var r=t;r>=0&&!e[r];r--);return 0===n&&r===t?e:n>r?[]:e.slice(n,r+1)}var l=/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/,c=/^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/,u={};function d(e){var t=l.exec(e),n=(t[1]||"")+(t[2]||""),r=t[3]||"",i=c.exec(r);return[n,i[1],i[2],i[3]]}function h(e){var t=l.exec(e),n=t[1]||"",r=!!n&&":"!==n[1];return{device:n,isUnc:r,isAbsolute:r||!!t[2],tail:t[3]}}function p(e){return"\\\\"+e.replace(/^[\\\/]+/,"").replace(/[\\\/]+/g,"\\")}u.resolve=function(){for(var e="",t="",n=!1,i=arguments.length-1;i>=-1;i--){var a;if(i>=0?a=arguments[i]:e?(a=r.env["="+e])&&a.substr(0,3).toLowerCase()===e.toLowerCase()+"\\"||(a=e+"\\"):a=r.cwd(),!o.isString(a))throw new TypeError("Arguments to path.resolve must be strings");if(a){var l=h(a),c=l.device,u=l.isUnc,d=l.isAbsolute,f=l.tail;if((!c||!e||c.toLowerCase()===e.toLowerCase())&&(e||(e=c),n||(t=f+"\\"+t,n=d),e&&n))break}}return u&&(e=p(e)),e+(n?"\\":"")+(t=s(t.split(/[\\\/]+/),!n).join("\\"))||"."},u.normalize=function(e){var t=h(e),n=t.device,r=t.isUnc,i=t.isAbsolute,o=t.tail,a=/[\\\/]$/.test(o);return(o=s(o.split(/[\\\/]+/),!i).join("\\"))||i||(o="."),o&&a&&(o+="\\"),r&&(n=p(n)),n+(i?"\\":"")+o},u.isAbsolute=function(e){return h(e).isAbsolute},u.join=function(){for(var e=[],t=0;t<arguments.length;t++){var n=arguments[t];if(!o.isString(n))throw new TypeError("Arguments to path.join must be strings");n&&e.push(n)}var r=e.join("\\");return/^[\\\/]{2}[^\\\/]/.test(e[0])||(r=r.replace(/^[\\\/]{2,}/,"\\")),u.normalize(r)},u.relative=function(e,t){e=u.resolve(e),t=u.resolve(t);for(var n=e.toLowerCase(),r=t.toLowerCase(),i=a(t.split("\\")),o=a(n.split("\\")),s=a(r.split("\\")),l=Math.min(o.length,s.length),c=l,d=0;d<l;d++)if(o[d]!==s[d]){c=d;break}if(0==c)return t;var h=[];for(d=c;d<o.length;d++)h.push("..");return(h=h.concat(i.slice(c))).join("\\")},u._makeLong=function(e){if(!o.isString(e))return e;if(!e)return"";var t=u.resolve(e);return/^[a-zA-Z]\:\\/.test(t)?"\\\\?\\"+t:/^\\\\[^?.]/.test(t)?"\\\\?\\UNC\\"+t.substring(2):e},u.dirname=function(e){var t=d(e),n=t[0],r=t[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."},u.basename=function(e,t){var n=d(e)[2];return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},u.extname=function(e){return d(e)[3]},u.format=function(e){if(!o.isObject(e))throw new TypeError("Parameter 'pathObject' must be an object, not "+typeof e);var t=e.root||"";if(!o.isString(t))throw new TypeError("'pathObject.root' must be a string or undefined, not "+typeof e.root);var n=e.dir,r=e.base||"";return n?n[n.length-1]===u.sep?n+r:n+u.sep+r:r},u.parse=function(e){if(!o.isString(e))throw new TypeError("Parameter 'pathString' must be a string, not "+typeof e);var t=d(e);if(!t||4!==t.length)throw new TypeError("Invalid path '"+e+"'");return{root:t[0],dir:t[0]+t[1].slice(0,-1),base:t[2],ext:t[3],name:t[2].slice(0,t[2].length-t[3].length)}},u.sep="\\",u.delimiter=";";var f=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,g={};function m(e){return f.exec(e).slice(1)}g.resolve=function(){for(var e="",t=!1,n=arguments.length-1;n>=-1&&!t;n--){var i=n>=0?arguments[n]:r.cwd();if(!o.isString(i))throw new TypeError("Arguments to path.resolve must be strings");i&&(e=i+"/"+e,t="/"===i[0])}return(t?"/":"")+(e=s(e.split("/"),!t).join("/"))||"."},g.normalize=function(e){var t=g.isAbsolute(e),n=e&&"/"===e[e.length-1];return(e=s(e.split("/"),!t).join("/"))||t||(e="."),e&&n&&(e+="/"),(t?"/":"")+e},g.isAbsolute=function(e){return"/"===e.charAt(0)},g.join=function(){for(var e="",t=0;t<arguments.length;t++){var n=arguments[t];if(!o.isString(n))throw new TypeError("Arguments to path.join must be strings");n&&(e+=e?"/"+n:n)}return g.normalize(e)},g.relative=function(e,t){e=g.resolve(e).substr(1),t=g.resolve(t).substr(1);for(var n=a(e.split("/")),r=a(t.split("/")),i=Math.min(n.length,r.length),o=i,s=0;s<i;s++)if(n[s]!==r[s]){o=s;break}var l=[];for(s=o;s<n.length;s++)l.push("..");return(l=l.concat(r.slice(o))).join("/")},g._makeLong=function(e){return e},g.dirname=function(e){var t=m(e),n=t[0],r=t[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."},g.basename=function(e,t){var n=m(e)[2];return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},g.extname=function(e){return m(e)[3]},g.format=function(e){if(!o.isObject(e))throw new TypeError("Parameter 'pathObject' must be an object, not "+typeof e);var t=e.root||"";if(!o.isString(t))throw new TypeError("'pathObject.root' must be a string or undefined, not "+typeof e.root);return(e.dir?e.dir+g.sep:"")+(e.base||"")},g.parse=function(e){if(!o.isString(e))throw new TypeError("Parameter 'pathString' must be a string, not "+typeof e);var t=m(e);if(!t||4!==t.length)throw new TypeError("Invalid path '"+e+"'");return t[1]=t[1]||"",t[2]=t[2]||"",t[3]=t[3]||"",{root:t[0],dir:t[0]+t[1].slice(0,-1),base:t[2],ext:t[3],name:t[2].slice(0,t[2].length-t[3].length)}},g.sep="/",g.delimiter=":",e.exports=i?u:g,e.exports.posix=g,e.exports.win32=u},155:e=>{var t,n,r=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function s(e){if(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i}catch(e){t=i}try{n="function"==typeof clearTimeout?clearTimeout:o}catch(e){n=o}}();var a,l=[],c=!1,u=-1;function d(){c&&a&&(c=!1,a.length?l=a.concat(l):u=-1,l.length&&h())}function h(){if(!c){var e=s(d);c=!0;for(var t=l.length;t;){for(a=l,l=[];++u<t;)a&&a[u].run();u=-1,t=l.length}a=null,c=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===o||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function f(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new p(e,t)),1!==l.length||c||s(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=f,r.addListener=f,r.once=f,r.off=f,r.removeListener=f,r.removeAllListeners=f,r.emit=f,r.prependListener=f,r.prependOnceListener=f,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},384:e=>{e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},539:(e,t,n)=>{var r=n(155),i=/%[sdj%]/g;t.format=function(e){if(!y(e)){for(var t=[],n=0;n<arguments.length;n++)t.push(a(arguments[n]));return t.join(" ")}n=1;for(var r=arguments,o=r.length,s=String(e).replace(i,(function(e){if("%%"===e)return"%";if(n>=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}})),l=r[n];n<o;l=r[++n])g(l)||!b(l)?s+=" "+l:s+=" "+a(l);return s},t.deprecate=function(e,i){if(v(n.g.process))return function(){return t.deprecate(e,i).apply(this,arguments)};if(!0===r.noDeprecation)return e;var o=!1;return function(){if(!o){if(r.throwDeprecation)throw new Error(i);r.traceDeprecation?console.trace(i):console.error(i),o=!0}return e.apply(this,arguments)}};var o,s={};function a(e,n){var r={seen:[],stylize:c};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),f(n)?r.showHidden=n:n&&t._extend(r,n),v(r.showHidden)&&(r.showHidden=!1),v(r.depth)&&(r.depth=2),v(r.colors)&&(r.colors=!1),v(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=l),u(r,e,r.depth)}function l(e,t){var n=a.styles[t];return n?"["+a.colors[n][0]+"m"+e+"["+a.colors[n][1]+"m":e}function c(e,t){return e}function u(e,n,r){if(e.customInspect&&n&&x(n.inspect)&&n.inspect!==t.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,e);return y(i)||(i=u(e,i,r)),i}var o=function(e,t){if(v(t))return e.stylize("undefined","undefined");if(y(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return m(t)?e.stylize(""+t,"number"):f(t)?e.stylize(""+t,"boolean"):g(t)?e.stylize("null","null"):void 0}(e,n);if(o)return o;var s=Object.keys(n),a=function(e){var t={};return e.forEach((function(e,n){t[e]=!0})),t}(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(n)),C(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return d(n);if(0===s.length){if(x(n)){var l=n.name?": "+n.name:"";return e.stylize("[Function"+l+"]","special")}if(_(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(w(n))return e.stylize(Date.prototype.toString.call(n),"date");if(C(n))return d(n)}var c,b="",S=!1,A=["{","}"];return p(n)&&(S=!0,A=["[","]"]),x(n)&&(b=" [Function"+(n.name?": "+n.name:"")+"]"),_(n)&&(b=" "+RegExp.prototype.toString.call(n)),w(n)&&(b=" "+Date.prototype.toUTCString.call(n)),C(n)&&(b=" "+d(n)),0!==s.length||S&&0!=n.length?r<0?_(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special"):(e.seen.push(n),c=S?function(e,t,n,r,i){for(var o=[],s=0,a=t.length;s<a;++s)O(t,String(s))?o.push(h(e,t,n,r,String(s),!0)):o.push("");return i.forEach((function(i){i.match(/^\d+$/)||o.push(h(e,t,n,r,i,!0))})),o}(e,n,r,a,s):s.map((function(t){return h(e,n,r,a,t,S)})),e.seen.pop(),function(e,t,n){return e.reduce((function(e,t){return t.indexOf("\n"),e+t.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}(c,b,A)):A[0]+b+A[1]}function d(e){return"["+Error.prototype.toString.call(e)+"]"}function h(e,t,n,r,i,o){var s,a,l;if((l=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?a=l.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):l.set&&(a=e.stylize("[Setter]","special")),O(r,i)||(s="["+i+"]"),a||(e.seen.indexOf(l.value)<0?(a=g(n)?u(e,l.value,null):u(e,l.value,n-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map((function(e){return" "+e})).join("\n").substr(2):"\n"+a.split("\n").map((function(e){return" "+e})).join("\n")):a=e.stylize("[Circular]","special")),v(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function p(e){return Array.isArray(e)}function f(e){return"boolean"==typeof e}function g(e){return null===e}function m(e){return"number"==typeof e}function y(e){return"string"==typeof e}function v(e){return void 0===e}function _(e){return b(e)&&"[object RegExp]"===S(e)}function b(e){return"object"==typeof e&&null!==e}function w(e){return b(e)&&"[object Date]"===S(e)}function C(e){return b(e)&&("[object Error]"===S(e)||e instanceof Error)}function x(e){return"function"==typeof e}function S(e){return Object.prototype.toString.call(e)}function A(e){return e<10?"0"+e.toString(10):e.toString(10)}t.debuglog=function(e){if(v(o)&&(o=r.env.NODE_DEBUG||""),e=e.toUpperCase(),!s[e])if(new RegExp("\\b"+e+"\\b","i").test(o)){var n=r.pid;s[e]=function(){var r=t.format.apply(t,arguments);console.error("%s %d: %s",e,n,r)}}else s[e]=function(){};return s[e]},t.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=p,t.isBoolean=f,t.isNull=g,t.isNullOrUndefined=function(e){return null==e},t.isNumber=m,t.isString=y,t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=v,t.isRegExp=_,t.isObject=b,t.isDate=w,t.isError=C,t.isFunction=x,t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=n(384);var E=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function T(){var e=new Date,t=[A(e.getHours()),A(e.getMinutes()),A(e.getSeconds())].join(":");return[e.getDate(),E[e.getMonth()],t].join(" ")}function O(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.log=function(){console.log("%s - %s",T(),t.format.apply(t,arguments))},t.inherits=n(717),t._extend=function(e,t){if(!t||!b(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{PluginLocal:()=>Ae,pluginHelpers:()=>e,setupPluginCore:()=>Te});var e={};n.r(e),n.d(e,{IS_DEV:()=>g,PROTOCOL_FILE:()=>m,PROTOCOL_LSP:()=>y,URL_LSP:()=>v,deepMerge:()=>x,deferred:()=>L,genID:()=>S,getAppPathRoot:()=>b,getSDKPathRoot:()=>w,invokeHostExportedApi:()=>k,isObject:()=>C,path:()=>f,safetyPathJoin:()=>T,safetyPathNormalize:()=>O,setupIframeSandbox:()=>I,setupInjectedStyle:()=>F,setupInjectedTheme:()=>D,setupInjectedUI:()=>M,transformableEvent:()=>j,ucFirst:()=>A,withFileProtocol:()=>E});var t=n(729),i=n.n(t),o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function s(e){return e.toLowerCase()}Object.create,Object.create;var a=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],l=/[^A-Z0-9]+/gi;function c(e,t,n){return t instanceof RegExp?e.replace(t,n):t.reduce((function(e,t){return e.replace(t,n)}),e)}function u(e,t){return void 0===t&&(t={}),function(e,t){return void 0===t&&(t={}),function(e,t){void 0===t&&(t={});for(var n=t.splitRegexp,r=void 0===n?a:n,i=t.stripRegexp,o=void 0===i?l:i,u=t.transform,d=void 0===u?s:u,h=t.delimiter,p=void 0===h?" ":h,f=c(c(e,r,"$1\0$2"),o,"\0"),g=0,m=f.length;"\0"===f.charAt(g);)g++;for(;"\0"===f.charAt(m-1);)m--;return f.slice(g,m).split("\0").map(d).join(p)}(e,o({delimiter:"."},t))}(e,o({delimiter:"_"},t))}var d=n(520),h=n(856),p=n.n(h);const f="win32"===navigator.platform.toLowerCase()?d.win32:d.posix,g=!1,m="file://",y="lsp://",v=y+"logseq.io/";let _;async function b(){return _||(_=await k("_callApplication","getAppPath"))}async function w(){return g?localStorage.getItem("LSP_DEV_SDK_ROOT")||"http://localhost:8080":T(await b(),"js")}function C(e){return e===Object(e)&&!Array.isArray(e)}function x(e,...t){if(!t.length)return e;const n=e;if(C(n)){const e=t.length;for(let r=0;r<e;r+=1){const e=t[r];if(C(e))for(const t in e)e.hasOwnProperty(t)&&(C(e[t])?(n[t]&&C(n[t])||(n[t]={}),x(n[t],e[t])):Array.isArray(n[t])&&Array.isArray(e[t])?n[t]=Array.from(new Set(n[t].concat(e[t]))):n[t]=e[t])}}return n}function S(){return"_"+Math.random().toString(36).substr(2,9)}function A(e){return e.charAt(0).toUpperCase()+e.slice(1)}function E(e){return e?(/^(http|file|lsp)/.test(e)||(e=m+e),e):""}function T(e,...t){try{const n=new URL(e);if(!n.origin)throw new Error(null);const r=f.join(e.substr(n.origin.length),...t);return n.origin+r}catch(n){return f.join(e,...t)}}function O(e){return e?.match(/^(http?|lsp|assets):/)||(e=f.normalize(e)),e}function L(e,t){let n,r,i=!1;const o=t=>n=>{e&&clearTimeout(e),t(n),i=!0},s=new Promise(((i,s)=>{n=o(i),r=o(s),e&&(e=setTimeout((()=>r(new Error(`[deferred timeout] ${t}`))),e))}));return{created:Date.now(),setTag:e=>t=e,resolve:n,reject:r,promise:s,get settled(){return i}}}function k(e,...t){const n=u(e=e?.startsWith("_call")?e:e?.replace(/^[_$]+/,"")),r=window.logseq?.api||{},i=r[n]||window.apis[n]||r[e]||window.apis[e];if(!i)throw new Error(`Not existed method #${e}`);return"function"!=typeof i?i:i.apply(null,t)}function I(e,t){const n=document.createElement("iframe");return n.classList.add("lsp-iframe-sandbox"),Object.entries(e).forEach((([e,t])=>{n.setAttribute(e,t)})),t.appendChild(n),async()=>{t.removeChild(n)}}function F(e,t){const n=t["data-injected-style"];let r=n&&document.querySelector(`[data-injected-style=${n}]`);if(!r)return r=document.createElement("style"),r.textContent=e,t&&Object.entries(t).forEach((([e,t])=>{r.setAttribute(e,t)})),document.head.append(r),()=>{document.head.removeChild(r)};r.textContent=e}const R=new Map;function M(e,t,n){let r,i,o="";const s=this;"slot"in e?(o=e.slot,r=`#${o}`):"path"in e?r=e.path:i=!0;const a=`${e.key}-${o}-${s.id}`,l=`${e.key}--${s.id}`,c=i?document.body:r&&document.querySelector(r);if(!c)return void console.error(`${this.debugTag} can not resolve selector target ${r}`);if(!e.template)return void R.get(a)?.call(null);e.template=p().sanitize(e.template,{ADD_TAGS:["iframe"],ALLOW_UNKNOWN_PROTOCOLS:!0,ADD_ATTR:["allow","src","allowfullscreen","frameborder","scrolling"]});let u,d,h=document.querySelector(`#${a}`),f=i?h?.querySelector(".ls-ui-float-content"):h;if(!f)return h=document.createElement("div"),h.id=a,h.dataset.injectedUi=l||"",i?(f=document.createElement("div"),f.classList.add("ls-ui-float-content"),h.appendChild(f)):f=h,f.innerHTML=e.template,t&&Object.entries(t).forEach((([e,t])=>{h.setAttribute(e,t)})),e.style&&Object.entries(e.style).forEach((([e,t])=>{h.style[e]=t})),i&&(h.setAttribute("draggable","true"),h.setAttribute("resizable","true"),e.close&&(h.dataset.close=e.close),h.classList.add("lsp-ui-float-container","visible"),s._setupResizableContainer(h,l),d=s._setupDraggableContainer(h,{key:l,close:()=>u(),title:t?.title})),o&&e.reset&&Array.from(c.querySelectorAll("[data-injected-ui]")).map((e=>e.id))?.forEach((e=>{R.get(e)?.call(null)})),c.appendChild(h),["click","focus","focusin","focusout","blur","dblclick","keyup","keypress","keydown","change","input"].forEach((e=>{h.addEventListener(e,(t=>{const n=t.target.closest(`[data-on-${e}]`);if(!n)return;const r=n.dataset[`on${A(e)}`];r&&s.caller?.callUserModel(r,j(n))}),!1)})),n?.({el:h,float:i}),u=()=>{d?.(),R.delete(a),c.removeChild(h)},R.set(a,u),u;{f.innerHTML=e.template,t&&Object.entries(t).forEach((([e,t])=>{h.setAttribute(e,t)}));let n=null!=h.dataset.dx;e.style&&Object.entries(e.style).forEach((([e,t])=>{n&&["left","top","bottom","right","width","height"].includes(e)||(h.style[e]=t)}))}}function j(e,t){const n={};if(e){const t=e.dataset,r="rect";["value","id","className","dataset",r].forEach((i=>{let o;switch(i){case r:if(!t.hasOwnProperty(r))return;o=e.getBoundingClientRect().toJSON();break;default:o=e[i]}"object"==typeof o&&(o={...o}),n[i]=o}))}return n}let P=null;function D(e){if(P?.call(),!e)return;const t=document.createElement("link");return t.rel="stylesheet",t.href=e,document.head.appendChild(t),P=()=>{try{document.head.removeChild(t)}catch(e){console.error(e)}P=null}}var N=n(227),U=n.n(N);const z="application/x-postmate-v1+json";let $=0;const H={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},W=(e,t)=>!("string"==typeof t&&e.origin!==t||!e.data||"object"==typeof e.data&&!("postmate"in e.data)||e.data.type!==z||!H[e.data.postmate]);class B{parent;frame;child;events={};childOrigin;listener;constructor(e){this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.listener=e=>{if(!W(e,this.childOrigin))return!1;const{data:t,name:n}=((e||{}).data||{}).value||{};"emit"===e.data.postmate&&n in this.events&&this.events[n].forEach((e=>{e.call(this,t)}))},this.parent.addEventListener("message",this.listener,!1)}get(e){return new Promise((t=>{const n=++$,r=e=>{e.data.uid===n&&"reply"===e.data.postmate&&(this.parent.removeEventListener("message",r,!1),t(e.data.value))};this.parent.addEventListener("message",r,!1),this.child.postMessage({postmate:"request",type:z,property:e,uid:n},this.childOrigin)}))}call(e,t){this.child.postMessage({postmate:"call",type:z,property:e,data:t},this.childOrigin)}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}destroy(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)}}class q{model;parent;parentOrigin;child;constructor(e){this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",(e=>{if(!W(e,this.parentOrigin))return;const{property:t,uid:n,data:r}=e.data;"call"!==e.data.postmate?((e,t)=>{const n="function"==typeof e[t]?e[t]():e[t];return Promise.resolve(n)})(this.model,t).then((r=>{e.source.postMessage({property:t,postmate:"reply",type:z,uid:n,value:r},e.origin)})):t in this.model&&"function"==typeof this.model[t]&&this.model[t](r)}))}emit(e,t){this.parent.postMessage({postmate:"emit",type:z,value:{name:e,data:t}},this.parentOrigin)}}class G{static debug=!1;container;parent;frame;child;childOrigin;url;model;static Model;constructor(e){this.container=e.container,this.url=e.url,this.parent=window,this.frame=document.createElement("iframe"),e.id&&(this.frame.id=e.id),e.name&&(this.frame.name=e.name),this.frame.classList.add.apply(this.frame.classList,e.classListArray||[]),this.container.appendChild(this.frame),this.child=this.frame.contentWindow,this.model=e.model||{}}sendHandshake(e){const t=(e=>{const t=document.createElement("a");t.href=e;const n=t.protocol.length>4?t.protocol:window.location.protocol,r=t.host.length?"80"===t.port||"443"===t.port?t.hostname:t.host:window.location.host;return t.origin||`${n}//${r}`})(e=e||this.url);let n,r=0;return new Promise(((i,o)=>{const s=e=>!!W(e,t)&&("handshake-reply"===e.data.postmate?(clearInterval(n),this.parent.removeEventListener("message",s,!1),this.childOrigin=e.origin,i(new B(this))):o("Failed handshake"));this.parent.addEventListener("message",s,!1);const a=()=>{r++,this.child.postMessage({postmate:"handshake",type:z,model:this.model},t),5===r&&clearInterval(n)};this.frame.addEventListener("load",(()=>{a(),n=setInterval(a,500)})),this.frame.src=e}))}}class J{child;model;parent;parentOrigin;constructor(e){this.child=window,this.model=e,this.parent=this.child.parent}sendHandshakeReply(){return new Promise(((e,t)=>{const n=r=>{if(r.data.postmate){if("handshake"===r.data.postmate){this.child.removeEventListener("message",n,!1),r.source.postMessage({postmate:"handshake-reply",type:z},r.origin),this.parentOrigin=r.origin;const t=r.data.model;return t&&Object.keys(t).forEach((e=>{this.model[e]=t[e]})),e(new q(this))}return t("Handshake Reply Failed")}};this.child.addEventListener("message",n,!1)}))}}class Z{ctx;constructor(e){this.ctx=e}get ctxId(){return this.ctx.baseInfo.id}setItem(e,t){return this.ctx.caller.callAsync("api:call",{method:"write-plugin-storage-file",args:[this.ctxId,e,t]})}getItem(e){return this.ctx.caller.callAsync("api:call",{method:"read-plugin-storage-file",args:[this.ctxId,e]})}removeItem(e){return this.ctx.caller.call("api:call",{method:"unlink-plugin-storage-file",args:[this.ctxId,e]})}clear(){return this.ctx.caller.call("api:call",{method:"clear-plugin-storage-files",args:[this.ctxId]})}hasItem(e){return this.ctx.caller.callAsync("api:call",{method:"exist-plugin-storage-file",args:[this.ctxId,e]})}}const K=Symbol.for("proxy-continue"),V=U()("LSPlugin:user");function Y(e,t,n){if("function"!=typeof n)return!1;const{key:r,label:i,desc:o,palette:s,keybinding:a}=t,l=`SimpleCommandHook${r}${++Q}`;this.Editor["on"+l](n),this.caller?.call("api:call",{method:"register-plugin-simple-command",args:[this.baseInfo.id,[{key:r,label:i,type:e,desc:o,keybinding:a},["editor/hook",l]],s]})}const X={registerCommand:Y,registerCommandPalette(e,t){const{key:n,label:r,keybinding:i}=e;return Y.call(this,"global-palette-command",{key:n,label:r,palette:!0,keybinding:i},t)},registerUIItem(e,t){const n=this.baseInfo.id;this.caller?.call("api:call",{method:"register-plugin-ui-item",args:[n,e,t]})},registerPageMenuItem(e,t){if("function"!=typeof t)return!1;const n=e+"_"+this.baseInfo.id,r=e;Y.call(this,"page-menu-item",{key:n,label:r},t)},setFullScreen(e){const t=(...e)=>this._callWin("setFullScreen",...e);"toggle"===e?this._callWin("isFullScreen").then((e=>{e?t():t(!0)})):e?t(!0):t()}};let Q=0;const ee={registerSlashCommand(e,t){V("Register slash command #",this.baseInfo.id,e,t),"function"==typeof t&&(t=[["editor/clear-current-slash",!1],["editor/restore-saved-cursor"],["editor/hook",t]]),t=t.map((e=>{const[t,...n]=e;switch(t){case"editor/hook":let r=n[0],i=()=>{this.caller?.callUserModel(r)};"function"==typeof r&&(i=r);const o=`SlashCommandHook${t}${++Q}`;e[1]=o,this.Editor["on"+o](i)}return e})),this.caller?.call("api:call",{method:"register-plugin-slash-command",args:[this.baseInfo.id,[e,t]]})},registerBlockContextMenuItem(e,t){if("function"!=typeof t)return!1;const n=e+"_"+this.baseInfo.id,r=e;Y.call(this,"block-context-menu-item",{key:n,label:r},t)},scrollToBlockInPage(e,t){const n="block-content-"+t;this.App.pushState("page",{name:e},{anchor:n})}},te={};class ne extends(i()){_baseInfo;_caller;_connected=!1;_ui=new Map;_fileStorage;_beforeunloadCallback;constructor(e,t){super(),this._baseInfo=e,this._caller=t,t.on("sys:ui:visible",(e=>{e?.toggle&&this.toggleMainUI()})),t.on("settings:changed",(e=>{const t=Object.assign({},this.settings),n=Object.assign(this._baseInfo.settings,e);this.emit("settings:changed",{...n},t)})),t.on("beforeunload",(async e=>{const{actor:n,...r}=e,i=this._beforeunloadCallback;try{i&&await i(r),n?.resolve(null)}catch(e){console.debug(`${t.debugTag} [beforeunload] `,e),n?.reject(e)}})),this._fileStorage=new Z(this)}async ready(e,t){if(!this._connected)try{"function"==typeof e&&(t=e,e={});let n=await this._caller.connectToParent(e);n=x(this._baseInfo,n),this._connected=!0,n?.id&&(this._caller.debugTag=`#${n.id} [${n.name}]`),t&&t.call(this,n)}catch(e){console.error("[LSPlugin Ready Error]",e)}}ensureConnected(){if(!this._connected)throw new Error("not connected")}beforeunload(e){"function"==typeof e&&(this._beforeunloadCallback=e)}provideModel(e){return this.caller._extendUserModel(e),this}provideTheme(e){return this.caller.call("provider:theme",e),this}provideStyle(e){return this.caller.call("provider:style",e),this}provideUI(e){return this.caller.call("provider:ui",e),this}updateSettings(e){this.caller.call("settings:update",e)}setMainUIAttrs(e){this.caller.call("main-ui:attrs",e)}setMainUIInlineStyle(e){this.caller.call("main-ui:style",e)}hideMainUI(e){const t={key:0,visible:!1,cursor:e?.restoreEditingCursor};this.caller.call("main-ui:visible",t),this.emit("ui:visible:changed",t),this._ui.set(t.key,t)}showMainUI(e){const t={key:0,visible:!0,autoFocus:e?.autoFocus};this.caller.call("main-ui:visible",t),this.emit("ui:visible:changed",t),this._ui.set(t.key,t)}toggleMainUI(){const e=this._ui.get(0);e&&e.visible?this.hideMainUI():this.showMainUI()}get isMainUIVisible(){const e=this._ui.get(0);return Boolean(e&&e.visible)}get connected(){return this._connected}get baseInfo(){return this._baseInfo}get settings(){return this.baseInfo?.settings}get caller(){return this._caller}resolveResourceFullUrl(e){if(this.ensureConnected(),e)return e=e.replace(/^[.\\/]+/,""),T(this._baseInfo.lsr,e)}_makeUserProxy(e,t){const n=this,r=this.caller;return new Proxy(e,{get(e,i,o){const s=e[i];return function(...e){if(!s||s.apply(n,e)===K){if(t){const n=i.toString().match(/^(once|off|on)/i);if(null!=n){const i=n[0].toLowerCase(),o=n.input.slice(i.length),s=`hook:${t}:${u(o)}`,a=e[0];return r[i](s,a),"off"!==i?()=>r.off(s,a):void 0}}return r.callAsync("api:call",{tag:t,method:i,args:e})}}}})}_callWin(...e){return this._caller.callAsync("api:call",{method:"_callMainWin",args:e})}get App(){return this._makeUserProxy(X,"app")}get Editor(){return this._makeUserProxy(ee,"editor")}get DB(){return this._makeUserProxy(te)}get FileStorage(){return this._fileStorage}}if(null==window.__LSP__HOST__){const e=new me(null);window.logseq=new ne({},e)}const{importHTML:re,createSandboxContainer:ie}=window.QSandbox||{};function oe(e,t){return e.startsWith("http")?fetch(e,t):(e=e.replace("file://",""),new Promise((async(t,n)=>{try{const n=await window.apis.doAction(["readFile",e]);t({text:()=>n})}catch(e){console.error(e),n(e)}})))}class se extends(i()){_pluginLocal;_frame;_root;_loaded=!1;_unmountFns=[];constructor(e){super(),this._pluginLocal=e,e._dispose((()=>{this._unmount()}))}async load(){const{name:e,entry:t}=this._pluginLocal.options;if(this.loaded||!t)return;const{template:n,execScripts:r}=await re(t,{fetch:oe});this._mount(n,document.body);const i=ie(e,{elementGetter:()=>this._root?.firstChild}).instance.proxy;i.__shadow_mode__=!0,i.LSPluginLocal=this._pluginLocal,i.LSPluginShadow=this,i.LSPluginUser=i.logseq=new ne(this._pluginLocal.toJSON(),this._pluginLocal.caller);const o=await r(i,!0);this._unmountFns.push(o.unmount),this._loaded=!0}_mount(e,t){const n=this._frame=document.createElement("div");n.classList.add("lsp-shadow-sandbox"),n.id=this._pluginLocal.id,this._root=n.attachShadow({mode:"open"}),this._root.innerHTML=`<div>${e}</div>`,t.appendChild(n),this.emit("mounted")}_unmount(){for(const e of this._unmountFns)e&&e.call(null)}destroy(){this.frame?.parentNode?.removeChild(this.frame)}get loaded(){return this._loaded}get document(){return this._root?.firstChild}get frame(){return this._frame}}const ae=U()("LSPlugin:caller"),le="#await#response#",ce="#lspmsg#",ue="#lspmsg#error#",de="#lspmsg#settings#",he="#lspmsg#beforeunload#",pe="#lspmsg#reply#",fe="#lspmsg#ready#",ge=e=>`#lspmsg#${e}`;class me extends(i()){_pluginLocal;_connected=!1;_parent;_child;_shadow;_status;_userModel={};_call;_callUserModel;_debugTag="";constructor(e){super(),this._pluginLocal=e,e&&(this._debugTag=e.debugTag)}async connectToChild(){if(this._connected)return;const{shadow:e}=this._pluginLocal;e?await this._setupShadowSandbox():await this._setupIframeSandbox()}async connectToParent(e={}){if(this._connected)return;const t=this,n=null!=this._pluginLocal;let r=0,i=0;const o=new Map,s=L(5e3),a=this._extendUserModel({[fe]:async e=>{a[ge(e?.pid)]=({type:e,payload:n})=>{ae(`[call from host (_call)] ${this._debugTag}`,e,n),t.emit(e,n)},await s.resolve()},[he]:async e=>{const n=L(1e4);t.emit("beforeunload",Object.assign({actor:n},e)),await n.promise},[de]:async({type:e,payload:n})=>{t.emit("settings:changed",n)},[ce]:async({ns:e,type:n,payload:r})=>{ae(`[call from host (async)] ${this._debugTag}`,e,n,r),e&&e.startsWith("hook")?t.emit(`${e}:${n}`,r):t.emit(n,r)},[pe]:({_sync:e,result:t})=>{if(ae(`[sync reply] #${e}`,t),o.has(e)){const n=o.get(e);n&&(t?.hasOwnProperty(ue)?n.reject(t[ue]):n.resolve(t),o.delete(e))}},...e});if(n)return await s.promise,JSON.parse(JSON.stringify(this._pluginLocal?.toJSON()));const l=new J(a).sendHandshakeReply();return this._status="pending",await l.then((e=>{this._child=e,this._connected=!0,this._call=async(t,n={},r)=>{if(r){const e=++i;o.set(e,r),n._sync=e,r.setTag(`async call #${e}`),ae("async call #",e)}return e.emit(ge(a.baseInfo.id),{type:t,payload:n}),r?.promise},this._callUserModel=async(e,t)=>{try{a[e](t)}catch(t){ae(`[model method] #${e} not existed`)}},r=setInterval((()=>{if(o.size>100)for(const[e,t]of o)t.settled&&o.delete(e)}),18e5)})).finally((()=>{this._status=void 0})),await s.promise,a.baseInfo}async call(e,t={}){return this._call?.call(this,e,t)}async callAsync(e,t={}){const n=L(1e4);return this._call?.call(this,e,t,n)}async callUserModel(e,t={}){return this._callUserModel?.call(this,e,t)}async _setupIframeSandbox(){const e=this._pluginLocal,t=e.id,n=new URL(e.options.entry);n.searchParams.set("__v__",g?Date.now().toString():e.options.version);const r=document.querySelector(`#${t}`);r&&r.parentElement.removeChild(r);const i=document.createElement("div");i.classList.add("lsp-iframe-sandbox-container"),i.id=t;{const e=this._pluginLocal.settings.get("layout")?.[0];if(e){i.dataset.inited_layout="true";const{width:t,height:n,left:r,top:o}=e;Object.assign(i.style,{width:t+"px",height:n+"px",left:r+"px",top:o+"px"})}}document.body.appendChild(i);let o,s=new G({id:t+"_iframe",container:i,url:n.href,classListArray:["lsp-iframe-sandbox"],model:{baseInfo:JSON.parse(JSON.stringify(e.toJSON()))}}).sendHandshake();return this._status="pending",new Promise(((t,n)=>{o=setTimeout((()=>{n(new Error("handshake Timeout"))}),3e3),s.then((n=>{this._parent=n,this._connected=!0,this.emit("connected"),n.on(ge(e.id),(({type:e,payload:t})=>{ae("[call from plugin] ",e,t),this._pluginLocal?.emit(e,t||{})})),this._call=async(...t)=>{await n.call(ge(e.id),{type:t[0],payload:Object.assign(t[1]||{},{$$pid:e.id})})},this._callUserModel=async(e,t)=>{if(e.startsWith(le))return await n.get(e.replace(le,""));n.call(e,t)},t(null)})).catch((e=>{n(e)})).finally((()=>{clearTimeout(o)}))})).catch((e=>{throw ae("[iframe sandbox] error",e),e})).finally((()=>{this._status=void 0}))}async _setupShadowSandbox(){const e=this._pluginLocal,t=this._shadow=new se(e);try{this._status="pending",await t.load(),this._connected=!0,this.emit("connected"),this._call=async(t,n={},r)=>(r&&(n.actor=r),this._pluginLocal?.emit(t,Object.assign(n,{$$pid:e.id})),r?.promise),this._callUserModel=async(...e)=>{let t=e[0];t?.startsWith(le)&&(t=t.replace(le,""));const n=e[1]||{},r=this._userModel[t];"function"==typeof r&&await r.call(null,n)}}catch(e){throw ae("[shadow sandbox] error",e),e}finally{this._status=void 0}}_extendUserModel(e){return Object.assign(this._userModel,e)}_getSandboxIframeContainer(){return this._parent?.frame.parentNode}_getSandboxShadowContainer(){return this._shadow?.frame.parentNode}_getSandboxIframeRoot(){return this._parent?.frame}_getSandboxShadowRoot(){return this._shadow?.frame}set debugTag(e){this._debugTag=e}async destroy(){let e=null;this._parent&&(e=this._getSandboxIframeContainer(),await this._parent.destroy()),this._shadow&&(e=this._getSandboxShadowContainer(),this._shadow.destroy()),e?.parentNode.removeChild(e)}}const ye=U()("LSPlugin:core"),ve="plugins";class _e extends(i()){_userPluginSettings;_settings={disabled:!1};constructor(e){super(),this._userPluginSettings=e,Object.assign(this._settings,e)}get(e){return this._settings[e]}set(e,t){const n=x({},this._settings);if("string"==typeof e){if(this._settings[e]==t)return;this._settings[e]=t}else{if(!C(e))return;x(this._settings,e)}this.emit("change",Object.assign({},this._settings),n)}set settings(e){this._settings=e}get settings(){return this._settings}toJSON(){return this._settings}}class be extends(i()){_tag;_logs=[];constructor(e){super(),this._tag=e}write(e,t){let n=t.reduce(((e,t)=>(t&&t instanceof Error?e+=`${t.message} ${t.stack}`:e+=t.toString(),e)),`[${this._tag}][${(new Date).toLocaleTimeString()}] `);this._logs.push([e,n]),this.emit("change")}clear(){this._logs=[],this.emit("change")}info(...e){this.write("INFO",e)}error(...e){this.write("ERROR",e)}warn(...e){this.write("WARN",e)}toJSON(){return this._logs}}var we;function Ce(e,t){return t&&e.startsWith(m+t)&&(e=T(v,e.substr(m.length+t.length))),e}!function(e){e.LOADING="loading",e.UNLOADING="unloading",e.LOADED="loaded",e.UNLOADED="unload",e.ERROR="error"}(we||(we={}));class xe extends Error{constructor(e){super(e),this.name=xe.name}}class Se extends Error{constructor(e){super(e),this.name=Se.name}}class Ae extends(i()){_options;_themeMgr;_ctx;_disposes=[];_id;_status=we.UNLOADED;_loadErr;_localRoot;_dotSettingsFile;_caller;constructor(e,t,n){var r;super(),this._options=e,this._themeMgr=t,this._ctx=n,this._id=e.key||S(),(r=this).on("settings:update",(e=>{e&&r.settings?.set(e)})),function(e){const t=e=>`main-ui:${e}`;e.on(t("visible"),(({visible:t,toggle:n,cursor:r,autoFocus:i})=>{const o=e.getMainUIContainer();o?.classList[n?"toggle":t?"add":"remove"]("visible"),t&&!e.shadow&&o&&!1!==i&&o.querySelector("iframe")?.contentWindow?.focus(),r&&k("restore_editing_cursor")})),e.on(t("attrs"),(t=>{const n=e.getMainUIContainer();Object.entries(t).forEach((([t,r])=>{n?.setAttribute(t,r),"draggable"===t&&r&&e._dispose(e._setupDraggableContainer(n,{title:e.options.name,close:()=>{e.caller.call("sys:ui:visible",{toggle:!0})}})),"resizable"===t&&r&&e._dispose(e._setupResizableContainer(n))}))})),e.on(t("style"),(t=>{const n=e.getMainUIContainer(),r=!!n.dataset.inited_layout;Object.entries(t).forEach((([e,t])=>{r&&["left","top","bottom","right","width","height"].includes(e)||(n.style[e]=t)}))}))}(this),function(e){let t=e=>`provider:${e}`,n=!1;e.on(t("theme"),(t=>{e.themeMgr.registerTheme(e.id,t),n||(e._dispose((()=>{e.themeMgr.unregisterTheme(e.id)})),n=!0)})),e.on(t("style"),(t=>{let n;"string"!=typeof t&&(n=t.key,t=t.style),t&&t.trim()&&e._dispose(F(t,{"data-injected-style":n?`${n}-${e.id}`:"","data-ref":e.id}))})),e.on(t("ui"),(t=>{e._onHostMounted((()=>{e._dispose(M.call(e,t,Object.assign({"data-ref":e.id},t.attrs||{}),(({el:t,float:n})=>{if(!n)return;const r=t.dataset.identity;e.layoutCore.move_container_to_top(r)})))}))}))}(this),function(e){e.on("api:call",(async t=>{let n;try{n=await k(t.method,...t.args)}catch(e){n={[ue]:e}}const{_sync:r}=t;if(e.shadow)t.actor&&t.actor.resolve(n);else if(null!=r){const t=t=>{e.caller?.callUserModel(pe,{result:t,_sync:r})};Promise.resolve(n).then(t,t)}}))}(this)}async _setupUserSettings(e){const{_options:t}=this,n=t.logger=new be("Loader");if(!t.settings||e)try{const n=()=>k("load_plugin_user_settings",this.id),[r,i]=await n();this._dotSettingsFile=r;let o=t.settings;if(o||(o=t.settings=new _e(i)),e)return void(o.settings=i);const s=async(e,t)=>{if(ye("Settings changed",this.debugTag,e),!e.disabled&&t.disabled){const[,t]=await n();t.disabled=!1,e=x(e,t),o.settings=e,await this.load()}if(e.disabled&&!t.disabled){const[,t]=await n();t.disabled=!0,e=x(e,t),await this.unload()}e&&k("save_plugin_user_settings",this.id,e)};return o.on("change",s),()=>{}}catch(e){ye("[load plugin user settings Error]",e),n?.error(e)}}getMainUIContainer(){return this.shadow?this.caller?._getSandboxShadowContainer():this.caller?._getSandboxIframeContainer()}_resolveResourceFullUrl(e,t){if(!e?.trim())return;t=t||this._localRoot;const n=/^(http|file)/;if(!n.test(e)){const r=f.join(t,e);e=n.test(r)?r:m+r}return!this.options.effect&&this.isInstalledInDotRoot?Ce(e,this.dotPluginsRoot):e}async _preparePackageConfigs(){const{url:e}=this._options;let t;try{if(!e)throw new Error("Can not resolve package config location");if(ye("prepare package root",e),t=await k("load_plugin_config",e),!t||(t=JSON.parse(t),!t))throw new Error(`Parse package config error #${e}/package.json`)}catch(e){throw new xe(e.message)}const n=this._localRoot=O(e),r=t.logseq||{};["name","author","repository","version","description","repo","title","effect"].concat(this.isInstalledInDotRoot?[]:["devEntry"]).forEach((e=>{this._options[e]=t[e]}));const i=r.entry||r.main||t.main;var o;(o=i)&&/\.(js|html)$/.test(o)&&(this._options.entry=this._resolveResourceFullUrl(i,n),this._options.devEntry=r.devEntry,r.mode&&(this._options.mode=r.mode));const s=r.title||t.title,a=r.icon||t.icon;if(this._options.title=s,this._options.icon=a&&this._resolveResourceFullUrl(a),this.isInstalledInDotRoot)this._id=f.basename(n);else if(r.id)this._id=r.id;else{r.id=this.id;try{await k("save_plugin_config",e,{...t,logseq:r})}catch(e){ye("[save plugin ID Error] ",e)}}const{registeredPlugins:l,isRegistering:c}=this._ctx;if(c&&l.has(r.id))throw new Se("prepare package Error");return async()=>{try{let e=r.themes;e&&await this._loadConfigThemes(Array.isArray(e)?e:[e])}catch(e){ye("[prepare package effect Error]",e)}}}async _tryToNormalizeEntry(){let{entry:e,settings:t,devEntry:n}=this.options;if(n=n||t?.get("_devEntry"),n)return void(this._options.entry=n);if(!e.endsWith(".js"))return;let r=null,i="write_user_tmp_file";this.isInstalledInDotRoot&&(i="write_dotdir_file",r=this._localRoot.replace(this.dotPluginsRoot,""),r=f.join(ve,r));let o=await w(),s=await k(i,`${this._id}_index.html`,`<!doctype html>\n<html lang="en">\n <head>\n <meta charset="UTF-8">\n <title>logseq plugin entry</title>\n <script src="${o}/lsplugin.user.js"><\/script>\n </head>\n <body>\n <div id="app"></div>\n <script src="${e}"><\/script>\n </body>\n</html>`,r);e=Ce(E(f.normalize(s)),this.dotPluginsRoot),this._options.entry=e}async _loadConfigThemes(e){e.forEach((e=>{e.url&&(!e.url.startsWith("http")&&this._localRoot&&(e.url=f.join(this._localRoot,e.url),e.url.startsWith("file:")||(e.url="assets://"+e.url)),this.emit("provider:theme",e))}))}_persistMainUILayoutData(e){const t=this.settings.get("layouts")||[];t[0]=e,this.settings.set("layout",t)}_setupDraggableContainer(e,t={}){const n=e.dataset;if(n.inited_draggable)return;n.identity||(n.identity="dd-"+S());const r=!!t.key,i=document.createElement("div");i.classList.add("draggable-handle"),i.innerHTML=`\n <div class="th">\n <div class="l"><h3>${t.title||""}</h3></div>\n <div class="r">\n <a class="button x"><i class="ti ti-x"></i></a>\n </div>\n </div>\n `,i.querySelector(".x").addEventListener("click",(e=>{t?.close?.(),e.stopPropagation()}),!1),i.addEventListener("mousedown",(e=>{if(e.target?.closest(".r"))return e.stopPropagation(),void e.preventDefault()}),!1),e.prepend(i),e.addEventListener("mousedown",(e=>{this.layoutCore.move_container_to_top(n.identity)}),!0);const o=this.layoutCore.setup_draggable_container_BANG_(e,r?()=>{}:this._persistMainUILayoutData.bind(this));var s;n.inited_draggable="true",t.title&&(s=t.title,i.querySelector("h3").textContent=s);let a=null;if("outside"===n.close){const n=n=>{const r=n.target;e.contains(r)||t.close()};document.addEventListener("click",n,!1),a=()=>{document.removeEventListener("click",n)}}return()=>{o(),a?.()}}_setupResizableContainer(e,t){const n=e.dataset;if(n.inited_resizable)return;n.identity||(n.identity="dd-"+S());const r=document.createElement("div");r.classList.add("resizable-handle"),e.prepend(r);const i=window.frontend.modules.layout.core.setup_resizable_container_BANG_(e,t?()=>{}:this._persistMainUILayoutData.bind(this));return n.inited_resizable="true",i}async load(e){if(!this.pending){this._status=we.LOADING,this._loadErr=void 0;try{let t=await this._preparePackageConfigs();if(this._dispose(await this._setupUserSettings(e?.reload)),this.disabled||await t.call(null),this.disabled||!this.options.entry)return;await this._tryToNormalizeEntry(),this._caller=new me(this),await this._caller.connectToChild();const n=()=>{this._caller?.callUserModel(fe,{pid:this.id})};e?.indicator?e.indicator.promise.then(n):n(),this._dispose((async()=>{await(this._caller?.destroy())}))}catch(e){ye("[Load Plugin Error] ",e),this.logger?.error(e),this._status=we.ERROR,this._loadErr=e}finally{this._loadErr||(this.disabled?this._status=we.UNLOADED:this._status=we.LOADED)}}}async reload(){this.pending||(this._ctx.emit("beforereload",this),await this.unload(),await this.load({reload:!0}),this._ctx.emit("reloaded",this))}async unload(e=!1){if(!this.pending){if(e)return await this.unload(),void(this.isInstalledInDotRoot&&this._ctx.emit("unlink-plugin",this.id));try{this._status=we.UNLOADING;const t={unregister:e};try{await(this._caller?.callUserModel((he,`${le}#lspmsg#beforeunload#`),t)),this.emit("beforeunload",t)}catch(e){console.error("[beforeunload Error]",e)}await this.dispose(),this.emit("unloaded")}catch(e){return ye("[plugin unload Error]",e),!1}finally{this._status=we.UNLOADED}}}async dispose(){for(const e of this._disposes)try{e&&await e()}catch(e){console.error(this.debugTag,"dispose Error",e)}this._disposes=[]}_dispose(e){e&&this._disposes.push(e)}_onHostMounted(e){const t=this._ctx.hostMountedActor;!t||t.settled?e():t?.promise.then(e)}get layoutCore(){return window.frontend.modules.layout.core}get isInstalledInDotRoot(){const e=this.dotConfigRoot,t=this.localRoot;return e&&t&&t.startsWith(e)}get loaded(){return this._status===we.LOADED}get pending(){return[we.LOADING,we.UNLOADING].includes(this._status)}get status(){return this._status}get settings(){return this.options.settings}get logger(){return this.options.logger}get disabled(){return this.settings?.get("disabled")}get caller(){return this._caller}get id(){return this._id}get shadow(){return"shadow"===this.options.mode}get options(){return this._options}get themeMgr(){return this._themeMgr}get debugTag(){const e=this._options?.name;return`#${this._id} ${e??""}`}get localRoot(){return this._localRoot||this._options.url}get loadErr(){return this._loadErr}get dotConfigRoot(){return f.normalize(this._ctx.options.dotConfigRoot)}get dotSettingsFile(){return this._dotSettingsFile}get dotPluginsRoot(){return f.join(this.dotConfigRoot,ve)}toJSON(){const e={...this.options};return e.id=this.id,e.err=this.loadErr,e.usf=this.dotSettingsFile,e.iir=this.isInstalledInDotRoot,e.lsr=this._resolveResourceFullUrl(""),e}}class Ee extends(i()){_options;_isRegistering=!1;_readyIndicator;_hostMountedActor=L();_userPreferences={};_registeredThemes=new Map;_registeredPlugins=new Map;_currentTheme;constructor(e){super(),this._options=e}async loadUserPreferences(){try{const e=await k("load_user_preferences");e&&Object.assign(this._userPreferences,e)}catch(e){ye("[load user preferences Error]",e)}}async saveUserPreferences(e){try{e&&Object.assign(this._userPreferences,e),await k("save_user_preferences",this._userPreferences)}catch(e){ye("[save user preferences Error]",e)}}async activateUserPreferences(){const{theme:e}=this._userPreferences;e&&await this.selectTheme(e,!1)}async register(e,t=!1){if(!Array.isArray(e))return void await this.register([e]);const n=new Map,r=()=>{const e=Array.from(n.values()).reduce(((e,t)=>{const{options:n,status:r,disabled:i}=t.o;return e[t.o.id]={name:n.name,entry:n.entry,status:r,enabled:"boolean"==typeof i?i?"⚫️":"🟢":"🔴",perf:t.e?`${(t.e-t.s).toFixed(2)}ms`:t.o.loadErr},e}),{});console.table(e)};window.__debugPluginsPerfInfo=r;try{this._isRegistering=!0,this._options.dotConfigRoot;const i=this._readyIndicator=L();await this.loadUserPreferences();const o=new Set(this._userPreferences.externals||[]);t&&(e=e.concat([...o].filter((t=>!e.length||e.every((e=>!e.entry&&e.url!==t)))).map((e=>({url:e})))));for(const t of e){const{url:e}=t,r=new Ae(t,this,this),s={o:r,s:performance.now(),e:0};n.set(r.id,s),await r.load({indicator:i});const{loadErr:a}=r;a&&(ye("[Failed LOAD Plugin] #",t),this.emit("error",a),a instanceof xe||a instanceof Se)||(s.e=performance.now(),r.settings?.on("change",(e=>{this.emit("settings-changed",r.id,e),r.caller?.callUserModel(de,{payload:e})})),this._registeredPlugins.set(r.id,r),this.emit("registered",r),r.isInstalledInDotRoot||o.add(e))}await this.saveUserPreferences({externals:Array.from(o)}),await this.activateUserPreferences(),i.resolve("ready")}catch(e){console.error(e)}finally{this._isRegistering=!1,r()}}async reload(e){if(Array.isArray(e))for(const t of e)try{const e=this.ensurePlugin(t);await e.reload()}catch(e){ye(e)}else await this.reload([e])}async unregister(e){if(!Array.isArray(e))return void await this.unregister([e]);const t=[];for(const n of e){const e=this.ensurePlugin(n);e.isInstalledInDotRoot||t.push(e.options.url),await e.unload(!0),this._registeredPlugins.delete(n),this.emit("unregistered",n)}let n=this._userPreferences.externals||[];n.length&&t.length&&await this.saveUserPreferences({externals:n.filter((e=>!t.includes(e)))})}async enable(e){const t=this.ensurePlugin(e);t.pending||(this.emit("beforeenable"),t.settings?.set("disabled",!1),this.emit("enabled",t.id))}async disable(e){const t=this.ensurePlugin(e);t.pending||(this.emit("beforedisable"),t.settings?.set("disabled",!0),this.emit("disabled",t.id))}async _hook(e,t,n,r){for(const[i,o]of this._registeredPlugins)r&&r!==o.id||o.caller?.callUserModel(ce,{ns:e,type:u(t),payload:n})}hookApp(e,t,n){this._hook("hook:app",e,t,n)}hookEditor(e,t,n){this._hook("hook:editor",e,t,n)}_execDirective(e,...t){}ensurePlugin(e){if(e instanceof Ae)return e;const t=this._registeredPlugins.get(e);if(!t)throw new Error(`plugin #${e} not existed.`);return t}hostMounted(){this._hostMountedActor.resolve()}get registeredPlugins(){return this._registeredPlugins}get options(){return this._options}get readyIndicator(){return this._readyIndicator}get hostMountedActor(){return this._hostMountedActor}get isRegistering(){return this._isRegistering}get themes(){return this._registeredThemes}async registerTheme(e,t){if(ye("registered Theme #",e,t),!e)return;let n=this._registeredThemes.get(e);n||this._registeredThemes.set(e,n=[]),n.push(t),this.emit("theme-changed",this.themes,{id:e,...t})}async selectTheme(e,t=!0){this._currentTheme&&this._currentTheme.dis?.();const n=D(e?.url);this.emit("theme-selected",e),t&&await this.saveUserPreferences({theme:e?.url?e:null}),e?.url&&(this._currentTheme={dis:()=>{n(),t&&this.saveUserPreferences({theme:null})},opt:e,pid:e.pid})}async unregisterTheme(e,t=!0){ye("unregistered Theme #",e),this._registeredThemes.has(e)&&(this._registeredThemes.delete(e),this.emit("theme-changed",this.themes,{id:e}),t&&this._currentTheme?.pid==e&&(this._currentTheme.dis?.(),this._currentTheme=null,this.emit("theme-selected",null)))}}function Te(e){const t=new Ee(e);ye("=== 🔗 Setup Logseq Plugin System 🔗 ==="),window.LSPluginCore=t}})(),r})()}));
|