var k=Object.create;var c=Object.defineProperty,B=Object.defineProperties,F=Object.getOwnPropertyDescriptor,V=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertyNames,x=Object.getOwnPropertySymbols,I=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var w=(n,t,e)=>t in n?c(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))L.call(t,e)&&w(n,e,t[e]);if(x)for(var e of x(t))j.call(t,e)&&w(n,e,t[e]);return n},T=(n,t)=>B(n,V(t)),M=n=>c(n,"__esModule",{value:!0});var X=typeof require!="undefined"?require:n=>{throw new Error('Dynamic require of "'+n+'" is not supported')};var Y=(n,t)=>{M(n);for(var e in t)c(n,e,{get:t[e],enumerable:!0})},$=(n,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of W(t))!L.call(n,i)&&i!=="default"&&c(n,i,{get:()=>t[i],enumerable:!(e=F(t,i))||e.enumerable});return n},h=n=>$(M(c(n!=null?k(I(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var r=(n,t,e)=>new Promise((i,s)=>{var a=o=>{try{d(e.next(o))}catch(E){s(E)}},p=o=>{try{d(e.throw(o))}catch(E){s(E)}},d=o=>o.done?i(o.value):Promise.resolve(o.value).then(a,p);d((e=e.apply(n,t)).next())});Y(exports,{default:()=>b});var R=h(require("obsidian"));var A=h(require("obsidian"));function O(n,t){let e=Object.assign({},t,n);return Object.keys(e).reduce((i,s)=>{let a=n[s],p=typeof a=="undefined"||a===null;return T(u({},i),{[s]:p?t[s]:a})},{})}function P(n,t){try{let e=(0,A.parseYaml)(n);return O(e,t)}catch(e){return t}}var v={style:"bullet",min_depth:2,max_depth:6,externalStyle:""},m="dynamic-toc",H=`.${m}`;var f=h(require("obsidian"));function K(n){return n.replace(/[[\]]/g,"")}function y(n,t){let{headings:e}=n,i=e.filter(a=>a.level>=t.min_depth&&a.level<=t.max_depth),s=i[0].level;return i.map(a=>{let p=t.style==="number"&&"1."||"-",d=new Array(Math.max(0,a.level-s)).fill(" ").join(""),o=K(a.heading);return`${d}${p} [[#${o}|${o}]]`}).join(` `)}function N(n){let t=null;return{start:()=>{t=new Date().getTime()},stop:()=>{!t||console.log(`Dynamic TOC ${n} completed in ${new Date().getTime()-t}ms.`)}}}var _=class extends f.MarkdownRenderChild{constructor(t,e,i,s){super(s);this.app=t;this.config=e;this.filePath=i;this.container=s;this.onSettingsChangeHandler=t=>{this.render(O(this.config,t))};this.onFileChangeHandler=t=>{t.deleted||t.path!==this.filePath||this.render()}}onload(){return r(this,null,function*(){yield this.render(),this.registerEvent(this.app.metadataCache.on("dynamic-toc:settings",this.onSettingsChangeHandler)),this.registerEvent(this.app.metadataCache.on("changed",this.onFileChangeHandler))})}render(t){return r(this,null,function*(){let e=N("codeblock renderer");e.start(),this.container.empty(),this.container.classList.add(m);let i=y(this.app.metadataCache.getCache(this.filePath),t||this.config);yield f.MarkdownRenderer.renderMarkdown(i,this.container,this.filePath,this),e.stop()})}};var l=h(require("obsidian"));var g={None:"",TOC:"[TOC]",_TOC_:"__TOC__"};var D=class extends l.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){let{containerEl:t}=this;t.empty(),t.createEl("h2",{text:"Dynamic Table of Contents Settings"}),new l.Setting(t).setName("List Style").setDesc("The table indication").addDropdown(e=>e.addOptions({bullet:"Bullet",number:"Number"}).setValue(this.plugin.settings.style).onChange(i=>r(this,null,function*(){this.plugin.settings.style=i,yield this.plugin.saveSettings()}))),new l.Setting(t).setName("Minimum Header Depth").setDesc("The default minimum header depth to render").addSlider(e=>e.setLimits(1,6,1).setValue(this.plugin.settings.min_depth).setDynamicTooltip().onChange(i=>r(this,null,function*(){i>this.plugin.settings.max_depth?new l.Notice("Min Depth is higher than Max Depth"):(this.plugin.settings.min_depth=i,yield this.plugin.saveSettings())}))),new l.Setting(t).setName("Maximum Header Depth").setDesc("The default maximum header depth to render").addSlider(e=>e.setLimits(1,6,1).setValue(this.plugin.settings.max_depth).setDynamicTooltip().onChange(i=>r(this,null,function*(){ie.addOptions(Object.keys(g).reduce((i,s)=>{let a=g[s];return T(u({},i),{[s]:a})},{})).setValue(this.plugin.settings.externalStyle).onChange(i=>r(this,null,function*(){this.plugin.settings.externalStyle=i,yield this.plugin.saveSettings()})))}};var C=h(require("obsidian"));var S=class extends C.MarkdownRenderChild{constructor(t,e,i,s,a){super(s);this.app=t;this.settings=e;this.filePath=i;this.match=a;this.onSettingsChangeHandler=()=>{this.render()};this.onFileChangeHandler=t=>{t.deleted||t.path!==this.filePath||this.render()}}static findMatch(t,e){return Array.from(t.querySelectorAll("p, span, a")).find(s=>s.textContent.toLowerCase().includes(e.toLowerCase()))||null}onload(){return r(this,null,function*(){this.render(),this.registerEvent(this.app.metadataCache.on("dynamic-toc:settings",this.onSettingsChangeHandler)),this.registerEvent(this.app.metadataCache.on("changed",this.onFileChangeHandler))})}render(){return r(this,null,function*(){let t=y(this.app.metadataCache.getCache(this.filePath),this.settings),e=document.createElement("div");e.classList.add(m),yield C.MarkdownRenderer.renderMarkdown(t,e,this.filePath,this),this.match.style.display="none";let i=this.containerEl.querySelector(H);i&&this.containerEl.removeChild(i),this.match.parentNode.appendChild(e)})}};var b=class extends R.Plugin{constructor(){super(...arguments);this.onload=()=>r(this,null,function*(){yield this.loadSettings(),console.log("Dynamic TOC Loaded"),this.addSettingTab(new D(this.app,this)),this.registerMarkdownCodeBlockProcessor("toc",(t,e,i)=>{let s=P(t,this.settings);i.addChild(new _(this.app,s,i.sourcePath,e))}),this.registerMarkdownPostProcessor((t,e)=>{let i=g[this.settings.externalStyle];if(!i)return;let s=null;try{s=S.findMatch(t,i)}catch(a){console.error(a)}(s==null?void 0:s.parentNode)&&e.addChild(new S(this.app,this.settings,e.sourcePath,t,s))})});this.loadSettings=()=>r(this,null,function*(){this.settings=Object.assign({},v,yield this.loadData())});this.saveSettings=()=>r(this,null,function*(){yield this.saveData(this.settings),this.app.metadataCache.trigger("dynamic-toc:settings",this.settings)})}};0&&(module.exports={});