`],o=new Blob([this.plugin.calloutManager.generateCssString()],{type:"text/css"});createEl("a",{attr:{download:"custom_callouts.css",href:URL.createObjectURL(o)}}).click()}).setDisabled(!Object.keys(this.plugin.data.userAdmonitions).length)),new d.Setting(c).setName("Export Custom Types as JSON").setDesc("Choose custom types to export as a JSON file that you can then share with other users.").addButton(i=>i.setButtonText("Download All").setCta().onClick(()=>{let n=Object.values(this.plugin.data.userAdmonitions);this.download(n)})).addButton(i=>i.setButtonText("Select & Download").onClick(()=>{let n=new p2(this.plugin);n.onClose=()=>{if(!n.export)return;let o=Object.values(this.plugin.data.userAdmonitions);this.download(o.filter(r=>n.selectedAdmonitions.includes(r.type)))},n.open()})),new d.Setting(c).setName("Use CSS Snippet for Custom Callouts").setDesc("Instead of managing it internally, Admonitions will maintain a CSS snippet to enable your custom types for callouts.").addToggle(i=>i.setValue(this.plugin.data.useSnippet).onChange(n=>{this.plugin.data.useSnippet=n,this.plugin.saveSettings(),this.plugin.calloutManager.setUseSnippet()})),new d.Setting(c).setName(b("Add New")).setDesc("Add a new Admonition type. All custom Admonitions will also be usable as callouts.").addButton(i=>i.setTooltip(b("Add Additional")).setButtonText("+").onClick(async()=>{let o=new l1(this.plugin);o.onClose=async()=>{if(o.saved){let r={type:o.type,color:o.color,icon:o.icon,command:!1,title:o.title,injectColor:o.injectColor,noTitle:o.noTitle,copy:o.copy};this.plugin.addAdmonition(r),this.plugin.calloutManager.addAdmonition(r),this.display()}},o.open()})),new d.Setting(c).setName("Import Admonition(s)").setDesc("Import admonitions from a JSON definition.").addButton(i=>{let n=createEl("input",{attr:{type:"file",name:"merge",accept:".json",multiple:!0,style:"display: none;"}});n.onchange=async()=>{let{files:o}=n;if(!!o.length){try{let r=[];for(let t of Array.from(o))r.push(JSON.parse(await t.text()));for(let t of r.flat()){if(typeof t!="object")continue;t.icon||(t.icon={name:"pencil-alt",type:"font-awesome"});let l=e1.validateImport(this.plugin,t);if(l.success==!1){new d.Notice(createFragment(s=>{s.createSpan({text:`Therewasanissueimportingthe${t.type}admonition:`}),s.createEl("br"),s.createSpan({text:l.message})}));continue}l.messages?.length&&new d.Notice(createFragment(s=>{s.createSpan({text:`Therewasanissueimportingthe${t.type}admonition:`});for(let f of l.messages)s.createEl("br"),s.createSpan({text:f})})),await this.plugin.addAdmonition(t)}this.display()}catch(r){new d.Notice(`Therewasanerrorwhileimportingtheadmonition${o.length==1?"":"s"}.`),console.error(r)}n.value=null}},i.setButtonText("Choose Files"),i.buttonEl.appendChild(n),i.onClick(()=>n.click())}).addExtraButton(i=>i.setIcon("info").onClick(()=>{let n=new d.Modal(this.plugin.app);n.onOpen=()=>{n.contentEl.createSpan({text:"Import one or more admonition definitions as a JSON array. An admonition definition should look as follows at minimum:"}),n.contentEl.createEl("br");let o=new d.TextAreaComponent(n.contentEl.createDiv()).setDisabled(!0).setValue(JSON.stringify({type:"embed-affliction",color:"149, 214, 148",icon:{name:"head-side-cough",type:"font-awesome"}},null,4));o.inputEl.setAttribute("style",`height:${o.inputEl.scrollHeight}px;resize:none;`),n.contentEl.createEl("br"),n.contentEl.createSpan({text:"See the plugin ReadMe for more information."})},n.open()})),this.additionalEl=c.createDiv("additional"),this.buildTypes(),this.buildAdmonitions(this.containerEl.createEl("details",{cls:"admonitions-nested-settings",attr:{...this.plugin.data.open.admonitions?{open:!0}:{}}})),this.buildIcons(this.containerEl.createEl("details",{cls:"admonitions-nested-settings",attr:{...this.plugin.data.open.icons?{open:!0}:{}}})),this.buildOtherSyntaxes(this.containerEl.createEl("details",{cls:"admonitions-nested-settings",attr:{...this.plugin.data.open.other?{open:!0}:{}}})),this.buildAdvanced(this.containerEl.createEl("details",{cls:"admonitions-nested-settings",attr:{...
>`)}`),this.converted++}returnc}buildAdvanced(c){c.empty(),c.ontoggle=()=>{this.plugin.data.open.advanced=c.open,this.plugin.saveSettings()};leta=c.createEl("summary");newd.Setting(a).setHeading().setName("Advanced Settings"),a.createDiv("collapser").createDiv("handle"),newd.Setting(c).setName(b("Markdown Syntax Highlighting")).setDesc(b("Use Obsidian's markdown syntax highlighter in admonition code blocks. This setting is experimental and could cause errors.")).addToggle(i=>{i.setValue(this.plugin.data.syntaxHighlight),i.onChange(asyncn=>{this.plugin.data.syntaxHighlight=n,n?this.plugin.turnOnSyntaxHighlighting():this.plugin.turnOffSyntaxHighlighting(),awaitthis.plugin.saveSettings()})})}buildTypes(){this.additionalEl.empty();for(letcofObject.values(this.plugin.data.userAdmonitions)){leta=newd.Setting(this.additionalEl),i=this.plugin.getAdmonitionElement(c.type,c.type[0].toUpperCase()+c.type.slice(1).toLowerCase(),c.icon,c.injectColor??this.plugin.data.injectColor?c.color:null);a.infoEl.replaceWith(i),c.command?a.addExtraButton(n=>{n.setIcon(r2.toString()).setTooltip(b("Unregister Commands")).onClick(async()=>{this.plugin.unregisterCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}):a.addExtraButton(n=>{n.setIcon(t2.toString()).setTooltip(b("Register Commands")).onClick(async()=>{this.plugin.registerCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}),a.addExtraButton(n=>{n.setIcon("pencil").setTooltip(b("Edit")).onClick(()=>{leto=newl1(this.plugin,c);o.onClose=async()=>{if(o.saved){letr=c.command,t={type:o.type,color:o.color,icon:o.icon,command:r,title:o.title,injectColor:o.injectColor,noTitle:o.noTitle,copy:o.copy};if(t.type!=c.type){this.plugin.unregisterType(c);letl=Object.entries(this.plugin.data.userAdmonitions);this.plugin.data.userAdmonitions=Object.fromEntries(l.map(([s,f])=>s==c.type?[t.type,t]:[s,f]))}elsethis.plugin.data.userAdmonitions[t.type]=t;this.plugin.registerType(t.type),this.plugin.calloutManager.addAdmonition(t),this.display()}},o.open()})}).addExtraButton(n=>{n.setIcon("trash").setTooltip(b("Delete")).onClick(()=>{this.plugin.removeAdmonition(c),this.display()})})}}},l1=classextendsd.Modal{constructor(c,a){super(c.app);this.plugin=c;this.color="#7d7d7d";this.icon={};this.saved=!1;this.error=!1;this.injectColor=this.plugin.data.injectColor;this.noTitle=!1;this.editing=!1;a&&(this.editing=!0,this.color=a.color,this.icon=a.icon,this.type=a.type,this.originalType=a.type,this.title=a.title,this.injectColor=a.injectColor??this.injectColor,this.noTitle=a.noTitle??!1,this.copy=a.copy??this.plugin.data.copyButton)}asyncdisplay(){this.containerEl.addClass("admonition-settings-modal"),this.titleEl.setText(`${this.editing?"Edit":"Add"} Admonition`);let{contentEl:c}=this;c.empty();leta=c.createDiv(),i=this.title??this.type??"...";this.admonitionPreview=this.plugin.getAdmonitionElement(this.type,i[0].toUpperCase()+i.slice(1).toLowerCase(),this.icon,this.injectColor??this.plugin.data.injectColor?this.color:null),this.admonitionPreview.createDiv("callout-content admonition-content").createEl("p",{text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod nulla."}),c.appendChild(this.admonitionPreview);letn,o=newd.Setting(a).setName(b("Admonition Type")).addText(h=>{n=h,n.setValue(this.type).onChange(v=>{letm=e1.validateType(v,this.plugin,this.originalType);if(m.success==!1){l1.setValidationError(h.inputEl,m.message);return}l1.removeValidationError(h.inputEl),this.type=v,this.title||this.updateTitle(this.admonitionPreview,this.type?.[0].toUpperCase()+this.type?.slice(1).toLowerCase())})});o.controlEl.addClass("admonition-type-setting"),o.descEl.createSpan({text:"This is used to create the admonition (e.g., "}),o.descEl.createEl("code",{text:"note"}),o.descEl.createSpan({text:" or "}),o.descEl.createEl("code",{text:"abstract"}),o.descEl.createSpan({text:")"}),newd.Setting(a).setName(b("Admonition Title")).setDesc(b("This will be the default title for this admonition type.")).addText(h=>{h.setValue(this.title).onChange(v=>{if(!v.length){thi
`).replace(/^> /gm,"")).then(async()=>{new k1.Notice("Callout content copied to clipboard.")})})}}if(o.noTitle&&!i.dataset.calloutFold&&r.querySelector(".callout-title-inner")?.textContent?.toLowerCase()===o.type.toLowerCase()&&r.addClass("no-title"),!o.noTitle&&this.plugin.data.autoCollapse&&!i.dataset.calloutFold&&this.setCollapsible(i),o.title&&r.textContent==n[0].toUpperCase()+n.slice(1).toLowerCase()){let s=r.querySelector(".callout-title-inner");s&&s.setText(o.title)}this.plugin.data.dropShadow&&i.addClass("drop-shadow")}setCollapsible(c){let a=c.querySelector(".callout-title"),i=c.querySelector(".callout-content");if(!i)return;c.addClass("is-collapsible"),this.plugin.data.defaultCollapseType=="closed"?(c.dataset.calloutFold="-",c.addClass("is-collapsed")):c.dataset.calloutFold="+";let n=a.createDiv("callout-fold");(0,k1.setIcon)(n,"chevron-down");let o=c.hasClass("is-collapsed");if(this.getComputedHeights(i),o)for(let r of this.heights)i.style.setProperty(r,"0px");a.onclick=r=>{this.collapse(c,r)}}collapse(c,a){a?.preventDefault();let i=c.querySelector(".callout-content");function n(r){i.removeEventListener("transitionend",n),i.style.removeProperty("transition")}i.addEventListener("transitionend",n),i.style.setProperty("transition","all 100ms cubic-bezier(.02, .01, .47, 1)");let o=c.hasClass("is-collapsed");if(!a||a.button==0){let r=this.getComputedHeights(i);for(let t of this.heights)i.style.setProperty(t,o?r[t]:"0px");c.toggleClass("is-collapsed",!o)}}getComputedHeights(c){if(this.heightMap.has(c))return this.heightMap.get(c);let a=getComputedStyle(c),i={};for(let n of this.heights)i[n]=a.getPropertyValue(n);return this.heightMap.set(c,i),i}generateCssString(){let c=[`/* This snippet was auto-generated by the Admonitions plugin */
`);let r=i.getCursor();i.setCursor(r.line-2)}catch{new V.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${c.type}`,name:`Insert${c.type}`,editorCheckCallback:(a,i,n)=>{if(a)return c.command;if(c.command)try{i.getDoc().replaceSelection(`\`\`\`ad-${c.type}
`);let o=i.getCursor();i.setCursor(o.line-2)}catch{new V.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${c.type}-with-title`,name:`Insert${c.type}WithTitle`,editorCheckCallback:(a,i,n)=>{if(a)return c.command;if(c.command)try{let o=c.title??"";i.getDoc().replaceSelection(`\`\`\`ad-${c.type}
`);let r=i.getCursor();i.setCursor(r.line-3)}catch{new V.Notice("There was an issue inserting the admonition.")}}})}unregisterType(c){this.data.syntaxHighlight&&this.turnOffSyntaxHighlighting([c.type]),c.command&&this.unregisterCommandsFor(c),this.postprocessors.has(c.type)&&(V.MarkdownPreviewRenderer.unregisterPostProcessor(this.postprocessors.get(c.type)),V.MarkdownPreviewRenderer.unregisterCodeBlockPostProcessor(`ad-${c.type}`),this.postprocessors.delete(c.type))}async removeAdmonition(c){this.data.userAdmonitions[c.type]&&delete this.data.userAdmonitions[c.type],this.unregisterType(c),this.calloutManager.removeAdmonition(c),await this.saveSettings()}unregisterCommandsFor(c){c.command=!1,this.app.commands.findCommand(`obsidian-admonition:insert-${c.type}`)&&(delete this.app.commands.editorCommands[`obsidian-admonition:insert-${c.type}`],delete this.app.commands.editorCommands[`obsidian-admonition:insert-${c.type}-with-title`],delete this.app.commands.commands[`obsidian-admonition:insert-${c.type}`],delete this.app.commands.commands[`obsidian-admonition:insert-${c.type}-with-title`])}async saveSettings(){this.data.version=this.manifest.version,await this.saveData(this.data)}async loadSettings(){let c=await this.loadData();if(this.data=Object.assign({},Bb,c),this.data.userAdmonitions){if(!this.data.version||Number(this.data.version.split(".")[0])<5)for(let a in this.data.userAdmonitions)Object.prototype.hasOwnProperty.call(this.data.userAdmonitions[a],"type")||(this.data.userAdmonitions[a]={...this.data.userAdmonitions[a],icon:{type:"font-awesome",name:this.data.userAdmonitions[a].icon}});(!this.data.version||Number(this.data.version.split(".")[0])<8)&&new V.Notice(createFragment(a=>{a.createSpan({text:"Admonitions: Obsidian now has native support for callouts! Check out the "}),a.createEl("a",{text:"Admonitions ReadMe",href:"obsidian://show-plugin?id=obsidian-admonition"}),a.createSpan({text:" for what that means for Admonitions going forward."})}),0)}if(!this.data.rpgDownloadedOnce&&this.data.userAdmonitions&&Object.values(this.data.userAdmonitions).some(a=>{if(a.icon.type=="rpg")return!0})&&!this.data.icons.includes("rpg"))try{await this.downloadIcon("rpg"),this.data.rpgDownloadedOnce=!0}catch{}await this.saveSettings()}turnOnSyntaxHighlighting(c=Object.keys(this.admonitions)){!this.data.syntaxHighlight||(c.forEach(a=>{if(this.data.syntaxHighlight){let[,i]=`${a}`.match(/^([\w+#-]*)[^\n`]*$/);window.CodeMirror.defineMode(`ad-${i}`,(n,o)=>window.CodeMirror.getMode({},"hypermd"))}}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(a=>a.setOption("mode",a.getOption("mode")))))}turnOffSyntaxHighlighting(c=Object.keys(this.admonitions)){c.forEach(a=>{window.CodeMirror.modes.hasOwnProperty(`ad-${a}`)&&deletewindow.CodeMirror.modes[`ad-${a}`]}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(a=>a.setOption("mode",a.getOption("mode"))))}asynconunload(){console.log("Obsidian Admonition unloaded"),this.postprocessors=null,this.turnOffSyntaxHighlighting()}};