Skill Tracer
Skills › Archify › archify › UPTXNAXN.js

UPTXNAXN.js

2 lines · archify/explainer/vendor/pele/chunks/UPTXNAXN.js at a406594

1import{a as ue,b as fe}from"./DKTLEL5E.js";import{g as oe}from"./GUJTEFZK.js";import{a as Q,b as F,c as k,d as ie,k as ae,m as J,n as le,o as ce}from"./IZOKQ2GT.js";import{a as ne,c as re,g as se}from"./XTDUIGUI.js";var B=class{type="sankey";nodes=[];links=[];title;accTitle;accDescr;lookup=new Map;findOrCreateNode(r){let n=this.lookup.get(r);return n===void 0&&(n={id:r,index:this.nodes.length},this.lookup.set(r,n),this.nodes.push(n)),n}addLink(r,n,o){this.links.push({source:r,target:n,value:o})}};var q=["$end","STUCK","SANKEY","NEWLINE","COMMA","DQUOTE","NON_ESCAPED_TEXT","ESCAPED_TEXT","EOF"];function he(t){return t>=32&&t<=126&&t!==34&&t!==44}function ge(t){let r=t.length,n=[],o=[],f=[],c=[],m=0,l=0,p=(h,$,d)=>{n.push(h),o.push(t.slice($,d)),f.push($),l=d},E=h=>t.slice(l,l+h.length).toLowerCase()===h&&!oe(t.charCodeAt(l+h.length));for(;l<r;){let h=t.charCodeAt(l),$=l,d=l;if(m===2){if(h===34&&t.charCodeAt(l+1)!==34){c.length>0&&(m=c.pop()),p(5,l,l+1);continue}for(;d<r;){let u=t.charCodeAt(d);if(he(u)||u===44||u===13||u===10)d++;else if(u===34&&t.charCodeAt(d+1)===34)d+=2;else break}p(7,l,d)}else{if(m===0&&(h|32)===115){let u=E("sankey-beta")?11:E("sankey")?6:0;if(u>0){c.push(m),m=1,p(2,l,l+u);continue}}if(h===10||h===13&&t.charCodeAt(l+1)===10){p(3,l,h===10?l+1:l+2);continue}if(h===44){p(4,l,l+1);continue}if(h===34){c.push(m),m=2,p(5,l,l+1);continue}for(;d<r&&he(t.charCodeAt(d));)d++;p(6,l,d)}if(d===$)return p(1,l,l),{types:n,texts:o,starts:f}}return p(m===2?7:8,r,r),p(0,r,r),{types:n,texts:o,starts:f}}var Ne=/[\n\r]+/g;function me(t){return t===10||t===13?!1:t<128?t===32||t===9||t===11||t===12:t===160||t===5760||t>=8192&&t<=8202||t===8232||t===8233||t===8239||t===8287||t===12288||t===65279}function de(t){let r=0,n=t.length;for(;r<n&&me(t.charCodeAt(r));)r++;for(;n>r&&me(t.charCodeAt(n-1));)n--;return t.slice(r,n).replace(Ne,`
2`).trim()}function ye(t,r){let{types:n,texts:o,starts:f}=ge(t),c=0,m=h=>{let $=n[c],d=$===1?q[n[c-1]]:q[$];throw re("sankey",t,f[c],`Expecting ${h}, got '${d}'`)},l=(h,$="")=>{n[c]!==h&&m(`'${q[h]}'${$}`),c++},p=()=>{if(n[c]===6)return o[c++];n[c]!==5&&m("'DQUOTE', 'NON_ESCAPED_TEXT'"),c++,n[c]!==7&&m("'ESCAPED_TEXT'");let h=o[c++];return l(5),h},E=()=>p().trim().replaceAll('""','"');for(l(2),l(3);;){let h=E();l(4,", 'NEWLINE', 'EOF'");let $=E();l(4,", 'NEWLINE', 'EOF'");let d=p(),u=r.findOrCreateNode(h),D=r.findOrCreateNode($);if(r.addLink(u,D,parseFloat(d.trim())),n[c]!==3)break;c++}n[c]===8&&c++,n[c]!==0&&m("'NEWLINE', 'EOF'")}var Ce=6;function ee(t,r){if(t.length>8){t.sort(r);return}for(let n=1;n<t.length;n++){let o=t[n],f=n-1;for(;f>=0&&r(t[f],o)>0;)t[f+1]=t[f],f--;t[f+1]=o}}function pe(t,r){let n=t.nodes.length,o=t.links.map(e=>({source:e.source.index,target:e.target.index,value:Number.isFinite(e.value)&&e.value>0?e.value:0,thickness:0,sourceY:0,targetY:0})),f=[],c=[];for(let e=0;e<n;e++)f.push([]),c.push([]);o.forEach((e,s)=>{f[e.source].push(s),c[e.target].push(s)});let m=new Int32Array(n),l=new Int32Array(n),p=[];for(let e=0;e<n;e++)l[e]=c[e].length,l[e]===0&&p.push(e);for(let e=0;e<p.length;e++){let s=p[e];for(let a of f[s]){let g=o[a].target;m[g]<m[s]+1&&(m[g]=m[s]+1),--l[g]===0&&p.push(g)}}if(p.length<n){let e=0;for(;l[e]===0;)e++;let s=new Uint8Array(n);for(;s[e]===0;){s[e]=1;for(let a of c[e])if(l[o[a].source]>0){e=o[a].source;break}}throw new ne(`Sankey diagrams cannot have circular links, and "${t.nodes[e].id}" is part of one.`,"semantic",{type:"sankey"})}let E=1;for(let e=0;e<n;e++)m[e]+1>E&&(E=m[e]+1);let h=new Int32Array(n);for(let e=n-1;e>=0;e--){let s=p[e];for(let a of f[s])h[s]<h[o[a].target]+1&&(h[s]=h[o[a].target]+1)}let $=0;for(let e of o)e.value>$&&($=e.value);let d=$>0?1/$:0,u=[],D=new Float64Array(n),N=[];for(let e=0;e<E;e++)N.push([]);let U=E>1?(r.width-r.nodeWidth)/(E-1):0;for(let e=0;e<n;e++){let s;if(r.alignment==="left")s=m[e];else if(r.alignment==="right")s=E-1-h[e];else if(r.alignment==="center"){if(s=m[e],c[e].length===0&&f[e].length>0){s=E;for(let x of f[e])m[o[x].target]-1<s&&(s=m[o[x].target]-1)}}else s=f[e].length>0?m[e]:E-1;let a=0,g=0,y=0,i=0;for(let x of c[e])a+=o[x].value*d,y+=o[x].value;for(let x of f[e])g+=o[x].value*d,i+=o[x].value;D[e]=Math.max(a,g),u.push({layer:s,value:Math.max(y,i),x:s*U,y:0,height:0}),N[s].push(e)}let X=1;for(let e of N)e.length>X&&(X=e.length);let O=X>1?Math.min(r.nodePadding,r.height/(X-1)):r.nodePadding,C=1/0;for(let e of N){let s=0;for(let a of e)s+=D[a];s>0&&(C=Math.min(C,(r.height-(e.length-1)*O)/s))}(!Number.isFinite(C)||C<0)&&(C=0);let I=Math.max(0,r.labelHeight-O),j=e=>{for(let s of N){let a=(s.length-1)*O;for(let g of s)a+=Math.max(D[g]*e,I);if(a>r.height+1e-6)return!1}return!0};if(I>0&&!j(C))if(j(0)){let e=0;for(let s=0;s<40;s++){let a=(e+C)/2;j(a)?e=a:C=a}C=e}else I=0;let A=new Float64Array(n);for(let e of o)e.thickness=e.value*d*C;for(let e of N){let s=0;for(let g of e)u[g].height=D[g]*C,A[g]=Math.max(0,I-u[g].height)/2,u[g].y=s+A[g],s+=u[g].height+2*A[g]+O;let a=(r.height-s+O)/(e.length+1);e.forEach((g,y)=>u[g].y+=a*(y+1))}let M=e=>u[e].y+u[e].height/2,w=new Float64Array(o.length),L=new Float64Array(o.length),z=(e,s)=>M(o[e].target)-M(o[s].target)||e-s,H=(e,s)=>M(o[e].source)-M(o[s].source)||e-s,G=(e,s)=>M(e)-M(s)||e-s,K=e=>{let s=0;ee(f[e],z);for(let a of f[e])w[a]=s+o[a].thickness/2,s+=o[a].thickness},_=e=>{let s=0;ee(c[e],H);for(let a of c[e])L[a]=s+o[a].thickness/2,s+=o[a].thickness},W=()=>{for(let e=0;e<n;e++)K(e),_(e)},R=(e,s,a)=>{for(let y of e){let i=a?c[y]:f[y];if(i.length===0)continue;a?_(y):K(y);let x=0,b=0,T=0;for(let S of i){let Y=a?u[o[S].source].y+w[S]-L[S]:u[o[S].target].y+L[S]-w[S];x+=Y*o[S].thickness,b+=o[S].thickness,T+=M(a?o[S].source:o[S].target)-u[y].height/2}let v=b>0?x/b:T/i.length;u[y].y+=(v-u[y].y)*s}ee(e,G);let g=0;for(let y of e)u[y].y-A[y]<g&&(u[y].y=g+A[y]),g=u[y].y+u[y].height+A[y]+O;g=r.height;for(let y=e.length-1;y>=0;y--){let i=e[y];u[i].y+u[i].height+A[i]>g&&(u[i].y=g-u[i].height-A[i]),g=u[i].y-A[i]-O}};W();for(let e=0;e<Ce;e++){let s=Math.pow(.99,e);for(let a=E-2;a>=0;a--)R(N[a],s,!1);W();for(let a=1;a<E;a++)R(N[a],s,!0);W()}for(let e=0;e<o.length;e++)o[e].sourceY=u[o[e].source].y+w[e],o[e].targetY=u[o[e].target].y+L[e];return{nodes:u,links:o}}var ke=6,Me=15;function Se(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function V(t,r,n,o,f){let c=t[r];return typeof c=="number"&&c>=o?Math.min(c,f):n}function be(t,r){let n=t[r];return typeof n=="string"||typeof n=="number"&&Number.isFinite(n)?String(n):""}function Ee(t){return Math.abs(t)<1e15?Math.round(t*100)/100:t}function xe(t){return typeof t=="string"?ae([`fill:${t}`]).shape:""}function $e(t,r,n){let o=Se(r.sankey)?r.sankey:{};return ue(n,V(o,"width",600,1,1e4),160,f=>ve(t,o,n,f))}function ve(t,r,n,o){let f=n.fontSize??16,c=Math.round(f*.875),m=n.measurer??se(n.fontFamily),l=n.padding??8,p=V(r,"height",400,1,1e4),E=Math.min(V(r,"nodeWidth",10,1,200),o),h=r.showValues!==!1,$=be(r,"prefix"),d=be(r,"suffix"),u=r.labelStyle==="outlined",D=r.nodeAlignment==="left"||r.nodeAlignment==="right"||r.nodeAlignment==="center"?r.nodeAlignment:"justify",N=typeof r.linkColor=="string"?r.linkColor:"gradient",{nodes:U,links:X}=pe(t,{width:o,height:p,nodeWidth:E,nodePadding:V(r,"nodePadding",12,0,200)+(h?Me:0),labelHeight:c*1.15,alignment:D}),O=new Map;if(Se(r.nodeColors))for(let[i,x]of Object.entries(r.nodeColors)){let b=xe(x);b&&O.set(i,b)}let C=i=>O.get(t.nodes[i].id)??"",I=0,j=0;U.forEach(i=>{i.value>j&&(j=i.value,I=i.layer)});let A=0,M=o,w=0,L=p,z="",H="";U.forEach((i,x)=>{let b=t.nodes[x].id,T=Math.max(i.height,1);H+=`<rect class="pele-sankey-node" data-id="${F(b)}" x="${k(i.x)}" y="${k(i.y)}" width="${k(E)}" height="${k(T)}" rx="${k(Math.min(2,T/2))}" fill="${J(x)}"${C(x)}/>`;let v=h?`${$}${Ee(i.value)}${d}`:"",S=u?i.layer>=I:i.x<o/2,Y=m.width(v?`${b} ${v}`:b,c,0),P=S?i.x+E+ke:i.x-ke,Z=i.y+i.height/2;A=Math.min(A,S?P:P-Y),M=Math.max(M,S?P+Y:P),w=Math.min(w,Z-c*.75),L=Math.max(L,Z+c*.75);let te=` x="${k(P)}" y="${k(Z+c*.35)}" text-anchor="${S?"start":"end"}"`,Ae=Q(b)+(v?` <tspan class="pele-sankey-value" fill="var(--_m)">${Q(v)}</tspan>`:"");z+=`<g class="pele-label" data-id="${F(b)}">`+(u?`<text${te} fill="none" stroke="var(--_bg)" stroke-width="3" stroke-linejoin="round">${Q(b)}${v?" "+Q(v):""}</text>`:"")+`<text${te}>${Ae}</text></g>`});let G=N==="gradient"||N==="source"||N==="target"?"":xe(N),K="";for(let i of X){let x=N==="target"?i.target:i.source,b=Math.max(i.thickness,1)/2,T=U[i.source].x+E,v=U[i.target].x,S=k((T+v)/2),Y=F(t.nodes[i.source].id),P=F(t.nodes[i.target].id);K+=`<path class="pele-sankey-link" data-id="${Y}-&gt;${P}" d="M${k(T)},${k(i.sourceY-b)}C${S},${k(i.sourceY-b)} ${S},${k(i.targetY-b)} ${k(v)},${k(i.targetY-b)}L${k(v)},${k(i.targetY+b)}C${S},${k(i.targetY+b)} ${S},${k(i.sourceY+b)} ${k(T)},${k(i.sourceY+b)}Z" fill="${J(x)}"${G||C(x)}><title>${Y} → ${P}: ${F($)}${Ee(i.value)}${F(d)}</title></path>`}let _=ce(t.title,!1,m,f,fe(n),1),W=_.height>0?_.height+12:0,R=Math.max(M-A,_.width),e=l-A+(R-(M-A))/2,s=l+W-w,a=Math.ceil(R+2*l),g=Math.ceil(L-w+W+2*l);return{svg:le("sankey",a,g,f,n,t,ie(_,a/2,l+_.height/2,' class="pele-title" font-weight="var(--_tw)"')+`<g transform="translate(${k(e)},${k(s)})"><g class="pele-sankey-links" fill-opacity="0.4">${K}</g><g class="pele-sankey-nodes">${H}</g><g class="pele-labels" font-size="${c}">${z}</g></g>`),width:a,height:g,links:[]}}var Ve={type:"sankey",parse(t,r,n){let o=new B;return n&&(o.title=n),ye(de(t),o),o},render:$e};export{Ve as a};