livebook/static/js/161.js

1 line
4.4 KiB
JavaScript
Raw Normal View History

2023-05-26 20:28:36 +08:00
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[161],{7161:(e,t,s)=>{s.d(t,{diagram:()=>N});var o=s(77415),a=s(45625),r=s(74309),i=s(31460),n=s(62335);s(93628),s(17967),s(27856),s(29451),s(69368);const d="rect",c="rectWithTitle",l="statediagram",p=`${l}-state`,b="transition",g=`${b} note-edge`,h=`${l}-note`,u=`${l}-cluster`,y=`${l}-cluster-alt`,f="parent",w="note",x="----",$=`${x}${w}`,m=`${x}${f}`,T="fill:none",S="fill: #333",k="text",D="normal";let A={},v=0;function B(e="",t=0,s="",o=x){return`state-${e}${null!==s&&s.length>0?`${o}${s}`:""}-${t}`}const E=(e,t,s,a,r,n)=>{const l=s.id,b=null==(x=a[l])?"":x.classes?x.classes.join(" "):"";var x;if("root"!==l){let t=d;!0===s.start&&(t="start"),!1===s.start&&(t="end"),s.type!==o.D&&(t=s.type),A[l]||(A[l]={id:l,shape:t,description:i.e.sanitizeText(l,(0,i.c)()),classes:`${b} ${p}`});const a=A[l];s.description&&(Array.isArray(a.description)?(a.shape=c,a.description.push(s.description)):a.description.length>0?(a.shape=c,a.description===l?a.description=[s.description]:a.description=[a.description,s.description]):(a.shape=d,a.description=s.description),a.description=i.e.sanitizeTextOrArray(a.description,(0,i.c)())),1===a.description.length&&a.shape===c&&(a.shape=d),!a.type&&s.doc&&(i.l.info("Setting cluster for ",l,R(s)),a.type="group",a.dir=R(s),a.shape=s.type===o.a?"divider":"roundedWithTitle",a.classes=a.classes+" "+u+" "+(n?y:""));const r={labelStyle:"",shape:a.shape,labelText:a.description,classes:a.classes,style:"",id:l,dir:a.dir,domId:B(l,v),type:a.type,padding:15,centerLabel:!0};if(s.note){const t={labelStyle:"",shape:"note",labelText:s.note.text,classes:h,style:"",id:l+$+"-"+v,domId:B(l,v,w),type:a.type,padding:15},o={labelStyle:"",shape:"noteGroup",labelText:s.note.text,classes:a.classes,style:"",id:l+m,domId:B(l,v,f),type:"group",padding:0};v++;const i=l+m;e.setNode(i,o),e.setNode(t.id,t),e.setNode(l,r),e.setParent(l,i),e.setParent(t.id,i);let n=l,d=t.id;"left of"===s.note.position&&(n=t.id,d=l),e.setEdge(n,d,{arrowhead:"none",arrowType:"",style:T,labelStyle:"",classes:g,arrowheadStyle:S,labelpos:"c",labelType:k,thickness:D})}else e.setNode(l,r)}t&&"root"!==t.id&&(i.l.trace("Setting node ",l," to be child of its parent ",t.id),e.setParent(l,t.id)),s.doc&&(i.l.trace("Adding nodes children "),C(e,s,s.doc,a,r,!n))},C=(e,t,s,a,r,n)=>{i.l.trace("items",s),s.forEach((s=>{switch(s.stmt){case o.b:case o.D:E(e,t,s,a,r,n);break;case o.S:{E(e,t,s.state1,a,r,n),E(e,t,s.state2,a,r,n);const o={id:"edge"+v,arrowhead:"normal",arrowTypeEnd:"arrow_barb",style:T,labelStyle:"",label:i.e.sanitizeText(s.description,(0,i.c)()),arrowheadStyle:S,labelpos:"c",labelType:k,thickness:D,classes:b};e.setEdge(s.state1.id,s.state2.id,o,v),v++}}}))},R=(e,t=o.c)=>{let s=t;if(e.doc)for(let t=0;t<e.doc.length;t++){const o=e.doc[t];"dir"===o.stmt&&(s=o.value)}return s},V={setConf:function(e){const t=Object.keys(e);for(const s of t)e[s]},getClasses:function(e,t){i.l.trace("Extracting classes"),t.db.clear();try{return t.parser.parse(e),t.db.extract(t.db.getRootDocV2()),t.db.getClasses()}catch(e){return e}},draw:async function(e,t,s,o){i.l.info("Drawing state diagram (v2)",t),A={},o.db.getDirection();const{securityLevel:c,state:p}=(0,i.c)(),b=p.nodeSpacing||50,g=p.rankSpacing||50;i.l.info(o.db.getRootDocV2()),o.db.extract(o.db.getRootDocV2()),i.l.info(o.db.getRootDocV2());const h=o.db.getStates(),u=new a.k({multigraph:!0,compound:!0}).setGraph({rankdir:R(o.db.getRootDocV2()),nodesep:b,ranksep:g,marginx:8,marginy:8}).setDefaultEdgeLabel((function(){return{}}));let y;E(u,void 0,o.db.getRootDocV2(),h,o.db,!0),"sandbox"===c&&(y=(0,r.Ys)("#i"+t));const f="sandbox"===c?(0,r.Ys)(y.nodes()[0].contentDocument.body):(0,r.Ys)("body"),w=f.select(`[id="${t}"]`),x=f.select("#"+t+" g");await(0,n.r)(x,u,["barb"],l,t),i.u.insertTitle(w,"statediagramTitleText",p.titleTopMargin,o.db.getDiagramTitle());const $=w.node().getBBox(),m=$.width+16,T=$.height+16;w.attr("class",l);const S=w.node().getBBox();(0,i.i)(w,T,m,p.useMaxWidth);const k=`${S.x-8} ${S.y-8} ${m} ${T}`;i.l.debug(`viewBox ${k}`),w.attr("viewBox",k);cons