`],t=new Blob([this.plugin.calloutManager.generateCssString()],{type:"text/css"});createEl("a",{attr:{download:"custom_callouts.css",href:URL.createObjectURL(t)}}).click()}).setDisabled(!Object.keys(this.plugin.data.userAdmonitions).length)),new z.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 t=Object.values(this.plugin.data.userAdmonitions);this.download(t.filter(r=>n.selectedAdmonitions.includes(r.type)))},n.open()})),new z.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 z.Setting(c).setName(L("Add New")).setDesc("Add a new Admonition type. All custom Admonitions will also be usable as callouts.").addButton(i=>i.setTooltip(L("Add Additional")).setButtonText("+").onClick(async()=>{let t=new l1(this.plugin);t.onClose=async()=>{if(t.saved){let r={type:t.type,color:t.color,icon:t.icon,command:!1,title:t.title,injectColor:t.injectColor,noTitle:t.noTitle,copy:t.copy};this.plugin.addAdmonition(r),this.plugin.calloutManager.addAdmonition(r),this.display()}},t.open()})),new z.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:t}=n;if(!!t.length){try{let r=[];for(let o of Array.from(t))r.push(JSON.parse(await o.text()));for(let o of r.flat()){if(typeof o!="object")continue;o.icon||(o.icon={name:"pencil-alt",type:"font-awesome"});let l=e1.validateImport(this.plugin,o);if(l.success==!1){new z.Notice(createFragment(f=>{f.createSpan({text:`Therewasanissueimportingthe${o.type}admonition:`}),f.createEl("br"),f.createSpan({text:l.message})}));continue}l.messages?.length&&new z.Notice(createFragment(f=>{f.createSpan({text:`Therewasanissueimportingthe${o.type}admonition:`});for(let s of l.messages)f.createEl("br"),f.createSpan({text:s})})),await this.plugin.addAdmonition(o)}this.display()}catch(r){new z.Notice(`Therewasanerrorwhileimportingtheadmonition${t.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 z.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 t=new z.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));t.inputEl.setAttribute("style",`height:${t.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");newz.Setting(a).setHeading().setName("Advanced Settings"),a.createDiv("collapser").createDiv("handle"),newz.Setting(c).setName(L("Markdown Syntax Highlighting")).setDesc(L("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()})}),newz.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=>{lett={};for(letfinthis.plugin.admonitions){lets=this.plugin.admonitions[f];t[f]={icon:this.plugin.iconManager.getIconNode(s.icon)?.outerHTML??"",color:s.color}}letr=c3.replace(/ADMONITION_ICON_MAP\s?=\s?\{\}/,"ADMONITION_ICON_MAP="+JSON.stringify(t)),o=newBlob([r],{type:"text/javascript"}),l=createEl("a",{href:URL.createObjectURL(o),attr:{download:"publish.admonition.js"}});l.click(),l.detach()})})}buildTypes(){this.additionalEl.empty();for(letcofObject.values(this.plugin.data.userAdmonitions)){leta=newz.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(L("Unregister Commands")).onClick(async()=>{this.plugin.unregisterCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}):a.addExtraButton(n=>{n.setIcon(o2.toString()).setTooltip(L("Register Commands")).onClick(async()=>{this.plugin.registerCommandsFor(c),awaitthis.plugin.saveSettings(),this.display()})}),a.addExtraButton(n=>{n.setIcon("pencil").setTooltip(L("Edit")).onClick(()=>{lett=newl1(this.plugin,c);t.onClose=async()=>{if(t.saved){letr=c.command,o={type:t.type,color:t.color,icon:t.icon,command:r,title:t.title,injectColor:t.injectColor,noTitle:t.noTitle,copy:t.copy};if(o.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?[o.type,o]:[f,s]))}elsethis.plugin.data.userAdmonitions[o.type]=o;this.plugin.registerType(o.type),this.plugin.calloutManager.addAdmonition(o),this.display()}},t.open()})}).addExtraButton(n=>{n.setIcon("trash").setTooltip(L("Delete")).onClick(()=>{this.plugin.removeAdmonition(c),this.display()})})}}},l1=classextendsz.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,t=newz.Setting(a).setName(L("Admonition Type")).a
`).replace(/^> /gm,"")).then(async()=>{new k1.Notice("Callout content copied to clipboard.")})})}}if(t.noTitle&&!i.dataset.calloutFold&&r.addClass("no-title"),!t.noTitle&&this.plugin.data.autoCollapse&&!i.dataset.calloutFold&&this.setCollapsible(i),t.title&&r.textContent==n[0].toUpperCase()+n.slice(1).toLowerCase()){let f=r.querySelector(".callout-title-inner");f&&f.setText(t.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 t=c.hasClass("is-collapsed");if(this.getComputedHeights(i),t)for(let r of this.heights)i.style.setProperty(r,"0px");a.onclick=r=>{r.preventDefault();function o(l){i.removeEventListener("transitionend",o),i.style.removeProperty("transition")}if(i.addEventListener("transitionend",o),i.style.setProperty("transition","all 100ms cubic-bezier(.02, .01, .47, 1)"),t=c.hasClass("is-collapsed"),r.button==0){for(let l of this.heights){let f=this.getComputedHeights(i);i.style.setProperty(l,t?f[l]:"0px")}c.toggleClass("is-collapsed",!t)}}}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 on ${new Date().toLocaleString()} */
`);let r=i.getCursor();i.setCursor(r.line-2)}catch{new b.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 t=i.getCursor();i.setCursor(t.line-2)}catch{new b.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 t=c.title??"";i.getDoc().replaceSelection(`\`\`\`ad-${c.type}
`);let r=i.getCursor();i.setCursor(r.line-3)}catch{new b.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)&&(b.MarkdownPreviewRenderer.unregisterPostProcessor(this.postprocessors.get(c.type)),b.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({},Zb,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 b.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,t)=>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()}};