@graphty/cytoscape-extensions 0.0.28 → 0.0.30
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.
- package/dist/algorithm-options.d.ts +5 -0
- package/dist/algorithm-options.d.ts.map +1 -0
- package/dist/algorithm-options.js +285 -0
- package/dist/algorithm-options.js.map +1 -0
- package/dist/algorithms.d.ts +489 -0
- package/dist/algorithms.d.ts.map +1 -0
- package/dist/algorithms.js +1184 -0
- package/dist/algorithms.js.map +1 -0
- package/dist/cdn/chunks/elements-DIunzJUl.js +1 -0
- package/dist/cdn/chunks/gpu-platform-browser-DnQwf3s0.js +2825 -0
- package/dist/cdn/chunks/index-C-jUF_Ve.js +1 -0
- package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
- package/dist/cdn/chunks/io-D-Vr0j3W.js +269 -0
- package/dist/cdn/chunks/preload-helper-Crt_PPe8.js +1 -0
- package/dist/cdn/chunks/samples-Dja23zzq.js +1 -0
- package/dist/cdn/chunks/sigv4-BXwVbza3-DZCCNyQA.js +3 -0
- package/dist/cdn/chunks/sources-cypher-oj3S6pKb.js +5 -0
- package/dist/cdn/chunks/sources-ndex-BgZhxHsL.js +1 -0
- package/dist/cdn/chunks/sources-rest-E6On5P3z.js +1 -0
- package/dist/cdn/chunks/sources-sparql-BAxh1dw-.js +5 -0
- package/dist/cdn/cytoscape-extensions.js +1 -0
- package/dist/cdn/io.js +1 -0
- package/dist/cytoscape-extensions.bundle.js +2825 -0
- package/dist/elements.d.ts +69 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +343 -0
- package/dist/elements.js.map +1 -0
- package/dist/gpu-platform-browser.d.ts +11 -0
- package/dist/gpu-platform-browser.d.ts.map +1 -0
- package/dist/gpu-platform-browser.js +22 -0
- package/dist/gpu-platform-browser.js.map +1 -0
- package/dist/gpu-platform-node.d.ts +15 -0
- package/dist/gpu-platform-node.d.ts.map +1 -0
- package/dist/gpu-platform-node.js +27 -0
- package/dist/gpu-platform-node.js.map +1 -0
- package/dist/gpu.d.ts +149 -0
- package/dist/gpu.d.ts.map +1 -0
- package/dist/gpu.js +312 -0
- package/dist/gpu.js.map +1 -0
- package/dist/graph-data.d.ts +101 -0
- package/dist/graph-data.d.ts.map +1 -0
- package/dist/graph-data.js +147 -0
- package/dist/graph-data.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +111 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +258 -0
- package/dist/io.js.map +1 -0
- package/dist/layouts.d.ts +207 -0
- package/dist/layouts.d.ts.map +1 -0
- package/dist/layouts.js +615 -0
- package/dist/layouts.js.map +1 -0
- package/dist/lazy.d.ts +21 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +32 -0
- package/dist/lazy.js.map +1 -0
- package/dist/samples.d.ts +115 -0
- package/dist/samples.d.ts.map +1 -0
- package/dist/samples.js +237 -0
- package/dist/samples.js.map +1 -0
- package/dist/snapshot.d.ts +81 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +225 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/webgpu-provider.d.ts +25 -0
- package/dist/webgpu-provider.d.ts.map +1 -0
- package/dist/webgpu-provider.js +53 -0
- package/dist/webgpu-provider.js.map +1 -0
- package/package.json +13 -9
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import{s as N,I as A,G as Up,M as yA,_ as xr}from"./preload-helper-Crt_PPe8.js";import{f as Bo,t as ty,a as xL,m as ny,e as ML,s as UL,b as GL,c as jL}from"./elements-DIunzJUl.js";const bA="E_FETCH",dt="E_MISSING_ID",Zn="E_MISSING_ENDPOINT",sn="W_DUPLICATE_NODE",ls="E_NO_GRAPH",Qn="W_MULTIPLE_GRAPHS",Ut="E_EMPTY_INPUT",kn="E_SYNTAX",Ku="E_XML_SYNTAX",Xu="E_XML_NESTING",vt="W_UNKNOWN_ELEMENT",qu="W_STRAY_TEXT",Ui="E_UNKNOWN_PARENT",EA="E_HYPEREDGE",FL="E_DUPLICATE_KEY",ln="W_COLUMN_RENAMED",zL="W_COLUMN_DROPPED",bn="W_ROLE_TAKEN",re="W_PRECISION",Rn="W_ID_MERGED",Ln="W_SINK_OPTION",Jt="W_OPTION_IGNORED",Kt="E_INVALID_UTF8",rn="E_INVALID_ENCODING",on="W_ENCODING_FALLBACK",En="W_UNKNOWN_ENCODING",hl="W_ENCODING_CONFLICT",fd="W_CONTROL_CHARACTER",wA="E_FOREIGN_FORMAT",_A="W_ISSUES_SUPPRESSED",Bd="W_UNKNOWN_XML_ATTRIBUTE",_i="W_DIRECTION_REFUSED",Vn="W_DIRECTION_FORCED",Or="E_MIXED_DIRECTION",Hd="W_COUNT_HINT",Zt="W_UNKNOWN_ATTR_TYPE",Ho="W_BAD_DEFAULT",SA="W_BAD_OPTIONS",Ai="E_DUPLICATE_EDGE_ID",ie="E_BAD_VALUE",fa="W_WIDENED",Xi="W_DANGLING_REFERENCE",fe="W_DUPLICATE_ATTRIBUTE",pl="E_PARENT_CYCLE",WL="W_EQUATION_AS_TEXT",to="W_STYLES_NOT_IMPORTED",mt="E_BAD_ASPECT_BLOCK",iy="W_MULTI_ASPECT_FRAGMENT",OA="W_SINGLE_OBJECT_ASPECT",Ju="W_JSON_NONSTANDARD_NUMBER",Bn="W_ASPECT_ORDER",Fs="W_COUNT_MISMATCH",Vd="E_STATUS_FAILED",ry="W_STATUS_WARNING",gl="E_TOO_LARGE",sy="E_COLUMN_TYPE",Nr="E_GRAPH_NOT_FOUND",as="E_AMBIGUOUS_GRAPH_NAME",BL="E_DUPLICATE_EDGE",HL="E_SELF_LOOP",VL="W_EDGES_MERGED",YL="W_SELF_LOOPS_DROPPED",tE="W_UNKNOWN_OPTION",KL="W_WEIGHT_NOT_FOUND",oy="W_ROLE_DROPPED",ly="W_PARENTS_DROPPED",NA="W_TEMPORAL_DROPPED",AA="W_MUTUAL_EXPANDED",TA="W_MUTUAL_AS_UNDIRECTED",cs="W_ID_TEXT_TYPE",IA="E_ID_TEXT_COLLISION",$A="W_TEMPORAL_TEXT_DROPPED",XL="W_WEIGHTS_DROPPED",CA="W_WEIGHT_KEY_CLASH",Qa="W_ROLE_ASSUMED",vA="W_COLUMN_NAME_CHANGED",ay="W_EMPTY_COLUMN_DROPPED",DA="W_STORAGE_CLASS_CHANGED",qL="W_INTEGRAL_F64_AS_I32",JL="W_TEXT_INFERRED",Yd="E_XML_ILLEGAL_CHAR",cy="W_COLUMN_AS_PROPERTY_VALUE",dy="W_RELATION_ASSUMED",uy="W_TYPEDEF_NODES",Zu="W_GRAPH_COLUMN_AS_METADATA",Gp="W_DIRECTION_DROPPED",fy="W_NONFINITE_AS_NULL",Qu="W_NODE_ORDER",ZL="W_OPTIONS_GAINED",Pn=Object.freeze({INVALID_ID:"E_INVALID_ID",UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",DUPLICATE_EDGE:BL,SELF_LOOP:HL,DUPLICATE_EDGE_ID:Ai}),xn=Object.freeze({EMPTY_INPUT:Ut,TOO_LARGE:gl,ENCODING_CONFLICT:hl,CONTROL_CHARACTER:fd,FOREIGN_FORMAT:wA,ISSUES_SUPPRESSED:_A});function O(t){return t===1?"":"s"}function C(t,e,n){return t===1?e:n}function kA(t,e){const n=[];return(t>0||e===0)&&n.push(`${t} node${O(t)}`),e>0&&n.push(`${e} edge${O(e)}`),n.join(" and ")}function RA(t){return`${/^[aeiou]/i.test(t)?"an":"a"} ${t}`}class it extends N{constructor(e,n,i){super("E_IMPORT",e,i),this.name="ImportError",Object.defineProperty(this,"report",{value:n,enumerable:!1}),this.issue=QL(n.issues,i?.code)}}function QL(t,e){let n=null;for(let i=t.length-1;i>=0;i--){if(t[i].code===e)return t[i];n===null&&t[i].severity==="error"&&(n=t[i])}return n}const Sc=1e3,hd=new WeakMap,bh=Symbol("nothing kept");function eP(t){return hd.get(t)}const tP={E_UNKNOWN_NODE:"missing-value",E_UNKNOWN_COLUMN:"missing-value",E_DIRECTED:"coercion",E_TOO_LARGE:"unsupported",E_UNSUPPORTED:"unsupported",E_GPU_INELIGIBLE:"unsupported"};function nE(t,e){const n=e?.line;return n==null||t.includes(`line ${n}`)?t:`line ${n}: ${t}`}class ne{constructor(e,n){this.counts={nodes:0,edges:0,skippedNodes:0,skippedEdges:0,expandedMixed:0},this.issueList=[],this.lossList=[],this.onceCodes=new Set,this.warningsByCode=new Map,this.errors=0,this.warnings=0,this.truncatedFlag=!1,this.kept=bh,this.format=e,this.errorLimit=n,this.startedAt=iE()}get issues(){return this.issueList}get errorCount(){return this.errors}get warningCount(){return this.warnings}get truncated(){return this.truncatedFlag}get lossy(){return this.lossList}error(e,n,i,r,s){const o=Oc(e,"error",n,i,r,s);if(this.issueList.push(o),this.errors++,this.errors>this.errorLimit)throw this.truncatedFlag=!0,this.abort(`error limit of ${this.errorLimit} exceeded: ${nE(i,r)}`,{code:n,limit:this.errorLimit});return o}warning(e,n,i,r,s){const o=Oc(e,"warning",n,i,r,s),l=(this.warningsByCode.get(n)??0)+1;return this.warningsByCode.set(n,l),l<=Sc&&(this.issueList.push(o),this.warnings++),o}warnOnce(e,n,i,r,s=n){return this.onceCodes.has(s)?null:(this.onceCodes.add(s),this.warning(e,n,i,r))}loss(e,n,i=null,r=null){const s=Object.freeze({code:e,message:n,column:i,count:r});return this.lossList.push(s),s}recordError(e,n){if(e instanceof N&&!(e instanceof it)){const i=tP[e.code]??"validation-error";return e.code==="E_TOO_LARGE"?this.failWith(i,e.code,e.message,n):this.error(i,e.code,e.message,n)}throw e}keepForStyles(e){return this.kept=e,this}fork(){const e=new ne(this.format,this.errorLimit);Object.assign(e.counts,this.counts),e.issueList.push(...this.issueList),e.lossList.push(...this.lossList);for(const n of this.onceCodes)e.onceCodes.add(n);for(const[n,i]of this.warningsByCode)e.warningsByCode.set(n,i);return e.errors=this.errors,e.warnings=this.warnings,e.truncatedFlag=this.truncatedFlag,e.kept=this.kept,e}abort(e,n){return new it(e,this.finish(),n)}fail(e,n,i,r){this.failWith("parse-error",e,n,i,r)}failWith(e,n,i,r,s,o){throw this.issueList.push(Oc(e,"error",n,i,r,o)),this.errors++,this.abort(nE(i,r),{code:n,...s})}include(e){for(const i of e.issues)this.issueList.push(i),i.severity==="error"?this.errors++:this.warnings++;const{counts:n}=e;return this.counts.nodes+=n.nodes,this.counts.edges+=n.edges,this.counts.skippedNodes+=n.skippedNodes,this.counts.skippedEdges+=n.skippedEdges,this.counts.expandedMixed+=n.expandedMixed,this.lossList.push(...e.lossy),this.truncatedFlag||=e.truncated,this.kept===bh&&hd.has(e)&&(this.kept=hd.get(e)),this}finish(){const{nodes:e,edges:n,skippedNodes:i,skippedEdges:r,expandedMixed:s}=this.counts,o=[];for(const[a,c]of this.warningsByCode)if(c>Sc){const d=c-Sc;o.push(Oc("unsupported","warning",_A,`${d} more ${a} warning${O(d)} ${C(d,"was","were")} not kept (the report keeps the first ${Sc})`,{element:a}))}const l=Object.freeze({format:this.format,counts:Object.freeze({nodes:e,edges:n,skippedNodes:i,skippedEdges:r,expandedMixed:s}),issues:Object.freeze([...this.issueList,...o]),errorCount:this.errors,warningCount:this.warnings+o.length,truncated:this.truncatedFlag,lossy:Object.freeze([...this.lossList]),durationMs:iE()-this.startedAt});return this.kept!==bh&&hd.set(l,this.kept),l}}function Oc(t,e,n,i,r,s){const o={category:t,severity:e,code:n,message:i,line:r?.line??null,element:r?.element??null};return Object.freeze(s===void 0?o:{...o,params:Object.freeze({...s})})}function nP(t){if(typeof t!="object"||t===null)return!1;const{name:e}=t;return e==="AbortError"||e==="TimeoutError"}function iP(t){return t instanceof Error?t.message:typeof t=="string"?t:`non-error thrown (${typeof t})`}function iE(){return typeof performance=="object"?performance.now():Date.now()}const rP="graphty.directed",LA="graphty.pair",sP="graphty.mutual",rE={name:rP,dtype:"bool",role:"directed"},sE={name:LA,dtype:"u32",role:"pair",refersTo:"edge"},oP={name:sP,dtype:"bool",role:"mutual"};class ei{constructor(e,n,i){this.directedHandle=A,this.pairHandle=A,this.mutualHandle=A,this.firstEdge=-1,this.nextEdge=-1,this.forcedCount=0,this.headerSet=!1,this.mirrorOfLast=A,this.sink=e,this.report=n,this.policy=i}get directed(){return this.sink.directed}get expanded(){return this.pairHandle!==A}setHeader(e,n){this.headerSet=!0;let i=e;(this.policy==="directed"||this.policy==="undirected")&&(i=this.policy==="directed",i!==e&&this.report.warnOnce("coercion",Vn,`the file declares ${Ti(e)} edges; read as ${Ti(i)} per onMixedDirection`,{line:n?.line??null},`${Vn}:${Ti(e)}`));const{sink:r}=this;if(r.directed===i){this.adoptExisting();return}try{if(i&&r.edgeCount>0&&!r.directedLocked){const s=r.edgeCount;r.setDirected(!0,{expand:!0}),this.adoptExpansionColumns(),this.report.counts.expandedMixed+=s}else r.setDirected(i)}catch(s){if(!(s instanceof N)||s.code!=="E_DIRECTED")throw s;this.report.warning("coercion",_i,`the file is ${Ti(i)} but the sink is ${Ti(r.directed)} (${lP(s)}); read as ${Ti(r.directed)}`,{line:n?.line??null})}this.adoptExisting()}adoptExisting(){this.pairHandle===A&&this.sink.edgeColumn(LA)!==A&&this.adoptExpansionColumns()}get lastMirror(){return this.mirrorOfLast}addEdge(e,n,i,r,s){if(!this.headerSet)throw new N("E_DIRECTED","DirectionResolver.setHeader() must run before the first edge",{reason:"header not set"});const{sink:o}=this;this.mirrorOfLast=A;const l=i!=="undirected";if(l===o.directed&&i!=="mutual"){const a=o.addEdge(e,n,r);return this.track(a),this.directedHandle!==A&&o.setEdgeValue(this.directedHandle,a,l),a}switch(this.policy){case"directed":case"undirected":{this.forcedCount++,this.report.warnOnce("coercion",Vn,`${i} edges read as ${Ti(o.directed)} per onMixedDirection`,s,`${Vn}:${i}`);const a=o.addEdge(e,n,r);return this.track(a),this.directedHandle!==A&&o.setEdgeValue(this.directedHandle,a,o.directed),a}case"error":throw this.report.error("validation-error",Or,`${i} edge in a ${Ti(o.directed)} graph (onMixedDirection: "error")`,s),this.report.abort("mixed direction refused",{code:Or});case"expand":return this.expand(e,n,i,r,s);default:{const a=this.policy;throw new N("E_UNSUPPORTED",`unknown onMixedDirection ${a}`,{option:"onMixedDirection",found:a})}}}get forced(){return this.forcedCount}expand(e,n,i,r,s){const{sink:o}=this;if(!o.directed){try{const f=o.edgeCount;o.setDirected(!0,{expand:!0}),this.adoptExpansionColumns(),this.report.counts.expandedMixed+=f}catch(f){throw!(f instanceof N)||f.code!=="E_DIRECTED"?f:(this.report.error("coercion",_i,`${Ti(!0)} edge in a locked ${Ti(!1)} sink cannot be expanded`,s),this.report.abort("the sink refused the expansion to directed",{code:_i,reason:f.details.reason}))}if(i==="directed"){const f=o.addEdge(e,n,r);return this.track(f),o.setEdgeValue(this.directedHandle,f,!0),f}}this.ensureExpansionColumns();const l=o.addEdge(e,n,r);this.track(l);const a=i==="mutual";o.setEdgeValue(this.directedHandle,l,a),this.report.counts.expandedMixed++,a&&(this.ensureMutualColumn(),o.setEdgeValue(this.mutualHandle,l,!0));const c=o.indexOf(e),d=o.indexOf(n);if(c===d)return l;const u=o.addEdge(n,e,r);return this.track(u),this.mirrorOfLast=u,o.setEdgeValue(this.directedHandle,u,a),o.setEdgeValue(this.pairHandle,l,u),o.setEdgeValue(this.pairHandle,u,l),l}track(e){this.firstEdge<0&&(this.firstEdge=e),this.nextEdge=e+1}adoptExpansionColumns(){this.directedHandle=this.sink.declareEdgeColumn(rE),this.pairHandle=this.sink.declareEdgeColumn(sE)}ensureExpansionColumns(){if(this.pairHandle===A&&(this.directedHandle=this.sink.declareEdgeColumn(rE),this.pairHandle=this.sink.declareEdgeColumn(sE),this.firstEdge>=0))for(let e=this.firstEdge;e<this.nextEdge;e++)this.sink.setEdgeValue(this.directedHandle,e,!0)}ensureMutualColumn(){this.mutualHandle===A&&(this.mutualHandle=this.sink.declareEdgeColumn(oP))}}function lP(t){const{reason:e}=t.details;return typeof e=="string"?e:"refused"}function Ti(t){return t?"directed":"undirected"}function Gt(t,e={}){const n=e.foldMutual??!1,i=Eh(t.edges.byRole("directed"),"bool"),r=Eh(t.edges.byRole("pair"),"u32"),s=Eh(t.edges.byRole("mutual"),"bool"),{edgeCount:o}=t,l=f=>{if(!r?.isSet(f))return A;const h=r.value(f);return typeof h=="number"&&h!==A?h:A},a=f=>i===null||!i.isSet(f)||i.value(f)===!0,c=f=>{if(s===null)return!1;if(s.isSet(f)&&s.value(f)===!0)return!0;const h=l(f);return h!==A&&s.isSet(h)&&s.value(h)===!0},d=f=>{const h=l(f);return h===A||h>=f?!1:!a(f)||n&&c(f)};let u=0;if(s!==null)for(let f=0;f<o;f++)s.isSet(f)&&s.value(f)===!0&&l(f)>f&&u++;return{expanded:r!==null,mutualCount:u,folded:d,mateOf:l,sourceDirected:a,isMutual:c}}function Eh(t,e){return t!==null&&t.dtype===e?t:null}function ct(t){if(!Number.isFinite(t))return String(t);if(t===0)return Object.is(t,-0)?"-0":"0";for(let e=1;e<=9;e++){const n=t.toPrecision(e);if(Math.fround(Number(n))===t)return String(Number(n))}return String(t)}function Fe(t){return Object.is(t,-0)?"-0":String(t)}function Hi(t){return typeof t=="number"?Fe(t):t}function Ar(t,e="f64"){if(!Number.isFinite(t))return String(t);if(Object.is(t,-0))return"-0.0";const n=Do(t,e);return n.includes(".")||n.includes("e")?n:`${n}.0`}function zs(t,e="f64"){if(Number.isNaN(t))return"NAN";if(!Number.isFinite(t))return t>0?"+INF":"-INF";const n=Ar(t,e);if(n.includes("."))return n;const i=n.indexOf("e");return`${n.slice(0,i)}.0${n.slice(i)}`}function Ge(t){return Number.isSafeInteger(t)||!Number.isFinite(t)?String(t):BigInt(t).toString()}function Do(t,e){return e==="f32"?ct(t):Fe(t)}const aP=1024,PA=4;function Yl(t){try{return new TextDecoder(t.trim()).encoding}catch{return null}}function cP(t){return pi(t,[255,254,0,0])?"utf-32le":pi(t,[0,0,254,255])?"utf-32be":pi(t,[239,187,191])?"utf-8":pi(t,[255,254])?"utf-16le":pi(t,[254,255])?"utf-16be":null}function pi(t,e){return t.byteLength>=e.length&&e.every((n,i)=>t[i]===n)}function dP(t){const e=Math.min(t.byteLength>>1,512);if(e<2)return null;let n=0,i=0;for(let r=0;r<e;r++){const s=t[2*r],o=t[2*r+1];s!==0&&o===0?n++:s===0&&o!==0&&i++}return n>=e*.9?"utf-16le":i>=e*.9?"utf-16be":null}function uP(t){return pi(t,[60,0,63,0])?"utf-16le":pi(t,[0,60,0,63])?"utf-16be":null}function xA(t){if(typeof t!="string"){if(pi(t,[31,139]))return"gzip-compressed data (decompress it first)";if(pi(t,[80,75,3,4])||pi(t,[80,75,5,6]))return"a zip archive (a Cytoscape session (.cys) is read by the cys importer; extract any other graph file from it first)";if(pi(t,[137,80,78,71]))return"a PNG image"}const e=typeof t=="string"?t.slice(0,64):String.fromCodePoint(...t.subarray(0,64)),n=String.fromCodePoint(239,187,191);let i=e.startsWith(n)?e.slice(3):e;return i=i.startsWith(GA)?i.slice(1):i,i.startsWith("%PDF-")?"a PDF document":/^\s*(<!doctype\s+html[\s>]|<html[\s>])/i.test(i)?"an HTML document (likely an error page saved in place of the file)":null}function MA(t,e,n){const i=xA(t);i!==null&&!(n.xml===!0&&i.startsWith("an HTML"))&&e.fail(wA,`the input is ${i}, not ${e.format} text`)}function fP(t,e){return t===e||t.startsWith("utf-16")&&e.startsWith("utf-16")}class hP{constructor(e,n){this.report=e,this.options=n,this.decoder=null,this.encoding="utf-8",this.mayFallBack=!1,this.asciiSoFar=!0,this.carry=new Uint8Array(0),this.offset=0,this.fellBack=!1,this.control=null,this.subAt=-1,this.textFollows=!1,this.declaredUtf8=!1,this.mixedPending=!1}get started(){return this.decoder!==null}start(e){MA(e,this.report,this.options);const n=this.options.encoding??null,i=cP(e);if((i==="utf-32le"||i==="utf-32be")&&this.report.fail(rn,`the input starts with a ${i.toUpperCase()} byte order mark; UTF-32 is not supported (convert the file to UTF-8)`,void 0,{byteOffset:0}),i!==null){const l=n===null?null:Yl(n);l!==null&&l!==i&&this.conflict(`the encoding option says ${l} but the byte order mark says ${i}; read as ${i}`),this.checkDeclaration(e,i,"its byte order mark says"),this.use(i,!1);return}if(n!==null){this.use(n,!1),this.checkDeclaration(e,this.encoding,"the encoding option says");return}const r=uP(e);if(r!==null){this.checkDeclaration(e,r,"its XML declaration's byte pattern says"),this.use(r,!1);return}const s=dP(e);if(s!==null&&this.options.bomlessUtf16===!0){this.use(s,!1);return}s!==null&&this.report.fail(rn,`the input looks like ${s} text without a byte order mark (every other byte is 0); pass the encoding option ${JSON.stringify(s)} to read it`,void 0,{byteOffset:0});const o=this.declared(e,"windows-1252");if(o!==null){const l=Yl(o);if(l===null)this.report.warning("unsupported",En,`the input declares the encoding ${JSON.stringify(o)}, which this platform cannot decode; reading it as UTF-8`,{element:o});else if(l.startsWith("utf-16"))this.conflict(`the input declares ${JSON.stringify(o)} but has no byte order mark and its bytes are not UTF-16; read as UTF-8`);else if(l==="utf-8")this.declaredUtf8=!0;else{this.use(l,!1);return}}this.use("utf-8",!0)}declared(e,n){const i=this.options.declaredEncoding;return i===void 0?null:i(new TextDecoder(n).decode(e))}checkDeclaration(e,n,i){const r=this.declared(e,n),s=r===null?null:Yl(r);s!==null&&!fP(s,n)&&this.conflict(`the input declares the encoding ${JSON.stringify(r)} but ${i} ${n}; read as ${n}`)}conflict(e){this.report.warning("coercion",hl,e)}decode(e,n){const i=typeof SharedArrayBuffer=="function"&&e.buffer instanceof SharedArrayBuffer?e.slice():e,r=this.decoder;(this.fellBack||this.mayFallBack&&this.asciiSoFar)&&(this.watch(i,!n),this.fellBack&&this.control!==null&&this.binary(this.control));const s=this.decodeOrRecover(r,i,n);return this.mixedPending&&this.reportUtf8After(i,this.offset),this.asciiSoFar&&this.mayFallBack&&this.trackAscii(i,s),this.mayFallBack&&this.options.nulIsBinary===!0&&s.includes("\0")&&this.binary({at:this.offset+i.indexOf(0),byte:0}),this.offset+=i.byteLength,s}decodeOrRecover(e,n,i){try{return e.decode(n,{stream:i})}catch(r){if(!(r instanceof TypeError))throw r;return this.recover(n,i)}}trackAscii(e,n){if(/[\u0080-\uffff]/.test(n)){this.asciiSoFar=!1,this.carry=new Uint8Array(0);return}const i=this.carry.byteLength===0?e:Kd([this.carry,e]);this.carry=i.slice(n.length)}flushBeforeText(e){this.textFollows=!0;try{return e()}finally{this.textFollows=!1}}recover(e,n){const i=this.carry.byteLength===0?e:Kd([this.carry,e]),r=this.offset-this.carry.byteLength,s=this.encoding==="utf-8"?bP(i):null,o=r+(s===null?0:s.index);if(this.mayFallBack&&this.asciiSoFar){const l=this.fallBack(i,s,o,r,n);if(l!==null)return l}return this.failDecode(e,o,r,n)}fallBack(e,n,i,r,s){if(this.control!==null)return this.binary(this.control);if(this.textFollows&&n?.cut===!0)return this.report.fail(Kt,`invalid UTF-8 at byte ${i}: a byte chunk ends inside a multi-byte sequence and a text chunk follows`,void 0,{byteOffset:i});if(!s&&n?.truncated===!0)return this.report.fail(Kt,`the input ends in the middle of a UTF-8 sequence at byte ${i} (it may be truncated)`,void 0,{byteOffset:i});if(gP(e))return null;const o=!s&&n?.cut===!0?": it ends inside a multi-byte UTF-8 sequence, so it may be truncated":"";return this.report.warning("coercion",on,this.declaredUtf8?`the input declares UTF-8 but is not valid UTF-8 (at byte ${i}); everything before was ASCII, so it is read as windows-1252 (pass the encoding option to choose another)`:`the input is not valid UTF-8 (at byte ${i}${o}) and declares no encoding; read as windows-1252 (pass the encoding option to choose another)`),this.use("windows-1252",!1),this.fellBack=!0,this.mixedPending=!0,this.reportUtf8After(e,r),this.decoder.decode(e,{stream:s})}failDecode(e,n,i,r){if(this.encoding==="utf-8"){const l=this.mayFallBack?" after valid non-ASCII UTF-8 text; pass the encoding option":"";return this.report.fail(Kt,`invalid UTF-8 at byte ${n}${l}`,void 0,{byteOffset:n})}const s=this.offset+e.byteLength,o=!r&&this.encoding.startsWith("utf-16")&&s%2===1;return this.report.fail(rn,o?`the input ends with half a ${this.encoding} code unit at byte ${s-1} (it may be truncated)`:`the bytes near byte ${i} are not valid ${this.encoding}`,void 0,{byteOffset:o?s-1:i})}reportUtf8After(e,n){const i=pP(e);i<0||(this.mixedPending=!1,this.report.warning("coercion",on,`bytes read as windows-1252 hold valid UTF-8 (at byte ${n+i}): the input mixes encodings, and its UTF-8 characters are read as windows-1252 (pass the encoding option to choose one)`))}watch(e,n){if(this.control!==null||e.byteLength===0)return;if(this.subAt>=0){this.control={at:this.subAt,byte:26};return}const i=SP(e,!0);i>=0?this.control={at:this.offset+i,byte:e[i]}:!n&&e[e.byteLength-1]===26&&(this.subAt=this.offset+e.byteLength-1)}binary(e){const n=e.byte.toString(16).padStart(2,"0");return this.report.fail(Kt,`the input is binary data, not text: control byte 0x${n} at byte ${e.at}`,void 0,{byteOffset:e.at})}use(e,n){this.decoder=new TextDecoder(e,{fatal:!0,ignoreBOM:!0}),this.encoding=this.decoder.encoding,this.mayFallBack=n}}function pP(t){for(let e=0;e<t.byteLength;e++)if(t[e]>=194&&UA(t,e))return e;return-1}function gP(t){const e=t.findIndex(n=>n>=128);return e>=0&&UA(t,e)}const mP=new TextDecoder("utf-8",{fatal:!0});function UA(t,e){const n=t[e];let i=0;if(n>=194&&n<=223?i=2:n>=224&&n<=239?i=3:n>=240&&n<=244&&(i=4),i===0||e+i>t.byteLength)return!1;try{return mP.decode(t.subarray(e,e+i)),!0}catch{return!1}}const yP=[199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160];function bP(t){let e=0;for(;e<t.byteLength;){const n=t[e],i=n<128?EP:wP(n);if(i===null)return{index:e,truncated:!1,cut:!1};const r=_P(t,e,i);if(r!==null)return r;e+=i.need+1}return{index:0,truncated:!1,cut:!1}}const EP={need:0,low:128,high:191};function wP(t){return t>=194&&t<=223?{need:1,low:128,high:191}:t>=224&&t<=239?{need:2,low:t===224?160:128,high:t===237?159:191}:t>=240&&t<=244?{need:3,low:t===240?144:128,high:t===244?143:191}:null}function _P(t,e,n){for(let i=1;i<=n.need;i++){if(e+i>=t.byteLength)return{index:e,truncated:i>1,cut:!0};const r=t[e+i],s=i===1?n.low:128,o=i===1?n.high:191;if(r<s||r>o)return{index:e,truncated:!1,cut:!1}}return null}function SP(t,e){const n=t.byteLength-1;for(let i=0;i<=n;i++){const r=t[i];if(r<32&&r!==9&&r!==10&&r!==12&&r!==13&&!(r===26&&e&&i===n))return i}return-1}function hy(t,e=!1){try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(t)}catch{if(!e)return new TextDecoder("windows-1252").decode(t);let n="";for(const i of t)n+=String.fromCodePoint(i<128?i:yP[i-128]);return n}}function Kd(t){if(t.length===1)return t[0];const e=new Uint8Array(t.reduce((i,r)=>i+r.byteLength,0));let n=0;for(const i of t)e.set(i,n),n+=i.byteLength;return e}const zl=256*1024,GA="\uFEFF",oE=String.fromCodePoint(26),Vo=2**29-24,OP=new RegExp(`[${String.fromCodePoint(0)}-${String.fromCodePoint(8,11,14)}-${String.fromCodePoint(31,127)}-${String.fromCodePoint(159)}${GA}]`);function jA(t){return typeof t=="string"||ef(t)!==null?!0:typeof t!="object"||t===null?!1:typeof t.getReader=="function"||Symbol.asyncIterator in t}function ef(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)&&Object.prototype.toString.call(t)==="[object Uint8Array]"?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):null}function tf(t){if(typeof t=="string")return t;const e=ef(t);if(e!==null)return e;if(jA(t))return t;const n=Object.prototype.toString.call(t).slice(8,-1);let i=t===null?"null":typeof t,r="";if(n==="ArrayBuffer"||n==="SharedArrayBuffer")i=`an ${n}`,r="; wrap it as new Uint8Array(buffer)";else if(ArrayBuffer.isView(t))i=`a ${n}`,r="; pass new Uint8Array(view.buffer, view.byteOffset, view.byteLength)";else if(typeof t=="object"&&t!==null){const s=t;typeof s.stream=="function"&&typeof s.size=="number"?(i="a Blob or File",r="; pass blob.stream()"):"body"in s&&typeof s.arrayBuffer=="function"?(i="a fetch Response",r="; pass response.body"):i=`an object (${n})`}throw new N("E_UNSUPPORTED",`the input is ${i}; an importer reads a string, a Uint8Array, a ReadableStream or an async iterable of strings and Uint8Arrays${r}`,{reason:"input type",found:i})}function NP(t){return typeof t=="string"?t.length:t instanceof Uint8Array?t.byteLength:null}function Xd(t){let e=0,n=0;for(;n<t.length;){const i=t.charCodeAt(n),r=i>=55296&&i<=56319&&(t.charCodeAt(n+1)&64512)===56320;i<128?e++:i<2048?e+=2:e+=r?4:3,n+=r?2:1}return e}function F(t){if(!t?.aborted)return;const{reason:e}=t;throw e===void 0?AP():e}function AP(){const t="The import was aborted";if(typeof DOMException=="function")return new DOMException(t,"AbortError");const e=new Error(t);return e.name="AbortError",e}function FA(t,e){return e===null||typeof e.addEventListener!="function"?t:new Promise((n,i)=>{const r=()=>{try{F(e)}catch(s){i(s)}};e.addEventListener("abort",r,{once:!0}),t.then(s=>{e.removeEventListener("abort",r),n(s)},s=>{e.removeEventListener("abort",r),i(s)})})}function zA(t){if(t.locked)throw new N("E_UNSUPPORTED","the input ReadableStream is locked: another reader holds it (release it, or pass a fresh stream)",{reason:"stream locked"});return t.getReader()}class WA{constructor(e,n){this.report=e,this.options=n,this.first=!0,this.content=!1,this.heldSub=!1,this.warned=!1,this.strayBom=!1}push(e){let n=this.heldSub?oE+e:e;if(this.heldSub=!1,n.length===0)return n;if(this.first){if(n=this.skipByteOrderMarks(n),n.length===0)return n;this.first=!1,MA(n,this.report,this.options)}return n.endsWith(oE)&&(this.heldSub=!0,n=n.slice(0,-1)),!this.content&&/\S/.test(n)&&(this.content=!0),this.warned||this.warnControl(n),n}skipByteOrderMarks(e){let n=0;for(;e.codePointAt(n)===65279;)n++;return n>1&&!this.strayBom&&(this.strayBom=!0,this.report.warning("validation-error",fd,`the input starts with ${n} byte order marks (U+FEFF); the extra ones were ignored`,{element:"U+FEFF"})),e.slice(n)}warnControl(e){const n=OP.exec(e);if(n===null)return;this.warned=!0;const i=(n[0].codePointAt(0)??0).toString(16).toUpperCase().padStart(4,"0"),r=JSON.stringify(e.slice(Math.max(0,n.index-20),n.index+20));this.report.warning("validation-error",fd,`the input holds the control character U+${i} (in ${r}); it is kept in the id or value it is part of`,{element:`U+${i}`})}end(){this.heldSub&&this.report.warning("validation-error",fd,"the input ends with a Ctrl-Z (0x1A), the DOS end-of-file marker; it was ignored",{element:"U+001A"}),!this.content&&this.options.allowEmpty!==!0&&this.report.fail(Ut,this.first?"the input is empty":"the input holds only whitespace")}}function BA(t,e){e!=null&&t.warning("unsupported",Jt,"option encoding has no effect on text input, which is already decoded",{element:"encoding"})}async function*$r(t,e,n={}){const i=tf(t),r=n.signal??null,s=new WA(e,n);if(F(r),typeof i=="string"){BA(e,n.encoding),yield*IP(i,s,n);return}const o=new hP(e,n);if(i instanceof Uint8Array){yield*$P(i,s,o,n);return}const l=new CP(s,o,n);for await(const c of VA(i)?YA(i,r):i){F(r);const d=l.push(c);d.length>0&&(yield d),n.onProgress?.(l.done)}const a=l.end();a.length>0&&(yield a),s.end(),n.onProgress?.(l.done,l.done)}function TP(t,e){const n=Math.min(e+zl,t.length),i=(t.charCodeAt(n-1)&64512)===55296;return n<t.length&&i?n+1:n}function*IP(t,e,n){const i=n.signal??null,r=n.onProgress??null,s=r===null?0:Xd(t);let o=0,l=0;for(;l<t.length;){F(i);const a=TP(t,l),c=l===0&&a===t.length?t:t.slice(l,a);l=a;const d=e.push(c);d.length>0&&(yield d),r!==null&&(o+=Xd(c),r(o,s))}t.length===0&&r?.(0,0),e.end()}function*$P(t,e,n,i){const r=i.signal??null,s=t.byteLength;n.start(t.subarray(0,HA(i)));for(let o=0;o<s;o+=zl){if(F(r),t.byteLength!==s)throw new N("E_UNSUPPORTED","the input's buffer was detached (transferred) or resized during the import",{reason:"detached"});const l=t.subarray(o,Math.min(o+zl,s)),a=e.push(n.decode(l,o+zl<s));a.length>0&&(yield a),i.onProgress?.(Math.min(o+zl,s),s)}s===0&&i.onProgress?.(0,0),e.end()}function HA(t){return Math.max(t.declarationBytes??aP,PA)}class CP{constructor(e,n,i){this.filter=e,this.decoder=n,this.done=0,this.head=[],this.headLength=0,this.headBytes=HA(i),this.needed=i.declaredEncoding===void 0?PA:this.headBytes,this.counting=(i.onProgress??null)!==null}push(e){if(typeof e=="string")return this.done+=this.counting?Xd(e):0,this.filter.push(this.beforeText()+e);const n=ef(e);if(n===null)throw new N("E_UNSUPPORTED","an input chunk must be a string or a Uint8Array",{reason:"chunk type",found:typeof e});return this.done+=n.byteLength,this.decoder.started?this.filter.push(this.decoder.decode(n,!0)):(this.head.push(n),this.headLength+=n.byteLength,this.headLength>=this.needed?this.filter.push(this.flushHead(!0)):"")}end(){let e="";return this.headLength>0?e=this.flushHead(!1):this.decoder.started&&(e=this.decoder.decode(new Uint8Array(0),!1)),this.filter.push(e)}flushHead(e){const n=Kd(this.head);return this.head=[],this.headLength=0,this.decoder.start(n.subarray(0,this.headBytes)),this.decoder.decode(n,e)}beforeText(){return this.headLength>0?this.decoder.flushBeforeText(()=>this.flushHead(!1)):this.decoder.started?this.decoder.flushBeforeText(()=>this.decoder.decode(new Uint8Array(0),!1)):(this.decoder.start(new Uint8Array(0)),"")}}function VA(t){return typeof t.getReader=="function"}async function*YA(t,e){const n=zA(t);let i=!1;try{for(;;){F(e);const{done:r,value:s}=await FA(n.read(),e);if(r){i=!0;return}yield s}}finally{i||await n.cancel(e?.reason).catch(()=>{}),n.releaseLock()}}async function KA(t,e={}){const n=tf(t),i=e.signal??null;if(F(i),typeof n=="string")return null;if(n instanceof Uint8Array)return e.onProgress?.(n.byteLength,n.byteLength),n;const r=[];let s=0;for await(const o of VA(n)?YA(n,i):n){if(F(i),typeof o=="string")return null;const l=ef(o);if(l===null)throw new N("E_UNSUPPORTED","an input chunk must be a string or a Uint8Array",{reason:"chunk type",found:typeof o});r.push(l),s+=l.byteLength,e.onProgress?.(s)}return e.onProgress?.(s,s),r.length===0?new Uint8Array(0):Kd(r)}function py(t,e,n){t.failWith("unsupported",gl,e,n===void 0?void 0:{line:n})}async function Kr(t,e,n={}){const i=tf(t);if(typeof i=="string"){F(n.signal),BA(e,n.encoding);const o=new WA(e,n),l=o.push(i);if(o.end(),n.onProgress!==null&&n.onProgress!==void 0){const a=Xd(i);n.onProgress(a,a)}return l}const r=[];let s=0;for await(const o of $r(i,e,n))s+=o.length,s>Vo&&py(e,`the document is longer than ${Vo} characters, the most one JavaScript string holds`),r.push(o);return r.length===1?r[0]:r.join("")}class jp{constructor(e,n,i={}){this.lineNumber=0,this.input=e,this.report=n,this.options=i}get line(){return this.lineNumber}lineTooLong(){return`a line is longer than ${Vo} characters, the most one JavaScript string holds`}async*[Symbol.asyncIterator](){const e=new vP(i=>py(this.report,this.lineTooLong(),i));let n=!1;for await(const i of $r(this.input,this.report,this.options)){let r=0;n&&(n=!1,this.lineNumber++,yield e.take().slice(0,-1),i.charCodeAt(0)===10&&(r=1));const s=new DP(i,r);for(;s.advance();)this.lineNumber++,yield e.finish(i.slice(r,s.cut),this.lineNumber),r=s.next;r<i.length&&(e.appendRest(i,r,this.lineNumber+1),n=i.codePointAt(i.length-1)===13)}if(!e.empty){this.lineNumber++;const i=e.take();yield i.endsWith("\r")?i.slice(0,-1):i}}}class vP{constructor(e){this.pieces=[],this.length=0,this.tooLong=e}get empty(){return this.pieces.length===0}appendRest(e,n,i){this.append(n===0?e:e.slice(n),i)}finish(e,n){return this.pieces.length===0?e:(this.append(e,n),this.take())}take(){const e=this.pieces.join("");return this.pieces.length=0,this.length=0,e}append(e,n){this.length+=e.length,this.length>Vo&&this.tooLong(n),this.pieces.push(e)}}class DP{constructor(e,n){this.cut=0,this.chunk=e,this.next=n,this.nl=e.indexOf(`
|
|
2
|
+
`,n),this.cr=e.indexOf("\r",n)}advance(){const{chunk:e,next:n}=this;this.nl>=0&&this.nl<n&&(this.nl=e.indexOf(`
|
|
3
|
+
`,n)),this.cr>=0&&this.cr<n&&(this.cr=e.indexOf("\r",n));const{nl:i,cr:r}=this;return r>=0&&(i<0||r<i)?r===e.length-1?!1:(this.cut=r,this.next=e.codePointAt(r+1)===10?r+2:r+1,!0):i<0?!1:(this.cut=i,this.next=i+1,!0)}}const XA="timeText",Wi=".text",kP=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?)?(Z|z|[+-]\d{2}(?::?\d{2})?)?$/,RP=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|z|[+-]\d{2}(?::?\d{2})?)?$/,qA=/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,qd=6e4,ko=864e5;function Ro(t,e){let n;switch(e){case"date":case"dateTime":case"localDateTime":n=LP(t,e);break;case"time":case"localTime":n=PP(t,e);break;default:{const r=e;throw new N("E_COLUMN_TYPE",`unknown temporal kind ${r}`,{kind:r})}}const i=ha(n,e);return{value:n,text:i===t?null:t}}function qi(t,e){const n=t.trim();switch(e){case"integer":case"double":return lE(n);case"date":return Ro(n,"date");case"dateTime":return Ro(n,"dateTime");case null:return qA.test(n)?lE(n):Ro(n,"dateTime");default:{const i=e;throw new N("E_COLUMN_TYPE",`unknown timeformat ${i}`,{timeFormat:i})}}}function ha(t,e){switch(e){case"date":{const n=new Date(t);return`${aE(n)}-${Ns(n.getUTCMonth()+1)}-${Ns(n.getUTCDate())}`}case"dateTime":case"localDateTime":{const n=new Date(t),i=`${aE(n)}-${Ns(n.getUTCMonth()+1)}-${Ns(n.getUTCDate())}`,r=cE(n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds());return e==="dateTime"?`${i}T${r}Z`:`${i}T${r}`}case"time":case"localTime":{const n=(t%ko+ko)%ko,i=Math.floor(n/36e5),r=Math.floor(n%36e5/qd),s=Math.floor(n%qd/1e3),o=cE(i,r,s,n%1e3);return e==="time"?`${o}Z`:o}default:{const n=e;throw new N("E_COLUMN_TYPE",`unknown temporal kind ${n}`,{kind:n})}}}function Jd(t,e){switch(e){case"date":return ha(t,"date");case"dateTime":return ha(t,"dateTime");case"integer":case"double":case null:return String(t);default:{const n=e;throw new N("E_COLUMN_TYPE",`unknown timeformat ${n}`,{timeFormat:n})}}}function JA(t){return{name:t+Wi,dtype:"string",role:XA,nullable:!0,extra:{for:t}}}function lE(t){if(!qA.test(t))throw new N("E_COLUMN_TYPE",`"${t}" is not a numeric time`,{value:t});const e=Number(t);return{value:e,text:String(e)===t?null:t}}function LP(t,e){const n=kP.exec(t);if(n===null)throw new N("E_COLUMN_TYPE",`"${t}" is not an ISO-8601 ${e}`,{value:t,kind:e});const i=Number(n[1]),r=Number(n[2]),s=Number(n[3]),o=n[4]===void 0?0:Number(n[4]),l=n[5]===void 0?0:Number(n[5]),a=n[6]===void 0?0:Number(n[6]),c=n[7]===void 0?0:ZA(n[7]);if(r<1||r>12||s<1||s>31||o>24||l>59||a>60)throw new N("E_COLUMN_TYPE",`"${t}" is out of range for a ${e}`,{value:t,kind:e});const d=new Date(0);if(d.setUTCFullYear(i,r-1,s),d.setUTCHours(o,l,a,c),d.getUTCDate()!==s&&o!==24)throw new N("E_COLUMN_TYPE",`"${t}" is not a calendar date`,{value:t,kind:e});const u=n[8]===void 0?0:QA(n[8]);return d.getTime()-u*qd}function PP(t,e){const n=RP.exec(t);if(n===null)throw new N("E_COLUMN_TYPE",`"${t}" is not an ISO-8601 ${e}`,{value:t,kind:e});const i=Number(n[1]),r=Number(n[2]),s=n[3]===void 0?0:Number(n[3]),o=n[4]===void 0?0:ZA(n[4]);if(i>24||r>59||s>60)throw new N("E_COLUMN_TYPE",`"${t}" is out of range for a ${e}`,{value:t,kind:e});const l=((i*60+r)*60+s)*1e3+o,a=n[5]===void 0?0:QA(n[5]);return((l-a*qd)%ko+ko)%ko}function ZA(t){return Math.floor(+`0.${t}`*1e3)}function QA(t){if(t==="Z"||t==="z")return 0;const e=t.startsWith("-")?-1:1,n=t.slice(1).replace(":",""),i=Number(n.slice(0,2)),r=n.length>2?Number(n.slice(2,4)):0;return e*(i*60+r)}function Ns(t){return t<10?`0${t}`:String(t)}function aE(t){const e=t.getUTCFullYear(),n=String(Math.abs(e)).padStart(4,"0");return e<0?`-${n}`:n}function cE(t,e,n,i){const r=`${Ns(t)}:${Ns(e)}:${Ns(n)}`;return i===0?r:`${r}.${String(i).padStart(3,"0")}`}const gy={dtype:"bool",kind:"boolean"},Xr={dtype:"i32",kind:"integer"},Zd={dtype:"f64",kind:"long",precision:!0},my={dtype:"f32",kind:"float"},nf={dtype:"f64",kind:"double"},Ri={dtype:"string",kind:"string"},eT={dtype:"f64",kind:"temporal",temporal:"date"},tT={dtype:"f64",kind:"temporal",temporal:"dateTime"},xP={dtype:"f64",kind:"temporal",temporal:"localDateTime"},MP={dtype:"f64",kind:"temporal",temporal:"time"},UP={dtype:"f64",kind:"temporal",temporal:"localTime"},GP={dtype:"string",kind:"duration"},jP={dtype:"json",kind:"point"},FP={dtype:"json",kind:"json"},zP={integer:Xr,long:Zd,double:nf,float:my,boolean:gy,string:Ri,anyuri:Ri,char:Ri,byte:Xr,short:Xr,bigdecimal:Ri,biginteger:Ri,date:eT,datetime:tT},WP={boolean:gy,int:Xr,long:Zd,float:my,double:nf,string:Ri},BP={int:Xr,real:nf,string:Ri,record:FP},HP={int:Xr,integer:Zd,long:Zd,float:my,double:nf,boolean:gy,byte:Xr,short:Xr,char:Ri,string:Ri,point:jP,date:eT,localtime:UP,time:MP,localdatetime:xP,datetime:tT,duration:GP},VP={gexf:zP,graphml:WP,gml:BP,neo4j:HP},dE=/^[+-]?\d+$/,nT=/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,YP=-2147483648,KP=2147483647;function yy(t,e,n){const i=VP[t];let r=e.trim().toLowerCase(),s=!1;if(t==="gexf"&&r.startsWith("list")&&r.length>4)s=!0,r=r.slice(4);else if(t==="neo4j"&&r.endsWith("[]"))s=!0,r=r.slice(0,-2);else if(t==="gml"&&r==="list")return{declared:e,dtype:"list",itemDtype:"json",kind:"json",list:!0,temporal:null,precision:!1};let o=i[r];return o===void 0?null:(o.kind==="long"&&n==="string"&&(o=Ri),{declared:e,dtype:s?"list":o.dtype,itemDtype:s?o.dtype:null,kind:o.kind,list:s,temporal:o.temporal??null,precision:o.precision??!1})}function uE(t){return{declared:t??"",dtype:"string",itemDtype:null,kind:"string",list:!1,temporal:null,precision:!1}}function XP(t,e,n=null){switch(e){case"boolean":{const i=qP(t);if(i===null)throw ur(t,e);return i}case"integer":{const i=t.trim();if(!dE.test(i))throw ur(t,e);const r=Number(i);if(r<YP||r>KP)throw new N("E_COLUMN_TYPE",`"${i}" is outside the 32-bit integer range`,{value:i,kind:e});return r}case"long":{const i=t.trim();if(!dE.test(i))throw ur(t,e);return Number(i)}case"float":case"double":return by(t,e);case"string":case"duration":return t;case"temporal":{if(n===null)throw new N("E_COLUMN_TYPE","a temporal value needs its temporal kind",{kind:e});return Ro(t.trim(),n).value}case"point":return JP(t);case"json":return ZP(t);default:{const i=e;throw new N("E_COLUMN_TYPE",`unknown value kind ${i}`,{kind:i})}}}function qP(t){switch(t.trim().toLowerCase()){case"true":case"1":return!0;case"false":case"0":return!1;default:return null}}function by(t,e="double"){const n=t.trim();if(nT.test(n))return Number(n);switch(n){case"INF":case"+INF":case"Infinity":case"+Infinity":return 1/0;case"-INF":case"-Infinity":return-1/0;case"NaN":return Number.NaN;default:throw ur(t,e)}}function Fp(t){const e=t.trim();return/^[+-]?[0-9.]/.test(e)&&Number(e)===(e.startsWith("-")?-1/0:1/0)}function JP(t){const e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))throw ur(t,"point");const n={},i=e.slice(1,-1).trim();if(i.length===0)return n;for(const r of i.split(",")){const s=r.indexOf(":");if(s<0)throw ur(t,"point");const o=r.slice(0,s).trim().replaceAll(/(?:^["'])|(?:["']$)/g,""),l=r.slice(s+1).trim();if(o.length===0)throw ur(t,"point");if(nT.test(l))n[o]=Number(l);else if(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))n[o]=l.slice(1,-1);else throw ur(t,"point")}return n}function ZP(t){try{return JSON.parse(t)}catch{throw ur(t,"json")}}function ur(t,e){const n=t.length>40?`${t.slice(0,40)}...`:t;return new N("E_COLUMN_TYPE",`"${n}" is not ${RA(e)}`,{value:t,kind:e})}function pa(t,e){const n=t.trim();if(n.length===0)return[];switch(e){case"gexf":{if(fE(n))return hE(n);const i=QP(n,["|",",",";"]);return i===null?[n]:Nc(n,i)}case"brackets":return fE(n)?hE(n):[n];case"pipe":return Nc(n,"|");case"comma":return Nc(n,",");case"semicolon":return Nc(n,";");default:{const i=e;throw new N("E_UNSUPPORTED",`unknown list syntax ${i}`,{option:"listSyntax",found:i})}}}function Ey(t,e){switch(e){case"gexf":case"brackets":return`[${t.map(nx).join(", ")}]`;case"pipe":return t.join("|");case"comma":return t.join(",");case"semicolon":return t.join(";");default:{const n=e;throw new N("E_UNSUPPORTED",`unknown list syntax ${n}`,{option:"listSyntax",found:n})}}}function fE(t){return t.length>=2&&t.startsWith("[")&&t.endsWith("]")}function QP(t,e){for(const n of e)if(t.includes(n))return n;return null}function Nc(t,e){return t.split(e).map(n=>n.trim())}function hE(t){const e=t.slice(1,-1),n=[],i=e.length;if(e.trim().length===0)return n;let r=0;for(;;){for(;r<i&&tx(e.charCodeAt(r));)r++;let s="";if(r<i&&(e[r]==='"'||e[r]==="'")){const l=ex(e,r);s=l.text,r=l.end}let o=e.indexOf(",",r);if(o<0&&(o=i),s+=e.slice(r,o).trim(),n.push(s),r=o,r>=i)return n;if(r++,e.slice(r).trim().length===0)return n.push(""),n}}function ex(t,e){const n=t[e],i=t.length;let r="",s=e+1;for(;s<i;)if(t[s]!==n)r+=t[s],s++;else if(t[s+1]===n)r+=n,s+=2;else return{text:r,end:s+1};return{text:r,end:s}}function tx(t){return t===32||t===9||t===13||t===10}function nx(t){return t.length===0||/[,[\]"']/.test(t)||t!==t.trim()?`"${t.replaceAll('"','""')}"`:t}const ix=Zt,ec=ln,rf=1024;function ga(t){const e=[],n=t.listSyntax??"gexf";let i=rx(t,e);const{name:r,renamed:s}=cx(t);s&&e.push({category:"coercion",code:ec,message:`attribute "${t.title??t.id??""}" renamed to "${r}": the name was taken`});const o={name:r,dtype:i.dtype,nullable:!0,origin:{format:t.format,id:t.id,title:t.title!==null&&t.title!==r?t.title:null,type:t.type,namespace:t.namespace??null}};i.list&&(o.itemDtype=i.itemDtype??"string"),t.role!==void 0&&t.role!==null&&(o.role=t.role),t.dynamic===!0&&(o.dynamic=!0);const l=t.optionsText??null;l!==null&&(i=sx(o,i,l,n,e));const a=t.defaultText??null;if(a!==null)try{o.default=ma(a,i,n)}catch(d){e.push({category:"validation-error",code:Ho,message:`default "${a}" of attribute "${r}" does not parse as ${i.declared}: ${iT(d)}`})}const c=i.temporal!==null&&!i.list?JA(r):null;return{decl:o,spec:i,listSyntax:n,companion:c,renamed:s,issues:e}}function rx(t,e){if(t.type===null)return uE(null);const n=yy(t.format,t.type,t.long);return n!==null?n:(e.push({category:"unsupported",code:ix,message:`${t.format} type "${t.type}" is not supported; values kept as text`}),uE(t.type))}function sx(t,e,n,i,r){try{const s=pa(n,i).map(o=>Wp(o,e));if(t.options=s,e.dtype==="string"&&!e.list&&s.every(o=>typeof o=="string"))return t.dtype="dict",{...e,dtype:"dict"}}catch(s){r.push({category:"validation-error",code:SA,message:`options "${n}" of attribute "${t.name}" do not parse as ${e.declared}: ${iT(s)}`})}return e}function ma(t,e,n){return e.list?pa(t,n).map(i=>Wp(i,e)):Wp(t,e)}function zp(t,e){if(e.temporal===null||e.list)throw new N("E_COLUMN_TYPE",`"${e.declared}" is not a scalar temporal type`,{declared:e.declared});return Ro(t.trim(),e.temporal)}const ox=/^[+-]?\d+$/;function Qd(t,e){if(!t.precision)return!1;const n=e.trim();if(!ox.test(n))return!1;const i=Number(n);return!Number.isFinite(i)||BigInt(n)!==BigInt(i)}function Lo(t,e,n){return e==="node"?t.declareNodeColumn(n):t.declareEdgeColumn(n)}function he(t,e,n,i,r){let s=n,o=!1,l=!1;for(;;)try{return{handle:Lo(t,e,s),decl:s,renamed:o,roleDropped:l}}catch(a){if(!(a instanceof N))throw a;if(a.code==="E_COLUMN_EXISTS"&&!o){s=lx(t,e,s,i,r),o=!0;continue}if(a.code==="E_DUPLICATE_ROLE"&&s.role!==void 0&&!l){s=ax(a,e,s,s.role,i,r),l=!0;continue}throw a}}function lx(t,e,n,i,r){const s=eu(t,e),o=n.origin?.id??null,l=Xt(n.name,o,s);return i.warning("coercion",ln,`${e} column "${n.name}" renamed to "${l}": the sink already holds that name with another shape`,{...r,element:r?.element??n.name}),{...n,name:l}}function ax(t,e,n,i,r,s){const o=typeof t.details.holder=="string"?t.details.holder:"another column";r.warning("coercion",bn,`${e} column "${n.name}" loses the ${i} role: "${o}" already holds it`,{...s,element:s?.element??n.name});const{role:l,...a}=n;return a}function wy(t,e,n,i){try{return Lo(t,e,n)}catch(r){if(r instanceof N&&r.code==="E_DUPLICATE_ROLE"){i?.warnOnce("coercion",bn,`${e} column "${n.name}" is declared without the timeText role: another companion holds it (exporters use extra.for)`,{element:n.name});const{role:s,...o}=n;return Lo(t,e,o)}throw r}}function eu(t,e){return n=>(e==="node"?t.nodeColumn(n):t.edgeColumn(n))!==A}function Xt(t,e,n){if(!n(t))return t;const i=e===null?t:`${t}#${e}`;if(e!==null&&!n(i))return i;for(let r=2;;r++){const s=`${i}#${r}`;if(!n(s))return s}}class no{constructor(e=rf){this.distinct=new Set,this.rowsSeen=0,this.sampleRows=e}get rows(){return this.rowsSeen}get distinctCount(){return this.distinct.size}get decided(){return this.rowsSeen>=this.sampleRows}observe(e){return this.rowsSeen++,this.distinct.size<this.rowsSeen&&this.distinct.add(e),this.rowsSeen===this.sampleRows}decide(){return this.rowsSeen>0&&this.distinct.size*2<this.rowsSeen?"dict":"string"}}function cx(t){const e=t.title!==null&&t.title.length>0?t.title:t.id;if(e===null||e.length===0)throw new N("E_COLUMN_TYPE","an attribute declaration needs a title or an id",{field:"name",format:t.format});if(t.taken===void 0)return{name:e,renamed:!1};const n=Xt(e,t.id,t.taken);return{name:n,renamed:n!==e}}function Wp(t,e){return XP(t,e.kind,e.temporal)}function iT(t){return t instanceof Error?t.message:String(t)}const dx=/^-?(0|[1-9]\d*)$/;function tc(t){if(t!=="-0"&&dx.test(t)){const e=Number(t);if(Number.isSafeInteger(e))return e}return t}function tu(t){return typeof tc(t)=="number"}function sf(t,e){switch(e){case"keep":case"string":return t;case"canonical":return tc(t);case"number":{if(t.trim().length===0)throw nu(t,"empty text is not a number");const n=Number(t);if(!Number.isFinite(n))throw nu(t,"not a finite number");return n}default:{const n=e;throw new N("E_UNSUPPORTED",`unknown id coercion ${n}`,{option:"ids",found:n})}}}function ux(t,e){if(typeof t=="string")return sf(t,e);if(typeof t=="number"){if(!Number.isFinite(t))throw nu(t,"not a finite number");return e==="string"?String(t):t}if(e==="string"&&(typeof t=="boolean"||typeof t=="bigint"||t===null))return String(t);throw nu(t,`a ${t===null?"null":typeof t} is not an id under ids: "${e}"`)}function nu(t,e){const n=typeof t=="string"||typeof t=="number"?t:typeof t;return new N("E_INVALID_ID",`invalid node id ${JSON.stringify(n)}: ${e}`,{reason:e,value:typeof t=="bigint"?t.toString():t})}class Mn{constructor(e){this.mergeCount=0,this.lastMerge=null,this.mode=e,this.firstText=e==="number"?new Map:null}text(e){const n=sf(e,this.mode);if(this.lastMerge=null,this.firstText!==null&&typeof n=="number"){const i=this.firstText.get(n);i===void 0?this.firstText.set(n,e):i!==e&&(this.mergeCount++,this.lastMerge={id:n,text:e,previousText:i})}return n}value(e){return typeof e=="string"?this.text(e):(this.lastMerge=null,ux(e,this.mode))}}const fx=new Set(["keep","canonical","string","number"]),hx=new Set(["id","label","index"]),px=new Set(["keep","error","first","last","sum","min","max"]),gx=new Set(["keep","drop","error"]),mx=new Set(["expand","directed","undirected","error"]),yx=new Set(["error","directed","undirected"]),bx=new Set(["f32","f64"]),Ex=new Set(["f64","string"]),wx=new Set(["error","skip","star","clique"]),_x=new Set(["error","mangle"]),Sx=100,rT=["addMissingNodes","duplicateEdges","selfLoops","weightDtype"];function _t(t,e,n,i=!1){if(e===void 0)return 0;let r=0;for(const s of rT){const o=e[s],l=t.options[s];o===void 0||o===l||s==="addMissingNodes"&&i&&o===!1||(n.warning("coercion",Ln,`option ${s}: ${JSON.stringify(o)} requested but the sink uses ${JSON.stringify(l)}; the sink's setting applies`,{element:s}),r++)}return r}const Ox=["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","hyperedges"],Nx={nodeIdFrom:"id",duplicateEdges:"keep",selfLoops:"keep",onMixedDirection:"expand",weightDtype:"f64",long:"f64",restoreMangledIds:!0,hyperedges:"skip"};function St(t,e,n){if(t===void 0)return 0;let i=0;for(const r of Ox){if(n.has(r)||rT.includes(r))continue;const s=t[r];s===void 0||s===Nx[r]||(e.warning("unsupported",Jt,`option ${r}: ${JSON.stringify(s)} has no effect on the ${e.format} importer`,{element:r}),i++)}return i}function io(t){return t?.graphIndex!==void 0||t?.graphName!==void 0}function pE(t){const e=t.slice(0,10).map((i,r)=>`${r} ${i===null?"(unnamed)":JSON.stringify(i)}`),n=t.length>e.length?`, and ${t.length-e.length} more`:"";return`; the file holds ${e.join(", ")}${n}`}function ml(t,e,n){const{graphIndex:i,graphName:r}=e??{};if(i!==void 0&&(typeof i!="number"||!Number.isInteger(i)||i<0))throw new N("E_UNSUPPORTED",`option graphIndex: ${Vi(i)} is not a non-negative integer`,{option:"graphIndex",found:i});if(r!==void 0&&typeof r!="string")throw new N("E_UNSUPPORTED",`option graphName: ${Vi(r)} is not a string`,{option:"graphName",found:r});if(i!==void 0&&r!==void 0)throw new N("E_UNSUPPORTED","options graphIndex and graphName both choose a graph; pass one",{option:"graphName",found:r});if(t.length===0)return n.fail(ls,"the input holds no graph");if(r!==void 0){const o=t.flatMap((l,a)=>l===r?[a]:[]);return o.length>1?n.fail(as,`graphName ${JSON.stringify(r)} names the graphs at indexes ${o.join(", ")}; pass graphIndex`,{element:r}):o.length===0?n.fail(Nr,`graphName ${JSON.stringify(r)} names none of the ${t.length} graph${O(t.length)}${pE(t)}`,{element:r},{names:[...t]}):o[0]}const s=i??0;return s>=t.length?n.fail(Nr,`graphIndex ${s} is beyond the ${t.length} graph${O(t.length)}${pE(t)}`):s}function tt(t,e){const n=t??{};return Object.freeze({ids:vi("ids",n.ids,e.ids,fx),nodeIdFrom:vi("nodeIdFrom",n.nodeIdFrom,"id",hx),addMissingNodes:wh("addMissingNodes",n.addMissingNodes,e.addMissingNodes??!0),duplicateEdges:vi("duplicateEdges",n.duplicateEdges,"keep",px),selfLoops:vi("selfLoops",n.selfLoops,"keep",gx),onMixedDirection:vi("onMixedDirection",n.onMixedDirection,"expand",mx),defaultDirected:wh("defaultDirected",n.defaultDirected,e.defaultDirected),weightFrom:Ax(n.weightFrom,e.weightFrom),weightDtype:vi("weightDtype",n.weightDtype,"f64",bx),long:vi("long",n.long,"f64",Ex),restoreMangledIds:wh("restoreMangledIds",n.restoreMangledIds,!0),hyperedges:vi("hyperedges",n.hyperedges,"skip",wx),errorLimit:Tx(n.errorLimit),signal:Ix(n.signal),onProgress:$x(n.onProgress),encoding:Cx(n.encoding)})}function ft(t){const e=t??{};return Object.freeze({sanitizeIds:vi("sanitizeIds",e.sanitizeIds,"error",_x),onMixedDirection:vi("onMixedDirection",e.onMixedDirection,"error",yx)})}function vi(t,e,n,i){if(e===void 0)return n;if(typeof e!="string"||!i.has(e))throw new N("E_UNSUPPORTED",`option ${t}: ${Vi(e)} is not one of ${Dx(i)}`,{option:t,found:e,supported:[...i]});return e}function wh(t,e,n){if(e===void 0)return n;if(typeof e!="boolean")throw new N("E_UNSUPPORTED",`option ${t}: ${Vi(e)} is not a boolean`,{option:t,found:e});return e}function Ax(t,e){if(t===void 0)return e;if(t===null||typeof t=="string"&&t.length>0)return t;throw new N("E_UNSUPPORTED",`option weightFrom: ${Vi(t)} is not an attribute name or null`,{option:"weightFrom",found:t})}function Tx(t){if(t===void 0)return Sx;if(typeof t=="number"&&t>=0&&(Number.isInteger(t)||t===1/0))return t;throw new N("E_UNSUPPORTED",`option errorLimit: ${Vi(t)} is not a non-negative integer or Infinity`,{option:"errorLimit",found:t})}function Ix(t){if(t==null)return null;if(typeof t=="object"&&typeof t.aborted=="boolean")return t;throw new N("E_UNSUPPORTED",`option signal: ${Vi(t)} is not an AbortSignal`,{option:"signal",found:typeof t})}function $x(t){if(t==null)return null;if(typeof t=="function")return t;throw new N("E_UNSUPPORTED",`option onProgress: ${Vi(t)} is not a function`,{option:"onProgress",found:typeof t})}function Cx(t){if(t==null)return null;const e=typeof t=="string"?Yl(t):null;if(e===null)throw new N("E_UNSUPPORTED",`option encoding: ${Vi(t)} is not an encoding this platform's TextDecoder knows`,{option:"encoding",found:t});return e}const vx=Object.freeze({csv:Object.freeze(["gephi","generic"]),json:Object.freeze(["node-link","d3","jgf","cytoscape","graphology","vis","obographs"])});function sT(t,e){return typeof e=="string"&&Object.entries(vx).some(([n,i])=>n!==t&&i.includes(e))}function Vi(t){switch(typeof t){case"string":return JSON.stringify(t);case"number":case"boolean":return String(t);default:return t===null?"null":typeof t}}function Dx(t){return[...t].map(e=>JSON.stringify(e)).join(", ")}const kx=1;function _y(t,e){return e!==null&&t===e}function Kn(t,e){const n=t.trim();if(n.length===0)return;let i;try{i=by(n)}catch(r){throw iu(t,r)}if(Number.isNaN(i))throw iu(t,null);return e!==void 0&&oT(n,i,e),i}function oT(t,e,n){!Number.isSafeInteger(e)&&Number.isFinite(e)&&/^[+-]?\d+$/.test(t)&&BigInt(t)!==BigInt(e)&&n.warnOnce("precision",re,`edge weights: integers beyond 2^53 are stored as the nearest double (first: ${t})`,void 0,`${re}:edge weight`)}function of(t){if(t!=null){if(typeof t=="number"){if(Number.isNaN(t))throw iu(t,null);return t}if(typeof t=="string")return Kn(t);throw iu(t,null)}}function iu(t,e){let n;switch(typeof t){case"string":n=JSON.stringify(t);break;case"number":n=String(t);break;default:n=typeof t}return new N("E_INVALID_WEIGHT",`invalid edge weight ${n}`,{value:typeof t=="object"?typeof t:t,cause:e instanceof Error?e.message:null})}const gE="-0",Rx=new Set(["f32","f64","i32","u32","u8"]);function Lx(t){switch(t){case"f32":return ct;case"f64":return Fe;default:return Ge}}function Ot(t){const e=t.edges.byRole("weight"),n=e!==null&&Rx.has(e.dtype)?e:null;if(n!==null){const r=n.dtype==="f32"?"f32":"f64",s=Lx(n.dtype);return{weighted:!0,dtype:r,isExplicit:o=>n.isSet(o),value:o=>n.value(o),text:(o,l=!1)=>{if(!n.isSet(o))return null;const a=n.value(o);return Object.is(a,-0)?gE:l&&Number.isInteger(a)?Ge(a):s(a)}}}const{weights:i}=t.edgeList();return i===null||!t.flags.weighted?{weighted:!1,dtype:"f32",isExplicit:()=>!1,value:()=>kx,text:()=>null}:{weighted:!0,dtype:"f32",isExplicit:()=>!0,value:r=>i[r],text:(r,s=!1)=>{const o=i[r];return Object.is(o,-0)?gE:s&&Number.isInteger(o)?Ge(o):ct(o)}}}const Px="E_ID_CHARSET",w=Object.freeze({COLUMN_DROPPED:zL,MIXED_DIRECTION:"W_MIXED_DIRECTION",MIXED_DIRECTION_ERROR:Or,MULTI_EDGES:"W_MULTI_EDGES",SELF_LOOPS:"W_SELF_LOOPS",EDGE_IDS_GENERATED:"W_EDGE_IDS_GENERATED",EDGE_IDS_DROPPED:"W_EDGE_IDS_DROPPED",ID_MANGLED:"W_ID_MANGLED",ID_CHARSET:Px,ID_RENUMBERED:"W_ID_RENUMBERED",DTYPE:"W_DTYPE_UNSUPPORTED",COMPONENTS:"W_COMPONENTS_FLATTENED",LIST:"W_LIST_UNSUPPORTED",JSON:"W_JSON_UNSUPPORTED",DEFAULT:"W_DEFAULT_DROPPED",OPTIONS:"W_OPTIONS_DROPPED",HIERARCHY:"W_HIERARCHY_DROPPED",TEMPORAL:NA,TEMPORAL_TEXT:$A,ROLE:oy,PARENTS:ly,MUTUAL_EXPANDED:AA,MUTUAL_AS_UNDIRECTED:TA,ID_TEXT_TYPE:cs,ID_TEXT_COLLISION:IA,WEIGHT_KEY_CLASH:CA,ROLE_ASSUMED:Qa,COLUMN_NAME_CHANGED:vA,EMPTY_COLUMN:ay,STORAGE_CLASS:DA,INTEGRAL_F64:qL,TEXT_INFERRED:JL,XML_ILLEGAL_CHAR:Yd,OPTIONS_GAINED:ZL,SPELLS:"W_SPELLS_DROPPED",DYNAMIC_VALUES:"W_DYNAMIC_VALUES_DROPPED",OPEN_INTERVAL:"W_OPEN_INTERVAL",GRAPH_ATTRIBUTES:"W_GRAPH_ATTRIBUTES_DROPPED",POSITIONS:"W_POSITIONS_DROPPED",VIZ:"W_VIZ_DROPPED",EXTENSION_TABLE:"W_EXTENSION_TABLE_DROPPED",NONFINITE_AS_NULL:fy,WEIGHTS_DROPPED:XL}),xx=Object.freeze({mixedDirection:!1,multiEdges:!1,selfLoops:!1,edgeIds:"none",idCharset:"any",dtypes:Object.freeze([]),components:!1,lists:!1,json:!1,defaults:!1,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!1,positions:!1,viz:!1});function Je(t){return Object.freeze({...xx,...t,dtypes:Object.freeze([...t.dtypes??[]])})}const Mx=new Set(["directed","pair","mutual","weight","originalId"]),Ux=new Set(["color","size","shape","thickness"]),Gx=new Set(["start","end","timestamp","timestamps"]),jx=new Set(["parent","parents"]);function Un(t,e,n,i={}){const r=[],s=(d,u,f=null,h=null)=>{r.push(Object.freeze({code:d,message:u,column:f,count:h}))},o=i.tables??["node","edge","graph"],l=o.includes("edge");l&&Fx(t,e,n,s);const a=lT(t,e.idCharset);if(a>0&&(e.idCharset==="dense-1-based"?s(w.ID_RENUMBERED,n.sanitizeIds==="mangle"?`${a} node id${O(a)} ${C(a,"is","are")} not their 1-based index; nodes are numbered 1..N, the original ids are written too, and an import with restoreMangledIds: true reads them back as the ids; they are also the labels of nodes without a label value`:`${a} node id${O(a)} ${C(a,"is","are")} not their 1-based index; nodes are numbered 1..N and ids kept as labels of the nodes without a label value (a node with one loses its id)`,null,a):n.sanitizeIds==="mangle"?s(w.ID_MANGLED,`${a} node id${O(a)} ${Bp(e.idCharset,a)}, so they are rewritten; the original ids are written too, and an import with restoreMangledIds: true reads them back`,null,a):s(w.ID_CHARSET,`${a} node id${O(a)} ${Bp(e.idCharset,a)}, so the save fails unless sanitizeIds is "mangle"`,null,a)),i.idsReadBack!==void 0){let d=0;for(let u=0;u<t.nodeCount;u++){const f=t.ids.idOf(u);sf(String(f),i.idsReadBack)!==f&&d++}d>0&&s(w.ID_TEXT_TYPE,`${d} node id${O(d)} ${C(d,"reads","read")} back with another type (a number as text, or text as a number)`,null,d)}l&&Bx(t,i,s),o.includes("node")&&_h(t.nodes,"node",e,i,s),l&&_h(t.edges,"edge",e,i,s);const c=o.includes("graph")?t.graph.names():[];c.length>0&&(e.graphAttributes?_h(t.graph,"graph",e,i,s):r.push(Object.freeze({code:w.GRAPH_ATTRIBUTES,message:`${c.length} graph attribute${O(c.length)} cannot be written`,column:null,count:c.length,columns:Object.freeze([...c])})));for(const[d,u]of t.extensions){const[,f]=d.split(":"),h=d.startsWith("temporal:")&&(f==="node"||f==="edge")?f:"graph";o.includes(h)&&(d.startsWith("temporal:")?e.temporal!=="dynamic-values"&&s(w.DYNAMIC_VALUES,`dynamic values of "${d}" (${u.rowCount} row${O(u.rowCount)}) cannot be written`,d,u.rowCount):s(w.EXTENSION_TABLE,`extension table "${d}" (${u.rowCount} row${O(u.rowCount)}) cannot be written`,d,u.rowCount))}return r}function Fx(t,e,n,i){const r=yl(t);if(r>0&&!e.mixedDirection&&(n.onMixedDirection==="error"?i(w.MIXED_DIRECTION_ERROR,`${r} undirected edge${O(r)} in a directed graph, and the format holds one direction per file, so the save fails unless onMixedDirection is "directed" or "undirected"`,null,r):i(w.MIXED_DIRECTION,`${r} undirected edge${O(r)} in a directed graph ${C(r,"is","are")} written as ${n.onMixedDirection} (onMixedDirection), and the format holds one direction per file`,null,r)),t.flags.multigraph&&!e.multiEdges){const o=e2(t);i(w.MULTI_EDGES,`${o} parallel edge${O(o)}; the format has no parallel edges`,null,o)}t.selfLoopCount>0&&!e.selfLoops&&i(w.SELF_LOOPS,`${t.selfLoopCount} self-loop${O(t.selfLoopCount)}; the format has no self-loops`,null,t.selfLoopCount);const s=t.edges.byRole("id");e.edgeIds==="required"&&s===null&&t.edgeCount>0?i(w.EDGE_IDS_GENERATED,"the format requires edge ids, and the graph has none; the edges are written with generated ids, which read back as a new edge id column",null,t.edgeCount):e.edgeIds==="none"&&s!==null&&i(w.EDGE_IDS_DROPPED,`edge id column "${s.meta.name}" cannot be written`,s.meta.name,t.edgeCount)}function Bp(t,e){const n=C(e,"is","are");switch(t){case"nmtoken":return`${n} not XML name tokens (letters, digits and . - _ : only; no spaces)`;case"integer":return`${n} not integers`;default:return`cannot be written as ${t} ids`}}function zx(t,e){return t==="node"?e.nodeRoleNames??e.roleNames:t==="edge"?e.edgeRoleNames??e.roleNames:e.roleNames}function Wx(t,e){return t==="node"?e.nodeAttributes??e.attributes:t==="edge"?e.edgeAttributes??e.attributes:e.attributes}function Bx(t,e,n){e.weights===!1&&Ot(t).weighted&&n(w.WEIGHTS_DROPPED,`the edge weights are not written; ${t.edgeCount} edge${O(t.edgeCount)} ${C(t.edgeCount,"reads","read")} back with weight 1`,null,t.edgeCount)}const Hx={label:"labels",weight:"weights",id:"ids",position:"positions",originalId:"original ids"};function gi(t){return t.length-t.nullCount}function _h(t,e,n,i,r){const s={domain:e,caps:n,extras:i,note:r};for(const o of t)Vx(o,s)}function Vx(t,e){const{name:n,role:i}=t.meta;if(i!==null&&Mx.has(i))return;const r=`${e.domain} column "${n}"`;if(Yx(t,r,e),e.domain==="edge"&&i==="id")return;if(Kx(t,e)){e.note(w.COLUMN_DROPPED,`${r} is not written`,n,gi(t));return}const s=i===null?void 0:Xx.find(([o])=>o(i));if(s!==void 0){s[1](t,r,e);return}Zx(t,r,e)}function Yx(t,e,n){const{name:i,role:r}=t.meta,s=r===null?void 0:zx(n.domain,n.extras)?.[r];r!==null&&s!==void 0&&s!==i&&n.note(w.COLUMN_NAME_CHANGED,`${e} (the ${Hx[r]??r}) is written as the format's own ${r} and reads back as "${s}"`,i,gi(t))}function Kx(t,e){const{name:n,role:i}=t.meta,{domain:r,extras:s}=e,o=s.writtenColumns?.[r]?.includes(n)??!1,l=i!==null&&(s.roles?.has(i)??!1);return Wx(r,s)===!1&&!o&&!l}const Xx=[[t=>t==="timeText",(t,e,n)=>{n.extras.temporalText!==!0&&n.note(w.TEMPORAL_TEXT,`${e} (the original text of a date or time column) cannot be written`,t.meta.name,gi(t))}],[t=>t==="position",qx],[t=>Ux.has(t),Jx],[t=>jx.has(t),(t,e,n)=>{if(!n.caps.hierarchy){const{name:i,role:r}=t.meta;n.note(w.HIERARCHY,`${e} (${String(r)}) cannot be written`,i,gi(t))}}],[t=>Gx.has(t),(t,e,n)=>{if(n.caps.temporal==="none"){const{name:i,role:r}=t.meta;n.note(w.TEMPORAL,`${e} (${String(r)}) cannot be written`,i,gi(t))}}],[t=>t==="spells",(t,e,n)=>{n.caps.temporal!=="spells"&&n.caps.temporal!=="dynamic-values"&&n.note(w.SPELLS,`${e} (spells) cannot be written`,t.meta.name,gi(t))}],[t=>t==="open"||t==="spellsOpen",(t,e,n)=>{n.extras.openIntervals!==!0&&n.note(w.OPEN_INTERVAL,`${e} (open intervals) cannot be written`,t.meta.name,gi(t))}]];function qx(t,e,n){const{caps:i,extras:r,note:s}=n,{meta:o}=t;i.positions?r.positionDtype!==void 0&&o.dtype!==r.positionDtype&&s(w.DTYPE,`${e} (positions) is ${o.dtype}; the format reads positions back as ${r.positionDtype}`,o.name,gi(t)):s(w.POSITIONS,`${e} (positions) cannot be written`,o.name,gi(t))}function Jx(t,e,n){const{caps:i,extras:r,note:s}=n;if(i.viz)return;const{name:o}=t.meta,l=String(t.meta.role);s(w.VIZ,r.vizAsAttributes===!0?`${e} (${l}) is written as a plain attribute; the format has no ${l} slot and the role is lost on re-import`:`${e} (${l}) cannot be written`,o,gi(t))}function Zx(t,e,n){const{caps:i,extras:r,note:s}=n,{meta:o}=t,{name:l,role:a}=o;a!==null&&!(r.roles?.has(a)??!1)&&s(w.ROLE,`${e} (${a}) is written as a plain attribute; the format has no ${a} slot and the role is lost`,l,gi(t)),o.dynamic&&i.temporal!=="dynamic-values"&&s(w.DYNAMIC_VALUES,`${e} is dynamic; only its static value can be written`,l,null),Qx(t,e,i,s),o.default!==void 0&&!i.defaults&&s(w.DEFAULT,`${e} declares a default; the format has no defaults`,l,null),o.options!==null&&!i.options&&s(w.OPTIONS,`${e} declares options; the format has no enumerations`,l,null)}function Qx(t,e,n,i){const{meta:r}=t,{name:s}=r,o=t.length-t.nullCount;switch(r.dtype){case"list":n.lists?r.itemDtype!==null&&!n.dtypes.includes(r.itemDtype)?i(w.DTYPE,`${e} holds ${r.itemDtype} items; the format cannot keep that dtype`,s,o):r.itemDtype==="dict"&&i(w.DTYPE,`${e} holds dict items; list items read back as string`,s,o):i(w.LIST,`${e} is a list; the format has no lists`,s,o);break;case"json":n.json||i(w.JSON,`${e} holds nested values; the format has no nested values`,s,o);break;default:n.dtypes.includes(r.dtype)||i(w.DTYPE,`${e} is ${r.dtype}; the format cannot keep that dtype`,s,o),r.components>1&&!n.components&&i(w.COMPONENTS,`${e} has ${r.components} components; the format has no strides`,s,o);break}}function yl(t){if(!t.directed)return 0;const e=t.edges.byRole("directed");if(e?.dtype!=="bool")return 0;const n=t.edges.byRole("pair");let i=0,r=0;for(let s=0;s<t.edgeCount;s++)e.isSet(s)&&e.value(s)===!1&&(i++,n!==null&&n.dtype==="u32"&&n.isSet(s)&&n.data[s]!==A&&r++);return r/2+(i-r)}function e2(t){const{rowPtr:e,colIdx:n,nodeCount:i}=t;let r=0;for(let s=0;s<i;s++)for(let o=e[s]+1;o<e[s+1];o++)n[o]===n[o-1]&&r++;return t.directed?r:Math.ceil(r/2)}const t2=[[45,46],[48,58],[65,90],[95,95],[97,122],[183,183],[192,214],[216,246],[248,893],[895,8191],[8204,8205],[8255,8256],[8304,8591],[11264,12271],[12289,55295],[63744,64975],[65008,65533],[65536,983039]];function bl(t){for(const[e,n]of t2){if(t<e)return!1;if(t<=n)return!0}return!1}function El(t){if(t.length===0)return!1;for(const e of t){const n=e.codePointAt(0);if(n===void 0||!bl(n))return!1}return!0}function Hp(t,e){switch(e){case"any":return!0;case"nmtoken":return El(String(t));case"integer":return typeof t=="number"&&Number.isSafeInteger(t);case"dense-1-based":return!1;default:{const n=e;throw new N("E_UNSUPPORTED",`unknown id charset ${n}`,{charset:n})}}}function lT(t,e){const{ids:n}=t;if(e==="any")return 0;if(e==="dense-1-based"){if(n.kind==="identity"&&n.offset===1)return 0;let r=0;for(let s=0;s<n.size;s++)n.idOf(s)!==s+1&&r++;return r}let i=0;for(let r=0;r<n.size;r++)Hp(n.idOf(r),e)||i++;return i}function wl(t,e,n){const{ids:i}=t,r=i.size;if(e==="dense-1-based"){const a=lT(t,e);return{charset:e,changed:a,idAt:c=>c+1,isChanged:c=>i.idOf(c)!==c+1,originalAt:c=>i.idOf(c)}}const s={charset:e,changed:0,idAt:a=>i.idOf(a),isChanged:()=>!1,originalAt:a=>i.idOf(a)};if(e==="any")return s;const o=[];for(let a=0;a<r;a++)Hp(i.idOf(a),e)||o.push(a);if(o.length===0)return s;if(n==="error"){const a=i.idOf(o[0]);throw new N("E_INVALID_ID",`${o.length} node id${O(o.length)} ${Bp(e,o.length)} (first: ${JSON.stringify(a)} at index ${o[0]}); pass sanitizeIds: "mangle" to rewrite them`,{reason:"charset",charset:e,count:o.length,id:a,index:o[0]})}const l=new Map;if(e==="nmtoken"){const a=new Set;for(let c=0;c<r;c++){const d=i.idOf(c);Hp(d,e)&&a.add(String(d))}for(const c of o){const d=aT(String(i.idOf(c)));let u=d;for(let f=2;a.has(u);f++)u=`${d}_${f}`;a.add(u),l.set(c,u)}}else{const a=new Set;for(let d=0;d<r;d++){const u=i.idOf(d);typeof u=="number"&&Number.isSafeInteger(u)&&a.add(u)}let c=0;for(const d of o){for(;a.has(c);)c++;a.add(c),l.set(d,c),c++}}return{charset:e,changed:o.length,idAt:a=>l.get(a)??i.idOf(a),isChanged:a=>l.has(a),originalAt:a=>i.idOf(a)}}function aT(t){let e="";for(const n of t){const i=n.codePointAt(0);e+=i!==void 0&&bl(i)?n:"_"}return e.length===0?"_":e}const cT=/^-?(0|[1-9]\d*)$/,n2=/^[+-]?((0|[1-9]\d*)(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,i2=-2147483648,r2=2147483647;function dT(t){let e=t.length;for(;e>0&&t[e-1]==="0";)e--;return t.slice(0,e)}function qn(t){if(t==="true"||t==="false")return"bool";if(cT.test(t)){const e=Number(t);return e>=i2&&e<=r2?"i32":Number.isFinite(e)?"f64":"string"}return n2.test(t)&&Number.isFinite(Number(t))?"f64":"string"}function lf(t){switch(qn(t)){case"bool":return t==="true";case"i32":case"f64":return Number(t);case"string":return t;default:return t}}function ci(t){const e=qn(t);return e==="i32"||e==="f64"}function s2(t,e){return String(e)===t}function Ac(t){switch(t){case"bool":return 0;case"i32":return 1;case"f64":return 2;case"string":return 3;default:{const e=t;throw new N("E_UNSUPPORTED",`unknown text dtype ${e}`,{dtype:e})}}}class Sy{constructor(e,n,i,r){this.handle=A,this.textDtype=null,this.valueDtype=null,this.keptRows=[],this.keptTexts=[],this.name=e,this.domain=n,this.sink=i,this.report=r}get column(){return this.handle}write(e,n){const i=qn(n),r=lf(n);this.warnIfImprecise(n,r);const s=this.textDtype==="string",o=this.textDtype===null||Ac(i)>Ac(this.textDtype)?i:this.textDtype;this.set(e,o==="string"?n:r),this.textDtype=o;const l=o2(r);if((this.valueDtype===null||Ac(l)>Ac(this.valueDtype))&&(this.valueDtype=l),this.textDtype==="string"){if(!s&&this.keptRows.length>0){for(let a=0;a<this.keptRows.length;a++)this.set(this.keptRows[a],this.keptTexts[a]);this.keptRows.length=0,this.keptTexts.length=0}return}typeof r=="number"&&!s2(n,r)&&(this.keptRows.push(e),this.keptTexts.push(n)),this.textDtype==="f64"&&this.valueDtype!=="f64"&&this.widen("f64")}warnIfImprecise(e,n){typeof n=="number"&&!Number.isSafeInteger(n)&&cT.test(e)&&BigInt(e)!==BigInt(n)&&this.report.warnOnce("precision",re,`${this.domain} column "${this.name}": integers beyond 2^53 are stored as the nearest double (first: ${e})`,{element:this.name},`${re}:${this.domain}:${this.name}`)}set(e,n){if(this.handle===A){this.domain==="node"?(this.sink.setNodeValue(this.name,e,n),this.handle=this.sink.nodeColumn(this.name)):(this.sink.setEdgeValue(this.name,e,n),this.handle=this.sink.edgeColumn(this.name));return}this.domain==="node"?this.sink.setNodeValue(this.handle,e,n):this.sink.setEdgeValue(this.handle,e,n)}widen(e){const{sink:n}=this;if(!(this.domain==="node"?n.widenNodeColumn!==void 0:n.widenEdgeColumn!==void 0)){this.report.warnOnce("coercion",af,`column "${this.name}" holds ${e} text but the sink cannot widen an inferred column; it keeps the value-inferred dtype`,{element:this.name}),this.valueDtype=e;return}try{this.domain==="node"?n.widenNodeColumn?.(this.handle,e):n.widenEdgeColumn?.(this.handle,e),this.valueDtype=e}catch(r){if(!(r instanceof N)||r.code!=="E_COLUMN_TYPE")throw r;this.valueDtype=e}}}const af="W_WIDENING_UNSUPPORTED";function o2(t){return typeof t=="boolean"?"bool":typeof t=="string"?"string":Number.isInteger(t)&&t>=-2147483648&&t<=2147483647?"i32":"f64"}class l2{constructor(e,n,i,r,s,o){this.nodeCount=e,this.rowPtr=n,this.children=i,this.parentCount=r,this.edgeCount=i.length,this.dropped=s,this.column=o;let l=0;for(let d=0;d<e;d++)r[d]===0&&l++;const a=new Uint32Array(l);let c=0;for(let d=0;d<e;d++)r[d]===0&&(a[c++]=d);this.roots=a,this.unreachable=e-this.reachableCount()}childrenOf(e){return this.children.subarray(this.rowPtr[e],this.rowPtr[e+1])}childCount(e){return this.rowPtr[e+1]-this.rowPtr[e]}hasChildren(e){return this.rowPtr[e+1]>this.rowPtr[e]}parentCountOf(e){return this.parentCount[e]}isRoot(e){return this.parentCount[e]===0}isEmpty(){return this.edgeCount===0}depthFirst(){const e=this.nodeCount,n=new Uint32Array(e),i=new Uint32Array(e),r=new Uint8Array(e),s=[],o=[];let l=0,a=!1;const c=(u,f)=>{r[u]=1,u!==l&&(a=!0),n[l++]=u,i[u]=f},d=u=>{for(c(u,0),s.push(u),o.push(this.rowPtr[u]);s.length>0;){const f=s.length-1,h=s[f],p=o[f];if(p>=this.rowPtr[h+1]){s.pop(),o.pop();continue}o[f]=p+1;const g=this.children[p];r[g]!==1&&(c(g,s.length),s.push(g),o.push(this.rowPtr[g]))}};for(const u of this.roots)d(u);for(let u=0;u<e;u++)r[u]===0&&d(u);return{order:n,depth:i,reordered:a}}reachableCount(){const e=new Uint8Array(this.nodeCount),n=new Uint32Array(this.nodeCount);let i=0,r=0;for(const s of this.roots)for(e[s]=1,r++,n[i++]=s;i>0;){const o=n[--i];for(let l=this.rowPtr[o];l<this.rowPtr[o+1];l++){const a=this.children[l];e[a]===0&&(e[a]=1,r++,n[i++]=a)}}return r}}function nc(t,e={}){const n=u2(t,e.column===void 0?"auto":e.column);return a2(t.nodeCount,n)}function a2(t,e){const n=new Uint32Array(t+1),i=new Uint32Array(t);let r=0;const s=[];if(e!==null){const a=(d,u)=>{if(!Number.isInteger(u)||u===A||u>=t||u===d){r++;return}s.push(d,u),n[u+1]++,i[d]++},c=c2(e,Math.min(e.length,t),a);r+=c}for(let a=0;a<t;a++)n[a+1]+=n[a];const o=new Uint32Array(n[t]),l=n.slice(0,t);for(let a=0;a<s.length;a+=2)o[l[s[a+1]]++]=s[a];return new l2(t,n,o,i,r,e)}function c2(t,e,n){if(t.dtype==="u32"){const{data:i}=t;for(let r=0;r<e;r++)t.isSet(r)&&n(r,i[r]);return 0}if(t.dtype==="list")return d2(t,e,n);throw new TypeError(`a containment column must be u32 or a list of u32, found ${t.dtype} column "${t.meta.name}"`)}function d2(t,e,n){let i=0;for(let r=0;r<e;r++)if(t.isSet(r))for(const s of t.sliceOf(r))typeof s=="number"?n(r,s):i++;return i}function u2(t,e){return typeof e!="string"?e:e==="parent"||e==="parents"?t.nodes.byRole(e):t.nodes.byRole("parent")??t.nodes.byRole("parents")}const f2=64*1024;async function*ti(t,e=f2){const n=new TextEncoder;let i=[],r=0;for await(const s of t)s.length!==0&&(i.push(s),r+=s.length,r>=e&&(yield n.encode(i.length===1?i[0]:i.join("")),i=[],r=0));i.length>0&&(yield n.encode(i.length===1?i[0]:i.join("")))}async function ni(t){const e=[];for await(const n of t)e.push(n);return e.join("")}async function h2(t){const e=[];let n=0;for await(const s of t)e.push(s),n+=s.byteLength;const i=new Uint8Array(n);let r=0;for(const s of e)i.set(s,r),r+=s.byteLength;return i}function uT(t,e){if(t===void 0)return e;if(typeof t=="number"&&Number.isInteger(t)&&t>=0&&t<=16)return" ".repeat(t);if(typeof t=="string"&&/^[ \t]{0,16}$/.test(t))return t;throw new N("E_UNSUPPORTED",`option indent: ${typeof t=="string"||typeof t=="number"?JSON.stringify(t):typeof t} is not a number of spaces (0 to 16) or a string of spaces or tabs`,{option:"indent",found:typeof t=="string"||typeof t=="number"?t:typeof t})}const Oy="E_CSV_UNCLOSED_QUOTE",Ny="E_CSV_QUOTE",Ws=Object.freeze([","," ",";","|"," "]),Ay=10,mE=64*1024,Li=10,fr=13,fT=9,hT=32,p2=/^sep=([^\r\n])(?:\r\n|\n|\r|$)/i,gt=0,As=1,or=2,Kl=3,pd=4,Tc=5;function Ty(t){for(const[e,n]of[["delimiter",t.delimiter],["quote",t.quote]])if(n!==null&&(n.length!==1||n===`
|
|
4
|
+
`||n==="\r"))throw new N("E_UNSUPPORTED",`option ${e}: ${JSON.stringify(n)} is not a single non-line-break character`,{option:e,found:n});if(t.delimiter!==null&&t.delimiter===t.quote)throw new N("E_UNSUPPORTED","options delimiter and quote must differ",{option:"delimiter",found:t.delimiter});return t}function pT(t){return!t.includes(`
|
|
5
|
+
`)&&t.includes("\r")?"\r":`
|
|
6
|
+
`}function cf(t,e,n,i,r=!1,s=!1){const o=e.codePointAt(0),l=new g2(t,n,o,s&&o===hT,r);let a=0;for(;a<t.length&&l.rows.length<i;)if(a=l.step(a),a<0)return null;return l.rows.length<i&&l.finish(),l.rows}class g2{constructor(e,n,i,r,s){this.text=e,this.quote=n,this.delimiterCode=i,this.whitespace=r,this.strictQuotes=s,this.rows=[],this.cells=[],this.state=gt,this.segment=0,this.field="",this.quoteCode=n.codePointAt(0)}step(e){const n=this.text.codePointAt(e);if(this.state===or)return n===this.quoteCode&&(this.field+=this.text.slice(this.segment,e),this.state=Kl),e+1;const i=n===this.delimiterCode||this.whitespace&&n===fT;if(this.state===Kl){const r=this.afterQuote(e,n,i||n===Li||n===fr);if(r!==null)return r}if(i||n===Li||n===fr)return this.separator(e,i);if(this.state===gt){const r=n===this.quoteCode;this.state=r?or:As,this.segment=r?e+1:e}return e+1}afterQuote(e,n,i){return n===this.quoteCode?(this.field+=this.quote,this.segment=e+1,this.state=or,e+1):this.strictQuotes&&!i?-1:(this.state=pd,this.segment=e,null)}separator(e,n){(this.state===As||this.state===pd)&&(this.field+=this.text.slice(this.segment,e));let i=e+1;return n&&this.whitespace&&this.state===gt||(n?(this.cells.push(this.field),this.field="",this.state=gt):(this.endRow(),this.state=gt,this.text.codePointAt(e)===fr&&this.text.codePointAt(e+1)===Li&&(i=e+2))),this.segment=i,i}endRow(){this.state===gt&&this.cells.length===0||(this.whitespace&&this.state===gt||this.cells.push(this.field),this.rows.push(this.cells),this.cells=[],this.field="")}finish(){this.state===gt&&this.cells.length===0||((this.state===As||this.state===pd||this.state===or)&&(this.field+=this.text.slice(this.segment)),this.whitespace&&this.state===gt||this.cells.push(this.field),this.rows.push(this.cells))}}function gT(t,e){if(e.length===0)return t;let n=0;for(;n<t.length;){if(t[n]===`
|
|
7
|
+
`||t[n]==="\r"){n++;continue}if(!e.includes(t[n]))break;const i=t.indexOf(`
|
|
8
|
+
`,n),r=t.indexOf("\r",n),s=Math.min(i<0?1/0:i,r<0?1/0:r);if(s===1/0)return"";n=s}return n===0?t:t.slice(n)}function Iy(t,e=`
|
|
9
|
+
`,n=Ws,i='"',r=!1,s=!1){let o=null,l=1/0;const a=t.endsWith(`
|
|
10
|
+
`)||t.endsWith("\r");for(const c of n){if(c===i||c===e)continue;const d=cf(t,c,i,Ay,r,s);if(d===null)continue;let u=d.filter(p=>!y2(p));if(u.length>1&&!a&&(u=u.slice(0,-1)),u.length===0)continue;const{average:f,delta:h}=m2(u);f>1.99&&h<l&&(o=c,l=h)}return o}function m2(t){let e=0,n=0;for(let i=0;i<t.length;i++){const r=t[i].length;e+=r,i>0&&(n+=Math.abs(r-t[i-1].length))}return{average:e/t.length,delta:n}}function y2(t){return t.length===1&&t[0].trim().length===0}class mT{constructor(e,n,i,r){this.cells=[],this.quoted=[],this.leadingComments=[],this.leadingCommentLines=[],this.strayQuoteLine=0,this.sepDirective=!1,this.recordLine=0,this.input=e,this.report=n,this.readOptions=r,this.syntax=i,this.delimiterText=i.delimiter}get line(){return this.recordLine}get delimiter(){return this.delimiterText}async*[Symbol.asyncIterator](){const e=new E2(this);for await(const n of this.chunks()){e.setDelimiter((this.delimiterText??",").charCodeAt(0));let i=0;for(;i<n.length;)i=e.scan(n,i),e.ready&&(e.ready=!1,this.recordLine=e.recordLine,yield e.count,e.count=0);e.endChunk(n)}e.finish()&&(this.recordLine=e.recordLine,yield e.count)}badQuote(e,n){return this.report.fail(Ny,`text after the closing quote of quoted field ${n} (a quote inside a quoted field is written as two quotes)`,{line:e})}unclosedQuote(e){return this.report.fail(Oy,`a quoted field starting on line ${e} is never closed`,{line:e})}async*chunks(){const e=$r(this.input,this.report,this.readOptions);if(this.delimiterText!==null){yield*e;return}const n=[];let i=0,r=!1;const s=new b2((this.syntax.comments??[]).map(o=>o.codePointAt(0)));for await(const o of e){if(r){yield o;continue}if(n.push(o),i+=o.length,s.scan(o),s.breaks<Ay&&i<mE)continue;const l=n.join("");n.length=0,this.sniff(l),r=!0,yield l}if(!r){const o=n.join("");o.length>0&&(this.sniff(o),yield o)}}sniff(e){const n=e.slice(0,mE),i=gT(n,this.syntax.comments??[]);if(this.syntax.inspect!==void 0){const o=n.slice(0,n.length-i.length).match(/\r\n|\r|\n/g)?.length??0;this.syntax.inspect(i,o+1)}const r=this.syntax.sepDirective===!0?p2.exec(e):null;if(r!==null&&r[1]!==this.syntax.quote){this.delimiterText=r[1],this.sepDirective=!0;return}const s=this.syntax.candidates??Ws;this.delimiterText=Iy(i,pT(i),s,this.syntax.quote,this.syntax.skipQuoteErrors,this.syntax.collapseSpaces)??s[0]}}class b2{constructor(e){this.breaks=0,this.lastWasCr=!1,this.lineStart=!0,this.inComment=!1,this.commentCodes=e,this.leading=e.length>0}scan(e){for(let n=0;n<e.length&&this.breaks<Ay;n++){const i=e.charCodeAt(n);i===Li||i===fr?this.lineBreak(i):this.character(i),this.lastWasCr=i===fr}}lineBreak(e){!(e===Li&&this.lastWasCr)&&!this.inComment&&this.breaks++,this.inComment=!1,this.lineStart=!0}character(e){this.lineStart&&this.leading&&(this.inComment=this.commentCodes.includes(e),this.leading=this.inComment),this.lineStart=!1}}class E2{constructor(e){this.ready=!1,this.count=0,this.recordLine=1,this.startLine=1,this.delimiterCode=-1,this.collapse=!1,this.state=gt,this.field="",this.fieldQuoted=!1,this.line=1,this.lastWasCr=!1,this.comment="",this.segment=0,this.reader=e,this.quoteCode=e.syntax.quote.charCodeAt(0),this.quoteText=e.syntax.quote,this.commentCodes=(e.syntax.comments??[]).map(n=>n.charCodeAt(0)),this.leading=this.commentCodes.length>0}setDelimiter(e){this.delimiterCode<0&&(this.delimiterCode=e,this.collapse=e===hT&&this.reader.syntax.collapseSpaces===!0)}scan(e,n){const{delimiterCode:i}=this,r=e.length;let s=n;for(this.segment=n;s<r;){const o=e.charCodeAt(s),{state:l}=this;if(l===Tc){this.commentChar(e,s,o),s++;continue}if(l===or){s=this.quotedRun(e,s);continue}const a=o===i||this.collapse&&o===fT;if(l===Kl||a||o===Li||o===fr){if(s=this.boundary(e,s,o,a),this.ready)return s;continue}this.fieldChar(o,s),s++}return s}commentChar(e,n,i){i!==Li&&i!==fr||(this.comment=this.grow(this.comment,e.slice(this.segment,n)),this.reader.leadingComments.push(this.comment),this.reader.leadingCommentLines.push(this.line),this.comment="",this.state=gt,this.endLine(i),this.segment=n+1)}quotedRun(e,n){const i=e.indexOf(this.quoteText,n),r=i<0?e.length:i;return r>n&&this.countLineBreaks(e,n,r),i<0?e.length:(this.field=this.grow(this.field,e.slice(this.segment,i)),this.state=Kl,this.lastWasCr=!1,i+1)}boundary(e,n,i,r){if(this.state===Kl){if(i===this.quoteCode)return this.field=this.grow(this.field,this.quoteText),this.segment=n+1,this.state=or,this.lastWasCr=!1,n+1;!r&&i!==Li&&i!==fr&&this.reader.badQuote(this.startLine,this.count+1),this.state=pd,this.segment=n}return i===Li&&this.lastWasCr?(this.lastWasCr=!1,this.segment=n+1,n+1):(this.state===As&&(this.field=this.grow(this.field,e.slice(this.segment,n))),r?(this.collapse&&this.state===gt||(this.push(),this.state=gt),this.lastWasCr=!1,this.segment=n+1,n+1):(this.lineEnd(i),this.segment=n+1,n+1))}lineEnd(e){this.state===gt&&(this.count===0||this.collapse)||this.push(),this.count>0&&(this.ready=!0,this.recordLine=this.startLine),this.state=gt,this.endLine(e)}fieldChar(e,n){if(this.lastWasCr=!1,this.state!==gt){e===this.quoteCode&&this.state===As&&this.reader.strayQuoteLine===0&&(this.reader.strayQuoteLine=this.startLine);return}if(this.leading&&this.count===0&&this.commentCodes.includes(e)){this.state=Tc,this.segment=n;return}this.leading=!1,e===this.quoteCode?(this.state=or,this.fieldQuoted=!0,this.segment=n+1):(this.state=As,this.segment=n)}endChunk(e){const n=e.length;this.segment>=n||(this.state===Tc?this.comment=this.grow(this.comment,e.slice(this.segment,n)):(this.state===or||this.state===As)&&(this.field=this.grow(this.field,e.slice(this.segment,n))),this.segment=n)}finish(){const{state:e}=this;return e===Tc?(this.reader.leadingComments.push(this.comment),this.reader.leadingCommentLines.push(this.line),!1):(e===or&&this.reader.unclosedQuote(this.startLine),e!==gt||this.count>0?(e===gt&&this.collapse||this.push(),this.recordLine=this.startLine,!0):!1)}countLineBreaks(e,n,i){const r=e.slice(n,i);let{line:s}=this,o=this.lastWasCr?-1:-2,l=r.indexOf(`
|
|
11
|
+
`),a=r.indexOf("\r");for(;l>=0||a>=0;)l<0||a>=0&&a<l?(s++,o=a,a=r.indexOf("\r",a+1)):(l!==o+1&&s++,l=r.indexOf(`
|
|
12
|
+
`,l+1));this.line=s,this.lastWasCr=o===r.length-1}grow(e,n){return e.length+n.length>Vo&&py(this.reader.report,`a cell is longer than ${Vo} characters, the most one JavaScript string holds`,this.startLine),e+n}push(){const{reader:e,count:n}=this;e.cells[n]=this.field,e.quoted[n]=this.fieldQuoted,this.count=n+1,this.field="",this.fieldQuoted=!1}endLine(e){e===Li&&this.lastWasCr||this.line++,this.startLine=this.line,this.lastWasCr=e===fr}}class yT{constructor(e,n,i={}){this.inner=new mT(e,n,{delimiter:i.delimiter??null,quote:'"',comments:i.comments,skipQuoteErrors:i.skipQuoteErrors,collapseSpaces:!0,sepDirective:!0,inspect:i.inspect},{signal:i.signal,onProgress:i.onProgress,encoding:i.encoding,allowEmpty:i.allowEmpty,nulIsBinary:!0})}get leadingComments(){return this.inner.leadingComments}get leadingCommentLines(){return this.inner.leadingCommentLines}get line(){return this.inner.line}get delimiter(){return this.inner.delimiter}get quoted(){return this.inner.quoted}get strayQuoteLine(){return this.inner.strayQuoteLine}get sepDirective(){return this.inner.sepDirective}async*[Symbol.asyncIterator](){const{inner:e}=this;for await(const n of e)w2(e.cells,e.quoted,n)||(yield e.cells.slice(0,n))}}function w2(t,e,n){for(let i=0;i<n;i++)if(e[i]||t[i].trim().length>0)return!1;return!0}class te extends Error{constructor(e,n){super(e),this.name="XmlSyntaxError",this.line=n}}const bT=1e5;class df extends te{constructor(e,n){super(`<${e}> is nested more than ${String(bT)} elements deep`,n),this.name="XmlNestingError"}}class $y extends te{constructor(e){super("the input is empty: no root element",e),this.name="XmlEmptyInputError"}}const _2=7,ET=/^&#(?:[xX]([0-9a-fA-F]{1,6})|(\d{1,7}));/,S2=/&#(?:[xX]([0-9a-fA-F]{1,6})|(\d{1,7}));$/,O2={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"},N2=60,ho=62,A2=47,T2=61,Ic=34,Sh=39,I2=91,$2=93,C2=33,Oh=45,yE=63,v2=16,bE=9;function gd(t){return t===32||t===9||t===10||t===13}function Cy(t){return!bl(t)||t>=48&&t<=57||t===45||t===46||t===183?!1:!(t>=768&&t<=879)&&t!==8255&&t!==8256}const vy=new Uint8Array(128),Dy=new Uint8Array(128);for(let t=0;t<128;t++)vy[t]=Cy(t)?1:0,Dy[t]=bl(t)?1:0;const wT=new RegExp("[\0-\b\v\f-\\uFFFE\\uFFFF\\uD800-\\uDFFF]","u");function Bs(t){return wT.test(t)}function EE(t){const e=wT.exec(t);return e===null?-1:e.index}function ky(t){const e=[];let n=0;for(let i=0;i<t.nodeCount;i++){const r=t.ids.idOf(i);typeof r=="string"&&Bs(r)&&n++}n>0&&e.push(Object.freeze({code:Yd,message:`${n} node id${O(n)} ${C(n,"holds","hold")} a character XML 1.0 cannot carry; the save fails`,column:null,count:n}));for(const[i,r]of[["node",t.nodes],["edge",t.edges],["graph",t.graph]])for(const s of r){const o=D2(s);o>0&&e.push(Object.freeze({code:Yd,message:`${i} column "${s.meta.name}": ${o} value${O(o)} ${C(o,"holds","hold")} a character XML 1.0 cannot carry; the save fails`,column:s.meta.name,count:o}))}return e}function D2(t){let e=0;if(t.dtype==="string"||t.dtype==="dict")for(let n=0;n<t.length;n++)t.isSet(n)&&Bs(t.value(n))&&e++;else if(t.dtype==="list"&&(t.meta.itemDtype==="string"||t.meta.itemDtype==="dict"))for(let n=0;n<t.length;n++)t.isSet(n)&&t.sliceOf(n).some(i=>typeof i=="string"&&Bs(i))&&e++;return e}const k2=/^<\?xml\s[^>]*?\bencoding\s*=\s*["']([A-Za-z][A-Za-z0-9._-]*)["']/;function uf(t){const e=k2.exec(t);return e===null?null:e[1]}function _T(t){let e="utf-8";return t[0]===255&&t[1]===254||t[0]===60&&t[1]===0&&t[2]===63?e="utf-16le":(t[0]===254&&t[1]===255||t[0]===0&&t[1]===60&&t[3]===63)&&(e="utf-16be"),new TextDecoder(e,{fatal:!1}).decode(t)}function ru(t){if(t.length===0)return!1;for(let e=0;e<t.length;){const n=t.codePointAt(e)??0;if(!R2(n,e===0))return!1;e+=n>65535?2:1}return!0}function R2(t,e){return t<128?(e?vy[t]:Dy[t])===1:e?Cy(t):bl(t)}function L2(t){return t===9||t===10||t===13||t>=32&&t<=55295||t>=57344&&t<=65533||t>=65536&&t<=1114111}function P2(t,e,n){let i=t.indexOf("&");if(i<0)return t;let r="",s=0;for(;i>=0;){r+=t.slice(s,i);const o=t.indexOf(";",i+1);if(n?.bareAmpersand!==void 0&&(o<0||o-i>_2)&&!ET.test(t.slice(i,i+12))){n.bareAmpersand(Gr(t,i,e)),r+="&",s=i+1,i=t.indexOf("&",s);continue}if(o<0)throw new te("unterminated entity reference",Gr(t,i,e));const l=t.slice(i+1,o);if(l.startsWith("#")){const a=l.startsWith("#x")||l.startsWith("#X"),c=l.slice(a?2:1),d=a?/^0*[\da-fA-F]{1,6}$/.test(c):/^0*\d{1,7}$/.test(c),u=a?16:10,f=d?Number.parseInt(c,u):-1,h=f>=55296&&f<=56319?x2(t,o+1,n):null;if(h!==null){n?.surrogatePair?.(Gr(t,i,e)),r+=String.fromCharCode(f,h.unit),s=h.end,i=t.indexOf("&",s);continue}if(f<0||!L2(f))throw new te(`invalid character reference &${l};`,Gr(t,i,e));r+=String.fromCodePoint(f)}else{const a=O2[l];if(a===void 0)throw new te(`unknown entity &${l};`,Gr(t,i,e));r+=a}s=o+1,i=t.indexOf("&",s)}return r+t.slice(s)}function Gr(t,e,n){let i=n;for(let r=t.indexOf(`
|
|
13
|
+
`);r>=0&&r<e;r=t.indexOf(`
|
|
14
|
+
`,r+1))i++;return i}function x2(t,e,n){if(n?.surrogatePair===void 0||t.charCodeAt(e)!==38)return null;const i=ET.exec(t.slice(e,e+12));if(i===null)return null;const r=i[1]===void 0?Number.parseInt(i[2],10):Number.parseInt(i[1],16);return r>=56320&&r<=57343?{unit:r,end:e+i[0].length}:null}function Tr(t){for(let e=0;e<t.length;e++)if(!gd(t.charCodeAt(e)))return!1;return!0}function Rs(t){const e=t.lastIndexOf(":");return e<0?t:t.slice(e+1)}async function ff(t,e,n){const i=new G2(e,n);let r=0,s=1,o=!0;try{for await(const l of t){if(o){const a=l.search(/\S/),c=a<0?l:l.slice(0,a);if(r+=c.length,s+=c.split(`
|
|
15
|
+
`).length-1,a>=0&&(o=!1,r>0&&/^<\?xml\s/.test(l.slice(a,a+6))))throw new te("the XML declaration must be at the very start of the document; whitespace precedes it",s)}i.push(l)}i.finish()}catch(l){throw l instanceof te&&i.declaresXml11&&!l.message.includes("XML 1.1")?new te(`${l.message}; the document declares XML 1.1, which graph-io does not read (it reads XML 1.0)`,l.line):l}}const wE={comment:"-->",cdata:"]]>",pi:"?>",endtag:">"},M2="http://www.w3.org/XML/1998/namespace",U2=["<!--","<![CDATA[","<!DOCTYPE"];class G2{constructor(e,n){this.buffer="",this.pending=null,this.line=1,this.nextBreak=-2,this.pendingCr=!1,this.final=!1,this.text="",this.textLine=1,this.stack=[],this.rootSeen=!1,this.rootClosed=!1,this.markupSeen=!1,this.atStart=!0,this.doctypeSeen=!1,this.version=null,this.textTail="",this.pendingHigh="",this.bindings=[],this.handler=e,this.repairs=n}get declaresXml11(){return this.version==="1.1"}push(e){let n=e;this.pendingHigh.length>0&&(n=this.pendingHigh+n,this.pendingHigh="");const i=n.charCodeAt(n.length-1);i>=55296&&i<=56319&&(this.pendingHigh=n.slice(-1),n=n.slice(0,-1)),this.pendingCr&&(n=`\r${n}`,this.pendingCr=!1),n.endsWith("\r")&&(this.pendingCr=!0,n=n.slice(0,-1)),n.includes("\r")&&(n=n.replaceAll(/\r\n?/g,`
|
|
16
|
+
`)),this.feed(n)}finish(){this.final=!0;const e=this.pendingHigh;if(this.pendingHigh="",this.pendingCr?(this.pendingCr=!1,this.feed(`
|
|
17
|
+
${e}`)):this.feed(e),this.pending!==null||this.buffer.length>0)throw new te("unexpected end of input inside markup",this.line);if(this.flushText(),this.stack.length>0)throw new te(`unclosed element <${this.stack[this.stack.length-1]}>`,this.line);if(!this.rootSeen)throw this.markupSeen?new te("no root element",this.line):new $y(this.line)}feed(e){const{pending:n}=this;if(n===null){this.buffer=this.buffer.length===0?e:this.buffer+e,this.nextBreak=-2,this.scan();return}if(n.kind==="decl"){this.pending=null,this.buffer=n.pieces.join("")+e,this.nextBreak=-2,this.scan();return}const i=this.scanPending(n,e);if(i<0){if(e.length>0&&n.pieces.push(e),this.final)throw new te("unexpected end of input inside markup",this.line);return}this.pending=null,n.pieces.push(e.slice(0,i)),this.buffer=n.pieces.join("")+e.slice(i),this.nextBreak=-2,this.scan()}scanPending(e,n){switch(e.kind){case"starttag":return this.scanStartTag(e,n,0);case"doctype":return this.scanDoctype(e,n,0);case"decl":return-1;default:{const i=wE[e.kind]??">",r=e.tail+n,s=r.indexOf(i);return s<0?(e.tail=r.slice(Math.max(0,r.length-(i.length-1))),-1):s+i.length-e.tail.length}}}scanStartTag(e,n,i){let{quote:r}=e;const s=n.length;let o=i;for(;o<s;){if(r!==0){const a=n.indexOf(String.fromCharCode(r),o);if(a<0)break;r=0,o=a+1;continue}const l=n.charCodeAt(o);if(l===Ic||l===Sh)r=l;else if(l===ho)return e.quote=0,o+1;o++}return e.quote=r,-1}scanDoctype(e,n,i){let{quote:r,depth:s,comment:o,pi:l,run:a}=e;for(let c=i;c<n.length;c++){const d=n.charCodeAt(c);if(l){d===ho&&a===1?(l=!1,a=0):a=d===yE?1:0;continue}if(o){d===Oh?a++:(d===ho&&a>=2&&(o=!1),a=0);continue}if(r!==0){d===r&&(r=0);continue}if(s>0){if(a===1&&d===C2){a=2;continue}if(a===2&&d===Oh){a=3;continue}if(a===3&&d===Oh){o=!0,a=0;continue}if(a===1&&d===yE){l=!0,a=0;continue}if(a=0,d===N2){a=1;continue}}if(d===Ic||d===Sh)r=d;else if(d===I2)s++;else if(d===$2)s--;else if(d===ho&&s<=0)return e.quote=0,e.depth=0,e.comment=!1,e.pi=!1,e.run=0,c+1}return e.quote=r,e.depth=s,e.comment=o,e.pi=l,e.run=a,-1}scan(){const{buffer:e}=this,{length:n}=e;let i=0,r=!1;for(;;){const s=e.indexOf("<",i);if(s<0){let l=n;if(!this.final){const a=e.lastIndexOf("&");a>=i&&!e.includes(";",a)&&(a>=n-v2||/^&#[xX]?0[\da-fA-F]*$/.test(e.slice(a)))&&(l=a),this.repairs?.surrogatePair!==void 0&&(l=this.holdHighSurrogate(i,l))}this.takeText(i,l),i=l;break}s>i&&(this.takeText(i,s),i=s);const o=this.consumeMarkup(i);if(o<0){r=!0;break}i=o}r?(this.pending=this.startPending(e,i),this.buffer=""):this.buffer=i===0?e:e.slice(i),this.nextBreak=-2}startPending(e,n){const i=n===0?e:e.slice(n),r={kind:"starttag",pieces:[i],tail:"",quote:0,depth:0,comment:!1,pi:!1,run:0};if(i.length<bE)return r.kind="decl",r;if(i.startsWith("<!--"))r.kind="comment";else if(i.startsWith("<![CDATA["))r.kind="cdata";else if(i.startsWith("<!DOCTYPE"))r.kind="doctype";else{if(i.startsWith("<!"))return r.kind="decl",r;i.startsWith("<?")?r.kind="pi":i.startsWith("</")&&(r.kind="endtag")}switch(r.kind){case"starttag":this.scanStartTag(r,i,1);break;case"doctype":this.scanDoctype(r,i,9);break;default:{const s=wE[r.kind]??">";r.tail=i.slice(Math.max(0,i.length-(s.length-1)));break}}return r}consumeMarkup(e){const n=this.markupEnd(e);return n>=0&&(this.markupSeen=!0,this.atStart=!1,this.textTail=""),n}markupEnd(e){const{buffer:n}=this;if(n.startsWith("<!",e))return this.declarationEnd(e);if(n.startsWith("<?",e)){const r=n.indexOf("?>",e+2);return r<0?-1:(this.processingInstruction(e,r),this.advanceLine(e,r+2),r+2)}if(n.startsWith("</",e)){const r=n.indexOf(">",e+2);if(r<0)return-1;const s=n.slice(e+2,r).trimEnd();if(!ru(s))throw new te(`malformed end tag </${s}>`,this.line);return this.flushText(),this.endElement(s),this.advanceLine(e,r+1),r+1}const i=this.parseStartTag(e);return i===null?-1:(this.flushText(),this.startElement(i.name,i.attrs,i.declaresNamespace),i.selfClosing&&this.endElement(i.name),this.advanceLine(e,i.end),i.end)}cdataEnd(e){const n=this.buffer.indexOf("]]>",e+9);if(n<0)return-1;this.text.length===0&&(this.textLine=this.line);const i=this.buffer.slice(e+9,n),r=EE(i);if(r>=0)throw new te("a character XML 1.0 forbids appears in a CDATA section",this.lineIn(e,e+9+r));return this.text+=i,this.advanceLine(e,n+3),n+3}declarationEnd(e){const{buffer:n}=this;if(n.length-e<bE){const s=n.slice(e);if(!this.final||U2.some(o=>o.startsWith(s)))return-1}if(n.startsWith("<!--",e)){const s=n.indexOf("-->",e+4);return s<0?-1:(this.advanceLine(e,s+3),s+3)}if(n.startsWith("<![CDATA[",e))return this.cdataEnd(e);if(!n.startsWith("<!DOCTYPE",e))throw n.slice(e+2,e+9).toUpperCase()==="DOCTYPE"?new te(`<!${n.slice(e+2,e+9)}> is not XML (it must be written <!DOCTYPE>); the input looks like an HTML document`,this.line):new te("unexpected markup declaration",this.line);if(this.rootSeen||this.doctypeSeen)throw new te("a DOCTYPE declaration is allowed once, before the root element",this.line);const i={kind:"doctype",pieces:[],tail:"",quote:0,depth:0,comment:!1,pi:!1,run:0},r=this.scanDoctype(i,n,e+9);return r<0?-1:(this.doctypeSeen=!0,this.handler.doctype?.(n.slice(e,r),this.line),this.advanceLine(e,r),r)}processingInstruction(e,n){const i=this.buffer.slice(e+2,n),r=/^[^\s]*/.exec(i)?.[0]??"";if(!ru(r))throw new te(`a processing instruction needs a target name, not "${r}"`,this.line);if(r.toLowerCase()!=="xml")return;if(r!=="xml")throw new te(`<?${r} is not an XML declaration (which is written <?xml in lower case); the target is reserved`,this.line);if(!this.atStart||e!==0)throw new te("an XML declaration (<?xml ...?>) may appear only at the very start of the document; the target xml is reserved",this.line);const s=/\bversion\s*=\s*(["'])([^"']*)\1/.exec(i)?.[2];if(s===void 0)throw new te("the XML declaration has no version",this.line);if(!/^1\.\d+$/.test(s))throw new te(`XML version ${s} is not supported (only 1.x)`,this.line);this.version=s}lineIn(e,n){return Gr(this.buffer.slice(e,n),n-e,this.line)}decode(e,n){try{return P2(e,n,this.repairs)}catch(i){throw i instanceof te&&this.version!==null&&this.version!=="1.0"?new te(`${i.message} (the document declares XML ${this.version}, whose character rules are not supported; it is read as XML 1.0)`,i.line):i}}parseStartTag(e){const{buffer:n}=this,{length:i}=n;let r=e+1;const s=this.readName(r);if(s<0)return null;if(s===r)throw new te("expected an element name after <",this.line);const o=n.slice(r,s);r=s;const l=new Map;let a=!1;for(;;){const c=r;for(;r<i&&gd(n.charCodeAt(r));)r++;if(r>=i)return null;const d=n.charCodeAt(r);if(d===ho)return{name:o,attrs:l,selfClosing:!1,declaresNamespace:a,end:r+1};if(d===A2){if(r+1>=i)return null;if(n.charCodeAt(r+1)!==ho)throw new te(`unexpected "/" in <${o}>`,this.lineIn(e,r));return{name:o,attrs:l,selfClosing:!0,declaresNamespace:a,end:r+2}}if(r===c)throw new te(`the attributes of <${o}> must be separated by whitespace`,this.lineIn(e,r));const u=this.readName(r);if(u<0)return null;if(u===r)throw new te(`malformed attribute in <${o}>`,this.lineIn(e,r));const f=n.slice(r,u);for(r=u;r<i&&gd(n.charCodeAt(r));)r++;if(r>=i)return null;if(n.charCodeAt(r)!==T2)throw new te(`attribute ${f} of <${o}> has no value`,this.lineIn(e,r));for(r++;r<i&&gd(n.charCodeAt(r));)r++;if(r>=i)return null;const h=n.charCodeAt(r);if(h!==Ic&&h!==Sh)throw new te(`attribute ${f} of <${o}> is not quoted`,this.lineIn(e,r));const p=n.indexOf(h===Ic?'"':"'",r+1);if(p<0)return null;const g=this.lineIn(e,r);if(l.has(f))throw new te(`duplicate attribute ${f} in <${o}>`,g);const m=n.slice(r+1,p);if(Bs(m))throw new te(`a character XML 1.0 forbids appears in attribute ${f} of <${o}>`,g);if(m.includes("<"))throw new te(`a "<" in the value of attribute ${f} of <${o}> (write <)`,g);f.startsWith("xmlns")&&(a=!0),l.set(f,this.decode(j2(m),g)),r=p+1}}readName(e){const{buffer:n}=this,{length:i}=n;let r=e;for(;r<i;){const s=n.charCodeAt(r);if(s<128){if((r===e?vy[s]:Dy[s])===0)break;r++;continue}const o=n.codePointAt(r);if(o===void 0||(r===e?!Cy(o):!bl(o)))break;r+=o>65535?2:1}return r>=i&&!this.final?-1:r}holdHighSurrogate(e,n){const i=this.buffer.slice(Math.max(e,n-12),n),r=S2.exec(i);if(r===null)return n;const s=r[1]===void 0?Number.parseInt(r[2],10):Number.parseInt(r[1],16);return s>=55296&&s<=56319?n-r[0].length:n}takeText(e,n){if(n<=e)return;this.text.length===0&&(this.textLine=this.line);const i=this.buffer.slice(e,n),r=EE(i);if(r>=0)throw new te("a character XML 1.0 forbids appears in character data",Gr(i,r,this.line));if(i.includes(">")){const o=(this.textTail+i).indexOf("]]>");if(o>=0)throw new te('"]]>" is not allowed in character data (write ]]>)',Gr(i,Math.max(0,o-this.textTail.length),this.line))}this.textTail=i.length>=2?i.slice(-2):(this.textTail+i).slice(-2),this.atStart=!1,this.text+=this.decode(i,this.line),this.advanceLine(e,n)}advanceLine(e,n){let i=this.nextBreak;if(i!==-1){for((i===-2||i<e)&&(i=this.buffer.indexOf(`
|
|
18
|
+
`,e));i>=0&&i<n;)this.line++,i=this.buffer.indexOf(`
|
|
19
|
+
`,i+1);this.nextBreak=i}}flushText(){if(this.text.length===0)return;const{text:e}=this;if(this.text="",this.stack.length===0){if(!Tr(e))throw new te("text outside the root element",this.textLine);return}this.handler.text(e,this.textLine)}startElement(e,n,i){if(this.stack.length===0){if(this.rootClosed)throw new te(`a second root element <${e}> follows the document element`,this.line);this.rootSeen=!0}if(i)for(const[r,s]of n)r==="xmlns"?this.bindings.push({prefix:"",uri:s,depth:this.stack.length}):r.startsWith("xmlns:")&&this.bindings.push({prefix:r.slice(6),uri:s,depth:this.stack.length});if(this.stack.length>=bT)throw new df(e,this.line);this.stack.push(e),this.handler.start(e,n,this.line,this.namespaceOf(e))}namespaceOf(e){const n=e.indexOf(":");if(n>=0&&(n===0||n===e.length-1||e.includes(":",n+1)))return null;const i=n<0?"":e.slice(0,n);for(let r=this.bindings.length-1;r>=0;r--)if(this.bindings[r].prefix===i)return this.bindings[r].uri;return i==="xml"?M2:i===""?"":null}endElement(e){const n=this.stack.at(-1)??null;if(n===null)throw new te(`unexpected end tag </${e}>`,this.line);if(n!==e)throw new te(`end tag </${e}> does not match <${n}>`,this.line);for(this.stack.pop();(this.bindings.at(-1)?.depth??-1)>=this.stack.length;)this.bindings.pop();this.stack.length===0&&(this.rootClosed=!0),this.handler.end(e,this.line)}}function j2(t){return t.includes(`
|
|
20
|
+
`)||t.includes(" ")?t.replaceAll(/[\n\t]/g," "):t}const F2=/[&<>\r]/g,z2=/[&<>"\t\n\r]/g,ST={"&":"&","<":"<",">":">",'"':"""," ":"	","\n":" ","\r":" "};function nt(t){if(Bs(t))throw OT(t);return t.replaceAll(F2,e=>ST[e])}function W(t){if(Bs(t))throw OT(t);return t.replaceAll(z2,e=>ST[e])}function OT(t){return new N("E_COLUMN_TYPE","the text holds a character XML 1.0 cannot carry",{reason:"xml illegal char",length:t.length})}const W2=/["&]|[^ -~]/gu;function Pi(t){return`"${t.replaceAll(W2,n=>{const i=n.codePointAt(0);if(i===void 0)return n;if(i>=55296&&i<=57343)throw new N("E_COLUMN_TYPE","a lone surrogate cannot be written as a GML string",{reason:"lone surrogate"});return`&#${i};`})}"`}const B2=/&(#\d+|#x[0-9a-fA-F]+|[A-Za-z][A-Za-z0-9]*);/g,H2=(()=>{const t=new Map([["amp","&"],["quot",'"'],["lt","<"],["gt",">"],["apos","'"]]);return"nbsp iexcl cent pound curren yen brvbar sect uml copy ordf laquo not shy reg macr deg plusmn sup2 sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig agrave aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml".split(" ").forEach((n,i)=>{t.set(n,String.fromCharCode(160+i))}),t})();function V2(t,e){return t.replaceAll(B2,(n,i)=>{if(i.startsWith("#")){const s=i.startsWith("#x")?Number.parseInt(i.slice(2),16):Number(i.slice(1));return s<=1114111?String.fromCodePoint(s):(e?.(n),n)}const r=H2.get(i);return r===void 0?(e?.(n),n):r})}const Y2=/^-?(\.\d+|\d+(\.\d*)?)$/,K2=new Set(["node","edge","graph","digraph","subgraph","strict"]);function X2(t){return K2.has(t.toLowerCase())?!1:q2(t)||Y2.test(t)}function q2(t){if(t.length===0)return!1;for(let e=0;e<t.length;e++){const n=t.charCodeAt(e),i=n>=65&&n<=90||n>=97&&n<=122||n===95||n>=128&&(e>0||n!==65279),r=n>=48&&n<=57;if(!i&&(e===0||!r))return!1}return!0}function NT(t){return!t.endsWith("\\")&&!t.includes(String.raw`\"`)&&!/\\[\r\n]/.test(t)}function nr(t){return X2(t)?t:`"${t.replaceAll('"',String.raw`\"`)}"`}function hf(t,e=",",n='"'){return t.length===0?n+n:!t.includes(e)&&!t.includes(n)&&!t.includes(`
|
|
21
|
+
`)&&!t.includes("\r")&&t===t.trim()?t:`${n}${t.split(n).join(n+n)}${n}`}function Ry(t){return!t.includes('"')&&!t.includes(`
|
|
22
|
+
`)&&!t.includes("\r")}function Yo(t){if(!Ry(t))throw new N("E_UNSUPPORTED","a Pajek label cannot contain a double quote or a line break",{reason:"pajek label",value:t});return t.length>0&&!/[\s"]/.test(t)&&!t.startsWith("[")&&!t.startsWith("%")?t:`"${t}"`}const Ko=Object.freeze(["source","src","from","start","source_id","sourceid","fromnodeid","start_id",":start_id"]),Xo=Object.freeze(["target","dst","dest","to","end","target_id","targetid","tonodeid","end_id",":end_id"]),su=Object.freeze(["id","node","name","key"]),qo=Object.freeze(["label"]),Ly=Object.freeze(["id"]),Nh="Type",J2=new Set([...Ko,...Xo,...su,...qo,"weight","type","value"]);function qt(t,e){for(const n of e){const i=t.indexOf(n);if(i>=0)return i;const r=n.toLowerCase(),s=t.findIndex(o=>o.toLowerCase()===r);if(s>=0)return s}return-1}function md(t,e,n){if(typeof e=="number"){if(!Number.isInteger(e)||e<0||e>=t.length)throw new N("E_UNSUPPORTED",`option ${n}: column ${e} does not exist (the file has ${t.length} column${O(t.length)})`,{option:n,found:e,columns:t.length});return e}const i=qt(t,[e]);if(i<0)throw new N("E_UNSUPPORTED",`option ${n}: no column named ${JSON.stringify(e)}`,{option:n,found:e,columns:[...t]});return i}function Z2(t,e){let n=!0,i=!1;for(const r of t){const s=r.trim();J2.has(s.toLowerCase())&&(i=!0),(s.length===0||qn(s)!=="string")&&(n=!1)}if(i){const r=ya(t);return e===null||qt(r,Ko)>=0&&qt(r,Xo)>=0?!0:!(t.length===2&&e.length>=1&&t[1].trim()===e[0].trim())||t[1].trim().length===0}return!n||e===null?!1:e.some(r=>r.trim().length>0&&qn(r.trim())!=="string")}function Q2(t){const e=[];for(let n=1;n<=t;n++)e.push(`column${n}`);return e}function ya(t){return t.map((e,n)=>{const i=e.trim();return i.length===0?`column${n+1}`:i})}class eM{constructor(e,n,i,r,s=rf){this.handle=A,this.text=!1,this.dict=!1,this.decided=!1,this.candidate=!0,this.writer=null,this.pendingRows=[],this.pendingTexts=[],this.name=e,this.domain=n,this.sink=i,this.report=r,this.heuristic=new no(s)}get isDict(){return this.dict}write(e,n){if(this.decided){this.push(e,n);return}this.pendingRows.push(e),this.pendingTexts.push(n),this.candidate&&qn(n)!=="string"&&(this.candidate=!1),(this.heuristic.observe(n)||!this.candidate)&&this.decide()}finish(){this.decided||this.decide(),this.handle===A&&(this.handle=this.lookup(),this.handle===A&&(this.handle=this.declare("string")))}decide(){this.decided=!0;const e=this.lookup();e!==A?(this.handle=e,this.text=this.holdsText()):this.candidate&&this.heuristic.decide()==="dict"?(this.dict=!0,this.text=!0,this.handle=this.declare("dict")):this.writer=new Sy(this.name,this.domain,this.sink,this.report);const n=this.pendingRows,i=this.pendingTexts;for(let r=0;r<n.length;r++)try{this.push(n[r],i[r])}catch(s){this.report.recordError(s,{element:this.name})}n.length=0,i.length=0}push(e,n){if(this.writer!==null){this.writer.write(e,n),this.handle=this.writer.column;return}const i=this.text?n:lf(n);this.set(this.handle,e,i)}set(e,n,i){this.domain==="node"?this.sink.setNodeValue(e,n,i):this.sink.setEdgeValue(e,n,i)}lookup(){return this.domain==="node"?this.sink.nodeColumn(this.name):this.sink.edgeColumn(this.name)}holdsText(){for(const e of["string","dict"])try{return this.declare(e),!0}catch(n){if(!(n instanceof N)||n.code!=="E_COLUMN_EXISTS")throw n}return!1}declare(e){const n={name:this.name,dtype:e,nullable:!0,origin:{format:"csv"}};return this.domain==="node"?this.sink.declareNodeColumn(n):this.sink.declareEdgeColumn(n)}}const AT=Ut,yd="E_CSV_NO_ENDPOINT_COLUMNS",Vp="E_CSV_NO_ID_COLUMN",Yp="E_CSV_FIELD_COUNT",TT=Zn,Kp=dt,IT="E_CSV_BAD_TYPE",$T="W_CSV_NO_DATA_ROWS",CT=sn,Py=Rn,vT="W_CSV_COLUMN_MISSING",tM=bn,DT=Ai,kT="E_CSV_OTHER_FORMAT",RT="W_CSV_STRAY_QUOTE",Xp="W_CSV_COMMENT_DIRECTION",LT="W_CSV_TYPE_COLUMN_IGNORED",PT="W_CSV_TRAILING_HEADER_DELIMITER",xT="W_CSV_SINGLE_COLUMN",MT="W_CSV_AMBIGUOUS_COLUMN",UT="W_CSV_PADDED_ID",GT="W_CSV_COMMENT_LIKE_RECORD",jT="W_CSV_TRAILING_DELIMITER",FT="W_CSV_WEIGHT_AS_ATTRIBUTE",nM=new Set(["edges","nodes","adjacency","auto"]),zT=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","errorLimit","signal","onProgress"]),iM=new Set([...zT,"nodeIdFrom"]),WT=Object.freeze(["#","%"]),rM=/^\s*[+-]?\d+,\d+(?:[eE][+-]?\d+)?\s*$/;function sM(t){const e=t.slice(1).trim().toLowerCase();return/^(?:directed graph|asym)\b/.test(e)?!0:/^(?:undirected graph|sym|bip)\b/.test(e)?!1:null}function Ah(t){return t?"directed":"undirected"}function oM(t,e){return e!==!0&&t.trim().length!==t.length}function lM(t){const e=t??{};aM(e);for(const n of["sourceColumn","targetColumn","idColumn","labelColumn"])_E(n,e[n]);if(e.typeColumn!==null&&_E("typeColumn",e.typeColumn),e.table==="adjacency"&&cM(e),e.rowNumberIds!==void 0&&typeof e.rowNumberIds!="boolean")throw new N("E_UNSUPPORTED","option rowNumberIds: expected a boolean",{option:"rowNumberIds",found:e.rowNumberIds});return{delimiter:e.delimiter??null,decimalComma:e.decimal===",",header:e.header??"auto",table:e.table??"auto",sourceColumn:e.sourceColumn??null,targetColumn:e.targetColumn??null,typeColumn:e.typeColumn,idColumn:e.idColumn??null,labelColumn:e.labelColumn??null,nodes:NM(e.nodes),rowNumberIds:e.rowNumberIds??!1,explicitDirected:typeof t?.defaultDirected=="boolean"?t.defaultDirected:null}}function aM(t){if(t.delimiter!==void 0&&(typeof t.delimiter!="string"||t.delimiter.length===0))throw new N("E_UNSUPPORTED","option delimiter: expected a non-empty string",{option:"delimiter",found:t.delimiter});if(t.decimal!==void 0&&t.decimal!=="."&&t.decimal!==",")throw new N("E_UNSUPPORTED",'option decimal: expected "." or ","',{option:"decimal",found:t.decimal});if(t.decimal===","&&t.delimiter===",")throw new N("E_UNSUPPORTED",'options delimiter and decimal are both ","; pass delimiter: ";"',{option:"decimal",found:t.decimal});if(t.delimiter!==void 0&&Ty({delimiter:t.delimiter,quote:'"'}),t.header!==void 0&&t.header!=="auto"&&typeof t.header!="boolean")throw new N("E_UNSUPPORTED",'option header: expected true, false or "auto"',{option:"header",found:t.header});if(t.table!==void 0&&!nM.has(t.table))throw new N("E_UNSUPPORTED",'option table: expected "edges", "nodes", "adjacency" or "auto"',{option:"table",found:t.table})}function cM(t){for(const e of["sourceColumn","targetColumn","typeColumn","idColumn","labelColumn"])if(t[e]!==void 0)throw new N("E_UNSUPPORTED",`option ${e}: an adjacency table has no columns`,{option:e,found:t[e]});if(t.rowNumberIds===!0)throw new N("E_UNSUPPORTED","option rowNumberIds: an adjacency table names its nodes",{option:"rowNumberIds",found:t.rowNumberIds})}function _E(t,e){if(e!==void 0&&!(typeof e=="string"&&e.length>0)&&!(typeof e=="number"&&Number.isInteger(e)&&e>=0))throw new N("E_UNSUPPORTED",`option ${t}: expected a column name or a 0-based position`,{option:t,found:e})}function xy(t){return t.length===0||t.trim().length===0}function zn(t,e){return e!==!0&&xy(t)}function dM(t,e){let n=0;for(let i=1;i<t.length;i++)zn(t[i],e[i])||n++;return n}const uM=64;function fM(t,e,n){const i=new Set;return t.map((r,s)=>{const o=Xt(r,String(s+1),l=>i.has(l));return i.add(o),o!==r&&e.warning("coercion",ec,`column ${s+1} "${r}" renamed to "${o}": the header repeats the name`,{line:n,element:r}),o})}function po(t,e,n){const i=t.map((r,s)=>n.has(s)?"":r);return qt(i,e)}function SE(t,e,n,i,r,s){const o={...n,origin:{...n.origin,id:String(i)}},l=he(t,e,o,r,{line:s,element:n.name});return l.roleDropped,l.handle}function OE(t){if(!xy(t))switch(t.trim().toLowerCase()){case"directed":return"directed";case"undirected":return"undirected";case"mutual":return"mutual";default:return null}}function hM(t){const e=t.lastIndexOf(":");if(e<0)return{id:t,weight:void 0};const n=t.slice(e+1);if(n.length===0)return{id:t.slice(0,e),weight:void 0};const i=BT(n);return i===null?{id:t,weight:void 0}:{id:t.slice(0,e),weight:i}}function BT(t){try{return Kn(t)??null}catch{return null}}class NE{constructor(e,n,i,r){this.plan=null,this.writers=[],this.idHandle=A,this.labelHandle=A,this.dataRows=0,this.nodeOrdinal=0,this.adjacencyHinted=!1,this.edgeIds=new Set,this.where={line:null,element:null},this.state=e,this.kind=i,this.rowNumbers=e.csv.rowNumberIds&&(i==="nodes"||i==="auto"&&e.csv.nodes===null);const s={delimiter:e.csv.delimiter,...e.csv.decimalComma?{candidates:Ws.filter(o=>o!==",")}:{},comments:WT,skipQuoteErrors:i==="adjacency",signal:e.common.signal,onProgress:r?e.common.onProgress:null,encoding:e.common.encoding,allowEmpty:i==="adjacency",inspect:gM(e.csv)?void 0:(o,l)=>{this.refuseOtherFormat(o,l)}};this.reader=new yT(n,e.report,s)}async read(){const e=this.reader[Symbol.asyncIterator]();try{await this.readRows(e)}finally{await e.return(void 0)}}async readRows(e){const{report:n}=this.state;let i=await e.next();if(!i.done&&(this.reader.sepDirective||this.isSepDirective(i.value))&&(i=await e.next()),i.done&&this.kind==="adjacency")return;const r=i.done?n.fail(AT,"the input is empty: no header row and no records"):i.value,s=this.reader.line,o=this.reader.quoted.slice(0,r.length),l=[],a=await this.decideHeader(e,{row:r,quoted:o,line:s},l),c=a?fM(ya(r),n,s):Q2(r.length),d=r.length-1,u=a&&d>0&&zn(r[d],o[d]);this.applyCommentDirection(),this.plan=this.resolvePlan(c,a,s,l.map(f=>f.row),u),u&&n.warning("validation-error",PT,"the header ends in a delimiter; rows without the empty last cell are read as complete",{line:s,element:c[d]}),this.reportCommentLikeRecords(c.length),this.reportSingleColumn(c.length,l.map(f=>f.row),s),this.prepareColumns(s);for(const{row:f,quoted:h,line:p}of l)this.processRow(f,h,p);await this.readRemainingRows(e),this.dataRows===0&&a&&n.warning("missing-value",$T,"the table has a header and no data rows",{line:s}),this.reportReaderFindings()}async decideHeader(e,n,i){const r=this.headerMode();let s=null,o;if(r==="auto"){const l=await e.next();s=l.done?null:{row:l.value,quoted:this.reader.quoted.slice(0,l.value.length),line:this.reader.line},o=Z2(n.row,s?.row??null)||this.namesExplicitColumn(n.row)}else o=r;return o||i.push(n),s!==null&&i.push(s),this.rowNumbers&&!o&&this.state.report.warning("unsupported",Jt,"option rowNumberIds ignored: a headerless node table takes its ids from column 0",{line:n.line,element:"rowNumberIds"}),o}headerMode(){const e=this.state.csv.header;return e==="auto"&&this.kind==="adjacency"?!1:e==="auto"&&this.rowNumbers?!0:e}async readRemainingRows(e){const{signal:n}=this.state.common;let i=0;for(;;){const r=await e.next();if(r.done)break;this.processRow(r.value,this.reader.quoted,this.reader.line),++i>=uM&&(i=0,F(n))}for(const r of this.writers)r?.finish()}isSepDirective(e){return this.state.csv.delimiter!==null&&!this.reader.quoted[0]&&/^sep=.$/i.test(e.join(this.state.csv.delimiter))}refuseOtherFormat(e,n){HT.some(i=>i.test(e))&&this.state.report.fail(kT,`the input opens like another format (XML / HTML, JSON, GML, DOT or Pajek), not CSV: ${JSON.stringify(e.trimStart().slice(0,60))}`,{line:n})}namesExplicitColumn(e){const{csv:n}=this.state,i=ya(e);return[n.sourceColumn,n.targetColumn,n.idColumn,n.typeColumn,n.labelColumn].some(r=>typeof r=="string"&&qt(i,[r])>=0)}applyCommentDirection(){const{state:e}=this,{leadingComments:n,leadingCommentLines:i}=this.reader;for(let r=0;r<n.length;r++){const s=n[r],o=sM(s);if(o===null)continue;const l={line:i[r],element:s};if(e.commentDirected===null){e.commentDirected=o,e.commentText=s;const a=e.csv.explicitDirected;a!==null&&a!==o&&e.report.warning("validation-error",Xp,`${JSON.stringify(s)} declares a ${Ah(o)} graph, which overrides defaultDirected: ${a}`,l)}else e.commentDirected!==o&&e.report.warning("validation-error",Xp,`${JSON.stringify(s)} declares a ${Ah(o)} graph but ${JSON.stringify(e.commentText)} declared a ${Ah(e.commentDirected)} one; the first applies`,l)}}reportCommentLikeRecords(e){const{delimiter:n,leadingComments:i,leadingCommentLines:r}=this.reader;if(!(e<2||n===null))for(let s=0;s<i.length;s++){const o=i[s];o.length>1&&o[1].trim().length>0&&o.split(n).length===e&&this.state.report.warnOnce("parse-error",GT,`${JSON.stringify(o)} was skipped as a leading comment but has the fields of a record; quote an id that starts with # or %`,{line:r[s],element:o})}}reportSingleColumn(e,n,i){if(e!==1||n.length===0||this.plan?.kind==="adjacency")return;const r=Ws.filter(o=>o!==this.reader.delimiter),s=Iy(`${n.map(o=>o[0]).join(`
|
|
23
|
+
`)}
|
|
24
|
+
`,`
|
|
25
|
+
`,r);s!==null&&this.state.report.warning("parse-error",xT,`every row read so far is one cell that ${JSON.stringify(s)} splits consistently; pass delimiter: ${JSON.stringify(s)} if that is the file's delimiter`,{line:i})}reportReaderFindings(){const{report:e}=this.state,{strayQuoteLine:n}=this.reader;n>0&&e.warnOnce("parse-error",RT,"a quote inside an unquoted field is kept as text (RFC 4180 quotes a whole field)",{line:n})}resolvePlan(e,n,i,r,s){const{csv:o}=this.state;if(this.kind==="adjacency")return{kind:"adjacency",names:[]};let l=-1,a=-1;if(this.kind!=="nodes"&&(l=TE(e,n,o.sourceColumn,"sourceColumn",Ko,0),a=TE(e,n,o.targetColumn,"targetColumn",Xo,1),l>=0&&a>=0&&l===a))throw new N("E_UNSUPPORTED","sourceColumn and targetColumn name the same column",{option:"targetColumn",found:e[a]});return l>=0&&a>=0?this.edgePlan(e,n,l,a,i,r,s):(this.refuseWithoutEndpoints(e,n,l,a,i),this.nodePlan(e,n,i,s))}refuseWithoutEndpoints(e,n,i,r,s){const{csv:o,report:l}=this.state,a=e.map(d=>JSON.stringify(d)).join(", ");if(i>=0||r>=0){const[d,u]=i>=0?["source","target"]:["target","source"];l.fail(yd,`the header has a ${d} column (${JSON.stringify(e[Math.max(i,r)])}) but no ${u} column (${a})`,{line:s},{columns:[...e]})}(this.kind==="edges"||this.kind==="auto"&&(o.sourceColumn!==null||o.targetColumn!==null||o.nodes!==null))&&l.fail(yd,`no source / target columns in the header (${a}); a node table goes in the nodes option`,{line:s},{columns:[...e]});const c=n?qt(e,su)>=0:e.length>=1;this.kind==="auto"&&o.idColumn===null&&!c&&!this.rowNumbers&&l.fail(yd,`no source / target columns and no id column in the header (${a}); the input is neither an edge table nor a node table`,{line:s},{columns:[...e]})}edgePlan(e,n,i,r,s,o,l){const{csv:a}=this.state,c=new Set([i,r]),d=this.weightColumn(e,n,c,s,o);d>=0&&c.add(d),n&&this.reportEndpointRivals(e,i,r,d,s);const u=this.typeColumn(e,n,i,r,c);u>=0&&c.add(u);const f=n&&u<0&&a.typeColumn===void 0?po(e,[Nh],c):-1,h=n?po(e,Ly,c):-1;h>=0&&c.add(h);const p=n?po(e,qo,c):-1;p>=0&&c.add(p);const g=[];for(let m=0;m<e.length;m++)c.has(m)||g.push(m);return{kind:"edges",names:e,width:e.length,source:i,target:r,weight:d,type:u,typeHint:f,id:h,label:p,attributes:g,optionalLast:l}}weightColumn(e,n,i,r,s){const{common:o,report:l}=this.state;if(o.weightFrom===null)return-1;if(n){const a=po(e,[o.weightFrom],i);return a<0&&this.state.weightFromExplicit&&l.warning("missing-value",vT,`weight column ${JSON.stringify(o.weightFrom)} not found; edges are unweighted`,{line:r,element:o.weightFrom}),a}return e.length<3||i.has(2)?-1:pM(e.length,s)?(l.warnOnce("validation-error",FT,`the third column holds text in the first rows, so it is read as the attribute ${e[2]}, not the weight`,{line:r,element:e[2]}),-1):2}reportEndpointRivals(e,n,i,r,s){const{csv:o,common:l}=this.state;o.sourceColumn===null&&this.reportRivals(e,Ko,n,"source",s),o.targetColumn===null&&this.reportRivals(e,Xo,i,"target",s),r>=0&&l.weightFrom!==null&&this.reportRivals(e,[l.weightFrom],r,"weight",s)}typeColumn(e,n,i,r,s){const{typeColumn:o}=this.state.csv;if(o===null)return-1;if(o===void 0){const c=n&&e[i]==="Source"&&e[r]==="Target"?po(e,[Nh],s):-1;return c>=0&&e[c]===Nh?c:-1}const l=md(e,o,"typeColumn");if(s.has(l))throw new N("E_UNSUPPORTED","typeColumn names an endpoint or weight column",{option:"typeColumn",found:e[l]});return l}reportRivals(e,n,i,r,s){const o=new Set(n.map(l=>l.toLowerCase()));e.forEach((l,a)=>{a!==i&&o.has(l.toLowerCase())&&this.state.report.warning("validation-error",MT,`columns ${JSON.stringify(e[i])} and ${JSON.stringify(l)} both name the ${r}; ${JSON.stringify(e[i])} is used and ${JSON.stringify(l)} is a plain attribute`,{line:s,element:l})})}labelOf(e,n,i){const{labelColumn:r}=this.state.csv;return r!==null?md(e,r,"labelColumn"):n?po(e,qo,i):-1}nodePlan(e,n,i,r){const{common:s}=this.state,o=new Set,l=this.idColumnOf(e,n),a=this.labelOf(e,n,new Set(l>=0?[l]:[])),c=this.nodeIdColumn(e,l,a,i);c>=0&&o.add(c),a>=0&&o.add(a);const d=[];for(let f=0;f<e.length;f++)o.has(f)||d.push(f);const u=c<0&&s.nodeIdFrom!=="index";return{kind:"nodes",names:e,width:e.length,id:c,rowNumber:u,label:a,attributes:d,optionalLast:r}}idColumnOf(e,n){const{idColumn:i}=this.state.csv;return i!==null?md(e,i,"idColumn"):n?qt(e,su):e.length>=1?0:-1}nodeIdColumn(e,n,i,r){const{common:s,report:o}=this.state,l=e.map(a=>JSON.stringify(a)).join(", ");return s.nodeIdFrom==="index"?-1:s.nodeIdFrom==="label"?(i<0&&o.fail(Vp,`nodeIdFrom is "label", but the node table has no column named "label" (${l}); pass labelColumn to name the column that holds the labels`,{line:r},{columns:[...e]}),i):(n<0&&!this.rowNumbers&&o.fail(Vp,`no id column in the node table header (${l})`,{line:r},{columns:[...e]}),n)}prepareColumns(e){const n=this.requirePlan();if(n.kind==="adjacency")return;const{sink:i,report:r}=this.state,s=n.kind==="edges"?"edge":"node",o={format:"csv"};n.kind==="edges"&&n.id>=0&&(this.idHandle=SE(i,"edge",{name:n.names[n.id],dtype:"string",nullable:!0,role:"id",unique:!0,origin:o},n.id+1,r,e)),n.label>=0&&(this.labelHandle=SE(i,s,{name:n.names[n.label],dtype:"string",nullable:!0,role:"label",origin:o},n.label+1,r,e)),this.writers=n.names.map(()=>null);for(const l of n.attributes)this.writers[l]=new eM(n.names[l],s,i,r)}requirePlan(){if(this.plan===null)throw new N("E_UNSUPPORTED","the header has not been read",{reason:"no plan"});return this.plan}processRow(e,n,i){const r=this.requirePlan();if(this.dataRows++,this.state.csv.decimalComma)for(let s=0;s<e.length;s++)rM.test(e[s])&&(e[s]=e[s].replace(",","."));r.kind==="edges"?this.processEdgeRow(r,e,n,i):r.kind==="nodes"?this.processNodeRow(r,e,n,i):this.processAdjacencyRow(e,n,i)}processAdjacencyRow(e,n,i){const{report:r,sink:s,resolver:o,common:l}=this.state,{counts:a}=r,{where:c}=this;c.line=i,c.element=null;const d=dM(e,n);if(zn(e[0],n[0])){r.error("missing-value",Kp,"blank node cell",{line:i}),a.skippedNodes++,a.skippedEdges+=d;return}const u=this.state.commentDirected??l.defaultDirected?"directed":"undirected";this.state.headerSet||(this.state.headerSet=!0,o.setHeader(u!=="undirected",c));let f;try{c.element=e[0],f=this.coerce(e[0]),s.indexOf(f)===A&&a.nodes++,s.addNode(f)}catch(h){r.recordError(h,c),a.skippedNodes++,a.skippedEdges+=d;return}for(let h=1;h<e.length;h++)if(!zn(e[h],n[h])){c.element=e[h];try{const p=hM(e[h]),g=this.coerce(p.id),m=s.indexOf(g)===A,y=s.edgeCount;o.addEdge(f,g,u,l.weightFrom===null?void 0:p.weight,c),a.edges+=s.edgeCount-y,a.nodes+=m?1:0}catch(p){r.recordError(p,c),a.skippedEdges++}}}processEdgeRow(e,n,i,r){const{report:s}=this.state,{counts:o}=s,l=AE(e,n,i,s,r);if(n.length!==e.width){this.reportRowWidth(e,n,r),o.skippedEdges++;return}const a=n[e.source],c=n[e.target],d=zn(a,l[e.source]);if(d||zn(c,l[e.target])){s.error("missing-value",TT,`blank ${d?"source":"target"} cell`,{line:r}),o.skippedEdges++;return}const u=this.rowKind(e,n,r);if(u===null){o.skippedEdges++;return}const{where:f}=this;f.line=r,f.element=null;const h=e.id>=0&&!zn(n[e.id],l[e.id])?n[e.id]:null;if(h!==null&&this.edgeIds.has(h)){s.error("validation-error",DT,`edge id ${JSON.stringify(h)} repeats an earlier row's; the row is skipped`,{line:r,element:h}),o.skippedEdges++;return}this.checkPadded(a,l[e.source],r),this.checkPadded(c,l[e.target],r);let p;try{p=this.addEdge(a,c,u,e.weight>=0?n[e.weight]:null)}catch(g){f.element=h??`${a}->${c}`,s.recordError(g,f),o.skippedEdges++;return}h!==null&&(this.edgeIds.add(h),this.writeRole(this.idHandle,"edge",p,h,e.names[e.id],r)),this.warnTypeHint(e,n,r),e.label>=0&&!zn(n[e.label],l[e.label])&&this.writeRole(this.labelHandle,"edge",p,n[e.label],e.names[e.label],r),this.writeAttributes(e,n,l,p,r)}warnTypeHint(e,n,i){e.typeHint<0||typeof OE(n[e.typeHint])!="string"||this.state.report.warnOnce("unsupported",LT,`column ${JSON.stringify(e.names[e.typeHint])} holds the direction word ${JSON.stringify(n[e.typeHint])} but is a plain attribute; the per-row direction is read from an exact "Type" column beside "Source" and "Target", or from the typeColumn option`,{line:i,element:e.names[e.typeHint]})}reportRowWidth(e,n,i){const r=this.state.csv.table==="auto"&&n.length>e.width&&!this.adjacencyHinted?'; if each line is a node followed by its neighbors, pass table: "adjacency"':"";this.adjacencyHinted||=r!=="",this.state.report.error("validation-error",Yp,`${n.length} field${O(n.length)}, expected ${e.width}${r}`,{line:i})}rowKind(e,n,i){const s=this.state.commentDirected??this.state.common.defaultDirected?"directed":"undirected";if(e.type<0)return s;const o=OE(n[e.type]);return o===null?(this.state.report.error("validation-error",IT,`Type ${JSON.stringify(n[e.type])} is not Directed, Undirected or Mutual`,{line:i}),null):o??s}addEdge(e,n,i,r){const{report:s,sink:o,resolver:l}=this.state,{where:a}=this,c=this.coerce(e),d=this.coerce(n),u=r===null?void 0:Kn(r,s);this.state.headerSet||(this.state.headerSet=!0,l.setHeader(i!=="undirected",a));const f=o.indexOf(c)===A,h=c!==d&&o.indexOf(d)===A,p=o.edgeCount,g=l.addEdge(c,d,i,u,a);return s.counts.edges+=o.edgeCount-p,s.counts.nodes+=(f?1:0)+(h?1:0),g}processNodeRow(e,n,i,r){const{report:s,sink:o}=this.state,{counts:l}=s,a=this.nodeOrdinal++,c=AE(e,n,i,s,r);if(n.length!==e.width){s.error("validation-error",Yp,`${n.length} field${O(n.length)}, expected ${e.width}`,{line:r}),l.skippedNodes++;return}const d=e.id>=0?n[e.id]:String(a);if(e.id>=0&&zn(d,c[e.id])){s.error("missing-value",Kp,"blank id cell",{line:r}),l.skippedNodes++;return}e.id>=0&&this.checkPadded(d,c[e.id],r);const{where:u}=this;u.line=r,u.element=d;let f;try{const h=e.id>=0||e.rowNumber?this.coerce(d):a;o.indexOf(h)!==A?s.warning("merged",CT,`node ${JSON.stringify(h)} already exists; its attributes are overwritten`,u):l.nodes++,f=o.addNode(h)}catch(h){s.recordError(h,u),l.skippedNodes++;return}e.label>=0&&!zn(n[e.label],c[e.label])&&this.writeRole(this.labelHandle,"node",f,n[e.label],e.names[e.label],r),this.writeAttributes(e,n,c,f,r)}checkPadded(e,n,i){oM(e,n)&&this.state.report.warnOnce("validation-error",UT,`id ${JSON.stringify(e)} has leading or trailing whitespace and is kept as written, a different id from the trimmed text`,{line:i,element:e})}coerce(e){const n=this.state.coercer.text(e),i=this.state.coercer.lastMerge;return i!==null&&this.state.report.warnOnce("coercion",Py,`id ${JSON.stringify(i.text)} merged with ${JSON.stringify(i.previousText)} as ${i.id} under ids: "number"`,this.where),n}writeRole(e,n,i,r,s,o){try{n==="node"?this.state.sink.setNodeValue(e,i,r):this.state.sink.setEdgeValue(e,i,r)}catch(l){this.state.report.recordError(l,{line:o,element:s})}}writeAttributes(e,n,i,r,s){for(const o of e.attributes){const l=n[o];if(zn(l,i[o]))continue;const a=this.writers[o];if(a!==null)try{a.write(r,l)}catch(c){this.state.report.recordError(c,{line:s,element:a.name})}}}}function pM(t,e){return t===3&&e.length>0&&e.every(n=>n.length===3&&!xy(n[2])&&BT(n[2])===null)}function gM(t){return t.delimiter!==null||t.header!=="auto"||t.table!=="auto"||t.sourceColumn!==null||t.targetColumn!==null||t.idColumn!==null||t.typeColumn!==void 0&&t.typeColumn!==null}function AE(t,e,n,i,r){if(e.length===t.width+1&&zn(e[t.width],n[t.width]))return e.pop(),i.warnOnce("validation-error",jT,"the row ends in a delimiter the header does not have; the empty last cell is dropped",{line:r}),n;if(!t.optionalLast||e.length!==t.width-1)return n;const s=n.slice(0,e.length);return e.push(""),s.push(!1),s}const mM=4096;function TE(t,e,n,i,r,s){return n!==null?md(t,n,i):e?qt(t,r):t.length>=2?s:-1}const IE=String.raw`<[a-z_][\w.-]*(?::[a-z_][\w.-]*)?`,HT=[/^\s*<(?:\?xml|!doctype|!--)/i,new RegExp(String.raw`^\s*${IE}\s*\/?>\s*(?:[^,;|\s]*<|$)`,"i"),new RegExp(String.raw`^\s*${IE}\s+[a-z_][\w.:-]*\s*=`,"i"),/^\s*\/[*/]/,/^\s*\{\s*(?:["}]|$)/,/^\s*\[\s*(?:[[{"\]\d-]|$)/,/^\s*(?:strict\s+)?(?:di)?graph(?:\s+\S+)?\s*\{/i,/^\s*\*(?:vertices|network|arcs|edges)\b/i,/^\s*(?:creator\s+"|graph\s*\[)/i];function yM(t){let e="utf-8";t[0]===255&&t[1]===254?e="utf-16le":t[0]===254&&t[1]===255&&(e="utf-16be");const n=gT(new TextDecoder(e).decode(t.subarray(0,mM)),WT);if(n.trim().length===0||bM(n)||HT.some(l=>l.test(n)))return 0;const i=pT(n),r=Iy(n,i,Ws,'"',!1,!0);if(r===null){const l=n.split(i,1)[0];return Ws.some(a=>_M(l,a))?.9:0}const s=cf(n,r,'"',2,!1,!0)??[],o=ya(s[0]??[]);return qt(o,Ko)>=0&&qt(o,Xo)>=0?.9:r!==" "&&qt(o,su)>=0?.6:r===" "&&o.length>3||wM(n,i,r)?0:.3}function bM(t){const e=t.length-1;for(let n=0;n<=e;n++){const i=t.codePointAt(n)??0;if(i<32&&i!==9&&i!==10&&i!==13&&!(i===26&&n===e))return!0}return!1}const EM=/[A-Za-z]{2}[.!?](?:\s|$)/;function wM(t,e,n){return t.split(e).filter(s=>s.trim()!=="").length<2?!0:(cf(t,n,'"',8,!1,!0)??[]).some(s=>s.some(o=>/\S\s+\S/.test(o.trim())&&EM.test(o.trim())))}function _M(t,e){const n=ya(cf(t,e,'"',1,!1,!0)?.[0]??[]);return n.length>1&&qt(n,Ko)>=0&&qt(n,Xo)>=0}async function SM(t,e,n){const i=tt(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=lM(n),s=new ne("csv",i.errorLimit);_t(e,n,s),St(n,s,r.table==="nodes"||r.nodes!==null?iM:zT);const o={sink:e,report:s,common:i,csv:r,weightFromExplicit:typeof n?.weightFrom=="string",coercer:new Mn(i.ids),resolver:new ei(e,s,i.onMixedDirection),headerSet:!1,commentDirected:null,commentText:""};return r.nodes!==null&&await new NE(o,r.nodes,"nodes",!1).read(),await new NE(o,t,r.table,!0).read(),o.coercer.mergeCount>1&&s.warning("coercion",Py,`${o.coercer.mergeCount} id cell${O(o.coercer.mergeCount)} merged into ids other cells already produced under ids: "number"`),F(i.signal),s.finish()}const OM=Object.freeze({format:"csv",options:Object.freeze(["decimal","delimiter","header","idColumn","labelColumn","nodes","rowNumberIds","sourceColumn","table","targetColumn","typeColumn"]),extensions:Object.freeze([".csv",".tsv",".edges",".edgelist"]),mimeTypes:Object.freeze(["text/csv","text/tab-separated-values","text/plain"]),sniff:yM,import:SM});function NM(t){if(t===void 0)return null;const e=t;return typeof t=="object"&&typeof e.stream=="function"&&typeof e.size=="number"?t.stream():t}const Ve=Object.freeze({ID_TEXT_COLLISION:w.ID_TEXT_COLLISION,ID_TEXT_TYPE:w.ID_TEXT_TYPE,DIRECTION_DROPPED:"W_CSV_DIRECTION_DROPPED",MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,RESERVED_NAME:"W_CSV_RESERVED_NAME",ROLE_ASSUMED:w.ROLE_ASSUMED,ROLE_NAME:"W_CSV_ROLE_NAME",TEXT_ROLE:"W_CSV_TEXT_ROLE",NONFINITE:"W_CSV_NONFINITE",TEXT_INFERRED:w.TEXT_INFERRED,STORAGE_CLASS_CHANGED:w.STORAGE_CLASS,NODE_TABLE:"W_CSV_NODE_TABLE",ISOLATED_NODES:"W_CSV_ISOLATED_NODES",NODE_ORDER:"W_CSV_NODE_ORDER",EDGE_COLUMNS:"W_CSV_EDGE_COLUMNS",HEADERLESS:"W_CSV_HEADERLESS"}),VT=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:["bool","i32","f64","string","dict"]}),AM={gephi:{source:"Source",target:"Target",type:"Type",id:"Id",label:"Label",weight:"Weight"},generic:{source:"source",target:"target",type:null,id:"id",label:"label",weight:"weight"}},TM=new Set(["id","label"]),IM=new Set(["directed","pair","mutual","weight","timeText","position","color","size","shape","thickness","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]);function $M(t){const e=t??{};if(e.dialect!==void 0&&e.dialect!=="gephi"&&e.dialect!=="generic"&&!sT("csv",e.dialect))throw new N("E_UNSUPPORTED",'option dialect: expected "gephi" or "generic"',{option:"dialect",found:e.dialect});if(e.table!==void 0&&e.table!=="edges"&&e.table!=="nodes"&&e.table!=="adjacency")throw new N("E_UNSUPPORTED",'option table: expected "edges", "nodes" or "adjacency"',{option:"table",found:e.table});if(e.delimiter!==void 0&&(typeof e.delimiter!="string"||e.delimiter.length!==1||e.delimiter==='"'||e.delimiter===`
|
|
26
|
+
`||e.delimiter==="\r"))throw new N("E_UNSUPPORTED","option delimiter: expected one character other than a quote or a line break",{option:"delimiter",found:e.delimiter});if(e.newline!==void 0&&e.newline!==`
|
|
27
|
+
`&&e.newline!==`\r
|
|
28
|
+
`)throw new N("E_UNSUPPORTED","option newline: expected LF or CRLF",{option:"newline",found:e.newline});if(e.table==="adjacency"&&e.header===!0)throw new N("E_UNSUPPORTED","option header: an adjacency table has no header row",{option:"header",found:e.header});if(e.header!==void 0&&typeof e.header!="boolean")throw new N("E_UNSUPPORTED","option header: expected a boolean",{option:"header",found:e.header});return{dialect:AM[e.dialect==="generic"?"generic":"gephi"],table:e.table??"edges",delimiter:e.delimiter??",",newline:e.newline??`
|
|
29
|
+
`,header:e.header??!0}}function $c(t,e){switch(t){case"bool":return e===!0?"true":"false";case"f32":case"f64":return typeof e=="number"?Ar(e,t):String(e);case"i32":case"u32":case"u8":return typeof e=="number"?Ge(e):String(e);case"string":case"dict":return typeof e=="string"?e:String(e);case"json":return JSON.stringify(e)??"";default:return String(e)}}function CM(t,e){if(!t.isSet(e))return null;switch(t.dtype){case"list":{const n=t.sliceOf(e),{dtype:i}=t.child;return Ey(n.map(r=>$c(i,r)),"semicolon")}case"json":return JSON.stringify(t.values[e])??"";case"bool":case"string":case"dict":return $c(t.dtype,t.value(e));default:{const{components:n}=t.meta,{data:i}=t;if(n===1)return $c(t.dtype,i[e]);const r=[];for(let s=0;s<n;s++)r.push($c(t.dtype,i[e*n+s]));return r.join(";")}}}function vM(t,e,n){const i=t.length;if(i>0){const r=t.slice(0,3).map(s=>JSON.stringify(s)).join(", ")+(i>3?", ...":"");n.push(Object.freeze({code:Ve.NODE_TABLE,message:`the ${e==="adjacency"?"adjacency":"edge"} table has no room for node attributes: ${i} node column${O(i)} (${r}) ${C(i,"is","are")} written only by a second export with table: "nodes"`,column:null,count:i,columns:Object.freeze([...t])}))}}function DM(t){const e=new Set;let n=0;for(let i=0;i<t.size;i++){const r=String(t.idOf(i));e.has(r)?n++:e.add(r)}return n}function kM(t,e,n){const{ids:i}=t;if(i.kind==="mixed"){const r=DM(i);r>0&&n(Ve.ID_TEXT_COLLISION,`${r} node id${O(r)} ${C(r,"shares","share")} their text with another id (a number and a string); the save fails with E_INVALID_ID`,null,r)}if(e&&i.kind!=="identity"&&i.kind!=="dense"){let r=0;for(let s=0;s<i.size;s++){const o=i.idOf(s);typeof tc(String(o))!=typeof o&&r++}r>0&&n(Ve.ID_TEXT_TYPE,`${r} node id${O(r)} ${C(r,"reads","read")} back as the other type under ids: "canonical" (a string "1" becomes 1, a number 1.5 becomes "1.5")`,null,r)}}function YT(t,e,n){const i=ft(e),r=$M(e),s=[],o=(y,b,_=null,S=null)=>{s.push(Object.freeze({code:y,message:b,column:_,count:S}))},{ids:l}=t,a=y=>String(l.idOf(y));kM(t,n,o);const c=Gt(t),d=[];for(let y=0;y<t.edgeCount;y++)c.folded(y)||d.push(y);RM(t,r,d.length,o),c.mutualCount>0&&r.table!=="nodes"&&o(Ve.MUTUAL_EXPANDED,`${c.mutualCount} mutual pair${O(c.mutualCount)} ${C(c.mutualCount,"is","are")} written as two directed rows; the mutual mark is lost`,null,c.mutualCount),r.table==="edges"&&xM(t,d,o);const u=Ot(t),{edgeId:f,edgeLabel:h,edgeColumns:p}=LM(t,r,d,n,o),{nodeLabel:g,nodeColumns:m}=PM(t,r,n,o);return r.table!=="nodes"&&vM([...g===null?[]:[g.meta.name],...m.map(y=>y.column.meta.name)],r.table,s),{csv:r,common:i,notes:s,edgeRows:d,folding:c,edgeId:f,edgeLabel:h,weights:u,edgeColumns:p,nodeLabel:g,nodeColumns:m,idText:a}}function RM(t,e,n,i){if(e.table!=="nodes"&&(e.dialect.type===null||e.table==="adjacency")){const r=e.table==="adjacency"?"an adjacency table":"the generic dialect",s=yl(t);t.directed?s>0&&i(Ve.DIRECTION_DROPPED,`${r} has no direction column; ${s} undirected edge${O(s)} of a mixed graph read back as one directed edge each`,null,s):i(Ve.DIRECTION_DROPPED,`${r} has no direction column; ${t.edgeCount} undirected edge${O(t.edgeCount)} ${C(t.edgeCount,"reads","read")} back as directed unless the importer is told otherwise`,null,t.edgeCount)}else e.table==="edges"&&!t.directed&&n===0&&i(Ve.DIRECTION_DROPPED,"the direction lives in the Type cell of each edge row; an undirected graph without edges reads back as directed",null,0)}function LM(t,e,n,i,r){const s=t.edges.byRole("id"),o=t.edges.byRole("label"),l=new Set([e.dialect.source,e.dialect.target,e.dialect.weight].map(ba));e.dialect.type!==null&&l.add(ba(e.dialect.type));const a=KT(t.edges,"edge",l,s,o,e.table==="edges"?r:null);if(e.table==="adjacency"){const c=a.length+(s===null?0:1)+(o===null?0:1);c>0&&r(Ve.EDGE_COLUMNS,`${c} edge column${O(c)} ${C(c,"is","are")} not written: an adjacency table holds the weight only`,null,c)}if(e.table==="edges"&&i){qp(s,"id",Ly,"edge",n,r),qp(o,"label",qo,"edge",n,r);for(const{column:c}of a)My(c,"edge",n,r)}return{edgeId:s,edgeLabel:o,edgeColumns:a}}function PM(t,e,n,i){const r=t.nodes.byRole("label"),s=new Set([ba(e.dialect.id)]),o=[];if(e.table==="nodes"&&n)for(let a=0;a<t.nodeCount;a++)o.push(a);const l=KT(t.nodes,"node",s,null,r,e.table==="nodes"?i:null);if(e.table==="nodes"&&n){qp(r,"label",qo,"node",o,i);for(const{column:a}of l)My(a,"node",o,i)}return{nodeLabel:r,nodeColumns:l}}function xM(t,e,n){const{nodeCount:i}=t;if(i===0)return;const r=t.edgeList(),s=new Uint8Array(i);let o=0,l=0;const a=d=>{s[d]!==1&&(s[d]=1,d!==o&&l++,o++)};for(const d of e)a(r.src[d]),a(r.dst[d]);const c=i-o;c>0&&n(Ve.ISOLATED_NODES,`${c} node${O(c)} ${C(c,"has","have")} no edge and cannot be written by the edge table; write the node table (table: "nodes") to keep them`,null,c),l>0&&n(Ve.NODE_ORDER,`${l} node${O(l)} ${C(l,"is","are")} first mentioned by an edge row out of index order; a re-import numbers nodes by first appearance`,null,l)}function ba(t){return t.toLowerCase()}function KT(t,e,n,i,r,s){const o=[];for(const l of t){const{name:a,role:c}=l.meta;if(l===i||l===r||c!==null&&IM.has(c))continue;const d=l.length-l.nullCount;MM(a,e,n,i,d,s)||qt([a],qo)>=0&&!UM(a,e,r,d,s)||o.push({column:l,header:a})}return o}function MM(t,e,n,i,r,s){const o=ba(t),l=e==="edge"?qt([t],Ly)>=0:!1;return n.has(o)||l||i!==null&&ba(i.meta.name)===o?(s?.(Ve.RESERVED_NAME,`${e} column "${t}" is not written: the name is reserved for the ${l?"edge id":o} column`,t,r),!0):!1}function UM(t,e,n,i,r){return n!==null?(r?.(Ve.RESERVED_NAME,`${e} column "${t}" is not written: the name is reserved for the label column`,t,i),!1):(r?.(Ve.ROLE_ASSUMED,`${e} column "${t}" reads back with the label role (string)`,t,i),!0)}function qp(t,e,n,i,r,s){if(t===null)return;const{name:o}=t.meta;qt([o],n)<0&&s(Ve.ROLE_NAME,`${i} column "${o}" (${e}) is written under its name, which the importer does not map to the ${e} role`,o,$E(t,r)),t.dtype!=="string"&&t.dtype!=="dict"&&s(Ve.TEXT_ROLE,`${i} column "${o}" (${e}) is ${t.dtype}; it reads back as string`,o,$E(t,r)),My(t,i,r,s,!0)}function $E(t,e){let n=0;for(const i of e)t.isSet(i)&&n++;return n}const XT={bool:0,i32:1,f64:2,string:3},GM=["bool","i32","f64","string"];function My(t,e,n,i,r=!1){const{name:s,dtype:o}=t.meta,l=`${e} column "${s}"`;if(t.dtype==="f32"||t.dtype==="f64"){const d=jM(t,n);d>0&&i(Ve.NONFINITE,`${l}: ${d} non-finite value${O(d)} ${C(d,"reads","read")} back as text`,s,d);return}if(o!=="string"&&o!=="dict")return;const a=FM(t,n);if(r||a.widest<0)return;const c=a.candidate&&a.heuristic.decide()==="dict";if(a.widest<XT.string&&!c){i(Ve.TEXT_INFERRED,`${l}: every value reads back as ${GM[a.widest]}`,s,a.set);return}o==="dict"&&!c?i(Ve.STORAGE_CLASS_CHANGED,`${l}: reads back as string (cardinality too high for a dict)`,s,null):o==="string"&&c&&i(Ve.STORAGE_CLASS_CHANGED,`${l}: reads back as dict (low cardinality)`,s,null)}function jM(t,e){let n=0;const{components:i}=t.meta,{data:r}=t;for(const s of e)if(t.isSet(s)){for(let o=0;o<i;o++)if(!Number.isFinite(r[s*i+o])){n++;break}}return n}function FM(t,e){let n=-1,i=!0,r=0;const s=new no(rf);for(const o of e){const l=t.isSet(o)?t.value(o):null;if(typeof l!="string")continue;r++;const a=qn(l);n=Math.max(n,XT[a]),s.decided||(i&&=a==="string",s.observe(l))}return{widest:n,candidate:i,set:r,heuristic:s}}function zM(t,e,n){return!t.directed||!e.folding.sourceDirected(n)?"Undirected":"Directed"}function WM(t,e){return e!==null?`${t}:${e}`:t.includes(":")?`${t}:`:t}function BM(t,e,n){const i=t[e[n]];let r=n;for(;r<e.length&&t[e[r]]===i;)r++;return r}function*HM(t,e){const{delimiter:n,newline:i}=e.csv,r=g=>`"${g.replaceAll('"','""')}"`,s=g=>Ws.some(m=>g.includes(m))?r(g):hf(g,n),o=g=>/^[#%]/.test(g)?r(g):s(g),l=t.edgeList(),{edgeRows:a,weights:c}=e,d=new Uint8Array(t.nodeCount);let u=0;const f=()=>{for(;u<d.length&&d[u]===1;)u++};function*h(g){for(let m=u;m<=g;m++)d[m]===0&&(d[m]=1,yield o(e.idText(m))+i);f()}let p=0;for(;p<a.length;){const g=l.src[a[p]],m=BM(l.src,a,p),y=[];let b=-1,_=!0;const S=$=>{d[$]===0&&(d[$]=1,_&&=$===u+y.length,y.push($),b=Math.max(b,$))};S(g);for(let $=p;$<m;$++)S(l.dst[a[$]]);if(!_){for(const $ of y)d[$]=0;yield*h(b)}f();const T=[o(e.idText(g))];for(let $=p;$<m;$++){const D=a[$];T.push(s(WM(e.idText(l.dst[D]),c.weighted?c.text(D):null)))}yield T.join(n)+i,p=m}yield*h(t.nodeCount-1)}function*CE(t,e){e.csv.table==="adjacency"?yield*HM(t,e):e.csv.table==="nodes"?yield*VM(t,e):yield*YM(t,e)}function qT(t){const e=i=>hf(i,t);return{quote:e,cell:(i,r)=>{const s=CM(i,r);return s===null?"":e(s)}}}function*VM(t,e){const{csv:n}=e,{delimiter:i,newline:r}=n,{quote:s,cell:o}=qT(i),l=[n.dialect.id];e.nodeLabel!==null&&l.push(e.nodeLabel.meta.name);for(const{header:a}of e.nodeColumns)l.push(a);n.header&&(yield l.map(s).join(i)+r);for(let a=0;a<t.nodeCount;a++){const c=[s(e.idText(a))];e.nodeLabel!==null&&c.push(o(e.nodeLabel,a));for(const{column:d}of e.nodeColumns)c.push(o(d,a));yield c.join(i)+r}}function*YM(t,e){const{csv:n}=e,{delimiter:i,newline:r}=n,{quote:s,cell:o}=qT(i);n.header&&(yield KM(e).map(s).join(i)+r);const l=t.edgeList();for(const a of e.edgeRows){const c=[s(e.idText(l.src[a])),s(e.idText(l.dst[a]))];n.dialect.type!==null&&c.push(zM(t,e,a)),e.edgeId!==null&&c.push(o(e.edgeId,a)),e.edgeLabel!==null&&c.push(o(e.edgeLabel,a)),e.weights.weighted&&c.push(e.weights.text(a)??"");for(const{column:d}of e.edgeColumns)c.push(o(d,a));yield c.join(i)+r}}function KM(t){const{dialect:e}=t.csv,n=[e.source,e.target];e.type!==null&&n.push(e.type),t.edgeId!==null&&n.push(t.edgeId.meta.name),t.edgeLabel!==null&&n.push(t.edgeLabel.meta.name),t.weights.weighted&&n.push(e.weight);for(const{header:i}of t.edgeColumns)n.push(i);return n}function vE(t,e){const n=YT(t,e,!1),i=n.notes.find(r=>r.code===Ve.ID_TEXT_COLLISION);if(i!==void 0)throw new N("E_INVALID_ID",i.message,{reason:"collision",count:i.count});return n}function XM(t){const{csv:e}=t;if(e.header||e.table==="adjacency")return[];const n=e.table==="nodes"?qM(t):JM(t);if(n.length===0)return[];const i=n.map(r=>JSON.stringify(r)).join(", ");return[Object.freeze({code:Ve.HEADERLESS,message:`without a header the file is read back by position (${e.table==="nodes"?"id":"source, target, weight"}, then unnamed columns), so ${n.length===1?"the column":"the columns"} ${i} ${C(n.length,"reads","read")} back unnamed or in another column's place; write the header, or for an edge list pass dialect: "generic" and write only source, target and weight`,column:null,count:n.length,columns:Object.freeze([...n])})]}function qM(t){return[...t.nodeLabel===null?[]:[t.nodeLabel.meta.name],...t.nodeColumns.map(n=>n.header)]}function JM(t){const{dialect:e}=t.csv,n=[];return e.type!==null&&n.push(e.type),t.edgeId!==null&&n.push(t.edgeId.meta.name),t.edgeLabel!==null&&n.push(t.edgeLabel.meta.name),t.weights.weighted&&n.length>0&&n.push(e.weight),n.push(...t.edgeColumns.map(i=>i.header)),n}function ZM(t,e){const n=YT(t,e,!0);return Object.freeze([...Un(t,VT,n.common,{roles:TM,...n.csv.table==="nodes"?{tables:["node"]}:{}}),...n.notes,...XM(n)])}const QM=Object.freeze({format:"csv",options:Object.freeze(["delimiter","dialect","header","newline","table"]),capabilities:VT,check:ZM,export(t,e){return ti(CE(t,vE(t,e)))},exportToString(t,e){return ni(CE(t,vE(t,e)))}});Object.freeze({...xn,...Pn,PRECISION:re,EMPTY_INPUT:AT,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,NO_ENDPOINT_COLUMNS:yd,NO_ID_COLUMN:Vp,FIELD_COUNT:Yp,MISSING_ENDPOINT:TT,MISSING_ID:Kp,BAD_TYPE:IT,UNCLOSED_QUOTE:Oy,QUOTE:Ny,NO_DATA_ROWS:$T,DUPLICATE_NODE:CT,DUPLICATE_EDGE_ID:DT,ID_MERGED:Py,COLUMN_MISSING:vT,ROLE_TAKEN:tM,COLUMN_RENAMED:ln,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or,WIDENING_UNSUPPORTED:af,OTHER_FORMAT:kT,STRAY_QUOTE:RT,COMMENT_DIRECTION:Xp,TYPE_COLUMN_IGNORED:LT,TRAILING_HEADER_DELIMITER:PT,SINGLE_COLUMN:xT,AMBIGUOUS_COLUMN:MT,PADDED_ID:UT,COMMENT_LIKE_RECORD:GT,TRAILING_DELIMITER:jT,WEIGHT_AS_ATTRIBUTE:FT});const ou=`${String.fromCodePoint(0)}cx:`,e3=/"\\u0000cx:(-?\d+)"/g,t3=/^-?[1-9]\d{15,}$/;function JT(t){return typeof t=="number"?Number.isSafeInteger(t):t3.test(t)&&!Number.isSafeInteger(Number(t))}function n3(t,e,n){const{ids:i}=t,r=[],s=new Set;for(let a=0;a<i.size;a++){const c=i.idOf(a);JT(c)?typeof c=="number"&&s.add(c):r.push(a)}if(r.length>0&&e==="error"){const a=i.idOf(r[0]);throw new N("E_INVALID_ID",`${r.length} node id${O(r.length)} cannot be written as ${n} integers (first: ${JSON.stringify(a)} at index ${r[0]}); pass sanitizeIds: "mangle" to rewrite them`,{reason:"charset",charset:"integer",count:r.length,index:r[0]})}const o=new Map;let l=0;for(const a of r){for(;s.has(l);)l++;s.add(l),o.set(a,l)}return{changed:r.length,idAt:a=>{const c=o.get(a)??i.idOf(a);return typeof c=="string"?`${ou}${c}`:c},isChanged:a=>o.has(a),originalAt:a=>i.idOf(a)}}function i3(t,e){let n=-1n;for(let r=0;r<e;r++){const s=t.idAt(r),o=BigInt(typeof s=="number"?s:s.slice(ou.length));o>n&&(n=o)}const i=n+1n;return i<=BigInt(Number.MAX_SAFE_INTEGER)?Number(i):`${ou}${i.toString()}`}function r3(t){let e=0;for(let n=0;n<t.ids.size;n++)JT(t.ids.idOf(n))||e++;return e}function ZT(t,e,n,i,r){const s=r3(t);s>0&&r(e.sanitizeIds==="mangle"?w.ID_MANGLED:w.ID_CHARSET,e.sanitizeIds==="mangle"?`${s} node id${O(s)} ${C(s,"is","are")} not integers, so they are renumbered; the original ids are written to the ${i} attribute, and an import with restoreMangledIds: true reads them back`:`${s} node id${O(s)} ${C(s,"is","are")} not integers, so the save fails unless sanitizeIds is "mangle"`,null,s);try{return n3(t,e.sanitizeIds,n)}catch(o){if(o instanceof N)return o;throw o}}function Th(t,e){switch(t){case"f64":return e?"long":"double";case"f32":return"double";case"i32":case"u8":return"integer";case"u32":return"long";case"bool":return"boolean";default:return"string"}}function s3(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!Number.isSafeInteger(t.value(e)))return!1;return!0}function QT(t){const{meta:e}=t,n=e.origin?.type??null,i=n!==null&&n.endsWith("long")&&(e.dtype!=="f64"||s3(t));return e.dtype==="list"?e.itemDtype===null||e.itemDtype==="json"?"string":`list_of_${Th(e.itemDtype,i)}`:e.components>1?`list_of_${Th(e.dtype,!1)}`:Th(e.dtype,i)}function o3(t){let e=0;for(let n=0;n<t.length;n++)if(t.isSet(n)){const i=t.value(n);(!Number.isFinite(i[0])||!Number.isFinite(i[1]))&&e++}return e}function e1(t,e,n=null){const i=t.edges.byRole("id"),r=new Set;let s=0;const o=l3(i,t.edgeCount,r);for(let c=0;n!==null&&c<t.nodeCount;c++){const d=n.idAt(c);typeof d=="number"&&r.add(d)}let l=0;const a=[];for(let c=0;c<t.edgeCount;c++){let d=o[c];if(d===null){for(;r.has(l);)l++;d=l,r.add(l),s++}a.push(d)}return i!==null&&s>0&&e(w.EDGE_IDS_GENERATED,`${s} edge${O(s)} ${C(s,"has","have")} no distinct integer id in "${i.meta.name}"; they are written with generated ids`,i.meta.name,s),i!==null&&i.dtype!=="f64"&&e(w.DTYPE,`edge id column "${i.meta.name}" is ${i.dtype}; CX edge ids are integers and read back as f64`,i.meta.name,t.edgeCount-i.nullCount),a}function l3(t,e,n){const i=new Array(e).fill(null);if(t===null)return i;for(let r=0;r<e;r++){const s=t.isSet(r)?t.value(r):void 0,o=typeof s=="number"||typeof s=="string"?Number(s):Number.NaN;Number.isSafeInteger(o)&&!n.has(o)&&(i[r]=o===0?0:o,n.add(o))}return i}function t1(t,e,n,i,r){if(!t.directed)r(i,`the snapshot is undirected; every edge is written as a directed edge (${t.edgeCount} edge${O(t.edgeCount)})`,null,t.edgeCount);else if(n.onMixedDirection!=="error"){let s=0;for(let o=0;o<t.edgeCount;o++)!e.folded(o)&&!e.sourceDirected(o)&&s++;s>0&&r(i,`${s} undirected edge${O(s)} ${C(s,"is","are")} written as one directed edge each (a pair folded to its primary); CX has no undirected edge`,null,s)}e.mutualCount>0&&r(w.MUTUAL_EXPANDED,`${e.mutualCount} mutual pair${O(e.mutualCount)} ${C(e.mutualCount,"is","are")} written as two directed edges; the mutual mark is lost`,null,e.mutualCount)}function a3(){const t=[];return{notes:t,note:(n,i,r=null,s=null)=>{t.push(Object.freeze({code:n,message:i,column:r,count:s}))}}}function Di(t){const e=JSON.stringify(t,(n,i)=>Object.is(i,-0)?`${ou}-0`:i);return e.includes(String.raw`\u0000cx:`)?e.replaceAll(e3,"$1"):e}function*n1(t,e){yield`{${JSON.stringify(t)}:[`;let n=!0;for(const i of e)yield n?`
|
|
30
|
+
${i}`:`,
|
|
31
|
+
${i}`,n=!1;yield`]},
|
|
32
|
+
`}const i1=new RegExp("(?<![0-9.])\\d{16}"),c3=new RegExp([/\d[eE]\+?0*(?:1[5-9]|[2-9]\d|[1-9]\d{2,})/,/\d[eE]-0*(?:[3-9]\d{2}|[1-9]\d{3,})/,new RegExp("(?<![\\d.])(?=(?:\\d\\.?){16})\\d+\\.\\d+[eE]")].map(t=>t.source).join("|")),d3=`${String.fromCodePoint(0)}graph-io`,DE=[["-Infinity",-1/0],["Infinity",1/0],["NaN",Number.NaN]],u3=/^-?(0|[1-9]\d*)$/,f3=/^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;function*h3(t){let e=t.indexOf('"');for(;e>=0;){let n=e+1;for(;n<t.length&&t[n]!=='"';)n+=t[n]==="\\"?2:1;if(n>=t.length)return;yield t.slice(e,n+1),e=t.indexOf('"',n+1)}}function p3(t){let e=t;if(/\\u0000/i.test(t)){const i=[];for(const r of h3(t))r.includes("\\")&&i.push(g3(r));e=`${i.join(`
|
|
33
|
+
`)}
|
|
34
|
+
${t}`}let n=0;for(;e.includes(`graph-io${n===0?"":String(n)}:`);)n++;return`${d3}${n===0?"":String(n)}:`}function g3(t){try{return String(JSON.parse(t))}catch{return t}}function m3(t){const e=Number(t);if(!Number.isFinite(e))return!0;if(e===0)return/[1-9]/.test(t.split(/[eE]/)[0]);if(Number.isSafeInteger(e)||!Number.isInteger(e))return!1;const n=f3.exec(t);if(n===null)return!1;const i=dT(n[2]+(n[3]??"")),r=Number(n[4]??"0")-(n[3]??"").length+((n[2]+(n[3]??"")).length-i.length);return i.replace(/^0+/,"").length<=15||r<0?!1:BigInt(i)*10n**BigInt(r)!==BigInt(Math.abs(e))}function Uy(t,e={}){const n=e.nonstandard??!0,i=e.exactSentinel??!1,r=p3(t),s=`${r}exact:`,o=[],l=new Set,a=[],c=[],d=[];let u=!0,f=0,h=0;const p=t.length;for(;h<p;){const y=t[h];if(y==='"'){for(h++;h<p&&t[h]!=='"';)h+=t[h]==="\\"?2:1;h++,u=!1;continue}if(y==="{"||y==="[")d.push(y==="["),u=y==="[";else if(y==="}"||y==="]")d.pop(),u=!1;else if(y===":")u=!0;else if(y===",")u=d.at(-1)??!1;else if(u&&y!==" "&&y!==" "&&y!==`
|
|
35
|
+
`&&y!=="\r"){u=!1;const b=n?DE.find(([T])=>t.startsWith(T,h)):void 0;let _=h,S=null;if(b!==void 0)_=h+b[0].length,l.add(b[0]),S=JSON.stringify(`${r}${b[0]}`);else if(y==="-"||y>="0"&&y<="9"){for(_=h+1;_<p&&"0123456789+-.eE".includes(t[_]);)_++;const T=t.slice(h,_);u3.test(T)?Number.isSafeInteger(Number(T))||(a.push(T),S=i?JSON.stringify(`${s}${T}`):`"${T}"`):m3(T)&&c.push(T)}S!==null&&(o.push(t.slice(f,h),S),f=_),h=Math.max(_,h+1);continue}h++}o.push(t.slice(f));const g=(y,b)=>{if(typeof b=="string"&&b.startsWith(r)){const _=DE.find(([S])=>S===b.slice(r.length));return _===void 0?b:_[1]}return b},m=(y,b)=>typeof b=="string"&&b.startsWith(s)?new vn(b.slice(s.length)):b;return{text:o.join(""),tokens:l,bigIntegers:a,inexact:c,revive:g,reviveExact:m}}const y3=32;function b3(t){const e=[],n=[],i=[];let r=0;const s=t.length;let o=0;for(;o<s;){const l=t.codePointAt(o);if(l===123||l===91)E3(n,i,r,l===91),r++;else if(l===125||l===93)r--;else if(l===34){const a=lu(t,o+1),c=r>0?n[r-1]:null;c!==null&&c[0]!==-1&&N3(t,a+1)&&w3(t,o+1,a,c,i,r-1)&&e.push({key:t.slice(o+1,a),offset:o}),o=a}o++}return e}function E3(t,e,n,i){t.length===n&&(t.push([]),e.push(null)),t[n].length=0,i&&t[n].push(-1),e[n]=null}function w3(t,e,n,i,r,s){const o=r[s];if(o!==null){const a=t.slice(e,n);return o.has(a)||(o.add(a),!1)}const l=n-e;for(let a=0;a<i.length;a+=2)if(i[a+1]-i[a]===l&&_3(t,i[a],e,l))return!0;if(i.push(e,n),i.length>2*y3){const a=new Set;for(let c=0;c<i.length;c+=2)a.add(t.slice(i[c],i[c+1]));r[s]=a}return!1}function _3(t,e,n,i){for(let r=0;r<i;r++)if(t.codePointAt(e+r)!==t.codePointAt(n+r))return!1;return!0}function lu(t,e){for(let n=t.indexOf('"',e);n>=0;n=t.indexOf('"',n+1)){let i=0;for(;t.codePointAt(n-1-i)===92;)i++;if(i%2===0)return n}return t.length}function S3(t,e){let n=lr(t,0);for(const r of e){let s=-1;if(typeof r=="number"&&t.codePointAt(n)===91){let o=0;Ih(t,n,!1,(l,a)=>{o++===r&&(s=a)})}else typeof r=="string"&&t.codePointAt(n)===123&&Ih(t,n,!0,(o,l)=>{o===r&&(s=l)});if(s<0)return null;n=s}if(t.codePointAt(n)!==123)return null;const i=new Set;return Ih(t,n,!0,r=>i.add(r)),[...i]}function Ih(t,e,n,i){let r=lr(t,e+1);const s=n?125:93;for(;r<t.length&&t.codePointAt(r)!==s;){let o=null;if(n){const l=lu(t,r+1);o=JSON.parse(t.slice(r,l+1)),r=lr(t,lr(t,l+1)+1)}i(o,r),r=lr(t,O3(t,r)),t.codePointAt(r)===44&&(r=lr(t,r+1))}}function O3(t,e){const n=t.codePointAt(e);if(n===34)return lu(t,e+1)+1;if(n!==123&&n!==91){let s=e;for(;s<t.length&&!s1(t.codePointAt(s)??32);)s++;return s}let i=0,r=e;for(;r<t.length;){const s=t.codePointAt(r);if(s===34)r=lu(t,r+1);else if(s===123||s===91)i++;else if((s===125||s===93)&&--i===0)return r+1;r++}return t.length}function lr(t,e){let n=e;for(;n<t.length&&pf(t.codePointAt(n));)n++;return n}function N3(t,e){let n=e;for(;n<t.length&&pf(t.codePointAt(n));)n++;return t.codePointAt(n)===58}class vn{constructor(e){this.digits=e}toJSON(){return Number(this.digits)}}function A3(t){if(!i1.test(t))return{value:JSON.parse(t),exact:!1};const e=Uy(t,{nonstandard:!1,exactSentinel:!0});return e.bigIntegers.length===0?{value:JSON.parse(t),exact:!1}:{value:JSON.parse(e.text,e.reviveExact),exact:!0}}function qe(t,e){if(t instanceof vn)return e?.(t.digits),Number(t.digits);if(Array.isArray(t))return t.map(n=>qe(n,e));if(typeof t=="object"&&t!==null){const n={};for(const[i,r]of Object.entries(t))Gy(n,i,qe(r,e));return n}return t}function Gy(t,e,n){e==="__proto__"?Object.defineProperty(t,e,{value:n,enumerable:!0,writable:!0,configurable:!0}):t[e]=n}function T3(t){if(!/NaN|Infinity/.test(t))return null;const e=Uy(t,{nonstandard:!0,exactSentinel:!0});if(e.tokens.size===0)return null;try{return{value:JSON.parse(e.text,(i,r)=>e.reviveExact(i,e.revive(i,r))),exact:e.bigIntegers.length>0,tokens:e.tokens}}catch{return null}}const I3=String.raw`\uD800-\uDFFF`,kE=new RegExp("[\\ud800-\\udbff](?![\\udc00-\\udfff])|(?<![\\ud800-\\udbff])[\\udc00-\\udfff]","g"),$3=/\\u[dD][89a-fA-F]|[\ud800-\udfff]/;function Jp(t,e){if(typeof t=="string"){const n=t.replaceAll(kE,"�");return n!==t&&e.count++,n}if(Array.isArray(t)){for(let n=0;n<t.length;n++)t[n]=Jp(t[n],e);return t}if(M(t)){const n=Object.keys(t),i=n.map(o=>o.replaceAll(kE,"�")),r=i.some((o,l)=>o!==n[l]),s=r?{}:t;return n.forEach((o,l)=>{i[l]!==o&&e.count++,r&&Object.hasOwn(s,i[l])&&e.collisions.push(i[l]),Gy(s,i[l],Jp(t[o],e))}),s}return t}function Zp(t){return Array.isArray(t)?t.reduce((e,n)=>e+Zp(n),0):M(t)?Object.keys(t).reduce((e,n)=>e+1+Zp(t[n]),0):0}function C3(t){const e=[];let n=0;for(;n<t.length;){const i=t[n];if(i==="{")e.push(new Set);else if(i==="[")e.push(null);else if(i==="}"||i==="]")e.pop();else if(i==='"'){const r=n;n=r1(t,n+1);const s=e.at(-1)??null;if(s!==null&&t[lr(t,n+1)]===":"){const o=JSON.parse(t.slice(r,n+1));if(s.has(o))return o;s.add(o)}}n++}return null}function r1(t,e){let n=e;for(;n<t.length&&t[n]!=='"';)n+=t[n]==="\\"?2:1;return n}const v3=/"\s*:/g;function D3(t,e,n,i){let r=e;if($3.test(t)){const s={count:0,collisions:[]};r=Jp(r,s);for(const o of s.collisions)i.warnOnce("validation-error",fe,`an object holds two keys that are the same key ${JSON.stringify(o)} once their lone surrogates are replaced with U+FFFD; the later value is read`,{line:n,element:o},`${fe}:json:${o}`);s.count>0&&i.error("validation-error",ie,`${s.count} string${O(s.count)} ${C(s.count,"holds","hold")} a lone surrogate (an unpaired ${I3} escape); each is read with U+FFFD in its place`,{line:n})}if(typeof r=="object"&&r!==null&&(t.match(v3)?.length??0)>Zp(r)){const s=C3(t);s!==null&&i.warnOnce("validation-error",fe,`an object holds the key ${JSON.stringify(s)} twice; the later value is read`,{line:n,element:s},`${fe}:json:${s}`)}return r}class et extends Error{constructor(e,n,i=!1){super(e),this.name="JsonScanError",this.line=n,this.empty=i}}const pf=t=>t===32||t===10||t===13||t===9,s1=t=>pf(t)||t===44||t===93||t===125||t===58,RE=/["\\]/g,gf=200;class k3{constructor(e){this.buf="",this.pos=0,this.linesBefore=1,this.countedTo=0,this.countedLines=0,this.parts=null,this.captureStart=0,this.deepest=0,this.iterator=e[Symbol.asyncIterator]()}async fill(){this.parts!==null&&(this.parts.push(this.buf.slice(this.captureStart)),this.captureStart=0),this.linesBefore+=LE(this.buf,0,this.buf.length),this.countedTo=0,this.countedLines=0;const e=this.buf.endsWith("\r");for(;;){const n=await this.iterator.next();if(n.done===!0)return this.buf="",this.pos=0,!1;if(n.value.length>0)return e&&n.value.startsWith(`
|
|
36
|
+
`)&&this.linesBefore--,this.buf=n.value,this.pos=0,!0}}line(){const e=Math.min(this.pos,this.buf.length);return e<this.countedTo&&(this.countedTo=0,this.countedLines=0),this.countedLines+=LE(this.buf,this.countedTo,e),this.countedTo=e,this.linesBefore+this.countedLines}ahead(e){return this.buf.slice(this.pos,this.pos+e)}async peek(){for(;;){for(;this.pos<this.buf.length&&pf(this.buf.charCodeAt(this.pos));)this.pos++;if(this.pos<this.buf.length)return this.buf[this.pos];if(!await this.fill())return""}}beginCapture(){this.parts=[],this.captureStart=this.pos}endCapture(){const e=this.parts??[];return e.push(this.buf.slice(this.captureStart,this.pos)),this.parts=null,e.length===1?e[0]:e.join("")}dropCapture(){this.parts=null}async skipValue(e=0){let n=e;if(this.deepest=n,n===0){const i=this.buf.charCodeAt(this.pos);if(i===34){this.pos++,await this.skipString();return}if(i!==123&&i!==91){await this.skipScalar();return}}for(;;){if(this.pos>=this.buf.length&&!await this.fill())throw new et("the document ends inside a value",this.line());const i=this.buf.charCodeAt(this.pos);if(this.pos++,i===34)await this.skipString();else if(i===123||i===91)n++,n>this.deepest&&(this.deepest=n);else if((i===125||i===93)&&(n--,n===0))return}}async skipString(){for(;;){RE.lastIndex=this.pos;const e=RE.exec(this.buf);if(e===null){if(this.pos=this.buf.length,!await this.fill())throw new et("the document ends inside a string",this.line());continue}if(this.pos=e.index+1,e[0]==='"')return;if(this.pos>=this.buf.length&&!await this.fill())throw new et("the document ends inside a string",this.line());this.pos++}}async skipScalar(){for(;;){for(;this.pos<this.buf.length&&!s1(this.buf.charCodeAt(this.pos));)this.pos++;if(this.pos<this.buf.length||!await this.fill())return}}async readString(){this.beginCapture(),this.pos++,await this.skipString();const e=this.endCapture();try{return JSON.parse(e)}catch(n){throw new et(`invalid string: ${o1(n)}`,this.line())}}}function LE(t,e,n){let i=0;for(let r=e;r<n;r++){const s=t.codePointAt(r);(s===10||s===13&&t.codePointAt(r+1)!==10)&&i++}return i}function o1(t){return t instanceof Error?t.message:String(t)}function Ea(t,e,n){let i;try{i=A3(t)}catch(r){const s=n===null?null:T3(t);if(s===null)throw new et(`invalid JSON: ${o1(r)}`,e);n?.warnOnce("coercion",Ju,`the document uses the non-standard token${O(s.tokens.size)} ${[...s.tokens].join(", ")}, which strict JSON does not allow; read as numbers`,{line:e}),i=s}return n!==null&&(i={...i,value:D3(t,i.value,e,n)}),i}function R3(t){return t.startsWith("<")?"; the input looks like HTML or XML (an error page saved as the file?), not JSON":t.startsWith("PK")?"; the input is a ZIP archive (a Cytoscape session .cys is read by the cys importer), not JSON":""}async function*l1(t,e=null){const n=new k3(t),i=await n.peek();if(i==="")throw new et("the input is empty",1,!0);const r=R3(n.ahead(16));if(r===""&&n.ahead(8).includes(String.fromCodePoint(0)))throw new et('the input holds NUL characters: UTF-16 without a byte order mark (pass the encoding option, such as "utf-16le"), or binary data; not JSON',n.line());if(i==="["){n.pos++,yield*P3(n,e);return}const s=n.line();if(i==="{"){yield{kind:"root",value:void 0,object:!0,line:s};return}yield{kind:"root",value:await L3(n,s,r),object:!1,line:s}}async function L3(t,e,n){t.beginCapture(),await t.skipValue();let i;try{({value:i}=Ea(t.endCapture(),e,null))}catch(r){throw r instanceof et&&n!==""?new et(`${r.message}${n}`,r.line):r}if(await t.peek()!=="")throw new et("unexpected text after the document",t.line());return i}async function*P3(t,e){let n=0,i=await t.peek();for(i==="]"&&t.pos++;i!=="]";){if(yield*x3(t,n,e),n++,i=await t.peek(),i!==","&&i!=="]")throw new et(i===""?"the document ends before its closing bracket":`expected "," or "]", found "${i}"`,t.line());t.pos++}if(await t.peek()!=="")throw new et("unexpected text after the closing bracket",t.line())}async function*x3(t,e,n){const i=await t.peek(),r=t.line();if(i===""||i==="]"||i===",")throw new et(i===""?"the document ends inside its array":`unexpected "${i}"`,r);if(t.beginCapture(),i!=="{"){await t.skipValue(),yield PE(t,e,r,n);return}if(t.pos++,await t.peek()!=='"'){await t.skipValue(1),yield PE(t,e,r,n);return}const s=t.endCapture(),o=t.line(),l={others:[],firstBlock:null,deep:0};let a=",",c=0;for(;a===",";){const d=await M3(t);if(yield*U3(t,d,c,e,l,n),c++,a=await t.peek(),a!==","&&a!=="}")throw new et(a===""?"the document ends inside a member":`expected "," or "}" after the key "${d.name}"`,t.line());t.pos++}yield*G3(l,e,r,{outer:s,firstLine:o},n)}function PE(t,e,n,i){if(t.deepest>gf)return t.dropCapture(),{kind:"deep",aspect:null,block:e,depth:t.deepest,line:n};const r=t.endCapture(),s=Ea(r,n,i);return{kind:"member",block:e,value:s.value,exact:s.exact,text:r,line:n}}async function M3(t){if(await t.peek()!=='"')throw new et("expected a key",t.line());const e=t.line(),n=await t.readString();if(await t.peek()!==":")throw new et(`expected ":" after the key "${n}"`,t.line());return t.pos++,{name:n,line:e}}async function*U3(t,e,n,i,r,s){if(await t.peek()==="["){t.pos++,yield{kind:"block",aspect:e.name,block:i,shared:n>0,line:e.line},r.firstBlock??=e.name,yield*j3(t,e.name,i,s);return}t.beginCapture(),await t.skipValue(),t.deepest+1>gf?(t.dropCapture(),r.deep=Math.max(r.deep,t.deepest+1),r.others.push({key:e.name,text:null,line:e.line})):r.others.push({key:e.name,text:t.endCapture(),line:e.line})}function*G3(t,e,n,i,r){const{others:s,firstBlock:o,deep:l}=t;if(o!==null){for(const u of s)u.text!==null&&Ea(u.text,u.line,null);s.length>0&&(yield{kind:"extraKeys",aspect:o,block:e,keys:s.map(u=>u.key),line:s[0].line});return}if(l>0){yield{kind:"deep",aspect:s[0].key,block:e,depth:l,line:n};return}const a=s.map(u=>[JSON.stringify(u.key),u.text??""].join(":")),c=`${i.outer}${a.join(",")}}`,d=Ea(c,i.firstLine,r);yield{kind:"member",block:e,value:d.value,exact:d.exact,text:c,line:n}}async function*j3(t,e,n,i){if(await t.peek()==="]"){t.pos++;return}for(;;){if(await t.peek()==="")throw new et(`the document ends inside the "${e}" block`,t.line());const s=t.line();if(t.beginCapture(),await t.skipValue(),t.deepest>gf)t.dropCapture(),yield{kind:"deep",aspect:e,block:n,depth:t.deepest,line:s};else{const l=t.endCapture(),a=Ea(l,s,i);yield{kind:"element",aspect:e,block:n,value:a.value,exact:a.exact,text:l,line:s}}const o=await t.peek();if(o===","){t.pos++;continue}if(o==="]"){t.pos++;return}throw new et(o===""?`the document ends inside the "${e}" block`:`expected "," or "]" in the "${e}" block, found "${o}"`,t.line())}}function a1(t,e){const n=e.aspect===null?"a member of the document":`an element of "${e.aspect}"`;t.error("parse-error",mt,`${n} is nested ${e.depth} levels deep, more than the ${gf} a graph keeps; skipped`,{line:e.line,element:e.aspect})}function c1(t,e){return n=>{t.warnOnce("precision",re,`an aspect kept in ${e} holds ${n}, beyond 2^53; it is kept as the nearest double`,{element:e},`${re}:kept`)}}function d1(t,e){e.shared&&t.warnOnce("coercion",iy,`the "${e.aspect}" aspect shares an array member with another aspect; each is read as its own fragment`,{line:e.line,element:e.aspect})}const F3=/^-?(0|[1-9]\d*)$/;function au(t,e=!1){if(t instanceof vn)return{id:t.digits,note:"precision"};if(typeof t=="number"){if(Number.isSafeInteger(t))return{id:t===0?0:t,note:e?"text":null};throw xE(t,Number.isInteger(t)?"an integer beyond 2^53 written inexactly":"not an integer")}if(typeof t=="string"&&t!=="-0"&&F3.test(t)){const n=Number(t);return Number.isSafeInteger(n)?{id:n,note:"text"}:{id:t,note:"precision"}}throw xE(t,"a CX id is an integer")}function xE(t,e){const n=typeof t=="string"||typeof t=="number"?JSON.stringify(t):typeof t;return new N("E_INVALID_ID",`invalid id ${t===null?"null":n}: ${e}`,{reason:e})}const ME=/-?\d[\d.eE+-]*/y;function u1(t,e,n=1){const i=JSON.stringify(e);let r=0,s=0;for(;s<t.length;){const o=t[s];if(o==="{"||o==="[")r++;else if(o==="}"||o==="]")r--;else if(o==='"'){const l=s;s=r1(t,s+1);const a=lr(t,s+1);if(r===n&&t.startsWith(i,l)&&t[a]===":")return z3(t,lr(t,a+1))}s++}return!1}function z3(t,e){ME.lastIndex=e;const n=ME.exec(t);return n!==null&&/[.eE]/.test(n[0])}const jy="position",W3="z";function f1(t,e=2){return{name:jy,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,extra:{sourceDims:e,units:"file"},origin:{format:t,namespace:"cytoscape"}}}function Qp(t){return{name:W3,dtype:"f64",nullable:!0,origin:{format:t,id:null,namespace:"cytoscape"},extra:{cytoscape:"z"}}}function h1(t){let e="utf-8";return t.byteLength>=2&&t[0]===255&&t[1]===254?e="utf-16le":t.byteLength>=2&&t[0]===254&&t[1]===255&&(e="utf-16be"),new TextDecoder(e).decode(t).replace(/^\uFEFF/,"")}const B3=new Set(["metaData","status","numberVerification"]);class p1{constructor(e,n=i=>i){this.counts=new Map,this.blocks=new Map,this.declared=new Map,this.metaDataBlocks=0,this.networkBlocks=0,this.postMetadata=!1,this.statusSeen=!1,this.status=void 0,this.report=e,this.canonical=n}get hasStatus(){return this.statusSeen}block(e,n){if(this.blocks.set(e,(this.blocks.get(e)??0)+1),this.statusSeen&&this.report.warnOnce("validation-error",Bn,`the "${e}" block comes after the status block, which must be last; it is read`,{line:n,element:e},`${Bn}:status`),e==="metaData"){this.metaDataBlocks++,this.networkBlocks>0&&(this.postMetadata=!0),this.metaDataBlocks>2&&this.report.warnOnce("validation-error",Bn,`${this.metaDataBlocks} metaData blocks; a document has at most two (pre and post)`,{line:n,element:e},`${Bn}:metaData`);return}if(e==="status"){this.statusSeen=!0;return}B3.has(e)||(this.networkBlocks++,this.postMetadata&&this.report.warnOnce("validation-error",Bn,`the "${e}" block comes after the post-metadata, where only status is allowed; it is read`,{line:n,element:e},`${Bn}:post`))}element(e,n,i){if(this.counts.set(e,(this.counts.get(e)??0)+1),e==="metaData"){this.readCount(n,i);return}e==="status"&&this.readStatus(n,i)}readCount(e,n){if(!M(e)||e.elementCount===void 0||e.elementCount===null)return;const i=e.elementCount;let r=null;if(i instanceof vn?r=Number(i.digits):typeof i=="number"&&Number.isInteger(i)&&(r=i),typeof e.name!="string"||r===null){const s=i instanceof vn?i.digits:JSON.stringify(i);this.report.warning("validation-error",Fs,`a metaData element declares the elementCount ${s} for the name ${JSON.stringify(e.name)??"undefined"}; not a count of a named aspect, not checked`,{line:n,element:"metaData"});return}this.declared.set(this.canonical(e.name),r)}readStatus(e,n){if(this.status!==void 0&&this.report.warnOnce("validation-error",Bn,"more than one status element; the last is used",{line:n,element:"status"},`${Bn}:status2`),this.status=e,!M(e))return;const i=typeof e.error=="string"?e.error:"";if(e.success===!1){const s=`the producer marked the document as failed${i.length>0?`: ${i}`:""}`;throw this.report.error("validation-error",Vd,s,{line:n,element:"status"}),this.report.abort(s,{code:Vd})}e.success===!0&&i.length>0&&this.report.warning("validation-error",ry,`the producer reports a warning: ${i}`,{line:n,element:"status"})}statusWellFormed(){return M(this.status)&&typeof this.status.success=="boolean"}checkCounts(){for(const[e,n]of this.declared){const i=this.counts.get(e)??0;i!==n&&this.report.warning("validation-error",Fs,`metaData declares ${n} "${e}" element${O(n)}; ${i} ${C(i,"was","were")} read`,{element:e})}}}function M(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&!(t instanceof vn)}function g1(t,e,n,i){const r=o=>(e==="node"?t.nodeColumn(o):t.edgeColumn(o))!==A;let s=n;return r(n.name)&&(s={...n,name:Xt(n.name,null,r)},i.warning("coercion",ln,`${e} column "${n.name}" renamed to "${s.name}": an attribute holds that name`,{element:n.name})),he(t,e,s,i).handle}const v=Object.freeze({VALUE_TOO_LONG:"W_STYLE_VALUE_TOO_LONG",BAD_VALUE:"W_STYLE_BAD_VALUE",UNKNOWN_VALUE:"W_STYLE_UNKNOWN_VALUE",ALPHA_DROPPED:"W_STYLE_ALPHA_DROPPED",COLOR_LIST:"W_STYLE_COLOR_LIST",GRADIENT:"W_STYLE_GRADIENT",UNFILLED:"W_STYLE_UNFILLED",NO_FILL:"W_STYLE_NO_FILL",NO_STROKE:"W_STYLE_NO_STROKE",SIZE_MINIMUM:"W_STYLE_SIZE_MINIMUM",HTML_LABEL:"W_STYLE_HTML_LABEL",RECORD_LABEL:"W_STYLE_RECORD_LABEL",EXTRA_LABELS:"W_STYLE_EXTRA_LABELS",INHERIT_COLOR:"W_STYLE_INHERIT_COLOR",NOT_CARRIED:"W_STYLE_NOT_CARRIED",ANNOTATION_SKIPPED:"W_STYLE_ANNOTATION_SKIPPED",BAD_MAPPING:"W_STYLE_BAD_MAPPING",MAPPING_COLUMN_MISSING:"W_STYLE_MAPPING_COLUMN_MISSING",REFERENCE_CYCLE:"W_STYLE_REFERENCE_CYCLE",UNRESOLVED:"W_STYLE_UNRESOLVED",NESTING:"W_STYLE_NESTING",UNREADABLE:"W_STYLE_UNREADABLE",NO_VIZMAP:"W_STYLE_NO_VIZMAP",VIEW_STYLE_MISSING:"W_STYLE_VIEW_STYLE_MISSING",OTHER_STYLES:"W_STYLE_OTHER_STYLES",OTHER_VIEWS:"W_STYLE_OTHER_VIEWS",SELECTOR:"W_STYLE_SELECTOR",SELECTOR_AS_COLUMN:"W_STYLE_SELECTOR_AS_COLUMN",STATE_ASSUMED:"W_STYLE_STATE_ASSUMED",RAMP_ROUNDED:"W_STYLE_RAMP_ROUNDED",LAYER_CAP:"W_STYLE_LAYER_CAP",BUDGET:"W_STYLE_BUDGET",BLOCK_IGNORED:"W_STYLE_BLOCK_IGNORED",NOT_WRITTEN:"W_STYLE_NOT_WRITTEN",APPROXIMATED:"W_STYLE_APPROXIMATED",RULES_NOT_KEPT:"W_STYLE_RULES_NOT_KEPT",LAYER_FLATTENED:"W_STYLE_LAYER_FLATTENED",NOT_IMPORTED:to,NOT_EXPORTED:"W_STYLES_NOT_EXPORTED",MISMATCH:"E_STYLES_MISMATCH"}),Ce=256;function H(t,e,n){t.notes.add(e,t.target,t.property,{sample:n,element:t.element})}function Oi(t,e){t.budget?.spend(t.target==="graph"?"node":t.target,e)}function ut(t,e){return Oi(e,1),t==null?null:typeof t=="number"?Number.isFinite(t)?String(t):(H(e,v.BAD_VALUE,String(t)),null):typeof t!="string"?(H(e,v.BAD_VALUE,typeof t),null):t.length>Ce?(H(e,v.VALUE_TOO_LONG,`${t.length} characters`),null):(Oi(e,t.length),t.trim()===""?(H(e,v.BAD_VALUE,t),null):t)}const m1=1e6,yt=72,H3=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function P(t){return Number(t.toPrecision(6))+0}function Fy(t,e){if(typeof t=="boolean")return H(e,v.BAD_VALUE,t),null;const n=ut(t,e);if(n===null)return null;const i=n.trim();let r=Number.NaN;return typeof t=="number"?r=t:H3.test(i)&&(r=Number(i)),Number.isFinite(r)?r:(H(e,v.BAD_VALUE,n),null)}function Y(t,e,n=1){const i=Fy(t,e);if(i===null)return null;const r=i*n;return r>=0&&r<=m1?P(r):(H(e,v.BAD_VALUE,typeof t=="string"?t:String(t)),null)}function wa(t,e){const n=Fy(t,e);return n===null?null:Math.abs(n)>m1?(H(e,v.BAD_VALUE,typeof t=="string"?t:String(t)),null):P(n)}function ic(t,e,n){const i=Fy(t,n);if(i===null)return null;const r=e==="cytoscape"?255:1;return i>=0&&i<=r?P(i/r):(H(n,v.BAD_VALUE,typeof t=="string"?t:String(t)),null)}const V3=new Map([["true",!0],["yes",!0],["on",!0],["1",!0],["false",!1],["no",!1],["off",!1],["0",!1]]);function rc(t,e){if(typeof t=="boolean")return Oi(e,1),t;const n=ut(t,e);if(n===null)return null;const i=V3.get(n.trim().toLowerCase());return i===void 0?(H(e,v.BAD_VALUE,n),null):i}function y1(t){return t==="gexf"||t==="dvips"?"relative":"px"}const Y3=8,K3=80,X3=new Map([["W_STYLE_VALUE_TOO_LONG","values longer than 256 characters were not parsed"],["W_STYLE_BAD_VALUE","values do not parse"],["W_STYLE_UNKNOWN_VALUE","values have no name in the vocabulary and are kept as other:<value>"],["W_STYLE_ALPHA_DROPPED","color alpha was dropped"],["W_STYLE_COLOR_LIST","color lists are not read as one color"],["W_STYLE_GRADIENT","gradients are read as their first color"],["W_STYLE_UNFILLED","nodes with a fill color are drawn unfilled"],["W_STYLE_NO_FILL","fills are marked transparent"],["W_STYLE_NO_STROKE","strokes are marked absent"],["W_STYLE_SIZE_MINIMUM","node sizes are minimums: the node grows to fit its label"],["W_STYLE_HTML_LABEL","HTML-like labels keep their text; markup was dropped"],["W_STYLE_RECORD_LABEL","record label fields were joined"],["W_STYLE_EXTRA_LABELS","elements have more than one label; the first was kept"],["W_STYLE_INHERIT_COLOR","inherited colors cannot be expressed"],["W_STYLE_NOT_CARRIED","style properties have no counterpart and were not carried"],["W_STYLE_ANNOTATION_SKIPPED","annotations of a kind graph-io does not read were skipped"],["W_STYLE_BAD_MAPPING","mappings cannot be read"],["W_STYLE_MAPPING_COLUMN_MISSING","mappings read a column the file does not have"],["W_STYLE_REFERENCE_CYCLE","style references are circular or too deep"],["W_STYLE_UNRESOLVED","style references name nothing"],["W_STYLE_NESTING","style structures are nested too deep"],["W_STYLE_UNREADABLE","a style section cannot be read"],["W_STYLE_NO_VIZMAP","the session holds no visual styles"],["W_STYLE_VIEW_STYLE_MISSING","the view names a style the file does not hold"],["W_STYLE_OTHER_STYLES","other visual styles were not read"],["W_STYLE_OTHER_VIEWS","other views were not read"],["W_STYLE_SELECTOR","invalid selectors match every element"],["W_STYLE_SELECTOR_AS_COLUMN","selectors were evaluated into per-element values"],["W_STYLE_STATE_ASSUMED","selector states were evaluated as at load"],["W_STYLE_RAMP_ROUNDED","continuous mappings match within the tool's rounding"],["W_STYLE_LAYER_CAP","rules were folded into per-element copies"],["W_STYLE_BUDGET","the work budget ran out; values were copied per element"],["W_STYLE_BLOCK_IGNORED","the graphty.styles block was ignored"],["W_STYLE_NOT_WRITTEN","the format cannot hold this style"],["W_STYLE_APPROXIMATED","written as the nearest value the format allows"],["W_STYLE_RULES_NOT_KEPT","per-element values were written but not the rules"],["W_STYLE_LAYER_FLATTENED","a style was written as per-element values"]]);class se{#e=new Map;add(e,n,i,r={}){const s=`${e}\0${n??""}\0${i??""}`;let o=this.#e.get(s);if(o===void 0&&(o={code:e,target:n,property:i,count:0,samples:[],elements:new Set,unindexed:!1},this.#e.set(s,o)),o.count+=r.count??1,r.element===void 0?o.unindexed=!0:o.elements.add(r.element),r.sample!==void 0&&o.samples.length<Y3){const l=q3(r.sample);o.samples.includes(l)||o.samples.push(l)}}covers(e,n,i,r){return this.#e.get(`${e}\0${n}\0${i??""}`)?.elements.has(r)===!0}list(){const e=[];for(const n of this.#e.values()){const i=n.property===null?n.target??"file":`${n.target??"file"} ${n.property}`;e.push({code:n.code,params:{property:n.property,target:n.target,count:n.count,samples:[...n.samples]},elements:n.unindexed?{count:n.count}:Array.from(n.elements).sort((r,s)=>r-s),message:`${i}: ${X3.get(n.code)??n.code} (${n.count})`})}return e}}function q3(t){let e;if(typeof t=="string")e=t;else try{e=JSON.stringify(t)??typeof t}catch{e=typeof t}return e.slice(0,K3)}const J3={ellipse:["ellipse","oval","circle","disc","disk","point","doublecircle","mcircle","dot","sphere","circular"],rectangle:["rectangle","rect","box","square","plaintext","plain","record","msquare","box3d","rectangle3d","component","tab","folder","note","underline"],"round-rectangle":["round-rectangle","roundrectangle","roundrect","rounded","roundedrectangle","round-rect","mrecord","round-tag","bottom-round-rectangle","bottomroundrectangle"],triangle:["triangle","invtriangle","round-triangle","tag"],diamond:["diamond","rhombus","mdiamond","round-diamond"],pentagon:["pentagon","round-pentagon"],hexagon:["hexagon","hexagon2","round-hexagon","concave-hexagon","concavehexagon","septagon","heptagon","round-heptagon"],octagon:["octagon","doubleoctagon","tripleoctagon","round-octagon","octagon2","cut-rectangle","cutrectangle"],parallelogram:["parallelogram","parallelogram2","rhomboid","right-rhomboid","fat-arrow","fatarrow"],trapezoid:["trapezoid","trapezoid2","invtrapezoid","trapezium","round-trapezoid"],star:["star","star5","star6","star8","polygon"],vee:["vee","v"],none:["none","empty","invis"]},Z3={solid:["solid","line"],dashed:["dashed","dash","equal-dash"],dotted:["dotted","dot","dots"],"dash-dot":["dash-dot","dashdot","dashed-dotted"],double:["double","parallel-lines"]},Q3={solid:["solid","line","continuous","separate-arrow"],dashed:["dashed","dash","dashed-line","equal-dash"],dotted:["dotted","dot","dots","dotted-line"],"dash-dot":["dash-dot","dashdot","dashed-dotted","dash-dot-dot"],"long-dash":["long-dash","longdash"],double:["double","parallel","parallel-lines"],zigzag:["zigzag"],sinewave:["sinewave","sine-wave"]},e6={none:["none","no-arrow","noarrow","0"],triangle:["triangle","normal","delta","standard","arrow","triangle-backcurve","white-delta-inverted","simple","short","plain","convex","a"],"triangle-open":["triangle-open","onormal","empty","white-delta","transparent-circle-inverted","open-delta"],vee:["vee","open","chevron","concave","triangle-cross","b"],tee:["tee","t","t-shape","half-bottom","half-top","bar"],diamond:["diamond","white-diamond-inverted"],"diamond-open":["diamond-open","odiamond","white-diamond","ediamond","open-diamond"],circle:["circle","dot","transparent-circle","white-circle-inverted"],"circle-open":["circle-open","odot","white-circle","open-circle"],square:["square","box","skewed-dash"],crow:["crow","crows-foot","crows-foot-many"],half:["half","half-top-arrow","half-open","lnormal","rnormal","halfopen"],inverted:["inverted","inv","inverted-triangle","inv-triangle"]},t6={normal:["normal","regular","plain","lighter","100","200","300","400","500"],bold:["bold","bolder","600","700","800","900"]},n6={center:["center","centre","middle","c"],top:["top","north","t"],bottom:["bottom","south","b"],left:["left","west","l"],right:["right","east","r"],"top-left":["top-left","north-west","northwest"],"top-right":["top-right","north-east","northeast"],"bottom-left":["bottom-left","south-west","southwest"],"bottom-right":["bottom-right","south-east","southeast"],"inside-top":["inside-top"],"inside-bottom":["inside-bottom"],"inside-left":["inside-left"],"inside-right":["inside-right"],"inside-top-left":["inside-top-left"],"inside-top-right":["inside-top-right"],"inside-bottom-left":["inside-bottom-left"],"inside-bottom-right":["inside-bottom-right"]},i6={inside:["inside"],center:["center","centre","middle"],outside:["outside"]},r6={left:["left"],right:["right"]},s6={left:["left","start"],center:["center","centre","middle"],right:["right","end"]},o6={inside:["inside"],bounds:["bounds"]},l6={shape:{"round-rectangle":["box"],ellipse:["dot"],triangle:["triangledown"],none:["text"]},arrow:{inverted:["inv-triangle"],square:["box"],"other:curve":["curve"],"other:inv-curve":["inv-curve"]}},a6={arrow:{"other:triangle-tee":["triangle-tee"],"other:triangle-cross":["triangle-cross"],"other:circle-triangle":["circle-triangle"],"other:chevron":["chevron"],vee:["triangle-backcurve"]}},c6={arrow:{"other:curve":["curve"],"other:inv-curve":["icurve"]}},d6={arrow:{vee:["standard"]}},u6=new Map([["vis",l6],["graphviz",c6],["cytoscape-js",a6],["yed",d6]]),f6=new Set(["shape","borderStyle","lineStyle","arrow"]);function di(t){const e=new Map;for(const[n,i]of Object.entries(t))for(const r of i)e.set(r,n);return e}const h6=new Map([["shape",di(J3)],["borderStyle",di(Z3)],["lineStyle",di(Q3)],["arrow",di(e6)],["arrowSide",di(r6)],["weight",di(t6)],["position",di(n6)],["labelFit",di(o6)],["borderPosition",di(i6)],["textAlign",di(s6)]]),p6=new Map(Array.from(u6,([t,e])=>[t,new Map(Object.entries(e).map(([n,i])=>[n,di(i)]))]));function le(t,e,n,i){const r=ut(e,i);if(r===null)return null;const s=r.trim(),o=s.toLowerCase().replaceAll(/[\s_]+/g,"-"),l=p6.get(n)?.get(t)?.get(o)??h6.get(t)?.get(o);return l!==void 0?l:(H(i,v.UNKNOWN_VALUE,s),f6.has(t)?`other:${s}`:null)}function rt(t,e){return Oi(e,1),t==null?null:typeof t=="string"?(Oi(e,t.length),t):typeof t=="number"&&Number.isFinite(t)||typeof t=="boolean"?String(t):(H(e,v.BAD_VALUE,typeof t=="number"?String(t):typeof t),null)}function mf(t,e,n){n!==void 0&&Oi(n,t.length);const i=zy(S6(b1(t,e)),r=>r==="n"||r==="l"||r==="r"?`
|
|
37
|
+
`:r);return i.endsWith(`
|
|
38
|
+
`)?i.slice(0,-1):i}function b1(t,e){const n={N:e.node,G:e.graph,E:e.edge,T:e.tail,H:e.head};return zy(t,i=>(Object.hasOwn(n,i)?n[i]:void 0)??`\\${i}`)}function g6(t,e){const n=zy(b1(t,e),l=>l==="n"||l==="l"||l==="r"?`\0${l}\0`:"x").split("\0"),i=n.filter((l,a)=>a%2===1);n.at(-1)!==""&&i.push("n");const r=l=>i.filter(a=>a===l).length,s=["l","r","n"].filter(l=>r(l)===Math.max(r("l"),r("r"),r("n"))),o=s.length>1?i.find(l=>s.includes(l))??"n":s[0];return o==="l"?"left":o==="r"?"right":null}function zy(t,e){let n="",i=0;for(;i<t.length;){const r=t[i];r==="\\"&&i+1<t.length?(n+=e(t[i+1]),i+=2):(n+=r,i++)}return n}const m6=new Map([["amp","&"],["lt","<"],["gt",">"],["quot",'"'],["apos","'"],["nbsp"," "]]);function y6(t){if(t.startsWith("#")){const e=t[1]==="x"||t[1]==="X",n=t.slice(e?2:1);if(n===""||n.length>7||!(e?/^[0-9a-f]+$/i:/^\d+$/).test(n))return;const i=Number.parseInt(n,e?16:10);return i>0&&i<=1114111?String.fromCodePoint(i):void 0}return m6.get(t.toLowerCase())}function eg(t,e){return Oi(e,t.length),H(e,v.HTML_LABEL,t),E1(t).map(n=>n.text).join("").trim()}const b6=/^<(\/?)(b|i|u|o|s|sub|sup|font)\b/i;function E1(t){const e=t.startsWith("<")&&t.endsWith(">")?t.slice(1,-1):t,n={spans:[],tags:[],out:"",open:[]};let i=0;for(;i<e.length;){const r=e[i];if(r==="<"){const s=e.indexOf(">",i+1);if(s<0)break;E6(n,e,i,s),i=s+1}else{const[s,o]=r==="&"?w1(e,i):[r,i+1];tg(n,n.open.at(-1)==="table"?"":s),i=o}}return n.spans}function tg(t,e){t.out+=e;const n=t.spans.at(-1);n?.tags===t.tags?t.spans[t.spans.length-1]={text:n.text+e,tags:t.tags}:e!==""&&t.spans.push({text:e,tags:t.tags})}function UE(t){return t.out.slice(t.out.lastIndexOf(`
|
|
39
|
+
`)+1).trim()!==""}function E6(t,e,n,i){const r=/^<(\/?)(br|table|tr|td)\b/i.exec(e.slice(n,n+7));if(r!==null){w6(t,r[2].toLowerCase(),r[1]==="/");return}const s=b6.exec(e.slice(n,n+6));s!==null&&s[1]==="/"?t.tags=_6(t.tags,s[2]):s!==null&&e[i-1]!=="/"&&(t.tags=[...t.tags,e.slice(n,i+1)])}function w6(t,e,n){e==="br"||e==="tr"?(e==="br"||!n&&UE(t))&&tg(t,`
|
|
40
|
+
`):n?t.open.pop():(e==="td"&&UE(t)&&tg(t," "),t.open.push(e==="td"?"td":"table"))}function _6(t,e){const n=e.toLowerCase();let i=t.length-1;for(;i>=0&&/^<(\w+)/.exec(t[i])?.[1].toLowerCase()!==n;)i--;return i<0?t:[...t.slice(0,i),...t.slice(i+1)]}function S6(t){let e="",n=0;for(let i=t.indexOf("&");i>=0;i=t.indexOf("&",n)){const[r,s]=w1(t,i);e+=t.slice(n,i)+r,n=s}return e+t.slice(n)}function w1(t,e){const n=t.slice(e+1,e+10).indexOf(";"),i=n<0?-1:e+1+n,r=i>e?y6(t.slice(e+1,i)):void 0;return r===void 0?["&",e+1]:[r,i+1]}function O6(t,e){Oi(e,t.length),H(e,v.RECORD_LABEL,t);const n=[];let i="";const r=()=>{const o=i.trim();o!==""&&n.push(o),i=""};let s=0;for(;s<t.length;){const o=t[s];if(o==="\\"&&s+1<t.length&&"|{}<> ".includes(t[s+1])){i+=t[s+1],s+=2;continue}if(o==="<"){const l=t.indexOf(">",s+1);s=l<0?t.length:l+1;continue}o==="|"||o==="{"||o==="}"?r():i+=o,s++}return r(),n.join(" | ")}const ii=Object.freeze({node:new Map([["fill","color"],["fillGradient","color"],["borderColor","color"],["labelColor","color"],["fillOpacity","opacity"],["opacity","opacity"],["borderOpacity","opacity"],["width","number"],["height","number"],["borderWidth","number"],["cornerRadius","number"],["fillGradientAngle","number"],["fillGradientColors","text"],["fillGradientStops","text"],["fillGradientKind","text"],["labelSize","number"],["labelWrapWidth","number"],["labelWrapTrailingSpace","boolean"],["labelWrapEllipsis","boolean"],["labelWrapAnywhere","boolean"],["labelWrapSpaceCount","number"],["labelRunAlign","text"],["labelOffsetX","signed"],["labelOffsetY","signed"],["labelShiftX","signed"],["labelShiftY","signed"],["labelOpacity","opacity"],["labelBackgroundOpacity","opacity"],["labelFit","labelFit"],["labelPaddingX","number"],["labelPaddingY","number"],["labelFitSquare","boolean"],["shape","shape"],["shapePoints","text"],["shapePointsStretch","boolean"],["shapeParts","text"],["shapeLines","text"],["shapeLineWidth","number"],["shapeTexts","text"],["borderStyle","borderStyle"],["borderPosition","borderPosition"],["borderWaveAmplitude","number"],["borderWavePeriod","number"],["outerBorderColor","color"],["outerBorderWidth","number"],["outerBorderOpacity","opacity"],["outerBorderStyle","borderStyle"],["outerBorderOffset","number"],["underlayColor","color"],["underlayOpacity","opacity"],["underlayPadding","number"],["underlayShape","shape"],["underlayCornerRadius","number"],["overlayColor","color"],["overlayOpacity","opacity"],["overlayPadding","number"],["overlayShape","shape"],["overlayCornerRadius","number"],["label","text"],["tooltip","text"],["labelFont","text"],["labelWeight","weight"],["labelItalic","boolean"],["labelPosition","position"],["labelTextAlign","textAlign"],["labelRuns","text"],["labelMinScreenSize","number"],["labelAvoidOverlap","boolean"],["labelMinNodeScreenSize","number"],["labelGridCellSize","number"],["labelOnTop","boolean"],["labelRotation","number"],["labelBackground","color"],["labelOutlineColor","color"],["labelOutlineWidth","number"],["labelBorderColor","color"],["labelBorderWidth","number"],["labelOutlineOpacity","opacity"],["labelBorderOpacity","opacity"],["labelPadding","number"],["labelCornerRadius","number"],["labelLineHeight","number"],["image","text"],["imageFit","text"],["imageFallback","text"],["imageWidth","number"],["imageHeight","number"],["imagePositionX","number"],["imagePositionY","number"],["imageOffsetX","signed"],["imageOffsetY","signed"],["imageRepeat","text"],["imageClip","text"],["imageSmoothing","boolean"],["imageAutoSize","text"],["imageOpacity","opacity"],["glyph","text"],["glyphFont","text"],["glyphSize","number"],["glyphWeight","weight"],["glyphColor","color"],["pieColors","text"],["pieSizes","text"],["pieOpacities","text"],["pieRadius","number"],["pieHole","number"],["pieRotation","number"],["pieFitBox","boolean"],["pieOffsetX","signed"],["pieOffsetY","signed"],["stripeColors","text"],["stripeSizes","text"],["stripeOpacities","text"],["stripeDirection","text"],["stripeSize","number"],["chartKind","text"],["chartValues","text"],["chartColors","text"],["chartMin","signed"],["chartMax","signed"],["chartHorizontal","boolean"],["chartSize","number"],["chartMargin","signed"],["chartGap","number"],["chartLineWidth","number"],["chartBorderColor","color"],["chartBorderWidth","number"],["groupPadding","number"],["groupPaddingRatio","number"],["groupPaddingOf","text"],["groupMinWidth","number"],["groupMinHeight","number"],["groupMinWidthBiasLeft","number"],["groupMinHeightBiasTop","number"],["groupIncludeLabels","boolean"],["visible","boolean"]]),edge:new Map([["color","color"],["sourceArrowColor","color"],["targetArrowColor","color"],["labelColor","color"],["opacity","opacity"],["width","number"],["minScreenWidth","number"],["outlineWidth","number"],["outlineColor","color"],["outlineOpacity","opacity"],["outlineStyle","lineStyle"],["underlayColor","color"],["underlayOpacity","opacity"],["underlayPadding","number"],["overlayColor","color"],["overlayOpacity","opacity"],["overlayPadding","number"],["gradientColors","text"],["gradientStops","text"],["gradientKind","text"],["labelSize","number"],["arrowSize","number"],["sourceArrowSize","number"],["sourceArrowLength","number"],["targetArrowLength","number"],["sourceArrowWidth","number"],["targetArrowWidth","number"],["sourceArrowGap","number"],["targetArrowGap","number"],["sourceArrowSide","arrowSide"],["targetArrowSide","arrowSide"],["arrowPosition","number"],["lineStyle","lineStyle"],["waveAmplitude","number"],["wavePeriod","number"],["sourceArrow","arrow"],["targetArrow","arrow"],["midTargetArrow","arrow"],["midSourceArrow","arrow"],["midTargetArrowColor","color"],["midSourceArrowColor","color"],["targetArrowImage","text"],["sourceArrowImage","text"],["midTargetArrowImage","text"],["targetArrowImageWidth","number"],["targetArrowImageHeight","number"],["sourceArrowImageWidth","number"],["sourceArrowImageHeight","number"],["midTargetArrowImageWidth","number"],["midTargetArrowImageHeight","number"],["curved","boolean"],["bends","text"],["fanSpacing","number"],["fanned","boolean"],["bendCurve","text"],["arcRadius","number"],["supportModel","text"],["supportSpringLength","number"],["supportSpringConstant","number"],["supportRepulsion","number"],["supportCentralGravity","number"],["nodeGap","number"],["sourceNodeGap","number"],["targetNodeGap","number"],["sourcePort","text"],["targetPort","text"],["label","text"],["tooltip","text"],["labelFont","text"],["labelWeight","weight"],["labelTextAlign","textAlign"],["labelRuns","text"],["labelItalic","boolean"],["labelWrapWidth","number"],["labelWrapEllipsis","boolean"],["labelWrapAnywhere","boolean"],["labelWrapSpaceCount","number"],["labelRunAlign","text"],["labelPosition","position"],["labelRotation","number"],["labelOffsetX","signed"],["labelOffsetY","signed"],["labelShiftX","signed"],["labelShiftY","signed"],["labelOpacity","opacity"],["labelBackgroundOpacity","opacity"],["labelBackground","color"],["labelOutlineColor","color"],["labelOutlineWidth","number"],["labelBorderColor","color"],["labelBorderWidth","number"],["labelOutlineOpacity","opacity"],["labelBorderOpacity","opacity"],["labelPadding","number"],["labelCornerRadius","number"],["labelLineHeight","number"],["sourceLabel","text"],["targetLabel","text"],["sourceLabelOffset","number"],["targetLabelOffset","number"],["sourceLabelOffsetX","signed"],["sourceLabelOffsetY","signed"],["targetLabelOffsetX","signed"],["targetLabelOffsetY","signed"],["sourceLabelRotation","number"],["targetLabelRotation","number"],["sourceLabelSize","number"],["targetLabelSize","number"],["sourceLabelColor","color"],["targetLabelColor","color"],["sourceLabelFont","text"],["targetLabelFont","text"],["labelMinScreenSize","number"],["labelOnTop","boolean"],["visible","boolean"]]),graph:new Map([["background","color"]])}),N6=new Map([["shape",["ellipse","rectangle","round-rectangle","triangle","diamond","pentagon","hexagon","octagon","parallelogram","trapezoid","star","vee","polygon","none"]],["borderStyle",["solid","dashed","dotted","dash-dot","double"]],["borderPosition",["inside","center","outside"]],["lineStyle",["solid","dashed","dotted","dash-dot","long-dash","double","zigzag","sinewave"]],["arrow",["none","triangle","triangle-open","vee","tee","diamond","diamond-open","circle","circle-open","square","crow","half","inverted"]],["arrowSide",["left","right"]],["weight",["normal","bold"]],["textAlign",["left","center","right"]],["labelFit",["inside","bounds"]],["position",["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right","inside-top","inside-bottom","inside-left","inside-right","inside-top-left","inside-top-right","inside-bottom-left","inside-bottom-right"]]]),A6=new Set(["shape","borderStyle","lineStyle","arrow"]);function Jo(t,e,n){if(t!=="graph"&&e.startsWith("graphty:"))return typeof n=="string"||typeof n=="number"||typeof n=="boolean";const i=ii[t].get(e);switch(i){case void 0:return!1;case"color":return typeof n=="string"&&/^#[0-9a-f]{6}$/.test(n);case"number":return typeof n=="number"&&Number.isFinite(n)&&n>=0;case"signed":return typeof n=="number"&&Number.isFinite(n);case"opacity":return typeof n=="number"&&n>=0&&n<=1;case"text":return typeof n=="string";case"boolean":return typeof n=="boolean";default:return typeof n=="string"&&((N6.get(i)?.includes(n)??!1)||A6.has(i)&&n.startsWith("other:")&&n.length>6)}}const T6=32,_1=8,cu=/^#[0-9a-f]{6}$/;function GE(t){return"style"in t?`style:${t.style}`:"computed"in t?`computed:${t.computed}`:`data:${t.data}`}function K(t){return t==null?null:typeof t=="bigint"?Number(t):ArrayBuffer.isView(t)?Array.from(t):t}function yf(t,e,n){const i=K(t.value(e,n));return typeof i=="number"&&t.get(e)?.dtype==="f32"?Number(ct(i)):i}function sc(t,e){let n;return e==="degree"?n=t.degree():e==="indegree"?n=t.inDegree():n=t.outDegree(),Array.from(n)}function Cr(t,e,n,i,r){const s=new Map,o=new Map;for(const l of i)o.set(GE(l.ref),l);return{n:e,column(l){if("style"in l)return n.get(l.style)??null;const a=GE(l);if(s.has(a))return s.get(a)??null;const c=r===void 0?o.get(a)?.values??null:I6(r,t,e,l);return s.set(a,c),c}}}function I6(t,e,n,i){if("computed"in i)return e==="node"?sc(t,i.computed):null;const r=e==="node"?t.nodes:t.edges;return r.has(i.data)?Array.from({length:n},(s,o)=>yf(r,i.data,o)):null}function bd(t,e,n){const i=t.column(e);return i===null?null:i[n]??null}function $6(t){if("and"in t){if(!Array.isArray(t.and)||t.and.length===0)return!1;let e=0;for(const n of t.and){const i=ng(n);if(i===0)return!1;e+=i}return e<=_1}return ng(t)>0}function ng(t){if("all"in t)return t.all?1:0;if("has"in t)return 1;if("not"in t)return"has"in t.not||"computed"in C6(t.not)?ng(t.not):0;if("eq"in t)return 1;if("in"in t){const e=Array.isArray(t.in[1])?t.in[1].length:0;return e>=1&&e<=_1?e:0}return 0}function C6(t){return"eq"in t?t.eq[0]:"in"in t?t.in[0]:{}}function jE(t,e){return t===e?t!=null:typeof e=="boolean"?FE(e,t):typeof t=="boolean"&&FE(t,e)}function FE(t,e){return e===(t?1:0)||typeof e=="string"&&e.toLowerCase()===String(t)}function Po(t,e,n,i=0){if(i>T6)return!1;if("all"in t)return t.all;if("has"in t){const r=bd(e,t.has,n);return r!==null&&r!==!1}if("eq"in t)return jE(bd(e,t.eq[0],n),t.eq[1]);if("in"in t){const r=bd(e,t.in[0],n);return t.in[1].some(s=>jE(r,s))}return"and"in t?t.and.every(r=>Po(r,e,n,i+1)):"or"in t?t.or.some(r=>Po(r,e,n,i+1)):"not"in t?!Po(t.not,e,n,i+1):!1}const v6=new Set(["shape","borderStyle","lineStyle","arrow","arrowSide","weight","position","labelFit","borderPosition","textAlign"]);function _l(t,e){const n=ii[t].get(e),i={notes:new se,target:t,property:e};if(n===void 0)return r=>typeof r=="string"||typeof r=="number"||typeof r=="boolean"?r:null;switch(n){case"color":return r=>typeof r=="string"&&/^#[0-9a-fA-F]{6}$/.test(r)?r.toLowerCase():null;case"number":return r=>Y(r,i);case"signed":return r=>wa(r,i);case"opacity":return r=>ic(r,"css",i);case"boolean":return r=>rc(r,i);case"text":return r=>rt(r,i);default:return v6.has(n)?r=>typeof r=="string"&&r.startsWith("other:")?r:le(n,r,"css",i):()=>null}}const zE=new WeakMap,D6=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function oc(t){return typeof t=="number"?Number.isFinite(t)?t:null:typeof t=="string"&&t.length<=64&&D6.test(t.trim())?Number(t.trim()):null}function S1(t){const e=zE.get(t);if(e!==void 0)return e;const n=new Map,i=new Map,r=new Map;t.forEach(([l],a)=>{if(l===null||typeof l=="object")return;const c=String(l);n.has(c)||n.set(c,a);const d=oc(l);d!==null&&!i.has(d)&&i.set(d,a);const u=c.toLowerCase();(u==="true"||u==="false")&&!r.has(u)&&r.set(u,a)});const s=l=>typeof l=="number"?i.get(l)??-1:typeof l=="boolean"?r.get(String(l))??-1:typeof l=="string"?n.get(l)??-1:-1,o=l=>{if(Array.isArray(l)){for(const a of l){const c=s(a);if(c>=0)return c}return-1}return s(l)};return zE.set(t,o),o}function k6(t){return Math.min(255,Math.max(0,Math.round(t))).toString(16).padStart(2,"0")}function O1(t){return Number(t.toPrecision(6))+0}function N1(t,e,n){if(typeof t=="number"&&typeof e=="number")return O1(t+(e-t)*n);if(typeof t=="string"&&typeof e=="string"&&cu.test(t)&&cu.test(e)){let i="#";for(const r of[1,3,5]){const s=Number.parseInt(t.slice(r,r+2),16),o=Number.parseInt(e.slice(r,r+2),16);i+=k6(s+(o-s)*n)}return i}return n<1?t:e}function bf(t,e,n){const i=R6(t,e);return typeof i=="number"&&n!==void 0&&n>0?O1(Math.round(i/n)*n):i}function R6(t,e){if(e===null||!Number.isFinite(e)||t.length===0)return null;if(e<t[0].at)return t[0].below;for(let n=0;n<t.length;n++){const i=t[n];if(e===i.at)return i.value;const r=t.at(n+1);if(r===void 0)return i.above;if(e<r.at)return N1(i.above,r.below,(e-i.at)/(r.at-i.at))}return null}function L6(t,e,n,i){const r=bd(n,t.by,i);if(r==null)return null;switch(t.kind){case"passthrough":return Array.isArray(r)?null:"style"in t.by?typeof r=="string"||typeof r=="number"||typeof r=="boolean"?r:null:e(r);case"discrete":{const s=S1(t.table)(r);return s<0?null:t.table[s][1]}case"continuous":return Array.isArray(r)?null:bf(t.points,oc(r),t.step);default:return null}}function A1(t,e){const n=t.set??{};return Object.hasOwn(n,e)?n[e]:void 0}function T1(t,e){const n=t.map??{};return Object.hasOwn(n,e)?n[e]:void 0}function Ni(t,e,n,i,r){const s=t.filter(c=>c.target===e&&(A1(c,n)!==void 0||T1(c,n)!==void 0)).reverse(),o=_l(e,n),l=new Array(i.n).fill(null);let a=0;for(let c=0;c<i.n;c++)for(const d of s){a++;const u=P6(d,n,o,i,c);if(u!==null){l[c]=u;break}}return r?.spend(e,a+i.n),l}function P6(t,e,n,i,r){if(!Po(t.where,i,r))return null;const s=A1(t,e);if(s!==void 0)return s;const o=T1(t,e);return o===void 0?null:L6(o,n,i,r)}function I1(t,e,n,i){return Ni(t.styles.rules,e,n,x6(t,e,i))}function x6(t,e,n){let i=t.fingerprint[e==="node"?"nodes":"edges"];return n!==void 0&&(i=e==="node"?n.nodeCount:n.edgeCount),Cr(e,i,t.columns[e],t.features[e],n)}function Wy(t,e){if(t===e)return!0;if(typeof t=="number"&&typeof e=="number")return Math.abs(t-e)<=1e-5*Math.max(Math.abs(t),Math.abs(e),1e-9);if(typeof t=="string"&&typeof e=="string"&&cu.test(t)&&cu.test(e)){for(const n of[1,3,5])if(Math.abs(Number.parseInt(t.slice(n,n+2),16)-Number.parseInt(e.slice(n,n+2),16))>2)return!1;return!0}return!1}function Ef(t){const e=new Map;for(const n of t.split(" ")){const i=n.indexOf("=");e.set(n.slice(0,i),`#${n.slice(i+1)}`)}return e}const Sl=Ef("aliceblue=f0f8ff antiquewhite=faebd7 aqua=00ffff aquamarine=7fffd4 azure=f0ffff beige=f5f5dc bisque=ffe4c4 black=000000 blanchedalmond=ffebcd blue=0000ff blueviolet=8a2be2 brown=a52a2a burlywood=deb887 cadetblue=5f9ea0 chartreuse=7fff00 chocolate=d2691e coral=ff7f50 cornflowerblue=6495ed cornsilk=fff8dc crimson=dc143c cyan=00ffff darkblue=00008b darkcyan=008b8b darkgoldenrod=b8860b darkgray=a9a9a9 darkgreen=006400 darkgrey=a9a9a9 darkkhaki=bdb76b darkmagenta=8b008b darkolivegreen=556b2f darkorange=ff8c00 darkorchid=9932cc darkred=8b0000 darksalmon=e9967a darkseagreen=8fbc8f darkslateblue=483d8b darkslategray=2f4f4f darkslategrey=2f4f4f darkturquoise=00ced1 darkviolet=9400d3 deeppink=ff1493 deepskyblue=00bfff dimgray=696969 dimgrey=696969 dodgerblue=1e90ff firebrick=b22222 floralwhite=fffaf0 forestgreen=228b22 fuchsia=ff00ff gainsboro=dcdcdc ghostwhite=f8f8ff gold=ffd700 goldenrod=daa520 gray=808080 green=008000 greenyellow=adff2f grey=808080 honeydew=f0fff0 hotpink=ff69b4 indianred=cd5c5c indigo=4b0082 ivory=fffff0 khaki=f0e68c lavender=e6e6fa lavenderblush=fff0f5 lawngreen=7cfc00 lemonchiffon=fffacd lightblue=add8e6 lightcoral=f08080 lightcyan=e0ffff lightgoldenrodyellow=fafad2 lightgray=d3d3d3 lightgreen=90ee90 lightgrey=d3d3d3 lightpink=ffb6c1 lightsalmon=ffa07a lightseagreen=20b2aa lightskyblue=87cefa lightslategray=778899 lightslategrey=778899 lightsteelblue=b0c4de lightyellow=ffffe0 lime=00ff00 limegreen=32cd32 linen=faf0e6 magenta=ff00ff maroon=800000 mediumaquamarine=66cdaa mediumblue=0000cd mediumorchid=ba55d3 mediumpurple=9370db mediumseagreen=3cb371 mediumslateblue=7b68ee mediumspringgreen=00fa9a mediumturquoise=48d1cc mediumvioletred=c71585 midnightblue=191970 mintcream=f5fffa mistyrose=ffe4e1 moccasin=ffe4b5 navajowhite=ffdead navy=000080 oldlace=fdf5e6 olive=808000 olivedrab=6b8e23 orange=ffa500 orangered=ff4500 orchid=da70d6 palegoldenrod=eee8aa palegreen=98fb98 paleturquoise=afeeee palevioletred=db7093 papayawhip=ffefd5 peachpuff=ffdab9 peru=cd853f pink=ffc0cb plum=dda0dd powderblue=b0e0e6 purple=800080 rebeccapurple=663399 red=ff0000 rosybrown=bc8f8f royalblue=4169e1 saddlebrown=8b4513 salmon=fa8072 sandybrown=f4a460 seagreen=2e8b57 seashell=fff5ee sienna=a0522d silver=c0c0c0 skyblue=87ceeb slateblue=6a5acd slategray=708090 slategrey=708090 snow=fffafa springgreen=00ff7f steelblue=4682b4 tan=d2b48c teal=008080 thistle=d8bfd8 tomato=ff6347 turquoise=40e0d0 violet=ee82ee wheat=f5deb3 white=ffffff whitesmoke=f5f5f5 yellow=ffff00 yellowgreen=9acd32"),M6=Ef("aliceblue=f0f8ff antiquewhite=faebd7 antiquewhite1=ffefdb antiquewhite2=eedfcc antiquewhite3=cdc0b0 antiquewhite4=8b8378 aqua=00ffff aquamarine=7fffd4 aquamarine1=7fffd4 aquamarine2=76eec6 aquamarine3=66cdaa aquamarine4=458b74 azure=f0ffff azure1=f0ffff azure2=e0eeee azure3=c1cdcd azure4=838b8b beige=f5f5dc bisque=ffe4c4 bisque1=ffe4c4 bisque2=eed5b7 bisque3=cdb79e bisque4=8b7d6b black=000000 blanchedalmond=ffebcd blue=0000ff blue1=0000ff blue2=0000ee blue3=0000cd blue4=00008b blueviolet=8a2be2 brown=a52a2a brown1=ff4040 brown2=ee3b3b brown3=cd3333 brown4=8b2323 burlywood=deb887 burlywood1=ffd39b burlywood2=eec591 burlywood3=cdaa7d burlywood4=8b7355 cadetblue=5f9ea0 cadetblue1=98f5ff cadetblue2=8ee5ee cadetblue3=7ac5cd cadetblue4=53868b chartreuse=7fff00 chartreuse1=7fff00 chartreuse2=76ee00 chartreuse3=66cd00 chartreuse4=458b00 chocolate=d2691e chocolate1=ff7f24 chocolate2=ee7621 chocolate3=cd661d chocolate4=8b4513 coral=ff7f50 coral1=ff7256 coral2=ee6a50 coral3=cd5b45 coral4=8b3e2f cornflowerblue=6495ed cornsilk=fff8dc cornsilk1=fff8dc cornsilk2=eee8cd cornsilk3=cdc8b1 cornsilk4=8b8878 crimson=dc143c cyan=00ffff cyan1=00ffff cyan2=00eeee cyan3=00cdcd cyan4=008b8b darkblue=00008b darkcyan=008b8b darkgoldenrod=b8860b darkgoldenrod1=ffb90f darkgoldenrod2=eead0e darkgoldenrod3=cd950c darkgoldenrod4=8b6508 darkgray=a9a9a9 darkgreen=006400 darkgrey=a9a9a9 darkkhaki=bdb76b darkmagenta=8b008b darkolivegreen=556b2f darkolivegreen1=caff70 darkolivegreen2=bcee68 darkolivegreen3=a2cd5a darkolivegreen4=6e8b3d darkorange=ff8c00 darkorange1=ff7f00 darkorange2=ee7600 darkorange3=cd6600 darkorange4=8b4500 darkorchid=9932cc darkorchid1=bf3eff darkorchid2=b23aee darkorchid3=9a32cd darkorchid4=68228b darkred=8b0000 darksalmon=e9967a darkseagreen=8fbc8f darkseagreen1=c1ffc1 darkseagreen2=b4eeb4 darkseagreen3=9bcd9b darkseagreen4=698b69 darkslateblue=483d8b darkslategray=2f4f4f darkslategray1=97ffff darkslategray2=8deeee darkslategray3=79cdcd darkslategray4=528b8b darkslategrey=2f4f4f darkturquoise=00ced1 darkviolet=9400d3 deeppink=ff1493 deeppink1=ff1493 deeppink2=ee1289 deeppink3=cd1076 deeppink4=8b0a50 deepskyblue=00bfff deepskyblue1=00bfff deepskyblue2=00b2ee deepskyblue3=009acd deepskyblue4=00688b dimgray=696969 dimgrey=696969 dodgerblue=1e90ff dodgerblue1=1e90ff dodgerblue2=1c86ee dodgerblue3=1874cd dodgerblue4=104e8b firebrick=b22222 firebrick1=ff3030 firebrick2=ee2c2c firebrick3=cd2626 firebrick4=8b1a1a floralwhite=fffaf0 forestgreen=228b22 fuchsia=ff00ff gainsboro=dcdcdc ghostwhite=f8f8ff gold=ffd700 gold1=ffd700 gold2=eec900 gold3=cdad00 gold4=8b7500 goldenrod=daa520 goldenrod1=ffc125 goldenrod2=eeb422 goldenrod3=cd9b1d goldenrod4=8b6914 gray=c0c0c0 gray0=000000 gray1=030303 gray10=1a1a1a gray100=ffffff gray11=1c1c1c gray12=1f1f1f gray13=212121 gray14=242424 gray15=262626 gray16=292929 gray17=2b2b2b gray18=2e2e2e gray19=303030 gray2=050505 gray20=333333 gray21=363636 gray22=383838 gray23=3b3b3b gray24=3d3d3d gray25=404040 gray26=424242 gray27=454545 gray28=474747 gray29=4a4a4a gray3=080808 gray30=4d4d4d gray31=4f4f4f gray32=525252 gray33=545454 gray34=575757 gray35=595959 gray36=5c5c5c gray37=5e5e5e gray38=616161 gray39=636363 gray4=0a0a0a gray40=666666 gray41=696969 gray42=6b6b6b gray43=6e6e6e gray44=707070 gray45=737373 gray46=757575 gray47=787878 gray48=7a7a7a gray49=7d7d7d gray5=0d0d0d gray50=7f7f7f gray51=828282 gray52=858585 gray53=878787 gray54=8a8a8a gray55=8c8c8c gray56=8f8f8f gray57=919191 gray58=949494 gray59=969696 gray6=0f0f0f gray60=999999 gray61=9c9c9c gray62=9e9e9e gray63=a1a1a1 gray64=a3a3a3 gray65=a6a6a6 gray66=a8a8a8 gray67=ababab gray68=adadad gray69=b0b0b0 gray7=121212 gray70=b3b3b3 gray71=b5b5b5 gray72=b8b8b8 gray73=bababa gray74=bdbdbd gray75=bfbfbf gray76=c2c2c2 gray77=c4c4c4 gray78=c7c7c7 gray79=c9c9c9 gray8=141414 gray80=cccccc gray81=cfcfcf gray82=d1d1d1 gray83=d4d4d4 gray84=d6d6d6 gray85=d9d9d9 gray86=dbdbdb gray87=dedede gray88=e0e0e0 gray89=e3e3e3 gray9=171717 gray90=e5e5e5 gray91=e8e8e8 gray92=ebebeb gray93=ededed gray94=f0f0f0 gray95=f2f2f2 gray96=f5f5f5 gray97=f7f7f7 gray98=fafafa gray99=fcfcfc green=00ff00 green1=00ff00 green2=00ee00 green3=00cd00 green4=008b00 greenyellow=adff2f grey=c0c0c0 grey0=000000 grey1=030303 grey10=1a1a1a grey100=ffffff grey11=1c1c1c grey12=1f1f1f grey13=212121 grey14=242424 grey15=262626 grey16=292929 grey17=2b2b2b grey18=2e2e2e grey19=303030 grey2=050505 grey20=333333 grey21=363636 grey22=383838 grey23=3b3b3b grey24=3d3d3d grey25=404040 grey26=424242 grey27=454545 grey28=474747 grey29=4a4a4a grey3=080808 grey30=4d4d4d grey31=4f4f4f grey32=525252 grey33=545454 grey34=575757 grey35=595959 grey36=5c5c5c grey37=5e5e5e grey38=616161 grey39=636363 grey4=0a0a0a grey40=666666 grey41=696969 grey42=6b6b6b grey43=6e6e6e grey44=707070 grey45=737373 grey46=757575 grey47=787878 grey48=7a7a7a grey49=7d7d7d grey5=0d0d0d grey50=7f7f7f grey51=828282 grey52=858585 grey53=878787 grey54=8a8a8a grey55=8c8c8c grey56=8f8f8f grey57=919191 grey58=949494 grey59=969696 grey6=0f0f0f grey60=999999 grey61=9c9c9c grey62=9e9e9e grey63=a1a1a1 grey64=a3a3a3 grey65=a6a6a6 grey66=a8a8a8 grey67=ababab grey68=adadad grey69=b0b0b0 grey7=121212 grey70=b3b3b3 grey71=b5b5b5 grey72=b8b8b8 grey73=bababa grey74=bdbdbd grey75=bfbfbf grey76=c2c2c2 grey77=c4c4c4 grey78=c7c7c7 grey79=c9c9c9 grey8=141414 grey80=cccccc grey81=cfcfcf grey82=d1d1d1 grey83=d4d4d4 grey84=d6d6d6 grey85=d9d9d9 grey86=dbdbdb grey87=dedede grey88=e0e0e0 grey89=e3e3e3 grey9=171717 grey90=e5e5e5 grey91=e8e8e8 grey92=ebebeb grey93=ededed grey94=f0f0f0 grey95=f2f2f2 grey96=f5f5f5 grey97=f7f7f7 grey98=fafafa grey99=fcfcfc honeydew=f0fff0 honeydew1=f0fff0 honeydew2=e0eee0 honeydew3=c1cdc1 honeydew4=838b83 hotpink=ff69b4 hotpink1=ff6eb4 hotpink2=ee6aa7 hotpink3=cd6090 hotpink4=8b3a62 indianred=cd5c5c indianred1=ff6a6a indianred2=ee6363 indianred3=cd5555 indianred4=8b3a3a indigo=4b0082 ivory=fffff0 ivory1=fffff0 ivory2=eeeee0 ivory3=cdcdc1 ivory4=8b8b83 khaki=f0e68c khaki1=fff68f khaki2=eee685 khaki3=cdc673 khaki4=8b864e lavender=e6e6fa lavenderblush=fff0f5 lavenderblush1=fff0f5 lavenderblush2=eee0e5 lavenderblush3=cdc1c5 lavenderblush4=8b8386 lawngreen=7cfc00 lemonchiffon=fffacd lemonchiffon1=fffacd lemonchiffon2=eee9bf lemonchiffon3=cdc9a5 lemonchiffon4=8b8970 lightblue=add8e6 lightblue1=bfefff lightblue2=b2dfee lightblue3=9ac0cd lightblue4=68838b lightcoral=f08080 lightcyan=e0ffff lightcyan1=e0ffff lightcyan2=d1eeee lightcyan3=b4cdcd lightcyan4=7a8b8b lightgoldenrod=eedd82 lightgoldenrod1=ffec8b lightgoldenrod2=eedc82 lightgoldenrod3=cdbe70 lightgoldenrod4=8b814c lightgoldenrodyellow=fafad2 lightgray=d3d3d3 lightgreen=90ee90 lightgrey=d3d3d3 lightpink=ffb6c1 lightpink1=ffaeb9 lightpink2=eea2ad lightpink3=cd8c95 lightpink4=8b5f65 lightsalmon=ffa07a lightsalmon1=ffa07a lightsalmon2=ee9572 lightsalmon3=cd8162 lightsalmon4=8b5742 lightseagreen=20b2aa lightskyblue=87cefa lightskyblue1=b0e2ff lightskyblue2=a4d3ee lightskyblue3=8db6cd lightskyblue4=607b8b lightslateblue=8470ff lightslategray=778899 lightslategrey=778899 lightsteelblue=b0c4de lightsteelblue1=cae1ff lightsteelblue2=bcd2ee lightsteelblue3=a2b5cd lightsteelblue4=6e7b8b lightyellow=ffffe0 lightyellow1=ffffe0 lightyellow2=eeeed1 lightyellow3=cdcdb4 lightyellow4=8b8b7a lime=00ff00 limegreen=32cd32 linen=faf0e6 magenta=ff00ff magenta1=ff00ff magenta2=ee00ee magenta3=cd00cd magenta4=8b008b maroon=b03060 maroon1=ff34b3 maroon2=ee30a7 maroon3=cd2990 maroon4=8b1c62 mediumaquamarine=66cdaa mediumblue=0000cd mediumorchid=ba55d3 mediumorchid1=e066ff mediumorchid2=d15fee mediumorchid3=b452cd mediumorchid4=7a378b mediumpurple=9370db mediumpurple1=ab82ff mediumpurple2=9f79ee mediumpurple3=8968cd mediumpurple4=5d478b mediumseagreen=3cb371 mediumslateblue=7b68ee mediumspringgreen=00fa9a mediumturquoise=48d1cc mediumvioletred=c71585 midnightblue=191970 mintcream=f5fffa mistyrose=ffe4e1 mistyrose1=ffe4e1 mistyrose2=eed5d2 mistyrose3=cdb7b5 mistyrose4=8b7d7b moccasin=ffe4b5 navajowhite=ffdead navajowhite1=ffdead navajowhite2=eecfa1 navajowhite3=cdb38b navajowhite4=8b795e navy=000080 navyblue=000080 oldlace=fdf5e6 olive=808000 olivedrab=6b8e23 olivedrab1=c0ff3e olivedrab2=b3ee3a olivedrab3=9acd32 olivedrab4=698b22 orange=ffa500 orange1=ffa500 orange2=ee9a00 orange3=cd8500 orange4=8b5a00 orangered=ff4500 orangered1=ff4500 orangered2=ee4000 orangered3=cd3700 orangered4=8b2500 orchid=da70d6 orchid1=ff83fa orchid2=ee7ae9 orchid3=cd69c9 orchid4=8b4789 palegoldenrod=eee8aa palegreen=98fb98 palegreen1=9aff9a palegreen2=90ee90 palegreen3=7ccd7c palegreen4=548b54 paleturquoise=afeeee paleturquoise1=bbffff paleturquoise2=aeeeee paleturquoise3=96cdcd paleturquoise4=668b8b palevioletred=db7093 palevioletred1=ff82ab palevioletred2=ee799f palevioletred3=cd6889 palevioletred4=8b475d papayawhip=ffefd5 peachpuff=ffdab9 peachpuff1=ffdab9 peachpuff2=eecbad peachpuff3=cdaf95 peachpuff4=8b7765 peru=cd853f pink=ffc0cb pink1=ffb5c5 pink2=eea9b8 pink3=cd919e pink4=8b636c plum=dda0dd plum1=ffbbff plum2=eeaeee plum3=cd96cd plum4=8b668b powderblue=b0e0e6 purple=a020f0 purple1=9b30ff purple2=912cee purple3=7d26cd purple4=551a8b rebeccapurple=663399 red=ff0000 red1=ff0000 red2=ee0000 red3=cd0000 red4=8b0000 rosybrown=bc8f8f rosybrown1=ffc1c1 rosybrown2=eeb4b4 rosybrown3=cd9b9b rosybrown4=8b6969 royalblue=4169e1 royalblue1=4876ff royalblue2=436eee royalblue3=3a5fcd royalblue4=27408b saddlebrown=8b4513 salmon=fa8072 salmon1=ff8c69 salmon2=ee8262 salmon3=cd7054 salmon4=8b4c39 sandybrown=f4a460 seagreen=2e8b57 seagreen1=54ff9f seagreen2=4eee94 seagreen3=43cd80 seagreen4=2e8b57 seashell=fff5ee seashell1=fff5ee seashell2=eee5de seashell3=cdc5bf seashell4=8b8682 sienna=a0522d sienna1=ff8247 sienna2=ee7942 sienna3=cd6839 sienna4=8b4726 silver=c0c0c0 skyblue=87ceeb skyblue1=87ceff skyblue2=7ec0ee skyblue3=6ca6cd skyblue4=4a708b slateblue=6a5acd slateblue1=836fff slateblue2=7a67ee slateblue3=6959cd slateblue4=473c8b slategray=708090 slategray1=c6e2ff slategray2=b9d3ee slategray3=9fb6cd slategray4=6c7b8b slategrey=708090 snow=fffafa snow1=fffafa snow2=eee9e9 snow3=cdc9c9 snow4=8b8989 springgreen=00ff7f springgreen1=00ff7f springgreen2=00ee76 springgreen3=00cd66 springgreen4=008b45 steelblue=4682b4 steelblue1=63b8ff steelblue2=5cacee steelblue3=4f94cd steelblue4=36648b tan=d2b48c tan1=ffa54f tan2=ee9a49 tan3=cd853f tan4=8b5a2b teal=008080 thistle=d8bfd8 thistle1=ffe1ff thistle2=eed2ee thistle3=cdb5cd thistle4=8b7b8b tomato=ff6347 tomato1=ff6347 tomato2=ee5c42 tomato3=cd4f39 tomato4=8b3626 turquoise=40e0d0 turquoise1=00f5ff turquoise2=00e5ee turquoise3=00c5cd turquoise4=00868b violet=ee82ee violetred=d02090 violetred1=ff3e96 violetred2=ee3a8c violetred3=cd3278 violetred4=8b2252 wheat=f5deb3 wheat1=ffe7ba wheat2=eed8ae wheat3=cdba96 wheat4=8b7e66 white=ffffff webgray=808080 webgreen=008000 webgrey=808080 webmaroon=800000 webpurple=800080 x11gray=bebebe x11green=00ff00 x11grey=bebebe x11maroon=b03060 x11purple=a020f0 whitesmoke=f5f5f5 yellow=ffff00 yellow1=ffff00 yellow2=eeee00 yellow3=cdcd00 yellow4=8b8b00 yellowgreen=9acd32"),$1=Ef("GreenYellow=d9ff4f Yellow=ffff00 Goldenrod=ffe629 Dandelion=ffb529 Apricot=ffad7a Peach=ff804d Melon=ff8a80 YellowOrange=ff9400 Orange=ff6321 BurntOrange=ff7d00 Bittersweet=c20300 RedOrange=ff3b21 Mahogany=a60000 Maroon=ad0000 BrickRed=b80000 Red=ff0000 OrangeRed=ff0080 RubineRed=ff00de WildStrawberry=ff0a9c Salmon=ff789e CarnationPink=ff5eff Magenta=ff00ff VioletRed=ff30ff Rhodamine=ff2eff Mulberry=a314fa RedViolet=9600a8 Fuchsia=7303eb Lavender=ff85ff Thistle=e069ff Orchid=ad5cff DarkOrchid=9933cc Purple=8c24ff Plum=8000ff Violet=361fff RoyalPurple=4019ff BlueViolet=190df5 Periwinkle=6e73ff CadetBlue=616ec4 CornflowerBlue=59deff MidnightBlue=007091 NavyBlue=0f75ff RoyalBlue=0080ff Blue=0000ff Cerulean=0fe3ff Cyan=00ffff ProcessBlue=0affff SkyBlue=61ffe0 Turquoise=26ffcc TealBlue=1ffaa3 Aquamarine=2effb2 BlueGreen=26ffab Emerald=00ff80 JungleGreen=03ff7a SeaGreen=4fff80 Green=00ff00 ForestGreen=00e000 PineGreen=00bf29 LimeGreen=80ff00 YellowGreen=8fff42 SpringGreen=bdff3d OliveGreen=009900 RawSienna=8c0000 Sepia=4d0000 Brown=660000 Tan=db9470 Gray=808080 Black=000000 White=ffffff LightYellow=ffff99 LightCyan=ccffff LightMagenta=ffccff LightPurple=ccccff LightGreen=ccffb3 LightOrange=ffd9bc Canary=ffff80 LFadedGreen=e6ffcc Pink=ffd9f2 LSkyBlue=d9f2ff"),U6=Ef("black=000000 blue=0000ff cyan=00ffff darkgray=404040 dark_gray=404040 gray=808080 green=00ff00 lightgray=c0c0c0 light_gray=c0c0c0 magenta=ff00ff orange=ffc800 pink=ffafaf red=ff0000 white=ffffff yellow=ffff00"),G6=new Map("accent3=7fc97f,beaed4,fdc086 accent4=7fc97f,beaed4,fdc086,ffff99 accent5=7fc97f,beaed4,fdc086,ffff99,386cb0 accent6=7fc97f,beaed4,fdc086,ffff99,386cb0,f0027f accent7=7fc97f,beaed4,fdc086,ffff99,386cb0,f0027f,bf5b17 accent8=7fc97f,beaed4,fdc086,ffff99,386cb0,f0027f,bf5b17,666666 blues3=deebf7,9ecae1,3182bd blues4=eff3ff,bdd7e7,6baed6,2171b5 blues5=eff3ff,bdd7e7,6baed6,3182bd,08519c blues6=eff3ff,c6dbef,9ecae1,6baed6,3182bd,08519c blues7=eff3ff,c6dbef,9ecae1,6baed6,4292c6,2171b5,084594 blues8=f7fbff,deebf7,c6dbef,9ecae1,6baed6,4292c6,2171b5,084594 blues9=f7fbff,deebf7,c6dbef,9ecae1,6baed6,4292c6,2171b5,08519c,08306b brbg10=543005,8c510a,bf812d,dfc27d,f6e8c3,c7eae5,80cdc1,35978f,01665e,003c30 brbg11=543005,8c510a,bf812d,dfc27d,f6e8c3,f5f5f5,c7eae5,80cdc1,35978f,01665e,003c30 brbg3=d8b365,f5f5f5,5ab4ac brbg4=a6611a,dfc27d,80cdc1,018571 brbg5=a6611a,dfc27d,f5f5f5,80cdc1,018571 brbg6=8c510a,d8b365,f6e8c3,c7eae5,5ab4ac,01665e brbg7=8c510a,d8b365,f6e8c3,f5f5f5,c7eae5,5ab4ac,01665e brbg8=8c510a,bf812d,dfc27d,f6e8c3,c7eae5,80cdc1,35978f,01665e brbg9=8c510a,bf812d,dfc27d,f6e8c3,f5f5f5,c7eae5,80cdc1,35978f,01665e bugn3=e5f5f9,99d8c9,2ca25f bugn4=edf8fb,b2e2e2,66c2a4,238b45 bugn5=edf8fb,b2e2e2,66c2a4,2ca25f,006d2c bugn6=edf8fb,ccece6,99d8c9,66c2a4,2ca25f,006d2c bugn7=edf8fb,ccece6,99d8c9,66c2a4,41ae76,238b45,005824 bugn8=f7fcfd,e5f5f9,ccece6,99d8c9,66c2a4,41ae76,238b45,005824 bugn9=f7fcfd,e5f5f9,ccece6,99d8c9,66c2a4,41ae76,238b45,006d2c,00441b bupu3=e0ecf4,9ebcda,8856a7 bupu4=edf8fb,b3cde3,8c96c6,88419d bupu5=edf8fb,b3cde3,8c96c6,8856a7,810f7c bupu6=edf8fb,bfd3e6,9ebcda,8c96c6,8856a7,810f7c bupu7=edf8fb,bfd3e6,9ebcda,8c96c6,8c6bb1,88419d,6e016b bupu8=f7fcfd,e0ecf4,bfd3e6,9ebcda,8c96c6,8c6bb1,88419d,6e016b bupu9=f7fcfd,e0ecf4,bfd3e6,9ebcda,8c96c6,8c6bb1,88419d,810f7c,4d004b dark23=1b9e77,d95f02,7570b3 dark24=1b9e77,d95f02,7570b3,e7298a dark25=1b9e77,d95f02,7570b3,e7298a,66a61e dark26=1b9e77,d95f02,7570b3,e7298a,66a61e,e6ab02 dark27=1b9e77,d95f02,7570b3,e7298a,66a61e,e6ab02,a6761d dark28=1b9e77,d95f02,7570b3,e7298a,66a61e,e6ab02,a6761d,666666 gnbu3=e0f3db,a8ddb5,43a2ca gnbu4=f0f9e8,bae4bc,7bccc4,2b8cbe gnbu5=f0f9e8,bae4bc,7bccc4,43a2ca,0868ac gnbu6=f0f9e8,ccebc5,a8ddb5,7bccc4,43a2ca,0868ac gnbu7=f0f9e8,ccebc5,a8ddb5,7bccc4,4eb3d3,2b8cbe,08589e gnbu8=f7fcf0,e0f3db,ccebc5,a8ddb5,7bccc4,4eb3d3,2b8cbe,08589e gnbu9=f7fcf0,e0f3db,ccebc5,a8ddb5,7bccc4,4eb3d3,2b8cbe,0868ac,084081 greens3=e5f5e0,a1d99b,31a354 greens4=edf8e9,bae4b3,74c476,238b45 greens5=edf8e9,bae4b3,74c476,31a354,006d2c greens6=edf8e9,c7e9c0,a1d99b,74c476,31a354,006d2c greens7=edf8e9,c7e9c0,a1d99b,74c476,41ab5d,238b45,005a32 greens8=f7fcf5,e5f5e0,c7e9c0,a1d99b,74c476,41ab5d,238b45,005a32 greens9=f7fcf5,e5f5e0,c7e9c0,a1d99b,74c476,41ab5d,238b45,006d2c,00441b greys3=f0f0f0,bdbdbd,636363 greys4=f7f7f7,cccccc,969696,525252 greys5=f7f7f7,cccccc,969696,636363,252525 greys6=f7f7f7,d9d9d9,bdbdbd,969696,636363,252525 greys7=f7f7f7,d9d9d9,bdbdbd,969696,737373,525252,252525 greys8=ffffff,f0f0f0,d9d9d9,bdbdbd,969696,737373,525252,252525 greys9=ffffff,f0f0f0,d9d9d9,bdbdbd,969696,737373,525252,252525,000000 oranges3=fee6ce,fdae6b,e6550d oranges4=feedde,fdbe85,fd8d3c,d94701 oranges5=feedde,fdbe85,fd8d3c,e6550d,a63603 oranges6=feedde,fdd0a2,fdae6b,fd8d3c,e6550d,a63603 oranges7=feedde,fdd0a2,fdae6b,fd8d3c,f16913,d94801,8c2d04 oranges8=fff5eb,fee6ce,fdd0a2,fdae6b,fd8d3c,f16913,d94801,8c2d04 oranges9=fff5eb,fee6ce,fdd0a2,fdae6b,fd8d3c,f16913,d94801,a63603,7f2704 orrd3=fee8c8,fdbb84,e34a33 orrd4=fef0d9,fdcc8a,fc8d59,d7301f orrd5=fef0d9,fdcc8a,fc8d59,e34a33,b30000 orrd6=fef0d9,fdd49e,fdbb84,fc8d59,e34a33,b30000 orrd7=fef0d9,fdd49e,fdbb84,fc8d59,ef6548,d7301f,990000 orrd8=fff7ec,fee8c8,fdd49e,fdbb84,fc8d59,ef6548,d7301f,990000 orrd9=fff7ec,fee8c8,fdd49e,fdbb84,fc8d59,ef6548,d7301f,b30000,7f0000 paired10=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f,ff7f00,cab2d6,6a3d9a paired11=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f,ff7f00,cab2d6,6a3d9a,ffff99 paired12=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f,ff7f00,cab2d6,6a3d9a,ffff99,b15928 paired3=a6cee3,1f78b4,b2df8a paired4=a6cee3,1f78b4,b2df8a,33a02c paired5=a6cee3,1f78b4,b2df8a,33a02c,fb9a99 paired6=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c paired7=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f paired8=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f,ff7f00 paired9=a6cee3,1f78b4,b2df8a,33a02c,fb9a99,e31a1c,fdbf6f,ff7f00,cab2d6 pastel13=fbb4ae,b3cde3,ccebc5 pastel14=fbb4ae,b3cde3,ccebc5,decbe4 pastel15=fbb4ae,b3cde3,ccebc5,decbe4,fed9a6 pastel16=fbb4ae,b3cde3,ccebc5,decbe4,fed9a6,ffffcc pastel17=fbb4ae,b3cde3,ccebc5,decbe4,fed9a6,ffffcc,e5d8bd pastel18=fbb4ae,b3cde3,ccebc5,decbe4,fed9a6,ffffcc,e5d8bd,fddaec pastel19=fbb4ae,b3cde3,ccebc5,decbe4,fed9a6,ffffcc,e5d8bd,fddaec,f2f2f2 pastel23=b3e2cd,fdcdac,cbd5e8 pastel24=b3e2cd,fdcdac,cbd5e8,f4cae4 pastel25=b3e2cd,fdcdac,cbd5e8,f4cae4,e6f5c9 pastel26=b3e2cd,fdcdac,cbd5e8,f4cae4,e6f5c9,fff2ae pastel27=b3e2cd,fdcdac,cbd5e8,f4cae4,e6f5c9,fff2ae,f1e2cc pastel28=b3e2cd,fdcdac,cbd5e8,f4cae4,e6f5c9,fff2ae,f1e2cc,cccccc piyg10=8e0152,c51b7d,de77ae,f1b6da,fde0ef,e6f5d0,b8e186,7fbc41,4d9221,276419 piyg11=8e0152,c51b7d,de77ae,f1b6da,fde0ef,f7f7f7,e6f5d0,b8e186,7fbc41,4d9221,276419 piyg3=e9a3c9,f7f7f7,a1d76a piyg4=d01c8b,f1b6da,b8e186,4dac26 piyg5=d01c8b,f1b6da,f7f7f7,b8e186,4dac26 piyg6=c51b7d,e9a3c9,fde0ef,e6f5d0,a1d76a,4d9221 piyg7=c51b7d,e9a3c9,fde0ef,f7f7f7,e6f5d0,a1d76a,4d9221 piyg8=c51b7d,de77ae,f1b6da,fde0ef,e6f5d0,b8e186,7fbc41,4d9221 piyg9=c51b7d,de77ae,f1b6da,fde0ef,f7f7f7,e6f5d0,b8e186,7fbc41,4d9221 prgn10=40004b,762a83,9970ab,c2a5cf,e7d4e8,d9f0d3,a6dba0,5aae61,1b7837,00441b prgn11=40004b,762a83,9970ab,c2a5cf,e7d4e8,f7f7f7,d9f0d3,a6dba0,5aae61,1b7837,00441b prgn3=af8dc3,f7f7f7,7fbf7b prgn4=7b3294,c2a5cf,a6dba0,008837 prgn5=7b3294,c2a5cf,f7f7f7,a6dba0,008837 prgn6=762a83,af8dc3,e7d4e8,d9f0d3,7fbf7b,1b7837 prgn7=762a83,af8dc3,e7d4e8,f7f7f7,d9f0d3,7fbf7b,1b7837 prgn8=762a83,9970ab,c2a5cf,e7d4e8,d9f0d3,a6dba0,5aae61,1b7837 prgn9=762a83,9970ab,c2a5cf,e7d4e8,f7f7f7,d9f0d3,a6dba0,5aae61,1b7837 pubu3=ece7f2,a6bddb,2b8cbe pubu4=f1eef6,bdc9e1,74a9cf,0570b0 pubu5=f1eef6,bdc9e1,74a9cf,2b8cbe,045a8d pubu6=f1eef6,d0d1e6,a6bddb,74a9cf,2b8cbe,045a8d pubu7=f1eef6,d0d1e6,a6bddb,74a9cf,3690c0,0570b0,034e7b pubu8=fff7fb,ece7f2,d0d1e6,a6bddb,74a9cf,3690c0,0570b0,034e7b pubu9=fff7fb,ece7f2,d0d1e6,a6bddb,74a9cf,3690c0,0570b0,045a8d,023858 pubugn3=ece2f0,a6bddb,1c9099 pubugn4=f6eff7,bdc9e1,67a9cf,02818a pubugn5=f6eff7,bdc9e1,67a9cf,1c9099,016c59 pubugn6=f6eff7,d0d1e6,a6bddb,67a9cf,1c9099,016c59 pubugn7=f6eff7,d0d1e6,a6bddb,67a9cf,3690c0,02818a,016450 pubugn8=fff7fb,ece2f0,d0d1e6,a6bddb,67a9cf,3690c0,02818a,016450 pubugn9=fff7fb,ece2f0,d0d1e6,a6bddb,67a9cf,3690c0,02818a,016c59,014636 puor10=7f3b08,b35806,e08214,fdb863,fee0b6,d8daeb,b2abd2,8073ac,542788,2d004b puor11=7f3b08,b35806,e08214,fdb863,fee0b6,f7f7f7,d8daeb,b2abd2,8073ac,542788,2d004b puor3=f1a340,f7f7f7,998ec3 puor4=e66101,fdb863,b2abd2,5e3c99 puor5=e66101,fdb863,f7f7f7,b2abd2,5e3c99 puor6=b35806,f1a340,fee0b6,d8daeb,998ec3,542788 puor7=b35806,f1a340,fee0b6,f7f7f7,d8daeb,998ec3,542788 puor8=b35806,e08214,fdb863,fee0b6,d8daeb,b2abd2,8073ac,542788 puor9=b35806,e08214,fdb863,fee0b6,f7f7f7,d8daeb,b2abd2,8073ac,542788 purd3=e7e1ef,c994c7,dd1c77 purd4=f1eef6,d7b5d8,df65b0,ce1256 purd5=f1eef6,d7b5d8,df65b0,dd1c77,980043 purd6=f1eef6,d4b9da,c994c7,df65b0,dd1c77,980043 purd7=f1eef6,d4b9da,c994c7,df65b0,e7298a,ce1256,91003f purd8=f7f4f9,e7e1ef,d4b9da,c994c7,df65b0,e7298a,ce1256,91003f purd9=f7f4f9,e7e1ef,d4b9da,c994c7,df65b0,e7298a,ce1256,980043,67001f purples3=efedf5,bcbddc,756bb1 purples4=f2f0f7,cbc9e2,9e9ac8,6a51a3 purples5=f2f0f7,cbc9e2,9e9ac8,756bb1,54278f purples6=f2f0f7,dadaeb,bcbddc,9e9ac8,756bb1,54278f purples7=f2f0f7,dadaeb,bcbddc,9e9ac8,807dba,6a51a3,4a1486 purples8=fcfbfd,efedf5,dadaeb,bcbddc,9e9ac8,807dba,6a51a3,4a1486 purples9=fcfbfd,efedf5,dadaeb,bcbddc,9e9ac8,807dba,6a51a3,54278f,3f007d rdbu10=67001f,b2182b,d6604d,f4a582,fddbc7,d1e5f0,92c5de,4393c3,2166ac,053061 rdbu11=67001f,b2182b,d6604d,f4a582,fddbc7,f7f7f7,d1e5f0,92c5de,4393c3,2166ac,053061 rdbu3=ef8a62,f7f7f7,67a9cf rdbu4=ca0020,f4a582,92c5de,0571b0 rdbu5=ca0020,f4a582,f7f7f7,92c5de,0571b0 rdbu6=b2182b,ef8a62,fddbc7,d1e5f0,67a9cf,2166ac rdbu7=b2182b,ef8a62,fddbc7,f7f7f7,d1e5f0,67a9cf,2166ac rdbu8=b2182b,d6604d,f4a582,fddbc7,d1e5f0,92c5de,4393c3,2166ac rdbu9=b2182b,d6604d,f4a582,fddbc7,f7f7f7,d1e5f0,92c5de,4393c3,2166ac rdgy10=67001f,b2182b,d6604d,f4a582,fddbc7,e0e0e0,bababa,878787,4d4d4d,1a1a1a rdgy11=67001f,b2182b,d6604d,f4a582,fddbc7,ffffff,e0e0e0,bababa,878787,4d4d4d,1a1a1a rdgy3=ef8a62,ffffff,999999 rdgy4=ca0020,f4a582,bababa,404040 rdgy5=ca0020,f4a582,ffffff,bababa,404040 rdgy6=b2182b,ef8a62,fddbc7,e0e0e0,999999,4d4d4d rdgy7=b2182b,ef8a62,fddbc7,ffffff,e0e0e0,999999,4d4d4d rdgy8=b2182b,d6604d,f4a582,fddbc7,e0e0e0,bababa,878787,4d4d4d rdgy9=b2182b,d6604d,f4a582,fddbc7,ffffff,e0e0e0,bababa,878787,4d4d4d rdpu3=fde0dd,fa9fb5,c51b8a rdpu4=feebe2,fbb4b9,f768a1,ae017e rdpu5=feebe2,fbb4b9,f768a1,c51b8a,7a0177 rdpu6=feebe2,fcc5c0,fa9fb5,f768a1,c51b8a,7a0177 rdpu7=feebe2,fcc5c0,fa9fb5,f768a1,dd3497,ae017e,7a0177 rdpu8=fff7f3,fde0dd,fcc5c0,fa9fb5,f768a1,dd3497,ae017e,7a0177 rdpu9=fff7f3,fde0dd,fcc5c0,fa9fb5,f768a1,dd3497,ae017e,7a0177,49006a rdylbu10=a50026,d73027,f46d43,fdae61,fee090,e0f3f8,abd9e9,74add1,4575b4,313695 rdylbu11=a50026,d73027,f46d43,fdae61,fee090,ffffbf,e0f3f8,abd9e9,74add1,4575b4,313695 rdylbu3=fc8d59,ffffbf,91bfdb rdylbu4=d7191c,fdae61,abd9e9,2c7bb6 rdylbu5=d7191c,fdae61,ffffbf,abd9e9,2c7bb6 rdylbu6=d73027,fc8d59,fee090,e0f3f8,91bfdb,4575b4 rdylbu7=d73027,fc8d59,fee090,ffffbf,e0f3f8,91bfdb,4575b4 rdylbu8=d73027,f46d43,fdae61,fee090,e0f3f8,abd9e9,74add1,4575b4 rdylbu9=d73027,f46d43,fdae61,fee090,ffffbf,e0f3f8,abd9e9,74add1,4575b4 rdylgn10=a50026,d73027,f46d43,fdae61,fee08b,d9ef8b,a6d96a,66bd63,1a9850,006837 rdylgn11=a50026,d73027,f46d43,fdae61,fee08b,ffffbf,d9ef8b,a6d96a,66bd63,1a9850,006837 rdylgn3=fc8d59,ffffbf,91cf60 rdylgn4=d7191c,fdae61,a6d96a,1a9641 rdylgn5=d7191c,fdae61,ffffbf,a6d96a,1a9641 rdylgn6=d73027,fc8d59,fee08b,d9ef8b,91cf60,1a9850 rdylgn7=d73027,fc8d59,fee08b,ffffbf,d9ef8b,91cf60,1a9850 rdylgn8=d73027,f46d43,fdae61,fee08b,d9ef8b,a6d96a,66bd63,1a9850 rdylgn9=d73027,f46d43,fdae61,fee08b,ffffbf,d9ef8b,a6d96a,66bd63,1a9850 reds3=fee0d2,fc9272,de2d26 reds4=fee5d9,fcae91,fb6a4a,cb181d reds5=fee5d9,fcae91,fb6a4a,de2d26,a50f15 reds6=fee5d9,fcbba1,fc9272,fb6a4a,de2d26,a50f15 reds7=fee5d9,fcbba1,fc9272,fb6a4a,ef3b2c,cb181d,99000d reds8=fff5f0,fee0d2,fcbba1,fc9272,fb6a4a,ef3b2c,cb181d,99000d reds9=fff5f0,fee0d2,fcbba1,fc9272,fb6a4a,ef3b2c,cb181d,a50f15,67000d set13=e41a1c,377eb8,4daf4a set14=e41a1c,377eb8,4daf4a,984ea3 set15=e41a1c,377eb8,4daf4a,984ea3,ff7f00 set16=e41a1c,377eb8,4daf4a,984ea3,ff7f00,ffff33 set17=e41a1c,377eb8,4daf4a,984ea3,ff7f00,ffff33,a65628 set18=e41a1c,377eb8,4daf4a,984ea3,ff7f00,ffff33,a65628,f781bf set19=e41a1c,377eb8,4daf4a,984ea3,ff7f00,ffff33,a65628,f781bf,999999 set23=66c2a5,fc8d62,8da0cb set24=66c2a5,fc8d62,8da0cb,e78ac3 set25=66c2a5,fc8d62,8da0cb,e78ac3,a6d854 set26=66c2a5,fc8d62,8da0cb,e78ac3,a6d854,ffd92f set27=66c2a5,fc8d62,8da0cb,e78ac3,a6d854,ffd92f,e5c494 set28=66c2a5,fc8d62,8da0cb,e78ac3,a6d854,ffd92f,e5c494,b3b3b3 set310=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69,fccde5,d9d9d9,bc80bd set311=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69,fccde5,d9d9d9,bc80bd,ccebc5 set312=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69,fccde5,d9d9d9,bc80bd,ccebc5,ffed6f set33=8dd3c7,ffffb3,bebada set34=8dd3c7,ffffb3,bebada,fb8072 set35=8dd3c7,ffffb3,bebada,fb8072,80b1d3 set36=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462 set37=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69 set38=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69,fccde5 set39=8dd3c7,ffffb3,bebada,fb8072,80b1d3,fdb462,b3de69,fccde5,d9d9d9 spectral10=9e0142,d53e4f,f46d43,fdae61,fee08b,e6f598,abdda4,66c2a5,3288bd,5e4fa2 spectral11=9e0142,d53e4f,f46d43,fdae61,fee08b,ffffbf,e6f598,abdda4,66c2a5,3288bd,5e4fa2 spectral3=fc8d59,ffffbf,99d594 spectral4=d7191c,fdae61,abdda4,2b83ba spectral5=d7191c,fdae61,ffffbf,abdda4,2b83ba spectral6=d53e4f,fc8d59,fee08b,e6f598,99d594,3288bd spectral7=d53e4f,fc8d59,fee08b,ffffbf,e6f598,99d594,3288bd spectral8=d53e4f,f46d43,fdae61,fee08b,e6f598,abdda4,66c2a5,3288bd spectral9=d53e4f,f46d43,fdae61,fee08b,ffffbf,e6f598,abdda4,66c2a5,3288bd ylgn3=f7fcb9,addd8e,31a354 ylgn4=ffffcc,c2e699,78c679,238443 ylgn5=ffffcc,c2e699,78c679,31a354,006837 ylgn6=ffffcc,d9f0a3,addd8e,78c679,31a354,006837 ylgn7=ffffcc,d9f0a3,addd8e,78c679,41ab5d,238443,005a32 ylgn8=ffffe5,f7fcb9,d9f0a3,addd8e,78c679,41ab5d,238443,005a32 ylgn9=ffffe5,f7fcb9,d9f0a3,addd8e,78c679,41ab5d,238443,006837,004529 ylgnbu3=edf8b1,7fcdbb,2c7fb8 ylgnbu4=ffffcc,a1dab4,41b6c4,225ea8 ylgnbu5=ffffcc,a1dab4,41b6c4,2c7fb8,253494 ylgnbu6=ffffcc,c7e9b4,7fcdbb,41b6c4,2c7fb8,253494 ylgnbu7=ffffcc,c7e9b4,7fcdbb,41b6c4,1d91c0,225ea8,0c2c84 ylgnbu8=ffffd9,edf8b1,c7e9b4,7fcdbb,41b6c4,1d91c0,225ea8,0c2c84 ylgnbu9=ffffd9,edf8b1,c7e9b4,7fcdbb,41b6c4,1d91c0,225ea8,253494,081d58 ylorbr3=fff7bc,fec44f,d95f0e ylorbr4=ffffd4,fed98e,fe9929,cc4c02 ylorbr5=ffffd4,fed98e,fe9929,d95f0e,993404 ylorbr6=ffffd4,fee391,fec44f,fe9929,d95f0e,993404 ylorbr7=ffffd4,fee391,fec44f,fe9929,ec7014,cc4c02,8c2d04 ylorbr8=ffffe5,fff7bc,fee391,fec44f,fe9929,ec7014,cc4c02,8c2d04 ylorbr9=ffffe5,fff7bc,fee391,fec44f,fe9929,ec7014,cc4c02,993404,662506 ylorrd3=ffeda0,feb24c,f03b20 ylorrd4=ffffb2,fecc5c,fd8d3c,e31a1c ylorrd5=ffffb2,fecc5c,fd8d3c,f03b20,bd0026 ylorrd6=ffffb2,fed976,feb24c,fd8d3c,f03b20,bd0026 ylorrd7=ffffb2,fed976,feb24c,fd8d3c,fc4e2a,e31a1c,b10026 ylorrd8=ffffcc,ffeda0,fed976,feb24c,fd8d3c,fc4e2a,e31a1c,b10026 ylorrd9=ffffcc,ffeda0,fed976,feb24c,fd8d3c,fc4e2a,e31a1c,bd0026,800026".split(" ").map(t=>{const e=t.indexOf("=");return[t.slice(0,e),t.slice(e+1).split(",").map(n=>`#${n}`)]})),j6=new Set(["transparent","none","invis"]),F6=/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function z6(t){return t.toString(16).padStart(2,"0")}function W6(t,e,n){const i=Math.floor(t*6),r=t*6-i,s=n*(1-e),o=n*(1-r*e),l=n*(1-(1-r)*e);return`#${[[n,l,s],[o,n,s],[s,n,l],[s,o,n],[l,s,n],[n,s,o]][i%6].map(c=>z6(Math.trunc(c*255))).join("")}`}function B6(t,e){if(t.startsWith("#")){const s=/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{1,2})?/.exec(t);return s===null?null:{hex:`#${s[1]}${s[2]}${s[3]}`.toLowerCase(),alpha:s[4]===void 0?1:Number.parseInt(s[4],16)/255}}const n=/^[.\d]/.test(t)?H6(t):null;if(n!==null)return{hex:n,alpha:1};const i=V6(t.toLowerCase(),e);if(i===null)return null;if(j6.has(i.name))return{hex:"#fffffe",alpha:0};const r=Y6(i.name,i.scheme);return r===void 0?null:{hex:r,alpha:1}}function H6(t){const e=t.split(/[ ,]+/);if(e.length<3||!e.slice(0,3).every(s=>F6.test(s)))return null;const[n,i,r]=e.slice(0,3).map(s=>Math.min(1,Math.max(0,Number(s))));return W6(n,i,r)}function V6(t,e){if(!t.startsWith("/"))return{name:t,scheme:e};const n=t.indexOf("/",1);if(n<0)return null;const i=t.slice(1,n);return{name:t.slice(n+1),scheme:i===""?e:i}}function Y6(t,e){if(e==="x11")return M6.get(t);if(e==="svg")return Sl.get(t);const n=G6.get(e),i=/^\d{1,3}$/.test(t)?Number(t):0;return n!==void 0&&i>=1?n[i-1]:void 0}function K6(t){return t==="line"?{hex:"#fffffe",alpha:0,unknown:!1,list:null}:{hex:"#000000",alpha:1,unknown:!1,list:null}}function X6(t){const e=t.indexOf(";");return e>=0?t.slice(0,e):t}function q6(t,e,n,i){const r=i&&t.startsWith(e)?Sl.get(e.toLowerCase()):void 0;if(r!==void 0)return{hex:r,alpha:1};if(e==="")return null;const s=n===null||n.trim()===""?"x11":n.toLowerCase();return B6(e,s)}function J6(t,e,n,i=!0){let r=t.replace(/^[ \t\r\n]+/,""),s=null;const o=r.indexOf(":"),l=n==="line"||n==="text";if(o>=0){if(r=r.slice(0,o),i&&l&&t.startsWith(r)&&Sl.has(r.toLowerCase()))return K6(n);l||(r=X6(r),s=n==="fill"?"gradient":"lines")}const a=q6(t,r,e,i);return a===null?{hex:"#000000",alpha:1,unknown:!0,list:s}:{hex:a.hex,alpha:a.alpha,unknown:!1,list:s}}function $h(t){return Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")}function Bi(t,e,n){return`#${$h(t)}${$h(e)}${$h(n)}`}function xo(t){return P(Math.max(0,Math.min(1,t)))}function Mo(t,e){return[t[0][0]*e[0]+t[0][1]*e[1]+t[0][2]*e[2],t[1][0]*e[0]+t[1][1]*e[1]+t[1][2]*e[2],t[2][0]*e[0]+t[2][1]*e[1]+t[2][2]*e[2]]}const Z6=[[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],Q6=[[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],eU=[[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.929286861586343,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],tU=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],nU=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],iU=[[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]];function ig(t){const e=t.map(i=>{const r=Math.abs(i);return Math.sign(i)*(r<=.04045?r/12.92:((r+.055)/1.055)**2.4)}),n=Mo(eU,Mo(Z6,e));return Mo(nU,n.map(Math.cbrt))}function C1(t){const e=Mo(iU,t).map(n=>n**3);return Mo(Q6,Mo(tU,e)).map(n=>{const i=Math.abs(n);return Math.sign(n)*(i>.0031308?1.055*i**(1/2.4)-.055:12.92*i)})}function rg(t){return t.every(e=>e>=0&&e<=1)}function sg(t){return t.map(e=>Math.max(0,Math.min(1,e)))}function v1(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2])}function rU(t){if(rg(t))return t;const e=.02,[n,i,r]=ig(t);if(n>=1)return[1,1,1];if(n<=0)return[0,0,0];const s=Math.abs(i)<2e-4&&Math.abs(r)<2e-4,o=(Math.atan2(r,i)*180/Math.PI%360+360)%360,l=u=>s?[n,0,0]:[n,u*Math.cos(o*Math.PI/180),u*Math.sin(o*Math.PI/180)],a=Math.sqrt(i**2+r**2),c=C1(l(a));if(rg(c))return c;const d=sg(c);return v1(ig(d),l(a))<e?sg(t):sU(l,a,d)}function sU(t,e,n){let s=n,o=0,l=e,a=!0;for(;l-o>1e-4;){const c=(o+l)/2,d=t(c),u=C1(d);if(a&&rg(u)){o=c;continue}s=sg(u);const f=v1(ig(s),d);if(f>=.02)l=c;else{if(.02-f<1e-4)break;a=!1,o=c}}return s}function WE(t){const[e,n,i]=rU(t);return Bi(e*255,n*255,i*255)}const oU=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,lU=/(%|deg|grad|rad|turn)$/i;function aU(t){const e=t.split("/");if(e.length>2)return null;const n=e[0].split(/[\s,]+/).filter(r=>r!=="");let i=e.length===2?e[1].trim():void 0;return i===void 0&&n.length===4&&(i=n.pop()),n.length===3&&i!==""?{parts:n,alpha:i}:null}function D1(t){const e=lU.exec(t)?.[1]??"",n=t.slice(0,t.length-e.length);if(!oU.test(n))return null;const i=Number(n);return Number.isFinite(i)?{value:i,unit:e.toLowerCase()}:null}function cU(t){if(t===void 0)return 1;const e=D1(t);return e===null||e.unit!==""&&e.unit!=="%"?null:xo(e.unit==="%"?e.value/100:e.value)}function dU(t){const e=/^(rgba?|hsla?)\(([^()]*)\)$/i.exec(t);if(e===null)return null;const n=aU(e[2]);if(n===null)return null;const i=n.parts.map(D1),r=cU(n.alpha);if(i.includes(null)||r===null)return null;const[s,o,l]=i;if(e[1].toLowerCase().startsWith("rgb")){if([s,o,l].some(p=>p.unit!==""&&p.unit!=="%"))return null;const h=[s,o,l].map(p=>p.unit==="%"?p.value/100:p.value/255);return{hex:WE(h),alpha:r}}const a={"":360,deg:360,grad:400,rad:2*Math.PI,turn:1};if(s.unit==="%"||!Object.hasOwn(a,s.unit)||[o,l].some(h=>h.unit!==""&&h.unit!=="%"))return null;const c=(s.value/a[s.unit]*360%360+360)%360,d=o.value/100,u=l.value/100,f=h=>{const p=(h+c/30)%12;return u-d*Math.min(u,1-u)*Math.max(-1,Math.min(p-3,9-p,1))};return{hex:WE([f(0),f(8),f(4)]),alpha:r}}function By(t,e){const n=/^#([0-9a-f]+)$/i.exec(t);if(n===null)return null;const i=n[1],r=s=>Number.parseInt(i.slice(s,s+2),16);switch(i.length){case 3:case 4:{const s=Array.from(i,o=>Number.parseInt(o+o,16));return{hex:Bi(s[0],s[1],s[2]),alpha:i.length===4?xo(s[3]/255):1}}case 6:return{hex:`#${i.toLowerCase()}`,alpha:1};case 8:return e?{hex:Bi(r(2),r(4),r(6)),alpha:xo(r(0)/255)}:{hex:Bi(r(0),r(2),r(4)),alpha:xo(r(6)/255)};default:return null}}function Ch(t){const e=t.toLowerCase();if(e==="transparent")return{hex:"#000000",alpha:0};const n=Sl.get(e);return n!==void 0?{hex:n,alpha:1}:By(t,!1)??dU(t)}function uU(t){const e=t.trim(),n=/^rgba?\s*\(/.exec(e);if(n===null||!e.endsWith(")"))return null;const i=e.slice(n[0].length,-1).split(",");if(i.length<3)return null;const r=i.slice(3).join(",").trimStart(),s=i.length>3?i[2].trim():i[2].trimStart(),o=[i[0].trim(),i[1].trim(),s];return!o.every(l=>/^\d*$/.test(l))||/[\n\r\u2028\u2029]/.test(r)?null:[o[0],o[1],o[2],r]}function k1(t){const e=t.toLowerCase();if(e==="transparent")return{color:"#000000",alpha:0,read:!0};const n=Sl.get(e);if(n!==void 0)return k1(n);let i=[0,0,0],r=1,s=!1;if(t.startsWith("#")){s=/^#(?:[\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i.test(t);const c=t.length===4?[1,1,2,2,3,3]:[1,2,3,4,5,6];i=[0,2,4].map(d=>Number.parseInt(t.charAt(c[d])+t.charAt(c[d+1]),16)||0),t.length===9&&(r=Number.parseInt(t.slice(7,9),16)/255)}else{const c=uU(t);c!==null&&(s=!0,i=[Number(c[0]),Number(c[1]),Number(c[2])],c[3]&&(r=Number(c[3])))}const[o,l,a]=i.map(c=>c&255);return{color:Bi(o,l,a),alpha:(r*255&255)/255,read:s}}const fU=/^(?:\d+(?:\.\d*)?|\.\d+)$/;function hU(t){const e=$1.get(t);if(e!==void 0)return{hex:e,alpha:1};const n=/^Gray(\d\d)$/.exec(t);if(n!==null){const f=255*(1-Number(n[1])/100);return{hex:Bi(f,f,f),alpha:1}}const i=/^RGB([0-9A-Fa-f]{6})$/.exec(t);if(i!==null)return{hex:`#${i[1].toLowerCase()}`,alpha:1};const r=/^CMYK([0-9A-Fa-f]{8})$/.exec(t);let s=null,o="";if(r===null){const f=/^(RGB|CMYK)\(([^()]*)\)$/.exec(t),h=f===null?[]:f[2].split(",");f!==null&&h.every(p=>fU.test(p))&&(o=f[1],s=h.map(Number))}else o="CMYK",s=[0,2,4,6].map(f=>Number.parseInt(r[1].slice(f,f+2),16)/255);if(s===null||s.some(f=>f>1)||s.length!==(o==="RGB"?3:4))return By(t,!1);if(o==="RGB")return{hex:Bi(s[0]*255,s[1]*255,s[2]*255),alpha:1};const[l,a,c,d]=s,u=f=>255*(1-Math.min(1,f+d));return{hex:Bi(u(l),u(a),u(c)),alpha:1}}function pU(t){if(!Object.hasOwn(t,"r")||!Object.hasOwn(t,"g")||!Object.hasOwn(t,"b"))return null;const e=t,[n,i,r]=[e.r,e.g,e.b].map(o=>typeof o=="number"||typeof o=="string"?Number(o):Number.NaN);if(![n,i,r].every(o=>Number.isFinite(o)&&o>=0&&o<=255))return null;const s=Object.hasOwn(t,"a")&&e.a!==void 0&&e.a!==null?Number(e.a):1;return Number.isFinite(s)?{hex:Bi(n,i,r),alpha:xo(s)}:null}function ve(t,e,n,i={}){if(t!==null&&typeof t=="object")return mU(t,e,n);if(typeof t=="number"&&e==="java"&&Number.isInteger(t)&&Math.abs(t)<=4294967295){Oi(n,1);const o=t>>>0;return{color:Bi(o>>>16&255,o>>>8&255,o&255),alpha:1}}if(e==="graphology"&&typeof t=="string"&&t.trim()==="")return Oi(n,1),H(n,v.BAD_VALUE,t),{color:"#000000",alpha:1};const r=ut(t,n);if(r===null)return null;if(e==="graphviz"||e==="x11")return yU(r,e==="x11"?"x11":"graphviz",n,i);if(e==="graphology")return gU(t,r,n);const s=bU(r.trim(),e);return s===null?(H(n,v.BAD_VALUE,r),null):{color:s.hex,alpha:s.alpha}}function gU(t,e,n){if(typeof t!="string")return H(n,v.BAD_VALUE,e),null;const i=k1(e);return i.read||H(n,v.BAD_VALUE,e),{color:i.color,alpha:i.alpha}}function mU(t,e,n){Oi(n,1);const i=e==="gexf"||e==="gephi"?pU(t):null;return i===null?(H(n,v.BAD_VALUE,t),null):{color:i.hex,alpha:i.alpha}}function yU(t,e,n,i){const r=e==="x11",s=J6(t,r?null:i.scheme??null,i.use??"line",!r);return s.unknown&&(H(n,v.BAD_VALUE,t),r)?null:(s.list!==null&&H(n,s.list==="gradient"?v.GRADIENT:v.COLOR_LIST,t),{color:s.hex,alpha:xo(s.alpha)})}function bU(t,e){const n=t.toLowerCase();switch(e){case"dvips":return hU(t);case"yfiles3":return By(t,!0)??Ch(n.replaceAll("_",""));case"java":case"gephi":case"cytoscape":{const i=U6.get(n);return i===void 0?Ch(t):{hex:i,alpha:1}}default:return Ch(t)}}function Ol(t,e,n,i){return i?t.alpha===1?e:P((e??1)*t.alpha):(t.alpha<1&&H(n,v.ALPHA_DROPPED,t.color),e)}function E(t,e){return{value:t,source:e}}const me="cytoscape-impl vizmap-gui-impl default_vizmap.xml, style default, line",Ae="cytoscape-api BasicVisualLexicon.java line",Dr="cytoscape-impl ding-presentation-impl 3.10.5 org.cytoscape.ding.impl.strokes: ZigzagStroke (amplitude 10, a turn every 10) and SineWaveStroke (amplitude 10, wavelength 20)",X="cytoscape.js 3.34.3 dist/cytoscape.cjs.js line",Re="graphviz.org/docs/attrs",EU="yEd Q&A, How can I change the default nodes and/or default edges",Gn="yEd GraphML corpus, most frequent value",xl="yFiles for Java 2.19 EdgeRealizer API docs",wU="yFiles for Java 2.19 DefaultBackgroundRenderer API docs",jt="yFiles for HTML API docs,",wn="gephi master 92e503df61a7",We="vis-network 10.1.2 vis-network.esm.js",Ml="vis-network 9.1.9 standalone/umd/vis-network.js",kr="sigma 3.0.3 packages/sigma/src",si="sigma 4.0.1 dist/types-d8ce3382.esm.js",Ji="Pajek 6.02 reference manual",Ii="ogdf master 1a40505ac006",Zi="OGDF 2025.10 GraphIO::drawSVG with its default SVGSettings (graph-io/test/fidelity/oracles/gml-specimen-labels-p5.svg: ",Be="networkx 6da4704cbf32 networkx/drawing/nx_pylab.py line",On="measured in the program's own SVG export (graph-io/test/fidelity/oracles/",Nt=`${On}pajek-`,BE={length:(t,e)=>2*(6*t+e),aspect:.5,shapes:{square:{length:.5,aspect:1},circle:{length:.5,aspect:1},"circle-open":{length:.5,aspect:1},half:{length:.5675,aspect:.881},"other:half-bottom":{length:.5675,aspect:.881},tee:{length:.1,aspect:10},"other:open-square":{length:.5,aspect:1},"other:half-circle":{length:.25,aspect:2},"other:open-half-circle":{length:.25,aspect:2}},source:`${On}cx-ndex-90f78bcd, cx2-u2os-hierarchy, cx2-signor-aml, cx2-syn-bypass, cx-syn-mappings: each arrow's unit glyph), Cytoscape 3.10.5`},HE=E("midpoints","cytoscape-impl ding-presentation-impl GraphGraphics.java computeCubicPolyEdgePath (cubic pieces between the handles' midpoints, controls pulled toward each handle by CURVE_ELLIPTICAL)"),R1=`${On}xgmml-specimen-labels: label-background-* boxes and the captions' two lines), Cytoscape 3.10.5`,Cc=E(0,R1),vc=E(1,R1),VE=E("inside",`${On}cx2-repro-shared-interaction, cys-luad-vest-v2, cx2-synthetic-lethal), Cytoscape 3.10.5`),YE={length:(t,e)=>6*t+e,aspect:1,source:`${On}graphml-*, draw.io 32.4.1 standing in for yEd)`};function jn(t){const e=`${X} 4386`;return E(8,t===void 0?e:`${e} (Cytoscape.js's rule; ${t} states none)`)}const _U=new Map([{tool:"cytoscape",version:"cytoscape-impl develop 6c63e97c5152 (3.11)",units:"px",roundedCornerRadius:jn("cytoscape"),arrowhead:BE,node:{fill:E("#89d0f5",`${me} 382`),fillOpacity:E(1,`${me} 383`),shape:E("round-rectangle",`${me} 367`),width:E(75,`${me} 384`),height:E(35,`${me} 358`),borderColor:E("#cccccc",`${me} 392`),borderWidth:E(0,`${me} 350`),borderStyle:E("solid",`${me} 366`),borderPosition:VE,borderWaveAmplitude:E(10,Dr),borderWavePeriod:E(20,Dr),labelColor:E("#000000",`${me} 395`),labelFont:E("DejaVu Sans, sans-serif",`${me} 370 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${me} 370`),labelItalic:E(!1,`${me} 370`),labelSize:E(12,`${me} 371`),labelWrapWidth:E(200,`${me} 372`),labelWrapTrailingSpace:E(!0,`${On}cx-ndex-90f78bcd: each word is measured with the space after it), Cytoscape 3.10.5`),labelPosition:E("center",`${me} 380`),labelPadding:Cc,labelLineHeight:vc},edge:{color:E("#848484",`${me} 431`),width:E(2,`${me} 417`),lineStyle:E("solid",`${me} 438`),waveAmplitude:E(10,Dr),wavePeriod:E(20,Dr),opacity:E(1,`${me} 423`),sourceArrow:E("none",`${me} 437`),targetArrow:E("none",`${me} 428`),sourceArrowColor:E("#000000",`${me} 432`),targetArrowColor:E("#000000",`${me} 432`),labelColor:E("#000000",`${me} 415`),labelFont:E("DejaVu Sans, sans-serif",`${me} 439 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${me} 439`),labelItalic:E(!1,`${me} 439`),labelSize:E(10,`${me} 439`),labelPadding:Cc,labelLineHeight:vc,curved:E(!1,`${me} 422`),bendCurve:HE},graph:{background:E("#ffffff",`${me} 335`)},derived:[{kind:"labelFromColumn",column:"name",source:`${me} 406-408`}]},{tool:"cytoscape-fallbacks",version:"cytoscape-api develop (3.11)",units:"px",roundedCornerRadius:jn("cytoscape-fallbacks"),arrowhead:BE,node:{fill:E("#c80000",`${Ae} 83`),fillOpacity:E(1,`${Ae} 273`),shape:E("ellipse",`${Ae} 302-303`),width:E(60,`${Ae} 155`),height:E(40,`${Ae} 163`),borderColor:E("#000000",`${Ae} 230`),borderWidth:E(2,`${Ae} 54`),borderPosition:VE,borderWaveAmplitude:E(10,Dr),borderWavePeriod:E(20,Dr),labelColor:E("#000000",`${Ae} 91`),labelFont:E("DejaVu Sans, sans-serif",`${Ae} 255 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${Ae} 255`),labelItalic:E(!1,`${Ae} 255`),labelSize:E(12,`${Ae} 55`),labelWrapWidth:E(200,`${Ae} 196`),labelWrapTrailingSpace:E(!0,`${On}cx-ndex-90f78bcd: each word is measured with the space after it), Cytoscape 3.10.5`),labelPosition:E("center",`${Ae} 205`),labelPadding:Cc,labelLineHeight:vc},edge:{color:E("#404040",`${Ae} 469`),width:E(1,`${Ae} 368`),lineStyle:E("solid",`${Ae} 392`),waveAmplitude:E(10,Dr),wavePeriod:E(20,Dr),sourceArrow:E("none",`${Ae} 487`),targetArrow:E("none",`${Ae} 493`),labelColor:E("#000000",`${Ae} 327`),labelFont:E("DejaVu Sans, sans-serif",`${Ae} 408 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${Ae} 408`),labelItalic:E(!1,`${Ae} 408`),labelSize:E(10,`${Ae} 416`),labelPadding:Cc,labelLineHeight:vc,bendCurve:HE},graph:{background:E("#ffffff",`${Ae} 667`)},derived:[]},{tool:"cytoscape-js",version:"cytoscape.js 3.34.3",units:"px",roundedCornerRadius:jn(),arrowhead:{length:(t,e)=>.3*Math.max((e*13.37)**.9,29)*t,aspect:1,shapes:{tee:{length:1/3,aspect:3},"other:triangle-tee":{length:5/3,aspect:.6},"other:triangle-cross":{length:1.5,aspect:.66},"other:circle-triangle":{length:2,aspect:.5},"other:chevron":{length:2/3,aspect:1.5}},source:`${X} 23497 (getArrowWidth), 22714-22716 (triangle), 22813-22814 (tee), 22627 (arrowShapeWidth)`},node:{fill:E("#999999",`${X} 18536`),fillOpacity:E(1,`${X} 18538`),shape:E("ellipse",`${X} 18571`),width:E(30,`${X} 18569`),height:E(30,`${X} 18570`),borderColor:E("#000000",`${X} 18555`),borderWidth:E(0,`${X} 18557`),borderStyle:E("solid",`${X} 18558`),borderPosition:E("center",`${X} 18563`),outerBorderColor:E("#999999",`${X} 18564`),underlayColor:E("#000000",`${X} 18524`),underlayPadding:E(10,`${X} 18525`),underlayShape:E("round-rectangle",`${X} 18526`),overlayColor:E("#000000",`${X} 18519`),overlayPadding:E(10,`${X} 18520`),overlayShape:E("round-rectangle",`${X} 18521`),opacity:E(1,`${X} 18503`),labelColor:E("#000000",`${X} 18474`),labelSize:E(16,`${X} 18496`),labelFont:E("Helvetica Neue, Helvetica, sans-serif",`${X} 18493`),labelWeight:E("normal",`${X} 18495`),labelPosition:E("top",`${X} 18470-18471`),labelWrapTrailingSpace:E(!0,`${X} 25218`)},edge:{color:E("#999999",`${X} 18639`),sourceArrowColor:E("#999999",`${X} 18639`),targetArrowColor:E("#999999",`${X} 18639`),outlineColor:E("#000000",`${X} 18644`),underlayColor:E("#000000",`${X} 18524`),underlayPadding:E(10,`${X} 18525`),overlayColor:E("#000000",`${X} 18519`),overlayPadding:E(10,`${X} 18520`),gradientKind:E("none",`${X} 18640 (line-fill solid)`),midSourceArrowColor:E("#999999",`${X} 18639`),midTargetArrowColor:E("#999999",`${X} 18639`),labelPosition:E("center",`${X} 24942`),sourceLabelOffset:E(0,`${X} 18511, 18515`),targetLabelOffset:E(0,`${X} 18511, 18515`),width:E(3,`${X} 18711`),lineStyle:E("solid",`${X} 18638`),opacity:E(1,`${X} 18503`),sourceArrow:E("none",`${X} 18670`),targetArrow:E("none",`${X} 18671`),arrowSize:E(1,`${X} 18660`),curved:E(!1,`${X} 18658`),fanSpacing:E(20,`${X} 18647`),labelColor:E("#000000",`${X} 18474`),labelSize:E(16,`${X} 18496`),labelFont:E("Helvetica Neue, Helvetica, sans-serif",`${X} 18493`),labelWeight:E("normal",`${X} 18495`)},graph:{background:E("#ffffff",`${X} 31537 (clearCanvas: clearRect)`)},derived:[]},{tool:"graphviz",version:"graphviz main (16.1.0)",units:"px",roundedCornerRadius:jn("graphviz"),arrowhead:{length:t=>10*t,aspect:.7,shapes:{tee:{length:.2,aspect:5},square:{length:.8,aspect:1},diamond:{length:1.2,aspect:2/3},"diamond-open":{length:1.2,aspect:2/3},circle:{length:.8,aspect:1},"circle-open":{length:.8,aspect:1},crow:{length:1,aspect:.9},vee:{length:1,aspect:.9},"other:curve":{length:.5,aspect:2},"other:inv-curve":{length:.5,aspect:2}},source:"graphviz lib/common/arrows.c (ARROW_LENGTH 10, Arrowtypes lenfact, arrow_type_normal 0.35, arrow_type_crow 0.45, arrow_type_tee, arrow_type_box 0.4, arrow_type_diamond 1/3, arrow_type_dot, arrow_type_curve)"},node:{fillOpacity:E(0,`${Re}/style/ (default "", not filled)`),borderColor:E("#000000",`${Re}/color/`),borderWidth:E(1,`${Re}/penwidth/; lib/common/const.h line 77`),borderPosition:E("center",`${On}dot-synth-nodes), Graphviz strokes the node's own outline`),shape:E("ellipse",`${Re}/shape/; lib/common/const.h line 76`),width:E(54,`${Re}/width/ (0.75 inch); lib/common/const.h line 72`),height:E(36,`${Re}/height/ (0.5 inch); lib/common/const.h line 73`),labelColor:E("#000000",`${Re}/fontcolor/`),labelSize:E(14,`${Re}/fontsize/; lib/common/const.h line 61`),labelFont:E("Times, serif",`${Re}/fontname/ (Times-Roman); lib/common/const.h line 67`),labelPosition:E("center",`${Re}/labelloc/`)},edge:{color:E("#000000",`${Re}/color/`),width:E(1,`${Re}/penwidth/`),lineStyle:E("solid",`${Re}/style/`),sourceArrow:E("none",`${Re}/dir/`),targetArrow:E("none",`${Re}/dir/ (none in a graph)`),arrowSize:E(1,`${Re}/arrowsize/`),labelColor:E("#000000",`${Re}/fontcolor/`),labelSize:E(14,`${Re}/fontsize/`),labelFont:E("Times, serif",`${Re}/fontname/ (Times-Roman)`)},graph:{background:E("#ffffff",`${Re}/bgcolor/ (default unset); lib/common/emit.c emit_background (an unset bgcolor paints the page white)`)},derived:[{kind:"labelFromId",source:String.raw`${Re}/label/ (default \N, the node name)`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${Re}/dir/ (forward in a digraph); ${Re}/arrowhead/ (normal)`}]},{tool:"yed",version:"yEd / yFiles for Java 2.19",units:"px",roundedCornerRadius:jn("yed"),arrowhead:YE,node:{fill:E("#ffcc00",`${EU}; ${Gn} of y:Fill color`),shape:E("rectangle","yFiles for Java 2.19 ShapeNodeRealizer API docs"),borderColor:E("#000000",`${Gn} of y:BorderStyle`),borderWidth:E(1,`${Gn} of y:BorderStyle`),borderStyle:E("solid",`${Gn} of y:BorderStyle`),borderPosition:E("center",`${On}graphml-*, draw.io 32.4.1 standing in for yEd)`),labelColor:E("#000000",`${Gn} of y:NodeLabel`),labelFont:E("DejaVu Sans, sans-serif",`${Gn} of y:NodeLabel (Dialog's face)`),labelSize:E(12,`${Gn} of y:NodeLabel`),labelWeight:E("normal",`${Gn} of y:NodeLabel`),labelPosition:E("center",`${Gn} of y:NodeLabel`)},edge:{color:E("#000000",`${xl} (line color defaults to Color.black)`),width:E(1,`${xl} (line type defaults to LineType.LINE_1)`),lineStyle:E("solid",`${xl} (line type defaults to LineType.LINE_1)`),sourceArrow:E("none",`${xl} (defaults to Arrow.NONE)`),targetArrow:E("none",`${xl} (defaults to Arrow.NONE)`),labelColor:E("#000000",`${Gn} of y:EdgeLabel`),labelFont:E("DejaVu Sans, sans-serif",`${Gn} of y:EdgeLabel (Dialog's face)`),labelSize:E(12,`${Gn} of y:EdgeLabel`)},graph:{background:E("#ffffff",`${wU} (setColor: "By default the background color is white"); yEd manual, Preferences, Background tab`)},derived:[]},{tool:"yfiles3",version:"yFiles for HTML (API docs retrieved 2026-10-11)",units:"px",roundedCornerRadius:jn("yfiles3"),arrowhead:YE,node:{fill:E("#ffffff",`${jt} ShapeNodeStyle fill`),borderColor:E("#000000",`${jt} ShapeNodeStyle stroke`),borderWidth:E(1,`${jt} ShapeNodeStyle stroke`),borderPosition:E("center",`${On}graphml-yfiles-html-*, draw.io 32.4.1 standing in for yFiles)`),shape:E("rectangle",`${jt} ShapeNodeStyle shape`),labelColor:E("#000000",`${jt} LabelStyle textFill`),labelFont:E("Arial",`${jt} LabelStyle font`),labelSize:E(12,`${jt} LabelStyle font`),labelPosition:E("center",`${jt} IGraph.nodeDefaults labels layoutParameter (InteriorLabelModel center)`)},edge:{color:E("#000000",`${jt} PolylineEdgeStyle stroke`),width:E(1,`${jt} PolylineEdgeStyle stroke`),sourceArrow:E("none",`${jt} PolylineEdgeStyle sourceArrow`),targetArrow:E("none",`${jt} PolylineEdgeStyle targetArrow`),labelColor:E("#000000",`${jt} LabelStyle textFill`),labelFont:E("Arial",`${jt} LabelStyle font`),labelSize:E(12,`${jt} LabelStyle font`)},graph:{background:E("#ffffff",`${jt} GraphComponent (a transparent canvas over the page's white)`)},derived:[]},{tool:"gephi",version:"gephi 0.11.4-SNAPSHOT",units:"relative",roundedCornerRadius:jn("gephi"),arrowhead:{length:(t,e)=>3.25*e*t,aspect:.9,source:`${On}gexf-synth-nx-viz, widths 1 to 4), Gephi Toolkit 0.11.3`},node:{fill:E("#000000","gephi/graphstore a4c790b2343e NodeImpl.java line 322"),width:E(20,`${wn} AbstractProcessor.java lines 195-198 (size 10 is a radius)`),height:E(20,`${wn} AbstractProcessor.java lines 195-198 (size 10 is a radius)`),shape:E("ellipse","GEXF 1.3 viz shape default disc; Preview NodeRenderer"),borderPosition:E("inside",`${On}gexf-specimen-node-fills-borders-p3), Gephi Toolkit 0.11.3: the border is stroked on a circle of radius size - border / 2`),labelPosition:E("center",`${wn} NodeLabelRenderer.java (a label is drawn centered on its node)`),labelOnTop:E(!0,`${wn} PreviewController (the node label items are drawn after every node); Gephi Toolkit 0.11.3 SVG export: g#node-labels after g#nodes`)},edge:{sourceArrow:E("none",`${wn} DefaultPreset.java line 62`),targetArrow:E("none",`${wn} DefaultPreset.java line 62`),curved:E(!0,`${wn} DefaultPreset.java (EDGE_CURVED true); Gephi Toolkit 0.11.3 SVG export`),fanned:E(!1,`${wn} EdgeRenderer.java (each curved edge bows left of its own direction, siblings ignored); Gephi Toolkit 0.11.3 SVG export`),arcRadius:E(1/1.2,`${wn} EdgeRenderer.java (CurvedEdgeRenderer: an arc through both node centers of radius length / ARC_CURVENESS, default 1.2)`)},graph:{background:E("#ffffff",`${wn} VizConfig.java line 111`)},derived:[{kind:"colorFromEndNodes",source:`${wn} DefaultPreset.java (EDGE_COLOR EdgeColor.Mode.MIXED); Gephi Toolkit 0.11.3 SVG export`},{kind:"widthFromWeight",source:`${wn} VizConfig.java lines 136, 144-145; DefaultPreset.java lines 67, 73`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${wn} DefaultPreset.java line 62`}]},{tool:"vis-network",version:"vis-network 10.1.2",units:"px",roundedCornerRadius:jn("vis-network"),arrowhead:{length:(t,e)=>15*t+3*e,aspect:.6,shapes:{tee:{length:.15,aspect:1/.15},square:{length:.6,aspect:1},circle:{length:.8,aspect:1},"other:curve":{length:.4,aspect:2},"other:inv-curve":{length:.4,aspect:2}},source:`${We} EdgeBase.getArrowData, ArrowHead, Bar, Box, Circle, Curve, InvertedCurve (measured on json-vis-unix, json-vis-world, json-vis-synth)`},nodeBorderOnScreen:E(!0,`${Ml} NodeBase.initContextForDraw and performStroke: borderWidth / view.scale, at most the node's width`),node:{fill:E("#97c2fc",`${We} lines 32986-33110`),borderColor:E("#2b7ce9",`${We} lines 32986-33110`),borderWidth:E(1,`${We} lines 32986-33110`),borderPosition:E("center",`${Ml} NodeBase.performStroke: ctx.stroke() on the shape's own path`),shape:E("ellipse",`${We} lines 32986-33110`),labelColor:E("#343434",`${We} lines 32986-33110`),labelSize:E(14,`${We} lines 32986-33110`),labelFont:E("arial",`${We} lines 32986-33110`),labelPosition:E("center",`${We} lines 32986-33110`),labelMinScreenSize:E(4,`${Ml} Label.draw, nodes scaling.label.drawThreshold 5`)},edge:{width:E(1,`${We} lines 25160-25290`),outlineColor:E("#6f6f6f",`${We} lines 25160-25290 (background.color)`),lineStyle:E("solid",`${We} lines 25160-25290 (dashes false)`),sourceArrow:E("none",`${We} lines 25160-25290`),targetArrow:E("none",`${We} lines 25160-25290`),labelColor:E("#343434",`${We} lines 25160-25290`),labelSize:E(14,`${We} lines 25160-25290`),labelFont:E("arial",`${We} lines 25160-25290`),labelMinScreenSize:E(4,`${Ml} Label.draw, edges scaling.label.drawThreshold 5`),labelPosition:E("center",`${Ml} Edge.drawLabel (the label at the line's middle point)`),labelOutlineColor:E("#ffffff",`${We} lines 25160-25290 (font.strokeColor)`),labelOutlineWidth:E(2,`${We} lines 25160-25290 (font.strokeWidth)`)},graph:{background:E("#ffffff","vis-network 9.1.9 vis-network.esm.js line 32378 (clearRect: the page's white shows through)")},derived:[{kind:"labelFromColumn",column:"label",source:`${We} lines 32986-33110`},{kind:"colorFromSourceNode",source:`${We} lines 25160-25290 (color.inherit "from")`}]},{tool:"sigma",version:"sigma 4.0.1",units:"relative",roundedCornerRadius:jn("sigma"),node:{fill:E("#666666",`${si} DEFAULT_NODE_DISPLAY_DATA (color "#666")`),shape:E("ellipse",`${kr}/settings.ts lines 119-126`),width:E(20,`${si} DEFAULT_NODE_DISPLAY_DATA (size 10 is a radius)`),height:E(20,`${si} DEFAULT_NODE_DISPLAY_DATA (size 10 is a radius)`),labelColor:E("#000000",`${kr}/settings.ts lines 119-126`),labelFont:E("Arial",`${kr}/settings.ts lines 119-126`),labelSize:E(12,`${si} DEFAULT_NODE_DISPLAY_DATA (labelSize 12)`),labelWeight:E("normal",`${kr}/settings.ts lines 119-126`),labelPosition:E("right",`${si} DEFAULT_NODE_DISPLAY_DATA (labelPosition "right")`),labelGridCellSize:E(100,`${si} LabelGrid.getLabelsToDisplay (labelDensity 1, labelGridCellSize 100)`),labelOnTop:E(!0,`${si} labels are drawn by their own program after every node and edge`),labelMinNodeScreenSize:E(12,`${si} renderLabels (labelRenderedSizeThreshold 6, a radius)`)},edge:{color:E("#cccccc",`${kr}/settings.ts lines 119-126`),width:E(.5,`${si} DEFAULT_EDGE_DISPLAY_DATA (size 1)`),labelColor:E("#666666",`${si} DEFAULT_EDGE_DISPLAY_DATA (labelColor "#666")`),labelSize:E(12,"sigma 4.0.1 dist/sigma.esm.js line 2816 (DEFAULT_EDGE_LABEL_SIZE)"),labelPosition:E("center","sigma 4.0.1 dist/sigma.esm.js line 3647 (the middle of its two ends)"),sourceArrow:E("none",`${kr}/settings.ts lines 119-126 (type line)`),targetArrow:E("none",`${kr}/settings.ts lines 119-126 (type line)`),minScreenWidth:E(.85,`${si} edge program (pixelsThickness = max(size, minEdgeThickness 1.7))`)},graph:{background:E("#ffffff","sigma 4.0.1 dist/sigma.esm.js line 5202 (gl.clear to transparent: the page's white shows through)")},derived:[{kind:"labelFromColumn",column:"label",source:`${kr}/settings.ts lines 119-126`}]},{tool:"pajek",version:"Pajek 6.02",units:"px",roundedCornerRadius:jn("pajek"),arrowhead:{length:t=>6*t,aspect:5/6,source:`${Nt}specimen-arrows: s 0.5, 1, 2, 3 and 5 draw arrowheads 3, 6, 12, 18 and 30 long, 2.5, 5, 10, 15 and 25 wide; football: s 4 and 9)`},node:{shape:E("ellipse",`${Ji} p. 85`),opacity:E(1,`${Ji} p. 87`),borderColor:E("#660000",`${Nt}football, kdorola: every vertex without bc)`),borderWidth:E(.5,`${Nt}football, kdorola: every vertex without bw)`),borderPosition:E("center",`${Nt}specimen-node-fills-borders-p3: bw 8 draws a vertex of size 36 44 across)`),width:E(20,`${Nt}football, iliad: a vertex without s_size, x_fact or y_fact)`),height:E(20,`${Nt}football, iliad: a vertex without s_size, x_fact or y_fact)`),fill:E("#ffd9bc",`${Nt}football, kdorola: every vertex without ic)`),labelColor:E("#ad0000",`${Nt}football, 1crn: every label without lc)`),labelSize:E(15,`${Nt}football, 1crn: every label without fos)`),labelFont:E("Arial",`${Nt}football, 1crn: every label without font)`),labelWeight:E("bold",`${Nt}football, 1crn: every label is bold)`),labelPosition:E("center",`${Nt}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelOffsetX:E(5.176380902,`${Nt}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelOffsetY:E(14.121016526,`${Nt}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelShiftX:E(.5,`${Nt}football, 1crn, specimen-labels: text-anchor start)`)},edge:{width:E(2,`${Nt}1crn, lin-rel4, synth-vertices: edges without w; c: w 0.5 drawn 1)`),color:E("#007091",`${Nt}1crn, lin-rel4, c: edges without c)`),lineStyle:E("solid",`${Ji} p. 90`),opacity:E(1,`${Ji} p. 87`),sourceArrow:E("none",`${Ji} p. 91`),targetArrow:E("none",`${Ji} p. 91 (edges have none)`)},graph:{background:E("#ffffff",`${Ji}, Draw window (assumed: a white background)`)},derived:[{kind:"labelFromColumn",column:"label",source:`${Ji}, vertex labels (drawn by default)`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${Ji} p. 91 (arcs)`}]},{tool:"ogdf",version:"ogdf master 1a40505ac006",units:"px",roundedCornerRadius:jn("ogdf"),arrowhead:{length:(t,e)=>3*e*t,aspect:.5,source:`${On}gml-specimen-arrows-p5.svg: lineWidth 1, 1.5 and 3 draw arrowheads 3, 4.5 and 9 long, 1.5, 2.25 and 4.5 wide)`},node:{fill:E("#ffffff",`${Ii} LayoutStandards.cpp lines 38-45`),shape:E("rectangle",`${Ii} LayoutStandards.cpp lines 38-45`),width:E(20,`${Ii} LayoutStandards.cpp lines 38-45`),height:E(20,`${Ii} LayoutStandards.cpp lines 38-45`),borderColor:E("#000000",`${Ii} LayoutStandards.cpp lines 38-45`),borderWidth:E(1,`${Ii} LayoutStandards.cpp lines 38-45`),borderStyle:E("solid",`${Ii} LayoutStandards.cpp lines 38-45`),labelColor:E("#000000",`${Zi}fill #000000)`),labelFont:E("Arial",`${Zi}font-family Arial)`),labelSize:E(10,`${Zi}font-size 10)`),labelPosition:E("center",`${Zi}text-anchor middle at the node's center)`)},edge:{color:E("#000000",`${Ii} LayoutStandards.cpp lines 38-45`),width:E(1,`${Ii} LayoutStandards.cpp lines 38-45`),lineStyle:E("solid",`${Ii} LayoutStandards.cpp lines 38-45`),labelColor:E("#000000",`${Zi}fill #000000)`),labelFont:E("Arial",`${Zi}font-family Arial)`),labelSize:E(10,`${Zi}font-size 10)`),labelPosition:E("center",`${Zi}text-anchor middle on the line, dominant-baseline middle)`)},graph:{background:E("#ffffff",`${Zi}no background: the page's white shows through)`)},derived:[]},{tool:"networkx",version:"networkx 3.7 (main 6da4704cbf32)",units:"px",roundedCornerRadius:jn("networkx"),node:{fill:E("#1f78b4",`${Be} 1378`),fillOpacity:E(1,`${Be} 549`),shape:E("ellipse",`${Be} 1379 (node_shape "o")`),width:E(17.3205,`${Be} 1377 (node_size 300, points squared)`),height:E(17.3205,`${Be} 1377 (node_size 300, points squared)`),labelColor:E("#000000",`${Be} 2143`),labelSize:E(12,`${Be} 2142`),labelFont:E("sans-serif",`${Be} 2144`),labelWeight:E("normal",`${Be} 2145`),labelPosition:E("center",`${Be} 2148-2149`)},edge:{color:E("#000000",`${Be} 1768 (edge_color "k")`),width:E(1,`${Be} 1767`),lineStyle:E("solid",`${Be} 1769`),opacity:E(1,`${Be} 568`),sourceArrow:E("none",`${Be} 1848-1849`),targetArrow:E("none",`${Be} 1849 (undirected graphs draw "-")`),labelColor:E("#000000",`${Be} 557`),labelSize:E(12,`${Be} 556`),labelFont:E("sans-serif",`${Be} 558`),labelWeight:E("normal",`${Be} 559`)},graph:{},derived:[{kind:"targetArrowOnDirected",arrow:"triangle",source:`${Be} 1848 (arrowstyle "-|>" for directed graphs)`}]}].map(t=>[t.tool,t]));function vr(t){return _U.get(t)??null}const SU=new Set(["string","dict","bool","i32","u32","u8","f32","f64"]),OU=/^(?:x|y|z|_pos)$/i,L1="graphty.parent",NU=8;function AU(t){const e=Gt(t);if(!e.expanded)return!1;for(let n=0;n<t.edgeCount;n++)if(e.folded(n))return!0;return!1}function Jr(t,e){const n=e==="node"?t.nodes:t.edges,i=e==="node"?t.nodeCount:t.edgeCount,r=[];for(const s of n.names().filter(o=>TU(n,o))){const o=Array.from({length:i},(l,a)=>{const c=yf(n,s,a);return typeof c=="string"||typeof c=="number"||typeof c=="boolean"?c:null});if(s!==L1)r.push({ref:{data:s},values:o});else if(e==="node"){const l=o.map(a=>typeof a=="number"&&a>=0&&a<t.nodeCount?String(t.ids.idOf(a)):null);r.push({ref:{style:"group"},values:l})}}if(e==="node"&&i>0&&!AU(t)){const s=t.directed?["degree","indegree","outdegree"]:["degree"];for(const o of s)r.push({ref:{computed:o},values:sc(t,o)})}return r}function TU(t,e){if(e.startsWith("graphty.")&&e!==L1||e==="selected"||OU.test(e))return!1;const n=t.get(e);return n!==null&&n.meta.role!=="position"&&SU.has(n.meta.dtype)&&n.meta.components===1}function ro(t){let e=0,n=0;for(let r=0;r<t.nodeCount;r++){const s=String(t.ids.idOf(r));let o=2166136261,l=1523705862;for(let a=0;a<s.length;a++){const c=s.charCodeAt(a);o=Math.imul(o^c,16777619),l=Math.imul(l^c,16777619)^l>>>13}e=e+(o>>>0)>>>0,n=n+(l>>>0)>>>0}const i=r=>(r>>>0).toString(16).padStart(8,"0");return{nodes:t.nodeCount,edges:t.edgeCount,heldEdges:Hy(t).length,ids:i(e)+i(n)}}function Hy(t){const e=t.edges.byRole("pair"),n=[];for(let i=0;i<t.edgeCount;i++)e?.isSet(i)===!0&&e.value(i)<i||n.push(i);return n}function IU(t){const e=new Set;let n=!0,i=!0,r=!0,s=1/0,o=-1/0,l=0;for(const a of t)a!==null&&(l++,e.add(`${typeof a}:${String(a)}`),typeof a!="number"?(i=!1,r=!1):Number.isFinite(a)?(r&&=Number.isInteger(a),n&&=Number.isInteger(a),s=Math.min(s,a),o=Math.max(o,a)):(i=!1,n=!1));return{seen:e,categorical:n,numeric:i,integers:r,lo:s,hi:o,count:l}}function $U(t){return"style"in t?t.style:"computed"in t?t.computed:t.data}function CU(t,e){const{seen:n,categorical:i,numeric:r,integers:s,lo:o,hi:l,count:a}=IU(t.values),d=!("computed"in t.ref)&&r&&s&&a>=NU&&n.size===a&&l-o+1===a;return{feature:t,name:$U(t.ref),distinct:n.size,categorical:a>0&&i,numeric:a>0&&r&&!d,raw:e}}const Z="graphty.styles",du=16*1024*1024,vU=64,Ls=4096,P1=256,x1=new Set(["__proto__","constructor","prototype"]),Vy=["node","edge"],DU=new Set(["degree","indegree","outdegree"]);function wf(t,e){return`graphty.style.${t}.${e}`}const kU={"\\":String.raw`\u005c`,n:String.raw`\u000a`,t:String.raw`\u0009`};function Nl(t,e={}){const{styles:n,columns:i,fingerprint:r}=t,s={version:1,source:n.source,units:n.units,graph:n.graph,rules:n.rules,columns:{node:Array.from(i.node.keys()),edge:Array.from(i.edge.keys())}},o=c=>Array.from(c).filter(([,d])=>d.some(u=>u!==null)&&d.every(u=>u===null||typeof u=="boolean")).map(([d])=>d),l={node:o(i.node),edge:o(i.edge)};if((l.node.length>0||l.edge.length>0)&&(s.booleans=l),e.inlineColumns===!0){if(e.snapshot!==void 0){const{ids:d,nodeCount:u}=e.snapshot;s.order=Array.from({length:u},(f,h)=>String(d.idOf(h)))}const c=e.snapshot===void 0?null:Hy(e.snapshot);s.values={node:Object.fromEntries(i.node),edge:Object.fromEntries(Array.from(i.edge,([d,u])=>[d,c===null?u:c.map(f=>u[f]??null)]))}}const{snapshot:a}=e;if(a!==void 0){const c=d=>{const u=d==="node"?a.nodes:a.edges,f=d==="node"?a.nodeCount:a.edgeCount,h=jU(n.rules.filter(p=>p.target===d)).filter(p=>u.has(p)&&!x1.has(p)&&p.length<=P1).slice(0,Ls);return Object.fromEntries(h.map(p=>[p,og(u,p,f)]))};s.data={node:c("node"),edge:c("edge")}}return s.fingerprint={nodes:r.nodes,edges:r.heldEdges??r.edges,ids:r.ids},JSON.stringify(s).replaceAll(/\\(.)/g,(c,d)=>kU[d]??c)}function lc(t,e,n="all"){let i=null;if(t.length>du)i="TOO_LARGE";else if(n==="all"){const r=JSON.parse(t),{nodes:s,edges:o,ids:l}=r.fingerprint,a=ac(t,{nodes:s,edges:o,ids:l});i=a.ok?null:a.reason}return i===null?[]:[Object.freeze({code:v.RULES_NOT_KEPT,message:`the ${Z} block would not read back (${i}): the styles are written as the format's own, and importing the file infers the rules again`,column:null,count:e})]}class M1 extends Error{}function oe(){throw new M1}function ac(t,e){if(typeof t!="string")return{ok:!1,reason:"INVALID"};if(t.length>du)return{ok:!1,reason:"TOO_LARGE"};let n;try{n=JSON.parse(t)}catch{return{ok:!1,reason:"NOT_JSON"}}if(!RU(n))return{ok:!1,reason:"INVALID"};const i=je(n)?n:null;if(i===null)return{ok:!1,reason:"INVALID"};if(i.version!==1)return{ok:!1,reason:"VERSION"};const r=je(i.fingerprint)?i.fingerprint:null;if(r!==null&&(r.nodes!==e.nodes||r.edges!==(e.heldEdges??e.edges)||r.ids!==e.ids))return{ok:!1,reason:"FINGERPRINT"};let s;try{s=LU(i)}catch(l){if(l instanceof M1)return{ok:!1,reason:"INVALID"};throw l}const o=s.fingerprint;return o.nodes!==e.nodes||o.edges!==(e.heldEdges??e.edges)||o.ids!==e.ids?{ok:!1,reason:"FINGERPRINT"}:{ok:!0,block:s}}function RU(t){const e=[[t,0]];for(;e.length>0;){const[n,i]=e.pop();if(n===null||typeof n!="object")continue;if(i>=vU||!Array.isArray(n)&&Object.keys(n).some(s=>x1.has(s)))return!1;const r=Array.isArray(n)?n:Object.values(n);for(const s of r)s!==null&&typeof s=="object"&&e.push([s,i+1])}return!0}function je(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function bt(t){return typeof t=="string"&&t.length<=P1?t:oe()}function KE(t){return t==null?null:bt(t)}function U1(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function mi(t){return U1(t)?t:oe()}function Dt(t,e){return Array.isArray(t)&&t.length<=e?t:oe()}function LU(t){const e=je(t.source)?t.source:oe(),n=je(t.units)?t.units:oe(),i=n.length==="px"||n.length==="relative"?n.length:oe(),r=je(t.fingerprint)?t.fingerprint:oe(),s=f=>typeof f=="number"&&Number.isSafeInteger(f)&&f>=0?f:oe(),o=je(t.columns)?t.columns:oe(),l={version:1,source:{format:bt(e.format),dialect:KE(e.dialect),tool:KE(e.tool)},units:{length:i},graph:G1(t.graph??{}),rules:Dt(t.rules,Ls).map(zU),columns:{node:Dt(o.node,Ls).map(bt),edge:Dt(o.edge,Ls).map(bt)},fingerprint:{nodes:s(r.nodes),edges:s(r.edges),ids:bt(r.ids)}},a=t.data===void 0?l:{...l,data:UU(t.data)},c=t.booleans===void 0?a:{...a,booleans:PU(t.booleans)};if(t.values===void 0)return c;const d=t.order===void 0?void 0:xU(t.order,l.fingerprint.nodes),u=MU(t.values,l);return{...c,...d===void 0?{}:{order:d},values:u}}function PU(t){const e=je(t)?t:oe();return{node:Dt(e.node??[],Ls).map(bt),edge:Dt(e.edge??[],Ls).map(bt)}}function xU(t,e){const n=Dt(t,e).map(i=>typeof i=="string"?i:oe());return n.length===e?n:oe()}function MU(t,e){const n=je(t)?t:oe(),i={node:new Map,edge:new Map};for(const r of Vy){const s=r==="node"?e.fingerprint.nodes:e.fingerprint.edges,o=je(n[r])?n[r]:oe();for(const l of e.columns[r]){const a=Dt(Object.hasOwn(o,l)?o[l]:oe(),s);a.length!==s&&oe(),i[r].set(l,a.map(c=>c===null?null:mi(c)))}}return i}function UU(t){const e=je(t)?t:oe(),n=i=>{const r=je(i)?i:oe(),s=Object.keys(r);return s.length>Ls&&oe(),new Map(s.map(o=>[bt(o),bt(r[o])]))};return{node:n(e.node),edge:n(e.edge)}}function GU(t){return t===null?"":typeof t=="string"||typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t)}function og(t,e,n){let i=2166136261,r=1523705862;for(let o=0;o<n;o++){const l=`${GU(K(t.value(e,o)))}\0`;for(let a=0;a<l.length;a++){const c=l.charCodeAt(a);i=Math.imul(i^c,16777619),r=Math.imul(r^c,16777619)^r>>>13}}const s=o=>(o>>>0).toString(16).padStart(8,"0");return s(i)+s(r)}function jU(t){const e=new Set;for(const{ext:n,...i}of t)JSON.stringify(i,(r,s)=>(je(s)&&typeof s.data=="string"&&Object.keys(s).length===1&&e.add(s.data),s));return[...e]}function FU(t,e){const{ext:n,...i}=t,r=JSON.parse(JSON.stringify(i,(s,o)=>je(o)&&typeof o.data=="string"&&Object.keys(o).length===1&&e.has(o.data)?{data:e.get(o.data)}:o));return n===void 0?r:{...r,ext:n}}function XE(t,e,n){const i=new Map,r=t.data?.[n];if(r===void 0||r.size===0)return i;const s=n==="node"?e.nodes:e.edges,o=n==="node"?e.nodeCount:e.edgeCount;let l=null;for(const[a,c]of r)if(!(s.has(a)&&og(s,a,o)===c)){l??=new Map(Array.from(s.names(),d=>[d,og(s,d,o)]));for(const[d,u]of l)if(u===c){i.set(a,d);break}}return i}function G1(t){const e=je(t)?t:oe(),n=Object.create(null);for(const i of Object.keys(e))n[bt(i)]=mi(e[i]);return n}function zU(t){const e=je(t)?t:oe(),n=e.target==="node"||e.target==="edge"?e.target:oe(),i={id:bt(e.id),target:n,role:bt(e.role),origin:bt(e.origin),where:wd(e.where)};if(e.set!==void 0&&(i.set=G1(e.set)),e.map!==void 0){const r=je(e.map)?e.map:oe(),s=Object.create(null);for(const o of Object.keys(r))s[bt(o)]=BU(r[o]);i.map=s}return e.facts!==void 0&&(i.facts=HU(e.facts)),e.ext!==void 0&&(i.ext=je(e.ext)?e.ext:oe()),i}function Ed(t){const e=je(t)?t:oe();return typeof e.data=="string"?{data:bt(e.data)}:typeof e.style=="string"?{style:bt(e.style)}:typeof e.computed=="string"&&DU.has(e.computed)?{computed:e.computed}:oe()}function wd(t){const e=je(t)?t:oe();if("all"in e)return e.all===!0?{all:!0}:oe();if("has"in e)return{has:Ed(e.has)};if("eq"in e){const n=Dt(e.eq,2);return n.length===2?{eq:[Ed(n[0]),mi(n[1])]}:oe()}if("in"in e){const n=Dt(e.in,2);return n.length===2?{in:[Ed(n[0]),Dt(n[1],65536).map(mi)]}:oe()}return"and"in e?{and:Dt(e.and,64).map(wd)}:"or"in e?{or:Dt(e.or,64).map(wd)}:"not"in e?{not:wd(e.not)}:e}function WU(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:oe()}function BU(t){const e=je(t)?t:oe(),n=Ed(e.by);switch(e.kind){case"passthrough":return{kind:"passthrough",by:n};case"discrete":return{kind:"discrete",by:n,table:Dt(e.table,1<<20).map(i=>{const r=Dt(i,2);return r.length===2?[mi(r[0]),mi(r[1])]:oe()})};case"continuous":return{kind:"continuous",by:n,points:Dt(e.points,4096).map(i=>{const r=je(i)?i:oe();return{at:typeof r.at=="number"&&Number.isFinite(r.at)?r.at:oe(),below:mi(r.below),value:mi(r.value),above:mi(r.above)}}),...e.step===void 0?{}:{step:WU(e.step)}};default:return{...e,kind:bt(e.kind),by:n}}}function HU(t){const e=je(t)?t:oe(),n=l=>typeof l=="number"&&Number.isSafeInteger(l)&&l>=0?l:void 0,i={},r=n(e.elements),s=n(e.classes),o=n(e.distinctValues);return r!==void 0&&(i.elements=r),s!==void 0&&(i.classes=s),o!==void 0&&(i.distinctValues=o),typeof e.reason=="string"&&(i.reason=bt(e.reason)),e.names!==void 0&&(i.names=Dt(e.names,1<<20).map(l=>{const a=Dt(l,2);return a.length===2?[mi(a[0]),String(mi(a[1]))]:oe()})),i}function qE(t,e,n){const i=new Map,r=n==="node"?e.nodes:e.edges,s=n==="node"?e.nodeCount:e.edgeCount;for(const o of t.columns[n]){const l=t.values?.[n].get(o);if(l!==void 0){i.set(o,n==="node"?KU(t,e,l):XU(e,l));continue}const a=wf(n,o);if(!r.has(a))return null;const c=Array.from({length:s},(d,u)=>{const f=K(r.value(a,u));return U1(f)?f:null});i.set(o,n==="edge"?j1(e,c):c)}return i}function VU(t,e){for(const n of Vy)for(const i of t.booleans?.[n]??[]){const r=e[n].get(i);r!==void 0&&e[n].set(i,r.map(YU))}}function YU(t){return t===1||t==="1"||t==="true"?!0:t===0||t==="0"||t==="false"?!1:t}function KU(t,e,n){const{order:i}=t;if(i===void 0||i.every((s,o)=>s===String(e.ids.idOf(o))))return n;const r=new Map;return i.forEach((s,o)=>{r.has(s)||r.set(s,o)}),Array.from({length:e.nodeCount},(s,o)=>n[r.get(String(e.ids.idOf(o)))??-1]??null)}function XU(t,e){const n=Hy(t);if(n.length===t.edgeCount)return e;const i=new Array(t.edgeCount).fill(null);return n.forEach((r,s)=>{i[r]=e[s]??null}),j1(t,i)}function j1(t,e){const n=t.edges.byRole("pair");if(n===null)return e;for(let i=0;i<e.length;i++)e[i]===null&&n.isSet(i)&&(e[i]=e[n.value(i)]??null);return e}const qU={node:["fill","fillOpacity"],edge:["color","opacity"]};function JU(t,e,n,i,r){const[s,o]=qU[e],l=t[s];if(l===void 0)return t;const a=t[o],c=Ni(n,e,o,i);let d=null;for(let u=0;u<r;u++){const f=c[u];(l[u]??null)!==null&&(a?.[u]??null)===null&&f!==null&&f!==1&&(d??=a===void 0?new Array(r).fill(null):[...a],d[u]=1)}return d===null?t:{...t,[o]:d}}function F1(t,e){let n=e,i=2;for(;t(n);)n=`${e}#${String(i)}`,i++;return n}function ZU(t,e){return ii[t].get(e)==="text"}function QU(t,e,n,i){const r=i?"":void 0;let s=null;for(let o=0;o<e.length;o++){const l=t[o]??null,a=e[o]===null&&(l===n||l===r);l!==null&&!Wy(l,e[o])&&!a&&(s??=new Array(e.length).fill(null),s[o]=l)}return s}function e5(t,e,n,i,r,s){const o=Object.create(null);for(const[l,a]of Object.entries(t).sort(([c],[d])=>c<d?-1:1)){if(a===void 0)continue;const c=Ni(e,n,l,i),d=QU(a,c,s(l),ZU(n,l));if(d!==null){const u=F1(f=>r.has(f),`exceptions.${l}`);r.set(u,d),o[l]={kind:"passthrough",by:{style:u}}}}return o}function z1(t,e,n,i={},r=[],s=null,o=!1){const l=qE(t,e,"node"),a=qE(t,e,"edge");if(l===null||a===null)return null;const c={node:l,edge:a};VU(t,c);const d={node:Jr(e,"node"),edge:Jr(e,"edge")},u={node:XE(t,e,"node"),edge:XE(t,e,"edge")},f=t.rules.map(p=>u[p.target].size===0?p:FU(p,u[p.target])),h=[...f];for(const p of Vy){const g=p==="node"?e.nodeCount:e.edgeCount,m=Cr(p,g,c[p],d[p],e),y=o?JU(i[p]??{},p,f,m,g):i[p],b=S=>(s===null?null:vr(s))?.[p]?.[S]?.value,_=e5(y??{},f,p,m,c[p],b);if(Object.keys(_).length>0){const S=F1(T=>h.some($=>$.id===T),`${p}.exceptions`);h.push({id:S,target:p,role:"exceptions",origin:"inferred",where:{all:!0},map:_})}}return{styles:{version:1,source:{format:n,dialect:"graphty",tool:"graphty"},units:t.units,graph:t.graph,rules:h,notes:r},columns:c,features:d,fingerprint:ro(e)}}const zt=(t,e)=>ve(t,"cytoscape",e)?.color??null,Oo=(t,e)=>{const n=Y(t,e);return n===null?null:n>255?(H(e,v.BAD_VALUE,String(t)),null):P(Math.round(n)/255)},No=(t,e)=>ic(t,"css",e),er=(t,e)=>Y(t,e),lg=(t,e)=>{const n=Y(t,e);return n===null?null:P(n/6)},JE=(t,e)=>{const n=typeof t=="number"?t:Number(ut(t,e)?.trim()??Number.NaN);return Number.isFinite(n)?P((n%360+360)%360):(H(e,v.BAD_VALUE,String(t)),null)},ZE=(t,e)=>{const n=Y(t,e);return n===null?null:Math.round(n)},Dc=(t,e)=>rt(t,e),vh=(t,e)=>rc(t,e),QE=(t,e)=>{if(typeof t=="string"){const n=t.trim().toLowerCase();if(n==="element"||n==="visible")return!0;if(n==="none"||n==="hidden")return!1}return rc(t,e)},t5=new Map([["rounded_rectangle","round-rectangle"]]),W1=t=>typeof t=="string"&&t.startsWith("other:")?`other:${t.slice(6).toLowerCase().replaceAll("_","-")}`:t,n5=(t,e)=>{const n=ut(t,e);return n===null?null:W1(t5.get(n.trim().toLowerCase())??le("shape",n,"cytoscape",e))},Yy=new Map([["none","none"],["delta","triangle"],["arrow","triangle"],["diamond","diamond"],["circle","circle"],["t","tee"],["half_top","half"],["half_bottom","other:half-bottom"],["square","square"],["delta_short_1","triangle"],["delta_short_2","triangle"],["arrow_short","triangle"],["diamond_short_1","diamond"],["diamond_short_2","diamond"],["open_delta","triangle-open"],["open_circle","circle-open"],["open_diamond","diamond-open"],["open_square","other:open-square"],["cross_delta","other:cross-delta"],["cross_open_delta","other:cross-open-delta"],["open_half_circle","other:open-half-circle"],["half_circle","other:half-circle"],["triangle","triangle"],["triangle-tee","tee"],["triangle-cross","other:cross-delta"],["triangle-backcurve","triangle"],["tee","tee"],["vee","vee"],["open-circle","circle-open"],["open-triangle","triangle-open"],["open-diamond","diamond-open"],["open-square","other:open-square"],["open-delta","triangle-open"],["half-top","half"],["half-bottom","other:half-bottom"]]),i5=new Map([["delta_short_1",{length:.5,width:1}],["delta_short_2",{length:.25,width:1}],["arrow_short",{length:.6,width:.8}],["diamond_short_1",{length:.5,width:1}],["diamond_short_2",{length:.25,width:1}],["cross_delta",{length:1.5,width:1.5}],["cross_open_delta",{length:1.5,width:1.5}],["triangle-cross",{length:1.5,width:1.5}]]),r5=new Map([["t",4],["tee",4],["half_circle",1],["open_half_circle",1],["half_top",.3/1.135],["half_bottom",.3/1.135],["half-top",.3/1.135],["half-bottom",.3/1.135],["square",.25],["open_square",.25],["open-square",.25]]),s5=["none","delta","delta","delta","arrow","arrow","arrow","diamond","diamond","diamond","circle","circle","circle","t","t","t","half_top","half_bottom"];function Ky(t){const e=t.trim().toLowerCase();return/^\d{1,2}$/.test(e)?s5.at(Number(e))??e:e}const ew=(t,e)=>{const n=ut(t,e);return n===null?null:W1(Yy.get(Ky(n))??le("arrow",n,"cytoscape",e))};function o5(t){return(e,n)=>{const i=ut(e,n);if(i===null)return null;const r=Ky(i);return i5.get(r)?.[t]??(Yy.has(r)?1:null)}}const l5=(t,e)=>{const n=ut(t,e);if(n===null)return null;const i=Ky(n);return r5.get(i)??(Yy.has(i)?0:null)},a5=new Map([["solid","solid"],["dot","dotted"],["dots","dotted"],["equal_dash","dashed"],["long_dash","dashed"],["dash_dot","dash-dot"],["sinewave","sinewave"],["zigzag","zigzag"],["parallel_lines","double"],["marquee_dash","dashed"],["marquee_equal","dashed"],["marquee_dash_dot","dash-dot"],["backward_slash","other:backward-slash"],["forward_slash","other:forward-slash"],["vertical_slash","other:vertical-slash"],["separate_arrow","other:separate-arrow"],["contiguous_arrow","other:contiguous-arrow"],["double","double"]]);function Ul(t){return(e,n)=>{const i=ut(e,n);if(i===null)return null;const r=i.trim().toLowerCase();let s;return/^line_\d{1,3}$/.test(r)?s="solid":/^dashed_\d{1,3}$/.test(r)?s="dashed":s=a5.get(r)??le(t,i,"cytoscape",n),s===null||Jo("node",t,s)||t==="lineStyle"||s.startsWith("other:")?s:`other:${s}`}}function c5(t){const e=/\.(bold|italic|plain|bolditalic)$/i.exec(t),n=e?.[1].toLowerCase()??"";return{family:e===null?t:t.slice(0,e.index),weight:n.includes("bold")?"bold":"normal",italic:n.includes("italic")}}function uu(t,e,n){const i=c5(t.trim());return{family:i.family,weight:e||i.weight==="bold"?"bold":"normal",italic:n||i.italic}}function Xy(t,e){if(t!==null&&typeof t=="object"&&!Array.isArray(t))return d5(t,e);const n=ut(t,e);if(n===null)return null;const i=n.split(",");return i.length>=2?uu(i[0],!1,!1):u5(n)??uu(n,!1,!1)}function d5(t,e){const n=Object.hasOwn(t,"FONT_NAME")?ut(t.FONT_NAME,e):null;let i=Object.hasOwn(t,"FONT_FAMILY")?ut(t.FONT_FAMILY,e):null;if(n!==null&&n.trim()!==""&&(i=n),i===null)return null;const r=Object.hasOwn(t,"FONT_WEIGHT")?String(t.FONT_WEIGHT):"",s=Object.hasOwn(t,"FONT_STYLE")?String(t.FONT_STYLE):"";return uu(i,/bold/i.test(r.slice(0,32)),/italic/i.test(s.slice(0,32)))}function u5(t){const e=t.split("-"),n=o=>/^\d+(?:\.\d+)?$/.test(o??"");if(e.length<3||!n(e.at(-1))||!n(e.at(-2)))return null;const i=Math.trunc(Number(e.at(-2)));let r=e.slice(0,-2).join("-"),s=(i&1)!==0;return/-bold$/i.test(r)&&(r=r.slice(0,-5),s=!0),uu(r,s,(i&2)!==0)}const Ts="DejaVu Sans, sans-serif",qy="DejaVu Serif, serif",Xl="DejaVu Sans Mono, monospace",f5=new Map([["sans-serif",Ts],["monospace",Xl],["sansserif",Ts],["dialog",Ts],["default",Ts],["dialoginput",Xl],["monospaced",Xl],["serif",qy]]),tw=(t,e)=>{const n=Xy(t,e)?.family??null;return n===null?null:_f(n)},h5=new Set(["sans-serif","serif","monospace","cursive","fantasy","system-ui"]);function _f(t){const e=f5.get(t.toLowerCase());return e!==void 0?e:t.includes(",")||h5.has(t.toLowerCase())?t:`${t}, ${Ts}`}const nw=(t,e)=>Xy(t,e)?.weight??null,iw=(t,e)=>Xy(t,e)?.italic??null,ag=new Map([["C",[0,0]],["N",[0,-1]],["S",[0,1]],["E",[1,0]],["W",[-1,0]],["NE",[1,-1]],["NW",[-1,-1]],["SE",[1,1]],["SW",[-1,1]],["NONE",[0,0]]]),p5=new Map([["center",0],["left",-1],["right",1],["top",-1],["bottom",1]]),rw=new Map([["l","left"],["left","left"],["c","center"],["center","center"],["r","right"],["right","right"]]);function g5(t,e){const n=i=>ag.get((ut(Object.hasOwn(t,i)?t[i]:"C",e)??"").trim().toUpperCase());return[...n("EDGE_ANCHOR")??[void 0,void 0],...n("LABEL_ANCHOR")??[void 0,void 0]]}function B1(t,e){if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const l=t,a=g=>((Object.hasOwn(l,g)?ut(l[g],e):null)??"center").trim().toLowerCase(),c=g=>{const m=Object.hasOwn(l,g)?Number(l[g]):0;return Number.isFinite(m)?m:0},d=Object.hasOwn(l,"EDGE_ANCHOR")?g5(l,e):["HORIZONTAL_ANCHOR","VERTICAL_ANCHOR","HORIZONTAL_ALIGN","VERTICAL_ALIGN"].map(g=>p5.get(a(g)));if(d.includes(void 0))return H(e,v.UNKNOWN_VALUE,JSON.stringify(t).slice(0,64)),null;const[u,f,h,p]=d;return{node:[u,f],label:[h,p],justify:rw.get(a("JUSTIFICATION"))??"center",offset:[c("MARGIN_X"),c("MARGIN_Y")]}}const n=ut(t,e);if(n===null)return null;const i=n.split(",").map(l=>l.trim()),r=ag.get(i[0].toUpperCase()),s=i.length>1?ag.get(i[1].toUpperCase()):r?.map(l=>-l);if(r===void 0||s===void 0)return H(e,v.UNKNOWN_VALUE,n),null;const o=l=>{const a=Number(i[l]??0);return Number.isFinite(a)?a:0};return{node:r,label:[s[0],s[1]],justify:rw.get((i[2]??"c").toLowerCase())??"center",offset:[o(3),o(4)]}}const m5=new Map([["0,0","center"],["0,-1","inside-top"],["0,1","inside-bottom"],["-1,0","inside-left"],["1,0","inside-right"],["-1,-1","inside-top-left"],["1,-1","inside-top-right"],["-1,1","inside-bottom-left"],["1,1","inside-bottom-right"]]);function Jy(t){return t.node[0]===t.label[0]&&t.node[1]===t.label[1]?m5.get(`${t.node[0]},${t.node[1]}`)??"center":"center"}function y5(t,e,n){return Jy(t)!=="center"||t.node[0]===0&&t.node[1]===0&&t.label[0]===0&&t.label[1]===0?{offset:t.offset,shift:[0,0]}:{offset:[t.node[0]*e/2+t.offset[0],t.node[1]*n/2+t.offset[1]],shift:[fu(t.label[0]),fu(t.label[1])]}}function fu(t){return t===0?0:-t/2}const b5=(t,e)=>{const n=B1(t,e);return n===null?null:Jy(n)},Zy=Object.freeze({node:new Map([["fill",[["NODE_FILL_COLOR",zt],["NODE_BACKGROUND_COLOR",zt],["NODE_PAINT",zt]]],["fillOpacity",[["NODE_TRANSPARENCY",Oo],["NODE_BACKGROUND_OPACITY",No]]],["borderColor",[["NODE_BORDER_PAINT",zt],["NODE_BORDER_COLOR",zt]]],["borderOpacity",[["NODE_BORDER_TRANSPARENCY",Oo],["NODE_BORDER_OPACITY",No]]],["borderWidth",[["NODE_BORDER_WIDTH",er]]],["borderStyle",[["NODE_BORDER_STROKE",Ul("borderStyle")],["NODE_BORDER_LINE_TYPE",Ul("borderStyle")],["NODE_BORDER_STYLE",Ul("borderStyle")]]],["shape",[["NODE_SHAPE",n5]]],["width",[["NODE_WIDTH",er]]],["height",[["NODE_HEIGHT",er]]],["label",[["NODE_LABEL",Dc]]],["labelColor",[["NODE_LABEL_COLOR",zt]]],["labelSize",[["NODE_LABEL_FONT_SIZE",ZE]]],["labelWrapWidth",[["NODE_LABEL_WIDTH",er],["NODE_LABEL_MAX_WIDTH",er]]],["labelFont",[["NODE_LABEL_FONT_FACE",tw]]],["labelWeight",[["NODE_LABEL_FONT_FACE",nw]]],["labelItalic",[["NODE_LABEL_FONT_FACE",iw]]],["labelPosition",[["NODE_LABEL_POSITION",b5]]],["labelRotation",[["NODE_LABEL_ROTATION",JE]]],["labelOpacity",[["NODE_LABEL_TRANSPARENCY",Oo],["NODE_LABEL_OPACITY",No]]],["tooltip",[["NODE_TOOLTIP",Dc]]],["visible",[["NODE_VISIBLE",vh],["NODE_VISIBILITY",QE]]]]),edge:new Map([["color",[["EDGE_STROKE_UNSELECTED_PAINT",zt],["EDGE_LINE_COLOR",zt],["EDGE_UNSELECTED_PAINT",zt],["EDGE_PAINT",zt]]],["opacity",[["EDGE_TRANSPARENCY",Oo],["EDGE_OPACITY",No]]],["width",[["EDGE_WIDTH",er]]],["lineStyle",[["EDGE_LINE_TYPE",Ul("lineStyle")],["EDGE_LINE_STYLE",Ul("lineStyle")]]],["sourceArrow",[["EDGE_SOURCE_ARROW_SHAPE",ew]]],["targetArrow",[["EDGE_TARGET_ARROW_SHAPE",ew]]],["arrowSize",[["EDGE_TARGET_ARROW_SIZE",lg],["EDGE_SOURCE_ARROW_SIZE",lg]]],["sourceArrowColor",[["EDGE_SOURCE_ARROW_UNSELECTED_PAINT",zt],["EDGE_SOURCE_ARROW_COLOR",zt]]],["targetArrowColor",[["EDGE_TARGET_ARROW_UNSELECTED_PAINT",zt],["EDGE_TARGET_ARROW_COLOR",zt]]],["curved",[["EDGE_CURVED",vh]]],["label",[["EDGE_LABEL",Dc]]],["labelColor",[["EDGE_LABEL_COLOR",zt]]],["labelSize",[["EDGE_LABEL_FONT_SIZE",ZE]]],["labelFont",[["EDGE_LABEL_FONT_FACE",tw]]],["labelWeight",[["EDGE_LABEL_FONT_FACE",nw]]],["labelItalic",[["EDGE_LABEL_FONT_FACE",iw]]],["labelWrapWidth",[["EDGE_LABEL_WIDTH",er],["EDGE_LABEL_MAX_WIDTH",er]]],["labelRotation",[["EDGE_LABEL_ROTATION",JE]]],["labelOpacity",[["EDGE_LABEL_TRANSPARENCY",Oo],["EDGE_LABEL_OPACITY",No]]],["tooltip",[["EDGE_TOOLTIP",Dc]]],["visible",[["EDGE_VISIBLE",vh],["EDGE_VISIBILITY",QE]]]])}),Zo="NODE_SIZE",Zr=er,Uo=zt,sw=t=>t.endsWith("_OPACITY")?No:Oo,E5=new Set([Zo,...Object.values(Zy).flatMap(t=>Array.from(t.values()).flatMap(e=>e.map(([n])=>n)))]),w5=/^(?:NODE|EDGE|NETWORK)_[XYZ]_LOCATION$|_SELECTED|SELECTION|^NETWORK_(?!BACKGROUND)|_DEPTH$|^COMPOUND_|EDGE_BEND|EDGE_CONTROL_POINTS|NODE_NESTED_NETWORK|_Z_ORDER$|EDGE_STACKING|_LABEL_WIDTH$|_HEIGHT$|_WIDTH$/;function _5(t){return!E5.has(t)&&!w5.test(t)}const S5={node:new Map([["fill","NODE_FILL_COLOR"],["w","NODE_WIDTH"],["h","NODE_HEIGHT"],["size","NODE_SIZE"],["type","NODE_SHAPE"],["outline","NODE_BORDER_PAINT"],["width","NODE_BORDER_WIDTH"],["borderlinetype","NODE_BORDER_LINE_TYPE"],["nodelabelfont","NODE_LABEL_FONT_FACE"],["nodetransparency","NODE_TRANSPARENCY_01"],["nodelabelposition","NODE_LABEL_POSITION"],["nodefillcolor","NODE_FILL_COLOR"],["nodesize","NODE_SIZE"],["nodewidth","NODE_WIDTH"],["nodehight","NODE_HEIGHT"],["nodeheight","NODE_HEIGHT"],["nodeopacity","NODE_TRANSPARENCY"],["nodebordercolor","NODE_BORDER_PAINT"],["nodelinewidth","NODE_BORDER_WIDTH"],["nodelinestyle","NODE_BORDER_LINE_TYPE"],["nodeshape","NODE_SHAPE"],["nodefont","NODE_LABEL_FONT_FACE"],["nodefontsize","NODE_LABEL_FONT_SIZE"],["nodelabel","NODE_LABEL"],["nodelabelcolor","NODE_LABEL_COLOR"],["nodetooltip","NODE_TOOLTIP"]]),edge:new Map([["width","EDGE_WIDTH"],["fill","EDGE_STROKE_UNSELECTED_PAINT"],["edgelinetype","EDGE_LINE_TYPE"],["edgelabelfont","EDGE_LABEL_FONT_FACE"],["sourcearrowcolor","EDGE_SOURCE_ARROW_UNSELECTED_PAINT"],["targetarrowcolor","EDGE_TARGET_ARROW_UNSELECTED_PAINT"],["edgesourcearrowcolor","EDGE_SOURCE_ARROW_UNSELECTED_PAINT"],["edgetargetarrowcolor","EDGE_TARGET_ARROW_UNSELECTED_PAINT"],["edgelinewidth","EDGE_WIDTH"],["edgecolor","EDGE_STROKE_UNSELECTED_PAINT"],["edgelinestyle","EDGE_LINE_TYPE"],["edgeopacity","EDGE_TRANSPARENCY"],["sourcearrow","EDGE_SOURCE_ARROW_SHAPE"],["targetarrow","EDGE_TARGET_ARROW_SHAPE"],["edgesourcearrowshape","EDGE_SOURCE_ARROW_SHAPE"],["edgetargetarrowshape","EDGE_TARGET_ARROW_SHAPE"],["edgelabel","EDGE_LABEL"],["edgefont","EDGE_LABEL_FONT_FACE"],["edgelabelcolor","EDGE_LABEL_COLOR"],["edgefontsize","EDGE_LABEL_FONT_SIZE"],["edgetooltip","EDGE_TOOLTIP"],["curved","EDGE_CURVED_LEGACY"],["edgecurved","EDGE_CURVED"],["edgebend","EDGE_BEND"]])},H1=8,O5=/^[A-Z][A-Z_0-9]+$/;function N5(t,e,n){const i=O5.test(e)?e:S5[t].get(e.toLowerCase().replace(/^cy:/,""));if(i===void 0)return[`?${e}`,n];if(i==="NODE_TRANSPARENCY_01"){let r=Number.NaN;return typeof n=="number"?r=n:typeof n=="string"&&(r=Number(n.trim())),["NODE_TRANSPARENCY",Number.isFinite(r)?Math.round(r*255):null]}return i==="EDGE_CURVED_LEGACY"?["EDGE_CURVED",typeof n=="string"&&n.toUpperCase()==="CURVED_LINES"]:[i,n]}function A5(t,e,n,i){const[r,s]=e;let o=0;for(const l of Object.keys(r)){const a=r[l];if(l==="lockedVisualProperties"||a===null||a===void 0)continue;if(typeof a=="object"&&!Array.isArray(a)&&!/^[A-Z_0-9]+$/.test(l)&&l.toLowerCase()!=="edgebend"){s+1>H1?o++:n.push([a,s+1]);continue}const[c,d]=N5(t,l,a);i.has(c)||i.set(c,d)}return o}function cg(t,e,n){if(e===null||typeof e!="object")return new Map;const i=new Map,r=[[e,0]];let s=0;for(let o=r.pop();o!==void 0;o=r.pop())s+=A5(t,o,r,i);return s>0&&n?.add(v.NESTING,t,"graphics",{sample:`deeper than ${H1}`,count:s}),i}const T5=new Map([["NODE_LABEL_FONT_SIZE",1],["EDGE_LABEL_FONT_SIZE",1],["NODE_TRANSPARENCY",1/255],["EDGE_TRANSPARENCY",1/255]]);function V1(t){return T5.get(t)}const hu=t=>String(Math.round(t*1e4)/1e4);function Al(t,e,n,i){const r=i?-1:1,s=e[0]-t[0],o=(e[1]-t[1])*r,l=s*s+o*o;if(n.length===0||l<=0||!Number.isFinite(l))return null;const a=[];for(const[c,d]of n){const u=c-t[0],f=(d-t[1])*r,h=(u*s+f*o)/l,p=(s*f-o*u)/l;if(!Number.isFinite(h)||!Number.isFinite(p))return null;a.push(`${hu(h)},${hu(p)}`)}return a.join(" ")}function Y1(t,e,n,i){const s=e[0]-t[0],o=(e[1]-t[1])*-1,l=[];for(const a of n.trim().split(/\s+/)){const[c,d,u]=a.split(",").map(Number);if(u!==void 0||!Number.isFinite(c)||!Number.isFinite(d))return null;const f=t[0]+c*s-d*o,h=t[1]+(c*o+d*s)*-1;if(!Number.isFinite(f)||!Number.isFinite(h))return null;l.push([f,h])}return l.length===0?null:l}function Sf(t,e=8){if(t.length<4||(t.length-1)%3!==0)return null;const n=[t[0]];for(let i=0;i+3<t.length;i+=3){const[r,s,o,l]=t.slice(i,i+4);for(let a=1;a<=e;a++){const c=a/e,d=1-c,u=[d*d*d,3*d*d*c,3*d*c*c,c*c*c];n.push([u[0]*r[0]+u[1]*s[0]+u[2]*o[0]+u[3]*l[0],u[0]*r[1]+u[1]*s[1]+u[2]*o[1]+u[3]*l[1]])}}return n}function Hs(t,e,n,i){const[r,s]=[e[0]/2,e[1]/2];if(n.length===0||Number.isNaN(r+s)||r<=0||s<=0)return null;const o=i?-1:1,l=[];for(const[a,c]of n){const d=(a-t[0])/r,u=(c-t[1])*o/s;if(!Number.isFinite(d)||!Number.isFinite(u))return null;l.push(`${hu(d)},${hu(u)}`)}return l.join(" ")}function pu(t,e,n,i){const s=[];for(const o of n.trim().split(/\s+/)){const[l,a,c]=o.split(",").map(Number),d=t[0]+l*e[0]/2,u=t[1]+a*e[1]*-1/2;if(c!==void 0||!Number.isFinite(d)||!Number.isFinite(u))return null;s.push([d,u])}return s.length===0?null:s}function K1(t,e,n=8){if(t.length<3)return[...t];const i=Math.min(1,Math.max(0,Number.isFinite(e)?e:0)),r=(l,a,c)=>[l[0]+(a[0]-l[0])*c,l[1]+(a[1]-l[1])*c],s=t.length-1,o=[t[0]];for(let l=1;l<s;l++){const a=t[l],c=l===1?t[0]:r(t[l-1],a,.5),d=l===s-1?t[s]:r(a,t[l+1],.5),u=r(a,c,1-i),f=r(a,d,1-i);for(let h=0;h<=n;h++){const p=h/n,g=1-p;o.push([g*g*u[0]+2*g*p*a[0]+p*p*f[0],g*g*u[1]+2*g*p*a[1]+p*p*f[1]])}}return o.push(t[s]),o.filter((l,a)=>a===0||l[0]!==o[a-1][0]||l[1]!==o[a-1][1])}function I5(t,e){const n=new Map;return(i,r)=>{const s=`${i} ${r}`;let o=n.get(s);return o===void 0&&(o=I1(e,i,r,t),n.set(s,o)),o}}function Vs(t,e,n){const i=new Map;for(const r of n)i.set(r,t(e,r));return r=>s=>i.get(s)?.[r]??null}function $5(t,e,n,i){const{values:r}=i,s=C5(t,n,i.writes),o=[...i.properties],l=new Map;for(let a=0;a<e;a++){const c=s(a),d=i.readBack(a,c);if(d!==null)for(const u of o){const f=c(u);v5(i,u,f,r[u]?.[a]??null,d)&&(D5(l,r,u,e)[a]=f)}}for(const[a,c]of l)r[a]=c}function C5(t,e,n){return n!==void 0?Vs(e,t,n):i=>r=>e(t,r)[i]??null}function v5(t,e,n,i,r){return t.take?.(e,n,i)!==!1&&i!==n&&i===(r(e)??null)}function D5(t,e,n,i){let r=t.get(n);if(r===void 0){const s=e[n];r=s===void 0?new Array(i).fill(null):[...s],t.set(n,r)}return r}function so(t,e,n,i){const r=e===null?null:ac(e,ro(t)),s=r?.ok===!0?z1(r.block,t,n):null;if(s===null)return;const o=I5(t,s);for(const l of["node","edge"]){const a=i(l,o,s);a!==null&&$5(l,l==="node"?t.nodeCount:t.edgeCount,o,a)}}function oo(){const t=()=>({defaults:new Map,mappings:new Map,dependencies:new Map,bypassAliases:new Map});return{network:{defaults:new Map},node:t(),edge:t()}}const k5=new Map([["shared name","name"],["shared interaction","interaction"]]);function X1(t,e){for(const[n,i]of t.mappings){const r=k5.get(i.column);r!==void 0&&!e(i.column)&&e(r)&&t.mappings.set(n,{...i,column:r})}}function q1(t,e,n){const i=e===null||n.has(e)?void 0:n.byRole("weight")?.meta.name;if(i!==void 0)for(const[r,s]of t.mappings)s.column===e&&t.mappings.set(r,{...s,column:i})}function ow(t){const e=(t??"").toLowerCase().replace(/^list_of_/,"").replace(/^java\.lang\./,"");return e==="integer"||e==="long"||e==="int"||e==="short"?"integral":e==="double"||e==="float"||e==="real"?"floating":null}function J1(t,e,n,i){for(const[r,s]of t.mappings){if(s.kind!=="discrete"||s.table.length===0)continue;const o=ow(s.type),l=ow(e(s.column));o!==null&&l!==null&&o!==l&&(t.mappings.set(r,{...s,table:[]}),n.add(v.BAD_MAPPING,i,s.column,{sample:`${r}: ${o} keys on a ${l} column`}))}}const R5=new Set(["integer","long","double","float","int","short"]),Z1=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function Qy(t,e){if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="boolean")return t;if(typeof t!="string")return null;const n=(e??"").toLowerCase().replace(/^list_of_/,"").replace(/^java\.lang\./,"");if(R5.has(n)&&t.length<=64&&Z1.test(t.trim()))return Number(t.trim());if(n==="boolean"){const i=t.trim().toLowerCase();if(i==="true"||i==="false")return i==="true"}return t}const L5=new Set(["K","V","L","E","G","OV"]);function P5(t){const e=[];let n=[],i=0,r=t.indexOf(",");for(;r>=0;)n.push(t.slice(i,r)),t[r+1]===","?(n.push(","),r++):(e.push(n.join("")),n=[]),i=r+1,r=t.indexOf(",",i);return n.push(t.slice(i)),e.push(n.join("")),e}function x5(t){const e=t.indexOf("="),n=e<0?-1:t.indexOf("=",e+1),i=t.slice(0,e);if(n<0||!L5.has(i))return null;const r=t.slice(e+1,n);return/^\d{1,15}$/.test(r)?{tag:i,index:Number(r),value:t.slice(n+1)}:null}function M5(t,e,n=null){const i=P5(t),r=new Map;let s=null,o=null,l=0;for(const a of i){if(a.startsWith("COL=")){s=a.slice(4);continue}if(a.startsWith("T=")){o=a.slice(2);continue}const c=x5(a);if(c===null)continue;const{tag:d,index:u,value:f}=c;if(u>i.length){l++;continue}let h=r.get(d);h===void 0&&(h=new Map,r.set(d,h)),h.set(u,f)}return l>0&&e?.add(v.BAD_MAPPING,n,s??"definition",{sample:`${l} entries with an index beyond the definition`,count:l}),{column:s,type:o,entries:r}}function lw(t,e){return Array.from(t.entries.get(e)?.keys()??[]).sort((n,i)=>n-i)}function dg(t){return typeof t=="number"?Number.isFinite(t)?t:null:typeof t=="string"&&t.length<=64&&Z1.test(t.trim())?Number(t.trim()):null}function U5(t,e,n=null){if(t===null||typeof t!="object"||typeof t.definition!="string")return null;const{type:i,definition:r}=t,s=M5(r,e,n);if(s.column===null)return null;const o=(l,a)=>s.entries.get(l)?.get(a);switch(String(i).toUpperCase()){case"PASSTHROUGH":return{kind:"passthrough",column:s.column,type:s.type};case"DISCRETE":{const l=[];for(const a of lw(s,"K")){const c=Qy(o("K",a),s.type),d=o("V",a);c!==null&&d!==void 0&&l.push([c,d])}return{kind:"discrete",column:s.column,type:s.type,table:l}}case"CONTINUOUS":{const l=[];for(const a of lw(s,"OV")){const c=dg(o("OV",a));c!==null&&l.push({at:c,below:o("L",a),value:o("E",a),above:o("G",a)})}return{kind:"continuous",column:s.column,type:s.type,points:l}}default:return null}}function _e(t,e){return t!==null&&typeof t=="object"&&Object.hasOwn(t,e)?t[e]:void 0}function G5(t){const e=_e(t,"definition"),n=_e(e,"attribute");if(typeof n!="string")return null;const i=_e(e,"type"),r=typeof i=="string"?i:null,s=_e(e,"map"),o=Array.isArray(s)?s:[];switch(String(_e(t,"type")).toUpperCase()){case"PASSTHROUGH":return{kind:"passthrough",column:n,type:r};case"DISCRETE":{const l=[];for(const a of o){const c=Qy(_e(a,"v"),r),d=_e(a,"vp");c!==null&&d!==void 0&&l.push([c,d])}return{kind:"discrete",column:n,type:r,table:l}}case"CONTINUOUS":return{kind:"continuous",column:n,type:r,points:j5(o)};default:return null}}function j5(t){const e=new Map,n=i=>{let r=e.get(i);return r===void 0&&(r={at:i},e.set(i,r)),r};for(const i of t)i!==null&&typeof i=="object"&&F5(i,n);return Array.from(e.values()).sort((i,r)=>i.at-r.at).map(i=>{const r=i.below??i.value??i.above,s=i.above??i.value??r;return{at:i.at,below:r,value:i.value??r,above:s}})}function F5(t,e){const n=dg(_e(t,"min")),i=dg(_e(t,"max")),r=_e(t,"minVPValue")??_e(t,"maxVPValue"),s=_e(t,"maxVPValue")??_e(t,"minVPValue");if(n!==null){const o=e(n);o.above=r,_e(t,"includeMin")!==!1&&(o.value=r)}if(i!==null){const o=e(i);o.below=s,_e(t,"includeMax")!==!1&&o.value===void 0&&(o.value=s)}}function ir(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}function z5(t,e){const n=oo(),i=s=>_e(s,"applies_to")??_e(s,"view")??null,r=[];for(const s of t)/default|network/.test(String(_e(s,"properties_of")))&&!r.includes(i(s))&&r.push(i(s));r.length>1&&e?.add(v.OTHER_VIEWS,null,"cyVisualProperties",{sample:`${r.length-1} more`,count:r.length-1});for(const s of t){const o=s!==null&&typeof s=="object"&&i(s)===r[0]?W5.get(String(_e(s,"properties_of"))):void 0;if(o===void 0)continue;const l=ir(_e(s,"properties"));for(const a of Object.keys(l))n[o].defaults.set(a,l[a]);o!=="network"&&B5(n,o,s,e)}return n}const W5=new Map([["nodes:default","node"],["edges:default","edge"],["network","network"]]);function B5(t,e,n,i){const r=ir(_e(n,"mappings"));for(const o of Object.keys(r)){const l=U5(r[o],i,e);l===null?i?.add(v.BAD_MAPPING,e,o,{sample:r[o]}):t[e].mappings.set(o,l)}const s=ir(_e(n,"dependencies"));for(const o of Object.keys(s))t[e].dependencies.set(o,String(s[o]).toLowerCase()==="true")}function H5(t,e,n){const i=oo(),r=a=>Array.isArray(a)?a[0]:a,s=ir(r(t)),o=ir(_e(ir(r(e)),"properties")),l=ir(_e(s,"default"));for(const a of["network","node","edge"]){const c=ir(_e(l,a));for(const d of Object.keys(c))i[a].defaults.set(d,c[d])}i.node.dependencies.set("nodeSizeLocked",_e(o,"nodeSizeLocked")===!0),i.edge.dependencies.set("arrowColorMatchesEdge",_e(o,"arrowColorMatchesEdge")===!0),i.node.dependencies.set("nodeCustomGraphicsSizeSync",_e(o,"nodeCustomGraphicsSizeSync")!==!1);for(const[a,c]of[["node","nodeMapping"],["edge","edgeMapping"]]){const d=ir(_e(s,c));for(const u of Object.keys(d)){const f=G5(d[u]);f===null?n?.add(v.BAD_MAPPING,a,u,{sample:d[u]}):i[a].mappings.set(u,f)}}V5(i.node);for(const a of[i.edge.defaults,i.edge.mappings])a.has("EDGE_CONTROL_POINTS")&&!a.has("EDGE_BEND")&&a.set("EDGE_BEND",a.get("EDGE_CONTROL_POINTS"));return i.edge.bypassAliases.set("EDGE_CONTROL_POINTS","EDGE_BEND"),i}function V5(t){if(t.dependencies.get("nodeSizeLocked")!==!0||t.defaults.has("NODE_SIZE")||t.mappings.has("NODE_SIZE"))return;t.defaults.has("NODE_WIDTH")&&t.defaults.set("NODE_SIZE",t.defaults.get("NODE_WIDTH"));const e=t.mappings.get("NODE_WIDTH");e!==void 0&&t.mappings.set("NODE_SIZE",e),t.bypassAliases.set("NODE_WIDTH","NODE_SIZE")}const an=t=>String(t).toUpperCase();function oi(t,e,n,i=new Set){return(r,s)=>{const o=String(r);if(Object.hasOwn(t,o))return t[o];if(o.startsWith("other:")&&i.has(o.slice(6).toLowerCase().replaceAll("_","-"))){const l=o.slice(6),a=n?l.toUpperCase().replaceAll("-","_"):l;return a!==l&&s(),a}return s(),Object.hasOwn(e,o)?e[o]:Object.values(t)[0]}}const Y5="borderPosition",Q1={node:new Map([[Y5,"inside"],["borderWaveAmplitude",10],["borderWavePeriod",20],["labelPadding",0],["labelLineHeight",1]]),edge:new Map([["waveAmplitude",10],["wavePeriod",20],["labelPadding",0],["labelLineHeight",1]])},kc={ellipse:"ELLIPSE",rectangle:"RECTANGLE","round-rectangle":"ROUND_RECTANGLE",triangle:"TRIANGLE",diamond:"DIAMOND",hexagon:"HEXAGON",octagon:"OCTAGON",parallelogram:"PARALLELOGRAM",vee:"V"},aw={pentagon:"hexagon",star:"octagon",trapezoid:"parallelogram",none:"ellipse","other:invtrapezium":"parallelogram","other:house":"hexagon","other:invhouse":"hexagon"},cw=t=>Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n==="V"?"vee":n.toLowerCase()])),Rr=(t,e)=>Object.fromEntries(Object.entries(e).map(([n,i])=>[n,t[i]])),ug={solid:"SOLID",dashed:"EQUAL_DASH",dotted:"DOT","dash-dot":"DASH_DOT",double:"PARALLEL_LINES"},dw={...ug,zigzag:"ZIGZAG",sinewave:"SINEWAVE"},Rc={solid:"solid",dashed:"dashed",dotted:"dotted",double:"double"},Lc={"dash-dot":"dashed","long-dash":"dashed",zigzag:"solid",sinewave:"solid"},uw={none:"NONE",triangle:"DELTA",tee:"T",diamond:"DIAMOND",circle:"CIRCLE",square:"SQUARE","triangle-open":"OPEN_DELTA","diamond-open":"OPEN_DIAMOND","circle-open":"OPEN_CIRCLE",half:"HALF_TOP","other:cross-delta":"CROSS_DELTA","other:cross-open-delta":"CROSS_OPEN_DELTA"},Pc={none:"none",triangle:"triangle",vee:"vee",tee:"tee",diamond:"diamond",circle:"circle",square:"square","triangle-open":"open-triangle","diamond-open":"open-diamond","circle-open":"open-circle",half:"half-top","other:cross-delta":"triangle-cross","other:cross-open-delta":"cross_open_delta"},fw={crow:"vee",inverted:"triangle"},hw={crow:"ARROW",inverted:"DELTA",vee:"ARROW"},xc=new Set(["open-square","open-half-circle","half-circle","half-bottom"]),fg=new Set(["backward-slash","forward-slash","vertical-slash","separate-arrow","contiguous-arrow"]),pw=new Set([...fg,"zigzag","sinewave"]),hg={center:["C","C"],top:["N","S"],bottom:["S","N"],left:["W","E"],right:["E","W"],"top-left":["NW","SE"],"top-right":["NE","SW"],"bottom-left":["SW","NE"],"bottom-right":["SE","NW"],"inside-top":["N","N"],"inside-bottom":["S","S"],"inside-left":["W","W"],"inside-right":["E","E"],"inside-top-left":["NW","NW"],"inside-top-right":["NE","NE"],"inside-bottom-left":["SW","SW"],"inside-bottom-right":["SE","SE"]},K5=Object.fromEntries(Object.entries(hg).map(([t,[e,n]])=>[t,`${e},${n},c,0.00,0.00`])),gw={C:["center","center"],N:["center","top"],S:["center","bottom"],W:["left","center"],E:["right","center"],NW:["left","top"],NE:["right","top"],SW:["left","bottom"],SE:["right","bottom"]},Lr=String,li=t=>t;function Mc(t){return(e,n)=>(typeof e=="number"&&!Number.isInteger(e)&&n(),t(e,n))}const go=String,Dh=t=>String(t===!0),kh=(t,e)=>{const n=Math.round(Number(t)*255);return P(n/255)!==t&&e(),String(n)},eb={desktop:{node:new Map([["fill",{vp:"NODE_FILL_COLOR",write:an}],["fillOpacity",{vp:"NODE_TRANSPARENCY",write:kh}],["borderColor",{vp:"NODE_BORDER_PAINT",write:an}],["borderOpacity",{vp:"NODE_BORDER_TRANSPARENCY",write:kh}],["borderWidth",{vp:"NODE_BORDER_WIDTH",write:Lr}],["borderStyle",{vp:"NODE_BORDER_LINE_TYPE",write:oi(ug,Rr(ug,Lc),!0,pw)}],["shape",{vp:"NODE_SHAPE",write:oi(kc,Rr(kc,aw),!0)}],["width",{vp:"NODE_WIDTH",write:Lr}],["height",{vp:"NODE_HEIGHT",write:Lr}],["label",{vp:"NODE_LABEL",write:go}],["labelColor",{vp:"NODE_LABEL_COLOR",write:an}],["labelSize",{vp:"NODE_LABEL_FONT_SIZE",write:Mc(Lr)}],["labelWrapWidth",{vp:"NODE_LABEL_WIDTH",write:Lr}],["labelPosition",{vp:"NODE_LABEL_POSITION",write:oi(K5,{},!1)}],["labelRotation",{vp:"NODE_LABEL_ROTATION",write:Lr}],["tooltip",{vp:"NODE_TOOLTIP",write:go}],["visible",{vp:"NODE_VISIBLE",write:Dh}]]),edge:new Map([["color",{vp:"EDGE_STROKE_UNSELECTED_PAINT",write:an}],["opacity",{vp:"EDGE_TRANSPARENCY",write:kh}],["width",{vp:"EDGE_WIDTH",write:Lr}],["lineStyle",{vp:"EDGE_LINE_TYPE",write:oi(dw,Rr(dw,Lc),!0,fg)}],["sourceArrow",{vp:"EDGE_SOURCE_ARROW_SHAPE",write:oi(uw,hw,!0,xc)}],["targetArrow",{vp:"EDGE_TARGET_ARROW_SHAPE",write:oi(uw,hw,!0,xc)}],["sourceArrowColor",{vp:"EDGE_SOURCE_ARROW_UNSELECTED_PAINT",write:an}],["targetArrowColor",{vp:"EDGE_TARGET_ARROW_UNSELECTED_PAINT",write:an}],["curved",{vp:"EDGE_CURVED",write:Dh}],["label",{vp:"EDGE_LABEL",write:go}],["labelColor",{vp:"EDGE_LABEL_COLOR",write:an}],["labelSize",{vp:"EDGE_LABEL_FONT_SIZE",write:Mc(Lr)}],["tooltip",{vp:"EDGE_TOOLTIP",write:go}],["visible",{vp:"EDGE_VISIBLE",write:Dh}]])},cx2:{node:new Map([["fill",{vp:"NODE_BACKGROUND_COLOR",write:an}],["fillOpacity",{vp:"NODE_BACKGROUND_OPACITY",write:li}],["borderColor",{vp:"NODE_BORDER_COLOR",write:an}],["borderOpacity",{vp:"NODE_BORDER_OPACITY",write:li}],["borderWidth",{vp:"NODE_BORDER_WIDTH",write:li}],["borderStyle",{vp:"NODE_BORDER_STYLE",write:oi(Rc,Rr(Rc,Lc),!1,pw)}],["shape",{vp:"NODE_SHAPE",write:oi(cw(kc),Rr(cw(kc),aw),!1)}],["width",{vp:"NODE_WIDTH",write:li}],["height",{vp:"NODE_HEIGHT",write:li}],["label",{vp:"NODE_LABEL",write:go}],["labelColor",{vp:"NODE_LABEL_COLOR",write:an}],["labelSize",{vp:"NODE_LABEL_FONT_SIZE",write:Mc(li)}],["labelWrapWidth",{vp:"NODE_LABEL_MAX_WIDTH",write:li}],["labelPosition",{vp:"NODE_LABEL_POSITION",write:X5}],["labelRotation",{vp:"NODE_LABEL_ROTATION",write:li}],["visible",{vp:"NODE_VISIBILITY",write:t=>t===!0?"element":"none"}]]),edge:new Map([["color",{vp:"EDGE_LINE_COLOR",write:an}],["opacity",{vp:"EDGE_OPACITY",write:li}],["width",{vp:"EDGE_WIDTH",write:li}],["lineStyle",{vp:"EDGE_LINE_STYLE",write:oi(Rc,Rr(Rc,Lc),!1,fg)}],["sourceArrow",{vp:"EDGE_SOURCE_ARROW_SHAPE",write:oi(Pc,Rr(Pc,fw),!1,xc)}],["targetArrow",{vp:"EDGE_TARGET_ARROW_SHAPE",write:oi(Pc,Rr(Pc,fw),!1,xc)}],["sourceArrowColor",{vp:"EDGE_SOURCE_ARROW_COLOR",write:an}],["targetArrowColor",{vp:"EDGE_TARGET_ARROW_COLOR",write:an}],["curved",{vp:"EDGE_CURVED",write:t=>t===!0}],["label",{vp:"EDGE_LABEL",write:go}],["labelColor",{vp:"EDGE_LABEL_COLOR",write:an}],["labelSize",{vp:"EDGE_LABEL_FONT_SIZE",write:Mc(li)}],["visible",{vp:"EDGE_VISIBILITY",write:t=>t===!0?"element":"none"}]])}};function X5(t){const[e,n]=Object.hasOwn(hg,String(t))?hg[String(t)]:["C","C"],[i,r]=gw[e],[s,o]=gw[n];return{HORIZONTAL_ALIGN:s,VERTICAL_ALIGN:o,HORIZONTAL_ANCHOR:i,VERTICAL_ANCHOR:r,MARGIN_X:0,MARGIN_Y:0,JUSTIFICATION:"center"}}const qr=["labelFont","labelWeight","labelItalic"],eI={node:"NODE_LABEL_FONT_FACE",edge:"EDGE_LABEL_FONT_FACE"},Uc={[Ts]:"SansSerif",[qy]:"Serif",[Xl]:"Monospaced"};function pg(t,e,n,i,r){const s=n==="bold",o=i===!0,l=e===null?"sans-serif":String(e);if(t==="cx2")return mw(l)!==l&&r(),{FONT_FAMILY:l,FONT_STYLE:o?"italic":"normal",FONT_WEIGHT:s?"bold":"normal"};const a=l.includes(",")?l.split(",")[0].trim():l,c=Object.hasOwn(Uc,a)?Uc[a]:a,d=Object.hasOwn(Uc,l)?Uc[l]:c;mw(d)!==l&&r();const u=q5(s,o);return`${u==="plain"?d:`${d}.${u}`},${s?"bold":"plain"},12`}function q5(t,e){return!t&&!e?"plain":(t?"bold":"")+(e?"italic":"")}function mw(t){return _f(t.replace(/\.(?:bold|italic|plain|bolditalic)$/i,""))}function J5(t,e){return"style"in e?`graphty.style.${t}.${e.style}`:`graphty.style.${t}.${"computed"in e?e.computed:e.data}`}const tI=new Set(["color","number","text","boolean"]);function nI(t,e,n){const i=n.notes??new se,r=oo(),s={node:new Array(e.nodeCount).fill(null),edge:new Array(e.edgeCount).fill(null)},o={node:new Map,edge:new Map};for(const a of["node","edge"])t4(Z5(a,t,e,n,i),r,s[a],o[a]);const l=t.styles.graph.background;return l!==void 0&&r.network.defaults.set(n.dialect==="cx2"?"NETWORK_BACKGROUND_COLOR":"NETWORK_BACKGROUND_PAINT",l.toUpperCase()),{style:r,bypasses:s,columns:o}}function Z5(t,e,n,i,r){const s=t==="node"?n.nodeCount:n.edgeCount,o=Cr(t,s,e.columns[t],e.features[t],n),l=e.styles.rules.filter(d=>d.target===t),a=new Set(l.flatMap(d=>[...Object.keys(d.set??{}),...Object.keys(d.map??{})])),c=new Map(Array.from(a,d=>[d,Ni(l,t,d,o)]));return{target:t,extracted:e,snapshot:n,options:i,notes:r,n:s,src:o,rules:l,truth:c,approx:d=>()=>{r.add(v.APPROXIMATED,t,d)},approxDefault:(d,u)=>()=>{const f=(c.get(d)??[]).filter(h=>h===u).length;r.add(v.APPROXIMATED,t,d,{count:Math.max(f,1)})}}}const Q5=new Map([["labelWrapTrailingSpace",!0],["bendCurve","midpoints"]]);function e4(t,e){const n=Q5.get(t);return n!==void 0&&e.every(i=>i===null||i===n)}function t4(t,e,n,i){const{target:r,notes:s,truth:o}=t,l=eb[t.options.dialect][r];for(const[f,h]of o){const p=Q1[r].get(f);if(p!==void 0){const g=h.filter(m=>m!==null&&m!==p).length;g>0&&s.add(v.APPROXIMATED,r,f,{count:g})}else if(!l.has(f)&&!qr.includes(f)&&!e4(f,h)){const g=h.filter(m=>m!==null).length;s.add(v.NOT_WRITTEN,r,f,{count:Math.max(g,1)})}}const a=new Set,c=f=>a.has(f)?0:(a.add(f),Math.max((o.get(f)??[]).filter(h=>h!==null).length,1)),d=o4(r,t.rules,l,s,c),u=e[r];u.dependencies.set(r==="node"?"nodeSizeLocked":"arrowColorMatchesEdge",!1);for(const[f,h]of l)o.has(f)&&n4(t,u,d,f,h,i,c);i4(t,d,l,n),u4(t,d,u,n)}function n4(t,e,n,i,r,s,o){const l=n.set.get(i);l!==void 0&&e.defaults.set(r.vp,r.write(l,t.approxDefault(i,l)));let a=n.map.get(i);if(a===void 0)return;t.options.dialect==="cx2"&&a.kind==="continuous"&&(a=d4(a,t.approx(i)),n.map.set(i,a));const c=l4(t,i,a,r,s);c===null?(t.notes.add(v.LAYER_FLATTENED,t.target,i,{sample:n.mappedBy.get(i),count:o(i)}),n.map.delete(i)):e.mappings.set(r.vp,c)}function i4(t,e,n,i){const{target:r}=t,s=[{id:"defaults",target:r,role:"defaults",origin:"declared",where:{all:!0},set:Object.fromEntries(e.set)},{id:"mappings",target:r,role:"mapping",origin:"declared",where:{all:!0},map:Object.fromEntries(e.map)}];for(const[o,l]of n){const a=t.truth.get(o);if(a===void 0)continue;const c=Ni(s,r,o,t.src),d=r4(e.map.get(o),l.vp,ii[r].get(o));let u=0;for(let f=0;f<t.n;f++){const h=a[f];h!==null&&h!==c[f]?(i[f]??=new Map,i[f]?.set(l.vp,l.write(h,t.approx(o)))):s4(h,d)&&u++}u>0&&t.notes.add(v.APPROXIMATED,r,o,{count:u})}}function r4(t,e,n){const i=t?.kind==="continuous"&&t.step===void 0,r=t?.kind==="passthrough"&&tI.has(n??"");return i||r?V1(e):void 0}function s4(t,e){return e!==void 0&&typeof t=="number"&&P(Math.round(t/e)*e)!==t}function o4(t,e,n,i,r){const s={set:new Map,map:new Map,mappedBy:new Map},o=(d,u)=>{i.add(v.LAYER_FLATTENED,t,d,{sample:u,count:r(d)})},l=d=>n.has(d)||qr.includes(d),a=(d,u)=>{for(const[f,h]of Object.entries(d.set??{}))if(!(h===void 0||!l(f))){if(!u){o(f,d.id);continue}s.set.set(f,h),s.map.delete(f),s.mappedBy.delete(f)}},c=(d,u)=>{for(const[f,h]of Object.entries(d.map??{})){if(h===void 0||!l(f))continue;if(!u||qr.includes(f)){o(f,d.id);continue}const p=s.mappedBy.get(f);p!==void 0&&o(f,p),s.map.set(f,h),s.mappedBy.set(f,d.id)}};for(const d of e){const u="all"in d.where&&d.where.all;a(d,u),c(d,u)}return s}function l4(t,e,n,i,r){const s=a4(t,n.by,r);if(s===null)return null;const o=t.approx(e),l=a=>i.write(a,o);if(n.kind==="passthrough")return c4(t,e,n.by,s,l);if(n.kind==="discrete")return{kind:"discrete",column:s,type:iI(t,n.by,n.table.map(([a])=>a)),table:n.table.map(([a,c])=>[a,l(c)])};if(n.kind==="continuous"){const a=n.points.map(c=>({at:c.at,below:l(c.below),value:l(c.value),above:l(c.above)}));return{kind:"continuous",column:s,type:"double",points:a}}return null}function a4(t,e,n){if("data"in e)return e.data;const{target:i}=t,r=(t.options.columnName??J5)(i,e);let s=null;return"style"in e?s=t.extracted.columns[i].get(e.style)??null:"computed"in e&&i==="node"&&(s=sc(t.snapshot,e.computed)),s===null?null:(n.set(r,s),r)}function c4(t,e,n,i,r){const{target:s}=t,o=ii[s].get(e)??"",l=t.src.column(n)??[];if(tI.has(o))return{kind:"passthrough",column:i,type:rI(Array.from(l))};const a="style"in n?u=>yw(u)?u:null:_l(s,e),c=new Map;for(let u=0;u<l.length;u++){const f=l[u],h=yw(f)&&!c.has(f)?a(f):null;h!==null&&c.set(f,r(h))}const d=Array.from(c);return{kind:"discrete",column:i,type:iI(t,n,d.map(([u])=>u)),table:d}}function d4(t,e){let n=!1;const i=t.points.map(r=>r.value===r.below||r.value===r.above?r:(n=!0,{...r,value:r.below}));return n?(e(),{...t,points:i}):t}function yw(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function iI(t,e,n){const i=rI(n);if(i!=="integer")return i;if(!("data"in e))return"double";const r=(t.target==="node"?t.snapshot.nodes:t.snapshot.edges).get(e.data)?.meta;return(r?.dtype==="f32"||r?.dtype==="f64")&&r.origin?.type!=="long"?"double":i}function rI(t){let e=0,n=0,i=0,r=0;for(const s of t)s!=null&&(r++,typeof s=="number"?(e++,Number.isInteger(s)&&n++):typeof s=="boolean"&&i++);return r>0&&e===r?n===r?"integer":"double":r>0&&i===r?"boolean":"string"}function u4(t,e,n,i){const{target:r,truth:s,n:o,approx:l,approxDefault:a}=t,{dialect:c}=t.options;if(!qr.some(y=>s.has(y)))return;const[d,u,f]=qr.map(y=>e.set.get(y)??null),h=eI[r];(d!==null||u!==null||f!==null)&&n.defaults.set(h,pg(c,d,u,f,d===null?l("labelFont"):a("labelFont",d)));const[p,g,m]=qr.map(y=>s.get(y)??null);for(let y=0;y<o;y++){const b=p?.[y]??null,_=g?.[y]??null,S=m?.[y]??null;(b!==null&&b!==d||_!==null&&_!==u||S!==null&&S!==f)&&(i[y]??=new Map,i[y]?.set(h,pg(c,b??d,_??u,S??f,l("labelFont"))))}}function mo(t){return String(t).replaceAll(",",",,")}function f4(t){const e=[`COL=${mo(t.column)}`,`T=${t.type??"string"}`];return t.kind==="discrete"?t.table.forEach(([n,i],r)=>{e.push(`K=${r}=${mo(n)}`,`V=${r}=${mo(i)}`)}):t.kind==="continuous"&&t.points.forEach((n,i)=>{e.push(`L=${i}=${mo(n.below)}`,`E=${i}=${mo(n.value)}`,`G=${i}=${mo(n.above)}`,`OV=${i}=${n.at}`)}),e.join(",")}function ar(t,e){const n={};for(const[i,r]of t)Object.defineProperty(n,i,{value:e(r),enumerable:!0,writable:!0,configurable:!0});return n}function h4(t){const e=(n,i)=>({properties_of:n,properties:ar(i.defaults,String),dependencies:ar(i.dependencies,String),mappings:ar(i.mappings,r=>({type:r.kind.toUpperCase(),definition:f4(r)}))});return[{properties_of:"network",properties:ar(t.network.defaults,String)},e("nodes:default",t.node),e("edges:default",t.edge)]}function p4(t){const e=(i,r)=>JSON.stringify(i)===JSON.stringify(r),n=[];for(let i=0;i<=t.length;i++){const r=t.at(i-1),s=t.at(i),o={};i>0&&r!==void 0&&(o.min=r.at,o.minVPValue=r.above,o.includeMin=e(r.value,r.above)),i<t.length&&s!==void 0&&(o.max=s.at,o.maxVPValue=s.below,o.includeMax=!e(s.value,s.above)&&e(s.value,s.below)),n.push(o)}return n}function g4(t){const e=i=>i.kind==="passthrough"?{type:"PASSTHROUGH",definition:{attribute:i.column}}:i.kind==="discrete"?{type:"DISCRETE",definition:{attribute:i.column,map:i.table.map(([r,s])=>({v:r,vp:s}))}}:{type:"CONTINUOUS",definition:{attribute:i.column,map:p4(i.points)}},n=i=>i;return{visualProperties:[{default:{network:ar(t.network.defaults,n),node:ar(t.node.defaults,n),edge:ar(t.edge.defaults,n)},nodeMapping:ar(t.node.mappings,e),edgeMapping:ar(t.edge.mappings,e)}],visualEditorProperties:[{properties:{nodeSizeLocked:t.node.dependencies.get("nodeSizeLocked")===!0,arrowColorMatchesEdge:t.edge.dependencies.get("arrowColorMatchesEdge")===!0}}]}}function cn(t,e){return` ${t}="${W(String(e))}"`}function m4(t,e){const n=[`<visualStyle${cn("name",e)}>`],i=(r,s,o)=>{n.push(` <${r}>`);for(const[a,c]of o?.dependencies??[])n.push(` <dependency${cn("name",a)}${cn("value",c)}/>`);const l=new Set([...s.keys(),...o?.mappings.keys()??[]]);for(const a of l){const c=s.has(a)?cn("default",s.get(a)):"",d=o?.mappings.get(a);d===void 0?n.push(` <visualProperty${cn("name",a)}${c}/>`):n.push(` <visualProperty${cn("name",a)}${c}>`,...y4(d)," </visualProperty>")}n.push(` </${r}>`)};return i("network",t.network.defaults),i("node",t.node.defaults,t.node),i("edge",t.edge.defaults,t.edge),n.push("</visualStyle>"),n.join(`
|
|
41
|
+
`)}function y4(t){const e=`${cn("attributeName",t.column)}${cn("attributeType",t.kind==="continuous"?"float":t.type??"string")}`;return t.kind==="passthrough"?[` <passthroughMapping${e}/>`]:t.kind==="discrete"?[` <discreteMapping${e}>`,...t.table.map(([n,i])=>` <discreteMappingEntry${cn("attributeValue",n)}${cn("value",i)}/>`)," </discreteMapping>"]:[` <continuousMapping${e}>`,...t.points.map(n=>` <continuousMappingPoint${cn("attrValue",n.at)}${cn("lesserValue",n.below)}${cn("equalValue",n.value)}${cn("greaterValue",n.above)}/>`)," </continuousMapping>"]}function gu(t,e){return[...eb[e][t].keys(),...qr,...Q1[t].keys(),...t==="node"?["labelWrapTrailingSpace"]:["bendCurve"]]}function tb(t,e,n,i){const r=new Map;for(const[a,c]of eb[n][t]){const d=e(a);d!==null&&r.set(c.vp,c.write(d,()=>{i(a)}))}const[s,o,l]=qr.map(a=>e(a));return(s!==null||o!==null||l!==null)&&r.set(eI[t],pg(n,s,o,l,()=>{i("labelFont")})),r}const ql=.9,bw=.4,Ew=Array.from({length:9},(t,e)=>`NODE_CUSTOMGRAPHICS_${String(e+1)}`),ww=/^org\.cytoscape\.(PieChart|RingChart|BarChart|LineChart|BoxChart|HeatMapChart)$/;function _w(t){if(typeof t=="object"&&t!==null&&!Array.isArray(t)){const i=t,r=ww.exec(typeof i.name=="string"?i.name:"")?.[1];return r!==void 0&&typeof i.properties=="object"&&i.properties!==null?{kind:r,ring:r==="RingChart",options:i.properties}:null}if(typeof t!="string")return null;const e=/^(org\.cytoscape\.\w+):(\{.*\})\s*$/s.exec(t.trim()),n=e===null?void 0:ww.exec(e[1])?.[1];if(e===null||n===void 0)return null;try{const i=JSON.parse(e[2]);return typeof i=="object"&&i!==null?{kind:n,ring:n==="RingChart",options:i}:null}catch{return null}}const b4={C:[0,0],N:[0,-1],NE:[1,-1],E:[1,0],SE:[1,1],S:[0,1],SW:[-1,1],W:[-1,0],NW:[-1,-1]};function E4(t){let e;if(typeof t=="string"){const l=t.split(",");e=[l[0],l[1],l[3],l[4]]}else if(typeof t=="object"&&t!==null){const l=t;e=[l.ENTITY_ANCHOR,l.GRAPHICS_ANCHOR,l.MARGIN_X,l.MARGIN_Y]}else return null;const n=l=>typeof l=="string"?b4[l.trim().toUpperCase()]:void 0,[i,r]=[n(e[0]),n(e[1])],[s,o]=[Number(e[2]??0),Number(e[3]??0)];return i===void 0||r===void 0?null:{node:i,chart:r,x:Number.isFinite(s)?s:0,y:Number.isFinite(o)?o:0}}function w4(t,e){const n=t.length===1?e(t[0]):void 0;return(Array.isArray(n)?n:t.map(r=>e(r))).map(r=>typeof r=="number"?r:Number(r))}function _4(t,e,n,i,r){const s=o=>{const l=t[o];if(l!==void 0)return l;const a=new Array(e).fill(null);return t[o]=a,a};for(let o=0;o<e;o++){const l=Ew.findIndex(u=>_w(n(u,o))!==null),a=l<0?null:_w(n(Ew[l],o));if(a===null)continue;const[c,d]=[t.width?.[o],t.height?.[o]];S4(a,{put:(u,f)=>{s(u)[o]=f},get:u=>t[u]?.[o],graphic:u=>n(`${u}_${String(l+1)}`,o),value:u=>i(u,o),w:typeof c=="number"?c:null,h:typeof d=="number"?d:null},r)}}function sI(t){return t.w!==null&&t.h!==null?Math.min(t.w,t.h):null}function S4(t,e,n){const{options:i}=t,r=Array.isArray(i.cy_colors)?i.cy_colors.map(String):[],s=Array.isArray(i.cy_dataColumns)?i.cy_dataColumns.map(String):[],o=w4(s,e.value);if(t.kind==="PieChart"||t.kind==="RingChart"){N4(t.ring,i,o,r,e,n);return}const l=Number(e.graphic("NODE_CUSTOMGRAPHICS_SIZE")),a=sI(e),c=l>0,u=a===null?null:{disc:ql*(n||!c?a:l),side:a};for(const[f,h]of Object.entries(U4(t.kind,i,o,r,u)))e.put(f,h)}function O4(t,e){const n=t.reduce((i,r)=>i+(Number.isFinite(r)&&r>0?r:0),0);return t.flatMap((i,r)=>Number.isFinite(i)&&i>0&&e[r]!==void 0?[{color:e[r].toLowerCase(),size:i/n}]:[])}function N4(t,e,n,i,r,s){const o=O4(n,i);if(o.length===0)return;const l=Number(e.cy_startAngle??0),a=Number.isFinite(l)?l:0,c=[...o].reverse();r.put("pieColors",c.map(g=>g.color).join(" ")),r.put("pieSizes",c.map(g=>String(P(g.size))).join(" "));const d=Number(r.graphic("NODE_CUSTOMGRAPHICS_SIZE")),u=sI(r),f=d>0,h=s||!f||u===null||u<=0;r.put("pieRadius",h?ql:P(ql*d/u)),A4(r,h,d),r.put("pieRotation",P(((90-a)%360+360)%360));const p=$4(e,n,i,r.value,{start:a,radius:ql*(h||u===null?1:d/u)*(u??0)/2,dx:Number(r.get("pieOffsetX")??0),dy:Number(r.get("pieOffsetY")??0),w:r.w,h:r.h});if(p!==null&&(r.get("shapeTexts")??null)===null&&r.put("shapeTexts",p),t){const g=Number(e.cy_holeSize??bw);r.put("pieHole",Number.isFinite(g)?Math.max(0,Math.min(1,g)):bw)}}function A4(t,e,n){const i=E4(t.graphic("NODE_CUSTOMGRAPHICS_POSITION")),{w:r,h:s}=t;if(i===null||r===null||s===null)return;const o=ql*(e?Math.min(r,s):n),l=i.node[0]*o/2-i.chart[0]*r/2+i.x,a=i.node[1]*o/2-i.chart[1]*s/2+i.y;(l!==0||a!==0)&&(t.put("pieOffsetX",P(l)),t.put("pieOffsetY",P(a)))}const Sw=.62,Ow=1,T4="#404040";function I4(t,e){if(t.cy_showItemLabels!==!0)return null;const n=typeof t.cy_itemLabelsColumn=="string"?e(t.cy_itemLabelsColumn):void 0,i=Array.isArray(n)?n:t.cy_itemLabels;return Array.isArray(i)?i.map(r=>r==null?"":String(r)):null}function $4(t,e,n,i,r){const s=I4(t,i),{w:o,h:l}=r;if(s===null||o===null||l===null||!(o>0&&l>0&&r.radius>0))return null;const c=e.map((p,g)=>Number.isFinite(p)&&p>0&&n[g]!==void 0),d=e.reduce((p,g,m)=>p+(c[m]?g:0),0),u=Number(t.cy_itemLabelFontSize??Ow),f=[];let h=r.start;return e.forEach((p,g)=>{if(!c[g])return;const m=360*p/d,y=(h+m/2)*Math.PI/180;h+=m;const b=s[g]??"";if(b==="")return;const _=r.dx+Sw*r.radius*Math.cos(y),S=-r.dy+Sw*r.radius*Math.sin(y);f.push([P(_/(o/2)),P(S/(l/2)),b,{size:P((Number.isFinite(u)&&u>0?u:Ow)/l),color:T4}])}),f.length===0?null:JSON.stringify(f)}const gg=.5,C4=.9,v4=1,D4=2,mg={color:"#404040",width:.25},oI=.025,k4=-.0125,Nw=.1;function Aw(t,e,n){const i=l=>[1,3,5].map(a=>Number.parseInt(l.slice(a,a+2),16)),[r,s]=[i(t),i(e)];if([...r,...s].some(l=>!Number.isFinite(l)))return t;const o=Math.max(0,Math.min(1,n));return`#${r.map((l,a)=>Math.round(l+(s[a]-l)*o).toString(16).padStart(2,"0")).join("")}`}function lI(t,e,n){const[i,r,s]=[t[0],t[1]??t[0],t[2]??t[0]];return e>=0?Aw(r,i,n[1]>0?e/n[1]:0):Aw(r,s,n[0]<0?e/n[0]:0)}function R4(t){const e=[...t].sort((a,c)=>a-c),n=a=>{const c=a.length/2;return a.length%2===1?a[Math.floor(c)]:(a[c-1]+a[c])/2},i=Math.ceil(e.length/2),[r,s]=[n(e.slice(0,i)),n(e.slice(e.length-i))],o=1.5*(s-r),l=e.filter(a=>a>=r-o&&a<=s+o);return[l[0],r,n(e),s,l.at(-1)??s]}function L4(t,e){if(!(e!==null&&e.side>0))return{};const i=C4+(t==="HeatMapChart"?D4:v4);return{chartSize:P(Math.max(0,e.disc-i)/e.side)}}function P4(t){return{chartBorderColor:(typeof t.cy_borderColor=="string"?t.cy_borderColor:mg.color).toLowerCase(),chartBorderWidth:P(gg*(Number(t.cy_borderWidth??mg.width)||0))}}function x4(t,e,n,i,r){const s=typeof t.cy_type=="string"?t.cy_type:"GROUPED",o=s==="STACKED";return{chartKind:o?"stacked-bar":"bar",chartValues:e.join(" "),chartColors:e.map((l,a)=>M4(s,n,l,a,i)).join(" "),chartMin:i[0],chartMax:i[1],chartHorizontal:o?!r:r,chartMargin:oI,chartGap:P(Math.max(0,Math.min(1,Number(t.cy_separation??0)||0)))}}function M4(t,e,n,i,r){return t==="HEAT_STRIPS"?lI(e,n,r):t==="UP_DOWN"?e[n>=0?0:e.length-1].toLowerCase():e[Math.min(i,e.length-1)].toLowerCase()}function U4(t,e,n,i,r){const s=n.filter(h=>Number.isFinite(h));if(s.length===0||i.length===0)return{};const o=Array.isArray(e.cy_range)?e.cy_range.map(Number):[],l=e.cy_globalRange!==!1&&o.length===2&&o.every(h=>Number.isFinite(h)),a=[Math.min(0,...s),Math.max(0,...s)];a[1]+=Nw*(a[1]-a[0]);const c=l?[o[0],o[1]]:a,d=e.cy_orientation==="HORIZONTAL",u=L4(t,r),f=P4(e);switch(t){case"BarChart":Object.assign(u,f,x4(e,s,i,c,d));break;case"LineChart":Object.assign(u,{chartKind:"line",chartValues:s.join(" "),chartColors:i[0].toLowerCase(),chartMin:c[0],chartMax:P(c[1]+(l?Nw*(c[1]-c[0]):0)),chartMargin:k4,chartLineWidth:P(gg*(Number(e.cy_lineWidth??1)||0))});break;case"BoxChart":Object.assign(u,f,{chartKind:"box",chartValues:R4(s).map(P).join(" "),chartColors:`${i[0].toLowerCase()} #000000`,chartMin:c[0],chartMax:c[1],chartHorizontal:d,chartMargin:oI,chartLineWidth:P(gg*mg.width)});break;case"HeatMapChart":{const h=d?[...s].reverse():s;Object.assign(u,{chartKind:"cells",chartValues:h.join(" "),chartColors:h.map(p=>lI(i,p,c)).join(" "),chartHorizontal:!d});break}}return u}const aI="EDGE_STACKING_DENSITY",G4="EDGE_STACKING",yg="EDGE_LABEL_AUTOROTATE";function j4(t,e){return new Map([...t].filter(([n])=>n!==e))}const cI=.5;function Of(t,e){const n=Array.from({length:t.nodeCount},(c,d)=>{const u=[e.width?.[d],e.height?.[d]].filter(f=>typeof f=="number");return u.length===0?null:Math.max(...u)}),i=Array.from({length:t.nodeCount},(c,d)=>{const[u,f,h]=[e.width?.[d],e.height?.[d],e.borderWidth?.[d]];return typeof u=="number"&&typeof f=="number"?[u,f,typeof h=="number"?h:0]:null}),r=t.nodes.byRole("position"),s=r?.meta.extra?.yAxis==="down",o=Array.from({length:t.nodeCount},(c,d)=>{const u=r?.isSet(d)===!0?r.value(d):null;return u===null?null:[u[0],s?u[1]:-u[1]]}),{src:l,dst:a}=t.edgeList();return{source:l,target:a,nodeSize:n,nodeBox:i,nodeAt:o}}const F4=50,dI=new Map([["NODE_FILL_COLOR","NODE_PAINT"],["NODE_BORDER_PAINT","NODE_PAINT"],["NODE_WIDTH","NODE_SIZE"],["NODE_HEIGHT","NODE_SIZE"],["EDGE_UNSELECTED_PAINT","EDGE_PAINT"],["EDGE_STROKE_UNSELECTED_PAINT","EDGE_UNSELECTED_PAINT"],["EDGE_SOURCE_ARROW_UNSELECTED_PAINT","EDGE_UNSELECTED_PAINT"],["EDGE_TARGET_ARROW_UNSELECTED_PAINT","EDGE_UNSELECTED_PAINT"]]);function z4(t,e){for(let n=e;n!==void 0;n=dI.get(n)){const i=t.get(n);if(i!=null)return i}}function uI(t,e){const n=new Set;for(const r of e)if(r)for(const s of r.keys())n.add(s);for(const[r,s]of t.bypassAliases)n.has(r)&&n.add(s);for(const[r,s]of dI)n.has(s)&&n.add(r);return{used:new Set([...t.defaults.keys(),...t.mappings.keys(),...n]),bypassed:n}}function fI(t,e,n){const i=new Map;for(const[r,s]of Zy[t]){const o=s.find(([l])=>n.has(l));o!==void 0&&i.set(r,o)}return t==="node"&&e.dependencies.get("nodeSizeLocked")===!0&&(i.delete("width"),i.delete("height")),t==="edge"&&e.dependencies.get("arrowColorMatchesEdge")===!0&&((n.has("EDGE_UNSELECTED_PAINT")||n.has("EDGE_STROKE_UNSELECTED_PAINT"))&&i.set("color",["EDGE_UNSELECTED_PAINT",Uo]),i.delete("sourceArrowColor"),i.delete("targetArrowColor")),i}function hI(t,e,n,i){switch(t.kind){case"passthrough":return{kind:"passthrough",column:t.column};case"discrete":{const r=[];for(const[s,o]of t.table){const l=e(o,n);l!==null&&r.push([s,l])}return{kind:"discrete",column:t.column,table:r}}default:{const r=V1(i),s=W4(t.points,e,n);return{kind:"continuous",column:t.column,points:s,...r===void 0?{}:{step:r}}}}}function W4(t,e,n){const i=[];for(const s of t){const o=e(s.below,n),l=e(s.value,n),a=e(s.above,n);o!==null&&l!==null&&a!==null&&i.push({at:s.at,below:o,value:l,above:a})}i.sort((s,o)=>s.at-o.at);const r=[];for(const s of i)r.at(-1)?.at===s.at?r[r.length-1]=s:r.push(s);return r}function B4(t,e,n,i){if(e==null)return null;switch(t.kind){case"passthrough":return Array.isArray(e)?null:n(e,i);case"discrete":{const r=S1(t.table)(e);return r<0?null:t.table[r][1]}default:return bf(t.points,oc(e),t.step)}}function Tw(t,e,n,i,r){const s=n.bypasses??[],o=new Map,l=u=>({notes:i,target:t,property:u,budget:r}),a=(u,f)=>{const h=s[u];if(!h)return;const p=h.get(f);if(p!=null)return p;for(const[g,m]of e.bypassAliases)if(m===f&&!h.has(m))return h.get(g);return z4(h,f)},c=(u,f,h)=>{const p=e.mappings.get(u);if(p===void 0)return;const g=`${u}\0${h}`;let m=o.get(g);if(m===void 0){const y=p.kind==="discrete"?p.table.length:0;r?.spend(t,1+y+(p.kind==="continuous"?p.points.length:0)),m=hI(p,f,l(h),u),o.set(g,m)}return m};return{bypass:a,one:(u,f,h,p)=>{const g={notes:i,target:t,property:h,element:p,budget:r},m=a(p,u),y=m==null?null:f(m,g);if(y!==null)return y;const b=c(u,f,h),_=b===void 0?null:B4(b,n.value(b.column,p),f,g);return _!==null?_:e.defaults.has(u)?f(e.defaults.get(u),l(h)):null}}}function nb(t,e,n,i={}){const r=i.notes??new se,s=e[t],o=n.count,{used:l,bypassed:a}=uI(s,n.bypasses??[]),c=fI(t,s,l),{one:d,bypass:u}=Tw(t,s,n,r,i.budget),f={},h=(p,g,m)=>{i.budget?.spend(t,o);const y=new Array(o);for(let b=0;b<o;b++)y[b]=d(p,g,m,b);return y};for(const[p,[g,m]]of c)f[p]=h(g,m,p);if(t==="node"&&s.dependencies.get("nodeSizeLocked")===!0){const p=h(Zo,Zr,"width").map(m=>m??F4),g=(m,y)=>p.map((b,_)=>{const S=u(_,m);return(S==null?null:Zr(S,{notes:r,target:t,property:y,element:_}))??b});f.width=g("NODE_WIDTH","width"),f.height=g("NODE_HEIGHT","height")}if(H4(t,f,d,o,n.ends),t==="node"){Z4(f);const p=g=>typeof g=="string"||typeof g=="number"?String(g):typeof g=="object"&&g!==null?JSON.stringify(g):null;_4(f,o,(g,m)=>{const y=d(g,p,"pieColors",m);return typeof y=="string"&&y.startsWith("{")?JSON.parse(y):y},(g,m)=>n.value(g,m),s.dependencies.get("nodeCustomGraphicsSizeSync")!==!1)}if(t==="edge"&&s.dependencies.get("arrowColorMatchesEdge")===!0&&!l.has("EDGE_UNSELECTED_PAINT")&&l.has("EDGE_STROKE_UNSELECTED_PAINT")){const p=vr("cytoscape-fallbacks")?.edge.color?.value??null;f.color=Array.from({length:o},(g,m)=>d("EDGE_UNSELECTED_PAINT",Uo,"color",m)??p)}if(t==="edge"&&s.dependencies.get("arrowColorMatchesEdge")===!0&&f.color!==void 0){const p=c.get("color")?.[0],g=Tw(t,s,{...n,bypasses:[]},r,i.budget).one,m=p==="EDGE_LINE_COLOR"?Array.from({length:o},(b,_)=>g(p,Uo,"color",_)):f.color;f.sourceArrowColor=m.slice(),f.targetArrowColor=m.slice();const y=[["color","EDGE_STROKE_UNSELECTED_PAINT"],["sourceArrowColor","EDGE_SOURCE_ARROW_UNSELECTED_PAINT"],["targetArrowColor","EDGE_TARGET_ARROW_UNSELECTED_PAINT"],["sourceArrowColor","EDGE_SOURCE_ARROW_COLOR"],["targetArrowColor","EDGE_TARGET_ARROW_COLOR"]];for(const[b,_]of y)f[b]=(f[b]??[]).map((S,T)=>{const $=u(T,_),D={notes:r,target:t,property:b,element:T};return($==null?null:Uo($,D))??S})}if(lG(t,s,l,a,r),t==="edge"){const p=h(ib,sG,"bends");p.some(m=>m!==null)&&(f.bends=p);const g=f.curved?.slice();eG(f,d,o,n.ends),rG(f,d,g,n.ends),Q4(f,h)}return pI(t,f,o,i.defaults??null),f}const Nf=t=>typeof t=="string"||typeof t=="number"||typeof t=="boolean"?String(t):typeof t=="object"&&t!==null?JSON.stringify(t):null;function H4(t,e,n,i,r){const s=c=>`${t==="node"?"NODE":"EDGE"}_LABEL_${c}`,o={},l=(c,d,u)=>{let f=o[c];f===void 0&&(f=new Array(i).fill(null),o[c]=f),f[d]=u};for(let c=0;c<i;c++){V4(s,n,c,l);const d=n(s("POSITION"),Nf,"labelPlace",c),u=typeof d=="string"&&d.startsWith("{")?JSON.parse(d):d,f=B1(u,{notes:new se,target:t,property:"labelPosition"});f!==null&&K4(t,f,c,e,l,r),t==="edge"&&X4(n,c,e,i,r)}const a=(c,d)=>d!==null&&d!==0&&(d!=="center"||c==="labelPosition"&&t==="edge");for(const[c,d]of Object.entries(o))d.some(u=>a(c,u))&&(e[c]=d)}function V4(t,e,n,i){const r=e(t("BACKGROUND_SHAPE"),Nf,"labelBackgroundShape",n);if(typeof r!="string"||r.trim().toUpperCase()==="NONE")return;i("labelBackground",n,e(t("BACKGROUND_COLOR"),Uo,"labelBackground",n)??"#b6b6b6");const[s,o]=[t("BACKGROUND_TRANSPARENCY"),t("BACKGROUND_OPACITY")],l=e(s,sw(s),"labelBackgroundOpacity",n)??e(o,sw(o),"labelBackgroundOpacity",n);if(i("labelBackgroundOpacity",n,l??1),r.trim().toUpperCase().replace("-","_")==="ROUND_RECTANGLE"){const a=e(t("FONT_SIZE"),Zr,"labelSize",n),c=t("FONT_SIZE").startsWith("EDGE")?10:12;i("labelCornerRadius",n,P(Y4*(typeof a=="number"?a:c)))}}const Y4=.1455;function K4(t,e,n,i,r,s){let o;if(t==="node"){const[l,a]=[i.width?.[n],i.height?.[n]];o=y5(e,typeof l=="number"?l:0,typeof a=="number"?a:0),r("labelPosition",n,Jy(e))}else{const[l,a]=q4(s,n,e.node[0]);o={offset:[l+e.offset[0],a+e.offset[1]],shift:[fu(e.label[0]),fu(e.label[1])]},r("labelPosition",n,"center")}r("labelOffsetX",n,P(o.offset[0])),r("labelOffsetY",n,P(o.offset[1])),r("labelShiftX",n,o.shift[0]),r("labelShiftY",n,o.shift[1]),r("labelTextAlign",n,e.justify)}function X4(t,e,n,i,r){const s=t(yg,Nf,"labelRotation",e),[o,l]=[r?.source[e],r?.target[e]],[a,c]=[o===void 0?null:r?.nodeAt?.[o],l===void 0?null:r?.nodeAt?.[l]];if(String(s).toLowerCase()!=="true"||!a||!c||a[0]===c[0]&&a[1]===c[1])return;const d=Math.atan2(c[1]-a[1],c[0]-a[0])*180/Math.PI;let u=d;d>90?u=d-180:d<=-90&&(u=d+180),n.labelRotation??=new Array(i).fill(null);const f=n.labelRotation,h=f[e];f[e]=P(((u+(typeof h=="number"?h:0))%360+360)%360)}function q4(t,e,n){const[i,r]=[t?.source[e],t?.target[e]],[s,o]=[i===void 0?null:t?.nodeAt?.[i],r===void 0?null:t?.nodeAt?.[r]];if(n===0||s===null||s===void 0||o===null||o===void 0)return[0,0];const l=Math.hypot(o[0]-s[0],o[1]-s[1]);if(l===0)return[0,0];const[a,c]=[(o[0]-s[0])/l,(o[1]-s[1])/l],d=p=>{const g=p===void 0?null:t?.nodeBox?.[p];if(g==null)return 0;const[m,y]=[g[0]/2,g[1]/2];return m===0||y===0?0:m*y/Math.hypot(y*a,m*c)},u=d(i),f=l-d(r),h=(n<0?u:f)-(u+f)/2;return[a*h,c*h]}const J4=Math.sqrt(3)/2;function Z4(t){const{shape:e,height:n}=t;if(e===void 0||n===void 0||!e.includes("hexagon"))return;const i=t.borderWidth;t.height=n.map((r,s)=>{if(e[s]!=="hexagon"||typeof r!="number")return r;const o=i?.[s],l=typeof o=="number"?Math.min(o,r):0;return(r-l)*J4+l})}function Q4(t,e){const n=t.arrowSize,i=e("EDGE_SOURCE_ARROW_SIZE",lg,"sourceArrowSize").map(r=>r??1);i.some((r,s)=>r!==(n?.[s]??1))&&(t.sourceArrowSize=i);for(const[r,s,o]of[["sourceArrowLength","EDGE_SOURCE_ARROW_SHAPE","length"],["targetArrowLength","EDGE_TARGET_ARROW_SHAPE","length"],["sourceArrowWidth","EDGE_SOURCE_ARROW_SHAPE","width"],["targetArrowWidth","EDGE_TARGET_ARROW_SHAPE","width"]]){const l=e(s,o5(o),r).map(a=>a===1?null:a);l.some(a=>a!==null)&&(t[r]=l)}for(const[r,s]of[["sourceArrowGap","EDGE_SOURCE_ARROW_SHAPE"],["targetArrowGap","EDGE_TARGET_ARROW_SHAPE"]]){const o=e(s,l5,r).map(l=>l===0?null:l);o.some(l=>l!==null)&&(t[r]=o)}}function eG(t,e,n,i){const r=t.curved??new Array(n).fill(null),s=p=>e(ib,rb,"curved",p)===!0,o=p=>String(e(G4,Nf,"fanned",p)??"").toUpperCase()==="HAYSTACK",l=i===void 0?new Map:tG(i,r.length,s,o),a=new Set(l.keys()),c=p=>a.has(p)||s(p),d=r.map((p,g)=>p===null?c(g)?!0:null:p===!0||a.has(g)?c(g):p);if((t.curved!==void 0||d.includes(!0))&&(t.curved=d),i?.nodeSize===void 0||a.size===0)return;const{source:u,target:f,nodeSize:h}=i;t.fanSpacing=r.map((p,g)=>{const m=Math.max(h[u[g]]??Number.NaN,h[f[g]]??Number.NaN);if(t.curved?.[g]!==!0||!a.has(g)||s(g)||!Number.isFinite(m))return null;const y=e(aI,Zr,"fanSpacing",g),b=Math.min(1,typeof y=="number"?y:cI);return m*b}),iG(t,i,l)}function tG(t,e,n,i){const r=new Map,s=new Map;for(const o of nG(e,t.created?.edge)){const[l,a]=[t.source[o],t.target[o]];if(l===a||i(o))continue;const c=`${Math.min(l,a)},${Math.max(l,a)}`,d=s.get(c);d===void 0?s.set(c,{f:o,k:0}):n(d.f)||(d.k++,r.set(o,d.k))}return r}function nG(t,e){const n=Array.from({length:t},(i,r)=>r);return n.sort(e===void 0?(i,r)=>r-i:(i,r)=>e[r]-e[i]),n}function iG(t,e,n){const{created:i,nodeAt:r,source:s,target:o}=e,l=t.fanSpacing?.slice();if(i===void 0||r===void 0||l===void 0)return;const a=t.bends?.slice()??new Array(s.length).fill(null),c=t.bendCurve?.slice()??new Array(s.length).fill(null);let d=!1;for(const[u,f]of n){const[h,p]=[s[u],o[u]],[g,m,y]=[r[h],r[p],l[u]];if(g==null||m===null||m===void 0||typeof y!="number")continue;const b=Math.hypot(m[0]-g[0],m[1]-g[1]);if(b===0)continue;const _=i.node[h]>i.node[p]?1:-1,[S,T]=[_*(m[0]-g[0])/b,_*(m[1]-g[1])/b],$=Math.ceil(f/2)*(f%2===0?1:-1)*2*y,[D,x]=[$*T,-$*S],R=(D*(m[1]-g[1])-x*(m[0]-g[0]))/(b*b);a[u]=`0.5,${String(Math.round(R*1e6)/1e6||0)}`,c[u]="bezier",l[u]=null,d=!0}d&&(t.bends=a,t.bendCurve=c,t.fanSpacing=l)}function rG(t,e,n,i){const r=i?.nodeBox;if(i===void 0||r===void 0)return;const s=t.bends?.slice()??new Array(i.source.length).fill(null),o=t.curved?.slice()??new Array(i.source.length).fill(null),l=new Map,a=d=>String(Math.round(d*1e4)/1e4||0);let c=!1;for(let d=i.source.length-1;d>=0;d--){const u=i.source[d],f=r[u];if(u!==i.target[d]||s[d]!==null)continue;const h=l.get(u)??0;if(l.set(u,h+1),f==null||f[0]<=0||f[1]<=0)continue;const p=e(aI,Zr,"fanSpacing",d),g=Math.min(1,typeof p=="number"?p:cI),m=(h+3)*(Math.max(f[0],f[1])+f[2])/2*2*g;s[d]=`${a(-m/(f[0]/2))},0 0,${a(m/(f[1]/2))}`,o[d]=n?.[d]!==!1,c=!0}c&&(t.bends=s,t.curved=o)}const ib="EDGE_BEND",rb=t=>{if(typeof t=="string"){const e=t.trim();return e!==""&&e!=='""'}return Array.isArray(t)?t.length>0:t!=null&&typeof t=="object"},sG=(t,e)=>{const n=Array.isArray(t)?t.map(r=>{const s=r??{};return`${Number(s.sin)},${Number(s.cos)},${Number(s.ratio)}`}).join("|"):t;if(typeof n!="string"||!rb(n))return null;const i=[];for(const r of n.trim().split("|")){const[s,o,l]=r.split(",").map(c=>Number(c.trim()));if(![s,o,l].every(c=>Number.isFinite(c)))return H(e,v.BAD_VALUE,n.slice(0,64)),null;const a=c=>String(Math.round(c*1e4)/1e4||0);i.push(`${a(l*s)},${a(-l*o)}`)}return i.join(" ")},oG=/NullCustomGraphics|^255$|^0(?:\.0+)?$|^$|^C,C,c,0\.00,0\.00$|^false$/;function lG(t,e,n,i,r){for(const s of n){if(!_5(s))continue;const o=e.defaults.get(s),l=typeof o=="string"||typeof o=="number"||typeof o=="boolean"?String(o):"";oG.test(l.slice(0,64))&&!e.mappings.has(s)&&!i.has(s)||r.add(v.NOT_CARRIED,t,s,{sample:l})}}function pI(t,e,n,i){const r=i===null?null:vr(i);if(r!==null)for(const[s,o]of Object.entries(r[t])){if(o===void 0||!Jo(t,s,o.value))continue;const l=o.value,a=e[s]===void 0?new Array(n).fill(null):e[s].slice();for(let c=0;c<n;c++)a[c]??=l;e[s]=a}}function gI(t,e){const n=t.network.defaults,i=n.get("NETWORK_BACKGROUND_PAINT")??n.get("NETWORK_BACKGROUND_COLOR");if(i===void 0)return null;const r=Uo(i,{notes:e??new se,target:"graph",property:"background"});return typeof r=="string"?r:null}function mI(t,e,n={}){const i=n.notes??new se,r=oo(),s={count:e.length,value:n.value??(()=>null),bypasses:e.map(l=>l?.has(yg)===!0?j4(l,yg):l),ends:n.ends},o=nb(t,r,s,{notes:i,budget:n.budget});if(t==="node"&&o.width===void 0){const l=e.map(a=>{const c=a?.get(Zo);return c===void 0?null:Zr(c,{notes:i,target:t,property:"width"})});l.some(a=>a!==null)&&(o.width=l,o.height=l.slice())}for(const l of e)if(l)for(const[a,c]of l)a.startsWith("?")&&i.add(v.NOT_CARRIED,t,a.slice(1),{sample:c});return pI(t,o,e.length,n.defaults??null),o}function yI(t,e,n,i={}){const r=i.notes??new se,s=i.columnRef??(b=>({data:b})),o=e[t],{used:l}=uI(o,n.bypasses??[]),a=fI(t,o,l),c=b=>({notes:r,target:t,property:b,budget:i.budget}),d=t==="node"&&o.dependencies.get("nodeSizeLocked")===!0,u=t==="edge"&&o.dependencies.get("arrowColorMatchesEdge")===!0,f=aG(o,a,c,{locked:d,matched:u}),h=new Map,p=new Map,g={target:t,refOf:s,elements:n,columns:h,notes:r,budget:i.budget},m=(b,_,S)=>{const T=o.mappings.get(_);if(T===void 0)return;const $=hI(T,S,c(b[0]),_),D=cG($,b[0],S,g),x=`${T.kind}\0${T.column}`;let R=p.get(x);R===void 0&&(R={id:`${t}.${T.kind}.${T.column}`,map:{}},p.set(x,R));for(const G of b)R.map[G]=D};for(const[b,[_,S]]of a)m(u&&b==="color"?["color","sourceArrowColor","targetArrowColor"]:[b],_,S);d&&m(["width","height"],Zo,Zr);const y=[];Object.keys(f).length>0&&y.push({id:`${t}.defaults`,target:t,role:"defaults",origin:"declared",where:{all:!0},set:f});for(const b of p.values())y.push({id:b.id,target:t,role:"mapping",origin:"declared",where:{all:!0},map:b.map});return{rules:y,columns:h}}function aG(t,e,n,i){const r={};for(const[s,[o,l]]of e){const a=t.defaults.has(o)?l(t.defaults.get(o),n(s)):null;a!==null&&(r[s]=a)}if(i.locked){const s=t.defaults.has(Zo)?Zr(t.defaults.get(Zo),n("width")):null;r.width=s??50,r.height=s??50}return i.matched&&r.color!==void 0&&(r.sourceArrowColor=r.color,r.targetArrowColor=r.color),r.curved===!0&&rb(t.defaults.get(ib),n("curved"))!==!0&&(r.curved=!1),r}function cG(t,e,n,i){const{target:r,elements:s,columns:o,notes:l,budget:a}=i,c=i.refOf(t.column);if(t.kind==="discrete")return{kind:"discrete",by:c,table:t.table};if(t.kind==="continuous")return{kind:"continuous",by:c,points:t.points,...t.step===void 0?{}:{step:t.step}};const d="style"in c?dG:_l(r,e),u=s.count;a?.spend(r,u);const f=new Array(u);let h=!0;for(let g=0;g<u;g++){const m=s.value(t.column,g),y=m==null||Array.isArray(m)?null:n(m,{notes:l,target:r,property:e,element:g});f[g]=y,h&&y!==(m==null||Array.isArray(m)?null:d(m))&&(h=!1)}if(h)return{kind:"passthrough",by:c};const p=`cytoscape.${e}`;return o.set(p,f),{kind:"passthrough",by:{style:p}}}function dG(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:null}const Ht="xgmml",uG=Object.freeze([".xgmml",".xml"]),fG=Object.freeze(["application/xgmml","text/xgmml","text/xgmml+xml"]),_a="http://www.cs.rpi.edu/XGMML",bI="http://www.cytoscape.org",sb="http://www.w3.org/1999/xlink",EI="xgmml",Ys="label",Qo="id",Tl="position",lo="z",Qt="graphics",cc="parent",Af="parents",Ks="xgmml.subgraph",dc="cytoscape.nestedNetwork",el="xgmml.networkPointer",Sa="xgmml.networks",Jl="interaction",pn="xgmml",Tf="cytoscape",j=Object.freeze({...xn,...Pn,XML_SYNTAX:Ku,XML_NESTING:Xu,EMPTY_INPUT:Ut,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,ENCODING_CONFLICT:hl,NO_GRAPH:ls,VIEW_DOCUMENT:"E_XGMML_VIEW_DOCUMENT",MISSING_ID:dt,ID_FROM_LABEL:"W_XGMML_ID_FROM_LABEL",ID_AND_HREF:"W_XGMML_ID_AND_HREF",MISSING_ENDPOINT:Zn,UNKNOWN_NODE:"E_UNKNOWN_NODE",LABEL_ALIAS:"W_XGMML_LABEL_ALIAS",DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,GROUP_DUPLICATE_EDGE:"W_XGMML_GROUP_DUPLICATE_EDGE",BAD_DIRECTED:"W_XGMML_BAD_DIRECTED",DOCUMENT_VERSION:"W_XGMML_DOCUMENT_VERSION",NO_NAMESPACE:"W_XGMML_NO_NAMESPACE",BAD_ATT:"W_XGMML_BAD_ATT",AMPERSAND_REPAIRED:"W_XGMML_AMPERSAND_REPAIRED",SURROGATE_PAIRED:"W_XGMML_SURROGATE_PAIRED",EMPTY_LIST_TYPE:"W_XGMML_EMPTY_LIST_TYPE",RECORD_LIST:"W_XGMML_RECORD_LIST",CROSS_FILE_REFERENCE:"W_XGMML_CROSS_FILE_REFERENCE",EDGE_NESTED_GRAPH:"W_XGMML_EDGE_NESTED_GRAPH",ROOT_ONLY_ELEMENTS:"W_XGMML_ROOT_ONLY_ELEMENTS",BAD_VALUE:ie,WIDENED:fa,PRECISION:re,DANGLING_REFERENCE:Xi,DUPLICATE_ATTRIBUTE:fe,UNKNOWN_PARENT:Ui,PARENT_CYCLE:pl,EQUATION_AS_TEXT:WL,UNKNOWN_ATTR_TYPE:Zt,UNKNOWN_ELEMENT:vt,STRAY_TEXT:qu,MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,COLUMN_RENAMED:ln,ROLE_TAKEN:bn,ID_MERGED:Rn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or}),un=Object.freeze({JSON_AS_STRING:"W_XGMML_JSON_AS_STRING",WIDENED_TYPE:"W_XGMML_WIDENED_TYPE",XML_ILLEGAL_CHAR:Yd,TEMPORAL_DROPPED:NA,TEMPORAL_TEXT_DROPPED:$A,ROLE_DROPPED:oy,PARENTS_DROPPED:ly,MUTUAL_EXPANDED:AA,ID_TEXT_TYPE:cs,EDGE_ID_TEXT:"W_XGMML_EDGE_ID_TEXT",BACKSLASH_ESCAPE:"W_XGMML_BACKSLASH_ESCAPE",POSITION:"W_XGMML_POSITION",PARENT_CYCLE:"W_XGMML_PARENT_CYCLE",COLUMN_NAME_CHANGED:vA,ROLE_ASSUMED:Qa,WEIGHT_KEY_CLASH:CA,STORAGE_CLASS_CHANGED:DA,INTERACTION_FROM_LABEL:"W_XGMML_INTERACTION_FROM_LABEL"});function wI(t){for(const e of t){const{origin:n}=e.meta;if(e.dtype==="json"&&n?.type==="graphics"&&n.namespace===pn)return e.meta.name}return t.get(Qt)?.dtype==="json"?Qt:null}function _I(t,e,n,i){const r=new Array(n).fill(null),s=wI(t);if(s===null)return r;for(let o=0;o<n;o++){const l=K(t.value(s,o));if(l===null||typeof l!="object"||Array.isArray(l))continue;const a=cg(e,l,i),c=Object.hasOwn(l,"lockedVisualProperties")?l.lockedVisualProperties:void 0;if(c!==null&&typeof c=="object")for(const[d,u]of cg(e,c,i))a.set(d,u);r[o]=a.size>0?a:null}return r}function SI(t,e,n){const i=new se,r={node:{values:{}},edge:{values:{}}};for(const s of["node","edge"]){e.signal?.throwIfAborted();const o=s==="node"?t.nodes:t.edges,l=s==="node"?t.nodeCount:t.edgeCount,a=_I(o,s,l,i),c=a.some(d=>d!==null)?mI(s,a,{notes:i,budget:e.budget,value:(d,u)=>o.has(d)?K(o.value(d,u)):null,...s==="edge"?{ends:Of(t,r.node.values)}:{}}):{};hG(t,s,r.node.values,c,n),ob(t,s,c),r[s]={values:lb(c)}}return{canonical:!0,dialect:"cytoscape",tool:n.tool,units:"px",node:r.node,edge:r.edge,graph:AI(t,i),notes:i.list()}}function hG(t,e,n,i,r){const s=e==="node"?t.nodes:t.edges,o=e==="node"?t.nodeCount:t.edgeCount,l=r.tool==="cytoscape";e==="edge"&&l&&pG(t,i),OI(s,r.hiddenColumn??null,o,i),NI(t,e,n,i),e==="node"&&l&&i.label===void 0&&!t.graph.has(Z)&&gG(s,o,i)}function pG(t,e){const{bends:n}=e,i=t.nodes.byRole("position");if(n===void 0||i===null)return;const r=l=>{const a=i.isSet(l)?i.value(l):null;return a===null?null:[a[0],a[1]]},{src:s,dst:o}=t.edgeList();e.bends=n.map((l,a)=>{const[c,d]=[r(s[a]),r(o[a])];if(typeof l!="string"||c===null||d===null)return l;const u=l.trim().split(/\s+/).length;return Al(c,d,Array.from({length:u},()=>[0,0]),!1)??l})}function gG(t,e,n){const i=t.byRole("label")?.meta.name??null,r=(o,l)=>{const a=o!==null&&t.has(o)?K(t.value(o,l)):null;return typeof a=="string"||typeof a=="number"?String(a):null},s=Array.from({length:e},(o,l)=>r("name",l)??r(i,l));s.some(o=>o!==null)&&(n.label=s)}function mG(t,e){return SI(t,e,{tool:"cytoscape"})}function ob(t,e,n,i="desktop",r){const s=t.graph.has(Z)?K(t.graph.value(Z,0)):null;typeof s=="string"&&so(t,s,"xgmml",(o,l)=>{if(o!==e)return null;const a=e==="node"?t.nodeCount:t.edgeCount,c=Array.from({length:a},(f,h)=>tb(e,p=>l(e,p)[h]??null,i,()=>{})),d=e==="edge"?{ends:{...Of(t,{width:l("node","width"),height:l("node","height"),borderWidth:l("node","borderWidth")}),...r===void 0?{}:{created:r}}}:{},u=mI(e,c,{notes:new se,...d});return{values:n,properties:Object.keys(n).filter(f=>n[f]!==void 0&&u[f]!==void 0),readBack:f=>h=>u[h]?.[f]??null,take:(f,h)=>h!==null||yG.has(f)}})}const yG=new Set(["fanSpacing","curved","bends","bendCurve","labelOffsetX","labelOffsetY","labelShiftX","labelShiftY"]);function OI(t,e,n,i){if(e===null||!t.has(e))return;let r=null;for(let s=0;s<n;s++)K(t.value(e,s))===!0&&(r??=i.visible===void 0?new Array(n).fill(null):[...i.visible],r[s]=!1);r!==null&&(i.visible=r)}function bG(t,e){const n=t.nodes.byRole("parent");if(n===null||t.graph.has(Z))return;const i=t.nodeCount,r=wG(n,i);if(r.size===0)return;const s=t.meta.extra?.xgmml?.graphId,o=e.visible===void 0?new Array(i).fill(null):[...e.visible];for(const[l,a]of r){if(!SG(t,l,s)){o[l]=!1;continue}for(const c of _G(l,a,r))o[c]=!1}e.visible=o}function NI(t,e,n,i){e==="node"?bG(t,i):EG(t,n,i)}function EG(t,e,n){const i=e.visible;if(i===void 0||!i.includes(!1)||t.graph.has(Z))return;const{src:r,dst:s}=t.edgeList(),o=n.visible===void 0?new Array(r.length).fill(null):[...n.visible];for(let l=0;l<r.length;l++)(i[r[l]]===!1||i[s[l]]===!1)&&(o[l]=!1);n.visible=o}function wG(t,e){const n=new Map;for(let i=0;i<e;i++){const r=t.isSet(i)?K(t.value(i)):null;typeof r=="number"&&r!==i&&n.set(r,[...n.get(r)??[],i])}return n}function _G(t,e,n){const i=[...e],r=new Set([t]),s=new Set;for(let o=i.pop();o!==void 0;o=i.pop())r.has(o)||(r.add(o),s.add(o),i.push(...n.get(o)??[]));return s}function SG(t,e,n){if(typeof n!="string"||!t.nodes.has(Ks))return!1;const i=K(t.nodes.value(Ks,e)),r=i!==null&&typeof i=="object"?i.atts:null,s=r!==null&&typeof r=="object"?r["__groupCollapsed.SUID"]:null;return Array.isArray(s)&&s.some(o=>String(o)===n)}function lb(t){const e={};for(const[n,i]of Object.entries(t))i?.some(r=>r!==null)===!0&&(e[n]=i);return e}function AI(t,e,n){const i=oo();for(const[s,o]of n?.network.defaults??[])i.network.defaults.set(s,o);for(const[s,o]of OG(t,e))i.network.defaults.set(s,o);const r=gI(i,e);return r===null?{}:{background:r}}function OG(t,e){const n=wI(t.graph),i=n===null?null:K(t.graph.value(n,0));if(i===null||typeof i!="object"||Array.isArray(i))return[];const r=Object.hasOwn(i,"lockedVisualProperties")?i.lockedVisualProperties:void 0;return[i,r].flatMap(s=>[...cg("node",s,e)].filter(([o])=>o.startsWith("NETWORK_")))}const TI=Object.freeze({tool:"cytoscape",node:Object.freeze(gu("node","desktop")),edge:Object.freeze(gu("edge","desktop")),graph:Object.freeze(["background"]),block:"attributes"}),NG={node:[["NODE_SHAPE","type"],["NODE_HEIGHT","h"],["NODE_WIDTH","w"],["NODE_FILL_COLOR","fill"],["NODE_BORDER_WIDTH","width"],["NODE_BORDER_PAINT","outline"]],edge:[["EDGE_WIDTH","width"],["EDGE_STROKE_UNSELECTED_PAINT","fill"]]};function II(t,e,n,i){const r=tb(t,o=>e.picture(t,o)[n]??null,"desktop",()=>{}),s={};for(const[o,l]of NG[t])r.has(o)&&(s[l]=String(r.get(o)));for(const[o,l]of Object.entries(i??{}))(o==="Line"||/^[A-Z][A-Z_0-9]+$/.test(o)&&!r.has(o))&&(s[o]=l);for(const[o,l]of r)s[o]=String(l);return Object.keys(s).length===0?null:s}function AG(t,e){const n=new se;for(const i of["node","edge"]){const r=i==="node"?e.nodeCount:e.edgeCount;for(let s=0;s<r;s++)tb(i,o=>t.picture(i,o)[s]??null,"desktop",o=>{n.add(v.APPROXIMATED,i,o,{element:s})})}return n.list().map(cb)}function TG(t,e){const{background:n}=t.rules.styles.graph,i={...e};return n!==void 0&&(i.NETWORK_BACKGROUND_PAINT=n.toUpperCase()),Object.keys(i).length===0?null:i}function $I(t){const e=t?.[0];if(e===null||typeof e!="object"||!Object.hasOwn(e,"block"))return null;const n=e.block;return typeof n=="string"?n:null}function CI(t){return[{block:t}]}function ab(t){const e=t.graph.get(Z),n=e?.isSet(0)?e.value(0):null;return typeof n=="string"?n:null}function IG(t,e,n){const i=[...t].filter(s=>s.meta.origin?.namespace===n),r=new Array(e).fill(null);for(let s=0;s<e;s++){let o=null;for(const l of i){const a=K(l.isSet(s)?l.value(s):null);if(a!==null){o??=new Map;const c=l.meta.origin?.id;o.set(typeof c=="string"&&c.length>0?c:l.meta.name,a)}}r[s]=o}return{maps:r,names:i.map(s=>s.meta.name)}}function $G(t,e,n,i){const{notes:r}=i;X1(t[e],s=>n.has(s)),e==="edge"&&q1(t.edge,i.weightFrom,n),i.dialect!=="cx2"&&J1(t[e],s=>n.get(s)?.meta.origin?.type??null,r,e);for(const s of t[e].mappings.values())!n.has(s.column)&&!(e==="edge"&&i.weights!==null&&s.column===i.weightFrom)&&r.add(v.MAPPING_COLUMN_MISSING,e,s.column,{sample:s.kind})}function CG(t,e){if(e===null||t.edges.has(e)||t.edges.byRole("weight")!==null)return null;const n=Ot(t);return n.weighted?n:null}function Iw(t){const e=t.map(o=>typeof o=="string"&&/^\d{1,15}$/.test(o)?Number(o):o);if(!e.every(o=>typeof o=="number"&&Number.isSafeInteger(o)&&o>=0))return null;let n=16;for(;e.length>.75*n;)n*=2;const i=o=>{const l=(o%4294967296^Math.floor(o/4294967296))>>>0;return(l^l>>>16)&n-1},r=e.map((o,l)=>l).sort((o,l)=>i(e[o])-i(e[l])||o-l),s=new Array(e.length);return r.forEach((o,l)=>{s[o]=l}),s}function vG(t){const e=t.edges.byRole("id");if(e===null)return null;const n=Iw(Array.from({length:t.nodeCount},(r,s)=>t.ids.idOf(s))),i=Iw(Array.from({length:t.edgeCount},(r,s)=>e.value(s)));return n===null||i===null?null:{node:n,edge:i}}function vI(t,e,n,i,r,s="desktop",o={}){const l=o.weightFrom??null,a=o.hashOrder===!0?vG(t)??void 0:void 0,c={node:{values:{}},edge:{values:{}}},d={node:[],edge:[]};for(const f of["node","edge"]){e.signal?.throwIfAborted();const h=f==="node"?t.nodes:t.edges,p=f==="node"?t.nodeCount:t.edgeCount,g=f==="edge"?CG(t,l):null;$G(n,f,h,{notes:r,dialect:s,weightFrom:l,weights:g});const{maps:m,names:y}=IG(h,p,i);d[f]=y;const b={count:p,value:($,D)=>g!==null&&$===l?g.isExplicit(D)?g.value(D):null:h.has($)?K(h.value($,D)):null,bypasses:m,...f==="edge"?{ends:{...Of(t,c.node.values),...a===void 0?{}:{created:a}}}:{}},_=nb(f,n,b,{notes:r,budget:e.budget});ob(t,f,_,s,a);const{rules:S,columns:T}=yI(f,n,b,{notes:r,budget:e.budget});c[f]={values:lb(_),rules:S,columns:T}}const u=gI(n,r);return{canonical:!0,dialect:"cytoscape",tool:"cytoscape",units:"px",node:c.node,edge:c.edge,graph:u===null?{}:{background:u},notes:r.list(),readFrom:d}}function DG(t,e){const n=new se,i=e.kept,r=z5(i?.entries??[],n),s=i?.otherViews??0;return s>0&&n.add(v.OTHER_VIEWS,null,"cyVisualProperties",{sample:`${s} more`,count:s}),vI(t,e,r,"cx.bypass",n,"desktop",{weightFrom:i?.weightFrom??null,hashOrder:i?.collection!==!0})}function DI(t){return Object.freeze({tool:"cytoscape",node:Object.freeze(gu("node",t)),edge:Object.freeze(gu("edge",t)),graph:Object.freeze(["background"]),block:"attributes"})}const kG=DI("desktop");function RG(t){const e=new Set(t.filter(n=>n!==null).map(n=>typeof n));return e.size===1&&e.has("number")?"f64":e.size===1&&e.has("boolean")?"bool":"string"}function cb(t){return Object.freeze({code:t.code,message:t.message,column:null,count:t.params.count,style:t.params.target===null||t.params.property===null||t.params.target==="graph"?void 0:Object.freeze({target:t.params.target,property:t.params.property})})}function If(t,e,n){if(e===void 0)return null;const i=new se,r=nI(e.rules,t,{dialect:n,notes:i});return{snapshot:LG(t,r),styled:r,notes:i.list().map(cb)}}function LG(t,e){const n=["node","edge"].flatMap(r=>[...e.columns[r]].filter(([s])=>!(r==="node"?t.nodes:t.edges).has(s)).map(([s,o])=>({target:r,name:s,values:o})));if(n.length===0)return t;const i=t.withColumns();for(const{target:r,name:s,values:o}of n){const l=RG(o),a=l==="string"?o.map(c=>c===null?null:String(c)):o;(r==="node"?i.nodes:i.edges).set(s,a,{dtype:l})}return i}const PG=DI("cx2");function xG(t,e){const n=new se,i=e.kept,r=H5(i?.visualProperties,i?.visualEditorProperties,n);return vI(t,e,r,"cx2.bypass",n,"cx2",{weightFrom:i?.weightFrom??null})}const Bt="cx2",kt="graphty:originalId",kI="cx2.bypass",ye=Object.freeze({...xn,...Pn,EMPTY_INPUT:Ut,SYNTAX:kn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,NO_DESCRIPTOR:"E_CX2_NO_DESCRIPTOR",VERSION:"E_CX2_VERSION",MINOR_VERSION:"W_CX2_MINOR_VERSION",NO_STATUS:"E_CX2_NO_STATUS",STATUS_FAILED:Vd,STATUS_WARNING:ry,UNDECLARED_FRAGMENTS:"W_CX2_UNDECLARED_FRAGMENTS",DECLARATION_CONFLICT:"E_CX2_DECLARATION_CONFLICT",UNDECLARED_ATTRIBUTE:"W_CX2_UNDECLARED_ATTRIBUTE",RESERVED_KEY:"W_CX2_RESERVED_KEY",ALIAS_CONFLICT:"E_CX2_ALIAS_CONFLICT",NETWORK_DECLARATION:"W_CX2_NETWORK_DECLARATION",EXTRA_ELEMENTS:"W_CX2_EXTRA_ELEMENTS",PARTIAL_LAYOUT:"W_CX2_PARTIAL_LAYOUT",ALIAS_BYPASSED:"W_CX2_ALIAS_BYPASSED",LEGACY_LAYOUT:"W_CX2_LEGACY_LAYOUT",SINGLE_OBJECT_ASPECT:OA,MULTI_ASPECT_FRAGMENT:iy,JSON_NONSTANDARD_NUMBER:Ju,STYLES_NOT_IMPORTED:to,BAD_ASPECT_BLOCK:mt,ASPECT_ORDER:Bn,COUNT_MISMATCH:Fs,BAD_VALUE:ie,BAD_DEFAULT:Ho,UNKNOWN_ATTR_TYPE:Zt,DANGLING_REFERENCE:Xi,DUPLICATE_ATTRIBUTE:fe,MISSING_ID:dt,MISSING_ENDPOINT:Zn,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,INVALID_ID:"E_INVALID_ID",UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",ID_TEXT_TYPE:cs,PRECISION:re,ID_MERGED:Rn,UNKNOWN_ELEMENT:vt,COLUMN_RENAMED:ln,ROLE_TAKEN:bn,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,TOO_LARGE:gl}),MG=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]),UG={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},RI=64,GG=new Set(["id","x","y","z","v"]),jG=new Set(["id","s","t","v"]),FG=["networkAttributes","visualProperties","visualEditorProperties"],$w=["visualProperties","visualEditorProperties","cyVisualProperties","tableVisualProperties","cyTableVisualProperties"],LI=new Set(["metaData","status"]),zG=new Set(["nodes","edges","attributeDeclarations","networkAttributes","nodeBypasses","edgeBypasses","status","metaData"]),WG=new Map([["string","string"],["long","long"],["integer","integer"],["double","double"],["boolean","boolean"],["str","string"],["int","integer"],["bool","boolean"],["float","double"]]);function mu(t){const e=t.startsWith("list_of_"),n=WG.get(e?t.slice(8):t);return n===void 0?null:{d:e?`list_of_${n}`:n,scalar:n,list:e}}function Cw(t,e){switch(t){case"string":return"string";case"long":return e==="string"?"string":"f64";case"integer":return"i32";case"double":return"f64";case"boolean":return"bool";default:return t}}const Ct=Symbol("bad"),PI=-2147483648,xI=2147483647;function vw(t,e,n,i){switch(e){case"string":return typeof t=="string"?t:Ct;case"boolean":return typeof t=="boolean"?t:Ct;case"double":return t instanceof vn?(i(t.digits),Number(t.digits)):typeof t=="number"?t:Ct;case"integer":return typeof t=="number"&&Number.isInteger(t)&&t>=PI&&t<=xI?t:Ct;case"long":return t instanceof vn?n==="string"?t.digits:(i(t.digits),Number(t.digits)):typeof t=="number"&&Number.isInteger(t)?n==="string"?String(t):t:Ct;default:return Ct}}function Gc(t,e,n,i){if(!e.list)return vw(t,e.scalar,n,i);if(!Array.isArray(t))return Ct;const r=[];for(const s of t){const o=s===null?Ct:vw(s,e.scalar,n,i);if(o===Ct)return Ct;r.push(o)}return r}function Oe(t){if(t instanceof vn)return t.digits;let e;try{e=JSON.stringify(t)??String(t)}catch{e=String(t)}return e.length>60?`${e.slice(0,57)}...`:e}function Dw(t,e,n=1){if(!/\d[.eE]/.test(t))return 0;let i=0;return e.forEach((r,s)=>{u1(t,r,n)&&(i|=1<<s)}),i}async function BG(t,e,n){const i=new p1(e),r={version:"",hasFragments:!1,nodes:[],edges:[],declarations:[],networkAttributes:[],nodeBypasses:[],edgeBypasses:[],cartesianLayout:[],opaque:new Map,structure:i};let s=!1,o=!1,l=0;const a=c1(e,"meta.extra.cx2.opaque"),c=(d,u,f,h,p,g=1)=>{switch(i.element(d,u,h),d){case"nodes":o=!0,r.nodes.push({value:u,line:h,inexact:Dw(f,["id"],g)});return;case"edges":o=!0,r.edges.push({value:u,line:h,inexact:Dw(f,["id","s","t"],g)});return;case"attributeDeclarations":o&&e.warnOnce("validation-error",Bn,"attributeDeclarations comes after the elements it types; the declarations are applied to them",{line:h,element:d},`${Bn}:declarations`),r.declarations.push({value:u,line:h,inexact:0});return;case"networkAttributes":o=!0,r.networkAttributes.push({value:u,line:h,inexact:0});return;case"nodeBypasses":r.nodeBypasses.push({value:u,line:h,inexact:0});return;case"edgeBypasses":r.edgeBypasses.push({value:u,line:h,inexact:0});return;case"cartesianLayout":r.cartesianLayout.push({value:u,line:h,inexact:0});return;default:if(LI.has(d))return;r.opaque.has(d)||r.opaque.set(d,[]),r.opaque.get(d)?.push(p?qe(u,a):u)}};try{for await(const d of l1($r(t,e,n),e))switch(++l>=RI&&(l=0,F(n.signal)),d.kind){case"root":e.fail(ye.NO_DESCRIPTOR,`a CX2 document is a JSON array; found ${d.object?"an object":Oe(d.value)}`,{line:d.line});break;case"member":if(!s){kw(d.value,d.line,r,e),s=!0;break}VG(d.value,d.line,i,e,(u,f)=>{c(u,f,d.text,d.line,d.exact,2)});break;case"block":d1(e,d),s||e.fail(ye.NO_DESCRIPTOR,`the document starts with a "${d.aspect}" block, not a descriptor with CXVersion${d.aspect==="numberVerification"||d.aspect==="metaData"?"; this looks like CX version 1 (read it with the cx importer)":""}`,{line:d.line}),i.block(d.aspect,d.line);break;case"element":c(d.aspect,d.value,d.text,d.line,d.exact);break;case"deep":a1(e,d),s||kw(null,d.line,r,e);break;case"extraKeys":e.error("parse-error",mt,`the "${d.aspect}" block holds more keys (${d.keys.join(", ")}) whose values are not arrays; an aspect block has one key, the others are skipped`,{line:d.line,element:d.aspect});break;default:break}}catch(d){throw d instanceof et&&e.fail(d.empty?Ut:kn,d.message,{line:d.line}),d}return s||e.fail(ye.NO_DESCRIPTOR,"the document is an empty array; a CX2 document starts with a descriptor"),r}function HG(t,e,n){const i=M(t)?Object.keys(t):[],r=i.length>0?` (keys: ${i.join(", ")})`:"";return n.fail(ye.NO_DESCRIPTOR,`the first member of the array is not a descriptor with CXVersion${r}`,{line:e})}function kw(t,e,n,i){(!M(t)||!("CXVersion"in t))&&HG(t,e,i);const r=t.CXVersion,s=typeof r=="string"||typeof r=="number"?String(r):"",o=/^\s*(\d+)(?=$|[.\s-])/.exec(s),l=o===null?Number.NaN:Number(o[1]);l===1&&i.fail(ye.VERSION,`CXVersion ${Oe(r)} is CX version 1, a different document shape; read it with the cx importer`,{line:e,element:"CXVersion"}),l!==2&&i.fail(ye.VERSION,`CXVersion ${Oe(r)} is not a CX2 version`,{line:e,element:"CXVersion"}),n.version=s,r!=="2.0"&&i.warning("validation-error",ye.MINOR_VERSION,`CXVersion ${Oe(r)} is not "2.0"; the document is read as CX2 2.0`,{line:e,element:"CXVersion"});for(const a of Object.keys(t))a==="hasFragments"?typeof t.hasFragments=="boolean"?n.hasFragments=t.hasFragments:i.error("validation-error",ie,`hasFragments is ${Oe(t.hasFragments)}, not a boolean; read as false`,{line:e,element:"hasFragments"}):a!=="CXVersion"&&i.warning("validation-error",vt,`the descriptor key "${a}" is not defined`,{line:e,element:a})}function VG(t,e,n,i,r){const s=M(t)?Object.keys(t):[];if(M(t)&&s.length===1&&M(t[s[0]])){zG.has(s[0])&&i.warning("validation-error",ye.SINGLE_OBJECT_ASPECT,`the "${s[0]}" aspect is one object, not an array of elements; read as one element`,{line:e,element:s[0]}),n.block(s[0],e),r(s[0],t[s[0]]);return}const o=s.length>1?`an object with ${s.length} keys (${s.join(", ")})`:Oe(t);i.error("parse-error",mt,`a member of the document is ${o}, not a one-key aspect block; skipped`,{line:e,element:s[0]??null})}function Rw(t){switch(typeof t){case"boolean":return"boolean";case"string":return"string";case"number":return Number.isInteger(t)&&t>=PI&&t<=xI?"integer":"double";default:return t instanceof vn?"double":null}}function Lw(t,e){return t===void 0||t===e?e:t===null||e===null?null:t==="integer"&&e==="double"||t==="double"&&e==="integer"?"double":null}function Pw(t,e){const n=Array.isArray(e);if(t.list!==void 0&&t.list!==n){t.kind=null;return}if(t.list=n,!n){t.kind=Lw(t.kind,Rw(e));return}for(const i of e)t.kind=Lw(t.kind,i===null||Array.isArray(i)?null:Rw(i))}function xw(t){if(t.kind===null)return null;const e=t.kind??"string";return mu(t.list===!0?`list_of_${e}`:e)}class Rh{constructor(){this.byName=new Map,this.byAlias=new Map}resolve(e){const n=this.byAlias.get(e);if(n!==void 0)return{decl:n,viaAlias:!0};const i=this.byName.get(e);return i===void 0?null:{decl:i,viaAlias:!1}}}const YG=new Map([["nodes","node"],["edges","edge"],["networkAttributes","network"]]);function Lh(t,e){return Object.hasOwn(t,e)}class KG{constructor(e,n,i,r,s){this.decls={node:new Rh,edge:new Rh,network:new Rh,other:{}},this.nodeRows=new Map,this.sinkIds=new Map,this.restored=new Set,this.edgeRows=new Map,this.positionHandle=A,this.zHandle=A,this.edgeIdHandle=A,this.positioned=new Set,this.sinceCheck=0,this.idType="integer",this.weighted=!1,this.dangling=new Map,this.point=[0,0,0],this.sink=e,this.report=n,this.options=i,this.zAs=r,this.doc=s,this.direction=new ei(e,n,i.onMixedDirection),this.coercer=new Mn(i.ids)}build(){const{doc:e,report:n}=this;this.direction.setHeader(!0),this.readDeclarations(),this.declareColumns(),this.sink.reserve(e.nodes.length,e.edges.length);for(const i of e.nodes)this.readNode(i);this.readLegacyLayout(),this.positioned.size>0&&this.positioned.size<this.nodeRows.size&&n.warnOnce("missing-value",ye.PARTIAL_LAYOUT,`${this.nodeRows.size-this.positioned.size} of ${this.nodeRows.size} node${O(this.nodeRows.size)} ${C(this.nodeRows.size-this.positioned.size,"has","have")} no coordinates; their positions are unset`,{element:"nodes"});for(const i of e.edges)this.readEdge(i);this.readNetworkAttributes(),this.readBypasses("node",e.nodeBypasses),this.readBypasses("edge",e.edgeBypasses);for(const[i,r]of this.dangling)n.warning("validation-error",Xi,`${r} ${i}${O(r)} ${C(r,"names","name")} no element; ignored`,{element:i});this.checkAspects(),this.setMeta()}readDeclarations(){const{report:e}=this;for(const n of this.doc.declarations){if(!M(n.value)){e.error("parse-error",mt,"an attributeDeclarations element is not an object",{line:n.line,element:"attributeDeclarations"});continue}for(const[i,r]of Object.entries(n.value)){const s=YG.get(i);if(s===void 0){e.warning("unsupported",vt,`attributeDeclarations holds the table "${i}", which CX2 does not define; kept in meta.extra.cx2.declarations, not applied`,{line:n.line,element:i}),Gy(this.decls.other,i,qe(r,o=>{this.precision(i,o)}));continue}if(!M(r)){e.error("validation-error",ie,`the ${i} declarations are not an object; ignored`,{line:n.line,element:i});continue}for(const[o,l]of Object.entries(r))this.declare(s,o,l,n.line)}}for(const n of["node","edge"])this.checkAliases(n);this.inferUndeclared("node",this.doc.nodes),this.inferUndeclared("edge",this.doc.edges)}inferUndeclared(e,n){const i=this.decls[e],r=new Map;for(const{value:s}of n)if(!(!M(s)||!M(s.v)))for(const[o,l]of Object.entries(s.v)){const a=i.resolve(o);if(o===""||a!==null&&a.decl.type!==null||l===null||l===void 0)continue;const c=a?.decl.name??o;let d=r.get(c);d===void 0&&(d={kind:void 0,list:void 0},r.set(c,d)),Pw(d,l)}for(const[s,o]of r){const l=xw(o),a=i.byName.get(s);if(a!==void 0){a.type=l,a.hasDefault&&l!==null&&(a.defaultValue=this.convertDefault(s,a.rawDefault,l,{element:s}),a.hasDefault=a.defaultValue!==Ct);continue}i.byName.set(s,{name:s,type:l,alias:null,hasDefault:!1,defaultValue:void 0,rawDefault:void 0,handle:A,undeclared:!0})}}declare(e,n,i,r){const{report:s}=this,o=this.decls[e],l={line:r,element:n};if(n===""){s.error("validation-error",ie,`a ${e} attribute declaration has an empty name; ignored`,l);return}if(!M(i)){s.error("validation-error",ie,`the declaration of "${n}" is not an object; ignored`,l);return}let a;i.d===void 0?(a=mu("string"),s.warning("unsupported",Zt,`the declaration of "${n}" has no type; read as string (the Java reader's rule)`,l)):(a=typeof i.d=="string"?mu(i.d):null,a===null&&s.warning("unsupported",Zt,`the type ${Oe(i.d)} of "${n}" is not a CX2 type; the column is inferred from its values`,l));const c=o.byName.get(n);if(c!==void 0){c.type?.d!==a?.d&&s.error("validation-error",ye.DECLARATION_CONFLICT,`"${n}" is declared ${c.type?.d??"untyped"} and again ${a?.d??"untyped"}; the first declaration wins`,l);return}i.a!==void 0&&i.a!==null&&typeof i.a!="string"&&s.error("validation-error",ie,`the alias ${Oe(i.a)} of "${n}" is not a string; ignored`,l);let d=typeof i.a=="string"?i.a:null,u=i.v!==void 0&&i.v!==null;e==="network"&&(i.a!==void 0||i.v!==void 0)&&(s.warning("validation-error",ye.NETWORK_DECLARATION,`the network attribute "${n}" declares an alias or a default, which CX2 forbids; ignored`,l),d=null,u=!1);let f;u&&a!==null&&(f=this.convertDefault(n,i.v,a,l),u=f!==Ct),o.byName.set(n,{name:n,type:a,alias:d,hasDefault:u,defaultValue:f,rawDefault:u&&a===null?qe(i.v):void 0,handle:A,undeclared:!1})}convertDefault(e,n,i,r){const s=Gc(n,i,this.options.long,l=>{this.precision(e,l)});if(s!==Ct)return s;const o=i.scalar==="double"||i.scalar==="integer"||i.scalar==="long";if(!i.list&&o&&typeof n=="string"&&n.trim()!==""&&Number.isFinite(Number(n))){const l=Gc(Number(n),i,this.options.long,()=>{});if(l!==Ct)return this.report.warning("validation-error",Ho,`the default ${Oe(n)} of "${e}" is a string, not a ${i.d}; read as ${Oe(l)}`,r),l}return this.report.warning("validation-error",Ho,`the default ${Oe(n)} of "${e}" is not a ${i.d}; the column has no default`,r),Ct}checkAliases(e){const n=this.decls[e];for(const i of n.byName.values()){const{alias:r}=i;if(r===null||r===i.name){r!==null&&n.byAlias.set(r,i);continue}const s=n.byName.get(r)??n.byAlias.get(r);if(s!==void 0){const o=s.name===r?"an attribute's name":`the alias of "${s.name}"`;this.report.error("validation-error",ye.ALIAS_CONFLICT,`the alias "${r}" of the ${e} attribute "${i.name}" is also ${o}; the alias is ignored`,{element:i.name}),i.alias=null;continue}n.byAlias.set(r,i)}}declareColumns(){const e=this.options.restoreMangledIds;for(const n of["node","edge"])for(const i of this.decls[n].byName.values()){if(n==="node"&&e&&i.name===kt||n==="edge"&&i.name===this.options.weightFrom)continue;const r=i.type===null?{name:i.name,dtype:"json",nullable:!0,origin:{format:Bt,id:i.alias}}:{...this.columnDecl(i.type),name:i.name,origin:{format:Bt,id:i.alias,type:i.type.d}};i.hasDefault&&(r.default=i.type===null?i.rawDefault:i.defaultValue),n==="node"&&i.name==="name"&&(r.role="label"),i.handle=he(this.sink,n,r,this.report).handle}}edgeIdColumn(){if(this.edgeIdHandle===A){const e=n=>this.sink.edgeColumn(n)!==A;this.edgeIdHandle=he(this.sink,"edge",{name:Xt("id","cx2",e),dtype:"f64",role:"id",nullable:!0},this.report).handle}return this.edgeIdHandle}columnDecl(e){const n=Cw(e.scalar,this.options.long);return e.list?{name:"",dtype:"list",itemDtype:n,nullable:!0}:{name:"",dtype:n,nullable:!0}}idOf(e,n,i,r,s=!1){let o;try{const l=au(e,n);l.note==="text"?this.report.warnOnce("coercion",cs,`${i}: the id ${Oe(e)} is not written as an integer; read as ${String(l.id)}`,{line:r,element:i}):l.note==="precision"&&s?this.report.warnOnce("precision",re,`${i}: the edge id ${String(l.id)} is beyond 2^53; the id column holds the nearest double`,{line:r,element:i},`${re}:edge`):l.note==="precision"&&(this.idType="mixed",this.report.warnOnce("precision",re,`${i}: the id ${String(l.id)} is beyond 2^53; kept as its digits (a string id)`,{line:r,element:i})),o=this.options.ids==="keep"?l.id:this.coercer.value(l.id)}catch(l){return this.report.recordError(l,{line:r,element:i}),null}return o}checkAbort(){++this.sinceCheck>=RI&&(this.sinceCheck=0,F(this.options.signal))}unknownKeys(e,n,i,r){for(const s of Object.keys(e))n.has(s)||this.report.warnOnce("unsupported",vt,`the ${i} key "${s}" is not defined by CX2; its values are not read`,{line:r,element:s},`${vt}:${i}:${s}`)}readNode(e){this.checkAbort();const{report:n,sink:i}=this,{value:r,line:s}=e;if(!M(r)){n.error("parse-error",mt,`a nodes element is ${Oe(r)}, not an object`,{line:s,element:"nodes"}),n.counts.skippedNodes++;return}if(this.unknownKeys(r,GG,"node",s),r.id===void 0||r.id===null){n.error("missing-value",dt,"a node has no id",{line:s,element:"nodes"}),n.counts.skippedNodes++;return}const o=`node ${Oe(r.id)}`,l=this.idOf(r.id,(e.inexact&1)!==0,o,s);if(l===null){n.counts.skippedNodes++;return}const a=M(r.v)?r.v:null;r.v!==void 0&&r.v!==null&&a===null&&n.error("validation-error",ie,`${o}: v is ${Oe(r.v)}, not an object`,{line:s,element:o});let c=this.nodeRows.get(l);if(c!==void 0)n.warning("merged",sn,`${o} is declared more than once; its attributes are merged (the later values win)`,{line:s,element:o});else{let d=this.originalIdOf(a,o,s);d!==null&&this.restored.has(d)&&(n.warning("merged",sn,`${o}: its original id ${Oe(d)} is already another node's; it keeps its CX id`,{line:s,element:o}),d=null),d!==null&&this.restored.add(d),this.idTypeOf(d??l);try{c=i.addNode(d??l)}catch(u){n.recordError(u,{line:s,element:o}),n.counts.skippedNodes++;return}this.nodeRows.set(l,c),this.sinkIds.set(l,d??l),n.counts.nodes++}this.readCoordinates(r,c,o,s),a!==null&&this.writeAttributes("node",c,a,o,s)}originalIdOf(e,n,i){if(e===null||!this.options.restoreMangledIds)return null;const r=this.decls.node.byName.get(kt)?.alias??null,s=e[kt]??(r===null?void 0:e[r]);return s!=null&&typeof s!="string"&&this.report.error("validation-error",ie,`${n}: ${kt} is ${Oe(s)}, not a string; the node keeps its CX id`,{line:i,element:n}),typeof s=="string"?s:null}idTypeOf(e){typeof e=="string"&&this.idType==="integer"&&(this.idType="mixed")}readCoordinates(e,n,i,r){const s=c=>{const d=e[c];return d==null?null:typeof d=="number"?d:(this.report.error("validation-error",ie,`${i}: ${c} is ${Oe(d)}, not a number`,{line:r,element:i}),null)},o=s("x"),l=s("y"),a=s("z");o===null!=(l===null)&&this.report.warnOnce("missing-value",ye.PARTIAL_LAYOUT,`${i} has ${o===null?"y without x":"x without y"}; its coordinates are dropped`,{line:r,element:i},`${ye.PARTIAL_LAYOUT}:half`),a!==null&&o===null&&l===null&&this.report.warnOnce("missing-value",ye.PARTIAL_LAYOUT,`${i} has z without x and y; ${this.zAs==="column"?"z is kept in the z column":"with no position, z is dropped"}`,{line:r,element:i},`${ye.PARTIAL_LAYOUT}:z`),o!==null&&l!==null&&(!Number.isFinite(o)||!Number.isFinite(l))?this.report.error("validation-error",ie,`${i}: the coordinates ${String(o)}, ${String(l)} are not both finite; the position is unset`,{line:r,element:i}):o!==null&&l!==null&&this.setPosition(n,o,l,a),a!==null&&this.zAs==="column"&&(this.zHandle===A&&(this.zHandle=he(this.sink,"node",Qp(Bt),this.report).handle),this.sink.setNodeValue(this.zHandle,n,a))}setPosition(e,n,i,r){this.positionHandle===A&&(this.positionHandle=he(this.sink,"node",f1(Bt,this.zAs==="position"?3:2),this.report).handle),this.point[0]=n,this.point[1]=Bo(i),this.point[2]=this.zAs==="position"&&r!==null?r:0,this.sink.setNodeValue(this.positionHandle,e,this.point),this.positioned.add(e)}readLegacyLayout(){const{cartesianLayout:e}=this.doc;if(e.length===0)return;if(this.positioned.size>0){this.doc.opaque.set("cartesianLayout",e.map(r=>qe(r.value))),this.report.warning("unsupported",ye.LEGACY_LAYOUT,`a CX1 cartesianLayout aspect (${e.length} element${O(e.length)}) next to node coordinates; the node coordinates are used, the aspect is kept in meta.extra.cx2`,{element:"cartesianLayout"});return}let n;const i=new Set;for(const r of e){const s=r.value;if(!M(s)||typeof s.x!="number"||typeof s.y!="number"){this.report.error("validation-error",ie,"a cartesianLayout element has no numeric x and y; skipped",{line:r.line,element:"cartesianLayout"});continue}const o=this.rowOf(this.nodeRows,s.node);if(o===void 0){this.dangle("cartesianLayout entry");continue}if(n??=s.view??null,(s.view??null)!==n){this.doc.opaque.set("cartesianLayout",e.map(a=>qe(a.value))),this.report.warnOnce("validation-error",fe,`the cartesianLayout aspect names several views; view ${Oe(n)} is read, the aspect is kept in meta.extra.cx2`,{line:r.line,element:"cartesianLayout"},`${fe}:layout:view`);continue}i.has(o)&&this.report.warnOnce("validation-error",fe,`node ${Oe(s.node)} has two cartesianLayout entries; the later wins`,{line:r.line,element:"cartesianLayout"},`${fe}:layout`),i.add(o);const l=typeof s.z=="number"?s.z:null;this.setPosition(o,s.x,s.y,l),l!==null&&this.zAs==="column"&&(this.zHandle===A&&(this.zHandle=he(this.sink,"node",Qp(Bt),this.report).handle),this.sink.setNodeValue(this.zHandle,o,l))}}rowOf(e,n){try{const{id:i}=au(n);return e.get(this.options.ids==="keep"?i:this.coercer.value(i))}catch{return}}dangle(e){this.dangling.set(e,(this.dangling.get(e)??0)+1)}writeAttributes(e,n,i,r,s){const{report:o}=this,l=this.decls[e];for(const a of Object.keys(i)){const c=i[a];if(a===""){o.error("validation-error",ie,`${r}: v holds an attribute with an empty name; skipped`,{line:s,element:r});continue}const d=l.resolve(a),u=d?.decl.name??a;if(e==="node"&&this.options.restoreMangledIds&&u===kt||e==="edge"&&u===this.options.weightFrom)continue;if(a==="id"&&o.warnOnce("validation-error",ye.RESERVED_KEY,`${r}: the attribute name "id" is reserved in v; read as an ordinary attribute`,{line:s,element:r},`${ye.RESERVED_KEY}:${e}`),d!==null&&!d.viaAlias&&d.decl.alias!==null&&d.decl.alias!==a){if(Lh(i,d.decl.alias)){o.warning("validation-error",fe,`${r}: "${u}" is given under its alias and its full name; the alias wins`,{line:s,element:r});continue}o.warnOnce("coercion",ye.ALIAS_BYPASSED,`${r}: the full name "${u}" is used although its alias "${d.decl.alias}" is declared; read as the same attribute`,{line:s,element:r},`${ye.ALIAS_BYPASSED}:${e}:${u}`)}if(c==null||d===null)continue;const{decl:f}=d;f.undeclared&&o.warnOnce("validation-error",ye.UNDECLARED_ATTRIBUTE,`the ${e} attribute "${a}" is not declared; its type is inferred from the values`,{line:s,element:a},`${ye.UNDECLARED_ATTRIBUTE}:${e}:${a}`);const h=f.type===null?qe(c,p=>{this.precision(u,p)}):Gc(c,f.type,this.options.long,p=>{this.precision(u,p)});if(h===Ct){o.error("validation-error",ie,`${r}: "${u}" is ${Oe(c)}, not a ${f.type?.d??"value"}; the cell is unset`,{line:s,element:r});continue}try{e==="node"?this.sink.setNodeValue(f.handle,n,h):this.sink.setEdgeValue(f.handle,n,h)}catch(p){o.recordError(p,{line:s,element:r})}}}precision(e,n){this.report.warnOnce("precision",re,`"${e}": ${n} is beyond 2^53; stored as the nearest double`,{element:e},`${re}:value`)}readEdge(e){this.checkAbort();const{report:n,sink:i}=this,{value:r,line:s}=e;if(!M(r)){n.error("parse-error",mt,`an edges element is ${Oe(r)}, not an object`,{line:s,element:"edges"}),n.counts.skippedEdges++;return}if(this.unknownKeys(r,jG,"edge",s),r.id===void 0||r.id===null){n.error("missing-value",dt,"an edge has no id",{line:s,element:"edges"}),n.counts.skippedEdges++;return}const o=`edge ${Oe(r.id)}`;for(const y of["s","t"])if(r[y]===void 0||r[y]===null){n.error("missing-value",Zn,`${o} has no ${y}`,{line:s,element:o}),n.counts.skippedEdges++;return}const l=this.idOf(r.id,(e.inexact&1)!==0,o,s,!0),a=l===null?null:this.idOf(r.s,(e.inexact&2)!==0,o,s),c=a===null?null:this.idOf(r.t,(e.inexact&4)!==0,o,s);if(l===null||a===null||c===null){n.counts.skippedEdges++;return}if(this.edgeRows.has(l)){n.error("validation-error",Ai,`${o} is declared more than once; the later edge is skipped`,{line:s,element:o}),n.counts.skippedEdges++;return}const d=this.endpoint(a,o,s),u=d===null?null:this.endpoint(c,o,s);if(d===null||u===null){n.counts.skippedEdges++;return}const f=M(r.v)?r.v:null;r.v!==void 0&&r.v!==null&&f===null&&n.error("validation-error",ie,`${o}: v is ${Oe(r.v)}, not an object`,{line:s,element:o});let h;const p=this.weightKey(f);try{h=p===null||f===null?void 0:of(qe(f[p]))}catch(y){n.recordError(y,{line:s,element:o}),n.counts.skippedEdges++;return}h!==void 0&&(this.weighted=!0);const g=i.edgeCount;let m;try{m=this.direction.addEdge(d,u,"directed",h,{line:s,element:o})}catch(y){n.recordError(y,{line:s,element:o}),n.counts.skippedEdges++;return}n.counts.edges+=i.edgeCount-g,this.edgeRows.set(l,m),i.setEdgeValue(this.edgeIdColumn(),m,typeof l=="number"?l:Number(l)),f!==null&&this.writeAttributes("edge",m,f,o,s)}weightKey(e){const{weightFrom:n}=this.options;if(n===null||e===null)return null;const i=this.decls.edge.byName.get(n)?.alias??null;return i!==null&&Lh(e,i)?i:Lh(e,n)?n:null}endpoint(e,n,i){const r=this.sinkIds.get(e);if(r!==void 0)return r;if(!this.options.addMissingNodes)return this.report.error("missing-value",ye.UNKNOWN_NODE,`${n}: the endpoint ${String(e)} is not a node; the edge is skipped`,{line:i,element:n}),null;try{this.nodeRows.set(e,this.sink.addNode(e))}catch(s){return this.report.recordError(s,{line:i,element:n}),null}return this.sinkIds.set(e,e),this.report.counts.nodes++,e}readNetworkAttributes(){const{networkAttributes:e}=this.doc;if(e.length===0)return;e.length>1&&this.report.warning("validation-error",ye.EXTRA_ELEMENTS,`networkAttributes holds ${e.length} elements; the first is read`,{line:e[1].line,element:"networkAttributes"});const{value:n,line:i}=e[0];if(!M(n)){this.report.error("parse-error",mt,"the networkAttributes element is not an object",{line:i,element:"networkAttributes"});return}for(const[r,s]of Object.entries(n)){if(s==null)continue;const o=this.decls.network.byName.get(r),l=`networkAttributes.${r}`;if(o===void 0&&this.report.warnOnce("validation-error",ye.UNDECLARED_ATTRIBUTE,`the network attribute "${r}" is not declared; its column is inferred from the value`,{line:i,element:r},`${ye.UNDECLARED_ATTRIBUTE}:network:${r}`),!((r==="name"||r==="description")&&typeof s=="string"&&o?.type?.d!=="list_of_string"))try{const a={kind:void 0,list:void 0};Pw(a,s);const c=o?.type??xw(a);if(c===null){this.sink.setGraphValue(r,qe(s,f=>{this.precision(r,f)}),{dtype:"json",origin:{format:Bt,id:null}});continue}const d=Gc(s,c,this.options.long,f=>{this.precision(r,f)});if(d===Ct){this.report.error("validation-error",ie,`${l} is ${Oe(s)}, not a ${c.d}; unset`,{line:i,element:l});continue}const u=Cw(c.scalar,this.options.long);this.sink.setGraphValue(r,d,{dtype:c.list?"list":u,...c.list?{itemDtype:u}:{},origin:{format:Bt,id:null,type:c.d}})}catch(a){this.report.recordError(a,{line:i,element:l})}}}readBypasses(e,n){const i=e==="node"?this.nodeRows:this.edgeRows,r=new Map;for(const s of n){this.checkAbort();const{value:o,line:l}=s;if(!M(o)||!M(o.v)){this.report.error("parse-error",mt,`a ${e}Bypasses element is not an object with an id and a v object; skipped`,{line:l,element:`${e}Bypasses`});continue}const a=this.rowOf(i,o.id);if(a===void 0){this.dangle(`${e} bypass`);continue}for(const[c,d]of Object.entries(o.v)){if(d==null)continue;if(c===""){this.report.error("validation-error",ie,`a ${e}Bypasses element holds a visual property with an empty name; skipped`,{line:l,element:`${e}Bypasses`});continue}let u=r.get(c);u===void 0&&(u={rows:[],values:[],at:new Map},r.set(c,u));const f=qe(d),h=u.at.get(a);if(h===void 0){u.at.set(a,u.rows.length),u.rows.push(a),u.values.push(f);continue}JSON.stringify(u.values[h])!==JSON.stringify(f)&&this.report.warnOnce("validation-error",fe,`a ${e} has the visual property "${c}" in two ${e}Bypasses elements; the later wins`,{line:l,element:c},`${fe}:bypass:${e}:${c}`),u.values[h]=f}}for(const[s,{rows:o,values:l}]of r){const a={name:s,dtype:XG(l),nullable:!0,origin:{format:Bt,id:s,namespace:kI}},c=g1(this.sink,e,a,this.report);for(let d=0;d<o.length;d++)e==="node"?this.sink.setNodeValue(c,o[d],l[d]):this.sink.setEdgeValue(c,o[d],l[d])}}checkAspects(){const{doc:e,report:n}=this,{structure:i}=e,r=[];for(const s of $w){const o=e.opaque.get(s);o!==void 0&&r.push(qG(s,o))}r.length>0&&n.warning("unsupported",to,`the file's style rules are not applied (${r.join("; ")}); they are kept in meta.extra.cx2.opaque`,{element:$w.filter(s=>e.opaque.has(s)).join(",")});for(const s of FG.slice(1)){const o=e.opaque.get(s)?.length??0;o>1&&n.warning("validation-error",ye.EXTRA_ELEMENTS,`${s} holds ${o} elements where CX2 allows one; all are kept, a reader uses the first`,{element:s})}if(!e.hasFragments)for(const[s,o]of i.blocks)o>1&&!LI.has(s)&&n.warnOnce("validation-error",ye.UNDECLARED_FRAGMENTS,`"${s}" comes in ${o} blocks although the descriptor does not declare hasFragments; the blocks are joined in order`,{element:s});this.checkStatus(),i.checkCounts()}checkStatus(){const{report:e}=this,{structure:n}=this.doc;if(!n.hasStatus)e.error("validation-error",ye.NO_STATUS,"the document ends without a status block",{element:"status"});else if(!n.statusWellFormed()||n.counts.get("status")!==1){const i=n.counts.get("status")??0,r=i===1?Oe(n.status):`${i} elements`;e.error("validation-error",ye.NO_STATUS,`the status is malformed (${r}): a document ends with one status block holding one object with a boolean success`,{element:"status"})}}setMeta(){const{doc:e}=this,n=e.networkAttributes[0]?.value,i=M(n)?n:{},r={};e.opaque.size>0&&(r.opaque=Object.fromEntries(e.opaque)),Object.keys(this.decls.other).length>0&&(r.declarations=this.decls.other);const{weightFrom:s}=this.options,o=s===null?void 0:this.decls.edge.byName.get(s),l={sourceFormat:Bt,sourceVersion:e.version,idType:this.idType,...typeof i.name=="string"?{name:i.name}:{},...typeof i.description=="string"?{description:i.description}:{},...this.weighted&&s!==null?{weightOrigin:{format:Bt,id:o?.alias??null,title:s,type:o?.type?.d??null,namespace:null}}:{},extra:{cx2:r}};this.sink.setMeta(l)}}function XG(t){return t.every(e=>typeof e=="number")?"f64":t.every(e=>typeof e=="boolean")?"bool":t.every(e=>typeof e=="string")?"string":"json"}function qG(t,e){const n=e[0];if(t==="visualProperties"&&M(n)){const i=s=>M(n[s])?Object.keys(n[s]).length:0,r=M(n.default)?Object.values(n.default).reduce((s,o)=>s+(M(o)?Object.keys(o).length:0),0):0;return`visualProperties: ${r} default${O(r)}, ${i("nodeMapping")} node mapping${O(i("nodeMapping"))}, ${i("edgeMapping")} edge mapping${O(i("edgeMapping"))}`}return`${t}: ${e.length} element${O(e.length)}`}function MI(t){if(t===void 0)return"column";if(t==="column"||t==="position")return t;throw new N("E_UNSUPPORTED",`option zAs: ${Oe(t)} is not one of "column", "position"`,{option:"zAs",found:typeof t=="string"?t:typeof t})}const JG=Object.freeze({format:Bt,options:Object.freeze(["zAs"]),extensions:Object.freeze([".cx2"]),mimeTypes:Object.freeze(["application/json"]),styles:xG,sniff(t){const e=h1(t);return/^\s*\[\s*\{(?:\s*"[^"]*"\s*:\s*(?:true|false|"[^"]*"|[0-9.]+)\s*,)*\s*"CXVersion"\s*:/.test(e)?.97:0},async import(t,e,n){const i=tt(n,UG),r=MI(n?.zAs),s=new ne(Bt,i.errorLimit);_t(e,n,s,!0),St(n,s,MG);const o=await BG(t,s,i),l=$I(o.opaque.get(Z));o.opaque.delete(Z),new KG(e,s,i,r,o).build(),l!==null&&e.setGraphValue(Z,l,{dtype:"string",origin:{format:Bt,id:null}});const a={visualProperties:o.opaque.get("visualProperties"),visualEditorProperties:o.opaque.get("visualEditorProperties"),weightFrom:i.weightFrom};return s.keepForStyles(a),F(i.signal),s.finish()}}),db="cx",UI=Object.freeze({UNDIRECTED_AS_DIRECTED:"W_CX_UNDIRECTED_AS_DIRECTED",JSON_AS_STRING:"W_CX_JSON_AS_STRING",MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,WEIGHT_KEY_CLASH:w.WEIGHT_KEY_CLASH,TEMPORAL_DROPPED:w.TEMPORAL,ROLE_DROPPED:w.ROLE,ROLE_ASSUMED:w.ROLE_ASSUMED,DTYPE_UNSUPPORTED:w.DTYPE,COMPONENTS_FLATTENED:w.COMPONENTS,DEFAULT_DROPPED:w.DEFAULT,OPTIONS_DROPPED:w.OPTIONS,ID_CHARSET:w.ID_CHARSET,ID_MANGLED:w.ID_MANGLED,EDGE_IDS_GENERATED:w.EDGE_IDS_GENERATED,COLUMN_NAME_CHANGED:w.COLUMN_NAME_CHANGED,EXTENSION_TABLE_DROPPED:w.EXTENSION_TABLE,NONFINITE_AS_NULL:w.NONFINITE_AS_NULL,VIZ_DROPPED:w.VIZ}),GI=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"required",idCharset:"integer",dtypes:["string","f64","i32","bool"],components:!1,lists:!0,json:!1,defaults:!1,options:!1,hierarchy:!0,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),ZG=new Set(["label","position","id"]),Mw=Object.freeze({label:"name",position:jy,id:"id",parent:"parent"}),bg=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness","id"]),QG="cx.bypass",jI=Object.freeze({"cx:citations":"citations","cx:supports":"supports"}),e8=new Set(["nodes","edges","nodeAttributes","edgeAttributes","networkAttributes","cartesianLayout","cyGroups","cyVisualProperties","cyTableColumn","cySubNetworks","cyNetworkRelations","cyViews","CX Element ID","citations","supports","nodeCitations","edgeCitations","nodeSupports","edgeSupports","functionTerms","reifiedEdges","numberVerification","metaData","status","groups","subnetwork",Z]),rr="weight",t8=new Set(["f32","f64","i32","u32","u8"]);function _d(t,e){return t.meta.origin?.format===db&&t.meta.origin.namespace===e}function Ao(t){return t.meta.origin?.namespace===QG}function n8(t){return t.meta.extra.cytoscape==="z"}function FI(t){return _d(t,"provenance")&&t.meta.dtype==="list"&&(t.meta.name==="citations"||t.meta.name==="supports")}function i8(t){const{dtype:e}=t.meta;return e!=="string"&&e!=="dict"&&e!=="json"}function r8(t,e,n,i,r,s){let o=null;const l=t.edges.byRole("label")?.meta.name,a=new Set(i.filter(c=>c!==null).map(c=>c.meta.name));for(const c of Un(t,GI,e,{roles:ZG,roleNames:n?{...Mw,parents:"parents"}:Mw}))if(!s8(c,a)){if(c.code===w.JSON){const d=c.column===null?"a column":`column "${c.column}"`;s(UI.JSON_AS_STRING,`${d} holds nested values; written as a string attribute holding their JSON text`,c.column,c.count);continue}if(o8(c,l)){s(w.ROLE,`edge column "${l??""}" (label) is written as a plain attribute; CX edges have no label slot and the role is lost`,c.column,c.count);continue}c.code===w.MIXED_DIRECTION_ERROR&&o===null&&(o=new N("E_DIRECTED",c.message,{reason:"mixed direction"})),r.push(c)}return l==="name"&&s(w.ROLE,'edge column "name" (label) is written as a plain attribute; CX edges have no label slot and the role is lost',"name",null),o}function s8(t,e){return t.column!==null&&e.has(t.column)&&(t.code===w.JSON||t.code===w.DTYPE)||t.code===w.ID_CHARSET||t.code===w.ID_MANGLED?!0:t.code===w.EXTENSION_TABLE&&t.column!==null&&t.column in jI}function o8(t,e){return t.code===w.COLUMN_NAME_CHANGED&&t.column===e&&t.message.startsWith("edge column")}function l8(t,e){const n=t.nodes.byRole("position"),i=[...t.nodes].find(n8)??null,r=i!==null&&f8(i,n)?i:null;if(n===null)return{position:n,z:r,positionZ:!1,nonfinite:0};let s=xh(n,a=>[a[0],a[1]]);const o=xh(n,a=>a[2]===0?[]:[Number.NaN]),l=i===null&&(n.meta.extra.sourceDims===3||o>0);return l&&(s+=xh(n,a=>Number.isFinite(a[0])&&Number.isFinite(a[1])?[a[2]]:[]),e(w.COMPONENTS,`node column "${n.meta.name}" (position) has a third coordinate; CX writes it as the layout's z, which reads back in the z column (a stacking order), not in the position`,n.meta.name,o)),{position:n,z:r,positionZ:l,nonfinite:s}}function a8(t,e){for(const n of t.graph){const i=n.meta.name==="name"||n.meta.name==="description";!Ao(n)&&i&&(n.dtype==="string"||n.dtype==="dict")&&e(w.ROLE_ASSUMED,`graph column "${n.meta.name}" is written as the network attribute ${n.meta.name}, which reads back as the graph's ${n.meta.name}, not as a column`,n.meta.name,null)}}function zI(t,e){const{notes:n,note:i}=a3(),r=[...t.nodes].find(J=>_d(J,"provenance")&&J.meta.name==="functionTerm")??null,s=[...t.nodes].find(J=>_d(J,"reifiedEdges")&&J.dtype==="u32")??null,o=nc(t),l=o.column?.meta.role==="parents"&&h8(o.column);let a=r8(t,e,l,[r,s],n,i);const c=Gt(t);t1(t,c,e,UI.UNDIRECTED_AS_DIRECTED,i);const d=ZT(t,e,"CX",kt,i),u=d instanceof N?null:d;d instanceof N&&(a??=d);const f=e1(t,i,u);t.nodes.has(kt)&&i(w.ROLE_ASSUMED,`node column "${kt}" is the importer's record of mangled ids: it reads back as the node ids unless restoreMangledIds is false`,kt,null);const h=l8(t,i),{position:p,z:g,positionZ:m}=h;let{nonfinite:y}=h;const b=[...t.nodes].find(J=>_d(J,"cyGroups")&&J.dtype==="bool")??null,_=c8(t,i),S=[],T=t.edges.get("interaction");T!==null&&(T.meta.role===null||!bg.has(T.meta.role))&&(S.push({key:"i",column:T}),Eg(T,"edge",i));const $=new Set([..._,...S].map(J=>J.column)),D=J=>$.has(J)||Ao(J)||FI(J)||J===g||J===b||J===r||J===s||J.meta.role!==null&&bg.has(J.meta.role),x=t.nodes.byRole("label"),R=x!==null&&x.meta.name!=="name"?t.nodes.get("name"):null;R!==null&&i(w.COLUMN_NAME_CHANGED,`node column "name" is written as the attribute "name#2" and reads back as "name#2", because the label column "${x?.meta.name??""}" is written as n and takes the name "name"`,"name",R.length-R.nullCount);const G=Ph(t.nodes,D,J=>J===R?"name#2":J.meta.name),B=d8(t,c,i),Q=t.edges.get(rr),be=Ph(t.edges,J=>D(J)||J===Q&&J.meta.role===null,J=>J.meta.name);y+=B.nonfinite,a8(t,i);const De=Ph(t.graph,J=>Ao(J)||J.meta.name===Z,J=>J.meta.name);return o.column!==null&&o.column.meta.role==="parents"&&!l&&i(w.COLUMN_NAME_CHANGED,`node column "${o.column.meta.name}" (parents) holds at most one parent per node; it reads back as the single-parent column "parent"`,o.column.meta.name,o.column.length-o.column.nullCount),y>0&&i(w.NONFINITE_AS_NULL,`${y} NaN or infinite position${O(y)}, stacking orders or weights cannot be written in CX; they read back unset`,null,y),{notes:n,fatal:a,ids:u,folding:c,edgeIds:f,weight:B.plan,nodeCore:_,edgeCore:S,nodeAttrs:G,edgeAttrs:be,graphAttrs:De,position:p,positionZ:m,z:g,bypass:{node:[...t.nodes].filter(Ao),edge:[...t.edges].filter(Ao),graph:[...t.graph].filter(Ao)},collapsed:b,links:p8(t),functionTerm:r,reifiedEdge:s}}function c8(t,e){const n=[],i=t.nodes.byRole("label"),r=t.nodes.get("name"),s=i??(r!==null&&r.meta.role===null?r:null);s!==null&&(n.push({key:"n",column:s}),Eg(s,"node",e),s!==i&&e(w.ROLE_ASSUMED,'node column "name" is written as n and reads back as the label',"name",s.length-s.nullCount));const o=t.nodes.get("represents");return o!==null&&o!==s&&(o.meta.role===null||!bg.has(o.meta.role))&&(n.push({key:"r",column:o}),Eg(o,"node",e)),n}function Eg(t,e,n){i8(t)&&n(w.DTYPE,`${e} column "${t.meta.name}" is ${t.dtype}; CX writes it as text and it reads back as string`,t.meta.name,t.length-t.nullCount)}function Ph(t,e,n){return[...t].filter(i=>!e(i)).map(i=>({column:i,name:n(i),d:QT(i)}))}function d8(t,e,n){const i=Ot(t),r=t.edges.get(rr),s=r!==null&&r.meta.role===null;let o=null;if(i.weighted)o={value:l=>i.isExplicit(l)?i.value(l):void 0},s&&n(w.WEIGHT_KEY_CLASH,`edge column "${rr}" is not written: the explicit weights are written under that name`,rr,null);else if(s){const l=t8.has(r.dtype);n(w.WEIGHT_KEY_CLASH,l?`edge column "${rr}" is written as the weight attribute and reads back as the edge weight`:`edge column "${rr}" is ${r.dtype}, and CX reads that attribute as the edge weight; it is not written`,rr,null),l&&(o={value:a=>r.isSet(a)?r.value(a):void 0})}return{plan:o,nonfinite:o===null?0:u8(t.edgeCount,o,e)}}function u8(t,e,n){let i=0;for(let r=0;r<t;r++){const s=e.value(r);!n.folded(r)&&s!==void 0&&Number.isNaN(s)&&i++}return i}function f8(t,e){for(let n=0;n<t.length;n++){if(!t.isSet(n))continue;const i=t.value(n),r=e?.isSet(n)===!0?e.value(n):null;if(typeof i!="number"||!Number.isFinite(i)||r===null||!Number.isFinite(r[0])||!Number.isFinite(r[1]))return!1}return!0}function xh(t,e){let n=0;for(let i=0;i<t.length;i++)t.isSet(i)&&e(t.value(i)).some(r=>!Number.isFinite(r))&&n++;return n}function h8(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&t.value(e).length>1)return!0;return!1}function p8(t){const e=[];for(const[n,i]of[["node",t.nodes],["edge",t.edges]])for(const r of i)if(FI(r)){const s=r.meta.name;e.push({aspect:`${n}${s==="citations"?"Citations":"Supports"}`,key:s,domain:n,column:r})}return e}function Oa(t){return typeof t=="number"?Object.is(t,-0)?"-0":String(t):typeof t=="string"?t:typeof t=="boolean"?String(t):JSON.stringify(t)}function Mh(t,e,n){if(!t.isSet(n))return;const i=t.value(n);if(t.meta.dtype==="json")return JSON.stringify(i);if(t.meta.dtype==="list"||t.meta.components>1){const r=Array.from(i);return e==="string"?JSON.stringify(r):r.map(Oa)}return Oa(i)}function Sd(t,e){if(!t.isSet(e))return;const n=t.value(e);return t.meta.dtype==="json"||t.meta.dtype==="list"||t.meta.components>1?JSON.stringify(t.meta.dtype==="json"?n:Array.from(n)):Oa(n)}function g8(t,e){const n=[];for(let i=0;i<t.edgeCount;i++)e.folded(i)||n.push(i);return n}function m8(t,e,n,i){const{src:r,dst:s}=t.edgeList(),o=g8(t,e.folding),l=()=>Array.from({length:t.nodeCount},(g,m)=>m),a=g=>e.nodeCore.find(m=>m.key===g)?.column??null,c=a("n"),d=a("r"),u=e.edgeCore[0]?.column??null,f=t.meta.sourceFormat===db&&M(t.meta.extra.cx)?t.meta.extra.cx:{},h=[{name:"nodes",idCounter:i3(n,t.nodeCount),*elements(){for(let g=0;g<t.nodeCount;g++){const m={"@id":n.idAt(g)},y=c===null?void 0:Sd(c,g),b=d===null?void 0:Sd(d,g);y!==void 0&&(m.n=y),b!==void 0&&(m.r=b),yield m}}},{name:"edges",idCounter:o.reduce((g,m)=>Math.max(g,e.edgeIds[m]+1),0),*elements(){for(const g of o){const m={"@id":e.edgeIds[g],s:n.idAt(r[g]),t:n.idAt(s[g])},y=u===null?void 0:Sd(u,g);y!==void 0&&(m.i=y),yield m}}},{name:"nodeAttributes",*elements(){for(const g of e.nodeAttrs)for(let m=0;m<t.nodeCount;m++){const y=Mh(g.column,g.d,m);y!==void 0&&(yield{po:n.idAt(m),n:g.name,v:y,d:g.d})}for(let g=0;g<t.nodeCount;g++)n.isChanged(g)&&(yield{po:n.idAt(g),n:kt,v:String(n.originalAt(g)),d:"string"})}},{name:"edgeAttributes",*elements(){for(const g of e.edgeAttrs)for(const m of o){const y=Mh(g.column,g.d,m);y!==void 0&&(yield{po:e.edgeIds[m],n:g.name,v:y,d:g.d})}if(e.weight!==null)for(const g of o){const m=e.weight.value(g);m!==void 0&&!Number.isNaN(m)&&(yield{po:e.edgeIds[g],n:rr,v:Oa(m),d:"double"})}}},{name:"networkAttributes",*elements(){for(const m of e.graphAttrs){const y=Mh(m.column,m.d,0);y!==void 0&&(yield{n:m.name,v:y,d:m.d})}const{meta:g}=t;for(const[m,y]of[["name",g.name],["description",g.description]])y!==null&&!e.graphAttrs.some(b=>b.name===m)&&(yield{n:m,v:y,d:"string"})}},{name:"cyTableColumn",elements:()=>y8(e,n)},{name:"cartesianLayout",elements:()=>w8(e,n,l())},{name:"cyGroups",elements:()=>_8(t,e,n,o)},{name:"cyVisualProperties",elements:()=>i===null?O8(e,n,l(),o,f):N8(i,n,e.edgeIds,o)}],p=ab(t);p!==null&&h.push({name:Z,elements:()=>CI(p)}),h.push(...T8(t,e,n,o));for(const[g,m]of Object.entries(f))!e8.has(g)&&Array.isArray(m)&&h.push({name:g,elements:()=>E8(m,f.subnetwork,b8.has(g))});return h}function*y8(t,e){for(const{key:n,column:i}of[...t.nodeCore,...t.edgeCore]){const r={n:"name",r:"represents",i:"interaction"}[n];r!==void 0&&i!==null&&(yield{applies_to:n==="i"?"edge_table":"node_table",n:r,d:"string"})}for(const n of t.nodeAttrs)yield{applies_to:"node_table",n:n.name,d:n.d};e.changed>0&&(yield{applies_to:"node_table",n:kt,d:"string"});for(const n of t.edgeAttrs)yield{applies_to:"edge_table",n:n.name,d:n.d};t.weight!==null&&(yield{applies_to:"edge_table",n:rr,d:"double"});for(const n of t.graphAttrs)yield{applies_to:"network_table",n:n.name,d:n.d}}const b8=new Set(["tableVisualProperties","cyTableVisualProperties"]);function*E8(t,e,n){for(const i of t){if(!M(i)){yield i;continue}if(i.s!==void 0&&i.s!==null&&i.s!==e)continue;const{s:r,...s}=i;yield n?WI(s):s}}function WI(t){const e={...t};return"view"in e&&(e.view=0),typeof e.applies_to=="number"&&(e.applies_to=0),e}function*w8(t,e,n){const{position:i}=t;if(i!==null)for(const r of n){if(!i.isSet(r))continue;const s=i.value(r);if(!Number.isFinite(s[0])||!Number.isFinite(s[1]))continue;const o={node:e.idAt(r),x:s[0],y:s[1]===0?0:-s[1]};t.z?.isSet(r)===!0?o.z=t.z.value(r):t.positionZ&&Number.isFinite(s[2])&&(o.z=s[2]),yield o}}function*_8(t,e,n,i){const r=nc(t),s=new Map,o=[];for(let d=0;d<t.nodeCount;d++){const u=r.childrenOf(d);(u.length>0||e.collapsed?.isSet(d)===!0)&&o.push(d);for(const f of u)s.set(f,[...s.get(f)??[],d])}if(o.length===0)return;const{internal:l,external:a}=S8(t,e,s,i),c=e.nodeCore.find(d=>d.key==="n")?.column??null;for(const d of o){const u={"@id":n.idAt(d)},f=c===null?void 0:Sd(c,d);f!==void 0&&(u.n=f),u.nodes=Array.from(r.childrenOf(d),h=>n.idAt(h)),u.internal_edges=l.get(d)??[],u.external_edges=a.get(d)??[],e.collapsed?.isSet(d)===!0&&(u.collapsed=e.collapsed.value(d)),yield u}}function S8(t,e,n,i){const r=new Map,s=new Map,o=(c,d,u)=>{c.set(d,[...c.get(d)??[],u])},{src:l,dst:a}=t.edgeList();for(const c of i){const d=n.get(l[c])??[],u=n.get(a[c])??[];for(const f of d)o(u.includes(f)?r:s,f,e.edgeIds[c]);for(const f of u.filter(h=>!d.includes(h)))o(s,f,e.edgeIds[c])}return{internal:r,external:s}}function Uh(t,e){let n=null;for(const i of t)if(i.isSet(e)){const r=i.meta.origin?.id;n??={},n[typeof r=="string"&&r.length>0?r:i.meta.name]=Oa(i.value(e))}return n}function*O8(t,e,n,i,r){const s=Uh(t.bypass.graph,0);s!==null&&(yield{properties_of:"network",properties:s});const o=A8(r);for(const l of Array.isArray(r.cyVisualProperties)?r.cyVisualProperties:[])M(l)&&!["nodes","edges","network"].includes(String(l.properties_of))&&(o===null||l.view===void 0||l.view===null||l.view===o)&&(yield WI(l));for(const l of n){const a=Uh(t.bypass.node,l);a!==null&&(yield{properties_of:"nodes",applies_to:e.idAt(l),properties:a})}for(const l of i){const a=Uh(t.bypass.edge,l);a!==null&&(yield{properties_of:"edges",applies_to:t.edgeIds[l],properties:a})}}function*N8(t,e,n,i){yield*h4(t.style);const r=s=>Object.fromEntries([...s].map(([o,l])=>[o,String(l)]));for(let s=0;s<t.bypasses.node.length;s++){const o=t.bypasses.node[s];o!==null&&o.size>0&&(yield{properties_of:"nodes",applies_to:e.idAt(s),properties:r(o)})}for(const s of i){const o=t.bypasses.edge[s];o!==null&&o.size>0&&(yield{properties_of:"edges",applies_to:n[s],properties:r(o)})}}function A8(t){const e=t.subnetwork;for(const n of Array.isArray(t.cyNetworkRelations)?t.cyNetworkRelations:[])if(M(n)&&n.r==="view"&&(e===void 0||n.p===e))return n.c;for(const n of Array.isArray(t.cyViews)?t.cyViews:[])if(M(n)&&(e===void 0||n.s===e))return n["@id"];return null}function T8(t,e,n,i){const r=[];for(const[l,a]of Object.entries(jI)){const c=t.extensions.get(l);if(c===void 0)continue;const d=c.get("id"),u=[...c].filter(h=>h!==d);let f=-1;for(let h=0;h<c.rowCount;h++)d?.isSet(h)===!0&&(f=Math.max(f,Number(d.value(h))));r.push({name:a,idCounter:f+1,*elements(){for(let h=0;h<c.rowCount;h++){const p={};d?.isSet(h)===!0&&(p["@id"]=d.value(h));for(const g of u)g.isSet(h)&&(p[g.meta.name]=g.value(h));yield p}}})}for(const l of e.links)r.push({name:l.aspect,*elements(){const a=l.domain==="node"?Array.from({length:t.nodeCount},(c,d)=>d):i;for(const c of a)l.column.isSet(c)&&(yield{po:[l.domain==="node"?n.idAt(c):e.edgeIds[c]],[l.key]:Array.from(l.column.value(c))})}});const s=e.functionTerm;s!==null&&r.push({name:"functionTerms",*elements(){for(let l=0;l<t.nodeCount;l++){const a=s.isSet(l)?s.value(l):null;M(a)&&(yield{po:n.idAt(l),...a})}}});const o=e.reifiedEdge;return o!==null&&r.push({name:"reifiedEdges",*elements(){for(let l=0;l<t.nodeCount;l++){const a=o.isSet(l)?o.value(l):-1;a>=0&&a<t.edgeCount&&(yield{node:n.idAt(l),edge:e.edgeIds[a]})}}}),r}function*I8(t,e,n=null){if(e.fatal!==null)throw e.fatal;const{ids:i}=e;if(i===null)throw new N("E_INVALID_ID","node ids cannot be written as CX integers",{reason:"charset"});const r=m8(t,e,i,n),s=[];for(const l of r){let a=0;for(const c of l.elements())a++;(a>0||l.name==="nodes")&&s.push({aspect:l,count:a})}const o=s.map(({aspect:l,count:a})=>({name:l.name,version:"1.0",...l.idCounter===void 0?{}:{idCounter:l.idCounter},elementCount:a,consistencyGroup:1}));yield`[{"numberVerification":[{"longNumber":281474976710655}]},
|
|
42
|
+
`,yield`{"metaData":${Di(o)}},
|
|
43
|
+
`;for(const{aspect:l}of s)yield*n1(l.name,$8(l.elements(),Di));yield`{"status":[{"error":"","success":true}]}]
|
|
44
|
+
`}function*$8(t,e){for(const n of t)yield e(n)}const C8=Object.freeze({format:db,options:Object.freeze([]),capabilities:GI,styles:Object.freeze({capabilities:kG}),check(t,e){const n=If(t,e?.styles,"desktop");return Object.freeze([...zI(n?.snapshot??t,ft(e)).notes,...n?.notes??[]])},export(t,e){return ti(Uw(t,e))},exportToString(t,e){return ni(Uw(t,e))}});function Uw(t,e){const n=If(t,e?.styles,"desktop"),i=n?.snapshot??t;return I8(i,zI(i,ft(e)),n?.styled??null)}const He="cx",Gw="cx.bypass",Hn=Object.freeze({...xn,...Pn,EMPTY_INPUT:Ut,SYNTAX:kn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,NOT_CX:"E_CX_NOT_CX",NUMBER_VERIFICATION:"W_CX_NUMBER_VERIFICATION",OLD_ASPECT_NAME:"W_CX_OLD_ASPECT_NAME",GROUP_NODE_ADDED:"W_CX_GROUP_NODE_ADDED",ROOT_ONLY:"W_CX_ROOT_ONLY",STATUS_FAILED:Vd,STATUS_WARNING:ry,BAD_ASPECT_BLOCK:mt,ASPECT_ORDER:Bn,COUNT_MISMATCH:Fs,BAD_VALUE:ie,WIDENED:fa,UNKNOWN_ATTR_TYPE:Zt,DANGLING_REFERENCE:Xi,DUPLICATE_ATTRIBUTE:fe,UNKNOWN_PARENT:Ui,PARENT_CYCLE:pl,STYLES_NOT_IMPORTED:to,MISSING_ID:dt,MISSING_ENDPOINT:Zn,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,INVALID_ID:"E_INVALID_ID",UNKNOWN_ELEMENT:vt,MULTI_ASPECT_FRAGMENT:iy,SINGLE_OBJECT_ASPECT:OA,JSON_NONSTANDARD_NUMBER:Ju,UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",ID_TEXT_TYPE:cs,PRECISION:re,ID_MERGED:Rn,MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,NO_GRAPH:ls,COLUMN_RENAMED:ln,ROLE_TAKEN:bn,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,TOO_LARGE:gl}),v8=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]),BI={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},HI=64,D8=new Set(["281474976710655","9223372036854775807"]),Od=new Map([["visualProperties","cyVisualProperties"],["subNetworks","cySubNetworks"],["networkRelations","cyNetworkRelations"],["hiddenAttributes","cyHiddenAttributes"]]),k8=new Set(["@id","n","r"]),R8=new Set(["@id","s","t","i"]),L8=new Set(["node_table","edge_table","network_table"]),wg=new Set(["nodes","edges","nodeAttributes","edgeAttributes","networkAttributes","cartesianLayout","cySubNetworks","cyNetworkRelations","cyViews","cyGroups","cyVisualProperties","cyTableColumn","citations","supports","nodeCitations","edgeCitations","nodeSupports","edgeSupports","functionTerms","reifiedEdges","numberVerification","metaData","status"]),P8=new Set(["cySubNetworks","cyNetworkRelations","cyViews","cyVisualProperties","cyTableColumn","numberVerification","metaData"]),VI=["tableVisualProperties","cyTableVisualProperties"],x8=["groups","subnetwork"],M8=new Set(["numberVerification","metaData"]),YI=new Set(["nodes","edges","nodeAttributes","edgeAttributes","networkAttributes","cartesianLayout","@context","cySubNetworks","subNetworks","cyNetworkRelations","networkRelations","cyVisualProperties","visualProperties","cyHiddenAttributes","hiddenAttributes","cyTableColumn","cyGroups","cyViews","ndexStatus","provenanceHistory","citations","supports","functionTerms"]),U8=new Map([["string","string"],["boolean","boolean"],["integer","integer"],["long","long"],["double","double"],["float","double"]]);function jc(t){if(t==null)return{scalar:"string",list:!1};if(typeof t!="string")return null;const e=t.startsWith("list_of_"),n=U8.get(e?t.slice(8):t);return n===void 0?null:{scalar:n,list:e}}function yo(t){return t.list?`list_of_${t.scalar}`:t.scalar}const jw={boolean:0,integer:1,long:2,double:3,string:4};function G8(t,e){if(t.list!==e.list)return null;if(t.scalar===e.scalar)return t;const n=i=>i==="integer"||i==="long"||i==="double";return n(t.scalar)&&n(e.scalar)?jw[t.scalar]>jw[e.scalar]?t:e:{scalar:"string",list:t.list}}const Vt=Symbol("bad"),tl=Symbol("unset"),KI=-2147483648,XI=2147483647,j8=/^-?\d+$/,F8=/^-?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;function qI(t){return t===""||t.toLowerCase()==="null"}function Fw(t,e,n,i){if(t instanceof vn)return e==="string"||e==="long"&&n==="string"?t.digits:e==="long"||e==="double"?(e==="long"&&i(t.digits),Number(t.digits)):Vt;if(typeof t=="number"||typeof t=="boolean")return z8(t,e,n);if(typeof t!="string")return Vt;if(e==="string")return t;if(qI(t))return tl;switch(e){case"boolean":{const r=t.toLowerCase();return r==="true"||r==="false"?r==="true":Vt}case"integer":case"long":{if(t==="NaN")return tl;if(!j8.test(t))return Vt;const r=Number(t);return e==="integer"?r>=KI&&r<=XI?r:Vt:n==="string"?t:(Number.isSafeInteger(r)||i(t),r)}default:{if(t==="NaN"||t==="nan")return Number.NaN;if(t==="Infinity"||t==="-Infinity")return Number(t);if(!F8.test(t))return Vt;const r=Number(t);return Number.isFinite(r)||i(t),r}}}function z8(t,e,n){switch(e){case"string":return String(t);case"boolean":return typeof t=="boolean"?t:Vt;case"integer":return typeof t=="number"&&Number.isInteger(t)&&t>=KI&&t<=XI?t:Vt;case"long":return typeof t!="number"||!Number.isInteger(t)?Vt:n==="string"?String(t):t;default:return typeof t=="number"?t:Vt}}function zw(t,e,n,i){if(Array.isArray(t)!==e.list)return Vt;if(!e.list)return Fw(t,e.scalar,n,i);const r=[];for(const s of t){let o=s===null?tl:Fw(s,e.scalar,n,i);if(o===tl&&(o=e.scalar==="double"?Number.NaN:Vt),o===Vt)return Vt;r.push(o)}return r}function Gh(t,e){switch(t){case"boolean":return"bool";case"integer":return"i32";case"long":return e==="string"?"string":"f64";case"double":return"f64";default:return"string"}}function W8(t,e){return e.scalar!=="string"?t:e.list?t.map(n=>typeof n=="string"?n:String(n)):typeof t=="string"?t:String(t)}function pe(t){if(t instanceof vn)return t.digits;let e;try{e=JSON.stringify(t)??String(t)}catch{e=String(t)}return e.length>60?`${e.slice(0,57)}...`:e}function Te(t,e){return t.aspects.get(e)??[]}function B8(t,e,n=1){if(!/\d[.eE]/.test(t))return 0;let i=0;return e.forEach((r,s)=>{u1(t,r,n)&&(i|=1<<s)}),i}function H8(t,e){switch(e){case"nodeAttributes":return t.attributes.node;case"edgeAttributes":return t.attributes.edge;case"networkAttributes":return t.attributes.network;default:return null}}function V8(t,e,n,i){const r=M(t)?t.longNumber:void 0,s=r instanceof vn?r.digits:String(r);if(e>1||!D8.has(s)){const o=r===void 0?null:s;n.warning("validation-error",Hn.NUMBER_VERIFICATION,e>1?"a second numberVerification element; ignored":`numberVerification holds ${pe(o)}, not 281474976710655`,{line:i,element:"numberVerification"})}}function Ww(t){return wg.has(t)||Od.has(t)||YI.has(t)||VI.includes(t)}const Y8=new Map([["nodes",["@id"]],["edges",["@id","s","t"]]]);function K8(t,e,n,i){const{value:r,line:s}=n,o=M(r)?r.n:void 0;if(o==null){i.error("missing-value",dt,`a ${e} element has no attribute name n; skipped`,{line:s,element:e});return}if(typeof o!="string"||o===""){i.error("validation-error",ie,`a ${e} element has the attribute name n ${pe(o)}, not a non-empty string; skipped`,{line:s,element:e});return}t.has(o)||t.set(o,[]),t.get(o)?.push(n)}function X8(t,e){const{doc:n,report:i}=t,{name:r,value:s,text:o,line:l,exact:a,depth:c}=e;if(n.structure.element(r,s,l),P8.has(r)||!wg.has(r)){n.kept.has(r)||n.kept.set(r,[]);const h=r==="numberVerification"?void 0:t.onKeptPrecision;n.kept.get(r)?.push(a?qe(s,h):s)}if(!wg.has(r)||r==="metaData"||r==="status")return;if(r==="numberVerification"){V8(s,++t.verifications,i,l);return}const d=Y8.get(r),u={value:s,line:l,inexact:d===void 0?0:B8(o,d,c)},f=H8(n,r);if(f!==null){K8(f,r,u,i);return}n.aspects.has(r)||n.aspects.set(r,[]),n.aspects.get(r)?.push(u)}async function JI(t,e,n){const i=new p1(e,p=>Od.get(p)??p),r={aspects:new Map,attributes:{node:new Map,edge:new Map,network:new Map},kept:new Map,structure:i},s={doc:r,report:e,verifications:0,onKeptPrecision:c1(e,"meta.extra.cx")};let o=0,l=0,a=0;const c=new Set,d={block:-1},u=(p,g)=>{p!==d.block&&(d.block=p,l++),g!==null&&Ww(g)?a++:g!==null&&c.add(g)},f=(p,g)=>{const m=Od.get(p);return m===void 0?p:(e.warnOnce("coercion",Hn.OLD_ASPECT_NAME,`the old aspect name "${p}" is read as "${m}"`,{line:g,element:p},`${Hn.OLD_ASPECT_NAME}:${p}`),m)},h=(p,g,m,y,b,_=1)=>{X8(s,{name:p,value:g,text:m,line:y,exact:b,depth:_})};try{for await(const p of l1($r(t,e,n),e))switch(++o>=HI&&(o=0,F(n.signal)),p.kind){case"root":e.fail(Hn.NOT_CX,`a CX document is a JSON array of aspects; found ${p.object?"an object":pe(p.value)}`,{line:p.line});break;case"member":{const{value:g}=p;M(g)&&"CXVersion"in g&&e.fail(Hn.NOT_CX,`the document is CX2 (CXVersion ${pe(g.CXVersion)}), not CX version 1; read it with the cx2 importer`,{line:p.line});const m=M(g)?Object.keys(g):[];if(M(g)&&m.length===1&&M(g[m[0]])){u(p.block,m[0]);const b=f(m[0],p.line);Ww(b)&&e.warning("validation-error",Hn.SINGLE_OBJECT_ASPECT,`the "${m[0]}" aspect is one object, not an array of elements; read as one element`,{line:p.line,element:m[0]}),i.block(b,p.line),h(b,g[m[0]],p.text,p.line,p.exact,2);break}u(p.block,null);const y=m.length>1?`an object with ${m.length} keys (${m.join(", ")})`:pe(g);e.error("parse-error",mt,`a member of the document is ${y}, not a one-key aspect fragment; skipped`,{line:p.line,element:m[0]??null});break}case"block":u(p.block,p.aspect),d1(e,p),i.block(f(p.aspect,p.line),p.line);break;case"element":{const g=Od.get(p.aspect)??p.aspect;h(g,p.value,p.text,p.line,p.exact);break}case"deep":u(p.block,p.aspect),a1(e,p);break;case"extraKeys":e.error("parse-error",mt,`the "${p.aspect}" fragment holds more keys (${p.keys.join(", ")}) whose values are not arrays; a fragment has one key, the others are skipped`,{line:p.line,element:p.aspect});break;default:break}}catch(p){throw p instanceof et&&e.fail(p.empty?Ut:kn,p.message,{line:p.line}),p}if(l>0&&a===0){const p=[...c].slice(0,5).map(y=>JSON.stringify(y)),g=c.has("data")?": Cytoscape.js elements?":"",m=p.length>0?` (found ${p.join(", ")}${g})`:"";e.fail(Hn.NOT_CX,`no member of the array is a CX aspect${m}; the input is not CX`)}return i.hasStatus&&!i.statusWellFormed()&&e.error("validation-error",ie,`the status element is ${pe(i.status??null)}, not an object with a boolean success; ignored`,{element:"status"}),i.checkCounts(),r}function Ee(t){try{return au(t).id}catch{return null}}function Bw(t){return t.view===void 0||t.view===null?null:Ee(t.view)}function Hw(t){return typeof t=="string"?t:JSON.stringify(t)}function _g(t,e){if(t==="all")return null;const n=new Set;if(Array.isArray(t))for(const i of t){const r=Ee(i);r===null?e?.(Hn.INVALID_ID,`the member ${pe(i)} is not an id; ignored`):n.add(r)}else t!==void 0&&e?.(ie,`the member list ${pe(t)} is neither a list of ids nor "all"; read as empty`);return n}function yu(t,e,n,i){const{value:r,line:s}=t;if(!M(r))return i.error("parse-error",mt,`a ${e} element is ${pe(r)}, not an object; skipped`,{line:s,element:e}),null;if(r[n]===void 0||r[n]===null)return i.error("missing-value",dt,`a ${e} element has no ${n}; skipped`,{line:s,element:e}),null;const o=Ee(r[n]);return o===null?(i.error("validation-error",Hn.INVALID_ID,`a ${e} element has the ${n} ${pe(r[n])}, not an integer id; skipped`,{line:s,element:e}),null):{value:r,id:o}}function ZI(t,e){const n=q8(t,e),{relationNames:i,order:r,views:s}=J8(t,n,e);if(r.length<=1){const o=r.length===1?r[0]:null,l=o===null?void 0:n.get(o);let a=o===null?[]:s.get(o)??[];return a.length===0&&(a=[...new Set([...s.values()].flat())]),a.length===0&&(a=Q8(t)),[{index:0,name:(o===null?null:i.get(o)??null)??Vw(t,o),subnetwork:o,nodes:l?.nodes??null,edges:l?.edges??null,views:a}]}return r.map((o,l)=>({index:l,name:i.get(o)??Vw(t,o),subnetwork:o,nodes:n.get(o)?.nodes??null,edges:n.get(o)?.edges??null,views:s.get(o)??[]}))}function q8(t,e){const n=new Map;for(const i of Te(t,"cySubNetworks")){const r=yu(i,"cySubNetworks","@id",e);if(r===null)continue;const{value:s,id:o}=r;if(n.has(o)){e.error("validation-error",mt,`a second cySubNetworks element has the @id ${String(o)}; skipped, the first is used`,{line:i.line,element:"cySubNetworks"});continue}const l=(a,c)=>{e.error("validation-error",a,`subnetwork ${String(o)}: ${c}`,{line:i.line,element:"cySubNetworks"})};n.set(o,{nodes:_g(s.nodes,l),edges:_g(s.edges,l)})}return n}function J8(t,e,n){const i=new Map,r=[],s=new Map,o=(l,a)=>{const c=s.get(l)??[];c.includes(a)||c.push(a),s.set(l,c)};for(const l of Te(t,"cyNetworkRelations")){const a=yu(l,"cyNetworkRelations","c",n);a!==null&&Z8(a,e,{relationNames:i,order:r,addView:o})}for(const l of Te(t,"cyViews")){const a=yu(l,"cyViews","@id",n),c=a===null?null:Ee(a.value.s);a!==null&&c!==null&&o(c,a.id)}return r.push(...[...e.keys()].filter(l=>!r.includes(l))),{relationNames:i,order:r,views:s}}function Z8(t,e,n){const{value:i,id:r}=t;if(i.r==="view"){const s=Ee(i.p);s!==null&&n.addView(s,r);return}typeof i.name=="string"&&n.relationNames.set(r,i.name),e.has(r)&&!n.order.includes(r)&&n.order.push(r)}function Vw(t,e){let n=null;for(const{value:i}of t.attributes.network.get("name")??[]){if(!M(i)||typeof i.v!="string")continue;const r=i.s===void 0?null:Ee(i.s);if(r===e)return i.v;r===null&&(n??=i.v)}return n}function Q8(t){const e=[];for(const{value:n}of Te(t,"cartesianLayout")){const i=M(n)&&n.view!==void 0?Ee(n.view):null;i!==null&&!e.includes(i)&&e.push(i)}return e}function Yw(t,e){return t===null?e:t.size}class ej{constructor(e,n,i,r,s,o){this.rootNodes=new Set,this.rootEdges=new Set,this.nodeRows=new Map,this.sinkRows=new Map,this.edgeRows=new Map,this.sinkIds=new Map,this.subnetworks=new Set,this.dangling=new Map,this.nameHandle=A,this.representsHandle=A,this.interactionHandle=A,this.edgeIdHandle=A,this.sinceCheck=0,this.idType="integer",this.weighted=!1,this.coreValues=new Map,this.weights=new Map,this.sink=e,this.report=n,this.options=i,this.zAs=r,this.doc=s,this.plan=o,this.direction=new ei(e,n,i.onMixedDirection),this.coercer=new Mn(i.ids);for(const{value:l}of Te(s,"nodes")){const a=M(l)?Ee(l["@id"]):null;a!==null&&this.rootNodes.add(a)}for(const{value:l}of Te(s,"edges")){const a=M(l)?Ee(l["@id"]):null;a!==null&&this.rootEdges.add(a)}for(const{value:l}of Te(s,"cySubNetworks")){const a=M(l)?Ee(l["@id"]):null;a!==null&&this.subnetworks.add(a)}}build(){const{report:e}=this;this.direction.setHeader(!0),this.checkMembers(),this.checkRootOnly(),this.checkTableColumns();const n=this.declareAttributes("node");this.readNodes(),this.readGroups(),this.writeAttributes("node",n),this.readLayout();const i=this.declareAttributes("edge");this.readEdges(),this.writeAttributes("edge",i),this.readNetworkAttributes(),this.readVisualProperties(),this.readStyleBlock(),this.readProvenance();for(const[r,s]of this.dangling)e.warning("validation-error",Xi,`${s} ${r}${O(s)} ${C(s,"names","name")} nothing; ignored`,{element:r});this.setMeta()}dangle(e){this.dangling.set(e,(this.dangling.get(e)??0)+1)}checkAbort(){++this.sinceCheck>=HI&&(this.sinceCheck=0,F(this.options.signal))}inGraph(e){return this.plan.nodes===null||this.plan.nodes.has(e)}scopeOf(e){if(e==null)return 1;const n=Ee(e);return n!==null&&n===this.plan.subnetwork?2:((n===null||!this.subnetworks.has(n))&&this.dangle("attribute subnetwork reference"),0)}idOf(e,n,i,r,s=!1){try{const o=au(e,n);return o.note==="text"?this.report.warnOnce("coercion",cs,`${i}: the id ${pe(e)} is not written as an integer; read as ${String(o.id)}`,{line:r,element:i}):o.note==="precision"&&s?this.report.warnOnce("precision",re,`${i}: the edge id ${String(o.id)} is beyond 2^53; the id column holds the nearest double`,{line:r,element:i},`${re}:edge`):o.note==="precision"&&(this.idType="mixed",this.report.warnOnce("precision",re,`${i}: the id ${String(o.id)} is beyond 2^53; kept as its digits (a string id)`,{line:r,element:i})),o.id}catch(o){return this.report.recordError(o,{line:r,element:i}),null}}sinkId(e){const n=this.sinkIds.get(e);return n!==void 0?n:this.options.ids==="keep"?e:this.coercer.value(e)}addNode(e){const n=this.sinkId(e),i=this.sinkRows.get(n);if(i!==void 0)return this.nodeRows.set(e,i),{row:i,added:!1};const r=this.sink.addNode(n);return this.sinkRows.set(n,r),this.nodeRows.set(e,r),{row:r,added:!0}}precision(e,n){const i=!Number.isFinite(Number(n));this.report.warnOnce("precision",re,i?`"${e}": ${n} is beyond the range of a double; stored as ${String(Number(n))}`:`"${e}": ${n} is beyond 2^53; stored as the nearest double`,{element:e},`${re}:value`)}unknownKeys(e,n,i,r){for(const s of Object.keys(e))n.has(s)||this.report.warnOnce("unsupported",vt,`the ${i} key "${s}" is not defined by CX; its values are not read`,{line:r,element:s},`${vt}:${i}:${s}`)}checkTableColumns(){for(const{value:e,line:n}of Te(this.doc,"cyTableColumn"))M(e)&&typeof e.applies_to=="string"&&!L8.has(e.applies_to)&&this.report.warnOnce("unsupported",vt,`a cyTableColumn entry applies to "${e.applies_to}", which is not node_table, edge_table or network_table; ignored`,{line:n,element:e.applies_to},`${vt}:table:${e.applies_to}`)}checkMembers(){for(const e of this.plan.nodes??[])this.rootNodes.has(e)||this.dangle("subnetwork node member");for(const e of this.plan.edges??[])this.rootEdges.has(e)||this.dangle("subnetwork edge member")}checkRootOnly(){const e=Te(this.doc,"cySubNetworks");if(e.length===0)return;const n={nodes:new Set,edges:new Set},i={nodes:!1,edges:!1};for(const{value:l}of e)if(M(l))for(const a of["nodes","edges"]){const c=_g(l[a]);c===null?i[a]=!0:c.forEach(d=>n[a].add(d))}const r=(l,a)=>i[l]?0:[...a].filter(c=>!n[l].has(c)).length,s=r("nodes",this.rootNodes),o=r("edges",this.rootEdges);s+o>0&&this.report.warning("unsupported",Hn.ROOT_ONLY,`${s} node${O(s)} and ${o} edge${O(o)} of the root network belong to no subnetwork (cySubNetworks); they are not read`,{element:"cySubNetworks"})}structural(e,n,i){return n===A?he(this.sink,e,i,this.report).handle:n}declareAttributes(e){const n=new Map,i=this.tableColumns(e==="node"?"node_table":"edge_table"),r=new Set([...i.keys(),...this.doc.attributes[e].keys()]);for(const s of r){if(e==="edge"&&s===this.options.weightFrom||e==="node"&&s===kt&&this.options.restoreMangledIds)continue;const o=[];let l=!1;const a=i.get(s);a!==void 0&&o.push(a);for(const{value:d}of this.doc.attributes[e].get(s)??[]){if(!M(d)||this.scopePeek(d.s)===0)continue;const u=jc(d.d);if(u===null){l=!0;continue}o.some(f=>f.scalar===u.scalar&&f.list===u.list)||o.push(u)}l&&(this.report.warnOnce("unsupported",Zt,`a ${e} attribute "${s}" declares a data type CX does not define; its values are kept as text`,{element:s},`${Zt}:${e}:${s}`),o.push({scalar:"string",list:!1}));let c=o[0]??{scalar:"string",list:!1};for(const d of o.slice(1))c=c===null?null:G8(c,d);if(o.length>1&&this.report.warnOnce("coercion",fa,`the ${e} attribute "${s}" has the data types ${o.map(yo).join(", ")}; the column holds ${c===null?"their values as JSON":yo(c)}`,{element:s},`${fa}:${e}:${s}`),this.isStructural(e,s)){n.set(s,{name:s,type:{scalar:"string",list:!1},handle:A});continue}n.set(s,{name:s,type:c,handle:this.declareColumn(e,s,c)})}return n}isStructural(e,n){return e==="node"?n==="name"||n==="represents":n==="interaction"}scopePeek(e){if(e==null)return 1;const n=Ee(e);return n!==null&&n===this.plan.subnetwork?2:0}tableColumns(e){const n=new Map;for(const{value:i}of Te(this.doc,"cyTableColumn")){if(!M(i)||i.applies_to!==e||typeof i.n!="string"||this.scopePeek(i.s)===0)continue;const r=jc(i.d);r===null?this.report.warnOnce("unsupported",Zt,`cyTableColumn declares "${i.n}" with the data type ${pe(i.d)}, which CX does not define; its values are typed by their own d`,{element:i.n},`${Zt}:table:${e}:${i.n}`):n.set(i.n,r)}return n}declareColumn(e,n,i){const{long:r}=this.options,s=i===null?{name:n,dtype:"json",nullable:!0,origin:{format:He,id:null}}:{name:n,dtype:i.list?"list":Gh(i.scalar,r),...i.list?{itemDtype:Gh(i.scalar,r)}:{},nullable:!0,origin:{format:He,id:null,type:yo(i)}};return he(this.sink,e,s,this.report).handle}writeAttributes(e,n){const i=e==="node"?this.nodeRows:this.edgeRows,r=e==="node"?this.rootNodes:this.rootEdges;for(const s of n.values()){const o=new Map;for(const l of this.doc.attributes[e].get(s.name)??[]){this.checkAbort();const{value:a,line:c}=l;if(!M(a)){this.report.error("parse-error",mt,`a ${e}Attributes element is not an object`,{line:c,element:`${e}Attributes`});continue}const d=this.scopeOf(a.s);if(d!==0){if(a.v===void 0){this.report.error("missing-value",ie,`a ${e}Attributes element for "${s.name}" has no v; skipped`,{line:c,element:s.name});continue}for(const u of Array.isArray(a.po)?a.po:[a.po]){const f=Ee(u),h=f===null?void 0:i.get(f);if(h===void 0){(f===null||!r.has(f))&&this.dangle(`${e} attribute target`);continue}if(a.v===null)continue;const p=o.get(h);p!==void 0&&p.scope>d||(p?.scope===d&&JSON.stringify(p.value)!==JSON.stringify(qe(a.v))&&this.report.warnOnce("validation-error",fe,`${e} ${pe(u)} has the attribute "${s.name}" twice; the later value wins`,{line:c,element:s.name},`${fe}:${e}:${s.name}`),o.set(h,{scope:d,value:a.v,d:a.d,line:c}))}}}for(const[l,{value:a,d:c,line:d}]of o)this.writeCell(e,s,l,a,c,d)}}writeCell(e,n,i,r,s,o){const l=`${e} attribute "${n.name}"`;let a;if(n.type===null)a=qe(r,d=>{this.precision(n.name,d)});else{const d=jc(s)??{scalar:"string",list:!1},u=zw(r,d,this.options.long,f=>{this.precision(n.name,f)});if(u===tl)return;if(u===Vt){this.report.error("validation-error",ie,`${l}: ${pe(r)} is not a ${yo(d)}; the cell is unset`,{line:o,element:n.name});return}a=W8(u,n.type)}let{handle:c}=n;if(this.isStructural(e,n.name)){if(Array.isArray(r)){this.report.error("validation-error",ie,`${l}: ${pe(r)} is a list; "${n.name}" holds one string, the cell is unset`,{line:o,element:n.name});return}c=this.coreColumn(e,n.name);const d=this.coreValue(e,i,n.name);d!==void 0&&d!==a&&this.report.warnOnce("validation-error",fe,`a ${e} has "${n.name}" both as its core field and as an attribute with another value; the attribute wins`,{line:o,element:n.name},`${fe}:core:${n.name}`)}try{e==="node"?this.sink.setNodeValue(c,i,a):this.sink.setEdgeValue(c,i,a)}catch(d){this.report.recordError(d,{line:o,element:n.name})}}coreValue(e,n,i){return this.coreValues.get(`${e}:${i}`)?.get(n)}coreColumn(e,n){return e==="edge"?(this.interactionHandle=this.structural("edge",this.interactionHandle,{name:"interaction",dtype:"string",nullable:!0,origin:{format:He,id:"i",type:"string"}}),this.interactionHandle):n==="name"?(this.nameHandle=this.structural("node",this.nameHandle,{name:"name",dtype:"string",role:"label",nullable:!0,origin:{format:He,id:"n",type:"string"}}),this.nameHandle):(this.representsHandle=this.structural("node",this.representsHandle,{name:"represents",dtype:"string",nullable:!0,origin:{format:He,id:"r",type:"string"}}),this.representsHandle)}readNodes(){const{report:e}=this,n=this.originalIds();for(const i of Te(this.doc,"nodes")){this.checkAbort();const{value:r,line:s}=i;if(!M(r)){e.error("parse-error",mt,`a nodes element is ${pe(r)}, not an object`,{line:s,element:"nodes"}),e.counts.skippedNodes++;continue}if(r["@id"]===void 0||r["@id"]===null){e.error("missing-value",dt,"a node has no @id",{line:s,element:"nodes"}),e.counts.skippedNodes++;continue}this.unknownKeys(r,k8,"node",s);const o=`node ${pe(r["@id"])}`,l=this.idOf(r["@id"],(i.inexact&1)!==0,o,s);if(l===null){e.counts.skippedNodes++;continue}if(!this.inGraph(l))continue;let a=this.nodeRows.get(l),c=!1;if(a===void 0){const d=n.get(Ee(r["@id"])??l);d!==void 0&&(this.idType="mixed",this.sinkIds.set(l,d));try{({row:a,added:c}=this.addNode(l))}catch(u){e.recordError(u,{line:s,element:o}),e.counts.skippedNodes++;continue}}c?e.counts.nodes++:e.warning("merged",sn,`${o} is declared more than once; its fields are merged (the later values win)`,{line:s,element:o}),this.writeCore("node",a,"name",r.n,o,s),this.writeCore("node",a,"represents",r.r,o,s)}}originalIds(){const e=new Map;if(!this.options.restoreMangledIds)return e;for(const{value:n}of this.doc.attributes.node.get(kt)??[]){const i=M(n)&&this.scopePeek(n.s)!==0?Ee(n.po):null;i!==null&&M(n)&&typeof n.v=="string"&&e.set(i,n.v)}return e}writeCore(e,n,i,r,s,o){if(r==null)return;if(typeof r!="string"){this.report.error("validation-error",ie,`${s}: ${i} is ${pe(r)}, not a string`,{line:o,element:s});return}const l=this.coreColumn(e,i);e==="node"?this.sink.setNodeValue(l,n,r):this.sink.setEdgeValue(l,n,r);const a=`${e}:${i}`;let c=this.coreValues.get(a);c===void 0&&(c=new Map,this.coreValues.set(a,c)),c.set(n,r)}readGroups(){const e=Te(this.doc,"cyGroups");if(e.length===0)return;const n=new Map,i=[];for(const r of e){const s=yu(r,"cyGroups","@id",this.report);if(s===null)continue;const{value:o,id:l}=s,{line:a}=r;o.nodes!==void 0&&o.nodes!==null&&!Array.isArray(o.nodes)&&this.report.error("validation-error",ie,`group ${String(l)}: nodes is ${pe(o.nodes)}, not a list of node ids; no member is read`,{line:a,element:String(l)}),o.collapsed!==void 0&&o.collapsed!==null&&typeof o.collapsed!="boolean"&&this.report.error("validation-error",ie,`group ${String(l)}: collapsed is ${pe(o.collapsed)}, not a boolean; unset`,{line:a,element:String(l)});let c=this.nodeRows.get(l);if(c===void 0){if(this.rootNodes.has(l)||!this.hasMemberIn(o.nodes))continue;try{c=this.addNode(l).row}catch(d){this.report.recordError(d,{line:a,element:String(l)});continue}this.report.counts.nodes++,this.report.warning("coercion",Hn.GROUP_NODE_ADDED,`group ${String(l)} is not a node; its group node is added`,{line:a,element:String(l)})}typeof o.n=="string"&&this.coreValue("node",c,"name")===void 0&&this.writeCore("node",c,"name",o.n,`group ${String(l)}`,a),typeof o.collapsed=="boolean"&&i.push([c,o.collapsed]);for(const d of Array.isArray(o.nodes)?o.nodes:[]){const u=Ee(d),f=u===null?void 0:this.nodeRows.get(u);if(f===void 0){(u===null||!this.rootNodes.has(u))&&this.report.error("missing-value",Ui,`group ${String(l)}: the member ${pe(d)} is not a node`,{line:a,element:String(l)});continue}if(this.closesCycle(n,f,c)){this.report.error("validation-error",pl,`group ${String(l)}: making ${pe(d)} a member would close a parent cycle; that membership is dropped`,{line:a,element:String(l)});continue}const h=n.get(f)??[];h.includes(c)||h.push(c),n.set(f,h)}}if(this.writeParents(n),i.length>0){const{handle:r}=he(this.sink,"node",{name:"collapsed",dtype:"bool",nullable:!0,origin:{format:He,namespace:"cyGroups"}},this.report);for(const[s,o]of i)this.sink.setNodeValue(r,s,o)}}hasMemberIn(e){return Array.isArray(e)&&e.some(n=>{const i=Ee(n);return i!==null&&this.nodeRows.has(i)})}closesCycle(e,n,i){const r=[i],s=new Set;for(;r.length>0;){const o=r.pop();if(o===n)return!0;s.has(o)||(s.add(o),r.push(...e.get(o)??[]))}return!1}writeParents(e){if(e.size===0)return;const n=[...e.values()].some(s=>s.length>1),i=n?{name:"parents",dtype:"list",itemDtype:"u32",role:"parents",refersTo:"node",nullable:!0}:{name:"parent",dtype:"u32",role:"parent",refersTo:"node",nullable:!0},{handle:r}=he(this.sink,"node",i,this.report);for(const[s,o]of e)this.sink.setNodeValue(r,s,n?o:o[0])}readLayout(){const e=Te(this.doc,"cartesianLayout");if(e.length===0)return;const{views:n}=this.plan,i=this.allViews(),r=new Map,s={current:A},o=new Set,l=[0,0,0];for(const{value:a,line:c}of e){if(this.checkAbort(),!M(a)){this.report.error("parse-error",mt,`a cartesianLayout element is ${pe(a)}, not an object; skipped`,{line:c,element:"cartesianLayout"});continue}const d=a.view===void 0||a.view===null?null:Ee(a.view);if(d!==null&&i.size>0&&!i.has(d)){this.dangle("layout view reference");continue}const u=d===null?0:n.indexOf(d);if(u<0)continue;if(typeof a.x!="number"||typeof a.y!="number"){this.report.error("validation-error",ie,`a cartesianLayout element for node ${pe(a.node)} has no numeric x and y; skipped`,{line:c,element:"cartesianLayout"});continue}if(!Number.isFinite(a.x)||!Number.isFinite(a.y)){this.report.error("validation-error",ie,`a cartesianLayout element for node ${pe(a.node)} has the coordinates ${String(a.x)}, ${String(a.y)}, which are not both finite; skipped`,{line:c,element:"cartesianLayout"});continue}const f=Ee(a.node),h=f===null?void 0:this.nodeRows.get(f);if(h===void 0){(f===null||!this.rootNodes.has(f))&&this.dangle("layout entry");continue}a.z!==void 0&&a.z!==null&&typeof a.z!="number"&&this.report.error("validation-error",ie,`a cartesianLayout element for node ${pe(a.node)} has the z ${pe(a.z)}, not a number; z is unset`,{line:c,element:"cartesianLayout"});const p=`${u}:${h}`;o.has(p)&&this.report.warnOnce("validation-error",fe,`node ${pe(a.node)} has two layout entries for one view; the later wins`,{line:c,element:"cartesianLayout"},`${fe}:layout`),o.add(p);const g=typeof a.z=="number"?a.z:null;l[0]=a.x,l[1]=Bo(a.y),l[2]=u===0&&this.zAs==="position"&&g!==null?g:0,this.sink.setNodeValue(this.layoutColumn(r,u,n),h,l),u===0&&g!==null&&this.zAs==="column"&&(s.current=this.structural("node",s.current,Qp(He)),this.sink.setNodeValue(s.current,h,g))}}allViews(){const e=new Set;for(const{value:n}of Te(this.doc,"cyNetworkRelations"))if(M(n)&&n.r==="view"){const i=Ee(n.c);i!==null&&e.add(i)}for(const{value:n}of Te(this.doc,"cyViews")){const i=M(n)?Ee(n["@id"]):null;i!==null&&e.add(i)}return e}layoutColumn(e,n,i){let r=e.get(n);if(r===void 0){const s=f1(He,this.zAs==="position"&&n===0?3:2),o=n===0?s:{...s,name:`position@${n+1}`,role:void 0,origin:{format:He,namespace:"cytoscape",id:String(i[n])}};({handle:r}=he(this.sink,"node",o,this.report)),e.set(n,r)}return r}readEdges(){const{report:e,sink:n}=this,i=this.plan.edges;this.weights=this.edgeWeights();for(const r of Te(this.doc,"edges")){this.checkAbort();const{value:s,line:o}=r;if(!M(s)){e.error("parse-error",mt,`an edges element is ${pe(s)}, not an object`,{line:o,element:"edges"}),e.counts.skippedEdges++;continue}if(s["@id"]===void 0||s["@id"]===null){e.error("missing-value",dt,"an edge has no @id",{line:o,element:"edges"}),e.counts.skippedEdges++;continue}this.unknownKeys(s,R8,"edge",o);const l=`edge ${pe(s["@id"])}`,a=this.idOf(s["@id"],(r.inexact&1)!==0,l,o,!0);if(a===null){e.counts.skippedEdges++;continue}if(i!==null&&!i.has(a))continue;if(s.s===void 0||s.s===null||s.t===void 0||s.t===null){e.error("missing-value",Zn,`${l} has no ${s.s===void 0||s.s===null?"s":"t"}`,{line:o,element:l}),e.counts.skippedEdges++;continue}const c=this.idOf(s.s,(r.inexact&2)!==0,l,o),d=c===null?null:this.idOf(s.t,(r.inexact&4)!==0,l,o);if(c===null||d===null){e.counts.skippedEdges++;continue}if(this.edgeRows.has(a)){e.error("validation-error",Ai,`${l} is declared more than once; the later edge is skipped`,{line:o,element:l}),e.counts.skippedEdges++;continue}if(!this.endpoint(c,l,o)||!this.endpoint(d,l,o)){e.counts.skippedEdges++;continue}let u;try{u=this.weightOf(a)}catch(p){e.recordError(p,{line:o,element:l}),e.counts.skippedEdges++;continue}const f=n.edgeCount;let h;try{h=this.direction.addEdge(this.sinkId(c),this.sinkId(d),"directed",u,{line:o,element:l})}catch(p){e.recordError(p,{line:o,element:l}),e.counts.skippedEdges++;continue}u!==void 0&&(this.weighted=!0),e.counts.edges+=n.edgeCount-f,this.edgeRows.set(a,h),this.edgeIdHandle=this.structural("edge",this.edgeIdHandle,{name:Xt("id","cx",p=>n.edgeColumn(p)!==A),dtype:"f64",role:"id",nullable:!0}),n.setEdgeValue(this.edgeIdHandle,h,typeof a=="number"?a:Number(a)),this.writeCore("edge",h,"interaction",s.i,l,o)}}endpoint(e,n,i){if(this.nodeRows.has(e))return!0;if(!this.options.addMissingNodes)return this.report.error("missing-value",Hn.UNKNOWN_NODE,`${n}: the endpoint ${String(e)} is not a node of the graph; the edge is skipped`,{line:i,element:n}),!1;try{this.addNode(e).added&&this.report.counts.nodes++}catch(r){return this.report.recordError(r,{line:i,element:n}),!1}return!0}edgeWeights(){const{weightFrom:e}=this.options,n=new Map;if(e===null)return new Map;for(const{value:i,line:r}of this.doc.attributes.edge.get(e)??[]){const s=M(i)?this.scopePeek(i.s):0;if(!M(i)||s===0||i.v===void 0||i.v===null)continue;const o=qe(i.v);for(const l of Array.isArray(i.po)?i.po:[i.po])this.chooseWeight(n,l,{scope:s,value:o},r,e)}return new Map([...n].map(([i,{value:r}])=>[i,r]))}chooseWeight(e,n,i,r,s){const o=Ee(n),l=o===null?void 0:e.get(o);o===null||l!==void 0&&l.scope>i.scope||(l?.scope===i.scope&&JSON.stringify(l.value)!==JSON.stringify(i.value)&&this.report.warnOnce("validation-error",fe,`edge ${pe(n)} has the attribute "${s}" twice; the later value wins`,{line:r,element:s},`${fe}:edge:${s}`),e.set(o,i))}weightOf(e){if(this.options.weightFrom===null)return;const n=this.weights.get(e);if(!(typeof n=="string"&&qI(n)))return of(n)}readNetworkAttributes(){for(const[e,n]of this.doc.attributes.network){let i=null,r=0;for(const{value:c,line:d}of n){if(!M(c))continue;const u=this.scopeOf(c.s);if(u!==0){if(c.v===void 0){this.report.error("missing-value",ie,`a networkAttributes element for "${e}" has no v; skipped`,{line:d,element:e});continue}i!==null&&u===r&&JSON.stringify(qe(i.v))!==JSON.stringify(qe(c.v))&&this.report.warnOnce("validation-error",fe,`the network attribute "${e}" is given twice; the later value wins`,{line:d,element:e},`${fe}:network:${e}`),u>=r&&(i=c,r=u)}}if(i?.v===void 0||i.v===null)continue;const s=jc(i.d);s===null&&this.report.warnOnce("unsupported",Zt,`the network attribute "${e}" declares a data type CX does not define; kept as text`,{element:e},`${Zt}:network:${e}`);const o=s??{scalar:"string",list:!1},l=zw(i.v,o,this.options.long,c=>{this.precision(e,c)});if(l===tl)continue;if(l===Vt){this.report.error("validation-error",ie,`the network attribute "${e}" is ${pe(i.v)}, not a ${yo(o)}; unset`,{element:e});continue}if((e==="name"||e==="description")&&typeof l=="string")continue;const a=Gh(o.scalar,this.options.long);try{this.sink.setGraphValue(e,l,{dtype:o.list?"list":a,...o.list?{itemDtype:a}:{},origin:{format:He,id:null,type:yo(o)}})}catch(c){this.report.recordError(c,{element:e})}}}readVisualProperties(){const e=Te(this.doc,"cyVisualProperties"),n=VI.reduce((o,l)=>o+(this.doc.kept.get(l)?.length??0),0),i=new Set(this.plan.views.slice(0,1)),r=o=>o===null||i.size===0||i.has(o);this.keepVisualPropertiesForStyles(e,r);const s={columns:{node:new Map,edge:new Map},network:new Map,defaults:0,mappings:0,dependencies:0};for(const{value:o}of e)M(o)&&r(Bw(o))&&this.collectVisualProperties(o,s);this.writeBypassColumns(s),this.warnStylesNotImported(s,n)}keepVisualPropertiesForStyles(e,n){const i=new Set,r=e.map(a=>a.value).filter(a=>{const c=M(a)?Bw(a):null;return n(c)?!0:(i.add(c),!1)}),{weightFrom:s}=this.options,o=Te(this.doc,"cySubNetworks").length>0,l=i.size>0?{entries:r,otherViews:i.size,weightFrom:s,collection:o}:{entries:r,weightFrom:s,collection:o};this.report.keepForStyles(l)}collectVisualProperties(e,n){const i=M(e.properties)?e.properties:{};if(n.mappings+=M(e.mappings)?Object.keys(e.mappings).length:0,n.dependencies+=M(e.dependencies)?Object.keys(e.dependencies).length:0,e.properties_of==="nodes"||e.properties_of==="edges")this.collectElementProperties(e,i,n);else if(e.properties_of==="network")for(const[r,s]of Object.entries(i))n.network.set(r,Hw(s));else n.defaults+=Object.keys(i).length}collectElementProperties(e,n,i){const r=e.properties_of==="nodes"?"node":"edge",s=Ee(e.applies_to),o=r==="node"?this.nodeRows:this.edgeRows,l=s===null?void 0:o.get(s);if(l===void 0){(s===null||!(r==="node"?this.rootNodes:this.rootEdges).has(s))&&this.dangle(`${r} visual property entry`);return}for(const[a,c]of Object.entries(n)){const d=i.columns[r].get(a)??[];d.push([l,Hw(c)]),i.columns[r].set(a,d)}}writeBypassColumns(e){for(const n of["node","edge"])for(const[i,r]of e.columns[n]){const s=g1(this.sink,n,{name:i,dtype:"string",nullable:!0,origin:{format:He,id:i,namespace:Gw}},this.report);for(const[o,l]of r)n==="node"?this.sink.setNodeValue(s,o,l):this.sink.setEdgeValue(s,o,l)}for(const[n,i]of e.network)try{this.sink.setGraphValue(n,i,{dtype:"string",origin:{format:He,id:null,namespace:Gw}})}catch(r){this.report.recordError(r,{element:n})}}warnStylesNotImported(e,n){const{defaults:i,mappings:r,dependencies:s}=e;if(i+r+s+n===0)return;const o=[`cyVisualProperties: ${i} default${O(i)}, ${r} mapping${O(r)}, ${s} dependenc(ies)`];n>0&&o.push(`${n} table style element${O(n)}`),this.report.warning("unsupported",to,`the file's style rules are not applied (${o.join("; ")}); they are kept in meta.extra.cx`,{element:"cyVisualProperties"})}readStyleBlock(){const e=$I(this.doc.kept.get(Z));e!==null&&this.sink.setGraphValue(Z,e,{dtype:"string",origin:{format:He,id:null}})}readProvenance(){for(const i of["citations","supports"])this.extensionTable(`cx:${i}`,Te(this.doc,i));for(const[i,r,s]of[["nodeCitations","node","citations"],["edgeCitations","edge","citations"],["nodeSupports","node","supports"],["edgeSupports","edge","supports"]])this.linkColumn(i,r,s);const e=[];for(const{value:i}of Te(this.doc,"functionTerms")){if(!M(i))continue;const r=Ee(i.po),s=r===null?void 0:this.nodeRows.get(r);if(s===void 0){(r===null||!this.rootNodes.has(r))&&this.dangle("functionTerms entry");continue}const{po:o,...l}=i;e.push([s,qe(l)])}this.writeColumn("node","functionTerm","json",null,e);const n=[];for(const{value:i}of Te(this.doc,"reifiedEdges")){if(!M(i))continue;const r=Ee(i.node),s=Ee(i.edge),o=r===null?void 0:this.nodeRows.get(r),l=s===null?void 0:this.edgeRows.get(s);if(o===void 0||l===void 0){(r===null||!this.rootNodes.has(r)||s===null||!this.rootEdges.has(s))&&this.dangle("reifiedEdges entry");continue}n.push([o,l])}if(n.length>0){const{handle:i}=he(this.sink,"node",{name:"reifiedEdge",dtype:"u32",refersTo:"edge",nullable:!0,origin:{format:He,namespace:"reifiedEdges"}},this.report);for(const[r,s]of n)this.sink.setNodeValue(i,r,s)}}extensionTable(e,n){const i=n.map(c=>c.value).filter(M);if(i.length===0)return;const r=[...new Set(i.flatMap(c=>Object.keys(c)).filter(c=>c!=="@id"))],s=new Set(["id"]),o=[{name:"id",dtype:"f64",nullable:!0},...r.map(c=>{const d=Xt(c,null,u=>s.has(u));return s.add(d),d!==c&&this.report.warning("coercion",ln,`${e} column "${c}" renamed to "${d}": the table's own id column holds that name`,{element:c}),{name:d,dtype:"json",nullable:!0}})],l=this.sink.addExtensionTable(e,o),a=c=>{this.precision(e,c)};for(const c of i){const d=Ee(c["@id"]);typeof d=="string"&&a(d),this.sink.addExtensionRow(l,[d===null?null:Number(d),...r.map(u=>c[u]===void 0?null:qe(c[u],a))])}}linkColumn(e,n,i){const r=n==="node"?this.nodeRows:this.edgeRows,s=n==="node"?this.rootNodes:this.rootEdges,o=new Map;for(const{value:l}of Te(this.doc,e)){if(!M(l))continue;const a=Array.isArray(l.po)?l.po:[l.po],c=(Array.isArray(l[i])?l[i]:[]).map(Ee).filter(d=>d!==null).map(Number);for(const d of a){const u=Ee(d),f=u===null?void 0:r.get(u);if(f===void 0){(u===null||!s.has(u))&&this.dangle(`${e} entry`);continue}o.set(f,[...o.get(f)??[],...c])}}this.writeColumn(n,i,"list","f64",[...o])}writeColumn(e,n,i,r,s){if(s.length===0)return;const o={name:n,dtype:i,...r===null?{}:{itemDtype:r},nullable:!0,origin:{format:He,namespace:"provenance"}},{handle:l}=he(this.sink,e,o,this.report);for(const[a,c]of s)e==="node"?this.sink.setNodeValue(l,a,c):this.sink.setEdgeValue(l,a,c)}setMeta(){const e=c=>{let d=null;for(const{value:u}of this.doc.attributes.network.get(c)??[])if(M(u)&&typeof u.v=="string"){const f=this.scopePeek(u.s);if(f===2)return u.v;f===1&&(d??=u.v)}return d},n=Object.fromEntries([...this.doc.kept].filter(([c])=>c!==Z)),i=Te(this.doc,"cyGroups").map(c=>qe(c.value)),r={};i.length>0&&(r.groups=i),this.plan.subnetwork!==null&&(r.subnetwork=this.plan.subnetwork);for(const c of x8)c in r&&this.doc.kept.has(c)&&this.report.warning("unsupported",vt,`the aspect "${c}" is not kept: meta.extra.cx.${c} holds the importer's own ${c==="groups"?"cyGroups":"subnetwork"} data`,{element:c});Object.assign(n,r);const{weightFrom:s}=this.options,o=this.plan.name??e("name"),l=e("description"),a={sourceFormat:He,sourceVersion:"1",idType:this.idType,...o===null?{}:{name:o},...l===null?{}:{description:l},...this.weighted&&s!==null?{weightOrigin:{format:He,id:null,title:s,type:"double",namespace:null}}:{},extra:{cx:n}};this.sink.setMeta(a)}}async function Kw(t,e,n,i){const r=tt(e,BI),s=MI(e?.zAs),o=new ne(He,r.errorLimit);St(e,o,v8);const l=await JI(t,o,r),a=ZI(l,o),c=i(a,o),d=[];return c.forEach((u,f)=>{const h=f===0?o:new ne(He,r.errorLimit),p=n(u);_t(p,e,h,!0),new ej(p,h,r,s,l,a[u]).build(),F(r.signal),d.push(h.finish())}),d}const tj=Object.freeze({format:He,options:Object.freeze(["zAs"]),extensions:Object.freeze([".cx"]),mimeTypes:Object.freeze(["application/json"]),styles:DG,sniff(t){const e=/^\s*\[\s*\{\s*"((?:[^"\\]|\\.)*)"\s*:/.exec(h1(t));return e===null?0:M8.has(e[1])?.95:YI.has(e[1])?.7:0},async import(t,e,n){const[i]=await Kw(t,n,()=>e,(r,s)=>{const o=ml(r.map(l=>l.name),n,s);return r.length>1&&!io(n)&&s.warning("unsupported",Qn,`the collection holds ${r.length} subnetworks; graph ${o} is read and ${r.length-1} skipped (importAllGraphs() reads every one)`),[o]});return i},importAll(t,e,n){return Kw(t,n,e,i=>i.map(r=>r.index))},async listGraphs(t,e){const n=tt(e,BI),i=new ne(He,n.errorLimit),r=await JI(t,i,n),s=Te(r,"nodes").length,o=Te(r,"edges").length;return ZI(r,i).map(l=>Object.freeze({index:l.index,name:l.name,nodes:Yw(l.nodes,s),edges:Yw(l.edges,o)}))}}),ub=Object.freeze({UNDIRECTED_AS_DIRECTED:"W_CX2_UNDIRECTED_AS_DIRECTED",JSON_AS_STRING:"W_CX2_JSON_AS_STRING",NONFINITE_AS_NULL:"W_CX2_NONFINITE_AS_NULL",MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,WEIGHT_KEY_CLASH:w.WEIGHT_KEY_CLASH,HIERARCHY_DROPPED:w.HIERARCHY,TEMPORAL_DROPPED:w.TEMPORAL,ROLE_DROPPED:w.ROLE,DTYPE_UNSUPPORTED:w.DTYPE,ID_CHARSET:w.ID_CHARSET,ID_MANGLED:w.ID_MANGLED,EDGE_IDS_GENERATED:w.EDGE_IDS_GENERATED}),QI=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"required",idCharset:"integer",dtypes:["string","f64","i32","bool"],components:!1,lists:!0,json:!1,defaults:!0,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),nj=new Set(["label","position","id"]),ij=Object.freeze({label:"name",position:jy}),e$=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),rj=new Set(["visualProperties","visualEditorProperties"]),sj=new Set([Z,"nodes","edges","attributeDeclarations","networkAttributes","nodeBypasses","edgeBypasses","metaData","status"]),Es="weight";function Zl(t){return t.meta.origin?.namespace===kI}function Sg(t){return t.meta.extra.cytoscape==="z"}function oj(t){const{dtype:e,itemDtype:n}=t.meta;if(!(e==="f32"||e==="f64"||e==="list"&&(n==="f32"||n==="f64")))return 0;let r=0;for(let s=0;s<t.length;s++){if(!t.isSet(s))continue;const o=t.value(s);e==="list"?o.some(l=>!Number.isFinite(l))&&r++:Number.isFinite(o)||r++}return r}function Og(t,e,n,i=new Set){const r=[],s=new Set(i),o=[...t].filter(l=>!e(l));for(const l of o)s.add(n(l));for(const l of o){const a=n(l),{origin:c}=l.meta;let d=a;const u=c?.format===Bt&&typeof c.id=="string"?c.id:null;u!==null&&u.length>0&&u!==a&&!s.has(u)&&(d=u,s.add(u)),r.push({column:l,name:a,key:d,d:QT(l),jsonText:l.meta.dtype==="json"})}return r}function lj(t,e,n,i){let r=null;const s=new Set([...t.nodes,...t.edges].filter(l=>Zl(l)||Sg(l)).map(l=>l.meta.name));for(const l of Un(t,QI,e,{roles:nj,roleNames:ij,edgeRoleNames:{}}))if(aj(l,s)){if(l.code===w.JSON){const a=l.column===null?"a column":`column "${l.column}"`;i(ub.JSON_AS_STRING,`${a} holds nested values; written as a string attribute holding their JSON text`,l.column,l.count);continue}l.code===w.MIXED_DIRECTION_ERROR&&r===null&&(r=new N("E_DIRECTED",l.message,{reason:"mixed direction"})),n.push(l)}const o=t.edges.byRole("label");return o!==null&&i(w.ROLE,`edge column "${o.meta.name}" (label) is written as a plain attribute; CX2 edges have no label slot and the role is lost`,o.meta.name,o.length-o.nullCount),r}function aj(t,e){return t.column!==null&&e.has(t.column)&&(t.code===w.JSON||t.code===w.DTYPE)?!1:t.code!==w.ID_CHARSET&&t.code!==w.ID_MANGLED}function cj(t,e,n,i,r){let s=0;for(const o of e)s+=oj(o.column);for(let o=0;o<t.edgeCount;o++)n.isExplicit(o)&&!Number.isFinite(n.value(o))&&s++;i!==null&&(s+=o3(i)),s>0&&r(ub.NONFINITE_AS_NULL,`${s} NaN or infinite value${O(s)} cannot be written in CX2; written as null, they read back unset`,null,s)}function dj(t,e,n){const i=t.edges.get(Es);return i!==null&&i.meta.role===null&&n(w.WEIGHT_KEY_CLASH,e.weighted?`edge column "${Es}" is not written: the explicit weights are written under that name`:`edge column "${Es}" reads back as the edge weight`,Es,null),Og(t.edges,r=>r.meta.role!==null&&(e$.has(r.meta.role)||r.meta.role==="id")||Zl(r)||e.weighted&&r===i,r=>r.meta.name,e.weighted?new Set([Es]):new Set)}function t$(t,e){const n=[],i=(y,b,_=null,S=null)=>{n.push(Object.freeze({code:y,message:b,column:_,count:S}))};let r=lj(t,e,n,i);const s=Gt(t);t1(t,s,e,ub.UNDIRECTED_AS_DIRECTED,i);const o=ZT(t,e,"CX2",kt,i),l=o instanceof N?null:o;o instanceof N&&(r??=o);const a=Ot(t),c=t.nodes.byRole("label"),d=Og(t.nodes,y=>y.meta.role!==null&&e$.has(y.meta.role)||Zl(y)||Sg(y),y=>y===c&&!t.nodes.has("name")?"name":y.meta.name,l!==null&&l.changed>0?new Set([kt]):new Set),u=dj(t,a,i),f=Og(t.graph,y=>y.meta.name===Z,y=>y.meta.name).map(y=>({...y,key:y.name})),h=t.nodes.byRole("position");cj(t,[...d,...u,...f],a,h,i);const p=e1(t,i,l),g=[...t.nodes].find(Sg)??null,m=h!==null&&g===null&&h.meta.extra.sourceDims===3;return{notes:n,fatal:r,ids:l,folding:s,weights:a,nodeAttrs:d,edgeAttrs:u,graphAttrs:f,nodeBypasses:[...t.nodes].filter(Zl),edgeBypasses:[...t.edges].filter(Zl),position:h,positionZ:m,z:g,edgeIds:p,originalIds:l!==null&&l.changed>0}}function n$(t,e){const{column:n}=t;if(!n.isSet(e))return;const i=n.value(e);if(t.jsonText)return JSON.stringify(i);if(n.meta.dtype==="list"||n.meta.components>1){const r=Array.from(i);return t.d==="string"?JSON.stringify(r):r.some(s=>typeof s=="number"&&!Number.isFinite(s))?null:r}return typeof i=="number"&&!Number.isFinite(i)?null:i}function Ng(t,e){const n={};for(const i of t){const r={d:i.d};e&&i.key!==i.name&&(r.a=i.key);const s=i.column.meta.default;e&&s!==void 0&&s!==null&&uj(mu(i.d),s)&&(r.v=s),n[i.name]=r}return n}function uj(t,e){if(t===null)return!1;if(t.list)return Array.isArray(e);switch(t.scalar){case"string":return typeof e=="string";case"boolean":return typeof e=="boolean";default:return typeof e=="number"&&Number.isFinite(e)}}function i$(t,e){let n=null;for(const i of t){const r=n$(i,e);r!==void 0&&(n??={},n[i.key]=r)}return n}function fj(t,e){const n=Ng(e.graphAttrs,!1),i={};for(const s of e.graphAttrs){const o=n$(s,0);o!==void 0&&(i[s.name]=o)}const{meta:r}=t;for(const[s,o]of[["name",r.name],["description",r.description]])o!==null&&!(s in i)&&!(s in n)&&(i[s]=o,n[s]={d:"string"});return{network:i,networkDecls:n}}function hj(t,e,n){const i=Ng(t.nodeAttrs,!0);t.originalIds&&(i[kt]={d:"string"});const r=Ng(t.edgeAttrs,!0);t.weights.weighted&&(r[Es]={d:"double"});const o={...M(e.declarations)?e.declarations:{}};for(const[l,a]of[["networkAttributes",n],["nodes",i],["edges",r]])Object.keys(a).length>0&&(o[l]=a);return o}function pj(t,e,n,i,r){const s={id:t.edgeIds[r],s:e.idAt(n[r]),t:e.idAt(i[r])};let o=i$(t.edgeAttrs,r);if(t.weights.isExplicit(r)){const l=t.weights.value(r);o??={},o[Es]=Number.isFinite(l)?l:null}return o!==null&&(s.v=o),s}function Xw(t){return t.filter(([,e])=>e>0).map(([e,n])=>[e,n])}function*gj(t,e,n=null){if(e.fatal!==null)throw e.fatal;const{ids:i}=e;if(i===null)throw new N("E_INVALID_ID","node ids cannot be written as CX2 integers",{reason:"charset"});const r=[];for(let S=0;S<t.edgeCount;S++)e.folding.folded(S)||r.push(S);const{network:s,networkDecls:o}=fj(t,e),{meta:l}=t,a=M(l.extra.cx2)?l.extra.cx2:{},c=l.sourceFormat===Bt&&M(a.opaque)?a.opaque:{},d=hj(e,a,o),{bypassOf:u,nodeBypassRows:f,edgeBypassRows:h,opaqueAspects:p}=mj(t,e,n,c),g=Object.keys(d).length>0,m=Object.keys(s).length>0,y=[...Xw([["attributeDeclarations",g?1:0],["networkAttributes",m?1:0]]),["nodes",t.nodeCount],["edges",r.length],...Xw([["nodeBypasses",f.length],["edgeBypasses",h.length]]),...p.map(([S,T])=>[S,T.length])];yield`[{"CXVersion":"2.0","hasFragments":false},
|
|
45
|
+
`,yield`{"metaData":${Di(y.map(([S,T])=>({name:S,elementCount:T})))}},
|
|
46
|
+
`,g&&(yield`{"attributeDeclarations":[${Di(d)}]},
|
|
47
|
+
`),m&&(yield`{"networkAttributes":[${Di(s)}]},
|
|
48
|
+
`),yield*Gl("nodes",t.nodeCount,S=>Di(yj(e,i,S)));const{src:b,dst:_}=t.edgeList();yield*Gl("edges",r.length,S=>Di(pj(e,i,b,_,r[S]))),f.length>0&&(yield*Gl("nodeBypasses",f.length,S=>{const T=f[S];return Di({id:i.idAt(T),v:u("node",T)})})),h.length>0&&(yield*Gl("edgeBypasses",h.length,S=>{const T=h[S];return Di({id:e.edgeIds[T],v:u("edge",T)})}));for(const[S,T]of p)yield*Gl(S,T.length,$=>Di(T[$]));yield`{"status":[{"error":"","success":true}]}]
|
|
49
|
+
`}function mj(t,e,n,i){const r=(d,u)=>{if(n===null)return Ej(d==="node"?e.nodeBypasses:e.edgeBypasses,u);const f=n.bypasses[d][u];return f===null||f.size===0?null:Object.fromEntries(f)},s=(d,u)=>{if(n===null)return bj(d==="node"?e.nodeBypasses:e.edgeBypasses,u);const f=[];for(let h=0;h<u;h++)r(d,h)!==null&&f.push(h);return f},o=s("node",t.nodeCount),l=s("edge",t.edgeCount).filter(d=>!e.folding.folded(d)),a=Object.entries(i).filter(d=>!sj.has(d[0])&&!(n!==null&&rj.has(d[0]))&&Array.isArray(d[1]));if(n!==null){const d=g4(n.style);a.push(["visualProperties",d.visualProperties],["visualEditorProperties",d.visualEditorProperties])}const c=ab(t);return c!==null&&a.push([Z,CI(c)]),{bypassOf:r,nodeBypassRows:o,edgeBypassRows:l,opaqueAspects:a}}function Gl(t,e,n){return n1(t,(function*(){for(let r=0;r<e;r++)yield n(r)})())}function yj(t,e,n){const i={id:e.idAt(n)};if(t.position?.isSet(n)===!0){const s=t.position.value(n);Number.isFinite(s[0])&&Number.isFinite(s[1])&&(i.x=s[0],i.y=s[1]===0?0:-s[1],t.positionZ&&Number.isFinite(s[2])&&(i.z=s[2]))}if(t.z?.isSet(n)===!0){const s=t.z.value(n);typeof s=="number"&&Number.isFinite(s)&&(i.z=s)}let r=i$(t.nodeAttrs,n);return t.originalIds&&e.isChanged(n)&&(r??={},r[kt]=String(e.originalAt(n))),r!==null&&(i.v=r),i}function bj(t,e){const n=[];if(t.length===0)return n;for(let i=0;i<e;i++)t.some(r=>r.isSet(i))&&n.push(i);return n}function Ej(t,e){const n={};for(const i of t)if(i.isSet(e)){const r=i.meta.origin?.id;n[typeof r=="string"&&r.length>0?r:i.meta.name]=i.value(e)}return n}const wj=Object.freeze({format:Bt,options:Object.freeze([]),capabilities:QI,styles:Object.freeze({capabilities:PG}),check(t,e){const n=If(t,e?.styles,"cx2");return Object.freeze([...t$(n?.snapshot??t,ft(e)).notes,...n?.notes??[]])},export(t,e){return ti(qw(t,e))},exportToString(t,e){return ni(qw(t,e))}});function qw(t,e){const n=If(t,e?.styles,"cx2"),i=n?.snapshot??t;return gj(i,t$(i,ft(e)),n?.styled??null)}const ws="http://graphml.graphdrawing.org/xmlns",Jw="http://www.yworks.com/xml/graphml",Nd="http://www.w3.org/2001/XMLSchema-instance",_j="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd",ot="graphml",Sj=Object.freeze([".graphml",".xml"]),Oj=Object.freeze(["application/graphml+xml","application/xml","text/xml"]),Ps="graphty:originalId",Nj="graphty.originalId",fb="id",hb="sourceport",pb="targetport",gb="parent",Aj="graphty.hyperedge",hr="label",r$=new Set([fb,hb,pb]),s$=new Set([gb]),o$="graphml",U=Object.freeze({...xn,...Pn,COLUMN_TYPE:sy,XML_SYNTAX:Ku,XML_NESTING:Xu,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,ENCODING_CONFLICT:hl,EMPTY_INPUT:Ut,NOT_GRAPHML:"E_NOT_GRAPHML",NAMESPACE:"W_GRAPHML_NAMESPACE",NO_GRAPH:ls,KEY_MISSING_ID:"E_GRAPHML_KEY_MISSING_ID",DUPLICATE_KEY:FL,KEY_DOMAIN_UNSUPPORTED:"W_GRAPHML_KEY_DOMAIN_UNSUPPORTED",MISSING_ID:dt,MISSING_ENDPOINT:Zn,UNKNOWN_NODE:"E_UNKNOWN_NODE",GRAPH_ENDPOINT:"W_GRAPHML_GRAPH_ENDPOINT",UNKNOWN_PARENT:Ui,DUPLICATE_ATTRIBUTE:fe,UNKNOWN_KEY:"E_GRAPHML_UNKNOWN_KEY",KEY_DECLARED_LATE:"W_GRAPHML_KEY_DECLARED_LATE",KEY_DOMAIN:"W_GRAPHML_KEY_DOMAIN",DATA_MISSING_KEY:"E_GRAPHML_DATA_MISSING_KEY",KEY_FOR_INVALID:"E_GRAPHML_KEY_FOR_INVALID",NESTED_GRAPH_DATA:"W_GRAPHML_NESTED_GRAPH_DATA",HYPEREDGE_DATA_DROPPED:"W_GRAPHML_HYPEREDGE_DATA_DROPPED",DATA_NESTED:"E_GRAPHML_DATA_NESTED",DATA_STRUCTURED:"W_GRAPHML_DATA_STRUCTURED",DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,INVALID_DIRECTED:"E_GRAPHML_INVALID_DIRECTED",INVALID_EDGEDEFAULT:"E_GRAPHML_INVALID_EDGEDEFAULT",EDGEDEFAULT_MISSING:"W_GRAPHML_EDGEDEFAULT_MISSING",MULTIPLE_GRAPHS:Qn,COUNT_HINT:Hd,COUNT_MISMATCH:Fs,HYPEREDGE:EA,HYPEREDGE_SKIPPED:"W_GRAPHML_HYPEREDGE_SKIPPED",HYPEREDGE_ENDPOINT:"E_GRAPHML_HYPEREDGE_ENDPOINT",PORT_DECLARATION:"W_GRAPHML_PORT_DECLARATION",DANGLING_REFERENCE:Xi,EDGE_GRAPH_DROPPED:"W_GRAPHML_EDGE_GRAPH_DROPPED",HUB_ID_CLASH:"W_GRAPHML_HUB_ID_CLASH",ORIGINAL_ID_IGNORED:"W_GRAPHML_ORIGINAL_ID_IGNORED",YFILES_VALUE:"W_GRAPHML_YFILES_VALUE",PARSE_HINT_IGNORED:"W_GRAPHML_PARSE_HINT_IGNORED",UNKNOWN_XML_ATTRIBUTE:Bd,LOCATOR_DROPPED:"W_GRAPHML_LOCATOR_DROPPED",DESC_DROPPED:"W_GRAPHML_DESC_DROPPED",UNKNOWN_ELEMENT:vt,STRAY_TEXT:qu,ID_MERGED:Rn,OPTION_IGNORED:Jt,YFILES_SKIPPED:"W_GRAPHML_YFILES_SKIPPED",COLUMN_RENAMED:ln,ROLE_TAKEN:bn,UNKNOWN_ATTR_TYPE:Zt,BAD_DEFAULT:Ho,PRECISION:re,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or}),pr=Object.freeze({YFILES_JSON:"W_GRAPHML_YFILES_JSON",MUTUAL_AS_UNDIRECTED:TA,PARENTS_DROPPED:ly,ROLE_DROPPED:oy,HIERARCHY_REORDERED:"W_GRAPHML_HIERARCHY_REORDERED",PARENT_CYCLE:"W_GRAPHML_PARENT_CYCLE",ID_TEXT_TYPE:cs,EDGE_ID_TEXT:"W_GRAPHML_EDGE_ID_TEXT",YFILES_GRAPHICS_STALE:"W_GRAPHML_YFILES_GRAPHICS_STALE",YFILES_TREE:"E_GRAPHML_YFILES_TREE"}),Tj=new Set(["id","label","name","xlink:href","cy:nodeId"]),Ij=new Set(["id","label","name","source","target","weight","cy:directed","xlink:href","cy:edgeId"]),$j=new Set(["name","label","type","value","cy:type","cy:elementType","cy:hidden","cy:equation","cy:editable"]),Cj=/^(1|true|yes)$/i;function Si(t){return t!=null&&Cj.test(t.trim())}function vj(t,e){const n=t.indexOf(":");if(n<=0)return t;const i=t.slice(0,n);return i==="xlink"||e.get(i)===sb?`xlink:${t.slice(n+1)}`:t}const Zw=new Map;class Dj{constructor(e){this.frames=[],this.scopes=[],this.rootGraph=null,this.nodes=[],this.edges=[],this.graphs=[],this.cytoscape=!1,this.xgmmlNamespace=!1,this.rootPrefix=null,this.rdf={},this.rdfXml=null,this.doctypeText=null,this.rdfElement=null,this.report=e}document(){const e=this.rootGraph;return e===null?this.report.fail(j.NO_GRAPH,"the document has no <graph> element"):{root:e,nodes:this.nodes,edges:this.edges,graphs:this.graphs,cytoscape:this.cytoscape,xgmmlNamespace:this.xgmmlNamespace,rdf:this.rdf,rdfXml:this.rdfXml,doctype:this.doctypeText}}doctype(e){this.doctypeText??=e}start(e,n,i){this.enterScope(n);const r=this.frames.at(-1)??null;if(r===null){this.startRoot(e,n,i);return}if(r.kind==="skip"){this.frames.push(r);return}if(r.kind==="capture"){this.capture(r,e,n);return}const s=this.normalize(n),o=this.isXgmmlName(e)?Rs(e):e;switch(r.kind){case"graph":this.startInGraph(r.graph,e,o,s,i);return;case"node":this.startInElement(r.node,e,o,s,i);return;case"edge":this.startInElement(r.edge,e,o,s,i);return;case"att":this.startInAtt(r,e,o,s,i);return;case"graphics":this.startInGraphics(r.target,e,o,s,i);return;case"line":if(o==="point"){r.points.push(Object.fromEntries(s)),this.frames.push({kind:"skip"});return}this.unknownElement(e,i);return;default:{const l=r;throw new Error(`unknown XGMML frame ${String(l)}`)}}}end(e,n){this.scopes.pop();const i=this.frames.pop(),r=this.frames.at(-1)??null;switch(i?.kind){case"capture":if(i.att.xml=`${i.att.xml??""}</${e}>`,i.depth--,i.depth>0){this.frames.push(i),this.rdfElement=null;return}i.att.xml=Rj(i.att.xml,i.start,i.scope),i.att.name==="networkMetadata"&&(this.rdfXml=i.att.xml),this.rdfElement=null;return;case"att":r?.kind==="graphics"&&this.graphicsAtt(r.target,i.att);return;case"line":r?.kind==="graphics"&&(r.target.graphics={...r.target.graphics,Line:i.points});return}}text(e,n){const i=this.frames.at(-1)??null;if(!(i===null||i.kind==="skip")){if(i.kind==="capture"){i.att.xml=`${i.att.xml??""}${nt(e)}`,this.captureRdfText(e);return}Tr(e)||(i.kind==="att"&&(i.att.text+=e),this.report.warnOnce("validation-error",j.STRAY_TEXT,i.kind==="att"?"text inside <att> is ignored; an XGMML value is the value attribute":"text where XGMML allows only elements was ignored",{line:n}))}}enterScope(e){const n=this.scopes.at(-1)??Zw;let i=n;for(const[r,s]of e)(r==="xmlns"||r.startsWith("xmlns:"))&&(i===n&&(i=new Map(n)),i.set(r==="xmlns"?"":r.slice(6),s));this.scopes.push(i)}get scope(){return this.scopes.at(-1)??Zw}normalize(e){const n=new Map,{scope:i}=this;for(const[r,s]of e)n.set(vj(r,i),s);return n}startRoot(e,n,i){const r=Rs(e),s=e.includes(":")?e.slice(0,e.indexOf(":")):null;for(const a of n.keys())(a==="xmlns:cy"||a.startsWith("cy:"))&&(this.cytoscape=!0);this.rootPrefix=s;const o=s===null?"xmlns":`xmlns:${s}`;this.xgmmlNamespace=n.get(o)===_a,r!=="graph"&&this.report.fail(j.NO_GRAPH,`the root element is <${e}>, not <graph>; an XGMML graph embedded in another document is not read`,{line:i});const l=this.newGraph(this.normalize(n),i,null,null);this.rootGraph=l,this.frames.push({kind:"graph",graph:l})}newGraph(e,n,i,r){const s={id:e.get("id")??null,label:e.get("label")??null,href:e.get("xlink:href")??null,registered:e.get("cy:registered")??null,attrs:e,atts:[],graphics:null,owner:i,parent:r,members:[],subgraphs:[],line:n};if(!this.cytoscape)for(const o of e.keys())o.startsWith("cy:")&&(this.cytoscape=!0);return this.graphs.push(s),s}startInGraph(e,n,i,r,s){switch(i){case"node":this.beginNode(e,r,s);return;case"edge":this.beginEdge(e,r,s);return;case"att":{const o=this.newAtt(r,s);e.atts.push(o),this.beginAtt(o,r,"graph");return}case"graphics":this.beginGraphics(e,r,s);return;default:this.unknownElement(n,s)}}startInElement(e,n,i,r,s){switch(i){case"att":{const o=this.newAtt(r,s);e.atts.push(o),this.beginAtt(o,r,e.kind);return}case"graphics":this.beginGraphics(e,r,s);return;default:this.unknownElement(n,s)}}startInAtt(e,n,i,r,s){const{att:o}=e,l=this.isXgmmlName(n);if(i==="att"&&l){const c=this.newAtt(r,s);o.children.push(c),this.beginAtt(c,r,e.owner==="graphics"?"graphics":"att");return}if(i==="graph"&&l){o.hasGraph=!0,this.beginNestedGraph(e,r,s);return}o.xml??="";const a={kind:"capture",att:o,depth:0,start:o.xml.length,scope:this.scope};this.frames.push(a),this.capture(a,n,r)}isXgmmlName(e){const n=e.indexOf(":");if(n<0)return!0;const i=e.slice(0,n);return i===this.rootPrefix||this.scope.get(i)===_a}beginNestedGraph(e,n,i){const r=this.attHolder();if(r===null||r.kind==="edge"||e.owner==="graphics"){this.report.warnOnce("unsupported",j.EDGE_NESTED_GRAPH,"a graph nested in an edge's (or a graphics) att has no model and was skipped with its content",{line:i}),this.frames.push({kind:"skip"});return}if(r.kind==="node"){const o=this.newGraph(n,i,r.node,r.node.graph);r.node.nested.push(o),this.frames.push({kind:"graph",graph:o});return}const s=this.newGraph(n,i,null,r.graph);r.graph.subgraphs.push(s),this.frames.push({kind:"graph",graph:s})}attHolder(){for(let e=this.frames.length-1;e>=0;e--){const n=this.frames[e];if(n.kind==="graph"||n.kind==="node"||n.kind==="edge")return n}return null}unknownElement(e,n){this.report.warnOnce("unsupported",j.UNKNOWN_ELEMENT,`element <${e}> is not XGMML here and was skipped with its content`,{line:n,element:e},`${j.UNKNOWN_ELEMENT}:${e}`),this.frames.push({kind:"skip"})}beginNode(e,n,i){const r=n.get("xlink:href")??null;let s=n.get("id")??null;const o=n.get("label")??null,l=n.get("name")??null,a=o??l;if(r!==null&&s!==null&&this.idAndHref("node",s,r,i),r===null&&s===null){if(a===null||a.length===0){this.report.counts.skippedNodes++,this.report.error("missing-value",j.MISSING_ID,"<node> without an id or a label",{line:i}),this.frames.push({kind:"skip"});return}this.report.warning("validation-error",j.ID_FROM_LABEL,`<node> without an id: its label "${a}" is used as the id`,{line:i,element:a}),s=a}const c={kind:"node",id:r===null?s:null,href:r,label:a,name:o!==null?l:null,xmlAttrs:Qw(n,Tj),atts:[],graphics:null,x:null,y:null,z:null,nested:[],graph:e,line:i,viewId:n.get("cy:nodeId")??null};e.members.push(c),r===null&&this.nodes.push(c),this.frames.push({kind:"node",node:c})}beginEdge(e,n,i){const r=n.get("xlink:href")??null,s=n.get("id")??null;r!==null&&s!==null&&this.idAndHref("edge",s,r,i);const o={kind:"edge",id:r===null?s:null,href:r,source:n.get("source")??null,target:n.get("target")??null,label:n.get("label")??null,name:n.get("name")??null,weight:n.get("weight")??null,directed:n.get("cy:directed")??null,xmlAttrs:Qw(n,Ij),atts:[],graphics:null,graph:e,line:i,viewId:n.get("cy:edgeId")??null};e.members.push(o),r===null&&this.edges.push(o),this.frames.push({kind:"edge",edge:o})}idAndHref(e,n,i,r){this.report.warning("validation-error",j.ID_AND_HREF,`<${e}> has both id "${n}" and xlink:href "${i}"; it is read as a reference to ${i} and the id is not used`,{line:r,element:n})}newAtt(e,n){const i={};for(const[r,s]of e)!$j.has(r)&&r!=="xmlns"&&!r.startsWith("xmlns:")&&(i[r]=s);return{name:e.get("name")??e.get("label")??null,type:e.get("type")??null,cyType:e.get("cy:type")??null,elementType:e.get("cy:elementType")??null,value:e.get("value")??null,hidden:Si(e.get("cy:hidden")),equation:Si(e.get("cy:equation")),children:[],extra:i,xml:null,hasGraph:!1,text:"",line:n}}beginAtt(e,n,i){this.frames.push({kind:"att",att:e,owner:i})}capture(e,n,i){let r=`<${n}`;for(const[s,o]of i)r+=` ${s}="${W(o)}"`;if(e.att.xml=`${e.att.xml??""}${r}>`,e.depth++,e.att.name==="networkMetadata"){const s=Rs(n);this.rdfElement=s,this.rdf[s]!==void 0&&(this.rdfElement=null,this.report.warning("validation-error",j.DUPLICATE_ATTRIBUTE,`the network metadata gives <${n}> twice; the first ("${this.rdf[s]}") is kept`,{line:e.att.line,element:s}))}}captureRdfText(e){this.rdfElement!==null&&!Tr(e)&&(this.rdf[this.rdfElement]=(this.rdf[this.rdfElement]??"")+e)}beginGraphics(e,n,i){const r={...e.graphics};for(const[s,o]of n)"x"in e&&(s==="x"||s==="y"||s==="z")?(e[s]!==null&&e[s]!==void 0&&this.duplicateGraphics(s,i),e[s]=o):s!=="xmlns"&&!s.startsWith("xmlns:")&&(s in r&&this.duplicateGraphics(s,i),r[s]=o);e.graphics=r,this.frames.push({kind:"graphics",target:e})}startInGraphics(e,n,i,r,s){switch(i){case"att":{this.frames.push({kind:"att",att:this.newAtt(r,s),owner:"graphics"});return}case"center":"x"in e&&(e.x??=r.get("x")??null,e.y??=r.get("y")??null,e.z??=r.get("z")??null),this.frames.push({kind:"skip"});return;case"Line":case"line":this.frames.push({kind:"line",points:[]});return;default:this.unknownElement(n,s)}}graphicsAtt(e,n){if(n.name==="z"&&"z"in e&&n.children.length===0){e.z??=n.value;return}if(n.name===null){this.report.warnOnce("validation-error",j.BAD_ATT,"a graphics <att> without a name was skipped",{line:n.line},`${j.BAD_ATT}:graphics-name`);return}e.graphics!==null&&n.name in e.graphics&&this.duplicateGraphics(n.name,n.line);const i=e.graphics??={};n.name==="__proto__"?Object.defineProperty(i,n.name,{value:Ag(n),writable:!0,enumerable:!0,configurable:!0}):i[n.name]=Ag(n)}duplicateGraphics(e,n){this.report.warnOnce("validation-error",j.DUPLICATE_ATTRIBUTE,`the graphics property "${e}" is given twice on one element; the later value is kept`,{line:n,element:e},`${j.DUPLICATE_ATTRIBUTE}:graphics:${e}`)}}function kj(t){const e=new Set(t.children.map(i=>i.name));if(e.size!==1)return!1;const[n]=e;return n===null||n===t.name||t.children.length>1}function Ag(t){return l$(t,e=>e.children.length>0?null:e.value!==null?{value:e.value}:{value:Object.keys(e.extra).length>0?{...e.extra}:null})}function l$(t,e){const n=e(t);if(n!==null)return n.value;const i=o=>kj(o)?[]:{},r=i(t),s=[[t,r]];for(let o=s.pop();o!==void 0;o=s.pop()){const[l,a]=o;for(const c of l.children){const d=e(c),u=d===null?i(c):d.value;Array.isArray(a)?a.push(u):a[c.name??""]=u,d===null&&s.push([c,u])}}return r}function Rj(t,e,n){const i=t.slice(e),r=new Set;for(const a of i.matchAll(/<\/?([A-Za-z_][\w.-]*):|\s([A-Za-z_][\w.-]*):[\w.-]+="/g))r.add(a[1]??a[2]);let s="";for(const a of r){const c=n.get(a);a!=="xmlns"&&a!=="xml"&&c!==void 0&&!i.includes(` xmlns:${a}="`)&&(s+=` xmlns:${a}="${W(c)}"`)}if(s.length===0)return t;const o=t.slice(e).search(/[\s>]/),l=e+(o<0?i.length:o);return`${t.slice(0,l)}${s}${t.slice(l)}`}function Qw(t,e){const n=[];for(const[i,r]of t)!e.has(i)&&i!=="xmlns"&&!i.startsWith("xmlns:")&&n.push([i,r]);return n}const a$={string:"string",double:"real",integer:"int",long:"long",boolean:"bool",list:"list"},c$={string:"string",real:"real",integer:"int",boolean:"bool",list:"list",map:"map"};function e_(t){let e,n=null;return t.cyType!==null&&t.cyType.length>0&&(e=a$[t.cyType.trim().toLowerCase()],n=t.cyType),e===void 0&&t.type!==null&&t.type.length>0&&(e=c$[t.type.trim().toLowerCase()],n=t.type),e===void 0?{kind:"string",declared:n,unknown:n??null}:(e==="int"&&t.cyType===null&&t.name?.endsWith(".SUID")===!0&&(e="long"),{kind:e,declared:n,unknown:null})}function Lj(t){if(t===null)return null;const e=a$[t.trim().toLowerCase()]??c$[t.trim().toLowerCase()];return e===void 0||e==="list"||e==="map"?null:e}function jh(t,e){return t===e?t:t==="string"||e==="string"||t==="bool"||e==="bool"?"string":t==="real"||e==="real"?"real":"long"}const Pj=/^[+-]?\d+$/,xj=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/,Mj=/^[+-]?(?:NaN|Infinity)$/,Uj=-2147483648,Gj=2147483647;function Tg(t,e,n){switch(e){case"string":return{value:n?jj(t):t};case"bool":{const i=t.trim().toLowerCase();return i==="1"||i==="true"||i==="yes"?{value:!0}:i==="0"||i==="false"||i==="no"?{value:!1}:null}case"int":case"long":{const i=t.trim();if(!Pj.test(i))return null;const r=Number(i);return e==="int"&&(r<Uj||r>Gj)?{value:r,overflow:Number.isSafeInteger(r)?"i32":"precision"}:{value:r,overflow:Number.isSafeInteger(r)?void 0:"precision"}}case"real":{const i=t.trim();if(!xj.test(i)&&!Mj.test(i))return null;const r=Number(i),s=!Number.isFinite(r)&&!/Infinity|NaN/.test(i)?"precision":void 0;return{value:r,overflow:s}}default:{const i=e;throw new Error(`unknown scalar kind ${String(i)}`)}}}function jj(t){return t.includes("\\")?t.replaceAll(String.raw`\t`," ").replaceAll(String.raw`\n`,`
|
|
50
|
+
`):t}const Fh={bool:"bool",int:"i32",long:"f64",real:"f64",string:"string"};class zh{constructor(e,n,i){this.plans=new Map,this.domain=e,this.report=n,this.options=i}has(e){return this.plans.has(t_(null,e))}addAtt(e,n,i){const{name:r}=n;if(r===null||r.length===0){this.badAtt("an <att> without a name was skipped",n,"name");return}const s=this.plan(r,n.namespace??null),o=e_(n);s.hidden||=n.hidden,s.suid||=r.endsWith(".SUID"),o.declared!==null&&(s.declaredType??=o.declared);const l={line:n.line,element:i.element??r};o.unknown!==null&&this.report.warnOnce("unsupported",j.UNKNOWN_ATTR_TYPE,`att type "${o.unknown}" of "${r}" is not an XGMML or Cytoscape type; its values are kept as text`,l,`${j.UNKNOWN_ATTR_TYPE}:${this.domain}:${r}`);let a;n.equation?(s.equation=!0,this.report.warnOnce("unsupported",j.EQUATION_AS_TEXT,`"${r}" holds Cytoscape formulas; each is kept as its text, never evaluated`,l,`${j.EQUATION_AS_TEXT}:${this.domain}:${r}`),a=n.value===null?null:n_("string",n.value,n.value,!0),a!==null&&s.declared.add("string")):(o.kind==="list"||o.kind==="map")&&Bj(n,r_)?(this.badAtt(`"${r}" is nested more than ${String(r_)} atts deep; it is skipped`,n,"depth"),a=null):o.kind==="list"?(a=this.listCell(n,r,s,l),s.declared.add("list")):o.kind==="map"?(a=Fc(i_(n)),this.recordList(`"${r}" is a 2.x map; it is kept as a json record`,l),s.declared.add("json")):a=this.scalarAtt(n,o.kind,s,l),a!==null&&this.set(s,e,a,l)}addText(e,n,i,r){const s=this.plan(n,null),o=lf(i),l=Wj(qn(i));this.set(s,e,{kind:l,value:o,text:i,items:[],itemKind:null,typed:!1},r)}addJson(e,n,i,r){this.set(this.plan(n,null),e,Fc(i),r)}write(e,n){const i=new Set(this.options.reserved),r=[...this.plans.values()].sort((s,o)=>+(s.namespace!==null)-+(o.namespace!==null));for(const s of r){let{name:o}=s;i.has(o)&&(o=Xt(s.name,s.namespace,l=>i.has(l)),this.report.warning("coercion",j.COLUMN_RENAMED,`${this.domain} attribute "${s.name}" renamed to "${o}": the name was taken`,{element:s.name})),i.add(o),this.writePlan(e,s,o,n)}}plan(e,n){const i=t_(n,e);let r=this.plans.get(i);return r===void 0&&(r={name:e,namespace:n,cells:new Map,declared:new Set,lines:new Map,declaredType:null,hidden:!1,equation:!1,suid:!1,overflow:!1,precision:!1},this.plans.set(i,r)),r}set(e,n,i,r){e.cells.has(n)&&this.report.warning("validation-error",j.DUPLICATE_ATTRIBUTE,`"${e.name}" is given twice on one ${this.domain}; the later value is kept`,{line:r.line??null,element:r.element??e.name}),e.cells.set(n,i),r.line!==void 0&&r.line!==null&&e.lines.set(n,r.line)}scalarAtt(e,n,i,r){if(e.children.length>0&&this.badAtt(`the ${n} att "${e.name??""}" holds child atts; they are ignored`,e,"children"),e.xml!==null)return this.recordList(`"${e.name??""}" holds foreign XML; it is kept as text in a json column`,r),i.declared.add("json"),Fc(e.xml);if(e.value===null)return i.declared.add(n),null;const s=Tg(e.value,n,this.options.unescape);return s===null||s.overflow!==void 0&&n==="int"&&Wh(e.cyType)?(this.badValue(e.value,n,r),null):(i.declared.add(n),s.overflow==="i32"?i.overflow=!0:s.overflow==="precision"&&(i.precision=!0,i.overflow||=n==="int"),n_(n,s.value,e.value,!0))}listCell(e,n,i,r){e.value!==null&&this.badAtt(`the list att "${n}" has a value; it is ignored`,e,"list-value");const{children:s}=e,o=new Set(s.map(c=>c.name).filter(c=>c!==null&&c!==n));if(o.size>1||s.some(c=>c.children.length>0||c.xml!==null))return this.recordList(`"${n}" is a record or a list of lists; it is kept as json`,r),Fc(o.size>1?i_(e):s.map(d$));let l=Lj(e.elementType);if(l===null&&e.elementType!==null&&e.elementType.trim().length>0&&this.report.warnOnce("unsupported",j.UNKNOWN_ATTR_TYPE,`list element type "${e.elementType}" of "${n}" is not a Cytoscape type; the items are read by their own types`,r,`${j.UNKNOWN_ATTR_TYPE}:${this.domain}:${n}:items`),l===null){const c=new Set;for(const d of s){const u=e_(d),f=u.kind==="list"||u.kind==="map"?"string":u.kind;c.add(f),l=l===null?f:jh(l,f)}c.size>1&&this.report.warnOnce("coercion",j.WIDENED,`the items of list "${n}" declare different types; they are read as ${l??"string"}`,r,`${j.WIDENED}:${this.domain}:${n}`)}const a=[];for(const c of s){if(c.value===null)continue;const d=Tg(c.value,l??"string",this.options.unescape),u=Wh(e.elementType)||Wh(c.cyType);if(d===null||d.overflow!==void 0&&l==="int"&&u){this.badValue(c.value,l??"string",{line:c.line,element:r.element});continue}d.overflow==="i32"?i.overflow=!0:d.overflow==="precision"&&(i.precision=!0,i.overflow||=l==="int"),a.push({value:d.value,text:c.value})}return{kind:"list",value:null,text:"",items:a,itemKind:l,typed:!0}}writePlan(e,n,i,r){const s=[...n.cells.values()],o=this.decide(n,s),l={name:i,dtype:o.dtype,nullable:!0,origin:{format:Ht,id:null,title:i===n.name?null:n.name,type:Fj(n,o),namespace:n.namespace??(n.hidden?Tf:null)}};o.itemDtype!==null&&(l.itemDtype=o.itemDtype);const a={};n.hidden&&(a.hidden=!0),n.suid&&(a.suidReference=!0),n.equation&&(a.equation=!0),Object.keys(a).length>0&&(l.extra=a);const c={element:i};if(this.domain==="graph"){const u=n.cells.get(0);try{e.setGraphValue(i,u===void 0?void 0:s_(u,o),l)}catch(f){this.report.recordError(f,c)}return}let d;try{({handle:d}=he(e,this.domain,l,this.report,c))}catch(u){this.report.recordError(u,c);return}for(const[u,f]of n.cells){const h=r(u);if(h<0)continue;const p=s_(f,o);try{this.domain==="node"?e.setNodeValue(d,h,p):e.setEdgeValue(d,h,p)}catch(g){this.report.recordError(g,{line:n.lines.get(u)??null,element:i})}}}decide(e,n){const i={element:e.name};let s=new Set(n.filter(l=>l.typed).map(l=>l.kind)).size>1||e.declared.size>1,o;if(n.some(l=>l.kind==="json")||n.some(l=>l.kind==="list")&&n.some(l=>l.kind!=="list"))o={dtype:"json",itemDtype:null,scalar:null,item:null,long:!1};else if(n.length>0&&n.every(l=>l.kind==="list")){let l=null;for(const a of n)a.itemKind!==null&&(s||=l!==null&&l!==a.itemKind,l=l===null?a.itemKind:jh(l,a.itemKind));l===null&&(this.report.warnOnce("coercion",j.EMPTY_LIST_TYPE,`list "${e.name}" has no element type and no items; it is a list of strings`,i,`${j.EMPTY_LIST_TYPE}:${this.domain}:${e.name}`),l="string"),e.overflow&&l==="int"&&(l="real",s=!0),o={dtype:"list",itemDtype:Fh[l],scalar:null,item:l,long:l==="long"}}else o=this.decideScalar(e,n),s||=e.overflow&&o.scalar==="real"&&e.declared.has("int");return s&&this.report.warnOnce("coercion",j.WIDENED,`${this.domain} column "${e.name}" was widened to ${o.dtype}: its values or declared types disagree`,i,`${j.WIDENED}:${this.domain}:${e.name}`),e.precision&&this.report.warnOnce("precision",j.PRECISION,`values of "${e.name}" beyond what a double holds exactly are stored as the nearest double (or infinity)`,i,`${j.PRECISION}:${this.domain}:${e.name}`),o}decideScalar(e,n){let i=null;for(const o of n){const l=o.kind;i=i===null?l:jh(i,l)}i===null&&(i=[...e.declared].find(l=>l in Fh)??"string"),i==="int"&&e.overflow&&(i="real");const r=i==="long";if(r&&this.options.long==="string")return{dtype:"string",itemDtype:null,scalar:"string",item:null,long:!0};let s=Fh[i];if(i==="string"){const o=new no;for(const l of n)if(o.observe(l.text))break;s=o.decide()}return{dtype:s,itemDtype:null,scalar:i,item:null,long:r}}badAtt(e,n,i){this.report.warnOnce("parse-error",j.BAD_ATT,e,{line:n.line,element:n.name},`${j.BAD_ATT}:${i}`)}badValue(e,n,i){this.report.error("validation-error",j.BAD_VALUE,`value ${JSON.stringify(e)} is not a valid ${zj[n]}; the cell is left unset`,i)}recordList(e,n){this.report.warnOnce("coercion",j.RECORD_LIST,e,n)}}function Wh(t){return t?.trim().toLowerCase()==="integer"}function Fj(t,e){return t.equation?"equation":e.long?"long":t.declaredType}const zj={bool:"boolean (1, 0, true, false, yes, no)",int:"integer",long:"long integer",real:"real number",string:"string"};function t_(t,e){return t===null?e:`${t}\0${e}`}function Wj(t){switch(t){case"bool":return"bool";case"i32":return"int";case"f64":return"real";default:return"string"}}function n_(t,e,n,i){return{kind:t,value:e,text:n,items:[],itemKind:null,typed:i}}function Fc(t){return{kind:"json",value:t,text:JSON.stringify(t),items:[],itemKind:null,typed:!0}}function i_(t){const e={};for(const n of t.children)e[n.name??""]=d$(n);return e}const r_=64;function Bj(t,e){const n=[[t,1]];for(let i=n.pop();i!==void 0;i=n.pop()){const[r,s]=i;if(s>e)return!0;for(const o of r.children)n.push([o,s+1])}return!1}function d$(t){return l$(t,e=>e.xml!==null?{value:e.xml}:e.children.length===0?{value:e.value}:null)}function s_(t,e){return e.dtype==="json"?t.kind==="json"?t.value:t.kind==="list"?t.items.map(n=>n.value):t.value:e.dtype==="list"?t.items.map(n=>o_(n.value,n.text,e.item??"string")):o_(t.value,t.text,e.long&&e.dtype==="string"?"string":e.scalar??"string")}function o_(t,e,n){switch(n){case"bool":return t;case"int":case"long":case"real":return Number(t);default:return typeof t=="string"?t:e}}const Hj=new Set(["documentVersion","networkMetadata"]),Vj=new Set(["id","label","directed","xlink:href","cy:documentVersion","cy:view","cy:registered","cy:networkId","cy:visualStyle","cy:rendererId"]),Yj=64,Kj=/[()]/;function u$(t,e){const{root:n}=t;let i=n.attrs.get("cy:documentVersion")??null;for(const o of n.atts)o.name==="documentVersion"&&o.value!==null&&(i??=o.value);let r=0;i!==null&&(r=Number(i.trim()),(!Number.isFinite(r)||r<0||i.trim().length===0)&&(e.warning("validation-error",j.DOCUMENT_VERSION,`documentVersion "${i}" does not parse; the dialect is chosen from the content`,{line:n.line}),r=0));const s=n.subgraphs.some(o=>Si(o.registered));return{versionText:i,version:r,cytoscape:t.cytoscape,cy2:t.cytoscape&&r<3,session:n.registered!==null&&!Si(n.registered)&&s,view:Si(n.attrs.get("cy:view"))}}function Xj(t,e){return e.session?t.root.subgraphs.filter(n=>Si(n.registered)):[t.root]}function f$(t){const e=Tg(t,"real",!1);return e===null||!Number.isFinite(e.value)?null:e.value}function uc(t){return t.startsWith("#")?t.slice(1):null}function qj(t,e){return t??(e===null?null:uc(e))}function ao(t,e){if(e===null)return{nodes:t.nodes,edges:t.edges,dangling:0};const n=l_(t.nodes),i=l_(t.edges),r=[],s=[];let o=0;for(const l of e.members){const a=Jj(l,n,i);a===void 0?o++:a.kind==="node"?r.push(a):s.push(a)}return{nodes:r,edges:s,dangling:o}}function Jj(t,e,n){if(t.href===null)return t;const i=uc(t.href);if(i!==null)return t.kind==="node"?e.get(i):n.get(i)}function l_(t){const e=new Map;for(const n of t)n.id!==null&&!e.has(n.id)&&e.set(n.id,n);return e}function Zj(t,e){if(t===null)return!1;const n=e.id??(e.label===null?null:JSON.stringify([e.label,e.source,e.target]));return n===null?!1:t.has(n)?!0:(t.add(n),!1)}function Qj(t){return t.name!==null&&Hj.has(t.name)?!1:!(t.hasGraph&&t.name===null)}class mb{constructor(e,n,i,r,s,o,l={}){this.rows=new Map,this.rowList=[],this.edgeIndex=[],this.sinceCheck=0,this.aliasResolved=0,this.aliasInteractions=0,this.weighted=!1,this.directions=new Map,this.nameLabel={node:!1,edge:!1},this.labelRows=null,this.doc=e,this.dialect=n,this.sink=i,this.report=r,this.options=s,this.settings=o,this.extras=l,this.coercer=new Mn(s.ids),this.direction=new ei(i,r,s.onMixedDirection);const a={unescape:o.cytoscapeEscapes,long:s.long},c=l.labelFromName===!0?[]:[Ys];this.nodeColumns=new zh("node",r,{...a,reserved:new Set([...c,Tl,lo,Qt,cc,Af,Ks,dc,el,Sa])}),this.edgeColumns=new zh("edge",r,{...a,reserved:new Set([Qo,...c,Qt])}),this.graphColumns=new zh("graph",r,{...a,reserved:new Set([Qt])})}emit(e){const n=ao(this.doc,e);n.dangling>0&&this.report.warning("validation-error",j.DANGLING_REFERENCE,`${this.prefix()}${n.dangling} xlink:href member reference${O(n.dangling)} ${C(n.dangling,"names","name")} no node or edge of the document`,{line:e?.line??null});const i=this.headerDirected();this.direction.setHeader(this.sinkDirection(n.edges,i),{line:this.doc.root.line}),this.addNodes(n.nodes),e===null&&this.checkReferences();const r=new i9(this);r.resolve(this.rowList,this.groupTest()),this.writeNodeExtras(e,o=>r.parentsOf(o)),this.addEdges(n.edges,i),this.finishAliases(),this.writeGraph(e);const s=o=>this.rowList[o].index;this.nodeColumns.write(this.sink,s),this.edgeColumns.write(this.sink,o=>this.edgeIndex[o]??-1),r.write(),this.writeMeta(e),F(this.options.signal)}get target(){return this.sink}get issues(){return this.report}rowOf(e){return this.rows.get(e)}resolvePointer(e){return this.extras.resolvePointer?.(e)??null}missingMember(e,n){return this.extras.onMissingMember===void 0?!1:(this.extras.onMissingMember(e,n),!0)}graphById(e){return this.doc.graphs.find(n=>n.id===e)}prefix(){return this.extras.entry===void 0?"":`${this.extras.entry}: `}checkAbort(){++this.sinceCheck>=Yj&&(this.sinceCheck=0,F(this.options.signal))}declare(e,n){try{return he(this.sink,e,n,this.report,{element:n.name}).handle}catch(i){return this.report.recordError(i,{element:n.name}),null}}headerDirected(){const e=this.doc.root.attrs.get("directed");return e===void 0?this.options.defaultDirected:this.flag(e,this.options.defaultDirected,{line:this.doc.root.line,element:"directed"})}edgeDirection(e,n){let i=this.directions.get(e);if(i===void 0){const r=this.graphDirected(e.graph,n);i=e.directed===null?r:this.flag(e.directed,r,{line:e.line,element:e.id??e.label}),this.directions.set(e,i)}return i}graphDirected(e,n){for(let i=e;i!==null&&i!==this.doc.root;i=i.parent){const r=i.attrs.get("directed");if(r!==void 0)return this.flag(r,n,{line:i.line,element:"directed"})}return n}sinkDirection(e,n){let i=null;for(const r of e){const s=this.edgeDirection(r,n);if(i===null)i=s;else if(i!==s)return n}return i??n}flag(e,n,i){const r=e.trim();if(r==="1"||r==="0")return r==="1";const s=r.toLowerCase(),o=s==="true"||s==="yes"||s==="false"||s==="no";let l;return o?l=s==="true"||s==="yes"?"1":"0":l=n?"directed":"undirected",this.report.warnOnce("validation-error",j.BAD_DIRECTED,`${this.prefix()}directed="${e}" is not 0 or 1; read as ${l}`,i,`${j.BAD_DIRECTED}:${e}`),o?s==="true"||s==="yes":n}addNodes(e){for(const n of e){const{id:i}=n;if(i===null)continue;const r=this.rows.get(i);if(r!==void 0){r.records.push(n),this.report.warning("validation-error",j.DUPLICATE_NODE,`${this.prefix()}node "${i}" is declared twice; the declarations are merged`,{line:n.line,element:i});continue}const s={id:i,records:[n],index:-1,row:this.rowList.length};try{s.index=this.sink.addNode(this.nodeId(i,n.line)),this.report.counts.nodes++}catch(o){this.report.counts.skippedNodes++,this.report.recordError(o,{line:n.line,element:i})}this.rows.set(i,s),this.rowList.push(s),this.checkAbort()}}idOf(e){return this.coercer.text(this.extras.restoredIds?.get(e)??e)}decideNameLabel(e,n){this.nameLabel[e]=this.extras.labelFromName===!0&&n.some(i=>i.atts.some(Bh))}labelOf(e){return this.nameLabel[e.kind]?e.atts.find(Bh)?.value??void 0:e.label??void 0}nodeId(e,n){const i=this.idOf(e),r=this.coercer.lastMerge;return r!==null&&this.report.warning("coercion",j.ID_MERGED,`id "${r.text}" merged with "${r.previousText}" as ${r.id} under ids: "number"`,{line:n,element:e}),i}groupTest(){const{groupNodes:e}=this.extras,{cytoscape:n}=this.dialect;return i=>!n||i.id!==null&&e?.has(i.id)===!0?!0:i.atts.some(r=>r.name==="__groupState"||r.name==="__isGroup"&&Si(r.value))}checkReferences(){const e=this.groupTest(),n=new Set(this.doc.edges.map(r=>r.id));let i=0;for(const r of this.doc.graphs)r.owner!==null&&e(r.owner)||(i+=this.danglingReferences(r,n));i>0&&this.report.warning("validation-error",j.DANGLING_REFERENCE,`${this.prefix()}${i} xlink:href reference${O(i)} ${C(i,"names","name")} no node or edge of the document`)}danglingReferences(e,n){let i=0;for(const r of e.members){if(r.href===null)continue;const s=uc(r.href);s!==null&&(r.kind==="node"?this.rows.has(s):n.has(s))||i++}return i}writeNodeExtras(e,n){const i=[],r=new e9(this,this.dialect.cytoscape?this.settings.zAs:"position"),s=new Na(this,"node",Qt,pn,"graphics"),o=new n9(this,this.groupTest());this.decideNameLabel("node",this.rowList.flatMap(l=>l.records));for(const l of this.rowList){const a={line:l.records[0].line,element:l.id},c=new Set;for(const d of l.records)i[l.row]??=this.labelOf(d),this.addElementColumns(this.nodeColumns,l.row,d,c,a),r.add(l,d),d.graphics!==null&&Object.keys(d.graphics).length>0&&s.set(l.index,d.graphics),o.add(l,d);this.checkAbort()}this.writeLabels("node",i,l=>this.rowList[l].index),r.write(n),o.write(),e===null&&this.writeNetworks()}addElementColumns(e,n,i,r,s){const o=r.size>0,l=new Set;i.name!==null&&(o&&r.has("name")||e.addText(n,"name",i.name,s),l.add("name"));for(const[a,c]of i.xmlAttrs)o&&r.has(a)||e.addText(n,a,c,s),l.add(a);for(const a of i.atts)this.skipAtt(i,a)||this.nameLabel[i.kind]&&Bh(a)||o&&a.name!==null&&r.has(a.name)||i.kind==="node"&&a.name==="__isGroup"&&i.nested.length>0&&Si(a.value)||a.hasGraph&&a.name===null||(e.addAtt(n,a,s),a.name!==null&&l.add(a.name));for(const a of l)r.add(a)}skipAtt(e,n){return e.kind!=="edge"||n.name!==this.options.weightFrom?!1:e.weight===null||n.name!=="weight"||n.children.length>0?e.weight===null:(this.report.warning("validation-error",j.DUPLICATE_ATTRIBUTE,`${this.prefix()}an edge has weight="${e.weight}" and a weight att "${n.value??""}"; the weight attribute is the weight and the att is not read`,{line:n.line,element:e.id??e.label??"weight"}),!0)}writeLabels(e,n,i){if(!n.some(s=>s!==void 0))return;const r=this.declare(e,{name:this.nameLabel[e]?"name":Ys,dtype:"string",role:"label",nullable:!0,origin:{format:Ht,id:null,title:null,type:"label",namespace:null}});r!==null&&n.forEach((s,o)=>{const l=i(o);s!==void 0&&l>=0&&(e==="node"?this.sink.setNodeValue(r,l,s):this.sink.setEdgeValue(r,l,s))})}networkMembership(e){const n=new Map;for(const i of e){const r=i.id??i.label??"";for(const s of i.members){const o=s.kind==="node"?qj(s.id,s.href):null,l=o===null?void 0:this.rows.get(o);if(l!==void 0&&l.index>=0){const a=n.get(l.index)??[];a.push(r),n.set(l.index,a)}}}return n}writeNetworks(){const{subgraphs:e}=this.doc.root;if(e.length===0)return;const n=this.networkMembership(e);if(n.size===0)return;const i=this.declare("node",{name:Sa,dtype:"list",itemDtype:"string",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graph",namespace:pn}});if(i!==null)for(const[r,s]of n)this.sink.setNodeValue(i,r,s)}addEdges(e,n){const i=new Set,r=this.dialect.cy2&&this.doc.nodes.some(f=>f.nested.length>0)?new Set:null;let s=0,o=null;const l=[],a=[],c=[];let d=0;this.decideNameLabel("edge",e);for(const f of e){const h={line:f.line,element:f.id??f.label};if(Zj(r,f)){s++,o??=h;continue}const p=this.addEdge(f,n,i,h);this.checkAbort(),!(p<0)&&(this.edgeIndex[d]=p,l[d]=this.labelOf(f),a[d]=f.id??void 0,this.addElementColumns(this.edgeColumns,d,f,new Set,h),this.fillInteraction(f,d,h),f.graphics!==null&&Object.keys(f.graphics).length>0&&c.push([p,f.graphics]),d++)}s>0&&this.report.warning("merged",j.GROUP_DUPLICATE_EDGE,`${this.prefix()}the Cytoscape 2.x writer repeats the edges of a group; ${s} repeat${O(s)} ${C(s,"was","were")} dropped`,o??void 0),this.writeEdgeIds(a),this.writeLabels("edge",l,f=>this.edgeIndex[f]??-1);const u=new Na(this,"edge",Qt,pn,"graphics");for(const[f,h]of c)u.set(f,h)}addEdge(e,n,i,r){const s=this.settings.labelAliases?Ig(e.label):null;let o,l;try{o=this.endpoint(e.source,s?.[0]??null,"source",r),l=this.endpoint(e.target,s?.[2]??null,"target",r)}catch(u){return this.report.counts.skippedEdges++,this.report.recordError(u,r),-1}if(o===null||l===null)return this.report.counts.skippedEdges++,-1;if(e.id!==null&&i.has(e.id))return this.report.counts.skippedEdges++,this.report.error("validation-error",j.DUPLICATE_EDGE_ID,`${this.prefix()}edge id "${e.id}" is used twice; the second edge is skipped`,r),-1;const c=this.edgeDirection(e,n)?"directed":"undirected";let d;try{d=this.weightOf(e);const u=this.sink.edgeCount,f=this.direction.addEdge(o,l,c,d,r);return this.report.counts.edges+=this.sink.edgeCount-u,e.id!==null&&i.add(e.id),f}catch(u){return this.report.counts.skippedEdges++,this.report.recordError(u,r),-1}}weightOf(e){const n=this.options.weightFrom;if(n===null)return;let i=n==="weight"?e.weight:null;if(i===null&&(i=e.atts.find(s=>s.name===n&&s.children.length===0)?.value??null),i===null)return;const r=Kn(i,this.report);return this.weighted||=r!==void 0,r}endpoint(e,n,i,r){if(e!==null){const s=this.rows.get(e);if(s!==void 0&&s.index>=0)return this.idOf(e)}if(n!==null){const s=this.aliasRow(n);if(s!==null)return this.aliasResolved++,this.idOf(s.id)}if(e===null){const s=n!==null&&this.aliasRow(n)===null&&this.labelRows?.get(n)===null;return this.report.error("missing-value",j.MISSING_ENDPOINT,s?`${this.prefix()}<edge> without a ${i}: its label alias "${n}" is ambiguous (several nodes have that label); the edge is skipped`:`${this.prefix()}<edge> without a ${i}`,r),null}if(this.options.addMissingNodes){const s=this.coercer.text(e);return this.sink.indexOf(s)===A&&(this.sink.addNode(s),this.report.counts.nodes++),s}return this.report.error("validation-error",j.UNKNOWN_NODE,`${this.prefix()}edge ${i} "${e}" is not a node of this graph; the edge is skipped`,r),null}aliasRow(e){const n=this.rows.get(e);if(n!==void 0&&n.index>=0)return n;if(this.labelRows===null){this.labelRows=new Map;for(const i of this.rowList){const{label:r}=i.records[0];r!==null&&i.index>=0&&this.labelRows.set(r,this.labelRows.has(r)?null:i)}}return this.labelRows.get(e)??null}fillInteraction(e,n,i){if(!this.settings.labelAliases||this.dialect.session||e.atts.some(s=>s.name===Jl))return;const r=Ig(e.label);r!==null&&(this.edgeColumns.addText(n,Jl,r[1],i),this.aliasInteractions++)}finishAliases(){this.aliasResolved===0&&this.aliasInteractions===0||this.report.warning("coercion",j.LABEL_ALIAS,`${this.prefix()}Cytoscape label aliases ("a (pp) b"): ${this.aliasResolved} endpoint${O(this.aliasResolved)} resolved, ${this.aliasInteractions} interaction${O(this.aliasInteractions)} filled from edge labels`)}writeEdgeIds(e){if(!e.some(i=>i!==void 0))return;const n=this.declare("edge",{name:Qo,dtype:"string",role:"id",unique:!0,nullable:!0,origin:{format:Ht,id:null,title:null,type:"id",namespace:null}});n!==null&&e.forEach((i,r)=>{const s=this.edgeIndex[r];if(i!==void 0&&s!==void 0)try{this.sink.setEdgeValue(n,s,i)}catch(o){this.report.recordError(o,{element:i})}})}writeGraph(e){const n=e??this.doc.root,i={line:n.line,element:n.id};if(e===null)for(const[s,o]of n.attrs)!Vj.has(s)&&s!=="xmlns"&&!s.startsWith("xmlns:")&&this.graphColumns.addText(0,s,o,i);for(const s of n.atts)Qj(s)&&this.graphColumns.addAtt(0,s,i);this.graphColumns.write(this.sink,()=>0);const r={...this.extras.graphJson};n.graphics!==null&&Object.keys(n.graphics).length>0&&(r[Qt]=n.graphics);for(const[s,o]of Object.entries(r))this.sink.setGraphValue(s,o,{name:s,dtype:"json",nullable:!0,origin:{format:Ht,id:null,title:null,type:s,namespace:pn}})}writeMeta(e){const n=e??this.doc.root,{rdf:i}=this.doc,r=this.extras.graphName??n.label??i.title??n.id??void 0;this.sink.setMeta({name:r??void 0,description:i.description??void 0,created:i.date??void 0,sourceFormat:this.extras.sourceFormat??Ht,sourceVersion:this.dialect.versionText??void 0,weightOrigin:this.weighted?{format:Ht,id:"weight",title:null,type:"weight",namespace:null}:void 0,extra:{[EI]:{graphId:n.id,directed:this.doc.root.attrs.get("directed")??null,rdf:Object.keys(i).length>0?{...i}:null},...this.extras.metaExtra}})}}function Bh(t){return t.name==="name"&&(t.namespace??null)===null&&t.value!==null&&t.children.length===0&&(t.cyType??"String")==="String"}function Ig(t){if(t===null)return null;const e=t.split(Kj);return e.length===3?[e[0].trim(),e[1],e[2].trim()]:null}class Na{constructor(e,n,i,r,s,o="json"){this.emitter=e,this.domain=n,this.name=i,this.namespace=r,this.type=s,this.dtype=o}set(e,n){if(e<0||(this.handle===void 0&&(this.handle=this.emitter.declare(this.domain,{name:this.name,dtype:this.dtype,nullable:!0,origin:{format:Ht,id:null,title:null,type:this.type,namespace:this.namespace}})),this.handle===null))return;const i=this.emitter.target;try{this.domain==="node"?i.setNodeValue(this.handle,e,n):i.setEdgeValue(this.handle,e,n)}catch(r){this.emitter.issues.recordError(r,{element:this.name})}}}class e9{constructor(e,n){this.emitter=e,this.zAs=n,this.values=new Map,this.locations=new Map,this.zValues=new Map,this.hasZ=!1}add(e,n){const i=e.index<0?null:t9([...n.atts,...n.nested.flatMap(a=>a.atts)]);if(i!==null&&this.locations.set(e.index,i),e.index<0||n.x===null&&n.y===null&&n.z===null)return;const r={line:n.line,element:e.id},s=this.number(n.x,r),o=this.number(n.y,r),l=this.number(n.z,r);l!==null&&(this.hasZ=!0,this.zAs==="column"&&this.zValues.set(e.index,l)),s!==null&&o!==null&&this.values.set(e.index,[s,Bo(o),this.zAs==="position"?l??0:0])}number(e,n){if(e===null)return null;const i=f$(e);return i===null?(this.emitter.issues.error("validation-error",j.BAD_VALUE,`${this.emitter.prefix()}graphics coordinate "${e}" is not a number`,n),null):i}followGroups(e){for(const[n,i]of this.locations){if(this.values.has(n))continue;const r=e(n).flatMap(s=>[...i].map(([o,[l,a]])=>({center:this.locations.get(s)?.get(o),dx:l,dy:a}))).find(s=>s.center!==void 0);r?.center!==void 0&&this.values.set(n,[r.center[0]+r.dx,Bo(r.center[1]+r.dy),0])}}write(e){this.followGroups(e);const n=this.emitter.target;if(this.values.size>0){const i=this.emitter.declare("node",{name:Tl,dtype:"f64",components:3,role:"position",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graphics",namespace:pn},extra:{sourceDims:this.zAs==="position"&&this.hasZ?3:2,units:"file"}});if(i!==null)for(const[r,s]of this.values)n.setNodeValue(i,r,s)}if(this.zValues.size>0){const i=this.emitter.declare("node",{name:lo,dtype:"f64",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graphics",namespace:Tf}});if(i!==null)for(const[r,s]of this.zValues)n.setNodeValue(i,r,s)}}}function t9(t){const e=o=>t.find(l=>l.name===o)?.children.map(l=>l.value)??[],n=e("__groupNetworks.SUID"),i=e("__xLocation"),r=e("__yLocation"),s=new Map;return n.forEach((o,l)=>{const a=Number(i[l]??Number.NaN),c=Number(r[l]??Number.NaN);o!==null&&Number.isFinite(a)&&Number.isFinite(c)&&s.set(o,[a,c])}),s.size>0?s:null}class n9{constructor(e,n){this.emitter=e,this.isGroup=n,this.names=new Map,this.crossFile=new Map,this.dangling=0}add(e,n){if(!(n.nested.length===0||this.isGroup(n)||e.index<0))for(const i of n.nested){if(i.href===null){this.names.set(e.index,i.label??i.id??"");continue}const r=uc(i.href);if(r===null){const o=this.emitter.resolvePointer(i.href);o!==null?this.names.set(e.index,o):this.crossFile.set(e.index,i.href);continue}const s=this.emitter.graphById(r);s===void 0?this.dangling++:this.names.set(e.index,s.label??s.id??r)}}write(){const e=this.emitter.prefix();this.dangling>0&&this.emitter.issues.warning("validation-error",j.DANGLING_REFERENCE,`${e}${this.dangling} nested-network pointer${O(this.dangling)} ${C(this.dangling,"names","name")} no graph of the document`);const n=new Na(this.emitter,"node",dc,Tf,"nestedNetwork","string");for(const[i,r]of this.names)n.set(i,r);if(this.crossFile.size>0){this.emitter.issues.warning("unsupported",j.CROSS_FILE_REFERENCE,`${e}${this.crossFile.size} nested-network pointer${O(this.crossFile.size)} ${C(this.crossFile.size,"points","point")} into another file; each is kept as text in ${el}`);const i=new Na(this.emitter,"node",el,pn,"xlink:href","string");for(const[r,s]of this.crossFile)i.set(r,s)}}}class i9{constructor(e){this.emitter=e,this.parents=new Map,this.subgraphs=new Map,this.groups=new Set}resolve(e,n){let i=0;for(const r of e)for(const s of r.records)if(!(r.index<0||s.nested.length===0||!n(s)))for(const o of s.nested){const l=o.atts.filter(a=>a.name!==null);(o.id!==null||o.label!==null||l.length>0)&&this.subgraphs.set(r.index,{id:o.id,label:o.label,atts:Object.fromEntries(l.map(a=>[a.name,Ag(a)]))});for(const a of o.members){if(a.kind!=="node")continue;const c=a.id??(a.href===null?null:uc(a.href)),d=c===null?void 0:this.emitter.rowOf(c);if(d===void 0){(c===null||!this.emitter.missingMember(r.id,c))&&i++;continue}d.index>=0&&this.link(d.index,r.index,a.line)}}i>0&&this.emitter.issues.error("missing-value",j.UNKNOWN_PARENT,`${this.emitter.prefix()}${i} group member${O(i)} ${C(i,"names","name")} no node of this graph`)}link(e,n,i){if(e===n||this.groups.has(e)&&this.isAncestor(e,n)){this.emitter.issues.error("validation-error",j.PARENT_CYCLE,`${this.emitter.prefix()}a group membership would make a node its own ancestor; that membership is dropped`,{line:i});return}const r=this.parents.get(e)??[];r.includes(n)||r.push(n),this.parents.set(e,r),this.groups.add(n)}isAncestor(e,n){const i=[n],r=new Set;for(;i.length>0;){const s=i.pop();if(s===e)return!0;r.has(s)||(r.add(s),i.push(...this.parents.get(s)??[]))}return!1}parentsOf(e){return this.parents.get(e)??[]}write(){const e=this.emitter.target;if(this.parents.size>0){const n=[...this.parents.values()].some(r=>r.length>1),i=this.emitter.declare("node",{name:n?Af:cc,dtype:n?"list":"u32",itemDtype:n?"u32":void 0,role:n?"parents":"parent",refersTo:"node",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graph",namespace:null}});if(i!==null)for(const[r,s]of this.parents)e.setNodeValue(i,r,n?s:s[0])}if(this.subgraphs.size>0){const n=new Na(this.emitter,"node",Ks,pn,"graph");for(const[i,r]of this.subgraphs)n.set(i,r)}}}const r9={ids:"keep",defaultDirected:!1,weightFrom:"weight",addMissingNodes:!1},h$=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","errorLimit","signal","onProgress","encoding"]),p$=/<!DOCTYPE\s+graph\s[^<>]*xgmml\.dtd/i;function $g(t,e){const n=t?.zAs??"column";if(n!=="column"&&n!=="position")throw new N("E_UNSUPPORTED",`option zAs: ${JSON.stringify(n)} is not "column" or "position"`,{option:"zAs",found:n});return{labelAliases:bu("labelAliases",t?.labelAliases,e),cytoscapeEscapes:bu("cytoscapeEscapes",t?.cytoscapeEscapes,e),zAs:n}}function bu(t,e,n){if(e===void 0)return n;if(typeof e!="boolean")throw new N("E_UNSUPPORTED",`option ${t}: ${JSON.stringify(e)} is not a boolean`,{option:t,found:e});return e}async function g$(t,e,n,i){const r=new Dj(e),s={content:!1};try{await ff(l9($r(t,e,{...n,declaredEncoding:uf,xml:!0}),s),r,s9(e,i))}catch(l){throw l instanceof te&&o9(e,l,s.content),l}const o=r.document();return!o.xgmmlNamespace&&!p$.test(o.doctype??"")&&e.warning("validation-error",j.NO_NAMESPACE,"the root <graph> has neither the XGMML namespace nor an XGMML DOCTYPE; it is read as XGMML",{line:o.root.line}),o}function s9(t,e){const n=r=>{t.warning("parse-error",j.AMPERSAND_REPAIRED,"a bare & was read as &",{line:r})},i=r=>{t.warning("parse-error",j.SURROGATE_PAIRED,"two surrogate character references were joined into one character",{line:r})};return{bareAmpersand:bu("repairBareAmpersands",e?.repairBareAmpersands,!1)?n:void 0,surrogatePair:bu("pairSurrogateReferences",e?.pairSurrogateReferences,!1)?i:void 0}}function o9(t,e,n){return n||t.fail(j.EMPTY_INPUT,"the input is empty"),t.fail(e instanceof df?j.XML_NESTING:j.XML_SYNTAX,e.message,{line:e.line})}async function*l9(t,e){for await(const n of t)e.content||=!Tr(n),yield n}async function yb(t,e,n){const i=tt(n,r9),r=new ne(Ht,i.errorLimit);e!==null&&(_t(e,n,r,!0),St(n,r,h$)),$g(n,!1);const s=await g$(t,r,i,n),o=u$(s,r);return o.view&&r.fail(j.VIEW_DOCUMENT,"this is a Cytoscape session view file (cy:view): it holds positions keyed by view ids and no topology; open the session (.cys) instead",{line:s.root.line}),{report:r,common:i,doc:s,dialect:o,settings:$g(n,s.cytoscape),graphs:Xj(s,o)}}function m$(t,e,n,i){const{doc:r,dialect:s,report:o,common:l,settings:a}=t;return new mb(r,s,n,o,l,a,i).emit(s.session?e:null),s.session&&a9(t),F(l.signal),o.finish()}function a9(t){const e=new Set;for(const r of t.graphs){const s=ao(t.doc,r);s.nodes.forEach(o=>e.add(o)),s.edges.forEach(o=>e.add(o))}const n=t.doc.nodes.filter(r=>!e.has(r)).length,i=t.doc.edges.filter(r=>!e.has(r)).length;n+i>0&&t.report.warning("unsupported",j.ROOT_ONLY_ELEMENTS,`${kA(n,i)} ${C(n+i,"belongs","belong")} to none of the file's networks (group meta-edges or collapsed group members) and ${C(n+i,"was","were")} not read`)}async function c9(t,e,n){const i=await yb(t,e,n),r=ml(i.graphs.map(s=>y$(s,i.doc)),n,i.report);return i.graphs.length>1&&!io(n)&&i.report.warning("unsupported",j.MULTIPLE_GRAPHS,`the session network document holds ${i.graphs.length} registered networks; only the first is read (importAllGraphs() reads every one; graphIndex or graphName chooses one)`),m$(i,i.graphs[r],e)}async function d9(t,e,n){const i=await yb(t,null,n),r=i.report.fork(),s=[];for(let o=0;o<i.graphs.length;o++){const l=e(o),a=o===0?i:{...i,report:r.fork()};_t(l,n,a.report,!0),St(n,a.report,h$),s.push(m$(a,a.graphs[o],l))}return s}async function u9(t,e){const n=await yb(t,null,e);return n.graphs.map((i,r)=>{const s=ao(n.doc,n.dialect.session?i:null);return Object.freeze({index:r,name:y$(i,n.doc),nodes:new Set(s.nodes.map(o=>o.id)).size,edges:s.edges.length})})}function y$(t,e){return t.label??(t===e.root?e.rdf.title??null:null)??t.id??null}function f9(t){let e="utf-8";t[0]===255&&t[1]===254||t[0]===60&&t[1]===0&&t[2]===63?e="utf-16le":(t[0]===254&&t[1]===255||t[0]===0&&t[1]===60&&t[2]===0)&&(e="utf-16be");const n=new TextDecoder(e,{fatal:!1}).decode(t);if(!/^\uFEFF?\s*</.test(n))return 0;if(p$.test(n))return .95;const i=/<(?![?!])([A-Za-z_][\w.-]*:)?([A-Za-z_][\w.-]*)[\s/>]/.exec(n.replaceAll(/<!--[\s\S]*?(-->|$)/g,""));if(i?.[2]!=="graph")return 0;const r=n.indexOf(">",i.index);return[...n.slice(i.index,r<0?void 0:r).matchAll(/\bxmlns(?::[\w.-]+)?\s*=\s*(["'])([^"']*)\1/g)].map(l=>l[2]).includes(_a)?.95:.5}const h9=Object.freeze({format:Ht,options:Object.freeze(["cytoscapeEscapes","labelAliases","pairSurrogateReferences","repairBareAmpersands","zAs"]),extensions:uG,mimeTypes:fG,sniff:f9,import:c9,importAll:d9,listGraphs:u9,styles:mG}),ri="cys",p9=Object.freeze([".cys"]),g9=Object.freeze(["application/zip"]),b$="cytoscape",m9="cytoscape",a_="cytoscape.selected",Eu="cytoscape.hidden",y9="position@",b9=2*1024*1024*1024,E9=1e3,w9=Object.fromEntries(Object.values(j).map(t=>[t.replace(/^[EW]_/,""),t])),ae=Object.freeze({...xn,...Pn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,...w9,NOT_ZIP:"E_CYS_NOT_ZIP",CORRUPT:"E_CYS_CORRUPT",NOT_SESSION:"E_CYS_NOT_SESSION",UNSUPPORTED:"E_CYS_UNSUPPORTED",VERSION:"E_CYS_VERSION",TABLE:"E_CYS_TABLE",TABLE_ROW:"W_CYS_TABLE_ROW",COLLAPSED_GROUP:"W_CYS_COLLAPSED_GROUP",ENTRY_SKIPPED:"W_CYS_ENTRY_SKIPPED",DUPLICATE_ENTRY:"W_CYS_DUPLICATE_ENTRY",SESSION_RECORD:"W_CYS_SESSION_RECORD",TOO_LARGE:gl,STYLES_NOT_IMPORTED:to,DANGLING_REFERENCE:Xi,EMPTY_INPUT:Ut,NO_GRAPH:ls,MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as}),E$="graphty.style.";class Se extends Error{constructor(e,n){super(n),this.name="ZipError",this.kind=e}}const _9=1024*1024,w$=101010256,S9=117853008,O9=101075792,Cg=33639248,bb=67324752,Ad=22,N9=65535,_s=46,gr=30,c_=56,A9=20,_$=65535,xs=4294967295,wu=2048,Hh=1024*1024,T9={1:"shrink",6:"implode",9:"deflate64",12:"bzip2",14:"LZMA",93:"zstd",95:"xz",96:"JPEG",97:"WavPack",98:"PPMd",99:"AES encryption"};function S$(t){return t.byteLength>=4&&t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}function I9(t,e){const n=e-A9;if(n>=0&&t.getUint32(n,!0)===S9){const o=v9(t,n);return{disk:t.getUint32(o+16,!0),directoryDisk:t.getUint32(o+20,!0),count:Ql(t,o+32),directorySize:Ql(t,o+40),directoryOffset:Ql(t,o+48),directoryEnd:o}}const i=t.getUint16(e+10,!0),r=t.getUint32(e+12,!0),s=t.getUint32(e+16,!0);if(i===_$||r===xs||s===xs)throw new Se("corrupt","the end record needs a zip64 record the archive does not have");return{disk:t.getUint16(e+4,!0),directoryDisk:t.getUint16(e+6,!0),count:i,directorySize:r,directoryOffset:s,directoryEnd:e}}function O$(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=C9(t,e);if(n<0)throw S$(t)?new Se("corrupt","the archive has no end of central directory record (truncated?)"):new Se("not-zip","the input is not a zip archive");const{disk:i,directoryDisk:r,count:s,directorySize:o,directoryOffset:l,directoryEnd:a}=I9(e,n);if(i!==0||r!==0)throw new Se("unsupported","a split (multi-disk) archive cannot be read");const c=a-o;if(c<0||l>t.byteLength)throw new Se("corrupt","the central directory lies outside the archive");const d=c-l;if(d<0)throw new Se("corrupt","the central directory offset does not match its position");const u=[];let f=c;for(let h=0;h<s;h++){if(f+_s>a||e.getUint32(f,!0)!==Cg)throw new Se("corrupt",`central directory entry ${h+1} of ${s} is damaged`);const p=e.getUint16(f+28,!0),g=e.getUint16(f+30,!0),m=e.getUint16(f+32,!0),y=f+_s+p+g+m;if(y>a)throw new Se("corrupt",`central directory entry ${h+1} runs past the directory`);const b=e.getUint16(f+8,!0),_=hy(t.subarray(f+_s,f+_s+p),(b&wu)===0);let S=e.getUint32(f+20,!0),T=e.getUint32(f+24,!0),$=e.getUint32(f+42,!0);(S===xs||T===xs||$===xs)&&({compressedSize:S,size:T,localOffset:$}=D9(e,f+_s+p,g,{compressedSize:S,size:T,localOffset:$})),u.push(Object.freeze({name:_,method:e.getUint16(f+10,!0),flags:b,crc32:e.getUint32(f+16,!0),compressedSize:S,size:T,localOffset:$+d,directory:_.endsWith("/")})),f=y}if(f+4<=a&&e.getUint32(f,!0)===Cg)throw new Se("corrupt",`the end record counts ${s} entries but the central directory holds more; entries would go unread`);return $9(u,e),u}function $9(t,e){const n=[...t].sort((r,s)=>r.localOffset-s.localOffset),i=r=>{const s=r.localOffset,l=s+gr<=e.byteLength&&e.getUint32(s,!0)===bb?e.getUint16(s+26,!0)+e.getUint16(s+28,!0):0;return s+gr+l+r.compressedSize};for(let r=1;r<n.length;r++){const s=n[r-1];if(n[r].localOffset<i(s))throw new Se("corrupt",`the entries ${s.name} and ${n[r].name} overlap`)}}function C9(t,e){const n=Math.max(0,t.byteLength-Ad-N9);let i=-1;for(let r=t.byteLength-Ad;r>=n;r--)if(e.getUint32(r,!0)===w$){if(r+Ad+e.getUint16(r+20,!0)===t.byteLength)return r;i<0&&(i=r)}return i}function v9(t,e){const n=Ql(t,e+8);for(const i of[n,e-c_])if(i>=0&&i+c_<=e&&t.getUint32(i,!0)===O9)return i;throw new Se("corrupt","the zip64 end record the locator names is missing")}function D9(t,e,n,i){const r={...i};for(let s=e;s+4<=e+n;){const o=t.getUint16(s,!0),l=t.getUint16(s+2,!0);if(o===1){let a=s+4;const c=a+l;for(const d of["size","compressedSize","localOffset"])if(i[d]===xs){if(a+8>c)throw new Se("corrupt","a zip64 extra field is too short");r[d]=Ql(t,a),a+=8}return r}s+=4+l}throw new Se("corrupt","an entry needs a zip64 extra field it does not have")}function Ql(t,e){const n=t.getUint32(e+4,!0);if(n>=2097152)throw new Se("unsupported","a zip64 size or offset beyond 2^53 cannot be read");return n*4294967296+t.getUint32(e,!0)}async function N$(t,e,n){if((e.flags&1)!==0||e.method===99)throw new Se("unsupported",`${e.name}: the entry is encrypted`);if(e.method!==0&&e.method!==8){const r=T9[e.method]??`method ${e.method}`;throw new Se("unsupported",`${e.name}: compression ${r} is not supported (only stored and deflate)`)}if(e.size>n.maxBytes)throw new Se("too-large",`${e.name}: ${e.size} uncompressed bytes exceed the limit of ${n.maxBytes}`);if(e.size>_9&&e.size>n.maxRatio*Math.max(e.compressedSize,1))throw new Se("too-large",`${e.name}: ${e.size} bytes from ${e.compressedSize} is a compression ratio above ${n.maxRatio}:1`);const i=k9(t,e);if(e.method===0){if(i.byteLength!==e.size)throw new Se("corrupt",`${e.name}: a stored entry's sizes disagree`);let r=4294967295;for(let s=0;s<i.byteLength;s+=Hh)F(n.signal),r=A$(r,i.subarray(s,Math.min(s+Hh,i.byteLength))),n.onBytes?.(Math.min(s+Hh,i.byteLength));if((r^4294967295)>>>0!==e.crc32)throw new Se("corrupt",`${e.name}: the data does not match its CRC-32`);return i}return R9(i,e,n)}function k9(t,e){const n=new DataView(t.buffer,t.byteOffset,t.byteLength),i=e.localOffset;if(i+gr>t.byteLength||n.getUint32(i,!0)!==bb)throw new Se("corrupt",`${e.name}: the local header is missing`);const r=n.getUint16(i+26,!0),s=hy(t.subarray(i+gr,Math.min(t.byteLength,i+gr+r)),(e.flags&wu)===0);if(s!==e.name)throw new Se("corrupt",`${e.name}: the local header names the entry ${JSON.stringify(s)}, the central directory ${JSON.stringify(e.name)}`);const o=i+gr+r+n.getUint16(i+28,!0),l=o+e.compressedSize;if(l>t.byteLength)throw new Se("corrupt",`${e.name}: the entry's data runs past the end of the archive (truncated?)`);return t.subarray(o,l)}async function R9(t,e,n){if(typeof DecompressionStream!="function")throw new Se("unsupported","this runtime has no DecompressionStream, so deflated entries cannot be read");const i=new Uint8Array(10+t.byteLength+8);i.set([31,139,8,0,0,0,0,0,0,255]),i.set(t,10);const r=new DataView(i.buffer,10+t.byteLength,8);r.setUint32(0,e.crc32,!0),r.setUint32(4,e.size%4294967296,!0);const o=new ReadableStream({start(u){u.enqueue(i),u.close()}}).pipeThrough(new DecompressionStream("gzip")).getReader(),l=[];let a=0;try{for(;;){F(n.signal);let u;try{u=await o.read()}catch{throw new Se("corrupt",`${e.name}: the deflate data is damaged or does not match its CRC-32 and size`)}if(u.done)break;if(a+=u.value.byteLength,a>e.size)throw new Se("corrupt",`${e.name}: the data is longer than its directory size`);l.push(u.value),n.onBytes?.(a)}}finally{await o.cancel().catch(()=>{})}if(a!==e.size)throw new Se("corrupt",`${e.name}: the data is shorter than its directory size`);if(l.length===1)return l[0];const c=new Uint8Array(a);let d=0;for(const u of l)c.set(u,d),d+=u.byteLength;return c}const L9=(()=>{const t=new Uint32Array(256);for(let e=0;e<256;e++){let n=e;for(let i=0;i<8;i++)n=(n&1)===1?3988292384^n>>>1:n>>>1;t[e]=n>>>0}return t})();function A$(t,e){let n=t;for(const i of e)n=L9[(n^i)&255]^n>>>8;return n>>>0}function P9(t){return(A$(4294967295,t)^4294967295)>>>0}const d_=33,Vh=10;function*x9(t){const e=new TextEncoder,n=[];let i=0,r=0;for(const a of t){const c=e.encode(a.name),{data:d}=a;if(i+gr+c.byteLength+d.byteLength>=xs||r===_$)throw new N("E_TOO_LARGE","the archive needs zip64, which graph-io does not write",{entry:a.name});const u=P9(d),f=new Uint8Array(gr+c.byteLength),h=new DataView(f.buffer);h.setUint32(0,bb,!0),h.setUint16(4,Vh,!0),h.setUint16(6,wu,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,d_,!0),h.setUint32(14,u,!0),h.setUint32(18,d.byteLength,!0),h.setUint32(22,d.byteLength,!0),h.setUint16(26,c.byteLength,!0),h.setUint16(28,0,!0),f.set(c,gr);const p=new Uint8Array(_s+c.byteLength),g=new DataView(p.buffer);g.setUint32(0,Cg,!0),g.setUint16(4,Vh,!0),g.setUint16(6,Vh,!0),g.setUint16(8,wu,!0),g.setUint16(10,0,!0),g.setUint16(12,0,!0),g.setUint16(14,d_,!0),g.setUint32(16,u,!0),g.setUint32(20,d.byteLength,!0),g.setUint32(24,d.byteLength,!0),g.setUint16(28,c.byteLength,!0),g.setUint32(42,i,!0),p.set(c,_s),n.push(p),yield f,d.byteLength>0&&(yield d),i+=f.byteLength+d.byteLength,r++}let s=0;for(const a of n)s+=a.byteLength,yield a;const o=new Uint8Array(Ad),l=new DataView(o.buffer);l.setUint32(0,w$,!0),l.setUint16(8,r,!0),l.setUint16(10,r,!0),l.setUint32(12,s,!0),l.setUint32(16,i,!0),yield o}const Is=Object.freeze({UNSET_AS_EMPTY_STRING:"W_CYS_UNSET_AS_EMPTY_STRING",LIST_ITEMS:"W_CYS_LIST_ITEMS",TEXT_AS_EQUATION:"W_CYS_TEXT_AS_EQUATION",JSON_AS_STRING:"W_CYS_JSON_AS_STRING",POSITION:"W_CYS_POSITION",COLUMN_NAME_CHANGED:w.COLUMN_NAME_CHANGED,ROLE_ASSUMED:w.ROLE_ASSUMED,MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,ID_TEXT_TYPE:w.ID_TEXT_TYPE,ID_TEXT_COLLISION:w.ID_TEXT_COLLISION,ID_CHARSET:w.ID_CHARSET,ID_MANGLED:w.ID_MANGLED,EDGE_IDS_GENERATED:w.EDGE_IDS_GENERATED,DTYPE_UNSUPPORTED:w.DTYPE,EMPTY_COLUMN_DROPPED:w.EMPTY_COLUMN,STORAGE_CLASS_CHANGED:w.STORAGE_CLASS,WEIGHT_KEY_CLASH:w.WEIGHT_KEY_CLASH,HIERARCHY_DROPPED:w.HIERARCHY,TEMPORAL_DROPPED:w.TEMPORAL,ROLE_DROPPED:w.ROLE,EXTENSION_TABLE_DROPPED:w.EXTENSION_TABLE}),T$=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"required",idCharset:"integer",dtypes:["string","dict","f64","i32","bool","list"],components:!1,lists:!0,json:!1,defaults:!1,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),M9=new Set(["label","id","position"]),U9=Object.freeze({label:"name",id:Qo,position:Tl}),G9=new Set(["directed","pair","mutual","weight","timeText","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),j9={node:new Map([["name","java.lang.String"],["shared name","java.lang.String"],["selected","java.lang.Boolean"]]),edge:new Map([["name","java.lang.String"],["shared name","java.lang.String"],["interaction","java.lang.String"],["shared interaction","java.lang.String"],["selected","java.lang.Boolean"]]),network:new Map([["name","java.lang.String"],["shared name","java.lang.String"],["selected","java.lang.Boolean"],["__annotations","java.util.List<java.lang.String>"]])},F9={node:new Set([Tl,lo,Qt,cc,Af,Ks,dc,el,Sa]),edge:new Set([Qo,Qt]),network:new Set([Qt])},Jn="java.lang.String",$f="java.lang.Double",vg="java.lang.Integer",_u="java.lang.Long",Eb="java.lang.Boolean",z9=2147483647,W9=Object.freeze({...TI,block:"native"}),fs="CytoscapeSession/",B9="Network",H9=/^[1-9]\d*$/;function I$(t){if(typeof t=="number")return Number.isSafeInteger(t)&&t>0?t:null;if(H9.test(t)){const e=Number(t);return Number.isSafeInteger(e)?e:null}return null}function V9(t){const e=[],n=[],i=new Set;for(let r=0;r<t.nodeCount;r++){const s=I$(t.ids.idOf(r));s===null||i.has(s)?(e.push(0),n.push(r)):(i.add(s),e.push(s))}return{kept:e,bad:n}}function Y9(t,e){const n=t.edges.byRole("id"),i=new Array(t.edgeCount).fill(0);if(n===null)return i;const r=new Set;for(let s=0;s<t.edgeCount;s++){const o=n.isSet(s)?n.value(s):null,l=typeof o=="number"||typeof o=="string"?I$(o):null;l!==null&&!r.has(l)&&!e.has(l)&&(r.add(l),i[s]=l)}return i}function Dg(t,e){switch(e){case"bool":return Eb;case"i32":case"u8":return vg;case"u32":return X9(t)>z9?_u:vg;case"f32":case"f64":return/long$/i.test(t.meta.origin?.type??"")&&K9(t)?_u:$f;default:return Jn}}function $$(t,e){return t.dtype==="list"?[...t.sliceOf(e)]:[t.value(e)]}function K9(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!$$(t,e).every(n=>typeof n=="number"&&Number.isSafeInteger(n)))return!1;return!0}function X9(t){let e=0;for(let n=0;n<t.length;n++)if(t.isSet(n))for(const i of $$(t,n))typeof i=="number"&&i>e&&(e=i);return e}function kg(t,e,n){return e===Eb?t===!0?"true":"false":e===$f?Ar(t,n==="f32"?"f32":"f64"):e===vg||e===_u?String(t):C$(t)}function C$(t){return typeof t=="string"?t:typeof t=="number"?Fe(t):typeof t=="boolean"?t?"true":"false":ArrayBuffer.isView(t)?JSON.stringify(Array.from(t).map(q9)):JSON.stringify(t)??""}function q9(t){return Number.isFinite(t)?t:String(t)}function Rg(t,e){const{meta:n}=t;if(t.dtype==="list"){const r=n.itemDtype,s=Dg(t,r==="json"?null:r);return{name:e,source:t,javaClass:`java.util.List<${s}>`,cell:o=>t.isSet(o)?[...t.sliceOf(o)].map(l=>kg(l,s,r)).join(`
|
|
51
|
+
`):null}}const i=n.dtype==="json"||n.components>1?Jn:Dg(t,n.dtype);return{name:e,source:t,javaClass:i,cell:r=>t.isSet(r)?kg(t.value(r),i,n.dtype):null}}function J9(t,e,n){const i=new Set(["suid"]),r=[];for(const s of e){const o=s.name.toLowerCase(),l=j9[t].get(o);let{name:a}=s;const c=l!==void 0&&l!==s.javaClass?l:null;if(i.has(o)||c!==null){let d=2;for(;i.has(`${o}#${d}`);)d++;a=`${s.name}#${d}`;const u=Z9(o,c),f=s.source===null?null:s.source.length-s.source.nullCount;n(w.COLUMN_NAME_CHANGED,`${t} column "${s.name}" is written as "${a}": ${u}`,s.name,f)}else s.source!==null&&F9[t].has(s.name)&&n(w.COLUMN_NAME_CHANGED,`${t} column "${s.name}" is written to the session's table and reads back as "${s.name}#2": graph-io's session reader makes a "${s.name}" column of its own`,s.name,s.source.length-s.source.nullCount);i.add(a.toLowerCase()),r.push({name:a,javaClass:s.javaClass,cell:s.cell})}return r}function Z9(t,e){return t==="suid"?"SUID is Cytoscape's key column":e!==null?`Cytoscape's own "${t}" column holds ${e}`:"its name is taken (Cytoscape column names ignore case)"}function u_(t){if(!t.includes(`
|
|
52
|
+
`))return[t];const e=t.split(`
|
|
53
|
+
`);for(;e.at(-1)==="";)e.pop();return e}function Q9(t,e,n,i){const{source:r}=e;if(r===null)return;const s=`${t} column "${r.meta.name}"`,{name:o}=r.meta,l=e.javaClass===Jn,{unset:a,equations:c,lists:d,set:u,heuristic:f}=eF(e,r,n);if(r.dtype==="json"&&i(Is.JSON_AS_STRING,`${s} holds nested values; written as their JSON text`,o,u),u===0&&(!l||n===0)){i(w.EMPTY_COLUMN,`${s} has no value; it is not in the re-import`,o,null);return}if(l&&a>0&&i(Is.UNSET_AS_EMPTY_STRING,`${s}: ${a} unset cell${O(a)} ${C(a,"is","are")} written empty and read back as ""`,o,a),d>0&&i(Is.LIST_ITEMS,`${s}: ${d} list cell${O(d)} ${C(d,"reads","read")} back changed (an unset or empty list of text as [""], an empty list of numbers unset, trailing empty items dropped, items holding a newline split)`,o,d),c>0&&i(Is.TEXT_AS_EQUATION,`${s}: ${c} cell${O(c)} start with "=", which Cytoscape reads as a formula (an error cell); graph-io reads them back as text`,o,c),l&&(r.dtype==="string"||r.dtype==="dict")){const h=f.decide();h!==r.dtype&&i(w.STORAGE_CLASS,`${s} reads back as ${h} (the cardinality heuristic)`,o,null)}}function eF(t,e,n){const i=t.javaClass===Jn,r=t.javaClass===`java.util.List<${Jn}>`,s={unset:0,equations:0,lists:0,set:0,heuristic:new no};for(let o=0;o<n;o++){const l=t.cell(o);l===null?s.unset++:s.set++;const a=l??"";i&&!s.heuristic.decided&&s.heuristic.observe(a),a.startsWith("=")?s.equations++:e.dtype==="list"&&tF(e,o,l,r)&&s.lists++}return s}function tF(t,e,n,i){const r=n??"";let s=null;i?s=r.length===0?[""]:u_(r):r.length>0&&(s=u_(r).filter(l=>l.length>0));const o=n===null?null:[...t.sliceOf(e)].map(l=>kg(l,"",null));return s===null||o===null?s!==o:s.length!==o.length||i&&s.some((l,a)=>l!==o[a])}function nF(t){return t.meta.name===lo&&t.meta.dtype==="f64"&&t.meta.role===null}function f_(t,e,n,i,r){const s=e==="node"?t.nodes:t.edges,o=s.byRole("label"),l=[];if(o!==null){const a=Rg(o,"name");l.push({...a,javaClass:Jn,cell:c=>o.isSet(c)?C$(o.value(c)):null}),o.dtype!=="string"&&o.dtype!=="dict"&&r(w.DTYPE,`${e} label column "${o.meta.name}" (${o.dtype}) is written as text and reads back as string`,o.meta.name,o.length-o.nullCount)}l.push(...n);for(const a of s){const{role:c}=a.meta;a===o||c!==null&&(G9.has(c)||c==="id")||i(a)||(l.push(Rg(a,a.meta.name)),o===null&&c===null&&a.meta.name==="name"&&Dg(a,a.dtype)===Jn&&r(w.ROLE_ASSUMED,`${e} column "name" is Cytoscape's name and reads back as the label`,"name",a.length-a.nullCount))}return l}function Yh(t,e,n,i){for(const r of e)Q9(t,r,n,i);return J9(t,e,i)}function iF(t,e){let n=0,i=0;const r=new Set;for(let o=0;o<t.nodeCount;o++){const l=t.ids.idOf(o);i+=typeof l=="number"?1:0;const a=String(l);r.has(a)&&n++,r.add(a)}let s=null;return n>0&&(e(w.ID_TEXT_COLLISION,`${n} node id${O(n)} ${C(n,"shares","share")} their text with another id (a number and a string); the save fails with E_INVALID_ID`,null,n),s=new N("E_INVALID_ID",`${n} node id${O(n)} ${C(n,"shares","share")} their text with another id`,{reason:"collision",count:n})),i>0&&e(w.ID_TEXT_TYPE,`${i} numeric node id${O(i)} ${C(i,"reads","read")} back as their text`,null,i),s}function rF(t,e,n,i){if(n)return i(w.ID_MANGLED,`${e.length} node id${O(e.length)} that ${C(e.length,"is","are")} not positive integers ${C(e.length,"is","are")} renumbered, since Cytoscape ids are positive integers; the originals are kept in the "${Ps}" column (restored by restoreMangledIds)`,null,e.length),null;i(w.ID_CHARSET,`${e.length} node id${O(e.length)} ${C(e.length,"is","are")} not positive integers, which Cytoscape requires; the save fails unless sanitizeIds is "mangle"`,null,e.length);const r=t.ids.idOf(e[0]);return new N("E_INVALID_ID",`${e.length} node id${O(e.length)} cannot be written as Cytoscape ids, which are positive integers (first: ${JSON.stringify(r)} at index ${e[0]}); pass sanitizeIds: "mangle" to rewrite them`,{reason:"charset",charset:"integer",count:e.length,index:e[0]})}function sF(t,e,n){const{kept:i,bad:r}=V9(t),s=iF(t,n),o=r.length>0?rF(t,r,e.sanitizeIds==="mangle",n):null,l=s??o,a=new Set(i.filter(g=>g>0)),c=Y9(t,a);let d=1;for(const g of[...a,...c])d=Math.max(d,g+1);const u=i.map(g=>g>0?g:d++),f=t.edges.byRole("id");let h=0;const p=c.map(g=>g>0?g:(h++,d++));return f!==null&&h>0&&n(w.EDGE_IDS_GENERATED,`${h} edge${O(h)} ${C(h,"has","have")} no distinct positive integer id in "${f.meta.name}"; they are written with new positive integer ids`,f.meta.name,h),f!==null&&f.dtype!=="string"&&n(w.DTYPE,`edge id column "${f.meta.name}" is ${f.dtype}; edge ids read back as text`,f.meta.name,t.edgeCount-f.nullCount),{nodeSuids:u,edgeSuids:p,next:d,fatal:l,mangled:e.sanitizeIds==="mangle"&&r.length>0}}function oF(t,e){const n=[],i=t.graph.get("name");(i===null||i.dtype!=="string"&&i.dtype!=="dict")&&n.push({name:"name",source:null,javaClass:Jn,cell:()=>e});const{description:r}=t.meta;r!==null&&t.graph.get("description")===null&&n.push({name:"description",source:null,javaClass:Jn,cell:()=>r});for(const s of t.graph)s.meta.name!==Z&&n.push(Rg(s,s.meta.name));return n}function h_(t,e){const n=[];for(const[i,r]of e){if(t.has(i))continue;const s=new Set(r.filter(a=>a!==null).map(a=>typeof a)),[o]=s;let l=Jn;s.size===1&&o==="number"?l=$f:s.size===1&&o==="boolean"&&(l=Eb),n.push({name:i,source:null,javaClass:l,cell:a=>{const c=r[a]??null;return c===null?null:typeof c=="number"?Ar(c):String(c)}})}return n}function v$(t,e,n){const i=[],r=(Ke,us,ze=null,yh=null)=>{i.push(Object.freeze({code:Ke,message:us,column:ze,count:yh}))},s=Un(t,T$,e,{roles:M9,roleNames:U9,positionDtype:"f64"});i.push(...s.filter(Ke=>!lF.has(Ke.code)));const o=sF(t,e,r),{nodeSuids:l,edgeSuids:a,mangled:c,fatal:d}=o;let{next:u}=o;const f=u++,h=u++,p=Gt(t);aF(p.mutualCount,r);const g=t.nodes.byRole("position"),m=[...t.nodes].find(nF)??null,y=g!==null&&m===null;g!==null&&fF(g,m,r);const b=p_(g)||p_(m),_=new se,S=n===void 0?null:nI(n.rules,t,{dialect:"desktop",notes:_}),T=Ke=>S!==null&&cF(Ke),$=b||S!==null?u++:null,D=u,x=c?[dF(t)]:[],R=Yh("node",[...f_(t,"node",x,Ke=>b&&Ke===m||T(Ke),r),...S===null?[]:h_(t.nodes,S.columns.node)],t.nodeCount,r),G=uF(t,r),B=t.edgeCount,Q=Yh("edge",[...f_(t,"edge",G,T,r),...S===null?[]:h_(t.edges,S.columns.edge)],B,r),be=t.meta.name??B9,De=Yh("network",oF(t,be),1,r),J=[{name:"name",javaClass:Jn,cell:()=>be}],st=n===void 0?null:Nl(n.rules,{inlineColumns:!0,snapshot:t}),ee=st===null?[]:lc(st,n?.rules.styles.rules.length??0,"size");return{notes:i,fatal:d,nodeSuids:l,edgeSuids:a,rootSuid:f,subSuid:h,viewSuid:$,viewNodeBase:D,name:be,folding:p,nodeTable:R,edgeTable:Q,networkTable:De,rootTable:J,position:g,z:b?m:null,positionZ:y,styled:S,styleNotes:[..._.list().map(cb),...ee],block:n===void 0?ab(t):st}}const lF=new Set([w.JSON,w.ID_CHARSET,w.ID_MANGLED]);function aF(t,e){t>0&&e(w.MUTUAL_EXPANDED,`${t} mutual pair${O(t)} ${C(t,"is","are")} written as two directed edges; the mutual mark is lost`,null,t)}function p_(t){return t!==null&&t.nullCount<t.length}function cF(t){return t.dtype==="json"&&t.meta.origin?.type==="graphics"&&t.meta.origin.namespace===pn}function dF(t){return{name:Ps,source:null,javaClass:Jn,cell:e=>String(t.ids.idOf(e))}}function uF(t,e){const n=Ot(t),i=t.edges.get("weight");return i!==null&&i.meta.role===null&&!n.weighted&&e(w.WEIGHT_KEY_CLASH,'edge column "weight" reads back as the edge weight',"weight",null),n.weighted?[{name:"weight",source:null,javaClass:$f,cell:r=>n.isExplicit(r)?Ar(n.value(r)):null}]:[]}function fF(t,e,n){const{name:i,components:r}=t.meta;r!==3&&n(Is.POSITION,`position column "${i}" has ${r} component${O(r)} and reads back with 3`,i,null);let s=0,o=0;for(let l=0;l<t.length;l++){if(!t.isSet(l))continue;const a=Array.from(t.value(l));a.slice(0,2).some(c=>!Number.isFinite(c))?s++:(a[2]??0)!==0&&o++}s>0&&n(Is.POSITION,`${s} position${O(s)} with a non-finite coordinate ${C(s,"is","are")} not written`,i,s),o>0&&n(Is.POSITION,e===null?`${o} position${O(o)} ${C(o,"has","have")} a z; it is written as the view's z and reads back in the z column`:`${o} position${O(o)} ${C(o,"has","have")} a z, but the view's z holds the z column; the position z is lost`,i,o)}function zc(t){const e=t.replaceAll(new RegExp("[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]","g"),"�");return encodeURIComponent(e).replaceAll(/[!~'()]/g,n=>`%${(n.codePointAt(0)??0).toString(16).toUpperCase()}`).replaceAll("%20","+").replaceAll("-","%2D")}function*Wc(t,e,n){const i=r=>`${r.map(s=>s===null?"":hf(s)).join(",")}
|
|
54
|
+
`;yield i(["CyCSV-Version","1"]),yield i(["SUID",...e.map(r=>r.name)]),yield i([_u,...e.map(r=>r.javaClass)]),yield i(["",...e.map(()=>"mutable")]),yield i([t,""]);for(const[r,s]of n)yield i([String(r),...e.map(o=>o.cell(s)??(o.name.startsWith(E$)?null:""))])}const wb=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
55
|
+
`,D$=`xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="${sb}" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cy="${bI}" xmlns="${_a}"`;function*hF(t,e){const n=Bs(e.name)?"":` label="${W(e.name)}"`;yield wb,yield`<graph id="${e.rootSuid}"${n} directed="${t.directed?"1":"0"}" cy:view="0" cy:registered="0" cy:documentVersion="3.0" ${D$}>
|
|
56
|
+
`,yield` <att>
|
|
57
|
+
<graph id="${e.subSuid}"${n} cy:registered="1">
|
|
58
|
+
`;for(let s=0;s<t.nodeCount;s++)yield` <node id="${e.nodeSuids[s]}"/>
|
|
59
|
+
`;const{src:i,dst:r}=t.edgeList();for(let s=0;s<t.edgeCount;s++){if(e.folding.folded(s))continue;const o=t.directed&&e.folding.sourceDirected(s);yield` <edge id="${e.edgeSuids[s]}" source="${e.nodeSuids[i[s]]}" target="${e.nodeSuids[r[s]]}" cy:directed="${o?"1":"0"}"/>
|
|
60
|
+
`}yield` </graph>
|
|
61
|
+
</att>
|
|
62
|
+
</graph>
|
|
63
|
+
`}function*pF(t,e,n){const i=e.styled===null?"default":e.name;yield wb,yield`<graph id="${n}" label="${n}" cy:view="1" cy:networkId="${e.subSuid}" cy:visualStyle="${W(i)}" cy:rendererId="org.cytoscape.ding" cy:documentVersion="3.0" ${D$}>
|
|
64
|
+
`;let r=e.viewNodeBase;for(let s=0;s<t.nodeCount;s++){const o=gF(e,s),l=e.styled?.bypasses.node[s]??null;(o.length>0||l!==null)&&(yield` <node id="${r++}" cy:nodeId="${e.nodeSuids[s]}">
|
|
65
|
+
`,yield*g_(o,l),yield` </node>
|
|
66
|
+
`)}for(let s=0;s<t.edgeCount;s++){const o=e.styled?.bypasses.edge[s]??null;o!==null&&!e.folding.folded(s)&&(yield` <edge id="${r++}" cy:edgeId="${e.edgeSuids[s]}">
|
|
67
|
+
`,yield*g_([],o),yield` </edge>
|
|
68
|
+
`)}yield`</graph>
|
|
69
|
+
`}function*g_(t,e){const n=t.length===0?" <graphics":` <graphics ${t.join(" ")}`;if(e===null){yield`${n}/>
|
|
70
|
+
`;return}yield`${n}>
|
|
71
|
+
<att name="lockedVisualProperties">
|
|
72
|
+
`;for(const[i,r]of e)yield` <att name="${W(i)}" value="${W(String(r))}" type="string" cy:type="String"/>
|
|
73
|
+
`;yield` </att>
|
|
74
|
+
</graphics>
|
|
75
|
+
`}function gF(t,e){const n=[];if(t.position?.isSet(e)===!0){const[i,r,s]=Array.from(t.position.value(e)),o=t.position.dtype==="f32"?ct:Fe;Number.isFinite(i)&&Number.isFinite(r)&&n.push(`x="${o(i)}"`,`y="${o(r===0?0:-r)}"`),Number.isFinite(i)&&Number.isFinite(r)&&t.positionZ&&s!==void 0&&s!==0&&Number.isFinite(s)&&n.push(`z="${o(s)}"`)}return t.z?.isSet(e)===!0&&n.push(`z="${Ar(t.z.value(e))}"`),n}function hs(t){let e="";for(const n of t)e+=n;return new TextEncoder().encode(e)}function*mF(t,e){if(e.fatal!==null)throw e.fatal;const n=zc(e.name),i=`${fs}tables/${e.subSuid}-${n}/LOCAL_ATTRS-org.cytoscape.model.`,r=(a,c)=>a.flatMap((d,u)=>c?.(u)===!0?[]:[[d,u]]),s=`${e.name} default node`,o=`${e.name} default edge`,l=`${e.name} default network`;yield{name:`${fs}3.0.0.version`,data:new Uint8Array(0)},yield{name:`${fs}networks/${e.rootSuid}-${n}.xgmml`,data:hs(hF(t,e))},yield{name:`${i}CyNode-${zc(s)}.cytable`,data:hs(Wc(s,e.nodeTable,r(e.nodeSuids)))},yield{name:`${i}CyEdge-${zc(o)}.cytable`,data:hs(Wc(o,e.edgeTable,r(e.edgeSuids,a=>e.folding.folded(a))))},yield{name:`${i}CyNetwork-${zc(l)}.cytable`,data:hs(Wc(l,e.networkTable,[[e.subSuid,0]]))},yield{name:`${fs}tables/${e.rootSuid}-${n}/LOCAL_ATTRS-org.cytoscape.model.CyNetwork-${e.rootSuid}+default+network.cytable`,data:hs(Wc(`${e.rootSuid} default network`,e.rootTable,[[e.rootSuid,0]]))},e.viewSuid!==null&&(yield{name:`${fs}views/${e.subSuid}-${e.viewSuid}-${n}.xgmml`,data:hs(pF(t,e,e.viewSuid))}),e.styled!==null&&(yield{name:`${fs}session_vizmap.xml`,data:hs([wb,`<vizmap documentVersion="3.0" id="VizMap-graphty">
|
|
76
|
+
`,m4(e.styled.style,e.name),`
|
|
77
|
+
</vizmap>
|
|
78
|
+
`])}),e.block!==null&&(yield{name:`${fs}${Z}`,data:new TextEncoder().encode(e.block)})}async function*yF(t,e){const n=v$(t,ft(e),e?.styles);await Promise.resolve(),yield*x9(mF(t,n))}const bF=Object.freeze({format:ri,options:Object.freeze([]),capabilities:T$,styles:Object.freeze({capabilities:W9}),check(t,e){const n=v$(t,ft(e),e?.styles);return Object.freeze([...n.notes,...n.styleNotes])},export(t,e){return yF(t,e)},exportToString(){return Promise.reject(new N("E_UNSUPPORTED","a Cytoscape session is a zip file, not text; use exportGraphToBytes() or exportGraphToBlob()",{reason:"binary"}))}});function Ms(t){const e=t.replaceAll("+"," ");try{return decodeURIComponent(e)}catch{return e}}async function EF(t,e,n,i){const r=await KA(t,n);r===null&&e.fail(ae.NOT_ZIP,"a Cytoscape session is a zip archive; text input cannot hold one (pass the bytes)"),r.byteLength===0&&e.fail(ae.EMPTY_INPUT,"the input is empty");let s;try{s=O$(r)}catch(u){return m_(u,e)}const o=NF(s,e);let l=i,a=0;const c=[...o.networks,...o.views,...o.tables,...o.files.values(),...[o.cytables,o.networkList,o.cysession].filter(u=>u!==null)].reduce((u,f)=>u+f.zip.size,0),d=new Set;return{layout:o,read:async(u,f)=>{const h=!d.has(u.name),p=a;try{const g=await N$(r,u.zip,{signal:n.signal,maxBytes:h?l:u.zip.size,maxRatio:E9,onBytes:h?m=>n.onProgress?.(Math.min(p+m,c),c):void 0});return h&&(d.add(u.name),l-=g.byteLength,a+=g.byteLength),g}catch(g){return m_(g,f)}},done:()=>{n.onProgress?.(c,c)}}}function m_(t,e){if(!(t instanceof Se))throw t;const n={"not-zip":ae.NOT_ZIP,corrupt:ae.CORRUPT,unsupported:ae.UNSUPPORTED,"too-large":ae.TOO_LARGE}[t.kind];if(t.kind==="too-large")throw e.error("unsupported",n,t.message),e.abort(t.message,{code:n});e.fail(n,t.message)}function y_(t,e){const n=s=>s.split("/").length,i=t.filter(s=>e.test(s)),r=Math.min(...i.map(n));return i.filter(s=>n(s)===r)}const wF=/^networks\/(\d+)(?:-([^/]*))?\.xgmml$/,_F=/^views\/(\d+)-(\d+)(?:-[^/]*)?\.xgmml$/,SF=/^tables\/((\d+)(?:-[^/]*)?\/([^/-]+)-([^/-]+)-[^/]*\.cytable)$/,OF=/(^|\/)(__MACOSX\/|\.DS_Store$)/;function NF(t,e){const n=new Map,i=[];for(const h of t){const p=h.name.replaceAll("\\","/");if(!(p.endsWith("/")||OF.test(p))){if(n.has(p)){i.push(p);continue}n.set(p,h)}}i.length>0&&e.warning("unsupported",ae.DUPLICATE_ENTRY,`${i.length} entry name${O(i.length)} appear more than once; the first of each is read: ${nl(i)}`);const r=[...n.keys()],s=y_(r,/(^|\/)[^/]+\.version$/),o=s.at(0),l=y_(r,/(^|\/)cysession\.xml$/).at(0);s.length>1&&e.warning("validation-error",ae.ENTRY_SKIPPED,`the session has ${s.length} version markers (${nl(s)}); ${s[0]} is used and the others are not read`);const a=o??l;a===void 0&&e.fail(ae.NOT_SESSION,"the zip holds neither a session version marker (<x.y.z>.version) nor cysession.xml: it is not a Cytoscape session");const c=a.slice(0,a.lastIndexOf("/")+1);let d="2",u="2.0.0";if(o!==void 0){u=o.slice(c.length,-8),/^\d+(\.\d+)*$/.test(u)||e.fail(ae.VERSION,`the session version marker ${o} does not parse as a version (<major>.<minor>.<patch>.version)`);const h=Number(u.split(".")[0]);h>3&&e.fail(ae.VERSION,`the session version ${u} is newer than the Cytoscape 3 sessions graph-io reads`),d=h===3?"3":"2"}const f={era:d,version:u,root:c,networks:[],views:[],tables:[],cytables:null,networkList:null,cysession:null,files:new Map,styles:[],block:null,skipped:[]};for(const[h,p]of n){if(!h.startsWith(c)||h===o){h!==o&&!s.includes(h)&&f.skipped.push(h);continue}const m={path:h.slice(c.length),name:h,zip:p};d==="3"?AF(m,f):TF(m,f)}return f}function AF(t,e){const{path:n}=t,i=wF.exec(n),r=_F.exec(n),s=SF.exec(n);if(i!==null)e.networks.push({...t,suid:i[1],title:Ms(i[2]??"")});else if(r!==null)e.views.push({...t,network:r[1],view:r[2]});else if(n==="tables/cytables.xml")e.cytables=t;else if(s!==null){const o={"org.cytoscape.model.CyNode":"node","org.cytoscape.model.CyEdge":"edge","org.cytoscape.model.CyNetwork":"network"}[Ms(s[4])];if(o===void 0){e.skipped.push(t.name);return}e.tables.push({...t,tablePath:s[1],network:s[2],namespace:Ms(s[3]),element:o})}else n==="apps/org.cytoscape.swing-application/network_list.xml"?e.networkList=t:/(^|\/)session_vizmap\.(xml|props)$/.test(n)?e.styles.push(t):n===Z?e.block=t:e.skipped.push(t.name)}function TF(t,e){const{path:n}=t;n==="cysession.xml"?e.cysession=t:/^[^/]+\.xgmml$/.test(n)?e.files.set(n,t):/^session_vizmap\.(props|xml)$/.test(n)?e.styles.push(t):e.skipped.push(t.name)}function nl(t){const e=t.slice(0,10).map(yn).join(", ");return t.length>10?`${e} and ${t.length-10} more`:e}function yn(t){return t.replace(/^[^/]*CytoscapeSession[^/]*\//,"")}async function IF(t,e,n,i){const r=await Cf(t,e,n,i);return typeof r=="string"?n.fail(ae.CORRUPT,`${e}: ${r}`):r}async function Cf(t,e,n,i){const r=new ne(ri,0),s=[{name:"",attrs:new Map,children:[]}];try{await ff($r(t,r,{signal:i.signal,declaredEncoding:uf,xml:!0}),{start(l,a){const c={name:l.slice(l.lastIndexOf(":")+1),attrs:a,children:[]};s[s.length-1].children.push(c),s.push(c)},end(){s.pop()},text(){}})}catch(l){if(l instanceof te||l instanceof it)return l.message;throw l}for(const l of r.issues)l.severity==="warning"&&n.warning(l.category,l.code,`${e}: ${l.message}`,{line:l.line,element:e});const[o]=s[0].children;return o??"the document is empty"}function _b(t,e){const n=[],i=[t];for(;i.length>0;){const r=i.pop();r.name===e&&n.push(r);for(let s=r.children.length-1;s>=0;s--)i.push(r.children[s])}return n}function $F(t,e){const n=e.kept;if(n?.era==="2")return SI(t,e,{tool:"cytoscape-fallbacks",hiddenColumn:Eu});const i=new se,r=CF(n,i),s={node:{values:{}},edge:{values:{}}};for(const o of["node","edge"])e.signal?.throwIfAborted(),o==="edge"&&q1(r.edge,n?.weightFrom??null,t.edges),s[o]=vF(t,o,r,{notes:i,budget:e.budget},s.node.values);return{canonical:!0,dialect:"cytoscape",tool:"cytoscape-fallbacks",units:"px",node:s.node,edge:s.edge,graph:AI(t,i,r),notes:i.list()}}function CF(t,e){if(t?.vizmap===null||t?.vizmap===void 0){const n=t?.problem??null;return e.add(n===null?v.NO_VIZMAP:v.UNREADABLE,null,"session_vizmap.xml",{sample:n??"absent"}),oo()}return DF(t.vizmap,t.visualStyle,e)}function vF(t,e,n,i,r){const{notes:s}=i,o=e==="node"?t.nodes:t.edges,l=e==="node"?t.nodeCount:t.edgeCount;X1(n[e],f=>o.has(f)),J1(n[e],f=>o.get(f)?.meta.origin?.type??null,s,e);for(const f of n[e].mappings.values())o.has(f.column)||s.add(v.MAPPING_COLUMN_MISSING,e,f.column,{sample:f.kind});const a={count:l,value:(f,h)=>o.has(f)?yf(o,f,h):null,bypasses:_I(o,e,l,s),...e==="edge"?{ends:Of(t,r)}:{}},c=nb(e,n,a,i);OI(o,Eu,l,c),NI(t,e,r,c),ob(t,e,c);const{rules:d,columns:u}=yI(e,n,a,i);return{values:lb(c),rules:d,columns:u}}function DF(t,e,n){const i=oo(),r=t.children.filter(o=>o.name==="visualStyle");let s=r.find(o=>o.attrs.get("name")===e);if(s===void 0){if(s=r.at(0),s===void 0)return n.add(v.NO_VIZMAP,null,"visualStyle",{sample:"no visualStyle"}),i;n.add(v.VIEW_STYLE_MISSING,null,"visualStyle",{sample:String(e)})}r.length>1&&n.add(v.OTHER_STYLES,null,"visualStyle",{sample:`${r.length-1} unused`,count:r.length-1});for(const o of["network","node","edge"]){const l=s.children.find(a=>a.name===o);for(const a of l?.children??[])kF(i,o,a)}return i}function kF(t,e,n){const i=n.attrs.get("name");if(i===void 0)return;if(n.name==="dependency"&&e!=="network"){t[e].dependencies.set(i,n.attrs.get("value")?.trim().toLowerCase()==="true");return}if(n.name!=="visualProperty")return;const r=n.attrs.get("default");if(r!==void 0&&t[e].defaults.set(i,r),e!=="network"){const s=RF(n);s!==null&&t[e].mappings.set(i,s)}}function RF(t){for(const e of t.children){const n=e.attrs.get("attributeName");if(n===void 0)continue;const i=e.attrs.get("attributeType")??null;if(e.name==="passthroughMapping")return{kind:"passthrough",column:n,type:i};if(e.name==="discreteMapping")return{kind:"discrete",column:n,type:i,table:LF(e,i)};if(e.name==="continuousMapping")return{kind:"continuous",column:n,type:i,points:PF(e)}}return null}function LF(t,e){const n=[];for(const i of t.children){const r=Qy(i.attrs.get("attributeValue"),e),s=i.attrs.get("value");i.name==="discreteMappingEntry"&&r!==null&&s!==void 0&&n.push([r,s])}return n}function PF(t){return t.children.filter(e=>e.name==="continuousMappingPoint"&&Number.isFinite(Number(e.attrs.get("attrValue")))).map(e=>({at:Number(e.attrs.get("attrValue")),below:e.attrs.get("lesserValue"),value:e.attrs.get("equalValue"),above:e.attrs.get("greaterValue")}))}const b_={"java.lang.String":"String","java.lang.Long":"Long","java.lang.Integer":"Integer","java.lang.Double":"Double","java.lang.Boolean":"Boolean"},xF=/^java\.util\.List<\s*([\w.]+)\s*>$/;async function MF(t,e,n,i,r){const s=await UF(t,r);if(typeof s=="string")return Kh(i,n,s);const o=GF(s);if(typeof o=="string")return Kh(i,n,o);const l=jF(s[o.at].cells,s[o.at+1].cells);if(typeof l=="string")return Kh(i,n,l);const{rows:a,lines:c,quotedEmpty:d,problems:u}=FF(s.slice(o.at+o.lines),l.length);return u.short+u.long+u.repeated>0&&i.warning("parse-error",ae.TABLE_ROW,`${yn(n)}: ${u.short} row${O(u.short)} with too few cells (the rest are unset), ${u.long} with too many (the extra cells are ignored), ${u.repeated} repeating a key (the first row is read)`),{path:e,entry:n,columns:l,rows:a,lines:c,quotedEmpty:d}}async function UF(t,e){const n=new ne(ri,0),i=new yT(t,n,{delimiter:",",encoding:"utf-8",signal:e.signal}),r=[];try{for await(const s of i){const o=s.flatMap((l,a)=>l.length===0&&i.quoted[a]?[a]:[]);r.push({cells:s,line:i.line,quotedEmpty:o.length===0?void 0:new Set(o)})}}catch(s){if(s instanceof it)return n.issues.at(-1)?.message??s.message;throw s}return r}function GF(t){let e=0,n=0;if(t[0]?.cells[0]==="CyCSV-Version"){const{cells:l}=t[0];if(l.length!==2||!/^\d+$/.test(l[1].trim()))return`the version row ${JSON.stringify(l)} does not parse`;n=Number(l[1]),e=1}if(n!==0&&n!==1)return`CyCSV version "${t[0].cells[1]}" is not 0 or 1`;const i=n===1?4:3;if(t.length<e+i-1)return"the table header is incomplete";const r=t[e+i-2],s=t.at(e+i-1),o=s===void 0||s.line>r.line+1&&!r.cells.some(l=>/[\r\n]/.test(l));return{at:e,lines:o?i-1:i}}function jF(t,e){if(t.length===0||e.length!==t.length)return`${t.length} column name${O(t.length)} but ${e.length} column class(es)`;const n=[];for(let i=0;i<t.length;i++){const r=zF(t[i],e[i]);if(r===null)return`column "${t[i]}" has the class "${e[i]}", which graph-io cannot read`;n.push(r)}return n}function FF(t,e){const n=new Map,i=new Map,r=new Map,s={short:0,long:0,repeated:0};for(const o of t){const{cells:l}=o;l.length<e?s.short++:l.length>e&&s.long++;const a=l[0];if(n.has(a)){s.repeated++;continue}n.set(a,l.slice(0,e)),i.set(a,o.line),o.quotedEmpty!==void 0&&r.set(a,o.quotedEmpty)}return{rows:n,lines:i,quotedEmpty:r,problems:s}}function zF(t,e){const n=b_[e.trim()];if(n!==void 0)return{name:t,type:n,list:!1};const i=xF.exec(e.trim()),r=i===null?void 0:b_[i[1]];return r===void 0?null:{name:t,type:r,list:!0}}function Kh(t,e,n){return t.error("parse-error",ae.TABLE,`${yn(e)}: ${n}; the table is not read`),null}function k$(t,e,n,i,r,s=!1){const o={line:n,namespace:i,hidden:r};if(e.startsWith("="))return Bc(t.name,t.list?"List":t.type,null,e,!0,o);if(!t.list)return e.length===0&&(t.type!=="String"||!s&&t.name.startsWith(E$))?null:Bc(t.name,t.type,null,e,!1,o);if(e.length===0&&t.type!=="String")return null;const l=Bc(t.name,"List",t.type,null,!1,o);for(const a of WF(e))a.length===0&&t.type!=="String"||l.children.push(Bc(t.name,t.type,null,a,!1,o));return l}function WF(t){if(!t.includes(`
|
|
79
|
+
`)&&!t.includes("\r"))return[t];const e=t.split(/\r\n|\r|\n/);for(;e.at(-1)?.length===0;)e.pop();return e}function Bc(t,e,n,i,r,s){const{line:o,namespace:l,hidden:a}=s;return{name:t,type:null,cyType:e,elementType:n,value:i,hidden:a,equation:r,children:[],extra:{},xml:null,hasGraph:!1,text:"",line:o,namespace:l}}async function BF(t,e,n,i){const r=[];for(const s of e){if(s.targetTable!==t.path)continue;const o=await R$(s,e,n,new Set);if(typeof o=="string"){i.error("parse-error",ae.TABLE,`${t.entry}: the virtual column "${s.name}" ${o}; the column is not read`);continue}const l=t.columns.findIndex(c=>c.name===s.targetJoinKey);if(l<0){i.error("parse-error",ae.TABLE,`${t.entry}: the virtual column "${s.name}" joins on the column "${s.targetJoinKey}", which the table does not have; the column is not read`);continue}const a=new Map;for(const[c,d]of t.rows){const u=l<=0?c:d[l],f=u===void 0?void 0:o.values.get(u);f!==void 0&&a.set(c,f)}r.push({column:{...o.column,name:s.name},values:a})}return r}async function R$(t,e,n,i){if(i.has(t))return"is part of a cycle of virtual columns";i.add(t);const r=await n(t.sourceTable);if(r===null)return`names the source table "${t.sourceTable}", which the session does not hold or cannot read`;const s=r.columns.findIndex(f=>f.name===t.sourceJoinKey);if(s<0)return`joins on the column "${t.sourceJoinKey}", which its source table does not have`;const o=(f,h)=>s===0?f:h[s],l=r.columns.findIndex(f=>f.name===t.sourceColumn);if(l>=0){const f=new Map;for(const[h,p]of r.rows){const g=o(h,p);g!==void 0&&p[l]!==void 0&&f.set(g,p[l])}return{column:r.columns[l],values:f}}const a=e.find(f=>f.targetTable===r.path&&f.name===t.sourceColumn);if(a===void 0)return`names the source column "${t.sourceColumn}", which its source table does not have`;const c=await R$(a,e,n,i);if(typeof c=="string")return c;const d=new Map,u=r.columns.findIndex(f=>f.name===a.targetJoinKey);if(u<0)return`reads the virtual column "${a.name}", which joins on the column "${a.targetJoinKey}" its table does not have`;for(const[f,h]of r.rows){const p=u<=0?f:h[u],g=p===void 0?void 0:c.values.get(p),m=o(f,h);g!==void 0&&m!==void 0&&d.set(m,g)}return{column:c.column,values:d}}const HF={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},L$=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]);function VF(t){if(t===void 0)return b9;if(typeof t!="number"||!(t>0))throw new N("E_UNSUPPORTED",`option maxUncompressedBytes: ${JSON.stringify(t)} is not a positive number`,{option:"maxUncompressedBytes",found:t});return t}async function Sb(t,e,n){const i=tt(n,HF),r=new ne(ri,i.errorLimit);e!==null&&(_t(e,n,r,!0),St(n,r,L$));const{zAs:s}=$g({zAs:n?.zAs},!1),o=VF(n?.maxUncompressedBytes),l=await EF(t,r,i,o),a=Object.freeze({...i,onProgress:null,encoding:null}),c=new Map,d=l.layout.era==="3"?await YF(l,r,a,c):await pz(l,r,a);return{report:r,common:i,inner:a,zAs:s,session:l,choices:d,docs:c}}async function P$(t,e,n,i){return await x$(t,e,n,i,!1)}async function x$(t,e,n,i,r){const s=new ne(ri,Math.max(0,n.errorLimit-n.errorCount));try{const o=await t.read(e,s),l=await g$(o,s,i,void 0),a=u$(l,s);return Xh(s.issues,n,e.name),E_(s,n),{doc:l,dialect:a}}catch(o){if(!(o instanceof it))throw o;E_(s,n);const{issues:l}=s;s.truncated&&Xh(l,n,e.name);const a=l.at(-1);Xh(l.slice(0,-1),n,e.name);const c=`${yn(e.name)}: ${a?.message??o.message}`,d={line:a?.line??null};if(a?.code===ae.TOO_LARGE)throw n.error("unsupported",a.code,c),n.abort(c,{code:a.code});return r?(n.error("parse-error",a?.code??ae.CORRUPT,`${c}; the entry is not read`,d),null):n.fail(a?.code??ae.CORRUPT,c,d)}}function E_(t,e){for(const n of Object.keys(t.counts))e.counts[n]+=t.counts[n]}function Xh(t,e,n){for(const i of t){const r={line:i.line,element:i.element};i.severity==="error"?e.error(i.category,i.code,`${yn(n)}: ${i.message}`,r):e.warning(i.category,i.code,`${yn(n)}: ${i.message}`,r)}}async function YF(t,e,n,i){const{layout:r}=t,s=[];for(const u of r.networks){const f=await P$(t,u,e,n);f.dialect.view&&e.fail(j.VIEW_DOCUMENT,`${u.name}: this is a session view file (cy:view), not a network file; it holds no topology`,{line:f.doc.root.line}),i.set(u.name,f);for(const h of M$(f)){if(h.id===null){const g=h.label===null?"":` ("${h.label}")`;e.error("missing-value",j.MISSING_ID,`${u.name}: a registered subnetwork${g} has no id; its tables and views cannot be found and it is skipped`,{line:h.line});continue}const p=ao(f.doc,h);s.push({era:"3",network:u,graph:h,graphId:h.id,name:h.label??h.id,nodes:new Set(p.nodes).size,edges:p.edges.length})}}const o=new Set(s.map(u=>u.graphId)),l=r.views.filter(u=>!o.has(u.network)).map(u=>u.name),a=r.tables.filter(u=>!o.has(u.network)&&!r.networks.some(f=>f.suid===u.network)&&!KF(u,t,i));if((l.length>0||a.length>0)&&e.warning("validation-error",ae.DANGLING_REFERENCE,`${l.length+a.length} view${O(l.length+a.length)} or table${O(l.length+a.length)} ${C(l.length+a.length,"belongs","belong")} to a network the session does not hold and were not read: ${nl([...l,...a.map(u=>u.name)])}`),r.networkList===null)return s;const c=await Cf(await t.read(r.networkList,e),r.networkList.name,e,n);if(typeof c=="string")return e.warning("unsupported",ae.ENTRY_SKIPPED,`${r.networkList.name}: ${c}; it is not read and the networks are listed in entry order`),s;const d=new Map;for(const u of _b(c,"network")){const f=u.attrs.get("id"),h=Number(u.attrs.get("order"));f!==void 0&&Number.isFinite(h)&&d.set(f,h)}return s.map((u,f)=>({choice:u,index:f})).sort((u,f)=>(d.get(u.choice.graphId)??1/0)-(d.get(f.choice.graphId)??1/0)||u.index-f.index).map(u=>u.choice)}function KF(t,e,n){for(const i of e.layout.networks)if(n.get(i.name)?.doc.graphs.some(r=>r.id===t.network)===!0)return!0;return!1}function M$(t){const e=t.doc.root.subgraphs.filter(n=>Si(n.registered));return e.length===0&&Si(t.doc.root.registered)?[t.doc.root]:e}async function XF(t,e,n,i){const{graph:r}=e,s=ao(i.doc,r),o=w_(s.nodes),l=w_(s.edges),a=qF(r,o,l);try{return await JF(t,e,n,i,o,l)}finally{a()}}function qF(t,e,n){const i=[...e.values()].map(l=>({n:l,atts:l.atts.length,x:l.x,y:l.y,z:l.z,graphics:l.graphics})),r=[...n.values()].map(l=>({e:l,atts:l.atts.length,graphics:l.graphics})),s=t.atts.length,o=t.graphics;return()=>{for(const{n:l,atts:a,x:c,y:d,z:u,graphics:f}of i)l.atts.length=a,Object.assign(l,{x:c,y:d,z:u,graphics:f});for(const{e:l,atts:a,graphics:c}of r)l.atts.length=a,l.graphics=c;t.atts.length=s,t.graphics=o}}async function JF(t,e,n,i,r,s){const{report:o,inner:l}=t,{doc:a,dialect:c}=i,{graph:d}=e,u=ao(a,d),f=await ez(t,e,a,r,s);f>0&&o.warning("parse-error",ae.TABLE_ROW,`${f} table row${O(f)} of network ${e.graphId} ${C(f,"names","name")} no node, edge or network in it (left over from deleted elements) and ${C(f,"is","are")} not read`);const h=l.restoreMangledIds?cz(u.nodes):new Map,{visualStyle:p,extraViews:g,extraIds:m}=await rz(t,e,r,s),y=t.session.layout.block===null?null:await yz(t,t.session.layout.block);y!==null&&d.atts.push(bz(Z,y));const b=j$(t,{collection:a.root.label??e.network.title,network:e.graphId,parentNetwork:uz(d,t.choices),visualStyle:p}),_=[];b.groups=_;const S={sourceFormat:ri,entry:e.network.name,graphName:dz(d)??e.name,metaExtra:{[b$]:b},labelFromName:!0,restoredIds:h,groupNodes:ZF(u.nodes),resolvePointer:fz(t,a),onMissingMember:($,D)=>{QF(_,$,D)}},T={labelAliases:!1,cytoscapeEscapes:!1,zAs:t.zAs};if(new mb(a,c,n,o,t.inner,T,S).emit(d),_.length>0){const $=_.reduce((D,x)=>D+x.members.length,0);o.warning("unsupported",ae.COLLAPSED_GROUP,`${_.length} collapsed group${O(_.length)} ${C(_.length,"holds","hold")} ${$} member${O($)} that are not in the network; they are listed in meta.extra.cytoscape.groups`)}return hz(i,o,e.network.name),az(n,g,m,o,t.inner,h),p}function ZF(t){return new Set(t.filter(e=>e.atts.some(n=>n.name==="__isGroup"&&Si(n.value))).flatMap(e=>e.id===null?[]:[e.id]))}function QF(t,e,n){const i=t.find(r=>r.group===e);i===void 0?t.push({group:e,members:[n]}):i.members.includes(n)||i.members.push(n)}async function ez(t,e,n,i,r){const{report:s,inner:o,session:l}=t,{layout:a}=l,c=new Map,d=h=>{let p=c.get(h);if(p===void 0){const g=a.tables.find(m=>m.tablePath===h);p=g===void 0?Promise.resolve(null):l.read(g,s).then(m=>MF(m,h,g.name,s,o)),c.set(h,p)}return p},u={choice:e,graph:e.graph,nodes:i,edges:r,declared:new Set([...n.nodes.flatMap(h=>h.id===null?[]:[h.id]),...n.edges.flatMap(h=>h.id===null?[]:[h.id])]),virtuals:a.cytables===null?[]:await sz(l,a.cytables,s,o),tableOf:d,report:s};let f=0;for(const h of a.tables.filter(p=>p.network===e.graphId&&p.element!==null)){F(o.signal);const p=await d(h.tablePath);p!==null&&(f+=await tz(u,h,p))}return f}async function tz(t,e,n){const i=e.namespace==="LOCAL_ATTRS",r=i?null:e.namespace,s=!i&&e.namespace!=="SHARED_ATTRS",o=a=>e.element==="network"?a===t.choice.graphId?t.graph.atts:void 0:(e.element==="node"?t.nodes:t.edges).get(a)?.atts;let l=0;for(const[a,c]of n.rows){const d=o(a);d!==void 0?d.push(...nz(n,a,c,r,s)):t.declared.has(a)||l++}for(const a of await BF(n,t.virtuals,t.tableOf,t.report)){const c=n.columns.some(u=>u.name===a.column.name),d=i?iz(c):r;for(const[u,f]of a.values){const h=o(u);h!==void 0&&U$(h,k$(a.column,f,n.lines.get(u)??0,d,s))}}return l}function nz(t,e,n,i,r){const s=t.lines.get(e)??0,o=[];for(let l=1;l<t.columns.length&&l<n.length;l++){const a=t.quotedEmpty?.get(e)?.has(l)===!0;U$(o,k$(t.columns[l],n[l],s,i,r,a))}return o}function iz(t){return t?"SHARED_ATTRS":null}function U$(t,e){e!==null&&t.push(e)}async function rz(t,e,n,i){const{report:r,inner:s,session:o}=t,l=o.layout.views.filter(f=>f.network===e.graphId).sort((f,h)=>f.view.length-h.view.length||(f.view<h.view?-1:+(f.view>h.view)));let a=null;const c=[],d=[];let u=!0;for(const f of l){const h=(await x$(o,f,r,s,!0))?.doc;h!==void 0&&(u?(u=!1,a=h.root.attrs.get("cy:visualStyle")??null,oz(h,e.graph,n,i,r,f.name)):(c.push(lz(h,t.zAs,n,r,f.name)),d.push(f.view)))}return{visualStyle:a,extraViews:c,extraIds:d}}async function sz(t,e,n,i){const r=await Cf(await t.read(e,n),e.name,n,i);if(typeof r=="string")return n.error("parse-error",ae.TABLE,`${yn(e.name)}: ${r}; its virtual columns are not read`),[];const s=[];for(const o of _b(r,"virtualColumn")){const l=["name","targetTable","sourceTable","sourceColumn"].filter(c=>!o.attrs.has(c));if(l.length>0){const c=o.attrs.has("name")?` "${o.attrs.get("name")??""}"`:"";n.error("parse-error",ae.TABLE,`${yn(e.name)}: a virtual column${c} has no ${l.join(", ")}; the column is not read`);continue}const a=c=>o.attrs.get(c)??"";s.push({name:a("name"),targetTable:a("targetTable"),sourceTable:a("sourceTable"),sourceColumn:a("sourceColumn"),sourceJoinKey:o.attrs.get("sourceJoinKey")??"SUID",targetJoinKey:o.attrs.get("targetJoinKey")??"SUID"})}return s}function w_(t){const e=new Map;for(const n of t)n.id!==null&&!e.has(n.id)&&e.set(n.id,n);return e}function oz(t,e,n,i,r,s){let o=0;const l=new Set;for(const a of t.nodes){const c=a.viewId===null?void 0:n.get(a.viewId);if(c===void 0){o++;continue}G$(l,a,r,s),c.x=a.x,c.y=a.y,c.z=a.z,a.graphics!==null&&(c.graphics={...c.graphics,...a.graphics})}for(const a of t.edges){const c=a.viewId===null?void 0:i.get(a.viewId);if(c===void 0){o++;continue}a.graphics!==null&&(c.graphics={...c.graphics,...a.graphics})}t.root.graphics!==null&&(e.graphics={...e.graphics,...t.root.graphics}),o>0&&r.warning("validation-error",ae.DANGLING_REFERENCE,`${yn(s)}: ${o} view element${O(o)} ${C(o,"names","name")} no node or edge of the network; they are not read`)}function G$(t,e,n,i){const r=e.viewId;t.has(r)&&n.warning("validation-error",j.DUPLICATE_NODE,`${yn(i)}: the view gives node "${r}" twice; the later element is used`,{line:e.line,element:r}),t.add(r)}function lz(t,e,n,i,r){const s=new Map,o=new Set;let l=0;const a=(c,d)=>{if(c===null)return null;const u=f$(c);return u===null&&i.error("validation-error",j.BAD_VALUE,`${yn(r)}: graphics coordinate "${c}" is not a number`,{line:d.line,element:d.viewId}),u};for(const c of t.nodes){if(c.viewId===null||!n.has(c.viewId)){l++;continue}G$(o,c,i,r);const d=a(c.x,c),u=a(c.y,c),f=e==="position"?a(c.z,c):null;d!==null&&u!==null?s.set(c.viewId,[d,u===0?0:-u,f??0]):s.delete(c.viewId)}return l>0&&i.warning("validation-error",ae.DANGLING_REFERENCE,`${yn(r)}: ${l} view element${O(l)} ${C(l,"names","name")} no node of the network; they are not read`),s}function az(t,e,n,i,r,s){const o=new Mn(r.ids);e.forEach((l,a)=>{const c=`${y9}${a+2}`,{handle:d}=he(t,"node",{name:c,dtype:"f32",components:3,nullable:!0,origin:{format:ri,id:n[a],title:null,type:"graphics",namespace:pn},extra:{sourceDims:2,units:"file"}},i,{element:c});for(const[u,f]of l){let h;try{h=t.indexOf(o.text(s.get(u)??u))}catch{continue}h!==A&&t.setNodeValue(d,h,f)}})}function cz(t){const e=new Map;for(const n of t){const i=n.atts.findIndex(r=>r.name===Ps&&(r.namespace??null)===null&&r.value!==null&&r.children.length===0);n.id!==null&&i>=0&&(e.set(n.id,n.atts[i].value),n.atts.splice(i,1))}return e}function dz(t){return t.atts.find(n=>n.name==="name"&&(n.namespace??null)===null)?.value??null}function uz(t,e){const n=t.atts.find(s=>s.name==="__parentNetwork.SUID"||s.name==="Cy2 Parent Network.SUID");if(n?.value===void 0||n.value===null||n.value.length===0)return null;const i=n.value;return e.find(s=>s.era==="3"&&s.graphId===i)?.name??i}function fz(t,e){const n=new Map;for(const i of e.graphs){const{href:r}=i,s=r?.indexOf("#")??-1;if(r===null||s<=0||n.has(r))continue;const o=Ms(r.slice(0,s)),l=r.slice(s+1),a=t.session.layout.networks.find(u=>Ms(u.path.slice(9))===o),d=(a===void 0?void 0:t.docs.get(a.name))?.doc.graphs.find(u=>u.id===l);d!==void 0&&n.set(r,d.label??l)}return i=>n.get(i)??null}function hz(t,e,n){const i=new Set;for(const o of M$(t)){const l=ao(t.doc,o);l.nodes.forEach(a=>i.add(a)),l.edges.forEach(a=>i.add(a))}const r=t.doc.nodes.filter(o=>!i.has(o)).length,s=t.doc.edges.filter(o=>!i.has(o)).length;r+s>0&&e.warning("unsupported",j.ROOT_ONLY_ELEMENTS,`${yn(n)}: ${kA(r,s)} ${C(r+s,"belongs","belong")} to none of the session's networks (group meta-edges or collapsed group members) and ${C(r+s,"was","were")} not read`)}async function pz(t,e,n){const{layout:i}=t;if(i.cysession===null)return e.fail(ae.NOT_SESSION,"the session has no cysession.xml");const r=await IF(await t.read(i.cysession,e),i.cysession.name,e,n),s=r.attrs.get("documentVersion")??"";s.length>0&&!/^\d+(\.\d+)*$/.test(s.trim())&&e.warning("validation-error",j.DOCUMENT_VERSION,`${i.cysession.name}: documentVersion "${s}" does not parse; the session is read as Cytoscape 2.x`),s.startsWith("3")&&e.fail(ae.VERSION,`cysession.xml has documentVersion ${s} and no version marker: the 2011 Cytoscape 3.0 pre-release layout, which no released Cytoscape reads`);const o=new Map;for(const[f,h]of i.files)o.set(f,h),o.set(Ms(f),h);const l=[...i.files.values()],a=[],c=[],d=new Set;for(const f of _b(r,"network")){const h=f.attrs.get("id"),p=f.attrs.get("filename")??(h===void 0?void 0:`${h}.xgmml`);if(h==="Network Root")continue;if(p===void 0){qh(e,i.cysession.name,"a <network> has neither an id nor a filename; it is not read");continue}const g=h??Ms(p.replace(/\.xgmml$/i,""));h===void 0&&qh(e,i.cysession.name,`a <network> for ${p} has no id; it is named "${g}" after its file`);const m=o.get(p);if(m===void 0){c.push(p);continue}if(d.has(m)){qh(e,i.cysession.name,`the <network> "${g}" names ${p}, which an earlier record already names; it is not read a second time`);continue}d.add(m);const y=f.children.find(b=>b.name==="parent")?.attrs.get("id")??null;a.push({era:"2",file:m,name:g,record:f,parent:y==="Network Root"||y==="NULL"?null:y})}c.length>0&&e.warning("validation-error",ae.DANGLING_REFERENCE,`cysession.xml names ${c.length} network file${O(c.length)} the session does not hold: ${nl(c)}`);const u=l.filter(f=>!d.has(f)).map(f=>f.name);return u.length>0&&e.warning("unsupported",ae.ENTRY_SKIPPED,`${u.length} network file${O(u.length)} ${C(u.length,"is","are")} not in cysession.xml's network tree and were not read: ${nl(u)}`),a.sort((f,h)=>l.indexOf(f.file)-l.indexOf(h.file))}function qh(t,e,n){t.warning("validation-error",ae.SESSION_RECORD,`${yn(e)}: ${n}`)}async function gz(t,e,n){const{report:i,inner:r,session:s}=t,{doc:o,dialect:l}=await P$(s,e.file,i,r);let a=0;for(const[f,h]of[["selectedNodes",a_],["hiddenNodes",Eu]])a+=S_(o.nodes,__(e.record,f),h);for(const[f,h]of[["selectedEdges",a_],["hiddenEdges",Eu]])a+=S_(o.edges,__(e.record,f),h);a>0&&i.warning("validation-error",ae.DANGLING_REFERENCE,`cysession.xml lists ${a} selected or hidden name${O(a)} that ${e.file.name} does not hold; they are not read`);const c=j$(t,{collection:null,network:e.name,parentNetwork:e.parent,visualStyle:e.record.attrs.get("visualStyle")??null}),d={sourceFormat:ri,entry:e.file.name,graphName:e.name,metaExtra:{[b$]:c}},u={labelAliases:!0,cytoscapeEscapes:!0,zAs:t.zAs};return new mb(o,l,n,i,r,u,d).emit(null),c.visualStyle}function __(t,e){const n=new Set;for(const i of t.children.filter(r=>r.name===e))for(const r of i.children){const s=r.attrs.get("id");s!==void 0&&n.add(s)}return n}function S_(t,e,n){if(e.size===0)return 0;const i=new Set;for(const r of t)r.id!==null&&e.has(r.id)&&i.add(r.id),r.label!==null&&e.has(r.label)&&i.add(r.label),(r.id!==null&&e.has(r.id)||r.label!==null&&e.has(r.label))&&r.atts.push({name:n,type:null,cyType:"Boolean",elementType:null,value:"true",hidden:!1,equation:!1,children:[],extra:{},xml:null,hasGraph:!1,text:"",line:r.line,namespace:m9});return e.size-i.size}function j$(t,e){const{layout:n}=t.session,{report:i}=t;return n.styles.length>0&&i.warning("unsupported",ae.STYLES_NOT_IMPORTED,`the session's styles (${n.styles.map(r=>r.path).join(", ")}) are not applied`),n.skipped.length>0&&i.warning("unsupported",ae.ENTRY_SKIPPED,`${n.skipped.length} ${n.skipped.length===1?"entry holds":"entries hold"} no graph data and ${C(n.skipped.length,"was","were")} not read (apps, global tables, properties, images): ${nl(n.skipped)}`),{sessionVersion:n.version,...e,skippedEntries:[...n.skipped]}}async function F$(t,e,n){const i=t.choices[e];let r;if(i.era==="3"){const s=t.docs.get(i.network.name);r=await XF(t,i,n,s)}else r=await gz(t,i,n);return await mz(t,e,r),F(t.common.signal),t.report.finish()}async function mz(t,e,n){const{layout:i}=t.session,r=i.styles.find(a=>a.path.endsWith("session_vizmap.xml"));let s=null,o=null;if(i.era==="3"&&r!==void 0){const a=await z$(t,r),c=typeof a=="string"?a:await Cf(a,r.name,new ne(ri,0),t.inner);typeof c=="string"?o=c:s=c}const l={era:i.era,vizmap:s,problem:o,visualStyle:n,network:{index:e,name:t.choices[e].name},weightFrom:t.inner.weightFrom};t.report.keepForStyles(l)}async function z$(t,e){try{return await t.session.read(e,new ne(ri,0))}catch(n){if(n instanceof it)return n.message;throw n}}async function yz(t,e){const n=await z$(t,e);if(typeof n=="string")return null;try{return await Kr(n,new ne(ri,0),{signal:t.common.signal})}catch(i){if(i instanceof it)return null;throw i}}function bz(t,e){return{name:t,type:"string",cyType:"String",elementType:null,value:e,hidden:!1,equation:!1,children:[],extra:{},xml:null,hasGraph:!1,text:"",line:0,namespace:null}}async function Ez(t,e,n){const i=await Sb(t,e,n),r=ml(i.choices.map(o=>o.name),n,i.report);i.choices.length>1&&!io(n)&&i.report.warning("unsupported",ae.MULTIPLE_GRAPHS,`the session holds ${i.choices.length} networks; only the first is read (importAllGraphs() reads every one; graphIndex or graphName chooses one)`);const s=await F$(i,r,e);return i.session.done(),s}async function wz(t,e,n){const i=await Sb(t,null,n),r=i.report.fork(),s=[];for(let o=0;o<i.choices.length;o++){const l=e(o),a=o===0?i:{...i,report:r.fork()};_t(l,n,a.report,!0),St(n,a.report,L$),s.push(await F$(a,o,l))}return i.session.done(),s}async function _z(t,e){return(await Sb(t,null,e)).choices.map((i,r)=>Object.freeze({index:r,name:i.name,nodes:i.era==="3"?i.nodes:null,edges:i.era==="3"?i.edges:null}))}const Sz=[/CytoscapeSession|cysession\.xml/,new RegExp("(?<!\\d)\\d+\\.\\d+\\.\\d+\\.version"),/(?:^|\/)apps\/org\.cytoscape\./,/(?:^|\/)(?:networks|views)\/\d+-[^/]*\.xgmml/,/(?:^|\/)tables\/\d+-[^/]*\/[^/]+\.cytable/];function Oz(t){for(let e=0;e+4<=t.byteLength;e++)if(S$(t.subarray(e)))return Sz.some(n=>n.test(hy(t.subarray(e))))?.95:0;return 0}const Nz=Object.freeze({format:ri,options:Object.freeze(["maxUncompressedBytes","zAs"]),extensions:p9,mimeTypes:g9,sniff:Oz,import:Ez,importAll:wz,listGraphs:_z,styles:$F});class Il{#e=new Map;add(e,n,i){const r=`${e}.${n}`,s=this.#e.get(r)??{count:0,samples:new Set};s.count++,s.samples.size<8&&s.samples.add(String(i)),this.#e.set(r,s)}notes(e){return Array.from(this.#e,([n,i])=>{const[r,s]=n.split(".");return Object.freeze({code:v.APPROXIMATED,message:`${r} ${s} is written as the nearest value ${e} has for ${String(i.count)} ${r}${i.count===1?"":"s"} (${[...i.samples].join(", ")}); the graphty.styles block keeps the exact value`,column:null,count:i.count,style:Object.freeze({target:r,property:s})})})}}function Ir(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Gi(t){const e=t.indexOf(":");return e<0?t:t.slice(e+1)}function wt(t,e){const n=[];if(!Ir(t))return n;for(const i of Object.keys(t)){if(i.startsWith("@_")||i==="#text"||Gi(i)!==e)continue;const r=t[i];if(Array.isArray(r))for(const s of r)n.push(s);else n.push(r)}return n}function ue(t,e){if(Ir(t)){for(const n of Object.keys(t))if(!n.startsWith("@_")&&n!=="#text"&&Gi(n)===e){const i=t[n];return Array.isArray(i)?i[0]:i}}}function k(t,e){if(!Ir(t)||!Object.hasOwn(t,`@_${e}`))return;const n=t[`@_${e}`];return typeof n=="string"?n:void 0}function Ob(t){if(typeof t=="string")return t;if(Ir(t)&&Object.hasOwn(t,"#text")){const e=t["#text"];return typeof e=="string"?e:null}return null}function Lg(t){const e=[];for(const n of t)n.dtype==="json"&&n.meta.origin?.namespace==="yfiles"&&e.push(n.meta.name);return e}function Pg(t){const e=[];for(const n of t)n.meta.origin?.namespace==="yfiles"&&e.push(n.meta.name);return e}const Nb=new Set(["ShapeNode","GenericNode","GroupNode","GenericGroupNode","SVGNode","ImageNode","TableNode","UMLClassNode","UMLNoteNode","ProxyAutoBoundsNode"]),Ab=new Set(["PolyLineEdge","ArcEdge","BezierEdge","QuadCurveEdge","SplineEdge","GenericEdge"]);function vf(t,e){if(!Ir(t))return null;for(const n of Object.keys(t)){const i=Gi(n);if(n.startsWith("@_")||!e.has(i))continue;const r=t[n],s=Array.isArray(r)?r[0]:r;return i==="ProxyAutoBoundsNode"?Az(s):{type:i,r:s}}return null}function Az(t){const e=ue(t,"Realizers"),n=[];if(Ir(e))for(const r of Object.keys(e).filter(s=>!s.startsWith("@_")&&s!=="#text"))for(const s of wt(e,Gi(r)))n.push({type:Gi(r),r:s});const i=Number(k(e,"active")??"0");return n[Number.isInteger(i)&&i>=0&&i<n.length?i:0]??null}function Ur(t,e,n,i,r,s,o=12){return Array.from({length:o+1},(l,a)=>{const c=r+(s-r)*a/o;return Tb(t+n*Math.cos(c),e+i*Math.sin(c))})}function Jh(t,e,n,i){return Array.from({length:17},(s,o)=>{const l=n+(i-n)*o/16;return Tb(l,t+e*Math.sin(Math.PI*l))})}function Tb(t,e){const n=i=>String(Math.round(i*1e3)/1e3+0);return`${n(t)},${n(e)}`}const Wt=Math.PI/2,Tz=Array.from({length:72},(t,e)=>{const n=2*Math.PI*e/72,i=.86+.14*Math.abs(Math.cos(4*n));return Tb(i*Math.cos(n),i*Math.sin(n))}).join(" "),Iz=[...Ur(.5,0,.5,1,-Wt,Wt),...Ur(-.5,0,.5,1,Wt,3*Wt)].join(" "),$z=new Map([["flowchart.process",{shape:"rectangle"}],["flowchart.predefinedprocess",{shape:"rectangle"}],["flowchart.internalstorage",{shape:"rectangle"}],["flowchart.decision",{shape:"diamond"}],["flowchart.terminator",{shape:"round-rectangle"}],["flowchart.start1",{shape:"ellipse"}],["flowchart.start2",{shape:"ellipse"}],["flowchart.onpagereference",{shape:"ellipse"}],["flowchart.sequentialdata",{shape:"ellipse"}],["flowchart.data",{shape:"parallelogram"}],["flowchart.preparation",{shape:"hexagon"}],["flowchart.database",{shape:"other:database"}],["flowchart.looplimit",{shape:"polygon",points:"-1,-1 1,-1 1,0.5 0.8,1 -0.8,1 -1,0.5"}],["flowchart.looplimitend",{shape:"polygon",points:"-1,1 -1,-0.5 -0.8,-1 0.8,-1 1,-0.5 1,1"}],["flowchart.manualinput",{shape:"polygon",points:"-1,-1 1,-1 1,1 -1,0.4"}],["flowchart.card",{shape:"polygon",points:"-1,-1 1,-1 1,1 -0.6,1 -1,0.6"}],["flowchart.manualoperation",{shape:"polygon",points:"-1,1 -0.7,-1 0.7,-1 1,1"}],["flowchart.offpagereference",{shape:"polygon",points:"-1,1 -1,0 0,-1 1,0 1,1"}],["flowchart.usermessage",{shape:"polygon",points:"-1,1 -1,-1 0.6,-1 1,0 0.6,1"}],["flowchart.networkmessage",{shape:"polygon",points:"-1,1 -0.6,0 -1,-1 1,-1 1,1"}],["flowchart.document",{shape:"polygon",points:["-1,1",...Jh(-.75,.2,-1,1),"1,1"].join(" ")}],["flowchart.papertype",{shape:"polygon",points:[...Jh(-.8,.2,-1,1),...Jh(.8,.2,1,-1)].join(" ")}],["flowchart.delay",{shape:"polygon",points:["-1,-1",...Ur(0,0,1,1,-Wt,Wt),"-1,1"].join(" ")}],["flowchart.display",{shape:"polygon",points:["-1,0","-0.6,-1",...Ur(.6,0,.4,1,-Wt,Wt),"-0.6,1"].join(" ")}],["flowchart.storeddata",{shape:"polygon",points:[...Ur(1,0,-.2,1,-Wt,Wt),...Ur(-.8,0,.2,1,Wt,3*Wt)].join(" ")}],["flowchart.directdata",{shape:"polygon",points:[...Ur(.8,0,.2,1,-Wt,Wt),...Ur(-.8,0,.2,1,Wt,3*Wt)].join(" ")}],["flowchart.cloud",{shape:"polygon",points:Tz}],["entityrelationship.relationship",{shape:"diamond"}],["entityrelationship.attribute",{shape:"ellipse"}],["bpmn.conversation",{shape:"hexagon"}],["sbgn.unspecifiedentity",{shape:"ellipse"}],["sbgn.simplechemical",{shape:"ellipse"}],["sbgn.emptyset",{shape:"ellipse"}],["sbgn.operator",{shape:"ellipse"}],["sbgn.macromolecule",{shape:"round-rectangle"}],["sbgn.phenotype",{shape:"hexagon"}],["sbgn.process",{shape:"rectangle"}],["sbgn.submap",{shape:"rectangle"}],["sbgn.unitofinformation",{shape:"rectangle"}],["sbgn.statevariable",{shape:"polygon",points:Iz}],["sbgn.tag",{shape:"polygon",points:"-1,1 -1,-1 0.6,-1 1,0 0.6,1"}]]);function Df(t){const e=t.slice(0,Ce).toLowerCase().replace(/^com\.yworks\./,"").replace(/\.withshadow$/,"");return $z.get(e)??null}const Cz=[["bpmn.activity","round-rectangle"],["bpmn.event","ellipse"],["bpmn.gateway","diamond"],["entityrelationship.attribute","ellipse"],["ellipse","ellipse"],["circle","ellipse"],["oval","ellipse"],["diamond","diamond"],["decision","diamond"],["hexagon","hexagon"],["octagon","octagon"],["triangle","triangle"],["rect","rectangle"],["process","rectangle"],["box","rectangle"]],vz=new Map([["c","center"],["t","top"],["b","bottom"],["l","left"],["r","right"],["tl","top-left"],["tr","top-right"],["bl","bottom-left"],["br","bottom-right"],["n","top"],["s","bottom"],["e","right"],["w","left"],["nw","top-left"],["ne","top-right"],["sw","bottom-left"],["se","bottom-right"]]),W$=new Map([["plain",["normal",!1]],["bold",["bold",!1]],["italic",["normal",!0]],["bolditalic",["bold",!0]]]);function Go(t,e,n,i,r){const s=ve(t,"yed",r(e));if(s===null)return;i(e,s.color);const o=Ol(s,null,r(e),n!==null);n!==null&&i(n,o)}function B$(t,e,n,i,r){let s,o="",l=0;for(const a of t){const c=Ob(a)?.trim()??"";c.length===0||k(a,"visible")==="false"||k(a,"hasText")==="false"||(s===void 0?(s=a,o=c):l++)}s!==void 0&&(l>0&&H(i("label"),v.EXTRA_LABELS,`${String(l+1)} labels`),n("label",rt(o,i("label"))),Dz(s,e,n,i,r))}function Dz(t,e,n,i,r){Go(k(t,"textColor"),"labelColor",null,n,i),k(t,"hasBackgroundColor")!=="false"&&Go(k(t,"backgroundColor"),"labelBackground",null,n,i),k(t,"hasLineColor")!=="false"&&k(t,"lineColor")!==void 0&&(Go(k(t,"lineColor"),"labelBorderColor",null,n,i),n("labelBorderWidth",1)),n("labelSize",Y(k(t,"fontSize"),i("labelSize")));const s=rt(k(t,"fontFamily"),i("labelFont"));n("labelFont",s===null?null:_f(s));const o=k(t,"fontStyle");if(o!==void 0){const l=W$.get(o.trim().toLowerCase());l===void 0?H(i("labelWeight"),v.UNKNOWN_VALUE,o.slice(0,Ce)):(n("labelWeight",l[0]),n("labelItalic",l[1]))}if(kz(t,n,i),e){const l=Pz(t,r,i);n("labelPosition",l),Lz(t,r,l,n),Rz(t,r,l,n)}}function kz(t,e,n){const i=wa(k(t,"rotationAngle"),n("labelRotation"));if(i===null)return;const r=(i%360+360)%360;e("labelRotation",r===0?null:r)}function Rz(t,e,n,i){const r=k(t,"modelName"),s=n==="center"&&r!==void 0&&r!=="internal";if(n===null||n.startsWith("inside-")||n==="center"&&!s||Number(k(t,"rotationAngle")??0)%360!==0)return;const o=(g,m)=>Number(k(g,m)??Number.NaN),[l,a,c,d]=["x","y","width","height"].map(g=>o(t,g)),[u,f]=[o(e,"width"),o(e,"height")];if(![l,a,c,d,u,f].every(Number.isFinite))return;const h=g=>{const m=Math.round(g*1e3)/1e3;return m===0?null:m},p=(g,m,y,b,_)=>h(b?g+m:_?g-y:g+m/2-y/2);i("labelOffsetX",p(l,c,u,n.includes("left"),n.includes("right"))),i("labelOffsetY",p(a,d,f,n.includes("top"),n.includes("bottom")))}function Lz(t,e,n,i){const r=k(t,"autoSizePolicy")?.startsWith("node_")===!0;if(n?.startsWith("inside-")!==!0||r)return;const s=(h,p)=>Number(k(h,p)??Number.NaN),[o,l,a,c]=["x","y","width","height"].map(h=>s(t,h)),[d,u]=[s(e,"width"),s(e,"height")],f=h=>Number.isFinite(h)&&h>0?Math.round(h*1e3)/1e3:null;if(n.includes("left"))i("labelOffsetX",f(o));else if(n.includes("right")){const h=f(d-o-a);i("labelOffsetX",h===null?null:-h)}if(n.includes("top"))i("labelOffsetY",f(l));else if(n.includes("bottom")){const h=f(u-l-c);i("labelOffsetY",h===null?null:-h)}}function Pz(t,e,n){const i=Uz(t,e);if(i!==null&&i!=="center")return i;const r=k(t,"modelPosition"),s=k(t,"modelName");if(s==="internal")return Gz(t,r);if(s==="custom")return xz(t,i,n);if(i!==null||r===void 0)return i;const o=vz.get(r.trim().toLowerCase());return o===void 0&&H(n("labelPosition"),v.UNKNOWN_VALUE,r.slice(0,Ce)),o??null}function xz(t,e,n){const i=ue(ue(t,"ModelParameter"),"SmartNodeLabelModelParameter");return i===void 0?(H(n("labelPosition"),v.UNKNOWN_VALUE,"custom"),e):e??Mz(i)}function Mz(t){const e=r=>{const s=Number(k(t,r));return Number.isFinite(s)?s:0},n=O_(e("nodeRatioX"),"left","right"),i=O_(e("nodeRatioY"),"top","bottom");return i==="top"&&n===""&&e("labelRatioY")<=0?"inside-top":i===""||n===""?i+n||"center":`${i}-${n}`}function O_(t,e,n){return t<0?e:t>0?n:""}function Uz(t,e){const n=(d,u)=>Number(k(d,u)??Number.NaN),[i,r,s,o]=["x","y","width","height"].map(d=>n(t,d)),[l,a]=[n(e,"width"),n(e,"height")];if(![i,r,s,o,l,a].every(Number.isFinite))return null;const c=(d,u,f)=>d+u<=0?-1:d>=f?1:0;return jz[c(r,o,a)+1][c(i,s,l)+1]}function Gz(t,e){const n=H$.get((e??"c").trim().toLowerCase())??"center",i=k(t,"alignment");return k(t,"autoSizePolicy")==="node_width"&&(i==="left"||i==="right")&&(n==="inside-top"||n==="inside-bottom")?`${n}-${i}`:n}const H$=new Map([["c","center"],["t","inside-top"],["b","inside-bottom"],["l","inside-left"],["r","inside-right"],["tl","inside-top-left"],["tr","inside-top-right"],["bl","inside-bottom-left"],["br","inside-bottom-right"]]),jz=[["top-left","top","top-right"],["left","center","right"],["bottom-left","bottom","bottom-right"]];function Fz(t,e){const n=ue(t.r,"Shape");if(n!==void 0)return le("shape",k(n,"type"),"yed",e("shape"));if(t.type==="ShapeNode"||t.type==="GroupNode"||t.type==="GenericGroupNode")return null;if(t.type==="TableNode")return le("shape","rectangle","yed",e("shape"));if(t.type==="GenericNode"){const i=k(t.r,"configuration")??"",r=Df(i);if(r!==null)return r.shape;const s=i.slice(0,Ce).toLowerCase();for(const[o,l]of Cz)if(s.includes(o))return l;return s.length===0?null:(H(e("shape"),v.UNKNOWN_VALUE,s),`other:${s}`)}return H(e("shape"),v.UNKNOWN_VALUE,t.type),`other:${t.type}`}const V$=45;function zz(t,e,n){const i=ue(t.r,"Fill");if(i===void 0)return;if(k(i,"hasColor")==="false"||k(i,"transparent")==="true"){H(n("fill"),v.NO_FILL,"transparent"),e("fillOpacity",0);return}Go(k(i,"color"),"fill","fillOpacity",e,n);const r=ve(k(i,"color2"),"yed",n("fillGradient"));r!==null&&(e("fillGradient",r.color),e("fillGradientAngle",V$))}function Zh(t,e,n){const r=wt(ue(t.r,"StyleProperties"),"Property").find(s=>k(s,"name")===e);return r===void 0?null:ve(k(r,"value"),"yed",n("stripeColors"))?.color??null}function Wz(t,e,n){const i=ue(t.r,"Table"),r=wt(ue(i,"Rows"),"Row"),s=wt(ue(i,"Columns"),"Column"),o=s.length>1&&r.length<=1,l=(o?s:r).map(_=>Number(k(_,o?"width":"height"))),a=ue(i,"Insets"),c=_=>Math.max(0,Number(k(a,_)??0)||0),[d,u]=o?[c("left"),c("right")]:[c("top"),c("bottom")],f=[d,...l,u],h=f.reduce((_,S)=>_+S,0);if(l.length===0||!f.every(Number.isFinite)||h<=0)return;const p=ve(k(ue(t.r,"Fill"),"color"),"yed",n("stripeColors"))?.color??"#ffffff",g=Zh(t,"yed.table.lane.color.main",n)??p,m=Zh(t,"yed.table.lane.color.alternating",n)??g,y=Zh(t,"yed.table.header.color.main",n)??p,b=[[d,y],...l.map((_,S)=>[_,S%2===0?g:m]),[u,p]].filter(([_])=>_>0);e("stripeColors",b.map(([,_])=>_).join(" ")),e("stripeSizes",b.map(([_])=>String(Number((_/h).toFixed(6)))).join(" ")),o&&e("stripeDirection","right")}function Bz(t){const e=new Map;for(const n of t.graph)n.dtype!=="json"||n.meta.origin?.namespace!=="yfiles"||Hz(K(t.graph.value(n.meta.name,0)),e);return e}function Hz(t,e){for(const n of wt(t,"Resources"))for(const i of wt(n,"Resource")){const r=k(i,"id"),s=r===void 0||e.has(r)?null:Vz(i);r!==void 0&&s!==null&&e.set(r,s)}}function Vz(t){const e=Ob(t)?.trim()??"";return e===""?null:(k(t,"type")??"").endsWith("BufferedImage")?`data:image/png;base64,${e.replaceAll(/\s+/g,"")}`:e.includes("<svg")?`data:image/svg+xml;utf8,${encodeURIComponent(e)}`:null}function Yz(t,e,n){const i=t.type==="ImageNode"?k(ue(t.r,"Image"),"refid"):k(ue(ue(t.r,"SVGModel"),"SVGContent"),"refid"),r=i===void 0?void 0:e.get(i);r!==void 0&&(n("image",r),n("imageFit","fill"),n("imageClip","none"))}function Y$(t,e,n,i){const{r}=t;zz(t,e,n);const s=ue(r,"BorderStyle");s!==void 0&&(k(s,"hasColor")==="false"?e("borderWidth",0):(Go(k(s,"color"),"borderColor",null,e,n),e("borderWidth",Y(k(s,"width"),n("borderWidth")))),e("borderStyle",le("borderStyle",k(s,"type"),"yed",n("borderStyle"))));const o=ue(r,"Geometry");e("width",Y(k(o,"width"),n("width"))),e("height",Y(k(o,"height"),n("height"))),e("shape",Fz(t,n));const l=t.type==="GenericNode"?Df(k(r,"configuration")??"")?.points:void 0;l!==void 0&&e("shapePoints",l),t.type==="TableNode"&&Wz(t,e,n),i!==void 0&&(t.type==="ImageNode"||t.type==="SVGNode")&&Yz(t,i,e),B$(wt(r,"NodeLabel"),!0,e,n,o)}function K$(t,e,n){const{r:i}=t,r=ue(i,"LineStyle");r!==void 0&&(Go(k(r,"color"),"color","opacity",e,n),e("width",Y(k(r,"width"),n("width"))),e("lineStyle",le("lineStyle",k(r,"type"),"yed",n("lineStyle"))));const s=ue(i,"Arrows");s!==void 0&&(e("sourceArrow",le("arrow",k(s,"source"),"yed",n("sourceArrow"))),e("targetArrow",le("arrow",k(s,"target"),"yed",n("targetArrow")))),e("curved",Kz(t)),t.type==="ArcEdge"&&e("bendCurve","arc"),B$(wt(i,"EdgeLabel"),!1,e,n)}function Kz(t){if(t.type==="ArcEdge")return!0;const e=wt(ue(t.r,"Path"),"Point").length;if(t.type==="QuadCurveEdge")return!1;if(t.type==="BezierEdge")return e>0&&(e+1)%3!==0;const n=e>0;if(t.type!=="PolyLineEdge"&&t.type!=="GenericEdge")return n;const i=k(ue(t.r,"BendStyle"),"smoothed");return i===void 0?null:i==="true"&&n}function Xz(t,e,n,i,r){const s=ue(t.r,"Path"),o=f=>[e[4*f],e[4*f+1]],l=f=>[e[4*f+2],e[4*f+3]],a=f=>Number(k(s,f)??0)||0,c=[[o(n)[0]+a("sx"),o(n)[1]+a("sy")],[o(i)[0]+a("tx"),o(i)[1]+a("ty")]],d=(f,h)=>h[0]===o(f)[0]&&h[1]===o(f)[1]?null:Hs(o(f),l(f),[h],!0);r("sourcePort",d(n,c[0])),r("targetPort",d(i,c[1]));let u=wt(s,"Point").map(f=>[Number(k(f,"x")),Number(k(f,"y"))]);if(u.length>0&&(t.type==="BezierEdge"||t.type==="QuadCurveEdge")){const f=[c[0],...u,c[1]];u=((t.type==="BezierEdge"?Sf(f):K1(f,Number(k(t.r,"straightness")??qz)))??f).slice(1,-1)}r("bends",n===i?Hs(o(n),l(n),u,!0):Al(o(n),o(i),u,!0))}const qz=.1;function Qr(t){const e=Object.create(null);return{values:e,put(n,i,r){r!==null&&(e[i]??=new Array(t).fill(null),e[i][n]=r)}}}function Jz(t,e,n){let i=!1;const r=Bz(t),s=new Float64Array(4*t.nodeCount).fill(Number.NaN),o=c=>{const d=c==="node"?t.nodes:t.edges,u=c==="node"?t.nodeCount:t.edgeCount,f=c==="node"?Nb:Ab,h=Lg(d),p=Qr(u);if(h.length===0)return p.values;for(let g=0;g<u;g++){n.spend(c,h.length);let m=null;for(let _=0;_<h.length&&m===null;_++)m=vf(K(d.value(h[_],g)),f);if(m===null)continue;i=!0;const y=_=>({notes:e,target:c,property:_,element:g,budget:n}),b=(_,S)=>{p.put(g,_,S)};if(c==="node"){Y$(m,b,y,r);const _=ue(m.r,"Geometry"),[S,T]=[Number(k(_,"width")),Number(k(_,"height"))];s.set([Number(k(_,"x"))+S/2,Number(k(_,"y"))+T/2,S,T],4*g)}else K$(m,b,y),Xz(m,s,t.edgeSource(g),t.edgeTarget(g),b)}return p.values},l=o("node"),a=o("edge");return i?{node:l,edge:a}:null}const Aa=Object.freeze({tool:"yed",node:Object.freeze(["fill","fillOpacity","fillGradient","fillGradientAngle","borderColor","borderWidth","borderStyle","shape","width","height","label","labelColor","labelSize","labelFont","labelWeight","labelItalic","labelPosition"]),edge:Object.freeze(["color","opacity","width","lineStyle","sourceArrow","targetArrow","curved","bends","sourcePort","targetPort","label","labelColor","labelSize","labelFont","labelWeight","labelItalic"]),block:"attributes"}),X$=new Map([["ellipse","ellipse"],["rectangle","rectangle"],["round-rectangle","roundrectangle"],["triangle","triangle"],["diamond","diamond"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","parallelogram"],["trapezoid","trapezoid"],["star","star5"]]),Ib=new Map([["solid","line"],["dashed","dashed"],["dotted","dotted"],["dash-dot","dashed_dotted"]]),q$=new Map([["none","none"],["triangle","delta"],["triangle-open","white_delta"],["vee","standard"],["tee","t_shape"],["diamond","diamond"],["diamond-open","white_diamond"],["circle","circle"],["circle-open","white_circle"],["square","skewed_dash"],["crow","crows_foot_many"]]),Zz=new Map([...H$].map(([t,e])=>[e,t])),Qz=new Map([["top","n"],["bottom","s"],["left","w"],["right","e"],["top-left","nw"],["top-right","ne"],["bottom-left","sw"],["bottom-right","se"]]);function xg(t,e,n){const i=t.get(e);return i!==void 0?{value:i,exact:!0}:e.startsWith("other:")?{value:e.slice(6),exact:!0}:{value:n,exact:!1}}function kf(t,e){const n=t.toUpperCase();return typeof e!="number"||e>=1?n:n+Math.round(Math.max(0,e)*255).toString(16).toUpperCase().padStart(2,"0")}function Ta(t,e,n,i,r){const s=xg(t,e,n);return s.exact||r(i,e),s.value}const N_={[Ts]:"Dialog",[qy]:"Serif",[Xl]:"Monospaced"};function J$(t){return Object.hasOwn(N_,t)?N_[t]:t.split(",")[0].trim()}function e7(t){const e={},n=t("labelFont");typeof n=="string"&&(e["@_fontFamily"]=J$(n));const i=t("labelSize");typeof i=="number"&&(e["@_fontSize"]=String(i));const r=t("labelWeight"),s=t("labelItalic");if(r!==null||s!==null){const o=(r==="bold"?"bold":"")+(s===!0?"italic":"");e["@_fontStyle"]=o.length===0?"plain":o}return e}function Z$(t,e,n){const i=t("label");if(typeof i!="string"||i.trim().length===0)return null;const r=e7(t),s=t("labelColor");typeof s=="string"&&(r["@_textColor"]=s.toUpperCase());const o=e?t("labelPosition"):null;if(typeof o=="string"){const l=Zz.get(o),a=Qz.get(o);l===void 0&&a===void 0&&n("labelPosition",o),r["@_modelName"]=a===void 0?"internal":"eight_pos",r["@_modelPosition"]=a??l??"c"}return r["#text"]=i,r}function Q$(t,e,n){const i={};i["y:Geometry"]=t7(t,e);const r=t("fill"),s=t("fillOpacity");if(typeof r=="string"){i["y:Fill"]={"@_color":kf(r,s),"@_transparent":"false"};const c=t("fillGradient");if(typeof c=="string"){i["y:Fill"]["@_color2"]=c.toUpperCase();const d=t("fillGradientAngle");d!==V$&&n("fillGradientAngle",d??0)}}else s===0&&(i["y:Fill"]={"@_hasColor":"false","@_transparent":"false"});const o=eC(t,["borderColor","borderWidth","borderStyle"],n);o!==null&&(i["y:BorderStyle"]=o);const l=Z$(t,!0,n);l!==null&&(i["y:NodeLabel"]=l);const a=t("shape");return typeof a=="string"&&(i["y:Shape"]={"@_type":Ta(X$,a,a==="vee"?"triangle":"rectangle","shape",n)}),{"y:ShapeNode":i}}function t7(t,e){const n={},i=t("height"),r=t("width");return typeof i=="number"&&(n["@_height"]=String(i)),typeof r=="number"&&(n["@_width"]=String(r)),e!==null&&(n["@_x"]=e[0],n["@_y"]=e[1]),n}function eC(t,e,n,i){const[r,s,o]=e,l=t(r),a=t(s),c=t(o);if(l===null&&a===null&&c===null)return null;const d={};if(typeof l=="string"&&(d["@_color"]=i===void 0?l.toUpperCase():kf(l,i)),typeof c=="string"){const u=o==="lineStyle"&&c==="long-dash"?"dashed":"line";d["@_type"]=Ta(Ib,c,u,o,n)}return typeof a=="number"&&(d["@_width"]=String(a)),d}function tC(t,e,n){const i={};e!==void 0&&(i["y:Path"]=e);const r=eC(t,["color","width","lineStyle"],n,t("opacity"));r!==null&&(i["y:LineStyle"]=r);const s=t("sourceArrow"),o=t("targetArrow");if(s!==null||o!==null){const c=(d,u)=>typeof u=="string"?Ta(q$,u,"delta",d,n):"none";i["y:Arrows"]={"@_source":c("sourceArrow",s),"@_target":c("targetArrow",o)}}const l=Z$(t,!1,n);l!==null&&(i["y:EdgeLabel"]=l);const a=t("curved");return typeof a=="boolean"&&(i["y:BendStyle"]={"@_smoothed":String(a)}),{"y:PolyLineEdge":i}}function n7(t,e,n){const i=new se;so(t,e,"graphml",r=>({values:n[r],properties:Aa[r],writes:Aa[r],readBack:(s,o)=>{const l=i7(r,o,i);return l===null?null:a=>l.get(a)??null}}))}function i7(t,e,n){const i=()=>{},r=t==="node"?Q$(e,null,i):tC(e,void 0,i),s=vf(r,t==="node"?Nb:Ab);if(s===null)return null;const o=new Map,l=c=>({notes:n,target:t,property:c}),a=(c,d)=>{d!==null&&o.set(c,d)};return t==="node"?Y$(s,a,l):K$(s,a,l),o}const A_={node:"nodegraphics",edge:"edgegraphics"};function r7(t,e,n){for(const i of e){const r=K(t.value(i,n)),s=vf(r,Nb),o=s===null?ue(r,"RectD"):ue(s.r,"Geometry"),l=k(o,s===null?"X":"x"),a=k(o,s===null?"Y":"y");if(l!==void 0&&a!==void 0)return[l,a]}return null}function s7(t,e,n){const i=t.nodes.byRole("position");if(i===null||i.meta.components<2||!i.isSet(e))return null;const r=i.value(e),s=n("width"),o=n("height"),l=[typeof s=="number"?s:0,typeof o=="number"?o:0],a=[r[0],r[1],0];ty(a,i.meta.extra??{},l,!1);const[c,d]=xL(Float64Array.from(a),o7,{width:Float64Array.of(l[0]),height:Float64Array.of(l[1])});return Number.isFinite(c)&&Number.isFinite(d)?[String(c),String(d)]:null}const o7={yAxis:"down",anchor:"top-left"};function l7(t,e,n){for(const i of e){const r=vf(K(t.value(i,n)),Ab),s=r===null?void 0:ue(r.r,"Path");if(s!==void 0)return s}}function a7(t,e,n,i){const r=e("bends"),[[s,o],[l]]=n;let a=null;typeof r=="string"&&(a=i?pu(s,o,r):Y1(s,l,r));const c=["sourcePort","targetPort"].map((f,h)=>{const p=e(f),[g,m]=n[h],y=typeof p=="string"?pu(g,m,p):null;return y===null?null:[y[0][0]-g[0],y[0][1]-g[1]]});if(a===null&&c.every(f=>f===null))return t;const d={};["sx","sy","tx","ty"].forEach((f,h)=>{const p=c[h>>1];d[`@_${f}`]=p===null?k(t,f)??"0.0":String(p[h&1])});const u=a??wt(t,"Point").map(f=>[Number(k(f,"x")),Number(k(f,"y"))]);return d["y:Point"]=u.map(([f,h])=>({"@_x":String(f),"@_y":String(h)})),d}function c7(t,e){let n=e,i=2;for(;t.has(n);)n=`${e}#${String(i)}`,i++;return n}function d7(t,e){if(e===void 0)return null;const n=new Il,i=p=>(g,m)=>{n.add(p,g,m)},r=(p,g)=>e.picture(p,g),s=Lg(t.nodes),o=Lg(t.edges),l=Vs(r,"node",Aa.node),a=Vs(r,"edge",Aa.edge),c=[];for(let p=0;p<t.nodeCount;p++){const g=l(p),m=r7(t.nodes,s,p)??s7(t,p,g);c.push(Q$(g,m,i("node")))}const d=c.map(p=>{const g=ue(ue(p,"ShapeNode"),"Geometry"),m=y=>Number(k(g,y)??Number.NaN);return[[m("x")+m("width")/2,m("y")+m("height")/2],[m("width"),m("height")]]}),u=[];for(let p=0;p<t.edgeCount;p++){const g=a(p),[m,y]=[t.edgeSource(p),t.edgeTarget(p)],b=a7(l7(t.edges,o,p),g,[d[m],d[y]],m===y);u.push(tC(g,b,i("edge")))}const f=t.withColumns();for(const[p,g,m]of[[f.nodes,c,"node"],[f.edges,u,"edge"]]){for(const b of Pg(p))p.remove(b);const y=c7(p,A_[m]);p.set(y,g,{dtype:"json",nullable:!0,origin:{format:"graphml",id:null,title:null,type:A_[m],namespace:"yfiles"}})}const h=[...f.graph].filter(p=>p.meta.origin?.namespace==="yfiles"&&(p.meta.origin.type??"").includes("://"));for(const p of h)f.graph.remove(p.meta.name);return{snapshot:f,notes:n.notes("yEd")}}const nC=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui"]),u7=new Map([["avantgarde",["URW Gothic","sans-serif"]],["bookman",["URW Bookman","serif"]],["courier",["Courier","monospace"]],["helvetica",["Helvetica","sans-serif"]],["helvetica-narrow",["Helvetica","sans-serif"]],["newcenturyschlbk",["Century Schoolbook","serif"]],["palatino",["Palatino","serif"]],["symbol",["Symbol","fantasy"]],["times",["Times","serif"]],["zapfchancery",["URW Chancery","serif"]],["zapfdingbats",["Dingbats","fantasy"]]]),f7=new Map([["",[!1,!1]],["roman",[!1,!1]],["book",[!1,!1]],["light",[!1,!1]],["bold",[!0,!1]],["demi",[!0,!1]],["italic",[!1,!0]],["oblique",[!1,!0]],["bookoblique",[!1,!0]],["lightitalic",[!1,!0]],["mediumitalic",[!1,!0]],["bolditalic",[!0,!0]],["boldoblique",[!0,!0]],["demiitalic",[!0,!0]],["demioblique",[!0,!0]]]);function Rf(t){const e=t.trim();if(e.includes(":"))return{family:"Times, serif",bold:!1,italic:!1};const n=iC(e);if(n!==null)return n;const i=e.split(",").at(-1)?.trim().toLowerCase()??"";return{family:nC.has(i)?e:`${e}, sans-serif`,bold:!1,italic:!1}}function iC(t){const e=t.toLowerCase();for(const[n,[i,r]]of u7)if(e===n||e.startsWith(`${n}-`)){const s=f7.get(e.slice(n.length+1));if(s!==void 0)return{family:`${i}, ${r}`,bold:s[0],italic:s[1]}}return null}const h7=[{family:"URW Gothic",name:"AvantGarde",plain:"Book",bold:"Demi",slant:"Oblique"},{family:"URW Bookman",name:"Bookman",plain:"Light",bold:"Demi",slant:"Italic"},{family:"Courier",name:"Courier",plain:"",bold:"Bold",slant:"Oblique"},{family:"Helvetica",name:"Helvetica",plain:"",bold:"Bold",slant:"Oblique"},{family:"Century Schoolbook",name:"NewCenturySchlbk",plain:"Roman",bold:"Bold",slant:"Italic"},{family:"Palatino",name:"Palatino",plain:"Roman",bold:"Bold",slant:"Italic"},{family:"Times",name:"Times",plain:"Roman",bold:"Bold",slant:"Italic"}];function $b(t,e,n){const i=t.split(",").map(l=>l.trim());if(i.length!==2||!nC.has(i[1].toLowerCase()))return t;const r=h7.find(l=>l.family.toLowerCase()===i[0].toLowerCase());if(r===void 0)return i[0];const s=n?r.slant:"",o=e?`${r.bold}${s}`:s||r.plain;return o===""?r.name:`${r.name}-${o}`}function p7(t){const{sides:e,distortion:n,skew:i,orientation:r}=t,s=2*Math.PI/e,o=Math.sin(s/2),l=Math.hypot(Math.abs(n)+Math.abs(i),1),a=n*Math.SQRT2/Math.cos(s/2),c=i/2;let d=(s-Math.PI)/2,u=.5*Math.cos(d),f=.5*Math.sin(d);d+=(Math.PI-s)/2;const h=[];for(let p=0;p<e;p++){d+=s,u+=o*Math.cos(d),f+=o*Math.sin(d);const g=u*(l+f*a)+f*c,m=r*Math.PI/180+Math.atan2(f,g),y=Math.hypot(g,f);h.push([2*y*Math.cos(m),2*y*Math.sin(m)])}return h}function rC(t){return t.sides===4&&Math.abs(t.orientation%90)<.5&&t.distortion===0&&t.skew===0}const sC=new Map([["triangle",3,0,0,0],["invtriangle",3,0,0,180],["trapezium",4,-.4,0,0],["invtrapezium",4,-.4,0,180],["parallelogram",4,0,.6,0],["house",5,-.64,0,0],["invhouse",5,-.64,0,180],["pentagon",5,0,0,0],["septagon",7,0,0,0],["egg",120,-.3,0,0]].map(([t,e,n,i,r])=>[t,{sides:e,distortion:n,skew:i,orientation:r}])),Pr=t=>[[-t,0],[t,0]],T_=[[3,6],[3,7.5],[1.5,9],[3,10.5],[3,12],[1.5,12],[0,10.5],[-1.5,12],[-3,12],[-3,10.5],[-1.5,9],[-3,7.5],[-3,6],[-1.5,6],[0,7.5],[1.5,6]],I_=[[1.5,6],[3,7.5],[3,10.5],[1.5,12],[-1.5,12],[-3,10.5],[-3,7.5],[-1.5,6]],$_=[[[0,0],[0,1.5]],[[0,3],[0,4.5]]],$i=(t,e,n)=>[[t,n],[e,n],[e,n+6],[t,n+6]],oC=new Map([["box3d",(t,e)=>({outline:[[t,e],[-t+4,e],[-t,e-4],[-t,-e],[t-4,-e],[t,-e+4]],parts:[],lines:[[[t-4,e-4],[-t,e-4]],[[t-4,e-4],[t-4,-e]],[[t-4,e-4],[t,e]]]})],["tab",(t,e)=>({outline:[[t,e],[-t+12,e],[-t+12,e+4],[-t,e+4],[-t,-e],[t,-e]],parts:[],lines:[[[-t,e],[-t+12,e]]]})],["folder",(t,e)=>({outline:[[t,e],[t-3,e+4],[t-24,e+4],[t-27,e],[-t,e],[-t,-e],[t,-e]],parts:[],lines:[]})],["component",(t,e)=>({outline:[[t,e],[-t,e],[-t,e-4],[-t-4,e-4],[-t-4,e-8],[-t,e-8],[-t,-e+8],[-t-4,-e+8],[-t-4,-e+4],[-t,-e+4],[-t,-e],[t,-e]],parts:[],lines:[[[-t,e-4],[-t+4,e-4],[-t+4,e-8],[-t,e-8]],[[-t,-e+8],[-t+4,-e+8],[-t+4,-e+4],[-t,-e+4]]]})],["note",(t,e)=>({outline:[[t-6,e],[-t,e],[-t,-e],[t,-e],[t,e-6]],parts:[],lines:[[[t-6,e],[t-6,e-6]],[[t,e-6],[t-6,e-6]]]})],["underline",(t,e)=>({outline:[[t,e],[-t,e],[-t,-e],[t,-e]],parts:[],lines:[[[-t,-e],[t,-e]]],unstroked:!0})],["cds",(t,e)=>({outline:[[t-12,e-6],[-t,e-6],[-t,-e+6],[t-12,-e+6],[t,0]],parts:[],lines:[]})],["larrow",(t,e)=>({outline:[[t,e-6],[-t+18,e-6],[-t+18,e],[-t,0],[-t+18,-e],[-t+18,-e+6],[t,-e+6]],parts:[],lines:[]})],["rarrow",(t,e)=>({outline:[[t-18,e-6],[-t,e-6],[-t,-e+6],[t-18,-e+6],[t-18,-e],[t,0],[t-18,e]],parts:[],lines:[]})],["lpromoter",(t,e)=>({outline:[[t,e-6],[-t+18,e-6],[-t+18,e],[-t,0],[-t+18,-e],[-t+18,-e+6],[t-18,-e+6],[t-18,-e],[t,-e]],parts:[],lines:[]})],["rpromoter",(t,e)=>({outline:[[t-18,e-6],[-t,e-6],[-t,-e],[-t+18,-e],[-t+18,-e+6],[t-18,-e+6],[t-18,-e],[t,0],[t-18,e]],parts:[],lines:[]})],["promoter",t=>({outline:[[t/4,18],[-t/2,18],[-t/2,0],[-t/2+6,0],[-t/2+6,12],[t/4,12],[t/4,9],[t/4+12,15],[t/4,21]],parts:[],lines:[Pr(t)]})],["terminator",t=>({outline:[[3,0],[3,6],[9,6],[9,12],[-9,12],[-9,6],[-3,6],[-3,0]],parts:[],lines:[Pr(t)]})],["utr",t=>({outline:[[9,0],[9,3],[3,9],[-3,9],[-9,3],[-9,0]],parts:[],lines:[Pr(t)]})],["primersite",t=>({outline:[[12,3],[0,15],[0,9],[-t/2,9],[-t/2,3]],parts:[],lines:[Pr(t)]})],["restrictionsite",t=>{const[e,n]=[t/4,t/4+6];return{outline:[[n,3],[-e,3],[-e,9],[-n,9],[-n,-3],[e,-3],[e,-9],[n,-9]],parts:[],lines:[[[-t,0],[-n,0]],[[n,0],[t,0]]]}}],["fivepoverhang",t=>({outline:$i(-t,-t+24,1.5),parts:[$i(-t+12,-t+24,-7.5)],lines:[[[-t+24,0],[t,0]]]})],["threepoverhang",t=>({outline:$i(t-24,t,1.5),parts:[$i(t-24,t-12,-7.5)],lines:[[[-t,0],[t-24,0]]]})],["noverhang",t=>({outline:$i(-13.5,-1.5,1.5),parts:[$i(-13.5,-1.5,-7.5),$i(1.5,13.5,-7.5),$i(1.5,13.5,1.5)],lines:[[[13.5,0],[t,0]],[[-13.5,0],[-t,0]]]})],["assembly",t=>({outline:$i(-12,12,1.5),parts:[$i(-12,12,-7.5)],lines:[[[12,0],[t,0]],[[-t,0],[-12,0]]]})],["signature",(t,e)=>({outline:[[t,e-6],[-t,e-6],[-t,-e+6],[t,-e+6]],parts:[],lines:[[[-t+3,1.5],[-t+6,-1.5]],[[-t+3,-1.5],[-t+6,1.5]],[[-t+3,-e+9],[t-3,-e+9]]]})],["insulator",t=>({outline:[[6,6],[6,-6],[-6,-6],[-6,6]],parts:[],ring:3,lines:[[[9,0],[t,0]],[[-t,0],[-9,0]]]})],["ribosite",t=>({outline:T_,parts:[],lines:[...$_,Pr(t)]})],["rnastab",t=>({outline:I_,parts:[],lines:[...$_,Pr(t)]})],["proteasesite",t=>({outline:T_,parts:[],lines:[[[0,7.5],[0,0]],Pr(t)]})],["proteinstab",t=>({outline:I_,parts:[],lines:[[[0,6],[0,0]],Pr(t)]})]]),Cb=new Set(oC.keys()),g7=new Set(["box3d","tab","folder","component","note","underline","cds","larrow","rarrow","lpromoter","rpromoter"]),C_=[54,36];function lC(t,e,n){const i=oC.get(t),r=e!==null&&e>0?e:C_[0],s=n!==null&&n>0?n:C_[1];return i===void 0?null:i(r/2,s/2)}async function vb(t,e,n,i){const r=t.importAll?.bind(t);if(r===void 0)return t.import(e,n,i);const s=await m7(e),o=[];await r(s,d=>o[d]=new Up({directed:!1}),{...i,onProgress:void 0});const l=o.map(d=>{try{return d.freeze().meta.name}catch{return null}}),a=ml(l,i,new ne(t.format,0));return(await r(s,d=>d===a?n:new Up({directed:!1}),i))[a]}async function m7(t){if(typeof t=="string"||t instanceof Uint8Array)return t;const e=[],n=new TextEncoder;if(typeof t.getReader=="function"){const s=t.getReader();for(let o=await s.read();!o.done;o=await s.read())e.push(o.value)}else for await(const s of t)e.push(typeof s=="string"?n.encode(s):s);const i=new Uint8Array(e.reduce((s,o)=>s+o.byteLength,0));let r=0;for(const s of e)i.set(s,r),r+=s.byteLength;return i}const $s="dot",ai=Object.freeze({format:$s}),Cs="graphty.cluster",aC="graphty.parent",cC="graphty.sourcePort",dC="graphty.targetPort",Ue="label",Xs="pos",y7="graphty.position",vs="key",b7="pin",E7="dot",Db="graphty.rank",kb="graphty.rankSet",w7=new Set(["color","size","shape","thickness","hidden"]),Lf=["node","edge"];function _7(t,e,n,i){const r=ro(t),s=n.fingerprint;if(r.nodes!==s.nodes||r.edges!==s.edges||r.ids!==s.ids)return{snapshot:t,input:null,notes:[],refusal:Object.freeze({code:v.MISMATCH,message:`the styles were read from or built for a different graph (${String(s.nodes)} nodes and ${String(s.edges)} edges, this graph has ${String(r.nodes)} and ${String(r.edges)}, or other node ids); nothing is written`,column:null,count:null})};const o=e.styles?.capabilities??null;let l=v_(t,e,n);if(Rb(e)){let a;try{a=e.check(l.snapshot,l.input===null?i:{...i,styles:l.input})}catch{a=[]}const c=N7(n,t,a);c!==n&&(l=v_(t,e,c))}return{snapshot:l.snapshot,input:l.input,notes:$7(l.extracted,e,o,l.picture,t),refusal:null}}const Td=new WeakMap;function S7(t,e,n){if(!Td.has(t))return n();const i=Td.get(t);if(i?.key.length===e.length&&i.key.every((s,o)=>s===e[o]))return i.value;const r=n();return Td.set(t,{key:e,value:r}),r}function v_(t,e,n){const i=e.styles?.capabilities??null,r=new Map,s=(c,d)=>{const u=`${c}\0${d}`;let f=r.get(u);return f===void 0&&(f=I1(n,c,d,t),r.set(u,f)),f},o={node:new Map,edge:new Map};for(const c of Lf)for(const[d,u]of n.columns[c])o[c].set(wf(c,d),u);const l=Nl(n,{snapshot:t}),a=e.styles===void 0?null:{picture:s,block:l,tags:o,rules:n};return a!==null&&Td.set(a,null),{snapshot:R7(t,i,o,l,n.styles.rules),input:a,extracted:n,picture:s}}const O7=/NODE_TABLE|NAME_CHANGED|ROLE_ASSUMED|STORAGE_CLASS|NUMBER_TYPE|INTEGRAL|WIDENED/;function N7(t,e,n){const i=new Set;let r=!1;for(const a of n){if(!O7.test(a.code))for(const c of a.columns??(a.column===null?[]:[a.column]))i.add(c);r||=/DIRECTION/.test(a.code)}const s=new A7(e,i,r,t.columns),o=t.styles.rules.map(a=>s.carry(a));return o.some((a,c)=>a!==t.styles.rules[c])?{...t,styles:{...t.styles,rules:o},columns:s.columns}:t}class A7{constructor(e,n,i,r){this.snapshot=e,this.lost=n,this.direction=i,this.touched=!1,this.columns={node:new Map(r.node),edge:new Map(r.edge)}}carry(e){this.touched=!1;const{ext:n,...i}=e,r=this.carryMap(e),s=this.walk(e,i.where);if(!this.touched)return e;const{map:o,...l}=i,a=Object.keys(r).length===0?{...l,where:s}:{...l,where:s,map:r},c=JSON.parse(JSON.stringify(a));return n===void 0?c:{...c,ext:n}}carryMap(e){const n=Object.create(null),{table:i}=this.tableOf(e.target);for(const[r,s]of Object.entries(e.map??{})){if(s===void 0)continue;if(s.kind!=="passthrough"){n[r]=this.walk(e,s);continue}const o=s.by.data,a=typeof o=="string"&&this.lost.has(o)&&i.has(o)?this.cells(e.target,o,_l(e.target,r)):null;a!==null&&!a.some(c=>c!==null)?this.touched=!0:a!==null&&this.isLost(e.target,o)?(this.touched=!0,n[r]={...s,by:this.copy(e.target,`${r}.data.${o}`,()=>a)}):n[r]=s}return n}walk(e,n){return JSON.parse(JSON.stringify(n,(i,r)=>this.replaced(e,r)))}replaced(e,n){if(typeof n!="object"||n===null||Array.isArray(n)||Object.keys(n).length!==1)return n;const i=n;if(this.isLost(e.target,i.data)){const s=i.data;return this.touched=!0,this.copy(e.target,`data.${s}`,()=>this.cells(e.target,s,o=>uC(o)?o:null))}const r=i.computed;return(r==="indegree"||r==="outdegree")&&this.direction&&e.target==="node"?(this.touched=!0,this.copy(e.target,`computed.${r}`,()=>sc(this.snapshot,r))):n}copy(e,n,i){const r=`input.${n}`,s=this.columns[e];return s.has(r)||s.set(r,i()),{style:r}}isLost(e,n){const{table:i,n:r}=this.tableOf(e);return typeof n=="string"&&this.lost.has(n)&&i.has(n)&&T7(i,r,n)}cells(e,n,i){const{table:r,n:s}=this.tableOf(e);return Array.from({length:s},(o,l)=>i(yf(r,n,l)))}tableOf(e){const{snapshot:n}=this;return e==="node"?{table:n.nodes,n:n.nodeCount}:{table:n.edges,n:n.edgeCount}}}function T7(t,e,n){let i=!1;for(let r=0;r<e;r++){const s=K(t.value(n,r));if(s!=null){if(!uC(s))return!1;i=!0}}return i}function uC(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function Rb(t){const e=t.styles?.capabilities;return e!==void 0&&(e.block==="native"||e.block==="attributes"&&t.capabilities.graphAttributes)}function I7(t,e){return t.style?.property.startsWith("graphty:")===!0&&Rb(e)}function $7(t,e,n,i,r){const s=[],o=Rb(e);for(const l of Lf){const a=new Set(n?.[l]??[]);for(const c of v7(t.styles.rules,l))if(a.has(c)||o&&c.startsWith("graphty:"))l==="edge"&&s.push(...k7(r,e,c,i("edge",c)));else{const d=D7(l,c,e,i);d.count!==0&&s.push(d)}}return s.push(...C7(t,e,n)),o?s.push(...lc(Nl(t,{snapshot:r}),t.styles.rules.length)):t.styles.rules.length>0&&s.push(Object.freeze({code:v.RULES_NOT_KEPT,message:`the style rules are not kept: the ${e.format} format has no place for them; importing the file infers them again from what it holds`,column:null,count:t.styles.rules.length})),s}function C7(t,e,n){const i=new Set(n?.graph??[]),r=(n?.tool===void 0?null:vr(n.tool))?.graph??{};return Object.entries(t.styles.graph).filter(([s,o])=>!i.has(s)&&r[s]?.value!==o).map(([s])=>s).map(s=>Object.freeze({code:v.NOT_WRITTEN,message:`the graph's ${s} is not written: the ${e.format} format has no place for it`,column:null,count:1,style:Object.freeze({target:"graph",property:s})}))}function v7(t,e){return new Set(t.filter(n=>n.target===e).flatMap(n=>[...Object.keys(n.set??{}),...Object.keys(n.map??{})]))}function D7(t,e,n,i){const r=i(t,e).filter(s=>s!==null).length;return Object.freeze({code:v.NOT_WRITTEN,message:`${t} ${e} is not written: the ${n.format} format has no place for it (${String(r)} ${t}${O(r)} ${C(r,"has","have")} a value)`,column:null,count:r,style:Object.freeze({target:t,property:e})})}function k7(t,e,n,i){const r=t.edges.byRole("pair");let s=0;for(let o=0;r!==null&&o<i.length;o++){const l=r.isSet(o)?r.value(o):o;l<o&&i[o]!==i[l]&&s++}return s===0?[]:[Object.freeze({code:v.APPROXIMATED,message:`edge ${n}: ${String(s)} undirected edge${O(s)} in a directed graph ${C(s,"has","have")} another value on each half; the ${e.format} format writes the edge once, with the first half's value`,column:null,count:s,style:Object.freeze({target:"edge",property:n})})]}function R7(t,e,n,i,r){const s=e?.block==="attributes",o={node:D_(t.nodes,r,"node"),edge:D_(t.edges,r,"edge")},l={node:k_(t.nodes,e,"node"),edge:k_(t.edges,e,"edge")},a=t.graph.has(Z),c=[o.node,o.edge,l.node,l.edge].some(u=>u.length>0);if(!s&&!a&&!c)return t;const d=t.withColumns();a&&d.graph.remove(Z);for(const u of Lf){const f=u==="node"?d.nodes:d.edges;for(const h of o[u])f.remove(h);for(const h of l[u]){const p=f.get(h);p!==null&&f.set(h,p,{role:void 0})}}return s&&(L7(d,n),d.graph.set(Z,[i],{dtype:"string"})),d}function D_(t,e,n){const i=fC(e,n);return t.names().filter(r=>P7(r)&&!i.has(r))}function k_(t,e,n){const i=(e?.[n]??[]).includes("label");return t.names().filter(r=>{const s=t.get(r)?.meta.role??"";return w7.has(s)||s==="label"&&i})}function L7(t,e){for(const n of Lf){const i=n==="node"?t.nodes:t.edges,r=wf(n,"");for(const s of i.names().filter(o=>o.startsWith(r)))i.remove(s);for(const[s,o]of e[n]){const l=x7(o);i.set(s,l==="string"?o.map(a=>a===null?null:String(a)):o,{dtype:l})}}}function P7(t){return t.startsWith("graphty.style.")||t.startsWith("graphty_style_")}function fC(t,e){const n=new Set;for(const{ext:i,...r}of t.filter(s=>s.target===e))JSON.stringify(r,(s,o)=>{const l=typeof o=="object"&&o!==null&&!Array.isArray(o)?o.data:null;return typeof l=="string"&&Object.keys(o).length===1&&n.add(l),o});return n}function x7(t){let e=null;for(const n of t)if(n!==null){if(e===null)e=typeof n;else if(e!==typeof n)return"string"}return e==="number"?"f64":e==="boolean"?"bool":"string"}const M7=10,R_=-25,L_={w:.75,h:.5};function U7(t,e,n,i,r){const s=t.edgeSource(n),o=t.edgeTarget(n),[l,a]=[e.center(s),e.center(o)],c=l===null||a===null?null:j7(l,a,i("pos")),d=(c?.start??null)===null?null:Su(i("lp"));if(d===null&&e.external&&s!==o&&(i("label")??i("xlabel"))!==null&&(r("labelPosition","center"),r("labelShiftX",-.5),r("labelShiftY",-.5)),!(c===null||l===null||a===null||s===o)){if(d!==null&&i("label")!==null){const u=F7(c.points);r("labelOffsetX",P(d[0]-u[0])),r("labelOffsetY",P(u[1]-d[1]))}P_(e,c,{node:o,at:a,other:l},"head",i,r),P_(e,c,{node:s,at:l,other:a},"tail",i,r)}}function P_(t,e,n,i,r,s){if(r(`${i}label`)===null)return;const o=i==="head",l=(o?e.end:e.start)??z7(t,n.node,n.at,n.other),c=(o?e.points.slice(0,-1).reverse():e.points.slice(1)).find(f=>Math.hypot(f[0]-l[0],f[1]-l[1])>1e-6)??n.other,u=(e.start===null?null:Su(r(`${i}_lp`)))??G7(r,l,c);if(u!==null){const f=o?"target":"source";s(`${f}LabelOffset`,0),s(`${f}LabelOffsetX`,P(u[0]-l[0])),s(`${f}LabelOffsetY`,P(l[1]-u[1]))}}function G7(t,e,n){const i=x_(t("labelangle"),R_,-180),r=x_(t("labeldistance"),1,0);if(i===R_&&r===1)return null;const s=Math.atan2(n[1]-e[1],n[0]-e[0])+i*Math.PI/180,o=M7*r;return[e[0]+o*Math.cos(s),e[1]+o*Math.sin(s)]}function x_(t,e,n){const i=t===null||t.trim()===""?Number.NaN:Number(t);return Number.isFinite(i)?Math.max(n,i):e}function Su(t){const e=(t??"").replace(/!$/,"").split(",").map(Number);return e.length>=2&&Number.isFinite(e[0])&&Number.isFinite(e[1])?[e[0],e[1]]:null}function j7(t,e,n){const i=(n??"").split(";")[0].trim().split(/\s+/).filter(Boolean),r=l=>{const a=i.find(c=>c.startsWith(`${l},`));return a===void 0?null:Su(a.slice(2))},s=i.filter(l=>!/^[es],/.test(l)).map(l=>Su(l)),o=s.every(l=>l!==null)&&s.length>=4?Sf(s):null;return o===null?{points:[t,e],start:null,end:null}:{points:[t,...o,e],start:r("s")??o[0],end:r("e")??o.at(-1)??null}}function F7(t){const e=t.slice(1).map((i,r)=>Math.hypot(i[0]-t[r][0],i[1]-t[r][1]));let n=e.reduce((i,r)=>i+r,0)/2;for(let i=0;i<e.length;i++){if(n<=e[i]&&e[i]>0){const r=n/e[i];return[t[i][0]+r*(t[i+1][0]-t[i][0]),t[i][1]+r*(t[i+1][1]-t[i][1])]}n-=e[i]}return t[0]}function z7(t,e,n,i){const r=(u,f)=>{const h=Number(t.node(e,u)??Number.NaN);return(Number.isFinite(h)&&h>=0?h:f)*72},[s,o]=[r("width",L_.w)/2,r("height",L_.h)/2],[l,a]=[i[0]-n[0],i[1]-n[1]],c=Math.hypot(l,a);if(c===0||s===0||o===0)return n;const d=1/Math.hypot(l/c/s,a/c/o);return[n[0]+l/c*d,n[1]+a/c*d]}const Ou={x:16,y:8},hC=1.2,W7=[651,821,942,1716,1303,1946,1597,563,799,799,1024,1716,651,739,651,690,1303,1303,1303,1303,1303,1303,1303,1303,1303,1303,690,690,1716,1716,1716,1087,2048,1401,1405,1430,1577,1294,1178,1587,1540,604,604,1343,1141,1767,1532,1612,1235,1612,1423,1300,1251,1499,1401,2025,1403,1251,1403,799,690,799,1716,1024,1024,1255,1300,1126,1300,1260,721,1300,1298,569,569,1186,569,1995,1298,1253,1300,1300,842,1067,803,1298,1212,1675,1212,1212,1075,1303,690,1303,1716];function pC(t,e){let n=0;for(const i of t){const r=i.codePointAt(0)??0;n+=r>=32&&r<=126?W7[r-32]:1229}return n/2048*e}function B7(t){const e=[];let n="",i=0;for(;i<t.length;){const r=t[i],s=t[i+1];r==="\\"&&(s==="n"||s==="l"||s==="r")?(e.push({text:n,justify:s==="n"?"c":s}),n="",i+=2):r==="\\"&&s!==void 0?(n+=r+s,i+=2):(n+=r,i++)}return(n!==""||e.length===0)&&e.push({text:n,justify:"c"}),e}function H7(t,e){return gC(t,{i:0},e,!0)}function M_(t,e){return{lines:null,port:null,children:t,lr:e,w:0,h:0,x:0,y:0}}function gC(t,e,n,i){const r=[],s={text:"",port:null,sub:null};for(;e.i<t.length;){const o=t[e.i];if(o==="{")e.i++,s.sub=gC(t,e,!n,!1);else if(o==="}"){if(e.i++,!i)return Qh(r,s,n),M_(r,n)}else o==="|"?(e.i++,Qh(r,s,n)):V7(t,e,s)}return Qh(r,s,n),M_(r,n)}function V7(t,e,n){const i=t[e.i],r=t.at(e.i+1);if(i==="\\"&&r!==void 0)n.text+="{}|<> ".includes(r)?r:i+r,e.i+=2;else if(i==="<"){const s=t.indexOf(">",e.i+1),o=s<0?t.length:s;n.port=t.slice(e.i+1,o).trim(),e.i=s<0?t.length:s+1}else n.text+=i,e.i++}function Qh(t,e,n){const{sub:i,port:r}=e;t.push(i??{lines:B7(e.text.trim()),port:r,children:[],lr:!n,w:0,h:0,x:0,y:0}),i!==null&&r!==null&&(i.port=r),e.text="",e.port=null,e.sub=null}function mC(t,e){if(t.lines!==null){const n=Math.max(...t.lines.map(r=>pC(r.text,e))),i=t.lines.length*e*hC;[t.w,t.h]=n>0||i>0?[n+Ou.x,i+Ou.y]:[0,0];return}t.w=0,t.h=0;for(const n of t.children)mC(n,e),t.w=t.lr?t.w+n.w:Math.max(t.w,n.w),t.h=t.lr?Math.max(t.h,n.h):t.h+n.h}function yC(t,e,n){const i=(t.lr?e-t.w:n-t.h)/Math.max(1,t.children.length);t.w=e,t.h=n,t.children.forEach((r,s)=>{const o=Math.trunc((s+1)*i)-Math.trunc(s*i);yC(r,t.lr?r.w+o:e,t.lr?n:r.h+o)})}function bC(t,e,n){t.x=e,t.y=n;let i=t.lr?e:n;for(const r of t.children)bC(r,t.lr?i:e,t.lr?n:i),i+=t.lr?r.w:-r.h}function Y7(t,e,n,i,r,s,o){const l=H7(t,e),a=m=>{m.lines!==null&&(m.lines=m.lines.map(y=>({...y,text:o(y.text)}))),m.children.forEach(a)};a(l),mC(l,s);const c=r?n:Math.max(n,l.w),d=r?i:Math.max(i,l.h);yC(l,c,d),bC(l,-c/2,d/2);const u=[],f=[],h=new Map,p=s*hC,g=m=>{if(m.port!==null&&m.port!==""&&h.set(m.port,{x:m.x+m.w/2,y:m.y-m.h/2,hw:m.w/2,hh:m.h/2}),m.children.forEach((b,_)=>{_>0&&u.push(m.lr?[b.x,b.y,b.x,b.y-b.h]:[b.x,b.y,b.x+b.w,b.y]),g(b)}),m.lines===null)return;const y=m.lines.length;m.lines.forEach((b,_)=>{if(b.text==="")return;const S=pC(b.text,s)/2;let T=m.x+m.w/2;b.justify==="l"?T=m.x+Ou.x/2+S:b.justify==="r"&&(T=m.x+m.w-Ou.x/2-S),f.push({x:T,y:m.y-m.h/2+((y-1)/2-_)*p,text:b.text})})};return g(l),{width:c,height:d,dividers:u,texts:f,ports:h}}const Nu=Object.freeze({tool:"graphviz",node:Object.freeze(["fill","fillOpacity","borderColor","borderWidth","borderStyle","shape","width","height","label","labelColor","labelSize","labelFont","labelWeight","labelItalic","labelPosition","shapePoints","shapePointsStretch","shapeParts","shapeLines","shapeLineWidth","tooltip","visible"]),edge:Object.freeze(["color","opacity","width","lineStyle","sourceArrow","targetArrow","sourceArrowColor","targetArrowColor","arrowSize","label","sourceLabel","targetLabel","labelColor","labelSize","labelFont","labelWeight","labelItalic","tooltip","visible"]),graph:Object.freeze(["background"]),block:"native"}),ep="name",U_="directed",K7="cluster",Mg=["colorscheme","color","fillcolor","bgcolor","pencolor","style","shape","width","height","fixedsize","regular","sides","distortion","skew","orientation","penwidth","gradientangle","fontname","fontsize","fontcolor","tooltip"],Ug=["colorscheme","color","style","penwidth","fontname","fontsize","fontcolor","tooltip","edgetooltip","arrowhead","arrowtail","dir","arrowsize","fillcolor","headlabel","taillabel","labelfontsize","labelfontcolor","labelfontname","xlabel"],X7=["peripheries","xlabel"],EC=new Set(["circle","doublecircle","mcircle","square","msquare"]),$l=new Set(["box","rect","rectangle","square"]),Pf=new Set(["","ellipse","oval","circle"]),Lb=new Set(["plain","plaintext","none"]),xf=new Set(["record","mrecord"]),q7=new Set(["true","yes","shape"]),G_=.05,J7=.5;function Yi(t){if(t.length<2||!t.startsWith("<")||!t.endsWith(">"))return!1;let e=0;for(let n=0;n<t.length;n++){const i=t.codePointAt(n);if(i===60)e++;else if(i===62&&(e--,e===0&&n!==t.length-1))return!1}return e===0}function Et(t,e,n){if(!t.has(e))return null;const i=K(t.value(e,n));return typeof i=="string"?i:typeof i=="number"||typeof i=="boolean"?String(i):null}function de(t){return t===null||t===""?null:t}function wC(t,e){return t===null?[]:t.length>Ce?(H(e,v.VALUE_TOO_LONG,`${String(t.length)} characters`),[]):t.toLowerCase().split(",").map(n=>n.replace(/^[ \t\r\n]+/,"")).filter(n=>n!=="")}function Mf(t){for(const e of t)if(e.startsWith("setlinewidth(")&&e.endsWith(")"))return e.slice(13,-1).trim();return null}function Ia(t){if(t===null)return!1;const e=t.trim().toLowerCase();return q7.has(e)||/^-?\d+$/.test(e)&&Number(e)!==0}function _C(t,e,n,i,r){return Yi(t)?eg(t,r):n.has(`<${t}>`)?eg(`<${t}>`,r):mf(i?O6(t,r):t,e,r)}function SC(t,e,n,i,r){if(Yi(t)||n.has(`<${t}>`)){const o=new Set([...t.matchAll(/<br\b([^>]*)>/gi)].map(u=>/\balign\s*=\s*["']?(left|right|center)/i.exec(u[1])?.[1].toLowerCase()??"center")),l=Yi(t)?t.slice(1,-1):t,a=/<br\b[^>]*>(?![\s\S]*<br\b)/i.exec(l),c=a===null?"":l.slice(a.index+a[0].length);Z7(c).trim()!==""&&o.add("center");const[d]=o;o.size===1&&d!=="center"&&r("labelTextAlign",d);return}if(i)return;const s=g6(t,e);s!==null&&r("labelTextAlign",s)}function Z7(t){let e="",n=0;for(;n<t.length;){const i=t.indexOf("<",n),r=i<0?-1:t.indexOf(">",i+1);if(r<0)return e+t.slice(n);e+=t.slice(n,i),n=r+1}return e}function OC(t,e,n,i,r){if(!Yi(t)&&!e.has(`<${t}>`))return;const s=Yi(t)?t:`<${t}>`,o=[];for(const a of E1(s)){const c={text:a.text,...tW(a.tags,n,r("labelRuns"))},d=o.at(-1);d!==void 0&&JSON.stringify({...d,text:""})===JSON.stringify({...c,text:""})?d.text=`${String(d.text)}${c.text}`:o.push(c)}if(Q7(o),o.every(a=>Object.keys(a).length===1))return;if(o.length===1){const{text:a,...c}=o[0];for(const[d,u]of Object.entries(c))i(eW[d],u);return}o[0].text=String(o[0].text).trimStart();const l=o.at(-1);l!==void 0&&(l.text=String(l.text).trimEnd()),i("labelRuns",JSON.stringify(o))}function Q7(t){for(;t.length>0&&String(t[0].text).trim()==="";)t.shift();for(;t.length>0&&String(t.at(-1)?.text).trim()==="";)t.pop()}const eW={weight:"labelWeight",italic:"labelItalic",font:"labelFont",size:"labelSize",color:"labelColor"};function tW(t,e,n){const i={};for(const r of t){const s=/^<(\w+)/.exec(r)?.[1].toLowerCase();if(s==="b")i.weight="bold";else if(s==="i")i.italic=!0;else if(s==="font")for(const[o,l]of iW(r))nW(o.toLowerCase(),l,e,n,i)}return i}function nW(t,e,n,i,r){if(t==="face"&&e.trim()!==""&&e.length<=Ce){const s=Rf(e);r.font=s.family,s.bold&&(r.weight="bold"),s.italic&&(r.italic=!0)}else if(t==="point-size"&&Number(e)>0)r.size=Number(e);else if(t==="color"){const s=ve(e,"graphviz",i,{scheme:n,use:"text"});s!==null&&(r.color=s.color)}}const j_=/^[\w-]$/;function iW(t){const e=[];let n=0;for(;n<t.length;){if(!j_.test(t[n])){n++;continue}let i=n;for(;i<t.length&&j_.test(t[i]);)i++;const r=rW(t,i);r!==null&&e.push([t.slice(n,i),r.text]),n=r===null?i:r.next}return e}function rW(t,e){let n=e;for(;n<t.length&&/\s/.test(t[n]);)n++;if(t[n]!=="=")return null;for(n++;n<t.length&&/\s/.test(t[n]);)n++;const i=t[n],r=i==='"'||i==="'"?t.indexOf(i,n+1):-1;return r<0?null:{text:t.slice(n+1,r),next:r+1}}function ds(t,e,n,i,r,s,o){if(t===null)return null;const l=ve(t,"graphviz",o(i),{scheme:e,use:n});return l===null?null:(s(i,l.color),i==="borderColor"?s("borderOpacity",l.alpha>0&&l.alpha<1?l.alpha:null):r!==null?s(r,l.alpha):Ol(l,null,o(i),!1),l.alpha)}function F_(t){const e=P(t);for(let n=6;n<17;n++){const i=Number((t/yt).toPrecision(n));if(P(i*yt)===e)return i+0}return t/yt}function Au(t,e){if(t===null)return null;const n=t.trim()===""?Number.NaN:Number(t);return!Number.isFinite(n)||n<0?(H(e,v.BAD_VALUE,t.slice(0,Ce)),null):n}function NC(t,e,n,i,r,s){(e.includes("invis")||e.includes("invisible"))&&r("visible",!1);const o=(d,u)=>{r(d,d==="labelOpacity"&&u===1?null:u)};ds(de(t("fontcolor")),n,"text","labelColor","labelOpacity",o,s);const l=t("fontsize");r("labelSize",l===null?null:Y(l,s("labelSize")));const a=t("fontname");if(a!==null&&a.length<=Ce){const d=Rf(a);r("labelFont",d.family),r("labelWeight",d.bold?"bold":null),r("labelItalic",d.italic?!0:null)}const c=t("tooltip")??t("edgetooltip");c!==null&&r("tooltip",mf(c,i,s("tooltip")))}function sW(t,e){const{get:n,cx:i,put:r,at:s,shape:o}=t,l=t.point?null:n(Ue),a=l===null?i.name:_C(l,e,i.html,xf.has(o),s("label"));oW(t,l,a,e);const c=l!==null&&(Yi(l)||i.html.has(`<${l}>`));o==="plain"&&a===""&&!c&&r("visible",!1),i.cluster?cW(n,r):lW(t,l,a,c,e)}function oW(t,e,n,i){const{get:r,cx:s,put:o,at:l,shape:a}=t;if(e!==null&&!(s.cluster&&e==="")&&(o("label",n),SC(e,i,s.html,xf.has(a),o),OC(e,s.html,t.scheme,o,l),s.cluster&&(o("labelPosition",IC(r)),dW(r,o))),!s.cluster&&!t.point){const c=TC(r);o("labelPosition",c==="center"?null:c)}}function lW(t,e,n,i,r){const{get:s,put:o,at:l,shape:a}=t;NW(s,a,t.point,o,l),xf.has(a)&&e!==null&&!i?aW(t,e,r):t.point||($W(s,a,e,n,o),AW(t,e))}const z_={w:54,h:36};function aW(t,e,n){const{get:i,put:r,at:s,cx:o}=t,l=(p,g)=>{const m=Au(i(p),s(p==="width"?"width":"height"));return m===null?g:m*yt},a=Number(i("fontsize")??14),c=Y7(e,!o.flip,l("width",z_.w),l("height",z_.h),Ia(i("fixedsize")),Number.isFinite(a)&&a>0?a:14,p=>mf(p,n)),d=c.width/2,u=c.height/2,f=p=>String(P(d>0?p/d:0)),h=p=>String(P(u>0?p/u:0));r("width",P(c.width)),r("height",P(c.height)),r("label",""),r("shapeLines",c.dividers.length===0?null:c.dividers.map(([p,g,m,y])=>`${f(p)},${h(g)} ${f(m)},${h(y)}`).join("; ")),r("shapeTexts",c.texts.length===0?null:JSON.stringify(c.texts.map(p=>[Number(f(p.x)),Number(h(p.y)),p.text])))}function cW(t,e){const n=(t("bb")??"").split(",").map(Number);n.length===4&&n.every(Number.isFinite)&&n[2]>=n[0]&&n[3]>=n[1]&&(e("width",P(n[2]-n[0])),e("height",P(n[3]-n[1])))}function AC(t,e,n,i){const r=wC(t("style"),i("visible")),s=de(t("shape")),o=(s??"").toLowerCase(),l={get:t,cx:e,put:n,at:i,tokens:r,shapeRaw:s,shape:o,point:!e.cluster&&o==="point",scheme:t("colorscheme"),color:de(t("color"))},a=e.cluster?{graph:e.name}:{node:e.name,graph:e.graph,edge:""};NC(t,r,l.scheme,a,n,i),e.cluster?uW(l):fW(l),hW(l),pW(l),mW(l),sW(l,a),de(t("xlabel"))!==null&&H(i("label"),v.NOT_CARRIED,"xlabel")}function TC(t){const e=(t("labelloc")??"").trim().toLowerCase();return e.startsWith("t")?"inside-top":e.startsWith("b")?"inside-bottom":"center"}const W_=8;function dW(t,e){const n=(t("lp")??"").split(",").map(Number),i=(t("bb")??"").split(",").map(Number);if(n.length===2&&i.length===4&&[...n,...i].every(Number.isFinite)){e("labelPosition","center"),e("labelOffsetX",P(n[0]-(i[0]+i[2])/2)),e("labelOffsetY",P((i[1]+i[3])/2-n[1]));return}const r=(t("labeljust")??"").trim().toLowerCase();r.startsWith("l")?e("labelOffsetX",W_):r.startsWith("r")&&e("labelOffsetX",-W_)}function IC(t){const e=(t("labelloc")??"").trim().toLowerCase().startsWith("b")?"inside-bottom":"inside-top",n=(t("labeljust")??"").trim().toLowerCase();return n.startsWith("l")?`${e}-left`:n.startsWith("r")?`${e}-right`:e}function uW(t){const{get:e,tokens:n}=t,i=n.includes("filled")||n.includes("radial")||n.includes("striped"),r=de(e("bgcolor")),s=i?de(e("fillcolor"))??t.color??r??"lightgrey":r;ds(s,t.scheme,"fill","fill","fillOpacity",t.put,t.at),n.includes("striped")||$C(t,s)}function $C(t,e){const n=e===null?-1:e.indexOf(":");if(e===null||n<0)return;const i=t.tokens.includes("radial");i&&t.put("fillGradientKind","radial");const r=Number(e.slice(0,n).split(";")[1]);r>0&&r<1&&t.put("fillGradientStops",`${String(P(r-.001))} ${String(P(r))}`);const s=e.slice(n+1).split(":")[0].split(";")[0],o=ve(s===""?"black":s,"graphviz",t.at("fillGradient"),{scheme:t.scheme,use:"fill"});if(o===null||(t.put("fillGradient",o.color),i))return;const l=Number(de(t.get("gradientangle"))??"0"),a=Number.isFinite(l)?(-l%360+360)%360:0;t.put("fillGradientAngle",P(a)+0)}function fW(t){const{point:e}=t,n=de(t.get("fillcolor"));if(vC(t)){const i=n??t.color??(e?"black":"lightgrey");ds(i,t.scheme,"fill","fill","fillOpacity",t.put,t.at);const r=t.tokens.includes("striped")&&$l.has(t.shape)||t.tokens.includes("wedged")&&Pf.has(t.shape);(t.tokens.includes("filled")||t.tokens.includes("radial"))&&!r&&$C(t,i)}else n!==null&&H(t.at("fill"),v.UNFILLED,n.slice(0,Ce))}function hW(t){const e=t.tokens.includes("striped")&&(t.cx.cluster||$l.has(t.shape)),n=!t.cx.cluster&&t.tokens.includes("wedged")&&Pf.has(t.shape),i=de(t.get("fillcolor"))??t.color;if(!e&&!n||!i?.includes(":"))return;const r=CC(i,t.scheme,"fill",t.at(e?"stripeColors":"pieColors"));if(r.length===0)return;const s=e?r:[...r].reverse(),o=e?"stripe":"pie";t.put(`${o}Colors`,s.map(l=>l.color).join(" ")),t.put(`${o}Sizes`,s.map(l=>String(l.size)).join(" ")),e?t.put("stripeDirection","right"):(t.put("pieFitBox",!0),t.put("pieRotation",90))}function CC(t,e,n,i){const s=t.split(":").map(f=>{const[h,p]=f.split(";"),g=ve(h.trim(),"graphviz",i,{scheme:e,use:n}),m=p===void 0?Number.NaN:Number(p);return{color:g?.color??null,fraction:Number.isFinite(m)&&m>=0?m:null}}).flatMap(f=>f.color===null?[]:[{color:f.color,fraction:f.fraction}]),o=s.reduce((f,h)=>f+(h.fraction??0),0),l=s.filter(f=>f.fraction===null).length,a=l>0?Math.max(0,1-o)/l:0;let c=0;const d=s.flatMap(f=>{const h=Math.min(f.fraction??a,1-c);return c+=Math.max(h,0),h>0?[{color:f.color,size:P(h)}]:[]}),u=d.at(-1);return u!==void 0&&l===0&&c<1&&(u.size=P(u.size+1-c)),d}function vC(t){const{shape:e,point:n}=t;return n||t.tokens.some(i=>i==="filled"||i==="radial"||i==="striped"&&$l.has(e)||i==="wedged"&&Pf.has(e))}function pW(t){const{get:e,cx:n,put:i,at:r,tokens:s}=t;if(!n.cluster&&Lb.has(t.shape))i("borderWidth",0);else{const o=n.cluster?de(e("pencolor"))??t.color:t.color,l=ds(o,t.scheme,"line","borderColor",null,i,r),a=de(e("penwidth"))??Mf(s);l===0||Number(de(e("peripheries"))??"1")===0?i("borderWidth",0):a!==null?i("borderWidth",RC(a,e("penwidth")!==null,r("borderWidth"))):s.includes("bold")&&i("borderWidth",2)}s.includes("dashed")?i("borderStyle","dashed"):s.includes("dotted")&&i("borderStyle","dotted"),n.cluster||gW(t)}const Pb=new Map([["doublecircle",2],["doubleoctagon",2],["tripleoctagon",3]]),xb=4;function gW(t){const e=de(t.get("peripheries")),n=e===null?Pb.get(t.shape)??1:Math.trunc(Number(e));if(Number.isNaN(n)||n<=1||Lb.has(t.shape))return;const i=t.color===null?null:ve(t.color,"graphviz",t.at("outerBorderColor"),{scheme:t.scheme,use:"line"});if(i!==null&&i.alpha===0)return;const r=de(t.get("penwidth"))??Mf(t.tokens),s=r===null?Number.NaN:Number(r),o=t.tokens.includes("bold")?2:1,l=Number.isFinite(s)?Math.max(0,s):o;t.put("outerBorderColor",i?.color??"#000000"),t.put("outerBorderOpacity",i!==null&&i.alpha<1?i.alpha:null),t.put("outerBorderWidth",P(l)),t.put("outerBorderOffset",P(Math.max(0,xb-l))),(t.tokens.includes("dashed")||t.tokens.includes("dotted"))&&t.put("outerBorderStyle",t.tokens.includes("dashed")?"dashed":"dotted"),n>2&&H(t.at("outerBorderWidth"),v.NOT_CARRIED,`peripheries=${String(n)}`)}function mW(t){const e=t.tokens.includes("rounded")&&!t.tokens.includes("striped"),n=bW(t);if(t.cx.cluster)t.put("shape",e?"round-rectangle":"rectangle");else if(t.shape==="polygon")EW(t,e);else if(n!==null)t.put("shape","polygon"),t.put("shapePoints",Uf(Mb(n))),t.put("shapePointsStretch",!1);else if(Tu.has(t.shape))t.put("shape","polygon"),t.put("shapePoints",Tu.get(t.shape)??null),t.put("shapePointsStretch",!1);else if(Cb.has(t.shape)){const i=r=>{const s=Au(t.get(r),t.at(r));return s===null?null:s*yt};DC(t.shape,i("width"),i("height"),t.put,()=>{const r=de(t.get("penwidth"))??Mf(t.tokens),s=r===null?Number.NaN:Number(r);return Number.isFinite(s)?Math.max(0,s):t.tokens.includes("bold")?2:1},()=>t.color===null?null:ve(t.color,"graphviz",t.at("outerBorderColor"),{scheme:t.scheme,use:"line"})?.color??null)}else if(t.shapeRaw!==null){const i=e&&$l.has(t.shape)?"round-rectangle":le("shape",t.shapeRaw,"graphviz",t.at("shape"));t.put("shape",i==="none"&&vC(t)?"rectangle":i)}}const yW=new Map([...[...$l].map(t=>[t,{sides:4,orientation:0}]),["diamond",{sides:4,orientation:45}],["hexagon",{sides:6,orientation:0}],["octagon",{sides:8,orientation:0}]]);function bW(t){const e=Number(de(t.get("orientation"))??"0"),n=yW.get(t.shape)??sC.get(t.shape);if(n===void 0||!Number.isFinite(e)||e%360===0)return null;const i={distortion:0,skew:0,...n,orientation:n.orientation+Math.max(-360,e)};return rC(i)?null:i}function EW(t,e){const n=(r,s,o)=>{const l=de(t.get(r)),a=l===null?Number.NaN:Number(l);return Number.isFinite(a)?Math.max(o,a):s},i={sides:Math.trunc(n("sides",4,0)),distortion:n("distortion",0,-100),skew:n("skew",0,-100),orientation:n("orientation",0,-360)};rC(i)?t.put("shape",e?"round-rectangle":"rectangle"):i.sides<3?t.put("shape","ellipse"):(t.put("shape","polygon"),t.put("shapePoints",Uf(Mb(i))),t.put("shapePointsStretch",!1))}function Mb(t){const e=p7(t),n=s=>Math.max(1,1/Math.max(...e.map(o=>Math.abs(o[s])))),[i,r]=[n(0),n(1)];return e.map(([s,o])=>[s*i,o*r])}function Uf(t){return t.map(([e,n])=>`${P(e)},${P(n)}`).join(" ")}const Tu=new Map([...sC].map(([t,e])=>[t,Uf(Mb(e))]));function DC(t,e,n,i,r,s){const o=kC(t,e,n);o!==null&&(i("shape","polygon"),i("shapePoints",o.outline),i("shapePointsStretch",!1),i("shapeParts",o.parts),i("shapeLines",o.lines),o.unstroked&&(i("shapeLineWidth",r()),i("borderWidth",0)),o.ring!==null&&(i("outerBorderColor",s()??"#000000"),i("outerBorderWidth",P(r())),i("outerBorderOffset",P(Math.max(0,o.ring-r())))))}function kC(t,e,n){const i=lC(t,e,n);if(i===null)return null;const r=(c,d)=>(c!==null&&c>0?c:d)/2,[s,o]=[r(e,54),r(n,36)],l=c=>Uf(c.map(([d,u])=>[d/s,u/o])),a=c=>c.length===0?null:c.map(l).join("; ");return{outline:l(i.outline),parts:a(i.parts),lines:a(i.lines),unstroked:i.unstroked===!0,ring:i.ring??null}}function wW(t){return Tu.get(t)}function _W(t){return Lb.has(t)}const SW=new Map([...Tu].map(([t,e])=>[e,t]));function OW(t,e,n){const i=o=>{const l=t(o);return typeof l=="string"?l.trim():null},r=i("shapePoints");if(r===null)return;const s=r===""?0:r.split(/\s+/).length;for(const o of Cb){if(lC(o,e,n)?.outline.length!==s)continue;const l=kC(o,e,n);if(l!==null&&l.outline===r&&l.parts===i("shapeParts")&&l.lines===i("shapeLines"))return{name:o,unstroked:l.unstroked}}}function RC(t,e,n){const i=Number(t.trim());return e&&Number.isFinite(i)&&i<0?(H(n,v.BAD_VALUE,t.slice(0,Ce)),0):Y(t,n)}function NW(t,e,n,i,r){let s=Au(t("width"),r("width")),o=Au(t("height"),r("height"));const l=n||EC.has(e)||Ia(t("regular"));if(e==="plain")s=o=0;else if(s===null&&o===null){if(n){i("width",P(G_*yt)),i("height",P(G_*yt));return}if(!l)return;s=o=J7}let a=s,c=o;n?a=c=Math.min(s??1/0,o??1/0):l&&(a=c=Math.max(s??0,o??0)),i("width",a===null?null:Y(a,r("width"),yt)),i("height",c===null?null:Y(c,r("height"),yt))}function AW(t,e){const{get:n,put:i,shape:r}=t;let s=$l.has(r)?1:null;Pf.has(r)&&(s=Math.SQRT2);const o=Number(n("width")??Number.NaN),l=Number(n("height")??Number.NaN);if(t.cx.quantum===0||s===null||e===""||Ia(n("fixedsize"))||!(o>=0&&l>=0))return;const a=t.cx.quantum*s;i("width",P(Math.max(o*yt,a))),i("height",P(Math.max(l*yt,a)))}const TW={x:8,y:4},IW=1.2;function $W(t,e,n,i,r){if(Ia(t("fixedsize"))||n===""&&!xf.has(e))return;const s=Math.max(1,i.replace(/\n$/,"").split(`
|
|
80
|
+
`).length),o=Number(t("fontsize")??14),l=Number.isFinite(o)&&o>0?o:14,a=(t("margin")??"").split(",").filter(f=>f.trim()!=="").map(Number).filter(CW),c=e==="plain"?{x:0,y:0}:TW,d=a.length>0?a[0]*yt:c.x,u=a.length>0?(a[1]??a[0])*yt:c.y;r("labelFit",g7.has(e)?"bounds":"inside"),r("labelPaddingX",P(d)),r("labelPaddingY",P(u+(IW-1)*l*s/2)),(EC.has(e)||Ia(t("regular")))&&r("labelFitSquare",!0)}function CW(t){return Number.isFinite(t)&&t>=0}function LC(t,e,n,i){const r=wC(t("style"),i("visible")),s=t("colorscheme");NC(t,r,s,e.names,n,i),ds(de(t("color")),s,"edge","color","opacity",n,i),DW(de(t("color")),s,n,i),MW(t,r,n,i),UW(t,e,n,i);for(const[o,l]of[[Ue,"label"],["headlabel","targetLabel"],["taillabel","sourceLabel"]]){const a=o===Ue?t(o)??de(t("xlabel")):t(o);a!==null&&(n(l,_C(a,e.names,e.html,!1,i(l))),l==="label"&&(SC(a,e.names,e.html,!1,n),OC(a,e.html,s,n,i)))}t(Ue)!==null&&de(t("xlabel"))!==null&&H(i("label"),v.NOT_CARRIED,"xlabel"),vW(t,s,n,i)}function vW(t,e,n,i){const r=["target","source"].filter(l=>t(l==="target"?"headlabel":"taillabel")!==null),s=t("labelfontsize"),o=t("labelfontname");for(const l of r)ds(de(t("labelfontcolor")),e,"text",`${l}LabelColor`,null,n,i),s!==null&&n(`${l}LabelSize`,Y(s,i(`${l}LabelSize`))),o!==null&&o.length<=Ce&&n(`${l}LabelFont`,Rf(o).family)}function DW(t,e,n,i){if(t===null||!t.includes(":")||!t.includes(";"))return;const r=CC(t,e,"edge",i("gradientColors"));if(r.length<2)return;const s=[],o=[];let l=0;for(const a of r)s.push(a.color,a.color),o.push(P(l),P(Math.min(1,l+a.size))),l+=a.size;n("gradientKind","linear"),n("gradientColors",s.join(" ")),n("gradientStops",o.join(" "))}function kW(t){const e=t.nodes.byRole("position");return{center:n=>{const i=e?.isSet(n)===!0?e.value(n):null;return i===null?null:[i[0],i[1]]},node:(n,i)=>de(Et(t.nodes,i,n)),external:(Et(t.graph,"layout",0)?.trim().toLowerCase()??"dot")!=="dot"}}function RW(t,e,n){if(n===null)return null;const i=t.nodes.byRole("position"),r=l=>{const a=i?.isSet(l)===!0?i.value(l):null;return a===null?null:[a[0],a[1]]},[s,o]=[r(t.edgeSource(e)),r(t.edgeTarget(e))];return s===null||o===null?null:LW(s,o,n)}function LW(t,e,n){const i=(l,a)=>{const c=(l??"").trim().split(/\s+/).find(f=>f.startsWith(`${a},`)),[d,u]=(c??"").slice(2).split(",").map(Number);return c!==void 0&&Number.isFinite(d)&&Number.isFinite(u)?[d,u]:null},r=n.split(";"),s={start:i(r[0],"s"),end:i(r.at(-1),"e")},o=r.map(l=>l.trim().split(/\s+/).filter(a=>!/^[es],/.test(a)).map(a=>{const[c,d]=a.split(",").map(Number);return[c,d]}));return PC(t,e,o,s)}const PW=1,B_={x:18,y:9};function xW(t){const e=o=>de(o("tailport"))===null&&de(o("headport"))===null&&de(o(Xs))===null,n=new Map,i=(de(Et(t.graph,"splines",0))??"").toLowerCase(),r=i!=="ortho"&&i!=="none"&&de(Et(t.graph,Z,0))===null;for(let o=0;o<t.edgeCount&&r;o++){const l=t.edgeSource(o);l===t.edgeTarget(o)&&e(a=>Et(t.edges,a,o))&&n.set(l,[...n.get(l)??[],o])}const s=(o,l,a)=>{const c=Number(de(Et(t.nodes,l,o))??Number.NaN);return(Number.isFinite(c)&&c>0?c:a)*yt};return{bendsOf:(o,l)=>{const a=t.edgeSource(o),c=n.get(a);if(a!==t.edgeTarget(o)||c===void 0||!e(l))return null;const[d,u]=[s(a,"width",.75),s(a,"height",.5)],f=c.indexOf(o)+1,h=d/2+B_.x*f,p=B_.y*f/c.length,g=Sf([[0,0],[h/3,p],[h,p],[h,0],[h,-p],[h/3,-p],[0,0]]);return g===null?null:Hs([0,0],[d,u],g.slice(1,-1),!1)}}}function PC(t,e,n,i){const r=[];for(const f of n){const h=Sf(f);if(h===null||h.some(([p,g])=>!Number.isFinite(p)||!Number.isFinite(g)))return null;r.push(...h)}const s=(f,h)=>h===void 0||Math.hypot(f[0]-h[0],f[1]-h[1])>1e-6,o=i?.start??null,l=i?.end??null;o!==null&&s(o,r[0])&&r.unshift(o),l!==null&&s(l,r.at(-1))&&r.push(l);const[a,c]=[e[0]-t[0],e[1]-t[1]],d=Math.hypot(a,c);return(d>0?Math.max(...r.map(([f,h])=>Math.abs((f-t[0])*c-(h-t[1])*a)))/d:0)>Math.max(.001*d,PW)?Al(t,e,r,!1):null}function MW(t,e,n,i){const r=de(t("penwidth"))??Mf(e);r!==null?n("width",RC(r,t("penwidth")!==null,i("width"))):e.includes("bold")&&n("width",2),e.includes("dashed")?n("lineStyle","dashed"):e.includes("dotted")?n("lineStyle","dotted"):e.includes("solid")||e.includes("bold")?n("lineStyle","solid"):e.includes("tapered")&&n("lineStyle","other:tapered")}function UW(t,e,n,i){const r=de(t("dir")),s=de(t("arrowhead")),o=de(t("arrowtail"));if(r!==null||s!==null||o!==null){const c=(r??(e.directed?"forward":"none")).trim().toLowerCase();H_("target",s,c==="forward"||c==="both",n,i),H_("source",o,c==="back"||c==="both",n,i)}const l=t("arrowsize");l!==null&&n("arrowSize",Y(l,i("arrowSize")));const a=de(t("fillcolor"));for(const c of["targetArrowColor","sourceArrowColor"])ds(a,t("colorscheme"),"fill",c,null,n,i)}function H_(t,e,n,i,r){const s=n?xC(e??"normal",r(`${t}Arrow`)):null;i(`${t}Arrow`,s===null?"none":s.value),s?.side!==null&&s?.side!==void 0&&i(`${t}ArrowSide`,s.side)}const GW=["left","right"],jW=new Set(["normal","diamond","dot","box","inv"]),FW=new Map([["obox","other:open-square"],["oinv","other:open-inverted"]]);function xC(t,e){const n=zW(t);return{value:(n===null?void 0:FW.get(n.name))??le("arrow",n?.name??t,"graphviz",e),side:n?.side??null}}function zW(t){let e=t.trim().toLowerCase();for(e==="invempty"&&(e="oinv");e.length>0;){const n=/^([olr]{0,3})(normal|crow|tee|box|diamond|dot|none|inv|vee|icurve|curve)/.exec(e);if(n===null)return null;e=e.slice(n[0].length);const[,i,r]=n;if(r!=="none"){const s=GW.find(l=>i.includes(l[0]))??null;return{name:(i.includes("o")&&jW.has(r)?"o":"")+r,side:s}}}return null}function WW(t){const e=new Set;for(let n=0;n<t.nodeCount;n++){const i=t.ids.idOf(n);typeof i=="string"&&Yi(i)&&e.add(i)}for(const[n,i]of[[t.nodes,t.nodeCount],[t.edges,t.edgeCount]])for(const r of[Ue,"headlabel","taillabel"].filter(s=>n.has(s)))BW(n,r,i,e);return e}function BW(t,e,n,i){for(let r=0;r<n;r++){const s=Et(t,e,r);s!==null&&Yi(s)&&i.add(s)}}function MC(t){const e=new Array(t.edgeCount).fill(t.directed),n=t.directed?t.edges.byRole("directed"):null;if(n!==null)for(let i=0;i<t.edgeCount;i++){const r=K(n.value(i));typeof r=="boolean"&&(e[i]=r)}return e}function HW(t,e){return t.nodes.has(Cs)&&t.nodes.value(Cs,e)===!0}function UC(t,e=null){const n=WW(t),i=t.meta.name??"",r=(Et(t.graph,"rankdir",0)??"").trim().toUpperCase(),s=r==="LR"||r==="RL",o=Number(Et(t.graph,"quantum",0)??Number.NaN),l=Number.isFinite(o)&&o>0?o*yt:0,a=MC(t),c=e===null||a.every(u=>u===t.directed)?a:a.map(()=>e),d=u=>String(t.ids.idOf(u));return{node:u=>({name:d(u),graph:i,cluster:HW(t,u),html:n,flip:s,quantum:l}),edge:u=>{const f=d(t.edgeSource(u)),h=d(t.edgeTarget(u));return{names:{graph:i,tail:f,head:h,edge:`${f}${c[u]?"->":"--"}${h}`},directed:c[u],html:n}}}}function GC(t,e,n){if(t.cluster||e==="point")return null;const i={notes:n,target:"node",property:"label"};return Yi(t.name)?eg(t.name,i):mf(String.raw`\N`,{node:t.name,graph:t.graph},i)}function V_(t,e){const n=new Set([...e,...X7]);return[...t.names()].filter(i=>n.has(i)||i.startsWith("graphty.style."))}function VW(t,e){const n={},i=de(Et(t.graph,"bgcolor",0));return!t.graph.has("bgcolor")||i===null||ds(i,Et(t.graph,"colorscheme",0),"fill","background",null,(r,s)=>{s!==null&&(n[r]=s)},r=>({notes:e,target:"graph",property:r})),n}function YW(t,e){const n=new se,i=UC(t),r=Qr(t.nodeCount),s=new Array(t.nodeCount).fill(null),o=new Array(t.nodeCount).fill(null);let l=0,a=0;for(let $=0;$<t.nodeCount;$++){e.budget.spend("node",Mg.length);const D=B=>Et(t.nodes,B,$),x=i.node($);AC(D,x,(B,Q)=>{r.put($,B,Q)},B=>({notes:n,target:"node",property:B,element:$,budget:e.budget}));const G=GC(x,(D("shape")??"").toLowerCase(),n);G!==null&&(s[$]=G,l++),x.cluster&&(o[$]=!0,a++)}const c=Qr(t.edgeCount),d=xW(t),u=Et(t.graph,"splines",0)?.trim().toLowerCase(),f=u===""||u==="none",h=kW(t);for(let $=0;$<t.edgeCount;$++){e.budget.spend("edge",Ug.length);const D=G=>Et(t.edges,G,$),x=G=>({notes:n,target:"edge",property:G,element:$,budget:e.budget});LC(D,i.edge($),(G,B)=>{c.put($,G,B)},x),f&&c.put($,"visible",!1);const R=RW(t,$,D(Xs))??d.bendsOf($,D);R!==null&&c.put($,"bends",R),U7(t,h,$,D,(G,B)=>{c.put($,G,B)})}const p=VW(t,n),g=Et(t.graph,Z,0);g!==null&&sB(t,g,{node:r.values,edge:c.values},i);const m=[],y=new Map;l>0&&(y.set(ep,s),m.push({id:"node.tool.name-label",target:"node",role:"passthrough",origin:"tool",where:{has:{style:ep}},map:{label:{kind:"passthrough",by:{style:ep}}},facts:{elements:l,reason:"NODE_NAME"}}));const b=a>0?[{ref:{style:K7},values:o}]:[],_=[],S=new Map,T=MC(t);return T.some(Boolean)&&(S.set(U_,T.map($=>$?!0:null)),_.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:U_}},set:{targetArrow:"triangle"}})),{canonical:!0,dialect:"graphviz",tool:"graphviz",units:"px",node:{values:r.values,rules:m,columns:y,features:b},edge:{values:c.values,rules:_,columns:S},graph:p,notes:n.list(),readFrom:{node:V_(t.nodes,Mg),edge:V_(t.edges,Ug)}}}const KW=new Map([["ellipse","ellipse"],["rectangle","box"],["round-rectangle","box"],["triangle","triangle"],["diamond","diamond"],["pentagon","pentagon"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","parallelogram"],["trapezoid","trapezium"],["star","star"],["none","none"]]),XW=new Map([["none","none"],["triangle","normal"],["triangle-open","onormal"],["vee","vee"],["tee","tee"],["diamond","diamond"],["diamond-open","odiamond"],["circle","dot"],["circle-open","odot"],["square","box"],["crow","crow"],["inverted","inv"],["other:open-square","obox"],["other:open-inverted","oinv"]]),jC=new Map([["dashed","dashed"],["dotted","dotted"]]);function Y_(t){const e=vr("graphviz")?.[t],n=new Map,i=(s,o,l=1)=>{const a=e[o]?.value;typeof a=="number"?n.set(s,P(a/l)):typeof a=="string"&&n.set(s,a)};i("fontcolor","labelColor"),i("fontsize","labelSize");const r=e.labelFont?.value;return typeof r=="string"&&n.set("fontname",$b(r,!1,!1)),t==="node"?(i("color","borderColor"),i("pencolor","borderColor"),i("penwidth","borderWidth"),i("shape","shape"),i("width","width",yt),i("height","height",yt)):(i("color","color"),i("penwidth","width"),i("arrowsize","arrowSize")),n}const qW={node:Y_("node"),edge:Y_("edge")};function FC(t,e){for(const[n,i]of qW[e])t.get(n)===i&&t.delete(n);return!t.has("width")&&!t.has("height")&&t.delete("fixedsize"),t}function zC(t,e){if(typeof e!="number"||e>=1)return t;const n=Math.max(0,Math.min(255,Math.round(e*255)));return t+n.toString(16).padStart(2,"0")}function Ub(t){return t.replaceAll("&","&").replaceAll("\\",String.raw`\\`).replaceAll(`
|
|
81
|
+
`,String.raw`\n`)}function Gf(t,e,n,i,r){const s=t.get(e);return s!==void 0?s:e.startsWith("other:")?e.slice(6):(r(i,e),n)}function WC(t,e,n,i){const r=t("labelColor");typeof r=="string"&&n.set("fontcolor",r);const s=t("labelSize");typeof s=="number"&&n.set("fontsize",s);const o=t("labelFont"),l=t("labelWeight")==="bold",a=t("labelItalic")===!0;if(typeof o=="string"){const d=$b(o,l,a);n.set("fontname",d);const u=Rf(d);u.bold!==l&&e("labelWeight",t("labelWeight")??"normal"),u.italic!==a&&e("labelItalic",a)}else(l||a)&&e(l?"labelWeight":"labelItalic",l?"bold":!0);const c=t("tooltip");typeof c=="string"&&n.set("tooltip",Ub(c)),t("visible")===!1&&i.push("invis")}function BC(t,e,n,i,r){const s=new Map,o=[];WC(t,i,s,o),ZW(t,e,i,s,o);const l=QW(t,e,i,s,o);e.cluster||iB(t,s);const a=t("label"),c=GC(e,l,r);return typeof a=="string"&&a!==c?s.set(Ue,Ub(a)):a===null&&c!==null&&s.set(Ue,""),JW(t("labelPosition"),e,n,i),o.length>0&&s.set("style",o.join(",")),FC(s,"node")}function JW(t,e,n,i){typeof t=="string"&&t!==(e.cluster?IC(n):TC(n))&&i("labelPosition",t)}function ZW(t,e,n,i,r){const s=t("fill"),o=t("fillOpacity");typeof s=="string"&&o!==0&&(r.push("filled"),i.set("fillcolor",zC(s,o)));const l=t("borderColor");typeof l=="string"&&i.set(e.cluster?"pencolor":"color",l);const a=t("borderWidth");typeof a=="number"&&i.set("penwidth",a);const c=t("borderStyle");if(typeof c=="string"&&c!=="solid"){const d=c.includes("dash")?"dashed":"solid";r.push(Gf(jC,c,d,"borderStyle",n))}}function QW(t,e,n,i,r){const s=t("shape");if(typeof s!="string")return"";if(s==="round-rectangle"&&r.push("rounded"),e.cluster)return s!=="rectangle"&&s!=="round-rectangle"&&n("shape",s),"";const o=d=>{const u=t(d);return typeof u=="number"?u:null},l=s==="polygon"?OW(t,o("width"),o("height")):void 0;if(l!==void 0)return eB(t,l,i);tB(t,n);const a=s==="polygon"?nB(t("shapePoints"),n,i):null;if(a!==null)return t("shapePointsStretch")!==!1&&n("shapePointsStretch",!0),a;const c=Gf(KW,s,s==="vee"?"invtriangle":"box","shape",n);return i.set("shape",c),c}function eB(t,e,n){n.set("shape",e.name);const i=t("shapeLineWidth");return e.unstroked&&typeof i=="number"&&n.set("penwidth",i),e.name}function tB(t,e){for(const n of["shapeParts","shapeLines","shapeLineWidth"]){const i=t(n);i!=null&&e(n,i)}}function nB(t,e,n){if(typeof t!="string")return null;const i=SW.get(t.trim());if(i!==void 0)return n.set("shape",i),i;const r=t.trim().split(/\s+/).length;return r<3?null:(n.set("shape","polygon"),n.set("sides",r),e("shapePoints",t),"polygon")}function iB(t,e){const n=t("width"),i=t("height");(typeof n=="number"||typeof i=="number")&&typeof t("labelFit")!="string"&&e.set("fixedsize","true"),typeof n=="number"&&e.set("width",F_(n)),typeof i=="number"&&e.set("height",F_(i))}function HC(t,e,n){const i=new Map,r=[];WC(t,n,i,r);const s=t("color");typeof s=="string"&&i.set("color",zC(s,t("opacity")));const o=t("width");typeof o=="number"&&i.set("penwidth",o);const l=t("lineStyle");typeof l=="string"&&l!=="solid"&&r.push(Gf(jC,l,l.includes("dash")?"dashed":"solid","lineStyle",n)),rB(t,e,n,i);const a=t("targetArrowColor"),c=t("sourceArrowColor"),d=a??c;typeof d=="string"&&(i.set("fillcolor",d),a!==null&&c!==null&&a!==c&&n("sourceArrowColor",c));const u=t("arrowSize");typeof u=="number"&&i.set("arrowsize",u);for(const[f,h]of[["label",Ue],["targetLabel","headlabel"],["sourceLabel","taillabel"]]){const p=t(f);typeof p=="string"&&i.set(h,Ub(p))}return r.length>0&&i.set("style",r.join(",")),FC(i,"edge")}function rB(t,e,n,i){const r=t("sourceArrow"),s=t("targetArrow"),o=typeof r=="string"&&r!=="none",l=typeof s=="string"&&s!=="none";if((e?l&&!o&&s==="triangle"&&t("targetArrowSide")===null:!l&&!o)||r===null&&s===null)return;let c="none";l&&o?c="both":l?c="forward":o&&(c="back"),i.set("dir",c);const d=(u,f,h)=>{if(u==="half")return n(h,u),n(`${h}Side`,u),"lnormal";const p=Gf(XW,u,"normal",h,n);return f==="left"||f==="right"?`${f[0]}${p}`:p};l&&i.set("arrowhead",d(s,t("targetArrowSide"),"targetArrow")),o&&i.set("arrowtail",d(r,t("sourceArrowSide"),"sourceArrow"))}function sB(t,e,n,i){const r=new se;so(t,e,"dot",s=>({values:n[s],properties:Nu[s],writes:Nu[s],readBack:(o,l)=>{const c=oB(s,o,l,{cx:i,raw:d=>Et(s==="node"?t.nodes:t.edges,d,o)},r);return d=>c.get(d)??null}}))}function oB(t,e,n,i,r){const{cx:s,raw:o}=i,l=()=>{},a=new Map,c=(u,f)=>{f!==null&&a.set(u,f)},d=u=>({notes:r,target:t,property:u});if(t==="node"){const u=s.node(e),f=BC(n,u,o,l,r),h=p=>p==="labelloc"||p==="labeljust"?o(p):null;AC(p=>f.has(p)?K_(f.get(p)):h(p),u,c,d)}else{const u=s.edge(e),f=HC(n,u.directed,l);LC(h=>K_(f.get(h)),u,c,d)}return a}function K_(t){return t===void 0?null:String(t)}function lB(t){const e=t.filter(n=>n!==null);return e.every(n=>typeof n=="number")?e.every(n=>Number.isFinite(n)):e.every(n=>typeof n=="boolean")?!0:e.every(n=>typeof n=="string")?e.some(n=>qn(n)==="string")&&e.every(n=>NT(n)):!1}function aB(t){return t.replaceAll(/\\(["\\])/g,(e,n)=>n==='"'?String.raw`\u0022`:String.raw`\u005c`)}function tp(t,e,n){return e===void 0?null:S7(e,[t,n],()=>cB(t,e,n))}function cB(t,e,n){const i=new Il,r=[],s=t.withColumns(),l=UC(t,n==="directed"||n==="undirected"?n==="directed":null),a=new se;for(const h of["node","edge"]){const p=h==="node"?s.nodes:s.edges,g=yB(e.rules.styles.rules,h),y=dB(t,e,h,{cx:l,approximate:(b,_)=>{i.add(h,b,_)},notes:a,read:g});r.push(...pB(p,h,y,g)),gB(p,y)}const{background:c}=e.rules.styles.graph;s.graph.has("bgcolor")&&s.graph.remove("bgcolor"),typeof c=="string"&&c!==vr("graphviz")?.graph.background?.value&&s.graph.set("bgcolor",[c],{dtype:"string"});const d=[...e.tags.node.values(),...e.tags.edge.values()].some(h=>!lB(h));d||mB(s,e);const u=d?Nl(e.rules,{inlineColumns:!0,snapshot:t}):e.block;s.graph.set(Z,[aB(u)],{dtype:"string"});const f=i.notes("Graphviz");return d&&f.push(...lc(u,e.rules.styles.rules.length,"size")),{snapshot:s,notes:[...r,...f]}}function dB(t,e,n,i){const r=n==="node"?t.nodeCount:t.edgeCount,s=Vs((l,a)=>e.picture(l,a),n,Nu[n]),o=new Map;for(let l=0;l<r;l++){const a=n==="node"?BC(s(l),i.cx.node(l),c=>Et(t.nodes,c,l),i.approximate,i.notes):HC(s(l),i.cx.edge(l).directed,i.approximate);n==="edge"&&t.edgeSource(l)===t.edgeTarget(l)&&i.approximate("bends","self-loop"),i.read.has(Ue)&&a.get(Ue)===""&&s(l)("label")===null&&i.approximate("label",""),uB(o,a,l,r)}return n==="node"&&hB(t,i.cx,o,e.rules.styles.graph.background),o}function uB(t,e,n,i){for(const[r,s]of e){let o=t.get(r);o===void 0&&(o=new Array(i).fill(null),t.set(r,o)),o[n]=s}}const fB=new Map([["style",""],["penwidth",1],["color",""],["pencolor",""],["fillcolor",""],["bgcolor",""],["fontname","Times-Roman"],["fontsize",14],["fontcolor","black"],[Ue,""]]);function hB(t,e,n,i){const r=Array.from({length:t.nodeCount},(s,o)=>o).filter(s=>e.node(s).cluster);for(const[s,o]of fB){const l=n.get(s);if(!(Et(t.graph,s,0)!==null||s==="bgcolor"&&typeof i=="string"||r.some(d=>(l?.[d]??null)!==null)))continue;const c=l??new Array(t.nodeCount).fill(null);for(const d of r)c[d]??=o;n.set(s,c)}}function pB(t,e,n,i){const r=e==="node"?Mg:Ug,s=[];for(const o of t.names()){if(!r.includes(o)&&o!==Ue&&!o.startsWith("graphty.style."))continue;const l=i.has(o)?bB(t,o,n.get(o)):0;l>0&&s.push(Object.freeze({code:VC,message:`${e} column "${o}" is not written: the ${o} attribute holds what graphty draws (${String(l)} ${e}${l===1?"":"s"} differ)`,column:o,count:l})),t.remove(o)}return s}function gB(t,e){for(const[n,i]of e)n===Ue?t.set(n,i,{dtype:"string",role:"label"},{replaceRole:!0}):i.every(r=>r===null||typeof r=="number")?t.set(n,i,{dtype:"f64"}):t.set(n,i.map(r=>r===null?null:String(r)),{dtype:"string"})}function mB(t,e){for(const n of["node","edge"]){const i=n==="node"?t.nodes:t.edges;for(const[r,s]of e.tags[n]){const o=new Set(s.filter(a=>a!==null).map(a=>typeof a));let l="string";o.has("number")?l="f64":o.has("boolean")&&(l="bool"),i.set(r,s,{dtype:l})}}}function yB(t,e){const n=new Set;for(const{ext:i,...r}of t.filter(s=>s.target===e))JSON.stringify(r,(s,o)=>{if(typeof o=="object"&&o!==null&&!Array.isArray(o)&&Object.keys(o).length===1){const{data:l}=o;typeof l=="string"&&n.add(l)}return o});return n}const VC="W_DOT_ATTRIBUTE_CLASH";function bB(t,e,n){const i=t.get(e);let r=0;for(let s=0;i!==null&&s<i.length;s++){const o=i.isSet(s)?K(i.value(s)):null,l=n?.[s]??null,a=typeof o=="string"?o:JSON.stringify(o);o!==null&&(l===null||String(l)!==a)&&r++}return r}const EB=new Set([Db,kb]),Nn=Object.freeze({TRAILING_BACKSLASH:"E_DOT_TRAILING_BACKSLASH",NON_FINITE:"W_DOT_NON_FINITE",TEXT_INFERRED:w.TEXT_INFERRED,ATTRIBUTE_CLASH:VC,MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,PARENTS_DROPPED:w.PARENTS,POSITION_SHAPE:"W_DOT_POSITION_SHAPE",ID_TEXT_TYPE:w.ID_TEXT_TYPE,EMPTY_COLUMN_DROPPED:w.EMPTY_COLUMN,ROLE_ASSUMED:w.ROLE_ASSUMED,CLUSTER_MARKED:"W_DOT_CLUSTER_MARKED",CHARSET_REWRITTEN:"W_DOT_CHARSET_REWRITTEN"}),YC=/^utf-?8$/i;function wB(t){const e=KC(t)&&t.isSet(0)?ea(t,0):null;return e===null||YC.test(e)?[]:[Object.freeze({code:Nn.CHARSET_REWRITTEN,message:`graph attribute charset ${JSON.stringify(e)} is written as "UTF-8", the encoding the file is written in`,column:t.meta.name,count:1})]}function KC(t){return t.meta.name.toLowerCase()==="charset"}const _B=new Set(["label","id","sourcePort","targetPort","parent"]),SB=Object.freeze({label:Ue,id:vs,sourcePort:cC,targetPort:dC,parent:aC,position:Xs}),Gb=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:["bool","i32","f64","string"],components:!1,lists:!1,json:!1,defaults:!1,options:!1,hierarchy:!0,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),OB=" ",NB="cluster",AB=new Set(["n","ne","e","se","s","sw","w","nw","c","_"]),TB=new Set(["parent","parents","position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen","timeText","directed","pair","mutual","weight"]),IB=new Set(["id","weight","directed","pair","mutual","sourcePort","targetPort","position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen","timeText","parent","parents"]),$B=new Set(["position","color","size","shape","thickness"]),CB=new Set(["label","id","sourcePort","targetPort"]),vB=Object.freeze({format:$s,options:Object.freeze(["indent","name","strict"]),capabilities:Gb,styles:Object.freeze({capabilities:Nu}),check(t,e){const n=tp(t,e?.styles,e?.onMixedDirection);return n===null?X_(t,e):Object.freeze([...X_(n.snapshot,e),...n.notes])},export(t,e){return ti(q_(tp(t,e?.styles,e?.onMixedDirection)?.snapshot??t,e))},exportToString(t,e){return ni(q_(tp(t,e?.styles,e?.onMixedDirection)?.snapshot??t,e))}});function X_(t,e){const n=ft(e),i=Un(t,Gb,n,{positionDtype:"f64",roles:_B,roleNames:SB}),r=new XC(t,n,e);return[...i,...r.notes()]}function*q_(t,e){const n=ft(e),i=new XC(t,n,e);i.refuse(),yield*i.write()}function J_(t){return!NT(t)}function Qi(t){return Yi(t)?t:nr(t)}function DB(t){const e=t.lastIndexOf(":");return e>0&&AB.has(t.slice(e+1))?`:${nr(t.slice(0,e))}:${t.slice(e+1)}`:`:${nr(t)}`}function np(t){return t.dtype!=="list"&&t.dtype!=="json"}function Z_(t,e,n){return new N("E_UNSUPPORTED",`option ${t} of the DOT exporter: expected ${n}, got ${JSON.stringify(e)}`,{option:t,found:e})}function kB(t,e,n){const{name:i,role:r}=e.meta,s=e.dtype==="string"||e.dtype==="dict";if(t!=="graph"&&e.nullCount===e.length){n(Nn.EMPTY_COLUMN_DROPPED,`${t} column "${i}" has no set cell and is not written: DOT writes cells, never declarations`,i,0);return}t!=="graph"&&r===null&&i===Ue&&s&&n(Nn.ROLE_ASSUMED,`${t} column "${i}" reads back with the label role`,i,e.length-e.nullCount);const o=e.dtype==="f32"||e.dtype==="f64"?xB(e):0;o>0&&n(Nn.NON_FINITE,`${t} column "${i}" holds ${o} non-finite value${O(o)} with no numeric DOT spelling; they read back as text`,i,o);const l=s&&(r===null||!CB.has(r))?MB(e):0;l>0&&n(Nn.TEXT_INFERRED,`${t} column "${i}" holds ${l} text value${O(l)} that look like numbers or booleans; DOT values are untyped and they read back as such`,i,l)}function RB(t,e,n){e!==null&&e.meta.components!==2&&e.meta.components!==3&&n(Nn.POSITION_SHAPE,`node column "${e.meta.name}" (position) has ${e.meta.components} components and is not written; pos takes 2 or 3`,e.meta.name,e.length-e.nullCount);for(const[i,r]of[["edge",t.edges],["graph",t.graph]]){const s=r.byRole("position");s!==null&&n(Nn.POSITION_SHAPE,`${i} column "${s.meta.name}" (position) is not written; only node positions map to pos`,s.meta.name,s.length-s.nullCount)}}let XC=class{constructor(e,n,i){this.extraNotes=[],this.snapshot=e,this.resolved=n;const{indent:r,name:s,strict:o}=i??{};if(s!=null&&typeof s!="string")throw Z_("name",s,"a string or null");if(o!==void 0&&typeof o!="boolean")throw Z_("strict",o,"a boolean");this.indent=uT(r,OB),this.name=s===void 0?e.meta.name:s,this.strict=o??LB(e),this.mixed=yl(e),this.mixed>0&&n.onMixedDirection!=="error"?this.directed=n.onMixedDirection==="directed":this.directed=e.directed;const{nodes:l,edges:a,graph:c}=e;this.position=l.byRole("position"),this.positionDims=PB(this.position),this.parent=l.byRole("parent");const d=l.get(Cs);this.cluster=d!==null&&d.dtype==="bool"?d:null,this.edgeId=a.byRole("id"),this.weights=Ot(e),this.folding=Gt(e),this.sourcePort=a.byRole("sourcePort"),this.targetPort=a.byRole("targetPort"),this.nodeLabel=l.byRole("label"),this.edgeLabel=a.byRole("label"),this.nodeColumns=[...l].filter(f=>this.writesNodeColumn(f)),this.edgeColumns=[...a].filter(f=>this.writesEdgeColumn(f)),this.graphColumns=[...c].filter(f=>np(f)&&(f.meta.role===null||!$B.has(f.meta.role))),this.children=nc(e,{column:this.parent!==null&&this.parent.dtype==="u32"?this.parent:null}),this.nodeColumns=Q_(this.nodeColumns,this.nodeTextOrder());const u=[];for(let f=0;f<e.edgeCount;f++)this.folding.folded(f)||u.push(f);this.edgeColumns=Q_(this.edgeColumns,u)}nodeTextOrder(){const e=[],n=new Uint8Array(this.snapshot.nodeCount),i=[];for(let r=this.snapshot.nodeCount-1;r>=0;r--)i.push(r);for(;i.length>0;){const r=i.pop();if(r<0){e.push(-r-1);continue}if(n[r]===1)continue;n[r]=1,this.cluster!==null&&this.cluster.isSet(r)&&this.cluster.value(r)===!0?i.push(-r-1):e.push(r);const o=this.children.childrenOf(r);for(let l=o.length-1;l>=0;l--)i.push(o[l])}return e}writesNodeColumn(e){const{name:n,role:i}=e.meta;return!np(e)||n===Cs||EB.has(n)||i!==null&&TB.has(i)?!1:n===Xs&&i!=="position"?(this.clash("node",n,"the position role is written as pos"),!1):this.labelFree("node",e,this.nodeLabel)}writesEdgeColumn(e){const{name:n,role:i}=e.meta;return!np(e)||i!==null&&IB.has(i)?!1:n===vs&&this.edgeId!==null?(this.clash("edge",n,"the edge id role is written as key"),!1):n==="weight"?(this.clash("edge",n,"the weight is written as weight"),!1):this.labelFree("edge",e,this.edgeLabel)}labelFree(e,n,i){return n.meta.name!==Ue||i===null||i===n?!0:(this.clash(e,n.meta.name,"the label role is written as label"),!1)}clash(e,n,i){this.extraNotes.push(Object.freeze({code:Nn.ATTRIBUTE_CLASH,message:`${e} column "${n}" has no role and is not written: ${i}`,column:n,count:null}))}notes(){const e=[...this.extraNotes],n=(o,l,a=null,c=null)=>{e.push(Object.freeze({code:o,message:l,column:a,count:c}))},{snapshot:i}=this,r=this.countUnwritable();r>0&&n(Nn.TRAILING_BACKSLASH,`${r} ids, names or text values hold a backslash before a quote or a line break, or at the end, which a DOT quoted string cannot carry; the save fails`,null,r);for(const[o,l]of[["node",this.nodeColumns],["edge",this.edgeColumns],["graph",this.graphColumns]])for(const a of l)o==="graph"&&e.push(...wB(a)),kB(o,a,n);this.structureNotes(n),RB(i,this.position,n);const s=UB(i);return s>0&&n(Nn.ID_TEXT_TYPE,`${s} node id${O(s)} ${C(s,"reads","read")} back as the other type under ids: "canonical" (a string "1" becomes 1, a number 1.5 becomes "1.5")`,null,s),e}structureNotes(e){const{snapshot:n}=this;let i=0;for(let o=0;o<n.nodeCount;o++)!(this.cluster?.isSet(o)===!0&&this.cluster.value(o)===!0)&&this.children.childrenOf(o).length>0&&i++;i>0&&e(Nn.CLUSTER_MARKED,`${i} parent node${O(i)} ${C(i,"is","are")} written as a node and a cluster of the same name and read back with "${Cs}" true`,Cs,i);const r=this.folding.mutualCount;r>0&&e(Nn.MUTUAL_EXPANDED,`${r} mutual pair${O(r)} ${C(r,"is","are")} written as two directed edges each; the mutual mark is lost`,null,r);const s=n.nodes.byRole("parents");s!==null&&e(Nn.PARENTS_DROPPED,`node column "${s.meta.name}" (parents) cannot be written: a DOT node is in one cluster`,s.meta.name,s.length-s.nullCount)}refuse(){if(this.mixed>0&&this.resolved.onMixedDirection==="error")throw new N("E_DIRECTED",`${this.mixed} undirected edge${O(this.mixed)} in a directed graph, and DOT holds one direction per file, so the save fails unless onMixedDirection is "directed" or "undirected"`,{reason:w.MIXED_DIRECTION_ERROR,count:this.mixed});const e=this.firstUnwritable();if(e!==null)throw new N(e.kind==="id"?"E_INVALID_ID":"E_COLUMN_TYPE",`${e.kind} ${JSON.stringify(e.text)} holds a backslash before a quote or a line break, or at its end, which a DOT quoted string cannot carry`,{reason:"trailing backslash",kind:e.kind,value:e.text});wl(this.snapshot,Gb.idCharset,this.resolved.sanitizeIds)}countUnwritable(){let e=0;return this.forEachText(n=>{J_(n)&&e++}),e}firstUnwritable(){let e=null;return this.forEachText((n,i)=>{e===null&&J_(n)&&(e={kind:i,text:n})}),e}forEachText(e){const{snapshot:n}=this;this.name!==null&&e(this.name,"graph name");for(let i=0;i<n.nodeCount;i++){const r=n.ids.idOf(i);typeof r=="string"&&e(r,"id")}for(const i of[this.nodeColumns,this.edgeColumns,this.graphColumns])for(const r of i)if(e(this.attributeName(r),"attribute name"),r.dtype==="string"||r.dtype==="dict")for(let s=0;s<r.length;s++)r.isSet(s)&&e(r.value(s),"value");for(const i of[this.edgeId,this.sourcePort,this.targetPort])if(i!==null&&(i.dtype==="string"||i.dtype==="dict"))for(let r=0;r<i.length;r++)i.isSet(r)&&e(i.value(r),"value")}*write(){const{snapshot:e,indent:n}=this,i=this.directed?"digraph":"graph",r=this.name===null?"":` ${nr(this.name)}`;yield`${this.strict?"strict ":""}${i}${r} {
|
|
82
|
+
`;const s=this.attributesOf(this.graphColumns,0);s.length>0&&(yield`${n}graph [${s.join(", ")}];
|
|
83
|
+
`);const o=new Uint8Array(e.nodeCount);for(let l=0;l<e.nodeCount;l++)yield*this.writeNode(l,1,o);yield*this.writeRanks(),yield*this.writeEdges(),yield`}
|
|
84
|
+
`}*writeRanks(){const{nodes:e}=this.snapshot,n=e.get(Db),i=e.get(kb);if(n===null||i===null)return;const r=new Map;for(let o=0;o<this.snapshot.nodeCount;o++)if(n.isSet(o)&&i.isSet(o)){const l=String(i.value(o)),a=r.get(l)??{rank:String(n.value(o)),members:[]};a.members.push(Qi(this.idText(o))),r.set(l,a)}const s=o=>o.startsWith("%")?Number(o.slice(1)):-1;for(const[o,l]of[...r].sort(([a],[c])=>s(a)-s(c))){const a=o.startsWith("%")?"":`subgraph ${nr(o)} `;yield`${this.indent}${a}{ rank=${nr(l.rank)}; ${l.members.join("; ")}; }
|
|
85
|
+
`}}*writeNode(e,n,i){if(i[e]===1)return;i[e]=1;const r=this.indent.repeat(n),s=this.idText(e),o=this.children.childrenOf(e),l=this.cluster!==null&&this.cluster.isSet(e)&&this.cluster.value(e)===!0;if(o.length===0&&!l){yield`${r}${this.nodeStatement(e,s)};
|
|
86
|
+
`;return}l||(yield`${r}${this.nodeStatement(e,s)};
|
|
87
|
+
`);const a=`${r}${this.indent}`;if(yield`${r}subgraph ${Qi(s)} {
|
|
88
|
+
`,s.startsWith(NB)||(yield`${a}cluster=true;
|
|
89
|
+
`),l){const c=this.nodeAttributes(e);c.length>0&&(yield`${a}graph [${c.join(", ")}];
|
|
90
|
+
`)}for(const c of o)i[c]===1?yield`${a}${Qi(this.idText(c))};
|
|
91
|
+
`:yield*this.writeNode(c,n+1,i);yield`${r}}
|
|
92
|
+
`}nodeStatement(e,n){const i=this.nodeAttributes(e);return i.length===0?Qi(n):`${Qi(n)} [${i.join(", ")}]`}nodeAttributes(e){const n=this.attributesOf(this.nodeColumns,e),i=this.positionText(e);return i!==null&&n.push(`${Xs}=${nr(i)}`),n}positionText(e){const n=this.position;if(!n?.isSet(e)||n.dtype!=="f32"&&n.dtype!=="f64"&&n.dtype!=="i32")return null;const{components:i}=n.meta;if(i!==2&&i!==3)return null;const r=n.dtype==="f32"?ct:Fe,s=e*i,{data:o}=n,l=[r(o[s]),r(o[s+1])];return this.positionDims===3&&l.push(r(i===3?o[s+2]:0)),l.join(",")}attributeName(e){return e===this.nodeLabel||e===this.edgeLabel?Ue:e.meta.name}attributesOf(e,n){const i=[];for(const r of e){if(!r.isSet(n))continue;let s=ea(r,n);s!==null&&e===this.graphColumns&&KC(r)&&!YC.test(s)&&(s="UTF-8"),s!==null&&i.push(`${nr(this.attributeName(r))}=${Qi(s)}`)}return i}*writeEdges(){const{snapshot:e,indent:n}=this,i=e.edgeList(),r=this.directed?"->":"--";for(let s=0;s<e.edgeCount;s++){if(this.folding.folded(s))continue;const o=this.attributesOf(this.edgeColumns,s),l=this.weights.text(s);l!==null&&o.unshift(`weight=${nr(l)}`);const a=this.keyText(s);a!==null&&o.unshift(`${vs}=${Qi(a)}`);const c=`${Qi(this.idText(i.src[s]))}${this.portText(this.sourcePort,s)}`,d=`${Qi(this.idText(i.dst[s]))}${this.portText(this.targetPort,s)}`,u=o.length===0?"":` [${o.join(", ")}]`;yield`${n}${c} ${r} ${d}${u};
|
|
93
|
+
`}}keyText(e){const n=this.edgeId;return n?.isSet(e)?n.dtype==="f32"||n.dtype==="f64"?Fe(n.data[e]):ea(n,e):null}portText(e,n){if(!e?.isSet(n))return"";const i=ea(e,n);return i===null||i.length===0?"":DB(i)}idText(e){return Hi(this.snapshot.ids.idOf(e))}};function LB(t){const e=t.meta.extra[E7];return typeof e=="object"&&e!==null&&e.strict===!0}function PB(t){if(t===null)return 2;const e=t.meta.extra.sourceDims;return e===2||e===3?e:t.meta.components===2?2:3}function Q_(t,e){const n=new Set(t),i=[];for(const r of e){if(n.size===0)break;for(const s of t)n.has(s)&&s.isSet(r)&&ea(s,r)!==null&&(i.push(s),n.delete(s))}return[...i,...n]}function ea(t,e){switch(t.dtype){case"bool":return t.value(e)===!0?"true":"false";case"i32":case"u32":case"u8":return ip(t,e,Ge);case"f32":return ip(t,e,n=>Ar(n,"f32"));case"f64":return ip(t,e,n=>Ar(n,"f64"));case"dict":case"string":return t.value(e)??"";case"list":case"json":return null;default:{const n=t.dtype;throw new N("E_COLUMN_TYPE",`unknown dtype ${n}`,{dtype:n})}}}function ip(t,e,n){const{components:i}=t.meta;if(i===1)return n(t.data[e]);const r=[];for(let s=0;s<i;s++)r.push(n(t.data[e*i+s]));return r.join(",")}function xB(t){if(t.dtype!=="f32"&&t.dtype!=="f64")return 0;const{components:e}=t.meta;let n=0;for(let i=0;i<t.length;i++)if(t.isSet(i)){for(let r=0;r<e;r++)if(!Number.isFinite(t.data[i*e+r])){n++;break}}return n}function MB(t){if(t.dtype!=="string"&&t.dtype!=="dict")return 0;let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&qn(t.value(n)??"")!=="string"&&e++;return e}function UB(t){const{ids:e}=t;if(e.kind==="identity"||e.kind==="dense")return 0;let n=0;for(let i=0;i<e.size;i++){const r=e.idOf(i);tc(Hi(r))!==r&&n++}return n}const eS=72;function GB(t){if(t.nodes.byRole("position")===null)return null;const e=t.graph.get("bb"),n=e!==null&&e.isSet(0)&&qC(e.value(0))!==null,i=t.nodes.get("width"),r=[];for(let s=0;i!==null&&s<i.length;s++){const o=i.isSet(s)?Number(i.value(s)):Number.NaN;Number.isFinite(o)&&r.push(n?o*eS:o)}return{units:n?"px":"file",...n?{}:{pxPerUnit:eS},yAxis:"up",groups:jB(t),medianNodeSize:ny(r),...n?{tool:"graphviz"}:{}}}function jB(t){const e=t.nodes.get("bb"),n=[];for(let i=0;e!==null&&i<e.length;i++){const r=e.isSet(i)?qC(e.value(i)):null;r!==null&&n.push({node:i,box:r})}return n}function qC(t){if(typeof t!="string")return null;const e=t.split(",").map(Number);if(e.length!==4||!e.every(Number.isFinite))return null;const[n,i,r,s]=e;return{x:(n+r)/2,y:(i+s)/2,width:r-n,height:s-i}}class xe extends Error{constructor(e,n){super(e),this.name="DotSyntaxError",this.line=n}}const FB="";function Gg(t){return t>=65&&t<=90||t>=97&&t<=122||t===95||t>=128&&t!==jb}const jb=65279;function zB(t){return Gg(t)||ys(t)||t===jb}function ys(t){return t>=48&&t<=57}function WB(t){return t===32||t===9||t===11||t===12||t===jb}class JC{constructor(e,n=null){this.pos=0,this.line=1,this.lookahead=[],this.text=e,this.onAmbiguity=n}peek(e=0){for(;this.lookahead.length<=e;)this.lookahead.push(this.lex());return this.lookahead[e]}next(){return this.lookahead.shift()??this.lex()}lex(){this.skipTrivia();const{text:e}=this;if(this.pos>=e.length)return{kind:"eof",text:FB,quoted:!1,html:!1,line:this.line};const n=this.pos,{line:i}=this,r=e.charCodeAt(n);switch(r){case 123:case 125:case 91:case 93:case 59:case 44:case 61:case 58:case 43:return this.pos++,{kind:"punct",text:e[n],quoted:!1,html:!1,line:i};case 45:{const s=e.charCodeAt(n+1);if(s===62||s===45)return this.pos+=2,{kind:"punct",text:e.slice(n,n+2),quoted:!1,html:!1,line:i};if(ys(s)||s===46&&ys(e.charCodeAt(n+2)))return this.numeral(n,i);throw new xe("unexpected '-': not an edge operator or a numeral",i)}case 34:return this.quoted(n,i);case 60:return this.html(n,i)}if(Gg(r)){let s=n+1;for(;s<e.length&&zB(e.charCodeAt(s));)s++;return this.pos=s,{kind:"id",text:e.slice(n,s),quoted:!1,html:!1,line:i}}if(ys(r)||r===46&&ys(e.charCodeAt(n+1)))return this.numeral(n,i);throw new xe(`unexpected character ${JSON.stringify(e[n])}`,i)}numeral(e,n){const{text:i}=this;let r=e;for(i.charCodeAt(r)===45&&r++;r<i.length&&ys(i.charCodeAt(r));)r++;if(i.charCodeAt(r)===46)for(r++;r<i.length&&ys(i.charCodeAt(r));)r++;this.pos=r;const s=i.slice(e,r),o=i.charCodeAt(r);return r<i.length&&(Gg(o)||o===46)&&this.onAmbiguity!==null&&this.onAmbiguity(s,n),{kind:"id",text:s,quoted:!1,html:!1,line:n}}quoted(e,n){const{text:i}=this;let r="",s=e+1,o=e+1;for(;;){if(o>=i.length)throw new xe("unterminated quoted string (missing closing quote)",n);const l=i.charCodeAt(o);if(l===34)return r+=i.slice(s,o),this.pos=o+1,{kind:"id",text:r,quoted:!0,html:!1,line:n};l===92&&this.isQuotedSplice(o)?(r+=i.slice(s,o),i.codePointAt(o+1)===34&&(r+='"'),o=this.quotedSpliceEnd(o),s=o):o=this.quotedStep(o,l)}}isQuotedSplice(e){const n=this.text.codePointAt(e+1);return n===34||n===10||n===13}quotedSpliceEnd(e){const{text:n}=this,i=n.charCodeAt(e+1);return i===34?e+2:(this.line++,i===13&&n.codePointAt(e+2)===10?e+3:e+2)}quotedStep(e,n){const{text:i}=this;if(n===92)return i.codePointAt(e+1)===92?e+2:e+1;if(n===10)this.line++;else if(n===13)return this.line++,i.codePointAt(e+1)===10?e+2:e+1;return e+1}html(e,n){const{text:i}=this;let r=0;for(let s=e;s<i.length;s++){const o=i.charCodeAt(s);if(o===60)r++;else if(o===62){if(r--,r===0)return this.pos=s+1,{kind:"id",text:i.slice(e,s+1),quoted:!1,html:!0,line:n}}else(o===10||o===13&&i.charCodeAt(s+1)!==10)&&this.line++}throw new xe("unterminated HTML string (missing closing '>')",n)}skipTrivia(){const{text:e}=this;for(;this.pos<e.length;){const n=e.charCodeAt(this.pos);if(WB(n))this.pos++;else if(!this.skipBreakOrComment(n))return}}skipBreakOrComment(e){return e===10||e===13?(this.skipLineBreak(e),!0):e===47?this.skipComment():e===35&&this.pos===0?(this.skipToLineEnd(),!0):!1}skipLineBreak(e){this.line++,this.pos+=e===13&&this.text.codePointAt(this.pos+1)===10?2:1,this.skipPreprocessorLine()}skipComment(){const e=this.text.codePointAt(this.pos+1);return e===47?(this.skipToLineEnd(),!0):e===42?(this.skipBlockComment(),!0):!1}skipPreprocessorLine(){this.text.charCodeAt(this.pos)===35&&this.skipToLineEnd()}skipToLineEnd(){const{text:e}=this;for(;this.pos<e.length;){const n=e.charCodeAt(this.pos);if(n===10||n===13)return;this.pos++}}skipBlockComment(){const{text:e}=this,n=this.line;let i=this.pos+2;for(;i<e.length;i++){const r=e.charCodeAt(i);if(r===42&&e.charCodeAt(i+1)===47){this.pos=i+2;return}(r===10||r===13&&e.charCodeAt(i+1)!==10)&&this.line++}throw new xe("unterminated block comment",n)}}const ht=Object.freeze({...xn,...Pn,SYNTAX:kn,EMPTY_INPUT:Ut,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,ENCODING_CONFLICT:hl,NESTING:"E_DOT_NESTING",EDGE_OPERATOR:"W_DOT_EDGE_OPERATOR",MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,NUMERAL_AMBIGUITY:"W_DOT_NUMERAL_AMBIGUITY",SUBGRAPH_ATTRIBUTES_DROPPED:"W_DOT_SUBGRAPH_ATTRIBUTES_DROPPED",RANK_CONFLICT:"W_DOT_RANK_CONFLICT",NODE_PORT_DROPPED:"W_DOT_NODE_PORT_DROPPED",CLUSTER_NODE_MERGED:"W_DOT_CLUSTER_NODE_MERGED",CLUSTER_CONFLICT:"W_DOT_CLUSTER_CONFLICT",BAD_POS:"W_DOT_BAD_POS",POS_DIMS:"W_DOT_POS_DIMS",PRECISION:re,DUPLICATE_ATTRIBUTE:fe,COMPASS_POINT:"W_DOT_COMPASS_POINT",LATE_CHARSET:"W_DOT_LATE_CHARSET",STRICT_MERGED:"W_DOT_STRICT_MERGED",KEY_MERGED:"W_DOT_KEY_MERGED",ROLE_TAKEN:bn,COLUMN_RENAMED:ln,OPTION_IGNORED:Jt,ID_MERGED:Rn,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or,WIDENING_UNSUPPORTED:af}),tS=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","errorLimit","signal","onProgress"]),nS=1024,BB=Object.freeze([".dot",".gv"]),HB=Object.freeze(["text/vnd.graphviz"]),VB="cluster",iS="cluster",rS="rank",YB=new Set(["same","min","max","source","sink"]),KB=64,XB=4096,qB=new Set(["bgcolor","color","colorscheme","fillcolor","fontcolor","fontname","fontsize","gradientangle","label","labeljust","labelloc","pencolor","penwidth","peripheries","style","tooltip"]),JB=/^\s*(strict\s+)?(di)?graph(?=[\s{"/]|$)(?!\s*\[)/i,ZB=new Set(["true","yes","1"]),QB=new Set(["n","ne","e","se","s","sw","w","nw","c","_"]),rp=String.raw`[-+]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?`,eH=new RegExp(String.raw`^\s*(${rp})\s*,\s*(${rp})(?:\s*,\s*(${rp}))?\s*(?:(!)\s*)?$`),ZC=Object.freeze({format:$s,options:Object.freeze(["keepPositionSource","mismatchedEdgeOperator","positions"]),extensions:BB,mimeTypes:HB,styles:YW,positions:GB,sniff(t){const e=nH(new TextDecoder("utf-8").decode(t));return JB.exec(e)===null?0:e.includes("{")?.95:.8},async import(t,e,n){if(io(n))return vb(ZC,t,e,n);const i=tt(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=cS(n?.mismatchedEdgeOperator),s=new ne($s,i.errorLimit);St(n,s,tS),_t(e,n,s);const o={},l=await Kr(t,s,{...i,declaredEncoding:h=>o.charset=aS(h),declarationBytes:lS}),c=sS(l,{current:s}),d=Id(s,()=>c.next()),u=new dS(c,e,s,i,r,n?.positions!==!1,n?.keepPositionSource===!0);u.headCharset=o.charset;const f=oS(u,s,d);if(f.kind!=="eof"){const h=Id(s,()=>tH(c,f));s.warning("unsupported",Qn,`the input holds ${h} more graph${O(h)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)`,{line:f.line})}return F(i.signal),s.finish()},async importAll(t,e,n){const i=tt(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=cS(n?.mismatchedEdgeOperator),s=new ne($s,i.errorLimit);St(n,s,tS);const o={},l=await Kr(t,s,{...i,declaredEncoding:f=>o.charset=aS(f),declarationBytes:lS}),a={current:s},c=sS(l,a),d=[];let u=Id(s,()=>c.next());do{const f=d.length===0?s:new ne($s,i.errorLimit);a.current=f;const h=e(d.length);_t(h,n,f);const p=new dS(c,h,f,i,r,n?.positions!==!1,n?.keepPositionSource===!0);p.headCharset=o.charset,u=oS(p,f,u),F(i.signal),d.push(f.finish())}while(u.kind!=="eof");return d}});function sS(t,e){return new JC(t,(n,i)=>{e.current.warning("validation-error",ht.NUMERAL_AMBIGUITY,`badly delimited number ${JSON.stringify(n)} splits into two tokens (Graphviz warns the same)`,{line:i,element:n})})}function Id(t,e){try{return e()}catch(n){throw n instanceof xe&&t.fail(kn,n.message,{line:n.line},{line:n.line}),n}}function oS(t,e,n){return Id(e,()=>t.parse(n))}function tH(t,e){let n=0,i=e;for(;i.kind!=="eof";){if(xi(i,"strict")&&(i=t.next()),Ie(i,"}"))throw new xe('unexpected "}" after the end of the graph: no "{" is open',i.line);if(!xi(i,"graph")&&!xi(i,"digraph"))throw new xe(`expected "graph" or "digraph", found ${ui(i)}`,i.line);if(i=t.next(),i.kind==="id"&&(i=t.next()),!Ie(i,"{"))throw new xe(`expected "{" after the graph header, found ${ui(i)}`,i.line);for(let r=1;r>0;){if(i=t.next(),i.kind==="eof")throw new xe('missing "}" at the end of a graph',i.line);Ie(i,"{")?r++:Ie(i,"}")&&r--}n++,i=t.next()}return n}const lS=64*1024;function aS(t){const e=new JC(t);let n=null,i=null;try{let r=e.next();for(;r.kind!=="eof";){if(Ie(r,"["))n=i!==null&&xi(i,"graph")?"graph":"other";else if(Ie(r,"]"))n=null;else if(n!=="other"&&xi(r,"charset")){const s=e.next(),o=Ie(s,"=")?e.next():s;if(o!==s&&o.kind==="id")return o.text.replace(/^(latin|big)-/i,"$1");r=o}i=r,r=e.next()}}catch(r){if(!(r instanceof xe))throw r}return null}function cS(t){if(t===void 0)return"operator";if(t==="operator"||t==="header"||t==="error")return t;throw new N("E_UNSUPPORTED",`option mismatchedEdgeOperator: ${JSON.stringify(t)} is not one of "operator", "header", "error"`,{option:"mismatchedEdgeOperator",found:t,supported:["operator","header","error"]})}function nH(t){let e=t;for(;;){const n=e.replace(/^\s+/,"");if(n.startsWith("//")||n.startsWith("#")){const i=n.search(/[\r\n]/);if(i<0)return"";e=n.slice(i);continue}if(n.startsWith("/*")){const i=n.indexOf("*/");if(i<0)return"";e=n.slice(i+2);continue}return n}}function xi(t,e){return t.kind==="id"&&!t.quoted&&!t.html&&t.text.toLowerCase()===e}function Ie(t,e){return t.kind==="punct"&&t.text===e}function Hc(t){return t.kind==="punct"&&(t.text==="->"||t.text==="--")}function ui(t){return t.kind==="eof"?"end of input":JSON.stringify(t.text.length>40?`${t.text.slice(0,40)}...`:t.text)}function iH(t){return t?.startsWith(VB)===!0}class dS{constructor(e,n,i,r,s,o,l){this.directed=!0,this.strict=!1,this.statements=0,this.idOf=new Map,this.containers=new Set,this.parentOf=new Map,this.inherited=new Map,this.ownAttributes=new Map,this.conflictWarned=new Set,this.strictEdges=new Map,this.keyedEdges=new Map,this.nodeLabelHandle=A,this.edgeLabelHandle=A,this.positionHandle=A,this.clusterHandle=A,this.parentHandle=A,this.keyHandle=A,this.sourcePortHandle=A,this.targetPortHandle=A,this.rankHandle=A,this.rankSetHandle=A,this.rankSetOf=new Map,this.anonymousRanks=0,this.depth=0,this.posDims=0,this.headCharset=void 0,this.nodeWriters=new Map,this.edgeWriters=new Map,this.lexer=e,this.sink=n,this.report=i,this.options=r,this.mismatch=s,this.positions=o,this.keepPositionSource=l,this.ids=new Mn(r.ids),this.resolver=new ei(n,i,r.onMixedDirection)}parse(e){const{lexer:n}=this;let i=e;if(i.kind==="eof"&&this.report.fail(Ut,"the input holds no graph (empty or only comments)",{line:i.line}),xi(i,"strict")&&(this.strict=!0,i=n.next()),xi(i,"digraph"))this.directed=!0;else if(xi(i,"graph"))this.directed=!1;else throw new xe(`expected "graph" or "digraph", found ${ui(i)}`,i.line);const r=i.line;i=n.next();let s=null;if(i.kind==="id"&&(s=i.text,i=n.next()),!Ie(i,"{"))throw new xe(`expected "{" after the graph header, found ${ui(i)}`,i.line);this.resolver.setHeader(this.directed,{line:r}),this.sink.setMeta({name:s,sourceFormat:$s,...this.strict?{extra:{dot:{strict:!0}}}:{}});const o=this.newScope(null,r,!0,null);return this.statementList(o),this.applyInherited(),n.next()}newScope(e,n,i,r){return{root:i,name:r,line:n,nodeDefaults:new Map(e?.nodeDefaults),edgeDefaults:new Map(e?.edgeDefaults),members:[],memberSet:new Set,containers:[],attributes:new Map,graphDefaults:new Map(e?.graphDefaults),cluster:!1,container:A}}statementList(e){const{lexer:n}=this;for(;;){const i=n.peek();if(Ie(i,"}")){n.next();return}if(i.kind==="eof")throw new xe(e.root?'unexpected end of input: missing "}" closing the graph':`unexpected end of input: missing "}" closing the subgraph opened on line ${e.line}`,i.line);if(Ie(i,";")){n.next();continue}this.statement(e),++this.statements%KB===0&&F(this.options.signal)}}statement(e){const{lexer:n}=this,i=n.peek();if(i.kind==="punct"){if(i.text==="{"){const r=this.subgraph(e);this.maybeEdgeStatement(e,r,i.line);return}throw new xe(`unexpected ${ui(i)} at the start of a statement`,i.line)}!i.quoted&&!i.html&&this.keywordStatement(e,i)||this.idStatement(e)}keywordStatement(e,n){const i=n.text.toLowerCase();if(i==="node"||i==="edge"||i==="graph")return this.lexer.next(),this.attributeStatement(e,i,n.line),!0;if(i==="subgraph"){const r=this.subgraph(e);return this.maybeEdgeStatement(e,r,n.line),!0}if(i==="digraph"||i==="strict")throw new xe(`unexpected keyword ${ui(n)} inside a graph`,n.line);return!1}idStatement(e){const{lexer:n}=this,i=this.identifier();if(Ie(n.peek(),"=")){n.next();const s=this.identifier();this.scopeAttribute(e,{name:i.text,value:s.text,line:i.line});return}const r=this.port();if(Ie(n.peek(),",")){this.nodeListStatement(e,[{id:i,port:r},...this.moreNodes()]);return}if(Hc(n.peek())){const s=this.mentionEndpoint(e,i,r);this.edgeStatement(e,s===null?[]:[s],i.line);return}this.nodeStatement(e,i,r)}moreNodes(){const e=[];for(;Ie(this.lexer.peek(),",");){this.lexer.next();const n=this.identifier();e.push({id:n,port:this.port()})}return e}nodeListStatement(e,n){if(Hc(this.lexer.peek())){this.edgeStatement(e,this.mentionAll(e,n),n[0].id.line);return}const i=this.attributeList();for(const r of n)this.applyNodeStatement(e,r.id,r.port,i)}identifier(){const{lexer:e}=this,n=e.next();if(n.kind!=="id")throw new xe(`expected an identifier, found ${ui(n)}`,n.line);if(!n.quoted||!Ie(e.peek(),"+"))return n;let{text:i}=n;for(;Ie(e.peek(),"+");){const r=e.next(),s=e.next();if(s.kind!=="id"||!s.quoted)throw new xe(`expected a quoted string after "+", found ${ui(s)}`,s.kind==="eof"?r.line:s.line);i+=s.text}return{kind:"id",text:i,quoted:!0,html:!1,line:n.line}}port(){const{lexer:e}=this;if(!Ie(e.peek(),":"))return null;e.next();let{text:n}=this.identifier();if(Ie(e.peek(),":")){e.next();const i=this.identifier();n+=`:${i.text}`,QB.has(i.text)||this.report.warning("validation-error",ht.COMPASS_POINT,`port ${JSON.stringify(n)}: ${JSON.stringify(i.text)} is not a compass point (n, ne, e, se, s, sw, w, nw, c, _); the port is kept as written`,{line:i.line,element:n})}return n}subgraph(e){const{lexer:n}=this;let i=n.next(),r=null;if(xi(i,"subgraph")&&(i=n.next(),i.kind==="id"&&(r=i.text,i=n.next())),!Ie(i,"{"))throw new xe(`expected "{" to open a subgraph, found ${ui(i)}`,i.line);++this.depth>nS&&this.report.fail(ht.NESTING,`subgraphs nested deeper than ${nS} levels (the parser recurses per level)`,{line:i.line});const s=this.newScope(e,i.line,!1,r);return iH(r)&&(s.cluster=!0,this.ensureContainer(s)),this.statementList(s),this.depth--,this.closeScope(s,e),s.members.map(o=>({id:this.idOf.get(o)??o,index:o,port:null}))}closeScope(e,n){const{container:i}=e;if(i===A?this.closePlainSubgraph(e,n):this.closeCluster(e,n,i),!n.root)for(const r of e.members)n.memberSet.has(r)||(n.memberSet.add(r),n.members.push(r))}closeCluster(e,n,i){const r=this.ownAttributes.get(i)??new Set;this.ownAttributes.set(i,r);for(const s of e.attributes.values())s.name!==iS&&(r.add(s.name),this.setNodeAttribute(i,s.name,s.value,s.line));for(const s of e.containers)s!==i&&!this.parentOf.has(s)&&this.setParent(s,i);for(const s of e.members)s!==i&&this.adoptMember(s,i,e.line);n.containers.push(i)}adoptMember(e,n,i){const r=this.parentOf.get(e);r===void 0?this.setParent(e,n):r!==n&&!this.isAncestor(n,r)&&this.clusterConflict(e,r,n,i)}closePlainSubgraph(e,n){const i=this.recordRank(e),r=[...e.attributes.keys()].filter(s=>!(i&&s===rS));if(r.length>0){const s=r.join(", ");this.report.warning("unsupported",ht.SUBGRAPH_ATTRIBUTES_DROPPED,`subgraph ${e.name===null?"(anonymous)":JSON.stringify(e.name)} is not a cluster; its attributes (${s}) cannot be represented and were dropped`,{line:e.line,element:e.name})}for(const s of e.containers)n.containers.push(s)}applyInherited(){for(const[e,n]of this.inherited){const i=this.ownAttributes.get(e);for(const r of n.values())i?.has(r.name)!==!0&&this.setNodeAttribute(e,r.name,r.value,r.line)}}isAncestor(e,n){let i=n;for(let r=0;i!==void 0&&r<XB;r++){if(i===e)return!0;i=this.parentOf.get(i)}return!1}clusterConflict(e,n,i,r){if(this.conflictWarned.has(e))return;this.conflictWarned.add(e);const s=this.idOf.get(e)??e;this.report.warning("coercion",ht.CLUSTER_CONFLICT,`node ${JSON.stringify(s)} is in cluster ${JSON.stringify(this.idOf.get(n)??n)} and in cluster ${JSON.stringify(this.idOf.get(i)??i)}; the first is kept`,{line:r,element:String(s)})}setParent(e,n){if(e!==n)try{this.sink.setNodeValue(this.parentColumn(),e,n),this.parentOf.set(e,n)}catch(i){this.report.recordError(i,{element:String(this.idOf.get(e)??e)})}}ensureContainer(e){if(e.container!==A||e.name===null)return;const n=this.coerceId(e.name,e.line);if(n===null)return;let i=this.sink.indexOf(n);try{i===A?(i=this.sink.addNode(n),this.report.counts.nodes++):this.containers.has(i)||this.report.warning("coercion",ht.CLUSTER_NODE_MERGED,`cluster ${JSON.stringify(e.name)} and the node of the same name were merged into one container node`,{line:e.line,element:e.name}),this.idOf.set(i,n),this.containers.has(i)||(this.containers.add(i),this.sink.setNodeValue(this.clusterColumn(),i,!0),this.inherited.set(i,new Map(e.graphDefaults))),e.container=i}catch(r){this.report.recordError(r,{line:e.line,element:e.name}),i===A&&this.report.counts.skippedNodes++}}scopeAttribute(e,n){if(qB.has(n.name)&&e.graphDefaults.set(n.name,n),e.root){this.setGraphAttribute(n);return}e.attributes.set(n.name,n),n.name===iS&&ZB.has(n.value.trim().toLowerCase())&&(e.cluster=!0,this.ensureContainer(e))}attributeStatement(e,n,i){if(!Ie(this.lexer.peek(),"[")){const s=this.lexer.peek();throw new xe(`expected "[" after "${n}", found ${ui(s)}`,s.line)}const r=this.attributeList();switch(n){case"node":for(const s of r)e.nodeDefaults.set(s.name,s.value);break;case"edge":for(const s of r)e.edgeDefaults.set(s.name,s.value);break;case"graph":for(const s of r)this.scopeAttribute(e,s);break;default:throw new xe(`unknown attribute statement "${n}"`,i)}}attributeList(){const{lexer:e}=this,n=[],i=new Set;for(;Ie(e.peek(),"[");)for(e.next();;){const r=e.peek();if(Ie(r,"]")){e.next();break}if(Ie(r,";")||Ie(r,",")){e.next();continue}const s=this.identifier(),o=e.next();if(!Ie(o,"="))throw new xe(`expected "=" after attribute name ${JSON.stringify(s.text)}, found ${ui(o)}`,o.line);const l=this.identifier();i.has(s.text)&&this.report.warning("merged",ht.DUPLICATE_ATTRIBUTE,`attribute ${JSON.stringify(s.text)} is set twice in one statement; the last value ${JSON.stringify(l.text)} stands`,{line:s.line,element:s.text}),i.add(s.text),n.push({name:s.text,value:l.text,line:s.line})}return n}nodeStatement(e,n,i){this.applyNodeStatement(e,n,i,this.attributeList())}applyNodeStatement(e,n,i,r){const s=this.mentionEndpoint(e,n,null);if(s!==null){i!==null&&this.report.warning("unsupported",ht.NODE_PORT_DROPPED,`port ${JSON.stringify(i)} on the node statement of ${JSON.stringify(n.text)} has no meaning and was dropped`,{line:n.line,element:n.text});for(const o of r)this.setNodeAttribute(s.index,o.name,o.value,o.line)}}maybeEdgeStatement(e,n,i){Hc(this.lexer.peek())&&this.edgeStatement(e,n,i)}edgeStatement(e,n,i){const{lexer:r}=this,s=[n],o=[];for(;Hc(r.peek());){const a=r.next();o.push(this.edgeKind(a));const c=r.peek();if(Ie(c,"{")||xi(c,"subgraph"))s.push(this.subgraph(e));else{const d=this.identifier();s.push(this.mentionAll(e,[{id:d,port:this.port()},...this.moreNodes()]))}}const l=this.attributeList();for(let a=0;a<o.length;a++){const c=s[a+1];for(const d of s[a])for(const u of c)this.pushEdge(e,d,u,o[a],l,i)}}mentionAll(e,n){const i=[];for(const r of n){const s=this.mentionEndpoint(e,r.id,r.port);s!==null&&i.push(s)}return i}edgeKind(e){const n=e.text==="->";if(n===this.directed)return n?"directed":"undirected";const i=`edge operator "${e.text}" in a ${this.directed?"digraph":"graph"}`;switch(this.mismatch){case"error":throw new xe(`${i} (mismatchedEdgeOperator: "error")`,e.line);case"header":return this.report.warnOnce("coercion",ht.EDGE_OPERATOR,`${i}; read with the graph's direction (mismatchedEdgeOperator: "header")`,{line:e.line}),this.directed?"directed":"undirected";case"operator":return this.report.warnOnce("coercion",ht.EDGE_OPERATOR,`${i}; read with the operator's direction, and onMixedDirection decides how the mixed graph is stored`,{line:e.line}),n?"directed":"undirected";default:{const r=this.mismatch;throw new N("E_UNSUPPORTED",`unknown mismatchedEdgeOperator ${r}`,{found:r})}}}coerceId(e,n){try{const i=this.ids.text(e),r=this.ids.lastMerge;return r!==null&&this.report.warning("coercion",ht.ID_MERGED,`id text ${JSON.stringify(r.text)} merged with ${JSON.stringify(r.previousText)} as ${r.id} under ids: "number"`,{line:n,element:e}),i}catch(i){return this.report.recordError(i,{line:n,element:e}),this.report.counts.skippedNodes++,null}}mentionEndpoint(e,n,i){const r=this.coerceId(n.text,n.line);if(r===null)return null;const{sink:s}=this;let o=s.indexOf(r);if(o===A){try{o=s.addNode(r)}catch(l){return this.report.recordError(l,{line:n.line,element:n.text}),this.report.counts.skippedNodes++,null}this.report.counts.nodes++,this.idOf.set(o,r);for(const[l,a]of e.nodeDefaults)this.setNodeAttribute(o,l,a,n.line)}else this.idOf.has(o)||this.idOf.set(o,r);return!e.root&&!e.memberSet.has(o)&&(e.memberSet.add(o),e.members.push(o)),{id:r,index:o,port:i}}pushEdge(e,n,i,r,s,o){const l=new Map(e.edgeDefaults);for(const b of s)l.set(b.name,b.value);const a=`${String(n.id)} ${r==="directed"?"->":"--"} ${String(i.id)}`,c={line:o,element:a},{weightFrom:d}=this.options;let u;const f=d===null?void 0:l.get(d);if(f!==void 0)try{u=Kn(f,this.report)}catch(b){this.report.recordError(b,c),this.report.counts.skippedEdges++;return}const h=l.get(vs),p=this.dedupeKey(n.index,i.index,r,h);if(p!==null){const b=(this.strict?this.strictEdges:this.keyedEdges).get(p);if(b!==void 0){this.mergeEdge(b,u,l,c,h),this.setPorts(b,n,i,c);return}}const{sink:g}=this,m=g.edgeCount;let y;try{y=this.resolver.addEdge(n.id,i.id,r,u,c)}catch(b){this.report.recordError(b,c),this.report.counts.skippedEdges++;return}this.report.counts.edges+=g.edgeCount-m,p!==null&&(this.strict?this.strictEdges:this.keyedEdges).set(p,y);for(const[b,_]of l)b!==d&&this.setEdgeAttribute(y,b,_,o,a);this.setPorts(y,n,i,c)}setPorts(e,n,i,r){n.port!==null&&this.setPort(e,"source",n.port,r),i.port!==null&&this.setPort(e,"target",i.port,r)}dedupeKey(e,n,i,r){const s=i==="undirected"&&n<e?`${n}>${e}`:`${e}>${n}`;return this.strict?s:r===void 0?null:`${s}#${r}`}mergeEdge(e,n,i,r,s){const o=!this.strict&&s!==void 0;this.report.warning("merged",o?ht.KEY_MERGED:ht.STRICT_MERGED,o?`edge ${r.element} with key ${JSON.stringify(s)} repeats an earlier edge; attributes merged`:`parallel edge ${r.element} merged into the earlier one (strict graph)`,r);try{n!==void 0&&this.sink.setEdgeWeight(e,n)}catch(l){this.report.recordError(l,r)}for(const[l,a]of i)l!==this.options.weightFrom&&this.setEdgeAttribute(e,l,a,r.line,r.element)}setNodeAttribute(e,n,i,r){const s=String(this.idOf.get(e)??e);try{n===Ue?this.sink.setNodeValue(this.nodeLabel(),e,i):n===Xs&&this.positions?(this.setPosition(e,i,r,s),this.keepPositionSource&&this.textWriter("node",n).write(e,i)):this.textWriter("node",n).write(e,i)}catch(o){this.report.recordError(o,{line:r,element:s})}}setEdgeAttribute(e,n,i,r,s){try{n===Ue?this.setEdgeText(this.edgeLabel(),e,i):n===vs?this.setEdgeText(this.keyColumn(),e,i):this.textWriter("edge",n).write(e,i)}catch(o){this.report.recordError(o,{line:r,element:s})}}setGraphAttribute(e){e.name.toLowerCase()==="charset"&&this.headCharset===null&&Yl(e.value)!=="utf-8"&&this.report.warning("unsupported",ht.LATE_CHARSET,`charset ${JSON.stringify(e.value)} is declared beyond the first 1024 bytes, after the input was decoded without it; pass the encoding option to decode it as declared`,{line:e.line,element:e.name});try{e.name===Ue?this.sink.setGraphValue(e.name,e.value,{dtype:"string",origin:ai}):this.sink.setGraphValue(e.name,lf(e.value),{dtype:qn(e.value),origin:ai})}catch(n){this.report.recordError(n,{line:e.line,element:e.name})}}setPosition(e,n,i,r){const s=eH.exec(n);if(s===null){this.report.warning("validation-error",ht.BAD_POS,`pos ${JSON.stringify(n)} is not a point "x,y[,z][!]"; dropped`,{line:i,element:r});return}const o=Number(s[1]),l=Number(s[2]),a=s[3]===void 0?0:Number(s[3]),c=s[3]===void 0?2:3,d=[o,l,a];if(d.some(u=>!Number.isFinite(u))){this.report.warning("validation-error",ht.BAD_POS,`pos ${JSON.stringify(n)} has a coordinate that is not finite; dropped`,{line:i,element:r});return}this.posDims===0?this.posDims=c:c!==this.posDims&&this.report.warnOnce("validation-error",ht.POS_DIMS,`pos values mix ${this.posDims} and ${c} coordinates; the position column records sourceDims ${this.posDims}`,{line:i,element:r}),this.sink.setNodeValue(this.positionColumn(c),e,d),s[4]==="!"&&this.sink.setNodeValue(b7,e,!0)}setPort(e,n,i,r){try{this.setEdgeText(n==="source"?this.sourcePortColumn():this.targetPortColumn(),e,i)}catch(s){this.report.recordError(s,r)}}setEdgeText(e,n,i){this.sink.setEdgeValue(e,n,i)}nodeLabel(){return this.nodeLabelHandle===A&&(this.nodeLabelHandle=this.declare("node",{name:Ue,dtype:"string",nullable:!0,role:"label",origin:ai})),this.nodeLabelHandle}edgeLabel(){return this.edgeLabelHandle===A&&(this.edgeLabelHandle=this.declare("edge",{name:Ue,dtype:"string",nullable:!0,role:"label",origin:ai})),this.edgeLabelHandle}positionColumn(e){return this.positionHandle===A&&(this.positionHandle=this.declare("node",{name:this.keepPositionSource?y7:Xs,dtype:"f64",components:3,nullable:!0,mutable:!0,role:"position",origin:{...ai,type:"point"},extra:{sourceDims:e,units:"file"}})),this.positionHandle}recordRank(e){const n=e.attributes.get(rS)?.value.trim();if(n===void 0||!YB.has(n))return!1;const i=e.name??`%${this.anonymousRanks++}`;for(const r of e.members){const s=this.rankSetOf.get(r),o=String(this.idOf.get(r)??r);if(s===void 0){this.rankSetOf.set(r,i);try{this.sink.setNodeValue(this.stringColumn("rankHandle",Db),r,n),this.sink.setNodeValue(this.stringColumn("rankSetHandle",kb),r,i)}catch(l){this.report.recordError(l,{element:o})}}else s!==i&&this.report.warning("coercion",ht.RANK_CONFLICT,`node ${JSON.stringify(o)} is in rank subgraph ${JSON.stringify(s)} and in rank subgraph ${JSON.stringify(i)}; the first is kept`,{line:e.line,element:o})}return!0}stringColumn(e,n){return this[e]===A&&(this[e]=this.declare("node",{name:n,dtype:"string",nullable:!0,origin:ai})),this[e]}clusterColumn(){return this.clusterHandle===A&&(this.clusterHandle=this.declare("node",{name:Cs,dtype:"bool",nullable:!0,origin:ai})),this.clusterHandle}parentColumn(){return this.parentHandle===A&&(this.parentHandle=this.declare("node",{name:aC,dtype:"u32",nullable:!0,role:"parent",refersTo:"node",origin:ai})),this.parentHandle}keyColumn(){return this.keyHandle===A&&(this.keyHandle=this.declare("edge",{name:vs,dtype:"string",nullable:!0,role:"id",origin:{...ai,id:vs}})),this.keyHandle}sourcePortColumn(){return this.sourcePortHandle===A&&(this.sourcePortHandle=this.declare("edge",{name:cC,dtype:"string",nullable:!0,role:"sourcePort",origin:ai})),this.sourcePortHandle}targetPortColumn(){return this.targetPortHandle===A&&(this.targetPortHandle=this.declare("edge",{name:dC,dtype:"string",nullable:!0,role:"targetPort",origin:ai})),this.targetPortHandle}textWriter(e,n){const i=e==="node"?this.nodeWriters:this.edgeWriters;let r=i.get(n);return r===void 0&&(r=new Sy(n,e,this.sink,this.report),i.set(n,r)),r}declare(e,n){const i=n.origin?.id===void 0?{...n,origin:{...n.origin,id:n.name}}:n;return he(this.sink,e,i,this.report,{element:n.name}).handle}}const Mi="gexf",rH={"1.2":{gexf:"http://www.gexf.net/1.2draft",viz:"http://www.gexf.net/1.2draft/viz"},"1.3":{gexf:"http://gexf.net/1.3",viz:"http://gexf.net/1.3/viz"}},sH=new Set(["integer","double","date","dateTime"]),oH=new Set(["static","dynamic","slice"]),lH=new Set(["interval","timestamp"]),jf="viz",Xe={format:Mi},jr={format:Mi,namespace:jf},ce=Object.freeze({label:"label",parent:"parent",parents:"parents",start:"start",end:"end",timestamp:"timestamp",spells:"spells",spellsOpen:"spells.open",timestamps:"timestamps",open:"open",position:"position",color:"color",size:"size",shape:"shape",shapeUri:"shape.uri"}),Tt=Object.freeze({id:"id",label:"label",kind:"kind",start:"start",end:"end",timestamp:"timestamp",spells:"spells",spellsOpen:"spells.open",timestamps:"timestamps",open:"open",color:"color",thickness:"thickness",shape:"shape"}),QC=new Set([...Object.values(ce),ce.start+Wi,ce.end+Wi,ce.timestamp+Wi]),ev=new Set([...Object.values(Tt),Tt.start+Wi,Tt.end+Wi,Tt.timestamp+Wi]),Ft={label:{name:ce.label,dtype:"string",role:"label",nullable:!0,origin:Xe},parent:{name:ce.parent,dtype:"u32",role:"parent",refersTo:"node",nullable:!0,origin:Xe},parents:{name:ce.parents,dtype:"list",itemDtype:"u32",role:"parents",refersTo:"node",nullable:!0,origin:Xe},start:{name:ce.start,dtype:"f64",role:"start",nullable:!0,origin:Xe},end:{name:ce.end,dtype:"f64",role:"end",nullable:!0,origin:Xe},timestamp:{name:ce.timestamp,dtype:"f64",role:"timestamp",nullable:!0,origin:Xe},spells:{name:ce.spells,dtype:"list",itemDtype:"f64",itemComponents:2,role:"spells",nullable:!0,origin:Xe},timestamps:{name:ce.timestamps,dtype:"list",itemDtype:"f64",role:"timestamps",nullable:!0,origin:Xe},open:{name:ce.open,dtype:"u8",role:"open",nullable:!0,origin:Xe},spellsOpen:{name:ce.spellsOpen,dtype:"list",itemDtype:"u8",role:"spellsOpen",nullable:!0,origin:Xe},position:{name:ce.position,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,origin:jr,extra:{units:"file",originUnplaced:!0}},color:{name:ce.color,dtype:"f32",components:4,role:"color",nullable:!0,origin:jr},size:{name:ce.size,dtype:"f32",role:"size",nullable:!0,origin:jr},shape:{name:ce.shape,dtype:"dict",role:"shape",nullable:!0,origin:jr},shapeUri:{name:ce.shapeUri,dtype:"string",nullable:!0,origin:jr}},_n={id:{name:Tt.id,dtype:"string",role:"id",unique:!0,nullable:!0,origin:Xe},label:{name:Tt.label,dtype:"string",role:"label",nullable:!0,origin:Xe},kind:{name:Tt.kind,dtype:"dict",role:"kind",nullable:!0,origin:Xe},start:{name:Tt.start,dtype:"f64",role:"start",nullable:!0,origin:Xe},end:{name:Tt.end,dtype:"f64",role:"end",nullable:!0,origin:Xe},timestamp:{name:Tt.timestamp,dtype:"f64",role:"timestamp",nullable:!0,origin:Xe},spells:{name:Tt.spells,dtype:"list",itemDtype:"f64",itemComponents:2,role:"spells",nullable:!0,origin:Xe},timestamps:{name:Tt.timestamps,dtype:"list",itemDtype:"f64",role:"timestamps",nullable:!0,origin:Xe},open:{name:Tt.open,dtype:"u8",role:"open",nullable:!0,origin:Xe},spellsOpen:{name:Tt.spellsOpen,dtype:"list",itemDtype:"u8",role:"spellsOpen",nullable:!0,origin:Xe},color:{name:Tt.color,dtype:"f32",components:4,role:"color",nullable:!0,origin:jr},thickness:{name:Tt.thickness,dtype:"f32",role:"thickness",nullable:!0,origin:jr},shape:{name:Tt.shape,dtype:"dict",role:"shape",nullable:!0,origin:jr}},Ff=1,zf=2,jg="temporal:",Me=Object.freeze({element:"element",start:"start",end:"end",value:"value",open:"open",startText:`start${Wi}`,endText:`end${Wi}`,valueText:`value${Wi}`});function Fg(t,e){return`${jg}${t}:${e}`}function aH(t){if(!t.startsWith(jg))return null;const e=t.slice(jg.length),n=e.indexOf(":");if(n<0)return null;const i=e.slice(0,n);return i!=="node"&&i!=="edge"?null:{domain:i,column:e.slice(n+1)}}function uS(t,e,n){const i=[{name:Me.element,dtype:"u32",refersTo:t,nullable:!1},{name:Me.start,dtype:"f64",role:"start",nullable:!0},{name:Me.end,dtype:"f64",role:"end",nullable:!0},{name:Me.value,...e,nullable:!0},{name:Me.startText,dtype:"string",role:XA,nullable:!0,extra:{for:Me.start}},{name:Me.endText,dtype:"string",nullable:!0,extra:{for:Me.end}},{name:Me.open,dtype:"u8",role:"open",nullable:!0}];return n&&i.push({name:Me.valueText,dtype:"string",nullable:!0,extra:{for:Me.value}}),i}const tv=new Set(["integer","long","double","float","boolean","string","anyURI"]),cH=new Set([...tv,"bigdecimal","biginteger","byte","char","short","date","dateTime"]);function $d(t,e){return(e==="1.2"?tv:cH).has(t)}function dH(t,e){return t.startsWith("list")&&t.length>4&&$d(t.slice(4),"1.3")}function fS(t){switch(t){case"bool":return"boolean";case"i32":case"u8":return"integer";case"u32":return"long";case"f32":return"float";case"f64":return"double";case"dict":case"string":case"json":case"list":return"string";default:return t}}const uH=[318,401,460,838,636,950,780,275,390,390,500,838,318,361,318,337,636,636,636,636,636,636,636,636,636,636,337,337,838,838,838,531,1e3,684,686,698,770,632,575,775,752,295,295,656,557,863,748,787,603,787,695,635,611,732,684,989,685,611,685,390,337,390,838,500,500,613,635,550,635,615,352,635,634,278,278,579,278,974,634,612,635,635,411,521,392,634,592,818,592,592,525,636,337,636,838],fH=[318,401,636,636,636,636,337,500,500,1e3,471,612,838,361,1e3,500,500,838,401,401,500,636,636,318,500,401,471,612,969,969,969,531,684,684,684,684,684,684,974,698,632,632,632,632,295,295,295,295,775,748,787,787,787,787,787,838,787,732,732,732,732,611,605,630,613,613,613,613,613,613,982,550,615,615,615,615,278,278,278,278,612,634,612,612,612,612,612,838,612,634,634,634,634,592,635,592,684,613,684,613,684,613,698,550,698,550,698,550,698,550,770,635,775,635,632,615,632,615,632,615,632,615,632,615,775,635,775,635,775,635,775,635,752,634,916,695,295,278,295,278,295,278,295,278,295,278,590,556,295,278,656,579,579,557,278,557,278,557,375,557,342,562,284,748,634,748,634,748,634,813,748,634,787,612,787,612,787,612,1070,1023,695,411,695,411,695,411,635,521,635,521,635,521,635,521,611,392,611,392,611,392,732,634,732,634,732,634,732,634,732,634,732,634,989,818,611,592,611,685,525,685,525,685,525,352,635,735,686,635,686,635,703,698,550,775,819,686,635,612,632,787,614,575,352,775,687,984,354,295,746,579,278,592,974,748,634,787,913,612,949,759,652,635,695,635,521,632,336,392,611,392,611,858,634,764,721,744,730,685,525,666,666,578,525,636,666,578,510,635,295,492,459,295,1422,1299,1154,835,787,457,931,924,797,684,613,295,278,787,612,732,634,732,634,732,634,732,634,732,634,615,684,613,684,613,974,982,775,635,775,635,656,579,787,612,787,612,666,578,278,1422,1299,1154,775,635,1113,682,748,634,684,613,974,982,787,612,684,613,684,613,632,615,632,615,295,278,295,278,787,612,787,612,695,411,695,411,732,634,732,634,635,521,611,392,627,521,752,634,735,838,698,610,685,525,684,613,632,615,787,612,787,612,787,612,787,612,611,592,475,843,477,278,998,998,684,698,550,557,611,521,525,603,479,686,732,684,632,615,295,278,781,635,695,411,611,592],hH=1.1640625;function pH(t){let e=0;for(const n of t){const i=n.codePointAt(0)??0;i>=32&&i<127?e+=uH[i-32]:e+=i>=160&&i<592?fH[i-160]:1e3}return e/1e3}const sp=Object.freeze({"edge.show":"true","edge.thickness":"1.0","edge.use-weight":"true","edge.rescale-weight":"false","edge.rescale-weight.min":"0.4","edge.rescale-weight.max":"8.0","edge.color":"mixed","edge.opacity":"100.0","edge.curved":"true","arrow.size":"3.0","node.border.fixed":"false","node.border.width":"1.0","node.border.color":"darker","node.opacity":"100.0","node.per.node.opacity":"false","node.label.show":"true","node.label.customFont":"false","node.label.font":"Dialog,plain,12","node.label.proportinalSize":"true","node.label.color":"#000000","node.label.shorten":"false","node.label.avoidOverlap":"true","node.label.overlapGridSize":"10","node.label.scale":"1.0","node.label.max-char":"30","node.label.outline.size":"0.0","node.label.outline.color":"#ffffff","node.label.outline.opacity":"80.0","node.label.box":"false","node.label.box.color":"parent","node.label.box.opacity":"100.0","edge.label.show":"false","edge.label.customFont":"false","edge.label.font":"Dialog,plain,10","edge.label.color":"original","edge.label.shorten":"false","edge.label.max-char":"30","edge.label.outline.size":"0.0","edge.label.outline.color":"#ffffff","edge.label.outline.opacity":"80.0"});class Cd{constructor(e={}){this.values={...sp,...e}}text(e){return(this.values[e]??"").trim().toLowerCase()}on(e){return this.text(e)==="true"}num(e){const n=Number(this.text(e));return Number.isFinite(n)?n:Number(sp[e]??0)}font(e){const n=`${e}.label.font`,i=this.on(`${e}.label.customFont`)?this.values[n]??"":sp[n]??"",[r="Dialog",s="plain",o=""]=i.split(",").map(d=>d.trim()),l=s.toLowerCase(),a=Number(o),c=e==="node"?12:10;return{family:r,bold:l.includes("bold"),italic:l.includes("italic"),size:Number.isFinite(a)&&a>0?a:c}}}function gH(t,e){return t.length>=e+3?`${t.slice(0,e)}...`:t}function Cl(t,e){switch(t){case"darker":return e.slice(0,3).map(n=>Math.floor(n/2));case"lighter":return e.slice(0,3).map(n=>Math.min(255,Math.floor(n*1.5)));case"parent":case"original":return e.slice(0,3);default:{const n=/^#([0-9a-f]{6})$/.exec(t);if(n===null)return null;const i=Number.parseInt(n[1],16);return[i>>16&255,i>>8&255,i&255]}}}function hS(t,e,n,i=!1){if(t===void 0||!e.on(`${n}.label.show`))return;const r=e.on(`${n}.label.shorten`)?e.num(`${n}.label.max-char`):1/0,s=o=>i?o:o.replaceAll(/[\r\n]/g,"");return t.map(o=>typeof o=="string"?s(gH(o,r)):o)}function mH(t,e,n){const i=n.num("edge.thickness");if(!n.on("edge.use-weight"))return t.map(()=>i);if(!n.on("edge.rescale-weight"))return t.map(a=>a*i);let r=1/0,s=-1/0;t.forEach((a,c)=>{e[c]&&(r=Math.min(r,a),s=Math.max(s,a))});const o=n.num("edge.rescale-weight.min"),l=n.num("edge.rescale-weight.max");return t.map(a=>(s>r?o+(a-r)/(s-r)*(l-o):o)*i)}const yH=ce.label,nv="https://graphty.app/ns/gexf",bH=Object.freeze({tool:"gephi",node:Object.freeze(["label","fill","fillOpacity","width","height","shape","image"]),edge:Object.freeze(["color","opacity","width","lineStyle"]),block:"native"}),Fb="#000000",pS="directed",gS="label-avoid-overlap",mS="gephi-hidden",EH="end-colors",wH=["width","weight-width"],zb=20,iv=1.3,_H=new Map([["ellipse","disc"],["rectangle","square"],["triangle","triangle"],["diamond","diamond"]]),SH=new Map([["round-rectangle","square"],["vee","triangle"]]),OH=new Set(["solid","dotted","dashed","double"]);function rv(t){const e=_H.get(t);return e===void 0?{value:SH.get(t)??"disc",exact:!1}:{value:e,exact:!0}}function sv(t){return OH.has(t)?{value:t,exact:!0}:{value:t==="dash-dot"||t==="long-dash"?"dashed":"solid",exact:!1}}const zg={node:["color","size","shape","shape.uri"],edge:["color","thickness","shape"]};function NH(t){const e=/^([+-]?)(?:(0x|0X|#)([0-9a-fA-F]+)|(0[0-7]+)|(\d+))$/.exec(t.trim());if(e===null)return null;const[,n,,i,r,s]=e;let o;if(i!==void 0?o=Number.parseInt(i,16):r!==void 0?o=Number.parseInt(r,8):o=Number.parseInt(s,10),n==="-"&&(o=-o),o<-2147483648||o>2147483647)return null;const l=o&16777215;return[l>>16&255,l>>8&255,l&255,1]}function Ds(t,e,n){const i=(e==="node"?t.nodes:t.edges).get(n);return i!==null&&i.meta.origin?.namespace===jf?n:null}function yS(t,e,n,i){const r=e==="node"?t.nodes:t.edges,s=e==="node"?t.nodeCount:t.edgeCount,o={},l={table:r,target:e,column:h=>o[h]??=new Array(s).fill(null),site:(h,p)=>({notes:n,target:e,property:p,element:h,budget:i.budget})},a=Ds(t,e,"color"),c=Ds(t,e,e==="node"?"size":"thickness"),d=Ds(t,e,"shape"),u=e==="node"?Ds(t,e,"shape.uri"):null,f=e==="node"?r.byRole("label"):null;for(let h=0;h<s;h++)f!==null&&AH(l,f,h),a!==null&&IH(l,a,h),c!==null&&$H(l,c,h),d!==null&&CH(l,d,h)&&u!==null&&TH(l,u,h);return o}function AH(t,e,n){const i=rt(K(e.value(n)),t.site(n,"label"));i!==null&&(t.column("label")[n]=i)}function TH(t,e,n){const i=K(t.table.value(e,n));typeof i=="string"&&i.length>0&&(t.column("image")[n]=i)}function IH(t,e,n){const i=K(t.table.value(e,n));if(!Array.isArray(i))return;const[r,s]=t.target==="node"?["fill","fillOpacity"]:["color","opacity"],[o,l,a,c=1]=i,d=ve({r:o*255,g:l*255,b:a*255,a:c},"gexf",t.site(n,r));d!==null&&(t.column(r)[n]=d.color,d.alpha<1&&(t.column(s)[n]=d.alpha))}function $H(t,e,n){const i=Y(K(t.table.value(e,n)),t.site(n,"width"));i!==null&&!(i===0&&t.target==="node")&&(t.target==="node"?(t.column("width")[n]=2*i,t.column("height")[n]=2*i):t.column("width")[n]=i)}function CH(t,e,n){const i=K(t.table.value(e,n));if(i===null)return!1;const r=t.target==="node"?"shape":"lineStyle";return t.column(r)[n]=le(r,i,"gexf",t.site(n,r)),typeof i=="string"&&i.toLowerCase()==="image"}function vH(t,e){const n=t.edgeCount,i=fv(t);if(!e)return RH(t);const r=LH(t),s=t.edges.byRole("directed"),o=t.edges.byRole("mutual"),l=t.edges.byRole("kind"),a=ov(t),c={directed:new Array(n).fill(!1),hidden:new Array(n).fill(!1),weight:new Array(n).fill(1)},d=new Map,u=[],f=kH(r,s,o);for(let g=0;g<n;g++){const m=i(g);if(m!==g)continue;const{ownUndirected:y,mismatched:b}=f(m);if(b){c.hidden[m]=!0;continue}const _=t.edgeSource(m),S=t.edgeTarget(m),T=r!=="undirected"&&_!==S&&!y;c.directed[m]=T;const D=`${l?.isSet(m)===!0?String(l.value(m)):""}\0${DH(_,S,T)}`,x=d.get(D);x===void 0?(d.set(D,m),u.push(m),c.weight[m]=a(m)):(c.weight[x]+=a(m),c.hidden[m]=!0)}const h=u.reduce((g,m)=>Math.min(g,c.weight[m]),1/0),p=h<=0?1-h:0;for(let g=0;g<n;g++){const m=i(g);c.directed[g]=c.directed[m],c.hidden[g]=c.hidden[m],c.weight[g]=c.weight[m]+p}return c}function DH(t,e,n){return n?`${String(t)}>${String(e)}`:`${String(Math.min(t,e))}-${String(Math.max(t,e))}`}function kH(t,e,n){const i=(r,s)=>({ownUndirected:r,mismatched:t==="directed"&&r||t==="undirected"&&s});return r=>{if(e===null)return i(t==="undirected",t!=="undirected");const s=n?.value(r)===!0;return i(e.value(r)===!1&&!s,e.value(r)===!0&&!s)}}function RH(t){const e=fv(t),n=ov(t),i=new Array(t.edgeCount).fill(t.directed),r=t.directed?t.edges.byRole("directed"):null,s=[];for(let o=0;o<t.edgeCount;o++){r!==null&&(i[o]=K(r.value(o))!==!1);const l=n(e(o));s.push(l>0?l:1)}return{directed:i,hidden:i.map(()=>!1),weight:s}}function LH(t){const e=t.meta.extra.gexf?.defaultedgetype;return typeof e=="string"?e.trim().toLowerCase():null}function ov(t){const e=s=>typeof s=="string"&&s.toLowerCase()==="weight",n=t.edges.names().map(s=>t.edges.get(s)).find(s=>s!==null&&s.meta.dynamic&&[s.meta.name,s.meta.origin?.id,s.meta.origin?.title].some(e)),i=n==null?void 0:t.extensions.get(Fg("edge",n.meta.name));if(i!==void 0){const s=i.get(Me.element),o=i.get(Me.start),l=i.get(Me.value),a=new Map;for(let c=0;s!==null&&l!==null&&c<i.rowCount;c++){const d=s.value(c),u=o?.isSet(c)===!0?o.value(c):-1/0,f=Number(l.value(c)),h=a.get(d);Number.isFinite(f)&&(h===void 0||u<h.start)&&a.set(d,{start:u,value:f})}return c=>a.get(c)?.value??0}const r=Ot(t);return s=>{const o=Number(r.text(s)??1);return Number.isFinite(o)?o:1}}function lv(t,e){const n=Number.parseInt((typeof t=="string"?t:Fb).slice(1),16),i=typeof e=="number"?Math.round(e*255):255;return[n>>16&255,n>>8&255,n&255,i]}function vl(t){return`#${t.slice(0,3).map(e=>e.toString(16).padStart(2,"0")).join("")}`}function tn(t,e,n,i,r){const[s,o]=n,l=i.filter(a=>a!==null).length;l!==0&&(t.columns.set(o,i),t.rules.push({id:`${e}.tool.${o}`,target:e,role:"passthrough",origin:"tool",where:{has:{style:o}},map:{[s]:{kind:"passthrough",by:{style:o}}},facts:{elements:l,reason:r}}))}function il(t,e,n,i){Object.keys(i).length>0&&t.rules.push({id:`${e}.tool.${n}`,target:e,role:"group",origin:"tool",where:{all:!0},set:i})}function Wb(t,e,n,i,r){const s=r?.preview??new Cd,o={rules:[],columns:new Map},l={rules:[],columns:new Map};i.spend("node",t.nodeCount),i.spend("edge",t.edgeCount);const a=Array.from({length:t.nodeCount},(d,u)=>lv(e.fill?.[u],e.fillOpacity?.[u])),c=PH(o,t,a,e,s);return zH(l,t,a,e,n,r,s),xH(o,a,c,s,r?.overlapSettled===!0),MH(o,a,e,s),{node:o,edge:l}}function jo(t,e){const n=t.width?.[e];return typeof n=="number"?n:zb}function PH(t,e,n,i,r){const s=Array.from({length:e.nodeCount},(h,p)=>p),o=r.on("node.per.node.opacity"),a=n.map(h=>(o?h[3]:255)/255*(r.num("node.opacity")/100)).map(h=>h<1?h:null);tn(t,"node",["fillOpacity","preview-opacity"],a,"NODE_OPACITY"),tn(t,"node",["borderOpacity","preview-border-opacity"],a,"NODE_OPACITY");const c=r.text("node.border.color");tn(t,"node",["borderColor","border-shade"],n.map(h=>vl(Cl(c,h)??h.map(p=>Math.floor(p/2)))),"NODE_FILL_SHADE");const d=r.on("node.border.fixed")?r.num("node.border.width"):null;tn(t,"node",["borderWidth","size-border"],s.map(h=>d===null?.08*jo(i,h):Math.min(d,jo(i,h)/2)),"NODE_SIZE");const u=r.font("node"),f=s.map(h=>r.on("node.label.proportinalSize")?Math.max(1,Math.round(u.size/40*jo(i,h))):u.size);return tn(t,"node",["labelSize","size-label"],f,"NODE_SIZE"),f}function xH(t,e,n,i,r){const s=i.text("node.label.color");s!=="#000000"&&s!=="original"&&tn(t,"node",["labelColor","preview-label-color"],e.map(l=>vl(Cl(s,l)??[0,0,0])),"NODE_LABEL_COLOR"),dv(t,"node",e,n,i);const o=i.font("node");il(t,"node","preview-label",cv(o,i.on("node.label.customFont"))),i.on("node.label.avoidOverlap")&&!r&&(t.columns.set(gS,n.map(()=>!0)),t.rules.push({id:"node.tool.label-avoid-overlap",target:"node",role:"group",origin:"tool",where:{has:{style:gS}},set:{labelAvoidOverlap:!0}}))}function av(t){return Math.floor(Math.min(Math.max(t,0),100)/100*255+1e-9)/255}function MH(t,e,n,i){if(!i.on("node.label.box"))return;const r=i.text("node.label.box.color");tn(t,"node",["labelBorderColor","preview-box-color"],e.map(s=>vl(Cl(r,s)??s)),"LABEL_BOX"),tn(t,"node",["labelBorderWidth","preview-box-width"],e.map((s,o)=>.04*jo(n,o)),"LABEL_BOX"),il(t,"node","preview-box",{labelBorderOpacity:av(i.num("node.label.box.opacity")),labelPadding:0,labelLineHeight:1})}function cv(t,e){return e?{labelFont:t.family,...t.bold?{labelWeight:"bold"}:{},...t.italic?{labelItalic:!0}:{}}:{}}function dv(t,e,n,i,r){const s=r.num(`${e}.label.outline.size`);if(s<=0)return;const o=r.text(`${e}.label.outline.color`);tn(t,e,["labelOutlineWidth","preview-outline-width"],i.map(l=>s/32*l),"LABEL_OUTLINE"),tn(t,e,["labelOutlineColor","preview-outline-color"],n.map(l=>vl(Cl(o,l)??[255,255,255])),"LABEL_OUTLINE"),il(t,e,"preview-outline",{labelOutlineOpacity:av(r.num(`${e}.label.outline.opacity`))})}function UH(t,e,n,i){const r=uv(t);if(r.includes(null))return null;const s=Math.fround,o=i.num("node.label.overlapGridSize"),l=i.on("node.label.proportinalSize"),a=s(i.font("node").size*i.num("node.label.scale")),c=r.map((R,G)=>{const B=n?.[G];return s((typeof B=="number"?B:zb)/2)}),d=c.map(R=>s(l?s(a*R)*s(.05):a*s(1+s(R*s(1e-5))))),u=d.map((R,G)=>G).sort((R,G)=>c[G]-c[R]),f=new Map;u.forEach(R=>f.set(Math.round(d[R]),d[R]));const h=r.map(R=>[R?.[0]??0,-(R?.[1]??0)]);let[p,g,m,y]=[1/0,1/0,-1/0,-1/0];for(const[R,G]of h)[p,g,m,y]=[Math.min(p,R),Math.min(g,G),Math.max(m,R),Math.max(y,G)];const[b,_]=[p-o,g-o],S=Math.ceil((m+o-b)/o),T=Math.ceil((y+o-_)/o),$=new Set,D=e.map(()=>!1),x=[...u].sort((R,G)=>d[G]-d[R]);for(const R of x){const G=e[R];if(typeof G!="string"||G.trim()==="")continue;const B=f.get(Math.round(d[R]))??d[R],Q=[pH(G)*B/2,hH*B/2],be=GH({min:[b,_],size:o,cols:S,rows:T},[h[R][0]-Q[0],h[R][1]-Q[1]],[h[R][0]+Q[0],h[R][1]+Q[1]]);be.some(De=>$.has(De))?D[R]=!0:be.forEach(De=>$.add(De))}return D}function GH(t,e,n){const i=(s,o)=>Math.min((o===0?t.cols:t.rows)-1,Math.max(0,Math.trunc((s-t.min[o])/t.size))),r=[];for(let s=i(e[1],1);s<=i(n[1],1);s++)for(let o=i(e[0],0);o<=i(n[0],0);o++)r.push(s*t.cols+o);return r}const bS=1.2;function uv(t){const e=t.nodes.byRole("position");return Array.from({length:t.nodeCount},(n,i)=>{const r=e?.isSet(i)===!0?e.value(i):null;return r===null?null:[r[0]||0,r[1]||0]})}function jH(t,e,n,i,r){const s=uv(t),o=r.num("edge.radius"),l=r.num("arrow.size"),a=2*Math.asin(Math.min(1,bS/2));return Array.from({length:t.edgeCount},(c,d)=>{const[u,f]=[t.edgeSource(d),t.edgeTarget(d)],[h,p]=[s[u],s[f]];if(u===f||h===null||p===null)return null;const g=Math.hypot(p[0]-h[0],p[1]-h[1]);if(g===0)return"all";const m=g/bS,y=S=>S>=m*a?1/0:2*Math.atan2(S/2,Math.sqrt(m*m-S/2*(S/2))),b=o+jo(e,u)/2,_=o+jo(e,f)/2+(n[d]?l*i[d]:0);return y(b)+y(_)>=a?"line":null})}const ES=96;function FH(t,e,n){const i=Ds(t,"node","size"),r=o=>{const l=i===null?null:Number(K(t.nodes.value(i,o)));return l!==null&&Number.isFinite(l)&&l>0?l:zb/2},s=o=>String(Math.round(o*1e4)/1e4);return Array.from({length:t.edgeCount},(o,l)=>{const a=t.edgeSource(l);if(a!==t.edgeTarget(l)||n[l])return null;const c=r(a),d=(.5*c+.33*iv*e[l])/c,u=[];for(let f=0;f<=ES;f++){const h=5*Math.PI/4-2*Math.PI*f/ES;u.push(`${s(d+d*Math.cos(h))},${s(d+d*Math.sin(h))}`)}return u.join(" ")})}function zH(t,e,n,i,r,s,o){const l=vH(e,s!==void 0),a=o.num("arrow.size");l.directed.some(Boolean)&&a>0&&(t.columns.set(pS,l.directed.map(p=>p?!0:null)),t.rules.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:pS}},set:{targetArrow:"triangle",...a===3?{}:{arrowSize:a/3}}}));const c=o.on("edge.show")?l.hidden:l.hidden.map(()=>!0),d=mH(l.weight,c.map(p=>!p),o);tn(t,"edge",wH,op(r.width,e.edgeCount,p=>e.edgeSource(p)===e.edgeTarget(p)?iv*d[p]:d[p]),"EDGE_WEIGHT"),tn(t,"edge",["bends","self-loop"],FH(e,d,c),"NODE_SIZE");const u=o.on("edge.curved")?jH(e,i,l.directed,d,o):c.map(()=>null);c.forEach((p,g)=>{const m=l.directed[g]&&a>0&&u[g]==="line";c[g]=p||u[g]!==null&&!m}),c.some(Boolean)&&(t.columns.set(mS,c.map(p=>p?!0:null)),t.rules.push({id:"edge.tool.gephi-hidden",target:"edge",role:"group",origin:"tool",where:{has:{style:mS}},set:{visible:!1}}));const f=WH(e,n,s,o);tn(t,"edge",["color",EH],op(r.color,e.edgeCount,p=>vl(f[p])),"END_NODE_COLORS"),tn(t,"edge",["opacity","end-opacity"],op(r.color,e.edgeCount,p=>f[p][3]/255).map((p,g)=>u[g]!==null&&!c[g]?0:p===1?null:p),"END_NODE_COLORS"),il(t,"edge","preview-curve",o.on("edge.curved")?{}:{curved:!1});const h=o.num("edge.radius");il(t,"edge","preview-radius",h>0?{nodeGap:h}:{}),BH(t,f,s,o)}function WH(t,e,n,i){const r=i.text("edge.color"),s=i.num("edge.opacity")/100,o=a=>{const c=n?.original?.color?.[a],d=n?.original?.opacity?.[a];return lv(typeof c=="string"?c:Fb,typeof d=="number"?d:null)},l=Cl(r,[0,0,0]);return Array.from({length:t.edgeCount},(a,c)=>{const d=e[t.edgeSource(c)],u=e[t.edgeTarget(c)];let f;return r==="source"?f=[...d]:r==="target"?f=[...u]:r==="original"?f=o(c):r.startsWith("#")&&l!==null?f=[...l,255]:f=d.map((h,p)=>Math.floor((h+u[p])/2)),s===1?f:[f[0],f[1],f[2],f[3]*s]})}function BH(t,e,n,i){if(n?.edgeLabels===void 0||!i.on("edge.label.show"))return;const r=i.font("edge"),s=i.text("edge.label.color");s!=="original"&&tn(t,"edge",["labelColor","preview-label-color"],e.map(o=>vl(Cl(s,o)??[0,0,0])),"EDGE_LABEL_COLOR"),dv(t,"edge",e,e.map(()=>r.size),i),il(t,"edge","preview-label",{labelSize:r.size,labelPosition:"center",...cv(r,i.on("edge.label.customFont"))})}function HH(t,e){const n=Number.parseInt(t.slice(1),16),i=Number.parseInt(e.slice(1),16);let r=0;for(const s of[16,8,0])r|=Math.floor(((n>>s&255)+(i>>s&255))/2)<<s;return`#${r.toString(16).padStart(6,"0")}`}function fv(t){const e=t.edges.byRole("pair");return n=>e?.isSet(n)===!0?Math.min(n,e.value(n)):n}function op(t,e,n){const i=new Array(e).fill(null);for(let r=0;r<e;r++)(t?.[r]===null||t===void 0)&&(i[r]=n(r));return i}function VH(t,e){const n=new se,i=yS(t,"node",n,e),r=yS(t,"edge",n,e),{block:s,preview:o}=YH(e.kept),l=i.fillOpacity,a={color:r.color,opacity:r.opacity};s===null?XH(i,r):qH(t,s,i,r);const c=hS(i.label,o,"node",s!==null),d=s===null&&c!==void 0&&o.on("node.label.avoidOverlap")?UH(t,c,i.width,o):null;d?.forEach((h,p)=>{h&&c!==void 0&&(c[p]=null)}),c===void 0?delete i.label:i.label=c;const u=hS(KH(t),o,"edge",s!==null);u!==void 0&&(r.label=u);const f=Wb(t,{fill:i.fill,fillOpacity:l,width:i.width},{color:r.color,width:r.width},e.budget,{preview:o,original:a,edgeLabels:u,overlapSettled:d!==null});return{canonical:!0,dialect:"gexf",tool:"gephi",units:"relative",node:{values:i,...f.node},edge:{values:r,...f.edge},notes:n.list(),opacityInColor:!0,block:s,readFrom:{node:zg.node.filter(h=>Ds(t,"node",h)!==null),edge:zg.edge.filter(h=>Ds(t,"edge",h)!==null)}}}function YH(t){if(typeof t=="string")return{block:t,preview:new Cd};if(typeof t=="object"&&t!==null){const{block:e,gephiPreview:n}=t;return{block:typeof e=="string"?e:null,preview:new Cd(n)}}return{block:null,preview:new Cd}}function KH(t){const e=t.edges.byRole("label");if(e!==null)return Array.from({length:t.edgeCount},(n,i)=>{const r=K(e.value(i));return typeof r=="string"&&r.length>0?r:null})}function XH(t,e){delete t.shape,delete t.image,delete t.fillOpacity,delete e.color,delete e.opacity,delete e.width,delete e.lineStyle}function qH(t,e,n,i){const r=new Map([["disc","ellipse"],["square","rectangle"]]),s=l=>{const a=l("width"),c=l("height");return typeof a=="number"&&typeof c=="number"?Math.max(a,c):a??c},o={shape:l=>{const{value:a}=rv(String(l("shape")));return r.get(a)??a},width:s,height:s,lineStyle:l=>sv(String(l("lineStyle"))).value};so(t,e,"gexf",l=>({values:l==="node"?n:i,properties:l==="node"?["shape","width","height"]:["lineStyle"],readBack:(a,c)=>d=>o[d](c),take:(a,c,d)=>d!==null&&(c!==null||a==="width"||a==="height")}))}function JH(t){const e=new Set(t.filter(n=>n!==null).map(n=>typeof n));return e.size===1&&e.has("number")?"f64":e.size===1&&e.has("boolean")?"bool":"string"}function hv(t,e){if(e===void 0)return null;const n=(p,g)=>e.picture(p,g),i=n("node","fill"),r=n("node","fillOpacity"),s=n("node","image"),o=n("edge","color"),l=n("edge","opacity"),a=n("edge","width"),c=n("node","height"),d=new Il,u=n("node","shape").map((p,g)=>QH(p,typeof s[g]=="string",d)),f=n("node","width").map((p,g)=>tV(p,c[g],d)),h=n("edge","lineStyle").map(p=>eV(p,d));return{snapshot:ZH(t,e),blockElement:`<graphty:styles xmlns:graphty="${nv}" name="${Z}">${pv(e.block)}</graphty:styles>`,notes:d.notes("GEXF"),node(p,g){const m=f[p],y=u[p];return wS(i[p],r[p],g)+(m===null?"":`${g}<viz:size value="${String(m/2)}"/>
|
|
94
|
+
`)+_S(y,y==="image"?String(s[p]):null,g)},edge(p,g){const m=a[p],y=o[p],b=S=>String(i[S]??Fb);return(typeof y=="string"&&y===HH(b(t.edgeSource(p)),b(t.edgeTarget(p)))&&(l[p]??1)===1?"":wS(y,l[p],g))+(typeof m=="number"?`${g}<viz:thickness value="${String(m)}"/>
|
|
95
|
+
`:"")+_S(h[p],null,g)}}}function ZH(t,e){const n=t.withColumns();for(const r of["node","edge"]){const s=r==="node"?n.nodes:n.edges;for(const o of zg[r])s.get(o)?.meta.origin?.namespace===jf&&s.remove(o);for(const[o,l]of e.tags[r]){const a=JH(l);s.set(o,a==="string"?l.map(c=>c===null?null:String(c)):l,{dtype:a})}}const i=e.picture("node","label").map(r=>typeof r=="string"?r:null);return n.nodes.set(yH,i,{dtype:"string",role:"label"},{replaceRole:!0}),n}function QH(t,e,n){if(e)return typeof t=="string"&&t!=="other:image"&&n.add("node","shape",t),"image";if(typeof t!="string")return null;const i=rv(t);return i.exact||n.add("node","shape",t),i.value}function eV(t,e){if(typeof t!="string")return null;const n=sv(t);return n.exact||e.add("edge","lineStyle",t),n.value}function tV(t,e,n){return typeof t=="number"&&typeof e=="number"&&t!==e?(n.add("node",t>e?"height":"width",`${String(t)} x ${String(e)}`),Math.max(t,e)):typeof t=="number"?t:typeof e=="number"?e:null}function wS(t,e,n){if(typeof t!="string")return"";const i=Number.parseInt(t.slice(1),16),r=typeof e=="number"&&e!==1?` a="${String(e)}"`:"";return`${n}<viz:color r="${String(i>>16&255)}" g="${String(i>>8&255)}" b="${String(i&255)}"${r}/>
|
|
96
|
+
`}function _S(t,e,n){return t===null?"":e===null?`${n}<viz:shape value="${t}"/>
|
|
97
|
+
`:`${n}<viz:shape value="${t}" uri="${pv(e)}"/>
|
|
98
|
+
`}function pv(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""")}const gv="E_NOT_GEXF",Wg="E_GEXF_MISSING_NODES",mv="E_GEXF_EDGE_TYPE",yv="E_GEXF_ATTRIBUTES_CLASS",bv="E_GEXF_ATTRIBUTE_ID",To="W_GEXF_HEADER_VALUE",Ev="W_GEXF_ATTRIBUTE_TYPE",Bg="W_GEXF_UNKNOWN_ATTRIBUTE",Hg="W_GEXF_ATTVALUE_SHAPE",wv="W_GEXF_TIMED_VALUE_ON_STATIC",_v="W_GEXF_WEIGHT_IGNORED",Sv="W_GEXF_VIZ_SKIPPED",Ov="W_GEXF_UNKNOWN_PID",Nv="W_GEXF_VIZ_DYNAMIC_DROPPED",nV="W_GEXF_SPELL_OPEN_DROPPED",Vg="W_GEXF_VIZ_VALUE",Av="W_GEXF_OPEN_BOUND_CONFLICT",Tv="W_GEXF_TIMESTAMP_CONFLICT",Yg="W_GEXF_VALUE_OUTSIDE_OPTIONS",iV=new Set(["1.0","1.1","1.2","1.3"]);function rV(t){if(t!==null&&/gephi\.org\/gexf\/?$/.test(t))return"1.0";const e=t===null?null:/gexf\.net\/(1\.[0-3])/.exec(t);return e===null?null:e[1]}function sV(t){return t!==null&&/(gexf\.net\/.*viz|gephi\.org\/gexf\/viz)\/?$/.test(t)}const oV=16,lV={gexf:new Set(["version","variant"]),meta:new Set(["lastmodifieddate"]),graph:new Set(["defaultedgetype","mode","type","timeformat","timerepresentation","idtype","start","end","timestamp","startopen","endopen"]),attributes:new Set(["class","mode","type","start","end","startopen","endopen"]),attribute:new Set(["id","title","type"]),attvalue:new Set(["for","value","start","end","timestamp","startopen","endopen","id"]),spell:new Set(["start","end","timestamp","startopen","endopen"]),parent:new Set(["for"]),nodes:new Set(["count"]),edges:new Set(["count"])},aV=/^\d+$/,cV=/^-?\d{4,}-\d{2}-\d{2}(.*)$/s,dV=/^T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?/,uV=/^(?:Z|[+-]\d{2}:\d{2})?$/;function fV(t){const e=cV.exec(t);if(e===null)return!1;const n=dV.exec(e[1])?.[0]??"";return uV.test(e[1].slice(n.length))}const SS=new Set(["directed","undirected","mutual"]);function lp(t){const e=t.trim().toLowerCase();return hV.get(e)??e}const hV=new Map([["dir","directed"],["undir","undirected"],["double","mutual"]]),pV=64,gV=new Set(["id","label","pid","start","end","timestamp","startopen","endopen","timestamps","intervals"]),mV=new Set(["id","source","target","type","label","weight","kind","start","end","timestamp","startopen","endopen","timestamps","intervals"]),yV=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","errorLimit","signal","onProgress"]);class Pe{constructor(e,n){this.handle=A,this.domain=e,this.decl=n}get(e,n,i){return this.handle===A&&(this.handle=he(e,this.domain,this.decl,n,i).handle),this.handle}set(e,n,i,r,s){const o=this.get(e,n,s);this.domain==="node"?e.setNodeValue(o,i,r):e.setEdgeValue(o,i,r)}}class bo{constructor(e,n){this.companion=A,this.domain=e,this.name=n.name,this.column=new Pe(e,n)}set(e,n,i,r,s){this.column.set(e,n,i,r.value,s),r.text!==null&&(this.companion===A&&(this.companion=wy(e,this.domain,JA(this.name),n)),this.domain==="node"?e.setNodeValue(this.companion,i,r.text):e.setEdgeValue(this.companion,i,r.text))}}class bV{constructor(e,n,i,r){this.ctx=[],this.timeFormat=null,this.defaultKind="undirected",this.meta={sourceFormat:Mi},this.metaText="",this.metaField=null,this.styleBlock="",this.keptBlock=null,this.implicitNodes=new Map,this.edgesFirst=!1,this.nodeAttrs=new Map,this.edgeAttrs=new Map,this.declaredNodeNames=new Set,this.declaredEdgeNames=new Set,this.weightAttr=null,this.parentColumn=new Pe("node",Ft.parent),this.parentsColumn=new Pe("node",Ft.parents),this.positionColumn=null,this.sizeColumn=new Pe("node",Ft.size),this.shapeUriColumn=new Pe("node",Ft.shapeUri),this.thicknessColumn=new Pe("edge",_n.thickness),this.edgeIdColumn=new Pe("edge",_n.id),this.edgeKindColumn=new Pe("edge",_n.kind),this.edgeIds=new Set,this.parentRefs=[],this.parentsRefs=[],this.unknownAttributes=new Set,this.nodeStack=[],this.edge=null,this.edgeFrame={index:A,mirror:A,where:{line:0,element:null},xmlWeight:null},this.attvalueIds=new Set,this.sections=[],this.unknownNames=new Map,this.unknownOverflow=new Map,this.valueWhere={line:0,element:null},this.attributeGroup=null,this.pendingAttribute=null,this.attributeText=null,this.attributeTextValue="",this.spellPairs=null,this.spellOpen=[],this.spellsWhere=null,this.parentIds=null,this.nodesSeen=!1,this.graphSeen=!1,this.elementsSinceCheck=0,this.sink=e,this.report=n,this.options=i,this.viz=r,this.coercer=new Mn(i.ids),this.resolver=new ei(e,n,i.onMixedDirection),this.nodeColumns={label:new Pe("node",Ft.label),start:new bo("node",Ft.start),end:new bo("node",Ft.end),timestamp:new bo("node",Ft.timestamp),spells:new Pe("node",Ft.spells),spellsOpen:new Pe("node",Ft.spellsOpen),timestamps:new Pe("node",Ft.timestamps),open:new Pe("node",Ft.open),color:new Pe("node",Ft.color),shape:new Pe("node",Ft.shape)},this.edgeColumns={label:new Pe("edge",_n.label),start:new bo("edge",_n.start),end:new bo("edge",_n.end),timestamp:new bo("edge",_n.timestamp),spells:new Pe("edge",_n.spells),spellsOpen:new Pe("edge",_n.spellsOpen),timestamps:new Pe("edge",_n.timestamps),open:new Pe("edge",_n.open),color:new Pe("edge",_n.color),shape:new Pe("edge",_n.shape)}}start(e,n,i,r=""){const s=this.ctx.at(-1)??null,o=Rs(e);if(r===null&&s!==null&&s!==14&&s!==2&&s!==6&&s!==15&&!e.startsWith("viz:")){this.unknownElement(e,i);return}switch(s){case null:o!=="gexf"&&this.report.fail(gv,`the root element is <${e}>, not <gexf>`,{line:i}),this.checkAttributes("gexf",n,i),this.readRoot(n,r,i),this.ctx.push(0);return;case 0:this.startInGexf(e,o,n,i);return;case 1:this.startInMeta(e,o,i,r);return;case 3:this.startInGraph(e,o,n,i);return;case 4:this.startInAttributes(e,o,n,i);return;case 5:this.startInAttribute(e,o,i);return;case 7:this.startInNodes(e,o,n,i);return;case 8:this.startInNode(e,o,n,i,r);return;case 9:this.startInAttvalues(e,o,n,i);return;case 10:this.startInParents(e,o,n,i);return;case 11:this.startInSpells(e,o,n,i);return;case 12:this.startInEdges(e,o,n,i);return;case 13:this.startInEdge(e,o,n,i,r);return;case 2:case 6:case 15:case 14:this.ctx.push(14);return;default:this.unknownElement(e,i)}}end(e,n){const i=this.ctx.pop();switch(i){case 1:this.finishMeta();return;case 2:this.finishMetaText();return;case 15:this.report.keepForStyles(this.styleBlock),this.keptBlock=this.styleBlock,this.styleBlock="";return;case 3:this.resolveParents(),!this.nodesSeen&&this.implicitNodes.size>0?this.report.error("validation-error",Wg,"the graph declares <edges> but no <nodes>"):this.options.addMissingNodes||this.dropUndeclaredNodes();return;case 4:this.attributeGroup=null;return;case 5:this.finishAttribute();return;case 6:this.finishAttributeText();return;case 8:this.nodeStack.pop();return;case 7:case 12:this.finishSection();return;case 13:this.edge=null;return;case 10:this.finishParents();return;case 11:this.finishSpells();return;case 0:case 9:case 14:case void 0:return;default:{const r=i;throw new N("E_UNSUPPORTED",`unknown reader state ${String(r)}`,{})}}}text(e,n){switch(this.ctx.at(-1)??null){case 2:this.metaText+=e;return;case 6:this.attributeTextValue+=e;return;case 15:this.styleBlock.length<=du&&(this.styleBlock+=e.slice(0,du+1-this.styleBlock.length));return;case 14:return;default:Tr(e)||this.report.warnOnce("validation-error",qu,"text where GEXF allows only elements was ignored",{line:n})}}finish(){this.graphSeen||this.report.fail(ls,"the document has no <graph> element");for(const[e,n]of this.unknownOverflow)this.report.warning("unsupported",Bd,`${n} more distinct attribute names on <${e}> are not GEXF attributes and are not kept (not listed one by one)`,{element:e})}readRoot(e,n,i){const r=e.get("version");if(r!==void 0&&r.length>0){this.meta.sourceVersion=r,iV.has(r)||this.report.warning("validation-error",To,`<gexf version="${r}"> is not a GEXF version graph-io knows (1.0 to 1.3); read as GEXF 1.3`,{line:i,element:"version"});return}const s=rV(n);s!==null&&(this.meta.sourceVersion=s)}startInGexf(e,n,i,r){switch(n){case"meta":{this.checkAttributes("meta",i,r);const s=i.get("lastmodifieddate");s!==void 0&&s.length>0&&(this.meta.modified=s,fV(s.trim())||this.report.warning("validation-error",To,`<meta lastmodifieddate="${s}"> is not an xs:date; kept as written`,{line:r,element:"lastmodifieddate"})),this.ctx.push(1);return}case"graph":this.checkAttributes("graph",i,r),this.graphSeen?this.report.warnOnce("unsupported",Qn,"a second <graph> element; its nodes and edges are merged into the first and its header is ignored",{line:r}):(this.graphSeen=!0,this.readHeader(i,r)),this.ctx.push(3);return;default:this.unknownElement(e,r)}}startInMeta(e,n,i,r){if(r===nv&&n==="styles"){this.styleBlock="",this.ctx.push(15);return}if(n==="creator"||n==="description"||n==="keywords"){this.metaField=n,this.metaText="",this.ctx.push(2);return}this.unknownElement(e,i)}finishMetaText(){const e=this.metaText;switch(this.metaField){case"creator":this.meta.creator=e;break;case"description":this.meta.description=e;break;case"keywords":this.meta.keywords=e.split(",").map(n=>n.trim()).filter(n=>n.length>0);break}this.metaField=null,this.metaText=""}finishMeta(){this.graphSeen&&this.sink.setMeta(this.meta)}readHeader(e,n){const i={line:n},r=this.meta,s=e.get("defaultedgetype");s===void 0?this.defaultKind=this.options.defaultDirected?"directed":"undirected":SS.has(lp(s))?this.defaultKind=lp(s):(this.defaultKind=this.options.defaultDirected?"directed":"undirected",this.warnHeader("defaultedgetype",s,i));const o=e.get("mode")??e.get("type");o!==void 0&&(oH.has(o)?r.mode=o:this.warnHeader("mode",o,i));const l=e.get("timeformat");l!==void 0&&(sH.has(l)?(this.timeFormat=l,r.timeFormat=this.timeFormat):this.warnHeader("timeformat",l,i));const a=e.get("timerepresentation");a!==void 0&&(lH.has(a)?r.timeRepresentation=a:this.warnHeader("timerepresentation",a,i));const c=e.get("idtype");c!==void 0&&(c==="string"?r.idType="string":c==="integer"||c==="long"?r.idType="integer":this.warnHeader("idtype",c,i));const d={};for(const u of["defaultedgetype","start","end","timestamp"]){const f=e.get(u);f!==void 0&&(d[u]=f)}Object.keys(d).length>0&&(r.extra={gexf:d}),this.sink.setMeta(r),this.resolver.setHeader(this.defaultKind!=="undirected",i)}warnHeader(e,n,i){this.report.warning("validation-error",To,`<graph ${e}="${n}"> is not a known value; the default applies`,{...i,element:e})}startInGraph(e,n,i,r){switch(n){case"attributes":this.beginAttributes(i,r);return;case"nodes":this.nodesSeen=!0,this.beginSection(i,"node",r);return;case"edges":!this.nodesSeen&&this.meta.sourceVersion==="1.0"?this.edgesFirst=!0:this.nodesSeen||this.report.error("validation-error",Wg,"the graph declares <edges> but no <nodes>",{line:r}),this.resolveParents(),this.beginSection(i,"edge",r);return;default:this.unknownElement(e,r)}}beginSection(e,n,i){this.checkAttributes(`${n}s`,e,i),this.sections.push({domain:n,hint:this.reserve(e,n,i),seen:0,line:i}),this.ctx.push(n==="node"?7:12)}finishSection(){const e=this.sections.pop();e?.hint===void 0||e.hint===null||e.hint===e.seen||this.report.warning("validation-error",Fs,`<${e.domain}s count="${e.hint}"> but the section holds ${e.seen} <${e.domain}> elements (nested ones included)`,{line:e.line,element:"count"})}reserve(e,n,i){const r=e.get("count");if(r===void 0)return null;const s=aV.test(r)?Number(r):Number.NaN;if(!Number.isSafeInteger(s)||s>yA)return this.report.warning("validation-error",Hd,`<${n}s count="${r}"> is not a count the sink can reserve; ignored`,{line:i,element:"count"}),null;if(s===0)return s;try{n==="node"?this.sink.reserve(s,void 0):this.sink.reserve(void 0,s)}catch(o){if(!(o instanceof N))throw o;this.report.warning("validation-error",Hd,`count hint ${r} refused: ${o.message}`,{line:i,element:"count"})}return s}beginAttributes(e,n){this.checkAttributes("attributes",e,n);const i=e.get("class"),r={line:n};let s=null;i==="node"||i==="edge"?s=i:this.report.error("validation-error",yv,i===void 0?"<attributes> without a class":`<attributes class="${i}"> is neither node nor edge`,r);const o=e.get("mode")??e.get("type");o!==void 0&&o!=="static"&&o!=="dynamic"&&this.warnHeader("mode",o,r),this.attributeGroup={domain:s,dynamic:o==="dynamic"},this.ctx.push(4)}startInAttributes(e,n,i,r){if(n!=="attribute"){this.unknownElement(e,r);return}this.checkAttributes("attribute",i,r);const s=this.attributeGroup;if(!s?.domain){this.ctx.push(14);return}this.pendingAttribute={domain:s.domain,dynamic:s.dynamic,attrs:i,line:r,defaultText:null,optionsText:null},this.ctx.push(5)}startInAttribute(e,n,i){if(n==="default"||n==="options"){this.attributeText=n,this.attributeTextValue="",this.ctx.push(6);return}this.unknownElement(e,i)}finishAttributeText(){const e=this.pendingAttribute;e!==null&&(this.attributeText==="default"?e.defaultText=this.attributeTextValue:this.attributeText==="options"&&(e.optionsText=this.attributeTextValue)),this.attributeText=null,this.attributeTextValue=""}finishAttribute(){const e=this.pendingAttribute;if(this.pendingAttribute=null,e!==null)try{this.declareOne(e)}catch(n){this.report.recordError(n,{line:e.line,element:e.attrs.get("id")??null})}}isDuplicateAttribute(e,n,i){const{report:r}=this;return(e==="node"?this.nodeAttrs:this.edgeAttrs).has(n)||e==="edge"&&this.weightAttr!==null&&this.weightAttr.id===n?(r.warning("validation-error",fe,`${e} attribute "${n}" is declared twice; the first declaration is kept`,i),!0):(this.unknownAttributes.has(`${e}:${n}`)&&r.warning("missing-value",Bg,`${e} attribute "${n}" is declared after values that use it; those values were dropped (declare <attributes> before <nodes>)`,i),!1)}claimsWeight(e,n){const{report:i,sink:r,options:s}=this,{domain:o,id:l,name:a,title:c,type:d}=e;if(o!=="edge"||!_y(a,s.weightFrom))return!1;if(this.weightAttr!==null)return i.warning("validation-error",fe,`edge attribute "${l}" is also titled ${a}; attribute "${this.weightAttr.id}" is the weight, "${l}" is kept as a column`,n),!1;const u=ga({format:Mi,id:l,title:c,type:d,long:s.long});for(const f of u.issues)i.warning(f.category,f.code,f.message,n);return this.weightAttr={id:l,spec:u.spec,table:A},r.setMeta({weightOrigin:{format:Mi,id:l,title:c,type:d,namespace:null}}),!0}declareOne(e){const{report:n,sink:i,options:r}=this,{domain:s,dynamic:o,attrs:l}=e,a=l.get("id"),c={line:e.line,element:a??null};if(a===void 0){n.error("validation-error",bv,"<attribute> without an id",c);return}const d=s==="node"?this.nodeAttrs:this.edgeAttrs;if(this.isDuplicateAttribute(s,a,c))return;const u=l.get("title")??null,f=l.get("type")??null;f===null&&n.warning("validation-error",Ev,`attribute "${a}" declares no type; read as string`,c);const h=u!==null&&u.length>0?u:a;if(this.claimsWeight({domain:s,id:a,name:h,title:u,type:f},c))return;const p=s==="node"?this.declaredNodeNames:this.declaredEdgeNames,g=s==="node"?QC:ev,m=s==="edge"&&this.weightAttr!==null?r.weightFrom:null,y=D=>g.has(D)||p.has(D)||D===m,b={format:Mi,id:a,title:u,type:f,defaultText:e.defaultText,optionsText:e.optionsText,listSyntax:"gexf",dynamic:o,long:r.long,taken:y},_=ga(b);for(const D of _.issues)n.warning(D.category,D.code,D.message,c);const S=he(i,s,_.decl,n,c);p.add(S.decl.name);let T=null;_.companion!==null&&(T={..._.companion,name:`${S.decl.name}.text`,extra:{for:S.decl.name}},p.add(T.name));const $={dtype:S.decl.dtype,itemDtype:S.decl.itemDtype,options:S.decl.options,origin:S.decl.origin};d.set(a,{id:a,name:S.decl.name,spec:_.spec,listSyntax:_.listSyntax,handle:S.handle,companionDecl:T,companion:A,dynamic:o,valueDecl:$,table:A})}startInNodes(e,n,i,r){if(n!=="node"){this.unknownElement(e,r);return}this.beginNode(i,r)}beginNode(e,n){const{report:i,sink:r}=this;this.checkAbort();const s=this.nodeStack.at(-1)?.index??A,o=e.get("id"),l={line:n,element:o??e.get("label")??null};if(this.countInSection("node"),this.checkAttributeNames(e,gV,"node",l),o===void 0){i.error("missing-value",dt,"<node> without an id",l),i.counts.skippedNodes++,this.nodeStack.push({index:A,where:l}),this.ctx.push(8);return}this.meta.idType==="integer"&&!/^\s*[+-]?\d+\s*$/.test(o)&&i.warnOnce("validation-error",To,`node id "${o}" is not an integer although the graph declares idtype="integer"; ids follow the ids option`,l,`${To}:idtype`);let a;try{const c=this.coerceId(o,l),d=r.indexOf(c);d!==A&&this.implicitNodes.delete(d)?a=d:d!==A?(i.warning("validation-error",sn,`node "${o}" is declared more than once; later attributes overwrite`,l),a=d):(a=r.addNode(c),i.counts.nodes++)}catch(c){i.recordError(c,l),i.counts.skippedNodes++,this.nodeStack.push({index:A,where:l}),this.ctx.push(8);return}this.nodeStack.push({index:a,where:l}),this.ctx.push(8);try{const c=e.get("label");c!==void 0&&this.nodeColumns.label.set(r,i,a,c,l)}catch(c){i.recordError(c,l)}try{const c=e.get("pid");c!==void 0?this.parentRefs.push({child:a,parentId:this.coerceId(c,l),parentIndex:A,where:l}):s!==A&&this.parentRefs.push({child:a,parentId:null,parentIndex:s,where:l})}catch(c){i.recordError(c,l)}try{this.writeLifetime(e,a,this.nodeColumns,l)}catch(c){i.recordError(c,l)}}countInSection(e){for(const n of this.sections)n.domain===e&&n.seen++}startInNode(e,n,i,r,s){const o=this.nodeStack[this.nodeStack.length-1];if(o.index===A&&n!=="nodes"){this.ctx.push(14);return}switch(o.index===A&&this.report.error("missing-value",Ui,"the nodes nested in this skipped <node> lose their parent; they are read as top-level nodes",{line:r}),n){case"attvalues":this.attvalueIds.clear(),this.ctx.push(9);return;case"parents":this.parentIds=[],this.ctx.push(10);return;case"spells":this.spellPairs=[],this.spellOpen=[],this.spellsWhere=o.where,this.ctx.push(11);return;case"nodes":this.beginSection(i,"node",r);return;case"color":case"position":case"size":case"shape":if(!OS(e,s)){this.unknownElement(e,r);return}this.writeViz(e,n,i,"node",o.index,o.where),this.ctx.push(14);return;default:this.unknownElement(e,r)}}startInParents(e,n,i,r){if(n!=="parent"){this.unknownElement(e,r);return}this.ctx.push(14),this.checkAttributes("parent",i,r);const s=this.nodeStack[this.nodeStack.length-1],o=i.get("for");if(o===void 0){this.report.error("missing-value",Ui,"<parent> without a for attribute names no parent",s.where);return}try{this.parentIds?.push(this.coerceId(o,s.where))}catch(l){this.report.recordError(l,s.where)}}finishParents(){const e=this.nodeStack[this.nodeStack.length-1];this.parentIds!==null&&e.index!==A&&this.parentsRefs.push({child:e.index,ids:this.parentIds,where:e.where}),this.parentIds=null}resolveParents(){const{sink:e,report:n}=this,i=this.parentRefs,r=this.parentsRefs;this.parentRefs=[],this.parentsRefs=[];const s=new Map,o=(l,a)=>{for(let c=a;c!==void 0;c=s.get(c))if(c===l)return!0;return!1};for(const l of i){const a=this.parentIndexOf(l);if(!(a===null||s.get(l.child)===a)){if(o(l.child,a)){n.error("validation-error",pl,`the parent link of node "${l.where.element??"?"}" would close a parent cycle; it is dropped`,l.where);continue}try{this.parentColumn.set(e,n,l.child,a,l.where),s.set(l.child,a)}catch(c){n.recordError(c,l.where)}}}this.resolveParentsLists(r)}resolveParentsLists(e){for(const n of e)this.resolveParentsList(n)}parentIndexOf(e){if(e.parentId===null)return e.parentIndex;const n=this.sink.indexOf(e.parentId);return n!==A?n:(this.meta.sourceVersion==="1.0"?this.report.warnOnce("missing-value",Ov,`pid "${String(e.parentId)}" names no node; GEXF 1.0 files write it on top-level nodes, which stay top-level`,e.where):this.report.error("missing-value",Ui,`pid "${String(e.parentId)}" names a node the document does not declare`,e.where),null)}resolveParentsList(e){const{sink:n,report:i}=this,r=[];for(const s of e.ids){const o=n.indexOf(s);if(o===A){i.error("missing-value",Ui,`<parent for="${String(s)}"> names a node the document does not declare`,e.where);continue}r.push(o)}try{this.parentsColumn.set(n,i,e.child,r,e.where)}catch(s){i.recordError(s,e.where)}}startInEdges(e,n,i,r){if(n!=="edge"){this.unknownElement(e,r);return}this.beginEdge(i,r)}beginEdge(e,n){const{report:i,sink:r}=this;this.checkAbort(),this.ctx.push(13),this.edge=null;const s=e.get("source"),o=e.get("target"),l=e.get("id"),{where:a}=this.edgeFrame;if(a.line=n,a.element=l??EV(s,o),this.countInSection("edge"),this.checkAttributeNames(e,mV,"edge",a),s===void 0||o===void 0){i.error("missing-value",Zn,`<edge> without a ${s===void 0?"source":"target"}`,a),i.counts.skippedEdges++;return}const c=this.edgeKindOf(e,a);if(c===null){i.counts.skippedEdges++;return}if(l!==void 0&&this.edgeIds.has(l)){i.error("validation-error",Ai,`edge id "${l}" is declared more than once; the edge is skipped`,a),i.counts.skippedEdges++;return}let d;try{const[f,h]=this.endpoints(s,o,a),p=this.xmlWeight(e,a),g=r.edgeCount;d=this.resolver.addEdge(f,h,c,p,a),i.counts.edges+=r.edgeCount-g}catch(f){i.recordError(f,a),i.counts.skippedEdges++;return}l!==void 0&&this.edgeIds.add(l);const u=this.edgeFrame;u.index=d,u.mirror=this.resolver.lastMirror,u.xmlWeight=e.get("weight")??null,this.edge=u,this.writeEdgeAttributes(e,d,a)}edgeKindOf(e,n){const i=e.get("type");if(i===void 0)return this.defaultKind;const r=lp(i);return SS.has(r)?r:(this.report.error("validation-error",mv,`edge type "${i}" is not directed, undirected or mutual`,n),null)}endpoints(e,n,i){const{sink:r}=this,s=[this.coerceId(e,i),this.coerceId(n,i)];if(this.edgesFirst&&!this.nodesSeen)for(const a of s)r.indexOf(a)===A&&(this.implicitNodes.set(r.addNode(a),a),this.report.counts.nodes++);const o=[e,n],l=this.options.addMissingNodes?-1:s.findIndex(a=>r.indexOf(a)===A);if(l!==-1)throw new N("E_UNKNOWN_NODE",`edge references undeclared node "${o[l]}"`,{id:s[l]});return s}writeEdgeAttributes(e,n,i){const{report:r,sink:s}=this,o=e.get("id");try{o!==void 0&&this.edgeIdColumn.set(s,r,n,o,i);const l=e.get("label");l!==void 0&&this.edgeColumns.label.set(s,r,n,l,i);const a=e.get("kind");a!==void 0&&this.edgeKindColumn.set(s,r,n,a,i),this.writeLifetime(e,n,this.edgeColumns,i)}catch(l){r.recordError(l,i)}}dropUndeclaredNodes(){const{sink:e,report:n}=this,i=e;for(const[r,s]of this.implicitNodes)if(n.error("validation-error","E_UNKNOWN_NODE",`edge references undeclared node "${String(s)}"`),typeof i.removeNodeByIndex=="function"){const o=i.removeNodeByIndex(r);n.counts.nodes--,n.counts.edges-=o.length,n.counts.skippedEdges+=o.length}this.implicitNodes.clear()}xmlWeight(e,n){const i=e.get("weight");if(i===void 0)return;if(this.options.weightFrom===null){this.report.warnOnce("coercion",_v,"the weight attribute is ignored because weightFrom is null; edges are unweighted",n);return}const r=Kn(i,this.report);return this.checkOverflow(i,n),r}checkOverflow(e,n){Fp(e)&&this.report.warnOnce("precision",re,`weight ${e.trim()} is beyond the double range and is stored as Infinity`,n,`${re}:weight`)}startInEdge(e,n,i,r,s){const{edge:o}=this;if(o===null){this.ctx.push(14);return}switch(n){case"attvalues":this.attvalueIds.clear(),this.ctx.push(9);return;case"spells":this.spellPairs=[],this.spellOpen=[],this.spellsWhere=o.where,this.ctx.push(11);return;case"color":case"thickness":case"shape":if(!OS(e,s)){this.unknownElement(e,r);return}this.writeViz(e,n,i,"edge",o.index,o.where),this.ctx.push(14);return;default:this.unknownElement(e,r)}}startInAttvalues(e,n,i,r){if(n!=="attvalue"){this.unknownElement(e,r);return}this.ctx.push(14),this.checkAttributes("attvalue",i,r);const{report:s,edge:o}=this,l=o===null?"node":"edge";let a,c;if(o!==null)({index:a}=o),c=o.where.element??null;else{const h=this.nodeStack[this.nodeStack.length-1];({index:a}=h),c=h.where.element??null}if(a===A)return;const d=i.get("for")??i.get("id"),{valueWhere:u}=this;if(u.line=r,u.element=c,d===void 0){s.warning("missing-value",Hg,"<attvalue> without a for attribute",u);return}const f=i.get("value");if(f===void 0){s.warning("missing-value",Hg,`<attvalue for="${d}"> without a value attribute`,u);return}Vc(i)||(this.attvalueIds.has(d)&&s.warning("validation-error",fe,`a second static <attvalue for="${d}"> on one ${l}; the later value "${f}" is kept`,{...u,element:d}),this.attvalueIds.add(d));try{if(l==="edge"&&this.weightAttr!==null&&this.weightAttr.id===d){Vc(i)?this.writeTimedWeight(i,f,a,u):this.applyStaticWeight(f,u);return}const p=(l==="node"?this.nodeAttrs:this.edgeAttrs).get(d);if(p===void 0){const g=`${l}:${d}`;this.unknownAttributes.has(g)||(this.unknownAttributes.add(g),s.warning("missing-value",Bg,`<attvalue for="${d}"> names an undeclared ${l} attribute; its values are dropped`,{...u,element:d}));return}Vc(i)?this.writeTimedValue(p,l,i,f,a,u):this.writeStaticValue(p,l,f,a,u)}catch(h){s.recordError(h,{...u,element:`${c??"?"}[${d}]`})}}applyStaticWeight(e,n){const{edge:i,sink:r}=this;if(i===null)return;const s=Kn(e,this.report);s!==void 0&&(this.checkOverflow(e,n),i.xmlWeight!==null&&this.report.warning("validation-error",fe,`the edge has both weight="${i.xmlWeight}" and a weight attvalue "${e}"; the attvalue is kept`,n),r.setEdgeWeight(i.index,s),i.mirror!==A&&r.setEdgeWeight(i.mirror,s))}writeStaticValue(e,n,i,r,s){const{spec:o}=e;if(o.temporal!==null&&!o.list){const a=zp(i,o);this.setCell(n,e.handle,r,a.value),a.text!==null&&e.companionDecl!==null&&(e.companion===A&&(e.companion=wy(this.sink,n,e.companionDecl,this.report)),this.setCell(n,e.companion,r,a.text));return}const l=ma(i,o,e.listSyntax);Qd(o,i)?this.report.warning("precision",re,`long value ${i.trim()} of "${e.name}" exceeds 2^53 and was rounded`,s):typeof l=="number"&&Fp(i)&&this.report.warnOnce("precision",re,`values of "${e.name}" beyond the double range (${i.trim()}) are stored as Infinity`,s,`${re}:overflow:${e.name}`),this.checkOptions(e,l,s),this.setCell(n,e.handle,r,l)}checkOptions(e,n,i){const{options:r}=e.valueDecl;if(r===void 0||r.length===0)return;const o=(Array.isArray(n)?n:[n]).find(l=>!r.includes(l));(typeof o=="string"||typeof o=="number"||typeof o=="boolean")&&this.report.warnOnce("validation-error",Yg,`"${o}" is not among the options of attribute "${e.name}"; the value is kept`,i,`${Yg}:${e.name}`)}writeTimedValue(e,n,i,r,s,o){const{sink:l,report:a}=this;e.dynamic||a.warnOnce("validation-error",wv,`attribute "${e.name}" is declared static but has timed values; they are stored as dynamic`,o);const{spec:c}=e,d=c.temporal!==null&&!c.list;e.table===A&&(e.table=l.addExtensionTable(Fg(n,e.name),uS(n,e.valueDecl,d)));let u,f=null;if(d){const p=zp(r,c);({value:u}=p),f=p.text}else u=ma(r,c,e.listSyntax),Qd(c,r)&&a.warning("precision",re,`long value ${r.trim()} of "${e.name}" exceeds 2^53 and was rounded`,o);const h=this.temporalRow(i,s,u,o);h!==null&&(d&&h.push(f??void 0),l.addExtensionRow(e.table,h))}writeTimedWeight(e,n,i,r){const{weightAttr:s}=this;if(s===null)return;const{sink:o}=this;s.table===A&&(s.table=o.addExtensionTable(Fg("edge",this.options.weightFrom??"weight"),uS("edge",{dtype:"f64",origin:{format:Mi,id:s.id,type:s.spec.declared}},!1)));const l=Kn(n,this.report);if(l===void 0)return;const a=this.temporalRow(e,i,l,r);a!==null&&o.addExtensionRow(s.table,a)}temporalRow(e,n,i,r){const s=this.readBounds(e,r);return s===null?null:[n,s.start.value,s.end.value,i,s.start.text??void 0,s.end.text??void 0,s.open===0?void 0:s.open]}readBounds(e,n){let i={value:-1/0,text:null},r={value:1/0,text:null},s=0;const o=e.get("timestamp");o!==void 0&&(i=qi(o,this.timeFormat),r=i,(e.has("start")||e.has("end")||e.has("startopen")||e.has("endopen"))&&this.report.warnOnce("validation-error",Tv,"both timestamp and start / end are given; start / end set the interval and the timestamp is kept as written",n));const l=e.get("start"),a=e.get("startopen");l!==void 0?(i=qi(l,this.timeFormat),a!==void 0&&this.warnOpenConflict("start",n)):a!==void 0&&(i=qi(a,this.timeFormat),s|=Ff);const c=e.get("end"),d=e.get("endopen");return c!==void 0?(r=qi(c,this.timeFormat),d!==void 0&&this.warnOpenConflict("end",n)):d!==void 0&&(r=qi(d,this.timeFormat),s|=zf),i.value>r.value?(this.report.error("validation-error",ie,`the interval starts after it ends (${i.text??String(i.value)} > ${r.text??String(r.value)}); it is not kept`,n),null):{start:i,end:r,open:s}}warnOpenConflict(e,n){this.report.warnOnce("validation-error",Av,`both ${e} and ${e}open are given; the closed bound is kept`,n)}writeLifetime(e,n,i,r){const{sink:s,report:o}=this;if(e.has("start")||e.has("end")||e.has("timestamp")||e.has("startopen")||e.has("endopen")){const c=this.readBounds(e,r);if(c===null)return;const d=e.get("timestamp");d!==void 0&&i.timestamp.set(s,o,n,qi(d,this.timeFormat),r),(e.has("start")||e.has("startopen"))&&i.start.set(s,o,n,c.start,r),(e.has("end")||e.has("endopen"))&&i.end.set(s,o,n,c.end,r),c.open!==0&&i.open.set(s,o,n,c.open,r)}const l=e.get("timestamps");if(l!==void 0){const c=pa(NS(l),"brackets");i.timestamps.set(s,o,n,c.map(d=>qi(d,this.timeFormat).value),r)}const a=e.get("intervals");a!==void 0&&i.spells.set(s,o,n,this.parseIntervals(a,r),r)}parseIntervals(e,n){const i=[];for(const r of NS(e).split(";")){if(r.trim().length===0)continue;const s=pa(r,"brackets");if(s.length!==2)throw new N("E_COLUMN_TYPE",`interval "${r.trim()}" is not a [start, end] pair`,{value:r,line:n.line??null});const o=[qi(s[0],this.timeFormat).value,qi(s[1],this.timeFormat).value];if(o[0]>o[1]){this.report.error("validation-error",ie,`interval "${r.trim()}" starts after it ends; it is not kept`,n);continue}i.push(o)}return i}startInSpells(e,n,i,r){if(n!=="spell"){this.unknownElement(e,r);return}this.ctx.push(14),this.checkAttributes("spell",i,r);const s=this.spellsWhere??{line:r};try{const o=this.readBounds(i,s);if(o===null)return;this.spellPairs?.push([o.start.value,o.end.value]),this.spellOpen.push(o.open)}catch(o){this.report.recordError(o,s)}}finishSpells(){const e=this.spellPairs,n=this.spellOpen,i=this.spellsWhere??void 0;if(this.spellPairs=null,this.spellOpen=[],this.spellsWhere=null,e!==null)try{const r=this.edge===null?this.nodeColumns:this.edgeColumns,{index:s}=this.edge??this.nodeStack[this.nodeStack.length-1];s!==A&&(r.spells.set(this.sink,this.report,s,e,i),n.some(o=>o!==0)&&r.spellsOpen.set(this.sink,this.report,s,n,i))}catch(r){this.report.recordError(r,i)}}writeVizPosition(e,n,i){const r=Ci(e,"x"),s=Ci(e,"y"),o=e.has("z")?Ci(e,"z"):0;this.positionColumn??=new Pe("node",{...Ft.position,extra:{...Ft.position.extra,sourceDims:e.has("z")?3:2}}),this.positionColumn.set(this.sink,this.report,n,[r,s,o],i)}writeVizShape(e,n,i,r,s){const o=n.get("value");if(o===void 0)throw new N("E_COLUMN_TYPE","<viz:shape> without a value",{element:e});(i==="node"?this.nodeColumns:this.edgeColumns).shape.set(this.sink,this.report,r,o,s);const a=n.get("uri");i==="node"&&a!==void 0&&this.shapeUriColumn.set(this.sink,this.report,r,a,s)}writeViz(e,n,i,r,s,o){const{sink:l,report:a}=this;if(!this.viz){a.warnOnce("unsupported",Sv,"viz elements are skipped (option viz: false)",o);return}Vc(i)&&a.warnOnce("unsupported",Nv,"dynamic viz elements are not supported; the bounds are dropped and the last value kept",o);const c=r==="node"?this.nodeColumns:this.edgeColumns;try{switch(n){case"color":c.color.set(l,a,s,this.vizColor(i,e,o),o);break;case"position":this.writeVizPosition(i,s,o);break;case"size":this.sizeColumn.set(l,a,s,Ci(i,"value"),o);break;case"thickness":this.thicknessColumn.set(l,a,s,Ci(i,"value"),o);break;case"shape":this.writeVizShape(e,i,r,s,o);break;default:break}}catch(d){if(!(d instanceof N)||d.code!=="E_COLUMN_TYPE")throw d;a.warning("validation-error",Vg,`<${e}> skipped: ${d.message}`,o)}}vizColor(e,n,i){const r=e.get("hex");let s;if(r!==void 0){const l=NH(r);if(l===null)throw new N("E_COLUMN_TYPE",`viz hex="${r}" is not a color Gephi reads (a #-prefixed hexadecimal, 0x, octal or decimal integer)`,{attribute:"hex"});s=[...l],e.has("a")&&(s[3]=Ci(e,"a"))}else s=[Ci(e,"r"),Ci(e,"g"),Ci(e,"b")],s.push(e.has("a")?Ci(e,"a"):1);const o=[255,255,255,1];return s.some((l,a)=>l<0||l>o[a])&&(this.report.warning("validation-error",Vg,`<${n}> has a channel outside 0..255 or an alpha outside 0..1; clamped`,i),s=s.map((l,a)=>Math.max(0,Math.min(o[a],l)))),[s[0]/255,s[1]/255,s[2]/255,s[3]]}unknownElement(e,n){this.report.warnOnce("unsupported",vt,`element <${e}> is not GEXF and was skipped`,{line:n,element:e}),this.ctx.push(14)}checkAttributeNames(e,n,i,r){if(e.size!==0)for(const s of e.keys()){if(n.has(s)||s==="xmlns"||/^(xmlns|xml|xsi):/.test(s))continue;let o=this.unknownNames.get(i);if(o===void 0&&(o=new Set,this.unknownNames.set(i,o)),!o.has(s)){if(o.add(s),o.size>oV){this.unknownOverflow.set(i,(this.unknownOverflow.get(i)??0)+1);continue}this.report.warning("unsupported",Bd,`attribute ${s} of <${i}> is not GEXF and was ignored`,{...r,element:s})}}}checkAttributes(e,n,i){this.checkAttributeNames(n,lV[e]??new Set,e,{line:i})}setCell(e,n,i,r){e==="node"?this.sink.setNodeValue(n,i,r):this.sink.setEdgeValue(n,i,r)}coerceId(e,n){const i=this.coercer.text(e),r=this.coercer.lastMerge;return r!==null&&this.report.warning("coercion",Rn,`id text "${r.text}" merged with "${r.previousText}" as ${r.id} under ids "number"`,n),i}checkAbort(){++this.elementsSinceCheck>=pV&&(this.elementsSinceCheck=0,F(this.options.signal))}}function OS(t,e){return sV(e)||e===null&&t.startsWith("viz:")}function EV(t,e){return`${t??"?"}->${e??"?"}`}function Vc(t){return t.has("start")||t.has("end")||t.has("timestamp")||t.has("startopen")||t.has("endopen")}function NS(t){let e=t.trim();return e.startsWith("<")&&(e=e.slice(1)),e.endsWith(">")&&(e=e.slice(0,-1)),e}function Ci(t,e){const n=t.get(e);if(n===void 0)throw new N("E_COLUMN_TYPE",`viz element without a ${e} attribute`,{attribute:e});const i=by(n);if(Number.isNaN(i))throw new N("E_COLUMN_TYPE",`viz ${e}="${n}" is not a number`,{attribute:e});return i}const wV=/^\uFEFF?\s*</;function _V(t){const e=_T(t);return wV.test(e)?/<(\w+:)?gexf[\s>]/.test(e)?1:e.includes("gexf.net")?.8:0:0}function SV(t){const e=t?.viz;if(e===void 0)return!0;if(typeof e!="boolean")throw new N("E_UNSUPPORTED",`option viz: ${typeof e} is not a boolean`,{option:"viz",found:e});return e}function OV(t){const e=t?.gephiPreview;if(e===void 0)return null;const n=r=>{throw new N("E_UNSUPPORTED","option gephiPreview: not an object of Preview property values",{option:"gephiPreview",found:r})};if(typeof e!="object"||e===null||Array.isArray(e))return n(e);const i={};for(const[r,s]of Object.entries(e)){if(typeof s!="string"&&typeof s!="number"&&typeof s!="boolean")return n(s);i[r]=String(s)}return i}const NV=Object.freeze({format:Mi,options:Object.freeze(["viz","gephiPreview"]),extensions:Object.freeze([".gexf"]),mimeTypes:Object.freeze(["application/gexf+xml","application/xml","text/xml"]),sniff:_V,styles:VH,async import(t,e,n){const i=tt(n,{ids:"canonical",defaultDirected:!1,weightFrom:"weight",addMissingNodes:!1}),r=SV(n),s=new ne(Mi,i.errorLimit);_t(e,n,s,!0),St(n,s,yV);const o=new bV(e,s,i,r);try{await ff($r(t,s,{...i,declaredEncoding:uf,xml:!0}),o)}catch(a){throw a instanceof $y&&s.fail(Ut,"the input is empty (no markup at all)",{line:a.line}),a instanceof te&&s.fail(a instanceof df?Xu:Ku,a.message,{line:a.line}),a}o.finish();const l=OV(n);return l!==null&&s.keepForStyles({block:o.keptBlock,gephiPreview:l}),F(i.signal),s.finish()}}),nn=Object.freeze({KIND_DROPPED:"W_GEXF_KIND_DROPPED",TIMESTAMP_AS_INTERVAL:"W_TIMESTAMP_AS_INTERVAL",LIST_SEPARATOR:"W_LIST_SEPARATOR",ROLE_SHAPE:"W_ROLE_SHAPE",TEMPORAL_TABLE_SHAPE:"W_TEMPORAL_TABLE_SHAPE",ATTRIBUTE_RENAMED:"W_ATTRIBUTE_RENAMED",VALUE_UNWRITABLE:"W_VALUE_UNWRITABLE",DECLARED_TYPE:"W_DECLARED_TYPE",ID_TEXT_TYPE:w.ID_TEXT_TYPE,EDGE_ID_TEXT:"W_GEXF_EDGE_ID_TEXT",VIZ_DTYPE:"W_GEXF_VIZ_DTYPE",WEIGHT_KEY_CLASH:w.WEIGHT_KEY_CLASH,OPTIONS_GAINED:w.OPTIONS_GAINED,XML_ILLEGAL_CHAR:w.XML_ILLEGAL_CHAR}),AV=["f32","f64","i32","bool","dict","string"],Bb=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:AV,lists:!0,defaults:!0,options:!0,hierarchy:!0,temporal:"dynamic-values",positions:!0,viz:!0}),TV=Je({...Bb,multiEdges:!1,edgeIds:"required"}),IV=new Set(["directed","pair","mutual","weight","timeText"]),$V="weight",fc=new Set(["f32","f64","i32","u32","u8"]),CV=new Set(["string","dict"]);function vV(t){const e=t?.version;if(e===void 0)return"1.3";if(e!=="1.2"&&e!=="1.3")throw new N("E_UNSUPPORTED",`option version: ${JSON.stringify(e)} is not "1.2" or "1.3"`,{option:"version",found:e,supported:["1.2","1.3"]});return e}function Iv(t,e){const n=vV(e),i=ft(e),s=[...Un(t,n==="1.2"?TV:Bb,i,{openIntervals:n==="1.2",temporalText:!0,positionDtype:"f64",roles:$v,roleNames:n==="1.2"?RV:Cv})],o=(y,b,_=null,S=null)=>{s.push(Object.freeze({code:y,message:b,column:_,count:S}))};s.push(...ky(t));let l=0;for(let y=0;y<t.nodeCount;y++){const b=t.ids.idOf(y);(typeof b=="number"?!Number.isSafeInteger(b):tu(b))&&l++}l>0&&o(nn.ID_TEXT_TYPE,`${l} node id${O(l)} ${C(l,"changes","change")} type when read back under ids: "canonical" (string ids that are integer text, non-integer numbers); the file's idtype is not honored by the importer`,null,l);const a=t.edges.byRole("id");a!==null&&a.dtype!=="string"&&a.dtype!=="dict"&&o(nn.EDGE_ID_TEXT,`edge id column "${a.meta.name}" is ${a.dtype}; GEXF edge ids read back as strings`,a.meta.name,t.edgeCount-a.nullCount);const c=PV(t,n,o),d=$S(t.nodes,"node",o),u=$S(t.edges,"edge",o),f=DS(t,"node",d,c.get("node")??new Map,n,o),h=DS(t,"edge",u,c.get("edge")??new Map,n,o),p=AS(d)||AS(u)||f.some(y=>y.dynamic)||h.some(y=>y.dynamic);if(n==="1.2"){for(const[y,b]of[["node",d],["edge",u]])(b.timestamp!==null||b.timestamps!==null)&&o(nn.TIMESTAMP_AS_INTERVAL,`${y} timestamps are written as closed intervals; GEXF 1.2 has no timestamp representation`,(b.timestamp??b.timestamps)?.meta.name??null,null);ta(t,"timestamp")!==null&&o(nn.TIMESTAMP_AS_INTERVAL,"the graph timestamp is written as a closed interval (start = end); GEXF 1.2 has no timestamp representation",null,null),u.kind!==null&&o(nn.KIND_DROPPED,`edge column "${u.kind.meta.name}" (kind) cannot be written; GEXF 1.2 has no edge kind`,u.kind.meta.name,u.kind.length-u.kind.nullCount)}const{meta:g}=t;let{timeRepresentation:m}=g;return m===null&&p&&(m=(d.timestamp!==null||u.timestamp!==null)&&d.start===null&&d.end===null&&u.start===null&&u.end===null?"timestamp":null),{version:n,options:i,notes:s,nodeRoles:d,edgeRoles:u,nodeAttrs:f,edgeAttrs:h,timeFormat:g.timeFormat,temporal:p,timeRepresentation:m}}function AS(t){return t.start!==null||t.end!==null||t.timestamp!==null||t.spells!==null||t.timestamps!==null}function ks(t){return fc.has(t.dtype)&&t.meta.components===1}function TS(t,e){return fc.has(t.dtype)&&e.includes(t.meta.components)}function ap(t){return CV.has(t.dtype)}function IS(t,e){return t.dtype==="list"&&t.meta.itemDtype!==null&&fc.has(t.meta.itemDtype)&&(t.meta.itemComponents??1)===e}function DV(t,e,n){switch(t){case"label":case"shape":return ap(e);case"kind":return n==="edge"&&ap(e);case"id":return n==="edge"&&(ap(e)||ks(e));case"start":case"end":case"timestamp":case"open":return ks(e);case"size":return n==="node"&&ks(e);case"thickness":return n==="edge"&&ks(e);case"spells":return IS(e,2);case"spellsOpen":return e.dtype==="list"&&e.meta.itemDtype==="u8";case"timestamps":return IS(e,1);case"position":return n==="node"&&TS(e,[2,3]);case"color":return TS(e,[3,4]);case"parent":return n==="node"&&e.dtype==="u32"&&e.meta.components===1;case"parents":return n==="node"&&e.dtype==="list"&&e.meta.itemDtype==="u32";default:return!1}}const kV=new Set(["position","color","size","thickness"]),$v=new Set(["label","id","kind","start","end","timestamp","spells","spellsOpen","timestamps","open","position","color","size","shape","thickness","parent","parents"]),Cv=Object.freeze({label:ce.label,id:"id",kind:"kind",start:ce.start,end:ce.end,timestamp:ce.timestamp,spells:ce.spells,spellsOpen:ce.spellsOpen,timestamps:ce.timestamps,open:ce.open,position:ce.position,color:ce.color,size:ce.size,shape:ce.shape,thickness:"thickness",parent:ce.parent,parents:ce.parents}),RV=Object.freeze(Object.fromEntries(Object.entries(Cv).filter(([t])=>t!=="kind")));function $S(t,e,n){const i=new Map,r={label:null,id:null,kind:null,start:null,end:null,timestamp:null,spells:null,spellsOpen:null,timestamps:null,open:null,position:null,color:null,size:null,shape:null,shapeUri:null,thickness:null,parent:null,parents:null,companions:i};for(const s of t){const{meta:o}=s,l=o.extra.for;if((o.role==="timeText"||typeof l=="string")&&s.dtype==="string"){typeof l=="string"&&i.set(l,s);continue}if(e==="node"&&o.name===ce.shapeUri&&o.origin?.namespace===jf){r.shapeUri=s.dtype==="string"?s:null;continue}const{role:a}=o;if(a===null||!$v.has(a))continue;if(!DV(a,s,e)){n(nn.ROLE_SHAPE,`${e} column "${o.name}" (${a}) has a shape GEXF cannot map (${LV(s)}); written as a plain attribute`,o.name,null);const d=s.length-s.nullCount;fc.has(s.dtype)&&o.components>1&&n(w.COMPONENTS,`${e} column "${o.name}" has ${o.components} components; written as a list`,o.name,d),s.dtype==="json"&&n(w.JSON,`${e} column "${o.name}" holds nested values; written as JSON text`,o.name,d),(s.dtype==="u32"||s.dtype==="u8")&&n(w.DTYPE,`${e} column "${o.name}" is ${s.dtype}; the format cannot keep that dtype`,o.name,d);continue}const c=a==="position"?"f64":"f32";kV.has(a)&&s.dtype!==c&&n(nn.VIZ_DTYPE,`${e} column "${o.name}" (${a}) is ${s.dtype}; viz values read back as ${c}`,o.name,s.length-s.nullCount),r[a]=s}return r}function LV(t){return t.dtype==="list"?`list of ${t.meta.itemDtype??"?"} x ${t.meta.itemComponents??1}`:`${t.dtype} x ${t.meta.components}`}function PV(t,e,n){const i=new Map;for(const[r,s]of t.extensions){const o=aH(r);if(o===null)continue;const l=s.get(Me.element),a=s.get(Me.start),c=s.get(Me.end),d=s.get(Me.value);if(l?.dtype!=="u32"||a===null||!ks(a)||c===null||!ks(c)||d===null){n(nn.TEMPORAL_TABLE_SHAPE,`extension table "${r}" lacks the element / start / end / value columns and cannot be written`,r,s.rowCount);continue}const u=new Map;for(let m=0;m<s.rowCount;m++){if(!l.isSet(m))continue;const y=l.value(m),b=u.get(y);b===void 0?u.set(y,[m]):b.push(m)}const f=Kg(d,e),h=xV(s.get(Me.open));e==="1.3"&&h!==null&&h.length-h.nullCount>0&&n(w.OPEN_INTERVAL,`dynamic values of "${r}" carry open intervals, which GEXF 1.3 cannot write`,r,h.length-h.nullCount);const p={element:l,start:a,end:c,value:d,startText:cp(s.get(Me.startText)),endText:cp(s.get(Me.endText)),valueText:Xg(f.type)?cp(s.get(Me.valueText)):null,open:h,rows:u,format:f.format};let g=i.get(o.domain);g===void 0&&(g=new Map,i.set(o.domain,g)),g.set(o.column,p)}return i}function cp(t){return t!==null&&t.dtype==="string"?t:null}function xV(t){return t!==null&&ks(t)?t:null}function Kg(t,e){const{meta:n}=t,i=n.origin?.type??null;if(n.dtype==="list"||fc.has(n.dtype)&&n.components>1){const l=n.dtype==="list"?n.itemDtype??"string":n.dtype;let a=fS(l);if(i!==null&&n.dtype==="list"&&dH(i)&&CS(i,"list",l)&&(a=i.slice(4)),e==="1.2"){const c=vd(a,l);return{type:"liststring",list:!0,itemType:"string",format:vS(c,e),dropped:a==="string"?null:`list${a}`}}return{type:`list${a}`,list:!0,itemType:a,format:vS(vd(a,l),e),dropped:null}}let r=fS(n.dtype),s=null;const o=i===null||n.dtype!=="f64"?null:MV(i);return o!==null?$d(o,e)?r=o:s=o:i!==null&&CS(i,n.dtype,null)&&($d(i,e)?r=i:$d(i,"1.3")&&(s=i)),{type:r,list:!1,itemType:r,format:vd(r,n.dtype),dropped:s}}function MV(t){switch(t.toLowerCase()){case"date":return"date";case"datetime":case"localdatetime":return"dateTime";default:return null}}function CS(t,e,n){const i=yy("gexf",t,"f64");return i===null?!1:e==="list"?i.list&&i.itemDtype===n:i.list?!1:i.dtype===e||e==="dict"&&i.dtype==="string"}function vd(t,e){switch(t){case"boolean":return n=>typeof n=="boolean"?n?"true":"false":typeof n!="number"?null:n!==0?"true":"false";case"integer":case"long":case"byte":case"short":case"biginteger":return n=>typeof n=="number"?Number.isInteger(n)?Ge(n):Fe(n):typeof n=="string"?n:null;case"float":return n=>typeof n=="number"?ct(n):null;case"double":case"bigdecimal":return n=>typeof n=="number"?e==="f32"?ct(n):Fe(n):typeof n=="string"?n:null;case"date":case"dateTime":return n=>typeof n=="number"?ha(n,t):typeof n=="string"?n:null;default:return n=>{switch(typeof n){case"string":return n;case"number":return e==="f32"?ct(n):Fe(n);case"boolean":return n?"true":"false";case"object":return n===null?null:JSON.stringify(n);default:return null}}}}function vS(t,e){return n=>{if(!Array.isArray(n)&&!ArrayBuffer.isView(n))return null;const i=[];for(const r of Array.from(n)){const s=t(r);if(s===null)return null;i.push(s)}return Ey(i,e==="1.2"?"pipe":"gexf")}}function DS(t,e,n,i,r,s){const o=e==="node"?t.nodes:t.edges,l=e==="node"?QC:ev,a=new Set,{companions:c,...d}=n;for(const g of Object.values(d))g!==null&&a.add(g);const u=new Set,f=[],h=new Set,p=(g,m,y,b,_,S)=>{const T=GV(y.id??m,m,u),$=y.title??m;b.dropped!==null&&s(nn.DECLARED_TYPE,`${e} column "${m}" is declared ${b.dropped}, which GEXF ${r} lacks; written as ${b.type}`,m,null),e==="edge"&&g!==null&&g.meta.role===null&&$===$V&&s(nn.WEIGHT_KEY_CLASH,`edge column "${m}" is written as an attribute titled "${$}", which the importer reads as the edge weight (weightFrom); it reads back as the weight, not as a column`,m,g.length-g.nullCount);const D=l.has($)?`${$}#${T}`:$;D!==m&&s(nn.ATTRIBUTE_RENAMED,`${e} column "${m}" is written with title "${$}" and reads back as "${D}"`,m,null);const{defaultText:x,optionsText:R}=g===null?{defaultText:null,optionsText:null}:UV(g,e,b,r,s),G=g===null?null:n.companions.get(m)??null;G!==null&&!Xg(b.type)&&s(w.TEMPORAL_TEXT,`${e} column "${G.meta.name}" (the lexical form of "${m}") cannot be written: "${m}" is written as ${b.type}, not a GEXF temporal type`,G.meta.name,G.length-G.nullCount),f.push({id:T,title:$,type:b.type,column:g,companion:Xg(b.type)?G:null,format:b.format,defaultText:x,optionsText:R,dynamic:_,table:S})};for(const g of o){const{meta:m}=g;if(a.has(g)||m.role!==null&&IV.has(m.role)||typeof m.extra.for=="string"&&g.dtype==="string"||e==="node"&&g===n.shapeUri)continue;const y=i.get(m.name)??null;y!==null&&h.add(m.name),p(g,m.name,{id:m.origin?.id??null,title:m.origin?.title??null},Kg(g,r),m.dynamic||y!==null,y)}for(const[g,m]of i){if(h.has(g))continue;const{origin:y}=m.value.meta,{weightOrigin:b}=t.meta,_=e==="edge"&&b!==null&&(b.title??b.id)===g?b.id:null;p(null,g,{id:y?.id??_,title:null},Kg(m.value,r),!0,m)}return f}function UV(t,e,n,i,r){const{meta:s}=t,{name:o}=s;let l=null,a=null;s.default!==void 0&&(l=n.format(s.default),l===null&&r(nn.VALUE_UNWRITABLE,`${e} column "${o}": the default cannot be written as ${n.type}`,o,null));const c=s.options??(t.dtype==="dict"?t.dictionary:null);if(s.options===null&&c!==null&&c.length>0&&r(nn.OPTIONS_GAINED,`${e} column "${o}" declares no options; its dictionary is written as <options> and reads back as declared options`,o,null),c!==null){const d=n.list?vd(n.itemType,s.itemDtype??"string"):n.format,u=[];let f=!0;for(const h of c){const p=d(h);if(p===null){f=!1;break}u.push(p)}f?a=Ey(u,i==="1.2"?"pipe":"gexf"):r(nn.VALUE_UNWRITABLE,`${e} column "${o}": the options cannot be written as ${n.type}`,o,null)}if(i==="1.2"&&t.dtype==="list"){let d=0;for(let u=0;u<t.length;u++)t.isSet(u)&&Fo(t,u).some(f=>String(f).includes("|"))&&d++;d>0&&r(nn.LIST_SEPARATOR,`${e} column "${o}": ${d} row${O(d)} ${C(d,"holds","hold")} an item containing "|", the 1.2 list separator`,o,d)}return{defaultText:l,optionsText:a}}function Xg(t){return t==="date"||t==="dateTime"}function GV(t,e,n){const i=[t,e];for(const r of i)if(r.length>0&&!n.has(r))return n.add(r),r;for(let r=2;;r++){const s=`${e}#${r}`;if(!n.has(s))return n.add(s),s}}function Dd(t,e,n,i){return e?.isSet(n)?e.value(n):Jd(t.value(n),i)}function kS(t,e,n){let i="";const{timeFormat:r,version:s}=n;let o=0;s==="1.2"&&t.open?.isSet(e)&&(o=t.open.value(e));const l=(a,c,d)=>{if(!c?.isSet(e))return;const u=c.value(e);if(!Number.isFinite(u))return;const f=Dd(c,t.companions.get(c.meta.name)??null,e,r),h=d?`${a}open`:a;i+=` ${h}="${W(f)}"`};if(t.timestamp?.isSet(e)?s==="1.3"&&n.timeRepresentation==="timestamp"?l("timestamp",t.timestamp,!1):(l("start",t.timestamp,!1),l("end",t.timestamp,!1)):(l("start",t.start,(o&Ff)!==0),l("end",t.end,(o&zf)!==0)),s==="1.3"&&t.timestamps?.isSet(e)){const c=`<[${Fo(t.timestamps,e).map(d=>Jd(d,r)).join(", ")}]>`;i+=` timestamps="${W(c)}"`}return i}function jV(t,e,n,i){let r="";if(Number.isFinite(t)){const s=(n&Ff)===0?"start":"startopen";r+=` ${s}="${W(Jd(t,i.timeFormat))}"`}if(Number.isFinite(e)){const s=(n&zf)===0?"end":"endopen";r+=` ${s}="${W(Jd(e,i.timeFormat))}"`}return r}function RS(t,e,n,i){const r=[];if(t.spells?.isSet(e)){const o=n.version==="1.2"&&t.spellsOpen?.isSet(e)?Fo(t.spellsOpen,e):[];Fo(t.spells,e).forEach((l,a)=>{const[c,d]=Array.from(l);r.push([c,d,o[a]??0])})}if(n.version==="1.2"&&t.timestamps?.isSet(e))for(const o of Fo(t.timestamps,e))r.push([o,o,0]);if(r.length===0)return"";let s=`${i}<spells>
|
|
99
|
+
`;for(const[o,l,a]of r)s+=`${i} <spell${jV(o,l,a,n)}/>
|
|
100
|
+
`;return`${s}${i}</spells>
|
|
101
|
+
`}function LS(t,e,n,i){let r="";for(const s of t){const{column:o}=s;if(o?.isSet(e)){let c;s.companion?.isSet(e)?c=s.companion.value(e):c=s.format(PS(o,e)),c!==null&&(r+=`${i} <attvalue for="${W(s.id)}" value="${W(c)}"/>
|
|
102
|
+
`)}const{table:l}=s;if(l===null)continue;const a=l.rows.get(e);if(a!==void 0)for(const c of a){if(!l.value.isSet(c))continue;let d;l.valueText?.isSet(c)?d=l.valueText.value(c):d=l.format(PS(l.value,c)),d!==null&&(r+=`${i} <attvalue for="${W(s.id)}" value="${W(d)}"${FV(l,c,n)}/>
|
|
103
|
+
`)}}return r.length===0?"":`${i}<attvalues>
|
|
104
|
+
${r}${i}</attvalues>
|
|
105
|
+
`}function FV(t,e,n){const i=t.start.isSet(e)?t.start.value(e):-1/0,r=t.end.isSet(e)?t.end.value(e):1/0;let s="";if(n.version==="1.3"&&n.timeRepresentation==="timestamp"&&i===r&&Number.isFinite(i))return` timestamp="${W(Dd(t.start,t.startText,e,n.timeFormat))}"`;let o=0;if(n.version==="1.2"&&t.open?.isSet(e)&&(o=t.open.value(e)),Number.isFinite(i)){const l=(o&Ff)!==0?"startopen":"start";s+=` ${l}="${W(Dd(t.start,t.startText,e,n.timeFormat))}"`}if(Number.isFinite(r)){const l=(o&zf)!==0?"endopen":"end";s+=` ${l}="${W(Dd(t.end,t.endText,e,n.timeFormat))}"`}return s}function PS(t,e){switch(t.dtype){case"list":return t.sliceOf(e);case"json":return t.values[e];default:{const n=t.value(e);return ArrayBuffer.isView(n)?Array.from(n):n}}}function zV(t){if(t===null||t.meta.components<3)return!1;if(t.meta.extra.sourceDims!==2)return!0;const{components:e}=t.meta;let n;switch(t.dtype){case"f32":case"f64":case"i32":case"u32":case"u8":({data:n}=t);break;default:return!0}for(let i=0;i<t.length;i++)if(t.isSet(i)&&n[i*e+2]!==0)return!0;return!1}function Fo(t,e){return t.dtype==="list"?t.sliceOf(e):[]}function xS(t,e,n,i){let r="";const{color:s}=t;if(s?.isSet(e)){const a=Array.from(s.value(e)),c=s.dtype==="u8"?1:255,d=f=>String(Math.max(0,Math.min(255,Math.round(f*c))));let u=` r="${d(a[0])}" g="${d(a[1])}" b="${d(a[2])}"`;if(a.length>3){const f=s.dtype==="u8"?a[3]/255:a[3];f!==1&&(u+=` a="${ct(Math.fround(f))}"`)}r+=`${n}<viz:color${u}/>
|
|
106
|
+
`}const{position:o}=t;if(o?.isSet(e)){const a=Array.from(o.value(e)),c=o.dtype==="f32"?ct:Fe;let d=` x="${c(a[0])}" y="${c(a[1])}"`;a.length>2&&i&&(d+=` z="${c(a[2])}"`),r+=`${n}<viz:position${d}/>
|
|
107
|
+
`}for(const[a,c]of[["size",t.size],["thickness",t.thickness]])if(c?.isSet(e)){const d=c.value(e),u=c.dtype==="f32"?ct(d):Fe(d);r+=`${n}<viz:${a} value="${W(u)}"/>
|
|
108
|
+
`}const{shape:l}=t;if(l?.isSet(e)){let a=` value="${W(String(l.value(e)))}"`;t.shapeUri?.isSet(e)&&(a+=` uri="${W(t.shapeUri.value(e))}"`),r+=`${n}<viz:shape${a}/>
|
|
109
|
+
`}return r}function MS(t,e,n){let i="";for(const r of["static","dynamic"]){const s=e.filter(o=>o.dynamic===(r==="dynamic"));if(s.length!==0){i+=`${n}<attributes class="${t}" mode="${r}">
|
|
110
|
+
`;for(const o of s){const l=`${n} <attribute id="${W(o.id)}" title="${W(o.title)}" type="${o.type}"`;if(o.defaultText===null&&o.optionsText===null){i+=`${l}/>
|
|
111
|
+
`;continue}i+=`${l}>
|
|
112
|
+
`,o.defaultText!==null&&(i+=`${n} <default>${nt(o.defaultText)}</default>
|
|
113
|
+
`),o.optionsText!==null&&(i+=`${n} <options>${nt(o.optionsText)}</options>
|
|
114
|
+
`),i+=`${n} </attribute>
|
|
115
|
+
`}i+=`${n}</attributes>
|
|
116
|
+
`}}return i}function US(t,e,n){return t.directed?n.folded(e)?null:n.sourceDirected(e)?n.mateOf(e)!==A||n.isMutual(e)?"mutual":"directed":"undirected":"undirected"}function*GS(t,e){const n=hv(t,e?.styles),i=n?.snapshot??t,r=Iv(i,e),{version:s}=r,o=wl(i,"any",r.options.sanitizeIds),l=b=>W(String(o.idAt(b))),a=rH[s],{meta:c}=i;yield`<?xml version="1.0" encoding="UTF-8"?>
|
|
117
|
+
`,yield`<gexf xmlns="${a.gexf}" xmlns:viz="${a.viz}" version="${s}">
|
|
118
|
+
`,yield WV(c,n),yield VV(i,r),yield MS("node",r.nodeAttrs," "),yield MS("edge",r.edgeAttrs," ");const{nodeRoles:d}=r,u=zV(d.position);yield` <nodes count="${i.nodeCount}">
|
|
119
|
+
`;for(let b=0;b<i.nodeCount;b++){let _=` id="${l(b)}"`;d.label?.isSet(b)&&(_+=` label="${W(String(d.label.value(b)))}"`),d.parent?.isSet(b)&&(_+=` pid="${l(d.parent.value(b))}"`),_+=kS(d,b,r);let S=LS(r.nodeAttrs,b,r," ");if(d.parents?.isSet(b)){const T=Fo(d.parents,b);if(T.length>0){S+=` <parents>
|
|
120
|
+
`;for(const $ of T)S+=` <parent for="${l($)}"/>
|
|
121
|
+
`;S+=` </parents>
|
|
122
|
+
`}}S+=RS(d,b,r," "),S+=xS(d,b," ",u),S+=n?.node(b," ")??"",yield S.length===0?` <node${_}/>
|
|
123
|
+
`:` <node${_}>
|
|
124
|
+
${S} </node>
|
|
125
|
+
`}yield` </nodes>
|
|
126
|
+
`;const{edgeRoles:f}=r,h=i.edgeList(),p=Gt(i,{foldMutual:!0}),g=Ot(i),m=vv(i);let y=0;for(let b=0;b<i.edgeCount;b++)US(i,b,p)!==null&&y++;yield` <edges count="${y}">
|
|
127
|
+
`;for(let b=0;b<i.edgeCount;b++){const _=US(i,b,p);if(_===null)continue;let S="";f.id?.isSet(b)?S+=` id="${W(String(f.id.value(b)))}"`:s==="1.2"&&(S+=` id="e${b}"`),S+=` source="${l(h.src[b])}" target="${l(h.dst[b])}"`,_!==m&&(S+=` type="${_}"`);const T=g.text(b);T!==null&&(S+=` weight="${T}"`),f.label?.isSet(b)&&(S+=` label="${W(String(f.label.value(b)))}"`),s==="1.3"&&f.kind?.isSet(b)&&(S+=` kind="${W(String(f.kind.value(b)))}"`),S+=kS(f,b,r);let $=LS(r.edgeAttrs,b,r," ");$+=RS(f,b,r," "),$+=xS(f,b," ",!1),$+=n?.edge(b," ")??"",yield $.length===0?` <edge${S}/>
|
|
128
|
+
`:` <edge${S}>
|
|
129
|
+
${$} </edge>
|
|
130
|
+
`}yield` </edges>
|
|
131
|
+
`,yield` </graph>
|
|
132
|
+
`,yield`</gexf>
|
|
133
|
+
`}function WV(t,e){let n="";t.creator!==null&&(n+=` <creator>${nt(t.creator)}</creator>
|
|
134
|
+
`),t.description!==null&&(n+=` <description>${nt(t.description)}</description>
|
|
135
|
+
`),t.keywords.length>0&&(n+=` <keywords>${nt(t.keywords.join(", "))}</keywords>
|
|
136
|
+
`),e!==null&&(n+=` ${e.blockElement}
|
|
137
|
+
`);const i=t.modified===null?"":` lastmodifieddate="${W(t.modified)}"`;return n.length===0&&i.length===0?"":n.length===0?` <meta${i}/>
|
|
138
|
+
`:` <meta${i}>
|
|
139
|
+
${n} </meta>
|
|
140
|
+
`}function BV(t){let{idType:e}=t.meta;if(e===null){const{kind:n}=t.ids;n==="string"?e="string":n!=="mixed"&&(e="integer")}return e==="integer"||e==="string"?` idtype="${e}"`:""}function HV(t,e){const n=ta(t,"timestamp"),i={start:ta(t,"start"),end:ta(t,"end"),timestamp:n};e.version==="1.2"&&n!==null&&(i.start??=n,i.end??=n,i.timestamp=null);let r="";for(const[s,o]of Object.entries(i))o!==null&&(r+=` ${s}="${W(o)}"`);return r}function VV(t,e){const{meta:n}=t;let i=` defaultedgetype="${vv(t)}"`,r=n.mode??"static";return e.temporal&&r==="static"&&(r="dynamic"),e.version==="1.2"&&r==="slice"&&(r="dynamic"),i+=` mode="${r}"`,i+=BV(t),e.timeFormat!==null?i+=` timeformat="${e.timeFormat}"`:e.temporal&&(i+=' timeformat="double"'),e.version==="1.3"&&e.timeRepresentation!==null&&(i+=` timerepresentation="${e.timeRepresentation}"`),i+=HV(t,e),` <graph${i}>
|
|
141
|
+
`}function vv(t){return t.directed?ta(t,"defaultedgetype")?.trim().toLowerCase()==="mutual"?"mutual":"directed":"undirected"}function ta(t,e){const n=t.meta.extra.gexf;if(typeof n!="object"||n===null)return null;const i=n[e];return typeof i=="string"?i:null}const YV=Object.freeze({format:Mi,options:Object.freeze(["version"]),capabilities:Bb,styles:Object.freeze({capabilities:bH}),check(t,e){const n=hv(t,e?.styles);return Object.freeze([...Iv(n?.snapshot??t,e).notes,...n?.notes??[]])},export(t,e){return ti(GS(t,e))},async exportToString(t,e){return ni(GS(t,e))}});Object.freeze({...xn,...Pn,COLUMN_TYPE:sy,XML_SYNTAX:Ku,XML_NESTING:Xu,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,ENCODING_CONFLICT:hl,EMPTY_INPUT:Ut,NOT_GEXF:gv,NO_GRAPH:ls,MULTIPLE_GRAPHS:Qn,MISSING_NODES:Wg,MISSING_ID:dt,MISSING_ENDPOINT:Zn,UNKNOWN_NODE:"E_UNKNOWN_NODE",EDGE_TYPE:mv,UNKNOWN_PARENT:Ui,UNKNOWN_PID:Ov,PARENT_CYCLE:pl,BAD_VALUE:ie,ATTRIBUTES_CLASS:yv,ATTRIBUTE_ID:bv,HEADER_VALUE:To,COUNT_HINT:Hd,COUNT_MISMATCH:Fs,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,DUPLICATE_ATTRIBUTE:fe,ATTRIBUTE_TYPE:Ev,UNKNOWN_ATTR_TYPE:Zt,BAD_DEFAULT:Ho,BAD_OPTIONS:SA,COLUMN_RENAMED:ln,ROLE_TAKEN:bn,UNKNOWN_ATTRIBUTE:Bg,ATTVALUE_SHAPE:Hg,TIMED_VALUE_ON_STATIC:wv,PRECISION:re,ID_MERGED:Rn,WEIGHT_IGNORED:_v,VIZ_SKIPPED:Sv,VIZ_DYNAMIC_DROPPED:Nv,SPELL_OPEN_DROPPED:nV,VIZ_VALUE:Vg,OPEN_BOUND_CONFLICT:Av,TIMESTAMP_CONFLICT:Tv,VALUE_OUTSIDE_OPTIONS:Yg,UNKNOWN_ELEMENT:vt,UNKNOWN_XML_ATTRIBUTE:Bd,STRAY_TEXT:qu,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or});const KV=[[/yfiles|yed/i,"yed"],[/cytoscape/i,"cytoscape"],[/gephi/i,"gephi"],[/graphviz/i,"graphviz"],[/pajek/i,"pajek"],[/networkx/i,"networkx"],[/tulip/i,"tulip"]];function Hb(t){return t==null?null:KV.find(([e])=>e.test(t))?.[1]??null}const XV="graphics";function qV(t){if(t.nodes.byRole("position")===null)return null;const e=t.graph.has("Creator")?t.graph.value("Creator",0):null,n=Dv(t),i=typeof e=="string"?e:null,r=n?"graphviz":Hb(t.meta.creator??i);return{units:"px",sourceDims:3,yAxis:r==="gephi"||r==="tulip"||n?"up":"down",tool:r,medianNodeSize:JV(t,r==="gephi")}}function Dv(t){return(t.meta.creator??null)!==null||t.graph.has("Creator")||!t.graph.has("version")?!1:Number(t.graph.value("version",0))===2}function JV(t,e){const n=t.nodes.get(XV),i=[];for(let r=0;n!==null&&r<n.length;r++){const s=n.isSet(r)?n.value(r):void 0,{w:o,h:l,H:a}=typeof s=="object"&&s!==null?s:{};e&&typeof o=="number"?i.push(2*o):typeof o=="number"&&typeof(l??a)=="number"&&i.push((o+Number(l??a))/2)}return ny(i)}const Wf=0,Ss=1,Vb=2,pt=3,ke=4,Bf=5,$a="_networkx_list_start",Ca="[]",qg="()",Br="graphty_originalId",kd=kn,ZV=kn,QV=kn,eY=kn,tY=/^[A-Za-z_]\w*$/,nY=/^[A-Za-z]\w*$/,iY=/^[+-]?\d+$/,rY=/^[+-]?(?:(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)$/,kv=/^[+-]?(?:inf|infinity|nan)$/i,sY=/^(?:inf|infinity|nan)$/i;class Hr extends Error{constructor(e,n,i){super(n),this.name="GmlSyntaxError",this.code=e,this.line=i}}class oY{constructor(e,n=1024){this.count=0,this.backslashEscapes=!1,this.onUnknownEntity=null,this.text=e,this.kind=new Uint8Array(n),this.start=new Uint32Array(n),this.end=new Uint32Array(n),this.line=new Uint32Array(n),this.match=new Uint32Array(0)}push(e,n,i,r){this.count===this.kind.length&&this.grow();const s=this.count++;this.kind[s]=e,this.start[s]=n,this.end[s]=i,this.line[s]=r}textOf(e){return this.text.slice(this.start[e],this.end[e])}stringOf(e){let n=this.textOf(e);if(n.includes("\r")&&(n=n.replaceAll(/\r\n?/g,`
|
|
142
|
+
`)),this.backslashEscapes&&n.includes("\\")&&(n=n.replaceAll(/\\([\s\S])/g,"$1")),!n.includes("&"))return n;const i=this.onUnknownEntity;return V2(n,i===null?void 0:r=>{i(r,this.line[e])})}isBracket(e){return this.kind[e]>=ke}nextPair(e){const n=e+1;return this.kind[n]===ke?this.match[n]+1:n+1}grow(){const e=this.kind.length*2,n=new Uint8Array(e);n.set(this.kind),this.kind=n;const i=new Uint32Array(e);i.set(this.start),this.start=i;const r=new Uint32Array(e);r.set(this.end),this.end=r;const s=new Uint32Array(e);s.set(this.line),this.line=s}}function lY(t){const e=new oY(t,Math.max(1024,t.length>>>3));e.backslashEscapes=uY(t);const n={text:t,tokens:e,i:0,line:1,spanningLine:0};for(;n.i<t.length;){const i=t.codePointAt(n.i)??0;i===34?cY(n):i===91||i===93?(e.push(i===91?ke:Bf,n.i,n.i+1,n.line),n.i++):aY(n,i)||dY(n)}return mY(e),e}function aY(t,e){const{text:n}=t;if(e===10||e===13)t.line++,t.i++,e===13&&t.i<n.length&&n.codePointAt(t.i)===10&&t.i++;else if(e===32||e===9||e===11||e===12||e===65279)t.i++;else if(e===35)t.i=hY(n,t.i);else return!1;return!0}function cY(t){const{text:e,tokens:n,i}=t,r=n.backslashEscapes?fY(e,i+1):e.indexOf('"',i+1);if(r<0){const o=t.spanningLine===0?"":`; the string opened at line ${t.spanningLine} spans lines, so a quote may be missing there`;throw new Hr(QV,`unclosed string opened at line ${t.line}${o}`,t.line)}n.push(pt,i+1,r,t.line);const s=t.line;for(let o=i+1;o<r;o++){const l=e.codePointAt(o);(l===10||l===13&&e.codePointAt(o+1)!==10)&&t.line++}t.line!==s&&t.spanningLine===0&&(t.spanningLine=s),t.i=r+1}function dY(t){const{text:e,i:n}=t;let i=n+1;for(;i<e.length&&!pY(e.codePointAt(i)??0);)i++;t.tokens.push(gY(e,n,i,t.line),n,i,t.line),t.i=i}function uY(t){const e=Math.min(t.length,512);let n=0;for(;n<e;){const i=t.codePointAt(n);if(i===35)for(;n<e&&t.codePointAt(n)!==10&&t.codePointAt(n)!==13;)n++;else if(i===32||i===9||i===10||i===13||i===12||i===11)n++;else break}return/^Creator\s+"ogdf::/.test(t.slice(n,n+64))}function fY(t,e){let n=e;for(;n<t.length;){const i=t.codePointAt(n);if(i===34)return n;n+=i===92?2:1}return-1}function hY(t,e){const n=t.length;for(let i=e;i<n;i++){const r=t.charCodeAt(i);if(r===10||r===13)return i}return n}function pY(t){return t===32||t===9||t===10||t===13||t===11||t===12||t===91||t===93||t===34||t===35}function gY(t,e,n,i){const r=t.slice(e,n);if(tY.test(r))return Wf;if(iY.test(r))return Ss;if(rY.test(r)||kv.test(r))return Vb;const s=d=>(d.codePointAt(0)??0).toString(16).toUpperCase().padStart(4,"0"),l=(r.length>20?`${r.slice(0,20)}...`:r).replaceAll(/[^\x20-\x7e]/gu,d=>String.raw`\u`+s(d)),a=/[^\x21-\x7e]/u.exec(r),c=a===null?"":` (it holds U+${s(a[0])}, which GML allows only inside a string)`;throw new Hr(ZV,`cannot tokenize "${l}" at line ${i}${c}`,i)}function mY(t){const{count:e,kind:n}=t,i=new Uint32Array(e),r=[];let s=0;for(;s<e;){const o=n[s];if(o===Bf){const a=r.pop();if(a===void 0)throw new Hr(kd,`unexpected "]" at line ${t.line[s]}: no open "["`,t.line[s]);i[a]=s,s++;continue}if(o!==Wf)throw new Hr(kd,`expected a key at line ${t.line[s]}, found ${Rv(t,s)}`,t.line[s]);const l=s+1;if(l>=e)throw new Hr(kd,`key "${t.textOf(s)}" at line ${t.line[s]} has no value`,t.line[s]);yY(t,s)===ke&&r.push(l),s=l+1}if(r.length>0){const o=r[r.length-1];throw new Hr(eY,`unexpected end of input: ${r.length} bracket${O(r.length)} still open, the last opened at line ${t.line[o]}`,t.line[o])}t.match=i}function yY(t,e){const{kind:n}=t,i=e+1,r=n[i]===Wf&&!sY.test(t.textOf(i));if(r&&t.textOf(e)==="Creator")return n[i]=pt,pt;if(n[i]===Bf||r)throw new Hr(kd,`expected a value for key "${t.textOf(e)}" at line ${t.line[e]}, found ${Rv(t,i)}`,t.line[i]);return n[i]}function Rv(t,e){switch(t.kind[e]){case ke:return'"["';case Bf:return'"]"';case pt:return`the string "${t.textOf(e)}"`;default:return`"${t.textOf(e)}"`}}function Os(t){if(kv.test(t)){const e=t.toLowerCase();return e.endsWith("nan")?Number.NaN:e.startsWith("-")?-1/0:1/0}return Number(t)}function zo(t){return nY.test(t)}const Yb="W_GML_KEY_MANGLED";function Dl(t){const e=t.replaceAll(/\W/g,"_");return/^[A-Za-z]/.test(e)?e:`x${e}`}function Jg(t,e){const n=Object.create(null),i=[{record:n,listKeys:null,close:t.match[e],next:e+1,key:null}];for(;i.length>0;){const r=i[i.length-1];if(r.next>=r.close){i.pop(),r.key!==null&&Zg(i[i.length-1],r.key,r.record);continue}const s=r.next;r.next=t.nextPair(s);const o=t.textOf(s),l=s+1;t.kind[l]===pt?bY(r,o,t.stringOf(l)):t.kind[l]===ke?i.push({record:Object.create(null),listKeys:null,close:t.match[l],next:l+1,key:o}):Zg(r,o,Os(t.textOf(l)))}return n}function bY(t,e,n){if(n===$a){t.record[e]=[],t.listKeys??=new Set,t.listKeys.add(e);return}Zg(t,e,n===Ca||n===qg?[]:n)}function Zg(t,e,n){const{record:i}=t;t.listKeys?.has(e)?i[e].push(n):e in i?(i[e]=[i[e],n],t.listKeys??=new Set,t.listKeys.add(e)):i[e]=n}function EY(t,e){return t.kind[e]===ke?Jg(t,e):Os(t.textOf(e))}const Qg=[[/^\s*(yfiles|yed)\b/i,{dialect:"yed",tool:"yed",vocabulary:"yed",spelling:"yed",units:"px",labelKey:!1}],[/^\s*cytoscape\b/i,{dialect:"cytoscape",tool:"cytoscape",vocabulary:"cytoscape",spelling:"cytoscape",units:"px",labelKey:!0}],[/^\s*gephi\b/i,{dialect:"gephi",tool:"gephi",vocabulary:"graphlet",spelling:"css",units:"relative",labelKey:!0}],[/^\s*ogdf::/i,{dialect:"ogdf",tool:"ogdf",vocabulary:"ogdf",spelling:"css",units:"px",labelKey:!0}],[/^\s*igraph\b/i,{dialect:"igraph",tool:null,vocabulary:"graphlet",spelling:"css",units:"px",labelKey:!0}]],wY={dialect:"gml",tool:null,vocabulary:"graphlet",spelling:"css",units:"px",labelKey:!0},_Y={dialect:"graphviz",tool:"graphviz",vocabulary:"graphviz",spelling:"graphviz",units:"px",labelKey:!0},Lv={...Qg[0][1],tool:null},Kb=Dl(Z),Iu=Dl("graphty.style.");function $u(t,e){return Dl(wf(t,e))}function Pv(t,e){if(!t.graph.has(e))return null;const n=K(t.graph.value(e,0));return typeof n=="string"?n:typeof n=="number"?String(n):null}const SY=new Map([...["c","t","b","l","r","tl","tr","bl","br"].map(t=>[t,"center"]),["n","top"],["s","bottom"],["e","right"],["w","left"],["nw","top-left"],["ne","top-right"],["sw","bottom-left"],["se","bottom-right"]]),OY=["isGroup","gid"];function NY(t){if(t.graph.has(Kb))return Lv;const e=t.meta.creator??Pv(t,"Creator")??"";for(const[n,i]of Qg)if(n.test(e))return i;return e.trim()===""&&(OY.some(n=>t.nodes.has(n))||t.graph.has("hierarchic"))?Qg[0][1]:e.trim()===""&&Dv(t)?_Y:wY}const AY=new Map([["none",["none","none"]],["last",["none","triangle"]],["first",["triangle","none"]],["both",["triangle","triangle"]]]),TY=new Map([["ellipse","ellipse"],["round_rectangle","round-rectangle"],["round_rect","round-rectangle"],["rectangle","rectangle"],["rect","rectangle"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","parallelogram"],["triangle","triangle"],["vee","vee"],["diamond","diamond"]]),IY=["none","solid","dashed","dotted","dash-dot","dash-dot"],$Y=new Map([["none","none"],["solid","solid"],["dash","dashed"],["dot","dotted"],["dashdot","dash-dot"],["dashdotdot","dash-dot"]]),CY=new Map([["rect","rectangle"],["roundedrect","round-rectangle"],["rhomb","diamond"],["image","rectangle"]]),vY=new Map([["triangle","0,1 0.866,-0.5 -0.866,-0.5"],["invtriangle","0,-1 0.866,0.5 -0.866,0.5"],["pentagon","0,1 0.951,0.309 0.588,-0.809 -0.588,-0.809 -0.951,0.309"],["hexagon","1,0 0.5,0.866 -0.5,0.866 -1,0 -0.5,-0.866 0.5,-0.866"],["octagon","0.924,0.383 0.383,0.924 -0.383,0.924 -0.924,0.383 -0.924,-0.383 -0.383,-0.924 0.383,-0.924 0.924,-0.383"],["trapeze","-1,-1 1,-1 0.5,1 -0.5,1"],["invtrapeze","-1,1 1,1 0.5,-1 -0.5,-1"],["parallelogram","-1,-1 0.5,-1 1,1 -0.5,1"],["invparallelogram","-1,1 0.5,1 1,-1 -0.5,-1"]]),DY=new Set(["triangle","invtriangle","pentagon","hexagon","octagon"]),kY=["outline","autoSizePolicy","model","configuration","borderDistance","modelName","modelPosition"],jS=Zy.edge.get("targetArrow")?.[0]?.[1];function Xb(t){return typeof t=="string"||typeof t=="number"?String(t).slice(0,Ce):"a record"}function at(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function qs(t,...e){for(const n of e)if(Object.hasOwn(t,n)&&t[n]!==void 0)return t[n]}function Js(t,e,n,i,r,s){if(t===void 0)return;const o=ve(t,i.spelling,s(e));if(o===null)return;r(e,o.color);const l=Ol(o,null,s(e),n!==null);n!==null&&r(n,l)}function Hf(t,e,n,i){if(t===void 0)return null;if(n.vocabulary==="ogdf"){const r=qb(t);return r===void 0?(H(i,v.UNKNOWN_VALUE,Xb(t)),null):r==="none"?null:r}return le(e,t,n.spelling,i)}function qb(t){const e=typeof t=="string"||typeof t=="number"?String(t).trim():"";return/^\d+$/.test(e)?IY[Number(e)]:$Y.get(e.toLowerCase())}function RY(t,e,n,i){const r=t.trim().toLowerCase(),s=vY.get(r);if(s!==void 0){n("shape","polygon"),n("shapePoints",s),DY.has(r)&&n("shapePointsStretch",!1);return}n("shape",le("shape",CY.get(r)??t,e.spelling,i("shape")))}function LY(t,e,n,i){const r=e.vocabulary;if(r==="graphviz"){UY(t,e,n,i);return}jY(t,e,n,i),FY(t,e,n,i),n("borderStyle",Hf(r==="ogdf"?t.stipple:t.outlineStyle,"borderStyle",e,i("borderStyle"))),r==="ogdf"&&t.stipple!==void 0&&qb(t.stipple)==="none"&&n("borderWidth",0),PY(t,e,n,i),r==="ogdf"&&MY(t.label,n,i),xY(t,e,n,i)}function PY(t,e,n,i){if(e.tool==="gephi"){const r=t.w===void 0?null:Y(t.w,i("width"));n("width",r===null?null:2*r),n("height",r===null?null:2*r)}else n("width",t.w===void 0?null:Y(t.w,i("width"))),n("height",t.h===void 0?null:Y(t.h,i("height")))}function xY(t,e,n,i){const r=e.vocabulary;if(r==="ogdf"&&typeof t.type=="string")RY(t.type,e,n,i);else if(r==="cytoscape"&&t.type!==void 0){const s=ut(t.type,i("shape"))?.trim().toLowerCase()??"",o=TY.get(s);o===void 0&&H(i("shape"),v.UNKNOWN_VALUE,s.slice(0,Ce)),n("shape",o??null)}else if(t.type!==void 0)n("shape",le("shape",t.type,e.spelling,i("shape")));else if(r==="yed"&&typeof t.customconfiguration=="string"){const s=Df(t.customconfiguration);n("shape",s?.shape??null),s?.points!==void 0&&n("shapePoints",s.points)}}function MY(t,e,n){if(typeof t!="object"||t===null||Array.isArray(t))return;const{x:i,y:r}=t;e("labelOffsetX",i===void 0?null:wa(i,n("labelOffsetX"))),e("labelOffsetY",r===void 0?null:wa(r,n("labelOffsetY")))}function UY(t,e,n,i){const r=typeof t.type=="string"?t.type.trim().toLowerCase():"";if(Number(t.hasFill)===1||r==="point"){const c=ve(t.fill??"black",e.spelling,i("fill"),{use:"fill"});n("fill",c?.color??null),n("fillOpacity",c?.alpha??null)}else t.fill!==void 0&&H(i("fill"),v.UNFILLED,Xb(t.fill));_W(r)?n("borderWidth",0):(Js(t.outline,"borderColor",null,e,n,i),n("borderWidth",t.width===void 0?null:Y(t.width,i("borderWidth"))));const s=Hf(t.outlineStyle,"borderStyle",e,i("borderStyle"));n("borderStyle",s),GY(t,r,s,e,n,i);const o=2*xb*((Pb.get(r)??1)-1),l=(c,d)=>{const u=c===void 0?null:Y(c,i(d));return u===null?null:Math.max(0,u-o)};n("width",l(t.w,"width")),n("height",l(qs(t,"H","h"),"height")),Number(t.visible)===0&&t.visible!==void 0&&n("visible",!1);const a=wW(r);if(r==="polygon")n("shape","rectangle");else if(a!==void 0)n("shape","polygon"),n("shapePoints",a),n("shapePointsStretch",!1);else if(Cb.has(r)){const c=(d,u)=>d===void 0?null:Y(d,i(u));DC(r,c(t.w,"width"),c(qs(t,"H","h"),"height"),n,()=>{const d=t.width===void 0?1:Number(t.width);return Number.isFinite(d)?Math.max(0,d):1},()=>ve(t.outline??"black",e.spelling,i("outerBorderColor"),{use:"line"})?.color??null)}else t.type!==void 0&&n("shape",le("shape",t.type,"graphviz",i("shape")))}function GY(t,e,n,i,r,s){const o=Pb.get(e)??1;if(o<2)return;const l=ve(t.outline??"black",i.spelling,s("outerBorderColor"),{use:"line"});if(l!==null&&l.alpha===0)return;const a=t.width===void 0?1:Number(t.width),c=Number.isFinite(a)?Math.max(0,a):1;r("outerBorderColor",l?.color??"#000000"),r("outerBorderOpacity",l!==null&&l.alpha<1?l.alpha:null),r("outerBorderWidth",c),r("outerBorderOffset",Math.max(0,xb-c)),(n==="dashed"||n==="dotted")&&r("outerBorderStyle",n),o>2&&H(s("outerBorderWidth"),v.NOT_CARRIED,`type ${e}`)}function jY(t,e,n,i){if(e.vocabulary==="yed"&&Number(t.hasFill)===0){H(i("fill"),v.NO_FILL,"hasFill 0"),n("fillOpacity",0);return}Js(t.fill,"fill","fillOpacity",e,n,i),t.fill2!==void 0&&H(i("fill"),v.GRADIENT,Xb(t.fill2))}function FY(t,e,n,i){const r=e.vocabulary;if(r==="yed"&&Number(t.hasOutline)===0){n("borderWidth",0);return}Js(r==="ogdf"?qs(t,"outline","line"):t.outline,"borderColor",null,e,n,i);const s=zY(t,r);n("borderWidth",s===void 0?null:Y(s,i("borderWidth")))}function zY(t,e){switch(e){case"yed":return t.outlineWidth;case"cytoscape":return qs(t,"outline_width","width");case"ogdf":return t.lineWidth;default:return qs(t,"width","outlineWidth")}}function WY(t,e,n,i){const r=e.vocabulary;if(r==="graphviz"){VY(t,e,n,i);return}Js(t.fill,"color","opacity",e,n,i);const s=r==="ogdf"?qs(t,"lineWidth","width"):t.width;n("width",s===void 0?null:Y(s,i("width"))),n("lineStyle",Hf(r==="ogdf"?t.stipple:t.style,"lineStyle",e,i("lineStyle"))),r==="ogdf"&&t.stipple!==void 0&&qb(t.stipple)==="none"&&n("visible",!1),BY(t,e,n,i),r==="yed"&&YY(t,n)}function BY(t,e,n,i){if(typeof t.arrow=="string"){const r=AY.get(t.arrow.trim().toLowerCase());r===void 0?H(i("targetArrow"),v.UNKNOWN_VALUE,t.arrow.slice(0,Ce)):(n("sourceArrow",r[0]),n("targetArrow",r[1]))}for(const[r,s]of[[["sourceArrow","source_arrow"],"sourceArrow"],[["targetArrow","target_arrow"],"targetArrow"]]){const o=qs(t,...r);o!==void 0&&n(s,e.vocabulary==="cytoscape"&&jS!==void 0?jS(o,i(s)):le("arrow",o,e.spelling,i(s)))}}const HY=new Map([["first",[!1,!0]],["last",[!0,!1]],["both",[!0,!0]],["none",[!1,!1]]]);function VY(t,e,n,i){Js(t.fill,"color","opacity",e,n,i),n("width",t.width===void 0?null:Y(t.width,i("width"))),n("lineStyle",Hf(t.style,"lineStyle",e,i("lineStyle"))),Number(t.visible)===0&&t.visible!==void 0&&n("visible",!1);const r=xv(t,e.directed===!0);if(r!==null)for(const[s,o,l]of[["target",t.targetArrow,r[1]],["source",t.sourceArrow,r[0]]]){const c=l?xC(typeof o=="string"?o:"normal",i(`${s}Arrow`)):null;n(`${s}Arrow`,c===null?"none":c.value),c?.side!==null&&c?.side!==void 0&&n(`${s}ArrowSide`,c.side)}}function xv(t,e){if(t.arrow===void 0&&t.targetArrow===void 0&&t.sourceArrow===void 0)return e?[!1,!0]:null;let n=e?"first":"none";return typeof t.arrow=="string"&&(n=t.arrow.trim().toLowerCase()),HY.get(n)??null}function YY(t,e){if(t.smoothBends!==void 0){const n=at(t.Line)?t.Line.point:void 0;e("curved",Number(t.smoothBends)===1&&Array.isArray(n)&&n.length>2)}}function KY(t,e,n,i,r){const s=(Array.isArray(t)?t:[t]).filter(c=>at(c)&&Number(c.visible)!==0),o=s.at(0);if(o===void 0)return;const l=s.slice(1).filter(c=>c.text!==void 0).length;l>0&&H(r("label"),v.EXTRA_LABELS,`${String(l+1)} labels`),o.text!==void 0&&i("label",e.vocabulary==="graphviz"?Mv(o.text,r("label")):rt(o.text,r("label")));const a=e.vocabulary==="yed"||kY.some(c=>Object.hasOwn(o,c));if(o.color!==void 0||o.fontColor!==void 0?Js(o.color??o.fontColor,"labelColor","labelOpacity",e,i,r):o.fill!==void 0&&!a&&Js(o.fill,"labelColor",null,e,i,r),o.fill!==void 0&&a&&H(r("label"),v.NOT_CARRIED,"label background"),XY(o,a||e.vocabulary==="cytoscape",i,r),n&&o.anchor!==void 0){const c=ut(o.anchor,r("labelPosition"))?.trim().toLowerCase()??"",d=SY.get(c);d===void 0&&H(r("labelPosition"),v.UNKNOWN_VALUE,c.slice(0,Ce)),i("labelPosition",d??null)}}function Mv(t,e){const n=rt(t,e);return n===null?null:n.replaceAll(/\\[nlr]/g,`
|
|
143
|
+
`).replace(/\n$/,"")}function XY(t,e,n,i){n("labelSize",t.fontSize===void 0?null:Y(t.fontSize,i("labelSize")));const r=t.fontName===void 0?null:rt(t.fontName,i("labelFont"));n("labelFont",e&&typeof r=="string"?_f(r):r);const s=ut(t.fontStyle,i("labelWeight"))?.trim().toLowerCase();if(s!==void 0){const o=W$.get(s);o===void 0?H(i("labelWeight"),v.UNKNOWN_VALUE,s.slice(0,Ce)):(n("labelWeight",o[0]),n("labelItalic",o[1]))}}function Uv(t,e,n,i,r,s,o){let l=!1;const a=(d,u)=>{l||=d==="label"&&u!==null,s(d,u)};at(e)&&(t==="node"?LY:WY)(e,r,s,o),n!=null&&KY(n,r,t==="node",a,o);const c=r.vocabulary==="cytoscape"?t==="node":r.labelKey&&(at(e)||n!==void 0);!l&&c&&i!==null&&i!==void 0&&(s("label",r.vocabulary==="graphviz"?Mv(i,o("label")):rt(i,o("label"))),t==="node"&&r.tool===null&&r.vocabulary==="graphlet"&&s("labelPosition","center"))}const qY=10;function JY(t,e){const n=t.nodeCount,i=o=>{const[l,a]=An(t,o),[c,d]=Cu(t,o);return[l-c/2,a-d/2,l+c/2,a+d/2]},r=[1/0,1/0,-1/0,-1/0];for(let o=0;o<n;o++){const l=i(o);l.every(Number.isFinite)&&(r[0]=Math.min(r[0],l[0]),r[1]=Math.min(r[1],l[1]),r[2]=Math.max(r[2],l[2]),r[3]=Math.max(r[3],l[3]))}const s=(o,l,a)=>{e[o]??=new Array(n).fill(null),e[o][l]=a};for(let o=0;o<n;o++){const l=t.ids.idOf(o),[a,c,d,u]=i(o);if(typeof l!="string"||!l.startsWith("cluster")||![a,c,d,u].every(Number.isFinite))continue;const f=r[3]-u>c-r[1],h=a-r[0]>r[2]-d;s("labelPosition",o,"center"),s("labelOffsetX",o,(h?-1:1)*(d-a)/2),s("labelShiftX",o,h?.5:-.5),s("labelOffsetY",o,(f?1:-1)*((u-c)/2+qY))}}function ZY(t,e,n,i){const r=n==="node"?t.nodes:t.edges,s=yi(r,"label",i);return e.vocabulary==="cytoscape"&&n==="node"&&(s===void 0||s==="")?String(t.ids.idOf(i)):s}function yi(t,e,n){return t.has(e)?K(t.value(e,n))??void 0:void 0}function An(t,e){const n=t.nodes.byRole("position"),i=n?.isSet(e)===!0?n.value(e):null;return i===null?[Number.NaN,Number.NaN]:[i[0],i[1]]}function Cu(t,e){const n=yi(t.nodes,"graphics",e);return at(n)?[Number(n.w??Number.NaN),Number(n.h??Number.NaN)]:[Number.NaN,Number.NaN]}function QY(t,e,n,i,r){const s=at(e)&&at(e.Line)?e.Line.point:void 0,o=at(s)?[s]:s;if(!Array.isArray(o)||o.length<(i?1:2))return;const l=o.map(f=>at(f)?[Number(f.x),Number(f.y)]:[Number.NaN,0]),[a,c]=[t.edgeSource(n),t.edgeTarget(n)],d=i?l:l.slice(1,-1),u=a===c?Hs(An(t,a),Cu(t,a),d,!0):Al(An(t,a),An(t,c),d,!0);if(u!==null&&r("bends",u),!i)for(const[f,h,p]of[["sourcePort",a,l[0]],["targetPort",c,l.at(-1)??l[0]]]){const g=An(t,h),m=p[0]===g[0]&&p[1]===g[1]?null:Hs(g,Cu(t,h),[p],!0);m!==null&&r(f,m)}}function eK(t,e,n,i){const r=at(e)&&at(e.Line)?e.Line.point:void 0,s=at(r)?[r]:r;if(!Array.isArray(s)||!at(e))return;let o=s.map(d=>at(d)?[Number(d.x),Number(d.y)]:[Number.NaN,0]);const l=(o.length-1)%3,a=l===2||l===1&&xv(e,t.directed)?.[0]===!0;o=o.slice(a?1:0,o.length-(l===2||l===1&&!a?1:0));const c=PC(An(t,t.edgeSource(n)),An(t,t.edgeTarget(n)),[o]);c!==null&&i("bends",c)}function Gv(t){const e=t.length-1;if(e%2===0)return t[e/2];const[n,i]=[t[(e-1)/2],t[(e+1)/2]];return[(n[0]+i[0])/2,(n[1]+i[1])/2]}function jv(t,e,n,i){const r=P(t[0]-e[0]),s=P((n?-1:1)*(t[1]-e[1]));Number.isFinite(r)&&Number.isFinite(s)&&(r!==0||s!==0)&&(i("labelPosition","center"),i("labelOffsetX",r),i("labelOffsetY",s))}function tK(t,e,n,i){const r=yi(t.edges,"lp",e),s=typeof r=="string"?/^\s*(-?[\d.]+)\s*,\s*(-?[\d.]+)\s*$/.exec(r):null;if(s===null||n)return;const[o,l]=[An(t,t.edgeSource(e)),An(t,t.edgeTarget(e))];jv([Number(s[1]),Number(s[2])],Gv([o,l]),!0,i)}function nK(t,e,n,i){const r=at(e)&&at(e.Line)?e.Line.point:void 0,s=at(r)?[r]:r,[o,l]=[An(t,t.edgeSource(n)),An(t,t.edgeTarget(n))];if(!Array.isArray(s)||t.edgeSource(n)===t.edgeTarget(n))return;const a=(u,f)=>Math.hypot(u[0]-f[0],u[1]-f[1])<1e-6,c=s.map(u=>at(u)?[Number(u.x),Number(u.y)]:[Number.NaN,0]).filter(u=>!a(u,o)&&!a(u,l));if(c.length===0)return;const d=[o,...c,l];jv([(d[0][0]+d[1][0])/2,(d[0][1]+d[1][1])/2],Gv(d),!1,i)}function iK(t,e){const n=t.meta.extra.gml?.directed,i=t.edges.byRole("directed");if(i===null||n===void 0)return;const r=Number(n)===1;for(let s=0;s<t.edgeCount;s++){const o=K(i.value(s));typeof o=="boolean"&&o!==r&&(e.visible??=new Array(t.edgeCount).fill(null),e.visible[s]=!1)}}function rK(t,e,n,i){let r=!1;const s=a=>{const c=a==="node"?t.nodes:t.edges,d=a==="node"?t.nodeCount:t.edgeCount,u=Qr(d);if(!c.has("graphics")&&!c.has("LabelGraphics")&&e.vocabulary!=="cytoscape")return u.values;for(let f=0;f<d;f++){i.budget.spend(a,1);const h=p=>({notes:n,target:a,property:p,element:f,budget:i.budget});if(Uv(a,yi(c,"graphics",f),yi(c,"LabelGraphics",f),ZY(t,e,a,f),e,(p,g)=>{g!==null&&(r=!0,u.put(f,p,g))},h),a==="edge"&&e.vocabulary==="graphviz"){let p=!1;eK(t,yi(c,"graphics",f),f,(g,m)=>{r=!0,p||=g==="bends",u.put(f,g,m)}),tK(t,f,p,(g,m)=>{u.put(f,g,m)})}else a==="edge"&&e.vocabulary==="ogdf"&&nK(t,yi(c,"graphics",f),f,(p,g)=>{u.put(f,p,g)});a==="edge"&&e.vocabulary!=="graphviz"&&QY(t,yi(c,"graphics",f),f,e.vocabulary==="ogdf",(p,g)=>{r=!0,u.put(f,p,g)})}return u.values},o=s("node"),l=s("edge");return{node:o,edge:l,found:r}}function sK(t,e){const n=ac(e,ro(t));if(!n.ok||n.block.values!==void 0)return e;const i=FS(t,"node",n.block.columns.node),r=FS(t,"edge",n.block.columns.edge);if(i===null||r===null)return e;const s=JSON.parse(e);return JSON.stringify({...s,values:{node:i,edge:r}})}function FS(t,e,n){const i=e==="node"?t.nodes:t.edges,r=e==="node"?t.nodeCount:t.edgeCount,s={};for(const o of n){const l=$u(e,o);if(!i.has(l))return null;s[o]=Array.from({length:r},(a,c)=>{const d=K(i.value(l,c));return typeof d=="string"||typeof d=="number"||typeof d=="boolean"?d:null})}return s}function zS(t){return[...t.names()].filter(e=>e==="graphics"||e==="LabelGraphics"||e.startsWith(Iu))}function oK(t,e){const n=new se,i={...NY(t),directed:t.directed},r=rK(t,i,n,e);i.vocabulary==="ogdf"&&JY(t,r.node);const s=Pv(t,Kb),o=s===null?null:sK(t,s);if(o!==null&&aK(t,o,r),i.tool===null&&!r.found&&o===null)return null;i.tool==="gephi"&&o===null&&(delete r.edge.color,t.edges.byRole("weight")===null&&t.edges.has("value")&&(r.edge.width=Array.from({length:t.edgeCount},(c,d)=>{const u=yi(t.edges,"value",d);return typeof u!="number"||!Number.isFinite(u)?null:u>0?u:1})),iK(t,r.edge));const l={rules:[],columns:new Map},a=i.tool==="gephi"?Wb(t,{fill:r.node.fill,width:r.node.width},{color:r.edge.color,width:r.edge.width},e.budget):{node:l,edge:l};return{canonical:!0,dialect:i.dialect,tool:i.tool,units:i.units,node:{values:r.node,...a.node},edge:{values:r.edge,...a.edge},notes:n.list(),opacityInColor:!0,block:o,readFrom:{node:zS(t.nodes),edge:zS(t.edges)}}}const va=Object.freeze({tool:"yed",node:Object.freeze(["fill","fillOpacity","borderColor","borderWidth","borderStyle","shape","width","height","label","labelColor","labelSize","labelFont","labelWeight","labelItalic"]),edge:Object.freeze(["color","opacity","width","lineStyle","sourceArrow","targetArrow","curved","bends","sourcePort","targetPort","label","labelColor","labelSize","labelFont","labelWeight","labelItalic"]),block:"native"}),Fv={node:new Set(["fill","fill2","hasFill","outline","hasOutline","outlineWidth","outline_width","outlineStyle","width","line","lineWidth","stipple","w","h","type"]),edge:new Set(["fill","width","lineWidth","style","stipple","arrow","sourceArrow","targetArrow","source_arrow","target_arrow","smoothBends"]),label:new Set(["text","color","fill","fontSize","fontName","fontStyle","visible"])};function zv(t,e){const n={},i=t("width"),r=t("height");typeof i=="number"&&(n.w=i),typeof r=="number"&&(n.h=r);const s=t("shape");if(typeof s=="string"){const u=xg(X$,s,s==="vee"?"triangle":"rectangle");u.exact||e("shape",s),n.type=u.value}const o=t("fill"),l=t("fillOpacity");typeof o=="string"?n.fill=kf(o,l):l===0&&(n.hasFill=0);const a=t("borderColor"),c=t("borderWidth"),d=t("borderStyle");if(typeof a=="string"&&(n.outline=a.toUpperCase()),typeof d=="string"){const u=xg(Ib,d,"line");u.exact||e("borderStyle",d),n.outlineStyle=u.value}return c===0?n.hasOutline=0:typeof c=="number"&&(n.outlineWidth=c),n}function Wv(t,e){const n={},i=t("color");typeof i=="string"&&(n.fill=kf(i,t("opacity")));const r=t("width");typeof r=="number"&&(n.width=r);const s=t("lineStyle");typeof s=="string"&&(n.style=Ta(Ib,s,s==="long-dash"?"dashed":"line","lineStyle",e));for(const l of["sourceArrow","targetArrow"]){const a=t(l);typeof a=="string"&&(n[l]=Ta(q$,a,"delta",l,e))}const o=t("curved");return typeof o=="boolean"&&(n.smoothBends=o?1:0),n}function Bv(t){const e=t("label");if(typeof e!="string"||e.trim().length===0)return null;const n={text:e},i=t("labelColor");typeof i=="string"&&(n.color=i.toUpperCase());const r=t("labelSize");typeof r=="number"&&(n.fontSize=r);const s=t("labelFont");typeof s=="string"&&(n.fontName=J$(s));const o=t("labelWeight"),l=t("labelItalic");if(o!==null||l!==null){const a=(o==="bold"?"bold":"")+(l===!0?"italic":"");n.fontStyle=a.length===0?"plain":a}return n}function Hv(t,e,n){const i={};if(at(t))for(const[r,s]of Object.entries(t))e.has(r)||(i[r]=s);return Object.assign(i,n),Object.keys(i).length===0?void 0:i}function lK(t,e){const n=Array.isArray(t)?t:[t],i=Hv(n[0],Fv.label,e??{}),r=n.slice(1).filter(s=>s!=null);return r.length===0?i:i===void 0?r:[i,...r]}function aK(t,e,n){const i=new se;so(t,e,"gml",r=>({values:n[r],properties:va[r],writes:va[r],readBack:(s,o)=>{const l=cK(r,o,i);return a=>l.get(a)??null}}))}function cK(t,e,n){const i=()=>{},r=t==="node"?zv(e,i):Wv(e,i),s=new Map;return Uv(t,r,Bv(e)??void 0,void 0,Lv,(o,l)=>{l!==null&&s.set(o,l)},o=>({notes:n,target:t,property:o})),s}function Vv(t,e){if(e===void 0)return null;const n=new Il,i=t.withColumns(),r=[];for(const c of["node","edge"]){const d=c==="node"?i.nodes:i.edges;dK(t,e,c,d,n);const u=fC(e.rules.styles.rules,c);for(const f of d.names().filter(h=>Dl(h).startsWith(Iu))){const h=d.get(f);d.remove(f),h!==null&&!(f.startsWith(Iu)&&!u.has(f))&&r.push(fK(d,c,f,h))}}let{block:s}=e;const o=[...e.rules.columns.node.keys()].map(c=>$u("node",c)),l=[...e.rules.columns.edge.keys()].map(c=>$u("edge",c));new Set(o).size!==o.length||new Set(l).size!==l.length?s=Nl(e.rules,{inlineColumns:!0,snapshot:t}):hK(i,e),i.graph.set(Kb,[s],{dtype:"string"});const a=[...r,...s===e.block?[]:lc(s,e.rules.styles.rules.length,"size"),...n.notes("yEd's GML")];return{snapshot:i,notes:a}}function dK(t,e,n,i,r){const s=n==="node"?t.nodeCount:t.edgeCount,o=(f,h)=>{r.add(n,f,h)},l=Vs((f,h)=>e.picture(f,h),n,va[n]),a=Vs((f,h)=>e.picture(f,h),"node",va.node),c=f=>{const[h,p]=[a(f)("width"),a(f)("height")];return typeof h=="number"&&typeof p=="number"?[h,p]:Cu(t,f)},d=[],u=[];for(let f=0;f<s;f++){const h=n==="node"?zv(l(f),o):Wv(l(f),o);if(n==="edge"){const p=uK(t,l(f),f,c);p!==null&&(h.Line=p)}d.push(Hv(yi(i,"graphics",f),Fv[n],h)),u.push(lK(yi(i,"LabelGraphics",f),Bv(l(f))))}for(const[f,h]of[["graphics",d],["LabelGraphics",u]])h.some(p=>p!==void 0)?i.set(f,h,{dtype:"json",nullable:!0}):i.has(f)&&i.remove(f)}function uK(t,e,n,i){const[r,s]=[t.edgeSource(n),t.edgeTarget(n)],o=An(t,r),l=An(t,s);if(![...o,...l].every(Number.isFinite))return null;const a=e("bends");let c=null;typeof a=="string"&&(c=r===s?pu(o,i(r),a):Y1(o,l,a));const d=(h,p,g)=>{const m=e(h);return typeof m=="string"?pu(g,i(p),m)?.[0]??null:null},u=d("sourcePort",r,o),f=d("targetPort",s,l);return c===null&&u===null&&f===null?null:{point:[u??o,...c??[],f??l].map(([h,p])=>({x:h,y:p}))}}function fK(t,e,n,i){let r=`data_${n}`,s=2;for(;t.has(r);)r=`data_${n}_${String(s)}`,s++;return t.set(r,i),Object.freeze({code:Yb,message:`${e} column "${n}" is written as "${r}": keys starting with ${Iu} hold graphty's style values`,column:n,count:null})}function hK(t,e){for(const n of["node","edge"]){const i=n==="node"?t.nodes:t.edges;for(const[r,s]of e.rules.columns[n]){const o=new Set(s.filter(c=>c!==null).map(c=>typeof c)),l=o.size>1||o.has("string");let a=o.has("boolean")?"bool":"f64";l&&(a="string"),i.set($u(n,r),l?s.map(c=>c===null?null:String(c)):s,{dtype:a})}}}const pK="W_GML_RECORD_NUMBER_TYPE",gK="W_GML_RECORD_BOOLEAN",mK="W_GML_RECORD_NULL",yK="E_GML_NESTED_ARRAY",bK="W_GML_JSON_ARRAY",Yv="E_GML_INVALID_KEY",EK="E_GML_RESERVED_KEY",wK="W_GML_POSITION_COMPONENTS",_K="W_GML_GRAPHICS_OVERRIDDEN",SK="E_GML_GRAPHICS_CONFLICT",OK="value",NK=new Set(["label","id","key"]),AK=Object.freeze({label:"label",id:"id",key:"key"}),Kv=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"integer",dtypes:["i32","f64","string","dict","json"],components:!1,lists:!0,json:!0,defaults:!1,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),TK=new Set(["directed","pair","mutual","weight","timeText","originalId","position","color","size","shape","thickness","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]),Xv=new Set(["id"]),IK=new Set(["source","target","directed"]),qv=new Set(["node","edge","directed","multigraph"]),$K=new Set(["graph"]),CK=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function Jv(t,e){const n=ft(e),i=e?.sanitizeKeys??"error";if(i!=="error"&&i!=="mangle")throw new N("E_UNSUPPORTED",`option sanitizeKeys: ${JSON.stringify(i)} is not "error" or "mangle"`,{option:"sanitizeKeys",found:i});let r=e?.weightKey;if(r===void 0){const s=t.meta.weightOrigin;r=s!==null&&s.format==="gml"&&s.id!==null?s.id:OK}else if(typeof r!="string"||!zo(r))throw new N("E_UNSUPPORTED",`option weightKey: ${JSON.stringify(r)} is not a GML key`,{option:"weightKey",found:r});return{common:n,weightKey:r,mangle:i==="mangle"}}function vK(t){const{role:e}=t.meta;return e===null||!TK.has(e)}function DK(t){const{origin:e,name:n}=t;return e?.format!=="gml"||e.id===null?n:n===e.id||n.startsWith(`${e.id}#`)?e.id:n}function Zv(t){return t.flags.weighted}function vu(t){return t.meta.extra.gmlTopLevel===!0}function kK(t){return CK.test(t)?t:Pi(t)}function RK(t,e,n){if(e!=="node"&&e!=="edge")return;const i=t.find(r=>r.meta.role==="label");return i!==void 0&&n.add("label"),i}function Vr(t,e,n,i,r,s=()=>!0){const o=new Set(e),l=[],a=[...t].filter(d=>vK(d)&&s(d)),c=RK(a,n,o);for(const d of a){const u=d===c?"label":DK(d.meta);let f=u;const h=zo(u),p=d!==c&&o.has(u);if(!h||p){const g=h?EK:Yv;let m="is not a GML key";if(h&&(m=e.has(u)?"collides with a structural GML key":"repeats another column's key"),!i.mangle){if(r===null)throw new N("E_UNSUPPORTED",`${n} column "${d.meta.name}" ${m}; pass sanitizeKeys: "mangle" to rewrite it`,{reason:"gml key",column:d.meta.name,key:u});r.push(Tn(g,`${n} column "${d.meta.name}" ${m}; the save fails unless sanitizeKeys is "mangle"`,d.meta.name));continue}f=Qv(h?u:Dl(u),o),r?.push(Tn(Yb,`${n} column "${d.meta.name}" is written as "${f}"`,d.meta.name))}o.add(f),l.push({column:d,key:f})}return l}function Qv(t,e){let n=t;for(let i=2;e.has(n);i++)n=`${t}_${i}`;return n}function Tn(t,e,n=null,i=null){return Object.freeze({code:t,message:e,column:n,count:i})}function Yc(t,e,n,i){t[e]||(t[e]=!0,n[i]++)}function na(t,e,n,i){if(t===null){Yc(i,"nulls",e,"nulls");return}switch(typeof t){case"number":Yc(i,"numbers",e,"numbers");return;case"boolean":Yc(i,"booleans",e,"booleans");return;case"string":return}if(Array.isArray(t)){n&&Yc(i,"nested",e,"nestedArrays");for(const s of t)na(s,e,!0,i);return}const r=t;for(const s of Object.keys(r))zo(s)||e.invalidKeys++,na(r[s],e,!1,i)}function jl(t){return`${t} row${O(t)}`}function LK(t,e,n,i,r){e>0&&t.push(Tn(n,i,r,e))}function Kc(t,e,n,i){for(const{column:r}of t){const s=PK(r);if(s===null)continue;const{name:o}=r.meta,l=`${e} column "${o}"`,a=(d,u,f)=>{LK(i,d,u,f,o)};a(s.numbers,pK,`${l} holds numbers in ${jl(s.numbers)}; GML records cannot keep the int / real distinction`),a(s.booleans,gK,`${l} holds booleans in ${jl(s.booleans)}; written as 1 / 0`),a(s.nulls,mK,`${l} holds nulls in ${jl(s.nulls)}; GML has no null, the key is omitted`),a(s.arrays,bK,`${l} holds arrays as values in ${jl(s.arrays)}; written as repeated keys, they re-import as a list`),a(s.nestedArrays,yK,`${l} holds arrays nested in arrays in ${jl(s.nestedArrays)}; GML cannot write them and the save fails`);const c=`${s.invalidKeys} record key${O(s.invalidKeys)} ${C(s.invalidKeys,"is","are")} not GML keys`;a(s.invalidKeys,n.mangle?Yb:Yv,n.mangle?`${l}: ${c} and are rewritten`:`${l}: ${c}; the save fails unless sanitizeKeys is "mangle"`)}}function PK(t){const e={numbers:0,booleans:0,nulls:0,nestedArrays:0,arrays:0,invalidKeys:0};if(t.dtype==="json"){for(let n=0;n<t.length;n++){if(!t.isSet(n))continue;const i=t.values[n],r={numbers:!1,booleans:!1,nulls:!1,nested:!1};if(Array.isArray(i)){e.arrays++;for(const s of i)na(s,e,!0,r)}else na(i,e,!1,r)}return e}if(t.dtype==="list"&&t.meta.itemDtype==="json"){for(let n=0;n<t.length;n++){if(!t.isSet(n))continue;const i={numbers:!1,booleans:!1,nulls:!1,nested:!1};for(const r of t.sliceOf(n))na(r,e,!0,i)}return e}return null}function Jb(t){const e=t.nodes.byRole("position");if(e===null)return null;switch(e.dtype){case"f32":case"f64":case"i32":case"u32":case"u8":return e;default:return null}}function eD(t){return t.nodes.typed("graphics","json")}function xK(t,e){const n=Jb(t);if(n===null)return;n.meta.components>3&&e.push(Tn(wK,`node column "${n.meta.name}" has ${n.meta.components} components; only x, y and z are written`,n.meta.name,n.length-n.nullCount));const i=eD(t);if(i===null)return;let r=0,s=0;for(let o=0;o<t.nodeCount;o++){if(!n.isSet(o)||!i.isSet(o))continue;const l=i.values[o];typeof l!="object"||l===null||Array.isArray(l)?s++:("x"in l||"y"in l||"z"in l)&&r++}r>0&&e.push(Tn(_K,`${r} node graphics record${O(r)} ${C(r,"has","have")} x / y / z keys the position column replaces`,"graphics",r)),s>0&&e.push(Tn(SK,`${s} node graphics value${O(s)} ${C(s,"is","are")} not records and cannot hold the position; the save fails`,"graphics",s))}function WS(t,e,n){for(const{column:i,key:r}of t){const{meta:s}=i,o=i.length-i.nullCount;if(o===0){n.push(Tn(w.EMPTY_COLUMN,`${e} column "${s.name}" has no set cell and is not written: GML writes cells, never declarations`,s.name,0));continue}if(s.role===null&&(r==="label"||e==="edge"&&(r==="id"||r==="key"))){n.push(Tn(w.ROLE_ASSUMED,`${e} column "${s.name}" is written under "${r}" and reads back with the ${r==="label"?"label":r} role`,s.name,o));continue}if(i.dtype==="list"||!(i.dtype==="string"||i.dtype==="dict"))continue;const l=new no(rf);for(let c=0;c<i.length&&!l.decided;c++)i.isSet(c)&&l.observe(i.value(c));const a=l.decide()==="dict";i.dtype==="string"&&a?n.push(Tn(w.STORAGE_CLASS,`${e} column "${s.name}" reads back as dict (low cardinality)`,s.name,null)):i.dtype==="dict"&&!a&&n.push(Tn(w.STORAGE_CLASS,`${e} column "${s.name}" reads back as string (cardinality too high for a dict)`,s.name,null))}}function MK(t,e,n){const i=Jb(t);if(i===null)return;const{name:r}=i.meta,o=e.some(l=>l.key==="position")?"position#graphics":"position";r!==o&&n.push(Tn(w.COLUMN_NAME_CHANGED,`node column "${r}" (position) is written as the graphics x / y / z keys and reads back as "${o}"`,r,i.length-i.nullCount))}function BS(t,e){const n=Jv(t,e),i=Un(t,Kv,n.common,{positionDtype:"f64",roles:NK,roleNames:AK}),r=new Set(Xv);(n.common.sanitizeIds==="mangle"&&UK(t)>0||t.nodes.byRole("originalId")!==null)&&r.add(Br);const s=t.edges.byRole("id"),o=tD(t,n,s),l=nD(t),a=Vr(t.nodes,r,"node",n,i),c=Vr(t.edges,o,"edge",n,i,h=>h!==s),d=Vr(t.graph,qv,"graph",n,i,h=>!vu(h)),u=Vr(t.graph,l,"top-level",n,i,vu);if(Kc(a,"node",n,i),Kc(c,"edge",n,i),Kc(d,"graph",n,i),Kc(u,"top-level",n,i),xK(t,i),MK(t,a,i),WS(a,"node",i),WS(c,"edge",i),!Zv(t)){const h=c.find(p=>p.key===n.weightKey);h!==void 0&&i.push(Tn(w.WEIGHT_KEY_CLASH,`edge column "${h.column.meta.name}" is written under "${n.weightKey}", the key the importer reads edge weights from; it reads back as the weight, not as a column`,h.column.meta.name,h.column.length-h.column.nullCount))}const f=Gt(t);return f.mutualCount>0&&i.push(Tn(w.MUTUAL_EXPANDED,`${f.mutualCount} mutual pair${O(f.mutualCount)} ${C(f.mutualCount,"is","are")} written as two directed edges; the mutual mark is lost`,null,f.mutualCount)),Object.freeze(i)}function tD(t,e,n){const i=new Set(IK);return Zv(t)&&i.add(e.weightKey),n!==null&&i.add("id"),i}function nD(t){const e=new Set($K);return t.meta.creator!==null&&e.add("Creator"),t.meta.sourceFormat==="gml"&&t.meta.sourceVersion!==null&&e.add("Version"),e}function UK(t){let e=0;for(let n=0;n<t.nodeCount;n++){const i=t.ids.idOf(n);(typeof i!="number"||!Number.isSafeInteger(i))&&e++}return e}function em(t,e){switch(e.dtype){case"i32":case"u32":case"u8":return Ge(t);case"f32":return zs(t,"f32");default:return e.origin?.type==="int"&&Number.isInteger(t)?Ge(t):zs(t,"f64")}}function iD(t){switch(typeof t){case"number":return Number.isInteger(t)?Ge(t):zs(t,"f64");case"boolean":return t?"1":"0";default:return Pi(t)}}function GK(t,e,n){switch(typeof t){case"number":switch(e){case"i32":case"u32":case"u8":return Ge(t);case"f32":return zs(t,"f32");case"json":return iD(t);default:return n.origin?.type==="int"&&Number.isInteger(t)?Ge(t):zs(t,"f64")}case"boolean":return t?"1":"0";case"string":return Pi(t);default:throw new N("E_COLUMN_TYPE",`column "${n.name}": a ${typeof t} list item cannot be written as GML`,{column:n.name,found:typeof t})}}class jK{constructor(e){this.lines=[],this.mangle=e}take(){const e=this.lines.join("");return this.lines.length=0,e}line(e,n,i){this.lines.push(`${e}${n} ${i}
|
|
144
|
+
`)}raw(e){this.lines.push(`${e}
|
|
145
|
+
`)}cell(e,n,i,r){const{meta:s,dtype:o}=i;switch(o){case"f32":case"f64":case"i32":case"u32":case"u8":{const{components:l}=s;if(l===1)this.line(e,n,em(i.data[r],s));else for(let a=0;a<l;a++)this.line(e,n,em(i.data[r*l+a],s));return}case"bool":this.line(e,n,i.value(r)===!0?"1":"0");return;case"dict":case"string":this.line(e,n,Pi(i.value(r)??""));return;case"list":this.list(e,n,i.sliceOf(r),s.itemDtype??"string",s);return;case"json":this.json(e,n,i.values[r],s.name);return;default:{const l=o;throw new N("E_COLUMN_TYPE",`unknown dtype ${l}`,{dtype:l})}}}list(e,n,i,r,s){if(i.length===0){this.line(e,n,Pi(Ca));return}i.length===1&&this.line(e,n,Pi($a));for(const o of i)r==="json"&&typeof o=="object"?this.json(e,n,o,s.name,!0):this.line(e,n,GK(o,r,s))}json(e,n,i,r,s=!1){if(i!=null){if(Array.isArray(i)){if(s)throw new N("E_UNSUPPORTED",`column "${r}": an array nested in an array cannot be written as GML`,{reason:"nested array",column:r});if(i.length===0){this.line(e,n,Pi(Ca));return}i.length===1&&this.line(e,n,Pi($a));for(const o of i)this.json(e,n,o,r,!0);return}if(typeof i=="object"){this.record(e,n,i,r);return}if(typeof i=="number"||typeof i=="string"||typeof i=="boolean"){this.line(e,n,iD(i));return}throw new N("E_COLUMN_TYPE",`column "${r}": a ${typeof i} cannot be written as GML`,{column:r,found:typeof i})}}record(e,n,i,r,s=null){this.raw(`${e}${n} [`);const o=`${e} `,l=new Set;if(s!==null)for(const[a,c]of s)this.line(o,a,c),l.add(a);for(const a of Object.keys(i)){if(l.has(a)&&s!==null&&(a==="x"||a==="y"||a==="z"))continue;const c=this.recordKey(a,l,r);l.add(c),this.json(o,c,i[a],r)}this.raw(`${e}]`)}recordKey(e,n,i){if(zo(e)&&!n.has(e))return e;if(!this.mangle)throw new N("E_UNSUPPORTED",`column "${i}": record key "${e}" ${zo(e)?"repeats a key":"is not a GML key"}; pass sanitizeKeys: "mangle" to rewrite it`,{reason:"gml key",column:i,key:e});return Qv(zo(e)?e:Dl(e),n)}}function FK(t,e){const n=Jv(t,e),i=wl(t,"integer",n.common.sanitizeIds),r=yl(t);if(r>0&&n.common.onMixedDirection==="error")throw new N("E_DIRECTED",`${r} undirected edge${O(r)} in a directed graph, and GML holds one direction per file, so the save fails unless onMixedDirection is "directed" or "undirected"`,{reason:"mixed direction",count:r});const s=r>0,o=t.directed&&n.common.onMixedDirection!=="undirected",l=t.nodes.byRole("originalId"),a=new Set(Xv);(i.changed>0||l!==null)&&a.add(Br);const c=t.edges.byRole("id"),d=tD(t,n,c),u=nD(t);return{snapshot:t,plan:n,ids:i,writeDirected:o,foldPairs:s,nodeColumns:Vr(t.nodes,a,"node",n,null,f=>!(f.meta.name==="graphics"&&f.dtype==="json")),edgeColumns:Vr(t.edges,d,"edge",n,null,f=>f!==c),graphColumns:Vr(t.graph,qv,"graph",n,null,f=>!vu(f)),topColumns:Vr(t.graph,u,"top-level",n,null,vu),position:Jb(t),graphics:eD(t),originalIds:l,edgeIds:c,weights:Ot(t),folding:Gt(t)}}function HS(t){return typeof t=="string"?Pi(t):Number.isSafeInteger(t)?Ge(t):zs(t,"f64")}function*zK(t){const{snapshot:e,plan:n,ids:i}=t,r=new jK(n.mangle),{meta:s}=e;s.creator!==null&&r.line("","Creator",Pi(s.creator)),s.sourceFormat==="gml"&&s.sourceVersion!==null&&r.line("","Version",kK(s.sourceVersion));for(const{column:d,key:u}of t.topColumns)d.isSet(0)&&r.cell("",u,d,0);r.raw("graph ["),r.line(" ","directed",t.writeDirected?"1":"0");const o=s.declaredMultigraph??(e.flags.multigraph?!0:null);o!==null&&r.line(" ","multigraph",o?"1":"0");for(const{column:d,key:u}of t.graphColumns)d.isSet(0)&&r.cell(" ",u,d,0);yield r.take();for(let d=0;d<e.nodeCount;d++){if(r.raw(" node ["),r.line(" ","id",Ge(i.idAt(d))),i.isChanged(d))r.line(" ",Br,HS(i.originalAt(d)));else if(t.originalIds?.isSet(d)){const u=t.originalIds.value(d);(typeof u=="string"||typeof u=="number")&&r.line(" ",Br,HS(u))}for(const{column:u,key:f}of t.nodeColumns)u.isSet(d)&&r.cell(" ",f,u,d);WK(r,t,d),r.raw(" ]"),yield r.take()}const l=e.edgeList(),a=s.weightOrigin,c=a!==null&&a.type==="int";for(let d=0;d<e.edgeCount;d++)if(!(t.foldPairs&&t.folding.folded(d))){if(r.raw(" edge ["),r.line(" ","source",Ge(i.idAt(l.src[d]))),r.line(" ","target",Ge(i.idAt(l.dst[d]))),t.edgeIds?.isSet(d)&&r.cell(" ","id",t.edgeIds,d),t.weights.isExplicit(d)){const u=t.weights.value(d),f=c&&Number.isInteger(u)?Ge(u):zs(u,t.weights.dtype);r.line(" ",n.weightKey,f)}for(const{column:u,key:f}of t.edgeColumns)u.isSet(d)&&r.cell(" ",f,u,d);r.raw(" ]"),yield r.take()}r.raw("]"),yield r.take()}function WK(t,e,n){const{position:i,graphics:r}=e,s=i?.isSet(n)===!0,o=r?.isSet(n)?r.values[n]:void 0;if(!s){r!==null&&o!==void 0&&t.cell(" ","graphics",r,n);return}const l=i,{components:a}=l.meta,c=Math.min(a,3),d=[],u=["x","y","z"];for(let h=0;h<c;h++)d.push([u[h],em(l.data[n*a+h],l.meta)]);let f={};if(o!==void 0){if(typeof o!="object"||o===null||Array.isArray(o))throw new N("E_UNSUPPORTED",`node ${n}: the graphics value is not a record and cannot hold the position`,{reason:"graphics conflict",node:n});f=o}t.record(" ","graphics",f,"graphics",d)}const BK=Object.freeze({format:"gml",options:Object.freeze(["sanitizeKeys","weightKey"]),capabilities:Kv,styles:Object.freeze({capabilities:va}),check(t,e){const n=Vv(t,e?.styles);return n===null?BS(t,e):Object.freeze([...BS(n.snapshot,e),...n.notes])},export(t,e){return ti(VS(t,e))},exportToString(t,e){return ni(VS(t,e))}});function*VS(t,e){yield*zK(FK(Vv(t,e?.styles)?.snapshot??t,e))}const tm=ls,rD=Qn,sD=dt,oD="E_GML_MISSING_LABEL",lD=Zn,nm="E_GML_ID_TYPE",aD="W_GML_STRING_ID",im=sn,rm="E_GML_REPEATED_KEY",cD="E_GML_ELEMENT_TYPE",dD="E_GML_FLAG_TYPE",Rd="W_GML_FLAG_VALUE",HK=/^\s*[+-]?\d+\s*$/,sm="W_GML_UNKNOWN_ENTITY",om="W_GML_GRAPHICS",lm="W_GML_NESTED_ELEMENT",Ld="W_GML_GROUPS",VK="graphty.parent",am=fa,Wl=re,YK=ln,KK=bn,uD="W_GML_ID_DROPPED",YS={ids:"canonical",defaultDirected:!1,weightFrom:"value"},Pd=1,Du=2,ia=4,ra=8,XK=-2147483648,qK=2147483647,JK=64,KS=new Set(["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","restoreMangledIds","long","errorLimit","signal","onProgress"]),dp=-1,XS=-2;function ZK(t,e){return cm(t,e)==="label"}function up(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function cm(t,e){if(e==="label"&&t!=="graph")return"label";if(t==="edge"){if(e==="id")return"id";if(e==="key")return"key"}return null}class qS{constructor(e,n,i,r,s=0){this.which=s,this.tokens=null,this.graphCount=0,this.resolver=null,this.nodeSchema=new Map,this.edgeSchema=new Map,this.graphSchema=new Map,this.topSchema=new Map,this.nodePlans=new Map,this.edgePlans=new Map,this.graphPlans=new Map,this.topPlans=new Map,this.graphNames=new Set,this.graphOpen=-1,this.directedToken=-1,this.multigraphToken=-1,this.creatorToken=-1,this.versionToken=-1,this.nodeCount=0,this.edgeCount=0,this.weightKinds=0,this.hasOriginalId=!1,this.headerDirected=!1,this.seq=0,this.nodeOrdinal=0,this.elementsSinceCheck=0,this.idMap=null,this.skippedIds=new Set,this.groupRefs=[],this.rootCluster=-1,this.parentHandle=null,this.clusterCount=0,this.declared=new Uint32Array(64),this.touched=[],this.graphTouched=[],this.seqNow=0,this.sink=e,this.report=n,this.options=i,this.positions=r?.positions??!0,this.keepPositionSource=r?.keepPositionSource??!1,this.dictionaries=r?.dictionaries??!0,this.coercer=new Mn(i.ids)}run(e){this.tokens=e,e.onUnknownEntity=(n,i)=>{this.report.warnOnce("parse-error",sm,`character entity ${n} cannot be decoded; it is kept as written`,{line:i,element:n},`${sm}:${n}`)},this.scan(),this.push()}scan(){const e=this.requireTokens();let n=-1;for(let i=0;i<e.count;i=e.nextPair(i)){const r=e.textOf(i),s=i+1,o=e.kind[s]===ke;r==="graph"&&!o&&n<0&&(n=s),this.scanTopPair(r,o,s)}this.graphOpen<0&&this.failNoGraph(e,n)}scanTopPair(e,n,i){e==="graph"&&n?this.graphCount++===this.which&&(this.graphOpen=i,this.scanGraph(i)):e==="Creator"&&!n&&this.creatorToken<0?this.creatorToken=i:e==="Version"&&!n&&this.versionToken<0?this.versionToken=i:e==="rootcluster"&&n&&this.rootCluster<0?this.rootCluster=i:this.observe(this.topSchema,"graph",e,i,XS)}failNoGraph(e,n){n>=0&&this.report.fail(tm,`the graph key at line ${e.line[n]} holds ${Eo(e,n)}, not a [ ... ] block; the input contains no graph block`,{line:e.line[n]}),this.report.fail(tm,"the input contains no graph [ ... ] block",{line:null})}scanGraph(e){const n=this.requireTokens(),i=n.match[e];for(let r=e+1;r<i;r=n.nextPair(r)){const s=n.textOf(r),o=r+1;switch(s){case"node":n.kind[o]===ke&&(this.nodeCount++,this.scanElement("node",o));break;case"edge":n.kind[o]===ke&&(this.edgeCount++,this.scanElement("edge",o));break;case"directed":this.directedToken<0&&(this.directedToken=o);break;case"multigraph":this.multigraphToken<0&&(this.multigraphToken=o);break;default:this.observe(this.graphSchema,"graph",s,o,dp)}}}scanElement(e,n){const i=this.requireTokens(),r=i.match[n],s=this.seq++,o=e==="node"?this.nodeSchema:this.edgeSchema;for(let l=n+1;l<r;l=i.nextPair(l)){const a=i.textOf(l),c=l+1;this.skipsKey(e,a,c)||this.observe(o,e,a,c,s)}}skipsKey(e,n,i){const{weightFrom:r,restoreMangledIds:s}=this.options;return e==="node"?n===Br&&s?(this.hasOriginalId=!0,!0):n==="id":n==="source"||n==="target"||n==="directed"?!0:n===r?(this.weightKinds|=QK(this.requireTokens(),i),!0):!1}observe(e,n,i,r,s){const o=this.requireTokens();this.noteStructure(n,i,r);let l=e.get(i);const a=n==="node"&&i==="graphics"&&this.positions;switch(l===void 0?(l={key:i,kinds:0,list:!1,lastSeq:s,wide:!1,unsafe:!1,dict:this.dictionaries&&cm(n,i)===null?new no:null,position:!1,rest:!1},e.set(i,l)):l.lastSeq===s?(l.list=!0,l.rest||=a):l.lastSeq=s,a&&o.kind[r]!==ke&&(l.rest=!0),o.kind[r]){case pt:{const c=o.textOf(r);if(c===$a||!ZK(n,i)&&(c===Ca||c===qg)){l.list=!0;return}l.kinds|=ia,l.dict!==null&&!l.dict.decided&&l.dict.observe(c);return}case Ss:{l.kinds|=Pd;const c=Number(o.textOf(r));(c<XK||c>qK)&&(l.wide=!0,Number.isSafeInteger(c)||(l.unsafe=!0));return}case ke:l.kinds|=ra,n==="node"&&i==="graphics"&&this.positions&&this.inspectGraphics(l,r);return;default:{l.kinds|=Du;const c=o.textOf(r);/\d/.test(c)&&!Number.isFinite(Number(c))&&this.report.warnOnce("precision",Wl,`${n} key "${i}" holds the real ${c}, beyond the f64 range; it is stored as ${Os(c)>0?"":"-"}Infinity`,{line:o.line[r],element:i},`${Wl}:overflow:${n}:${i}`)}}}noteStructure(e,n,i){const r=this.requireTokens();e!=="graph"&&(n==="graph"||n==="node"||n==="edge")&&r.kind[i]===ke&&this.report.warnOnce("unsupported",lm,`a nested ${n} record inside a ${e} is kept as the json column "${n}"; it is not read as structure`,{line:r.line[i],element:n},`${lm}:${e}:${n}`)}inspectGraphics(e,n){const i=this.requireTokens(),r=i.match[n];let s=!1,o=!1,l=!1;for(let c=n+1;c<r;c=i.nextPair(c)){const d=i.textOf(c),u=i.kind[c+1]===Ss||i.kind[c+1]===Vb;d==="x"&&u&&!s?s=!0:d==="y"&&u&&!o?o=!0:d==="z"&&u||(l=!0)}const a=s&&o;e.position||=a,e.rest||=a?l||this.keepPositionSource:!0}push(){const{sink:e,report:n,options:i}=this,r=this.requireTokens();e.reserve(this.nodeCount,this.edgeCount),this.buildPlans(),this.setMetadata(),this.headerDirected=this.readFlag(this.directedToken,"directed")??i.defaultDirected;const s=new ei(e,n,i.onMixedDirection);s.setHeader(this.headerDirected,{line:this.directedToken>=0?r.line[this.directedToken]:r.line[this.graphOpen]}),this.resolver=s,(i.nodeIdFrom!=="id"||this.hasOriginalId)&&(this.idMap=new Map),i.nodeIdFrom!=="id"&&n.loss(uD,`node ids taken from the ${i.nodeIdFrom}; the integer id keys are not kept as a column`,null,this.nodeCount),this.pushTopLevel(),this.pushNodes(),this.pushGroups(),this.pushClusters(),this.pushEdges()}pushGroups(){const e=this.requireTokens();for(const[n,i]of this.groupRefs){let r=A;try{const s=this.coerceFileId(i,this.fileIdOf(i,"gid"));r=this.sink.indexOf(this.idMap?.get(s)??s)}catch{r=A}if(r===A||r===n){this.report.warnOnce("validation-error",Ld,`gid ${e.kind[i]===ke?"[...]":e.textOf(i)} names no other node; it is kept as a plain column value`,{line:e.line[i],element:"gid"});continue}this.setParent(n,r,"gid")}}setParent(e,n,i){this.parentHandle??=this.sink.declareNodeColumn({name:Xt(VK,null,r=>this.sink.nodeColumn(r)!==A),dtype:"u32",role:"parent",refersTo:"node",nullable:!0,origin:{format:"gml",id:null,title:null,type:i,namespace:null}}),this.sink.setNodeValue(this.parentHandle,e,n)}pushClusters(){if(this.rootCluster<0)return;const e=this.requireTokens(),n=[[this.rootCluster,A]];for(let i=n.pop();i!==void 0;i=n.pop()){const[r,s]=i;for(let o=r+1;o<e.match[r];o=e.nextPair(o)){const l=e.textOf(o),a=o+1;if(l==="cluster"&&e.kind[a]===ke){const c=this.addCluster(a,s);c!==A&&n.push([a,c])}else l==="vertex"&&s!==A&&this.addClusterVertex(a,s)}}}addClusterVertex(e,n){const i=this.requireTokens(),r=i.kind[e]===pt?this.coercer.text(i.stringOf(e)):null,s=r===null?A:this.sink.indexOf(this.idMap?.get(r)??r);if(s===A||s===n){this.report.warnOnce("validation-error",Ld,`cluster vertex ${Eo(i,e)} names no node; it is in no cluster`,{line:i.line[e],element:"vertex"});return}this.setParent(s,n,"rootcluster")}addCluster(e,n){const i=this.requireTokens(),r=Jg(i,e),s=this.clusterCount++,o=typeof r.id=="number"||typeof r.id=="string"?String(r.id):null,l=`#${String(s)}`,a=`cluster${o??l}`;if(this.sink.indexOf(a)!==A)return this.report.warnOnce("validation-error",Ld,`cluster ${a} has the id of a node; it is read as no group`,{line:i.line[e],element:a}),A;const c=this.sink.addNode(a);this.report.counts.nodes++,n!==A&&this.setParent(c,n,"rootcluster");const d=this.nodePlans.get("label");typeof r.label=="string"&&r.label!==""&&d?.kind==="string"&&!d.list&&this.sink.setNodeValue(this.handleOf(d,"node"),c,r.label);const u=this.nodePlans.get("graphics"),f=up(r.graphics)?r.graphics:null;if(f===null||u?.position===void 0||u.position===null)return c;const{x:h,y:p,width:g,height:m,color:y,style:b,stipple:_,...S}=f;return typeof h=="number"&&typeof p=="number"&&typeof g=="number"&&typeof m=="number"&&(this.sink.setNodeValue(this.handleOf(u.position,"node"),c,[h+g/2,p+m/2,0]),Object.assign(S,{w:g,h:m})),Object.assign(S,y===void 0?{}:{outline:y},b===void 0?{}:{type:b},_===void 0?{}:{clusterStipple:_}),u.rest!==null&&this.sink.setNodeValue(this.handleOf(u.rest,"node"),c,S),c}buildPlans(){for(const[e,n]of this.nodeSchema)this.nodePlans.set(e,this.planOf("node",n));for(const[e,n]of this.edgeSchema)this.edgePlans.set(e,this.planOf("edge",n));for(const[e,n]of this.graphSchema)this.graphPlans.set(e,this.planOf("graph",n));for(const[e,n]of this.topSchema)this.topPlans.set(e,this.planOf("graph",n,!0))}warnKinds(e,n,i){(n.kinds&ia)!==0&&(n.kinds&(Pd|Du))!==0&&(n.kinds&ra)===0&&this.report.warnOnce("coercion",am,`${e} key "${n.key}" mixes numbers and strings; the column is string and the numbers are kept as written`,{element:n.key},`${am}:${e}:${n.key}`),n.unsafe&&!i&&this.report.warnOnce("precision",Wl,`${e} key "${n.key}" holds integers beyond 2^53; they are stored as the nearest f64 (pass long: "string" to keep every digit as text)`,{element:n.key},`${Wl}:${e}:${n.key}`)}graphicsPlan(e,n){const r={...e,name:Xt("position","graphics",o=>this.nodeSchema.has(o)||this.sink.nodeColumn(o)!==A),dtype:"f64",itemDtype:null,kind:"real",list:!1,role:"position"},s=n.rest?{...e,dtype:"json",itemDtype:null,kind:"record",list:!1}:null;return{...e,position:r,rest:s}}planOf(e,n,i=!1){const r=n.unsafe&&this.options.long==="string"&&JS(n)==="int",s=r?"string":JS(n);let o=eX(s,n);o==="string"&&!n.list&&n.dict!==null&&n.kinds===ia&&n.dict.decide()==="dict"&&(o="dict"),this.warnKinds(e,n,r);const l=e==="graph"?this.uniqueGraphName(n.key):n.key;let a=null;n.list&&(a=o==="dict"?"string":o);const c={key:n.key,name:l,dtype:n.list?"list":o,itemDtype:a,kind:s,list:n.list,role:cm(e,n.key),top:i,position:null,rest:null,handle:A,declared:!1,items:null,seq:Number.NEGATIVE_INFINITY};return e==="node"&&n.key==="graphics"&&this.positions&&(n.kinds&ra)!==0?this.graphicsPlan(c,n):c}uniqueGraphName(e){const n=Xt(e,e,i=>this.graphNames.has(i));return this.graphNames.add(n),n!==e&&this.report.warning("coercion",YK,`the top-level key "${e}" and a key of the graph block share the graph column name; the top-level value is stored as "${n}"`,{element:e}),n}setMetadata(){const e=this.requireTokens(),{sink:n,options:i}=this,r=o=>e.kind[o]===pt?e.stringOf(o):e.textOf(o),s=this.readFlag(this.multigraphToken,"multigraph");n.setMeta({sourceFormat:"gml",creator:this.creatorToken>=0?r(this.creatorToken):void 0,sourceVersion:this.versionToken>=0?r(this.versionToken):void 0,declaredMultigraph:s??void 0,weightOrigin:this.weightKinds!==0&&i.weightFrom!==null?{format:"gml",id:i.weightFrom,title:null,type:this.weightKinds===Pd?"int":"real",namespace:null}:void 0,extra:this.directedToken>=0?{gml:{directed:r(this.directedToken)}}:void 0})}readFlag(e,n){if(e<0)return null;const i=this.requireTokens(),r=i.kind[e]===pt&&HK.test(i.stringOf(e));if(r)this.report.warning("validation-error",Rd,`flag "${n}" is written as the string ${Eo(i,e)}; read as an integer`,{line:i.line[e],element:n});else if(i.kind[e]!==Ss)return this.report.error("validation-error",dD,`flag "${n}" must be the integer 0 or 1, found ${Eo(i,e)}`,{line:i.line[e],element:n}),null;const s=Number(r?i.stringOf(e):i.textOf(e));return s!==0&&s!==1&&this.report.warning("validation-error",Rd,`flag "${n}" is ${s}; read as ${s!==0?"1":"0"}`,{line:i.line[e],element:n}),s!==0}pushTopLevel(){const e=this.requireTokens();for(let n=0;n<e.count;n=e.nextPair(n)){const i=n+1;if(i===this.graphOpen||i===this.creatorToken||i===this.versionToken)continue;const r=this.topPlans.get(e.textOf(n));r!==void 0&&this.writeGraph(r,i,XS)}this.flushGraphLists()}pushNodes(){const e=this.requireTokens(),n=e.match[this.graphOpen];for(let i=this.graphOpen+1;i<n;i=e.nextPair(i)){const r=e.textOf(i),s=i+1;switch(r){case"node":e.kind[s]===ke?this.importNode(s):(this.badElement("node",i),this.report.counts.skippedNodes++);break;case"edge":break;case"directed":case"multigraph":s!==this.directedToken&&s!==this.multigraphToken&&this.report.warning("validation-error",Rd,`graph flag "${r}" repeated; the first value stands`,{line:e.line[i],element:r});break;default:{const o=this.graphPlans.get(r);o!==void 0&&this.writeGraph(o,s,dp)}}}this.flushGraphLists()}pushEdges(){const e=this.requireTokens(),n=e.match[this.graphOpen];let i=0;for(let r=this.graphOpen+1;r<n;r=e.nextPair(r)){if(e.textOf(r)!=="edge")continue;const s=r+1;e.kind[s]===ke?this.importEdge(s,i):(this.badElement("edge",r),this.report.counts.skippedEdges++),i++}}badElement(e,n){const i=this.requireTokens();this.report.error("validation-error",cD,`${e} must be a [ ... ] block, found ${Eo(i,n+1)}`,{line:i.line[n],element:e})}nodeKeyTokens(e,n){const i=this.requireTokens();let r=-1,s=-1,o=-1;for(let l=e+1;l<n;l=i.nextPair(l)){const a=i.textOf(l);a==="id"?r=this.structuralToken(r,l,"id"):a==="label"?s=s<0?l+1:s:a===Br&&this.options.restoreMangledIds&&(o=o<0?l+1:o)}return{idTok:r,labelTok:s,originalTok:o}}nodeSinkId(e,n,i,r){if(i>=0)return this.restoredId(i);switch(this.options.nodeIdFrom){case"label":if(n<0)throw new N("E_INVALID_ID","node has no label",{reason:"missing label"});return this.coerceValueToken(n);case"index":return r;default:return e}}mapFileId(e,n,i){if(this.idMap===null)return;const r=this.idMap.get(e);r!==void 0&&r!==n&&this.report.warning("merged",im,`file id ${JSON.stringify(e)} is declared twice (nodes ${JSON.stringify(r)} and ${JSON.stringify(n)}); edges to it resolve to the later`,{line:i,element:String(e)}),this.idMap.set(e,n)}importNode(e){const n=this.requireTokens(),{sink:i,report:r}=this,s=n.match[e],o=n.line[e],l=this.nodeOrdinal++;this.checkAbort();let a,c,d;try{const{idTok:u,labelTok:f,originalTok:h}=this.nodeKeyTokens(e,s);if(u<0)throw new N("E_INVALID_ID","node has no id",{reason:"missing id"});d=this.coerceFileId(u,this.fileIdOf(u,"id")),c=this.nodeSinkId(d,f,h,l),a=i.addNode(c),this.mapFileId(d,c,o)}catch(u){this.recordNodeError(u,o),r.counts.skippedNodes++,d!==void 0&&this.skippedIds.add(d);return}this.isDeclared(a)?r.warning("merged",im,`node ${JSON.stringify(c)} is declared twice; later keys overwrite`,{line:o,element:String(c)}):(this.markDeclared(a),r.counts.nodes++),this.beginElement(this.seq++);try{this.writeNodeKeys(e,a,c),this.flushLists("node",a)}catch(u){this.touched.length=0,r.recordError(u,{line:o,element:String(c)})}}writeNodeKeys(e,n,i){const r=this.requireTokens(),s=[];let o=null;for(let l=e+1;l<r.match[e];l=r.nextPair(l)){const a=r.textOf(l);if(a==="id"||a===Br&&this.options.restoreMangledIds)continue;a==="gid"&&this.groupRefs.push([n,l+1]);const c=this.nodePlans.get(a);c!==void 0&&c.position!==null?(o=c,s.push(l+1)):c!==void 0&&this.writeNode(c,n,l+1)}o!==null&&this.writeGraphics(o,n,s,{line:r.line[s[0]],element:String(i)})}importEdge(e,n){const i=this.requireTokens(),{sink:r,report:s,options:o}=this,l=i.match[e],a=i.line[e],c=`edge #${n}`;this.checkAbort();let d;try{let u=-1,f=-1,h=-1,p=-1;for(let $=e+1;$<l;$=i.nextPair($)){const D=i.textOf($);D==="source"?u=this.structuralToken(u,$,"source"):D==="target"?f=this.structuralToken(f,$,"target"):D==="directed"?p=this.structuralToken(p,$,"directed"):D===o.weightFrom&&(h=$+1)}if(u<0||f<0)throw new N("E_UNKNOWN_NODE",`edge has no ${u<0?"source":"target"}`,{reason:"missing endpoint"});const g=this.endpoint(u,"source"),m=this.endpoint(f,"target"),y=h>=0?this.weightOf(h):void 0,b=r.edgeCount,_=r.indexOf(g)===A,S=g!==m&&r.indexOf(m)===A,T=this.readFlag(p,"directed")??this.headerDirected;d=this.requireResolver().addEdge(g,m,T?"directed":"undirected",y,{line:a,element:c}),s.counts.edges+=r.edgeCount-b,s.counts.nodes+=(_?1:0)+(S?1:0)}catch(u){this.recordEdgeError(u,a,c),s.counts.skippedEdges++;return}this.beginElement(this.seq++);try{for(let u=e+1;u<l;u=i.nextPair(u)){const f=i.textOf(u);if(f==="source"||f==="target"||f==="directed"||f===o.weightFrom)continue;const h=this.edgePlans.get(f);h!==void 0&&this.writeEdge(h,d,u+1)}this.flushLists("edge",d)}catch(u){this.touched.length=0,s.recordError(u,{line:a,element:c})}}structuralToken(e,n,i){if(e>=0)throw new N("E_INVALID_ID",`key "${i}" appears twice in one block`,{reason:"duplicate key",key:i});return n+1}fileIdOf(e,n){const i=this.requireTokens();if(i.kind[e]===pt)return this.report.warnOnce("validation-error",aD,`${n} is the string "${i.textOf(e)}"; GML ids are integers, string ids are kept under the ids rule`,{line:i.line[e],element:i.stringOf(e)}),i.stringOf(e);if(i.kind[e]!==Ss)throw new N("E_INVALID_ID",`${n} must be an integer or a string, found ${Eo(i,e)}`,{reason:"not an integer",key:n,value:i.kind[e]===ke?"[...]":i.textOf(e)});return Number(i.textOf(e))}coerceFileId(e,n){return typeof n=="string"?this.coercer.text(n):this.coerceInteger(e,n)}coerceInteger(e,n){return Number.isSafeInteger(n)&&this.coercer.mode!=="string"?this.coercer.value(n):this.coercer.text(this.requireTokens().textOf(e))}coerceValueToken(e){const n=this.requireTokens();switch(n.kind[e]){case pt:return this.coercer.text(n.stringOf(e));case Ss:return this.coerceInteger(e,Number(n.textOf(e)));case ke:throw new N("E_INVALID_ID","label must be a string or a number, found a record",{reason:"record label"});default:return this.coercer.value(Os(n.textOf(e)))}}restoredId(e){const n=this.requireTokens();switch(n.kind[e]){case pt:return n.stringOf(e);case ke:throw new N("E_INVALID_ID",`${Br} must be a string or a number`,{reason:"record original id"});default:return Os(n.textOf(e))}}endpoint(e,n){const i=this.coerceFileId(e,this.fileIdOf(e,n)),r=this.idMap?.get(i);if(r!==void 0)return r;if(this.skippedIds.has(i))throw new N("E_UNKNOWN_NODE",`${n} ${JSON.stringify(i)} names a node block that was skipped after an error`,{reason:"skipped node",id:i});return i}weightOf(e){const n=this.requireTokens();switch(n.kind[e]){case pt:return Kn(n.stringOf(e),this.report);case ke:throw new N("E_INVALID_WEIGHT","edge weight is a record",{value:"[...]"});default:{const i=n.textOf(e),r=of(Os(i));return r!==void 0&&oT(i,r,this.report),r}}}recordNodeError(e,n){const{report:i}=this;if(e instanceof N&&e.code==="E_INVALID_ID"){const{reason:r}=e.details;switch(r){case"missing id":i.error("missing-value",sD,e.message,{line:n,element:"node"});return;case"missing label":i.error("missing-value",oD,e.message,{line:n,element:"node"});return;case"duplicate key":i.error("validation-error",rm,e.message,{line:n,element:"node"});return;case"not an integer":i.error("validation-error",nm,e.message,{line:n,element:"node"});return}}i.recordError(e,{line:n,element:"node"})}recordEdgeError(e,n,i){const{report:r}=this;if(e instanceof N){const{reason:s}=e.details;if(e.code==="E_UNKNOWN_NODE"&&s==="missing endpoint"){r.error("missing-value",lD,e.message,{line:n,element:i});return}if(e.code==="E_INVALID_ID"&&s==="duplicate key"){r.error("validation-error",rm,e.message,{line:n,element:i});return}if(e.code==="E_INVALID_ID"&&s==="not an integer"){r.error("validation-error",nm,e.message,{line:n,element:i});return}}r.recordError(e,{line:n,element:i})}writeNode(e,n,i){if(e.list){this.collectItem(e,i,this.seqNow,this.touched);return}this.sink.setNodeValue(this.handleOf(e,"node"),n,this.scalarOf(e,i))}writeEdge(e,n,i){if(e.list){this.collectItem(e,i,this.seqNow,this.touched);return}this.sink.setEdgeValue(this.handleOf(e,"edge"),n,this.scalarOf(e,i))}writeGraph(e,n,i){if(e.list){this.collectItem(e,n,i,this.graphTouched);return}const r=this.scalarOf(e,n);this.sink.setGraphValue(e.name,r,ZS(e)),i===dp&&e.key==="name"&&typeof r=="string"&&this.sink.setMeta({name:r})}writeGraphics(e,n,i,r){const s=this.requireTokens(),{sink:o}=this,l=i.map(u=>s.kind[u]===ke?Jg(s,u):this.scalarOf(e,u)),a=l[0],c=e.position;let d=a;if(up(a)&&c!==null){const u=this.writePosition(c,n,this.keepPositionSource?{...a}:a,r);d=this.keepPositionSource?a:u}else up(a)||this.graphicsWarning("scalar",`node ${r.element}'s graphics is not a record`,r);l.length>1&&(this.graphicsWarning("repeated",`node ${r.element} has ${l.length} graphics records; the position comes from the first`,r),d=l),d!==void 0&&e.rest!==null&&o.setNodeValue(this.handleOf(e.rest,"node"),n,d)}writePosition(e,n,i,r){const{x:s,y:o,z:l}=i;let a=i;if(typeof s=="number"&&typeof o=="number"){const c=typeof l=="number"?l:0;this.sink.setNodeValue(this.handleOf(e,"node"),n,[s,o,c]),delete i.x,delete i.y,typeof l=="number"&&delete i.z,a=Object.keys(i).length>0?i:void 0}return("x"in i||"y"in i||"z"in i)&&this.graphicsWarning("coordinate",`node ${r.element}'s graphics x / y / z is not one number each`,r),a}graphicsWarning(e,n,i){this.report.warnOnce("validation-error",om,`${n}; the value is kept in the graphics json column (warned once for every such node)`,i,`${om}:${e}`)}collectItem(e,n,i,r){const s=this.requireTokens();if(e.seq!==i&&(e.seq=i,e.items=[],r.push(e)),s.kind[n]===pt){const o=s.textOf(n);if(o===$a||o===Ca||o===qg)return}e.items.push(this.scalarOf(e,n))}beginElement(e){this.seqNow=e,this.touched.length=0}flushLists(e,n){const{sink:i,touched:r}=this;for(const s of r){const o=this.handleOf(s,e);e==="node"?i.setNodeValue(o,n,s.items):i.setEdgeValue(o,n,s.items),s.items=null}r.length=0}flushGraphLists(){const{sink:e,graphTouched:n}=this;for(const i of n)e.setGraphValue(i.name,i.items,ZS(i)),i.items=null;n.length=0}scalarOf(e,n){const i=this.requireTokens(),r=i.kind[n];switch(e.kind){case"int":return Number(i.textOf(n));case"real":return Os(i.textOf(n));case"string":return r===pt?i.stringOf(n):i.textOf(n);default:return r===pt?i.stringOf(n):EY(i,n)}}handleOf(e,n){if(e.declared)return e.handle;e.declared=!0;const{sink:i,report:r}=this,s={name:e.name,dtype:e.dtype,nullable:!0,origin:{format:"gml",id:e.key,title:null,type:fD(e),namespace:null}};e.list&&(s.itemDtype=e.itemDtype??"string"),e.role==="position"&&(s.components=3),e.role!==null&&(s.role=e.role);const o=he(i,n,s,r,{element:e.name});return e.handle=o.handle,o.renamed&&(e.name=o.decl.name),e.handle}isDeclared(e){const n=e>>>5;return n<this.declared.length&&(this.declared[n]>>>(e&31)&1)===1}markDeclared(e){const n=e>>>5;if(n>=this.declared.length){const i=new Uint32Array(Math.max(n+1,this.declared.length*2));i.set(this.declared),this.declared=i}this.declared[n]|=1<<(e&31)}checkAbort(){++this.elementsSinceCheck>=JK&&(this.elementsSinceCheck=0,F(this.options.signal))}requireTokens(){if(this.tokens===null)throw new N("E_UNSUPPORTED","the GML text was not lexed",{reason:"no tokens"});return this.tokens}requireResolver(){if(this.resolver===null)throw new N("E_DIRECTED","the header was not set",{reason:"no resolver"});return this.resolver}}function QK(t,e){switch(t.kind[e]){case Ss:return Pd;case pt:return ia;case ke:return ra;default:return Du}}function JS(t){return(t.kinds&ra)!==0?"record":(t.kinds&ia)!==0?"string":(t.kinds&Du)!==0?"real":"int"}function eX(t,e){switch(t){case"int":return e.wide?"f64":"i32";case"real":return"f64";case"string":return"string";default:return"json"}}function fD(t){return t.kind}function ZS(t){const e={name:t.name,dtype:t.dtype,nullable:!0,origin:{format:"gml",id:t.key,title:null,type:fD(t),namespace:null}};return t.list&&(e.itemDtype=t.itemDtype??"string"),t.top&&(e.extra={gmlTopLevel:!0}),e}function Eo(t,e){switch(t.kind[e]){case ke:return"a record";case pt:return`the string "${t.textOf(e)}"`;case Vb:return`the real ${t.textOf(e)}`;case Wf:return`the word ${t.textOf(e)}`;default:return t.textOf(e)}}const tX=/^(?:\s|#[^\n]*\n)*graph\s*\[/,nX=/(?:^|\s)graph\s*\[/,iX=/^(?:\s|#[^\n]*\n)*[A-Za-z_]\w*\s+(?:"|[+-]?[0-9.]|\[)/;function rX(t){let e=new TextDecoder("utf-8",{fatal:!1}).decode(t);return e.charCodeAt(0)===65279&&(e=e.slice(1)),tX.test(e)?.95:iX.test(e)?nX.test(e)?.85:.4:0}const hD=Object.freeze({format:"gml",options:Object.freeze(["dictionaries","keepPositionSource","positions"]),extensions:Object.freeze([".gml"]),mimeTypes:Object.freeze(["text/x-gml","text/plain"]),sniff:rX,styles:oK,positions:qV,async import(t,e,n){if(io(n))return vb(hD,t,e,n);const i=tt(n,YS),r=new ne("gml",i.errorLimit);_t(e,n,r),St(n,r,KS);const s=QS(await Kr(t,r,i),r);F(i.signal);const o=new qS(e,r,i,n);return o.run(s),o.graphCount>1&&r.warning("unsupported",rD,`the input holds ${o.graphCount-1} more graph block${O(o.graphCount-1)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)`),F(i.signal),r.finish()},async importAll(t,e,n){const i=tt(n,YS),r=new ne("gml",i.errorLimit);St(n,r,KS);const s=QS(await Kr(t,r,i),r),o=[];let l=1;for(let a=0;a<l;a++){F(i.signal);const c=a===0?r:new ne("gml",i.errorLimit),d=e(a);_t(d,n,c);const u=new qS(d,c,i,n,a);u.run(s),l=u.graphCount,o.push(c.finish())}return F(i.signal),o}});function QS(t,e){try{return lY(t)}catch(n){throw n instanceof Hr&&e.fail(n.code,n.message,{line:n.line}),n}}Object.freeze({...xn,...Pn,SYNTAX:kn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,NO_GRAPH:tm,MULTIPLE_GRAPHS:rD,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,MISSING_ID:sD,MISSING_LABEL:oD,MISSING_ENDPOINT:lD,ID_TYPE:nm,STRING_ID:aD,DUPLICATE_NODE:im,REPEATED_KEY:rm,ELEMENT_TYPE:cD,FLAG_TYPE:dD,FLAG_VALUE:Rd,UNKNOWN_ENTITY:sm,PRECISION:Wl,GRAPHICS:om,NESTED_ELEMENT:lm,GROUPS:Ld,WIDENED:am,COLUMN_RENAMED:ln,ROLE_TAKEN:KK,ID_MERGED:Rn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:_i,DIRECTION_FORCED:Vn,MIXED_DIRECTION:Or,ID_DROPPED:uD});const Zs="@_",kl="#text";class sX{constructor(){this.frames=[],this.root={name:"",node:{},hasAttrs:!1,hasChildren:!1,text:""}}get open(){return this.frames.length>0}start(e,n){const i={};let r=!1;for(const[s,o]of n)i[Zs+s]=o,r=!0;this.frames.push({name:e,node:i,hasAttrs:r,hasChildren:!1,text:""})}text(e){const n=this.frames.at(-1)??this.root;n.text+=e}end(){const e=this.frames.pop();if(e===void 0)throw new N("E_COLUMN_TYPE","XmlTreeBuilder.end() without a matching start()",{reason:"tree builder underflow"});const n=this.frames.at(-1)??this.root;lX(n,e.name,oX(e))}finish(){if(this.frames.length>0)throw new N("E_COLUMN_TYPE","XmlTreeBuilder.finish() with open elements",{reason:"tree builder open"});const{root:e}=this;return e.hasChildren?(Tr(e.text)||(e.node[kl]=e.text),e.node):e.text}}function oX(t){return!t.hasAttrs&&!t.hasChildren?t.text:(Tr(t.text)||(t.node[kl]=t.text),t.node)}function lX(t,e,n){t.hasChildren=!0;const i=Object.hasOwn(t.node,e)?t.node[e]:void 0;i===void 0?Object.defineProperty(t.node,e,{value:n,writable:!0,enumerable:!0,configurable:!0}):Array.isArray(i)?i.push(n):t.node[e]=[i,n]}function ku(t){if(t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean")return null;if(Array.isArray(t)){for(const e of t){if(Array.isArray(e))return"nested arrays cannot be written as elements";const n=ku(e);if(n!==null)return n}return null}if(typeof t!="object")return`a ${typeof t} cannot be written as XML`;for(const[e,n]of Object.entries(t)){if(e===kl){if(n!==null&&typeof n=="object")return"#text must be a scalar";continue}if(e.startsWith(Zs)){const r=e.slice(Zs.length);if(!ru(r))return`"${r}" is not an XML attribute name`;if(n!==null&&typeof n=="object")return`attribute ${r} must be a scalar`;continue}if(!ru(e))return`"${e}" is not an XML element name`;const i=ku(n);if(i!==null)return i}return null}function Da(t,e,n){const i=ku(t);if(i!==null)throw new N("E_COLUMN_TYPE",`a yfiles value cannot be written as XML: ${i}`,{reason:"xml tree"});if(t===null||typeof t!="object"||Array.isArray(t)){n.push(nt(ka(t)));return}const r=t;let s=null;for(const[o,l]of Object.entries(r))o===kl?s=ka(l):o.startsWith(Zs)||Zb(o,l,e,n);s!==null&&n.push(nt(s))}function Zb(t,e,n,i){if(Array.isArray(e)){for(const s of e)Zb(t,s,n,i);return}const r=n===null?"":`
|
|
146
|
+
${n}`;if(e===null||typeof e!="object"){const s=ka(e);i.push(s.length===0?`${r}<${t}/>`:`${r}<${t}>${nt(s)}</${t}>`);return}aX(t,e,n,i)}function aX(t,e,n,i){const r=n===null?"":`
|
|
147
|
+
${n}`,{attrs:s,text:o,hasChildren:l}=cX(e);if(!l){i.push(o===null||o.length===0?`${r}<${t}${s}/>`:`${r}<${t}${s}>${nt(o)}</${t}>`);return}const a=n===null||o!==null?null:`${n} `;i.push(`${r}<${t}${s}>`),o!==null&&i.push(nt(o));for(const[c,d]of Object.entries(e))c!==kl&&!c.startsWith(Zs)&&Zb(c,d,a,i);i.push(a===null?`</${t}>`:`${r}</${t}>`)}function cX(t){let e="",n=null,i=!1;for(const[r,s]of Object.entries(t))r===kl?n=ka(s):r.startsWith(Zs)?e+=` ${r.slice(Zs.length)}="${W(ka(s))}"`:i=!0;return{attrs:e,text:n,hasChildren:i}}function ka(t){switch(typeof t){case"string":return t;case"number":case"boolean":case"bigint":return String(t);default:return""}}const Ra="yfiles.",dX={position:{dtype:"f64",components:3,role:"position",mutable:!0,extra:{units:"px",yAxis:"down",anchor:"top-left",width:`${Ra}width`,height:`${Ra}height`}},width:{dtype:"f64"},height:{dtype:"f64"},color:{dtype:"string"},borderColor:{dtype:"string"},borderWidth:{dtype:"f64"},label:{dtype:"string",role:"label"},shape:{dtype:"string"}},uX={color:{dtype:"string"},width:{dtype:"f64"},directed:{dtype:"bool"},targetArrow:{dtype:"string"},sourceArrow:{dtype:"string"}};function fX(t,e,n){return{...(t==="node"?dX:uX)[e],name:Ra+e,nullable:!0,origin:{format:"graphml",id:n,title:null,type:t==="node"?"ShapeNode":"PolyLineEdge",namespace:"yfiles"}}}function hX(t){return t.nodes.byRole("position")?.meta.origin?.namespace==="yfiles"?{tool:"yed"}:null}function pD(t){return t.dtype!=="json"&&t.origin?.namespace==="yfiles"&&t.name.startsWith(Ra)}function pX(t,e,n){const i=t.meta.name.slice(Ra.length),r=[];for(const o of e)o.dtype==="json"&&o.meta.origin?.namespace==="yfiles"&&r.push(o);let s=0;for(let o=0;o<t.length;o++){const l=gX(r,n,i,o),a=t.value(o),c=t.meta.components>1&&a!==void 0?Array.from(a):a;l.has(JSON.stringify(c))||s++}return s}function gX(t,e,n,i){const r=new Set;for(const s of t){const o=gD(e,s.values[i]).find(([l])=>l===n);o!==void 0&&r.add(JSON.stringify(o[1]))}return r.size===0&&r.add(JSON.stringify(void 0)),r}function gD(t,e,n=[]){const i=[];if(t==="node"){const r=fn(e,"ShapeNode"),s=fn(e,"RectD");s!==void 0?dm({"@_x":Rt(s,"X"),"@_y":Rt(s,"Y"),"@_width":Rt(s,"Width"),"@_height":Rt(s,"Height")},i,n):r===void 0?dm(fn(bX(e),"Geometry"),i,n):mX(r,i,n)}else{const r=fn(e,"PolyLineEdge");r!==void 0&&wX(r,i,n)}return i}function mX(t,e,n){dm(fn(t,"Geometry"),e,n),ji(e,"color",fm(Rt(fn(t,"Fill"),"color")));const i=fn(t,"BorderStyle");ji(e,"borderColor",fm(Rt(i,"color"))),ji(e,"borderWidth",Co(Rt(i,"width"),"borderWidth",n));const r=fn(t,"NodeLabel");(typeof r=="string"?r.length>0:r!==void 0)&&e.push(["label",(typeof r=="string"?r:_X(r)??"").trim()]),ji(e,"shape",um(Rt(fn(t,"Shape"),"type")))}function dm(t,e,n){const i=Co(Rt(t,"x"),"x",n),r=Co(Rt(t,"y"),"y",n);i!==void 0&&r!==void 0&&e.push(["position",[i,r,0]]),ji(e,"width",Co(Rt(t,"width"),"width",n)),ji(e,"height",Co(Rt(t,"height"),"height",n))}const yX=["GenericNode","ImageNode","SVGNode","UMLClassNode","UMLNoteNode","TableNode"];function bX(t){for(const i of yX){const r=fn(t,i);if(r!==void 0)return r}const e=fn(fn(t,"ProxyAutoBoundsNode"),"Realizers"),n=Number.parseInt(Rt(e,"active")??"0",10);return EX(e)[Number.isNaN(n)?0:n]}function EX(t){return typeof t!="object"||t===null?[]:Object.entries(t).filter(([e])=>!e.startsWith("@_")&&e!=="#text").flatMap(([,e])=>Array.isArray(e)?e:[e])}function wX(t,e,n){const i=fn(t,"LineStyle");ji(e,"color",fm(Rt(i,"color"))),ji(e,"width",Co(Rt(i,"width"),"width",n));const r=fn(t,"Arrows");if(r!==void 0&&typeof r=="object"){const s=Rt(r,"target"),o=Rt(r,"source");e.push(["directed",s!==void 0&&s!=="none"]),ji(e,"targetArrow",s==="none"?void 0:um(s)),ji(e,"sourceArrow",o==="none"?void 0:um(o))}}function ji(t,e,n){n!==void 0&&t.push([e,n])}function fn(t,e){if(!(typeof t!="object"||t===null)){for(const[n,i]of Object.entries(t))if(!n.startsWith("@_")&&n!=="#text"&&Rs(n)===e)return Array.isArray(i)?i[0]:i}}function Rt(t,e){if(typeof t!="object"||t===null)return;const n=t[`@_${e}`];return typeof n=="string"?n:void 0}function _X(t){const e=typeof t=="object"&&t!==null?t["#text"]:void 0;return typeof e=="string"?e:void 0}function um(t){return t===void 0||t.length===0?void 0:t}function SX(t){if(t===void 0||t.length===0)return;const e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}function Co(t,e,n){const i=SX(t);return i===void 0&&t!==void 0&&t.length>0&&n.push(e),i}function fm(t){if(!(t===void 0||t.length===0)){if(/^#[0-9A-Fa-f]{6}$/.test(t))return t.toUpperCase();if(/^#[0-9A-Fa-f]{3}$/.test(t)){const[,e,n,i]=t;return`#${e}${e}${n}${n}${i}${i}`.toUpperCase()}return t}}const mD=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"nmtoken",dtypes:["bool","i32","f32","f64","string"],components:!1,lists:!1,json:!1,defaults:!0,options:!1,hierarchy:!0,temporal:"none",graphAttributes:!0,positions:!1,viz:!1}),OX=new Set(["directed","pair","mutual","weight","timeText","originalId"]),NX=new Set(["position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen"]),yD=new Set(["label","id","sourcePort","targetPort","parent"]),AX={graph:new Set,node:new Set(["parent"]),edge:new Set(["id","sourcePort","targetPort"])},TX=Object.freeze({label:hr,id:fb,sourcePort:hb,targetPort:pb,parent:gb}),IX="weight",$X={boolean:"bool",int:"i32",long:"f64",float:"f32",double:"f64",string:"string"},CX=2147483647,vX={node:"nodegraphics",edge:"edgegraphics",graph:"resources"};function DX(t){const e=t?.pretty??!0;if(typeof e!="boolean")throw new N("E_UNSUPPORTED","option pretty must be a boolean",{option:"pretty",found:typeof e});const n=t?.edgedefault??null;if(n!==null&&n!=="directed"&&n!=="undirected")throw new N("E_UNSUPPORTED",`option edgedefault: ${JSON.stringify(n)} is not "directed" or "undirected"`,{option:"edgedefault",found:n});return{pretty:e,edgedefault:n}}function kX(t){const e=t.meta.extra[o$];if(typeof e!="object"||e===null)return null;const n=e,i=typeof n.graphId=="string"?n.graphId:null,r=n.edgedefault==="directed"||n.edgedefault==="undirected"?n.edgedefault:null,s={};if(typeof n.namespaces=="object"&&n.namespaces!==null)for(const[o,l]of Object.entries(n.namespaces))typeof l=="string"&&(s[o]=l);return{graphId:i,edgedefault:r,namespaces:s}}function RX(t,e,n,i=!1){const r=new Set([...t.nodes,...t.edges].filter($=>pD($.meta)).map($=>$.meta.name)),s=Un(t,mD,e,{roles:yD,roleNames:TX}).filter($=>$.code!==w.JSON&&($.column===null||!r.has($.column))),o=($,D,x=null,R=null)=>{s.push(Object.freeze({code:$,message:D,column:x,count:R}))};s.push(...ky(t));const l=kX(t),a=new LX,c=fp(t.graph,"graph",s,o),d=fp(t.nodes,"node",s,o),u=fp(t.edges,"edge",s,o),f=PX([...c,...d,...u],a);if(i){const $=new Map(f.map((x,R)=>[x.id,R])),D=(x,R)=>($.get(x.keyId)??0)-($.get(R.keyId)??0);d.sort(D),u.sort(D)}eO(d,s$,o),eO(u,r$,o);const h=xX(t,u,a,f,o),p=YX(t);p>0&&o(pr.ID_TEXT_TYPE,`${p} node id${O(p)} ${C(p,"changes","change")} type when read back under ids: "canonical" (string ids that are integer text, non-integer numbers)`,null,p);const g=t.edges.byRole("id");g!==null&&MX(t,g,e,o);const y=KX(t)>0&&e.sanitizeIds==="mangle",b=y?a.next(null):null,_=Gt(t,{foldMutual:!0});_.mutualCount>0&&o(pr.MUTUAL_AS_UNDIRECTED,`${_.mutualCount} mutual pair${O(_.mutualCount)} ${C(_.mutualCount,"is","are")} written as undirected edges; the mutual mark is lost`,null,_.mutualCount);const S=UX(t,_,n,l),T=qX(t);return T.reordered&&o(pr.HIERARCHY_REORDERED,"nodes are written in containment order (children nested under their parent); node indices change after a round trip",T.parent?.meta.name??null),T.unreachable>0&&o(pr.PARENT_CYCLE,`${T.unreachable} node${O(T.unreachable)} whose parent chain never reaches a root ${C(T.unreachable,"is","are")} written at the top level`,T.parent?.meta.name??null,T.unreachable),{options:e,pretty:n.pretty,notes:s,keys:f,graphColumns:c,nodeColumns:d,edgeColumns:u,weight:h,originalIdKey:b,edgedefault:S,folding:_,edgeIdColumn:g,sourcePortColumn:t.edges.byRole("sourcePort"),targetPortColumn:t.edges.byRole("targetPort"),hierarchy:T,meta:l,needsOriginalIdKey:y}}function eO(t,e,n){for(const i of t){const{column:r,attrName:s,keyId:o}=i;s===null||!e.has(s)||n(w.COLUMN_NAME_CHANGED,`${i.domain} column "${r.meta.name}" is titled like the importer's ${s} column and reads back as "${s}#${o}"`,r.meta.name,r.length-r.nullCount)}}class LX{constructor(){this.used=new Set,this.counter=0}next(e){if(e!==null&&El(e)&&!this.used.has(e))return this.used.add(e),e;for(;;){const n=`d${this.counter}`;if(this.counter++,!this.used.has(n))return this.used.add(n),n}}}function PX(t,e){const n=[],i=new Map;for(const s of t){const{origin:o}=s.column.meta;if(o!==null&&o.format===ot&&o.id!==null){const l=i.get(o.id)??[];l.push(s),i.set(o.id,l)}}const r=new Set;for(const s of t){if(r.has(s))continue;const{origin:o}=s.column.meta,l=o!==null&&o.format===ot&&o.id!==null?i.get(o.id)??[s]:[s],c=l.length>1&&l.every(p=>p===s||GX(s,p))?l:[s],d=e.next(o!==null&&o.format===ot?o.id:null);for(const p of c)p.keyId=d,r.add(p);const u=c.map(p=>p.domain),f=s.column.meta.origin?.title??s.column.meta.name;let{attrName:h}=s;s.yfiles&&(h=f===d?null:f),n.push({id:d,domains:u.length>1?["graph","node","edge"]:u,attrName:h,attrType:s.attrType,yfilesType:s.yfilesType,column:s.column})}return n}function xX(t,e,n,i,r){const s=Ot(t),o=t.meta.weightOrigin,l=s.weighted&&o!==null&&o.format===ot,a=l&&o.title!==null?o.title:IX;for(const u of e)u.attrName===a&&r(w.WEIGHT_KEY_CLASH,`edge column "${u.column.meta.name}" is written as a key titled "${a}", which the importer reads as the edge weight (weightFrom); it reads back as the weight, not as a column`,u.column.meta.name,u.column.length-u.column.nullCount);if(!s.weighted)return null;let c="double";if(l&&o.type!==null){const u=o.type.trim().toLowerCase();(u==="float"||u==="double"||u==="long"||u==="int")&&(c=u)}(c==="int"||c==="long")&&!HX(t,s)&&(c="double");const d=n.next(l?o.id:null);return i.push({id:d,domains:["edge"],attrName:a,attrType:c,yfilesType:null,column:null}),{keyId:d,attrType:c,weights:s}}function MX(t,e,n,i){e.dtype!=="string"&&e.dtype!=="dict"&&i(pr.EDGE_ID_TEXT,`edge id column "${e.meta.name}" is ${e.dtype}; GraphML edge ids read back as strings`,e.meta.name,t.edgeCount-e.nullCount);const r=XX(e);r!==0&&(n.sanitizeIds==="mangle"?i(w.ID_MANGLED,`${r} edge id${O(r)} outside the nmtoken charset ${C(r,"is","are")} rewritten`,e.meta.name,r):i(w.ID_CHARSET,`${r} edge id${O(r)} outside the nmtoken charset; the save fails unless sanitizeIds is "mangle"`,e.meta.name,r))}function UX(t,e,n,i){if(n.edgedefault!==null)return n.edgedefault;if(!t.directed)return"undirected";let r=0,s=0;for(let l=0;l<t.edgeCount;l++)e.folded(l)||(ED(e,l)?r++:s++);if(s===0)return"directed";const o=i===null?null:i.edgedefault;return o!==null?o:s>r?"undirected":"directed"}function GX(t,e){return t.attrName===e.attrName&&t.attrType===e.attrType&&t.yfilesType===e.yfilesType&&t.domain!==e.domain&&JSON.stringify(t.column.meta.default??null)===JSON.stringify(e.column.meta.default??null)}function fp(t,e,n,i){const r=[],s=[...t],o=new Set(s.map(l=>l.meta.name));for(const l of s){const{meta:a}=l,{role:c,name:d}=a;if(pD(a)){const g=e==="graph"?0:pX(l,s,e);g>0&&i(pr.YFILES_GRAPHICS_STALE,`${g} value${O(g)} of ${e} column "${d}" differ from the yFiles tree it was read from; only the tree is written, so they are lost`,d,g);continue}if(c==="parents"){i(pr.PARENTS_DROPPED,`${e} column "${d}" (parents) cannot be written: nested graphs hold one parent per node`,d,l.length-l.nullCount);continue}if(c!==null&&(OX.has(c)||NX.has(c)||AX[e].has(c)))continue;c!==null&&c!=="label"&&yD.has(c)&&(bD(n,d),i(w.ROLE,`${e} column "${d}" (${c}) is written as a plain attribute; GraphML has no ${c} slot for a ${e} and the role is lost`,d,l.length-l.nullCount));const u=a.dtype==="json"&&a.origin?.namespace==="yfiles";if(a.dtype==="json"&&!u&&i(w.JSON,`${e} column "${d}" holds nested values; written as JSON text, which reads back as string`,d,l.length-l.nullCount),u){const g=VX(l);g>0&&i(pr.YFILES_TREE,`${g} value${O(g)} of yfiles column "${d}" ${C(g,"is","are")} not XML trees; the save fails with E_COLUMN_TYPE`,d,g)}const{origin:f}=a,h=f!==null&&f.format===ot;let p=null;u||(p=h&&f.title!==null?f.title:d,c==="label"&&e!=="graph"&&p!==hr?p=jX(l,e,o,n,i):c===null&&e!=="graph"&&p===hr&&i(w.ROLE_ASSUMED,`${e} column "${d}" has no role but is titled "${hr}", which the importer reads back with the label role`,d,l.length-l.nullCount)),r.push({column:l,domain:e,keyId:"",attrType:u?null:FX(l),attrName:p,yfilesType:u?f?.type??vX[e]:null,yfiles:u})}return r}function jX(t,e,n,i,r){const{name:s}=t.meta;return n.has(hr)?(bD(i,s),r(w.ROLE,`${e} column "${s}" (label) is written as a plain attribute: the label slot (a key titled "${hr}") is taken by column "${hr}" and the role is lost`,s,t.length-t.nullCount),s):hr}function bD(t,e){const n=t.findIndex(i=>i.code===w.COLUMN_NAME_CHANGED&&i.column===e);n>=0&&t.splice(n,1)}function FX(t){const{meta:e}=t,{origin:n}=e,i=n!==null&&n.format===ot&&n.type!==null?n.type:null;if(e.components>1)return"string";switch(e.dtype){case"bool":return"boolean";case"i32":return"int";case"f32":return"float";case"f64":return i!==null&&i.trim().toLowerCase()==="long"&&WX(t)?"long":"double";case"u8":return"int";case"u32":return BX(t)<=CX?"int":"long";case"string":return i!==null&&i.trim().toLowerCase()==="long"&&zX(t)?"long":i!==null&&$X[i.trim().toLowerCase()]===void 0?i:"string";case"dict":case"list":case"json":return"string";default:{const{dtype:r}=e;throw new N("E_UNSUPPORTED",`unknown dtype ${String(r)}`,{dtype:r})}}}function zX(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!/^[+-]?\d+$/.test(String(t.value(e))))return!1;return!0}function WX(t){if(t.dtype!=="f64")return!1;const{data:e}=t;for(let n=0;n<t.length;n++)if(t.isSet(n)&&!Number.isInteger(e[n]))return!1;return!0}function BX(t){if(t.dtype!=="u32")return 0;let e=0;const{data:n}=t;for(let i=0;i<t.length;i++)t.isSet(i)&&n[i]>e&&(e=n[i]);return e}function HX(t,e){for(let n=0;n<t.edgeCount;n++)if(e.isExplicit(n)&&!Number.isInteger(e.value(n)))return!1;return!0}function VX(t){if(t.dtype!=="json")return 0;let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&ku(t.values[n])!==null&&e++;return e}function YX(t){const{ids:e}=t;if(e.kind==="identity"||e.kind==="dense")return 0;let n=0;for(let i=0;i<e.size;i++){const r=e.idOf(i);(typeof r=="string"?El(r)&&tu(r):!Number.isSafeInteger(r))&&n++}return n}function KX(t){const{ids:e}=t;if(e.kind==="identity"||e.kind==="dense")return 0;let n=0;for(let i=0;i<e.size;i++)El(String(e.idOf(i)))||n++;return n}function XX(t){let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&!El(xd(t,n))&&e++;return e}function xd(t,e){const n=t.value(e);return typeof n=="string"?n:typeof n=="number"?Number.isInteger(n)?Ge(n):Fe(n):String(n)}function ED(t,e){return t.mateOf(e)===A&&t.sourceDirected(e)}function qX(t){const e=t.nodes.byRole("parent"),n=nc(t,{column:e!==null&&e.dtype==="u32"?e:null}),i=n.depthFirst(),r=i.order.filter(s=>i.depth[s]===0);return{parent:n.column,roots:r,childStart:n.rowPtr,childList:n.children,reordered:i.reordered,unreachable:n.unreachable}}function JX(t,e,n){if(t.meta.components>1){const i=t.value(e);return JSON.stringify(Array.from(i))}switch(t.dtype){case"bool":return t.value(e)===!0?"true":"false";case"i32":case"u32":case"u8":return String(t.data[e]);case"f32":return ct(t.data[e]);case"f64":{const i=t.data[e];return(n==="long"||n==="int")&&Number.isInteger(i)?Ge(i):Fe(i)}case"string":return t.valueAt(e);case"dict":return t.dictionary[t.codes[e]];case"list":return JSON.stringify(Array.from(t.sliceOf(e)));case"json":return JSON.stringify(t.values[e])??"";default:{const i=t;throw new N("E_UNSUPPORTED",`unknown dtype ${String(i)}`,{})}}}function ZX(t,e){const n=t.meta.default;if(n===void 0)return null;switch(typeof n){case"boolean":return n?"true":"false";case"number":return t.dtype==="f32"?ct(n):(e==="long"||e==="int")&&Number.isInteger(n)?Ge(n):Fe(n);case"string":return n;default:return JSON.stringify(n)??""}}function Qb(t,e,n,i){const{column:r}=t;if(r.isSet(e)){if(t.yfiles&&r.dtype==="json"){QX(t.keyId,r.values[e],n,i);return}i.push(`
|
|
148
|
+
${n}<data key="${t.keyId}">${nt(JX(r,e,t.attrType))}</data>`)}}function QX(t,e,n,i){if(e===null||typeof e!="object"||Array.isArray(e)){const r=[];Da(e,n,r),i.push(`
|
|
149
|
+
${n}<data key="${t}">${r.join("")}</data>`);return}i.push(`
|
|
150
|
+
${n}<data key="${t}">`),Da(e,`${n} `,i),i.push(`
|
|
151
|
+
${n}</data>`)}function eq(t,e,n,i){if(t.yfilesType===null){i.push(`
|
|
152
|
+
${n}<default>${nt(ZX(e,t.attrType)??"")}</default>`);return}const r=e.meta.default;if(r!==null&&typeof r=="object"&&!Array.isArray(r))i.push(`
|
|
153
|
+
${n}<default>`),Da(r,`${n} `,i),i.push(`
|
|
154
|
+
${n}</default>`);else{const s=[];Da(r,n,s),i.push(`
|
|
155
|
+
${n}<default>${s.join("")}</default>`)}}function tq(t,e){const n=t.domains.length===3?"all":t.domains[0];let i=`${e}<key id="${W(t.id)}" for="${n}"`;if(t.attrName!==null&&(i+=` attr.name="${W(t.attrName)}"`),t.attrType!==null&&(i+=` attr.type="${W(t.attrType)}"`),t.yfilesType!==null){const c=t.yfilesType.includes("://");i+=` ${c?"y:attr.uri":"yfiles.type"}="${W(t.yfilesType)}"`}const{column:r}=t,s=r?.meta.extra.desc,o=r?.meta.default!==void 0;if(r===null||typeof s!="string"&&!o)return`${i}/>
|
|
156
|
+
`;const l=[`${i}>`],a=`${e} `;return typeof s=="string"&&l.push(`
|
|
157
|
+
${a}<desc>${nt(s)}</desc>`),o&&eq(t,r,a,l),l.push(`
|
|
158
|
+
${e}</key>
|
|
159
|
+
`),l.join("")}function nq(t,e,n){const i=new Array(n).fill(null);if(t===null)return i;const r=new Set,s=[];for(let o=0;o<n;o++){if(!t.isSet(o))continue;const l=xd(t,o);El(l)?(i[o]=l,r.add(l)):s.push(o)}if(s.length>0&&e==="error")throw new N("E_INVALID_ID",`${s.length} edge id${O(s.length)} ${C(s.length,"is","are")} not XML name tokens (first: ${JSON.stringify(xd(t,s[0]))} at edge ${s[0]}); pass sanitizeIds: "mangle" to rewrite them`,{reason:"charset",charset:"nmtoken",count:s.length,edge:s[0]});for(const o of s){const l=aT(xd(t,o));let a=l;for(let c=2;r.has(a);c++)a=`${l}_${c}`;r.add(a),i[o]=a}return i}function*tO(t,e){const n=wl(t,"nmtoken",e.options.sanitizeIds),i=nq(e.edgeIdColumn,e.options.sanitizeIds,t.edgeCount),r=e.pretty?" ":"",s=e.pretty?" ":"",o=e.pretty?" ":"",l=e.pretty?" ":"";yield`<?xml version="1.0" encoding="UTF-8"?>
|
|
160
|
+
`,yield iq(e);for(const g of e.keys)yield tq(g,r);e.originalIdKey!==null&&(yield`${r}<key id="${e.originalIdKey}" for="node" attr.name="${Ps}" attr.type="string"/>
|
|
161
|
+
`);const a=e.meta?.graphId??"G";yield`${r}<graph id="${W(a)}" edgedefault="${e.edgedefault}">`;const{description:c}=t.meta;c!==null&&(yield`
|
|
162
|
+
${s}<desc>${nt(c)}</desc>`);const d=[];for(const g of e.graphColumns)Qb(g,0,s,d);d.length>0&&(yield d.join(""));const{hierarchy:u}=e,f=u.childList.length>0,h={stackNode:[],stackCursor:[],written:f?new Uint8Array(t.nodeCount):null};for(const g of u.roots)yield*oq(g,e,n,s,l,h);const p=t.edgeList();for(let g=0;g<t.edgeCount;g++)if(!e.folding.folded(g)){const m=rq(t,e,g,String(n.idAt(p.src[g])),String(n.idAt(p.dst[g])));yield sq(e,g,i[g],m,[s,o])}yield`
|
|
163
|
+
${r}</graph>
|
|
164
|
+
</graphml>
|
|
165
|
+
`}function iq(t){const e={...t.meta?.namespaces},n=t.nodeColumns.some(s=>s.yfiles)||t.edgeColumns.some(s=>s.yfiles)||t.graphColumns.some(s=>s.yfiles);(t.yedGraphics===!0||n&&!Object.values(e).includes(Jw)&&e.y===void 0)&&(e.y=Jw),Object.values(e).includes(Nd)||(e.xsi=Nd);let i=`<graphml xmlns="${ws}"`;for(const[s,o]of Object.entries(e))i+=` xmlns:${s}="${W(o)}"`;const r=Object.entries(e).find(([,s])=>s===Nd)?.[0]??"xsi";return`${i} ${r}:schemaLocation="${_j}">
|
|
166
|
+
`}function rq(t,e,n,i,r){let s=` source="${W(i)}" target="${W(r)}"`;const o=t.directed&&ED(e.folding,n);o!==(e.edgedefault==="directed")&&(s+=` directed="${o?"true":"false"}"`);const l=nO(e.sourcePortColumn,n);l!==null&&(s+=` sourceport="${W(l)}"`);const a=nO(e.targetPortColumn,n);return a!==null&&(s+=` targetport="${W(a)}"`),s}function sq(t,e,n,i,r){const[s,o]=r,l=[`
|
|
167
|
+
${s}<edge`];n!==null&&l.push(` id="${W(n)}"`),l.push(i);const a=l.length;if(t.weight!==null){const{keyId:c,attrType:d}=t.weight,u=t.weight.weights.text(e,d==="int"||d==="long");u!==null&&l.push(`
|
|
168
|
+
${o}<data key="${c}">${nt(u)}</data>`)}for(const c of t.edgeColumns)Qb(c,e,o,l);return l.length===a?l.push("/>"):(l.splice(a,0,">"),l.push(`
|
|
169
|
+
${s}</edge>`)),l.join("")}function nO(t,e){if(!t?.isSet(e))return null;const n=t.value(e);return typeof n=="string"?n:String(n)}function*oq(t,e,n,i,r,s){const{stackNode:o,stackCursor:l,written:a}=s,{hierarchy:c}=e,d=h=>c.childStart[h+1]>c.childStart[h],u=(h,p)=>{const g=i+r.repeat(p*2),m=[`
|
|
170
|
+
${g}<node id="${W(String(n.idAt(h)))}"`],y=m.length;e.originalIdKey!==null&&n.isChanged(h)&&m.push(`
|
|
171
|
+
${g}${r}<data key="${e.originalIdKey}">${nt(String(n.originalAt(h)))}</data>`);for(const b of e.nodeColumns)Qb(b,h,g+r,m);if(d(h)){m.splice(y,0,">");const b=`${String(n.idAt(h))}:`;return m.push(`
|
|
172
|
+
${g}${r}<graph id="${W(b)}" edgedefault="${e.edgedefault}">`),m.join("")}return m.length===y?m.push("/>"):(m.splice(y,0,">"),m.push(`
|
|
173
|
+
${g}</node>`)),m.join("")},f=h=>{const p=i+r.repeat(h*2);return`
|
|
174
|
+
${p}${r}</graph>
|
|
175
|
+
${p}</node>`};if(a!==null&&(a[t]=1),yield u(t,0),!!d(t))for(o.push(t),l.push(c.childStart[t]);o.length>0;){const h=o.length-1,p=o[h],g=l[h];if(g>=c.childStart[p+1]){o.pop(),l.pop(),yield f(h);continue}l[h]=g+1;const m=c.childList[g];a!==null&&a[m]===1||(a!==null&&(a[m]=1),yield u(m,h+1),d(m)&&(o.push(m),l.push(c.childStart[m])))}}const lq=Object.freeze({format:ot,options:Object.freeze(["edgedefault","pretty"]),capabilities:mD,styles:Object.freeze({capabilities:Aa}),check(t,e){const{plan:n,styled:i}=hp(t,e);return Object.freeze([...n.notes,...i?.notes??[]])},export(t,e){const{plan:n,written:i}=hp(t,e);return ti(tO(i,n))},exportToString(t,e){const{plan:n,written:i}=hp(t,e);return ni(tO(i,n))}});function hp(t,e){const n=d7(t,e?.styles),i=n?.snapshot??t,r=RX(i,ft(e),DX(e),n!==null);if(n===null)return{plan:r,written:i,styled:n};const s=i.nodes.byRole("position")?.meta.name,o=r.notes.filter(l=>l.code!==w.POSITIONS||l.column!==s);return{plan:{...r,notes:o,yedGraphics:!0},written:i,styled:n}}const wD=16,gn=Symbol("x:Null"),aq=/^\{\s*[\w.-]*:?GraphMLReference\s+([^\s}]+)\s*\}$/,cq=/^\{\s*[\w.-]*:?Null\s*\}$/,dq=new Set(["NodeStyle","EdgeStyle","NodeLabels","EdgeLabels","NodeGeometry","EdgeGeometry"]);function uq(t){if(typeof t!="string"||!t.includes("://"))return null;const e=t.slice(t.lastIndexOf("/")+1);return dq.has(e)||e==="SharedData"?e:null}function pp(t){const e=new Map;for(const n of t){const i=n.dtype==="json"&&n.meta.origin?.namespace==="yfiles"?uq(n.meta.origin.type):null;i!==null&&!e.has(i)&&e.set(i,n.meta.name)}return e}class fq{constructor(e){this.shared=new Map,this.cycles=0;for(const n of wt(e,"SharedData"))Ir(n)&&this.collect(n)}collect(e){for(const n of Object.keys(e).filter(i=>!i.startsWith("@_")&&i!=="#text"))for(const i of wt(e,Gi(n))){const r=hq(i);r!==null&&!this.shared.has(r)&&this.shared.set(r,{tag:Gi(n),e:i})}}tooDeep(e){return e>wD?(this.cycles++,!0):!1}object(e,n){return e==="GraphMLReference"?this.shared.get(k(n,"ResourceKey")??"")??null:{tag:e,e:n}}first(e){if(!Ir(e))return null;for(const n of Object.keys(e))if(!n.startsWith("@_")&&n!=="#text")return this.object(Gi(n),wt(e,Gi(n))[0]);return null}deref(e,n=0){if(e==null||this.tooDeep(n))return null;if(typeof e=="object")return this.first(e);if(typeof e!="string")return null;const i=e.trim();if(i.length>Ce)return i;if(cq.test(i))return gn;const r=aq.exec(i);return r!==null?this.shared.get(r[1])??null:i}}function hq(t){if(!Ir(t))return null;for(const e of Object.keys(t))if(e.startsWith("@_")&&Gi(e.slice(2))==="Key"){const n=t[e];return typeof n=="string"?n:null}return null}function Qe(t,e){const n=k(t.e,e);return n!==void 0?n:ue(t.e,`${t.tag}.${e}`)}function Fi(t,e,n,i=0){if(t.tooDeep(i))return null;const r=t.deref(e,i);if(r===null||r===gn)return r;if(typeof r=="string")return{raw:r,dialect:"yfiles3"};const{tag:s}=r;if(s==="SolidColorFill")return Fi(t,Qe(r,"color"),n,i+1);if(s==="Color")return Fi(t,k(r.e,"value"),n,i+1);if(s==="CssFill"){const o=k(r.e,"cssString");return o===void 0?null:{raw:o,dialect:"css"}}if(s.endsWith("Gradient")){n?.();const o=wt(r.e,"GradientStop")[0]??wt(ue(r.e,`${s}.GradientStops`),"GradientStop")[0];return o===void 0?null:Fi(t,k(o,"color"),null,i+1)}return s==="Stroke"?Fi(t,Qe(r,"fill"),n,i+1):null}const pq=new Map([["solid","solid"],["dash","dashed"],["dot","dotted"],["dashdot","dash-dot"],["dashdotdot","dash-dot"]]);function La(t,e){const n=t.deref(e);if(n===null||n===gn)return n;if(typeof n=="string"||n.tag!=="Stroke")return{color:Fi(t,e,null),width:1,line:"solid"};let i="solid";const r=t.deref(Qe(n,"dashStyle"),1);if(typeof r=="string"){const o=r.slice(0,Ce).toLowerCase().replaceAll("_","");i=pq.get(o)??`other:${o}`}else if(r!==null&&r!==gn){const o=(k(r.e,"dashes")??"").slice(0,Ce).trim().split(/[\s,]+/).map(Number).filter(Number.isFinite);o.length===2?i=o[0]<=1?"dotted":"dashed":o.length===4?i="dash-dot":o.length>0&&(i=`other:dashes ${o.slice(0,8).join(" ")}`)}const s=Qe(n,"thickness");return{color:Fi(t,Qe(n,"fill"),null),width:typeof s=="string"?s:1,line:i}}function Rl(t,e,n,i,r){if(t===null||t===gn)return;const s=ve(t.raw,t.dialect,r(e));if(s===null)return;i(e,s.color);const o=Ol(s,null,r(e),n!==null);n!==null&&i(n,o)}const Xc="#FF000000",gq="#FFB7C9E3",_D=new Map([["sheared-rectangle",{shape:"parallelogram"}],["sheared-rectangle2",{shape:"polygon",points:"-0.5,-1 1,-1 0.5,1 -1,1"}],["trapez",{shape:"polygon",points:"-0.5,-1 0.5,-1 1,1 -1,1"}],["trapez2",{shape:"trapezoid"}],["star5-up",{shape:"star"}],["triangle2",{shape:"polygon",points:"-1,1 0,-1 1,1"}],["fat-arrow",{shape:"polygon",points:"-1,-1 0.6,-1 1,0 0.6,1 -1,1 -0.6,0"}],["fat-arrow2",{shape:"polygon",points:"-0.6,-1 1,-1 0.6,0 1,1 -0.6,1 -1,0"}],["pill",{shape:"round-rectangle"}]]),mq=10;function iO(t,e,n,i){const r=t===void 0?e:Y(t,i("cornerRadius"));if(r===0){n("shape","rectangle");return}n("shape","round-rectangle"),n("cornerRadius",r)}function yq(t,e,n,i){const r=s=>{Rl(Fi(t,s,()=>{H(i("fill"),v.GRADIENT,e.tag)}),"fill","fillOpacity",n,i)};switch(e.tag){case"BevelNodeStyle":return r(Qe(e,"color")??Xc),n("borderWidth",0),iO(k(e.e,"radius"),10,n,i),!0;case"PanelNodeStyle":return r(Qe(e,"color")??Xc),n("borderWidth",0),n("shape","rectangle"),!0;case"ShinyPlateNodeStyle":{r(Qe(e,"fill")??Xc);const s=Qe(e,"stroke");return s===void 0?n("borderWidth",0):hm(La(t,s),n,i),iO(k(e.e,"radius"),5,n,i),!0}case"FlowchartNodeStyle":{r(Qe(e,"fill")??gq);const s=k(e.e,"type")??"";s==="annotation"?n("borderWidth",0):hm(La(t,Qe(e,"stroke")??Xc),n,i);const o=s===""||s==="annotation"?null:Df(`flowchart.${s}`);return o===null&&s!==""&&s!=="annotation"&&H(i("shape"),v.UNKNOWN_VALUE,s.slice(0,Ce)),n("shape",o?.shape??"rectangle"),o?.points!==void 0&&n("shapePoints",o.points),!0}default:return!1}}function hm(t,e,n){t===gn?e("borderWidth",0):t!==null&&(Rl(t.color,"borderColor","borderOpacity",e,n),e("borderWidth",Y(t.width,n("borderWidth"))),e("borderStyle",le("borderStyle",t.line,"yfiles3",n("borderStyle"))))}function bq(t,e,n,i,r){const s=Eq(t,t.first(e));if(s===null||typeof s!="object"){e!=null&&e!==""&&H(i("fill"),v.UNRESOLVED,"NodeStyle");return}const o=s;if(yq(t,o,n,i))return;Rl(Fi(t,Qe(o,"fill"),()=>{H(i("fill"),v.GRADIENT,o.tag)}),"fill","fillOpacity",n,i),hm(La(t,Qe(o,"stroke")),n,i),n("shape",wq(o,i));const l=_D.get(pm(k(o.e,"shape"))??"")?.points;l!==void 0&&n("shapePoints",l);const a=o.tag==="RectangleNodeStyle"?k(o.e,"cornerSize"):void 0;a!==void 0&&n("cornerRadius",Y(a,i("cornerRadius")));const c=o.tag==="ShapeNodeStyle"?pm(k(o.e,"shape")):null;c==="round-rectangle"?n("cornerRadius",mq):c==="pill"&&r!==null&&n("cornerRadius",Math.min(r.width,r.height)/2)}function pm(t){return t===void 0?null:t.slice(0,Ce).trim().toLowerCase().replaceAll("_","-")}function Eq(t,e){let n=e;const i=new Set;for(;n!==null&&typeof n=="object"&&n.tag==="CollapsibleNodeStyleDecorator";){if(i.has(n.e)||t.tooDeep(i.size))return t.cycles++,null;i.add(n.e),n=t.deref(Qe(n,"wrappedStyle"))}return n}function wq(t,e){const n=k(t.e,"shape");return n!==void 0?_D.get(pm(n)??"")?.shape??le("shape",n,"yfiles3",e("shape")):t.tag==="RectangleNodeStyle"?k(t.e,"cornerSize")===void 0?"rectangle":"round-rectangle":t.tag==="ShapeNodeStyle"?"rectangle":(H(e("shape"),v.UNKNOWN_VALUE,t.tag),`other:${t.tag}`)}function _q(t,e,n,i){const r=t.first(e);if(r===null)return;const s=La(t,Qe(r,"stroke"));s===gn?H(i("color"),v.NO_STROKE,"{x:Null}"):s!==null&&(Rl(s.color,"color","opacity",n,i),n("width",Y(s.width,i("width"))),n("lineStyle",le("lineStyle",s.line,"yfiles3",i("lineStyle"))));for(const o of["source","target"])Sq(t,t.deref(Qe(r,`${o}Arrow`)),o,n,i)}function Sq(t,e,n,i,r){const s=`${n}Arrow`;let o=null,l=!1;if(e!==null&&e!==gn&&typeof e=="object"){o=k(e.e,"type")??"DEFAULT";const a=Fi(t,Qe(e,"fill"),null),c=a===gn?La(t,Qe(e,"stroke")):null;l=c!==null&&c!==gn,Rl(c!==null&&c!==gn?c.color:a,`${n}ArrowColor`,null,i,r)}else typeof e=="string"&&(o=e);if(o!==null){const a=le("arrow",Oq.get(o.toUpperCase())??o,"yfiles3",r(s));i(s,l?Nq.get(a??"")??a:a)}}const Oq=new Map([["DEFAULT","vee"],["STEALTH","vee"],["ELLIPSE","circle"]]),Nq=new Map([["triangle","triangle-open"],["vee","triangle-open"],["diamond","diamond-open"],["circle","circle-open"]]);function Aq(t,e,n,i,r){const s=wt(ue(e,"List"),"Bend").map(f=>{const[h,p]=(k(f,"Location")??"").split(",").map(Number);return[h,p]}),[o,l,a]=i,c=a?Hs([o[0],o[1]],[o[2],o[3]],s,!0):Al([o[0],o[1]],[l[0],l[1]],s,!0);r("bends",c);const d=t.first(n),u=d===null?void 0:k(d.e,"smoothingLength");c!==null&&d?.tag==="PolylineEdgeStyle"&&Number(u)>0&&r("curved",!0)}const Tq=new Map([["north","top"],["south","bottom"],["east","right"],["west","left"],["northeast","top-right"],["northwest","top-left"],["southeast","bottom-right"],["southwest","bottom-left"],["top","top"],["bottom","bottom"],["right","right"],["left","left"],["topright","top-right"],["topleft","top-left"],["bottomright","bottom-right"],["bottomleft","bottom-left"]]),Iq=new Map([["ExteriorLabelModelParameter","outside"],["ExteriorNodeLabelModelParameter","outside"],["SandwichParameter","outside"],["SandwichLabelModelParameter","outside"],["InteriorLabelModelParameter","inside"],["InteriorNodeLabelModelParameter","inside"],["InteriorStretchLabelModelParameter","inside"],["StretchNodeLabelModelParameter","inside"]]),$q=/^\{\s*[\w.-]*:?Static\s+(?:[\w.-]+:)?(\w+)\.(\w+)\s*\}$/;function SD(t,e){const n=k(e,"LayoutParameter");if(n!==void 0){const r=$q.exec(n.slice(0,Ce).trim());if(r!==null)return{tag:`${r[1]}Parameter`,e:{"@_Position":r[2]}}}const i=t.deref(n??ue(e,"Label.LayoutParameter"));return i===null||i===gn||typeof i!="object"?null:i}function Cq(t,e){const n=SD(t,e),i=n===null?void 0:Iq.get(n.tag);if(n===null||i===void 0)return"center";const r=k(n.e,"Position")??"",s=Tq.get(r.slice(0,Ce).toLowerCase().replaceAll("_",""));return s===void 0?"center":i==="inside"?`inside-${s}`:s}const vq=new Map([["aboveedge","top"],["belowedge","bottom"],["onedge","center"],["centerabove","top"],["centerbelow","bottom"],["centercentered","center"]]),Dq=new Map([["NinePositionsEdgeLabelModelParameter","Position"],["EdgePathLabelModelParameter","SideOfEdge"]]);function kq(t,e){const n=SD(t,e);if(n===null)return null;const i=k(n.e,"Ratio");if(i!==void 0&&Number(i)!==.5)return null;const r=Dq.get(n.tag),s=r===void 0?void 0:k(n.e,r);return s===void 0?null:vq.get(s.slice(0,Ce).toLowerCase())??null}function Rq(t,e,n,i){let r,s="",o=0;for(const a of wt(ue(e,"List"),"Label")){const c=k(a,"Text")??Ob(ue(a,"Label.Text"))??"";c.trim().length!==0&&(r===void 0?(r=a,s=c):o++)}if(r===void 0)return;o>0&&H(i("label"),v.EXTRA_LABELS,`${String(o+1)} labels`),n("label",rt(s,i("label"))),n("labelPosition",i("label").target==="node"?Cq(t,r):kq(t,r));const l=t.deref(k(r,"Style")??ue(r,"Label.Style"));l===null||l===gn||typeof l!="object"||!l.tag.endsWith("LabelStyle")||(Rl(Fi(t,Qe(l,"textFill"),null),"labelColor",null,n,i),Lq(t.deref(Qe(l,"font")),n,i))}function Lq(t,e,n){if(t===null||t===gn||typeof t!="object"||t.tag!=="Font")return;e("labelSize",Y(k(t.e,"fontSize"),n("labelSize")));const i=k(t.e,"fontFamily");i!==void 0&&e("labelFont",rt(i.replaceAll(/(^['"])|(['"]$)/g,""),n("labelFont")));const r=k(t.e,"fontWeight");r!==void 0&&e("labelWeight",le("weight",r,"yfiles3",n("labelWeight")))}const Pq={node:["NodeStyle","NodeLabels","NodeGeometry"],edge:["EdgeStyle","EdgeLabels","EdgeGeometry"]};function xq(t,e,n){const{snapshot:i,notes:r,budget:s,refs:o,boxes:l}=t,a=e==="node",c=a?i.nodes:i.edges,d=a?i.nodeCount:i.edgeCount,u=Qr(d),[f,h,p]=Pq[e].map(m=>n.get(m)),g=(m,y)=>m===void 0?void 0:K(c.value(m,y));for(let m=0;m<d;m++){s.spend(e,1);const y=S=>({notes:r,target:e,property:S,element:m,budget:s}),b=(S,T)=>{u.put(m,S,T)};let _=null;if(p!==void 0&&!a){const S=D=>l.subarray(4*D,4*D+4),[T,$]=[i.edgeSource(m),i.edgeTarget(m)];Aq(o,g(p,m),g(f,m),[S(T),S($),T===$],b)}else p!==void 0&&(_=Mq(g(p,m),m,l,b,y));f!==void 0&&a?bq(o,g(f,m),b,y,_):f!==void 0&&_q(o,g(f,m),b,y),h!==void 0&&Rq(o,g(h,m),b,y)}return u.values}function Mq(t,e,n,i,r){const s=ue(t,"RectD"),o=Y(k(s,"Width"),r("width")),l=Y(k(s,"Height"),r("height"));if(i("width",o),i("height",l),o===null||l===null)return null;const[a,c]=[Number(k(s,"X")),Number(k(s,"Y"))];return n.set([a+o/2,c+l/2,o,l],4*e),{width:o,height:l}}function Uq(t,e,n){const i=pp(t.nodes),r=pp(t.edges);if(![...i.keys(),...r.keys()].some(h=>h!=="SharedData"))return null;const l=pp(t.graph).get("SharedData"),a=new fq(l===void 0?null:K(t.graph.value(l,0))),c=new Float64Array(4*t.nodeCount).fill(Number.NaN),d=(h,p)=>xq({snapshot:t,notes:e,budget:n,refs:a,boxes:c},h,p),u=d("node",i),f=d("edge",r);return a.cycles>0&&e.add(v.REFERENCE_CYCLE,null,null,{sample:`references deeper than ${String(wD)} or circular (${String(a.cycles)})`}),{node:u,edge:f}}const Gq=["r","g","b","size"];function OD(t){return t.has("r")&&t.has("g")&&t.has("b")}function jq(t,e,n){const i=r=>{const s=r==="node"?t.nodes:t.edges,o=r==="node"?t.nodeCount:t.edgeCount,l=Qr(o),a={rgb:OD(s),size:r==="node"&&s.has("size"),label:s.has("label")};for(let c=0;c<o;c++)n.budget.spend(r,1),Fq(s,r,c,a,(u,f)=>{l.put(c,u,f)},u=>({notes:e,target:r,property:u,element:c,budget:n.budget}));return l.values};return{node:i("node"),edge:i("edge")}}function Fq(t,e,n,i,r,s){if(i.rgb){const[o,l,a]=["r","g","b"].map(c=>K(t.value(c,n)));if(o!==null&&l!==null&&a!==null){const c=e==="node"?"fill":"color";r(c,ve({r:o,g:l,b:a},"gephi",s(c))?.color??null)}}if(i.size){const o=Y(K(t.value("size",n)),s("width"));r("width",o),r("height",o)}i.label&&r("label",rt(K(t.value("label",n)),s("label")))}function zq(t,e){const n=t.graph.has(Z)?K(t.graph.value(Z,0)):null;typeof n=="string"&&n7(t,n,e)}function Wq(t,e){const n=new se,i={node:Pg(t.nodes),edge:Pg(t.edges)},r=Uq(t,n,e.budget);if(r!==null)return{canonical:!0,dialect:"yfiles3",tool:"yfiles3",units:"px",node:{values:r.node},edge:{values:r.edge},notes:n.list(),readFrom:i};const s=Jz(t,n,e.budget);if(s!==null)return zq(t,s),{canonical:!0,dialect:"yed",tool:"yed",units:"px",node:{values:s.node},edge:{values:s.edge},notes:n.list(),opacityInColor:!0,readFrom:i};if(OD(t.nodes)){const o=jq(t,n,e);delete o.edge.color;const l=Wb(t,{fill:o.node.fill,width:o.node.width},{},e.budget),a=c=>Gq.filter(d=>c.has(d));return{canonical:!0,dialect:"gephi",tool:"gephi",units:"relative",node:{values:o.node,...l.node},edge:{values:o.edge,...l.edge},notes:n.list(),readFrom:{node:a(t.nodes),edge:a(t.edges)}}}if(t.nodes.has("SUID")&&t.nodes.has("shared name")){const o=Qr(t.nodeCount);if(t.nodes.has("name"))for(let l=0;l<t.nodeCount;l++)o.put(l,"label",rt(K(t.nodes.value("name",l)),{notes:n,target:"node",property:"label",element:l,budget:e.budget}));return{canonical:!0,dialect:"cytoscape",tool:"cytoscape",units:"px",node:{values:o.values},edge:{values:{}},notes:n.list()}}return null}function Bq(t,e){return e==="xmlns"||/^(xmlns|xml|xsi):/.test(e)||ND(t,e)}function Hq(t,e,n){return n?`the <${t}> parse hint ${e} is ignored`:eJ.has(e)?`the <${t}> attribute ${e} is not kept`:`the <${t}> attribute ${e} is not a GraphML attribute; it is not kept`}const Vq=new Set(["id","edgedefault","parse.nodes","parse.edges"]),Yq=new Set(["id"]),Kq=new Set(["id","for","attr.name","attr.type","name","type","yfiles.type"]),Xq=new Set(["key"]),qq=new Set(["id"]),Jq=new Set(["node","type"]),Zq=new Set(["name"]),rO=new Set;function ND(t,e){return t==="key"&&e.endsWith(":attr.uri")}function Qq(t){for(const[e,n]of t)if(ND("key",e)&&n.length>0)return n;return null}const eJ=new Set(["id","port","parse.order","parse.nodeids","parse.edgeids"]),sO=16,tJ=new Set(["id","source","target","directed","sourceport","targetport"]),nJ={ids:"canonical",defaultDirected:!1,weightFrom:"weight"},iJ=4096,rJ=new Set(["json","skip"]),sJ=64,oJ=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","hyperedges","errorLimit","signal","onProgress"]);class oO{constructor(){this.words=new Uint32Array(64)}has(e){const n=e>>>5;return n<this.words.length&&(this.words[n]>>>(e&31)&1)===1}add(e){const n=e>>>5;if(n>=this.words.length){let i=this.words.length*2;for(;i<=n;)i*=2;const r=new Uint32Array(i);r.set(this.words),this.words=r}this.words[n]|=1<<(e&31)}}class lJ{constructor(e,n,i,r){this.ctx=[],this.keys=new Map,this.graphs=[],this.nodes=[],this.declared=new oO,this.edgeIds=new Set,this.unknownKeyIds=new Set,this.deferredEdgeIds=new Set,this.elementsSinceCheck=0,this.restored=new Map,this.graphColumnNames=new Set,this.pendingKey=null,this.edge=null,this.hyperedge=null,this.content={key:null,pendingKey:null,domain:"node",text:"",tree:null,line:0},this.descTarget=null,this.descText="",this.descLine=0,this.graphKeys={keys:null},this.description=null,this.graphSeen=!1,this.graphId=null,this.edgedefault=null,this.namespaces={},this.weightOrigin=null,this.yfilesLossNoted=!1,this.graphicsColumns=new Map,this.hyperedgeCount=0,this.edgeIdHandle=A,this.sourcePortHandle=A,this.targetPortHandle=A,this.parentHandle=A,this.hubHandle=A,this.hubs=new oO,this.deferred=[],this.graphIds=new Set,this.topGraphs=0,this.rootNs=ws,this.graphDescSeen=!1,this.unknownNames=new Map,this.unknownOverflow=new Map,this.ports=new Map,this.portRefs=[],this.sink=e,this.report=n,this.options=i,this.yfilesMode=r,this.coercer=new Mn(i.ids),this.direction=new ei(e,n,i.onMixedDirection)}start(e,n,i,r=""){const s=this.ctx.at(-1)??null;switch(s){case 9:case 8:case 3:this.captureStart(e,n);return;case 10:case 1:this.ctx.push(10);return;case 12:this.dropStart(Rs(e));return}const o=Rs(e);if(s!==null&&r!==ws&&r!==""&&r!==this.rootNs){this.unknownElement(e,i);return}switch(s){case null:o!=="graphml"&&this.report.fail(U.NOT_GRAPHML,`the root element is <${e}>, not <graphml>`,{line:i}),r!==ws&&r!==""&&this.report.warning("validation-error",U.NAMESPACE,r===null?`the root <${e}> uses an undeclared prefix; read as GraphML`:`the root <${e}> is in the namespace ${JSON.stringify(r)}, not ${ws}; read as GraphML`,{line:i,element:r}),this.rootNs=r,this.reportUnreadAttributes("graphml",n,rO,i),this.readRoot(n),this.ctx.push(0);return;case 0:this.startInGraphml(e,o,n,i);return;case 2:this.startInKey(e,o,n,i);return;case 4:this.startInGraph(e,o,n,i);return;case 5:this.startInNode(e,o,n,i);return;case 6:this.startInEdge(e,o,n,i);return;case 7:this.startInHyperedge(e,o,n,i);return;case 11:this.startInPort(e,o,n,i);return;default:this.unknownElement(e,i)}}end(e,n){const i=this.ctx.pop();switch(i){case 9:this.captureEnd();return;case 10:case 0:case 11:case 12:case void 0:return;case 1:this.finishDesc();return;case 2:this.finishKey();return;case 3:this.finishDefault();return;case 8:this.finishData();return;case 5:this.finishNode();return;case 6:this.finishEdge();return;case 7:this.finishHyperedge();return;case 4:this.finishGraph();return;default:{const r=i;throw new N("E_UNSUPPORTED",`unknown reader state ${String(r)}`,{name:e})}}}text(e,n){switch(this.ctx.at(-1)??null){case 9:this.content.tree?.text(e);return;case 8:case 3:this.content.tree===null?this.content.text+=e:this.content.tree.text(e);return;case 1:this.descText+=e;return;case 10:case 12:return;default:Tr(e)||this.report.warnOnce("validation-error",U.STRAY_TEXT,"text where GraphML allows only elements was ignored",{line:n})}}finish(){this.graphSeen||this.report.fail(U.NO_GRAPH,"the document has no <graph> element");for(const n of this.deferred)"endpoints"in n?this.expandHyperedge(n):this.addEdge(n);this.deferred.length=0,this.checkPorts();for(const[n,i]of this.unknownOverflow)this.report.warning("unsupported",U.UNKNOWN_XML_ATTRIBUTE,`${i} more distinct attribute names on <${n}> are not GraphML attributes and are not kept (not listed one by one)`,{element:n});const e={graphId:this.graphId,edgedefault:this.edgedefault,namespaces:this.namespaces};this.sink.setMeta({sourceFormat:ot,description:this.description??void 0,weightOrigin:this.weightOrigin===null?void 0:{format:ot,id:this.weightOrigin.id,title:this.weightOrigin.title,type:this.weightOrigin.type,namespace:null},extra:{[o$]:e}})}readRoot(e){for(const[n,i]of e)n.startsWith("xmlns:")&&i!==ws&&i!==Nd&&(this.namespaces[n.slice(6)]=i)}startInGraphml(e,n,i,r){switch(n){case"desc":this.beginDesc("graph",r);return;case"key":this.beginKey(i,r);return;case"graph":this.beginGraph(i,r,A);return;case"data":this.beginData(i,r,"graph");return;default:this.unknownElement(e,r)}}startInKey(e,n,i,r){switch(n){case"desc":this.beginDesc("key",r);return;case"default":this.reportUnreadAttributes("default",i,rO,r),this.pendingKey!==null&&(this.pendingKey.defaultText!==null||this.pendingKey.defaultTree!==void 0)&&this.report.warning("validation-error",U.DUPLICATE_ATTRIBUTE,`key "${this.pendingKey.id??""}" has a second <default>; the later one is kept`,{line:r,element:this.pendingKey.id}),this.content.key=null,this.content.pendingKey=this.pendingKey,this.content.text="",this.content.tree=null,this.content.line=r,this.ctx.push(3);return;default:this.unknownElement(e,r)}}startInGraph(e,n,i,r){const s=this.graphs.length===1&&this.topGraphs===1;switch(n){case"desc":s?this.beginDesc("graph",r):(this.report.warnOnce("unsupported",U.DESC_DROPPED,`the <desc> of a ${this.graphs.length===1?"second top-level":"nested"} <graph> is not kept`,{line:r},`${U.DESC_DROPPED}:graph`),this.ctx.push(10));return;case"data":s?this.beginData(i,r,"graph"):(this.report.warnOnce("unsupported",U.NESTED_GRAPH_DATA,this.graphs.length===1?"data of a second top-level <graph> cannot be kept; the graphs are merged and only the first one's attributes are kept":"data of a nested <graph> cannot be kept; only the top-level graph has attributes",{line:r}),this.ctx.push(10));return;case"node":this.beginNode(i,r);return;case"edge":this.beginEdge(i,r);return;case"hyperedge":this.beginHyperedge(i,r);return;case"locator":this.report.warnOnce("unsupported",U.LOCATOR_DROPPED,"<locator> references are not followed",{line:r}),this.ctx.push(10);return;default:this.unknownElement(e,r)}}startInNode(e,n,i,r){switch(n){case"desc":this.report.warnOnce("unsupported",U.DESC_DROPPED,"node and edge <desc> texts are not kept",{line:r}),this.ctx.push(10);return;case"data":this.beginData(i,r,"node");return;case"port":this.report.warnOnce("unsupported",U.PORT_DECLARATION,"<port> declarations are not kept; sourceport / targetport edge attributes are",{line:r}),this.beginPort(i,r);return;case"graph":{const s=this.nodes[this.nodes.length-1];this.materializeNode(s),s.index===A&&this.report.error("missing-value",U.UNKNOWN_PARENT,"the nodes of this nested <graph> lose their parent: the node holding it was skipped; they are read as top-level nodes",{line:r}),this.beginGraph(i,r,s.index);return}case"locator":this.report.warnOnce("unsupported",U.LOCATOR_DROPPED,"<locator> references are not followed",{line:r}),this.ctx.push(10);return;default:this.unknownElement(e,r)}}startInEdge(e,n,i,r){switch(n){case"desc":this.report.warnOnce("unsupported",U.DESC_DROPPED,"node and edge <desc> texts are not kept",{line:r}),this.ctx.push(10);return;case"data":this.beginData(i,r,"edge");return;case"graph":this.report.warnOnce("unsupported",U.EDGE_GRAPH_DROPPED,"a <graph> inside an <edge> is not supported; it is dropped with the nodes and edges it holds (counted as skipped)",{line:r,element:i.get("id")??null}),this.ctx.push(12);return;default:this.unknownElement(e,r)}}dropStart(e){e==="node"?this.report.counts.skippedNodes++:(e==="edge"||e==="hyperedge")&&this.report.counts.skippedEdges++,this.ctx.push(e==="data"||e==="desc"?10:12)}beginPort(e,n){this.reportUnreadAttributes("port",e,Zq,n);const i=this.nodes[this.nodes.length-1],r=e.get("name");if(i.id!==null&&r!==void 0){const s=i.restoredId??i.id;let o=this.ports.get(s);o===void 0&&(o=new Set,this.ports.set(s,o)),o.add(r)}this.ctx.push(11)}startInPort(e,n,i,r){switch(n){case"port":this.beginPort(i,r);return;case"data":case"desc":this.ctx.push(10);return;default:this.unknownElement(e,r)}}checkPorts(){let e=0,n=null;for(const[i,r]of this.portRefs)this.ports.get(i)?.has(r)!==!0&&(e++,n??=`${String(i)}:${r}`);e>0&&this.report.warning("missing-value",U.DANGLING_REFERENCE,`${e} edge port reference${O(e)} ${C(e,"names","name")} a port their node does not declare (first: ${n??""}); the values are kept`,{element:n})}startInHyperedge(e,n,i,r){switch(n){case"endpoint":this.reportUnreadAttributes("endpoint",i,Jq,r),this.readEndpoint(i,r),this.ctx.push(10);return;case"data":this.report.warnOnce("unsupported",U.HYPEREDGE_DATA_DROPPED,"hyperedge data are not kept by the star / clique expansions",{line:r}),this.ctx.push(10);return;case"desc":this.report.warnOnce("unsupported",U.DESC_DROPPED,"the <desc> of a hyperedge is not kept by the star / clique expansions",{line:r},`${U.DESC_DROPPED}:hyperedge`),this.ctx.push(10);return;default:this.unknownElement(e,r)}}unknownElement(e,n){this.report.warnOnce("unsupported",U.UNKNOWN_ELEMENT,pJ(e),{line:n,element:e}),this.ctx.push(10)}beginDesc(e,n){this.descTarget=e,this.descText="",this.descLine=n,this.ctx.push(1)}finishDesc(){const e=this.descText.trim();this.descTarget==="key"&&this.pendingKey!==null?this.pendingKey.desc=e:this.descTarget==="graph"&&e.length>0&&(this.graphDescSeen&&this.report.warning("unsupported",U.DESC_DROPPED,"a second graph-level <desc> replaces the first; the earlier text is not kept",{line:this.descLine}),this.graphDescSeen=!0,this.description=e),this.descTarget=null,this.descText=""}reportUnreadAttributes(e,n,i,r){for(const s of n.keys())!i.has(s)&&!Bq(e,s)&&this.reportUnreadAttribute(e,s,r)}reportUnreadAttribute(e,n,i){const r=n.startsWith("parse.");let s=this.unknownNames.get(e);if(s===void 0&&(s=new Set,this.unknownNames.set(e,s)),s.has(n)||(s.size>=sO&&!r&&this.unknownOverflow.set(e,(this.unknownOverflow.get(e)??0)+1),s.add(n),s.size>sO&&!r))return;const o=r?U.PARSE_HINT_IGNORED:U.UNKNOWN_XML_ATTRIBUTE;this.report.warning("unsupported",o,Hq(e,n,r),{line:i,element:n})}beginGraph(e,n,i){this.reportUnreadAttributes("graph",e,Vq,n);const r=this.graphs.length===0;r&&this.topGraphs++;const s=e.get("id");s!==void 0&&s.length>0&&this.graphIds.add(s);const o=e.get("edgedefault");let l;if(o==="directed"||o==="undirected")l=o==="directed";else if(o===void 0){l=r?this.options.defaultDirected:this.graphs[this.graphs.length-1].directed;const c=l?"directed":"undirected";this.report.warnOnce("validation-error",U.EDGEDEFAULT_MISSING,r?`<graph> has no edgedefault; read as ${c}`:`a nested <graph> has no edgedefault; it takes its container's (${c})`,{line:n},`${U.EDGEDEFAULT_MISSING}:${r?"top":"nested"}`)}else l=r?this.options.defaultDirected:this.graphs[this.graphs.length-1].directed,this.report.error("validation-error",U.INVALID_EDGEDEFAULT,`edgedefault "${o}" is neither directed nor undirected; read as ${l?"directed":"undirected"}`,{line:n});let a=null;if(r&&this.graphSeen){this.report.warnOnce("unsupported",U.MULTIPLE_GRAPHS,"the document holds more than one top-level <graph>; their nodes and edges are merged into one graph",{line:n,element:e.get("id")??null});for(const c of["parse.nodes","parse.edges"])e.has(c)&&this.report.warnOnce("unsupported",U.PARSE_HINT_IGNORED,`the ${c} hint of a second top-level <graph> is ignored`,{line:n,element:c},`${U.PARSE_HINT_IGNORED}:second:${c}`)}else if(r){this.graphSeen=!0,this.graphId=e.get("id")??null,this.edgedefault=l?"directed":"undirected",this.direction.setHeader(l,{line:n});const c=this.hint(e.get("parse.nodes"),"parse.nodes",n),d=this.hint(e.get("parse.edges"),"parse.edges",n);if(a=c===null&&d===null?null:{nodes:c,edges:d},c!==null||d!==null)try{this.sink.reserve(c??void 0,d??void 0)}catch(u){if(!(u instanceof N))throw u;this.report.warning("validation-error",U.COUNT_HINT,`count hint refused: ${u.message}`,{line:n})}}this.graphs.push({directed:l,parent:i,hints:a,nodes:0,edges:0,line:n}),this.ctx.push(4)}finishGraph(){const e=this.graphs.pop();if(!(e?.hints===null||e===void 0))for(const[n,i,r]of[["parse.nodes",e.hints.nodes,e.nodes],["parse.edges",e.hints.edges,e.edges]])i!==null&&i!==r&&this.report.warning("validation-error",U.COUNT_MISMATCH,`<graph ${n}="${i}"> but the graph holds ${r} ${n==="parse.nodes"?"<node>":"<edge>"} elements`,{line:e.line,element:n})}hint(e,n,i){if(e===void 0)return null;const r=aJ(e);return r===null||r>yA?(this.report.warning("validation-error",U.COUNT_HINT,`<graph ${n}="${e}"> is not a count the sink can reserve; ignored`,{line:i,element:n}),null):r}beginKey(e,n){this.reportUnreadAttributes("key",e,Kq,n);const i=e.get("id")??null;i!==null&&this.unknownKeyIds.delete(i)&&this.report.warning("missing-value",U.KEY_DECLARED_LATE,`key "${i}" is declared after data that uses it; those values were dropped (declare <key> before <graph>)`,{line:n,element:i});const r=e.get("for")??"all";let s;switch(r){case"all":s=["graph","node","edge"];break;case"graphml":s=["graph"];break;case"graph":case"node":case"edge":s=[r];break;case"hyperedge":case"port":case"endpoint":this.report.warning("unsupported",U.KEY_DOMAIN_UNSUPPORTED,`key "${i??""}" is declared for ${r} elements, which are not kept`,{line:n,element:i}),s=[];break;default:this.report.error("validation-error",U.KEY_FOR_INVALID,`key "${i??""}" has an unknown for="${r}"`,{line:n,element:i}),s=[]}const o=e.get("attr.type")??e.get("type")??null;this.pendingKey={id:i,attrName:e.get("attr.name")??e.get("name")??null,attrType:o,yfilesType:e.get("yfiles.type")??(o===null?Qq(e):null),domains:s,line:n,desc:"",defaultText:null,defaultTree:void 0},this.ctx.push(2)}finishKey(){const e=this.pendingKey;if(this.pendingKey=null,e===null)return;const n={line:e.line,element:e.id};if(e.id===null||e.id.length===0){this.report.error("validation-error",U.KEY_MISSING_ID,"<key> without an id",n);return}const i=this.keys.get(e.id)??[];if(i.some(f=>f.domains.some(h=>e.domains.includes(h)))){this.report.error("validation-error",U.DUPLICATE_KEY,`key "${e.id}" is declared twice for the same kind of element`,n);return}const r=e.yfilesType!==null,s=e.attrName!==null&&e.attrName.length>0?e.attrName:e.id,o=r&&this.yfilesMode==="skip";o&&this.report.warning("unsupported",U.YFILES_SKIPPED,`yFiles key "${e.id}" (${e.yfilesType??""}) skipped per the yfiles option`,n);let l=!1,a=!1,c=null,d=null,u=null;for(const f of e.domains)if(!o){if(f==="edge"&&!r&&_y(s,this.options.weightFrom)){l=!0,this.weightOrigin??={id:e.id,title:e.attrName,type:e.attrType};continue}if(f==="node"&&!r&&s===Ps){if(this.options.restoreMangledIds){a=!0;continue}c=this.declareOriginalIdColumn(e);continue}try{const h=r?this.declareYfiles(e,s,f):this.declareTyped(e,s,f);f==="node"?c=h:f==="edge"?d=h:u=h}catch(h){this.report.recordError(h,n)}}this.keys.set(e.id,[...i,{id:e.id,name:s,node:c,edge:d,graph:u,weight:l,originalId:a,yfiles:r,skipped:o,domains:e.domains}])}declareTyped(e,n,i){const r=e.id??"",s=ga({format:ot,id:r,title:e.attrName!==null&&e.attrName.length>0?e.attrName:null,type:e.attrType,defaultText:e.defaultTree===void 0?e.defaultText:null,listSyntax:"comma",role:i!=="graph"&&n===hr?"label":null,long:this.options.long,taken:this.takenIn(i)});for(const l of s.issues)this.report.warning(l.category,l.code,l.message,{line:e.line,element:r});e.defaultTree!==void 0&&this.report.warning("validation-error",U.DATA_NESTED,`the <default> of key "${r}" holds elements; a ${e.attrType??"string"} default must be text`,{line:e.line,element:r});const{decl:o}=s;return e.desc.length>0&&(o.extra={desc:e.desc}),this.declareTarget(i,o,s.spec,s.listSyntax)}declareYfiles(e,n,i){const r=e.id??"",s=Xt(n,r,this.takenIn(i)),o={name:s,dtype:"json",nullable:!0,origin:{format:ot,id:r,title:e.attrName!==null&&e.attrName!==s?e.attrName:null,type:e.yfilesType,namespace:"yfiles"}};return e.defaultTree!==void 0?o.default=e.defaultTree:e.defaultText!==null&&(o.default=e.defaultText),e.desc.length>0&&(o.extra={desc:e.desc}),this.declareTarget(i,o,null,"comma")}declareOriginalIdColumn(e){const n={name:Xt(Nj,e.id,this.takenIn("node")),dtype:"string",nullable:!0,role:"originalId",origin:{format:ot,id:e.id,title:e.attrName,type:e.attrType,namespace:null}};return this.declareTarget("node",n,null,"comma")}declareTarget(e,n,i,r){if(e==="graph")return this.sink.setGraphValue(n.name,void 0,n),this.graphColumnNames.add(n.name),{name:n.name,handle:A,decl:n,spec:i,listSyntax:r};const s=he(this.sink,e,n,this.report,{element:n.name});return{name:s.decl.name,handle:s.handle,decl:s.decl,spec:i,listSyntax:r}}takenIn(e){if(e==="graph")return r=>this.graphColumnNames.has(r);const n=e==="node"?s$:r$,i=eu(this.sink,e);return r=>n.has(r)||i(r)}beginData(e,n,i){this.reportUnreadAttributes("data",e,Xq,n);const r=e.get("key"),{content:s}=this;if(r!==void 0&&this.checkDuplicateData(r,i,n),s.key=null,s.pendingKey=null,s.domain=i,s.text="",s.tree=null,s.line=n,r===void 0)this.report.error("validation-error",U.DATA_MISSING_KEY,"<data> without a key attribute",{line:n});else{const o=this.keys.get(r),l=o?.find(a=>a.domains.includes(i))??o?.[0];l===void 0?(this.unknownKeyIds.add(r),this.report.error("validation-error",U.UNKNOWN_KEY,`<data> references undeclared key "${r}"`,{line:n,element:r})):!l.skipped&&!l.domains.includes(i)?this.report.warnOnce("validation-error",U.KEY_DOMAIN,`key "${r}" is declared for ${l.domains.join(" / ")} elements but used on a ${i}; ignored`,{line:n,element:r}):s.key=l}this.ctx.push(8)}checkDuplicateData(e,n,i){let r=null;n==="node"?r=this.nodes.at(-1)??null:n==="edge"?r=this.edge:r=this.graphKeys,r!==null&&(r.keys??=new Set,r.keys.has(e)&&this.report.warning("validation-error",U.DUPLICATE_ATTRIBUTE,`a second <data key="${e}"> on one ${n}; the later value is kept`,{line:i,element:e}),r.keys.add(e))}captureStart(e,n){const{content:i}=this;i.tree===null&&(i.tree=new sX,i.text.length>0&&(i.tree.text(i.text),i.text="")),i.tree.start(e,n),this.ctx.push(9)}captureEnd(){this.content.tree?.end()}finishDefault(){const{content:e}=this,n=e.pendingKey;n!==null&&(e.tree!==null?n.defaultTree=e.tree.finish():n.defaultText=e.text,e.tree=null,e.text="",e.pendingKey=null)}finishData(){const{content:e}=this,{key:n}=e,i=e.tree===null?e.text:e.tree.finish();if(e.tree=null,e.text="",e.key=null,n===null||n.skipped)return;const r={line:e.line,element:n.id};switch(e.domain){case"node":{const s=this.nodes[this.nodes.length-1];if(n.originalId){if(typeof i!="string"||s.index!==A){this.report.warning("validation-error",U.ORIGINAL_ID_IGNORED,typeof i=="string"?`the ${Ps} value comes after the node's nested <graph>, which added the node under its written id; it is not restored`:`the ${Ps} value holds elements, not text; it is not restored`,r);return}s.restoredId=i;return}if(n.yfiles)for(const[l,a]of this.graphics("node",n,i,r))this.setNodeData(s,l,a);if(n.node===null)return;const o=this.parseValue(n.node,i,r);o!==void 0&&this.setNodeData(s,n.node.handle,o);return}case"edge":{const{edge:s}=this;if(s===null)return;if(n.weight){if(typeof i!="string"){this.report.error("validation-error",U.DATA_NESTED,"a weight value must be text",r);return}s.weightKey!==null&&s.weightKey!==n.id&&this.report.warning("validation-error",U.DUPLICATE_ATTRIBUTE,`the edge has values of two weight keys ("${s.weightKey}" and "${n.id}"); the later one is kept`,r),s.weightKey=n.id;try{s.weight=Kn(i,this.report),this.checkOverflow(i,s.weight,n.name,r)}catch(l){this.skipEdge(s),this.report.recordError(l,r)}return}if(n.yfiles)for(const[l,a]of this.graphics("edge",n,i,r))s.pending.push(l,a);if(n.edge===null)return;const o=this.parseValue(n.edge,i,r);o!==void 0&&s.pending.push(n.edge.handle,o);return}case"graph":{if(n.graph===null)return;const s=this.parseValue(n.graph,i,r);if(s!==void 0)try{this.sink.setGraphValue(n.graph.name,s,n.graph.decl)}catch(o){this.report.recordError(o,r)}return}default:{const{domain:s}=e;throw new N("E_UNSUPPORTED",`unknown data domain ${String(s)}`,{})}}}setNodeData(e,n,i){e.index===A?e.pending.push(n,i):e.failed||this.sink.setNodeValue(n,e.index,i)}graphics(e,n,i,r){const s=[],o=[],l=gD(e,i,o);for(const a of o)this.report.warnOnce("validation-error",U.YFILES_VALUE,`a yFiles ${e} ${a} that is not a number is not mapped to its yfiles column (the graphics tree is kept)`,r,`${U.YFILES_VALUE}:${e}:${a}`);for(const[a,c]of l){const d=`${e}:${a}`;let u=this.graphicsColumns.get(d);if(u===void 0){try{({handle:u}=he(this.sink,e,fX(e,a,n.id),this.report,r))}catch(f){this.report.recordError(f,r);continue}this.graphicsColumns.set(d,u)}s.push([u,c])}return s}parseValue(e,n,i){if(e.spec===null)return this.yfilesLossNoted||(this.yfilesLossNoted=!0,this.report.loss(pr.YFILES_JSON,"yFiles nested XML is kept as a JSON tree: structure preserved, not byte-exact",e.name)),n;if(typeof n!="string"&&e.spec.declared===""){this.report.warnOnce("validation-error",U.DATA_STRUCTURED,`<data> of the untyped attribute "${e.name}" holds elements; they are kept as XML text`,{line:i.line,element:e.name},`${U.DATA_STRUCTURED}:${e.name}`);const s=[];return Da(n,"",s),s.join("").trim()}if(typeof n!="string"){this.report.error("validation-error",U.DATA_NESTED,`<data> of the ${e.spec.declared} attribute "${e.name}" holds elements, not text`,i);return}const{spec:r}=e;if(!(r.kind!=="string"&&Tr(n)))try{const s=ma(n,r,e.listSyntax);return r.precision&&Qd(r,n)&&this.report.warnOnce("precision",re,`long values of "${e.name}" beyond 2^53 are stored as the nearest double`,{line:i.line,element:e.name}),this.checkOverflow(n,s,e.name,i),s}catch(s){this.report.recordError(s,i);return}}checkOverflow(e,n,i,r){typeof n=="number"&&Fp(e)&&this.report.warnOnce("precision",re,`values of "${i}" beyond the double range (${e.trim()}) are stored as Infinity`,{line:r.line,element:i},`${re}:overflow:${i}`)}beginNode(e,n){this.reportUnreadAttributes("node",e,Yq,n);const i=this.graphs[this.graphs.length-1];i.nodes++;const r={id:null,idText:null,index:A,parent:i.parent,pending:[],restoredId:null,failed:!1,line:n,keys:null},s=e.get("id");if(s===void 0||s.length===0)this.skipNode(r),this.report.error("missing-value",U.MISSING_ID,"<node> without an id",{line:n});else try{r.id=this.coercer.text(s),r.idText=s,this.reportMerge(s,n)}catch(o){this.skipNode(r),this.report.recordError(o,{line:n,element:s})}this.nodes.push(r),this.ctx.push(5)}materializeNode(e){if(e.index!==A||e.failed)return;const n=e.restoredId??e.id;if(n===null){e.failed=!0;return}e.restoredId!==null&&e.idText!==null&&this.restored.set(e.idText,e.restoredId);try{const i=this.sink.indexOf(n),r=this.sink.addNode(n);i!==A&&this.hubs.has(r)?this.report.warning("validation-error",U.HUB_ID_CLASH,`node "${String(n)}" has the id of the hub a star-expanded hyperedge created earlier; the node is merged into the hub`,{line:e.line,element:String(n)}):i!==A&&this.declared.has(r)?this.report.warning("validation-error",U.DUPLICATE_NODE,`node "${String(n)}" is declared twice; the declarations are merged`,{line:e.line,element:String(n)}):this.report.counts.nodes++,this.declared.add(r),e.index=r,this.checkAbort(),e.parent!==A&&this.sink.setNodeValue(this.parentColumn(),r,e.parent);const{pending:s}=e;for(let o=0;o<s.length;o+=2)this.sink.setNodeValue(s[o],r,s[o+1]);s.length=0}catch(i){this.skipNode(e),this.report.recordError(i,{line:e.line,element:String(n)})}}skipNode(e){e.failed||(e.failed=!0,this.report.counts.skippedNodes++)}finishNode(){const e=this.nodes.pop();e!==void 0&&this.materializeNode(e)}parentColumn(){return this.parentHandle===A&&(this.parentHandle=this.sink.declareNodeColumn({name:gb,dtype:"u32",role:"parent",refersTo:"node",nullable:!0,origin:{format:ot,id:null,title:null,type:"graph",namespace:null}})),this.parentHandle}beginEdge(e,n){this.reportUnreadAttributes("edge",e,tJ,n);const i=this.graphs[this.graphs.length-1];i.edges++;const r=e.get("id"),s=e.get("source"),o=e.get("target"),l={source:null,target:null,id:r===void 0||r.length===0?null:r,kind:i.directed?"directed":"undirected",sourcePort:e.get("sourceport")??null,targetPort:e.get("targetport")??null,weight:void 0,pending:[],failed:!1,line:n,keys:null,weightKey:null,sourceText:s??null,targetText:o??null},a={line:n,element:l.id};if((s===void 0||s.length===0)&&(this.skipEdge(l),this.report.error("missing-value",U.MISSING_ENDPOINT,"<edge> without a source",a)),(o===void 0||o.length===0)&&(this.skipEdge(l),this.report.error("missing-value",U.MISSING_ENDPOINT,"<edge> without a target",a)),!l.failed&&s!==void 0&&o!==void 0)try{l.source=this.endpointId(s,n),l.target=this.endpointId(o,n)}catch(d){this.skipEdge(l),this.report.recordError(d,a)}const c=e.get("directed");c!==void 0&&(c==="true"||c==="1"?l.kind="directed":c==="false"||c==="0"?l.kind="undirected":(this.skipEdge(l),this.report.error("validation-error",U.INVALID_DIRECTED,`directed="${c}" is neither true nor false (nor 1 or 0)`,a))),this.edge=l,this.ctx.push(6)}finishEdge(){const{edge:e}=this;if(this.edge=null,e!==null){if(e.failed||e.source===null||e.target===null){this.skipEdge(e);return}if(!this.options.addMissingNodes&&(this.sink.indexOf(e.source)===A||this.sink.indexOf(e.target)===A)||e.id!==null&&this.deferredEdgeIds.has(e.id)){e.id!==null&&this.deferredEdgeIds.add(e.id),this.deferred.push(e);return}this.addEdge(e)}}addEdge(e){if(e.source===null||e.target===null)return;const n=e.id??`${String(e.source)} -> ${String(e.target)}`,i={line:e.line,element:n};try{if(this.options.addMissingNodes||(this.requireNode(e.source),this.requireNode(e.target)),this.checkGraphEndpoint(e.source,e.sourceText,i),this.checkGraphEndpoint(e.target,e.targetText,i),e.id!==null&&this.edgeIds.has(e.id))throw new N("E_DUPLICATE_EDGE_ID",`edge id "${e.id}" is used twice`,{id:e.id});const r=this.sink.edgeCount;this.countEndpoints(e.source,e.target);const s=this.direction.addEdge(e.source,e.target,e.kind,e.weight,i);this.report.counts.edges+=this.sink.edgeCount-r,this.checkAbort(),e.id!==null&&(this.edgeIds.add(e.id),this.sink.setEdgeValue(this.edgeIdColumn(),s,e.id)),e.sourcePort!==null&&(this.sink.setEdgeValue(this.portColumn("source"),s,e.sourcePort),this.portRefs.push([e.source,e.sourcePort])),e.targetPort!==null&&(this.sink.setEdgeValue(this.portColumn("target"),s,e.targetPort),this.portRefs.push([e.target,e.targetPort]));const{pending:o}=e;for(let l=0;l<o.length;l+=2)this.sink.setEdgeValue(o[l],s,o[l+1])}catch(r){this.skipEdge(e),this.report.recordError(r,i)}}skipEdge(e){e.failed||(e.failed=!0,this.report.counts.skippedEdges++)}checkGraphEndpoint(e,n,i){n!==null&&this.graphIds.has(n)&&this.sink.indexOf(e)===A&&this.report.warning("validation-error",U.GRAPH_ENDPOINT,`edge endpoint "${n}" names a <graph>, not a node; a node "${n}" is created`,i)}requireNode(e){if(this.sink.indexOf(e)===A)throw new N("E_UNKNOWN_NODE",`edge endpoint "${String(e)}" is not a declared node`,{id:e})}edgeIdColumn(){return this.edgeIdHandle===A&&(this.edgeIdHandle=this.sink.declareEdgeColumn({name:fb,dtype:"string",role:"id",unique:!0,nullable:!0,origin:{format:ot,id:null,title:null,type:"id",namespace:null}})),this.edgeIdHandle}portColumn(e){return e==="source"?(this.sourcePortHandle===A&&(this.sourcePortHandle=this.sink.declareEdgeColumn({name:hb,dtype:"string",role:"sourcePort",nullable:!0,origin:{format:ot,id:null,title:null,type:"sourceport",namespace:null}})),this.sourcePortHandle):(this.targetPortHandle===A&&(this.targetPortHandle=this.sink.declareEdgeColumn({name:pb,dtype:"string",role:"targetPort",nullable:!0,origin:{format:ot,id:null,title:null,type:"targetport",namespace:null}})),this.targetPortHandle)}beginHyperedge(e,n){this.reportUnreadAttributes("hyperedge",e,qq,n);const i=e.get("id")??null,r={line:n,element:i};switch(this.options.hyperedges){case"error":throw this.report.error("unsupported",U.HYPEREDGE,'hyperedge refused (hyperedges: "error")',r),this.report.abort("hyperedge refused",{code:U.HYPEREDGE});case"skip":this.report.warnOnce("unsupported",U.HYPEREDGE_SKIPPED,'hyperedges are skipped (hyperedges: "skip"); use "star" or "clique" to expand them',r),this.report.counts.skippedEdges++,this.ctx.push(10);return;case"star":case"clique":this.hyperedge={id:i,endpoints:[],failed:!1,line:n},this.ctx.push(7);return;default:{const s=this.options.hyperedges;throw new N("E_UNSUPPORTED",`unknown hyperedges policy ${String(s)}`,{option:"hyperedges"})}}}readEndpoint(e,n){const{hyperedge:i}=this;if(i===null)return;const r={line:n,element:i.id},s=e.get("node"),o=e.get("type")??"undir";if(s===void 0||s.length===0){this.skipEdge(i),this.report.error("missing-value",U.HYPEREDGE_ENDPOINT,"<endpoint> without a node",r);return}if(o!=="in"&&o!=="out"&&o!=="undir"){this.skipEdge(i),this.report.error("validation-error",U.HYPEREDGE_ENDPOINT,`endpoint type "${o}" is not in, out or undir`,r);return}try{const l=this.endpointId(s,n);i.endpoints.push({node:l,type:o})}catch(l){this.skipEdge(i),this.report.recordError(l,r)}}finishHyperedge(){const{hyperedge:e}=this;if(this.hyperedge=null,e!==null&&!e.failed){if(e.endpoints.length===0){this.skipEdge(e),this.report.error("missing-value",U.HYPEREDGE_ENDPOINT,"<hyperedge> without endpoints yields no edge",{line:e.line,element:e.id});return}if(!this.options.addMissingNodes&&e.endpoints.some(n=>this.sink.indexOf(n.node)===A)){this.deferred.push(e);return}this.expandHyperedge(e)}}expandHyperedge(e){const n={line:e.line,element:e.id};try{for(const i of e.endpoints)this.options.addMissingNodes||this.requireNode(i.node);for(const i of new Set(e.endpoints.map(r=>r.node)))this.countEndpoints(i,i);this.options.hyperedges==="star"?this.expandStar(e,n):this.expandClique(e,n)===0&&(this.skipEdge(e),this.report.error("validation-error",U.HYPEREDGE_ENDPOINT,"no two endpoints of this hyperedge can be joined (all in, all out, or only one); it yields no edge",n))}catch(i){this.skipEdge(e),this.report.recordError(i,n)}}expandStar(e,n){this.hyperedgeCount++;const i=e.id??`hyperedge${this.hyperedgeCount}`;let r=i;for(let o=2;this.sink.indexOf(r)!==A;o++)r=`${i}#${o}`;const s=this.sink.addNode(r);this.declared.add(s),this.hubs.add(s),this.report.counts.nodes++,this.hubHandle===A&&(this.hubHandle=this.sink.declareNodeColumn({name:Aj,dtype:"bool",nullable:!0,origin:{format:ot,id:null,title:null,type:"hyperedge",namespace:null}})),this.sink.setNodeValue(this.hubHandle,s,!0);for(const o of e.endpoints){const l=this.sink.edgeCount;switch(o.type){case"in":this.direction.addEdge(o.node,r,"directed",void 0,n);break;case"out":this.direction.addEdge(r,o.node,"directed",void 0,n);break;case"undir":this.direction.addEdge(o.node,r,"undirected",void 0,n);break;default:{const{type:a}=o;throw new N("E_UNSUPPORTED",`unknown endpoint type ${String(a)}`,{})}}this.report.counts.edges+=this.sink.edgeCount-l}}expandClique(e,n){const{endpoints:i}=e;let r=0;for(let s=0;s<i.length;s++)for(let o=s+1;o<i.length;o++){const l=i[s],a=i[o],c=this.sink.edgeCount;if(l.type==="undir"||a.type==="undir")this.direction.addEdge(l.node,a.node,"undirected",void 0,n);else if(l.type==="in"&&a.type==="out")this.direction.addEdge(l.node,a.node,"directed",void 0,n);else if(l.type==="out"&&a.type==="in")this.direction.addEdge(a.node,l.node,"directed",void 0,n);else continue;r++,this.report.counts.edges+=this.sink.edgeCount-c}return r}countEndpoints(e,n){if(!this.options.addMissingNodes)return;let i=0;this.sink.indexOf(e)===A&&i++,e!==n&&this.sink.indexOf(n)===A&&i++,this.report.counts.nodes+=i}checkAbort(){++this.elementsSinceCheck>=sJ&&(this.elementsSinceCheck=0,F(this.options.signal))}endpointId(e,n){const i=this.restored.get(e);if(i!==void 0)return i;const r=this.coercer.text(e);return this.reportMerge(e,n),r}reportMerge(e,n){const i=this.coercer.lastMerge;i!==null&&this.report.warning("coercion",U.ID_MERGED,`id "${i.text}" merged with "${i.previousText}" as ${i.id} under ids: "number"`,{line:n,element:e})}}function aJ(t){if(t===void 0||!/^\d+$/.test(t))return null;const e=Number(t);return Number.isSafeInteger(e)?e:null}function cJ(t){const e=t?.yfiles;if(e===void 0)return"json";if(typeof e!="string"||!rJ.has(e))throw new N("E_UNSUPPORTED",`option yfiles: ${JSON.stringify(e)} is not "json" or "skip"`,{option:"yfiles",found:e});return e}function dJ(t){const e=_T(t.subarray(0,iJ));if(!/^\uFEFF?\s*</.test(e))return 0;const n=e.search(/<([\w.-]+:)?graphml[\s>/]/);return n>=0?e.includes(ws,n)?1:.9:/^\s*<(\?xml|!--|!DOCTYPE)/.test(e)?.05:0}async function uJ(t,e,n){const i=tt(n,nJ),r=cJ(n),s=new ne(ot,i.errorLimit);_t(e,n,s,!0),St(n,s,oJ);const o=new lJ(e,s,i,r);try{await ff($r(t,s,{...i,declaredEncoding:uf,xml:!0}),o)}catch(l){throw l instanceof $y&&s.fail(U.EMPTY_INPUT,"the input is empty (no markup at all)",{line:l.line}),l instanceof te&&s.fail(l instanceof df?U.XML_NESTING:U.XML_SYNTAX,l.message,{line:l.line}),l}return o.finish(),F(i.signal),s.finish()}const fJ=Object.freeze({format:ot,options:Object.freeze(["yfiles"]),extensions:Sj,mimeTypes:Oj,sniff:dJ,styles:Wq,positions:hX,import:uJ}),hJ=new Set(["graphml","key","default","graph","node","edge","hyperedge","endpoint","port","data","desc","locator"]);function pJ(t){return t==="key"?"element <key> is only allowed as a child of <graphml>, before the first <graph>; it was skipped":hJ.has(t)?`element <${t}> is not allowed at this place in a GraphML file and was skipped`:`element <${t}> is not GraphML and was skipped`}const Ki=Object.freeze({type:{dtype:"dict"},name:{dtype:"string",role:"label"},namespace:{dtype:"dict"},def:{dtype:"string"},"def.xrefs":{dtype:"list"},comment:{dtype:"string"},synonym:{dtype:"json"},xref:{dtype:"list"},"xref.descriptions":{dtype:"json"},alt_id:{dtype:"list"},subset:{dtype:"list"},replaced_by:{dtype:"list"},consider:{dtype:"list"},is_obsolete:{dtype:"bool"},is_anonymous:{dtype:"bool"},builtin:{dtype:"bool"},created_by:{dtype:"string"},creation_date:{dtype:"string"},intersection_of:{dtype:"json"},union_of:{dtype:"list"},equivalent_to:{dtype:"list"},disjoint_from:{dtype:"list"},property_value:{dtype:"json"},domain:{dtype:"string"},range:{dtype:"string"},inverse_of:{dtype:"string"},transitive_over:{dtype:"list"},disjoint_over:{dtype:"list"},holds_over_chain:{dtype:"json"},equivalent_to_chain:{dtype:"json"},expand_assertion_to:{dtype:"json"},expand_expression_to:{dtype:"json"},is_cyclic:{dtype:"bool"},is_reflexive:{dtype:"bool"},is_symmetric:{dtype:"bool"},is_anti_symmetric:{dtype:"bool"},is_asymmetric:{dtype:"bool"},is_transitive:{dtype:"bool"},is_functional:{dtype:"bool"},is_inverse_functional:{dtype:"bool"},is_metadata_tag:{dtype:"bool"},is_class_level:{dtype:"bool"},propertyType:{dtype:"dict"},"obo.qualifiers":{dtype:"json"},"obo.unrecognized":{dtype:"json"}}),gJ=Object.freeze({relation:{dtype:"dict",role:"kind"},qualifiers:{dtype:"json"},meta:{dtype:"json"}}),co="graphty.placeholder";function Pa(t,e){if(e===co)return{name:e,dtype:"bool",nullable:!0,origin:{format:"graphty",id:"placeholder"}};const n=(t==="node"?Ki:gJ)[e],i={name:e,dtype:n.dtype,nullable:!0,origin:{format:"obo",id:e}};return n.dtype==="list"&&(i.itemDtype="string"),n.role!==void 0&&(i.role=n.role),i}const Vf="http://purl.obolibrary.org/obo/",mJ="https://purl.obolibrary.org/obo/",sr="http://www.geneontology.org/formats/oboInOwl#";function Ru(t){const e=[Vf,mJ].find(s=>t.startsWith(s));if(e===void 0)return t;const n=t.slice(e.length),i=n.indexOf("#");if(i>0){const s=n.slice(i+1);return s.length>0&&!n.slice(0,i).includes("/")?s:t}const r=n.indexOf("_");return r<=0||n.includes("/")||r===n.length-1?t:`${n.slice(0,r)}:${n.slice(r+1)}`}const xa=new Set(["EXACT","BROAD","NARROW","RELATED"]);function yJ(t){const e=t.startsWith(sr)?t.slice(sr.length):t,n=/^has(Exact|Broad|Narrow|Related)Synonym$/.exec(e);return n===null?null:n[1].toUpperCase()}const hc=new Map([[`${sr}hasOBONamespace`,"namespace"],[`${sr}hasAlternativeId`,"alt_id"],[`${sr}created_by`,"created_by"],[`${sr}creation_date`,"creation_date"],[`${Vf}IAO_0100001`,"replaced_by"],[`${sr}consider`,"consider"],[`${sr}shorthand`,"shorthand"]]),bJ=new Set([w.DTYPE,w.LIST,w.JSON,w.COMPONENTS,w.GRAPH_ATTRIBUTES]),EJ=new Set(["label","kind"]),wJ=Object.freeze({label:"name"}),_J=Object.freeze({kind:"relation"}),Ma=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),SJ=new Set(["Term","Instance","Typedef"]);function Ne(t,e){if(!t.isSet(e))return;const n=t.value(e);return ArrayBuffer.isView(n)?Array.from(n):n}function rl(t,e){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return Do(t,e==="f32"||e==="i32"||e==="u32"||e==="u8"?e:"f64");default:return JSON.stringify(t)??"null"}}function AD(t,e){switch(t){case"list":case"bool":case"json":return e.dtype===t;default:return Lu(e)}}function TD(t){return t===void 0?[]:Array.isArray(t)?t:[t]}function sa(t,e,n){const i=t.byRole(e);if(i!==null)return{column:Lu(i)?i:null,assumed:!1};const r=t.get(n);return r!==null&&r.meta.role===null&&Lu(r)?{column:r,assumed:!0}:{column:null,assumed:!1}}function Lu(t){return t.dtype==="string"||t.dtype==="dict"}function OJ(t){const e=t.nodes.get(co);return e!==null&&e.dtype==="bool"?e:null}function ID(t,e,n){const i=new Uint8Array(t.nodeCount),r=OJ(t);if(r===null)return i;const{src:s,dst:o}=t.edgeList(),l=new Uint8Array(t.nodeCount),a=new Uint8Array(t.nodeCount);for(const d of e)l[o[d]]=1,n.outgoingAllowed?l[s[d]]=1:a[s[d]]=1;const c=[...t.nodes].filter(d=>d!==r);for(let d=0;d<t.nodeCount;d++)r.isSet(d)&&r.value(d)===!0&&l[d]===1&&a[d]===0&&!n.changed(d)&&c.every(u=>!u.isSet(d))&&(i[d]=1);return i}function $D(t,e){const n=[];for(let s=0;s<t.length;s++)t[s]===0&&n.push(s);const i=new Uint8Array(t.length);for(const s of e)t[s]===1&&i[s]===0&&(i[s]=1,n.push(s));let r=0;for(let s=0;s<n.length;s++)n[s]!==s&&r++;return r}function e0(t,e){if(typeof t!="object"||t===null||Array.isArray(t))return!1;const n=Object.entries(t);return n.length>0&&n.every(([i,r])=>e(i)&&(typeof r=="string"||Array.isArray(r)&&r.length>=2&&r.every(s=>typeof s=="string")))}function CD(t,e,n){const{label:i,note:r}=n;let s=null;const o=t.edges.byRole("kind"),l={roles:EJ,nodeRoleNames:i===null?{}:wJ,edgeRoleNames:o!==null&&Lu(o)?_J:{}};for(const a of Un(t,n.caps,e,l))bJ.has(a.code)||(a.code===w.MIXED_DIRECTION_ERROR&&s===null&&(s=new N("E_DIRECTED",a.message,{reason:"mixed direction"})),r(a.code,a.message,a.column,a.count));return NJ(t,n),s}function NJ(t,e){const{label:n,note:i}=e,r=t.nodes.byRole("kind");r!==null&&i(w.ROLE,`node column "${r.meta.name}" (kind) is written as property values; the format has no node kind slot`,r.meta.name,r.length-r.nullCount);const s=t.edges.byRole("label");s!==null&&i(w.ROLE,`edge column "${s.meta.name}" (label) is written as ${e.edgeSlot}; the format has no edge label slot`,s.meta.name,s.length-s.nullCount),n!==null&&e.labelAssumed&&i(Qa,`node column "name" is written as each node's name and reads back as the label`,"name",n.length-n.nullCount)}function vD(t,e,n,i,r){const s=[["node",t.nodes,o=>e.some(l=>o.isSet(l))||o.meta.name===co&&n.some((l,a)=>l===1&&o.isSet(a))],["edge",t.edges,o=>i.some(l=>o.isSet(l))]];for(const[o,l,a]of s)for(const c of l){const{role:d,name:u}=c.meta;d!==null&&(Ma.has(d)||o==="edge"&&d==="id")||a(c)||r(w.EMPTY_COLUMN,`${o} column "${u}" has no value to write; it reads back absent`,u,0)}}function t0(t,e,n,i){const r=n.filter(o=>e.isSet(o)).length;if(r===0)return;const s=e.meta.role===null?"":` (its ${e.meta.role} role is lost)`;t(cy,`node column "${e.meta.name}" is written as ${i} and reads back inside the property_value column, not as its own column${s}`,e.meta.name,r)}const AJ=2e8;class Yf{#e={node:0,edge:0};constructor(e=AJ){this.limit=e}spend(e,n){return this.#e[e]+=n,this.#e[e]<=this.limit}exhausted(e){return this.#e[e]>this.limit}used(e){return this.#e[e]}}const TJ=new Map([["background-color","rgb(153,153,153)"],["background-opacity","1"],["opacity","1"],["border-color","rgb(0,0,0)"],["border-opacity","1"],["border-width","0px"],["border-style","solid"],["shape","ellipse"],["width","30px"],["height","30px"],["label",""],["color","rgb(0,0,0)"],["font-size","16px"],["font-family","Helvetica Neue, Helvetica, sans-serif"],["font-weight","normal"],["font-style","normal"],["visibility","visible"],["display","element"],["text-valign","top"],["text-halign","center"],["text-wrap","none"],["text-max-width","9999px"],["line-color","rgb(153,153,153)"],["line-style","solid"],["target-arrow-shape","none"],["source-arrow-shape","none"],["target-arrow-fill","filled"],["source-arrow-fill","filled"],["target-arrow-color","rgb(153,153,153)"],["source-arrow-color","rgb(153,153,153)"],["curve-style","haystack"],["arrow-scale","1"],["source-label",""],["target-label",""]]),gm=[{selector:":parent",style:{shape:"rectangle",padding:"10px","background-color":"rgb(238,238,238)","border-color":"rgb(204,204,204)","border-width":"1px"}},{selector:"edge",style:{width:"3px"}},{selector:":loop",style:{"curve-style":"bezier"}},{selector:"edge:compound",style:{"curve-style":"bezier"}},{selector:":selected",style:{"background-color":"rgb(1,105,217)","line-color":"rgb(1,105,217)","source-arrow-color":"rgb(1,105,217)","target-arrow-color":"rgb(1,105,217)"}},{selector:":parent:selected",style:{"background-color":"rgb(204,225,249)","border-color":"rgb(174,200,229)"}}],DD=16,Le=t=>({property:t,type:"text"}),lO=t=>({property:t,type:"color"}),IJ=[["background-image",Le("_bgImage")],["background-fit",Le("_bgFit")],["background-width",Le("_bgWidth")],["background-height",Le("_bgHeight")],["background-width-relative-to",Le("_bgWidthRel")],["background-height-relative-to",Le("_bgHeightRel")],["background-position-x",Le("_bgPosX")],["background-position-y",Le("_bgPosY")],["background-offset-x",Le("_bgOffX")],["background-offset-y",Le("_bgOffY")],["background-repeat",Le("_bgRepeat")],["background-clip",Le("_bgClip")],["background-image-smoothing",Le("_bgSmooth")],["background-image-opacity",Le("_bgOpacity")],["pie-size",Le("_pieSize")],["pie-hole",Le("_pieHole")],["pie-start-angle",Le("_pieStart")],["stripe-size",Le("_stripeSize")],["stripe-direction",Le("_stripeDir")],...Array.from({length:DD},(t,e)=>[[`pie-${String(e+1)}-background-color`,lO(`_pieC${String(e+1)}`)],[`pie-${String(e+1)}-background-size`,Le(`_pieS${String(e+1)}`)],[`pie-${String(e+1)}-background-opacity`,Le(`_pieO${String(e+1)}`)],[`stripe-${String(e+1)}-background-color`,lO(`_stripeC${String(e+1)}`)],[`stripe-${String(e+1)}-background-size`,Le(`_stripeS${String(e+1)}`)],[`stripe-${String(e+1)}-background-opacity`,Le(`_stripeO${String(e+1)}`)]]).flat()];function pc(t){const e=/^(-?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)\s*([a-z%]*)$/i.exec((t??"").trim());return e===null?null:[Number(e[1]),e[2].toLowerCase()]}const sl=t=>Math.round(t*1e6)/1e6;function Ua(t,e){const n=pc(t);if(n===null)return null;let i=null;return n[1]==="%"?i=e===null?null:n[0]/100*e:(n[1]==="px"||n[1]==="")&&(i=n[0]),i===null||i<0?null:sl(i)}function $J(t){const e=Number.parseFloat(t??"");return!Number.isFinite(e)||e<=0?0:(t??"").trim().endsWith("%")?e/100:e}function Ga(t){const e=pc(t);return e===null?null:e[1]==="%"?sl(e[0]/100):e[1]===""?sl(e[0]):null}function CJ(t){const e=(t??"").trim().split(/\s+/)[0]??"",n=/^url\((['"]?)(.*)\1\)$/.exec(e)?.[2]??e;return n===""||n==="none"?null:n}function vJ(t){const e=pc(t);if(e===null||e[1]!=="rad"&&e[1]!=="deg"&&e[1]!=="")return null;const n=e[1]==="rad"?e[0]*180/Math.PI:e[0];return sl((n%360+360)%360)}function aO(t,e,n){const i=[],r=[],s=[];for(let o=1;o<=DD;o++){const l=pc(t.get(`${e}S${String(o)}`)?.[n]),a=l!==null&&(l[1]==="%"||l[1]==="")?sl(l[0]/100):null;if(a===null||a<=0)continue;i.push(t.get(`${e}C${String(o)}`)?.[n]??"#000000"),r.push(String(a));const c=Number(t.get(`${e}O${String(o)}`)?.[n]??"1");s.push(String(Number.isFinite(c)?Math.max(0,Math.min(1,c)):1))}return i.length===0?null:{colors:i.join(" "),sizes:r.join(" "),opacities:s.every(o=>o==="1")?null:s.join(" ")}}function DJ(t,e,n){const i=s=>n[s]??=new Array(t).fill(null),r=(s,o)=>{const l=n[s]?.[o];return typeof l=="number"?l:null};for(let s=0;s<t;s++){const o={word:c=>e.get(c)?.[s]??null,put:(c,d)=>{i(c)[s]=d},w:r("width",s)??30,h:r("height",s)??30};kJ(o);const l=aO(e,"_pie",s);l!==null&&xJ(o,l);const a=aO(e,"_stripe",s);a!==null&&MJ(o,a)}}function kJ(t){const e=CJ(t.word("_bgImage"));if(e===null)return;t.put("image",e);const n=t.word("_bgFit")??"none";t.put("imageFit",["none","contain","cover"].includes(n)?n:"none"),RJ(t),LJ(t),PJ(t)}function RJ(t){const e=$J(t.word("_padding")),n=(o,l)=>o==="inner"?l:l+2*e,i=["repeat","repeat-x","repeat-y"].includes(t.word("_bgRepeat")??""),r=i?null:Ua(t.word("_bgWidth"),n(t.word("_bgWidthRel"),t.w)),s=i?null:Ua(t.word("_bgHeight"),n(t.word("_bgHeightRel"),t.h));r!==null&&t.put("imageWidth",r),s!==null&&t.put("imageHeight",s),r===null!=(s===null)&&t.put("imageAutoSize","natural")}function LJ(t){const e=Ga(t.word("_bgPosX")),n=Ga(t.word("_bgPosY"));e!==null&&e>=0&&t.put("imagePositionX",e),n!==null&&n>=0&&t.put("imagePositionY",n);const i=Ua(t.word("_bgOffX"),t.w),r=Ua(t.word("_bgOffY"),t.h);i!==null&&t.put("imageOffsetX",i),r!==null&&t.put("imageOffsetY",r)}function PJ(t){const e=t.word("_bgRepeat");e!==null&&["repeat","repeat-x","repeat-y","no-repeat"].includes(e)&&t.put("imageRepeat",e);const n=t.word("_bgClip");n!==null&&t.put("imageClip",n==="none"?"none":"node");const i=t.word("_bgSmooth");(i==="yes"||i==="no")&&t.put("imageSmoothing",i==="yes");const r=Number(t.word("_bgOpacity")??Number.NaN);Number.isFinite(r)&&t.put("imageOpacity",Math.max(0,Math.min(1,r)))}function xJ(t,e){t.put("pieColors",e.colors),t.put("pieSizes",e.sizes),e.opacities!==null&&t.put("pieOpacities",e.opacities);const n=t.word("_pieSize"),i=pc(n)?.[1]==="px"?Ua(n,null):null,r=i===null?Ga(n):i/Math.min(t.w,t.h);r!==null&&t.put("pieRadius",sl(r));const s=Ga(t.word("_pieHole"));s!==null&&s>=0&&s<=1&&t.put("pieHole",s);const o=vJ(t.word("_pieStart"));o!==null&&t.put("pieRotation",o)}function MJ(t,e){t.put("stripeColors",e.colors),t.put("stripeSizes",e.sizes),e.opacities!==null&&t.put("stripeOpacities",e.opacities),t.word("_stripeDir")==="righward"&&t.put("stripeDirection","right");const n=Ga(t.word("_stripeSize"));n!==null&&n>=0&&t.put("stripeSize",n)}const gp=["rectangle","roundrectangle","round-rectangle","cutrectangle","cut-rectangle","bottomroundrectangle","bottom-round-rectangle","barrel","ellipse","triangle","round-triangle","square","pentagon","round-pentagon","hexagon","round-hexagon","concavehexagon","concave-hexagon","heptagon","round-heptagon","octagon","round-octagon","tag","round-tag","star","diamond","round-diamond","vee","rhomboid","right-rhomboid","polygon"],qc=["tee","triangle","triangle-tee","circle-triangle","triangle-cross","triangle-backcurve","vee","square","circle","diamond","chevron","none"],UJ=["normal","bold","bolder","lighter","100","200","300","400","500","600","800","900",100,200,300,400,500,600,700,800,900],kD=["bezier","unbundled-bezier","haystack","segments","straight","straight-triangle","taxi","round-segments","round-taxi"],GJ=new Set(["haystack","straight","straight-triangle","segments","taxi","round-segments","round-taxi"]),RD=[["label",{property:"label",type:"text"}],["color",{property:"labelColor",type:"color"}],["font-size",{property:"labelSize",type:"size"}],["font-family",{property:"labelFont",type:"fontFamily"}],["font-weight",{property:"labelWeight",type:"fontWeight"}],["font-style",{property:"labelItalic",type:"enum",enums:["italic","normal","oblique"]}],["visibility",{property:"_visibility",type:"enum",enums:["hidden","visible"]}],["display",{property:"_display",type:"enum",enums:["element","none"]}],["opacity",{property:"opacity",type:"zeroOne"}],["text-transform",{property:"_transform",type:"enum",enums:["none","uppercase","lowercase"]}],["text-wrap",{property:"_wrap",type:"enum",enums:["none","wrap","ellipsis"]}],["text-overflow-wrap",{property:"_overflowWrap",type:"enum",enums:["whitespace","anywhere"]}],["text-justification",{property:"_justification",type:"enum",enums:["auto","left","center","right"]}],["text-max-width",{property:"_maxWidth",type:"size"}],["text-outline-color",{property:"_outlineColor",type:"color"}],["text-outline-width",{property:"_outlineWidth",type:"size"}],["text-outline-opacity",{property:"_outlineOpacity",type:"zeroOne"}],["text-background-color",{property:"_backgroundColor",type:"color"}],["text-background-opacity",{property:"_backgroundOpacity",type:"zeroOne"}],["text-background-padding",{property:"_backgroundPadding",type:"size"}],["text-background-shape",{property:"_backgroundShape",type:"enum",enums:["rectangle","round-rectangle","roundrectangle","circle"]}],["text-rotation",{property:"_rotation",type:"text"}],["text-opacity",{property:"_textOpacity",type:"zeroOne"}],["text-margin-x",{property:"labelOffsetX",type:"signedSize"}],["text-margin-y",{property:"labelOffsetY",type:"signedSize"}],["text-border-color",{property:"_textBorderColor",type:"color"}],["text-border-width",{property:"_textBorderWidth",type:"size"}],["text-border-opacity",{property:"_textBorderOpacity",type:"zeroOne"}],["text-border-style",{property:"_textBorderStyle",type:"enum",enums:["solid","dotted","dashed","double"]}]],jJ=["to-bottom","to-top","to-left","to-right","to-bottom-right","to-bottom-left","to-top-right","to-top-left","to-right-bottom","to-left-bottom","to-right-top","to-left-top"],FJ=16;function zJ(t){const e=t.trim().split(/[\s,]+/).map(Number);if(e.length<6||e.length%2!==0||!e.every(i=>Number.isFinite(i)))return null;const n=[];for(let i=0;i<e.length;i+=2)n.push(`${String(ol(e[i]))},${String(ol(-e[i+1]))}`);return n.join(" ")}function WJ(t){const e=t.trim().split(/[\s,]+/).map(Number);if(e.length<6||e.length%2!==0||!e.every(i=>Number.isFinite(i)))return null;const n=[];for(let i=0;i<e.length;i+=2)n.push(`${String(ol(e[i]))} ${String(ol(-e[i+1]))}`);return n.join(" ")}const ol=t=>Math.round(t*1e6)/1e6+0;function cO(){const t=Array.from({length:7},(s,o)=>{const l=Math.PI/2+2*Math.PI*o/7;return[Math.cos(l),Math.sin(l)]}),[e,n]=[Math.min(...t.map(([s])=>s)),Math.max(...t.map(([s])=>s))],[i,r]=[Math.min(...t.map(([,s])=>s)),Math.max(...t.map(([,s])=>s))];return t.map(([s,o])=>`${ol(2*(s-e)/(n-e)-1)},${ol(2*(o-i)/(r-i)-1)}`).join(" ")}const LD=new Map([["heptagon",cO()],["round-heptagon",cO()],["tag","-1,-1 0.25,-1 1,0 0.25,1 -1,1"],["round-tag","-1,-1 0.25,-1 1,0 0.25,1 -1,1"]]),BJ=new Set(["round-triangle","round-diamond","round-pentagon","round-hexagon","round-octagon"]);function PD(t){const{shape:e}=t,n=r=>typeof r=="string"&&r.startsWith("other:")?LD.get(r.slice(6)):void 0;if(Array.isArray(e)){const r=e;if(!r.some(o=>n(o)!==void 0))return;const s=Array.isArray(t.shapePoints)?[...t.shapePoints]:new Array(r.length).fill(null);t.shape=r.map((o,l)=>{const a=n(o);return a===void 0?o:(s[l]=a,dO(o))}),t.shapePoints=s;return}const i=n(e);i!==void 0&&(t.shape=dO(e),t.shapePoints=i)}function dO(t){return typeof t=="string"&&t.startsWith("other:round-")?"other:round-polygon":"polygon"}const HJ=new Map([["solid","none"],["linear-gradient","linear"],["radial-gradient","radial"]]);function VJ(t){const e=new Array(t.length+1).fill(!1);for(let s=t.length-1;s>=0;s--)e[s]=t[s]===")"||t[s]!=="("&&e[s+1];const n=[];let i=0,r=0;for(;r<t.length;){if(!/\s/.test(t[r])){r++;continue}let s=r+1;for(;s<t.length&&/\s/.test(t[s]);)s++;e[s]||(n.push(t.slice(i,r)),i=s),r=s}return n.push(t.slice(i)),n}function xD(t,e){const n=[];for(const i of VJ(t.trim())){const r=i===""?null:ve(i,"css",e);if(r===null)return;n.push(r.color)}return n.join(" ")}function YJ(t,e){return xD(t,e)?.split(" ")??[]}function MD(t){const e=t.trim().split(/\s+/).map(n=>n.endsWith("%")?Number.parseFloat(n)/100:Number.parseFloat(n));return e.every(n=>Number.isFinite(n))?e.map(n=>P(n)).join(" "):void 0}const KJ=new Set(["fanSpacing","outerBorderOffset"]),n0=new Map([["background-color",{property:"fill",type:"color"}],["background-opacity",{property:"fillOpacity",type:"zeroOne"}],["border-color",{property:"borderColor",type:"color"}],["border-opacity",{property:"_ringOpacity",type:"zeroOne"}],["border-width",{property:"borderWidth",type:"size"}],["border-style",{property:"borderStyle",type:"enum",enums:["solid","dotted","dashed","double"]}],["border-dash-pattern",{property:"_dashPattern",type:"text"}],["border-cap",{property:"_dashCap",type:"enum",enums:["butt","round","square"]}],["border-position",{property:"borderPosition",type:"enum",enums:["center","inside","outside"]}],["outline-color",{property:"outerBorderColor",type:"color"}],["outline-opacity",{property:"_outlineRingOpacity",type:"zeroOne"}],["outline-width",{property:"outerBorderWidth",type:"size"}],["outline-style",{property:"outerBorderStyle",type:"enum",enums:["solid","dotted","dashed","double"]}],["outline-offset",{property:"outerBorderOffset",type:"size"}],["underlay-color",{property:"underlayColor",type:"color"}],["underlay-opacity",{property:"underlayOpacity",type:"zeroOne"}],["underlay-padding",{property:"underlayPadding",type:"size"}],["underlay-shape",{property:"underlayShape",type:"enum",enums:gp}],["underlay-corner-radius",{property:"underlayCornerRadius",type:"size"}],["overlay-color",{property:"overlayColor",type:"color"}],["overlay-opacity",{property:"overlayOpacity",type:"zeroOne"}],["overlay-padding",{property:"overlayPadding",type:"size"}],["overlay-shape",{property:"overlayShape",type:"enum",enums:gp}],["overlay-corner-radius",{property:"overlayCornerRadius",type:"size"}],["shape",{property:"shape",type:"enum",enums:gp}],["shape-polygon-points",{property:"shapePoints",type:"text"}],["corner-radius",{property:"cornerRadius",type:"size"}],["width",{property:"width",type:"nodeSize"}],["height",{property:"height",type:"nodeSize"}],["padding",{property:"_padding",type:"text"}],["padding-relative-to",{property:"_paddingOf",type:"enum",enums:["width","height","average","min","max"]}],["min-width",{property:"_minWidth",type:"text"}],["min-height",{property:"_minHeight",type:"text"}],["min-width-bias-left",{property:"_biasLeft",type:"text"}],["min-width-bias-right",{property:"_biasRight",type:"text"}],["min-height-bias-top",{property:"_biasTop",type:"text"}],["min-height-bias-bottom",{property:"_biasBottom",type:"text"}],["compound-sizing-wrt-labels",{property:"_compoundLabels",type:"enum",enums:["include","exclude"]}],["text-valign",{property:"_valign",type:"enum",enums:["top","top-inside","center","bottom","bottom-inside"]}],["text-halign",{property:"_halign",type:"enum",enums:["left","left-inside","center","right","right-inside"]}],["background-fill",{property:"_backgroundFill",type:"enum",enums:["solid","linear-gradient","radial-gradient"]}],["background-gradient-stop-colors",{property:"_backgroundStops",type:"text"}],["background-gradient-stop-positions",{property:"_backgroundPositions",type:"text"}],["background-gradient-direction",{property:"_backgroundDirection",type:"enum",enums:jJ}],...IJ,...RD]),i0=new Map([["line-color",{property:"color",type:"color"}],["width",{property:"width",type:"nodeSize"}],["line-style",{property:"lineStyle",type:"enum",enums:["solid","dotted","dashed"]}],["line-dash-pattern",{property:"_dashPattern",type:"text"}],["line-cap",{property:"_dashCap",type:"enum",enums:["butt","round","square"]}],["line-opacity",{property:"_lineOpacity",type:"zeroOne"}],["line-outline-width",{property:"outlineWidth",type:"size"}],["line-fill",{property:"gradientKind",type:"enum",enums:["solid","linear-gradient","radial-gradient"]}],["line-gradient-stop-colors",{property:"gradientColors",type:"text"}],["line-gradient-stop-positions",{property:"gradientStops",type:"text"}],["line-outline-color",{property:"outlineColor",type:"color"}],["underlay-color",{property:"underlayColor",type:"color"}],["underlay-opacity",{property:"underlayOpacity",type:"zeroOne"}],["underlay-padding",{property:"underlayPadding",type:"size"}],["overlay-color",{property:"overlayColor",type:"color"}],["overlay-opacity",{property:"overlayOpacity",type:"zeroOne"}],["overlay-padding",{property:"overlayPadding",type:"size"}],["target-arrow-shape",{property:"targetArrow",type:"enum",enums:qc}],["source-arrow-shape",{property:"sourceArrow",type:"enum",enums:qc}],["target-arrow-color",{property:"targetArrowColor",type:"color"}],["source-arrow-color",{property:"sourceArrowColor",type:"color"}],["mid-target-arrow-shape",{property:"midTargetArrow",type:"enum",enums:qc}],["mid-source-arrow-shape",{property:"midSourceArrow",type:"enum",enums:qc}],["mid-target-arrow-color",{property:"midTargetArrowColor",type:"color"}],["mid-source-arrow-color",{property:"midSourceArrowColor",type:"color"}],["target-arrow-fill",{property:"_targetArrowFill",type:"enum",enums:["filled","hollow"]}],["source-arrow-fill",{property:"_sourceArrowFill",type:"enum",enums:["filled","hollow"]}],["mid-target-arrow-fill",{property:"_midTargetArrowFill",type:"enum",enums:["filled","hollow"]}],["mid-source-arrow-fill",{property:"_midSourceArrowFill",type:"enum",enums:["filled","hollow"]}],["curve-style",{property:"curved",type:"enum",enums:kD}],["segment-distances",{property:"_segmentDistances",type:"text"}],["segment-weights",{property:"_segmentWeights",type:"text"}],["control-point-distances",{property:"_controlPointDistances",type:"text"}],["control-point-weights",{property:"_controlPointWeights",type:"text"}],["taxi-direction",{property:"_taxiDirection",type:"text"}],["taxi-turn",{property:"_taxiTurn",type:"text"}],["taxi-turn-min-distance",{property:"_taxiTurnMinDistance",type:"size"}],["edge-distances",{property:"_edgeDistances",type:"text"}],["loop-direction",{property:"_loopDirection",type:"text"}],["loop-sweep",{property:"_loopSweep",type:"text"}],["segment-radii",{property:"_segmentRadii",type:"text"}],["taxi-radius",{property:"_taxiRadius",type:"text"}],["radius-type",{property:"_radiusType",type:"text"}],["source-endpoint",{property:"_sourceEndpoint",type:"text"}],["target-endpoint",{property:"_targetEndpoint",type:"text"}],["source-distance-from-node",{property:"sourceNodeGap",type:"size"}],["target-distance-from-node",{property:"targetNodeGap",type:"size"}],["control-point-step-size",{property:"fanSpacing",type:"size"}],["arrow-scale",{property:"arrowSize",type:"positive"}],["source-label",{property:"sourceLabel",type:"text"}],["target-label",{property:"targetLabel",type:"text"}],["source-text-offset",{property:"sourceLabelOffset",type:"size"}],["target-text-offset",{property:"targetLabelOffset",type:"size"}],["source-text-margin-x",{property:"sourceLabelOffsetX",type:"signedSize"}],["source-text-margin-y",{property:"sourceLabelOffsetY",type:"signedSize"}],["target-text-margin-x",{property:"targetLabelOffsetX",type:"signedSize"}],["target-text-margin-y",{property:"targetLabelOffsetY",type:"signedSize"}],["source-text-rotation",{property:"_sourceRotation",type:"text"}],["target-text-rotation",{property:"_targetRotation",type:"text"}],...RD]);function Kf(t){return t==="node"?n0:i0}const XJ=new Map([["content","label"],["control-point-distance","control-point-distances"],["control-point-weight","control-point-weights"],["segment-distance","segment-distances"],["segment-weight","segment-weights"],["segment-radius","segment-radii"],["edge-text-rotation","text-rotation"],["padding-left","padding"],["padding-right","padding"],["padding-top","padding"],["padding-bottom","padding"]]);function UD(t){return XJ.get(t)??t}function r0(t){return UD(t.replaceAll(/[A-Z]/g,e=>`-${e.toLowerCase()}`))}const yr="throws",lt=String.raw`[-+]?(?:(?:\d+|\d*\.\d+)(?:[Ee][+-]?\d+)?)`,qJ=new RegExp(`^(${lt})(px|em)?$`),uO=new RegExp(String.raw`^\s*${lt}\s*$`),JJ=new RegExp(String.raw`^rgb[a]?\((${lt}[%]?)\s*,\s*(${lt}[%]?)\s*,\s*(${lt}[%]?)(?:\s*,\s*(${lt}))?\)$`),ZJ=new RegExp(String.raw`^hsl[a]?\((${lt})\s*,\s*(${lt}[%])\s*,\s*(${lt}[%])(?:\s*,\s*(${lt}))?\)$`),fO=new RegExp(String.raw`^(?:${lt}|\w+|rgb[a]?\((?:${lt}[%]?)\s*,\s*(?:${lt}[%]?)\s*,\s*(?:${lt}[%]?)(?:\s*,\s*(?:${lt}))?\)`+String.raw`|hsl[a]?\((?:${lt})\s*,\s*(?:${lt}[%])\s*,\s*(?:${lt}[%])(?:\s*,\s*(?:${lt}))?\)`+String.raw`|\#[0-9a-fA-F]{3}|\#[0-9a-fA-F]{6})$`),QJ=/^[\w.]+$/,eZ=/^[\w\- "]$/;function tZ(t){return t==="transparent"?"#000000":t==="rebeccapurple"?void 0:Sl.get(t)}function nZ(t){const e=tZ(t.toLowerCase());if(e!==void 0)return[Number.parseInt(e.slice(1,3),16),Number.parseInt(e.slice(3,5),16),Number.parseInt(e.slice(5,7),16)];if((t.length===4||t.length===7)&&t.startsWith("#")){const i=t.length===4,r=s=>Number.parseInt(i?t[s]+t[s]:t.slice(2*s-1,2*s+1),16);return[r(1),r(2),r(3)]}const n=JJ.exec(t);return n===null?rZ(t):iZ(n)}function iZ(t){const e=[1,2,3].map(r=>t[r].endsWith("%"));if(e.some(Boolean)&&!e.every(Boolean))return null;const n=[1,2,3].map(r=>{const s=Number.parseFloat(t[r]);return e[r-1]?s/100*255:s});if(n.some(r=>r<0||r>255))return null;const i=t.at(4);return i!==void 0&&(Number.parseFloat(i)<0||Number.parseFloat(i)>1)?null:[Math.floor(n[0]),Math.floor(n[1]),Math.floor(n[2])]}function rZ(t){const e=ZJ.exec(t);if(e===null)return null;let n=Number.parseInt(e[1],10);n<0?n=(360- -1*n%360)%360:n>360&&(n=n%360),n/=360;const i=Number.parseFloat(e[2]),r=Number.parseFloat(e[3]);if(i<0||i>100||r<0||r>100)return null;const s=e.at(4);if(s!==void 0&&(Number.parseFloat(s)<0||Number.parseFloat(s)>1))return null;const o=i/100,l=r/100;if(o===0){const u=Math.round(l*255);return[u,u,u]}const a=(u,f,h)=>{let p=h;return p<0&&(p+=1),p>1&&(p-=1),p<1/6?u+(f-u)*6*p:p<1/2?f:p<2/3?u+(f-u)*(2/3-p)*6:u},c=l<.5?l*(1+o):l+o-l*o,d=2*l-c;return[Math.round(255*a(d,c,n+1/3)),Math.round(255*a(d,c,n)),Math.round(255*a(d,c,n-1/3))]}function GD(t){const e=t.split(",");return e.length===1?e[0].length>0&&qf(e[0],Xf):sZ(e[0])&&oZ(e.at(-1)??"")&&e.slice(1,-1).every(n=>lZ(n))}function Xf(t){return eZ.test(t)}function Pu(t){return/\s/.test(t)}function qf(t,e){return Array.from(t).every(e)}function sZ(t){let e=0;for(;e<t.length&&Xf(t[e]);)e++;return e>0&&qf(t.slice(e),Pu)}function oZ(t){let e=t.length;for(;e>0&&Xf(t[e-1]);)e--;return e<t.length&&qf(t.slice(0,e),Pu)}function lZ(t){let e=0,n=t.length;for(;e<n&&Pu(t[e]);)e++;for(;n>e&&Pu(t[n-1]);)n--;return e===n?t.includes(" "):qf(t.slice(e,n),Xf)}function Us(t,e,n=!1){const i=typeof e=="string"?e.trim():e;switch(t.type){case"color":return aZ(i);case"zeroOne":case"positive":{const r=Number.parseFloat(String(i));return(t.type==="zeroOne"?r>=0&&r<=1:r>0)?{kind:"number",value:r,units:null,str:String(r)}:null}case"size":case"signedSize":case"nodeSize":return cZ(t,i,e);case"text":return{kind:"word",value:String(i),str:String(i)};case"fontFamily":{const r=String(i);return GD(r)?{kind:"word",value:r,str:r}:null}case"fontWeight":case"enum":{const s=(t.type==="fontWeight"?UJ:t.enums??[]).find(o=>o===i||n&&String(o)===i);return s===void 0?null:{kind:"word",value:s,str:String(s)}}default:return null}}function aZ(t){if(Array.isArray(t)){const[n,i,r]=t,s=[Number(n),Number(i),Number(r)];return{kind:"color",rgb:s,str:`rgb(${s[0]},${s[1]},${s[2]})`}}if(typeof t!="string")return yr;const e=nZ(t);return e===null?null:{kind:"color",rgb:e,str:`rgb(${e[0]},${e[1]},${e[2]})`}}function cZ(t,e,n){let i="px",r=e;if(typeof e=="string"){const o=qJ.exec(e);o===null?i=null:(r=o[1],i=o.at(2)==="em"?"em":"px")}const s=Number.parseFloat(String(r));return Number.isNaN(s)?t.type==="nodeSize"&&n==="label"?{kind:"word",value:"label",str:"label"}:null:s<0&&t.type!=="signedSize"?null:{kind:"number",value:s,units:i,str:`${String(s)}${i??""}`}}function dZ(t){const e=[];let n=0,i=0;for(let r=0;r<t.length;r++){const s=t[r];s==="("?n++:s===")"?n--:s===","&&n===0&&(e.push(t.slice(i,r)),i=r+1)}return e.push(t.slice(i)),e}function jD(t,e){if(!t.startsWith(e)||!t.endsWith(")"))return null;let n=e.length;for(;n<t.length&&/\s/.test(t[n]);)n++;return t[n]==="("?t.slice(n+1,-1):null}function s0(t,e,n){if(e===void 0)return null;if(typeof e=="function")return n==="flat"?null:{kind:"fn"};const i=typeof e=="string"?e.trim():e;if(n!=="flat"&&typeof i=="string"&&i.length>=7&&i[1]==="a"){const r=uZ(t,i,n);if(r!==void 0)return r}return Us(t,e)}function uZ(t,e,n){if(e.startsWith("d")){const i=jD(e,"data")?.trim();return i===void 0||!QJ.test(i)?void 0:n==="bypass"?null:{kind:"data",field:i}}if(!(!e.startsWith("m")||e.length<10))return fZ(t,e,n)}function fZ(t,e,n){const i=jD(e,"mapData");if(i===null)return;const r=dZ(i);if(!hZ(r))return;if(n==="bypass")return null;const s=t.type==="zeroOne"||t.type==="positive"||t.type==="size"||t.type==="signedSize"||t.type==="nodeSize";if(t.type!=="color"&&!s)return null;const o=Us(t,r[3].trim()),l=Us(t,r[4].trim());if(o===null||l===null||o===yr||l===yr)return null;if(o.str===l.str||o.kind==="number"&&l.kind==="number"&&hO(o)===hO(l)){const a=Us(t,o.str);return a===yr?null:a}return{kind:"mapData",field:r[0].trim(),fieldMin:Number.parseFloat(r[1]),fieldMax:Number.parseFloat(r[2]),min:o,max:l}}function hZ(t){return t.length===5&&/^[\w.]+\s*$/.test(t[0])&&uO.test(t[1])&&uO.test(t[2])&&fO.test(t[3].trim())&&fO.test(t[4].replace(/^\s+/,""))}function hO(t){return t.value}function pZ(t,e){let n=t;for(const i of e.split(".")){if(!n)break;n=n[i]}return n}function gZ(t,e,n){const i=pZ(n,e.field);if(i==null)return null;if(e.kind==="data")return Us(t,i);if(typeof i!="number"||Number.isNaN(i))return null;const r=e.fieldMax-e.fieldMin,s=Math.min(1,Math.max(0,r===0?0:(i-e.fieldMin)/r)),{min:o,max:l}=e;if(o.kind==="color"&&l.kind==="color"){const a=[0,1,2].map(c=>Math.round(o.rgb[c]+(l.rgb[c]-o.rgb[c])*s));return{kind:"color",rgb:a,str:`rgb(${a[0]}, ${a[1]}, ${a[2]})`}}return o.kind==="number"&&l.kind==="number"?Us(t,o.value+(l.value-o.value)*s):null}function mZ(t,e){if(t.rgb.some(n=>!Number.isFinite(n)||n<0||n>255)){e.notes.add(v.BAD_VALUE,e.target,e.property,{sample:t.str,element:e.element});return}return`#${t.rgb.map(n=>Math.round(n).toString(16).padStart(2,"0")).join("")}`}function ja(t,e,n){switch(e.kind){case"color":return mZ(e,n);case"number":return P((KJ.has(t.property)?e.value/2:e.value)*(e.units==="em"?FJ:1))}const i=e.value;switch(t.property){case"width":case"height":n.target==="edge"&&n.notes.add(v.BAD_VALUE,n.target,n.property,{sample:e.str,element:n.element});return;case"label":case"sourceLabel":case"targetLabel":case"labelFont":return String(i);case"gradientKind":return HJ.get(String(i))??void 0;case"gradientColors":return xD(String(i),n);case"gradientStops":return MD(String(i));case"labelItalic":return i==="italic"||i==="oblique";case"curved":return!GJ.has(String(i));case"shapePoints":return zJ(String(i))??void 0;case"underlayShape":case"overlayShape":return le("shape",String(i),"cytoscape-js",n)??void 0;case"shape":{const r=String(i).toLowerCase();return r==="polygon"?"polygon":LD.has(r)||BJ.has(r)?`other:${r}`:le("shape",String(i),"cytoscape-js",n)??void 0}case"borderStyle":return le("borderStyle",String(i),"cytoscape-js",n)??void 0;case"outerBorderStyle":return i==="double"?"solid":le("borderStyle",String(i),"cytoscape-js",n)??void 0;case"lineStyle":return le("lineStyle",String(i),"cytoscape-js",n)??void 0;case"sourceArrow":case"targetArrow":case"midSourceArrow":case"midTargetArrow":return le("arrow",String(i),"cytoscape-js",n)??void 0;case"labelWeight":return le("weight",String(i),"cytoscape-js",n)??void 0;default:return i}}function yZ(t,e,n,i){const r=Kf(t).get(r0(e));if(r===void 0||typeof n!="string")return null;const s=Us(r,n,!0);return s===null||s===yr?null:ja(r,s,i)}function bZ(t,e,n){const i=t.length%2===1?[...t,...t]:[...t],r=n==="butt"?0:e,s=i.filter((a,c)=>c%2===0).map(a=>Math.max(0,a)+r),o=i.filter((a,c)=>c%2===1).map(a=>Math.max(0,a-r)),l=a=>a.reduce((c,d)=>c+d,0);return l(o)<=.1*(l(s)+l(o))?"solid":s.every(a=>a<=Math.max(1,e)*1.5)?"dotted":Math.max(...s)>=2*Math.min(...s)?"dash-dot":"dashed"}function Io(t){const e=t.trim().split(/\s+/).map(n=>Number.parseFloat(n));return e.every(n=>Number.isFinite(n))?e:[]}function pO(t){const e=t.trim(),n=Number.parseFloat(e);return e.endsWith("deg")?n*Math.PI/180:n}function ll(t,e){const[n,i]=t.center,r=e[0]-n,s=e[1]-i,[o,l]=[t.size[0]/2,t.size[1]/2];if(r===0&&s===0||o<=0||l<=0)return t.center;const a=t.ellipse?1/Math.hypot(r/o,s/l):Math.min(gO(r,o),gO(s,l));return[n+r*a,i+s*a]}function gO(t,e){return t===0?1/0:e/Math.abs(t)}function mO(t,e,n){const i=ll(e,n.center),r=ll(n,e.center),s=r[0]-i[0],o=r[1]-i[1],l=Math.hypot(s,o)||1,a=[-o/l,s/l];return t.edgeDistances==="node-position"?{a:e.center,b:n.center,normal:a}:{a:i,b:r,normal:a}}function yO(t,e,n){const i=Math.min(e.length,n.length);return Array.from({length:i},(r,s)=>{const o=e[s],l=n[s];return[t.a[0]*(1-o)+t.b[0]*o+t.normal[0]*l,t.a[1]*(1-o)+t.b[1]*o+t.normal[1]*l]})}function EZ(t,e,n){const i=t.edgeDistances!=="node-position",[r,s]=e.center,[o,l]=n.center,[a,c]=e.size,[d,u]=n.size,f=o-r,h=l-s,p=bO(f,i?(a+d)/2:0),g=bO(h,i?(c+u)/2:0),m=t.taxiDirection??"auto",y=m==="auto"?Math.abs(p)<=Math.abs(g):m==="vertical"||m==="upward"||m==="downward",[b,_]=y?[g,h]:[p,f],{d:S,l:T,sgn:$,forced:D}=wZ(t,m,b,_),x=t.taxiTurnMinDistance??10,R=be=>Math.abs(be)<x||Math.abs(be)>=Math.abs(T);if((R(S)||R(Math.abs(T)-Math.abs(S)))&&!D)return SZ(y,{x1:r,y1:s,x2:o,y2:l,pl:_,pdx:f,pdy:h},e.size,n.size);const B=i?(y?c:a)/2*$:0;if(y){const be=s+S+B;return[[r,be],[o,be]]}const Q=r+S+B;return[[Q,s],[Q,l]]}function bO(t,e){return t>0?Math.max(t-e,0):Math.min(t+e,0)}function wZ(t,e,n,i){const r=e!=="auto"&&e!=="vertical"&&e!=="horizontal",s=(t.taxiTurn??"50%").trim(),o=s.endsWith("%"),l=o?Number.parseFloat(s)/100:Number.parseFloat(s),a=!(r&&(o||l<0))&&_Z(e,i),c=a?-Math.sign(i):Math.sign(i),d=a?c*Math.abs(n):n;return o?{d:(l<0?1+l:l)*d,l:d,sgn:c,forced:a}:{d:(l<0?d:0)+l*c,l:d,sgn:c,forced:a}}function _Z(t,e){return t==="downward"&&e<0||t==="upward"&&e>0||t==="leftward"&&e>0||t==="rightward"&&e<0}function SZ(t,e,n,i){const{x1:r,y1:s,x2:o,y2:l,pl:a,pdx:c,pdy:d}=e,u=(r+o)/2,f=(s+l)/2;return t?Math.abs(a)<=n[1]/2?[[u,s],[u,l]]:Math.abs(c)<=i[0]/2?[[r,f],[o,f]]:[[r,l]]:Math.abs(a)<=n[0]/2?[[r,f],[o,f]]:Math.abs(d)<=i[1]/2?[[u,s],[u,l]]:[[o,s]]}function FD(t,e,n){const i=ll(t,n[0]),r=ll(e,n.at(-1)??e.center);return K1([i,...n,r],0).slice(1,-1)}function OZ(t,e,n,i){const r=t.curveStyle;if(r==="haystack")return null;if(e===n)return AZ(t,e,i);let s=[];if(r.endsWith("segments")){const o=Io(t.segmentDistances??"20"),l=Io(t.segmentWeights??"0.5");s=yO(mO(t,e,n),l,o)}else if(r.endsWith("taxi"))s=EZ(t,e,n);else if(r==="unbundled-bezier"){const o=Io(t.controlPointDistances??String(t.controlPointStepSize??40)),l=Io(t.controlPointWeights??"0.5"),a=yO(mO(t,e,n),l,o);s=a.length===0?[]:FD(e,n,a)}if(s.length>0&&r.startsWith("round-")){const o=Io((r==="round-taxi"?t.taxiRadius:t.segmentRadii)??"15"),l=(t.radiusType??"arc-radius").trim().split(/\s+/),a=ll(e,s[0]),c=ll(n,s.at(-1)??n.center);s=NZ([a,...s,c],o,l).slice(1,-1)}return s.length===0?null:Al(e.center,n.center,s,!0)}const EO=8;function NZ(t,e,n){const i=[t[0]];for(let r=1;r<t.length-1;r++){const[s,o,l]=[t[r],t[r-1],t[r+1]],a=e[Math.min(r-1,e.length-1)]??15,c=(n[Math.min(r-1,n.length-1)]??"arc-radius")!=="influence-radius",d=Math.hypot(o[0]-s[0],o[1]-s[1]),u=Math.hypot(l[0]-s[0],l[1]-s[1]),f=[(o[0]-s[0])/d,(o[1]-s[1])/d],h=[(l[0]-s[0])/u,(l[1]-s[1])/u],p=Math.acos(Math.max(-1,Math.min(1,f[0]*h[0]+f[1]*h[1]))),g=p/2;if(!(a>0&&d>0&&u>0)||Math.abs(Math.PI-p)<1e-6){i.push(s);continue}const y=Math.min(d/2,u/2),b=Math.min(y,c?a/Math.tan(g):a),_=b*Math.tan(g),S=[f[0]+h[0],f[1]+h[1]],T=Math.hypot(S[0],S[1]),$=Math.hypot(b,_),D=[s[0]+S[0]/T*$,s[1]+S[1]/T*$],x=Math.atan2(s[1]+f[1]*b-D[1],s[0]+f[0]*b-D[0]);let G=Math.atan2(s[1]+h[1]*b-D[1],s[0]+h[0]*b-D[0])-x;G-=2*Math.PI*Math.round(G/(2*Math.PI));for(let B=0;B<=EO;B++){const Q=x+G*B/EO;i.push([D[0]+Math.cos(Q)*_,D[1]+Math.sin(Q)*_])}}return i.push(t.at(-1)??t[0]),i}function AZ(t,e,n){const r=t.curveStyle==="unbundled-bezier"?Io(t.controlPointDistances??"").at(0)??Number.NaN:t.controlPointStepSize??40,s=pO(t.loopDirection??"-45deg"),o=pO(t.loopSweep??"-90deg");if(!Number.isFinite(r+s+o))return null;const l=s-Math.PI/2,a=1.4*r*(n/3+1),[c,d]=e.center,u=h=>[c+Math.cos(h)*a,d+Math.sin(h)*a],f=FD(e,e,[u(l-o/2),u(l+o/2)]);return Hs(e.center,e.box,f,!0)}const TZ=new Set(["selected","unselected","selectable","unselectable","locked","unlocked","visible","hidden","transparent","grabbed","free","removed","inside","grabbable","ungrabbable","animated","unanimated","parent","childless","child","orphan","nonorphan","compound","loop","simple","active","inactive","backgrounding","nonbackgrounding"]),IZ=1<<22,zD=new Set("!\"#$%&'()*+,./:;<=>?@[]^`{|}~"),$Z=["!=",">=","<=","*=","^=","$=","=",">","<"],CZ=["indegree","outdegree","degree"];function vZ(t){if(t===void 0)return!1;const e=t.codePointAt(0)??0;return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95}function DZ(t){return t!==void 0&&/\s/.test(t)}class kZ{constructor(e){this.text=e,this.pos=0}spaceEnd(e){let n=e;for(;n<this.text.length&&DZ(this.text[n]);)n++;return n}name(e,n){let i=e;const r=this.text;for(;i<r.length;){const s=r[i];if(vZ(s)||s==="-"||n&&s===".")i++;else if(s==="\\"&&i+1<r.length&&zD.has(r[i+1]))i+=2;else break}return i>e?{raw:r.slice(e,i),end:i}:null}numberEnds(e){const n=this.text;let i=e;(n[i]==="+"||n[i]==="-")&&i++;const r=a=>{let c=a;for(;c<n.length&&n[c]>="0"&&n[c]<="9";)c++;return c},s=[],o=r(i);if(o>i&&s.push(o),n[o]==="."){const a=r(o+1);a>o+1&&s.unshift(a)}const l=[];for(const a of s){if(n[a]==="e"||n[a]==="E"){let c=a+1;(n[c]==="+"||n[c]==="-")&&c++;const d=r(c);d>c&&l.push(d)}l.push(a)}return l}stringEnds(e){const n=this.text,i=n[e],r=[];for(let s=e+1;s<n.length&&!(n[s]===i&&(r.push(s+1),n[s-1]!=="\\"||s-1===e));s++);return r.reverse()}op(e){const n=this.text;let i=e,r="";n[i]==="!"&&n[i+1]!=="="&&(r+="!",i++),n[i]==="@"&&(r+="@",i++);for(const s of $Z)if(n.startsWith(s,i))return r.includes("!")&&s==="!="?null:{text:r+s,end:i+s.length};return null}}function o0(t){let e="",n=0;for(;n<t.length;){const i=t[n]==="\\"&&n+1<t.length&&zD.has(t[n+1]);e+=i?t[n+1]:t[n],n+=i?2:1}return e}function WD(t){let e=t,n=!1,i=!1;return e.includes("!")&&(e=e.replace("!",""),n=!0),e.includes("@")&&(e=e.replace("@",""),i=!0),{op:e,not:n,ci:i}}function oa(t,e){t.queries[t.queries.length-1]=e}function mm(t){return t.queries.at(-1)}function wO(t){return(e,n)=>{if(e.subject===null){const s={checks:[]},o={checks:[]},l=mm(e);return s.checks.push(t==="child"?{type:"child",parent:l,child:o}:{type:"descendant",ancestor:l,descendant:o}),oa(e,s),e.compoundCount++,o}if(e.subject===n){const s={checks:[]},o=mm(e),l={checks:[]},a={checks:n.checks},c={checks:[]},d={checks:[{type:"true"}]};return n.checks=[{type:"true"}],l.checks.push(t==="child"?{type:"parent",parent:d,child:c}:{type:"ancestor",ancestor:d,descendant:c}),s.checks.push({type:"split",left:o,right:l,subject:a}),oa(e,s),e.subject=a,e.compoundCount++,c}const i={checks:n.checks},r={checks:[]};return n.checks=[t==="child"?{type:"parent",parent:i,child:r}:{type:"ancestor",ancestor:i,descendant:r}],e.compoundCount++,r}}function RZ(t){const e=t.text[t.pos];return LZ(t)??(e===":"?PZ(t):null)??(e==="#"||e==="."?xZ(t,e):null)??(e==="["?FZ(t,t.pos):null)??MZ(t)??(e==="$"?GZ(t):null)}function Qs(t,e){return{end:t,fill:(n,i)=>(i.checks.push(e),null)}}function LZ(t){const e=t.pos;for(const[n,i]of[["node","nodes"],["edge","edges"],["*","*"]])if(t.text.startsWith(n,e))return Qs(e+n.length,{type:"group",value:i});return null}function PZ(t){const e=t.pos;let n=null;for(const i of TZ)t.text.startsWith(i,e+1)&&(n===null||i.length>n.length)&&(n=i);return n===null?null:Qs(e+1+n.length,{type:"state",value:n})}function xZ(t,e){const n=t.name(t.pos+1,e==="#");return n===null?null:Qs(n.end,{type:e==="#"?"id":"class",value:o0(n.raw)})}function MZ(t){const e=t.text,n=t.pos,i=t.spaceEnd(n);if(e[i]===",")return{end:t.spaceEnd(i+1),fill:UZ};if(i===n)return null;for(const[r,s]of[["->","directed"],["<->","undirected"],[">","child"]]){const o=e.startsWith(r,i)?t.spaceEnd(i+r.length):-1;if(o>i+r.length)return{end:o,fill:s==="child"?wO("child"):jZ(s)}}return{end:i,fill:wO("descendant")}}function UZ(t){t.counts.push({edgeCount:t.edgeCount,compoundCount:t.compoundCount,subject:t.subject}),t.subject=null,t.edgeCount=0,t.compoundCount=0;const e={checks:[]};return t.queries.push(e),e}function GZ(t){return{end:t.pos+1,fill:(e,n)=>{if(e.subject!==null&&e.subject!==n)return!1;e.subject=n;const i=mm(e),r=i.checks.at(0);return r?.type==="directedEdge"?i.checks[0]={type:"nodeTarget",source:r.source,target:r.target}:r?.type==="undirectedEdge"&&(i.checks[0]={type:"nodeNeighbor",node:r.nodes[1],neighbor:r.nodes[0]}),null}}}function jZ(t){return(e,n)=>{const i={checks:[]},r={checks:[]};return e.subject===null?(r.checks.push(t==="directed"?{type:"directedEdge",source:n,target:i}:{type:"undirectedEdge",nodes:[n,i]}),oa(e,r),e.edgeCount++,i):t==="directed"?(r.checks.push({type:"nodeSource",source:n,target:i}),oa(e,r),e.edgeCount++,i):(r.checks.push({type:"nodeNeighbor",node:n,neighbor:i}),oa(e,r),i)}}function FZ(t,e){const n=t.spaceEnd(e+1);return zZ(t,n)??WZ(t,n)??(t.text[e+1]==="["?BZ(t,e):null)}function zZ(t,e){const n=t.text,i=t.name(e,!0);if(i===null)return null;const r=o0(i.raw),s=t.spaceEnd(i.end);if(n[s]==="]")return Qs(s+1,{type:"exist",field:r});const o=t.op(s);if(o===null)return null;const l=t.spaceEnd(o.end),a=n[l]==='"'||n[l]==="'",c=(a?t.stringEnds(l):t.numberEnds(l)).find(g=>n[t.spaceEnd(g)]==="]");if(c===void 0)return null;const d=n.slice(l,c),u=a?d.slice(1,-1):Number.parseFloat(d),{op:f,not:h,ci:p}=WD(o.text);return Qs(t.spaceEnd(c)+1,{type:"compare",field:r,op:f,not:h,ci:p,value:u})}function WZ(t,e){const n=t.text,i=n[e];if(i!=="?"&&i!=="!"&&i!=="^")return null;const r=t.name(t.spaceEnd(e+1),!0),s=r===null?-1:t.spaceEnd(r.end);return r===null||n[s]!=="]"?null:Qs(s+1,{type:"bool",field:o0(r.raw),op:i})}function BZ(t,e){const n=t.text,i=t.spaceEnd(e+2),r=CZ.find(f=>n.startsWith(f,i)),s=r===void 0?null:t.op(t.spaceEnd(i+r.length));if(r===void 0||s===null)return null;const o=t.spaceEnd(s.end),l=t.numberEnds(o).find(f=>{const h=t.spaceEnd(f);return n[h]==="]"&&n[h+1]==="]"});if(l===void 0)return null;const a=Number.parseFloat(n.slice(o,l)),{op:c,not:d,ci:u}=WD(s.text);return Qs(t.spaceEnd(l)+2,{type:"meta",field:r,op:c,not:d,ci:u,value:a})}function HZ(t){return/^\s*$/.test(t.length>1024?t.slice(0,1024):t)&&t.trim()===""}function xu(t){if(typeof t!="string"||HZ(t))return{queries:[],invalid:!1};if(t.length>IZ)return{queries:[],invalid:!0};const e=new kZ(t),n={checks:[]},i={queries:[n],subject:null,edgeCount:0,compoundCount:0,counts:[]};let r=n;for(e.pos=e.spaceEnd(0);;){const o=RZ(e);if(o===null)return{queries:i.queries,invalid:!0};const l=o.fill(i,r);if(l===!1)return{queries:i.queries,invalid:!0};if(l!==null&&(r=l),e.pos=o.end,e.spaceEnd(e.pos)>=t.length)break}i.counts.push({edgeCount:i.edgeCount,compoundCount:i.compoundCount,subject:i.subject});const s=i.counts.some(o=>o.compoundCount>0&&o.edgeCount>0||o.edgeCount>1);return{queries:i.queries,invalid:s}}const mp=/[\n\r\u2028\u2029]/,l0=/\s/;function VZ(t){let e="",n=0;for(;;){const i=t.indexOf("/*",n);if(i<0)break;const r=t.indexOf("*/",i+3);if(r<0)break;e+=t.slice(n,i),n=r+2}return e+t.slice(n)}function _O(t,e){let n=e;for(;n<t.length&&l0.test(t[n]);)n++;return n}function BD(t){let e=t.length;for(;e>0&&l0.test(t[e-1]);)e--;return t.slice(0,e)}function YZ(t,e,n){const i=t.length,r=n[e],s=t.indexOf(":",r+1);if(s<0)return null;const o=BD(t.slice(r,s));if(o===""||mp.test(o))return null;const l=n[s+1];for(let a=l+1;a<=i&&!mp.test(t[a-1]);a++){const c=n[a];if(c>=i)return{name:o,value:t.slice(l,a),end:i};if(t[c]===";")return{name:o,value:t.slice(l,a),end:c+1}}if(l>=i){for(let a=s+1;a<i;a++)if(!mp.test(t[a]))return{name:o,value:t[a],end:i}}return null}function KZ(t){const e=new Int32Array(t.length+1);e[t.length]=t.length;for(let n=t.length-1;n>=0;n--)e[n]=l0.test(t[n])?e[n+1]:n;return e}function XZ(t){const e=VZ(t),n=[];let i=0;for(;_O(e,i)<e.length;){const r=_O(e,i);let s=e.indexOf("{",r+1),o=r;if(e[r]==="{"&&r>i&&(o=r-1,s=r),s<0)return{entries:n,stop:"NO_BLOCK"};const l=e.indexOf("}",s+2);if(l<0)return{entries:n,stop:"NO_BLOCK"};const a=BD(e.slice(o,s)),c=e.slice(s+1,l);if(i=l+1,a!=="core"&&xu(a).invalid)continue;const d=qZ(c);if(d===null)return{entries:n,stop:"BAD_PROPERTY"};n.push({selector:a,properties:d,dashOnly:!0})}return{entries:n,stop:null}}function qZ(t){const e=[],n=KZ(t);let i=0;for(;n[i]<t.length;){const r=YZ(t,i,n);if(r===null)return null;e.push([r.name,r.value]),i=r.end}return e}function es(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function JZ(t){return typeof t=="number"&&!Number.isNaN(t)?String(t):typeof t=="string"&&t!==""&&!/^\s+$/.test(t)?t:null}function ZZ(t,e){const n=t.pannable===void 0?e:!!t.pannable,i=t.grabbable===void 0?!0:!!t.grabbable;return{selected:!!t.selected,selectable:t.selectable===void 0?!0:!!t.selectable,locked:!!t.locked,grabbable:!n&&i}}function QZ(t){const e=new Set;let n=[];Array.isArray(t)?n=t:typeof t=="string"&&(n=t.split(/\s+/));for(const i of n)i&&e.add(i);return e}function eQ(t,e){const n=new Int32Array(t.length).fill(-1),i=t.map(()=>[]),r=Int32Array.from(t,(o,l)=>l),s=o=>{for(;r[o]!==o;)r[o]=r[r[o]],o=r[o];return o};for(let o=0;o<t.length;o++){const l=t[o].data.parent;if(l==null)continue;const a=typeof l=="number"&&!Number.isNaN(l)?String(l):l,c=typeof a=="string"?e.get(a):void 0;if(c===void 0||c<0){t[o].overrides.set("parent",void 0);continue}if(typeof l=="number"&&t[o].overrides.set("parent",a),s(c)===o){t[o].overrides.set("parent",void 0);continue}n[o]=c,r[o]=c,i[c].push(o)}return{parent:n,children:i}}function tQ(t){const{nodeJson:e,edgeJson:n}=nQ(t),i=new Map,r=rQ(i),s=[];for(const h of e){const p=r(h,!1,new Map);p!==null&&(i.set(p.id,s.length),s.push(p))}const o=[],l=[],a=[],c=new Set;for(const h of n){const p=new Map,g=r(h,!0,p),m=g===null||c.has(g.id)?null:sQ(g,i,p);g!==null&&m!==null&&(c.add(g.id),o.push(g),l.push(m[0]),a.push(m[1]))}for(const h of c)i.set(h,-1);const{parent:d,children:u}=eQ(s,i),f=s.map(()=>[]);for(let h=0;h<o.length;h++)f[l[h]].push(h),l[h]!==a[h]&&f[a[h]].push(h);return{nodes:s,edges:o,source:Int32Array.from(l),target:Int32Array.from(a),parent:d,children:u,incident:f}}function nQ(t){const e=[],n=[],i=(r,s)=>{const o=iQ(r,s);o==="nodes"?e.push(r):o==="edges"&&n.push(r)};if(Array.isArray(t))for(const r of t)i(r,void 0);else if(es(t)){for(const r of Array.isArray(t.nodes)?t.nodes:[])i(r,"nodes");for(const r of Array.isArray(t.edges)?t.edges:[])i(r,"edges")}return{nodeJson:e,edgeJson:n}}function iQ(t,e){if(!es(t))return;const n=t.data??{};if(!es(n))return;const i=e??t.group;return i??(n.source!==void 0&&n.source!==null&&n.target!==void 0&&n.target!==null?"edges":"nodes")}function rQ(t){let e=0;return(n,i,r)=>{const s=es(n.data)?n.data:{};let o;if(s.id===void 0)o=`${String.fromCodePoint(0)}generated-${String(e++)}`,r.set("id",o);else{if(o=JZ(s.id),o===null||t.has(o))return null;typeof s.id=="number"&&r.set("id",o)}return{json:n,data:s,overrides:r,id:o,classes:QZ(n.classes),...ZZ(n,i)}}}function sQ(t,e,n){const i=[];for(const r of["source","target"]){const s=t.data[r],o=typeof s=="number"&&!Number.isNaN(s)?String(s):s;typeof s=="number"&&n.set(r,o);const l=typeof o=="string"?e.get(o):void 0;l!==void 0&&i.push(l)}return i.length===2?[i[0],i[1]]:null}function la(t,e){if(t.overrides.has(e))return t.overrides.get(e);const n=t.data[e];if(n!==void 0||!e.includes("."))return n;let i=t.data;const r=e.split(".");let s=0;for(;i!=null&&s<r.length;)i=i[r[s++]];return s===r.length?i:void 0}function oQ(t){return t.overrides.size===0?t.data:new Proxy(t.data,{get:(e,n)=>typeof n=="string"&&t.overrides.has(n)?t.overrides.get(n):e[n]})}function lQ(t,e){if(typeof t=="string"){const{entries:i,stop:r}=XZ(t);return r!==null&&e.add(v.UNREADABLE,null,"stylesheet",{sample:r}),i}if(!Array.isArray(t))return[];const n=[];for(const i of t){if(!es(i))continue;const r=i.style??i.css,s=[];if(es(r))for(const o of Object.keys(r))s.push([o,r[o]]);n.push({selector:i.selector,properties:s,dashOnly:!1})}return n}const ym=64;function HD(t,e=0){if(e>ym)return e;let n=e;for(const i of t.checks)for(const r of aQ(i))if(n=Math.max(n,HD(r,e+1)),n>ym)return n;return n}function aQ(t){switch(t.type){case"child":case"parent":return[t.parent,t.child];case"descendant":case"ancestor":return[t.ancestor,t.descendant];case"split":return[t.left,t.right,t.subject];case"directedEdge":case"nodeSource":case"nodeTarget":return[t.source,t.target];case"undirectedEdge":return[t.nodes[0],t.nodes[1]];case"nodeNeighbor":return[t.node,t.neighbor];default:return[]}}function SO(t,e,n,i,r){let s=t,o=r;const l=typeof t=="string",a=typeof t=="number"&&!Number.isNaN(t);let c=null,d=null;(l||typeof r=="string"||i)&&(c=!l&&!a?"":String(t),d=String(r)),i&&c!==null&&d!==null&&(c=c.toLowerCase(),d=d.toLowerCase(),s=c,o=d);let u=!1,f=!1;switch(e){case"*=":u=c!==null&&d!==null&&c.includes(d);break;case"$=":u=c!==null&&d!==null&&c.endsWith(d);break;case"^=":u=c!==null&&d!==null&&c.startsWith(d);break;case"=":u=s===o;break;case">":f=!0,u=s>o;break;case">=":f=!0,u=s>=o;break;case"<":f=!0,u=s<o;break;case"<=":f=!0,u=s<=o;break}return n&&(t!=null||!f)&&(u=!u),u}const cQ=new Set(["child","parent","descendant","ancestor","split","directedEdge","undirectedEdge","nodeSource","nodeTarget","nodeNeighbor"]),dQ=new Set(["active","inactive","grabbed","free","animated","unanimated","visible","hidden","transparent","backgrounding","nonbackgrounding"]);class VD extends Error{}const uQ=4096;class fQ{constructor(e,n){this.g=e,this.notes=n,this.work=0,this.#e=null,this.#t=0,this.#n={node:new Map,edge:new Map};const i=e.nodes.length;this.degree=new Int32Array(i),this.indegree=new Int32Array(i),this.outdegree=new Int32Array(i);for(let r=0;r<e.edges.length;r++){const s=e.source[r],o=e.target[r];this.degree[s]+=s===o?2:1,s!==o&&this.degree[o]++,this.outdegree[s]++,this.indegree[o]++}}#e;#t;#n;query(e,n,i){for(const r of e.checks)if(this.work++,this.#e!==null&&this.work-this.#t>=uQ&&this.settle(),!this.check(r,n,i))return!1;return!0}begin(e,n,i){this.#e={kind:e,budget:n,signal:i},this.#t=this.work,this.#n.node.clear(),this.#n.edge.clear()}end(){const e=this.#e;this.#e=null,e?.budget.spend(e.kind,this.work-this.#t),this.#t=this.work,this.#n.node.clear(),this.#n.edge.clear()}settle(){const e=this.#e;if(e!==null&&(e.budget.spend(e.kind,this.work-this.#t),this.#t=this.work,e.signal?.throwIfAborted(),e.budget.exhausted(e.kind)))throw new VD}sub(e,n,i){const r=this.#n[n];let s=r.get(e);if(s===void 0&&(s=new Uint8Array(n==="node"?this.g.nodes.length:this.g.edges.length),r.set(e,s)),s[i]!==0)return s[i]===1;const o=this.query(e,n,i);return s[i]=o?1:2,o}check(e,n,i){return cQ.has(e.type)?this.structureCheck(e,n,i):this.elementCheck(e,n,i)}elementCheck(e,n,i){const{g:r}=this,s=n==="node"?r.nodes[i]:r.edges[i];switch(e.type){case"group":return e.value==="*"||e.value===`${n}s`;case"state":return this.state(e.value,n,i,s);case"id":return s.id===e.value;case"class":return s.classes.has(e.value);case"exist":return la(s,e.field)!==void 0;case"bool":{const o=la(s,e.field);return e.op==="?"?!!o:e.op==="!"?!o:o===void 0}case"compare":return SO(la(s,e.field),e.op,e.not,e.ci,e.value);case"meta":{const o=n==="node"?this[e.field][i]:void 0;return SO(o,e.op,e.not,e.ci,e.value)}case"true":return!0;default:return!1}}structureCheck(e,n,i){const{g:r}=this;switch(e.type){case"child":return this.sub(e.child,n,i)&&n==="node"&&r.parent[i]>=0&&this.sub(e.parent,"node",r.parent[i]);case"parent":return this.sub(e.parent,n,i)&&n==="node"&&r.children[i].some(s=>this.sub(e.child,"node",s));case"descendant":return this.sub(e.descendant,n,i)&&n==="node"&&this.someAncestor(i,e.ancestor);case"ancestor":return this.sub(e.ancestor,n,i)&&n==="node"&&this.someDescendant(i,e.descendant);case"split":return this.sub(e.subject,n,i)&&this.sub(e.left,n,i)&&this.sub(e.right,n,i);case"directedEdge":return n==="edge"&&this.sub(e.source,"node",r.source[i])&&this.sub(e.target,"node",r.target[i]);case"undirectedEdge":{if(n!=="edge")return!1;const[s,o]=e.nodes,l=r.source[i],a=r.target[i];return this.sub(s,"node",l)&&this.sub(o,"node",a)||this.sub(o,"node",l)&&this.sub(s,"node",a)}case"nodeSource":return n==="node"&&this.sub(e.source,n,i)&&r.incident[i].some(s=>r.source[s]===i&&this.sub(e.target,"node",r.target[s]));case"nodeTarget":return n==="node"&&this.sub(e.target,n,i)&&r.incident[i].some(s=>r.target[s]===i&&this.sub(e.source,"node",r.source[s]));case"nodeNeighbor":return n==="node"&&this.sub(e.node,n,i)&&r.incident[i].some(s=>{const o=r.source[s]===i?r.target[s]:r.source[s];return this.sub(e.neighbor,"node",o)});default:return!1}}someAncestor(e,n){for(let i=this.g.parent[e];i>=0;i=this.g.parent[i])if(this.sub(n,"node",i))return!0;return!1}someDescendant(e,n){const i=[...this.g.children[e]];for(;i.length>0;){const r=i.pop();if(this.sub(n,"node",r))return!0;for(const s of this.g.children[r])i.push(s)}return!1}state(e,n,i,r){const{g:s}=this;dQ.has(e)&&this.notes.add(v.STATE_ASSUMED,n,`:${e}`,{sample:`:${e}`});const o=n==="node";switch(e){case"selected":return r.selected;case"unselected":return!r.selected;case"selectable":return r.selectable;case"unselectable":return!r.selectable;case"locked":return r.locked;case"unlocked":return!r.locked;case"grabbable":return r.grabbable;case"ungrabbable":return!r.grabbable;case"free":case"inside":case"unanimated":case"inactive":case"nonbackgrounding":case"visible":return!0;case"parent":return o&&s.children[i].length>0;case"childless":return o&&s.children[i].length===0;case"child":case"nonorphan":return o&&s.parent[i]>=0;case"orphan":return o&&s.parent[i]<0;case"compound":return o?s.children[i].length>0:s.children[s.source[i]].length>0||s.children[s.target[i]].length>0;case"loop":return!o&&s.source[i]===s.target[i];case"simple":return!o&&s.source[i]!==s.target[i];default:return!1}}}class hQ{constructor(e,n){this.elements=e,this.spend=n,this.byClass=new Map,this.byId=new Map,this.byValue=new Map,this.stamp=0,this.marks=new Int32Array(e.length);for(let i=0;i<e.length;i++){for(const r of e[i].classes){let s=this.byClass.get(r);s===void 0&&(s=[],this.byClass.set(r,s)),s.push(i)}this.byId.has(e[i].id)||this.byId.set(e[i].id,i)}n(e.length)}equal(e,n){let i=this.byValue.get(e);if(i===void 0){i=new Map;for(let r=0;r<this.elements.length;r++){const s=la(this.elements[r],e);if(typeof s!="string"&&typeof s!="number")continue;const o=`${typeof s}:${String(s)}`;let l=i.get(o);l===void 0&&(l=[],i.set(o,l)),l.push(r)}this.byValue.set(e,i),this.spend(this.elements.length)}return typeof n=="number"&&Number.isNaN(n)?[]:i.get(`${typeof n}:${String(n)}`)??[]}}function pQ(t,e,n){let i=null;for(const r of t.checks){let s=null;if(r.type==="group"&&r.value!=="*"&&r.value!==`${e}s`)return[];if(r.type==="class")s=n.byClass.get(r.value)??[];else if(r.type==="id"){const o=n.byId.get(r.value);s=o===void 0?[]:[o]}else r.type==="compare"&&r.op==="="&&!r.not&&!r.ci&&(s=n.equal(r.field,r.value));s!==null&&(i===null||s.length<i.length)&&(i=s)}return i}const OO=new Map([["top,left","top-left"],["top,center","top"],["top,right","top-right"],["center,left","left"],["center,center","center"],["center,right","right"],["bottom,left","bottom-left"],["bottom,center","bottom"],["bottom,right","bottom-right"]]),gQ=new Map([["top,left","inside-top-left"],["top,center","inside-top"],["top,right","inside-top-right"],["center,left","inside-left"],["center,right","inside-right"],["bottom,left","inside-bottom-left"],["bottom,center","inside-bottom"],["bottom,right","inside-bottom-right"]]);function a0(t){const e=t.notes??new se,n=t.budget??new Yf,i=tQ(t.elements),r=[];t.toolDefaults!==!1&&gm.forEach((u,f)=>{r.push({index:f-gm.length,tool:!0,text:u.selector,selector:xu(u.selector),properties:Object.entries(u.style),dashOnly:!0})});const s=lQ(t.style,e);let o=0,l=0;s.forEach((u,f)=>{let h=xu(u.selector);h.invalid&&o++,h.queries.some(p=>HD(p)>ym)&&(l++,h={queries:[],invalid:!0}),r.push({index:f,tool:!1,text:typeof u.selector=="string"?u.selector:"",selector:h,properties:u.properties,dashOnly:u.dashOnly})}),o>0&&e.add(v.SELECTOR,null,"selector",{count:o,sample:"invalid"}),l>0&&e.add(v.SELECTOR,null,"selector",{count:l,sample:"nested too deep"});const a=new fQ(i,e),c=NO("node",i,r,a,t,{notes:e,budget:n,nodes:null}),d=NO("edge",i,r,a,t,{notes:e,budget:n,nodes:c});return{node:c,edge:d,graph:i}}function YD(t,e,n,i){const r=t==="node"?e.nodes:e.edges;if(n===void 0)return Int32Array.from(r,(c,d)=>d);if(t==="node"){const c=new Int32Array(n.nodeCount).fill(-1);for(let d=0;d<r.length;d++){const u=mQ(n,r[d].id);u>=0&&c[u]<0&&(c[u]=d)}return c}const s=new Int32Array(n.edgeCount).fill(-1),o=YD("node",e,n,i),l=new Int32Array(e.nodes.length).fill(-1);o.forEach((c,d)=>{c>=0&&(l[c]=d)});let a=0;for(let c=0;c<r.length&&a<n.edgeCount;c++)l[e.source[c]]===n.edgeSource(a)&&l[e.target[c]]===n.edgeTarget(a)&&(s[a++]=c);return a<n.edgeCount&&i.add(v.UNRESOLVED,"edge","elements",{count:n.edgeCount-a,sample:"edge order"}),s}function mQ(t,e){if(t.ids.has(e))return t.ids.indexOf(e);const n=Number(e);return e.trim()!==""&&Number.isFinite(n)&&t.ids.has(n)?t.ids.indexOf(n):-1}function KD(t,e,n){let i=t.get(e);return i===void 0&&(i=new Array(n),t.set(e,i)),i}function NO(t,e,n,i,r,s){const{notes:o,budget:l}=s,a=t==="node"?e.nodes:e.edges,c=m=>{l.spend(t,m)},{cells:d,applied:u}=yQ(t,a,n,i,r,o,l),f=YD(t,e,r.snapshot,o),h=new Int32Array(a.length).fill(-1);f.forEach((m,y)=>{m>=0&&(h[m]=y)}),EQ(t,a,d,h,o),t==="edge"&&AQ(e,d.get("curve-style"));const p=wQ(t,a,d,f,r.rendered,o,c);if(t==="edge"&&r.toolDefaults!==!1){const m={kind:t,els:a,cells:d,order:f,rendered:r.rendered,notes:o},y=dn(m,"curve-style",pee);gee(y,p),s.nodes!==null&&XQ(e,m,y,s.nodes,p)}if(t==="node"){const m={kind:t,els:a,cells:d,order:f,rendered:r.rendered,notes:o};iee(e,m,p),lee(e,m,p),fee(e,m,p)}t==="edge"&&OQ(e,SQ(e,d,r.rendered),h,p.curved);const g=Eee(t,u,{els:a,order:f,coreToOut:h},r,p,{matcher:i,notes:o,spend:c});return{n:f.length,values:p,rules:g.rules,columns:g.columns,rawColumns:g.rawColumns,elements:Array.from(f,m=>m>=0?a[m]:null)}}function yQ(t,e,n,i,r,s,o){const l=e.length,a=Kf(t),c=g=>{o.spend(t,g)},d=new hQ(e,c),u=new Map,f=new Map,h=[];let p=!1;for(const g of n){r.signal?.throwIfAborted();const m=TQ(g,t,a,s,f);if(m.length===0)continue;const y=o.exhausted(t)?null:bQ(g.selector,{kind:t,n:l},i,d,r,o);if(y===null){p=!0;break}c(y.length),h.push({entry:g,list:y,props:m});for(const b of m){const _=KD(u,b.name,l);for(const S of y)_[S]=XD(b,e[S]);c(y.length)}}p&&s.add(v.BUDGET,t,null,{sample:"stylesheet"});for(const[g,m]of f)s.add(v.NOT_CARRIED,t,g,{count:m,sample:g});return{cells:u,applied:h}}function bQ(t,e,n,i,r,s){n.begin(e.kind,s,r.signal);try{return $Q(t,e.kind,e.n,n,i)}catch(o){if(!(o instanceof VD))throw o;return null}finally{n.end()}}function EQ(t,e,n,i,r){const s=Kf(t);for(let o=0;o<e.length;o++){const{json:l}=e[o],a=l.style??l.css;if(es(a))for(const c of Object.keys(a)){const d=r0(c),u=s.get(d),f=a[c];if(u===void 0||f===""||f===null)continue;const h=s0(u,f,"bypass");if(h===null||h===yr||!c0(h)){r.add(v.BAD_VALUE,t,u.property,{sample:f,element:i[o]});continue}KD(n,d,e.length)[o]=h}}}function wQ(t,e,n,i,r,s,o){const l=i.length,a={},c=new Map,d={kind:t,els:e,cells:n,order:i,rendered:r,notes:s};for(const[f,h]of Kf(t)){if(!n.has(f)&&r===void 0)continue;const p=dn(d,f,h);if(o(2*l),h.property.startsWith("_")){c.set(h.property,p.map(m=>typeof m=="string"||typeof m=="number"?String(m):null));continue}a[h.property]??=new Array(l).fill(null);const g=a[h.property];p.forEach((m,y)=>{m!=null&&(g[y]=m)})}vQ(t,l,c,a,s),t==="node"&&PD(a);const u={};for(const[f,h]of Object.entries(a))h.some(p=>p!==null)&&(u[f]=h);return u}function dn(t,e,n){const{kind:i,order:r,notes:s,rendered:o}=t,l=r.length,a=new Array(l).fill(null),c=t.cells.get(e);for(let d=0;d<l&&c!==void 0;d++){const u=r[d]>=0?c[r[d]]:void 0;u!==void 0&&(a[d]=qD(n,e,u,{notes:s,target:i,property:n.property,element:d}))}return o!==void 0&&_Q(t,o,e,n,a),a}function _Q(t,e,n,i,r){const{kind:s,order:o,notes:l}=t;for(let a=0;a<o.length;a++){const c=o[a]>=0?e.get(t.els[o[a]].json):void 0;if(c!==void 0&&Object.hasOwn(c,n)){const d={notes:l,target:s,property:i.property,element:a},u=yZ(s,n,c[n],d);r[a]=u===void 0||u===""&&i.type==="text"?null:u}}}function SQ(t,e,n){const i=e.get("curve-style");return t.edges.map((r,s)=>{const o=n?.get(r.json);if(o!==void 0&&Object.hasOwn(o,"curve-style"))return o["curve-style"];const l=i?.[s];return typeof l=="object"&&l.kind==="word"?l.value:void 0})}function OQ(t,e,n,i){if(i!==void 0)for(const r of NQ(t,e)){const s=r.length%2===1?n[r[(r.length-1)/2]]:-1;s>=0&&(i[s]=!1)}}function NQ(t,e){const n=new Map;for(let i=0;i<t.edges.length;i++){const r=t.source[i],s=t.target[i];if(r===s||e[i]!=="bezier")continue;const o=r<s?`${r} ${s}`:`${s} ${r}`,l=n.get(o);l===void 0?n.set(o,[i]):l.push(i)}return n.values()}function AQ(t,e){if(e!==void 0)for(let n=0;n<t.edges.length;n++){const i=e[n];t.source[n]===t.target[n]&&typeof i=="object"&&i.kind==="word"&&i.value!=="bezier"&&i.value!=="haystack"&&(e[n]={kind:"word",value:"bezier",str:"bezier"})}}function TQ(t,e,n,i,r){const s=[];for(const[o,l]of t.properties){const a=t.dashOnly?UD(o):r0(o),c=n.get(a);if(c===void 0){e==="node"&&!IQ.has(a)&&!t.tool&&r.set(a,(r.get(a)??0)+1);continue}const d=s0(c,l,"rule");if(d===null||d===yr){t.tool||i.add(v.BAD_VALUE,e,null,{sample:`${a}: ${String(l)}`});continue}s.push({name:a,spec:c,parsed:d})}return s}const IQ=new Set(["line-color","line-style","line-outline-width","line-outline-color","line-fill","line-gradient-stop-colors","line-gradient-stop-positions","target-arrow-shape","source-arrow-shape","target-arrow-color","source-arrow-color","mid-target-arrow-shape","mid-source-arrow-shape","mid-target-arrow-color","mid-source-arrow-color","target-arrow-fill","source-arrow-fill","curve-style","arrow-scale","source-label","target-label","source-text-offset","target-text-offset","source-text-margin-x","source-text-margin-y","target-text-margin-x","target-text-margin-y","source-text-rotation","target-text-rotation","source-distance-from-node","target-distance-from-node"]);function $Q(t,e,n,i,r){if(t.queries.length===0)return[];const s=++r.stamp,o=r.marks,l=[];let a=!1;const c=(d,u)=>{o[u]!==s&&i.query(d,e,u)&&(o[u]=s,l.push(u))};for(const d of t.queries){const u=pQ(d,e,r);if(u===null){a=!0;for(let f=0;f<n;f++)c(d,f)}else{i.work+=u.length;for(const f of u)c(d,f)}}return(a||t.queries.length>1)&&l.sort((d,u)=>d-u),i.work+=l.length,l}function XD(t,e){const n=t.parsed;return n.kind==="data"||n.kind==="mapData"?gZ(t.spec,n,oQ(e))??"reset":n.kind==="fn"?"fn":n}const yp=new Map;function CQ(t,e){const n=`${e.type}|${t}`;if(!yp.has(n)){const i=TJ.get(t),r=i===void 0?null:s0(e,i,"flat");yp.set(n,r===null||r===yr||!c0(r)?null:r)}return yp.get(n)??null}function c0(t){return t.kind==="color"||t.kind==="number"||t.kind==="word"}function qD(t,e,n,i){if(n===yr){i.notes.add(v.BAD_VALUE,i.target,i.property,{sample:"unstyleable",element:i.element});return}if(n==="fn"){i.notes.add(v.LAYER_FLATTENED,i.target,i.property,{sample:"FUNCTION",element:i.element});return}const r=n==="reset"?CQ(e,t):n;return r===null?null:ja(t,r,i)}function vQ(t,e,n,i,r){const s=[...i.opacity??new Array(e).fill(null)];DQ(e,n,i),t==="node"&&kQ(e,n,i);const o=n.get("_valign"),l=n.get("_halign");t==="node"&&(o!==void 0||l!==void 0)&&(i.labelPosition=Array.from({length:e},(u,f)=>bee(o?.[f]??null,l?.[f]??null)));const a=n.get("_wrap"),c=n.get("_maxWidth"),d=n.get("_overflowWrap");if(a!==void 0){const u=f=>a[f]==="wrap"||a[f]==="ellipsis";i.labelWrapWidth=Array.from({length:e},(f,h)=>u(h)&&typeof c?.[h]=="string"?Number(c[h]):null),a.includes("ellipsis")&&(i.labelWrapEllipsis=a.map(f=>f==="ellipsis"?!0:null)),d?.includes("anywhere")===!0&&(i.labelWrapAnywhere=a.map((f,h)=>f==="wrap"&&d[h]==="anywhere"?!0:null))}t==="node"?(DJ(e,n,i),YQ(e,n,i,r)):(yee(e,n,i,r),HQ(e,n.get("_lineOpacity"),i)),RQ(t,e,n,i),MQ(t,e,n,i),jQ(t,e,n,i,r,s),xQ(t,e,n,i)}function DQ(t,e,n){const i=e.get("_textOpacity"),r=n.opacity;if(i===void 0&&r===void 0)return;const s=new Array(t).fill(null);for(let o=0;o<t;o++){const l=i?.[o]??null,a=r?.[o],c=Math.round((l===null?1:Number(l))*(typeof a=="number"?a:1)*1e6)/1e6;s[o]=c===1||!Number.isFinite(c)?null:c}n.labelOpacity=s}function kQ(t,e,n){const i=n.opacity;for(const[r,s]of[["_ringOpacity","borderOpacity"],["_outlineRingOpacity","outerBorderOpacity"]]){const o=e.get(r);o===void 0&&i===void 0||(n[s]=Array.from({length:t},(l,a)=>{const c=o?.[a]??null,d=i?.[a],u=Math.round((c===null?1:Number(c))*(typeof d=="number"?d:1)*1e6)/1e6;return u===1||!Number.isFinite(u)?null:u}))}}function RQ(t,e,n,i){const r=t==="edge"?[["lineStyle","width",3,"6 3",!0]]:[["borderStyle","borderWidth",0,"4 2",!0],["outerBorderStyle","outerBorderWidth",0,"4 2",!1]];for(const[s,o,l,a,c]of r){const d=i[s];d!==void 0&&LQ(d,e,i[o],{fallback:l,pattern:a},c?n:null)}}function LQ(t,e,n,i,r){for(let s=0;s<e;s++){if(t[s]!=="dashed")continue;const o=n?.[s],l=PQ(r,s,i.pattern,typeof o=="number"?o:i.fallback);l!==null&&(t[s]=l)}}function PQ(t,e,n,i){const r=(t?.get("_dashPattern")?.[e]??n).split(/[\s,[\]]+/).filter(s=>s!=="").map(s=>Number.parseFloat(s));return r.length===0||!r.every(s=>Number.isFinite(s))?null:bZ(r,i,t?.get("_dashCap")?.[e]??"butt")}function al(t,e,n){let i=t[e];return i===void 0&&(i=new Array(n).fill(null),t[e]=i),i}function xQ(t,e,n,i){const r=n.get("_visibility"),s=n.get("_display");if(r===void 0&&s===void 0)return;const o=new Array(e).fill(null);for(let l=0;l<e;l++){const a=r?.[l]??null,c=s?.[l]??null;if(a===null&&c===null)continue;const d=t==="node"&&a==="hidden"&&c!=="none";if(o[l]=d||a!=="hidden"&&c!=="none",d){for(const u of["opacity","borderOpacity","outerBorderOpacity","labelOpacity"])al(i,u,e)[l]=0;al(i,"label",e)[l]=""}}i.visible=o}function MQ(t,e,n,i){UQ(e,n.get("_transform"),i.label);const r=n.get("_justification");if(r!==void 0&&t==="edge")GQ(e,r,n.get("_wrap"),i);else if(r!==void 0){const o=n.get("_halign"),l={left:"right",right:"left","left-inside":"left","right-inside":"right"};i.labelTextAlign=r.map((a,c)=>a===null?null:a==="auto"?l[o?.[c]??"center"]??"center":a)}const s=[["_rotation","labelRotation"],["_sourceRotation","sourceLabelRotation"],["_targetRotation","targetLabelRotation"]];for(const[o,l]of s){const a=n.get(o);a!==void 0&&(i[l]=a.map(c=>c===null?null:BQ(c)))}}function UQ(t,e,n){if(!(e===void 0||n===void 0))for(let i=0;i<t;i++){const r=n[i];typeof r=="string"&&e[i]==="uppercase"?n[i]=r.toUpperCase():typeof r=="string"&&e[i]==="lowercase"&&(n[i]=r.toLowerCase())}}function GQ(t,e,n,i){const r={left:-.5,right:.5};for(let s=0;s<t;s++){const o=n?.[s]==="wrap"?r[e[s]??""]:void 0;o!==void 0&&(al(i,"labelShiftX",t)[s]=o)}}function jQ(t,e,n,i,r,s){const o=(h,p,g)=>{const m=n.get(h)?.[p];return m==null?g:Number(m)},l=h=>i[h]??=new Array(e).fill(null),a=n.has("_outlineWidth"),c=n.has("_backgroundOpacity"),d=n.has("_textBorderWidth")&&n.has("_textBorderOpacity"),u=h=>typeof h=="number"?h:1,f=h=>{const p=Math.round(h*1e6)/1e6;return p<1?p:null};for(let h=0;h<e&&(a||c||d);h++){const p=o("_outlineWidth",h,0),g=o("_outlineOpacity",h,1);a&&p>0&&g>0&&(l("labelOutlineColor")[h]=n.get("_outlineColor")?.[h]??"#000000",l("labelOutlineWidth")[h]=2*p,l("labelOutlineOpacity")[h]=f(g*u(i.labelOpacity?.[h])));const m=o("_backgroundOpacity",h,0),y=c&&m>0;y&&(l("labelBackground")[h]=n.get("_backgroundColor")?.[h]??"#000000",l("labelBackgroundOpacity")[h]=f(m*u(s[h])));const b=d&&zQ(t,h,n,l,r,u(s[h]));(y||b)&&FQ(t,h,n,l,r)}}function FQ(t,e,n,i,r){const s=n.get("_backgroundPadding")?.[e];i("labelPadding")[e]=s==null?0:Number(s),i("labelLineHeight")[e]=1;const o=n.get("_backgroundShape")?.[e];o==="round-rectangle"||o==="roundrectangle"?i("labelCornerRadius")[e]=2:o==="circle"&&r.add(v.APPROXIMATED,t,"labelBackground",{sample:"circle",element:e})}function zQ(t,e,n,i,r,s){const o=u=>Number(n.get(u)?.[e]??0),[l,a]=[o("_textBorderWidth"),o("_textBorderOpacity")];if(!(l>0&&a>0))return!1;const c=n.get("_textBorderStyle")?.[e]??"solid";i("labelBorderColor")[e]=n.get("_textBorderColor")?.[e]??"#000000",i("labelBorderWidth")[e]=c==="double"?l/4:l;const d=Math.round(a*s*1e6)/1e6;return i("labelBorderOpacity")[e]=d<1?d:null,(c==="dotted"||c==="dashed"||c==="double")&&r.add(v.APPROXIMATED,t,"labelBorderColor",{sample:c,element:e}),!0}function WQ(t,e){const n=e[0]-t[0],i=Math.atan((e[1]-t[1])/n),r=(n===0?Math.abs(i):i)*180/Math.PI;return Number.isFinite(r)?Math.round((r%360+360)%360*1e6)/1e6+0:0}function BQ(t){const e=t.trim();if(e==="none"||e==="autorotate")return 0;const n=/^(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)(deg|rad)?$/i.exec(e);if(n===null)return null;const i=Number(n[1]),r=n[2]?.toLowerCase()==="deg"?i:i*180/Math.PI;return Math.round((r%360+360)%360*1e6)/1e6+0}function HQ(t,e,n){if(e===void 0)return;const i=n.opacity;n.opacity=Array.from({length:t},(r,s)=>{const o=e[s]===null?null:Number(e[s]),l=i?.[s];return o===null||!Number.isFinite(o)?l??null:Math.round(o*(typeof l=="number"?l:1)*1e6)/1e6})}const VQ=new Map([["to-bottom",90],["to-top",270],["to-left",180],["to-right",0],["to-bottom-right",45],["to-right-bottom",45],["to-bottom-left",135],["to-left-bottom",135],["to-top-right",315],["to-right-top",315],["to-top-left",225],["to-left-top",225]]);function YQ(t,e,n,i){const r=e.get("_backgroundFill");if(r===void 0)return;const s=e.get("_backgroundStops"),o=e.get("_backgroundPositions"),l=e.get("_backgroundDirection"),a=c=>n[c]??=new Array(t).fill(null);for(let c=0;c<t;c++){const d=r[c]==="radial-gradient";if(r[c]!=="linear-gradient"&&!d)continue;const u=YJ(s?.[c]??"#999",{notes:i,target:"node",property:"fill",element:c});if(u.length<2)continue;a("fill")[c]=u[0],a("fillGradient")[c]=u.at(-1)??null,u.length>2&&(a("fillGradientColors")[c]=u.join(" "));const f=MD(o?.[c]??"");f?.split(" ").length===u.length&&(a("fillGradientStops")[c]=f),d?a("fillGradientKind")[c]="radial":a("fillGradientAngle")[c]=VQ.get(l?.[c]??"to-bottom")??90}}const KQ=[["segmentDistances","segment-distances",{property:"_segmentDistances",type:"text"}],["segmentWeights","segment-weights",{property:"_segmentWeights",type:"text"}],["controlPointDistances","control-point-distances",{property:"_controlPointDistances",type:"text"}],["controlPointWeights","control-point-weights",{property:"_controlPointWeights",type:"text"}],["controlPointStepSize","control-point-step-size",{property:"_controlPointStepSize",type:"size"}],["taxiDirection","taxi-direction",{property:"_taxiDirection",type:"text"}],["taxiTurn","taxi-turn",{property:"_taxiTurn",type:"text"}],["taxiTurnMinDistance","taxi-turn-min-distance",{property:"_taxiTurnMinDistance",type:"size"}],["edgeDistances","edge-distances",{property:"_edgeDistances",type:"text"}],["loopDirection","loop-direction",{property:"_loopDirection",type:"text"}],["loopSweep","loop-sweep",{property:"_loopSweep",type:"text"}],["segmentRadii","segment-radii",{property:"_segmentRadii",type:"text"}],["taxiRadius","taxi-radius",{property:"_taxiRadius",type:"text"}],["radiusType","radius-type",{property:"_radiusType",type:"text"}]];function XQ(t,e,n,i,r){const s=new Map(KQ.map(([h,p,g])=>[h,dn(e,p,g)])),o=new Map;i.elements.forEach((h,p)=>{h!==null&&o.set(h,p)});const l=h=>qQ(t.nodes[h],o,i),a=[["labelRotation",dn(e,"text-rotation",Fr)],["sourceLabelRotation",dn(e,"source-text-rotation",Fr)],["targetLabelRotation",dn(e,"target-text-rotation",Fr)]],c=[dn(e,"source-endpoint",Fr),dn(e,"target-endpoint",Fr)],d=new Map,u=e.order.length;let f=null;for(let h=0;h<u;h++){const p=e.order[h],g=JQ(t,p,l);if(g===null)continue;const{src:m,tgt:y,loop:b}=g;b||ZQ(r,a,h,u,WQ(m.center,y.center));const _=nee(s,h,n[h]),S=OZ(_,m,y,b?QQ(d,t.source[p],_):0);S!==null&&(f??=r.bends??new Array(u).fill(null),f[h]=S,al(r,"curved",u)[h]=!1),b||eee(_.curveStyle,[c[0][h],c[1][h]],[m,y],(T,$)=>{al(r,T,u)[h]=$})}f!==null&&(r.bends=f)}function qQ(t,e,n){const i=e.get(t),r=t.json.position;if(i===void 0||!es(r)||typeof r.x!="number"||typeof r.y!="number")return null;const s=(c,d)=>{const u=n.values[c]?.[i];return typeof u=="number"?u:d},[o,l,a]=[s("width",30),s("height",30),s("borderWidth",0)];return{center:[r.x,r.y],size:[o+a,l+a],box:[o,l],ellipse:(n.values.shape?.[i]??"ellipse")==="ellipse"}}function JQ(t,e,n){if(e<0)return null;const i=t.source[e]===t.target[e],r=n(t.source[e]),s=i?r:n(t.target[e]);return r===null||s===null?null:{src:r,tgt:s,loop:i}}function ZQ(t,e,n,i,r){for(const[s,o]of e)o[n]==="autorotate"&&(al(t,s,i)[n]=r)}function QQ(t,e,n){const i=`${String(e)} ${String(n.loopDirection)} ${String(n.loopSweep)}`,r=t.get(i)??0;return t.set(i,r+1),r}function eee(t,e,n,i){t==="taxi"||t==="round-taxi"||["sourcePort","targetPort"].forEach((r,s)=>{const o=t==="haystack"?"0,0":tee(String(e[s]??""),n[s]);o!==null&&i(r,o)})}function tee(t,e){const n=t.trim();if(n==="inside-to-node")return"0,0";const i=n.split(/\s+/),[r,s]=e.size,o=h=>String(Math.round(h*1e6)/1e6+0),l=(h,p)=>{const g=/^(-?(?:\d+(?:\.\d*)?|\.\d+))(%|px)?$/.exec(h);return g===null||Number.isNaN(p)||p<=0?null:(g[2]==="%"?Number(g[1])/100*p:Number(g[1]))/(p/2)};if(i.length===2){const[h,p]=[l(i[0],r),l(i[1],s)];return h===null||p===null?null:`${o(h)},${o(-p)}`}const a=/^(-?(?:\d+(?:\.\d*)?|\.\d+))(deg|rad)$/.exec(n);if(a===null)return null;const c=a[2]==="deg"?Number(a[1])*Math.PI/180:Number(a[1]),[d,u]=[Math.sin(c)/(r/2),Math.cos(c)/(s/2)],f=e.ellipse?Math.hypot(d,u):Math.max(Math.abs(d),Math.abs(u));return f>0?`${o(d/f)},${o(u/f)}`:null}function nee(t,e,n){const i=s=>{const o=t.get(s)?.[e];return o==null?null:String(o)},r=s=>{const o=i(s);return o===null?null:Number(o)};return{curveStyle:String(n??"haystack"),segmentDistances:i("segmentDistances"),segmentWeights:i("segmentWeights"),controlPointDistances:i("controlPointDistances"),controlPointWeights:i("controlPointWeights"),controlPointStepSize:r("controlPointStepSize"),taxiDirection:i("taxiDirection"),taxiTurn:i("taxiTurn"),taxiTurnMinDistance:r("taxiTurnMinDistance"),edgeDistances:i("edgeDistances"),loopDirection:i("loopDirection"),loopSweep:i("loopSweep"),segmentRadii:i("segmentRadii"),taxiRadius:i("taxiRadius"),radiusType:i("radiusType")}}const Fr={property:"_text",type:"text"};function iee(t,e,n){const i=dn(e,"padding",Fr),r=["width","height"].map(l=>dn(e,l,hee)),s=e.order.length,o=l=>n[l]??=new Array(s).fill(null);for(let l=0;l<s;l++){const a=e.order[l],c=a<0||t.children[a].length>0?0:JD(i[l]),d=r.map(u=>u[l]==="label");if(d[0]||d[1]){o("labelFit")[l]="bounds",o("labelPaddingX")[l]=c,o("labelPaddingY")[l]=c,["width","height"].forEach((u,f)=>{const h=n[u]?.[l],p=typeof h=="number"?h:30;o(u)[l]=d[f]?0:p+2*c});continue}if(!(c<=0))for(const u of["width","height"]){const f=n[u]?.[l];o(u)[l]=(typeof f=="number"?f:30)+2*c}}}const ree={property:"_paddingOf",type:"enum",enums:["width","height","average","min","max"]},see={property:"_compoundLabels",type:"enum",enums:["include","exclude"]};function d0(t){if(typeof t!="string"&&typeof t!="number")return null;const e=Number.parseFloat(String(t));return Number.isFinite(e)?{value:e,percent:String(t).trim().endsWith("%")}:null}function oee(t,e,n){const i=o=>{const l=d0(o);return l===null||l.value<=0?0:l.percent?l.value:l.value*100/n},r=i(t),s=r+i(e);return s>0?r/s:null}function lee(t,e,n){const i=(u,f=Fr)=>dn(e,u,f),r=i("padding"),s=i("padding-relative-to",ree),o=i("compound-sizing-wrt-labels",see),l=[{min:i("min-width"),near:i("min-width-bias-left"),far:i("min-width-bias-right")},{min:i("min-height"),near:i("min-height-bias-top"),far:i("min-height-bias-bottom")}],a=[["groupMinWidth","groupMinWidthBiasLeft"],["groupMinHeight","groupMinHeightBiasTop"]],c=e.order.length,d=(u,f,h)=>{const p=n[u]??new Array(c).fill(null);n[u]=p,p[f]=h};for(let u=0;u<c;u++){const f=e.order[u];if(!(f<0||t.children[f].length===0)){for(const[h,p]of aee(r[u],s[u]))d(h,u,p);d("groupIncludeLabels",u,o[u]!=="exclude"),l.forEach((h,p)=>{for(const[g,m]of cee(h.min[u],h.near[u],h.far[u],a[p]))d(g,u,m)})}}}function aee(t,e){const n=d0(t);return n?.percent!==!0?[["groupPadding",Math.max(0,n?.value??0)]]:[["groupPaddingRatio",Math.max(0,n.value/100)],["groupPaddingOf",typeof e=="string"?e:"width"]]}function cee(t,e,n,i){const r=d0(t);if(r===null||r.percent||r.value<=0)return[];const s=oee(e,n,r.value);return s===null?[[i[0],r.value]]:[[i[0],r.value],[i[1],s]]}const dee={property:"_valign",type:"enum",enums:["top","top-inside","center","bottom","bottom-inside"]},uee={property:"_halign",type:"enum",enums:["left","left-inside","center","right","right-inside"]};function AO(t,e,n){const i=/^(left|top)/.test(t);if(!i&&!/^(right|bottom)/.test(t))return{offset:0,shift:0};const r=i?-1:1;return t.endsWith("-inside")?{offset:r*(e-2*n),shift:-r/2}:{offset:r*e,shift:r/2}}function fee(t,e,n){const i=dn(e,"text-valign",dee),r=dn(e,"text-halign",uee),s=dn(e,"padding",Fr),o=e.order.length,l=a=>n[a]??=new Array(o).fill(null);for(let a=0;a<o;a++){const c=typeof i[a]=="string"?String(i[a]):"top",d=typeof r[a]=="string"?String(r[a]):"center";if(!(c.endsWith("-inside")||d.endsWith("-inside"))||!(c==="top"||c==="bottom"||d==="left"||d==="right"))continue;if(n.labelFit?.[a]!==void 0&&n.labelFit[a]!==null){e.notes.add(v.APPROXIMATED,"node","labelPosition",{sample:`${c} ${d}`,element:a});continue}const h=e.order[a],p=h<0||t.children[h].length>0?0:JD(s[a]),g=_=>{const S=n[_]?.[a];return typeof S=="number"?S:30+2*p},m=AO(d,g("width")/2,p),y=AO(c,g("height")/2,p),b=(_,S)=>{const T=n[_]?.[a];l(_)[a]=(typeof T=="number"?T:0)+S};l("labelPosition")[a]="center",b("labelOffsetX",m.offset),b("labelOffsetY",y.offset),l("labelShiftX")[a]=m.shift,l("labelShiftY")[a]=y.shift}}const hee={property:"_size",type:"nodeSize"};function JD(t){if(typeof t!="string")return 0;const e=Number.parseFloat(t);return!Number.isFinite(e)||e<=0?0:t.trim().endsWith("%")?e/100:e}const pee={property:"_curve",type:"enum",enums:kD};function gee(t,e){const n=t.length;for(const i of["targetArrow","sourceArrow"]){const r=e[i];if(r!==void 0)for(let s=0;s<n;s++)(t[s]??"haystack")==="haystack"&&r[s]!==null&&(r[s]="none")}}const ZD=new Map([["triangle","triangle-open"],["diamond","diamond-open"],["circle","circle-open"],["square","other:open-square"]]);function mee(t,e){for(const n of e){const i=/^_(\w+Arrow)Fill$/.exec(n.spec.property)?.[1],r=i===void 0?void 0:t[i];if(i===void 0||r===void 0||n.parsed.kind!=="word")continue;const s=ZD.get(r);s!==void 0&&n.parsed.value==="hollow"&&(t[i]=s)}}function yee(t,e,n,i){for(const r of["targetArrow","sourceArrow","midTargetArrow","midSourceArrow"]){const s=e.get(`_${r}Fill`),o=n[r];if(!(s===void 0||o===void 0))for(let l=0;l<t;l++){const a=o[l];if(s[l]!=="hollow"||a===null||a==="none")continue;const c=ZD.get(a);if(c!==void 0)o[l]=c;else if(!String(a).includes("open")){const d=r.replaceAll(/[A-Z]/g,u=>`-${u.toLowerCase()}`).replace("-arrow","-arrow-fill");i.add(v.NOT_CARRIED,"edge",d,{sample:`hollow ${String(a)}`,element:l})}}}}function bee(t,e){if(t===null&&e===null)return null;const n=(t??"").endsWith("-inside"),i=(e??"").endsWith("-inside"),r=(t??"top").replace("-inside",""),s=(e??"center").replace("-inside","");return n||i?!(r!=="center"&&!n)&&!(s!=="center"&&!i)?gQ.get(`${r},${s}`)??null:OO.get(`${n?"center":r},${i?"center":s}`)??null:OO.get(`${r},${s}`)??null}function Eee(t,e,n,i,r,s){const{els:o,order:l,coreToOut:a}=n,{matcher:c,notes:d,spend:u}=s,f=l.length,h=new Map,p=new Set,g={kind:t,els:o,coreToOut:a,out:f,snapshot:i.snapshot,truth:i.rendered===void 0?null:r,matcher:c,notes:d,spend:u,columns:h,raw:p,members:new Map,faithful:new Map,degrees:new Map},m=[];for(const b of e){const _=b.props.filter(S=>!S.spec.property.startsWith("_"));_.length===0||b.list.length===0||m.push(wee(g,b.entry,b.list,_,b.props))}return{rules:Lee(g,m),columns:h,rawColumns:[...p]}}function wee(t,e,n,i,r){const s=new Map,o=new Map;let l=!1;const a=e.tool?`${t.kind}.cytoscape-js.${String(e.index+gm.length)}`:`${t.kind}.sheet.${String(e.index)}`;for(const h of i){s.delete(h.spec.property),o.delete(h.spec.property);const p=h.parsed;if(p.kind==="fn"){const g=_ee(t,e,n,h.spec.property);g!==null&&(o.set(h.spec.property,g),l=!0)}else if(c0(p)){const g=ja(h.spec,p,{notes:new se,target:t.kind,property:h.spec.property});g!==void 0&&s.set(h.spec.property,g)}else o.set(h.spec.property,Dee(t,e,n,h))}const c=Object.fromEntries(s);t.kind==="node"?PD(c):mee(c,r);const d=Object.fromEntries(o),u=o.size>0;return{rule:()=>{const h=Aee(t,e,n);return{id:a,target:t.kind,role:See(u,h),origin:e.tool?"tool":"declared",where:h,...s.size>0?{set:c}:{},...u?{map:d}:{},facts:l?{elements:n.length,reason:"FUNCTION"}:{elements:n.length}}},id:a,set:c,tool:e.tool,single:u||e.tool?null:Oee(e.selector,t.kind),list:n}}function _ee(t,e,n,i){const r=t.truth?.[i];if(r===void 0)return null;const s=`function.${String(e.index)}.${i}`,o=new Array(t.out).fill(null);for(const l of n){const a=t.coreToOut[l];a>=0&&(o[a]=r[a])}return t.columns.set(s,o),{kind:"passthrough",by:{style:s}}}function See(t,e){return t?"mapping":"all"in e?"defaults":"group"}function Oee(t,e){if(t.invalid||t.queries.length!==1)return null;const n=t.queries[0].checks.filter(s=>!(s.type==="group"&&(s.value==="*"||s.value===`${e}s`))),i=n.at(-1);if(i===void 0||n.slice(0,-1).some(s=>s.type!=="compare"&&s.type!=="class"))return null;const r=JSON.stringify(n.slice(0,-1));return i.type==="class"&&typeof i.value=="string"?{sig:`class\0${r}`,key:i.value}:i.type==="id"?{sig:`id\0${r}`,key:i.value}:i.type==="compare"&&i.op==="="&&!i.not&&!i.ci?{sig:`eq\0${r}\0${i.field}`,key:i.value}:null}function Md(t,e){const n=t.faithful.get(e);if(n!==void 0)return n;let i=t.snapshot!==void 0;const r=t.kind==="node"?t.snapshot?.nodes:t.snapshot?.edges,s=r?.names().includes(e)??!1;for(let o=0;i&&o<t.els.length;o++){const l=t.coreToOut[o],a=la(t.els[o],e);if(a===null||a===!1){i=!1;break}const c=l>=0&&s&&r!==void 0?K(r.value(e,l)):null;(a===void 0?c!==null:a!==c)&&(i=!1)}return t.spend(t.els.length),t.faithful.set(e,i),i}function Nee(t,e){const n=t.degrees.get(e);if(n!==void 0)return n;let i=t.snapshot!==void 0&&t.kind==="node"&&(e==="degree"||t.snapshot.directed);if(i&&t.snapshot!==void 0){const r=sc(t.snapshot,e);for(let s=0;s<t.els.length;s++){const o=t.coreToOut[s];if(o<0||r[o]!==t.matcher[e][s]){i=!1;break}}i&&=t.els.length===t.out}return t.degrees.set(e,i),i}function Aee(t,e,n){const i=Tee(t,e.selector);if(i!==null)return i;if(n.length===t.els.length&&t.els.length===t.out)return{all:!0};const r=`${e.tool?"tool":"file"}\0${e.text}`;let s=t.members.get(r);if(s===void 0){s=`member.${String(t.members.size+1)}`,t.members.set(r,s);const o=new Array(t.out).fill(null);for(const l of n){const a=t.coreToOut[l];a>=0&&(o[a]=!0)}t.spend(t.out+n.length),t.columns.set(s,o),t.notes.add(v.SELECTOR_AS_COLUMN,t.kind,s,{sample:e.text})}return{has:{style:s}}}function Tee(t,e){if(e.invalid)return null;const n=[];for(const i of e.queries){const r=Iee(t,i);if(r===null)return null;r!=="never"&&n.push(r)}if(n.length===0)return null;if(n.some(i=>i.length===0))return t.els.length===t.out?{all:!0}:null;if(n.length===1){const i=n[0];return i.length>8?null:i.length===1?i[0]:{and:i}}return $ee(n)}function Iee(t,e){const n=[];let i=!1;for(const r of e.checks){if(r.type==="group"){i||=r.value!=="*"&&r.value!==`${t.kind}s`;continue}const s=Cee(t,r);if(s===null)return null;n.push(s)}return i?"never":n}function $ee(t){if(t.length>8||!t.every(i=>i.length===1&&"eq"in i[0]))return null;const e=t[0][0].eq[0],n=[];for(const i of t){const[r,s]=i[0].eq;if(JSON.stringify(r)!==JSON.stringify(e))return null;n.push(s)}return{in:[e,n]}}function Cee(t,e){switch(e.type){case"compare":return e.op!=="="||e.ci||!Md(t,e.field)?null:e.not?{not:{eq:[{data:e.field},e.value]}}:{eq:[{data:e.field},e.value]};case"exist":return Md(t,e.field)?{has:{data:e.field}}:null;case"bool":return e.op==="^"&&Md(t,e.field)?{not:{has:{data:e.field}}}:null;case"meta":return e.ci||!Nee(t,e.field)?null:vee(e.field,e.op,e.not,e.value);default:return null}}function vee(t,e,n,i){const r={computed:t};if(e==="=")return n?{not:{eq:[r,i]}}:{eq:[r,i]};let s;if(e===">"||e==="<=")s=Math.floor(i)+1;else if(e===">="||e==="<")s=Math.ceil(i);else return null;if(!Number.isFinite(s)||s<1||s>8)return null;const o=Array.from({length:s},(c,d)=>d),l=e==="<"||e==="<=",a={in:[r,o]};return l!==n?a:{not:a}}function Dee(t,e,n,i){const r=i.parsed,s=new Array(n.length),o={notes:new se,target:t.kind,property:i.spec.property};for(let d=0;d<n.length;d++){const u=XD(i,t.els[n[d]]),f=qD(i.spec,i.name,u,o);s[d]=f??null}t.spend(n.length*2);const l=Ree(t,r,i);if(l!==null&&t.snapshot!==void 0){const d=kee(t,t.snapshot,l,{field:r.field,property:i.spec.property},n,s);if(t.spend(n.length),d)return t.raw.add(r.field),l}const a=`value.${e.tool?"tool":String(e.index)}.${i.spec.property}`,c=new Array(t.out).fill(null);for(let d=0;d<n.length;d++){const u=t.coreToOut[n[d]];u>=0&&(c[u]=s[d])}return t.columns.set(a,c),{kind:"passthrough",by:{style:a}}}function kee(t,e,n,i,r,s){const o=t.kind==="node"?e.nodes:e.edges;if(!o.names().includes(i.field))return!1;const l=_l(t.kind,i.property);for(let a=0;a<r.length;a++){const c=t.coreToOut[r[a]],d=c<0?null:K(o.value(i.field,c));let u=null;if(d!==null&&!Array.isArray(d)&&(u=n.kind==="passthrough"?l(d):bf(n.points,oc(d))),c>=0&&u!==s[a])return!1}return!0}function Ree(t,e,n){if(e.kind==="data")return{kind:"passthrough",by:{data:e.field}};if(e.fieldMin===e.fieldMax)return null;const i={notes:new se,target:t.kind,property:n.spec.property},r=ja(n.spec,e.min,i),s=ja(n.spec,e.max,i);if(r===void 0||s===void 0)return null;const o={at:e.fieldMin,below:r,value:r,above:r},l={at:e.fieldMax,below:s,value:s,above:s};return{kind:"continuous",by:{data:e.field},points:e.fieldMin<e.fieldMax?[o,l]:[l,o]}}function Lee(t,e){const n=[];let i=0,r=0;for(;r<e.length;){const s=e[r].single?.sig??null;let o=r+1;for(;s!==null&&o<e.length&&e[o].single?.sig===s;)o++;if(s===null||o-r<3)for(const l of e.slice(r,o)){const a=l.rule();l.tool&&"all"in a.where||n.push(a)}else i++,n.push(Pee(t,e.slice(r,o),s,i));r=o}return n}function Pee(t,e,n,i){const r=new Set(e.flatMap(c=>Object.keys(c.set))),s=n.split("\0"),o=s[0]==="eq"&&s[1]==="[]"?s[2]:null,l={};for(const c of r)l[c]=xee(t,e,c,{field:o,key:`winner.${String(i)}.${c}`});const a=e[0].id.split(".").pop()??"";return{id:`${t.kind}.sheet.by.${s[0]==="eq"?"value":s[0]}.${a}`,target:t.kind,role:"mapping",origin:"declared",where:{all:!0},map:l,facts:{elements:e.reduce((c,d)=>c+d.list.length,0)}}}function xee(t,e,n,i){const r=new Array(t.out).fill(null),s=new Map;for(const c of e){const d=c.set[n];if(d===void 0||c.single===null)continue;const{key:u}=c.single;s.set(`${typeof u}:${String(u)}`,[u,d]);for(const f of c.list){const h=t.coreToOut[f];h>=0&&(r[h]=u)}t.spend(c.list.length)}const o=[...s.values()],l=new Map(o.map(([c,d])=>[`${typeof c}:${String(c)}`,d])),{field:a}=i;return a!==null&&Md(t,a)&&Mee(t,a,r,l)?{kind:"discrete",by:{data:a},table:o}:(t.columns.set(i.key,r),{kind:"discrete",by:{style:i.key},table:o})}function Mee(t,e,n,i){const r=t.kind==="node"?t.snapshot?.nodes:t.snapshot?.edges;if(!r?.names().includes(e))return!1;for(let s=0;s<t.out;s++){const o=K(r.value(e,s)),l=typeof o=="string"||typeof o=="number"?i.get(`${typeof o}:${String(o)}`)??null:null,a=n[s],c=a===null?null:i.get(`${typeof a}:${String(a)}`)??null;if(l!==c)return!1}return!0}function Uee(t){const e=t.notes??new se,n=a0({...t,notes:e}),i=r=>({values:r.values,rules:r.rules,columns:r.columns});return{canonical:!0,dialect:"cytoscape-js",tool:"cytoscape-js",units:"px",node:i(n.node),edge:i(n.edge),notes:e.list()}}const vo="graphty_import";function TO(t){return`graphty_style_${t.replaceAll(/\W/g,"_")}`}const QD=/^[A-Za-z_]\w*$/,Gee=new Map([["ellipse","ellipse"],["rectangle","rectangle"],["round-rectangle","round-rectangle"],["triangle","triangle"],["diamond","diamond"],["pentagon","pentagon"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","rhomboid"],["star","star"],["vee","vee"],["polygon","polygon"]]),jee=new Map([["none","none"],["triangle","triangle"],["vee","vee"],["tee","tee"],["diamond","diamond"],["circle","circle"],["square","square"]]),Fee=new Map([["none","solid"],["linear","linear-gradient"],["radial","radial-gradient"]]),zee={sourceArrow:"source-arrow-shape",targetArrow:"target-arrow-shape",midSourceArrow:"mid-source-arrow-shape",midTargetArrow:"mid-target-arrow-shape"},Wee=new Map([["triangle-open","triangle"],["diamond-open","diamond"],["circle-open","circle"]]),Bee=new Map([["half","triangle"],["inverted","triangle"],["crow","vee"]]);function u0(t,e,n){const i=t==="node"?n0:i0;switch(e){case"visible":return ge({display:n===!1?"none":"element"});case"shapePoints":return Kee(String(n));case"labelItalic":return ge({"font-style":n===!0?"italic":"normal"});case"curved":return ge({"curve-style":n===!0?"unbundled-bezier":"straight"});case"labelPosition":return qee(String(n));case"fanSpacing":case"labelWrapWidth":return fi(n,r=>Xee(e,r));case"gradientKind":return Vee(String(n));case"gradientStops":return ge({"line-gradient-stop-positions":String(n).trim().split(/\s+/).map(r=>`${P(Number(r)*100)}%`).join(" ")});case"outerBorderOffset":return fi(n,r=>ge({"outline-offset":P(r*2)}));case"outerBorderStyle":return Yee(String(n));case"shape":return ek("shape",String(n),Gee,i);case"borderStyle":return tk(String(n));case"lineStyle":return Zee(String(n));case"sourceArrow":case"targetArrow":case"midSourceArrow":case"midTargetArrow":return Jee(zee[e],String(n),i);case"labelFont":return GD(String(n))?ge({"font-family":String(n)}):null;case"labelBackground":return ge({"text-background-color":String(n),"text-background-opacity":1});case"labelOutlineColor":return ge({"text-outline-color":String(n)});case"labelOutlineWidth":return fi(n,r=>ge({"text-outline-width":P(r/2)}));case"labelPadding":return fi(n,r=>ge({"text-background-padding":r}));case"labelBorderColor":return ge({"text-border-color":String(n),"text-border-opacity":1});case"labelBorderWidth":return fi(n,r=>ge({"text-border-width":r,"text-border-opacity":1}));default:return Hee(e,n)??Qee(e,n,i)}}function Hee(t,e){const n=i=>`${P(i*100)}%`;switch(t){case"groupPadding":return fi(e,i=>ge({padding:`${P(i)}px`}));case"groupPaddingRatio":return fi(e,i=>ge({padding:n(i)}));case"groupPaddingOf":return ge({"padding-relative-to":String(e)});case"groupMinWidth":return fi(e,i=>ge({"min-width":`${P(i)}px`}));case"groupMinHeight":return fi(e,i=>ge({"min-height":`${P(i)}px`}));case"groupMinWidthBiasLeft":return fi(e,i=>ge({"min-width-bias-left":n(i),"min-width-bias-right":n(1-i)}));case"groupMinHeightBiasTop":return fi(e,i=>ge({"min-height-bias-top":n(i),"min-height-bias-bottom":n(1-i)}));case"groupIncludeLabels":return ge({"compound-sizing-wrt-labels":e===!1?"exclude":"include"});default:return null}}function fi(t,e){return typeof t=="number"?e(t):null}function Vee(t){const e=Fee.get(t);return e===void 0?null:ge({"line-fill":e})}function Yee(t){const e=tk(t);return e===null?null:{...e,props:{"outline-style":e.props["border-style"]}}}function Kee(t){const e=WJ(t);return e===null?null:ge({"shape-polygon-points":e})}function Xee(t,e){return ge(t==="fanSpacing"?{"control-point-step-size":P(e*2)}:{"text-wrap":"wrap","text-max-width":e})}function ge(t){return{props:t,approximate:!1}}function f0(t){return{props:t,approximate:!0}}function qee(t){const e=t.startsWith("inside-"),n=e?t.slice(7):t,i=["top","bottom"].find(o=>n.startsWith(o))??"center",r=["left","right"].find(o=>n.endsWith(o))??"center",s=o=>e&&o!=="center"?`${o}-inside`:o;return ge({"text-valign":s(i),"text-halign":s(r)})}function ek(t,e,n,i){const r=n.get(e);if(r!==void 0)return ge({[t]:r});const s=e.startsWith("other:")?e.slice(6):null;return s!==null&&i.get(t)?.enums?.includes(s)===!0?ge({[t]:s}):null}function Jee(t,e,n){const i=t.replace("-shape","-fill"),r=Wee.get(e);if(r!==void 0)return ge({[t]:r,[i]:"hollow"});const s=ek(t,e,jee,n),o=Bee.get(e),l=s??(o===void 0?null:f0({[t]:o}));return l===null||e==="none"?l:{...l,props:{...l.props,[i]:"filled"}}}function tk(t){return t==="dash-dot"?f0({"border-style":"dashed"}):["solid","dotted","dashed","double"].includes(t)?ge({"border-style":t}):null}function Zee(t){return["solid","dotted","dashed"].includes(t)?ge({"line-style":t}):f0({"line-style":t==="dash-dot"||t==="long-dash"?"dashed":"solid"})}function Qee(t,e,n){const i=Array.from(n).find(([,o])=>o.property===t);if(i===void 0)return null;const[r,s]=i;return s.type==="positive"&&!(typeof e=="number"&&e>0)?null:e===""&&/label$/i.test(t)?ge({[r]:" "}):ge({[r]:typeof e=="boolean"?String(e):e})}function h0(t){return typeof t=="number"?Number.isFinite(t)?String(t):null:typeof t!="string"||t.includes("\\")||/[\n\r\u2028\u2029]/.test(t)?null:t.includes('"')?t.includes("'")?null:`'${t}'`:`"${t}"`}function Jf(t,e,n){const i=t.keys[e].get(n);if(i!==void 0)return{key:i,fresh:!1};let r=TO(n),s=2;for(;t.used[e].has(r);)r=`${TO(n)}_${String(s)}`,s++;return t.keys[e].set(n,r),t.used[e].add(r),{key:r,fresh:!0}}function Zf(t,e,n,i){const r=t.data[e];for(let s=0;s<r.length&&s<i.length;s++){const o=i[s];o!=null&&o!==!1&&(r[s][n]=o)}}function p0(t,e,n){if("all"in n)return n.all?[""]:null;if("has"in n){const i=Fa(t,e,n.has);return i===null||!("style"in n.has)?null:[`[${i}]`]}if("eq"in n)return nk(t,e,n.eq,"=");if("in"in n){const i=Fa(t,e,n.in[0]),r=n.in[1].map(s=>h0(s));return r.length===0?[]:i===null||r.includes(null)?null:r.map(s=>`[${i} = ${String(s)}]`)}return"not"in n?ete(t,e,n.not):"and"in n?tte(t,e,n.and):"or"in n?nte(t,e,n.or):null}function nk(t,e,n,i){const r=Fa(t,e,n[0]),s=h0(n[1]);return r===null||s===null?null:[`[${r} ${i} ${s}]`]}function ete(t,e,n){if("has"in n&&"style"in n.has){const i=Fa(t,e,n.has);return i===null?null:[`[^${i}]`]}return"eq"in n?nk(t,e,n.eq,"!="):null}function tte(t,e,n){let i=[""];for(const r of n){const s=p0(t,e,r);if(s===null||(i=i.flatMap(o=>s.map(l=>o+l)),i.length>8))return null}return i}function nte(t,e,n){const i=[];for(const r of n){const s=p0(t,e,r);if(s===null)return null;i.push(...s)}return i.length>8?null:i}function Fa(t,e,n){if("style"in n){const i=t.extracted.columns[e].get(n.style);if(i===void 0)return null;const{key:r,fresh:s}=Jf(t,e,n.style);return s&&Zf(t,e,r,i),r}return"data"in n&&QD.test(n.data)&&n.data!==vo&&!n.data.startsWith("graphty_")?n.data:null}function ite(t,e,n){const i=`${e.target}${t.scope}`,r=p0(t,e.target,e.where);if(r!==null)return r.map(a=>i+a);const s=Cr(e.target,t.data[e.target].length,t.extracted.columns[e.target],t.extracted.features[e.target]),{key:o}=Jf(t,e.target,`emit.where.${String(n)}`),l=new Array(s.n);for(let a=0;a<s.n;a++)l[a]=Po(e.where,s,a)?!0:null;return Zf(t,e.target,o,l),[`${i}[${o}]`]}function rte(t,e,n){const{target:i}=e,r=ite(t,e,n),s={};for(const[o,l]of Object.entries(e.set??{})){if(l===void 0)continue;const a=zr(t,i,o,l);a!==null&&Object.assign(s,a)}if(Object.keys(s).length>0)for(const o of r)t.stylesheet.push({selector:o,style:s}),i==="edge"&&s["curve-style"]==="straight"&&t.stylesheet.push({selector:`${o}:loop`,style:{"curve-style":"haystack"}});for(const[o,l]of Object.entries(e.map??{}))l!==void 0&&ote(t,e,n,r,o,l)}function ste(t,e,n){const i=u0(t,e,n);return i!==null&&!i.approximate}function zr(t,e,n,i){const r=u0(e,n,i);return r===null?(t.notes.add(v.NOT_WRITTEN,e,n,{sample:i}),null):(r.approximate&&t.notes.add(v.APPROXIMATED,e,n,{sample:i}),r.props)}function ote(t,e,n,i,r,s){const{target:o}=e;if(s.kind==="discrete"){const l=Fa(t,o,s.by),a=s.table.map(([c])=>h0(c));if(l===null||a.includes(null)){IO(t,e,n,i,r);return}s.table.forEach(([,c],d)=>{const u=zr(t,o,r,c);if(u!==null)for(const f of i)t.stylesheet.push({selector:`${f}[${l} = ${String(a[d])}]`,style:u})});return}if(s.kind==="continuous"&<e(o,r)){const l=ate(t,o,s.by,n);if(l!==null){cte(t,o,i,r,l,s.points);return}}IO(t,e,n,i,r)}function lte(t,e){const n=ii[t].get(e);return n==="number"||n==="opacity"||n==="color"}function ate(t,e,n,i){const r=Cr(e,t.data[e].length,t.extracted.columns[e],t.extracted.features[e]),s=r.column(n);if(s===null)return null;if("data"in n&&QD.test(n.data)&&!n.data.startsWith("graphty_"))return n.data;const{key:o}=Jf(t,e,`emit.input.${String(i)}`),l=new Array(r.n);for(let a=0;a<r.n;a++){const c=s[a];l[a]=typeof c=="number"&&Number.isFinite(c)?c:null}return Zf(t,e,o,l),o}function cte(t,e,n,i,r,s){if(s.length===0)return;const o=String,l=(d,u)=>{if(u!==null)for(const f of n)t.stylesheet.push({selector:`${f}${d}`,style:u})},a=s[0],c=s.at(-1)??a;l(`[${r} < ${o(a.at)}]`,zr(t,e,i,a.below));for(let d=0;d+1<s.length;d++){const u=s[d],f=s[d+1],h=zr(t,e,i,u.above),p=zr(t,e,i,f.below);if(h===null||p===null)continue;const g={};for(const m of Object.keys(h))g[m]=`mapData(${r}, ${o(u.at)}, ${o(f.at)}, ${String(h[m])}, ${String(p[m])})`;l(`[${r} > ${o(u.at)}][${r} < ${o(f.at)}]`,g)}l(`[${r} > ${o(c.at)}]`,zr(t,e,i,c.above));for(const d of s)l(`[${r} = ${o(d.at)}]`,zr(t,e,i,d.value))}function IO(t,e,n,i,r){const{target:s}=e,o=t.data[s].length,l=Cr(s,o,t.extracted.columns[s],t.extracted.features[s]),a=new Map(Object.entries(e.map??{})).get(r),c={...e,where:{all:!0},set:void 0,map:{[r]:a}},d=Ni([c],s,r,l),u=new Map;for(let f=0;f<o;f++){const h=d[f];if(h===null)continue;const p=zr(t,s,r,h);if(p!==null)for(const[g,m]of Object.entries(p)){let y=u.get(g);y===void 0&&(y=new Array(o).fill(null),u.set(g,y)),y[f]=m}}for(const[f,h]of u){const{key:p}=Jf(t,s,`emit.value.${String(n)}.${f}`);Zf(t,s,p,h);for(const g of i)t.stylesheet.push({selector:`${g}[${p}]`,style:{[f]:`data(${p})`}})}}function ik(t,e={}){const n=new se,i=e.importId?.replaceAll(/["'\\\n\r\u2028\u2029]/g,"_"),{nodes:r}=t.fingerprint,{edges:s}=t.fingerprint,o={extracted:t,notes:n,scope:i===void 0?"":`[${vo} = "${i}"]`,stylesheet:[],data:{node:Array.from({length:r},()=>({})),edge:Array.from({length:s},()=>({}))},keys:{node:new Map,edge:new Map},used:{node:new Set([vo,...$O(t,"node")]),edge:new Set([vo,...$O(t,"edge")])}};if(i!==void 0)for(const d of[o.data.node,o.data.edge])for(const u of d)u[vo]=i;const l=t.styles.source.tool==="cytoscape-js"?t.styles.rules.filter(d=>d.origin!=="tool"):t.styles.rules;l.forEach((d,u)=>{d.role!=="exceptions"&&rte(o,d,u)});const a=dte(o,l);for(const d of o.stylesheet)xu(d.selector).invalid&&n.add(v.NOT_WRITTEN,null,"selector",{sample:d.selector});const c=d=>d.map(u=>Object.keys(u).length>0?u:null);return{stylesheet:o.stylesheet,elementData:{node:c(o.data.node),edge:c(o.data.edge)},bypass:a,notes:n.list()}}function dte(t,e){const{extracted:n}=t,i=t.data.node.length,r=[];for(let a=0;a<i;a++)r.push({group:"nodes",data:{...CO(n,"node",a),...t.data.node[a],id:`n${String(a)}`}});const s=i>1?"n1":"n0";for(let a=0;a<t.data.edge.length&&i>0;a++)r.push({group:"edges",data:{...CO(n,"edge",a),...t.data.edge[a],id:`e${String(a)}`,source:"n0",target:s}});const o=a0({elements:r,style:t.stylesheet,toolDefaults:!1}),l={node:[],edge:[]};for(const a of["node","edge"]){const c=t.data[a].length,d=Cr(a,c,n.columns[a],n.features[a]),u=new Array(c).fill(null);for(const p of ii[a].keys()){const g=Ni(e,a,p,d);pte(u,a,p,g,o[a].values[p])}const f=p=>Ni(e,a,p,d);a==="node"&&hte(u,f,o.node.values),ute(u,f,o[a].values);const h=[["labelBackgroundOpacity","text-background-opacity","opacity","labelBackground"],["labelBorderOpacity","text-border-opacity","opacity","labelBorderWidth"],["labelOutlineOpacity","text-outline-opacity","labelOpacity","labelOutlineWidth"]];a==="node"&&h.push(["borderOpacity","border-opacity","opacity",null],["outerBorderOpacity","outline-opacity","opacity",null]);for(const p of h)fte(u,f,o[a].values,p);l[a]=u}return l}function ute(t,e,n){const i=e("labelOpacity"),r=e("opacity"),s=o=>typeof o=="number"?o:1;for(let o=0;o<t.length;o++){const[l,a]=[s(i[o]),s(r[o])],c=t[o]?.opacity!==void 0;l===s(n.labelOpacity?.[o])&&!c||Number.isNaN(a)||a<=0||l===a&&c||(l<=a?t[o]={...t[o],"text-opacity":P(l/a)}:l>0&&(t[o]={...t[o],opacity:P(l),"line-opacity":P(a/l),"text-opacity":1}))}}function fte(t,e,n,i){const[r,s,o,l]=i,a=e(r),c=e(o),d=l===null?null:e(l),u=f=>typeof f=="number"?f:1;for(let f=0;f<t.length;f++){if(d!==null&&d[f]===null)continue;const[h,p]=[u(a[f]),u(c[f])],g=t[f]?.opacity!==void 0||t[f]?.["text-opacity"]!==void 0;h===u(n[r]?.[f])&&!g||Number.isNaN(p)||p<=0||h>p||(t[f]={...t[f],[s]:P(h/p)})}}function hte(t,e,n){const i=e("labelFit");for(const r of["width","height"]){const s=e(r);for(let o=0;o<t.length;o++)i[o]==="bounds"&&s[o]===0&&!(n.labelFit?.[o]==="bounds"&&n[r]?.[o]===0)&&(t[o]={...t[o],[r]:"label"})}}function pte(t,e,n,i,r){for(let s=0;s<t.length;s++){const o=i[s],l=o===null||(r?.[s]??null)===o?null:u0(e,n,o);l!==null&&!l.approximate&&(t[s]={...t[s],...l.props})}}function $O(t,e){return t.features[e].flatMap(n=>"data"in n.ref?[n.ref.data]:[])}function CO(t,e,n){const i=Object.create(null);for(const r of t.features[e])"data"in r.ref&&r.values[n]!==null&&(i[r.ref.data]=r.values[n]);return i}const g0=Object.freeze(["node-link","d3","jgf","cytoscape","graphology","vis","obographs"]),rk=Object.freeze([...g0,"adjacency","tree"]),m0="json";function vO(t){const e=t.meta.extra[m0];return I(e)?e:null}function I(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function z(t,e){return Object.hasOwn(t,e)}function sk(t){return typeof t=="string"&&g0.includes(t)}function gte(t){return typeof t=="string"&&rk.includes(t)}function za(t){if(Array.isArray(t)){const n=bm(t);return t.length===0||n!==null&&I(n.data)?"cytoscape":null}if(!I(t))return null;const e=mte(t)??yte(t);return e===void 0?bte(t):e}function mte(t){if(z(t,"elements"))return"cytoscape";if(I(t.graph)&&(z(t.graph,"nodes")||z(t.graph,"edges")))return"jgf";if(Array.isArray(t.graphs))return t.graphs.some(e=>I(e)&&Ote(e))?"obographs":"jgf"}function yte(t){if(!(z(t,"edges")||z(t,"links")))return z(t,"nodes")?z(t,"adjacency")?"adjacency":void 0:z(t,"children")?"tree":null}function bte(t){const e=bm(t.nodes),n=bm(z(t,"edges")?t.edges:t.links);if(I(t.options)&&(z(t.options,"type")||z(t.options,"multi")))return"graphology";const i=z(t,"links")||z(t,"directed")||z(t,"multigraph")||z(t,"graph"),r=i?void 0:_te(e,n);return r!==void 0?r:!i&&n===null&&wte(t.options)?"vis":!z(t,"directed")&&!z(t,"multigraph")&&!z(t,"graph")&&z(t,"links")?"d3":"node-link"}const Ete=["nodes","edges","groups","physics","layout","interaction","manipulation","configure","autoResize","clickToUse","locale","locales","height","width"];function wte(t){return I(t)&&Ete.some(e=>z(t,e))}function _te(t,e){return t!==null&&z(t,"key")&&!z(t,"id")?"graphology":e===null?t!==null&&z(t,"id")&&I(t.attributes)?"graphology":void 0:z(e,"from")?z(e,"to")&&!z(e,"source")?"vis":void 0:z(e,"undirected")||I(e.attributes)?"graphology":void 0}const Ste=new Set(["CLASS","INDIVIDUAL","PROPERTY"]);function Ote(t){if(t===null)return!1;const e=i=>I(i)&&(z(i,"obj")&&(z(i,"sub")||z(i,"subj"))||z(i,"pred")),n=i=>I(i)&&(z(i,"lbl")||z(i,"meta")||Ste.has(i.type));return Array.isArray(t.edges)&&t.edges.some(e)||Array.isArray(t.nodes)&&t.nodes.some(n)}function bm(t){if(!Array.isArray(t))return null;const e=t.find(n=>I(n));return I(e)?e:null}function Nte(t){const e=t.extra[m0];if(!I(e))return{};const n=s=>typeof e[s]=="string"?e[s]:void 0,i=s=>typeof e[s]=="boolean"?e[s]:void 0,{nodeIdKey:r}=e;return{dialect:sk(e.dialect)?e.dialect:void 0,edgesKey:n("edgesKey"),nodeIdKey:r===null||typeof r=="string"?r:void 0,indexLinks:i("indexLinks"),sourceKey:n("sourceKey"),targetKey:n("targetKey"),id:n("id"),type:n("type"),allowSelfLoops:i("allowSelfLoops"),cytoscape:I(e.cytoscape)?e.cytoscape:void 0}}const ok=Object.freeze({"node-link":!1,d3:!1,jgf:!0,cytoscape:!0,graphology:!0,vis:!1,adjacency:!1,tree:!0,obographs:!0}),Ate=Object.freeze(["f64","i32","bool","string"]),wo={multiEdges:!0,selfLoops:!0,idCharset:"any",dtypes:Ate,components:!1,lists:!1,json:!0,defaults:!1,options:!1,temporal:"none",positions:!1,viz:!1},Tte=Object.freeze({"node-link":Je({...wo,mixedDirection:!1,edgeIds:"none",hierarchy:!1,graphAttributes:!0}),d3:Je({...wo,mixedDirection:!1,edgeIds:"none",hierarchy:!1,graphAttributes:!1}),jgf:Je({...wo,mixedDirection:!0,edgeIds:"optional",hierarchy:!1,graphAttributes:!0}),cytoscape:Je({...wo,positions:!0,mixedDirection:!1,edgeIds:"required",hierarchy:!0,graphAttributes:!0}),graphology:Je({...wo,mixedDirection:!0,edgeIds:"optional",hierarchy:!1,graphAttributes:!0}),vis:Je({...wo,mixedDirection:!1,edgeIds:"optional",hierarchy:!1,graphAttributes:!1}),obographs:Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"any"})});function Qf(t){return Tte[t]}const lk=new Set(["selected","selectable","locked","grabbable","pannable","removed","scratch","renderedPosition"]),Ite=new Set(["data","group","position","classes"]),Lt=Object.freeze({data:"#data",element:"#element"}),y0=Object.freeze(["source","src","from"]),b0=Object.freeze(["target","dst","to"]),$te="position",ak="classes",Cte="parent";function eh(t){const e=/^(-?)(\d{16,})$/.exec(t);if(e===null||Number.isSafeInteger(Number(t)))return t;const[,n,i]=e,r=dT(i),s=r.length>1?`.${r.slice(1)}`:"";return`${n}${r[0]}${s}e+${i.length-1}`}const vte=.5,Wr=8192;function Dte(t,e){const n=e?0:t.lastIndexOf(".")+1;for(let i=n;i<t.length;i++)if(t[i]==="?"||t[i]==="#")return i;return t.length}function kte(t){const e=/^[a-z][a-z\d+.-]+:/i.test(t),n=t.slice(0,Dte(t,e)),i=n.slice(Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\"))+1),r=i.lastIndexOf(".");return r<=0||r===i.length-1?null:i.slice(r).toLowerCase()}function Rte(t){const e=t.indexOf(";");return(e<0?t:t.slice(0,e)).trim().toLowerCase()}function E0(t){if(typeof t=="string")return new TextEncoder().encode(t.slice(0,Wr)).subarray(0,Wr);if(t.byteLength>=2&&(t[0]===255&&t[1]===254||t[0]===254&&t[1]===255)){const e=t[0]===255?"utf-16le":"utf-16be";return E0(new TextDecoder(e).decode(t.subarray(0,Wr)))}return t.byteLength>Wr?t.subarray(0,Wr):t}function DO(t,e,n){const i=typeof t.filename=="string"?kte(t.filename):null,r=typeof t.mimeType=="string"?Rte(t.mimeType):null,s=t.head===void 0||t.head===null?null:E0(t.head),o=[...e],l=i!==null&&o.some(d=>d.extensions.some(u=>u.toLowerCase()===i)),a=[];let c=0;for(const d of o){const u=i!==null&&d.extensions.some(b=>b.toLowerCase()===i),f=r!==null&&d.mimeTypes.some(b=>b.toLowerCase()===r),h=s!==null&&s.byteLength>0&&typeof d.sniff=="function",p=h?Lte(d,s,n):0,g=Pte(p,{extensionMatch:u,mimeMatch:f,extensionClaimed:l,sniffed:h});if(g===null)continue;const m=d.format==="json"&&s!==null?ck(s):null,y=Object.freeze({format:d.format,confidence:Math.min(1,g),content:p,extension:u,mimeType:f,dialect:m});a.push({result:y,rank:c++})}return a.sort((d,u)=>u.result.confidence-d.result.confidence||d.rank-u.rank),a.map(d=>d.result)}function Lte(t,e,n){try{return Vte(t.sniff?.(e)??0)}catch(i){return n?.(t.format,i),0}}function Pte(t,e){const{extensionMatch:n,mimeMatch:i}=e,r=i?.05:0;return t>0&&t<vte&&e.extensionClaimed&&!n?.25*t+r:t>0?.5+.35*t+(n?.1:0)+r:n||i&&!e.sniffed?(n?.3:0)+(i?.1:0):null}function ck(t){const e=typeof t=="string"?t:new TextDecoder("utf-8",{fatal:!1}).decode(t),i=(e.charCodeAt(0)===65279?e.slice(1):e).trimStart();if(!i.startsWith("{")&&!i.startsWith("["))return null;let r;try{r=JSON.parse(i)}catch{const s=xte(i);if(r=s,typeof s=="object"&&s!==null&&!Array.isArray(s)&&!["edges","links","directed","multigraph","graph"].some(o=>o in s)){const o=za(s);return o==="node-link"?null:o}}return za(r)}function xte(t){const e=Gte(t);if(t.startsWith("[")){const r=e.get("nodes[0]");return r===void 0?null:[Wa(r)]}const n=e.get("");if(n===void 0)return null;const i={};for(const r of n)i[r]=Mte(r,e);return i}function Mte(t,e){switch(t){case"graph":case"options":return Wa(e.get(t));case"graphs":return Ute(e);case"nodes":case"edges":case"links":{const n=e.get(`${t}[0]`);return n===void 0?[]:[Wa(n)]}default:return!0}}function Ute(t){const e=t.get("graphs[0].nodes[]"),n=t.get("graphs[0].edges[]");if(e===void 0&&n===void 0)return[];const i={};return e!==void 0&&(i.nodes=[Wa(e)]),n!==void 0&&(i.edges=[Wa(n)]),[i]}function Wa(t){const e={};if(t!==void 0)for(const n of t)e[n]=n==="attributes"||n==="data"?{}:!0;return e}function Gte(t){const e=new Map,n=[],i=[],r=[];let s=null,o=!1,l=0;const a=t.length;for(;l<a;){const c=t[l];if(c==='"'){const d=Bte(t,l+1);if(d<0)break;const u=t.slice(l+1,d);l=d+1,o&&(s=Hte(u),o=!1);continue}if(c==="{"||c==="["){let d="";n.length>0&&(d=n.at(-1)==="object"?s??"":String(r.at(-1))),n.push(c==="{"?"object":"array"),i.push(d),r.push(0),o=c==="{",s=null}else if(c==="}"||c==="]")n.pop(),i.pop(),r.pop(),o=!1,s=null;else if(c===":"){if(s!==null){const d=jte(n,i);if(d!==null){let u=e.get(d);u===void 0&&(u=new Set,e.set(d,u)),u.add(s)}}}else if(c===","){const d=n.length-1;d>=0&&(r[d]++,o=n[d]==="object"),s=null}l++}return e}function jte(t,e){switch(t.length){case 1:return t[0]==="object"?"":null;case 2:return Fte(t,e);case 3:return zte(t,e);case 5:return Wte(t,e);default:return null}}function Fte(t,e){return t[0]==="array"&&t[1]==="object"&&e[1]==="0"?"nodes[0]":t[0]==="object"&&t[1]==="object"&&(e[1]==="graph"||e[1]==="options")?e[1]:null}function zte(t,e){if(t[0]!=="object"||t[1]!=="array"||t[2]!=="object"||e[2]!=="0")return null;const n=e[1];return n==="nodes"||n==="edges"||n==="links"?`${n}[0]`:null}function Wte(t,e){return t.join()!=="object,array,object,array,object"||e[1]!=="graphs"||e[2]!=="0"?null:e[3]==="nodes"?"graphs[0].nodes[]":e[3]==="edges"?"graphs[0].edges[]":null}function Bte(t,e){let n=e;for(;n<t.length;){const i=t[n];if(i==="\\"){n+=2;continue}if(i==='"')return n;n++}return-1}function Hte(t){if(!t.includes("\\"))return t;try{return JSON.parse(`"${t}"`)}catch{return t}}function Vte(t){return t>0?Math.min(t,1):0}const Yte={padding:30},Kte=["vx","vy","fx","fy","index","physics"];function Xte(t){if(t.nodes.byRole("position")!==null)return vO(t)?.dialect==="cytoscape"?{containersFollowChildren:!0}:null;const e=bp(t.nodes.get("x")),n=bp(t.nodes.get("y"));if(e===null||n===null)return null;const i=bp(t.nodes.get("z")),r=vO(t)?.dialect,s=r!=="graphology"&&Kte.some(l=>t.nodes.get(l)!==null),o=i===null&&(r==="vis"||s);return{x:e.meta.name,y:n.meta.name,...i===null?{}:{z:i.meta.name},yAxis:o?"down":"up",units:o?"px":"file",...r==="graphology"?{viewerFit:Yte}:{}}}function bp(t){const e=["f64","f32","i32","u32","u8"];return t!==null&&t.meta.components===1&&e.includes(t.dtype)?t:null}const dk={renderEdgeLabels:!1,edgeLabelAnchors:"nodeLabels"},w0=["node","edge"];function qte(t,e){const n=e.kept;if(!I(n))return null;switch(n.dialect){case"cytoscape":return Jte(t,n,e);case"graphology":return nne(t,n,e);case"vis":return Hne(t,n,e);case"node-link":return n.networkx===!0?ene(t):n.block===null?null:{canonical:!0,block:n.block};default:return n.block===null?null:{canonical:!0,block:n.block}}}function Jte(t,e,n){const i=(e.style===void 0||e.style===null)&&e.generatedBy?.startsWith("cytoscape-")===!0,r=e.block!==null&&ac(e.block,ro(t)).ok,s=Uee({elements:Qte(e.elements,e.generatedIds),style:i?[]:e.style??[],snapshot:t,toolDefaults:!r&&!i,budget:n.budget,signal:n.signal});if(!("canonical"in s))return s;let o="cytoscape-js";return r?(o=null,S0(t,e.block,{node:s.node?.values??{},edge:s.edge?.values??{}},Zte,ste)):i&&(o="cytoscape"),{...s,tool:o,block:e.block}}const kO=t=>e=>{const n=e(t);return typeof n=="string"?n.trim():null},Em={node:["label"],edge:["label","sourceLabel","targetLabel"]},Zte={node:Object.fromEntries(Em.node.map(t=>[t,kO(t)])),edge:{...Object.fromEntries(Em.edge.map(t=>[t,kO(t)])),curved:(t,e,n)=>n.edgeSource(e)===n.edgeTarget(e)&&t("curved")!==null?!0:t("curved")}};function Qte(t,e){if(e===void 0||e.size===0)return t;const n=i=>{const r=I(i)?e.get(i):void 0;return r===void 0||!I(i)?i:{...i,data:{...i.data,id:r}}};return Array.isArray(t)?t.map(n):I(t)&&Array.isArray(t.nodes)?{...t,nodes:t.nodes.map(n)}:t}function ene(t){return{canonical:!0,dialect:null,tool:"networkx",units:"px",node:{values:{}},edge:tne(t)}}function tne(t){if(!t.directed||t.edgeCount===0)return{values:{},rules:[],columns:new Map};const e=t.edges.byRole("directed"),n=Array.from({length:t.edgeCount},(i,r)=>e===null||K(e.value(r))!==!1?!0:null);return{values:{},rules:[{id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:"directed"}},set:{targetArrow:"triangle"}}],columns:new Map([["directed",n]])}}function br(t,e,n){const i=e==="node"?t.nodes:t.edges;return i.has(n)?r=>K(i.value(n,r)):null}function _0(t){const e={};return{values:e,put:(n,i,r)=>{r!==null&&uk(e,n,t,i,r)}}}function uk(t,e,n,i,r){t[e]??=new Array(n).fill(null),t[e][i]=r}function nne(t,e,n){const i=new se,r={node:{},edge:{}},s={node:[],edge:[]},o=ine(t,e.sigma??dk);for(const l of w0){const a=l==="node"?t.nodeCount:t.edgeCount,{values:c,put:d}=_0(a),u={color:br(t,l,"color"),size:br(t,l,"size"),label:br(t,l,"label")};s[l].push(...Object.entries(u).flatMap(([f,h])=>h===null?[]:[f]));for(let f=0;f<a;f++){const h=p=>({notes:i,target:l,property:p,element:f,budget:n.budget});rne(u,l,l==="node"||o(f),f,d,h)}r[l]=c}return S0(t,lne(t,e),r,cne),{canonical:!0,dialect:"graphology",tool:"sigma",opacityInColor:!0,units:"relative",node:{values:r.node},edge:{values:r.edge},notes:i.list(),readFrom:s}}function ine(t,e){if(!e.renderEdgeLabels)return()=>!1;if(e.edgeLabelAnchors==="allNodes")return()=>!0;const n=br(t,"node","label"),i=r=>{const s=n?.(r);return typeof s=="string"?s!=="":s!=null};return r=>i(t.edgeSource(r))&&i(t.edgeTarget(r))}function rne(t,e,n,i,r,s){const{color:o,size:l,label:a}=t;if(o!==null){const[c,d]=e==="node"?["fill","fillOpacity"]:["color","opacity"];one(r,c,d,i,o(i),s(c))}if(l!==null&&sne(r,e,i,l(i),s),a!==null&&n){const c=rt(a(i),s("label"));r("label",i,c===null?null:c.replaceAll(/[\t\n\f\r]/g," "))}}function sne(t,e,n,i,r){if(e==="node"){const s=Number(i)<0?0:Y(i,r("width")),o=s===null?null:s*2;t("width",n,o),t("height",n,o)}else{const s=Y(i,r("width"));t("width",n,s===null?null:s/2)}}function one(t,e,n,i,r,s){if(r==null)return;const o=ve(r,"graphology",s);o!==null&&(t(e,i,o.color),o.alpha<1&&(n===null?s.notes.add(v.ALPHA_DROPPED,s.target,e,{sample:r,element:i}):t(n,i,o.alpha)))}function lne(t,e){if(e.block!==null)return e.block;if(!t.graph.has(Z))return null;const n=K(t.graph.value(Z,0));return typeof n=="string"?n:null}function S0(t,e,n,i,r){so(t,e,"json",(s,o,l)=>{const a=s==="node"?t.nodeCount:t.edgeCount;if(r!==void 0){const d=new Set(l.styles.rules.filter(u=>u.target===s).flatMap(u=>[...Object.keys(u.set??{}),...Object.keys(u.map??{})]));for(const u of d){const f=h=>r(s,u,h);ane(n[s],u,o(s,u),a,f)}}const c=i[s]??{};return{values:n[s],properties:Object.keys(c),readBack:(d,u)=>f=>c[f](u,d,t),take:(d,u,f)=>f!==null}})}function ane(t,e,n,i,r){for(let s=0;s<i;s++){const o=n[s];o!==null&&!r(o)&&uk(t,e,i,s,o)}}const wm=t=>{const e=t("width"),n=t("height");return typeof e=="number"&&typeof n=="number"?Math.max(e,n):e??n},cne={node:{width:wm,height:wm}},Ll=new Set(["image","circularImage","diamond","dot","star","triangle","triangleDown","hexagon","square","icon"]),dne=new Map([["box",{square:!1,ellipse:!1}],["text",{square:!1,ellipse:!1}],["circle",{square:!0,ellipse:!1}],["database",{square:!0,ellipse:!1}],["ellipse",{square:!1,ellipse:!0}]]),O0=5,N0=14,RO=[["#2B7CE9","#97C2FC"],["#FFA500","#FFFF00"],["#FA0A10","#FB7E81"],["#41A906","#7BE141"],["#E129F0","#EB7DF4"],["#7C29F0","#AD85E4"],["#C37F00","#FFA807"],["#4220FB","#6E6EFD"],["#FD5A77","#FFC0CB"],["#4AD63A","#C2FABC"],["#990000","#EE0000"],["#FF6000","#FF6000"],["#97C2FC","#2B7CE9"],["#399605","#255C03"],["#B70054","#FF007E"],["#AD85E4","#7C29F0"],["#4557FA","#000EA1"],["#FFC0CB","#FD5A77"],["#C2FABC","#74D66A"],["#EE0000","#990000"]],une="#97C2FC",fne="#2B7CE9",hne="#848484";function pne(t){let e=t;const n=/^rgb\( *(\d{1,3}) *, *(\d{1,3}) *, *(\d{1,3}) *\)$/i.exec(t);if(n?.slice(1).every(r=>Number(r)<=255)&&(e=`#${((1<<24)+(Number(n[1])<<16)+(Number(n[2])<<8)+Number(n[3])).toString(16).slice(1)}`),!/^#([0-9a-f]{6}|[0-9a-f]{3})$/i.test(e))return{background:t,border:t};const i=e.length===4?`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}`:e;return{background:i,border:gne(i)}}function gne(t){const e=Number.parseInt(t.slice(1),16),[n,i,r]=[e>>16&255,e>>8&255,e&255].map(y=>y/255),s=Math.max(n,i,r),o=Math.min(n,i,r);let l=0,a=0;if(s!==o){let y=r-n,b=5;n===o?(y=i-r,b=3):r===o&&(y=n-i,b=1),l=60*(b-y/(s-o))/360,a=(s-o)/s}const c=Math.min(1,a*1.25),d=s*.8,u=Math.floor(l*6),f=l*6-u,h=d*(1-c),p=d*(1-f*c),g=d*(1-(1-f)*c),m=[[d,g,h],[p,d,h],[h,d,g],[h,p,d],[g,h,d],[d,h,p]][u%6].map(y=>Math.floor(y*255));return`#${((1<<24)+(m[0]<<16)+(m[1]<<8)+m[2]).toString(16).slice(1)}`}function Gs(t,e){if(!I(t))return{};const n={},i=(r,s)=>{s!=null&&(n[r]=s)};return e==="node"?mne(t,i):_ne(t,i),i("hidden",t.hidden),i("label",t.label),i("title",t.title),i("wrapWidth",I(t.widthConstraint)?t.widthConstraint.maximum:t.widthConstraint),I(t.scaling)&&i("scalingLabel",t.scaling.label),Sne(t.font,i),e==="edge"&&t.font!==void 0&&t.font!==null&&i("fontText",typeof t.font=="string"),n}function mne(t,e){const{color:n}=t;if(typeof n=="string"){const i=pne(n.trim());e("fill",i.background),e("border",i.border)}else I(n)&&(e("fill",n.background),e("border",n.border));e("shape",t.shape),e("size",t.size),e("value",t.value),I(t.scaling)&&(e("scalingMin",t.scaling.min),e("scalingMax",t.scaling.max)),e("borderWidth",t.borderWidth),e("opacity",t.opacity),e("margin",t.margin),e("widthMin",I(t.widthConstraint)?t.widthConstraint.minimum:t.widthConstraint),e("heightMin",I(t.heightConstraint)?t.heightConstraint.minimum:t.heightConstraint),e("valign",I(t.heightConstraint)?t.heightConstraint.valign:void 0),e("image",I(t.image)?t.image.unselected:t.image),e("brokenImage",t.brokenImage),e("imagePadding",t.imagePadding),I(t.icon)&&(e("iconCode",t.icon.code),e("iconFace",t.icon.face),e("iconSize",t.icon.size),e("iconColor",t.icon.color),e("iconWeight",t.icon.weight)),I(t.shapeProperties)&&(e("useImageSize",t.shapeProperties.useImageSize),e("useBorderWithImage",t.shapeProperties.useBorderWithImage),e("interpolation",t.shapeProperties.interpolation),e("coordinateOrigin",t.shapeProperties.coordinateOrigin),e("borderDashes",t.shapeProperties.borderDashes),e("borderRadius",t.shapeProperties.borderRadius))}function yne(t,e,n){const i=d=>typeof d=="string"&&d!==""?d:null,[r,s]=[i(t.image),i(t.brokenImage)],o=r??s;if(e!=="image"&&e!=="circularImage"||o===null)return{};const l=e==="circularImage",a={image:o,...r!==null&&s!==null?{imageFallback:s}:{},imageFit:t.useImageSize===!0?"none":"cover",imageClip:l?"node":"none",shape:"ellipse"};l||(a.shape=t.useBorderWithImage===!0?"rectangle":"none"),t.interpolation===!1&&(a.imageSmoothing=!1);const c=typeof t.opacity=="number"&&t.opacity>=0&&t.opacity<1?t.opacity:null;return c!==null&&(a.imageOpacity=c),bne(a,t,n),a}function bne(t,e,n){const i=wne(e.imagePadding);i!==null&&e.useImageSize!==!0&&(t.imageFit="none",t.imageWidth=Math.max(0,n.width-i.left-i.right),t.imageHeight=Math.max(0,n.height-i.top-i.bottom),t.imageOffsetX=(i.left-i.right)/2,t.imageOffsetY=(i.top-i.bottom)/2),e.coordinateOrigin==="top-left"&&t.shape==="none"&&(t.imageOffsetX=n.width/2+(typeof t.imageOffsetX=="number"?t.imageOffsetX:0),t.imageOffsetY=n.height/2+(typeof t.imageOffsetY=="number"?t.imageOffsetY:0))}function Ene(t,e){const n=typeof t.iconCode=="string"&&t.iconCode!==""?t.iconCode:null;if(n===null)return{};const i=typeof t.iconSize=="number"&&t.iconSize>=0?t.iconSize:50,r=typeof t.iconColor=="string"?ve(t.iconColor,"vis",e):null,s=t.iconWeight,o=s==="bold"||s==="bolder"||typeof s=="number"&&s>=600;return{glyph:n,glyphFont:typeof t.iconFace=="string"&&t.iconFace!==""?t.iconFace:"FontAwesome",glyphSize:i,glyphColor:r?.color??"#2b7ce9",glyphWeight:o?"bold":"normal"}}function wne(t){const e=i=>typeof i=="number"&&Number.isFinite(i)&&i>0?i:0;let n=null;return typeof t=="number"?n={top:e(t),right:e(t),bottom:e(t),left:e(t)}:I(t)&&(n={top:e(t.top),right:e(t.right),bottom:e(t.bottom),left:e(t.left)}),n===null||n.top+n.right+n.bottom+n.left===0?null:n}function _ne(t,e){const{color:n}=t;if(typeof n=="string")e("edgeColor",n),e("inherit",!1);else if(I(n)){e("edgeColor",n.color),e("edgeOpacity",n.opacity);const i=n.color!==void 0||n.highlight!==void 0||n.hover!==void 0;e("inherit",i?!1:n.inherit)}e("width",t.width),e("value",t.value),I(t.scaling)&&(e("scalingMin",t.scaling.min),e("scalingMax",t.scaling.max)),e("dashes",t.dashes),e("arrows",t.arrows),e("background",t.background),e("smooth",t.smooth),e("selfReference",t.selfReference),e("selfReferenceSize",t.selfReferenceSize),e("physics",t.physics),e("length",t.length)}function Sne(t,e){if(I(t)){e("fontMulti",t.multi),e("fontStrokeWidth",t.strokeWidth),e("fontStrokeColor",t.strokeColor),e("fontBackground",t.background),e("fontAlign",t.align),e("fontColor",t.color),e("fontSize",t.size),e("fontFace",t.face),e("fontVadjust",t.vadjust);const n=["bold","ital","boldital","mono"].filter(i=>t[i]!==void 0&&t[i]!==null);n.length>0&&e("fontMods",Object.fromEntries(n.map(i=>[i,t[i]])))}else if(typeof t=="string"){const n=/^\s*(\d+(?:\.\d+)?)(?:px)?\s+(\S+)(?:\s+(\S+))?/.exec(t.slice(0,256));n!==null&&(e("fontSize",Number(n[1])),e("fontFace",n[2]),e("fontColor",n[3]))}}function gc(t,e,n,i){const r={},s=(l,a)=>{a!==null&&(r[l]=a)},o=(l,a,c)=>{if(c==null||c==="")return;const d=ve(c,"vis",n(l));d!==null&&(s(l,d.color),d.alpha<1&&a!==null&&s(a,d.alpha))};return e==="node"?(o("fill","fillOpacity",t.fill),o("borderColor","borderOpacity",t.border),jne(t,i,s,n)):(o("color","opacity",t.edgeColor),zne(t,s,n),One(t,s,o)),t.hidden!==void 0&&rc(t.hidden,n("visible"))===!0&&s("visible",!1),Nne(t,e,s,o,n),r}function One(t,e,n){if(!I(t.background))return;const i=t.background,r=t.smooth===!1||I(t.smooth)&&t.smooth.enabled===!1;if(n("outlineColor","outlineOpacity",i.color),i.enabled!==void 0){const o=typeof i.size=="number"?i.size:10,l=typeof t.width=="number"?t.width:1;e("outlineWidth",i.enabled===!0&&!r?Math.max(0,o-l):0)}const s=fk(i,!1);s!==null&&e("outlineStyle",s)}function Nne(t,e,n,i,r){t.fontSize!==void 0&&n("labelSize",Y(t.fontSize,r("labelSize"))),t.fontFace!==void 0&&n("labelFont",rt(t.fontFace,r("labelFont"))),t.label!==void 0&&Ane(t,e,n,r),typeof t.wrapWidth=="number"&&Number.isFinite(t.wrapWidth)&&t.wrapWidth>0&&(n("labelWrapWidth",t.wrapWidth),n("labelWrapSpaceCount",3)),t.title!==void 0&&n("tooltip",rt(t.title,r("tooltip")));const s=I(t.scalingLabel)?t.scalingLabel.drawThreshold:void 0;typeof s=="number"&&Number.isFinite(s)&&n("labelMinScreenSize",Math.max(0,s-1)),Tne(t,e,n,i,r)}function Ane(t,e,n,i){const r=e==="edge"&&t.fontText===!0?"":rt(t.label,i("label")),s=typeof r=="string"?$ne(r,t.fontMulti):null;if(n("label",s?.text??r),s!==null){const o=vne(s.runs,t,i("labelRuns"));n("labelRuns",o),o!==null&&n("labelRunAlign",Dne(t,e))}for(const[o,l]of Object.entries(Ine[s?.mod??"normal"]??{}))n(o,l)}function Tne(t,e,n,i,r){i("labelColor",null,t.fontColor),i("labelBackground",null,t.fontBackground==="none"?void 0:t.fontBackground),typeof t.fontBackground=="string"&&t.fontBackground!=="none"&&(n("labelPadding",0),n("labelLineHeight",1));const s=typeof t.fontStrokeWidth=="number"&&t.fontStrokeWidth>0;i("labelOutlineColor",null,t.fontStrokeColor??(s?"#ffffff":void 0)),t.fontStrokeWidth!==void 0&&n("labelOutlineWidth",Y(t.fontStrokeWidth,r("labelOutlineWidth"))),e==="edge"&&typeof t.fontAlign=="string"?n("labelPosition",t.fontAlign==="top"||t.fontAlign==="bottom"?t.fontAlign:"center"):e==="node"&&typeof t.fontAlign=="string"&&n("labelTextAlign",{center:"center",right:"right"}[t.fontAlign]??"left"),typeof t.fontVadjust=="number"&&Number.isFinite(t.fontVadjust)&&t.fontVadjust!==0&&n("labelOffsetY",t.fontVadjust)}const Ine={bold:{labelWeight:"bold"},ital:{labelItalic:!0},boldital:{labelWeight:"bold",labelItalic:!0},mono:{labelFont:"monospace"}};function LO(t){return t===void 0?!0:typeof t=="string"&&!t.includes("rgba")&&(t.includes("rgb")||/^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i.test(t.trim()))}function fk(t,e){return t.dashes===void 0||t.dashes===!1?null:th(t.dashes===!0?[5,5]:t.dashes,typeof t.size=="number"?t.size:10,e)}function th(t,e,n){if(!Array.isArray(t))return t===!1?"solid":"dashed";const i=t.filter(c=>typeof c=="number"&&Number.isFinite(c)),r=i.length%2===1?[...i,...i]:i,s=n?e:0,o=r.filter((c,d)=>d%2===0).map(c=>Math.max(0,c)+s),l=r.filter((c,d)=>d%2===1).map(c=>Math.max(0,c-s)),a=c=>c.reduce((d,u)=>d+u,0);return o.length===0||a(l)<.1*(a(o)+a(l))?"solid":o.every(c=>c<=1.5*Math.max(1,e))?"dotted":Math.max(...o)>=2*Math.min(...o)?"dash-dot":"dashed"}function $ne(t,e){const n=Pne.get(e);if(n===void 0)return null;const i={bold:!1,ital:!1,mono:!1},r=[],s=t.slice(0,4096);let o=0;for(;o<s.length;){const d=Mne(s,o,n,i);if(d>0){o+=d;continue}const[u,f]=Une(s,o,n);r.push({text:u,mod:Gne(i)}),o=f}const l=new Set(r.filter(d=>/\S/.test(d.text)).map(d=>d.mod)),a=l.size===1?[...l][0]:null,c=[];for(const d of r){const u=c.at(-1);u?.mod===d.mod?u.text+=d.text:c.push({...d})}return{text:r.map(d=>d.text).join(""),mod:a==="normal"?null:a,runs:c}}const Cne={bold:{mod:"bold"},ital:{mod:"italic"},boldital:{mod:"bold italic"},mono:{mod:"",face:"monospace",size:15,vadjust:2}};function vne(t,e,n){const i={face:typeof e.fontFace=="string"?e.fontFace:"arial",size:typeof e.fontSize=="number"?e.fontSize:N0,color:typeof e.fontColor=="string"?e.fontColor:null,vadjust:typeof e.fontVadjust=="number"&&Number.isFinite(e.fontVadjust)?e.fontVadjust:0},r=I(e.fontMods)?e.fontMods:{};let s=!1;const o=t.map(l=>{const a={text:l.text},c=Cne[l.mod];if(c===void 0)return a;const d=Lne(r[l.mod]),u=typeof d.mod=="string"?d.mod:c.mod,f=typeof d.face=="string"?d.face:c.face??i.face,h=typeof d.size=="number"?d.size:c.size??i.size,p=typeof d.vadjust=="number"?d.vadjust:c.vadjust??i.vadjust,g=typeof d.color=="string"?ve(d.color,"vis",n)?.color:null;return u.includes("bold")&&(a.weight="bold"),u.includes("italic")&&(a.italic=!0),f!==null&&f!==i.face&&(a.font=f),h!==i.size&&(a.size=h),Number.isFinite(p)&&p!==i.vadjust&&(a.shift=p-i.vadjust),typeof g=="string"&&(a.color=g),s||=Object.keys(a).length>1,a});return s?JSON.stringify(o):null}function Dne(t,e){if(e==="edge")return{top:"baseline",bottom:"hanging"}[String(t.fontAlign)]??"middle";const n=typeof t.shape=="string"?t.shape:"ellipse";return Ll.has(n)?"hanging":"middle"}function kne(t){return 2+t/6}function Rne(t,e){let n;try{n=JSON.parse(t)}catch{return 0}if(!Array.isArray(n))return 0;const i=[e];for(const r of n){const s=typeof r.size=="number"?r.size:e;(typeof r.text=="string"?r.text:"").split(`
|
|
176
|
+
`).forEach((o,l)=>{l>0&&i.push(e),o!==""&&(i[i.length-1]=Math.max(i.at(-1)??e,s))})}return i.reduce((r,s)=>r+s-e,0)/2}function Lne(t){if(I(t))return t;if(typeof t=="string"){const e=/^\s*(\d+(?:\.\d+)?)(?:px)?\s+(\S+)(?:\s+(\S+))?/.exec(t.slice(0,256));if(e!==null)return{size:Number(e[1]),face:e[2],...e[3]===void 0?{}:{color:e[3]}}}return{}}const Pne=new Map([[!0,"html"],["html","html"],["markdown","md"],["md","md"]]),xne={html:{"<b>":"bold","</b>":"bold","<i>":"ital","</i>":"ital","<code>":"mono","</code>":"mono"},md:{"*":"bold",_:"ital","`":"mono"}};function Mne(t,e,n,i){const r=xne[n],s=Object.keys(r).find(a=>t.startsWith(a,e));if(s===void 0)return 0;const o=r[s];return(n==="html"?i[o]===s.startsWith("</"):i[o]||e===0||/\s/.test(t[e-1]))?(i[o]=!i[o],s.length):0}function Une(t,e,n){if(n==="md")return t[e]==="\\"&&e+1<t.length?[t[e+1],e+2]:[t[e],e+1];const i=[["<","<"],["&","&"]].find(([r])=>t.startsWith(r,e));return i===void 0?[t[e],e+1]:[i[1],e+i[0].length]}function Gne(t){return t.mono?"mono":t.bold?t.ital?"boldital":"bold":t.ital?"ital":"normal"}function jne(t,e,n,i){if(t.shape!==void 0&&(n("shape",le("shape",t.shape,"vis",i("shape"))),typeof t.shape=="string"&&n("labelPosition",Ll.has(t.shape)?"bottom":"center")),e&&t.size!==void 0){const r=Y(t.size,i("width"));n("width",r===null?null:2*r),n("height",r===null?null:2*r)}t.borderWidth!==void 0&&n("borderWidth",Y(t.borderWidth,i("borderWidth"))),Fne(t,n,i)}function Fne(t,e,n){if(t.opacity!==void 0){const i=ic(t.opacity,"vis",n("opacity"));e("opacity",LO(t.fill)?i:null),e("borderOpacity",LO(t.border)?i:null)}if(t.borderDashes!==void 0){const i=typeof t.borderWidth=="number"?t.borderWidth:1;e("borderStyle",th(t.borderDashes===!0?[5,15]:t.borderDashes,i,!1))}}function zne(t,e,n){if(t.edgeOpacity!==void 0&&e("opacity",ic(t.edgeOpacity,"vis",n("opacity"))),t.width!==void 0&&e("width",Y(t.width,n("width"))),t.dashes!==void 0){const i=typeof t.width=="number"?t.width:1,r=t.dashes===!0?[5,5]:t.dashes;e("lineStyle",t.dashes==="false"?"solid":th(r,i,!0))}if(t.arrows!==void 0){const[i,r,s]=Bne(t.arrows,n);e("targetArrow",i),e("sourceArrow",r),e("midTargetArrow",s);const o=a=>{const c=I(t.arrows)?t.arrows[a]:void 0;return I(c)?c.scaleFactor:void 0},l=o("to")??o("from")??o("middle");l!==void 0&&e("arrowSize",Y(l,n("arrowSize"))),Wne(t.arrows,e,n)}}function Wne(t,e,n){if(I(t))for(const[i,r]of[["to","targetArrow"],["from","sourceArrow"],["middle","midTargetArrow"]]){const s=t[i];!I(s)||s.type!=="image"||typeof s.src!="string"||s.src===""||(e(`${r}Image`,s.src),s.imageWidth!==void 0&&e(`${r}ImageWidth`,Y(s.imageWidth,n(`${r}ImageWidth`))),s.imageHeight!==void 0&&e(`${r}ImageHeight`,Y(s.imageHeight,n(`${r}ImageHeight`))))}}function Bne(t,e){const n=(i,r,s="none")=>{if(typeof t=="string")return new RegExp(String.raw`\b${i}\b`).test(t.slice(0,256))?"triangle":s;if(!I(t))return null;const o=t[i];return o===!0?"triangle":o===void 0?s:!I(o)||o.enabled===!1?"none":le("arrow",o.type??"arrow","vis",e(r))};return[n("to","targetArrow"),n("from","sourceArrow"),n("middle","midTargetArrow",null)]}function Hne(t,e,n){const i=new se,r=I(e.options)?e.options:{},s=t.nodeCount,o=B=>Q=>({notes:i,target:B,property:Q}),l=[],a=new Map,c=Gs(r.nodes,"node"),d=br(t,"node","group"),u=B=>{const Q=d?.(B);return typeof Q=="string"||typeof Q=="number"?String(Q):null},{groupLayers:f,paletteRows:h}=nie(s,u,MO(e,r));n.budget.spend("node",s);const p=_0(s),g=[],m=yk(t,"node"),y=Vne(s,u,m,f,c),b=iie(f,MO(e,r));for(let B=0;B<s;B++){const Q=u(B),be=m(B),De=Gs(be,"node"),J=Q===null?{}:b(Q,be),st=Ep(De)??Ep(J)??Ep(c)??"ellipse";g.push(st);const ee=us=>({notes:i,target:"node",property:us,element:B,budget:n.budget}),Ke=Yne(c,J,De,Q!==null&&be.color!==void 0);for(const[us,ze]of Object.entries(Kne(Ke,st,y,ee)))p.put(us,B,ze)}const _=gc(c,"node",o("node"),!0);Object.keys(_).length>0&&l.push(T0("node.vis.defaults","node","defaults","declared",{all:!0},_)),Xne(s,u,f,h,o("node"),l,a);const S=vr("vis-network")?.node,T=B=>p.values.borderColor?.[B]??S?.borderColor?.value??"#2b7ce9",$=lie(t,p.values,g),D=gk(r.physics,r.layout),x=Gs(r.edges,"edge"),R=rie(t,x,T,{...$,support:D},i,n),G={node:p.values,edge:R.values};return S0(t,e.block,G,Aie(t,G.edge)),{canonical:!0,dialect:"vis",tool:"vis-network",opacityInColor:!0,units:"px",node:{values:G.node,rules:l,columns:a},edge:{values:G.edge,rules:R.rules,columns:R.columns},notes:i.list(),block:e.block,readFrom:{node:Sm.node.filter(B=>t.nodes.has(B)),edge:Sm.edge.filter(B=>t.edges.has(B))}}}function Ep(t){return typeof t.shape=="string"?t.shape:null}function Vne(t,e,n,i,r){return pk(t,s=>{const o=e(s),a=Gs(n(s),"node").value??(o===null?void 0:i.get(o)?.value)??r.value;return typeof a=="number"&&Number.isFinite(a)?a:null})}function Yne(t,e,n,i){const r={...t,...e,...n};return i&&(r.fill??=une,r.border??=fne),r}function Kne(t,e,n,i){const r=Ll.has(e),s=gc(t,"node",i,r),o=r?qne(t,e,tie(t,n,i),i):Jne(t,e);if(r&&t.label!==void 0){const a=_m(t,n)??(typeof t.fontSize=="number"?t.fontSize:N0),c=typeof s.labelRuns=="string"?Rne(s.labelRuns,a):0,d=typeof s.labelOffsetY=="number"?s.labelOffsetY:0;s.labelOffsetY=d+c+kne(a)}for(const a of["labelOffsetX","labelOffsetY"]){const[c,d]=[s[a],o[a]];typeof c=="number"&&typeof d=="number"&&(o[a]=c+d)}Object.assign(s,o);const l=_m(t,n);return l!==null&&(s.labelSize=l),s}function Xne(t,e,n,i,r,s,o){let l=0;for(const[a,c]of n){const d=i.get(a)??gc(c,"node",r,!0);if(Object.keys(d).length===0)continue;const u=`group.${String(l)}`;o.set(u,Array.from({length:t},(p,g)=>e(g)===a?!0:null));const f=i.has(a)?"tool":"declared",h=T0(`node.vis.group.${String(l++)}`,"node","group",f,{has:{style:u}},d);s.push({...h,facts:{names:[[u,a]]}})}}function qne(t,e,n,i){const r={width:2*n,height:2*n};return e==="hexagon"&&(r.height=Math.sqrt(3)*n,r.labelOffsetY=(2-Math.sqrt(3))*n/2),Object.assign(r,yne(t,e,{width:2*n,height:2*n})),e==="icon"&&Object.assign(r,{shape:"none"},Ene(t,i("glyphColor"))),e==="triangleDown"&&(r.shape="polygon",r.shapePoints="-1,1 0,-1 1,1"),r}function Jne(t,e){const n=hk(t,e);if(t.margin===0&&(e==="box"||e==="circle"||e==="database")&&(n.visible=!1),t.valign==="top"||t.valign==="bottom")n.labelPosition=`inside-${t.valign}`;else if(e==="database"){const i=t.margin,r=I(i)?i.top:i;n.labelPosition="inside-top",n.labelOffsetY=typeof r=="number"&&Number.isFinite(r)&&r>=0?r:O0}return e==="box"&&typeof t.borderRadius=="number"&&Number.isFinite(t.borderRadius)&&(n.cornerRadius=Math.max(0,t.borderRadius)),n}function hk(t,e){const n=dne.get(e);if(n===void 0)return{};const i=g=>typeof g=="number"&&Number.isFinite(g)&&g>=0?g:null,r=i(t.fontSize)??N0,s=typeof t.label=="string"?Math.max(1,t.label.split(`
|
|
177
|
+
`).length):1,o=i(t.widthMin)??0,l=i(t.heightMin)??0;let a,c,d={};n.ellipse?(a=Math.max(s*r,l)/2,c=a):{padX:a,padY:c,offset:d}=Zne(t.margin,n.square);const u=typeof t.label!="string"||t.label==="",[f,h]=u?[Math.max(o,14),Math.max(l,14)]:[o,l];u&&n.ellipse&&(a=h/2,c=a);const p={...d,labelFit:"bounds",labelPaddingX:a,labelPaddingY:c,width:f>0?f+2*a:0,height:h>0?h+2*c:0};return n.square&&(p.labelFitSquare=!0),p}function Zne(t,e){const n=s=>typeof s=="number"&&Number.isFinite(s)&&s>=0?s:null,i=s=>(I(t)?n(t[s]):n(t))??O0,r={};return!e&&i("left")!==i("right")&&(r.labelOffsetX=(i("left")-i("right"))/2),!e&&i("top")!==i("bottom")&&(r.labelOffsetY=(i("top")-i("bottom"))/2),{padX:(i("left")+i("right"))/2,padY:(i("top")+i("bottom"))/2,offset:r}}function _m(t,e){const n=nh(t.value),i=t.scalingLabel;if(n===null||e===null||!I(i)||i.enabled!==!0)return null;const r=typeof i.min=="number"?i.min:14,s=typeof i.max=="number"?i.max:30;return A0(n,e,r,s)}const Qne=25,PO=[10,30];function pk(t,e){let n=1/0,i=-1/0;for(let r=0;r<t;r++){const s=e(r);s!==null&&(n=Math.min(n,s),i=Math.max(i,s))}return n<=i?[n,i]:null}const nh=t=>typeof t=="number"&&Number.isFinite(t)?t:null;function A0(t,e,n,i){const[r,s]=e,o=s===r?.5:Math.max(0,(t-r)/(s-r));return n+o*(i-n)}const xO=[1,15];function eie(t,e,n,i){if(n===null)return{};const r=nh(t.value);if(r!==null){const s=typeof t.scalingMin=="number"?t.scalingMin:xO[0],o=typeof t.scalingMax=="number"?t.scalingMax:xO[1];return{width:A0(r,n,s,o)}}return{width:(e.width===void 0?null:Y(e.width,i("width")))??1}}function tie(t,e,n){const i=nh(t.value);if(i!==null&&e!==null){const s=typeof t.scalingMin=="number"?t.scalingMin:PO[0],o=typeof t.scalingMax=="number"?t.scalingMax:PO[1];return A0(i,e,s,o)}return(t.size===void 0?null:Y(t.size,n("width")))??Qne}function MO(t,e){return I(e.groups)?e.groups:I(t.groups)?t.groups:{}}function nie(t,e,n){const i=new Map,r=new Map;let s=0;for(let o=0;o<t;o++){const l=e(o);if(!(l===null||i.has(l)))if(Object.hasOwn(n,l))i.set(l,Gs(n[l],"node"));else{const[a,c]=RO[s++%RO.length];i.set(l,{fill:c,border:a}),r.set(l,{fill:c.toLowerCase(),borderColor:a.toLowerCase()})}}return{groupLayers:i,paletteRows:r}}function iie(t,e){const n=new Map;return(i,r)=>{const s=t.get(i)??{},o=Object.hasOwn(e,i)?e[i]:null,l=Object.keys(r).filter(d=>d!=="font"&&(I(o)?Object.hasOwn(o,d):d==="color"));if(l.length===0)return s;const a=`${i}\0${l.join("\0")}`;let c=n.get(a);return c===void 0&&(c=I(o)?Gs(Object.fromEntries(Object.entries(o).filter(([d])=>!l.includes(d))),"node"):{},n.set(a,c)),c}}function rie(t,e,n,i,r,s){const o=t.edgeCount,l=_0(o),a=_ie(t,"edge"),c=new Array(o).fill(null);let d=0;const u=pk(o,g=>nh({...e,...a(g)}.value));let f=!1;for(let g=0;g<o;g++){const m=a(g),y=m.dashes===void 0&&Array.isArray(e.dashes)?{dashes:!0}:{},b={...e,...m,...y},_=R=>({notes:r,target:"edge",property:R,element:g,budget:s.budget}),[S,T]=[t.edgeSource(g),t.edgeTarget(g)],$={...gc(b,"edge",_,!0),...eie(b,e,u,_),...gie(e,m,S,T,i),...cie(b,u,i.at(S),i.at(T))};f||=b.hidden!==!0&&![void 0,!1,"false"].includes(b.dashes);const D=f&&I(b.background)?fk(b.background,!0):null;D!==null&&($.outlineStyle=D);const x=sie($,m.inherit??e.inherit??"from",n,S,T);for(const[R,G]of Object.entries($))l.put(R,g,G);x!==null&&(c[g]=x,d++)}s.budget.spend("edge",o);const{rules:h,columns:p}=oie(e,r,c,d);return{values:l.values,rules:h,columns:p}}function sie(t,e,n,i,r){const s=e!==!1&&e!=="false";return s&&delete t.color,e==="both"&&(t.gradientKind="linear",t.gradientColors=`${String(n(i))} ${String(n(r))}`),s?n(e==="to"?r:i):(t.color===void 0&&(t.color=hne),null)}function oie(t,e,n,i){const r=[],s=new Map,o=gc(t,"edge",l=>({notes:e,target:"edge",property:l}),!0);return Object.keys(o).length>0&&r.push(T0("edge.vis.defaults","edge","defaults","declared",{all:!0},o)),i>0&&(s.set("source-color",n),r.push({id:"edge.tool.source-color",target:"edge",role:"passthrough",origin:"tool",where:{has:{style:"source-color"}},map:{color:{kind:"passthrough",by:{style:"source-color"}}},facts:{elements:i,reason:"SOURCE_NODE_COLOR"}})),{rules:r,columns:s}}function lie(t,e,n){const i=l=>typeof l=="string"?Number.parseInt(l,10):typeof l=="number"&&Number.isFinite(l)?Math.trunc(l):Number.NaN,[r,s]=[br(t,"node","x"),br(t,"node","y")],o=l=>typeof l=="number"&&l>0?l:null;return{at:l=>{const a=[i(r?.(l)),i(s?.(l))];return Number.isNaN(a[0])||Number.isNaN(a[1])?null:a},box:l=>{const[a,c]=[o(e.width?.[l]),o(e.height?.[l])],d=e.borderWidth?.[l];return a===null||c===null?null:[a/2,c/2,typeof d=="number"?d:1,n[l]]}}}function aie(...t){const e={enabled:!0,type:"dynamic",roundness:.5,forceDirection:"none"};for(const n of t)typeof n=="boolean"?e.enabled=n:I(n)&&(e.enabled=typeof n.enabled=="boolean"?n.enabled:e.enabled,e.type=typeof n.type=="string"?n.type:e.type,e.roundness=typeof n.roundness=="number"&&Number.isFinite(n.roundness)?n.roundness:e.roundness,e.forceDirection=n.forceDirection??e.forceDirection);return e}function cie(t,e,n,i){const r={},s=_m(t,e);s!==null&&(r.labelSize=s);const o=die(t.fontAlign,n,i);return o!==null&&(r.labelRotation=o),r}function die(t,e,n){if(typeof t!="string"||t==="horizontal"||e===null||n===null)return null;const[i,r]=[e[0]-n[0],e[1]-n[1]];let s=Math.atan2(r,i);(s<-1&&i<0||s>0&&i<0)&&(s+=Math.PI);const o=Math.round(s*180/Math.PI*1e4)/1e4;return o<0?o+360:o}function uie(t,e,n){const i=n.roundness,[r,s]=t,[o,l]=e,a=Math.abs(r-o),c=Math.abs(s-l),d=i*Math.max(a,c),u=d*(Math.sign(o-r)||1),f=d*(Math.sign(l-s)||-1),h=(1-i)*a*(Math.sign(r-o)||1),p=(1-i)*c*(Math.sign(s-l)||1);switch(n.type){case"discrete":return fie(t,[r+u,s+f],a,c,i);case"diagonalCross":return[r+u,s+f];case"straightCross":return a<=c?[o,l+p]:[o+h,l];case"horizontal":return[o+h,s];case"vertical":return[r,l+p];case"curvedCW":return UO(t,e,i,i*.5+.5);case"curvedCCW":return UO(t,e,i,-i*.5+.5);default:return a<=c?[r+Math.sign(u)*Math.min(d,a),s+f]:[r+u,s+Math.sign(f)*Math.min(d,c)]}}function fie(t,e,n,i,r){return n<=i?[n<r*i?t[0]:e[0],e[1]]:[e[0],i<r*n?t[1]:e[1]]}function UO(t,e,n,i){const r=e[0]-t[0],s=t[1]-e[1],o=(n*.5+.5)*Math.hypot(r,s),l=(Math.atan2(s,r)+i*Math.PI)%(2*Math.PI);return[t[0]+o*Math.sin(l),t[1]+o*Math.cos(l)]}function hie(t,e,n){const[i,r]=[t[0]-e[0],t[1]-e[1]],s=n.roundness,o=n.forceDirection;return(Math.abs(i)>Math.abs(r)||o===!0||o==="horizontal")&&o!=="vertical"?[[t[0]-s*i,t[1]],[e[0]+s*i,e[1]]]:[[t[0],t[1]-s*r],[e[0],e[1]+s*r]]}function pie(t,e,n){const[i,r]=[e[0]-t[0],e[1]-t[1]],[s,o]=[n[0]-t[0],n[1]-t[1]],l=i*i+r*r;return`${ts((s*i+o*r)/l)},${ts((r*s-i*o)/l)}`}const ts=t=>String(Math.round(t*1e4)/1e4||0);function gie(t,e,n,i,r){if(n===i)return bie(t,e,r.box(n));const s=aie(t.smooth,e.smooth);if(s.enabled&&s.type==="dynamic")return mie(t,e,r.support??null);const[o,l]=[r.at(n),r.at(i)];return!s.enabled||o===null||l===null||o[0]===l[0]&&o[1]===l[1]?{}:{curved:!0,bendCurve:"bezier",bends:(s.type==="cubicBezier"?hie(o,l,s):[uie(o,l,s)]).map(c=>pie(o,l,c)).join(" ")}}function mie(t,e,n){if(n===null||e.physics===!1||e.physics===void 0&&t.physics===!1)return{};const i=[e.length,t.length].find(r=>typeof r=="number"&&Number.isFinite(r)&&r>=0);return{curved:!0,...n,...i===void 0?{}:{supportSpringLength:i}}}const yie={barnesHut:{model:"barnesHut",g:-2e3,cg:.3,length:95,k:.04},forceAtlas2Based:{model:"forceAtlas2",g:-50,cg:.01,length:100,k:.08}};function gk(t,e){const n=I(e)?e.hierarchical:void 0;if(n===!0||I(n)&&n.enabled!==!1||t===!1||I(t)&&t.enabled===!1)return null;const i=I(t)?t:{},r=typeof i.solver=="string"?i.solver:"barnesHut",s=yie[r];if(s===void 0)return null;const o=I(i[r])?i[r]:{},l=(a,c)=>typeof a=="number"&&Number.isFinite(a)?a:c;return{supportModel:s.model,supportSpringLength:Math.max(0,l(o.springLength,s.length)),supportSpringConstant:Math.max(0,l(o.springConstant,s.k)),supportRepulsion:Math.max(0,-l(o.gravitationalConstant,s.g)),supportCentralGravity:Math.max(0,l(o.centralGravity,s.cg))}}function bie(t,e,n){if(n===null)return{};const i=(g,m)=>I(g.selfReference)?g.selfReference[m]:void 0,r=(...g)=>g.find(m=>typeof m=="number"&&Number.isFinite(m))??null,s=r(i(e,"size"),e.selfReferenceSize,i(t,"size"),t.selfReferenceSize)??20,o=r(i(e,"angle"),i(t,"angle"))??Math.PI/4,[l,a]=n,c=mk(n,o),[d,u]=[Math.cos(o)*c,Math.sin(o)*c];if([i(e,"renderBehindTheNode"),i(t,"renderBehindTheNode")].find(g=>typeof g=="boolean")===!1)return wie(d,u,s,o,n);const h=n[3]==="dot"||n[3]==="circle"||n[3]==="circularImage";if(c+(h?l:Math.hypot(l,a))<s)return Eie(d,u,s,o,n);const p=[];for(let g=0;g<=4;g++){const m=o+Math.PI+g%4*Math.PI/2,[y,b]=[d+Math.SQRT2*s*Math.cos(m),u+Math.SQRT2*s*Math.sin(m)];p.push(`${ts(y/l)},${ts(b/a)}`)}return{curved:!0,bendCurve:"midpoints",bends:p.join(" ")}}const Ud=96;function Eie(t,e,n,i,r){const[s,o]=r,l=[];for(let a=0;a<=Ud;a++){const c=i+Math.PI+2*Math.PI*(a%Ud)/Ud;l.push(`${ts((t+n*Math.cos(c))/s)},${ts((e+n*Math.sin(c))/o)}`)}return{curved:!1,bends:l.join(" ")}}function wie(t,e,n,i,r){const[s,o]=[t,-e],l=m=>{let[y,b]=[i,i+Math.PI],_=[s,o];for(let S=0;y<=b&&S<10;S++){const T=(y+b)*.5,$=T*2*Math.PI;_=[s+n*Math.cos($),o-n*Math.sin($)];const D=mk(r,Math.atan2(-_[1],-_[0]))-Math.hypot(_[0],_[1]);if(Math.abs(D)<.05)break;D>0==m>0?y=T:b=T}return _},[a,c]=[l(-1),l(1)],d=Math.atan2(a[1]-o,a[0]-s);let u=Math.atan2(c[1]-o,c[0]-s);u<d&&(u+=2*Math.PI);const[f,h]=r,p=Math.max(2,Math.ceil((u-d)/(2*Math.PI)*Ud)),g=[];for(let m=0;m<=p;m++){const y=d+(u-d)*m/p;g.push(`${ts((s+n*Math.cos(y))/f)},${ts(-(o+n*Math.sin(y))/h)}`)}return{curved:!1,sourcePort:g[0],bends:g.slice(1,-1).join(" "),targetPort:g.at(-1)??g[0]}}function mk(t,e){const[n,i,r,s]=t;return s==="dot"||s==="circle"||s==="circularImage"?n:s==="ellipse"?n*i/Math.hypot(Math.sin(e)*n,Math.cos(e)*i):Math.min(Math.abs(n/Math.cos(e)),Math.abs(i/Math.sin(e)))+r}const Sm={node:["color","shape","size","value","scaling","borderWidth","opacity","hidden","label","title","font","margin","widthConstraint","heightConstraint","image","brokenImage","imagePadding","icon","shapeProperties"],edge:["color","width","value","scaling","dashes","arrows","hidden","label","title","font","background","smooth","selfReference","selfReferenceSize","physics","length","widthConstraint"]};function _ie(t,e){const n=yk(t,e);return i=>Gs(n(i),e)}function yk(t,e){const n=Sm[e].map(i=>[i,br(t,e,i)]).filter(i=>i[1]!==null);return i=>{const r={};for(const[s,o]of n){const l=o(i);l!==null&&(r[s]=l)}return r}}function T0(t,e,n,i,r,s){const o={};for(const[l,a]of Object.entries(s))a!==null&&(o[l]=a);return{id:t,target:e,role:n,origin:i,where:r,set:o}}const Sie=new Map([["ellipse",["dot",!0]],["rectangle",["square",!0]],["round-rectangle",["box",!0]],["triangle",["triangle",!0]],["diamond",["diamond",!0]],["star",["star",!0]],["hexagon",["hexagon",!0]],["none",["text",!0]],["pentagon",["hexagon",!1]],["octagon",["hexagon",!1]],["parallelogram",["box",!1]],["trapezoid",["box",!1]],["vee",["triangle",!1]]]),Oie=new Map([["triangle",["arrow",!0]],["tee",["bar",!0]],["circle",["circle",!0]],["square",["box",!0]],["crow",["crow",!0]],["diamond",["diamond",!0]],["vee",["vee",!0]],["inverted",["inv_triangle",!0]],["triangle-open",["arrow",!1]],["diamond-open",["diamond",!1]],["circle-open",["circle",!1]],["half",["arrow",!1]]]);function cl(t){const e=Sie.get(t);return e!==void 0?e:t.startsWith("other:")?[t.slice(6),!0]:["dot",!1]}function bk(t){if(t==="none")return[null,!0];const e=Oie.get(t);return e!==void 0?e:t.startsWith("other:")?[t.slice(6),!0]:["arrow",!1]}const Om=t=>{const e=t("shape"),n=typeof e=="string"?cl(e)[0]:"ellipse";return Ll.has(n)?wm(t):null},Nie=t=>{const e=t("shape");return typeof e=="string"?cl(e)[0]:"ellipse"},GO=t=>e=>{const n=Nie(e),i=Om(e);return n==="hexagon"&&typeof i=="number"?t==="height"?Math.sqrt(3)*i/2:(2-Math.sqrt(3))*i/4:t==="labelOffsetY"&&n==="database"?O0:null},_o=t=>e=>{const n=e("shape"),i=typeof n=="string"?cl(n)[0]:"ellipse";return hk({fontSize:e("labelSize"),label:e("label")},i)[t]??null};function Aie(t,e){const n=a=>t.edgeSource(a)===t.edgeTarget(a),i=a=>(c,d)=>n(d)?e[a]?.[d]??null:c(a),r=gk(void 0,void 0)??{},s=a=>(c,d)=>n(d)?e[a]?.[d]??null:r[a]??null,o=Object.fromEntries(Object.keys(r).map(a=>[a,s(a)])),l=br(t,"edge","length");return o.supportSpringLength=(a,c)=>{const d=l?.(c);return typeof d=="number"&&Number.isFinite(d)&&d>=0&&!n(c)?d:s("supportSpringLength")(a,c)},{node:jO.node,edge:{...jO.edge,...o,bends:i("bends"),bendCurve:i("bendCurve"),curved:(a,c)=>n(c)?e.curved?.[c]??null:!0}}}const jO={node:{width:t=>Om(t)??_o("width")(t),height:t=>GO("height")(t)??Om(t)??_o("height")(t),labelOffsetY:GO("labelOffsetY"),labelFit:_o("labelFit"),labelPaddingX:_o("labelPaddingX"),labelPaddingY:_o("labelPaddingY"),labelFitSquare:_o("labelFitSquare"),borderOpacity:t=>{const e=t("opacity");return typeof e=="number"?e:t("borderOpacity")},shape:t=>{const e=t("shape");if(typeof e!="string")return null;const n={notes:new se,target:"node",property:"shape"};return le("shape",cl(e)[0],"vis",n)},labelPosition:t=>{const e=t("shape");if(typeof e!="string")return null;const n=cl(e)[0];return n==="database"?"inside-top":Ll.has(n)?"bottom":"center"}},edge:{lineStyle:t=>{const e=t("lineStyle");if(e===null)return null;if(e==="solid")return"solid";const n=t("width");return th([5,5],typeof n=="number"?n:1,!0)},targetArrow:t=>FO(t("targetArrow")),sourceArrow:t=>FO(t("sourceArrow"))}};function FO(t){if(typeof t!="string")return null;const[e]=bk(t),n={notes:new se,target:"edge",property:"targetArrow"};return e===null?"none":le("arrow",e,"vis",n)}function zO(t,e){const n=new Set;for(const i of t.values())i.property.startsWith("_")||n.add(i.property);for(const i of e)n.add(i);return[...n]}const bs={cytoscape:{node:zO(n0,["labelPosition","labelItalic","visible"]),edge:zO(i0,["curved","labelItalic","visible"])},graphology:{node:["fill","fillOpacity","width","height","label"],edge:["color","opacity","width","label"]},vis:{node:["fill","fillOpacity","borderColor","borderWidth","shape","width","height","opacity","label","tooltip","labelColor","labelSize","labelFont","visible"],edge:["color","opacity","width","lineStyle","targetArrow","sourceArrow","label","tooltip","labelColor","labelSize","labelFont","visible"]}},Ek=Object.freeze({node:Object.freeze([...new Set([...bs.cytoscape.node,...bs.vis.node,...bs.graphology.node])]),edge:Object.freeze([...new Set([...bs.cytoscape.edge,...bs.vis.edge,...bs.graphology.edge])]),block:"native"}),WO=new Set(["node-link","jgf","graphology"]);function Tie(t,e,n){if(n===void 0)return null;const i=e==="cytoscape"||e==="graphology"||e==="vis"?bs[e]:null,r=[...Pie(n,e,i),...Iie(t,e,n)];if(e==="obographs")return{snapshot:t,topLevelBlock:null,stylesheet:null,groups:null,notes:r};const s=t.withColumns(),o=kie(n.rules.styles.rules);for(const[d,u]of[[s.nodes,"node"],[s.edges,"edge"]]){$ie(d,e,o[u]);for(const[f,h]of n.tags[u])Mu(d,f,h)}s.graph.has(Z)&&s.graph.remove(Z),WO.has(e)&&s.graph.set(Z,[n.block],{dtype:"string"});let l=null;const a=new Il,c=new Mie(s.nodes);if(e==="cytoscape"){const d=Cie(s,n);({stylesheet:l}=d),r.push(...d.notes.map(xie)),vie(n,a)}else e==="graphology"?Uie(s,n,a,c):e==="vis"&&Gie(s,n,a,c);return r.push(...a.notes(`the ${e} dialect of JSON`),...c.notes(e)),{snapshot:s,topLevelBlock:WO.has(e)?null:n.block,stylesheet:l,groups:e==="vis"?Die(s):null,notes:r}}function Iie(t,e,n){let i=null;return e==="jgf"&&!Lie(t)?i="the style rules are not kept: JGF changes the node ids' type or order (number ids become text, integer-like ids are read first), so the graphty.styles block no longer matches the graph read back":e==="obographs"&&(i="the style rules are not kept: OBO Graphs has no place for them"),i===null?[]:[Object.freeze({code:v.RULES_NOT_KEPT,message:i,column:null,count:n.rules.styles.rules.length})]}function $ie(t,e,n){for(const i of t.names())(i.startsWith("graphty.style.")||i.startsWith("graphty_style_")||i===vo)&&!n.has(i)&&t.remove(i);if(e==="cytoscape")for(const i of["style#element","css#element"].filter(r=>t.has(r)))t.remove(i)}function Cie(t,e){const n={node:e.rules.features.node.filter(r=>!("data"in r.ref)||t.nodes.has(r.ref.data)),edge:e.rules.features.edge.filter(r=>!("data"in r.ref)||t.edges.has(r.ref.data))},i=ik({...e.rules,features:n});for(const[r,s]of[[t.nodes,"node"],[t.edges,"edge"]]){const o=i.elementData[s],l=new Set(o.flatMap(c=>Object.keys(c??{})));for(const c of l)Mu(r,c,o.map(d=>d?.[c]??null));const a=i.bypass[s].map(c=>c===null||Object.keys(c).length===0?null:c);a.some(c=>c!==null)&&Mu(r,"style#element",a)}return i}function vie(t,e){for(const n of w0)for(const i of Em[n])for(const r of t.picture(n,i))typeof r=="string"&&r.trim()!==r&&e.add(n,i,JSON.stringify(r))}function Die(t){const e=t.nodes.get("group");if(e==null)return null;const n=new Map;for(let i=0;i<t.nodeCount;i++){const r=e.isSet(i)?e.value(i):null;(typeof r=="string"||typeof r=="number")&&n.set(String(r),{})}return n.size===0?null:Object.fromEntries(n)}function kie(t){const e={node:new Set,edge:new Set};for(const n of t){const i=[...Rie(n.where),...Object.values(n.map??{}).flatMap(r=>r===void 0?[]:[r.by])];for(const r of i)"data"in r&&e[n.target].add(r.data)}return e}function Rie(t){const e=[],n=[t];for(;n.length>0;){const i=n.pop();"has"in i?e.push(i.has):"eq"in i?e.push(i.eq[0]):"in"in i?e.push(i.in[0]):"and"in i?n.push(...i.and):"or"in i?n.push(...i.or):"not"in i&&n.push(i.not)}return e}function Lie(t){let e=-1,n=!1;for(let i=0;i<t.nodeCount;i++){const r=t.ids.idOf(i);if(typeof r=="number")return!1;if(/^(0|[1-9]\d*)$/.test(r)&&Number(r)<4294967295){if(n||Number(r)<=e)return!1;e=Number(r)}else n=!0}return!0}function Pie(t,e,n){const i=[];for(const r of w0){const s=new Set(Ek[r]),o=new Set(n?.[r]??[]),l=new Set;for(const a of t.rules.styles.rules)if(a.target===r)for(const c of[...Object.keys(a.set??{}),...Object.keys(a.map??{})])l.add(c);for(const a of l){if(!s.has(a)||o.has(a))continue;const c=t.picture(r,a).filter(d=>d!==null).length;i.push(Object.freeze({code:v.NOT_WRITTEN,message:`${r} ${a} is not written: the ${e} dialect of JSON has no place for it`,column:null,count:c,style:Object.freeze({target:r,property:a})}))}}return i}function xie(t){return Object.freeze({code:t.code,message:t.message,column:null,count:t.params.count,style:t.params.target===null||t.params.property===null?void 0:Object.freeze({target:t.params.target,property:t.params.property})})}function Mu(t,e,n){const i=new Set(n.filter(s=>s!=null).map(s=>typeof s));let r="json";i.size===1&&(i.has("number")?r="f64":i.has("boolean")?r="bool":i.has("string")&&(r="string")),t.set(e,n.map(s=>s===null?void 0:s),{dtype:r})}function It(t,e,n,i){const r=t.get(e);let s=0;if(r!==null)for(let o=0;o<n.length;o++){const l=K(r.value(o)),a=n[o]??null;l!==null&&JSON.stringify(l)!==JSON.stringify(a)&&s++}if(s>0&&i.add(t===i.nodes?"node":"edge",e,s),n.every(o=>o==null)){r!==null&&t.remove(e);return}Mu(t,e,n)}const wk="W_JSON_STYLE_KEY_REPLACED";class Mie{constructor(e){this.nodes=e}#e=new Map;add(e,n,i){this.#e.set(`${e}\0${n}`,(this.#e.get(`${e}\0${n}`)??0)+i)}notes(e){return Array.from(this.#e,([n,i])=>{const[r,s]=n.split("\0");return Object.freeze({code:wk,message:`${r} column "${s}" is the ${e} dialect's style key: ${String(i)} ${r}${i===1?"":"s"} get what graphty draws instead of the value the column held`,column:s,count:i})})}}function _k(t,e){if(typeof t!="string")return null;if(typeof e!="number"||e>=1)return t;const n=Number.parseInt(t.slice(1),16);return`rgba(${String(n>>16&255)},${String(n>>8&255)},${String(n&255)},${String(e)})`}function Sk(t,e,n){return t.map((i,r)=>{const s=t[r],o=e[r];return typeof s=="number"&&typeof o=="number"&&s!==o?(n.add("node",s>o?"height":"width",`${String(s)} x ${String(o)}`),Math.max(s,o)):typeof s=="number"?s:typeof o=="number"?o:null})}function Uie(t,e,n,i){const r=(s,o)=>e.picture(s,o);for(const[s,o]of[[t.nodes,"node"],[t.edges,"edge"]]){const[l,a]=o==="node"?["fill","fillOpacity"]:["color","opacity"],c=r(o,l),d=r(o,a);It(s,"color",c.map((u,f)=>_k(u,d[f])),i),It(s,"size",o==="node"?Sk(r("node","width"),r("node","height"),n).map(u=>u===null?null:u/2):r("edge","width").map(u=>typeof u=="number"?u*2:u),i),It(s,"label",r(o,"label"),i)}}function BO(t,e,n){const i=t.get("value");if(i===null)return;const r=e.map((s,o)=>typeof s!="number"||typeof K(i.value(o))!="number"?null:{min:s,max:s});It(t,"scaling",r,n)}function Gie(t,e,n,i){const r=(b,_)=>e.picture(b,_),s=b=>{const _=r(b,"labelColor"),S=r(b,"labelSize"),T=r(b,"labelFont");return _.map(($,D)=>{const x={};return _[D]!==null&&(x.color=_[D]),S[D]!==null&&(x.size=S[D]),T[D]!==null&&(x.face=T[D]),Object.keys(x).length===0?null:x})},o=(b,_)=>{It(b,"label",r(_,"label"),i),It(b,"title",r(_,"tooltip"),i),It(b,"font",s(_),i),It(b,"hidden",r(_,"visible").map(S=>S===!1?!0:null),i)},l=r("node","fill"),a=r("node","fillOpacity"),c=r("node","borderColor");It(t.nodes,"color",l.map((b,_)=>{const S={},T=_k(l[_],a[_]);return T!==null&&(S.background=T),typeof c[_]=="string"&&(S.border=c[_]),Object.keys(S).length===0?null:S}),i);const d=Sk(r("node","width"),r("node","height"),n),u=r("node","shape").map((b,_)=>{const[S,T]=typeof b=="string"?cl(b):[null,!0],$=S==="dot"&&b==="ellipse"&&d[_]===null?"ellipse":S;return T||n.add("node","shape",b),d[_]!==null&&!Ll.has($??"ellipse")&&n.add("node","width",`${String(b??"ellipse")} sized by its label`),$});It(t.nodes,"shape",u,i);const f=d.map(b=>b===null?null:b/2);It(t.nodes,"size",f,i),BO(t.nodes,f,i),It(t.nodes,"borderWidth",r("node","borderWidth"),i),It(t.nodes,"opacity",r("node","opacity"),i),o(t.nodes,"node");const h=r("edge","color"),p=r("edge","opacity");It(t.edges,"color",h.map((b,_)=>{const S={};return typeof h[_]=="string"&&(S.color=h[_]),typeof p[_]=="number"&&(S.opacity=p[_]),Object.keys(S).length===0?null:S}),i);const g=r("edge","width");It(t.edges,"width",g,i),BO(t.edges,g,i),It(t.edges,"dashes",r("edge","lineStyle").map(b=>typeof b!="string"?null:(b!=="solid"&&b!=="dashed"&&n.add("edge","lineStyle",b),b!=="solid")),i);const m=r("edge","targetArrow"),y=r("edge","sourceArrow");It(t.edges,"arrows",m.map((b,_)=>{const S={};for(const[T,$,D]of[["to",m[_],"targetArrow"],["from",y[_],"sourceArrow"]]){if(typeof $!="string")continue;const[x,R]=bk($);R||n.add("edge",D,$),S[T]=x===null?{enabled:!1}:{enabled:!0,type:x}}return Object.keys(S).length===0?null:S}),i),o(t.edges,"edge")}const L=Object.freeze({...xn,...Pn,EMPTY_INPUT:Ut,SYNTAX:kn,DIALECT:"E_JSON_DIALECT",SHAPE:"E_JSON_SHAPE",MISSING_SECTION:"W_MISSING_SECTION",BAD_ELEMENT:"E_BAD_ELEMENT",MISSING_ID:dt,UNSUPPORTED_ID:"E_UNSUPPORTED_ID",MISSING_ENDPOINT:Zn,BAD_INDEX:"E_BAD_INDEX",BAD_VALUE:ie,BAD_FLAG:"W_BAD_FLAG",UNKNOWN_PARENT:Ui,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Ai,ID_MERGED:Rn,EDGE_ID_STRINGIFIED:"W_EDGE_ID_STRINGIFIED",MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,OBOGRAPHS_SUBJ:"W_JSON_OBOGRAPHS_SUBJ",DANGLING_REFERENCE:Xi,TOO_LARGE:gl,HYPEREDGE:EA,HYPEREDGES_SKIPPED:"W_HYPEREDGES_SKIPPED",HYPEREDGE_SHAPE:"E_HYPEREDGE_SHAPE",POSITIONAL_NODES:"W_POSITIONAL_NODES",UNREAD_KEY:"W_JSON_UNREAD_KEY",SINK_OPTION:Ln,OPTION_IGNORED:Jt,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,NONSTANDARD_NUMBER:Ju,BIG_INTEGER:"W_JSON_BIG_INTEGER",UNKNOWN_ENCODING:En,PRECISION:re,INCONSISTENT:"W_JSON_INCONSISTENT",INDEX_LINKS:"W_JSON_INDEX_LINKS",PARENT_CYCLE:pl,EMPTY_COLUMN_DROPPED:ay,UNKNOWN_ELEMENT:vt,DUPLICATE_ATTRIBUTE:fe,COLUMN_RENAMED:ln,ROLE_TAKEN:bn}),jie=new Set(["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","hyperedges","errorLimit","signal","onProgress"]),wp={ids:"keep",defaultDirected:!1,weightFrom:"weight"},Fie=4096,_p=5,zie=64,Wie=['"nodes"','"links"','"edges"','"elements"','"graph"','"graphs"'],Bie="\uFEFF",Ok=new Set(["id","source","target","relation","directed","label","metadata"]),Hie=new Set([...Ok,"nodes"]),Vie=/^(?:0|[1-9]\d{0,9})$/,Yie=new Set(["label","metadata"]),Kie=new Set(["key","attributes"]),Nk=new Set(["key","source","target","attributes","undirected"]),Xie=new Set(["id","attributes"]),qie=new Set([...Nk,"id"]),Jie=new Set(["label","x","y","size","color"]),Zie=new Set(["label","size","color"]),Qie=Object.freeze(["from"]),ere=Object.freeze(["to"]),Nm=new Set(["node-link","d3","vis","graphology"]);function Sp(t){const e=t??{},n=e.dialect??"auto";if(n!=="auto"&&!gte(n))throw hi("dialect",n,[...rk,"auto"]);const i=e.indexLinks??"auto";if(i!=="auto"&&typeof i!="boolean")throw hi("indexLinks",i,["true","false","auto"]);const r=e.graphIndex??0;if(!Number.isInteger(r)||r<0)throw hi("graphIndex",r,["a non-negative integer"]);const s=e.oboIds??"curie";if(s!=="curie"&&s!=="iri")throw hi("oboIds",s,["curie","iri"]);const o=e.typedefs??"metadata";if(o!=="metadata"&&o!=="nodes")throw hi("typedefs",o,["metadata","nodes"]);const l=HO("nodesPath",e.nodesPath),a=HO("edgesPath",e.edgesPath);if((l!==null||a!==null)&&n!=="auto"&&!Nm.has(n))throw hi(l===null?"edgesPath":"nodesPath",n,[...Nm]);return{dialect:n,nodeIdKey:Jc("nodeIdKey",e.nodeIdKey),edgesKey:Jc("edgesKey",e.edgesKey),sourceKey:Jc("sourceKey",e.sourceKey),targetKey:Jc("targetKey",e.targetKey),indexLinks:i,graphIndex:r,choice:{graphIndex:e.graphIndex,graphName:e.graphName},oboIds:s,typedefs:o,nodesPath:l,edgesPath:a,sigma:tre(e.sigmaSettings)}}function tre(t){if(t===void 0)return dk;if(!I(t))throw hi("sigmaSettings",t,["an object of sigma.js settings"]);const{renderEdgeLabels:e=!1,edgeLabelAnchors:n="nodeLabels"}=t;if(typeof e!="boolean")throw hi("sigmaSettings.renderEdgeLabels",e,["true","false"]);if(n!=="nodeLabels"&&n!=="allNodes")throw hi("sigmaSettings.edgeLabelAnchors",n,["nodeLabels","allNodes"]);return{renderEdgeLabels:e,edgeLabelAnchors:n}}function HO(t,e){if(e===void 0)return null;const n=typeof e=="string"?e.split("."):[];if(n.length===0||n.some(i=>i.length===0))throw hi(t,e,["a dotted path of non-empty keys"]);return n}function VO(t,e){let n=t;for(const i of e)if(Array.isArray(n)&&/^(0|[1-9]\d*)$/.test(i)&&Number(i)<n.length)n=n[Number(i)];else if(I(n)&&z(n,i))n=n[i];else return;return n}function nre(t,e,n){const{nodesPath:i,edgesPath:r}=e;if(i===null&&r===null)return t;const s=(d,u)=>{const f=VO(t,u);if(f===void 0){const h=u.join(".");return n.warning("missing-value",L.MISSING_SECTION,`${d} ${JSON.stringify(h)} names nothing in the document`,{element:h}),[]}return f},o=i===null?[]:i.slice(0,-1),l=VO(t,o),a=new Set;i!==null&&a.add(i[i.length-1]),r!==null&&(a.add("edges"),a.add("links"));let c=Object.fromEntries(Object.entries(I(l)?l:{}).filter(([d])=>!a.has(d)));if(r!==null&&r.length>o.length&&o.every((d,u)=>r[u]===d)){const d=Ak(c,r.slice(o.length));c=I(d)?d:{}}return i!==null&&(c.nodes=s("nodesPath",i)),r!==null&&(c[Tk(e,r)]=s("edgesPath",r)),c}function Ak(t,e){if(e.length===0)return;const[n,...i]=e;if(!I(t)||!z(t,n))return t;const r=Object.entries(t).map(([s,o])=>[s,s===n?Ak(o,i):o]).filter(([,s])=>s!==void 0);return r.length===0?void 0:Object.fromEntries(r)}function Tk(t,e){return t.edgesKey??(e.at(-1)==="links"?"links":"edges")}function ire(t,e,n){if(e!=="auto")return e;if(n&&I(t)&&z(t,"links")&&!z(t,"edges")){const{links:r,...s}=t,o=za({...s,edges:r});if(o==="vis"||o==="graphology")return o}const i=za(t);return i!==null&&Nm.has(i)?i:"node-link"}function Op(t,e,n){if(e.nodesPath===null&&e.edgesPath===null)return{root:t,dialect:are(t,e.dialect,n)};const i=nre(t,e,n),r=ire(i,e.dialect,e.edgesPath!==null);if(e.edgesPath!==null&&(r==="vis"||r==="graphology")&&I(i)){const s=Tk(e,e.edgesPath);return{root:Object.fromEntries(Object.entries(i).map(([l,a])=>[l===s?"edges":l,a])),dialect:r}}return{root:i,dialect:r}}function Jc(t,e){if(e===void 0)return null;if(typeof e!="string"||e.length===0)throw hi(t,e,["a non-empty key"]);return e}function hi(t,e,n){return new N("E_UNSUPPORTED",`option ${t}: ${Ye(e)} is not one of ${n.join(", ")}`,{option:t,found:typeof e=="string"?e:typeof e,supported:[...n]})}function Ye(t){if(t===null)return"null";if(Array.isArray(t))return"array";switch(typeof t){case"string":case"number":case"boolean":return JSON.stringify(t);default:return typeof t}}class YO{constructor(e,n,i){this.handles=new Map,this.reservedNames=new Set,this.nullOnly=new Set,this.sink=e,this.domain=n,this.report=i}declare(e){this.reservedNames.add(e.name);const n=this.domain==="node"?this.sink.declareNodeColumn(e):this.sink.declareEdgeColumn(e);return this.handles.set(e.name,n),n}declareIf(e,n){return n?this.declare(e):A}taken(e){return this.lookup(e)!==A}write(e,n,i,r,s){if(i===void 0)return;const o=this.reservedNames.has(n)?`${n}${r}`:n;if(i===null){this.nullOnly.add(o);return}try{const a=this.handles.get(o);if(a!==void 0){this.set(a,e,i);return}this.set(o,e,i)}catch(a){if(!(a instanceof N))throw a;this.report.recordError(a,{element:`${s}.${n}`});return}const l=this.lookup(o);l!==A&&this.handles.set(o,l)}reportNullOnly(){const e=[...this.nullOnly].filter(n=>this.lookup(n)===A);e.length>0&&this.report.warning("missing-value",ay,`${this.domain} key${O(e.length)} ${e.map(n=>JSON.stringify(n)).join(", ")} ${C(e.length,"is","are")} null wherever they appear; no column is made for them`,{element:e[0]})}set(e,n,i){this.domain==="node"?this.sink.setNodeValue(e,n,i):this.sink.setEdgeValue(e,n,i)}lookup(e){return this.domain==="node"?this.sink.nodeColumn(e):this.sink.edgeColumn(e)}}class rre{constructor(e,n,i,r,s){this.text="",this.elementsSinceCheck=0,this.fileDirected=!1,this.danglingIds=[],this.danglingCount=0,this.nodesFromEdges=!1,this.styleSource=null,this.nearMatches=[],this.sink=e,this.report=n,this.options=i,this.json=r,this.ids=new Mn(i.ids),this.direction=new ei(e,n,i.onMixedDirection),this.nodes=new YO(e,"node",n),this.edges=new YO(e,"edge",n),this.explicitDefaultDirected=s}reportNodeIdFrom(e,n){this.options.nodeIdFrom!=="id"&&this.report.warning("unsupported",L.OPTION_IGNORED,`nodeIdFrom "${this.options.nodeIdFrom}" does not apply to ${e}; ids are read from ${n}`,{element:"nodeIdFrom"})}defaultDirected(e){return this.explicitDefaultDirected?this.options.defaultDirected:ok[e]}setHeader(e){this.fileDirected=e,this.direction.setHeader(e)}uniformKind(){return this.fileDirected?"directed":"undirected"}coerceId(e,n){if(e===void 0)return this.report.error("missing-value",L.MISSING_ID,`${n} has no id`,{element:n}),null;if((typeof e=="boolean"||e===null)&&this.options.ids!=="string"){const s=e===null?"null":"boolean";return this.report.error("unsupported",L.UNSUPPORTED_ID,`${n}: a JSON ${s} is not a node id (pass ids: "string" to coerce it)`,{element:n}),null}let i;try{i=this.ids.value(this.options.ids==="string"&&typeof e=="number"?String(e):e)}catch(s){return this.report.recordError(s,{element:n}),null}const r=this.ids.lastMerge;return r!==null&&this.report.warning("coercion",L.ID_MERGED,`id text ${JSON.stringify(r.text)} merged with ${JSON.stringify(r.previousText)} as ${r.id}`,{element:n}),i}requireId(e,n){if((typeof e=="boolean"||e===null)&&this.options.ids!=="string"){const i=e===null?"null":"boolean";throw new N("E_INVALID_ID",`${n}: a JSON ${i} is not a node id`,{reason:"unsupported id"})}return this.ids.value(this.options.ids==="string"&&typeof e=="number"?String(e):e)}pushNode(e,n,i=""){this.checkAbort();const r=this.sink.indexOf(e);if(r!==A)return this.report.warning("merged",L.DUPLICATE_NODE,`${n}: node ${JSON.stringify(e)} already exists${i}; its attributes are merged (the later values win)`,{element:n}),r;let s;try{s=this.sink.addNode(e)}catch(o){return this.skip(o,"node",n),-1}return this.report.counts.nodes++,s}pushEdge(e,n,i,r,s){this.checkAbort();const o=this.sink.edgeCount,l=this.sink.indexOf(e)===A,a=e!==n&&this.sink.indexOf(n)===A,c=this.direction.addEdge(e,n,i,r,{element:s});return this.report.counts.edges+=this.sink.edgeCount-o,l&&this.dangling(e),a&&this.dangling(n),c}textualId(e,n){const i=this.coerceId(e,n);if(i===null||this.sink.indexOf(i)!==A)return i;let r=null;if(typeof e=="number"&&Number.isFinite(e)?r=String(e):typeof e=="string"&&/^-?\d+(?:\.\d+)?$/.test(e)&&(r=Number(e)),r===null)return i;const s=this.ids.value(r);return this.sink.indexOf(s)===A?i:s}dangling(e){this.report.counts.nodes++,this.danglingCount++,this.danglingIds.length<_p&&this.danglingIds.push(e);const n=typeof e=="number"?String(e):Number(e);this.nearMatches.length<_p&&(typeof n=="string"||String(n)===e)&&this.sink.indexOf(n)!==A&&this.nearMatches.push(e)}reportDangling(){if(this.danglingCount===0||this.nodesFromEdges)return;const e=this.danglingIds.map(i=>JSON.stringify(i)).join(", "),n=this.nearMatches.length>0?`; ${this.nearMatches.map(i=>JSON.stringify(i)).join(", ")} ${C(this.nearMatches.length,"names","name")} a node id of another JSON type (a string next to a number), which is a different id`:"";this.report.warning("validation-error",L.DANGLING_REFERENCE,`${this.danglingCount} edge endpoint${O(this.danglingCount)} ${C(this.danglingCount,"names","name")} no node and became placeholder nodes: ${e}${this.danglingCount>_p?", ...":""}${n}`,{element:String(this.danglingIds[0])})}checkAbort(){++this.elementsSinceCheck>=zie&&(this.elementsSinceCheck=0,F(this.options.signal))}skip(e,n,i){this.report.recordError(e,{element:i}),n==="node"?this.report.counts.skippedNodes++:this.report.counts.skippedEdges++}badElement(e,n,i="an object"){this.report.error("validation-error",L.BAD_ELEMENT,`${n} is not ${i}`,{element:n}),this.countSkipped(e)}countSkipped(e){e==="node"?this.report.counts.skippedNodes++:this.report.counts.skippedEdges++}missingEndpoint(e,n){this.report.error("missing-value",L.MISSING_ENDPOINT,`${e} has no ${n}`,{element:e}),this.report.counts.skippedEdges++}setMeta(e,n={}){const i={};for(const[r,s]of Object.entries(e))s!==void 0&&(i[r]=s);this.sink.setMeta({sourceFormat:"json",...n,extra:{[m0]:i}})}weightOriginPatch(){const{weightFrom:e}=this.options;return e===null?{}:{weightOrigin:{format:"json",id:e,title:null,type:null,namespace:null}}}writeGraphDict(e,n){if(e!=null){if(!I(e)){this.report.warning("validation-error",L.BAD_FLAG,`${n} is not an object; ignored`,{element:n});return}for(const i of Object.keys(e)){const r=e[i];if(r!=null)try{this.sink.setGraphValue(i,r)}catch(s){this.report.recordError(s,{element:`${n}.${i}`})}}}}weightOf(e){const{weightFrom:n}=this.options;if(!(n===null||!z(e,n)))return of(e[n])}writeNested(e,n,i,r,s,o,l={}){const{weightFrom:a=null,plain:c=!1,dataKeys:d}=l;for(const u of Object.keys(r))if(u!==a){const f=d?.has(u)===!0?`${u}${Lt.data}`:u;e.write(n,f,r[u],Lt.data,o)}for(const u of Object.keys(i))s.has(u)||e.write(n,c?u:`${u}${Lt.element}`,i[u],Lt.data,o)}writeStringField(e,n,i,r,s,o){if(!(n===A||r===void 0||r===null)){if(typeof r!="string"){this.report.error("validation-error",L.BAD_VALUE,`${o}: ${s} must be a string, found ${Ye(r)}`,{element:o});return}e.set(n,i,r)}}declareEdgeIds(e,n,i,r){let s=0,o=0,l=0;for(const h of e){if(!I(h))continue;const p=n(h);typeof p=="number"?s++:typeof p=="string"?o++:p!=null&&l++}if(s+o+l===0)return null;const a=o===0&&s>0?"f64":"string",c=Xt(i,"id",h=>this.edges.taken(h)),d=this.edges.declare({name:c,dtype:a,role:"id",nullable:!0,unique:r}),u=o>0&&s>0,f=r?new Set:null;return u&&this.report.warning("coercion",L.EDGE_ID_STRINGIFIED,`edge ids mix numbers and strings; ${s} numeric id${O(s)} stored as text`,{element:c}),{handle:d,stringify:u,seen:f}}edgeIdValue(e,n){if(e===null||n===void 0||n===null)return null;let i;if(typeof n=="number")i=e.stringify?String(n):n;else if(typeof n=="string")i=n;else throw new N("E_COLUMN_TYPE",`an edge id must be a string or a number, found ${Ye(n)}`,{found:typeof n});if(e.seen!==null){const r=String(i);if(e.seen.has(r))throw new N(L.DUPLICATE_EDGE_ID,`edge id ${JSON.stringify(i)} is declared more than once; the edge is skipped`,{id:i});e.seen.add(r)}return i}setEdgeId(e,n,i){e!==null&&i!==null&&this.edges.set(e.handle,n,i)}}function Np(t,e){t.trim().length===0&&e.fail(L.EMPTY_INPUT,"the input is empty");let n,i=null,r=t;try{n=JSON.parse(t)}catch(o){i=o instanceof Error?o.message:String(o)}if(i===null&&!i1.test(t)&&!c3.test(t))return XO(t,e),n;let s;try{if(s=Uy(t),s.tokens.size>0||s.bigIntegers.length>0)try{n=JSON.parse(s.text,s.tokens.size>0?s.revive:void 0),i=null}catch(o){if(o instanceof RangeError)throw o;i=o instanceof Error?o.message:String(o),r=s.text}}catch(o){if(!(o instanceof RangeError))throw o;const l="the document with its numbers rewritten is longer than the most one JavaScript string holds";throw e.error("unsupported",L.TOO_LARGE,l),e.abort(l,{code:L.TOO_LARGE})}return i!==null?e.fail(L.SYNTAX,lre(t,i),{line:ore(r,i)}):(XO(t,e),s.tokens.size>0&&e.warning("coercion",L.NONSTANDARD_NUMBER,`the document uses the non-standard token${O(s.tokens.size)} ${[...s.tokens].join(", ")}, which strict JSON does not allow; read as numbers`),s.bigIntegers.length>0&&e.warning("precision",L.BIG_INTEGER,`${s.bigIntegers.length} integer${O(s.bigIntegers.length)} beyond 2^53 kept as text so no digit is lost: ${KO(s.bigIntegers)}`),s.inexact.length>0&&e.warning("precision",L.PRECISION,`${s.inexact.length} number literal${O(s.inexact.length)} no double holds exactly, read as the nearest double (an infinity beyond the range, 0 below it): ${KO(s.inexact)}`),n)}function KO(t){const e=t.length-qO,n=t.slice(0,qO).join(", ");return e>0?`${n} and ${e} more`:n}const Zc=10;function XO(t,e){const n=b3(t);let i=1,r=0;for(const{key:s,offset:o}of n.slice(0,Zc))i+=Gd(t,r,o),r=o,e.warning("merged",L.DUPLICATE_ATTRIBUTE,`key ${JSON.stringify(s)} appears twice in one object; the earlier value is dropped (JSON.parse keeps the last)`,{line:i,element:s});n.length>Zc&&e.warning("merged",L.DUPLICATE_ATTRIBUTE,`${n.length-Zc} more repeated key${O(n.length-Zc)}; each earlier value is dropped`)}function Gd(t,e,n){let i=0;for(let r=t.indexOf(`
|
|
178
|
+
`,e);r>=0&&r<n;r=t.indexOf(`
|
|
179
|
+
`,r+1))i++;return i}const sre=64*1024*1024;function ore(t,e){const n=/\(line (\d+)/.exec(e);if(n!==null)return Number(n[1]);const i=/position (\d+)/.exec(e);if(i!==null)return Gd(t,0,Number(i[1]))+1;if(!e.startsWith("Unexpected token")||t.length>sre)return Gd(t,0,t.length)+1;let r=0,s=t.length;for(;r<s;){const o=r+s>>>1;let l=!1;try{JSON.parse(t.slice(0,o+1))}catch(a){l=a instanceof Error&&a.message.startsWith("Unexpected token")}l?s=o:r=o+1}return Gd(t,0,r)+1}function lre(t,e){return Xre(t)?`invalid JSON: the input is JSON Lines (one JSON value per line), which is not a graph format graph-io reads; convert it to one JSON document (${e})`:`invalid JSON: ${e}`}const qO=10;function are(t,e,n){if(e!=="auto")return e;const i=za(t);return i!==null?i:Array.isArray(t)?n.fail(L.DIALECT,"a top-level array is only read as Cytoscape elements (objects with a data record)"):I(t)?n.fail(L.DIALECT,"no known dialect: expected nodes / links / edges (node-link), nodes / adjacency (adjacency), children (tree), elements (Cytoscape) or graph (JGF)"):n.fail(L.DIALECT,`the document is a JSON ${Ye(t)}, not a graph object`)}function Dn(t,e,n){return t==null?null:Array.isArray(t)?t:n.fail(L.SHAPE,`${e} must be an array, found ${Ye(t)}`,{element:e})}function ns(t,e,n,i){return t==null?n:typeof t=="boolean"?t:(i.warning("validation-error",L.BAD_FLAG,`${e} is ${Ye(t)}, not a boolean; ${n} assumed`,{element:e}),n)}function is(t,e,n){if(e!==null)return{key:$n(t,e)?e:null,value:t[e]};for(const i of n)if($n(t,i))return{key:i,value:t[i]};return{key:null,value:void 0}}function $n(t,e){return z(t,e)&&t[e]!==null}function Ba(t,e,n,i){for(const r of Object.keys(e)){if(n.has(r))continue;const s=e[r],o=Array.isArray(s)&&s.length===1?"entry":"entries",l=Array.isArray(s)?`${String(s.length)} ${o}`:Ye(s);t.report.warning("unsupported",L.UNREAD_KEY,`${i.length===0?"top-level key":"key"} ${i}${r} (${l}) is not read; dropped`,{element:`${i}${r}`})}}const cre=new Set(["nodes","edges",Z]),dre=new Set(["nodes","edges","options","attributes",Z]),ure=new Set(["id","type","label","directed","metadata","nodes","edges","hyperedges"]);function mr(t,e){return t.some(n=>I(n)&&n[e]!==void 0&&n[e]!==null)}function Am(t,e){return typeof t=="number"&&Number.isInteger(t)&&t>=0&&t<e}function fre(t,e,n){const{report:i,json:r}=t,s=r.edgesKey??(z(e,"edges")||!z(e,"links")?"edges":"links"),{nodeList:o,edgeList:l}=hre(t,e,s),a=ns(e.directed,"directed",t.defaultDirected(n),i),c=z(e,"multigraph")?ns(e.multigraph,"multigraph",!1,i):null;t.setHeader(a),t.writeGraphDict(e.graph,"graph"),Ba(t,e,new Set(["nodes",s,"directed","multigraph","graph",Z]),"");const d=z(e,"directed")&&z(e,"multigraph")&&z(e,"graph");t.styleSource={dialect:n,block:mc(e),networkx:d},t.sink.reserve(o.length,l.length);const u=pre(t,o),f=u===null;let h;f?h=!0:r.indexLinks==="auto"?h=Ere(o,l,u,r):{indexLinks:h}=r,h&&!f&&r.indexLinks==="auto"&&bre(t,o,l,u);const p=gre(t,o,u,h);F(t.options.signal);const g=yre(t,l,s,p,c);t.setMeta({dialect:n,edgesKey:s,nodeIdKey:u,indexLinks:h,sourceKey:g.source??void 0,targetKey:g.target??void 0},{declaredMultigraph:c,...t.weightOriginPatch()})}function hre(t,e,n){const{report:i}=t,r=Dn(e.nodes,"nodes",i),s=Dn(e[n],n,i);return r===null&&(i.warning("missing-value",L.MISSING_SECTION,"the document has no nodes array; nodes come from the edges",{element:"nodes"}),t.nodesFromEdges=!0),s===null&&i.warning("missing-value",L.MISSING_SECTION,`the document has no ${n} array; the graph has no edges`,{element:n}),{nodeList:r??[],edgeList:s??[]}}function pre(t,e){const{report:n,json:i}=t;if(t.options.nodeIdFrom==="index")return null;if(i.nodeIdKey!==null)return i.nodeIdKey;const r=t.options.nodeIdFrom==="label",o=(r?["label","name","id"]:["id","name"]).find(l=>mr(e,l))??null;return r&&(o==="id"||o==="name")&&n.warning("unsupported",L.OPTION_IGNORED,o==="id"?'nodeIdFrom "label": no node has a label or name key; ids are read from "id"':'nodeIdFrom "label": no node has a "label" key; ids are read from "name"',{element:"nodeIdFrom"}),o!==null||e.length===0?o??"id":(n.warning("missing-value",L.POSITIONAL_NODES,"no node has an id or name key; array positions are the node ids",{element:"nodes"}),null)}function gre(t,e,n,i){const r=i?[]:null;for(let s=0;s<e.length;s++){const o=`nodes[${s}]`,l=e[s];let a=null;I(l)?a=mre(t,l,s,n):t.badElement("node",o),r?.push(a)}return r}function mre(t,e,n,i){const r=`nodes[${n}]`,s=i!==null&&z(e,i)?e[i]:void 0,o=i===null?n:t.coerceId(s,r);if(o===null)return t.countSkipped("node"),null;const l=t.pushNode(o,r);return l<0?null:(ih(t.nodes,l,e,o,a=>a!==i),o)}function yre(t,e,n,i,r){const{json:s}=t,o=t.uniformKind();let l=null,a=null;const c=r===null?null:new Set;let d=0;for(let u=0;u<e.length;u++){const f=`${n}[${u}]`,h=e[u];if(!I(h)){t.badElement("edge",f);continue}const p=is(h,s.sourceKey,y0),g=is(h,s.targetKey,b0);if(p.key===null||g.key===null){t.missingEndpoint(f,p.key===null?"source":"target");continue}l??=p.key,a??=g.key;try{const m=JO(t,p.value,i,f,"source"),y=JO(t,g.value,i,f,"target");if(m===null||y===null){t.countSkipped("edge");continue}const b=t.weightOf(h);if(c!==null){const T=Ik(m,y,o==="directed");if(r===!1)d+=c.has(T)?1:0,c.add(T);else if(z(h,"key")){const $=`${T} ${JSON.stringify(h.key)}`;if(c.has($))throw new N(L.DUPLICATE_EDGE_ID,`${f}: key ${JSON.stringify(h.key)} is repeated for the same pair; NetworkX reads it as the same edge, so it is skipped`,{id:String(h.key)});c.add($)}}const _=t.pushEdge(m,y,o,b,f),{weightFrom:S}=t.options;for(const T of Object.keys(h))T!==p.key&&T!==g.key&&T!==S&&t.edges.write(_,T,h[T],Lt.data,f)}catch(m){t.skip(m,"edge",f)}}return d>0&&t.report.warning("validation-error",L.INCONSISTENT,`the document declares multigraph false, but ${d} link${O(d)} ${C(d,"repeats","repeat")} the endpoints of an earlier one; all are kept`,{element:n}),{source:l,target:a}}function Ik(t,e,n){const i=JSON.stringify(t),r=JSON.stringify(e);return n||i<=r?`${i} ${r}`:`${r} ${i}`}function bre(t,e,n,i){const r=new Set;for(const s of e)I(s)&&typeof s[i]=="string"&&r.add(s[i]);for(const s of n)if(I(s)){for(const o of[is(s,t.json.sourceKey,y0).value,is(s,t.json.targetKey,b0).value])if(typeof o=="number"&&r.has(String(o))){t.report.warning("coercion",L.INDEX_LINKS,`integer endpoints are read as array positions, but ${o} is also a node id; pass indexLinks: false to read the endpoints as ids`,{element:"indexLinks"});return}}}function ih(t,e,n,i,r){for(const s of Object.keys(n))r(s)&&t.write(e,s,n[s],Lt.data,String(i))}function Ere(t,e,n,i){if(e.length===0||t.length===0)return!1;for(const s of t)if(I(s)&&typeof s[n]=="number")return!1;let r=0;for(const s of e){if(!I(s))continue;const o=is(s,i.sourceKey,y0).value,l=is(s,i.targetKey,b0).value;if(o!==void 0&&typeof o!="number"||l!==void 0&&typeof l!="number")return!1;(Am(o,1/0)||Am(l,1/0))&&r++}return r>0}function JO(t,e,n,i,r){if(n===null)return t.coerceId(e,`${i}.${r}`);if(!Am(e,n.length))return t.report.error("validation-error",L.BAD_INDEX,`${i}: ${r} ${Ye(e)} is not a node index below ${n.length}`,{element:i}),null;const s=n[e];return s===null&&t.report.error("missing-value",L.BAD_INDEX,`${i}: ${r} names a node that was skipped`,{element:i}),s}function wre(t,e){const{report:n,json:i}=t,r=Dn(e.nodes,"nodes",n)??[],s=Dn(e.edges,"edges",n)??[];Ba(t,e,cre,""),t.setHeader(t.defaultDirected("vis")),t.sink.reserve(r.length,s.length);const o=i.nodeIdKey??"id";t.reportNodeIdFrom("vis",`the ${JSON.stringify(o)} key`);for(let f=0;f<r.length;f++){const h=`nodes[${f}]`,p=r[f];if(!I(p)){t.badElement("node",h);continue}const g=t.coerceId(z(p,o)?p[o]:void 0,h);if(g===null){t.countSkipped("node");continue}const m=t.pushNode(g,h);m>=0&&ih(t.nodes,m,p,g,y=>y!==o)}F(t.options.signal);const l=t.declareEdgeIds(s,f=>f.id,"id",!0),a=t.uniformKind();let c=null,d=null;for(let f=0;f<s.length;f++){const h=`edges[${f}]`,p=s[f];if(!I(p)){t.badElement("edge",h);continue}const g=is(p,i.sourceKey,Qie),m=is(p,i.targetKey,ere);if(g.key===null||m.key===null){t.missingEndpoint(h,g.key===null?"from":"to");continue}c??=g.key,d??=m.key;try{const y=t.coerceId(g.value,`${h}.from`),b=t.coerceId(m.value,`${h}.to`);if(y===null||b===null){t.countSkipped("edge");continue}const _=t.edgeIdValue(l,p.id),S=t.pushEdge(y,b,a,t.weightOf(p),h);t.setEdgeId(l,S,_);const{weightFrom:T}=t.options;for(const $ of Object.keys(p))$!==g.key&&$!==m.key&&$!=="id"&&$!==T&&t.edges.write(S,$,p[$],Lt.data,h)}catch(y){t.skip(y,"edge",h)}}const u=a==="undirected"?s.filter(f=>I(f)&&f.arrows!==void 0&&f.arrows!==null&&f.arrows!=="").length:0;u>0&&n.warning("validation-error",L.INCONSISTENT,`${u} edge${O(u)} ${C(u,"carries","carry")} vis.js arrows but the graph is read undirected; the arrows are kept as an attribute (pass defaultDirected: true to read the edges as directed)`,{element:"arrows"}),t.styleSource={dialect:"vis",block:mc(e),options:e.options,groups:e.groups},t.setMeta({dialect:"vis",nodeIdKey:o,sourceKey:c??void 0,targetKey:d??void 0},t.weightOriginPatch())}function _re(t,e){const{report:n}=t,i=Dn(e.nodes,"nodes",n)??[],r=Dn(e.adjacency,"adjacency",n);r===null&&n.warning("missing-value",L.MISSING_SECTION,"the document has no adjacency array; the graph has no edges",{element:"adjacency"});const s=ns(e.directed,"directed",t.defaultDirected("adjacency"),n),o=z(e,"multigraph")?ns(e.multigraph,"multigraph",!1,n):null;t.setHeader(s),t.writeGraphDict(vre(e.graph)?Object.fromEntries(e.graph):e.graph,"graph"),Ore(t,e);const l=r??[];t.sink.reserve(i.length,l.reduce((u,f)=>u+(Array.isArray(f)?f.length:0),0));const a=t.json.nodeIdKey??"id";t.reportNodeIdFrom("adjacency",`the ${JSON.stringify(a)} key`);const c=i.map((u,f)=>Nre(t,u,`nodes[${f}]`,a));F(t.options.signal);const d={owners:c,nodeCount:i.length,directed:s,kind:t.uniformKind(),idKey:a,pending:new Map,disagreeing:0};for(let u=0;u<l.length;u++)Are(t,d,u,l[u]);Ire(t,i.length,r===null?null:l.length,d.disagreeing,d.pending),t.setMeta({},{declaredMultigraph:o,...t.weightOriginPatch()})}const Sre=new Set(["nodes","adjacency","directed","multigraph","graph"]);function Ore(t,e){for(const n of Object.keys(e))Sre.has(n)||t.report.warning("unsupported",L.UNREAD_KEY,`top-level key ${n} (${Ye(e[n])}) is not read; dropped`,{element:n})}function Nre(t,e,n,i){if(!I(e))return t.badElement("node",n),null;const r=t.coerceId(z(e,i)?e[i]:void 0,n);if(r===null)return t.countSkipped("node"),null;const s=t.pushNode(r,n);return s<0?null:(ih(t.nodes,s,e,r,o=>o!==i),r)}function Are(t,e,n,i){const{report:r}=t,s=`adjacency[${n}]`;if(!Array.isArray(i)){r.error("validation-error",L.BAD_ELEMENT,`${s} is not an array`,{element:s});return}const o=n<e.owners.length?e.owners[n]:null;if(o===null){const l=n<e.nodeCount?`nodes[${n}] was skipped`:`there is no nodes[${n}]`;r.error("missing-value",L.BAD_INDEX,`${s}: ${l}; its ${i.length} edge${O(i.length)} ${C(i.length,"is","are")} skipped`,{element:s}),r.counts.skippedEdges+=i.length;return}for(let l=0;l<i.length;l++)Tre(t,e,o,i[l],s,`${s}[${l}]`)}function Tre(t,e,n,i,r,s){const{idKey:o}=e;if(!I(i)){t.badElement("edge",s);return}if(!z(i,o)){t.missingEndpoint(s,o);return}try{const l=t.coerceId(i[o],`${s}.${o}`);if(l===null){t.countSkipped("edge");return}if(!e.directed){const d=Cre(e.pending,n,l,i,o);if(e.disagreeing+=d==="disagrees"?1:0,d!=="new")return}const a=t.pushEdge(n,l,e.kind,t.weightOf(i),s),{weightFrom:c}=t.options;for(const d of Object.keys(i))d!==o&&d!==c&&t.edges.write(a,d,i[d],Lt.data,r)}catch(l){t.skip(l,"edge",s)}}function Ire(t,e,n,i,r){const{report:s}=t;n!==null&&n<e&&s.warning("missing-value",L.MISSING_SECTION,`${e-n} node${O(e-n)} from nodes[${n}] on ${C(e-n,"has","have")} no adjacency list (NetworkX writes one per node); their edges listed elsewhere are kept`,{element:"adjacency"}),i>0&&s.warning("validation-error",L.INCONSISTENT,`the two listings of ${i} undirected edge${O(i)} ${C(i,"disagrees","disagree")} on their attributes; the first listing is kept`,{element:"adjacency"});let o=0;for(const l of r.values())o+=l.length;o>0&&s.warning("validation-error",L.INCONSISTENT,`${o} undirected adjacency entr(ies) have no mirror in the other node's list; each is read as one edge`,{element:"adjacency"})}function $re(t,e){return I(e)?Object.fromEntries(Object.entries(e).sort(([n],[i])=>n<i?-1:1)):e}function Cre(t,e,n,i,r){const s=JSON.stringify(e),o=JSON.stringify(n);if(s===o)return"new";const l=JSON.stringify(i.key??null),a=JSON.stringify(Object.fromEntries(Object.entries(i).filter(([f])=>f!==r)),$re),c=t.get(`${o} ${s} ${l}`);if(c!==void 0&&c.length>0)return c.shift()===a?"mirror":"disagrees";const d=`${s} ${o} ${l}`,u=t.get(d);return u===void 0?t.set(d,[a]):u.push(a),"new"}function vre(t){return Array.isArray(t)&&t.every(e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="string")}function Dre(t,e){const n=t.json.nodeIdKey??"id";t.setHeader(t.defaultDirected("tree")),t.reportNodeIdFrom("tree",`the ${JSON.stringify(n)} key`);const i=t.uniformKind(),r=[{record:e,element:"root",parent:null}];for(let s=r.pop();s!==void 0;s=r.pop()){const{record:o,element:l,parent:a}=s;if(!I(o)){t.badElement("node",l);continue}let c=t.coerceId(z(o,n)?o[n]:void 0,l);if(c===null)t.countSkipped("node");else if(t.pushNode(c,l)<0)c=null;else if(ih(t.nodes,t.sink.indexOf(c),o,c,u=>u!==n&&u!=="children"),a!==null)try{t.pushEdge(a,c,i,void 0,l)}catch(u){t.skip(u,"edge",l)}const{children:d}=o;if(Array.isArray(d))for(let u=d.length-1;u>=0;u--)r.push({record:d[u],element:`${l}.children[${u}]`,parent:c});else d!=null&&t.report.error("validation-error",L.BAD_VALUE,`${l}: children must be an array, found ${Ye(d)}`,{element:l})}t.setMeta({})}function kre(t,e){const{report:n}=t,i=Dn(e.nodes,"nodes",n)??[],r=Dn(e.edges,"edges",n)??[];Ba(t,e,dre,"");const s=I(e.options)?e.options:{};z(e,"options")&&!I(e.options)&&n.warning("validation-error",L.BAD_FLAG,"options is not an object; ignored",{element:"options"});const o=Rre(t,s);t.setHeader(o==="mixed"?Lre(t,r):o==="directed");const l=z(s,"multi")?ns(s.multi,"options.multi",!1,n):null,a=z(s,"allowSelfLoops")?ns(s.allowSelfLoops,"options.allowSelfLoops",!0,n):void 0;t.writeGraphDict(e.attributes,"attributes");const c=i.find(f=>I(f)),d=I(c)&&!z(c,"key")&&z(c,"id");t.styleSource={dialect:"graphology",block:mc(e),gephi:d,sigma:t.json.sigma},t.reportNodeIdFrom("graphology","the node key"),t.sink.reserve(i.length,r.length),Pre(t,i,d),F(t.options.signal);const u=xre(t,r,{type:o,gephi:d,multi:l,allowSelfLoops:a});Gre(t,u,o),t.setMeta({dialect:"graphology",allowSelfLoops:a},{declaredMultigraph:l,...t.weightOriginPatch()})}function Rre(t,e){return e.type==="directed"||e.type==="undirected"||e.type==="mixed"?e.type:(e.type!==void 0&&e.type!==null&&t.report.warning("validation-error",L.BAD_FLAG,`options.type ${Ye(e.type)} is not directed, undirected or mixed; mixed assumed`,{element:"options.type"}),"mixed")}function Lre(t,e){const n=e.filter(r=>I(r)),i=n.filter(r=>r.undirected===!0).length;return n.length===0?t.defaultDirected("graphology"):i<n.length}function Pre(t,e,n){const i=n?"id":"key";for(let r=0;r<e.length;r++){const s=`nodes[${r}]`,o=e[r];if(!I(o)){t.badElement("node",s);continue}const l=t.coerceId(z(o,i)?o[i]:void 0,s);if(l===null){t.countSkipped("node");continue}jre(t,l,o,"attributes",n?Xie:Kie,s,n)}}function xre(t,e,n){const{gephi:i}=n,r=t.declareEdgeIds(e,l=>i&&!z(l,"key")?l.id:l.key,"key",!0),s={selfLoops:0,parallels:0,flags:0},o=n.multi===!1?new Set:null;for(let l=0;l<e.length;l++){const a=`edges[${l}]`,c=Mre(t,e[l],a);if(c!==null)try{const d=Ure(t,c,a,r,n,s);d!==null&&o!==null&&(s.parallels+=o.has(d)?1:0,o.add(d))}catch(d){t.skip(d,"edge",a)}}return s}function Mre(t,e,n){return I(e)?!$n(e,"source")||!$n(e,"target")?(t.missingEndpoint(n,$n(e,"source")?"target":"source"),null):e:(t.badElement("edge",n),null)}function Ure(t,e,n,i,r,s){const{report:o}=t,{type:l,gephi:a}=r,c=t.coerceId(e.source,`${n}.source`),d=t.coerceId(e.target,`${n}.target`);if(c===null||d===null)return t.countSkipped("edge"),null;let u;l==="mixed"?u=ns(e.undirected,`${n}.undirected`,!1,o)?"undirected":"directed":(u=l,typeof e.undirected=="boolean"&&e.undirected!==(l==="undirected")&&s.flags++);const{attributes:f}=e;f!=null&&!I(f)&&o.error("validation-error",L.BAD_VALUE,`${n}: attributes must be an object, found ${Ye(f)}`,{element:n});const h=I(f)?f:{},p=t.edgeIdValue(i,e.key),g=t.pushEdge(c,d,u,t.weightOf(h),n);return t.setEdgeId(i,g,p),t.writeNested(t.edges,g,e,h,a?qie:Nk,n,{weightFrom:t.options.weightFrom,plain:a,dataKeys:a?Zie:void 0}),r.allowSelfLoops===!1&&c===d&&s.selfLoops++,`${u} ${Ik(c,d,u==="directed")}`}function Gre(t,e,n){const i=[];e.selfLoops>0&&i.push(`options.allowSelfLoops is false, but ${e.selfLoops} self-loop${O(e.selfLoops)} ${C(e.selfLoops,"is","are")} listed`),e.parallels>0&&i.push(`options.multi is false, but ${e.parallels} parallel edge${O(e.parallels)} ${C(e.parallels,"is","are")} listed`),e.flags>0&&i.push(`options.type is ${n}, but ${e.flags} edge${O(e.flags)} ${C(e.flags,"carries","carry")} the other undirected flag; read as ${n}`);for(const r of i)t.report.warning("validation-error",L.INCONSISTENT,`${r}; every edge is kept`,{element:"options"})}function jre(t,e,n,i,r,s,o=!1){const l=t.pushNode(e,s);if(l<0)return l;try{const a=n[i];a!=null&&!I(a)&&t.report.error("validation-error",L.BAD_VALUE,`${s}: ${i} must be an object, found ${Ye(a)}`,{element:s}),t.writeNested(t.nodes,l,n,I(a)?a:{},r,s,{plain:o,dataKeys:o?Jie:void 0})}catch(a){t.report.recordError(a,{element:String(e)})}return l}function Fre(t,e){const{report:n}=t,i=Kre(t,e),r=Dn(i.edges,"graph.edges",n)??[],s=Dn(i.hyperedges,"graph.hyperedges",n)??[],o=i.nodes;o!=null&&!I(o)&&!Array.isArray(o)&&n.fail(L.SHAPE,`graph.nodes must be an object keyed by id or an array, found ${Ye(o)}`);const l=Array.isArray(o)?o:Object.values(o??{}),a=zre(t,i,r);t.setHeader(a),t.writeGraphDict(i.metadata,"graph.metadata");const c={dialect:"jgf",id:typeof i.id=="string"?i.id:void 0,type:typeof i.type=="string"?i.type:void 0},d=typeof i.label=="string"?i.label:null;t.reportNodeIdFrom("jgf","the node keys"),t.sink.reserve(l.length,r.length);const u=t.nodes.declareIf({name:"label",dtype:"string",role:"label",nullable:!0},mr(l,"label"));if(I(o))for(const h of Yre(t,e,i,o))Wre(t,h,o[h],u);else for(let h=0;h<l.length;h++)Bre(t,l[h],u,`nodes[${h}]`);F(t.options.signal);const f=Hre(t,r,s);for(let h=0;h<r.length;h++)Vre(t,r[h],`edges[${h}]`,a,f);qre(t,s,a,f),t.setMeta(c,{name:d,...t.weightOriginPatch()})}function zre(t,e,n){if(typeof e.directed=="boolean")return e.directed;if(t.explicitDefaultDirected)return t.options.defaultDirected;e.directed!==void 0&&e.directed!==null&&t.report.warning("validation-error",L.BAD_FLAG,`graph.directed is ${Ye(e.directed)}, not a boolean`,{element:"graph.directed"});const i=n.filter(r=>I(r));return i.length===0||!i.every(r=>r.directed===!1)}function Wre(t,e,n,i){const r=`nodes[${JSON.stringify(e)}]`;if(n!==null&&!I(n)){t.badElement("node",r);return}const s=t.coerceId(e,r);if(s===null){t.countSkipped("node");return}n!==null&&z(n,"id")&&n.id!==e&&t.report.warning("validation-error",L.INCONSISTENT,`${r}: the inner id ${Ye(n.id)} differs from the key; the key is the id, the inner one is kept as id${Lt.element}`,{element:r}),Ck(t,s,n??{},i,r)}function Bre(t,e,n,i){if(!I(e)){t.badElement("node",i);return}const r=t.coerceId(z(e,"id")?e.id:void 0,i);if(r===null){t.countSkipped("node");return}Ck(t,r,e,n,i)}function Hre(t,e,n){const i=t.declareEdgeIds([...e,...n],o=>o.id,"id",!1),r=t.edges.declareIf({name:"relation",dtype:"string",role:"kind",nullable:!0},mr(e,"relation")||mr(n,"relation")),s=t.edges.declareIf({name:"label",dtype:"string",role:"label",nullable:!0},mr(e,"label")||mr(n,"label"));return(o,l,a,c,d,u=Ok)=>{const{metadata:f}=o,h=I(f)?f:{},p=t.edgeIdValue(i,o.id),g=t.pushEdge(l,a,c,t.weightOf(h),d);t.setEdgeId(i,g,p),t.writeStringField(t.edges,r,g,o.relation,"relation",d),t.writeStringField(t.edges,s,g,o.label,"label",d),f!=null&&!I(f)&&t.report.error("validation-error",L.BAD_VALUE,`${d}: metadata must be an object`,{element:d}),t.writeNested(t.edges,g,o,h,u,d,{weightFrom:t.options.weightFrom})}}function Vre(t,e,n,i,r){if(!I(e)){t.badElement("edge",n);return}if(!$n(e,"source")||!$n(e,"target")){t.missingEndpoint(n,$n(e,"source")?"target":"source");return}try{const s=t.coerceId(e.source,`${n}.source`),o=t.coerceId(e.target,`${n}.target`);if(s===null||o===null){t.countSkipped("edge");return}const l=ns(e.directed,`${n}.directed`,i,t.report);r(e,s,o,l?"directed":"undirected",n)}catch(s){t.skip(s,"edge",n)}}function Yre(t,e,n,i){const r=Object.keys(i);if(!r.some(o=>Vie.test(o)))return r;const s=I(e.graph)?["graph","nodes"]:["graphs",e.graphs.indexOf(n),"nodes"];return S3(t.text,s)??r}function Kre(t,e){const n=I(e.graph);Ba(t,e,new Set([n?"graph":"graphs"]),"");const i=n?e.graph:$k(t,e,"JGF"),r=n?"graph.":`graphs[${e.graphs.indexOf(i)}].`;Ba(t,i,ure,r);for(const s of["id","type","label"])i[s]!==void 0&&i[s]!==null&&typeof i[s]!="string"&&t.report.error("validation-error",L.BAD_VALUE,`${r}${s} must be a string, found ${Ye(i[s])}; ignored`,{element:`${r}${s}`});return i}function $k(t,e,n){const{report:i}=t,r=Dn(e.graphs,"graphs",i)??[];r.length===0&&i.fail(L.SHAPE,`a ${n} document needs a graph object or a non-empty graphs array`);const s=t.json.all===!0?t.json.graphIndex:ml(r.map(Tm),t.json.choice,i);r.length>1&&t.json.all!==!0&&!io(t.json.choice)&&i.warning("unsupported",L.MULTIPLE_GRAPHS,`the document holds ${r.length} graphs; only graphs[${s}] is read (${r.length-1} skipped); importAllGraphs() reads every one`,{element:"graphs"});const o=r[s];return I(o)?o:t.json.all!==!0?i.fail(L.SHAPE,`graphs[${s}] is not an object`):(i.error("validation-error",L.SHAPE,`graphs[${s}] is not an object; it is read as empty`,{element:`graphs[${s}]`}),{})}function Tm(t){if(!I(t))return null;for(const e of["id","label","lbl"])if(typeof t[e]=="string")return t[e];return null}function Qc(t){return t==null?0:Array.isArray(t)?t.length:I(t)?Object.keys(t).length:null}function ZO(t,e){if((e==="jgf"||e==="obographs")&&I(t)){if(Array.isArray(t.graphs)&&!I(t.graph))return t.graphs.map((n,i)=>({index:i,name:Tm(n),nodes:I(n)?Qc(n.nodes):null,edges:I(n)?Qc(n.edges):null}));if(I(t.graph)){const{graph:n}=t;return[{index:0,name:Tm(n),nodes:Qc(n.nodes),edges:Qc(n.edges)}]}}return[{index:0,name:null,nodes:null,edges:null}]}function Xre(t){const e=t.slice(0,65536).split(/\r?\n/).filter(n=>n.trim().length>0).slice(0,2);return e.length===2&&e.every(n=>{try{const i=JSON.parse(n);return typeof i=="object"&&i!==null}catch{return!1}})}function Ck(t,e,n,i,r){const s=t.pushNode(e,r);if(!(s<0))try{t.writeStringField(t.nodes,i,s,n.label,"label",r);const{metadata:o}=n;o!=null&&!I(o)&&t.report.error("validation-error",L.BAD_VALUE,`${r}: metadata must be an object`,{element:r}),t.writeNested(t.nodes,s,n,I(o)?o:{},Yie,r)}catch(o){t.report.recordError(o,{element:String(e)})}}function qre(t,e,n,i){if(e.length===0)return;const{report:r}=t,s=t.options.hyperedges;if(s==="error")throw r.error("unsupported",L.HYPEREDGE,`${e.length} hyperedge${O(e.length)} (hyperedges: "error")`,{element:"hyperedges"}),r.abort("hyperedges refused",{code:L.HYPEREDGE,count:e.length});if(s==="skip"){r.warning("unsupported",L.HYPEREDGES_SKIPPED,`${e.length} hyperedge${O(e.length)} skipped`,{element:"hyperedges"}),r.loss(L.HYPEREDGES_SKIPPED,`${e.length} hyperedge${O(e.length)} ${C(e.length,"was","were")} not imported`,null,e.length);return}const o=(a,c,d,u)=>{for(const[f,h]of c)try{i(a,f,h,d,u,Hie)}catch(p){t.skip(p,"edge",u)}},l={used:0};for(let a=0;a<e.length;a++){const c=`hyperedges[${a}]`,d=e[a];if(!I(d)){t.badElement("edge",c);continue}try{if(Array.isArray(d.nodes)){const u=Jre(t,d.nodes.map(p=>t.requireId(p,c)),c);if(u.length<2)throw new N("E_INVALID_ID",`${c}: an undirected hyperedge needs two or more nodes`,{reason:"hyperedge shape"});const f=u.length;QO(s==="star"?f-1:f*(f-1)/2,l,c);const h=[];if(s==="star")for(let p=1;p<f;p++)h.push([u[0],u[p]]);else for(let p=0;p<f;p++)for(let g=p+1;g<f;g++)h.push([u[p],u[g]]);o(d,h,n?"directed":"undirected",c)}else if(Array.isArray(d.source)&&Array.isArray(d.target)){const u=d.source.map(h=>t.requireId(h,c)),f=d.target.map(h=>t.requireId(h,c));if(u.length===0||f.length===0)throw new N("E_INVALID_ID",`${c}: a directed hyperedge needs sources and targets`,{reason:"hyperedge shape"});QO(u.length*f.length,l,c),o(d,u.flatMap(h=>f.map(p=>[h,p])),"directed",c)}else r.error("validation-error",L.HYPEREDGE_SHAPE,`${c} has neither a nodes array nor source / target arrays`,{element:c}),t.countSkipped("edge")}catch(u){u instanceof vk?(r.error("unsupported",u.code,u.message,{element:c}),t.countSkipped("edge")):t.skip(u,"edge",c)}}}class vk extends N{}const Ap=1e6;function QO(t,e,n){if(e.used+t>Ap)throw new vk("E_TOO_LARGE",`${n}: the expansion makes ${t} edges, which with the ${e.used} already expanded is more than ${Ap}; the hyperedge is skipped`,{count:t,used:e.used,limit:Ap});e.used+=t}function Jre(t,e,n){const i=[...new Set(e)];return i.length<e.length&&t.report.error("validation-error",L.HYPEREDGE_SHAPE,`${n} lists ${e.length-i.length} member${O(e.length-i.length)} more than once; each is read once`,{element:n}),i}function Zre(t,e){const{elements:n,extra:i}=Qre(t,e),{nodes:r,edges:s}=lse(t,n),o=ase(r);t.styleSource={dialect:"cytoscape",block:mc(e),elements:n??[],style:I(e)?e.style:void 0,generatedBy:I(e)&&typeof e.generated_by=="string"?e.generated_by:null,generatedIds:o},t.setHeader(t.defaultDirected("cytoscape")),t.reportNodeIdFrom("cytoscape","data.id"),t.sink.reserve(r.length,s.length);const l=ese(t,r),a=t.edges.declareIf({name:ak,dtype:"list",itemDtype:"string",role:"classes",nullable:!0},mr(s,"classes")),c=[];for(let d=0;d<r.length;d++){const u=`nodes[${d}]`,f=r[d];if(I(f)&&I(f.data)){const h=f.data.id===void 0?o.get(f):f.data.id;tse(t,f,f.data,h,u,l,c)}else t.badElement("node",u,"an element with a data object")}ise(t,c,l.parent),F(t.options.signal),sse(t,s,a),t.setMeta({dialect:"cytoscape",cytoscape:i},t.weightOriginPatch())}function Qre(t,e){if(Array.isArray(e))return{elements:e};I(e)||t.report.fail(L.SHAPE,`a Cytoscape document must be an object or an array, found ${Ye(e)}`);const n=e;t.writeGraphDict(n.data,"data");const i={};for(const r of Object.keys(n))r!=="elements"&&r!=="data"&&r!==Z&&(i[r]=n[r]);return Object.keys(i).length>0?{elements:n.elements,extra:i}:{elements:n.elements}}function ese(t,e){const n=(i,r)=>i.some(s=>I(s)&&I(s.data)&&s.data[r]!==void 0);return{position:t.nodes.declareIf({name:$te,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,extra:{sourceDims:e.some(cse)?3:2,units:"file"},origin:{format:"json",namespace:"cytoscape"}},mr(e,"position")),classes:t.nodes.declareIf({name:ak,dtype:"list",itemDtype:"string",role:"classes",nullable:!0},mr(e,"classes")),parent:t.nodes.declareIf({name:Cte,dtype:"u32",role:"parent",refersTo:"node",nullable:!0},n(e,"parent"))}}function tse(t,e,n,i,r,s,o){const{report:l}=t,a=t.coerceId(i,r);if(a===null){t.countSkipped("node");return}const c=t.pushNode(a,r);if(!(c<0)){$n(n,"source")&&$n(n,"target")&&l.warning("validation-error",L.INCONSISTENT,`${r} has data.source and data.target, the shape of an edge, but its section or group says node; read as a node`,{element:r});try{for(const d of Object.keys(n).filter(u=>u!=="id")){if(d!=="parent"){t.nodes.write(c,d,n[d],Lt.data,r);continue}const u=n.parent===null?null:t.coerceId(n.parent,`${r}.data.parent`);u!==null&&o.push({index:c,parent:u,element:r})}nse(t,s.position,c,e.position,r),Dk(t,t.nodes,s.classes,c,e.classes,r),kk(t.nodes,c,e,r)}catch(d){l.recordError(d,{element:String(a)})}}}function nse(t,e,n,i,r){if(i==null)return;const s=I(i)?i.z??0:0;I(i)&&Tp(i.x)&&Tp(i.y)&&Tp(s)?t.nodes.set(e,n,[i.x,Bo(i.y),s]):t.report.error("validation-error",L.BAD_VALUE,`${r}: position must be an object with numeric x and y (and z) that are finite numbers`,{element:r})}function ise(t,e,n){const{report:i}=t,r=new Map;for(let o=0;o<e.length;o++){const{index:l,element:a}=e[o];let{parent:c}=e[o];t.sink.indexOf(c)===A&&(c=t.textualId(c,a)??c);const d=t.sink.indexOf(c);if(d===A){i.error("missing-value",L.UNKNOWN_PARENT,`${a}: parent ${JSON.stringify(c)} is not a node`,{element:a});continue}r.set(l,{parent:d,id:c,order:o,element:a})}const s=new Set;for(const o of r.keys()){const l=[],a=new Set;let c=o;for(;c!==void 0&&!s.has(c)&&!a.has(c);)l.push(c),a.add(c),c=r.get(c)?.parent;c!==void 0&&a.has(c)&&rse(i,r,l.slice(l.indexOf(c)));for(const d of l)s.add(d)}for(const[o,{parent:l}]of r)t.nodes.set(n,o,l)}function rse(t,e,n){let i=null;for(const o of n){const l=e.get(o);l!==void 0&&(i===null||l.order>i[1].order)&&(i=[o,l])}if(i===null)return;const{id:r,element:s}=i[1];t.error("validation-error",L.PARENT_CYCLE,`${s}: parent ${JSON.stringify(r)} would make the node its own ancestor; the link is dropped`,{element:s}),e.delete(i[0])}function sse(t,e,n){const i=t.declareEdgeIds(e,s=>I(s.data)?s.data.id:void 0,"id",!0),r=t.uniformKind();for(let s=0;s<e.length;s++){const o=`edges[${s}]`,l=e[s];if(!I(l)||!I(l.data)){t.badElement("edge",o,"an element with a data object");continue}const{data:a}=l;if(!$n(a,"source")||!$n(a,"target")){t.missingEndpoint(o,`data.${$n(a,"source")?"target":"source"}`);continue}ose(t,{ids:i,kind:r,edgeClassesColumn:n},l,a,o)}}function ose(t,e,n,i,r){const{ids:s,kind:o,edgeClassesColumn:l}=e;try{const a=t.textualId(i.source,`${r}.data.source`),c=t.textualId(i.target,`${r}.data.target`);if(a===null||c===null){t.countSkipped("edge");return}const d=t.edgeIdValue(s,i.id),u=t.pushEdge(a,c,o,t.weightOf(i),r);t.setEdgeId(s,u,d);const{weightFrom:f}=t.options;for(const h of Object.keys(i))h!=="id"&&h!=="source"&&h!=="target"&&h!==f&&t.edges.write(u,h,i[h],Lt.data,r);Dk(t,t.edges,l,u,n.classes,r),kk(t.edges,u,n,r)}catch(a){t.skip(a,"edge",r)}}function lse(t,e){const{report:n}=t;if(Array.isArray(e)){const i=[],r=[];return e.forEach((s,o)=>{I(s)&&s.group!==void 0&&s.group!=="nodes"&&s.group!=="edges"&&n.error("validation-error",L.BAD_VALUE,`elements[${o}]: group ${Ye(s.group)} is neither "nodes" nor "edges"; classed by its endpoints`,{element:`elements[${o}]`}),(I(s)&&!dse(s)?r:i).push(s)}),{nodes:i,edges:r}}return I(e)?{nodes:Dn(e.nodes,"elements.nodes",n)??[],edges:Dn(e.edges,"elements.edges",n)??[]}:e==null?(n.warning("missing-value",L.MISSING_SECTION,"the document has no elements",{element:"elements"}),{nodes:[],edges:[]}):n.fail(L.SHAPE,`elements must be an object or an array, found ${Ye(e)}`)}function ase(t){const e=new Map,n=t.filter(r=>I(r)&&I(r.data)&&r.data.id===void 0);if(n.length===0)return e;const i=new Set;for(const r of t){const s=I(r)&&I(r.data)?r.data.id:void 0;(typeof s=="string"||typeof s=="number")&&i.add(String(s))}for(let r=0;r<n.length;r++){let s=`n${String(r)}`,o=2;for(;i.has(s);)s=`n${String(r)}_${String(o)}`,o++;i.add(s),e.set(n[r],s)}return e}function mc(t){return I(t)&&typeof t[Z]=="string"?t[Z]:null}function cse(t){return I(t)&&I(t.position)&&typeof t.position.z=="number"}function Tp(t){return typeof t=="number"&&Number.isFinite(t)}function dse(t){if(t.group==="nodes")return!0;if(t.group==="edges")return!1;const{data:e}=t;return!(I(e)&&z(e,"source")&&z(e,"target"))}function Dk(t,e,n,i,r,s){if(n===A||r===void 0||r===null)return;let o;if(typeof r=="string")o=r.split(/\s+/).filter(l=>l.length>0);else if(Array.isArray(r)&&r.every(l=>typeof l=="string"))o=r;else{t.report.error("validation-error",L.BAD_VALUE,`${s}: classes must be a string or an array of strings`,{element:s});return}e.set(n,i,o)}function kk(t,e,n,i){for(const r of Object.keys(n)){if(Ite.has(r))continue;const s=lk.has(r)?r:`${r}${Lt.element}`;t.write(e,s,n[r],Lt.data,i)}}const use=Object.freeze({format:"json",options:Object.freeze(["dialect","edgesKey","edgesPath","indexLinks","nodeIdKey","nodesPath","oboIds","sigmaSettings","sourceKey","targetKey","typedefs"]),extensions:Object.freeze([".json"]),positions:Xte,mimeTypes:Object.freeze(["application/json"]),sniff(t){const e=new TextDecoder("utf-8").decode(E0(t).subarray(0,Fie)),n=(e.startsWith(Bie)?e.slice(1):e).trimStart();if(!n.startsWith("{")&&!n.startsWith("["))return 0;const i=Wie.some(r=>n.includes(r))?.9:.5;return n.startsWith("[")&&ck(n)!=="cytoscape"?Math.min(i,.3):i},async import(t,e,n){const i=tt(n,wp),r=Sp(n),s=new ne("json",i.errorLimit),o=await Kr(t,s,{...i,bomlessUtf16:!0}),{root:l,dialect:a}=Op(Np(o,s),r,s);return eN({root:l,dialect:a,text:o},e,s,i,r,n),s.finish()},async listGraphs(t,e){const n=tt(e,wp),i=Sp(e),r=new ne("json",n.errorLimit),s=await Kr(t,r,{...n,bomlessUtf16:!0}),{root:o,dialect:l}=Op(Np(s,r),i,r);return ZO(o,l)},async importAll(t,e,n){const i=tt(n,wp),r=Sp(n),s=new ne("json",i.errorLimit),o=await Kr(t,s,{...i,bomlessUtf16:!0}),{root:l,dialect:a}=Op(Np(o,s),r,s),c=ZO(l,a).length,d=[];for(let u=0;u<Math.max(c,1);u++){const f=u===0?s:new ne("json",i.errorLimit);eN({root:l,dialect:a,text:o},e(u),f,i,{...r,graphIndex:u,all:!0},n),d.push(f.finish())}return d},styles:qte});function eN(t,e,n,i,r,s){const{root:o,dialect:l,text:a}=t,c=new rre(e,n,i,r,s?.defaultDirected!==void 0);c.text=a,_t(e,s,n,l==="obographs"),St(s,n,jie),fse(c,o,l),n.keepForStyles(c.styleSource??{dialect:l,block:mc(o)}),c.reportDangling(),c.nodes.reportNullOnly(),c.edges.reportNullOnly(),F(i.signal)}function fse(t,e,n){if(n==="cytoscape"){Zre(t,e);return}const i=I(e)?e:t.report.fail(L.SHAPE,`a ${n} document must be a JSON object, found ${Ye(e)}`);switch(n){case"node-link":case"d3":fre(t,i,n);break;case"jgf":Fre(t,i);break;case"graphology":kre(t,i);break;case"vis":wre(t,i);break;case"adjacency":_re(t,i);break;case"tree":Dre(t,i);break;case"obographs":yse(t,i);break;default:{const r=n;throw new N("E_UNSUPPORTED",`unknown dialect ${r}`,{option:"dialect",found:r})}}}const Rk=new Set(["id","lbl","type","propertyType","meta"]),Lk=new Set(["definition","comments","subsets","xrefs","synonyms","basicPropertyValues","deprecated"]),I0=Object.freeze({CLASS:"Term",INDIVIDUAL:"Instance",PROPERTY:"Typedef"}),Pk=Object.freeze({is_a:"is_a",subPropertyOf:"is_a",type:"instance_of",inverseOf:"inverse_of"}),xk=new Set(["subPropertyOf","inverseOf"]);class hse{constructor(e){this.handles=new Map,this.ctx=e}node(e,n,i){this.ctx.sink.setNodeValue(this.handle("node",e),n,i)}edge(e,n,i){this.ctx.sink.setEdgeValue(this.handle("edge",e),n,i)}handle(e,n){const i=`${e}:${n}`,r=this.handles.get(i);if(r!==void 0)return r;const{handle:s}=he(this.ctx.sink,e,Pa(e,n),this.ctx.report);return this.handles.set(i,s),s}}const pse=["logicalDefinitionAxioms","equivalentNodesSets","domainRangeAxioms","propertyChainAxioms"],gse=new Set(["sub","subj","pred","obj","meta"]);function mse(t,e){const n=new Map,i=new Set,r=new Set;for(const o of t){if(!I(o)||typeof o.id!="string")continue;if(o.type!=="PROPERTY"){r.add(o.id);continue}i.add(o.id);const l=Mk(o.meta).find(a=>hc.get(a.pred)==="shorthand");l!==void 0&&n.set(o.id,l.val)}const s=o=>e==="curie"?Ru(o):o;return{id:o=>e==="curie"?n.get(o)??Ru(o):o,relation:o=>Pk[o]??n.get(o)??s(o),isProperty:o=>i.has(o)&&!r.has(o),isClass:o=>r.has(o),properties:Object.create(null),written:new Map}}function Mk(t,e=null,n=""){if(!I(t)||t.basicPropertyValues===void 0||t.basicPropertyValues===null)return[];const i=`${n}.meta.basicPropertyValues`;if(!Array.isArray(t.basicPropertyValues))return e!==null&&Pt(e,`${i} must be an array; it is dropped`,i),[];const r=[];return t.basicPropertyValues.forEach((s,o)=>{I(s)&&typeof s.pred=="string"&&typeof s.val=="string"?r.push(s):e!==null&&Pt(e,`${i}[${o}] needs a string pred and a string val; it is dropped`,`${i}[${o}]`)}),r}function aa(t,e,n){if(e==null)return[];if(!Array.isArray(e))return Pt(t,`${n} must be an array; it is dropped`,n),[];const i=[];return e.forEach((r,s)=>{typeof r=="string"?i.push(r):I(r)&&typeof r.val=="string"?i.push(r.val):Pt(t,`${n}[${s}] is not a string or a { val } record; it is dropped`,`${n}[${s}]`)}),i}function yse(t,e){const n=$k(t,e,"OBO Graphs"),i=tN(t,n,"nodes"),r=tN(t,n,"edges"),s=mse(i,t.json.oboIds),o=new hse(t);t.reportNodeIdFrom("obographs","the node ids"),t.setHeader(!0),t.sink.reserve(i.length,r.length);for(let f=0;f<i.length;f++)bse(t,o,s,i[f],`nodes[${f}]`);const l=Tse(t,o,s,r),a={};for(const f of Object.keys(n))f!=="nodes"&&f!=="edges"&&(a[f]=n[f]);for(const f of pse){const h=n[f];h!=null&&!Array.isArray(h)&&Pt(t,`the graph's ${f} must be an array; it is kept as written`,f)}const c={};for(const f of Object.keys(e))f!=="graphs"&&(c[f]=e[f]);const u=(typeof n.lbl=="string"?n.lbl:null)??(typeof n.id=="string"?n.id:null);t.sink.setMeta({sourceFormat:"json",name:u,extra:{json:{dialect:"obographs"},obographs:{ids:t.json.oboIds,graph:a,document:c,properties:s.properties,propertyEdges:l}}})}function tN(t,e,n){const i=e[n];return i==null?[]:Array.isArray(i)?i:t.report.fail(L.SHAPE,`an OBO Graphs graph's ${n} must be an array`,{element:n})}function bse(t,e,n,i,r){if(!I(i)){t.badElement("node",r);return}if(typeof i.id!="string"||i.id.length===0){i.id===void 0?t.coerceId(void 0,r):i.id===""?t.report.error("missing-value",L.MISSING_ID,`${r} has an empty id; it is skipped`,{element:r}):Pt(t,`${r}.id must be a string; the node is skipped`),t.countSkipped("node");return}if(typeof i.type=="string"&&I0[i.type]===void 0&&t.report.warnOnce("unsupported",L.UNKNOWN_ELEMENT,`${r}: node type ${JSON.stringify(i.type)} is not CLASS, INDIVIDUAL or PROPERTY; kept as written`,{element:i.type},`${L.UNKNOWN_ELEMENT}:type:${i.type}`),i.type==="PROPERTY"&&t.json.typedefs==="metadata"){Ese(t,n,i,i.id,r);return}const s=n.id(i.id),o=t.coerceId(s,r),l=n.written.get(s);l===void 0&&n.written.set(s,i.id);const a=l===void 0||l===i.id?"":` (${l} and ${i.id} meet only after IRI compaction; oboIds "iri" keeps them apart)`,c=o===null?-1:t.pushNode(o,r,a);if(!(c<0))try{wse(t,e,n,i,c,r)}catch(d){t.report.recordError(d,{element:i.id})}}function Ese(t,e,n,i,r){if(Object.hasOwn(e.properties,i)){t.report.warning("merged",L.DUPLICATE_NODE,`${r}: property ${JSON.stringify(i)} is declared again; the first declaration is kept`,{element:r});return}const s=e.id(i)===i?void 0:e.id(i),o={};for(const[l,a]of Object.entries({lbl:n.lbl,propertyType:n.propertyType,shorthand:s,meta:n.meta}))a!==void 0&&(o[l]=a);e.properties[i]=o}function wse(t,e,n,i,r,s){const o={},l=(c,d)=>{const u=i[c];typeof u=="string"?e.node(d,r,d==="type"?I0[u]??u:u):u!=null&&Pt(t,`${s}.${c} must be a string`)};l("type","type"),l("lbl","name"),l("propertyType","propertyType");for(const c of Object.keys(i))Rk.has(c)||(o[c]=i[c]);const{meta:a}=i;I(a)?_se(t,e,n,a,r,o,s):a!=null&&Pt(t,`${s}.meta must be an object`),Object.keys(o).length>0&&e.node("obo.unrecognized",r,o)}function _se(t,e,n,i,r,s,o){const l=`${o}.meta`;Sse(t,e,i.definition,r,s,l);const a=aa(t,i.comments,`${l}.comments`);a.length>0&&e.node("comment",r,a.join(`
|
|
180
|
+
`));const c=aa(t,i.subsets,`${l}.subsets`).map(f=>n.id(f));c.length>0&&e.node("subset",r,c);const d=aa(t,i.xrefs,`${l}.xrefs`);d.length>0&&e.node("xref",r,d);const u=Ose(t,n,i.synonyms,`${l}.synonyms`);u.length>0&&e.node("synonym",r,u),typeof i.deprecated=="boolean"?e.node("is_obsolete",r,i.deprecated):i.deprecated!==void 0&&i.deprecated!==null&&Pt(t,`${l}.deprecated must be a boolean; it is dropped`,`${l}.deprecated`),Nse(t,e,n,i,r,s,o);for(const f of Object.keys(i))Lk.has(f)||(s[`meta.${f}`]=i[f])}function Sse(t,e,n,i,r,s){if(I(n)){const o=aa(t,n.xrefs,`${s}.definition.xrefs`);typeof n.val=="string"?(e.node("def",i,n.val),e.node("def.xrefs",i,o)):Pt(t,`${s}.definition has no string val; it is dropped`,`${s}.definition.val`),n.meta!==void 0&&(r["meta.definition.meta"]=n.meta)}else n!=null&&Pt(t,`${s}.definition must be an object with a val; it is dropped`,`${s}.definition`)}function Ose(t,e,n,i){if(n==null)return[];if(!Array.isArray(n))return Pt(t,`${i} must be an array; it is dropped`,i),[];const r=[];return n.forEach((s,o)=>{const l=`${i}[${o}]`;if(!I(s)){Pt(t,`${l} is not an object; it is dropped`,l);return}if(typeof s.val!="string"){Pt(t,`${l} has no string val; it is dropped`,`${l}.val`);return}const a=typeof s.pred=="string"?yJ(s.pred):null;a===null&&typeof s.pred=="string"&&t.report.warnOnce("unsupported",L.UNKNOWN_ELEMENT,`${l}: synonym predicate ${JSON.stringify(s.pred)} is not one of the four scopes; kept with scope null`,{element:s.pred},`${L.UNKNOWN_ELEMENT}:pred:${s.pred}`);const c={text:s.val,scope:a,type:null,xrefs:aa(t,s.xrefs,`${l}.xrefs`)};typeof s.synonymType=="string"?c.type=e.id(s.synonymType):s.synonymType!==void 0&&s.synonymType!==null&&Pt(t,`${l}.synonymType must be a string; it is dropped`,`${l}.synonymType`),s.meta!==void 0&&(c.meta=s.meta),r.push(c)}),r}function Nse(t,e,n,i,r,s,o){const l=new Map,a=new Map,c=[];Mk(i,t,o).forEach(({pred:u,val:f,meta:h},p)=>{const g=hc.get(u);if(g!=="shorthand"){if(g===void 0){const m={relation:n.id(u),value:f,datatype:null};h!==void 0&&(m.meta=h),c.push(m);return}if(h!==void 0&&(s[`meta.basicPropertyValues[${p}].meta`]=h),Ki[g].dtype==="list"){const m=l.get(g)??[];m.push(g==="alt_id"?f:n.id(f)),l.set(g,m)}else a.get(g)===f||(a.has(g)?t.report.warning("validation-error",L.DUPLICATE_ATTRIBUTE,`${o}: a second ${g} (${JSON.stringify(f)}); the first is kept`,{element:g}):(a.set(g,f),e.node(g,r,f)))}});for(const[u,f]of l)e.node(u,r,f);c.length>0&&e.node("property_value",r,c)}function Pt(t,e,n){t.report.error("validation-error",L.BAD_VALUE,e,n===void 0?void 0:{element:n})}function Ase(t,e,n){const{report:i}=t;for(const r of Object.keys(e))gse.has(r)||i.warnOnce("unsupported",L.UNREAD_KEY,`${n}: the key ${JSON.stringify(r)} is not part of an OBO Graphs edge; it is not read`,{element:`${n}.${r}`},`${L.UNREAD_KEY}:edge:${r}`);return z(e,"sub")?(z(e,"subj")&&e.subj!==e.sub&&i.warning("coercion",L.OBOGRAPHS_SUBJ,`${n} has both sub and the outdated subj, which differ; sub is read and subj ignored`,{element:n}),e.sub):(z(e,"subj")&&i.warnOnce("coercion",L.OBOGRAPHS_SUBJ,`${n} uses the outdated key subj; read as sub`,{element:n}),e.subj)}function Tse(t,e,n,i){const{report:r,sink:s}=t,o=[],l=[];let a=0;const c=(d,u)=>{const f=t.coerceId(n.id(d),u);if(f===null||s.indexOf(f)!==A)return f;if(l.push(d),!t.options.addMissingNodes)return null;const h=t.pushNode(f,u);return h>=0&&e.node(co,h,!0),f};for(let d=0;d<i.length;d++){const u=`edges[${d}]`,f=i[d];if(!I(f)){t.badElement("edge",u);continue}const h=Ase(t,f,u),{obj:p,pred:g}=f;if(typeof h!="string"||typeof p!="string"||h.length===0||p.length===0){t.missingEndpoint(u,typeof h=="string"&&h.length>0?"obj":"sub");continue}if((n.isProperty(h)&&n.isProperty(p)||typeof g=="string"&&xk.has(g)&&!n.isClass(h)&&!n.isClass(p))&&t.json.typedefs==="metadata"){o.push(f);continue}try{const y=c(h,`${u}.sub`),b=c(p,`${u}.obj`);if(y===null||b===null){a++,t.countSkipped("edge");continue}const _=t.pushEdge(y,b,"directed",void 0,u);typeof g=="string"?e.edge("relation",_,n.relation(g)):Pt(t,`${u} has no pred; its relation is unset`),I(f.meta)?e.edge("meta",_,f.meta):f.meta!==void 0&&f.meta!==null&&Pt(t,`${u}.meta must be an object; it is dropped`,`${u}.meta`)}catch(y){t.skip(y,"edge",u)}}if(l.length>0){const d=[...new Set(l)].slice(0,5).join(", "),u=t.options.addMissingNodes?"each became a placeholder node (graphty.placeholder)":`${a} edge${O(a)} to them ${C(a,"was","were")} dropped (addMissingNodes false)`;r.warning("validation-error",L.DANGLING_REFERENCE,`${new Set(l).size} edge endpoint${O(new Set(l).size)} missing from nodes: ${d}; ${u}`,{element:l[0]})}return o}const cr=Object.freeze({EDGE_COLUMN_AS_META:"W_OBOGRAPHS_EDGE_COLUMN_AS_META",ID_CHANGED:"W_OBOGRAPHS_ID_CHANGED",DATATYPE_DROPPED:"W_OBOGRAPHS_DATATYPE_DROPPED",TYPE_GAINED:"W_OBOGRAPHS_TYPE_GAINED"}),ed=Object.freeze({COLUMN_AS_PROPERTY_VALUE:cy,RELATION_ASSUMED:dy,TYPEDEF_NODES:uy,GRAPH_COLUMN_AS_METADATA:Zu}),Ise=Object.freeze({Term:"CLASS",Instance:"INDIVIDUAL",Typedef:"PROPERTY"}),$se=new Map([...hc].map(([t,e])=>[e,t])),Cse=Object.freeze({is_a:"is_a",instance_of:"type"}),vse=new Set(["type","propertyType","def","def.xrefs","comment","subset","xref","synonym","is_obsolete","namespace","created_by","creation_date","alt_id","replaced_by","consider","property_value","obo.unrecognized"]),Dse=["namespace","alt_id","created_by","creation_date","replaced_by","consider"],nN=/^[A-Za-z][A-Za-z0-9+.-]*:\/\//,kse=/^([A-Za-z][A-Za-z0-9.-]*):(.+)$/;function Rse(t){const e=t.meta.extra.obographs,n=I(e)?e:{},i={};if(I(n.properties))for(const[r,s]of Object.entries(n.properties))I(s)&&(i[r]=s);return{ids:n.ids==="iri"?"iri":"curie",graph:I(n.graph)?n.graph:{},document:I(n.document)?n.document:{},properties:i,propertyEdges:Array.isArray(n.propertyEdges)?n.propertyEdges:[]}}function Lse(t){if(!I(t)||!Array.isArray(t.basicPropertyValues))return null;for(const e of t.basicPropertyValues)if(I(e)&&typeof e.pred=="string"&&hc.get(e.pred)==="shorthand"&&typeof e.val=="string")return e.val;return null}function Pse(t,e,n){if(n!==null)return n;if(typeof e.graph.id=="string")return e.graph.id;const{obo:i}=t.meta.extra,r=I(i)&&I(i.header)?i.header:{},o=(Array.isArray(r.ontology)&&typeof r.ontology[0]=="string"?r.ontology[0].trim():null)??t.meta.name,l=o===null||o.length===0?"graph":o.replaceAll(/[^A-Za-z0-9_.\-/]/g,"_");return`${Vf}${l}.owl`}function tr(t,e){return typeof t=="number"?Number.isFinite(t)?Object.is(t,-0)?"-0":eh(JSON.stringify(t)):(e.count++,"null"):Array.isArray(t)?`[${t.map(n=>tr(n,e)).join(",")}]`:I(t)?`{${Object.entries(t).filter(([,n])=>n!==void 0).map(([n,i])=>`${JSON.stringify(n)}:${tr(i,e)}`).join(",")}}`:JSON.stringify(t)??"null"}function td(t,e=!1){return Array.isArray(t)&&(e||t.length>0)&&t.every(n=>typeof n=="string")}function xse(t,e){const n=Ne(t,e);return n===void 0?[]:t.dtype==="list"?n.map(r=>rl(r,t.child.dtype)):[t.dtype==="json"||t.meta.components>1?JSON.stringify(n)??"null":rl(n,t.dtype)]}function Mse(t){const e=[];for(const n of t.graph){const i=n.dtype==="list"?n.child.dtype:n.dtype;for(const r of TD(Ne(n,0)))e.push({pred:n.meta.name,val:typeof r=="string"?r:rl(r,i)})}return e}function Use(t,e,n){const i=n.dtype==="list"&&n.child.dtype!=="string";((e==="string"||e==="dict")&&n.dtype!==e||i)&&t(w.DTYPE,`node column "${n.meta.name}" holds ${i?"non-string items":n.dtype}; it reads back as ${i?"string items":e}`,n.meta.name,n.length-n.nullCount)}function Gse(t,e){let n=0;for(const i of e)for(const r of Ne(t,i)??[])n+=r.datatype===null?0:1;return n}class jse{constructor(e,n){this.snapshot=e,this.notes=[],this.note=(i,r,s=null,o=null)=>{this.notes.push(Object.freeze({code:i,message:r,column:s,count:o}))},this.shorthands=new Map,this.shorthandIris=new Map,this.iris=[],this.changedRows=new Set,this.typedefShorthands=new Map,this.written=[],this.rows=[],this.frameless=new Uint8Array(0),this.label=null,this.placed=new Map,this.properties=[],this.metaColumn=null,this.edgeColumns=[],this.preds=new Map,this.nonfinite={count:0},this.kept=Rse(e),this.ontologyIri=Pse(e,this.kept,n.ontologyIri),this.indent=n.indent!==""?`
|
|
181
|
+
${n.indent}`:"";for(const[i,r]of Object.entries(this.kept.properties)){const s=Lse(r.meta);s!==null&&(this.shorthands.set(i,s),this.shorthandIris.set(s,i))}this.folding=Gt(e),this.ends=e.edgeList();for(let i=0;i<e.edgeCount;i++)this.folding.folded(i)||this.written.push(i);if(this.weights=Ot(e),this.planIds(),this.planNodes(),this.fatal=CD(e,n.common,{caps:Qf("obographs"),label:this.label,labelAssumed:sa(e.nodes,"label","name").assumed,edgeSlot:"edge meta",note:this.note})??this.emptyIdError(),this.planColumnNotes(),this.planEdges(n.common),vD(e,this.rows,this.frameless,this.written,this.note),this.fatal===null){const i=this.write();for(;i.next().done!==!0;);}this.nonfinite.count>0&&this.note(fy,`${this.nonfinite.count} NaN or infinite value${O(this.nonfinite.count)} ${C(this.nonfinite.count,"is","are")} written as null`,null,this.nonfinite.count)}reread(e){return this.shorthands.get(e)??Ru(e)}expand(e){if(nN.test(e))return e;const n=kse.exec(e);return n!==null&&!n[1].includes("_")?`${Vf}${n[1]}_${n[2]}`:`${this.ontologyIri}#${e}`}iriOf(e){const n=this.kept.ids==="iri"?[e]:[this.shorthandIris.get(e),this.expand(e),e].filter(r=>r!==void 0),i=n.find(r=>this.reread(r)===e);return i===void 0?{iri:n[0],exact:!1}:{iri:i,exact:!0}}predOf(e){const i=[Cse[e],this.shorthandIris.get(e),this.expand(e),e].filter(o=>o!==void 0&&!xk.has(o)),r=o=>Pk[o]??this.shorthands.get(o)??Ru(o),s=this.kept.ids==="iri"?i.find(o=>o===e&&r(o)===e):i.find(o=>r(o)===e);return s!==void 0?{pred:s,exact:!0}:{pred:this.kept.ids==="iri"?e:i[0],exact:!1}}emptyIdError(){const{snapshot:e}=this;let n=0,i=-1;for(let s=0;s<e.nodeCount;s++)String(e.ids.idOf(s))===""&&(n++,i=i<0?s:i);if(n===0)return null;const r=`${n} node id${O(n)} ${C(n,"is","are")} empty; an OBO Graphs node needs an id, so the save fails`;return this.note(w.ID_CHARSET,r,null,n),new N("E_INVALID_ID",r,{reason:"charset",count:n,id:"",index:i})}planIds(){const{snapshot:e}=this,n=e.nodes.get("type");let i=0;for(let r=0;r<e.nodeCount;r++){const s=e.ids.idOf(r);i+=typeof s=="number"?1:0;const o=String(s);let{iri:l,exact:a}=this.iriOf(o);const c=n!==null&&n.isSet(r)&&n.value(r)==="Typedef";!a&&c&&!nN.test(o)&&this.kept.ids==="curie"&&(l=this.expand(o),this.shorthands.set(l,o),this.shorthandIris.set(o,l),this.typedefShorthands.set(r,o),a=!0),this.iris.push(l),a||this.changedRows.add(r)}i>0&&this.note(w.ID_TEXT_TYPE,`${i} numeric node id${O(i)} ${C(i,"is","are")} written as text and read back as strings`,null,i)}planNodes(){const{snapshot:e}=this,{src:n,dst:i}=this.ends;this.frameless=ID(e,this.written,{outgoingAllowed:!0,changed:s=>this.changedRows.has(s)});const r=$D(this.frameless,this.written.flatMap(s=>[n[s],i[s]]));r>0&&this.note(Qu,`${r} node${O(r)} ${C(r,"reads","read")} back at another position: placeholder nodes are not written and read back after the written nodes`,null,r),this.rows=[];for(let s=0;s<e.nodeCount;s++)this.frameless[s]===0&&this.rows.push(s);this.label=sa(e.nodes,"label","name").column,this.placeColumns(),this.planProperties()}placeColumns(){const{snapshot:e}=this,n=s=>typeof s=="string"&&this.iriOf(s).exact;for(const s of vse){const o=e.nodes.get(s);o!==null&&o!==this.label&&o.meta.role===null&&Fse(s,o,this.rows,n)&&this.placed.set(s,o)}const i=this.placed.get("def"),r=this.placed.get("def.xrefs");r!==void 0&&(i===void 0||this.rows.some(s=>i.isSet(s)!==r.isSet(s)))&&this.placed.delete("def.xrefs"),i!==void 0&&!this.placed.has("def.xrefs")&&e.nodes.get("def.xrefs")!==null&&this.placed.delete("def")}planProperties(){const{snapshot:e}=this,n=new Set([...this.placed.values(),...this.label===null?[]:[this.label]]);for(const i of e.nodes){const{role:r,name:s}=i.meta;n.has(i)||r!==null&&Ma.has(r)||s===co&&this.rows.every(o=>!i.isSet(o))||(this.properties.push(i),t0(this.note,i,this.rows,`basicPropertyValues (pred ${JSON.stringify(s)})`))}}planColumnNotes(){const{snapshot:e,rows:n,label:i,note:r}=this,s=this.placed.get("type"),o=s===void 0?0:n.filter(c=>s.isSet(c)&&s.value(c)==="Typedef").length;n.length>0&&e.nodes.get("type")===null&&r(cr.TYPE_GAINED,`${n.length} node${O(n.length)} ${C(n.length,"is","are")} written with the type CLASS and ${C(n.length,"reads","read")} back with the type Term in a new node column "type"`,null,n.length),o>0&&r(uy,`${o} node${O(o)} ${C(o,"is","are")} written as PROPERTY nodes; they read back as nodes only when imported with typedefs: "nodes", and then their edges with them`,"type",o);for(const[c,d]of[...this.placed,...i===null?[]:[["name",i]]])Use(r,c==="name"?"string":Ki[c].dtype,d);const l=this.placed.get("property_value"),a=l===void 0?0:Gse(l,n);a>0&&r(cr.DATATYPE_DROPPED,`${a} property value${O(a)} ${C(a,"carries","carry")} an xsd datatype; OBO Graphs basicPropertyValues have none, so they read back without it`,"property_value",a);for(const c of e.graph)r(Zu,`graph column "${c.meta.name}" is written as a basicPropertyValue of the graph's meta and reads back in meta.extra.obographs, not as a column`,c.meta.name,c.length-c.nullCount)}planEdges(e){const{snapshot:n,written:i,note:r}=this,s=sa(n.edges,"kind","relation"),o=s.column;s.assumed&&o!==null&&r(w.ROLE_ASSUMED,`edge column "relation" has no role, so it is taken as the relation of each edge: it is written as each edge's pred, and reads back with the relation role ("kind")`,"relation",o.length-o.nullCount);const l=n.edges.get("meta"),a=l!==null&&l.dtype==="json"&&l.meta.role===null&&i.every(u=>!l.isSet(u)||I(Ne(l,u)));this.metaColumn=a?l:null;for(const u of n.edges){const{role:f}=u.meta;if(u===o||u===this.metaColumn||f==="id"||f!==null&&Ma.has(f))continue;this.edgeColumns.push(u);const h=i.filter(p=>u.isSet(p)).length;h>0&&r(cr.EDGE_COLUMN_AS_META,`edge column "${u.meta.name}" is written into each edge's meta and reads back inside the meta column`,u.meta.name,h)}const{weights:c}=this,d=c.weighted?i.filter(u=>c.isExplicit(u)).length:0;d>0&&r(cr.EDGE_COLUMN_AS_META,`${d} explicit edge weight${O(d)} ${C(d,"is","are")} written as "weight" in each edge's meta and read back inside the meta column, not as weights`,n.edges.byRole("weight")?.meta.name??null,d),this.planPreds(o),this.directionNotes(e)}planPreds(e){let n=0,i=0;for(const s of this.written){const o=e===null?void 0:Ne(e,s);if(typeof o!="string"){n++,this.preds.set(s,"is_a");continue}const{pred:l,exact:a}=this.predOf(o);this.preds.set(s,l),i+=a?0:1}n>0&&this.note(dy,`${n} edge${O(n)} ${C(n,"has","have")} no relation; written with the pred is_a (an ontology reads is_a as subclassing)`,e?.meta.name??null,n);const r=this.rows.filter(s=>this.changedRows.has(s)).length;r+i>0&&this.note(cr.ID_CHANGED,`${r} node id${O(r)} and ${i} relation${O(i)} are written as IRIs the importer reads back as other ids under its default oboIds "curie"`,null,r+i)}directionNotes(e){const{snapshot:n,written:i,folding:r,note:s}=this;if(!n.directed)s(Gp,`the snapshot is undirected; OBO Graphs edges are directed and read back directed (${i.length} edge${O(i.length)})`,null,i.length);else if(e.onMixedDirection!=="error"){const o=i.filter(l=>!r.sourceDirected(l)).length;o>0&&s(Gp,`${o} undirected edge${O(o)} ${C(o,"is","are")} written as one directed edge each`,null,o)}r.mutualCount>0&&s(w.MUTUAL_EXPANDED,`${r.mutualCount} mutual pair${O(r.mutualCount)} ${C(r.mutualCount,"is","are")} written as two edges; the mutual mark is lost`,null,r.mutualCount)}at(e,n){const i=this.placed.get(e);return i===void 0?void 0:Ne(i,n)}nodeRecord(e){const n={id:this.iris[e]},i=this.label===null?void 0:Ne(this.label,e);typeof i=="string"&&(n.lbl=i);const r=this.snapshot.nodes.get("type")===null?"Term":void 0,s=this.placed.has("type")?this.at("type",e):r;typeof s=="string"&&(n.type=Ise[s]??s);const o=this.at("propertyType",e);o!==void 0&&(n.propertyType=o);const l=this.nodeMeta(e),a=this.at("obo.unrecognized",e);if(I(a))for(const[c,d]of Object.entries(a))c.startsWith("meta.")?l[c.slice(5)]=d:n[c]=d;return Object.keys(l).length>0&&(n.meta=l),tr(n,this.nonfinite)}nodeMeta(e){const n={},i=this.at("def",e);typeof i=="string"&&(n.definition={val:i,xrefs:this.at("def.xrefs",e)??[]});const r=this.at("comment",e);typeof r=="string"&&(n.comments=[r]);const s=this.at("subset",e);Array.isArray(s)&&(n.subsets=s.map(d=>this.iriOf(String(d)).iri));const o=this.at("xref",e);Array.isArray(o)&&(n.xrefs=o.map(d=>({val:d})));const l=this.at("synonym",e);Array.isArray(l)&&(n.synonyms=l.map(d=>this.synonymRecord(d)));const a=this.at("is_obsolete",e);typeof a=="boolean"&&(n.deprecated=a);const c=this.propertyValues(e);return c.length>0&&(n.basicPropertyValues=c),n}synonymRecord(e){const n={pred:e.scope===null?"hasSynonym":`has${e.scope[0]}${e.scope.slice(1).toLowerCase()}Synonym`};return e.text!==null&&(n.val=e.text),e.xrefs.length>0&&(n.xrefs=e.xrefs),e.type!==null&&(n.synonymType=this.iriOf(e.type).iri),e.meta!==void 0&&(n.meta=e.meta),n}propertyValues(e){const n=[];for(const r of Dse){const s=this.at(r,e),o=$se.get(r)??r;for(const l of TD(s)){const a=String(l);n.push({pred:o,val:r==="replaced_by"||r==="consider"?this.iriOf(a).iri:a})}}const i=this.typedefShorthands.get(e);i!==void 0&&n.push({pred:`${sr}shorthand`,val:i});for(const r of this.at("property_value",e)??[])n.push({pred:this.iriOf(r.relation).iri,val:r.value});for(const r of this.properties)for(const s of xse(r,e))n.push({pred:r.meta.name,val:s});return n}edgeRecord(e){const{src:n,dst:i}=this.ends,r={sub:this.iris[n[e]],pred:this.preds.get(e),obj:this.iris[i[e]]},s=this.metaColumn===null?void 0:Ne(this.metaColumn,e),o=I(s)?{...s}:{};for(const l of this.edgeColumns){const a=Ne(l,e);a!==void 0&&(o[l.meta.name]=a)}return this.weights.weighted&&this.weights.isExplicit(e)&&(o.weight=this.weights.value(e)),(Object.keys(o).length>0||s!==void 0)&&(r.meta=o),tr(r,this.nonfinite)}graphHead(){const{kept:e,snapshot:n}=this,i={id:typeof e.graph.id=="string"?e.graph.id:this.ontologyIri},r=n.meta.name!==null&&e.graph.id===void 0,s=e.graph.lbl??(r?n.meta.name:void 0);s!==void 0&&(i.lbl=s);const o=I(e.graph.meta)?{...e.graph.meta}:{},l=Array.isArray(o.basicPropertyValues)?[...o.basicPropertyValues]:[];return l.push(...Mse(n)),l.length>0&&(o.basicPropertyValues=l),Object.keys(o).length>0&&(i.meta=o),tr(i,this.nonfinite).slice(0,-1)}graphTail(){const e={};for(const[i,r]of Object.entries(this.kept.graph))i!=="id"&&i!=="lbl"&&i!=="meta"&&i!=="nodes"&&i!=="edges"&&(e[i]=r);const n=tr(e,this.nonfinite);return n==="{}"?"}":`,${n.slice(1)}`}propertyNodes(){const e=new Set(this.rows.map(i=>this.iris[i])),n=[];for(const[i,r]of Object.entries(this.kept.properties)){if(e.has(i))continue;const s={id:i,lbl:r.lbl,type:"PROPERTY"};s.propertyType=r.propertyType,s.meta=r.meta,n.push(tr(s,this.nonfinite))}return n}*write(){if(this.fatal!==null)throw this.fatal;const{indent:e}=this;yield`{"graphs":[${this.graphHead()},"nodes":[`;let n=!0;const i=s=>{const o=`${n?"":","}${e}${s}`;return n=!1,o};for(const s of this.rows)yield i(this.nodeRecord(s));for(const s of this.propertyNodes())yield i(s);yield'],"edges":[',n=!0;for(const s of this.written)yield i(this.edgeRecord(s));for(const s of this.kept.propertyEdges)yield i(tr(s,this.nonfinite));yield`]${this.graphTail()}]`;const r=tr(this.kept.document,this.nonfinite);yield r==="{}"?`}
|
|
182
|
+
`:`,${r.slice(1)}
|
|
183
|
+
`}}function Uk(t,e){const n=new jse(t,e);return{notes:n.notes,write:()=>n.write()}}function Fse(t,e,n,i){const r=Ki[t];if(!AD(r.dtype,e)||e.meta.components>1)return!1;const s=o=>{switch(t){case"type":return typeof o=="string"&&!Object.hasOwn(I0,o);case"propertyType":case"def":case"comment":case"namespace":case"created_by":case"creation_date":return typeof o=="string";case"is_obsolete":return typeof o=="boolean";case"def.xrefs":return td(o,!0);case"xref":case"alt_id":return td(o);case"subset":case"replaced_by":case"consider":return td(o)&&o.every(i);case"synonym":return Array.isArray(o)&&o.length>0&&o.every(l=>I(l)&&Object.keys(l).length===("meta"in l?5:4)&&(l.text===null||typeof l.text=="string")&&(l.scope===null||typeof l.scope=="string"&&xa.has(l.scope))&&(l.type===null||i(l.type))&&td(l.xrefs,!0));case"property_value":return Array.isArray(o)&&o.length>0&&o.every(l=>I(l)&&Object.keys(l).length===3&&i(l.relation)&&!hc.has(String(l.relation))&&typeof l.value=="string"&&(l.datatype===null||typeof l.datatype=="string"));case"obo.unrecognized":return I(o)&&Object.keys(o).every(l=>l.startsWith("meta.")?!Lk.has(l.slice(5))&&l.length>5:!Rk.has(l));default:return!1}};return n.every(o=>!e.isSet(o)||s(Ne(e,o)))}const Er=Object.freeze({NONFINITE_AS_NULL:fy,DIRECTION_DROPPED:Gp,MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,NUMERIC_IDS_STRINGIFIED:"W_NUMERIC_IDS_STRINGIFIED",ID_TEXT_COLLISION:w.ID_TEXT_COLLISION,NODE_ORDER:Qu,RESERVED_KEY:"W_RESERVED_KEY",WEIGHT_KEY_CLASH:w.WEIGHT_KEY_CLASH,POSITIONS_DROPPED:w.POSITIONS,POSITION_Z_DROPPED:"W_POSITION_Z_DROPPED",PARENTS_DROPPED:w.PARENTS,EDGE_IDS_DROPPED:w.EDGE_IDS_DROPPED,INTEGRAL_F64_AS_I32:w.INTEGRAL_F64,ROLE_DROPPED:w.ROLE,EMPTY_COLUMN_DROPPED:w.EMPTY_COLUMN,OBOGRAPHS_EDGE_COLUMN_AS_META:cr.EDGE_COLUMN_AS_META,OBOGRAPHS_ID_CHANGED:cr.ID_CHANGED,OBOGRAPHS_DATATYPE_DROPPED:cr.DATATYPE_DROPPED,OBOGRAPHS_TYPE_GAINED:cr.TYPE_GAINED,COLUMN_AS_PROPERTY_VALUE:ed.COLUMN_AS_PROPERTY_VALUE,RELATION_ASSUMED:ed.RELATION_ASSUMED,TYPEDEF_NODES:ed.TYPEDEF_NODES,GRAPH_COLUMN_AS_METADATA:ed.GRAPH_COLUMN_AS_METADATA,ID_TEXT_TYPE:w.ID_TEXT_TYPE,ROLE_ASSUMED:w.ROLE_ASSUMED,COLUMN_NAME_CHANGED:w.COLUMN_NAME_CHANGED,DTYPE_UNSUPPORTED:w.DTYPE,STYLE_KEY_REPLACED:wk}),zse=Object.freeze({"node-link":new Set,d3:new Set,jgf:new Set(["label","kind"]),cytoscape:new Set(["classes"]),graphology:new Set,vis:new Set,obographs:new Set(["label","kind"])}),Wse=new Set(["directed","pair","mutual","weight","timeText","originalId"]),Bse=new Set(["start","end","timestamp","timestamps","spells","open","spellsOpen"]),Hse=new Set(["jgf","cytoscape","graphology"]);function Vse(t,e){const n=e??{},i=ft(e),r=Nte(t.meta);let s;if(n.dialect===void 0||sT("json",n.dialect))s=r.dialect??"node-link";else if(sk(n.dialect))({dialect:s}=n);else throw Im("dialect",n.dialect,g0);const o=uT(n.indent,""),l=r.dialect===s,a=(y,b)=>l&&y!==void 0?y:b,c=So("edgesKey",n.edgesKey)??a(r.edgesKey,s==="d3"?"links":"edges");let d;n.nodeIdKey!==void 0?d=So("nodeIdKey",n.nodeIdKey):l&&r.nodeIdKey!==void 0?{nodeIdKey:d}=r:d="id";let u=n.indexLinks??a(r.indexLinks,!1);if(typeof u!="boolean")throw Im("indexLinks",u,["true","false"]);d===null&&(u=!0);const f=So("sourceKey",n.sourceKey)??a(r.sourceKey,s==="vis"?"from":"source"),h=So("targetKey",n.targetKey)??a(r.targetKey,s==="vis"?"to":"target"),{weightOrigin:p}=t.meta,g=So("weightKey",n.weightKey)??(p!==null&&p.format==="json"&&p.id!==null?p.id:"weight"),m=So("ontologyIri",n.ontologyIri);return{common:i,dialect:s,indent:o,edgesKey:c,nodeIdKey:d,indexLinks:u,sourceKey:f,targetKey:h,weightKey:g,shape:r,ontologyIri:m}}function So(t,e){if(e===void 0)return null;if(typeof e!="string"||e.length===0)throw Im(t,e,["a non-empty key"]);return e}function Im(t,e,n){const i=typeof e=="string"?JSON.stringify(e):String(e);return new N("E_UNSUPPORTED",`option ${t}: ${i} is not one of ${n.join(", ")}`,{option:t,found:typeof e=="string"||typeof e=="number"?e:typeof e,supported:[...n]})}function $m(t,e,n){return Number.isFinite(t)?eh(e?ct(t):Fe(t)):(n.count++,"null")}function dr(t,e,n){switch(typeof t){case"number":return $m(t,e,n);case"boolean":return t?"true":"false";case"string":return JSON.stringify(t);case"undefined":return"null"}if(t===null)return"null";if(Array.isArray(t)||ArrayBuffer.isView(t))return`[${Array.from(t,s=>dr(s,e,n)).join(",")}]`;const i=JSON.stringify(t);return i===void 0?"null":i}function $0(t,e,n,i){switch(t.dtype){case"list":return dr(t.sliceOf(e),t.child.dtype==="f32",i);case"json":return dr(t.values[e],!1,i);case"u32":if(t.meta.refersTo==="node"&&t.meta.components===1){const r=t.data[e];return r===A?"null":Cn(n.idOf(r))}return dr(t.value(e),!1,i);case"f32":return dr(t.value(e),!0,i);default:return dr(t.value(e),!1,i)}}function Yse(t){let e;switch(t.dtype){case"f32":case"f64":({data:e}=t);break;case"list":if(t.child.dtype!=="f32"&&t.child.dtype!=="f64")return 0;({data:e}=t.child);break;default:return 0}let n=0;for(let i=0;i<e.length;i++)Number.isFinite(e[i])||n++;return n}class yc{constructor(e){this.parts=[],this.depth=0,this.firstAtDepth=[],this.indent=e}open(e){this.parts.push(e),this.depth++,this.firstAtDepth.push(!0)}close(e){const n=this.firstAtDepth.pop()??!0;this.depth--,n||this.parts.push(this.newline()),this.parts.push(e)}key(e){this.separator(),this.parts.push(JSON.stringify(e),this.indent!==""?": ":":")}item(){this.separator()}raw(e){this.parts.push(e)}member(e,n){this.key(e),this.parts.push(n)}take(){const e=this.parts.length===1?this.parts[0]:this.parts.join("");return this.parts=[],e}separator(){const e=this.firstAtDepth.length-1;this.firstAtDepth[e]?this.firstAtDepth[e]=!1:this.parts.push(","),this.parts.push(this.newline())}newline(){return this.indent!==""?`
|
|
184
|
+
${this.indent.repeat(this.depth)}`:""}}function Gk(t,e){const{dialect:n}=e,i=Qf(n),r=Un(t,i,e.common,{roles:zse[n],positionDtype:"f64",vizAsAttributes:!0}).filter(g=>g.code!==w.POSITIONS&&g.code!==w.EDGE_IDS_DROPPED),s=(g,m,y=null,b=null)=>{r.push(Object.freeze({code:g,message:m,column:y,count:b}))},o={snapshot:t,resolved:e,dialect:n,caps:i,notes:r,note:s,reserved:Xse(t,e),nonfinite:{count:0}},l=Ip(o,t.nodes,"node"),a=Ip(o,t.edges,"edge"),c=i.graphAttributes?Ip(o,t.graph,"graph"):[];Kse(r,[...l,...a]);const d=Zse(o,a);o.nonfinite.count>0&&s(Er.NONFINITE_AS_NULL,`${o.nonfinite.count} non-finite number${O(o.nonfinite.count)} ${C(o.nonfinite.count,"is","are")} written as null`,null,o.nonfinite.count);const{folding:u,directed:f}=Qse(o),h=t.flags.multigraph||t.meta.declaredMultigraph===!0;n==="jgf"&&toe(t,s);const p=t.edges.byRole("id");return n==="cytoscape"&&p!==null&&p.nullCount>0&&s(w.EDGE_IDS_GENERATED,`${p.nullCount} edge${O(p.nullCount)} ${C(p.nullCount,"has","have")} no id; canonical e<index> ids are generated for them`,p.meta.name,p.nullCount),{resolved:e,notes:r,nodes:l,edges:a,graph:c,edgeIds:p,weights:d,folding:u,directed:f,multigraph:h}}function Kse(t,e){for(const n of e){if(n.slot!=="classes")continue;const i=t.findIndex(r=>r.code===w.LIST&&r.column===n.column.meta.name);i>=0&&t.splice(i,1)}}function Xse(t,e){const{dialect:n}=e,i=new Set,r=new Set(t.flags.weighted?[e.weightKey]:[]),s=new Set;switch(n){case"node-link":case"d3":e.nodeIdKey!==null&&i.add(e.nodeIdKey),r.add(e.sourceKey).add(e.targetKey);break;case"vis":i.add(e.nodeIdKey??"id"),r.add(e.sourceKey).add(e.targetKey).add("source").add("target");break;case"cytoscape":i.add("id").add("parent"),r.add("id").add("source").add("target");break;case"jgf":case"graphology":break;default:{const o=n;throw new N("E_UNSUPPORTED",`unknown dialect ${o}`,{option:"dialect",found:o})}}return{node:i,edge:r,graph:s}}function Ip(t,e,n){const{dialect:i,note:r}=t,s=[],o=t.reserved[n],l=new Set;for(const a of e){const{meta:c}=a,{role:d}=c,u=a.length-a.nullCount;if(d!==null&&(Wse.has(d)||Bse.has(d)))continue;n!=="graph"&&(t.nonfinite.count+=Yse(a));const f=qse(t,a,n);if(f!==null){f!==Cm&&s.push(f);continue}let h=c.name,p="attribute";if(Hse.has(i)&&n!=="graph"&&(h.endsWith(Lt.element)?(h=h.slice(0,-Lt.element.length),p="element"):i==="cytoscape"&&lk.has(h)?p="element":h.endsWith(Lt.data)&&(h=h.slice(0,-Lt.data.length))),p==="attribute"&&o.has(h)){r(Er.RESERVED_KEY,`${n} column "${c.name}" cannot be written: "${h}" is a reserved key of ${i}`,c.name,u);continue}const g=`${p}:${h}`;if(l.has(g)){r(Er.RESERVED_KEY,`${n} column "${c.name}" cannot be written: key "${h}" is already used by another column`,c.name,u);continue}l.add(g),u===0&&n!=="graph"&&r(w.EMPTY_COLUMN,`${n} column "${c.name}" has no set cell and is not written: JSON writes values, never declarations`,c.name,0),Jse(t,a,n,u),s.push({column:a,key:h,slot:p})}return s}const Cm=Symbol("skipped");function qse(t,e,n){const{dialect:i,note:r}=t,{meta:s}=e,{role:o}=s,l=e.length-e.nullCount;if(o==="parent"||o==="parents"){if(i==="cytoscape"&&n==="node"){if(o==="parent"&&e.dtype==="u32"&&s.refersTo==="node")return{column:e,key:"parent",slot:"parent"};r(w.PARENTS,`node column "${s.name}" (${o}) cannot be written: Cytoscape has a single parent`,s.name,l)}return Cm}if(o==="position"&&n==="node"){if(i==="cytoscape"&&(e.dtype==="f32"||e.dtype==="f64")&&s.components>=2){const a=eoe(e);return a>0&&r(Er.POSITION_Z_DROPPED,`${a} position${O(a)} ${C(a,"has","have")} a non-zero z; Cytoscape positions are 2D`,s.name,a),{column:e,key:"position",slot:"cytoscapePosition"}}return r(w.POSITIONS,`node column "${s.name}" (position) is written as a plain array attribute; its role is lost on re-import`,s.name,l),{column:e,key:s.name,slot:"position"}}return o==="id"&&n==="edge"?i==="node-link"||i==="d3"?(r(w.EDGE_IDS_DROPPED,`edge column "${s.name}" (id) is written as a plain attribute; ${i} has no edge id`,s.name,l),null):Cm:i==="cytoscape"&&o==="classes"&&e.dtype==="list"&&e.child.dtype==="string"?{column:e,key:"classes",slot:"classes"}:i==="jgf"&&o==="label"&&(e.dtype==="string"||e.dtype==="dict")?{column:e,key:"label",slot:"label"}:i==="jgf"&&o==="kind"&&n==="edge"&&(e.dtype==="string"||e.dtype==="dict")?{column:e,key:"relation",slot:"relation"}:null}function Jse(t,e,n,i){if(e.dtype!=="f64"||e.meta.components>1||i===0)return;const{data:r}=e;let s=0;for(let o=0;o<e.length;o++)if(e.isSet(o)&&Number.isFinite(r[o])){if(!Number.isInteger(r[o]))return;s++}s!==0&&t.note(w.INTEGRAL_F64,`${n} column "${e.meta.name}" is f64 with integral values only; JSON declares no types and it reads back as i32`,e.meta.name,i)}function Zse(t,e){const{snapshot:n,nonfinite:i}=t,r=Ot(n);if(!r.weighted){const s=e.find(o=>o.slot==="attribute"&&o.key===t.resolved.weightKey);return s!==void 0&&t.note(w.WEIGHT_KEY_CLASH,`edge column "${s.column.meta.name}" is written under "${s.key}", the key the importer reads edge weights from; it reads back as the weight, not as a column`,s.column.meta.name,s.column.length-s.column.nullCount),()=>null}for(let s=0;s<n.edgeCount;s++)r.isExplicit(s)&&!Number.isFinite(r.value(s))&&i.count++;return s=>{if(!r.isExplicit(s))return null;const o=Number.isFinite(r.value(s))?r.text(s):"null";return o===null?null:eh(o)}}function Qse(t){const{snapshot:e,dialect:n,caps:i,note:r}=t,s=Gt(e);s.mutualCount>0&&r(w.MUTUAL_EXPANDED,`${s.mutualCount} mutual pair${O(s.mutualCount)} ${C(s.mutualCount,"is","are")} written as two directed edges; the mutual mark is lost`,null,s.mutualCount);let{directed:o}=e;if(!i.mixedDirection&&yl(e)>0&&t.resolved.common.onMixedDirection==="undirected"&&(o=!1),n==="cytoscape"||n==="vis"||n==="d3"){const l=ok[n];o!==l&&r(Er.DIRECTION_DROPPED,`${n} has no direction flag; the ${o?"directed":"undirected"} graph re-imports as ${l?"directed":"undirected"} unless defaultDirected is passed`)}return{folding:s,directed:o}}function eoe(t){if(t.dtype!=="f32"&&t.dtype!=="f64"||t.meta.components<3)return 0;const{components:e}=t.meta;let n=0;for(let i=0;i<t.length;i++)t.isSet(i)&&t.data[i*e+2]!==0&&n++;return n}function toe(t,e){const{ids:n}=t,i=new Set;let r=0,s=0,o=0,l=-1,a=!0,c=!1;for(let d=0;d<n.size;d++){const u=n.idOf(d),f=String(u);if(typeof u=="number"&&r++,i.has(f)&&s++,i.add(f),noe(f)){o++;const h=Number(f);(c||h<=l)&&(a=!1),l=h}else c=!0}r>0&&e(Er.NUMERIC_IDS_STRINGIFIED,`${r} numeric node id${O(r)} ${C(r,"becomes","become")} JGF object keys (strings); pass ids: "canonical" on re-import`,null,r),s>0&&e(Er.ID_TEXT_COLLISION,`${s} node id${O(s)} ${C(s,"shares","share")} their text with another id; the save fails`,null,s),a||e(Er.NODE_ORDER,`${o} integer-like node id${O(o)} ${C(o,"is","are")} enumerated first and ascending by JSON parsers; node order changes on re-import`,null,o)}function noe(t){return/^(0|[1-9]\d*)$/.test(t)&&Number(t)<4294967295}function*ioe(t,e){const{dialect:n}=e.resolved;if(e.notes.some(i=>i.code===w.MIXED_DIRECTION_ERROR))throw new N("E_DIRECTED",`${n} has no mixed direction; pass onMixedDirection "directed" or "undirected"`,{reason:"mixed direction",dialect:n});if(e.notes.some(i=>i.code===Er.ID_TEXT_COLLISION))throw new N("E_INVALID_ID","two node ids have the same text; JGF keys nodes by text",{reason:"collision"});switch(n){case"node-link":case"d3":yield*ooe(t,e);return;case"vis":yield*loe(t,e);return;case"graphology":yield*aoe(t,e);return;case"jgf":yield*coe(t,e);return;case"cytoscape":yield*doe(t,e);return;default:{const i=n;throw new N("E_UNSUPPORTED",`unknown dialect ${i}`,{option:"dialect",found:i})}}}function Ze(t,e,n,i){for(const r of e){if(!i.has(r.slot)||!r.column.isSet(n))continue;let s;switch(r.slot){case"position":{const o=r.column.value(n),l=roe(r.column),a=Array.from(o).slice(0,l);s=dr(a,r.column.dtype==="f32",t.nonfinite);break}case"classes":s=JSON.stringify(r.column.sliceOf(n).join(" "));break;default:s=$0(r.column,n,t.ids,t.nonfinite);break}t.w.member(r.key,s)}}const mn=new Set(["attribute","position"]),dl=new Set(["element","classes"]);function roe(t){const e=t.meta.extra.sourceDims;return typeof e=="number"&&e>=1&&e<=t.meta.components?e:t.meta.components}function Uu(t,e,n){return t.some(i=>n.has(i.slot)&&i.column.isSet(e))}function Cn(t){return typeof t=="number"?Object.is(t,-0)?"0":eh(String(t)):JSON.stringify(t)}function rh(t,e,n){const i=t.edgeIds;return i?.isSet(e)?$0(i,e,n.ids,n.nonfinite):null}function bc(t,e){const{folding:n}=t;return n.folded(e)?"skip":t.directed?n.sourceDirected(e)?"directed":Qf(t.resolved.dialect).mixedDirection?"undirected":t.resolved.common.onMixedDirection==="directed"?"directed":"undirected":"undirected"}function sh(t,e){t.w.open("{");for(const n of e.graph)n.column.isSet(0)&&t.w.member(n.key,$0(n.column,0,t.ids,t.nonfinite));t.w.close("}")}function soe(t,e,n){const i=t.edgeList(),r=i.src[n],s=i.dst[n];return e.resolved.indexLinks?[String(r),String(s)]:[Cn(t.ids.idOf(r)),Cn(t.ids.idOf(s))]}function*ooe(t,e){const{resolved:n}=e,i={w:new yc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i;r.open("{"),n.dialect!=="d3"&&(r.member("directed",e.directed?"true":"false"),r.member("multigraph",e.multigraph?"true":"false"),r.key("graph"),sh(i,e)),r.key("nodes"),r.open("["),yield r.take();for(let s=0;s<t.nodeCount;s++)r.item(),r.open("{"),n.nodeIdKey!==null&&r.member(n.nodeIdKey,Cn(t.ids.idOf(s))),Ze(i,e.nodes,s,mn),r.close("}"),yield r.take();r.close("]"),r.key(n.edgesKey),r.open("[");for(let s=0;s<t.edgeCount;s++){if(bc(e,s)==="skip")continue;const[l,a]=soe(t,e,s);r.item(),r.open("{"),r.member(n.sourceKey,l),r.member(n.targetKey,a);const c=e.weights(s);c!==null&&r.member(n.weightKey,c),Ze(i,e.edges,s,mn),r.close("}"),yield r.take()}r.close("]"),C0(i,e),r.close("}"),yield r.take()}function C0(t,e){const n=e.resolved.styled?.groups??null;n!==null&&t.w.member("groups",JSON.stringify(n));const i=e.resolved.styled?.topLevelBlock??null;i!==null&&t.w.member(Z,JSON.stringify(i))}function*loe(t,e){const{resolved:n}=e,i={w:new yc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i,s=n.nodeIdKey??"id";r.open("{"),r.key("nodes"),r.open("["),yield r.take();for(let o=0;o<t.nodeCount;o++)r.item(),r.open("{"),r.member(s,Cn(t.ids.idOf(o))),Ze(i,e.nodes,o,mn),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");for(let o=0;o<t.edgeCount;o++){if(bc(e,o)==="skip")continue;const l=t.edgeList();r.item(),r.open("{");const a=rh(e,o,i);a!==null&&r.member("id",a),r.member(n.sourceKey,Cn(t.ids.idOf(l.src[o]))),r.member(n.targetKey,Cn(t.ids.idOf(l.dst[o])));const c=e.weights(o);c!==null&&r.member(n.weightKey,c),Ze(i,e.edges,o,mn),r.close("}"),yield r.take()}r.close("]"),C0(i,e),r.close("}"),yield r.take()}function*aoe(t,e){const{resolved:n}=e,i={w:new yc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i;let s;e.directed?s=yl(t)>0?"mixed":"directed":s="undirected",r.open("{"),r.key("attributes"),sh(i,e),r.key("options"),r.open("{"),r.member("type",JSON.stringify(s)),(t.meta.declaredMultigraph!==null||e.multigraph)&&r.member("multi",e.multigraph?"true":"false"),n.shape.allowSelfLoops!==void 0&&r.member("allowSelfLoops",!n.shape.allowSelfLoops&&t.selfLoopCount===0?"false":"true"),r.close("}"),r.key("nodes"),r.open("["),yield r.take();for(let o=0;o<t.nodeCount;o++)r.item(),r.open("{"),r.member("key",Cn(t.ids.idOf(o))),Uu(e.nodes,o,mn)&&(r.key("attributes"),r.open("{"),Ze(i,e.nodes,o,mn),r.close("}")),Ze(i,e.nodes,o,dl),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");for(let o=0;o<t.edgeCount;o++){const l=bc(e,o);if(l==="skip")continue;const a=t.edgeList();r.item(),r.open("{");const c=rh(e,o,i);c!==null&&r.member("key",c),r.member("source",Cn(t.ids.idOf(a.src[o]))),r.member("target",Cn(t.ids.idOf(a.dst[o]))),s==="mixed"&&l==="undirected"&&r.member("undirected","true");const d=e.weights(o);(d!==null||Uu(e.edges,o,mn))&&(r.key("attributes"),r.open("{"),d!==null&&r.member(n.weightKey,d),Ze(i,e.edges,o,mn),r.close("}")),Ze(i,e.edges,o,dl),r.close("}"),yield r.take()}r.close("]"),r.close("}"),yield r.take()}function*coe(t,e){const{resolved:n}=e,i={w:new yc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i,s=new Set(["label"]),o=new Set(["relation"]);r.open("{"),r.key("graph"),r.open("{"),n.shape.id!==void 0&&r.member("id",JSON.stringify(n.shape.id)),t.meta.name!==null&&r.member("label",JSON.stringify(t.meta.name)),n.shape.type!==void 0&&r.member("type",JSON.stringify(n.shape.type)),r.member("directed",e.directed?"true":"false"),e.graph.some(l=>l.column.isSet(0))&&(r.key("metadata"),sh(i,e)),r.key("nodes"),r.open("{"),yield r.take();for(let l=0;l<t.nodeCount;l++)r.key(String(t.ids.idOf(l))),r.open("{"),Ze(i,e.nodes,l,s),Uu(e.nodes,l,mn)&&(r.key("metadata"),r.open("{"),Ze(i,e.nodes,l,mn),r.close("}")),Ze(i,e.nodes,l,dl),r.close("}"),yield r.take();r.close("}"),r.key("edges"),r.open("[");for(let l=0;l<t.edgeCount;l++){const a=bc(e,l);if(a==="skip")continue;const c=t.edgeList();r.item(),r.open("{");const d=rh(e,l,i);d!==null&&r.member("id",d),r.member("source",JSON.stringify(String(t.ids.idOf(c.src[l])))),r.member("target",JSON.stringify(String(t.ids.idOf(c.dst[l])))),Ze(i,e.edges,l,o),e.directed&&a==="undirected"&&r.member("directed","false"),Ze(i,e.edges,l,s);const u=e.weights(l);(u!==null||Uu(e.edges,l,mn))&&(r.key("metadata"),r.open("{"),u!==null&&r.member(n.weightKey,u),Ze(i,e.edges,l,mn),r.close("}")),Ze(i,e.edges,l,dl),r.close("}"),yield r.take()}r.close("]"),r.close("}"),r.close("}"),yield r.take()}function*doe(t,e){const{resolved:n}=e,i={w:new yc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i,s=new Set(["parent"]);r.open("{"),r.key("elements"),r.open("{"),r.key("nodes"),r.open("["),yield r.take();for(let l=0;l<t.nodeCount;l++)r.item(),r.open("{"),r.key("data"),r.open("{"),r.member("id",Cn(t.ids.idOf(l))),Ze(i,e.nodes,l,s),Ze(i,e.nodes,l,mn),r.close("}"),uoe(i,e,l),Ze(i,e.nodes,l,dl),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");const o=hoe(t,e);for(let l=0;l<t.edgeCount;l++){if(bc(e,l)==="skip")continue;const a=t.edgeList();r.item(),r.open("{"),r.key("data"),r.open("{"),r.member("id",rh(e,l,i)??o(l)),r.member("source",Cn(t.ids.idOf(a.src[l]))),r.member("target",Cn(t.ids.idOf(a.dst[l])));const c=e.weights(l);c!==null&&r.member(n.weightKey,c),Ze(i,e.edges,l,mn),r.close("}"),Ze(i,e.edges,l,dl),r.close("}"),yield r.take()}r.close("]"),r.close("}"),e.graph.some(l=>l.column.isSet(0))&&(r.key("data"),sh(i,e)),foe(i,e),C0(i,e),r.close("}"),yield r.take()}function uoe(t,e,n){const{w:i}=t;for(const r of e.nodes)if(r.slot==="cytoscapePosition"&&r.column.isSet(n)){const s=r.column.value(n),o=r.column.dtype==="f32";i.key("position"),i.open("{"),i.member("x",$m(s[0],o,t.nonfinite)),i.member("y",$m(Bo(s[1]),o,t.nonfinite)),i.close("}")}}function foe(t,e){const{w:n}=t,i=e.resolved.shape.cytoscape??{},r=e.resolved.styled?.stylesheet??null;for(const s of Object.keys(i))s!=="elements"&&s!=="data"&&!(s==="style"&&r!==null)&&n.member(s,dr(i[s],!1,t.nonfinite));r!==null&&n.member("style",dr(r,!1,t.nonfinite))}function hoe(t,e){const n=new Set;for(let r=0;r<t.nodeCount;r++)n.add(String(t.ids.idOf(r)));const i=e.edgeIds;if(i!==null)for(let r=0;r<t.edgeCount;r++)i.isSet(r)&&n.add(String(i.value(r)));return r=>{let s=`e${r}`;for(let o=2;n.has(s);o++)s=`e${r}_${o}`;return n.add(s),JSON.stringify(s)}}function iN(t,e){const n=e.styled?.snapshot??t;return e.dialect==="obographs"?Uk(n,e).write():ioe(n,Gk(n,e))}function $p(t,e){const n=Vse(t,e),i=Tie(t,n.dialect,e?.styles);return i===null?n:{...n,styled:i}}const poe=Object.freeze({format:"json",options:Object.freeze(["dialect","edgesKey","indent","indexLinks","nodeIdKey","ontologyIri","sourceKey","targetKey","weightKey"]),capabilities:Qf("node-link"),styles:Object.freeze({capabilities:Ek}),check(t,e){const n=$p(t,e),i=n.styled?.snapshot??t,r=n.dialect==="obographs"?Uk(i,n).notes:Gk(i,n).notes;return Object.freeze([...r,...n.styled?.notes??[]])},export(t,e){return ti(iN(t,$p(t,e)))},exportToString(t,e){return ni(iN(t,$p(t,e)))}}),goe=new Set(["ID","LABEL","START_ID","END_ID","TYPE","IGNORE"]),moe=new Set(["ID","START_ID","END_ID"]),yoe=/^[^:{}()]*:\s*(ID|START_ID|END_ID)\s*(\(|\{|$)/i,boe=/^([^:(){}]*)(?::([^:(){}]*))?(?:\(([^)]*)\))?(?:\{([^}]*)\})?$/;function jk(t,e,n){let i=!1;for(let r=0;r<e;r++){const s=t[r];if(s.includes(":")&&yoe.test(s.trim())){if(n?.[r]!==!0)return!0;i=!0}}return i&&n!==void 0&&Eoe(t,e,n)}function Eoe(t,e,n){for(let i=0;i<e;i++){if(!n[i])return!1;try{Fk(t[i])}catch{return!1}}return!0}function Fk(t){const e=t.trim(),n=boe.exec(e);if(n===null)throw zi(t,"not a neo4j header cell");const i=n[1].trim(),r=n[2]===void 0?null:n[2].trim(),s=n[3]===void 0?null:n[3].trim(),o=Soe(t,n[4]);if(r===null)return woe(t,i,s,o);if(r.length===0)throw zi(t,"an empty field type");const l=r.toUpperCase();if(goe.has(l))return _oe(t,i,l,s,o);if(i.length===0)throw zi(t,"a property column needs a name");if(s!==null)throw zi(t,"an id space is only allowed on ID, START_ID and END_ID");return{text:t,name:i,kind:"PROPERTY",type:r,space:null,options:o}}function woe(t,e,n,i){if(e.length===0)throw zi(t,"an empty header cell");if(n!==null||i.size>0)throw zi(t,"an id space or options need a field type");return{text:t,name:e,kind:"PROPERTY",type:null,space:null,options:i}}function _oe(t,e,n,i,r){if(i!==null&&!moe.has(n))throw zi(t,`an id space is only allowed on ID, START_ID and END_ID, not ${n}`);if(e.length>0&&n!=="ID"&&n!=="IGNORE")throw zi(t,`a ${n} field cannot be stored as a property`);return{text:t,name:e,kind:n,type:null,space:i===""?null:i,options:r}}function Soe(t,e){const n=new Map;if(e===void 0||e.trim().length===0)return n;for(const i of e.split(",")){const r=i.indexOf(":");if(r<0)throw zi(t,`option "${i.trim()}" is not key:value`);const s=i.slice(0,r).trim().toLowerCase(),o=i.slice(r+1).trim();if(s.length===0)throw zi(t,"an option needs a key");n.set(s,o)}return n}function zi(t,e){return new N("E_UNSUPPORTED",`header cell "${t}": ${e}`,{reason:"header",cell:t,detail:e})}function ps(t,e,n){const i=`${t}:${e}`;return n===null?i:`${i}(${n})`}const zk="labels",Wk="type",Bk="idSpace",Ooe="originalId",vm="E_NEO4J_HEADER",Dm="E_NEO4J_COLUMN_COUNT",Hk=dt,Vk=Zn,Yk=sn,Kk="E_NEO4J_ID_SPACE_COLLISION",Xk="E_NEO4J_ENDPOINT_SPACE",qk=Rn,km="W_NEO4J_HEADER_OPTION_IGNORED",Jk=bn,Zk="W_NEO4J_MISSING_TYPE",Qk="W_NEO4J_SECTION_KIND",eR=Xi,Noe="W_NEO4J_IGNORED_COLUMNS",Aoe=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","errorLimit","signal","onProgress"]),rs="neo4j",Toe=64,Ioe={name:zk,dtype:"list",itemDtype:"dict",nullable:!0,role:"labels",origin:{format:rs,id:":LABEL",title:null,type:"LABEL",namespace:null}},$oe={name:Wk,dtype:"dict",nullable:!0,role:"kind",origin:{format:rs,id:":TYPE",title:null,type:"TYPE",namespace:null}},Coe={name:Bk,dtype:"dict",nullable:!0,role:"idSpace",origin:{format:rs,id:":ID",title:null,type:"ID",namespace:null}},voe={name:Ooe,dtype:"string",nullable:!0,origin:{format:rs,id:":ID",title:null,type:null,namespace:null}},Doe={";":"semicolon",",":"comma","|":"pipe"},koe=Object.freeze([","," "]);function Roe(t){const e=t??{},n=e.arrayDelimiter??";",i=Doe[n];if(typeof n!="string"||i===void 0)throw new N("E_UNSUPPORTED",`option arrayDelimiter: ${JSON.stringify(n)} is not one of ";", ",", "|"`,{option:"arrayDelimiter",found:n});if(n===","&&e.delimiter===void 0)throw new N("E_UNSUPPORTED",'option arrayDelimiter "," needs the delimiter option: the field delimiter is a comma unless another is given',{option:"arrayDelimiter",found:n});const r=Ty({delimiter:e.delimiter??null,quote:e.quote??'"',candidates:koe.filter(s=>s!==n)});if(r.delimiter===n)throw new N("E_UNSUPPORTED",`options delimiter and arrayDelimiter must differ: both are ${JSON.stringify(n)}; pass another arrayDelimiter (";", "," or "|")`,{option:"arrayDelimiter",found:n});return{nodes:rN("nodes",e.nodes),relationships:rN("relationships",e.relationships),syntax:r,listSyntax:i}}function rN(t,e){if(e==null)return[];const n=Array.isArray(e)?e:[e];for(const i of n)if(!jA(i))throw new N("E_UNSUPPORTED",`option ${t}: an entry is not an ImportInput`,{option:t,found:typeof i});return n}class Loe{constructor(){this.codes=new Uint32Array(1024),this.spaces=new Map}codeOf(e){let n=this.spaces.get(e);return n===void 0&&(n=this.spaces.size+1,this.spaces.set(e,n)),n}declare(e,n){if(e>=this.codes.length){let r=this.codes.length*2;for(;r<=e;)r*=2;const s=new Uint32Array(r);s.set(this.codes),this.codes=s}const i=this.codes[e];return i===0?(this.codes[e]=n,"new"):i===n?"duplicate":"collision"}codeAt(e){return e<this.codes.length?this.codes[e]:0}}class Poe{constructor(e,n){this.offset=0,this.lastDone=0,this.callback=e;let i=0;for(const r of n){const s=NP(r);if(s===null){i=void 0;break}i+=s}this.total=i}optionsFor(e){const{callback:n}=this;return n===null?{signal:e}:{signal:e,onProgress:i=>{this.lastDone=i,n(this.offset+i,this.total)}}}finishInput(){this.offset+=this.lastDone,this.lastDone=0}}class xoe{constructor(e,n,i,r){this.registry=new Loe,this.weightProperty=null,this.labelsHandle=A,this.typeHandle=A,this.idSpaceHandle=A,this.originalIdHandle=A,this.ignoredColumns=0,this.headerSet=!1,this.values=[],this.texts=[],this.precisionSlots=[],this.overflows=[],this.expectedKind=null,this.nodeRows=!1,this.placeholders=[],this.sink=e,this.report=n,this.common=i,this.options=r,this.coercer=new Mn(i.ids),this.direction=new ei(e,n,i.onMixedDirection)}async run(e){const n=new Poe(this.common.onProgress,e.map(r=>r.input));let i=null;for(const{input:r,kind:s}of e)this.expectedKind=s,i!==null&&s!==null&&i.kind!==s&&(i=null),i=await this.readInput(r,{...n.optionsFor(this.common.signal),encoding:this.common.encoding},i,e.length>1),n.finishInput();this.ignoredColumns>0&&this.report.loss(Noe,`${this.ignoredColumns} :IGNORE column${O(this.ignoredColumns)} ${C(this.ignoredColumns,"was","were")} skipped as the header instructs`,null,this.ignoredColumns),this.reportDangling()}async readInput(e,n,i,r){const s=new mT(e,this.report,this.options.syntax,{...n,allowEmpty:r});let o=i,l=0,a=0,c=0;for await(const d of s){const{cells:u,quoted:f}=s;if(!(l===0&&d===1&&!f[0]&&u[0].trim().length===0)){if(l++,o===null||jk(u,d,f)){o=this.declareSection(s,d),a=0;continue}a++,o.kind==="node"?this.nodeRow(o,s,d):this.relationshipRow(o,s,d),++c>=Toe&&(c=0,F(n.signal))}}return l===0&&i===null&&!r&&this.report.fail(vm,"the input has no header row",{line:1}),o===i?i:a===0?o:null}declareSection(e,n){const{line:i}=e,r=[];try{for(let f=0;f<n;f++)r.push(Fk(e.cells[f]));const s=new Map;r.forEach((f,h)=>{const p=s.get(f.kind);p===void 0?s.set(f.kind,[h]):p.push(h)});const o=s.get("ID")??[],l=s.get("START_ID")??[],a=s.get("END_ID")??[],c=o.length>0,d=l.length>0||a.length>0;if(c&&d)throw Mr("a header mixes :ID with :START_ID / :END_ID");if(!c&&!d){const f=r.some(h=>h.name==="_id"||h.name==="_start");throw Mr(f?"a header needs an :ID column (nodes) or :START_ID and :END_ID columns (relationships); this is the apoc.export.csv layout (_id, _labels, _start, _end, _type), which is not the neo4j-admin import format":"a header needs an :ID column (nodes) or :START_ID and :END_ID columns (relationships)")}if(this.expectedKind!==null&&this.expectedKind!==(c?"node":"relationship")&&this.report.warning("validation-error",Qk,`a ${c?"node":"relationship"} header in a file given as ${this.expectedKind==="node"?"nodes":"relationships"}; read by its header`,{line:i}),Hoe(r),this.ignoredColumns+=(s.get("IGNORE")??[]).length,c){if(o.length>1)throw Mr("a node header has more than one :ID column");if(s.has("TYPE"))throw Mr("a node header cannot have a :TYPE column");return this.declareNodeSection(r,o[0],s.get("LABEL")??[],i)}if(l.length!==1||a.length!==1)throw Mr("a relationship header needs exactly one :START_ID and one :END_ID column");if(s.has("LABEL"))throw Mr("a relationship header cannot have a :LABEL column");const u=s.get("TYPE")??[];if(u.length>1)throw Mr("a relationship header has more than one :TYPE column");return this.declareRelationshipSection(r,l[0],a[0],u.length===1?u[0]:-1,i)}catch(s){if(s instanceof N&&!(s instanceof it)){const o=[";","|"," ",","].find(a=>a!==e.delimiter&&e.cells.slice(0,n).some(c=>c.includes(a))),l=o===void 0?"":`; if the file is delimited by ${JSON.stringify(o)}, pass the delimiter option`;this.report.fail(vm,`${s.message}${l}`,{line:i},{cause:s.code})}throw s}}declareNodeSection(e,n,i,r){const s=e[n],o=[];for(const c of e)for(const[d,u]of c.options)d==="label"&&c.kind==="ID"?o.push(u):this.report.warning("unsupported",km,`header option ${d}:${u} of "${c.text}" is ignored`,{line:r,element:c.text});(i.length>0||o.length>0)&&this.ensureLabels(),s.space!==null&&this.ensureIdSpace();let l=A;s.name.length>0&&(l=this.declareProperty("node",{...s,type:null},n,{origin:{format:rs,id:s.name,title:null,type:"ID",namespace:s.space}},r).handle);const a=this.declareProperties("node",e,r,null);return{kind:"node",width:e.length,idCell:n,idHandle:l,space:s.space,spaceCode:this.registry.codeOf(s.space),labelCells:i,extraLabels:o,properties:a}}declareRelationshipSection(e,n,i,r,s){for(const u of e)for(const[f,h]of u.options)this.report.warning("unsupported",km,`header option ${f}:${h} of "${u.text}" is ignored`,{line:s,element:u.text});r>=0&&this.ensureType();const{weightFrom:o}=this.common;let l=-1;o!==null&&(l=e.findIndex(u=>u.kind==="PROPERTY"&&u.name===o),l>=0&&o!=="weight"&&(this.weightProperty=o));const a=this.declareProperties("edge",e,s,l),{space:c}=e[n],{space:d}=e[i];return{kind:"relationship",width:e.length,startCell:n,endCell:i,startSpace:c,endSpace:d,startSpaceCode:c===null?0:this.registry.codeOf(c),endSpaceCode:d===null?0:this.registry.codeOf(d),typeCell:r,weightCell:l,properties:a}}declareProperties(e,n,i,r){const s=[];n.forEach((l,a)=>{l.kind!=="PROPERTY"||a===r||s.push(this.declareProperty(e,l,a,{},i))});const o=n.length;return this.values.length<o&&(this.values=new Array(o),this.texts=new Array(o)),s}declareProperty(e,n,i,r,s){const{sink:o,report:l}=this,{listSyntax:a}=this.options,c={format:rs,id:n.name,title:null,type:n.type,namespace:null,listSyntax:a,long:this.common.long};let d=ga(c),u={...d.decl,...r},f;try{f=Lo(o,e,u)}catch(h){if(!(h instanceof N)||h.code!=="E_COLUMN_EXISTS")throw h;d=ga({...c,taken:eu(o,e)}),u={...d.decl,...r,name:d.decl.name},f=Lo(o,e,u)}for(const h of d.issues)l.warning(h.category,h.code,h.message,{line:s,element:n.text});return{cell:i,name:u.name,handle:f,spec:d.spec,companionDecl:d.companion,companion:A}}ensureLabels(){this.labelsHandle===A&&(this.labelsHandle=this.declareReserved("node",Ioe))}ensureType(){this.typeHandle===A&&(this.typeHandle=this.declareReserved("edge",$oe))}ensureIdSpace(){this.idSpaceHandle===A&&(this.idSpaceHandle=this.declareReserved("node",Coe),this.originalIdHandle=this.declareReserved("node",voe))}declareReserved(e,n){const{sink:i,report:r}=this;let s=n;for(;;)try{return Lo(i,e,s)}catch(o){if(!(o instanceof N))throw o;if(o.code==="E_COLUMN_EXISTS"){const l=Xt(s.name,s.origin?.id??null,eu(i,e));r.warning("coercion",ec,`column "${s.name}" renamed to "${l}": the name was taken`,{element:s.name}),s={...s,name:l}}else if(o.code==="E_DUPLICATE_ROLE"){r.warning("coercion",Jk,`column "${s.name}" declared without role "${String(s.role)}": the sink already holds that role`,{element:s.name});const{role:l,...a}=s;s=a}else throw o}}nodeRow(e,n,i){const{sink:r,report:s}=this,{cells:o,quoted:l,line:a}=n;if(i!==e.width){s.error("validation-error",Dm,`row has ${i} cell${O(i)} but the header has ${e.width}`,{line:a}),s.counts.skippedNodes++;return}const c=o[e.idCell];if(c.length===0&&!l[e.idCell]){s.error("missing-value",Hk,"empty :ID cell",{line:a}),s.counts.skippedNodes++;return}const d=this.coerceId(c,a);if(d===null||!this.parseProperties(e.properties,o,l,a,c)){s.counts.skippedNodes++;return}const u=Cp(d,e.space);let f;(e.labelCells.length>0||e.extraLabels.length>0)&&(f=this.labelsOf(e,o,l)),this.nodeRows=!0;const h=r.indexOf(u)!==A;let p;try{p=r.addNode(u)}catch(y){s.recordError(y,{line:a,element:c}),s.counts.skippedNodes++;return}const g=this.registry.declare(p,e.spaceCode);if(g==="collision"){s.error("validation-error",Kk,`node ${c} is declared in id space ${e.space??"(none)"} and in another id space; the core has one id space and this row is skipped`,{line:a,element:c}),s.counts.skippedNodes++;return}g==="duplicate"&&s.warning("merged",Yk,`node ${c} is declared twice; the later properties win`,{line:a,element:c});const m=(y,b)=>{this.guarded(a,c,()=>{r.setNodeValue(y,p,b)})};e.idHandle!==A&&m(e.idHandle,c),e.space!==null&&(m(this.idSpaceHandle,e.space),m(this.originalIdHandle,c)),f!==void 0&&m(this.labelsHandle,f),this.writeProperties("node",e.properties,p,a,c),this.reportPrecision(a,c),h||s.counts.nodes++}guarded(e,n,i){try{i()}catch(r){if(!(r instanceof N)||r instanceof it)throw r;this.report.recordError(r,{line:e,element:n})}}reportDangling(){const e=this.placeholders.filter(i=>this.registry.codeAt(i.index)===0);if(e.length===0||!this.nodeRows)return;const n=e.slice(0,5).map(i=>String(i.id)).join(", ");this.report.warning("validation-error",eR,`${e.length} relationship endpoint${O(e.length)} ${C(e.length,"names","name")} no node row and became nodes: ${n}${e.length>5?", ...":""} (neo4j-admin refuses such relationships)`,{element:String(e[0].id)})}relationshipRow(e,n,i){const{sink:r,report:s}=this,{cells:o,quoted:l,line:a}=n;if(this.headerSet||(this.headerSet=!0,this.direction.setHeader(!0,{line:a})),i!==e.width){s.error("validation-error",Dm,`row has ${i} cell${O(i)} but the header has ${e.width}`,{line:a}),s.counts.skippedEdges++;return}const c=o[e.startCell],d=o[e.endCell],u=c.length===0&&!l[e.startCell];if(u||d.length===0&&!l[e.endCell]){s.error("missing-value",Vk,`empty ${u?":START_ID":":END_ID"} cell`,{line:a}),s.counts.skippedEdges++;return}const f=`${c}->${d}`,h=this.coerceId(c,a),p=h===null?null:this.coerceId(d,a);if(h===null||p===null){s.counts.skippedEdges++;return}const g=Cp(h,e.startSpace),m=Cp(p,e.endSpace);let y=null;if(this.wrongSpace(g,e.startSpaceCode)?y=c:this.wrongSpace(m,e.endSpaceCode)&&(y=d),y!==null){s.error("missing-value",Xk,`endpoint ${y} is not a node of its declared id space (a node of another id space has that id); the row is skipped`,{line:a,element:f}),s.counts.skippedEdges++;return}let b;if(e.weightCell>=0)try{b=Kn(o[e.weightCell],this.report)}catch(T){s.recordError(T,{line:a,element:f}),s.counts.skippedEdges++;return}if(!this.parseProperties(e.properties,o,l,a,f)){s.counts.skippedEdges++;return}const _=[g,m].filter((T,$)=>($===0||T!==g)&&r.indexOf(T)===A);let S;try{S=this.direction.addEdge(g,m,"directed",b,{line:a,element:f})}catch(T){s.recordError(T,{line:a,element:f}),s.counts.skippedEdges++;return}for(const T of _)s.counts.nodes++,this.placeholders.push({id:T,index:r.indexOf(T)});if(e.typeCell>=0){const T=o[e.typeCell];T.length>0?this.guarded(a,f,()=>{r.setEdgeValue(this.typeHandle,S,T)}):s.warning("missing-value",Zk,"empty :TYPE cell; neo4j-admin requires a relationship type, the relationship is kept without one",{line:a,element:f})}this.writeProperties("edge",e.properties,S,a,f),this.reportPrecision(a,f),s.counts.edges++}wrongSpace(e,n){if(n===0)return!1;const i=this.sink.indexOf(e);if(i<0)return!1;const r=this.registry.codeAt(i);return r!==0&&r!==n}coerceId(e,n){const{coercer:i,report:r}=this;let s;try{s=i.text(e)}catch(l){return r.recordError(l,{line:n,element:e}),null}const o=i.lastMerge;return o!==null&&r.warning("coercion",qk,`id "${o.text}" merged with "${o.previousText}" as ${o.id} under ids: "number"`,{line:n,element:e}),s}parseProperties(e,n,i,r,s){const{values:o,texts:l,precisionSlots:a}=this;a.length=0,this.overflows.length=0;for(const c of e){const d=n[c.cell];if(l[c.cell]=null,d.length===0){o[c.cell]=i[c.cell]?Boe(c.spec):void 0;continue}const{spec:u}=c;try{this.parseCell(c,d)}catch(f){return this.report.recordError(f,{line:r,element:`${s} ${c.name}`}),!1}zoe(u,o[c.cell],d)&&this.overflows.push(c.name),u.precision&&Qd(u,d)&&a.push(c)}return!0}parseCell(e,n){const{values:i,texts:r}=this,{spec:s}=e;if(s.temporal!==null&&!s.list){const o=Woe(n,s),l=zp(o,s);i[e.cell]=l.value,r[e.cell]=o===n?l.text:n}else i[e.cell]=ma(n,s,this.options.listSyntax),joe(s,i[e.cell],n)}writeProperties(e,n,i,r,s){const{sink:o,values:l,texts:a}=this;for(const c of n){const d=l[c.cell];if(d===void 0)continue;const u=a[c.cell];this.guarded(r,`${s} ${c.name}`,()=>{u!==null&&c.companion===A&&c.companionDecl!==null&&(c.companion=wy(o,e,c.companionDecl)),e==="node"?(o.setNodeValue(c.handle,i,d),u!==null&&o.setNodeValue(c.companion,i,u)):(o.setEdgeValue(c.handle,i,d),u!==null&&o.setEdgeValue(c.companion,i,u))})}}reportPrecision(e,n){for(const i of this.precisionSlots)this.report.warning("precision",re,`long value of "${i.name}" is beyond 2^53 and was stored as the nearest f64`,{line:e,element:n});this.precisionSlots.length=0;for(const i of this.overflows)this.report.warning("precision",re,`the value of "${i}" is beyond the range of its float / double type and was stored as the nearest representable value`,{line:e,element:n});this.overflows.length=0}labelsOf(e,n,i){let r;for(const s of e.labelCells){const o=n[s];if(!(o.length===0&&!i[s])){r===void 0&&(r=[]);for(const l of pa(o,this.options.listSyntax))l.length>0&&r.push(l)}}return e.extraLabels.length>0&&(r===void 0&&(r=[]),r.push(...e.extraLabels)),r}}function Cp(t,e){return e===null?t:`${e}:${String(t)}`}const Moe={byte:[-128,127],short:[-32768,32767]};function Uoe(t){if(Goe.test(t))return!0;const e=/^[+-]?P([^T]*)(?:T(.*))?$/i.exec(t);return e===null||e[2]===""||e[1]===""&&e[2]===void 0?!1:sN(e[1],"YMWD")&&sN(e[2]??"","HMS")}const Goe=/^[+-]?P\d{4}-?\d{2}-?\d{2}T\d{2}:?\d{2}:?\d{2}(?:\.\d+)?$/i;function sN(t,e){let n=t.toUpperCase(),i=0;for(;n!=="";){const r=/^[-+]?\d+(?:\.\d+)?([A-Z])/.exec(n),s=r===null?-1:e.indexOf(r[1],i);if(r===null||s<0)return!1;i=s+1,n=n.slice(r[0].length)}return!0}function joe(t,e,n){const i=t.declared.trim().toLowerCase().replace(/\[\]$/,""),r=t.list&&Array.isArray(e)?e:[e],s=Moe[i];for(const o of r){let l=!1;if(s!==void 0?l=typeof o=="number"&&(o<s[0]||o>s[1]):i==="char"?l=typeof o=="string"&&o.length!==1:i==="duration"&&(l=typeof o=="string"&&!Uoe(o.trim())),l){const a=s===void 0?"":` (${s[0]} to ${s[1]})`;throw new N("E_COLUMN_TYPE",`"${n}" is not ${RA(i)}${a}`,{value:n,kind:i})}}}const Foe=34028234663852886e22;function zoe(t,e,n){return t.kind!=="float"&&t.kind!=="double"||/inf|nan/i.test(n)?!1:(t.list&&Array.isArray(e)?e:[e]).some(r=>typeof r=="number"&&(!Number.isFinite(r)||t.kind==="float"&&Math.abs(r)>Foe))}function Woe(t,e){const n=t.trim(),i=n.lastIndexOf("[");if(e.temporal!=="dateTime"||i<0||!n.endsWith("]"))return t;const r=n.slice(0,i),s=n.slice(i+1,-1);if(s===""||s.includes("]")||/[\n\r\u2028\u2029]/.test(r))return t;let o;try{o=new Intl.DateTimeFormat("en-US",{timeZone:s,timeZoneName:"longOffset"})}catch{throw new N("E_COLUMN_TYPE",`"${t}" names an unknown time zone ${s}`,{value:t})}if(/(Z|z|[+-]\d{2}(:?\d{2})?)$/.test(r))return r;const l=Ro(r,"localDateTime").value,a=f=>{const h=o.formatToParts(new Date(f)).find(g=>g.type==="timeZoneName")?.value??"GMT",p=/GMT([+-])(\d{2}):(\d{2})/.exec(h);return p===null?0:(p[1]==="-"?-1:1)*(Number(p[2])*60+Number(p[3]))},c=a(l-a(l)*6e4),d=c<0?"-":"+",u=Math.abs(c);return`${r}${d}${String(Math.floor(u/60)).padStart(2,"0")}:${String(u%60).padStart(2,"0")}`}function Boe(t){if(t.list)return[];if(t.kind==="string"||t.kind==="duration")return""}function Hoe(t){const e=new Set;for(const n of t)if(!(n.name.length===0||n.kind==="IGNORE")){if(e.has(n.name))throw Mr(`property "${n.name}" is declared twice`);e.add(n.name)}}function Mr(t){return new N("E_UNSUPPORTED",t,{reason:"header"})}function Voe(t){const e=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!1}).decode(t),n=e.search(/[\r\n]/),r=(n<0?e:e.slice(0,n)).split(/[,;|\t]/);return jk(r,r.length)?.95:0}const Yoe=Object.freeze({format:rs,options:Object.freeze(["arrayDelimiter","delimiter","nodes","quote","relationships"]),extensions:Object.freeze([".csv",".tsv"]),mimeTypes:Object.freeze(["text/csv","text/tab-separated-values"]),sniff:Voe,async import(t,e,n){const i=tt(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=Roe(n),s=new ne(rs,i.errorLimit);_t(e,n,s),St(n,s,Aoe);const o=new xoe(e,s,i,r);return await o.run([{input:t,kind:null},...r.nodes.map(l=>({input:l,kind:"node"})),...r.relationships.map(l=>({input:l,kind:"relationship"}))]),o.weightProperty!==null&&e.setMeta({extra:{neo4j:{weightProperty:o.weightProperty}}}),F(i.signal),s.finish()}}),Rm="W_NEO4J_UNDIRECTED_AS_DIRECTED",tR=cs,Koe=IA,nR="E_NEO4J_WEIGHT_COLUMN_TAKEN",iR="E_NEO4J_ID_COLUMN_TAKEN",rR="W_NEO4J_MULTIPLE_ID_PROPERTIES",Xoe="W_NEO4J_DECLARED_TYPE_CHANGED",qoe="W_NEO4J_ARRAY_DELIMITER",Joe=new Set(["kind","labels","idSpace"]),Ha="neo4j",sR="ID",Zoe="weight",Qoe=Object.freeze({kind:Wk,labels:zk,idSpace:Bk}),Lm=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"any",dtypes:["f32","f64","i32","bool","string"],components:!1,lists:!0,json:!1,defaults:!1,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!1,positions:!1,viz:!1}),ele=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]),tle=new Set([w.MIXED_DIRECTION,w.MIXED_DIRECTION_ERROR,w.MULTI_EDGES,w.SELF_LOOPS,w.EDGE_IDS_GENERATED,w.EDGE_IDS_DROPPED,Rm,nR]),nle=new Set([w.ID_MANGLED,w.ID_CHARSET,w.ID_RENUMBERED,tR,iR,rR]),ile=new Set([";",",","|"]),rle=new Set(["all","nodes","relationships"]);function sle(t,e){const n=t??{},i=n.part??"all";if(!rle.has(i))throw new N("E_UNSUPPORTED",`option part: ${JSON.stringify(i)} is not "all", "nodes" or "relationships"`,{option:"part",found:i});const r=n.arrayDelimiter??";";if(!ile.has(r))throw new N("E_UNSUPPORTED",`option arrayDelimiter: ${JSON.stringify(r)} is not one of ";", ",", "|"`,{option:"arrayDelimiter",found:r});const s=n.delimiter??",",o={...Ty({delimiter:s,quote:n.quote??'"'}),delimiter:s};if(o.delimiter===r)throw new N("E_UNSUPPORTED",`options delimiter and arrayDelimiter must differ: both are ${JSON.stringify(r)}; pass another arrayDelimiter (";", "," or "|")`,{option:"arrayDelimiter",found:r});const l=n.weightColumn===void 0?e??"weight":n.weightColumn;if(l!==null&&(typeof l!="string"||l.length===0))throw new N("E_UNSUPPORTED","option weightColumn: expected a non-empty name or null",{option:"weightColumn",found:l});const a=n.idColumn??null;if(a!==null&&(typeof a!="string"||a.length===0))throw new N("E_UNSUPPORTED","option idColumn: expected a non-empty name or null",{option:"idColumn",found:a});return{part:i,syntax:o,arrayDelimiter:r,weightColumn:l,idColumn:a}}class ole{constructor(e,n,i){this.notes=[],this.ownNotes=[],this.fatalNodes=null,this.fatalEdges=null,this.fatalAll=null,this.nodeColumns=[],this.edgeColumns=[],this.idColumns=[],this.snapshot=e,this.options=n,this.common=i,this.idSpace=e.nodes.byRole("idSpace"),this.originalId=[...e.nodes].find(o=>lle(o.meta))??null,this.labels=e.nodes.byRole("labels"),this.kind=e.edges.byRole("kind");for(const o of e.nodes)oN(o.meta)&&this.idColumns.push(o);const r=Un(e,Lm,i,{roles:Joe,roleNames:Qoe,temporalText:!0,weights:n.weightColumn!==null});this.planColumns("node",e.nodes,this.nodeColumns),this.planColumns("edge",e.edges,this.edgeColumns),this.weights=this.planWeightSource(),this.folding=Gt(e),this.checkIds(),this.checkIdColumn(),this.checkStoredIds(),this.directionNotes();const s=new Set([this.kind,this.labels,this.idSpace].flatMap(o=>o===null?[]:[o.meta.name]));this.addGenericNotes(r,s),this.notes.push(...this.ownNotes),this.filterNotesByPart()}addGenericNotes(e,n){for(const i of e)if(!(i.code===w.JSON&&i.column!==null&&this.writtenAsPoint(i.column))&&!(i.code===w.DTYPE&&i.column!==null&&n.has(i.column))){if(i.code===w.MIXED_DIRECTION_ERROR&&this.fatalEdges===null&&(this.fatalEdges=new N("E_DIRECTED",i.message,{reason:"mixed direction"})),(i.code===w.POSITIONS||i.code===w.VIZ)&&i.column!==null){this.notes.push(Object.freeze({code:i.code,message:`node column "${i.column}" is written as a plain property; its role is lost on re-import`,column:i.column,count:i.count}));continue}this.notes.push(i)}}directionNotes(){const{snapshot:e,folding:n}=this;if(!e.directed)this.note(Rm,`the snapshot is undirected; every edge is written as a directed relationship (${e.edgeCount} edge${O(e.edgeCount)})`,null,e.edgeCount);else if(this.common.onMixedDirection!=="error"){let i=0;for(let r=0;r<e.edgeCount;r++)!n.folded(r)&&!n.sourceDirected(r)&&i++;i>0&&this.note(Rm,`${i} undirected edge${O(i)} ${C(i,"is","are")} written as one directed relationship each (source to target, a pair folded to its primary); Neo4j has no undirected relationship`,null,i)}n.mutualCount>0&&this.note(w.MUTUAL_EXPANDED,`${n.mutualCount} mutual pair${O(n.mutualCount)} ${C(n.mutualCount,"is","are")} written as two directed relationships; the mutual mark is lost`,null,n.mutualCount)}note(e,n,i=null,r=null){this.ownNotes.push(Object.freeze({code:e,message:n,column:i,count:r}))}planColumns(e,n,i){const r=[...n],s=new Set(r.map(a=>a.meta.name)),o=new Map,l=new Set;for(const a of r){const c=a.meta.extra.for;a.dtype==="string"&&typeof c=="string"&&s.has(c)&&(o.set(c,a),l.add(a))}for(const a of r){const{meta:c}=a,{role:d}=c;l.has(a)||d!==null&&ele.has(d)||e==="node"&&(oN(c)||a===this.idSpace||a===this.labels||a===this.originalId)||e==="edge"&&(d==="id"||a===this.kind)||i.push(this.planColumn(a,o.get(c.name)??null))}}planColumn(e,n){const{meta:i}=e,r=i.origin?.type??null,s=r===null?null:yy(Ha,r,"f64"),o=`${i.domain} column "${i.name}"`;if(i.dtype==="list"){const f=i.itemDtype??"string";let p=s!==null&&s.list&&s.itemDtype===f&&s.kind!=="long"?{type:lN(r),kind:aN(s),temporal:s.temporal}:cN(f);s!==null&&s.list&&s.kind==="long"&&f==="f64"&&(p=this.integralOrDouble(e,lN(r),o));const g=i.itemComponents??1;return g>1&&this.note(w.COMPONENTS,`${o} holds items of ${g} components; they are flattened into one array`,i.name,e.length-e.nullCount),this.checkArrayItems(e,p,o),{column:e,header:ps(i.name,`${p.type}[]`,null),scalar:p,list:!0,companion:n}}let l;const a=s!==null&&!s.list&&s.dtype===i.dtype;a&&s.kind==="long"?l=this.integralOrDouble(e,r,o):a?l={type:r,kind:aN(s),temporal:s.temporal}:l=cN(i.dtype);const c=i.role==="position"||i.role!==null&&ale(i.role);if(c&&i.dtype==="json"&&l.kind!=="point"?this.note(w.JSON,`${o} holds nested values; the format has no nested values`,i.name,e.length-e.nullCount):c&&i.dtype!=="json"&&!Lm.dtypes.includes(i.dtype)&&this.note(w.DTYPE,`${o} is ${i.dtype}; the format cannot keep that dtype`,i.name,e.length-e.nullCount),i.components>1)return c&&this.note(w.COMPONENTS,`${o} has ${i.components} components; the format has no strides`,i.name,e.length-e.nullCount),{column:e,header:ps(i.name,`${l.type}[]`,null),scalar:l,list:!0,companion:n};const u=r===null&&i.origin?.format===Ha&&i.dtype==="string"?i.name:ps(i.name,l.type,null);return{column:e,header:u,scalar:l,list:!1,companion:n}}integralOrDouble(e,n,i){return hle(e)?{type:n,kind:"integer",temporal:null}:(this.note(Xoe,`${i} is declared ${n} but holds non-integral values; written as double`,e.meta.name,null),{type:"double",kind:"double",temporal:null})}checkArrayItems(e,n,i){if(e.dtype!=="list"||n.kind!=="string"&&n.kind!=="json"&&n.kind!=="point")return;const{arrayDelimiter:r}=this.options;let s=0;for(let o=0;o<e.length;o++)if(e.isSet(o)){for(const l of e.sliceOf(o))if(id(l,n,null).includes(r)){s++;break}}s>0&&this.note(qoe,`${i}: ${s} row${O(s)} ${C(s,"holds","hold")} an item containing the array delimiter "${r}", which Neo4j cannot escape`,e.meta.name,s)}planWeightSource(){const{snapshot:e}=this,n=this.options.weightColumn;if(n===null)return null;const i=Ot(e),r=this.edgeColumns.find(s=>s.column.meta.name===n);return r!==void 0&&i.weighted?(this.note(nR,`edge column "${n}" already exists; explicit weights cannot be written under weightColumn "${n}"`,n,null),this.fatalEdges===null&&(this.fatalEdges=new N("E_COLUMN_EXISTS",`edge column "${n}" already exists; choose another weightColumn`,{column:n,domain:"edge"}))):r!==void 0&&n===Zoe&&this.note(w.WEIGHT_KEY_CLASH,`edge column "${n}" is written under the property the importer reads edge weights from (weightFrom "${n}"); it reads back as the weight, not as a column`,n,r.column.length-r.column.nullCount),i.weighted?i:null}checkIds(){const{ids:e}=this.snapshot;let n=0,i=0;switch(e.kind){case"identity":case"dense":break;case"numeric":for(let r=0;r<e.size;r++)Number.isSafeInteger(e.idOf(r))||n++;break;case"string":for(let r=0;r<e.size;r++)tu(String(e.idOf(r)))&&n++;break;case"mixed":{const r=new Set;for(let s=0;s<e.size;s++){const o=e.idOf(s),l=String(o);(typeof o=="number"?!Number.isSafeInteger(o):tu(l))&&n++,r.has(l)?i++:r.add(l)}break}default:{const r=e.kind;throw new N("E_UNSUPPORTED",`unknown id map kind ${r}`,{kind:r})}}n>0&&this.note(tR,`${n} node id${O(n)} re-import as another type under the canonical id rule (a string of canonical integer text, or a non-integer number)`,null,n),i>0&&(this.note(Koe,`${i} node id${O(i)} ${C(i,"shares","share")} their text with another id (a number and a string); the save fails`,null,i),this.fatalAll=new N("E_INVALID_ID",`${i} node id${O(i)} ${C(i,"shares","share")} their text with another id; Neo4j ids are text`,{reason:"text collision",count:i}))}checkIdColumn(){const e=this.options.idColumn;e===null||!(this.nodeColumns.some(i=>i.column.meta.name===e)||this.idColumns.some(i=>i.meta.name===e))||(this.note(iR,`node column "${e}" already exists; the :ID column cannot be named idColumn "${e}"`,e,null),this.fatalNodes===null&&(this.fatalNodes=new N("E_COLUMN_EXISTS",`node column "${e}" already exists; choose another idColumn`,{column:e,domain:"node"})))}checkStoredIds(){if(this.idColumns.length<2)return;let e=0;for(let n=0;n<this.snapshot.nodeCount;n++){let i=0;for(const r of this.idColumns)r.isSet(n)&&i++;i>1&&e++}e>0&&this.note(rR,`${e} node${O(e)} ${C(e,"has","have")} more than one stored-id column set; only the first in declaration order is written`,null,e)}writtenAsPoint(e){for(const n of[...this.nodeColumns,...this.edgeColumns])if(n.column.meta.name===e&&n.scalar.kind==="point")return!0;return!1}filterNotesByPart(){const{part:e}=this.options;if(e==="all")return;const{snapshot:n}=this,i=this.notes.filter(r=>e==="nodes"?tle.has(r.code)?!1:r.column===null||!n.edges.has(r.column)||n.nodes.has(r.column):nle.has(r.code)?!1:r.column===null||!n.nodes.has(r.column)||n.edges.has(r.column));this.notes.length=0,this.notes.push(...i)}get fatal(){if(this.fatalAll!==null)return this.fatalAll;const{part:e}=this.options;return e!=="relationships"&&this.fatalNodes!==null?this.fatalNodes:e==="nodes"?null:this.fatalEdges}spaceOf(e){const{idSpace:n}=this;if(!n?.isSet(e))return null;const i=n.value(e);return typeof i=="string"?i:String(i)}idTextOf(e){const{originalId:n}=this;return n!==null&&n.isSet(e)&&this.spaceOf(e)!==null?rd(n,e):dle(this.snapshot.ids.idOf(e))}storedIdOf(e){for(const n of this.idColumns)if(n.isSet(e))return n;return null}*lines(){for(const e of this.rows())yield e.line}*rows(){if(this.fatal!==null)throw this.fatal;const{part:e}=this.options;e!=="relationships"&&(yield*this.nodeLines()),e!=="nodes"&&(yield*this.relationshipLines())}files(){const e=new Map,n=new Set;let i=null;for(const s of this.rows())if(s.file!==null){let o=e.get(s.line);if(o===void 0){let l=`${s.file.name}.csv`,a=2;for(;n.has(l);)l=`${s.file.name}-${a}.csv`,a++;n.add(l),o={name:l,kind:s.file.kind,rows:[]},e.set(s.line,o)}i=o}else i!==null&&i.rows.push(s.line);return[...e].filter(([,s],o)=>s.rows.length>0||o===0&&e.size===1).map(([s,o])=>Object.freeze({name:o.name,kind:o.kind,text:s+o.rows.join("")}))}*nodeLines(){const{snapshot:e}=this;let n=0,i=null,r=null;for(let s=0;s<e.nodeCount;s++){const o=this.spaceOf(s),l=this.storedIdOf(s),a=l===null?this.options.idColumn??"":l.meta.name;(n===0||o!==i||a!==r)&&(n++,i=o,r=a,yield this.nodeHeader(a,o,o??a)),yield{line:this.nodeRow(s),file:null}}n===0&&(yield this.nodeHeader(this.options.idColumn??"",null,null))}nodeHeader(e,n,i){const{delimiter:r}=this.options.syntax,s=[ps(e,sR,n)];this.labels!==null&&s.push(":LABEL");const o=this.nodeColumns.map(l=>l.header).join(r);return o.length>0&&s.push(o),{line:`${s.join(r)}
|
|
185
|
+
`,file:{kind:"nodes",name:dN("nodes",i,null)}}}nodeRow(e){const n=[this.cell(this.idTextOf(e))];this.labels!==null&&n.push(this.cell(this.labelsText(e)));for(const i of this.nodeColumns)n.push(this.cell(this.valueText(i,e)));return`${n.join(this.options.syntax.delimiter)}
|
|
186
|
+
`}*relationshipLines(){const{snapshot:e,folding:n}=this,i=e.edgeList();let r=0,s=null,o=null;for(let l=0;l<e.edgeCount;l++){if(n.folded(l))continue;const a=i.src[l],c=i.dst[l],d=this.spaceOf(a),u=this.spaceOf(c);(r===0||d!==s||u!==o)&&(r++,s=d,o=u,yield this.relationshipHeader(d,u)),yield{line:this.relationshipRow(l,a,c),file:null}}r===0&&(yield this.relationshipHeader(null,null))}relationshipHeader(e,n){const{delimiter:i}=this.options.syntax,r=[ps("","START_ID",e),ps("","END_ID",n)];this.kind!==null&&r.push(":TYPE"),this.weights!==null&&r.push(ps(this.options.weightColumn??"weight","double",null));const s=this.edgeColumns.map(o=>o.header).join(i);return s.length>0&&r.push(s),{line:`${r.join(i)}
|
|
187
|
+
`,file:{kind:"relationships",name:dN("relationships",e,n)}}}relationshipRow(e,n,i){const{kind:r,weights:s}=this,o=[this.cell(this.idTextOf(n)),this.cell(this.idTextOf(i))];r!==null&&o.push(this.cell(r.isSet(e)?rd(r,e):null)),s!==null&&o.push(this.cell(s.text(e)));for(const l of this.edgeColumns)o.push(this.cell(this.valueText(l,e)));return`${o.join(this.options.syntax.delimiter)}
|
|
188
|
+
`}cell(e){if(e===null)return"";const{quote:n}=this.options.syntax;return e.length===0?n+n:hf(e,this.options.syntax.delimiter,n)}labelsText(e){const{labels:n}=this;return n?.isSet(e)?n.dtype==="list"?n.sliceOf(e).map(String).join(this.options.arrayDelimiter):rd(n,e):null}valueText(e,n){const{column:i,scalar:r,companion:s}=e;if(!i.isSet(n))return null;if(e.list)return this.listText(e,n);const o=s?.isSet(n)?rd(s,n):null;return id(i.dtype==="json"?i.values[n]:i.value(n),r,o)}listText(e,n){const{column:i,scalar:r}=e,s=i.dtype==="list"?i.sliceOf(n):i.value(n),o=[];for(const l of Array.from(s))if(Array.isArray(l)||ArrayBuffer.isView(l))for(const a of Array.from(l))o.push(id(a,r,null));else o.push(id(l,r,null));return o.join(this.options.arrayDelimiter)}}function lle(t){return t.role===null&&t.dtype==="string"&&t.origin!==null&&t.origin.format===Ha&&t.origin.id===":ID"&&t.origin.type===null}function oN(t){return t.role===null&&t.dtype==="string"&&t.origin!==null&&t.origin.format===Ha&&t.origin.type===sR}function ale(t){return t==="color"||t==="size"||t==="shape"||t==="thickness"}function lN(t){const e=t.trim();return e.endsWith("[]")?e.slice(0,-2):e}function aN(t){switch(t.kind){case"boolean":return"boolean";case"integer":case"long":return"integer";case"float":return"float";case"double":return"double";case"string":case"duration":return"string";case"temporal":return"temporal";case"point":return"point";case"json":return"json";default:{const e=t.kind;throw new N("E_UNSUPPORTED",`unknown value kind ${e}`,{kind:e})}}}function cN(t){switch(t){case"f32":return{type:"float",kind:"float",temporal:null};case"f64":return{type:"double",kind:"double",temporal:null};case"i32":case"u8":return{type:"int",kind:"integer",temporal:null};case"u32":return{type:"long",kind:"integer",temporal:null};case"bool":return{type:"boolean",kind:"boolean",temporal:null};case"dict":case"string":return{type:"string",kind:"string",temporal:null};case"json":return{type:"string",kind:"json",temporal:null};case"list":return{type:"string",kind:"json",temporal:null};default:{const e=t;throw new N("E_UNSUPPORTED",`unknown dtype ${e}`,{dtype:e})}}}function nd(t,e){return typeof t=="number"?e(t):String(t)}function id(t,e,n){switch(e.kind){case"integer":return nd(t,Ge);case"float":return nd(t,ct);case"double":return nd(t,Fe);case"boolean":return t===!0?"true":"false";case"string":return String(t);case"temporal":return n??nd(t,i=>e.temporal===null?String(i):ha(i,e.temporal));case"point":return cle(t);case"json":return JSON.stringify(t)??"";default:{const i=e.kind;throw new N("E_UNSUPPORTED",`unknown cell kind ${i}`,{kind:i})}}}function cle(t){if(typeof t!="object"||t===null||Array.isArray(t))return JSON.stringify(t)??"";const e=[];for(const[n,i]of Object.entries(t))if(typeof i=="number")e.push(`${n}:${Fe(i)}`);else if(typeof i=="string")e.push(`${n}:'${i.replaceAll("'","")}'`);else return JSON.stringify(t)??"";return`{${e.join(", ")}}`}function dle(t){return typeof t=="string"?t:Number.isInteger(t)?Ge(t):String(t)}function rd(t,e){switch(t.dtype){case"string":return t.valueAt(e);case"dict":return String(t.value(e));case"list":return t.sliceOf(e).map(String).join(",");case"json":return JSON.stringify(t.values[e])??"";case"bool":return t.value(e)===!0?"true":"false";default:{const n=t.value(e);return typeof n=="number"?String(n):Array.from(n).join(",")}}}const ule=Object.freeze({format:Ha,options:Object.freeze(["arrayDelimiter","delimiter","idColumn","part","quote","weightColumn"]),capabilities:Lm,check(t,e){return Object.freeze([...vp(t,e).notes])},export(t,e){return ti(vp(t,e).lines())},exportToString(t,e){return ni(vp(t,e).lines())}});function dN(t,e,n){return[t,e??"",n??""].filter(r=>r!=="").join("-").replaceAll(/[^\w.-]/g,"_")}function vp(t,e){return new ole(t,sle(e,fle(t)),ft(e))}function fle(t){const n=t.meta.extra?.neo4j?.weightProperty;return typeof n=="string"&&n!==""?n:null}function hle(t){if(t.dtype==="f64"){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!Number.isInteger(t.data[e]))return!1}else if(t.dtype==="list"&&t.child.dtype==="f64"){const{data:e}=t.child;for(let n=0;n<e.length;n++)if(!Number.isInteger(e[n]))return!1}return!0}Object.freeze({...xn,...Pn,COLUMN_TYPE:sy,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,CSV_UNCLOSED_QUOTE:Oy,CSV_QUOTE:Ny,HEADER:vm,COLUMN_COUNT:Dm,MISSING_ID:Hk,MISSING_ENDPOINT:Vk,DUPLICATE_NODE:Yk,ID_SPACE_COLLISION:Kk,ENDPOINT_SPACE:Xk,ID_MERGED:qk,HEADER_OPTION_IGNORED:km,UNKNOWN_ATTR_TYPE:Zt,PRECISION:re,COLUMN_RENAMED:ln,ROLE_TAKEN:Jk,OPTION_IGNORED:Jt,SINK_OPTION:Ln,MISSING_TYPE:Zk,SECTION_KIND:Qk,DANGLING_REFERENCE:eR});const ple=Object.freeze({n:`
|
|
189
|
+
`,t:" ",W:" "});function $t(t){if(!t.includes("\\"))return t;let e="";for(let n=0;n<t.length;n++){const i=t.charAt(n);if(i!=="\\"){e+=i;continue}if(n++,n<t.length){const r=t.charAt(n);e+=ple[r]??r}}return e}function oR(t,e){let n=0;for(let i=e-1;i>=0&&t.charAt(i)==="\\";i--)n++;return n%2===1}function gle(t){if(!t.includes("\f"))return[t];const e=[];let n=!1,i=0;for(let r=0;r<t.length;r+=t.charAt(r)==="\\"?2:1){const s=t.charAt(r);s==='"'?n=!n:s==="\f"&&!n&&(e.push(t.slice(i,r)),i=r+1)}return e.push(t.slice(i)),e}function mle(t){return t.endsWith("\\")&&!oR(t,t.length-1)}function yle(t){for(let e=0;e<t.length;e++){if(t.charAt(e)==="\\"){e++;continue}if(t.charAt(e)===":")return{tag:$t(t.slice(0,e).trim()),rest:t.slice(e+1).trimStart()}}return null}const uN=String.raw`\"!`,fN=String.raw`\"[]{}`;function Pm(t){let e=!1;const n=[-2,-2,-2];let i=Gu(t,0,uN,n);for(;i>=0;){const r=t.charAt(i),s=i===0||t.charAt(i-1)===" "||t.charAt(i-1)===" ";if(r==='"'&&(e||s))e=!e;else if(r==="!"&&!e&&s)return t.slice(0,i).trimEnd();i=Gu(t,r==="\\"?i+2:i+1,uN,n)}return t.trimEnd()}function Gu(t,e,n,i){let r=-1;for(let s=0;s<n.length;s++)i[s]!==-1&&i[s]<e&&(i[s]=t.indexOf(n.charAt(s),e)),i[s]!==-1&&(r===-1||i[s]<r)&&(r=i[s]);return r}function Bl(t){if(!t.endsWith("}"))return{value:t,qualifiers:null,badBlock:null};const e=ble(t),n=[];let i=t.length,r=null;for(;i>0&&t.charAt(i-1)==="}"&&!oR(t,i-1);){const o=e.get(i-1)??-1,l=o<0?null:wle(t.slice(o+1,i-1));if(l===null){r=t.slice(Math.max(o,0),i);break}for(n.push(l),i=o;i>0&&/\s/.test(t.charAt(i-1));)i--}let s=null;for(let o=n.length-1;o>=0;o--){s??=Object.create(null);for(const[l,a]of Object.entries(n[o]))lR(s,l,a)}return{value:t.slice(0,i),qualifiers:s,badBlock:r}}function ble(t){const e=new Map;let n=!1,i=-1;for(let r=0;r<t.length;r++){const s=t.charAt(r);if(s==="\\"){r++;continue}s==='"'?n=!n:!n&&s==="{"?i=r:!n&&s==="}"&&(e.set(r,i),i=-1)}return e}function Ele(t){let e=!1,n=-1;for(let i=0;i<t.length;i+=t.charAt(i)==="\\"?2:1){const r=t.charAt(i);r!=="\\"&&(r==='"'&&n<0?e=!e:!e&&r==="{"?n=i:!e&&r==="}"&&(n=-1))}return n}function lR(t,e,n){const i=Array.isArray(n)?n:[n];if(!Object.hasOwn(t,e)){t[e]=Array.isArray(n)?[...n]:n;return}const r=t[e];if(Array.isArray(r))for(const s of i)r.push(s);else t[e]=[r,...i]}function wle(t){const e=Object.create(null);let n=0;const i=t.length;let r=!1;for(;n<i;){for(;n<i&&(t.charAt(n)===" "||t.charAt(n)===" "||t.charAt(n)===",");)n++;if(n>=i)break;const s=t.indexOf("=",n);if(s<0)return null;const o=$t(t.slice(n,s).trim());if(o.length===0||o.includes('"'))return null;for(n=s+1;n<i&&(t.charAt(n)===" "||t.charAt(n)===" ");)n++;let l;if(t.charAt(n)==='"'){const a=v0(t,n+1);if(a<0)return null;l=$t(t.slice(n+1,a)),n=a+1}else{let a=n;for(;a<i&&t.charAt(a)!==",";)a+=t.charAt(a)==="\\"?2:1;l=$t(t.slice(n,a).trim()),n=a}lR(e,o,l),r=!0}return r?e:null}function v0(t,e){for(let n=e;n<t.length;n++)if(t.charAt(n)==="\\")n++;else if(t.charAt(n)==='"')return n;return-1}function Hl(t){const e=[],n=t.length;let i=0;for(;i<n;){const r=t.charAt(i);if(r===" "||r===" "){i++;continue}if(r==='"'){const o=v0(t,i+1),l=o<0?n:o;let a=l+1;if(o>=0&&t.charAt(a)==="@")for(;a<n&&t.charAt(a)!==" "&&t.charAt(a)!==" ";)a++;const c=o<0?"":t.slice(l+1,a);e.push({kind:"quoted",text:$t(t.slice(i+1,l))+c,unterminated:o<0}),i=a;continue}if(r==="["){const o=_le(t,i+1),l=o<0?n:o;e.push({kind:"list",text:t.slice(i+1,l),unterminated:o<0}),i=l+1;continue}let s=i;for(;s<n&&t.charAt(s)!==" "&&t.charAt(s)!==" ";)s+=t.charAt(s)==="\\"?2:1;e.push({kind:"word",text:$t(t.slice(i,Math.min(s,n))),unterminated:!1}),i=s}return e}function _le(t,e){let n=!1;for(let i=e;i<t.length;i++){const r=t.charAt(i);if(r==="\\")i++;else if(r==='"')n=!n;else if(r==="]"&&!n)return i}return-1}function aR(t){const{value:e,qualifiers:n}=Bl(t.trim());let i=-1;for(let l=0;l<e.length;l++)if(e.charAt(l)==="\\")l++;else if(e.charAt(l)==='"'){i=l;break}const r=$t((i<0?e:e.slice(0,i)).trim());if(r.length===0)return null;let s=null,o=!1;if(i>=0){const l=v0(e,i+1);o=l<0,s=$t(e.slice(i+1,l<0?e.length:l))}return{id:r,description:s,qualifiers:n,unterminated:o}}function hN(t){const e=[];let n=!1,i=0,r=0;const s=o=>{const l=aR(t.slice(r,o));l!==null&&e.push(l)};for(let o=0;o<t.length;o++){const l=t.charAt(o);l==="\\"?o++:l==='"'?n=!n:!n&&l==="{"?i++:!n&&l==="}"?i=Math.max(0,i-1):!n&&i===0&&l===","&&(s(o),r=o+1)}return s(t.length),e}function Sle(t){let e=!1,n=!1;const i=[-2,-2,-2,-2,-2,-2];let r=Gu(t,0,fN,i);for(;r>=0;){const s=t.charAt(r);if(s==='"')e=!e;else if(!e&&(s==="["||s==="]"))n=s==="[";else if(!e&&!n&&(s==="{"||s==="}"))return!0;r=Gu(t,s==="\\"?r+2:r+1,fN,i)}return!1}const Ole=/\r\n|\r|\f/g;function Nle(t){return t.includes("\r")||t.includes("\f")}function wr(t){return t.replaceAll(Ole,`
|
|
190
|
+
`).replaceAll(/[\\"\n\t]/g,e=>{switch(e){case`
|
|
191
|
+
`:return String.raw`\n`;case" ":return String.raw`\t`;default:return`\\${e}`}})}function uo(t){return wr(t).replaceAll(/[!{}[\],]/g,e=>`\\${e}`)}function fo(t){return t.length>0&&!cR.test(t)}const cR=/[\s!{}\p{Cc}]/u;function en(t){const e=t.replaceAll(/[\\"]/g,n=>`\\${n}`);return e.startsWith("[")?`\\${e}`:e}function oh(t){return t.length>0&&t===t.trim()&&!/[=",{}[\]!\\\n\r\t\f]/.test(t)}function D0(t){return t.length===0?"":` {${t.map(([n,i])=>`${n}="${wr(i)}"`).join(", ")}}`}const V=Object.freeze({...xn,...Pn,EMPTY_INPUT:Ut,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,MISSING_ID:dt,BAD_VALUE:ie,DUPLICATE_NODE:sn,DUPLICATE_ATTRIBUTE:fe,UNKNOWN_ELEMENT:vt,DANGLING_REFERENCE:Xi,SYNTAX:"W_OBO_SYNTAX",NOT_OBO:"E_OBO_NOT_OBO",FORMAT_VERSION:"W_OBO_FORMAT_VERSION",ID_NOT_FIRST:"W_OBO_ID_NOT_FIRST",SYNONYM_SCOPE:"W_OBO_SYNONYM_SCOPE",UNDECLARED:"W_OBO_UNDECLARED",ID_KIND_CLASH:"W_OBO_ID_KIND_CLASH",CARDINALITY:"W_OBO_CARDINALITY",OBSOLETION:"W_OBO_OBSOLETION",DEPRECATED_TAG:"W_OBO_DEPRECATED_TAG",DEPRECATED_SYNTAX:"W_OBO_DEPRECATED_SYNTAX",HEADER_NOT_APPLIED:"W_OBO_HEADER_NOT_APPLIED",OBSOLETE_DROPPED:"W_OBO_OBSOLETE_DROPPED",ID_MERGED:Rn,COLUMN_RENAMED:ec,ROLE_TAKEN:bn,OPTION_IGNORED:Jt,SINK_OPTION:Ln}),Ale=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightDtype","errorLimit","signal","onProgress","encoding","restoreMangledIds"]),Tle="graphty:originalId",Ile={ids:"keep",defaultDirected:!0,weightFrom:null},dR=64,pN=4096,Dp=new Set(["Term","Typedef","Instance"]),$le=/^(import|typeref|id-mapping|default-relationship-id-prefix|owl-axioms|treat-xrefs-as-.*)$/,Cle=new Map([["typeref","import"],["version","data-version"]]),uR=new Map([["exact_synonym",["synonym","EXACT"]],["narrow_synonym",["synonym","NARROW"]],["broad_synonym",["synonym","BROAD"]],["related_synonym",["synonym","RELATED"]],["xref_analog",["xref",null]],["xref_unk",["xref",null]],["xref_unknown",["xref",null]],["use_term",["consider",null]]]),vle=new Set(["is_a","instance_of","disjoint_from","inverse_of","union_of","intersection_of"]),lh=new Set(["name","namespace","comment","created_by","creation_date","domain","range","inverse_of"]),ah=new Set(Object.keys(Ki).filter(t=>Ki[t].dtype==="bool")),Ec=new Set(["alt_id","subset","replaced_by","consider","union_of","equivalent_to","disjoint_from","transitive_over","disjoint_over"]),Dle=new Set(["format-version","data-version","version","date","saved-by","auto-generated-by","default-namespace","ontology","default-relationship-id-prefix"]),kle=/^(GO_)?1\.[024]$/,Rle=new Set([...Ec,"is_a","instance_of","relationship","intersection_of"]),Lle=100;function fR(t){for(const e of t)if(e<" "&&e!==" "&&e!==`
|
|
192
|
+
`&&e!=="\f"&&e!=="\r"||e==="")return!0;return!1}function gN(t){return t.length>0&&!fR(t)&&!/[\s{}"<>[\]()]/.test(t)}function $o(){return Object.create(null)}function sd(t,e,n){Object.hasOwn(t,e)?t[e].push(n):t[e]=[n]}const ju=new Set(["domain","range","inverse_of","transitive_over","disjoint_over","holds_over_chain","equivalent_to_chain","expand_assertion_to","expand_expression_to","is_cyclic","is_reflexive","is_symmetric","is_anti_symmetric","is_asymmetric","is_transitive","is_functional","is_inverse_functional","is_metadata_tag","is_class_level"]);function Ple(t){const e=t?.obsolete??"keep",n=t?.typedefs??"metadata";if(e!=="keep"&&e!=="drop")throw mN("obsolete",e,["keep","drop"]);if(n!=="metadata"&&n!=="nodes")throw mN("typedefs",n,["metadata","nodes"]);return{obsolete:e,typedefs:n}}function mN(t,e,n){return new N("E_UNSUPPORTED",`option ${t}: ${JSON.stringify(e)} is not one of ${n.join(", ")}`,{option:t,found:e,supported:n})}class xle{constructor(e,n,i){this.header=$o(),this.frameSeen=!1,this.tagClauses=0,this.firstBadLine=null,this.version=null,this.defaultNamespace=null,this.subsets=new Set,this.synonymTypes=new Map,this.nodes=new Map,this.typedefs=new Map,this.tallies=new Map,this.frame=null,this.unknownFrames=[],this.framesSinceCheck=0,this.significant=!1,this.report=e,this.signal=n,this.typedefsAsNodes=i}line(e,n){const i=e.trim();if(i.length===0||(this.significant=!0,i.startsWith("!"))||i.startsWith("[")&&this.frameHeader(i,n))return;const r=yle(Pm(i));if(r===null||r.tag.length===0){this.firstBadLine??=n;const o=r===null?"a line without a colon was skipped":"a line without a tag was skipped";this.tally("parse-error",V.SYNTAX,o,"line",n);return}const s={tag:r.tag,value:Pm(r.rest),line:n};this.frame===null?(gN(r.tag)?this.tagClauses++:this.firstBadLine??=n,this.headerClause(s)):this.frame.clauses.push(s)}frameHeader(e,n){const i=e.indexOf("]"),r=(i<0?e.slice(1):e.slice(1,i)).trim(),s=i<0?"":e.slice(i+1).trim(),o=i>=0&&(s.length===0||s.startsWith("!"));if(!o&&!Dp.has(r)&&e.includes(":"))return!1;if(!o){const a=i<0?"a frame header without its closing ] starts the frame":"text after a frame header was ignored";this.tally("parse-error",V.SYNTAX,a,`[${r}]`,n)}const l=Dp.has(r)||o&&/^[A-Za-z]/.test(r)&&gN(r);return l||(this.firstBadLine??=n),this.startFrame(r,n,l),!0}startFrame(e,n,i){this.finishFrame(),this.frameSeen||=i;const r=Dp.has(e)?e:null;r===null&&this.tally("validation-error",V.UNKNOWN_ELEMENT,"frames of an unknown type are not nodes; kept in meta.extra.obo.unknownFrames",`[${e}]`,n),this.frame={kind:r,name:e,line:n,clauses:[]}}headerClause(e){sd(this.header,e.tag,e.value);const{tag:n}=e;Dle.has(n)&&this.header[n].length>1&&this.tally("validation-error",V.DUPLICATE_ATTRIBUTE,"a single-valued header tag given twice; the first is kept",n,e.line);const i=Hl(Bl(e.value).value),r=i.length>0&&i[0].kind==="word"?i[0].text:null;if(n==="format-version")this.version??=$t(e.value).trim();else if(n==="default-namespace")this.defaultNamespace??=r;else if((n==="subsetdef"||n==="synonymtypedef")&&r===null)this.tally("parse-error",V.SYNTAX,"a declaration whose name is not a word declares nothing",n,e.line);else if(n==="subsetdef"&&r!==null)this.subsets.add(r);else if(n==="synonymtypedef"&&r!==null){const o=i.slice(1).find(l=>l.kind==="word"&&xa.has(l.text));this.synonymTypes.set(r,o?.text??null)}const s=Cle.get(n);s!==void 0&&this.tally("coercion",V.DEPRECATED_TAG,`the 1.0 header tag is read as ${s}`,n,e.line),$le.test(n)&&this.tally("unsupported",V.HEADER_NOT_APPLIED,"kept in meta.extra.obo.header, not applied",n,e.line)}finishFrame(){const{frame:e}=this;if(this.frame=null,e===null)return;if(e.kind===null){const a=$o();for(const c of e.clauses)sd(a,c.tag,c.value);this.unknownFrames.push({type:e.name,clauses:a});return}++this.framesSinceCheck>=dR&&(this.framesSinceCheck=0,F(this.signal));const n=e.clauses.findIndex(a=>a.tag==="id"),i=n<0?null:Bl(e.clauses[n].value),r=i===null?"":i.value.trim(),s=$t(r).trim(),o=e.kind!=="Typedef"||this.typedefsAsNodes;if(s.length===0){this.report.error("missing-value",V.MISSING_ID,`a [${e.kind}] frame has no id; it is skipped`,{line:e.line}),o&&this.report.counts.skippedNodes++;return}if(Hl(r).length>1||fR(s)){this.report.error("validation-error",V.BAD_VALUE,`a [${e.kind}] frame's id ${JSON.stringify(s)} holds unescaped whitespace or a control character; the frame is skipped`,{line:e.clauses[n].line,element:s}),o&&this.report.counts.skippedNodes++;return}n>0&&this.tally("validation-error",V.ID_NOT_FIRST,"the id clause is not the frame's first; it is used","id",e.clauses[n].line);const l=this.recordFor(e.kind,s,e.line);this.extraQualifiers(l,"id",s,i?.qualifiers??null);for(let a=0;a<e.clauses.length;a++){const c=e.clauses[a];if(c.tag==="id"){a!==n&&this.tally("validation-error",V.DUPLICATE_ATTRIBUTE,"a frame names a second id; the first is kept","id",c.line);continue}this.applyClause(l,c)}l.kind==="Typedef"&&!Object.hasOwn(l.raw,"id")&&(l.raw.id=[s])}recordFor(e,n,i){const r=e==="Typedef"?this.typedefs:this.nodes,s=r.get(n);if(s!==void 0)return s.kind!==e?this.tally("validation-error",V.ID_KIND_CLASH,`an id names both a ${s.kind} and an ${e}; the ${s.kind} is the node`,n,i):this.tally("merged",V.DUPLICATE_NODE,`[${e}] frames with this id are merged (spec 4.1.1)`,n,i),s;const o={id:n,kind:e,line:i,values:new Map,lists:new Map,edges:[],seen:new Set,raw:$o()};return r.set(n,o),o}clauseParts(e){let{tag:n}=e,i=null;const r=uR.get(n);r!==void 0&&(this.tally("coercion",V.DEPRECATED_TAG,`the 1.0 tag is read as ${r[0]}`,n,e.line),[n,i]=r);let s=Bl(e.value);const o=Rle.has(n)?Ele(s.value):-1;o>=0&&(this.tally("parse-error",V.SYNTAX,"a qualifier block without its closing brace was dropped",n,e.line),s=Bl(s.value.slice(0,o).trimEnd()));const{qualifiers:l}=s;return s.badBlock!==null?this.tally("parse-error",V.SYNTAX,"a closing brace that is not a qualifier block was kept as text",n,e.line):Sle(s.value)&&this.tally("parse-error",V.SYNTAX,"an unescaped brace inside a value was kept as text",n,e.line),{tag:n,scope:i,qualifiers:l,value:s.value}}definition(e,n,i,r,s,o){if(n==="def"&&e.values.has("def")){this.single(e,"def",null,o);return}const l=this.quotedWithXrefs(e,n,i,r,o);n==="def"?(this.single(e,"def",l.text,o,()=>{e.values.set("def.xrefs",l.xrefs)}),this.extraQualifiers(e,n,l.text,s)):this.push(e,n,od({template:l.text,xrefs:l.xrefs},s))}applyClause(e,n){const i=`${n.tag}\0${n.value}`;if(e.seen.has(i))return;e.seen.add(i),e.kind==="Typedef"&&sd(e.raw,n.tag,n.value);const{tag:r,scope:s,qualifiers:o,value:l}=this.clauseParts(n),a={line:n.line,element:e.id};if(ju.has(r)&&e.kind!=="Typedef"){this.unrecognized(e,n);return}if(lh.has(r)){this.text(e,r,l,o,n.line);return}if(ah.has(r)){const d=$t(l).trim();if(d!=="true"&&d!=="false"){this.report.error("validation-error",V.BAD_VALUE,`${r}: ${JSON.stringify(d)} is not true or false; the clause is skipped`,a);return}this.single(e,r,d==="true",n.line),this.extraQualifiers(e,r,d,o);return}const c=Hl(l);if(Ec.has(r)){const d=this.oneWord(c,r,a);d!==null&&(this.push(e,r,d),this.extraQualifiers(e,r,d,o),r==="subset"&&!this.subsets.has(d)&&this.tally("validation-error",V.UNDECLARED,"a subset no subsetdef declares",d,n.line));return}switch(r){case"is_a":case"instance_of":{if(r==="instance_of"&&e.kind!=="Instance"){this.unrecognized(e,n);return}const d=this.oneWord(c,r,a);d!==null&&e.edges.push({relation:r,target:d,qualifiers:o,line:n.line});return}case"relationship":{if(c.length!==2||c.some(d=>d.kind!=="word")){this.report.error("validation-error",V.BAD_VALUE,`relationship needs a relation and a target, found ${JSON.stringify($t(l))}; the clause is skipped`,a);return}e.edges.push({relation:c[0].text,target:c[1].text,qualifiers:o,line:n.line});return}case"intersection_of":{if(c.length<1||c.length>2||c.some(u=>u.kind!=="word")){this.report.error("validation-error",V.BAD_VALUE,`intersection_of needs a class, or a relation and a class, found ${JSON.stringify($t(l))}; the clause is skipped`,a);return}const d=c.length===1?{relation:null,target:c[0].text}:{relation:c[0].text,target:c[1].text};this.push(e,r,od(d,o));return}case"holds_over_chain":case"equivalent_to_chain":{if(c.length!==2||c.some(d=>d.kind!=="word")){this.report.error("validation-error",V.BAD_VALUE,`${r} needs two relations; the clause is skipped`,a);return}this.push(e,r,[c[0].text,c[1].text]),this.extraQualifiers(e,r,`${c[0].text} ${c[1].text}`,o);return}case"def":case"expand_assertion_to":case"expand_expression_to":this.definition(e,r,l,c,o,n.line);return;case"synonym":this.synonym(e,c,s,o,n.line);return;case"xref":{const d=aR(l);if(d===null){this.report.error("validation-error",V.BAD_VALUE,"xref has no id; the clause is skipped",a);return}this.push(e,"xref",d.id),this.describe(e,[d],r,n.line),this.extraQualifiers(e,r,d.id,o??d.qualifiers);return}case"property_value":this.propertyValue(e,c,o,a);return;default:this.unrecognized(e,n)}}text(e,n,i,r,s){Hl(i).some(l=>l.kind==="quoted"&&l.unterminated)&&this.tally("parse-error",V.SYNTAX,"an unterminated quote; the text after it, a comment included, is kept",n,s);const o=$t(i).trim();this.single(e,n,o,s),this.extraQualifiers(e,n,o,r)}oneWord(e,n,i){if(e.length===1&&e[0].kind==="word")return e[0].text;const r=e.map(s=>s.text).join(" ");return this.report.error("validation-error",V.BAD_VALUE,`${n} needs one id, found ${JSON.stringify(r)}; the clause is skipped`,i),null}quotedWithXrefs(e,n,i,r,s){if(r.length===0||r[0].kind!=="quoted")return this.tally("parse-error",V.SYNTAX,"the text is not quoted; the whole value is kept",n,s),{text:$t(i).trim(),xrefs:[]};if(r[0].unterminated)return this.tally("parse-error",V.SYNTAX,"an unterminated quote; the text runs to the end of the line",n,s),{text:r[0].text,xrefs:[]};const o=r[1];if(o?.kind!=="list")return this.tally("parse-error",V.SYNTAX,"the xref list is missing",n,s),{text:r[0].text,xrefs:[]};o.unterminated&&this.tally("parse-error",V.SYNTAX,"an xref list without its closing ]; kept as read",n,s),r.length>2&&this.tally("parse-error",V.SYNTAX,"text after the xref list was ignored",n,s);const l=hN(o.text);return this.describe(e,l,n,s),this.xrefQualifiers(e,n,l),{text:r[0].text,xrefs:l.map(a=>a.id)}}synonym(e,n,i,r,s){if(n.length===0||n[0].kind!=="quoted"){this.report.error("validation-error",V.BAD_VALUE,"a synonym needs its quoted text; the clause is skipped",{line:s,element:e.id});return}n[0].unterminated&&this.tally("parse-error",V.SYNTAX,"an unterminated quote; the text runs to the end of the line","synonym",s);const o=n.slice(1).filter(h=>h.kind==="word").map(h=>h.text),l=n.slice(1).find(h=>h.kind==="list");let a=i,c=null;if(i===null&&(o.length>0&&xa.has(o[0])?([a]=o,c=o[1]??null):o.length>0&&this.synonymTypes.has(o[0])?([c]=o,a="RELATED"):o.length>0?([c]=o,this.tally("validation-error",V.SYNONYM_SCOPE,"a scope that is not EXACT, BROAD, NARROW or RELATED was kept as the type, scope null",o[0],s)):a="RELATED",a==="RELATED"&&(o.length===0||o[0]===c)&&!this.allowsMissingScope()&&this.tally("validation-error",V.SYNONYM_SCOPE,"a synonym without a scope (1.2 only) is read as RELATED","synonym",s)),c!==null){const h=this.synonymTypes.get(c);h===void 0?a!==null&&this.tally("validation-error",V.UNDECLARED,"a synonym type no synonymtypedef declares",c,s):h!==null&&(a=h)}(o.length>2||l===void 0)&&this.tally("parse-error",V.SYNTAX,l===void 0?"a synonym without its xref list":"extra words after the synonym type","synonym",s);const d=l===void 0?-1:n.indexOf(l);n.some((h,p)=>p>0&&(h.kind==="quoted"||h.kind==="list"&&p!==d||d>=0&&p>d))&&this.tally("parse-error",V.SYNTAX,"a second quoted string, a second xref list or text after the list was ignored","synonym",s),l?.unterminated===!0&&this.tally("parse-error",V.SYNTAX,"an xref list without its closing ]; kept as read","synonym",s);const f=l===void 0?[]:hN(l.text);this.describe(e,f,"synonym",s),this.xrefQualifiers(e,"synonym",f),this.push(e,"synonym",od({text:n[0].text,scope:a,type:c,xrefs:f.map(h=>h.id)},r))}allowsMissingScope(){return this.version!==null&&/^(1\.[0-2]|GO_1\.[0-2])\b/.test(this.version)}propertyValue(e,n,i,r){if(n.length<2||n.length>3||n[0].kind!=="word"||n[1].kind==="list"){this.report.error("validation-error",V.BAD_VALUE,"property_value needs a relation and a value; the clause is skipped",r);return}n.some(o=>o.unterminated)&&this.tally("parse-error",V.SYNTAX,"an unterminated quote; the text runs to the end of the line","property_value",r.line);let s=n.length===3?n[2].text:null;n.length===3&&n[2].kind!=="word"&&(this.tally("parse-error",V.SYNTAX,"a datatype that is not a word was ignored","property_value",r.line),s=null),this.push(e,"property_value",od({relation:n[0].text,value:n[1].text,datatype:s},i))}single(e,n,i,r,s){if(e.values.has(n)){this.tally("validation-error",V.DUPLICATE_ATTRIBUTE,"a single-valued tag given twice for one id; the first is kept",n,r);return}e.values.set(n,i),s?.()}push(e,n,i){let r=e.lists.get(n);r===void 0&&(r=[],e.lists.set(n,r)),(typeof i=="object"||!r.includes(i))&&r.push(i)}describe(e,n,i,r){for(const s of n)if(s.unterminated&&this.tally("parse-error",V.SYNTAX,"an xref description whose quote never closes runs to the end",i,r),s.description!==null){let o=e.values.get("xref.descriptions");o===void 0&&(o=$o(),e.values.set("xref.descriptions",o)),Object.hasOwn(o,s.id)||(o[s.id]=s.description)}}xrefQualifiers(e,n,i){for(const r of i)this.extraQualifiers(e,`${n}.xrefs`,r.id,r.qualifiers)}extraQualifiers(e,n,i,r){if(r===null)return;const s=e.values.get("obo.qualifiers")??{};s[n]??=[],s[n].push({value:i,qualifiers:r}),e.values.set("obo.qualifiers",s)}unrecognized(e,n){let i=e.values.get("obo.unrecognized");i===void 0&&(i=$o(),e.values.set("obo.unrecognized",i)),sd(i,n.tag,$t(n.value)),this.tally("validation-error",V.UNKNOWN_ELEMENT,"an unknown tag was kept in obo.unrecognized",n.tag,n.line)}tally(e,n,i,r,s){const o=`${n}\0${r}\0${i}`,l=this.tallies.get(o);l===void 0?this.tallies.set(o,{category:e,code:n,element:r,what:i,line:s,count:1}):l.count++}flushTallies(){const e=new Map,n=new Map;for(const i of this.tallies.values()){const r=(e.get(i.code)??0)+1;if(e.set(i.code,r),r>Lle){const s=n.get(i.code)??[];s.push(i),n.set(i.code,s);continue}this.report.warning(i.category,i.code,`${i.element}: ${i.what} (${i.count} time${O(i.count)}, first at line ${i.line})`,{line:i.line,element:i.element})}for(const[i,r]of n)this.report.warning(r[0].category,i,`${r.length} more element${O(r.length)} with this warning, not listed (first: ${r[0].element}: ${r[0].what}, line ${r[0].line})`,{line:r[0].line});this.tallies.clear()}notObo(){return this.frameSeen||this.tagClauses>0?null:this.firstBadLine}checkHeader(){if(this.version===null){const n=this.frameSeen?"":" and the file has no frames: nothing was read";this.tally("validation-error",V.FORMAT_VERSION,`the header has no format-version (required by 1.2 and 1.4)${n}; read as the 1.0 / 1.2 / 1.4 union`,"format-version",1)}else kle.test(this.version)||this.tally("validation-error",V.FORMAT_VERSION,`format-version ${JSON.stringify(this.version)} is not 1.0, 1.2 or 1.4; read as 1.4`,"format-version",1);const e=this.header.date?.[0];e!==void 0&&/^\d{2}:\d{2}:\d{4}\s+\d{2}:\d{2}$/.test(e.trim())&&yN(e.trim())===null&&this.tally("validation-error",V.SYNTAX,"the header date is not a real calendar date; created is null","date",1)}meta(){const e=n=>{const i=this.header[n];return i===void 0?null:$t(i[0]).trim()};return{name:e("ontology"),sourceFormat:"obo",sourceVersion:this.version,created:yN(e("date")),creator:e("saved-by")}}headerRecord(){return this.header}namespaceDefault(){return this.defaultNamespace}}function od(t,e){return e===null?t:{...t,qualifiers:e}}function yN(t){const e=t===null?null:/^(\d{2}):(\d{2}):(\d{4})\s+(\d{2}):(\d{2})$/.exec(t);if(e===null)return null;const[,n,i,r,s,o]=e,l=new Date(Date.UTC(Number(r),Number(i)-1,Number(n)));return Number(i)<1||Number(i)>12||l.getUTCDate()!==Number(n)||Number(s)>23||Number(o)>59?null:`${r}-${i}-${n}T${s}:${o}`}function Mle(t,e,n,i){const r=[...t.nodes.values()];for(const[h,p]of t.typedefs){const g=t.nodes.get(h);g!==void 0?t.tally("validation-error",V.ID_KIND_CLASH,`an id names both a ${g.kind} and a Typedef; the ${g.kind} is the node`,h,p.line):i.typedefs==="nodes"&&r.push(p)}for(const h of[...t.nodes.values(),...t.typedefs.values()])for(const p of["intersection_of","union_of"])h.lists.get(p)?.length===1&&t.tally("validation-error",V.CARDINALITY,"a single clause (a class expression needs two or more)",p,h.line);const s=new Set,o=new Set;for(const h of r){const p=h.values.get("is_obsolete")===!0;(i.obsolete==="drop"&&p?s:o).add(h.id),p&&h.edges.length>0&&t.tally("validation-error",V.OBSOLETION,"an obsolete term has is_a or relationship clauses; they are kept","is_obsolete",h.edges[0].line),!p&&(h.lists.has("replaced_by")||h.lists.has("consider"))&&t.tally("validation-error",V.OBSOLETION,"replaced_by or consider on a term that is not obsolete; kept","replaced_by",h.line)}const l=new Set(t.typedefs.keys());for(const h of t.typedefs.values())for(const p of h.lists.get("xref")??[])l.add(p);const a=[],c=new Set;let d=0,u=0;const f=[];for(const h of r)for(const p of h.edges){if(s.has(h.id)||s.has(p.target)){u++;continue}if(!vle.has(p.relation)&&!l.has(p.relation)&&t.tally("validation-error",V.UNDECLARED,"a relation no Typedef declares",p.relation,p.line),!o.has(p.target)&&(c.has(p.target)||(c.add(p.target),a.push(p.target)),!n)){d++,e.counts.skippedEdges++;continue}f.push({source:h.id,edge:p})}return t.flushTallies(),Ule(r,a,n,d,e,new Set(t.typedefs.keys())),s.size>0&&e.warning("merged",V.OBSOLETE_DROPPED,`${s.size} obsolete term${O(s.size)} and ${u} edge${O(u)} to or from them were left out (obsolete: "drop")`,{element:[...s][0]}),{nodes:r.filter(h=>o.has(h.id)),placeholders:n?a:[],edges:f}}function Ule(t,e,n,i,r,s){if(e.length===0)return;const o=new Map;for(const d of t)for(const u of d.lists.get("alt_id")??[])o.set(u,d.id);const l=e.slice(0,5).map(d=>{const u=o.get(d);return s.has(d)?`${d} (a Typedef, kept as metadata, not a node)`:u===void 0?d:`${d} (an alt_id of ${u})`}),a=e.length>5?`, ... (${e.length-5} more)`:"",c=n?"each became a placeholder node (graphty.placeholder)":`${i} edge${O(i)} to them ${C(i,"was","were")} dropped (addMissingNodes false)`;r.warning("validation-error",V.DANGLING_REFERENCE,`${e.length} target${O(e.length)} no frame declares: ${l.join(", ")}${a}; ${c}`,{element:e[0]})}class Gle{constructor(e,n,i){this.restored=new Map,this.since=0,this.sink=e,this.report=n,this.coercer=new Mn(i.ids),this.signal=i.signal}id(e){const n=this.coercer.text(this.restored.get(e)??e),i=this.coercer.lastMerge;return i!==null&&this.report.warning("coercion",V.ID_MERGED,`id text ${JSON.stringify(i.text)} merged with ${JSON.stringify(i.previousText)} as ${i.id}`,{element:e}),n}node(e,n){this.tick();try{const i=this.id(e),r=this.sink.indexOf(i)!==A,s=this.sink.addNode(i);return r||this.report.counts.nodes++,s}catch(i){return this.report.recordError(i,{line:n,element:e}),this.report.counts.skippedNodes++,-1}}tick(){++this.since>=dR&&(this.since=0,F(this.signal))}}function jle(t,e,n,i,r){const s=Mle(t,n,i.addMissingNodes,r),o=new Gle(e,n,i);i.restoreMangledIds&&Fle(s.nodes,o.restored);const l=t.namespaceDefault(),a=new Set(["type"]);for(const d of s.nodes)for(const u of[...d.values.keys(),...d.lists.keys()])a.add(u);l!==null&&a.add("namespace");const c=new Map;for(const d of s.nodes.length>0?Object.keys(Ki):[])a.has(d)&&c.set(d,he(e,"node",Pa("node",d),n).handle);e.reserve(s.nodes.length+s.placeholders.length,s.edges.length);for(const d of s.nodes){const u=o.node(d.id,d.line);if(u<0)continue;const f=[["type",d.kind],...d.values,...d.lists];l!==null&&!d.values.has("namespace")&&f.push(["namespace",l]);for(const[h,p]of f){const g=c.get(h);g!==void 0&&e.setNodeValue(g,u,p)}}if(s.placeholders.length>0){const d=he(e,"node",Pa("node",co),n).handle;for(const u of s.placeholders){const f=o.node(u);f>=0&&e.setNodeValue(d,f,!0)}}Wle(s,o,i)}function Fle(t,e){const n=new Set(t.map(i=>i.id));for(const i of t){const r=i.lists.get("property_value"),s=r?.findIndex(l=>l.relation===Tle)??-1;if(r===void 0||s<0)continue;const o=zle(r[s].value);n.has(o)||(n.add(o),e.set(i.id,o),r.splice(s,1),r.length===0&&i.lists.delete("property_value"))}}function zle(t){try{const e=JSON.parse(t);return typeof e=="string"?e:t}catch{return t}}function Wle(t,e,n){const{sink:i,report:r}=e,s=new ei(i,r,n.onMixedDirection);if(s.setHeader(!0),t.edges.length===0)return;const o=he(i,"edge",Pa("edge","relation"),r).handle,l=t.edges.some(a=>a.edge.qualifiers!==null)?he(i,"edge",Pa("edge","qualifiers"),r).handle:null;for(const{source:a,edge:c}of t.edges){e.tick();const d=i.edgeCount;try{const u=s.addEdge(e.id(a),e.id(c.target),"directed",void 0,{line:c.line,element:a});if(r.counts.edges+=i.edgeCount-d,u<0)continue;i.setEdgeValue(o,u,c.relation),l!==null&&c.qualifiers!==null&&i.setEdgeValue(l,u,c.qualifiers)}catch(u){r.recordError(u,{line:c.line,element:a}),r.counts.skippedEdges++}}}async function Ble(t,e){const n=[];let i=0;const r=(s,o)=>{for(const l of gle(s))e.line(l,o)};for await(const s of t){const{line:o}=t;if(n.length>0){const l=s.trimStart();l.length===0||l.startsWith("[")?(e.tally("parse-error",V.SYNTAX,"a line continuation before a frame header or a blank line was ignored","\\",i),r(n.join(""),i),n.length=0):e.tally("coercion",V.DEPRECATED_SYNTAX,"a backslash line continuation was joined (deprecated in 1.4)","\\",i)}if(mle(s)&&Pm(s)===s){n.push(s.slice(0,-1)),i=o;continue}n.length>0?(n.push(s),r(n.join(""),o),n.length=0):r(s,o)}n.length>0&&(e.tally("coercion",V.DEPRECATED_SYNTAX,"a backslash line continuation was joined (deprecated in 1.4)","\\",i),r(n.join(""),i))}function Hle(t){let e=new TextDecoder("utf-8").decode(t.subarray(0,pN));e.charCodeAt(0)===65279&&(e=e.slice(1));const n=e.split(/\r\n|\r|\n|\f/);n.length>1&&t.byteLength>=pN&&n.pop();let i=0;for(const r of n){const s=r.trim();if(!(s.length===0||s.startsWith("!"))){if(/^\[(Term|Typedef|Instance)\]\s*(!.*)?$/.test(s)||i===0&&/^format-version\s*:/.test(s))return .9;if(/^[A-Za-z][A-Za-z0-9_-]*\s*:(\s|$)/.test(s)){i++;continue}return 0}}return i>0?.4:0}const Vle=Object.freeze({format:"obo",options:Object.freeze(["obsolete","typedefs"]),extensions:Object.freeze([".obo"]),mimeTypes:Object.freeze(["text/obo","application/obo"]),sniff(t){return Hle(t)},async import(t,e,n){const i=tt(n,Ile),r=Ple(n),s=new ne("obo",i.errorLimit);_t(e,n,s,!0),St(n,s,Ale);const o=new xle(s,i.signal,r.typedefs==="nodes");await Ble(new jp(t,s,i),o),o.finishFrame(),o.significant||s.fail(V.EMPTY_INPUT,"the input is empty");const l=o.notObo();l!==null&&s.fail(V.NOT_OBO,`the input is not OBO: it has no frame header and no header tag, and line ${l} is not a tag-value line`,{line:l}),F(i.signal),o.checkHeader(),jle(o,e,s,i,r);const a=$o();for(const[d,u]of o.typedefs)a[d]=u.raw;const c={header:o.headerRecord(),typedefs:a};return o.unknownFrames.length>0&&(c.unknownFrames=o.unknownFrames),e.setMeta({...o.meta(),extra:{obo:c}}),F(i.signal),s.finish()}}),Xn=Object.freeze({COLUMN_AS_PROPERTY_VALUE:cy,EDGE_COLUMN_AS_QUALIFIER:"W_OBO_EDGE_COLUMN_AS_QUALIFIER",UNDIRECTED_AS_DIRECTED:"W_OBO_UNDIRECTED_AS_DIRECTED",DUPLICATE_CLAUSE:"W_OBO_DUPLICATE_CLAUSE",RELATION_ASSUMED:dy,RELATION_RENAMED:"W_OBO_RELATION_RENAMED",ONTOLOGY_NAME:"W_OBO_ONTOLOGY_NAME",TYPEDEF_NODES:uy,TYPE_GAINED:"W_OBO_TYPE_GAINED",EDGE_ORDER:"W_OBO_EDGE_ORDER",GRAPH_COLUMN_AS_METADATA:Zu,LINE_END:"W_OBO_LINE_END",NODE_ORDER:Qu,MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,MIXED_DIRECTION:w.MIXED_DIRECTION,MIXED_DIRECTION_ERROR:w.MIXED_DIRECTION_ERROR,EDGE_IDS_DROPPED:w.EDGE_IDS_DROPPED,POSITIONS_DROPPED:w.POSITIONS,HIERARCHY_DROPPED:w.HIERARCHY,TEMPORAL_DROPPED:w.TEMPORAL,VIZ_DROPPED:w.VIZ,ROLE_DROPPED:w.ROLE,ROLE_ASSUMED:Qa,COLUMN_NAME_CHANGED:w.COLUMN_NAME_CHANGED,DTYPE_UNSUPPORTED:w.DTYPE,EMPTY_COLUMN_DROPPED:w.EMPTY_COLUMN,DEFAULT_DROPPED:w.DEFAULT,OPTIONS_DROPPED:w.OPTIONS,EXTENSION_TABLE_DROPPED:w.EXTENSION_TABLE,ID_CHARSET:w.ID_CHARSET,ID_MANGLED:w.ID_MANGLED,ID_TEXT_TYPE:w.ID_TEXT_TYPE,ID_TEXT_COLLISION:w.ID_TEXT_COLLISION}),hR=Je({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"any",dtypes:[],components:!1,lists:!1,json:!1,defaults:!1,options:!1,hierarchy:!1,temporal:"none",graphAttributes:!1,positions:!1,viz:!1}),ch="graphty:originalId",kp="relation",Yle="qualifiers",pR="weight",gR=new Set(["is_a","instance_of","disjoint_from","inverse_of","union_of","intersection_of"]),mR="\0edges",k0="obo.unrecognized",Kle=["is_anonymous","name","namespace","alt_id","def","comment","subset","synonym","xref","builtin","property_value","domain","range","holds_over_chain","is_anti_symmetric","is_cyclic","is_reflexive","is_symmetric","is_asymmetric","is_transitive","is_functional","is_inverse_functional",mR,"intersection_of","union_of","equivalent_to","disjoint_from","inverse_of","transitive_over","equivalent_to_chain","disjoint_over","created_by","creation_date","is_obsolete","replaced_by","consider","expand_assertion_to","expand_expression_to","is_metadata_tag","is_class_level",k0],Xle=["format-version","data-version","version","date","saved-by","auto-generated-by","import","subsetdef","synonymtypedef","idspace","default-relationship-id-prefix","id-mapping","default-namespace","namespace-id-rule","remark","ontology"],qle=new Set(["id","is_a","instance_of","relationship","intersection_of","holds_over_chain","equivalent_to_chain","def","expand_assertion_to","expand_expression_to","synonym","xref","property_value",...lh,...ah,...Ec,...uR.keys()]),Jle=new Set(Object.keys(Ki).filter(t=>t!=="type"&&t!=="name"&&t!=="propertyType")),Zle=Object.freeze({string:"xsd:string",dict:"xsd:string",bool:"xsd:boolean",i32:"xsd:integer",u32:"xsd:integer",u8:"xsd:integer",f32:"xsd:double",f64:"xsd:double"});function Va(t){return t.length>0&&t===t.trim()}function Sn(t,e,n=!0){return Array.isArray(t)&&(!n||t.length>0)&&t.every(e)}function ld(t){return typeof t=="string"&&t.length>0&&Va(t)}function gs(t){return typeof t=="string"&&fo(t)}function Fl(t,e){if(typeof t!="object"||t===null||Array.isArray(t))return!1;const n=Object.keys(t),i=t;return Object.hasOwn(i,"qualifiers")?e0(i.qualifiers,oh)?n.length===e.length+1&&e.every(r=>Object.hasOwn(i,r)):!1:n.length===e.length&&e.every(r=>Object.hasOwn(i,r))}function wc(t){const e=t.replaceAll(new RegExp(cR.source,"gu"),"_");return e.length===0?"_":e}function R0(t){const e=[];for(const[n,i]of Object.entries(t))for(const r of Array.isArray(i)?i:[i])e.push([n,r]);return e}function Qle(t){const e=t?.relation??"is_a";if(typeof e!="string"||!fo(e))throw new N("E_UNSUPPORTED",`option relation: ${JSON.stringify(e)} is not an OBO id`,{option:"relation",found:e});const n=t?.ontology??null;if(n!==null&&(typeof n!="string"||!/^[A-Za-z0-9_.\-/]+$/.test(n)))throw new N("E_UNSUPPORTED",`option ontology: ${JSON.stringify(n)} is not an ontology id (letters, digits, _ . - /)`,{option:"ontology",found:n});return{relation:e,ontology:n}}function eae(t,e,n){const i=t.nodeCount,r=new Array(i),s=[];let o=0;for(let c=0;c<i;c++){const d=t.ids.idOf(c);typeof d=="number"&&o++,r[c]=String(d),fo(r[c])||s.push(c)}o>0&&n(w.ID_TEXT_TYPE,`${o} numeric node id${O(o)} ${C(o,"is","are")} written as text and read back as strings`,null,o);const l=new Map;let a=null;return s.length>0&&e==="error"?a=tae(t,r,s,n):s.length>0&&nae(r,s,l,n),{ids:r,originals:l,fatal:a??iae(t,r,n)}}function tae(t,e,n,i){return i(w.ID_CHARSET,`${n.length} node id${O(n.length)} ${C(n.length,"is","are")} not OBO ids (empty, or holding whitespace, a control character, "!", "{" or "}"); the save fails unless sanitizeIds is "mangle"`,null,n.length),new N("E_INVALID_ID",`${n.length} node id${O(n.length)} cannot be written as OBO ids (first: ${JSON.stringify(e[n[0]])}); pass sanitizeIds: "mangle" to rewrite them`,{reason:"charset",count:n.length,id:t.ids.idOf(n[0]),index:n[0]})}function nae(t,e,n,i){const r=new Set(e),s=new Set(t.filter((o,l)=>!r.has(l)));for(const o of e){const l=wc(t[o]);let a=l,c=2;for(;s.has(a);)a=`${l}_${c}`,c++;s.add(a),n.set(o,t[o]),t[o]=a}i(w.ID_MANGLED,`${e.length} node id${O(e.length)} that ${C(e.length,"is","are")} not OBO ids ${C(e.length,"is","are")} rewritten with "_"; the originals are kept as ${ch} property values (JSON text; an import with restoreMangledIds: true reads them back as the ids)`,null,e.length)}function iae(t,e,n){const i=new Map;for(let r=0;r<e.length;r++){const s=i.get(e[r]);if(s!==void 0)return n(w.ID_TEXT_COLLISION,`node ids ${JSON.stringify(t.ids.idOf(s))} and ${JSON.stringify(t.ids.idOf(r))} have the same text; the save fails`,null,1),new N("E_INVALID_ID","two node ids have the same text; OBO keeps ids as text",{reason:"collision"});i.set(e[r],r)}return null}function rae(t,e,n,i){const{src:r,dst:s}=t.edgeList(),o=[];for(let u=0;u<t.edgeCount;u++)e.folded(u)||o.push(u);const l=new Uint32Array(t.nodeCount+1);for(const u of o)l[r[u]+1]++;for(let u=0;u<t.nodeCount;u++)l[u+1]+=l[u];const a=l.slice(0,t.nodeCount),c=new Uint32Array(o.length);for(const u of o)c[a[r[u]]++]=u;let d=0;for(let u=0;u<c.length;u++)c[u]!==o[u]&&d++;if(d>0&&i(Xn.EDGE_ORDER,`${d} edge${O(d)} ${C(d,"reads","read")} back at another position: edges are written on their source's frame, grouped by source in node order`,null,d),!t.directed)i(Xn.UNDIRECTED_AS_DIRECTED,`the snapshot is undirected; every edge is written from its source to its target and reads back directed (${o.length} edge${O(o.length)})`,null,o.length);else if(n.onMixedDirection!=="error"){const u=o.filter(f=>!e.sourceDirected(f)).length;u>0&&i(Xn.UNDIRECTED_AS_DIRECTED,`${u} undirected edge${O(u)} ${C(u,"is","are")} written as one directed clause each; OBO has no undirected edge`,null,u)}return e.mutualCount>0&&i(w.MUTUAL_EXPANDED,`${e.mutualCount} mutual pair${O(e.mutualCount)} ${C(e.mutualCount,"is","are")} written as two clauses; the mutual mark is lost`,null,e.mutualCount),{written:o,edgeStart:l,edgeOrder:c,dst:s}}function sae(t,e){const n=new Array(t.nodeCount).fill("Term"),i=t.nodes.get("type");if(i===null||i.dtype!=="dict"&&i.dtype!=="string")return{kinds:n,type:null};for(let r=0;r<t.nodeCount;r++){if(e[r]===1){if(i.isSet(r))return{kinds:n.fill("Term"),type:null};continue}const s=Ne(i,r);if(typeof s!="string"||!SJ.has(s))return{kinds:n.fill("Term"),type:null};n[r]=s}return{kinds:n,type:i}}function oae(t,e,n,i,r){const s=Ki[t];if(!AD(s.dtype,e)||e.meta.components>1)return!1;const o=ju.has(t),l=a=>{if(lh.has(t))return typeof a=="string"&&Va(a);if(ah.has(t))return typeof a=="boolean";if(Ec.has(t))return Sn(a,gs);switch(t){case"def":return typeof a=="string";case"def.xrefs":return Sn(a,ld,!1);case"xref":return Sn(a,ld);case"xref.descriptions":return typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.values(a).every(c=>typeof c=="string");case"synonym":return Sn(a,c=>Fl(c,["text","scope","type","xrefs"])&&typeof c.text=="string"&&typeof c.scope=="string"&&xa.has(c.scope)&&(c.type===null||gs(c.type))&&(c.type===null||(r.get(c.type)??c.scope)===c.scope)&&Sn(c.xrefs,ld,!1));case"intersection_of":return Sn(a,c=>Fl(c,["relation","target"])&&(c.relation===null||gs(c.relation))&&gs(c.target));case"property_value":return Sn(a,c=>Fl(c,["relation","value","datatype"])&&gs(c.relation)&&c.relation!==ch&&typeof c.value=="string"&&(c.datatype===null||gs(c.datatype)));case"holds_over_chain":case"equivalent_to_chain":return Sn(a,c=>Sn(c,gs)&&c.length===2);case"expand_assertion_to":case"expand_expression_to":return Sn(a,c=>Fl(c,["template","xrefs"])&&typeof c.template=="string"&&Sn(c.xrefs,ld,!1));case"obo.qualifiers":return typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.values(a).every(c=>Sn(c,d=>Fl(d,["value"])&&Object.hasOwn(d,"qualifiers")&&typeof d.value=="string"&&e0(d.qualifiers,oh)));default:return!1}};for(const a of n)if(e.isSet(a)&&(o&&i[a]!=="Typedef"||!l(Ne(e,a))))return!1;return!0}function lae(t,e,n){if(t.dtype!=="json")return!1;for(const i of e){const r=Ne(t,i);if(r!==void 0){if(typeof r!="object"||r===null||Array.isArray(r))return!1;for(const[s,o]of Object.entries(r))if((qle.has(s)||ju.has(s))&&!(ju.has(s)&&n[i]!=="Typedef")&&!(s==="instance_of"&&n[i]!=="Instance")||s.length===0||!Va(s)||!Sn(o,a=>typeof a=="string"&&Va(a)))return!1}}return!0}function aae(t){const e=new Map;for(const n of t.synonymtypedef??[]){const i=Hl(n);if(i.length>0&&i[0].kind==="word"){const r=i.slice(1).find(s=>s.kind==="word"&&xa.has(s.text));e.set(i[0].text,r?.text??null)}}return e}function cae(t){const e=t.meta.extra.obo,n=typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{},i=o=>{const l={};if(typeof o=="object"&&o!==null&&!Array.isArray(o))for(const[a,c]of Object.entries(o))Array.isArray(c)&&(l[a]=c.filter(d=>typeof d=="string"));return l},r={};if(typeof n.typedefs=="object"&&n.typedefs!==null&&!Array.isArray(n.typedefs))for(const[o,l]of Object.entries(n.typedefs))r[o]=i(l);const s=Array.isArray(n.unknownFrames)?n.unknownFrames.flatMap(o=>typeof o=="object"&&o!==null&&typeof o.type=="string"?[{type:o.type,clauses:i(o.clauses)}]:[]):[];return{header:i(n.header),typedefs:r,unknownFrames:s}}function dae(t,e,n,i){e.length>0&&!t.nodes.has("type")&&i(Xn.TYPE_GAINED,`${e.length} node${O(e.length)} ${C(e.length,"is","are")} written as [Term] frames and ${C(e.length,"reads","read")} back with the type Term in a new node column "type"`,null,e.length);const r=e.filter(s=>n[s]==="Typedef").length;r>0&&i(Xn.TYPEDEF_NODES,`${r} node${O(r)} ${C(r,"is","are")} written as [Typedef] frames; they read back as nodes only when imported with typedefs: "nodes", and then after the other nodes, with the [Typedef] frames that declare the relations`,"type",r)}function yR(t,e){const n=ft(e),i=Qle(e),r=[],s=(ze,yh,LL=null,PL=null)=>{r.push(Object.freeze({code:ze,message:yh,column:LL,count:PL}))};let o=null;const{ids:l,originals:a,fatal:c}=eae(t,n.sanitizeIds,s);o??=c;const d=Gt(t),{written:u,edgeStart:f,edgeOrder:h,dst:p}=rae(t,d,n,s),g=ID(t,u,{outgoingAllowed:!1,changed:ze=>a.has(ze)}),m=$D(g,Array.from(h,ze=>p[ze]));m>0&&s(Qu,`${m} node${O(m)} ${C(m,"reads","read")} back at another position: placeholder nodes have no frame and read back after the written nodes`,null,m);const y=[];for(let ze=0;ze<t.nodeCount;ze++)g[ze]===0&&y.push(ze);const{kinds:b,type:_}=sae(t,g);dae(t,y,b,s);const S=cae(t),T=aae(S.header),$=sa(t.nodes,"label","name"),D=$.column,x=D!==null&&y.every(ze=>!D.isSet(ze)||Va(String(D.value(ze))))?D:null,R=uae(t,y,b,T,x);o??=CD(t,n,{caps:hR,label:x,labelAssumed:$.assumed,edgeSlot:"a qualifier",note:s}),hae(t,x,R,s);const G=pae(t,y,g,x,R,_,s),B=sa(t.edges,"kind",kp),Q=gae(t,u,B.column,i.relation,s);B.assumed&&B.column!==null&&s(Qa,`edge column "${kp}" has no role, so it is taken as the relation of each edge: it is written as each line's relation, and reads back with the relation role ("kind")`,kp,B.column.length-B.column.nullCount);const be=Ot(t),{qualifiers:De,edgeColumns:J}=mae(t,u,B.column,be,s);vD(t,y,g,u,s);const st={notes:r,fatal:o,options:i,ids:l,originals:a,frameless:g,kinds:b,label:x,tags:R,properties:G,edgeStart:f,edgeOrder:h,dst:p,relations:Q,qualifiers:De,edgeColumns:J,weights:be,header:[],tail:[]};let ee=_N(st,y);if(!ee.qualifiersPlaced){R.delete("obo.qualifiers");const ze=t.nodes.get("obo.qualifiers");ze!==null&&(G.push({column:ze,relation:"obo.qualifiers"}),t0(s,ze,y,"property_value lines (relation obo.qualifiers)")),ee=_N(st,y)}ee.duplicates>0&&s(Xn.DUPLICATE_CLAUSE,`${ee.duplicates} clause${O(ee.duplicates)} ${C(ee.duplicates,"repeats","repeat")} another clause of their frame word for word (parallel edges with one relation and the same qualifiers, a repeated list item) and read back as one`,null,ee.duplicates);const Ke=bae(t,S.header,i,y,R,s,ee),us=Sae({kept:S,rows:y,kinds:b,ids:l,properties:G,relations:Q,edges:h,xref:R.get("xref")??null});return ee.lineEnds>0&&s(Xn.LINE_END,`${ee.lineEnds} text${O(ee.lineEnds)} ${C(ee.lineEnds,"holds","hold")} a carriage return or form feed, which OBO cannot carry; written as a line feed`,null,ee.lineEnds),{...st,header:Ke,tail:us}}function uae(t,e,n,i,r){const s=new Map;for(const c of Jle){const d=t.nodes.get(c);d===null||d===r||d.meta.role!==null&&d.meta.role!=="label"||(c===k0?lae(d,e,n):oae(c,d,e,n,i))&&s.set(c,d)}const o=s.get("def"),l=s.get("def.xrefs");l!==void 0&&(o===void 0||e.some(c=>o.isSet(c)!==l.isSet(c)))&&s.delete("def.xrefs"),o!==void 0&&!s.has("def.xrefs")&&t.nodes.get("def.xrefs")!==null&&s.delete("def");const a=s.get("xref.descriptions");return a!==void 0&&!e.every(c=>fae(s,a,c))&&s.delete("xref.descriptions"),s}function fae(t,e,n){const i=Ne(e,n);if(i===void 0)return!0;const r=new Set,s=o=>{if(Array.isArray(o))for(const l of o)typeof l=="string"&&r.add(l)};for(const o of["def.xrefs","xref"]){const l=t.get(o);l!==void 0&&s(Ne(l,n))}for(const o of["synonym","expand_assertion_to","expand_expression_to"]){const l=t.get(o),a=l===void 0?void 0:Ne(l,n);if(Array.isArray(a))for(const c of a)s(c.xrefs)}return Object.keys(i).every(o=>r.has(o))}function hae(t,e,n,i){for(const[r,s]of[...n,...e===null?[]:[["name",e]]]){const o=r==="name"?"string":Ki[r].dtype;if((o==="string"||o==="dict")&&s.dtype!==o||s.dtype==="list"&&s.child.dtype!=="string"){const l=s.dtype==="list"?`${s.child.dtype} items`:s.dtype;i(w.DTYPE,`node column "${s.meta.name}" holds ${l}; it reads back as ${s.dtype==="list"?"string items":o}`,s.meta.name,s.length-s.nullCount)}}for(const r of t.graph)i(Zu,`graph column "${r.meta.name}" is written as a header property_value and reads back in meta.extra.obo.header, not as a column`,r.meta.name,r.length-r.nullCount)}function pae(t,e,n,i,r,s,o){const l=[],a=new Set([...r.values(),...i===null?[]:[i],...s===null?[]:[s]]);for(const c of t.nodes){const{role:d,name:u}=c.meta;if(a.has(c)||d!==null&&Ma.has(d)||u===co&&e.every(h=>!c.isSet(h))&&n.includes(1))continue;const f=fo(u)&&u!==ch?u:wc(u.replaceAll(":","_"));l.push({column:c,relation:f}),t0(o,c,e,`property_value lines (relation ${f})`)}return l}function gae(t,e,n,i,r){const s=new Array(t.edgeCount).fill(i);let o=0,l=0;for(const a of e){const c=n===null?void 0:Ne(n,a);if(typeof c!="string"){o++;continue}fo(c)?s[a]=c:(s[a]=wc(c),l++)}return o>0&&r(Xn.RELATION_ASSUMED,`${o} edge${O(o)} ${C(o,"has","have")} no relation; written as ${i} (an ontology reads is_a as subclassing)`,n?.meta.name??null,o),l>0&&r(Xn.RELATION_RENAMED,`${l} relation${O(l)} ${C(l,"is","are")} not OBO ids; written with "_" in place of the space, "!", "{" or "}"`,n?.meta.name??null,l),s}function mae(t,e,n,i,r){const s=yae(t,e),o=[],l=d=>e.filter(u=>d.isSet(u)).length,a=s===null?"":" (merged with its values)";for(const d of t.edges){const{role:u,name:f}=d.meta;if(d===n||d===s||u==="id"||u!==null&&Ma.has(u))continue;const h=oh(f)?f:wc(f.replaceAll(/[=",[\]\\]/g,"_"));o.push({column:d,name:h});const p=l(d);p>0&&r(Xn.EDGE_COLUMN_AS_QUALIFIER,`edge column "${f}" is written as the qualifier ${h} and reads back inside the qualifiers column${a}`,f,p)}const c=i.weighted?e.filter(d=>i.isExplicit(d)).length:0;return c>0&&r(Xn.EDGE_COLUMN_AS_QUALIFIER,`${c} explicit edge weight${O(c)} ${C(c,"is","are")} written as the qualifier ${pR} and read back inside the qualifiers column, not as weights`,t.edges.byRole("weight")?.meta.name??null,c),{qualifiers:s,edgeColumns:o}}function yae(t,e){const n=t.edges.get(Yle);return n?.dtype!=="json"||n.meta.role!==null?null:e.every(r=>!n.isSet(r)||e0(Ne(n,r),oh))?n:null}function bae(t,e,n,i,r,s,o){const{values:l,filled:a}=Eae(t,e,n.ontology,s),c=r.get("namespace");l.has("default-namespace")&&(c===void 0||i.some(f=>!c.isSet(f)))&&l.delete("default-namespace");const d=[],u=[...Xle.filter(f=>a.has(f)),...[...l.keys()].filter(f=>!a.has(f))];for(const f of u)for(const h of l.get(f)??[])d.push(`${L0(f)}: ${h}`);d.length===0&&i.length===0&&d.push("format-version: 1.4");for(const f of t.graph){const h=fo(f.meta.name)?f.meta.name:wc(f.meta.name);for(const p of _R({column:f,relation:h},0,o))d.push(`property_value: ${p}`)}return d}function Eae(t,e,n,i){const{meta:r}=t,s=new Map(Object.entries(e).map(([c,d])=>[c,d.map(bR)])),o=new Set,l=(c,d)=>{d!==null&&!s.has(c)&&(s.set(c,[d]),o.add(c))};r.sourceFormat!=="obo"&&(l("format-version","1.4"),l("date",_ae(r.created)),l("saved-by",r.creator===null?null:uo(r.creator)));const a=wae(n,r.name,s.has("ontology"),i);return a!==null&&(s.has("ontology")||o.add("ontology"),s.set("ontology",[a])),{values:s,filled:o}}function wae(t,e,n,i){if(t!==null)return t;if(e===null||e.length===0||n)return null;if(/^[A-Za-z0-9_.\-/]+$/.test(e))return e;const r=e.replaceAll(/[^A-Za-z0-9_.-]/g,"_");return i(Xn.ONTOLOGY_NAME,`the graph name ${JSON.stringify(e)} is not an ontology id; written as ${r}`,null,null),r}function bR(t){return t.replaceAll(/\r\n|\r|\n|\f/g,String.raw`\n`)}function L0(t){return uo(t).replaceAll(":",String.raw`\:`)}function _ae(t){const e=t===null?null:/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}))?/.exec(t);return e===null?null:`${e[3]}:${e[2]}:${e[1]} ${e[4]??"00"}:${e[5]??"00"}`}function Sae(t){const{kept:e,rows:n,properties:i,relations:r}=t,s=[],o=Oae(t);Nae(e.typedefs,o,s);const l=(c,d)=>{o.has(c)||(o.add(c),s.push("","[Typedef]",`id: ${en(c)}`,`name: ${uo(c)}`),d&&s.push("is_metadata_tag: true"))},a=new Set;for(const c of t.edges)a.add(r[c]);for(const{column:c,relation:d}of i)n.some(u=>c.isSet(u))&&l(d,!0);for(const c of a)l(c,!1);for(const c of e.unknownFrames)s.push("",`[${c.type.replaceAll(/[\]\r\n]/g,"_")}]`,...ER(c.clauses));return s}function Oae(t){const{rows:e,kinds:n,ids:i,xref:r}=t,s=new Set(gR);for(const o of e){if(n[o]!=="Typedef")continue;s.add(i[o]);const l=r===null?void 0:Ne(r,o);for(const a of Array.isArray(l)?l:[])s.add(String(a))}return s}function Nae(t,e,n){for(const[i,r]of Object.entries(t))if(!(e.has(i)&&!gR.has(i))){e.add(i),n.push("","[Typedef]",`id: ${en(i)}`,...ER(r,"id"));for(const s of r.xref??[])e.add(s.trim())}}function ER(t,e=null){return Object.entries(t).filter(([n])=>n!==e).flatMap(([n,i])=>i.map(r=>`${L0(n)}: ${bR(r)}`))}class Aae{constructor(e){this.next=new Map,this.entries=e??{}}block(e,n){const i=Object.hasOwn(this.entries,e)?this.entries[e]:void 0,r=this.next.get(e)??0;return i===void 0||r>=i.length||i[r].value!==n?"":(this.next.set(e,r+1),D0(R0(i[r].qualifiers)))}placed(){return Object.entries(this.entries).every(([e,n])=>(this.next.get(e)??0)===n.length)}}function wi(t,e){return Nle(e)&&t.lineEnds++,e}function wR(t,e,n){let i=uo(wi(t.stats,e));const r=t.p.tags.get("xref.descriptions"),s=r===void 0?void 0:Ne(r,t.row);return s!==void 0&&Object.hasOwn(s,e)&&!t.described.has(e)&&(t.described.add(e),i+=` "${wr(wi(t.stats,s[e]))}"`),n!==null&&(i+=t.cursor.block(n,e)),i}function xm(t,e,n){const i=`${n}.xrefs`;return`[${e.map(r=>wR(t,r,i)).join(", ")}]`}function _R(t,e,n){const{column:i,relation:r}=t,s=Ne(i,e);if(s===void 0)return[];const o=en(r),l=(a,c)=>{let d,u=Zle[c]??"xsd:string";return typeof a=="number"&&u==="xsd:double"?d=Tae(a,c):typeof a=="string"||typeof a=="boolean"||typeof a=="number"?d=rl(a,c):(d=JSON.stringify(a)??"null",u="xsd:string"),`${o} "${wr(wi(n,d))}" ${u}`};return i.dtype==="list"?s.map(a=>l(a,i.child.dtype)):i.dtype==="json"||i.meta.components>1?[l(s,"json")]:[l(s,i.dtype)]}function Tae(t,e){return Number.isNaN(t)?"NaN":Number.isFinite(t)?Do(t,e==="f32"?"f32":"f64"):t>0?"INF":"-INF"}function Iae(t,e){const{p:n}=t,i=[];if(n.qualifiers!==null){const s=Ne(n.qualifiers,e);s!==void 0&&i.push(...R0(s))}for(const{column:s,name:o}of n.edgeColumns)i.push(...$ae(s,e).map(l=>[o,l]));const r=n.weights.text(e);r!==null&&i.push([pR,r]);for(const[,s]of i)wi(t.stats,s);return D0(i)}function $ae(t,e){const n=Ne(t,e);return n===void 0?[]:t.dtype==="list"?n.map(i=>rl(i,t.child.dtype)):[t.dtype==="json"?JSON.stringify(n)??"null":rl(n,t.dtype)]}function SR(t,e,n,i){const r=Ne(n,t.row);if(r===void 0)return;const{cursor:s,stats:o}=t,l=(a,c,d=!1)=>{i.push(`${e}: ${d?a:uo(wi(o,a))}${s.block(e,c)}`)};if(lh.has(e)){l(r,r);return}if(ah.has(e)){l(r?"true":"false",r?"true":"false",!0);return}if(Ec.has(e)){for(const a of r)l(en(a),a,!0);return}Object.hasOwn(bN,e)&&bN[e](t,e,r,i)}function jd(t){return t===void 0?"":D0(R0(t))}const bN={def(t,e,n,i){const r=t.p.tags.get("def.xrefs"),s=r===void 0?[]:Ne(r,t.row)??[],o=n;i.push(`def: "${wr(wi(t.stats,o))}" ${xm(t,s,"def")}${t.cursor.block("def",o)}`)},xref(t,e,n,i){for(const r of n)i.push(`xref: ${wR(t,r,null)}${t.cursor.block("xref",r)}`)},synonym(t,e,n,i){for(const r of n){const s=r.type===null?"":` ${en(r.type)}`;i.push(`synonym: "${wr(wi(t.stats,r.text))}" ${r.scope}${s} ${xm(t,r.xrefs,"synonym")}${jd(r.qualifiers)}`)}},intersection_of(t,e,n,i){for(const r of n){const s=r.relation===null?"":`${en(r.relation)} `;i.push(`intersection_of: ${s}${en(r.target)}${jd(r.qualifiers)}`)}},property_value(t,e,n,i){for(const r of n){const s=r.datatype===null?"":` ${en(r.datatype)}`,o=r.datatype===null&&fo(r.value)?en(r.value):`"${wr(wi(t.stats,r.value))}"${s}`;i.push(`property_value: ${en(r.relation)} ${o}${jd(r.qualifiers)}`)}},holds_over_chain:EN,equivalent_to_chain:EN,expand_assertion_to:wN,expand_expression_to:wN,[k0](t,e,n,i){for(const[r,s]of Object.entries(n))for(const o of s)i.push(`${L0(r)}: ${uo(wi(t.stats,o))}`)}};function EN(t,e,n,i){for(const[r,s]of n){const o=`${r} ${s}`;i.push(`${e}: ${en(r)} ${en(s)}${t.cursor.block(e,o)}`)}}function wN(t,e,n,i){for(const r of n)i.push(`${e}: "${wr(wi(t.stats,r.template))}" ${xm(t,r.xrefs,e)}${jd(r.qualifiers)}`)}function OR(t,e,n){const i=t.tags.get("obo.qualifiers"),r={p:t,row:e,cursor:new Aae(i===void 0?void 0:Ne(i,e)),described:new Set,stats:n},s=[`[${t.kinds[e]}]`,`id: ${en(t.ids[e])}`];for(const o of Kle)if(o==="name")Cae(r,s);else if(o==="property_value")vae(r,s);else if(o===mR)Dae(r,s);else{const l=t.tags.get(o);l!==void 0&&SR(r,o,l,s)}return n.qualifiersPlaced&&=r.cursor.placed(),s}function Cae(t,e){const n=t.p.label===null?void 0:Ne(t.p.label,t.row);typeof n=="string"&&e.push(`name: ${uo(wi(t.stats,n))}${t.cursor.block("name",n)}`)}function vae(t,e){const{p:n,row:i}=t,r=n.originals.get(i);r!==void 0&&e.push(`property_value: ${ch} "${wr(JSON.stringify(r))}" xsd:string`);const s=n.tags.get("property_value");s!==void 0&&SR(t,"property_value",s,e);for(const o of n.properties)for(const l of _R(o,i,t.stats))e.push(`property_value: ${l}`)}function Dae(t,e){const{p:n,row:i}=t;for(let r=n.edgeStart[i];r<n.edgeStart[i+1];r++){const s=n.edgeOrder[r],o=en(n.ids[n.dst[s]]),l=n.relations[s],a=Iae(t,s);l==="is_a"||l==="instance_of"&&n.kinds[i]==="Instance"?e.push(`${l}: ${o}${a}`):e.push(`relationship: ${en(l)} ${o}${a}`)}}function _N(t,e){const n={lineEnds:0,qualifiersPlaced:!0,duplicates:0};for(const i of e){const r=OR(t,i,n),s=new Set;for(let o=2;o<r.length;o++)s.has(r[o])&&n.duplicates++,s.add(r[o])}return n}function*kae(t){if(t.fatal!==null)throw t.fatal;yield t.header.map(n=>`${n}
|
|
193
|
+
`).join("");const e={lineEnds:0,qualifiersPlaced:!0};for(let n=0;n<t.ids.length;n++)t.frameless[n]===0&&(yield`
|
|
194
|
+
${OR(t,n,e).join(`
|
|
195
|
+
`)}
|
|
196
|
+
`);t.tail.length>0&&(yield`${t.tail.join(`
|
|
197
|
+
`)}
|
|
198
|
+
`)}function*SN(t,e){yield*kae(yR(t,e))}const Rae=Object.freeze({format:"obo",options:Object.freeze(["ontology","relation"]),capabilities:hR,check(t,e){return Object.freeze([...yR(t,e).notes])},export(t,e){return ti(SN(t,e))},exportToString(t,e){return ni(SN(t,e))}}),ON=500;function NN(t){if(t===void 0)return null;const e=s=>{throw new N("E_UNSUPPORTED","option pajekDraw: not an object of Pajek draw settings",{option:"pajekDraw",found:s})};if(typeof t!="object"||t===null||Array.isArray(t))return e(t);const n=t,i=(s,o,l)=>s===void 0?o:typeof s!="number"||!Number.isFinite(s)?e(s):(l?s>0:s>=0)?s:e(s),r=new Map;for(const[s,o]of Object.entries(n.ini??{})){if(typeof o!="string"&&typeof o!="number"&&typeof o!="boolean")return e(o);r.set(s,String(o))}return{width:i(n.width,ON,!0),height:i(n.height,ON,!0),partition:i(n.partition,0,!1),vector:i(n.vector,0,!1),vector2:i(n.vector2,0,!1),ini:r}}function Ya(t,e){const n=t.ini.get(e);return n!==void 0&&n!=="0"&&n!=="false"}function Lae(t){return t!==null&&Ya(t,"Form8.withLabels1")}function Pae(t){return t!==null&&Ya(t,"Form10.StraightLinesOnly1")}function dh(t,e){const n=t.ini.get(e),i=n===void 0||n.trim()===""?Number.NaN:Number(n);return Number.isFinite(i)?i:null}const AN=["#00ffff","#ffff00","#7fff00","#ff0000","#0000ff","#ffd8f2","#ffffff","#ff6321","#8c23ff","#606dc4","#1ef9a3","#009900","#7f7f7f","#000000","#ad0000","#ccffb2","#ffff99","#ff00ff","#007091","#ffb528","#ff0a9b","#00e000","#ff779e","#d8f2ff","#d8ff4f","#ff84ff","#e5ffcc","#ccccff","#59ddff","#ffd9bc","#db9370","#ccffff","#d8d8d8","#666666","#a5a5a5","#3f3f3f","#e5e5e5","#262626","#bfbfbf","#595959"],NR=20,AR="#ffd9bc",TN=8;function Mm(t,e,n){if(n<1)return null;const r=t.meta.extra.pajek?.objects?.filter(s=>s.kind===e)[n-1]?.column;return r===void 0||!t.nodes.has(r)?null:s=>{const o=t.nodes.value(r,s);return typeof o=="number"&&Number.isFinite(o)?o:null}}function Yt(t,e,n){return t[e]??=new Array(n).fill(null),t[e]}function xae(t,e,n){const i=e.nodeCount,r=Yt(n,"width",i),s=Yt(n,"height",i);Mae(t,r,s),Fae(t,e,r,s),Uae(t,e,n);const o=dh(t,"TransparencyofVertices");if(o!==null&&o<1){const l=Math.max(0,o),a=Yt(n,"fillOpacity",i);a.forEach((c,d)=>{a[d]=(typeof c=="number"?c:1)*l}),Yt(n,"borderOpacity",i).fill(l*l)}Ya(t,"Form10.effect3d")&&jae(e,n),Gae(t,n,i);for(const l of["width","height"])n[l].every(a=>a===null)&&Reflect.deleteProperty(n,l)}function Mae(t,e,n){const i=dh(t,"Form8.SizeofVertices");if(i===null||i===TN)return;const r=i/TN,s=o=>typeof o=="number"?o*r:NR*r*r;for(let o=0;o<e.length;o++)e[o]=s(e[o]),n[o]=s(n[o])}function Uae(t,e,n){const i=Mm(e,"partition",t.partition);if(i===null)return;const r=Yt(n,"fill",e.nodeCount);for(let s=0;s<e.nodeCount;s++){const o=i(s);o!==null&&(r[s]=AN[Math.abs(o)%AN.length])}}function Gae(t,e,n){const i=dh(t,"Form8.MarkVerticesUsing");i===2?Yt(e,"label",n).forEach((r,s,o)=>{o[s]=String(s+1)}):(i===3||i===4)&&Yt(e,"label",n).fill("")}function jae(t,e){const n=t.nodeCount,i=Yt(e,"fill",n),r=Yt(e,"fillGradient",n),s=Yt(e,"fillGradientAngle",n),o=l=>{const a=l/2,c=Math.floor(a);return a-c===.5&&c%2===0?c:Math.round(a)};for(let l=0;l<n;l++){const a=typeof i[l]=="string"?String(i[l]):AR;r[l]=`#${[1,3,5].map(d=>o(Number.parseInt(a.slice(d,d+2),16)).toString(16).padStart(2,"0")).join("")}`;const c=t.nodes.has("phi")?Number(t.nodes.value("phi",l)):0;s[l]=Number.isFinite(c)?((90-c)%360+360)%360:90}}function Fae(t,e,n,i){const r=Mm(e,"vector",t.vector);if(r===null)return;const s=Mm(e,"vector",t.vector2),o=(l,a,c)=>{c!==null&&c>=0&&(l[a]=(typeof l[a]=="number"?l[a]:NR)*c)};for(let l=0;l<e.nodeCount;l++){const a=r(l);if(s===null){const c=a===null||a<0?null:Math.sqrt(a);o(n,l,c),o(i,l,c)}else o(n,l,a),o(i,l,s(l))}}function zae(t,e,n,i){const r=e.edgeCount,s=dh(t,"TransparencyofLines");if(s!==null&&s<1){const o=Yt(i,"opacity",r);o.forEach((l,a)=>{o[a]=(typeof l=="number"?l:1)*Math.max(0,s)})}if(Ya(t,"Form10.StraightLinesOnly1")){const o=Yt(i,"curved",r);for(let l=0;l<r;l++){const a=i.bends?.[l];a==null&&(o[l]=!1)}}if(Ya(t,"Form10.ColorGradientLines")){const o=n.fill,l=f=>typeof o?.[f]=="string"?o[f]:AR,a=Yt(i,"gradientColors",r),c=Yt(i,"gradientKind",r),d=Yt(i,"sourceArrowColor",r),u=Yt(i,"targetArrowColor",r);for(let f=0;f<r;f++){const[h,p]=[l(e.edgeSource(f)),l(e.edgeTarget(f))];a[f]=`${h} ${p}`,c[f]="linear",d[f]=h,u[f]=p}}}const bi="label",TR="position",xt="shape",IR="relation",Wae="spells",$R="value",CR="value",Bae="partition",Hae="vector",P0=new Set(["ellipse","box","diamond","triangle","cross","empty","house","man","woman"]);function Um(t){return P0.has(t.toLowerCase())}const _r="graphty_originalId",Gm="% graphty.styles ",Vae=new Map([["network","network"],["vertices","vertices"],["arcs","arcs"],["edges","edges"],["arcslist","arcslist"],["edgeslist","edgeslist"],["matrix","matrix"],["partition","partition"],["vector","vector"]]),jm=/^[+-]?\d+$/,Yae=/^(\*|[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:-(\*|[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))?$/;function vR(t,e){const n=new Kae(t,e);let i=0;for(;i<t.length;)i=n.step(i);return n.finish()}class Kae{constructor(e,n){this.line=e,this.notes=n,this.tokens=[],this.current="",this.started=!1,this.quoted=!1}step(e){const n=this.line.codePointAt(e);if(n===34)return this.quote(e),e+1;const i=!this.quoted&&!this.started&&n===91?this.intervalEnd(e):-1;if(i>0)return this.current+=this.line.slice(e,i+1),this.started=!0,i+1;if(!this.quoted&&Rp(n))return this.endToken(),e+1;let r=e+1;for(;r<this.line.length;){const s=this.line.charCodeAt(r);if(s===34||!this.quoted&&Rp(s))break;r++}return this.current+=this.line.slice(e,r),this.started=!0,r}finish(){return this.quoted?null:(this.endToken(),this.tokens)}quote(e){const n=this.line.codePointAt(e+1);(this.quoted?e+1<this.line.length&&!Rp(n):this.started)&&this.notes!==void 0&&(this.notes.oddQuote=!0),this.quoted=!this.quoted,this.started=!0}intervalEnd(e){const n=this.line.indexOf("]",e);return n>e&&this.line.lastIndexOf("[",n)===e?n:-1}endToken(){this.started&&(this.tokens.push(this.current),this.current="",this.started=!1)}}function Rp(t){return t===32||t===9||t===13||t===12||t===11}function DR(t){return Xae.has(t.toLowerCase())}const Xae=new Set(["permutation","cluster","hierarchy"]);function kR(t){for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(!(n===32||n===9||n===13||n===12||n===11))return n===37}return!0}function RR(t){for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(!(n===32||n===9||n===13||n===12||n===11))return n===42}return!1}function LR(t){const e=vR(t.trimStart().slice(1));if(e===null||e.length===0||e[0].length===0)return null;const n=e[0],i=Vae.get(n.toLowerCase())??"unsupported";let r;switch(i){case"vertices":r=qae(e);break;case"arcs":case"edges":case"arcslist":case"edgeslist":case"matrix":r=Jae(e);break;case"network":case"partition":case"vector":r=Zae(e);break;case"unsupported":r={...Sr,next:e.length};break;default:{const d=i;throw new Error(`unknown section kind ${d}`)}}const{count:s,secondCount:o,relation:l,name:a,next:c}=r;return{kind:i,keyword:n,count:s,secondCount:o,relation:l,name:a,extra:e.slice(c)}}const Sr={count:null,secondCount:null,relation:null,name:null,next:1};function qae(t){if(t.length<2||!jm.test(t[1]))return Sr;const e=Number(t[1]);return t.length<3||!jm.test(t[2])?{...Sr,count:e,next:2}:{...Sr,count:e,secondCount:Number(t[2]),next:3}}function Jae(t){if(t.length<2||!t[1].startsWith(":")||!jm.test(t[1].slice(1)))return Sr;const e=Number(t[1].slice(1));return t.length<3?{...Sr,relation:e,next:2}:{...Sr,relation:e,name:t[2],next:3}}function Zae(t){return t.length<2?Sr:{...Sr,name:t.slice(1).join(" "),next:t.length}}function Lp(t){if(t.length===0)return!1;for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n<48||n>57)return!1}return!0}function Qae(t){return t.length>=2&&t.startsWith("[")&&t.endsWith("]")}function ece(t){const e=t.slice(1,-1);if(e.trim().length===0)return[];const n=[];for(const i of e.split(/[,/]/))n.push(tce(t,i));return n}function tce(t,e){const n=Yae.exec(e.replaceAll(/\s+/g,""));if(n===null)throw new Error(`malformed time interval ${t}: "${e}" is not a-b, a-* or a`);const[,i,r]=n;if(i==="*"&&r===void 0)throw new Error(`malformed time interval ${t}: "*" alone is not a time point`);const s=i==="*"?-1/0:Number(i);let o;if(r===void 0?o=s:r==="*"?o=1/0:o=Number(r),i!=="*"&&!Number.isFinite(s)||r!==void 0&&r!=="*"&&!Number.isFinite(o))throw new Error(`malformed time interval ${t}: "${e}" is beyond the number range`);if(s>o)throw new Error(`malformed time interval ${t}: ${i} is after ${r??""}`);return[s,o]}const PR=/&#(?:[xX]([\da-fA-F]+)|(\d+));/g;function nce(t,e){return t.includes("&#")?t.replaceAll(PR,(n,i,r)=>{const s=i===void 0?Number(r):Number.parseInt(i,16);return s<=1114111?String.fromCodePoint(s):(e?.(n),n)}):t}function ice(t){return t.includes("&#")?t.replaceAll(PR,e=>`&${e.slice(1)}`):t}function rce(t){const e=[];for(const[n,i]of t){const r=n===-1/0?"*":String(n);n===i?e.push(r):e.push(`${r}-${i===1/0?"*":String(i)}`)}return`[${e.join(",")}]`}function sce(t){return t.length===0||/[\s"]/.test(t)||t.startsWith("[")||t.startsWith("*")||t.startsWith("%")||Um(t)?!1:!/^[+-]?(\.\d|\d)/.test(t)&&!/^[+-]?(?:nan|inf|infinity)$/i.test(t)}const xR=new Set(["bc","bw","s_size","phi","r","q","lc","la","lr","lphi","fos","font"]),x0=Object.freeze({tool:"pajek",node:Object.freeze(["label","fill","fillOpacity","opacity","borderColor","borderWidth","shape","shapePoints","width","height","labelColor","labelSize","labelFont","labelPosition","labelOffsetX","labelOffsetY","labelShiftX"]),edge:Object.freeze(["color","opacity","width","lineStyle","sourceArrow","targetArrow","arrowSize","arrowPosition","label","labelColor","labelSize","labelFont"]),block:"native"}),Ka=20,MR=new Map([["other:man",[2.502,6.487]],["other:woman",[3.003,6.478]]]),oce=.3,ss=500,M0=["ic","bc","bw","s_size","x_fact","y_fact","phi","q","lc","fos","font","lr","lphi","la"],UR=["c","w","p","s","ap","l","lc","fos","font"],uh={node:[xt,...M0],edge:["c","w","p","s","ap"]},lce=uh.edge.filter(t=>t!=="p"&&t!=="ap"),fh=2,Fm={color:"#999999",width:1};function ace(t,e){let n=new Map;return i=>{const r=new Map;for(const o of t){const l=i(o);l!==null&&r.set(o,l)}if(e){if(r.size>0)return n=r,i}else for(const[o,l]of r)n.set(o,l);const s=n;return o=>i(o)??(t.includes(o)?s.get(o)??null:null)}}const IN="directed",cce={node:["label","shape","shapePoints","shapePointsStretch","fill","fillOpacity","borderColor","borderWidth","width","height","labelColor","labelSize","labelFont","labelPosition","labelOffsetX","labelOffsetY","labelShiftX","labelRotation"],edge:["color","opacity","width","lineStyle","arrowSize","arrowPosition","label","labelColor","labelSize","labelFont"]};function ca(t,e,n,i,r){if(t===null)return;const s=ve(t,"dvips",r(e));if(s===null){const l=dce.get(e);l!==void 0&&typeof t=="string"&&/^[A-Za-z]\w*$/.test(t.trim())&&i(e,l);return}i(e,s.color);const o=Ol(s,null,r(e),n!==null);n!==null&&i(n,o)}const dce=new Map([["fill","#ffffff"],["color","#000000"]]);function da(t,e,n,i){t!==null&&n(e,Y(t,i(e)))}function GR(t,e,n,i=null){const r=t(bi);r!==null&&r!==""&&e("label",rt(r,n("label")));const s=t(xt),o=s===null?null:le("shape",s,"dvips",n("shape"));if(s!==null&&e("shape",o),ca(t("ic"),"fill","fillOpacity",e,n),ca(t("bc"),"borderColor",null,e,n),da(t("bw"),"borderWidth",e,n),gce(t,e,n,MR.get(String(o))),fce(t,e,o),ca(t("lc"),"labelColor",null,e,n),da(t("fos"),"labelSize",e,n),FR(t("font"),e,n),bce(t,e,n),pce(t("la"),e,n,i),o==="none")for(const[l,a]of hce)e(l,a)}const uce=new Map([["rectangle",[[-1,1],[1,1],[1,-1],[-1,-1]]],["triangle",[[1,-1],[0,1],[-1,-1]]],["other:house",[[-.7,-1],[.7,-1],[.7,.3],[1,.3],[1,.4],[0,1],[-1,.4],[-1,.3],[-.7,.3]]]]),jR=.001;function fce(t,e,n){const i=Yn(t("phi"))??0,r=Yn(t("q"))??jR,s=[[-1,0],[-r,1],[r,1],[1,0],[r,-1],[-r,-1]],o=n==="diamond"?s:uce.get(String(n));if(o===void 0||n!=="diamond"&&i%360===0)return;const[l,a]=[Yn(t("x_fact"))||1,Yn(t("y_fact"))||1],[c,d]=[Math.cos(i*Math.PI/180),Math.sin(i*Math.PI/180)],u=h=>String(Number(h.toFixed(4))+0),f=o.map(([h,p])=>{const[g,m]=[h*l,p*a];return`${u((g*c-m*d)/l)},${u((g*d+m*c)/a)}`});e("shape","polygon"),e("shapePoints",f.join(" ")),e("shapePointsStretch",!1)}const hce=[["labelSize",1],["labelColor","#ffffff"],["labelPosition","center"],["labelOffsetX",0],["labelOffsetY",0],["labelShiftX",0]];function FR(t,e,n){if(t===null||t==="")return;const i=typeof t=="string"?iC(t.trim()):null;if(i===null){zR(t,"labelFont",e,n);return}e("labelFont",i.family)}function pce(t,e,n,i){let r=t===null?null:Y(t,n("labelRotation"));r!==null&&r>=360&&(r=i===null?null:Math.atan2(.5-i[1],i[0]-.5)*180/Math.PI+r-360),r!==null&&e("labelRotation",Number((((360-r)%360+360)%360).toPrecision(12)))}function gce(t,e,n,i){for(const[r,s,o]of[["x_fact","width",0],["y_fact","height",1]]){const l=t(r);if(l===null&&i===void 0)continue;const c=l===null?i===void 0?1:oce:Y(l,n(s)),d=i?.[o]??1;e(s,c===null?null:Number((Ka*c*d).toPrecision(15)))}}function zR(t,e,n,i){t!==null&&t!==""&&n(e,rt(t,i(e)))}const mce=new Map([["right",0],["top-right",90],["left",180],["bottom-right",285]]),yce=new Map([["top","top-right"],["top-left","top-right"],["bottom","bottom-right"],["bottom-left","bottom-right"]]);function bce(t,e,n){const[i,r,s]=[t("lr"),t("lphi"),t("fos")];if(i===null&&r===null&&s===null)return;const o=i===null?WR:Y(i,n("labelPosition")),l=r===null?zm:Y(r,n("labelPosition")),a=s===null?U0:Y(s,n("labelSize"));if(o===null||l===null||a===null)return;const[c,d]=Ece(o,l,a);e("labelPosition","center"),e("labelOffsetX",c),e("labelOffsetY",d),e("labelShiftX",o===0?0:.5)}function Ece(t,e,n){if(t===0)return[0,0];const i=e*Math.PI/180,r=s=>Number(s.toFixed(9))+0;return[r(t*Math.cos(i)),r(-t*Math.sin(i)-G0*n)]}const WR=20,zm=285,U0=15,G0=.3465;function BR(t,e,n,i,r=!0,s=null,o=null){ca(t("c"),"color","opacity",e,n),da(t("w"),"width",(d,u)=>{e(d,typeof u=="number"&&!i?u*fh:u)},n);const l=t("p");l==="Dots"?e("lineStyle",j0(t,i)):l==="Solid"?e("lineStyle","solid"):l!==null&&(H(n("lineStyle"),v.UNKNOWN_VALUE,typeof l=="string"?l:JSON.stringify(l)),e("lineStyle","solid")),da(t("s"),"arrowSize",e,n),Rce(t("ap"),e,n,s);const a=o===null?t:wce(t),c=o===null?null:_ce(a,e,o);r&&(zR(t("l"),"label",e,n),c===null?CN(t,e,n,s):CN(a,e,n,[ss,0],Sce(c))),o===null&&Nce(t,e,s),ca(t("lc"),"labelColor",null,e,n),da(t("fos"),"labelSize",e,n),FR(t("font"),e,n)}const $N={a1:-70,k1:.3,a2:-70,k2:.3};function wce(t){return e=>t(e)??(e in $N?$N[e]:null)}function _ce(t,e,n){const r=Xa(t,[ss,0]);if(r===null)return null;const[[s,o],[l,a]]=r,c=ss,[d,u]=[[s*c,-o*c],[(l-1)*c,-a*c]];return n([d,u]),e("curved",!0),e("bendCurve","bezier"),e("targetArrow","none"),[d,u]}function Sce(t){const[e,n]=t;return Math.atan2(n[1]-e[1],n[0]-e[0])*180/Math.PI}function Oce(t,e,n,i){const r=s=>String(Math.round(s*1e4)/1e4||0);for(const[s,o]of e){const l=t.edgeSource(s),a=f=>{const h=n[f]?.[l];return(typeof h=="number"&&h>0?h:Ka)/2},[c,d]=[a("width"),a("height")],u=f=>i[f]??=new Array(t.edgeCount).fill(null);u("bends")[s]=o.map(([f,h])=>`${r(f/c)},${r(-h/d)}`).join(" "),u("curved")[s]=!0,u("bendCurve")[s]="bezier"}}function CN(t,e,n,i,r){const s=i===null?0:Math.hypot(i[0],i[1]);if(i===null||s===0)return;const o=(b,_,S)=>{const T=t(b);return T===null?_:Y(T,n(S))},[l,a,c,d]=[o("lp",.5,"labelOffsetX"),o("lr",0,"labelOffsetX"),o("lphi",0,"labelOffsetX"),o("la",0,"labelRotation")],u=o("fos",U0,"labelSize");if(l===null||a===null||c===null||d===null||u===null)return;const f=.5-(l<=1?l:l/s),h=c*Math.PI/180,p=b=>Number(b.toFixed(9))+0,g=((r??$ce(t,i,f+.5))-d)%360+360,m=g*Math.PI/180,y=G0*u;e("labelPosition","center"),e("labelOffsetX",p(f*i[0]+a*Math.cos(h)+y*Math.sin(m))),e("labelOffsetY",p(f*i[1]-a*Math.sin(h)-y*Math.cos(m))),e("labelRotation",p(g%360))}function Nce(t,e,n){const i=Xa(t,n);if(i===null)return;const r=s=>String(Math.round(s*1e4)/1e4||0);e("curved",!0),e("bendCurve","bezier"),e("bends",i.map(([s,o])=>`${r(s)},${r(o)}`).join(" "))}const Pp=1.5;function Ace(t,e,n,i){const r=Yn(t("ap"))??0,s=Math.hypot(n[0],n[1]);if(r!==0||s===0||Xa(t,n)===null)return!1;const[o,l]=[n[0]/s,n[1]/s],a=1/Math.hypot(o/(i[0]/2),l/(i[1]/2)),c=Pp+5*(Yn(t("s"))??1),d=-(Yn(t("a2"))??0)*Math.PI/180,[u,f]=[Math.cos(d),Math.sin(d)],h=[n[0]-a*o-c*(o*u-l*f),n[1]-a*l-c*(o*f+l*u)],p=Xa(t,h);if(p===null)return!1;const g=s*s,m=_=>String(Math.round(_*1e4)/1e4||0),y=p.map(([_,S])=>{const[T,$]=[_*h[0]+S*h[1],_*h[1]-S*h[0]];return`${m((T*n[0]+$*n[1])/g)},${m((T*n[1]-$*n[0])/g)}`});e("bends",y.join(" "));const b=[-a*o-Pp*(o*u-l*f),-a*l-Pp*(o*f+l*u)];return e("targetPort",`${m(b[0]/(i[0]/2))},${m(-b[1]/(i[1]/2))}`),!0}const Tce=1;function Ice(t,e){const n=Yn(t("s"))??1;n>0&&e("targetArrowGap",Number((Tce/(6*n)).toPrecision(6)))}function Xa(t,e){const[n,i,r,s]=["a1","k1","a2","k2"].map(u=>Yn(t(u)));if(n===null&&i===null&&r===null&&s===null||e===null||e[0]===0&&e[1]===0)return null;const[o,l]=[i??1,s??1];if(o<0||l<0)return null;const a=Math.PI/180,[c,d]=[(n??0)*a,(r??0)*a];return[[o/2*Math.cos(c),-o/2*Math.sin(c)],[1-l/2*Math.cos(d),-l/2*Math.sin(d)]]}function $ce(t,e,n){const i=Xa(t,e);let[r,s]=e;if(i!==null){const o=Math.min(1,Math.max(0,n)),l=[[0,0],...i,[1,0]],a=u=>3*(1-o)**2*(l[1][u]-l[0][u])+6*(1-o)*o*(l[2][u]-l[1][u])+3*o**2*(l[3][u]-l[2][u]),[c,d]=[a(0),a(1)];[r,s]=[c*e[0]+d*e[1],c*e[1]-d*e[0]]}return Math.atan2(s,r)*180/Math.PI}function Cce(t,e,n,i=!0){t===0?n("visible",!1):t!==null&&t<0&&e("p")===null&&n("lineStyle",j0(e,i))}const vce=5;function j0(t,e){const i=(Yn(t("w"))??1)*(e?1:fh);return vce<=1.5*Math.max(1,i)?"dotted":"dashed"}function Dce(t,e,n,i){for(const[r,s,o]of[["h1","sourcePort",n],["h2","targetPort",i]]){const l=Yn(t(r)),a=l===null?null:kce(o,l);if(a!==null){const c=d=>String(Number(d.toFixed(4))+0);e(s,`${c(a[0])},${c(a[1])}`)}}}function kce(t,e){if(!Number.isInteger(e)||e<1)return null;const n=typeof t=="string"?t.toLowerCase():"ellipse";if(n==="ellipse"||n==="cross"){const r=e*Math.PI/180;return[Math.cos(r),Math.sin(r)]}if(n!=="box"||e>400)return null;const i=e*.02;return e<=50?[1,i]:e<=150?[2-i,1]:e<=250?[-1,4-i]:e<=350?[i-6,-1]:[1,i-8]}function Yn(t){return typeof t=="string"&&t.trim()!==""&&(t=Number(t)),typeof t=="number"&&Number.isFinite(t)?t:null}function Rce(t,e,n,i=null){if(t===null)return;const r=Y(t,n("arrowPosition")),s=i===null?0:Math.hypot(i[0],i[1]);if(r!==null&&r>1){s>0?e("arrowPosition",Number(Math.min(1,r/s).toPrecision(6))):H(n("arrowPosition"),v.NOT_CARRIED,`ap ${String(r)}`);return}r!==0&&e("arrowPosition",r)}function vN(t,e){return n=>{const i=t.has(n)?K(t.value(n,e)):null;return Lce.has(n)&&typeof i=="string"&&Pce.test(i)?null:i}}const Lce=new Set(["ic","bc","lc","c"]),Pce=/^[\d.]+(?: [\d.]+)*$/;function F0(t){const e=new Array(t.edgeCount).fill(t.directed),n=t.directed?t.edges.byRole("directed"):null;if(n!==null)for(let i=0;i<t.edgeCount;i++)e[i]=K(n.value(i))!==!1;return e}const DN={a1:15,k1:.25,a2:15,k2:.25};function xce(t,e){const n=new Map;for(let r=0;r<t.edgeCount;r++){const[s,o]=[t.edgeSource(r),t.edgeTarget(r)];if(e[r]&&s!==o){const l=s<o?`${String(s)} ${String(o)}`:`${String(o)} ${String(s)}`;n.set(l,[...n.get(l)??[],r])}}const i=new Map;for(const r of n.values())if(!(r.length<2))for(const s of r){const o=r.filter(l=>t.edgeSource(l)===t.edgeSource(s));i.set(s,(o.length-1-o.indexOf(s))%2===0?1:-1)}return i}function Mce(t,e){return Object.keys(DN).some(n=>t(n)!==null)?t:n=>{const i=DN[n];return i===void 0?t(n):n.startsWith("a")?e*i:i}}function kN(t,e){return e.filter(n=>t.has(n))}function Uce(t,e){const n=new se,{block:i,draw:r,voided:s}=jce(e.kept),o=Lae(r),l=Gce(t),a=r??{width:ss,height:ss},c=new Map,d=D=>{const[x,R]=[l(t.edgeSource(D)),l(t.edgeTarget(D))];return x===null||R===null?null:[(R[0]-x[0])*a.width,(R[1]-x[1])*a.height]},u=D=>{const x=D==="node"?t.nodes:t.edges,R=D==="node"?t.nodeCount:t.edgeCount,G=Qr(R),B=ace(D==="node"?uh.node:lce,D==="node");for(let Q=0;Q<R;Q++){e.budget.spend(D,1);const be=ee=>({notes:n,target:D,property:ee,element:Q,budget:e.budget}),De=(ee,Ke)=>{G.put(Q,ee,Ke)},J=vN(x,Q),st=D==="node"&&s.has(Q)?Fce(J,g[Q-1]??null):B(J);D==="node"?(GR(st,De,be,l(Q)),g[Q]=st(xt)):f(Q,st,De,be)}return G.values},f=(D,x,R,G)=>{const B=d(D),Q=B!==null&&i===null&&t.edgeSource(D)===t.edgeTarget(D)?st=>{c.set(D,st)}:null,be=p.get(D),De=be===void 0?x:Mce(x,be);BR(De,R,G,h[D],o,B,Q);const J=h[D]&&B!==null&&Ace(De,R,B,_(t.edgeTarget(D)));h[D]&&Q===null&&!J&&i===null&&Ice(x,R),Cce(y(D),x,R,h[D]),Dce(x,R,g[t.edgeSource(D)],g[t.edgeTarget(D)])},h=F0(t),p=Pae(r)||i!==null?new Map:xce(t,h),g=[],m=Ot(t),y=D=>m.isExplicit(D)?m.value(D):Yn(vN(t.edges,D)($R)),b=u("node"),_=D=>{const x=R=>{const G=b[R]?.[D];return typeof G=="number"&&G>0?G:Ka};return[x("width"),x("height")]},S=u("edge");r!==null&&(xae(r,t,b),zae(r,t,b,S)),Oce(t,c,b,S),i!==null&&Qce(t,i,{node:b,edge:S},o);const T=[],$=new Map;return h.some(Boolean)&&($.set(IN,h.map(D=>D?!0:null)),T.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:IN}},set:{targetArrow:"triangle",color:Fm.color,width:Fm.width}})),{canonical:!0,dialect:"dvips",tool:"pajek",units:"px",node:{values:b},edge:{values:S,rules:T,columns:$},notes:n.list(),block:i,readFrom:{node:kN(t.nodes,[xt,...M0]),edge:kN(t.edges,UR)}}}function Gce(t){const e=t.nodes.byRole("position");return n=>{const i=e==null?null:e.value(n);if(i===null||typeof i!="object"||!("length"in i))return null;const[r,s]=i;return typeof r=="number"&&typeof s=="number"?[r,s]:null}}function jce(t){if(typeof t=="string")return{block:t,draw:null,voided:new Set};if(typeof t=="object"&&t!==null){const{block:e,pajekDraw:n,voided:i}=t;return{block:typeof e=="string"?e:null,draw:n??null,voided:new Set(i??[])}}return{block:null,draw:null,voided:new Set}}function Fce(t,e){return n=>n===bi?t(n):n===xt?e:null}const zce=new Map([["ellipse","ellipse"],["rectangle","box"],["diamond","diamond"],["triangle","triangle"],["none","empty"],["other:cross","cross"],["other:house","house"],["other:man","man"],["other:woman","woman"]]),Wce=new Map([["round-rectangle","box"],["parallelogram","box"],["trapezoid","box"],["vee","triangle"]]),Bce=new Map([...$1].reverse().map(([t,e])=>[e,t]));function hh(t){return Bce.get(t)??`RGB${t.slice(1).toUpperCase()}`}function HR(t,e,n){for(const i of e){const r=t(i);r!==null&&r!==1&&n(i,r)}}function Hce(t,e){const n=t("shape");if(typeof n!="string")return"ellipse";const i=zce.get(n);if(i!==void 0)return i;if(n==="polygon"&&VR(t)!==null)return"diamond";e("shape",n);const r=t("shapePoints");return n==="polygon"&&r!==null&&e("shapePoints",r),Wce.get(n)??"ellipse"}function VR(t){const e=t("shapePoints"),n=typeof e=="string"?e.trim().split(/\s+/).map(s=>s.split(",").map(Number)):[];if(n.length!==6)return null;const i=n[2][0];return[[-1,0],[-i,1],[i,1],[1,0],[i,-1],[-i,-1]].every(([s,o],l)=>n[l][0]===s&&n[l][1]===o)?i:null}function ul(t,e){return vr("pajek")?.[t]?.[e]?.value}function YR(t,e){const n=new Map;HR(t,["fillOpacity","opacity"],e);const i=Hce(t,e);i!=="ellipse"&&n.set(xt,i);const r=VR(t);r!==null&&r!==jR&&n.set("q",r),Vce(t,n),Yce(t,n);const s=t("borderWidth");return typeof s=="number"&&s!==ul("node","borderWidth")&&n.set("bw",s),KR(t,n,ul("node","labelFont")),Kce(t,n,e),n}function Vce(t,e){const n=[["fill","ic"],["borderColor","bc"],["labelColor","lc"]];for(const[i,r]of n){const s=t(i);typeof s=="string"&&s!==ul("node",i)&&e.set(r,hh(s))}}function Yce(t,e){const n=[["width","x_fact",Ka],["height","y_fact",Ka],["labelSize","fos",1]],i=MR.get(String(t("shape")));for(const[r,s,o]of n){const l=t(r);let a=1;i!==void 0&&s!=="fos"&&(a=i[s==="x_fact"?0:1]),typeof l=="number"&&(a!==1||l!==ul("node",r))&&e.set(s,Number((l/(o*a)).toPrecision(15)))}}function KR(t,e,n){const i=t("labelFont"),r=typeof i=="string"&&i!==""?$b(i,!1,!1):null;r!==null&&r!==n&&e.set("font",r)}function Kce(t,e,n){const i=t("labelPosition");if(typeof i!="string")return;if(i==="center"){const o=Xce(t);o===null?e.set("lr",0):(o[0]!==WR||o[1]!==zm)&&(e.set("lr",o[0]),e.set("lphi",o[1]));return}const r=yce.get(i);r!==void 0&&n("labelPosition",i);const s=mce.get(r??i);s!==void 0&&s!==zm&&e.set("lphi",s)}function Xce(t){const[e,n,i]=[t("labelOffsetX"),t("labelOffsetY"),t("labelShiftX")];if(typeof e!="number"||typeof n!="number"||i!==.5)return null;const r=t("labelSize"),s=n+G0*(typeof r=="number"?r:U0),o=a=>Number(a.toFixed(6))+0,l=o(Math.hypot(e,s));return l===0?null:[l,o((Math.atan2(-s,e)*180/Math.PI%360+360)%360)]}function XR(t){return t?Fm:{color:ul("edge","color"),width:ul("edge","width")}}function qR(t,e,n){const i=new Map;HR(t,["opacity"],n);const r=XR(e),s=t("color");typeof s=="string"&&s!==r.color&&i.set("c",hh(s));const o=t("width");typeof o=="number"&&o!==r.width&&i.set("w",e?o:Number((o/fh).toPrecision(15)));const l=t("lineStyle");typeof l=="string"&&l!=="solid"&&Zce(l,i,e,n)&&i.set("p","Dots"),qce(t,i),Jce(t,i,n);const a=t("targetArrow");a!==null&&a!==(e?"triangle":"none")&&n("targetArrow",a);const c=t("sourceArrow");return c!==null&&c!=="none"&&n("sourceArrow",c),i}function qce(t,e){const n=t("arrowSize");typeof n=="number"&&n!==1&&e.set("s",n);const i=t("arrowPosition");typeof i=="number"&&i>0&&e.set("ap",i)}function Jce(t,e,n){const i=t("label");if(typeof i=="string"&&i!==""){const o=ph(i);o!==i&&n("label",i),e.set("l",o)}const r=t("labelColor");typeof r=="string"&&e.set("lc",hh(r));const s=t("labelSize");typeof s=="number"&&e.set("fos",s),KR(t,e)}function Zce(t,e,n,i){return t===j0(r=>e.get(r)??null,n)?!0:(i("lineStyle",t),["dashed","dotted","dash-dot","long-dash"].includes(t))}function Qce(t,e,n,i){const r=new se,s=F0(t);so(t,e,"pajek",o=>({values:n[o],properties:cce[o],writes:x0[o],readBack:(l,a)=>{const c=nde(o,a,s[l],r,i);return d=>c.get(d)??null},take:(l,a)=>a!==null||tde.has(l)||ede.has(l)}))}const ede=new Set(["shapePoints","shapePointsStretch"]),tde=new Set(["labelOffsetX","labelOffsetY","labelShiftX"]);function nde(t,e,n,i,r){const s=()=>{},o=t==="node"?YR(e,s):qR(e,n,s),l=new Map,a=t==="node"?e("label"):null;typeof a=="string"&&o.set(bi,ph(a)),t==="node"&&[...o.keys()].every(f=>f===bi)&&o.set(xt,"ellipse");for(const f of t==="edge"?uh.edge:[])o.has(f)||o.set(f,ZR(f,n));const c=f=>o.get(f)??null,d=(f,h)=>{h!==null&&l.set(f,h)},u=f=>({notes:i,target:t,property:f});return t==="node"?GR(c,d,u):BR(c,d,u,n,r),l}function JR(t,e){if(e===void 0)return null;const n=new Il,i=t.withColumns(),r=F0(t);for(const l of["node","edge"]){const a=l==="node"?i.nodes:i.edges,c=(p,g)=>{n.add(l,p,g)},d=Vs((p,g)=>e.picture(p,g),l,x0[l]),u=l==="node"?t.nodeCount:t.edgeCount,h=lde(u,p=>l==="node"?YR(d(p),c):qR(d(p),r[p],c));l==="edge"&&ide(t,h),ode(l,h,r),sde(a,l==="node"?[xt,...M0]:UR,h)}i.nodes.set(bi,rde(e,t.nodeCount,n),{dtype:"string",role:"label"},{replaceRole:!0});const s=n.notes("Pajek"),o=Nl(e.rules,{inlineColumns:!0,snapshot:t});return s.push(...lc(o,e.rules.styles.rules.length,"size")),{snapshot:i,comment:Gm+o,notes:s}}function ide(t,e){if(!t.edges.has("l"))return;const n=r=>K(t.edges.value("l",r));let i=e.get("l");for(let r=0;r<t.edgeCount;r++){const s=n(r);typeof s=="string"&&s!==""&&(i?.[r]??null)===null&&(i??=new Array(t.edgeCount).fill(null),i[r]=ph(s))}i!==void 0&&e.set("l",i)}function rde(t,e,n){const i=t.picture("node","label"),r=new Array(e).fill("");for(let s=0;s<e;s++){const o=i[s]??null;typeof o=="string"&&(r[s]=ph(o),r[s]!==o&&n.add("node","label",o))}return r}function ph(t){return t.replaceAll(/\r\n|[\r\n]/g," ").replaceAll('"',"'")}function sde(t,e,n){for(const i of e)t.has(i)&&t.remove(i);for(const[i,r]of n){const s=r.every(o=>o===null||typeof o=="number");t.set(i,r,{dtype:s?"f64":"string"})}}function ode(t,e,n){if(t==="node"){const i=[...e.values()];if(i.length===0)return;const r=i[0].length,s=e.get(xt)??new Array(r).fill(null);for(let o=0;o<r;o++)i.every(l=>l[o]===null)&&(s[o]="ellipse");e.set(xt,s);return}for(const i of uh.edge){const r=e.get(i);if(r!==void 0)for(let s=0;s<r.length;s++)r[s]??=ZR(i,n[s])}}function ZR(t,e){const n=XR(e);switch(t){case"c":return hh(String(n.color));case"w":return e?Number(n.width):Number(n.width)/fh;case"p":return"Solid";case"s":return 1;default:return 0}}function lde(t,e){const n=new Map;for(let i=0;i<t;i++)for(const[r,s]of e(i)){let o=n.get(r);o===void 0&&(o=new Array(t).fill(null),n.set(r,o)),o[i]=s}return n}const Mt=Object.freeze({TEXT:"E_PAJEK_TEXT",KEY_DROPPED:"W_PAJEK_KEY_DROPPED",LABEL_AS_TEXT:"W_PAJEK_LABEL_AS_TEXT",NONFINITE_AS_TEXT:"W_PAJEK_NONFINITE_AS_TEXT",MUTUAL_AS_UNDIRECTED:w.MUTUAL_AS_UNDIRECTED,TEMPORAL_DROPPED:w.TEMPORAL,POSITION_STRIDE:"W_PAJEK_POSITION_STRIDE",FIRST_MODE_DROPPED:"W_PAJEK_FIRST_MODE_DROPPED",ROLE_DROPPED:w.ROLE,SHAPE_AS_PARAMETER:"W_PAJEK_SHAPE_AS_PARAMETER",LABEL_GAINED:"W_PAJEK_LABEL_GAINED",ROLE_ASSUMED:w.ROLE_ASSUMED,COLUMN_DROPPED:w.COLUMN_DROPPED,ID_TEXT_TYPE:w.ID_TEXT_TYPE,TEXT_INFERRED:w.TEXT_INFERRED}),ade=new Set(["label"]),cde=Object.freeze({label:"label",position:TR}),dde=new Set(["directed","pair","mutual","weight","timeText","originalId"]),ude=new Set(["color","size","shape","thickness","parent","parents","open","spellsOpen"]),fde=new Set(["start","end","timestamp","timestamps"]),gh=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"dense-1-based",dtypes:["f64","i32","bool","string"],temporal:"spells",positions:!0});function Fu(t,e,n){const i=[];for(const r of t){const s=hde(r,e,n);s!==null&&i.push({column:r,slot:s})}return i}function eo(t,e,n,i){t?.push(In(e,n,i.meta.name,i.length-i.nullCount))}function hde(t,e,n){const{role:i,name:r}=t.meta;return i==="label"&&e==="node"?pde(t,n):i==="position"?gde(t,e,n):i==="spells"?mde(t,e,n):i!==null&&fde.has(i)?(eo(n,Mt.TEMPORAL_DROPPED,`${e} column "${r}" (${i}) cannot be written; Pajek intervals come from the spells role`,t),null):yde(t,e)?null:bde(t,e,n)}function pde(t,e){const{name:n,dtype:i}=t.meta;return i!=="string"&&i!=="dict"&&eo(e,Mt.LABEL_AS_TEXT,`node column "${n}" (label) is ${i}; labels are text and re-import as string`,t),"label"}function gde(t,e,n){const{name:i,components:r}=t.meta;return e==="edge"?(eo(n,w.POSITIONS,`edge column "${i}" (position) cannot be written`,t),null):r===2||r===3?"position":(eo(n,Mt.POSITION_STRIDE,`node column "${i}" (position) has ${r} components; Pajek coordinates are x y [z]`,t),null)}function mde(t,e,n){const{name:i,dtype:r,itemDtype:s}=t.meta;return r==="list"&&(s==="f64"||s==="i32"||s==="f32")?"spells":(eo(n,w.SPELLS,`${e} column "${i}" (spells) is not a list of number pairs; it cannot be written`,t),null)}function yde(t,e){const{role:n,dtype:i}=t.meta;return n!==null&&(dde.has(n)||ude.has(n))?!0:e==="edge"&&n==="id"||i==="list"||i==="json"}function bde(t,e,n){const{name:i,dtype:r}=t.meta,s=r==="dict"||r==="string";return s&&e==="node"&&i===xt?Ede(t,n):s&&e==="edge"&&i===IR?"relation":sce(i)?"param":(eo(n,Mt.KEY_DROPPED,`${e} column "${i}" cannot be a Pajek parameter key; it is not written`,t),null)}function Ede(t,e){return Sde(t)?"shape":(t.meta.dtype==="dict"&&eo(e,Mt.SHAPE_AS_PARAMETER,`node column "${t.meta.name}" holds values outside the Pajek shape keywords; it is written as a parameter and reads back as string`,t),"param")}function wde(t,e,n){let i=null,r=0;for(const{column:l,slot:a}of e)a==="label"?i=l:a!=="skip"&&a!=="relation"&&r++;const s=[...t.nodes].find(l=>l.meta.role===null&&l.meta.name===bi);s!==void 0&&(n.push(In(Mt.ROLE_ASSUMED,`node column "${bi}" has no role; written as a parameter, it reads back as the vertex label (role label)`,bi,s.length-s.nullCount)),i!==null&&i!==s&&n.push(In(Mt.COLUMN_DROPPED,`node column "${i.meta.name}" (the labels) reads back replaced by the parameter "${bi}"`,i.meta.name,i.length-i.nullCount)));const o=r===0?0:_de(t.nodeCount,i);o>0&&n.push(In(Mt.LABEL_GAINED,`${o} vertex line${O(o)} ${C(o,"carries","carry")} coordinates, a shape or parameters and need a label; the id text is written there and reads back as a label`,i===null?bi:i.meta.name,o))}function _de(t,e){let n=0;for(let i=0;i<t;i++)e?.isSet(i)||n++;return n}function Sde(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!P0.has(t.value(e)))return!1;return!0}function In(t,e,n=null,i=null){return Object.freeze({code:t,message:e,column:n,count:i})}function RN(t,e){switch(e){case"i32":case"u32":case"u8":return Ge(t);case"f32":return ct(t);case"f64":return Ar(t,"f64");default:{const n=e;throw new Error(`unknown numeric dtype ${n}`)}}}function qa(t,e){switch(t.dtype){case"f32":case"f64":case"i32":case"u32":case"u8":{const n=t.value(e);if(typeof n=="number")return RN(n,t.dtype);const i=[],r=n;for(let s=0;s<r.length;s++)i.push(RN(r[s],t.dtype));return i.join(" ")}case"bool":return t.value(e)===!0?"true":"false";case"dict":case"string":return t.value(e);case"list":case"json":return JSON.stringify(t.value(e));default:{const n=t.dtype;throw new Error(`unknown dtype ${n}`)}}}function zu(t,e,n){for(const{column:i,slot:r}of t){if(r==="position"||r==="spells")continue;const{name:s}=i.meta;let o=0,l=0,a=0;for(let c=0;c<i.length;c++)if(i.isSet(c)){if(i.dtype==="f64"||i.dtype==="f32"){const d=i.value(c);typeof d=="number"?Number.isFinite(d)||l++:d!==void 0&&!Array.from(d).every(u=>Number.isFinite(u))&&l++}else if(i.dtype==="string"||i.dtype==="dict"){const d=i.value(c);Ry(d)?r==="param"&&qn(d)!=="string"&&a++:o++}}o>0&&n.push(In(Mt.TEXT,`${o} value${O(o)} of ${e} column "${s}" hold a double quote or a line break; Pajek cannot write them`,s,o)),a>0&&n.push(In(Mt.TEXT_INFERRED,`${a} value${O(a)} of ${e} column "${s}" look like numbers or booleans; Pajek parameters are untyped and they read back as such`,s,a)),l>0&&n.push(In(Mt.NONFINITE_AS_TEXT,`${l} non-finite value${O(l)} of ${e} column "${s}" ${C(l,"is","are")} written as text`,s,l))}}function QR(t){const{pajek:e}=t.meta.extra;if(typeof e!="object"||e===null)return null;const n=e.firstMode;return n===void 0?null:typeof n=="number"&&Number.isInteger(n)&&n>=0&&n<=t.nodeCount?n:Number.NaN}function Ode(t,e,n,i){return t?.isSet(n)?qa(t,n):i||e.isChanged(n)?Hi(e.originalAt(n)):null}function eL(t,e){if(t.dtype!=="list"||!t.isSet(e))return null;const n=t.sliceOf(e);if(n.length===0)return null;const i=[];for(const r of n){const s=r;i.push([s[0],s[1]])}return rce(i)}function Nde(t,e,n){if(!t.isSet(e))return null;const i=t.dtype,r=t.value(e),s=Do(r[0],i),o=Do(r[1],i);return t.meta.components===3&&n?`${s} ${o} ${Do(r[2],i)}`:`${s} ${o}`}function Ade(t){if(t.meta.components!==3)return!1;if(t.meta.extra.sourceDims!==2)return!0;for(let e=0;e<t.length;e++)if(t.isSet(e)&&t.value(e)[2]!==0)return!0;return!1}function*LN(t,e,n=null){const i=wl(t,gh.idCharset,e.mangle?"mangle":"error"),r=tL(Fu(t.nodes,"node",null),e.mangle),s=Fu(t.edges,"edge",null),o=[];zu(r,"node",o),zu(s,"edge",o),nL(t.nodeCount,i,e.mangle,o);for(const a of o)if(a.code===Mt.TEXT)throw new N("E_UNSUPPORTED",a.message,{reason:"pajek label",column:a.column,count:a.count});n!==null&&(yield`${n}
|
|
199
|
+
`),e.networkHeader&&(yield e.name===null?`*Network
|
|
200
|
+
`:`*Network ${e.name}
|
|
201
|
+
`);const l=QR(t);yield l!==null&&!Number.isNaN(l)?`*Vertices ${t.nodeCount} ${l}
|
|
202
|
+
`:`*Vertices ${t.nodeCount}
|
|
203
|
+
`,yield*Tde(t,i,r,e.mangle),yield*Cde(t,s)}function tL(t,e){return e?t.filter(n=>!(n.slot==="param"&&n.column.meta.name===_r)):t}function nL(t,e,n,i){let r=0,s=0;for(let o=0;o<t;o++){if(!e.isChanged(o))continue;const l=e.originalAt(o),a=Hi(l);Ry(a)?n&&typeof tc(a)!=typeof l&&s++:r++}r>0&&i.push(In(Mt.TEXT,`${r} node id${O(r)} ${C(r,"holds","hold")} a double quote or a line break; Pajek cannot write them as labels or parameters`,null,r)),s>0&&i.push(In(Mt.ID_TEXT_TYPE,`${s} original id${O(s)} ${C(s,"reads","read")} back from ${_r} as the other type under ids: "canonical" (a string "1" becomes 1, a number 1.5 becomes "1.5")`,null,s))}function*Tde(t,e,n,i){const r=Ide(n),s=r.position!==null&&Ade(r.position);for(let o=0;o<t.nodeCount;o++){const l=$de(r,o,s);if(i&&e.isChanged(o)&&l.push(`${_r} ${Yo(Hi(e.originalAt(o)))}`),r.spells!==null){const d=eL(r.spells,o);d!==null&&l.push(d)}const a=Ode(r.labels,e,o,l.length>0);let c=String(o+1);a!==null&&(c+=` ${Yo(ice(a))}`),l.length>0&&(c+=` ${l.join(" ")}`),yield`${c}
|
|
204
|
+
`}}function Ide(t){const e={labels:null,position:null,shape:null,spells:null,params:[]};for(const{column:n,slot:i}of t)switch(i){case"label":e.labels=n;break;case"position":e.position=n;break;case"shape":e.shape=n;break;case"spells":e.spells=n;break;case"param":e.params.push(n);break;case"relation":case"skip":break;default:{const r=i;throw new Error(`unknown slot ${r}`)}}return e}function $de(t,e,n){const{position:i,shape:r}=t,s=[],o=i===null?null:Nde(i,e,n);o!==null&&s.push(o);const l=s.length>0,a=r?.isSet(e)===!0;if(a){const d=qa(r,e);s.push(P0.has(d)?d:`${xt} ${Yo(d)}`)}const c=s.length;for(const d of t.params)d.isSet(e)&&(l&&!a&&s.length===c&&xR.has(d.meta.name)&&s.push("ellipse"),s.push(`${d.meta.name} ${Yo(qa(d,e))}`));return s}function*Cde(t,e){const n=Gt(t,{foldMutual:!0}),i=Ot(t),{src:r,dst:s}=t.edgeList();let o=null,l=null;const a=[];for(const{column:h,slot:p}of e)switch(p){case"relation":o=h;break;case"spells":l=h;break;case"param":a.push(h);break;case"label":case"position":case"shape":case"skip":break;default:{const g=p;throw new Error(`unknown slot ${g}`)}}const c=new Map;let d=null,u=null,f=!1;for(let h=0;h<t.edgeCount;h++){if(n.folded(h))continue;const g=t.directed&&n.sourceDirected(h)&&!n.isMutual(h)?"arcs":"edges",m=o?.isSet(h)?qa(o,h):null;if(!f||g!==d||m!==u){d=g,u=m,f=!0;const _=g==="arcs"?"*Arcs":"*Edges";if(m===null)yield`${_}
|
|
205
|
+
`;else{let S=c.get(m);S===void 0&&(S=c.size+1,c.set(m,S)),yield`${_} :${S} ${Yo(m)}
|
|
206
|
+
`}}let y=`${r[h]+1} ${s[h]+1}`;const b=i.text(h);b!==null&&(y+=` ${b}`);for(const _ of a)_.isSet(h)&&(y+=` ${_.meta.name} ${Yo(qa(_,h))}`);if(l!==null){const _=eL(l,h);_!==null&&(y+=` ${_}`)}yield`${y}
|
|
207
|
+
`}f||(yield t.directed?`*Arcs
|
|
208
|
+
`:`*Edges
|
|
209
|
+
`)}function Wm(t,e){const n=ft(e),i=e?.networkHeader;if(i!==void 0&&typeof i!="boolean")throw new N("E_UNSUPPORTED","option networkHeader: not a boolean",{option:"networkHeader",found:typeof i});const r=e?.name;if(r!==void 0&&(typeof r!="string"||/[\r\n]/.test(r)))throw new N("E_UNSUPPORTED","option name: not a one-line string",{option:"name",found:typeof r});return{networkHeader:i??r!==void 0,name:r??t.meta.name,mangle:n.sanitizeIds==="mangle"}}const vde=Object.freeze({format:"pajek",options:Object.freeze(["name","networkHeader"]),capabilities:gh,styles:Object.freeze({capabilities:x0}),check(t,e){const n=JR(t,e?.styles);return n===null?xN(t,e):Object.freeze([...xN(n.snapshot,iL(e)),...n.notes])},export(t,e){return ti(PN(t,e))},exportToString(t,e){return ni(PN(t,e))}});function PN(t,e){const n=JR(t,e?.styles);return n===null?LN(t,Wm(t,e)):LN(n.snapshot,Wm(n.snapshot,iL(e)),n.comment)}function iL(t){return t?.sanitizeIds===void 0?{...t,sanitizeIds:"mangle"}:t}function Dde(t,e){const n=new Set,i=r=>`${r.meta.domain}:${r.meta.name}`;for(const{column:r,slot:s}of e){const o=s==="param"&&r.meta.domain==="node"&&r.meta.name===xt;(s==="shape"||s==="relation"||o)&&n.add(i(r))}for(const r of[...t.nodes,...t.edges])r.meta.role==="spells"&&n.add(i(r));return n}function kde(t,e,n){return Un(t,gh,e,{roles:ade,roleNames:cde,edgeRoleNames:{}}).filter(r=>{if(r.column===null||r.code!==w.LIST&&r.code!==w.DTYPE)return!0;const s=r.message.startsWith("node column")?"node":"edge";return!n.has(`${s}:${r.column}`)})}function xN(t,e){const n=ft(e),{mangle:i}=Wm(t,e),r=[],s=Fu(t.nodes,"node",r),o=tL(s,i),l=Fu(t.edges,"edge",r),a=wl(t,gh.idCharset,i?"mangle":"error");nL(t.nodeCount,a,i,r);const c=o.length===s.length?void 0:s.find(f=>f.slot==="param"&&f.column.meta.name===_r);c!==void 0&&r.push(In(Mt.KEY_DROPPED,`node column "${_r}" is the parameter the exporter writes the original ids under (sanitizeIds "mangle"); it is not written`,_r,c.column.length-c.column.nullCount));const d=Dde(t,[...o,...l]);r.push(...kde(t,n,d)),wde(t,o,r);for(const f of[...t.edges].filter(h=>h.meta.role==="label"))r.push(In(w.ROLE,`edge column "${f.meta.name}" (label) is written as a plain parameter; Pajek labels vertices only and the role is lost`,f.meta.name,f.length-f.nullCount));zu(o,"node",r),zu(l,"edge",r);const u=Gt(t,{foldMutual:!0});return u.mutualCount>0&&r.push(In(Mt.MUTUAL_AS_UNDIRECTED,`${u.mutualCount} mutual pair${O(u.mutualCount)} ${C(u.mutualCount,"is","are")} written as undirected edges; the mutual mark is lost`,t.edges.byRole("mutual")?.meta.name??null,u.mutualCount)),Number.isNaN(QR(t))&&r.push(In(Mt.FIRST_MODE_DROPPED,"meta.extra.pajek.firstMode is not a count within 0..nodeCount; the two-mode header is not written")),r}const q=Object.freeze({...xn,...Pn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:En,NO_VERTICES:"E_PAJEK_NO_VERTICES",VERTICES_COUNT:"E_PAJEK_VERTICES_COUNT",MULTIPLE_GRAPHS:Qn,GRAPH_NOT_FOUND:Nr,AMBIGUOUS_GRAPH_NAME:as,OUTSIDE_SECTION:"E_PAJEK_OUTSIDE_SECTION",SYNTAX:kn,UNTERMINATED_QUOTE:"E_PAJEK_UNTERMINATED_QUOTE",VERTEX_LINE:"E_PAJEK_VERTEX_LINE",VERTEX_RANGE:"E_PAJEK_VERTEX_RANGE",VERTEX_COUNT:"W_PAJEK_VERTEX_COUNT",DUPLICATE_NODE:sn,LINE:"E_PAJEK_LINE",UNKNOWN_NODE:"E_UNKNOWN_NODE",INTERVAL:"E_PAJEK_INTERVAL",MATRIX_ROWS:"E_PAJEK_MATRIX_ROWS",MATRIX_EXTRA:"W_PAJEK_MATRIX_EXTRA",OBJECT_COUNT:"E_PAJEK_OBJECT_COUNT",UNSUPPORTED_SECTION:"W_PAJEK_UNSUPPORTED_SECTION",HEADER_EXTRA:"W_PAJEK_HEADER_EXTRA",NO_LINES:"W_PAJEK_NO_LINES",ZERO_BASED:"W_PAJEK_ZERO_BASED",COORD_DIMS:"W_PAJEK_COORD_DIMS",LABEL_MERGED:"W_PAJEK_LABEL_MERGED",ID_MERGED:Rn,WIDENING_UNSUPPORTED:af,COLUMN_RENAMED:ec,ROLE_TAKEN:bn,ORIGINAL_ID_MERGED:"W_PAJEK_ORIGINAL_ID_MERGED",ORIGINAL_ID_UNRESTORED:"W_PAJEK_ORIGINAL_ID_UNRESTORED",OPTION_IGNORED:Jt,SINK_OPTION:Ln,QUOTE_IN_TOKEN:"W_PAJEK_QUOTE_IN_TOKEN",DUPLICATE_ATTRIBUTE:fe,REFERENCE_RANGE:"W_PAJEK_REFERENCE_RANGE",TWO_MODE_LINE:"W_PAJEK_TWO_MODE_LINE",NUMERIC_LABEL:"W_PAJEK_NUMERIC_LABEL",RELATION_RENAMED:"W_PAJEK_RELATION_RENAMED",NEGATIVE_LIST_ENTRY:"W_PAJEK_NEGATIVE_LIST_ENTRY",PRECISION:re,TRAILING_VALUE:"W_PAJEK_TRAILING_VALUE",NAN_VALUE:"W_PAJEK_NAN_VALUE"}),MN=new Set(["ids","nodeIdFrom","restoreMangledIds","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","errorLimit","signal","onProgress"]),UN={ids:"canonical",defaultDirected:!0,weightFrom:CR},GN=64,Rde=new Set([0,1,"auto"]),Lde=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Pde=/^[+-]?(?:nan|inf|infinity)$/i,xde=/^[+-]?nan$/i,Mde={name:bi,dtype:"string",nullable:!0,role:"label",origin:{format:"pajek",id:"label"}},Ude={name:xt,dtype:"dict",nullable:!0,origin:{format:"pajek",id:"shape"}},Gde={name:IR,dtype:"dict",nullable:!0,origin:{format:"pajek",id:"relation"}};function jN(){return{name:Wae,dtype:"list",itemDtype:"f64",itemComponents:2,nullable:!0,role:"spells",origin:{format:"pajek",id:"interval"}}}function jde(t,e){return{name:TR,dtype:"f64",components:3,nullable:!0,role:"position",origin:{format:"pajek",id:"coordinates"},extra:{sourceDims:t,units:"file",pxPerUnit:e.width,...e.height===e.width?{}:{pxPerUnitY:e.height},yAxis:"down",zOrigin:.5,zeroUnplaced:!0}}}const Bm={width:ss,height:ss};class At extends Error{constructor(e,n,i){super(i),this.name="PajekLineError",this.category=e,this.code=n}}function Fde(t){return Number.isInteger(t)&&t>=-2147483648&&t<=2147483647}const zde=/^-?\d+$/,Wde=/^(\d+):$/;class FN{constructor(e,n,i,r,s=Bm){this.keptBlock=null,this.voided=[],this.section="none",this.kind="directed",this.relation=null,this.vertexCount=-1,this.verticesLine=0,this.firstMode=null,this.networkName=null,this.base=1,this.baseKnown=!1,this.nodesCreated=!1,this.verticesDone=!1,this.sawLineSection=!1,this.firstKind="directed",this.directionSet=!1,this.relationNames=new Map,this.objects=[],this.objectHeader=!1,this.firstUnsupported=null,this.outOfRange=0,this.indexOfPos=new Uint32Array(0),this.idOfPos=null,this.seen=new Uint8Array(0),this.seenCount=0,this.filledBelow=0,this.matrixRows=0,this.coordDims=0,this.labelHandle=A,this.positionHandle=A,this.shapeHandle=A,this.nodeSpellsHandle=A,this.relationHandle=A,this.edgeSpellsHandle=A,this.nodeParams=new Map,this.ended=!1,this.edgeParams=new Map,this.styleBlockKept=!1,this.window=s,this.sink=e,this.report=n,this.options=i,this.firstVertex=r,this.resolver=new ei(e,n,i.onMixedDirection),this.coercer=new Mn(i.ids)}comment(e){if(this.styleBlockKept)return;const n=e.trimStart();n.startsWith(Gm)&&(this.styleBlockKept=!0,this.keptBlock=n.slice(Gm.length),this.report.keepForStyles(this.keptBlock))}line(e,n){if(kR(e))return this.comment(e),!1;const i=this.objectHeader;this.objectHeader=!1;try{if(RR(e))return this.header(e,n,i),this.ended;switch(this.section){case"none":throw new At("parse-error",q.OUTSIDE_SECTION,"data before the first section header; a Pajek network starts with *Vertices");case"vertices":return this.vertexLine(e,n),!1;case"lines":return this.edgeLine(e,n),!1;case"list":return this.listLine(e,n),!1;case"matrix":return this.matrixLine(e,n),!1;case"object":return this.objectLine(e,n),!1;case"skip":return!1;default:{const r=this.section;throw new Error(`unknown section state ${r}`)}}}catch(r){return r instanceof At?(this.report.error(r.category,r.code,r.message,{line:n}),!1):(this.report.recordError(r,{line:n}),!1)}}finish(){if(this.vertexCount<0){const r=this.firstUnsupported===null?"":` (the file has the unrecognised section *${this.firstUnsupported})`;this.report.fail(q.NO_VERTICES,`not a Pajek network: no *Vertices section found${r}`)}this.endSection(),this.finishVertices(),this.sawLineSection?this.directionSet||this.resolver.setHeader(this.firstKind==="directed"):(this.report.warning("validation-error",q.NO_LINES,"the file declares vertices but no *Arcs, *Edges, *Arcslist, *Edgeslist or *Matrix section"),this.resolver.setHeader(this.options.defaultDirected));const e=this.writeObjects();this.coercer.mergeCount>0&&this.report.warning("coercion",q.ID_MERGED,`${this.coercer.mergeCount} label${O(this.coercer.mergeCount)} merged into an id another label already produced under ids "number"`);const n={...this.firstMode===null?{}:{firstMode:this.firstMode},...e.length===0?{}:{objects:e}},i={sourceFormat:"pajek",...this.networkName===null?{}:{name:this.networkName},...Object.keys(n).length===0?{}:{extra:{pajek:n}}};this.sink.setMeta(i)}writeObjects(){const e=new Set,n=[];for(const i of this.objects){const r={line:i.line},s=i.kind==="partition",o=Xt(s?Bae:Hae,null,u=>e.has(u));e.add(o);const{handle:l,decl:a}=he(this.sink,"node",{name:o,dtype:s?"i32":"f64",nullable:!0,origin:{format:"pajek",id:i.kind}},this.report,r),c=Math.min(i.values.length,this.vertexCount);for(let u=0;u<c;u++){const f=i.values[u];f!==null&&this.sink.setNodeValue(l,this.indexOfPos[u],f)}const d=i.count??i.values.length;(d!==this.vertexCount||i.values.length!==d)&&this.report.error("validation-error",q.OBJECT_COUNT,`*${s?"Partition":"Vector"} "${i.name}" declares ${d} vertices and holds ${i.values.length} value${O(i.values.length)}; the network has ${this.vertexCount}`,r),n.push({kind:i.kind,name:i.name,column:a.name})}return n}header(e,n,i){const r=this.section;this.endSection();const s=LR(e);if(s===null)throw this.section="skip",new At("parse-error",q.SYNTAX,`cannot read the section header "${e}"`);switch(s.extra.length>0&&this.report.warning("validation-error",q.HEADER_EXTRA,`ignored ${s.extra.length} unexpected token${O(s.extra.length)} after *${s.keyword}: ${s.extra.join(" ")}`,{line:n}),s.kind){case"network":if(this.networkName!==null||this.vertexCount>=0){this.ended=!0;return}this.networkName=s.name??"",this.section="none";return;case"vertices":this.verticesSectionLine(s,n,r,i);return;case"arcs":case"edges":this.lineSection(s,n,"lines",s.kind==="arcs"?"directed":"undirected");return;case"arcslist":case"edgeslist":this.lineSection(s,n,"list",s.kind==="arcslist"?"directed":"undirected");return;case"matrix":this.lineSection(s,n,"matrix","directed"),this.matrixRows=0;return;case"partition":case"vector":this.objects.push({kind:s.kind,name:s.name??"",line:n,count:null,values:[]}),this.section="object",this.objectHeader=!0;return;case"unsupported":this.section="skip",this.objectHeader=DR(s.keyword),this.firstUnsupported??=s.keyword,this.report.warning("unsupported",q.UNSUPPORTED_SECTION,`the *${s.keyword} section is not supported; its lines are skipped`,{line:n});return;default:{const o=s.kind;throw new Error(`unknown section kind ${o}`)}}}verticesSectionLine(e,n,i,r){if(r){this.section=i,i==="object"&&(this.objects[this.objects.length-1].count=e.count);return}if(this.vertexCount>=0){this.ended=!0;return}this.verticesHeader(e,n)}verticesHeader(e,n){e.count===null&&this.report.fail(q.VERTICES_COUNT,"*Vertices needs a vertex count",{line:n}),Number.isSafeInteger(e.count)||this.report.fail(q.VERTICES_COUNT,`*Vertices ${e.count}: not a count`,{line:n}),e.secondCount!==null&&(e.secondCount<0||e.secondCount>e.count)&&this.report.fail(q.VERTICES_COUNT,`*Vertices ${e.count} ${e.secondCount}: the first-mode count is not within 0..${e.count}`,{line:n});try{this.sink.reserve(e.count)}catch(i){const r=i instanceof Error?i.message:String(i);this.report.fail(q.VERTICES_COUNT,`*Vertices ${e.count}: the sink cannot hold that many (${r})`,{line:n})}this.vertexCount=e.count,this.verticesLine=n,e.secondCount!==null&&(this.firstMode=e.secondCount),this.section="vertices",this.indexOfPos=new Uint32Array(e.count),this.seen=new Uint8Array(e.count),this.filledBelow=0,(this.options.nodeIdFrom==="label"||this.restoresIds())&&(this.idOfPos=new Array(e.count)),this.firstVertex!=="auto"&&this.setBase(this.firstVertex,n)}lineSection(e,n,i,r){if(this.vertexCount<0&&this.report.fail(q.NO_VERTICES,`*${e.keyword} before *Vertices; a Pajek network starts with *Vertices`,{line:n}),this.finishVertices(),this.sawLineSection||(this.sawLineSection=!0,this.firstKind=r),this.section=i,this.kind=r,this.relation=e.relation===null?null:e.name??String(e.relation),e.relation!==null){const s=this.relation??String(e.relation),o=this.relationNames.get(e.relation);o!==void 0&&o!==s&&this.report.warning("validation-error",q.RELATION_RENAMED,`relation ${e.relation} was named ${JSON.stringify(o)} and is now named ${JSON.stringify(s)}; its lines carry the name of their own section`,{line:n,element:String(e.relation)}),this.relationNames.set(e.relation,s)}}endSection(){const e=this.firstMode??this.vertexCount;this.section==="matrix"&&this.matrixRows!==e&&this.report.error("validation-error",q.MATRIX_ROWS,`*Matrix has ${this.matrixRows} row${O(this.matrixRows)}; *Vertices declares ${e}`),this.section="none"}setBase(e,n){this.base=e,this.baseKnown=!0,e===0&&this.firstVertex==="auto"&&this.report.warning("coercion",q.ZERO_BASED,"vertex numbering starts at 0; Pajek numbers vertices from 1",{line:n})}createNodes(){if(this.nodesCreated||this.idOfPos!==null)return;this.nodesCreated=!0;const e=this.vertexCount;for(let n=0;n<e;n++)this.indexOfPos[n]=this.addNode(this.idOfNumber(n+this.base));this.report.counts.nodes+=e}addNode(e){try{return this.sink.addNode(e)}catch(n){if(!(n instanceof N)||n.code!=="E_TOO_LARGE")throw n;return this.report.fail(q.VERTICES_COUNT,`*Vertices ${this.vertexCount}: the sink cannot hold that many (${n.message})`,{line:this.verticesLine})}}idOfNumber(e){if(this.options.nodeIdFrom==="index")return e-this.base;switch(this.options.ids){case"canonical":case"number":return e;case"keep":case"string":return String(e);default:return sf(String(e),this.options.ids)}}idAt(e){return this.idOfPos!==null?this.idOfPos[e]:this.idOfNumber(e+this.base)}finishVertices(){if(this.verticesDone)return;this.verticesDone=!0,this.baseKnown||this.setBase(1,0);const e=this.vertexCount;if(this.createNodes(),this.idOfPos!==null)for(let i=0;i<e;i++)this.idOfPos[i]===void 0&&this.numberedNode(this.idOfPos,i);const n=this.seenCount+this.report.counts.skippedNodes-this.outOfRange;this.seenCount>0&&n<e&&this.report.warning("validation-error",q.VERTEX_COUNT,`*Vertices declares ${e} vertices but ${n} vertex line${O(n)} ${C(n,"was","were")} read; the others have no label`)}vertexLine(e,n){const i=this.tokens(e,"node",n),{k:r,pos:s}=this.vertexNumber(i,n);let o=1,l=null;i.length>1&&!Vde(e,i)&&(l=this.labelOf(i[1],r,n),o=2);const{xyz:a,dims:c,next:d}=this.vertexCoordinates(i,o,r);o=d,this.checkCoordinates(e,i,o,c===2&&l!==null,r,n);let u=null;o<i.length&&Um(i[o])&&(u=i[o].toLowerCase(),o++);const f=this.extras(i,o,"node",n);u=f.shape??u;const h=this.restoredId(f);this.createNodes();const p=this.markVertexSeen(s,r,n),g=this.vertexIndex(s,r,l,h,p,n);u===null&&c>0&&f.keys.length>0&&xR.has(f.keys[0])&&this.voided.push(g),l!==null&&(this.labelHandle=this.nodeHandle(this.labelHandle,Mde,n),this.sink.setNodeValue(this.labelHandle,g,l)),c>0&&this.writePosition(g,c,a,r,n),u!==null&&this.writeShape(g,u,n);for(let m=0;m<f.keys.length;m++)this.writeParameter("node",f.keys[m],g,f.values[m]);f.spells!==null&&(this.nodeSpellsHandle=this.nodeHandle(this.nodeSpellsHandle,jN(),n),this.sink.setNodeValue(this.nodeSpellsHandle,g,f.spells))}vertexNumber(e,n){if(!Lp(e[0]))throw this.report.counts.skippedNodes++,new At("parse-error",q.VERTEX_LINE,`a vertex line starts with a vertex number, not "${e[0]}"`);const i=Number(e[0]);this.baseKnown||this.setBase(i===0?0:1,n);const r=i-this.base;if(r<0||r>=this.vertexCount)throw this.report.counts.skippedNodes++,this.outOfRange++,new At("validation-error",q.VERTEX_RANGE,`vertex ${i} is outside ${this.base}..${this.base+this.vertexCount-1}`);return{k:i,pos:r}}vertexCoordinates(e,n,i){if(n+1<e.length&&ci(e[n])&&ci(e[n+1])){const r=Number(e[n]),s=Number(e[n+1]);return n+2<e.length&&ci(e[n+2])?{xyz:[r,s,Number(e[n+2])],dims:3,next:n+3}:{xyz:[r,s,0],dims:2,next:n+2}}if(n<e.length&&ci(e[n]))throw this.report.counts.skippedNodes++,new At("parse-error",q.VERTEX_LINE,`vertex ${i}: a single coordinate "${e[n]}"; coordinates are x y [z]`);return{xyz:[0,0,0],dims:0,next:n}}markVertexSeen(e,n,i){return this.seen[e]!==0?(this.report.warning("merged",q.DUPLICATE_NODE,`vertex ${n} has more than one line; the later values overwrite`,{line:i,element:String(n)}),!0):(this.seen[e]=1,this.seenCount++,!1)}vertexIndex(e,n,i,r,s,o){const{idOfPos:l}=this;if(l!==null&&!s&&this.options.nodeIdFrom==="label")return this.deferredNode(l,e,n,i,o,"label");if(l!==null&&l[e]===void 0){for(let a=this.filledBelow;a<e;a++)l[a]===void 0&&this.numberedNode(l,a);return e>this.filledBelow&&(this.filledBelow=e),this.deferredNode(l,e,n,r,o,"originalId")}return r!==null&&!s&&this.report.warning("coercion",q.ORIGINAL_ID_UNRESTORED,`vertex ${n} carries ${_r} ${JSON.stringify(r)} but a later vertex's line came first and created it under its number; the original id is not restored`,{line:o,element:String(n)}),this.indexOfPos[e]}nodeHandle(e,n,i){return e===A?he(this.sink,"node",n,this.report,{line:i}).handle:e}writeShape(e,n,i){if(this.shapeHandle===A&&this.nodeParams.has(xt)){this.writeParameter("node",xt,e,n);return}this.shapeHandle=this.nodeHandle(this.shapeHandle,Ude,i),this.sink.setNodeValue(this.shapeHandle,e,n)}labelOf(e,n,i){return nce(e,r=>{this.report.warnOnce("validation-error",q.REFERENCE_RANGE,`character reference ${r} is beyond U+10FFFF; it is kept as written`,{line:i,element:String(n)},`${q.REFERENCE_RANGE}:${r}`)})}checkCoordinates(e,n,i,r,s,o){if(i<n.length&&(Lde.test(n[i])||Pde.test(n[i]))&&!ci(n[i]))throw this.report.counts.skippedNodes++,new At("parse-error",q.VERTEX_LINE,`vertex ${s}: coordinate "${n[i]}" is not a finite number`);const l=n[1];r&&ci(l)&&!Number.isInteger(Number(l))&&!rL(e,n)&&this.report.warnOnce("validation-error",q.NUMERIC_LABEL,`vertex ${s}: "${l} ${n[2]} ${n[3]}" is read as the label ${l} and x y; quote the label, or it may be meant as x y z`,{line:o,element:String(s)})}writePosition(e,n,i,r,s){this.positionHandle===A?(this.coordDims=n,this.positionHandle=he(this.sink,"node",jde(n,this.window),this.report,{line:s}).handle):n!==this.coordDims&&this.report.warnOnce("validation-error",q.COORD_DIMS,`vertex lines mix ${this.coordDims} and ${n} coordinates; the position column records sourceDims ${this.coordDims}`,{line:s,element:String(r)}),this.sink.setNodeValue(this.positionHandle,e,i)}restoresIds(){return this.options.restoreMangledIds&&this.options.nodeIdFrom==="id"}numberedNode(e,n){const i=this.idOfNumber(n+this.base);e[n]=i,this.indexOfPos[n]=this.addNode(i),this.report.counts.nodes++}restoredId(e){if(!this.restoresIds())return null;const n=e.keys.indexOf(_r);if(n<0)return null;const[i]=e.values.splice(n,1);return e.keys.splice(n,1),i}deferredNode(e,n,i,r,s,o){const l=r===null?this.idOfNumber(i):this.coercer.text(r),a=this.sink.indexOf(l),c=this.addNode(l);return e[n]=l,this.indexOfPos[n]=c,this.report.counts.nodes++,a!==A&&this.report.warning("merged",o==="label"?q.LABEL_MERGED:q.ORIGINAL_ID_MERGED,o==="label"?`vertex ${i} has the label ${JSON.stringify(String(l))} of an earlier vertex; both are one node`:`vertex ${i} has the ${_r} ${JSON.stringify(String(l))} of an earlier vertex; both are one node`,{line:s,element:String(i)}),c}edgeLine(e,n){let i=this.tokens(e,"edge",n),{relation:r}=this;const s=Wde.exec(i[0]);if(s!==null){const g=Number(s[1]);r=this.relationNames.get(g)??String(g),i=i.slice(1)}if(i.length<2||!Lp(i[0])||!Lp(i[1]))throw this.report.counts.skippedEdges++,new At("parse-error",q.LINE,`a line starts with two vertex numbers, not "${i.slice(0,2).join(" ")}"`);const o=this.endpoint(Number(i[0])),l=this.endpoint(Number(i[1]));let a=2,c=null;a<i.length&&ci(i[a])?(c=i[a],a++):a<i.length&&xde.test(i[a])&&(this.report.warnOnce("validation-error",q.NAN_VALUE,`a line value ${JSON.stringify(i[a])} is not a number; the line is kept without a value`,{line:n}),a++);const d=this.extras(i,a,"edge",n),{weightFrom:u}=this.options;let f,h=!1;if(_y(CR,u))h=!0,c!==null&&(f=this.weightOf(c));else if(u!==null){const g=d.keys.indexOf(u);g>=0&&(f=this.weightOf(d.values[g]),d.keys.splice(g,1),d.values.splice(g,1))}const p=this.pushEdge(o,l,f,n);c!==null&&!h&&this.writeParameter("edge",$R,p,c),this.writeEdgeExtras(p,d,r)}listLine(e,n){const i=this.tokens(e,"edge",n);for(const s of i)if(!zde.test(s))throw this.report.counts.skippedEdges++,new At("parse-error",q.LINE,`an adjacency list holds vertex numbers only, not "${s}"`);i.some(s=>s.startsWith("-"))&&this.report.warnOnce("coercion",q.NEGATIVE_LIST_ENTRY,"an adjacency list holds a negative vertex number; it is read as its absolute value and the sign is dropped",{line:n});const r=this.endpoint(Math.abs(Number(i[0])));for(let s=1;s<i.length;s++){const o=this.endpoint(Math.abs(Number(i[s]))),l=this.pushEdge(r,o,void 0,n);this.writeRelation(l)}}matrixLine(e,n){const i=this.tokens(e,"edge",n),r=this.matrixRows;this.matrixRows++;const s=this.firstMode??0,o=this.firstMode??this.vertexCount,l=this.vertexCount-s;if(r>=o)throw new At("validation-error",q.MATRIX_ROWS,`*Matrix row ${r+1} is beyond the ${o} declared row${O(o)}`);if(i.length<l)throw new At("parse-error",q.LINE,`*Matrix row ${r+1} has ${i.length} value${O(i.length)}; the matrix has ${l} column${O(l)}`);for(let a=0;a<l;a++)if(!ci(i[a]))throw new At("parse-error",q.LINE,`*Matrix row ${r+1}: "${i[a]}" is not a number`);i.length>l&&this.report.warnOnce("validation-error",q.MATRIX_EXTRA,`*Matrix row ${r+1} has ${i.length} value${O(i.length)} for ${l} column${O(l)}; the extra values are ignored`,{line:n});for(let a=0;a<l;a++){const c=Number(i[a]);if(c===0)continue;const d=this.pushEdge(r,s+a,c,n);this.writeRelation(d)}}objectLine(e,n){const i=this.objects[this.objects.length-1],r=this.tokens(e,"node",n);for(const s of r)if(!ci(s)||i.kind==="partition"&&!Fde(Number(s)))throw i.values.push(null),new At("parse-error",q.LINE,`*${i.kind==="partition"?"Partition":"Vector"} "${i.name}": "${s}" is not ${i.kind==="partition"?"an integer":"a number"}`);for(const s of r)i.values.push(Number(s))}pushEdge(e,n,i,r){const{sink:s}=this;this.directionSet||(this.directionSet=!0,this.resolver.setHeader(this.kind==="directed",{line:r})),this.firstMode!==null&&e<this.firstMode==n<this.firstMode&&this.report.warnOnce("validation-error",q.TWO_MODE_LINE,`a line of the two-mode network joins two vertices of the ${e<this.firstMode?"first":"second"} mode`,{line:r});const o=s.edgeCount,l=this.resolver.addEdge(this.idAt(e),this.idAt(n),this.kind,i,{line:r});return this.report.counts.edges+=s.edgeCount-o,l}writeEdgeExtras(e,n,i){const{sink:r}=this;this.writeRelation(e,i);for(let s=0;s<n.keys.length;s++)this.writeParameter("edge",n.keys[s],e,n.values[s]);n.spells!==null&&(this.edgeSpellsHandle===A&&(this.edgeSpellsHandle=he(r,"edge",jN(),this.report).handle),r.setEdgeValue(this.edgeSpellsHandle,e,n.spells))}writeRelation(e,n=this.relation){n!==null&&(this.relationHandle===A&&(this.relationHandle=he(this.sink,"edge",Gde,this.report).handle),this.sink.setEdgeValue(this.relationHandle,e,n))}endpoint(e){const n=e-this.base;if(n<0||n>=this.vertexCount)throw this.report.counts.skippedEdges++,new At("missing-value",q.UNKNOWN_NODE,`vertex ${e} is outside ${this.base}..${this.base+this.vertexCount-1}`);return n}weightOf(e){try{return Kn(e,this.report)}catch(n){throw this.report.counts.skippedEdges++,n}}tokens(e,n,i){const r={oddQuote:!1},s=vR(e,r);if(r.oddQuote&&this.report.warnOnce("coercion",q.QUOTE_IN_TOKEN,"a double quote inside a token is removed and the parts joined (Pajek has no escape for a quote)",{line:i}),s===null)throw n==="node"?this.report.counts.skippedNodes++:this.report.counts.skippedEdges++,new At("parse-error",q.UNTERMINATED_QUOTE,"a double quote is not closed");return s}extras(e,n,i,r){const s={keys:[],values:[],spells:null,shape:null},o=new Set;for(let l=n;l<e.length;){const a=e[l];if(a.startsWith("[")){s.spells=this.intervals(a,i,r),l++;continue}if(i==="node"&&Um(a)){s.shape=a.toLowerCase(),l++;continue}if(l+1>=e.length){this.loneLastToken(a,i,r);break}o.has(a)&&this.report.warning("merged",q.DUPLICATE_ATTRIBUTE,`parameter ${JSON.stringify(a)} is given twice on one line; the later value ${JSON.stringify(e[l+1])} stands`,{line:r,element:a}),o.add(a),s.keys.push(a);const c=Bde.has(a)?Hde(e,l+1):null;s.values.push(c??e[l+1]),l+=c===null?2:4}return s}loneLastToken(e,n,i){if(ci(e)){this.report.warnOnce("validation-error",q.TRAILING_VALUE,`the number ${JSON.stringify(e)} alone at the end of a row is not a parameter; it is ignored`,{line:i});return}throw this.skip(n),new At("parse-error",n==="node"?q.VERTEX_LINE:q.LINE,`parameter "${e}" has no value`)}intervals(e,n,i){if(!Qae(e))throw this.skip(n),new At("validation-error",q.INTERVAL,`time interval ${e} is not closed by "]"`);try{const r=ece(e);return r.length===0?null:r}catch(r){return this.report.error("validation-error",q.INTERVAL,`${r instanceof Error?r.message:String(r)}; the interval is dropped and the rest of the line kept`,{line:i}),null}}skip(e){e==="node"?this.report.counts.skippedNodes++:this.report.counts.skippedEdges++}writeParameter(e,n,i,r){if(e==="node"&&n===xt&&this.shapeHandle!==A){this.sink.setNodeValue(this.shapeHandle,i,r);return}const s=e==="node"?this.nodeParams:this.edgeParams;let o=s.get(n);o===void 0&&(o=new Sy(n,e,this.sink,this.report),s.set(n,o)),o.write(i,r)}}const Bde=new Set(["ic","bc","lc","c"]);function Hde(t,e){const n=t.slice(e,e+3),i=r=>/^[01]?(?:\.\d+)?$/.test(r)&&r!==""&&Number(r)<=1;return n.length===3&&n.every(i)?n.join(" "):null}function Vde(t,e){if(rL(t,e))return!1;let n=0;for(;1+n<e.length&&ci(e[1+n]);)n++;return n===2}function rL(t,e){return t.trimStart().slice(e[0].length).trimStart().startsWith('"')}function zN(t){if(t===void 0)return"auto";if(Rde.has(t))return t;throw new N("E_UNSUPPORTED",`option firstVertex: ${JSON.stringify(t)??typeof t} is not 0, 1 or "auto"`,{option:"firstVertex",found:t})}function Yde(t){let e=t.trimStart();for(;e.startsWith("%");){const n=e.search(/[\r\n]/);e=n<0?"":e.slice(n).trimStart()}return/^\*(vertices|network)\b/i.exec(e)?.[1].toLowerCase()??null}const sL=Object.freeze({format:"pajek",options:Object.freeze(["firstVertex","pajekDraw"]),extensions:Object.freeze([".net",".paj"]),mimeTypes:Object.freeze(["text/x-pajek","text/plain"]),styles:Uce,positions(t){return t.nodes.byRole("position")!==null?null:{units:"file",pxPerUnit:ss,yAxis:"down",unplacedCircle:{center:[.5,.5],radius:.4,startDegrees:180,direction:1}}},sniff(t){const e=new TextDecoder("utf-8").decode(t),n=Yde(e.startsWith("\uFEFF")?e.slice(1):e);return n===null?0:n==="vertices"?.9:.8},async import(t,e,n){if(io(n))return vb(sL,t,e,n);const i=tt(n,UN),r=zN(n?.firstVertex),s=NN(n?.pajekDraw),o=new ne("pajek",i.errorLimit);_t(e,n,o),St(n,o,MN);const l=new FN(e,o,i,r,s??Bm),a=new jp(t,o,i);let c=null,d=0,u=0;for await(const f of a){const h=WN(f);c!==null?c.line(h):l.line(h,a.line)&&(c=new Kde,c.line(h),d=a.line),++u>=GN&&(u=0,F(i.signal))}if(l.finish(),(s!==null||l.voided.length>0)&&o.keepForStyles({block:l.keptBlock,pajekDraw:s??void 0,voided:l.voided}),c!==null){const f=c.objects>0?`; ${c.objects} *Partition / *Vector object(s) after them are not read`:"";o.warning("unsupported",q.MULTIPLE_GRAPHS,`the project file holds ${c.count} more network${O(c.count)} after the first; the first is read (graphIndex or graphName chooses another; importAllGraphs() reads every one)${f}`,{line:d})}return F(i.signal),o.finish()},async importAll(t,e,n){const i=tt(n,UN),r=zN(n?.firstVertex),s=NN(n?.pajekDraw),o=[new ne("pajek",i.errorLimit)];St(n,o[0],MN);const l=()=>{const f=o[o.length-1],h=e(o.length-1);return _t(h,n,f),new FN(h,f,i,r,s??Bm)},a=f=>{f.finish();const h=o.at(-1);h!==void 0&&(s!==null||f.voided.length>0)&&h.keepForStyles({block:f.keptBlock,pajekDraw:s??void 0,voided:f.voided})};let c=l();const d=new jp(t,o[0],i);let u=0;for await(const f of d){const h=WN(f);c.line(h,d.line)&&(a(c),o.push(new ne("pajek",i.errorLimit)),c=l(),c.line(h,d.line)),++u>=GN&&(u=0,F(i.signal))}return a(c),F(i.signal),o.map(f=>f.finish())}});function WN(t){return t.codePointAt(0)===65279?t.slice(1):t}class Kde{constructor(){this.count=0,this.objects=0,this.named=!1,this.populated=!1,this.afterObjectHeader=!1}line(e){if(kR(e))return;const{afterObjectHeader:n}=this;if(this.afterObjectHeader=!1,!RR(e))return;const i=LR(e);if(i===null)return;const{kind:r}=i;r==="partition"||r==="vector"?(this.afterObjectHeader=!0,this.objects++):r==="unsupported"?this.afterObjectHeader=DR(i.keyword):r==="network"?((this.count===0||this.named||this.populated)&&(this.count++,this.populated=!1),this.named=!0):r==="vertices"&&!n&&((this.count===0||this.populated)&&(this.count++,this.named=!1),this.populated=!0)}}const Xde=String.raw`\n or \t`,oL=Je({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:["string","dict","f64","f32","i32","u32","u8","bool","list"],components:!1,lists:!0,json:!1,defaults:!1,options:!1,hierarchy:!0,temporal:"none",graphAttributes:!0,positions:!0,viz:!1}),qde=new Set(["label","id","parent","parents","position"]),Jde=Object.freeze({label:Ys,id:Qo,parent:cc,position:Tl}),Zde=new Set(["color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen"]),Qde={node:new Set(["id","label","name"]),edge:new Set(["id","label","name","source","target","weight"])},eue=new Set(["directed","pair","mutual","weight","parent","parents","position"]),tue=new Set([Ys,Tl,lo,Qt,cc,Af,Ks,dc,el,Sa]),nue=new Set([Qo,Ys,Qt]),iue={graph:new Set([Qt]),node:tue,edge:nue},rue=new Set(["type","w","h","d","image","bitmap","width","arrow","capstyle","joinstyle","smooth","splinesteps","justify","font","background","foreground","extent","start","style","stipple","visible","fill","outline","anchor"]),lL=2147483647;function Hm(t,e){if(t.meta.components>1)return["string","String"];switch(e){case"bool":return["boolean","Boolean"];case"i32":case"u8":return["integer","Integer"];case"u32":return aL(t)>lL?["integer","Long"]:["integer","Integer"];case"f32":case"f64":return t.meta.origin?.type==="long"&&sue(t)?["integer","Long"]:["real","Double"];default:return["string","String"]}}function sue(t){for(let e=0;e<t.length;e++){if(!t.isSet(e))continue;if(!(t.dtype==="list"?[...t.sliceOf(e)]:[t.value(e)]).every(i=>typeof i=="number"&&Number.isSafeInteger(i)))return!1}return!0}function aL(t){let e=0;for(let n=0;n<t.length;n++){if(!t.isSet(n))continue;const i=t.value(n),r=t.dtype==="list"?[...t.sliceOf(n)]:[i];for(const s of r)typeof s=="number"&&s>e&&(e=s)}return e}function Vl(t,e){const{origin:n}=t.meta;return n!==null&&n.namespace===e}function xp(t,e,n,i){const r=[],s=iue[e],o=e!=="graph"&&(e==="node"?n.nodes:n.edges).byRole("label")!==null;for(const l of t){const{meta:a}=l;if(a.role!==null&&(eue.has(a.role)||Zde.has(a.role)||a.role==="id"||a.role==="timeText"))continue;const c=oue(l,e,o),d=l.length-l.nullCount;c==="att"&&s.has(a.name)?i(w.COLUMN_NAME_CHANGED,`${e} column "${a.name}" is named like a column the XGMML importer owns and reads back renamed`,a.name,d):c==="label"&&a.dtype!=="string"&&a.dtype!=="dict"?i(w.DTYPE,`${e} label column "${a.name}" (${a.dtype}) is written as text and reads back as string`,a.name,d):c==="label"&&a.role===null&&i(w.ROLE_ASSUMED,`${e} column "${a.name}" is written as the label and reads back with the label role`,a.name,d),c==="att"&&due(l,e,i);const u=a.dtype==="list"?a.itemDtype:a.dtype,[f,h]=a.dtype==="list"?["list","List"]:cue(l,Hm(l,u));r.push({column:l,name:a.name,kind:c,type:f,cyType:h,elementType:a.dtype==="list"?Hm(l,u)[1]:null})}return r}function oue(t,e,n){const{meta:i}=t;return e!=="graph"&&aue(t,e)?"xml":i.role==="label"||!n&&e!=="graph"&&i.role===null&&i.name===Ys&&(i.dtype==="string"||i.dtype==="dict")?"label":i.dtype==="json"&&i.name===Qt&&Vl(t,pn)?"graphics":e!=="node"?"att":lue(t)}function lue(t){const{meta:e}=t;return e.name===lo&&e.dtype==="f64"&&e.role===null?"z":e.name===Ks&&e.dtype==="json"&&Vl(t,pn)?"subgraph":e.name===dc&&e.dtype==="string"&&Vl(t,Tf)?"nested":e.name===el&&e.dtype==="string"&&Vl(t,pn)?"pointer":e.name===Sa&&e.dtype==="list"&&Vl(t,pn)?"networks":"att"}function aue(t,e){const{meta:n}=t,{origin:i}=n;return i!==null&&i.format===Ht&&i.type===null&&i.namespace===null&&n.role===null&&n.components===1&&(n.dtype==="string"||n.dtype==="bool"||n.dtype==="i32"||n.dtype==="f64")&&/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(n.name)&&!Qde[e].has(n.name)}function cue(t,e){const{origin:n}=t.meta;return n!==null&&n.format===Ht&&n.type===e[0]&&t.meta.components===1?[e[0],null]:e}function due(t,e,n){const{meta:i}=t,r=t.length-t.nullCount,s=`${e} column "${i.name}"`,o=i.dtype==="list"?i.itemDtype:i.dtype;if(i.dtype==="json"){n(un.JSON_AS_STRING,`${s} holds nested values; they are written as JSON text and read back as strings`,i.name,r);return}if((o==="f32"||o==="u8"||o==="u32")&&n(un.WIDENED_TYPE,`${s} (${o}) is written as a wider Cytoscape type and reads back as ${uue(t,o)}`,i.name,r),o==="string"||o==="dict"){let l=0;for(let a=0;a<t.length;a++)t.isSet(a)&&(t.dtype==="list"?[...t.sliceOf(a)]:[t.value(a)]).some(d=>typeof d=="string"&&/\\[nt]/.test(d))&&l++;l>0&&n(un.BACKSLASH_ESCAPE,`${s}: ${l} value${O(l)} ${C(l,"holds","hold")} a literal ${Xde}, which Cytoscape's escape convention reads back as a newline or tab`,i.name,l)}if(i.dtype==="string"||i.dtype==="dict"){const l=new no;for(let c=0;c<t.length&&!l.decided;c++)t.isSet(c)&&l.observe(t.value(c));const a=l.decide();a!==i.dtype&&n(un.STORAGE_CLASS_CHANGED,`${s} reads back as ${a}: the importer stores text with few distinct values as dict and other text as string; the values are the same`,i.name,null)}}function uue(t,e){return e==="u8"||e==="u32"&&aL(t)<=lL?"i32":"f64"}function cL(t,e,n){const i=Un(t,oL,e,{roles:qde,roleNames:Jde,positionDtype:"f64"}).filter(f=>f.code!==w.JSON),r=(f,h,p=null,g=null)=>{i.push(Object.freeze({code:f,message:h,column:p,count:g}))};i.push(...ky(t));const s=Gt(t);s.mutualCount>0&&r(un.MUTUAL_EXPANDED,`${s.mutualCount} mutual pair${O(s.mutualCount)} ${C(s.mutualCount,"is","are")} written as two directed edges; the mutual mark is lost`,null,s.mutualCount);const o=mue(t);o>0&&r(un.ID_TEXT_TYPE,`${o} numeric node id${O(o)} ${C(o,"is","are")} written as text and read back as strings`,null,o);const l=t.edges.byRole("id");l!==null&&l.dtype!=="string"&&l.dtype!=="dict"&&r(un.EDGE_ID_TEXT,`edge id column "${l.meta.name}" (${l.dtype}) is written as text and reads back as strings`,l.meta.name,null);const a=nc(t);a.unreachable>0&&r(un.PARENT_CYCLE,`${a.unreachable} node${O(a.unreachable)} whose parent chain never reaches a root ${C(a.unreachable,"is","are")} written at the top level and lose their parent`,null,a.unreachable);const c=t.nodes.byRole("parents");c!==null&&t.nodes.byRole("parent")!==null?r(un.PARENTS_DROPPED,`parents column "${c.meta.name}" is not written: the "parent" column is the containment written`,c.meta.name,c.length-c.nullCount):c!==null&&!pue(c)&&r(w.COLUMN_NAME_CHANGED,`parents column "${c.meta.name}" holds one parent per node and reads back as the "parent" column`,c.meta.name,null);const d=t.nodes.byRole("position");d!==null&&gue(d,t,r),fue(t,r);const u=Ot(t);for(const f of t.edges)f.meta.name==="weight"&&f.meta.role===null&&!u.weighted&&r(w.WEIGHT_KEY_CLASH,'edge column "weight" reads back as the edge weight, not as a column',"weight",null);return{options:e,escapes:n,notes:i,graph:xp(t.graph,"graph",t,r),nodes:xp(t.nodes,"node",t,r),edges:xp(t.edges,"edge",t,r),folding:s,weights:u,hierarchy:a,reachable:hue(t.nodeCount,a),position:d,edgeId:l}}function fue(t,e){const n=t.edges.byRole("label")??t.edges.get(Ys);if(n===null||t.edges.get(Jl)!==null)return;let i=0;for(let r=0;r<n.length;r++)n.isSet(r)&&Ig(fl(n.value(r)))!==null&&i++;i>0&&e(un.INTERACTION_FROM_LABEL,`${i} edge label${O(i)} ${C(i,"has","have")} Cytoscape's "a (i) b" shape and read back with an "${Jl}" column`,Jl,i)}function hue(t,e){const n=new Uint8Array(t),i=Array.from(e.roots);for(const r of i)n[r]=1;for(;i.length>0;)for(const r of e.childrenOf(i.pop()))n[r]===0&&(n[r]=1,i.push(r));return n}function pue(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&t.dtype==="list"&&t.sliceOf(e).length>1)return!0;return!1}function gue(t,e,n){const{meta:i}=t;i.components!==3&&n(un.POSITION,`position column "${i.name}" has ${i.components} component${O(i.components)} and reads back with 3`,i.name,null);let r=0,s=0;for(let l=0;l<t.length;l++){if(!t.isSet(l))continue;const a=Array.from(t.value(l));a.slice(0,2).some(c=>!Number.isFinite(c))?r++:(a[2]??0)!==0&&s++}r>0&&n(un.POSITION,`${r} position${O(r)} with a non-finite coordinate ${C(r,"is","are")} not written`,i.name,r);const o=e.nodes.get(lo);s>0&&n(un.POSITION,o===null?`${s} position${O(s)} ${C(s,"has","have")} a z; it is written as graphics z and reads back in the z column (zAs: "position" reads it as a coordinate)`:`${s} position${O(s)} ${C(s,"has","have")} a z, but graphics z holds the z column; the position z is lost`,i.name,s)}function mue(t){let e=0;for(let n=0;n<t.nodeCount;n++)typeof t.ids.idOf(n)=="number"&&e++;return e}function Fd(t,e){return e===null?"":` ${t}="${e}"`}function Vm(t){return t.map(([e,n])=>` ${e}="${W(String(n))}"`).join("")}function BN(t,e,n){let i;return typeof t=="boolean"?i=t?"1":"0":typeof t=="number"?i=e==="f32"?ct(t):Fe(t):typeof t=="string"?i=n?t.replaceAll(`
|
|
210
|
+
`,String.raw`\n`).replaceAll(" ",String.raw`\t`):t:ArrayBuffer.isView(t)?i=JSON.stringify(Array.from(t)):i=JSON.stringify(t)??"",W(i)}function fl(t){return typeof t=="string"?t:typeof t=="number"?Fe(t):typeof t=="boolean"?t?"true":"false":JSON.stringify(t)??""}function dL(t,e){let n="";for(const i of t)i.kind==="xml"&&i.column.isSet(e)&&(n+=` ${i.name}="${W(fl(i.column.value(e)))}"`);return n}function*z0(t,e,n,i,r){for(const s of t){if(s.kind!=="att")continue;const{column:o}=s,l=o.isSet(e);if(!l&&!(n&&o.nullCount===o.length))continue;const a=`${r}<att name="${W(s.name)}"`,c=Fd("type",s.type)+Fd("cy:type",s.cyType),d=`${o.meta.extra.hidden===!0?' cy:hidden="1"':""}${o.meta.extra.equation===!0?' cy:equation="1"':""}`;if(!l){yield`${a}${c}${Fd("cy:elementType",s.elementType)}${d}/>
|
|
211
|
+
`;continue}if(o.dtype==="list"){const u=[...o.sliceOf(e)],[f,h]=Hm(o,o.meta.itemDtype);if(yield`${a}${c} cy:elementType="${s.elementType??"String"}"${d}${u.length===0?"/>":">"}
|
|
212
|
+
`,u.length>0){for(const p of u)yield`${r} <att name="${W(s.name)}" value="${BN(p,o.meta.itemDtype,i.escapes)}" type="${f}" cy:type="${h}"/>
|
|
213
|
+
`;yield`${r}</att>
|
|
214
|
+
`}continue}yield`${a} value="${BN(o.value(e),o.dtype,i.escapes)}"${c}${d}/>
|
|
215
|
+
`}}function*W0(t,e,n){const i=[...e],r=[];for(const[o,l]of Object.entries(t??{}))o==="Line"?r.push([o,l]):typeof l=="string"&&(rue.has(o)||o.startsWith("cy:"))?i.push([o,l]):r.push([o,l]);if(i.length===0&&r.length===0)return;const s=`${n}<graphics${Vm(i)}`;if(r.length===0){yield`${s}/>
|
|
216
|
+
`;return}yield`${s}>
|
|
217
|
+
`;for(const[o,l]of r)if(o==="Line"&&Array.isArray(l)){yield`${n} <Line>
|
|
218
|
+
`;for(const a of l){const c=typeof a=="object"&&a!==null?Object.entries(a):[];yield`${n} <point${Vm(c)}/>
|
|
219
|
+
`}yield`${n} </Line>
|
|
220
|
+
`}else yield*Wu(o,l,`${n} `);yield`${n}</graphics>
|
|
221
|
+
`}function*Wu(t,e,n){const i=t===null?"":` name="${W(t)}"`;if(Array.isArray(e)){yield`${n}<att${i} type="list">
|
|
222
|
+
`;for(const r of e)yield*Wu(t,r,`${n} `);yield`${n}</att>
|
|
223
|
+
`}else if(typeof e=="object"&&e!==null){const r=Object.entries(e);if(t!==null&&r.every(([,s])=>typeof s=="string")&&r.length<=3&&r.every(([s])=>/^[a-z]$/.test(s))){yield`${n}<att${i}${Vm(r)}/>
|
|
224
|
+
`;return}yield`${n}<att${i}>
|
|
225
|
+
`;for(const[s,o]of r)yield*Wu(s,o,`${n} `);yield`${n}</att>
|
|
226
|
+
`}else e==null?yield`${n}<att${i} type="string"/>
|
|
227
|
+
`:yield`${n}<att${i} value="${W(fl(e))}" type="string"/>
|
|
228
|
+
`}function ki(t,e){return t.find(n=>n.kind===e)?.column??null}function Ei(t,e){return t?.isSet(e)?t.value(e):null}function yue(t,e,n){const i=bue(t,e,n),r=Ei(e,n);return typeof r=="number"&&i.push(["z",Fe(r)]),i}function bue(t,e,n){const i=Ei(t.position,n);if(i===null)return[];const[r,s,o]=Array.from(i);if(!Number.isFinite(r)||!Number.isFinite(s))return[];const l=t.position?.dtype==="f32"?ct:Fe,a=[["x",l(r)],["y",l(s===0?0:-s)]];return e===null&&o!==void 0&&o!==0&&Number.isFinite(o)&&a.push(["z",l(o)]),a}function*Eue(t,e,n,i){yield`${i}<att name="__isGroup" value="1" type="boolean" cy:type="Boolean" cy:hidden="1"/>
|
|
229
|
+
`;const r=typeof e.id=="string"?` id="${W(e.id)}"`:"",s=typeof e.label=="string"?` label="${W(e.label)}"`:"";yield`${i}<att>
|
|
230
|
+
${i} <graph${r}${s}>
|
|
231
|
+
`;const o=typeof e.atts=="object"&&e.atts!==null?Object.entries(e.atts):[];for(const[l,a]of o)yield*Wu(l,a,`${i} `);for(const l of n)yield`${i} <node xlink:href="#${W(Hi(t.ids.idOf(l)))}"/>
|
|
232
|
+
`;yield`${i} </graph>
|
|
233
|
+
${i}</att>
|
|
234
|
+
`}function*wue(t,e,n,i,r){const s=ki(e.nodes,"label"),o=Ei(s,n),l=o===null?"":` label="${W(fl(o))}"`;yield`${i}<node id="${W(Hi(t.ids.idOf(n)))}"${l}${dL(e.nodes,n)}>
|
|
235
|
+
`;const a=`${i} `;yield*z0(e.nodes,n,n===0,e,a);const c=e.reachable[n]===1?e.hierarchy.childrenOf(n):[],d=Ei(ki(e.nodes,"nested"),n),u=Ei(ki(e.nodes,"pointer"),n),f=Ei(ki(e.nodes,"subgraph"),n);c.length>0||f!==null?yield*Eue(t,f??{},c,a):typeof d=="string"?yield`${a}<att>
|
|
236
|
+
${a} <graph label="${W(d)}"/>
|
|
237
|
+
${a}</att>
|
|
238
|
+
`:typeof u=="string"&&(yield`${a}<att>
|
|
239
|
+
${a} <graph xlink:href="${W(u)}"/>
|
|
240
|
+
${a}</att>
|
|
241
|
+
`);const h=Ei(ki(e.nodes,"graphics"),n),p=r===void 0?h:II("node",r,n,h);yield*W0(p,yue(e,ki(e.nodes,"z"),n),a),yield`${i}</node>
|
|
242
|
+
`}function*HN(t,e){const n=Nue(t,e),i=e?.styles,r=t.meta.extra[EI],s=typeof r?.graphId=="string"?` id="${W(r.graphId)}"`:"",o=(r?.directed==="0"||r?.directed==="1")&&t.edgeCount>0&&t.edges.byRole("directed")===null;let l=t.directed?"1":"0";o&&(l=r?.directed);const a=t.meta.name===null?"":` label="${W(t.meta.name)}"`;yield`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
243
|
+
`,yield`<graph${s}${a} directed="${l}" cy:documentVersion="3.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="${sb}" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cy="${bI}" xmlns="${_a}">
|
|
244
|
+
`,yield*_ue(t),yield*z0(n.graph,0,!0,n," ");const c=Ei(ki(n.graph,"graphics"),0);yield*W0(i===void 0?c:TG(i,c),[]," ");for(let d=0;d<t.nodeCount;d++)yield*wue(t,n,d," ",i);yield*Sue(t,n),yield*Oue(t,n,i),yield`</graph>
|
|
245
|
+
`}function*_ue(t){const{name:e,description:n,created:i}=t.meta;n===null&&i===null||(yield` <att name="networkMetadata">
|
|
246
|
+
<rdf:RDF>
|
|
247
|
+
<rdf:Description rdf:about="http://www.cytoscape.org/">
|
|
248
|
+
`,e!==null&&(yield` <dc:title>${nt(e)}</dc:title>
|
|
249
|
+
`),n!==null&&(yield` <dc:description>${nt(n)}</dc:description>
|
|
250
|
+
`),i!==null&&(yield` <dc:date>${nt(i)}</dc:date>
|
|
251
|
+
`),yield` </rdf:Description>
|
|
252
|
+
</rdf:RDF>
|
|
253
|
+
</att>
|
|
254
|
+
`)}function*Sue(t,e){const n=ki(e.nodes,"networks");if(n?.dtype!=="list")return;const i=new Map;for(let r=0;r<t.nodeCount;r++)for(const s of n.isSet(r)?n.sliceOf(r):[]){const o=i.get(String(s))??[];o.push(r),i.set(String(s),o)}for(const[r,s]of i){yield` <att>
|
|
255
|
+
<graph id="${W(r)}">
|
|
256
|
+
`;for(const o of s)yield` <node xlink:href="#${W(Hi(t.ids.idOf(o)))}"/>
|
|
257
|
+
`;yield` </graph>
|
|
258
|
+
</att>
|
|
259
|
+
`}}function*Oue(t,e,n){const{folding:i,weights:r}=e,s=ki(e.edges,"label"),o=ki(e.edges,"graphics"),l=t.edgeList();let a=!0;for(let c=0;c<t.edgeCount;c++){if(i.folded(c))continue;const d=l.src[c],u=l.dst[c],f=t.directed&&i.sourceDirected(c),h=Ei(e.edgeId,c),p=Ei(s,c),g=r.text(c),m=h===null?"":` id="${W(fl(h))}"`,y=p===null?"":` label="${W(fl(p))}"`,b=W(Hi(t.ids.idOf(d))),_=W(Hi(t.ids.idOf(u)));yield` <edge${m}${y} source="${b}" target="${_}" cy:directed="${f?"1":"0"}"${Fd("weight",g)}${dL(e.edges,c)}>
|
|
260
|
+
`,yield*z0(e.edges,c,a,e," ");const S=Ei(o,c);yield*W0(n===void 0?S:II("edge",n,c,S),[]," "),yield` </edge>
|
|
261
|
+
`,a=!1}}function uL(t){const e=t?.cytoscapeEscapes??!1;if(typeof e!="boolean")throw new N("E_UNSUPPORTED","option cytoscapeEscapes must be a boolean",{option:"cytoscapeEscapes",found:typeof e});return e}function Nue(t,e){const n=cL(t,ft(e),uL(e)),i=n.notes.find(r=>r.code===un.XML_ILLEGAL_CHAR);if(i!==void 0)throw new N("E_COLUMN_TYPE",i.message,{code:i.code,column:i.column});return n}const Aue=Object.freeze({format:Ht,options:Object.freeze(["cytoscapeEscapes"]),capabilities:oL,styles:Object.freeze({capabilities:TI}),check:(t,e)=>Object.freeze([...cL(t,ft(e),uL(e)).notes,...e?.styles===void 0?[]:AG(e.styles,t)]),export:(t,e)=>ti(HN(t,e)),exportToString:(t,e)=>ni(HN(t,e))}),B0=[{name:"query",plainName:"Query",type:"query",language:"cypher"},{name:"mode",plainName:"Mode",type:"enum",values:[{value:"query",label:"Query"},{value:"all",label:"Everything"},{value:"neighborhood",label:"Neighborhood"}]},{name:"ids",plainName:"Seed ids",type:"node-id"},{name:"depth",plainName:"Depth",type:"integer",default:1,min:1,max:10},{name:"labels",plainName:"Labels",type:"string",role:"filter",advanced:!0},{name:"relationshipTypes",plainName:"Relationship types",type:"string",role:"filter",advanced:!0},{name:"idProperty",plainName:"Id property",type:"string",advanced:!0},{name:"database",plainName:"Database",type:"string"},{name:"long",plainName:"Large integers",type:"enum",advanced:!0,values:[{value:"f64",label:"Number"},{value:"string",label:"Text"}]},{name:"countFirst",plainName:"Count first",type:"boolean",advanced:!0},{name:"pageSize",plainName:"Page size",type:"integer",default:1e3,min:1,max:1e5,advanced:!0}],H0=["expand","probe","validate","page"],Ja={name:"transport",plainName:"Transport",type:"enum",values:[{value:"query-api",label:"Neo4j Query API"},{value:"bolt",label:"Bolt"},{value:"neptune-https",label:"Neptune Database"},{value:"neptune-analytics",label:"Neptune Analytics"}]},Tue=Object.freeze({plainName:"Cypher database",kind:"database",version:1,auth:["basic","bearer","aws-sigv4"],authRequired:"optional",features:H0,params:[...B0,Ja]}),Iue=Object.freeze({plainName:"Neo4j",kind:"database",version:1,auth:["basic","bearer"],authRequired:"optional",features:H0,params:[...B0,{...Ja,values:Ja.values?.filter(t=>t.value==="query-api"||t.value==="bolt")}],samples:[{id:"neo4j-movies",plainName:"Neo4j demo: movies",endpoint:"https://demo.neo4jlabs.com:7473",params:{database:"movies",mode:"all"},publicLogin:{username:"movies",password:"movies"},counts:{nodes:171,edges:253}},{id:"hetionet",plainName:"Hetionet",endpoint:"bolt+s://neo4j.het.io:7687",params:{transport:"bolt",mode:"neighborhood",idProperty:"name",ids:["Metformin"],depth:1},counts:{nodes:47031,edges:2250197},whole:!1}]}),$ue=Object.freeze({plainName:"Amazon Neptune",kind:"database",version:1,auth:["aws-sigv4"],authRequired:"optional",features:H0,params:[...B0,{...Ja,values:Ja.values?.filter(t=>t.value.startsWith("neptune"))}],runtimes:{browser:{supported:!1,reason:"cors"},worker:{supported:!1,reason:"cors"}}}),age=Object.freeze({E_FETCH:bA,E_SOURCE_BLOCKED:"E_SOURCE_BLOCKED",E_SOURCE_AUTH:"E_SOURCE_AUTH",E_SOURCE_FORBIDDEN:"E_SOURCE_FORBIDDEN",E_SOURCE_NOT_FOUND:"E_SOURCE_NOT_FOUND",E_SOURCE_QUOTA:"E_SOURCE_QUOTA",E_SOURCE_TIMEOUT:"E_SOURCE_TIMEOUT",E_SOURCE_QUERY:"E_SOURCE_QUERY",E_SOURCE_NOT_A_GRAPH:"E_SOURCE_NOT_A_GRAPH",E_SOURCE_RESPONSE:"E_SOURCE_RESPONSE",E_SOURCE_REDIRECT:"E_SOURCE_REDIRECT",E_SOURCE_RUNTIME:"E_SOURCE_RUNTIME",E_SOURCE_PARAM:"E_SOURCE_PARAM",E_SOURCE_LIMIT:"E_SOURCE_LIMIT",E_SOURCE_UNKNOWN:"E_SOURCE_UNKNOWN",E_SOURCE_UNSUPPORTED:"E_SOURCE_UNSUPPORTED",E_SOURCE_INVALID:"E_SOURCE_INVALID",W_SOURCE_LIMIT:"W_SOURCE_LIMIT",W_SOURCE_AUTH:"W_SOURCE_AUTH",W_SOURCE_RETRIED:"W_SOURCE_RETRIED",W_SOURCE_VALUE:"W_SOURCE_VALUE"}),Cue="ndex",vue="cypher",Due="neo4j",kue="neptune",Rue="rest",Lue="openalex",Pue="sparql",cge="_source.stub",dge="_source.entity",uge="_source.degree",xue="source:",Mue={E_SOURCE_PARAM:"validation-error",E_SOURCE_INVALID:"validation-error",E_SOURCE_RESPONSE:"parse-error",E_SOURCE_NOT_A_GRAPH:"parse-error",E_SOURCE_NOT_FOUND:"missing-value",E_SOURCE_UNKNOWN:"missing-value"};function we(t,e,n,i){return t.fork().failWith(Mue[e]??"unsupported",e,n,void 0,i,i)}function ua(t,e,n,i="source"){we(new ne(i,0),t,e,n)}function Ym(t,e,n,i){t.warning("unsupported",e,n,void 0,i)}const Uue=/^[a-z0-9]+(-[a-z0-9]+)*$/,Gue=[["expand","expand"],["probe","probe"],["list","list"],["validate","validate"]];function Bu(t,e,n){ua("E_SOURCE_INVALID",n,{id:t,reason:e})}function fL(t){(typeof t!="string"||!Uue.test(t))&&Bu(String(t),"id",`source id ${JSON.stringify(t)} must be lowercase letters, digits and dashes`)}function jue(t){return Gue.filter(([,e])=>typeof t[e]=="function").map(([e])=>e)}function zd(t,e){fL(t.id),["records","file","import"].filter(r=>typeof t[r]=="function").length!==1&&Bu(t.id,"read-methods",`source ${t.id} must have exactly one of records, file and import`);const i=(e??t.descriptor)?.features;if(i!==void 0){const r=new Set(jue(t));for(const s of i)s!=="page"&&!r.has(s)&&Bu(t.id,"features",`source ${t.id} declares ${s} but has no ${s} method`)}}function Fue(t){fL(t.id),(typeof t.load!="function"||typeof t.descriptor!="object")&&Bu(t.id,"lazy",`lazy source ${t.id} needs a descriptor and a load function`)}function fge(t){return zd(t),t}function zue(t,e){return typeof e!="number"||Number.isNaN(e)||t.type==="integer"&&!Number.isInteger(e)?"type":t.min!==void 0&&e<t.min||t.max!==void 0&&e>t.max?"range":null}function Wue(t){let e;try{e=new URL(typeof t=="string"?t:"")}catch{return"type"}return e.username!==""||e.password!==""?"credentials-in-url":null}function Bue(t,e){switch(t.type){case"integer":case"number":return zue(t,e);case"boolean":return typeof e=="boolean"?null:"type";case"enum":return t.values!==void 0&&!t.values.some(n=>n.value===e)?"enum":null;case"url":return Wue(e);default:return null}}function Hue(t,e,n){(typeof t!="object"||t===null)&&we(n,"E_SOURCE_PARAM","params must be an object",{name:"params",reason:"type"});for(const i of e?.params??[]){const r=t[i.name],s=r==null;let o=null;s?i.required===!0&&i.default===void 0&&(o="required"):o=Bue(i,r),o!==null&&we(n,"E_SOURCE_PARAM",`parameter ${i.name}: ${o}`,{name:i.name,reason:o})}}const Vue=new WeakMap;function Wn(t){return`${t.protocol}//${t.host}`}function Yue(t){let e="";for(const n of new TextEncoder().encode(t))e+=String.fromCodePoint(n);return btoa(e)}function V0(t){return Vue.get(t)}function Kue(t){const e=V0(t);return e?.kind==="api-key"&&e.header===null?e.query??"api_key":null}async function Xue(t,e){const n=V0(t);if(n===void 0)return ua("E_SOURCE_PARAM","the credential was not made by the credentials factories",{name:"credential",reason:"type"});switch(n.kind){case"bearer":{const i=typeof n.token=="string"?n.token:await n.token(),r=new Headers(e.headers);return r.set("Authorization",`Bearer ${i}`),new Request(e,{headers:r})}case"basic":{const i=new Headers(e.headers),r=`${n.username}:${n.password}`;return i.set("Authorization",`Basic ${Yue(r)}`),new Request(e,{headers:i})}case"api-key":{if(n.header!==null){const r=new Headers(e.headers);return r.set(n.header,n.value),new Request(e,{headers:r})}const i=new URL(e.url);return i.searchParams.set(n.query??"api_key",n.value),new Request(i,e)}case"aws-sigv4":{const{signRequest:i}=await xr(async()=>{const{signRequest:r}=await import("./sigv4-BXwVbza3-DZCCNyQA.js");return{signRequest:r}},[],import.meta.url);return i(e,n.options)}case"custom":return n.apply(e);default:return e}}function hge(t){const e=V0(t);return e?.kind==="basic"?{kind:"basic",username:e.username,password:e.password}:e?.kind==="bearer"?{kind:"bearer",token:e.token}:e===void 0?void 0:{kind:t.kind}}function ms(t,e,n,i,r){return{id:t,plainName:e,params:{uuid:n},counts:{nodes:i,edges:r}}}const que=Object.freeze({plainName:"NDEx",kind:"repository",version:1,defaultEndpoint:"https://www.ndexbio.org/",auth:["basic","bearer","api-key"],authRequired:"optional",rateLimit:{requests:50,perMs:1e3,concurrent:4},params:[{name:"uuid",plainName:"Network UUID",type:"string",required:!0},{name:"format",plainName:"Format",type:"enum",default:"cx2",advanced:!0,values:[{value:"cx2",label:"CX2"},{value:"cx",label:"CX"}]},{name:"idAttribute",plainName:"Id attribute",type:"string",advanced:!0}],features:["probe","list","expand","validate"],samples:[ms("ndex-wp5483","WikiPathways WP5483","86719f5b-1439-11f0-9806-005056ae3c32",57,34),ms("ndex-nci-pid","NCI PID cancer signaling","640e2cef-795d-11e8-a4bf-0ac135e8bacf",2794,25296),ms("ndex-huri","HuRI human interactome","73bc2c06-5fb2-11e9-9f06-0ac135e8bacf",8275,52569),ms("ndex-signor","Signor","523fff27-afe8-11e9-8bb4-0ac135e8bacf",10339,33381),ms("ndex-dgidb","DGIdb drugs and target genes","7e5e64ff-f6cf-11ea-99da-0ac135e8bacf",12100,32814),ms("ndex-wikipathways-landscape","WikiPathways landscape","2b3ed6af-5031-11eb-9e72-0ac135e8bacf",32077,74109),{...ms("ndex-pcnet","PCNet 2.2","8b4b54fa-e87d-11ee-9621-005056ae23aa",18558,3323928),whole:!1}]}),VN=Object.freeze({version:1,endpoint:"https://api.deps.dev",load:"dependencies",directed:!0,requests:{dependencies:{path:"/v3/systems/{system}/packages/{package}/versions/{version}:dependencies",records:".",entity:"graph"}},entities:{graph:{id:"nodes",node:!1,edges:[{each:"edges[]",from:"fromNode",to:"toNode",type:"depends_on",entity:"package",fields:{requirement:"requirement"}}],embedded:[{at:"nodes[]",entity:"package"}]},package:{id:"#",fields:{name:"versionKey.name",version:"versionKey.version",system:"versionKey.system",relation:"relation"}}}}),YN=Object.freeze({version:1,endpoint:"https://string-db.org",load:"network",directed:!1,requests:{network:{path:"/api/json/network",query:{identifiers:"{identifiers}",species:"{species}",add_nodes:"{add_nodes}"},records:".",entity:"interaction"}},entities:{interaction:{id:"stringId_A",node:!1,edges:[{from:"stringId_A",to:"stringId_B",type:"interacts_with",entity:"protein-b",fields:{score:"score"}}],embedded:[{at:".",entity:"protein-a"},{at:".",entity:"protein-b"}]},"protein-a":{id:"stringId_A",label:"protein",fields:{name:"preferredName_A"}},"protein-b":{id:"stringId_B",label:"protein",fields:{name:"preferredName_B"}}}}),Jue=Object.freeze({plainName:"REST API",kind:"rest",version:1,auth:["bearer","api-key"],authRequired:"optional",features:["expand","probe","validate","page"],params:[{name:"mapping",plainName:"Mapping",type:"text",required:!0}],samples:[{id:"string-tp53",plainName:"STRING: TP53's functional partners",params:{mapping:YN,identifiers:"TP53",species:"9606",add_nodes:"20"},endpoint:YN.endpoint,counts:{nodes:21,edges:113}},{id:"deps-dev-webpack",plainName:"deps.dev: webpack 5.90.0",params:{mapping:VN,system:"npm",package:"webpack",version:"5.90.0"},endpoint:VN.endpoint,counts:{nodes:84,edges:121}}]}),Zue=Object.freeze({plainName:"OpenAlex",kind:"rest",version:1,defaultEndpoint:"https://api.openalex.org",auth:["api-key"],authRequired:"optional",credentials:[{name:"api_key",kind:"api-key",required:!1,plainName:"API key",send:{query:"api_key"}}],apiKey:{query:"api_key"},rateLimit:{requests:10,perMs:1e3},features:["expand","probe","validate","page"],params:[{name:"work",plainName:"Work",type:"string"},{name:"author",plainName:"Author",type:"string"},{name:"graph",plainName:"Graph",type:"enum",default:"citation",values:[{value:"citation",label:"Citations"},{value:"coauthorship",label:"Co-authors"}]},{name:"include",plainName:"Include",type:"string",advanced:!0}],samples:[{id:"openalex-watts-strogatz",plainName:"Watts-Strogatz paper's citations",params:{work:"W2112090702"},whole:!1,firstPage:200}]}),Que=`PREFIX wd: <http://www.wikidata.org/entity/>
|
|
262
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
263
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
264
|
+
CONSTRUCT { ?person wdt:P184 ?advisor . ?person rdfs:label ?name . ?advisor rdfs:label ?advisorName . }
|
|
265
|
+
WHERE {
|
|
266
|
+
?person wdt:P166 wd:Q38104 ; wdt:P184 ?advisor ; rdfs:label ?name .
|
|
267
|
+
?advisor rdfs:label ?advisorName .
|
|
268
|
+
FILTER(lang(?name) = "en" && lang(?advisorName) = "en")
|
|
269
|
+
}`,efe=Object.freeze({plainName:"SPARQL endpoint",kind:"sparql",version:1,auth:["basic","bearer"],authRequired:"optional",features:["expand","probe","validate","page"],params:[{name:"query",plainName:"Query",type:"query",language:"sparql"},{name:"mode",plainName:"Mode",type:"enum",values:[{value:"query",label:"Query"},{value:"all",label:"Everything"},{value:"neighborhood",label:"Seed nodes"}]},{name:"ids",plainName:"Seed IRIs",type:"node-id"},{name:"language",plainName:"Language",type:"string",advanced:!0},{name:"predicates",plainName:"Follow predicates",type:"string",advanced:!0},{name:"pageSize",plainName:"Page size",type:"integer",default:1e3,min:1,max:1e4,advanced:!0}],samples:[{id:"wikidata-physics-advisors",plainName:"Wikidata: physics Nobel laureates and their advisors",endpoint:"https://query.wikidata.org/sparql",params:{query:Que,pageSize:100,language:"en",predicates:["http://www.wikidata.org/prop/direct/"]}}]}),tfe=new Set([429,502,503,504]),nfe=new Set([101,204,205,304]),ife=new Set([301,302,303,307,308]),rfe=5;class Za extends Error{constructor(e,n){super(`${e} reached at ${String(n)}`),this.limit=e,this.value=n,this.name="LimitStop"}}function hL(){const t=globalThis;return typeof t.process?.versions?.node=="string"?"node":typeof t.importScripts=="function"?"worker":t.window!==void 0&&t.document!==void 0?"browser":"other"}function Fn(t){return`${Wn(t)}${t.pathname}`}function Km(t){const e=t.replaceAll(/(?:^\[)|(?:\]$)/g,"").toLowerCase();return e==="localhost"||e.endsWith(".localhost")||/^127(\.\d{1,3}){3}$/.test(e)||e==="::1"}function KN(t){const e=t.replaceAll(/(?:^\[)|(?:\]$)/g,"").toLowerCase();return Km(e)||e.endsWith(".local")||/^10(\.\d{1,3}){3}$/.test(e)||/^192\.168(\.\d{1,3}){2}$/.test(e)||/^169\.254(\.\d{1,3}){2}$/.test(e)||/^172\.(1[6-9]|2\d|3[01])(\.\d{1,3}){2}$/.test(e)||/^f[cd][0-9a-f]{2}:/.test(e)||e.startsWith("fe80:")}const XN=new Map;function ad(t,e){return new Promise((n,i)=>{if(e.aborted){i(e.reason);return}const r=()=>{clearTimeout(s),i(e.reason)},s=setTimeout(()=>{e.removeEventListener("abort",r),n()},t);e.addEventListener("abort",r,{once:!0})})}function qN(t){const e=t.headers.get("retry-after");if(e===null)return null;const n=Number(e);if(Number.isFinite(n))return Math.max(0,n*1e3);const i=Date.parse(e);return Number.isNaN(i)?null:Math.max(0,i-Date.now())}function sfe(t,e){return t===void 0?[]:t.origins.length>0?t.origins:e===null?[]:[Wn(e)]}class ofe{constructor(e){this.input=e,this.state={requests:0,bytes:0,finish:null},this.controller=new AbortController,this.warnedLimits=new Set,this.onCallerAbort=()=>{this.controller.abort(this.input.options.signal?.reason)};const{options:n,endpoint:i}=e;this.runtime=e.runtime??hL(),this.fetchImpl=n.fetch??((...l)=>globalThis.fetch(...l)),this.limitOptions=n.limits??{};const r=n.retry===!1?{retries:0}:n.retry??{};this.retry={retries:r.retries??3,baseDelayMs:r.baseDelayMs??500,maxDelayMs:r.maxDelayMs??3e4},this.credentialOrigins=sfe(n.credential,i);const s=n.signal;s?.aborted===!0?this.controller.abort(s.reason):s?.addEventListener("abort",this.onCallerAbort,{once:!0});const{timeoutMs:o}=this.limitOptions;this.timer=o===void 0?void 0:setTimeout(()=>{this.timeOut(o)},o),this.signal=this.controller.signal}dispose(){clearTimeout(this.timer),this.input.options.signal?.removeEventListener("abort",this.onCallerAbort)}timeOut(e){try{we(this.input.report,"E_SOURCE_TIMEOUT",`the load ran longer than ${String(e)} ms`,{timeoutMs:e,serverSide:!1})}catch(n){this.controller.abort(n)}}limitHit(e,n){const{report:i}=this.input;throw(this.limitOptions.onLimit??"stop")==="error"&&we(i,"E_SOURCE_LIMIT",`${e} of ${String(n)} reached`,{limit:e,value:n}),this.warnedLimits.has(e)||(this.warnedLimits.add(e),Ym(i,"W_SOURCE_LIMIT",`${e} reached at ${String(n)}; what came first is kept`,{limit:e,value:n})),new Za(e,n)}reached(){const{nodes:e,edges:n}=this.input.counts(),r=[["maxNodes",e,this.limitOptions.maxNodes],["maxEdges",n,this.limitOptions.maxEdges],["maxBytes",this.state.bytes,this.limitOptions.maxBytes],["maxRequests",this.state.requests,this.limitOptions.maxRequests]].find(([,s,o])=>o!==void 0&&s>=o);if(r===void 0)return!1;try{this.limitHit(r[0],r[1])}catch(s){if(!(s instanceof Za))throw s}return!0}progress(e,n,i="items"){i==="bytes"&&(this.byteTotal=n),this.input.options.onProgress?.(e,n,i)}resolve(e){const{report:n,endpoint:i}=this.input;let r;try{r=i===null?new URL(e):new URL(e,i)}catch{return we(n,"E_SOURCE_PARAM","a relative URL needs an endpoint",{name:"endpoint",reason:"missing"})}(r.username!==""||r.password!=="")&&we(n,"E_SOURCE_PARAM","a URL may not carry a user name or password",{name:"endpoint",reason:"credentials-in-url"});const s=globalThis.location,o=r.protocol==="http:"||r.protocol==="ws:";return this.runtime==="browser"&&s?.protocol==="https:"&&o&&!Km(r.hostname)&&we(n,"E_SOURCE_RUNTIME","an https page cannot reach a plain http endpoint",{runtime:this.runtime,reason:"insecure-endpoint"}),r}async pace(e){const n=this.input.descriptor?.rateLimit;if(n===void 0)return()=>{};const i=`${this.input.id} ${Wn(e)}`,r=XN.get(i)??{active:0,times:[],waiters:[]};for(XN.set(i,r);;){const s=Date.now();if(r.times=r.times.filter(o=>s-o<n.perMs),n.concurrent!==void 0&&r.active>=n.concurrent)await new Promise(o=>r.waiters.push(o));else if(r.times.length>=n.requests)await ad(Math.max(1,n.perMs-(s-r.times[0])),this.signal);else return r.times.push(s),r.active++,()=>{r.active--,r.waiters.shift()?.()}}}counted(e){if(e.body===null||nfe.has(e.status))return e;const n=new TransformStream({transform:(i,r)=>{this.state.bytes+=i.byteLength;const s=this.limitOptions.maxBytes;s!==void 0&&this.state.bytes>s&&this.limitHit("maxBytes",this.state.bytes),this.input.unit==="bytes"&&this.input.options.onProgress?.(this.state.bytes,this.byteTotal,"bytes"),r.enqueue(i)}});return new Response(e.body.pipeThrough(n),{status:e.status,statusText:e.statusText,headers:e.headers})}async statusFailure(e,n){await e.body?.cancel().catch(()=>{});const{report:i}=this.input,{status:r}=e,s=Fn(n);switch(r){case 401:return we(i,"E_SOURCE_AUTH",`${s} answered 401`,{origin:Wn(n),status:r,scheme:e.headers.get("www-authenticate")?.split(/\s/)[0]??null,serverCode:null});case 403:return we(i,"E_SOURCE_FORBIDDEN",`${s} answered 403`,{status:r,serverCode:null});case 404:return we(i,"E_SOURCE_NOT_FOUND",`${s} answered 404`,{what:"url",value:s});case 429:return we(i,"E_SOURCE_QUOTA",`${s} answered 429`,{retryAfterMs:qN(e)});default:return we(i,"E_FETCH",`${s} answered ${String(r)}`,{url:s,status:r})}}async request(e,n,i){const{options:r,report:s}=this.input,o=new Headers(n.headers);r.userAgent!==void 0&&this.runtime==="node"&&o.set("User-Agent",r.userAgent);const{retry:l,idempotent:a,allowStatus:c,...d}=n,u={cache:"no-store",credentials:"omit",redirect:this.runtime==="browser"?"error":"manual"},f=new Request(e,{...d,headers:o,signal:this.signal,...i?u:{}});if(!i||r.credential===void 0)return f;const h=await Xue(r.credential,f),p=new URL(h.url);return Wn(p)!==Wn(e)&&we(s,"E_SOURCE_REDIRECT","the credential changed the request's origin",{from:Fn(e),to:Fn(p)}),h}async send(e,n,i){const{options:r,report:s}=this.input,o=r.credential!==void 0&&this.credentialOrigins.includes(Wn(e)),l=e.protocol==="http:"||e.protocol==="ws:";o&&l&&!Km(e.hostname)&&r.allowInsecure!==!0&&we(s,"E_SOURCE_PARAM","a credential is never sent without TLS",{name:"endpoint",reason:"insecure-endpoint"});const a=await this.request(e,n,o);this.state.requests++;const c=await this.fetchImpl(a);if(!o||!ife.has(c.status))return c;const d=c.headers.get("location");await c.body?.cancel().catch(()=>{});const u=d===null?null:new URL(d,e);return u===null||Wn(u)!==Wn(e)||i>=rfe?we(s,"E_SOURCE_REDIRECT","a redirect while a credential was attached",{from:Fn(e),to:u===null?null:Fn(u)}):this.send(u,c.status===303?{...n,method:"GET",body:null}:n,i+1)}async redirects(e){if(this.input.options.retry===!1)return!1;try{const n=await this.fetchImpl(e,{method:"GET",redirect:"manual",credentials:"omit",cache:"no-store",signal:this.signal});return await n.body?.cancel().catch(()=>{}),n.type==="opaqueredirect"}catch{return F(this.signal),!1}}async diagnose(e){const n=globalThis.location;if(n?.hostname!==void 0&&!KN(n.hostname)&&KN(e.hostname))return"local-network";if(this.input.options.retry===!1)return"unknown";try{return await this.fetchImpl(`${Wn(e)}/`,{mode:"no-cors",method:"GET",credentials:"omit",cache:"no-store",signal:this.signal}),"cors"}catch{return F(this.signal),"unreachable"}}backoff(e){return Math.random()*Math.min(this.retry.maxDelayMs,this.retry.baseDelayMs*2**e)}async networkFailure(e,n,i,r,s,o){if(F(this.signal),!(e instanceof TypeError))throw e;const{report:l}=this.input;if(s.push(null),this.runtime==="browser"){if(o&&await this.redirects(n))return we(l,"E_SOURCE_REDIRECT","a redirect while a credential was attached",{from:Fn(n),to:null});const a=await this.diagnose(n);return a==="cors"&&i===0&&r>0?(await ad(this.backoff(0),this.signal),!0):we(l,"E_SOURCE_BLOCKED",`the browser refused ${Fn(n)}`,{url:Fn(n),cause:a})}return i<r?(await ad(this.backoff(i),this.signal),!0):we(l,"E_FETCH",`${Fn(n)} could not be reached`,{url:Fn(n),status:null})}async attempt(e,n,i,r,s){const o=this.limitOptions.maxRequests;o!==void 0&&this.state.requests>=o&&this.limitHit("maxRequests",this.state.requests);const l=await this.pace(e);try{return await this.send(e,n,0)}catch(a){const c=(n.method??"GET").toUpperCase(),d=this.input.options.credential!==void 0&&this.credentialOrigins.includes(Wn(e));return await this.networkFailure(a,e,i,r,s,d&&(c==="GET"||c==="HEAD")),null}finally{l()}}async fetch(e,n={}){F(this.signal);const i=this.resolve(e),r=(n.method??"GET").toUpperCase(),s=r==="GET"||r==="HEAD"||n.idempotent===!0,o=n.retry===!1||!s?0:this.retry.retries,l=[];for(let a=0;;a++){const c=await this.attempt(i,n,a,o,l);if(c===null)continue;if(!tfe.has(c.status)||a>=o)return this.settle(c,i,n,a,l);l.push(c.status);const d=qN(c);await c.body?.cancel().catch(()=>{}),await ad(d===null?this.backoff(a):Math.min(d,this.retry.maxDelayMs),this.signal)}}settle(e,n,i,r,s){if(s.length>0&&e.ok){const o=r+1;Ym(this.input.report,"W_SOURCE_RETRIED",`${Fn(n)} answered after ${String(o)} attempts`,{attempts:o,statuses:s})}return!e.ok&&e.status!==304&&!(i.allowStatus??[]).includes(e.status)?this.statusFailure(e,n):this.counted(e)}async fetchJson(e,n={}){const i=new Headers(n.headers);i.has("accept")||i.set("Accept","application/json");const r=await this.fetch(e,{...n,headers:i});let s;try{s=await r.text()}catch(o){throw F(this.signal),o}try{return JSON.parse(s)}catch{return we(this.input.report,"E_SOURCE_RESPONSE","the response is not JSON",{expected:"json",contentType:r.headers.get("content-type")})}}info(e){const{finish:n}=this.state,{id:i,descriptor:r,endpoint:s}=this.input;return Object.freeze({id:i,version:r?.version??1,endpoint:s===null?null:Fn(s),requests:this.state.requests,bytes:this.state.bytes,next:e,...n?.server===void 0?{}:{server:n.server},...n?.budget===void 0?{}:{budget:n.budget},...n?.validators===void 0?{}:{validators:n.validators},...n?.total===void 0?{}:{total:n.total}})}}const pL=new WeakMap;function pge(t){const e=pL.get(t)??{};return{credential:e.credential,allowInsecure:e.allowInsecure,userAgent:e.userAgent}}function lfe(t){const e=new ofe(t),n=Object.freeze({...t.options.limits,reached:()=>e.reached()}),i=Object.freeze({fetch:(r,s)=>e.fetch(r,s),fetchJson:(r,s)=>e.fetchJson(r,s),endpoint:t.endpoint,signal:e.signal,report:t.report,limits:n,cursor:t.cursor,runtime:e.runtime,progress:(r,s,o)=>{e.progress(r,s,o)},finish:r=>(e.state.finish=r??{},Object.freeze({...t.report.finish(),source:e.info(r?.next??null)}))});return pL.set(i,t.options),{ctx:i,state:e.state,info:r=>e.info(r),dispose:()=>{e.dispose()}}}const Hu="__Annotations",Y0="org.cytoscape.view.presentation.annotations.",afe=new Map([["rectangle","rectangle"],["roundedrectangle","round-rectangle"],["rounded_rectangle","round-rectangle"],["ellipse","ellipse"],["triangle","triangle"],["diamond","diamond"],["pentagon","pentagon"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","parallelogram"],["star5","star"],["star6","star"],["v","vee"]]),gL=["circle","triangle","vee","diamond","triangle-open","none","other:x","triangle","tee"],JN=[10,17,17,17,17,0,10,5,0],cfe=10,dfe=new Map([["circle","circle"],["closed arrow","triangle"],["concave arrow","vee"],["diamond","diamond"],["open arrow","triangle-open"],["no arrow","none"],["pipe","tee"],["triangle","triangle"],["t","tee"],["t-shape","tee"],["triangular head","triangle"],["x","other:x"],["x arrow","other:x"]]);function ufe(t){const{graph:e}=t,n=e.has(Hu)?e.value(Hu,0):null,r=mL(n).map(yL),s=new Map(r.map((a,c)=>[a.get("uuid")??String(c),a])),o=[],l=new Set;return r.forEach((a,c)=>{const d=hfe(a,String(c),s);d===null?l.add((a.get("type")??"").replace(Y0,"")):o.push(...d)}),{annotations:o,skipped:[...l]}}function ffe(t){const{graph:e}=t,n=e.has(Hu)?e.value(Hu,0):null;return mL(n).flatMap((i,r)=>{const s=yL(i),o=s.get("URL")??"";if((s.get("type")??"").replace(Y0,"")!=="ImageAnnotation"||o==="")return[];const l=hn(s.get("zoom"))??1,a=$e(s.get("x"))??0,c=$e(s.get("y"))??0,d=(hn(s.get("width"))??0)/l,u=(hn(s.get("height"))??0)/l,f=js(s.get("edgeColor"))??{color:"#000000",alpha:1},h=$e(s.get("opacity"));return[{id:s.get("uuid")??String(r),layer:s.get("canvas")==="background"?"background":"foreground",z:$e(s.get("z"))??0,kind:"image",rotation:$e(s.get("rotation"))??0,center:{x:a+d/2,y:-(c+u/2)},width:d,height:u,url:o,opacity:h===null?1:Math.min(1,Math.max(0,h)),borderColor:f.color,borderOpacity:f.alpha*Vu(s.get("edgeOpacity")),borderWidth:($e(s.get("edgeThickness"))??0)/l}]})}function mL(t){return typeof t=="string"?t.split(/[\r\n]+/).filter(e=>e!==""):t!==null&&typeof t=="object"&&Symbol.iterator in t?Array.from(t).filter(e=>typeof e=="string"&&e!==""):[]}function yL(t){const e=new Map;for(const n of t.split("|")){const i=n.indexOf("=");i>0&&e.set(n.slice(0,i),n.slice(i+1))}return e}function hfe(t,e,n){const i=(t.get("type")??"").replace(Y0,""),r=hn(t.get("zoom"))??1,s={id:t.get("uuid")??e,layer:t.get("canvas")==="background"?"background":"foreground",z:$e(t.get("z"))??0};switch(i){case"ShapeAnnotation":return[ZN(t,s,r)];case"TextAnnotation":return[QN(t,s,r,{x:$e(t.get("x"))??0,y:-($e(t.get("y"))??0)},"top-left")];case"BoundedTextAnnotation":{const o=ZN(t,s,r);return[o,QN(t,{...s,id:`${s.id}:text`},r,o.center,"center")]}case"ArrowAnnotation":return pfe(t,s,r,n);default:return null}}function ZN(t,e,n){const i=$e(t.get("x"))??0,r=$e(t.get("y"))??0,s=(hn(t.get("width"))??0)/n,o=(hn(t.get("height"))??0)/n,l=js(t.get("fillColor")),a=js(t.get("edgeColor"))??{color:"#000000",alpha:1};return{...e,kind:"shape",rotation:$e(t.get("rotation"))??0,center:{x:i+s/2,y:-(r+o/2)},width:s,height:o,shape:afe.get((t.get("shapeType")??"rectangle").toLowerCase())??"rectangle",fill:l?.color??null,fillOpacity:l===null?0:l.alpha*Vu(t.get("fillOpacity")),borderColor:a.color,borderOpacity:a.alpha*Vu(t.get("edgeOpacity")),borderWidth:($e(t.get("edgeThickness"))??1)/n}}function QN(t,e,n,i,r){const s=$e(t.get("fontStyle"))??0,o=js(t.get("color"))??{color:"#000000",alpha:1};return{...e,kind:"text",rotation:$e(t.get("rotation"))??0,text:t.get("text")??"",at:i,anchor:r,fontSize:(hn(t.get("fontSize"))??12)/n,fontFamily:t.get("fontFamily")??"sans-serif",bold:(s&1)!==0,italic:(s&2)!==0,color:o.color,opacity:o.alpha}}function pfe(t,e,n,i){const r=tA(i.get(t.get("sourceAnnotation")??""),n),s=tA(i.get(t.get("targetAnnotation")??""),n),o=iA(t.get("targetPoint"))??iA(t.get("targetNode")),l={x:$e(t.get("x"))??0,y:$e(t.get("y"))??0},a=r===null?l:Xm(r),c=o??(s===null?null:Xm(s));if(c===null)return null;const d=r!==null&&r.width>0&&r.height>0?nA(r,c):{x:c.x>l.x?l.x:a.x,y:c.y>l.y?l.y:a.y},u=o??nA(s??{x:c.x,y:c.y,width:0,height:0},a),f=js(t.get("lineColor"))??{color:"#000000",alpha:1},h=js(t.get("sourceColor"))?.color??f.color,p=js(t.get("targetColor"))?.color??f.color;return[{...e,kind:"arrow",from:{x:d.x,y:-d.y},to:{x:u.x,y:-u.y},color:f.color,opacity:f.alpha*Vu(t.get("lineOpacity")),width:Math.max(1,(hn(t.get("lineThickness"))??1)/n/2),sourceArrow:qm(t.get("sourceType")),targetArrow:qm(t.get("targetType")),sourceSize:hn(t.get("sourceSize"))??1,targetSize:hn(t.get("targetSize"))??1,sourceColor:h,targetColor:p,...eA("source",t.get("sourceType"),hn(t.get("sourceSize"))??1),...eA("target",t.get("targetType"),hn(t.get("targetSize"))??1)}]}function eA(t,e,n){const i=qm(e);if(i==="none")return{};const r=$e(e)??gL.indexOf(i),s=JN[r]??JN[1];return{[`${t}HeadLength`]:s*n,[`${t}HeadWidth`]:cfe*n}}function tA(t,e){if(t===void 0)return null;const n=$e(t.get("x")),i=$e(t.get("y"));return n===null||i===null?null:{x:n,y:i,width:(hn(t.get("width"))??0)/e,height:(hn(t.get("height"))??0)/e}}function Xm(t){return{x:t.x+t.width/2,y:t.y+t.height/2}}function nA(t,e){const n=Xm(t),i=e.x-n.x,r=e.y-n.y;return Math.abs(i)*t.height>=Math.abs(r)*t.width?{x:n.x+Math.sign(i)*(t.width/2),y:n.y}:{x:n.x,y:n.y+Math.sign(r)*(t.height/2)}}function qm(t){if(t===void 0)return"none";const e=$e(t);return e!==null?gL[e]??"triangle":dfe.get(t.trim().toLowerCase())??"triangle"}function iA(t){const[e,n]=(t??"").split(",").map(i=>$e(i));return e==null||n===null||n===void 0?null:{x:e,y:n}}function js(t){const e=$e(t);if(e===null||!Number.isInteger(e))return null;const n=e>>>0;return{color:`#${(n&16777215).toString(16).padStart(6,"0")}`,alpha:(n>>>24)/255}}function Vu(t){const e=$e(t);return e===null?1:Math.min(1,Math.max(0,e/100))}function $e(t){if(t===void 0||t.trim()==="")return null;const e=Number(t);return Number.isFinite(e)?e:null}function hn(t){const e=$e(t);return e!==null&&e>0?e:null}function _c(t){return t==null?"\0null":`${typeof t}:${String(t)}`}function gfe(t){const e=new Map,n=new Int32Array(t.length);for(let i=0;i<t.length;i++){const r=t[i];if(r===null)continue;const s=_c(r);let o=e.get(s);o===void 0&&(o=e.size+1,e.set(s,o)),n[i]=o}return{blocks:n,k:e.size}}function mfe(t){let e=2166136261;for(const n of t)e=Math.imul(e^n,16777619);return e>>>0}function yfe(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function bfe(t){const e=new Map,n=[];for(const[i,r]of t){const{blocks:s,k:o}=gfe(r),l=mfe(s),a=e.get(l)??[],c=a.find(f=>yfe(f.blocks,s));if(c!==void 0){c.props.push(i);continue}const d=[];for(let f=0;f<s.length;f++)s[f]!==0&&d.push(f);const u={props:[i],blocks:s,k:o,styled:d};a.push(u),e.set(l,a),n.push(u)}return n}const K0=8,Efe=256,wfe=.2;function _fe(t,e,n,i){const r=t.styled.length;if(!e.categorical||e.raw||r<K0||e.distinct<2||e.distinct>Math.min(Efe,r/2)||e.distinct>=.9*n)return null;i(n);const{values:s}=e.feature,{votes:o,nullBlocks:l}=Sfe(t,s),{table:a,exceptions:c}=Ofe(o);let d=c;const u=Nfe(t,s,a,n);if(u===null)return null;let f=null;if(l.size===1&&!u)f=l.keys().next().value??null;else for(const p of l.values())d+=p;if(d>Math.max(2,wfe*r))return null;const h=50+a.size*t.props.length+(d>0?50+d:0)+(f===null?0:50);return{type:"discrete",info:e,table:a,bucket:f,cost:h}}function Sfe(t,e){const n=new Map,i=new Map;for(const r of t.styled){const s=t.blocks[r],o=e[r];if(o===null){i.set(s,(i.get(s)??0)+1);continue}const l=_c(o);let a=n.get(l);a===void 0&&(a={raw:o,counts:new Map},n.set(l,a)),a.counts.set(s,(a.counts.get(s)??0)+1)}return{votes:n,nullBlocks:i}}function Ofe(t){const e=new Map;let n=0;for(const[i,{raw:r,counts:s}]of t){let o=-1,l=-1,a=0;for(const[c,d]of s)a+=d,d>l&&(l=d,o=c);e.set(i,{raw:r,block:o}),n+=a-l}return{table:e,exceptions:n}}function Nfe(t,e,n,i){let r=!1;for(let s=0;s<i;s++){const o=e[s];if(t.blocks[s]===0){if(o!==null&&n.has(_c(o)))return null;r||=o===null||o===!1}}return r}const bL=64,Afe=4,Tfe=new Set(["width","height"]),EL="class";function Ife(t){const e=new Set;for(const n of t)if(e.add(_c(n)),e.size>bL+1)return!1;return!0}function $fe(t,e,n){let i="",r=!1;for(const s of t){const o=(e.get(s)??[])[n]??null;r||=o!==null,i+=`${_c(o)}`}return r?i:null}function Cfe(t,e,n,i,r){const s=e.filter(g=>ii[t].get(g)!=="text"&&!Tfe.has(g)&&Ife(n.get(g)??[]));if(s.length===0)return null;r(i*(s.length+1));const o=new Map,l=new Array(i).fill(null);let a=0;for(let g=0;g<i;g++){const m=$fe(s,n,g);if(m===null)continue;a++,l[g]=m;const y=o.get(m);if(y===void 0){if(o.set(m,{count:1,rep:g}),o.size>bL)return null}else y.count++}if(o.size===0||a<K0||o.size*2>a)return null;const c=Array.from(o.entries()).sort((g,m)=>m[1].count-g[1].count),d=new Map(c.map(([g],m)=>[g,m+1])),u=l.map(g=>g===null?null:d.get(g)??null),f={style:EL},h=(g,m)=>(n.get(g)??[])[m]??null,p=[];if(c.length<=Math.min(Afe,Math.floor(a/4)))c.forEach(([,{count:g,rep:m}],y)=>{const b={};for(const _ of s){const S=h(_,m);S!==null&&(b[_]=S)}p.push({id:`${t}.class.${String(y+1)}`,target:t,role:"group",origin:"inferred",where:{eq:[f,y+1]},set:b,facts:{elements:g,reason:"STYLE_CLASS"}})});else{const g={};for(const m of s){const y=[];c.forEach(([,{rep:b}],_)=>{const S=h(m,b);S!==null&&y.push([_+1,S])}),g[m]={kind:"discrete",by:f,table:y}}p.push({id:`${t}.classes`,target:t,role:"mapping",origin:"inferred",where:{all:!0},map:g,facts:{classes:c.length,elements:a,reason:"STYLE_CLASS"}})}return{classed:s,column:u,rules:p}}const vfe=8,Dfe=4096,kfe=/^#[0-9a-f]{6}$/;function Rfe(t){return typeof t=="number"||typeof t=="string"&&kfe.test(t)}function Lfe(t,e,n,i){const r=[];let s=0;for(;s<t.length;){let o=s;for(;o+1<t.length;){const l=Pfe(t,e,s,o+1,n);if(i(o+1-s),!l)break;o++}if(r.push([s,o]),r.length>vfe)return null;s=o+1}return r}function Pfe(t,e,n,i,r){for(let s=n+1;s<i;s++){const o=N1(e[n],e[i],(t[s]-t[n])/(t[i]-t[n]));if(r?!Wy(o,e[s]):o!==e[s])return!1}return!0}function xfe(t,e,n){const i=[];for(const[r,s]of n)i.push({at:t[r],below:e[r],value:e[r],above:e[r]}),s!==r&&i.push({at:t[s],below:e[s],value:e[s],above:e[s]});return i}function Mfe(t,e,n,i){if(!e.numeric||e.raw||t.styled.length<K0)return null;const{values:r}=e.feature;if(i(r.length),r.some((s,o)=>t.blocks[o]===0==(typeof s=="number")))return null;for(const s of[!1,!0]){const o=Ufe(t,r,n,s,i);if(o!==null){const l=Array.from(o.values()).reduce((a,c)=>a+c.length,0);return{type:"continuous",info:e,points:o,tolerant:s,cost:50+l+(s?10:0)}}}return null}function Ufe(t,e,n,i,r){const s=new Map;for(const o of t.props){const l=Gfe(t,e,n.get(o)??[],i,r);if(l===null)return null;s.set(o,l)}return s}function Gfe(t,e,n,i,r){const s=new Map;let o=!0;for(const d of t.styled){const u=n[d],f=e[d],h=s.get(f);if(!Rfe(u)||h!==void 0&&h!==u){o=!1;break}s.set(f,u)}if(r(t.styled.length),!o||s.size<2||s.size>Dfe||new Set(s.values()).size<3)return null;const l=Array.from(s.keys()).sort((d,u)=>d-u),a=l.map(d=>s.get(d)),c=Lfe(l,a,i,r);return c===null||c.length*3>l.length?null:xfe(l,a,c)}const jfe=16,Ffe=64,zfe=new Set(["width","height","borderWidth","labelSize","labelWrapWidth","labelPaddingX","labelPaddingY","labelOffsetX","labelOffsetY","fanSpacing","nodeGap"]);function wL(t,e,n={}){const i=n.notes??new se,r=n.budget??new Yf,s=n.toolDefaults!==!1&&t.tool!==void 0&&t.tool!==null?vr(t.tool):null,o=t.units??"px",l=[],a={node:new Map,edge:new Map},c={node:[],edge:[]};for(const u of["node","edge"]){const f=t[u],h=n.toolDefaults===!1&&f?.rules!==void 0?{...f,rules:f.rules.filter(m=>m.origin!=="tool")}:f;c[u]=[...e[u],...h?.features??[]];const p=s===null?null:Wfe(s,u,o),g={target:u,n:u==="node"?t.fingerprint.nodes:t.fingerprint.edges,notes:i,budget:r,spend:m=>{r.spend(u,m)},columns:a[u],ids:new Set};l.push(...Jfe(g,h,c[u],new Set(n.rawColumns?.[u]??[]),{set:p,derived:s?.derived??[]},n.signal))}const d=Bfe(s,t.graph??{});return{styles:{version:1,source:{format:t.format,dialect:t.dialect??null,tool:s===null?null:s.tool},units:{length:o},graph:d,rules:l,notes:i.list()},columns:a,features:c,fingerprint:t.fingerprint}}function Wfe(t,e,n){const i={};for(const[r,s]of Object.entries(t[e]))s!==void 0&&Jo(e,r,s.value)&&!(zfe.has(r)&&t.units!==n)&&(i[r]=s.value);return Object.keys(i).length===0?null:i}function Bfe(t,e){const n={},i=Object.entries(t?.graph??{});for(const[r,s]of i)s!==void 0&&Jo("graph",r,s.value)&&(n[r]=s.value);for(const[r,s]of Object.entries(e))Jo("graph",r,s)&&(n[r]=s);return n}function Wo(t,e){let n=e,i=2;for(;t.ids.has(n);)n=`${e}#${String(i)}`,i++;return t.ids.add(n),n}function Pl(t,e,n){t.map??={},t.map[e]=n}function Hfe(t,e){const n=new Map;for(const[i,r]of Object.entries(e?.values??{})){if(r===void 0)continue;if(!ii[t.target].has(i)&&!i.startsWith("graphty:")){t.notes.add(v.NOT_CARRIED,t.target,i,{sample:i});continue}const s=Vfe(t,i,r);t.spend(t.n),s.some(o=>o!==null)&&n.set(i,s)}return n}function Vfe(t,e,n){const i=new Array(t.n).fill(null);for(let r=0;r<t.n&&r<n.length;r++){const s=n[r]??null;s!==null&&Jo(t.target,e,s)?i[r]=s:s!==null&&t.notes.add(v.BAD_VALUE,t.target,e,{sample:s,element:r})}return i}function rA(t){if(t===void 0)return;const e={};for(const[n,i]of Object.entries(t))i!==void 0&&(e[n]=i);return e}function X0(t){return[...Object.keys(t.set??{}),...Object.keys(t.map??{})]}function Yfe(t,e,n){const i=Cr(t.target,t.n,t.columns,n),r=[];for(const o of e.filter(l=>l.target===t.target)){const l={...o,set:rA(o.set),map:rA(o.map)};l.set===void 0&&delete l.set,l.map===void 0&&delete l.map,$6(o.where)||Kfe(t,l,o,i),r.push(l)}const s=Xfe(t.target,r);for(const o of s)o.id=Wo(t,o.id);return s}function Kfe(t,e,n,i){let r=1;for(;t.columns.has(`member.${String(r)}`);)r++;const s=`member.${String(r)}`,o=new Array(t.n).fill(null);let l=0;for(let a=0;a<t.n;a++)Po(n.where,i,a)&&(o[a]=!0,l++);t.spend(t.n*8),t.columns.set(s,o),e.where={has:{style:s}},e.facts={...n.facts,elements:l,reason:n.facts?.reason??"SELECTOR"},t.notes.add(v.SELECTOR_AS_COLUMN,t.target,n.id,{count:l})}function Xfe(t,e){const n=[],i=s=>"all"in s.where&&s.set!==void 0&&s.map===void 0;let r=0;for(;r<e.length;){let s=r+1;for(;i(e[r])&&s<e.length&&i(e[s]);)s++;s-r>=2?n.push({id:e[r].id,target:t,role:"defaults",origin:"declared",where:{all:!0},set:Object.assign({},...e.slice(r,s).map(o=>o.set))}):n.push(e[r]),r=s}return n}const sA=["passdata","discrete","continuous","opaque"];function qfe(t,e,n,i){const r=new Map;for(const o of e.props){const l=_l(t.target,o),a=ii[t.target].get(o)==="color",c=n.get(o)??[],d=i.find(u=>{if(!("data"in u.feature.ref))return!1;t.spend(t.n);for(let f=0;f<t.n;f++){const h=u.feature.values[f];if(a&&h!==null&&!(typeof h=="string"&&/^#[0-9a-fA-F]{6}$/.test(h))||(h===null?null:l(h))!==c[f])return!1}return!0});if(d===void 0)return null;r.set(o,d)}const s=Array.from(r.values()).some(o=>o.raw);return{type:"passdata",cols:r,raw:s,cost:s?240:50}}function Jfe(t,e,n,i,r,s){const{target:o,n:l}=t,a=r.set;for(const[ee,Ke]of e?.columns??[])t.columns.set(ee,Ke);const c=Hfe(t,e),d=a===null?[]:[{id:Wo(t,`${o}.tool`),target:o,role:"defaults",origin:"tool",where:{all:!0},set:a}];d.push(...Zfe(t,r.derived,n,e?.rules??[],c));const u=Yfe(t,e?.rules??[],n),f=new Set(u.flatMap(X0)),{defaults:h,rest:p}=Qfe(l,c,f);t.spend(l*c.size);const g=[];Object.keys(h).length>0&&g.push({id:Wo(t,`${o}.defaults`),target:o,role:"defaults",origin:"inferred",where:{all:!0},set:h});const m=bfe(p);t.spend(l*p.length);const y=n.map(ee=>CU(ee,"data"in ee.ref&&i.has(ee.ref.data))).sort((ee,Ke)=>ee.distinct-Ke.distinct);t.spend(l*n.length);const b=y.filter(ee=>ee.categorical||ee.numeric).slice(0,Ffe),_=[],S=new Map,T={id:`${o}.passthrough`,target:o,role:"passthrough",origin:"inferred",where:{all:!0},map:{}},$={id:`${o}.passthrough.raw`,target:o,role:"passthrough",origin:"inferred",where:{all:!0},map:{},facts:{reason:"NO_EXPLANATION"}},D={id:`${o}.copy`,target:o,role:"passthrough",origin:"inferred",where:{all:!0},map:{},facts:{reason:"NO_EXPLANATION"}},x=[],R=new Map;let G=0;const B={groups:_,mappings:S,passData:T,passRaw:$,copy:D,opaque:x,tolerated:R};for(const ee of m){if(s?.throwIfAborted(),t.budget.exhausted(o)){G++,x.push({fam:ee,raw:null});continue}the(t,B,ee,ehe(t,ee,b,y,c),c)}G>0&&t.notes.add(v.BUDGET,o,null,{count:G}),rhe(t,B,G,c);const Q=ee=>Object.keys(ee.map??{}).length>0,be=Array.from(S.values()).sort((ee,Ke)=>lhe(ee.id,Ke.id)),De=[...d,...u,...g,..._,...be,...[T,$,D].filter(Q)];for(const ee of De.slice(d.length+u.length+g.length))ee.id=Wo(t,ee.id);const J=Cr(o,l,t.columns,n);ahe(t,De,c,J);const st=dhe(t,De,c,a,R,J);return st!==null&&De.push(st),De.map(q0)}function Zfe(t,e,n,i,r){const s=new Set([...i.filter(l=>l.origin==="tool").flatMap(X0),...r.keys()]),o=[];for(const l of e){if(t.target!=="node"||l.kind!=="labelFromColumn"||s.has("label"))continue;const{column:a}=l;n.find(d=>"data"in d.ref&&d.ref.data===a)?.values.some(d=>d!==null&&d!=="")===!0&&(s.add("label"),o.push({id:Wo(t,"node.tool.label"),target:"node",role:"passthrough",origin:"tool",where:{has:{data:a}},map:{label:{kind:"passthrough",by:{data:a}}},facts:{reason:"NODE_NAME"}}))}return o}function Qfe(t,e,n){const i={},r=[];for(const[s,o]of e){const l=o[0];n.has(s)||(t>0&&l!==null&&o.every(a=>a===l)?i[s]=l:r.push([s,o]))}return{defaults:i,rest:r}}function ehe(t,e,n,i,r){const{target:s,n:o}=t,l=[];if(!e.props.some(d=>ii[s].get(d)==="text"))for(const d of n){const u=_fe(e,d,o,t.spend);u!==null&&l.push(u);const f=Mfe(e,d,r,t.spend);if(f!==null&&l.push(f),t.budget.exhausted(s))break}const c=qfe(t,e,r,i);return c!==null&&l.push(c),l.push({type:"opaque",cost:250}),l.sort((d,u)=>d.cost-u.cost||sA.indexOf(d.type)-sA.indexOf(u.type)),l[0]}function the(t,e,n,i,r){if(i.type==="discrete")nhe(t,e,n,i,r);else if(i.type==="continuous")ihe(t,e,n,i,r);else if(i.type==="passdata"&&!i.raw)for(const s of n.props)Pl(e.passData,s,{kind:"passthrough",by:i.cols.get(s).feature.ref});else e.opaque.push({fam:n,raw:i.type==="passdata"?i.cols:null})}function _L(t,e,n,i){let r=e.mappings.get(n);return r===void 0&&(r={id:i,target:t.target,role:"mapping",origin:"inferred",where:{all:!0},map:{}},e.mappings.set(n,r)),r}function SL(t,e){"style"in e.feature.ref&&t.columns.set(e.feature.ref.style,e.feature.values)}function nhe(t,e,n,i,r){const{target:s}=t;SL(t,i.info);const o=_L(t,e,`discrete|${i.info.name}`,`${s}.by.${i.info.name}`),l=new Map;for(const c of n.styled)l.has(n.blocks[c])||l.set(n.blocks[c],c);for(const c of n.props){const d=r.get(c)??[],u=Array.from(i.table.values(),({raw:f,block:h})=>[f,d[l.get(h)??-1]]);Pl(o,c,{kind:"discrete",by:i.info.feature.ref,table:u})}if(i.bucket===null)return;const a={};for(const c of n.props)a[c]=(r.get(c)??[])[l.get(i.bucket)??-1];e.groups.push({id:`${s}.missing.${i.info.name}`,target:s,role:"group",origin:"inferred",where:{not:{has:i.info.feature.ref}},set:a})}function ihe(t,e,n,i,r){const{target:s}=t;SL(t,i.info);const o=_L(t,e,`continuous|${i.info.name}`,`${s}.ramp.${i.info.name}`);for(const l of n.props){const a=i.points.get(l)??[];if(Pl(o,l,{kind:"continuous",by:i.info.feature.ref,points:a}),!i.tolerant)continue;const c=r.get(l)??[],d=new Set;for(const u of n.styled)bf(a,oc(i.info.feature.values[u]))!==c[u]&&(d.add(u),t.notes.add(v.RAMP_ROUNDED,s,l,{element:u,sample:c[u]}));e.tolerated.set(l,d)}}function rhe(t,e,n,i){const{target:r,n:s}=t;if(e.opaque.length===0)return;const o=e.opaque.flatMap(d=>d.fam.props),l=n>0?null:Cfe(r,o,i,s,t.spend),a=new Set(l?.classed??[]);l!==null&&she(t,e,l);let c=0;for(const{fam:d,raw:u}of e.opaque)for(const f of d.props.filter(h=>!a.has(h))){const h=u?.get(f);h===void 0?c=Math.max(c,ohe(t,e.copy,f,i.get(f)??[])):Pl(e.passRaw,f,{kind:"passthrough",by:h.feature.ref})}e.copy.facts={reason:n>0?"BUDGET":"NO_EXPLANATION",distinctValues:c}}function she(t,e,n){t.columns.set(EL,n.column);for(const i of n.rules)i.role==="group"?e.groups.push({...i,id:i.id,set:{...i.set}}):e.mappings.set(i.id,{...i,map:{...i.map}})}function ohe(t,e,n,i){return t.columns.set(`copy.${n}`,i.slice()),Pl(e,n,{kind:"passthrough",by:{style:`copy.${n}`}}),t.spend(t.n),new Set(i.filter(r=>r!==null)).size}function q0(t){const e={id:t.id,target:t.target,role:t.role,origin:t.origin,where:t.where};return t.set!==void 0&&Object.keys(t.set).length>0&&(e.set=t.set),t.map!==void 0&&Object.keys(t.map).length>0&&(e.map=t.map),t.facts!==void 0&&(e.facts=Object.fromEntries(Object.entries(t.facts).filter(([,n])=>n!==void 0))),t.ext!==void 0&&(e.ext=t.ext),e}function lhe(t,e){return t===e?0:t<e?-1:1}function oA(t){let e=Object.keys(t.set??{}).length;for(const n of Object.values(t.map??{}))n.kind==="discrete"?e+=n.table.length:n.kind==="continuous"?e+=n.points.length:e+=1;return e}const lA={inferred:0,declared:1,tool:2};function ahe(t,e,n,i){const r=jfe-1,s=`${t.target}.copy`;let o=0;for(;e.length>r;){const l=e.filter(f=>f.id!==s);if(l.length===0)break;const a=f=>f.origin==="tool"&&"all"in f.where?1:0;l.sort((f,h)=>{const p=f.role==="passthrough"?1:0,g=h.role==="passthrough"?1:0;return p-g||(lA[f.origin]??1)-(lA[h.origin]??1)||a(f)-a(h)||oA(h)-oA(f)||e.indexOf(h)-e.indexOf(f)});const c=l[0],d=e.map(q0);e.splice(e.indexOf(c),1);let u=e.find(f=>f.id===s);u===void 0?(u={id:s,target:t.target,role:"passthrough",origin:"inferred",where:{all:!0},map:{}},t.ids.add(s)):e.splice(e.indexOf(u),1);for(const f of new Set(X0(c))){const h=n.get(f),p=h===void 0?Ni(d,t.target,f,i,t.budget):h.slice();t.columns.set(`copy.${f}`,p),Pl(u,f,{kind:"passthrough",by:{style:`copy.${f}`}})}u.facts={...u.facts,reason:"LAYER_CAP"},e.push(u),o++}o>0&&t.notes.add(v.LAYER_CAP,t.target,null,{count:o})}function che(t,e,n,i){let r=null;for(let s=0;s<t;s++){const o=n(s);o!==null&&e[s]!==o&&!(i?.has(s)===!0&&Wy(e[s],o))&&(r??=new Array(t).fill(null),r[s]=o)}return r}function dhe(t,e,n,i,r,s){const o=e.map(q0),l=o.filter(d=>d.origin==="tool"),a=l.length>(i===null?0:1),c={};for(const[d,u]of n){const f=Ni(o,t.target,d,s,t.budget),h=a?Ni(l,t.target,d,s,t.budget):null,p=i?.[d]??null,g=y=>u[y]??(h===null?p:h[y]),m=che(t.n,f,g,r.get(d));m!==null&&(t.columns.set(`exceptions.${d}`,m),c[d]={kind:"passthrough",by:{style:`exceptions.${d}`}})}return Object.keys(c).length===0?null:{id:Wo(t,`${t.target}.exceptions`),target:t.target,role:"exceptions",origin:"inferred",where:{all:!0},map:c}}const OL=["node","edge"],uhe=new Set(["shape","borderStyle","lineStyle","arrow","arrowSide","weight","position","labelFit","borderPosition"]);function fhe(t,e,n,i={}){const r=i.signal??void 0,s=new se,o=i.budget??new Yf,l=ffe(e).length>0;for(const p of ufe(e).skipped)l&&p==="ImageAnnotation"||s.add(v.ANNOTATION_SKIPPED,"graph","annotations",{sample:p});const a=phe(t,e,n,{notes:s,budget:o,signal:r}),c=ro(e),d=hhe(t,e,a,s,c);if(d!==null)return d;if(a===null){const p=s.list();return p.length===0?null:yhe(t.format,p,e,c)}const u={node:new Set(a.raw.node),edge:new Set(a.raw.edge)},f={node:Jr(e,"node").filter(p=>!("data"in p.ref&&u.node.has(p.ref.data))),edge:Jr(e,"edge").filter(p=>!("data"in p.ref&&u.edge.has(p.ref.data)))},h=wL({format:t.format,dialect:a.dialect,tool:a.tool,units:a.units,graph:a.graph,node:a.node,edge:a.edge,fingerprint:c},f,{toolDefaults:i.toolDefaults,budget:o,notes:s,rawColumns:{node:a.raw.node,edge:a.raw.edge},signal:r});return a.notes.length===0?h:{...h,styles:{...h.styles,notes:[...a.notes,...h.styles.notes]}}}function hhe(t,e,n,i,r){const s=n?.block??mhe(e,Z);if(s===void 0)return null;const o=ac(s,r);if(!o.ok)return i.add(v.BLOCK_IGNORED,null,null,{sample:o.reason}),null;const l=n===null?{}:{node:n.node.values,edge:n.edge.values},a=z1(o.block,e,t.format,l,n?.notes??[],n?.tool??null,n?.opacityInColor===!0);if(a===null)return i.add(v.BLOCK_IGNORED,null,null,{sample:"INVALID"}),null;const c=i.list();return c.length===0?a:{...a,styles:{...a.styles,notes:[...a.styles.notes,...c]}}}function phe(t,e,n,i){const{notes:r,budget:s,signal:o}=i;o?.throwIfAborted();let l;if(t.styles===void 0)l=Ihe(e,t.format,r,s);else{const a=t.styles(e,{signal:o,budget:s,kept:eP(n)});l=a===null?null:bhe(a,e,r,s,o)}return o?.throwIfAborted(),l===null?null:ghe(l,e)}function ghe(t,e){const n=e.edges.byRole("pair");if(n===null)return t;const i={};for(const[r,s]of Object.entries(t.edge.values)){if(s===void 0)continue;const o=[...s];for(let l=0;l<o.length;l++){const a=n.isSet(l)?n.value(l):l;a<l&&(o[l]=s[a]??null)}i[r]=o}return{...t,edge:{...t.edge,values:i}}}function mhe(t,e){return t.graph.has(e)?K(t.graph.value(e,0)):void 0}function yhe(t,e,n,i){return{styles:{version:1,source:{format:t,dialect:null,tool:null},units:{length:"px"},graph:{},rules:[],notes:e},columns:{node:new Map,edge:new Map},features:{node:Jr(n,"node"),edge:Jr(n,"edge")},fingerprint:i}}function bhe(t,e,n,i,r){if("canonical"in t)return{dialect:t.dialect??null,tool:t.tool??null,units:t.units??"px",graph:t.graph??{},node:t.node??{values:{}},edge:t.edge??{values:{}},raw:{node:t.readFrom?.node??[],edge:t.readFrom?.edge??[]},notes:t.notes??[],block:t.block??null,opacityInColor:t.opacityInColor===!0};const{dialect:s}=t,o={node:[],edge:[]},l={node:{values:{}},edge:{values:{}}};for(const a of OL){const c=t[a];if(c===void 0)continue;const d=new Map;for(const[u,f]of Object.entries(c)){r?.throwIfAborted();const h=Ehe(e,a,u,f,n,o[a]);h!==null&&d.set(u,h)}l[a]={values:NL(a,d,s,J0(e,a),n,i)}}return{dialect:s,tool:null,units:y1(s),graph:{},node:l.node,edge:l.edge,raw:o,notes:[]}}function J0(t,e){return e==="node"?t.nodeCount:t.edgeCount}function Ehe(t,e,n,i,r,s){if(Array.isArray(i))return i;if(i===null||typeof i!="object"||typeof i.data!="string")return r.add(v.BAD_MAPPING,e,n,{sample:i}),null;const o=i.data,l=e==="node"?t.nodes:t.edges;if(!l.has(o))return r.add(v.MAPPING_COLUMN_MISSING,e,n,{sample:o}),null;s.push(o);const a=J0(t,e),c=new Array(a);for(let d=0;d<a;d++)c[d]=K(l.value(o,d));return c}function NL(t,e,n,i,r,s){const o={target:t,dialect:n,n:i,notes:r,budget:s},l=Object.create(null),a=new Map;for(const[c,d]of e){const{col:u,alpha:f}=whe(o,c,d);l[c]=u,f!==null&&a.set(c,f)}for(const[c,d]of a)She(o,l,c,d);return l}function whe(t,e,n){const{target:i,dialect:r,n:s,notes:o,budget:l}=t,a=ii[i].get(e),c=new Array(s).fill(null);let d=null;for(let u=0;u<s&&u<n.length;u++){const f={notes:o,target:i,property:e,element:u,budget:l},h=_he(n[u],f);if(h==null)continue;if(a!=="color"){c[u]=Ahe(a,e,h,r,f);continue}const p=ve(h,r,f,{use:Nhe(i,e)});c[u]=p?.color??null,p!==null&&p.alpha<1&&(d??=new Array(s).fill(null),d[u]=p.alpha)}return{col:c,alpha:d}}function _he(t,e){return Array.isArray(t)?(t.length>1&&e.notes.add(v.BAD_VALUE,e.target,e.property,{sample:t,element:e.element}),t.length===0?null:t[0]):t}function She(t,e,n,i){const{target:r,n:s,notes:o}=t,l=Ohe.get(`${r}.${n}`)??null;let a=null;l!==null&&(e[l]??=new Array(s).fill(null),a=e[l]);for(let c=0;c<s;c++){const d=i[c];if(d===null)continue;const u={notes:o,target:r,property:n,element:c},f=a===null?null:a[c],h=Ol({color:e[n][c],alpha:d},f,u,a!==null);a!==null&&(a[c]=h)}}const Ohe=new Map([["node.fill","fillOpacity"],["edge.color","opacity"]]);function Nhe(t,e){return e==="fill"?"fill":t==="edge"&&e==="color"?"edge":"line"}function Ahe(t,e,n,i,r){switch(t){case"number":return Y(n,r,i==="graphviz"&&(e==="width"||e==="height")?yt:1);case"signed":return wa(n,r);case"opacity":return ic(n,i,r);case"boolean":return rc(n,r);case"text":return rt(n,r);case void 0:return typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n)?n:null;default:return uhe.has(t)?le(t,n,i,r):null}}const The={node:[["color",["fill"]],["size",["width","height"]],["shape",["shape"]],["hidden",["visible"]]],edge:[["color",["color"]],["thickness",["width"]],["shape",["lineStyle"]],["hidden",["visible"]]]};function Ihe(t,e,n,i){const r={node:[],edge:[]},s={node:{values:{}},edge:{values:{}}};for(const o of OL){const l=o==="node"?t.nodes:t.edges,a=J0(t,o),c=new Map;for(const[d,u]of The[o]){const f=l.byRole(d);if(f===null)continue;r[o].push(f.meta.name);const h=$he(l,f.meta,d,a);for(const p of u)c.set(p,h)}s[o]={values:NL(o,c,e,a,n,i)}}return r.node.length===0&&r.edge.length===0?null:{dialect:e,tool:null,units:y1(e),graph:{},node:s.node,edge:s.edge,raw:r,notes:[]}}function $he(t,e,n,i){return Array.from({length:i},(r,s)=>{const o=K(t.value(e.name,s));return n==="color"?Che(o,e.dtype):n==="hidden"?typeof o=="boolean"?!o:null:o})}function Che(t,e){if(!Array.isArray(t)||t.length!==3&&t.length!==4||!t.every(a=>typeof a=="number"&&Number.isFinite(a)))return t;const n=e==="f32"||e==="f64"?255:1,[i,r,s]=t.map(a=>Math.round(a*n)),o=n===255?1:255,l=t.length===4?t[3]/o:1;return`rgba(${String(i)}, ${String(r)}, ${String(s)}, ${String(l)})`}const vhe="E_TOO_MANY_EMPTY_CELLS",Dhe=2**24;function AL(t){if(t===void 0)return Dhe;if(typeof t=="number"&&t>=0&&(Number.isInteger(t)||t===1/0))return t;throw new N("E_UNSUPPORTED",`option maxEmptyCells: ${Vi(t)} is not a non-negative integer or Infinity`,{option:"maxEmptyCells",found:t})}class khe extends Up{constructor(e,n,i){super(e),this.format=n,this.maxEmptyCells=i,this.nodeColumns=new Set,this.edgeColumns=new Set,this.values=0}addNode(e){const n=super.addNode(e);return this.checkBudget(),n}addEdge(e,n,i){const r=super.addEdge(e,n,i);return this.checkBudget(),r}declareNodeColumn(e){const n=super.declareNodeColumn(e);return this.nodeColumns.add(n),this.checkBudget(),n}declareEdgeColumn(e){const n=super.declareEdgeColumn(e);return this.edgeColumns.add(n),this.checkBudget(),n}setNodeValue(e,n,i){super.setNodeValue(e,n,i),this.nodeColumns.add(typeof e=="string"?this.nodeColumn(e):e),this.count(i)}setEdgeValue(e,n,i){super.setEdgeValue(e,n,i),this.edgeColumns.add(typeof e=="string"?this.edgeColumn(e):e),this.count(i)}count(e){e!=null&&this.values++,this.checkBudget()}checkBudget(){const n=this.nodeColumns.size*this.nodeBound+this.edgeColumns.size*this.edgeBound-this.values;n>this.maxEmptyCells&&new ne(this.format,1/0).fail(vhe,`the attributes are too sparse: ${this.nodeColumns.size} node and ${this.edgeColumns.size} edge attribute columns over ${this.nodeBound} node${O(this.nodeBound)} and ${this.edgeBound} edge${O(this.edgeBound)} would allocate more than ${this.maxEmptyCells} slots that hold no value; pass a larger maxEmptyCells (or Infinity) to read the file anyway`,void 0,{emptyCells:n,maxEmptyCells:this.maxEmptyCells})}}function Rhe(){return[{id:Cue,descriptor:que,load:async()=>(await xr(async()=>{const{ndexSource:t}=await import("./sources-ndex-BgZhxHsL.js");return{ndexSource:t}},[],import.meta.url)).ndexSource},{id:vue,descriptor:Tue,load:async()=>(await xr(async()=>{const{cypherSource:t}=await import("./sources-cypher-oj3S6pKb.js");return{cypherSource:t}},[],import.meta.url)).cypherSource},{id:Due,descriptor:Iue,load:async()=>(await xr(async()=>{const{neo4jSource:t}=await import("./sources-cypher-oj3S6pKb.js");return{neo4jSource:t}},[],import.meta.url)).neo4jSource},{id:kue,descriptor:$ue,load:async()=>(await xr(async()=>{const{neptuneSource:t}=await import("./sources-cypher-oj3S6pKb.js");return{neptuneSource:t}},[],import.meta.url)).neptuneSource},{id:Rue,descriptor:Jue,load:async()=>(await xr(async()=>{const{restMappingSource:t}=await import("./sources-rest-E6On5P3z.js");return{restMappingSource:t}},[],import.meta.url)).restMappingSource},{id:Lue,descriptor:Zue,load:async()=>(await xr(async()=>{const{openalexSource:t}=await import("./sources-rest-E6On5P3z.js");return{openalexSource:t}},[],import.meta.url)).openalexSource},{id:Pue,descriptor:efe,load:async()=>(await xr(async()=>{const{sparqlSource:t}=await import("./sources-sparql-BAxh1dw-.js");return{sparqlSource:t}},[],import.meta.url)).sparqlSource}]}const TL="~v",Lhe=new Set(["endpoint","credential","cursor","limits","retry","idPrefix","allowInsecure","fetch","userAgent","builder","freeze","onProgress","signal"]),Phe=new Set(["E_SOURCE_AUTH","E_SOURCE_FORBIDDEN"]);function Yr(t){return`${xue}${t}`}function Jm(t,e){return t==null?null:Object.freeze({...t,[TL]:e})}function IL(t,e,n,i){const{descriptor:r}=t,s=r?.version??1,o=new ne(Yr(t.id),n.errorLimit??100);xhe(t,o),Hue(e,r,o);const l={};for(const h of r?.params??[])h.default!==void 0&&(l[h.name]=h.default);Object.assign(l,e);const a=Mhe(n.endpoint??r?.defaultEndpoint??null,o);n.credential?.origins.length===0&&a===null&&we(o,"E_SOURCE_PARAM","a credential needs an endpoint or its own origins",{name:"credential",reason:"credential-unbound"});const c=Uhe(n.cursor,s,o),d={nodes:new Set,edgesAtStart:0,sink:null},u=lfe({id:t.id,descriptor:r,options:n,report:o,endpoint:a,cursor:c,unit:i,counts:()=>({nodes:d.nodes.size,edges:d.sink===null?0:d.sink.edgeCount-d.edgesAtStart})}),f=n.credential===void 0?null:Kue(n.credential);return{report:o,created:u,params:l,counts:d,secretQuery:f}}function xhe(t,e){const{descriptor:n}=t,i=hL(),r=n?.runtimes?.[i];r?.supported===!1&&we(e,"E_SOURCE_RUNTIME",`source ${t.id} cannot run in ${i}`,{runtime:i,reason:r.reason??"unsupported"}),n?.needs?.secureContext===!0&&i==="browser"&&globalThis.isSecureContext===!1&&we(e,"E_SOURCE_RUNTIME",`source ${t.id} needs a secure context`,{runtime:i,reason:"needs-secure-context"})}function Mhe(t,e){if(t===null)return null;let n;try{n=new URL(t)}catch{we(e,"E_SOURCE_PARAM","the endpoint is not a URL",{name:"endpoint",reason:"type"})}return(n.username!==""||n.password!=="")&&we(e,"E_SOURCE_PARAM","the endpoint may not carry a user name or password",{name:"endpoint",reason:"credentials-in-url"}),n}function Uhe(t,e,n){if(t==null)return null;const{[TL]:i,...r}=t;return i!==void 0&&i!==e&&we(n,"E_SOURCE_PARAM","the cursor was made by another version of the source",{name:"cursor",reason:"stale-cursor"}),Object.freeze(r)}function $L(t,e,n){e.counts.sink=t,e.counts.edgesAtStart=t.edgeCount;const i=e.counts.nodes,r=l=>n===void 0||n===""?l:`${n}${String(l)}`,s=l=>(i.add(l),l),o=l=>{const[a,c]=t.edgeEndpoints(l);return i.add(a),i.add(c),l};return new Proxy(t,{get(l,a){switch(a){case"addNode":return c=>s(l.addNode(r(c)));case"addNodeRecord":return(c,d)=>s(l.addNodeRecord(r(c),d));case"addNodes":return(c,d)=>{const u=l.addNodes(Array.from(c,r),d);return u.forEach(f=>i.add(f)),u};case"addEdge":return(c,d,u)=>o(l.addEdge(r(c),r(d),u));case"addEdgeRecord":return(c,d,u,f)=>o(l.addEdgeRecord(r(c),r(d),u,f));case"indexOf":return c=>l.indexOf(r(c));default:{const c=Reflect.get(l,a,l);return typeof c=="function"?c.bind(l):c}}}})}function Ghe(t,e){const n={signal:e};for(const[i,r]of Object.entries(t))Lhe.has(i)||(n[i]=r);return n}function CL(t,e){const n={};for(const[i,r]of Object.entries(e))(i==="name"||i==="description"||i==="modified")&&typeof r=="string"?n[i]=r:i!=="directed"&&(typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&t.setGraphValue(i,r);Object.keys(n).length>0&&t.setMeta(n)}function jhe(t,e,n,i,r){const s=n.idKey??"id",o=n.sourceKey??"source",l=n.targetKey??"target",a=t.meta??{};r&&typeof a.directed=="boolean"&&e.edgeCount===0&&e.setDirected(a.directed),CL(e,a);const c=Fhe(t,e,s,i);zhe(t,e,o,l,i,c)}function Fhe(t,e,n,i){const{report:r}=i,{signal:s}=i.created.ctx;let o=0;for(const l of t.nodes??[]){o++%64===0&&F(s);const{[n]:a,...c}=l;if(typeof a!="string"&&typeof a!="number"){r.error("missing-value",dt,`a node record has no ${n}`),r.counts.skippedNodes++;continue}try{e.addNodeRecord(a,c),r.counts.nodes++}catch(d){r.recordError(d,{element:String(a)}),r.counts.skippedNodes++}}return o}function zhe(t,e,n,i,r,s){const{report:o}=r,{signal:l}=r.created.ctx;let a=s,c=null;for(const d of t.edges??[]){a++%64===0&&F(l);const u=d[n],f=d[i],h=d.id,p=Object.fromEntries(Object.entries(d).filter(([g])=>g!==n&&g!==i&&g!=="id"));if(typeof u!="string"&&typeof u!="number"||typeof f!="string"&&typeof f!="number"){o.error("missing-value",dt,`an edge record has no ${n} or ${i}`),o.counts.skippedEdges++;continue}try{const g=e.addEdgeRecord(u,f,p);(typeof h=="string"||typeof h=="number")&&(c??=Bhe(e),e.setEdgeValue(c,g,String(h))),o.counts.edges++}catch(g){o.recordError(g,{element:`${String(u)} -> ${String(f)}`}),o.counts.skippedEdges++}}}function Whe(t){return t===null?"":Wn(t)}function Bhe(t){const e=t.edgeColumn("id");return e===A?t.declareEdgeColumn({name:"id",dtype:"string",role:"id",nullable:!0}):e}function Hhe(t){if(Symbol.asyncIterator in t)return t[Symbol.asyncIterator]();let e=!1;return{async next(){return e?{done:!0,value:void 0}:(e=!0,{done:!1,value:await t})}}}function Vhe(t,e,n){if(!(t instanceof Za)){if(e>0&&t instanceof it&&Phe.has(String(t.issue?.code))){const i=t.issue?.params??{};Ym(n.report,"W_SOURCE_AUTH","a later page needs a credential; the pages before it are kept",{origin:typeof i.origin=="string"?i.origin:Whe(n.created.ctx.endpoint),status:typeof i.status=="number"?i.status:null});return}throw t}}async function Yhe(t,e,n){const{ctx:i}=n.created,r=t.records,s=Hhe(r(n.params,i));let o=i.cursor,l=0,a=!1;try{for(;;){let c;try{c=await s.next()}catch(d){return Vhe(d,l,n),a=!0,o}if(c.done===!0)return l===0?null:o;if(jhe(c.value,e,t,n,l===0),l++,o=c.value.next??null,i.progress(n.report.counts.nodes+n.report.counts.edges,void 0,"items"),i.limits.reached())return a=!0,o}}finally{a&&await s.return?.().catch(()=>{})}}async function Khe(t,e,n){let i=t.body instanceof Response?t.body.body??new Uint8Array(0):t.body,{filename:r}=t,s=t.mimeType??(t.body instanceof Response?t.body.headers.get("content-type")??void 0:void 0);const o=/\.gz$/i.test(r??"")||/gzip/i.test(s??""),l=/\.zip$/i.test(r??"")||/\/(x-)?zip\b/i.test(s??"");if(o)i=((i instanceof ReadableStream?i:new Response(await Zm(i,n)).body)??new Response("").body??new ReadableStream).pipeThrough(new DecompressionStream("gzip")),r=r?.replace(/\.gz$/i,""),s=void 0;else if(l){const a=await Zm(i,n),c=O$(a).find(d=>!d.directory&&e.sniff({filename:d.name})!==null);if(c===void 0)throw new it("the zip holds no graph file",new ne("zip",0).finish());i=await N$(a,c,{signal:n,maxBytes:Number.MAX_SAFE_INTEGER,maxRatio:1e3}),r=c.name,s=void 0}return{input:i,filename:r,mimeType:s}}async function Zm(t,e){return await KA(t,{signal:e})??new TextEncoder().encode(typeof t=="string"?t:"")}async function Xhe(t,e,n,i,r){const{ctx:s}=n.created,o=t.file,l=await o(n.params,s),{input:a,filename:c,mimeType:d}=await Khe(l,i,s.signal);let{format:u}=l,f=a;if(u===void 0){const p=await Zm(a,s.signal);u=i.sniff({filename:c,mimeType:d,head:p.subarray(0,Wr)})?.format,f=p,u===void 0&&we(n.report,"E_SOURCE_RESPONSE","the file is in no format graph-io reads",{expected:"graph-file",contentType:d??null})}const h=i.importer(u);return n.report.include(await h.import(f,e,Ghe(r,s.signal))),CL(e,l.meta??{}),u}async function aA(t,e,n,i,r){const s=IL(t,e,i,typeof t.file=="function"?"bytes":"items"),{ctx:o}=s.created,l=t.descriptor?.version??1,a=$L(n,s,i.idPrefix);try{if(typeof t.records=="function"){const u=await Yhe(t,a,s);return F(o.signal),{report:Wd(s.report.finish(),s,Jm(u,l)),format:Yr(t.id)}}if(typeof t.file=="function"){const u=await Xhe(t,a,s,r,i);return{report:Wd(s.report.finish(),s,null),format:u}}const c=t.import,d=await vL(c(s.params,a,o),s);return F(o.signal),{report:Wd(d,s,Jm(s.created.state.finish?.next,l)),format:Yr(t.id)}}catch(c){throw Z0(c,s)}finally{s.created.dispose()}}async function cd(t,e,n,i,r){typeof t[e]!="function"&&we(new ne(Yr(t.id),0),"E_SOURCE_UNSUPPORTED",`source ${t.id} has no ${e}`,{feature:e});const s=IL(t,n,i,"items");try{const o=await r(s);return F(s.created.ctx.signal),o}catch(o){throw Z0(o,s)}finally{s.created.dispose()}}function Wd(t,e,n){const i=e.report.finish(),r=e.secretQuery===null||n===null?n:Qm(n,e.secretQuery),s=i.issues.filter(o=>!t.issues.includes(o));return Object.freeze({...t,issues:s.length===0?t.issues:Object.freeze([...t.issues,...s]),warningCount:t.warningCount+s.filter(o=>o.severity==="warning").length,errorCount:t.errorCount+s.filter(o=>o.severity==="error").length,source:e.created.info(r)})}function Qm(t,e){if(typeof t=="string"&&/^https?:\/\//i.test(t)){const n=new URL(t);return n.searchParams.has(e)?(n.searchParams.delete(e),n.href):t}return Array.isArray(t)?Object.freeze(t.map(n=>Qm(n,e))):typeof t=="object"&&t!==null?Object.freeze(Object.fromEntries(Object.entries(t).map(([n,i])=>[n,Qm(i,e)]))):t}function Z0(t,e){const{signal:n}=e.created.ctx;if(n.aborted)return n.reason;if(t instanceof Za)return Z0(qhe(t,e),e);if(t instanceof it&&t.report.source===void 0){const i=new it(t.message,{...t.report,source:e.created.info(null)},t.details);return i.stack=t.stack,i}return t}function qhe(t,e){try{return we(e.report,"E_SOURCE_LIMIT",t.message,{limit:t.limit,value:t.value})}catch(n){return n}}async function vL(t,e){try{return await t}catch(n){if(n instanceof Za)return e.report.finish();throw n}}function cA(t){const e=t;return typeof e.load=="function"&&e.records===void 0&&e.file===void 0&&e.import===void 0}class Jhe{constructor(e,n){this.formats=e,this.building=n,this.entries=new Map}register(e){cA(e)?Fue(e):zd(e),this.entries.has(e.id)&&ua("E_SOURCE_INVALID",`a source with id ${e.id} is already registered`,{id:e.id,reason:"duplicate"});const n=cA(e)?e:null;this.entries.set(e.id,{descriptor:e.descriptor??{plainName:e.id,params:[]},lazy:n,source:n===null?e:null,loading:null})}has(e){return this.entries.has(e)}list(){return Object.freeze([...this.entries].map(([e,n])=>Object.freeze({id:e,descriptor:n.descriptor,loaded:n.source!==null})))}async resolve(e){if(typeof e!="string")return zd(e),e;const n=this.entries.get(e);if(n===void 0)return ua("E_SOURCE_UNKNOWN",`no source has id ${JSON.stringify(e)}`,{id:e,known:[...this.entries.keys()]},Yr(e));if(n.source!==null)return n.source;const i=n.lazy;return n.loading??=i.load().then(r=>(r.id!==i.id&&ua("E_SOURCE_INVALID",`lazy source ${i.id} loaded a source with id ${r.id}`,{id:i.id,reason:"lazy"}),zd(r,i.descriptor),n.source=r.descriptor===void 0?{...r,descriptor:i.descriptor}:r,n.source),r=>{throw n.loading=null,r}),n.loading}async load(e,n,i={}){const r=await this.resolve(e),s=this.building.newBuilder(i,Yr(r.id)),{report:o,format:l}=await aA(r,n,s,i,this.formats);return this.building.freeze(l,s,o,i)}async import(e,n,i,r={}){const s=await this.resolve(e);return(await aA(s,n,i,r,this.formats)).report}async expand(e,n,i={}){const r=await this.resolve(e),s=this.building.newBuilder(i,Yr(r.id)),o=await cd(r,"expand",n.params,i,async l=>{const a=$L(s,l,i.idPrefix),c=r.expand?.({...n,params:l.params},a,l.created.ctx),d=await vL(c,l);return Wd(d,l,Jm(l.created.state.finish?.next,r.descriptor?.version??1))});return this.building.freeze(Yr(r.id),s,o,i)}async probe(e,n,i={}){const r=await this.resolve(e);return cd(r,"probe",n,i,s=>r.probe?.(s.params,s.created.ctx))}async search(e,n,i={}){const r=await this.resolve(e),s=r.descriptor===void 0?void 0:{...r.descriptor,params:r.descriptor.params.map(o=>({...o,required:!1}))};return cd({...r,descriptor:s},"list",n.params,i,o=>r.list?.({...n,params:o.params},o.created.ctx))}async validate(e,n,i,r={}){const s=await this.resolve(e);return cd(s,"validate",n,r,o=>s.validate?.(o.params,i,o.created.ctx))}}const Zhe="E_UNKNOWN_FORMAT",Qhe="W_SNIFF_FAILED",epe=new Set(["addMissingNodes","builder","defaultDirected","duplicateEdges","encoding","errorLimit","filename","format","freeze","graphIndex","graphName","hyperedges","ids","long","maxEmptyCells","mimeType","nodeIdFrom","onMixedDirection","onProgress","request","restoreMangledIds","sanitizeIds","selfLoops","signal","styles","weightDtype","weightFrom"]),tpe=new Set(["format","filename","mimeType","builder","freeze","maxEmptyCells","styles"]);class npe{constructor(){this.importerMap=new Map,this.exporterMap=new Map,this.sources=new Jhe(this,{newBuilder:(e,n)=>ud(e,n),freeze:(e,n,i,r)=>Mp({importer:{format:e},sniff:null,warnings:[]},n,i,r)})}registerSource(e){return this.sources.register(e),this}source(e){return this.sources.resolve(e)}hasSource(e){return this.sources.has(e)}listSources(){return this.sources.list()}loadFromSource(e,n,i){return this.sources.load(e,n,i)}importFromSource(e,n,i,r){return this.sources.import(e,n,i,r)}expandFromSource(e,n,i){return this.sources.expand(e,n,i)}probeSource(e,n,i){return this.sources.probe(e,n,i)}listFromSource(e,n,i){return this.sources.search(e,n,i)}validateSource(e,n,i,r){return this.sources.validate(e,n,i,r)}registerImporter(e){return this.importerMap.set(e.format,e),this}registerExporter(e){return this.exporterMap.set(e.format,e),this}importer(e){const n=this.importerMap.get(e);if(n===void 0)throw pA("importer",e,this.importerMap.keys());return n}exporter(e){const n=this.exporterMap.get(e);if(n===void 0)throw pA("exporter",e,this.exporterMap.keys());return n}hasImporter(e){return this.importerMap.has(e)}hasExporter(e){return this.exporterMap.has(e)}importers(){return[...this.importerMap.values()]}exporters(){return[...this.exporterMap.values()]}formats(){return[...new Set([...this.importerMap.keys(),...this.exporterMap.keys()])]}sniffAll(e){return DO(e,this.importerMap.values())}sniff(e){const n=this.sniffAll(e);return n.length>0?n[0]:null}async importGraph(e,n={}){const i=n,r=await this.choose(e,i),s=this.unknownOptions(i).map(d=>Object.freeze({category:"unsupported",severity:"warning",code:tE,message:hA(d),line:null,element:d})),o=s.length===0?r:{...r,warnings:[...r.warnings,...s]},{importer:l}=o;if((i.graphIndex!==void 0||i.graphName!==void 0)&&l.importAll!==void 0&&l.listGraphs===void 0){const d=await this.readAll(o,i),u=d.map(f=>f.snapshot.meta.name);return d[ml(u,i,new ne(l.format,0))]}let a,c;try{a=ud(i,o.importer.format),c=await o.importer.import(o.source,a,dd(i))}catch(d){throw await o.peeked?.close(),o.sniff===null?uA(d,l.format,i.filename):d}return Mp(o,a,c,i)}async loadFromUrl(e,n={}){const i=n,{request:r,...s}=i,o=r?.signal??s.signal??null,a=`${r?.method??"GET"} ${String(e)}`;let c;try{c=await fetch(e,{signal:s.signal,...r})}catch(d){if(o?.aborted===!0||nP(d))throw d;return dA(s,e,`${a} failed: ${lpe(e,d)}`,null,d)}if(!c.ok){await c.body?.cancel().catch(()=>{});const d=`${String(c.status)} ${c.statusText}`.trim();return dA(s,e,`${a} failed: ${d}`,c.status,null)}return this.importGraph(c.body??new Uint8Array(0),{...s,filename:s.filename??ape(e),mimeType:s.mimeType??c.headers.get("content-type")})}loadFromFile(e,n={}){const i=n,{name:r}=e;return this.importGraph(e.stream(),{...i,filename:i.filename??(typeof r=="string"?r:null),mimeType:i.mimeType??(e.type===""?null:e.type)})}async importAllGraphs(e,n={}){const i=n;return this.readAll(await this.choose(e,i),i)}async readAll(e,n){const{importer:i}=e,r=[];let s;try{i.importAll===void 0?(r.push(ud(n,i.format)),s=[await i.import(e.source,r[0],dd(n))]):s=await i.importAll(e.source,()=>{const o=ud(n,i.format);return r.push(o),o},dd(n))}catch(o){throw await e.peeked?.close(),fA(e.sniff===null?uA(o,i.format,n.filename):o,r.length-1)}return s.map((o,l)=>{try{return Mp(e,r[l],o,n)}catch(a){throw fA(a,l)}})}async listGraphs(e,n={}){const i=n,r=await this.choose(e,i);try{return r.importer.listGraphs===void 0?null:await r.importer.listGraphs(r.source,dd(i))}finally{await r.peeked?.close()}}async choose(e,n){const i=tf(e),r=n.format??"auto";if(r!=="auto")return{importer:this.importer(r),sniff:null,source:i,peeked:null,warnings:[]};const s=tt(n,{ids:"keep",defaultDirected:!0,weightFrom:null});AL(n.maxEmptyCells);const o=await ype(i,Wr,s.signal),l=s.encoding!==null&&o.head instanceof Uint8Array?new TextDecoder(s.encoding).decode(o.head,{stream:!0}):o.head;let a;const c=new ne("unknown",0),d=[];try{const h={filename:n.filename,mimeType:n.mimeType,head:l},p=DO(h,this.importerMap.values(),(g,m)=>{d.push(c.warning("unsupported",Qhe,`the ${g} importer's sniff() threw (${iP(m)}); it was treated as not recognizing the input`,{element:g}))});a=p.length>0?p[0]:null}catch(h){throw await o.close(),h}const u=xA(o.head),f=a!==null&&a.content>0&&!(u?.startsWith("an HTML")??!1);return a===null||u!==null&&!f?(await o.close(),this.refuseUndetected(c,l,u,n)):{importer:this.importer(a.format),sniff:a,source:o.input,peeked:o,warnings:d}}refuseUndetected(e,n,i,r){const s=typeof n=="string"?n:new TextDecoder().decode(n??new Uint8Array(0));if(s.trim()===""&&s.length<Wr)return e.fail(Ut,s===""?"the input is empty":"the input holds only whitespace");const o=i===null?"":`: it is ${i}`;return e.fail(Zhe,`the input is not in a graph format graph-io recognizes${mpe(r)}${o}; if you know its format, pass it as the format option`,void 0,{formats:this.formats()})}exportGraph(e,n,i){const r=this.styled(e,n,i);return r===null?this.exporter(n).export(e,i):r.refusal!==null?upe(r.refusal):r.exporter.export(r.snapshot,r.options)}styled(e,n,i){const r=i?.styles;if(r==null)return null;const s=this.exporter(n),{styles:o,...l}=i,a=_7(e,s,r,l);return{exporter:s,snapshot:a.snapshot,options:a.input===null?l:{...l,styles:a.input},plain:l,notes:a.notes,refusal:a.refusal}}async exportGraphToString(e,n,i){const r=this.styled(e,n,i);if(r===null)return this.exporter(n).exportToString(e,i);if(r.refusal!==null)throw DL(r.refusal);return r.exporter.exportToString(r.snapshot,r.options)}exportGraphToBytes(e,n,i){return h2(this.exportGraph(e,n,i))}async exportGraphToBlob(e,n,i){const r=[];for await(const o of this.exportGraph(e,n,i))r.push(o);const s=this.listFormats().find(o=>o.format===n);return new Blob(r,{type:s?.mimeTypes[0]??"application/octet-stream"})}checkExport(e,n,i){const r=this.styled(e,n,i);let s;if(r===null)s=this.exporter(n).check(e,i);else if(r.refusal===null){const l=c=>`${c.code}\0${c.style?.target??""}\0${c.style?.property??""}`,a=new Set(r.notes.filter(c=>c.style!==void 0).map(l));s=[...r.exporter.check(r.snapshot,r.options).filter(c=>c.style===void 0||!a.has(l(c))&&!I7(c,r.exporter)),...r.notes]}else s=[...r.exporter.check(e,r.plain),r.refusal];const o=this.unknownOptions(i);return o.length===0?s:Object.freeze([...s,...o.map(l=>Object.freeze({code:tE,message:hA(l),column:null,count:null}))])}unknownOptions(e){if(e==null)return[];const n=new Set(epe);for(const i of[...this.importerMap.values(),...this.exporterMap.values()]){if(i.options===void 0)return[];for(const r of i.options)n.add(r)}return Object.entries(e).filter(([i,r])=>r!==void 0&&!n.has(i)).map(([i])=>i)}async downloadGraph(e,n,i={}){if(typeof document>"u")throw new N("E_UNSUPPORTED","downloadGraph() needs a browser document; use exportGraphToBytes() and write the bytes yourself");const{filename:r,...s}=i,o=await this.exportGraphToBlob(e,n,s),l=this.listFormats().find(d=>d.format===n)?.extensions[0]??`.${n}`,a=URL.createObjectURL(o),c=document.createElement("a");c.href=a,c.download=r??`graph${l}`,c.click(),setTimeout(()=>{URL.revokeObjectURL(a)},0)}listFormats(){return this.formats().map(e=>{const n=this.importerMap.get(e),i=this.exporterMap.get(e);return Object.freeze({format:e,extensions:n?.extensions??i?.extensions??[],mimeTypes:n?.mimeTypes??i?.mimeTypes??[],canImport:n!==void 0,canExport:i!==void 0,capabilities:fpe(i)})})}}function ipe(){const t=new npe().registerImporter(use).registerExporter(poe).registerImporter(fJ).registerExporter(lq).registerImporter(NV).registerExporter(YV).registerImporter(OM).registerExporter(QM).registerImporter(hD).registerExporter(BK).registerImporter(ZC).registerExporter(vB).registerImporter(sL).registerExporter(vde).registerImporter(Yoe).registerExporter(ule).registerImporter(h9).registerExporter(Aue).registerImporter(JG).registerExporter(wj).registerImporter(tj).registerExporter(C8).registerImporter(Vle).registerExporter(Rae).registerImporter(Nz).registerExporter(bF);for(const e of Rhe())t.registerSource(e);return t}const mh=ipe();function rpe(t,e){return mh.importGraph(t,e)}async function spe(t,e,n){return mh.exportGraphToString(t,e,n)}function ope(t,e,n){return mh.checkExport(t,e,n)}function dA(t,e,n,i,r){const s=t.format===void 0||t.format==="auto"?"unknown":t.format;return new ne(s,0).fail(bA,n,void 0,{url:String(e),status:i,cause:r})}function uA(t,e,n){if(!(t instanceof it)||t.issue?.category!=="parse-error"||t.report.errorCount>1||t.report.counts.nodes+t.report.counts.edges>0)return t;const i=n==null?"the input":JSON.stringify(n);return new it(`${i} could not be read as ${e}: ${t.message}`,t.report,t.details)}function lpe(t,e){let n=null;try{n=new URL(t)}catch{}if(n===null&&globalThis.location===void 0)return"a relative URL needs a web page to resolve against; outside a browser pass an absolute http(s) URL, or read a local file with loadFromFile() or importGraph()";if(n?.protocol==="file:")return"fetch() cannot read file: URLs here; read a local file with loadFromFile() or importGraph()";const i=e?.cause?.message;return`the server could not be reached, or (in a browser) it does not allow this page to read the file (CORS)${typeof i=="string"&&i!==""?` (${i})`:""}`}function ape(t){const e=new URL(t,"http://localhost/").pathname,n=e.slice(e.lastIndexOf("/")+1);return n===""?null:n}function dd(t){const e={};for(const[n,i]of Object.entries(t))tpe.has(n)||(e[n]=i);return e}function ud(t,e){const n=AL(t.maxEmptyCells);try{return cpe(t,e,n)}catch(i){if(i instanceof N&&i.code==="E_UNSUPPORTED"&&typeof i.details.field=="string"){const r=i.details.field;throw new N("E_UNSUPPORTED",`option ${r}: ${JSON.stringify(i.details.found)} is not one of the values it takes`,{option:r,found:i.details.found})}throw i}}function cpe(t,e,n){return new khe({weightDtype:t.weightDtype??"f64",...t.builder,directed:!0,addMissingNodes:t.addMissingNodes??!0,duplicateEdges:t.duplicateEdges??"keep",selfLoops:t.selfLoops??"keep"},e,n)}function fA(t,e){return!(t instanceof it)||e<0?t:new it(`graph ${e}: ${t.message}`,t.report,{...t.details,graphIndex:e})}function Mp(t,e,n,i){let r;try{r=e.freezeWithReport(i.freeze)}catch(d){throw gpe(d,n)}const{warnings:s}=t,o=i.styles;let l;o!==void 0&&o!==!1&&(l=fhe(t.importer,r.snapshot,n,{signal:i.signal,toolDefaults:typeof o=="object"?o.toolDefaults:void 0}));const a=l!==void 0&&t.importer.styles!==void 0?dpe(n):n,c={format:t.importer.format,sniff:t.sniff,snapshot:r.snapshot,report:ppe(hpe(s.length===0?a:Object.freeze({...a,issues:Object.freeze([...s,...a.issues]),warningCount:a.warningCount+s.length}),r.snapshot,i.weightFrom),r.report)};return l!==void 0&&Object.assign(c,{styles:l}),Object.defineProperty(c,"freeze",{value:r.report,enumerable:!1}),Object.freeze(c)}function dpe(t){const e=t.issues.filter(n=>n.code!==to);return e.length===t.issues.length?t:Object.freeze({...t,issues:Object.freeze(e),warningCount:t.warningCount-(t.issues.length-e.length)})}function DL(t){return new N("E_UNSUPPORTED",t.message,{code:t.code})}function upe(t){return{[Symbol.asyncIterator]:()=>({next:()=>Promise.reject(DL(t))})}}function fpe(t){return t===void 0?null:t.styles===void 0?t.capabilities:Object.freeze({...t.capabilities,styles:t.styles.capabilities})}function hA(t){return`option ${JSON.stringify(t)} is not an option of any format or of the load and save functions, so it has no effect; check its spelling`}function hpe(t,e,n){if(typeof n!="string"||e.edgeCount===0||e.edgeList().weights!==null||t.issues.some(r=>r.code===Jt&&r.element==="weightFrom"))return t;const i=Object.freeze({category:"missing-value",severity:"warning",code:KL,message:`weightFrom: ${JSON.stringify(n)} names no attribute an edge has a value for, so the graph has no weights`,line:null,element:"weightFrom"});return Object.freeze({...t,issues:Object.freeze([...t.issues,i]),warningCount:t.warningCount+1})}function ppe(t,e){const n=[],i=(r,s,o)=>{n.push(Object.freeze({category:r,severity:"warning",code:s,message:o,line:null,element:null}))};return e.mergedEdges>0&&i("merged",VL,`${e.mergedEdges} parallel edge${O(e.mergedEdges)} ${C(e.mergedEdges,"was","were")} merged into one edge per pair by the duplicateEdges policy; whatever told them apart (a relation, a label) is lost`),e.droppedSelfLoops>0&&i("validation-error",YL,`${e.droppedSelfLoops} self-loop${O(e.droppedSelfLoops)} ${C(e.droppedSelfLoops,"was","were")} removed by selfLoops: "drop"`),n.length===0?t:Object.freeze({...t,issues:Object.freeze([...t.issues,...n]),warningCount:t.warningCount+n.length})}function gpe(t,e){if(!(t instanceof N)||t instanceof it)return t;const n=Object.freeze({category:"validation-error",severity:"error",code:t.code,message:t.message,line:null,element:null}),i=Object.freeze({...e,issues:Object.freeze([...e.issues,n]),errorCount:e.errorCount+1});return new it(`the graph cannot be frozen: ${t.message}`,i,{code:t.code,...t.details})}function pA(t,e,n){const i=[...n];return new N("E_UNSUPPORTED",`no ${t} is registered for format ${JSON.stringify(e)}; known: ${i.join(", ")}`,{option:"format",found:e,supported:i})}function mpe(t){const e=[];return typeof t.filename=="string"&&t.filename.length>0&&e.push(`filename ${JSON.stringify(t.filename)}`),typeof t.mimeType=="string"&&t.mimeType.length>0&&e.push(`MIME type ${JSON.stringify(t.mimeType)}`),e.length===0?"":` (${e.join(", ")})`}async function ype(t,e,n){if(typeof t=="string")return{head:t.slice(0,e),input:t,close:()=>Promise.resolve()};if(t instanceof Uint8Array)return{head:t.subarray(0,e),input:t,close:()=>Promise.resolve()};F(n);const i=typeof t.getReader=="function"?wpe(t,n):t[Symbol.asyncIterator](),r=[];let s=0,o=!1;for(;s<e;){n?.aborted&&(await i.return?.(),F(n));const a=await i.next();if(a.done===!0){o=!0;break}r.push(a.value),s+=typeof a.value=="string"?a.value.length:a.value.byteLength}!o&&n?.aborted&&(await i.return?.(),F(n));const l=Epe(r,i,o);return{head:bpe(r,e),input:l,close:()=>l.close()}}function bpe(t,e){if(t.every(r=>r instanceof Uint8Array)){const r=Math.min(e,t.reduce((l,a)=>l+a.byteLength,0)),s=new Uint8Array(r);let o=0;for(const l of t){if(o>=r)break;const a=l.subarray(0,Math.min(l.byteLength,r-o));s.set(a,o),o+=a.byteLength}return s}const n=new TextDecoder("utf-8",{fatal:!1});let i="";for(const r of t)if(i+=typeof r=="string"?r:n.decode(r,{stream:!0}),i.length>=e)break;return i.slice(0,e)}function Epe(t,e,n){let i=n;const r=async()=>{i||(i=!0,await e.return?.())};return{close:r,[Symbol.asyncIterator](){let s=0;return{async next(){if(s<t.length)return{done:!1,value:t[s++]};if(i)return{done:!0,value:void 0};const o=await e.next();return o.done===!0?(i=!0,{done:!0,value:void 0}):o},async return(){return await r(),{done:!0,value:void 0}}}}}}function wpe(t,e){const n=zA(t);let i=!1;return{async next(){if(i)return{done:!0,value:void 0};let r;try{r=await FA(n.read(),e)}catch(s){throw i=!0,await n.cancel(e?.reason).catch(()=>{}),n.releaseLock(),s}return r.done?(i=!0,n.releaseLock(),{done:!0,value:void 0}):{done:!1,value:r.value}},async return(){return i||(i=!0,await n.cancel(e?.reason).catch(()=>{}),n.releaseLock()),{done:!0,value:void 0}}}}const os=Object.freeze({STACKED:"W_POSITION_STACKED",PARTIAL:"W_POSITION_PARTIAL",NON_FINITE:"W_POSITION_NON_FINITE",DIMS_MIXED:"W_POSITION_DIMS_MIXED",ANCHOR_NO_SIZE:"W_POSITION_ANCHOR_NO_SIZE",OTHER_VIEWS:"W_POSITION_OTHER_VIEWS",NOT_READ:"W_POSITIONS_NOT_READ"}),_pe=8,gA=80;class Spe{#e=new Map;add(e,n={},i=null){const r=`${e}\0${i??""}`;let s=this.#e.get(r);if(s===void 0&&(s={code:e,property:i,count:0,samples:[],elements:new Set,unindexed:!1},this.#e.set(r,s)),s.count+=n.count??1,n.element===void 0?s.unindexed=!0:s.elements.add(n.element),n.sample!==void 0&&s.samples.length<_pe){const o=Ope(n.sample);s.samples.includes(o)||s.samples.push(o)}}list(){return Array.from(this.#e.values(),e=>({code:e.code,property:e.property,count:e.count,samples:[...e.samples],elements:e.unindexed?{count:e.count}:Array.from(e.elements).sort((n,i)=>n-i)}))}}function Ope(t){const e=typeof t=="string"?t:JSON.stringify(t)??String(t);return e.length>gA?`${e.slice(0,gA-3)}...`:e}const Npe=new Set(["W_PAJEK_COORD_DIMS","W_DOT_POS_DIMS"]),Ape={W_POSITION_STACKED:"every placed node is on one point; the positions were dropped",W_POSITION_PARTIAL:"nodes have no position",W_POSITION_NON_FINITE:"positions are not finite numbers",W_POSITION_DIMS_MIXED:"positions mix 2 and 3 coordinates",W_POSITION_ANCHOR_NO_SIZE:"top-left positions have no size and were not moved to the center",W_POSITION_OTHER_VIEWS:"other views were not used",W_POSITIONS_NOT_READ:"position-like columns this format does not read"};function Tpe(t,e,n,i={}){const r=i.signal??null;r?.throwIfAborted();const s=new Spe,o=Ipe(t,e,r);if(o===null)return Wpe(e,s),s.list().length===0?null:Hpe(t,e,s);const l=e.nodeCount,a=Dpe(l,o,s);r?.throwIfAborted();const c=xpe(e);if(o.extra.containersFollowChildren===!0)for(const p of c)a.values.fill(Number.NaN,3*p,3*p+3);const d=Mpe(o,a);Upe(o,a,c,d);const{placed:u,total:f}=Gpe(a,c,s),h=jpe(a,u,s);return Fpe(n,s),zpe(e,s),{version:1,source:{format:t.format,tool:o.tool??Hb(e.meta.creator),yAxis:o.extra.yAxis??"up"},units:o.extra.units??"file",...o.extra.pxPerUnit===void 0?{}:{pxPerUnit:o.extra.pxPerUnit},...o.extra.viewerFit===void 0?{}:{viewerFit:o.extra.viewerFit},medianNodeSize:o.medianNodeSize??Vpe(o.size,l,c),dims:a.realZ?3:2,coords:a.values,placed:h?0:u,total:f,usable:!h&&u>0,bounds:h?null:Ype(a.values),groups:d,notes:kL(s)}}function Ipe(t,e,n){const i=t.positions?.(e,{signal:n})??null;if(i?.x!==void 0&&i.y!==void 0)return Cpe(e,i);const r=i?.column===void 0?e.nodes.byRole("position"):e.nodes.get(i.column);if(r===null||r.meta.components<2)return i?.unplacedCircle===void 0?null:$pe(e,i);const s={...Yu(r.meta.extra),...Yu(i??{})};return{read:vpe(r),size:eE(e,s),extra:s,...Q0(i)}}function $pe(t,e){const n=e.unplacedCircle,i=t.nodeCount,r=(o,l)=>{if(n===void 0||i===0)return!1;const a=(n.startDegrees+n.direction*360*o/i)*Math.PI/180;return l[0]=n.center[0]+n.radius*Math.cos(a),l[1]=n.center[1]+n.radius*Math.sin(a),l[2]=0,!0},s={...Yu(e),sourceDims:2};return{read:r,size:eE(t,s),extra:s,...Q0(e)}}function Cpe(t,e){const n=t.nodes.get(e.x??""),i=t.nodes.get(e.y??""),r=e.z===void 0?null:t.nodes.get(e.z);if(n===null||i===null)return null;const s=(l,a)=>!n.isSet(l)||!i.isSet(l)?!1:(a[0]=Number(n.value(l)),a[1]=Number(i.value(l)),a[2]=r?.isSet(l)===!0?Number(r.value(l)):0,!0),o={...Yu(e),sourceDims:r===null?2:3};return{read:s,size:eE(t,o),extra:o,...Q0(e)}}function Q0(t){return{groups:t?.groups??[],medianNodeSize:t?.medianNodeSize,tool:t?.tool}}function vpe(t){return(e,n)=>{if(!t.isSet(e))return!1;const i=t.value(e);return n[0]=i[0],n[1]=i[1],n[2]=i.length>2?i[2]:0,!0}}function Yu(t){const e=t,n={},i=(s,o)=>{o(e[s])&&(n[s]=e[s])};i("units",s=>s==="px"||s==="file"),i("sourceDims",s=>s===2||s===3),i("yAxis",s=>s==="up"||s==="down"),i("anchor",s=>s==="center"||s==="top-left"),i("width",s=>typeof s=="string"),i("height",s=>typeof s=="string"),i("pxPerUnit",s=>typeof s=="number"&&Number.isFinite(s)&&s>0),i("pxPerUnitY",s=>typeof s=="number"&&Number.isFinite(s)&&s>0),i("zOrigin",s=>typeof s=="number"&&Number.isFinite(s)),i("zeroUnplaced",s=>typeof s=="boolean"),i("originUnplaced",s=>typeof s=="boolean"),i("containersFollowChildren",s=>typeof s=="boolean");const r=e.viewerFit;return typeof r?.padding=="number"&&Number.isFinite(r.padding)&&r.padding>=0&&(n.viewerFit={padding:r.padding}),n}function Dpe(t,e,n){const i=new Float64Array(3*t).fill(Number.NaN),r=[0,0,0];for(let o=0;o<t;o++)e.read(o,r)&&(Number.isFinite(r[0])&&Number.isFinite(r[1])&&Number.isFinite(r[2])?i.set(r,3*o):n.add(os.NON_FINITE,{element:o,sample:r.join(",")}));e.extra.zeroUnplaced===!0&&Lpe(i),e.extra.originUnplaced===!0&&kpe(i);const s=e.extra.sourceDims===3&&!Ppe(i);return Rpe(i,e.extra,e.size,s,n),{values:i,realZ:s}}function kpe(t){if(t.some(e=>!Number.isNaN(e)))for(let e=0;e<t.length;e+=3)Number.isNaN(t[e])&&t.fill(0,e,e+3)}function Rpe(t,e,n,i,r){const s=[0,0,0];for(let o=0;o<t.length;o+=3){if(Number.isNaN(t[o]))continue;const l=e.anchor==="top-left"?n(o/3):null;e.anchor==="top-left"&&l===null&&r.add(os.ANCHOR_NO_SIZE,{element:o/3}),s[0]=t[o],s[1]=t[o+1],s[2]=t[o+2],ty(s,e,l,i),t.set(s,o)}}function eE(t,e){const n=e.width===void 0?null:t.nodes.get(e.width),i=e.height===void 0?null:t.nodes.get(e.height);return n===null||i===null?()=>null:r=>{if(!n.isSet(r)||!i.isSet(r))return null;const s=[Number(n.value(r)),Number(i.value(r))];return Number.isFinite(s[0])&&Number.isFinite(s[1])?s:null}}function Lpe(t){const e=[];let n=0;for(let i=0;i<t.length;i+=3)t[i]===0&&t[i+1]===0?e.push(i):Number.isNaN(t[i])||n++;if(e.length>=2&&n>0)for(const i of e)t.fill(Number.NaN,i,i+3)}function Ppe(t){let e=Number.NaN;for(let n=0;n<t.length;n+=3)if(!Number.isNaN(t[n])){if(Number.isNaN(e))e=t[n+2];else if(t[n+2]!==e)return!1}return!0}function xpe(t){const e=new Set,n=t.nodes.byRole("parent");if(n===null)return e;for(let i=0;i<n.length;i++){const r=n.isSet(i)?n.value(i):void 0;typeof r=="number"&&e.add(r)}return e}function Mpe(t,e){const n=[];for(const{node:i,box:r}of t.groups){const s=[r.x,r.y,0];ty(s,t.extra,[r.width,r.height],!1),Number.isNaN(e.values[3*i])&&e.values.set(s,3*i),n.some(o=>o.node===i)||n.push({node:i,box:{x:s[0],y:s[1],width:r.width,height:r.height}})}return n}function Upe(t,e,n,i){for(const r of n){const s=t.size(r),o=3*r;s!==null&&!Number.isNaN(e.values[o])&&!i.some(l=>l.node===r)&&i.push({node:r,box:{x:e.values[o],y:e.values[o+1],width:s[0],height:s[1]}})}}function Gpe(t,e,n){const{values:i}=t,r=[];let s=0,o=0;for(let l=0;3*l<i.length;l++){const a=!Number.isNaN(i[3*l]);a?s++:e.has(l)||r.push(l),o+=a||!e.has(l)?1:0}if(s>0&&r.length>0)for(const l of r)n.add(os.PARTIAL,{element:l});return{placed:s,total:o}}function jpe(t,e,n){if(e<2)return!1;const{values:i}=t;let r=-1;for(let s=0;s<i.length;s+=3)if(!Number.isNaN(i[s])){if(r<0)r=s;else if(i[s]!==i[r]||i[s+1]!==i[r+1]||i[s+2]!==i[r+2])return!1}return n.add(os.STACKED,{count:e,sample:Array.from(i.subarray(r,r+3)).join(",")}),i.fill(Number.NaN),!0}function Fpe(t,e){for(const n of t.issues)Npe.has(n.code)&&e.add(os.DIMS_MIXED,{sample:n.code})}function zpe(t,e){for(const n of t.nodes)/^position@\d+$/.test(n.meta.name)&&n.meta.role===null&&e.add(os.OTHER_VIEWS,{sample:n.meta.name})}function Wpe(t,e){const n=s=>[...t.nodes].find(o=>o.meta.name.toLowerCase()===s&&o.meta.components===1&&Bpe(o.dtype)),i=n("x"),r=n("y");i!==void 0&&r!==void 0&&(e.add(os.NOT_READ,{sample:i.meta.name}),e.add(os.NOT_READ,{sample:r.meta.name}))}function Bpe(t){return t==="f64"||t==="f32"||t==="i32"||t==="u32"||t==="u8"}function kL(t){return t.list().map(e=>({code:e.code,params:{count:e.count,samples:e.samples},elements:e.elements,message:`${Ape[e.code]} (${e.count})`}))}function Hpe(t,e,n){return{version:1,source:{format:t.format,tool:Hb(e.meta.creator),yAxis:"up"},units:"file",medianNodeSize:null,dims:2,coords:new Float64Array(3*e.nodeCount).fill(Number.NaN),placed:0,total:e.nodeCount,usable:!1,bounds:null,groups:[],notes:kL(n)}}function Vpe(t,e,n){const i=[];for(let r=0;r<e;r++){const s=n.has(r)?null:t(r);s!==null&&i.push((s[0]+s[1])/2)}return ny(i)}function Ype(t){const e=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let i=0;i<t.length;i+=3)if(!Number.isNaN(t[i]))for(let r=0;r<3;r++)e[r]=Math.min(e[r],t[i+r]),n[r]=Math.max(n[r],t[i+r]);return e[0]===1/0?null:{min:e,max:n}}const Kpe=()=>null;function Xpe(t){return Array.isArray(t)?t.map(e=>{if(e===null||typeof e!="object")return e;const n=e,i=n.style??n.css;if(i===null||typeof i!="object")return e;const r=Object.create(null);for(const s of Object.keys(i)){const o=i[s];r[s]=o==="fn"?Kpe:o}return{selector:n.selector,style:r}}):t}function qpe(t){if(Array.isArray(t))return t;if(t!==null&&typeof t=="object"){const e=t;return[...Array.isArray(e.nodes)?e.nodes:[],...Array.isArray(e.edges)?e.edges:[]]}return[]}function Jpe(t){const e=t.notes??new se,n=t.budget??new Yf;let i;if(t.rendered!==void 0){i=new Map;const o=qpe(t.elements);for(let l=0;l<o.length&&l<t.rendered.length;l++){const a=o[l],c=t.rendered[l];a!==null&&typeof a=="object"&&c!==null&&c!==void 0&&typeof c=="object"&&i.set(a,c)}}const r=a0({elements:t.elements,style:Xpe(t.style),snapshot:t.snapshot,toolDefaults:t.toolDefaults,rendered:i,notes:e,budget:n,signal:t.signal}),s=t.snapshot;return wL({format:t.format??"json",dialect:"cytoscape-js",tool:"cytoscape-js",units:"px",node:{values:r.node.values,rules:r.node.rules,columns:r.node.columns},edge:{values:r.edge.values,rules:r.edge.rules,columns:r.edge.columns},fingerprint:ro(s)},{node:Jr(s,"node"),edge:Jr(s,"edge")},{toolDefaults:t.toolDefaults,notes:e,budget:n,signal:t.signal,rawColumns:{node:r.node.rawColumns,edge:r.edge.rawColumns}})}let mA=0;function Zpe(t){return{category:"unsupported",severity:"warning",code:t.code,message:t.message,line:null,element:t.params.property}}async function gge(t,e="auto",n={}){const{applyStyles:i,importId:r,...s}=n,o=await rpe(t instanceof ArrayBuffer?new Uint8Array(t):t,{...s,format:e});if(o.snapshot.nodeCount===0&&o.report.errorCount>0){const f=o.report.issues.find(h=>h.severity==="error");throw new it(`nothing could be read from the input as ${o.format}: ${f?.code??"E_IMPORT"}: ${f?.message??""}`,o.report,{format:o.format})}const l=[],a=UL(o.snapshot,({domain:f,from:h,to:p})=>l.push({category:"coercion",severity:"warning",code:"W_COLUMN_RENAMED",message:`${f} attribute "${h}" renamed to "${p}": Cytoscape reserves the data field "${h}"`,line:null,element:h}),(f,h)=>l.push({category:"coercion",severity:"warning",code:"W_EDGE_ID_DROPPED",message:`edge id "${f}" is already the id of ${h==="node"?"a node":"an earlier edge"}; Cytoscape gives this edge a new id`,line:null,element:f}),o.styles!==void 0&&o.styles!==null),c=Tpe(mh.importer(o.format),o.snapshot,o.report);for(let f=0;f<o.snapshot.nodeCount;f++){const h=a[f],p=c?.usable===!0?c.coords[3*f]:Number.NaN;Number.isNaN(p)?delete h.position:h.position={x:p,y:GL(c?.coords[3*f+1]??0)}}let d={};if(o.styles!==void 0&&o.styles!==null){mA++;const f=ik(o.styles,{importId:r??String(mA)}),h=o.snapshot.nodeCount,p=(g,m)=>m<h?g.node[m]:g.edge[m-h];a.forEach((g,m)=>Object.assign(g.data,p(f.elementData,m))),d={stylesheet:f.stylesheet,bypass:a.map((g,m)=>p(f.bypass,m))},l.push(...f.notes.map(Zpe))}const u=l.length===0?o.report:{...o.report,issues:[...o.report.issues,...l],warningCount:o.report.warningCount+l.length};return{elements:a,directed:o.snapshot.directed,format:o.format,report:u,...d}}const Qpe=new Set(["W_ID_TEXT_TYPE","W_ID_RENUMBERED","W_CSV_NODE_ORDER","W_STORAGE_CLASS_CHANGED"]);function ege(t){return Qpe.has(t.code)||t.code==="W_COLUMN_NAME_CHANGED"&&(t.column==="id"||t.column==="parent"||t.column==="position")?!1:!(t.code==="W_ROLE_DROPPED"&&t.column==="label")}function RL(t){return t.cy()}function ey(t){return t.style()}function tge(t,e){const n=ey(RL(t));if(n===void 0)return null;const i=t.nodes(),r=jL(t);return Jpe({elements:{nodes:i.jsons(),edges:r.jsons()},style:n.json(),rendered:[...i.map(s=>s.style()),...r.map(s=>s.style())],snapshot:e})}function nge(t){return t.styles.notes.filter(e=>e.code===v.LAYER_FLATTENED).map(e=>({code:e.code,message:e.message,column:null,count:e.params.count,...e.params.target==="node"||e.params.target==="edge"?{style:{target:e.params.target,property:e.params.property}}:{}}))}function ige(t,e){const n=ey(t);if(n===void 0)return e?[{code:v.NOT_EXPORTED,message:"no styles are written: the core has styles disabled; create it with { styleEnabled: true }",column:null,count:null}]:[];const i=new t.constructor({headless:!0,styleEnabled:!0}),r=JSON.stringify(n.json())!==JSON.stringify(ey(i)?.json());return i.destroy(),r?[{code:v.NOT_EXPORTED,message:"the core's stylesheet is not written; export with { styles: true } to write it",column:null,count:null}]:[]}const rge=new Set(["gml","cx2"]);async function mge(t,e,n={}){if(typeof t?.nodes!="function")throw new TypeError("exportElements needs a Cytoscape collection; wrap element definitions with cytoscape({ headless: true, elements }).elements()");const{directed:i,onLoss:r,styles:s,...o}=n,l=ML(t,{directed:i,format:e,integerIds:rge.has(e)}),a=s===!0?tge(t,l):null,c={sanitizeIds:"mangle",...e==="json"?{dialect:"cytoscape"}:{},...o,...a===null?{}:{styles:a}};if(r!==void 0){const d=[...a===null?ige(RL(t),s===!0):nge(a),...ope(l,e,c).filter(ege)];d.length>0&&r(d)}return spe(l,e,c)}export{mge as A,gge as B,Tue as C,VN as D,it as I,que as N,Zue as O,re as P,Jue as R,age as S,Cue as a,pge as b,tj as c,fge as d,ua as e,we as f,vue as g,Iue as h,Km as i,Due as j,$ue as k,kue as l,uge as m,Rue as n,Wn as o,Lue as p,dge as q,cge as r,ad as s,F as t,hge as u,YN as v,Ym as w,efe as x,Pue as y,hL as z};
|