Object.defineProperty(mhchemParser$1,"__esModule",{value:!0}),mhchemParser$1.mhchemParser=void0;varmhchemParser=function(){functione(){}returne.toTex=function(e,t){return_mhchemTexify.go(_mhchemParser.go(e,t),"tex"!==t)},e}();function_mhchemCreateTransitions(e){vart,n,i={};for(tine)for(nine[t]){varr=n.split("|");e[t][n].stateArray=r;for(varo=0;o<r.length;o++)i[r[o]]=[]}for(tine)for(nine[t])for(r=e[t][n].stateArray||[],o=0;o<r.length;o++){vara=e[t][n];a.action_=[].concat(a.action_);for(vars=0;s<a.action_.length;s++)"string"==typeofa.action_[s]&&(a.action_[s]={type_:a.action_[s]});for(varl=t.split("|"),c=0;c<l.length;c++)if("*"===r[o]){varT=void0;for(Tini)i[T].push({pattern:l[c],task:a})}elsei[r[o]].push({pattern:l[c],task:a})}returni}mhchemParser$1.mhchemParser=mhchemParser;var_mhchemParser={go:function(e,t){if(!e)return[];void0===t&&(t="ce");varn,i="0",r={parenthesisLevel:0};e=(e=(e=e.replace(/\n/g," ")).replace(/[\u2212\u2013\u2014\u2010]/g,"-")).replace(/[\u2026]/g,"...");for(varo=10,a=[];;){n!==e?(o=10,n=e):o--;vars=_mhchemParser.stateMachines[t],l=s.transitions[i]||s.transitions["*"];e:for(varc=0;c<l.length;c++){varT=_mhchemParser.patterns.match_(l[c].pattern,e);if(T){for(vard=l[c].task,Q=0;Q<d.action_.length;Q++){varu=void0;if(s.actions[d.action_[Q].type_])u=s.actions[d.action_[Q].type_](r,T.match_,d.action_[Q].option);else{if(!_mhchemParser.actions[d.action_[Q].type_])throw["MhchemBugA","mhchem bug A. Please report. ("+d.action_[Q].type_+")"];u=_mhchemParser.actions[d.action_[Q].type_](r,T.match_,d.action_[Q].option)}_mhchemParser.concatArray(a,u)}if(i=d.nextState||i,!(e.length>0))returna;if(d.revisit||(e=T.remainder),!d.toContinue)breake}}if(o<=0)throw["MhchemBugU","mhchem bug U. Please report."]}},concatArray:function(e,t){if(t)if(Array.isArray(t))for(varn=0;n<t.length;n++)e.push(t[n]);elsee.push(t)},patterns:{patterns:{empty:/^$/,else:/^./,else2:/^./,space:/^\s/,"space A":/^\s(?=[A-Z\\$])/,space$:/^\s$/,"a-z":/^[a-z]/,x:/^x/,x$:/^x$/,i$:/^i$/,letters:/^(?:[a-zA-Z\u03B1-\u03C9\u0391-\u03A9?@]|(?:\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))))+/,"\\greek":/^\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))/,"one lowercase latin letter $":/^(?:([a-z])(?:$|[^a-zA-Z]))$/,"$one lowercase latin letter$ $":/^\$(?:([a-z])(?:$|[^a-zA-Z]))\$$/,"one lowercase greek letter $":/^(?:\$?[\u03B1-\u03C9]\$?|\$?\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)\s*\$?)(?:\s+|\{\}|(?![a-zA-Z]))$/,digits:/^[0-9]+/,"-9.,9":/^[+\-]?(?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))/,"-9.,9 no missing 0":/^[+\-]?[0-9]+(?:[.,][0-9]+)?/,"(-)(9.,9)(e)(99)":function(e){vart=e.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))?(\((?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))\))?(?:(?:([eE])|\s*(\*|x|\\times|\u00D7)\s*10\^)([+\-]?[0-9]+|\{[+\-]?[0-9]+\}))?/);returnt&&t[0]?{match_:t.slice(1),remainder:e.substr(t[0].length)}:null},"(-)(9)^(-9)":/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+)?)\^([+\-]?[0-9]+|\{[+\-]?[0-9]+\})/,"state of aggregation $":function(e){vart=_mhchemParser.patterns.findObserveGroups(e,"",/^\([a-z]{1,3}(?=[\),])/,")","");if(t&&t.remainder.match(/^($|[\s,;\)\]\}])/))returnt;varn=e.match(/^(?:\((?:\\ca\s?)?\$[amothc]\$\))/);returnn?{match_:n[0],remainder:e.substr(n[0].length)}:null},"_{(state of aggregation)}$":/^_\{(\([a-z]{1,3}\))\}/,"{[(":/^(?:\\\{|\[|\()/,")]}":/^(?:\)|\]|\\\})/,", ":/^[,;]\s*/,",":/^[,;]/,".":/^[.]/,". __* ":/^([.\u22C5\u00B7\u2022]|[*])\s*/,"...":/^\.\.\.(?=$|[^.])/,"^{(...)}":function(e){return_mhchemParser.patterns.findObserveGroups(e,"^{","","","}")},"^($...$)":function(e){return_mhchemParser.pattern
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
functionisNothing(e){returnnull==e}functionisObject(e){return"object"==typeofe&&null!==e}functiontoArray(e){returnArray.isArray(e)?e:isNothing(e)?[]:[e]}functionextend(e,t){varn,i,r,o;if(t)for(n=0,i=(o=Object.keys(t)).length;n<i;n+=1)e[r=o[n]]=t[r];returne}functionrepeat(e,t){varn,i="";for(n=0;n<t;n+=1)i+=e;returni}functionisNegativeZero(e){return0===e&&Number.NEGATIVE_INFINITY===1/e}varisNothing_1=isNothing,isObject_1=isObject,toArray_1=toArray,repeat_1=repeat,isNegativeZero_1=isNegativeZero,extend_1=extend,common={isNothing:isNothing_1,isObject:isObject_1,toArray:toArray_1,repeat:repeat_1,isNegativeZero:isNegativeZero_1,extend:extend_1};functionformatError(e,t){varn="",i=e.reason||"(unknown reason)";returne.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),i+" "+n):i}functionYAMLException$1(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=formatError(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(newError).stack||""}YAMLException$1.prototype=Object.create(Error.prototype),YAMLException$1.prototype.constructor=YAMLException$1,YAMLException$1.prototype.toString=function(e){returnthis.name+": "+formatError(this,e)};varexception=YAMLException$1;functiongetLine(e,t,n,i,r){varo="",a="",s=Math.floor(r/2)-1;returni-t>s&&(t=i-s+(o=" ... ").length),n-i>s&&(n=i+s-(a=" ...").length),{str:o+e.slice(t,n).replace(/\t/g,"→")+a,pos:i-t+o.length}}functionpadStart(e,t){returncommon.repeat(" ",t-e.length)+e}functionmakeSnippet(e,t){if(t=Object.create(t||null),!e.buffer)returnnull;t.maxLength||(t.maxLength=79),"number"!=typeoft.indent&&(t.indent=1),"number"!=typeoft.linesBefore&&(t.linesBefore=3),"number"!=typeoft.linesAfter&&(t.linesAfter=2);for(varn,i=/\r?\n|\r|\0/g,r=[0],o=[],a=-1;n=i.exec(e.buffer);)o.push(n.index),r.push(n.index+n[0].length),e.position<=n.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);vars,l,c="",T=Math.min(e.line+t.linesAfter,o.length).toString().length,d=t.maxLength-(t.indent+T+3);for(s=1;s<=t.linesBefore&&!(a-s<0);s++)l=getLine(e.buffer,r[a-s],o[a-s],e.position-(r[a]-r[a-s]),d),c=common.repeat(" ",t.indent)+padStart((e.line-s+1).toString(),T)+" | "+l.str+"\n"+c;for(l=getLine(e.buffer,r[a],o[a],e.position,d),c+=common.repeat(" ",t.indent)+padStart((e.line+1).toString(),T)+" | "+l.str+"\n",c+=common.repeat("-",t.indent+T+3+l.pos)+"^\n",s=1;s<=t.linesAfter&&!(a+s>=o.length);s++)l=getLine(e.buffer,r[a+s],o[a+s],e.position-(r[a]-r[a+s]),d),c+=common.repeat(" ",t.indent)+padStart((e.line+s+1).toString(),T)+" | "+l.str+"\n";returnc.replace(/\n$/,"")}varsnippet=makeSnippet,TYPE_CONSTRUCTOR_OPTIONS=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],YAML_NODE_KINDS=["scalar","sequence","mapping"];functioncompileStyleAliases(e){vart={};returnnull!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}functionType$1(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===TYPE_CONSTRUCTOR_OPTIONS.indexOf(t))thrownewexception('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){returne},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=compileStyleAliases(t.styleAliases||null),-1===YAML_NODE_KINDS.indexOf(this.kind))thrownewexception('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')}vartype=Type$1;functioncompileList(e,t){varn=[];returne[t].forEach((function(e){vart=n.length;n.forEach((function(n,i){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=i)})),n[t]=e})),n}functioncompileMap(){vare,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scala
//![[link|alias]] [alias](link){num}
EXPR:/(!)?(\[\[([^|\]]+)\|?([^\]]+)?]]|\[([^\]]*)]\(([^)]*)\))(\{(\d+)\})?/g,getResList:e=>{constt=e.matchAll(REGEX_LINK.EXPR);letn;consti=[];for(;!(n=t.next()).done;)i.push(n);returni},getRes:e=>e.matchAll(REGEX_LINK.EXPR),isTransclusion:e=>!!e.value[1],getLink:e=>e.value[3]?e.value[3]:e.value[6],isWikiLink:e=>!!e.value[3],getAliasOrLink:e=>REGEX_LINK.isWikiLink(e)?e.value[4]?e.value[4]:e.value[3]:e.value[5]?e.value[5]:e.value[6],getWrapLength:(e,t)=>{constn=parseInt(e.value[8]);returnisNaN(n)?t>0?t:null:n}},DRAWING_REG=/\n##? Drawing\n[^`]*(```json\n)([\s\S]*?)```\n/gm,DRAWING_REG_FALLBACK=/\n##? Drawing\n(```json\n)?(.*)(```)?(%%)?/gm,DRAWING_COMPRESSED_REG=/(\n##? Drawing\n[^`]*(?:```compressed\-json\n))([\s\S]*?)(```\n)/gm,DRAWING_COMPRESSED_REG_FALLBACK=/(\n##? Drawing\n(?:```compressed\-json\n)?)(.*)((```)?(%%)?)/gm,REG_LINKINDEX_HYPERLINK=/^\w+:\/\//,isCompressedMD=e=>null!==e.match(/```compressed\-json\n/gm),getDecompressedScene=e=>{lett,n=e.matchAll(DRAWING_COMPRESSED_REG);returnt=n.next(),t.done&&(n=e.matchAll(DRAWING_COMPRESSED_REG_FALLBACK),t=n.next()),t.value&&t.value.length>1?[decompress(t.value[2]),t]:[null,t]},changeThemeOfExcalidrawMD=e=>{constt=isCompressedMD(e);letn=t?getDecompressedScene(e)[0]:e;returnn?(isObsidianThemeDark?1===(n.match(/"theme"\s*:\s*"light"\s*,/g)||[]).length&&(n=n.replace(/"theme"\s*:\s*"light"\s*,/,'"theme": "dark",')):1===(n.match(/"theme"\s*:\s*"dark"\s*,/g)||[]).length&&(n=n.replace(/"theme"\s*:\s*"dark"\s*,/,'"theme": "light",')),t?e.replace(DRAWING_COMPRESSED_REG,`$1${compress(n)}$3`):n):e};functiongetJSON(e){lett,n;if(isCompressedMD(e)){const[t,n]=getDecompressedScene(e);returnt?{scene:t.substring(0,t.lastIndexOf("}")+1),pos:n.value.index}:{scene:e,pos:n.value?n.value.index:0}}if(t=e.matchAll(DRAWING_REG),n=t.next(),n.done&&(t=e.matchAll(DRAWING_REG_FALLBACK),n=t.next()),n.value&&n.value.length>1){conste=n.value[2];return{scene:e.substr(0,e.lastIndexOf("}")+1),pos:n.value.index}}return{scene:e,pos:n.value?n.value.index:0}}functiongetMarkdownDrawingSection(e,t){returnt?`## Drawing\n\`\`\`compressed-json\n${compress(e)}\n\`\`\`\n%%`:`## Drawing\n\`\`\`json\n${e}\n\`\`\`\n%%`}constRE_EXCALIDRAWDATA_WITHSECTION_OK=/^(#\n+)%%\n+# Excalidraw Data(?:\n|$)/m,RE_EXCALIDRAWDATA_WITHSECTION_NOTOK=/#\n+%%\n+# Excalidraw Data(?:\n|$)/m,RE_EXCALIDRAWDATA_NOSECTION_OK=/^(%%\n+)?# Excalidraw Data(?:\n|$)/m,RE_TEXTELEMENTS_WITHSECTION_OK=/^#\n+%%\n+##? Text Elements(?:\n|$)/m,RE_TEXTELEMENTS_WITHSECTION_NOTOK=/#\n+%%\n+##? Text Elements(?:\n|$)/m,RE_TEXTELEMENTS_NOSECTION_OK=/^(%%\n+)?##? Text Elements(?:\n|$)/m,RE_EXCALIDRAWDATA_FALLBACK_1=/(.*)%%\n+# Excalidraw Data(?:\n|$)/m,RE_EXCALIDRAWDATA_FALLBACK_2=/(.*)# Excalidraw Data(?:\n|$)/m,RE_TEXTELEMENTS_FALLBACK_1=/(.*)%%\n+##? Text Elements(?:\n|$)/m,RE_TEXTELEMENTS_FALLBACK_2=/(.*)##? Text Elements(?:\n|$)/m,RE_DRAWING=/^(%%\n+)?##? Drawing\n/m,getExcalidrawMarkdownHeaderSection=(e,t)=>{varn;consti=e.search(RE_DRAWING);i>0&&(e=e.substring(0,i));constr=e.match(RE_EXCALIDRAWDATA_WITHSECTION_OK);leto=null!==(n=null==r?void0:r.index)&&void0!==n?n:-1,a=!1;if(o>0&&(o+=r[1].length),-1===o&&(o=e.search(RE_EXCALIDRAWDATA_WITHSECTION_NOTOK),o>0&&(a=!0)),-1===o&&(o=e.search(RE_EXCALIDRAWDATA_NOSECTION_OK)),-1===o){constt=e.match(RE_EXCALIDRAWDATA_FALLBACK_1);t&&Boolean(t[1])&&(o=t.index+t[1].length)}if(-1===o){constt=e.match(RE_EXCALIDRAWDATA_FALLBACK_2);t&&Boolean(t[1])&&(o=t.index+t[1].length)}if(-1===o&&(o=e.search(RE_TEXTELEMENTS_WITHSECTION_OK),o>0&&(o+=2)),-1===o&&(o=e.search(RE_TEXTELEMENTS_WITHSECTION_NOTOK),o>0&&(a=!0)),-1===o&&(o=e.search(RE_TEXTELEMENTS_NOSECTION_OK)),-1===o){constt=e.match(RE_TEXTELEMENTS_FALLBACK_1);t&&Boolean(t[1])&&(o=t.index+t[1].length)}if(-1===o){constt=e.match(RE_TEXTELEMENTS_FALLBACK_2);t&&Boolean(t[1])&&(o=t.index+t[1].length)}if(-1===o&&i>0&&(o=i),-1===o)returne.endsWith("\n")?e:e+"\n";lets=updateFrontmatterInString(e.substring(0,o),t);returna?s+"\n#\n":s.endsWith("\n")?s:s+"\n"};classExcalidrawData{constructor(e){this.plugin=e,this.textElements=null,this.scene=null,this.delete
,renderTopRightUI:(e,t)=>this.obsidianMenu.renderButton(e,t),renderEmbeddableMenu:e=>this.embeddableMenu.renderButtons(e),onPaste:(e,t)=>this.onPaste(e,t),onThemeChange:asynce=>this.onThemeChange(e),ownerDocument:this.ownerDocument,ownerWindow:this.ownerWindow,onDrop:e=>this.onDrop(e),onBeforeTextEdit:e=>this.onBeforeTextEdit(e),onBeforeTextSubmit:(e,t,n,i)=>this.onBeforeTextSubmit(e,t,n,i),onLinkOpen:(e,t)=>this.onLinkOpen(e,t),onLinkHover:(e,t)=>this.onLinkHover(e,t),onContextMenu:T,onViewModeChange:e=>this.onViewModeChange(e),validateEmbeddable:!0,renderWebview:DEVICE.isDesktop,renderEmbeddable:(e,t)=>d(e,t),renderMermaid:shouldRenderMermaid(),obsidianHostPlugin:this.plugin},Q(),t.createElement(a,{},t.createElement(a.Center,{},t.createElement(a.Center.Logo,{},t.createElement(LogoWrapper,{},ICONS.ExcalidrawSword)),t.createElement(a.Center.Heading,{},'Type "Excalidraw" in the Command Palette',t.createElement("br"),"Explore the Obsidian Menu in the top right",t.createElement("br"),"Visit the Script Library",t.createElement("br"),"Find help in the hamburger-menu"),t.createElement(a.Center.Menu,{},t.createElement(a.Center.MenuItemLink,{icon:ICONS.YouTube,href:"https://www.youtube.com/@VisualPKM",shortcut:null,"aria-label":"Visual PKM YouTube Channel"}," Check out the Visual PKM YouTube channel."),t.createElement(a.Center.MenuItemLink,{icon:ICONS.Discord,href:"https://discord.gg/DyfAXFwUHc",shortcut:null,"aria-label":"Join the Visual Thinking Discord Server"}," Join the Visual Thinking Discord Server"),t.createElement(a.Center.MenuItemLink,{icon:ICONS.twitter,href:"https://twitter.com/zsviczian",shortcut:null,"aria-label":"Follow me on Twitter"}," Follow me on Twitter"),t.createElement(a.Center.MenuItemLink,{icon:ICONS.heart,href:"https://ko-fi.com/zsolt",shortcut:null,"aria-label":"Donate to support Excalidraw-Obsidian"},' Say "Thank You" & support the plugin.')))),t.createElement(l,{onTextSubmit:asynce=>{vart,n,i,r,o,a;try{consts=awaitpostOpenAI({systemPrompt:"The user will provide you with a text prompt. Your task is to generate a mermaid diagram based on the prompt. Use the graph, sequenceDiagram, flowchart or classDiagram types based on what best fits the request. Return a single message containing only the mermaid diagram in a codeblock. Avoid the use of `()` parenthesis in the mermaid script.",text:e,instruction:"Return a single message containing only the mermaid diagram in a codeblock."});if(!s)return{error:newError("Request failed")};constl=s.json;if(null==l?void0:l.error)returnlog(s),{error:newError(l.error.message)};if(!(null===(i=null===(n=null===(t=null==l?void0:l.choices)||void0===t?void0:t[0])||void0===n?void0:n.message)||void0===i?void0:i.content))returnlog(s),{error:newError("Generation failed... see console log for details")};letc=null===(a=extractCodeBlocks(null===(o=null===(r=l.choices[0])||void0===r?void0:r.message)||void0===o?void0:o.content)[0])||void0===a?void0:a.data;returnc?(c.startsWith("mermaid")&&(c=c.replace(/^mermaid/,"").trim()),{generatedResponse:c,rateLimit:100,rateLimitRemaining:100}):(log(s),{error:newError("Generation failed... see console log for details")})}catch(e){thrownewError("Request failed")}}}),t.createElement(s,{})),u());returnt.createElement(t.Fragment,null,g)}));n.createRoot(this.contentEl).render(p)}updateContainerSize(e,t=!1){constn=this.excalidrawAPI;if(!n)return;consti=()=>{constt=e?n.getSceneElements().filter((t=>t.id===e&&"arrow"!==t.type)):n.getSceneElements().filter(isContainer);t.length>0&&(this.initialContainerSizeUpdate&&(this.semaphores.justLoaded=!0),n.updateContainerSize(t)),this.initialContainerSizeUpdate=!1};t?setTimeout((()=>i()),50):i()}zoomToFit(e=!0,t=!1){if(document.body.querySelector("div.modal-container"))return;constn=this.excalidrawAPI;if(!n||this.semaphores.isEditingText||this.semaphores.preventAutozoom)return;consti=this.plugin.settings.zoomToFitMaxLevel,r=n.getSceneElements().filter((e=>e.width<1e4&&e.height<1e4));DEVICE.isMobile&&r.length>1e3||r.length>2500?t&&n.scrollToContent():e?setTimeout((()=>n.zoomToFit(