import{T as yt,s as St,b as ct,e as N,h as ht,c as D,d as k,g as d,u as P,U as T,j as b,k as j,n as $,m as tt,o as Et,V as et,w as ot,t as z,p as U,f as C,W as xt,l as Mt}from"./scheduler.DwsPIhql.js";import{S as Zt,i as zt}from"./index.md5u5HDA.js";import{am as Ct,an as H,ak as nt,al as Pt,ao as F,ap as At,aq as Nt,ar as it,as as Dt,a as Bt}from"./state.Ctxf--Md.js";function st(t){return(t==null?void 0:t.length)!==void 0?t:Array.from(t)}let L=!0,ft,R,W;const It=1e3,Tt=150,pt=Ct(()=>{L=!0,ft()},It),_t=(t,e)=>{W==null||W();const{autoSync:o}=yt(H);if(!o)return;ft=e;const n=t>Tt;L||pt(),L=!n},Vt=()=>(R||(R=new Promise(t=>{W=()=>{R=void 0,t()}})),L||pt(),L),ee=()=>R??Promise.resolve();var kt=function(){var t="",e,o,n,i=[],s={passive:!0};window.addEventListener?(e="addEventListener",o="removeEventListener"):(e="attachEvent",o="detachEvent",t="on"),n="onwheel"in document.createElement("div")?"wheel":document.onmousewheel!==void 0?"mousewheel":"DOMMouseScroll";function r(m,p){var f=function(v){!v&&(v=window.event);var w={originalEvent:v,target:v.target||v.srcElement,type:"wheel",deltaMode:v.type=="MozMousePixelScroll"?0:1,deltaX:0,delatZ:0,preventDefault:function(){v.preventDefault?v.preventDefault():v.returnValue=!1}};return n=="mousewheel"?(w.deltaY=-.025*v.wheelDelta,v.wheelDeltaX&&(w.deltaX=-.025*v.wheelDeltaX)):w.deltaY=v.detail,p(w)};return i.push({element:m,fn:f}),f}function a(m){for(var p=0;pe?(clearTimeout(a),a=null,l=M,r=t.apply(i,s),a||(i=s=null)):!a&&o.trailing!==!1&&(a=setTimeout(h,E)),r}},createRequestAnimationFrame:function(t){var e=null;return t!=="auto"&&t<60&&t>1&&(e=Math.floor(1e3/t)),e===null?window.requestAnimationFrame||rt(33):rt(e)}};function rt(t){return function(e){window.setTimeout(e,t)}}var X=K,mt="unknown";document.documentMode&&(mt="ie");var J={svgNS:"http://www.w3.org/2000/svg",xmlNS:"http://www.w3.org/XML/1998/namespace",xmlnsNS:"http://www.w3.org/2000/xmlns/",xlinkNS:"http://www.w3.org/1999/xlink",evNS:"http://www.w3.org/2001/xml-events",getBoundingClientRectNormalized:function(t){if(t.clientWidth&&t.clientHeight)return{width:t.clientWidth,height:t.clientHeight};if(t.getBoundingClientRect())return t.getBoundingClientRect();throw new Error("Cannot get BoundingClientRect for SVG.")},getOrCreateViewport:function(t,e){var o=null;if(X.isElement(e)?o=e:o=t.querySelector(e),!o){var n=Array.prototype.slice.call(t.childNodes||t.children).filter(function(l){return l.nodeName!=="defs"&&l.nodeName!=="#text"});n.length===1&&n[0].nodeName==="g"&&n[0].getAttribute("transform")===null&&(o=n[0])}if(!o){var i="viewport-"+new Date().toISOString().replace(/\D/g,"");o=document.createElementNS(this.svgNS,"g"),o.setAttribute("id",i);var s=t.childNodes||t.children;if(s&&s.length>0)for(var r=s.length;r>0;r--)s[s.length-r].nodeName!=="defs"&&o.appendChild(s[s.length-r]);t.appendChild(o)}var a=[];return o.getAttribute("class")&&(a=o.getAttribute("class").split(" ")),~a.indexOf("svg-pan-zoom_viewport")||(a.push("svg-pan-zoom_viewport"),o.setAttribute("class",a.join(" "))),o},setupSvgAttributes:function(t){if(t.setAttribute("xmlns",this.svgNS),t.setAttributeNS(this.xmlnsNS,"xmlns:xlink",this.xlinkNS),t.setAttributeNS(this.xmlnsNS,"xmlns:ev",this.evNS),t.parentNode!==null){var e=t.getAttribute("style")||"";e.toLowerCase().indexOf("overflow")===-1&&t.setAttribute("style","overflow: hidden; "+e)}},internetExplorerRedisplayInterval:300,refreshDefsGlobal:X.throttle(function(){for(var t=document.querySelectorAll("defs"),e=t.length,o=0;o=0;n--)this.eventListeners.hasOwnProperty(o[n])&&delete this.eventListeners[o[n]]}for(var i in this.eventListeners)(this.options.eventsListenerElement||this.svg).addEventListener(i,this.eventListeners[i],this.options.preventMouseEventsDefault?!1:vt);this.options.mouseWheelZoomEnabled&&(this.options.mouseWheelZoomEnabled=!1,this.enableMouseWheelZoom())};c.prototype.enableMouseWheelZoom=function(){if(!this.options.mouseWheelZoomEnabled){var t=this;this.wheelListener=function(o){return t.handleMouseWheel(o)};var e=!this.options.preventMouseEventsDefault;dt.on(this.options.eventsListenerElement||this.svg,this.wheelListener,e),this.options.mouseWheelZoomEnabled=!0}};c.prototype.disableMouseWheelZoom=function(){if(this.options.mouseWheelZoomEnabled){var t=!this.options.preventMouseEventsDefault;dt.off(this.options.eventsListenerElement||this.svg,this.wheelListener,t),this.options.mouseWheelZoomEnabled=!1}};c.prototype.handleMouseWheel=function(t){if(!(!this.options.zoomEnabled||this.state!=="none")){this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1);var e=t.deltaY||1,o=Date.now()-this.lastMouseWheelEventTime,n=3+Math.max(0,30-o);this.lastMouseWheelEventTime=Date.now(),"deltaMode"in t&&t.deltaMode===0&&t.wheelDelta&&(e=t.deltaY===0?0:Math.abs(t.wheelDelta)/t.deltaY),e=-.30?1:-1)*Math.log(Math.abs(e)+10)/n;var i=this.svg.getScreenCTM().inverse(),s=x.getEventPoint(t,this.svg).matrixTransform(i),r=Math.pow(1+this.options.zoomScaleSensitivity,-1*e);this.zoomAtPoint(r,s)}};c.prototype.zoomAtPoint=function(t,e,o){var n=this.viewport.getOriginalState();o?(t=Math.max(this.options.minZoom*n.zoom,Math.min(this.options.maxZoom*n.zoom,t)),t=t/this.getZoom()):this.getZoom()*tthis.options.maxZoom*n.zoom&&(t=this.options.maxZoom*n.zoom/this.getZoom());var i=this.viewport.getCTM(),s=e.matrixTransform(i.inverse()),r=this.svg.createSVGMatrix().translate(s.x,s.y).scale(t).translate(-s.x,-s.y),a=i.multiply(r);a.a!==i.a&&this.viewport.setCTM(a)};c.prototype.zoom=function(t,e){this.zoomAtPoint(t,x.getSvgCenterPoint(this.svg,this.width,this.height),e)};c.prototype.publicZoom=function(t,e){e&&(t=this.computeFromRelativeZoom(t)),this.zoom(t,e)};c.prototype.publicZoomAtPoint=function(t,e,o){if(o&&(t=this.computeFromRelativeZoom(t)),S.getType(e)!=="SVGPoint")if("x"in e&&"y"in e)e=x.createSVGPoint(this.svg,e.x,e.y);else throw new Error("Given point is invalid");this.zoomAtPoint(t,e,o)};c.prototype.getZoom=function(){return this.viewport.getZoom()};c.prototype.getRelativeZoom=function(){return this.viewport.getRelativeZoom()};c.prototype.computeFromRelativeZoom=function(t){return t*this.viewport.getOriginalState().zoom};c.prototype.resetZoom=function(){var t=this.viewport.getOriginalState();this.zoom(t.zoom,!0)};c.prototype.resetPan=function(){this.pan(this.viewport.getOriginalState())};c.prototype.reset=function(){this.resetZoom(),this.resetPan()};c.prototype.handleDblClick=function(t){if(this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1),this.options.controlIconsEnabled){var e=t.target.getAttribute("class")||"";if(e.indexOf("svg-pan-zoom-control")>-1)return!1}var o;t.shiftKey?o=1/((1+this.options.zoomScaleSensitivity)*2):o=(1+this.options.zoomScaleSensitivity)*2;var n=x.getEventPoint(t,this.svg).matrixTransform(this.svg.getScreenCTM().inverse());this.zoomAtPoint(o,n)};c.prototype.handleMouseDown=function(t,e){this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1),S.mouseAndTouchNormalize(t,this.svg),this.options.dblClickZoomEnabled&&S.isDblClick(t,e)?this.handleDblClick(t):(this.state="pan",this.firstEventCTM=this.viewport.getCTM(),this.stateOrigin=x.getEventPoint(t,this.svg).matrixTransform(this.firstEventCTM.inverse()))};c.prototype.handleMouseMove=function(t){if(this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1),this.state==="pan"&&this.options.panEnabled){var e=x.getEventPoint(t,this.svg).matrixTransform(this.firstEventCTM.inverse()),o=this.firstEventCTM.translate(e.x-this.stateOrigin.x,e.y-this.stateOrigin.y);this.viewport.setCTM(o)}};c.prototype.handleMouseUp=function(t){this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1),this.state==="pan"&&(this.state="none")};c.prototype.fit=function(){var t=this.viewport.getViewBox(),e=Math.min(this.width/t.width,this.height/t.height);this.zoom(e,!0)};c.prototype.contain=function(){var t=this.viewport.getViewBox(),e=Math.max(this.width/t.width,this.height/t.height);this.zoom(e,!0)};c.prototype.center=function(){var t=this.viewport.getViewBox(),e=(this.width-(t.width+t.x*2)*this.getZoom())*.5,o=(this.height-(t.height+t.y*2)*this.getZoom())*.5;this.getPublicInstance().pan({x:e,y:o})};c.prototype.updateBBox=function(){this.viewport.simpleViewBoxCache()};c.prototype.pan=function(t){var e=this.viewport.getCTM();e.e=t.x,e.f=t.y,this.viewport.setCTM(e)};c.prototype.panBy=function(t){var e=this.viewport.getCTM();e.e+=t.x,e.f+=t.y,this.viewport.setCTM(e)};c.prototype.getPan=function(){var t=this.viewport.getState();return{x:t.x,y:t.y}};c.prototype.resize=function(){var t=x.getBoundingClientRectNormalized(this.svg);this.width=t.width,this.height=t.height;var e=this.viewport;e.options.width=this.width,e.options.height=this.height,e.processCTM(),this.options.controlIconsEnabled&&(this.getPublicInstance().disableControlIcons(),this.getPublicInstance().enableControlIcons())};c.prototype.destroy=function(){var t=this;this.beforeZoom=null,this.onZoom=null,this.beforePan=null,this.onPan=null,this.onUpdatedCTM=null,this.options.customEventsHandler!=null&&this.options.customEventsHandler.destroy({svgElement:this.svg,eventsListenerElement:this.options.eventsListenerElement,instance:this.getPublicInstance()});for(var e in this.eventListeners)(this.options.eventsListenerElement||this.svg).removeEventListener(e,this.eventListeners[e],this.options.preventMouseEventsDefault?!1:vt);this.disableMouseWheelZoom(),this.getPublicInstance().disableControlIcons(),this.reset(),Z=Z.filter(function(o){return o.svg!==t.svg}),delete this.options,delete this.viewport,delete this.publicInstance,delete this.pi,this.getPublicInstance=function(){return null}};c.prototype.getPublicInstance=function(){var t=this;return this.publicInstance||(this.publicInstance=this.pi={enablePan:function(){return t.options.panEnabled=!0,t.pi},disablePan:function(){return t.options.panEnabled=!1,t.pi},isPanEnabled:function(){return!!t.options.panEnabled},pan:function(e){return t.pan(e),t.pi},panBy:function(e){return t.panBy(e),t.pi},getPan:function(){return t.getPan()},setBeforePan:function(e){return t.options.beforePan=e===null?null:S.proxy(e,t.publicInstance),t.pi},setOnPan:function(e){return t.options.onPan=e===null?null:S.proxy(e,t.publicInstance),t.pi},enableZoom:function(){return t.options.zoomEnabled=!0,t.pi},disableZoom:function(){return t.options.zoomEnabled=!1,t.pi},isZoomEnabled:function(){return!!t.options.zoomEnabled},enableControlIcons:function(){return t.options.controlIconsEnabled||(t.options.controlIconsEnabled=!0,Y.enable(t)),t.pi},disableControlIcons:function(){return t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!1,Y.disable(t)),t.pi},isControlIconsEnabled:function(){return!!t.options.controlIconsEnabled},enableDblClickZoom:function(){return t.options.dblClickZoomEnabled=!0,t.pi},disableDblClickZoom:function(){return t.options.dblClickZoomEnabled=!1,t.pi},isDblClickZoomEnabled:function(){return!!t.options.dblClickZoomEnabled},enableMouseWheelZoom:function(){return t.enableMouseWheelZoom(),t.pi},disableMouseWheelZoom:function(){return t.disableMouseWheelZoom(),t.pi},isMouseWheelZoomEnabled:function(){return!!t.options.mouseWheelZoomEnabled},setZoomScaleSensitivity:function(e){return t.options.zoomScaleSensitivity=e,t.pi},setMinZoom:function(e){return t.options.minZoom=e,t.pi},setMaxZoom:function(e){return t.options.maxZoom=e,t.pi},setBeforeZoom:function(e){return t.options.beforeZoom=e===null?null:S.proxy(e,t.publicInstance),t.pi},setOnZoom:function(e){return t.options.onZoom=e===null?null:S.proxy(e,t.publicInstance),t.pi},zoom:function(e){return t.publicZoom(e,!0),t.pi},zoomBy:function(e){return t.publicZoom(e,!1),t.pi},zoomAtPoint:function(e,o){return t.publicZoomAtPoint(e,o,!0),t.pi},zoomAtPointBy:function(e,o){return t.publicZoomAtPoint(e,o,!1),t.pi},zoomIn:function(){return this.zoomBy(1+t.options.zoomScaleSensitivity),t.pi},zoomOut:function(){return this.zoomBy(1/(1+t.options.zoomScaleSensitivity)),t.pi},getZoom:function(){return t.getRelativeZoom()},setOnUpdatedCTM:function(e){return t.options.onUpdatedCTM=e===null?null:S.proxy(e,t.publicInstance),t.pi},resetZoom:function(){return t.resetZoom(),t.pi},resetPan:function(){return t.resetPan(),t.pi},reset:function(){return t.reset(),t.pi},fit:function(){return t.fit(),t.pi},contain:function(){return t.contain(),t.pi},center:function(){return t.center(),t.pi},updateBBox:function(){return t.updateBBox(),t.pi},resize:function(){return t.resize(),t.pi},getSizes:function(){return{width:t.width,height:t.height,realZoom:t.getZoom(),viewBox:t.viewport.getViewBox()}},destroy:function(){return t.destroy(),t.pi}}),this.publicInstance};var Z=[],Ut=function(t,e){var o=S.getSvg(t);if(o===null)return null;for(var n=Z.length-1;n>=0;n--)if(Z[n].svg===o)return Z[n].instance.getPublicInstance();return Z.push({svg:o,instance:new c(o,e)}),Z[Z.length-1].instance.getPublicInstance()},Gt=Ut;const Ft=Pt(Gt);function at(t,e,o){const n=t.slice();return n[18]=e[o],n}function lt(t){let e,o;function n(r,a){return r[2]?jt:Xt}let i=n(t),s=i(t);return{c(){e=N("div"),s.c(),this.h()},l(r){e=D(r,"DIV",{class:!0,id:!0});var a=k(e);s.l(a),a.forEach(d),this.h()},h(){P(e,"class",o="absolute z-10 w-full p-2 font-mono "+(t[2]?"text-red-600":"text-yellow-600")+" bg-base-100 bg-opacity-80 text-left"),P(e,"id","errorContainer")},m(r,a){b(r,e,a),s.m(e,null)},p(r,a){i===(i=n(r))&&s?s.p(r,a):(s.d(1),s=i(r),s&&(s.c(),s.m(e,null))),a&4&&o!==(o="absolute z-10 w-full p-2 font-mono "+(r[2]?"text-red-600":"text-yellow-600")+" bg-base-100 bg-opacity-80 text-left")&&P(e,"class",o)},d(r){r&&d(e),s.d()}}}function Xt(t){let e,o,n,i;function s(l,h){return l[6].autoSync?Yt:Ht}let r=s(t),a=r(t);return{c(){e=z("Diagram out of sync. "),o=N("br"),n=ct(),a.c(),i=U()},l(l){e=C(l,"Diagram out of sync. "),o=D(l,"BR",{}),n=ht(l),a.l(l),i=U()},m(l,h){b(l,e,h),b(l,o,h),b(l,n,h),a.m(l,h),b(l,i,h)},p(l,h){r!==(r=s(l))&&(a.d(1),a=r(l),a&&(a.c(),a.m(i.parentNode,i)))},d(l){l&&(d(e),d(o),d(n),d(i)),a.d(l)}}}function jt(t){let e,o=st(t[3]),n=[];for(let i=0;io(6,n=u)),tt(t,F,u=>o(14,i=u));let s="",r="",a,l,h=!1,M=[],E=!1,_=!1,m=!0,p=n.panZoom,f;const v=()=>{if(!f)return;const u=f.getPan(),B=f.getZoom();Dt({pan:u,zoom:B}),Bt("panZoom")},w=u=>{u.panZoom&&(o(5,_=!0),f==null||f.destroy(),f=void 0,Promise.resolve().then(()=>{const B=document.querySelector("#graph-div");if(!B)return;f=Ft(B,{onPan:v,onZoom:v,controlIconsEnabled:!0,fit:!0,center:!0});const{pan:V,zoom:I}=u;V!==void 0&&I!==void 0&&Number.isFinite(I)&&(f.zoom(I),f.pan(V)),o(5,_=!1)}))},gt=async u=>{var I;const B=Date.now();if(u.error!==void 0){o(2,h=!0),o(3,M=u.error.toString().split(` `));return}o(2,h=!1);try{if(a&&u&&(u.updateDiagram||u.autoSync)){if(u.autoSync||et(F,i.updateDiagram=!1,i),o(4,E=!1),m=!0,s===u.code&&r===u.mermaid&&p===u.panZoom)return;if(!Vt()){o(4,E=!0);return}s=u.code,r=u.mermaid,p=u.panZoom;const O=(I=l.parentElement)==null?void 0:I.scrollTop;delete a.dataset.processed;const{svg:G,bindFunctions:Q}=await At(Object.assign({},JSON.parse(u.mermaid)),s,"graph-div");if(G.length>0){w(u),o(0,a.innerHTML=G,a),console.log({svg:G});const q=document.querySelector("#graph-div");if(!q)throw new Error("graph-div not found");q.setAttribute("height","100%"),q.style.maxWidth="100%",Q&&Q(q)}l.parentElement&&O&&o(1,l.parentElement.scrollTop=O,l),o(2,h=!1)}else m?m=!1:(s!==u.code||r!==u.mermaid)&&o(4,E=!0)}catch(O){console.error("view fail",O),o(2,h=!0)}const V=Date.now()-B;Nt(s,V),_t(V,()=>{et(F,i.updateDiagram=!0,i)})};Et(()=>{H.subscribe(u=>{gt(u)}),window.addEventListener("resize",()=>{n.panZoom&&f&&f.resize()})});function bt(u){ot[u?"unshift":"push"](()=>{a=u,o(0,a)})}function wt(u){ot[u?"unshift":"push"](()=>{l=u,o(1,l)})}return[a,l,h,M,E,_,n,bt,wt]}class oe extends Zt{constructor(e){super(),zt(this,e,Jt,Kt,St,{})}}export{oe as V,st as e,ee as w};