2024-09-04 14:19:22 +08:00
import { _ as m , d as lt , g as _t , s as xt , b as vt , c as bt , q as wt , p as St , r as Lt , e as Et , o as At , j as H , O as Tt } from "./index-BtSBdRoK.js" ; import { o as Mt } from "./ordinal-Cboi1Yqb.js" ; import "./init-Gi6I4Gst.js" ; function Nt ( t ) { for ( var e = t . length / 6 | 0 , i = new Array ( e ) , a = 0 ; a < e ; ) i [ a ] = "#" + t . slice ( a * 6 , ++ a * 6 ) ; return i } const It = Nt ( "4e79a7f28e2ce1575976b7b259a14fedc949af7aa1ff9da79c755fbab0ab" ) ; function ct ( t , e ) { let i ; if ( e === void 0 ) for ( const a of t ) a != null && ( i < a || i === void 0 && a >= a ) && ( i = a ) ; else { let a = - 1 ; for ( let h of t ) ( h = e ( h , ++ a , t ) ) != null && ( i < h || i === void 0 && h >= h ) && ( i = h ) } return i } function pt ( t , e ) { let i ; if ( e === void 0 ) for ( const a of t ) a != null && ( i > a || i === void 0 && a >= a ) && ( i = a ) ; else { let a = - 1 ; for ( let h of t ) ( h = e ( h , ++ a , t ) ) != null && ( i > h || i === void 0 && h >= h ) && ( i = h ) } return i } function nt ( t , e ) { let i = 0 ; if ( e === void 0 ) for ( let a of t ) ( a = + a ) && ( i += a ) ; else { let a = - 1 ; for ( let h of t ) ( h = + e ( h , ++ a , t ) ) && ( i += h ) } return i } function Pt ( t ) { return t . target . depth } function Ct ( t ) { return t . depth } function Ot ( t , e ) { return e - 1 - t . height } function mt ( t , e ) { return t . sourceLinks . length ? t . depth : e - 1 } function Dt ( t ) { return t . targetLinks . length ? t . depth : t . sourceLinks . length ? pt ( t . sourceLinks , Pt ) - 1 : 0 } function X ( t ) { return function ( ) { return t } } function ut ( t , e ) { return Q ( t . source , e . source ) || t . index - e . index } function ht ( t , e ) { return Q ( t . target , e . target ) || t . index - e . index } function Q ( t , e ) { return t . y0 - e . y0 } function it ( t ) { return t . value } function jt ( t ) { return t . index } function zt ( t ) { return t . nodes } function $t ( t ) { return t . links } function ft ( t , e ) { const i = t . get ( e ) ; if ( ! i ) throw new Error ( "missing: " + e ) ; return i } function yt ( { nodes : t } ) { for ( const e of t ) { let i = e . y0 , a = i ; for ( const h of e . sourceLinks ) h . y0 = i + h . width / 2 , i += h . width ; for ( const h of e . targetLinks ) h . y1 = a + h . width / 2 , a += h . width } } function Bt ( ) { let t = 0 , e = 0 , i = 1 , a = 1 , h = 24 , d = 8 , p , _ = jt , s = mt , o , l , x = zt , v = $t , y = 6 ; function b ( ) { const n = { nodes : x . apply ( null , arguments ) , links : v . apply ( null , arguments ) } ; return M ( n ) , T ( n ) , N ( n ) , C ( n ) , S ( n ) , yt ( n ) , n } b . update = function ( n ) { return yt ( n ) , n } , b . nodeId = function ( n ) { return arguments . length ? ( _ = typeof n == "function" ? n : X ( n ) , b ) : _ } , b . nodeAlign = function ( n ) { return arguments . length ? ( s = typeof n == "function" ? n : X ( n ) , b ) : s } , b . nodeSort = function ( n ) { return arguments . length ? ( o = n , b ) : o } , b . nodeWidth = function ( n ) { return arguments . length ? ( h = + n , b ) : h } , b . nodePadding = function ( n ) { return arguments . length ? ( d = p = + n , b ) : d } , b . nodes = function ( n ) { return arguments . length ? ( x = typeof n == "function" ? n : X ( n ) , b ) : x } , b . links = function ( n ) { return arguments . length ? ( v = typeof n == "function" ? n : X ( n ) , b ) : v } , b . linkSort = function ( n ) { return arguments . length ? ( l = n , b ) : l } , b . size = function ( n ) { return arguments . length ? ( t = e = 0 , i = + n [ 0 ] , a = + n [ 1 ] , b ) : [ i - t , a - e ] } , b . extent = function ( n ) { return arguments . length ? ( t = + n [ 0 ] [ 0 ] , i = + n [ 1 ] [ 0 ] , e = + n [ 0 ] [ 1 ] , a = + n [ 1 ] [ 1 ] , b ) : [ [ t , e ] , [ i , a ] ] } , b . iterations = function ( n ) { return arguments . length ? ( y = + n , b ) : y } ; function M ( { nodes : n , links : f } ) { for ( const [ c , r ] of n . entries ( ) ) r . index = c , r . sourceLinks = [ ] , r . targetLinks = [ ] ; const u = new Map ( n . map ( ( c , r ) => [ _ ( c , r , n ) , c ] ) ) ; for ( const [ c , r ] of f . entries ( ) ) { r . index = c ; let { source : k , target : w } = r ; typeof k != "object" && ( k = r . source = ft ( u , k ) ) , typeof w != "object" && ( w = r . target = ft ( u , w ) ) , k . sourceLinks . push ( r ) , w . targetLinks . push ( r ) } if ( l != null ) for ( const { sourceLinks : c , targetLinks : r } of n ) c . sort ( l ) , r . sort ( l ) } function T ( { nodes : n } ) { for ( const f of n ) f . value = f . fixedValue === void 0 ? Math . max ( nt ( f . sourceLinks , it ) , nt ( f . targetLinks , it ) ) : f . fixedValue } function N ( { nodes : n } ) { const f = n . length ; let u = new Set ( n ) , c = new Set , r = 0 ; for ( ; u . size ; ) { for ( const k of u ) { k . depth = r ; for ( const { target : w } of k . sourceLinks ) c . add ( w ) } if ( ++ r > f ) throw new Error ( "circular link" ) ; u = c , c = new Set } } function C ( { nodes : n } ) { const f = n . length ; let u = new Set ( n ) , c = new Set , r = 0 ; for ( ; u . size ; ) { for ( const k of u ) { k . height = r ; for ( const { source : w } of k . targetLinks ) c . add ( w ) } if ( ++ r > f ) throw new Error ( "circular link" ) ; u = c , c = new Set } } function j ( { nodes : n } ) { const f = ct ( n , r => r . depth ) + 1 , u = ( i - t - h ) / ( f - 1 ) , c = new Array ( f ) ; for ( const r of n ) { const k = Math . max ( 0 , Math . min ( f - 1 , Math . floor ( s . call ( null , r , f ) ) ) ) ; r . layer = k , r . x0 = t + k * u , r . x1 = r . x0 + h , c [ k ] ? c [ k ] . push ( r ) : c [ k ] = [ r ] } if ( o ) for ( const r of c ) r . sort ( o ) ; return c } function R ( n ) { const f = pt ( n , u => ( a - e - ( u . length - 1 ) * p ) / nt ( u , it ) ) ; for ( const u of n ) { let c = e ; for ( const r
2024-08-27 22:31:52 +08:00
` +S.showPosition()+ `
Expecting ` +k.join(", ")+", got '"+(this.terminals_[A]||A)+"'":w="Parse error on line "+(T+1)+": Unexpected "+(A==j?"end of input":"'"+(this.terminals_[A]||A)+"'"),this.parseError(w,{text:S.match,token:this.terminals_[A]||A,line:S.yylineno,loc:O,expected:k})}if(I[0]instanceof Array&&I.length>1)throw new Error("Parse Error: multiple actions possible at state: "+z+", token: "+A);switch(I[0]){case 1:l.push(A),v.push(S.yytext),y.push(S.yylloc),l.push(I[1]),A=null,N=S.yyleng,M=S.yytext,T=S.yylineno,O=S.yylloc;break;case 2:if(c=this.productions_[I[1]][1],f. $ =v[v.length-c],f._ $ ={first_line:y[y.length-(c||1)].first_line,last_line:y[y.length-1].last_line,first_column:y[y.length-(c||1)].first_column,last_column:y[y.length-1].last_column},D&&(f._ $ .range=[y[y.length-(c||1)].range[0],y[y.length-1].range[1]]),n=this.performAction.apply(f,[M,N,T,P.yy,I[1],v,y].concat(R)),typeof n<"u")return n;c&&(l=l.slice(0,-1*c*2),v=v.slice(0,-1*c),y=y.slice(0,-1*c)),l.push(this.productions_[I[1]][0]),v.push(f. $ ),y.push(f._ $ ),r=b[l[l.length-2]][l[l.length-1]],l.push(r);break;case 3:return!0}}return!0},"parse")},d=function(){var _={EOF:1,parseError:m(function(o,l){if(this.yy.parser)this.yy.parser.parseError(o,l);else throw new Error(o)},"parseError"),setInput:m(function(s,o){return this.yy=o||this.yy||{},this._input=s,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},"setInput"),input:m(function(){var s=this._input[0];this.yytext+=s,this.yyleng++,this.offset++,this.match+=s,this.matched+=s;var o=s.match(/(?: \r \n ?| \n ).*/g);return o?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),s},"input"),unput:m(function(s){var o=s.length,l=s.split(/(?: \r \n ?| \n )/g);this._input=s+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-o),this.offset-=o;var x=this.match.split(/(?: \r \n ?| \n )/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),l.length-1&&(this.yylineno-=l.length-1);var v=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:l?(l.length===x.length?this.yylloc.first_column:0)+x[x.length-l.length].length-l[0].length:this.yylloc.first_column-o},this.options.ranges&&(this.yylloc.range=[v[0],v[0]+this.yyleng-o]),this.yyleng=this.yytext.length,this},"unput"),more:m(function(){return this._more=!0,this},"more"),reject:m(function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+ ` . You can only invoke reject ( ) in the lexer when the lexer is of the backtracking persuasion ( options . backtrack _lexer = true ) .
` +this.showPosition(),{text:"",token:null,line:this.yylineno});return this},"reject"),less:m(function(s){this.unput(this.match.slice(s))},"less"),pastInput:m(function(){var s=this.matched.substr(0,this.matched.length-this.match.length);return(s.length>20?"...":"")+s.substr(-20).replace(/ \n /g,"")},"pastInput"),upcomingInput:m(function(){var s=this.match;return s.length<20&&(s+=this._input.substr(0,20-s.length)),(s.substr(0,20)+(s.length>20?"...":"")).replace(/ \n /g,"")},"upcomingInput"),showPosition:m(function(){var s=this.pastInput(),o=new Array(s.length+1).join("-");return s+this.upcomingInput()+ `
` +o+"^"},"showPosition"),test_match:m(function(s,o){var l,x,v;if(this.options.backtrack_lexer&&(v={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(v.yylloc.range=this.yylloc.range.slice(0))),x=s[0].match(/(?: \r \n ?| \n ).*/g),x&&(this.yylineno+=x.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:x?x[x.length-1].length-x[x.length-1].match(/ \r ? \n ?/)[0].length:this.yylloc.last_column+s[0].length},this.yytext+=s[0],this.match+=s[0],this.matches=s,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(s[0].length),this.matched+=s[0],l=this.performAction.call(this,this.yy,this,o,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),l)return l;if(this._backtrack){for(var y in v)this[y]=v[y];return!1}return!1},"test_match"),next:m(function(){if(this.done)return this.EOF;this._input||(this.done=!0);var s,o,l,x;this._more||(this.yytext="",this.match="");for(var v=this._currentRules(),y=0;y<v.length;y++)if(l=this._input.match(this.rules[v[y]]),l&&(!o||l[0].length>o[0].length)){if(o=l,x=y,this.options.backtrack_lexer){if(s=this.test_match(l,v[y]),s!==!1)return s;if(this._backtrack){o=!1;continue}else return!1}else if(!this.options.flex)break}return o?(s=this.test_match(o,v[x]),s!==!1?s:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+ ` . Unrecognized text .
` +this.showPosition(),{text:"",token:null,line:this.yylineno})},"next"),lex:m(function(){var o=this.next();return o||this.lex()},"lex"),begin:m(function(o){this.conditionStack.push(o)},"begin"),popState:m(function(){var o=this.conditionStack.length-1;return o>0?this.conditionStack.pop():this.conditionStack[0]},"popState"),_currentRules:m(function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},"_currentRules"),topState:m(function(o){return o=this.conditionStack.length-1-Math.abs(o||0),o>=0?this.conditionStack[o]:"INITIAL"},"topState"),pushState:m(function(o){this.begin(o)},"pushState"),stateStackSize:m(function(){return this.conditionStack.length},"stateStackSize"),options:{"case-insensitive":!0},performAction:m(function(o,l,x,v){switch(x){case 0:return this.pushState("csv"),4;case 1:return 10;case 2:return 5;case 3:return 12;case 4:return this.pushState("escaped_text"),18;case 5:return 20;case 6:return this.popState("escaped_text"),18;case 7:return 19}},"anonymous"),rules:[/^(?:sankey-beta \b )/i,/^(?: $ )/i,/^(?:(( \u 000D \u 000A)|( \u 000A)))/i,/^(?:( \u 002C))/i,/^(?:( \u 0022))/i,/^(?:([ \u 0020- \u 0021 \u 0023- \u 002B \u 002D- \u 007E])*)/i,/^(?:( \u 0022)(?!( \u 0022)))/i,/^(?:(([ \u 0020- \u 0021 \u 0023- \u 002B \u 002D- \u 007E])|( \u 002C)|( \u 000D)|( \u 000A)|( \u 0022)( \u 0022))*)/i],conditions:{csv:{rules:[1,2,3,4,5,6,7],inclusive:!1},escaped_text:{rules:[6,7],inclusive:!1},INITIAL:{rules:[0,1,2,3,4,5,6,7],inclusive:!0}}};return _}();h.lexer=d;function p(){this.yy={}}return m(p,"Parser"),p.prototype=h,h.Parser=p,new p}();at.parser=at;var K=at,J=[],tt=[],Z=new Map,Zt=m(()=>{J=[],tt=[],Z=new Map,Lt()},"clear"),W,Jt=(W=class{constructor(e,i,a=0){this.source=e,this.target=i,this.value=a}},m(W,"SankeyLink"),W),te=m((t,e,i)=>{J.push(new Jt(t,e,i))},"addLink"),U,ee=(U=class{constructor(e){this.ID=e}},m(U,"SankeyNode"),U),ne=m(t=>{t=Et.sanitizeText(t,lt());let e=Z.get(t);return e===void 0&&(e=new ee(t),Z.set(t,e),tt.push(e)),e},"findOrCreateNode"),ie=m(()=>tt,"getNodes"),se=m(()=>J,"getLinks"),re=m(()=>({nodes:tt.map(t=>({id:t.ID})),links:J.map(t=>({source:t.source.ID,target:t.target.ID,value:t.value}))}),"getGraph"),oe={nodesMap:Z,getConfig:m(()=>lt().sankey,"getConfig"),getNodes:ie,getLinks:se,getGraph:re,addLink:te,findOrCreateNode:ne,getAccTitle:_t,setAccTitle:xt,getAccDescription:vt,setAccDescription:bt,getDiagramTitle:wt,setDiagramTitle:St,clear:Zt}, $ ,gt=( $ =class{static next(e){return new $ (e+ ++ $ .count)}constructor(e){this.id=e,this.href= ` # $ { e } ` }toString(){return"url("+this.href+")"}},m( $ ,"Uid"), $ .count=0, $ ),ae={left:Ct,right:Ot,center:Dt,justify:mt},le=m(function(t,e,i,a){const{securityLevel:h,sankey:d}=lt(),p=At.sankey;let _;h==="sandbox"&&(_=H("#i"+e));const s=h==="sandbox"?H(_.nodes()[0].contentDocument.body):H("body"),o=h==="sandbox"?s.select( ` [ id = "${e}" ] ` ):H( ` [ id = "${e}" ] ` ),l=(d==null?void 0:d.width)??p.width,x=(d==null?void 0:d.height)??p.width,v=(d==null?void 0:d.useMaxWidth)??p.useMaxWidth,y=(d==null?void 0:d.nodeAlignment)??p.nodeAlignment,b=(d==null?void 0:d.prefix)??p.prefix,M=(d==null?void 0:d.suffix)??p.suffix,T=(d==null?void 0:d.showValues)??p.showValues,N=a.db.getGraph(),C=ae[y];Bt().nodeId(g=>g.id).nodeWidth(10).nodePadding(10+(T?15:0)).nodeAlign(C).extent([[0,0],[l,x]])(N);const S=Mt(It);o.append("g").attr("class","nodes").selectAll(".node").data(N.nodes).join("g").attr("class","node").attr("id",g=>(g.uid=gt.next("node-")).id).attr("transform",function(g){return"translate("+g.x0+","+g.y0+")"}).attr("x",g=>g.x0).attr("y",g=>g.y0).append("rect").attr("height",g=>g.y1-g.y0).attr("width",g=>g.x1-g.x0).attr("fill",g=>S(g.id));const P=m(({id:g,value:E})=>T? ` $ { g }
$ { b } $ { Math . round ( E * 100 ) / 100 } $ { M } ` :g,"getText");o.append("g").attr("class","node-labels").attr("font-family","sans-serif").attr("font-size",14).selectAll("text").data(N.nodes).join("text").attr("x",g=>g.x0<l/2?g.x1+6:g.x0-6).attr("y",g=>(g.y1+g.y0)/2).attr("dy", ` $ { T ? "0" : "0.35" } em ` ).attr("text-anchor",g=>g.x0<l/2?"start":"end").text(P);const B=o.append("g").attr("class","links").attr("fill","none").attr("stroke-opacity",.5).selectAll(".link").data(N.links).join("g").attr("class","link").style("mix-blend-mode","multiply"),O=(d==null?void 0:d.linkColor)??"gradient";if(O==="gradient"){const g=B.append("linearGradient").attr("id",E=>(E.uid=gt.next("linearGradient-")).id).attr("gradientUnits","userSpaceOnUse").attr("x1",E=>E.source.x1).attr("x2",E=>E.target.x0);g.append("stop").attr("offset","0%").attr("stop-color",E=>S(E.source.id)),g.append("stop").attr("offset","100%").attr("stop-color",E=>S(E.target.id))}let D;switch(O){case"gradient":D=m(g=>g.uid,"coloring");break;case"source":D=m(g=>S(g.source.id),"coloring");break;case"target":D=m(g=>S(g.target.id),"coloring");break;default:D=O}B.append("path").attr("d",Kt()).attr("stroke",D).attr("stroke-width",g=>Math.max(1,g.width)),Tt(void 0,o,0,v)},"draw"),ce={draw:le},ue=m(t=>t.replaceAll(/^[^ \S \n \r ]+|[^ \S \n \r ]+ $ /g,"").replaceAll(/([ \n \r ])+/g, `
` ).trim(),"prepareTextForParsing"),he=K.parse.bind(K);K.parse=t=>he(ue(t));var ge={parser:K,db:oe,renderer:ce};export{ge as diagram};