(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=jQuery;var n=t.n(e);document.addEventListener("DOMContentLoaded",function(){i.init()});const i={init:function(){this.holder=document.querySelectorAll(".qi-block-table-of-contents"),this.holder.length&&[...this.holder].map(t=>{i.initItem(t)})},getRealCurrentItem:function(t){return"string"==typeof t&&""!==t&&(t=qiBlocksEditor.qodefGetCurrentBlockElement.get(t)),t},initItem:function(t,e){if(!(t=i.getRealCurrentItem(t)))return;let r,o=["h1","h2","h3","h4","h5","h6"],l=t.querySelector(".qodef-m-table-content"),a=void 0!==l.getAttribute("data-excluded-tags")?l.getAttribute("data-excluded-tags"):"",c=void 0!==l.getAttribute("data-excluded-cids")?l.getAttribute("data-excluded-cids"):"",d=void 0!==l.getAttribute("data-type")?l.getAttribute("data-type"):"ul",u=n()(t.querySelector(".qodef-m-table-content > "+d)),f="",s={},p={},h=[".qodef-e-number",".qodef-e-mark"],g=0;e&&(g=200,o=o.map(function(t){return".block-editor-block-list__layout.is-root-container "+t}),o.push(".editor-post-title.editor-post-title__block .editor-post-title__input")),setTimeout(()=>{r=i.prepareHeadings(a,c,o,e),e&&u.empty(),r.length&&(r.forEach((t,e)=>{let r,o=n()(t),l=o.clone();if(r=i.prepareId(h,l,f),f+=r.id+";",s[e]={id:r.finalID,tag:o.prop("tagName").replace("H","")},e>0){const t=o.prop("tagName").replace("H",""),n=s[e-1].tag;if(t>n){const t=u.find("a[href=#"+s[e-1].id+"]").parent();t.append("<"+d+">"),u=t.find(d).first()}else if(t<n){const n=i.findSiblings(t,e,s),r=u.parents(".qodef-m-table-content").find("a[href=#"+n+"]").parent();u=r.parents(d).first()}}o.attr("id",r.finalID);var a=n()("<li>");n()("<a>").attr("href","#"+r.finalID).text(l.text()).appendTo(a),a.appendTo(u)}),p=l.querySelectorAll("li > a"),p.forEach(t=>{t.addEventListener("click",function(e){e.preventDefault(),i.animateAnchor(t,t.getAttribute("href"))})}))},g)},prepareHeadings:function(t,e,i,r){let o,l,a,c=[],d="";if(0<t.length){l=t.split(","),r&&(l=l.map(function(t){return".block-editor-block-list__layout.is-root-container "+t}));for(let t=0;t<l.length;t++)-1!==i.indexOf(l[t])&&i.splice(i.indexOf(l[t]),1)}if(0<e.length){a=e.split(",");for(let t=0;t<a.length;t++)[".","#"].includes(a[t])||(d+=":not("+a[t]+")")}i=i.join(d+", ")+d;let u=document;document.body.classList.contains("wp-admin")&&(u=qiBlocksEditor.qodefGetCurrentBlockElement.getCurrentDocument()),o=u.querySelectorAll(i),Array.isArray(o)||(o=Array.from(o)),o.length&&o.forEach((t,e)=>{const i=n()(t);for(let t=0;t<a.length;t++)if(![".","#"].includes(a[t])){if(i.parents(a[t]).length)return void c.push(e)}});for(let t=c.length-1;t>=0;t--)o.splice(c[t],1);return o},prepareId:function(t,e,n){let i={};if(t.forEach(function(t){e.find(t).remove()}),i.id=e.text().trim().replaceAll(" ","_").replaceAll(/[^a-zA-Z_]+/g,""),0!==n.length){let t=new RegExp(i.id+";","g"),e=n.match(t),r=0;null!==e&&(r=e.length),0!==r?(r+=1,i.finalID=i.id+"____"+r):i.finalID=i.id}else i.finalID=i.id;return i},findSiblings:function(t,e,n){if(0===e)return n[0].id;{const r=e-1;return n[r].tag>t?i.findSiblings(t,r,n):n[r].id}},animateAnchor:function(t,e){let r,o=window.scrollY,l=n()(e).offset().top,a=o>l?-1:1,c=50,d=n()("#wpadminbar");d.length&&(l-=d.height());const u=function(){if(o===l)return;Math.abs(o-l)<=100&&(c=8),(-1===a&&o<l||1===a&&o>l)&&(o=l);const t=i.easingFunction((o-l)/o);n()("html, body").scrollTop(o-(o-l)*t),o+=a*c,r=requestAnimationFrame(u)};u(),n()(window).one("wheel touchstart",function(){cancelAnimationFrame(r)})},easingFunction:function(t){return 0===t?0:Math.pow(1024,t-1)}}})();