(()=>{"use strict";const e=class{constructor(e,t){this.element=e,this.isFrontend=t,this.scrollTarget=t?window:document.querySelector('[name="editor-canvas"]')?.contentWindow,this.circle=this.element?.querySelector(".ablocks-scroll-progress-ring__circle"),this.scrollButton=this.element?.querySelector(".ablocks-scroll-progress-wrapper, .ablocks-scroll-to-top-button-text, .ablocks-icon-wrap"),this.setupCircle(),this.init()}setupCircle(){this.circle&&(this.radius=this.circle.r.baseVal.value,this.circumference=2*Math.PI*this.radius,Object.assign(this.circle.style,{strokeDasharray:`${this.circumference} ${this.circumference}`,strokeDashoffset:this.circumference,transform:"rotate(-90deg)",transformOrigin:"50% 50%"}))}init(){this.element&&this.scrollTarget&&(this.scrollTarget.addEventListener("scroll",()=>this.updateProgress()),this.scrollButton?.addEventListener("click",()=>{this.scrollTarget.scrollTo({top:0,behavior:"smooth"})}),this.updateProgress())}updateProgress(){if(!this.scrollTarget?.document)return;const{document:e,innerHeight:t,scrollY:s}=this.scrollTarget,i=e.documentElement.scrollHeight-t,r=null!=s?s:e.documentElement.scrollTop;if(this.isFrontend&&(0===r?(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.style.transition="opacity 0.3s ease"):(this.element.style.visibility="visible",this.element.style.opacity="1",this.element.style.transition="opacity 0.3s ease")),this.circle){const e=i>0?r/i:0;this.circle.style.strokeDashoffset=this.circumference*(1-e)}}};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".ablocks-block--scroll-to-top").forEach(t=>{new e(t,!0)})})})();