`],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 u.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 u.Setting(c).setName(g("Add New")).setDesc("Add a new Admonition type. All custom Admonitions will also be usable as callouts.").addButton(i=>i.setTooltip(g("Add Additional")).setButtonText("+").onClick(async()=>{let o=new F(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()})),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.plugin.data.open.advanced?{open:!0}:{}}})),this.containerEl.createDiv("coffee").createEl("a",{href:"https://www.buymeacoffee.com/valentine195"}).createEl("img",{attr:{src:"https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=\u2615&slug=valentine195&button_colour=e3e7ef&font_colour=262626&font_family=Inter&outline_colour=262626&coffee_colour=ff0000"}})}buildAdmonitions(c){c.empty(),c.ontoggle=()=>{this.plugin.data.open.admonitions=c.open,this.plugin.saveSettings()};let e=c.createEl("summary");new u.Setting(e).setHeading().setName("Admonitions & Callouts"),e.createDiv("collapser").createDiv("handle"),new u.Setting(c).setName("Add Drop Shadow").setDesc("A drop shadow will be added to admonitions.").addToggle(i=>{i.setValue(this.plugin.data.dropShadow).onChange(async n=>{this.plugin.data.dropShadow=n,this.display(),await this.plugin.saveSettings()})}),new u.Setting(c).setName(g("Collapsible by Default")).setDesc(createFragment(i=>{i.createSpan({text:"All admonitions & callouts will be collapsible by default. Use "}),i.createEl("code",{text:"collapse: none"}),i.createSpan({text:g(" to prevent.")})})).addToggle(i=>{i.setValue(this.plugin.data.autoCollapse).onChange(async n=>{this.plugin.data.autoCollapse=n,this.display(),await this.plugin.saveSettings()})}),this.plugin.data.autoCollapse&&new u.Setting(c).setName(g("Default Collapse Type")).setDesc("Collapsible admonitions & callouts will be either opened or closed.").addDropdown(i=>{i.addOption("open","open"),i.addOption("closed","closed"),i.setValue(this.plugin.data.defaultCollapseType),i.onChange(async n=>{this.plugin.data.defaultCollapseType=n,await this.plugin.saveSettings()})}),new u.Setting(c).setName(g("Add Copy Button")).setDesc("Add a 'copy content' button to admonitions & callouts.").addToggle(i=>{i.setValue(this.plugin.data.copyButton),i.onChange(async n=>{this.plugin.data.copyButton=n,n||document.querySelectorAll(".admonition-content-copy").forEach(o=>{o.detach()}),await this.plugin.saveSettings()})}),new u.Setting(c).setName(g("Parse Titles as Markdown")).setDesc(g("Admonition Titles will be rendered as markdown.")).addToggle(i=>{i.setValue(this.plugin.data.parseTitles),i.onChange(async n=>{this.plugin.data.parseTitles=n,await this.plugin.saveSettings()})}),new u.Setting(c).setName("Set Admonition Colors").setDesc("Disable this setting to turn off admonition colorin
>`)}`),this.converted++}returnc}buildAdvanced(c){c.empty(),c.ontoggle=()=>{this.plugin.data.open.advanced=c.open,this.plugin.saveSettings()};lete=c.createEl("summary");newu.Setting(e).setHeading().setName("Advanced Settings"),e.createDiv("collapser").createDiv("handle"),newu.Setting(c).setName(g("Markdown Syntax Highlighting")).setDesc(g("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()})}),newu.Setting(c).setName("Generate JS for Publish").setDesc(createFragment(i=>{i.createSpan({text:"Generate a javascript file to place in your "}),i.createEl("code",{text:"publish.js"}),i.createSpan({text:"file."}),i.createEl("br"),i.createEl("strong",{text:"Please note that this can only be done on custom domain publish sites."})})).addButton(i=>{i.setButtonText("Generate"),i.onClick(n=>{leto={};for(letfinthis.plugin.admonitions){lets=this.plugin.admonitions[f];o[f]={icon:this.plugin.iconManager.getIconNode(s.icon)?.outerHTML??"",color:s.color}}letr=W4.replace(/ADMONITION_ICON_MAP\s?=\s?\{\}/,"ADMONITION_ICON_MAP="+JSON.stringify(o)),t=newBlob([r],{type:"text/javascript"}),l=createEl("a",{href:URL.createObjectURL(t),attr:{download:"publish.admonition.js"}});l.click(),l.detach()})})}buildTypes(){this.additionalEl.empty();for(letcofObject.values(this.plugin.data.userAdmonitions)){lete=newu.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);e.infoEl.replaceWith(i),c.command?e.addExtraButton(n=>{n.setIcon(Q1.toString()).setTooltip(g("Unregister Commands")).onClick(async()=>{this.plugin.unregisterCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}):e.addExtraButton(n=>{n.setIcon(K1.toString()).setTooltip(g("Register Commands")).onClick(async()=>{this.plugin.registerCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}),e.addExtraButton(n=>{n.setIcon("pencil").setTooltip(g("Edit")).onClick(()=>{leto=newF(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(([f,s])=>f==c.type?[t.type,t]:[f,s]))}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(g("Delete")).onClick(()=>{this.plugin.removeAdmonition(c),this.display()})})}}},F=classextendsu.Modal{constructor(c,e){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;e&&(this.color=e.color,this.icon=e.icon,this.type=e.type,this.originalType=e.type,this.title=e.title,this.injectColor=e.injectColor??this.injectColor,this.noTitle=e.noTitle??!1,this.copy=e.copy??this.plugin.data.copyButton)}asyncdisplay(){let{contentEl:c}=this;c.empty();lete=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=newu.Setting(e).setName(g("Admonition Type")).addText(h=>{n=h,n.setValue(this.type).onChange(m=>{if(!m.length){F.setValidationError(h,g("Admonition type cannot be empty."));return}if(m.includes(" ")){
`).replace(/^> /gm,"")).then(async()=>{new L1.Notice("Callout content copied to clipboard.")})})}}if(o.noTitle&&!i.dataset.calloutFold&&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 f=r.querySelector(".callout-title-inner");f&&f.setText(o.title)}this.plugin.data.dropShadow&&i.addClass("drop-shadow")}setCollapsible(c){let e=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=e.createDiv("callout-fold");(0,L1.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");e.onclick=r=>{r.preventDefault();function t(l){i.removeEventListener("transitionend",t),i.style.removeProperty("transition")}if(i.addEventListener("transitionend",t),i.style.setProperty("transition","all 100ms cubic-bezier(.02, .01, .47, 1)"),o=c.hasClass("is-collapsed"),r.button==0){for(let l of this.heights){let f=this.getComputedHeights(i);i.style.setProperty(l,o?f[l]:"0px")}c.toggleClass("is-collapsed",!o)}}}getComputedHeights(c){if(this.heightMap.has(c))return this.heightMap.get(c);let e=getComputedStyle(c),i={};for(let n of this.heights)i[n]=e.getPropertyValue(n);return this.heightMap.set(c,i),i}generateCssString(){let c=[`/* This snippet was auto-generated by the Admonitions plugin on ${new Date().toLocaleString()} */
`];for(let e of Array.from(this.sheet.cssRules))c.push(e.cssText);return c.join(`
`);let r=i.getCursor();i.setCursor(r.line-2)}catch{new x.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${c.type}`,name:`Insert${c.type}`,editorCheckCallback:(e,i,n)=>{if(e)return c.command;if(c.command)try{i.getDoc().replaceSelection(`\`\`\`ad-${c.type}
`);let o=i.getCursor();i.setCursor(o.line-2)}catch{new x.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${c.type}-with-title`,name:`Insert${c.type}WithTitle`,editorCheckCallback:(e,i,n)=>{if(e)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 x.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)&&(x.MarkdownPreviewRenderer.unregisterPostProcessor(this.postprocessors.get(c.type)),x.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 e in this.data.userAdmonitions)Object.prototype.hasOwnProperty.call(this.data.userAdmonitions[e],"type")||(this.data.userAdmonitions[e]={...this.data.userAdmonitions[e],icon:{type:"font-awesome",name:this.data.userAdmonitions[e].icon}});(!this.data.version||Number(this.data.version.split(".")[0])<8)&&new x.Notice(createFragment(e=>{e.createSpan({text:"Admonitions: Obsidian now has native support for callouts! Check out the "}),e.createEl("a",{text:"Admonitions ReadMe",href:"obsidian://show-plugin?id=obsidian-admonition"}),e.createSpan({text:" for what that means for Admonitions going forward."})}),0)}if(!this.data.rpgDownloadedOnce&&this.data.userAdmonitions&&Object.values(this.data.userAdmonitions).some(e=>{if(e.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(e=>{if(this.data.syntaxHighlight){let[,i]=`${e}`.match(/^([\w+#-]*)[^\n`]*$/);window.CodeMirror.defineMode(`ad-${i}`,(n,o)=>window.CodeMirror.getMode({},"hypermd"))}}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(e=>e.setOption("mode",e.getOption("mode")))))}turnOffSyntaxHighlighting(c=Object.keys(this.admonitions)){c.forEach(e=>{window.CodeMirror.modes.hasOwnProperty(`ad-${e}`)&&deletewindow.CodeMirror.modes[`ad-${e}`]}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(e=>e.setOption("mode",e.getOption("mode"))))}asynconunload(){console.log("Obsidian Admonition unloaded"),this.postprocessors=null,this.turnOffSyntaxHighlighting()}};