import{S as st,i as rt,s as at,a as lt,k as T,c as ut,l as _,m as k,h as b,n as C,M as N,b as E,H as q,I as W,G as H,o as ht,a2 as ct,w as X,q as D,r as I,a3 as pt,e as F,a4 as ft}from"./index.2bb936cc.js";import{h as j,j as mt,s as Y,k as K,C as dt,z as J,y as vt,b as gt}from"./state.98d33881.js";var bt=function(){var t="",e,o,i,s=[],n={passive:!0};window.addEventListener?(e="addEventListener",o="removeEventListener"):(e="attachEvent",o="detachEvent",t="on"),i="onwheel"in document.createElement("div")?"wheel":document.onmousewheel!==void 0?"mousewheel":"DOMMouseScroll";function r(m,u){var g=function(v){!v&&(v=window.event);var y={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 i=="mousewheel"?(y.deltaY=-.025*v.wheelDelta,v.wheelDeltaX&&(y.deltaX=-.025*v.wheelDeltaX)):y.deltaY=v.detail,u(y)};return s.push({element:m,fn:g}),g}function a(m){for(var u=0;ue?(clearTimeout(a),a=null,p=l,r=t.apply(s,n),a||(s=n=null)):!a&&o.trailing!==!1&&(a=setTimeout(w,f)),r}},createRequestAnimationFrame:function(t){var e=null;return t!=="auto"&&t<60&&t>1&&(e=Math.floor(1e3/t)),e===null?window.requestAnimationFrame||Q(33):Q(e)}};function Q(t){return function(e){window.setTimeout(e,t)}}var L=U,tt="unknown";document.documentMode&&(tt="ie");var G={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(L.isElement(e)?o=e:o=t.querySelector(e),!o){var i=Array.prototype.slice.call(t.childNodes||t.children).filter(function(p){return p.nodeName!=="defs"&&p.nodeName!=="#text"});i.length===1&&i[0].nodeName==="g"&&i[0].getAttribute("transform")===null&&(o=i[0])}if(!o){var s="viewport-"+new Date().toISOString().replace(/\D/g,"");o=document.createElementNS(this.svgNS,"g"),o.setAttribute("id",s);var n=t.childNodes||t.children;if(n&&n.length>0)for(var r=n.length;r>0;r--)n[n.length-r].nodeName!=="defs"&&o.appendChild(n[n.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:L.throttle(function(){for(var t=document.querySelectorAll("defs"),e=t.length,o=0;o=0;i--)this.eventListeners.hasOwnProperty(o[i])&&delete this.eventListeners[o[i]]}for(var s in this.eventListeners)(this.options.eventsListenerElement||this.svg).addEventListener(s,this.eventListeners[s],this.options.preventMouseEventsDefault?!1:ot);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;et.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;et.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,i=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)/i;var s=this.svg.getScreenCTM().inverse(),n=M.getEventPoint(t,this.svg).matrixTransform(s),r=Math.pow(1+this.options.zoomScaleSensitivity,-1*e);this.zoomAtPoint(r,n)}};c.prototype.zoomAtPoint=function(t,e,o){var i=this.viewport.getOriginalState();o?(t=Math.max(this.options.minZoom*i.zoom,Math.min(this.options.maxZoom*i.zoom,t)),t=t/this.getZoom()):this.getZoom()*tthis.options.maxZoom*i.zoom&&(t=this.options.maxZoom*i.zoom/this.getZoom());var s=this.viewport.getCTM(),n=e.matrixTransform(s.inverse()),r=this.svg.createSVGMatrix().translate(n.x,n.y).scale(t).translate(-n.x,-n.y),a=s.multiply(r);a.a!==s.a&&this.viewport.setCTM(a)};c.prototype.zoom=function(t,e){this.zoomAtPoint(t,M.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)),x.getType(e)!=="SVGPoint")if("x"in e&&"y"in e)e=M.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 i=M.getEventPoint(t,this.svg).matrixTransform(this.svg.getScreenCTM().inverse());this.zoomAtPoint(o,i)};c.prototype.handleMouseDown=function(t,e){this.options.preventMouseEventsDefault&&(t.preventDefault?t.preventDefault():t.returnValue=!1),x.mouseAndTouchNormalize(t,this.svg),this.options.dblClickZoomEnabled&&x.isDblClick(t,e)?this.handleDblClick(t):(this.state="pan",this.firstEventCTM=this.viewport.getCTM(),this.stateOrigin=M.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=M.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=M.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:ot);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:x.proxy(e,t.publicInstance),t.pi},setOnPan:function(e){return t.options.onPan=e===null?null:x.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,R.enable(t)),t.pi},disableControlIcons:function(){return t.options.controlIconsEnabled&&(t.options.controlIconsEnabled=!1,R.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:x.proxy(e,t.publicInstance),t.pi},setOnZoom:function(e){return t.options.onZoom=e===null?null:x.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:x.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=[],Mt=function(t,e){var o=x.getSvg(t);if(o===null)return null;for(var i=z.length-1;i>=0;i--)if(z[i].svg===o)return z[i].instance.getPublicInstance();return z.push({svg:o,instance:new c(o,e)}),z[z.length-1].instance.getPublicInstance()},Zt=Mt;const zt=mt(Zt);function $(t){let e,o;function i(r,a){return r[2]?Pt:Ct}let s=i(t),n=s(t);return{c(){e=T("div"),n.c(),this.h()},l(r){e=_(r,"DIV",{class:!0,id:!0});var a=k(e);n.l(a),a.forEach(b),this.h()},h(){C(e,"class",o="absolute w-full p-2 z-10 font-mono "+(t[2]?"text-red-600":"text-yellow-600")+" bg-base-100 bg-opacity-80 text-left"),C(e,"id","errorContainer")},m(r,a){E(r,e,a),n.m(e,null)},p(r,a){s===(s=i(r))&&n?n.p(r,a):(n.d(1),n=s(r),n&&(n.c(),n.m(e,null))),a&4&&o!==(o="absolute w-full p-2 z-10 font-mono "+(r[2]?"text-red-600":"text-yellow-600")+" bg-base-100 bg-opacity-80 text-left")&&C(e,"class",o)},d(r){r&&b(e),n.d()}}}function Ct(t){let e,o,i,s,n,r,a,p,w;return{c(){e=D("Diagram out of sync. "),o=T("br"),i=D(` Press `),s=T("i"),n=D(" (Sync button) or "),r=T("kbd"),a=D(J),p=D(" + Enter"),w=D(" to sync."),this.h()},l(l){e=I(l,"Diagram out of sync. "),o=_(l,"BR",{}),i=I(l,` Press `),s=_(l,"I",{class:!0}),k(s).forEach(b),n=I(l," (Sync button) or "),r=_(l,"KBD",{});var f=k(r);a=I(f,J),p=I(f," + Enter"),f.forEach(b),w=I(l," to sync."),this.h()},h(){C(s,"class","fas fa-sync")},m(l,f){E(l,e,f),E(l,o,f),E(l,i,f),E(l,s,f),E(l,n,f),E(l,r,f),q(r,a),q(r,p),E(l,w,f)},p:W,d(l){l&&b(e),l&&b(o),l&&b(i),l&&b(s),l&&b(n),l&&b(r),l&&b(w)}}}function Pt(t){var s;let e,o=((s=t[5].error)==null?void 0:s.toString().replace(/\n/g,"
"))+"",i;return{c(){e=new pt(!1),i=F(),this.h()},l(n){e=ft(n,!1),i=F(),this.h()},h(){e.a=i},m(n,r){e.m(o,n,r),E(n,i,r)},p(n,r){var a;r&32&&o!==(o=((a=n[5].error)==null?void 0:a.toString().replace(/\n/g,"
"))+"")&&e.p(o)},d(n){n&&b(i),n&&e.d()}}}function At(t){let e,o,i,s=(t[2]&&t[5].error instanceof Error||t[3])&&$(t);return{c(){s&&s.c(),e=lt(),o=T("div"),i=T("div"),this.h()},l(n){s&&s.l(n),e=ut(n),o=_(n,"DIV",{id:!0,class:!0});var r=k(o);i=_(r,"DIV",{id:!0,class:!0}),k(i).forEach(b),r.forEach(b),this.h()},h(){C(i,"id","container"),C(i,"class","h-full overflow-auto svelte-1ewr4tw"),N(i,"hide",t[4]),C(o,"id","view"),C(o,"class","p-2 h-full svelte-1ewr4tw"),N(o,"error",t[2]),N(o,"outOfSync",t[3])},m(n,r){s&&s.m(n,r),E(n,e,r),E(n,o,r),q(o,i),t[6](i),t[7](o)},p(n,[r]){n[2]&&n[5].error instanceof Error||n[3]?s?s.p(n,r):(s=$(n),s.c(),s.m(e.parentNode,e)):s&&(s.d(1),s=null),r&16&&N(i,"hide",n[4]),r&4&&N(o,"error",n[2]),r&8&&N(o,"outOfSync",n[3])},i:W,o:W,d(n){s&&s.d(n),n&&b(e),n&&b(o),t[6](null),t[7](null)}}}function Bt(t,e,o){let i,s;H(t,Y,h=>o(5,i=h)),H(t,K,h=>o(13,s=h));let n="",r="",a,p,w=!1,l=!1,f=!1,V=!0,m=i.panZoom,u;const g=()=>{if(!u)return;const h=u.getPan(),Z=u.getZoom();vt({pan:h,zoom:Z}),gt("panZoom")},v=h=>{h.panZoom&&(o(4,f=!0),u==null||u.destroy(),u=void 0,Promise.resolve().then(()=>{const Z=document.getElementById("graph-div");if(!Z)return;u=zt(Z,{onPan:g,onZoom:g,controlIconsEnabled:!0,fit:!0,center:!0});const{pan:A,zoom:B}=h;A!==void 0&&B!==void 0&&Number.isFinite(B)&&(u.zoom(B),u.pan(A)),o(4,f=!1)}))},y=async h=>{if(h.error!==void 0){o(2,w=!0);return}o(2,w=!1);try{if(a&&h&&(h.updateDiagram||h.autoSync)){if(h.autoSync||ct(K,s.updateDiagram=!1,s),o(3,l=!1),V=!0,n===h.code&&r===h.mermaid&&m===h.panZoom)return;n=h.code,r=h.mermaid,m=h.panZoom;const Z=p.parentElement.scrollTop;delete a.dataset.processed;const{svg:A,bindFunctions:B}=await dt(Object.assign({},JSON.parse(h.mermaid)),n,"graph-div");if(A.length>0){v(h),o(0,a.innerHTML=A,a),console.log({svg:A});const O=document.getElementById("graph-div");if(!O)throw new Error("graph-div not found");O.setAttribute("height","100%"),O.style.maxWidth="100%",B&&B(O)}o(1,p.parentElement.scrollTop=Z,p),o(2,w=!1)}else V?V=!1:(n!==h.code||r!==h.mermaid)&&o(3,l=!0)}catch(Z){console.error("view fail",Z),o(2,w=!0)}};ht(()=>{Y.subscribe(h=>{y(h)}),window.addEventListener("resize",()=>{i.panZoom&&u&&u.resize()})});function it(h){X[h?"unshift":"push"](()=>{a=h,o(0,a)})}function nt(h){X[h?"unshift":"push"](()=>{p=h,o(1,p)})}return[a,p,w,l,f,i,it,nt]}class It extends st{constructor(e){super(),rt(this,e,Bt,At,at,{})}}export{It as V};