`],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 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 o=Object.values(this.plugin.data.userAdmonitions);this.download(o.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 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 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: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 z.Notice(createFragment(f=>{f.createSpan({text:`Therewasanissueimportingthe${t.type}admonition:`}),f.createEl("br"),f.createSpan({text:l.message})}));continue}l.messages?.length&&new z.Notice(createFragment(f=>{f.createSpan({text:`Therewasanissueimportingthe${t.type}admonition:`});for(let s of l.messages)f.createEl("br"),f.createSpan({text:s})})),await this.plugin.addAdmonition(t)}this.display()}catch(r){new z.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 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 o=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));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");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=>{leto={};for(letfinthis.plugin.admonitions){lets=this.plugin.admonitions[f];o[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(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)){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(t2.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(()=>{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(([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(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;a&&(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(){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=newz.Setting(a).setName(L("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.inpu
`).replace(/^> /gm,"")).then(async()=>{new k1.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 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=>{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 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 o=i.getCursor();i.setCursor(o.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 o=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,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()}};