@a9n-shoji/rvw 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n,l as r,t as i}from"./FileIcon-wDKKQgGv.js";import{A as a,C as o,D as s,E as c,O as l,S as u,T as d,_ as f,a as p,b as m,c as h,d as g,f as _,g as v,h as y,i as b,k as x,l as S,m as C,n as w,o as ee,p as T,r as te,s as ne,t as re,u as ie,v as ae,w as oe,x as se,y as ce}from"./index-zyXQjX9Z.js";var E=e(r(),1),le=210,ue=136,de=64,fe=11,pe=2,me=300,he=180,ge=26,D=5,O=5,_e=[me,240,180,144],k=[`below-left`,`above-left`,`below-right`,`above-right`],ve=5,A=20,ye=72,j=12,be=6,M=36,xe=4096,Se=32768,Ce=22,we=24,Te=12,N=8,Ee=12,De=3,Oe=32,ke=3,Ae=64,je=128,Me=[1,2];Me.length;var Ne=Array.from({length:22},(e,t)=>.08+t*.04).sort((e,t)=>Math.abs(e-.5)-Math.abs(t-.5)),Pe=[0,14,-14,28,-28,44,-44,64,-64,88,-88,116,-116,152,-152,196,-196,248,-248];function P(e,t){return e===t?0:e<t?-1:1}function Fe(e){let t=[...new Set(e)],n=new Map(t.map(e=>[e,e.split(`/`)]));return new Map(t.map(e=>{let r=n.get(e);for(let i=1;i<=r.length;i+=1){let a=r.slice(-i).join(`/`);if(t.every(t=>t===e||n.get(t).slice(-i).join(`/`)!==a))return[e,a]}return[e,e]}))}function Ie(e,t){let n=e.anchors.flatMap(e=>{let n=t.get(e.path);return n?[n]:[]}),r=[...new Set(n)].sort(P);return{anchorCount:e.anchors.length,changeKind:r.length>1?`mixed`:r.length===1?r[0]:null}}var Le=12,Re=56,ze=28,Be=22;function Ve(e){return Array.from({length:49},(t,n)=>{let r=n/48,i=1-r;return{x:i**3*e.start.x+3*i**2*r*e.control1.x+3*i*r**2*e.control2.x+r**3*e.end.x,y:i**3*e.start.y+3*i**2*r*e.control1.y+3*i*r**2*e.control2.y+r**3*e.end.y}})}function He(e){return{left:Math.min(...e.map(({x:e})=>e)),top:Math.min(...e.map(({y:e})=>e)),right:Math.max(...e.map(({x:e})=>e)),bottom:Math.max(...e.map(({y:e})=>e))}}function Ue(e){let t=e.at(-1),n=[...e].reverse().slice(1).find(e=>e.x!==t.x||e.y!==t.y),r=t.x-n.x,i=t.y-n.y,a=Math.hypot(r,i),o={x:r/a,y:i/a},s=Math.min(12,a),c={x:t.x-o.x*s,y:t.y-o.y*s};return{base:c,path:`M ${c.x} ${c.y} L ${t.x} ${t.y}`,tangent:o}}function F(e,t){let n=Ue(e.points);return{...e,strokePath:t,arrowPath:n.path,arrowBaseX:n.base.x,arrowBaseY:n.base.y,arrowTangentX:n.tangent.x,arrowTangentY:n.tangent.y}}function We(e){let t=Ve(e);return{path:`M ${e.start.x} ${e.start.y} C ${e.control1.x} ${e.control1.y}, ${e.control2.x} ${e.control2.y}, ${e.end.x} ${e.end.y}`,points:t,startX:e.start.x,startY:e.start.y,control1X:e.control1.x,control1Y:e.control1.y,control2X:e.control2.x,control2Y:e.control2.y,endX:e.end.x,endY:e.end.y,bounds:He([...t,e.control1,e.control2])}}function Ge(e){let t=We(e),n=I([e.boundaryStart,...t.points,e.boundaryEnd]),r={...t,path:`M ${e.boundaryStart.x} ${e.boundaryStart.y} L ${e.start.x} ${e.start.y} C ${e.control1.x} ${e.control1.y}, ${e.control2.x} ${e.control2.y}, ${e.end.x} ${e.end.y} L ${e.boundaryEnd.x} ${e.boundaryEnd.y}`,points:n,startX:e.boundaryStart.x,startY:e.boundaryStart.y,endX:e.boundaryEnd.x,endY:e.boundaryEnd.y,bounds:He([...n,e.control1,e.control2])},i=Ue(n);return F(r,`M ${e.boundaryStart.x} ${e.boundaryStart.y} L ${e.start.x} ${e.start.y} C ${e.control1.x} ${e.control1.y}, ${e.control2.x} ${e.control2.y}, ${e.end.x} ${e.end.y} L ${i.base.x} ${i.base.y}`)}function I(e){let t=[];for(let n of e){let e=t.at(-1);if(e&&e.x===n.x&&e.y===n.y)continue;let r=t.at(-2);r&&e&&(r.x===e.x&&e.x===n.x||r.y===e.y&&e.y===n.y)?t[t.length-1]=n:t.push(n)}return t}function Ke(e){let t=I(e),n=t[0],r=t.at(-1);if(!n||!r||t.length<2)return null;let i=e=>{let t=e[0],n=e.slice(1).map((t,n)=>{let r=e[n];return`C ${r.x+(t.x-r.x)/3} ${r.y+(t.y-r.y)/3}, ${r.x+(t.x-r.x)*2/3} ${r.y+(t.y-r.y)*2/3}, ${t.x} ${t.y}`});return`M ${t.x} ${t.y} ${n.join(` `)}`},a=t[1],o=t.at(-2),s={path:i(t),points:t,startX:n.x,startY:n.y,control1X:n.x+(a.x-n.x)/3,control1Y:n.y+(a.y-n.y)/3,control2X:o.x+(r.x-o.x)*2/3,control2Y:o.y+(r.y-o.y)*2/3,endX:r.x,endY:r.y,bounds:He(t)},c=Ue(t);return F(s,i(I([...t.slice(0,-1),c.base])))}function qe(e,t,n,r,i,a){let o=t[e.from],s=t[e.to];if(!o||!s||e.from===e.to)return null;let c={x:o.x+114,y:o.y+56},l={x:s.x+114,y:s.y+56},u=at(c,l),d=at(l,c),f=$e(Ye(o,0),i?.from??n,Be,a?.get(e.from)).find(({side:e})=>e===u),p=$e(Ye(s,0),i?.to??n,Be,a?.get(e.to)).find(({side:e})=>e===d),m=p.point.x-f.point.x,h=p.point.y-f.point.y,g=Math.max(1,Math.hypot(m,h)),_=m/g,v=-(h/g),y=_,b=f.point,x=p.point,S=n*(r?5.5:4),C={x:b.x+(x.x-b.x)/3+v*S,y:b.y+(x.y-b.y)/3+y*S},w={x:b.x+(x.x-b.x)*2/3+v*S,y:b.y+(x.y-b.y)*2/3+y*S};return Ge({boundaryStart:f.boundaryPoint,start:b,control1:C,control2:w,end:x,boundaryEnd:p.boundaryPoint})}function Je(e){let t=new Set(e.filter(e=>e.directed&&e.from!==e.to).map(e=>JSON.stringify([e.from,e.to])));return new Set(e.filter(e=>e.directed&&e.from!==e.to&&t.has(JSON.stringify([e.to,e.from]))).map(e=>e.id))}function Ye(e,t=Le){return{left:e.x-t,top:e.y-t,right:e.x+228+t,bottom:e.y+112+t}}function Xe(e,t){return e.x>t.left&&e.x<t.right&&e.y>t.top&&e.y<t.bottom}function Ze(e,t,n){if(e.y===t.y){let r=Math.min(e.x,t.x),i=Math.max(e.x,t.x);return n.some(t=>e.y>t.top&&e.y<t.bottom&&r<t.right&&i>t.left)}if(e.x===t.x){let r=Math.min(e.y,t.y),i=Math.max(e.y,t.y);return n.some(t=>e.x>t.left&&e.x<t.right&&r<t.bottom&&i>t.top)}return!0}function Qe(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=0,o=1;for(let[t,s,c,l]of[[e.x,r,n.left,n.right],[e.y,i,n.top,n.bottom]]){if(Math.abs(s)<1e-6){if(t<c||t>l)return!1;continue}let e=(c-t)/s,n=(l-t)/s;if(a=Math.max(a,Math.min(e,n)),o=Math.min(o,Math.max(e,n)),a>o)return!1}return o>=0&&a<=1}function L(e,t){return e.slice(1).some((n,r)=>t.some(t=>Qe(e[r],n,t)))}function $e(e,t,n,r=`plain`){let i=(e.left+e.right)/2,a=(e.top+e.bottom)/2,o=e=>typeof t==`number`?t:t[e],s=t=>Math.max(-(e.right-e.left)/2+16,Math.min((e.right-e.left)/2-16,o(t))),c=t=>Math.max(-(e.bottom-e.top)/2+16,Math.min((e.bottom-e.top)/2-16,o(t)));return[{boundaryPoint:{x:e.left,y:a+c(`left`)},side:`left`},{boundaryPoint:{x:e.right,y:a+c(`right`)},side:`right`},{boundaryPoint:{x:i+s(`top`),y:e.top},side:`top`},{boundaryPoint:{x:i+s(`bottom`),y:e.bottom},side:`bottom`}].map(({boundaryPoint:t,side:i})=>{let a=nt(e,i,t,r);return{point:(()=>{switch(i){case`left`:return{x:e.left-n,y:a.y};case`right`:return{x:e.right+n,y:a.y};case`top`:return{x:a.x,y:e.top-n};case`bottom`:return{x:a.x,y:e.bottom+n}}})(),boundaryPoint:a,side:i}})}function et(e,t,n,r,i){let a=(e.left+e.right)/2,o=(e.top+e.bottom)/2,s=(e.right-e.left)/2,c=(e.bottom-e.top)/2,l=Math.max(0,s-r),u=Math.max(0,c-i);if(t===`top`||t===`bottom`){let o=n.x-a;if(Math.abs(o)<=l)return n;let s=a+Math.sign(o||1)*l,c=Math.max(-1,Math.min(1,(n.x-s)/r)),u=i*(1-Math.sqrt(Math.max(0,1-c**2)));return{x:n.x,y:t===`top`?e.top+u:e.bottom-u}}let d=n.y-o;if(Math.abs(d)<=u)return n;let f=o+Math.sign(d||1)*u,p=Math.max(-1,Math.min(1,(n.y-f)/i)),m=r*(1-Math.sqrt(Math.max(0,1-p**2)));return{x:t===`left`?e.left+m:e.right-m,y:n.y}}function tt(e,t,n){let r=e.right-e.left,i=e.bottom-e.top,a=(e.left+e.right)/2,o=(e.top+e.bottom)/2,s=r*.09;if(t===`left`||t===`right`){let r=s*Math.min(1,Math.abs(n.y-o)/(i/2));return{x:t===`left`?e.left+r:e.right-r,y:n.y}}let c=r/2-s,l=n.x-a;if(Math.abs(l)<=c)return n;let u=(Math.abs(l)-c)/s*(i/2);return{x:n.x,y:t===`top`?e.top+u:e.bottom-u}}function nt(e,t,n,r){if(r===`external`)return tt(e,t,n);if(r===`concept`){let r=Math.min((e.right-e.left)/2,(e.bottom-e.top)/2);return et(e,t,n,r,r)}return r===`database`?et(e,t,n,(e.right-e.left)/2,(e.bottom-e.top)*.14):n}function rt(e,t){if(e<=1)return[0];let n=Math.max(1,t/2-16),r=n*2/(e-1);return Array.from({length:e},(e,t)=>-n+t*r)}function it(e,t){let n=new Map;for(let r of e){if(r.from===r.to)continue;let e=t[r.from],i=t[r.to];if(!e||!i)continue;let a={x:e.x+114,y:e.y+56},o={x:i.x+114,y:i.y+56},s=[{edge:r,end:`from`,nodeId:r.from,otherNodeId:r.to,otherCenter:o},{edge:r,end:`to`,nodeId:r.to,otherNodeId:r.from,otherCenter:a}];for(let e of s){let t=n.get(e.nodeId)??[];t.push(e),n.set(e.nodeId,t)}}let r=new Map,i=()=>({left:0,right:0,top:0,bottom:0}),a=e=>(t,n)=>(e===`left`||e===`right`?t.otherCenter.y:t.otherCenter.x)-(e===`left`||e===`right`?n.otherCenter.y:n.otherCenter.x)||P(t.otherNodeId,n.otherNodeId)||P(t.edge.id,n.edge.id)||P(t.end,n.end);for(let e of n.values())for(let t of[`left`,`right`,`top`,`bottom`]){let n=[...e].sort(a(t)),o=t===`left`||t===`right`?112:228,s=rt(n.length,o);n.forEach((e,n)=>{let a=r.get(e.edge.id)??{from:i(),to:i()};a[e.end][t]=s[n],r.set(e.edge.id,a)})}return r}function at(e,t){let n=t.x-e.x,r=t.y-e.y;return Math.abs(n)>=Math.abs(r)?n>=0?`right`:`left`:r>=0?`bottom`:`top`}function ot(e,t){return e===t?0:e===`left`&&t===`right`||e===`right`&&t===`left`||e===`top`&&t===`bottom`||e===`bottom`&&t===`top`?72:24}function R(e){return`${e.x}:${e.y}`}function st(e,t){return e.cost-t.cost||P(e.stateKey,t.stateKey)}function ct(e,t){e.push(t);for(let t=e.length-1;t>0;){let n=Math.floor((t-1)/2);if(st(e[n],e[t])<=0)break;[e[n],e[t]]=[e[t],e[n]],t=n}}function lt(e){let t=e[0],n=e.pop();if(!t||!n||e.length===0)return t;e[0]=n;for(let t=0;t<e.length;){let n=t*2+1,r=n+1,i=t;if(n<e.length&&st(e[n],e[i])<0&&(i=n),r<e.length&&st(e[r],e[i])<0&&(i=r),i===t)break;[e[t],e[i]]=[e[i],e[t]],t=i}return t}function ut(e){let t=jt([...e.obstacles,...e.sources.map(({point:e})=>({left:e.x,top:e.y,right:e.x,bottom:e.y})),...e.targets.map(({point:e})=>({left:e.x,top:e.y,right:e.x,bottom:e.y}))]);if(!t)return null;let n=null;for(let r of e.sources)for(let i of e.targets){let a=e.channelOffset===0?[[r.point,{x:i.point.x,y:r.point.y},i.point],[r.point,{x:r.point.x,y:i.point.y},i.point]]:[t.left-Re-e.channelOffset,t.right+Re+e.channelOffset].map(e=>[r.point,{x:e,y:r.point.y},{x:e,y:i.point.y},i.point]).concat([t.top-Re-e.channelOffset,t.bottom+Re+e.channelOffset].map(e=>[r.point,{x:r.point.x,y:e},{x:i.point.x,y:e},i.point]));for(let t of a){let a=I(t);if(a.length<2||a.slice(1).some((t,n)=>Ze(a[n],t,e.obstacles)))continue;let o=a.slice(1).reduce((e,t,n)=>{let r=a[n];return e+Math.abs(t.x-r.x)+Math.abs(t.y-r.y)},0),s=r.penalty+i.penalty+o+Math.max(0,a.length-2)*ze,c=a.map(R).join(`|`);(n===null||s<n.cost||s===n.cost&&P(c,n.key)<0)&&(n={cost:s,key:c,points:a})}}return n?.points??null}function dt(e){if(e.sources.length===0||e.targets.length===0)return null;if(e.obstacles.length>=64){let t=ut({...e,channelOffset:Math.max(0,e.channelOffset??0)});if(t)return t}let t=[...e.sources,...e.targets],n=jt([...e.obstacles,...t.map(({point:e})=>({left:e.x,top:e.y,right:e.x,bottom:e.y}))]);if(!n)return null;let r=Math.max(0,e.channelOffset??0),i=[n.left-Re-r,n.right+Re+r,...e.obstacles.flatMap(e=>[e.left-r,e.right+r]),...t.map(({point:e})=>e.x)].sort((e,t)=>e-t),a=[n.top-Re-r,n.bottom+Re+r,...e.obstacles.flatMap(e=>[e.top-r,e.bottom+r]),...t.map(({point:e})=>e.y)].sort((e,t)=>e-t),o=[...new Set(i)],s=[...new Set(a)],c=new Map;for(let t of s)for(let n of o){let r={x:n,y:t};e.obstacles.some(e=>Xe(r,e))||c.set(R(r),r)}let l=new Map([...c.keys()].map(e=>[e,new Set])),u=(t,n)=>{if(Ze(t,n,e.obstacles))return;let r=R(t),i=R(n);l.get(r)?.add(i),l.get(i)?.add(r)};for(let e of s){let t=null;for(let n of o){let r=c.get(R({x:n,y:e}));r&&(t&&u(t,r),t=r)}}for(let e of o){let t=null;for(let n of s){let r=c.get(R({x:e,y:n}));r&&(t&&u(t,r),t=r)}}let d=new Map;for(let{point:t,penalty:n}of e.targets){let e=R(t);d.set(e,Math.min(n,d.get(e)??1/0))}let f=[],p=new Map,m=new Map;for(let{point:t,penalty:n}of e.sources){let e=R(t);if(!c.has(e))continue;let r=`${e}|start`,i=n;i>=(p.get(r)??1/0)||(p.set(r,i),m.set(r,null),ct(f,{stateKey:r,vertexKey:e,direction:`start`,cost:i}))}let h=null,g=1/0;for(;f.length>0;){let e=lt(f);if(e.cost!==p.get(e.stateKey))continue;if(e.cost>g)break;let t=d.get(e.vertexKey);if(t!==void 0){let n=e.cost+t;(n<g||n===g&&(!h||P(e.stateKey,h.stateKey)<0))&&(h=e,g=n)}let n=c.get(e.vertexKey);for(let t of[...l.get(e.vertexKey)??[]].sort(P)){let r=c.get(t),i=n.x===r.x?`vertical`:`horizontal`,a=Math.abs(n.x-r.x)+Math.abs(n.y-r.y),o=e.direction===`start`||e.direction===i?0:ze,s=e.cost+a+o,l=`${t}|${i}`;s>=(p.get(l)??1/0)||(p.set(l,s),m.set(l,e.stateKey),ct(f,{stateKey:l,vertexKey:t,direction:i,cost:s}))}}if(!h)return null;let _=[];for(let e=h.stateKey;e!==null;){let t=e.lastIndexOf(`|`),n=e.slice(0,t);_.push(c.get(n)),e=m.get(e)??null}return I(_.reverse())}function ft(e){let t=at(e.from,e.to),n=at(e.to,e.from),r=Le,i=Be,a=$e(e.fromBox,e.portOffsets.from,r,e.fromNotation),o=$e(e.toBox,e.portOffsets.to,i,e.toNotation),s=dt({sources:a.map(({point:e,side:n})=>({point:e,penalty:ot(n,t)})),targets:o.map(({point:e,side:t})=>({point:e,penalty:ot(t,n)})),obstacles:e.obstacles,...e.channelOffset===void 0?{}:{channelOffset:e.channelOffset}});if(!s)return null;let c=s[0],l=s.at(-1),u=a.find(({point:e})=>R(e)===R(c)),d=o.find(({point:e})=>R(e)===R(l));return!u||!d?null:I([u.boundaryPoint,...s,d.boundaryPoint])}function z(e){return e.points.slice(1).flatMap((t,n)=>{let r=e.points[n];return r.y===t.y&&r.x!==t.x?[{orientation:`horizontal`,fixed:t.y,minimum:Math.min(r.x,t.x),maximum:Math.max(r.x,t.x)}]:r.x===t.x&&r.y!==t.y?[{orientation:`vertical`,fixed:t.x,minimum:Math.min(r.y,t.y),maximum:Math.max(r.y,t.y)}]:[]})}function pt(e,t){return z(e).some(e=>z(t).some(t=>e.orientation!==t.orientation||Math.abs(e.fixed-t.fixed)>4?!1:Math.min(e.maximum,t.maximum)-Math.max(e.minimum,t.minimum)>=48))}function B(e,t){let n=new Map(e.map(e=>[e,new Set]));for(let r=0;r<e.length;r+=1){let i=e[r],a=t.get(i);if(a)for(let o=r+1;o<e.length;o+=1){let r=e[o],s=t.get(r);!s||!pt(a,s)||(n.get(i).add(r),n.get(r).add(i))}}let r=[],i=new Set;for(let t of e){if(i.has(t)||n.get(t)?.size===0)continue;let e=[],a=[t];i.add(t);for(let t=0;t<a.length;t+=1){let r=a[t];e.push(r);for(let e of[...n.get(r)??[]].sort(P))i.has(e)||(i.add(e),a.push(e))}r.push(e.sort(P))}return r}function V(e){let{point:t,notation:n,laneOffset:r,obstacles:i}=e,a=t.x,o=t.x+228,s=t.y,c=t.y+112,l=r*.55,u=e=>Math.max(a+16,Math.min(o-16,e)),d=e=>Math.max(s+16,Math.min(c-16,e));for(let e=0;e<12;e+=1){let t=88+Math.abs(r)*2+e*72,f={left:a,right:o,top:s,bottom:c},p=nt(f,`right`,{x:o,y:d(s+32+l)},n),m=nt(f,`right`,{x:o,y:d(c-32+l)},n),h=nt(f,`left`,{x:a,y:d(c-32-l)},n),g=nt(f,`left`,{x:a,y:d(s+32-l)},n),_=nt(f,`top`,{x:u(a+48+l),y:s},n),v=nt(f,`top`,{x:u(o-48+l),y:s},n),y=nt(f,`bottom`,{x:u(o-48-l),y:c},n),b=nt(f,`bottom`,{x:u(a+48-l),y:c},n),x=[Ge({boundaryStart:p,start:{x:o+Be,y:p.y},control1:{x:o+t,y:s-64+l},control2:{x:o+t,y:c+64+l},end:{x:o+Be,y:m.y},boundaryEnd:m}),Ge({boundaryStart:h,start:{x:a-Be,y:h.y},control1:{x:a-t,y:c+64-l},control2:{x:a-t,y:s-64-l},end:{x:a-Be,y:g.y},boundaryEnd:g}),Ge({boundaryStart:_,start:{x:_.x,y:s-Be},control1:{x:a-72+l,y:s-t},control2:{x:o+72+l,y:s-t},end:{x:v.x,y:s-Be},boundaryEnd:v}),Ge({boundaryStart:y,start:{x:y.x,y:c+Be},control1:{x:o+72-l,y:c+t},control2:{x:a-72-l,y:c+t},end:{x:b.x,y:c+Be},boundaryEnd:b})].find(e=>!L(e.points,i));if(x)return x}return null}function mt(e,t,n){let r=c(e),i=it(e,n),a=new Map(t.map(e=>[e.id,e.notation])),o=Je(e),s=new Map(t.flatMap(e=>{let t=n[e.id];return t?[[e.id,Ye(t,0)]]:[]})),l=new Map(t.flatMap(e=>{let t=n[e.id];return t?[[e.id,Ye(t)]]:[]})),u=new Map,d=[],f=[...e].sort((e,t)=>P(e.id,t.id)),p=(e,t=0)=>{let r=n[e.from],o=n[e.to],c=s.get(e.from),u=s.get(e.to);if(!r||!o||!c||!u)return null;let d=[...l].filter(([t])=>{if(t===e.from||t===e.to)return!0;let n=s.get(t);return!n||!H(n,c)&&!H(n,u)}).map(([,e])=>e),f=ft({from:{x:r.x+114,y:r.y+56},to:{x:o.x+114,y:o.y+56},fromBox:c,toBox:u,obstacles:d,portOffsets:i.get(e.id)??{from:{left:0,right:0,top:0,bottom:0},to:{left:0,right:0,top:0,bottom:0}},fromNotation:a.get(e.from)??`plain`,toNotation:a.get(e.to)??`plain`,channelOffset:t});return f?Ke(f):null};for(let e of f){let t=n[e.from],c=n[e.to];if(!t||!c)continue;let f=[...l].filter(([t])=>{if(t===e.from||t===e.to)return!1;let n=s.get(t),r=s.get(e.from),i=s.get(e.to);return n&&r&&i?!H(n,r)&&!H(n,i):!0}).map(([,e])=>e),m=r.get(e.id)??0;if(e.from===e.to){let n=V({point:t,notation:a.get(e.from)??`plain`,laneOffset:m,obstacles:f});n&&u.set(e.id,n);continue}let h=qe(e,n,m,o.has(e.id),i.get(e.id),a);if(h&&!H(l.get(e.from),l.get(e.to))&&!L(h.points,f)){u.set(e.id,h);continue}let g=p(e);g&&u.set(e.id,g),d.push(e.id)}let m=new Map([...d].sort(P).map((e,t)=>[e,t])),h=new Map(f.map(e=>[e.id,e]));for(let e=0;e<Math.min(8,d.length);e+=1){let e=B(d,u);if(e.length===0)break;for(let t of e)t.forEach(e=>{let t=h.get(e),n=m.get(e),r=p(t,(n+1)*8);r&&u.set(e,r)})}return u}function ht(e,t,n){let r=e.points.slice(1).map((t,n)=>{let r=e.points[n];return{previous:r,point:t,length:Math.hypot(t.x-r.x,t.y-r.y)}}),i=r.reduce((e,t)=>e+t.length,0)*t,a=r.find(e=>i<=e.length||(i-=e.length,!1))??r.at(-1);if(!a){let r={x:e.startX,y:e.startY};return{point:r,routePoint:r,tangent:{x:1,y:0},fraction:t,normalOffset:n}}let o=a.length===0?0:Math.min(1,i/a.length),s=a.previous.x+(a.point.x-a.previous.x)*o,c=a.previous.y+(a.point.y-a.previous.y)*o,l=a.point.x-a.previous.x,u=a.point.y-a.previous.y,d=Math.max(1,Math.hypot(l,u)),f={x:l/d,y:u/d},p={x:s,y:c};return{point:{x:s+-f.y*n,y:c+f.x*n},routePoint:p,tangent:f,fraction:t,normalOffset:n}}function H(e,t){return!(e.right<t.left||e.left>t.right||e.bottom<t.top||e.top>t.bottom)}function U(e,t,n,r,i=0){return{left:e-n/2-i,top:t-r/2-i,right:e+n/2+i,bottom:t+r/2+i}}function W(e,t){return{left:e.left-t,top:e.top-t,right:e.right+t,bottom:e.bottom+t}}function gt(e,t){let n=Math.max(t.left-e.x,0,e.x-t.right),r=Math.max(t.top-e.y,0,e.y-t.bottom);return Math.hypot(n,r)}function _t(e,t,n){let r=n.x-t.x,i=n.y-t.y,a=r*r+i*i;if(a===0)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*r+(e.y-t.y)*i)/a));return Math.hypot(e.x-(t.x+r*o),e.y-(t.y+i*o))}function G(e,t,n){if(Qe(t,n,e))return 0;let r=[{x:e.left,y:e.top},{x:e.right,y:e.top},{x:e.right,y:e.bottom},{x:e.left,y:e.bottom}];return Math.min(gt(t,e),gt(n,e),...r.map(e=>_t(e,t,n)))}function vt(e,t){return t.length<2?1/0:Math.min(...t.slice(1).map((n,r)=>G(e,t[r],n)))}function yt(e,t,n=0){return{left:Math.min(e.x,t.x)-n,top:Math.min(e.y,t.y)-n,right:Math.max(e.x,t.x)+n,bottom:Math.max(e.y,t.y)+n}}function bt(e){let t=[],n=Math.floor(e.left/je),r=Math.floor(e.right/je),i=Math.floor(e.top/je),a=Math.floor(e.bottom/je);for(let e=n;e<=r;e+=1)for(let n=i;n<=a;n+=1)t.push(`${e}:${n}`);return t}function xt(){let e=new Map;return{addPolyline(t,n){n.slice(1).forEach((r,i)=>{let a=n[i];if(a.x===r.x&&a.y===r.y)return;let o={ownerId:t,start:a,end:r};for(let t of bt(yt(a,r))){let n=e.get(t)??[];n.push(o),e.set(t,n)}})},query(t){let n=new Set;for(let r of bt(t))for(let t of e.get(r)??[])n.add(t);return[...n]}}}function St(e,t,n,r){let i={x:t.x-e.x,y:t.y-e.y},a={x:r.x-n.x,y:r.y-n.y},o=Math.hypot(i.x,i.y),s=Math.hypot(a.x,a.y);if(o===0||s===0||Math.abs(i.x*a.y-i.y*a.x)/(o*s)>.17||Math.min(_t(e,n,r),_t(t,n,r),_t(n,e,t),_t(r,e,t))>be)return null;let c={x:i.x/o,y:i.y/o},l=t=>(t.x-e.x)*c.x+(t.y-e.y)*c.y,u=l(n),d=l(r),f=Math.max(0,Math.min(u,d)),p=Math.min(o,Math.max(u,d));return p>f?{start:f,end:p}:null}function Ct(e){let t=0;for(let n of e.values()){let e=[...n].sort((e,t)=>e.start-t.start||e.end-t.end),r=null,i=null;for(let n of e){if(r===null||i===null){r=n.start,i=n.end;continue}if(n.start<=i+.001){i=Math.max(i,n.end);continue}t=Math.max(t,i-r),r=n.start,i=n.end}r!==null&&i!==null&&(t=Math.max(t,i-r))}return t}function wt(e,t,n,r){let i=(e,t,n)=>(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x),a=i(e,t,n),o=i(e,t,r),s=i(n,r,e),c=i(n,r,t);return a*o<-1e-6&&s*c<-1e-6}function Tt(e){return e.slice(1).reduce((t,n,r)=>{let i=e[r];return t+Math.hypot(n.x-i.x,n.y-i.y)},0)}function Et(e,t,n){let r=new Map,i=0,a=0;return e.slice(1).forEach((o,s)=>{let c=e[s],l=yt(c,o,be),u=(e,t)=>{let n=St(c,o,e.start,e.end);if(n){let i=`${t}:${e.ownerId}`,o=r.get(i)??[];o.push({start:a+n.start,end:a+n.end}),r.set(i,o)}wt(c,o,e.start,e.end)&&(i+=1)};for(let e of t.query(l))u(e,`route`);for(let e of n.query(l))u(e,`leader`);a+=Math.hypot(o.x-c.x,o.y-c.y)}),{length:a,maxParallelOverlap:Ct(r),crossingCount:i}}function Dt(e,t){let n={x:(e.left+e.right)/2,y:(e.top+e.bottom)/2},r=t.x-n.x,i=t.y-n.y;if(r===0&&i===0)return{x:n.x,y:e.top};let a=Math.max(1,(e.right-e.left)/2),o=Math.max(1,(e.bottom-e.top)/2),s=1/Math.max(Math.abs(r)/a,Math.abs(i)/o);return{x:n.x+r*s,y:n.y+i*s}}function Ot(e){let t=(e.left+e.right)/2,n=(e.top+e.bottom)/2;return[{x:e.left,y:n},{x:e.right,y:n},{x:t,y:e.top},{x:t,y:e.bottom}]}function kt(e){let t=new Set([...e.obstacles.flatMap(e=>[e.left,e.right]),...e.sources.map(({point:e})=>e.x),...e.targets.map(({point:e})=>e.x)]),n=new Set([...e.obstacles.flatMap(e=>[e.top,e.bottom]),...e.sources.map(({point:e})=>e.y),...e.targets.map(({point:e})=>e.y)]);return t.size*n.size}function At(e){if(e.obstacles.some(t=>Xe(e.routePoint,t)))return null;let t={x:-e.routeTangent.y,y:e.routeTangent.x},n={x:(e.label.left+e.label.right)/2,y:(e.label.top+e.label.bottom)/2},r=(n.x-e.routePoint.x)*t.x+(n.y-e.routePoint.y)*t.y>=0?1:-1,i=e.targetPorts??Ot(e.label),a=e.targetPorts?[...i].sort((t,n)=>Math.hypot(t.x-e.routePoint.x,t.y-e.routePoint.y)-Math.hypot(n.x-e.routePoint.x,n.y-e.routePoint.y)||P(R(t),R(n)))[0]:Dt(e.label,e.routePoint),o=Math.hypot(a.x-e.routePoint.x,a.y-e.routePoint.y),s=Math.min(j,Math.max(2,o*.45)),c=[],l=[];for(let n of[r,-r]){let r={x:e.routePoint.x+t.x*s*n,y:e.routePoint.y+t.y*s*n};if(e.obstacles.some(t=>Qe(e.routePoint,r,t)))continue;l.push(r);let i=Dt(e.label,r);e.obstacles.some(e=>Qe(r,i,e))||c.push([e.routePoint,r,i])}let u=t=>[...new Map(t.map(e=>I(e)).filter(t=>t.length>=2&&!t.slice(1).some((n,r)=>e.obstacles.some(e=>Qe(t[r],n,W(e,-.001))))).map(e=>[e.map(R).join(`|`),e])).values()].map(t=>({points:t,...Et(t,e.routeSegments,e.leaderSegments)})),d=(e,t)=>{let n=e.maxParallelOverlap>=M,r=t.maxParallelOverlap>=M;return Number(n)-Number(r)||e.length+e.crossingCount*8-(t.length+t.crossingCount*8)||e.maxParallelOverlap-t.maxParallelOverlap||e.points.length-t.points.length||P(e.points.map(R).join(`|`),t.points.map(R).join(`|`))},f=u(c).sort(d);if(f[0]&&f[0].maxParallelOverlap<M)return f[0];let p=l.flatMap(t=>{let n={sources:[{point:t,penalty:0}],targets:i.map(e=>({point:e,penalty:0})),obstacles:[...e.obstacles,e.label],channelOffset:0},r=ut(n)??(e.allowOuterRoute?ut({...n,channelOffset:N}):null)??(kt(n)<=(e.fullGridVertexLimit??xe)?dt(n):null);return r?[[e.routePoint,...r]]:[]});return[...f,...u(p)].sort(d)[0]??null}function jt(e){return e.length===0?null:{left:Math.min(...e.map(e=>e.left)),top:Math.min(...e.map(e=>e.top)),right:Math.max(...e.map(e=>e.right)),bottom:Math.max(...e.map(e=>e.bottom))}}function Mt(e){return[...e].reduce((e,t)=>e+(/\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}/u.test(t)?1:.56),0)}function Nt(e,t){if(/\s/u.test(e)||/[./_-]/u.test(e)||e===`:`&&t===`:`)return!0;if(!t||!/[\p{L}\p{N}]/u.test(e)||!/[\p{L}\p{N}]/u.test(t))return!1;let n=e=>/\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}/u.test(e);return n(e)!==n(t)}function Pt(e,t){let n=[...e.trimEnd()];for(;n.length>0&&Mt(n.join(``)+`…`)>t;)n.pop();return`${n.join(``).trimEnd()}…`}function Ft(e,t){let n=e.trim();if(!n)return[``];let r=[];for(;Mt(n)>t;){let e=[...n],i=0,a=0,o=0;for(let n=0;n<e.length;n+=1){let r=e[n],s=i+Mt(r);if(s>t&&a>0)break;if(i=s,a=n+1,Nt(r,e[n+1])){if(r===`:`&&e[n+1]===`:`){if(s+Mt(e[n+1])<=t)o=n+2;else if(n>0){o=n;break}}else o=n+1}if(i>t)break}let s=Math.min(e.length,o>0?o:Math.max(1,a));if(r.push(e.slice(0,s).join(``).trimEnd()),n=e.slice(s).join(``).trimStart(),!n)break}return n&&r.push(n),r}function It(e){let t=Math.max(.56,e.maxUnits),n=e.text.replaceAll(`\r
2
+ `,`
3
+ `).replaceAll(`\r`,`
4
+ `).split(`
5
+ `).flatMap(e=>Ft(e,t)),r=e.maxLines??1/0;if(n.length<=r)return n;let i=n.slice(0,Math.max(1,r));return e.ellipsize!==!1&&(i[i.length-1]=Pt(i[i.length-1],t)),i}function K(e,t,n,r,i=le){let a=Math.ceil(Mt(e.label)*11.5),o=Math.min(i,Math.max(de,a+fe+pe)),s=Math.max(1,o-fe),c=It({text:e.label,maxUnits:s/11.5,ellipsize:!1}),l=Math.max(24,c.length*14+10),u=Ie(e,t),d=u.anchorCount>1?4:0,f=n===`source-actions`&&u.anchorCount>0?29+d:0,p=n===`source-actions`?Math.max(l,u.anchorCount>1?34:u.anchorCount===1?26:0):l;return{selectWidth:o,boxWidth:o+f,height:p,displayLines:c,source:u}}function Lt(e){if(!e.enabled||e.size.source.anchorCount<=1||e.size.boxWidth<=e.size.selectWidth)return[];let t=U(e.point.x,e.point.y,e.size.boxWidth,e.size.height),n=Math.min(he,e.size.source.anchorCount*ge+Math.max(0,e.size.source.anchorCount-1)*D+14+2),r=t.right-(e.size.boxWidth-e.size.selectWidth);return _e.flatMap(i=>k.map(a=>{let o=a.endsWith(`right`),s=a.startsWith(`below`),c=o?r:t.right-i,l=e.point.y+ge/2+O,u=e.point.y-ge/2-O,d=s?l:u-n;return{placement:a,width:i,box:W({left:c,top:d,right:c+i,bottom:d+n},ve)}}))}function Rt(e,t,n){let r=Math.max(0,t-e);if(r<=n)return[(e+t)/2];let i=Math.max(1,Math.floor((r+Ee)/(n+Ee))),a=Math.min(Oe,i);if(a===1)return[(e+t)/2];let o=e+n/2,s=t-n/2;return Array.from({length:a},(e,t)=>o+(s-o)*t/(a-1))}function zt(e){let t=Tt(e.points);if(t<=0)return[ht(e,.5,0)];let n=Math.min(j,t/2)/t;return[n,1-n,...Ne].filter((e,t,n)=>n.indexOf(e)===t).map(t=>ht(e,t,0))}function Bt(e){return e<=ye?0:1+Math.floor((e-ye)/ye)}function Vt(e,t,n,r,i,a,o){let s=new Set(t.map(({id:e})=>e)),c=t.flatMap(e=>{let t=n[e.id];return t?[{left:t.x,top:t.y,right:t.x+228,bottom:t.y+112}]:[]}),l=c.map(e=>W(e,20)),u=new Map,d=[],f=xt(),p=xt(),m=[],h=null,g=null;for(let[e,t]of i)f.addPolyline(e,t.points);let _=e=>{let t=new Set;for(let n of bt(e)){let r=u.get(n);if(r){for(let n of r)if(!t.has(n)&&(t.add(n),H(e,n)))return!0}}return!1},v=e=>{d.push(e);for(let t of bt(e)){let n=u.get(t)??[];n.push(e),u.set(t,n)}},y=(e,t)=>new Set(f.query(e).filter(n=>n.ownerId!==t&&Qe(n.start,n.end,e)).map(({ownerId:e})=>e)),b=e=>p.query(e).some(t=>Qe(t.start,t.end,e)),x=[],S=[...e].sort((e,t)=>P(e.id,t.id));for(let e of S){let t=i.get(e.id);if(!t)continue;let n=K(e,r,a,o),s=[{size:n,usedCompactWidth:!1}];if(o===`viewer-adaptive`){let t=K(e,r,a,o,ue);t.boxWidth<n.boxWidth&&s.push({size:t,usedCompactWidth:!0})}let u=s.flatMap(({size:e,usedCompactWidth:n})=>Pe.flatMap(r=>Ne.map(i=>{let a=ht(t,i,r),o=U(a.point.x,a.point.y,e.boxWidth,e.height),s=vt(o,t.points);return{sample:a,size:e,box:o,collisionBox:W(o,ve),edgeDistance:s,usedCompactWidth:n}})));u.sort((e,t)=>e.edgeDistance-t.edgeDistance||Math.abs(e.sample.normalOffset)-Math.abs(t.sample.normalOffset)||Math.abs(e.sample.fraction-.5)-Math.abs(t.sample.fraction-.5)||Number(e.usedCompactWidth)-Number(t.usedCompactWidth)||e.size.height-t.size.height||e.sample.point.y-t.sample.point.y||e.sample.point.x-t.sample.point.x);let S=[...c.map(e=>W(e,4)),...d.map(e=>W(e,2))],C=(e,t)=>e.associationOverlapCount-t.associationOverlapCount||Number((e.leader?.maxParallelOverlap??0)>=M)-Number((t.leader?.maxParallelOverlap??0)>=M)||(e.leader?.crossingCount??0)-(t.leader?.crossingCount??0)||(e.leader?.maxParallelOverlap??0)-(t.leader?.maxParallelOverlap??0)||e.candidate.edgeDistance-t.candidate.edgeDistance||Math.abs(e.candidate.sample.normalOffset)-Math.abs(t.candidate.sample.normalOffset)||Math.abs(e.candidate.sample.fraction-.5)-Math.abs(t.candidate.sample.fraction-.5)||Number(e.candidate.usedCompactWidth)-Number(t.candidate.usedCompactWidth)||e.candidate.sample.point.y-t.candidate.sample.point.y||e.candidate.sample.point.x-t.candidate.sample.point.x,w,ee=null,T;for(let t of u){let n=Bt(t.edgeDistance);if(ee!==null&&n!==ee&&(w=T,w))break;if((ee===null||n!==ee)&&(ee=n,T=void 0),[t.collisionBox].some(e=>l.some(t=>H(e,t))||_(e)||b(e)))continue;let r=y(t.collisionBox,e.id).size,i=r,a=t.edgeDistance>1e-6,o=a?At({routePoint:t.sample.routePoint,routeTangent:t.sample.tangent,label:t.box,obstacles:S,routeSegments:f,leaderSegments:p}):null;if(a&&!o)continue;let s=(o?.maxParallelOverlap??0)>=M,c={candidate:t,displaced:a,leader:o,otherRouteIntersections:r,associationOverlapCount:i,degraded:i>0||s,emergency:!1};if((!T||C(c,T)<0)&&(T=c),!c.degraded&&(c.leader?.crossingCount??0)===0&&(c.leader?.maxParallelOverlap??0)===0){w=c;break}}w??=T;let te,ne=jt(l);if(!w&&ne){let n=s.flatMap(({size:e,usedCompactWidth:n})=>{let r=Rt(ne.left,ne.right,e.boxWidth),i=Rt(ne.top,ne.bottom,e.height),a=e.height+Ee,o=[...Array.from({length:De},(t,n)=>r.map(t=>({point:{x:t,y:ne.top-e.height/2-N-n*a},sideIndex:n*4}))).flat(),...Array.from({length:De},(t,n)=>r.map(t=>({point:{x:t,y:ne.bottom+e.height/2+N+n*a},sideIndex:n*4+1}))).flat(),...i.map(t=>({point:{x:ne.left-e.boxWidth/2-N,y:t},sideIndex:2})),...i.map(t=>({point:{x:ne.right+e.boxWidth/2+N,y:t},sideIndex:3}))],s=Ne.map(e=>ht(t,e,0));return o.flatMap(({point:r,sideIndex:i})=>[...s].sort((e,t)=>Math.hypot(e.routePoint.x-r.x,e.routePoint.y-r.y)-Math.hypot(t.routePoint.x-r.x,t.routePoint.y-r.y)||Math.abs(e.fraction-.5)-Math.abs(t.fraction-.5)).slice(0,ke).map(a=>{let o={...a,point:r},s=U(r.x,r.y,e.boxWidth,e.height),c=vt(s,t.points);return{candidate:{sample:o,size:e,box:s,collisionBox:W(s,ve),edgeDistance:c,usedCompactWidth:n},sideIndex:i}}))});n.sort((e,t)=>e.candidate.edgeDistance-t.candidate.edgeDistance||Math.abs(e.candidate.sample.fraction-.5)-Math.abs(t.candidate.sample.fraction-.5)||e.sideIndex-t.sideIndex||Number(e.candidate.usedCompactWidth)-Number(t.candidate.usedCompactWidth)||e.candidate.sample.point.y-t.candidate.sample.point.y||e.candidate.sample.point.x-t.candidate.sample.point.x);let r=0;for(let{candidate:t}of n){if([t.collisionBox].some(e=>l.some(t=>H(e,t))||_(e)||b(e)))continue;let n=t.edgeDistance>1e-6;if(n&&r>=Ae)break;let i=n?At({routePoint:t.sample.routePoint,routeTangent:t.sample.tangent,label:t.box,obstacles:S,routeSegments:f,leaderSegments:p}):null;if(n&&(r+=1),n&&!i)continue;let a=y(t.collisionBox,e.id).size,o=a+Number(b(t.collisionBox)),s=(i?.maxParallelOverlap??0)>=M,c={candidate:t,displaced:n,leader:i,otherRouteIntersections:a,associationOverlapCount:o,degraded:!0,emergency:!0};if(o===0&&!s){w=c;break}te??=c}}if(w??=te,!w){let{size:n,usedCompactWidth:r}=s.at(-1),a=jt([...c,...[...i.values()].map(e=>e.bounds),...d,...m]);h??=a.right+we;let o=Math.max(g??a.bottom+we,a.bottom+we),l={x:h+n.boxWidth/2,y:o+n.height/2},u=U(l.x,l.y,n.boxWidth,n.height),_=W(u,ve),v=vt(u,t.points),x=c.map(e=>W(e,4)),S=d.map(e=>W(e,2)),C=[...x,...S],ee=[{x:u.left,y:l.y}],T=zt(t).slice(0,Ce).flatMap(t=>{let i=At({routePoint:t.routePoint,routeTangent:t.tangent,label:u,obstacles:C,routeSegments:f,leaderSegments:p,targetPorts:ee,allowOuterRoute:!0});if(!i)return[];let a=y(_,e.id).size;return[{candidate:{sample:{...t,point:l},size:n,box:u,collisionBox:_,edgeDistance:v,usedCompactWidth:r},displaced:!0,leader:i,otherRouteIntersections:a,associationOverlapCount:a,degraded:!0,emergency:!0}]});if(T.sort((e,t)=>Number((e.leader?.maxParallelOverlap??0)>=M)-Number((t.leader?.maxParallelOverlap??0)>=M)||(e.leader?.length??0)+(e.leader?.crossingCount??0)*8-((t.leader?.length??0)+(t.leader?.crossingCount??0)*8)||Math.abs(e.candidate.sample.fraction-.5)-Math.abs(t.candidate.sample.fraction-.5)||e.candidate.sample.point.x-t.candidate.sample.point.x),w=T[0],!w){let i=zt(t)[0],a=null;for(let e of zt(t).slice(0,Ce)){let t=At({routePoint:e.routePoint,routeTangent:e.tangent,label:u,obstacles:C,routeSegments:f,leaderSegments:p,targetPorts:ee,allowOuterRoute:!0,fullGridVertexLimit:Se});if(t){i=e,a=t;break}}if(!a){let e=zt(t).slice(0,Ce).flatMap(e=>{let t={x:-e.tangent.y,y:e.tangent.x},n=(l.x-e.routePoint.x)*t.x+(l.y-e.routePoint.y)*t.y>=0?1:-1;return[n,-n].map(n=>{let r={x:e.routePoint.x+t.x*j*n,y:e.routePoint.y+t.y*j*n},i=I([e.routePoint,r,ee[0]]),a=e=>e.filter(e=>i.slice(1).some((t,n)=>Qe(i[n],t,W(e,-.001)))).length;return{sample:e,leader:{points:i,...Et(i,f,p)},nodeCrossings:a(x),labelCrossings:a(S)}})}).sort((e,t)=>e.nodeCrossings-t.nodeCrossings||e.labelCrossings-t.labelCrossings||Number(e.leader.maxParallelOverlap>=M)-Number(t.leader.maxParallelOverlap>=M)||e.leader.length+e.leader.crossingCount*8-(t.leader.length+t.leader.crossingCount*8)||P(e.leader.points.map(R).join(`|`),t.leader.points.map(R).join(`|`)))[0];e&&(i=e.sample,a=e.leader)}let o=y(_,e.id).size;w={candidate:{sample:{...i,point:l},size:n,box:u,collisionBox:_,edgeDistance:vt(u,t.points),usedCompactWidth:r},displaced:!0,leader:a,otherRouteIntersections:o,associationOverlapCount:o+Number(b(_)),degraded:!0,emergency:!0}}g=w.candidate.box.bottom+Te}v(W(w.candidate.box,4));let re=w.leader?I(w.leader.points):null;re&&(p.addPolyline(e.id,re),m.push(W(He(re),3)));let ie=re?`M ${re[0].x} ${re[0].y} ${re.slice(1).map(e=>`L ${e.x} ${e.y}`).join(` `)}`:null,ae=w.emergency?`emergency`:w.associationOverlapCount>0?`label-route-overlap`:(w.leader?.maxParallelOverlap??0)>=M?`leader-overlap`:w.candidate.edgeDistance>ye?`distant`:null;x.push({edge:e,displayLines:w.candidate.size.displayLines,source:w.candidate.size.source,x:w.candidate.sample.point.x,y:w.candidate.sample.point.y,selectWidth:w.candidate.size.selectWidth,boxWidth:w.candidate.size.boxWidth,height:w.candidate.size.height,crowded:w.degraded,displaced:w.displaced,leaderPath:ie,leaderBounds:re?W(He(re),3):null,leaderEdgeAnchor:re?.[0]??null,leaderLabelAnchor:re?.at(-1)??null,sourceMenuPlacement:null,sourceMenuWidth:null,diagnostics:{edgeDistance:w.candidate.edgeDistance,leaderLength:w.leader?.length??0,maxParallelOverlap:w.leader?.maxParallelOverlap??0,crossingCount:w.leader?.crossingCount??0,usedCompactWidth:w.candidate.usedCompactWidth,spacingPressure:ae!==null||w.candidate.edgeDistance>A,fallbackReason:ae}})}let C=[],w=new Map(x.map(e=>[e.edge.id,U(e.x,e.y,e.boxWidth,e.height)])),ee=(e,t)=>Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top));return x.map(e=>{let t=Lt({enabled:s.has(e.edge.from)&&s.has(e.edge.to),point:{x:e.x,y:e.y},size:e});if(t.length===0)return e;let n=t.map((t,n)=>{let r=c.filter(e=>H(t.box,e)),i=[...w].filter(([t])=>t!==e.edge.id).map(([,e])=>e).filter(e=>H(t.box,e)),a=C.filter(e=>H(t.box,e)),o=new Set(p.query(t.box).filter(e=>Qe(e.start,e.end,t.box)).map(({ownerId:e})=>e)),s=new Set(f.query(t.box).filter(e=>Qe(e.start,e.end,t.box)).map(({ownerId:e})=>e)),l=[...r,...i].reduce((e,n)=>e+ee(t.box,n),0);return{reservation:t,nodeCollisionCount:r.length,labelCollisionCount:i.length,bodyCollisionArea:l,leaderCollisionCount:o.size,menuCollisionCount:a.length,routeCollisionCount:s.size,preference:n}}).sort((e,t)=>e.nodeCollisionCount-t.nodeCollisionCount||e.labelCollisionCount-t.labelCollisionCount||e.bodyCollisionArea-t.bodyCollisionArea||e.leaderCollisionCount-t.leaderCollisionCount||e.menuCollisionCount-t.menuCollisionCount||e.routeCollisionCount-t.routeCollisionCount||e.preference-t.preference)[0].reservation;return C.push(n.box),{...e,sourceMenuPlacement:n.placement,sourceMenuWidth:n.width}})}function Ht(e){let{structure:t,positions:n,sourceChangeKinds:r,labelAccessory:i,edgeLabelMode:a}=e,o=Fe([...t.nodes.flatMap(e=>e.anchor?[e.anchor.path]:[]),...t.edges.flatMap(e=>e.anchors.map(e=>e.path))]),s=t.nodes.flatMap(e=>{let t=n[e.id];return t?[{node:e,point:t,sourceLabel:e.anchor?o.get(e.anchor.path)??e.anchor.path:null,changeKind:e.anchor?r.get(e.anchor.path)??null:null}]:[]}),c=mt(t.edges,t.nodes,n),l=t.edges.flatMap(e=>{let t=c.get(e.id);return t?[{edge:e,geometry:t,source:Ie(e,r)}]:[]}),u=Vt(t.edges,t.nodes,n,r,c,i,a);return{nodes:s,edges:l,labels:u,presentation:t.presentation?(()=>{let e=new Set(t.edges.map(({id:e})=>e)),r=new Set((t.presentation.primaryBackbone?.edgeIds??[]).filter(t=>e.has(t)).sort(P)),i=new Set(t.edges.filter(e=>r.has(e.id)).flatMap(e=>[e.from,e.to]).sort(P)),a=[...t.presentation.regions].sort((e,t)=>P(e.id,t.id)).flatMap((e,r)=>{let i=[...new Set(e.nodeIds)].filter(e=>n[e]).sort(P),a=new Set(i),o=new Set(t.edges.filter(e=>a.has(e.from)&&a.has(e.to)).map(e=>e.id)),s=jt([...i.map(e=>{let t=n[e];return{left:t.x,top:t.y,right:t.x+228,bottom:t.y+112}}),...t.edges.flatMap(e=>{if(!o.has(e.id))return[];let t=c.get(e.id);return t?[t.bounds]:[]}),...u.flatMap(e=>o.has(e.edge.id)?[U(e.x,e.y,e.boxWidth,e.height,4),...e.leaderBounds?[e.leaderBounds]:[]]:[])]);return s?[{id:e.id,index:r,label:e.label,summary:e.summary,nodeIds:i,bounds:s}]:[]});return{thesis:t.presentation.thesis,startNodeId:t.presentation.startNodeId,primaryBackboneNodeIds:i,primaryBackboneEdgeIds:r,regions:a}})():null}}function Ut(e,t,n){if(!n||Object.values(n).some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return!1;let r=e.nodes.map(({id:e})=>e);return!r.some(e=>!n[e])&&r.some(e=>{let r=t[e],i=n[e];return!r||r.x!==i.x||r.y!==i.y})}function Wt(e){let{retryPositions:t,...n}=e,r=n.positions,i=Ht(n),a=0;for(let o of Me){let s=i.labels.filter(({diagnostics:e})=>e.spacingPressure);if(s.length===0)break;let c=t({attempt:o,positions:r,foundation:i,pressureLabels:s});if(!Ut(e.structure,r,c))break;r=c,i=Ht({...n,positions:r}),a+=1}return{foundation:i,positions:r,retryCount:a}}function Gt(e,t){let n=e.nodes.filter(({node:e})=>t.nodeIds.has(e.id)),r=new Set(n.map(({node:e})=>e.id)),i=e.edges.filter(({edge:e})=>t.edgeIds.has(e.id)&&r.has(e.from)&&r.has(e.to)),a=new Set(i.map(({edge:e})=>e.id)),o=e.labels.filter(({edge:e})=>a.has(e.id)&&t.labelEdgeIds.has(e.id)),s=n.map(({point:e})=>({left:e.x,top:e.y,right:e.x+228,bottom:e.y+112}));return s.push(...i.map(({geometry:e})=>e.bounds)),s.push(...o.map(e=>U(e.x,e.y,e.boxWidth,e.height,4))),s.push(...o.flatMap(({leaderBounds:e})=>e?[e]:[])),{nodes:n,edges:i,labels:o,presentation:e.presentation,bounds:jt(s)}}function Kt(e,t){let n=new Set(t),r=new Set(e.edges.filter(({edge:e})=>n.has(e.from)&&n.has(e.to)).map(({edge:e})=>e.id));return Gt(e,{nodeIds:n,edgeIds:r,labelEdgeIds:r}).bounds}function qt(e){let{selection:t,...n}=e;return Gt(Ht(n),t)}function Jt(e){let{structure:t}=e;return qt({...e,selection:{nodeIds:new Set(t.nodes.map(e=>e.id)),edgeIds:new Set(t.edges.map(e=>e.id)),labelEdgeIds:new Set(t.edges.map(e=>e.id))},labelAccessory:`none`,edgeLabelMode:`export-complete`})}function q(e,t){return e===t?0:e<t?-1:1}function Yt(e){return[...new Set(e)].sort(q)}function Xt(e,t){return JSON.stringify([e,t])}function Zt(e){let t=e.split(/[-_]+/u).filter(Boolean);return(t.length>1?t.slice(0,3).map(e=>e[0]).join(``):[...e].slice(0,3).join(``)).toUpperCase()}function Qt(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36).toUpperCase().padStart(7,`0`)}function $t(e){let t=Yt(e.map(({id:e})=>e)),n=new Map;for(let e of t){let t=Zt(e),r=n.get(t);r?r.push(e):n.set(t,[e])}let r=new Map;for(let[e,t]of n){if(t.length===1){r.set(t[0],e);continue}let n=new Map(t.map(e=>[e,Qt(e)])),i=2;for(;i<7&&new Set(t.map(e=>n.get(e).slice(0,i))).size<t.length;)i+=1;let a=t.map(t=>`${e}·${n.get(t).slice(0,i)}`),o=new Set(a).size===a.length;for(let[e,n]of t.entries())r.set(n,o?a[e]:`${a[e]}·${n}`)}return r}function en(e,t){let n=[...e].sort((e,t)=>q(e.id,t.id)).map(e=>({...e,nodeIds:Yt(e.nodeIds.filter(e=>t.has(e)))})),r=new Map;for(let e of n)for(let t of e.nodeIds)r.has(t)||r.set(t,e.id);return{regions:n.map(e=>({...e,nodeIds:e.nodeIds.filter(t=>r.get(t)===e.id)})),regionByNodeId:r}}function tn(e,t){return e.filter(e=>t.has(e.from)&&t.has(e.to)).sort((e,t)=>q(e.id,t.id))}function nn(e){let t=e.presentation;if(!t)return null;let n=new Set(e.nodes.map(({id:e})=>e)),{regions:r,regionByNodeId:i}=en(t.regions,n),a=new Set(t.primaryBackbone?.edgeIds??[]),o=tn(e.edges,n),s=new Map,c=new Map,l=new Map(r.map(({id:e})=>[e,[]])),u=new Map(r.map(({id:e})=>[e,[]])),d=new Map(r.map(({id:e})=>[e,[]])),f=new Map(r.map(({id:e})=>[e,new Set])),p=new Map(r.map(({id:e})=>[e,new Set])),m=new Map([...n].filter(e=>!i.has(e)).sort(q).map(e=>[e,new Set])),h=[];for(let e of o){let t=i.get(e.from),n=i.get(e.to);if(a.has(e.id)&&(t&&d.get(t)?.push(e.id),n&&n!==t&&d.get(n)?.push(e.id)),t&&t===n){l.get(t)?.push(e.id);continue}if(t&&n){let r=[t,n].sort(q),i=Xt(...r),o=s.get(i)??{regionIds:r,edgeIds:[],backboneEdgeIds:[],directions:{fromFirstRegionEdgeIds:[],fromSecondRegionEdgeIds:[],undirectedEdgeIds:[]}};o.edgeIds.push(e.id),a.has(e.id)&&o.backboneEdgeIds.push(e.id),e.directed?t===r[0]?o.directions.fromFirstRegionEdgeIds.push(e.id):o.directions.fromSecondRegionEdgeIds.push(e.id):o.directions.undirectedEdgeIds.push(e.id),s.set(i,o),u.get(t)?.push(e.id),u.get(n)?.push(e.id),f.get(t)?.add(n),f.get(n)?.add(t);continue}if(!t&&!n){h.push(e),e.from!==e.to&&(m.get(e.from)?.add(e.to),m.get(e.to)?.add(e.from));continue}let r=t??n,o=t?e.to:e.from,g=Xt(r,o),_=c.get(g)??{regionId:r,unassignedNodeId:o,edgeIds:[],backboneEdgeIds:[],directions:{fromRegionEdgeIds:[],fromUnassignedNodeEdgeIds:[],undirectedEdgeIds:[]}};_.edgeIds.push(e.id),a.has(e.id)&&_.backboneEdgeIds.push(e.id),e.directed?t?_.directions.fromRegionEdgeIds.push(e.id):_.directions.fromUnassignedNodeEdgeIds.push(e.id):_.directions.undirectedEdgeIds.push(e.id),c.set(g,_),u.get(r)?.push(e.id),p.get(r)?.add(o)}let g=[...c.values()].sort((e,t)=>q(e.regionId,t.regionId)||q(e.unassignedNodeId,t.unassignedNodeId)),_=new Map;for(let e of g){let t=_.get(e.unassignedNodeId)??[];t.push(e),_.set(e.unassignedNodeId,t)}let v=[],y=new Set;for(let e of[...m.keys()].sort(q)){if(y.has(e))continue;let t=[],n=[e];y.add(e);for(let e=0;e<n.length;e+=1){let r=n[e];t.push(r);for(let e of[...m.get(r)??[]].sort(q))y.has(e)||(y.add(e),n.push(e))}t.sort(q);let r=new Set(t),i=h.filter(e=>r.has(e.from)&&r.has(e.to)).map(({id:e})=>e),o=t.flatMap(e=>_.get(e)??[]),s=Yt(o.flatMap(({edgeIds:e})=>e));v.push({nodeIds:t,internalEdgeIds:i,boundaryEdgeIds:s,backboneEdgeIds:Yt([...i,...s].filter(e=>a.has(e))),adjacentRegionIds:Yt(o.map(({regionId:e})=>e))})}return{startRegionId:i.get(t.startNodeId)??null,regions:r.map(e=>({id:e.id,label:e.label,summary:e.summary,nodeIds:e.nodeIds,nodeCount:e.nodeIds.length,internalEdgeIds:Yt(l.get(e.id)??[]),boundaryEdgeIds:Yt(u.get(e.id)??[]),backboneEdgeIds:Yt(d.get(e.id)??[]),adjacentRegionIds:Yt(f.get(e.id)??[]),unassignedNeighborNodeIds:Yt(p.get(e.id)??[])})),directRelations:[...s.values()].sort((e,t)=>{let n=q(e.regionIds[0],t.regionIds[0]);return n===0?q(e.regionIds[1],t.regionIds[1]):n}),unassignedBoundaries:g,unassignedComponents:v}}function rn(e){return`context:${JSON.stringify(e)}`}function an(e){let t=e.unassignedComponents.map(e=>({id:rn(e.nodeIds),...e})),n=new Map(t.flatMap(e=>e.nodeIds.map(t=>[t,e.id]))),r=new Map;for(let t of e.unassignedBoundaries){let e=n.get(t.unassignedNodeId);if(!e)continue;let i=Xt(t.regionId,e),a=r.get(i)??{contextId:e,regionId:t.regionId,edgeIds:[],backboneEdgeIds:[],directions:{fromRegionEdgeIds:[],fromUnassignedNodeEdgeIds:[],undirectedEdgeIds:[]}};a.edgeIds.push(...t.edgeIds),a.backboneEdgeIds.push(...t.backboneEdgeIds),a.directions.fromRegionEdgeIds.push(...t.directions.fromRegionEdgeIds),a.directions.fromUnassignedNodeEdgeIds.push(...t.directions.fromUnassignedNodeEdgeIds),a.directions.undirectedEdgeIds.push(...t.directions.undirectedEdgeIds),r.set(i,a)}return{contexts:t,boundaryRelations:[...r.values()].map(e=>({...e,edgeIds:Yt(e.edgeIds),backboneEdgeIds:Yt(e.backboneEdgeIds),directions:{fromRegionEdgeIds:Yt(e.directions.fromRegionEdgeIds),fromUnassignedNodeEdgeIds:Yt(e.directions.fromUnassignedNodeEdgeIds),undirectedEdgeIds:Yt(e.directions.undirectedEdgeIds)}})).sort((e,t)=>q(e.regionId,t.regionId)||q(e.contextId,t.contextId))}}function on(e){return e.backboneEdgeIds.length>0?3:1}function sn(e){let{fromFirstRegionEdgeIds:t,fromSecondRegionEdgeIds:n,undirectedEdgeIds:r}=e.directions;return r.length>0?null:t.length>0&&n.length===0?e.regionIds:n.length>0&&t.length===0?[e.regionIds[1],e.regionIds[0]]:null}function cn(e){if(e.regions.length===0)return{width:0,height:0,columnCount:0,rowCount:0,regions:[],directRelations:[]};let t=e.regions.map(({id:e})=>e).sort(q),n=new Map(t.map(e=>[e,new Map]));for(let t of e.directRelations){let[e,r]=t.regionIds,i=on(t);n.get(e)?.set(r,i),n.get(r)?.set(e,i)}let r=new Map(e.directRelations.map(e=>[JSON.stringify(e.regionIds),e])),i=e=>[...n.get(e)?.values()??[]].reduce((e,t)=>e+t,0),a=[],o=new Set(t),s=new Set;for(;o.size>0;){let t=[...o].sort((t,r)=>{if(a.length===0&&e.startRegionId){if(t===e.startRegionId)return-1;if(r===e.startRegionId)return 1}let o=e=>[...n.get(e)??[]].reduce((e,[t,n])=>e+(s.has(t)?n:0),0);return o(r)-o(t)||i(r)-i(t)||q(t,r)})[0];a.push(t),s.add(t),o.delete(t)}let c=e.regions.length===1?1:2,l=Math.max(c,Math.min(e.regions.length,Math.ceil(Math.sqrt(e.regions.length*2)))),u=[];for(let i=c;i<=l;i+=1){let o=Math.ceil(t.length/i),s=Array.from({length:t.length},(e,t)=>({column:t%i,row:Math.floor(t/i)})),c=new Map;for(let[e,t]of a.entries()){let i=[...s].sort((i,a)=>{if(e===0)return i.column-a.column||Math.abs(i.row-(o-1)/2)-Math.abs(a.row-(o-1)/2)||i.row-a.row;let s=e=>{let i=0,a=0,o=0;for(let[s,l]of n.get(t)??[]){let n=c.get(s);if(!n)continue;a+=l,i+=l*(Math.abs(e.column-n.column)+Math.abs(e.row-n.row));let u=r.get(JSON.stringify([t,s].sort(q))),d=u?sn(u):null;d?.[0]===s&&e.column<n.column&&(o+=1),d?.[1]===s&&e.column>n.column&&(o+=1)}let s=Math.min(...[...c.values()].map(t=>Math.abs(e.column-t.column)+Math.abs(e.row-t.row)));return{adjacencyWeight:a,adjacencyDistance:i,directionPenalty:o,nearestPlaced:s}},l=s(i),u=s(a);return Number(u.adjacencyWeight>0)-Number(l.adjacencyWeight>0)||l.directionPenalty-u.directionPenalty||l.adjacencyDistance-u.adjacencyDistance||l.nearestPlaced-u.nearestPlaced||i.row-a.row||i.column-a.column})[0];c.set(t,i),s.splice(s.indexOf(i),1)}let l=i*232+Math.max(0,i-1)*272,d=o*176+Math.max(0,o-1)*76,f=e.directRelations.reduce((e,t)=>{let n=c.get(t.regionIds[0]),r=c.get(t.regionIds[1]);return e+on(t)*(Math.abs(n.column-r.column)+Math.abs(n.row-r.row))},0),p=e.directRelations.filter(e=>{let t=sn(e);return t?c.get(t[0]).column>c.get(t[1]).column:!1}).length;u.push({columnCount:i,rowCount:o,cellByRegionId:c,score:Math.max(l/1.6666666666666667,d)+f*36+p*120,signature:t.map(e=>{let t=c.get(e);return`${e}:${t.column},${t.row}`}).join(`|`)})}u.sort((e,t)=>e.score-t.score||e.columnCount*e.rowCount-t.columnCount*t.rowCount||q(e.signature,t.signature));let d=u[0],f=t.map(e=>{let t=d.cellByRegionId.get(e);return{regionId:e,...t,center:{x:t.column*504+116,y:t.row*252+88}}}),p=new Map(f.map(({regionId:e,center:t})=>[e,t]));return{width:d.columnCount*232+Math.max(0,d.columnCount-1)*272,height:d.rowCount*176+Math.max(0,d.rowCount-1)*76,columnCount:d.columnCount,rowCount:d.rowCount,regions:f,directRelations:e.directRelations.map(e=>({regionIds:e.regionIds,edgeIds:e.edgeIds,backboneEdgeIds:e.backboneEdgeIds,directions:e.directions,firstCenter:p.get(e.regionIds[0]),secondCenter:p.get(e.regionIds[1])}))}}var J=.001,ln=34,un=72,dn=520,fn=48,pn=32,mn=1024;function hn(e){return`${e.x}:${e.y}`}function gn(e,t=0){return{id:e.id,left:e.center.x-e.width/2-t,top:e.center.y-e.height/2-t,right:e.center.x+e.width/2+t,bottom:e.center.y+e.height/2+t}}function _n(e,t,n,r=0){return{id:`label`,left:e.x-t/2-r,top:e.y-n/2-r,right:e.x+t/2+r,bottom:e.y+n/2+r}}function Y(e,t){return e.left<t.right-J&&e.right>t.left+J&&e.top<t.bottom-J&&e.bottom>t.top+J}function vn(e,t){return e.x>t.left+J&&e.x<t.right-J&&e.y>t.top+J&&e.y<t.bottom-J}function yn(e,t,n){if(Math.abs(e.y-t.y)<J){if(e.y<=n.top+J||e.y>=n.bottom-J)return!1;let r=Math.min(e.x,t.x),i=Math.max(e.x,t.x);return r<n.right-J&&i>n.left+J}if(Math.abs(e.x-t.x)<J){if(e.x<=n.left+J||e.x>=n.right-J)return!1;let r=Math.min(e.y,t.y),i=Math.max(e.y,t.y);return r<n.bottom-J&&i>n.top+J}return!0}function bn(e,t,n){let r=0,i=Math.abs(e.y-t.y)<J;for(let a of n)for(let n=1;n<a.points.length;n+=1){let o=a.points[n-1],s=a.points[n];if(i===Math.abs(o.y-s.y)<J){if(i?Math.abs(e.y-o.y)>=J:Math.abs(e.x-o.x)>=J)continue;let n=i?Math.min(e.x,t.x):Math.min(e.y,t.y),a=i?Math.max(e.x,t.x):Math.max(e.y,t.y),c=i?Math.min(o.x,s.x):Math.min(o.y,s.y),l=i?Math.max(o.x,s.x):Math.max(o.y,s.y),u=Math.min(a,l)-Math.max(n,c);u>=fn&&(r+=dn+u);continue}let c=i?e:o,l=i?t:s,u=i?o:e,d=i?s:t,f=Math.min(c.x,l.x),p=Math.max(c.x,l.x),m=Math.min(u.y,d.y),h=Math.max(u.y,d.y);u.x>f+J&&u.x<p-J&&c.y>m+J&&c.y<h-J&&(r+=un)}return r}function xn(e,t){return e.cost<t.cost||e.cost===t.cost&&e.state<t.state}function Sn(e,t){e.push(t);let n=e.length-1;for(;n>0;){let t=Math.floor((n-1)/2);if(!xn(e[n],e[t]))break;[e[t],e[n]]=[e[n],e[t]],n=t}}function Cn(e){let t=e[0],n=e.pop();if(!t||!n||e.length===0)return t;e[0]=n;let r=0;for(;;){let t=r*2+1,n=t+1,i=r;if(t<e.length&&xn(e[t],e[i])&&(i=t),n<e.length&&xn(e[n],e[i])&&(i=n),i===r)break;[e[r],e[i]]=[e[i],e[r]],r=i}return t}function wn(e){return[...new Set(e)].sort((e,t)=>e-t)}function Tn(e){let t=wn(e);return wn([...t,...t.slice(1).map((e,n)=>(t[n]+e)/2)])}function En(e){let t=e.filter((t,n)=>n===0||hn(t)!==hn(e[n-1]));return t.filter((e,n)=>{if(n===0||n===t.length-1)return!0;let r=t[n-1],i=t[n+1];return!(Math.abs(r.x-e.x)<J&&Math.abs(e.x-i.x)<J||Math.abs(r.y-e.y)<J&&Math.abs(e.y-i.y)<J)})}function Dn(e,t){let n=e.width/2,r=e.height/2;return[{port:{x:e.center.x-n,y:e.center.y},escape:{x:e.center.x-n-t,y:e.center.y}},{port:{x:e.center.x+n,y:e.center.y},escape:{x:e.center.x+n+t,y:e.center.y}},{port:{x:e.center.x,y:e.center.y-r},escape:{x:e.center.x,y:e.center.y-r-t}},{port:{x:e.center.x,y:e.center.y+r},escape:{x:e.center.x,y:e.center.y+r+t}}]}function X(e){let t=Tn([12,e.width-12,...e.starts.map(({x:e})=>e),...e.targets.map(({x:e})=>e),...e.extraX??[],...e.obstacles.flatMap(({left:e,right:t})=>[e,t])]),n=Tn([12,e.height-12,...e.starts.map(({y:e})=>e),...e.targets.map(({y:e})=>e),...e.extraY??[],...e.obstacles.flatMap(({top:e,bottom:t})=>[e,t])]),r=new Map(t.map((e,t)=>[e,t])),i=new Map(n.map((e,t)=>[e,t])),a=(e,n)=>n*t.length+e,o=e=>({x:t[e%t.length],y:n[Math.floor(e/t.length)]}),s=t=>!e.obstacles.some(e=>vn(t,e)),c=new Uint8Array(t.length*n.length);for(let e=0;e<n.length;e+=1)for(let n=0;n<t.length;n+=1){let t=a(n,e);s(o(t))&&(c[t]=1)}let l=e=>e.flatMap(e=>{let t=r.get(e.x),n=i.get(e.y);if(t===void 0||n===void 0)return[];let o=a(t,n);return c[o]===1?[o]:[]}),u=l(e.starts),d=new Set(l(e.targets));if(u.length===0||d.size===0)return null;let f=t.length*n.length*3,p=new Float64Array(f);p.fill(1/0);let m=new Int32Array(f);m.fill(-1);let h=[];for(let e of u.sort((e,t)=>e-t)){let t=e*3;p[t]=0,Sn(h,{cost:0,state:t})}let g=-1;for(;h.length>0;){let r=Cn(h);if(r.cost!==p[r.state])continue;let i=Math.floor(r.state/3),s=r.state%3;if(d.has(i)){g=r.state;break}let l=i%t.length,u=Math.floor(i/t.length),f=[[l-1,u,1],[l+1,u,1],[l,u-1,2],[l,u+1,2]],_=o(i);for(let[i,l,u]of f){if(i<0||i>=t.length||l<0||l>=n.length)continue;let d=a(i,l);if(c[d]!==1)continue;let f=o(d),g=Math.abs(_.x-f.x)+Math.abs(_.y-f.y),v=s!==0&&s!==u?ln:0,y=bn(_,f,e.routed),b=d*3+u,x=r.cost+g+v+y;x+J>=p[b]||(p[b]=x,m[b]=r.state,Sn(h,{cost:x,state:b}))}}if(g<0)return null;let _=[];for(let e=g;e>=0&&(_.push(Math.floor(e/3)),!(m[e]<0));e=m[e]);let v=_.reverse().map(o);return{points:En(v),start:v[0],target:v.at(-1)}}function On(e){return e.slice(1).map((t,n)=>[e[n],t])}function kn(e,t,n){let r=On(e),i=r.map(([e,t])=>Math.abs(e.x-t.x)+Math.abs(e.y-t.y)),a=i.reduce((e,t)=>e+t,0),o=[],s=0;for(let[e,[c,l]]of r.entries()){let u=Math.abs(c.y-l.y)<J,d=(u?c.x:c.y)<=(u?l.x:l.y),f=e===0,p=e===r.length-1,m=(f&&d?28:0)+(p&&!d?28:0),h=(f&&!d?28:0)+(p&&d?28:0),g=u?Math.min(c.x,l.x)+t/2+8+m:Math.min(c.y,l.y)+n/2+8+m,_=u?Math.max(c.x,l.x)-t/2-8-h:Math.max(c.y,l.y)-n/2-8-h;if(g<=_+J){let e=new Set([g,_,(g+_)/2]);for(let t=g;t<=_+J;t+=12)e.add(Math.min(t,_));for(let t of e){let e=Math.abs(u?t-c.x:t-c.y);o.push({center:u?{x:t,y:c.y}:{x:c.x,y:t},distanceFromMiddle:Math.abs(s+e-a/2)})}}s+=i[e]}return o.sort((e,t)=>e.distanceFromMiddle-t.distanceFromMiddle||e.center.y-t.center.y||e.center.x-t.center.x)}function An(e,t){return On(t.points).some(([t,n])=>yn(t,n,e))}function jn(e){return kn(e.points,e.labelWidth,e.labelHeight).map(({center:e})=>e).find(t=>{let n=_n(t,e.labelWidth,e.labelHeight),r=_n(t,e.labelWidth,e.labelHeight,8);return r.left>=0&&r.top>=0&&r.right<=e.width&&r.bottom<=e.height&&!e.cardRects.some(e=>Y(r,e))&&!e.labelRects.some(e=>Y(r,e))&&!e.routed.some(e=>An(n,e))})}function Mn(e){let t=On(e.points),n=t.map(([e,t])=>Math.abs(e.x-t.x)+Math.abs(e.y-t.y)),r=n.reduce((e,t)=>e+t,0),i=[],a=0;for(let[o,[s,c]]of t.entries()){let t=s.y===c.y,l=t?Math.min(s.x,c.x):Math.min(s.y,c.y),u=t?Math.max(s.x,c.x):Math.max(s.y,c.y),d=new Set([l,u,(l+u)/2]);for(let e=l;e<=u+J;e+=12)d.add(Math.min(e,u));let f=t?e.labelHeight/2:e.labelWidth/2;for(let n of d){let o=Math.abs(n-(t?s.x:s.y));for(let c of[-1,1])for(let l of[0,12,24,48,72]){let u=f+8+l,d=t?{x:n,y:s.y}:{x:s.x,y:n},p=t?{x:n,y:s.y+c*u}:{x:s.x+c*u,y:n},m=t?{x:n,y:p.y-c*(e.labelHeight/2)}:{x:p.x-c*(e.labelWidth/2),y:n},h=_n(p,e.labelWidth,e.labelHeight),g=_n(p,e.labelWidth,e.labelHeight,8);g.left<0||g.top<0||g.right>e.width||g.bottom>e.height||e.cardRects.some(e=>Y(g,e))||e.labelRects.some(e=>Y(g,e))||e.routed.some(e=>An(h,e))||e.cardRects.some(e=>yn(d,m,e))||e.labelRects.some(e=>yn(d,m,e))||i.push({center:p,leaderPoints:hn(d)===hn(m)?[]:[d,m],score:l*4+Math.abs(a+o-r/2)})}}a+=n[o]}return i.sort((e,t)=>e.score-t.score||e.center.y-t.center.y||e.center.x-t.center.x),i[0]??null}function Nn(e){let t=e.height-12,n={x:12,y:t},r={x:e.width-12,y:t},i=new Map,a=new Map,o=t=>{let r=i.get(t.id);if(r)return r;let a=Dn(t,12),o=X({starts:a.map(({escape:e})=>e),targets:[n],obstacles:e.cardObstacles,routed:[],width:e.width,height:e.height});if(!o)return null;let s=a.find(({escape:e})=>hn(e)===hn(o.start));if(!s)return null;let c={points:En([s.port,...o.points])};return i.set(t.id,c),c},s=t=>{let n=a.get(t.id);if(n)return n;let i=Dn(t,12),o=X({starts:[r],targets:i.map(({escape:e})=>e),obstacles:e.cardObstacles,routed:[],width:e.width,height:e.height});if(!o)return null;let s=i.find(({escape:e})=>hn(e)===hn(o.target));if(!s)return null;let c={points:En([...o.points,s.port])};return a.set(t.id,c),c},c=e.height,l=[];for(let t of e.relations){let i=e.cardById.get(t.fromCardId),a=e.cardById.get(t.toCardId);if(!i||!a||i.id===a.id)continue;let u=o(i),d=s(a);if(!u||!d)return null;let f=c+16+t.labelHeight/2+12;c=f+t.labelHeight/2+16;let p={x:(n.x+r.x)/2,y:f};l.push({id:t.id,points:En([...u.points,{x:n.x,y:f},{x:r.x,y:f},...d.points]),labelCenter:p,labelPlacement:`shelf`,labelLeaderPoints:[]})}return{width:e.width,height:c,routes:l}}function Pn(e){let t=[...e.cards].sort((e,t)=>q(e.id,t.id)),n=new Map(t.map(e=>[e.id,e])),r=t.map(e=>gn(e)),i=t.map(e=>gn(e,12)),a=e.width,o=e.height,s=[...e.relations].sort((e,t)=>(e.priority??0)-(t.priority??0)||q(e.id,t.id));if(s.length>pn||t.length*s.length>mn){let e=Nn({relations:s,cardById:n,cardObstacles:i,width:a,height:o});if(e)return e}let c=[],l=[];for(let e of s){let t=n.get(e.fromCardId),r=n.get(e.toCardId);if(!t||!r||t.id===r.id)continue;let s=Dn(t,12),u=Dn(r,12),d=X({starts:s.map(({escape:e})=>e),targets:u.map(({escape:e})=>e),obstacles:i,routed:l,width:a,height:o});if(!d)continue;let f=s.find(({escape:e})=>hn(e)===hn(d.start)),p=u.find(({escape:e})=>hn(e)===hn(d.target)),m=En([f.port,...d.points,p.port]);c.push({relation:e,sourceEndpoints:s,targetEndpoints:u,points:m}),l.push({points:m})}let u=[],d=[];for(let e of c){let{relation:t,sourceEndpoints:n,targetEndpoints:s}=e,l=c.filter(t=>t!==e).map(({points:e})=>({points:e})),f=e.points,p=jn({points:f,labelWidth:t.labelWidth,labelHeight:t.labelHeight,cardRects:r,labelRects:d,routed:l,width:a,height:o}),m=`route`,h=[];if(!p){let e=Mn({points:f,labelWidth:t.labelWidth,labelHeight:t.labelHeight,cardRects:r,labelRects:d,routed:l,width:a,height:o});e&&(p=e.center,m=`offset`,h=e.leaderPoints)}if(!p){let r=o+16+t.labelHeight/2+12,c=r+t.labelHeight/2+16,u={x:12,y:r},g={x:a-12,y:r},_=[...i,...d],v=X({starts:n.map(({escape:e})=>e),targets:[u],obstacles:_,routed:l,width:a,height:c,extraY:[r]}),y=X({starts:[g],targets:s.map(({escape:e})=>e),obstacles:_,routed:l,width:a,height:c,extraY:[r]});if(v&&y){let t=n.find(({escape:e})=>hn(e)===hn(v.start)),i=s.find(({escape:e})=>hn(e)===hn(y.target));f=En([t.port,...v.points,g,...y.points,i.port]),p={x:(u.x+g.x)/2,y:r},m=`shelf`,h=[],o=c,e.points=f}}p||=f[Math.floor(f.length/2)],d.push(_n(p,t.labelWidth,t.labelHeight,8)),u.push({id:t.id,points:f,labelCenter:p,labelPlacement:m,labelLeaderPoints:h})}return{width:a,height:o,routes:u}}var Fn=class extends Error{code;constructor(e){super(e),this.code=e,this.name=`StructureExportError`}},In=48,Ln=2,Rn=16384,zn=32e6,Bn=.5,Vn=`ui-monospace, SFMono-Regular, Consolas, Liberation Mono, monospace`,Hn=`Arial, Helvetica Neue, sans-serif`,Un=[`default`,`added`,`modified`,`deleted`,`renamed`,`type-changed`,`mixed`],Wn={background:`--bg`,panel:`--panel`,text:`--text`,muted:`--muted`,line:`--line`,lineStrong:`--line-strong`,accent:`--accent`,success:`--success`,attention:`--attention`,danger:`--danger`,done:`--done`,info:`--info`};function Gn(e){let t=getComputedStyle(e);return Object.fromEntries(Object.entries(Wn).map(([e,n])=>{let r=t.getPropertyValue(n).trim();if(!r)throw new Fn(`INVALID_BOUNDS`);return[e,r]}))}function Kn(e){let t=``;for(let n of e){let e=n.codePointAt(0);(e===9||e===10||e===13||e>=32&&e<=55295||e>=57344&&e<=65533||e>=65536&&e<=1114111)&&(t+=n)}return t}function Z(e){return Kn(e).replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`).replaceAll(`'`,`&apos;`)}function Q(e){if(!Number.isFinite(e))throw new Fn(`INVALID_BOUNDS`);return Number(e.toFixed(3)).toString()}function qn(e,t,n){switch(e){case`added`:return t.success;case`modified`:case`mixed`:return t.attention;case`deleted`:return t.danger;case`renamed`:return t.done;case`type-changed`:return t.info;default:return n}}function Jn(e){let t=e.anchor??`start`;return`<text x="${Q(e.x)}" y="${Q(e.firstY)}" fill="${Z(e.fill)}" font-family="${Z(e.fontFamily)}" font-size="${Q(e.fontSize)}"${e.fontWeight?` font-weight="${e.fontWeight}"`:``} text-anchor="${t}">${e.lines.map((t,n)=>`<tspan x="${Q(e.x)}" dy="${n===0?`0`:Q(e.lineHeight)}">${Z(t)}</tspan>`).join(``)}</text>`}function Yn(e){let{node:t,point:n}=e;switch(t.notation){case`database`:return{x:n.x+10,y:n.y+21,width:208,height:84};case`component`:return{x:n.x+22,y:n.y+6,width:198,height:100};case`external`:return{x:n.x+18,y:n.y+6,width:192,height:100};case`concept`:return{x:n.x+24,y:n.y+12,width:180,height:94};default:return{x:n.x+8,y:n.y+6,width:212,height:100}}}function Xn(e,t,n){let{node:r,point:i}=e,a=i.x,o=i.y,s=`fill="${Z(n.panel)}" stroke="${Z(t)}" stroke-width="1.4"`;switch(r.notation){case`class`:case`interface`:return`<rect x="${Q(a)}" y="${Q(o)}" width="228" height="112" rx="2" ${s}${r.notation===`interface`?` stroke-dasharray="5 3"`:``}/>`;case`database`:{let e=a,n=a+228,r=o+10;return`<rect x="${Q(e)}" y="${Q(o)}" width="228" height="112" rx="${Q(114)}" ry="${Q(15.680000000000001)}" ${s}/><path d="M ${Q(e)} ${Q(r)} C ${Q(e)} ${Q(o+23)}, ${Q(n)} ${Q(o+23)}, ${Q(n)} ${Q(r)}" fill="none" stroke="${Z(t)}" stroke-width="1.2"/>`}case`component`:return`<rect x="${Q(a)}" y="${Q(o)}" width="228" height="112" rx="3" ${s}/><rect x="${Q(a+2)}" y="${Q(o+36)}" width="13" height="8" ${s}/><rect x="${Q(a+2)}" y="${Q(o+52)}" width="13" height="8" ${s}/>`;case`external`:return`<polygon points="${Q(a+20.52)},${Q(o)} ${Q(a+228*.91)},${Q(o)} ${Q(a+228)},${Q(o+56)} ${Q(a+228*.91)},${Q(o+112)} ${Q(a+20.52)},${Q(o+112)} ${Q(a)},${Q(o+56)}" ${s}/>`;case`concept`:return`<rect x="${Q(a)}" y="${Q(o)}" width="228" height="112" rx="56" ${s}/>`;default:return`<rect x="${Q(a)}" y="${Q(o)}" width="228" height="112" rx="8" ${s}/>`}}function Zn(e,t,n,r,i){let{node:a,point:o}=e,s=qn(e.changeKind,n,n.lineStrong),c=Yn(e),l=e.sourceLabel?It({text:e.sourceLabel,maxUnits:c.width/10,maxLines:1,ellipsize:!0}):[],u=l.length>0?17:0,d=l.length>0?3:4,f=It({text:a.label,maxUnits:c.width/11,maxLines:d,ellipsize:!0}),p=14.5,m=Math.max(1,f.length)*p,h=c.y+u+m+3,g=12.6,_=Math.max(0,Math.floor((c.y+c.height-h)/g)),v=_>0?It({text:a.description??`Producerによる説明なし`,maxUnits:c.width/9,maxLines:_,ellipsize:!0}):[],y=a.notation===`class`||a.notation===`interface`?`<line x1="${Q(c.x)}" y1="${Q(h-2)}" x2="${Q(c.x+c.width)}" y2="${Q(h-2)}" stroke="${Z(s)}" stroke-width="1"/>`:``,b=(()=>{switch(a.notation){case`external`:return{x:o.x+22,top:o.y+16,bottom:o.y+112-16};case`concept`:return{x:o.x+20,top:o.y+24,bottom:o.y+112-24};case`database`:return{x:o.x+5,top:o.y+18,bottom:o.y+112-18};case`component`:return{x:o.x+18,top:o.y+10,bottom:o.y+112-10};default:return{x:o.x+4,top:o.y+10,bottom:o.y+112-10}}})(),x=a.id===t.originNodeId?`<line data-node-origin-mark="true" x1="${Q(b.x)}" y1="${Q(b.top)}" x2="${Q(b.x)}" y2="${Q(b.bottom)}" stroke="${Z(n.accent)}" stroke-width="4" stroke-linecap="round"/>`:``,S=r?.primaryBackboneNodeIds.has(a.id)??!1,C=S?`<line data-node-primary-backbone-mark="true" x1="${Q(o.x+18)}" y1="${Q(o.y+3)}" x2="${Q(o.x+228-18)}" y2="${Q(o.y+3)}" stroke="${Z(n.accent)}" stroke-width="3" stroke-linecap="round" opacity="0.58"/>`:``,w=t.presentation?.startNodeId===a.id,ee=w?`<circle data-node-presentation-start-mark="true" cx="${Q(o.x+228-11)}" cy="${Q(o.y+11)}" r="5" fill="${Z(n.accent)}"/>`:``,T=r?.regions.find(e=>e.nodeIds.includes(a.id)),te=l.length>0?Jn({lines:l,x:c.x,firstY:c.y+10,lineHeight:12,fontSize:10,fontFamily:Vn,fill:n.muted,fontWeight:600}):``,ne=c.y+u+10,re=Jn({lines:f,x:c.x,firstY:ne,lineHeight:p,fontSize:11,fontFamily:Vn,fill:n.text,fontWeight:700}),ie=v.length>0?Jn({lines:v,x:c.x,firstY:h+9,lineHeight:g,fontSize:9,fontFamily:Hn,fill:n.muted}):``,ae=[a.id===t.originNodeId?`Factual graph origin`:null,w?`Authorial presentation start`:null,S?`Explanation backbone member`:null,T?`Region ${i.get(T.id)??T.id}: ${T.label}. ${T.summary}`:null].filter(e=>e!==null).join(`
6
+ `);return`<g data-node-id="${Z(a.id)}" data-node-notation="${Z(a.notation)}"${a.id===t.originNodeId?` data-origin-node="true"`:``}${w?` data-presentation-start-node="true"`:``}${S?` data-primary-backbone="true"`:``}${T?` data-presentation-region-id="${Z(T.id)}"`:``}${e.changeKind?` data-source-change-kind="${Z(e.changeKind)}"`:``}>${Xn(e,s,n)}${x}${C}${ee}<g data-node-content="true">${te}${re}${y}${ie}</g><title>${Z(a.label)}</title><desc>${Z(`${a.description??``}${ae?`\n${ae}`:``}`)}</desc></g>`}function Qn(e,t){let n=e.nodes.length===t.nodes.length&&e.edges.length===t.edges.length&&e.labels.length===t.edges.length&&e.bounds!==null,r=e.bounds?[e.bounds.left,e.bounds.top,e.bounds.right,e.bounds.bottom].every(Number.isFinite):!1;if(!n||!r)throw new Fn(`INCOMPLETE_LAYOUT`)}function $n(e,t,n){if(!e.leaderPath||!e.leaderEdgeAnchor)return``;let r=qn(e.source.changeKind,t,t.accent);return`<g data-edge-label-leader-id="${Z(e.edge.id)}"${n?` data-primary-backbone="true"`:``}><path data-edge-label-leader-halo="true" d="${Z(e.leaderPath)}" fill="none" stroke="${Z(t.panel)}" stroke-width="4" stroke-linecap="round" opacity="0.94"/><path data-edge-label-leader-line="true" d="${Z(e.leaderPath)}" fill="none" stroke="${Z(t.muted)}" stroke-width="1.1" stroke-linecap="round" stroke-dasharray="1 4" opacity="0.72"/><circle data-edge-label-leader-anchor="true" cx="${Q(e.leaderEdgeAnchor.x)}" cy="${Q(e.leaderEdgeAnchor.y)}" r="2.5" fill="${Z(r)}" stroke="${Z(t.panel)}" stroke-width="1"/></g>`}function er(e,t,n){let r=qn(e.source.changeKind,t,t.accent),i=e.displayLines,a=-((i.length-1)*14)/2+3.5;return`<g data-edge-label-id="${Z(e.edge.id)}" transform="translate(${Q(e.x)} ${Q(e.y)})"${n?` data-primary-backbone="true"`:``}${e.crowded?` data-crowded="true"`:``}${e.displaced?` data-displaced="true"`:``}><rect x="${Q(-e.selectWidth/2)}" y="${Q(-e.height/2)}" width="${Q(e.selectWidth)}" height="${Q(e.height)}" rx="${Q(e.height/2)}" fill="${Z(t.panel)}" stroke="${Z(r)}" stroke-width="${n?`1.4`:`1`}"${e.crowded?` stroke-dasharray="4 3"`:``}/>${Jn({lines:i,x:0,firstY:a,lineHeight:14,fontSize:10,fontFamily:Hn,fill:r,anchor:`middle`})}<title>${Z(e.edge.label)}</title></g>`}function tr(e,t,n){let r=new Map(e.nodes.map(({node:e,point:t})=>[e.id,t]));return(e.presentation?.regions??[]).flatMap(e=>e.nodeIds.flatMap(i=>{let a=r.get(i);if(!a)return[];let o=n.get(e.id)??e.id,s=a.x+228-34,c=a.y-14;return[`<g data-presentation-region-id="${Z(e.id)}" data-presentation-region-label="${Z(e.label)}" data-presentation-region-member-node-id="${Z(i)}"><rect x="${Q(s)}" y="${Q(c)}" width="34" height="15" rx="7.5" fill="${Z(t.panel)}" stroke="${Z(t.accent)}" stroke-opacity="0.55"/><text x="${Q(s+17)}" y="${Q(c+10.5)}" text-anchor="middle" fill="${Z(t.accent)}" font-family="${Vn}" font-size="7" font-weight="700">${Z(o)}</text><title>${Z(`Region ${o}: ${e.label}. ${e.summary}`)}</title></g>`]})).join(``)}function nr(e){let t=$t(e.regions),n=e=>`${e} ${e===1?`Edge`:`Edges`}`,r=e.directRelations.flatMap(e=>{let r=t.get(e.regionIds[0]),i=t.get(e.regionIds[1]);return!r||!i?[]:[...e.directions.fromFirstRegionEdgeIds.length>0?[`${r} → ${i} (${n(e.directions.fromFirstRegionEdgeIds.length)})`]:[],...e.directions.fromSecondRegionEdgeIds.length>0?[`${i} → ${r} (${n(e.directions.fromSecondRegionEdgeIds.length)})`]:[],...e.directions.undirectedEdgeIds.length>0?[`${r} — ${i} (${n(e.directions.undirectedEdgeIds.length)})`]:[]]});return r.length>0?`DIRECT REGION CONNECTIONS · ${r.join(` · `)}`:null}function rr(e){return e??`default`}function ir(e){return`rvw-structure-arrow-${e}`}function ar(e,t){return qn(e==="default"?null:e,t,t.muted)}function or(e){return Un.map(t=>{let n=ar(t,e);return`<marker id="${ir(t)}" data-edge-marker-kind="${t}" viewBox="0 0 12 10" refX="12" refY="5" markerWidth="12" markerHeight="10" orient="auto" markerUnits="userSpaceOnUse"><path d="M 0 0 L 12 5 L 0 10 z" fill="${Z(n)}"/></marker>`}).join(``)}function sr(e){let{structure:t,model:n,palette:r}=e;Qn(n,t);let i=n.bounds,a=i.right-i.left,o=n.presentation?Math.max(360,Math.min(960,a)):0,s=n.presentation?It({text:n.presentation.thesis,maxUnits:Math.max(12,(o-28)/9.5),ellipsize:!1}):[],c=n.presentation?.primaryBackboneEdgeIds.size??0,l=nn(t),u=l?.regions??[],d=$t(u),f=l?nr(l):null,p=t.presentation?[`START · ${t.nodes.find(({id:e})=>e===t.presentation.startNodeId)?.label??t.presentation.startNodeId}`,...c>0?[`BACKBONE · ${c} exact ${c===1?`relation`:`relations`} highlighted`]:[],...u.length>0?[`REGIONS · ${u.map(e=>`${d.get(e.id)??e.id} ${e.label} (${e.nodeCount} ${e.nodeCount===1?`Node`:`Nodes`}) — ${e.summary}`).join(` · `)}`]:[],...f?[f]:[]].join(`
7
+ `):``,m=n.presentation?It({text:p,maxUnits:Math.max(12,(o-28)/9.5),ellipsize:!1}):[],h=n.presentation?34+s.length*15+(m.length>0?13+m.length*13:0):0,g=i.left,_=i.top-h-24,v=Math.floor(Math.min(i.left,g)-In),y=Math.floor(Math.min(i.top,_)-In),b=Math.ceil(Math.max(i.right,g+o)+In),x=Math.ceil(i.bottom+In),S=b-v,C=x-y;if(![v,y,S,C].every(Number.isFinite)||S<=0||C<=0)throw new Fn(`INVALID_BOUNDS`);let w=n.edges.map(({edge:e,geometry:t,source:i})=>{let a=rr(i.changeKind),o=ar(a,r),s=n.presentation?.primaryBackboneEdgeIds.has(e.id)??!1,c=s?`0.82`:i.changeKind?`0.76`:`0.58`,l=`<path data-edge-id="${Z(e.id)}"${s?` data-primary-backbone="true"`:``}${e.directed?` data-arrow-base-x="${Q(t.arrowBaseX)}" data-arrow-base-y="${Q(t.arrowBaseY)}" data-arrow-tangent-x="${Q(t.arrowTangentX)}" data-arrow-tangent-y="${Q(t.arrowTangentY)}"`:``} d="${Z(e.directed?t.strokePath:t.path)}" fill="none" stroke="${Z(o)}" stroke-width="${s?`2`:`1.4`}" opacity="${c}"/>`;return e.directed?`${l}${`<path data-edge-arrow-id="${Z(e.id)}" d="${Z(t.arrowPath)}" fill="none" stroke="${Z(o)}" stroke-width="0" opacity="${c}" marker-end="url(#${ir(a)})"/>`}`:l}).join(``),ee=n.labels.map(e=>er(e,r,n.presentation?.primaryBackboneEdgeIds.has(e.edge.id)??!1)).join(``),T=n.labels.map(e=>$n(e,r,n.presentation?.primaryBackboneEdgeIds.has(e.edge.id)??!1)).join(``),te=n.nodes.map(e=>Zn(e,t,r,n.presentation,d)).join(``),ne=tr(n,r,d),re=n.presentation?`<g data-layer="presentation-thesis" data-presentation-thesis="true"><rect x="${Q(g)}" y="${Q(_)}" width="${Q(o)}" height="${Q(h)}" rx="10" fill="${Z(r.panel)}" stroke="${Z(r.lineStrong)}" stroke-width="1"/>${Jn({lines:[`THESIS`],x:g+14,firstY:_+17,lineHeight:11,fontSize:8,fontFamily:Vn,fill:r.accent,fontWeight:700})}${Jn({lines:s,x:g+14,firstY:_+36,lineHeight:15,fontSize:11,fontFamily:Hn,fill:r.text})}${Jn({lines:m,x:g+14,firstY:_+36+s.length*15+9,lineHeight:13,fontSize:9,fontFamily:Vn,fill:r.muted,fontWeight:600})}</g>`:``,ie=n.presentation?`${t.scope}\nThesis: ${n.presentation.thesis}\n${p}`:t.scope,ae=n.presentation?re:``,oe=n.presentation&&n.presentation.regions.length>0?`<g data-layer="presentation-region-members">${ne}</g>`:``;return{source:`<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="${S}" height="${C}" viewBox="${v} ${y} ${S} ${C}" role="img" aria-labelledby="rvw-structure-title rvw-structure-description" data-rvw-structure-id="${Z(t.id)}" data-rvw-source-oid="${Z(t.sourceOid)}"><title id="rvw-structure-title">${Z(t.title)}</title><desc id="rvw-structure-description">${Z(ie)}</desc><defs>${or(r)}</defs><rect x="${v}" y="${y}" width="${S}" height="${C}" fill="${Z(r.background)}"/>${ae}<g data-layer="edges">${w}</g><g data-layer="edge-label-leaders">${T}</g><g data-layer="edge-labels">${ee}</g><g data-layer="nodes">${te}</g>${oe}</svg>`,width:S,height:C,viewBox:{x:v,y,width:S,height:C}}}function cr(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)throw new Fn(`INVALID_BOUNDS`);let n=Math.min(Ln,Rn/e,Rn/t,Math.sqrt(zn/(e*t)));if(!Number.isFinite(n)||n<Bn)throw new Fn(`PNG_TOO_LARGE`);return{scale:n,pixelWidth:Math.max(1,Math.floor(e*n)),pixelHeight:Math.max(1,Math.floor(t*n)),downscaled:n<Ln}}function lr(e,t){return e.source.replace(/(<svg\b[^>]*\bwidth=")[^"]*(")/u,`$1${t.pixelWidth}$2`).replace(/(<svg\b[^>]*\bheight=")[^"]*(")/u,`$1${t.pixelHeight}$2`)}async function ur(e,t){let n=new Blob([lr(e,t)],{type:`image/svg+xml;charset=utf-8`}),r=URL.createObjectURL(n);try{let e=new Image;e.decoding=`async`,await new Promise((t,n)=>{e.onload=()=>t(),e.onerror=()=>n(new Fn(`PNG_DECODE_FAILED`)),e.src=r});let n=window.document.createElement(`canvas`);n.width=t.pixelWidth,n.height=t.pixelHeight;let i=n.getContext(`2d`);if(!i)throw new Fn(`PNG_ENCODE_FAILED`);return i.drawImage(e,0,0,t.pixelWidth,t.pixelHeight),await new Promise((e,t)=>{n.toBlob(n=>n?e(n):t(new Fn(`PNG_ENCODE_FAILED`)),`image/png`)})}finally{URL.revokeObjectURL(r)}}function dr(e,t){return`rvw-structure-${[...Kn(e.title).replace(/[<>:"\\|?*]+|\//gu,`-`).replace(/\s+/gu,`-`).replace(/-+/gu,`-`).replace(/^[.\s-]+|[.\s-]+$/gu,``)].slice(0,80).join(``)||`structure`}-${e.sourceOid.slice(0,8)}.${t}`}function fr(e,t){let n=URL.createObjectURL(e),r=window.document.createElement(`a`);r.href=n,r.download=t,r.style.display=`none`,window.document.body.append(r),r.click(),r.remove(),window.setTimeout(()=>URL.revokeObjectURL(n),0)}function pr(e){if(e instanceof Fn)switch(e.code){case`INCOMPLETE_LAYOUT`:return`Structure全体の配置を構築できませんでした。レイアウトを戻して再実行してください。`;case`PNG_TOO_LARGE`:return`図がPNGの安全なサイズを超えています。SVGを使用するか、Node配置を近づけてから再実行してください。`;case`PNG_DECODE_FAILED`:return`Structure SVGをPNGへ変換できませんでした。SVG形式で再実行してください。`;case`PNG_ENCODE_FAILED`:return`PNGファイルを生成できませんでした。SVG形式で再実行してください。`;case`INVALID_BOUNDS`:return`Structureの出力範囲を計算できませんでした。`}return e instanceof Error?e.message:`Structureをエクスポートできませんでした。`}var mr=3,hr=24,gr={distant:{1:32,2:24},"leader-overlap":{1:44,2:32},"label-route-overlap":{1:52,2:40},emergency:{1:72,2:56}};function _r(e,t){return e===t?0:e<t?-1:1}function vr(e){switch(e){case`emergency`:return 4;case`label-route-overlap`:return 3;case`leader-overlap`:return 2;case`distant`:return 1;case null:return 0}}function yr(e,t,n){let r=[],i={x:0,y:0},a=[...n].sort((e,t)=>vr(t.diagnostics.fallbackReason)-vr(e.diagnostics.fallbackReason)||t.diagnostics.edgeDistance-e.diagnostics.edgeDistance||t.diagnostics.maxParallelOverlap-e.diagnostics.maxParallelOverlap||t.diagnostics.leaderLength-e.diagnostics.leaderLength||_r(e.edge.id,t.edge.id)),o=new Set(e.edges.map(({id:e})=>e));for(let{edge:e,diagnostics:n}of a){if(!o.has(e.id))continue;let a=t[e.from],s=t[e.to];if(!a||!s||a.x===s.x&&a.y===s.y)continue;let c=Math.abs(s.x-a.x)>=Math.abs(s.y-a.y)?`x`:`y`;if(i[c]>=mr)continue;let l=(a[c]+s[c])/2,u=n.fallbackReason??`distant`,d=r.find(e=>e.axis===c&&Math.abs(e.coordinate-l)<hr);if(d){vr(u)>vr(d.fallbackReason)&&(d.fallbackReason=u);continue}r.push({axis:c,coordinate:l,fallbackReason:u}),i[c]+=1}return r}function br(e,t,n,r){return t.reduce((t,i)=>{if(i.axis!==n||e===i.coordinate)return t;let a=gr[i.fallbackReason][r];return t+(e<i.coordinate?-a/2:a/2)},0)}function xr(e,t,n){let r=e.nodes.flatMap(({id:e})=>{let r=t[e];return r?[r[n]]:[]});return r.length===0?0:Math.max(...r)-Math.min(...r)}function Sr(e,t,n,r,i,a){let o=xr(e,t,a),s=xr(e,n,a),c=Math.max(o,xr(e,r,a)-i);return s<=c||s<=o?1:Math.max(0,Math.min(1,(c-o)/(s-o)))}function Cr({structure:e,anchorNodeId:t,attempt:n,positions:r,pressureLabels:i,maximumExtentPositions:a,minimumExtentReduction:o=0}){let s=yr(e,r,i);if(s.length===0)return null;let c=(t&&r[t]?t:null)??(e.originNodeId&&r[e.originNodeId]?e.originNodeId:e.nodes.find(({id:e})=>r[e])?.id??null),l=c?r[c]:void 0,u=l?{x:br(l.x,s,`x`,n),y:br(l.y,s,`y`,n)}:{x:0,y:0},d=Object.fromEntries(e.nodes.flatMap(({id:e})=>{let t=r[e];return t?[[e,{x:t.x+br(t.x,s,`x`,n)-u.x,y:t.y+br(t.y,s,`y`,n)-u.y}]]:[]}));if(!a)return d;let f=Sr(e,r,d,a,o,`x`),p=Sr(e,r,d,a,o,`y`);return f===1&&p===1?d:Object.fromEntries(e.nodes.flatMap(({id:e})=>{let t=r[e],n=d[e];return!t||!n?[]:[[e,{x:t.x+(n.x-t.x)*f,y:t.y+(n.y-t.y)*p}]]}))}function wr(e){return e.startLine===null?e.path:`${e.path}:${e.startLine}${e.endLine===e.startLine?``:`-${e.endLine}`}`}var $=t();function Tr({disabled:e,exporting:t,onExport:n}){let r=(0,E.useRef)(null),i=e=>{r.current?.removeAttribute(`open`),n(e)};return(0,$.jsxs)(`details`,{className:`structure-export-menu`,ref:r,children:[(0,$.jsxs)(`summary`,{className:`structure-header-action`,"aria-label":`Structureをエクスポート`,"aria-disabled":e,onClick:t=>{e&&t.preventDefault()},children:[t?`${t.toUpperCase()}…`:`Export`,(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`▾`})]}),(0,$.jsxs)(`div`,{className:`structure-export-popover`,children:[(0,$.jsxs)(`button`,{type:`button`,disabled:e,onClick:()=>i(`svg`),children:[(0,$.jsx)(`strong`,{children:`SVG`}),(0,$.jsx)(`span`,{children:`全体・ベクター`})]}),(0,$.jsxs)(`button`,{type:`button`,disabled:e,onClick:()=>i(`png`),children:[(0,$.jsx)(`strong`,{children:`PNG`}),(0,$.jsx)(`span`,{children:`全体・2×`})]}),(0,$.jsx)(`p`,{children:`現在の配置で、全Node・全Relation・全Edge labelを書き出します。`})]})]})}function Er(e,t){return{id:e.id,label:e.label,isStart:e.id===t}}function Dr(e){let t=e.presentation;if(!t)return null;let n=e.nodes.find(e=>e.id===t.startNodeId);return n?{thesis:t.thesis,startNode:Er(n,t.startNodeId)}:null}function Or({node:e,focused:t,onFocusNode:n}){return(0,$.jsxs)(`button`,{type:`button`,className:`structure-presentation-overview-node compact`,"data-node-id":e.id,"data-authorial-start":`true`,"data-focused":t?`true`:void 0,"aria-label":`${e.label}. Authorial start node. Open this node and its one-hop context in Graph.`,"aria-pressed":t,onClick:()=>n(e.id),children:[(0,$.jsx)(`span`,{className:`structure-presentation-overview-start`,children:`Start`}),(0,$.jsx)(`span`,{children:e.label})]})}function kr({structure:e,focusedNodeId:t,disclosure:n,onToggleDisclosure:r,onFocusNode:i}){let a=Dr(e);return a?(0,$.jsxs)(`section`,{className:`structure-presentation-overview`,"aria-label":`Authorial Structure guide`,children:[(0,$.jsxs)(`div`,{className:`structure-presentation-guide-header`,children:[(0,$.jsx)(`strong`,{children:`Guide`}),(0,$.jsx)(Or,{node:a.startNode,focused:t===a.startNode.id,onFocusNode:i}),(0,$.jsxs)(`button`,{type:`button`,className:`structure-presentation-guide-toggle`,"aria-expanded":n.thesis,onClick:()=>r(`thesis`),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:n.thesis?`▾`:`▸`}),`Thesis`]})]}),n.thesis&&(0,$.jsxs)(`div`,{className:`structure-presentation-guide-section structure-presentation-overview-thesis`,role:`note`,"aria-label":`Structure thesis`,children:[(0,$.jsx)(`strong`,{children:`Thesis`}),(0,$.jsx)(`span`,{children:a.thesis})]})]}):null}var Ar=210,jr=104,Mr=62,Nr=112,Pr=48;function Fr(e){return`region:${JSON.stringify(e.regionIds)}`}function Ir(e){return`context:${JSON.stringify([e.regionId,e.contextId])}`}function Lr(e){return 16+e.length*15}function Rr(e,t){return e===t?0:e<t?-1:1}function zr(e,t,n,r){if(t.contexts.length===0)return{contexts:[],width:e.width,height:e.height};let i=Math.max(e.columnCount,Math.min(4,Math.ceil(Math.sqrt(t.contexts.length)))),a=Math.ceil(t.contexts.length/i),o=new Map(e.regions.map(({regionId:e,column:t})=>[e,t])),s=[...t.contexts].sort((e,t)=>Number(t.nodeIds.includes(n))-Number(e.nodeIds.includes(n))||Number(t.backboneEdgeIds.length>0)-Number(e.backboneEdgeIds.length>0)||Rr(e.id,t.id)),c=Array.from({length:a*i},(e,t)=>({column:t%i,row:Math.floor(t/i)}));return{contexts:s.map(t=>{let n=t.adjacentRegionIds.flatMap(e=>{let t=o.get(e);return t===void 0?[]:[t]}),a=n.length>0?n.reduce((e,t)=>e+t,0)/n.length:(i-1)/2,s=[...c].sort((e,t)=>e.row-t.row||Math.abs(e.column-a)-Math.abs(t.column-a)||e.column-t.column)[0];return c.splice(c.findIndex(({column:e,row:t})=>e===s.column&&t===s.row),1),{contextId:t.id,...s,center:{x:s.column*504+116,y:e.height+r+s.row*166+jr/2}}}),width:Math.max(e.width,i*232+Math.max(0,i-1)*272),height:e.height+r+a*jr+Math.max(0,a-1)*Mr}}function Br(e){let t=nn(e);if(!t||t.regions.length===0)return null;let n=an(t),r=new Map(e.edges.map(e=>[e.id,e.label])),i=new Map(t.regions.map(e=>[e.id,e.label])),a=new Map(t.directRelations.map(e=>[Fr(e),qr(e,r,i)])),o=new Map(n.boundaryRelations.map(e=>[Ir(e),Jr(e,r,i)])),s=[...a.values(),...o.values()].map(({lines:e})=>e.length),c=16+Math.max(1,...s)*15,l=Hr(cn(t),272,Math.max(76,c+72)),u=zr(l,n,e.presentation.startNodeId,Math.max(Nr,c+24)),d=Pn({cards:[...l.regions.map(e=>({id:`region:${e.regionId}`,center:{x:e.center.x+Pr,y:e.center.y+Pr},width:232,height:176})),...u.contexts.map(e=>({id:`context:${e.contextId}`,center:{x:e.center.x+Pr,y:e.center.y+Pr},width:Ar,height:jr}))],relations:[...t.directRelations.map(e=>{let t=Fr(e);return{id:t,fromCardId:`region:${e.regionIds[0]}`,toCardId:`region:${e.regionIds[1]}`,labelWidth:200,labelHeight:Lr(a.get(t).lines),priority:0}}),...n.boundaryRelations.map(e=>{let t=Ir(e);return{id:t,fromCardId:`region:${e.regionId}`,toCardId:`context:${e.contextId}`,labelWidth:200,labelHeight:Lr(o.get(t).lines),priority:1}})],width:u.width+96,height:u.height+96}),f=new Set(t.regions.flatMap(e=>e.nodeIds));return{regionOverview:t,regionLayout:l,contextSurface:n,contextLayouts:u.contexts,relationRoutes:d.routes,width:d.width,height:d.height,assignedNodeCount:f.size,unassignedNodeCount:Math.max(0,e.nodes.length-f.size)}}function Vr(e,t){let n=e.presentation?.startNodeId;if(!n)return null;let r=t.regionLayout.regions.find(({regionId:e})=>e===t.regionOverview.startRegionId);if(r){let e=r.center.x+Pr,t=r.center.y+Pr;return{left:e-116,top:t-88,right:e+116,bottom:t+88}}let i=t.contextSurface.contexts.find(({nodeIds:e})=>e.includes(n))?.id,a=t.contextLayouts.find(({contextId:e})=>e===i);if(!a)return null;let o=a.center.x+Pr,s=a.center.y+Pr;return{left:o-Ar/2,top:s-jr/2,right:o+Ar/2,bottom:s+jr/2}}function Hr(e,t,n){let r=e.regions.map(e=>({...e,center:{x:e.column*(232+t)+116,y:e.row*(176+n)+88}})),i=new Map(r.map(({regionId:e,center:t})=>[e,t]));return{...e,width:e.columnCount*232+Math.max(0,e.columnCount-1)*t,height:e.rowCount*176+Math.max(0,e.rowCount-1)*n,regions:r,directRelations:e.directRelations.map(e=>({...e,firstCenter:i.get(e.regionIds[0]),secondCenter:i.get(e.regionIds[1])}))}}function Ur(e){let t=e.directions.fromFirstRegionEdgeIds.length>0,n=e.directions.fromSecondRegionEdgeIds.length>0;return e.directions.undirectedEdgeIds.length>0&&(t||n)?`mixed`:t&&n?`reciprocal`:t?`first-to-second`:n?`second-to-first`:`undirected`}function Wr(e){let t=e.directions.fromRegionEdgeIds.length>0,n=e.directions.fromUnassignedNodeEdgeIds.length>0;return e.directions.undirectedEdgeIds.length>0&&(t||n)?`mixed`:t&&n?`reciprocal`:t?`region-to-context`:n?`context-to-region`:`undirected`}var Gr=17;function Kr(e){let t=[...new Map(e.map(e=>[JSON.stringify([e.fromLabel,e.symbol,e.toLabel,e.predicate,e.isCore]),e])).values()],n=t.slice(0,3),r=new Map;for(let e of n){let t=JSON.stringify([e.fromLabel,e.symbol,e.toLabel]),n=r.get(t);n?n.push(e):r.set(t,[e])}let i=[...r.values()].flatMap(e=>{let n=e[0];return[...It({text:`${n.fromLabel} ${n.symbol} ${n.toLabel}`,maxUnits:Gr,maxLines:2}),...e.flatMap(e=>It({text:`↳ ${e.isCore?`Core · `:``}${e.predicate}`,maxUnits:Gr,...t.length===1?{}:{maxLines:2}}))]}),a=t.length-n.length;a>0&&i.push(`+${a} more predicates`);let o=e.filter(({isCore:e})=>e).length;return e.length>1&&i.push(`${e.length} exact Edges${o>0?` · Core ${o}/${e.length}`:``}`),{full:e.map(e=>`${e.fromLabel} ${e.symbol} ${e.toLabel}: ${e.predicate}${e.isCore?` (Core)`:``}`).join(` · `),lines:i.length>0?i:[`relation`],edgeCount:e.length,coreEdgeCount:o}}function qr(e,t,n){let[r,i]=e.regionIds,a=n.get(r)??r,o=n.get(i)??i,s=new Set(e.directions.fromFirstRegionEdgeIds),c=new Set(e.directions.fromSecondRegionEdgeIds),l=new Set(e.backboneEdgeIds);return Kr(e.edgeIds.map(e=>s.has(e)?{edgeId:e,fromLabel:a,toLabel:o,symbol:`→`,predicate:t.get(e)??e,isCore:l.has(e)}:c.has(e)?{edgeId:e,fromLabel:o,toLabel:a,symbol:`→`,predicate:t.get(e)??e,isCore:l.has(e)}:{edgeId:e,fromLabel:a,toLabel:o,symbol:`—`,predicate:t.get(e)??e,isCore:l.has(e)}))}function Jr(e,t,n){let r=n.get(e.regionId)??e.regionId,i=new Set(e.directions.fromRegionEdgeIds),a=new Set(e.directions.fromUnassignedNodeEdgeIds),o=new Set(e.backboneEdgeIds);return Kr(e.edgeIds.map(e=>i.has(e)?{edgeId:e,fromLabel:r,toLabel:`Context`,symbol:`→`,predicate:t.get(e)??e,isCore:o.has(e)}:a.has(e)?{edgeId:e,fromLabel:`Context`,toLabel:r,symbol:`→`,predicate:t.get(e)??e,isCore:o.has(e)}:{edgeId:e,fromLabel:r,toLabel:`Context`,symbol:`—`,predicate:t.get(e)??e,isCore:o.has(e)}))}function Yr({label:e}){return(0,$.jsx)(`span`,{className:`structure-region-map-relation-label`,"data-edge-count":e.edgeCount,"data-core-edge-count":e.coreEdgeCount,children:e.lines.map((e,t)=>(0,$.jsx)(`span`,{children:e},`${t}-${e}`))})}function Xr(e,t){let n=t.get(e.from)??e.from,r=t.get(e.to)??e.to;return e.directed?`${n} → ${r}: ${e.label}`:`${n} — ${r}: ${e.label}`}function Zr({edge:e,onOpenEdgeSource:t}){return e.anchors.length===0?(0,$.jsx)(`span`,{className:`structure-region-relation-no-source`,children:`sourceなし`}):(0,$.jsx)(`span`,{className:`structure-region-relation-sources`,children:e.anchors.map((n,r)=>{let i=wr(n);return(0,$.jsxs)(`button`,{type:`button`,className:`structure-region-relation-source`,title:`${i}を開く`,"aria-label":`${e.label}のsource ${i}を開く`,onClick:i=>t(e.id,r,n,i.metaKey||i.ctrlKey),children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`</>`}),(0,$.jsx)(`span`,{children:i})]},`${e.id}:${r}`)})})}function Qr({edges:e,nodeLabelsById:t,onOpenEdge:n,onOpenEdgeSource:r}){return(0,$.jsx)(`ul`,{children:e.map(e=>(0,$.jsxs)(`li`,{"data-edge-id":e.id,children:[(0,$.jsxs)(`code`,{className:`structure-region-relation-edge-id`,children:[`Edge · `,e.id]}),(0,$.jsx)(`button`,{type:`button`,className:`structure-region-relation-edge`,title:`Graphでこのexact Edgeを選択`,onClick:()=>n(e.id),children:Xr(e,t)}),(0,$.jsx)(Zr,{edge:e,onOpenEdgeSource:r})]},e.id))})}function $r(e,t){let n=e.nodeIds.slice(0,2).map(e=>t.get(e)??e),r=e.nodeIds.length-n.length;return`${n.join(` · `)}${r>0?` · +${r}`:``}`}function ei(e){return e.map(({x:e,y:t},n)=>`${n===0?`M`:`L`} ${e} ${t}`).join(` `)}function ti(e){if(e.button!==0)return;e.preventDefault();let t=e.currentTarget.closest(`.structure-regions-canvas-scroll`);t&&(t.scrollLeft=0,t.scrollTop=0)}function ni(e){e.button===0&&e.currentTarget.focus({preventScroll:!0})}function ri({structure:e,model:t,viewport:n={x:0,y:0,scale:1},surfaceRef:r,framedRegionId:i,onOpenRegion:a,onOpenContext:o,onOpenEdge:s,onOpenEdgeSource:c,onPointerDown:l,onPointerMove:u,onPointerUp:d,onPointerCancel:f,onFocusCapture:p,onDoubleClick:m}){let h=`structure-region-${(0,E.useId)().replaceAll(`:`,``)}`,[g,_]=(0,E.useState)(null),v=t??Br(e);if(!v)return null;let{regionOverview:y,regionLayout:b,contextSurface:x}=v,S=new Map(y.regions.map(e=>[e.id,e])),C=new Map(x.contexts.map(e=>[e.id,e])),w=new Map(v.relationRoutes.map(e=>[e.id,e])),ee=new Map(e.edges.map(e=>[e.id,e.label])),T=new Map(e.nodes.map(e=>[e.id,e.label])),te=new Map(y.regions.map(e=>[e.id,e.label])),ne=v.width,re=v.height,ie=[...y.directRelations.map(e=>{let t=S.get(e.regionIds[0])?.label??e.regionIds[0],n=S.get(e.regionIds[1])?.label??e.regionIds[1],r=Ur(e);return{id:Fr(e),edgeIds:e.edgeIds,coreEdgeIds:e.backboneEdgeIds,label:qr(e,ee,te),orientation:r===`first-to-second`?`${t} → ${n}`:r===`second-to-first`?`${n} → ${t}`:r===`undirected`?`${t} — ${n}`:`${t} ↔ ${n}`}}),...x.boundaryRelations.map(e=>{let t=S.get(e.regionId)?.label??e.regionId,n=C.get(e.contextId),r=n?$r(n,T):`unassigned context`,i=Wr(e);return{id:Ir(e),edgeIds:e.edgeIds,coreEdgeIds:e.backboneEdgeIds,label:Jr(e,ee,te),orientation:i===`region-to-context`?`${t} → Context · ${r}`:i===`context-to-region`?`Context · ${r} → ${t}`:i===`undirected`?`${t} — Context · ${r}`:`${t} ↔ Context · ${r}`}})],ae=ie.find(({id:e})=>e===g),oe=(ae?.edgeIds??[]).flatMap(t=>{let n=e.edges.find(e=>e.id===t);return n?[n]:[]});return(0,$.jsxs)(`section`,{className:`structure-regions-canvas`,"aria-label":`${e.title} Regions`,children:[(0,$.jsxs)(`div`,{className:`structure-regions-canvas-intro`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`strong`,{children:`Comprehension Regions`}),(0,$.jsxs)(`span`,{children:[y.regions.length,` Regions · `,v.assignedNodeCount,`/`,e.nodes.length,` Nodes assigned`,v.unassignedNodeCount>0?` · ${x.contexts.length} Context ${x.contexts.length===1?`component`:`components`}`:``]})]}),(0,$.jsx)(`p`,{children:`Connections are exact direct factual Edges. Select a card or relation to inspect its facts.`})]}),(0,$.jsx)(`div`,{ref:r,className:`structure-regions-canvas-scroll`,tabIndex:0,"aria-label":`Regions map。ドラッグまたはホイールで移動、修飾キーとホイールで拡大縮小`,"data-viewport-scale":n.scale.toFixed(3),onPointerDown:l,onPointerMove:u,onPointerUp:d,onPointerCancel:f,onFocusCapture:e=>{e.currentTarget.scrollLeft=0,e.currentTarget.scrollTop=0,p?.(e)},onScroll:e=>{e.currentTarget.scrollLeft=0,e.currentTarget.scrollTop=0},onDoubleClick:m,children:(0,$.jsxs)(`div`,{className:`structure-region-map`,style:{width:ne,height:re,transform:`translate(${n.x}px, ${n.y}px) scale(${n.scale})`},"data-region-count":y.regions.length,"data-context-count":x.contexts.length,"data-direct-relation-count":y.directRelations.length,children:[(0,$.jsxs)(`svg`,{className:`structure-region-map-relations`,width:ne,height:re,viewBox:`0 0 ${ne} ${re}`,"aria-hidden":`true`,children:[(0,$.jsxs)(`defs`,{children:[(0,$.jsx)(`marker`,{id:`${h}-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,$.jsx)(`path`,{className:`structure-region-map-arrowhead`,d:`M 0 0 L 8 4 L 0 8 z`})}),(0,$.jsx)(`marker`,{id:`${h}-core-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,$.jsx)(`path`,{className:`structure-region-map-arrowhead core`,d:`M 0 0 L 8 4 L 0 8 z`})})]}),y.directRelations.map(e=>{let t=w.get(Fr(e));if(!t)return null;let n=Ur(e),r=qr(e,ee,te),i=S.get(e.regionIds[0])?.label??e.regionIds[0],a=S.get(e.regionIds[1])?.label??e.regionIds[1],o=e.backboneEdgeIds.length===e.edgeIds.length?` core`:e.backboneEdgeIds.length>0?` has-core`:``,s=`${h}-${o===` core`?`core-arrow`:`arrow`}`;return(0,$.jsxs)(`g`,{className:`structure-region-map-relation${o}`,"data-direction":n,"data-edge-ids":e.edgeIds.join(` `),"data-core-edge-count":e.backboneEdgeIds.length,children:[(0,$.jsx)(`title`,{children:`${i} ${n} ${a}: ${r.full} (${e.edgeIds.length} exact ${e.edgeIds.length===1?`Edge`:`Edges`})`}),(0,$.jsx)(`path`,{className:`structure-region-map-relation-line`,d:ei(t.points),"data-route-points":t.points.map(({x:e,y:t})=>`${e},${t}`).join(` `),markerStart:e.directions.fromSecondRegionEdgeIds.length>0?`url(#${s})`:void 0,markerEnd:e.directions.fromFirstRegionEdgeIds.length>0?`url(#${s})`:void 0}),t.labelLeaderPoints.length>1&&(0,$.jsx)(`path`,{className:`structure-region-map-label-leader`,d:ei(t.labelLeaderPoints)})]},e.regionIds.join(`:`))}),x.boundaryRelations.map(e=>{let t=w.get(Ir(e));if(!t)return null;let n=Wr(e),r=Jr(e,ee,te),i=S.get(e.regionId)?.label??e.regionId,a=C.get(e.contextId),o=a?$r(a,T):`unassigned context`,s=e.backboneEdgeIds.length===e.edgeIds.length?` core`:e.backboneEdgeIds.length>0?` has-core`:``,c=`${h}-${s===` core`?`core-arrow`:`arrow`}`;return(0,$.jsxs)(`g`,{className:`structure-region-map-relation context-boundary${s}`,"data-direction":n,"data-edge-ids":e.edgeIds.join(` `),"data-core-edge-count":e.backboneEdgeIds.length,children:[(0,$.jsx)(`title`,{children:`${i} ${n} Context ${o}: ${r.full} (${e.edgeIds.length} exact ${e.edgeIds.length===1?`Edge`:`Edges`})`}),(0,$.jsx)(`path`,{className:`structure-region-map-relation-line`,d:ei(t.points),"data-route-points":t.points.map(({x:e,y:t})=>`${e},${t}`).join(` `),markerStart:e.directions.fromUnassignedNodeEdgeIds.length>0?`url(#${c})`:void 0,markerEnd:e.directions.fromRegionEdgeIds.length>0?`url(#${c})`:void 0}),t.labelLeaderPoints.length>1&&(0,$.jsx)(`path`,{className:`structure-region-map-label-leader`,d:ei(t.labelLeaderPoints)})]},`${e.regionId}:${e.contextId}`)})]}),ie.map(e=>{let t=w.get(e.id);if(!t)return null;let n=Lr(e.label.lines),r=g===e.id;return(0,$.jsx)(`button`,{type:`button`,className:`structure-region-map-relation-action${e.coreEdgeIds.length===e.edgeIds.length?` core`:e.coreEdgeIds.length>0?` has-core`:``}`,"data-edge-ids":e.edgeIds.join(` `),"aria-label":`Inspect ${e.orientation}; ${e.edgeIds.length} exact factual ${e.edgeIds.length===1?`Edge`:`Edges`}: ${e.label.full}`,"aria-pressed":r,title:`${e.label.full}\nExact Edgeを確認`,style:{left:t.labelCenter.x-100,top:t.labelCenter.y-n/2,width:200,minHeight:n},onPointerDown:ti,onPointerUp:ni,onClick:t=>{if(g===e.id){_(null);return}let n=t.currentTarget.closest(`.structure-regions-canvas`);_(e.id),requestAnimationFrame(()=>n?.querySelector(`.structure-region-relation-edge`)?.focus({preventScroll:!0}))},children:(0,$.jsx)(Yr,{label:e.label})},`action:${e.id}`)}),b.regions.map(e=>{let t=S.get(e.regionId);if(!t)return null;let n=t.id===y.startRegionId,r=t.backboneEdgeIds.length>0,o=i===t.id;return(0,$.jsxs)(`button`,{type:`button`,className:`structure-region-map-card`,"data-region-id":t.id,"data-start-region":n?`true`:void 0,"data-framed-region":o?`true`:void 0,"aria-label":`Open region ${t.label} in Graph, ${t.nodeCount} ${t.nodeCount===1?`node`:`nodes`}. ${t.summary}`,title:`${t.summary}\nOpen exact members in Graph`,onPointerDown:ti,onPointerUp:ni,onClick:()=>a(t.id),style:{left:e.center.x+Pr-116,top:e.center.y+Pr-88,width:232,height:176},children:[(0,$.jsxs)(`span`,{className:`structure-region-map-card-heading`,children:[(0,$.jsx)(`strong`,{children:t.label}),n&&(0,$.jsx)(`span`,{className:`structure-region-map-card-start`,children:`Start`}),r&&(0,$.jsx)(`span`,{className:`structure-region-map-card-core`,children:`Core`})]}),(0,$.jsx)(`span`,{className:`structure-region-map-card-summary`,children:t.summary}),(0,$.jsxs)(`span`,{className:`structure-region-map-card-count`,children:[t.nodeCount,` `,t.nodeCount===1?`Node`:`Nodes`,` ·`,` `,t.adjacentRegionIds.length,` direct Region`,` `,t.adjacentRegionIds.length===1?`connection`:`connections`,o?` · Framed in Graph`:``]})]},t.id)}),v.contextLayouts.map(t=>{let n=C.get(t.contextId);if(!n)return null;let r=n.nodeIds.includes(e.presentation.startNodeId),i=n.backboneEdgeIds.length>0,a=$r(n,T);return(0,$.jsxs)(`button`,{type:`button`,className:`structure-region-context-card`,"data-context-id":n.id,"data-start-context":r?`true`:void 0,"data-core-context":i?`true`:void 0,"aria-label":`Open unassigned Context ${a} in Graph, ${n.nodeIds.length} ${n.nodeIds.length===1?`node`:`nodes`}.`,title:`Open exact Context members in Graph`,onPointerDown:ti,onPointerUp:ni,onClick:()=>o(n.nodeIds),style:{left:t.center.x+Pr-Ar/2,top:t.center.y+Pr-jr/2,width:Ar,height:jr},children:[(0,$.jsxs)(`span`,{className:`structure-region-context-card-heading`,children:[(0,$.jsx)(`strong`,{children:`Context`}),r&&(0,$.jsx)(`span`,{className:`structure-region-context-card-start`,children:`Start`}),i&&(0,$.jsx)(`span`,{className:`structure-region-context-card-core`,children:`Core`})]}),(0,$.jsx)(`span`,{className:`structure-region-context-card-label`,title:a,children:a}),(0,$.jsxs)(`span`,{className:`structure-region-context-card-count`,children:[n.nodeIds.length,` `,n.nodeIds.length===1?`Node`:`Nodes`,` ·`,` `,n.internalEdgeIds.length,` internal · `,n.boundaryEdgeIds.length,` `,`boundary`]})]},n.id)})]})}),oe.length>0&&(0,$.jsxs)(`aside`,{className:`structure-region-relation-inspector`,"aria-label":`Exact factual Edges`,children:[(0,$.jsxs)(`header`,{children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`strong`,{children:`Exact factual Edges`}),(0,$.jsxs)(`span`,{children:[oe.length,`件`]})]}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Exact Edge一覧を閉じる`,onClick:e=>{let t=e.currentTarget.closest(`.structure-regions-canvas`)?.querySelector(`.structure-region-map-relation-action[aria-pressed="true"]`);_(null),requestAnimationFrame(()=>t?.focus({preventScroll:!0}))},children:`×`})]}),(0,$.jsx)(`p`,{className:`structure-region-relation-inspector-orientation`,children:ae?.orientation}),(0,$.jsx)(Qr,{edges:oe,nodeLabelsById:T,onOpenEdge:s,onOpenEdgeSource:c})]})]})}var ii=2,ai=.005,oi=.002,si=24;function ci(e){let t=getComputedStyle(e).transform;if(!t||t===`none`)return null;try{let e=new DOMMatrixReadOnly(t);return[e.a,e.b,e.c,e.d,e.e,e.f].some(e=>!Number.isFinite(e))||e.a<=0||Math.abs(e.b)>.001||Math.abs(e.c)>.001||Math.abs(e.a-e.d)>.001?null:{x:e.e,y:e.f,scale:e.a}}catch{return null}}function li(e){let t=new Map;for(let n of e){let e=a(n);e&&t.set(e,n.kind),n.oldPath&&t.set(n.oldPath,n.kind),n.newPath&&t.set(n.newPath,n.kind)}return t}function ui(e){return JSON.stringify([...e].sort(([e],[t])=>e.localeCompare(t,`en`)))}var di=new WeakMap;function fi(e,t){let n=t.nodeIds,r=t.edgeIds,i=e.presentation?{...e.presentation,primaryBackbone:e.presentation.primaryBackbone?{edgeIds:e.presentation.primaryBackbone.edgeIds.filter(e=>r.has(e))}:null,regions:e.presentation.regions.flatMap(e=>{let t=e.nodeIds.filter(e=>n.has(e));return t.length===0?[]:[{...e,nodeIds:t}]})}:null;return{nodes:t.nodes,edges:t.edges,presentation:i}}function pi(e){let{structure:t,positions:n,sourceChangeKinds:r,anchorNodeId:i,maximumSpacingExtentPositions:a,structureId:o,structureUpdatedAt:s}=e,c=Wt({structure:t,positions:n,sourceChangeKinds:r,labelAccessory:`source-actions`,edgeLabelMode:`viewer-adaptive`,retryPositions:({attempt:e,positions:n,pressureLabels:r})=>Cr({structure:t,anchorNodeId:i,attempt:e,positions:n,pressureLabels:r,...a?{maximumExtentPositions:a}:{},minimumExtentReduction:a?si:0})});return di.set(c.positions,{structureId:o,structureUpdatedAt:s,sourceChangeKindsKey:ui(r),foundation:c.foundation}),c}function mi(e,t){let n=null;for(let[r,i]of t)e[r]&&(n??={...e},n[r]=i);return n??e}function hi(e){let{structure:t,centerNodeId:n,depth:r,fullPositions:i,previousLocalPositions:a}=e,o=u(t,n,r,i);return o?{...o,positions:d(o,a)}:null}function gi(e){let{structure:t,centerNodeId:n,depth:r,fullPositions:i,sourceChangeKinds:a}=e,o=u(t,n,r,i);if(!o)return null;let s=pi({structure:fi(t,o.graph),positions:o.positions,sourceChangeKinds:a,anchorNodeId:n,maximumSpacingExtentPositions:i,structureId:t.id,structureUpdatedAt:t.updatedAt});return{...o,positions:s.positions,foundation:s.foundation}}function _i(e){let{structure:t,session:n,previousActivePositions:r,previousLocalPositions:i,sourceChangeKinds:a}=e;if(n.depth===`all`||n.localCenterId===null||n.localPositions)return n;let o=i?u(t,n.localCenterId,n.depth,n.positions):gi({structure:t,centerNodeId:n.localCenterId,depth:n.depth,fullPositions:n.positions,sourceChangeKinds:a}),s=T({structure:t,centerId:n.localCenterId,depth:n.depth,positions:n.positions});if(!o||!s)return n;let c=i?d(o,i):o.positions,l=n.focusId&&r[n.focusId]&&c[n.focusId]?n.focusId:n.localCenterId;return{...n,localPositions:c,localLayoutBasisKey:s,viewport:p({viewport:n.viewport,surfaceSize:n.surfaceSize,nodeId:l,nodeIds:o.graph.nodeIds,previousPositions:r,nextPositions:c})}}function vi(e){let{structure:t,previousLayoutBasisKey:n,session:r,sourceChangeKinds:i}=e;if(n===r.layoutBasisKey)return r;let a=(r.focusId&&r.positions[r.focusId]?r.focusId:null)??(r.localCenterId&&r.positions[r.localCenterId]?r.localCenterId:null)??t.presentation?.startNodeId??t.originNodeId,o=pi({structure:t,positions:r.positions,sourceChangeKinds:i,anchorNodeId:a,structureId:t.id,structureUpdatedAt:t.updatedAt});return{...r,positions:o.positions,localPositions:null,localLayoutBasisKey:null}}function yi({anchor:e,compact:t=!1,onOpen:n}){let r=`${wr(e)}を開く`;return(0,$.jsxs)(`button`,{type:`button`,className:`structure-source${t?` compact`:``}`,title:r,"aria-label":r,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),n(e.metaKey||e.ctrlKey)},children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`</>`}),!t&&(0,$.jsx)(`span`,{children:wr(e)})]})}function bi({edge:e,sourceMenuWidth:t,onOpen:n}){return e.anchors.length===0?null:e.anchors.length===1?(0,$.jsx)(yi,{compact:!0,anchor:e.anchors[0],onOpen:t=>n({kind:`edge`,edgeId:e.id,anchorIndex:0},e.anchors[0],t)}):(0,$.jsxs)(`details`,{className:`structure-edge-sources`,children:[(0,$.jsxs)(`summary`,{className:`structure-source compact`,"aria-label":`${e.label}のsource evidence ${e.anchors.length}件を表示`,title:`source evidence ${e.anchors.length}件`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`</>`}),(0,$.jsx)(`span`,{className:`structure-edge-source-count`,"aria-hidden":`true`,children:e.anchors.length})]}),(0,$.jsx)(`div`,{className:`structure-edge-source-menu`,style:t===null?void 0:{width:`min(${t}px, 42vw)`},children:e.anchors.map((t,r)=>(0,$.jsx)(yi,{anchor:t,onOpen:i=>n({kind:`edge`,edgeId:e.id,anchorIndex:r},t,i)},`${e.id}:${r}`))})]})}function xi({anchor:e,changeKind:t,sourceLabel:n}){return(0,$.jsxs)(`span`,{className:`structure-source-identity`,"data-source-path":e.path,"data-source-change-kind":t??void 0,title:e.path,children:[(0,$.jsx)(i,{path:e.path,kind:`file`}),t&&(0,$.jsx)(x,{kind:t}),(0,$.jsx)(`span`,{className:`structure-source-name`,children:n})]})}function Si({label:e}){let t=e.split(/(::|[./_-])/u);return(0,$.jsx)($.Fragment,{children:t.map((e,t)=>(0,$.jsxs)(E.Fragment,{children:[e,(e===`::`||/^[./_-]$/u.test(e))&&(0,$.jsx)(`wbr`,{})]},`${t}-${e}`))})}function Ci({structure:e,positions:t,focusedNodeId:n,localCenterId:r,framedRegionId:i,localNodeIds:a,viewport:o,viewportElement:c}){let l=s(e.nodes.map(e=>e.id),t);if(!l)return null;let u=Math.max(1,l.maxX-l.minX),d=Math.max(1,l.maxY-l.minY),f=Math.min(164/u,98/d),p=a?s(a,t):null,m=p?{x:p.minX,y:p.minY,width:p.maxX-p.minX,height:p.maxY-p.minY}:c?{x:-o.x/o.scale,y:-o.y/o.scale,width:c.clientWidth/o.scale,height:c.clientHeight/o.scale}:null,h=e=>(e-l.minX)*f,g=e=>(e-l.minY)*f,_=new Set(e.presentation?.primaryBackbone?.edgeIds??[]),v=ie(e),y=new Map((e.presentation?.regions??[]).flatMap(e=>e.nodeIds.map(t=>[t,e.id]))),b=e.presentation?t[e.presentation.startNodeId]:void 0;return(0,$.jsxs)(`svg`,{className:`structure-minimap`,viewBox:`0 0 164 98`,"aria-label":`Structure minimap`,children:[e.edges.flatMap(e=>{if(!_.has(e.id))return[];let n=t[e.from],r=t[e.to];return!n||!r?[]:[(0,$.jsx)(`line`,{className:`structure-minimap-primary-backbone`,"data-edge-id":e.id,x1:h(n.x+114),y1:g(n.y+56),x2:h(r.x+114),y2:g(r.y+56)},e.id)]}),e.nodes.map(e=>{let a=t[e.id];if(!a)return null;let o=[e.id===n?`focused`:null,e.id===r?`local-center`:null,v.has(e.id)?`primary-backbone`:null,y.has(e.id)?`region-member`:null,y.get(e.id)===i?`framed-region-member`:null].filter(e=>e!==null);return(0,$.jsx)(`circle`,{cx:h(a.x+114),cy:g(a.y+56),r:e.id===n||e.id===r?3.2:1.7,className:o.join(` `),"data-region-id":y.get(e.id)},e.id)}),b&&(0,$.jsx)(`circle`,{className:`structure-minimap-presentation-start`,cx:h(b.x+114),cy:g(b.y+56),r:`4.6`}),m&&(0,$.jsx)(`rect`,{className:`structure-minimap-viewport`,"data-map-frame":p?`local-footprint`:`viewport`,x:h(m.x),y:g(m.y),width:Math.max(2,m.width*f),height:Math.max(2,m.height*f)})]})}function wi({paneId:e,pullRequestId:t,structure:r,changedFiles:i,navigationTarget:a=null,readingNavigationTarget:s=null,onNavigationApplied:c,onNavigationFailed:u,onOpenSource:x,onReadingNavigationApplied:le,onPushReadingHistory:ue,onReadingSnapshotChanged:de,onReplaceReadingHistory:fe,onBrowserBack:pe,onDeleted:me}){let he=`structure-${e}-${r.id}`,[ge]=(0,E.useState)(()=>{let t=te(e,r.id),n=li(i);if(t){let e=vi({structure:r,previousLayoutBasisKey:t.layoutBasisKey,session:ee(r,t),sourceChangeKinds:n});return{hadCachedSession:!0,session:_i({structure:r,session:e,previousActivePositions:t.depth===`all`?t.positions:t.localPositions??t.positions,previousLocalPositions:t.depth===`all`||t.layoutBasisKey!==e.layoutBasisKey?null:t.localPositions??null,sourceChangeKinds:n}),initialFullRenderFoundation:null,initialSourceChangeKindsKey:null,initialStructureId:r.id}}let a=re(r),o=pi({structure:r,positions:a.positions,sourceChangeKinds:n,anchorNodeId:a.localCenterId,structureId:r.id,structureUpdatedAt:r.updatedAt});return{hadCachedSession:!1,session:{...a,positions:o.positions},initialFullRenderFoundation:o.foundation,initialSourceChangeKindsKey:ui(n),initialStructureId:r.id}}),D=ge.session,O=(0,E.useMemo)(()=>li(i),[i]),_e=(0,E.useMemo)(()=>ui(O),[O]),[k,ve]=(0,E.useState)(D.viewMode),[A,ye]=(0,E.useState)(D.focusId),[j,be]=(0,E.useState)(D.localCenterId),[M,xe]=(0,E.useState)(D.selectedEdgeId),[Se,Ce]=(0,E.useState)(null),[we,Te]=(0,E.useState)(null),[N,Ee]=(0,E.useState)(D.depth),[De,Oe]=(0,E.useState)(D.framedRegionId),[ke,Ae]=(0,E.useState)(D.positions),[je,Me]=(0,E.useState)(D.localPositions),[Ne,Pe]=(0,E.useState)(D.localLayoutBasisKey),[P,Fe]=(0,E.useState)(0),Ie=(0,E.useRef)({id:r.id,sourceOid:r.sourceOid,updatedAt:r.updatedAt}),Le=Ie.current.id!==r.id||Ie.current.updatedAt!==r.updatedAt,Re=(0,E.useMemo)(()=>T({structure:r,centerId:j,depth:N,positions:ke}),[N,ke,j,r]),ze=je!==null&&Ne===Re,Be=(0,E.useMemo)(()=>N===`all`||j===null||ze||Le?null:gi({structure:r,centerNodeId:j,depth:N,fullPositions:ke,sourceChangeKinds:O}),[N,ke,ze,j,O,r,Le]),Ve=ze||Le?je:Be?.positions??null,He=je,Ue=Ne,F=N===`all`||Ve===null?ke:Ve,[We,Ge]=(0,E.useState)(D.viewport),[I,Ke]=(0,E.useState)(D.regionsView),[qe,Je]=(0,E.useState)(D.guideDisclosure),[Ye,Xe]=(0,E.useState)(!1),[Ze,Qe]=(0,E.useState)(!1),[L,$e]=(0,E.useState)({width:0,height:0}),[et,tt]=(0,E.useState)(null),[nt,rt]=(0,E.useState)(null),[it,at]=(0,E.useState)(!1),ot=(0,E.useRef)(null),R=(0,E.useRef)(null),st=(0,E.useRef)(null),ct=(0,E.useRef)(D.surfaceSize),lt=(0,E.useRef)(k),ut=(0,E.useRef)(A),dt=(0,E.useRef)(j),ft=(0,E.useRef)(M),z=(0,E.useRef)(N),pt=(0,E.useRef)(De),B=(0,E.useRef)(F),V=(0,E.useRef)(ke),mt=(0,E.useRef)(He),ht=(0,E.useRef)(Ue),H=(0,E.useRef)(We),U=(0,E.useRef)(D.allViewport),W=(0,E.useRef)(D.allSurfaceSize),gt=(0,E.useRef)(D.allCameraFrame),_t=(0,E.useRef)(I),G=(0,E.useRef)(D.cameraFrame??null),vt=(0,E.useRef)(new Map),yt=(0,E.useRef)(()=>null),bt=(0,E.useRef)(null),xt=(0,E.useRef)(null),St=(0,E.useRef)(0),Ct=(0,E.useRef)(null),wt=(0,E.useRef)(0),Tt=(0,E.useRef)(new Map),Et=(0,E.useRef)(D),Dt=(0,E.useRef)(ge.hadCachedSession?null:`initial`),Ot=(0,E.useRef)(null),kt=(0,E.useRef)(null),At=(0,E.useRef)(null),jt=(0,E.useRef)(null),Mt=(0,E.useRef)(null),Nt=(0,E.useCallback)(()=>{let e=ot.current,t=e?{width:e.clientWidth,height:e.clientHeight}:{width:0,height:0};return t.width>0&&t.height>0?(ct.current=t,t):ct.current},[]),Pt=(0,E.useMemo)(()=>Br(r),[r]),Ft=(0,E.useCallback)(e=>{Ke(t=>{let n=e(t);return _t.current=n,n})},[]),It=(0,E.useCallback)((e,t)=>{if(!Pt)return null;let n={contentSize:{width:Pt.width,height:Pt.height},surfaceSize:t};return e===`fit`?v(n):f({...n,attentionBounds:Vr(r,Pt)})},[Pt,r]),K=(0,E.useCallback)(()=>{St.current+=1,Ct.current=null,bt.current&&=(clearTimeout(bt.current),null),xt.current&&=(clearTimeout(xt.current),null),Xe(!1),Qe(!1)},[]),Lt=(0,E.useCallback)(()=>{let e=ot.current?.querySelector(`.structure-world`),t=(e?.classList.contains(`camera-transition`)?ci(e):null)??H.current;return H.current=t,Ge(t),z.current===`all`&&(U.current=t,W.current=ct.current),t},[]),Rt=(0,E.useCallback)(e=>{H.current=e,Ge(e),z.current===`all`&&(U.current=e,W.current=ct.current,gt.current=null)},[]);lt.current=k,ut.current=A,dt.current=j,ft.current=M,z.current=N,pt.current=De,B.current=F,V.current=ke,mt.current=He,ht.current=Ue,H.current=We,N===`all`&&(U.current=We,W.current=ct.current,gt.current=G.current),_t.current=I,Et.current={viewMode:k,focusId:A,localCenterId:j,selectedEdgeId:M,depth:N,framedRegionId:De,cameraFrame:G.current,positions:ke,localPositions:He,localLayoutBasisKey:Ue,viewport:We,surfaceSize:ct.current,allViewport:N===`all`?We:U.current,allSurfaceSize:N===`all`?ct.current:W.current,allCameraFrame:N===`all`?G.current:gt.current,regionsView:I,guideDisclosure:qe,layoutBasisKey:Et.current.layoutBasisKey,updatedAt:Et.current.updatedAt},(0,E.useEffect)(()=>()=>{bt.current&&clearTimeout(bt.current),xt.current&&clearTimeout(xt.current)},[]),(0,E.useLayoutEffect)(()=>{N===`all`||Be===null||Re===null||je!==null&&Ne===Re||(mt.current=Be.positions,Tt.current.clear(),ht.current=Re,Me(Be.positions),Pe(Re))},[N,Be,Re,Ne,je]),(0,E.useLayoutEffect)(()=>{let e=ot.current;if(!e)return;let t=()=>{let t={width:e.clientWidth,height:e.clientHeight};if(t.width===0||t.height===0)return;let n=ct.current;ct.current=t,$e(t);let r=G.current;if(r){let e=ce({frame:r,positions:B.current,regionBounds:vt.current,surfaceSize:t,renderBoundsForNodeIds:yt.current});if(e){H.current=e,Ge(e);return}}n.width!==0&&n.height!==0&&Ge(e=>{let r={...e,x:e.x+(t.width-n.width)/2,y:e.y+(t.height-n.height)/2},i=ut.current?B.current[ut.current]:void 0;if(!i)return r;let a=228*r.scale,o=112*r.scale,s=r.x+i.x*r.scale,c=r.y+i.y*r.scale;return a>t.width-24?r.x=t.width/2-(i.x+114)*r.scale:s<12?r.x+=12-s:s+a>t.width-12&&(r.x-=s+a-(t.width-12)),o>t.height-24?r.y=t.height/2-(i.y+56)*r.scale:c<12?r.y+=12-c:c+o>t.height-12&&(r.y-=c+o-(t.height-12)),H.current=r,r})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]),(0,E.useLayoutEffect)(()=>{let e=R.current;if(k!==`regions`||!e||!Pt)return;let t=()=>{let t={width:e.clientWidth,height:e.clientHeight};t.width!==0&&t.height!==0&&Ft(e=>{let n=e.surfaceSize,r=e.cameraMode!==`manual`||n.width===0||n.height===0,i=e.cameraMode===`fit`?`fit`:`home`,a=r?It(i,t)??e.viewport:{...e.viewport,x:e.viewport.x+(t.width-n.width)/2,y:e.viewport.y+(t.height-n.height)/2};return n.width===t.width&&n.height===t.height&&a.x===e.viewport.x&&a.y===e.viewport.y&&a.scale===e.viewport.scale?e:{...e,viewport:a,surfaceSize:t}})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[It,I.cameraMode,I.layoutBasisKey,Ft,k]),(0,E.useEffect)(()=>{let e=ot.current;if(!e)return;let t=t=>{let n=t.ctrlKey||t.metaKey;if(t.target instanceof Element){let e=t.target.closest(`.structure-node-focus`),r=Math.abs(t.deltaY)>=Math.abs(t.deltaX),i=e?t.deltaY<0?e.scrollTop>0:t.deltaY>0&&e.scrollTop+e.clientHeight<e.scrollHeight-1:!1;if(!n&&r&&i)return}t.preventDefault(),t.stopPropagation();let r=Lt(),i=t.deltaMode===WheelEvent.DOM_DELTA_LINE?16:t.deltaMode===WheelEvent.DOM_DELTA_PAGE?Math.max(1,e.clientHeight):1;if(!n){Rt({...r,x:r.x-t.deltaX*i*ii,y:r.y-t.deltaY*i*ii}),K(),G.current=null;return}let a=e.getBoundingClientRect(),o=t.clientX-a.left,s=t.clientY-a.top,c=t.ctrlKey&&!t.metaKey?ai:oi,l=h(r.scale,Math.exp(-t.deltaY*i*c)),u=(o-r.x)/r.scale,d=(s-r.y)/r.scale;Rt({scale:l,x:o-u*l,y:s-d*l}),K(),G.current=null};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[K,Rt,Lt]),(0,E.useEffect)(()=>{let e=R.current;if(k!==`regions`||!e)return;let t=t=>{let n=t.ctrlKey||t.metaKey;if(!n&&t.target instanceof Element){let e=t.target.closest(`.structure-region-map-card-summary`),n=Math.abs(t.deltaY)>=Math.abs(t.deltaX),r=e?t.deltaY<0?e.scrollTop>0:t.deltaY>0&&e.scrollTop+e.clientHeight<e.scrollHeight-1:!1;if(n&&r)return}t.preventDefault(),t.stopPropagation();let r=t.deltaMode===WheelEvent.DOM_DELTA_LINE?16:t.deltaMode===WheelEvent.DOM_DELTA_PAGE?Math.max(1,e.clientHeight):1;if(!n){Ft(e=>({...e,cameraMode:`manual`,viewport:{...e.viewport,x:e.viewport.x-t.deltaX*r*ii,y:e.viewport.y-t.deltaY*r*ii}}));return}let i=e.getBoundingClientRect(),a=t.clientX-i.left,o=t.clientY-i.top;Ft(e=>{let n=t.ctrlKey&&!t.metaKey?ai:oi,i=h(e.viewport.scale,Math.exp(-t.deltaY*r*n)),s=(a-e.viewport.x)/e.viewport.scale,c=(o-e.viewport.y)/e.viewport.scale;return{...e,cameraMode:`manual`,viewport:{scale:i,x:a-s*i,y:o-c*i}}})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[Ft,k]),(0,E.useEffect)(()=>{let e=Et.current,t=vi({structure:r,previousLayoutBasisKey:e.layoutBasisKey,session:ee(r,e),sourceChangeKinds:O}),n=_i({structure:r,session:t,previousActivePositions:e.depth===`all`?e.positions:e.localPositions??e.positions,previousLocalPositions:e.depth===`all`||e.layoutBasisKey!==t.layoutBasisKey?null:e.localPositions??null,sourceChangeKinds:O});if(Ie.current.id===r.id&&e.updatedAt===n.updatedAt&&e.layoutBasisKey===n.layoutBasisKey&&e.regionsView.layoutBasisKey===n.regionsView.layoutBasisKey)return;K();let i=Ie.current;i.id===r.id&&i.updatedAt!==r.updatedAt&&tt(i.sourceOid===r.sourceOid?`Structureが更新されました。閲覧状態を保ったまま最新のclaimへ反映しています。`:`Structureが更新されました。exact source ${i.sourceOid.slice(0,8)} → ${r.sourceOid.slice(0,8)}`),Ie.current={id:r.id,sourceOid:r.sourceOid,updatedAt:r.updatedAt},G.current=n.cameraFrame,Et.current=n,lt.current=n.viewMode,ut.current=n.focusId,dt.current=n.localCenterId,z.current=n.depth,pt.current=n.framedRegionId,V.current=n.positions,mt.current=n.localPositions,Tt.current.clear(),ht.current=n.localLayoutBasisKey,B.current=n.depth===`all`||n.localPositions===null?n.positions:n.localPositions,H.current=n.viewport,U.current=n.allViewport,W.current=n.allSurfaceSize,gt.current=n.allCameraFrame,_t.current=n.regionsView,ve(n.viewMode),ye(n.focusId),be(n.localCenterId),xe(n.selectedEdgeId),Ee(n.depth),Oe(n.framedRegionId),Ae(n.positions),Me(n.localPositions),Pe(n.localLayoutBasisKey),Ge(n.viewport),Ke(n.regionsView),Je(n.guideDisclosure)},[K,O,r]),(0,E.useEffect)(()=>{S(e,r.id,Et.current)},[N,A,De,ke,qe,j,Ne,je,e,M,r.id,r.updatedAt,L,I,k,We]);let zt=(0,E.useMemo)(()=>N===`all`||j===null?null:Be?.graph??se(r,j,N),[N,Be?.graph,j,r]),Bt=(0,E.useMemo)(()=>zt?{nodeIds:zt.nodeIds,edgeIds:zt.edgeIds}:l(r,null,`all`),[zt,r]);(0,E.useLayoutEffect)(()=>{M===null||Bt.edgeIds.has(M)||(ft.current=null,xe(null))},[M,Bt.edgeIds]);let Vt=(0,E.useMemo)(()=>!zt||N===`all`?r:fi(r,zt),[N,zt,r]),Ut=(0,E.useMemo)(()=>new Map(r.nodes.map(e=>[e.id,e])),[r.nodes]),Wt=A?Ut.get(A)??null:null,qt=Ut.get(r.originNodeId),q=M&&Bt.edgeIds.has(M)?r.edges.find(e=>e.id===M)??null:null,Yt=(0,E.useMemo)(()=>new Set(q?[q.from,q.to]:[]),[q]),Xt=(0,E.useMemo)(()=>A?o(r,A):[],[A,r]),Zt=(0,E.useMemo)(()=>new Set(r.presentation?.primaryBackbone?.edgeIds??[]),[r.presentation]),Qt=(0,E.useMemo)(()=>ie(r),[r]),$t=(r.presentation?.regions.length??0)>0,en=(0,E.useMemo)(()=>A?C(r,[A]):Bt.nodeIds,[A,r,Bt.nodeIds]),tn=(0,E.useMemo)(()=>A===null?new Set:new Set(r.edges.filter(e=>!en.has(e.from)||!en.has(e.to)).map(e=>e.id)),[A,en,r.edges]),nn=(0,E.useMemo)(()=>new Set(Bt.edgeIds),[Bt.edgeIds]),rn=(0,E.useMemo)(()=>{if(ge.initialFullRenderFoundation&&ke===D.positions&&_e===ge.initialSourceChangeKindsKey&&r.id===ge.initialStructureId&&r.updatedAt===D.updatedAt)return ge.initialFullRenderFoundation;let e=di.get(ke);return e?.structureId===r.id&&e.structureUpdatedAt===r.updatedAt&&e.sourceChangeKindsKey===_e?e.foundation:Ht({structure:r,positions:ke,sourceChangeKinds:O,labelAccessory:`source-actions`,edgeLabelMode:`viewer-adaptive`})},[ke,D.positions,D.updatedAt,ge.initialFullRenderFoundation,ge.initialSourceChangeKindsKey,ge.initialStructureId,O,_e,r]),an=(0,E.useMemo)(()=>{if(N===`all`||zt===null)return null;let e=di.get(F);return e?.structureId===r.id&&e.structureUpdatedAt===r.updatedAt&&e.sourceChangeKindsKey===_e?e.foundation:Ht({structure:Vt,positions:F,sourceChangeKinds:O,labelAccessory:`source-actions`,edgeLabelMode:`viewer-adaptive`})},[N,zt,F,Vt,O,_e,r.id,r.updatedAt])??rn,on=(0,E.useCallback)(e=>Kt(rn,e),[rn]),sn=(0,E.useCallback)(e=>Kt(an,e),[an]);yt.current=sn;let cn=(0,E.useCallback)((e,t)=>{let n=sn(e);return n?ae({bounds:n,surfaceSize:t}):m({nodeIds:e,positions:F,surfaceSize:t})},[F,sn]),J=(0,E.useCallback)((e,t)=>{let n=on(e);return n?ae({bounds:n,surfaceSize:t}):m({nodeIds:e,positions:ke,surfaceSize:t})},[ke,on]),ln=(0,E.useMemo)(()=>Gt(an,{nodeIds:Bt.nodeIds,edgeIds:Bt.edgeIds,labelEdgeIds:nn}),[nn,an,Bt.edgeIds,Bt.nodeIds]),un=(0,E.useMemo)(()=>new Map((ln.presentation?.regions??[]).map(e=>[e.id,e.bounds])),[ln.presentation?.regions]);vt.current=un;let dn=ln.edges.map(({edge:e})=>e),fn=ln.nodes.map(({node:e})=>e),pn=ln.labels,mn=ln.edges.find(({edge:e})=>e.id===(Se??we)),hn=pn.filter(e=>e.diagnostics.spacingPressure).length,gn=pn.filter(e=>e.diagnostics.fallbackReason!==null).length,_n=(0,E.useMemo)(()=>new Map((r.presentation?.regions??[]).flatMap(e=>e.nodeIds.map(t=>[t,{id:e.id,label:e.label,summary:e.summary}]))),[r.presentation]),Y=(0,E.useMemo)(()=>De===null?null:r.presentation?.regions.find(e=>e.id===De)??null,[De,r.presentation]),vn=(0,E.useMemo)(()=>new Set(Y?.nodeIds??[]),[Y]),yn=(0,E.useMemo)(()=>Y===null?0:r.edges.filter(e=>vn.has(e.from)&&vn.has(e.to)).length,[Y,vn,r.edges]),bn=ln.bounds,xn=Math.max(1200,(bn?.right??1e3)+180),Sn=Math.max(800,(bn?.bottom??600)+180);(0,E.useLayoutEffect)(()=>{let e=G.current;if(e?.kind!==`region`&&e?.kind!==`nodes`||Mt.current!==null)return;let t=ce({frame:e,positions:F,regionBounds:un,surfaceSize:L,renderBoundsForNodeIds:sn});t&&(H.current=t,Ge(t))},[F,un,sn,L]);let Cn=()=>{let e=Nt();return!bn||e.width===0||e.height===0?null:ae({bounds:bn,surfaceSize:e})},wn=()=>{let e=Cn();e&&(K(),bn&&(G.current={kind:`bounds`,bounds:bn}),H.current=e,Ge(e))};(0,E.useLayoutEffect)(()=>{if(!Dt.current||!bn||L.width===0||L.height===0)return;Dt.current=null;let e=[..._(r)],t={kind:`nodes`,nodeIds:e},n=cn(e,L)??b({structure:r,positions:F,surfaceSize:L});G.current=t,H.current=n,Ge(n)},[bn,F,r,L,cn]);let Tn=(0,E.useCallback)((e,t)=>{let n=F[e];if(!n)return;K();let r=Nt(),i=t??H.current.scale;G.current={kind:`center-node`,nodeId:e,scale:i};let a={scale:i,x:r.width/2-(n.x+114)*i,y:r.height/2-(n.y+56)*i};H.current=a,Ge(a)},[K,Nt,F]),En=(0,E.useCallback)((e,t=null)=>{bt.current&&clearTimeout(bt.current),G.current=t,Xe(!0),H.current=e,Ge(e),bt.current=setTimeout(()=>{bt.current=null,Xe(!1)},220)},[]),Dn=(0,E.useCallback)(()=>{xt.current&&clearTimeout(xt.current),Qe(!0),xt.current=setTimeout(()=>{xt.current=null,Qe(!1)},240)},[]),X=(0,E.useCallback)((e={})=>({artifactUpdatedAt:r.updatedAt,viewMode:lt.current,focusId:ut.current,localCenterId:dt.current,selectedEdgeId:ft.current,depth:z.current,framedRegionId:pt.current,cameraFrame:G.current,viewport:H.current,surfaceSize:ct.current,allCameraFrame:z.current===`all`?G.current:gt.current,allViewport:z.current===`all`?H.current:U.current,allSurfaceSize:z.current===`all`?ct.current:W.current,positions:V.current,localPositions:mt.current,localLayoutBasisKey:ht.current,regionsViewport:_t.current.viewport,regionsSurfaceSize:_t.current.surfaceSize,regionsCameraMode:_t.current.cameraMode,layoutBasisKey:Et.current.layoutBasisKey,positionsKey:y(B.current),regionsLayoutBasisKey:_t.current.layoutBasisKey,...e}),[r.updatedAt]),On=(0,E.useCallback)(e=>{let t=X();JSON.stringify(e)!==JSON.stringify(t)&&ue(e,t)},[X,ue]);(0,E.useLayoutEffect)(()=>{let e=Ct.current;if(!e||e.requestId!==P||(Ct.current=null,e.generation!==St.current||N===`all`||j!==e.nodeId))return;let t=se(r,e.nodeId,N);if(!t)return;let n=[...t.nodeIds].sort((e,t)=>e.localeCompare(t,`en`)),i=cn(n,Nt());i&&(En(i,{kind:`nodes`,nodeIds:n}),On(e.readingSource))},[En,N,j,P,Nt,On,r,cn]),(0,E.useLayoutEffect)(()=>{de(X())},[X,N,A,De,ke,j,Ne,je,de,F,I,M,k,We]),(0,E.useEffect)(()=>{let e=X(),t=window.setTimeout(()=>fe(e),150);return()=>window.clearTimeout(t)},[X,N,A,De,ke,j,Ne,je,fe,F,I,M,k,We]);let kn=(0,E.useCallback)(e=>{F[e]&&(Dt.current=null,ft.current=null,xe(null),lt.current=`graph`,ve(`graph`),pt.current=null,Oe(null),ut.current=e,ye(e))},[F]),An=(0,E.useCallback)(e=>{if(!F[e])return;K();let t=[...C(r,[e])],n={kind:`nodes`,nodeIds:t},i=cn(t,Nt());if(!i)return;let a=X(),o=Dt.current===`initial`;Dt.current=null,En(i,n),o||On(a)},[En,K,X,Nt,F,On,r,cn]),jn=(0,E.useCallback)(e=>{let t=z.current;if(t===`all`)return;K();let n=gi({structure:r,centerNodeId:e,depth:t,fullPositions:V.current,sourceChangeKinds:O});if(!n)return;let i=T({structure:r,centerId:e,depth:t,positions:V.current});if(!i)return;let a=X(),o=St.current,s=wt.current+1;if(wt.current=s,Dt.current=null,Ct.current={requestId:s,generation:o,nodeId:e,readingSource:a},G.current=null,Fe(s),dt.current!==e){let t=mi(n.positions,Tt.current);dt.current=e,mt.current=t,ht.current=i,B.current=t,be(e),Me(t),Pe(i),Dn()}},[Dn,K,X,O,r]),Mn=(0,E.useCallback)(e=>{kn(e),z.current===`all`?An(e):jn(e)},[An,jn,kn]),Nn=()=>{K();let e=X(),t=r.presentation?.startNodeId??r.originNodeId,n=[..._(r)],i={kind:`nodes`,nodeIds:n},a=Nt(),o=J(n,a),s=Dt.current===`initial`;Dt.current=null,ft.current=null,xe(null),lt.current=`graph`,ve(`graph`),pt.current=null,Oe(null),ut.current=t,ye(t),dt.current=t,be(t),z.current=`all`,B.current=V.current,Ee(`all`),o&&(U.current=o,W.current=a,gt.current=i,N!==`all`&&Dn(),En(o,i)),s||On(e)},Pn=()=>{fe(X()),pe()},Fn=e=>{let t=r.presentation?.regions??[],n=t.findIndex(t=>t.id===e);if(n<0)return;K();let i=t[n],a=Nt(),o={kind:`region`,regionId:i.id},s=on(i.nodeIds),c=s?ae({bounds:s,surfaceSize:a,topInset:150}):m({nodeIds:i.nodeIds,positions:V.current,surfaceSize:a});if(!c)return;let l=X(),u=Dt.current===`initial`;Dt.current=null,z.current=`all`,B.current=V.current,Ee(`all`),pt.current=i.id,Oe(i.id),lt.current=`graph`,ve(`graph`),U.current=c,W.current=a,gt.current=o,N!==`all`&&Dn(),En(c,o),u||On(l),tt(`${i.label} RegionをGraphで表示しました。`),requestAnimationFrame(()=>st.current?.focus())};(0,E.useLayoutEffect)(()=>{if(!a||a.structureId!==r.id||a.pane!==e||Ot.current===a.requestId||r.updatedAt<a.structureUpdatedAt)return;if(r.updatedAt>a.structureUpdatedAt){Ot.current=a.requestId,tt(`Structureが更新されたため、ファイル参照を更新しました。もう一度選択してください。`),u(a.requestId);return}let t=r.nodes.find(e=>e.id===a.nodeId);if(!t){Ot.current=a.requestId,tt(`移動先のNodeはStructureの更新により削除されています。ファイル参照を更新しました。`),u(a.requestId);return}if(!V.current[t.id]||L.width===0||L.height===0)return;K(),Dt.current=null,tt(null),ft.current=null,xe(null),lt.current=`graph`,ve(`graph`),pt.current=null,Oe(null),ut.current=t.id,ye(t.id);let n=z.current;if(n===`all`)Tn(t.id);else{let e=hi({structure:r,centerNodeId:t.id,depth:n,fullPositions:V.current,previousLocalPositions:mt.current??B.current}),i=T({structure:r,centerId:t.id,depth:n,positions:V.current}),a=e?.positions[t.id];if(!e||!i||!a)return;dt.current=t.id,mt.current=e.positions,ht.current=i,B.current=e.positions,be(t.id),Me(e.positions),Pe(i);let o=Nt(),s={scale:H.current.scale,x:o.width/2-(a.x+114)*H.current.scale,y:o.height/2-(a.y+56)*H.current.scale};Dn(),En(s,{kind:`center-node`,nodeId:t.id,scale:s.scale})}let i=X();de(i),fe(i),Ot.current=a.requestId,c(a.requestId)},[X,Tn,Dn,En,K,Nt,a,c,u,de,fe,e,O,r,L.height,L.width]),(0,E.useLayoutEffect)(()=>{if(!s||s.structureId!==r.id||s.pane!==e||kt.current===s.requestId||L.width===0||L.height===0)return;K();let t=s.snapshot,n=Et.current,i={...n,viewMode:t.viewMode,focusId:t.focusId,localCenterId:t.localCenterId===void 0?t.depth===`all`?n.localCenterId:t.focusId:t.localCenterId,selectedEdgeId:t.selectedEdgeId,depth:t.depth,framedRegionId:t.framedRegionId,cameraFrame:t.cameraFrame,viewport:t.viewport,surfaceSize:t.surfaceSize,positions:t.positions??n.positions,localPositions:t.localPositions===void 0?n.localPositions:t.localPositions,localLayoutBasisKey:t.localLayoutBasisKey===void 0?n.localLayoutBasisKey:t.localLayoutBasisKey,allViewport:t.allViewport??(t.depth===`all`?t.viewport:n.allViewport),allSurfaceSize:t.allSurfaceSize??(t.depth===`all`?t.surfaceSize:n.allSurfaceSize),allCameraFrame:t.allCameraFrame===void 0?n.allCameraFrame:t.allCameraFrame,layoutBasisKey:t.layoutBasisKey,updatedAt:t.artifactUpdatedAt},a=vi({structure:r,previousLayoutBasisKey:i.layoutBasisKey,session:ee(r,i),sourceChangeKinds:O}),o=a.depth===`all`||a.localCenterId===null?null:se(r,a.localCenterId,a.depth),c=a.localPositions!==null||o===null?null:gi({structure:r,centerNodeId:o.centerNodeId,depth:o.depth,fullPositions:a.positions,sourceChangeKinds:O}),l=a.localPositions??(c&&t.localPositions&&t.layoutBasisKey===a.layoutBasisKey?d(c,t.localPositions):c?.positions??null),u=T({structure:r,centerId:a.localCenterId,depth:a.depth,positions:a.positions}),f=a.depth===`all`||l===null?a.positions:l,m=o?fi(r,o):r,h=(e,t)=>{let n=di.get(t);return n?.structureId===r.id&&n.structureUpdatedAt===r.updatedAt&&n.sourceChangeKindsKey===_e?n.foundation:Ht({structure:e,positions:t,sourceChangeKinds:O,labelAccessory:`source-actions`,edgeLabelMode:`viewer-adaptive`})},_=(e,t,n,r)=>{let i=e.kind===`nodes`||e.kind===`region`?h(t,n):null,a=new Map((i?.presentation?.regions??[]).map(e=>[e.id,e.bounds]));return ce({frame:e,positions:n,regionBounds:a,surfaceSize:r,...i?{renderBoundsForNodeIds:e=>Kt(i,e)}:{}})},v=y(f),b=t.layoutBasisKey===a.layoutBasisKey&&t.positionsKey===v,x=g({frame:a.cameraFrame,snapshotArtifactUpdatedAt:t.artifactUpdatedAt,currentArtifactUpdatedAt:r.updatedAt,geometryMatches:b}),S=t.cameraFrame?.kind===`bounds`&&x===null,C=t.artifactUpdatedAt===r.updatedAt,w=Nt(),te={...t.viewport,x:t.viewport.x+(w.width-t.surfaceSize.width)/2,y:t.viewport.y+(w.height-t.surfaceSize.height)/2},re=t.depth===`all`?t.positions:t.localPositions??t.positions,ie=re?p({viewport:te,surfaceSize:w,nodeId:a.focusId??a.localCenterId,nodeIds:Object.keys(f),previousPositions:re,nextPositions:f}):te,ae=S?n.viewport:b&&C?te:x?_(x,m,f,w)??ie:ie,oe=t.layoutBasisKey===a.layoutBasisKey&&(t.positions===void 0||y(t.positions)===y(a.positions)),E=g({frame:a.allCameraFrame,snapshotArtifactUpdatedAt:t.artifactUpdatedAt,currentArtifactUpdatedAt:r.updatedAt,geometryMatches:oe}),ue=t.allViewport&&t.allSurfaceSize?{...t.allViewport,x:t.allViewport.x+(w.width-t.allSurfaceSize.width)/2,y:t.allViewport.y+(w.height-t.allSurfaceSize.height)/2}:null,de={...a.allViewport,x:a.allViewport.x+(w.width-a.allSurfaceSize.width)/2,y:a.allViewport.y+(w.height-a.allSurfaceSize.height)/2},fe=ue??de,pe=t.positions?p({viewport:fe,surfaceSize:w,nodeId:a.focusId??a.localCenterId,nodeIds:Object.keys(a.positions),previousPositions:t.positions,nextPositions:a.positions}):fe,me=a.depth===`all`?ae:oe&&C&&ue?ue:E?_(E,r,a.positions,w)??pe:pe,he=t.regionsLayoutBasisKey===_t.current.layoutBasisKey?ne(_t.current,{regionsViewport:t.regionsViewport,regionsSurfaceSize:t.regionsSurfaceSize,regionsCameraMode:t.regionsCameraMode},_t.current.surfaceSize):_t.current;Dt.current=null,tt(null),lt.current=a.viewMode,ve(a.viewMode),ut.current=a.focusId,ye(a.focusId),dt.current=a.localCenterId,be(a.localCenterId),ft.current=a.selectedEdgeId,xe(a.selectedEdgeId),z.current=a.depth,Ee(a.depth),pt.current=a.framedRegionId,Oe(a.framedRegionId),V.current=a.positions,mt.current=l,Tt.current.clear(),ht.current=u,B.current=f,Ae(a.positions),Me(l),Pe(u),G.current=x,H.current=ae,Ge(ae),U.current=me,W.current=w,gt.current=E,_t.current=he,Ke(he),kt.current=s.requestId,le(s.requestId)},[Nt,le,e,s,O,_e,r,K,L.height,L.width]);let In=()=>{A&&Tn(A)},Ln=()=>{K(),G.current=null;let e=z.current,t=dt.current,n=(()=>{if(e===`all`){let e=oe(r);return pi({structure:r,positions:e,sourceChangeKinds:O,anchorNodeId:(ut.current&&e[ut.current]?ut.current:t)??r.presentation?.startNodeId??r.originNodeId,structureId:r.id,structureUpdatedAt:r.updatedAt}).positions}return t===null?null:gi({structure:r,centerNodeId:t,depth:e,fullPositions:V.current,sourceChangeKinds:O})?.positions??null})();if(!n)return;let i=Object.keys(n),a=p({viewport:H.current,surfaceSize:ct.current,nodeId:ut.current??dt.current,nodeIds:i,previousPositions:B.current,nextPositions:n});if(B.current=n,e===`all`)V.current=n,Ae(n),mt.current=null,Tt.current.clear(),ht.current=null,Me(null),Pe(null),U.current=a,gt.current=null;else{let t=T({structure:r,centerId:dt.current,depth:e,positions:V.current});mt.current=n,Tt.current.clear(),ht.current=t,Me(n),Pe(t)}Dn(),En(a,null)},Rn=()=>{ft.current=null,xe(null),ut.current=null,ye(null)},zn=e=>{let t=z.current;if(e===t)return;K();let n=Nt();if(e===`all`){let e=W.current,t={...U.current,x:U.current.x+(n.width-e.width)/2,y:U.current.y+(n.height-e.height)/2};z.current=`all`,B.current=V.current,U.current=t,W.current=n,Ee(`all`),pt.current=null,Oe(null),Dn(),En(t,gt.current),de(X()),fe(X());return}let i=r.presentation?.startNodeId??r.originNodeId,a=ut.current&&V.current[ut.current]?ut.current:null,o=dt.current&&V.current[dt.current]?dt.current:null,s=t===`all`?a??o??i:o??a??i,c=gi({structure:r,centerNodeId:s,depth:e,fullPositions:V.current,sourceChangeKinds:O}),l=T({structure:r,centerId:s,depth:e,positions:V.current});if(!c||!l)return;t===`all`&&(U.current=H.current,W.current=n,gt.current=G.current);let u=p({viewport:H.current,surfaceSize:n,nodeId:s,nodeIds:c.graph.nodeIds,previousPositions:B.current,nextPositions:c.positions});dt.current=s,mt.current=c.positions,Tt.current.clear(),ht.current=l,B.current=c.positions,be(s),Me(c.positions),Pe(l),z.current=e,Ee(e),pt.current=null,Oe(null),Dn(),En(u,null);let d=X();de(d),fe(d)},Bn=async()=>{try{await navigator.clipboard.writeText(r.ref),tt(`Structure参照をコピーしました。`)}catch{tt(`Structure参照をコピーできませんでした。`)}},Vn=async e=>{if(!nt){rt(e),tt(null);try{let t=sr({structure:r,model:Jt({structure:r,positions:V.current,sourceChangeKinds:O}),palette:Gn(document.documentElement)});if(e===`svg`){fr(new Blob([t.source],{type:`image/svg+xml;charset=utf-8`}),dr(r,`svg`));return}let n=cr(t.width,t.height);fr(await ur(t,n),dr(r,`png`)),n.downscaled&&tt(`PNGを${Math.round(n.scale*100)}%で出力しました。より高い解像度にはSVGを使用してください。`)}catch(e){tt(pr(e))}finally{rt(null)}}},Hn=e=>{K(),G.current=null,Ge(t=>{let n=h(t.scale,e),r=L.width/2,i=L.height/2,a=(r-t.x)/t.scale,o=(i-t.y)/t.scale;return{scale:n,x:r-a*n,y:i-o*n}})},Un=()=>{let e=R.current,t=e?{width:e.clientWidth,height:e.clientHeight}:_t.current.surfaceSize,n=It(`fit`,t);n&&Ft(e=>({...e,viewport:n,surfaceSize:t,cameraMode:`fit`}))},Wn=()=>{let e=R.current,t=e?{width:e.clientWidth,height:e.clientHeight}:_t.current.surfaceSize,n=It(`home`,t);n&&Ft(e=>({...e,viewport:n,surfaceSize:t,cameraMode:`home`}))},Kn=e=>{let t=R.current,n=t?{width:t.clientWidth,height:t.clientHeight}:_t.current.surfaceSize;Ft(t=>{let r=h(t.viewport.scale,e),i=n.width/2,a=n.height/2,o=(i-t.viewport.x)/t.viewport.scale,s=(a-t.viewport.y)/t.viewport.scale;return{...t,cameraMode:`manual`,viewport:{scale:r,x:i-o*r,y:a-s*r}}})},Z=async(e,t,n)=>{tt(null);let r=X();de(r),fe(r);try{let t=await x(e,n);tt(t)}catch(e){tt(e instanceof Error?e.message:`参照先を開けません · ${t.path}`)}},Q=e=>{let t=new Set(r.nodes.map(e=>e.id)),n=e.filter(e=>t.has(e));if(n.length===0)return;let i=Nt(),a={kind:`nodes`,nodeIds:n},o=J(n,i);if(!o)return;K();let s=X();ft.current=null,xe(null),z.current=`all`,B.current=V.current,Ee(`all`),pt.current=null,Oe(null),lt.current=`graph`,ve(`graph`),U.current=o,W.current=i,gt.current=a,N!==`all`&&Dn(),En(o,a),On(s),tt(`Context componentのexact ${n.length} NodeをGraphで表示しました。`),requestAnimationFrame(()=>st.current?.focus())},qn=e=>{let t=r.edges.find(t=>t.id===e);if(!t)return;let n=[...new Set([t.from,t.to])],i=Nt(),a={kind:`nodes`,nodeIds:n},o=J(n,i);if(!o)return;K();let s=X();ft.current=t.id,xe(t.id),z.current=`all`,B.current=V.current,Ee(`all`),pt.current=null,Oe(null),lt.current=`graph`,ve(`graph`),U.current=o,W.current=i,gt.current=a,N!==`all`&&Dn(),En(o,a),On(s),tt(`exact Edge「${t.label}」をGraphで選択しました。`),requestAnimationFrame(()=>st.current?.focus())},Jn=async()=>{if(it)return;let e=r.nodes.filter(e=>e.anchor!==null).length+r.edges.reduce((e,t)=>e+t.anchors.length,0);if(window.confirm(`Structure「${r.title}」を削除します。\n\nNode ${r.nodes.length}\nEdge ${r.edges.length}\nSource anchor ${e}\n\nこの操作は元に戻せません。`)){at(!0),tt(null);try{await n(`/api/pull-requests/${t}/structures/${r.id}`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify({expectedUpdatedAt:r.updatedAt})}),w(r.id),me()}catch(e){tt(e instanceof Error?e.message:`Structureを削除できませんでした。`)}finally{at(!1)}}},Yn=e=>{let t=Mt.current;if(t?.pointerId===e.pointerId){let n=(e.clientX-t.x)/H.current.scale,r=(e.clientY-t.y)/H.current.scale,i=t.distance+Math.hypot(e.clientX-t.x,e.clientY-t.y),a=t.dragging||i>=4;if(Mt.current={...t,x:e.clientX,y:e.clientY,distance:i,dragging:a},!a)return;G.current=null;let o=t.dragging?null:{x:t.startPoint.x+(e.clientX-t.startX)/H.current.scale,y:t.startPoint.y+(e.clientY-t.startY)/H.current.scale},s=e=>{let i=e[t.nodeId];return i?{...e,[t.nodeId]:o??{x:i.x+n,y:i.y+r}}:e};if(z.current===`all`)Ae(e=>{let t=s(e);return V.current=t,B.current=t,t}),mt.current=null,Tt.current.clear(),ht.current=null,Me(null),Pe(null);else{let e=mt.current;if(!e)return;let n=s(e);mt.current=n,B.current=n,Me(n);let r=n[t.nodeId];r&&Tt.current.set(t.nodeId,r)}return}let n=At.current;if(n?.pointerId!==e.pointerId)return;let r=e.clientX-n.x,i=e.clientY-n.y;At.current={...n,x:e.clientX,y:e.clientY},Rt({...H.current,x:H.current.x+r,y:H.current.y+i})},Xn=e=>{if(At.current?.pointerId===e.pointerId&&(At.current=null),Mt.current?.pointerId===e.pointerId){let e=Mt.current;Mt.current=null,e.dragging||(e.nodeElement.style.left=`${e.committedPoint.x}px`,e.nodeElement.style.top=`${e.committedPoint.y}px`,H.current=e.committedViewport,Ge(e.committedViewport),z.current===`all`&&(U.current=e.committedViewport,W.current=ct.current),e.focusTarget?.focus({preventScroll:!0}),kn(e.nodeId))}e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},Zn=e=>{let t=jt.current;if(t?.pointerId!==e.pointerId)return;let n=e.clientX-t.x,r=e.clientY-t.y;jt.current={...t,x:e.clientX,y:e.clientY},Ft(e=>({...e,cameraMode:`manual`,viewport:{...e.viewport,x:e.viewport.x+n,y:e.viewport.y+r}}))},Qn=e=>{jt.current?.pointerId===e.pointerId&&(jt.current=null),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)};return(0,$.jsxs)(`article`,{className:`structure-viewer`,"data-structure-id":r.id,"data-visible-node-count":k===`graph`?Bt.nodeIds.size:void 0,"data-total-node-count":k===`graph`?r.nodes.length:void 0,"data-visible-edge-count":k===`graph`?Bt.edgeIds.size:void 0,"data-total-edge-count":k===`graph`?r.edges.length:void 0,"data-rendered-node-count":k===`graph`?fn.length:void 0,"data-rendered-edge-count":k===`graph`?dn.length:void 0,"data-has-presentation":r.presentation?`true`:void 0,"data-view-mode":k,"data-viewport-scale":k===`graph`?We.scale.toFixed(3):void 0,"data-regions-viewport-scale":k===`regions`?I.viewport.scale.toFixed(3):void 0,"data-regions-camera-mode":k===`regions`?I.cameraMode:void 0,"data-semantic-zoom":k===`graph`?We.scale<.42?`overview`:`detail`:void 0,"data-framed-region-id":De??void 0,"data-selected-edge-id":M??void 0,"data-selected-node-id":A??void 0,"data-local-center-id":N===`all`?void 0:j??void 0,"data-neighborhood-depth":N,"data-label-spacing-pressure-count":hn,"data-label-fallback-count":gn,children:[(0,$.jsxs)(`header`,{className:`structure-header`,children:[(0,$.jsxs)(`div`,{className:`structure-header-main`,children:[(0,$.jsx)(`span`,{className:`structure-kicker`,children:`Structure`}),(0,$.jsx)(`h2`,{title:r.title,children:r.title}),(0,$.jsx)(`span`,{className:`structure-source-oid`,title:`exact source ${r.sourceOid}`,children:r.sourceOid.slice(0,8)}),(0,$.jsxs)(`details`,{className:`structure-scope-details`,children:[(0,$.jsx)(`summary`,{"aria-label":`scopeを表示`,children:`scope`}),(0,$.jsx)(`p`,{children:r.scope})]})]}),(0,$.jsxs)(`div`,{className:`structure-header-side`,children:[(0,$.jsx)(`button`,{type:`button`,className:`structure-header-action`,"aria-label":`参照をコピー`,title:`Structure参照をコピー`,onClick:()=>void Bn(),children:`参照`}),(0,$.jsx)(Tr,{disabled:it||nt!==null,exporting:nt,onExport:e=>void Vn(e)}),(0,$.jsx)(`button`,{type:`button`,className:`danger structure-delete`,disabled:it,onClick:()=>void Jn(),children:it?`削除中…`:`削除`})]})]}),(0,$.jsx)(kr,{structure:r,focusedNodeId:A,disclosure:qe,onToggleDisclosure:e=>Je(t=>({...t,[e]:!t[e]})),onFocusNode:Mn}),(0,$.jsxs)(`div`,{className:`structure-body`,children:[(0,$.jsxs)(`div`,{className:`structure-toolbar`,"aria-label":`Structure表示操作`,children:[(0,$.jsxs)(`div`,{className:`structure-toolbar-group structure-view-mode`,role:`group`,"aria-label":`Structure表示モード`,children:[(0,$.jsx)(`button`,{ref:st,type:`button`,className:k===`graph`?`active`:``,"aria-pressed":k===`graph`,onClick:()=>{K(),lt.current=`graph`,ve(`graph`);let e=X();de(e),fe(e)},children:`Graph`}),(0,$.jsx)(`button`,{type:`button`,className:k===`regions`?`active`:``,"aria-pressed":k===`regions`,disabled:!$t,title:$t?`責務chunkと直接のfactual relationを表示`:`このStructureにはRegionがありません`,onClick:()=>{K(),lt.current=`regions`,ve(`regions`);let e=X();de(e),fe(e)},children:`Regions`})]}),(0,$.jsxs)(`div`,{className:`structure-toolbar-group`,role:`group`,"aria-label":`Structure内navigation`,children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":`Back`,title:`ブラウザの一つ前のreading destinationへ戻る`,onClick:Pn,children:`Back`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Home`,title:`説明のstartと1-hopを表示`,onClick:Nn,children:`Home`})]}),(0,$.jsx)(`div`,{className:`structure-toolbar-group`,role:`group`,"aria-label":`近傍の深さ`,hidden:k!==`graph`,children:[1,2,`all`].map(e=>(0,$.jsx)(`button`,{type:`button`,className:N===e?`active`:``,"aria-pressed":N===e,onClick:()=>zn(e),children:e===`all`?`全体`:`${e}-hop`},e))}),(0,$.jsxs)(`div`,{className:`structure-toolbar-group`,hidden:k!==`graph`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Hn(1/1.2),"aria-label":`縮小`,children:`−`}),(0,$.jsxs)(`span`,{children:[Math.round(We.scale*100),`%`]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Hn(1.2),"aria-label":`拡大`,children:`+`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`表示中を収める`,title:`表示中を収める`,onClick:wn,children:`Fit`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`focusを中央へ`,title:`選択Nodeを中央へ`,disabled:!A,onClick:In,children:`中央`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`focusを解除`,title:`Node選択を解除`,disabled:!A,onClick:Rn,children:`解除`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`レイアウトを戻す`,title:`レイアウトを戻す`,onClick:Ln,children:`Reset`})]}),(0,$.jsxs)(`div`,{className:`structure-toolbar-group`,role:`group`,"aria-label":`Regions map表示操作`,hidden:k!==`regions`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Kn(1/1.2),"aria-label":`Regionsを縮小`,children:`−`}),(0,$.jsxs)(`span`,{children:[Math.round(I.viewport.scale*100),`%`]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Kn(1.2),"aria-label":`Regionsを拡大`,children:`+`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Regions全体を収める`,title:`Regions全体を収める`,onClick:Un,children:`Fit`}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Regions表示を戻す`,title:`RegionsのcameraをStartが読める初期表示へ戻す`,onClick:Wn,children:`Reset`})]})]}),et&&(0,$.jsx)(`div`,{className:`structure-status`,role:`status`,"aria-live":`polite`,children:et}),(0,$.jsxs)(`section`,{className:`structure-canvas-shell`,"aria-label":`${r.title} ${k===`graph`?`graph`:`Regions`}`,children:[(0,$.jsxs)(`div`,{ref:ot,className:`structure-canvas`,hidden:k!==`graph`,tabIndex:0,onFocusCapture:e=>{e.currentTarget.scrollLeft=0,e.currentTarget.scrollTop=0},onKeyDown:e=>{e.key!==`Escape`||!M&&!A||(e.preventDefault(),M?xe(null):Rn())},onPointerDown:e=>{e.button!==0||e.target instanceof Element&&e.target.closest(`.structure-node, .structure-edge-label, button`)||(Lt(),K(),G.current=null,At.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY},e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:Yn,onPointerUp:Xn,onPointerCancel:Xn,onScroll:e=>{e.currentTarget.scrollLeft=0,e.currentTarget.scrollTop=0},onDoubleClick:e=>{let t=document.elementFromPoint(e.clientX,e.clientY),n=t?.closest(`.structure-node`);if(n&&e.currentTarget.contains(n)&&!t?.closest(`.structure-source, .structure-node-neighborhood`)){let e=n.dataset.nodeId;e&&Mn(e);return}e.target===e.currentTarget&&wn()},children:[Y&&(0,$.jsxs)(`aside`,{className:`structure-region-lens`,"data-region-id":Y.id,"aria-label":`${Y.label} Region lens. ${Y.nodeIds.length} exact member ${Y.nodeIds.length===1?`Node`:`Nodes`}. ${Y.summary}`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:`structure-region-lens-heading`,children:[(0,$.jsx)(`span`,{className:`structure-region-lens-kicker`,children:`Region lens`}),(0,$.jsx)(`strong`,{children:Y.label}),(0,$.jsxs)(`span`,{className:`structure-region-lens-count`,children:[Y.nodeIds.length,` exact member`,Y.nodeIds.length===1?` Node`:` Nodes`,` ·`,` `,yn,` internal`,yn===1?` Relation`:` Relations`]})]}),(0,$.jsx)(`p`,{children:Y.summary}),(0,$.jsxs)(`span`,{className:`structure-region-lens-context`,children:[`focus · `,Wt?.label??`なし`,` · origin · `,qt.label,` · Graph ·`,` `,Bt.nodeIds.size,`/`,r.nodes.length,` Node · `,Bt.edgeIds.size,`/`,r.edges.length,` Relation`]})]}),(0,$.jsxs)(`div`,{className:`structure-world${Ye?` camera-transition`:``}${Ze?` layout-transition`:``}`,style:{width:xn,height:Sn,transform:`translate(${We.x}px, ${We.y}px) scale(${We.scale})`},children:[(0,$.jsxs)(`svg`,{className:`structure-edges`,width:xn,height:Sn,"aria-hidden":`true`,children:[(0,$.jsx)(`defs`,{children:(0,$.jsx)(`marker`,{id:`${he}-arrow`,viewBox:`0 0 12 10`,refX:12,refY:5,markerWidth:12,markerHeight:10,markerUnits:`userSpaceOnUse`,orient:`auto`,children:(0,$.jsx)(`path`,{d:`M 0 0 L 12 5 L 0 10 z`})})}),ln.edges.map(({edge:e,geometry:t,source:n})=>{let r=e.from===A||e.to===A,i=e.id===M,a=M!==null&&!i,o=Zt.has(e.id),s=tn.has(e.id),c=vn.has(e.from)&&vn.has(e.to),l=Y!==null&&!c,u=s&&!c,d=n.changeKind,f=`${o?` primary-backbone`:``}${r?` focused`:``}${c?` framed-region-relation`:``}${l?` region-frame-context`:``}${i?` selected`:``}${u?` context-distant`:``}${a?` muted`:``}`;return(0,$.jsxs)(E.Fragment,{children:[(0,$.jsx)(`path`,{className:`structure-edge${f}`,"data-edge-id":e.id,"data-primary-backbone":o?`true`:void 0,"data-focus-relevance":r?`incident`:s?`distant`:`near`,"data-framed-region-relation":c?`true`:void 0,"data-source-change-kind":d??void 0,"data-start-x":t.startX,"data-start-y":t.startY,"data-end-x":t.endX,"data-end-y":t.endY,"data-arrow-base-x":e.directed?t.arrowBaseX:void 0,"data-arrow-base-y":e.directed?t.arrowBaseY:void 0,"data-arrow-tangent-x":e.directed?t.arrowTangentX:void 0,"data-arrow-tangent-y":e.directed?t.arrowTangentY:void 0,d:e.directed?t.strokePath:t.path}),e.directed&&(0,$.jsx)(`path`,{className:`structure-edge-arrow-carrier${f}`,"data-edge-arrow-id":e.id,"data-source-change-kind":d??void 0,d:t.arrowPath,markerEnd:`url(#${he}-arrow)`})]},e.id)}),mn&&(0,$.jsxs)(`g`,{className:`structure-edge-label-emphasis`,"data-edge-label-emphasis-id":mn.edge.id,"data-source-change-kind":mn.source.changeKind??void 0,children:[(0,$.jsx)(`path`,{className:`structure-edge-label-emphasis-halo`,d:mn.edge.directed?mn.geometry.strokePath:mn.geometry.path}),(0,$.jsx)(`path`,{className:`structure-edge-label-emphasis-line`,d:mn.edge.directed?mn.geometry.strokePath:mn.geometry.path})]}),pn.flatMap(({edge:e,leaderPath:t,leaderEdgeAnchor:n,source:r})=>{if(!t||!n)return[];let i=Zt.has(e.id),a=e.from===A||e.to===A,o=e.id===M,s=M!==null&&!o,c=tn.has(e.id),l=vn.has(e.from)&&vn.has(e.to);return[(0,$.jsxs)(`g`,{className:`structure-edge-label-leader${i?` primary-backbone`:``}${a?` focus-incident`:``}${l?` framed-region-relation`:``}${Y!==null&&!l?` region-frame-context`:``}${o?` selected`:``}${c&&!l?` context-distant`:``}${s?` muted`:``}`,"data-edge-id":e.id,"data-primary-backbone":i?`true`:void 0,"data-framed-region-relation":l?`true`:void 0,"data-source-change-kind":r.changeKind??void 0,children:[(0,$.jsx)(`path`,{className:`structure-edge-label-leader-halo`,d:t}),(0,$.jsx)(`path`,{className:`structure-edge-label-leader-line`,d:t}),(0,$.jsx)(`circle`,{className:`structure-edge-label-leader-anchor`,cx:n.x,cy:n.y,r:2.5})]},`label-leader:${e.id}`)]})]}),pn.map(({edge:e,displayLines:t,source:n,x:r,y:i,selectWidth:a,boxWidth:o,height:s,crowded:c,displaced:l,sourceMenuPlacement:u,sourceMenuWidth:d,diagnostics:f})=>{let p=n.changeKind,m=Ut.get(e.from),h=Ut.get(e.to),g=Zt.has(e.id),_=e.from===A||e.to===A,v=`${e.directed?`${m?.label??e.from} から ${h?.label??e.to} へ: ${e.label}`:`${m?.label??e.from} と ${h?.label??e.to} の関係: ${e.label}`}${g?` · explanation backbone relation`:``}`,y=e.id===M,b=M!==null&&!y,x=tn.has(e.id),S=vn.has(e.from)&&vn.has(e.to);return(0,$.jsxs)(`div`,{className:`structure-edge-label${g?` primary-backbone`:``}${_?` focus-incident`:``}${S?` framed-region-relation`:``}${Y!==null&&!S?` region-frame-context`:``}${y?` selected`:``}${x&&!S?` context-distant`:``}${c?` crowded`:``}${b?` muted`:``}`,"data-edge-id":e.id,"data-label-displaced":l?`true`:`false`,"data-label-edge-distance":f.edgeDistance.toFixed(2),"data-label-leader-length":f.leaderLength.toFixed(2),"data-label-parallel-overlap":f.maxParallelOverlap.toFixed(2),"data-label-crossing-count":f.crossingCount,"data-label-compact":f.usedCompactWidth?`true`:`false`,"data-label-fallback":f.fallbackReason??void 0,"data-primary-backbone":g?`true`:void 0,"data-framed-region-relation":S?`true`:void 0,"data-focus-relevance":_?`incident`:x?`distant`:`near`,"data-source-anchor-count":n.anchorCount,"data-source-menu-placement":u??void 0,"data-source-menu-width":d??void 0,"data-source-change-kind":p??void 0,style:{left:r,top:i,width:o,height:s},onPointerEnter:()=>Ce(e.id),onPointerLeave:()=>Ce(t=>t===e.id?null:t),onFocusCapture:()=>Te(e.id),onBlurCapture:t=>{t.relatedTarget instanceof Node&&t.currentTarget.contains(t.relatedTarget)||Te(t=>t===e.id?null:t)},onPointerDownCapture:e=>{e.button===0&&(e.preventDefault(),ot.current&&(ot.current.scrollLeft=0,ot.current.scrollTop=0))},onPointerUpCapture:e=>{if(e.button!==0||!(e.target instanceof Element))return;let t=e.target.closest(`button, summary`);t&&e.currentTarget.contains(t)&&t.focus({preventScroll:!0})},children:[(0,$.jsx)(`button`,{type:`button`,className:`structure-edge-select${y?` selected`:``}`,title:e.label,"aria-label":v,"aria-pressed":y,style:{width:a},onClick:()=>xe(t=>t===e.id?null:e.id),children:(0,$.jsx)(`span`,{className:`structure-edge-label-text`,"aria-hidden":`true`,children:t.map((t,n)=>(0,$.jsxs)(E.Fragment,{children:[n>0&&(0,$.jsx)(`br`,{}),t]},`${e.id}:line:${n}`))})}),(0,$.jsx)(bi,{edge:e,sourceMenuWidth:d,onOpen:(e,t,n)=>void Z(e,t,n)})]},`label:${e.id}`)}),ln.nodes.map(({node:e,point:t,changeKind:n,sourceLabel:i})=>{let a=e.id===A,o=N!==`all`&&e.id===j,s=Qt.has(e.id),c=r.presentation?.startNodeId===e.id,l=_n.get(e.id),u=Xt.some(t=>t.from===e.id||t.to===e.id),d=A!==null&&!en.has(e.id),f=vn.has(e.id),p=Y!==null&&!f,m=d&&!f;return(0,$.jsxs)(`div`,{className:`structure-node notation-${e.notation}${e.id===r.originNodeId?` origin`:``}${c?` presentation-start`:``}${s?` primary-backbone`:``}${f?` framed-region-member`:``}${p?` region-frame-context`:``}${a?` focused`:``}${o?` local-center`:``}${u?` neighboring`:``}${m?` context-distant`:``}${Yt.has(e.id)?` edge-endpoint`:``}`,"data-node-id":e.id,"data-node-notation":e.notation,"data-origin-node":e.id===r.originNodeId?`true`:void 0,"data-presentation-start-node":c?`true`:void 0,"data-primary-backbone":s?`true`:void 0,"data-focus-relevance":a?`active`:d?`distant`:`near`,"data-local-center":o?`true`:void 0,"data-framed-region-member":f?`true`:void 0,"data-region-id":l?.id,"data-region-label":l?.label,"data-source-change-kind":n??void 0,style:{left:t.x,top:t.y},onPointerDown:n=>{if(n.button!==0)return;n.preventDefault(),n.stopPropagation(),ot.current&&(ot.current.scrollLeft=0,ot.current.scrollTop=0);let r=(z.current===`all`?V.current[e.id]:mt.current?.[e.id])??t,i=getComputedStyle(n.currentTarget),a=Number.parseFloat(i.left),o=Number.parseFloat(i.top),s=xt.current!==null&&Number.isFinite(a)&&Number.isFinite(o)?{x:a,y:o}:r;n.currentTarget.style.left=`${s.x}px`,n.currentTarget.style.top=`${s.y}px`;let c=H.current;Lt(),K(),Mt.current={pointerId:n.pointerId,nodeId:e.id,nodeElement:n.currentTarget,focusTarget:n.currentTarget.querySelector(`:scope > .structure-node-focus`),startX:n.clientX,startY:n.clientY,x:n.clientX,y:n.clientY,distance:0,startPoint:s,committedPoint:r,committedViewport:c,dragging:!1},ot.current?.setPointerCapture(n.pointerId)},children:[o&&(0,$.jsx)(`span`,{className:`structure-node-local-center-marker`,"aria-hidden":`true`,title:`Local center`}),c&&(0,$.jsx)(`span`,{className:`structure-node-presentation-start`,"aria-hidden":`true`,title:`Authorial start`}),(0,$.jsxs)(`button`,{type:`button`,className:`structure-node-focus`,"aria-label":`${e.label}${e.id===r.originNodeId?` · factual origin`:``}${c?` · authorial start`:``}${s?` · explanation backbone member`:``}${l?` · region: ${l.label}`:``}`,"aria-pressed":a,title:`${e.label}\nDouble-click to focus neighborhood`,onClick:t=>{t.detail===0&&kn(e.id)},children:[e.anchor&&(0,$.jsx)(xi,{anchor:e.anchor,changeKind:n,sourceLabel:i??e.anchor.path}),(0,$.jsx)(`strong`,{className:`structure-node-title`,children:(0,$.jsx)(`span`,{className:`structure-node-title-text`,title:`${e.label}\nDouble-click to focus neighborhood`,children:(0,$.jsx)(Si,{label:e.label})})}),(0,$.jsx)(`span`,{className:`structure-node-description`,children:e.description??`Producerによる説明なし`})]}),(0,$.jsx)(`button`,{type:`button`,className:`structure-node-neighborhood`,"aria-label":`${e.label}の周辺を表示`,title:`このNodeと${N===`all`?`1`:N}-hop周辺へ移動`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),Mn(e.id)},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`⊙`})}),e.anchor&&(0,$.jsx)(yi,{compact:!0,anchor:e.anchor,onOpen:t=>void Z({kind:`node`,nodeId:e.id},e.anchor,t)})]},e.id)})]}),!Y&&(0,$.jsxs)(`div`,{className:`structure-canvas-status`,children:[(0,$.jsx)(`strong`,{children:Wt?.label??`選択なし`}),N!==`all`&&(0,$.jsxs)(`span`,{children:[`local center ·`,` `,j?Ut.get(j)?.label??j:`なし`]}),(0,$.jsxs)(`span`,{children:[`origin · `,qt.label]}),(0,$.jsxs)(`span`,{children:[Bt.nodeIds.size,`/`,r.nodes.length,` Node · `,Bt.edgeIds.size,`/`,r.edges.length,` Relation`]})]}),(0,$.jsx)(Ci,{structure:r,positions:ke,focusedNodeId:A,localCenterId:N===`all`?null:j,framedRegionId:De,localNodeIds:N===`all`?null:Bt.nodeIds,viewport:We,viewportElement:ot.current})]}),k===`regions`&&(0,$.jsx)(ri,{structure:r,model:Pt,viewport:I.viewport,surfaceRef:R,framedRegionId:De,onOpenRegion:Fn,onOpenContext:Q,onOpenEdge:qn,onOpenEdgeSource:(e,t,n,r)=>void Z({kind:`edge`,edgeId:e,anchorIndex:t},n,r),onPointerDown:e=>{e.button!==0||e.target instanceof Element&&e.target.closest(`.structure-region-map-card, .structure-region-map-relation-label, button`)||(jt.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY},e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:Zn,onPointerUp:Qn,onPointerCancel:Qn,onFocusCapture:e=>{if(!(e.target instanceof HTMLElement))return;let t=e.target.closest(`.structure-region-map-card, .structure-region-context-card, .structure-region-map-relation-action`),n=R.current;if(!t||!n)return;let r=n.getBoundingClientRect(),i=t.getBoundingClientRect(),a=0,o=0;i.left<r.left+16?a=r.left+16-i.left:i.right>r.right-16&&(a=r.right-16-i.right),i.top<r.top+16?o=r.top+16-i.top:i.bottom>r.bottom-16&&(o=r.bottom-16-i.bottom),(a!==0||o!==0)&&Ft(e=>({...e,cameraMode:`manual`,viewport:{...e.viewport,x:e.viewport.x+a,y:e.viewport.y+o}}))},onDoubleClick:e=>{e.target instanceof Element&&e.target.closest(`.structure-region-map-card, button`)||Un()}})]})]})]})}export{wi as StructureViewer};