`);return d!==void 0&&d!=="none"&&d!=="open"&&d!=="closed"&&(d="closed"),"title"in r||e.noTitle||(m=t),m&&m.trim()===""&&d!==void 0&&d!=="none"&&(m=t,new he.Notice("An admonition must have a title if it is collapsible.")),{title:m,collapse:d,content:w,icon:g,color:h,metadata:p}}function Xe(c,n,e){let t=c/360,o=n/100,i=e/100,a=0,s=0,r=0,m=Math.floor(t*6),d=t*6-m,g=i*(1-o),h=i*(1-d*o),p=i*(1-(1-d)*o);switch(m%6){case 0:a=i,s=p,r=g;break;case 1:a=h,s=i,r=g;break;case 2:a=g,s=i,r=p;break;case 3:a=g,s=h,r=i;break;case 4:a=p,s=g,r=i;break;case 5:a=i,s=g,r=h;break}return[Math.round(a*255),Math.round(s*255),Math.round(r*255)]}var D=require("obsidian");var z=class extends D.Component{constructor(e){super();u(this,"plugin",e);u(this,"style");u(this,"heights",["height","padding-top","padding-bottom","margin-top","margin-bottom"]);u(this,"heightMap",new WeakMap);u(this,"indexing",[]);this.style=activeDocument.head.createEl("style",{attr:{id:"ADMONITIONS_CUSTOM_STYLE_SHEET"}})}get sheet(){return this.style.sheet}onload(){activeDocument.head.appendChild(this.style);for(let e of Object.values(this.plugin.data.userAdmonitions))this.addAdmonition(e);this.setUseSnippet()}calloutProcessor(e,t){let o=e?.querySelector(".callout");if(!o)return;let i=o.dataset.callout,a=i?this.plugin.admonitions[i]:void 0;if(!a)return;let s=o.querySelector(".callout-title"),r=o.querySelector(".callout-content");if(!s||!r)return;let m=t.getSectionInfo(e);if(m){let{text:g,lineStart:h,lineEnd:p}=m,w=g.split(`
`).replace(/^> /gm,"")).then(()=>{new D.Notice("Callout content copied to clipboard.")})})}}a.noTitle&&!o.dataset.calloutFold&&s.querySelector(".callout-title-inner")?.textContent?.toLowerCase()===a.type.toLowerCase()&&s.addClass("no-title"),!a.noTitle&&this.plugin.data.autoCollapse&&!o.dataset.calloutFold&&this.setCollapsible(o);let d=s?.querySelector(".callout-title-inner");if(d&&a.title){let g=d.textContent?.toLowerCase()??"";(g===i?.toLowerCase()||g==="")&&d.setText(a.title)}this.plugin.data.dropShadow&&o.addClass("drop-shadow")}setCollapsible(e){let t=e.querySelector(".callout-title"),o=e.querySelector(".callout-content");if(!o||!t)return;e.addClass("is-collapsible"),this.plugin.data.defaultCollapseType==="closed"?(e.dataset.calloutFold="-",e.addClass("is-collapsed")):e.dataset.calloutFold="+";let i=t.createDiv("callout-fold");(0,D.setIcon)(i,"chevron-down");let a=e.hasClass("is-collapsed");if(this.getComputedHeights(o),a){let s={};for(let r of this.heights)s[r]="0px";o.setCssStyles(s)}t.onclick=s=>{this.collapse(e,s)}}collapse(e,t){t?.preventDefault();let o=e.querySelector(".callout-content");if(!o)return;let i=s=>{o.removeEventListener("transitionend",i),o.style.removeProperty("transition")};o.addEventListener("transitionend",i),o.setCssStyles({transition:"all 100ms cubic-bezier(.02, .01, .47, 1)"});let a=e.hasClass("is-collapsed");if(!t||t.button===0){let s=this.getComputedHeights(o);for(let r of this.heights)o.style.setProperty(r,a?s[r]:"0px");e.toggleClass("is-collapsed",!a)}}getComputedHeights(e){if(this.heightMap.has(e))return this.heightMap.get(e);let t=getComputedStyle(e),o={};for(let i of this.heights)o[i]=t.getPropertyValue(i);return this.heightMap.set(e,o),o}generateCssString(){let e=[`/* This snippet was auto-generated by the Admonitions plugin */
`)}addAdmonition(e){if(!this.sheet)return;let t=e.type.toLowerCase();if(this.indexing.contains(t)){let s=this.indexing.indexOf(t);this.sheet.deleteRule(s),this.indexing.splice(s,1)}if(this.plugin.isIconWithCss(e)){this.updateSnippet();return}let o=this.plugin.shouldInjectColor(e)?`--callout-color: ${e.color};`:"",i="";if(e.icon?.name&&e.icon?.type&&(e.icon.type==="obsidian"?i=`--callout-icon: ${e.icon.name}; /* Icon name from the Obsidian Icon Set */`:i=`--callout-icon: "${(this.plugin.iconManager.getIconNode(e.icon)?.outerHTML??"").replace(/(width|height)=(\\?"|')\d+(\\?"|')/g,"").replace(/"/g,'\\"')}";`),!o&&!i){this.updateSnippet();return}let a=`.callout[data-callout="${t}"] {
`);lets=o.getCursor();o.setCursor(s.line-2)}catch{newf.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${e.type}`,name:`Insert ${e.type}`,editorCheckCallback:(t,o,i)=>{if(t)returne.command;if(e.command)try{o.replaceSelection(`\`\`\`ad-${e.type}
`);leta=o.getCursor();o.setCursor(a.line-2)}catch{newf.Notice("There was an issue inserting the admonition.")}}}),this.addCommand({id:`insert-${e.type}-with-title`,name:`Insert ${e.type} With Title`,editorCheckCallback:(t,o,i)=>{if(t)returne.command;if(e.command)try{leta=e.title??"";o.replaceSelection(`\`\`\`ad-${e.type}
`);lets=o.getCursor();o.setCursor(s.line-3)}catch{newf.Notice("There was an issue inserting the admonition.")}}})}unregisterType(e){this.data.syntaxHighlight&&this.turnOffSyntaxHighlighting([e.type]),e.command&&this.unregisterCommandsFor(e);lett=this.postprocessors.get(e.type);t&&(f.MarkdownPreviewRenderer.unregisterPostProcessor(t),f.MarkdownPreviewRenderer.unregisterCodeBlockPostProcessor(`ad-${e.type}`),this.postprocessors.delete(e.type))}asyncremoveAdmonition(e){this.data.userAdmonitions[e.type]&&deletethis.data.userAdmonitions[e.type],this.unregisterType(e),this.calloutManager.removeAdmonition(e),awaitthis.saveSettings()}unregisterCommandsFor(e){e.command=!1,this.removeCommand(`insert-${e.type}-callout`),this.removeCommand(`insert-${e.type}`),this.removeCommand(`insert-${e.type}-with-title`)}asyncsaveSettings(){this.data.version=this.manifest.version;lete={...this.data};deletee.msDocConverted,awaitthis.saveData(e)}asyncloadSettings(){lete=awaitthis.loadData();if(this.data=Object.assign({},at,e),this.data.userAdmonitions){if(!this.data.version||Number(this.data.version.split(".")[0])<5)for(lettinthis.data.userAdmonitions)Object.hasOwn(this.data.userAdmonitions[t],"type")||(this.data.userAdmonitions[t]={...this.data.userAdmonitions[t],icon:{type:"font-awesome",name:this.data.userAdmonitions[t].icon}});for(lettofObject.keys(this.data.userAdmonitions)){leto=this.data.userAdmonitions[t];o.color&&/^\d+,\s*\d+,\s*\d+$/.test(o.color)&&(o.color=`rgb(${o.color})`)}}if(!this.data.rpgDownloadedOnce&&this.data.userAdmonitions&&Object.values(this.data.userAdmonitions).some(t=>t.icon?.type==="rpg")&&!this.data.icons.includes("rpg"))try{awaitthis.downloadIcon("rpg"),this.data.rpgDownloadedOnce=!0}catch{}if(this.data.useFontAwesome&&this.data.userAdmonitions){lett=newSet;for(letoofObject.values(this.data.userAdmonitions)){if(o.icon?.type!=="font-awesome"||!o.icon.name)continue;leti=K(o.icon.name);i&&(o.icon.type=i,t.add(i))}for(letooft)if(!this.data.icons.includes(o))try{awaitthis.downloadIcon(o)}catch{}this.data.useFontAwesome=!1}if(this.data.userAdmonitions)for(lettofObject.keys(this.data.userAdmonitions)){leto=t.toLowerCase();o!==t&&(this.data.userAdmonitions[o]={...this.data.userAdmonitions[t],type:o},deletethis.data.userAdmonitions[t])}awaitthis.saveSettings()}turnOnSyntaxHighlighting(e=Object.keys(this.admonitions)){this.data.syntaxHighlight&&(e.forEach(t=>{leto=`${t}`.match(/^([\w+#-]*)[^\n`]*$/);if(!o)return;let[,i]=o;window.CodeMirror.defineMode(`ad-${i}`,(a,s)=>window.CodeMirror.getMode({},"hypermd"))}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(t=>t.setOption("mode",t.getOption("mode")))))}turnOffSyntaxHighlighting(e=Object.keys(this.admonitions)){e.forEach(t=>{Object.hasOwn(window.CodeMirror.modes,`ad-${t}`)&&deletewindow.CodeMirror.modes[`ad-${t}`]}),this.app.workspace.onLayoutReady(()=>this.app.workspace.iterateCodeMirrors(t=>t.setOption("mode",t.getOption("mode"))))}onunload(){console.debug("Obsidian Admonition unloaded"),this.postprocessors.clear(),this.turnOffSyntaxHighlighting()}};