spytial-core 2.2.1 → 2.2.2-beta.1

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.
@@ -848,7 +848,7 @@ Expecting `+F1.join(", ")+", got '"+(this.terminals_[eo]||eo)+"'":E1="Parse erro
848
848
  </svg>
849
849
  </div>
850
850
  <div id="error" style="display: none; color: red;"></div>
851
- `;}initializeD3(){Ss||(Ss=window.d3),this.svg=Ss.select(this.shadowRoot.querySelector("#svg")),this.container=this.svg.select(".zoomable"),Ss.zoom?(this.zoomBehavior=Ss.zoom().scaleExtent([.01,20]).on("start",()=>{Ss.event.sourceEvent&&(this.userHasManuallyZoomed=true);}).on("zoom",()=>{this.container.attr("transform",Ss.event.transform),this.updateZoomControlStates(),this.updateSmallNodeClasses();}),this.svg.call(this.zoomBehavior),this.initializeZoomControls()):console.warn("D3 zoom behavior not available. Ensure D3 v4+ is loaded.");}initializeZoomControls(){let r=this.shadowRoot.querySelector("#zoom-in"),o=this.shadowRoot.querySelector("#zoom-out"),s=this.shadowRoot.querySelector("#zoom-fit");r&&r.addEventListener("click",()=>{this.userHasManuallyZoomed=true,this.zoomIn();}),o&&o.addEventListener("click",()=>{this.userHasManuallyZoomed=true,this.zoomOut();}),s&&s.addEventListener("click",()=>{this.resetViewToFitContent();});let e=this.shadowRoot.querySelector("#routing-mode");if(e){let a=this.layoutFormat||"default";e.value=a,e.addEventListener("change",()=>{this.handleRoutingModeChange(e.value);});}let i=this.shadowRoot.querySelector("#screenshot-btn");i&&i.addEventListener("click",()=>{this.takeScreenshot();}),this.updateZoomControlStates();}handleRoutingModeChange(r){this.setAttribute("layoutFormat",r),this.currentLayout&&this.colaLayout&&(r==="grid"?this.gridify(10,25,10):this.routeEdges(),this.dispatchEvent(new CustomEvent("routing-mode-changed",{detail:{mode:r}})));}updateRoutingModeDropdown(){let r=this.shadowRoot?.querySelector("#routing-mode");if(r){let o=this.layoutFormat||"default";r.value=o;}}initializeInputModeHandlers(){this.inputModeEnabled&&this.attachInputModeListeners();}attachInputModeListeners(){this.inputModeListenersAttached||(document.addEventListener("keydown",this.handleInputModeKeydown),document.addEventListener("keyup",this.handleInputModeKeyup),window.addEventListener("blur",this.handleInputModeBlur),this.inputModeListenersAttached=true);}detachInputModeListeners(){this.inputModeListenersAttached&&(document.removeEventListener("keydown",this.handleInputModeKeydown),document.removeEventListener("keyup",this.handleInputModeKeyup),window.removeEventListener("blur",this.handleInputModeBlur),this.inputModeListenersAttached=false);}activateInputMode(){this.isInputModeActive=true,this.svg&&this.svg.classed("input-mode",true),this.disableNodeDragging(),this.disableZoom(),this.updateEdgeEndpointMarkers(),this.dispatchEvent(new CustomEvent("input-mode-activated",{detail:{active:true}}));}deactivateInputMode(){this.isInputModeActive=false,this.svg&&this.svg.classed("input-mode",false),this.cleanupEdgeCreation(),this.enableNodeDragging(),this.enableZoom(),this.updateEdgeEndpointMarkers(),this.dispatchEvent(new CustomEvent("input-mode-deactivated",{detail:{active:false}}));}disableNodeDragging(){this.svgNodes&&this.colaLayout&&this.svgNodes.on(".drag",null);}enableNodeDragging(){if(this.svgNodes&&this.colaLayout&&this.colaLayout.drag){let r=this.colaLayout.drag();this.setupNodeDragHandlers(r),this.svgNodes.call(r);}}disableZoom(){this.svg&&this.zoomBehavior&&(this.storedTransform=Ss.zoomTransform(this.svg.node()),this.svg.on(".zoom",null));}enableZoom(){this.svg&&this.zoomBehavior&&(this.svg.call(this.zoomBehavior),this.storedTransform&&this.svg.call(this.zoomBehavior.transform,this.storedTransform));}zoomIn(){this.svg&&this.zoomBehavior&&this.svg.transition().duration(200).call(this.zoomBehavior.scaleBy,1.5);}zoomOut(){this.svg&&this.zoomBehavior&&this.svg.transition().duration(200).call(this.zoomBehavior.scaleBy,1/1.5);}updateZoomControlStates(){if(!this.svg||!this.zoomBehavior)return;let o=Ss.zoomTransform(this.svg.node()).k,[s,e]=this.zoomBehavior.scaleExtent(),i=this.shadowRoot.querySelector("#zoom-in"),a=this.shadowRoot.querySelector("#zoom-out");i&&(i.disabled=o>=e),a&&(a.disabled=o<=s);}cleanupEdgeCreation(){this.edgeCreationState.temporaryEdge&&this.edgeCreationState.temporaryEdge.remove(),this.edgeCreationState={isCreating:false,sourceNode:null,temporaryEdge:null};}setupNodeDragHandlers(r){r.on("start.cnd",o=>{this.userHasManuallyZoomed=true;let s={x:o.x,y:o.y};this.dragStartPositions.set(o.id,s),this.dispatchEvent(new CustomEvent("node-drag-start",{detail:{id:o.id,position:s}}));}).on("end.cnd",o=>{let s=this.dragStartPositions.get(o.id);this.dragStartPositions.delete(o.id);let e={id:o.id,previous:s,current:{x:o.x,y:o.y}};this.dispatchEvent(new CustomEvent("node-drag-end",{detail:e}));});}startEdgeCreation(r){this.isInputModeActive&&(this.cleanupEdgeCreation(),this.edgeCreationState.isCreating=true,this.edgeCreationState.sourceNode=r,this.edgeCreationState.temporaryEdge=this.container.append("line").attr("class","temporary-edge").attr("x1",r.x).attr("y1",r.y).attr("x2",r.x).attr("y2",r.y).attr("stroke","#007bff").attr("stroke-width",2).attr("stroke-dasharray","5,5").attr("opacity",.7),this.svg.on("mousemove.edgecreation",()=>{if(this.edgeCreationState.isCreating&&this.edgeCreationState.temporaryEdge){let[o,s]=Ss.mouse(this.container.node());this.edgeCreationState.temporaryEdge.attr("x2",o).attr("y2",s);}}));}async finishEdgeCreation(r){if(!this.isInputModeActive||!this.edgeCreationState.isCreating||!this.edgeCreationState.sourceNode)return;let o=this.edgeCreationState.sourceNode;if(o.id===r.id&&!await this.showConfirmDialog(`Are you sure you want to create a self-loop edge on "${o.label||o.id}"?`)){this.cleanupEdgeCreation();return}this.svg.on("mousemove.edgecreation",null),await this.showEdgeLabelInput(o,r);}async showEdgeLabelInput(r,o){let s=await this.showPromptDialog(`Enter label for edge from "${r.label||r.id}" to "${o.label||o.id}":`,"");s!==null&&await this.createNewEdge(r,o,s||""),this.cleanupEdgeCreation();}async createNewEdge(r,o,s){if(!this.currentLayout)return;let e=this.currentLayout.nodes.findIndex(v=>v.id===r.id),i=this.currentLayout.nodes.findIndex(v=>v.id===o.id);if(e===-1||i===-1){console.error("Could not find node indices for edge creation");return}let h={id:`edge_${r.id}_${o.id}_${Date.now()}`,source:e,target:i,label:s,relName:s,color:"#333",isUserCreated:true};this.currentLayout.links.push(h),await this.updateExternalStateForNewEdge(r,o,s),this.dispatchEvent(new CustomEvent("edge-created",{detail:{edge:h,sourceNode:r,targetNode:o}})),this.rerenderGraph();}async updateExternalStateForNewEdge(r,o,s){if(s.trim())try{let e={atoms:[r.id,o.id],types:[r.type||"untyped",o.type||"untyped"]};console.log(`Dispatching edge creation request: ${s}(${r.id}, ${o.id})`);let i=new CustomEvent("edge-creation-requested",{detail:{relationId:s,sourceNodeId:r.id,targetNodeId:o.id,tuple:e},bubbles:!0});this.dispatchEvent(i);}catch(e){console.error("Failed to update external state for new edge:",e);}}rerenderGraph(){!this.currentLayout||!this.colaLayout||(this.colaLayout.links(this.currentLayout.links),this.container.selectAll(".link-group").remove(),this.renderLinks(this.currentLayout.links,this.colaLayout),this.colaLayout.start());}async editEdgeLabel(r){if(!this.isInputModeActive)return;let o=r.label||r.relName||"",s=await this.showEdgeEditDialog("Edit edge label:",o);if(s==="DELETE"){await this.deleteEdge(r);return}if(s!==null&&s!==o){let e=s,i=this.getNodeFromEdge(r,"source"),a=this.getNodeFromEdge(r,"target");await this.updateExternalStateForEdgeModification(i,a,o,e),r.label=e,r.relName=e,this.dispatchEvent(new CustomEvent("edge-modified",{detail:{edge:r,oldLabel:o,newLabel:e}})),this.rerenderGraph();}}getNodeFromEdge(r,o){if(!this.currentLayout)return null;let s=typeof r[o]=="number"?r[o]:r[o].index;return this.currentLayout.nodes[s]||null}async updateExternalStateForEdgeModification(r,o,s,e){if(!(!r||!o))try{let i={atoms:[r.id,o.id],types:[r.type||"untyped",o.type||"untyped"]};console.log(`Dispatching edge modification request: ${s} -> ${e}`);let a=new CustomEvent("edge-modification-requested",{detail:{oldRelationId:s,newRelationId:e,sourceNodeId:r.id,targetNodeId:o.id,tuple:i},bubbles:!0});this.dispatchEvent(a);}catch(i){console.error("Failed to update external state for edge modification:",i);}}resolveTransitionMode(r){if(r?.transitionMode==="replace")return "replace";if(r?.transitionMode==="morph")return "morph";let o=this.getAttribute("transition-mode");return o==="replace"?"replace":o==="morph"||r?.policy?"morph":"replace"}async renderLayout(r,o){if(!kb(r))throw new Error("Invalid instance layout provided. Expected an InstanceLayout instance.");let s=this.resolveTransitionMode(o),e=s==="morph",i=s==="replace",a,h=false;if(o?.policy&&o.prevInstance&&o.currInstance){let g=this.buildPolicyRawState(o),u=this.getViewportBoundsInLayoutSpace(g.transform),c=o.policy.apply({priorState:g,prevInstance:o.prevInstance,currInstance:o.currInstance,spec:{constraints:{orientation:{relative:[],cyclic:[]},alignment:[],grouping:{groups:[],subgroups:[]}},directives:{sizes:[],hiddenAtoms:[],icons:[],projections:[],edgeStyles:[]}},viewportBounds:u});a=c.effectivePriorState,h=c.useReducedIterations;}else if(o?.priorPositions)a=o.priorPositions,h=true;else if(e&&this.currentLayout?.nodes?.length){let g=this.getLayoutState();g.positions.length>0&&(a=g,h=true);}let v=!!(a&&a.positions.length>0),_=this.hasValidTransform(a?.transform),y=v?{priorPositions:a,lockUnconstrainedNodes:h}:void 0;if(this.applyViewportRenderPolicy(v,_),this.svg&&this.zoomBehavior&&Ss)try{if(_){let g=a.transform,u=Ss.zoomIdentity.translate(g.x,g.y).scale(g.k);this.svg.call(this.zoomBehavior.transform,u);}else if(!v){let g=Ss.zoomIdentity;this.svg.call(this.zoomBehavior.transform,g);}}catch(g){console.warn("Failed to set zoom transform:",g);}try{if(!Ss)throw new Error("D3 library not available. Please ensure D3 v4 is loaded from CDN.");if(!Fd){if(!window.cola)throw new Error("WebCola library not available. Please ensure vendor/cola.js is loaded.");Fd=window.cola;}if((!this.container||!this.svg)&&this.initializeD3(),!this.container)throw new Error("Failed to initialize D3 container. SVG elements may not be available.");i?(this.showLoading(),this.updateLoadingProgress("Translating layout...")):this.hideLoading();let u=this.shadowRoot.querySelector("#svg-container").getBoundingClientRect(),c=u.width||800,l=u.height||600,d=await new exports.WebColaTranslator().translate(r,c,l,y);i&&this.updateLoadingProgress(`Computing layout for ${d.nodes.length} nodes...`);let m=d.nodes.length,b=pi.INITIAL_UNCONSTRAINED_ITERATIONS,C=pi.INITIAL_USER_CONSTRAINT_ITERATIONS,E=pi.INITIAL_ALL_CONSTRAINTS_ITERATIONS;v&&h&&(b=0,C=Math.min(10,C),E=Math.min(20,E)),m>100?(b=Math.max(v?0:5,Math.floor(b*.5)),C=Math.max(25,Math.floor(C*.5)),E=Math.max(100,Math.floor(E*.5))):m>50&&(b=Math.max(v?0:8,Math.floor(b*.8)),C=Math.max(40,Math.floor(C*.8)),E=Math.max(150,Math.floor(E*.75)));let{scaledConstraints:T,linkLength:G,groupCompactness:q}=this.getScaledDetails(d.constraints,gB,d.nodes,d.groups,d.links);i&&this.updateLoadingProgress("Applying constraints and initializing...");let B=v?.1:.001,K=Fd.d3adaptor(Ss).linkDistance(G).convergenceThreshold(B).avoidOverlaps(!0).handleDisconnected(!0).nodes(d.nodes).links(d.links).constraints(T).groups(d.groups).groupCompactness(q).size([d.FIG_WIDTH,d.FIG_HEIGHT]);if(e&&this.currentLayout?.nodes?.length){this.morphOldPositions=new Map;for(let V of this.currentLayout.nodes)V.x!=null&&V.y!=null&&this.morphOldPositions.set(V.id,{x:V.x,y:V.y});this.applyMorphExitSnapshot(d);}else this.morphOldPositions=null;this.currentLayout=d,this.colaLayout=K,e&&this.container&&this.snapshotOldGraph(),this.container.selectAll("*").remove(),this.renderGroups(d.groups,K),this.renderLinks(d.links,K),this.renderNodes(d.nodes,K),e&&this.container&&this.container.attr("opacity",0);let nt=0,w=b+C+E,H=!0;K.on("tick",()=>{if(H){if(nt++,nt%20===0){let V=Math.min(95,Math.round(nt/w*100));i&&this.updateLoadingProgress(`Computing layout... ${V}%`);}return}this.layoutFormat==="default"||!this.layoutFormat||this.layoutFormat===null?this.updatePositions():this.layoutFormat==="grid"&&this.gridUpdatePositions();}).on("end",()=>{H=!1,i&&this.updateLoadingProgress("Finalizing..."),e&&this.morphOldPositions&&this.morphOldPositions.size>0?(this.container&&this.container.attr("opacity",1),this.startMorphExitAnimation(),this.layoutFormat==="default"||!this.layoutFormat?this.updatePositions():this.layoutFormat==="grid"&&this.gridUpdatePositions(),this.hideEnteringElements(),this.animateMorphSlide()):(this.container&&this.container.attr("opacity",1),this.layoutFormat==="default"||!this.layoutFormat?(this.updatePositions(),this.routeEdges()):this.layoutFormat==="grid"&&(this.gridUpdatePositions(),this.gridify(10,25,10))),this.isUnsatCore&&this.showErrorIcon(),this.dispatchRelationsAvailableEvent(),this.dispatchEvent(new CustomEvent("layout-complete",{detail:{nodePositions:this.getNodePositions()}})),this.updateRoutingModeDropdown(),i&&this.hideLoading();});try{K.start(b,C,E,pi.GRID_SNAP_ITERATIONS);}catch(V){console.warn("WebCola layout start encountered an error, trying alternative approach:",V);try{K.start();}catch(tt){throw console.error("Both WebCola start methods failed:",tt),new Error(`WebCola layout failed to start: ${tt.message}`)}}}catch(g){console.error("Error rendering layout:",g),this.showError(`Layout rendering failed: ${g.message}`);}}snapshotOldGraph(){if(!this.svg||!this.container)return;this.svg.selectAll(".morph-old-graph").interrupt().remove();let r=this.container.node();if(!r)return;let o=r.cloneNode(true);o.setAttribute("class","morph-old-graph"),o.style.pointerEvents="none";let s=this.svg.node();s&&s.appendChild(o);}applyMorphExitSnapshot(r){if(!this.svg||!this.container)return;this.svg.selectAll(".morph-exit-layer").interrupt().remove();let o=this.currentLayout?.nodes||[],s=this.currentLayout?.links||[],e=new Set(r.nodes.map(c=>c.id)),i=new Set(r.links.map(c=>c.id)),a=new Set(o.map(c=>c.id)),h=new Set(s.map(c=>c.id));this.morphEnteringNodeIds=new Set([...e].filter(c=>!a.has(c))),this.morphEnteringEdgeIds=new Set([...i].filter(c=>!h.has(c)));let v=new Set([...a].filter(c=>!e.has(c))),_=new Set([...h].filter(c=>!i.has(c)));if(v.size===0&&_.size===0)return;let y=this.svg.node();if(!y)return;let g=document.createElementNS("http://www.w3.org/2000/svg","g");g.setAttribute("class","morph-exit-layer"),g.style.pointerEvents="none";let u=this.container.attr("transform");u&&g.setAttribute("transform",u),this.svgNodes&&this.svgNodes.each(function(c){v.has(c.id)&&g.appendChild(this.cloneNode(true));}),this.svgLinkGroups&&this.svgLinkGroups.each(function(c){let l=c.id,f=c.source?.id??"",d=c.target?.id??"";(_.has(l)||v.has(f)||v.has(d))&&g.appendChild(this.cloneNode(true));}),this.svgGroups&&this.svgGroups.each(function(c){c.id&&!r.groups.some(l=>l.id===c.id)&&g.appendChild(this.cloneNode(true));}),g.childElementCount!==0&&y.appendChild(g);}startMorphExitAnimation(){if(!this.svg)return;this.svg.selectAll(".morph-old-graph").remove();let r=this.svg.select(".morph-exit-layer");if(r.empty())return;let o=this.morphExitDurationMs;r.selectAll("g.link-group, g.inferredLinkGroup, g.alignmentLinkGroup").each(function(){let s=this.querySelector("path");if(!s)return;let e=s.getTotalLength();!e||e<=0||(s.setAttribute("stroke-dasharray",String(e)),s.setAttribute("stroke-dashoffset","0"),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",0),Ss.select(s).transition().duration(o).ease(Ss.easeCubicIn).attr("stroke-dashoffset",e));}),r.selectAll("g.node, rect.group").transition().duration(o).ease(Ss.easeCubicOut).attr("opacity",0),r.transition().duration(o).on("end",function(){Ss.select(this).remove();});}hideEnteringElements(){let r=this.morphEnteringNodeIds,o=this.morphEnteringEdgeIds;r.size===0&&o.size===0||(this.svgNodes&&r.size>0&&this.svgNodes.filter(s=>r.has(s.id)).attr("opacity",0),this.svgLinkGroups&&(o.size>0||r.size>0)&&this.svgLinkGroups.filter(s=>{if(o.has(s.id))return true;let e=s.source?.id??"",i=s.target?.id??"";return r.has(e)||r.has(i)}).attr("opacity",0));}applyMorphEnterTransition(){let r=this.morphEnteringNodeIds,o=this.morphEnteringEdgeIds;if(!(!(r.size>0||o.size>0)&&this.morphEnteringNodeIds.size===0&&this.morphEnteringEdgeIds.size===0)){if(this.svgNodes&&r.size>0&&this.svgNodes.filter(e=>r.has(e.id)).attr("opacity",0).transition().delay(this.morphEnterDelayMs).duration(this.morphEnterDurationMs).ease(Ss.easeCubicOut).attr("opacity",1),this.svgLinkGroups&&(o.size>0||r.size>0)&&this.svgLinkGroups.filter(e=>{if(o.has(e.id))return true;let i=e.source?.id??"",a=e.target?.id??"";return r.has(i)||r.has(a)}).each(function(){let e=this.querySelector("path");if(!e)return;let i=e.getTotalLength();!i||i<=0||(Ss.select(e).attr("stroke-dasharray",i).attr("stroke-dashoffset",i),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",0));}).attr("opacity",1).transition().delay(this.morphEnterDelayMs).duration(this.morphEnterDurationMs).ease(Ss.easeCubicOut).tween("draw-in",function(){let e=this.querySelector("path");if(!e)return ()=>{};let i=e.getTotalLength();if(!i||i<=0)return ()=>{};let a=Ss.interpolateNumber(i,0);return h=>{e.setAttribute("stroke-dashoffset",String(a(h)));}}).on("end",function(){let e=this.querySelector("path");e&&(e.removeAttribute("stroke-dasharray"),e.removeAttribute("stroke-dashoffset")),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",1);}),this.svgGroups&&this.svgGroupLabels){new Set((this.currentLayout?.groups||[]).map(i=>i.id).filter(Boolean));}this.morphEnteringNodeIds=new Set,this.morphEnteringEdgeIds=new Set;}}animateMorphSlide(){let r=this.morphOldPositions;if(!r||r.size===0||!this.currentLayout?.nodes){this.morphOldPositions=null;return}let o=this.currentLayout.nodes,s=this.morphSlideDurationMs;if(s<=0){this.morphOldPositions=null;return}let e=[];for(let h of o){let v=r.get(h.id);v&&e.push({node:h,oldX:v.x,oldY:v.y,finalX:h.x,finalY:h.y});}if(e.length===0){this.morphOldPositions=null;return}for(let h of e)h.node.x=h.oldX,h.node.y=h.oldY;this.updatePositions();let i=h=>1-Math.pow(1-h,3),a=performance.now();this.morphSlideTimer&&(this.morphSlideTimer.stop(),this.morphSlideTimer=null),this.morphSlideTimer=Ss.timer(()=>{let h=performance.now()-a,v=Math.min(1,h/s),_=i(v);for(let y of e)y.node.x=y.oldX+(y.finalX-y.oldX)*_,y.node.y=y.oldY+(y.finalY-y.oldY)*_;if(this.updatePositions(),v>=1){this.morphSlideTimer.stop(),this.morphSlideTimer=null;for(let y of e)y.node.x=y.finalX,y.node.y=y.finalY;this.updatePositions(),(this.layoutFormat==="default"||!this.layoutFormat)&&this.routeEdges(),this.applyMorphEnterTransition(),this.morphOldPositions=null;}});}setTransitionMode(r){this.setAttribute("transition-mode",r);}setMorphSpeed(r){this.setAttribute("morph-speed",String(Math.max(0,Math.min(r,1))));}clear(){if(this.colaLayout)try{this.colaLayout.stop?.();}catch{}this.container&&this.container.selectAll("*").remove(),this.svg&&this.svg.selectAll(".morph-exit-layer").interrupt().remove(),this.morphSlideTimer&&(this.morphSlideTimer.stop(),this.morphSlideTimer=null),this.morphOldPositions=null,this.currentLayout=null,this.colaLayout=null,this.svgNodes=null,this.svgLinks=null,this.svgGroups=null,this.edgeRoutingCache.edgesBetweenNodes.clear(),this.edgeRoutingCache.alignmentEdges.clear(),this.dragStartPositions.clear(),this.hideLoading();}getNodePositions(){return this.currentLayout?.nodes?this.currentLayout.nodes.map(r=>({id:r.id,x:r.x,y:r.y})):[]}getCurrentTransform(){if(this.svg&&this.svg.node())try{let r=Ss.zoomTransform(this.svg.node());return {k:r.k,x:r.x,y:r.y}}catch{return {k:1,x:0,y:0}}return {k:1,x:0,y:0}}getLayoutState(){return {positions:this.getNodePositions(),transform:this.getCurrentTransform()}}addToolbarControl(r){let o=this.shadowRoot?.querySelector("#graph-toolbar");o&&o.appendChild(r);}getToolbar(){return this.shadowRoot?.querySelector("#graph-toolbar")||null}renderGroups(r,o){if(!this.currentLayout.nodes||this.currentLayout.nodes.length===0){console.warn("Cannot render groups: nodes not available");return}this.svgGroups=this.setupGroups(r,this.currentLayout.nodes,o);}setupLinks(r,o){let s=this.container.selectAll(".link-group").data(r).enter().append("g").attr("class","link-group");return this.setupLinkPaths(s),this.setupLinkLabels(s),this.setupEdgeEndpointMarkers(s),s}setupLinkPaths(r){r.append("path").attr("class",o=>this.isAlignmentEdge(o)?"alignmentLink":this.isInferredEdge(o)?"inferredLink":"link").attr("data-link-id",o=>o.id||"").attr("stroke",o=>this.isAlignmentEdge(o)?"none":o.color).attr("fill","none").attr("opacity",o=>this.isAlignmentEdge(o)?0:null).style("stroke-width",o=>this.isAlignmentEdge(o)?"0":o.weight!=null?`${o.weight}px`:null).attr("stroke-dasharray",o=>this.isAlignmentEdge(o)?null:this.getEdgeDasharray(o.style)).attr("marker-end",o=>this.isAlignmentEdge(o)?"none":"url(#end-arrow)").attr("marker-start",o=>this.isAlignmentEdge(o)||!o.bidirectional?"none":"url(#start-arrow)").on("click.inputmode",o=>{this.isInputModeActive&&!this.isAlignmentEdge(o)&&(Ss.event.stopPropagation(),this.editEdgeLabel(o).catch(s=>{console.error("Error editing edge label:",s);}));}).style("cursor",()=>this.isInputModeActive?"pointer":"default");}getEdgeDasharray(r){if(!r)return null;switch(r.toLowerCase()){case "dotted":return "1,4";case "dashed":return "6,4";case "solid":return null;default:return null}}setupLinkLabels(r){r.filter(o=>!this.isAlignmentEdge(o)&&(this.isInferredEdge(o)||o.showLabel!==false)).append("text").attr("class","linklabel").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("font-family","system-ui").attr("pointer-events","none").text(o=>o.label||o.relName||"");}setupEdgeEndpointMarkers(r){r.filter(o=>!this.isAlignmentEdge(o)).append("circle").attr("class","edge-endpoint-marker target-marker").attr("r",8).attr("fill","#007bff").attr("stroke","white").attr("stroke-width",2).attr("opacity",0).attr("cursor","move").style("pointer-events","none").call(Ss.drag().on("start",o=>this.startEdgeEndpointDrag(o,"target")).on("drag",o=>this.dragEdgeEndpoint(o,"target")).on("end",o=>this.endEdgeEndpointDrag(o,"target"))),r.filter(o=>!this.isAlignmentEdge(o)).append("circle").attr("class","edge-endpoint-marker source-marker").attr("r",8).attr("fill","#28a745").attr("stroke","white").attr("stroke-width",2).attr("opacity",0).attr("cursor","move").style("pointer-events","none").call(Ss.drag().on("start",o=>this.startEdgeEndpointDrag(o,"source")).on("drag",o=>this.dragEdgeEndpoint(o,"source")).on("end",o=>this.endEdgeEndpointDrag(o,"source")));}startEdgeEndpointDrag(r,o){Ss.event.sourceEvent.stopPropagation(),this.edgeDragState.isDragging=true,this.edgeDragState.edge=r,this.edgeDragState.endpoint=o,console.log(`\u{1F535} Started dragging ${o} endpoint of edge:`,r.id);}dragEdgeEndpoint(r,o){if(!this.edgeDragState.isDragging)return;let[s,e]=Ss.mouse(this.container.node()),i=o==="target"?".target-marker":".source-marker";this.container.selectAll(".link-group").filter(a=>a.id===r.id).select(i).attr("cx",s).attr("cy",e);}async endEdgeEndpointDrag(r,o){if(!this.edgeDragState.isDragging)return;let[s,e]=Ss.mouse(this.container.node()),i=this.findNodeAtPosition(s,e);i?(console.log(`\u{1F517} Reconnecting ${o} to node:`,i.id),await this.reconnectEdge(r,o,i)):(console.log("\u{1F5D1}\uFE0F No node found - deleting edge:",r.id),await this.deleteEdge(r)),this.edgeDragState={isDragging:false,edge:null,endpoint:null,dragMarker:null},this.rerenderGraph();}findNodeAtPosition(r,o){if(!this.currentLayout?.nodes)return null;for(let s of this.currentLayout.nodes){let e=(s.visualWidth??s.width??0)/2,i=(s.visualHeight??s.height??0)/2;if(r>=s.x-e&&r<=s.x+e&&o>=s.y-i&&o<=s.y+i)return s}return null}async reconnectEdge(r,o,s){let e=this.getNodeFromEdge(r,"source"),i=this.getNodeFromEdge(r,"target");if(!e||!i){console.error("Could not find source or target node");return}let a,h;if(o==="source"?(a=s,h=i):(a=e,h=s),a.id===e.id&&h.id===i.id){console.log("\u23ED\uFE0F Edge already connected to this node, no change needed");return}let v=r.label||r.relName||"";if(!v.trim()){console.warn("Edge has no relation name, cannot reconnect");return}let _={atoms:[e.id,i.id],types:[e.type||"untyped",i.type||"untyped"]},y={atoms:[a.id,h.id],types:[a.type||"untyped",h.type||"untyped"]};console.log(`\u{1F504} Reconnecting edge from ${e.id}->${i.id} to ${a.id}->${h.id}`);let g=new CustomEvent("edge-reconnection-requested",{detail:{relationId:v,oldTuple:_,newTuple:y,oldSourceNodeId:e.id,oldTargetNodeId:i.id,newSourceNodeId:a.id,newTargetNodeId:h.id},bubbles:true});this.dispatchEvent(g);let u=this.currentLayout.nodes.findIndex(l=>l.id===a.id),c=this.currentLayout.nodes.findIndex(l=>l.id===h.id);u!==-1&&c!==-1&&(r.source=u,r.target=c);}async deleteEdge(r){let o=this.getNodeFromEdge(r,"source"),s=this.getNodeFromEdge(r,"target");if(!o||!s){console.error("Could not find source or target node for edge deletion");return}let e=r.label||r.relName||"";if(!e.trim()){console.warn("Edge has no relation name, cannot delete from data instance"),this.removeEdgeFromLayout(r);return}let i=[];if(r.groupId&&r.keyNodeId&&this.currentLayout){let h=(this.currentLayout.groups||[]).find(v=>v.id===r.groupId);if(h){let v=this.currentLayout.groups||[],_=this.collectGroupNodeIndices(h,v),y=this.currentLayout.nodes.find(g=>g.id===r.keyNodeId);for(let g of _){let u=this.currentLayout.nodes[g];u&&y&&i.push({atoms:[y.id,u.id],types:[y.type||"untyped",u.type||"untyped"]});}}}i.length===0&&i.push({atoms:[o.id,s.id],types:[o.type||"untyped",s.type||"untyped"]}),console.log(`\u{1F5D1}\uFE0F Deleting edge: ${e} (${i.length} tuple(s))`);let a=new CustomEvent("edge-modification-requested",{detail:{oldRelationId:e,newRelationId:"",sourceNodeId:o.id,targetNodeId:s.id,tuples:i},bubbles:true});this.dispatchEvent(a),this.removeEdgeFromLayout(r);}removeEdgeFromLayout(r){if(!this.currentLayout?.links)return;let o=this.currentLayout.links.findIndex(s=>s.id===r.id);o!==-1&&(this.currentLayout.links.splice(o,1),console.log(`\u2705 Edge removed from layout: ${r.id}`));}setupGroups(r,o,s){let e=this.setupGroupRectangles(r,o,s);return this.svgGroupLabels=this.setupGroupLabels(r,s),e}setupGroupRectangles(r,o,s){return this.container.selectAll(".group").data(r).enter().append("rect").attr("class",i=>this.isDisconnectedGroup(i)?"disconnectedNode":this.isErrorGroup(i)?"error-group":"group").attr("rx",pi.GROUP_BORDER_RADIUS).attr("ry",pi.GROUP_BORDER_RADIUS).style("fill",i=>this.isDisconnectedGroup(i)?"transparent":o[i.keyNode]?.color||"#cccccc").attr("fill-opacity",pi.GROUP_FILL_OPACITY).attr("stroke",i=>this.isDisconnectedGroup(i)?"none":o[i.keyNode]?.color||"#999999").attr("stroke-width",1).call(s.drag)}resolveGroupLeafToNodeIndex(r){if(typeof r=="number"&&Number.isInteger(r)&&r>=0)return r;if(r&&typeof r=="object"){let o=r;if(typeof o.index=="number"&&Number.isInteger(o.index)&&o.index>=0)return o.index;if(typeof o.id=="string"&&this.currentLayout?.nodes){let s=this.currentLayout.nodes.findIndex(e=>e.id===o.id);return s>=0?s:null}}return null}collectGroupNodeIndices(r,o){let s=new Set,e=new Set,i=(h,v)=>{if(h){if(typeof v=="number"){if(e.has(v))return;e.add(v);}Array.isArray(h.leaves)&&h.leaves.forEach(_=>{let y=this.resolveGroupLeafToNodeIndex(_);y!==null&&s.add(y);}),Array.isArray(h.groups)&&h.groups.forEach(_=>{typeof _=="number"&&Number.isInteger(_)&&_>=0&&_<o.length&&i(o[_],_);});}},a=o.indexOf(r);return i(r,a>=0?a:void 0),Array.from(s)}getNodeMainLabelFontSize(r){let o=r?._mainLabelFontSize;if(typeof o=="number"&&Number.isFinite(o))return o;let s=r?.visualWidth??r?.width??100,e=r?.visualHeight??r?.height??60,i=Math.max(1,s-pi.TEXT_PADDING*2),a=Math.max(1,e-pi.TEXT_PADDING*2),h=r?.label||r?.name||r?.id||"Node",v=Object.keys(r?.labels||{}).length>0,_=Object.keys(r?.attributes||{}).length>0,g=v||_?a*.5:a;return this.calculateOptimalFontSize(h,i,Math.max(1,g),"system-ui")}calculateGroupLabelFontSize(r,o){if(!this.currentLayout?.nodes?.length)return pi.DEFAULT_FONT_SIZE;let s=this.collectGroupNodeIndices(r,o);if(s.length===0)return pi.DEFAULT_FONT_SIZE;let e=s.map(h=>this.currentLayout.nodes[h]).filter(h=>!!h).map(h=>this.getNodeMainLabelFontSize(h));if(e.length===0)return pi.DEFAULT_FONT_SIZE;let i=e.reduce((h,v)=>h+v,0)/e.length,a=Math.max(pi.MIN_FONT_SIZE,Math.min(i,pi.MAX_FONT_SIZE));return Math.round(a*10)/10}setupGroupLabels(r,o){return this.container.selectAll(".groupLabel").data(r).enter().append("text").attr("class","groupLabel").attr("text-anchor","middle").attr("dominant-baseline","hanging").attr("font-family","system-ui").attr("font-size",s=>{let e=this.calculateGroupLabelFontSize(s,r);return s._groupLabelFontSize=e,`${e}px`}).attr("font-weight","bold").attr("fill","#333").attr("pointer-events","none").text(s=>s.showLabel||false?(s.padding&&(s.padding=Math.max(s.padding,pi.GROUP_LABEL_PADDING)),s.name||""):"").call(o.drag)}renderLinks(r,o){this.edgeRoutingCache.alignmentEdges.clear(),this.svgLinkGroups=this.setupLinks(r,o);}setupNodes(r,o){let s=o.drag();this.setupNodeDragHandlers(s);let e=this.container.selectAll(".node").data(r).enter().append("g").attr("class",i=>{let a=this.isErrorNode(i)?"error-node":"node";return this.isErrorNode(i)&&this.isSmallNode(i)?a+" small-error-node":a}).call(s).on("mousedown.inputmode",i=>{this.isInputModeActive&&(Ss.event.stopPropagation(),this.startEdgeCreation(i));}).on("mouseup.inputmode",i=>{this.isInputModeActive&&this.edgeCreationState.isCreating&&(Ss.event.stopPropagation(),this.finishEdgeCreation(i).catch(a=>{console.error("Error finishing edge creation:",a);}));}).on("mouseover",function(i){Ss.select(this).append("title").attr("class","node-tooltip").text(`ID: ${i.id}`);}).on("mouseout",function(){Ss.select(this).select("title.node-tooltip").remove();});return this.setupNodeRectangles(e),this.setupNodeIcons(e),this.setupMostSpecificTypeLabels(e),this.setupNodeLabels(e),e}setupNodeRectangles(r){r.append("rect").attr("width",o=>o.visualWidth??o.width).attr("height",o=>o.visualHeight??o.height).attr("x",o=>-(o.visualWidth??o.width)/2).attr("y",o=>-(o.visualHeight??o.height)/2).attr("stroke",o=>o.color||"black").attr("rx",pi.NODE_BORDER_RADIUS).attr("ry",pi.NODE_BORDER_RADIUS).attr("stroke-width",pi.NODE_STROKE_WIDTH).attr("fill",o=>{let s=this.isHiddenNode(o),e=!!o.icon,i=o.showLabels;return s||e&&!i?"transparent":"white"});}setupNodeIcons(r){r.filter(o=>o.icon).append("image").attr("xlink:href",o=>o.icon).attr("width",o=>{let s=o.visualWidth??o.width;return o.showLabels?s*pi.SMALL_IMG_SCALE_FACTOR:s}).attr("height",o=>{let s=o.visualHeight??o.height;return o.showLabels?s*pi.SMALL_IMG_SCALE_FACTOR:s}).attr("x",o=>{let s=o.visualWidth??o.width;return o.showLabels?o.x+s-s*pi.SMALL_IMG_SCALE_FACTOR:o.x-s/2}).attr("y",o=>{let s=o.visualHeight??o.height;return o.y-s/2}).append("title").text(o=>o.label||o.name||o.id||"Node").on("error",function(o,s){Ss.select(this).attr("xlink:href","img/default.png"),console.error(`Failed to load icon for node ${s.id}: ${s.icon}`);});}setupMostSpecificTypeLabels(r){r.append("text").attr("class","mostSpecificTypeLabel").style("fill",o=>o.color||"black").text(o=>o.mostSpecificType||"");}getTextMeasurementContext(){return this.textMeasurementCanvas||(this.textMeasurementCanvas=document.createElement("canvas")),this.textMeasurementCanvas.getContext("2d")}measureTextWidth(r,o,s="system-ui"){let e=this.getTextMeasurementContext();return e.font=`${o}px ${s}`,e.measureText(r).width}calculateOptimalFontSize(r,o,s,e="system-ui"){let i=pi.DEFAULT_FONT_SIZE;for(;i>pi.MIN_FONT_SIZE;){let a=this.measureTextWidth(r,i,e),h=i*pi.LINE_HEIGHT_RATIO;if(a<=o&&h<=s)break;i-=.5;}for(;i<pi.MAX_FONT_SIZE;){let a=i+.5,h=this.measureTextWidth(r,a,e),v=a*pi.LINE_HEIGHT_RATIO;if(h>o||v>s)break;i=a;}return Math.max(pi.MIN_FONT_SIZE,Math.min(i,pi.MAX_FONT_SIZE))}wrapText(r,o,s,e="system-ui"){let i=r.split(/\s+/),a=[],h="";for(let v of i){let _=h?`${h} ${v}`:v;this.measureTextWidth(_,s,e)<=o?h=_:h?(a.push(h),h=v):a.push(v);}return h&&a.push(h),a}setupNodeLabelsWithDynamicSizing(r){r.append("text").attr("class","label").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("font-family","system-ui").attr("fill","black").each((o,s,e)=>{if(this.isHiddenNode(o)||!o.showLabels)return;let a=Ss.select(e[s]),h=o.width||100,v=o.height||60,_=h-pi.TEXT_PADDING*2,y=v-pi.TEXT_PADDING*2,g=o.label||o.name||o.id||"Node",u=o.attributes||{},c=Object.entries(u).sort(([V],[tt])=>V.localeCompare(tt)),l=o.labels||{},f=Object.entries(l),d=f.length>0,m=c.length>0,b=d||m,C=b?y*.5:y,E=this.calculateOptimalFontSize(g,_,C,"system-ui");o._mainLabelFontSize=E,a.attr("font-size",`${E}px`);let T=E*pi.LINE_HEIGHT_RATIO,G=f.length+c.length,q=b?-G*T*.5:0;o._labelVerticalOffset=q,o._labelLineHeight=T,a.append("tspan").attr("x",0).attr("dy",`${q}px`).attr("class","main-label-tspan").style("font-weight","bold").style("font-size",`${E}px`).text(g);let B="";for(let[V,tt]of f){let pt=Array.isArray(tt)?tt.join(", "):String(tt);pt.length>B.length&&(B=pt);}for(let[V,tt]of c){let pt=`${V}: ${tt}`;pt.length>B.length&&(B=pt);}let K=E*.65,nt=y-T,w=G>0?this.calculateOptimalFontSize(B||"SampleText",_,nt/G,"system-ui"):E*.8,H=Math.max(w,K);if(d){let V="black";for(let[tt,pt]of f){let J=Array.isArray(pt)?pt.join(", "):String(pt);a.append("tspan").attr("x",0).attr("dy",`${H*pi.LINE_HEIGHT_RATIO}px`).style("font-size",`${H}px`).style("fill",V).style("font-style","italic").text(J);}}if(m)for(let V=0;V<c.length;V++){let[tt,pt]=c[V],J=`${tt}: ${pt}`;a.append("tspan").attr("x",0).attr("dy",`${H*pi.LINE_HEIGHT_RATIO}px`).style("font-size",`${H}px`).text(J);}});}setupNodeLabels(r){this.setupNodeLabelsWithDynamicSizing(r);}renderNodes(r,o){this.svgNodes=this.setupNodes(r,o);}resolveGroupEdgeEndpoints(r){if(!r.groupId)return {source:r.source,target:r.target};let o=this.currentLayout?.groups||[],s=o.find(h=>h.id===r.groupId);if(this._groupEdgeDebugLogged||(this._groupEdgeDebugLogged=new Set),this._groupEdgeDebugLogged.has(r.id)||(this._groupEdgeDebugLogged.add(r.id),console.log("[groupEdge DEBUG]",{edgeId:r.id,groupId:r.groupId,keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id,sourceIsInt:typeof r.source=="number",targetIsInt:typeof r.target=="number",groupFound:!!s,groupId_on_group:s?.id,availableGroupIds:o.map(h=>h.id)})),!s)return {source:r.source,target:r.target};let e=r.source,i=r.target;r.source?.id===r.keyNodeId?i=s:r.target?.id===r.keyNodeId?e=s:console.warn("[groupEdge] keyNodeId matched neither side",{keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id});let a=e===s?r.source:i===s?r.target:null;if(a&&!s.bounds&&a.x!=null&&Fd?.Rectangle){let h=(a.visualWidth??a.width??50)/2,v=(a.visualHeight??a.height??30)/2;s.bounds=new Fd.Rectangle(a.x-h,a.x+h,a.y-v,a.y+v);}return {source:e,target:i}}updateNodePositionsOnly(){this.svgNodes&&(this.svgNodes.select("rect").attr("x",r=>r.x!=null?r.x-(r.visualWidth??r.width)/2:0).attr("y",r=>r.y!=null?r.y-(r.visualHeight??r.height)/2:0).attr("width",r=>r.visualWidth??r.width).attr("height",r=>r.visualHeight??r.height),this.svgNodes.select("image").attr("x",r=>{if(r.x==null)return 0;let o=r.visualWidth??r.width;return r.showLabels?r.x+o/2-o*pi.SMALL_IMG_SCALE_FACTOR:r.x-o/2}).attr("y",r=>{if(r.y==null)return 0;let o=r.visualHeight??r.height;return r.y-o/2}),this.svgNodes.select(".mostSpecificTypeLabel").attr("x",r=>r.x!=null?r.x-(r.visualWidth??r.width??0)/2+5:0).attr("y",r=>r.y!=null?r.y-(r.visualHeight??r.height??0)/2+10:0),this.svgNodes.select(".label").attr("x",r=>r.x??0).attr("y",r=>r.y??0).each((r,o,s)=>{if(r.x==null)return;let e=r._labelVerticalOffset||0,i=r._labelLineHeight||12;Ss.select(s[o]).selectAll("tspan").attr("x",r.x).attr("dy",(a,h)=>h===0?`${e}px`:`${i}px`);}));}updatePositions(){this.svgGroups.attr("x",r=>r.bounds.x).attr("y",r=>r.bounds.y).attr("width",r=>r.bounds.width()).attr("height",r=>r.bounds.height()).lower(),this.svgNodes.select("rect").each(r=>{r.bounds&&(r.innerBounds=r.bounds.inflate(-1));}).attr("x",r=>r.x-(r.visualWidth??r.width)/2).attr("y",r=>r.y-(r.visualHeight??r.height)/2).attr("width",r=>r.visualWidth??r.width).attr("height",r=>r.visualHeight??r.height),this.svgNodes.select("image").attr("x",r=>{let o=r.visualWidth??r.width;return r.showLabels?r.x+o/2-o*pi.SMALL_IMG_SCALE_FACTOR:r.x-o/2}).attr("y",r=>{let o=r.visualHeight??r.height;return r.showLabels,r.y-o/2}),this.svgNodes.select(".mostSpecificTypeLabel").attr("x",r=>r.x-(r.visualWidth??r.width??0)/2+5).attr("y",r=>r.y-(r.visualHeight??r.height??0)/2+10).raise(),this.svgNodes.select(".label").attr("x",r=>r.x).attr("y",r=>r.y).each((r,o,s)=>{let e=r._labelVerticalOffset||0,i=r._labelLineHeight||12;Ss.select(s[o]).selectAll("tspan").attr("x",r.x).attr("dy",(a,h)=>h===0?`${e}px`:`${i}px`);}).raise(),this.svgLinkGroups.select("path").attr("d",r=>{let{source:o,target:s}=this.resolveGroupEdgeEndpoints(r),e=this.getStableEdgePath(o,s);return this.lineFunction(e)}).attr("marker-end",r=>this.isAlignmentEdge(r)?"none":"url(#end-arrow)").attr("marker-start",r=>this.isAlignmentEdge(r)||!r.bidirectional?"none":"url(#start-arrow)").raise(),this.svgLinkGroups.select(".linklabel").attr("x",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?this.calculateNewPosition(o,"x"):(r.source.x+r.target.x)/2}).attr("y",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?this.calculateNewPosition(o,"y"):(r.source.y+r.target.y)/2}).style("font-size",()=>{let r=this.getCurrentZoomScale(),o=12,s=r<1?o/Math.sqrt(r):o;return `${Math.min(s,16)}px`}).raise(),this.updateEdgeEndpointMarkers(),this.svgGroupLabels.attr("x",r=>r.bounds?r.bounds.x+r.bounds.width()/2:0).attr("y",r=>{if(!r.bounds)return 0;let o=r._groupLabelFontSize||pi.DEFAULT_FONT_SIZE;return r.bounds.y+Math.max(4,o*.35)}).attr("text-anchor","middle").lower(),this.svgLinkGroups.selectAll("marker").raise(),this.svgLinkGroups.selectAll(".linklabel").raise(),this.svgNodes.selectAll(".error-node").raise();}updateEdgeEndpointMarkers(){this.svgLinkGroups&&(this.svgLinkGroups.select(".target-marker").attr("cx",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(o){let s=o.getTotalLength();return o.getPointAtLength(s).x}return r.target.x||0}).attr("cy",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(o){let s=o.getTotalLength();return o.getPointAtLength(s).y}return r.target.y||0}).attr("opacity",this.isInputModeActive?.8:0).style("pointer-events",this.isInputModeActive?"all":"none").raise(),this.svgLinkGroups.select(".source-marker").attr("cx",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?o.getPointAtLength(0).x:r.source.x||0}).attr("cy",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?o.getPointAtLength(0).y:r.source.y||0}).attr("opacity",this.isInputModeActive?.8:0).style("pointer-events",this.isInputModeActive?"all":"none").raise());}gridUpdatePositions(){this.ensureNodeBounds(true);let r=this.container.selectAll(".node"),o=this.container.selectAll(".mostSpecificTypeLabel"),s=this.container.selectAll(".label"),e=this.container.selectAll(".group"),i=this.container.selectAll(".groupLabel");r.select("rect").each(function(h){h.innerBounds=h.bounds.inflate(-1);}).attr("x",function(h){return h.bounds.x}).attr("y",function(h){return h.bounds.y}).attr("width",function(h){return h.bounds.width()}).attr("height",function(h){return h.bounds.height()}),r.select("image").attr("x",function(h){let v=h.visualWidth??h.width;return h.showLabels?h.x+v/2-v*pi.SMALL_IMG_SCALE_FACTOR:h.bounds.x}).attr("y",function(h){let v=h.visualHeight??h.height;return h.showLabels?h.y-v/2:h.bounds.y}),o.attr("x",function(h){return h.bounds.x+5}).attr("y",function(h){return h.bounds.y+10}).raise(),s.attr("x",h=>h.x).attr("y",h=>h.y).each(function(h){var v=0;Ss.select(this).selectAll("tspan").attr("x",h.x).attr("dy",function(){return v+=1,v===1?"0em":"1em"});}).raise(),e.attr("x",function(h){return h.bounds.x}).attr("y",function(h){return h.bounds.y}).attr("width",function(h){return h.bounds.width()}).attr("height",function(h){return h.bounds.height()}).lower(),i.attr("x",function(h){return h.bounds.x+h.bounds.width()/2}).attr("y",function(h){let v=h._groupLabelFontSize||pi.DEFAULT_FONT_SIZE;return h.bounds.y+Math.max(4,v*.35)}).attr("text-anchor","middle").raise();let a=this.container.selectAll(".link-group");a.select("path").attr("d",h=>{if(h.source?.id===h.target?.id){let f=this.createSelfLoopRoute(h);return this.lineFunction(f)}let{source:v,target:_}=this.resolveGroupEdgeEndpoints(h),y=f=>f.bounds?typeof f.bounds.cx=="function"?{x:f.bounds.cx(),y:f.bounds.cy()}:{x:(f.bounds.x+f.bounds.X)/2,y:(f.bounds.y+f.bounds.Y)/2}:{x:f.x??0,y:f.y??0},g=y(v),u=y(_),c=u.x-g.x,l=u.y-g.y;if(Math.abs(c)>Math.abs(l)){let f=g.x+c/2;return this.gridLineFunction([{x:g.x,y:g.y},{x:f,y:g.y},{x:f,y:u.y},{x:u.x,y:u.y}])}else {let f=g.y+l/2;return this.gridLineFunction([{x:g.x,y:g.y},{x:g.x,y:f},{x:u.x,y:f},{x:u.x,y:u.y}])}}),a.select("text.linklabel").attr("x",h=>{let v=this.shadowRoot?.querySelector(`path[data-link-id="${h.id}"]`);if(v){let g=v.getTotalLength();return v.getPointAtLength(g/2).x}let _=h.source?.x??h.source?.bounds?.cx()??0,y=h.target?.x??h.target?.bounds?.cx()??0;return (_+y)/2}).attr("y",h=>{let v=this.shadowRoot?.querySelector(`path[data-link-id="${h.id}"]`);if(v){let g=v.getTotalLength();return v.getPointAtLength(g/2).y}let _=h.source?.y??h.source?.bounds?.cy()??0,y=h.target?.y??h.target?.bounds?.cy()??0;return (_+y)/2}).raise();}routeEdges(){try{this.ensureNodeBounds(!0),typeof this.colaLayout?.prepareEdgeRouting=="function"&&this.colaLayout.prepareEdgeRouting(pi.VIEWBOX_PADDING/pi.EDGE_ROUTE_MARGIN_DIVISOR),this.buildEdgeRoutingCaches(),this.routeLinkPaths(),this.updateLinkLabelsAfterRouting(),this.fitViewportToContent();}catch(r){console.error("Error in edge routing:",r),this.showError(`Edge routing failed: ${r.message}`);}}ensureNodeBounds(r=false){if(!(!this.currentLayout?.nodes||!Fd?.Rectangle))for(let o of this.currentLayout.nodes){if(!r&&o.bounds&&typeof o.bounds.rayIntersection=="function"){let _=o.bounds.cx(),y=o.bounds.cy(),g=1;if(Math.abs(_-(o.x||0))<g&&Math.abs(y-(o.y||0))<g)continue}let s=(o.visualWidth??o.width??50)/2,e=(o.visualHeight??o.height??30)/2,i=(o.x||0)-s,a=(o.x||0)+s,h=(o.y||0)-e,v=(o.y||0)+e;o.bounds=new Fd.Rectangle(i,a,h,v),o.innerBounds=o.bounds.inflate(-1);}}buildEdgeRoutingCaches(){this.edgeRoutingCache.edgesBetweenNodes.clear(),this.edgeRoutingCache.alignmentEdges.clear(),this.currentLayout?.links&&(this.currentLayout.links.forEach(r=>{r.id?.startsWith("_alignment_")&&this.edgeRoutingCache.alignmentEdges.add(r.id);}),this.currentLayout.links.forEach(r=>{if(this.isAlignmentEdge(r))return;let o=r.source.id,s=r.target.id,e=this.getNodePairKey(o,s);this.edgeRoutingCache.edgesBetweenNodes.has(e)||this.edgeRoutingCache.edgesBetweenNodes.set(e,[]),this.edgeRoutingCache.edgesBetweenNodes.get(e).push(r);}));}getNodePairKey(r,o){return r<o?`${r}:${o}`:`${o}:${r}`}route(r=[],o=[],s,e){r.forEach(a=>{let h=a.bounds||a.innerBounds||this.createFallbackBounds(a);a.routerNode={name:a.name,bounds:h};}),o.forEach(a=>{a.bounds||console.warn("Grid routing group missing bounds; routing may be degraded.",a),a.routerNode={bounds:a.bounds?.inflate(-e)??a.bounds,children:(typeof a.groups<"u"?a.groups.map(h=>r.length+h.id):[]).concat(typeof a.leaves<"u"?a.leaves.map(h=>h.index):[])};});let i=r.concat(o).map((a,h)=>a.routerNode?(a.routerNode.id=h,a.routerNode):null).filter(Boolean);return new Fd.GridRouter(i,{getChildren:a=>a.children,getBounds:a=>a.bounds},s-e)}gridify(r,o,s){if(this.isGridifyingInProgress){console.warn("[gridify] Already in progress, skipping re-entrant call");return}this.isGridifyingInProgress=true;try{this.gridifyInternal(r,o,s);}catch(e){console.log("Error routing edges in GridRouter"),console.error(e);try{this.fallbackGridRouting(this.currentLayout?.links??[]);}catch(a){console.error("Fallback grid routing also failed:",a);}let i=document.getElementById("runtime_messages");if(i){let a=document.createElement("div");a.className="alert alert-danger alert-dismissible fade show",a.setAttribute("role","alert"),a.innerHTML="Runtime (WebCola) error when gridifying edges. You may have to click and drag these nodes slightly to un-stick layout.",i.querySelectorAll(".alert").forEach(v=>{v.innerHTML===a.innerHTML&&v.remove();}),i.appendChild(a);}}finally{this.isGridifyingInProgress=false;}}gridifyInternal(r,o,s){let e=this.currentLayout?.nodes??[],i=this.currentLayout?.groups??[],a=this.currentLayout?.links??[];if(e.length===0){console.warn("No nodes available for GridRouter; skipping gridify.");return}if(a.length===0){console.warn("No edges to route in GridRouter");return}console.log("[gridify] Node positions BEFORE ensureNodeBounds:"),e.slice(0,3).forEach(l=>{console.log(` ${l.id}: x=${l.x?.toFixed(2)}, y=${l.y?.toFixed(2)}, bounds.cx=${l.bounds?.cx?.()?.toFixed(2)}, bounds.x=${l.bounds?.x?.toFixed(2)}`);}),this.ensureNodeBounds(true);let h=e.filter(l=>!Number.isFinite(l.x)||!Number.isFinite(l.y));if(h.length>0){console.warn("[gridify] Found nodes with invalid positions, falling back to default routing:",h.map(l=>({id:l.id,x:l.x,y:l.y}))),this.fallbackGridRouting(a);return}console.log("[gridify] Node positions AFTER ensureNodeBounds:"),e.slice(0,3).forEach(l=>{console.log(` ${l.id}: x=${l.x?.toFixed(2)}, y=${l.y?.toFixed(2)}, bounds.cx=${l.bounds?.cx?.()?.toFixed(2)}, bounds.x=${l.bounds?.x?.toFixed(2)}`);});let v=this.route(e,i,o,s),_=[],y=a.filter(l=>{let f=l?.source?.routerNode&&l?.target?.routerNode,d=l?.source?.id===l?.target?.id;return f&&!d}),g=a.filter(l=>l?.source?.id===l?.target?.id);console.log("[gridify] Total edges:",a.length,"Routable:",y.length,"Self-loops:",g.length),y.length+g.length!==a.length&&a.filter(f=>(!f?.source?.routerNode||!f?.target?.routerNode)&&f?.source?.id!==f?.target?.id).forEach(f=>{console.warn("[gridify] Unroutable edge:",f.id,"source routerNode:",!!f?.source?.routerNode,"target routerNode:",!!f?.target?.routerNode,"source:",f?.source?.id,"x:",f?.source?.x,"y:",f?.source?.y,"target:",f?.target?.id,"x:",f?.target?.x,"y:",f?.target?.y);}),_=v.routeEdges(y,r,function(l){return l.source.routerNode.id},function(l){return l.target.routerNode.id});let u=new Map;y.forEach((l,f)=>{let d=_[f];l?.id&&d&&u.set(l.id,this.adjustGridRouteForEdge(l,d));}),console.log("[gridify] Routes generated:",u.size,"out of",y.length),this.container.selectAll(".link-group").data(a,l=>l.id??l).select("path").attr("d",l=>{if(l.source?.id===l.target?.id){let T=this.createSelfLoopRoute(l);return this.lineFunction(T)}let f=u.get(l.id);if(!f){let T=l.source?.x??l.source?.bounds?.cx()??0,G=l.source?.y??l.source?.bounds?.cy()??0,q=l.target?.x??l.target?.bounds?.cx()??0,B=l.target?.y??l.target?.bounds?.cy()??0;console.log("[gridify] Fallback path for edge:",l.id,"from",l.source?.id,"(",T,",",G,")","to",l.target?.id,"(",q,",",B,")");let K=q-T,nt=B-G;if(Math.abs(K)>Math.abs(nt)){let w=T+K/2;return this.gridLineFunction([{x:T,y:G},{x:w,y:G},{x:w,y:B},{x:q,y:B}])}else {let w=G+nt/2;return this.gridLineFunction([{x:T,y:G},{x:T,y:w},{x:q,y:w},{x:q,y:B}])}}let C=Fd.GridRouter.getRoutePath(f,5,3,7);return this.adjustGridRouteForArrowPositioning(l,C.routepath,f)||C.routepath}),this.gridUpdateLinkLabels(a,u),this.fitViewportToContent(),this.dispatchEvent(new Event("relationsAvailable"));}fallbackGridRouting(r){this.container.selectAll(".link-group").data(r,s=>s.id??s).select("path").attr("d",s=>{if(s.source?.id===s.target?.id){let y=this.createSelfLoopRoute(s);return this.lineFunction(y)}let e=s.source?.x??s.source?.bounds?.cx()??0,i=s.source?.y??s.source?.bounds?.cy()??0,a=s.target?.x??s.target?.bounds?.cx()??0,h=s.target?.y??s.target?.bounds?.cy()??0,v=a-e,_=h-i;if(Math.abs(v)>Math.abs(_)){let y=e+v/2;return this.gridLineFunction([{x:e,y:i},{x:y,y:i},{x:y,y:h},{x:a,y:h}])}else {let y=i+_/2;return this.gridLineFunction([{x:e,y:i},{x:e,y},{x:a,y},{x:a,y:h}])}}),this.fitViewportToContent();}gridUpdateLinkLabels(r,o){this.container.selectAll(".link-group").filter(e=>!this.isAlignmentEdge(e)).select("text.linklabel").attr("x",e=>{let i=this.shadowRoot?.querySelector(`path[data-link-id="${e.id}"]`);if(i)try{let h=i.getTotalLength();return i.getPointAtLength(h/2).x}catch{}return this.getGridRouteMidpoint(e,o)?.x??e.source?.x??e.source?.bounds?.cx()??0}).attr("y",e=>{let i=this.shadowRoot?.querySelector(`path[data-link-id="${e.id}"]`);if(i)try{let h=i.getTotalLength();return i.getPointAtLength(h/2).y}catch{}return this.getGridRouteMidpoint(e,o)?.y??e.source?.y??e.source?.bounds?.cy()??0}).attr("text-anchor","middle").attr("dominant-baseline","middle");}getGridRouteMidpoint(r,o){let s=o.get(r.id);if(!s){let y=r.source?.x??r.source?.bounds?.cx()??0,g=r.source?.y??r.source?.bounds?.cy()??0,u=r.target?.x??r.target?.bounds?.cx()??0,c=r.target?.y??r.target?.bounds?.cy()??0;return {x:(y+u)/2,y:(g+c)/2}}let e=[];if(s.forEach(y=>{e.length===0&&y.length>0&&e.push(y[0]),y.length>1&&e.push(y[1]);}),e.length<2)return null;let i=0,a=[];for(let y=0;y<e.length-1;y++){let g=e[y+1].x-e[y].x,u=e[y+1].y-e[y].y,c=Math.sqrt(g*g+u*u);a.push(c),i+=c;}let h=i/2,v=0;for(let y=0;y<a.length;y++){let g=a[y];if(v+g>=h){let u=h-v,c=g>0?u/g:0;return {x:e[y].x+c*(e[y+1].x-e[y].x),y:e[y].y+c*(e[y+1].y-e[y].y)}}v+=g;}let _=Math.floor(e.length/2);return e[_]}adjustGridRouteForEdge(r,o){if(!r?.id?.startsWith("_g_"))return o;let s=this.gridRouteToPoints(o);if(s.length<2)return o;let e=this.routeGroupEdge(r,s);return this.pointsToGridRoute(e)}adjustGridRouteForArrowPositioning(r,o,s){if(!o||!r.source||!r.target)return null;try{let e=this.gridRouteToPoints(s);if(e.length<2)return null;let i=r.source,a=r.target,h=i.bounds||{x:i.x-(i.width||0)/2,y:i.y-(i.height||0)/2,width:()=>i.width||0,height:()=>i.height||0},v=a.bounds||{x:a.x-(a.width||0)/2,y:a.y-(a.height||0)/2,width:()=>a.width||0,height:()=>a.height||0},y=this.getTouchDirection(h,v,5);if(y!=="none"){let{sourcePoint:f,targetPoint:d,middlePoints:m}=this.computePerpendicularRoute(h,v,y),b=[f,...m,d];return this.gridLineFunction(b)}let g=e.length>1?e[1]:e[0],u=this.getRectangleIntersection(h.x+h.width()/2,h.y+h.height()/2,g.x,g.y,h);u&&(e[0]=u);let c=e.length>1?e[e.length-2]:e[e.length-1],l=this.getRectangleIntersection(v.x+v.width()/2,v.y+v.height()/2,c.x,c.y,v);return l&&(e[e.length-1]=l),this.gridLineFunction(e)}catch(e){return console.warn("Error adjusting grid route for arrow positioning:",e),null}}getTouchDirection(r,o,s){let e=r.x,i=r.x+r.width(),a=r.y,h=r.y+r.height(),v=o.x,_=o.x+o.width(),y=o.y,g=o.y+o.height(),u=Math.max(0,Math.max(v-i,e-_)),c=Math.max(0,Math.max(y-h,a-g)),l=!(h<y||g<a),f=!(i<v||_<e);return u<=s&&l?"horizontal":c<=s&&f?"vertical":"none"}computePerpendicularRoute(r,o,s){let e=r.width(),i=r.height(),a=o.width(),h=o.height(),v=r.x+e/2,_=r.y+i/2,y=o.x+a/2,g=o.y+h/2,u=15;if(s==="horizontal")if(_<=g){let l=Math.min(r.y,o.y)-u;return {sourcePoint:{x:v,y:r.y},targetPoint:{x:y,y:o.y},middlePoints:[{x:v,y:l},{x:y,y:l}]}}else {let l=Math.max(r.y+i,o.y+h)+u;return {sourcePoint:{x:v,y:r.y+i},targetPoint:{x:y,y:o.y+h},middlePoints:[{x:v,y:l},{x:y,y:l}]}}else if(v<=y){let l=Math.min(r.x,o.x)-u;return {sourcePoint:{x:r.x,y:_},targetPoint:{x:o.x,y:g},middlePoints:[{x:l,y:_},{x:l,y:g}]}}else {let l=Math.max(r.x+e,o.x+a)+u;return {sourcePoint:{x:r.x+e,y:_},targetPoint:{x:o.x+a,y:g},middlePoints:[{x:l,y:_},{x:l,y:g}]}}}areBoundsNear(r,o,s){let e=r.x,i=r.x+r.width(),a=r.y,h=r.y+r.height(),v=o.x,_=o.x+o.width(),y=o.y,g=o.y+o.height(),u=Math.max(0,Math.max(v-i,e-_)),c=Math.max(0,Math.max(y-h,a-g));return Math.sqrt(u*u+c*c)<=s}chooseBoundaryPoint(r,o,s,e){let i=Math.max(1,s.width()),a=Math.max(1,s.height()),h=[{x:s.x,y:s.y+a/2},{x:s.x+i,y:s.y+a/2},{x:s.x+i/2,y:s.y},{x:s.x+i/2,y:s.y+a}],v=h[0],_=-1/0;for(let y of h){let g=y.x-e.x,u=y.y-e.y,c=Math.sqrt(g*g+u*u);c>_&&(_=c,v=y);}return v}normalizeNodeBounds(r){let o=r.visualWidth??r.width??50,s=r.visualHeight??r.height??30,e=r.bounds||{x:r.x-o/2,y:r.y-s/2,width:()=>o,height:()=>s};return {x:typeof e.x=="number"||e.X!==void 0?e.x:r.x-o/2,y:typeof e.y=="number"?e.y:r.y-s/2,width:()=>typeof e.width=="function"?e.width():e.X!==void 0?e.X-e.x:o,height:()=>typeof e.height=="function"?e.height():e.Y!==void 0?e.Y-e.y:s}}lineIntersectsRect(r,o,s){let e=s.x,i=s.x+s.width(),a=s.y,h=s.y+s.height(),v=Math.min(r.x,o.x),_=Math.max(r.x,o.x),y=Math.min(r.y,o.y),g=Math.max(r.y,o.y);if(_<e||v>i||g<a||y>h)return false;let u=r.x>=e&&r.x<=i&&r.y>=a&&r.y<=h,c=o.x>=e&&o.x<=i&&o.y>=a&&o.y<=h;if(u||c)return true;let l=o.x-r.x,f=o.y-r.y,d=(b,C,E)=>{if(f===0)return false;let T=(b-r.y)/f;if(T<0||T>1)return false;let G=r.x+T*l;return G>=C&&G<=E},m=(b,C,E)=>{if(l===0)return false;let T=(b-r.x)/l;if(T<0||T>1)return false;let G=r.y+T*f;return G>=C&&G<=E};return d(a,e,i)||d(h,e,i)||m(e,a,h)||m(i,a,h)}findBlockingNodes(r,o,s,e){if(!this.currentLayout?.nodes)return [];let i=this.normalizeNodeBounds(r),a=this.normalizeNodeBounds(o),h={x:i.x+i.width()/2,y:i.y+i.height()/2},v={x:a.x+a.width()/2,y:a.y+a.height()/2},_=[];for(let y of this.currentLayout.nodes){if(y.id===s||y.id===e)continue;let g=this.normalizeNodeBounds(y);if(this.lineIntersectsRect(h,v,g)){let u={x:g.x+g.width()/2,y:g.y+g.height()/2},c=Math.sqrt(Math.pow(u.x-h.x,2)+Math.pow(u.y-h.y,2));_.push({node:y,bounds:g,distance:c});}}return _.sort((y,g)=>y.distance-g.distance),_.map(y=>({node:y.node,bounds:y.bounds}))}computeRouteAroundBlockingNodes(r,o,s){let i=Math.min(r.x,o.x),a=Math.max(r.x+r.width(),o.x+o.width()),h=Math.min(r.y,o.y),v=Math.max(r.y+r.height(),o.y+o.height());for(let{bounds:f}of s)i=Math.min(i,f.x),a=Math.max(a,f.x+f.width()),h=Math.min(h,f.y),v=Math.max(v,f.y+f.height());let _=r.x+r.width()/2,y=r.y+r.height()/2,g=o.x+o.width()/2,u=o.y+o.height()/2,c=Math.abs(g-_);if(Math.abs(u-y)>c)if(_<=g){let d=i-15;return {sourcePoint:{x:r.x,y},targetPoint:{x:o.x,y:u},middlePoints:[{x:d,y},{x:d,y:u}]}}else {let d=a+15;return {sourcePoint:{x:r.x+r.width(),y},targetPoint:{x:o.x+o.width(),y:u},middlePoints:[{x:d,y},{x:d,y:u}]}}else if(y<=u){let d=h-15;return {sourcePoint:{x:_,y:r.y},targetPoint:{x:g,y:o.y},middlePoints:[{x:_,y:d},{x:g,y:d}]}}else {let d=v+15;return {sourcePoint:{x:_,y:r.y+r.height()},targetPoint:{x:g,y:o.y+o.height()},middlePoints:[{x:_,y:d},{x:g,y:d}]}}}getNearTouchPerpendicularRoute(r){if(!r.source||!r.target||r.source.id===r.target.id)return null;let o=r.source,s=r.target,e=this.normalizeNodeBounds(o),i=this.normalizeNodeBounds(s),h=this.getTouchDirection(e,i,5);if(h!=="none"){let{sourcePoint:_,targetPoint:y,middlePoints:g}=this.computePerpendicularRoute(e,i,h);return [_,...g,y]}let v=this.findBlockingNodes(o,s,o.id,s.id);if(v.length>0){let{sourcePoint:_,targetPoint:y,middlePoints:g}=this.computeRouteAroundBlockingNodes(e,i,v);return [_,...g,y]}return null}gridRouteToPoints(r){let o=[];return r.forEach((s,e)=>{e===0&&o.push({x:s[0].x,y:s[0].y}),o.push({x:s[1].x,y:s[1].y});}),o}pointsToGridRoute(r){let o=[];for(let s=0;s<r.length-1;s+=1)o.push([r[s],r[s+1]]);return o}createFallbackBounds(r){if(!Fd?.Rectangle)return null;let o=((r.visualWidth??r.width)||50)/2,s=((r.visualHeight??r.height)||30)/2,e=(r.x||0)-o,i=(r.x||0)+o,a=(r.y||0)-s,h=(r.y||0)+s;return new Fd.Rectangle(e,i,a,h)}getRectangleIntersection(r,o,s,e,i){let a=i.x,h=i.x+i.width(),v=i.y,_=i.y+i.height(),y=s-r,g=e-o;if(y===0&&g===0)return {x:r,y:o};let u=0,c=1;if(y!==0){let f=(a-r)/y,d=(h-r)/y;u=Math.max(u,Math.min(f,d)),c=Math.min(c,Math.max(f,d));}if(g!==0){let f=(v-o)/g,d=(_-o)/g;u=Math.max(u,Math.min(f,d)),c=Math.min(c,Math.max(f,d));}if(u>c)return null;let l=u>0?u:c;return {x:r+l*y,y:o+l*g}}routeLinkPaths(){this.container.selectAll(".link-group path").attr("d",r=>{try{return this.routeSingleEdge(r)}catch(o){return console.error(`Error routing edge ${r.id} from ${r.source.id} to ${r.target.id}:`,o),this.showRuntimeAlert(r.source.id,r.target.id),this.lineFunction([{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}])}});}routeSingleEdge(r){if(this.isAlignmentEdge(r))return this.lineFunction([{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}]);let o=[{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}],s;if(typeof this.colaLayout?.routeEdge=="function")try{if(s=this.colaLayout.routeEdge(r),!s||!Array.isArray(s)||s.length<2||!s[0]||!s[1]||s[0].x===void 0||s[0].y===void 0)throw new Error(`WebCola failed to route edge ${r.id} from ${r.source.id} to ${r.target.id}`)}catch(i){return console.log("Error routing edge",r.id,`from ${r.source.id} to ${r.target.id}`),console.error(i),this.lineFunction(o)}else s=o;if(r.source.id===r.target.id)s=this.createSelfLoopRoute(r);else {if(r.id?.startsWith("_g_"))return s=this.routeGroupEdge(r,s),this.lineFunction(s);s=this.handleMultipleEdgeRouting(r,s);}let e=this.getNearTouchPerpendicularRoute(r);return e?this.lineFunction(e):this.lineFunction(s)}createSelfLoopRoute(r){let o=r.source,s=o.bounds;if(!s)return [{x:o.x,y:o.y},{x:o.x+20,y:o.y-20},{x:o.x,y:o.y}];let e=s.X-s.x,i=s.Y-s.y,a={x:s.x+e/2,y:s.y},h={x:s.X,y:s.y+i/2},_=1+(r.selfLoopIndex||0)*pi.SELF_LOOP_CURVATURE_SCALE,y={x:s.X+e/2*_,y:s.y-i/2*_};return [a,y,h]}routeGroupEdge(r,o){let s=r.groupId?(this.currentLayout?.groups||[]).find(e=>e.id===r.groupId):null;if(!s)console.warn("[routeGroupEdge] Group not found for edge:",r.id,"\u2014 groupId:",r.groupId);else {if(!s.bounds&&Fd?.Rectangle){let e=r.source?.id===r.keyNodeId?o[o.length-1]:o[0];e&&(s.bounds=new Fd.Rectangle(e.x-50,e.x+50,e.y-30,e.y+30));}if(s.bounds)if(r.source?.id===r.keyNodeId)o[o.length-1]=this.closestPointOnRect(s.bounds,o[0]);else if(r.target?.id===r.keyNodeId){let e=s.bounds.inflate?.(-1)??s.bounds;o[0]=this.closestPointOnRect(e,o[o.length-1]);}else console.warn("[routeGroupEdge] keyNodeId matched neither side",{keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id});}return o.length>2&&o.splice(1,o.length-2),o}handleMultipleEdgeRouting(r,o){let s=this.getAllEdgesBetweenNodes(r.source.id,r.target.id);if(s.length<=1)return o;if(o.length===2){let _={x:(o[0].x+o[1].x)/2,y:(o[0].y+o[1].y)/2};o.splice(1,0,_);}let e=o[1].x-o[0].x,i=o[1].y-o[0].y,a=Math.atan2(i,e),h=this.getRouteLength(o),v=s.findIndex(_=>_.id===r.id);if(v!==-1){o=this.applyEdgeOffsetWithIndex(r,o,s,a,v,h);let _=this.calculateCurvatureWithIndex(s,r.id,v),y=this.clampCurvature(_);o=this.applyCurvatureToRoute(o,y,a,h);}return o}getAllEdgesBetweenNodes(r,o){if(!this.currentLayout?.links)return [];let s=this.getNodePairKey(r,o);return this.edgeRoutingCache.edgesBetweenNodes.has(s)?this.edgeRoutingCache.edgesBetweenNodes.get(s):this.currentLayout.links.filter(e=>!this.isAlignmentEdge(e)&&(e.source.id===r&&e.target.id===o||e.source.id===o&&e.target.id===r))}calculateCurvature(r,o,s,e){if(e.startsWith("_alignment_"))return 0;let i=r.length,a=r.findIndex(h=>h.id===e);return i<=1?0:(a%2===0?1:-1)*(Math.floor(a/2)+1)*pi.CURVATURE_BASE_MULTIPLIER*i}calculateCurvatureWithIndex(r,o,s){let e=r.length;return e<=1?0:(s%2===0?1:-1)*(Math.floor(s/2)+1)*pi.CURVATURE_BASE_MULTIPLIER*e}applyEdgeOffset(r,o,s,e){let i=s.findIndex(h=>h.id===r.id),a=this.getRouteLength(o);return this.applyEdgeOffsetWithIndex(r,o,s,e,i,a)}applyEdgeOffsetWithIndex(r,o,s,e,i,a){let h=(i%2===0?1:-1)*(Math.floor(i/2)+1)*pi.MIN_EDGE_DISTANCE,v=this.clampOffset(h,a),_=this.getDominantDirection(e);return _==="right"||_==="left"?(o[0].y+=v,o[o.length-1].y+=v):(_==="up"||_==="down")&&(o[0].x+=v,o[o.length-1].x+=v),r.source.innerBounds&&(o[0]=this.adjustPointToRectanglePerimeter(o[0],r.source.innerBounds)),r.target.innerBounds&&(o[o.length-1]=this.adjustPointToRectanglePerimeter(o[o.length-1],r.target.innerBounds)),o}clampOffset(r,o){let s=Math.max(pi.MIN_EDGE_DISTANCE,o*pi.MAX_EDGE_OFFSET_RATIO);return Math.max(-s,Math.min(s,r))}getRouteLength(r){return r.length<2?0:r.slice(1).reduce((o,s,e)=>{let i=r[e],a=s.x-i.x,h=s.y-i.y;return o+Math.sqrt(a*a+h*h)},0)}clampCurvature(r){return Math.max(-pi.MAX_EDGE_CURVATURE_RATIO,Math.min(pi.MAX_EDGE_CURVATURE_RATIO,r))}applyCurvatureToRoute(r,o,s,e){return o===0||r.forEach((i,a)=>{if(a>0&&a<r.length-1){let h=o*Math.abs(Math.sin(s))*e,v=o*Math.abs(Math.cos(s))*e;i.x+=h,i.y+=v;}}),r}getDominantDirection(r){return r=(r+Math.PI)%(2*Math.PI)-Math.PI,r>=-Math.PI/4&&r<=Math.PI/4?"right":r>Math.PI/4&&r<3*Math.PI/4?"up":r>=3*Math.PI/4||r<=-3*Math.PI/4?"left":r>-3*Math.PI/4&&r<-Math.PI/4?"down":null}closestPointOnRect(r,o){if(!r)return o;let{x:s,y:e,X:i,Y:a}=r,h=Math.max(s,Math.min(o.x,i)),v=Math.max(e,Math.min(o.y,a));return {x:h,y:v}}getStableEdgeAnchor(r,o){if(!r)return o;let s,e,i,a;if(typeof r.cx=="function")s=r.cx(),e=r.cy(),i=r.width()/2,a=r.height()/2;else if(r.x!==void 0&&r.X!==void 0)s=(r.x+r.X)/2,e=(r.y+r.Y)/2,i=(r.X-r.x)/2,a=(r.Y-r.y)/2;else return o;let h=o.x-s,v=o.y-e,_=Math.abs(h)/i,y=Math.abs(v)/a;return _>y?h>0?{x:s+i,y:e}:{x:s-i,y:e}:v>0?{x:s,y:e+a}:{x:s,y:e-a}}getStableEdgePath(r,o){let s={x:r.x||0,y:r.y||0},e={x:o.x||0,y:o.y||0},i=y=>{let g=((y.visualWidth??y.width)||0)/2,u=((y.visualHeight??y.height)||0)/2;if(g===0&&u===0)return null;let c=y.x||0,l=y.y||0;return {cx:()=>c,cy:()=>l,width:()=>g*2,height:()=>u*2,x:c-g,X:c+g,y:l-u,Y:l+u}},a=i(r)??r.bounds??r.innerBounds,h=i(o)??o.bounds??o.innerBounds,v=a?this.getStableEdgeAnchor(a,e):s,_=h?this.getStableEdgeAnchor(h,s):e;return [v,_]}adjustPointToRectanglePerimeter(r,o){return o?this.closestPointOnRect(o,r):r}updateLinkLabelsAfterRouting(){this.container.selectAll(".link-group .linklabel").attr("x",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(!o)return 0;let s=o.getTotalLength();return o.getPointAtLength(s/2).x}).attr("y",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(!o)return 0;let s=o.getTotalLength();return o.getPointAtLength(s/2).y}).attr("text-anchor","middle").each((r,o,s)=>{this.handleLabelOverlap(s[o]);}).raise();}handleLabelOverlap(r){let o=[];this.container.selectAll(".linklabel").each(function(){this!==r&&V0t(this,r)&&o.push(this);}),o.length>0&&this.minimizeOverlap(r,o);}minimizeOverlap(r,o){}fitViewportToContent(r=false){let o=this.svg?.node();if(!o||!this.zoomBehavior||this.userHasManuallyZoomed&&!this.isInitialRender&&!r)return;let s=this.calculateContentBounds();if(!s)return;let e=o.clientWidth||o.parentElement?.clientWidth||800,i=o.clientHeight||o.parentElement?.clientHeight||600,a=pi.VIEWBOX_PADDING*4,h=(e-a*2)/s.width,v=(i-a*2)/s.height,_=Math.min(h,v,1),[y,g]=this.zoomBehavior.scaleExtent(),u=Math.max(y,Math.min(g,_)),c=s.x+s.width/2,l=s.y+s.height/2,f=e/2-c*u,d=i/2-l*u,m=Ss.zoomIdentity.translate(f,d).scale(u);this.isInitialRender?(this.svg.call(this.zoomBehavior.transform,m),this.isInitialRender=false):this.svg.transition().duration(300).ease(Ss.easeCubicOut).call(this.zoomBehavior.transform,m),this.updateZoomControlStates();}resetViewToFitContent(){this.userHasManuallyZoomed=false,this.fitViewportToContent(true);}calculateContentBounds(){try{if(!this.currentLayout||!this.container)return null;let r=1/0,o=1/0,s=-1/0,e=-1/0,i=(c,l,f,d)=>{[c,l,f,d].every(Number.isFinite)&&(r=Math.min(r,c),s=Math.max(s,l),o=Math.min(o,f),e=Math.max(e,d));},a=this.currentLayout.nodes;a&&a.length>0&&a.forEach(c=>{if(this.isHiddenNode(c)||typeof c.x!="number"||typeof c.y!="number")return;let l=c.visualWidth??c.width??0,f=c.visualHeight??c.height??0,d=l/2,m=f/2;i(c.x-d,c.x+d,c.y-m,c.y+m);});let h=this,v=this.container.selectAll(".link-group path");v.empty()||v.each(function(c){if(!(c?.id&&h.isAlignmentEdge(c)))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x,l.x+l.width,l.y,l.y+l.height);}catch{}});let _=this.container.selectAll(".node, .error-node");_.empty()||_.each(function(c){if(!h.isHiddenNode(c))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x,l.x+l.width,l.y,l.y+l.height);}catch{}});let y=this.container.selectAll("text");y.empty()||y.each(function(c){if(!(c&&(typeof c.name=="string"||typeof c.id=="string")&&h.isHiddenNode(c)))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x-5,l.x+l.width+5,l.y-5,l.y+l.height+5);}catch{}});let g=this.container.selectAll(".group");return g.empty()||g.each(function(){try{let c=this.getBBox();(c.width>0||c.height>0)&&i(c.x,c.x+c.width,c.y,c.y+c.height);}catch{}}),r===1/0||o===1/0||s===-1/0||e===-1/0?(console.warn("Could not calculate content bounds - no valid elements found"),null):{x:r,y:o,width:s-r,height:e-o}}catch(r){return console.error("Error calculating content bounds:",r),null}}dispatchRelationsAvailableEvent(){let r=this.getAllRelations(),o=new CustomEvent("relations-available",{detail:{relations:r,count:r.length,timestamp:Date.now(),graphId:this.id||"unknown"},bubbles:true,cancelable:true});this.dispatchEvent(o);}getAllRelations(){if(!this.currentLayout?.links)return [];let r=new Set(this.currentLayout.links.filter(o=>!this.isAlignmentEdge(o)).map(o=>o.relName).filter(Boolean));return Array.from(r)}highlightRelation(r){return this.currentLayout?.links?(this.svgLinkGroups.filter(o=>o.relName===r&&!this.isAlignmentEdge(o)).selectAll("path").classed("highlighted",true),true):false}clearHighlightRelation(r){return this.currentLayout?.links?(this.svgLinkGroups.filter(o=>o.relName===r&&!this.isAlignmentEdge(o)).selectAll("path").classed("highlighted",false),true):false}highlightNodes(r){if(!this.currentLayout?.nodes||!this.svgNodes||!r||r.length===0)return false;let o=new Set(r),s=false;return this.svgNodes.each((e,i,a)=>{o.has(e.id)&&(Ss.select(a[i]).classed("highlighted",true),s=true);}),s}highlightNodePairs(r,o={}){if(!this.currentLayout?.nodes||!this.svgNodes||!r||r.length===0)return false;let{showBadges:s=false}=o,e=new Set,i=new Set;r.forEach((h,v)=>{if(!Array.isArray(h)){console.warn(`highlightNodePairs: Pair at index ${v} is not an array, skipping`);return}if(h.length!==2){console.warn(`highlightNodePairs: Pair at index ${v} has ${h.length} elements (expected 2), skipping`);return}let[_,y]=h;_&&e.add(_),y&&i.add(y);});let a=false;return this.svgNodes.each((h,v,_)=>{let y=Ss.select(_[v]);e.has(h.id)&&(y.classed("highlighted-first",true),a=true,s&&this.addHighlightBadge(y,h,"1","#007aff")),i.has(h.id)&&(y.classed("highlighted-second",true),a=true,s&&(e.has(h.id)?this.addHighlightBadge(y,h,"1,2","#9B59B6"):this.addHighlightBadge(y,h,"2","#ff3b30")));}),a}clearNodeHighlights(){return this.svgNodes?(this.svgNodes.classed("highlighted",false).classed("highlighted-first",false).classed("highlighted-second",false).selectAll(".highlight-badge, .highlight-badge-bg").remove(),true):false}addHighlightBadge(r,o,s,e){r.selectAll(".highlight-badge, .highlight-badge-bg").remove();let i=16,a=4,h=(o.width||0)/2-i/2-a,v=-(o.height||0)/2+i/2+a;r.append("circle").attr("class","highlight-badge-bg").attr("cx",h).attr("cy",v).attr("r",i/2).attr("fill",e),r.append("text").attr("class","highlight-badge").attr("x",h).attr("y",v).attr("dy","0.35em").text(s);}showRuntimeAlert(r,o){console.warn(`Runtime (WebCola) error when laying out an edge from ${r} to ${o}. You may have to click and drag these nodes slightly to un-stick layout.`);}getCSS(){return `
851
+ `;}initializeD3(){Ss||(Ss=window.d3),this.svg=Ss.select(this.shadowRoot.querySelector("#svg")),this.container=this.svg.select(".zoomable"),Ss.zoom?(this.zoomBehavior=Ss.zoom().scaleExtent([.01,20]).on("start",()=>{Ss.event.sourceEvent&&(this.userHasManuallyZoomed=true);}).on("zoom",()=>{this.container.attr("transform",Ss.event.transform),this.updateZoomControlStates(),this.updateSmallNodeClasses();}),this.svg.call(this.zoomBehavior),this.initializeZoomControls()):console.warn("D3 zoom behavior not available. Ensure D3 v4+ is loaded.");}initializeZoomControls(){let r=this.shadowRoot.querySelector("#zoom-in"),o=this.shadowRoot.querySelector("#zoom-out"),s=this.shadowRoot.querySelector("#zoom-fit");r&&r.addEventListener("click",()=>{this.userHasManuallyZoomed=true,this.zoomIn();}),o&&o.addEventListener("click",()=>{this.userHasManuallyZoomed=true,this.zoomOut();}),s&&s.addEventListener("click",()=>{this.resetViewToFitContent();});let e=this.shadowRoot.querySelector("#routing-mode");if(e){let a=this.layoutFormat||"default";e.value=a,e.addEventListener("change",()=>{this.handleRoutingModeChange(e.value);});}let i=this.shadowRoot.querySelector("#screenshot-btn");i&&i.addEventListener("click",()=>{this.takeScreenshot();}),this.updateZoomControlStates();}handleRoutingModeChange(r){this.setAttribute("layoutFormat",r),this.currentLayout&&this.colaLayout&&(r==="grid"?this.gridify(10,25,10):this.routeEdges(),this.dispatchEvent(new CustomEvent("routing-mode-changed",{detail:{mode:r}})));}updateRoutingModeDropdown(){let r=this.shadowRoot?.querySelector("#routing-mode");if(r){let o=this.layoutFormat||"default";r.value=o;}}initializeInputModeHandlers(){this.inputModeEnabled&&this.attachInputModeListeners();}attachInputModeListeners(){this.inputModeListenersAttached||(document.addEventListener("keydown",this.handleInputModeKeydown),document.addEventListener("keyup",this.handleInputModeKeyup),window.addEventListener("blur",this.handleInputModeBlur),this.inputModeListenersAttached=true);}detachInputModeListeners(){this.inputModeListenersAttached&&(document.removeEventListener("keydown",this.handleInputModeKeydown),document.removeEventListener("keyup",this.handleInputModeKeyup),window.removeEventListener("blur",this.handleInputModeBlur),this.inputModeListenersAttached=false);}activateInputMode(){this.isInputModeActive=true,this.svg&&this.svg.classed("input-mode",true),this.disableNodeDragging(),this.disableZoom(),this.updateEdgeEndpointMarkers(),this.dispatchEvent(new CustomEvent("input-mode-activated",{detail:{active:true}}));}deactivateInputMode(){this.isInputModeActive=false,this.svg&&this.svg.classed("input-mode",false),this.cleanupEdgeCreation(),this.enableNodeDragging(),this.enableZoom(),this.updateEdgeEndpointMarkers(),this.dispatchEvent(new CustomEvent("input-mode-deactivated",{detail:{active:false}}));}disableNodeDragging(){this.svgNodes&&this.colaLayout&&this.svgNodes.on(".drag",null);}enableNodeDragging(){if(this.svgNodes&&this.colaLayout&&this.colaLayout.drag){let r=this.colaLayout.drag();this.setupNodeDragHandlers(r),this.svgNodes.call(r);}}disableZoom(){this.svg&&this.zoomBehavior&&(this.storedTransform=Ss.zoomTransform(this.svg.node()),this.svg.on(".zoom",null));}enableZoom(){this.svg&&this.zoomBehavior&&(this.svg.call(this.zoomBehavior),this.storedTransform&&this.svg.call(this.zoomBehavior.transform,this.storedTransform));}zoomIn(){this.svg&&this.zoomBehavior&&this.svg.transition().duration(200).call(this.zoomBehavior.scaleBy,1.5);}zoomOut(){this.svg&&this.zoomBehavior&&this.svg.transition().duration(200).call(this.zoomBehavior.scaleBy,1/1.5);}updateZoomControlStates(){if(!this.svg||!this.zoomBehavior)return;let o=Ss.zoomTransform(this.svg.node()).k,[s,e]=this.zoomBehavior.scaleExtent(),i=this.shadowRoot.querySelector("#zoom-in"),a=this.shadowRoot.querySelector("#zoom-out");i&&(i.disabled=o>=e),a&&(a.disabled=o<=s);}cleanupEdgeCreation(){this.edgeCreationState.temporaryEdge&&this.edgeCreationState.temporaryEdge.remove(),this.edgeCreationState={isCreating:false,sourceNode:null,temporaryEdge:null};}setupNodeDragHandlers(r){r.on("start.cnd",o=>{this.userHasManuallyZoomed=true;let s={x:o.x,y:o.y};this.dragStartPositions.set(o.id,s),this.dispatchEvent(new CustomEvent("node-drag-start",{detail:{id:o.id,position:s}}));}).on("end.cnd",o=>{let s=this.dragStartPositions.get(o.id);this.dragStartPositions.delete(o.id);let e={id:o.id,previous:s,current:{x:o.x,y:o.y}};this.dispatchEvent(new CustomEvent("node-drag-end",{detail:e}));});}startEdgeCreation(r){this.isInputModeActive&&(this.cleanupEdgeCreation(),this.edgeCreationState.isCreating=true,this.edgeCreationState.sourceNode=r,this.edgeCreationState.temporaryEdge=this.container.append("line").attr("class","temporary-edge").attr("x1",r.x).attr("y1",r.y).attr("x2",r.x).attr("y2",r.y).attr("stroke","#007bff").attr("stroke-width",2).attr("stroke-dasharray","5,5").attr("opacity",.7),this.svg.on("mousemove.edgecreation",()=>{if(this.edgeCreationState.isCreating&&this.edgeCreationState.temporaryEdge){let[o,s]=Ss.mouse(this.container.node());this.edgeCreationState.temporaryEdge.attr("x2",o).attr("y2",s);}}));}async finishEdgeCreation(r){if(!this.isInputModeActive||!this.edgeCreationState.isCreating||!this.edgeCreationState.sourceNode)return;let o=this.edgeCreationState.sourceNode;if(o.id===r.id&&!await this.showConfirmDialog(`Are you sure you want to create a self-loop edge on "${o.label||o.id}"?`)){this.cleanupEdgeCreation();return}this.svg.on("mousemove.edgecreation",null),await this.showEdgeLabelInput(o,r);}async showEdgeLabelInput(r,o){let s=await this.showPromptDialog(`Enter label for edge from "${r.label||r.id}" to "${o.label||o.id}":`,"");s!==null&&await this.createNewEdge(r,o,s||""),this.cleanupEdgeCreation();}async createNewEdge(r,o,s){if(!this.currentLayout)return;let e=this.currentLayout.nodes.findIndex(v=>v.id===r.id),i=this.currentLayout.nodes.findIndex(v=>v.id===o.id);if(e===-1||i===-1){console.error("Could not find node indices for edge creation");return}let h={id:`edge_${r.id}_${o.id}_${Date.now()}`,source:e,target:i,label:s,relName:s,color:"#333",isUserCreated:true};this.currentLayout.links.push(h),await this.updateExternalStateForNewEdge(r,o,s),this.dispatchEvent(new CustomEvent("edge-created",{detail:{edge:h,sourceNode:r,targetNode:o}})),this.rerenderGraph();}async updateExternalStateForNewEdge(r,o,s){if(s.trim())try{let e={atoms:[r.id,o.id],types:[r.type||"untyped",o.type||"untyped"]};console.log(`Dispatching edge creation request: ${s}(${r.id}, ${o.id})`);let i=new CustomEvent("edge-creation-requested",{detail:{relationId:s,sourceNodeId:r.id,targetNodeId:o.id,tuple:e},bubbles:!0});this.dispatchEvent(i);}catch(e){console.error("Failed to update external state for new edge:",e);}}rerenderGraph(){!this.currentLayout||!this.colaLayout||(this.colaLayout.links(this.currentLayout.links),this.container.selectAll(".link-group").remove(),this.renderLinks(this.currentLayout.links,this.colaLayout),this.updatePositions());}async editEdgeLabel(r){if(!this.isInputModeActive)return;let o=r.label||r.relName||"",s=await this.showEdgeEditDialog("Edit edge label:",o);if(s==="DELETE"){await this.deleteEdge(r);return}if(s!==null&&s!==o){let e=s,i=this.getNodeFromEdge(r,"source"),a=this.getNodeFromEdge(r,"target");await this.updateExternalStateForEdgeModification(i,a,o,e),r.label=e,r.relName=e,this.dispatchEvent(new CustomEvent("edge-modified",{detail:{edge:r,oldLabel:o,newLabel:e}})),this.rerenderGraph();}}getNodeFromEdge(r,o){if(!this.currentLayout)return null;let s=typeof r[o]=="number"?r[o]:r[o].index;return this.currentLayout.nodes[s]||null}async updateExternalStateForEdgeModification(r,o,s,e){if(!(!r||!o))try{let i={atoms:[r.id,o.id],types:[r.type||"untyped",o.type||"untyped"]};console.log(`Dispatching edge modification request: ${s} -> ${e}`);let a=new CustomEvent("edge-modification-requested",{detail:{oldRelationId:s,newRelationId:e,sourceNodeId:r.id,targetNodeId:o.id,tuple:i},bubbles:!0});this.dispatchEvent(a);}catch(i){console.error("Failed to update external state for edge modification:",i);}}resolveTransitionMode(r){if(r?.transitionMode==="replace")return "replace";if(r?.transitionMode==="morph")return "morph";let o=this.getAttribute("transition-mode");return o==="replace"?"replace":o==="morph"||r?.policy?"morph":"replace"}async renderLayout(r,o){if(!kb(r))throw new Error("Invalid instance layout provided. Expected an InstanceLayout instance.");let s=this.resolveTransitionMode(o),e=s==="morph",i=s==="replace",a,h=false;if(o?.policy&&o.prevInstance&&o.currInstance){let g=this.buildPolicyRawState(o),u=this.getViewportBoundsInLayoutSpace(g.transform),c=o.policy.apply({priorState:g,prevInstance:o.prevInstance,currInstance:o.currInstance,spec:{constraints:{orientation:{relative:[],cyclic:[]},alignment:[],grouping:{groups:[],subgroups:[]}},directives:{sizes:[],hiddenAtoms:[],icons:[],projections:[],edgeStyles:[]}},viewportBounds:u});a=c.effectivePriorState,h=c.useReducedIterations;}else if(o?.priorPositions)a=o.priorPositions,h=true;else if(e&&this.currentLayout?.nodes?.length){let g=this.getLayoutState();g.positions.length>0&&(a=g,h=true);}let v=!!(a&&a.positions.length>0),_=this.hasValidTransform(a?.transform),y=v?{priorPositions:a,lockUnconstrainedNodes:h}:void 0;if(this.applyViewportRenderPolicy(v,_),this.svg&&this.zoomBehavior&&Ss)try{if(_){let g=a.transform,u=Ss.zoomIdentity.translate(g.x,g.y).scale(g.k);this.svg.call(this.zoomBehavior.transform,u);}else if(!v){let g=Ss.zoomIdentity;this.svg.call(this.zoomBehavior.transform,g);}}catch(g){console.warn("Failed to set zoom transform:",g);}try{if(!Ss)throw new Error("D3 library not available. Please ensure D3 v4 is loaded from CDN.");if(!Fd){if(!window.cola)throw new Error("WebCola library not available. Please ensure vendor/cola.js is loaded.");Fd=window.cola;}if((!this.container||!this.svg)&&this.initializeD3(),!this.container)throw new Error("Failed to initialize D3 container. SVG elements may not be available.");i?(this.showLoading(),this.updateLoadingProgress("Translating layout...")):this.hideLoading();let u=this.shadowRoot.querySelector("#svg-container").getBoundingClientRect(),c=u.width||800,l=u.height||600,d=await new exports.WebColaTranslator().translate(r,c,l,y);i&&this.updateLoadingProgress(`Computing layout for ${d.nodes.length} nodes...`);let m=d.nodes.length,b=pi.INITIAL_UNCONSTRAINED_ITERATIONS,C=pi.INITIAL_USER_CONSTRAINT_ITERATIONS,E=pi.INITIAL_ALL_CONSTRAINTS_ITERATIONS;v&&h&&(b=0,C=Math.min(10,C),E=Math.min(20,E)),m>100?(b=Math.max(v?0:5,Math.floor(b*.5)),C=Math.max(25,Math.floor(C*.5)),E=Math.max(100,Math.floor(E*.5))):m>50&&(b=Math.max(v?0:8,Math.floor(b*.8)),C=Math.max(40,Math.floor(C*.8)),E=Math.max(150,Math.floor(E*.75)));let{scaledConstraints:T,linkLength:G,groupCompactness:q}=this.getScaledDetails(d.constraints,gB,d.nodes,d.groups,d.links);i&&this.updateLoadingProgress("Applying constraints and initializing...");let B=v?.1:.001,K=Fd.d3adaptor(Ss).linkDistance(G).convergenceThreshold(B).avoidOverlaps(!0).handleDisconnected(!0).nodes(d.nodes).links(d.links).constraints(T).groups(d.groups).groupCompactness(q).size([d.FIG_WIDTH,d.FIG_HEIGHT]);if(e&&this.currentLayout?.nodes?.length){this.morphOldPositions=new Map;for(let V of this.currentLayout.nodes)V.x!=null&&V.y!=null&&this.morphOldPositions.set(V.id,{x:V.x,y:V.y});this.applyMorphExitSnapshot(d);}else this.morphOldPositions=null;this.currentLayout=d,this.colaLayout=K,e&&this.container&&this.snapshotOldGraph(),this.container.selectAll("*").remove(),this.renderGroups(d.groups,K),this.renderLinks(d.links,K),this.renderNodes(d.nodes,K),e&&this.container&&this.container.attr("opacity",0);let nt=0,w=b+C+E,H=!0;K.on("tick",()=>{if(H){if(nt++,nt%20===0){let V=Math.min(95,Math.round(nt/w*100));i&&this.updateLoadingProgress(`Computing layout... ${V}%`);}return}this.layoutFormat==="default"||!this.layoutFormat||this.layoutFormat===null?this.updatePositions():this.layoutFormat==="grid"&&this.gridUpdatePositions();}).on("end",()=>{H=!1,i&&this.updateLoadingProgress("Finalizing..."),e&&this.morphOldPositions&&this.morphOldPositions.size>0?(this.container&&this.container.attr("opacity",1),this.startMorphExitAnimation(),this.layoutFormat==="default"||!this.layoutFormat?this.updatePositions():this.layoutFormat==="grid"&&this.gridUpdatePositions(),this.hideEnteringElements(),this.animateMorphSlide()):(this.container&&this.container.attr("opacity",1),this.layoutFormat==="default"||!this.layoutFormat?(this.updatePositions(),this.routeEdges()):this.layoutFormat==="grid"&&(this.gridUpdatePositions(),this.gridify(10,25,10))),this.isUnsatCore&&this.showErrorIcon(),this.dispatchRelationsAvailableEvent(),this.dispatchEvent(new CustomEvent("layout-complete",{detail:{nodePositions:this.getNodePositions()}})),this.updateRoutingModeDropdown(),i&&this.hideLoading();});try{K.start(b,C,E,pi.GRID_SNAP_ITERATIONS);}catch(V){console.warn("WebCola layout start encountered an error, trying alternative approach:",V);try{K.start();}catch(tt){throw console.error("Both WebCola start methods failed:",tt),new Error(`WebCola layout failed to start: ${tt.message}`)}}}catch(g){console.error("Error rendering layout:",g),this.showError(`Layout rendering failed: ${g.message}`);}}snapshotOldGraph(){if(!this.svg||!this.container)return;this.svg.selectAll(".morph-old-graph").interrupt().remove();let r=this.container.node();if(!r)return;let o=r.cloneNode(true);o.setAttribute("class","morph-old-graph"),o.style.pointerEvents="none";let s=this.svg.node();s&&s.appendChild(o);}applyMorphExitSnapshot(r){if(!this.svg||!this.container)return;this.svg.selectAll(".morph-exit-layer").interrupt().remove();let o=this.currentLayout?.nodes||[],s=this.currentLayout?.links||[],e=new Set(r.nodes.map(c=>c.id)),i=new Set(r.links.map(c=>c.id)),a=new Set(o.map(c=>c.id)),h=new Set(s.map(c=>c.id));this.morphEnteringNodeIds=new Set([...e].filter(c=>!a.has(c))),this.morphEnteringEdgeIds=new Set([...i].filter(c=>!h.has(c)));let v=new Set([...a].filter(c=>!e.has(c))),_=new Set([...h].filter(c=>!i.has(c)));if(v.size===0&&_.size===0)return;let y=this.svg.node();if(!y)return;let g=document.createElementNS("http://www.w3.org/2000/svg","g");g.setAttribute("class","morph-exit-layer"),g.style.pointerEvents="none";let u=this.container.attr("transform");u&&g.setAttribute("transform",u),this.svgNodes&&this.svgNodes.each(function(c){v.has(c.id)&&g.appendChild(this.cloneNode(true));}),this.svgLinkGroups&&this.svgLinkGroups.each(function(c){let l=c.id,f=c.source?.id??"",d=c.target?.id??"";(_.has(l)||v.has(f)||v.has(d))&&g.appendChild(this.cloneNode(true));}),this.svgGroups&&this.svgGroups.each(function(c){c.id&&!r.groups.some(l=>l.id===c.id)&&g.appendChild(this.cloneNode(true));}),g.childElementCount!==0&&y.appendChild(g);}startMorphExitAnimation(){if(!this.svg)return;this.svg.selectAll(".morph-old-graph").remove();let r=this.svg.select(".morph-exit-layer");if(r.empty())return;let o=this.morphExitDurationMs;r.selectAll("g.link-group, g.inferredLinkGroup, g.alignmentLinkGroup").each(function(){let s=this.querySelector("path");if(!s)return;let e=s.getTotalLength();!e||e<=0||(s.setAttribute("stroke-dasharray",String(e)),s.setAttribute("stroke-dashoffset","0"),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",0),Ss.select(s).transition().duration(o).ease(Ss.easeCubicIn).attr("stroke-dashoffset",e));}),r.selectAll("g.node, rect.group").transition().duration(o).ease(Ss.easeCubicOut).attr("opacity",0),r.transition().duration(o).on("end",function(){Ss.select(this).remove();});}hideEnteringElements(){let r=this.morphEnteringNodeIds,o=this.morphEnteringEdgeIds;r.size===0&&o.size===0||(this.svgNodes&&r.size>0&&this.svgNodes.filter(s=>r.has(s.id)).attr("opacity",0),this.svgLinkGroups&&(o.size>0||r.size>0)&&this.svgLinkGroups.filter(s=>{if(o.has(s.id))return true;let e=s.source?.id??"",i=s.target?.id??"";return r.has(e)||r.has(i)}).attr("opacity",0));}applyMorphEnterTransition(){let r=this.morphEnteringNodeIds,o=this.morphEnteringEdgeIds;if(!(!(r.size>0||o.size>0)&&this.morphEnteringNodeIds.size===0&&this.morphEnteringEdgeIds.size===0)){if(this.svgNodes&&r.size>0&&this.svgNodes.filter(e=>r.has(e.id)).attr("opacity",0).transition().delay(this.morphEnterDelayMs).duration(this.morphEnterDurationMs).ease(Ss.easeCubicOut).attr("opacity",1),this.svgLinkGroups&&(o.size>0||r.size>0)&&this.svgLinkGroups.filter(e=>{if(o.has(e.id))return true;let i=e.source?.id??"",a=e.target?.id??"";return r.has(i)||r.has(a)}).each(function(){let e=this.querySelector("path");if(!e)return;let i=e.getTotalLength();!i||i<=0||(Ss.select(e).attr("stroke-dasharray",i).attr("stroke-dashoffset",i),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",0));}).attr("opacity",1).transition().delay(this.morphEnterDelayMs).duration(this.morphEnterDurationMs).ease(Ss.easeCubicOut).tween("draw-in",function(){let e=this.querySelector("path");if(!e)return ()=>{};let i=e.getTotalLength();if(!i||i<=0)return ()=>{};let a=Ss.interpolateNumber(i,0);return h=>{e.setAttribute("stroke-dashoffset",String(a(h)));}}).on("end",function(){let e=this.querySelector("path");e&&(e.removeAttribute("stroke-dasharray"),e.removeAttribute("stroke-dashoffset")),Ss.select(this).selectAll(".linklabel, .arrowhead").attr("opacity",1);}),this.svgGroups&&this.svgGroupLabels){new Set((this.currentLayout?.groups||[]).map(i=>i.id).filter(Boolean));}this.morphEnteringNodeIds=new Set,this.morphEnteringEdgeIds=new Set;}}animateMorphSlide(){let r=this.morphOldPositions;if(!r||r.size===0||!this.currentLayout?.nodes){this.morphOldPositions=null;return}let o=this.currentLayout.nodes,s=this.morphSlideDurationMs;if(s<=0){this.morphOldPositions=null;return}let e=[];for(let h of o){let v=r.get(h.id);v&&e.push({node:h,oldX:v.x,oldY:v.y,finalX:h.x,finalY:h.y});}if(e.length===0){this.morphOldPositions=null;return}for(let h of e)h.node.x=h.oldX,h.node.y=h.oldY;this.updatePositions();let i=h=>1-Math.pow(1-h,3),a=performance.now();this.morphSlideTimer&&(this.morphSlideTimer.stop(),this.morphSlideTimer=null),this.morphSlideTimer=Ss.timer(()=>{let h=performance.now()-a,v=Math.min(1,h/s),_=i(v);for(let y of e)y.node.x=y.oldX+(y.finalX-y.oldX)*_,y.node.y=y.oldY+(y.finalY-y.oldY)*_;if(this.updatePositions(),v>=1){this.morphSlideTimer.stop(),this.morphSlideTimer=null;for(let y of e)y.node.x=y.finalX,y.node.y=y.finalY;this.updatePositions(),(this.layoutFormat==="default"||!this.layoutFormat)&&this.routeEdges(),this.applyMorphEnterTransition(),this.morphOldPositions=null;}});}setTransitionMode(r){this.setAttribute("transition-mode",r);}setMorphSpeed(r){this.setAttribute("morph-speed",String(Math.max(0,Math.min(r,1))));}clear(){if(this.colaLayout)try{this.colaLayout.stop?.();}catch{}this.container&&this.container.selectAll("*").remove(),this.svg&&this.svg.selectAll(".morph-exit-layer").interrupt().remove(),this.morphSlideTimer&&(this.morphSlideTimer.stop(),this.morphSlideTimer=null),this.morphOldPositions=null,this.currentLayout=null,this.colaLayout=null,this.svgNodes=null,this.svgLinks=null,this.svgGroups=null,this.edgeRoutingCache.edgesBetweenNodes.clear(),this.edgeRoutingCache.alignmentEdges.clear(),this.dragStartPositions.clear(),this.hideLoading();}getNodePositions(){return this.currentLayout?.nodes?this.currentLayout.nodes.map(r=>({id:r.id,x:r.x,y:r.y})):[]}getCurrentTransform(){if(this.svg&&this.svg.node())try{let r=Ss.zoomTransform(this.svg.node());return {k:r.k,x:r.x,y:r.y}}catch{return {k:1,x:0,y:0}}return {k:1,x:0,y:0}}getLayoutState(){return {positions:this.getNodePositions(),transform:this.getCurrentTransform()}}addToolbarControl(r){let o=this.shadowRoot?.querySelector("#graph-toolbar");o&&o.appendChild(r);}getToolbar(){return this.shadowRoot?.querySelector("#graph-toolbar")||null}renderGroups(r,o){if(!this.currentLayout.nodes||this.currentLayout.nodes.length===0){console.warn("Cannot render groups: nodes not available");return}this.svgGroups=this.setupGroups(r,this.currentLayout.nodes,o);}setupLinks(r,o){let s=this.container.selectAll(".link-group").data(r).enter().append("g").attr("class","link-group");return this.setupLinkPaths(s),this.setupLinkLabels(s),this.setupEdgeEndpointMarkers(s),s}setupLinkPaths(r){r.append("path").attr("class",o=>this.isAlignmentEdge(o)?"alignmentLink":this.isInferredEdge(o)?"inferredLink":"link").attr("data-link-id",o=>o.id||"").attr("stroke",o=>this.isAlignmentEdge(o)?"none":o.color).attr("fill","none").attr("opacity",o=>this.isAlignmentEdge(o)?0:null).style("stroke-width",o=>this.isAlignmentEdge(o)?"0":o.weight!=null?`${o.weight}px`:null).attr("stroke-dasharray",o=>this.isAlignmentEdge(o)?null:this.getEdgeDasharray(o.style)).attr("marker-end",o=>this.isAlignmentEdge(o)?"none":"url(#end-arrow)").attr("marker-start",o=>this.isAlignmentEdge(o)||!o.bidirectional?"none":"url(#start-arrow)").on("click.inputmode",o=>{this.isInputModeActive&&!this.isAlignmentEdge(o)&&(Ss.event.stopPropagation(),this.editEdgeLabel(o).catch(s=>{console.error("Error editing edge label:",s);}));}).style("cursor",()=>this.isInputModeActive?"pointer":"default");}getEdgeDasharray(r){if(!r)return null;switch(r.toLowerCase()){case "dotted":return "1,4";case "dashed":return "6,4";case "solid":return null;default:return null}}setupLinkLabels(r){r.filter(o=>!this.isAlignmentEdge(o)&&(this.isInferredEdge(o)||o.showLabel!==false)).append("text").attr("class","linklabel").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("font-family","system-ui").attr("pointer-events","none").text(o=>o.label||o.relName||"");}setupEdgeEndpointMarkers(r){r.filter(o=>!this.isAlignmentEdge(o)).append("circle").attr("class","edge-endpoint-marker target-marker").attr("r",8).attr("fill","#007bff").attr("stroke","white").attr("stroke-width",2).attr("opacity",0).attr("cursor","move").style("pointer-events","none").call(Ss.drag().on("start",o=>this.startEdgeEndpointDrag(o,"target")).on("drag",o=>this.dragEdgeEndpoint(o,"target")).on("end",o=>this.endEdgeEndpointDrag(o,"target"))),r.filter(o=>!this.isAlignmentEdge(o)).append("circle").attr("class","edge-endpoint-marker source-marker").attr("r",8).attr("fill","#28a745").attr("stroke","white").attr("stroke-width",2).attr("opacity",0).attr("cursor","move").style("pointer-events","none").call(Ss.drag().on("start",o=>this.startEdgeEndpointDrag(o,"source")).on("drag",o=>this.dragEdgeEndpoint(o,"source")).on("end",o=>this.endEdgeEndpointDrag(o,"source")));}startEdgeEndpointDrag(r,o){Ss.event.sourceEvent.stopPropagation(),this.edgeDragState.isDragging=true,this.edgeDragState.edge=r,this.edgeDragState.endpoint=o,console.log(`\u{1F535} Started dragging ${o} endpoint of edge:`,r.id);}dragEdgeEndpoint(r,o){if(!this.edgeDragState.isDragging)return;let[s,e]=Ss.mouse(this.container.node()),i=o==="target"?".target-marker":".source-marker";this.container.selectAll(".link-group").filter(a=>a.id===r.id).select(i).attr("cx",s).attr("cy",e);}async endEdgeEndpointDrag(r,o){if(!this.edgeDragState.isDragging)return;let[s,e]=Ss.mouse(this.container.node()),i=this.findNodeAtPosition(s,e);i?(console.log(`\u{1F517} Reconnecting ${o} to node:`,i.id),await this.reconnectEdge(r,o,i)):(console.log("\u{1F5D1}\uFE0F No node found - deleting edge:",r.id),await this.deleteEdge(r)),this.edgeDragState={isDragging:false,edge:null,endpoint:null,dragMarker:null},this.rerenderGraph();}findNodeAtPosition(r,o){if(!this.currentLayout?.nodes)return null;for(let s of this.currentLayout.nodes){let e=(s.visualWidth??s.width??0)/2,i=(s.visualHeight??s.height??0)/2;if(r>=s.x-e&&r<=s.x+e&&o>=s.y-i&&o<=s.y+i)return s}return null}async reconnectEdge(r,o,s){let e=this.getNodeFromEdge(r,"source"),i=this.getNodeFromEdge(r,"target");if(!e||!i){console.error("Could not find source or target node");return}let a,h;if(o==="source"?(a=s,h=i):(a=e,h=s),a.id===e.id&&h.id===i.id){console.log("\u23ED\uFE0F Edge already connected to this node, no change needed");return}let v=r.label||r.relName||"";if(!v.trim()){console.warn("Edge has no relation name, cannot reconnect");return}let _={atoms:[e.id,i.id],types:[e.type||"untyped",i.type||"untyped"]},y={atoms:[a.id,h.id],types:[a.type||"untyped",h.type||"untyped"]};console.log(`\u{1F504} Reconnecting edge from ${e.id}->${i.id} to ${a.id}->${h.id}`);let g=new CustomEvent("edge-reconnection-requested",{detail:{relationId:v,oldTuple:_,newTuple:y,oldSourceNodeId:e.id,oldTargetNodeId:i.id,newSourceNodeId:a.id,newTargetNodeId:h.id},bubbles:true});this.dispatchEvent(g);let u=this.currentLayout.nodes.findIndex(l=>l.id===a.id),c=this.currentLayout.nodes.findIndex(l=>l.id===h.id);u!==-1&&c!==-1&&(r.source=u,r.target=c);}async deleteEdge(r){let o=this.getNodeFromEdge(r,"source"),s=this.getNodeFromEdge(r,"target");if(!o||!s){console.error("Could not find source or target node for edge deletion");return}let e=r.label||r.relName||"";if(!e.trim()){console.warn("Edge has no relation name, cannot delete from data instance"),this.removeEdgeFromLayout(r);return}let i=[];if(r.groupId&&r.keyNodeId&&this.currentLayout){let h=(this.currentLayout.groups||[]).find(v=>v.id===r.groupId);if(h){let v=this.currentLayout.groups||[],_=this.collectGroupNodeIndices(h,v),y=this.currentLayout.nodes.find(g=>g.id===r.keyNodeId);for(let g of _){let u=this.currentLayout.nodes[g];u&&y&&i.push({atoms:[y.id,u.id],types:[y.type||"untyped",u.type||"untyped"]});}}}i.length===0&&i.push({atoms:[o.id,s.id],types:[o.type||"untyped",s.type||"untyped"]}),console.log(`\u{1F5D1}\uFE0F Deleting edge: ${e} (${i.length} tuple(s))`);let a=new CustomEvent("edge-modification-requested",{detail:{oldRelationId:e,newRelationId:"",sourceNodeId:o.id,targetNodeId:s.id,tuples:i},bubbles:true});this.dispatchEvent(a),this.removeEdgeFromLayout(r);}removeEdgeFromLayout(r){if(!this.currentLayout?.links)return;let o=this.currentLayout.links.findIndex(s=>s.id===r.id);o!==-1&&(this.currentLayout.links.splice(o,1),console.log(`\u2705 Edge removed from layout: ${r.id}`));}setupGroups(r,o,s){let e=this.setupGroupRectangles(r,o,s);return this.svgGroupLabels=this.setupGroupLabels(r,s),e}setupGroupRectangles(r,o,s){return this.container.selectAll(".group").data(r).enter().append("rect").attr("class",i=>this.isDisconnectedGroup(i)?"disconnectedNode":this.isErrorGroup(i)?"error-group":"group").attr("rx",pi.GROUP_BORDER_RADIUS).attr("ry",pi.GROUP_BORDER_RADIUS).style("fill",i=>this.isDisconnectedGroup(i)?"transparent":o[i.keyNode]?.color||"#cccccc").attr("fill-opacity",pi.GROUP_FILL_OPACITY).attr("stroke",i=>this.isDisconnectedGroup(i)?"none":o[i.keyNode]?.color||"#999999").attr("stroke-width",1).call(s.drag)}resolveGroupLeafToNodeIndex(r){if(typeof r=="number"&&Number.isInteger(r)&&r>=0)return r;if(r&&typeof r=="object"){let o=r;if(typeof o.index=="number"&&Number.isInteger(o.index)&&o.index>=0)return o.index;if(typeof o.id=="string"&&this.currentLayout?.nodes){let s=this.currentLayout.nodes.findIndex(e=>e.id===o.id);return s>=0?s:null}}return null}collectGroupNodeIndices(r,o){let s=new Set,e=new Set,i=(h,v)=>{if(h){if(typeof v=="number"){if(e.has(v))return;e.add(v);}Array.isArray(h.leaves)&&h.leaves.forEach(_=>{let y=this.resolveGroupLeafToNodeIndex(_);y!==null&&s.add(y);}),Array.isArray(h.groups)&&h.groups.forEach(_=>{typeof _=="number"&&Number.isInteger(_)&&_>=0&&_<o.length&&i(o[_],_);});}},a=o.indexOf(r);return i(r,a>=0?a:void 0),Array.from(s)}getNodeMainLabelFontSize(r){let o=r?._mainLabelFontSize;if(typeof o=="number"&&Number.isFinite(o))return o;let s=r?.visualWidth??r?.width??100,e=r?.visualHeight??r?.height??60,i=Math.max(1,s-pi.TEXT_PADDING*2),a=Math.max(1,e-pi.TEXT_PADDING*2),h=r?.label||r?.name||r?.id||"Node",v=Object.keys(r?.labels||{}).length>0,_=Object.keys(r?.attributes||{}).length>0,g=v||_?a*.5:a;return this.calculateOptimalFontSize(h,i,Math.max(1,g),"system-ui")}calculateGroupLabelFontSize(r,o){if(!this.currentLayout?.nodes?.length)return pi.DEFAULT_FONT_SIZE;let s=this.collectGroupNodeIndices(r,o);if(s.length===0)return pi.DEFAULT_FONT_SIZE;let e=s.map(h=>this.currentLayout.nodes[h]).filter(h=>!!h).map(h=>this.getNodeMainLabelFontSize(h));if(e.length===0)return pi.DEFAULT_FONT_SIZE;let i=e.reduce((h,v)=>h+v,0)/e.length,a=Math.max(pi.MIN_FONT_SIZE,Math.min(i,pi.MAX_FONT_SIZE));return Math.round(a*10)/10}setupGroupLabels(r,o){return this.container.selectAll(".groupLabel").data(r).enter().append("text").attr("class","groupLabel").attr("text-anchor","middle").attr("dominant-baseline","hanging").attr("font-family","system-ui").attr("font-size",s=>{let e=this.calculateGroupLabelFontSize(s,r);return s._groupLabelFontSize=e,`${e}px`}).attr("font-weight","bold").attr("fill","#333").attr("pointer-events","none").text(s=>s.showLabel||false?(s.padding&&(s.padding=Math.max(s.padding,pi.GROUP_LABEL_PADDING)),s.name||""):"").call(o.drag)}renderLinks(r,o){this.edgeRoutingCache.alignmentEdges.clear(),this.svgLinkGroups=this.setupLinks(r,o);}setupNodes(r,o){let s=o.drag();this.setupNodeDragHandlers(s);let e=this.container.selectAll(".node").data(r).enter().append("g").attr("class",i=>{let a=this.isErrorNode(i)?"error-node":"node";return this.isErrorNode(i)&&this.isSmallNode(i)?a+" small-error-node":a}).call(s).on("mousedown.inputmode",i=>{this.isInputModeActive&&(Ss.event.stopPropagation(),this.startEdgeCreation(i));}).on("mouseup.inputmode",i=>{this.isInputModeActive&&this.edgeCreationState.isCreating&&(Ss.event.stopPropagation(),this.finishEdgeCreation(i).catch(a=>{console.error("Error finishing edge creation:",a);}));}).on("mouseover",function(i){Ss.select(this).append("title").attr("class","node-tooltip").text(`ID: ${i.id}`);}).on("mouseout",function(){Ss.select(this).select("title.node-tooltip").remove();});return this.setupNodeRectangles(e),this.setupNodeIcons(e),this.setupMostSpecificTypeLabels(e),this.setupNodeLabels(e),e}setupNodeRectangles(r){r.append("rect").attr("width",o=>o.visualWidth??o.width).attr("height",o=>o.visualHeight??o.height).attr("x",o=>-(o.visualWidth??o.width)/2).attr("y",o=>-(o.visualHeight??o.height)/2).attr("stroke",o=>o.color||"black").attr("rx",pi.NODE_BORDER_RADIUS).attr("ry",pi.NODE_BORDER_RADIUS).attr("stroke-width",pi.NODE_STROKE_WIDTH).attr("fill",o=>{let s=this.isHiddenNode(o),e=!!o.icon,i=o.showLabels;return s||e&&!i?"transparent":"white"});}setupNodeIcons(r){r.filter(o=>o.icon).append("image").attr("xlink:href",o=>o.icon).attr("width",o=>{let s=o.visualWidth??o.width;return o.showLabels?s*pi.SMALL_IMG_SCALE_FACTOR:s}).attr("height",o=>{let s=o.visualHeight??o.height;return o.showLabels?s*pi.SMALL_IMG_SCALE_FACTOR:s}).attr("x",o=>{let s=o.visualWidth??o.width;return o.showLabels?o.x+s-s*pi.SMALL_IMG_SCALE_FACTOR:o.x-s/2}).attr("y",o=>{let s=o.visualHeight??o.height;return o.y-s/2}).append("title").text(o=>o.label||o.name||o.id||"Node").on("error",function(o,s){Ss.select(this).attr("xlink:href","img/default.png"),console.error(`Failed to load icon for node ${s.id}: ${s.icon}`);});}setupMostSpecificTypeLabels(r){r.append("text").attr("class","mostSpecificTypeLabel").style("fill",o=>o.color||"black").text(o=>o.mostSpecificType||"");}getTextMeasurementContext(){return this.textMeasurementCanvas||(this.textMeasurementCanvas=document.createElement("canvas")),this.textMeasurementCanvas.getContext("2d")}measureTextWidth(r,o,s="system-ui"){let e=this.getTextMeasurementContext();return e.font=`${o}px ${s}`,e.measureText(r).width}calculateOptimalFontSize(r,o,s,e="system-ui"){let i=pi.DEFAULT_FONT_SIZE;for(;i>pi.MIN_FONT_SIZE;){let a=this.measureTextWidth(r,i,e),h=i*pi.LINE_HEIGHT_RATIO;if(a<=o&&h<=s)break;i-=.5;}for(;i<pi.MAX_FONT_SIZE;){let a=i+.5,h=this.measureTextWidth(r,a,e),v=a*pi.LINE_HEIGHT_RATIO;if(h>o||v>s)break;i=a;}return Math.max(pi.MIN_FONT_SIZE,Math.min(i,pi.MAX_FONT_SIZE))}wrapText(r,o,s,e="system-ui"){let i=r.split(/\s+/),a=[],h="";for(let v of i){let _=h?`${h} ${v}`:v;this.measureTextWidth(_,s,e)<=o?h=_:h?(a.push(h),h=v):a.push(v);}return h&&a.push(h),a}setupNodeLabelsWithDynamicSizing(r){r.append("text").attr("class","label").attr("text-anchor","middle").attr("dominant-baseline","middle").attr("font-family","system-ui").attr("fill","black").each((o,s,e)=>{if(this.isHiddenNode(o)||!o.showLabels)return;let a=Ss.select(e[s]),h=o.width||100,v=o.height||60,_=h-pi.TEXT_PADDING*2,y=v-pi.TEXT_PADDING*2,g=o.label||o.name||o.id||"Node",u=o.attributes||{},c=Object.entries(u).sort(([V],[tt])=>V.localeCompare(tt)),l=o.labels||{},f=Object.entries(l),d=f.length>0,m=c.length>0,b=d||m,C=b?y*.5:y,E=this.calculateOptimalFontSize(g,_,C,"system-ui");o._mainLabelFontSize=E,a.attr("font-size",`${E}px`);let T=E*pi.LINE_HEIGHT_RATIO,G=f.length+c.length,q=b?-G*T*.5:0;o._labelVerticalOffset=q,o._labelLineHeight=T,a.append("tspan").attr("x",0).attr("dy",`${q}px`).attr("class","main-label-tspan").style("font-weight","bold").style("font-size",`${E}px`).text(g);let B="";for(let[V,tt]of f){let pt=Array.isArray(tt)?tt.join(", "):String(tt);pt.length>B.length&&(B=pt);}for(let[V,tt]of c){let pt=`${V}: ${tt}`;pt.length>B.length&&(B=pt);}let K=E*.65,nt=y-T,w=G>0?this.calculateOptimalFontSize(B||"SampleText",_,nt/G,"system-ui"):E*.8,H=Math.max(w,K);if(d){let V="black";for(let[tt,pt]of f){let J=Array.isArray(pt)?pt.join(", "):String(pt);a.append("tspan").attr("x",0).attr("dy",`${H*pi.LINE_HEIGHT_RATIO}px`).style("font-size",`${H}px`).style("fill",V).style("font-style","italic").text(J);}}if(m)for(let V=0;V<c.length;V++){let[tt,pt]=c[V],J=`${tt}: ${pt}`;a.append("tspan").attr("x",0).attr("dy",`${H*pi.LINE_HEIGHT_RATIO}px`).style("font-size",`${H}px`).text(J);}});}setupNodeLabels(r){this.setupNodeLabelsWithDynamicSizing(r);}renderNodes(r,o){this.svgNodes=this.setupNodes(r,o);}resolveGroupEdgeEndpoints(r){if(!r.groupId)return {source:r.source,target:r.target};let o=this.currentLayout?.groups||[],s=o.find(h=>h.id===r.groupId);if(this._groupEdgeDebugLogged||(this._groupEdgeDebugLogged=new Set),this._groupEdgeDebugLogged.has(r.id)||(this._groupEdgeDebugLogged.add(r.id),console.log("[groupEdge DEBUG]",{edgeId:r.id,groupId:r.groupId,keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id,sourceIsInt:typeof r.source=="number",targetIsInt:typeof r.target=="number",groupFound:!!s,groupId_on_group:s?.id,availableGroupIds:o.map(h=>h.id)})),!s)return {source:r.source,target:r.target};let e=r.source,i=r.target;r.source?.id===r.keyNodeId?i=s:r.target?.id===r.keyNodeId?e=s:console.warn("[groupEdge] keyNodeId matched neither side",{keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id});let a=e===s?r.source:i===s?r.target:null;if(a&&!s.bounds&&a.x!=null&&Fd?.Rectangle){let h=(a.visualWidth??a.width??50)/2,v=(a.visualHeight??a.height??30)/2;s.bounds=new Fd.Rectangle(a.x-h,a.x+h,a.y-v,a.y+v);}return {source:e,target:i}}updateNodePositionsOnly(){this.svgNodes&&(this.svgNodes.select("rect").attr("x",r=>r.x!=null?r.x-(r.visualWidth??r.width)/2:0).attr("y",r=>r.y!=null?r.y-(r.visualHeight??r.height)/2:0).attr("width",r=>r.visualWidth??r.width).attr("height",r=>r.visualHeight??r.height),this.svgNodes.select("image").attr("x",r=>{if(r.x==null)return 0;let o=r.visualWidth??r.width;return r.showLabels?r.x+o/2-o*pi.SMALL_IMG_SCALE_FACTOR:r.x-o/2}).attr("y",r=>{if(r.y==null)return 0;let o=r.visualHeight??r.height;return r.y-o/2}),this.svgNodes.select(".mostSpecificTypeLabel").attr("x",r=>r.x!=null?r.x-(r.visualWidth??r.width??0)/2+5:0).attr("y",r=>r.y!=null?r.y-(r.visualHeight??r.height??0)/2+10:0),this.svgNodes.select(".label").attr("x",r=>r.x??0).attr("y",r=>r.y??0).each((r,o,s)=>{if(r.x==null)return;let e=r._labelVerticalOffset||0,i=r._labelLineHeight||12;Ss.select(s[o]).selectAll("tspan").attr("x",r.x).attr("dy",(a,h)=>h===0?`${e}px`:`${i}px`);}));}updatePositions(){this.svgGroups.attr("x",r=>r.bounds.x).attr("y",r=>r.bounds.y).attr("width",r=>r.bounds.width()).attr("height",r=>r.bounds.height()).lower(),this.svgNodes.select("rect").each(r=>{r.bounds&&(r.innerBounds=r.bounds.inflate(-1));}).attr("x",r=>r.x-(r.visualWidth??r.width)/2).attr("y",r=>r.y-(r.visualHeight??r.height)/2).attr("width",r=>r.visualWidth??r.width).attr("height",r=>r.visualHeight??r.height),this.svgNodes.select("image").attr("x",r=>{let o=r.visualWidth??r.width;return r.showLabels?r.x+o/2-o*pi.SMALL_IMG_SCALE_FACTOR:r.x-o/2}).attr("y",r=>{let o=r.visualHeight??r.height;return r.showLabels,r.y-o/2}),this.svgNodes.select(".mostSpecificTypeLabel").attr("x",r=>r.x-(r.visualWidth??r.width??0)/2+5).attr("y",r=>r.y-(r.visualHeight??r.height??0)/2+10).raise(),this.svgNodes.select(".label").attr("x",r=>r.x).attr("y",r=>r.y).each((r,o,s)=>{let e=r._labelVerticalOffset||0,i=r._labelLineHeight||12;Ss.select(s[o]).selectAll("tspan").attr("x",r.x).attr("dy",(a,h)=>h===0?`${e}px`:`${i}px`);}).raise(),this.svgLinkGroups.select("path").attr("d",r=>{let{source:o,target:s}=this.resolveGroupEdgeEndpoints(r),e=this.getStableEdgePath(o,s);return this.lineFunction(e)}).attr("marker-end",r=>this.isAlignmentEdge(r)?"none":"url(#end-arrow)").attr("marker-start",r=>this.isAlignmentEdge(r)||!r.bidirectional?"none":"url(#start-arrow)").raise(),this.svgLinkGroups.select(".linklabel").attr("x",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?this.calculateNewPosition(o,"x"):(r.source.x+r.target.x)/2}).attr("y",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?this.calculateNewPosition(o,"y"):(r.source.y+r.target.y)/2}).style("font-size",()=>{let r=this.getCurrentZoomScale(),o=12,s=r<1?o/Math.sqrt(r):o;return `${Math.min(s,16)}px`}).raise(),this.updateEdgeEndpointMarkers(),this.svgGroupLabels.attr("x",r=>r.bounds?r.bounds.x+r.bounds.width()/2:0).attr("y",r=>{if(!r.bounds)return 0;let o=r._groupLabelFontSize||pi.DEFAULT_FONT_SIZE;return r.bounds.y+Math.max(4,o*.35)}).attr("text-anchor","middle").lower(),this.svgLinkGroups.selectAll("marker").raise(),this.svgLinkGroups.selectAll(".linklabel").raise(),this.svgNodes.selectAll(".error-node").raise();}updateEdgeEndpointMarkers(){this.svgLinkGroups&&(this.svgLinkGroups.select(".target-marker").attr("cx",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(o){let s=o.getTotalLength();return o.getPointAtLength(s).x}return r.target.x||0}).attr("cy",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(o){let s=o.getTotalLength();return o.getPointAtLength(s).y}return r.target.y||0}).attr("opacity",this.isInputModeActive?.8:0).style("pointer-events",this.isInputModeActive?"all":"none").raise(),this.svgLinkGroups.select(".source-marker").attr("cx",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?o.getPointAtLength(0).x:r.source.x||0}).attr("cy",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);return o?o.getPointAtLength(0).y:r.source.y||0}).attr("opacity",this.isInputModeActive?.8:0).style("pointer-events",this.isInputModeActive?"all":"none").raise());}gridUpdatePositions(){this.ensureNodeBounds(true);let r=this.container.selectAll(".node"),o=this.container.selectAll(".mostSpecificTypeLabel"),s=this.container.selectAll(".label"),e=this.container.selectAll(".group"),i=this.container.selectAll(".groupLabel");r.select("rect").each(function(h){h.innerBounds=h.bounds.inflate(-1);}).attr("x",function(h){return h.bounds.x}).attr("y",function(h){return h.bounds.y}).attr("width",function(h){return h.bounds.width()}).attr("height",function(h){return h.bounds.height()}),r.select("image").attr("x",function(h){let v=h.visualWidth??h.width;return h.showLabels?h.x+v/2-v*pi.SMALL_IMG_SCALE_FACTOR:h.bounds.x}).attr("y",function(h){let v=h.visualHeight??h.height;return h.showLabels?h.y-v/2:h.bounds.y}),o.attr("x",function(h){return h.bounds.x+5}).attr("y",function(h){return h.bounds.y+10}).raise(),s.attr("x",h=>h.x).attr("y",h=>h.y).each(function(h){var v=0;Ss.select(this).selectAll("tspan").attr("x",h.x).attr("dy",function(){return v+=1,v===1?"0em":"1em"});}).raise(),e.attr("x",function(h){return h.bounds.x}).attr("y",function(h){return h.bounds.y}).attr("width",function(h){return h.bounds.width()}).attr("height",function(h){return h.bounds.height()}).lower(),i.attr("x",function(h){return h.bounds.x+h.bounds.width()/2}).attr("y",function(h){let v=h._groupLabelFontSize||pi.DEFAULT_FONT_SIZE;return h.bounds.y+Math.max(4,v*.35)}).attr("text-anchor","middle").raise();let a=this.container.selectAll(".link-group");a.select("path").attr("d",h=>{if(h.source?.id===h.target?.id){let f=this.createSelfLoopRoute(h);return this.lineFunction(f)}let{source:v,target:_}=this.resolveGroupEdgeEndpoints(h),y=f=>f.bounds?typeof f.bounds.cx=="function"?{x:f.bounds.cx(),y:f.bounds.cy()}:{x:(f.bounds.x+f.bounds.X)/2,y:(f.bounds.y+f.bounds.Y)/2}:{x:f.x??0,y:f.y??0},g=y(v),u=y(_),c=u.x-g.x,l=u.y-g.y;if(Math.abs(c)>Math.abs(l)){let f=g.x+c/2;return this.gridLineFunction([{x:g.x,y:g.y},{x:f,y:g.y},{x:f,y:u.y},{x:u.x,y:u.y}])}else {let f=g.y+l/2;return this.gridLineFunction([{x:g.x,y:g.y},{x:g.x,y:f},{x:u.x,y:f},{x:u.x,y:u.y}])}}),a.select("text.linklabel").attr("x",h=>{let v=this.shadowRoot?.querySelector(`path[data-link-id="${h.id}"]`);if(v){let g=v.getTotalLength();return v.getPointAtLength(g/2).x}let _=h.source?.x??h.source?.bounds?.cx()??0,y=h.target?.x??h.target?.bounds?.cx()??0;return (_+y)/2}).attr("y",h=>{let v=this.shadowRoot?.querySelector(`path[data-link-id="${h.id}"]`);if(v){let g=v.getTotalLength();return v.getPointAtLength(g/2).y}let _=h.source?.y??h.source?.bounds?.cy()??0,y=h.target?.y??h.target?.bounds?.cy()??0;return (_+y)/2}).raise();}routeEdges(){try{this.ensureNodeBounds(!0),typeof this.colaLayout?.prepareEdgeRouting=="function"&&this.colaLayout.prepareEdgeRouting(pi.VIEWBOX_PADDING/pi.EDGE_ROUTE_MARGIN_DIVISOR),this.buildEdgeRoutingCaches(),this.routeLinkPaths(),this.updateLinkLabelsAfterRouting(),this.fitViewportToContent();}catch(r){console.error("Error in edge routing:",r),this.showError(`Edge routing failed: ${r.message}`);}}ensureNodeBounds(r=false){if(!(!this.currentLayout?.nodes||!Fd?.Rectangle))for(let o of this.currentLayout.nodes){if(!r&&o.bounds&&typeof o.bounds.rayIntersection=="function"){let _=o.bounds.cx(),y=o.bounds.cy(),g=1;if(Math.abs(_-(o.x||0))<g&&Math.abs(y-(o.y||0))<g)continue}let s=(o.visualWidth??o.width??50)/2,e=(o.visualHeight??o.height??30)/2,i=(o.x||0)-s,a=(o.x||0)+s,h=(o.y||0)-e,v=(o.y||0)+e;o.bounds=new Fd.Rectangle(i,a,h,v),o.innerBounds=o.bounds.inflate(-1);}}buildEdgeRoutingCaches(){this.edgeRoutingCache.edgesBetweenNodes.clear(),this.edgeRoutingCache.alignmentEdges.clear(),this.currentLayout?.links&&(this.currentLayout.links.forEach(r=>{r.id?.startsWith("_alignment_")&&this.edgeRoutingCache.alignmentEdges.add(r.id);}),this.currentLayout.links.forEach(r=>{if(this.isAlignmentEdge(r))return;let o=r.source.id,s=r.target.id,e=this.getNodePairKey(o,s);this.edgeRoutingCache.edgesBetweenNodes.has(e)||this.edgeRoutingCache.edgesBetweenNodes.set(e,[]),this.edgeRoutingCache.edgesBetweenNodes.get(e).push(r);}));}getNodePairKey(r,o){return r<o?`${r}:${o}`:`${o}:${r}`}route(r=[],o=[],s,e){r.forEach(a=>{let h=a.bounds||a.innerBounds||this.createFallbackBounds(a);a.routerNode={name:a.name,bounds:h};}),o.forEach(a=>{a.bounds||console.warn("Grid routing group missing bounds; routing may be degraded.",a),a.routerNode={bounds:a.bounds?.inflate(-e)??a.bounds,children:(typeof a.groups<"u"?a.groups.map(h=>r.length+h.id):[]).concat(typeof a.leaves<"u"?a.leaves.map(h=>h.index):[])};});let i=r.concat(o).map((a,h)=>a.routerNode?(a.routerNode.id=h,a.routerNode):null).filter(Boolean);return new Fd.GridRouter(i,{getChildren:a=>a.children,getBounds:a=>a.bounds},s-e)}gridify(r,o,s){if(this.isGridifyingInProgress){console.warn("[gridify] Already in progress, skipping re-entrant call");return}this.isGridifyingInProgress=true;try{this.gridifyInternal(r,o,s);}catch(e){console.log("Error routing edges in GridRouter"),console.error(e);try{this.fallbackGridRouting(this.currentLayout?.links??[]);}catch(a){console.error("Fallback grid routing also failed:",a);}let i=document.getElementById("runtime_messages");if(i){let a=document.createElement("div");a.className="alert alert-danger alert-dismissible fade show",a.setAttribute("role","alert"),a.innerHTML="Runtime (WebCola) error when gridifying edges. You may have to click and drag these nodes slightly to un-stick layout.",i.querySelectorAll(".alert").forEach(v=>{v.innerHTML===a.innerHTML&&v.remove();}),i.appendChild(a);}}finally{this.isGridifyingInProgress=false;}}gridifyInternal(r,o,s){let e=this.currentLayout?.nodes??[],i=this.currentLayout?.groups??[],a=this.currentLayout?.links??[];if(e.length===0){console.warn("No nodes available for GridRouter; skipping gridify.");return}if(a.length===0){console.warn("No edges to route in GridRouter");return}console.log("[gridify] Node positions BEFORE ensureNodeBounds:"),e.slice(0,3).forEach(l=>{console.log(` ${l.id}: x=${l.x?.toFixed(2)}, y=${l.y?.toFixed(2)}, bounds.cx=${l.bounds?.cx?.()?.toFixed(2)}, bounds.x=${l.bounds?.x?.toFixed(2)}`);}),this.ensureNodeBounds(true);let h=e.filter(l=>!Number.isFinite(l.x)||!Number.isFinite(l.y));if(h.length>0){console.warn("[gridify] Found nodes with invalid positions, falling back to default routing:",h.map(l=>({id:l.id,x:l.x,y:l.y}))),this.fallbackGridRouting(a);return}console.log("[gridify] Node positions AFTER ensureNodeBounds:"),e.slice(0,3).forEach(l=>{console.log(` ${l.id}: x=${l.x?.toFixed(2)}, y=${l.y?.toFixed(2)}, bounds.cx=${l.bounds?.cx?.()?.toFixed(2)}, bounds.x=${l.bounds?.x?.toFixed(2)}`);});let v=this.route(e,i,o,s),_=[],y=a.filter(l=>{let f=l?.source?.routerNode&&l?.target?.routerNode,d=l?.source?.id===l?.target?.id;return f&&!d}),g=a.filter(l=>l?.source?.id===l?.target?.id);console.log("[gridify] Total edges:",a.length,"Routable:",y.length,"Self-loops:",g.length),y.length+g.length!==a.length&&a.filter(f=>(!f?.source?.routerNode||!f?.target?.routerNode)&&f?.source?.id!==f?.target?.id).forEach(f=>{console.warn("[gridify] Unroutable edge:",f.id,"source routerNode:",!!f?.source?.routerNode,"target routerNode:",!!f?.target?.routerNode,"source:",f?.source?.id,"x:",f?.source?.x,"y:",f?.source?.y,"target:",f?.target?.id,"x:",f?.target?.x,"y:",f?.target?.y);}),_=v.routeEdges(y,r,function(l){return l.source.routerNode.id},function(l){return l.target.routerNode.id});let u=new Map;y.forEach((l,f)=>{let d=_[f];l?.id&&d&&u.set(l.id,this.adjustGridRouteForEdge(l,d));}),console.log("[gridify] Routes generated:",u.size,"out of",y.length),this.container.selectAll(".link-group").data(a,l=>l.id??l).select("path").attr("d",l=>{if(l.source?.id===l.target?.id){let T=this.createSelfLoopRoute(l);return this.lineFunction(T)}let f=u.get(l.id);if(!f){let T=l.source?.x??l.source?.bounds?.cx()??0,G=l.source?.y??l.source?.bounds?.cy()??0,q=l.target?.x??l.target?.bounds?.cx()??0,B=l.target?.y??l.target?.bounds?.cy()??0;console.log("[gridify] Fallback path for edge:",l.id,"from",l.source?.id,"(",T,",",G,")","to",l.target?.id,"(",q,",",B,")");let K=q-T,nt=B-G;if(Math.abs(K)>Math.abs(nt)){let w=T+K/2;return this.gridLineFunction([{x:T,y:G},{x:w,y:G},{x:w,y:B},{x:q,y:B}])}else {let w=G+nt/2;return this.gridLineFunction([{x:T,y:G},{x:T,y:w},{x:q,y:w},{x:q,y:B}])}}let C=Fd.GridRouter.getRoutePath(f,5,3,7);return this.adjustGridRouteForArrowPositioning(l,C.routepath,f)||C.routepath}),this.gridUpdateLinkLabels(a,u),this.fitViewportToContent(),this.dispatchEvent(new Event("relationsAvailable"));}fallbackGridRouting(r){this.container.selectAll(".link-group").data(r,s=>s.id??s).select("path").attr("d",s=>{if(s.source?.id===s.target?.id){let y=this.createSelfLoopRoute(s);return this.lineFunction(y)}let e=s.source?.x??s.source?.bounds?.cx()??0,i=s.source?.y??s.source?.bounds?.cy()??0,a=s.target?.x??s.target?.bounds?.cx()??0,h=s.target?.y??s.target?.bounds?.cy()??0,v=a-e,_=h-i;if(Math.abs(v)>Math.abs(_)){let y=e+v/2;return this.gridLineFunction([{x:e,y:i},{x:y,y:i},{x:y,y:h},{x:a,y:h}])}else {let y=i+_/2;return this.gridLineFunction([{x:e,y:i},{x:e,y},{x:a,y},{x:a,y:h}])}}),this.fitViewportToContent();}gridUpdateLinkLabels(r,o){this.container.selectAll(".link-group").filter(e=>!this.isAlignmentEdge(e)).select("text.linklabel").attr("x",e=>{let i=this.shadowRoot?.querySelector(`path[data-link-id="${e.id}"]`);if(i)try{let h=i.getTotalLength();return i.getPointAtLength(h/2).x}catch{}return this.getGridRouteMidpoint(e,o)?.x??e.source?.x??e.source?.bounds?.cx()??0}).attr("y",e=>{let i=this.shadowRoot?.querySelector(`path[data-link-id="${e.id}"]`);if(i)try{let h=i.getTotalLength();return i.getPointAtLength(h/2).y}catch{}return this.getGridRouteMidpoint(e,o)?.y??e.source?.y??e.source?.bounds?.cy()??0}).attr("text-anchor","middle").attr("dominant-baseline","middle");}getGridRouteMidpoint(r,o){let s=o.get(r.id);if(!s){let y=r.source?.x??r.source?.bounds?.cx()??0,g=r.source?.y??r.source?.bounds?.cy()??0,u=r.target?.x??r.target?.bounds?.cx()??0,c=r.target?.y??r.target?.bounds?.cy()??0;return {x:(y+u)/2,y:(g+c)/2}}let e=[];if(s.forEach(y=>{e.length===0&&y.length>0&&e.push(y[0]),y.length>1&&e.push(y[1]);}),e.length<2)return null;let i=0,a=[];for(let y=0;y<e.length-1;y++){let g=e[y+1].x-e[y].x,u=e[y+1].y-e[y].y,c=Math.sqrt(g*g+u*u);a.push(c),i+=c;}let h=i/2,v=0;for(let y=0;y<a.length;y++){let g=a[y];if(v+g>=h){let u=h-v,c=g>0?u/g:0;return {x:e[y].x+c*(e[y+1].x-e[y].x),y:e[y].y+c*(e[y+1].y-e[y].y)}}v+=g;}let _=Math.floor(e.length/2);return e[_]}adjustGridRouteForEdge(r,o){if(!r?.id?.startsWith("_g_"))return o;let s=this.gridRouteToPoints(o);if(s.length<2)return o;let e=this.routeGroupEdge(r,s);return this.pointsToGridRoute(e)}adjustGridRouteForArrowPositioning(r,o,s){if(!o||!r.source||!r.target)return null;try{let e=this.gridRouteToPoints(s);if(e.length<2)return null;let i=r.source,a=r.target,h=i.bounds||{x:i.x-(i.width||0)/2,y:i.y-(i.height||0)/2,width:()=>i.width||0,height:()=>i.height||0},v=a.bounds||{x:a.x-(a.width||0)/2,y:a.y-(a.height||0)/2,width:()=>a.width||0,height:()=>a.height||0},y=this.getTouchDirection(h,v,5);if(y!=="none"){let{sourcePoint:f,targetPoint:d,middlePoints:m}=this.computePerpendicularRoute(h,v,y),b=[f,...m,d];return this.gridLineFunction(b)}let g=e.length>1?e[1]:e[0],u=this.getRectangleIntersection(h.x+h.width()/2,h.y+h.height()/2,g.x,g.y,h);u&&(e[0]=u);let c=e.length>1?e[e.length-2]:e[e.length-1],l=this.getRectangleIntersection(v.x+v.width()/2,v.y+v.height()/2,c.x,c.y,v);return l&&(e[e.length-1]=l),this.gridLineFunction(e)}catch(e){return console.warn("Error adjusting grid route for arrow positioning:",e),null}}getTouchDirection(r,o,s){let e=r.x,i=r.x+r.width(),a=r.y,h=r.y+r.height(),v=o.x,_=o.x+o.width(),y=o.y,g=o.y+o.height(),u=Math.max(0,Math.max(v-i,e-_)),c=Math.max(0,Math.max(y-h,a-g)),l=!(h<y||g<a),f=!(i<v||_<e);return u<=s&&l?"horizontal":c<=s&&f?"vertical":"none"}computePerpendicularRoute(r,o,s){let e=r.width(),i=r.height(),a=o.width(),h=o.height(),v=r.x+e/2,_=r.y+i/2,y=o.x+a/2,g=o.y+h/2,u=15;if(s==="horizontal")if(_<=g){let l=Math.min(r.y,o.y)-u;return {sourcePoint:{x:v,y:r.y},targetPoint:{x:y,y:o.y},middlePoints:[{x:v,y:l},{x:y,y:l}]}}else {let l=Math.max(r.y+i,o.y+h)+u;return {sourcePoint:{x:v,y:r.y+i},targetPoint:{x:y,y:o.y+h},middlePoints:[{x:v,y:l},{x:y,y:l}]}}else if(v<=y){let l=Math.min(r.x,o.x)-u;return {sourcePoint:{x:r.x,y:_},targetPoint:{x:o.x,y:g},middlePoints:[{x:l,y:_},{x:l,y:g}]}}else {let l=Math.max(r.x+e,o.x+a)+u;return {sourcePoint:{x:r.x+e,y:_},targetPoint:{x:o.x+a,y:g},middlePoints:[{x:l,y:_},{x:l,y:g}]}}}areBoundsNear(r,o,s){let e=r.x,i=r.x+r.width(),a=r.y,h=r.y+r.height(),v=o.x,_=o.x+o.width(),y=o.y,g=o.y+o.height(),u=Math.max(0,Math.max(v-i,e-_)),c=Math.max(0,Math.max(y-h,a-g));return Math.sqrt(u*u+c*c)<=s}chooseBoundaryPoint(r,o,s,e){let i=Math.max(1,s.width()),a=Math.max(1,s.height()),h=[{x:s.x,y:s.y+a/2},{x:s.x+i,y:s.y+a/2},{x:s.x+i/2,y:s.y},{x:s.x+i/2,y:s.y+a}],v=h[0],_=-1/0;for(let y of h){let g=y.x-e.x,u=y.y-e.y,c=Math.sqrt(g*g+u*u);c>_&&(_=c,v=y);}return v}normalizeNodeBounds(r){let o=r.visualWidth??r.width??50,s=r.visualHeight??r.height??30,e=r.bounds||{x:r.x-o/2,y:r.y-s/2,width:()=>o,height:()=>s};return {x:typeof e.x=="number"||e.X!==void 0?e.x:r.x-o/2,y:typeof e.y=="number"?e.y:r.y-s/2,width:()=>typeof e.width=="function"?e.width():e.X!==void 0?e.X-e.x:o,height:()=>typeof e.height=="function"?e.height():e.Y!==void 0?e.Y-e.y:s}}lineIntersectsRect(r,o,s){let e=s.x,i=s.x+s.width(),a=s.y,h=s.y+s.height(),v=Math.min(r.x,o.x),_=Math.max(r.x,o.x),y=Math.min(r.y,o.y),g=Math.max(r.y,o.y);if(_<e||v>i||g<a||y>h)return false;let u=r.x>=e&&r.x<=i&&r.y>=a&&r.y<=h,c=o.x>=e&&o.x<=i&&o.y>=a&&o.y<=h;if(u||c)return true;let l=o.x-r.x,f=o.y-r.y,d=(b,C,E)=>{if(f===0)return false;let T=(b-r.y)/f;if(T<0||T>1)return false;let G=r.x+T*l;return G>=C&&G<=E},m=(b,C,E)=>{if(l===0)return false;let T=(b-r.x)/l;if(T<0||T>1)return false;let G=r.y+T*f;return G>=C&&G<=E};return d(a,e,i)||d(h,e,i)||m(e,a,h)||m(i,a,h)}findBlockingNodes(r,o,s,e){if(!this.currentLayout?.nodes)return [];let i=this.normalizeNodeBounds(r),a=this.normalizeNodeBounds(o),h={x:i.x+i.width()/2,y:i.y+i.height()/2},v={x:a.x+a.width()/2,y:a.y+a.height()/2},_=[];for(let y of this.currentLayout.nodes){if(y.id===s||y.id===e)continue;let g=this.normalizeNodeBounds(y);if(this.lineIntersectsRect(h,v,g)){let u={x:g.x+g.width()/2,y:g.y+g.height()/2},c=Math.sqrt(Math.pow(u.x-h.x,2)+Math.pow(u.y-h.y,2));_.push({node:y,bounds:g,distance:c});}}return _.sort((y,g)=>y.distance-g.distance),_.map(y=>({node:y.node,bounds:y.bounds}))}computeRouteAroundBlockingNodes(r,o,s){let i=Math.min(r.x,o.x),a=Math.max(r.x+r.width(),o.x+o.width()),h=Math.min(r.y,o.y),v=Math.max(r.y+r.height(),o.y+o.height());for(let{bounds:f}of s)i=Math.min(i,f.x),a=Math.max(a,f.x+f.width()),h=Math.min(h,f.y),v=Math.max(v,f.y+f.height());let _=r.x+r.width()/2,y=r.y+r.height()/2,g=o.x+o.width()/2,u=o.y+o.height()/2,c=Math.abs(g-_);if(Math.abs(u-y)>c)if(_<=g){let d=i-15;return {sourcePoint:{x:r.x,y},targetPoint:{x:o.x,y:u},middlePoints:[{x:d,y},{x:d,y:u}]}}else {let d=a+15;return {sourcePoint:{x:r.x+r.width(),y},targetPoint:{x:o.x+o.width(),y:u},middlePoints:[{x:d,y},{x:d,y:u}]}}else if(y<=u){let d=h-15;return {sourcePoint:{x:_,y:r.y},targetPoint:{x:g,y:o.y},middlePoints:[{x:_,y:d},{x:g,y:d}]}}else {let d=v+15;return {sourcePoint:{x:_,y:r.y+r.height()},targetPoint:{x:g,y:o.y+o.height()},middlePoints:[{x:_,y:d},{x:g,y:d}]}}}getNearTouchPerpendicularRoute(r){if(!r.source||!r.target||r.source.id===r.target.id)return null;let o=r.source,s=r.target,e=this.normalizeNodeBounds(o),i=this.normalizeNodeBounds(s),h=this.getTouchDirection(e,i,5);if(h!=="none"){let{sourcePoint:_,targetPoint:y,middlePoints:g}=this.computePerpendicularRoute(e,i,h);return [_,...g,y]}let v=this.findBlockingNodes(o,s,o.id,s.id);if(v.length>0){let{sourcePoint:_,targetPoint:y,middlePoints:g}=this.computeRouteAroundBlockingNodes(e,i,v);return [_,...g,y]}return null}gridRouteToPoints(r){let o=[];return r.forEach((s,e)=>{e===0&&o.push({x:s[0].x,y:s[0].y}),o.push({x:s[1].x,y:s[1].y});}),o}pointsToGridRoute(r){let o=[];for(let s=0;s<r.length-1;s+=1)o.push([r[s],r[s+1]]);return o}createFallbackBounds(r){if(!Fd?.Rectangle)return null;let o=((r.visualWidth??r.width)||50)/2,s=((r.visualHeight??r.height)||30)/2,e=(r.x||0)-o,i=(r.x||0)+o,a=(r.y||0)-s,h=(r.y||0)+s;return new Fd.Rectangle(e,i,a,h)}getRectangleIntersection(r,o,s,e,i){let a=i.x,h=i.x+i.width(),v=i.y,_=i.y+i.height(),y=s-r,g=e-o;if(y===0&&g===0)return {x:r,y:o};let u=0,c=1;if(y!==0){let f=(a-r)/y,d=(h-r)/y;u=Math.max(u,Math.min(f,d)),c=Math.min(c,Math.max(f,d));}if(g!==0){let f=(v-o)/g,d=(_-o)/g;u=Math.max(u,Math.min(f,d)),c=Math.min(c,Math.max(f,d));}if(u>c)return null;let l=u>0?u:c;return {x:r+l*y,y:o+l*g}}routeLinkPaths(){this.container.selectAll(".link-group path").attr("d",r=>{try{return this.routeSingleEdge(r)}catch(o){return console.error(`Error routing edge ${r.id} from ${r.source.id} to ${r.target.id}:`,o),this.showRuntimeAlert(r.source.id,r.target.id),this.lineFunction([{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}])}});}routeSingleEdge(r){if(this.isAlignmentEdge(r))return this.lineFunction([{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}]);let o=[{x:r.source.x||0,y:r.source.y||0},{x:r.target.x||0,y:r.target.y||0}],s;if(typeof this.colaLayout?.routeEdge=="function")try{if(s=this.colaLayout.routeEdge(r),!s||!Array.isArray(s)||s.length<2||!s[0]||!s[1]||s[0].x===void 0||s[0].y===void 0)throw new Error(`WebCola failed to route edge ${r.id} from ${r.source.id} to ${r.target.id}`)}catch(i){return console.log("Error routing edge",r.id,`from ${r.source.id} to ${r.target.id}`),console.error(i),this.lineFunction(o)}else s=o;if(r.source.id===r.target.id)s=this.createSelfLoopRoute(r);else {if(r.id?.startsWith("_g_"))return s=this.routeGroupEdge(r,s),this.lineFunction(s);s=this.handleMultipleEdgeRouting(r,s);}let e=this.getNearTouchPerpendicularRoute(r);return e?this.lineFunction(e):this.lineFunction(s)}createSelfLoopRoute(r){let o=r.source,s=o.bounds;if(!s)return [{x:o.x,y:o.y},{x:o.x+20,y:o.y-20},{x:o.x,y:o.y}];let e=s.X-s.x,i=s.Y-s.y,a={x:s.x+e/2,y:s.y},h={x:s.X,y:s.y+i/2},_=1+(r.selfLoopIndex||0)*pi.SELF_LOOP_CURVATURE_SCALE,y={x:s.X+e/2*_,y:s.y-i/2*_};return [a,y,h]}routeGroupEdge(r,o){let s=r.groupId?(this.currentLayout?.groups||[]).find(e=>e.id===r.groupId):null;if(!s)console.warn("[routeGroupEdge] Group not found for edge:",r.id,"\u2014 groupId:",r.groupId);else {if(!s.bounds&&Fd?.Rectangle){let e=r.source?.id===r.keyNodeId?o[o.length-1]:o[0];e&&(s.bounds=new Fd.Rectangle(e.x-50,e.x+50,e.y-30,e.y+30));}if(s.bounds)if(r.source?.id===r.keyNodeId)o[o.length-1]=this.closestPointOnRect(s.bounds,o[0]);else if(r.target?.id===r.keyNodeId){let e=s.bounds.inflate?.(-1)??s.bounds;o[0]=this.closestPointOnRect(e,o[o.length-1]);}else console.warn("[routeGroupEdge] keyNodeId matched neither side",{keyNodeId:r.keyNodeId,sourceId:r.source?.id,targetId:r.target?.id});}return o.length>2&&o.splice(1,o.length-2),o}handleMultipleEdgeRouting(r,o){let s=this.getAllEdgesBetweenNodes(r.source.id,r.target.id);if(s.length<=1)return o;if(o.length===2){let _={x:(o[0].x+o[1].x)/2,y:(o[0].y+o[1].y)/2};o.splice(1,0,_);}let e=o[1].x-o[0].x,i=o[1].y-o[0].y,a=Math.atan2(i,e),h=this.getRouteLength(o),v=s.findIndex(_=>_.id===r.id);if(v!==-1){o=this.applyEdgeOffsetWithIndex(r,o,s,a,v,h);let _=this.calculateCurvatureWithIndex(s,r.id,v),y=this.clampCurvature(_);o=this.applyCurvatureToRoute(o,y,a,h);}return o}getAllEdgesBetweenNodes(r,o){if(!this.currentLayout?.links)return [];let s=this.getNodePairKey(r,o);return this.edgeRoutingCache.edgesBetweenNodes.has(s)?this.edgeRoutingCache.edgesBetweenNodes.get(s):this.currentLayout.links.filter(e=>!this.isAlignmentEdge(e)&&(e.source.id===r&&e.target.id===o||e.source.id===o&&e.target.id===r))}calculateCurvature(r,o,s,e){if(e.startsWith("_alignment_"))return 0;let i=r.length,a=r.findIndex(h=>h.id===e);return i<=1?0:(a%2===0?1:-1)*(Math.floor(a/2)+1)*pi.CURVATURE_BASE_MULTIPLIER*i}calculateCurvatureWithIndex(r,o,s){let e=r.length;return e<=1?0:(s%2===0?1:-1)*(Math.floor(s/2)+1)*pi.CURVATURE_BASE_MULTIPLIER*e}applyEdgeOffset(r,o,s,e){let i=s.findIndex(h=>h.id===r.id),a=this.getRouteLength(o);return this.applyEdgeOffsetWithIndex(r,o,s,e,i,a)}applyEdgeOffsetWithIndex(r,o,s,e,i,a){let h=(i%2===0?1:-1)*(Math.floor(i/2)+1)*pi.MIN_EDGE_DISTANCE,v=this.clampOffset(h,a),_=this.getDominantDirection(e);return _==="right"||_==="left"?(o[0].y+=v,o[o.length-1].y+=v):(_==="up"||_==="down")&&(o[0].x+=v,o[o.length-1].x+=v),r.source.innerBounds&&(o[0]=this.adjustPointToRectanglePerimeter(o[0],r.source.innerBounds)),r.target.innerBounds&&(o[o.length-1]=this.adjustPointToRectanglePerimeter(o[o.length-1],r.target.innerBounds)),o}clampOffset(r,o){let s=Math.max(pi.MIN_EDGE_DISTANCE,o*pi.MAX_EDGE_OFFSET_RATIO);return Math.max(-s,Math.min(s,r))}getRouteLength(r){return r.length<2?0:r.slice(1).reduce((o,s,e)=>{let i=r[e],a=s.x-i.x,h=s.y-i.y;return o+Math.sqrt(a*a+h*h)},0)}clampCurvature(r){return Math.max(-pi.MAX_EDGE_CURVATURE_RATIO,Math.min(pi.MAX_EDGE_CURVATURE_RATIO,r))}applyCurvatureToRoute(r,o,s,e){return o===0||r.forEach((i,a)=>{if(a>0&&a<r.length-1){let h=o*Math.abs(Math.sin(s))*e,v=o*Math.abs(Math.cos(s))*e;i.x+=h,i.y+=v;}}),r}getDominantDirection(r){return r=(r+Math.PI)%(2*Math.PI)-Math.PI,r>=-Math.PI/4&&r<=Math.PI/4?"right":r>Math.PI/4&&r<3*Math.PI/4?"up":r>=3*Math.PI/4||r<=-3*Math.PI/4?"left":r>-3*Math.PI/4&&r<-Math.PI/4?"down":null}closestPointOnRect(r,o){if(!r)return o;let{x:s,y:e,X:i,Y:a}=r,h=Math.max(s,Math.min(o.x,i)),v=Math.max(e,Math.min(o.y,a));return {x:h,y:v}}getStableEdgeAnchor(r,o){if(!r)return o;let s,e,i,a;if(typeof r.cx=="function")s=r.cx(),e=r.cy(),i=r.width()/2,a=r.height()/2;else if(r.x!==void 0&&r.X!==void 0)s=(r.x+r.X)/2,e=(r.y+r.Y)/2,i=(r.X-r.x)/2,a=(r.Y-r.y)/2;else return o;let h=o.x-s,v=o.y-e,_=Math.abs(h)/i,y=Math.abs(v)/a;return _>y?h>0?{x:s+i,y:e}:{x:s-i,y:e}:v>0?{x:s,y:e+a}:{x:s,y:e-a}}getStableEdgePath(r,o){let s={x:r.x||0,y:r.y||0},e={x:o.x||0,y:o.y||0},i=y=>{let g=((y.visualWidth??y.width)||0)/2,u=((y.visualHeight??y.height)||0)/2;if(g===0&&u===0)return null;let c=y.x||0,l=y.y||0;return {cx:()=>c,cy:()=>l,width:()=>g*2,height:()=>u*2,x:c-g,X:c+g,y:l-u,Y:l+u}},a=i(r)??r.bounds??r.innerBounds,h=i(o)??o.bounds??o.innerBounds,v=a?this.getStableEdgeAnchor(a,e):s,_=h?this.getStableEdgeAnchor(h,s):e;return [v,_]}adjustPointToRectanglePerimeter(r,o){return o?this.closestPointOnRect(o,r):r}updateLinkLabelsAfterRouting(){this.container.selectAll(".link-group .linklabel").attr("x",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(!o)return 0;let s=o.getTotalLength();return o.getPointAtLength(s/2).x}).attr("y",r=>{let o=this.shadowRoot?.querySelector(`path[data-link-id="${r.id}"]`);if(!o)return 0;let s=o.getTotalLength();return o.getPointAtLength(s/2).y}).attr("text-anchor","middle").each((r,o,s)=>{this.handleLabelOverlap(s[o]);}).raise();}handleLabelOverlap(r){let o=[];this.container.selectAll(".linklabel").each(function(){this!==r&&V0t(this,r)&&o.push(this);}),o.length>0&&this.minimizeOverlap(r,o);}minimizeOverlap(r,o){}fitViewportToContent(r=false){let o=this.svg?.node();if(!o||!this.zoomBehavior||this.userHasManuallyZoomed&&!this.isInitialRender&&!r)return;let s=this.calculateContentBounds();if(!s)return;let e=o.clientWidth||o.parentElement?.clientWidth||800,i=o.clientHeight||o.parentElement?.clientHeight||600,a=pi.VIEWBOX_PADDING*4,h=(e-a*2)/s.width,v=(i-a*2)/s.height,_=Math.min(h,v,1),[y,g]=this.zoomBehavior.scaleExtent(),u=Math.max(y,Math.min(g,_)),c=s.x+s.width/2,l=s.y+s.height/2,f=e/2-c*u,d=i/2-l*u,m=Ss.zoomIdentity.translate(f,d).scale(u);this.isInitialRender?(this.svg.call(this.zoomBehavior.transform,m),this.isInitialRender=false):this.svg.transition().duration(300).ease(Ss.easeCubicOut).call(this.zoomBehavior.transform,m),this.updateZoomControlStates();}resetViewToFitContent(){this.userHasManuallyZoomed=false,this.fitViewportToContent(true);}calculateContentBounds(){try{if(!this.currentLayout||!this.container)return null;let r=1/0,o=1/0,s=-1/0,e=-1/0,i=(c,l,f,d)=>{[c,l,f,d].every(Number.isFinite)&&(r=Math.min(r,c),s=Math.max(s,l),o=Math.min(o,f),e=Math.max(e,d));},a=this.currentLayout.nodes;a&&a.length>0&&a.forEach(c=>{if(this.isHiddenNode(c)||typeof c.x!="number"||typeof c.y!="number")return;let l=c.visualWidth??c.width??0,f=c.visualHeight??c.height??0,d=l/2,m=f/2;i(c.x-d,c.x+d,c.y-m,c.y+m);});let h=this,v=this.container.selectAll(".link-group path");v.empty()||v.each(function(c){if(!(c?.id&&h.isAlignmentEdge(c)))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x,l.x+l.width,l.y,l.y+l.height);}catch{}});let _=this.container.selectAll(".node, .error-node");_.empty()||_.each(function(c){if(!h.isHiddenNode(c))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x,l.x+l.width,l.y,l.y+l.height);}catch{}});let y=this.container.selectAll("text");y.empty()||y.each(function(c){if(!(c&&(typeof c.name=="string"||typeof c.id=="string")&&h.isHiddenNode(c)))try{let l=this.getBBox();(l.width>0||l.height>0)&&i(l.x-5,l.x+l.width+5,l.y-5,l.y+l.height+5);}catch{}});let g=this.container.selectAll(".group");return g.empty()||g.each(function(){try{let c=this.getBBox();(c.width>0||c.height>0)&&i(c.x,c.x+c.width,c.y,c.y+c.height);}catch{}}),r===1/0||o===1/0||s===-1/0||e===-1/0?(console.warn("Could not calculate content bounds - no valid elements found"),null):{x:r,y:o,width:s-r,height:e-o}}catch(r){return console.error("Error calculating content bounds:",r),null}}dispatchRelationsAvailableEvent(){let r=this.getAllRelations(),o=new CustomEvent("relations-available",{detail:{relations:r,count:r.length,timestamp:Date.now(),graphId:this.id||"unknown"},bubbles:true,cancelable:true});this.dispatchEvent(o);}getAllRelations(){if(!this.currentLayout?.links)return [];let r=new Set(this.currentLayout.links.filter(o=>!this.isAlignmentEdge(o)).map(o=>o.relName).filter(Boolean));return Array.from(r)}highlightRelation(r){return this.currentLayout?.links?(this.svgLinkGroups.filter(o=>o.relName===r&&!this.isAlignmentEdge(o)).selectAll("path").classed("highlighted",true),true):false}clearHighlightRelation(r){return this.currentLayout?.links?(this.svgLinkGroups.filter(o=>o.relName===r&&!this.isAlignmentEdge(o)).selectAll("path").classed("highlighted",false),true):false}highlightNodes(r){if(!this.currentLayout?.nodes||!this.svgNodes||!r||r.length===0)return false;let o=new Set(r),s=false;return this.svgNodes.each((e,i,a)=>{o.has(e.id)&&(Ss.select(a[i]).classed("highlighted",true),s=true);}),s}highlightNodePairs(r,o={}){if(!this.currentLayout?.nodes||!this.svgNodes||!r||r.length===0)return false;let{showBadges:s=false}=o,e=new Set,i=new Set;r.forEach((h,v)=>{if(!Array.isArray(h)){console.warn(`highlightNodePairs: Pair at index ${v} is not an array, skipping`);return}if(h.length!==2){console.warn(`highlightNodePairs: Pair at index ${v} has ${h.length} elements (expected 2), skipping`);return}let[_,y]=h;_&&e.add(_),y&&i.add(y);});let a=false;return this.svgNodes.each((h,v,_)=>{let y=Ss.select(_[v]);e.has(h.id)&&(y.classed("highlighted-first",true),a=true,s&&this.addHighlightBadge(y,h,"1","#007aff")),i.has(h.id)&&(y.classed("highlighted-second",true),a=true,s&&(e.has(h.id)?this.addHighlightBadge(y,h,"1,2","#9B59B6"):this.addHighlightBadge(y,h,"2","#ff3b30")));}),a}clearNodeHighlights(){return this.svgNodes?(this.svgNodes.classed("highlighted",false).classed("highlighted-first",false).classed("highlighted-second",false).selectAll(".highlight-badge, .highlight-badge-bg").remove(),true):false}addHighlightBadge(r,o,s,e){r.selectAll(".highlight-badge, .highlight-badge-bg").remove();let i=16,a=4,h=(o.width||0)/2-i/2-a,v=-(o.height||0)/2+i/2+a;r.append("circle").attr("class","highlight-badge-bg").attr("cx",h).attr("cy",v).attr("r",i/2).attr("fill",e),r.append("text").attr("class","highlight-badge").attr("x",h).attr("y",v).attr("dy","0.35em").text(s);}showRuntimeAlert(r,o){console.warn(`Runtime (WebCola) error when laying out an edge from ${r} to ${o}. You may have to click and drag these nodes slightly to un-stick layout.`);}getCSS(){return `
852
852
  :host {
853
853
  display: block;
854
854
  width: 100%;
@@ -1610,7 +1610,7 @@ Expecting `+F1.join(", ")+", got '"+(this.terminals_[eo]||eo)+"'":E1="Parse erro
1610
1610
  </div>
1611
1611
  `,this.positionPopover(a,r);let h=a.querySelector(".si-del-atom"),v=a.querySelector(".si-del-rel"),_=a.querySelector(".si-btn-danger"),y=()=>{_.disabled=!h.value&&!v.value;};h.addEventListener("change",()=>{h.value&&(v.value=""),y();}),v.addEventListener("change",()=>{v.value&&(h.value=""),y();}),_.addEventListener("click",async()=>{if(h.value)await this.deleteAtom(h.value);else if(v.value){let[g]=v.value.split("::");await this.deleteRelation(g);}this.dismissOverlays(),this.updateDeletionSelects(),this.updateAtomPositions();}),this.setupPopoverDismiss(a);}positionPopover(r,o){if(!this.shadowRoot)return;let s=this.getBoundingClientRect(),e=o.getBoundingClientRect();r.style.position="absolute",r.style.top=`${e.bottom-s.top+4}px`,r.style.left=`${e.left-s.left}px`,r.style.zIndex="10001",this.shadowRoot.appendChild(r);}setupPopoverDismiss(r){this._activePopover=r,r.addEventListener("mousedown",o=>o.stopPropagation());}setupCanvasInteractions(){let r=this.shadowRoot?.querySelector("#svg-container"),o=this.shadowRoot?.querySelector("#svg");!r||!o||(this.setAttribute("tabindex","0"),this.style.outline="none",this.style.position="relative",this.shadowRoot?.addEventListener("mousedown",()=>{this._activePopover&&this.dismissOverlays();}),document.addEventListener("mousedown",()=>{this._activePopover&&this.dismissOverlays();}),o.addEventListener("click",s=>{if(s.ctrlKey||s.metaKey)return;let e=s.target,i=e.closest(".node")||e.closest(".error-node");if(this.clearNodeHighlights(),this.selectedNodeId=null,i){let a=vB.select(i).datum();a?.id&&(this.selectedNodeId=a.id,this.highlightNodes([a.id]),this.focus());}}),o.addEventListener("contextmenu",s=>{let e=s.target,i=e.closest(".node")||e.closest(".error-node");if(!i)return;s.preventDefault(),s.stopPropagation();let a=vB.select(i).datum();if(!a?.id)return;let h=r.getBoundingClientRect(),v=s.clientX-h.left,_=s.clientY-h.top;this.showNodeContextMenu(r,a,v,_);}),this.addEventListener("keydown",s=>{if(s.key==="Escape"){this.selectedNodeId=null,this.clearNodeHighlights(),this.dismissOverlays();return}if(this.selectedNodeId&&(s.key==="Delete"||s.key==="Backspace")){let e=this.shadowRoot?.activeElement;if(e&&(e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.tagName==="SELECT"))return;s.preventDefault();let i=this.selectedNodeId;this.selectedNodeId=null,this.clearNodeHighlights(),this.deleteAtom(i),this.updateDeletionSelects(),this.updateAtomPositions();}}));}showNodeContextMenu(r,o,s,e){this.dismissOverlays();let i=document.createElement("div");i.className="node-context-menu",i.style.left=`${s}px`,i.style.top=`${e}px`;let a=o.name||o.label||o.id;i.innerHTML=`
1612
1612
  <div class="menu-item danger" data-action="delete">Delete "${a}"</div>
1613
- `,r.appendChild(i),i.addEventListener("click",async v=>{v.target.dataset.action==="delete"&&(this.dismissOverlays(),await this.deleteAtom(o.id),this.updateDeletionSelects(),this.updateAtomPositions());});let h=v=>{i.contains(v.target)||this.dismissOverlays(),this.shadowRoot?.removeEventListener("click",h),document.removeEventListener("click",h);};setTimeout(()=>{this.shadowRoot?.addEventListener("click",h),document.addEventListener("click",h);},0);}dismissOverlays(){this._activePopover=null,this.shadowRoot?.querySelectorAll(".si-popover, .node-context-menu").forEach(r=>r.remove());}async handleEdgeCreationRequest(r){console.log("\u{1F517} Handling edge creation request:",r.detail);let{relationId:o,sourceNodeId:s,targetNodeId:e,tuple:i}=r.detail;try{this._suppressDataChangeRerender=!0;try{this.dataInstance.addRelationTuple(o,i),console.log(`\u2705 Added relation to data instance: ${o}(${s}, ${e})`);}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(a){console.error("\u274C Failed to handle edge creation request:",a);}}async handleEdgeModificationRequest(r){console.log("\u{1F517} Handling edge modification request:",r.detail);let{oldRelationId:o,newRelationId:s,sourceNodeId:e,targetNodeId:i,tuple:a,tuples:h}=r.detail,v=h??(a?[a]:[]);try{this._suppressDataChangeRerender=!0;try{if(!s||s.trim()===""){if(console.log(`\u{1F5D1}\uFE0F Deleting edge (${v.length} tuple(s))`),o&&o.trim()){for(let _ of v)this.dataInstance.removeRelationTuple(o,_);console.log(`\u2705 Removed ${v.length} relation tuple(s) from ${o}`);}}else if(o.trim()===s.trim()){console.log("\u23ED\uFE0F Same relation name, no data changes needed");return}else {if(o&&o.trim())for(let _ of v)try{this.dataInstance.removeRelationTuple(o,_),console.log(`\u{1F5D1}\uFE0F Removed from ${o}`);}catch(y){let g=y instanceof Error?y.message:String(y);console.log(`\u26A0\uFE0F Could not remove from ${o}: ${g}`);}for(let _ of v)this.dataInstance.addRelationTuple(s,_);console.log(`\u2795 Added ${v.length} tuple(s) to ${s}`);}}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(_){console.error("\u274C Failed to handle edge modification request:",_);}}async handleEdgeReconnectionRequest(r){console.log("\u{1F504} Handling edge reconnection request:",r.detail);let{relationId:o,oldTuple:s,newTuple:e,oldSourceNodeId:i,oldTargetNodeId:a,newSourceNodeId:h,newTargetNodeId:v}=r.detail;try{this._suppressDataChangeRerender=!0;try{if(o&&o.trim())try{this.dataInstance.removeRelationTuple(o,s),console.log(`\u{1F5D1}\uFE0F Removed old tuple from ${o}: ${i} -> ${a}`);}catch(_){let y=_ instanceof Error?_.message:String(_);console.log(`\u26A0\uFE0F Could not remove old tuple from ${o}: ${y}`);}this.dataInstance.addRelationTuple(o,e),console.log(`\u2795 Added new tuple to ${o}: ${h} -> ${v}`);}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(_){console.error("\u274C Failed to handle edge reconnection request:",_);}}async parseCnDSpec(r){try{console.log("\u{1F504} Parsing CnD spec and initializing pipeline..."),this.cndSpecString=r,await this.initializeCnDPipeline(r),this.updateTypeDatalist(),this.updateSpecInfo(),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("spec-loaded",{detail:{spec:this.cndSpecString}})),console.log("\u2705 CnD spec parsed and pipeline initialized");}catch(o){console.error("\u274C Failed to parse CnD spec:",o),this.updateSpecInfo("error",o instanceof Error?o.message:"Parse error");}}async initializeCnDPipeline(r){if(!r.trim()){console.log("\u{1F4DD} Empty spec - clearing pipeline"),this.evaluator=null,this.layoutInstance=null;return}try{console.log("\u{1F527} Initializing CnD pipeline with spec...");let o=hx(r);console.log("\u{1F4CB} Layout spec parsed successfully"),this.evaluator=new exports.SGraphQueryEvaluator,this.evaluator.initialize({sourceData:this.dataInstance}),console.log("\u{1F50D} SGraphQueryEvaluator initialized with data instance"),this.layoutInstance=new exports.LayoutInstance(o,this.evaluator,0,!0),console.log("\u{1F4D0} LayoutInstance created"),console.log("\u2705 CnD pipeline initialized successfully (evaluator + layout instance)");}catch(o){throw console.error("\u274C Failed to initialize CnD pipeline:",o),this.evaluator=null,this.layoutInstance=null,o}}async enforceConstraintsAndRegenerate(){console.log("\u{1F504} enforceConstraintsAndRegenerate() called");try{if(!this.layoutInstance){console.log("\u26A0\uFE0F Cannot enforce constraints - no layout instance available");return}console.log("\u{1F4CA} Current data instance state:",{atoms:this.dataInstance.getAtoms().length,relations:this.dataInstance.getRelations().length}),this.evaluator&&(console.log("\u{1F504} Re-initializing evaluator with updated data instance..."),this.evaluator.initialize({sourceData:this.dataInstance}),console.log("\u2705 Evaluator re-initialized")),console.log("\u{1F527} Generating layout with constraint enforcement...");let r=this.layoutInstance.generateLayout(this.dataInstance);r.error?(console.warn("\u26A0\uFE0F Constraint validation error detected:",r.error),this.currentConstraintError=r.error,this.dispatchEvent(new CustomEvent("constraint-error",{detail:{error:r.error,layout:r.layout},bubbles:!0})),console.log("\u{1F4E4} Dispatched constraint-error event with UNSAT core information")):(console.log("\u2705 Layout generated successfully - all constraints satisfied"),this.currentConstraintError!==null&&(console.log("\u{1F9F9} Clearing previous constraint error - constraints now satisfied"),this.currentConstraintError=null,this.dispatchEvent(new CustomEvent("constraints-satisfied",{detail:{layout:r.layout},bubbles:!0})),console.log("\u{1F4E4} Dispatched constraints-satisfied event"))),console.log("\u{1F3A8} Rendering layout...");let o=this.getLayoutState(),s=o.positions.length>0;await this.renderLayout(r.layout,s?{priorPositions:o}:void 0),console.log("\u2705 Constraints enforced and layout regenerated successfully");}catch(r){console.error("\u274C Failed to enforce constraints and regenerate layout:",r),this.dispatchEvent(new CustomEvent("layout-generation-error",{detail:{error:r},bubbles:true}));}}refreshTypesFromDataInstance(){}getAvailableAtomTypes(){let r=new Set;return this.dataInstance&&this.dataInstance.getAtoms().forEach(s=>{s.type&&r.add(s.type);}),r.size===0&&(r.add("Entity"),r.add("Person"),r.add("Object")),Array.from(r)}updateDataInstance(r){try{console.log("Data instance updated:",r);}catch(o){console.error("Failed to update data instance:",o);}}updateExportVisibility(r){}updateTypeDatalist(){}updateSpecInfo(r,o){}generateAtomId(r){if(!this.dataInstance)return `${r}-1`;let o=this.dataInstance.getAtoms(),s=new Set(o.map(a=>a.id)),e=1,i=`${r}-${e}`;for(;s.has(i);)e++,i=`${r}-${e}`;return i}async addAtomFromForm(r,o){if(!r||!o)return null;try{console.log(`\u{1F535} Adding atom: ${o} (${r})`);let e={id:this.generateAtomId(r),type:r,label:o};return this.dataInstance.addAtom(e),console.log(`\u2705 Atom added to data instance: ${e.label} (${e.id}:${e.type})`),this.refreshTypesFromDataInstance(),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("atom-added",{detail:{atom:e}})),console.log(`\u{1F389} Atom addition completed: ${e.label} (${e.id}:${e.type})`),e}catch(s){return console.error("\u274C Failed to add atom:",s),null}}updateAtomPositions(){}updateRelationButtonState(){}async addRelationFromForm(r){try{let o=r?.trim()||this.shadowRoot?.querySelector(".si-rel-name")?.value?.trim()||"";if(!o)return;let s=this.relationAtomPositions.filter(h=>h.trim()!=="");if(s.length<2){console.warn("Need at least 2 atoms for a relation");return}console.log(`\u{1F517} Adding relation: ${o}(${s.join(", ")})`);let e=this.dataInstance.getAtoms(),i=s.map(h=>e.find(_=>_.id===h)?.type||"untyped"),a={atoms:s,types:i};this.dataInstance.addRelationTuple(o,a),console.log(`\u2705 Relation added to data instance: ${o}(${s.join(", ")})`),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("relation-added",{detail:{relationType:o,tuple:a}})),console.log(`\u{1F389} Relation addition completed: ${o}(${s.join(", ")})`);}catch(o){console.error("\u274C Failed to add relation:",o);}}exportDataAsJSON(){try{console.log("\u{1F4E4} Exporting data instance using reify()...");let r=this.dataInstance.reify(),o=typeof r=="string"?r:JSON.stringify(r,null,2);this.dispatchEvent(new CustomEvent("data-exported",{detail:{data:o,format:typeof r=="string"?"text":"json",reified:r}})),console.log("\u2705 Data exported using reify()");}catch(r){console.error("\u274C Failed to export data:",r);}}handleDataChangeUIUpdate(r=false){}async handleDataDeletionWithValidation(r=false){await this.enforceConstraintsAndRegenerate();}setDataInstance(r){console.log("\u{1F504} Setting new data instance"),this.dataInstance&&(this.dataInstanceEventHandlers.atomAdded&&this.dataInstance.removeEventListener("atomAdded",this.dataInstanceEventHandlers.atomAdded),this.dataInstanceEventHandlers.atomRemoved&&this.dataInstance.removeEventListener("atomRemoved",this.dataInstanceEventHandlers.atomRemoved),this.dataInstanceEventHandlers.relationTupleAdded&&this.dataInstance.removeEventListener("relationTupleAdded",this.dataInstanceEventHandlers.relationTupleAdded),this.dataInstanceEventHandlers.relationTupleRemoved&&this.dataInstance.removeEventListener("relationTupleRemoved",this.dataInstanceEventHandlers.relationTupleRemoved)),this.dataInstance=r,this.refreshTypesFromDataInstance(),this.dataInstanceEventHandlers.atomAdded=async()=>{console.log("\u{1F4CD} Atom added to instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(true),this._suppressDataChangeRerender||await this.enforceConstraintsAndRegenerate();},this.dataInstanceEventHandlers.relationTupleAdded=async()=>{console.log("\u{1F517} Relation added to instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(false),this._suppressDataChangeRerender||await this.enforceConstraintsAndRegenerate();},this.dataInstanceEventHandlers.atomRemoved=async()=>{console.log("\u{1F5D1}\uFE0F Atom removed from instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(true),this._suppressDataChangeRerender||await this.handleDataDeletionWithValidation(true);},this.dataInstanceEventHandlers.relationTupleRemoved=async()=>{console.log("\u{1F5D1}\uFE0F Relation tuple removed from instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(false),this._suppressDataChangeRerender||await this.handleDataDeletionWithValidation(false);},r.addEventListener("atomAdded",this.dataInstanceEventHandlers.atomAdded),r.addEventListener("relationTupleAdded",this.dataInstanceEventHandlers.relationTupleAdded),r.addEventListener("atomRemoved",this.dataInstanceEventHandlers.atomRemoved),r.addEventListener("relationTupleRemoved",this.dataInstanceEventHandlers.relationTupleRemoved),this.updateDeletionSelects(),this.updateAtomPositions(),console.log("\u2705 Data instance set successfully");}updateDeletionSelects(){}async deleteAtom(r){if(r)try{console.log(`\u{1F5D1}\uFE0F Deleting atom: ${r}`);let s=this.dataInstance.getAtoms().find(e=>e.id===r);if(!s){console.warn(`\u26A0\uFE0F Atom ${r} not found`);return}this.dataInstance.removeAtom(r),console.log(`\u2705 Atom removed from data instance: ${s.label} (${s.id})`),console.log(`\u{1F389} Atom deletion completed: ${s.label} (${s.id})`),this.dispatchEvent(new CustomEvent("atom-deleted",{detail:{atom:s}}));}catch(o){console.error("\u274C Failed to delete atom:",o);}}async deleteRelation(r){if(r)try{let o=parseInt(r,10);console.log(`\u{1F5D1}\uFE0F Deleting relation tuple at index: ${o}`);let s=this.dataInstance.getRelations(),e=0,i=null,a=null;for(let v of s){for(let _ of v.tuples){if(e===o){i=v,a=_;break}e++;}if(i)break}if(!i||!a){console.warn(`\u26A0\uFE0F Relation tuple at index ${o} not found`);return}let h=i.id||i.name;console.log(`\u{1F5D1}\uFE0F Found tuple in relation "${h}": ${a.atoms.join(" \u2192 ")}`),this.dataInstance.removeRelationTuple(h,a),console.log(`\u2705 Relation tuple removed from data instance: ${h}: ${a.atoms.join(" \u2192 ")}`),console.log(`\u{1F389} Relation tuple deletion completed: ${h}: ${a.atoms.join(" \u2192 ")}`),this.dispatchEvent(new CustomEvent("relation-tuple-deleted",{detail:{relationId:h,tuple:a}}));}catch(o){console.error("\u274C Failed to delete relation tuple:",o);}}async clearAllItems(){try{console.log("\u{1F9F9} Clearing all atoms and relations...");let r=new exports.JSONDataInstance({atoms:[],relations:[],types:[]});this.setDataInstance(r),console.log("\u2705 All items cleared from data instance"),await this.enforceConstraintsAndRegenerate(),console.log("\u{1F389} Clear all completed"),this.dispatchEvent(new CustomEvent("all-items-cleared",{detail:{}}));}catch(r){console.error("\u274C Failed to clear all items:",r);}}getDataInstance(){return this.dataInstance}getCurrentConstraintError(){return this.currentConstraintError}hasConstraintErrors(){return this.currentConstraintError!==null}async setCnDSpec(r){this.setAttribute("cnd-spec",r),await this.parseCnDSpec(r);}getAvailableTypes(){return this.getAvailableAtomTypes()}};});var SB=be((Om,Hv)=>{(function(){var t,n="4.17.23",r=200,o="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",s="Expected a function",e="Invalid `variable` option passed into `_.template`",i="__lodash_hash_undefined__",a=500,h="__lodash_placeholder__",v=1,_=2,y=4,g=1,u=2,c=1,l=2,f=4,d=8,m=16,b=32,C=64,E=128,T=256,G=512,q=30,B="...",K=800,nt=16,w=1,H=2,V=3,tt=1/0,pt=9007199254740991,J=17976931348623157e292,dt=NaN,mt=4294967295,Tt=mt-1,gt=mt>>>1,Ot=[["ary",E],["bind",c],["bindKey",l],["curry",d],["curryRight",m],["flip",G],["partial",b],["partialRight",C],["rearg",T]],Zt="[object Arguments]",oe="[object Array]",te="[object AsyncFunction]",Oe="[object Boolean]",ee="[object Date]",Jt="[object DOMException]",Et="[object Error]",ht="[object Function]",xt="[object GeneratorFunction]",bt="[object Map]",Dt="[object Number]",Pt="[object Null]",Bt="[object Object]",ne="[object Promise]",ce="[object Proxy]",Ht="[object RegExp]",Ae="[object Set]",kt="[object String]",jt="[object Symbol]",Kt="[object Undefined]",$t="[object WeakMap]",yt="[object WeakSet]",zt="[object ArrayBuffer]",De="[object DataView]",ie="[object Float32Array]",yn="[object Float64Array]",wr="[object Int8Array]",ni="[object Int16Array]",Fr="[object Int32Array]",He="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Qn="[object Uint16Array]",Gr="[object Uint32Array]",ti=/\b__p \+= '';/g,oi=/\b(__p \+=) '' \+/g,fi=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Mi=/&(?:amp|lt|gt|quot|#39);/g,Fi=/[&<>"']/g,ve=RegExp(Mi.source),$n=RegExp(Fi.source),mr=/<%-([\s\S]+?)%>/g,Ur=/<%([\s\S]+?)%>/g,Yr=/<%=([\s\S]+?)%>/g,$i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wi=/^\w*$/,ps=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,no=/[\\^$.*+?()[\]{}|]/g,Wi=RegExp(no.source),ki=/^\s+/,Fs=/\s/,ba=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Po=/\{\n\/\* \[wrapped with (.+)\] \*/,bu=/,? & /,$l=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,du=/[()=,{}\[\]\/\s]/,Ta=/\\(\\)?/g,Mo=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,rl=/\w*$/,Tu=/^[-+]0x[0-9a-f]+$/i,Al=/^0b[01]+$/i,tu=/^\[object .+?Constructor\]$/,No=/^0o[0-7]+$/i,Ro=/^(?:0|[1-9]\d*)$/,pu=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Bu=/($^)/,il=/['\n\r\u2028\u2029\\]/g,ao="\\ud800-\\udfff",xu="\\u0300-\\u036f",pr="\\ufe20-\\ufe2f",D="\\u20d0-\\u20ff",O=xu+pr+D,it="\\u2700-\\u27bf",Gt="a-z\\xdf-\\xf6\\xf8-\\xff",Zn="\\xac\\xb1\\xd7\\xf7",Wr="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",p="\\u2000-\\u206f",$=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",k="A-Z\\xc0-\\xd6\\xd8-\\xde",F="\\ufe0e\\ufe0f",W=Zn+Wr+p+$,P="['\u2019]",X="["+ao+"]",Q="["+W+"]",lt="["+O+"]",pe="\\d+",fe="["+it+"]",Mt="["+Gt+"]",Rt="[^"+ao+W+pe+it+Gt+k+"]",qt="\\ud83c[\\udffb-\\udfff]",we="(?:"+lt+"|"+qt+")",Ee="[^"+ao+"]",Pe="(?:\\ud83c[\\udde6-\\uddff]){2}",me="[\\ud800-\\udbff][\\udc00-\\udfff]",se="["+k+"]",jn="\\u200d",Be="(?:"+Mt+"|"+Rt+")",nr="(?:"+se+"|"+Rt+")",An="(?:"+P+"(?:d|ll|m|re|s|t|ve))?",on="(?:"+P+"(?:D|LL|M|RE|S|T|VE))?",Cn=we+"?",ir="["+F+"]?",br="(?:"+jn+"(?:"+[Ee,Pe,me].join("|")+")"+ir+Cn+")*",ei="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ve="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",yr=ir+Cn+br,gr="(?:"+[fe,Pe,me].join("|")+")"+yr,cr="(?:"+[Ee+lt+"?",lt,Pe,me,X].join("|")+")",_i=RegExp(P,"g"),_s=RegExp(lt,"g"),Js=RegExp(qt+"(?="+qt+")|"+cr+yr,"g"),Uo=RegExp([se+"?"+Mt+"+"+An+"(?="+[Q,se,"$"].join("|")+")",nr+"+"+on+"(?="+[Q,se+Be,"$"].join("|")+")",se+"?"+Be+"+"+An,se+"+"+on,Ve,ei,pe,gr].join("|"),"g"),Ns=RegExp("["+jn+ao+O+F+"]"),Gi=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,xs=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],eu=-1,ts={};ts[ie]=ts[yn]=ts[wr]=ts[ni]=ts[Fr]=ts[He]=ts[Ge]=ts[Qn]=ts[Gr]=true,ts[Zt]=ts[oe]=ts[zt]=ts[Oe]=ts[De]=ts[ee]=ts[Et]=ts[ht]=ts[bt]=ts[Dt]=ts[Bt]=ts[Ht]=ts[Ae]=ts[kt]=ts[$t]=false;var Jr={};Jr[Zt]=Jr[oe]=Jr[zt]=Jr[De]=Jr[Oe]=Jr[ee]=Jr[ie]=Jr[yn]=Jr[wr]=Jr[ni]=Jr[Fr]=Jr[bt]=Jr[Dt]=Jr[Bt]=Jr[Ht]=Jr[Ae]=Jr[kt]=Jr[jt]=Jr[He]=Jr[Ge]=Jr[Qn]=Jr[Gr]=true,Jr[Et]=Jr[ht]=Jr[$t]=false;var us={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},Yo={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ka={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},sl={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Hl=parseFloat,ga=parseInt,Ks=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,ms=typeof self=="object"&&self&&self.Object===Object&&self,$r=Ks||ms||Function("return this")(),Sf=typeof Om=="object"&&Om&&!Om.nodeType&&Om,nh=Sf&&typeof Hv=="object"&&Hv&&!Hv.nodeType&&Hv,Wt=nh&&nh.exports===Sf,Yt=Wt&&Ks.process,ue=(function(){try{var an=nh&&nh.require&&nh.require("util").types;return an||Yt&&Yt.binding&&Yt.binding("util")}catch{}})(),Se=ue&&ue.isArrayBuffer,ge=ue&&ue.isDate,ae=ue&&ue.isMap,ke=ue&&ue.isRegExp,Ke=ue&&ue.isSet,Xe=ue&&ue.isTypedArray;function qi(an,nn,wn){switch(wn.length){case 0:return an.call(nn);case 1:return an.call(nn,wn[0]);case 2:return an.call(nn,wn[0],wn[1]);case 3:return an.call(nn,wn[0],wn[1],wn[2])}return an.apply(nn,wn)}function ua(an,nn,wn,Ii){for(var os=-1,Ys=an==null?0:an.length;++os<Ys;){var Au=an[os];nn(Ii,Au,wn(Au),an);}return Ii}function la(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii&&nn(an[wn],wn,an)!==false;);return an}function ko(an,nn){for(var wn=an==null?0:an.length;wn--&&nn(an[wn],wn,an)!==false;);return an}function Te(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii;)if(!nn(an[wn],wn,an))return false;return true}function Ne(an,nn){for(var wn=-1,Ii=an==null?0:an.length,os=0,Ys=[];++wn<Ii;){var Au=an[wn];nn(Au,wn,an)&&(Ys[os++]=Au);}return Ys}function Ce(an,nn){var wn=an==null?0:an.length;return !!wn&&vn(an,nn,0)>-1}function $e(an,nn,wn){for(var Ii=-1,os=an==null?0:an.length;++Ii<os;)if(wn(nn,an[Ii]))return true;return false}function Le(an,nn){for(var wn=-1,Ii=an==null?0:an.length,os=Array(Ii);++wn<Ii;)os[wn]=nn(an[wn],wn,an);return os}function tn(an,nn){for(var wn=-1,Ii=nn.length,os=an.length;++wn<Ii;)an[os+wn]=nn[wn];return an}function pn(an,nn,wn,Ii){var os=-1,Ys=an==null?0:an.length;for(Ii&&Ys&&(wn=an[++os]);++os<Ys;)wn=nn(wn,an[os],os,an);return wn}function en(an,nn,wn,Ii){var os=an==null?0:an.length;for(Ii&&os&&(wn=an[--os]);os--;)wn=nn(wn,an[os],os,an);return wn}function bn(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii;)if(nn(an[wn],wn,an))return true;return false}var Un=Yn("length");function Jn(an){return an.split("")}function Je(an){return an.match($l)||[]}function Tn(an,nn,wn){var Ii;return wn(an,function(os,Ys,Au){if(nn(os,Ys,Au))return Ii=Ys,false}),Ii}function On(an,nn,wn,Ii){for(var os=an.length,Ys=wn+(Ii?1:-1);Ii?Ys--:++Ys<os;)if(nn(an[Ys],Ys,an))return Ys;return -1}function vn(an,nn,wn){return nn===nn?Fc(an,nn,wn):On(an,qn,wn)}function Hn(an,nn,wn,Ii){for(var os=wn-1,Ys=an.length;++os<Ys;)if(Ii(an[os],nn))return os;return -1}function qn(an){return an!==an}function xn(an,nn){var wn=an==null?0:an.length;return wn?Nn(an,nn)/wn:dt}function Yn(an){return function(nn){return nn==null?t:nn[an]}}function Wn(an){return function(nn){return an==null?t:an[nn]}}function zn(an,nn,wn,Ii,os){return os(an,function(Ys,Au,Ws){wn=Ii?(Ii=false,Ys):nn(wn,Ys,Au,Ws);}),wn}function Xn(an,nn){var wn=an.length;for(an.sort(nn);wn--;)an[wn]=an[wn].value;return an}function Nn(an,nn){for(var wn,Ii=-1,os=an.length;++Ii<os;){var Ys=nn(an[Ii]);Ys!==t&&(wn=wn===t?Ys:wn+Ys);}return wn}function Mn(an,nn){for(var wn=-1,Ii=Array(an);++wn<an;)Ii[wn]=nn(wn);return Ii}function Ln(an,nn){return Le(nn,function(wn){return [wn,an[wn]]})}function mn(an){return an&&an.slice(0,Nf(an)+1).replace(ki,"")}function dn(an){return function(nn){return an(nn)}}function In(an,nn){return Le(nn,function(wn){return an[wn]})}function Sn(an,nn){return an.has(nn)}function En(an,nn){for(var wn=-1,Ii=an.length;++wn<Ii&&vn(nn,an[wn],0)>-1;);return wn}function kn(an,nn){for(var wn=an.length;wn--&&vn(nn,an[wn],0)>-1;);return wn}function cn(an,nn){for(var wn=an.length,Ii=0;wn--;)an[wn]===nn&&++Ii;return Ii}var _n=Wn(us),Fn=Wn(Yo);function Dn(an){return "\\"+sl[an]}function Bn(an,nn){return an==null?t:an[nn]}function sn(an){return Ns.test(an)}function tr(an){return Gi.test(an)}function er(an){for(var nn,wn=[];!(nn=an.next()).done;)wn.push(nn.value);return wn}function Vn(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii,os){wn[++nn]=[os,Ii];}),wn}function Ze(an,nn){return function(wn){return an(nn(wn))}}function We(an,nn){for(var wn=-1,Ii=an.length,os=0,Ys=[];++wn<Ii;){var Au=an[wn];(Au===nn||Au===h)&&(an[wn]=h,Ys[os++]=wn);}return Ys}function kc(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii){wn[++nn]=Ii;}),wn}function rh(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii){wn[++nn]=[Ii,Ii];}),wn}function Fc(an,nn,wn){for(var Ii=wn-1,os=an.length;++Ii<os;)if(an[Ii]===nn)return Ii;return -1}function Zf(an,nn,wn){for(var Ii=wn+1;Ii--;)if(an[Ii]===nn)return Ii;return Ii}function vo(an){return sn(an)?Bc(an):Un(an)}function ro(an){return sn(an)?Ud(an):Jn(an)}function Nf(an){for(var nn=an.length;nn--&&Fs.test(an.charAt(nn)););return nn}var Th=Wn(ka);function Bc(an){for(var nn=Js.lastIndex=0;Js.test(an);)++nn;return nn}function Ud(an){return an.match(Js)||[]}function ad(an){return an.match(Uo)||[]}var t0=(function an(nn){nn=nn==null?$r:Wo.defaults($r.Object(),nn,Wo.pick($r,xs));var wn=nn.Array,Ii=nn.Date,os=nn.Error,Ys=nn.Function,Au=nn.Math,Ws=nn.Object,un=nn.RegExp,fr=nn.String,Kn=nn.TypeError,Ni=wn.prototype,ls=Ys.prototype,At=Ws.prototype,Ko=nn["__core-js_shared__"],$s=ls.toString,Rs=At.hasOwnProperty,Xs=0,Xo=(function(){var R=/[^.]+$/.exec(Ko&&Ko.keys&&Ko.keys.IE_PROTO||"");return R?"Symbol(src)_1."+R:""})(),ju=At.toString,hc=$s.call(Ws),Uu=$r._,Xa=un("^"+$s.call(Rs).replace(no,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Cu=Wt?nn.Buffer:t,Hs=nn.Symbol,ol=nn.Uint8Array,e0=Cu?Cu.allocUnsafe:t,fc=Ze(Ws.getPrototypeOf,Ws),Ah=Ws.create,Oi=At.propertyIsEnumerable,si=Ni.splice,hr=Hs?Hs.isConcatSpreadable:t,sr=Hs?Hs.iterator:t,Cr=Hs?Hs.toStringTag:t,jc=(function(){try{var R=La(Ws,"defineProperty");return R({},"",{}),R}catch{}})(),Or=nn.clearTimeout!==$r.clearTimeout&&nn.clearTimeout,kr=Ii&&Ii.now!==$r.Date.now&&Ii.now,Br=nn.setTimeout!==$r.setTimeout&&nn.setTimeout,ui=Au.ceil,ci=Au.floor,Hr=Ws.getOwnPropertySymbols,qr=Cu?Cu.isBuffer:t,bi=nn.isFinite,Bi=Ni.join,hi=Ze(Ws.keys,Ws),_r=Au.max,vr=Au.min,Kr=Ii.now,Mr=nn.parseInt,ri=Au.random,Zr=Ni.reverse,Pr=La(nn,"DataView"),Er=La(nn,"Map"),Tr=La(nn,"Promise"),Nr=La(nn,"Set"),Ti=La(nn,"WeakMap"),xi=La(Ws,"create"),di=Ti&&new Ti,yi={},vi=ch(Pr),gi=ch(Er),Ai=ch(Tr),Ri=ch(Nr),Si=ch(Ti),Xr=Hs?Hs.prototype:t,Ci=Xr?Xr.valueOf:t,dc=Xr?Xr.toString:t;function he(R){if(dl(R)&&!zs(R)&&!(R instanceof qs)){if(R instanceof Cl)return R;if(Rs.call(R,"__wrapped__"))return Wu(R)}return new Cl(R)}var ec=(function(){function R(){}return function(j){if(!Zu(j))return {};if(Ah)return Ah(j);R.prototype=j;var at=new R;return R.prototype=t,at}})();function Ch(){}function Cl(R,j){this.__wrapped__=R,this.__actions__=[],this.__chain__=!!j,this.__index__=0,this.__values__=t;}he.templateSettings={escape:mr,evaluate:Ur,interpolate:Yr,variable:"",imports:{_:he}},he.prototype=Ch.prototype,he.prototype.constructor=he,Cl.prototype=ec(Ch.prototype),Cl.prototype.constructor=Cl;function qs(R){this.__wrapped__=R,this.__actions__=[],this.__dir__=1,this.__filtered__=false,this.__iteratees__=[],this.__takeCount__=mt,this.__views__=[];}function zh(){var R=new qs(this.__wrapped__);return R.__actions__=zl(this.__actions__),R.__dir__=this.__dir__,R.__filtered__=this.__filtered__,R.__iteratees__=zl(this.__iteratees__),R.__takeCount__=this.__takeCount__,R.__views__=zl(this.__views__),R}function Fa(){if(this.__filtered__){var R=new qs(this);R.__dir__=-1,R.__filtered__=true;}else R=this.clone(),R.__dir__*=-1;return R}function pc(){var R=this.__wrapped__.value(),j=this.__dir__,at=zs(R),Nt=j<0,Qt=at?R.length:0,ye=Qr(0,Qt,this.__views__),Ue=ye.start,Qe=ye.end,S=Qe-Ue,M=Nt?Qe:Ue-1,rt=this.__iteratees__,vt=rt.length,Ft=0,re=vr(S,this.__takeCount__);if(!at||!Nt&&Qt==S&&re==S)return pd(R,this.__actions__);var Re=[];t:for(;S--&&Ft<re;){M+=j;for(var je=-1,Ye=R[M];++je<vt;){var or=rt[je],ar=or.iteratee,Lr=or.type,li=ar(Ye);if(Lr==H)Ye=li;else if(!li){if(Lr==w)continue t;break t}}Re[Ft++]=Ye;}return Re}qs.prototype=ec(Ch.prototype),qs.prototype.constructor=qs;function le(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function ys(){this.__data__=xi?xi(null):{},this.size=0;}function Rf(R){var j=this.has(R)&&delete this.__data__[R];return this.size-=j?1:0,j}function ia(R){var j=this.__data__;if(xi){var at=j[R];return at===i?t:at}return Rs.call(j,R)?j[R]:t}function ws(R){var j=this.__data__;return xi?j[R]!==t:Rs.call(j,R)}function Aa(R,j){var at=this.__data__;return this.size+=this.has(R)?0:1,at[R]=xi&&j===t?i:j,this}le.prototype.clear=ys,le.prototype.delete=Rf,le.prototype.get=ia,le.prototype.has=ws,le.prototype.set=Aa;function fo(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function Vh(){this.__data__=[],this.size=0;}function Ou(R){var j=this.__data__,at=Nu(j,R);if(at<0)return false;var Nt=j.length-1;return at==Nt?j.pop():si.call(j,at,1),--this.size,true}function ud(R){var j=this.__data__,at=Nu(j,R);return at<0?t:j[at][1]}function wf(R){return Nu(this.__data__,R)>-1}function Is(R,j){var at=this.__data__,Nt=Nu(at,R);return Nt<0?(++this.size,at.push([R,j])):at[Nt][1]=j,this}fo.prototype.clear=Vh,fo.prototype.delete=Ou,fo.prototype.get=ud,fo.prototype.has=wf,fo.prototype.set=Is;function nu(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function ld(){this.size=0,this.__data__={hash:new le,map:new(Er||fo),string:new le};}function Ca(R){var j=Vc(this,R).delete(R);return this.size-=j?1:0,j}function Ol(R){return Vc(this,R).get(R)}function n0(R){return Vc(this,R).has(R)}function C0(R,j){var at=Vc(this,R),Nt=at.size;return at.set(R,j),this.size+=at.size==Nt?0:1,this}nu.prototype.clear=ld,nu.prototype.delete=Ca,nu.prototype.get=Ol,nu.prototype.has=n0,nu.prototype.set=C0;function xc(R){var j=-1,at=R==null?0:R.length;for(this.__data__=new nu;++j<at;)this.add(R[j]);}function Kd(R){return this.__data__.set(R,i),this}function Uc(R){return this.__data__.has(R)}xc.prototype.add=xc.prototype.push=Kd,xc.prototype.has=Uc;function gc(R){var j=this.__data__=new fo(R);this.size=j.size;}function Oh(){this.__data__=new fo,this.size=0;}function Ku(R){var j=this.__data__,at=j.delete(R);return this.size=j.size,at}function ru(R){return this.__data__.get(R)}function Gl(R){return this.__data__.has(R)}function Qo(R,j){var at=this.__data__;if(at instanceof fo){var Nt=at.__data__;if(!Er||Nt.length<r-1)return Nt.push([R,j]),this.size=++at.size,this;at=this.__data__=new nu(Nt);}return at.set(R,j),this.size=at.size,this}gc.prototype.clear=Oh,gc.prototype.delete=Ku,gc.prototype.get=ru,gc.prototype.has=Gl,gc.prototype.set=Qo;function iu(R,j){var at=zs(R),Nt=!at&&O1(R),Qt=!at&&!Nt&&U0(R),ye=!at&&!Nt&&!Qt&&Wd(R),Ue=at||Nt||Qt||ye,Qe=Ue?Mn(R.length,fr):[],S=Qe.length;for(var M in R)(j||Rs.call(R,M))&&!(Ue&&(M=="length"||Qt&&(M=="offset"||M=="parent")||ye&&(M=="buffer"||M=="byteLength"||M=="byteOffset")||ah(M,S)))&&Qe.push(M);return Qe}function al(R){var j=R.length;return j?R[r0(0,j-1)]:t}function $o(R,j){return Uf(zl(R),ha(j,0,R.length))}function xl(R){return Uf(zl(R))}function Su(R,j,at){(at!==t&&!dh(R[j],at)||at===t&&!(j in R))&&Fo(R,j,at);}function Ba(R,j,at){var Nt=R[j];(!(Rs.call(R,j)&&dh(Nt,at))||at===t&&!(j in R))&&Fo(R,j,at);}function Nu(R,j){for(var at=R.length;at--;)if(dh(R[at][0],j))return at;return -1}function Jo(R,j,at,Nt){return Eo(R,function(Qt,ye,Ue){j(Nt,Qt,at(Qt),Ue);}),Nt}function ca(R,j){return R&&ih(j,Xl(j),R)}function Ru(R,j){return R&&ih(j,Kh(j),R)}function Fo(R,j,at){j=="__proto__"&&jc?jc(R,j,{configurable:true,enumerable:true,value:at,writable:true}):R[j]=at;}function $u(R,j){for(var at=-1,Nt=j.length,Qt=wn(Nt),ye=R==null;++at<Nt;)Qt[at]=ye?t:X1(R,j[at]);return Qt}function ha(R,j,at){return R===R&&(at!==t&&(R=R<=at?R:at),j!==t&&(R=R>=j?R:j)),R}function io(R,j,at,Nt,Qt,ye){var Ue,Qe=j&v,S=j&_,M=j&y;if(at&&(Ue=Qt?at(R,Nt,Qt,ye):at(R)),Ue!==t)return Ue;if(!Zu(R))return R;var rt=zs(R);if(rt){if(Ue=nf(R),!Qe)return zl(R,Ue)}else {var vt=_o(R),Ft=vt==ht||vt==xt;if(U0(R))return gl(R,Qe);if(vt==Bt||vt==Zt||Ft&&!Qt){if(Ue=S||Ft?{}:Oo(R),!Qe)return S?_c(R,Ru(Ue,R)):I0(R,ca(Ue,R))}else {if(!Jr[vt])return Qt?R:{};Ue=D0(R,vt,Qe);}}ye||(ye=new gc);var re=ye.get(R);if(re)return re;ye.set(R,Ue),cg(R)?R.forEach(function(Ye){Ue.add(io(Ye,j,at,Ye,R,ye));}):ug(R)&&R.forEach(function(Ye,or){Ue.set(or,io(Ye,j,at,or,R,ye));});var Re=M?S?Bs:Ps:S?Kh:Xl,je=rt?t:Re(R);return la(je||R,function(Ye,or){je&&(or=Ye,Ye=R[or]),Ba(Ue,or,io(Ye,j,at,or,R,ye));}),Ue}function sa(R){var j=Xl(R);return function(at){return wu(at,R,j)}}function wu(R,j,at){var Nt=at.length;if(R==null)return !Nt;for(R=Ws(R);Nt--;){var Qt=at[Nt],ye=j[Qt],Ue=R[Qt];if(Ue===t&&!(Qt in R)||!ye(Ue))return false}return true}function Hu(R,j,at){if(typeof R!="function")throw new Kn(s);return Mh(function(){R.apply(t,at);},j)}function su(R,j,at,Nt){var Qt=-1,ye=Ce,Ue=true,Qe=R.length,S=[],M=j.length;if(!Qe)return S;at&&(j=Le(j,dn(at))),Nt?(ye=$e,Ue=false):j.length>=r&&(ye=Sn,Ue=false,j=new xc(j));t:for(;++Qt<Qe;){var rt=R[Qt],vt=at==null?rt:at(rt);if(rt=Nt||rt!==0?rt:0,Ue&&vt===vt){for(var Ft=M;Ft--;)if(j[Ft]===vt)continue t;S.push(rt);}else ye(j,vt,Nt)||S.push(rt);}return S}var Eo=Dh(Sa),Iu=Dh(gu,true);function oa(R,j){var at=true;return Eo(R,function(Nt,Qt,ye){return at=!!j(Nt,Qt,ye),at}),at}function Bo(R,j,at){for(var Nt=-1,Qt=R.length;++Nt<Qt;){var ye=R[Nt],Ue=j(ye);if(Ue!=null&&(Qe===t?Ue===Ue&&!lf(Ue):at(Ue,Qe)))var Qe=Ue,S=ye;}return S}function ul(R,j,at,Nt){var Qt=R.length;for(at=Us(at),at<0&&(at=-at>Qt?0:Qt+at),Nt=Nt===t||Nt>Qt?Qt:Us(Nt),Nt<0&&(Nt+=Qt),Nt=at>Nt?0:K0(Nt);at<Nt;)R[at++]=j;return R}function ll(R,j){var at=[];return Eo(R,function(Nt,Qt,ye){j(Nt,Qt,ye)&&at.push(Nt);}),at}function so(R,j,at,Nt,Qt){var ye=-1,Ue=R.length;for(at||(at=au),Qt||(Qt=[]);++ye<Ue;){var Qe=R[ye];j>0&&at(Qe)?j>1?so(Qe,j-1,at,Nt,Qt):tn(Qt,Qe):Nt||(Qt[Qt.length]=Qe);}return Qt}var ja=Mf(),Oa=Mf(true);function Sa(R,j){return R&&ja(R,j,Xl)}function gu(R,j){return R&&Oa(R,j,Xl)}function wo(R,j){return Ne(j,function(at){return wc(R[at])})}function Qa(R,j){j=ql(j,R);for(var at=0,Nt=j.length;R!=null&&at<Nt;)R=R[ic(j[at++])];return at&&at==Nt?R:t}function cl(R,j,at){var Nt=j(R);return zs(R)?Nt:tn(Nt,at(R))}function Ls(R){return R==null?R===t?Kt:Pt:Cr&&Cr in Ws(R)?Yu(R):k0(R)}function mu(R,j){return R>j}function ma(R,j){return R!=null&&Rs.call(R,j)}function fa(R,j){return R!=null&&j in Ws(R)}function yu(R,j,at){return R>=vr(j,at)&&R<_r(j,at)}function Na(R,j,at){for(var Nt=at?$e:Ce,Qt=R[0].length,ye=R.length,Ue=ye,Qe=wn(ye),S=1/0,M=[];Ue--;){var rt=R[Ue];Ue&&j&&(rt=Le(rt,dn(j))),S=vr(rt.length,S),Qe[Ue]=!at&&(j||Qt>=120&&rt.length>=120)?new xc(Ue&&rt):t;}rt=R[0];var vt=-1,Ft=Qe[0];t:for(;++vt<Qt&&M.length<S;){var re=rt[vt],Re=j?j(re):re;if(re=at||re!==0?re:0,!(Ft?Sn(Ft,Re):Nt(M,Re,at))){for(Ue=ye;--Ue;){var je=Qe[Ue];if(!(je?Sn(je,Re):Nt(R[Ue],Re,at)))continue t}Ft&&Ft.push(Re),M.push(re);}}return M}function Ra(R,j,at,Nt){return Sa(R,function(Qt,ye,Ue){j(Nt,at(Qt),ye,Ue);}),Nt}function Ho(R,j,at){j=ql(j,R),R=Oc(R,j);var Nt=R==null?R:R[ic(Dl(j))];return Nt==null?t:qi(Nt,R,at)}function Ei(R){return dl(R)&&Ls(R)==Zt}function nc(R){return dl(R)&&Ls(R)==zt}function cd(R){return dl(R)&&Ls(R)==ee}function cs(R,j,at,Nt,Qt){return R===j?true:R==null||j==null||!dl(R)&&!dl(j)?R!==R&&j!==j:Gu(R,j,at,Nt,cs,Qt)}function Gu(R,j,at,Nt,Qt,ye){var Ue=zs(R),Qe=zs(j),S=Ue?oe:_o(R),M=Qe?oe:_o(j);S=S==Zt?Bt:S,M=M==Zt?Bt:M;var rt=S==Bt,vt=M==Bt,Ft=S==M;if(Ft&&U0(R)){if(!U0(j))return false;Ue=true,rt=false;}if(Ft&&!rt)return ye||(ye=new gc),Ue||Wd(R)?wl(R,j,at,Nt,Qt,ye):u0(R,j,S,at,Nt,Qt,ye);if(!(at&g)){var re=rt&&Rs.call(R,"__wrapped__"),Re=vt&&Rs.call(j,"__wrapped__");if(re||Re){var je=re?R.value():R,Ye=Re?j.value():j;return ye||(ye=new gc),Qt(je,Ye,at,Nt,ye)}}return Ft?(ye||(ye=new gc),zc(R,j,at,Nt,Qt,ye)):false}function O0(R){return dl(R)&&_o(R)==bt}function ii(R,j,at,Nt){var Qt=at.length,ye=Qt,Ue=!Nt;if(R==null)return !ye;for(R=Ws(R);Qt--;){var Qe=at[Qt];if(Ue&&Qe[2]?Qe[1]!==R[Qe[0]]:!(Qe[0]in R))return false}for(;++Qt<ye;){Qe=at[Qt];var S=Qe[0],M=R[S],rt=Qe[1];if(Ue&&Qe[2]){if(M===t&&!(S in R))return false}else {var vt=new gc;if(Nt)var Ft=Nt(M,rt,S,R,j,vt);if(!(Ft===t?cs(rt,M,g|u,Nt,vt):Ft))return false}}return true}function Yh(R){if(!Zu(R)||Du(R))return false;var j=wc(R)?Xa:tu;return j.test(ch(R))}function S0(R){return dl(R)&&Ls(R)==Ht}function f1(R){return dl(R)&&_o(R)==Ae}function po(R){return dl(R)&&q1(R.length)&&!!ts[Ls(R)]}function Zo(R){return typeof R=="function"?R:R==null?ea:typeof R=="object"?zs(R)?fd(R[0],R[1]):hd(R):n3(R)}function mc(R){if(!M0(R))return hi(R);var j=[];for(var at in Ws(R))Rs.call(R,at)&&at!="constructor"&&j.push(at);return j}function yc(R){if(!Zu(R))return jf(R);var j=M0(R),at=[];for(var Nt in R)Nt=="constructor"&&(j||!Rs.call(R,Nt))||at.push(Nt);return at}function Wh(R,j){return R<j}function Xh(R,j){var at=-1,Nt=Rc(R)?wn(R.length):[];return Eo(R,function(Qt,ye,Ue){Nt[++at]=j(Qt,ye,Ue);}),Nt}function hd(R){var j=Ga(R);return j.length==1&&j[0][2]?to(j[0][0],j[0][1]):function(at){return at===R||ii(at,R,j)}}function fd(R,j){return P0(R)&&fl(j)?to(ic(R),j):function(at){var Nt=X1(at,R);return Nt===t&&Nt===j?qx(at,R):cs(j,Nt,g|u)}}function If(R,j,at,Nt,Qt){R!==j&&ja(j,function(ye,Ue){if(Qt||(Qt=new gc),Zu(ye))$d(R,j,Ue,at,If,Nt,Qt);else {var Qe=Nt?Nt(uh(R,Ue),ye,Ue+"",R,j,Qt):t;Qe===t&&(Qe=ye),Su(R,Ue,Qe);}},Kh);}function $d(R,j,at,Nt,Qt,ye,Ue){var Qe=uh(R,at),S=uh(j,at),M=Ue.get(S);if(M){Su(R,at,M);return}var rt=ye?ye(Qe,S,at+"",R,j,Ue):t,vt=rt===t;if(vt){var Ft=zs(S),re=!Ft&&U0(S),Re=!Ft&&!re&&Wd(S);rt=S,Ft||re||Re?zs(Qe)?rt=Qe:Qu(Qe)?rt=zl(Qe):re?(vt=false,rt=gl(S,true)):Re?(vt=false,rt=Rl(S,true)):rt=[]:z1(S)||O1(S)?(rt=Qe,O1(Qe)?rt=Bx(Qe):(!Zu(Qe)||wc(Qe))&&(rt=Oo(S))):vt=false;}vt&&(Ue.set(S,rt),Qt(rt,S,Nt,ye,Ue),Ue.delete(S)),Su(R,at,rt);}function Sh(R,j){var at=R.length;if(at)return j+=j<0?at:0,ah(j,at)?R[j]:t}function rc(R,j,at){j.length?j=Le(j,function(ye){return zs(ye)?function(Ue){return Qa(Ue,ye.length===1?ye[0]:ye)}:ye}):j=[ea];var Nt=-1;j=Le(j,dn(zi()));var Qt=Xh(R,function(ye,Ue,Qe){var S=Le(j,function(M){return M(ye)});return {criteria:S,index:++Nt,value:ye}});return Xn(Qt,function(ye,Ue){return rs(ye,Ue,at)})}function Qh(R,j){return Lf(R,j,function(at,Nt){return qx(R,Nt)})}function Lf(R,j,at){for(var Nt=-1,Qt=j.length,ye={};++Nt<Qt;){var Ue=j[Nt],Qe=Qa(R,Ue);at(Qe,Ue)&&Co(ye,ql(Ue,R),Qe);}return ye}function vc(R){return function(j){return Qa(j,R)}}function Df(R,j,at,Nt){var Qt=Nt?Hn:vn,ye=-1,Ue=j.length,Qe=R;for(R===j&&(j=zl(j)),at&&(Qe=Le(R,dn(at)));++ye<Ue;)for(var S=0,M=j[ye],rt=at?at(M):M;(S=Qt(Qe,rt,S,Nt))>-1;)Qe!==R&&si.call(Qe,S,1),si.call(R,S,1);return R}function Nh(R,j){for(var at=R?j.length:0,Nt=at-1;at--;){var Qt=j[at];if(at==Nt||Qt!==ye){var ye=Qt;ah(Qt)?si.call(R,Qt,1):Nl(R,Qt);}}return R}function r0(R,j){return R+ci(ri()*(j-R+1))}function N0(R,j,at,Nt){for(var Qt=-1,ye=_r(ui((j-R)/(at||1)),0),Ue=wn(ye);ye--;)Ue[Nt?ye:++Qt]=R,R+=at;return Ue}function Ua(R,j){var at="";if(!R||j<1||j>pt)return at;do j%2&&(at+=R),j=ci(j/2),j&&(R+=R);while(j);return at}function Yi(R,j){return lh(rf(R,j,ea),R+"")}function qu(R){return al(cu(R))}function wa(R,j){var at=cu(R);return Uf(at,ha(j,0,at.length))}function Co(R,j,at,Nt){if(!Zu(R))return R;j=ql(j,R);for(var Qt=-1,ye=j.length,Ue=ye-1,Qe=R;Qe!=null&&++Qt<ye;){var S=ic(j[Qt]),M=at;if(S==="__proto__"||S==="constructor"||S==="prototype")return R;if(Qt!=Ue){var rt=Qe[S];M=Nt?Nt(rt,S,Qe):t,M===t&&(M=Zu(rt)?rt:ah(j[Qt+1])?[]:{});}Ba(Qe,S,M),Qe=Qe[S];}return R}var Ec=di?function(R,j){return di.set(R,j),R}:ea,dd=jc?function(R,j){return jc(R,"toString",{configurable:true,enumerable:false,value:J1(j),writable:true})}:ea;function Go(R){return Uf(cu(R))}function Sl(R,j,at){var Nt=-1,Qt=R.length;j<0&&(j=-j>Qt?0:Qt+j),at=at>Qt?Qt:at,at<0&&(at+=Qt),Qt=j>at?0:at-j>>>0,j>>>=0;for(var ye=wn(Qt);++Nt<Qt;)ye[Nt]=R[Nt+j];return ye}function Ds(R,j){var at;return Eo(R,function(Nt,Qt,ye){return at=j(Nt,Qt,ye),!at}),!!at}function Rh(R,j,at){var Nt=0,Qt=R==null?Nt:R.length;if(typeof j=="number"&&j===j&&Qt<=gt){for(;Nt<Qt;){var ye=Nt+Qt>>>1,Ue=R[ye];Ue!==null&&!lf(Ue)&&(at?Ue<=j:Ue<j)?Nt=ye+1:Qt=ye;}return Qt}return R0(R,j,ea,at)}function R0(R,j,at,Nt){var Qt=0,ye=R==null?0:R.length;if(ye===0)return 0;j=at(j);for(var Ue=j!==j,Qe=j===null,S=lf(j),M=j===t;Qt<ye;){var rt=ci((Qt+ye)/2),vt=at(R[rt]),Ft=vt!==t,re=vt===null,Re=vt===vt,je=lf(vt);if(Ue)var Ye=Nt||Re;else M?Ye=Re&&(Nt||Ft):Qe?Ye=Re&&Ft&&(Nt||!re):S?Ye=Re&&Ft&&!re&&(Nt||!je):re||je?Ye=false:Ye=Nt?vt<=j:vt<j;Ye?Qt=rt+1:ye=rt;}return vr(ye,Tt)}function Pf(R,j){for(var at=-1,Nt=R.length,Qt=0,ye=[];++at<Nt;){var Ue=R[at],Qe=j?j(Ue):Ue;if(!at||!dh(Qe,S)){var S=Qe;ye[Qt++]=Ue===0?0:Ue;}}return ye}function Hd(R){return typeof R=="number"?R:lf(R)?dt:+R}function Ia(R){if(typeof R=="string")return R;if(zs(R))return Le(R,Ia)+"";if(lf(R))return dc?dc.call(R):"";var j=R+"";return j=="0"&&1/R==-tt?"-0":j}function wh(R,j,at){var Nt=-1,Qt=Ce,ye=R.length,Ue=true,Qe=[],S=Qe;if(at)Ue=false,Qt=$e;else if(ye>=r){var M=j?null:yd(R);if(M)return kc(M);Ue=false,Qt=Sn,S=new xc;}else S=j?[]:Qe;t:for(;++Nt<ye;){var rt=R[Nt],vt=j?j(rt):rt;if(rt=at||rt!==0?rt:0,Ue&&vt===vt){for(var Ft=S.length;Ft--;)if(S[Ft]===vt)continue t;j&&S.push(vt),Qe.push(rt);}else Qt(S,vt,at)||(S!==Qe&&S.push(vt),Qe.push(rt));}return Qe}function Nl(R,j){j=ql(j,R);var at=-1,Nt=j.length;if(!Nt)return true;for(var Qt=R==null||typeof R!="object"&&typeof R!="function";++at<Nt;){var ye=j[at];if(typeof ye=="string"){if(ye==="__proto__"&&!Rs.call(R,"__proto__"))return false;if(ye==="constructor"&&at+1<Nt&&typeof j[at+1]=="string"&&j[at+1]==="prototype"){if(Qt&&at===0)continue;return false}}}var Ue=Oc(R,j);return Ue==null||delete Ue[ic(Dl(j))]}function Kc(R,j,at,Nt){return Co(R,j,at(Qa(R,j)),Nt)}function Ih(R,j,at,Nt){for(var Qt=R.length,ye=Nt?Qt:-1;(Nt?ye--:++ye<Qt)&&j(R[ye],ye,R););return at?Sl(R,Nt?0:ye,Nt?ye+1:Qt):Sl(R,Nt?ye+1:0,Nt?Qt:ye)}function pd(R,j){var at=R;return at instanceof qs&&(at=at.value()),pn(j,function(Nt,Qt){return Qt.func.apply(Qt.thisArg,tn([Nt],Qt.args))},at)}function $c(R,j,at){var Nt=R.length;if(Nt<2)return Nt?wh(R[0]):[];for(var Qt=-1,ye=wn(Nt);++Qt<Nt;)for(var Ue=R[Qt],Qe=-1;++Qe<Nt;)Qe!=Qt&&(ye[Qt]=su(ye[Qt]||Ue,R[Qe],j,at));return wh(so(ye,1),j,at)}function Jh(R,j,at){for(var Nt=-1,Qt=R.length,ye=j.length,Ue={};++Nt<Qt;){var Qe=Nt<ye?j[Nt]:t;at(Ue,R[Nt],Qe);}return Ue}function Ka(R){return Qu(R)?R:[]}function zu(R){return typeof R=="function"?R:ea}function ql(R,j){return zs(R)?R:P0(R,j)?[R]:qd(ya(R))}var d1=Yi;function Hc(R,j,at){var Nt=R.length;return at=at===t?Nt:at,!j&&at>=Nt?R:Sl(R,j,at)}var Gd=Or||function(R){return $r.clearTimeout(R)};function gl(R,j){if(j)return R.slice();var at=R.length,Nt=e0?e0(at):new R.constructor(at);return R.copy(Nt),Nt}function xd(R){var j=new R.constructor(R.byteLength);return new ol(j).set(new ol(R)),j}function w0(R,j){var at=j?xd(R.buffer):R.buffer;return new R.constructor(at,R.byteOffset,R.byteLength)}function i0(R){var j=new R.constructor(R.source,rl.exec(R));return j.lastIndex=R.lastIndex,j}function ou(R){return Ci?Ws(Ci.call(R)):{}}function Rl(R,j){var at=j?xd(R.buffer):R.buffer;return new R.constructor(at,R.byteOffset,R.length)}function $a(R,j){if(R!==j){var at=R!==t,Nt=R===null,Qt=R===R,ye=lf(R),Ue=j!==t,Qe=j===null,S=j===j,M=lf(j);if(!Qe&&!M&&!ye&&R>j||ye&&Ue&&S&&!Qe&&!M||Nt&&Ue&&S||!at&&S||!Qt)return 1;if(!Nt&&!ye&&!M&&R<j||M&&at&&Qt&&!Nt&&!ye||Qe&&at&&Qt||!Ue&&Qt||!S)return -1}return 0}function rs(R,j,at){for(var Nt=-1,Qt=R.criteria,ye=j.criteria,Ue=Qt.length,Qe=at.length;++Nt<Ue;){var S=$a(Qt[Nt],ye[Nt]);if(S){if(Nt>=Qe)return S;var M=at[Nt];return S*(M=="desc"?-1:1)}}return R.index-j.index}function Zh(R,j,at,Nt){for(var Qt=-1,ye=R.length,Ue=at.length,Qe=-1,S=j.length,M=_r(ye-Ue,0),rt=wn(S+M),vt=!Nt;++Qe<S;)rt[Qe]=j[Qe];for(;++Qt<Ue;)(vt||Qt<ye)&&(rt[at[Qt]]=R[Qt]);for(;M--;)rt[Qe++]=R[Qt++];return rt}function Lh(R,j,at,Nt){for(var Qt=-1,ye=R.length,Ue=-1,Qe=at.length,S=-1,M=j.length,rt=_r(ye-Qe,0),vt=wn(rt+M),Ft=!Nt;++Qt<rt;)vt[Qt]=R[Qt];for(var re=Qt;++S<M;)vt[re+S]=j[S];for(;++Ue<Qe;)(Ft||Qt<ye)&&(vt[re+at[Ue]]=R[Qt++]);return vt}function zl(R,j){var at=-1,Nt=R.length;for(j||(j=wn(Nt));++at<Nt;)j[at]=R[at];return j}function ih(R,j,at,Nt){var Qt=!at;at||(at={});for(var ye=-1,Ue=j.length;++ye<Ue;){var Qe=j[ye],S=Nt?Nt(at[Qe],R[Qe],Qe,at,R):t;S===t&&(S=R[Qe]),Qt?Fo(at,Qe,S):Ba(at,Qe,S);}return at}function I0(R,j){return ih(R,ef(R),j)}function _c(R,j){return ih(R,Yc(R),j)}function bc(R,j){return function(at,Nt){var Qt=zs(at)?ua:Jo,ye=j?j():{};return Qt(at,R,zi(Nt,2),ye)}}function Tc(R){return Yi(function(j,at){var Nt=-1,Qt=at.length,ye=Qt>1?at[Qt-1]:t,Ue=Qt>2?at[2]:t;for(ye=R.length>3&&typeof ye=="function"?(Qt--,ye):t,Ue&&Lu(at[0],at[1],Ue)&&(ye=Qt<3?t:ye,Qt=1),j=Ws(j);++Nt<Qt;){var Qe=at[Nt];Qe&&R(j,Qe,Nt,ye);}return j})}function Dh(R,j){return function(at,Nt){if(at==null)return at;if(!Rc(at))return R(at,Nt);for(var Qt=at.length,ye=j?Qt:-1,Ue=Ws(at);(j?ye--:++ye<Qt)&&Nt(Ue[ye],ye,Ue)!==false;);return at}}function Mf(R){return function(j,at,Nt){for(var Qt=-1,ye=Ws(j),Ue=Nt(j),Qe=Ue.length;Qe--;){var S=Ue[R?Qe:++Qt];if(at(ye[S],S,ye)===false)break}return j}}function ml(R,j,at){var Nt=j&c,Qt=s0(R);function ye(){var Ue=this&&this!==$r&&this instanceof ye?Qt:R;return Ue.apply(Nt?at:this,arguments)}return ye}function Vl(R){return function(j){j=ya(j);var at=sn(j)?ro(j):t,Nt=at?at[0]:j.charAt(0),Qt=at?Hc(at,1).join(""):j.slice(1);return Nt[R]()+Qt}}function kf(R){return function(j){return pn(R1(H0(j).replace(_i,"")),R,"")}}function s0(R){return function(){var j=arguments;switch(j.length){case 0:return new R;case 1:return new R(j[0]);case 2:return new R(j[0],j[1]);case 3:return new R(j[0],j[1],j[2]);case 4:return new R(j[0],j[1],j[2],j[3]);case 5:return new R(j[0],j[1],j[2],j[3],j[4]);case 6:return new R(j[0],j[1],j[2],j[3],j[4],j[5]);case 7:return new R(j[0],j[1],j[2],j[3],j[4],j[5],j[6])}var at=ec(R.prototype),Nt=R.apply(at,j);return Zu(Nt)?Nt:at}}function gd(R,j,at){var Nt=s0(R);function Qt(){for(var ye=arguments.length,Ue=wn(ye),Qe=ye,S=Ha(Qt);Qe--;)Ue[Qe]=arguments[Qe];var M=ye<3&&Ue[0]!==S&&Ue[ye-1]!==S?[]:We(Ue,S);if(ye-=M.length,ye<at)return Cc(R,j,sh,Qt.placeholder,t,Ue,M,t,t,at-ye);var rt=this&&this!==$r&&this instanceof Qt?Nt:R;return qi(rt,this,Ue)}return Qt}function Ac(R){return function(j,at,Nt){var Qt=Ws(j);if(!Rc(j)){var ye=zi(at,3);j=Xl(j),at=function(Qe){return ye(Qt[Qe],Qe,Qt)};}var Ue=R(j,at,Nt);return Ue>-1?Qt[ye?j[Ue]:Ue]:t}}function o0(R){return uo(function(j){var at=j.length,Nt=at,Qt=Cl.prototype.thru;for(R&&j.reverse();Nt--;){var ye=j[Nt];if(typeof ye!="function")throw new Kn(s);if(Qt&&!Ue&&oh(ye)=="wrapper")var Ue=new Cl([],true);}for(Nt=Ue?Nt:at;++Nt<at;){ye=j[Nt];var Qe=oh(ye),S=Qe=="wrapper"?l0(ye):t;S&&Ph(S[0])&&S[1]==(E|d|b|T)&&!S[4].length&&S[9]==1?Ue=Ue[oh(S[0])].apply(Ue,S[3]):Ue=ye.length==1&&Ph(ye)?Ue[Qe]():Ue.thru(ye);}return function(){var M=arguments,rt=M[0];if(Ue&&M.length==1&&zs(rt))return Ue.plant(rt).value();for(var vt=0,Ft=at?j[vt].apply(this,M):rt;++vt<at;)Ft=j[vt].call(this,Ft);return Ft}})}function sh(R,j,at,Nt,Qt,ye,Ue,Qe,S,M){var rt=j&E,vt=j&c,Ft=j&l,re=j&(d|m),Re=j&G,je=Ft?t:s0(R);function Ye(){for(var or=arguments.length,ar=wn(or),Lr=or;Lr--;)ar[Lr]=arguments[Lr];if(re)var li=Ha(Ye),Ui=cn(ar,li);if(Nt&&(ar=Zh(ar,Nt,Qt,re)),ye&&(ar=Lh(ar,ye,Ue,re)),or-=Ui,re&&or<M){var Ki=We(ar,li);return Cc(R,j,sh,Ye.placeholder,at,ar,Ki,Qe,S,M-or)}var Os=vt?at:this,es=Ft?Os[R]:R;return or=ar.length,Qe?ar=sf(ar,Qe):Re&&or>1&&ar.reverse(),rt&&S<or&&(ar.length=S),this&&this!==$r&&this instanceof Ye&&(es=je||s0(es)),es.apply(Os,ar)}return Ye}function p1(R,j){return function(at,Nt){return Ra(at,R,j(Nt),{})}}function tf(R,j){return function(at,Nt){var Qt;if(at===t&&Nt===t)return j;if(at!==t&&(Qt=at),Nt!==t){if(Qt===t)return Nt;typeof at=="string"||typeof Nt=="string"?(at=Ia(at),Nt=Ia(Nt)):(at=Hd(at),Nt=Hd(Nt)),Qt=R(at,Nt);}return Qt}}function Gc(R){return uo(function(j){return j=Le(j,dn(zi())),Yi(function(at){var Nt=this;return R(j,function(Qt){return qi(Qt,Nt,at)})})})}function yl(R,j){j=j===t?" ":Ia(j);var at=j.length;if(at<2)return at?Ua(j,R):j;var Nt=Ua(j,ui(R/vo(j)));return sn(j)?Hc(ro(Nt),0,R).join(""):Nt.slice(0,R)}function qc(R,j,at,Nt){var Qt=j&c,ye=s0(R);function Ue(){for(var Qe=-1,S=arguments.length,M=-1,rt=Nt.length,vt=wn(rt+S),Ft=this&&this!==$r&&this instanceof Ue?ye:R;++M<rt;)vt[M]=Nt[M];for(;S--;)vt[M++]=arguments[++Qe];return qi(Ft,Qt?at:this,vt)}return Ue}function md(R){return function(j,at,Nt){return Nt&&typeof Nt!="number"&&Lu(j,at,Nt)&&(at=Nt=t),j=Pu(j),at===t?(at=j,j=0):at=Pu(at),Nt=Nt===t?j<at?1:-1:Pu(Nt),N0(j,at,Nt,R)}}function L0(R){return function(j,at){return typeof j=="string"&&typeof at=="string"||(j=cf(j),at=cf(at)),R(j,at)}}function Cc(R,j,at,Nt,Qt,ye,Ue,Qe,S,M){var rt=j&d,vt=rt?Ue:t,Ft=rt?t:Ue,re=rt?ye:t,Re=rt?t:ye;j|=rt?b:C,j&=~(rt?C:b),j&f||(j&=-4);var je=[R,j,Qt,re,vt,Re,Ft,Qe,S,M],Ye=at.apply(t,je);return Ph(R)&&Sc(Ye,je),Ye.placeholder=Nt,Wc(Ye,R,j)}function bs(R){var j=Au[R];return function(at,Nt){if(at=cf(at),Nt=Nt==null?0:vr(Us(Nt),292),Nt&&bi(at)){var Qt=(ya(at)+"e").split("e"),ye=j(Qt[0]+"e"+(+Qt[1]+Nt));return Qt=(ya(ye)+"e").split("e"),+(Qt[0]+"e"+(+Qt[1]-Nt))}return j(at)}}var yd=Nr&&1/kc(new Nr([,-0]))[1]==tt?function(R){return new Nr(R)}:Mu;function Vu(R){return function(j){var at=_o(j);return at==bt?Vn(j):at==Ae?rh(j):Ln(j,R(j))}}function Zs(R,j,at,Nt,Qt,ye,Ue,Qe){var S=j&l;if(!S&&typeof R!="function")throw new Kn(s);var M=Nt?Nt.length:0;if(M||(j&=-97,Nt=Qt=t),Ue=Ue===t?Ue:_r(Us(Ue),0),Qe=Qe===t?Qe:Us(Qe),M-=Qt?Qt.length:0,j&C){var rt=Nt,vt=Qt;Nt=Qt=t;}var Ft=S?t:l0(R),re=[R,j,at,Nt,Qt,rt,vt,ye,Ue,Qe];if(Ft&&vd(re,Ft),R=re[0],j=re[1],at=re[2],Nt=re[3],Qt=re[4],Qe=re[9]=re[9]===t?S?0:R.length:_r(re[9]-M,0),!Qe&&j&(d|m)&&(j&=-25),!j||j==c)var Re=ml(R,j,at);else j==d||j==m?Re=gd(R,j,Qe):(j==b||j==(c|b))&&!Qt.length?Re=qc(R,j,at,Nt):Re=sh.apply(t,re);var je=Ft?Ec:Sc;return Wc(je(Re,re),R,j)}function Xi(R,j,at,Nt){return R===t||dh(R,At[at])&&!Rs.call(Nt,at)?j:R}function vl(R,j,at,Nt,Qt,ye){return Zu(R)&&Zu(j)&&(ye.set(j,R),If(R,j,t,vl,ye),ye.delete(j)),R}function a0(R){return z1(R)?t:R}function wl(R,j,at,Nt,Qt,ye){var Ue=at&g,Qe=R.length,S=j.length;if(Qe!=S&&!(Ue&&S>Qe))return false;var M=ye.get(R),rt=ye.get(j);if(M&&rt)return M==j&&rt==R;var vt=-1,Ft=true,re=at&u?new xc:t;for(ye.set(R,j),ye.set(j,R);++vt<Qe;){var Re=R[vt],je=j[vt];if(Nt)var Ye=Ue?Nt(je,Re,vt,j,R,ye):Nt(Re,je,vt,R,j,ye);if(Ye!==t){if(Ye)continue;Ft=false;break}if(re){if(!bn(j,function(or,ar){if(!Sn(re,ar)&&(Re===or||Qt(Re,or,at,Nt,ye)))return re.push(ar)})){Ft=false;break}}else if(!(Re===je||Qt(Re,je,at,Nt,ye))){Ft=false;break}}return ye.delete(R),ye.delete(j),Ft}function u0(R,j,at,Nt,Qt,ye,Ue){switch(at){case De:if(R.byteLength!=j.byteLength||R.byteOffset!=j.byteOffset)return false;R=R.buffer,j=j.buffer;case zt:return !(R.byteLength!=j.byteLength||!ye(new ol(R),new ol(j)));case Oe:case ee:case Dt:return dh(+R,+j);case Et:return R.name==j.name&&R.message==j.message;case Ht:case kt:return R==j+"";case bt:var Qe=Vn;case Ae:var S=Nt&g;if(Qe||(Qe=kc),R.size!=j.size&&!S)return false;var M=Ue.get(R);if(M)return M==j;Nt|=u,Ue.set(R,j);var rt=wl(Qe(R),Qe(j),Nt,Qt,ye,Ue);return Ue.delete(R),rt;case jt:if(Ci)return Ci.call(R)==Ci.call(j)}return false}function zc(R,j,at,Nt,Qt,ye){var Ue=at&g,Qe=Ps(R),S=Qe.length,M=Ps(j),rt=M.length;if(S!=rt&&!Ue)return false;for(var vt=S;vt--;){var Ft=Qe[vt];if(!(Ue?Ft in j:Rs.call(j,Ft)))return false}var re=ye.get(R),Re=ye.get(j);if(re&&Re)return re==j&&Re==R;var je=true;ye.set(R,j),ye.set(j,R);for(var Ye=Ue;++vt<S;){Ft=Qe[vt];var or=R[Ft],ar=j[Ft];if(Nt)var Lr=Ue?Nt(ar,or,Ft,j,R,ye):Nt(or,ar,Ft,R,j,ye);if(!(Lr===t?or===ar||Qt(or,ar,at,Nt,ye):Lr)){je=false;break}Ye||(Ye=Ft=="constructor");}if(je&&!Ye){var li=R.constructor,Ui=j.constructor;li!=Ui&&"constructor"in R&&"constructor"in j&&!(typeof li=="function"&&li instanceof li&&typeof Ui=="function"&&Ui instanceof Ui)&&(je=false);}return ye.delete(R),ye.delete(j),je}function uo(R){return lh(rf(R,t,h0),R+"")}function Ps(R){return cl(R,Xl,ef)}function Bs(R){return cl(R,Kh,Yc)}var l0=di?function(R){return di.get(R)}:Mu;function oh(R){for(var j=R.name+"",at=yi[j],Nt=Rs.call(yi,j)?at.length:0;Nt--;){var Qt=at[Nt],ye=Qt.func;if(ye==null||ye==R)return Qt.name}return j}function Ha(R){var j=Rs.call(he,"placeholder")?he:R;return j.placeholder}function zi(){var R=he.iteratee||Lp;return R=R===Lp?Zo:R,arguments.length?R(arguments[0],arguments[1]):R}function Vc(R,j){var at=R.__data__;return hl(j)?at[typeof j=="string"?"string":"hash"]:at.map}function Ga(R){for(var j=Xl(R),at=j.length;at--;){var Nt=j[at],Qt=R[Nt];j[at]=[Nt,Qt,fl(Qt)];}return j}function La(R,j){var at=Bn(R,j);return Yh(at)?at:t}function Yu(R){var j=Rs.call(R,Cr),at=R[Cr];try{R[Cr]=t;var Nt=!0;}catch{}var Qt=ju.call(R);return Nt&&(j?R[Cr]=at:delete R[Cr]),Qt}var ef=Hr?function(R){return R==null?[]:(R=Ws(R),Ne(Hr(R),function(j){return Oi.call(R,j)}))}:M2,Yc=Hr?function(R){for(var j=[];R;)tn(j,ef(R)),R=fc(R);return j}:M2,_o=Ls;(Pr&&_o(new Pr(new ArrayBuffer(1)))!=De||Er&&_o(new Er)!=bt||Tr&&_o(Tr.resolve())!=ne||Nr&&_o(new Nr)!=Ae||Ti&&_o(new Ti)!=$t)&&(_o=function(R){var j=Ls(R),at=j==Bt?R.constructor:t,Nt=at?ch(at):"";if(Nt)switch(Nt){case vi:return De;case gi:return bt;case Ai:return ne;case Ri:return Ae;case Si:return $t}return j});function Qr(R,j,at){for(var Nt=-1,Qt=at.length;++Nt<Qt;){var ye=at[Nt],Ue=ye.size;switch(ye.type){case "drop":R+=Ue;break;case "dropRight":j-=Ue;break;case "take":j=vr(j,R+Ue);break;case "takeRight":R=_r(R,j-Ue);break}}return {start:R,end:j}}function Ff(R){var j=R.match(Po);return j?j[1].split(bu):[]}function El(R,j,at){j=ql(j,R);for(var Nt=-1,Qt=j.length,ye=false;++Nt<Qt;){var Ue=ic(j[Nt]);if(!(ye=R!=null&&at(R,Ue)))break;R=R[Ue];}return ye||++Nt!=Qt?ye:(Qt=R==null?0:R.length,!!Qt&&q1(Qt)&&ah(Ue,Qt)&&(zs(R)||O1(R)))}function nf(R){var j=R.length,at=new R.constructor(j);return j&&typeof R[0]=="string"&&Rs.call(R,"index")&&(at.index=R.index,at.input=R.input),at}function Oo(R){return typeof R.constructor=="function"&&!M0(R)?ec(fc(R)):{}}function D0(R,j,at){var Nt=R.constructor;switch(j){case zt:return xd(R);case Oe:case ee:return new Nt(+R);case De:return w0(R,at);case ie:case yn:case wr:case ni:case Fr:case He:case Ge:case Qn:case Gr:return Rl(R,at);case bt:return new Nt;case Dt:case kt:return new Nt(R);case Ht:return i0(R);case Ae:return new Nt;case jt:return ou(R)}}function Bf(R,j){var at=j.length;if(!at)return R;var Nt=at-1;return j[Nt]=(at>1?"& ":"")+j[Nt],j=j.join(at>2?", ":" "),R.replace(ba,`{
1613
+ `,r.appendChild(i),i.addEventListener("click",async v=>{v.target.dataset.action==="delete"&&(this.dismissOverlays(),await this.deleteAtom(o.id),this.updateDeletionSelects(),this.updateAtomPositions());});let h=v=>{i.contains(v.target)||this.dismissOverlays(),this.shadowRoot?.removeEventListener("click",h),document.removeEventListener("click",h);};setTimeout(()=>{this.shadowRoot?.addEventListener("click",h),document.addEventListener("click",h);},0);}dismissOverlays(){this._activePopover=null,this.shadowRoot?.querySelectorAll(".si-popover, .node-context-menu").forEach(r=>r.remove());}async handleEdgeCreationRequest(r){console.log("\u{1F517} Handling edge creation request:",r.detail);let{relationId:o,sourceNodeId:s,targetNodeId:e,tuple:i}=r.detail;try{this._suppressDataChangeRerender=!0;try{this.dataInstance.addRelationTuple(o,i),console.log(`\u2705 Added relation to data instance: ${o}(${s}, ${e})`);}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(a){console.error("\u274C Failed to handle edge creation request:",a);}}async handleEdgeModificationRequest(r){console.log("\u{1F517} Handling edge modification request:",r.detail);let{oldRelationId:o,newRelationId:s,sourceNodeId:e,targetNodeId:i,tuple:a,tuples:h}=r.detail,v=h??(a?[a]:[]);try{this._suppressDataChangeRerender=!0;try{if(!s||s.trim()===""){if(console.log(`\u{1F5D1}\uFE0F Deleting edge (${v.length} tuple(s))`),o&&o.trim()){for(let _ of v)this.dataInstance.removeRelationTuple(o,_);console.log(`\u2705 Removed ${v.length} relation tuple(s) from ${o}`);}}else if(o.trim()===s.trim()){console.log("\u23ED\uFE0F Same relation name, no data changes needed");return}else {if(o&&o.trim())for(let _ of v)try{this.dataInstance.removeRelationTuple(o,_),console.log(`\u{1F5D1}\uFE0F Removed from ${o}`);}catch(y){let g=y instanceof Error?y.message:String(y);console.log(`\u26A0\uFE0F Could not remove from ${o}: ${g}`);}for(let _ of v)this.dataInstance.addRelationTuple(s,_);console.log(`\u2795 Added ${v.length} tuple(s) to ${s}`);}}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(_){console.error("\u274C Failed to handle edge modification request:",_);}}async handleEdgeReconnectionRequest(r){console.log("\u{1F504} Handling edge reconnection request:",r.detail);let{relationId:o,oldTuple:s,newTuple:e,oldSourceNodeId:i,oldTargetNodeId:a,newSourceNodeId:h,newTargetNodeId:v}=r.detail;try{this._suppressDataChangeRerender=!0;try{if(o&&o.trim())try{this.dataInstance.removeRelationTuple(o,s),console.log(`\u{1F5D1}\uFE0F Removed old tuple from ${o}: ${i} -> ${a}`);}catch(_){let y=_ instanceof Error?_.message:String(_);console.log(`\u26A0\uFE0F Could not remove old tuple from ${o}: ${y}`);}this.dataInstance.addRelationTuple(o,e),console.log(`\u2795 Added new tuple to ${o}: ${h} -> ${v}`);}finally{this._suppressDataChangeRerender=!1;}await this.enforceConstraintsAndRegenerate();}catch(_){console.error("\u274C Failed to handle edge reconnection request:",_);}}async parseCnDSpec(r){try{console.log("\u{1F504} Parsing CnD spec and initializing pipeline..."),this.cndSpecString=r,await this.initializeCnDPipeline(r),this.updateTypeDatalist(),this.updateSpecInfo(),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("spec-loaded",{detail:{spec:this.cndSpecString}})),console.log("\u2705 CnD spec parsed and pipeline initialized");}catch(o){console.error("\u274C Failed to parse CnD spec:",o),this.updateSpecInfo("error",o instanceof Error?o.message:"Parse error");}}async initializeCnDPipeline(r){if(!r.trim()){console.log("\u{1F4DD} Empty spec - clearing pipeline"),this.evaluator=null,this.layoutInstance=null;return}try{console.log("\u{1F527} Initializing CnD pipeline with spec...");let o=hx(r);console.log("\u{1F4CB} Layout spec parsed successfully"),this.evaluator=new exports.SGraphQueryEvaluator,this.evaluator.initialize({sourceData:this.dataInstance}),console.log("\u{1F50D} SGraphQueryEvaluator initialized with data instance"),this.layoutInstance=new exports.LayoutInstance(o,this.evaluator,0,!0),console.log("\u{1F4D0} LayoutInstance created"),console.log("\u2705 CnD pipeline initialized successfully (evaluator + layout instance)");}catch(o){throw console.error("\u274C Failed to initialize CnD pipeline:",o),this.evaluator=null,this.layoutInstance=null,o}}async enforceConstraintsAndRegenerate(){console.log("\u{1F504} enforceConstraintsAndRegenerate() called");try{if(!this.layoutInstance){console.log("\u26A0\uFE0F Cannot enforce constraints - no layout instance available"),this.rerenderGraph();return}console.log("\u{1F4CA} Current data instance state:",{atoms:this.dataInstance.getAtoms().length,relations:this.dataInstance.getRelations().length}),this.evaluator&&(console.log("\u{1F504} Re-initializing evaluator with updated data instance..."),this.evaluator.initialize({sourceData:this.dataInstance}),console.log("\u2705 Evaluator re-initialized")),console.log("\u{1F527} Generating layout with constraint enforcement...");let r=this.layoutInstance.generateLayout(this.dataInstance);r.error?(console.warn("\u26A0\uFE0F Constraint validation error detected:",r.error),this.currentConstraintError=r.error,this.dispatchEvent(new CustomEvent("constraint-error",{detail:{error:r.error,layout:r.layout},bubbles:!0})),console.log("\u{1F4E4} Dispatched constraint-error event with UNSAT core information")):(console.log("\u2705 Layout generated successfully - all constraints satisfied"),this.currentConstraintError!==null&&(console.log("\u{1F9F9} Clearing previous constraint error - constraints now satisfied"),this.currentConstraintError=null,this.dispatchEvent(new CustomEvent("constraints-satisfied",{detail:{layout:r.layout},bubbles:!0})),console.log("\u{1F4E4} Dispatched constraints-satisfied event"))),console.log("\u{1F3A8} Rendering layout...");let o=this.getLayoutState(),s=o.positions.length>0;await this.renderLayout(r.layout,s?{priorPositions:o}:void 0),console.log("\u2705 Constraints enforced and layout regenerated successfully");}catch(r){console.error("\u274C Failed to enforce constraints and regenerate layout:",r),this.dispatchEvent(new CustomEvent("layout-generation-error",{detail:{error:r},bubbles:true}));}}refreshTypesFromDataInstance(){}getAvailableAtomTypes(){let r=new Set;return this.dataInstance&&this.dataInstance.getAtoms().forEach(s=>{s.type&&r.add(s.type);}),r.size===0&&(r.add("Entity"),r.add("Person"),r.add("Object")),Array.from(r)}updateDataInstance(r){try{console.log("Data instance updated:",r);}catch(o){console.error("Failed to update data instance:",o);}}updateExportVisibility(r){}updateTypeDatalist(){}updateSpecInfo(r,o){}generateAtomId(r){if(!this.dataInstance)return `${r}-1`;let o=this.dataInstance.getAtoms(),s=new Set(o.map(a=>a.id)),e=1,i=`${r}-${e}`;for(;s.has(i);)e++,i=`${r}-${e}`;return i}async addAtomFromForm(r,o){if(!r||!o)return null;try{console.log(`\u{1F535} Adding atom: ${o} (${r})`);let e={id:this.generateAtomId(r),type:r,label:o};return this.dataInstance.addAtom(e),console.log(`\u2705 Atom added to data instance: ${e.label} (${e.id}:${e.type})`),this.refreshTypesFromDataInstance(),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("atom-added",{detail:{atom:e}})),console.log(`\u{1F389} Atom addition completed: ${e.label} (${e.id}:${e.type})`),e}catch(s){return console.error("\u274C Failed to add atom:",s),null}}updateAtomPositions(){}updateRelationButtonState(){}async addRelationFromForm(r){try{let o=r?.trim()||this.shadowRoot?.querySelector(".si-rel-name")?.value?.trim()||"";if(!o)return;let s=this.relationAtomPositions.filter(h=>h.trim()!=="");if(s.length<2){console.warn("Need at least 2 atoms for a relation");return}console.log(`\u{1F517} Adding relation: ${o}(${s.join(", ")})`);let e=this.dataInstance.getAtoms(),i=s.map(h=>e.find(_=>_.id===h)?.type||"untyped"),a={atoms:s,types:i};this.dataInstance.addRelationTuple(o,a),console.log(`\u2705 Relation added to data instance: ${o}(${s.join(", ")})`),await this.enforceConstraintsAndRegenerate(),this.dispatchEvent(new CustomEvent("relation-added",{detail:{relationType:o,tuple:a}})),console.log(`\u{1F389} Relation addition completed: ${o}(${s.join(", ")})`);}catch(o){console.error("\u274C Failed to add relation:",o);}}exportDataAsJSON(){try{console.log("\u{1F4E4} Exporting data instance using reify()...");let r=this.dataInstance.reify(),o=typeof r=="string"?r:JSON.stringify(r,null,2);this.dispatchEvent(new CustomEvent("data-exported",{detail:{data:o,format:typeof r=="string"?"text":"json",reified:r}})),console.log("\u2705 Data exported using reify()");}catch(r){console.error("\u274C Failed to export data:",r);}}handleDataChangeUIUpdate(r=false){}async handleDataDeletionWithValidation(r=false){await this.enforceConstraintsAndRegenerate();}setDataInstance(r){console.log("\u{1F504} Setting new data instance"),this.dataInstance&&(this.dataInstanceEventHandlers.atomAdded&&this.dataInstance.removeEventListener("atomAdded",this.dataInstanceEventHandlers.atomAdded),this.dataInstanceEventHandlers.atomRemoved&&this.dataInstance.removeEventListener("atomRemoved",this.dataInstanceEventHandlers.atomRemoved),this.dataInstanceEventHandlers.relationTupleAdded&&this.dataInstance.removeEventListener("relationTupleAdded",this.dataInstanceEventHandlers.relationTupleAdded),this.dataInstanceEventHandlers.relationTupleRemoved&&this.dataInstance.removeEventListener("relationTupleRemoved",this.dataInstanceEventHandlers.relationTupleRemoved)),this.dataInstance=r,this.refreshTypesFromDataInstance(),this.dataInstanceEventHandlers.atomAdded=async()=>{console.log("\u{1F4CD} Atom added to instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(true),this._suppressDataChangeRerender||await this.enforceConstraintsAndRegenerate();},this.dataInstanceEventHandlers.relationTupleAdded=async()=>{console.log("\u{1F517} Relation added to instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(false),this._suppressDataChangeRerender||await this.enforceConstraintsAndRegenerate();},this.dataInstanceEventHandlers.atomRemoved=async()=>{console.log("\u{1F5D1}\uFE0F Atom removed from instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(true),this._suppressDataChangeRerender||await this.handleDataDeletionWithValidation(true);},this.dataInstanceEventHandlers.relationTupleRemoved=async()=>{console.log("\u{1F5D1}\uFE0F Relation tuple removed from instance - updating UI and re-validating constraints"),this.handleDataChangeUIUpdate(false),this._suppressDataChangeRerender||await this.handleDataDeletionWithValidation(false);},r.addEventListener("atomAdded",this.dataInstanceEventHandlers.atomAdded),r.addEventListener("relationTupleAdded",this.dataInstanceEventHandlers.relationTupleAdded),r.addEventListener("atomRemoved",this.dataInstanceEventHandlers.atomRemoved),r.addEventListener("relationTupleRemoved",this.dataInstanceEventHandlers.relationTupleRemoved),this.updateDeletionSelects(),this.updateAtomPositions(),console.log("\u2705 Data instance set successfully");}updateDeletionSelects(){}async deleteAtom(r){if(r)try{console.log(`\u{1F5D1}\uFE0F Deleting atom: ${r}`);let s=this.dataInstance.getAtoms().find(e=>e.id===r);if(!s){console.warn(`\u26A0\uFE0F Atom ${r} not found`);return}this.dataInstance.removeAtom(r),console.log(`\u2705 Atom removed from data instance: ${s.label} (${s.id})`),console.log(`\u{1F389} Atom deletion completed: ${s.label} (${s.id})`),this.dispatchEvent(new CustomEvent("atom-deleted",{detail:{atom:s}}));}catch(o){console.error("\u274C Failed to delete atom:",o);}}async deleteRelation(r){if(r)try{let o=parseInt(r,10);console.log(`\u{1F5D1}\uFE0F Deleting relation tuple at index: ${o}`);let s=this.dataInstance.getRelations(),e=0,i=null,a=null;for(let v of s){for(let _ of v.tuples){if(e===o){i=v,a=_;break}e++;}if(i)break}if(!i||!a){console.warn(`\u26A0\uFE0F Relation tuple at index ${o} not found`);return}let h=i.id||i.name;console.log(`\u{1F5D1}\uFE0F Found tuple in relation "${h}": ${a.atoms.join(" \u2192 ")}`),this.dataInstance.removeRelationTuple(h,a),console.log(`\u2705 Relation tuple removed from data instance: ${h}: ${a.atoms.join(" \u2192 ")}`),console.log(`\u{1F389} Relation tuple deletion completed: ${h}: ${a.atoms.join(" \u2192 ")}`),this.dispatchEvent(new CustomEvent("relation-tuple-deleted",{detail:{relationId:h,tuple:a}}));}catch(o){console.error("\u274C Failed to delete relation tuple:",o);}}async clearAllItems(){try{console.log("\u{1F9F9} Clearing all atoms and relations...");let r=new exports.JSONDataInstance({atoms:[],relations:[],types:[]});this.setDataInstance(r),console.log("\u2705 All items cleared from data instance"),await this.enforceConstraintsAndRegenerate(),console.log("\u{1F389} Clear all completed"),this.dispatchEvent(new CustomEvent("all-items-cleared",{detail:{}}));}catch(r){console.error("\u274C Failed to clear all items:",r);}}getDataInstance(){return this.dataInstance}getCurrentConstraintError(){return this.currentConstraintError}hasConstraintErrors(){return this.currentConstraintError!==null}async setCnDSpec(r){this.setAttribute("cnd-spec",r),await this.parseCnDSpec(r);}getAvailableTypes(){return this.getAvailableAtomTypes()}};});var SB=be((Om,Hv)=>{(function(){var t,n="4.17.23",r=200,o="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",s="Expected a function",e="Invalid `variable` option passed into `_.template`",i="__lodash_hash_undefined__",a=500,h="__lodash_placeholder__",v=1,_=2,y=4,g=1,u=2,c=1,l=2,f=4,d=8,m=16,b=32,C=64,E=128,T=256,G=512,q=30,B="...",K=800,nt=16,w=1,H=2,V=3,tt=1/0,pt=9007199254740991,J=17976931348623157e292,dt=NaN,mt=4294967295,Tt=mt-1,gt=mt>>>1,Ot=[["ary",E],["bind",c],["bindKey",l],["curry",d],["curryRight",m],["flip",G],["partial",b],["partialRight",C],["rearg",T]],Zt="[object Arguments]",oe="[object Array]",te="[object AsyncFunction]",Oe="[object Boolean]",ee="[object Date]",Jt="[object DOMException]",Et="[object Error]",ht="[object Function]",xt="[object GeneratorFunction]",bt="[object Map]",Dt="[object Number]",Pt="[object Null]",Bt="[object Object]",ne="[object Promise]",ce="[object Proxy]",Ht="[object RegExp]",Ae="[object Set]",kt="[object String]",jt="[object Symbol]",Kt="[object Undefined]",$t="[object WeakMap]",yt="[object WeakSet]",zt="[object ArrayBuffer]",De="[object DataView]",ie="[object Float32Array]",yn="[object Float64Array]",wr="[object Int8Array]",ni="[object Int16Array]",Fr="[object Int32Array]",He="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Qn="[object Uint16Array]",Gr="[object Uint32Array]",ti=/\b__p \+= '';/g,oi=/\b(__p \+=) '' \+/g,fi=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Mi=/&(?:amp|lt|gt|quot|#39);/g,Fi=/[&<>"']/g,ve=RegExp(Mi.source),$n=RegExp(Fi.source),mr=/<%-([\s\S]+?)%>/g,Ur=/<%([\s\S]+?)%>/g,Yr=/<%=([\s\S]+?)%>/g,$i=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,wi=/^\w*$/,ps=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,no=/[\\^$.*+?()[\]{}|]/g,Wi=RegExp(no.source),ki=/^\s+/,Fs=/\s/,ba=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Po=/\{\n\/\* \[wrapped with (.+)\] \*/,bu=/,? & /,$l=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,du=/[()=,{}\[\]\/\s]/,Ta=/\\(\\)?/g,Mo=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,rl=/\w*$/,Tu=/^[-+]0x[0-9a-f]+$/i,Al=/^0b[01]+$/i,tu=/^\[object .+?Constructor\]$/,No=/^0o[0-7]+$/i,Ro=/^(?:0|[1-9]\d*)$/,pu=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Bu=/($^)/,il=/['\n\r\u2028\u2029\\]/g,ao="\\ud800-\\udfff",xu="\\u0300-\\u036f",pr="\\ufe20-\\ufe2f",D="\\u20d0-\\u20ff",O=xu+pr+D,it="\\u2700-\\u27bf",Gt="a-z\\xdf-\\xf6\\xf8-\\xff",Zn="\\xac\\xb1\\xd7\\xf7",Wr="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",p="\\u2000-\\u206f",$=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",k="A-Z\\xc0-\\xd6\\xd8-\\xde",F="\\ufe0e\\ufe0f",W=Zn+Wr+p+$,P="['\u2019]",X="["+ao+"]",Q="["+W+"]",lt="["+O+"]",pe="\\d+",fe="["+it+"]",Mt="["+Gt+"]",Rt="[^"+ao+W+pe+it+Gt+k+"]",qt="\\ud83c[\\udffb-\\udfff]",we="(?:"+lt+"|"+qt+")",Ee="[^"+ao+"]",Pe="(?:\\ud83c[\\udde6-\\uddff]){2}",me="[\\ud800-\\udbff][\\udc00-\\udfff]",se="["+k+"]",jn="\\u200d",Be="(?:"+Mt+"|"+Rt+")",nr="(?:"+se+"|"+Rt+")",An="(?:"+P+"(?:d|ll|m|re|s|t|ve))?",on="(?:"+P+"(?:D|LL|M|RE|S|T|VE))?",Cn=we+"?",ir="["+F+"]?",br="(?:"+jn+"(?:"+[Ee,Pe,me].join("|")+")"+ir+Cn+")*",ei="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ve="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",yr=ir+Cn+br,gr="(?:"+[fe,Pe,me].join("|")+")"+yr,cr="(?:"+[Ee+lt+"?",lt,Pe,me,X].join("|")+")",_i=RegExp(P,"g"),_s=RegExp(lt,"g"),Js=RegExp(qt+"(?="+qt+")|"+cr+yr,"g"),Uo=RegExp([se+"?"+Mt+"+"+An+"(?="+[Q,se,"$"].join("|")+")",nr+"+"+on+"(?="+[Q,se+Be,"$"].join("|")+")",se+"?"+Be+"+"+An,se+"+"+on,Ve,ei,pe,gr].join("|"),"g"),Ns=RegExp("["+jn+ao+O+F+"]"),Gi=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,xs=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],eu=-1,ts={};ts[ie]=ts[yn]=ts[wr]=ts[ni]=ts[Fr]=ts[He]=ts[Ge]=ts[Qn]=ts[Gr]=true,ts[Zt]=ts[oe]=ts[zt]=ts[Oe]=ts[De]=ts[ee]=ts[Et]=ts[ht]=ts[bt]=ts[Dt]=ts[Bt]=ts[Ht]=ts[Ae]=ts[kt]=ts[$t]=false;var Jr={};Jr[Zt]=Jr[oe]=Jr[zt]=Jr[De]=Jr[Oe]=Jr[ee]=Jr[ie]=Jr[yn]=Jr[wr]=Jr[ni]=Jr[Fr]=Jr[bt]=Jr[Dt]=Jr[Bt]=Jr[Ht]=Jr[Ae]=Jr[kt]=Jr[jt]=Jr[He]=Jr[Ge]=Jr[Qn]=Jr[Gr]=true,Jr[Et]=Jr[ht]=Jr[$t]=false;var us={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},Yo={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ka={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},sl={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Hl=parseFloat,ga=parseInt,Ks=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,ms=typeof self=="object"&&self&&self.Object===Object&&self,$r=Ks||ms||Function("return this")(),Sf=typeof Om=="object"&&Om&&!Om.nodeType&&Om,nh=Sf&&typeof Hv=="object"&&Hv&&!Hv.nodeType&&Hv,Wt=nh&&nh.exports===Sf,Yt=Wt&&Ks.process,ue=(function(){try{var an=nh&&nh.require&&nh.require("util").types;return an||Yt&&Yt.binding&&Yt.binding("util")}catch{}})(),Se=ue&&ue.isArrayBuffer,ge=ue&&ue.isDate,ae=ue&&ue.isMap,ke=ue&&ue.isRegExp,Ke=ue&&ue.isSet,Xe=ue&&ue.isTypedArray;function qi(an,nn,wn){switch(wn.length){case 0:return an.call(nn);case 1:return an.call(nn,wn[0]);case 2:return an.call(nn,wn[0],wn[1]);case 3:return an.call(nn,wn[0],wn[1],wn[2])}return an.apply(nn,wn)}function ua(an,nn,wn,Ii){for(var os=-1,Ys=an==null?0:an.length;++os<Ys;){var Au=an[os];nn(Ii,Au,wn(Au),an);}return Ii}function la(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii&&nn(an[wn],wn,an)!==false;);return an}function ko(an,nn){for(var wn=an==null?0:an.length;wn--&&nn(an[wn],wn,an)!==false;);return an}function Te(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii;)if(!nn(an[wn],wn,an))return false;return true}function Ne(an,nn){for(var wn=-1,Ii=an==null?0:an.length,os=0,Ys=[];++wn<Ii;){var Au=an[wn];nn(Au,wn,an)&&(Ys[os++]=Au);}return Ys}function Ce(an,nn){var wn=an==null?0:an.length;return !!wn&&vn(an,nn,0)>-1}function $e(an,nn,wn){for(var Ii=-1,os=an==null?0:an.length;++Ii<os;)if(wn(nn,an[Ii]))return true;return false}function Le(an,nn){for(var wn=-1,Ii=an==null?0:an.length,os=Array(Ii);++wn<Ii;)os[wn]=nn(an[wn],wn,an);return os}function tn(an,nn){for(var wn=-1,Ii=nn.length,os=an.length;++wn<Ii;)an[os+wn]=nn[wn];return an}function pn(an,nn,wn,Ii){var os=-1,Ys=an==null?0:an.length;for(Ii&&Ys&&(wn=an[++os]);++os<Ys;)wn=nn(wn,an[os],os,an);return wn}function en(an,nn,wn,Ii){var os=an==null?0:an.length;for(Ii&&os&&(wn=an[--os]);os--;)wn=nn(wn,an[os],os,an);return wn}function bn(an,nn){for(var wn=-1,Ii=an==null?0:an.length;++wn<Ii;)if(nn(an[wn],wn,an))return true;return false}var Un=Yn("length");function Jn(an){return an.split("")}function Je(an){return an.match($l)||[]}function Tn(an,nn,wn){var Ii;return wn(an,function(os,Ys,Au){if(nn(os,Ys,Au))return Ii=Ys,false}),Ii}function On(an,nn,wn,Ii){for(var os=an.length,Ys=wn+(Ii?1:-1);Ii?Ys--:++Ys<os;)if(nn(an[Ys],Ys,an))return Ys;return -1}function vn(an,nn,wn){return nn===nn?Fc(an,nn,wn):On(an,qn,wn)}function Hn(an,nn,wn,Ii){for(var os=wn-1,Ys=an.length;++os<Ys;)if(Ii(an[os],nn))return os;return -1}function qn(an){return an!==an}function xn(an,nn){var wn=an==null?0:an.length;return wn?Nn(an,nn)/wn:dt}function Yn(an){return function(nn){return nn==null?t:nn[an]}}function Wn(an){return function(nn){return an==null?t:an[nn]}}function zn(an,nn,wn,Ii,os){return os(an,function(Ys,Au,Ws){wn=Ii?(Ii=false,Ys):nn(wn,Ys,Au,Ws);}),wn}function Xn(an,nn){var wn=an.length;for(an.sort(nn);wn--;)an[wn]=an[wn].value;return an}function Nn(an,nn){for(var wn,Ii=-1,os=an.length;++Ii<os;){var Ys=nn(an[Ii]);Ys!==t&&(wn=wn===t?Ys:wn+Ys);}return wn}function Mn(an,nn){for(var wn=-1,Ii=Array(an);++wn<an;)Ii[wn]=nn(wn);return Ii}function Ln(an,nn){return Le(nn,function(wn){return [wn,an[wn]]})}function mn(an){return an&&an.slice(0,Nf(an)+1).replace(ki,"")}function dn(an){return function(nn){return an(nn)}}function In(an,nn){return Le(nn,function(wn){return an[wn]})}function Sn(an,nn){return an.has(nn)}function En(an,nn){for(var wn=-1,Ii=an.length;++wn<Ii&&vn(nn,an[wn],0)>-1;);return wn}function kn(an,nn){for(var wn=an.length;wn--&&vn(nn,an[wn],0)>-1;);return wn}function cn(an,nn){for(var wn=an.length,Ii=0;wn--;)an[wn]===nn&&++Ii;return Ii}var _n=Wn(us),Fn=Wn(Yo);function Dn(an){return "\\"+sl[an]}function Bn(an,nn){return an==null?t:an[nn]}function sn(an){return Ns.test(an)}function tr(an){return Gi.test(an)}function er(an){for(var nn,wn=[];!(nn=an.next()).done;)wn.push(nn.value);return wn}function Vn(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii,os){wn[++nn]=[os,Ii];}),wn}function Ze(an,nn){return function(wn){return an(nn(wn))}}function We(an,nn){for(var wn=-1,Ii=an.length,os=0,Ys=[];++wn<Ii;){var Au=an[wn];(Au===nn||Au===h)&&(an[wn]=h,Ys[os++]=wn);}return Ys}function kc(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii){wn[++nn]=Ii;}),wn}function rh(an){var nn=-1,wn=Array(an.size);return an.forEach(function(Ii){wn[++nn]=[Ii,Ii];}),wn}function Fc(an,nn,wn){for(var Ii=wn-1,os=an.length;++Ii<os;)if(an[Ii]===nn)return Ii;return -1}function Zf(an,nn,wn){for(var Ii=wn+1;Ii--;)if(an[Ii]===nn)return Ii;return Ii}function vo(an){return sn(an)?Bc(an):Un(an)}function ro(an){return sn(an)?Ud(an):Jn(an)}function Nf(an){for(var nn=an.length;nn--&&Fs.test(an.charAt(nn)););return nn}var Th=Wn(ka);function Bc(an){for(var nn=Js.lastIndex=0;Js.test(an);)++nn;return nn}function Ud(an){return an.match(Js)||[]}function ad(an){return an.match(Uo)||[]}var t0=(function an(nn){nn=nn==null?$r:Wo.defaults($r.Object(),nn,Wo.pick($r,xs));var wn=nn.Array,Ii=nn.Date,os=nn.Error,Ys=nn.Function,Au=nn.Math,Ws=nn.Object,un=nn.RegExp,fr=nn.String,Kn=nn.TypeError,Ni=wn.prototype,ls=Ys.prototype,At=Ws.prototype,Ko=nn["__core-js_shared__"],$s=ls.toString,Rs=At.hasOwnProperty,Xs=0,Xo=(function(){var R=/[^.]+$/.exec(Ko&&Ko.keys&&Ko.keys.IE_PROTO||"");return R?"Symbol(src)_1."+R:""})(),ju=At.toString,hc=$s.call(Ws),Uu=$r._,Xa=un("^"+$s.call(Rs).replace(no,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Cu=Wt?nn.Buffer:t,Hs=nn.Symbol,ol=nn.Uint8Array,e0=Cu?Cu.allocUnsafe:t,fc=Ze(Ws.getPrototypeOf,Ws),Ah=Ws.create,Oi=At.propertyIsEnumerable,si=Ni.splice,hr=Hs?Hs.isConcatSpreadable:t,sr=Hs?Hs.iterator:t,Cr=Hs?Hs.toStringTag:t,jc=(function(){try{var R=La(Ws,"defineProperty");return R({},"",{}),R}catch{}})(),Or=nn.clearTimeout!==$r.clearTimeout&&nn.clearTimeout,kr=Ii&&Ii.now!==$r.Date.now&&Ii.now,Br=nn.setTimeout!==$r.setTimeout&&nn.setTimeout,ui=Au.ceil,ci=Au.floor,Hr=Ws.getOwnPropertySymbols,qr=Cu?Cu.isBuffer:t,bi=nn.isFinite,Bi=Ni.join,hi=Ze(Ws.keys,Ws),_r=Au.max,vr=Au.min,Kr=Ii.now,Mr=nn.parseInt,ri=Au.random,Zr=Ni.reverse,Pr=La(nn,"DataView"),Er=La(nn,"Map"),Tr=La(nn,"Promise"),Nr=La(nn,"Set"),Ti=La(nn,"WeakMap"),xi=La(Ws,"create"),di=Ti&&new Ti,yi={},vi=ch(Pr),gi=ch(Er),Ai=ch(Tr),Ri=ch(Nr),Si=ch(Ti),Xr=Hs?Hs.prototype:t,Ci=Xr?Xr.valueOf:t,dc=Xr?Xr.toString:t;function he(R){if(dl(R)&&!zs(R)&&!(R instanceof qs)){if(R instanceof Cl)return R;if(Rs.call(R,"__wrapped__"))return Wu(R)}return new Cl(R)}var ec=(function(){function R(){}return function(j){if(!Zu(j))return {};if(Ah)return Ah(j);R.prototype=j;var at=new R;return R.prototype=t,at}})();function Ch(){}function Cl(R,j){this.__wrapped__=R,this.__actions__=[],this.__chain__=!!j,this.__index__=0,this.__values__=t;}he.templateSettings={escape:mr,evaluate:Ur,interpolate:Yr,variable:"",imports:{_:he}},he.prototype=Ch.prototype,he.prototype.constructor=he,Cl.prototype=ec(Ch.prototype),Cl.prototype.constructor=Cl;function qs(R){this.__wrapped__=R,this.__actions__=[],this.__dir__=1,this.__filtered__=false,this.__iteratees__=[],this.__takeCount__=mt,this.__views__=[];}function zh(){var R=new qs(this.__wrapped__);return R.__actions__=zl(this.__actions__),R.__dir__=this.__dir__,R.__filtered__=this.__filtered__,R.__iteratees__=zl(this.__iteratees__),R.__takeCount__=this.__takeCount__,R.__views__=zl(this.__views__),R}function Fa(){if(this.__filtered__){var R=new qs(this);R.__dir__=-1,R.__filtered__=true;}else R=this.clone(),R.__dir__*=-1;return R}function pc(){var R=this.__wrapped__.value(),j=this.__dir__,at=zs(R),Nt=j<0,Qt=at?R.length:0,ye=Qr(0,Qt,this.__views__),Ue=ye.start,Qe=ye.end,S=Qe-Ue,M=Nt?Qe:Ue-1,rt=this.__iteratees__,vt=rt.length,Ft=0,re=vr(S,this.__takeCount__);if(!at||!Nt&&Qt==S&&re==S)return pd(R,this.__actions__);var Re=[];t:for(;S--&&Ft<re;){M+=j;for(var je=-1,Ye=R[M];++je<vt;){var or=rt[je],ar=or.iteratee,Lr=or.type,li=ar(Ye);if(Lr==H)Ye=li;else if(!li){if(Lr==w)continue t;break t}}Re[Ft++]=Ye;}return Re}qs.prototype=ec(Ch.prototype),qs.prototype.constructor=qs;function le(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function ys(){this.__data__=xi?xi(null):{},this.size=0;}function Rf(R){var j=this.has(R)&&delete this.__data__[R];return this.size-=j?1:0,j}function ia(R){var j=this.__data__;if(xi){var at=j[R];return at===i?t:at}return Rs.call(j,R)?j[R]:t}function ws(R){var j=this.__data__;return xi?j[R]!==t:Rs.call(j,R)}function Aa(R,j){var at=this.__data__;return this.size+=this.has(R)?0:1,at[R]=xi&&j===t?i:j,this}le.prototype.clear=ys,le.prototype.delete=Rf,le.prototype.get=ia,le.prototype.has=ws,le.prototype.set=Aa;function fo(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function Vh(){this.__data__=[],this.size=0;}function Ou(R){var j=this.__data__,at=Nu(j,R);if(at<0)return false;var Nt=j.length-1;return at==Nt?j.pop():si.call(j,at,1),--this.size,true}function ud(R){var j=this.__data__,at=Nu(j,R);return at<0?t:j[at][1]}function wf(R){return Nu(this.__data__,R)>-1}function Is(R,j){var at=this.__data__,Nt=Nu(at,R);return Nt<0?(++this.size,at.push([R,j])):at[Nt][1]=j,this}fo.prototype.clear=Vh,fo.prototype.delete=Ou,fo.prototype.get=ud,fo.prototype.has=wf,fo.prototype.set=Is;function nu(R){var j=-1,at=R==null?0:R.length;for(this.clear();++j<at;){var Nt=R[j];this.set(Nt[0],Nt[1]);}}function ld(){this.size=0,this.__data__={hash:new le,map:new(Er||fo),string:new le};}function Ca(R){var j=Vc(this,R).delete(R);return this.size-=j?1:0,j}function Ol(R){return Vc(this,R).get(R)}function n0(R){return Vc(this,R).has(R)}function C0(R,j){var at=Vc(this,R),Nt=at.size;return at.set(R,j),this.size+=at.size==Nt?0:1,this}nu.prototype.clear=ld,nu.prototype.delete=Ca,nu.prototype.get=Ol,nu.prototype.has=n0,nu.prototype.set=C0;function xc(R){var j=-1,at=R==null?0:R.length;for(this.__data__=new nu;++j<at;)this.add(R[j]);}function Kd(R){return this.__data__.set(R,i),this}function Uc(R){return this.__data__.has(R)}xc.prototype.add=xc.prototype.push=Kd,xc.prototype.has=Uc;function gc(R){var j=this.__data__=new fo(R);this.size=j.size;}function Oh(){this.__data__=new fo,this.size=0;}function Ku(R){var j=this.__data__,at=j.delete(R);return this.size=j.size,at}function ru(R){return this.__data__.get(R)}function Gl(R){return this.__data__.has(R)}function Qo(R,j){var at=this.__data__;if(at instanceof fo){var Nt=at.__data__;if(!Er||Nt.length<r-1)return Nt.push([R,j]),this.size=++at.size,this;at=this.__data__=new nu(Nt);}return at.set(R,j),this.size=at.size,this}gc.prototype.clear=Oh,gc.prototype.delete=Ku,gc.prototype.get=ru,gc.prototype.has=Gl,gc.prototype.set=Qo;function iu(R,j){var at=zs(R),Nt=!at&&O1(R),Qt=!at&&!Nt&&U0(R),ye=!at&&!Nt&&!Qt&&Wd(R),Ue=at||Nt||Qt||ye,Qe=Ue?Mn(R.length,fr):[],S=Qe.length;for(var M in R)(j||Rs.call(R,M))&&!(Ue&&(M=="length"||Qt&&(M=="offset"||M=="parent")||ye&&(M=="buffer"||M=="byteLength"||M=="byteOffset")||ah(M,S)))&&Qe.push(M);return Qe}function al(R){var j=R.length;return j?R[r0(0,j-1)]:t}function $o(R,j){return Uf(zl(R),ha(j,0,R.length))}function xl(R){return Uf(zl(R))}function Su(R,j,at){(at!==t&&!dh(R[j],at)||at===t&&!(j in R))&&Fo(R,j,at);}function Ba(R,j,at){var Nt=R[j];(!(Rs.call(R,j)&&dh(Nt,at))||at===t&&!(j in R))&&Fo(R,j,at);}function Nu(R,j){for(var at=R.length;at--;)if(dh(R[at][0],j))return at;return -1}function Jo(R,j,at,Nt){return Eo(R,function(Qt,ye,Ue){j(Nt,Qt,at(Qt),Ue);}),Nt}function ca(R,j){return R&&ih(j,Xl(j),R)}function Ru(R,j){return R&&ih(j,Kh(j),R)}function Fo(R,j,at){j=="__proto__"&&jc?jc(R,j,{configurable:true,enumerable:true,value:at,writable:true}):R[j]=at;}function $u(R,j){for(var at=-1,Nt=j.length,Qt=wn(Nt),ye=R==null;++at<Nt;)Qt[at]=ye?t:X1(R,j[at]);return Qt}function ha(R,j,at){return R===R&&(at!==t&&(R=R<=at?R:at),j!==t&&(R=R>=j?R:j)),R}function io(R,j,at,Nt,Qt,ye){var Ue,Qe=j&v,S=j&_,M=j&y;if(at&&(Ue=Qt?at(R,Nt,Qt,ye):at(R)),Ue!==t)return Ue;if(!Zu(R))return R;var rt=zs(R);if(rt){if(Ue=nf(R),!Qe)return zl(R,Ue)}else {var vt=_o(R),Ft=vt==ht||vt==xt;if(U0(R))return gl(R,Qe);if(vt==Bt||vt==Zt||Ft&&!Qt){if(Ue=S||Ft?{}:Oo(R),!Qe)return S?_c(R,Ru(Ue,R)):I0(R,ca(Ue,R))}else {if(!Jr[vt])return Qt?R:{};Ue=D0(R,vt,Qe);}}ye||(ye=new gc);var re=ye.get(R);if(re)return re;ye.set(R,Ue),cg(R)?R.forEach(function(Ye){Ue.add(io(Ye,j,at,Ye,R,ye));}):ug(R)&&R.forEach(function(Ye,or){Ue.set(or,io(Ye,j,at,or,R,ye));});var Re=M?S?Bs:Ps:S?Kh:Xl,je=rt?t:Re(R);return la(je||R,function(Ye,or){je&&(or=Ye,Ye=R[or]),Ba(Ue,or,io(Ye,j,at,or,R,ye));}),Ue}function sa(R){var j=Xl(R);return function(at){return wu(at,R,j)}}function wu(R,j,at){var Nt=at.length;if(R==null)return !Nt;for(R=Ws(R);Nt--;){var Qt=at[Nt],ye=j[Qt],Ue=R[Qt];if(Ue===t&&!(Qt in R)||!ye(Ue))return false}return true}function Hu(R,j,at){if(typeof R!="function")throw new Kn(s);return Mh(function(){R.apply(t,at);},j)}function su(R,j,at,Nt){var Qt=-1,ye=Ce,Ue=true,Qe=R.length,S=[],M=j.length;if(!Qe)return S;at&&(j=Le(j,dn(at))),Nt?(ye=$e,Ue=false):j.length>=r&&(ye=Sn,Ue=false,j=new xc(j));t:for(;++Qt<Qe;){var rt=R[Qt],vt=at==null?rt:at(rt);if(rt=Nt||rt!==0?rt:0,Ue&&vt===vt){for(var Ft=M;Ft--;)if(j[Ft]===vt)continue t;S.push(rt);}else ye(j,vt,Nt)||S.push(rt);}return S}var Eo=Dh(Sa),Iu=Dh(gu,true);function oa(R,j){var at=true;return Eo(R,function(Nt,Qt,ye){return at=!!j(Nt,Qt,ye),at}),at}function Bo(R,j,at){for(var Nt=-1,Qt=R.length;++Nt<Qt;){var ye=R[Nt],Ue=j(ye);if(Ue!=null&&(Qe===t?Ue===Ue&&!lf(Ue):at(Ue,Qe)))var Qe=Ue,S=ye;}return S}function ul(R,j,at,Nt){var Qt=R.length;for(at=Us(at),at<0&&(at=-at>Qt?0:Qt+at),Nt=Nt===t||Nt>Qt?Qt:Us(Nt),Nt<0&&(Nt+=Qt),Nt=at>Nt?0:K0(Nt);at<Nt;)R[at++]=j;return R}function ll(R,j){var at=[];return Eo(R,function(Nt,Qt,ye){j(Nt,Qt,ye)&&at.push(Nt);}),at}function so(R,j,at,Nt,Qt){var ye=-1,Ue=R.length;for(at||(at=au),Qt||(Qt=[]);++ye<Ue;){var Qe=R[ye];j>0&&at(Qe)?j>1?so(Qe,j-1,at,Nt,Qt):tn(Qt,Qe):Nt||(Qt[Qt.length]=Qe);}return Qt}var ja=Mf(),Oa=Mf(true);function Sa(R,j){return R&&ja(R,j,Xl)}function gu(R,j){return R&&Oa(R,j,Xl)}function wo(R,j){return Ne(j,function(at){return wc(R[at])})}function Qa(R,j){j=ql(j,R);for(var at=0,Nt=j.length;R!=null&&at<Nt;)R=R[ic(j[at++])];return at&&at==Nt?R:t}function cl(R,j,at){var Nt=j(R);return zs(R)?Nt:tn(Nt,at(R))}function Ls(R){return R==null?R===t?Kt:Pt:Cr&&Cr in Ws(R)?Yu(R):k0(R)}function mu(R,j){return R>j}function ma(R,j){return R!=null&&Rs.call(R,j)}function fa(R,j){return R!=null&&j in Ws(R)}function yu(R,j,at){return R>=vr(j,at)&&R<_r(j,at)}function Na(R,j,at){for(var Nt=at?$e:Ce,Qt=R[0].length,ye=R.length,Ue=ye,Qe=wn(ye),S=1/0,M=[];Ue--;){var rt=R[Ue];Ue&&j&&(rt=Le(rt,dn(j))),S=vr(rt.length,S),Qe[Ue]=!at&&(j||Qt>=120&&rt.length>=120)?new xc(Ue&&rt):t;}rt=R[0];var vt=-1,Ft=Qe[0];t:for(;++vt<Qt&&M.length<S;){var re=rt[vt],Re=j?j(re):re;if(re=at||re!==0?re:0,!(Ft?Sn(Ft,Re):Nt(M,Re,at))){for(Ue=ye;--Ue;){var je=Qe[Ue];if(!(je?Sn(je,Re):Nt(R[Ue],Re,at)))continue t}Ft&&Ft.push(Re),M.push(re);}}return M}function Ra(R,j,at,Nt){return Sa(R,function(Qt,ye,Ue){j(Nt,at(Qt),ye,Ue);}),Nt}function Ho(R,j,at){j=ql(j,R),R=Oc(R,j);var Nt=R==null?R:R[ic(Dl(j))];return Nt==null?t:qi(Nt,R,at)}function Ei(R){return dl(R)&&Ls(R)==Zt}function nc(R){return dl(R)&&Ls(R)==zt}function cd(R){return dl(R)&&Ls(R)==ee}function cs(R,j,at,Nt,Qt){return R===j?true:R==null||j==null||!dl(R)&&!dl(j)?R!==R&&j!==j:Gu(R,j,at,Nt,cs,Qt)}function Gu(R,j,at,Nt,Qt,ye){var Ue=zs(R),Qe=zs(j),S=Ue?oe:_o(R),M=Qe?oe:_o(j);S=S==Zt?Bt:S,M=M==Zt?Bt:M;var rt=S==Bt,vt=M==Bt,Ft=S==M;if(Ft&&U0(R)){if(!U0(j))return false;Ue=true,rt=false;}if(Ft&&!rt)return ye||(ye=new gc),Ue||Wd(R)?wl(R,j,at,Nt,Qt,ye):u0(R,j,S,at,Nt,Qt,ye);if(!(at&g)){var re=rt&&Rs.call(R,"__wrapped__"),Re=vt&&Rs.call(j,"__wrapped__");if(re||Re){var je=re?R.value():R,Ye=Re?j.value():j;return ye||(ye=new gc),Qt(je,Ye,at,Nt,ye)}}return Ft?(ye||(ye=new gc),zc(R,j,at,Nt,Qt,ye)):false}function O0(R){return dl(R)&&_o(R)==bt}function ii(R,j,at,Nt){var Qt=at.length,ye=Qt,Ue=!Nt;if(R==null)return !ye;for(R=Ws(R);Qt--;){var Qe=at[Qt];if(Ue&&Qe[2]?Qe[1]!==R[Qe[0]]:!(Qe[0]in R))return false}for(;++Qt<ye;){Qe=at[Qt];var S=Qe[0],M=R[S],rt=Qe[1];if(Ue&&Qe[2]){if(M===t&&!(S in R))return false}else {var vt=new gc;if(Nt)var Ft=Nt(M,rt,S,R,j,vt);if(!(Ft===t?cs(rt,M,g|u,Nt,vt):Ft))return false}}return true}function Yh(R){if(!Zu(R)||Du(R))return false;var j=wc(R)?Xa:tu;return j.test(ch(R))}function S0(R){return dl(R)&&Ls(R)==Ht}function f1(R){return dl(R)&&_o(R)==Ae}function po(R){return dl(R)&&q1(R.length)&&!!ts[Ls(R)]}function Zo(R){return typeof R=="function"?R:R==null?ea:typeof R=="object"?zs(R)?fd(R[0],R[1]):hd(R):n3(R)}function mc(R){if(!M0(R))return hi(R);var j=[];for(var at in Ws(R))Rs.call(R,at)&&at!="constructor"&&j.push(at);return j}function yc(R){if(!Zu(R))return jf(R);var j=M0(R),at=[];for(var Nt in R)Nt=="constructor"&&(j||!Rs.call(R,Nt))||at.push(Nt);return at}function Wh(R,j){return R<j}function Xh(R,j){var at=-1,Nt=Rc(R)?wn(R.length):[];return Eo(R,function(Qt,ye,Ue){Nt[++at]=j(Qt,ye,Ue);}),Nt}function hd(R){var j=Ga(R);return j.length==1&&j[0][2]?to(j[0][0],j[0][1]):function(at){return at===R||ii(at,R,j)}}function fd(R,j){return P0(R)&&fl(j)?to(ic(R),j):function(at){var Nt=X1(at,R);return Nt===t&&Nt===j?qx(at,R):cs(j,Nt,g|u)}}function If(R,j,at,Nt,Qt){R!==j&&ja(j,function(ye,Ue){if(Qt||(Qt=new gc),Zu(ye))$d(R,j,Ue,at,If,Nt,Qt);else {var Qe=Nt?Nt(uh(R,Ue),ye,Ue+"",R,j,Qt):t;Qe===t&&(Qe=ye),Su(R,Ue,Qe);}},Kh);}function $d(R,j,at,Nt,Qt,ye,Ue){var Qe=uh(R,at),S=uh(j,at),M=Ue.get(S);if(M){Su(R,at,M);return}var rt=ye?ye(Qe,S,at+"",R,j,Ue):t,vt=rt===t;if(vt){var Ft=zs(S),re=!Ft&&U0(S),Re=!Ft&&!re&&Wd(S);rt=S,Ft||re||Re?zs(Qe)?rt=Qe:Qu(Qe)?rt=zl(Qe):re?(vt=false,rt=gl(S,true)):Re?(vt=false,rt=Rl(S,true)):rt=[]:z1(S)||O1(S)?(rt=Qe,O1(Qe)?rt=Bx(Qe):(!Zu(Qe)||wc(Qe))&&(rt=Oo(S))):vt=false;}vt&&(Ue.set(S,rt),Qt(rt,S,Nt,ye,Ue),Ue.delete(S)),Su(R,at,rt);}function Sh(R,j){var at=R.length;if(at)return j+=j<0?at:0,ah(j,at)?R[j]:t}function rc(R,j,at){j.length?j=Le(j,function(ye){return zs(ye)?function(Ue){return Qa(Ue,ye.length===1?ye[0]:ye)}:ye}):j=[ea];var Nt=-1;j=Le(j,dn(zi()));var Qt=Xh(R,function(ye,Ue,Qe){var S=Le(j,function(M){return M(ye)});return {criteria:S,index:++Nt,value:ye}});return Xn(Qt,function(ye,Ue){return rs(ye,Ue,at)})}function Qh(R,j){return Lf(R,j,function(at,Nt){return qx(R,Nt)})}function Lf(R,j,at){for(var Nt=-1,Qt=j.length,ye={};++Nt<Qt;){var Ue=j[Nt],Qe=Qa(R,Ue);at(Qe,Ue)&&Co(ye,ql(Ue,R),Qe);}return ye}function vc(R){return function(j){return Qa(j,R)}}function Df(R,j,at,Nt){var Qt=Nt?Hn:vn,ye=-1,Ue=j.length,Qe=R;for(R===j&&(j=zl(j)),at&&(Qe=Le(R,dn(at)));++ye<Ue;)for(var S=0,M=j[ye],rt=at?at(M):M;(S=Qt(Qe,rt,S,Nt))>-1;)Qe!==R&&si.call(Qe,S,1),si.call(R,S,1);return R}function Nh(R,j){for(var at=R?j.length:0,Nt=at-1;at--;){var Qt=j[at];if(at==Nt||Qt!==ye){var ye=Qt;ah(Qt)?si.call(R,Qt,1):Nl(R,Qt);}}return R}function r0(R,j){return R+ci(ri()*(j-R+1))}function N0(R,j,at,Nt){for(var Qt=-1,ye=_r(ui((j-R)/(at||1)),0),Ue=wn(ye);ye--;)Ue[Nt?ye:++Qt]=R,R+=at;return Ue}function Ua(R,j){var at="";if(!R||j<1||j>pt)return at;do j%2&&(at+=R),j=ci(j/2),j&&(R+=R);while(j);return at}function Yi(R,j){return lh(rf(R,j,ea),R+"")}function qu(R){return al(cu(R))}function wa(R,j){var at=cu(R);return Uf(at,ha(j,0,at.length))}function Co(R,j,at,Nt){if(!Zu(R))return R;j=ql(j,R);for(var Qt=-1,ye=j.length,Ue=ye-1,Qe=R;Qe!=null&&++Qt<ye;){var S=ic(j[Qt]),M=at;if(S==="__proto__"||S==="constructor"||S==="prototype")return R;if(Qt!=Ue){var rt=Qe[S];M=Nt?Nt(rt,S,Qe):t,M===t&&(M=Zu(rt)?rt:ah(j[Qt+1])?[]:{});}Ba(Qe,S,M),Qe=Qe[S];}return R}var Ec=di?function(R,j){return di.set(R,j),R}:ea,dd=jc?function(R,j){return jc(R,"toString",{configurable:true,enumerable:false,value:J1(j),writable:true})}:ea;function Go(R){return Uf(cu(R))}function Sl(R,j,at){var Nt=-1,Qt=R.length;j<0&&(j=-j>Qt?0:Qt+j),at=at>Qt?Qt:at,at<0&&(at+=Qt),Qt=j>at?0:at-j>>>0,j>>>=0;for(var ye=wn(Qt);++Nt<Qt;)ye[Nt]=R[Nt+j];return ye}function Ds(R,j){var at;return Eo(R,function(Nt,Qt,ye){return at=j(Nt,Qt,ye),!at}),!!at}function Rh(R,j,at){var Nt=0,Qt=R==null?Nt:R.length;if(typeof j=="number"&&j===j&&Qt<=gt){for(;Nt<Qt;){var ye=Nt+Qt>>>1,Ue=R[ye];Ue!==null&&!lf(Ue)&&(at?Ue<=j:Ue<j)?Nt=ye+1:Qt=ye;}return Qt}return R0(R,j,ea,at)}function R0(R,j,at,Nt){var Qt=0,ye=R==null?0:R.length;if(ye===0)return 0;j=at(j);for(var Ue=j!==j,Qe=j===null,S=lf(j),M=j===t;Qt<ye;){var rt=ci((Qt+ye)/2),vt=at(R[rt]),Ft=vt!==t,re=vt===null,Re=vt===vt,je=lf(vt);if(Ue)var Ye=Nt||Re;else M?Ye=Re&&(Nt||Ft):Qe?Ye=Re&&Ft&&(Nt||!re):S?Ye=Re&&Ft&&!re&&(Nt||!je):re||je?Ye=false:Ye=Nt?vt<=j:vt<j;Ye?Qt=rt+1:ye=rt;}return vr(ye,Tt)}function Pf(R,j){for(var at=-1,Nt=R.length,Qt=0,ye=[];++at<Nt;){var Ue=R[at],Qe=j?j(Ue):Ue;if(!at||!dh(Qe,S)){var S=Qe;ye[Qt++]=Ue===0?0:Ue;}}return ye}function Hd(R){return typeof R=="number"?R:lf(R)?dt:+R}function Ia(R){if(typeof R=="string")return R;if(zs(R))return Le(R,Ia)+"";if(lf(R))return dc?dc.call(R):"";var j=R+"";return j=="0"&&1/R==-tt?"-0":j}function wh(R,j,at){var Nt=-1,Qt=Ce,ye=R.length,Ue=true,Qe=[],S=Qe;if(at)Ue=false,Qt=$e;else if(ye>=r){var M=j?null:yd(R);if(M)return kc(M);Ue=false,Qt=Sn,S=new xc;}else S=j?[]:Qe;t:for(;++Nt<ye;){var rt=R[Nt],vt=j?j(rt):rt;if(rt=at||rt!==0?rt:0,Ue&&vt===vt){for(var Ft=S.length;Ft--;)if(S[Ft]===vt)continue t;j&&S.push(vt),Qe.push(rt);}else Qt(S,vt,at)||(S!==Qe&&S.push(vt),Qe.push(rt));}return Qe}function Nl(R,j){j=ql(j,R);var at=-1,Nt=j.length;if(!Nt)return true;for(var Qt=R==null||typeof R!="object"&&typeof R!="function";++at<Nt;){var ye=j[at];if(typeof ye=="string"){if(ye==="__proto__"&&!Rs.call(R,"__proto__"))return false;if(ye==="constructor"&&at+1<Nt&&typeof j[at+1]=="string"&&j[at+1]==="prototype"){if(Qt&&at===0)continue;return false}}}var Ue=Oc(R,j);return Ue==null||delete Ue[ic(Dl(j))]}function Kc(R,j,at,Nt){return Co(R,j,at(Qa(R,j)),Nt)}function Ih(R,j,at,Nt){for(var Qt=R.length,ye=Nt?Qt:-1;(Nt?ye--:++ye<Qt)&&j(R[ye],ye,R););return at?Sl(R,Nt?0:ye,Nt?ye+1:Qt):Sl(R,Nt?ye+1:0,Nt?Qt:ye)}function pd(R,j){var at=R;return at instanceof qs&&(at=at.value()),pn(j,function(Nt,Qt){return Qt.func.apply(Qt.thisArg,tn([Nt],Qt.args))},at)}function $c(R,j,at){var Nt=R.length;if(Nt<2)return Nt?wh(R[0]):[];for(var Qt=-1,ye=wn(Nt);++Qt<Nt;)for(var Ue=R[Qt],Qe=-1;++Qe<Nt;)Qe!=Qt&&(ye[Qt]=su(ye[Qt]||Ue,R[Qe],j,at));return wh(so(ye,1),j,at)}function Jh(R,j,at){for(var Nt=-1,Qt=R.length,ye=j.length,Ue={};++Nt<Qt;){var Qe=Nt<ye?j[Nt]:t;at(Ue,R[Nt],Qe);}return Ue}function Ka(R){return Qu(R)?R:[]}function zu(R){return typeof R=="function"?R:ea}function ql(R,j){return zs(R)?R:P0(R,j)?[R]:qd(ya(R))}var d1=Yi;function Hc(R,j,at){var Nt=R.length;return at=at===t?Nt:at,!j&&at>=Nt?R:Sl(R,j,at)}var Gd=Or||function(R){return $r.clearTimeout(R)};function gl(R,j){if(j)return R.slice();var at=R.length,Nt=e0?e0(at):new R.constructor(at);return R.copy(Nt),Nt}function xd(R){var j=new R.constructor(R.byteLength);return new ol(j).set(new ol(R)),j}function w0(R,j){var at=j?xd(R.buffer):R.buffer;return new R.constructor(at,R.byteOffset,R.byteLength)}function i0(R){var j=new R.constructor(R.source,rl.exec(R));return j.lastIndex=R.lastIndex,j}function ou(R){return Ci?Ws(Ci.call(R)):{}}function Rl(R,j){var at=j?xd(R.buffer):R.buffer;return new R.constructor(at,R.byteOffset,R.length)}function $a(R,j){if(R!==j){var at=R!==t,Nt=R===null,Qt=R===R,ye=lf(R),Ue=j!==t,Qe=j===null,S=j===j,M=lf(j);if(!Qe&&!M&&!ye&&R>j||ye&&Ue&&S&&!Qe&&!M||Nt&&Ue&&S||!at&&S||!Qt)return 1;if(!Nt&&!ye&&!M&&R<j||M&&at&&Qt&&!Nt&&!ye||Qe&&at&&Qt||!Ue&&Qt||!S)return -1}return 0}function rs(R,j,at){for(var Nt=-1,Qt=R.criteria,ye=j.criteria,Ue=Qt.length,Qe=at.length;++Nt<Ue;){var S=$a(Qt[Nt],ye[Nt]);if(S){if(Nt>=Qe)return S;var M=at[Nt];return S*(M=="desc"?-1:1)}}return R.index-j.index}function Zh(R,j,at,Nt){for(var Qt=-1,ye=R.length,Ue=at.length,Qe=-1,S=j.length,M=_r(ye-Ue,0),rt=wn(S+M),vt=!Nt;++Qe<S;)rt[Qe]=j[Qe];for(;++Qt<Ue;)(vt||Qt<ye)&&(rt[at[Qt]]=R[Qt]);for(;M--;)rt[Qe++]=R[Qt++];return rt}function Lh(R,j,at,Nt){for(var Qt=-1,ye=R.length,Ue=-1,Qe=at.length,S=-1,M=j.length,rt=_r(ye-Qe,0),vt=wn(rt+M),Ft=!Nt;++Qt<rt;)vt[Qt]=R[Qt];for(var re=Qt;++S<M;)vt[re+S]=j[S];for(;++Ue<Qe;)(Ft||Qt<ye)&&(vt[re+at[Ue]]=R[Qt++]);return vt}function zl(R,j){var at=-1,Nt=R.length;for(j||(j=wn(Nt));++at<Nt;)j[at]=R[at];return j}function ih(R,j,at,Nt){var Qt=!at;at||(at={});for(var ye=-1,Ue=j.length;++ye<Ue;){var Qe=j[ye],S=Nt?Nt(at[Qe],R[Qe],Qe,at,R):t;S===t&&(S=R[Qe]),Qt?Fo(at,Qe,S):Ba(at,Qe,S);}return at}function I0(R,j){return ih(R,ef(R),j)}function _c(R,j){return ih(R,Yc(R),j)}function bc(R,j){return function(at,Nt){var Qt=zs(at)?ua:Jo,ye=j?j():{};return Qt(at,R,zi(Nt,2),ye)}}function Tc(R){return Yi(function(j,at){var Nt=-1,Qt=at.length,ye=Qt>1?at[Qt-1]:t,Ue=Qt>2?at[2]:t;for(ye=R.length>3&&typeof ye=="function"?(Qt--,ye):t,Ue&&Lu(at[0],at[1],Ue)&&(ye=Qt<3?t:ye,Qt=1),j=Ws(j);++Nt<Qt;){var Qe=at[Nt];Qe&&R(j,Qe,Nt,ye);}return j})}function Dh(R,j){return function(at,Nt){if(at==null)return at;if(!Rc(at))return R(at,Nt);for(var Qt=at.length,ye=j?Qt:-1,Ue=Ws(at);(j?ye--:++ye<Qt)&&Nt(Ue[ye],ye,Ue)!==false;);return at}}function Mf(R){return function(j,at,Nt){for(var Qt=-1,ye=Ws(j),Ue=Nt(j),Qe=Ue.length;Qe--;){var S=Ue[R?Qe:++Qt];if(at(ye[S],S,ye)===false)break}return j}}function ml(R,j,at){var Nt=j&c,Qt=s0(R);function ye(){var Ue=this&&this!==$r&&this instanceof ye?Qt:R;return Ue.apply(Nt?at:this,arguments)}return ye}function Vl(R){return function(j){j=ya(j);var at=sn(j)?ro(j):t,Nt=at?at[0]:j.charAt(0),Qt=at?Hc(at,1).join(""):j.slice(1);return Nt[R]()+Qt}}function kf(R){return function(j){return pn(R1(H0(j).replace(_i,"")),R,"")}}function s0(R){return function(){var j=arguments;switch(j.length){case 0:return new R;case 1:return new R(j[0]);case 2:return new R(j[0],j[1]);case 3:return new R(j[0],j[1],j[2]);case 4:return new R(j[0],j[1],j[2],j[3]);case 5:return new R(j[0],j[1],j[2],j[3],j[4]);case 6:return new R(j[0],j[1],j[2],j[3],j[4],j[5]);case 7:return new R(j[0],j[1],j[2],j[3],j[4],j[5],j[6])}var at=ec(R.prototype),Nt=R.apply(at,j);return Zu(Nt)?Nt:at}}function gd(R,j,at){var Nt=s0(R);function Qt(){for(var ye=arguments.length,Ue=wn(ye),Qe=ye,S=Ha(Qt);Qe--;)Ue[Qe]=arguments[Qe];var M=ye<3&&Ue[0]!==S&&Ue[ye-1]!==S?[]:We(Ue,S);if(ye-=M.length,ye<at)return Cc(R,j,sh,Qt.placeholder,t,Ue,M,t,t,at-ye);var rt=this&&this!==$r&&this instanceof Qt?Nt:R;return qi(rt,this,Ue)}return Qt}function Ac(R){return function(j,at,Nt){var Qt=Ws(j);if(!Rc(j)){var ye=zi(at,3);j=Xl(j),at=function(Qe){return ye(Qt[Qe],Qe,Qt)};}var Ue=R(j,at,Nt);return Ue>-1?Qt[ye?j[Ue]:Ue]:t}}function o0(R){return uo(function(j){var at=j.length,Nt=at,Qt=Cl.prototype.thru;for(R&&j.reverse();Nt--;){var ye=j[Nt];if(typeof ye!="function")throw new Kn(s);if(Qt&&!Ue&&oh(ye)=="wrapper")var Ue=new Cl([],true);}for(Nt=Ue?Nt:at;++Nt<at;){ye=j[Nt];var Qe=oh(ye),S=Qe=="wrapper"?l0(ye):t;S&&Ph(S[0])&&S[1]==(E|d|b|T)&&!S[4].length&&S[9]==1?Ue=Ue[oh(S[0])].apply(Ue,S[3]):Ue=ye.length==1&&Ph(ye)?Ue[Qe]():Ue.thru(ye);}return function(){var M=arguments,rt=M[0];if(Ue&&M.length==1&&zs(rt))return Ue.plant(rt).value();for(var vt=0,Ft=at?j[vt].apply(this,M):rt;++vt<at;)Ft=j[vt].call(this,Ft);return Ft}})}function sh(R,j,at,Nt,Qt,ye,Ue,Qe,S,M){var rt=j&E,vt=j&c,Ft=j&l,re=j&(d|m),Re=j&G,je=Ft?t:s0(R);function Ye(){for(var or=arguments.length,ar=wn(or),Lr=or;Lr--;)ar[Lr]=arguments[Lr];if(re)var li=Ha(Ye),Ui=cn(ar,li);if(Nt&&(ar=Zh(ar,Nt,Qt,re)),ye&&(ar=Lh(ar,ye,Ue,re)),or-=Ui,re&&or<M){var Ki=We(ar,li);return Cc(R,j,sh,Ye.placeholder,at,ar,Ki,Qe,S,M-or)}var Os=vt?at:this,es=Ft?Os[R]:R;return or=ar.length,Qe?ar=sf(ar,Qe):Re&&or>1&&ar.reverse(),rt&&S<or&&(ar.length=S),this&&this!==$r&&this instanceof Ye&&(es=je||s0(es)),es.apply(Os,ar)}return Ye}function p1(R,j){return function(at,Nt){return Ra(at,R,j(Nt),{})}}function tf(R,j){return function(at,Nt){var Qt;if(at===t&&Nt===t)return j;if(at!==t&&(Qt=at),Nt!==t){if(Qt===t)return Nt;typeof at=="string"||typeof Nt=="string"?(at=Ia(at),Nt=Ia(Nt)):(at=Hd(at),Nt=Hd(Nt)),Qt=R(at,Nt);}return Qt}}function Gc(R){return uo(function(j){return j=Le(j,dn(zi())),Yi(function(at){var Nt=this;return R(j,function(Qt){return qi(Qt,Nt,at)})})})}function yl(R,j){j=j===t?" ":Ia(j);var at=j.length;if(at<2)return at?Ua(j,R):j;var Nt=Ua(j,ui(R/vo(j)));return sn(j)?Hc(ro(Nt),0,R).join(""):Nt.slice(0,R)}function qc(R,j,at,Nt){var Qt=j&c,ye=s0(R);function Ue(){for(var Qe=-1,S=arguments.length,M=-1,rt=Nt.length,vt=wn(rt+S),Ft=this&&this!==$r&&this instanceof Ue?ye:R;++M<rt;)vt[M]=Nt[M];for(;S--;)vt[M++]=arguments[++Qe];return qi(Ft,Qt?at:this,vt)}return Ue}function md(R){return function(j,at,Nt){return Nt&&typeof Nt!="number"&&Lu(j,at,Nt)&&(at=Nt=t),j=Pu(j),at===t?(at=j,j=0):at=Pu(at),Nt=Nt===t?j<at?1:-1:Pu(Nt),N0(j,at,Nt,R)}}function L0(R){return function(j,at){return typeof j=="string"&&typeof at=="string"||(j=cf(j),at=cf(at)),R(j,at)}}function Cc(R,j,at,Nt,Qt,ye,Ue,Qe,S,M){var rt=j&d,vt=rt?Ue:t,Ft=rt?t:Ue,re=rt?ye:t,Re=rt?t:ye;j|=rt?b:C,j&=~(rt?C:b),j&f||(j&=-4);var je=[R,j,Qt,re,vt,Re,Ft,Qe,S,M],Ye=at.apply(t,je);return Ph(R)&&Sc(Ye,je),Ye.placeholder=Nt,Wc(Ye,R,j)}function bs(R){var j=Au[R];return function(at,Nt){if(at=cf(at),Nt=Nt==null?0:vr(Us(Nt),292),Nt&&bi(at)){var Qt=(ya(at)+"e").split("e"),ye=j(Qt[0]+"e"+(+Qt[1]+Nt));return Qt=(ya(ye)+"e").split("e"),+(Qt[0]+"e"+(+Qt[1]-Nt))}return j(at)}}var yd=Nr&&1/kc(new Nr([,-0]))[1]==tt?function(R){return new Nr(R)}:Mu;function Vu(R){return function(j){var at=_o(j);return at==bt?Vn(j):at==Ae?rh(j):Ln(j,R(j))}}function Zs(R,j,at,Nt,Qt,ye,Ue,Qe){var S=j&l;if(!S&&typeof R!="function")throw new Kn(s);var M=Nt?Nt.length:0;if(M||(j&=-97,Nt=Qt=t),Ue=Ue===t?Ue:_r(Us(Ue),0),Qe=Qe===t?Qe:Us(Qe),M-=Qt?Qt.length:0,j&C){var rt=Nt,vt=Qt;Nt=Qt=t;}var Ft=S?t:l0(R),re=[R,j,at,Nt,Qt,rt,vt,ye,Ue,Qe];if(Ft&&vd(re,Ft),R=re[0],j=re[1],at=re[2],Nt=re[3],Qt=re[4],Qe=re[9]=re[9]===t?S?0:R.length:_r(re[9]-M,0),!Qe&&j&(d|m)&&(j&=-25),!j||j==c)var Re=ml(R,j,at);else j==d||j==m?Re=gd(R,j,Qe):(j==b||j==(c|b))&&!Qt.length?Re=qc(R,j,at,Nt):Re=sh.apply(t,re);var je=Ft?Ec:Sc;return Wc(je(Re,re),R,j)}function Xi(R,j,at,Nt){return R===t||dh(R,At[at])&&!Rs.call(Nt,at)?j:R}function vl(R,j,at,Nt,Qt,ye){return Zu(R)&&Zu(j)&&(ye.set(j,R),If(R,j,t,vl,ye),ye.delete(j)),R}function a0(R){return z1(R)?t:R}function wl(R,j,at,Nt,Qt,ye){var Ue=at&g,Qe=R.length,S=j.length;if(Qe!=S&&!(Ue&&S>Qe))return false;var M=ye.get(R),rt=ye.get(j);if(M&&rt)return M==j&&rt==R;var vt=-1,Ft=true,re=at&u?new xc:t;for(ye.set(R,j),ye.set(j,R);++vt<Qe;){var Re=R[vt],je=j[vt];if(Nt)var Ye=Ue?Nt(je,Re,vt,j,R,ye):Nt(Re,je,vt,R,j,ye);if(Ye!==t){if(Ye)continue;Ft=false;break}if(re){if(!bn(j,function(or,ar){if(!Sn(re,ar)&&(Re===or||Qt(Re,or,at,Nt,ye)))return re.push(ar)})){Ft=false;break}}else if(!(Re===je||Qt(Re,je,at,Nt,ye))){Ft=false;break}}return ye.delete(R),ye.delete(j),Ft}function u0(R,j,at,Nt,Qt,ye,Ue){switch(at){case De:if(R.byteLength!=j.byteLength||R.byteOffset!=j.byteOffset)return false;R=R.buffer,j=j.buffer;case zt:return !(R.byteLength!=j.byteLength||!ye(new ol(R),new ol(j)));case Oe:case ee:case Dt:return dh(+R,+j);case Et:return R.name==j.name&&R.message==j.message;case Ht:case kt:return R==j+"";case bt:var Qe=Vn;case Ae:var S=Nt&g;if(Qe||(Qe=kc),R.size!=j.size&&!S)return false;var M=Ue.get(R);if(M)return M==j;Nt|=u,Ue.set(R,j);var rt=wl(Qe(R),Qe(j),Nt,Qt,ye,Ue);return Ue.delete(R),rt;case jt:if(Ci)return Ci.call(R)==Ci.call(j)}return false}function zc(R,j,at,Nt,Qt,ye){var Ue=at&g,Qe=Ps(R),S=Qe.length,M=Ps(j),rt=M.length;if(S!=rt&&!Ue)return false;for(var vt=S;vt--;){var Ft=Qe[vt];if(!(Ue?Ft in j:Rs.call(j,Ft)))return false}var re=ye.get(R),Re=ye.get(j);if(re&&Re)return re==j&&Re==R;var je=true;ye.set(R,j),ye.set(j,R);for(var Ye=Ue;++vt<S;){Ft=Qe[vt];var or=R[Ft],ar=j[Ft];if(Nt)var Lr=Ue?Nt(ar,or,Ft,j,R,ye):Nt(or,ar,Ft,R,j,ye);if(!(Lr===t?or===ar||Qt(or,ar,at,Nt,ye):Lr)){je=false;break}Ye||(Ye=Ft=="constructor");}if(je&&!Ye){var li=R.constructor,Ui=j.constructor;li!=Ui&&"constructor"in R&&"constructor"in j&&!(typeof li=="function"&&li instanceof li&&typeof Ui=="function"&&Ui instanceof Ui)&&(je=false);}return ye.delete(R),ye.delete(j),je}function uo(R){return lh(rf(R,t,h0),R+"")}function Ps(R){return cl(R,Xl,ef)}function Bs(R){return cl(R,Kh,Yc)}var l0=di?function(R){return di.get(R)}:Mu;function oh(R){for(var j=R.name+"",at=yi[j],Nt=Rs.call(yi,j)?at.length:0;Nt--;){var Qt=at[Nt],ye=Qt.func;if(ye==null||ye==R)return Qt.name}return j}function Ha(R){var j=Rs.call(he,"placeholder")?he:R;return j.placeholder}function zi(){var R=he.iteratee||Lp;return R=R===Lp?Zo:R,arguments.length?R(arguments[0],arguments[1]):R}function Vc(R,j){var at=R.__data__;return hl(j)?at[typeof j=="string"?"string":"hash"]:at.map}function Ga(R){for(var j=Xl(R),at=j.length;at--;){var Nt=j[at],Qt=R[Nt];j[at]=[Nt,Qt,fl(Qt)];}return j}function La(R,j){var at=Bn(R,j);return Yh(at)?at:t}function Yu(R){var j=Rs.call(R,Cr),at=R[Cr];try{R[Cr]=t;var Nt=!0;}catch{}var Qt=ju.call(R);return Nt&&(j?R[Cr]=at:delete R[Cr]),Qt}var ef=Hr?function(R){return R==null?[]:(R=Ws(R),Ne(Hr(R),function(j){return Oi.call(R,j)}))}:M2,Yc=Hr?function(R){for(var j=[];R;)tn(j,ef(R)),R=fc(R);return j}:M2,_o=Ls;(Pr&&_o(new Pr(new ArrayBuffer(1)))!=De||Er&&_o(new Er)!=bt||Tr&&_o(Tr.resolve())!=ne||Nr&&_o(new Nr)!=Ae||Ti&&_o(new Ti)!=$t)&&(_o=function(R){var j=Ls(R),at=j==Bt?R.constructor:t,Nt=at?ch(at):"";if(Nt)switch(Nt){case vi:return De;case gi:return bt;case Ai:return ne;case Ri:return Ae;case Si:return $t}return j});function Qr(R,j,at){for(var Nt=-1,Qt=at.length;++Nt<Qt;){var ye=at[Nt],Ue=ye.size;switch(ye.type){case "drop":R+=Ue;break;case "dropRight":j-=Ue;break;case "take":j=vr(j,R+Ue);break;case "takeRight":R=_r(R,j-Ue);break}}return {start:R,end:j}}function Ff(R){var j=R.match(Po);return j?j[1].split(bu):[]}function El(R,j,at){j=ql(j,R);for(var Nt=-1,Qt=j.length,ye=false;++Nt<Qt;){var Ue=ic(j[Nt]);if(!(ye=R!=null&&at(R,Ue)))break;R=R[Ue];}return ye||++Nt!=Qt?ye:(Qt=R==null?0:R.length,!!Qt&&q1(Qt)&&ah(Ue,Qt)&&(zs(R)||O1(R)))}function nf(R){var j=R.length,at=new R.constructor(j);return j&&typeof R[0]=="string"&&Rs.call(R,"index")&&(at.index=R.index,at.input=R.input),at}function Oo(R){return typeof R.constructor=="function"&&!M0(R)?ec(fc(R)):{}}function D0(R,j,at){var Nt=R.constructor;switch(j){case zt:return xd(R);case Oe:case ee:return new Nt(+R);case De:return w0(R,at);case ie:case yn:case wr:case ni:case Fr:case He:case Ge:case Qn:case Gr:return Rl(R,at);case bt:return new Nt;case Dt:case kt:return new Nt(R);case Ht:return i0(R);case Ae:return new Nt;case jt:return ou(R)}}function Bf(R,j){var at=j.length;if(!at)return R;var Nt=at-1;return j[Nt]=(at>1?"& ":"")+j[Nt],j=j.join(at>2?", ":" "),R.replace(ba,`{
1614
1614
  /* [wrapped with `+j+`] */
1615
1615
  `)}function au(R){return zs(R)||O1(R)||!!(hr&&R&&R[hr])}function ah(R,j){var at=typeof R;return j=j??pt,!!j&&(at=="number"||at!="symbol"&&Ro.test(R))&&R>-1&&R%1==0&&R<j}function Lu(R,j,at){if(!Zu(at))return false;var Nt=typeof j;return (Nt=="number"?Rc(at)&&ah(j,at.length):Nt=="string"&&j in at)?dh(at[j],R):false}function P0(R,j){if(zs(R))return false;var at=typeof R;return at=="number"||at=="symbol"||at=="boolean"||R==null||lf(R)?true:wi.test(R)||!$i.test(R)||j!=null&&R in Ws(j)}function hl(R){var j=typeof R;return j=="string"||j=="number"||j=="symbol"||j=="boolean"?R!=="__proto__":R===null}function Ph(R){var j=oh(R),at=he[j];if(typeof at!="function"||!(j in qs.prototype))return false;if(R===at)return true;var Nt=l0(at);return !!Nt&&R===Nt[0]}function Du(R){return !!Xo&&Xo in R}var x1=Ko?wc:k2;function M0(R){var j=R&&R.constructor,at=typeof j=="function"&&j.prototype||At;return R===at}function fl(R){return R===R&&!Zu(R)}function to(R,j){return function(at){return at==null?false:at[R]===j&&(j!==t||R in Ws(at))}}function uu(R){var j=T1(R,function(Nt){return at.size===a&&at.clear(),Nt}),at=j.cache;return j}function vd(R,j){var at=R[1],Nt=j[1],Qt=at|Nt,ye=Qt<(c|l|E),Ue=Nt==E&&at==d||Nt==E&&at==T&&R[7].length<=j[8]||Nt==(E|T)&&j[7].length<=j[8]&&at==d;if(!(ye||Ue))return R;Nt&c&&(R[2]=j[2],Qt|=at&c?0:f);var Qe=j[3];if(Qe){var S=R[3];R[3]=S?Zh(S,Qe,j[4]):Qe,R[4]=S?We(R[3],h):j[4];}return Qe=j[5],Qe&&(S=R[5],R[5]=S?Lh(S,Qe,j[6]):Qe,R[6]=S?We(R[5],h):j[6]),Qe=j[7],Qe&&(R[7]=Qe),Nt&E&&(R[8]=R[8]==null?j[8]:vr(R[8],j[8])),R[9]==null&&(R[9]=j[9]),R[0]=j[0],R[1]=Qt,R}function jf(R){var j=[];if(R!=null)for(var at in Ws(R))j.push(at);return j}function k0(R){return ju.call(R)}function rf(R,j,at){return j=_r(j===t?R.length-1:j,0),function(){for(var Nt=arguments,Qt=-1,ye=_r(Nt.length-j,0),Ue=wn(ye);++Qt<ye;)Ue[Qt]=Nt[j+Qt];Qt=-1;for(var Qe=wn(j+1);++Qt<j;)Qe[Qt]=Nt[Qt];return Qe[j]=at(Ue),qi(R,this,Qe)}}function Oc(R,j){return j.length<2?R:Qa(R,Sl(j,0,-1))}function sf(R,j){for(var at=R.length,Nt=vr(j.length,at),Qt=zl(R);Nt--;){var ye=j[Nt];R[Nt]=ah(ye,at)?Qt[ye]:t;}return R}function uh(R,j){if(!(j==="constructor"&&typeof R[j]=="function")&&j!="__proto__")return R[j]}var Sc=of(Ec),Mh=Br||function(R,j){return $r.setTimeout(R,j)},lh=of(dd);function Wc(R,j,at){var Nt=j+"";return lh(R,Bf(Nt,af(Ff(Nt),at)))}function of(R){var j=0,at=0;return function(){var Nt=Kr(),Qt=nt-(Nt-at);if(at=Nt,Qt>0){if(++j>=K)return arguments[0]}else j=0;return R.apply(t,arguments)}}function Uf(R,j){var at=-1,Nt=R.length,Qt=Nt-1;for(j=j===t?Nt:j;++at<j;){var ye=r0(at,Qt),Ue=R[ye];R[ye]=R[at],R[at]=Ue;}return R.length=j,R}var qd=uu(function(R){var j=[];return R.charCodeAt(0)===46&&j.push(""),R.replace(ps,function(at,Nt,Qt,ye){j.push(Qt?ye.replace(Ta,"$1"):Nt||at);}),j});function ic(R){if(typeof R=="string"||lf(R))return R;var j=R+"";return j=="0"&&1/R==-tt?"-0":j}function ch(R){if(R!=null){try{return $s.call(R)}catch{}try{return R+""}catch{}}return ""}function af(R,j){return la(Ot,function(at){var Nt="_."+at[0];j&at[1]&&!Ce(R,Nt)&&R.push(Nt);}),R.sort()}function Wu(R){if(R instanceof qs)return R.clone();var j=new Cl(R.__wrapped__,R.__chain__);return j.__actions__=zl(R.__actions__),j.__index__=R.__index__,j.__values__=R.__values__,j}function Ed(R,j,at){(at?Lu(R,j,at):j===t)?j=1:j=_r(Us(j),0);var Nt=R==null?0:R.length;if(!Nt||j<1)return [];for(var Qt=0,ye=0,Ue=wn(ui(Nt/j));Qt<Nt;)Ue[ye++]=Sl(R,Qt,Qt+=j);return Ue}function _d(R){for(var j=-1,at=R==null?0:R.length,Nt=0,Qt=[];++j<at;){var ye=R[j];ye&&(Qt[Nt++]=ye);}return Qt}function F0(){var R=arguments.length;if(!R)return [];for(var j=wn(R-1),at=arguments[0],Nt=R;Nt--;)j[Nt-1]=arguments[Nt];return tn(zs(at)?zl(at):[at],so(j,1))}var Kf=Yi(function(R,j){return Qu(R)?su(R,so(j,1,Qu,true)):[]}),Il=Yi(function(R,j){var at=Dl(j);return Qu(at)&&(at=t),Qu(R)?su(R,so(j,1,Qu,true),zi(at,2)):[]}),Nc=Yi(function(R,j){var at=Dl(j);return Qu(at)&&(at=t),Qu(R)?su(R,so(j,1,Qu,true),t,at):[]});function Ll(R,j,at){var Nt=R==null?0:R.length;return Nt?(j=at||j===t?1:Us(j),Sl(R,j<0?0:j,Nt)):[]}function B0(R,j,at){var Nt=R==null?0:R.length;return Nt?(j=at||j===t?1:Us(j),j=Nt-j,Sl(R,0,j<0?0:j)):[]}function g1(R,j){return R&&R.length?Ih(R,zi(j,3),true,true):[]}function m1(R,j){return R&&R.length?Ih(R,zi(j,3),true):[]}function zd(R,j,at,Nt){var Qt=R==null?0:R.length;return Qt?(at&&typeof at!="number"&&Lu(R,j,at)&&(at=0,Nt=Qt),ul(R,j,at,Nt)):[]}function j0(R,j,at){var Nt=R==null?0:R.length;if(!Nt)return -1;var Qt=at==null?0:Us(at);return Qt<0&&(Qt=_r(Nt+Qt,0)),On(R,zi(j,3),Qt)}function c0(R,j,at){var Nt=R==null?0:R.length;if(!Nt)return -1;var Qt=Nt-1;return at!==t&&(Qt=Us(at),Qt=at<0?_r(Nt+Qt,0):vr(Qt,Nt-1)),On(R,zi(j,3),Qt,true)}function h0(R){var j=R==null?0:R.length;return j?so(R,1):[]}function kh(R){var j=R==null?0:R.length;return j?so(R,tt):[]}function hh(R,j){var at=R==null?0:R.length;return at?(j=j===t?1:Us(j),so(R,j)):[]}function f0(R){for(var j=-1,at=R==null?0:R.length,Nt={};++j<at;){var Qt=R[j];Nt[Qt[0]]=Qt[1];}return Nt}function d0(R){return R&&R.length?R[0]:t}function $f(R,j,at){var Nt=R==null?0:R.length;if(!Nt)return -1;var Qt=at==null?0:Us(at);return Qt<0&&(Qt=_r(Nt+Qt,0)),vn(R,j,Qt)}function Hf(R){var j=R==null?0:R.length;return j?Sl(R,0,-1):[]}var bd=Yi(function(R){var j=Le(R,Ka);return j.length&&j[0]===R[0]?Na(j):[]}),Td=Yi(function(R){var j=Dl(R),at=Le(R,Ka);return j===Dl(at)?j=t:at.pop(),at.length&&at[0]===R[0]?Na(at,zi(j,2)):[]}),y1=Yi(function(R){var j=Dl(R),at=Le(R,Ka);return j=typeof j=="function"?j:t,j&&at.pop(),at.length&&at[0]===R[0]?Na(at,t,j):[]});function Vd(R,j){return R==null?"":Bi.call(R,j)}function Dl(R){var j=R==null?0:R.length;return j?R[j-1]:t}function Gf(R,j,at){var Nt=R==null?0:R.length;if(!Nt)return -1;var Qt=Nt;return at!==t&&(Qt=Us(at),Qt=Qt<0?_r(Nt+Qt,0):vr(Qt,Nt-1)),j===j?Zf(R,j,Qt):On(R,qn,Qt,true)}function Fh(R,j){return R&&R.length?Sh(R,Us(j)):t}var p0=Yi(I);function I(R,j){return R&&R.length&&j&&j.length?Df(R,j):R}function Y(R,j,at){return R&&R.length&&j&&j.length?Df(R,j,zi(at,2)):R}function ft(R,j,at){return R&&R.length&&j&&j.length?Df(R,j,t,at):R}var wt=uo(function(R,j){var at=R==null?0:R.length,Nt=$u(R,j);return Nh(R,Le(j,function(Qt){return ah(Qt,at)?+Qt:Qt}).sort($a)),Nt});function Xt(R,j){var at=[];if(!(R&&R.length))return at;var Nt=-1,Qt=[],ye=R.length;for(j=zi(j,3);++Nt<ye;){var Ue=R[Nt];j(Ue,Nt,R)&&(at.push(Ue),Qt.push(Nt));}return Nh(R,Qt),at}function _e(R){return R==null?R:Zr.call(R)}function qe(R,j,at){var Nt=R==null?0:R.length;return Nt?(at&&typeof at!="number"&&Lu(R,j,at)?(j=0,at=Nt):(j=j==null?0:Us(j),at=at===t?Nt:Us(at)),Sl(R,j,at)):[]}function rn(R,j){return Rh(R,j)}function Pn(R,j,at){return R0(R,j,zi(at,2))}function Rr(R,j){var at=R==null?0:R.length;if(at){var Nt=Rh(R,j);if(Nt<at&&dh(R[Nt],j))return Nt}return -1}function Sr(R,j){return Rh(R,j,true)}function Vr(R,j,at){return R0(R,j,zi(at,2),true)}function ji(R,j){var at=R==null?0:R.length;if(at){var Nt=Rh(R,j,true)-1;if(dh(R[Nt],j))return Nt}return -1}function Hi(R){return R&&R.length?Pf(R):[]}function Ji(R,j){return R&&R.length?Pf(R,zi(j,2)):[]}function Ir(R){var j=R==null?0:R.length;return j?Sl(R,1,j):[]}function ai(R,j,at){return R&&R.length?(j=at||j===t?1:Us(j),Sl(R,0,j<0?0:j)):[]}function Qi(R,j,at){var Nt=R==null?0:R.length;return Nt?(j=at||j===t?1:Us(j),j=Nt-j,Sl(R,j<0?0:j,Nt)):[]}function Li(R,j){return R&&R.length?Ih(R,zi(j,3),false,true):[]}function ds(R,j){return R&&R.length?Ih(R,zi(j,3)):[]}var vs=Yi(function(R){return wh(so(R,1,Qu,true))}),Ms=Yi(function(R){var j=Dl(R);return Qu(j)&&(j=t),wh(so(R,1,Qu,true),zi(j,2))}),xr=Yi(function(R){var j=Dl(R);return j=typeof j=="function"?j:t,wh(so(R,1,Qu,true),t,j)});function jr(R){return R&&R.length?wh(R):[]}function It(R,j){return R&&R.length?wh(R,zi(j,2)):[]}function hs(R,j){return j=typeof j=="function"?j:t,R&&R.length?wh(R,t,j):[]}function st(R){if(!(R&&R.length))return [];var j=0;return R=Ne(R,function(at){if(Qu(at))return j=_r(at.length,j),true}),Mn(j,function(at){return Le(R,Yn(at))})}function ks(R,j){if(!(R&&R.length))return [];var at=st(R);return j==null?at:Le(at,function(Nt){return qi(j,t,Nt)})}var ot=Yi(function(R,j){return Qu(R)?su(R,j):[]}),vu=Yi(function(R){return $c(Ne(R,Qu))}),Yl=Yi(function(R){var j=Dl(R);return Qu(j)&&(j=t),$c(Ne(R,Qu),zi(j,2))}),xo=Yi(function(R){var j=Dl(R);return j=typeof j=="function"?j:t,$c(Ne(R,Qu),t,j)}),qa=Yi(st);function sc(R,j){return Jh(R||[],j||[],Ba)}function fh(R,j){return Jh(R||[],j||[],Co)}var Io=Yi(function(R){var j=R.length,at=j>1?R[j-1]:t;return at=typeof at=="function"?(R.pop(),at):t,ks(R,at)});function _l(R){var j=he(R);return j.__chain__=true,j}function Pl(R,j){return j(R),R}function Xu(R,j){return j(R)}var qf=uo(function(R){var j=R.length,at=j?R[0]:0,Nt=this.__wrapped__,Qt=function(ye){return $u(ye,R)};return j>1||this.__actions__.length||!(Nt instanceof qs)||!ah(at)?this.thru(Qt):(Nt=Nt.slice(at,+at+(j?1:0)),Nt.__actions__.push({func:Xu,args:[Qt],thisArg:t}),new Cl(Nt,this.__chain__).thru(function(ye){return j&&!ye.length&&ye.push(t),ye}))});function uf(){return _l(this)}function Bh(){return new Cl(this.value(),this.__chain__)}function eo(){this.__values__===t&&(this.__values__=Xd(this.value()));var R=this.__index__>=this.__values__.length,j=R?t:this.__values__[this.__index__++];return {done:R,value:j}}function oc(){return this}function Ml(R){for(var j,at=this;at instanceof Ch;){var Nt=Wu(at);Nt.__index__=0,Nt.__values__=t,j?Qt.__wrapped__=Nt:j=Nt;var Qt=Nt;at=at.__wrapped__;}return Qt.__wrapped__=R,j}function Wl(){var R=this.__wrapped__;if(R instanceof qs){var j=R;return this.__actions__.length&&(j=new qs(this)),j=j.reverse(),j.__actions__.push({func:Xu,args:[_e],thisArg:t}),new Cl(j,this.__chain__)}return this.thru(_e)}function jh(){return pd(this.__wrapped__,this.__actions__)}var yp=bc(function(R,j,at){Rs.call(R,at)?++R[at]:Fo(R,at,1);});function Yd(R,j,at){var Nt=zs(R)?Te:oa;return at&&Lu(R,j,at)&&(j=t),Nt(R,zi(j,3))}function k1(R,j){var at=zs(R)?Ne:ll;return at(R,zi(j,3))}var x0=Ac(j0),i2=Ac(c0);function F1(R,j){return so(Ep(R,j),1)}function v1(R,j){return so(Ep(R,j),tt)}function E1(R,j,at){return at=at===t?1:Us(at),so(Ep(R,j),at)}function B1(R,j){var at=zs(R)?la:Eo;return at(R,zi(j,3))}function ac(R,j){var at=zs(R)?ko:Iu;return at(R,zi(j,3))}var j1=bc(function(R,j,at){Rs.call(R,at)?R[at].push(j):Fo(R,at,[j]);});function vp(R,j,at,Nt){R=Rc(R)?R:cu(R),at=at&&!Nt?Us(at):0;var Qt=R.length;return at<0&&(at=_r(Qt+at,0)),Op(R)?at<=Qt&&R.indexOf(j,at)>-1:!!Qt&&vn(R,j,at)>-1}var X3=Yi(function(R,j,at){var Nt=-1,Qt=typeof j=="function",ye=Rc(R)?wn(R.length):[];return Eo(R,function(Ue){ye[++Nt]=Qt?qi(j,Ue,at):Ho(Ue,j,at);}),ye}),Q3=bc(function(R,j,at){Fo(R,at,j);});function Ep(R,j){var at=zs(R)?Le:Xh;return at(R,zi(j,3))}function U1(R,j,at,Nt){return R==null?[]:(zs(j)||(j=j==null?[]:[j]),at=Nt?t:at,zs(at)||(at=at==null?[]:[at]),rc(R,j,at))}var wx=bc(function(R,j,at){R[at?0:1].push(j);},function(){return [[],[]]});function J3(R,j,at){var Nt=zs(R)?pn:zn,Qt=arguments.length<3;return Nt(R,zi(j,4),at,Qt,Eo)}function Ix(R,j,at){var Nt=zs(R)?en:zn,Qt=arguments.length<3;return Nt(R,zi(j,4),at,Qt,Iu)}function s2(R,j){var at=zs(R)?Ne:ll;return at(R,Ad(zi(j,3)))}function _p(R){var j=zs(R)?al:qu;return j(R)}function Z3(R,j,at){(at?Lu(R,j,at):j===t)?j=1:j=Us(j);var Nt=zs(R)?$o:wa;return Nt(R,j)}function bp(R){var j=zs(R)?xl:Go;return j(R)}function tg(R){if(R==null)return 0;if(Rc(R))return Op(R)?vo(R):R.length;var j=_o(R);return j==bt||j==Ae?R.size:mc(R).length}function Tp(R,j,at){var Nt=zs(R)?bn:Ds;return at&&Lu(R,j,at)&&(j=t),Nt(R,zi(j,3))}var Lx=Yi(function(R,j){if(R==null)return [];var at=j.length;return at>1&&Lu(R,j[0],j[1])?j=[]:at>2&&Lu(j[0],j[1],j[2])&&(j=[j[0]]),rc(R,so(j,1),[])}),Ap=kr||function(){return $r.Date.now()};function o2(R,j){if(typeof j!="function")throw new Kn(s);return R=Us(R),function(){if(--R<1)return j.apply(this,arguments)}}function Cp(R,j,at){return j=at?t:j,j=R&&j==null?R.length:j,Zs(R,E,t,t,t,t,j)}function K1(R,j){var at;if(typeof j!="function")throw new Kn(s);return R=Us(R),function(){return --R>0&&(at=j.apply(this,arguments)),R<=1&&(j=t),at}}var _1=Yi(function(R,j,at){var Nt=c;if(at.length){var Qt=We(at,Ha(_1));Nt|=b;}return Zs(R,Nt,j,at,Qt)}),eg=Yi(function(R,j,at){var Nt=c|l;if(at.length){var Qt=We(at,Ha(eg));Nt|=b;}return Zs(j,Nt,R,at,Qt)});function ng(R,j,at){j=at?t:j;var Nt=Zs(R,d,t,t,t,t,t,j);return Nt.placeholder=ng.placeholder,Nt}function a2(R,j,at){j=at?t:j;var Nt=Zs(R,m,t,t,t,t,t,j);return Nt.placeholder=a2.placeholder,Nt}function b1(R,j,at){var Nt,Qt,ye,Ue,Qe,S,M=0,rt=false,vt=false,Ft=true;if(typeof R!="function")throw new Kn(s);j=cf(j)||0,Zu(at)&&(rt=!!at.leading,vt="maxWait"in at,ye=vt?_r(cf(at.maxWait)||0,j):ye,Ft="trailing"in at?!!at.trailing:Ft);function re(Ki){var Os=Nt,es=Qt;return Nt=Qt=t,M=Ki,Ue=R.apply(es,Os),Ue}function Re(Ki){return M=Ki,Qe=Mh(or,j),rt?re(Ki):Ue}function je(Ki){var Os=Ki-S,es=Ki-M,go=j-Os;return vt?vr(go,ye-es):go}function Ye(Ki){var Os=Ki-S,es=Ki-M;return S===t||Os>=j||Os<0||vt&&es>=ye}function or(){var Ki=Ap();if(Ye(Ki))return ar(Ki);Qe=Mh(or,je(Ki));}function ar(Ki){return Qe=t,Ft&&Nt?re(Ki):(Nt=Qt=t,Ue)}function Lr(){Qe!==t&&Gd(Qe),M=0,Nt=S=Qt=Qe=t;}function li(){return Qe===t?Ue:ar(Ap())}function Ui(){var Ki=Ap(),Os=Ye(Ki);if(Nt=arguments,Qt=this,S=Ki,Os){if(Qe===t)return Re(S);if(vt)return Gd(Qe),Qe=Mh(or,j),re(S)}return Qe===t&&(Qe=Mh(or,j)),Ue}return Ui.cancel=Lr,Ui.flush=li,Ui}var rg=Yi(function(R,j){return Hu(R,1,j)}),u2=Yi(function(R,j,at){return Hu(R,cf(j)||0,at)});function Dx(R){return Zs(R,G)}function T1(R,j){if(typeof R!="function"||j!=null&&typeof j!="function")throw new Kn(s);var at=function(){var Nt=arguments,Qt=j?j.apply(this,Nt):Nt[0],ye=at.cache;if(ye.has(Qt))return ye.get(Qt);var Ue=R.apply(this,Nt);return at.cache=ye.set(Qt,Ue)||ye,Ue};return at.cache=new(T1.Cache||nu),at}T1.Cache=nu;function Ad(R){if(typeof R!="function")throw new Kn(s);return function(){var j=arguments;switch(j.length){case 0:return !R.call(this);case 1:return !R.call(this,j[0]);case 2:return !R.call(this,j[0],j[1]);case 3:return !R.call(this,j[0],j[1],j[2])}return !R.apply(this,j)}}function l2(R){return K1(2,R)}var Px=d1(function(R,j){j=j.length==1&&zs(j[0])?Le(j[0],dn(zi())):Le(so(j,1),dn(zi()));var at=j.length;return Yi(function(Nt){for(var Qt=-1,ye=vr(Nt.length,at);++Qt<ye;)Nt[Qt]=j[Qt].call(this,Nt[Qt]);return qi(R,this,Nt)})}),c2=Yi(function(R,j){var at=We(j,Ha(c2));return Zs(R,b,t,j,at)}),ig=Yi(function(R,j){var at=We(j,Ha(ig));return Zs(R,C,t,j,at)}),Mm=uo(function(R,j){return Zs(R,T,t,t,t,j)});function km(R,j){if(typeof R!="function")throw new Kn(s);return j=j===t?j:Us(j),Yi(R,j)}function h2(R,j){if(typeof R!="function")throw new Kn(s);return j=j==null?0:_r(Us(j),0),Yi(function(at){var Nt=at[j],Qt=Hc(at,0,j);return Nt&&tn(Qt,Nt),qi(R,this,Qt)})}function f2(R,j,at){var Nt=true,Qt=true;if(typeof R!="function")throw new Kn(s);return Zu(at)&&(Nt="leading"in at?!!at.leading:Nt,Qt="trailing"in at?!!at.trailing:Qt),b1(R,j,{leading:Nt,maxWait:j,trailing:Qt})}function d2(R){return Cp(R,1)}function $1(R,j){return c2(zu(j),R)}function A1(){if(!arguments.length)return [];var R=arguments[0];return zs(R)?R:[R]}function H1(R){return io(R,y)}function sg(R,j){return j=typeof j=="function"?j:t,io(R,y,j)}function p2(R){return io(R,v|y)}function C1(R,j){return j=typeof j=="function"?j:t,io(R,v|y,j)}function x2(R,j){return j==null||wu(R,j,Xl(j))}function dh(R,j){return R===j||R!==R&&j!==j}var og=L0(mu),Fm=L0(function(R,j){return R>=j}),O1=Ei((function(){return arguments})())?Ei:function(R){return dl(R)&&Rs.call(R,"callee")&&!Oi.call(R,"callee")},zs=wn.isArray,Mx=Se?dn(Se):nc;function Rc(R){return R!=null&&q1(R.length)&&!wc(R)}function Qu(R){return dl(R)&&Rc(R)}function zf(R){return R===true||R===false||dl(R)&&Ls(R)==Oe}var U0=qr||k2,g2=ge?dn(ge):cd;function S1(R){return dl(R)&&R.nodeType===1&&!z1(R)}function Qs(R){if(R==null)return true;if(Rc(R)&&(zs(R)||typeof R=="string"||typeof R.splice=="function"||U0(R)||Wd(R)||O1(R)))return !R.length;var j=_o(R);if(j==bt||j==Ae)return !R.size;if(M0(R))return !mc(R).length;for(var at in R)if(Rs.call(R,at))return false;return true}function G1(R,j){return cs(R,j)}function Uh(R,j,at){at=typeof at=="function"?at:t;var Nt=at?at(R,j):t;return Nt===t?cs(R,j,t,at):!!Nt}function Ju(R){if(!dl(R))return false;var j=Ls(R);return j==Et||j==Jt||typeof R.message=="string"&&typeof R.name=="string"&&!z1(R)}function ag(R){return typeof R=="number"&&bi(R)}function wc(R){if(!Zu(R))return false;var j=Ls(R);return j==ht||j==xt||j==te||j==ce}function kx(R){return typeof R=="number"&&R==Us(R)}function q1(R){return typeof R=="number"&&R>-1&&R%1==0&&R<=pt}function Zu(R){var j=typeof R;return R!=null&&(j=="object"||j=="function")}function dl(R){return R!=null&&typeof R=="object"}var ug=ae?dn(ae):O0;function Fx(R,j){return R===j||ii(R,j,Ga(j))}function Bm(R,j,at){return at=typeof at=="function"?at:t,ii(R,j,Ga(j),at)}function Cd(R){return tl(R)&&R!=+R}function lg(R){if(x1(R))throw new os(o);return Yh(R)}function m2(R){return R===null}function lu(R){return R==null}function tl(R){return typeof R=="number"||dl(R)&&Ls(R)==Dt}function z1(R){if(!dl(R)||Ls(R)!=Bt)return false;var j=fc(R);if(j===null)return true;var at=Rs.call(j,"constructor")&&j.constructor;return typeof at=="function"&&at instanceof at&&$s.call(at)==hc}var y2=ke?dn(ke):S0;function V1(R){return kx(R)&&R>=-pt&&R<=pt}var cg=Ke?dn(Ke):f1;function Op(R){return typeof R=="string"||!zs(R)&&dl(R)&&Ls(R)==kt}function lf(R){return typeof R=="symbol"||dl(R)&&Ls(R)==jt}var Wd=Xe?dn(Xe):po;function hg(R){return R===t}function Y1(R){return dl(R)&&_o(R)==$t}function Sp(R){return dl(R)&&Ls(R)==yt}var W1=L0(Wh),N1=L0(function(R,j){return R<=j});function Xd(R){if(!R)return [];if(Rc(R))return Op(R)?ro(R):zl(R);if(sr&&R[sr])return er(R[sr]());var j=_o(R),at=j==bt?Vn:j==Ae?kc:cu;return at(R)}function Pu(R){if(!R)return R===0?R:0;if(R=cf(R),R===tt||R===-tt){var j=R<0?-1:1;return j*J}return R===R?R:0}function Us(R){var j=Pu(R),at=j%1;return j===j?at?j-at:j:0}function K0(R){return R?ha(Us(R),0,mt):0}function cf(R){if(typeof R=="number")return R;if(lf(R))return dt;if(Zu(R)){var j=typeof R.valueOf=="function"?R.valueOf():R;R=Zu(j)?j+"":j;}if(typeof R!="string")return R===0?R:+R;R=mn(R);var at=Al.test(R);return at||No.test(R)?ga(R.slice(2),at?2:8):Tu.test(R)?dt:+R}function Bx(R){return ih(R,Kh(R))}function jm(R){return R?ha(Us(R),-pt,pt):R===0?R:0}function ya(R){return R==null?"":Ia(R)}var jx=Tc(function(R,j){if(M0(j)||Rc(j)){ih(j,Xl(j),R);return}for(var at in j)Rs.call(j,at)&&Ba(R,at,j[at]);}),g0=Tc(function(R,j){ih(j,Kh(j),R);}),Gs=Tc(function(R,j,at,Nt){ih(j,Kh(j),R,Nt);}),Np=Tc(function(R,j,at,Nt){ih(j,Xl(j),R,Nt);}),hf=uo($u);function Ux(R,j){var at=ec(R);return j==null?at:ca(at,j)}var Um=Yi(function(R,j){R=Ws(R);var at=-1,Nt=j.length,Qt=Nt>2?j[2]:t;for(Qt&&Lu(j[0],j[1],Qt)&&(Nt=1);++at<Nt;)for(var ye=j[at],Ue=Kh(ye),Qe=-1,S=Ue.length;++Qe<S;){var M=Ue[Qe],rt=R[M];(rt===t||dh(rt,At[M])&&!Rs.call(R,M))&&(R[M]=ye[M]);}return R}),aa=Yi(function(R){return R.push(t,vl),qi(Vx,t,R)});function Kx(R,j){return Tn(R,zi(j,3),Sa)}function fg(R,j){return Tn(R,zi(j,3),gu)}function $0(R,j){return R==null?R:ja(R,zi(j,3),Kh)}function dg(R,j){return R==null?R:Oa(R,zi(j,3),Kh)}function $x(R,j){return R&&Sa(R,zi(j,3))}function Hx(R,j){return R&&gu(R,zi(j,3))}function Rp(R){return R==null?[]:wo(R,Xl(R))}function Gx(R){return R==null?[]:wo(R,Kh(R))}function X1(R,j,at){var Nt=R==null?t:Qa(R,j);return Nt===t?at:Nt}function pg(R,j){return R!=null&&El(R,j,ma)}function qx(R,j){return R!=null&&El(R,j,fa)}var Km=p1(function(R,j,at){j!=null&&typeof j.toString!="function"&&(j=ju.call(j)),R[j]=at;},J1(ea)),$m=p1(function(R,j,at){j!=null&&typeof j.toString!="function"&&(j=ju.call(j)),Rs.call(R,j)?R[j].push(at):R[j]=[at];},zi),v2=Yi(Ho);function Xl(R){return Rc(R)?iu(R):mc(R)}function Kh(R){return Rc(R)?iu(R,true):yc(R)}function zx(R,j){var at={};return j=zi(j,3),Sa(R,function(Nt,Qt,ye){Fo(at,j(Nt,Qt,ye),Nt);}),at}function Hm(R,j){var at={};return j=zi(j,3),Sa(R,function(Nt,Qt,ye){Fo(at,Qt,j(Nt,Qt,ye));}),at}var Ic=Tc(function(R,j,at){If(R,j,at);}),Vx=Tc(function(R,j,at,Nt){If(R,j,at,Nt);}),Gm=uo(function(R,j){var at={};if(R==null)return at;var Nt=false;j=Le(j,function(ye){return ye=ql(ye,R),Nt||(Nt=ye.length>1),ye}),ih(R,Bs(R),at),Nt&&(at=io(at,v|_|y,a0));for(var Qt=j.length;Qt--;)Nl(at,j[Qt]);return at});function qm(R,j){return ph(R,Ad(zi(j)))}var Ql=uo(function(R,j){return R==null?{}:Qh(R,j)});function ph(R,j){if(R==null)return {};var at=Le(Bs(R),function(Nt){return [Nt]});return j=zi(j),Lf(R,at,function(Nt,Qt){return j(Nt,Qt[0])})}function E2(R,j,at){j=ql(j,R);var Nt=-1,Qt=j.length;for(Qt||(Qt=1,R=t);++Nt<Qt;){var ye=R==null?t:R[ic(j[Nt])];ye===t&&(Nt=Qt,ye=at),R=wc(ye)?ye.call(R):ye;}return R}function xg(R,j,at){return R==null?R:Co(R,j,at)}function gg(R,j,at,Nt){return Nt=typeof Nt=="function"?Nt:t,R==null?R:Co(R,j,at,Nt)}var _2=Vu(Xl),b2=Vu(Kh);function Yx(R,j,at){var Nt=zs(R),Qt=Nt||U0(R)||Wd(R);if(j=zi(j,4),at==null){var ye=R&&R.constructor;Qt?at=Nt?new ye:[]:Zu(R)?at=wc(ye)?ec(fc(R)):{}:at={};}return (Qt?la:Sa)(R,function(Ue,Qe,S){return j(at,Ue,Qe,S)}),at}function Wx(R,j){return R==null?true:Nl(R,j)}function el(R,j,at){return R==null?R:Kc(R,j,zu(at))}function ff(R,j,at,Nt){return Nt=typeof Nt=="function"?Nt:t,R==null?R:Kc(R,j,zu(at),Nt)}function cu(R){return R==null?[]:In(R,Xl(R))}function Vf(R){return R==null?[]:In(R,Kh(R))}function Qd(R,j,at){return at===t&&(at=j,j=t),at!==t&&(at=cf(at),at=at===at?at:0),j!==t&&(j=cf(j),j=j===j?j:0),ha(cf(R),j,at)}function Xx(R,j,at){return j=Pu(j),at===t?(at=j,j=0):at=Pu(at),R=cf(R),yu(R,j,at)}function mg(R,j,at){if(at&&typeof at!="boolean"&&Lu(R,j,at)&&(j=at=t),at===t&&(typeof j=="boolean"?(at=j,j=t):typeof R=="boolean"&&(at=R,R=t)),R===t&&j===t?(R=0,j=1):(R=Pu(R),j===t?(j=R,R=0):j=Pu(j)),R>j){var Nt=R;R=j,j=Nt;}if(at||R%1||j%1){var Qt=ri();return vr(R+Qt*(j-R+Hl("1e-"+((Qt+"").length-1))),j)}return r0(R,j)}var Q1=kf(function(R,j,at){return j=j.toLowerCase(),R+(at?Od(j):j)});function Od(R){return ta(ya(R).toLowerCase())}function H0(R){return R=ya(R),R&&R.replace(pu,_n).replace(_s,"")}function Sd(R,j,at){R=ya(R),j=Ia(j);var Nt=R.length;at=at===t?Nt:ha(Us(at),0,Nt);var Qt=at;return at-=j.length,at>=0&&R.slice(at,Qt)==j}function T2(R){return R=ya(R),R&&$n.test(R)?R.replace(Fi,Fn):R}function A2(R){return R=ya(R),R&&Wi.test(R)?R.replace(no,"\\$&"):R}var C2=kf(function(R,j,at){return R+(at?"-":"")+j.toLowerCase()}),O2=kf(function(R,j,at){return R+(at?" ":"")+j.toLowerCase()}),S2=Vl("toLowerCase");function wp(R,j,at){R=ya(R),j=Us(j);var Nt=j?vo(R):0;if(!j||Nt>=j)return R;var Qt=(j-Nt)/2;return yl(ci(Qt),at)+R+yl(ui(Qt),at)}function Ip(R,j,at){R=ya(R),j=Us(j);var Nt=j?vo(R):0;return j&&Nt<j?R+yl(j-Nt,at):R}function Qx(R,j,at){R=ya(R),j=Us(j);var Nt=j?vo(R):0;return j&&Nt<j?yl(j-Nt,at)+R:R}function Jx(R,j,at){return at||j==null?j=0:j&&(j=+j),Mr(ya(R).replace(ki,""),j||0)}function Zx(R,j,at){return (at?Lu(R,j,at):j===t)?j=1:j=Us(j),Ua(ya(R),j)}function yg(){var R=arguments,j=ya(R[0]);return R.length<3?j:j.replace(R[1],R[2])}var vg=kf(function(R,j,at){return R+(at?"_":"")+j.toLowerCase()});function xh(R,j,at){return at&&typeof at!="number"&&Lu(R,j,at)&&(j=at=t),at=at===t?mt:at>>>0,at?(R=ya(R),R&&(typeof j=="string"||j!=null&&!y2(j))&&(j=Ia(j),!j&&sn(R))?Hc(ro(R),0,at):R.split(j,at)):[]}var gh=kf(function(R,j,at){return R+(at?" ":"")+ta(j)});function mh(R,j,at){return R=ya(R),at=at==null?0:ha(Us(at),0,R.length),j=Ia(j),R.slice(at,at+j.length)==j}function N2(R,j,at){var Nt=he.templateSettings;at&&Lu(R,j,at)&&(j=t),R=ya(R),j=Gs({},j,Nt,Xi);var Qt=Gs({},j.imports,Nt.imports,Xi),ye=Xl(Qt),Ue=In(Qt,ye),Qe,S,M=0,rt=j.interpolate||Bu,vt="__p += '",Ft=un((j.escape||Bu).source+"|"+rt.source+"|"+(rt===Yr?Mo:Bu).source+"|"+(j.evaluate||Bu).source+"|$","g"),re="//# sourceURL="+(Rs.call(j,"sourceURL")?(j.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++eu+"]")+`
1616
1616
  `;R.replace(Ft,function(Ye,or,ar,Lr,li,Ui){return ar||(ar=Lr),vt+=R.slice(M,Ui).replace(il,Dn),or&&(Qe=true,vt+=`' +