2024-01-24 23:02:24 +08:00
import { $a as J , C as bt , I as Ft , Ka as St , Za as wt , b as Vt , bb as Lt , c as Wt , db as At , eb as Et , fb as Tt , gb as Ct , h as X , hb as Mt , ib as Ot , jb as It , l as vt } from "./chunk-KR7JTV7U.js" ; import { h as ot } from "./chunk-3V74GZ4F.js" ; function G ( t , r ) { let s ; if ( r === void 0 ) for ( let u of t ) u != null && ( s < u || s === void 0 && u >= u ) && ( s = u ) ; else { let u = - 1 ; for ( let c of t ) ( c = r ( c , ++ u , t ) ) != null && ( s < c || s === void 0 && c >= c ) && ( s = c ) } return s } function B ( t , r ) { let s ; if ( r === void 0 ) for ( let u of t ) u != null && ( s > u || s === void 0 && u >= u ) && ( s = u ) ; else { let u = - 1 ; for ( let c of t ) ( c = r ( c , ++ u , t ) ) != null && ( s > c || s === void 0 && c >= c ) && ( s = c ) } return s } function V ( t , r ) { let s = 0 ; if ( r === void 0 ) for ( let u of t ) ( u = + u ) && ( s += u ) ; else { let u = - 1 ; for ( let c of t ) ( c = + r ( c , ++ u , t ) ) && ( s += c ) } return s } function qt ( t ) { return t . target . depth } function st ( t ) { return t . depth } function it ( t , r ) { return r - 1 - t . height } function Q ( t , r ) { return t . sourceLinks . length ? t . depth : r - 1 } function at ( t ) { return t . targetLinks . length ? t . depth : t . sourceLinks . length ? B ( t . sourceLinks , qt ) - 1 : 0 } function W ( t ) { return function ( ) { return t } } function Nt ( t , r ) { return K ( t . source , r . source ) || t . index - r . index } function Pt ( t , r ) { return K ( t . target , r . target ) || t . index - r . index } function K ( t , r ) { return t . y0 - r . y0 } function lt ( t ) { return t . value } function Ut ( t ) { return t . index } function Yt ( t ) { return t . nodes } function Ht ( t ) { return t . links } function zt ( t , r ) { let s = t . get ( r ) ; if ( ! s ) throw new Error ( "missing: " + r ) ; return s } function Rt ( { nodes : t } ) { for ( let r of t ) { let s = r . y0 , u = s ; for ( let c of r . sourceLinks ) c . y0 = s + c . width / 2 , s += c . width ; for ( let c of r . targetLinks ) c . y1 = u + c . width / 2 , u += c . width } } function Z ( ) { let t = 0 , r = 0 , s = 1 , u = 1 , c = 24 , x = 8 , p , m = Ut , o = Q , a , f , y = Yt , v = Ht , d = 6 ; function k ( ) { let n = { nodes : y . apply ( null , arguments ) , links : v . apply ( null , arguments ) } ; return A ( n ) , L ( n ) , E ( n ) , M ( n ) , b ( n ) , Rt ( n ) , n } k . update = function ( n ) { return Rt ( n ) , n } , k . nodeId = function ( n ) { return arguments . length ? ( m = typeof n == "function" ? n : W ( n ) , k ) : m } , k . nodeAlign = function ( n ) { return arguments . length ? ( o = typeof n == "function" ? n : W ( n ) , k ) : o } , k . nodeSort = function ( n ) { return arguments . length ? ( a = n , k ) : a } , k . nodeWidth = function ( n ) { return arguments . length ? ( c = + n , k ) : c } , k . nodePadding = function ( n ) { return arguments . length ? ( x = p = + n , k ) : x } , k . nodes = function ( n ) { return arguments . length ? ( y = typeof n == "function" ? n : W ( n ) , k ) : y } , k . links = function ( n ) { return arguments . length ? ( v = typeof n == "function" ? n : W ( n ) , k ) : v } , k . linkSort = function ( n ) { return arguments . length ? ( f = n , k ) : f } , k . size = function ( n ) { return arguments . length ? ( t = r = 0 , s = + n [ 0 ] , u = + n [ 1 ] , k ) : [ s - t , u - r ] } , k . extent = function ( n ) { return arguments . length ? ( t = + n [ 0 ] [ 0 ] , s = + n [ 1 ] [ 0 ] , r = + n [ 0 ] [ 1 ] , u = + n [ 1 ] [ 1 ] , k ) : [ [ t , r ] , [ s , u ] ] } , k . iterations = function ( n ) { return arguments . length ? ( d = + n , k ) : d } ; function A ( { nodes : n , links : h } ) { for ( let [ l , i ] of n . entries ( ) ) i . index = l , i . sourceLinks = [ ] , i . targetLinks = [ ] ; let e = new Map ( n . map ( ( l , i ) => [ m ( l , i , n ) , l ] ) ) ; for ( let [ l , i ] of h . entries ( ) ) { i . index = l ; let { source : g , target : _ } = i ; typeof g != "object" && ( g = i . source = zt ( e , g ) ) , typeof _ != "object" && ( _ = i . target = zt ( e , _ ) ) , g . sourceLinks . push ( i ) , _ . targetLinks . push ( i ) } if ( f != null ) for ( let { sourceLinks : l , targetLinks : i } of n ) l . sort ( f ) , i . sort ( f ) } function L ( { nodes : n } ) { for ( let h of n ) h . value = h . fixedValue === void 0 ? Math . max ( V ( h . sourceLinks , lt ) , V ( h . targetLinks , lt ) ) : h . fixedValue } function E ( { nodes : n } ) { let h = n . length , e = new Set ( n ) , l = new Set , i = 0 ; for ( ; e . size ; ) { for ( let g of e ) { g . depth = i ; for ( let { target : _ } of g . sourceLinks ) l . add ( _ ) } if ( ++ i > h ) throw new Error ( "circular link" ) ; e = l , l = new Set } } function M ( { nodes : n } ) { let h = n . length , e = new Set ( n ) , l = new Set , i = 0 ; for ( ; e . size ; ) { for ( let g of e ) { g . height = i ; for ( let { source : _ } of g . targetLinks ) l . add ( _ ) } if ( ++ i > h ) throw new Error ( "circular link" ) ; e = l , l = new Set } } function O ( { nodes : n } ) { let h = G ( n , i => i . depth ) + 1 , e = ( s - t - c ) / ( h - 1 ) , l = new Array ( h ) ; for ( let i of n ) { let g = Math . max ( 0 , Math . min ( h - 1 , Math . floor ( o . call ( null , i , h ) ) ) ) ; i . layer = g , i . x0 = t + g * e , i . x1 = i . x0 + c , l [ g ] ? l [ g ] . push ( i ) : l [ g ] = [ i ] } if ( a ) for ( let i of l ) i . sort ( a ) ; return l } function R ( n ) { let h = B ( n , e => ( u - r - ( e . length - 1 ) * p ) / V ( e , lt ) ) ; for ( let e of n ) { let l = r ; for ( let i of e ) { i . y0 = l , i . y1 = l + i . value * h , l = i . y1 + p ; for ( let g of i . sourceLinks ) g . width = g . value * h } l = ( u - l + p ) / ( e . length + 1 ) ; for ( let i = 0 ; i < e . length ; ++ i ) { let g = e [ i ] ; g . y0 += l * ( i + 1 ) , g . y1 += l * ( i + 1 ) } T ( e ) } } function b ( n ) { let h = O ( n ) ; p = Math . min ( x , ( u - r ) / ( G ( h , e
2023-10-06 00:34:57 +08:00
` +b.showPosition()+ `
Expecting ` +i.join(", ")+", got '"+(this.terminals_[S]||S)+"'":g="Parse error on line "+(L+1)+": Unexpected "+(S==O?"end of input":"'"+(this.terminals_[S]||S)+"'"),this.parseError(g,{text:b.match,token:this.terminals_[S]||S,line:b.yylineno,loc:I,expected:i})}if(w[0]instanceof Array&&w.length>1)throw new Error("Parse Error: multiple actions possible at state: "+T+", token: "+S);switch(w[0]){case 1:f.push(S),v.push(b.yytext),d.push(b.yylloc),f.push(w[1]),S=null,E=b.yyleng,A=b.yytext,L=b.yylineno,I=b.yylloc;break;case 2:if(e=this.productions_[w[1]][1],n. $ =v[v.length-e],n._ $ ={first_line:d[d.length-(e||1)].first_line,last_line:d[d.length-1].last_line,first_column:d[d.length-(e||1)].first_column,last_column:d[d.length-1].last_column},N&&(n._ $ .range=[d[d.length-(e||1)].range[0],d[d.length-1].range[1]]),z=this.performAction.apply(n,[A,E,L,C.yy,w[1],v,d].concat(R)),typeof z!="undefined")return z;e&&(f=f.slice(0,-1*e*2),v=v.slice(0,-1*e),d=d.slice(0,-1*e)),f.push(this.productions_[w[1]][0]),v.push(n. $ ),d.push(n._ $ ),l=k[f[f.length-2]][f[f.length-1]],f.push(l);break;case 3:return!0}}return!0}},x=function(){var m={EOF:1,parseError:function(a,f){if(this.yy.parser)this.yy.parser.parseError(a,f);else throw new Error(a)},setInput:function(o,a){return this.yy=a||this.yy||{},this._input=o,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},input:function(){var o=this._input[0];this.yytext+=o,this.yyleng++,this.offset++,this.match+=o,this.matched+=o;var a=o.match(/(?: \r \n ?| \n ).*/g);return a?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),o},unput:function(o){var a=o.length,f=o.split(/(?: \r \n ?| \n )/g);this._input=o+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-a),this.offset-=a;var y=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),f.length-1&&(this.yylineno-=f.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:f?(f.length===y.length?this.yylloc.first_column:0)+y[y.length-f.length].length-f[0].length:this.yylloc.first_column-a},this.options.ranges&&(this.yylloc.range=[v[0],v[0]+this.yyleng-a]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject: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},less:function(o){this.unput(this.match.slice(o))},pastInput:function(){var o=this.matched.substr(0,this.matched.length-this.match.length);return(o.length>20?"...":"")+o.substr(-20).replace(/ \n /g,"")},upcomingInput:function(){var o=this.match;return o.length<20&&(o+=this._input.substr(0,20-o.length)),(o.substr(0,20)+(o.length>20?"...":"")).replace(/ \n /g,"")},showPosition:function(){var o=this.pastInput(),a=new Array(o.length+1).join("-");return o+this.upcomingInput()+ `
` +a+"^"},test_match:function(o,a){var f,y,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))),y=o[0].match(/(?: \r \n ?| \n ).*/g),y&&(this.yylineno+=y.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:y?y[y.length-1].length-y[y.length-1].match(/ \r ? \n ?/)[0].length:this.yylloc.last_column+o[0].length},this.yytext+=o[0],this.match+=o[0],this.matches=o,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(o[0].length),this.matched+=o[0],f=this.performAction.call(this,this.yy,this,a,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),f)return f;if(this._backtrack){for(var d in v)this[d]=v[d];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var o,a,f,y;this._more||(this.yytext="",this.match="");for(var v=this._currentRules(),d=0;d<v.length;d++)if(f=this._input.match(this.rules[v[d]]),f&&(!a||f[0].length>a[0].length)){if(a=f,y=d,this.options.backtrack_lexer){if(o=this.test_match(f,v[d]),o!==!1)return o;if(this._backtrack){a=!1;continue}else return!1}else if(!this.options.flex)break}return a?(o=this.test_match(a,v[y]),o!==!1?o:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+ ` . Unrecognized text .
` +this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a||this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{easy_keword_rules:!0},performAction:function(a,f,y,v){switch(y){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}},rules:[/^(?:sankey-beta \b )/,/^(?: $ )/,/^(?:(( \u 000D \u 000A)|( \u 000A)))/,/^(?:( \u 002C))/,/^(?:( \u 0022))/,/^(?:([ \u 0020- \u 0021 \u 0023- \u 002B \u 002D- \u 007E])*)/,/^(?:( \u 0022)(?!( \u 0022)))/,/^(?:(([ \u 0020- \u 0021 \u 0023- \u 002B \u 002D- \u 007E])|( \u 002C)|( \u 000D)|( \u 000A)|( \u 0022)( \u 0022))*)/],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 m}();c.lexer=x;function p(){this.yy={}}return p.prototype=c,c.Parser=p,new p}();mt.parser=mt;var tt=mt,et=[],nt=[],F={},ee=()=>{et=[],nt=[],F={},At()},gt=class{constructor(r,s,u=0){this.source=r,this.target=s,this.value=u}},ne=(t,r,s)=>{et.push(new gt(t,r,s))},xt=class{constructor(r){this.ID=r}},re=t=>(t=St.sanitizeText(t,J()),F[t]||(F[t]=new xt(t),nt.push(F[t])),F[t]),oe=()=>nt,se=()=>et,ie=()=>({nodes:nt.map(t=>({id:t.ID})),links:et.map(t=>({source:t.source.ID,target:t.target.ID,value:t.value}))}),ae={nodesMap:F,getConfig:()=>J().sankey,getNodes:oe,getLinks:se,getGraph:ie,addLink:ne,findOrCreateNode:re,getAccTitle:Tt,setAccTitle:Et,getAccDescription:Mt,setAccDescription:Ct,getDiagramTitle:It,setDiagramTitle:Ot,clear:ee},kt=class{static next(t){return new kt(t+ ++kt.count)}constructor(t){this.id=t,this.href= ` # $ { t } ` }toString(){return"url("+this.href+")"}},_t=kt;_t.count=0;var le={left:st,right:it,center:at,justify:Q},ue=function(t,r,s,u){var D,S,T,w,z,n,h;let{securityLevel:c,sankey:x}=J(),p=wt.sankey,m;c==="sandbox"&&(m=X("#i"+r));let o=c==="sandbox"?X(m.nodes()[0].contentDocument.body):X("body"),a=c==="sandbox"?o.select( ` [ id = "${r}" ] ` ):X( ` [ id = "${r}" ] ` ),f=(D=x==null?void 0:x.width)!=null?D:p.width,y=(S=x==null?void 0:x.height)!=null?S:p.width,v=(T=x==null?void 0:x.useMaxWidth)!=null?T:p.useMaxWidth,d=(w=x==null?void 0:x.nodeAlignment)!=null?w:p.nodeAlignment,k=(z=x==null?void 0:x.prefix)!=null?z:p.prefix,A=(n=x==null?void 0:x.suffix)!=null?n:p.suffix,L=(h=x==null?void 0:x.showValues)!=null?h:p.showValues;Lt(a,y,f,v);let E=u.db.getGraph(),M=le[d],O=10;Z().nodeId(e=>e.id).nodeWidth(O).nodePadding(10+(L?15:0)).nodeAlign(M).extent([[0,0],[f,y]])(E);let b=vt(bt);a.append("g").attr("class","nodes").selectAll(".node").data(E.nodes).join("g").attr("class","node").attr("id",e=>(e.uid=_t.next("node-")).id).attr("transform",function(e){return"translate("+e.x0+","+e.y0+")"}).attr("x",e=>e.x0).attr("y",e=>e.y0).append("rect").attr("height",e=>e.y1-e.y0).attr("width",e=>e.x1-e.x0).attr("fill",e=>b(e.id));let C=({id:e,value:l})=>L? ` $ { e }
$ { k } $ { Math . round ( l * 100 ) / 100 } $ { A } ` :e;a.append("g").attr("class","node-labels").attr("font-family","sans-serif").attr("font-size",14).selectAll("text").data(E.nodes).join("text").attr("x",e=>e.x0<f/2?e.x1+6:e.x0-6).attr("y",e=>(e.y1+e.y0)/2).attr("dy", ` $ { L ? "0" : "0.35" } em ` ).attr("text-anchor",e=>e.x0<f/2?"start":"end").text(C);let P=a.append("g").attr("class","links").attr("fill","none").attr("stroke-opacity",.5).selectAll(".link").data(E.links).join("g").attr("class","link").style("mix-blend-mode","multiply"),I=(x==null?void 0:x.linkColor)||"gradient";if(I==="gradient"){let e=P.append("linearGradient").attr("id",l=>(l.uid=_t.next("linearGradient-")).id).attr("gradientUnits","userSpaceOnUse").attr("x1",l=>l.source.x1).attr("x2",l=>l.target.x0);e.append("stop").attr("offset","0%").attr("stop-color",l=>b(l.source.id)),e.append("stop").attr("offset","100%").attr("stop-color",l=>b(l.target.id))}let N;switch(I){case"gradient":N=e=>e.uid;break;case"source":N=e=>b(e.source.id);break;case"target":N=e=>b(e.target.id);break;default:N=I}P.append("path").attr("d",yt()).attr("stroke",N).attr("stroke-width",e=>Math.max(1,e.width))},fe={draw:ue},ce=t=>t.replaceAll(/^[^ \S \n \r ]+|[^ \S \n \r ]+ $ /g,"").replaceAll(/([ \n \r ])+/g, `
` ).trim(),he=tt.parse.bind(tt);tt.parse=t=>he(ce(t));var en={parser:tt,db:ae,renderer:fe};export{en as diagram};