vuepress-theme-plume/assets/stateDiagram-MLPALWAM-DnN3EPIS.js

1 line
10 KiB
JavaScript

import{t as e}from"./chunk-VELTKBKT-MF1JIm2u.js";import"./chunk-JIN56HTB-CgNZbRDp.js";import"./chunk-QU3B7NT4-Cw7PUtsg.js";import"./chunk-H3VCZNTA-BFf2tOHH.js";import{V as t,a as n,q as r,r as i}from"./chunk-MGPAVIPZ-BiIvV5Xa.js";import{F as a,P as o,Y as s,r as c}from"./chunk-5YUVU3PZ-BK7KuoPj.js";import"./chunk-XBXGYYE5-DKC57bIp.js";import{c as l}from"./chunk-2HR5LOFI-BF6gey_n.js";import"./chunk-BWNR3NKH-DWeyBdhh.js";import{t as u}from"./chunk-HN6EAY2L-C9xRd3g8.js";import"./chunk-35NHKZTR-Bjpr_jUT.js";import"./chunk-SRFB55UJ-Cq5faoiH.js";import"./chunk-TBF5ZNIQ-41MOcQHH.js";import"./chunk-RWUO3TPN-Dg6qtQ-i.js";import"./chunk-73ENG63I-BRlQ-GyX.js";import"./chunk-IWDTEBJL-CERtcYnn.js";import"./chunk-SEEX5HTF-D1Go1h8q.js";import"./chunk-HNL3EPQF-D1Jey-5G.js";import"./chunk-XEIFE4KY-BePa521_.js";import{t as d}from"./chunk-3YCYZ6SJ-DW3WSM8q.js";import{n as f,r as p,t as m}from"./chunk-3GS5O3IE-C2dpM7fk.js";var h=e(e=>e.append(`circle`).attr(`class`,`start-state`).attr(`r`,s().state.sizeUnit).attr(`cx`,s().state.padding+s().state.sizeUnit).attr(`cy`,s().state.padding+s().state.sizeUnit),`drawStartState`),g=e(e=>e.append(`line`).style(`stroke`,`grey`).style(`stroke-dasharray`,`3`).attr(`x1`,s().state.textHeight).attr(`class`,`divider`).attr(`x2`,s().state.textHeight*2).attr(`y1`,0).attr(`y2`,0),`drawDivider`),_=e((e,t)=>{let n=e.append(`text`).attr(`x`,2*s().state.padding).attr(`y`,s().state.textHeight+2*s().state.padding).attr(`font-size`,s().state.fontSize).attr(`class`,`state-title`).text(t.id),r=n.node().getBBox();return e.insert(`rect`,`:first-child`).attr(`x`,s().state.padding).attr(`y`,s().state.padding).attr(`width`,r.width+2*s().state.padding).attr(`height`,r.height+2*s().state.padding).attr(`rx`,s().state.radius),n},`drawSimpleState`),v=e((t,n)=>{let r=e(function(e,t,n){let r=e.append(`tspan`).attr(`x`,2*s().state.padding).text(t);n||r.attr(`dy`,s().state.textHeight)},`addTspan`),i=t.append(`text`).attr(`x`,2*s().state.padding).attr(`y`,s().state.textHeight+1.3*s().state.padding).attr(`font-size`,s().state.fontSize).attr(`class`,`state-title`).text(n.descriptions[0]).node().getBBox(),a=i.height,o=t.append(`text`).attr(`x`,s().state.padding).attr(`y`,a+s().state.padding*.4+s().state.dividerMargin+s().state.textHeight).attr(`class`,`state-description`),c=!0,l=!0;n.descriptions.forEach(function(e){c||(r(o,e,l),l=!1),c=!1});let u=t.append(`line`).attr(`x1`,s().state.padding).attr(`y1`,s().state.padding+a+s().state.dividerMargin/2).attr(`y2`,s().state.padding+a+s().state.dividerMargin/2).attr(`class`,`descr-divider`),d=o.node().getBBox(),f=Math.max(d.width,i.width);return u.attr(`x2`,f+3*s().state.padding),t.insert(`rect`,`:first-child`).attr(`x`,s().state.padding).attr(`y`,s().state.padding).attr(`width`,f+2*s().state.padding).attr(`height`,d.height+a+2*s().state.padding).attr(`rx`,s().state.radius),t},`drawDescrState`),y=e((e,t,n)=>{let r=s().state.padding,i=2*s().state.padding,a=e.node().getBBox(),o=a.width,c=a.x,l=e.append(`text`).attr(`x`,0).attr(`y`,s().state.titleShift).attr(`font-size`,s().state.fontSize).attr(`class`,`state-title`).text(t.id),u=l.node().getBBox().width+i,d=Math.max(u,o);d===o&&(d+=i);let f,p=e.node().getBBox();t.doc,f=c-r,u>o&&(f=(o-d)/2+r),Math.abs(c-p.x)<r&&u>o&&(f=c-(u-o)/2);let m=1-s().state.textHeight;return e.insert(`rect`,`:first-child`).attr(`x`,f).attr(`y`,m).attr(`class`,n?`alt-composit`:`composit`).attr(`width`,d).attr(`height`,p.height+s().state.textHeight+s().state.titleShift+1).attr(`rx`,`0`),l.attr(`x`,f+r),u<=o&&l.attr(`x`,c+(d-i)/2-u/2+r),e.insert(`rect`,`:first-child`).attr(`x`,f).attr(`y`,s().state.titleShift-s().state.textHeight-s().state.padding).attr(`width`,d).attr(`height`,s().state.textHeight*3).attr(`rx`,s().state.radius),e.insert(`rect`,`:first-child`).attr(`x`,f).attr(`y`,s().state.titleShift-s().state.textHeight-s().state.padding).attr(`width`,d).attr(`height`,p.height+3+2*s().state.textHeight).attr(`rx`,s().state.radius),e},`addTitleAndBox`),b=e(e=>(e.append(`circle`).attr(`class`,`end-state-outer`).attr(`r`,s().state.sizeUnit+s().state.miniPadding).attr(`cx`,s().state.padding+s().state.sizeUnit+s().state.miniPadding).attr(`cy`,s().state.padding+s().state.sizeUnit+s().state.miniPadding),e.append(`circle`).attr(`class`,`end-state-inner`).attr(`r`,s().state.sizeUnit).attr(`cx`,s().state.padding+s().state.sizeUnit+2).attr(`cy`,s().state.padding+s().state.sizeUnit+2)),`drawEndState`),x=e((e,t)=>{let n=s().state.forkWidth,r=s().state.forkHeight;if(t.parentId){let e=n;n=r,r=e}return e.append(`rect`).style(`stroke`,`black`).style(`fill`,`black`).attr(`width`,n).attr(`height`,r).attr(`x`,s().state.padding).attr(`y`,s().state.padding)},`drawForkJoinState`),S=e((e,t,n,r)=>{let i=0,a=r.append(`text`);a.style(`text-anchor`,`start`),a.attr(`class`,`noteText`);let o=e.replace(/\r\n/g,`<br/>`);o=o.replace(/\n/g,`<br/>`);let l=o.split(c.lineBreakRegex),u=1.25*s().state.noteMargin;for(let e of l){let r=e.trim();if(r.length>0){let e=a.append(`tspan`);if(e.text(r),u===0){let t=e.node().getBBox();u+=t.height}i+=u,e.attr(`x`,t+s().state.noteMargin),e.attr(`y`,n+i+1.25*s().state.noteMargin)}}return{textWidth:a.node().getBBox().width,textHeight:i}},`_drawLongText`),C=e((e,t)=>{t.attr(`class`,`state-note`);let n=t.append(`rect`).attr(`x`,0).attr(`y`,s().state.padding),{textWidth:r,textHeight:i}=S(e,0,0,t.append(`g`));return n.attr(`height`,i+2*s().state.noteMargin),n.attr(`width`,r+s().state.noteMargin*2),n},`drawNote`),w=e(function(e,t){let n=t.id,r={id:n,label:t.id,width:0,height:0},i=e.append(`g`).attr(`id`,n).attr(`class`,`stateGroup`);t.type===`start`&&h(i),t.type===`end`&&b(i),(t.type===`fork`||t.type===`join`)&&x(i,t),t.type===`note`&&C(t.note.text,i),t.type===`divider`&&g(i),t.type===`default`&&t.descriptions.length===0&&_(i,t),t.type===`default`&&t.descriptions.length>0&&v(i,t);let a=i.node().getBBox();return r.width=a.width+2*s().state.padding,r.height=a.height+2*s().state.padding,r},`drawState`),T=0,E=e(function(t,o,u){let d=e(function(e){switch(e){case f.relationType.AGGREGATION:return`aggregation`;case f.relationType.EXTENSION:return`extension`;case f.relationType.COMPOSITION:return`composition`;case f.relationType.DEPENDENCY:return`dependency`}},`getRelationType`);o.points=o.points.filter(e=>!Number.isNaN(e.y));let p=o.points,m=n().x(function(e){return e.x}).y(function(e){return e.y}).curve(i),h=t.append(`path`).attr(`d`,m(p)).attr(`id`,`edge`+T).attr(`class`,`transition`),g=``;if(s().state.arrowMarkerAbsolute&&(g=a(!0)),h.attr(`marker-end`,`url(`+g+`#`+d(f.relationType.DEPENDENCY)+`End)`),u.title!==void 0){let e=t.append(`g`).attr(`class`,`stateLabel`),{x:n,y:i}=l.calcLabelPosition(o.points),a=c.getRows(u.title),d=0,f=[],p=0,m=0;for(let t=0;t<=a.length;t++){let o=e.append(`text`).attr(`text-anchor`,`middle`).text(a[t]).attr(`x`,n).attr(`y`,i+d),s=o.node().getBBox();p=Math.max(p,s.width),m=Math.min(m,s.x),r.info(s.x,n,i+d),d===0&&(d=o.node().getBBox().height,r.info(`Title height`,d,i)),f.push(o)}let h=d*a.length;if(a.length>1){let e=(a.length-1)*d*.5;f.forEach((t,n)=>t.attr(`y`,i+n*d-e)),h=d*a.length}let g=e.node().getBBox();e.insert(`rect`,`:first-child`).attr(`class`,`box`).attr(`x`,n-p/2-s().state.padding/2).attr(`y`,i-h/2-s().state.padding/2-3.5).attr(`width`,p+s().state.padding).attr(`height`,h+s().state.padding),r.info(g)}T++},`drawEdge`),D,O={},k=e(function(){},`setConf`),A=e(function(e){e.append(`defs`).append(`marker`).attr(`id`,`dependencyEnd`).attr(`refX`,19).attr(`refY`,7).attr(`markerWidth`,20).attr(`markerHeight`,28).attr(`orient`,`auto`).append(`path`).attr(`d`,`M 19,7 L9,13 L14,7 L9,1 Z`)},`insertMarkers`),j=e(function(e,n,i,a){D=s().state;let c=s().securityLevel,l;c===`sandbox`&&(l=t(`#i`+n));let u=t(c===`sandbox`?l.nodes()[0].contentDocument.body:`body`),d=c===`sandbox`?l.nodes()[0].contentDocument:document;r.debug(`Rendering diagram `+e);let f=u.select(`[id='${n}']`);A(f),N(a.db.getRootDoc(),f.append(`g`).attr(`id`,n+`-root`),void 0,!1,u,d,a);let p=D.padding,m=f.node().getBBox(),h=m.width+p*2,g=m.height+p*2;o(f,g,h*1.75,D.useMaxWidth),f.attr(`viewBox`,`${m.x-D.padding} ${m.y-D.padding} `+h+` `+g)},`draw`),M=e(e=>e?e.length*D.fontSizeFactor:1,`getLabelWidth`),N=e((e,t,n,i,a,o,s)=>{let l=new u({compound:!0,multigraph:!0}),f,p=!0;for(f=0;f<e.length;f++)if(e[f].stmt===`relation`){p=!1;break}n?l.setGraph({rankdir:`LR`,multigraph:!0,compound:!0,ranker:`tight-tree`,ranksep:p?1:D.edgeLengthFactor,nodeSep:p?1:50,isMultiGraph:!0}):l.setGraph({rankdir:`TB`,multigraph:!0,compound:!0,ranksep:p?1:D.edgeLengthFactor,nodeSep:p?1:50,ranker:`tight-tree`,isMultiGraph:!0}),l.setDefaultEdgeLabel(function(){return{}});let m=s.db.getStates(),h=s.db.getRelations(),g=Object.keys(m);for(let e of g){let r=m[e];n&&(r.parentId=n);let c;if(r.doc){let e=t.append(`g`).attr(`id`,r.id).attr(`class`,`stateGroup`);if(c=N(r.doc,e,r.id,!i,a,o,s),!0){e=y(e,r,i);let t=e.node().getBBox();c.width=t.width,c.height=t.height+D.padding/2,O[r.id]={y:D.compositTitleSize}}}else c=w(t,r,l);if(r.note){let e=w(t,{descriptions:[],id:r.id+`-note`,note:r.note,type:`note`},l);r.note.position===`left of`?(l.setNode(c.id+`-note`,e),l.setNode(c.id,c)):(l.setNode(c.id,c),l.setNode(c.id+`-note`,e)),l.setParent(c.id,c.id+`-group`),l.setParent(c.id+`-note`,c.id+`-group`)}else l.setNode(c.id,c)}r.debug(`Count=`,l.nodeCount(),l);let _=0;h.forEach(function(e){_++,r.debug(`Setting edge`,e),l.setEdge(e.id1,e.id2,{relation:e,width:M(e.title),height:D.labelHeight*c.getRows(e.title).length,labelpos:`c`},`id`+_)}),d(l),r.debug(`Graph after layout`,l.nodes());let v=t.node();l.nodes().forEach(function(e){e!==void 0&&l.node(e)!==void 0?(r.warn(`Node `+e+`: `+JSON.stringify(l.node(e))),a.select(`#`+v.id+` #`+e).attr(`transform`,`translate(`+(l.node(e).x-l.node(e).width/2)+`,`+(l.node(e).y+(O[e]?O[e].y:0)-l.node(e).height/2)+` )`),a.select(`#`+v.id+` #`+e).attr(`data-x-shift`,l.node(e).x-l.node(e).width/2),o.querySelectorAll(`#`+v.id+` #`+e+` .divider`).forEach(e=>{let t=e.parentElement,n=0,r=0;t&&(t.parentElement&&(n=t.parentElement.getBBox().width),r=parseInt(t.getAttribute(`data-x-shift`),10),Number.isNaN(r)&&(r=0)),e.setAttribute(`x1`,0-r+8),e.setAttribute(`x2`,n-r-8)})):r.debug(`No Node `+e+`: `+JSON.stringify(l.node(e)))});let b=v.getBBox();l.edges().forEach(function(e){e!==void 0&&l.edge(e)!==void 0&&(r.debug(`Edge `+e.v+` -> `+e.w+`: `+JSON.stringify(l.edge(e))),E(t,l.edge(e),l.edge(e).relation))}),b=v.getBBox();let x={id:n||`root`,label:n||`root`,width:0,height:0};return x.width=b.width+2*D.padding,x.height=b.height+2*D.padding,r.debug(`Doc rendered`,x,l),x},`renderDoc`),P={parser:m,get db(){return new f(1)},renderer:{setConf:k,draw:j},styles:p,init:e(e=>{e.state||={},e.state.arrowMarkerAbsolute=e.arrowMarkerAbsolute},`init`)};export{P as diagram};