@graphty/cytoscape-extensions 0.0.28 → 0.0.29

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.
Files changed (72) hide show
  1. package/dist/algorithm-options.d.ts +5 -0
  2. package/dist/algorithm-options.d.ts.map +1 -0
  3. package/dist/algorithm-options.js +285 -0
  4. package/dist/algorithm-options.js.map +1 -0
  5. package/dist/algorithms.d.ts +489 -0
  6. package/dist/algorithms.d.ts.map +1 -0
  7. package/dist/algorithms.js +1184 -0
  8. package/dist/algorithms.js.map +1 -0
  9. package/dist/cdn/chunks/elements-DkrLtNP8.js +1 -0
  10. package/dist/cdn/chunks/gpu-platform-browser-VBah74fl.js +2825 -0
  11. package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
  12. package/dist/cdn/chunks/index-CAhmhhmb.js +1 -0
  13. package/dist/cdn/chunks/io-Da5POp5D.js +268 -0
  14. package/dist/cdn/chunks/preload-helper-DEpZAvig.js +1 -0
  15. package/dist/cdn/chunks/samples-BkLzaDJ3.js +1 -0
  16. package/dist/cdn/chunks/sigv4-EokFic1V-CWJiFeEe.js +3 -0
  17. package/dist/cdn/chunks/sources-cypher-BGGD4kJ9.js +5 -0
  18. package/dist/cdn/chunks/sources-ndex-CxnPOYff.js +1 -0
  19. package/dist/cdn/chunks/sources-rest-BPNV8mX-.js +1 -0
  20. package/dist/cdn/chunks/sources-sparql-BiqRQuHD.js +5 -0
  21. package/dist/cdn/cytoscape-extensions.js +1 -0
  22. package/dist/cdn/io.js +1 -0
  23. package/dist/cytoscape-extensions.bundle.js +2825 -0
  24. package/dist/elements.d.ts +69 -0
  25. package/dist/elements.d.ts.map +1 -0
  26. package/dist/elements.js +343 -0
  27. package/dist/elements.js.map +1 -0
  28. package/dist/gpu-platform-browser.d.ts +11 -0
  29. package/dist/gpu-platform-browser.d.ts.map +1 -0
  30. package/dist/gpu-platform-browser.js +22 -0
  31. package/dist/gpu-platform-browser.js.map +1 -0
  32. package/dist/gpu-platform-node.d.ts +15 -0
  33. package/dist/gpu-platform-node.d.ts.map +1 -0
  34. package/dist/gpu-platform-node.js +27 -0
  35. package/dist/gpu-platform-node.js.map +1 -0
  36. package/dist/gpu.d.ts +149 -0
  37. package/dist/gpu.d.ts.map +1 -0
  38. package/dist/gpu.js +312 -0
  39. package/dist/gpu.js.map +1 -0
  40. package/dist/graph-data.d.ts +101 -0
  41. package/dist/graph-data.d.ts.map +1 -0
  42. package/dist/graph-data.js +147 -0
  43. package/dist/graph-data.js.map +1 -0
  44. package/dist/index.d.ts +36 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +48 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/io.d.ts +111 -0
  49. package/dist/io.d.ts.map +1 -0
  50. package/dist/io.js +258 -0
  51. package/dist/io.js.map +1 -0
  52. package/dist/layouts.d.ts +207 -0
  53. package/dist/layouts.d.ts.map +1 -0
  54. package/dist/layouts.js +615 -0
  55. package/dist/layouts.js.map +1 -0
  56. package/dist/lazy.d.ts +21 -0
  57. package/dist/lazy.d.ts.map +1 -0
  58. package/dist/lazy.js +32 -0
  59. package/dist/lazy.js.map +1 -0
  60. package/dist/samples.d.ts +115 -0
  61. package/dist/samples.d.ts.map +1 -0
  62. package/dist/samples.js +237 -0
  63. package/dist/samples.js.map +1 -0
  64. package/dist/snapshot.d.ts +81 -0
  65. package/dist/snapshot.d.ts.map +1 -0
  66. package/dist/snapshot.js +225 -0
  67. package/dist/snapshot.js.map +1 -0
  68. package/dist/webgpu-provider.d.ts +25 -0
  69. package/dist/webgpu-provider.d.ts.map +1 -0
  70. package/dist/webgpu-provider.js +53 -0
  71. package/dist/webgpu-provider.js.map +1 -0
  72. package/package.json +13 -9
@@ -0,0 +1,268 @@
1
+ import{s as N,I as A,G as xp,M as cA,_ as Rr}from"./preload-helper-DEpZAvig.js";import{f as zo,t as Zm,a as $L,m as Qm,e as CL,s as vL,b as DL,c as kL}from"./elements-DkrLtNP8.js";const dA="E_FETCH",at="E_MISSING_ID",Jn="E_MISSING_ENDPOINT",sn="W_DUPLICATE_NODE",rs="E_NO_GRAPH",Zn="W_MULTIPLE_GRAPHS",Mt="E_EMPTY_INPUT",kn="E_SYNTAX",Vu="E_XML_SYNTAX",Ku="E_XML_NESTING",$t="W_UNKNOWN_ELEMENT",Xu="W_STRAY_TEXT",Mi="E_UNKNOWN_PARENT",uA="E_HYPEREDGE",RL="E_DUPLICATE_KEY",ln="W_COLUMN_RENAMED",LL="W_COLUMN_DROPPED",yn="W_ROLE_TAKEN",ie="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",bn="W_UNKNOWN_ENCODING",ul="W_ENCODING_CONFLICT",dd="W_CONTROL_CHARACTER",fA="E_FOREIGN_FORMAT",hA="W_ISSUES_SUPPRESSED",zd="W_UNKNOWN_XML_ATTRIBUTE",Ei="W_DIRECTION_REFUSED",Yn="W_DIRECTION_FORCED",Er="E_MIXED_DIRECTION",Wd="W_COUNT_HINT",Zt="W_UNKNOWN_ATTR_TYPE",Wo="W_BAD_DEFAULT",pA="W_BAD_OPTIONS",Oi="E_DUPLICATE_EDGE_ID",ne="E_BAD_VALUE",ua="W_WIDENED",Ki="W_DANGLING_REFERENCE",de="W_DUPLICATE_ATTRIBUTE",fl="E_PARENT_CYCLE",PL="W_EQUATION_AS_TEXT",Zs="W_STYLES_NOT_IMPORTED",pt="E_BAD_ASPECT_BLOCK",ey="W_MULTI_ASPECT_FRAGMENT",gA="W_SINGLE_OBJECT_ASPECT",qu="W_JSON_NONSTANDARD_NUMBER",Bn="W_ASPECT_ORDER",Us="W_COUNT_MISMATCH",Bd="E_STATUS_FAILED",ty="W_STATUS_WARNING",hl="E_TOO_LARGE",ny="E_COLUMN_TYPE",wr="E_GRAPH_NOT_FOUND",ss="E_AMBIGUOUS_GRAPH_NAME",xL="E_DUPLICATE_EDGE",ML="E_SELF_LOOP",UL="W_EDGES_MERGED",GL="W_SELF_LOOPS_DROPPED",X0="W_UNKNOWN_OPTION",jL="W_WEIGHT_NOT_FOUND",iy="W_ROLE_DROPPED",ry="W_PARENTS_DROPPED",mA="W_TEMPORAL_DROPPED",yA="W_MUTUAL_EXPANDED",bA="W_MUTUAL_AS_UNDIRECTED",os="W_ID_TEXT_TYPE",EA="E_ID_TEXT_COLLISION",wA="W_TEMPORAL_TEXT_DROPPED",FL="W_WEIGHTS_DROPPED",_A="W_WEIGHT_KEY_CLASH",Ja="W_ROLE_ASSUMED",SA="W_COLUMN_NAME_CHANGED",sy="W_EMPTY_COLUMN_DROPPED",OA="W_STORAGE_CLASS_CHANGED",zL="W_INTEGRAL_F64_AS_I32",WL="W_TEXT_INFERRED",Hd="E_XML_ILLEGAL_CHAR",oy="W_COLUMN_AS_PROPERTY_VALUE",ly="W_RELATION_ASSUMED",ay="W_TYPEDEF_NODES",Ju="W_GRAPH_COLUMN_AS_METADATA",Mp="W_DIRECTION_DROPPED",cy="W_NONFINITE_AS_NULL",Zu="W_NODE_ORDER",BL="W_OPTIONS_GAINED",Pn=Object.freeze({INVALID_ID:"E_INVALID_ID",UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",DUPLICATE_EDGE:xL,SELF_LOOP:ML,DUPLICATE_EDGE_ID:Oi}),xn=Object.freeze({EMPTY_INPUT:Mt,TOO_LARGE:hl,ENCODING_CONFLICT:ul,CONTROL_CHARACTER:dd,FOREIGN_FORMAT:fA,ISSUES_SUPPRESSED:hA});function O(t){return t===1?"":"s"}function C(t,e,n){return t===1?e:n}function NA(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 AA(t){return`${/^[aeiou]/i.test(t)?"an":"a"} ${t}`}class tt extends N{constructor(e,n,i){super("E_IMPORT",e,i),this.name="ImportError",Object.defineProperty(this,"report",{value:n,enumerable:!1}),this.issue=HL(n.issues,i?.code)}}function HL(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 wc=1e3,ud=new WeakMap,yh=Symbol("nothing kept");function YL(t){return ud.get(t)}const VL={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 q0(t,e){const n=e?.line;return n==null||t.includes(`line ${n}`)?t:`line ${n}: ${t}`}class te{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=yh,this.format=e,this.errorLimit=n,this.startedAt=J0()}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=_c(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: ${q0(i,r)}`,{code:n,limit:this.errorLimit});return o}warning(e,n,i,r,s){const o=_c(e,"warning",n,i,r,s),l=(this.warningsByCode.get(n)??0)+1;return this.warningsByCode.set(n,l),l<=wc&&(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 tt)){const i=VL[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 te(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 tt(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(_c(e,"error",n,i,r,o)),this.errors++,this.abort(q0(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===yh&&ud.has(e)&&(this.kept=ud.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>wc){const d=c-wc;o.push(_c("unsupported","warning",hA,`${d} more ${a} warning${O(d)} ${C(d,"was","were")} not kept (the report keeps the first ${wc})`,{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:J0()-this.startedAt});return this.kept!==yh&&ud.set(l,this.kept),l}}function _c(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 KL(t){if(typeof t!="object"||t===null)return!1;const{name:e}=t;return e==="AbortError"||e==="TimeoutError"}function XL(t){return t instanceof Error?t.message:typeof t=="string"?t:`non-error thrown (${typeof t})`}function J0(){return typeof performance=="object"?performance.now():Date.now()}const qL="graphty.directed",TA="graphty.pair",JL="graphty.mutual",Z0={name:qL,dtype:"bool",role:"directed"},Q0={name:TA,dtype:"u32",role:"pair",refersTo:"edge"},ZL={name:JL,dtype:"bool",role:"mutual"};class Qn{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",Yn,`the file declares ${Ni(e)} edges; read as ${Ni(i)} per onMixedDirection`,{line:n?.line??null},`${Yn}:${Ni(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",Ei,`the file is ${Ni(i)} but the sink is ${Ni(r.directed)} (${QL(s)}); read as ${Ni(r.directed)}`,{line:n?.line??null})}this.adoptExisting()}adoptExisting(){this.pairHandle===A&&this.sink.edgeColumn(TA)!==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",Yn,`${i} edges read as ${Ni(o.directed)} per onMixedDirection`,s,`${Yn}:${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",Er,`${i} edge in a ${Ni(o.directed)} graph (onMixedDirection: "error")`,s),this.report.abort("mixed direction refused",{code:Er});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",Ei,`${Ni(!0)} edge in a locked ${Ni(!1)} sink cannot be expanded`,s),this.report.abort("the sink refused the expansion to directed",{code:Ei,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(Z0),this.pairHandle=this.sink.declareEdgeColumn(Q0)}ensureExpansionColumns(){if(this.pairHandle===A&&(this.directedHandle=this.sink.declareEdgeColumn(Z0),this.pairHandle=this.sink.declareEdgeColumn(Q0),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(ZL))}}function QL(t){const{reason:e}=t.details;return typeof e=="string"?e:"refused"}function Ni(t){return t?"directed":"undirected"}function Ut(t,e={}){const n=e.foldMutual??!1,i=bh(t.edges.byRole("directed"),"bool"),r=bh(t.edges.byRole("pair"),"u32"),s=bh(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 bh(t,e){return t!==null&&t.dtype===e?t:null}function lt(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 je(t){return Object.is(t,-0)?"-0":String(t)}function Bi(t){return typeof t=="number"?je(t):t}function _r(t,e="f64"){if(!Number.isFinite(t))return String(t);if(Object.is(t,-0))return"-0.0";const n=Co(t,e);return n.includes(".")||n.includes("e")?n:`${n}.0`}function Gs(t,e="f64"){if(Number.isNaN(t))return"NAN";if(!Number.isFinite(t))return t>0?"+INF":"-INF";const n=_r(t,e);if(n.includes("."))return n;const i=n.indexOf("e");return`${n.slice(0,i)}.0${n.slice(i)}`}function Ue(t){return Number.isSafeInteger(t)||!Number.isFinite(t)?String(t):BigInt(t).toString()}function Co(t,e){return e==="f32"?lt(t):je(t)}const eP=1024,IA=4;function Yl(t){try{return new TextDecoder(t.trim()).encoding}catch{return null}}function tP(t){return ui(t,[255,254,0,0])?"utf-32le":ui(t,[0,0,254,255])?"utf-32be":ui(t,[239,187,191])?"utf-8":ui(t,[255,254])?"utf-16le":ui(t,[254,255])?"utf-16be":null}function ui(t,e){return t.byteLength>=e.length&&e.every((n,i)=>t[i]===n)}function nP(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 iP(t){return ui(t,[60,0,63,0])?"utf-16le":ui(t,[0,60,0,63])?"utf-16be":null}function $A(t){if(typeof t!="string"){if(ui(t,[31,139]))return"gzip-compressed data (decompress it first)";if(ui(t,[80,75,3,4])||ui(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(ui(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(DA)?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 CA(t,e,n){const i=$A(t);i!==null&&!(n.xml===!0&&i.startsWith("an HTML"))&&e.fail(fA,`the input is ${i}, not ${e.format} text`)}function rP(t,e){return t===e||t.startsWith("utf-16")&&e.startsWith("utf-16")}class sP{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){CA(e,this.report,this.options);const n=this.options.encoding??null,i=tP(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=iP(e);if(r!==null){this.checkDeclaration(e,r,"its XML declaration's byte pattern says"),this.use(r,!1);return}const s=nP(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",bn,`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&&!rP(s,n)&&this.conflict(`the input declares the encoding ${JSON.stringify(r)} but ${i} ${n}; read as ${n}`)}conflict(e){this.report.warning("coercion",ul,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:Yd([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:Yd([this.carry,e]),r=this.offset-this.carry.byteLength,s=this.encoding==="utf-8"?dP(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(lP(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=oP(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=pP(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 oP(t){for(let e=0;e<t.byteLength;e++)if(t[e]>=194&&vA(t,e))return e;return-1}function lP(t){const e=t.findIndex(n=>n>=128);return e>=0&&vA(t,e)}const aP=new TextDecoder("utf-8",{fatal:!0});function vA(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 aP.decode(t.subarray(e,e+i)),!0}catch{return!1}}const cP=[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 dP(t){let e=0;for(;e<t.byteLength;){const n=t[e],i=n<128?uP:fP(n);if(i===null)return{index:e,truncated:!1,cut:!1};const r=hP(t,e,i);if(r!==null)return r;e+=i.need+1}return{index:0,truncated:!1,cut:!1}}const uP={need:0,low:128,high:191};function fP(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 hP(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 pP(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 dy(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:cP[i-128]);return n}}function Yd(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 Fl=256*1024,DA="\uFEFF",eE=String.fromCodePoint(26),Bo=2**29-24,gP=new RegExp(`[${String.fromCodePoint(0)}-${String.fromCodePoint(8,11,14)}-${String.fromCodePoint(31,127)}-${String.fromCodePoint(159)}${DA}]`);function kA(t){return typeof t=="string"||Qu(t)!==null?!0:typeof t!="object"||t===null?!1:typeof t.getReader=="function"||Symbol.asyncIterator in t}function Qu(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 ef(t){if(typeof t=="string")return t;const e=Qu(t);if(e!==null)return e;if(kA(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 mP(t){return typeof t=="string"?t.length:t instanceof Uint8Array?t.byteLength:null}function Vd(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?yP():e}function yP(){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 RA(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 LA(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 PA{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?eE+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,CA(n,this.report,this.options)}return n.endsWith(eE)&&(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",dd,`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=gP.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",dd,`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",dd,"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(Mt,this.first?"the input is empty":"the input holds only whitespace")}}function xA(t,e){e!=null&&t.warning("unsupported",Jt,"option encoding has no effect on text input, which is already decoded",{element:"encoding"})}async function*Nr(t,e,n={}){const i=ef(t),r=n.signal??null,s=new PA(e,n);if(F(r),typeof i=="string"){xA(e,n.encoding),yield*EP(i,s,n);return}const o=new sP(e,n);if(i instanceof Uint8Array){yield*wP(i,s,o,n);return}const l=new _P(s,o,n);for await(const c of UA(i)?GA(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 bP(t,e){const n=Math.min(e+Fl,t.length),i=(t.charCodeAt(n-1)&64512)===55296;return n<t.length&&i?n+1:n}function*EP(t,e,n){const i=n.signal??null,r=n.onProgress??null,s=r===null?0:Vd(t);let o=0,l=0;for(;l<t.length;){F(i);const a=bP(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+=Vd(c),r(o,s))}t.length===0&&r?.(0,0),e.end()}function*wP(t,e,n,i){const r=i.signal??null,s=t.byteLength;n.start(t.subarray(0,MA(i)));for(let o=0;o<s;o+=Fl){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+Fl,s)),a=e.push(n.decode(l,o+Fl<s));a.length>0&&(yield a),i.onProgress?.(Math.min(o+Fl,s),s)}s===0&&i.onProgress?.(0,0),e.end()}function MA(t){return Math.max(t.declarationBytes??eP,IA)}class _P{constructor(e,n,i){this.filter=e,this.decoder=n,this.done=0,this.head=[],this.headLength=0,this.headBytes=MA(i),this.needed=i.declaredEncoding===void 0?IA:this.headBytes,this.counting=(i.onProgress??null)!==null}push(e){if(typeof e=="string")return this.done+=this.counting?Vd(e):0,this.filter.push(this.beforeText()+e);const n=Qu(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=Yd(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 UA(t){return typeof t.getReader=="function"}async function*GA(t,e){const n=LA(t);let i=!1;try{for(;;){F(e);const{done:r,value:s}=await RA(n.read(),e);if(r){i=!0;return}yield s}}finally{i||await n.cancel(e?.reason).catch(()=>{}),n.releaseLock()}}async function jA(t,e={}){const n=ef(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 UA(n)?GA(n,i):n){if(F(i),typeof o=="string")return null;const l=Qu(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):Yd(r)}function uy(t,e,n){t.failWith("unsupported",hl,e,n===void 0?void 0:{line:n})}async function Br(t,e,n={}){const i=ef(t);if(typeof i=="string"){F(n.signal),xA(e,n.encoding);const o=new PA(e,n),l=o.push(i);if(o.end(),n.onProgress!==null&&n.onProgress!==void 0){const a=Vd(i);n.onProgress(a,a)}return l}const r=[];let s=0;for await(const o of Nr(i,e,n))s+=o.length,s>Bo&&uy(e,`the document is longer than ${Bo} characters, the most one JavaScript string holds`),r.push(o);return r.length===1?r[0]:r.join("")}class Up{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 ${Bo} characters, the most one JavaScript string holds`}async*[Symbol.asyncIterator](){const e=new SP(i=>uy(this.report,this.lineTooLong(),i));let n=!1;for await(const i of Nr(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 OP(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 SP{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>Bo&&this.tooLong(n),this.pieces.push(e)}}class OP{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 FA="timeText",zi=".text",NP=/^(-?\d{4,})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?)?(Z|z|[+-]\d{2}(?::?\d{2})?)?$/,AP=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|z|[+-]\d{2}(?::?\d{2})?)?$/,zA=/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,Kd=6e4,vo=864e5;function Do(t,e){let n;switch(e){case"date":case"dateTime":case"localDateTime":n=TP(t,e);break;case"time":case"localTime":n=IP(t,e);break;default:{const r=e;throw new N("E_COLUMN_TYPE",`unknown temporal kind ${r}`,{kind:r})}}const i=fa(n,e);return{value:n,text:i===t?null:t}}function Xi(t,e){const n=t.trim();switch(e){case"integer":case"double":return tE(n);case"date":return Do(n,"date");case"dateTime":return Do(n,"dateTime");case null:return zA.test(n)?tE(n):Do(n,"dateTime");default:{const i=e;throw new N("E_COLUMN_TYPE",`unknown timeformat ${i}`,{timeFormat:i})}}}function fa(t,e){switch(e){case"date":{const n=new Date(t);return`${nE(n)}-${ws(n.getUTCMonth()+1)}-${ws(n.getUTCDate())}`}case"dateTime":case"localDateTime":{const n=new Date(t),i=`${nE(n)}-${ws(n.getUTCMonth()+1)}-${ws(n.getUTCDate())}`,r=iE(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%vo+vo)%vo,i=Math.floor(n/36e5),r=Math.floor(n%36e5/Kd),s=Math.floor(n%Kd/1e3),o=iE(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 Xd(t,e){switch(e){case"date":return fa(t,"date");case"dateTime":return fa(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 WA(t){return{name:t+zi,dtype:"string",role:FA,nullable:!0,extra:{for:t}}}function tE(t){if(!zA.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 TP(t,e){const n=NP.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:BA(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:HA(n[8]);return d.getTime()-u*Kd}function IP(t,e){const n=AP.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:BA(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:HA(n[5]);return((l-a*Kd)%vo+vo)%vo}function BA(t){return Math.floor(+`0.${t}`*1e3)}function HA(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 ws(t){return t<10?`0${t}`:String(t)}function nE(t){const e=t.getUTCFullYear(),n=String(Math.abs(e)).padStart(4,"0");return e<0?`-${n}`:n}function iE(t,e,n,i){const r=`${ws(t)}:${ws(e)}:${ws(n)}`;return i===0?r:`${r}.${String(i).padStart(3,"0")}`}const fy={dtype:"bool",kind:"boolean"},Hr={dtype:"i32",kind:"integer"},qd={dtype:"f64",kind:"long",precision:!0},hy={dtype:"f32",kind:"float"},tf={dtype:"f64",kind:"double"},ki={dtype:"string",kind:"string"},YA={dtype:"f64",kind:"temporal",temporal:"date"},VA={dtype:"f64",kind:"temporal",temporal:"dateTime"},$P={dtype:"f64",kind:"temporal",temporal:"localDateTime"},CP={dtype:"f64",kind:"temporal",temporal:"time"},vP={dtype:"f64",kind:"temporal",temporal:"localTime"},DP={dtype:"string",kind:"duration"},kP={dtype:"json",kind:"point"},RP={dtype:"json",kind:"json"},LP={integer:Hr,long:qd,double:tf,float:hy,boolean:fy,string:ki,anyuri:ki,char:ki,byte:Hr,short:Hr,bigdecimal:ki,biginteger:ki,date:YA,datetime:VA},PP={boolean:fy,int:Hr,long:qd,float:hy,double:tf,string:ki},xP={int:Hr,real:tf,string:ki,record:RP},MP={int:Hr,integer:qd,long:qd,float:hy,double:tf,boolean:fy,byte:Hr,short:Hr,char:ki,string:ki,point:kP,date:YA,localtime:vP,time:CP,localdatetime:$P,datetime:VA,duration:DP},UP={gexf:LP,graphml:PP,gml:xP,neo4j:MP},rE=/^[+-]?\d+$/,KA=/^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,GP=-2147483648,jP=2147483647;function py(t,e,n){const i=UP[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=ki),{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 sE(t){return{declared:t??"",dtype:"string",itemDtype:null,kind:"string",list:!1,temporal:null,precision:!1}}function FP(t,e,n=null){switch(e){case"boolean":{const i=zP(t);if(i===null)throw ar(t,e);return i}case"integer":{const i=t.trim();if(!rE.test(i))throw ar(t,e);const r=Number(i);if(r<GP||r>jP)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(!rE.test(i))throw ar(t,e);return Number(i)}case"float":case"double":return gy(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 Do(t.trim(),n).value}case"point":return WP(t);case"json":return BP(t);default:{const i=e;throw new N("E_COLUMN_TYPE",`unknown value kind ${i}`,{kind:i})}}}function zP(t){switch(t.trim().toLowerCase()){case"true":case"1":return!0;case"false":case"0":return!1;default:return null}}function gy(t,e="double"){const n=t.trim();if(KA.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 ar(t,e)}}function Gp(t){const e=t.trim();return/^[+-]?[0-9.]/.test(e)&&Number(e)===(e.startsWith("-")?-1/0:1/0)}function WP(t){const e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))throw ar(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 ar(t,"point");const o=r.slice(0,s).trim().replaceAll(/(?:^["'])|(?:["']$)/g,""),l=r.slice(s+1).trim();if(o.length===0)throw ar(t,"point");if(KA.test(l))n[o]=Number(l);else if(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))n[o]=l.slice(1,-1);else throw ar(t,"point")}return n}function BP(t){try{return JSON.parse(t)}catch{throw ar(t,"json")}}function ar(t,e){const n=t.length>40?`${t.slice(0,40)}...`:t;return new N("E_COLUMN_TYPE",`"${n}" is not ${AA(e)}`,{value:t,kind:e})}function ha(t,e){const n=t.trim();if(n.length===0)return[];switch(e){case"gexf":{if(oE(n))return lE(n);const i=HP(n,["|",",",";"]);return i===null?[n]:Sc(n,i)}case"brackets":return oE(n)?lE(n):[n];case"pipe":return Sc(n,"|");case"comma":return Sc(n,",");case"semicolon":return Sc(n,";");default:{const i=e;throw new N("E_UNSUPPORTED",`unknown list syntax ${i}`,{option:"listSyntax",found:i})}}}function my(t,e){switch(e){case"gexf":case"brackets":return`[${t.map(KP).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 oE(t){return t.length>=2&&t.startsWith("[")&&t.endsWith("]")}function HP(t,e){for(const n of e)if(t.includes(n))return n;return null}function Sc(t,e){return t.split(e).map(n=>n.trim())}function lE(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&&VP(e.charCodeAt(r));)r++;let s="";if(r<i&&(e[r]==='"'||e[r]==="'")){const l=YP(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 YP(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 VP(t){return t===32||t===9||t===13||t===10}function KP(t){return t.length===0||/[,[\]"']/.test(t)||t!==t.trim()?`"${t.replaceAll('"','""')}"`:t}const XP=Zt,Za=ln,nf=1024;function pa(t){const e=[],n=t.listSyntax??"gexf";let i=qP(t,e);const{name:r,renamed:s}=tx(t);s&&e.push({category:"coercion",code:Za,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=JP(o,i,l,n,e));const a=t.defaultText??null;if(a!==null)try{o.default=ga(a,i,n)}catch(d){e.push({category:"validation-error",code:Wo,message:`default "${a}" of attribute "${r}" does not parse as ${i.declared}: ${XA(d)}`})}const c=i.temporal!==null&&!i.list?WA(r):null;return{decl:o,spec:i,listSyntax:n,companion:c,renamed:s,issues:e}}function qP(t,e){if(t.type===null)return sE(null);const n=py(t.format,t.type,t.long);return n!==null?n:(e.push({category:"unsupported",code:XP,message:`${t.format} type "${t.type}" is not supported; values kept as text`}),sE(t.type))}function JP(t,e,n,i,r){try{const s=ha(n,i).map(o=>Fp(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:pA,message:`options "${n}" of attribute "${t.name}" do not parse as ${e.declared}: ${XA(s)}`})}return e}function ga(t,e,n){return e.list?ha(t,n).map(i=>Fp(i,e)):Fp(t,e)}function jp(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 Do(t.trim(),e.temporal)}const ZP=/^[+-]?\d+$/;function Jd(t,e){if(!t.precision)return!1;const n=e.trim();if(!ZP.test(n))return!1;const i=Number(n);return!Number.isFinite(i)||BigInt(n)!==BigInt(i)}function ko(t,e,n){return e==="node"?t.declareNodeColumn(n):t.declareEdgeColumn(n)}function fe(t,e,n,i,r){let s=n,o=!1,l=!1;for(;;)try{return{handle:ko(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=QP(t,e,s,i,r),o=!0;continue}if(a.code==="E_DUPLICATE_ROLE"&&s.role!==void 0&&!l){s=ex(a,e,s,s.role,i,r),l=!0;continue}throw a}}function QP(t,e,n,i,r){const s=Zd(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 ex(t,e,n,i,r,s){const o=typeof t.details.holder=="string"?t.details.holder:"another column";r.warning("coercion",yn,`${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 yy(t,e,n,i){try{return ko(t,e,n)}catch(r){if(r instanceof N&&r.code==="E_DUPLICATE_ROLE"){i?.warnOnce("coercion",yn,`${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 ko(t,e,o)}throw r}}function Zd(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 Qs{constructor(e=nf){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 tx(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 Fp(t,e){return FP(t,e.kind,e.temporal)}function XA(t){return t instanceof Error?t.message:String(t)}const nx=/^-?(0|[1-9]\d*)$/;function Qa(t){if(t!=="-0"&&nx.test(t)){const e=Number(t);if(Number.isSafeInteger(e))return e}return t}function Qd(t){return typeof Qa(t)=="number"}function rf(t,e){switch(e){case"keep":case"string":return t;case"canonical":return Qa(t);case"number":{if(t.trim().length===0)throw eu(t,"empty text is not a number");const n=Number(t);if(!Number.isFinite(n))throw eu(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 ix(t,e){if(typeof t=="string")return rf(t,e);if(typeof t=="number"){if(!Number.isFinite(t))throw eu(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 eu(t,`a ${t===null?"null":typeof t} is not an id under ids: "${e}"`)}function eu(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=rf(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,ix(e,this.mode))}}const rx=new Set(["keep","canonical","string","number"]),sx=new Set(["id","label","index"]),ox=new Set(["keep","error","first","last","sum","min","max"]),lx=new Set(["keep","drop","error"]),ax=new Set(["expand","directed","undirected","error"]),cx=new Set(["error","directed","undirected"]),dx=new Set(["f32","f64"]),ux=new Set(["f64","string"]),fx=new Set(["error","skip","star","clique"]),hx=new Set(["error","mangle"]),px=100,qA=["addMissingNodes","duplicateEdges","selfLoops","weightDtype"];function bt(t,e,n,i=!1){if(e===void 0)return 0;let r=0;for(const s of qA){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 gx=["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","hyperedges"],mx={nodeIdFrom:"id",duplicateEdges:"keep",selfLoops:"keep",onMixedDirection:"expand",weightDtype:"f64",long:"f64",restoreMangledIds:!0,hyperedges:"skip"};function Et(t,e,n){if(t===void 0)return 0;let i=0;for(const r of gx){if(n.has(r)||qA.includes(r))continue;const s=t[r];s===void 0||s===mx[r]||(e.warning("unsupported",Jt,`option ${r}: ${JSON.stringify(s)} has no effect on the ${e.format} importer`,{element:r}),i++)}return i}function eo(t){return t?.graphIndex!==void 0||t?.graphName!==void 0}function aE(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 pl(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: ${Hi(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: ${Hi(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(rs,"the input holds no graph");if(r!==void 0){const o=t.flatMap((l,a)=>l===r?[a]:[]);return o.length>1?n.fail(ss,`graphName ${JSON.stringify(r)} names the graphs at indexes ${o.join(", ")}; pass graphIndex`,{element:r}):o.length===0?n.fail(wr,`graphName ${JSON.stringify(r)} names none of the ${t.length} graph${O(t.length)}${aE(t)}`,{element:r},{names:[...t]}):o[0]}const s=i??0;return s>=t.length?n.fail(wr,`graphIndex ${s} is beyond the ${t.length} graph${O(t.length)}${aE(t)}`):s}function Qe(t,e){const n=t??{};return Object.freeze({ids:Ci("ids",n.ids,e.ids,rx),nodeIdFrom:Ci("nodeIdFrom",n.nodeIdFrom,"id",sx),addMissingNodes:Eh("addMissingNodes",n.addMissingNodes,e.addMissingNodes??!0),duplicateEdges:Ci("duplicateEdges",n.duplicateEdges,"keep",ox),selfLoops:Ci("selfLoops",n.selfLoops,"keep",lx),onMixedDirection:Ci("onMixedDirection",n.onMixedDirection,"expand",ax),defaultDirected:Eh("defaultDirected",n.defaultDirected,e.defaultDirected),weightFrom:yx(n.weightFrom,e.weightFrom),weightDtype:Ci("weightDtype",n.weightDtype,"f64",dx),long:Ci("long",n.long,"f64",ux),restoreMangledIds:Eh("restoreMangledIds",n.restoreMangledIds,!0),hyperedges:Ci("hyperedges",n.hyperedges,"skip",fx),errorLimit:bx(n.errorLimit),signal:Ex(n.signal),onProgress:wx(n.onProgress),encoding:_x(n.encoding)})}function dt(t){const e=t??{};return Object.freeze({sanitizeIds:Ci("sanitizeIds",e.sanitizeIds,"error",hx),onMixedDirection:Ci("onMixedDirection",e.onMixedDirection,"error",cx)})}function Ci(t,e,n,i){if(e===void 0)return n;if(typeof e!="string"||!i.has(e))throw new N("E_UNSUPPORTED",`option ${t}: ${Hi(e)} is not one of ${Ox(i)}`,{option:t,found:e,supported:[...i]});return e}function Eh(t,e,n){if(e===void 0)return n;if(typeof e!="boolean")throw new N("E_UNSUPPORTED",`option ${t}: ${Hi(e)} is not a boolean`,{option:t,found:e});return e}function yx(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: ${Hi(t)} is not an attribute name or null`,{option:"weightFrom",found:t})}function bx(t){if(t===void 0)return px;if(typeof t=="number"&&t>=0&&(Number.isInteger(t)||t===1/0))return t;throw new N("E_UNSUPPORTED",`option errorLimit: ${Hi(t)} is not a non-negative integer or Infinity`,{option:"errorLimit",found:t})}function Ex(t){if(t==null)return null;if(typeof t=="object"&&typeof t.aborted=="boolean")return t;throw new N("E_UNSUPPORTED",`option signal: ${Hi(t)} is not an AbortSignal`,{option:"signal",found:typeof t})}function wx(t){if(t==null)return null;if(typeof t=="function")return t;throw new N("E_UNSUPPORTED",`option onProgress: ${Hi(t)} is not a function`,{option:"onProgress",found:typeof t})}function _x(t){if(t==null)return null;const e=typeof t=="string"?Yl(t):null;if(e===null)throw new N("E_UNSUPPORTED",`option encoding: ${Hi(t)} is not an encoding this platform's TextDecoder knows`,{option:"encoding",found:t});return e}const Sx=Object.freeze({csv:Object.freeze(["gephi","generic"]),json:Object.freeze(["node-link","d3","jgf","cytoscape","graphology","vis","obographs"])});function JA(t,e){return typeof e=="string"&&Object.entries(Sx).some(([n,i])=>n!==t&&i.includes(e))}function Hi(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 Ox(t){return[...t].map(e=>JSON.stringify(e)).join(", ")}const Nx=1;function by(t,e){return e!==null&&t===e}function Vn(t,e){const n=t.trim();if(n.length===0)return;let i;try{i=gy(n)}catch(r){throw tu(t,r)}if(Number.isNaN(i))throw tu(t,null);return e!==void 0&&ZA(n,i,e),i}function ZA(t,e,n){!Number.isSafeInteger(e)&&Number.isFinite(e)&&/^[+-]?\d+$/.test(t)&&BigInt(t)!==BigInt(e)&&n.warnOnce("precision",ie,`edge weights: integers beyond 2^53 are stored as the nearest double (first: ${t})`,void 0,`${ie}:edge weight`)}function sf(t){if(t!=null){if(typeof t=="number"){if(Number.isNaN(t))throw tu(t,null);return t}if(typeof t=="string")return Vn(t);throw tu(t,null)}}function tu(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 cE="-0",Ax=new Set(["f32","f64","i32","u32","u8"]);function Tx(t){switch(t){case"f32":return lt;case"f64":return je;default:return Ue}}function wt(t){const e=t.edges.byRole("weight"),n=e!==null&&Ax.has(e.dtype)?e:null;if(n!==null){const r=n.dtype==="f32"?"f32":"f64",s=Tx(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)?cE:l&&Number.isInteger(a)?Ue(a):s(a)}}}const{weights:i}=t.edgeList();return i===null||!t.flags.weighted?{weighted:!1,dtype:"f32",isExplicit:()=>!1,value:()=>Nx,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)?cE:s&&Number.isInteger(o)?Ue(o):lt(o)}}}const Ix="E_ID_CHARSET",w=Object.freeze({COLUMN_DROPPED:LL,MIXED_DIRECTION:"W_MIXED_DIRECTION",MIXED_DIRECTION_ERROR:Er,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:Ix,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:mA,TEMPORAL_TEXT:wA,ROLE:iy,PARENTS:ry,MUTUAL_EXPANDED:yA,MUTUAL_AS_UNDIRECTED:bA,ID_TEXT_TYPE:os,ID_TEXT_COLLISION:EA,WEIGHT_KEY_CLASH:_A,ROLE_ASSUMED:Ja,COLUMN_NAME_CHANGED:SA,EMPTY_COLUMN:sy,STORAGE_CLASS:OA,INTEGRAL_F64:zL,TEXT_INFERRED:WL,XML_ILLEGAL_CHAR:Hd,OPTIONS_GAINED:BL,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:cy,WEIGHTS_DROPPED:FL}),$x=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 Xe(t){return Object.freeze({...$x,...t,dtypes:Object.freeze([...t.dtypes??[]])})}const Cx=new Set(["directed","pair","mutual","weight","originalId"]),vx=new Set(["color","size","shape","thickness"]),Dx=new Set(["start","end","timestamp","timestamps"]),kx=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&&Rx(t,e,n,s);const a=QA(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)} ${zp(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)} ${zp(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);rf(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&&xx(t,i,s),o.includes("node")&&wh(t.nodes,"node",e,i,s),l&&wh(t.edges,"edge",e,i,s);const c=o.includes("graph")?t.graph.names():[];c.length>0&&(e.graphAttributes?wh(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 Rx(t,e,n,i){const r=gl(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=Yx(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 zp(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 Lx(t,e){return t==="node"?e.nodeRoleNames??e.roleNames:t==="edge"?e.edgeRoleNames??e.roleNames:e.roleNames}function Px(t,e){return t==="node"?e.nodeAttributes??e.attributes:t==="edge"?e.edgeAttributes??e.attributes:e.attributes}function xx(t,e,n){e.weights===!1&&wt(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 Mx={label:"labels",weight:"weights",id:"ids",position:"positions",originalId:"original ids"};function fi(t){return t.length-t.nullCount}function wh(t,e,n,i,r){const s={domain:e,caps:n,extras:i,note:r};for(const o of t)Ux(o,s)}function Ux(t,e){const{name:n,role:i}=t.meta;if(i!==null&&Cx.has(i))return;const r=`${e.domain} column "${n}"`;if(Gx(t,r,e),e.domain==="edge"&&i==="id")return;if(jx(t,e)){e.note(w.COLUMN_DROPPED,`${r} is not written`,n,fi(t));return}const s=i===null?void 0:Fx.find(([o])=>o(i));if(s!==void 0){s[1](t,r,e);return}Bx(t,r,e)}function Gx(t,e,n){const{name:i,role:r}=t.meta,s=r===null?void 0:Lx(n.domain,n.extras)?.[r];r!==null&&s!==void 0&&s!==i&&n.note(w.COLUMN_NAME_CHANGED,`${e} (the ${Mx[r]??r}) is written as the format's own ${r} and reads back as "${s}"`,i,fi(t))}function jx(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 Px(r,s)===!1&&!o&&!l}const Fx=[[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,fi(t))}],[t=>t==="position",zx],[t=>vx.has(t),Wx],[t=>kx.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,fi(t))}}],[t=>Dx.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,fi(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,fi(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,fi(t))}]];function zx(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,fi(t)):s(w.POSITIONS,`${e} (positions) cannot be written`,o.name,fi(t))}function Wx(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,fi(t))}function Bx(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,fi(t)),o.dynamic&&i.temporal!=="dynamic-values"&&s(w.DYNAMIC_VALUES,`${e} is dynamic; only its static value can be written`,l,null),Hx(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 Hx(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 gl(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 Yx(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 Vx=[[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 ml(t){for(const[e,n]of Vx){if(t<e)return!1;if(t<=n)return!0}return!1}function yl(t){if(t.length===0)return!1;for(const e of t){const n=e.codePointAt(0);if(n===void 0||!ml(n))return!1}return!0}function Wp(t,e){switch(e){case"any":return!0;case"nmtoken":return yl(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 QA(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++)Wp(n.idOf(r),e)||i++;return i}function bl(t,e,n){const{ids:i}=t,r=i.size;if(e==="dense-1-based"){const a=QA(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++)Wp(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)} ${zp(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);Wp(d,e)&&a.add(String(d))}for(const c of o){const d=eT(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 eT(t){let e="";for(const n of t){const i=n.codePointAt(0);e+=i!==void 0&&ml(i)?n:"_"}return e.length===0?"_":e}const tT=/^-?(0|[1-9]\d*)$/,Kx=/^[+-]?((0|[1-9]\d*)(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/,Xx=-2147483648,qx=2147483647;function nT(t){let e=t.length;for(;e>0&&t[e-1]==="0";)e--;return t.slice(0,e)}function Xn(t){if(t==="true"||t==="false")return"bool";if(tT.test(t)){const e=Number(t);return e>=Xx&&e<=qx?"i32":Number.isFinite(e)?"f64":"string"}return Kx.test(t)&&Number.isFinite(Number(t))?"f64":"string"}function of(t){switch(Xn(t)){case"bool":return t==="true";case"i32":case"f64":return Number(t);case"string":return t;default:return t}}function li(t){const e=Xn(t);return e==="i32"||e==="f64"}function Jx(t,e){return String(e)===t}function Oc(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 Ey{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=Xn(n),r=of(n);this.warnIfImprecise(n,r);const s=this.textDtype==="string",o=this.textDtype===null||Oc(i)>Oc(this.textDtype)?i:this.textDtype;this.set(e,o==="string"?n:r),this.textDtype=o;const l=Zx(r);if((this.valueDtype===null||Oc(l)>Oc(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"&&!Jx(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)&&tT.test(e)&&BigInt(e)!==BigInt(n)&&this.report.warnOnce("precision",ie,`${this.domain} column "${this.name}": integers beyond 2^53 are stored as the nearest double (first: ${e})`,{element:this.name},`${ie}:${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",lf,`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 lf="W_WIDENING_UNSUPPORTED";function Zx(t){return typeof t=="boolean"?"bool":typeof t=="string"?"string":Number.isInteger(t)&&t>=-2147483648&&t<=2147483647?"i32":"f64"}class Qx{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 ec(t,e={}){const n=i2(t,e.column===void 0?"auto":e.column);return e2(t.nodeCount,n)}function e2(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=t2(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 Qx(t,n,o,i,r,e)}function t2(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 n2(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 n2(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 i2(t,e){return typeof e!="string"?e:e==="parent"||e==="parents"?t.nodes.byRole(e):t.nodes.byRole("parent")??t.nodes.byRole("parents")}const r2=64*1024;async function*ei(t,e=r2){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 ti(t){const e=[];for await(const n of t)e.push(n);return e.join("")}async function s2(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 iT(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 wy="E_CSV_UNCLOSED_QUOTE",_y="E_CSV_QUOTE",js=Object.freeze([","," ",";","|"," "]),Sy=10,dE=64*1024,Ri=10,cr=13,rT=9,sT=32,o2=/^sep=([^\r\n])(?:\r\n|\n|\r|$)/i,ht=0,_s=1,ir=2,Vl=3,fd=4,Nc=5;function Oy(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 oT(t){return!t.includes(`
5
+ `)&&t.includes("\r")?"\r":`
6
+ `}function af(t,e,n,i,r=!1,s=!1){const o=e.codePointAt(0),l=new l2(t,n,o,s&&o===sT,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 l2{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=ht,this.segment=0,this.field="",this.quoteCode=n.codePointAt(0)}step(e){const n=this.text.codePointAt(e);if(this.state===ir)return n===this.quoteCode&&(this.field+=this.text.slice(this.segment,e),this.state=Vl),e+1;const i=n===this.delimiterCode||this.whitespace&&n===rT;if(this.state===Vl){const r=this.afterQuote(e,n,i||n===Ri||n===cr);if(r!==null)return r}if(i||n===Ri||n===cr)return this.separator(e,i);if(this.state===ht){const r=n===this.quoteCode;this.state=r?ir:_s,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=ir,e+1):this.strictQuotes&&!i?-1:(this.state=fd,this.segment=e,null)}separator(e,n){(this.state===_s||this.state===fd)&&(this.field+=this.text.slice(this.segment,e));let i=e+1;return n&&this.whitespace&&this.state===ht||(n?(this.cells.push(this.field),this.field="",this.state=ht):(this.endRow(),this.state=ht,this.text.codePointAt(e)===cr&&this.text.codePointAt(e+1)===Ri&&(i=e+2))),this.segment=i,i}endRow(){this.state===ht&&this.cells.length===0||(this.whitespace&&this.state===ht||this.cells.push(this.field),this.rows.push(this.cells),this.cells=[],this.field="")}finish(){this.state===ht&&this.cells.length===0||((this.state===_s||this.state===fd||this.state===ir)&&(this.field+=this.text.slice(this.segment)),this.whitespace&&this.state===ht||this.cells.push(this.field),this.rows.push(this.cells))}}function lT(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 Ny(t,e=`
9
+ `,n=js,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=af(t,c,i,Sy,r,s);if(d===null)continue;let u=d.filter(p=>!c2(p));if(u.length>1&&!a&&(u=u.slice(0,-1)),u.length===0)continue;const{average:f,delta:h}=a2(u);f>1.99&&h<l&&(o=c,l=h)}return o}function a2(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 c2(t){return t.length===1&&t[0].trim().length===0}class aT{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 u2(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(_y,`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(wy,`a quoted field starting on line ${e} is never closed`,{line:e})}async*chunks(){const e=Nr(this.input,this.report,this.readOptions);if(this.delimiterText!==null){yield*e;return}const n=[];let i=0,r=!1;const s=new d2((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<Sy&&i<dE)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,dE),i=lT(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?o2.exec(e):null;if(r!==null&&r[1]!==this.syntax.quote){this.delimiterText=r[1],this.sepDirective=!0;return}const s=this.syntax.candidates??js;this.delimiterText=Ny(i,oT(i),s,this.syntax.quote,this.syntax.skipQuoteErrors,this.syntax.collapseSpaces)??s[0]}}class d2{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<Sy;n++){const i=e.charCodeAt(n);i===Ri||i===cr?this.lineBreak(i):this.character(i),this.lastWasCr=i===cr}}lineBreak(e){!(e===Ri&&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 u2{constructor(e){this.ready=!1,this.count=0,this.recordLine=1,this.startLine=1,this.delimiterCode=-1,this.collapse=!1,this.state=ht,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===sT&&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===Nc){this.commentChar(e,s,o),s++;continue}if(l===ir){s=this.quotedRun(e,s);continue}const a=o===i||this.collapse&&o===rT;if(l===Vl||a||o===Ri||o===cr){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!==Ri&&i!==cr||(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=ht,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=Vl,this.lastWasCr=!1,i+1)}boundary(e,n,i,r){if(this.state===Vl){if(i===this.quoteCode)return this.field=this.grow(this.field,this.quoteText),this.segment=n+1,this.state=ir,this.lastWasCr=!1,n+1;!r&&i!==Ri&&i!==cr&&this.reader.badQuote(this.startLine,this.count+1),this.state=fd,this.segment=n}return i===Ri&&this.lastWasCr?(this.lastWasCr=!1,this.segment=n+1,n+1):(this.state===_s&&(this.field=this.grow(this.field,e.slice(this.segment,n))),r?(this.collapse&&this.state===ht||(this.push(),this.state=ht),this.lastWasCr=!1,this.segment=n+1,n+1):(this.lineEnd(i),this.segment=n+1,n+1))}lineEnd(e){this.state===ht&&(this.count===0||this.collapse)||this.push(),this.count>0&&(this.ready=!0,this.recordLine=this.startLine),this.state=ht,this.endLine(e)}fieldChar(e,n){if(this.lastWasCr=!1,this.state!==ht){e===this.quoteCode&&this.state===_s&&this.reader.strayQuoteLine===0&&(this.reader.strayQuoteLine=this.startLine);return}if(this.leading&&this.count===0&&this.commentCodes.includes(e)){this.state=Nc,this.segment=n;return}this.leading=!1,e===this.quoteCode?(this.state=ir,this.fieldQuoted=!0,this.segment=n+1):(this.state=_s,this.segment=n)}endChunk(e){const n=e.length;this.segment>=n||(this.state===Nc?this.comment=this.grow(this.comment,e.slice(this.segment,n)):(this.state===ir||this.state===_s)&&(this.field=this.grow(this.field,e.slice(this.segment,n))),this.segment=n)}finish(){const{state:e}=this;return e===Nc?(this.reader.leadingComments.push(this.comment),this.reader.leadingCommentLines.push(this.line),!1):(e===ir&&this.reader.unclosedQuote(this.startLine),e!==ht||this.count>0?(e===ht&&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>Bo&&uy(this.reader.report,`a cell is longer than ${Bo} 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===Ri&&this.lastWasCr||this.line++,this.startLine=this.line,this.lastWasCr=e===cr}}class cT{constructor(e,n,i={}){this.inner=new aT(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)f2(e.cells,e.quoted,n)||(yield e.cells.slice(0,n))}}function f2(t,e,n){for(let i=0;i<n;i++)if(e[i]||t[i].trim().length>0)return!1;return!0}class ee extends Error{constructor(e,n){super(e),this.name="XmlSyntaxError",this.line=n}}const dT=1e5;class cf extends ee{constructor(e,n){super(`<${e}> is nested more than ${String(dT)} elements deep`,n),this.name="XmlNestingError"}}class Ay extends ee{constructor(e){super("the input is empty: no root element",e),this.name="XmlEmptyInputError"}}const h2=7,uT=/^&#(?:[xX]([0-9a-fA-F]{1,6})|(\d{1,7}));/,p2=/&#(?:[xX]([0-9a-fA-F]{1,6})|(\d{1,7}));$/,g2={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"},m2=60,uo=62,y2=47,b2=61,Ac=34,_h=39,E2=91,w2=93,_2=33,Sh=45,uE=63,S2=16,fE=9;function hd(t){return t===32||t===9||t===10||t===13}function Ty(t){return!ml(t)||t>=48&&t<=57||t===45||t===46||t===183?!1:!(t>=768&&t<=879)&&t!==8255&&t!==8256}const Iy=new Uint8Array(128),$y=new Uint8Array(128);for(let t=0;t<128;t++)Iy[t]=Ty(t)?1:0,$y[t]=ml(t)?1:0;const fT=new RegExp("[\0-\b\v\f-\\uFFFE\\uFFFF\\uD800-\\uDFFF]","u");function Fs(t){return fT.test(t)}function hE(t){const e=fT.exec(t);return e===null?-1:e.index}function Cy(t){const e=[];let n=0;for(let i=0;i<t.nodeCount;i++){const r=t.ids.idOf(i);typeof r=="string"&&Fs(r)&&n++}n>0&&e.push(Object.freeze({code:Hd,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=O2(s);o>0&&e.push(Object.freeze({code:Hd,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 O2(t){let e=0;if(t.dtype==="string"||t.dtype==="dict")for(let n=0;n<t.length;n++)t.isSet(n)&&Fs(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"&&Fs(i))&&e++;return e}const N2=/^<\?xml\s[^>]*?\bencoding\s*=\s*["']([A-Za-z][A-Za-z0-9._-]*)["']/;function df(t){const e=N2.exec(t);return e===null?null:e[1]}function hT(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 nu(t){if(t.length===0)return!1;for(let e=0;e<t.length;){const n=t.codePointAt(e)??0;if(!A2(n,e===0))return!1;e+=n>65535?2:1}return!0}function A2(t,e){return t<128?(e?Iy[t]:$y[t])===1:e?Ty(t):ml(t)}function T2(t){return t===9||t===10||t===13||t>=32&&t<=55295||t>=57344&&t<=65533||t>=65536&&t<=1114111}function I2(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>h2)&&!uT.test(t.slice(i,i+12))){n.bareAmpersand(xr(t,i,e)),r+="&",s=i+1,i=t.indexOf("&",s);continue}if(o<0)throw new ee("unterminated entity reference",xr(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?$2(t,o+1,n):null;if(h!==null){n?.surrogatePair?.(xr(t,i,e)),r+=String.fromCharCode(f,h.unit),s=h.end,i=t.indexOf("&",s);continue}if(f<0||!T2(f))throw new ee(`invalid character reference &${l};`,xr(t,i,e));r+=String.fromCodePoint(f)}else{const a=g2[l];if(a===void 0)throw new ee(`unknown entity &${l};`,xr(t,i,e));r+=a}s=o+1,i=t.indexOf("&",s)}return r+t.slice(s)}function xr(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 $2(t,e,n){if(n?.surrogatePair===void 0||t.charCodeAt(e)!==38)return null;const i=uT.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 Sr(t){for(let e=0;e<t.length;e++)if(!hd(t.charCodeAt(e)))return!1;return!0}function vs(t){const e=t.lastIndexOf(":");return e<0?t:t.slice(e+1)}async function uf(t,e,n){const i=new D2(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 ee("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 ee&&i.declaresXml11&&!l.message.includes("XML 1.1")?new ee(`${l.message}; the document declares XML 1.1, which graph-io does not read (it reads XML 1.0)`,l.line):l}}const pE={comment:"-->",cdata:"]]>",pi:"?>",endtag:">"},C2="http://www.w3.org/XML/1998/namespace",v2=["<!--","<![CDATA[","<!DOCTYPE"];class D2{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 ee("unexpected end of input inside markup",this.line);if(this.flushText(),this.stack.length>0)throw new ee(`unclosed element <${this.stack[this.stack.length-1]}>`,this.line);if(!this.rootSeen)throw this.markupSeen?new ee("no root element",this.line):new Ay(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 ee("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=pE[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===Ac||l===_h)r=l;else if(l===uo)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===uo&&a===1?(l=!1,a=0):a=d===uE?1:0;continue}if(o){d===Sh?a++:(d===uo&&a>=2&&(o=!1),a=0);continue}if(r!==0){d===r&&(r=0);continue}if(s>0){if(a===1&&d===_2){a=2;continue}if(a===2&&d===Sh){a=3;continue}if(a===3&&d===Sh){o=!0,a=0;continue}if(a===1&&d===uE){l=!0,a=0;continue}if(a=0,d===m2){a=1;continue}}if(d===Ac||d===_h)r=d;else if(d===E2)s++;else if(d===w2)s--;else if(d===uo&&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-S2||/^&#[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<fE)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=pE[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(!nu(s))throw new ee(`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=hE(i);if(r>=0)throw new ee("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<fE){const s=n.slice(e);if(!this.final||v2.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 ee(`<!${n.slice(e+2,e+9)}> is not XML (it must be written <!DOCTYPE>); the input looks like an HTML document`,this.line):new ee("unexpected markup declaration",this.line);if(this.rootSeen||this.doctypeSeen)throw new ee("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(!nu(r))throw new ee(`a processing instruction needs a target name, not "${r}"`,this.line);if(r.toLowerCase()!=="xml")return;if(r!=="xml")throw new ee(`<?${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 ee("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 ee("the XML declaration has no version",this.line);if(!/^1\.\d+$/.test(s))throw new ee(`XML version ${s} is not supported (only 1.x)`,this.line);this.version=s}lineIn(e,n){return xr(this.buffer.slice(e,n),n-e,this.line)}decode(e,n){try{return I2(e,n,this.repairs)}catch(i){throw i instanceof ee&&this.version!==null&&this.version!=="1.0"?new ee(`${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 ee("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&&hd(n.charCodeAt(r));)r++;if(r>=i)return null;const d=n.charCodeAt(r);if(d===uo)return{name:o,attrs:l,selfClosing:!1,declaresNamespace:a,end:r+1};if(d===y2){if(r+1>=i)return null;if(n.charCodeAt(r+1)!==uo)throw new ee(`unexpected "/" in <${o}>`,this.lineIn(e,r));return{name:o,attrs:l,selfClosing:!0,declaresNamespace:a,end:r+2}}if(r===c)throw new ee(`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 ee(`malformed attribute in <${o}>`,this.lineIn(e,r));const f=n.slice(r,u);for(r=u;r<i&&hd(n.charCodeAt(r));)r++;if(r>=i)return null;if(n.charCodeAt(r)!==b2)throw new ee(`attribute ${f} of <${o}> has no value`,this.lineIn(e,r));for(r++;r<i&&hd(n.charCodeAt(r));)r++;if(r>=i)return null;const h=n.charCodeAt(r);if(h!==Ac&&h!==_h)throw new ee(`attribute ${f} of <${o}> is not quoted`,this.lineIn(e,r));const p=n.indexOf(h===Ac?'"':"'",r+1);if(p<0)return null;const g=this.lineIn(e,r);if(l.has(f))throw new ee(`duplicate attribute ${f} in <${o}>`,g);const m=n.slice(r+1,p);if(Fs(m))throw new ee(`a character XML 1.0 forbids appears in attribute ${f} of <${o}>`,g);if(m.includes("<"))throw new ee(`a "<" in the value of attribute ${f} of <${o}> (write &lt;)`,g);f.startsWith("xmlns")&&(a=!0),l.set(f,this.decode(k2(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?Iy[s]:$y[s])===0)break;r++;continue}const o=n.codePointAt(r);if(o===void 0||(r===e?!Ty(o):!ml(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=p2.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=hE(i);if(r>=0)throw new ee("a character XML 1.0 forbids appears in character data",xr(i,r,this.line));if(i.includes(">")){const o=(this.textTail+i).indexOf("]]>");if(o>=0)throw new ee('"]]>" is not allowed in character data (write ]]&gt;)',xr(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(!Sr(e))throw new ee("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 ee(`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>=dT)throw new cf(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"?C2:i===""?"":null}endElement(e){const n=this.stack.at(-1)??null;if(n===null)throw new ee(`unexpected end tag </${e}>`,this.line);if(n!==e)throw new ee(`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 k2(t){return t.includes(`
20
+ `)||t.includes(" ")?t.replaceAll(/[\n\t]/g," "):t}const R2=/[&<>\r]/g,L2=/[&<>"\t\n\r]/g,pT={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"," ":"&#9;","\n":"&#10;","\r":"&#13;"};function et(t){if(Fs(t))throw gT(t);return t.replaceAll(R2,e=>pT[e])}function W(t){if(Fs(t))throw gT(t);return t.replaceAll(L2,e=>pT[e])}function gT(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 P2=/["&]|[^ -~]/gu;function Li(t){return`"${t.replaceAll(P2,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 x2=/&(#\d+|#x[0-9a-fA-F]+|[A-Za-z][A-Za-z0-9]*);/g,M2=(()=>{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 U2(t,e){return t.replaceAll(x2,(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=M2.get(i);return r===void 0?(e?.(n),n):r})}const G2=/^-?(\.\d+|\d+(\.\d*)?)$/,j2=new Set(["node","edge","graph","digraph","subgraph","strict"]);function F2(t){return j2.has(t.toLowerCase())?!1:z2(t)||G2.test(t)}function z2(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 mT(t){return!t.endsWith("\\")&&!t.includes(String.raw`\"`)&&!/\\[\r\n]/.test(t)}function Ss(t){return F2(t)?t:`"${t.replaceAll('"',String.raw`\"`)}"`}function ff(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 vy(t){return!t.includes('"')&&!t.includes(`
22
+ `)&&!t.includes("\r")}function Ho(t){if(!vy(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 Yo=Object.freeze(["source","src","from","start","source_id","sourceid","fromnodeid","start_id",":start_id"]),Vo=Object.freeze(["target","dst","dest","to","end","target_id","targetid","tonodeid","end_id",":end_id"]),iu=Object.freeze(["id","node","name","key"]),Ko=Object.freeze(["label"]),Dy=Object.freeze(["id"]),Oh="Type",W2=new Set([...Yo,...Vo,...iu,...Ko,"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 pd(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 B2(t,e){let n=!0,i=!1;for(const r of t){const s=r.trim();W2.has(s.toLowerCase())&&(i=!0),(s.length===0||Xn(s)!=="string")&&(n=!1)}if(i){const r=ma(t);return e===null||qt(r,Yo)>=0&&qt(r,Vo)>=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&&Xn(r.trim())!=="string")}function H2(t){const e=[];for(let n=1;n<=t;n++)e.push(`column${n}`);return e}function ma(t){return t.map((e,n)=>{const i=e.trim();return i.length===0?`column${n+1}`:i})}class Y2{constructor(e,n,i,r,s=nf){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 Qs(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&&Xn(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 Ey(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:of(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 yT=Mt,gd="E_CSV_NO_ENDPOINT_COLUMNS",Bp="E_CSV_NO_ID_COLUMN",Hp="E_CSV_FIELD_COUNT",bT=Jn,Yp=at,ET="E_CSV_BAD_TYPE",wT="W_CSV_NO_DATA_ROWS",_T=sn,ky=Rn,ST="W_CSV_COLUMN_MISSING",V2=yn,OT=Oi,NT="E_CSV_OTHER_FORMAT",AT="W_CSV_STRAY_QUOTE",Vp="W_CSV_COMMENT_DIRECTION",TT="W_CSV_TYPE_COLUMN_IGNORED",IT="W_CSV_TRAILING_HEADER_DELIMITER",$T="W_CSV_SINGLE_COLUMN",CT="W_CSV_AMBIGUOUS_COLUMN",vT="W_CSV_PADDED_ID",DT="W_CSV_COMMENT_LIKE_RECORD",kT="W_CSV_TRAILING_DELIMITER",RT="W_CSV_WEIGHT_AS_ATTRIBUTE",K2=new Set(["edges","nodes","adjacency","auto"]),LT=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","errorLimit","signal","onProgress"]),X2=new Set([...LT,"nodeIdFrom"]),PT=Object.freeze(["#","%"]),q2=/^\s*[+-]?\d+,\d+(?:[eE][+-]?\d+)?\s*$/;function J2(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 Nh(t){return t?"directed":"undirected"}function Z2(t,e){return e!==!0&&t.trim().length!==t.length}function Q2(t){const e=t??{};eM(e);for(const n of["sourceColumn","targetColumn","idColumn","labelColumn"])gE(n,e[n]);if(e.typeColumn!==null&&gE("typeColumn",e.typeColumn),e.table==="adjacency"&&tM(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:mM(e.nodes),rowNumberIds:e.rowNumberIds??!1,explicitDirected:typeof t?.defaultDirected=="boolean"?t.defaultDirected:null}}function eM(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&&Oy({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&&!K2.has(t.table))throw new N("E_UNSUPPORTED",'option table: expected "edges", "nodes", "adjacency" or "auto"',{option:"table",found:t.table})}function tM(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 gE(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 Ry(t){return t.length===0||t.trim().length===0}function zn(t,e){return e!==!0&&Ry(t)}function nM(t,e){let n=0;for(let i=1;i<t.length;i++)zn(t[i],e[i])||n++;return n}const iM=64;function rM(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",Za,`column ${s+1} "${r}" renamed to "${o}": the header repeats the name`,{line:n,element:r}),o})}function fo(t,e,n){const i=t.map((r,s)=>n.has(s)?"":r);return qt(i,e)}function mE(t,e,n,i,r,s){const o={...n,origin:{...n.origin,id:String(i)}},l=fe(t,e,o,r,{line:s,element:n.name});return l.roleDropped,l.handle}function yE(t){if(!Ry(t))switch(t.trim().toLowerCase()){case"directed":return"directed";case"undirected":return"undirected";case"mutual":return"mutual";default:return null}}function sM(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=xT(n);return i===null?{id:t,weight:void 0}:{id:t.slice(0,e),weight:i}}function xT(t){try{return Vn(t)??null}catch{return null}}class bE{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:js.filter(o=>o!==",")}:{},comments:PT,skipQuoteErrors:i==="adjacency",signal:e.common.signal,onProgress:r?e.common.onProgress:null,encoding:e.common.encoding,allowEmpty:i==="adjacency",inspect:lM(e.csv)?void 0:(o,l)=>{this.refuseOtherFormat(o,l)}};this.reader=new cT(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(yT,"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?rM(ma(r),n,s):H2(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",IT,"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",wT,"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=B2(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>=iM&&(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){MT.some(i=>i.test(e))&&this.state.report.fail(NT,`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=ma(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=J2(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",Vp,`${JSON.stringify(s)} declares a ${Nh(o)} graph, which overrides defaultDirected: ${a}`,l)}else e.commentDirected!==o&&e.report.warning("validation-error",Vp,`${JSON.stringify(s)} declares a ${Nh(o)} graph but ${JSON.stringify(e.commentText)} declared a ${Nh(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",DT,`${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=js.filter(o=>o!==this.reader.delimiter),s=Ny(`${n.map(o=>o[0]).join(`
23
+ `)}
24
+ `,`
25
+ `,r);s!==null&&this.state.report.warning("parse-error",$T,`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",AT,"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=wE(e,n,o.sourceColumn,"sourceColumn",Yo,0),a=wE(e,n,o.targetColumn,"targetColumn",Vo,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(gd,`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(gd,`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,iu)>=0:e.length>=1;this.kind==="auto"&&o.idColumn===null&&!c&&!this.rowNumbers&&l.fail(gd,`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?fo(e,[Oh],c):-1,h=n?fo(e,Dy,c):-1;h>=0&&c.add(h);const p=n?fo(e,Ko,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=fo(e,[o.weightFrom],i);return a<0&&this.state.weightFromExplicit&&l.warning("missing-value",ST,`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:oM(e.length,s)?(l.warnOnce("validation-error",RT,`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,Yo,n,"source",s),o.targetColumn===null&&this.reportRivals(e,Vo,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"?fo(e,[Oh],s):-1;return c>=0&&e[c]===Oh?c:-1}const l=pd(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",CT,`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?pd(e,r,"labelColumn"):n?fo(e,Ko,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?pd(e,i,"idColumn"):n?qt(e,iu):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(Bp,`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(Bp,`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=mE(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=mE(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 Y2(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++)q2.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=nM(e,n);if(zn(e[0],n[0])){r.error("missing-value",Yp,"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=sM(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=EE(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",bT,`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",OT,`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 yE(n[e.typeHint])!="string"||this.state.report.warnOnce("unsupported",TT,`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",Hp,`${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=yE(n[e.type]);return o===null?(this.state.report.error("validation-error",ET,`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:Vn(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=EE(e,n,i,s,r);if(n.length!==e.width){s.error("validation-error",Hp,`${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",Yp,"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",_T,`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){Z2(e,n)&&this.state.report.warnOnce("validation-error",vT,`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",ky,`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 oM(t,e){return t===3&&e.length>0&&e.every(n=>n.length===3&&!Ry(n[2])&&xT(n[2])===null)}function lM(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 EE(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",kT,"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 aM=4096;function wE(t,e,n,i,r,s){return n!==null?pd(t,n,i):e?qt(t,r):t.length>=2?s:-1}const _E=String.raw`<[a-z_][\w.-]*(?::[a-z_][\w.-]*)?`,MT=[/^\s*<(?:\?xml|!doctype|!--)/i,new RegExp(String.raw`^\s*${_E}\s*\/?>\s*(?:[^,;|\s]*<|$)`,"i"),new RegExp(String.raw`^\s*${_E}\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 cM(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=lT(new TextDecoder(e).decode(t.subarray(0,aM)),PT);if(n.trim().length===0||dM(n)||MT.some(l=>l.test(n)))return 0;const i=oT(n),r=Ny(n,i,js,'"',!1,!0);if(r===null){const l=n.split(i,1)[0];return js.some(a=>hM(l,a))?.9:0}const s=af(n,r,'"',2,!1,!0)??[],o=ma(s[0]??[]);return qt(o,Yo)>=0&&qt(o,Vo)>=0?.9:r!==" "&&qt(o,iu)>=0?.6:r===" "&&o.length>3||fM(n,i,r)?0:.3}function dM(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 uM=/[A-Za-z]{2}[.!?](?:\s|$)/;function fM(t,e,n){return t.split(e).filter(s=>s.trim()!=="").length<2?!0:(af(t,n,'"',8,!1,!0)??[]).some(s=>s.some(o=>/\S\s+\S/.test(o.trim())&&uM.test(o.trim())))}function hM(t,e){const n=ma(af(t,e,'"',1,!1,!0)?.[0]??[]);return n.length>1&&qt(n,Yo)>=0&&qt(n,Vo)>=0}async function pM(t,e,n){const i=Qe(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=Q2(n),s=new te("csv",i.errorLimit);bt(e,n,s),Et(n,s,r.table==="nodes"||r.nodes!==null?X2:LT);const o={sink:e,report:s,common:i,csv:r,weightFromExplicit:typeof n?.weightFrom=="string",coercer:new Mn(i.ids),resolver:new Qn(e,s,i.onMixedDirection),headerSet:!1,commentDirected:null,commentText:""};return r.nodes!==null&&await new bE(o,r.nodes,"nodes",!1).read(),await new bE(o,t,r.table,!0).read(),o.coercer.mergeCount>1&&s.warning("coercion",ky,`${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 gM=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:cM,import:pM});function mM(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 He=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"}),UT=Xe({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:["bool","i32","f64","string","dict"]}),yM={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"}},bM=new Set(["id","label"]),EM=new Set(["directed","pair","mutual","weight","timeText","position","color","size","shape","thickness","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]);function wM(t){const e=t??{};if(e.dialect!==void 0&&e.dialect!=="gephi"&&e.dialect!=="generic"&&!JA("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:yM[e.dialect==="generic"?"generic":"gephi"],table:e.table??"edges",delimiter:e.delimiter??",",newline:e.newline??`
29
+ `,header:e.header??!0}}function Tc(t,e){switch(t){case"bool":return e===!0?"true":"false";case"f32":case"f64":return typeof e=="number"?_r(e,t):String(e);case"i32":case"u32":case"u8":return typeof e=="number"?Ue(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 _M(t,e){if(!t.isSet(e))return null;switch(t.dtype){case"list":{const n=t.sliceOf(e),{dtype:i}=t.child;return my(n.map(r=>Tc(i,r)),"semicolon")}case"json":return JSON.stringify(t.values[e])??"";case"bool":case"string":case"dict":return Tc(t.dtype,t.value(e));default:{const{components:n}=t.meta,{data:i}=t;if(n===1)return Tc(t.dtype,i[e]);const r=[];for(let s=0;s<n;s++)r.push(Tc(t.dtype,i[e*n+s]));return r.join(";")}}}function SM(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:He.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 OM(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 NM(t,e,n){const{ids:i}=t;if(i.kind==="mixed"){const r=OM(i);r>0&&n(He.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 Qa(String(o))!=typeof o&&r++}r>0&&n(He.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 GT(t,e,n){const i=dt(e),r=wM(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));NM(t,n,o);const c=Ut(t),d=[];for(let y=0;y<t.edgeCount;y++)c.folded(y)||d.push(y);AM(t,r,d.length,o),c.mutualCount>0&&r.table!=="nodes"&&o(He.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"&&$M(t,d,o);const u=wt(t),{edgeId:f,edgeLabel:h,edgeColumns:p}=TM(t,r,d,n,o),{nodeLabel:g,nodeColumns:m}=IM(t,r,n,o);return r.table!=="nodes"&&SM([...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 AM(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=gl(t);t.directed?s>0&&i(He.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(He.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(He.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 TM(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(ya));e.dialect.type!==null&&l.add(ya(e.dialect.type));const a=jT(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(He.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){Kp(s,"id",Dy,"edge",n,r),Kp(o,"label",Ko,"edge",n,r);for(const{column:c}of a)Ly(c,"edge",n,r)}return{edgeId:s,edgeLabel:o,edgeColumns:a}}function IM(t,e,n,i){const r=t.nodes.byRole("label"),s=new Set([ya(e.dialect.id)]),o=[];if(e.table==="nodes"&&n)for(let a=0;a<t.nodeCount;a++)o.push(a);const l=jT(t.nodes,"node",s,null,r,e.table==="nodes"?i:null);if(e.table==="nodes"&&n){Kp(r,"label",Ko,"node",o,i);for(const{column:a}of l)Ly(a,"node",o,i)}return{nodeLabel:r,nodeColumns:l}}function $M(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(He.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(He.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 ya(t){return t.toLowerCase()}function jT(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&&EM.has(c))continue;const d=l.length-l.nullCount;CM(a,e,n,i,d,s)||qt([a],Ko)>=0&&!vM(a,e,r,d,s)||o.push({column:l,header:a})}return o}function CM(t,e,n,i,r,s){const o=ya(t),l=e==="edge"?qt([t],Dy)>=0:!1;return n.has(o)||l||i!==null&&ya(i.meta.name)===o?(s?.(He.RESERVED_NAME,`${e} column "${t}" is not written: the name is reserved for the ${l?"edge id":o} column`,t,r),!0):!1}function vM(t,e,n,i,r){return n!==null?(r?.(He.RESERVED_NAME,`${e} column "${t}" is not written: the name is reserved for the label column`,t,i),!1):(r?.(He.ROLE_ASSUMED,`${e} column "${t}" reads back with the label role (string)`,t,i),!0)}function Kp(t,e,n,i,r,s){if(t===null)return;const{name:o}=t.meta;qt([o],n)<0&&s(He.ROLE_NAME,`${i} column "${o}" (${e}) is written under its name, which the importer does not map to the ${e} role`,o,SE(t,r)),t.dtype!=="string"&&t.dtype!=="dict"&&s(He.TEXT_ROLE,`${i} column "${o}" (${e}) is ${t.dtype}; it reads back as string`,o,SE(t,r)),Ly(t,i,r,s,!0)}function SE(t,e){let n=0;for(const i of e)t.isSet(i)&&n++;return n}const FT={bool:0,i32:1,f64:2,string:3},DM=["bool","i32","f64","string"];function Ly(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=kM(t,n);d>0&&i(He.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=RM(t,n);if(r||a.widest<0)return;const c=a.candidate&&a.heuristic.decide()==="dict";if(a.widest<FT.string&&!c){i(He.TEXT_INFERRED,`${l}: every value reads back as ${DM[a.widest]}`,s,a.set);return}o==="dict"&&!c?i(He.STORAGE_CLASS_CHANGED,`${l}: reads back as string (cardinality too high for a dict)`,s,null):o==="string"&&c&&i(He.STORAGE_CLASS_CHANGED,`${l}: reads back as dict (low cardinality)`,s,null)}function kM(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 RM(t,e){let n=-1,i=!0,r=0;const s=new Qs(nf);for(const o of e){const l=t.isSet(o)?t.value(o):null;if(typeof l!="string")continue;r++;const a=Xn(l);n=Math.max(n,FT[a]),s.decided||(i&&=a==="string",s.observe(l))}return{widest:n,candidate:i,set:r,heuristic:s}}function LM(t,e,n){return!t.directed||!e.folding.sourceDirected(n)?"Undirected":"Directed"}function PM(t,e){return e!==null?`${t}:${e}`:t.includes(":")?`${t}:`:t}function xM(t,e,n){const i=t[e[n]];let r=n;for(;r<e.length&&t[e[r]]===i;)r++;return r}function*MM(t,e){const{delimiter:n,newline:i}=e.csv,r=g=>`"${g.replaceAll('"','""')}"`,s=g=>js.some(m=>g.includes(m))?r(g):ff(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=xM(l.src,a,p),y=[];let b=-1,_=!0;const S=T=>{d[T]===0&&(d[T]=1,_&&=T===u+y.length,y.push(T),b=Math.max(b,T))};S(g);for(let T=p;T<m;T++)S(l.dst[a[T]]);if(!_){for(const T of y)d[T]=0;yield*h(b)}f();const I=[o(e.idText(g))];for(let T=p;T<m;T++){const D=a[T];I.push(s(PM(e.idText(l.dst[D]),c.weighted?c.text(D):null)))}yield I.join(n)+i,p=m}yield*h(t.nodeCount-1)}function*OE(t,e){e.csv.table==="adjacency"?yield*MM(t,e):e.csv.table==="nodes"?yield*UM(t,e):yield*GM(t,e)}function zT(t){const e=i=>ff(i,t);return{quote:e,cell:(i,r)=>{const s=_M(i,r);return s===null?"":e(s)}}}function*UM(t,e){const{csv:n}=e,{delimiter:i,newline:r}=n,{quote:s,cell:o}=zT(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*GM(t,e){const{csv:n}=e,{delimiter:i,newline:r}=n,{quote:s,cell:o}=zT(i);n.header&&(yield jM(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(LM(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 jM(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 NE(t,e){const n=GT(t,e,!1),i=n.notes.find(r=>r.code===He.ID_TEXT_COLLISION);if(i!==void 0)throw new N("E_INVALID_ID",i.message,{reason:"collision",count:i.count});return n}function FM(t){const{csv:e}=t;if(e.header||e.table==="adjacency")return[];const n=e.table==="nodes"?zM(t):WM(t);if(n.length===0)return[];const i=n.map(r=>JSON.stringify(r)).join(", ");return[Object.freeze({code:He.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 zM(t){return[...t.nodeLabel===null?[]:[t.nodeLabel.meta.name],...t.nodeColumns.map(n=>n.header)]}function WM(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 BM(t,e){const n=GT(t,e,!0);return Object.freeze([...Un(t,UT,n.common,{roles:bM,...n.csv.table==="nodes"?{tables:["node"]}:{}}),...n.notes,...FM(n)])}const HM=Object.freeze({format:"csv",options:Object.freeze(["delimiter","dialect","header","newline","table"]),capabilities:UT,check:BM,export(t,e){return ei(OE(t,NE(t,e)))},exportToString(t,e){return ti(OE(t,NE(t,e)))}});Object.freeze({...xn,...Pn,PRECISION:ie,EMPTY_INPUT:yT,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,NO_ENDPOINT_COLUMNS:gd,NO_ID_COLUMN:Bp,FIELD_COUNT:Hp,MISSING_ENDPOINT:bT,MISSING_ID:Yp,BAD_TYPE:ET,UNCLOSED_QUOTE:wy,QUOTE:_y,NO_DATA_ROWS:wT,DUPLICATE_NODE:_T,DUPLICATE_EDGE_ID:OT,ID_MERGED:ky,COLUMN_MISSING:ST,ROLE_TAKEN:V2,COLUMN_RENAMED:ln,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er,WIDENING_UNSUPPORTED:lf,OTHER_FORMAT:NT,STRAY_QUOTE:AT,COMMENT_DIRECTION:Vp,TYPE_COLUMN_IGNORED:TT,TRAILING_HEADER_DELIMITER:IT,SINGLE_COLUMN:$T,AMBIGUOUS_COLUMN:CT,PADDED_ID:vT,COMMENT_LIKE_RECORD:DT,TRAILING_DELIMITER:kT,WEIGHT_AS_ATTRIBUTE:RT});const ru=`${String.fromCodePoint(0)}cx:`,YM=/"\\u0000cx:(-?\d+)"/g,VM=/^-?[1-9]\d{15,}$/;function WT(t){return typeof t=="number"?Number.isSafeInteger(t):VM.test(t)&&!Number.isSafeInteger(Number(t))}function KM(t,e,n){const{ids:i}=t,r=[],s=new Set;for(let a=0;a<i.size;a++){const c=i.idOf(a);WT(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"?`${ru}${c}`:c},isChanged:a=>o.has(a),originalAt:a=>i.idOf(a)}}function XM(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(ru.length));o>n&&(n=o)}const i=n+1n;return i<=BigInt(Number.MAX_SAFE_INTEGER)?Number(i):`${ru}${i.toString()}`}function qM(t){let e=0;for(let n=0;n<t.ids.size;n++)WT(t.ids.idOf(n))||e++;return e}function BT(t,e,n,i,r){const s=qM(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 KM(t,e.sanitizeIds,n)}catch(o){if(o instanceof N)return o;throw o}}function Ah(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 JM(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!Number.isSafeInteger(t.value(e)))return!1;return!0}function HT(t){const{meta:e}=t,n=e.origin?.type??null,i=n!==null&&n.endsWith("long")&&(e.dtype!=="f64"||JM(t));return e.dtype==="list"?e.itemDtype===null||e.itemDtype==="json"?"string":`list_of_${Ah(e.itemDtype,i)}`:e.components>1?`list_of_${Ah(e.dtype,!1)}`:Ah(e.dtype,i)}function ZM(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 YT(t,e,n=null){const i=t.edges.byRole("id"),r=new Set;let s=0;const o=QM(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 QM(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 VT(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 e3(){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 vi(t){const e=JSON.stringify(t,(n,i)=>Object.is(i,-0)?`${ru}-0`:i);return e.includes(String.raw`\u0000cx:`)?e.replaceAll(YM,"$1"):e}function*KT(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 XT=new RegExp("(?<![0-9.])\\d{16}"),t3=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("|")),n3=`${String.fromCodePoint(0)}graph-io`,AE=[["-Infinity",-1/0],["Infinity",1/0],["NaN",Number.NaN]],i3=/^-?(0|[1-9]\d*)$/,r3=/^(-?)(\d+)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/;function*s3(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 o3(t){let e=t;if(/\\u0000/i.test(t)){const i=[];for(const r of s3(t))r.includes("\\")&&i.push(l3(r));e=`${i.join(`
33
+ `)}
34
+ ${t}`}let n=0;for(;e.includes(`graph-io${n===0?"":String(n)}:`);)n++;return`${n3}${n===0?"":String(n)}:`}function l3(t){try{return String(JSON.parse(t))}catch{return t}}function a3(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=r3.exec(t);if(n===null)return!1;const i=nT(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 Py(t,e={}){const n=e.nonstandard??!0,i=e.exactSentinel??!1,r=o3(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?AE.find(([I])=>t.startsWith(I,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 I=t.slice(h,_);i3.test(I)?Number.isSafeInteger(Number(I))||(a.push(I),S=i?JSON.stringify(`${s}${I}`):`"${I}"`):a3(I)&&c.push(I)}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 _=AE.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 c3=32;function d3(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)u3(n,i,r,l===91),r++;else if(l===125||l===93)r--;else if(l===34){const a=su(t,o+1),c=r>0?n[r-1]:null;c!==null&&c[0]!==-1&&m3(t,a+1)&&f3(t,o+1,a,c,i,r-1)&&e.push({key:t.slice(o+1,a),offset:o}),o=a}o++}return e}function u3(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 f3(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&&h3(t,i[a],e,l))return!0;if(i.push(e,n),i.length>2*c3){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 h3(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 su(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 p3(t,e){let n=rr(t,0);for(const r of e){let s=-1;if(typeof r=="number"&&t.codePointAt(n)===91){let o=0;Th(t,n,!1,(l,a)=>{o++===r&&(s=a)})}else typeof r=="string"&&t.codePointAt(n)===123&&Th(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 Th(t,n,!0,r=>i.add(r)),[...i]}function Th(t,e,n,i){let r=rr(t,e+1);const s=n?125:93;for(;r<t.length&&t.codePointAt(r)!==s;){let o=null;if(n){const l=su(t,r+1);o=JSON.parse(t.slice(r,l+1)),r=rr(t,rr(t,l+1)+1)}i(o,r),r=rr(t,g3(t,r)),t.codePointAt(r)===44&&(r=rr(t,r+1))}}function g3(t,e){const n=t.codePointAt(e);if(n===34)return su(t,e+1)+1;if(n!==123&&n!==91){let s=e;for(;s<t.length&&!JT(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=su(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 rr(t,e){let n=e;for(;n<t.length&&hf(t.codePointAt(n));)n++;return n}function m3(t,e){let n=e;for(;n<t.length&&hf(t.codePointAt(n));)n++;return t.codePointAt(n)===58}class vn{constructor(e){this.digits=e}toJSON(){return Number(this.digits)}}function y3(t){if(!XT.test(t))return{value:JSON.parse(t),exact:!1};const e=Py(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 Ke(t,e){if(t instanceof vn)return e?.(t.digits),Number(t.digits);if(Array.isArray(t))return t.map(n=>Ke(n,e));if(typeof t=="object"&&t!==null){const n={};for(const[i,r]of Object.entries(t))xy(n,i,Ke(r,e));return n}return t}function xy(t,e,n){e==="__proto__"?Object.defineProperty(t,e,{value:n,enumerable:!0,writable:!0,configurable:!0}):t[e]=n}function b3(t){if(!/NaN|Infinity/.test(t))return null;const e=Py(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 E3=String.raw`\uD800-\uDFFF`,TE=new RegExp("[\\ud800-\\udbff](?![\\udc00-\\udfff])|(?<![\\ud800-\\udbff])[\\udc00-\\udfff]","g"),w3=/\\u[dD][89a-fA-F]|[\ud800-\udfff]/;function Xp(t,e){if(typeof t=="string"){const n=t.replaceAll(TE,"�");return n!==t&&e.count++,n}if(Array.isArray(t)){for(let n=0;n<t.length;n++)t[n]=Xp(t[n],e);return t}if(M(t)){const n=Object.keys(t),i=n.map(o=>o.replaceAll(TE,"�")),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]),xy(s,i[l],Xp(t[o],e))}),s}return t}function qp(t){return Array.isArray(t)?t.reduce((e,n)=>e+qp(n),0):M(t)?Object.keys(t).reduce((e,n)=>e+1+qp(t[n]),0):0}function _3(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=qT(t,n+1);const s=e.at(-1)??null;if(s!==null&&t[rr(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 qT(t,e){let n=e;for(;n<t.length&&t[n]!=='"';)n+=t[n]==="\\"?2:1;return n}const S3=/"\s*:/g;function O3(t,e,n,i){let r=e;if(w3.test(t)){const s={count:0,collisions:[]};r=Xp(r,s);for(const o of s.collisions)i.warnOnce("validation-error",de,`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},`${de}:json:${o}`);s.count>0&&i.error("validation-error",ne,`${s.count} string${O(s.count)} ${C(s.count,"holds","hold")} a lone surrogate (an unpaired ${E3} escape); each is read with U+FFFD in its place`,{line:n})}if(typeof r=="object"&&r!==null&&(t.match(S3)?.length??0)>qp(r)){const s=_3(t);s!==null&&i.warnOnce("validation-error",de,`an object holds the key ${JSON.stringify(s)} twice; the later value is read`,{line:n,element:s},`${de}:json:${s}`)}return r}class Ze extends Error{constructor(e,n,i=!1){super(e),this.name="JsonScanError",this.line=n,this.empty=i}}const hf=t=>t===32||t===10||t===13||t===9,JT=t=>hf(t)||t===44||t===93||t===125||t===58,IE=/["\\]/g,pf=200;class N3{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+=$E(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+=$E(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&&hf(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 Ze("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(;;){IE.lastIndex=this.pos;const e=IE.exec(this.buf);if(e===null){if(this.pos=this.buf.length,!await this.fill())throw new Ze("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 Ze("the document ends inside a string",this.line());this.pos++}}async skipScalar(){for(;;){for(;this.pos<this.buf.length&&!JT(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 Ze(`invalid string: ${ZT(n)}`,this.line())}}}function $E(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 ZT(t){return t instanceof Error?t.message:String(t)}function ba(t,e,n){let i;try{i=y3(t)}catch(r){const s=n===null?null:b3(t);if(s===null)throw new Ze(`invalid JSON: ${ZT(r)}`,e);n?.warnOnce("coercion",qu,`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:O3(t,i.value,e,n)}),i}function A3(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*QT(t,e=null){const n=new N3(t),i=await n.peek();if(i==="")throw new Ze("the input is empty",1,!0);const r=A3(n.ahead(16));if(r===""&&n.ahead(8).includes(String.fromCodePoint(0)))throw new Ze('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*I3(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 T3(n,s,r),object:!1,line:s}}async function T3(t,e,n){t.beginCapture(),await t.skipValue();let i;try{({value:i}=ba(t.endCapture(),e,null))}catch(r){throw r instanceof Ze&&n!==""?new Ze(`${r.message}${n}`,r.line):r}if(await t.peek()!=="")throw new Ze("unexpected text after the document",t.line());return i}async function*I3(t,e){let n=0,i=await t.peek();for(i==="]"&&t.pos++;i!=="]";){if(yield*$3(t,n,e),n++,i=await t.peek(),i!==","&&i!=="]")throw new Ze(i===""?"the document ends before its closing bracket":`expected "," or "]", found "${i}"`,t.line());t.pos++}if(await t.peek()!=="")throw new Ze("unexpected text after the closing bracket",t.line())}async function*$3(t,e,n){const i=await t.peek(),r=t.line();if(i===""||i==="]"||i===",")throw new Ze(i===""?"the document ends inside its array":`unexpected "${i}"`,r);if(t.beginCapture(),i!=="{"){await t.skipValue(),yield CE(t,e,r,n);return}if(t.pos++,await t.peek()!=='"'){await t.skipValue(1),yield CE(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 C3(t);if(yield*v3(t,d,c,e,l,n),c++,a=await t.peek(),a!==","&&a!=="}")throw new Ze(a===""?"the document ends inside a member":`expected "," or "}" after the key "${d.name}"`,t.line());t.pos++}yield*D3(l,e,r,{outer:s,firstLine:o},n)}function CE(t,e,n,i){if(t.deepest>pf)return t.dropCapture(),{kind:"deep",aspect:null,block:e,depth:t.deepest,line:n};const r=t.endCapture(),s=ba(r,n,i);return{kind:"member",block:e,value:s.value,exact:s.exact,text:r,line:n}}async function C3(t){if(await t.peek()!=='"')throw new Ze("expected a key",t.line());const e=t.line(),n=await t.readString();if(await t.peek()!==":")throw new Ze(`expected ":" after the key "${n}"`,t.line());return t.pos++,{name:n,line:e}}async function*v3(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*k3(t,e.name,i,s);return}t.beginCapture(),await t.skipValue(),t.deepest+1>pf?(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*D3(t,e,n,i,r){const{others:s,firstBlock:o,deep:l}=t;if(o!==null){for(const u of s)u.text!==null&&ba(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=ba(c,i.firstLine,r);yield{kind:"member",block:e,value:d.value,exact:d.exact,text:c,line:n}}async function*k3(t,e,n,i){if(await t.peek()==="]"){t.pos++;return}for(;;){if(await t.peek()==="")throw new Ze(`the document ends inside the "${e}" block`,t.line());const s=t.line();if(t.beginCapture(),await t.skipValue(),t.deepest>pf)t.dropCapture(),yield{kind:"deep",aspect:e,block:n,depth:t.deepest,line:s};else{const l=t.endCapture(),a=ba(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 Ze(o===""?`the document ends inside the "${e}" block`:`expected "," or "]" in the "${e}" block, found "${o}"`,t.line())}}function e1(t,e){const n=e.aspect===null?"a member of the document":`an element of "${e.aspect}"`;t.error("parse-error",pt,`${n} is nested ${e.depth} levels deep, more than the ${pf} a graph keeps; skipped`,{line:e.line,element:e.aspect})}function t1(t,e){return n=>{t.warnOnce("precision",ie,`an aspect kept in ${e} holds ${n}, beyond 2^53; it is kept as the nearest double`,{element:e},`${ie}:kept`)}}function n1(t,e){e.shared&&t.warnOnce("coercion",ey,`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 R3=/^-?(0|[1-9]\d*)$/;function ou(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 vE(t,Number.isInteger(t)?"an integer beyond 2^53 written inexactly":"not an integer")}if(typeof t=="string"&&t!=="-0"&&R3.test(t)){const n=Number(t);return Number.isSafeInteger(n)?{id:n,note:"text"}:{id:t,note:"precision"}}throw vE(t,"a CX id is an integer")}function vE(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 DE=/-?\d[\d.eE+-]*/y;function i1(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=qT(t,s+1);const a=rr(t,s+1);if(r===n&&t.startsWith(i,l)&&t[a]===":")return L3(t,rr(t,a+1))}s++}return!1}function L3(t,e){DE.lastIndex=e;const n=DE.exec(t);return n!==null&&/[.eE]/.test(n[0])}const My="position",P3="z";function r1(t,e=2){return{name:My,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,extra:{sourceDims:e,units:"file"},origin:{format:t,namespace:"cytoscape"}}}function Jp(t){return{name:P3,dtype:"f64",nullable:!0,origin:{format:t,id:null,namespace:"cytoscape"},extra:{cytoscape:"z"}}}function s1(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 x3=new Set(["metaData","status","numberVerification"]);class o1{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}x3.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",Us,`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",Bd,s,{line:n,element:"status"}),this.report.abort(s,{code:Bd})}e.success===!0&&i.length>0&&this.report.warning("validation-error",ty,`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",Us,`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 l1(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})),fe(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:Zs,NOT_EXPORTED:"W_STYLES_NOT_EXPORTED",MISMATCH:"E_STYLES_MISMATCH"}),De=256;function B(t,e,n){t.notes.add(e,t.target,t.property,{sample:n,element:t.element})}function _i(t,e){t.budget?.spend(t.target==="graph"?"node":t.target,e)}function ct(t,e){return _i(e,1),t==null?null:typeof t=="number"?Number.isFinite(t)?String(t):(B(e,v.BAD_VALUE,String(t)),null):typeof t!="string"?(B(e,v.BAD_VALUE,typeof t),null):t.length>De?(B(e,v.VALUE_TOO_LONG,`${t.length} characters`),null):(_i(e,t.length),t.trim()===""?(B(e,v.BAD_VALUE,t),null):t)}const a1=1e6,gt=72,M3=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function x(t){return Number(t.toPrecision(6))+0}function Uy(t,e){if(typeof t=="boolean")return B(e,v.BAD_VALUE,t),null;const n=ct(t,e);if(n===null)return null;const i=n.trim();let r=Number.NaN;return typeof t=="number"?r=t:M3.test(i)&&(r=Number(i)),Number.isFinite(r)?r:(B(e,v.BAD_VALUE,n),null)}function V(t,e,n=1){const i=Uy(t,e);if(i===null)return null;const r=i*n;return r>=0&&r<=a1?x(r):(B(e,v.BAD_VALUE,typeof t=="string"?t:String(t)),null)}function Ea(t,e){const n=Uy(t,e);return n===null?null:Math.abs(n)>a1?(B(e,v.BAD_VALUE,typeof t=="string"?t:String(t)),null):x(n)}function tc(t,e,n){const i=Uy(t,n);if(i===null)return null;const r=e==="cytoscape"?255:1;return i>=0&&i<=r?x(i/r):(B(n,v.BAD_VALUE,typeof t=="string"?t:String(t)),null)}const U3=new Map([["true",!0],["yes",!0],["on",!0],["1",!0],["false",!1],["no",!1],["off",!1],["0",!1]]);function nc(t,e){if(typeof t=="boolean")return _i(e,1),t;const n=ct(t,e);if(n===null)return null;const i=U3.get(n.trim().toLowerCase());return i===void 0?(B(e,v.BAD_VALUE,n),null):i}function c1(t){return t==="gexf"||t==="dvips"?"relative":"px"}const G3=8,j3=80,F3=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 re{#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<G3){const l=z3(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}: ${F3.get(n.code)??n.code} (${n.count})`})}return e}}function z3(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,j3)}const W3={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"]},B3={solid:["solid","line"],dashed:["dashed","dash","equal-dash"],dotted:["dotted","dot","dots"],"dash-dot":["dash-dot","dashdot","dashed-dotted"],double:["double","parallel-lines"]},H3={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"]},Y3={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"]},V3={normal:["normal","regular","plain","lighter","100","200","300","400","500"],bold:["bold","bolder","600","700","800","900"]},K3={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"]},X3={inside:["inside"],center:["center","centre","middle"],outside:["outside"]},q3={left:["left"],right:["right"]},J3={left:["left","start"],center:["center","centre","middle"],right:["right","end"]},Z3={inside:["inside"],bounds:["bounds"]},Q3={shape:{"round-rectangle":["box"],ellipse:["dot"],triangle:["triangledown"],none:["text"]},arrow:{inverted:["inv-triangle"],square:["box"],"other:curve":["curve"],"other:inv-curve":["inv-curve"]}},e6={arrow:{"other:triangle-tee":["triangle-tee"],"other:triangle-cross":["triangle-cross"],"other:circle-triangle":["circle-triangle"],"other:chevron":["chevron"],vee:["triangle-backcurve"]}},t6={arrow:{"other:curve":["curve"],"other:inv-curve":["icurve"]}},n6=new Map([["vis",Q3],["graphviz",t6],["cytoscape-js",e6]]),i6=new Set(["shape","borderStyle","lineStyle","arrow"]);function ai(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 r6=new Map([["shape",ai(W3)],["borderStyle",ai(B3)],["lineStyle",ai(H3)],["arrow",ai(Y3)],["arrowSide",ai(q3)],["weight",ai(V3)],["position",ai(K3)],["labelFit",ai(Z3)],["borderPosition",ai(X3)],["textAlign",ai(J3)]]),s6=new Map(Array.from(n6,([t,e])=>[t,new Map(Object.entries(e).map(([n,i])=>[n,ai(i)]))]));function oe(t,e,n,i){const r=ct(e,i);if(r===null)return null;const s=r.trim(),o=s.toLowerCase().replaceAll(/[\s_]+/g,"-"),l=s6.get(n)?.get(t)?.get(o)??r6.get(t)?.get(o);return l!==void 0?l:(B(i,v.UNKNOWN_VALUE,s),i6.has(t)?`other:${s}`:null)}function nt(t,e){return _i(e,1),t==null?null:typeof t=="string"?(_i(e,t.length),t):typeof t=="number"&&Number.isFinite(t)||typeof t=="boolean"?String(t):(B(e,v.BAD_VALUE,typeof t=="number"?String(t):typeof t),null)}function gf(t,e,n){n!==void 0&&_i(n,t.length);const i=Gy(h6(d1(t,e)),r=>r==="n"||r==="l"||r==="r"?`
37
+ `:r);return i.endsWith(`
38
+ `)?i.slice(0,-1):i}function d1(t,e){const n={N:e.node,G:e.graph,E:e.edge,T:e.tail,H:e.head};return Gy(t,i=>(Object.hasOwn(n,i)?n[i]:void 0)??`\\${i}`)}function o6(t,e){const n=Gy(d1(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 Gy(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 l6=new Map([["amp","&"],["lt","<"],["gt",">"],["quot",'"'],["apos","'"],["nbsp"," "]]);function a6(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 l6.get(t.toLowerCase())}function Zp(t,e){return _i(e,t.length),B(e,v.HTML_LABEL,t),u1(t).map(n=>n.text).join("").trim()}const c6=/^<(\/?)(b|i|u|o|s|sub|sup|font)\b/i;function u1(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;d6(n,e,i,s),i=s+1}else{const[s,o]=r==="&"?f1(e,i):[r,i+1];Qp(n,n.open.at(-1)==="table"?"":s),i=o}}return n.spans}function Qp(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 kE(t){return t.out.slice(t.out.lastIndexOf(`
39
+ `)+1).trim()!==""}function d6(t,e,n,i){const r=/^<(\/?)(br|table|tr|td)\b/i.exec(e.slice(n,n+7));if(r!==null){u6(t,r[2].toLowerCase(),r[1]==="/");return}const s=c6.exec(e.slice(n,n+6));s!==null&&s[1]==="/"?t.tags=f6(t.tags,s[2]):s!==null&&e[i-1]!=="/"&&(t.tags=[...t.tags,e.slice(n,i+1)])}function u6(t,e,n){e==="br"||e==="tr"?(e==="br"||!n&&kE(t))&&Qp(t,`
40
+ `):n?t.open.pop():(e==="td"&&kE(t)&&Qp(t," "),t.open.push(e==="td"?"td":"table"))}function f6(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 h6(t){let e="",n=0;for(let i=t.indexOf("&");i>=0;i=t.indexOf("&",n)){const[r,s]=f1(t,i);e+=t.slice(n,i)+r,n=s}return e+t.slice(n)}function f1(t,e){const n=t.slice(e+1,e+10).indexOf(";"),i=n<0?-1:e+1+n,r=i>e?a6(t.slice(e+1,i)):void 0;return r===void 0?["&",e+1]:[r,i+1]}function p6(t,e){_i(e,t.length),B(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 ni=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"],["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"],["nodeGap","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"],["labelMinScreenSize","number"],["labelOnTop","boolean"],["visible","boolean"]]),graph:new Map([["background","color"]])}),g6=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"]]]),m6=new Set(["shape","borderStyle","lineStyle","arrow"]);function Xo(t,e,n){if(t!=="graph"&&e.startsWith("graphty:"))return typeof n=="string"||typeof n=="number"||typeof n=="boolean";const i=ni[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"&&((g6.get(i)?.includes(n)??!1)||m6.has(i)&&n.startsWith("other:")&&n.length>6)}}const y6=32,h1=8,lu=/^#[0-9a-f]{6}$/;function RE(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 mf(t,e,n){const i=K(t.value(e,n));return typeof i=="number"&&t.get(e)?.dtype==="f32"?Number(lt(i)):i}function ic(t,e){let n;return e==="degree"?n=t.degree():e==="indegree"?n=t.inDegree():n=t.outDegree(),Array.from(n)}function Ar(t,e,n,i,r){const s=new Map,o=new Map;for(const l of i)o.set(RE(l.ref),l);return{n:e,column(l){if("style"in l)return n.get(l.style)??null;const a=RE(l);if(s.has(a))return s.get(a)??null;const c=r===void 0?o.get(a)?.values??null:b6(r,t,e,l);return s.set(a,c),c}}}function b6(t,e,n,i){if("computed"in i)return e==="node"?ic(t,i.computed):null;const r=e==="node"?t.nodes:t.edges;return r.has(i.data)?Array.from({length:n},(s,o)=>mf(r,i.data,o)):null}function md(t,e,n){const i=t.column(e);return i===null?null:i[n]??null}function E6(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=eg(n);if(i===0)return!1;e+=i}return e<=h1}return eg(t)>0}function eg(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 w6(t.not)?eg(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<=h1?e:0}return 0}function w6(t){return"eq"in t?t.eq[0]:"in"in t?t.in[0]:{}}function LE(t,e){return t===e?t!=null:typeof e=="boolean"?PE(e,t):typeof t=="boolean"&&PE(t,e)}function PE(t,e){return e===(t?1:0)||typeof e=="string"&&e.toLowerCase()===String(t)}function Ro(t,e,n,i=0){if(i>y6)return!1;if("all"in t)return t.all;if("has"in t){const r=md(e,t.has,n);return r!==null&&r!==!1}if("eq"in t)return LE(md(e,t.eq[0],n),t.eq[1]);if("in"in t){const r=md(e,t.in[0],n);return t.in[1].some(s=>LE(r,s))}return"and"in t?t.and.every(r=>Ro(r,e,n,i+1)):"or"in t?t.or.some(r=>Ro(r,e,n,i+1)):"not"in t?!Ro(t.not,e,n,i+1):!1}const _6=new Set(["shape","borderStyle","lineStyle","arrow","arrowSide","weight","position","labelFit","borderPosition","textAlign"]);function El(t,e){const n=ni[t].get(e),i={notes:new re,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=>V(r,i);case"signed":return r=>Ea(r,i);case"opacity":return r=>tc(r,"css",i);case"boolean":return r=>nc(r,i);case"text":return r=>nt(r,i);default:return _6.has(n)?r=>typeof r=="string"&&r.startsWith("other:")?r:oe(n,r,"css",i):()=>null}}const xE=new WeakMap,S6=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function rc(t){return typeof t=="number"?Number.isFinite(t)?t:null:typeof t=="string"&&t.length<=64&&S6.test(t.trim())?Number(t.trim()):null}function p1(t){const e=xE.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=rc(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 xE.set(t,o),o}function O6(t){return Math.min(255,Math.max(0,Math.round(t))).toString(16).padStart(2,"0")}function g1(t){return Number(t.toPrecision(6))+0}function m1(t,e,n){if(typeof t=="number"&&typeof e=="number")return g1(t+(e-t)*n);if(typeof t=="string"&&typeof e=="string"&&lu.test(t)&&lu.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+=O6(s+(o-s)*n)}return i}return n<1?t:e}function yf(t,e,n){const i=N6(t,e);return typeof i=="number"&&n!==void 0&&n>0?g1(Math.round(i/n)*n):i}function N6(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 m1(i.above,r.below,(e-i.at)/(r.at-i.at))}return null}function A6(t,e,n,i){const r=md(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=p1(t.table)(r);return s<0?null:t.table[s][1]}case"continuous":return Array.isArray(r)?null:yf(t.points,rc(r),t.step);default:return null}}function y1(t,e){const n=t.set??{};return Object.hasOwn(n,e)?n[e]:void 0}function b1(t,e){const n=t.map??{};return Object.hasOwn(n,e)?n[e]:void 0}function Si(t,e,n,i,r){const s=t.filter(c=>c.target===e&&(y1(c,n)!==void 0||b1(c,n)!==void 0)).reverse(),o=El(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=T6(d,n,o,i,c);if(u!==null){l[c]=u;break}}return r?.spend(e,a+i.n),l}function T6(t,e,n,i,r){if(!Ro(t.where,i,r))return null;const s=y1(t,e);if(s!==void 0)return s;const o=b1(t,e);return o===void 0?null:A6(o,n,i,r)}function E1(t,e,n,i){return Si(t.styles.rules,e,n,I6(t,e,i))}function I6(t,e,n){let i=t.fingerprint[e==="node"?"nodes":"edges"];return n!==void 0&&(i=e==="node"?n.nodeCount:n.edgeCount),Ar(e,i,t.columns[e],t.features[e],n)}function jy(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"&&lu.test(t)&&lu.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 bf(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 wl=bf("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"),$6=bf("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"),w1=bf("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"),C6=bf("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"),v6=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}`)]})),D6=new Set(["transparent","none","invis"]),k6=/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function R6(t){return t.toString(16).padStart(2,"0")}function L6(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=>R6(Math.trunc(c*255))).join("")}`}function P6(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)?x6(t):null;if(n!==null)return{hex:n,alpha:1};const i=M6(t.toLowerCase(),e);if(i===null)return null;if(D6.has(i.name))return{hex:"#fffffe",alpha:0};const r=U6(i.name,i.scheme);return r===void 0?null:{hex:r,alpha:1}}function x6(t){const e=t.split(/[ ,]+/);if(e.length<3||!e.slice(0,3).every(s=>k6.test(s)))return null;const[n,i,r]=e.slice(0,3).map(s=>Math.min(1,Math.max(0,Number(s))));return L6(n,i,r)}function M6(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 U6(t,e){if(e==="x11")return $6.get(t);if(e==="svg")return wl.get(t);const n=v6.get(e),i=/^\d{1,3}$/.test(t)?Number(t):0;return n!==void 0&&i>=1?n[i-1]:void 0}function G6(t){return t==="line"?{hex:"#fffffe",alpha:0,unknown:!1,list:null}:{hex:"#000000",alpha:1,unknown:!1,list:null}}function j6(t){const e=t.indexOf(";");return e>=0?t.slice(0,e):t}function F6(t,e,n,i){const r=i&&t.startsWith(e)?wl.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 P6(e,s)}function z6(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)&&wl.has(r.toLowerCase()))return G6(n);l||(r=j6(r),s=n==="fill"?"gradient":"lines")}const a=F6(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 Ih(t){return Math.max(0,Math.min(255,Math.round(t))).toString(16).padStart(2,"0")}function Wi(t,e,n){return`#${Ih(t)}${Ih(e)}${Ih(n)}`}function Lo(t){return x(Math.max(0,Math.min(1,t)))}function Po(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 W6=[[.41239079926595934,.357584339383878,.1804807884018343],[.21263900587151027,.715168678767756,.07219231536073371],[.01933081871559182,.11919477979462598,.9505321522496607]],B6=[[3.2409699419045226,-1.537383177570094,-.4986107602930034],[-.9692436362808796,1.8759675015077202,.04155505740717559],[.05563007969699366,-.20397695888897652,1.0569715142428786]],H6=[[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.929286861586343,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],Y6=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],V6=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],K6=[[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]];function tg(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=Po(H6,Po(W6,e));return Po(V6,n.map(Math.cbrt))}function _1(t){const e=Po(K6,t).map(n=>n**3);return Po(B6,Po(Y6,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 ng(t){return t.every(e=>e>=0&&e<=1)}function ig(t){return t.map(e=>Math.max(0,Math.min(1,e)))}function S1(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2])}function X6(t){if(ng(t))return t;const e=.02,[n,i,r]=tg(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=_1(l(a));if(ng(c))return c;const d=ig(c);return S1(tg(d),l(a))<e?ig(t):q6(l,a,d)}function q6(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=_1(d);if(a&&ng(u)){o=c;continue}s=ig(u);const f=S1(tg(s),d);if(f>=.02)l=c;else{if(.02-f<1e-4)break;a=!1,o=c}}return s}function ME(t){const[e,n,i]=X6(t);return Wi(e*255,n*255,i*255)}const J6=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Z6=/(%|deg|grad|rad|turn)$/i;function Q6(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 O1(t){const e=Z6.exec(t)?.[1]??"",n=t.slice(0,t.length-e.length);if(!J6.test(n))return null;const i=Number(n);return Number.isFinite(i)?{value:i,unit:e.toLowerCase()}:null}function eU(t){if(t===void 0)return 1;const e=O1(t);return e===null||e.unit!==""&&e.unit!=="%"?null:Lo(e.unit==="%"?e.value/100:e.value)}function tU(t){const e=/^(rgba?|hsla?)\(([^()]*)\)$/i.exec(t);if(e===null)return null;const n=Q6(e[2]);if(n===null)return null;const i=n.parts.map(O1),r=eU(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:ME(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:ME([f(0),f(8),f(4)]),alpha:r}}function Fy(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:Wi(s[0],s[1],s[2]),alpha:i.length===4?Lo(s[3]/255):1}}case 6:return{hex:`#${i.toLowerCase()}`,alpha:1};case 8:return e?{hex:Wi(r(2),r(4),r(6)),alpha:Lo(r(0)/255)}:{hex:Wi(r(0),r(2),r(4)),alpha:Lo(r(6)/255)};default:return null}}function $h(t){const e=t.toLowerCase();if(e==="transparent")return{hex:"#000000",alpha:0};const n=wl.get(e);return n!==void 0?{hex:n,alpha:1}:Fy(t,!1)??tU(t)}function nU(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 N1(t){const e=t.toLowerCase();if(e==="transparent")return{color:"#000000",alpha:0,read:!0};const n=wl.get(e);if(n!==void 0)return N1(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=nU(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:Wi(o,l,a),alpha:(r*255&255)/255,read:s}}const iU=/^(?:\d+(?:\.\d*)?|\.\d+)$/;function rU(t){const e=w1.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:Wi(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=>iU.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 Fy(t,!1);if(o==="RGB")return{hex:Wi(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:Wi(u(l),u(a),u(c)),alpha:1}}function sU(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:Wi(n,i,r),alpha:Lo(s)}:null}function $e(t,e,n,i={}){if(t!==null&&typeof t=="object")return lU(t,e,n);if(typeof t=="number"&&e==="java"&&Number.isInteger(t)&&Math.abs(t)<=4294967295){_i(n,1);const o=t>>>0;return{color:Wi(o>>>16&255,o>>>8&255,o&255),alpha:1}}if(e==="graphology"&&typeof t=="string"&&t.trim()==="")return _i(n,1),B(n,v.BAD_VALUE,t),{color:"#000000",alpha:1};const r=ct(t,n);if(r===null)return null;if(e==="graphviz"||e==="x11")return aU(r,e==="x11"?"x11":"graphviz",n,i);if(e==="graphology")return oU(t,r,n);const s=cU(r.trim(),e);return s===null?(B(n,v.BAD_VALUE,r),null):{color:s.hex,alpha:s.alpha}}function oU(t,e,n){if(typeof t!="string")return B(n,v.BAD_VALUE,e),null;const i=N1(e);return i.read||B(n,v.BAD_VALUE,e),{color:i.color,alpha:i.alpha}}function lU(t,e,n){_i(n,1);const i=e==="gexf"||e==="gephi"?sU(t):null;return i===null?(B(n,v.BAD_VALUE,t),null):{color:i.hex,alpha:i.alpha}}function aU(t,e,n,i){const r=e==="x11",s=z6(t,r?null:i.scheme??null,i.use??"line",!r);return s.unknown&&(B(n,v.BAD_VALUE,t),r)?null:(s.list!==null&&B(n,s.list==="gradient"?v.GRADIENT:v.COLOR_LIST,t),{color:s.hex,alpha:Lo(s.alpha)})}function cU(t,e){const n=t.toLowerCase();switch(e){case"dvips":return rU(t);case"yfiles3":return Fy(t,!0)??$h(n.replaceAll("_",""));case"java":case"gephi":case"cytoscape":{const i=C6.get(n);return i===void 0?$h(t):{hex:i,alpha:1}}default:return $h(t)}}function _l(t,e,n,i){return i?t.alpha===1?e:x((e??1)*t.alpha):(t.alpha<1&&B(n,v.ALPHA_DROPPED,t.color),e)}function E(t,e){return{value:t,source:e}}const pe="cytoscape-impl vizmap-gui-impl default_vizmap.xml, style default, line",Ne="cytoscape-api BasicVisualLexicon.java line",Ir="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",ke="graphviz.org/docs/attrs",dU="yEd Q&A, How can I change the default nodes and/or default edges",Gn="yEd GraphML corpus, most frequent value",Ll="yFiles for Java 2.19 EdgeRealizer API docs",uU="yFiles for Java 2.19 DefaultBackgroundRenderer API docs",jt="yFiles for HTML API docs,",En="gephi master 92e503df61a7",ze="vis-network 10.1.2 vis-network.esm.js",Pl="vis-network 9.1.9 standalone/umd/vis-network.js",$r="sigma 3.0.3 packages/sigma/src",ri="sigma 4.0.1 dist/types-d8ce3382.esm.js",qi="Pajek 6.02 reference manual",Ai="ogdf master 1a40505ac006",Ji="OGDF 2025.10 GraphIO::drawSVG with its default SVGSettings (graph-io/test/fidelity/oracles/gml-specimen-labels-p5.svg: ",We="networkx 6da4704cbf32 networkx/drawing/nx_pylab.py line",Sn="measured in the program's own SVG export (graph-io/test/fidelity/oracles/",_t=`${Sn}pajek-`,UE={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:`${Sn}cx-ndex-90f78bcd, cx2-u2os-hierarchy, cx2-signor-aml, cx2-syn-bypass, cx-syn-mappings: each arrow's unit glyph), Cytoscape 3.10.5`},GE=E("midpoints","cytoscape-impl ding-presentation-impl GraphGraphics.java computeCubicPolyEdgePath (cubic pieces between the handles' midpoints, controls pulled toward each handle by CURVE_ELLIPTICAL)"),A1=`${Sn}xgmml-specimen-labels: label-background-* boxes and the captions' two lines), Cytoscape 3.10.5`,Ic=E(0,A1),$c=E(1,A1),jE=E("inside",`${Sn}cx2-repro-shared-interaction, cys-luad-vest-v2, cx2-synthetic-lethal), Cytoscape 3.10.5`),FE={length:(t,e)=>6*t+e,aspect:1,source:`${Sn}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 fU=new Map([{tool:"cytoscape",version:"cytoscape-impl develop 6c63e97c5152 (3.11)",units:"px",roundedCornerRadius:jn("cytoscape"),arrowhead:UE,node:{fill:E("#89d0f5",`${pe} 382`),fillOpacity:E(1,`${pe} 383`),shape:E("round-rectangle",`${pe} 367`),width:E(75,`${pe} 384`),height:E(35,`${pe} 358`),borderColor:E("#cccccc",`${pe} 392`),borderWidth:E(0,`${pe} 350`),borderStyle:E("solid",`${pe} 366`),borderPosition:jE,borderWaveAmplitude:E(10,Ir),borderWavePeriod:E(20,Ir),labelColor:E("#000000",`${pe} 395`),labelFont:E("DejaVu Sans, sans-serif",`${pe} 370 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${pe} 370`),labelItalic:E(!1,`${pe} 370`),labelSize:E(12,`${pe} 371`),labelWrapWidth:E(200,`${pe} 372`),labelWrapTrailingSpace:E(!0,`${Sn}cx-ndex-90f78bcd: each word is measured with the space after it), Cytoscape 3.10.5`),labelPosition:E("center",`${pe} 380`),labelPadding:Ic,labelLineHeight:$c},edge:{color:E("#848484",`${pe} 431`),width:E(2,`${pe} 417`),lineStyle:E("solid",`${pe} 438`),waveAmplitude:E(10,Ir),wavePeriod:E(20,Ir),opacity:E(1,`${pe} 423`),sourceArrow:E("none",`${pe} 437`),targetArrow:E("none",`${pe} 428`),sourceArrowColor:E("#000000",`${pe} 432`),targetArrowColor:E("#000000",`${pe} 432`),labelColor:E("#000000",`${pe} 415`),labelFont:E("DejaVu Sans, sans-serif",`${pe} 439 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${pe} 439`),labelItalic:E(!1,`${pe} 439`),labelSize:E(10,`${pe} 439`),labelPadding:Ic,labelLineHeight:$c,curved:E(!1,`${pe} 422`),bendCurve:GE},graph:{background:E("#ffffff",`${pe} 335`)},derived:[{kind:"labelFromColumn",column:"name",source:`${pe} 406-408`}]},{tool:"cytoscape-fallbacks",version:"cytoscape-api develop (3.11)",units:"px",roundedCornerRadius:jn("cytoscape-fallbacks"),arrowhead:UE,node:{fill:E("#c80000",`${Ne} 83`),fillOpacity:E(1,`${Ne} 273`),shape:E("ellipse",`${Ne} 302-303`),width:E(60,`${Ne} 155`),height:E(40,`${Ne} 163`),borderColor:E("#000000",`${Ne} 230`),borderWidth:E(2,`${Ne} 54`),borderPosition:jE,borderWaveAmplitude:E(10,Ir),borderWavePeriod:E(20,Ir),labelColor:E("#000000",`${Ne} 91`),labelFont:E("DejaVu Sans, sans-serif",`${Ne} 255 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${Ne} 255`),labelItalic:E(!1,`${Ne} 255`),labelSize:E(12,`${Ne} 55`),labelWrapWidth:E(200,`${Ne} 196`),labelWrapTrailingSpace:E(!0,`${Sn}cx-ndex-90f78bcd: each word is measured with the space after it), Cytoscape 3.10.5`),labelPosition:E("center",`${Ne} 205`),labelPadding:Ic,labelLineHeight:$c},edge:{color:E("#404040",`${Ne} 469`),width:E(1,`${Ne} 368`),lineStyle:E("solid",`${Ne} 392`),waveAmplitude:E(10,Ir),wavePeriod:E(20,Ir),sourceArrow:E("none",`${Ne} 487`),targetArrow:E("none",`${Ne} 493`),labelColor:E("#000000",`${Ne} 327`),labelFont:E("DejaVu Sans, sans-serif",`${Ne} 408 (SansSerif, drawn in Java's face for it)`),labelWeight:E("normal",`${Ne} 408`),labelItalic:E(!1,`${Ne} 408`),labelSize:E(10,`${Ne} 416`),labelPadding:Ic,labelLineHeight:$c,bendCurve:GE},graph:{background:E("#ffffff",`${Ne} 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,`${ke}/style/ (default "", not filled)`),borderColor:E("#000000",`${ke}/color/`),borderWidth:E(1,`${ke}/penwidth/; lib/common/const.h line 77`),borderPosition:E("center",`${Sn}dot-synth-nodes), Graphviz strokes the node's own outline`),shape:E("ellipse",`${ke}/shape/; lib/common/const.h line 76`),width:E(54,`${ke}/width/ (0.75 inch); lib/common/const.h line 72`),height:E(36,`${ke}/height/ (0.5 inch); lib/common/const.h line 73`),labelColor:E("#000000",`${ke}/fontcolor/`),labelSize:E(14,`${ke}/fontsize/; lib/common/const.h line 61`),labelFont:E("Times, serif",`${ke}/fontname/ (Times-Roman); lib/common/const.h line 67`),labelPosition:E("center",`${ke}/labelloc/`)},edge:{color:E("#000000",`${ke}/color/`),width:E(1,`${ke}/penwidth/`),lineStyle:E("solid",`${ke}/style/`),sourceArrow:E("none",`${ke}/dir/`),targetArrow:E("none",`${ke}/dir/ (none in a graph)`),arrowSize:E(1,`${ke}/arrowsize/`),labelColor:E("#000000",`${ke}/fontcolor/`),labelSize:E(14,`${ke}/fontsize/`),labelFont:E("Times, serif",`${ke}/fontname/ (Times-Roman)`)},graph:{background:E("#ffffff",`${ke}/bgcolor/ (default unset); lib/common/emit.c emit_background (an unset bgcolor paints the page white)`)},derived:[{kind:"labelFromId",source:String.raw`${ke}/label/ (default \N, the node name)`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${ke}/dir/ (forward in a digraph); ${ke}/arrowhead/ (normal)`}]},{tool:"yed",version:"yEd / yFiles for Java 2.19",units:"px",roundedCornerRadius:jn("yed"),arrowhead:FE,node:{fill:E("#ffcc00",`${dU}; ${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",`${Sn}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",`${Ll} (line color defaults to Color.black)`),width:E(1,`${Ll} (line type defaults to LineType.LINE_1)`),lineStyle:E("solid",`${Ll} (line type defaults to LineType.LINE_1)`),sourceArrow:E("none",`${Ll} (defaults to Arrow.NONE)`),targetArrow:E("none",`${Ll} (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",`${uU} (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:FE,node:{fill:E("#ffffff",`${jt} ShapeNodeStyle fill`),borderColor:E("#000000",`${jt} ShapeNodeStyle stroke`),borderWidth:E(1,`${jt} ShapeNodeStyle stroke`),borderPosition:E("center",`${Sn}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:`${Sn}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,`${En} AbstractProcessor.java lines 195-198 (size 10 is a radius)`),height:E(20,`${En} 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",`${Sn}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",`${En} NodeLabelRenderer.java (a label is drawn centered on its node)`),labelOnTop:E(!0,`${En} 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",`${En} DefaultPreset.java line 62`),targetArrow:E("none",`${En} DefaultPreset.java line 62`),curved:E(!0,`${En} DefaultPreset.java (EDGE_CURVED true); Gephi Toolkit 0.11.3 SVG export`),fanned:E(!1,`${En} 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,`${En} EdgeRenderer.java (CurvedEdgeRenderer: an arc through both node centers of radius length / ARC_CURVENESS, default 1.2)`)},graph:{background:E("#ffffff",`${En} VizConfig.java line 111`)},derived:[{kind:"colorFromEndNodes",source:`${En} DefaultPreset.java (EDGE_COLOR EdgeColor.Mode.MIXED); Gephi Toolkit 0.11.3 SVG export`},{kind:"widthFromWeight",source:`${En} VizConfig.java lines 136, 144-145; DefaultPreset.java lines 67, 73`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${En} 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:`${ze} EdgeBase.getArrowData, ArrowHead, Bar, Box, Circle, Curve, InvertedCurve (measured on json-vis-unix, json-vis-world, json-vis-synth)`},nodeBorderOnScreen:E(!0,`${Pl} NodeBase.initContextForDraw and performStroke: borderWidth / view.scale, at most the node's width`),node:{fill:E("#97c2fc",`${ze} lines 32986-33110`),borderColor:E("#2b7ce9",`${ze} lines 32986-33110`),borderWidth:E(1,`${ze} lines 32986-33110`),borderPosition:E("center",`${Pl} NodeBase.performStroke: ctx.stroke() on the shape's own path`),shape:E("ellipse",`${ze} lines 32986-33110`),labelColor:E("#343434",`${ze} lines 32986-33110`),labelSize:E(14,`${ze} lines 32986-33110`),labelFont:E("arial",`${ze} lines 32986-33110`),labelPosition:E("center",`${ze} lines 32986-33110`),labelMinScreenSize:E(4,`${Pl} Label.draw, nodes scaling.label.drawThreshold 5`)},edge:{width:E(1,`${ze} lines 25160-25290`),outlineColor:E("#6f6f6f",`${ze} lines 25160-25290 (background.color)`),lineStyle:E("solid",`${ze} lines 25160-25290 (dashes false)`),sourceArrow:E("none",`${ze} lines 25160-25290`),targetArrow:E("none",`${ze} lines 25160-25290`),labelColor:E("#343434",`${ze} lines 25160-25290`),labelSize:E(14,`${ze} lines 25160-25290`),labelFont:E("arial",`${ze} lines 25160-25290`),labelMinScreenSize:E(4,`${Pl} Label.draw, edges scaling.label.drawThreshold 5`),labelPosition:E("center",`${Pl} Edge.drawLabel (the label at the line's middle point)`),labelOutlineColor:E("#ffffff",`${ze} lines 25160-25290 (font.strokeColor)`),labelOutlineWidth:E(2,`${ze} 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:`${ze} lines 32986-33110`},{kind:"colorFromSourceNode",source:`${ze} lines 25160-25290 (color.inherit "from")`}]},{tool:"sigma",version:"sigma 4.0.1",units:"relative",roundedCornerRadius:jn("sigma"),node:{fill:E("#666666",`${ri} DEFAULT_NODE_DISPLAY_DATA (color "#666")`),shape:E("ellipse",`${$r}/settings.ts lines 119-126`),width:E(20,`${ri} DEFAULT_NODE_DISPLAY_DATA (size 10 is a radius)`),height:E(20,`${ri} DEFAULT_NODE_DISPLAY_DATA (size 10 is a radius)`),labelColor:E("#000000",`${$r}/settings.ts lines 119-126`),labelFont:E("Arial",`${$r}/settings.ts lines 119-126`),labelSize:E(12,`${ri} DEFAULT_NODE_DISPLAY_DATA (labelSize 12)`),labelWeight:E("normal",`${$r}/settings.ts lines 119-126`),labelPosition:E("right",`${ri} DEFAULT_NODE_DISPLAY_DATA (labelPosition "right")`),labelGridCellSize:E(100,`${ri} LabelGrid.getLabelsToDisplay (labelDensity 1, labelGridCellSize 100)`),labelOnTop:E(!0,`${ri} labels are drawn by their own program after every node and edge`),labelMinNodeScreenSize:E(12,`${ri} renderLabels (labelRenderedSizeThreshold 6, a radius)`)},edge:{color:E("#cccccc",`${$r}/settings.ts lines 119-126`),width:E(.5,`${ri} DEFAULT_EDGE_DISPLAY_DATA (size 1)`),labelColor:E("#666666",`${ri} 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",`${$r}/settings.ts lines 119-126 (type line)`),targetArrow:E("none",`${$r}/settings.ts lines 119-126 (type line)`),minScreenWidth:E(.85,`${ri} 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:`${$r}/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:`${_t}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",`${qi} p. 85`),opacity:E(1,`${qi} p. 87`),borderColor:E("#660000",`${_t}football, kdorola: every vertex without bc)`),borderWidth:E(.5,`${_t}football, kdorola: every vertex without bw)`),borderPosition:E("center",`${_t}specimen-node-fills-borders-p3: bw 8 draws a vertex of size 36 44 across)`),width:E(20,`${_t}football, iliad: a vertex without s_size, x_fact or y_fact)`),height:E(20,`${_t}football, iliad: a vertex without s_size, x_fact or y_fact)`),fill:E("#ffd9bc",`${_t}football, kdorola: every vertex without ic)`),labelColor:E("#ad0000",`${_t}football, 1crn: every label without lc)`),labelSize:E(15,`${_t}football, 1crn: every label without fos)`),labelFont:E("Arial",`${_t}football, 1crn: every label without font)`),labelWeight:E("bold",`${_t}football, 1crn: every label is bold)`),labelPosition:E("center",`${_t}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelOffsetX:E(5.176380902,`${_t}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelOffsetY:E(14.121016526,`${_t}football, 1crn, specimen-labels: lr 20 lphi 285)`),labelShiftX:E(.5,`${_t}football, 1crn, specimen-labels: text-anchor start)`)},edge:{width:E(2,`${_t}1crn, lin-rel4, synth-vertices: edges without w; c: w 0.5 drawn 1)`),color:E("#007091",`${_t}1crn, lin-rel4, c: edges without c)`),lineStyle:E("solid",`${qi} p. 90`),opacity:E(1,`${qi} p. 87`),sourceArrow:E("none",`${qi} p. 91`),targetArrow:E("none",`${qi} p. 91 (edges have none)`)},graph:{background:E("#ffffff",`${qi}, Draw window (assumed: a white background)`)},derived:[{kind:"labelFromColumn",column:"label",source:`${qi}, vertex labels (drawn by default)`},{kind:"targetArrowOnDirected",arrow:"triangle",source:`${qi} p. 91 (arcs)`}]},{tool:"ogdf",version:"ogdf master 1a40505ac006",units:"px",roundedCornerRadius:jn("ogdf"),arrowhead:{length:(t,e)=>3*e*t,aspect:.5,source:`${Sn}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",`${Ai} LayoutStandards.cpp lines 38-45`),shape:E("rectangle",`${Ai} LayoutStandards.cpp lines 38-45`),width:E(20,`${Ai} LayoutStandards.cpp lines 38-45`),height:E(20,`${Ai} LayoutStandards.cpp lines 38-45`),borderColor:E("#000000",`${Ai} LayoutStandards.cpp lines 38-45`),borderWidth:E(1,`${Ai} LayoutStandards.cpp lines 38-45`),borderStyle:E("solid",`${Ai} LayoutStandards.cpp lines 38-45`),labelColor:E("#000000",`${Ji}fill #000000)`),labelFont:E("Arial",`${Ji}font-family Arial)`),labelSize:E(10,`${Ji}font-size 10)`),labelPosition:E("center",`${Ji}text-anchor middle at the node's center)`)},edge:{color:E("#000000",`${Ai} LayoutStandards.cpp lines 38-45`),width:E(1,`${Ai} LayoutStandards.cpp lines 38-45`),lineStyle:E("solid",`${Ai} LayoutStandards.cpp lines 38-45`),labelColor:E("#000000",`${Ji}fill #000000)`),labelFont:E("Arial",`${Ji}font-family Arial)`),labelSize:E(10,`${Ji}font-size 10)`),labelPosition:E("center",`${Ji}text-anchor middle on the line, dominant-baseline middle)`)},graph:{background:E("#ffffff",`${Ji}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",`${We} 1378`),fillOpacity:E(1,`${We} 549`),shape:E("ellipse",`${We} 1379 (node_shape "o")`),width:E(17.3205,`${We} 1377 (node_size 300, points squared)`),height:E(17.3205,`${We} 1377 (node_size 300, points squared)`),labelColor:E("#000000",`${We} 2143`),labelSize:E(12,`${We} 2142`),labelFont:E("sans-serif",`${We} 2144`),labelWeight:E("normal",`${We} 2145`),labelPosition:E("center",`${We} 2148-2149`)},edge:{color:E("#000000",`${We} 1768 (edge_color "k")`),width:E(1,`${We} 1767`),lineStyle:E("solid",`${We} 1769`),opacity:E(1,`${We} 568`),sourceArrow:E("none",`${We} 1848-1849`),targetArrow:E("none",`${We} 1849 (undirected graphs draw "-")`),labelColor:E("#000000",`${We} 557`),labelSize:E(12,`${We} 556`),labelFont:E("sans-serif",`${We} 558`),labelWeight:E("normal",`${We} 559`)},graph:{},derived:[{kind:"targetArrowOnDirected",arrow:"triangle",source:`${We} 1848 (arrowstyle "-|>" for directed graphs)`}]}].map(t=>[t.tool,t]));function Tr(t){return fU.get(t)??null}const hU=new Set(["string","dict","bool","i32","u32","u8","f32","f64"]),pU=/^(?:x|y|z|_pos)$/i,T1="graphty.parent",gU=8;function mU(t){const e=Ut(t);if(!e.expanded)return!1;for(let n=0;n<t.edgeCount;n++)if(e.folded(n))return!0;return!1}function Kr(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=>yU(n,o))){const o=Array.from({length:i},(l,a)=>{const c=mf(n,s,a);return typeof c=="string"||typeof c=="number"||typeof c=="boolean"?c:null});if(s!==T1)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&&!mU(t)){const s=t.directed?["degree","indegree","outdegree"]:["degree"];for(const o of s)r.push({ref:{computed:o},values:ic(t,o)})}return r}function yU(t,e){if(e.startsWith("graphty.")&&e!==T1||e==="selected"||pU.test(e))return!1;const n=t.get(e);return n!==null&&n.meta.role!=="position"&&hU.has(n.meta.dtype)&&n.meta.components===1}function to(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:zy(t).length,ids:i(e)+i(n)}}function zy(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 bU(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 EU(t){return"style"in t?t.style:"computed"in t?t.computed:t.data}function wU(t,e){const{seen:n,categorical:i,numeric:r,integers:s,lo:o,hi:l,count:a}=bU(t.values),d=!("computed"in t.ref)&&r&&s&&a>=gU&&n.size===a&&l-o+1===a;return{feature:t,name:EU(t.ref),distinct:n.size,categorical:a>0&&i,numeric:a>0&&r&&!d,raw:e}}const Z="graphty.styles",au=16*1024*1024,_U=64,Ds=4096,I1=256,$1=new Set(["__proto__","constructor","prototype"]),Wy=["node","edge"],SU=new Set(["degree","indegree","outdegree"]);function Ef(t,e){return`graphty.style.${t}.${e}`}const OU={"\\":String.raw`\u005c`,n:String.raw`\u000a`,t:String.raw`\u0009`};function Sl(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:zy(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=DU(n.rules.filter(p=>p.target===d)).filter(p=>u.has(p)&&!$1.has(p)&&p.length<=I1).slice(0,Ds);return Object.fromEntries(h.map(p=>[p,rg(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)=>OU[d]??c)}function sc(t,e,n="all"){let i=null;if(t.length>au)i="TOO_LARGE";else if(n==="all"){const r=JSON.parse(t),{nodes:s,edges:o,ids:l}=r.fingerprint,a=oc(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 C1 extends Error{}function se(){throw new C1}function oc(t,e){if(typeof t!="string")return{ok:!1,reason:"INVALID"};if(t.length>au)return{ok:!1,reason:"TOO_LARGE"};let n;try{n=JSON.parse(t)}catch{return{ok:!1,reason:"NOT_JSON"}}if(!NU(n))return{ok:!1,reason:"INVALID"};const i=Ge(n)?n:null;if(i===null)return{ok:!1,reason:"INVALID"};if(i.version!==1)return{ok:!1,reason:"VERSION"};const r=Ge(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=AU(i)}catch(l){if(l instanceof C1)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 NU(t){const e=[[t,0]];for(;e.length>0;){const[n,i]=e.pop();if(n===null||typeof n!="object")continue;if(i>=_U||!Array.isArray(n)&&Object.keys(n).some(s=>$1.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 Ge(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function mt(t){return typeof t=="string"&&t.length<=I1?t:se()}function zE(t){return t==null?null:mt(t)}function v1(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function hi(t){return v1(t)?t:se()}function Ct(t,e){return Array.isArray(t)&&t.length<=e?t:se()}function AU(t){const e=Ge(t.source)?t.source:se(),n=Ge(t.units)?t.units:se(),i=n.length==="px"||n.length==="relative"?n.length:se(),r=Ge(t.fingerprint)?t.fingerprint:se(),s=f=>typeof f=="number"&&Number.isSafeInteger(f)&&f>=0?f:se(),o=Ge(t.columns)?t.columns:se(),l={version:1,source:{format:mt(e.format),dialect:zE(e.dialect),tool:zE(e.tool)},units:{length:i},graph:D1(t.graph??{}),rules:Ct(t.rules,Ds).map(RU),columns:{node:Ct(o.node,Ds).map(mt),edge:Ct(o.edge,Ds).map(mt)},fingerprint:{nodes:s(r.nodes),edges:s(r.edges),ids:mt(r.ids)}},a=t.data===void 0?l:{...l,data:CU(t.data)},c=t.booleans===void 0?a:{...a,booleans:TU(t.booleans)};if(t.values===void 0)return c;const d=t.order===void 0?void 0:IU(t.order,l.fingerprint.nodes),u=$U(t.values,l);return{...c,...d===void 0?{}:{order:d},values:u}}function TU(t){const e=Ge(t)?t:se();return{node:Ct(e.node??[],Ds).map(mt),edge:Ct(e.edge??[],Ds).map(mt)}}function IU(t,e){const n=Ct(t,e).map(i=>typeof i=="string"?i:se());return n.length===e?n:se()}function $U(t,e){const n=Ge(t)?t:se(),i={node:new Map,edge:new Map};for(const r of Wy){const s=r==="node"?e.fingerprint.nodes:e.fingerprint.edges,o=Ge(n[r])?n[r]:se();for(const l of e.columns[r]){const a=Ct(Object.hasOwn(o,l)?o[l]:se(),s);a.length!==s&&se(),i[r].set(l,a.map(c=>c===null?null:hi(c)))}}return i}function CU(t){const e=Ge(t)?t:se(),n=i=>{const r=Ge(i)?i:se(),s=Object.keys(r);return s.length>Ds&&se(),new Map(s.map(o=>[mt(o),mt(r[o])]))};return{node:n(e.node),edge:n(e.edge)}}function vU(t){return t===null?"":typeof t=="string"||typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t)}function rg(t,e,n){let i=2166136261,r=1523705862;for(let o=0;o<n;o++){const l=`${vU(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 DU(t){const e=new Set;for(const{ext:n,...i}of t)JSON.stringify(i,(r,s)=>(Ge(s)&&typeof s.data=="string"&&Object.keys(s).length===1&&e.add(s.data),s));return[...e]}function kU(t,e){const{ext:n,...i}=t,r=JSON.parse(JSON.stringify(i,(s,o)=>Ge(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 WE(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)&&rg(s,a,o)===c)){l??=new Map(Array.from(s.names(),d=>[d,rg(s,d,o)]));for(const[d,u]of l)if(u===c){i.set(a,d);break}}return i}function D1(t){const e=Ge(t)?t:se(),n=Object.create(null);for(const i of Object.keys(e))n[mt(i)]=hi(e[i]);return n}function RU(t){const e=Ge(t)?t:se(),n=e.target==="node"||e.target==="edge"?e.target:se(),i={id:mt(e.id),target:n,role:mt(e.role),origin:mt(e.origin),where:bd(e.where)};if(e.set!==void 0&&(i.set=D1(e.set)),e.map!==void 0){const r=Ge(e.map)?e.map:se(),s=Object.create(null);for(const o of Object.keys(r))s[mt(o)]=PU(r[o]);i.map=s}return e.facts!==void 0&&(i.facts=xU(e.facts)),e.ext!==void 0&&(i.ext=Ge(e.ext)?e.ext:se()),i}function yd(t){const e=Ge(t)?t:se();return typeof e.data=="string"?{data:mt(e.data)}:typeof e.style=="string"?{style:mt(e.style)}:typeof e.computed=="string"&&SU.has(e.computed)?{computed:e.computed}:se()}function bd(t){const e=Ge(t)?t:se();if("all"in e)return e.all===!0?{all:!0}:se();if("has"in e)return{has:yd(e.has)};if("eq"in e){const n=Ct(e.eq,2);return n.length===2?{eq:[yd(n[0]),hi(n[1])]}:se()}if("in"in e){const n=Ct(e.in,2);return n.length===2?{in:[yd(n[0]),Ct(n[1],65536).map(hi)]}:se()}return"and"in e?{and:Ct(e.and,64).map(bd)}:"or"in e?{or:Ct(e.or,64).map(bd)}:"not"in e?{not:bd(e.not)}:e}function LU(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?t:se()}function PU(t){const e=Ge(t)?t:se(),n=yd(e.by);switch(e.kind){case"passthrough":return{kind:"passthrough",by:n};case"discrete":return{kind:"discrete",by:n,table:Ct(e.table,1<<20).map(i=>{const r=Ct(i,2);return r.length===2?[hi(r[0]),hi(r[1])]:se()})};case"continuous":return{kind:"continuous",by:n,points:Ct(e.points,4096).map(i=>{const r=Ge(i)?i:se();return{at:typeof r.at=="number"&&Number.isFinite(r.at)?r.at:se(),below:hi(r.below),value:hi(r.value),above:hi(r.above)}}),...e.step===void 0?{}:{step:LU(e.step)}};default:return{...e,kind:mt(e.kind),by:n}}}function xU(t){const e=Ge(t)?t:se(),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=mt(e.reason)),e.names!==void 0&&(i.names=Ct(e.names,1<<20).map(l=>{const a=Ct(l,2);return a.length===2?[hi(a[0]),String(hi(a[1]))]:se()})),i}function BE(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"?GU(t,e,l):jU(e,l));continue}const a=Ef(n,o);if(!r.has(a))return null;const c=Array.from({length:s},(d,u)=>{const f=K(r.value(a,u));return v1(f)?f:null});i.set(o,n==="edge"?k1(e,c):c)}return i}function MU(t,e){for(const n of Wy)for(const i of t.booleans?.[n]??[]){const r=e[n].get(i);r!==void 0&&e[n].set(i,r.map(UU))}}function UU(t){return t===1||t==="1"||t==="true"?!0:t===0||t==="0"||t==="false"?!1:t}function GU(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 jU(t,e){const n=zy(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}),k1(t,i)}function k1(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 FU={node:["fill","fillOpacity"],edge:["color","opacity"]};function zU(t,e,n,i,r){const[s,o]=FU[e],l=t[s];if(l===void 0)return t;const a=t[o],c=Si(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 R1(t,e){let n=e,i=2;for(;t(n);)n=`${e}#${String(i)}`,i++;return n}function WU(t,e){return ni[t].get(e)==="text"}function BU(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&&!jy(l,e[o])&&!a&&(s??=new Array(e.length).fill(null),s[o]=l)}return s}function HU(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=Si(e,n,l,i),d=BU(a,c,s(l),WU(n,l));if(d!==null){const u=R1(f=>r.has(f),`exceptions.${l}`);r.set(u,d),o[l]={kind:"passthrough",by:{style:u}}}}return o}function L1(t,e,n,i={},r=[],s=null,o=!1){const l=BE(t,e,"node"),a=BE(t,e,"edge");if(l===null||a===null)return null;const c={node:l,edge:a};MU(t,c);const d={node:Kr(e,"node"),edge:Kr(e,"edge")},u={node:WE(t,e,"node"),edge:WE(t,e,"edge")},f=t.rules.map(p=>u[p.target].size===0?p:kU(p,u[p.target])),h=[...f];for(const p of Wy){const g=p==="node"?e.nodeCount:e.edgeCount,m=Ar(p,g,c[p],d[p],e),y=o?zU(i[p]??{},p,f,m,g):i[p],b=S=>(s===null?null:Tr(s))?.[p]?.[S]?.value,_=HU(y??{},f,p,m,c[p],b);if(Object.keys(_).length>0){const S=R1(I=>h.some(T=>T.id===I),`${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:to(e)}}const zt=(t,e)=>$e(t,"cytoscape",e)?.color??null,_o=(t,e)=>{const n=V(t,e);return n===null?null:n>255?(B(e,v.BAD_VALUE,String(t)),null):x(Math.round(n)/255)},So=(t,e)=>tc(t,"css",e),Zi=(t,e)=>V(t,e),sg=(t,e)=>{const n=V(t,e);return n===null?null:x(n/6)},HE=(t,e)=>{const n=typeof t=="number"?t:Number(ct(t,e)?.trim()??Number.NaN);return Number.isFinite(n)?x((n%360+360)%360):(B(e,v.BAD_VALUE,String(t)),null)},YE=(t,e)=>{const n=V(t,e);return n===null?null:Math.round(n)},Cc=(t,e)=>nt(t,e),Ch=(t,e)=>nc(t,e),VE=(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 nc(t,e)},YU=new Map([["rounded_rectangle","round-rectangle"]]),P1=t=>typeof t=="string"&&t.startsWith("other:")?`other:${t.slice(6).toLowerCase().replaceAll("_","-")}`:t,VU=(t,e)=>{const n=ct(t,e);return n===null?null:P1(YU.get(n.trim().toLowerCase())??oe("shape",n,"cytoscape",e))},By=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"]]),KU=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}]]),XU=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]]),qU=["none","delta","delta","delta","arrow","arrow","arrow","diamond","diamond","diamond","circle","circle","circle","t","t","t","half_top","half_bottom"];function Hy(t){const e=t.trim().toLowerCase();return/^\d{1,2}$/.test(e)?qU.at(Number(e))??e:e}const KE=(t,e)=>{const n=ct(t,e);return n===null?null:P1(By.get(Hy(n))??oe("arrow",n,"cytoscape",e))};function JU(t){return(e,n)=>{const i=ct(e,n);if(i===null)return null;const r=Hy(i);return KU.get(r)?.[t]??(By.has(r)?1:null)}}const ZU=(t,e)=>{const n=ct(t,e);if(n===null)return null;const i=Hy(n);return XU.get(i)??(By.has(i)?0:null)},QU=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 xl(t){return(e,n)=>{const i=ct(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=QU.get(r)??oe(t,i,"cytoscape",n),s===null||Xo("node",t,s)||t==="lineStyle"||s.startsWith("other:")?s:`other:${s}`}}function e4(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 cu(t,e,n){const i=e4(t.trim());return{family:i.family,weight:e||i.weight==="bold"?"bold":"normal",italic:n||i.italic}}function Yy(t,e){if(t!==null&&typeof t=="object"&&!Array.isArray(t))return t4(t,e);const n=ct(t,e);if(n===null)return null;const i=n.split(",");return i.length>=2?cu(i[0],!1,!1):n4(n)??cu(n,!1,!1)}function t4(t,e){const n=Object.hasOwn(t,"FONT_NAME")?ct(t.FONT_NAME,e):null;let i=Object.hasOwn(t,"FONT_FAMILY")?ct(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 cu(i,/bold/i.test(r.slice(0,32)),/italic/i.test(s.slice(0,32)))}function n4(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),cu(r,s,(i&2)!==0)}const Os="DejaVu Sans, sans-serif",Vy="DejaVu Serif, serif",Kl="DejaVu Sans Mono, monospace",i4=new Map([["sans-serif",Os],["monospace",Kl],["sansserif",Os],["dialog",Os],["default",Os],["dialoginput",Kl],["monospaced",Kl],["serif",Vy]]),XE=(t,e)=>{const n=Yy(t,e)?.family??null;return n===null?null:wf(n)},r4=new Set(["sans-serif","serif","monospace","cursive","fantasy","system-ui"]);function wf(t){const e=i4.get(t.toLowerCase());return e!==void 0?e:t.includes(",")||r4.has(t.toLowerCase())?t:`${t}, ${Os}`}const qE=(t,e)=>Yy(t,e)?.weight??null,JE=(t,e)=>Yy(t,e)?.italic??null,og=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]]]),s4=new Map([["center",0],["left",-1],["right",1],["top",-1],["bottom",1]]),ZE=new Map([["l","left"],["left","left"],["c","center"],["center","center"],["r","right"],["right","right"]]);function o4(t,e){const n=i=>og.get((ct(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 x1(t,e){if(t!==null&&typeof t=="object"&&!Array.isArray(t)){const l=t,a=g=>((Object.hasOwn(l,g)?ct(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")?o4(l,e):["HORIZONTAL_ANCHOR","VERTICAL_ANCHOR","HORIZONTAL_ALIGN","VERTICAL_ALIGN"].map(g=>s4.get(a(g)));if(d.includes(void 0))return B(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:ZE.get(a("JUSTIFICATION"))??"center",offset:[c("MARGIN_X"),c("MARGIN_Y")]}}const n=ct(t,e);if(n===null)return null;const i=n.split(",").map(l=>l.trim()),r=og.get(i[0].toUpperCase()),s=i.length>1?og.get(i[1].toUpperCase()):r?.map(l=>-l);if(r===void 0||s===void 0)return B(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:ZE.get((i[2]??"c").toLowerCase())??"center",offset:[o(3),o(4)]}}const l4=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 Ky(t){return t.node[0]===t.label[0]&&t.node[1]===t.label[1]?l4.get(`${t.node[0]},${t.node[1]}`)??"center":"center"}function a4(t,e,n){return Ky(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:[du(t.label[0]),du(t.label[1])]}}function du(t){return t===0?0:-t/2}const c4=(t,e)=>{const n=x1(t,e);return n===null?null:Ky(n)},Xy=Object.freeze({node:new Map([["fill",[["NODE_FILL_COLOR",zt],["NODE_BACKGROUND_COLOR",zt],["NODE_PAINT",zt]]],["fillOpacity",[["NODE_TRANSPARENCY",_o],["NODE_BACKGROUND_OPACITY",So]]],["borderColor",[["NODE_BORDER_PAINT",zt],["NODE_BORDER_COLOR",zt]]],["borderOpacity",[["NODE_BORDER_TRANSPARENCY",_o],["NODE_BORDER_OPACITY",So]]],["borderWidth",[["NODE_BORDER_WIDTH",Zi]]],["borderStyle",[["NODE_BORDER_STROKE",xl("borderStyle")],["NODE_BORDER_LINE_TYPE",xl("borderStyle")],["NODE_BORDER_STYLE",xl("borderStyle")]]],["shape",[["NODE_SHAPE",VU]]],["width",[["NODE_WIDTH",Zi]]],["height",[["NODE_HEIGHT",Zi]]],["label",[["NODE_LABEL",Cc]]],["labelColor",[["NODE_LABEL_COLOR",zt]]],["labelSize",[["NODE_LABEL_FONT_SIZE",YE]]],["labelWrapWidth",[["NODE_LABEL_WIDTH",Zi],["NODE_LABEL_MAX_WIDTH",Zi]]],["labelFont",[["NODE_LABEL_FONT_FACE",XE]]],["labelWeight",[["NODE_LABEL_FONT_FACE",qE]]],["labelItalic",[["NODE_LABEL_FONT_FACE",JE]]],["labelPosition",[["NODE_LABEL_POSITION",c4]]],["labelRotation",[["NODE_LABEL_ROTATION",HE]]],["labelOpacity",[["NODE_LABEL_TRANSPARENCY",_o],["NODE_LABEL_OPACITY",So]]],["tooltip",[["NODE_TOOLTIP",Cc]]],["visible",[["NODE_VISIBLE",Ch],["NODE_VISIBILITY",VE]]]]),edge:new Map([["color",[["EDGE_STROKE_UNSELECTED_PAINT",zt],["EDGE_LINE_COLOR",zt],["EDGE_UNSELECTED_PAINT",zt],["EDGE_PAINT",zt]]],["opacity",[["EDGE_TRANSPARENCY",_o],["EDGE_OPACITY",So]]],["width",[["EDGE_WIDTH",Zi]]],["lineStyle",[["EDGE_LINE_TYPE",xl("lineStyle")],["EDGE_LINE_STYLE",xl("lineStyle")]]],["sourceArrow",[["EDGE_SOURCE_ARROW_SHAPE",KE]]],["targetArrow",[["EDGE_TARGET_ARROW_SHAPE",KE]]],["arrowSize",[["EDGE_TARGET_ARROW_SIZE",sg],["EDGE_SOURCE_ARROW_SIZE",sg]]],["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",Ch]]],["label",[["EDGE_LABEL",Cc]]],["labelColor",[["EDGE_LABEL_COLOR",zt]]],["labelSize",[["EDGE_LABEL_FONT_SIZE",YE]]],["labelFont",[["EDGE_LABEL_FONT_FACE",XE]]],["labelWeight",[["EDGE_LABEL_FONT_FACE",qE]]],["labelItalic",[["EDGE_LABEL_FONT_FACE",JE]]],["labelWrapWidth",[["EDGE_LABEL_WIDTH",Zi],["EDGE_LABEL_MAX_WIDTH",Zi]]],["labelRotation",[["EDGE_LABEL_ROTATION",HE]]],["labelOpacity",[["EDGE_LABEL_TRANSPARENCY",_o],["EDGE_LABEL_OPACITY",So]]],["tooltip",[["EDGE_TOOLTIP",Cc]]],["visible",[["EDGE_VISIBLE",Ch],["EDGE_VISIBILITY",VE]]]])}),qo="NODE_SIZE",Xr=Zi,xo=zt,QE=t=>t.endsWith("_OPACITY")?So:_o,d4=new Set([qo,...Object.values(Xy).flatMap(t=>Array.from(t.values()).flatMap(e=>e.map(([n])=>n)))]),u4=/^(?: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 f4(t){return!d4.has(t)&&!u4.test(t)}const h4={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"]])},M1=8,p4=/^[A-Z][A-Z_0-9]+$/;function g4(t,e,n){const i=p4.test(e)?e:h4[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 m4(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>M1?o++:n.push([a,s+1]);continue}const[c,d]=g4(t,l,a);i.has(c)||i.set(c,d)}return o}function lg(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+=m4(t,o,r,i);return s>0&&n?.add(v.NESTING,t,"graphics",{sample:`deeper than ${M1}`,count:s}),i}const y4=new Map([["NODE_LABEL_FONT_SIZE",1],["EDGE_LABEL_FONT_SIZE",1],["NODE_TRANSPARENCY",1/255],["EDGE_TRANSPARENCY",1/255]]);function U1(t){return y4.get(t)}const uu=t=>String(Math.round(t*1e4)/1e4);function Ol(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(`${uu(h)},${uu(p)}`)}return a.join(" ")}function G1(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 _f(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 zs(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(`${uu(d)},${uu(u)}`)}return l.join(" ")}function fu(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 j1(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 b4(t,e){const n=new Map;return(i,r)=>{const s=`${i} ${r}`;let o=n.get(s);return o===void 0&&(o=E1(e,i,r,t),n.set(s,o)),o}}function Ws(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 E4(t,e,n,i){const{values:r}=i,s=w4(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);_4(i,u,f,r[u]?.[a]??null,d)&&(S4(l,r,u,e)[a]=f)}}for(const[a,c]of l)r[a]=c}function w4(t,e,n){return n!==void 0?Ws(e,t,n):i=>r=>e(t,r)[i]??null}function _4(t,e,n,i,r){return t.take?.(e,n,i)!==!1&&i!==n&&i===(r(e)??null)}function S4(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 no(t,e,n,i){const r=e===null?null:oc(e,to(t)),s=r?.ok===!0?L1(r.block,t,n):null;if(s===null)return;const o=b4(t,s);for(const l of["node","edge"]){const a=i(l,o,s);a!==null&&E4(l,l==="node"?t.nodeCount:t.edgeCount,o,a)}}function io(){const t=()=>({defaults:new Map,mappings:new Map,dependencies:new Map,bypassAliases:new Map});return{network:{defaults:new Map},node:t(),edge:t()}}const O4=new Map([["shared name","name"],["shared interaction","interaction"]]);function F1(t,e){for(const[n,i]of t.mappings){const r=O4.get(i.column);r!==void 0&&!e(i.column)&&e(r)&&t.mappings.set(n,{...i,column:r})}}function z1(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 ew(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 W1(t,e,n,i){for(const[r,s]of t.mappings){if(s.kind!=="discrete"||s.table.length===0)continue;const o=ew(s.type),l=ew(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 N4=new Set(["integer","long","double","float","int","short"]),B1=/^[+-]?(?:\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(N4.has(n)&&t.length<=64&&B1.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 A4=new Set(["K","V","L","E","G","OV"]);function T4(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 I4(t){const e=t.indexOf("="),n=e<0?-1:t.indexOf("=",e+1),i=t.slice(0,e);if(n<0||!A4.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 $4(t,e,n=null){const i=T4(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=I4(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 tw(t,e){return Array.from(t.entries.get(e)?.keys()??[]).sort((n,i)=>n-i)}function ag(t){return typeof t=="number"?Number.isFinite(t)?t:null:typeof t=="string"&&t.length<=64&&B1.test(t.trim())?Number(t.trim()):null}function C4(t,e,n=null){if(t===null||typeof t!="object"||typeof t.definition!="string")return null;const{type:i,definition:r}=t,s=$4(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 tw(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 tw(s,"OV")){const c=ag(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 Ee(t,e){return t!==null&&typeof t=="object"&&Object.hasOwn(t,e)?t[e]:void 0}function v4(t){const e=Ee(t,"definition"),n=Ee(e,"attribute");if(typeof n!="string")return null;const i=Ee(e,"type"),r=typeof i=="string"?i:null,s=Ee(e,"map"),o=Array.isArray(s)?s:[];switch(String(Ee(t,"type")).toUpperCase()){case"PASSTHROUGH":return{kind:"passthrough",column:n,type:r};case"DISCRETE":{const l=[];for(const a of o){const c=qy(Ee(a,"v"),r),d=Ee(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:D4(o)};default:return null}}function D4(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"&&k4(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 k4(t,e){const n=ag(Ee(t,"min")),i=ag(Ee(t,"max")),r=Ee(t,"minVPValue")??Ee(t,"maxVPValue"),s=Ee(t,"maxVPValue")??Ee(t,"minVPValue");if(n!==null){const o=e(n);o.above=r,Ee(t,"includeMin")!==!1&&(o.value=r)}if(i!==null){const o=e(i);o.below=s,Ee(t,"includeMax")!==!1&&o.value===void 0&&(o.value=s)}}function er(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)?t:{}}function R4(t,e){const n=io(),i=s=>Ee(s,"applies_to")??Ee(s,"view")??null,r=[];for(const s of t)/default|network/.test(String(Ee(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]?L4.get(String(Ee(s,"properties_of"))):void 0;if(o===void 0)continue;const l=er(Ee(s,"properties"));for(const a of Object.keys(l))n[o].defaults.set(a,l[a]);o!=="network"&&P4(n,o,s,e)}return n}const L4=new Map([["nodes:default","node"],["edges:default","edge"],["network","network"]]);function P4(t,e,n,i){const r=er(Ee(n,"mappings"));for(const o of Object.keys(r)){const l=C4(r[o],i,e);l===null?i?.add(v.BAD_MAPPING,e,o,{sample:r[o]}):t[e].mappings.set(o,l)}const s=er(Ee(n,"dependencies"));for(const o of Object.keys(s))t[e].dependencies.set(o,String(s[o]).toLowerCase()==="true")}function x4(t,e,n){const i=io(),r=a=>Array.isArray(a)?a[0]:a,s=er(r(t)),o=er(Ee(er(r(e)),"properties")),l=er(Ee(s,"default"));for(const a of["network","node","edge"]){const c=er(Ee(l,a));for(const d of Object.keys(c))i[a].defaults.set(d,c[d])}i.node.dependencies.set("nodeSizeLocked",Ee(o,"nodeSizeLocked")===!0),i.edge.dependencies.set("arrowColorMatchesEdge",Ee(o,"arrowColorMatchesEdge")===!0),i.node.dependencies.set("nodeCustomGraphicsSizeSync",Ee(o,"nodeCustomGraphicsSizeSync")!==!1);for(const[a,c]of[["node","nodeMapping"],["edge","edgeMapping"]]){const d=er(Ee(s,c));for(const u of Object.keys(d)){const f=v4(d[u]);f===null?n?.add(v.BAD_MAPPING,a,u,{sample:d[u]}):i[a].mappings.set(u,f)}}M4(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 M4(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 si(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 U4="borderPosition",H1={node:new Map([[U4,"inside"],["borderWaveAmplitude",10],["borderWavePeriod",20],["labelPadding",0],["labelLineHeight",1]]),edge:new Map([["waveAmplitude",10],["wavePeriod",20],["labelPadding",0],["labelLineHeight",1]])},vc={ellipse:"ELLIPSE",rectangle:"RECTANGLE","round-rectangle":"ROUND_RECTANGLE",triangle:"TRIANGLE",diamond:"DIAMOND",hexagon:"HEXAGON",octagon:"OCTAGON",parallelogram:"PARALLELOGRAM",vee:"V"},nw={pentagon:"hexagon",star:"octagon",trapezoid:"parallelogram",none:"ellipse","other:invtrapezium":"parallelogram","other:house":"hexagon","other:invhouse":"hexagon"},iw=t=>Object.fromEntries(Object.entries(t).map(([e,n])=>[e,n==="V"?"vee":n.toLowerCase()])),Cr=(t,e)=>Object.fromEntries(Object.entries(e).map(([n,i])=>[n,t[i]])),cg={solid:"SOLID",dashed:"EQUAL_DASH",dotted:"DOT","dash-dot":"DASH_DOT",double:"PARALLEL_LINES"},rw={...cg,zigzag:"ZIGZAG",sinewave:"SINEWAVE"},Dc={solid:"solid",dashed:"dashed",dotted:"dotted",double:"double"},kc={"dash-dot":"dashed","long-dash":"dashed",zigzag:"solid",sinewave:"solid"},sw={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"},Rc={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"},ow={crow:"vee",inverted:"triangle"},lw={crow:"ARROW",inverted:"DELTA",vee:"ARROW"},Lc=new Set(["open-square","open-half-circle","half-circle","half-bottom"]),dg=new Set(["backward-slash","forward-slash","vertical-slash","separate-arrow","contiguous-arrow"]),aw=new Set([...dg,"zigzag","sinewave"]),ug={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"]},G4=Object.fromEntries(Object.entries(ug).map(([t,[e,n]])=>[t,`${e},${n},c,0.00,0.00`])),cw={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"]},vr=String,oi=t=>t;function Pc(t){return(e,n)=>(typeof e=="number"&&!Number.isInteger(e)&&n(),t(e,n))}const ho=String,vh=t=>String(t===!0),Dh=(t,e)=>{const n=Math.round(Number(t)*255);return x(n/255)!==t&&e(),String(n)},Jy={desktop:{node:new Map([["fill",{vp:"NODE_FILL_COLOR",write:an}],["fillOpacity",{vp:"NODE_TRANSPARENCY",write:Dh}],["borderColor",{vp:"NODE_BORDER_PAINT",write:an}],["borderOpacity",{vp:"NODE_BORDER_TRANSPARENCY",write:Dh}],["borderWidth",{vp:"NODE_BORDER_WIDTH",write:vr}],["borderStyle",{vp:"NODE_BORDER_LINE_TYPE",write:si(cg,Cr(cg,kc),!0,aw)}],["shape",{vp:"NODE_SHAPE",write:si(vc,Cr(vc,nw),!0)}],["width",{vp:"NODE_WIDTH",write:vr}],["height",{vp:"NODE_HEIGHT",write:vr}],["label",{vp:"NODE_LABEL",write:ho}],["labelColor",{vp:"NODE_LABEL_COLOR",write:an}],["labelSize",{vp:"NODE_LABEL_FONT_SIZE",write:Pc(vr)}],["labelWrapWidth",{vp:"NODE_LABEL_WIDTH",write:vr}],["labelPosition",{vp:"NODE_LABEL_POSITION",write:si(G4,{},!1)}],["labelRotation",{vp:"NODE_LABEL_ROTATION",write:vr}],["tooltip",{vp:"NODE_TOOLTIP",write:ho}],["visible",{vp:"NODE_VISIBLE",write:vh}]]),edge:new Map([["color",{vp:"EDGE_STROKE_UNSELECTED_PAINT",write:an}],["opacity",{vp:"EDGE_TRANSPARENCY",write:Dh}],["width",{vp:"EDGE_WIDTH",write:vr}],["lineStyle",{vp:"EDGE_LINE_TYPE",write:si(rw,Cr(rw,kc),!0,dg)}],["sourceArrow",{vp:"EDGE_SOURCE_ARROW_SHAPE",write:si(sw,lw,!0,Lc)}],["targetArrow",{vp:"EDGE_TARGET_ARROW_SHAPE",write:si(sw,lw,!0,Lc)}],["sourceArrowColor",{vp:"EDGE_SOURCE_ARROW_UNSELECTED_PAINT",write:an}],["targetArrowColor",{vp:"EDGE_TARGET_ARROW_UNSELECTED_PAINT",write:an}],["curved",{vp:"EDGE_CURVED",write:vh}],["label",{vp:"EDGE_LABEL",write:ho}],["labelColor",{vp:"EDGE_LABEL_COLOR",write:an}],["labelSize",{vp:"EDGE_LABEL_FONT_SIZE",write:Pc(vr)}],["tooltip",{vp:"EDGE_TOOLTIP",write:ho}],["visible",{vp:"EDGE_VISIBLE",write:vh}]])},cx2:{node:new Map([["fill",{vp:"NODE_BACKGROUND_COLOR",write:an}],["fillOpacity",{vp:"NODE_BACKGROUND_OPACITY",write:oi}],["borderColor",{vp:"NODE_BORDER_COLOR",write:an}],["borderOpacity",{vp:"NODE_BORDER_OPACITY",write:oi}],["borderWidth",{vp:"NODE_BORDER_WIDTH",write:oi}],["borderStyle",{vp:"NODE_BORDER_STYLE",write:si(Dc,Cr(Dc,kc),!1,aw)}],["shape",{vp:"NODE_SHAPE",write:si(iw(vc),Cr(iw(vc),nw),!1)}],["width",{vp:"NODE_WIDTH",write:oi}],["height",{vp:"NODE_HEIGHT",write:oi}],["label",{vp:"NODE_LABEL",write:ho}],["labelColor",{vp:"NODE_LABEL_COLOR",write:an}],["labelSize",{vp:"NODE_LABEL_FONT_SIZE",write:Pc(oi)}],["labelWrapWidth",{vp:"NODE_LABEL_MAX_WIDTH",write:oi}],["labelPosition",{vp:"NODE_LABEL_POSITION",write:j4}],["labelRotation",{vp:"NODE_LABEL_ROTATION",write:oi}],["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:oi}],["width",{vp:"EDGE_WIDTH",write:oi}],["lineStyle",{vp:"EDGE_LINE_STYLE",write:si(Dc,Cr(Dc,kc),!1,dg)}],["sourceArrow",{vp:"EDGE_SOURCE_ARROW_SHAPE",write:si(Rc,Cr(Rc,ow),!1,Lc)}],["targetArrow",{vp:"EDGE_TARGET_ARROW_SHAPE",write:si(Rc,Cr(Rc,ow),!1,Lc)}],["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:ho}],["labelColor",{vp:"EDGE_LABEL_COLOR",write:an}],["labelSize",{vp:"EDGE_LABEL_FONT_SIZE",write:Pc(oi)}],["visible",{vp:"EDGE_VISIBILITY",write:t=>t===!0?"element":"none"}]])}};function j4(t){const[e,n]=Object.hasOwn(ug,String(t))?ug[String(t)]:["C","C"],[i,r]=cw[e],[s,o]=cw[n];return{HORIZONTAL_ALIGN:s,VERTICAL_ALIGN:o,HORIZONTAL_ANCHOR:i,VERTICAL_ANCHOR:r,MARGIN_X:0,MARGIN_Y:0,JUSTIFICATION:"center"}}const Yr=["labelFont","labelWeight","labelItalic"],Y1={node:"NODE_LABEL_FONT_FACE",edge:"EDGE_LABEL_FONT_FACE"},xc={[Os]:"SansSerif",[Vy]:"Serif",[Kl]:"Monospaced"};function fg(t,e,n,i,r){const s=n==="bold",o=i===!0,l=e===null?"sans-serif":String(e);if(t==="cx2")return dw(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(xc,a)?xc[a]:a,d=Object.hasOwn(xc,l)?xc[l]:c;dw(d)!==l&&r();const u=F4(s,o);return`${u==="plain"?d:`${d}.${u}`},${s?"bold":"plain"},12`}function F4(t,e){return!t&&!e?"plain":(t?"bold":"")+(e?"italic":"")}function dw(t){return wf(t.replace(/\.(?:bold|italic|plain|bolditalic)$/i,""))}function z4(t,e){return"style"in e?`graphty.style.${t}.${e.style}`:`graphty.style.${t}.${"computed"in e?e.computed:e.data}`}const V1=new Set(["color","number","text","boolean"]);function K1(t,e,n){const i=n.notes??new re,r=io(),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"])Y4(W4(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 W4(t,e,n,i,r){const s=t==="node"?n.nodeCount:n.edgeCount,o=Ar(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,Si(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 B4=new Map([["labelWrapTrailingSpace",!0],["bendCurve","midpoints"]]);function H4(t,e){const n=B4.get(t);return n!==void 0&&e.every(i=>i===null||i===n)}function Y4(t,e,n,i){const{target:r,notes:s,truth:o}=t,l=Jy[t.options.dialect][r];for(const[f,h]of o){const p=H1[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)&&!Yr.includes(f)&&!H4(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=J4(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)&&V4(t,u,d,f,h,i,c);K4(t,d,l,n),n5(t,d,u,n)}function V4(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=t5(a,t.approx(i)),n.map.set(i,a));const c=Z4(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 K4(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=Si(s,r,o,t.src),d=X4(e.map.get(o),l.vp,ni[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)))):q4(h,d)&&u++}u>0&&t.notes.add(v.APPROXIMATED,r,o,{count:u})}}function X4(t,e,n){const i=t?.kind==="continuous"&&t.step===void 0,r=t?.kind==="passthrough"&&V1.has(n??"");return i||r?U1(e):void 0}function q4(t,e){return e!==void 0&&typeof t=="number"&&x(Math.round(t/e)*e)!==t}function J4(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)||Yr.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||Yr.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 Z4(t,e,n,i,r){const s=Q4(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 e5(t,e,n.by,s,l);if(n.kind==="discrete")return{kind:"discrete",column:s,type:X1(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 Q4(t,e,n){if("data"in e)return e.data;const{target:i}=t,r=(t.options.columnName??z4)(i,e);let s=null;return"style"in e?s=t.extracted.columns[i].get(e.style)??null:"computed"in e&&i==="node"&&(s=ic(t.snapshot,e.computed)),s===null?null:(n.set(r,s),r)}function e5(t,e,n,i,r){const{target:s}=t,o=ni[s].get(e)??"",l=t.src.column(n)??[];if(V1.has(o))return{kind:"passthrough",column:i,type:q1(Array.from(l))};const a="style"in n?u=>uw(u)?u:null:El(s,e),c=new Map;for(let u=0;u<l.length;u++){const f=l[u],h=uw(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:X1(t,n,d.map(([u])=>u)),table:d}}function t5(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 uw(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function X1(t,e,n){const i=q1(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 q1(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 n5(t,e,n,i){const{target:r,truth:s,n:o,approx:l,approxDefault:a}=t,{dialect:c}=t.options;if(!Yr.some(y=>s.has(y)))return;const[d,u,f]=Yr.map(y=>e.set.get(y)??null),h=Y1[r];(d!==null||u!==null||f!==null)&&n.defaults.set(h,fg(c,d,u,f,d===null?l("labelFont"):a("labelFont",d)));const[p,g,m]=Yr.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,fg(c,b??d,_??u,S??f,l("labelFont"))))}}function po(t){return String(t).replaceAll(",",",,")}function i5(t){const e=[`COL=${po(t.column)}`,`T=${t.type??"string"}`];return t.kind==="discrete"?t.table.forEach(([n,i],r)=>{e.push(`K=${r}=${po(n)}`,`V=${r}=${po(i)}`)}):t.kind==="continuous"&&t.points.forEach((n,i)=>{e.push(`L=${i}=${po(n.below)}`,`E=${i}=${po(n.value)}`,`G=${i}=${po(n.above)}`,`OV=${i}=${n.at}`)}),e.join(",")}function sr(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 r5(t){const e=(n,i)=>({properties_of:n,properties:sr(i.defaults,String),dependencies:sr(i.dependencies,String),mappings:sr(i.mappings,r=>({type:r.kind.toUpperCase(),definition:i5(r)}))});return[{properties_of:"network",properties:sr(t.network.defaults,String)},e("nodes:default",t.node),e("edges:default",t.edge)]}function s5(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 o5(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:s5(i.points)}},n=i=>i;return{visualProperties:[{default:{network:sr(t.network.defaults,n),node:sr(t.node.defaults,n),edge:sr(t.edge.defaults,n)},nodeMapping:sr(t.node.mappings,e),edgeMapping:sr(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 l5(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}>`,...a5(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 a5(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 hu(t,e){return[...Jy[e][t].keys(),...Yr,...H1[t].keys(),...t==="node"?["labelWrapTrailingSpace"]:["bendCurve"]]}function Zy(t,e,n,i){const r=new Map;for(const[a,c]of Jy[n][t]){const d=e(a);d!==null&&r.set(c.vp,c.write(d,()=>{i(a)}))}const[s,o,l]=Yr.map(a=>e(a));return(s!==null||o!==null||l!==null)&&r.set(Y1[t],fg(n,s,o,l,()=>{i("labelFont")})),r}const Xl=.9,fw=.4,hw=Array.from({length:9},(t,e)=>`NODE_CUSTOMGRAPHICS_${String(e+1)}`),pw=/^org\.cytoscape\.(PieChart|RingChart|BarChart|LineChart|BoxChart|HeatMapChart)$/;function gw(t){if(typeof t=="object"&&t!==null&&!Array.isArray(t)){const i=t,r=pw.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:pw.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 c5={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 d5(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"?c5[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 u5(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 f5(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=hw.findIndex(u=>gw(n(u,o))!==null),a=l<0?null:gw(n(hw[l],o));if(a===null)continue;const[c,d]=[t.width?.[o],t.height?.[o]];h5(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 J1(t){return t.w!==null&&t.h!==null?Math.min(t.w,t.h):null}function h5(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=u5(s,e.value);if(t.kind==="PieChart"||t.kind==="RingChart"){g5(t.ring,i,o,r,e,n);return}const l=Number(e.graphic("NODE_CUSTOMGRAPHICS_SIZE")),a=J1(e),c=l>0,u=a===null?null:{disc:Xl*(n||!c?a:l),side:a};for(const[f,h]of Object.entries(C5(t.kind,i,o,r,u)))e.put(f,h)}function p5(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 g5(t,e,n,i,r,s){const o=p5(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(x(g.size))).join(" "));const d=Number(r.graphic("NODE_CUSTOMGRAPHICS_SIZE")),u=J1(r),f=d>0,h=s||!f||u===null||u<=0;r.put("pieRadius",h?Xl:x(Xl*d/u)),m5(r,h,d),r.put("pieRotation",x(((90-a)%360+360)%360));const p=E5(e,n,i,r.value,{start:a,radius:Xl*(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??fw);r.put("pieHole",Number.isFinite(g)?Math.max(0,Math.min(1,g)):fw)}}function m5(t,e,n){const i=d5(t.graphic("NODE_CUSTOMGRAPHICS_POSITION")),{w:r,h:s}=t;if(i===null||r===null||s===null)return;const o=Xl*(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",x(l)),t.put("pieOffsetY",x(a)))}const mw=.62,yw=1,y5="#404040";function b5(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 E5(t,e,n,i,r){const s=b5(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??yw),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+mw*r.radius*Math.cos(y),S=-r.dy+mw*r.radius*Math.sin(y);f.push([x(_/(o/2)),x(S/(l/2)),b,{size:x((Number.isFinite(u)&&u>0?u:yw)/l),color:y5}])}),f.length===0?null:JSON.stringify(f)}const hg=.5,w5=.9,_5=1,S5=2,pg={color:"#404040",width:.25},Z1=.025,O5=-.0125,bw=.1;function Ew(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 Q1(t,e,n){const[i,r,s]=[t[0],t[1]??t[0],t[2]??t[0]];return e>=0?Ew(r,i,n[1]>0?e/n[1]:0):Ew(r,s,n[0]<0?e/n[0]:0)}function N5(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 A5(t,e){if(!(e!==null&&e.side>0))return{};const i=w5+(t==="HeatMapChart"?S5:_5);return{chartSize:x(Math.max(0,e.disc-i)/e.side)}}function T5(t){return{chartBorderColor:(typeof t.cy_borderColor=="string"?t.cy_borderColor:pg.color).toLowerCase(),chartBorderWidth:x(hg*(Number(t.cy_borderWidth??pg.width)||0))}}function I5(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)=>$5(s,n,l,a,i)).join(" "),chartMin:i[0],chartMax:i[1],chartHorizontal:o?!r:r,chartMargin:Z1,chartGap:x(Math.max(0,Math.min(1,Number(t.cy_separation??0)||0)))}}function $5(t,e,n,i,r){return t==="HEAT_STRIPS"?Q1(e,n,r):t==="UP_DOWN"?e[n>=0?0:e.length-1].toLowerCase():e[Math.min(i,e.length-1)].toLowerCase()}function C5(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]+=bw*(a[1]-a[0]);const c=l?[o[0],o[1]]:a,d=e.cy_orientation==="HORIZONTAL",u=A5(t,r),f=T5(e);switch(t){case"BarChart":Object.assign(u,f,I5(e,s,i,c,d));break;case"LineChart":Object.assign(u,{chartKind:"line",chartValues:s.join(" "),chartColors:i[0].toLowerCase(),chartMin:c[0],chartMax:x(c[1]+(l?bw*(c[1]-c[0]):0)),chartMargin:O5,chartLineWidth:x(hg*(Number(e.cy_lineWidth??1)||0))});break;case"BoxChart":Object.assign(u,f,{chartKind:"box",chartValues:N5(s).map(x).join(" "),chartColors:`${i[0].toLowerCase()} #000000`,chartMin:c[0],chartMax:c[1],chartHorizontal:d,chartMargin:Z1,chartLineWidth:x(hg*pg.width)});break;case"HeatMapChart":{const h=d?[...s].reverse():s;Object.assign(u,{chartKind:"cells",chartValues:h.join(" "),chartColors:h.map(p=>Q1(i,p,c)).join(" "),chartHorizontal:!d});break}}return u}const eI="EDGE_STACKING_DENSITY",v5="EDGE_STACKING",gg="EDGE_LABEL_AUTOROTATE";function D5(t,e){return new Map([...t].filter(([n])=>n!==e))}const tI=.5;function Sf(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 k5=50,nI=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 R5(t,e){for(let n=e;n!==void 0;n=nI.get(n)){const i=t.get(n);if(i!=null)return i}}function iI(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 nI)n.has(s)&&n.add(r);return{used:new Set([...t.defaults.keys(),...t.mappings.keys(),...n]),bypassed:n}}function rI(t,e,n){const i=new Map;for(const[r,s]of Xy[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",xo]),i.delete("sourceArrowColor"),i.delete("targetArrowColor")),i}function sI(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=U1(i),s=L5(t.points,e,n);return{kind:"continuous",column:t.column,points:s,...r===void 0?{}:{step:r}}}}}function L5(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 P5(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=p1(t.table)(e);return r<0?null:t.table[r][1]}default:return yf(t.points,rc(e),t.step)}}function ww(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 R5(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=sI(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:P5(b,n.value(b.column,p),f,g);return _!==null?_:e.defaults.has(u)?f(e.defaults.get(u),l(h)):null}}}function Qy(t,e,n,i={}){const r=i.notes??new re,s=e[t],o=n.count,{used:l,bypassed:a}=iI(s,n.bypasses??[]),c=rI(t,s,l),{one:d,bypass:u}=ww(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(qo,Xr,"width").map(m=>m??k5),g=(m,y)=>p.map((b,_)=>{const S=u(_,m);return(S==null?null:Xr(S,{notes:r,target:t,property:y,element:_}))??b});f.width=g("NODE_WIDTH","width"),f.height=g("NODE_HEIGHT","height")}if(x5(t,f,d,o,n.ends),t==="node"){W5(f);const p=g=>typeof g=="string"||typeof g=="number"?String(g):typeof g=="object"&&g!==null?JSON.stringify(g):null;f5(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=Tr("cytoscape-fallbacks")?.edge.color?.value??null;f.color=Array.from({length:o},(g,m)=>d("EDGE_UNSELECTED_PAINT",xo,"color",m)??p)}if(t==="edge"&&s.dependencies.get("arrowColorMatchesEdge")===!0&&f.color!==void 0){const p=c.get("color")?.[0],g=ww(t,s,{...n,bypasses:[]},r,i.budget).one,m=p==="EDGE_LINE_COLOR"?Array.from({length:o},(b,_)=>g(p,xo,"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,I)=>{const T=u(I,_),D={notes:r,target:t,property:b,element:I};return(T==null?null:xo(T,D))??S})}if(Z5(t,s,l,a,r),t==="edge"){const p=h(eb,q5,"bends");p.some(m=>m!==null)&&(f.bends=p);const g=f.curved?.slice();H5(f,d,o,n.ends),X5(f,d,g,n.ends),B5(f,h)}return oI(t,f,o,i.defaults??null),f}const Of=t=>typeof t=="string"||typeof t=="number"||typeof t=="boolean"?String(t):typeof t=="object"&&t!==null?JSON.stringify(t):null;function x5(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++){M5(s,n,c,l);const d=n(s("POSITION"),Of,"labelPlace",c),u=typeof d=="string"&&d.startsWith("{")?JSON.parse(d):d,f=x1(u,{notes:new re,target:t,property:"labelPosition"});f!==null&&G5(t,f,c,e,l,r),t==="edge"&&j5(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 M5(t,e,n,i){const r=e(t("BACKGROUND_SHAPE"),Of,"labelBackgroundShape",n);if(typeof r!="string"||r.trim().toUpperCase()==="NONE")return;i("labelBackground",n,e(t("BACKGROUND_COLOR"),xo,"labelBackground",n)??"#b6b6b6");const[s,o]=[t("BACKGROUND_TRANSPARENCY"),t("BACKGROUND_OPACITY")],l=e(s,QE(s),"labelBackgroundOpacity",n)??e(o,QE(o),"labelBackgroundOpacity",n);if(i("labelBackgroundOpacity",n,l??1),r.trim().toUpperCase().replace("-","_")==="ROUND_RECTANGLE"){const a=e(t("FONT_SIZE"),Xr,"labelSize",n),c=t("FONT_SIZE").startsWith("EDGE")?10:12;i("labelCornerRadius",n,x(U5*(typeof a=="number"?a:c)))}}const U5=.1455;function G5(t,e,n,i,r,s){let o;if(t==="node"){const[l,a]=[i.width?.[n],i.height?.[n]];o=a4(e,typeof l=="number"?l:0,typeof a=="number"?a:0),r("labelPosition",n,Ky(e))}else{const[l,a]=F5(s,n,e.node[0]);o={offset:[l+e.offset[0],a+e.offset[1]],shift:[du(e.label[0]),du(e.label[1])]},r("labelPosition",n,"center")}r("labelOffsetX",n,x(o.offset[0])),r("labelOffsetY",n,x(o.offset[1])),r("labelShiftX",n,o.shift[0]),r("labelShiftY",n,o.shift[1]),r("labelTextAlign",n,e.justify)}function j5(t,e,n,i,r){const s=t(gg,Of,"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]=x(((u+(typeof h=="number"?h:0))%360+360)%360)}function F5(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 z5=Math.sqrt(3)/2;function W5(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)*z5+l})}function B5(t,e){const n=t.arrowSize,i=e("EDGE_SOURCE_ARROW_SIZE",sg,"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,JU(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,ZU,r).map(l=>l===0?null:l);o.some(l=>l!==null)&&(t[r]=o)}}function H5(t,e,n,i){const r=t.curved??new Array(n).fill(null),s=p=>e(eb,tb,"curved",p)===!0,o=p=>String(e(v5,Of,"fanned",p)??"").toUpperCase()==="HAYSTACK",l=i===void 0?new Map:Y5(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(eI,Xr,"fanSpacing",g),b=Math.min(1,typeof y=="number"?y:tI);return m*b}),K5(t,i,l)}function Y5(t,e,n,i){const r=new Map,s=new Map;for(const o of V5(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 V5(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 K5(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,I]=[_*(m[0]-g[0])/b,_*(m[1]-g[1])/b],T=Math.ceil(f/2)*(f%2===0?1:-1)*2*y,[D,P]=[T*I,-T*S],k=(D*(m[1]-g[1])-P*(m[0]-g[0]))/(b*b);a[u]=`0.5,${String(Math.round(k*1e6)/1e6||0)}`,c[u]="bezier",l[u]=null,d=!0}d&&(t.bends=a,t.bendCurve=c,t.fanSpacing=l)}function X5(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(eI,Xr,"fanSpacing",d),g=Math.min(1,typeof p=="number"?p:tI),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 eb="EDGE_BEND",tb=t=>{if(typeof t=="string"){const e=t.trim();return e!==""&&e!=='""'}return Array.isArray(t)?t.length>0:t!=null&&typeof t=="object"},q5=(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"||!tb(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 B(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(" ")},J5=/NullCustomGraphics|^255$|^0(?:\.0+)?$|^$|^C,C,c,0\.00,0\.00$|^false$/;function Z5(t,e,n,i,r){for(const s of n){if(!f4(s))continue;const o=e.defaults.get(s),l=typeof o=="string"||typeof o=="number"||typeof o=="boolean"?String(o):"";J5.test(l.slice(0,64))&&!e.mappings.has(s)&&!i.has(s)||r.add(v.NOT_CARRIED,t,s,{sample:l})}}function oI(t,e,n,i){const r=i===null?null:Tr(i);if(r!==null)for(const[s,o]of Object.entries(r[t])){if(o===void 0||!Xo(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 lI(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=xo(i,{notes:e??new re,target:"graph",property:"background"});return typeof r=="string"?r:null}function aI(t,e,n={}){const i=n.notes??new re,r=io(),s={count:e.length,value:n.value??(()=>null),bypasses:e.map(l=>l?.has(gg)===!0?D5(l,gg):l),ends:n.ends},o=Qy(t,r,s,{notes:i,budget:n.budget});if(t==="node"&&o.width===void 0){const l=e.map(a=>{const c=a?.get(qo);return c===void 0?null:Xr(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 oI(t,o,e.length,n.defaults??null),o}function cI(t,e,n,i={}){const r=i.notes??new re,s=i.columnRef??(b=>({data:b})),o=e[t],{used:l}=iI(o,n.bypasses??[]),a=rI(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=Q5(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 I=o.mappings.get(_);if(I===void 0)return;const T=sI(I,S,c(b[0]),_),D=eG(T,b[0],S,g),P=`${I.kind}\0${I.column}`;let k=p.get(P);k===void 0&&(k={id:`${t}.${I.kind}.${I.column}`,map:{}},p.set(P,k));for(const U of b)k.map[U]=D};for(const[b,[_,S]]of a)m(u&&b==="color"?["color","sourceArrowColor","targetArrowColor"]:[b],_,S);d&&m(["width","height"],qo,Xr);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 Q5(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(qo)?Xr(t.defaults.get(qo),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&&tb(t.defaults.get(eb),n("curved"))!==!0&&(r.curved=!1),r}function eG(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?tG:El(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 tG(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:null}const Ht="xgmml",nG=Object.freeze([".xgmml",".xml"]),iG=Object.freeze(["application/xgmml","text/xgmml","text/xgmml+xml"]),wa="http://www.cs.rpi.edu/XGMML",dI="http://www.cytoscape.org",nb="http://www.w3.org/1999/xlink",uI="xgmml",Bs="label",Jo="id",Nl="position",ro="z",Qt="graphics",lc="parent",Nf="parents",Hs="xgmml.subgraph",ac="cytoscape.nestedNetwork",Zo="xgmml.networkPointer",_a="xgmml.networks",ql="interaction",hn="xgmml",Af="cytoscape",j=Object.freeze({...xn,...Pn,XML_SYNTAX:Vu,XML_NESTING:Ku,EMPTY_INPUT:Mt,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,ENCODING_CONFLICT:ul,NO_GRAPH:rs,VIEW_DOCUMENT:"E_XGMML_VIEW_DOCUMENT",MISSING_ID:at,ID_FROM_LABEL:"W_XGMML_ID_FROM_LABEL",ID_AND_HREF:"W_XGMML_ID_AND_HREF",MISSING_ENDPOINT:Jn,UNKNOWN_NODE:"E_UNKNOWN_NODE",LABEL_ALIAS:"W_XGMML_LABEL_ALIAS",DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Oi,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:ne,WIDENED:ua,PRECISION:ie,DANGLING_REFERENCE:Ki,DUPLICATE_ATTRIBUTE:de,UNKNOWN_PARENT:Mi,PARENT_CYCLE:fl,EQUATION_AS_TEXT:PL,UNKNOWN_ATTR_TYPE:Zt,UNKNOWN_ELEMENT:$t,STRAY_TEXT:Xu,MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,COLUMN_RENAMED:ln,ROLE_TAKEN:yn,ID_MERGED:Rn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er}),dn=Object.freeze({JSON_AS_STRING:"W_XGMML_JSON_AS_STRING",WIDENED_TYPE:"W_XGMML_WIDENED_TYPE",XML_ILLEGAL_CHAR:Hd,TEMPORAL_DROPPED:mA,TEMPORAL_TEXT_DROPPED:wA,ROLE_DROPPED:iy,PARENTS_DROPPED:ry,MUTUAL_EXPANDED:yA,ID_TEXT_TYPE:os,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:SA,ROLE_ASSUMED:Ja,WEIGHT_KEY_CLASH:_A,STORAGE_CLASS_CHANGED:OA,INTERACTION_FROM_LABEL:"W_XGMML_INTERACTION_FROM_LABEL"});function fI(t){for(const e of t){const{origin:n}=e.meta;if(e.dtype==="json"&&n?.type==="graphics"&&n.namespace===hn)return e.meta.name}return t.get(Qt)?.dtype==="json"?Qt:null}function hI(t,e,n,i){const r=new Array(n).fill(null),s=fI(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=lg(e,l,i),c=Object.hasOwn(l,"lockedVisualProperties")?l.lockedVisualProperties:void 0;if(c!==null&&typeof c=="object")for(const[d,u]of lg(e,c,i))a.set(d,u);r[o]=a.size>0?a:null}return r}function pI(t,e,n){const i=new re,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=hI(o,s,l,i),c=a.some(d=>d!==null)?aI(s,a,{notes:i,budget:e.budget,value:(d,u)=>o.has(d)?K(o.value(d,u)):null,...s==="edge"?{ends:Sf(t,r.node.values)}:{}}):{};rG(t,s,r.node.values,c,n),ib(t,s,c),r[s]={values:rb(c)}}return{canonical:!0,dialect:"cytoscape",tool:n.tool,units:"px",node:r.node,edge:r.edge,graph:yI(t,i),notes:i.list()}}function rG(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&&sG(t,i),gI(s,r.hiddenColumn??null,o,i),mI(t,e,n,i),e==="node"&&l&&i.label===void 0&&!t.graph.has(Z)&&oG(s,o,i)}function sG(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 Ol(c,d,Array.from({length:u},()=>[0,0]),!1)??l})}function oG(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 lG(t,e){return pI(t,e,{tool:"cytoscape"})}function ib(t,e,n,i="desktop",r){const s=t.graph.has(Z)?K(t.graph.value(Z,0)):null;typeof s=="string"&&no(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)=>Zy(e,p=>l(e,p)[h]??null,i,()=>{})),d=e==="edge"?{ends:{...Sf(t,{width:l("node","width"),height:l("node","height"),borderWidth:l("node","borderWidth")}),...r===void 0?{}:{created:r}}}:{},u=aI(e,c,{notes:new re,...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||aG.has(f)}})}const aG=new Set(["fanSpacing","curved","bends","bendCurve","labelOffsetX","labelOffsetY","labelShiftX","labelShiftY"]);function gI(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 cG(t,e){const n=t.nodes.byRole("parent");if(n===null||t.graph.has(Z))return;const i=t.nodeCount,r=uG(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(!hG(t,l,s)){o[l]=!1;continue}for(const c of fG(l,a,r))o[c]=!1}e.visible=o}function mI(t,e,n,i){e==="node"?cG(t,i):dG(t,n,i)}function dG(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 uG(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 fG(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 hG(t,e,n){if(typeof n!="string"||!t.nodes.has(Hs))return!1;const i=K(t.nodes.value(Hs,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 rb(t){const e={};for(const[n,i]of Object.entries(t))i?.some(r=>r!==null)===!0&&(e[n]=i);return e}function yI(t,e,n){const i=io();for(const[s,o]of n?.network.defaults??[])i.network.defaults.set(s,o);for(const[s,o]of pG(t,e))i.network.defaults.set(s,o);const r=lI(i,e);return r===null?{}:{background:r}}function pG(t,e){const n=fI(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=>[...lg("node",s,e)].filter(([o])=>o.startsWith("NETWORK_")))}const bI=Object.freeze({tool:"cytoscape",node:Object.freeze(hu("node","desktop")),edge:Object.freeze(hu("edge","desktop")),graph:Object.freeze(["background"]),block:"attributes"}),gG={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 EI(t,e,n,i){const r=Zy(t,o=>e.picture(t,o)[n]??null,"desktop",()=>{}),s={};for(const[o,l]of gG[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 mG(t,e){const n=new re;for(const i of["node","edge"]){const r=i==="node"?e.nodeCount:e.edgeCount;for(let s=0;s<r;s++)Zy(i,o=>t.picture(i,o)[s]??null,"desktop",o=>{n.add(v.APPROXIMATED,i,o,{element:s})})}return n.list().map(ob)}function yG(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 wI(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 _I(t){return[{block:t}]}function sb(t){const e=t.graph.get(Z),n=e?.isSet(0)?e.value(0):null;return typeof n=="string"?n:null}function bG(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 EG(t,e,n,i){const{notes:r}=i;F1(t[e],s=>n.has(s)),e==="edge"&&z1(t.edge,i.weightFrom,n),i.dialect!=="cx2"&&W1(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 wG(t,e){if(e===null||t.edges.has(e)||t.edges.byRole("weight")!==null)return null;const n=wt(t);return n.weighted?n:null}function _w(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 _G(t){const e=t.edges.byRole("id");if(e===null)return null;const n=_w(Array.from({length:t.nodeCount},(r,s)=>t.ids.idOf(s))),i=_w(Array.from({length:t.edgeCount},(r,s)=>e.value(s)));return n===null||i===null?null:{node:n,edge:i}}function SI(t,e,n,i,r,s="desktop",o={}){const l=o.weightFrom??null,a=o.hashOrder===!0?_G(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"?wG(t,l):null;EG(n,f,h,{notes:r,dialect:s,weightFrom:l,weights:g});const{maps:m,names:y}=bG(h,p,i);d[f]=y;const b={count:p,value:(T,D)=>g!==null&&T===l?g.isExplicit(D)?g.value(D):null:h.has(T)?K(h.value(T,D)):null,bypasses:m,...f==="edge"?{ends:{...Sf(t,c.node.values),...a===void 0?{}:{created:a}}}:{}},_=Qy(f,n,b,{notes:r,budget:e.budget});ib(t,f,_,s,a);const{rules:S,columns:I}=cI(f,n,b,{notes:r,budget:e.budget});c[f]={values:rb(_),rules:S,columns:I}}const u=lI(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 SG(t,e){const n=new re,i=e.kept,r=R4(i?.entries??[],n),s=i?.otherViews??0;return s>0&&n.add(v.OTHER_VIEWS,null,"cyVisualProperties",{sample:`${s} more`,count:s}),SI(t,e,r,"cx.bypass",n,"desktop",{weightFrom:i?.weightFrom??null,hashOrder:i?.collection!==!0})}function OI(t){return Object.freeze({tool:"cytoscape",node:Object.freeze(hu("node",t)),edge:Object.freeze(hu("edge",t)),graph:Object.freeze(["background"]),block:"attributes"})}const OG=OI("desktop");function NG(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 ob(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 Tf(t,e,n){if(e===void 0)return null;const i=new re,r=K1(e.rules,t,{dialect:n,notes:i});return{snapshot:AG(t,r),styled:r,notes:i.list().map(ob)}}function AG(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=NG(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 TG=OI("cx2");function IG(t,e){const n=new re,i=e.kept,r=x4(i?.visualProperties,i?.visualEditorProperties,n);return SI(t,e,r,"cx2.bypass",n,"cx2",{weightFrom:i?.weightFrom??null})}const Bt="cx2",vt="graphty:originalId",NI="cx2.bypass",ge=Object.freeze({...xn,...Pn,EMPTY_INPUT:Mt,SYNTAX:kn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,NO_DESCRIPTOR:"E_CX2_NO_DESCRIPTOR",VERSION:"E_CX2_VERSION",MINOR_VERSION:"W_CX2_MINOR_VERSION",NO_STATUS:"E_CX2_NO_STATUS",STATUS_FAILED:Bd,STATUS_WARNING:ty,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:gA,MULTI_ASPECT_FRAGMENT:ey,JSON_NONSTANDARD_NUMBER:qu,STYLES_NOT_IMPORTED:Zs,BAD_ASPECT_BLOCK:pt,ASPECT_ORDER:Bn,COUNT_MISMATCH:Us,BAD_VALUE:ne,BAD_DEFAULT:Wo,UNKNOWN_ATTR_TYPE:Zt,DANGLING_REFERENCE:Ki,DUPLICATE_ATTRIBUTE:de,MISSING_ID:at,MISSING_ENDPOINT:Jn,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Oi,INVALID_ID:"E_INVALID_ID",UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",ID_TEXT_TYPE:os,PRECISION:ie,ID_MERGED:Rn,UNKNOWN_ELEMENT:$t,COLUMN_RENAMED:ln,ROLE_TAKEN:yn,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,TOO_LARGE:hl}),$G=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]),CG={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},AI=64,vG=new Set(["id","x","y","z","v"]),DG=new Set(["id","s","t","v"]),kG=["networkAttributes","visualProperties","visualEditorProperties"],Sw=["visualProperties","visualEditorProperties","cyVisualProperties","tableVisualProperties","cyTableVisualProperties"],TI=new Set(["metaData","status"]),RG=new Set(["nodes","edges","attributeDeclarations","networkAttributes","nodeBypasses","edgeBypasses","status","metaData"]),LG=new Map([["string","string"],["long","long"],["integer","integer"],["double","double"],["boolean","boolean"],["str","string"],["int","integer"],["bool","boolean"],["float","double"]]);function pu(t){const e=t.startsWith("list_of_"),n=LG.get(e?t.slice(8):t);return n===void 0?null:{d:e?`list_of_${n}`:n,scalar:n,list:e}}function Ow(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 It=Symbol("bad"),II=-2147483648,$I=2147483647;function Nw(t,e,n,i){switch(e){case"string":return typeof t=="string"?t:It;case"boolean":return typeof t=="boolean"?t:It;case"double":return t instanceof vn?(i(t.digits),Number(t.digits)):typeof t=="number"?t:It;case"integer":return typeof t=="number"&&Number.isInteger(t)&&t>=II&&t<=$I?t:It;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:It;default:return It}}function Mc(t,e,n,i){if(!e.list)return Nw(t,e.scalar,n,i);if(!Array.isArray(t))return It;const r=[];for(const s of t){const o=s===null?It:Nw(s,e.scalar,n,i);if(o===It)return It;r.push(o)}return r}function _e(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 Aw(t,e,n=1){if(!/\d[.eE]/.test(t))return 0;let i=0;return e.forEach((r,s)=>{i1(t,r,n)&&(i|=1<<s)}),i}async function PG(t,e,n){const i=new o1(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=t1(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:Aw(f,["id"],g)});return;case"edges":o=!0,r.edges.push({value:u,line:h,inexact:Aw(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(TI.has(d))return;r.opaque.has(d)||r.opaque.set(d,[]),r.opaque.get(d)?.push(p?Ke(u,a):u)}};try{for await(const d of QT(Nr(t,e,n),e))switch(++l>=AI&&(l=0,F(n.signal)),d.kind){case"root":e.fail(ge.NO_DESCRIPTOR,`a CX2 document is a JSON array; found ${d.object?"an object":_e(d.value)}`,{line:d.line});break;case"member":if(!s){Tw(d.value,d.line,r,e),s=!0;break}MG(d.value,d.line,i,e,(u,f)=>{c(u,f,d.text,d.line,d.exact,2)});break;case"block":n1(e,d),s||e.fail(ge.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":e1(e,d),s||Tw(null,d.line,r,e);break;case"extraKeys":e.error("parse-error",pt,`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 Ze&&e.fail(d.empty?Mt:kn,d.message,{line:d.line}),d}return s||e.fail(ge.NO_DESCRIPTOR,"the document is an empty array; a CX2 document starts with a descriptor"),r}function xG(t,e,n){const i=M(t)?Object.keys(t):[],r=i.length>0?` (keys: ${i.join(", ")})`:"";return n.fail(ge.NO_DESCRIPTOR,`the first member of the array is not a descriptor with CXVersion${r}`,{line:e})}function Tw(t,e,n,i){(!M(t)||!("CXVersion"in t))&&xG(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(ge.VERSION,`CXVersion ${_e(r)} is CX version 1, a different document shape; read it with the cx importer`,{line:e,element:"CXVersion"}),l!==2&&i.fail(ge.VERSION,`CXVersion ${_e(r)} is not a CX2 version`,{line:e,element:"CXVersion"}),n.version=s,r!=="2.0"&&i.warning("validation-error",ge.MINOR_VERSION,`CXVersion ${_e(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",ne,`hasFragments is ${_e(t.hasFragments)}, not a boolean; read as false`,{line:e,element:"hasFragments"}):a!=="CXVersion"&&i.warning("validation-error",$t,`the descriptor key "${a}" is not defined`,{line:e,element:a})}function MG(t,e,n,i,r){const s=M(t)?Object.keys(t):[];if(M(t)&&s.length===1&&M(t[s[0]])){RG.has(s[0])&&i.warning("validation-error",ge.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(", ")})`:_e(t);i.error("parse-error",pt,`a member of the document is ${o}, not a one-key aspect block; skipped`,{line:e,element:s[0]??null})}function Iw(t){switch(typeof t){case"boolean":return"boolean";case"string":return"string";case"number":return Number.isInteger(t)&&t>=II&&t<=$I?"integer":"double";default:return t instanceof vn?"double":null}}function $w(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 Cw(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=$w(t.kind,Iw(e));return}for(const i of e)t.kind=$w(t.kind,i===null||Array.isArray(i)?null:Iw(i))}function vw(t){if(t.kind===null)return null;const e=t.kind??"string";return pu(t.list===!0?`list_of_${e}`:e)}class kh{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 UG=new Map([["nodes","node"],["edges","edge"],["networkAttributes","network"]]);function Rh(t,e){return Object.hasOwn(t,e)}class GG{constructor(e,n,i,r,s){this.decls={node:new kh,edge:new kh,network:new kh,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 Qn(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",ge.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",Ki,`${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",pt,"an attributeDeclarations element is not an object",{line:n.line,element:"attributeDeclarations"});continue}for(const[i,r]of Object.entries(n.value)){const s=UG.get(i);if(s===void 0){e.warning("unsupported",$t,`attributeDeclarations holds the table "${i}", which CX2 does not define; kept in meta.extra.cx2.declarations, not applied`,{line:n.line,element:i}),xy(this.decls.other,i,Ke(r,o=>{this.precision(i,o)}));continue}if(!M(r)){e.error("validation-error",ne,`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)),Cw(d,l)}for(const[s,o]of r){const l=vw(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!==It);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",ne,`a ${e} attribute declaration has an empty name; ignored`,l);return}if(!M(i)){s.error("validation-error",ne,`the declaration of "${n}" is not an object; ignored`,l);return}let a;i.d===void 0?(a=pu("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"?pu(i.d):null,a===null&&s.warning("unsupported",Zt,`the type ${_e(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",ge.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",ne,`the alias ${_e(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",ge.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!==It),o.byName.set(n,{name:n,type:a,alias:d,hasDefault:u,defaultValue:f,rawDefault:u&&a===null?Ke(i.v):void 0,handle:A,undeclared:!1})}convertDefault(e,n,i,r){const s=Mc(n,i,this.options.long,l=>{this.precision(e,l)});if(s!==It)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=Mc(Number(n),i,this.options.long,()=>{});if(l!==It)return this.report.warning("validation-error",Wo,`the default ${_e(n)} of "${e}" is a string, not a ${i.d}; read as ${_e(l)}`,r),l}return this.report.warning("validation-error",Wo,`the default ${_e(n)} of "${e}" is not a ${i.d}; the column has no default`,r),It}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",ge.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===vt||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=fe(this.sink,n,r,this.report).handle}}edgeIdColumn(){if(this.edgeIdHandle===A){const e=n=>this.sink.edgeColumn(n)!==A;this.edgeIdHandle=fe(this.sink,"edge",{name:Xt("id","cx2",e),dtype:"f64",role:"id",nullable:!0},this.report).handle}return this.edgeIdHandle}columnDecl(e){const n=Ow(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=ou(e,n);l.note==="text"?this.report.warnOnce("coercion",os,`${i}: the id ${_e(e)} is not written as an integer; read as ${String(l.id)}`,{line:r,element:i}):l.note==="precision"&&s?this.report.warnOnce("precision",ie,`${i}: the edge id ${String(l.id)} is beyond 2^53; the id column holds the nearest double`,{line:r,element:i},`${ie}:edge`):l.note==="precision"&&(this.idType="mixed",this.report.warnOnce("precision",ie,`${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>=AI&&(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",$t,`the ${i} key "${s}" is not defined by CX2; its values are not read`,{line:r,element:s},`${$t}:${i}:${s}`)}readNode(e){this.checkAbort();const{report:n,sink:i}=this,{value:r,line:s}=e;if(!M(r)){n.error("parse-error",pt,`a nodes element is ${_e(r)}, not an object`,{line:s,element:"nodes"}),n.counts.skippedNodes++;return}if(this.unknownKeys(r,vG,"node",s),r.id===void 0||r.id===null){n.error("missing-value",at,"a node has no id",{line:s,element:"nodes"}),n.counts.skippedNodes++;return}const o=`node ${_e(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",ne,`${o}: v is ${_e(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 ${_e(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(vt)?.alias??null,s=e[vt]??(r===null?void 0:e[r]);return s!=null&&typeof s!="string"&&this.report.error("validation-error",ne,`${n}: ${vt} is ${_e(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",ne,`${i}: ${c} is ${_e(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",ge.PARTIAL_LAYOUT,`${i} has ${o===null?"y without x":"x without y"}; its coordinates are dropped`,{line:r,element:i},`${ge.PARTIAL_LAYOUT}:half`),a!==null&&o===null&&l===null&&this.report.warnOnce("missing-value",ge.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},`${ge.PARTIAL_LAYOUT}:z`),o!==null&&l!==null&&(!Number.isFinite(o)||!Number.isFinite(l))?this.report.error("validation-error",ne,`${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=fe(this.sink,"node",Jp(Bt),this.report).handle),this.sink.setNodeValue(this.zHandle,n,a))}setPosition(e,n,i,r){this.positionHandle===A&&(this.positionHandle=fe(this.sink,"node",r1(Bt,this.zAs==="position"?3:2),this.report).handle),this.point[0]=n,this.point[1]=zo(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=>Ke(r.value))),this.report.warning("unsupported",ge.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",ne,"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=>Ke(a.value))),this.report.warnOnce("validation-error",de,`the cartesianLayout aspect names several views; view ${_e(n)} is read, the aspect is kept in meta.extra.cx2`,{line:r.line,element:"cartesianLayout"},`${de}:layout:view`);continue}i.has(o)&&this.report.warnOnce("validation-error",de,`node ${_e(s.node)} has two cartesianLayout entries; the later wins`,{line:r.line,element:"cartesianLayout"},`${de}: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=fe(this.sink,"node",Jp(Bt),this.report).handle),this.sink.setNodeValue(this.zHandle,o,l))}}rowOf(e,n){try{const{id:i}=ou(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",ne,`${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===vt||e==="edge"&&u===this.options.weightFrom)continue;if(a==="id"&&o.warnOnce("validation-error",ge.RESERVED_KEY,`${r}: the attribute name "id" is reserved in v; read as an ordinary attribute`,{line:s,element:r},`${ge.RESERVED_KEY}:${e}`),d!==null&&!d.viaAlias&&d.decl.alias!==null&&d.decl.alias!==a){if(Rh(i,d.decl.alias)){o.warning("validation-error",de,`${r}: "${u}" is given under its alias and its full name; the alias wins`,{line:s,element:r});continue}o.warnOnce("coercion",ge.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},`${ge.ALIAS_BYPASSED}:${e}:${u}`)}if(c==null||d===null)continue;const{decl:f}=d;f.undeclared&&o.warnOnce("validation-error",ge.UNDECLARED_ATTRIBUTE,`the ${e} attribute "${a}" is not declared; its type is inferred from the values`,{line:s,element:a},`${ge.UNDECLARED_ATTRIBUTE}:${e}:${a}`);const h=f.type===null?Ke(c,p=>{this.precision(u,p)}):Mc(c,f.type,this.options.long,p=>{this.precision(u,p)});if(h===It){o.error("validation-error",ne,`${r}: "${u}" is ${_e(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",ie,`"${e}": ${n} is beyond 2^53; stored as the nearest double`,{element:e},`${ie}:value`)}readEdge(e){this.checkAbort();const{report:n,sink:i}=this,{value:r,line:s}=e;if(!M(r)){n.error("parse-error",pt,`an edges element is ${_e(r)}, not an object`,{line:s,element:"edges"}),n.counts.skippedEdges++;return}if(this.unknownKeys(r,DG,"edge",s),r.id===void 0||r.id===null){n.error("missing-value",at,"an edge has no id",{line:s,element:"edges"}),n.counts.skippedEdges++;return}const o=`edge ${_e(r.id)}`;for(const y of["s","t"])if(r[y]===void 0||r[y]===null){n.error("missing-value",Jn,`${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",Oi,`${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",ne,`${o}: v is ${_e(r.v)}, not an object`,{line:s,element:o});let h;const p=this.weightKey(f);try{h=p===null||f===null?void 0:sf(Ke(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&&Rh(e,i)?i:Rh(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",ge.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",ge.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",pt,"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",ge.UNDECLARED_ATTRIBUTE,`the network attribute "${r}" is not declared; its column is inferred from the value`,{line:i,element:r},`${ge.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};Cw(a,s);const c=o?.type??vw(a);if(c===null){this.sink.setGraphValue(r,Ke(s,f=>{this.precision(r,f)}),{dtype:"json",origin:{format:Bt,id:null}});continue}const d=Mc(s,c,this.options.long,f=>{this.precision(r,f)});if(d===It){this.report.error("validation-error",ne,`${l} is ${_e(s)}, not a ${c.d}; unset`,{line:i,element:l});continue}const u=Ow(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",pt,`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",ne,`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=Ke(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",de,`a ${e} has the visual property "${c}" in two ${e}Bypasses elements; the later wins`,{line:l,element:c},`${de}:bypass:${e}:${c}`),u.values[h]=f}}for(const[s,{rows:o,values:l}]of r){const a={name:s,dtype:jG(l),nullable:!0,origin:{format:Bt,id:s,namespace:NI}},c=l1(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 Sw){const o=e.opaque.get(s);o!==void 0&&r.push(FG(s,o))}r.length>0&&n.warning("unsupported",Zs,`the file's style rules are not applied (${r.join("; ")}); they are kept in meta.extra.cx2.opaque`,{element:Sw.filter(s=>e.opaque.has(s)).join(",")});for(const s of kG.slice(1)){const o=e.opaque.get(s)?.length??0;o>1&&n.warning("validation-error",ge.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&&!TI.has(s)&&n.warnOnce("validation-error",ge.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",ge.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?_e(n.status):`${i} elements`;e.error("validation-error",ge.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 jG(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 FG(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 CI(t){if(t===void 0)return"column";if(t==="column"||t==="position")return t;throw new N("E_UNSUPPORTED",`option zAs: ${_e(t)} is not one of "column", "position"`,{option:"zAs",found:typeof t=="string"?t:typeof t})}const zG=Object.freeze({format:Bt,options:Object.freeze(["zAs"]),extensions:Object.freeze([".cx2"]),mimeTypes:Object.freeze(["application/json"]),styles:IG,sniff(t){const e=s1(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=Qe(n,CG),r=CI(n?.zAs),s=new te(Bt,i.errorLimit);bt(e,n,s,!0),Et(n,s,$G);const o=await PG(t,s,i),l=wI(o.opaque.get(Z));o.opaque.delete(Z),new GG(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()}}),lb="cx",vI=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}),DI=Xe({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}),WG=new Set(["label","position","id"]),Dw=Object.freeze({label:"name",position:My,id:"id",parent:"parent"}),mg=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness","id"]),BG="cx.bypass",kI=Object.freeze({"cx:citations":"citations","cx:supports":"supports"}),HG=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]),tr="weight",YG=new Set(["f32","f64","i32","u32","u8"]);function Ed(t,e){return t.meta.origin?.format===lb&&t.meta.origin.namespace===e}function Oo(t){return t.meta.origin?.namespace===BG}function VG(t){return t.meta.extra.cytoscape==="z"}function RI(t){return Ed(t,"provenance")&&t.meta.dtype==="list"&&(t.meta.name==="citations"||t.meta.name==="supports")}function KG(t){const{dtype:e}=t.meta;return e!=="string"&&e!=="dict"&&e!=="json"}function XG(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,DI,e,{roles:WG,roleNames:n?{...Dw,parents:"parents"}:Dw}))if(!qG(c,a)){if(c.code===w.JSON){const d=c.column===null?"a column":`column "${c.column}"`;s(vI.JSON_AS_STRING,`${d} holds nested values; written as a string attribute holding their JSON text`,c.column,c.count);continue}if(JG(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 qG(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 kI}function JG(t,e){return t.code===w.COLUMN_NAME_CHANGED&&t.column===e&&t.message.startsWith("edge column")}function ZG(t,e){const n=t.nodes.byRole("position"),i=[...t.nodes].find(VG)??null,r=i!==null&&i8(i,n)?i:null;if(n===null)return{position:n,z:r,positionZ:!1,nonfinite:0};let s=Ph(n,a=>[a[0],a[1]]);const o=Ph(n,a=>a[2]===0?[]:[Number.NaN]),l=i===null&&(n.meta.extra.sourceDims===3||o>0);return l&&(s+=Ph(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 QG(t,e){for(const n of t.graph){const i=n.meta.name==="name"||n.meta.name==="description";!Oo(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 LI(t,e){const{notes:n,note:i}=e3(),r=[...t.nodes].find(J=>Ed(J,"provenance")&&J.meta.name==="functionTerm")??null,s=[...t.nodes].find(J=>Ed(J,"reifiedEdges")&&J.dtype==="u32")??null,o=ec(t),l=o.column?.meta.role==="parents"&&r8(o.column);let a=XG(t,e,l,[r,s],n,i);const c=Ut(t);VT(t,c,e,vI.UNDIRECTED_AS_DIRECTED,i);const d=BT(t,e,"CX",vt,i),u=d instanceof N?null:d;d instanceof N&&(a??=d);const f=YT(t,i,u);t.nodes.has(vt)&&i(w.ROLE_ASSUMED,`node column "${vt}" is the importer's record of mangled ids: it reads back as the node ids unless restoreMangledIds is false`,vt,null);const h=ZG(t,i),{position:p,z:g,positionZ:m}=h;let{nonfinite:y}=h;const b=[...t.nodes].find(J=>Ed(J,"cyGroups")&&J.dtype==="bool")??null,_=e8(t,i),S=[],I=t.edges.get("interaction");I!==null&&(I.meta.role===null||!mg.has(I.meta.role))&&(S.push({key:"i",column:I}),yg(I,"edge",i));const T=new Set([..._,...S].map(J=>J.column)),D=J=>T.has(J)||Oo(J)||RI(J)||J===g||J===b||J===r||J===s||J.meta.role!==null&&mg.has(J.meta.role),P=t.nodes.byRole("label"),k=P!==null&&P.meta.name!=="name"?t.nodes.get("name"):null;k!==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 "${P?.meta.name??""}" is written as n and takes the name "name"`,"name",k.length-k.nullCount);const U=Lh(t.nodes,D,J=>J===k?"name#2":J.meta.name),Y=t8(t,c,i),me=t.edges.get(tr),Oe=Lh(t.edges,J=>D(J)||J===me&&J.meta.role===null,J=>J.meta.name);y+=Y.nonfinite,QG(t,i);const Fe=Lh(t.graph,J=>Oo(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:Y.plan,nodeCore:_,edgeCore:S,nodeAttrs:U,edgeAttrs:Oe,graphAttrs:Fe,position:p,positionZ:m,z:g,bypass:{node:[...t.nodes].filter(Oo),edge:[...t.edges].filter(Oo),graph:[...t.graph].filter(Oo)},collapsed:b,links:s8(t),functionTerm:r,reifiedEdge:s}}function e8(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}),yg(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||!mg.has(o.meta.role))&&(n.push({key:"r",column:o}),yg(o,"node",e)),n}function yg(t,e,n){KG(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 Lh(t,e,n){return[...t].filter(i=>!e(i)).map(i=>({column:i,name:n(i),d:HT(i)}))}function t8(t,e,n){const i=wt(t),r=t.edges.get(tr),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 "${tr}" is not written: the explicit weights are written under that name`,tr,null);else if(s){const l=YG.has(r.dtype);n(w.WEIGHT_KEY_CLASH,l?`edge column "${tr}" is written as the weight attribute and reads back as the edge weight`:`edge column "${tr}" is ${r.dtype}, and CX reads that attribute as the edge weight; it is not written`,tr,null),l&&(o={value:a=>r.isSet(a)?r.value(a):void 0})}return{plan:o,nonfinite:o===null?0:n8(t.edgeCount,o,e)}}function n8(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 i8(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 Ph(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 r8(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&t.value(e).length>1)return!0;return!1}function s8(t){const e=[];for(const[n,i]of[["node",t.nodes],["edge",t.edges]])for(const r of i)if(RI(r)){const s=r.meta.name;e.push({aspect:`${n}${s==="citations"?"Citations":"Supports"}`,key:s,domain:n,column:r})}return e}function Sa(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 xh(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(Sa)}return Sa(i)}function wd(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)):Sa(n)}function o8(t,e){const n=[];for(let i=0;i<t.edgeCount;i++)e.folded(i)||n.push(i);return n}function l8(t,e,n,i){const{src:r,dst:s}=t.edgeList(),o=o8(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===lb&&M(t.meta.extra.cx)?t.meta.extra.cx:{},h=[{name:"nodes",idCounter:XM(n,t.nodeCount),*elements(){for(let g=0;g<t.nodeCount;g++){const m={"@id":n.idAt(g)},y=c===null?void 0:wd(c,g),b=d===null?void 0:wd(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:wd(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=xh(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:vt,v:String(n.originalAt(g)),d:"string"})}},{name:"edgeAttributes",*elements(){for(const g of e.edgeAttrs)for(const m of o){const y=xh(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:tr,v:Sa(m),d:"double"})}}},{name:"networkAttributes",*elements(){for(const m of e.graphAttrs){const y=xh(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:()=>a8(e,n)},{name:"cartesianLayout",elements:()=>u8(e,n,l())},{name:"cyGroups",elements:()=>f8(t,e,n,o)},{name:"cyVisualProperties",elements:()=>i===null?p8(e,n,l(),o,f):g8(i,n,e.edgeIds,o)}],p=sb(t);p!==null&&h.push({name:Z,elements:()=>_I(p)}),h.push(...y8(t,e,n,o));for(const[g,m]of Object.entries(f))!HG.has(g)&&Array.isArray(m)&&h.push({name:g,elements:()=>d8(m,f.subnetwork,c8.has(g))});return h}function*a8(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:vt,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:tr,d:"double"});for(const n of t.graphAttrs)yield{applies_to:"network_table",n:n.name,d:n.d}}const c8=new Set(["tableVisualProperties","cyTableVisualProperties"]);function*d8(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?PI(s):s}}function PI(t){const e={...t};return"view"in e&&(e.view=0),typeof e.applies_to=="number"&&(e.applies_to=0),e}function*u8(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*f8(t,e,n,i){const r=ec(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}=h8(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:wd(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 h8(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 Mh(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]=Sa(i.value(e))}return n}function*p8(t,e,n,i,r){const s=Mh(t.bypass.graph,0);s!==null&&(yield{properties_of:"network",properties:s});const o=m8(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 PI(l));for(const l of n){const a=Mh(t.bypass.node,l);a!==null&&(yield{properties_of:"nodes",applies_to:e.idAt(l),properties:a})}for(const l of i){const a=Mh(t.bypass.edge,l);a!==null&&(yield{properties_of:"edges",applies_to:t.edgeIds[l],properties:a})}}function*g8(t,e,n,i){yield*r5(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 m8(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 y8(t,e,n,i){const r=[];for(const[l,a]of Object.entries(kI)){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*b8(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=l8(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":${vi(o)}},
43
+ `;for(const{aspect:l}of s)yield*KT(l.name,E8(l.elements(),vi));yield`{"status":[{"error":"","success":true}]}]
44
+ `}function*E8(t,e){for(const n of t)yield e(n)}const w8=Object.freeze({format:lb,options:Object.freeze([]),capabilities:DI,styles:Object.freeze({capabilities:OG}),check(t,e){const n=Tf(t,e?.styles,"desktop");return Object.freeze([...LI(n?.snapshot??t,dt(e)).notes,...n?.notes??[]])},export(t,e){return ei(kw(t,e))},exportToString(t,e){return ti(kw(t,e))}});function kw(t,e){const n=Tf(t,e?.styles,"desktop"),i=n?.snapshot??t;return b8(i,LI(i,dt(e)),n?.styled??null)}const Be="cx",Rw="cx.bypass",Hn=Object.freeze({...xn,...Pn,EMPTY_INPUT:Mt,SYNTAX:kn,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,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:Bd,STATUS_WARNING:ty,BAD_ASPECT_BLOCK:pt,ASPECT_ORDER:Bn,COUNT_MISMATCH:Us,BAD_VALUE:ne,WIDENED:ua,UNKNOWN_ATTR_TYPE:Zt,DANGLING_REFERENCE:Ki,DUPLICATE_ATTRIBUTE:de,UNKNOWN_PARENT:Mi,PARENT_CYCLE:fl,STYLES_NOT_IMPORTED:Zs,MISSING_ID:at,MISSING_ENDPOINT:Jn,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Oi,INVALID_ID:"E_INVALID_ID",UNKNOWN_ELEMENT:$t,MULTI_ASPECT_FRAGMENT:ey,SINGLE_OBJECT_ASPECT:gA,JSON_NONSTANDARD_NUMBER:qu,UNKNOWN_NODE:"E_UNKNOWN_NODE",INVALID_WEIGHT:"E_INVALID_WEIGHT",ID_TEXT_TYPE:os,PRECISION:ie,ID_MERGED:Rn,MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,NO_GRAPH:rs,COLUMN_RENAMED:ln,ROLE_TAKEN:yn,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,TOO_LARGE:hl}),_8=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]),xI={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},MI=64,S8=new Set(["281474976710655","9223372036854775807"]),_d=new Map([["visualProperties","cyVisualProperties"],["subNetworks","cySubNetworks"],["networkRelations","cyNetworkRelations"],["hiddenAttributes","cyHiddenAttributes"]]),O8=new Set(["@id","n","r"]),N8=new Set(["@id","s","t","i"]),A8=new Set(["node_table","edge_table","network_table"]),bg=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"]),T8=new Set(["cySubNetworks","cyNetworkRelations","cyViews","cyVisualProperties","cyTableColumn","numberVerification","metaData"]),UI=["tableVisualProperties","cyTableVisualProperties"],I8=["groups","subnetwork"],$8=new Set(["numberVerification","metaData"]),GI=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"]),C8=new Map([["string","string"],["boolean","boolean"],["integer","integer"],["long","long"],["double","double"],["float","double"]]);function Uc(t){if(t==null)return{scalar:"string",list:!1};if(typeof t!="string")return null;const e=t.startsWith("list_of_"),n=C8.get(e?t.slice(8):t);return n===void 0?null:{scalar:n,list:e}}function go(t){return t.list?`list_of_${t.scalar}`:t.scalar}const Lw={boolean:0,integer:1,long:2,double:3,string:4};function v8(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)?Lw[t.scalar]>Lw[e.scalar]?t:e:{scalar:"string",list:t.list}}const Yt=Symbol("bad"),Qo=Symbol("unset"),jI=-2147483648,FI=2147483647,D8=/^-?\d+$/,k8=/^-?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;function zI(t){return t===""||t.toLowerCase()==="null"}function Pw(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)):Yt;if(typeof t=="number"||typeof t=="boolean")return R8(t,e,n);if(typeof t!="string")return Yt;if(e==="string")return t;if(zI(t))return Qo;switch(e){case"boolean":{const r=t.toLowerCase();return r==="true"||r==="false"?r==="true":Yt}case"integer":case"long":{if(t==="NaN")return Qo;if(!D8.test(t))return Yt;const r=Number(t);return e==="integer"?r>=jI&&r<=FI?r:Yt: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(!k8.test(t))return Yt;const r=Number(t);return Number.isFinite(r)||i(t),r}}}function R8(t,e,n){switch(e){case"string":return String(t);case"boolean":return typeof t=="boolean"?t:Yt;case"integer":return typeof t=="number"&&Number.isInteger(t)&&t>=jI&&t<=FI?t:Yt;case"long":return typeof t!="number"||!Number.isInteger(t)?Yt:n==="string"?String(t):t;default:return typeof t=="number"?t:Yt}}function xw(t,e,n,i){if(Array.isArray(t)!==e.list)return Yt;if(!e.list)return Pw(t,e.scalar,n,i);const r=[];for(const s of t){let o=s===null?Qo:Pw(s,e.scalar,n,i);if(o===Qo&&(o=e.scalar==="double"?Number.NaN:Yt),o===Yt)return Yt;r.push(o)}return r}function Uh(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 L8(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 he(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 Ae(t,e){return t.aspects.get(e)??[]}function P8(t,e,n=1){if(!/\d[.eE]/.test(t))return 0;let i=0;return e.forEach((r,s)=>{i1(t,r,n)&&(i|=1<<s)}),i}function x8(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 M8(t,e,n,i){const r=M(t)?t.longNumber:void 0,s=r instanceof vn?r.digits:String(r);if(e>1||!S8.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 ${he(o)}, not 281474976710655`,{line:i,element:"numberVerification"})}}function Mw(t){return bg.has(t)||_d.has(t)||GI.has(t)||UI.includes(t)}const U8=new Map([["nodes",["@id"]],["edges",["@id","s","t"]]]);function G8(t,e,n,i){const{value:r,line:s}=n,o=M(r)?r.n:void 0;if(o==null){i.error("missing-value",at,`a ${e} element has no attribute name n; skipped`,{line:s,element:e});return}if(typeof o!="string"||o===""){i.error("validation-error",ne,`a ${e} element has the attribute name n ${he(o)}, not a non-empty string; skipped`,{line:s,element:e});return}t.has(o)||t.set(o,[]),t.get(o)?.push(n)}function j8(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),T8.has(r)||!bg.has(r)){n.kept.has(r)||n.kept.set(r,[]);const h=r==="numberVerification"?void 0:t.onKeptPrecision;n.kept.get(r)?.push(a?Ke(s,h):s)}if(!bg.has(r)||r==="metaData"||r==="status")return;if(r==="numberVerification"){M8(s,++t.verifications,i,l);return}const d=U8.get(r),u={value:s,line:l,inexact:d===void 0?0:P8(o,d,c)},f=x8(n,r);if(f!==null){G8(f,r,u,i);return}n.aspects.has(r)||n.aspects.set(r,[]),n.aspects.get(r)?.push(u)}async function WI(t,e,n){const i=new o1(e,p=>_d.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:t1(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&&Mw(g)?a++:g!==null&&c.add(g)},f=(p,g)=>{const m=_d.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)=>{j8(s,{name:p,value:g,text:m,line:y,exact:b,depth:_})};try{for await(const p of QT(Nr(t,e,n),e))switch(++o>=MI&&(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":he(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 ${he(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);Mw(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(", ")})`:he(g);e.error("parse-error",pt,`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),n1(e,p),i.block(f(p.aspect,p.line),p.line);break;case"element":{const g=_d.get(p.aspect)??p.aspect;h(g,p.value,p.text,p.line,p.exact);break}case"deep":u(p.block,p.aspect),e1(e,p);break;case"extraKeys":e.error("parse-error",pt,`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 Ze&&e.fail(p.empty?Mt: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",ne,`the status element is ${he(i.status??null)}, not an object with a boolean success; ignored`,{element:"status"}),i.checkCounts(),r}function ye(t){try{return ou(t).id}catch{return null}}function Uw(t){return t.view===void 0||t.view===null?null:ye(t.view)}function Gw(t){return typeof t=="string"?t:JSON.stringify(t)}function Eg(t,e){if(t==="all")return null;const n=new Set;if(Array.isArray(t))for(const i of t){const r=ye(i);r===null?e?.(Hn.INVALID_ID,`the member ${he(i)} is not an id; ignored`):n.add(r)}else t!==void 0&&e?.(ne,`the member list ${he(t)} is neither a list of ids nor "all"; read as empty`);return n}function gu(t,e,n,i){const{value:r,line:s}=t;if(!M(r))return i.error("parse-error",pt,`a ${e} element is ${he(r)}, not an object; skipped`,{line:s,element:e}),null;if(r[n]===void 0||r[n]===null)return i.error("missing-value",at,`a ${e} element has no ${n}; skipped`,{line:s,element:e}),null;const o=ye(r[n]);return o===null?(i.error("validation-error",Hn.INVALID_ID,`a ${e} element has the ${n} ${he(r[n])}, not an integer id; skipped`,{line:s,element:e}),null):{value:r,id:o}}function BI(t,e){const n=F8(t,e),{relationNames:i,order:r,views:s}=z8(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=B8(t)),[{index:0,name:(o===null?null:i.get(o)??null)??jw(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)??jw(t,o),subnetwork:o,nodes:n.get(o)?.nodes??null,edges:n.get(o)?.edges??null,views:s.get(o)??[]}))}function F8(t,e){const n=new Map;for(const i of Ae(t,"cySubNetworks")){const r=gu(i,"cySubNetworks","@id",e);if(r===null)continue;const{value:s,id:o}=r;if(n.has(o)){e.error("validation-error",pt,`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:Eg(s.nodes,l),edges:Eg(s.edges,l)})}return n}function z8(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 Ae(t,"cyNetworkRelations")){const a=gu(l,"cyNetworkRelations","c",n);a!==null&&W8(a,e,{relationNames:i,order:r,addView:o})}for(const l of Ae(t,"cyViews")){const a=gu(l,"cyViews","@id",n),c=a===null?null:ye(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 W8(t,e,n){const{value:i,id:r}=t;if(i.r==="view"){const s=ye(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 jw(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:ye(i.s);if(r===e)return i.v;r===null&&(n??=i.v)}return n}function B8(t){const e=[];for(const{value:n}of Ae(t,"cartesianLayout")){const i=M(n)&&n.view!==void 0?ye(n.view):null;i!==null&&!e.includes(i)&&e.push(i)}return e}function Fw(t,e){return t===null?e:t.size}class H8{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 Qn(e,n,i.onMixedDirection),this.coercer=new Mn(i.ids);for(const{value:l}of Ae(s,"nodes")){const a=M(l)?ye(l["@id"]):null;a!==null&&this.rootNodes.add(a)}for(const{value:l}of Ae(s,"edges")){const a=M(l)?ye(l["@id"]):null;a!==null&&this.rootEdges.add(a)}for(const{value:l}of Ae(s,"cySubNetworks")){const a=M(l)?ye(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",Ki,`${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>=MI&&(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=ye(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=ou(e,n);return o.note==="text"?this.report.warnOnce("coercion",os,`${i}: the id ${he(e)} is not written as an integer; read as ${String(o.id)}`,{line:r,element:i}):o.note==="precision"&&s?this.report.warnOnce("precision",ie,`${i}: the edge id ${String(o.id)} is beyond 2^53; the id column holds the nearest double`,{line:r,element:i},`${ie}:edge`):o.note==="precision"&&(this.idType="mixed",this.report.warnOnce("precision",ie,`${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",ie,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},`${ie}:value`)}unknownKeys(e,n,i,r){for(const s of Object.keys(e))n.has(s)||this.report.warnOnce("unsupported",$t,`the ${i} key "${s}" is not defined by CX; its values are not read`,{line:r,element:s},`${$t}:${i}:${s}`)}checkTableColumns(){for(const{value:e,line:n}of Ae(this.doc,"cyTableColumn"))M(e)&&typeof e.applies_to=="string"&&!A8.has(e.applies_to)&&this.report.warnOnce("unsupported",$t,`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},`${$t}: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=Ae(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=Eg(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?fe(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===vt&&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=Uc(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:v8(c,d);if(o.length>1&&this.report.warnOnce("coercion",ua,`the ${e} attribute "${s}" has the data types ${o.map(go).join(", ")}; the column holds ${c===null?"their values as JSON":go(c)}`,{element:s},`${ua}:${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=ye(e);return n!==null&&n===this.plan.subnetwork?2:0}tableColumns(e){const n=new Map;for(const{value:i}of Ae(this.doc,"cyTableColumn")){if(!M(i)||i.applies_to!==e||typeof i.n!="string"||this.scopePeek(i.s)===0)continue;const r=Uc(i.d);r===null?this.report.warnOnce("unsupported",Zt,`cyTableColumn declares "${i.n}" with the data type ${he(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:Be,id:null}}:{name:n,dtype:i.list?"list":Uh(i.scalar,r),...i.list?{itemDtype:Uh(i.scalar,r)}:{},nullable:!0,origin:{format:Be,id:null,type:go(i)}};return fe(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",pt,`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",ne,`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=ye(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(Ke(a.v))&&this.report.warnOnce("validation-error",de,`${e} ${he(u)} has the attribute "${s.name}" twice; the later value wins`,{line:c,element:s.name},`${de}:${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=Ke(r,d=>{this.precision(n.name,d)});else{const d=Uc(s)??{scalar:"string",list:!1},u=xw(r,d,this.options.long,f=>{this.precision(n.name,f)});if(u===Qo)return;if(u===Yt){this.report.error("validation-error",ne,`${l}: ${he(r)} is not a ${go(d)}; the cell is unset`,{line:o,element:n.name});return}a=L8(u,n.type)}let{handle:c}=n;if(this.isStructural(e,n.name)){if(Array.isArray(r)){this.report.error("validation-error",ne,`${l}: ${he(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",de,`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},`${de}: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:Be,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:Be,id:"n",type:"string"}}),this.nameHandle):(this.representsHandle=this.structural("node",this.representsHandle,{name:"represents",dtype:"string",nullable:!0,origin:{format:Be,id:"r",type:"string"}}),this.representsHandle)}readNodes(){const{report:e}=this,n=this.originalIds();for(const i of Ae(this.doc,"nodes")){this.checkAbort();const{value:r,line:s}=i;if(!M(r)){e.error("parse-error",pt,`a nodes element is ${he(r)}, not an object`,{line:s,element:"nodes"}),e.counts.skippedNodes++;continue}if(r["@id"]===void 0||r["@id"]===null){e.error("missing-value",at,"a node has no @id",{line:s,element:"nodes"}),e.counts.skippedNodes++;continue}this.unknownKeys(r,O8,"node",s);const o=`node ${he(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(ye(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(vt)??[]){const i=M(n)&&this.scopePeek(n.s)!==0?ye(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",ne,`${s}: ${i} is ${he(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=Ae(this.doc,"cyGroups");if(e.length===0)return;const n=new Map,i=[];for(const r of e){const s=gu(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",ne,`group ${String(l)}: nodes is ${he(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",ne,`group ${String(l)}: collapsed is ${he(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=ye(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",Mi,`group ${String(l)}: the member ${he(d)} is not a node`,{line:a,element:String(l)});continue}if(this.closesCycle(n,f,c)){this.report.error("validation-error",fl,`group ${String(l)}: making ${he(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}=fe(this.sink,"node",{name:"collapsed",dtype:"bool",nullable:!0,origin:{format:Be,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=ye(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}=fe(this.sink,"node",i,this.report);for(const[s,o]of e)this.sink.setNodeValue(r,s,n?o:o[0])}readLayout(){const e=Ae(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",pt,`a cartesianLayout element is ${he(a)}, not an object; skipped`,{line:c,element:"cartesianLayout"});continue}const d=a.view===void 0||a.view===null?null:ye(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",ne,`a cartesianLayout element for node ${he(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",ne,`a cartesianLayout element for node ${he(a.node)} has the coordinates ${String(a.x)}, ${String(a.y)}, which are not both finite; skipped`,{line:c,element:"cartesianLayout"});continue}const f=ye(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",ne,`a cartesianLayout element for node ${he(a.node)} has the z ${he(a.z)}, not a number; z is unset`,{line:c,element:"cartesianLayout"});const p=`${u}:${h}`;o.has(p)&&this.report.warnOnce("validation-error",de,`node ${he(a.node)} has two layout entries for one view; the later wins`,{line:c,element:"cartesianLayout"},`${de}:layout`),o.add(p);const g=typeof a.z=="number"?a.z:null;l[0]=a.x,l[1]=zo(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,Jp(Be)),this.sink.setNodeValue(s.current,h,g))}}allViews(){const e=new Set;for(const{value:n}of Ae(this.doc,"cyNetworkRelations"))if(M(n)&&n.r==="view"){const i=ye(n.c);i!==null&&e.add(i)}for(const{value:n}of Ae(this.doc,"cyViews")){const i=M(n)?ye(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=r1(Be,this.zAs==="position"&&n===0?3:2),o=n===0?s:{...s,name:`position@${n+1}`,role:void 0,origin:{format:Be,namespace:"cytoscape",id:String(i[n])}};({handle:r}=fe(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 Ae(this.doc,"edges")){this.checkAbort();const{value:s,line:o}=r;if(!M(s)){e.error("parse-error",pt,`an edges element is ${he(s)}, not an object`,{line:o,element:"edges"}),e.counts.skippedEdges++;continue}if(s["@id"]===void 0||s["@id"]===null){e.error("missing-value",at,"an edge has no @id",{line:o,element:"edges"}),e.counts.skippedEdges++;continue}this.unknownKeys(s,N8,"edge",o);const l=`edge ${he(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",Jn,`${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",Oi,`${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=Ke(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=ye(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",de,`edge ${he(n)} has the attribute "${s}" twice; the later value wins`,{line:r,element:s},`${de}:edge:${s}`),e.set(o,i))}weightOf(e){if(this.options.weightFrom===null)return;const n=this.weights.get(e);if(!(typeof n=="string"&&zI(n)))return sf(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",ne,`a networkAttributes element for "${e}" has no v; skipped`,{line:d,element:e});continue}i!==null&&u===r&&JSON.stringify(Ke(i.v))!==JSON.stringify(Ke(c.v))&&this.report.warnOnce("validation-error",de,`the network attribute "${e}" is given twice; the later value wins`,{line:d,element:e},`${de}:network:${e}`),u>=r&&(i=c,r=u)}}if(i?.v===void 0||i.v===null)continue;const s=Uc(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=xw(i.v,o,this.options.long,c=>{this.precision(e,c)});if(l===Qo)continue;if(l===Yt){this.report.error("validation-error",ne,`the network attribute "${e}" is ${he(i.v)}, not a ${go(o)}; unset`,{element:e});continue}if((e==="name"||e==="description")&&typeof l=="string")continue;const a=Uh(o.scalar,this.options.long);try{this.sink.setGraphValue(e,l,{dtype:o.list?"list":a,...o.list?{itemDtype:a}:{},origin:{format:Be,id:null,type:go(o)}})}catch(c){this.report.recordError(c,{element:e})}}}readVisualProperties(){const e=Ae(this.doc,"cyVisualProperties"),n=UI.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(Uw(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)?Uw(a):null;return n(c)?!0:(i.add(c),!1)}),{weightFrom:s}=this.options,o=Ae(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,Gw(s));else n.defaults+=Object.keys(i).length}collectElementProperties(e,n,i){const r=e.properties_of==="nodes"?"node":"edge",s=ye(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,Gw(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=l1(this.sink,n,{name:i,dtype:"string",nullable:!0,origin:{format:Be,id:i,namespace:Rw}},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:Be,id:null,namespace:Rw}})}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",Zs,`the file's style rules are not applied (${o.join("; ")}); they are kept in meta.extra.cx`,{element:"cyVisualProperties"})}readStyleBlock(){const e=wI(this.doc.kept.get(Z));e!==null&&this.sink.setGraphValue(Z,e,{dtype:"string",origin:{format:Be,id:null}})}readProvenance(){for(const i of["citations","supports"])this.extensionTable(`cx:${i}`,Ae(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 Ae(this.doc,"functionTerms")){if(!M(i))continue;const r=ye(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,Ke(l)])}this.writeColumn("node","functionTerm","json",null,e);const n=[];for(const{value:i}of Ae(this.doc,"reifiedEdges")){if(!M(i))continue;const r=ye(i.node),s=ye(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}=fe(this.sink,"node",{name:"reifiedEdge",dtype:"u32",refersTo:"edge",nullable:!0,origin:{format:Be,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=ye(c["@id"]);typeof d=="string"&&a(d),this.sink.addExtensionRow(l,[d===null?null:Number(d),...r.map(u=>c[u]===void 0?null:Ke(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 Ae(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(ye).filter(d=>d!==null).map(Number);for(const d of a){const u=ye(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:Be,namespace:"provenance"}},{handle:l}=fe(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=Ae(this.doc,"cyGroups").map(c=>Ke(c.value)),r={};i.length>0&&(r.groups=i),this.plan.subnetwork!==null&&(r.subnetwork=this.plan.subnetwork);for(const c of I8)c in r&&this.doc.kept.has(c)&&this.report.warning("unsupported",$t,`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:Be,sourceVersion:"1",idType:this.idType,...o===null?{}:{name:o},...l===null?{}:{description:l},...this.weighted&&s!==null?{weightOrigin:{format:Be,id:null,title:s,type:"double",namespace:null}}:{},extra:{cx:n}};this.sink.setMeta(a)}}async function zw(t,e,n,i){const r=Qe(e,xI),s=CI(e?.zAs),o=new te(Be,r.errorLimit);Et(e,o,_8);const l=await WI(t,o,r),a=BI(l,o),c=i(a,o),d=[];return c.forEach((u,f)=>{const h=f===0?o:new te(Be,r.errorLimit),p=n(u);bt(p,e,h,!0),new H8(p,h,r,s,l,a[u]).build(),F(r.signal),d.push(h.finish())}),d}const Y8=Object.freeze({format:Be,options:Object.freeze(["zAs"]),extensions:Object.freeze([".cx"]),mimeTypes:Object.freeze(["application/json"]),styles:SG,sniff(t){const e=/^\s*\[\s*\{\s*"((?:[^"\\]|\\.)*)"\s*:/.exec(s1(t));return e===null?0:$8.has(e[1])?.95:GI.has(e[1])?.7:0},async import(t,e,n){const[i]=await zw(t,n,()=>e,(r,s)=>{const o=pl(r.map(l=>l.name),n,s);return r.length>1&&!eo(n)&&s.warning("unsupported",Zn,`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 zw(t,n,e,i=>i.map(r=>r.index))},async listGraphs(t,e){const n=Qe(e,xI),i=new te(Be,n.errorLimit),r=await WI(t,i,n),s=Ae(r,"nodes").length,o=Ae(r,"edges").length;return BI(r,i).map(l=>Object.freeze({index:l.index,name:l.name,nodes:Fw(l.nodes,s),edges:Fw(l.edges,o)}))}}),ab=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}),HI=Xe({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}),V8=new Set(["label","position","id"]),K8=Object.freeze({label:"name",position:My}),YI=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),X8=new Set(["visualProperties","visualEditorProperties"]),q8=new Set([Z,"nodes","edges","attributeDeclarations","networkAttributes","nodeBypasses","edgeBypasses","metaData","status"]),ps="weight";function Jl(t){return t.meta.origin?.namespace===NI}function wg(t){return t.meta.extra.cytoscape==="z"}function J8(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 _g(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:HT(l),jsonText:l.meta.dtype==="json"})}return r}function Z8(t,e,n,i){let r=null;const s=new Set([...t.nodes,...t.edges].filter(l=>Jl(l)||wg(l)).map(l=>l.meta.name));for(const l of Un(t,HI,e,{roles:V8,roleNames:K8,edgeRoleNames:{}}))if(Q8(l,s)){if(l.code===w.JSON){const a=l.column===null?"a column":`column "${l.column}"`;i(ab.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 Q8(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 e9(t,e,n,i,r){let s=0;for(const o of e)s+=J8(o.column);for(let o=0;o<t.edgeCount;o++)n.isExplicit(o)&&!Number.isFinite(n.value(o))&&s++;i!==null&&(s+=ZM(i)),s>0&&r(ab.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 t9(t,e,n){const i=t.edges.get(ps);return i!==null&&i.meta.role===null&&n(w.WEIGHT_KEY_CLASH,e.weighted?`edge column "${ps}" is not written: the explicit weights are written under that name`:`edge column "${ps}" reads back as the edge weight`,ps,null),_g(t.edges,r=>r.meta.role!==null&&(YI.has(r.meta.role)||r.meta.role==="id")||Jl(r)||e.weighted&&r===i,r=>r.meta.name,e.weighted?new Set([ps]):new Set)}function VI(t,e){const n=[],i=(y,b,_=null,S=null)=>{n.push(Object.freeze({code:y,message:b,column:_,count:S}))};let r=Z8(t,e,n,i);const s=Ut(t);VT(t,s,e,ab.UNDIRECTED_AS_DIRECTED,i);const o=BT(t,e,"CX2",vt,i),l=o instanceof N?null:o;o instanceof N&&(r??=o);const a=wt(t),c=t.nodes.byRole("label"),d=_g(t.nodes,y=>y.meta.role!==null&&YI.has(y.meta.role)||Jl(y)||wg(y),y=>y===c&&!t.nodes.has("name")?"name":y.meta.name,l!==null&&l.changed>0?new Set([vt]):new Set),u=t9(t,a,i),f=_g(t.graph,y=>y.meta.name===Z,y=>y.meta.name).map(y=>({...y,key:y.name})),h=t.nodes.byRole("position");e9(t,[...d,...u,...f],a,h,i);const p=YT(t,i,l),g=[...t.nodes].find(wg)??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(Jl),edgeBypasses:[...t.edges].filter(Jl),position:h,positionZ:m,z:g,edgeIds:p,originalIds:l!==null&&l.changed>0}}function KI(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 Sg(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&&n9(pu(i.d),s)&&(r.v=s),n[i.name]=r}return n}function n9(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 XI(t,e){let n=null;for(const i of t){const r=KI(i,e);r!==void 0&&(n??={},n[i.key]=r)}return n}function i9(t,e){const n=Sg(e.graphAttrs,!1),i={};for(const s of e.graphAttrs){const o=KI(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 r9(t,e,n){const i=Sg(t.nodeAttrs,!0);t.originalIds&&(i[vt]={d:"string"});const r=Sg(t.edgeAttrs,!0);t.weights.weighted&&(r[ps]={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 s9(t,e,n,i,r){const s={id:t.edgeIds[r],s:e.idAt(n[r]),t:e.idAt(i[r])};let o=XI(t.edgeAttrs,r);if(t.weights.isExplicit(r)){const l=t.weights.value(r);o??={},o[ps]=Number.isFinite(l)?l:null}return o!==null&&(s.v=o),s}function Ww(t){return t.filter(([,e])=>e>0).map(([e,n])=>[e,n])}function*o9(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}=i9(t,e),{meta:l}=t,a=M(l.extra.cx2)?l.extra.cx2:{},c=l.sourceFormat===Bt&&M(a.opaque)?a.opaque:{},d=r9(e,a,o),{bypassOf:u,nodeBypassRows:f,edgeBypassRows:h,opaqueAspects:p}=l9(t,e,n,c),g=Object.keys(d).length>0,m=Object.keys(s).length>0,y=[...Ww([["attributeDeclarations",g?1:0],["networkAttributes",m?1:0]]),["nodes",t.nodeCount],["edges",r.length],...Ww([["nodeBypasses",f.length],["edgeBypasses",h.length]]),...p.map(([S,I])=>[S,I.length])];yield`[{"CXVersion":"2.0","hasFragments":false},
45
+ `,yield`{"metaData":${vi(y.map(([S,I])=>({name:S,elementCount:I})))}},
46
+ `,g&&(yield`{"attributeDeclarations":[${vi(d)}]},
47
+ `),m&&(yield`{"networkAttributes":[${vi(s)}]},
48
+ `),yield*Ml("nodes",t.nodeCount,S=>vi(a9(e,i,S)));const{src:b,dst:_}=t.edgeList();yield*Ml("edges",r.length,S=>vi(s9(e,i,b,_,r[S]))),f.length>0&&(yield*Ml("nodeBypasses",f.length,S=>{const I=f[S];return vi({id:i.idAt(I),v:u("node",I)})})),h.length>0&&(yield*Ml("edgeBypasses",h.length,S=>{const I=h[S];return vi({id:e.edgeIds[I],v:u("edge",I)})}));for(const[S,I]of p)yield*Ml(S,I.length,T=>vi(I[T]));yield`{"status":[{"error":"","success":true}]}]
49
+ `}function l9(t,e,n,i){const r=(d,u)=>{if(n===null)return d9(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 c9(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=>!q8.has(d[0])&&!(n!==null&&X8.has(d[0]))&&Array.isArray(d[1]));if(n!==null){const d=o5(n.style);a.push(["visualProperties",d.visualProperties],["visualEditorProperties",d.visualEditorProperties])}const c=sb(t);return c!==null&&a.push([Z,_I(c)]),{bypassOf:r,nodeBypassRows:o,edgeBypassRows:l,opaqueAspects:a}}function Ml(t,e,n){return KT(t,(function*(){for(let r=0;r<e;r++)yield n(r)})())}function a9(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=XI(t.nodeAttrs,n);return t.originalIds&&e.isChanged(n)&&(r??={},r[vt]=String(e.originalAt(n))),r!==null&&(i.v=r),i}function c9(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 d9(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 u9=Object.freeze({format:Bt,options:Object.freeze([]),capabilities:HI,styles:Object.freeze({capabilities:TG}),check(t,e){const n=Tf(t,e?.styles,"cx2");return Object.freeze([...VI(n?.snapshot??t,dt(e)).notes,...n?.notes??[]])},export(t,e){return ei(Bw(t,e))},exportToString(t,e){return ti(Bw(t,e))}});function Bw(t,e){const n=Tf(t,e?.styles,"cx2"),i=n?.snapshot??t;return o9(i,VI(i,dt(e)),n?.styled??null)}const gs="http://graphml.graphdrawing.org/xmlns",Hw="http://www.yworks.com/xml/graphml",Sd="http://www.w3.org/2001/XMLSchema-instance",f9="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd",rt="graphml",h9=Object.freeze([".graphml",".xml"]),p9=Object.freeze(["application/graphml+xml","application/xml","text/xml"]),ks="graphty:originalId",g9="graphty.originalId",cb="id",db="sourceport",ub="targetport",fb="parent",m9="graphty.hyperedge",dr="label",qI=new Set([cb,db,ub]),JI=new Set([fb]),ZI="graphml",G=Object.freeze({...xn,...Pn,COLUMN_TYPE:ny,XML_SYNTAX:Vu,XML_NESTING:Ku,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,ENCODING_CONFLICT:ul,EMPTY_INPUT:Mt,NOT_GRAPHML:"E_NOT_GRAPHML",NAMESPACE:"W_GRAPHML_NAMESPACE",NO_GRAPH:rs,KEY_MISSING_ID:"E_GRAPHML_KEY_MISSING_ID",DUPLICATE_KEY:RL,KEY_DOMAIN_UNSUPPORTED:"W_GRAPHML_KEY_DOMAIN_UNSUPPORTED",MISSING_ID:at,MISSING_ENDPOINT:Jn,UNKNOWN_NODE:"E_UNKNOWN_NODE",GRAPH_ENDPOINT:"W_GRAPHML_GRAPH_ENDPOINT",UNKNOWN_PARENT:Mi,DUPLICATE_ATTRIBUTE:de,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:Oi,INVALID_DIRECTED:"E_GRAPHML_INVALID_DIRECTED",INVALID_EDGEDEFAULT:"E_GRAPHML_INVALID_EDGEDEFAULT",EDGEDEFAULT_MISSING:"W_GRAPHML_EDGEDEFAULT_MISSING",MULTIPLE_GRAPHS:Zn,COUNT_HINT:Wd,COUNT_MISMATCH:Us,HYPEREDGE:uA,HYPEREDGE_SKIPPED:"W_GRAPHML_HYPEREDGE_SKIPPED",HYPEREDGE_ENDPOINT:"E_GRAPHML_HYPEREDGE_ENDPOINT",PORT_DECLARATION:"W_GRAPHML_PORT_DECLARATION",DANGLING_REFERENCE:Ki,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:zd,LOCATOR_DROPPED:"W_GRAPHML_LOCATOR_DROPPED",DESC_DROPPED:"W_GRAPHML_DESC_DROPPED",UNKNOWN_ELEMENT:$t,STRAY_TEXT:Xu,ID_MERGED:Rn,OPTION_IGNORED:Jt,YFILES_SKIPPED:"W_GRAPHML_YFILES_SKIPPED",COLUMN_RENAMED:ln,ROLE_TAKEN:yn,UNKNOWN_ATTR_TYPE:Zt,BAD_DEFAULT:Wo,PRECISION:ie,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er}),ur=Object.freeze({YFILES_JSON:"W_GRAPHML_YFILES_JSON",MUTUAL_AS_UNDIRECTED:bA,PARENTS_DROPPED:ry,ROLE_DROPPED:iy,HIERARCHY_REORDERED:"W_GRAPHML_HIERARCHY_REORDERED",PARENT_CYCLE:"W_GRAPHML_PARENT_CYCLE",ID_TEXT_TYPE:os,EDGE_ID_TEXT:"W_GRAPHML_EDGE_ID_TEXT",YFILES_GRAPHICS_STALE:"W_GRAPHML_YFILES_GRAPHICS_STALE",YFILES_TREE:"E_GRAPHML_YFILES_TREE"}),y9=new Set(["id","label","name","xlink:href","cy:nodeId"]),b9=new Set(["id","label","name","source","target","weight","cy:directed","xlink:href","cy:edgeId"]),E9=new Set(["name","label","type","value","cy:type","cy:elementType","cy:hidden","cy:equation","cy:editable"]),w9=/^(1|true|yes)$/i;function wi(t){return t!=null&&w9.test(t.trim())}function _9(t,e){const n=t.indexOf(":");if(n<=0)return t;const i=t.slice(0,n);return i==="xlink"||e.get(i)===nb?`xlink:${t.slice(n+1)}`:t}const Yw=new Map;class S9{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)?vs(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=N9(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??""}${et(e)}`,this.captureRdfText(e);return}Sr(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)??Yw;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)??Yw}normalize(e){const n=new Map,{scope:i}=this;for(const[r,s]of e)n.set(_9(r,i),s);return n}startRoot(e,n,i){const r=vs(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)===wa,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)===wa}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:Vw(n,y9),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:Vw(n,b9),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)!E9.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:wi(e.get("cy:hidden")),equation:wi(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=vs(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&&!Sr(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:Og(n),writable:!0,enumerable:!0,configurable:!0}):i[n.name]=Og(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 O9(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 Og(t){return QI(t,e=>e.children.length>0?null:e.value!==null?{value:e.value}:{value:Object.keys(e.extra).length>0?{...e.extra}:null})}function QI(t,e){const n=e(t);if(n!==null)return n.value;const i=o=>O9(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 N9(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 Vw(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 e$={string:"string",double:"real",integer:"int",long:"long",boolean:"bool",list:"list"},t$={string:"string",real:"real",integer:"int",boolean:"bool",list:"list",map:"map"};function Kw(t){let e,n=null;return t.cyType!==null&&t.cyType.length>0&&(e=e$[t.cyType.trim().toLowerCase()],n=t.cyType),e===void 0&&t.type!==null&&t.type.length>0&&(e=t$[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 A9(t){if(t===null)return null;const e=e$[t.trim().toLowerCase()]??t$[t.trim().toLowerCase()];return e===void 0||e==="list"||e==="map"?null:e}function Gh(t,e){return t===e?t:t==="string"||e==="string"||t==="bool"||e==="bool"?"string":t==="real"||e==="real"?"real":"long"}const T9=/^[+-]?\d+$/,I9=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/,$9=/^[+-]?(?:NaN|Infinity)$/,C9=-2147483648,v9=2147483647;function Ng(t,e,n){switch(e){case"string":return{value:n?D9(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(!T9.test(i))return null;const r=Number(i);return e==="int"&&(r<C9||r>v9)?{value:r,overflow:Number.isSafeInteger(r)?"i32":"precision"}:{value:r,overflow:Number.isSafeInteger(r)?void 0:"precision"}}case"real":{const i=t.trim();if(!I9.test(i)&&!$9.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 D9(t){return t.includes("\\")?t.replaceAll(String.raw`\t`," ").replaceAll(String.raw`\n`,`
50
+ `):t}const jh={bool:"bool",int:"i32",long:"f64",real:"f64",string:"string"};class Fh{constructor(e,n,i){this.plans=new Map,this.domain=e,this.report=n,this.options=i}has(e){return this.plans.has(Xw(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=Kw(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:qw("string",n.value,n.value,!0),a!==null&&s.declared.add("string")):(o.kind==="list"||o.kind==="map")&&P9(n,Zw)?(this.badAtt(`"${r}" is nested more than ${String(Zw)} 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=Gc(Jw(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=of(i),l=L9(Xn(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,Gc(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=Xw(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"),Gc(e.xml);if(e.value===null)return i.declared.add(n),null;const s=Ng(e.value,n,this.options.unescape);return s===null||s.overflow!==void 0&&n==="int"&&zh(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"),qw(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),Gc(o.size>1?Jw(e):s.map(n$));let l=A9(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=Kw(d),f=u.kind==="list"||u.kind==="map"?"string":u.kind;c.add(f),l=l===null?f:Gh(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=Ng(c.value,l??"string",this.options.unescape),u=zh(e.elementType)||zh(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:k9(n,o),namespace:n.namespace??(n.hidden?Af: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:Qw(u,o),l)}catch(f){this.report.recordError(f,c)}return}let d;try{({handle:d}=fe(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=Qw(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:Gh(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:jh[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:Gh(i,l)}i===null&&(i=[...e.declared].find(l=>l in jh)??"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=jh[i];if(i==="string"){const o=new Qs;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 ${R9[n]}; the cell is left unset`,i)}recordList(e,n){this.report.warnOnce("coercion",j.RECORD_LIST,e,n)}}function zh(t){return t?.trim().toLowerCase()==="integer"}function k9(t,e){return t.equation?"equation":e.long?"long":t.declaredType}const R9={bool:"boolean (1, 0, true, false, yes, no)",int:"integer",long:"long integer",real:"real number",string:"string"};function Xw(t,e){return t===null?e:`${t}\0${e}`}function L9(t){switch(t){case"bool":return"bool";case"i32":return"int";case"f64":return"real";default:return"string"}}function qw(t,e,n,i){return{kind:t,value:e,text:n,items:[],itemKind:null,typed:i}}function Gc(t){return{kind:"json",value:t,text:JSON.stringify(t),items:[],itemKind:null,typed:!0}}function Jw(t){const e={};for(const n of t.children)e[n.name??""]=n$(n);return e}const Zw=64;function P9(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 n$(t){return QI(t,e=>e.xml!==null?{value:e.xml}:e.children.length===0?{value:e.value}:null)}function Qw(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=>e_(n.value,n.text,e.item??"string")):e_(t.value,t.text,e.long&&e.dtype==="string"?"string":e.scalar??"string")}function e_(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 x9=new Set(["documentVersion","networkMetadata"]),M9=new Set(["id","label","directed","xlink:href","cy:documentVersion","cy:view","cy:registered","cy:networkId","cy:visualStyle","cy:rendererId"]),U9=64,G9=/[()]/;function i$(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=>wi(o.registered));return{versionText:i,version:r,cytoscape:t.cytoscape,cy2:t.cytoscape&&r<3,session:n.registered!==null&&!wi(n.registered)&&s,view:wi(n.attrs.get("cy:view"))}}function j9(t,e){return e.session?t.root.subgraphs.filter(n=>wi(n.registered)):[t.root]}function r$(t){const e=Ng(t,"real",!1);return e===null||!Number.isFinite(e.value)?null:e.value}function cc(t){return t.startsWith("#")?t.slice(1):null}function F9(t,e){return t??(e===null?null:cc(e))}function so(t,e){if(e===null)return{nodes:t.nodes,edges:t.edges,dangling:0};const n=t_(t.nodes),i=t_(t.edges),r=[],s=[];let o=0;for(const l of e.members){const a=z9(l,n,i);a===void 0?o++:a.kind==="node"?r.push(a):s.push(a)}return{nodes:r,edges:s,dangling:o}}function z9(t,e,n){if(t.href===null)return t;const i=cc(t.href);if(i!==null)return t.kind==="node"?e.get(i):n.get(i)}function t_(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 W9(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 B9(t){return t.name!==null&&x9.has(t.name)?!1:!(t.hasGraph&&t.name===null)}class hb{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 Qn(i,r,s.onMixedDirection);const a={unescape:o.cytoscapeEscapes,long:s.long},c=l.labelFromName===!0?[]:[Bs];this.nodeColumns=new Fh("node",r,{...a,reserved:new Set([...c,Nl,ro,Qt,lc,Nf,Hs,ac,Zo,_a])}),this.edgeColumns=new Fh("edge",r,{...a,reserved:new Set([Jo,...c,Qt])}),this.graphColumns=new Fh("graph",r,{...a,reserved:new Set([Qt])})}emit(e){const n=so(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 K9(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>=U9&&(this.sinceCheck=0,F(this.options.signal))}declare(e,n){try{return fe(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(Wh))}labelOf(e){return this.nameLabel[e.kind]?e.atts.find(Wh)?.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"&&wi(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=cc(r.href);s!==null&&(r.kind==="node"?this.rows.has(s):n.has(s))||i++}return i}writeNodeExtras(e,n){const i=[],r=new H9(this,this.dialect.cytoscape?this.settings.zAs:"position"),s=new Oa(this,"node",Qt,hn,"graphics"),o=new V9(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]&&Wh(a)||o&&a.name!==null&&r.has(a.name)||i.kind==="node"&&a.name==="__isGroup"&&i.nested.length>0&&wi(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":Bs,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"?F9(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:_a,dtype:"list",itemDtype:"string",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graph",namespace:hn}});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(W9(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 Oa(this,"edge",Qt,hn,"graphics");for(const[f,h]of c)u.set(f,h)}addEdge(e,n,i,r){const s=this.settings.labelAliases?Ag(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=Vn(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===ql))return;const r=Ag(e.label);r!==null&&(this.edgeColumns.addText(n,ql,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:Jo,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)!M9.has(s)&&s!=="xmlns"&&!s.startsWith("xmlns:")&&this.graphColumns.addText(0,s,o,i);for(const s of n.atts)B9(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:hn}})}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:{[uI]:{graphId:n.id,directed:this.doc.root.attrs.get("directed")??null,rdf:Object.keys(i).length>0?{...i}:null},...this.extras.metaExtra}})}}function Wh(t){return t.name==="name"&&(t.namespace??null)===null&&t.value!==null&&t.children.length===0&&(t.cyType??"String")==="String"}function Ag(t){if(t===null)return null;const e=t.split(G9);return e.length===3?[e[0].trim(),e[1],e[2].trim()]:null}class Oa{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 H9{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:Y9([...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,zo(o),this.zAs==="position"?l??0:0])}number(e,n){if(e===null)return null;const i=r$(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,zo(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:Nl,dtype:"f64",components:3,role:"position",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graphics",namespace:hn},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:ro,dtype:"f64",nullable:!0,origin:{format:Ht,id:null,title:null,type:"graphics",namespace:Af}});if(i!==null)for(const[r,s]of this.zValues)n.setNodeValue(i,r,s)}}}function Y9(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 V9{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=cc(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 Oa(this.emitter,"node",ac,Af,"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 ${Zo}`);const i=new Oa(this.emitter,"node",Zo,hn,"xlink:href","string");for(const[r,s]of this.crossFile)i.set(r,s)}}}class K9{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,Og(a)]))});for(const a of o.members){if(a.kind!=="node")continue;const c=a.id??(a.href===null?null:cc(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?Nf:lc,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 Oa(this.emitter,"node",Hs,hn,"graph");for(const[i,r]of this.subgraphs)n.set(i,r)}}}const X9={ids:"keep",defaultDirected:!1,weightFrom:"weight",addMissingNodes:!1},s$=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","errorLimit","signal","onProgress","encoding"]),o$=/<!DOCTYPE\s+graph\s[^<>]*xgmml\.dtd/i;function Tg(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:mu("labelAliases",t?.labelAliases,e),cytoscapeEscapes:mu("cytoscapeEscapes",t?.cytoscapeEscapes,e),zAs:n}}function mu(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 l$(t,e,n,i){const r=new S9(e),s={content:!1};try{await uf(Z9(Nr(t,e,{...n,declaredEncoding:df,xml:!0}),s),r,q9(e,i))}catch(l){throw l instanceof ee&&J9(e,l,s.content),l}const o=r.document();return!o.xgmmlNamespace&&!o$.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 q9(t,e){const n=r=>{t.warning("parse-error",j.AMPERSAND_REPAIRED,"a bare & was read as &amp;",{line:r})},i=r=>{t.warning("parse-error",j.SURROGATE_PAIRED,"two surrogate character references were joined into one character",{line:r})};return{bareAmpersand:mu("repairBareAmpersands",e?.repairBareAmpersands,!1)?n:void 0,surrogatePair:mu("pairSurrogateReferences",e?.pairSurrogateReferences,!1)?i:void 0}}function J9(t,e,n){return n||t.fail(j.EMPTY_INPUT,"the input is empty"),t.fail(e instanceof cf?j.XML_NESTING:j.XML_SYNTAX,e.message,{line:e.line})}async function*Z9(t,e){for await(const n of t)e.content||=!Sr(n),yield n}async function pb(t,e,n){const i=Qe(n,X9),r=new te(Ht,i.errorLimit);e!==null&&(bt(e,n,r,!0),Et(n,r,s$)),Tg(n,!1);const s=await l$(t,r,i,n),o=i$(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:Tg(n,s.cytoscape),graphs:j9(s,o)}}function a$(t,e,n,i){const{doc:r,dialect:s,report:o,common:l,settings:a}=t;return new hb(r,s,n,o,l,a,i).emit(s.session?e:null),s.session&&Q9(t),F(l.signal),o.finish()}function Q9(t){const e=new Set;for(const r of t.graphs){const s=so(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,`${NA(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 ej(t,e,n){const i=await pb(t,e,n),r=pl(i.graphs.map(s=>c$(s,i.doc)),n,i.report);return i.graphs.length>1&&!eo(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)`),a$(i,i.graphs[r],e)}async function tj(t,e,n){const i=await pb(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()};bt(l,n,a.report,!0),Et(n,a.report,s$),s.push(a$(a,a.graphs[o],l))}return s}async function nj(t,e){const n=await pb(t,null,e);return n.graphs.map((i,r)=>{const s=so(n.doc,n.dialect.session?i:null);return Object.freeze({index:r,name:c$(i,n.doc),nodes:new Set(s.nodes.map(o=>o.id)).size,edges:s.edges.length})})}function c$(t,e){return t.label??(t===e.root?e.rdf.title??null:null)??t.id??null}function ij(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(o$.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(wa)?.95:.5}const rj=Object.freeze({format:Ht,options:Object.freeze(["cytoscapeEscapes","labelAliases","pairSurrogateReferences","repairBareAmpersands","zAs"]),extensions:nG,mimeTypes:iG,sniff:ij,import:ej,importAll:tj,listGraphs:nj,styles:lG}),ii="cys",sj=Object.freeze([".cys"]),oj=Object.freeze(["application/zip"]),d$="cytoscape",lj="cytoscape",n_="cytoscape.selected",yu="cytoscape.hidden",aj="position@",cj=2*1024*1024*1024,dj=1e3,uj=Object.fromEntries(Object.values(j).map(t=>[t.replace(/^[EW]_/,""),t])),le=Object.freeze({...xn,...Pn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,...uj,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:hl,STYLES_NOT_IMPORTED:Zs,DANGLING_REFERENCE:Ki,EMPTY_INPUT:Mt,NO_GRAPH:rs,MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss}),u$="graphty.style.";class we extends Error{constructor(e,n){super(n),this.name="ZipError",this.kind=e}}const fj=1024*1024,f$=101010256,hj=117853008,pj=101075792,Ig=33639248,gb=67324752,Od=22,gj=65535,ms=46,fr=30,i_=56,mj=20,h$=65535,Rs=4294967295,bu=2048,Bh=1024*1024,yj={1:"shrink",6:"implode",9:"deflate64",12:"bzip2",14:"LZMA",93:"zstd",95:"xz",96:"JPEG",97:"WavPack",98:"PPMd",99:"AES encryption"};function p$(t){return t.byteLength>=4&&t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}function bj(t,e){const n=e-mj;if(n>=0&&t.getUint32(n,!0)===hj){const o=_j(t,n);return{disk:t.getUint32(o+16,!0),directoryDisk:t.getUint32(o+20,!0),count:Zl(t,o+32),directorySize:Zl(t,o+40),directoryOffset:Zl(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===h$||r===Rs||s===Rs)throw new we("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 g$(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=wj(t,e);if(n<0)throw p$(t)?new we("corrupt","the archive has no end of central directory record (truncated?)"):new we("not-zip","the input is not a zip archive");const{disk:i,directoryDisk:r,count:s,directorySize:o,directoryOffset:l,directoryEnd:a}=bj(e,n);if(i!==0||r!==0)throw new we("unsupported","a split (multi-disk) archive cannot be read");const c=a-o;if(c<0||l>t.byteLength)throw new we("corrupt","the central directory lies outside the archive");const d=c-l;if(d<0)throw new we("corrupt","the central directory offset does not match its position");const u=[];let f=c;for(let h=0;h<s;h++){if(f+ms>a||e.getUint32(f,!0)!==Ig)throw new we("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+ms+p+g+m;if(y>a)throw new we("corrupt",`central directory entry ${h+1} runs past the directory`);const b=e.getUint16(f+8,!0),_=dy(t.subarray(f+ms,f+ms+p),(b&bu)===0);let S=e.getUint32(f+20,!0),I=e.getUint32(f+24,!0),T=e.getUint32(f+42,!0);(S===Rs||I===Rs||T===Rs)&&({compressedSize:S,size:I,localOffset:T}=Sj(e,f+ms+p,g,{compressedSize:S,size:I,localOffset:T})),u.push(Object.freeze({name:_,method:e.getUint16(f+10,!0),flags:b,crc32:e.getUint32(f+16,!0),compressedSize:S,size:I,localOffset:T+d,directory:_.endsWith("/")})),f=y}if(f+4<=a&&e.getUint32(f,!0)===Ig)throw new we("corrupt",`the end record counts ${s} entries but the central directory holds more; entries would go unread`);return Ej(u,e),u}function Ej(t,e){const n=[...t].sort((r,s)=>r.localOffset-s.localOffset),i=r=>{const s=r.localOffset,l=s+fr<=e.byteLength&&e.getUint32(s,!0)===gb?e.getUint16(s+26,!0)+e.getUint16(s+28,!0):0;return s+fr+l+r.compressedSize};for(let r=1;r<n.length;r++){const s=n[r-1];if(n[r].localOffset<i(s))throw new we("corrupt",`the entries ${s.name} and ${n[r].name} overlap`)}}function wj(t,e){const n=Math.max(0,t.byteLength-Od-gj);let i=-1;for(let r=t.byteLength-Od;r>=n;r--)if(e.getUint32(r,!0)===f$){if(r+Od+e.getUint16(r+20,!0)===t.byteLength)return r;i<0&&(i=r)}return i}function _j(t,e){const n=Zl(t,e+8);for(const i of[n,e-i_])if(i>=0&&i+i_<=e&&t.getUint32(i,!0)===pj)return i;throw new we("corrupt","the zip64 end record the locator names is missing")}function Sj(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]===Rs){if(a+8>c)throw new we("corrupt","a zip64 extra field is too short");r[d]=Zl(t,a),a+=8}return r}s+=4+l}throw new we("corrupt","an entry needs a zip64 extra field it does not have")}function Zl(t,e){const n=t.getUint32(e+4,!0);if(n>=2097152)throw new we("unsupported","a zip64 size or offset beyond 2^53 cannot be read");return n*4294967296+t.getUint32(e,!0)}async function m$(t,e,n){if((e.flags&1)!==0||e.method===99)throw new we("unsupported",`${e.name}: the entry is encrypted`);if(e.method!==0&&e.method!==8){const r=yj[e.method]??`method ${e.method}`;throw new we("unsupported",`${e.name}: compression ${r} is not supported (only stored and deflate)`)}if(e.size>n.maxBytes)throw new we("too-large",`${e.name}: ${e.size} uncompressed bytes exceed the limit of ${n.maxBytes}`);if(e.size>fj&&e.size>n.maxRatio*Math.max(e.compressedSize,1))throw new we("too-large",`${e.name}: ${e.size} bytes from ${e.compressedSize} is a compression ratio above ${n.maxRatio}:1`);const i=Oj(t,e);if(e.method===0){if(i.byteLength!==e.size)throw new we("corrupt",`${e.name}: a stored entry's sizes disagree`);let r=4294967295;for(let s=0;s<i.byteLength;s+=Bh)F(n.signal),r=y$(r,i.subarray(s,Math.min(s+Bh,i.byteLength))),n.onBytes?.(Math.min(s+Bh,i.byteLength));if((r^4294967295)>>>0!==e.crc32)throw new we("corrupt",`${e.name}: the data does not match its CRC-32`);return i}return Nj(i,e,n)}function Oj(t,e){const n=new DataView(t.buffer,t.byteOffset,t.byteLength),i=e.localOffset;if(i+fr>t.byteLength||n.getUint32(i,!0)!==gb)throw new we("corrupt",`${e.name}: the local header is missing`);const r=n.getUint16(i+26,!0),s=dy(t.subarray(i+fr,Math.min(t.byteLength,i+fr+r)),(e.flags&bu)===0);if(s!==e.name)throw new we("corrupt",`${e.name}: the local header names the entry ${JSON.stringify(s)}, the central directory ${JSON.stringify(e.name)}`);const o=i+fr+r+n.getUint16(i+28,!0),l=o+e.compressedSize;if(l>t.byteLength)throw new we("corrupt",`${e.name}: the entry's data runs past the end of the archive (truncated?)`);return t.subarray(o,l)}async function Nj(t,e,n){if(typeof DecompressionStream!="function")throw new we("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 we("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 we("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 we("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 Aj=(()=>{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 y$(t,e){let n=t;for(const i of e)n=Aj[(n^i)&255]^n>>>8;return n>>>0}function Tj(t){return(y$(4294967295,t)^4294967295)>>>0}const r_=33,Hh=10;function*Ij(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+fr+c.byteLength+d.byteLength>=Rs||r===h$)throw new N("E_TOO_LARGE","the archive needs zip64, which graph-io does not write",{entry:a.name});const u=Tj(d),f=new Uint8Array(fr+c.byteLength),h=new DataView(f.buffer);h.setUint32(0,gb,!0),h.setUint16(4,Hh,!0),h.setUint16(6,bu,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,r_,!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,fr);const p=new Uint8Array(ms+c.byteLength),g=new DataView(p.buffer);g.setUint32(0,Ig,!0),g.setUint16(4,Hh,!0),g.setUint16(6,Hh,!0),g.setUint16(8,bu,!0),g.setUint16(10,0,!0),g.setUint16(12,0,!0),g.setUint16(14,r_,!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,ms),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(Od),l=new DataView(o.buffer);l.setUint32(0,f$,!0),l.setUint16(8,r,!0),l.setUint16(10,r,!0),l.setUint32(12,s,!0),l.setUint32(16,i,!0),yield o}const Ns=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}),b$=Xe({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}),$j=new Set(["label","id","position"]),Cj=Object.freeze({label:"name",id:Jo,position:Nl}),vj=new Set(["directed","pair","mutual","weight","timeText","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),Dj={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>"]])},kj={node:new Set([Nl,ro,Qt,lc,Nf,Hs,ac,Zo,_a]),edge:new Set([Jo,Qt]),network:new Set([Qt])},qn="java.lang.String",If="java.lang.Double",$g="java.lang.Integer",Eu="java.lang.Long",mb="java.lang.Boolean",Rj=2147483647,Lj=Object.freeze({...bI,block:"native"}),ls="CytoscapeSession/",Pj="Network",xj=/^[1-9]\d*$/;function E$(t){if(typeof t=="number")return Number.isSafeInteger(t)&&t>0?t:null;if(xj.test(t)){const e=Number(t);return Number.isSafeInteger(e)?e:null}return null}function Mj(t){const e=[],n=[],i=new Set;for(let r=0;r<t.nodeCount;r++){const s=E$(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 Uj(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"?E$(o):null;l!==null&&!r.has(l)&&!e.has(l)&&(r.add(l),i[s]=l)}return i}function Cg(t,e){switch(e){case"bool":return mb;case"i32":case"u8":return $g;case"u32":return jj(t)>Rj?Eu:$g;case"f32":case"f64":return/long$/i.test(t.meta.origin?.type??"")&&Gj(t)?Eu:If;default:return qn}}function w$(t,e){return t.dtype==="list"?[...t.sliceOf(e)]:[t.value(e)]}function Gj(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!w$(t,e).every(n=>typeof n=="number"&&Number.isSafeInteger(n)))return!1;return!0}function jj(t){let e=0;for(let n=0;n<t.length;n++)if(t.isSet(n))for(const i of w$(t,n))typeof i=="number"&&i>e&&(e=i);return e}function vg(t,e,n){return e===mb?t===!0?"true":"false":e===If?_r(t,n==="f32"?"f32":"f64"):e===$g||e===Eu?String(t):_$(t)}function _$(t){return typeof t=="string"?t:typeof t=="number"?je(t):typeof t=="boolean"?t?"true":"false":ArrayBuffer.isView(t)?JSON.stringify(Array.from(t).map(Fj)):JSON.stringify(t)??""}function Fj(t){return Number.isFinite(t)?t:String(t)}function Dg(t,e){const{meta:n}=t;if(t.dtype==="list"){const r=n.itemDtype,s=Cg(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=>vg(l,s,r)).join(`
51
+ `):null}}const i=n.dtype==="json"||n.components>1?qn:Cg(t,n.dtype);return{name:e,source:t,javaClass:i,cell:r=>t.isSet(r)?vg(t.value(r),i,n.dtype):null}}function zj(t,e,n){const i=new Set(["suid"]),r=[];for(const s of e){const o=s.name.toLowerCase(),l=Dj[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=Wj(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&&kj[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 Wj(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 s_(t){if(!t.includes(`
52
+ `))return[t];const e=t.split(`
53
+ `);for(;e.at(-1)==="";)e.pop();return e}function Bj(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===qn,{unset:a,equations:c,lists:d,set:u,heuristic:f}=Hj(e,r,n);if(r.dtype==="json"&&i(Ns.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(Ns.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(Ns.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(Ns.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 Hj(t,e,n){const i=t.javaClass===qn,r=t.javaClass===`java.util.List<${qn}>`,s={unset:0,equations:0,lists:0,set:0,heuristic:new Qs};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"&&Yj(e,o,l,r)&&s.lists++}return s}function Yj(t,e,n,i){const r=n??"";let s=null;i?s=r.length===0?[""]:s_(r):r.length>0&&(s=s_(r).filter(l=>l.length>0));const o=n===null?null:[...t.sliceOf(e)].map(l=>vg(l,"",null));return s===null||o===null?s!==o:s.length!==o.length||i&&s.some((l,a)=>l!==o[a])}function Vj(t){return t.meta.name===ro&&t.meta.dtype==="f64"&&t.meta.role===null}function o_(t,e,n,i,r){const s=e==="node"?t.nodes:t.edges,o=s.byRole("label"),l=[];if(o!==null){const a=Dg(o,"name");l.push({...a,javaClass:qn,cell:c=>o.isSet(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&&(vj.has(c)||c==="id")||i(a)||(l.push(Dg(a,a.meta.name)),o===null&&c===null&&a.meta.name==="name"&&Cg(a,a.dtype)===qn&&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)Bj(t,r,n,i);return zj(t,e,i)}function Kj(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 Xj(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 "${ks}" 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 qj(t,e,n){const{kept:i,bad:r}=Mj(t),s=Kj(t,n),o=r.length>0?Xj(t,r,e.sanitizeIds==="mangle",n):null,l=s??o,a=new Set(i.filter(g=>g>0)),c=Uj(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 Jj(t,e){const n=[],i=t.graph.get("name");(i===null||i.dtype!=="string"&&i.dtype!=="dict")&&n.push({name:"name",source:null,javaClass:qn,cell:()=>e});const{description:r}=t.meta;r!==null&&t.graph.get("description")===null&&n.push({name:"description",source:null,javaClass:qn,cell:()=>r});for(const s of t.graph)s.meta.name!==Z&&n.push(Dg(s,s.meta.name));return n}function l_(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=qn;s.size===1&&o==="number"?l=If:s.size===1&&o==="boolean"&&(l=mb),n.push({name:i,source:null,javaClass:l,cell:a=>{const c=r[a]??null;return c===null?null:typeof c=="number"?_r(c):String(c)}})}return n}function S$(t,e,n){const i=[],r=(ut,gh,it=null,mh=null)=>{i.push(Object.freeze({code:ut,message:gh,column:it,count:mh}))},s=Un(t,b$,e,{roles:$j,roleNames:Cj,positionDtype:"f64"});i.push(...s.filter(ut=>!Zj.has(ut.code)));const o=qj(t,e,r),{nodeSuids:l,edgeSuids:a,mangled:c,fatal:d}=o;let{next:u}=o;const f=u++,h=u++,p=Ut(t);Qj(p.mutualCount,r);const g=t.nodes.byRole("position"),m=[...t.nodes].find(Vj)??null,y=g!==null&&m===null;g!==null&&iF(g,m,r);const b=a_(g)||a_(m),_=new re,S=n===void 0?null:K1(n.rules,t,{dialect:"desktop",notes:_}),I=ut=>S!==null&&eF(ut),T=b||S!==null?u++:null,D=u,P=c?[tF(t)]:[],k=Yh("node",[...o_(t,"node",P,ut=>b&&ut===m||I(ut),r),...S===null?[]:l_(t.nodes,S.columns.node)],t.nodeCount,r),U=nF(t,r),Y=t.edgeCount,me=Yh("edge",[...o_(t,"edge",U,I,r),...S===null?[]:l_(t.edges,S.columns.edge)],Y,r),Oe=t.meta.name??Pj,Fe=Yh("network",Jj(t,Oe),1,r),J=[{name:"name",javaClass:qn,cell:()=>Oe}],Gt=n===void 0?null:Sl(n.rules,{inlineColumns:!0,snapshot:t}),Q=Gt===null?[]:sc(Gt,n?.rules.styles.rules.length??0,"size");return{notes:i,fatal:d,nodeSuids:l,edgeSuids:a,rootSuid:f,subSuid:h,viewSuid:T,viewNodeBase:D,name:Oe,folding:p,nodeTable:k,edgeTable:me,networkTable:Fe,rootTable:J,position:g,z:b?m:null,positionZ:y,styled:S,styleNotes:[..._.list().map(ob),...Q],block:n===void 0?sb(t):Gt}}const Zj=new Set([w.JSON,w.ID_CHARSET,w.ID_MANGLED]);function Qj(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 a_(t){return t!==null&&t.nullCount<t.length}function eF(t){return t.dtype==="json"&&t.meta.origin?.type==="graphics"&&t.meta.origin.namespace===hn}function tF(t){return{name:ks,source:null,javaClass:qn,cell:e=>String(t.ids.idOf(e))}}function nF(t,e){const n=wt(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:If,cell:r=>n.isExplicit(r)?_r(n.value(r)):null}]:[]}function iF(t,e,n){const{name:i,components:r}=t.meta;r!==3&&n(Ns.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(Ns.POSITION,`${s} position${O(s)} with a non-finite coordinate ${C(s,"is","are")} not written`,i,s),o>0&&n(Ns.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 jc(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*Fc(t,e,n){const i=r=>`${r.map(s=>s===null?"":ff(s)).join(",")}
54
+ `;yield i(["CyCSV-Version","1"]),yield i(["SUID",...e.map(r=>r.name)]),yield i([Eu,...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(u$)?null:""))])}const yb=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
55
+ `,O$=`xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="${nb}" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cy="${dI}" xmlns="${wa}"`;function*rF(t,e){const n=Fs(e.name)?"":` label="${W(e.name)}"`;yield yb,yield`<graph id="${e.rootSuid}"${n} directed="${t.directed?"1":"0"}" cy:view="0" cy:registered="0" cy:documentVersion="3.0" ${O$}>
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*sF(t,e,n){const i=e.styled===null?"default":e.name;yield yb,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" ${O$}>
64
+ `;let r=e.viewNodeBase;for(let s=0;s<t.nodeCount;s++){const o=oF(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*c_(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*c_([],o),yield` </edge>
68
+ `)}yield`</graph>
69
+ `}function*c_(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 oF(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"?lt:je;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="${_r(t.z.value(e))}"`),n}function as(t){let e="";for(const n of t)e+=n;return new TextEncoder().encode(e)}function*lF(t,e){if(e.fatal!==null)throw e.fatal;const n=jc(e.name),i=`${ls}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:`${ls}3.0.0.version`,data:new Uint8Array(0)},yield{name:`${ls}networks/${e.rootSuid}-${n}.xgmml`,data:as(rF(t,e))},yield{name:`${i}CyNode-${jc(s)}.cytable`,data:as(Fc(s,e.nodeTable,r(e.nodeSuids)))},yield{name:`${i}CyEdge-${jc(o)}.cytable`,data:as(Fc(o,e.edgeTable,r(e.edgeSuids,a=>e.folding.folded(a))))},yield{name:`${i}CyNetwork-${jc(l)}.cytable`,data:as(Fc(l,e.networkTable,[[e.subSuid,0]]))},yield{name:`${ls}tables/${e.rootSuid}-${n}/LOCAL_ATTRS-org.cytoscape.model.CyNetwork-${e.rootSuid}+default+network.cytable`,data:as(Fc(`${e.rootSuid} default network`,e.rootTable,[[e.rootSuid,0]]))},e.viewSuid!==null&&(yield{name:`${ls}views/${e.subSuid}-${e.viewSuid}-${n}.xgmml`,data:as(sF(t,e,e.viewSuid))}),e.styled!==null&&(yield{name:`${ls}session_vizmap.xml`,data:as([yb,`<vizmap documentVersion="3.0" id="VizMap-graphty">
76
+ `,l5(e.styled.style,e.name),`
77
+ </vizmap>
78
+ `])}),e.block!==null&&(yield{name:`${ls}${Z}`,data:new TextEncoder().encode(e.block)})}async function*aF(t,e){const n=S$(t,dt(e),e?.styles);await Promise.resolve(),yield*Ij(lF(t,n))}const cF=Object.freeze({format:ii,options:Object.freeze([]),capabilities:b$,styles:Object.freeze({capabilities:Lj}),check(t,e){const n=S$(t,dt(e),e?.styles);return Object.freeze([...n.notes,...n.styleNotes])},export(t,e){return aF(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 Ls(t){const e=t.replaceAll("+"," ");try{return decodeURIComponent(e)}catch{return e}}async function dF(t,e,n,i){const r=await jA(t,n);r===null&&e.fail(le.NOT_ZIP,"a Cytoscape session is a zip archive; text input cannot hold one (pass the bytes)"),r.byteLength===0&&e.fail(le.EMPTY_INPUT,"the input is empty");let s;try{s=g$(r)}catch(u){return d_(u,e)}const o=gF(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 m$(r,u.zip,{signal:n.signal,maxBytes:h?l:u.zip.size,maxRatio:dj,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 d_(g,f)}},done:()=>{n.onProgress?.(c,c)}}}function d_(t,e){if(!(t instanceof we))throw t;const n={"not-zip":le.NOT_ZIP,corrupt:le.CORRUPT,unsupported:le.UNSUPPORTED,"too-large":le.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 u_(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 uF=/^networks\/(\d+)(?:-([^/]*))?\.xgmml$/,fF=/^views\/(\d+)-(\d+)(?:-[^/]*)?\.xgmml$/,hF=/^tables\/((\d+)(?:-[^/]*)?\/([^/-]+)-([^/-]+)-[^/]*\.cytable)$/,pF=/(^|\/)(__MACOSX\/|\.DS_Store$)/;function gF(t,e){const n=new Map,i=[];for(const h of t){const p=h.name.replaceAll("\\","/");if(!(p.endsWith("/")||pF.test(p))){if(n.has(p)){i.push(p);continue}n.set(p,h)}}i.length>0&&e.warning("unsupported",le.DUPLICATE_ENTRY,`${i.length} entry name${O(i.length)} appear more than once; the first of each is read: ${el(i)}`);const r=[...n.keys()],s=u_(r,/(^|\/)[^/]+\.version$/),o=s.at(0),l=u_(r,/(^|\/)cysession\.xml$/).at(0);s.length>1&&e.warning("validation-error",le.ENTRY_SKIPPED,`the session has ${s.length} version markers (${el(s)}); ${s[0]} is used and the others are not read`);const a=o??l;a===void 0&&e.fail(le.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(le.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(le.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"?mF(m,f):yF(m,f)}return f}function mF(t,e){const{path:n}=t,i=uF.exec(n),r=fF.exec(n),s=hF.exec(n);if(i!==null)e.networks.push({...t,suid:i[1],title:Ls(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"}[Ls(s[4])];if(o===void 0){e.skipped.push(t.name);return}e.tables.push({...t,tablePath:s[1],network:s[2],namespace:Ls(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 yF(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 el(t){const e=t.slice(0,10).map(mn).join(", ");return t.length>10?`${e} and ${t.length-10} more`:e}function mn(t){return t.replace(/^[^/]*CytoscapeSession[^/]*\//,"")}async function bF(t,e,n,i){const r=await $f(t,e,n,i);return typeof r=="string"?n.fail(le.CORRUPT,`${e}: ${r}`):r}async function $f(t,e,n,i){const r=new te(ii,0),s=[{name:"",attrs:new Map,children:[]}];try{await uf(Nr(t,r,{signal:i.signal,declaredEncoding:df,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 ee||l instanceof tt)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 bb(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 EF(t,e){const n=e.kept;if(n?.era==="2")return pI(t,e,{tool:"cytoscape-fallbacks",hiddenColumn:yu});const i=new re,r=wF(n,i),s={node:{values:{}},edge:{values:{}}};for(const o of["node","edge"])e.signal?.throwIfAborted(),o==="edge"&&z1(r.edge,n?.weightFrom??null,t.edges),s[o]=_F(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:yI(t,i,r),notes:i.list()}}function wF(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"}),io()}return SF(t.vizmap,t.visualStyle,e)}function _F(t,e,n,i,r){const{notes:s}=i,o=e==="node"?t.nodes:t.edges,l=e==="node"?t.nodeCount:t.edgeCount;F1(n[e],f=>o.has(f)),W1(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)?mf(o,f,h):null,bypasses:hI(o,e,l,s),...e==="edge"?{ends:Sf(t,r)}:{}},c=Qy(e,n,a,i);gI(o,yu,l,c),mI(t,e,r,c),ib(t,e,c);const{rules:d,columns:u}=cI(e,n,a,i);return{values:rb(c),rules:d,columns:u}}function SF(t,e,n){const i=io(),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??[])OF(i,o,a)}return i}function OF(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=NF(n);s!==null&&t[e].mappings.set(i,s)}}function NF(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:AF(e,i)};if(e.name==="continuousMapping")return{kind:"continuous",column:n,type:i,points:TF(e)}}return null}function AF(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 TF(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 f_={"java.lang.String":"String","java.lang.Long":"Long","java.lang.Integer":"Integer","java.lang.Double":"Double","java.lang.Boolean":"Boolean"},IF=/^java\.util\.List<\s*([\w.]+)\s*>$/;async function $F(t,e,n,i,r){const s=await CF(t,r);if(typeof s=="string")return Vh(i,n,s);const o=vF(s);if(typeof o=="string")return Vh(i,n,o);const l=DF(s[o.at].cells,s[o.at+1].cells);if(typeof l=="string")return Vh(i,n,l);const{rows:a,lines:c,quotedEmpty:d,problems:u}=kF(s.slice(o.at+o.lines),l.length);return u.short+u.long+u.repeated>0&&i.warning("parse-error",le.TABLE_ROW,`${mn(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 CF(t,e){const n=new te(ii,0),i=new cT(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 tt)return n.issues.at(-1)?.message??s.message;throw s}return r}function vF(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 DF(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=RF(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 kF(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 RF(t,e){const n=f_[e.trim()];if(n!==void 0)return{name:t,type:n,list:!1};const i=IF.exec(e.trim()),r=i===null?void 0:f_[i[1]];return r===void 0?null:{name:t,type:r,list:!0}}function Vh(t,e,n){return t.error("parse-error",le.TABLE,`${mn(e)}: ${n}; the table is not read`),null}function N$(t,e,n,i,r,s=!1){const o={line:n,namespace:i,hidden:r};if(e.startsWith("="))return zc(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(u$))?null:zc(t.name,t.type,null,e,!1,o);if(e.length===0&&t.type!=="String")return null;const l=zc(t.name,"List",t.type,null,!1,o);for(const a of LF(e))a.length===0&&t.type!=="String"||l.children.push(zc(t.name,t.type,null,a,!1,o));return l}function LF(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 zc(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 PF(t,e,n,i){const r=[];for(const s of e){if(s.targetTable!==t.path)continue;const o=await A$(s,e,n,new Set);if(typeof o=="string"){i.error("parse-error",le.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",le.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 A$(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 A$(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 xF={ids:"keep",defaultDirected:!0,weightFrom:"weight",addMissingNodes:!1},T$=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","errorLimit","signal","onProgress"]);function MF(t){if(t===void 0)return cj;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 Eb(t,e,n){const i=Qe(n,xF),r=new te(ii,i.errorLimit);e!==null&&(bt(e,n,r,!0),Et(n,r,T$));const{zAs:s}=Tg({zAs:n?.zAs},!1),o=MF(n?.maxUncompressedBytes),l=await dF(t,r,i,o),a=Object.freeze({...i,onProgress:null,encoding:null}),c=new Map,d=l.layout.era==="3"?await UF(l,r,a,c):await sz(l,r,a);return{report:r,common:i,inner:a,zAs:s,session:l,choices:d,docs:c}}async function I$(t,e,n,i){return await $$(t,e,n,i,!1)}async function $$(t,e,n,i,r){const s=new te(ii,Math.max(0,n.errorLimit-n.errorCount));try{const o=await t.read(e,s),l=await l$(o,s,i,void 0),a=i$(l,s);return Kh(s.issues,n,e.name),h_(s,n),{doc:l,dialect:a}}catch(o){if(!(o instanceof tt))throw o;h_(s,n);const{issues:l}=s;s.truncated&&Kh(l,n,e.name);const a=l.at(-1);Kh(l.slice(0,-1),n,e.name);const c=`${mn(e.name)}: ${a?.message??o.message}`,d={line:a?.line??null};if(a?.code===le.TOO_LARGE)throw n.error("unsupported",a.code,c),n.abort(c,{code:a.code});return r?(n.error("parse-error",a?.code??le.CORRUPT,`${c}; the entry is not read`,d),null):n.fail(a?.code??le.CORRUPT,c,d)}}function h_(t,e){for(const n of Object.keys(t.counts))e.counts[n]+=t.counts[n]}function Kh(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,`${mn(n)}: ${i.message}`,r):e.warning(i.category,i.code,`${mn(n)}: ${i.message}`,r)}}async function UF(t,e,n,i){const{layout:r}=t,s=[];for(const u of r.networks){const f=await I$(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 C$(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=so(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)&&!GF(u,t,i));if((l.length>0||a.length>0)&&e.warning("validation-error",le.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: ${el([...l,...a.map(u=>u.name)])}`),r.networkList===null)return s;const c=await $f(await t.read(r.networkList,e),r.networkList.name,e,n);if(typeof c=="string")return e.warning("unsupported",le.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 bb(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 GF(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 C$(t){const e=t.doc.root.subgraphs.filter(n=>wi(n.registered));return e.length===0&&wi(t.doc.root.registered)?[t.doc.root]:e}async function jF(t,e,n,i){const{graph:r}=e,s=so(i.doc,r),o=p_(s.nodes),l=p_(s.edges),a=FF(r,o,l);try{return await zF(t,e,n,i,o,l)}finally{a()}}function FF(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 zF(t,e,n,i,r,s){const{report:o,inner:l}=t,{doc:a,dialect:c}=i,{graph:d}=e,u=so(a,d),f=await HF(t,e,a,r,s);f>0&&o.warning("parse-error",le.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?ez(u.nodes):new Map,{visualStyle:p,extraViews:g,extraIds:m}=await XF(t,e,r,s),y=t.session.layout.block===null?null:await az(t,t.session.layout.block);y!==null&&d.atts.push(cz(Z,y));const b=k$(t,{collection:a.root.label??e.network.title,network:e.graphId,parentNetwork:nz(d,t.choices),visualStyle:p}),_=[];b.groups=_;const S={sourceFormat:ii,entry:e.network.name,graphName:tz(d)??e.name,metaExtra:{[d$]:b},labelFromName:!0,restoredIds:h,groupNodes:WF(u.nodes),resolvePointer:iz(t,a),onMissingMember:(T,D)=>{BF(_,T,D)}},I={labelAliases:!1,cytoscapeEscapes:!1,zAs:t.zAs};if(new hb(a,c,n,o,t.inner,I,S).emit(d),_.length>0){const T=_.reduce((D,P)=>D+P.members.length,0);o.warning("unsupported",le.COLLAPSED_GROUP,`${_.length} collapsed group${O(_.length)} ${C(_.length,"holds","hold")} ${T} member${O(T)} that are not in the network; they are listed in meta.extra.cytoscape.groups`)}return rz(i,o,e.network.name),QF(n,g,m,o,t.inner,h),p}function WF(t){return new Set(t.filter(e=>e.atts.some(n=>n.name==="__isGroup"&&wi(n.value))).flatMap(e=>e.id===null?[]:[e.id]))}function BF(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 HF(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=>$F(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 qF(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 YF(u,h,p))}return f}async function YF(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(...VF(n,a,c,r,s)):t.declared.has(a)||l++}for(const a of await PF(n,t.virtuals,t.tableOf,t.report)){const c=n.columns.some(u=>u.name===a.column.name),d=i?KF(c):r;for(const[u,f]of a.values){const h=o(u);h!==void 0&&v$(h,N$(a.column,f,n.lines.get(u)??0,d,s))}}return l}function VF(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;v$(o,N$(t.columns[l],n[l],s,i,r,a))}return o}function KF(t){return t?"SHARED_ATTRS":null}function v$(t,e){e!==null&&t.push(e)}async function XF(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 $$(o,f,r,s,!0))?.doc;h!==void 0&&(u?(u=!1,a=h.root.attrs.get("cy:visualStyle")??null,JF(h,e.graph,n,i,r,f.name)):(c.push(ZF(h,t.zAs,n,r,f.name)),d.push(f.view)))}return{visualStyle:a,extraViews:c,extraIds:d}}async function qF(t,e,n,i){const r=await $f(await t.read(e,n),e.name,n,i);if(typeof r=="string")return n.error("parse-error",le.TABLE,`${mn(e.name)}: ${r}; its virtual columns are not read`),[];const s=[];for(const o of bb(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",le.TABLE,`${mn(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 p_(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 JF(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}D$(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",le.DANGLING_REFERENCE,`${mn(s)}: ${o} view element${O(o)} ${C(o,"names","name")} no node or edge of the network; they are not read`)}function D$(t,e,n,i){const r=e.viewId;t.has(r)&&n.warning("validation-error",j.DUPLICATE_NODE,`${mn(i)}: the view gives node "${r}" twice; the later element is used`,{line:e.line,element:r}),t.add(r)}function ZF(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=r$(c);return u===null&&i.error("validation-error",j.BAD_VALUE,`${mn(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}D$(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",le.DANGLING_REFERENCE,`${mn(r)}: ${l} view element${O(l)} ${C(l,"names","name")} no node of the network; they are not read`),s}function QF(t,e,n,i,r,s){const o=new Mn(r.ids);e.forEach((l,a)=>{const c=`${aj}${a+2}`,{handle:d}=fe(t,"node",{name:c,dtype:"f32",components:3,nullable:!0,origin:{format:ii,id:n[a],title:null,type:"graphics",namespace:hn},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 ez(t){const e=new Map;for(const n of t){const i=n.atts.findIndex(r=>r.name===ks&&(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 tz(t){return t.atts.find(n=>n.name==="name"&&(n.namespace??null)===null)?.value??null}function nz(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 iz(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=Ls(r.slice(0,s)),l=r.slice(s+1),a=t.session.layout.networks.find(u=>Ls(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 rz(t,e,n){const i=new Set;for(const o of C$(t)){const l=so(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,`${mn(n)}: ${NA(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 sz(t,e,n){const{layout:i}=t;if(i.cysession===null)return e.fail(le.NOT_SESSION,"the session has no cysession.xml");const r=await bF(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(le.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(Ls(f),h);const l=[...i.files.values()],a=[],c=[],d=new Set;for(const f of bb(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){Xh(e,i.cysession.name,"a <network> has neither an id nor a filename; it is not read");continue}const g=h??Ls(p.replace(/\.xgmml$/i,""));h===void 0&&Xh(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)){Xh(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",le.DANGLING_REFERENCE,`cysession.xml names ${c.length} network file${O(c.length)} the session does not hold: ${el(c)}`);const u=l.filter(f=>!d.has(f)).map(f=>f.name);return u.length>0&&e.warning("unsupported",le.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: ${el(u)}`),a.sort((f,h)=>l.indexOf(f.file)-l.indexOf(h.file))}function Xh(t,e,n){t.warning("validation-error",le.SESSION_RECORD,`${mn(e)}: ${n}`)}async function oz(t,e,n){const{report:i,inner:r,session:s}=t,{doc:o,dialect:l}=await I$(s,e.file,i,r);let a=0;for(const[f,h]of[["selectedNodes",n_],["hiddenNodes",yu]])a+=m_(o.nodes,g_(e.record,f),h);for(const[f,h]of[["selectedEdges",n_],["hiddenEdges",yu]])a+=m_(o.edges,g_(e.record,f),h);a>0&&i.warning("validation-error",le.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=k$(t,{collection:null,network:e.name,parentNetwork:e.parent,visualStyle:e.record.attrs.get("visualStyle")??null}),d={sourceFormat:ii,entry:e.file.name,graphName:e.name,metaExtra:{[d$]:c}},u={labelAliases:!0,cytoscapeEscapes:!0,zAs:t.zAs};return new hb(o,l,n,i,r,u,d).emit(null),c.visualStyle}function g_(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 m_(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:lj});return e.size-i.size}function k$(t,e){const{layout:n}=t.session,{report:i}=t;return n.styles.length>0&&i.warning("unsupported",le.STYLES_NOT_IMPORTED,`the session's styles (${n.styles.map(r=>r.path).join(", ")}) are not applied`),n.skipped.length>0&&i.warning("unsupported",le.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): ${el(n.skipped)}`),{sessionVersion:n.version,...e,skippedEntries:[...n.skipped]}}async function R$(t,e,n){const i=t.choices[e];let r;if(i.era==="3"){const s=t.docs.get(i.network.name);r=await jF(t,i,n,s)}else r=await oz(t,i,n);return await lz(t,e,r),F(t.common.signal),t.report.finish()}async function lz(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 L$(t,r),c=typeof a=="string"?a:await $f(a,r.name,new te(ii,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 L$(t,e){try{return await t.session.read(e,new te(ii,0))}catch(n){if(n instanceof tt)return n.message;throw n}}async function az(t,e){const n=await L$(t,e);if(typeof n=="string")return null;try{return await Br(n,new te(ii,0),{signal:t.common.signal})}catch(i){if(i instanceof tt)return null;throw i}}function cz(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 dz(t,e,n){const i=await Eb(t,e,n),r=pl(i.choices.map(o=>o.name),n,i.report);i.choices.length>1&&!eo(n)&&i.report.warning("unsupported",le.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 R$(i,r,e);return i.session.done(),s}async function uz(t,e,n){const i=await Eb(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()};bt(l,n,a.report,!0),Et(n,a.report,T$),s.push(await R$(a,o,l))}return i.session.done(),s}async function fz(t,e){return(await Eb(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 hz=[/CytoscapeSession|cysession\.xml/,new RegExp("(?<!\\d)\\d+\\.\\d+\\.\\d+\\.version"),/(?:^|\/)apps\/org\.cytoscape\./,/(?:^|\/)(?:networks|views)\/\d+-[^/]*\.xgmml/,/(?:^|\/)tables\/\d+-[^/]*\/[^/]+\.cytable/];function pz(t){for(let e=0;e+4<=t.byteLength;e++)if(p$(t.subarray(e)))return hz.some(n=>n.test(dy(t.subarray(e))))?.95:0;return 0}const gz=Object.freeze({format:ii,options:Object.freeze(["maxUncompressedBytes","zAs"]),extensions:sj,mimeTypes:oj,sniff:pz,import:dz,importAll:uz,listGraphs:fz,styles:EF});class Al{#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 Or(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Ui(t){const e=t.indexOf(":");return e<0?t:t.slice(e+1)}function yt(t,e){const n=[];if(!Or(t))return n;for(const i of Object.keys(t)){if(i.startsWith("@_")||i==="#text"||Ui(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 ce(t,e){if(Or(t)){for(const n of Object.keys(t))if(!n.startsWith("@_")&&n!=="#text"&&Ui(n)===e){const i=t[n];return Array.isArray(i)?i[0]:i}}}function R(t,e){if(!Or(t)||!Object.hasOwn(t,`@_${e}`))return;const n=t[`@_${e}`];return typeof n=="string"?n:void 0}function wb(t){if(typeof t=="string")return t;if(Or(t)&&Object.hasOwn(t,"#text")){const e=t["#text"];return typeof e=="string"?e:null}return null}function kg(t){const e=[];for(const n of t)n.dtype==="json"&&n.meta.origin?.namespace==="yfiles"&&e.push(n.meta.name);return e}function Rg(t){const e=[];for(const n of t)n.meta.origin?.namespace==="yfiles"&&e.push(n.meta.name);return e}const _b=new Set(["ShapeNode","GenericNode","GroupNode","GenericGroupNode","SVGNode","ImageNode","TableNode","UMLClassNode","UMLNoteNode","ProxyAutoBoundsNode"]),Sb=new Set(["PolyLineEdge","ArcEdge","BezierEdge","QuadCurveEdge","SplineEdge","GenericEdge"]);function Cf(t,e){if(!Or(t))return null;for(const n of Object.keys(t)){const i=Ui(n);if(n.startsWith("@_")||!e.has(i))continue;const r=t[n],s=Array.isArray(r)?r[0]:r;return i==="ProxyAutoBoundsNode"?mz(s):{type:i,r:s}}return null}function mz(t){const e=ce(t,"Realizers"),n=[];if(Or(e))for(const r of Object.keys(e).filter(s=>!s.startsWith("@_")&&s!=="#text"))for(const s of yt(e,Ui(r)))n.push({type:Ui(r),r:s});const i=Number(R(e,"active")??"0");return n[Number.isInteger(i)&&i>=0&&i<n.length?i:0]??null}function Pr(t,e,n,i,r,s,o=12){return Array.from({length:o+1},(l,a)=>{const c=r+(s-r)*a/o;return Ob(t+n*Math.cos(c),e+i*Math.sin(c))})}function qh(t,e,n,i){return Array.from({length:17},(s,o)=>{const l=n+(i-n)*o/16;return Ob(l,t+e*Math.sin(Math.PI*l))})}function Ob(t,e){const n=i=>String(Math.round(i*1e3)/1e3+0);return`${n(t)},${n(e)}`}const Wt=Math.PI/2,yz=Array.from({length:72},(t,e)=>{const n=2*Math.PI*e/72,i=.86+.14*Math.abs(Math.cos(4*n));return Ob(i*Math.cos(n),i*Math.sin(n))}).join(" "),bz=[...Pr(.5,0,.5,1,-Wt,Wt),...Pr(-.5,0,.5,1,Wt,3*Wt)].join(" "),Ez=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",...qh(-.75,.2,-1,1),"1,1"].join(" ")}],["flowchart.papertype",{shape:"polygon",points:[...qh(-.8,.2,-1,1),...qh(.8,.2,1,-1)].join(" ")}],["flowchart.delay",{shape:"polygon",points:["-1,-1",...Pr(0,0,1,1,-Wt,Wt),"-1,1"].join(" ")}],["flowchart.display",{shape:"polygon",points:["-1,0","-0.6,-1",...Pr(.6,0,.4,1,-Wt,Wt),"-0.6,1"].join(" ")}],["flowchart.storeddata",{shape:"polygon",points:[...Pr(1,0,-.2,1,-Wt,Wt),...Pr(-.8,0,.2,1,Wt,3*Wt)].join(" ")}],["flowchart.directdata",{shape:"polygon",points:[...Pr(.8,0,.2,1,-Wt,Wt),...Pr(-.8,0,.2,1,Wt,3*Wt)].join(" ")}],["flowchart.cloud",{shape:"polygon",points:yz}],["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:bz}],["sbgn.tag",{shape:"polygon",points:"-1,1 -1,-1 0.6,-1 1,0 0.6,1"}]]);function vf(t){const e=t.slice(0,De).toLowerCase().replace(/^com\.yworks\./,"").replace(/\.withshadow$/,"");return Ez.get(e)??null}const wz=[["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"]],_z=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"]]),P$=new Map([["plain",["normal",!1]],["bold",["bold",!1]],["italic",["normal",!0]],["bolditalic",["bold",!0]]]);function Mo(t,e,n,i,r){const s=$e(t,"yed",r(e));if(s===null)return;i(e,s.color);const o=_l(s,null,r(e),n!==null);n!==null&&i(n,o)}function x$(t,e,n,i,r){let s,o="",l=0;for(const a of t){const c=wb(a)?.trim()??"";c.length===0||R(a,"visible")==="false"||R(a,"hasText")==="false"||(s===void 0?(s=a,o=c):l++)}s!==void 0&&(l>0&&B(i("label"),v.EXTRA_LABELS,`${String(l+1)} labels`),n("label",nt(o,i("label"))),Sz(s,e,n,i,r))}function Sz(t,e,n,i,r){Mo(R(t,"textColor"),"labelColor",null,n,i),R(t,"hasBackgroundColor")!=="false"&&Mo(R(t,"backgroundColor"),"labelBackground",null,n,i),R(t,"hasLineColor")!=="false"&&R(t,"lineColor")!==void 0&&(Mo(R(t,"lineColor"),"labelBorderColor",null,n,i),n("labelBorderWidth",1)),n("labelSize",V(R(t,"fontSize"),i("labelSize")));const s=nt(R(t,"fontFamily"),i("labelFont"));n("labelFont",s===null?null:wf(s));const o=R(t,"fontStyle");if(o!==void 0){const l=P$.get(o.trim().toLowerCase());l===void 0?B(i("labelWeight"),v.UNKNOWN_VALUE,o.slice(0,De)):(n("labelWeight",l[0]),n("labelItalic",l[1]))}if(Oz(t,n,i),e){const l=Tz(t,r,i);n("labelPosition",l),Az(t,r,l,n),Nz(t,r,l,n)}}function Oz(t,e,n){const i=Ea(R(t,"rotationAngle"),n("labelRotation"));if(i===null)return;const r=(i%360+360)%360;e("labelRotation",r===0?null:r)}function Nz(t,e,n,i){const r=R(t,"modelName"),s=n==="center"&&r!==void 0&&r!=="internal";if(n===null||n.startsWith("inside-")||n==="center"&&!s||Number(R(t,"rotationAngle")??0)%360!==0)return;const o=(g,m)=>Number(R(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 Az(t,e,n,i){const r=R(t,"autoSizePolicy")?.startsWith("node_")===!0;if(n?.startsWith("inside-")!==!0||r)return;const s=(h,p)=>Number(R(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 Tz(t,e,n){const i=Cz(t,e);if(i!==null&&i!=="center")return i;const r=R(t,"modelPosition"),s=R(t,"modelName");if(s==="internal")return vz(t,r);if(s==="custom")return Iz(t,i,n);if(i!==null||r===void 0)return i;const o=_z.get(r.trim().toLowerCase());return o===void 0&&B(n("labelPosition"),v.UNKNOWN_VALUE,r.slice(0,De)),o??null}function Iz(t,e,n){const i=ce(ce(t,"ModelParameter"),"SmartNodeLabelModelParameter");return i===void 0?(B(n("labelPosition"),v.UNKNOWN_VALUE,"custom"),e):e??$z(i)}function $z(t){const e=r=>{const s=Number(R(t,r));return Number.isFinite(s)?s:0},n=y_(e("nodeRatioX"),"left","right"),i=y_(e("nodeRatioY"),"top","bottom");return i==="top"&&n===""&&e("labelRatioY")<=0?"inside-top":i===""||n===""?i+n||"center":`${i}-${n}`}function y_(t,e,n){return t<0?e:t>0?n:""}function Cz(t,e){const n=(d,u)=>Number(R(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 Dz[c(r,o,a)+1][c(i,s,l)+1]}function vz(t,e){const n=M$.get((e??"c").trim().toLowerCase())??"center",i=R(t,"alignment");return R(t,"autoSizePolicy")==="node_width"&&(i==="left"||i==="right")&&(n==="inside-top"||n==="inside-bottom")?`${n}-${i}`:n}const M$=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"]]),Dz=[["top-left","top","top-right"],["left","center","right"],["bottom-left","bottom","bottom-right"]];function kz(t,e){const n=ce(t.r,"Shape");if(n!==void 0)return oe("shape",R(n,"type"),"yed",e("shape"));if(t.type==="ShapeNode"||t.type==="GroupNode"||t.type==="GenericGroupNode")return null;if(t.type==="TableNode")return oe("shape","rectangle","yed",e("shape"));if(t.type==="GenericNode"){const i=R(t.r,"configuration")??"",r=vf(i);if(r!==null)return r.shape;const s=i.slice(0,De).toLowerCase();for(const[o,l]of wz)if(s.includes(o))return l;return s.length===0?null:(B(e("shape"),v.UNKNOWN_VALUE,s),`other:${s}`)}return B(e("shape"),v.UNKNOWN_VALUE,t.type),`other:${t.type}`}const U$=45;function Rz(t,e,n){const i=ce(t.r,"Fill");if(i===void 0)return;if(R(i,"hasColor")==="false"||R(i,"transparent")==="true"){B(n("fill"),v.NO_FILL,"transparent"),e("fillOpacity",0);return}Mo(R(i,"color"),"fill","fillOpacity",e,n);const r=$e(R(i,"color2"),"yed",n("fillGradient"));r!==null&&(e("fillGradient",r.color),e("fillGradientAngle",U$))}function Jh(t,e,n){const r=yt(ce(t.r,"StyleProperties"),"Property").find(s=>R(s,"name")===e);return r===void 0?null:$e(R(r,"value"),"yed",n("stripeColors"))?.color??null}function Lz(t,e,n){const i=ce(t.r,"Table"),r=yt(ce(i,"Rows"),"Row"),s=yt(ce(i,"Columns"),"Column"),o=s.length>1&&r.length<=1,l=(o?s:r).map(_=>Number(R(_,o?"width":"height"))),a=ce(i,"Insets"),c=_=>Math.max(0,Number(R(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=$e(R(ce(t.r,"Fill"),"color"),"yed",n("stripeColors"))?.color??"#ffffff",g=Jh(t,"yed.table.lane.color.main",n)??p,m=Jh(t,"yed.table.lane.color.alternating",n)??g,y=Jh(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 Pz(t){const e=new Map;for(const n of t.graph)n.dtype!=="json"||n.meta.origin?.namespace!=="yfiles"||xz(K(t.graph.value(n.meta.name,0)),e);return e}function xz(t,e){for(const n of yt(t,"Resources"))for(const i of yt(n,"Resource")){const r=R(i,"id"),s=r===void 0||e.has(r)?null:Mz(i);r!==void 0&&s!==null&&e.set(r,s)}}function Mz(t){const e=wb(t)?.trim()??"";return e===""?null:(R(t,"type")??"").endsWith("BufferedImage")?`data:image/png;base64,${e.replaceAll(/\s+/g,"")}`:e.includes("<svg")?`data:image/svg+xml;utf8,${encodeURIComponent(e)}`:null}function Uz(t,e,n){const i=t.type==="ImageNode"?R(ce(t.r,"Image"),"refid"):R(ce(ce(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 G$(t,e,n,i){const{r}=t;Rz(t,e,n);const s=ce(r,"BorderStyle");s!==void 0&&(R(s,"hasColor")==="false"?e("borderWidth",0):(Mo(R(s,"color"),"borderColor",null,e,n),e("borderWidth",V(R(s,"width"),n("borderWidth")))),e("borderStyle",oe("borderStyle",R(s,"type"),"yed",n("borderStyle"))));const o=ce(r,"Geometry");e("width",V(R(o,"width"),n("width"))),e("height",V(R(o,"height"),n("height"))),e("shape",kz(t,n));const l=t.type==="GenericNode"?vf(R(r,"configuration")??"")?.points:void 0;l!==void 0&&e("shapePoints",l),t.type==="TableNode"&&Lz(t,e,n),i!==void 0&&(t.type==="ImageNode"||t.type==="SVGNode")&&Uz(t,i,e),x$(yt(r,"NodeLabel"),!0,e,n,o)}function j$(t,e,n){const{r:i}=t,r=ce(i,"LineStyle");r!==void 0&&(Mo(R(r,"color"),"color","opacity",e,n),e("width",V(R(r,"width"),n("width"))),e("lineStyle",oe("lineStyle",R(r,"type"),"yed",n("lineStyle"))));const s=ce(i,"Arrows");s!==void 0&&(e("sourceArrow",oe("arrow",R(s,"source"),"yed",n("sourceArrow"))),e("targetArrow",oe("arrow",R(s,"target"),"yed",n("targetArrow")))),e("curved",Gz(t)),t.type==="ArcEdge"&&e("bendCurve","arc"),x$(yt(i,"EdgeLabel"),!1,e,n)}function Gz(t){if(t.type==="ArcEdge")return!0;const e=yt(ce(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=R(ce(t.r,"BendStyle"),"smoothed");return i===void 0?null:i==="true"&&n}function jz(t,e,n,i,r){const s=ce(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(R(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:zs(o(f),l(f),[h],!0);r("sourcePort",d(n,c[0])),r("targetPort",d(i,c[1]));let u=yt(s,"Point").map(f=>[Number(R(f,"x")),Number(R(f,"y"))]);if(u.length>0&&(t.type==="BezierEdge"||t.type==="QuadCurveEdge")){const f=[c[0],...u,c[1]];u=((t.type==="BezierEdge"?_f(f):j1(f,Number(R(t.r,"straightness")??Fz)))??f).slice(1,-1)}r("bends",n===i?zs(o(n),l(n),u,!0):Ol(o(n),o(i),u,!0))}const Fz=.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 zz(t,e,n){let i=!1;const r=Pz(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"?_b:Sb,h=kg(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=Cf(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"){G$(m,b,y,r);const _=ce(m.r,"Geometry"),[S,I]=[Number(R(_,"width")),Number(R(_,"height"))];s.set([Number(R(_,"x"))+S/2,Number(R(_,"y"))+I/2,S,I],4*g)}else j$(m,b,y),jz(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 Na=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"}),F$=new Map([["ellipse","ellipse"],["rectangle","rectangle"],["round-rectangle","roundrectangle"],["triangle","triangle"],["diamond","diamond"],["hexagon","hexagon"],["octagon","octagon"],["parallelogram","parallelogram"],["trapezoid","trapezoid"],["star","star5"]]),Nb=new Map([["solid","line"],["dashed","dashed"],["dotted","dotted"],["dash-dot","dashed_dotted"]]),z$=new Map([["none","none"],["triangle","standard"],["triangle-open","white_delta"],["vee","concave"],["tee","t_shape"],["diamond","diamond"],["diamond-open","white_diamond"],["circle","circle"],["circle-open","white_circle"],["square","skewed_dash"],["crow","crows_foot_many"]]),Wz=new Map([...M$].map(([t,e])=>[e,t])),Bz=new Map([["top","n"],["bottom","s"],["left","w"],["right","e"],["top-left","nw"],["top-right","ne"],["bottom-left","sw"],["bottom-right","se"]]);function Lg(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 Df(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 Aa(t,e,n,i,r){const s=Lg(t,e,n);return s.exact||r(i,e),s.value}const b_={[Os]:"Dialog",[Vy]:"Serif",[Kl]:"Monospaced"};function W$(t){return Object.hasOwn(b_,t)?b_[t]:t.split(",")[0].trim()}function Hz(t){const e={},n=t("labelFont");typeof n=="string"&&(e["@_fontFamily"]=W$(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 B$(t,e,n){const i=t("label");if(typeof i!="string"||i.trim().length===0)return null;const r=Hz(t),s=t("labelColor");typeof s=="string"&&(r["@_textColor"]=s.toUpperCase());const o=e?t("labelPosition"):null;if(typeof o=="string"){const l=Wz.get(o),a=Bz.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 H$(t,e,n){const i={};i["y:Geometry"]=Yz(t,e);const r=t("fill"),s=t("fillOpacity");if(typeof r=="string"){i["y:Fill"]={"@_color":Df(r,s),"@_transparent":"false"};const c=t("fillGradient");if(typeof c=="string"){i["y:Fill"]["@_color2"]=c.toUpperCase();const d=t("fillGradientAngle");d!==U$&&n("fillGradientAngle",d??0)}}else s===0&&(i["y:Fill"]={"@_hasColor":"false","@_transparent":"false"});const o=Y$(t,["borderColor","borderWidth","borderStyle"],n);o!==null&&(i["y:BorderStyle"]=o);const l=B$(t,!0,n);l!==null&&(i["y:NodeLabel"]=l);const a=t("shape");return typeof a=="string"&&(i["y:Shape"]={"@_type":Aa(F$,a,a==="vee"?"triangle":"rectangle","shape",n)}),{"y:ShapeNode":i}}function Yz(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 Y$(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():Df(l,i)),typeof c=="string"){const u=o==="lineStyle"&&c==="long-dash"?"dashed":"line";d["@_type"]=Aa(Nb,c,u,o,n)}return typeof a=="number"&&(d["@_width"]=String(a)),d}function V$(t,e,n){const i={};e!==void 0&&(i["y:Path"]=e);const r=Y$(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"?Aa(z$,u,"standard",d,n):"none";i["y:Arrows"]={"@_source":c("sourceArrow",s),"@_target":c("targetArrow",o)}}const l=B$(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 Vz(t,e,n){const i=new re;no(t,e,"graphml",r=>({values:n[r],properties:Na[r],writes:Na[r],readBack:(s,o)=>{const l=Kz(r,o,i);return l===null?null:a=>l.get(a)??null}}))}function Kz(t,e,n){const i=()=>{},r=t==="node"?H$(e,null,i):V$(e,void 0,i),s=Cf(r,t==="node"?_b:Sb);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"?G$(s,a,l):j$(s,a,l),o}const E_={node:"nodegraphics",edge:"edgegraphics"};function Xz(t,e,n){for(const i of e){const r=K(t.value(i,n)),s=Cf(r,_b),o=s===null?ce(r,"RectD"):ce(s.r,"Geometry"),l=R(o,s===null?"X":"x"),a=R(o,s===null?"Y":"y");if(l!==void 0&&a!==void 0)return[l,a]}return null}function qz(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];Zm(a,i.meta.extra??{},l,!1);const[c,d]=$L(Float64Array.from(a),Jz,{width:Float64Array.of(l[0]),height:Float64Array.of(l[1])});return Number.isFinite(c)&&Number.isFinite(d)?[String(c),String(d)]:null}const Jz={yAxis:"down",anchor:"top-left"};function Zz(t,e,n){for(const i of e){const r=Cf(K(t.value(i,n)),Sb),s=r===null?void 0:ce(r.r,"Path");if(s!==void 0)return s}}function Qz(t,e,n,i){const r=e("bends"),[[s,o],[l]]=n;let a=null;typeof r=="string"&&(a=i?fu(s,o,r):G1(s,l,r));const c=["sourcePort","targetPort"].map((f,h)=>{const p=e(f),[g,m]=n[h],y=typeof p=="string"?fu(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?R(t,f)??"0.0":String(p[h&1])});const u=a??yt(t,"Point").map(f=>[Number(R(f,"x")),Number(R(f,"y"))]);return d["y:Point"]=u.map(([f,h])=>({"@_x":String(f),"@_y":String(h)})),d}function e7(t,e){let n=e,i=2;for(;t.has(n);)n=`${e}#${String(i)}`,i++;return n}function t7(t,e){if(e===void 0)return null;const n=new Al,i=p=>(g,m)=>{n.add(p,g,m)},r=(p,g)=>e.picture(p,g),s=kg(t.nodes),o=kg(t.edges),l=Ws(r,"node",Na.node),a=Ws(r,"edge",Na.edge),c=[];for(let p=0;p<t.nodeCount;p++){const g=l(p),m=Xz(t.nodes,s,p)??qz(t,p,g);c.push(H$(g,m,i("node")))}const d=c.map(p=>{const g=ce(ce(p,"ShapeNode"),"Geometry"),m=y=>Number(R(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=Qz(Zz(t.edges,o,p),g,[d[m],d[y]],m===y);u.push(V$(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 Rg(p))p.remove(b);const y=e7(p,E_[m]);p.set(y,g,{dtype:"json",nullable:!0,origin:{format:"graphml",id:null,title:null,type:E_[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 K$=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui"]),n7=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"]]]),i7=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 Ab(t){const e=t.trim();if(e.includes(":"))return{family:"Times, serif",bold:!1,italic:!1};const n=X$(e);if(n!==null)return n;const i=e.split(",").at(-1)?.trim().toLowerCase()??"";return{family:K$.has(i)?e:`${e}, sans-serif`,bold:!1,italic:!1}}function X$(t){const e=t.toLowerCase();for(const[n,[i,r]]of n7)if(e===n||e.startsWith(`${n}-`)){const s=i7.get(e.slice(n.length+1));if(s!==void 0)return{family:`${i}, ${r}`,bold:s[0],italic:s[1]}}return null}const r7=[{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 Tb(t,e,n){const i=t.split(",").map(l=>l.trim());if(i.length!==2||!K$.has(i[1].toLowerCase()))return t;const r=r7.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 s7(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 q$(t){return t.sides===4&&Math.abs(t.orientation%90)<.5&&t.distortion===0&&t.skew===0}const J$=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}])),Dr=t=>[[-t,0],[t,0]],w_=[[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]],__=[[1.5,6],[3,7.5],[3,10.5],[1.5,12],[-1.5,12],[-3,10.5],[-3,7.5],[-1.5,6]],S_=[[[0,0],[0,1.5]],[[0,3],[0,4.5]]],Ti=(t,e,n)=>[[t,n],[e,n],[e,n+6],[t,n+6]],Z$=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:[Dr(t)]})],["terminator",t=>({outline:[[3,0],[3,6],[9,6],[9,12],[-9,12],[-9,6],[-3,6],[-3,0]],parts:[],lines:[Dr(t)]})],["utr",t=>({outline:[[9,0],[9,3],[3,9],[-3,9],[-9,3],[-9,0]],parts:[],lines:[Dr(t)]})],["primersite",t=>({outline:[[12,3],[0,15],[0,9],[-t/2,9],[-t/2,3]],parts:[],lines:[Dr(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:Ti(-t,-t+24,1.5),parts:[Ti(-t+12,-t+24,-7.5)],lines:[[[-t+24,0],[t,0]]]})],["threepoverhang",t=>({outline:Ti(t-24,t,1.5),parts:[Ti(t-24,t-12,-7.5)],lines:[[[-t,0],[t-24,0]]]})],["noverhang",t=>({outline:Ti(-13.5,-1.5,1.5),parts:[Ti(-13.5,-1.5,-7.5),Ti(1.5,13.5,-7.5),Ti(1.5,13.5,1.5)],lines:[[[13.5,0],[t,0]],[[-13.5,0],[-t,0]]]})],["assembly",t=>({outline:Ti(-12,12,1.5),parts:[Ti(-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:w_,parts:[],lines:[...S_,Dr(t)]})],["rnastab",t=>({outline:__,parts:[],lines:[...S_,Dr(t)]})],["proteasesite",t=>({outline:w_,parts:[],lines:[[[0,7.5],[0,0]],Dr(t)]})],["proteinstab",t=>({outline:__,parts:[],lines:[[[0,6],[0,0]],Dr(t)]})]]),Ib=new Set(Z$.keys()),o7=new Set(["box3d","tab","folder","component","note","underline","cds","larrow","rarrow","lpromoter","rpromoter"]),O_=[54,36];function Q$(t,e,n){const i=Z$.get(t),r=e!==null&&e>0?e:O_[0],s=n!==null&&n>0?n:O_[1];return i===void 0?null:i(r/2,s/2)}async function $b(t,e,n,i){const r=t.importAll?.bind(t);if(r===void 0)return t.import(e,n,i);const s=await l7(e),o=[];await r(s,d=>o[d]=new xp({directed:!1}),{...i,onProgress:void 0});const l=o.map(d=>{try{return d.freeze().meta.name}catch{return null}}),a=pl(l,i,new te(t.format,0));return(await r(s,d=>d===a?n:new xp({directed:!1}),i))[a]}async function l7(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 As="dot",Ii=Object.freeze({format:As}),Ts="graphty.cluster",eC="graphty.parent",tC="graphty.sourcePort",nC="graphty.targetPort",Me="label",Ys="pos",a7="graphty.position",Is="key",c7="pin",d7="dot",u7=new Set(["color","size","shape","thickness","hidden"]),kf=["node","edge"];function f7(t,e,n,i){const r=to(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=N_(t,e,n);if(Cb(e)){let a;try{a=e.check(l.snapshot,l.input===null?i:{...i,styles:l.input})}catch{a=[]}const c=g7(n,t,a);c!==n&&(l=N_(t,e,c))}return{snapshot:l.snapshot,input:l.input,notes:E7(l.extracted,e,o,l.picture,t),refusal:null}}const Nd=new WeakMap;function h7(t,e,n){if(!Nd.has(t))return n();const i=Nd.get(t);if(i?.key.length===e.length&&i.key.every((s,o)=>s===e[o]))return i.value;const r=n();return Nd.set(t,{key:e,value:r}),r}function N_(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=E1(n,c,d,t),r.set(u,f)),f},o={node:new Map,edge:new Map};for(const c of kf)for(const[d,u]of n.columns[c])o[c].set(Ef(c,d),u);const l=Sl(n,{snapshot:t}),a=e.styles===void 0?null:{picture:s,block:l,tags:o,rules:n};return a!==null&&Nd.set(a,null),{snapshot:N7(t,i,o,l,n.styles.rules),input:a,extracted:n,picture:s}}const p7=/NODE_TABLE|NAME_CHANGED|ROLE_ASSUMED|STORAGE_CLASS|NUMBER_TYPE|INTEGRAL|WIDENED/;function g7(t,e,n){const i=new Set;let r=!1;for(const a of n){if(!p7.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 m7(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 m7{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,El(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=>iC(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}`,()=>ic(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)&&y7(i,r,n)}cells(e,n,i){const{table:r,n:s}=this.tableOf(e);return Array.from({length:s},(o,l)=>i(mf(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 y7(t,e,n){let i=!1;for(let r=0;r<e;r++){const s=K(t.value(n,r));if(s!=null){if(!iC(s))return!1;i=!0}}return i}function iC(t){return typeof t=="string"||typeof t=="boolean"||typeof t=="number"&&Number.isFinite(t)}function Cb(t){const e=t.styles?.capabilities;return e!==void 0&&(e.block==="native"||e.block==="attributes"&&t.capabilities.graphAttributes)}function b7(t,e){return t.style?.property.startsWith("graphty:")===!0&&Cb(e)}function E7(t,e,n,i,r){const s=[],o=Cb(e);for(const l of kf){const a=new Set(n?.[l]??[]);for(const c of _7(t.styles.rules,l))if(a.has(c)||o&&c.startsWith("graphty:"))l==="edge"&&s.push(...O7(r,e,c,i("edge",c)));else{const d=S7(l,c,e,i);d.count!==0&&s.push(d)}}return s.push(...w7(t,e,n)),o?s.push(...sc(Sl(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 w7(t,e,n){const i=new Set(n?.graph??[]),r=(n?.tool===void 0?null:Tr(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 _7(t,e){return new Set(t.filter(n=>n.target===e).flatMap(n=>[...Object.keys(n.set??{}),...Object.keys(n.map??{})]))}function S7(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 O7(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 N7(t,e,n,i,r){const s=e?.block==="attributes",o={node:A_(t.nodes,r,"node"),edge:A_(t.edges,r,"edge")},l={node:T_(t.nodes,e,"node"),edge:T_(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 kf){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&&(A7(d,n),d.graph.set(Z,[i],{dtype:"string"})),d}function A_(t,e,n){const i=rC(e,n);return t.names().filter(r=>T7(r)&&!i.has(r))}function T_(t,e,n){const i=(e?.[n]??[]).includes("label");return t.names().filter(r=>{const s=t.get(r)?.meta.role??"";return u7.has(s)||s==="label"&&i})}function A7(t,e){for(const n of kf){const i=n==="node"?t.nodes:t.edges,r=Ef(n,"");for(const s of i.names().filter(o=>o.startsWith(r)))i.remove(s);for(const[s,o]of e[n]){const l=I7(o);i.set(s,l==="string"?o.map(a=>a===null?null:String(a)):o,{dtype:l})}}}function T7(t){return t.startsWith("graphty.style.")||t.startsWith("graphty_style_")}function rC(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 I7(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 $7=10,I_=-25,$_={w:.75,h:.5};function C7(t,e,n,i,r){const s=t.edgeSource(n),o=t.edgeTarget(n),[l,a]=[e.center(s),e.center(o)];if(l===null||a===null||s===o)return;const c=D7(l,a,i("pos")),d=c.start===null?null:wu(i("lp"));if(d!==null&&i("label")!==null){const u=k7(c.points);r("labelOffsetX",x(d[0]-u[0])),r("labelOffsetY",x(u[1]-d[1]))}C_(e,c,{node:o,at:a,other:l},"head",i,r),C_(e,c,{node:s,at:l,other:a},"tail",i,r)}function C_(t,e,n,i,r,s){if(r(`${i}label`)===null)return;const o=i==="head",l=(o?e.end:e.start)??R7(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:wu(r(`${i}_lp`)))??v7(r,l,c);if(u!==null){const f=o?"target":"source";s(`${f}LabelOffset`,0),s(`${f}LabelOffsetX`,x(u[0]-l[0])),s(`${f}LabelOffsetY`,x(l[1]-u[1]))}}function v7(t,e,n){const i=v_(t("labelangle"),I_,-180),r=v_(t("labeldistance"),1,0);if(i===I_&&r===1)return null;const s=Math.atan2(n[1]-e[1],n[0]-e[0])+i*Math.PI/180,o=$7*r;return[e[0]+o*Math.cos(s),e[1]+o*Math.sin(s)]}function v_(t,e,n){const i=t===null||t.trim()===""?Number.NaN:Number(t);return Number.isFinite(i)?Math.max(n,i):e}function wu(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 D7(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:wu(a.slice(2))},s=i.filter(l=>!/^[es],/.test(l)).map(l=>wu(l)),o=s.every(l=>l!==null)&&s.length>=4?_f(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 k7(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 R7(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",$_.w)/2,r("height",$_.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 _u={x:16,y:8},sC=1.2,L7=[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 oC(t,e){let n=0;for(const i of t){const r=i.codePointAt(0)??0;n+=r>=32&&r<=126?L7[r-32]:1229}return n/2048*e}function P7(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 x7(t,e){return lC(t,{i:0},e,!0)}function D_(t,e){return{lines:null,port:null,children:t,lr:e,w:0,h:0,x:0,y:0}}function lC(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=lC(t,e,!n,!1);else if(o==="}"){if(e.i++,!i)return Zh(r,s,n),D_(r,n)}else o==="|"?(e.i++,Zh(r,s,n)):M7(t,e,s)}return Zh(r,s,n),D_(r,n)}function M7(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 Zh(t,e,n){const{sub:i,port:r}=e;t.push(i??{lines:P7(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 aC(t,e){if(t.lines!==null){const n=Math.max(...t.lines.map(r=>oC(r.text,e))),i=t.lines.length*e*sC;[t.w,t.h]=n>0||i>0?[n+_u.x,i+_u.y]:[0,0];return}t.w=0,t.h=0;for(const n of t.children)aC(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 cC(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);cC(r,t.lr?r.w+o:e,t.lr?n:r.h+o)})}function dC(t,e,n){t.x=e,t.y=n;let i=t.lr?e:n;for(const r of t.children)dC(r,t.lr?i:e,t.lr?n:i),i+=t.lr?r.w:-r.h}function U7(t,e,n,i,r,s,o){const l=x7(t,e),a=m=>{m.lines!==null&&(m.lines=m.lines.map(y=>({...y,text:o(y.text)}))),m.children.forEach(a)};a(l),aC(l,s);const c=r?n:Math.max(n,l.w),d=r?i:Math.max(i,l.h);cC(l,c,d),dC(l,-c/2,d/2);const u=[],f=[],h=new Map,p=s*sC,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=oC(b.text,s)/2;let I=m.x+m.w/2;b.justify==="l"?I=m.x+_u.x/2+S:b.justify==="r"&&(I=m.x+m.w-_u.x/2-S),f.push({x:I,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 Su=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"}),Qh="name",k_="directed",G7="cluster",Pg=["colorscheme","color","fillcolor","bgcolor","pencolor","style","shape","width","height","fixedsize","regular","sides","distortion","skew","orientation","penwidth","gradientangle","fontname","fontsize","fontcolor","tooltip"],xg=["colorscheme","color","style","penwidth","fontname","fontsize","fontcolor","tooltip","edgetooltip","arrowhead","arrowtail","dir","arrowsize","fillcolor","headlabel","taillabel","xlabel"],j7=["peripheries","xlabel"],uC=new Set(["circle","doublecircle","mcircle","square","msquare"]),Tl=new Set(["box","rect","rectangle","square"]),Rf=new Set(["","ellipse","oval","circle"]),vb=new Set(["plain","plaintext","none"]),Lf=new Set(["record","mrecord"]),F7=new Set(["true","yes","shape"]),R_=.05,z7=.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 Dt(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 ue(t){return t===null||t===""?null:t}function fC(t,e){return t===null?[]:t.length>De?(B(e,v.VALUE_TOO_LONG,`${String(t.length)} characters`),[]):t.toLowerCase().split(",").map(n=>n.replace(/^[ \t\r\n]+/,"")).filter(n=>n!=="")}function Pf(t){for(const e of t)if(e.startsWith("setlinewidth(")&&e.endsWith(")"))return e.slice(13,-1).trim();return null}function Ta(t){if(t===null)return!1;const e=t.trim().toLowerCase();return F7.has(e)||/^-?\d+$/.test(e)&&Number(e)!==0}function hC(t,e,n,i,r){return Yi(t)?Zp(t,r):n.has(`<${t}>`)?Zp(`<${t}>`,r):gf(i?p6(t,r):t,e,r)}function pC(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);W7(c).trim()!==""&&o.add("center");const[d]=o;o.size===1&&d!=="center"&&r("labelTextAlign",d);return}if(i)return;const s=o6(t,e);s!==null&&r("labelTextAlign",s)}function W7(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 gC(t,e,n,i,r){if(!Yi(t)&&!e.has(`<${t}>`))return;const s=Yi(t)?t:`<${t}>`,o=[];for(const a of u1(s)){const c={text:a.text,...Y7(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(B7(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(H7[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 B7(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 H7={weight:"labelWeight",italic:"labelItalic",font:"labelFont",size:"labelSize",color:"labelColor"};function Y7(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 K7(r))V7(o.toLowerCase(),l,e,n,i)}return i}function V7(t,e,n,i,r){if(t==="face"&&e.trim()!==""&&e.length<=De){const s=Ab(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=$e(e,"graphviz",i,{scheme:n,use:"text"});s!==null&&(r.color=s.color)}}const L_=/^[\w-]$/;function K7(t){const e=[];let n=0;for(;n<t.length;){if(!L_.test(t[n])){n++;continue}let i=n;for(;i<t.length&&L_.test(t[i]);)i++;const r=X7(t,i);r!==null&&e.push([t.slice(n,i),r.text]),n=r===null?i:r.next}return e}function X7(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 oo(t,e,n,i,r,s,o){if(t===null)return null;const l=$e(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):_l(l,null,o(i),!1),l.alpha)}function P_(t){const e=x(t);for(let n=6;n<17;n++){const i=Number((t/gt).toPrecision(n));if(x(i*gt)===e)return i+0}return t/gt}function Ou(t,e){if(t===null)return null;const n=t.trim()===""?Number.NaN:Number(t);return!Number.isFinite(n)||n<0?(B(e,v.BAD_VALUE,t.slice(0,De)),null):n}function mC(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)};oo(ue(t("fontcolor")),n,"text","labelColor","labelOpacity",o,s);const l=t("fontsize");r("labelSize",l===null?null:V(l,s("labelSize")));const a=t("fontname");if(a!==null&&a.length<=De){const d=Ab(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",gf(c,i,s("tooltip")))}function q7(t,e){const{get:n,cx:i,put:r,at:s,shape:o}=t,l=t.point?null:n(Me),a=l===null?i.name:hC(l,e,i.html,Lf.has(o),s("label"));J7(t,l,a,e);const c=l!==null&&(Yi(l)||i.html.has(`<${l}>`));o==="plain"&&a===""&&!c&&r("visible",!1),i.cluster?eW(n,r):Z7(t,l,a,c,e)}function J7(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),pC(e,i,s.html,Lf.has(a),o),gC(e,s.html,t.scheme,o,l),s.cluster&&(o("labelPosition",EC(r)),tW(r,o))),!s.cluster&&!t.point){const c=bC(r);o("labelPosition",c==="center"?null:c)}}function Z7(t,e,n,i,r){const{get:s,put:o,at:l,shape:a}=t;gW(s,a,t.point,o,l),Lf.has(a)&&e!==null&&!i?Q7(t,e,r):t.point||(EW(s,a,e,n,o),mW(t,e))}const x_={w:54,h:36};function Q7(t,e,n){const{get:i,put:r,at:s,cx:o}=t,l=(p,g)=>{const m=Ou(i(p),s(p==="width"?"width":"height"));return m===null?g:m*gt},a=Number(i("fontsize")??14),c=U7(e,!o.flip,l("width",x_.w),l("height",x_.h),Ta(i("fixedsize")),Number.isFinite(a)&&a>0?a:14,p=>gf(p,n)),d=c.width/2,u=c.height/2,f=p=>String(x(d>0?p/d:0)),h=p=>String(x(u>0?p/u:0));r("width",x(c.width)),r("height",x(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 eW(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",x(n[2]-n[0])),e("height",x(n[3]-n[1])))}function yC(t,e,n,i){const r=fC(t("style"),i("visible")),s=ue(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:ue(t("color"))},a=e.cluster?{graph:e.name}:{node:e.name,graph:e.graph,edge:""};mC(t,r,l.scheme,a,n,i),e.cluster?nW(l):iW(l),rW(l),sW(l),lW(l),q7(l,a),ue(t("xlabel"))!==null&&B(i("label"),v.NOT_CARRIED,"xlabel")}function bC(t){const e=(t("labelloc")??"").trim().toLowerCase();return e.startsWith("t")?"inside-top":e.startsWith("b")?"inside-bottom":"center"}const M_=8;function tW(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",x(n[0]-(i[0]+i[2])/2)),e("labelOffsetY",x((i[1]+i[3])/2-n[1]));return}const r=(t("labeljust")??"").trim().toLowerCase();r.startsWith("l")?e("labelOffsetX",M_):r.startsWith("r")&&e("labelOffsetX",-M_)}function EC(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 nW(t){const{get:e,tokens:n}=t,i=n.includes("filled")||n.includes("radial")||n.includes("striped"),r=ue(e("bgcolor")),s=i?ue(e("fillcolor"))??t.color??r??"lightgrey":r;oo(s,t.scheme,"fill","fill","fillOpacity",t.put,t.at),n.includes("striped")||wC(t,s)}function wC(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(x(r-.001))} ${String(x(r))}`);const s=e.slice(n+1).split(":")[0].split(";")[0],o=$e(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(ue(t.get("gradientangle"))??"0"),a=Number.isFinite(l)?(-l%360+360)%360:0;t.put("fillGradientAngle",x(a)+0)}function iW(t){const{point:e}=t,n=ue(t.get("fillcolor"));if(SC(t)){const i=n??t.color??(e?"black":"lightgrey");oo(i,t.scheme,"fill","fill","fillOpacity",t.put,t.at);const r=t.tokens.includes("striped")&&Tl.has(t.shape)||t.tokens.includes("wedged")&&Rf.has(t.shape);(t.tokens.includes("filled")||t.tokens.includes("radial"))&&!r&&wC(t,i)}else n!==null&&B(t.at("fill"),v.UNFILLED,n.slice(0,De))}function rW(t){const e=t.tokens.includes("striped")&&(t.cx.cluster||Tl.has(t.shape)),n=!t.cx.cluster&&t.tokens.includes("wedged")&&Rf.has(t.shape),i=ue(t.get("fillcolor"))??t.color;if(!e&&!n||!i?.includes(":"))return;const r=_C(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 _C(t,e,n,i){const s=t.split(":").map(f=>{const[h,p]=f.split(";"),g=$e(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:x(h)}]:[]}),u=d.at(-1);return u!==void 0&&l===0&&c<1&&(u.size=x(u.size+1-c)),d}function SC(t){const{shape:e,point:n}=t;return n||t.tokens.some(i=>i==="filled"||i==="radial"||i==="striped"&&Tl.has(e)||i==="wedged"&&Rf.has(e))}function sW(t){const{get:e,cx:n,put:i,at:r,tokens:s}=t;if(!n.cluster&&vb.has(t.shape))i("borderWidth",0);else{const o=n.cluster?ue(e("pencolor"))??t.color:t.color,l=oo(o,t.scheme,"line","borderColor",null,i,r),a=ue(e("penwidth"))??Pf(s);l===0||Number(ue(e("peripheries"))??"1")===0?i("borderWidth",0):a!==null?i("borderWidth",AC(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||oW(t)}const Db=new Map([["doublecircle",2],["doubleoctagon",2],["tripleoctagon",3]]),kb=4;function oW(t){const e=ue(t.get("peripheries")),n=e===null?Db.get(t.shape)??1:Math.trunc(Number(e));if(Number.isNaN(n)||n<=1||vb.has(t.shape))return;const i=t.color===null?null:$e(t.color,"graphviz",t.at("outerBorderColor"),{scheme:t.scheme,use:"line"});if(i!==null&&i.alpha===0)return;const r=ue(t.get("penwidth"))??Pf(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",x(l)),t.put("outerBorderOffset",x(Math.max(0,kb-l))),(t.tokens.includes("dashed")||t.tokens.includes("dotted"))&&t.put("outerBorderStyle",t.tokens.includes("dashed")?"dashed":"dotted"),n>2&&B(t.at("outerBorderWidth"),v.NOT_CARRIED,`peripheries=${String(n)}`)}function lW(t){const e=t.tokens.includes("rounded")&&!t.tokens.includes("striped"),n=cW(t);if(t.cx.cluster)t.put("shape",e?"round-rectangle":"rectangle");else if(t.shape==="polygon")dW(t,e);else if(n!==null)t.put("shape","polygon"),t.put("shapePoints",xf(Rb(n))),t.put("shapePointsStretch",!1);else if(Nu.has(t.shape))t.put("shape","polygon"),t.put("shapePoints",Nu.get(t.shape)??null),t.put("shapePointsStretch",!1);else if(Ib.has(t.shape)){const i=r=>{const s=Ou(t.get(r),t.at(r));return s===null?null:s*gt};OC(t.shape,i("width"),i("height"),t.put,()=>{const r=ue(t.get("penwidth"))??Pf(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:$e(t.color,"graphviz",t.at("outerBorderColor"),{scheme:t.scheme,use:"line"})?.color??null)}else if(t.shapeRaw!==null){const i=e&&Tl.has(t.shape)?"round-rectangle":oe("shape",t.shapeRaw,"graphviz",t.at("shape"));t.put("shape",i==="none"&&SC(t)?"rectangle":i)}}const aW=new Map([...[...Tl].map(t=>[t,{sides:4,orientation:0}]),["diamond",{sides:4,orientation:45}],["hexagon",{sides:6,orientation:0}],["octagon",{sides:8,orientation:0}]]);function cW(t){const e=Number(ue(t.get("orientation"))??"0"),n=aW.get(t.shape)??J$.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 q$(i)?null:i}function dW(t,e){const n=(r,s,o)=>{const l=ue(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)};q$(i)?t.put("shape",e?"round-rectangle":"rectangle"):i.sides<3?t.put("shape","ellipse"):(t.put("shape","polygon"),t.put("shapePoints",xf(Rb(i))),t.put("shapePointsStretch",!1))}function Rb(t){const e=s7(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 xf(t){return t.map(([e,n])=>`${x(e)},${x(n)}`).join(" ")}const Nu=new Map([...J$].map(([t,e])=>[t,xf(Rb(e))]));function OC(t,e,n,i,r,s){const o=NC(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",x(r())),i("outerBorderOffset",x(Math.max(0,o.ring-r())))))}function NC(t,e,n){const i=Q$(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=>xf(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 uW(t){return Nu.get(t)}function fW(t){return vb.has(t)}const hW=new Map([...Nu].map(([t,e])=>[e,t]));function pW(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 Ib){if(Q$(o,e,n)?.outline.length!==s)continue;const l=NC(o,e,n);if(l!==null&&l.outline===r&&l.parts===i("shapeParts")&&l.lines===i("shapeLines"))return{name:o,unstroked:l.unstroked}}}function AC(t,e,n){const i=Number(t.trim());return e&&Number.isFinite(i)&&i<0?(B(n,v.BAD_VALUE,t.slice(0,De)),0):V(t,n)}function gW(t,e,n,i,r){let s=Ou(t("width"),r("width")),o=Ou(t("height"),r("height"));const l=n||uC.has(e)||Ta(t("regular"));if(e==="plain")s=o=0;else if(s===null&&o===null){if(n){i("width",x(R_*gt)),i("height",x(R_*gt));return}if(!l)return;s=o=z7}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:V(a,r("width"),gt)),i("height",c===null?null:V(c,r("height"),gt))}function mW(t,e){const{get:n,put:i,shape:r}=t;let s=Tl.has(r)?1:null;Rf.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===""||Ta(n("fixedsize"))||!(o>=0&&l>=0))return;const a=t.cx.quantum*s;i("width",x(Math.max(o*gt,a))),i("height",x(Math.max(l*gt,a)))}const yW={x:8,y:4},bW=1.2;function EW(t,e,n,i,r){if(Ta(t("fixedsize"))||n===""&&!Lf.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(wW),c=e==="plain"?{x:0,y:0}:yW,d=a.length>0?a[0]*gt:c.x,u=a.length>0?(a[1]??a[0])*gt:c.y;r("labelFit",o7.has(e)?"bounds":"inside"),r("labelPaddingX",x(d)),r("labelPaddingY",x(u+(bW-1)*l*s/2)),(uC.has(e)||Ta(t("regular")))&&r("labelFitSquare",!0)}function wW(t){return Number.isFinite(t)&&t>=0}function TC(t,e,n,i){const r=fC(t("style"),i("visible")),s=t("colorscheme");mC(t,r,s,e.names,n,i),oo(ue(t("color")),s,"edge","color","opacity",n,i),_W(ue(t("color")),s,n,i),AW(t,r,n,i),TW(t,e,n,i);for(const[o,l]of[[Me,"label"],["headlabel","targetLabel"],["taillabel","sourceLabel"]]){const a=o===Me?t(o)??ue(t("xlabel")):t(o);a!==null&&(n(l,hC(a,e.names,e.html,!1,i(l))),l==="label"&&(pC(a,e.names,e.html,!1,n),gC(a,e.html,s,n,i)))}t(Me)!==null&&ue(t("xlabel"))!==null&&B(i("label"),v.NOT_CARRIED,"xlabel")}function _W(t,e,n,i){if(t===null||!t.includes(":")||!t.includes(";"))return;const r=_C(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(x(l),x(Math.min(1,l+a.size))),l+=a.size;n("gradientKind","linear"),n("gradientColors",s.join(" ")),n("gradientStops",o.join(" "))}function SW(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)=>ue(Dt(t.nodes,i,n))}}function OW(t,e,n){if(n===null)return null;const i=t.nodes.byRole("position"),r=u=>{const f=i?.isSet(u)===!0?i.value(u):null;return f===null?null:[f[0],f[1]]},[s,o]=[r(t.edgeSource(e)),r(t.edgeTarget(e))];if(s===null||o===null)return null;const l=(u,f)=>{const h=(u??"").trim().split(/\s+/).find(m=>m.startsWith(`${f},`)),[p,g]=(h??"").slice(2).split(",").map(Number);return h!==void 0&&Number.isFinite(p)&&Number.isFinite(g)?[p,g]:null},a=n.split(";"),c={start:l(a[0],"s"),end:l(a.at(-1),"e")},d=a.map(u=>u.trim().split(/\s+/).filter(f=>!/^[es],/.test(f)).map(f=>{const[h,p]=f.split(",").map(Number);return[h,p]}));return IC(s,o,d,c)}const U_={x:18,y:9};function NW(t){const e=o=>ue(o("tailport"))===null&&ue(o("headport"))===null&&ue(o(Ys))===null,n=new Map,i=(ue(Dt(t.graph,"splines",0))??"").toLowerCase(),r=i!=="ortho"&&i!=="none"&&ue(Dt(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=>Dt(t.edges,a,o))&&n.set(l,[...n.get(l)??[],o])}const s=(o,l,a)=>{const c=Number(ue(Dt(t.nodes,l,o))??Number.NaN);return(Number.isFinite(c)&&c>0?c:a)*gt};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+U_.x*f,p=U_.y*f/c.length,g=_f([[0,0],[h/3,p],[h,p],[h,0],[h,-p],[h/3,-p],[0,0]]);return g===null?null:zs([0,0],[d,u],g.slice(1,-1),!1)}}}function IC(t,e,n,i){const r=[];for(const f of n){const h=_f(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),u=Math.max(...r.map(([f,h])=>Math.abs((f-t[0])*c-(h-t[1])*a)));return d>0&&u/(d*d)>.001?Ol(t,e,r,!1):null}function AW(t,e,n,i){const r=ue(t("penwidth"))??Pf(e);r!==null?n("width",AC(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 TW(t,e,n,i){const r=ue(t("dir")),s=ue(t("arrowhead")),o=ue(t("arrowtail"));if(r!==null||s!==null||o!==null){const c=(r??(e.directed?"forward":"none")).trim().toLowerCase();G_("target",s,c==="forward"||c==="both",n,i),G_("source",o,c==="back"||c==="both",n,i)}const l=t("arrowsize");l!==null&&n("arrowSize",V(l,i("arrowSize")));const a=ue(t("fillcolor"));for(const c of["targetArrowColor","sourceArrowColor"])oo(a,t("colorscheme"),"fill",c,null,n,i)}function G_(t,e,n,i,r){const s=n?$C(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 IW=["left","right"],$W=new Set(["normal","diamond","dot","box","inv"]),CW=new Map([["obox","other:open-square"],["oinv","other:open-inverted"]]);function $C(t,e){const n=vW(t);return{value:(n===null?void 0:CW.get(n.name))??oe("arrow",n?.name??t,"graphviz",e),side:n?.side??null}}function vW(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=IW.find(l=>i.includes(l[0]))??null;return{name:(i.includes("o")&&$W.has(r)?"o":"")+r,side:s}}}return null}function DW(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[Me,"headlabel","taillabel"].filter(s=>n.has(s)))kW(n,r,i,e);return e}function kW(t,e,n,i){for(let r=0;r<n;r++){const s=Dt(t,e,r);s!==null&&Yi(s)&&i.add(s)}}function CC(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 RW(t,e){return t.nodes.has(Ts)&&t.nodes.value(Ts,e)===!0}function vC(t,e=null){const n=DW(t),i=t.meta.name??"",r=(Dt(t.graph,"rankdir",0)??"").trim().toUpperCase(),s=r==="LR"||r==="RL",o=Number(Dt(t.graph,"quantum",0)??Number.NaN),l=Number.isFinite(o)&&o>0?o*gt:0,a=CC(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:RW(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 DC(t,e,n){if(t.cluster||e==="point")return null;const i={notes:n,target:"node",property:"label"};return Yi(t.name)?Zp(t.name,i):gf(String.raw`\N`,{node:t.name,graph:t.graph},i)}function j_(t,e){const n=new Set([...e,...j7]);return[...t.names()].filter(i=>n.has(i)||i.startsWith("graphty.style."))}function LW(t,e){const n={},i=ue(Dt(t.graph,"bgcolor",0));return!t.graph.has("bgcolor")||i===null||oo(i,Dt(t.graph,"colorscheme",0),"fill","background",null,(r,s)=>{s!==null&&(n[r]=s)},r=>({notes:e,target:"graph",property:r})),n}function PW(t,e){const n=new re,i=vC(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 T=0;T<t.nodeCount;T++){e.budget.spend("node",Pg.length);const D=Y=>Dt(t.nodes,Y,T),P=i.node(T);yC(D,P,(Y,me)=>{r.put(T,Y,me)},Y=>({notes:n,target:"node",property:Y,element:T,budget:e.budget}));const U=DC(P,(D("shape")??"").toLowerCase(),n);U!==null&&(s[T]=U,l++),P.cluster&&(o[T]=!0,a++)}const c=qr(t.edgeCount),d=NW(t),u=Dt(t.graph,"splines",0)?.trim().toLowerCase(),f=u===""||u==="none",h=SW(t);for(let T=0;T<t.edgeCount;T++){e.budget.spend("edge",xg.length);const D=U=>Dt(t.edges,U,T),P=U=>({notes:n,target:"edge",property:U,element:T,budget:e.budget});TC(D,i.edge(T),(U,Y)=>{c.put(T,U,Y)},P),f&&c.put(T,"visible",!1);const k=OW(t,T,D(Ys))??d.bendsOf(T,D);k!==null&&c.put(T,"bends",k),C7(t,h,T,D,(U,Y)=>{c.put(T,U,Y)})}const p=LW(t,n),g=Dt(t.graph,Z,0);g!==null&&VW(t,g,{node:r.values,edge:c.values},i);const m=[],y=new Map;l>0&&(y.set(Qh,s),m.push({id:"node.tool.name-label",target:"node",role:"passthrough",origin:"tool",where:{has:{style:Qh}},map:{label:{kind:"passthrough",by:{style:Qh}}},facts:{elements:l,reason:"NODE_NAME"}}));const b=a>0?[{ref:{style:G7},values:o}]:[],_=[],S=new Map,I=CC(t);return I.some(Boolean)&&(S.set(k_,I.map(T=>T?!0:null)),_.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:k_}},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:j_(t.nodes,Pg),edge:j_(t.edges,xg)}}}const xW=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"]]),MW=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"]]),kC=new Map([["dashed","dashed"],["dotted","dotted"]]);function F_(t){const e=Tr("graphviz")?.[t],n=new Map,i=(s,o,l=1)=>{const a=e[o]?.value;typeof a=="number"?n.set(s,x(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",Tb(r,!1,!1)),t==="node"?(i("color","borderColor"),i("pencolor","borderColor"),i("penwidth","borderWidth"),i("shape","shape"),i("width","width",gt),i("height","height",gt)):(i("color","color"),i("penwidth","width"),i("arrowsize","arrowSize")),n}const UW={node:F_("node"),edge:F_("edge")};function RC(t,e){for(const[n,i]of UW[e])t.get(n)===i&&t.delete(n);return!t.has("width")&&!t.has("height")&&t.delete("fixedsize"),t}function LC(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 Lb(t){return t.replaceAll("&","&amp;").replaceAll("\\",String.raw`\\`).replaceAll(`
81
+ `,String.raw`\n`)}function Mf(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 PC(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=Tb(o,l,a);n.set("fontname",d);const u=Ab(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",Lb(c)),t("visible")===!1&&i.push("invis")}function xC(t,e,n,i,r){const s=new Map,o=[];PC(t,i,s,o),jW(t,e,i,s,o);const l=FW(t,e,i,s,o);e.cluster||HW(t,s);const a=t("label"),c=DC(e,l,r);return typeof a=="string"&&a!==c?s.set(Me,Lb(a)):a===null&&c!==null&&s.set(Me,""),GW(t("labelPosition"),e,n,i),o.length>0&&s.set("style",o.join(",")),RC(s,"node")}function GW(t,e,n,i){typeof t=="string"&&t!==(e.cluster?EC(n):bC(n))&&i("labelPosition",t)}function jW(t,e,n,i,r){const s=t("fill"),o=t("fillOpacity");typeof s=="string"&&o!==0&&(r.push("filled"),i.set("fillcolor",LC(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(Mf(kC,c,d,"borderStyle",n))}}function FW(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"?pW(t,o("width"),o("height")):void 0;if(l!==void 0)return zW(t,l,i);WW(t,n);const a=s==="polygon"?BW(t("shapePoints"),n,i):null;if(a!==null)return t("shapePointsStretch")!==!1&&n("shapePointsStretch",!0),a;const c=Mf(xW,s,s==="vee"?"invtriangle":"box","shape",n);return i.set("shape",c),c}function zW(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 WW(t,e){for(const n of["shapeParts","shapeLines","shapeLineWidth"]){const i=t(n);i!=null&&e(n,i)}}function BW(t,e,n){if(typeof t!="string")return null;const i=hW.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 HW(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",P_(n)),typeof i=="number"&&e.set("height",P_(i))}function MC(t,e,n){const i=new Map,r=[];PC(t,n,i,r);const s=t("color");typeof s=="string"&&i.set("color",LC(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(Mf(kC,l,l.includes("dash")?"dashed":"solid","lineStyle",n)),YW(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",Me],["targetLabel","headlabel"],["sourceLabel","taillabel"]]){const p=t(f);typeof p=="string"&&i.set(h,Lb(p))}return r.length>0&&i.set("style",r.join(",")),RC(i,"edge")}function YW(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=Mf(MW,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 VW(t,e,n,i){const r=new re;no(t,e,"dot",s=>({values:n[s],properties:Su[s],writes:Su[s],readBack:(o,l)=>{const c=KW(s,o,l,{cx:i,raw:d=>Dt(s==="node"?t.nodes:t.edges,d,o)},r);return d=>c.get(d)??null}}))}function KW(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=xC(n,u,o,l,r),h=p=>p==="labelloc"||p==="labeljust"?o(p):null;yC(p=>f.has(p)?z_(f.get(p)):h(p),u,c,d)}else{const u=s.edge(e),f=MC(n,u.directed,l);TC(h=>z_(f.get(h)),u,c,d)}return a}function z_(t){return t===void 0?null:String(t)}function XW(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=>Xn(n)==="string")&&e.every(n=>mT(n)):!1}function qW(t){return t.replaceAll(/\\(["\\])/g,(e,n)=>n==='"'?String.raw`\u0022`:String.raw`\u005c`)}function ep(t,e,n){return e===void 0?null:h7(e,[t,n],()=>JW(t,e,n))}function JW(t,e,n){const i=new Al,r=[],s=t.withColumns(),l=vC(t,n==="directed"||n==="undirected"?n==="directed":null),a=new re;for(const h of["node","edge"]){const p=h==="node"?s.nodes:s.edges,g=sB(e.rules.styles.rules,h),y=ZW(t,e,h,{cx:l,approximate:(b,_)=>{i.add(h,b,_)},notes:a,read:g});r.push(...nB(p,h,y,g)),iB(p,y)}const{background:c}=e.rules.styles.graph;s.graph.has("bgcolor")&&s.graph.remove("bgcolor"),typeof c=="string"&&c!==Tr("graphviz")?.graph.background?.value&&s.graph.set("bgcolor",[c],{dtype:"string"});const d=[...e.tags.node.values(),...e.tags.edge.values()].some(h=>!XW(h));d||rB(s,e);const u=d?Sl(e.rules,{inlineColumns:!0,snapshot:t}):e.block;s.graph.set(Z,[qW(u)],{dtype:"string"});const f=i.notes("Graphviz");return d&&f.push(...sc(u,e.rules.styles.rules.length,"size")),{snapshot:s,notes:[...r,...f]}}function ZW(t,e,n,i){const r=n==="node"?t.nodeCount:t.edgeCount,s=Ws((l,a)=>e.picture(l,a),n,Su[n]),o=new Map;for(let l=0;l<r;l++){const a=n==="node"?xC(s(l),i.cx.node(l),c=>Dt(t.nodes,c,l),i.approximate,i.notes):MC(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(Me)&&a.get(Me)===""&&s(l)("label")===null&&i.approximate("label",""),QW(o,a,l,r)}return n==="node"&&tB(t,i.cx,o,e.rules.styles.graph.background),o}function QW(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 eB=new Map([["style",""],["penwidth",1],["color",""],["pencolor",""],["fillcolor",""],["bgcolor",""],["fontname","Times-Roman"],["fontsize",14],["fontcolor","black"],[Me,""]]);function tB(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 eB){const l=n.get(s);if(!(Dt(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 nB(t,e,n,i){const r=e==="node"?Pg:xg,s=[];for(const o of t.names()){if(!r.includes(o)&&o!==Me&&!o.startsWith("graphty.style."))continue;const l=i.has(o)?oB(t,o,n.get(o)):0;l>0&&s.push(Object.freeze({code:UC,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 iB(t,e){for(const[n,i]of e)n===Me?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 rB(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 sB(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 UC="W_DOT_ATTRIBUTE_CLASH";function oB(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 On=Object.freeze({TRAILING_BACKSLASH:"E_DOT_TRAILING_BACKSLASH",NON_FINITE:"W_DOT_NON_FINITE",TEXT_INFERRED:w.TEXT_INFERRED,ATTRIBUTE_CLASH:UC,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"}),GC=/^utf-?8$/i;function lB(t){const e=jC(t)&&t.isSet(0)?Ql(t,0):null;return e===null||GC.test(e)?[]:[Object.freeze({code:On.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 jC(t){return t.meta.name.toLowerCase()==="charset"}const aB=new Set(["label","id","sourcePort","targetPort","parent"]),cB=Object.freeze({label:Me,id:Is,sourcePort:tC,targetPort:nC,parent:eC,position:Ys}),Pb=Xe({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}),dB=" ",uB="cluster",fB=new Set(["n","ne","e","se","s","sw","w","nw","c","_"]),hB=new Set(["parent","parents","position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen","timeText","directed","pair","mutual","weight"]),pB=new Set(["id","weight","directed","pair","mutual","sourcePort","targetPort","position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen","timeText","parent","parents"]),gB=new Set(["position","color","size","shape","thickness"]),mB=new Set(["label","id","sourcePort","targetPort"]),yB=Object.freeze({format:As,options:Object.freeze(["indent","name","strict"]),capabilities:Pb,styles:Object.freeze({capabilities:Su}),check(t,e){const n=ep(t,e?.styles,e?.onMixedDirection);return n===null?W_(t,e):Object.freeze([...W_(n.snapshot,e),...n.notes])},export(t,e){return ei(B_(ep(t,e?.styles,e?.onMixedDirection)?.snapshot??t,e))},exportToString(t,e){return ti(B_(ep(t,e?.styles,e?.onMixedDirection)?.snapshot??t,e))}});function W_(t,e){const n=dt(e),i=Un(t,Pb,n,{positionDtype:"f64",roles:aB,roleNames:cB}),r=new FC(t,n,e);return[...i,...r.notes()]}function*B_(t,e){const n=dt(e),i=new FC(t,n,e);i.refuse(),yield*i.write()}function H_(t){return!mT(t)}function kr(t){return Yi(t)?t:Ss(t)}function bB(t){const e=t.lastIndexOf(":");return e>0&&fB.has(t.slice(e+1))?`:${Ss(t.slice(0,e))}:${t.slice(e+1)}`:`:${Ss(t)}`}function tp(t){return t.dtype!=="list"&&t.dtype!=="json"}function Y_(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 EB(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(On.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===Me&&s&&n(On.ROLE_ASSUMED,`${t} column "${i}" reads back with the label role`,i,e.length-e.nullCount);const o=e.dtype==="f32"||e.dtype==="f64"?OB(e):0;o>0&&n(On.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||!mB.has(r))?NB(e):0;l>0&&n(On.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 wB(t,e,n){e!==null&&e.meta.components!==2&&e.meta.components!==3&&n(On.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(On.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 FC=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 Y_("name",s,"a string or null");if(o!==void 0&&typeof o!="boolean")throw Y_("strict",o,"a boolean");this.indent=iT(r,dB),this.name=s===void 0?e.meta.name:s,this.strict=o??_B(e),this.mixed=gl(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=SB(this.position),this.parent=l.byRole("parent");const d=l.get(Ts);this.cluster=d!==null&&d.dtype==="bool"?d:null,this.edgeId=a.byRole("id"),this.weights=wt(e),this.folding=Ut(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=>tp(f)&&(f.meta.role===null||!gB.has(f.meta.role))),this.children=ec(e,{column:this.parent!==null&&this.parent.dtype==="u32"?this.parent:null}),this.nodeColumns=V_(this.nodeColumns,this.nodeTextOrder());const u=[];for(let f=0;f<e.edgeCount;f++)this.folding.folded(f)||u.push(f);this.edgeColumns=V_(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!tp(e)||n===Ts||i!==null&&hB.has(i)?!1:n===Ys&&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!tp(e)||i!==null&&pB.has(i)?!1:n===Is&&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!==Me||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:On.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(On.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(...lB(a)),EB(o,a,n);this.structureNotes(n),wB(i,this.position,n);const s=AB(i);return s>0&&n(On.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(On.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 "${Ts}" true`,Ts,i);const r=this.folding.mutualCount;r>0&&e(On.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(On.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});bl(this.snapshot,Pb.idCharset,this.resolved.sanitizeIds)}countUnwritable(){let e=0;return this.forEachText(n=>{H_(n)&&e++}),e}firstUnwritable(){let e=null;return this.forEachText((n,i)=>{e===null&&H_(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?"":` ${Ss(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.writeEdges(),yield`}
84
+ `}*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)};
85
+ `;return}l||(yield`${r}${this.nodeStatement(e,s)};
86
+ `);const a=`${r}${this.indent}`;if(yield`${r}subgraph ${kr(s)} {
87
+ `,s.startsWith(uB)||(yield`${a}cluster=true;
88
+ `),l){const c=this.nodeAttributes(e);c.length>0&&(yield`${a}graph [${c.join(", ")}];
89
+ `)}for(const c of o)i[c]===1?yield`${a}${kr(this.idText(c))};
90
+ `:yield*this.writeNode(c,n+1,i);yield`${r}}
91
+ `}nodeStatement(e,n){const i=this.nodeAttributes(e);return i.length===0?kr(n):`${kr(n)} [${i.join(", ")}]`}nodeAttributes(e){const n=this.attributesOf(this.nodeColumns,e),i=this.positionText(e);return i!==null&&n.push(`${Ys}=${Ss(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"?lt:je,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?Me:e.meta.name}attributesOf(e,n){const i=[];for(const r of e){if(!r.isSet(n))continue;let s=Ql(r,n);s!==null&&e===this.graphColumns&&jC(r)&&!GC.test(s)&&(s="UTF-8"),s!==null&&i.push(`${Ss(this.attributeName(r))}=${kr(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=${Ss(l)}`);const a=this.keyText(s);a!==null&&o.unshift(`${Is}=${kr(a)}`);const c=`${kr(this.idText(i.src[s]))}${this.portText(this.sourcePort,s)}`,d=`${kr(this.idText(i.dst[s]))}${this.portText(this.targetPort,s)}`,u=o.length===0?"":` [${o.join(", ")}]`;yield`${n}${c} ${r} ${d}${u};
92
+ `}}keyText(e){const n=this.edgeId;return n?.isSet(e)?n.dtype==="f32"||n.dtype==="f64"?je(n.data[e]):Ql(n,e):null}portText(e,n){if(!e?.isSet(n))return"";const i=Ql(e,n);return i===null||i.length===0?"":bB(i)}idText(e){return Bi(this.snapshot.ids.idOf(e))}};function _B(t){const e=t.meta.extra[d7];return typeof e=="object"&&e!==null&&e.strict===!0}function SB(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 V_(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)&&Ql(s,r)!==null&&(i.push(s),n.delete(s))}return[...i,...n]}function Ql(t,e){switch(t.dtype){case"bool":return t.value(e)===!0?"true":"false";case"i32":case"u32":case"u8":return np(t,e,Ue);case"f32":return np(t,e,n=>_r(n,"f32"));case"f64":return np(t,e,n=>_r(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 np(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 OB(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 NB(t){if(t.dtype!=="string"&&t.dtype!=="dict")return 0;let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&Xn(t.value(n)??"")!=="string"&&e++;return e}function AB(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);Qa(Bi(r))!==r&&n++}return n}const K_=72;function TB(t){if(t.nodes.byRole("position")===null)return null;const e=t.graph.get("bb"),n=e!==null&&e.isSet(0)&&zC(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*K_:o)}return{units:n?"px":"file",...n?{}:{pxPerUnit:K_},yAxis:"up",groups:IB(t),medianNodeSize:Qm(r),...n?{tool:"graphviz"}:{}}}function IB(t){const e=t.nodes.get("bb"),n=[];for(let i=0;e!==null&&i<e.length;i++){const r=e.isSet(i)?zC(e.value(i)):null;r!==null&&n.push({node:i,box:r})}return n}function zC(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 Pe extends Error{constructor(e,n){super(e),this.name="DotSyntaxError",this.line=n}}const $B="";function Mg(t){return t>=65&&t<=90||t>=97&&t<=122||t===95||t>=128&&t!==xb}const xb=65279;function CB(t){return Mg(t)||fs(t)||t===xb}function fs(t){return t>=48&&t<=57}function vB(t){return t===32||t===9||t===11||t===12||t===xb}class WC{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:$B,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(fs(s)||s===46&&fs(e.charCodeAt(n+2)))return this.numeral(n,i);throw new Pe("unexpected '-': not an edge operator or a numeral",i)}case 34:return this.quoted(n,i);case 60:return this.html(n,i)}if(Mg(r)){let s=n+1;for(;s<e.length&&CB(e.charCodeAt(s));)s++;return this.pos=s,{kind:"id",text:e.slice(n,s),quoted:!1,html:!1,line:i}}if(fs(r)||r===46&&fs(e.charCodeAt(n+1)))return this.numeral(n,i);throw new Pe(`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&&fs(i.charCodeAt(r));)r++;if(i.charCodeAt(r)===46)for(r++;r<i.length&&fs(i.charCodeAt(r));)r++;this.pos=r;const s=i.slice(e,r),o=i.charCodeAt(r);return r<i.length&&(Mg(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 Pe("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 Pe("unterminated HTML string (missing closing '>')",n)}skipTrivia(){const{text:e}=this;for(;this.pos<e.length;){const n=e.charCodeAt(this.pos);if(vB(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 Pe("unterminated block comment",n)}}const Ot=Object.freeze({...xn,...Pn,SYNTAX:kn,EMPTY_INPUT:Mt,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,ENCODING_CONFLICT:ul,NESTING:"E_DOT_NESTING",EDGE_OPERATOR:"W_DOT_EDGE_OPERATOR",MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,NUMERAL_AMBIGUITY:"W_DOT_NUMERAL_AMBIGUITY",SUBGRAPH_ATTRIBUTES_DROPPED:"W_DOT_SUBGRAPH_ATTRIBUTES_DROPPED",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:ie,DUPLICATE_ATTRIBUTE:de,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:yn,COLUMN_RENAMED:ln,OPTION_IGNORED:Jt,ID_MERGED:Rn,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er,WIDENING_UNSUPPORTED:lf}),X_=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","errorLimit","signal","onProgress"]),q_=1024,DB=Object.freeze([".dot",".gv"]),kB=Object.freeze(["text/vnd.graphviz"]),RB="cluster",J_="cluster",LB=64,PB=4096,xB=new Set(["bgcolor","color","colorscheme","fillcolor","fontcolor","fontname","fontsize","gradientangle","label","labeljust","labelloc","pencolor","penwidth","peripheries","style","tooltip"]),MB=/^\s*(strict\s+)?(di)?graph(?=[\s{"/]|$)(?!\s*\[)/i,UB=new Set(["true","yes","1"]),GB=new Set(["n","ne","e","se","s","sw","w","nw","c","_"]),ip=String.raw`[-+]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][-+]?\d+)?`,jB=new RegExp(String.raw`^\s*(${ip})\s*,\s*(${ip})(?:\s*,\s*(${ip}))?\s*(?:(!)\s*)?$`),BC=Object.freeze({format:As,options:Object.freeze(["keepPositionSource","mismatchedEdgeOperator","positions"]),extensions:DB,mimeTypes:kB,styles:PW,positions:TB,sniff(t){const e=zB(new TextDecoder("utf-8").decode(t));return MB.exec(e)===null?0:e.includes("{")?.95:.8},async import(t,e,n){if(eo(n))return $b(BC,t,e,n);const i=Qe(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=nS(n?.mismatchedEdgeOperator),s=new te(As,i.errorLimit);Et(n,s,X_),bt(e,n,s);const o={},l=await Br(t,s,{...i,declaredEncoding:h=>o.charset=tS(h),declarationBytes:eS}),c=Z_(l,{current:s}),d=Ad(s,()=>c.next()),u=new iS(c,e,s,i,r,n?.positions!==!1,n?.keepPositionSource===!0);u.headCharset=o.charset;const f=Q_(u,s,d);if(f.kind!=="eof"){const h=Ad(s,()=>FB(c,f));s.warning("unsupported",Zn,`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=Qe(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=nS(n?.mismatchedEdgeOperator),s=new te(As,i.errorLimit);Et(n,s,X_);const o={},l=await Br(t,s,{...i,declaredEncoding:f=>o.charset=tS(f),declarationBytes:eS}),a={current:s},c=Z_(l,a),d=[];let u=Ad(s,()=>c.next());do{const f=d.length===0?s:new te(As,i.errorLimit);a.current=f;const h=e(d.length);bt(h,n,f);const p=new iS(c,h,f,i,r,n?.positions!==!1,n?.keepPositionSource===!0);p.headCharset=o.charset,u=Q_(p,f,u),F(i.signal),d.push(f.finish())}while(u.kind!=="eof");return d}});function Z_(t,e){return new WC(t,(n,i)=>{e.current.warning("validation-error",Ot.NUMERAL_AMBIGUITY,`badly delimited number ${JSON.stringify(n)} splits into two tokens (Graphviz warns the same)`,{line:i,element:n})})}function Ad(t,e){try{return e()}catch(n){throw n instanceof Pe&&t.fail(kn,n.message,{line:n.line},{line:n.line}),n}}function Q_(t,e,n){return Ad(e,()=>t.parse(n))}function FB(t,e){let n=0,i=e;for(;i.kind!=="eof";){if(Pi(i,"strict")&&(i=t.next()),Te(i,"}"))throw new Pe('unexpected "}" after the end of the graph: no "{" is open',i.line);if(!Pi(i,"graph")&&!Pi(i,"digraph"))throw new Pe(`expected "graph" or "digraph", found ${ci(i)}`,i.line);if(i=t.next(),i.kind==="id"&&(i=t.next()),!Te(i,"{"))throw new Pe(`expected "{" after the graph header, found ${ci(i)}`,i.line);for(let r=1;r>0;){if(i=t.next(),i.kind==="eof")throw new Pe('missing "}" at the end of a graph',i.line);Te(i,"{")?r++:Te(i,"}")&&r--}n++,i=t.next()}return n}const eS=64*1024;function tS(t){const e=new WC(t);let n=null,i=null;try{let r=e.next();for(;r.kind!=="eof";){if(Te(r,"["))n=i!==null&&Pi(i,"graph")?"graph":"other";else if(Te(r,"]"))n=null;else if(n!=="other"&&Pi(r,"charset")){const s=e.next(),o=Te(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 Pe))throw r}return null}function nS(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 zB(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 Pi(t,e){return t.kind==="id"&&!t.quoted&&!t.html&&t.text.toLowerCase()===e}function Te(t,e){return t.kind==="punct"&&t.text===e}function Wc(t){return t.kind==="punct"&&(t.text==="->"||t.text==="--")}function ci(t){return t.kind==="eof"?"end of input":JSON.stringify(t.text.length>40?`${t.text.slice(0,40)}...`:t.text)}function WB(t){return t?.startsWith(RB)===!0}class iS{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.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 Qn(n,i,r.onMixedDirection)}parse(e){const{lexer:n}=this;let i=e;if(i.kind==="eof"&&this.report.fail(Mt,"the input holds no graph (empty or only comments)",{line:i.line}),Pi(i,"strict")&&(this.strict=!0,i=n.next()),Pi(i,"digraph"))this.directed=!0;else if(Pi(i,"graph"))this.directed=!1;else throw new Pe(`expected "graph" or "digraph", found ${ci(i)}`,i.line);const r=i.line;i=n.next();let s=null;if(i.kind==="id"&&(s=i.text,i=n.next()),!Te(i,"{"))throw new Pe(`expected "{" after the graph header, found ${ci(i)}`,i.line);this.resolver.setHeader(this.directed,{line:r}),this.sink.setMeta({name:s,sourceFormat:As,...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(Te(i,"}")){n.next();return}if(i.kind==="eof")throw new Pe(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(Te(i,";")){n.next();continue}this.statement(e),++this.statements%LB===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 Pe(`unexpected ${ci(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 Pe(`unexpected keyword ${ci(n)} inside a graph`,n.line);return!1}idStatement(e){const{lexer:n}=this,i=this.identifier();if(Te(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(Te(n.peek(),",")){this.nodeListStatement(e,[{id:i,port:r},...this.moreNodes()]);return}if(Wc(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(;Te(this.lexer.peek(),",");){this.lexer.next();const n=this.identifier();e.push({id:n,port:this.port()})}return e}nodeListStatement(e,n){if(Wc(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 Pe(`expected an identifier, found ${ci(n)}`,n.line);if(!n.quoted||!Te(e.peek(),"+"))return n;let{text:i}=n;for(;Te(e.peek(),"+");){const r=e.next(),s=e.next();if(s.kind!=="id"||!s.quoted)throw new Pe(`expected a quoted string after "+", found ${ci(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(!Te(e.peek(),":"))return null;e.next();let{text:n}=this.identifier();if(Te(e.peek(),":")){e.next();const i=this.identifier();n+=`:${i.text}`,GB.has(i.text)||this.report.warning("validation-error",Ot.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(Pi(i,"subgraph")&&(i=n.next(),i.kind==="id"&&(r=i.text,i=n.next())),!Te(i,"{"))throw new Pe(`expected "{" to open a subgraph, found ${ci(i)}`,i.line);++this.depth>q_&&this.report.fail(Ot.NESTING,`subgraphs nested deeper than ${q_} levels (the parser recurses per level)`,{line:i.line});const s=this.newScope(e,i.line,!1,r);return WB(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!==J_&&(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){if(e.attributes.size>0){const i=[...e.attributes.keys()].join(", ");this.report.warning("unsupported",Ot.SUBGRAPH_ATTRIBUTES_DROPPED,`subgraph ${e.name===null?"(anonymous)":JSON.stringify(e.name)} is not a cluster; its attributes (${i}) cannot be represented and were dropped`,{line:e.line,element:e.name})}for(const i of e.containers)n.containers.push(i)}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<PB;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",Ot.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",Ot.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(xB.has(n.name)&&e.graphDefaults.set(n.name,n),e.root){this.setGraphAttribute(n);return}e.attributes.set(n.name,n),n.name===J_&&UB.has(n.value.trim().toLowerCase())&&(e.cluster=!0,this.ensureContainer(e))}attributeStatement(e,n,i){if(!Te(this.lexer.peek(),"[")){const s=this.lexer.peek();throw new Pe(`expected "[" after "${n}", found ${ci(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 Pe(`unknown attribute statement "${n}"`,i)}}attributeList(){const{lexer:e}=this,n=[],i=new Set;for(;Te(e.peek(),"[");)for(e.next();;){const r=e.peek();if(Te(r,"]")){e.next();break}if(Te(r,";")||Te(r,",")){e.next();continue}const s=this.identifier(),o=e.next();if(!Te(o,"="))throw new Pe(`expected "=" after attribute name ${JSON.stringify(s.text)}, found ${ci(o)}`,o.line);const l=this.identifier();i.has(s.text)&&this.report.warning("merged",Ot.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",Ot.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){Wc(this.lexer.peek())&&this.edgeStatement(e,n,i)}edgeStatement(e,n,i){const{lexer:r}=this,s=[n],o=[];for(;Wc(r.peek());){const a=r.next();o.push(this.edgeKind(a));const c=r.peek();if(Te(c,"{")||Pi(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 Pe(`${i} (mismatchedEdgeOperator: "error")`,e.line);case"header":return this.report.warnOnce("coercion",Ot.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",Ot.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",Ot.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=Vn(f,this.report)}catch(b){this.report.recordError(b,c),this.report.counts.skippedEdges++;return}const h=l.get(Is),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?Ot.KEY_MERGED:Ot.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===Me?this.sink.setNodeValue(this.nodeLabel(),e,i):n===Ys&&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===Me?this.setEdgeText(this.edgeLabel(),e,i):n===Is?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",Ot.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===Me?this.sink.setGraphValue(e.name,e.value,{dtype:"string",origin:Ii}):this.sink.setGraphValue(e.name,of(e.value),{dtype:Xn(e.value),origin:Ii})}catch(n){this.report.recordError(n,{line:e.line,element:e.name})}}setPosition(e,n,i,r){const s=jB.exec(n);if(s===null){this.report.warning("validation-error",Ot.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",Ot.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",Ot.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(c7,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:Me,dtype:"string",nullable:!0,role:"label",origin:Ii})),this.nodeLabelHandle}edgeLabel(){return this.edgeLabelHandle===A&&(this.edgeLabelHandle=this.declare("edge",{name:Me,dtype:"string",nullable:!0,role:"label",origin:Ii})),this.edgeLabelHandle}positionColumn(e){return this.positionHandle===A&&(this.positionHandle=this.declare("node",{name:this.keepPositionSource?a7:Ys,dtype:"f64",components:3,nullable:!0,mutable:!0,role:"position",origin:{...Ii,type:"point"},extra:{sourceDims:e,units:"file"}})),this.positionHandle}clusterColumn(){return this.clusterHandle===A&&(this.clusterHandle=this.declare("node",{name:Ts,dtype:"bool",nullable:!0,origin:Ii})),this.clusterHandle}parentColumn(){return this.parentHandle===A&&(this.parentHandle=this.declare("node",{name:eC,dtype:"u32",nullable:!0,role:"parent",refersTo:"node",origin:Ii})),this.parentHandle}keyColumn(){return this.keyHandle===A&&(this.keyHandle=this.declare("edge",{name:Is,dtype:"string",nullable:!0,role:"id",origin:{...Ii,id:Is}})),this.keyHandle}sourcePortColumn(){return this.sourcePortHandle===A&&(this.sourcePortHandle=this.declare("edge",{name:tC,dtype:"string",nullable:!0,role:"sourcePort",origin:Ii})),this.sourcePortHandle}targetPortColumn(){return this.targetPortHandle===A&&(this.targetPortHandle=this.declare("edge",{name:nC,dtype:"string",nullable:!0,role:"targetPort",origin:Ii})),this.targetPortHandle}textWriter(e,n){const i=e==="node"?this.nodeWriters:this.edgeWriters;let r=i.get(n);return r===void 0&&(r=new Ey(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 fe(this.sink,e,i,this.report,{element:n.name}).handle}}const xi="gexf",BB={"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"}},HB=new Set(["integer","double","date","dateTime"]),YB=new Set(["static","dynamic","slice"]),VB=new Set(["interval","timestamp"]),Uf="viz",Ve={format:xi},Mr={format:xi,namespace:Uf},ae=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"}),Nt=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"}),HC=new Set([...Object.values(ae),ae.start+zi,ae.end+zi,ae.timestamp+zi]),YC=new Set([...Object.values(Nt),Nt.start+zi,Nt.end+zi,Nt.timestamp+zi]),Ft={label:{name:ae.label,dtype:"string",role:"label",nullable:!0,origin:Ve},parent:{name:ae.parent,dtype:"u32",role:"parent",refersTo:"node",nullable:!0,origin:Ve},parents:{name:ae.parents,dtype:"list",itemDtype:"u32",role:"parents",refersTo:"node",nullable:!0,origin:Ve},start:{name:ae.start,dtype:"f64",role:"start",nullable:!0,origin:Ve},end:{name:ae.end,dtype:"f64",role:"end",nullable:!0,origin:Ve},timestamp:{name:ae.timestamp,dtype:"f64",role:"timestamp",nullable:!0,origin:Ve},spells:{name:ae.spells,dtype:"list",itemDtype:"f64",itemComponents:2,role:"spells",nullable:!0,origin:Ve},timestamps:{name:ae.timestamps,dtype:"list",itemDtype:"f64",role:"timestamps",nullable:!0,origin:Ve},open:{name:ae.open,dtype:"u8",role:"open",nullable:!0,origin:Ve},spellsOpen:{name:ae.spellsOpen,dtype:"list",itemDtype:"u8",role:"spellsOpen",nullable:!0,origin:Ve},position:{name:ae.position,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,origin:Mr,extra:{units:"file",originUnplaced:!0}},color:{name:ae.color,dtype:"f32",components:4,role:"color",nullable:!0,origin:Mr},size:{name:ae.size,dtype:"f32",role:"size",nullable:!0,origin:Mr},shape:{name:ae.shape,dtype:"dict",role:"shape",nullable:!0,origin:Mr},shapeUri:{name:ae.shapeUri,dtype:"string",nullable:!0,origin:Mr}},wn={id:{name:Nt.id,dtype:"string",role:"id",unique:!0,nullable:!0,origin:Ve},label:{name:Nt.label,dtype:"string",role:"label",nullable:!0,origin:Ve},kind:{name:Nt.kind,dtype:"dict",role:"kind",nullable:!0,origin:Ve},start:{name:Nt.start,dtype:"f64",role:"start",nullable:!0,origin:Ve},end:{name:Nt.end,dtype:"f64",role:"end",nullable:!0,origin:Ve},timestamp:{name:Nt.timestamp,dtype:"f64",role:"timestamp",nullable:!0,origin:Ve},spells:{name:Nt.spells,dtype:"list",itemDtype:"f64",itemComponents:2,role:"spells",nullable:!0,origin:Ve},timestamps:{name:Nt.timestamps,dtype:"list",itemDtype:"f64",role:"timestamps",nullable:!0,origin:Ve},open:{name:Nt.open,dtype:"u8",role:"open",nullable:!0,origin:Ve},spellsOpen:{name:Nt.spellsOpen,dtype:"list",itemDtype:"u8",role:"spellsOpen",nullable:!0,origin:Ve},color:{name:Nt.color,dtype:"f32",components:4,role:"color",nullable:!0,origin:Mr},thickness:{name:Nt.thickness,dtype:"f32",role:"thickness",nullable:!0,origin:Mr},shape:{name:Nt.shape,dtype:"dict",role:"shape",nullable:!0,origin:Mr}},Gf=1,jf=2,Ug="temporal:",xe=Object.freeze({element:"element",start:"start",end:"end",value:"value",open:"open",startText:`start${zi}`,endText:`end${zi}`,valueText:`value${zi}`});function Gg(t,e){return`${Ug}${t}:${e}`}function KB(t){if(!t.startsWith(Ug))return null;const e=t.slice(Ug.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 rS(t,e,n){const i=[{name:xe.element,dtype:"u32",refersTo:t,nullable:!1},{name:xe.start,dtype:"f64",role:"start",nullable:!0},{name:xe.end,dtype:"f64",role:"end",nullable:!0},{name:xe.value,...e,nullable:!0},{name:xe.startText,dtype:"string",role:FA,nullable:!0,extra:{for:xe.start}},{name:xe.endText,dtype:"string",nullable:!0,extra:{for:xe.end}},{name:xe.open,dtype:"u8",role:"open",nullable:!0}];return n&&i.push({name:xe.valueText,dtype:"string",nullable:!0,extra:{for:xe.value}}),i}const VC=new Set(["integer","long","double","float","boolean","string","anyURI"]),XB=new Set([...VC,"bigdecimal","biginteger","byte","char","short","date","dateTime"]);function Td(t,e){return(e==="1.2"?VC:XB).has(t)}function qB(t,e){return t.startsWith("list")&&t.length>4&&Td(t.slice(4),"1.3")}function sS(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 JB=[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],ZB=[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],QB=1.1640625;function eH(t){let e=0;for(const n of t){const i=n.codePointAt(0)??0;i>=32&&i<127?e+=JB[i-32]:e+=i>=160&&i<592?ZB[i-160]:1e3}return e/1e3}const rp=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 Id{constructor(e={}){this.values={...rp,...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(rp[e]??0)}font(e){const n=`${e}.label.font`,i=this.on(`${e}.label.customFont`)?this.values[n]??"":rp[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 tH(t,e){return t.length>=e+3?`${t.slice(0,e)}...`:t}function Il(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 oS(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(tH(o,r)):o)}function nH(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 iH=ae.label,KC="https://graphty.app/ns/gexf",rH=Object.freeze({tool:"gephi",node:Object.freeze(["label","fill","fillOpacity","width","height","shape","image"]),edge:Object.freeze(["color","opacity","width","lineStyle"]),block:"native"}),Mb="#000000",lS="directed",aS="label-avoid-overlap",cS="gephi-hidden",sH="end-colors",oH=["width","weight-width"],Ub=20,XC=1.3,lH=new Map([["ellipse","disc"],["rectangle","square"],["triangle","triangle"],["diamond","diamond"]]),aH=new Map([["round-rectangle","square"],["vee","triangle"]]),cH=new Set(["solid","dotted","dashed","double"]);function qC(t){const e=lH.get(t);return e===void 0?{value:aH.get(t)??"disc",exact:!1}:{value:e,exact:!0}}function JC(t){return cH.has(t)?{value:t,exact:!0}:{value:t==="dash-dot"||t==="long-dash"?"dashed":"solid",exact:!1}}const jg={node:["color","size","shape","shape.uri"],edge:["color","thickness","shape"]};function dH(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 $s(t,e,n){const i=(e==="node"?t.nodes:t.edges).get(n);return i!==null&&i.meta.origin?.namespace===Uf?n:null}function dS(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=$s(t,e,"color"),c=$s(t,e,e==="node"?"size":"thickness"),d=$s(t,e,"shape"),u=e==="node"?$s(t,e,"shape.uri"):null,f=e==="node"?r.byRole("label"):null;for(let h=0;h<s;h++)f!==null&&uH(l,f,h),a!==null&&hH(l,a,h),c!==null&&pH(l,c,h),d!==null&&gH(l,d,h)&&u!==null&&fH(l,u,h);return o}function uH(t,e,n){const i=nt(K(e.value(n)),t.site(n,"label"));i!==null&&(t.column("label")[n]=i)}function fH(t,e,n){const i=K(t.table.value(e,n));typeof i=="string"&&i.length>0&&(t.column("image")[n]=i)}function hH(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=$e({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 pH(t,e,n){const i=V(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 gH(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]=oe(r,i,"gexf",t.site(n,r)),typeof i=="string"&&i.toLowerCase()==="image"}function mH(t,e){const n=t.edgeCount,i=rv(t);if(!e)return EH(t);const r=wH(t),s=t.edges.byRole("directed"),o=t.edges.byRole("mutual"),l=t.edges.byRole("kind"),a=ZC(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=bH(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),I=r!=="undirected"&&_!==S&&!y;c.directed[m]=I;const D=`${l?.isSet(m)===!0?String(l.value(m)):""}\0${yH(_,S,I)}`,P=d.get(D);P===void 0?(d.set(D,m),u.push(m),c.weight[m]=a(m)):(c.weight[P]+=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 yH(t,e,n){return n?`${String(t)}>${String(e)}`:`${String(Math.min(t,e))}-${String(Math.max(t,e))}`}function bH(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 EH(t){const e=rv(t),n=ZC(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 wH(t){const e=t.meta.extra.gexf?.defaultedgetype;return typeof e=="string"?e.trim().toLowerCase():null}function ZC(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(Gg("edge",n.meta.name));if(i!==void 0){const s=i.get(xe.element),o=i.get(xe.start),l=i.get(xe.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=wt(t);return s=>{const o=Number(r.text(s)??1);return Number.isFinite(o)?o:1}}function QC(t,e){const n=Number.parseInt((typeof t=="string"?t:Mb).slice(1),16),i=typeof e=="number"?Math.round(e*255):255;return[n>>16&255,n>>8&255,n&255,i]}function $l(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 tl(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 Gb(t,e,n,i,r){const s=r?.preview??new Id,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)=>QC(e.fill?.[u],e.fillOpacity?.[u])),c=_H(o,t,a,e,s);return $H(l,t,a,e,n,r,s),SH(o,a,c,s,r?.overlapSettled===!0),OH(o,a,e,s),{node:o,edge:l}}function Uo(t,e){const n=t.width?.[e];return typeof n=="number"?n:Ub}function _H(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=>$l(Il(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*Uo(i,h):Math.min(d,Uo(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*Uo(i,h))):u.size);return tn(t,"node",["labelSize","size-label"],f,"NODE_SIZE"),f}function SH(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=>$l(Il(s,l)??[0,0,0])),"NODE_LABEL_COLOR"),nv(t,"node",e,n,i);const o=i.font("node");tl(t,"node","preview-label",tv(o,i.on("node.label.customFont"))),i.on("node.label.avoidOverlap")&&!r&&(t.columns.set(aS,n.map(()=>!0)),t.rules.push({id:"node.tool.label-avoid-overlap",target:"node",role:"group",origin:"tool",where:{has:{style:aS}},set:{labelAvoidOverlap:!0}}))}function ev(t){return Math.floor(Math.min(Math.max(t,0),100)/100*255+1e-9)/255}function OH(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=>$l(Il(r,s)??s)),"LABEL_BOX"),tn(t,"node",["labelBorderWidth","preview-box-width"],e.map((s,o)=>.04*Uo(n,o)),"LABEL_BOX"),tl(t,"node","preview-box",{labelBorderOpacity:ev(i.num("node.label.box.opacity")),labelPadding:0,labelLineHeight:1})}function tv(t,e){return e?{labelFont:t.family,...t.bold?{labelWeight:"bold"}:{},...t.italic?{labelItalic:!0}:{}}:{}}function nv(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=>$l(Il(o,l)??[255,255,255])),"LABEL_OUTLINE"),tl(t,e,"preview-outline",{labelOutlineOpacity:ev(r.num(`${e}.label.outline.opacity`))})}function NH(t,e,n,i){const r=iv(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((k,U)=>{const Y=n?.[U];return s((typeof Y=="number"?Y:Ub)/2)}),d=c.map(k=>s(l?s(a*k)*s(.05):a*s(1+s(k*s(1e-5))))),u=d.map((k,U)=>U).sort((k,U)=>c[U]-c[k]),f=new Map;u.forEach(k=>f.set(Math.round(d[k]),d[k]));const h=r.map(k=>[k?.[0]??0,-(k?.[1]??0)]);let[p,g,m,y]=[1/0,1/0,-1/0,-1/0];for(const[k,U]of h)[p,g,m,y]=[Math.min(p,k),Math.min(g,U),Math.max(m,k),Math.max(y,U)];const[b,_]=[p-o,g-o],S=Math.ceil((m+o-b)/o),I=Math.ceil((y+o-_)/o),T=new Set,D=e.map(()=>!1),P=[...u].sort((k,U)=>d[U]-d[k]);for(const k of P){const U=e[k];if(typeof U!="string"||U.trim()==="")continue;const Y=f.get(Math.round(d[k]))??d[k],me=[eH(U)*Y/2,QB*Y/2],Oe=AH({min:[b,_],size:o,cols:S,rows:I},[h[k][0]-me[0],h[k][1]-me[1]],[h[k][0]+me[0],h[k][1]+me[1]]);Oe.some(Fe=>T.has(Fe))?D[k]=!0:Oe.forEach(Fe=>T.add(Fe))}return D}function AH(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 uS=1.2;function iv(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 TH(t,e,n,i,r){const s=iv(t),o=r.num("edge.radius"),l=r.num("arrow.size"),a=2*Math.asin(Math.min(1,uS/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/uS,y=S=>S>=m*a?1/0:2*Math.atan2(S/2,Math.sqrt(m*m-S/2*(S/2))),b=o+Uo(e,u)/2,_=o+Uo(e,f)/2+(n[d]?l*i[d]:0);return y(b)+y(_)>=a?"line":null})}const fS=96;function IH(t,e,n){const i=$s(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:Ub/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*XC*e[l])/c,u=[];for(let f=0;f<=fS;f++){const h=5*Math.PI/4-2*Math.PI*f/fS;u.push(`${s(d+d*Math.cos(h))},${s(d+d*Math.sin(h))}`)}return u.join(" ")})}function $H(t,e,n,i,r,s,o){const l=mH(e,s!==void 0),a=o.num("arrow.size");l.directed.some(Boolean)&&a>0&&(t.columns.set(lS,l.directed.map(p=>p?!0:null)),t.rules.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:lS}},set:{targetArrow:"triangle",...a===3?{}:{arrowSize:a/3}}}));const c=o.on("edge.show")?l.hidden:l.hidden.map(()=>!0),d=nH(l.weight,c.map(p=>!p),o);tn(t,"edge",oH,sp(r.width,e.edgeCount,p=>e.edgeSource(p)===e.edgeTarget(p)?XC*d[p]:d[p]),"EDGE_WEIGHT"),tn(t,"edge",["bends","self-loop"],IH(e,d,c),"NODE_SIZE");const u=o.on("edge.curved")?TH(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(cS,c.map(p=>p?!0:null)),t.rules.push({id:"edge.tool.gephi-hidden",target:"edge",role:"group",origin:"tool",where:{has:{style:cS}},set:{visible:!1}}));const f=CH(e,n,s,o);tn(t,"edge",["color",sH],sp(r.color,e.edgeCount,p=>$l(f[p])),"END_NODE_COLORS"),tn(t,"edge",["opacity","end-opacity"],sp(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"),tl(t,"edge","preview-curve",o.on("edge.curved")?{}:{curved:!1});const h=o.num("edge.radius");tl(t,"edge","preview-radius",h>0?{nodeGap:h}:{}),vH(t,f,s,o)}function CH(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 QC(typeof c=="string"?c:Mb,typeof d=="number"?d:null)},l=Il(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 vH(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=>$l(Il(s,o)??[0,0,0])),"EDGE_LABEL_COLOR"),nv(t,"edge",e,e.map(()=>r.size),i),tl(t,"edge","preview-label",{labelSize:r.size,labelPosition:"center",...tv(r,i.on("edge.label.customFont"))})}function DH(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 rv(t){const e=t.edges.byRole("pair");return n=>e?.isSet(n)===!0?Math.min(n,e.value(n)):n}function sp(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 kH(t,e){const n=new re,i=dS(t,"node",n,e),r=dS(t,"edge",n,e),{block:s,preview:o}=RH(e.kept),l=i.fillOpacity,a={color:r.color,opacity:r.opacity};s===null?PH(i,r):xH(t,s,i,r);const c=oS(i.label,o,"node",s!==null),d=s===null&&c!==void 0&&o.on("node.label.avoidOverlap")?NH(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=oS(LH(t),o,"edge",s!==null);u!==void 0&&(r.label=u);const f=Gb(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:jg.node.filter(h=>$s(t,"node",h)!==null),edge:jg.edge.filter(h=>$s(t,"edge",h)!==null)}}}function RH(t){if(typeof t=="string")return{block:t,preview:new Id};if(typeof t=="object"&&t!==null){const{block:e,gephiPreview:n}=t;return{block:typeof e=="string"?e:null,preview:new Id(n)}}return{block:null,preview:new Id}}function LH(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 PH(t,e){delete t.shape,delete t.image,delete t.fillOpacity,delete e.color,delete e.opacity,delete e.width,delete e.lineStyle}function xH(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}=qC(String(l("shape")));return r.get(a)??a},width:s,height:s,lineStyle:l=>JC(String(l("lineStyle"))).value};no(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 MH(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 sv(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 Al,u=n("node","shape").map((p,g)=>GH(p,typeof s[g]=="string",d)),f=n("node","width").map((p,g)=>FH(p,c[g],d)),h=n("edge","lineStyle").map(p=>jH(p,d));return{snapshot:UH(t,e),blockElement:`<graphty:styles xmlns:graphty="${KC}" name="${Z}">${ov(e.block)}</graphty:styles>`,notes:d.notes("GEXF"),node(p,g){const m=f[p],y=u[p];return hS(i[p],r[p],g)+(m===null?"":`${g}<viz:size value="${String(m/2)}"/>
93
+ `)+pS(y,y==="image"?String(s[p]):null,g)},edge(p,g){const m=a[p],y=o[p],b=S=>String(i[S]??Mb);return(typeof y=="string"&&y===DH(b(t.edgeSource(p)),b(t.edgeTarget(p)))&&(l[p]??1)===1?"":hS(y,l[p],g))+(typeof m=="number"?`${g}<viz:thickness value="${String(m)}"/>
94
+ `:"")+pS(h[p],null,g)}}}function UH(t,e){const n=t.withColumns();for(const r of["node","edge"]){const s=r==="node"?n.nodes:n.edges;for(const o of jg[r])s.get(o)?.meta.origin?.namespace===Uf&&s.remove(o);for(const[o,l]of e.tags[r]){const a=MH(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(iH,i,{dtype:"string",role:"label"},{replaceRole:!0}),n}function GH(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=qC(t);return i.exact||n.add("node","shape",t),i.value}function jH(t,e){if(typeof t!="string")return null;const n=JC(t);return n.exact||e.add("edge","lineStyle",t),n.value}function FH(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 hS(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}/>
95
+ `}function pS(t,e,n){return t===null?"":e===null?`${n}<viz:shape value="${t}"/>
96
+ `:`${n}<viz:shape value="${t}" uri="${ov(e)}"/>
97
+ `}function ov(t){return t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;")}const lv="E_NOT_GEXF",Fg="E_GEXF_MISSING_NODES",av="E_GEXF_EDGE_TYPE",cv="E_GEXF_ATTRIBUTES_CLASS",dv="E_GEXF_ATTRIBUTE_ID",No="W_GEXF_HEADER_VALUE",uv="W_GEXF_ATTRIBUTE_TYPE",zg="W_GEXF_UNKNOWN_ATTRIBUTE",Wg="W_GEXF_ATTVALUE_SHAPE",fv="W_GEXF_TIMED_VALUE_ON_STATIC",hv="W_GEXF_WEIGHT_IGNORED",pv="W_GEXF_VIZ_SKIPPED",gv="W_GEXF_UNKNOWN_PID",mv="W_GEXF_VIZ_DYNAMIC_DROPPED",zH="W_GEXF_SPELL_OPEN_DROPPED",Bg="W_GEXF_VIZ_VALUE",yv="W_GEXF_OPEN_BOUND_CONFLICT",bv="W_GEXF_TIMESTAMP_CONFLICT",Hg="W_GEXF_VALUE_OUTSIDE_OPTIONS",WH=new Set(["1.0","1.1","1.2","1.3"]);function BH(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 HH(t){return t!==null&&/(gexf\.net\/.*viz|gephi\.org\/gexf\/viz)\/?$/.test(t)}const YH=16,VH={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"])},KH=/^\d+$/,XH=/^-?\d{4,}-\d{2}-\d{2}(.*)$/s,qH=/^T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?/,JH=/^(?:Z|[+-]\d{2}:\d{2})?$/;function ZH(t){const e=XH.exec(t);if(e===null)return!1;const n=qH.exec(e[1])?.[0]??"";return JH.test(e[1].slice(n.length))}const gS=new Set(["directed","undirected","mutual"]);function op(t){const e=t.trim().toLowerCase();return QH.get(e)??e}const QH=new Map([["dir","directed"],["undir","undirected"],["double","mutual"]]),eY=64,tY=new Set(["id","label","pid","start","end","timestamp","startopen","endopen","timestamps","intervals"]),nY=new Set(["id","source","target","type","label","weight","kind","start","end","timestamp","startopen","endopen","timestamps","intervals"]),iY=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","errorLimit","signal","onProgress"]);class Le{constructor(e,n){this.handle=A,this.domain=e,this.decl=n}get(e,n,i){return this.handle===A&&(this.handle=fe(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 mo{constructor(e,n){this.companion=A,this.domain=e,this.name=n.name,this.column=new Le(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=yy(e,this.domain,WA(this.name),n)),this.domain==="node"?e.setNodeValue(this.companion,i,r.text):e.setEdgeValue(this.companion,i,r.text))}}class rY{constructor(e,n,i,r){this.ctx=[],this.timeFormat=null,this.defaultKind="undirected",this.meta={sourceFormat:xi},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 Le("node",Ft.parent),this.parentsColumn=new Le("node",Ft.parents),this.positionColumn=null,this.sizeColumn=new Le("node",Ft.size),this.shapeUriColumn=new Le("node",Ft.shapeUri),this.thicknessColumn=new Le("edge",wn.thickness),this.edgeIdColumn=new Le("edge",wn.id),this.edgeKindColumn=new Le("edge",wn.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 Qn(e,n,i.onMixedDirection),this.nodeColumns={label:new Le("node",Ft.label),start:new mo("node",Ft.start),end:new mo("node",Ft.end),timestamp:new mo("node",Ft.timestamp),spells:new Le("node",Ft.spells),spellsOpen:new Le("node",Ft.spellsOpen),timestamps:new Le("node",Ft.timestamps),open:new Le("node",Ft.open),color:new Le("node",Ft.color),shape:new Le("node",Ft.shape)},this.edgeColumns={label:new Le("edge",wn.label),start:new mo("edge",wn.start),end:new mo("edge",wn.end),timestamp:new mo("edge",wn.timestamp),spells:new Le("edge",wn.spells),spellsOpen:new Le("edge",wn.spellsOpen),timestamps:new Le("edge",wn.timestamps),open:new Le("edge",wn.open),color:new Le("edge",wn.color),shape:new Le("edge",wn.shape)}}start(e,n,i,r=""){const s=this.ctx.at(-1)??null,o=vs(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(lv,`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",Fg,"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<=au&&(this.styleBlock+=e.slice(0,au+1-this.styleBlock.length));return;case 14:return;default:Sr(e)||this.report.warnOnce("validation-error",Xu,"text where GEXF allows only elements was ignored",{line:n})}}finish(){this.graphSeen||this.report.fail(rs,"the document has no <graph> element");for(const[e,n]of this.unknownOverflow)this.report.warning("unsupported",zd,`${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,WH.has(r)||this.report.warning("validation-error",No,`<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=BH(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,ZH(s.trim())||this.report.warning("validation-error",No,`<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",Zn,"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===KC&&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":gS.has(op(s))?this.defaultKind=op(s):(this.defaultKind=this.options.defaultDirected?"directed":"undirected",this.warnHeader("defaultedgetype",s,i));const o=e.get("mode")??e.get("type");o!==void 0&&(YB.has(o)?r.mode=o:this.warnHeader("mode",o,i));const l=e.get("timeformat");l!==void 0&&(HB.has(l)?(this.timeFormat=l,r.timeFormat=this.timeFormat):this.warnHeader("timeformat",l,i));const a=e.get("timerepresentation");a!==void 0&&(VB.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",No,`<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",Fg,"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",Us,`<${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=KH.test(r)?Number(r):Number.NaN;if(!Number.isSafeInteger(s)||s>cA)return this.report.warning("validation-error",Wd,`<${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",Wd,`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",cv,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",de,`${e} attribute "${n}" is declared twice; the first declaration is kept`,i),!0):(this.unknownAttributes.has(`${e}:${n}`)&&r.warning("missing-value",zg,`${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"||!by(a,s.weightFrom))return!1;if(this.weightAttr!==null)return i.warning("validation-error",de,`edge attribute "${l}" is also titled ${a}; attribute "${this.weightAttr.id}" is the weight, "${l}" is kept as a column`,n),!1;const u=pa({format:xi,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:xi,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",dv,"<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",uv,`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"?HC:YC,m=s==="edge"&&this.weightAttr!==null?r.weightFrom:null,y=D=>g.has(D)||p.has(D)||D===m,b={format:xi,id:a,title:u,type:f,defaultText:e.defaultText,optionsText:e.optionsText,listSyntax:"gexf",dynamic:o,long:r.long,taken:y},_=pa(b);for(const D of _.issues)n.warning(D.category,D.code,D.message,c);const S=fe(i,s,_.decl,n,c);p.add(S.decl.name);let I=null;_.companion!==null&&(I={..._.companion,name:`${S.decl.name}.text`,extra:{for:S.decl.name}},p.add(I.name));const T={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:I,companion:A,dynamic:o,valueDecl:T,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,tY,"node",l),o===void 0){i.error("missing-value",at,"<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",No,`node id "${o}" is not an integer although the graph declares idtype="integer"; ids follow the ids option`,l,`${No}: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",Mi,"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(!mS(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",Mi,"<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",fl,`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",gv,`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",Mi,`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",Mi,`<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??sY(s,o),this.countInSection("edge"),this.checkAttributeNames(e,nY,"edge",a),s===void 0||o===void 0){i.error("missing-value",Jn,`<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",Oi,`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=op(i);return gS.has(r)?r:(this.report.error("validation-error",av,`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",hv,"the weight attribute is ignored because weightFrom is null; edges are unweighted",n);return}const r=Vn(i,this.report);return this.checkOverflow(i,n),r}checkOverflow(e,n){Gp(e)&&this.report.warnOnce("precision",ie,`weight ${e.trim()} is beyond the double range and is stored as Infinity`,n,`${ie}: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(!mS(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",Wg,"<attvalue> without a for attribute",u);return}const f=i.get("value");if(f===void 0){s.warning("missing-value",Wg,`<attvalue for="${d}"> without a value attribute`,u);return}Bc(i)||(this.attvalueIds.has(d)&&s.warning("validation-error",de,`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){Bc(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",zg,`<attvalue for="${d}"> names an undeclared ${l} attribute; its values are dropped`,{...u,element:d}));return}Bc(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=Vn(e,this.report);s!==void 0&&(this.checkOverflow(e,n),i.xmlWeight!==null&&this.report.warning("validation-error",de,`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=jp(i,o);this.setCell(n,e.handle,r,a.value),a.text!==null&&e.companionDecl!==null&&(e.companion===A&&(e.companion=yy(this.sink,n,e.companionDecl,this.report)),this.setCell(n,e.companion,r,a.text));return}const l=ga(i,o,e.listSyntax);Jd(o,i)?this.report.warning("precision",ie,`long value ${i.trim()} of "${e.name}" exceeds 2^53 and was rounded`,s):typeof l=="number"&&Gp(i)&&this.report.warnOnce("precision",ie,`values of "${e.name}" beyond the double range (${i.trim()}) are stored as Infinity`,s,`${ie}: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",Hg,`"${o}" is not among the options of attribute "${e.name}"; the value is kept`,i,`${Hg}:${e.name}`)}writeTimedValue(e,n,i,r,s,o){const{sink:l,report:a}=this;e.dynamic||a.warnOnce("validation-error",fv,`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(Gg(n,e.name),rS(n,e.valueDecl,d)));let u,f=null;if(d){const p=jp(r,c);({value:u}=p),f=p.text}else u=ga(r,c,e.listSyntax),Jd(c,r)&&a.warning("precision",ie,`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(Gg("edge",this.options.weightFrom??"weight"),rS("edge",{dtype:"f64",origin:{format:xi,id:s.id,type:s.spec.declared}},!1)));const l=Vn(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=Xi(o,this.timeFormat),r=i,(e.has("start")||e.has("end")||e.has("startopen")||e.has("endopen"))&&this.report.warnOnce("validation-error",bv,"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=Xi(l,this.timeFormat),a!==void 0&&this.warnOpenConflict("start",n)):a!==void 0&&(i=Xi(a,this.timeFormat),s|=Gf);const c=e.get("end"),d=e.get("endopen");return c!==void 0?(r=Xi(c,this.timeFormat),d!==void 0&&this.warnOpenConflict("end",n)):d!==void 0&&(r=Xi(d,this.timeFormat),s|=jf),i.value>r.value?(this.report.error("validation-error",ne,`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",yv,`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,Xi(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=ha(yS(l),"brackets");i.timestamps.set(s,o,n,c.map(d=>Xi(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 yS(e).split(";")){if(r.trim().length===0)continue;const s=ha(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=[Xi(s[0],this.timeFormat).value,Xi(s[1],this.timeFormat).value];if(o[0]>o[1]){this.report.error("validation-error",ne,`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=$i(e,"x"),s=$i(e,"y"),o=e.has("z")?$i(e,"z"):0;this.positionColumn??=new Le("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",pv,"viz elements are skipped (option viz: false)",o);return}Bc(i)&&a.warnOnce("unsupported",mv,"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,$i(i,"value"),o);break;case"thickness":this.thicknessColumn.set(l,a,s,$i(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",Bg,`<${e}> skipped: ${d.message}`,o)}}vizColor(e,n,i){const r=e.get("hex");let s;if(r!==void 0){const l=dH(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]=$i(e,"a"))}else s=[$i(e,"r"),$i(e,"g"),$i(e,"b")],s.push(e.has("a")?$i(e,"a"):1);const o=[255,255,255,1];return s.some((l,a)=>l<0||l>o[a])&&(this.report.warning("validation-error",Bg,`<${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",$t,`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>YH){this.unknownOverflow.set(i,(this.unknownOverflow.get(i)??0)+1);continue}this.report.warning("unsupported",zd,`attribute ${s} of <${i}> is not GEXF and was ignored`,{...r,element:s})}}}checkAttributes(e,n,i){this.checkAttributeNames(n,VH[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>=eY&&(this.elementsSinceCheck=0,F(this.options.signal))}}function mS(t,e){return HH(e)||e===null&&t.startsWith("viz:")}function sY(t,e){return`${t??"?"}->${e??"?"}`}function Bc(t){return t.has("start")||t.has("end")||t.has("timestamp")||t.has("startopen")||t.has("endopen")}function yS(t){let e=t.trim();return e.startsWith("<")&&(e=e.slice(1)),e.endsWith(">")&&(e=e.slice(0,-1)),e}function $i(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=gy(n);if(Number.isNaN(i))throw new N("E_COLUMN_TYPE",`viz ${e}="${n}" is not a number`,{attribute:e});return i}const oY=/^\uFEFF?\s*</;function lY(t){const e=hT(t);return oY.test(e)?/<(\w+:)?gexf[\s>]/.test(e)?1:e.includes("gexf.net")?.8:0:0}function aY(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 cY(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 dY=Object.freeze({format:xi,options:Object.freeze(["viz","gephiPreview"]),extensions:Object.freeze([".gexf"]),mimeTypes:Object.freeze(["application/gexf+xml","application/xml","text/xml"]),sniff:lY,styles:kH,async import(t,e,n){const i=Qe(n,{ids:"canonical",defaultDirected:!1,weightFrom:"weight",addMissingNodes:!1}),r=aY(n),s=new te(xi,i.errorLimit);bt(e,n,s,!0),Et(n,s,iY);const o=new rY(e,s,i,r);try{await uf(Nr(t,s,{...i,declaredEncoding:df,xml:!0}),o)}catch(a){throw a instanceof Ay&&s.fail(Mt,"the input is empty (no markup at all)",{line:a.line}),a instanceof ee&&s.fail(a instanceof cf?Ku:Vu,a.message,{line:a.line}),a}o.finish();const l=cY(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}),uY=["f32","f64","i32","bool","dict","string"],jb=Xe({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"optional",idCharset:"any",dtypes:uY,lists:!0,defaults:!0,options:!0,hierarchy:!0,temporal:"dynamic-values",positions:!0,viz:!0}),fY=Xe({...jb,multiEdges:!1,edgeIds:"required"}),hY=new Set(["directed","pair","mutual","weight","timeText"]),pY="weight",dc=new Set(["f32","f64","i32","u32","u8"]),gY=new Set(["string","dict"]);function mY(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 Ev(t,e){const n=mY(e),i=dt(e),s=[...Un(t,n==="1.2"?fY:jb,i,{openIntervals:n==="1.2",temporalText:!0,positionDtype:"f64",roles:wv,roleNames:n==="1.2"?EY:_v})],o=(y,b,_=null,S=null)=>{s.push(Object.freeze({code:y,message:b,column:_,count:S}))};s.push(...Cy(t));let l=0;for(let y=0;y<t.nodeCount;y++){const b=t.ids.idOf(y);(typeof b=="number"?!Number.isSafeInteger(b):Qd(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=_Y(t,n,o),d=_S(t.nodes,"node",o),u=_S(t.edges,"edge",o),f=NS(t,"node",d,c.get("node")??new Map,n,o),h=NS(t,"edge",u,c.get("edge")??new Map,n,o),p=bS(d)||bS(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);ea(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 bS(t){return t.start!==null||t.end!==null||t.timestamp!==null||t.spells!==null||t.timestamps!==null}function Cs(t){return dc.has(t.dtype)&&t.meta.components===1}function ES(t,e){return dc.has(t.dtype)&&e.includes(t.meta.components)}function lp(t){return gY.has(t.dtype)}function wS(t,e){return t.dtype==="list"&&t.meta.itemDtype!==null&&dc.has(t.meta.itemDtype)&&(t.meta.itemComponents??1)===e}function yY(t,e,n){switch(t){case"label":case"shape":return lp(e);case"kind":return n==="edge"&&lp(e);case"id":return n==="edge"&&(lp(e)||Cs(e));case"start":case"end":case"timestamp":case"open":return Cs(e);case"size":return n==="node"&&Cs(e);case"thickness":return n==="edge"&&Cs(e);case"spells":return wS(e,2);case"spellsOpen":return e.dtype==="list"&&e.meta.itemDtype==="u8";case"timestamps":return wS(e,1);case"position":return n==="node"&&ES(e,[2,3]);case"color":return ES(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 bY=new Set(["position","color","size","thickness"]),wv=new Set(["label","id","kind","start","end","timestamp","spells","spellsOpen","timestamps","open","position","color","size","shape","thickness","parent","parents"]),_v=Object.freeze({label:ae.label,id:"id",kind:"kind",start:ae.start,end:ae.end,timestamp:ae.timestamp,spells:ae.spells,spellsOpen:ae.spellsOpen,timestamps:ae.timestamps,open:ae.open,position:ae.position,color:ae.color,size:ae.size,shape:ae.shape,thickness:"thickness",parent:ae.parent,parents:ae.parents}),EY=Object.freeze(Object.fromEntries(Object.entries(_v).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===ae.shapeUri&&o.origin?.namespace===Uf){r.shapeUri=s.dtype==="string"?s:null;continue}const{role:a}=o;if(a===null||!wv.has(a))continue;if(!yY(a,s,e)){n(nn.ROLE_SHAPE,`${e} column "${o.name}" (${a}) has a shape GEXF cannot map (${wY(s)}); written as a plain attribute`,o.name,null);const d=s.length-s.nullCount;dc.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";bY.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 wY(t){return t.dtype==="list"?`list of ${t.meta.itemDtype??"?"} x ${t.meta.itemComponents??1}`:`${t.dtype} x ${t.meta.components}`}function _Y(t,e,n){const i=new Map;for(const[r,s]of t.extensions){const o=KB(r);if(o===null)continue;const l=s.get(xe.element),a=s.get(xe.start),c=s.get(xe.end),d=s.get(xe.value);if(l?.dtype!=="u32"||a===null||!Cs(a)||c===null||!Cs(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=Yg(d,e),h=SY(s.get(xe.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:ap(s.get(xe.startText)),endText:ap(s.get(xe.endText)),valueText:Vg(f.type)?ap(s.get(xe.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 ap(t){return t!==null&&t.dtype==="string"?t:null}function SY(t){return t!==null&&Cs(t)?t:null}function Yg(t,e){const{meta:n}=t,i=n.origin?.type??null;if(n.dtype==="list"||dc.has(n.dtype)&&n.components>1){const l=n.dtype==="list"?n.itemDtype??"string":n.dtype;let a=sS(l);if(i!==null&&n.dtype==="list"&&qB(i)&&SS(i,"list",l)&&(a=i.slice(4)),e==="1.2"){const c=$d(a,l);return{type:"liststring",list:!0,itemType:"string",format:OS(c,e),dropped:a==="string"?null:`list${a}`}}return{type:`list${a}`,list:!0,itemType:a,format:OS($d(a,l),e),dropped:null}}let r=sS(n.dtype),s=null;const o=i===null||n.dtype!=="f64"?null:OY(i);return o!==null?Td(o,e)?r=o:s=o:i!==null&&SS(i,n.dtype,null)&&(Td(i,e)?r=i:Td(i,"1.3")&&(s=i)),{type:r,list:!1,itemType:r,format:$d(r,n.dtype),dropped:s}}function OY(t){switch(t.toLowerCase()){case"date":return"date";case"datetime":case"localdatetime":return"dateTime";default:return null}}function SS(t,e,n){const i=py("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 $d(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)?Ue(n):je(n):typeof n=="string"?n:null;case"float":return n=>typeof n=="number"?lt(n):null;case"double":case"bigdecimal":return n=>typeof n=="number"?e==="f32"?lt(n):je(n):typeof n=="string"?n:null;case"date":case"dateTime":return n=>typeof n=="number"?fa(n,t):typeof n=="string"?n:null;default:return n=>{switch(typeof n){case"string":return n;case"number":return e==="f32"?lt(n):je(n);case"boolean":return n?"true":"false";case"object":return n===null?null:JSON.stringify(n);default:return null}}}}function OS(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 my(i,e==="1.2"?"pipe":"gexf")}}function NS(t,e,n,i,r,s){const o=e==="node"?t.nodes:t.edges,l=e==="node"?HC:YC,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 I=AY(y.id??m,m,u),T=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&&T===pY&&s(nn.WEIGHT_KEY_CLASH,`edge column "${m}" is written as an attribute titled "${T}", 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)?`${T}#${I}`:T;D!==m&&s(nn.ATTRIBUTE_RENAMED,`${e} column "${m}" is written with title "${T}" and reads back as "${D}"`,m,null);const{defaultText:P,optionsText:k}=g===null?{defaultText:null,optionsText:null}:NY(g,e,b,r,s),U=g===null?null:n.companions.get(m)??null;U!==null&&!Vg(b.type)&&s(w.TEMPORAL_TEXT,`${e} column "${U.meta.name}" (the lexical form of "${m}") cannot be written: "${m}" is written as ${b.type}, not a GEXF temporal type`,U.meta.name,U.length-U.nullCount),f.push({id:I,title:T,type:b.type,column:g,companion:Vg(b.type)?U:null,format:b.format,defaultText:P,optionsText:k,dynamic:_,table:S})};for(const g of o){const{meta:m}=g;if(a.has(g)||m.role!==null&&hY.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},Yg(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},Yg(m.value,r),!0,m)}return f}function NY(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?$d(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=my(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)&&Go(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 Vg(t){return t==="date"||t==="dateTime"}function AY(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 Cd(t,e,n,i){return e?.isSet(n)?e.value(n):Xd(t.value(n),i)}function AS(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=Cd(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&Gf)!==0),l("end",t.end,(o&jf)!==0)),s==="1.3"&&t.timestamps?.isSet(e)){const c=`<[${Go(t.timestamps,e).map(d=>Xd(d,r)).join(", ")}]>`;i+=` timestamps="${W(c)}"`}return i}function TY(t,e,n,i){let r="";if(Number.isFinite(t)){const s=(n&Gf)===0?"start":"startopen";r+=` ${s}="${W(Xd(t,i.timeFormat))}"`}if(Number.isFinite(e)){const s=(n&jf)===0?"end":"endopen";r+=` ${s}="${W(Xd(e,i.timeFormat))}"`}return r}function TS(t,e,n,i){const r=[];if(t.spells?.isSet(e)){const o=n.version==="1.2"&&t.spellsOpen?.isSet(e)?Go(t.spellsOpen,e):[];Go(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 Go(t.timestamps,e))r.push([o,o,0]);if(r.length===0)return"";let s=`${i}<spells>
98
+ `;for(const[o,l,a]of r)s+=`${i} <spell${TY(o,l,a,n)}/>
99
+ `;return`${s}${i}</spells>
100
+ `}function IS(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($S(o,e)),c!==null&&(r+=`${i} <attvalue for="${W(s.id)}" value="${W(c)}"/>
101
+ `)}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($S(l.value,c)),d!==null&&(r+=`${i} <attvalue for="${W(s.id)}" value="${W(d)}"${IY(l,c,n)}/>
102
+ `)}}return r.length===0?"":`${i}<attvalues>
103
+ ${r}${i}</attvalues>
104
+ `}function IY(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(Cd(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&Gf)!==0?"startopen":"start";s+=` ${l}="${W(Cd(t.start,t.startText,e,n.timeFormat))}"`}if(Number.isFinite(r)){const l=(o&jf)!==0?"endopen":"end";s+=` ${l}="${W(Cd(t.end,t.endText,e,n.timeFormat))}"`}return s}function $S(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 $Y(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 Go(t,e){return t.dtype==="list"?t.sliceOf(e):[]}function CS(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="${lt(Math.fround(f))}"`)}r+=`${n}<viz:color${u}/>
105
+ `}const{position:o}=t;if(o?.isSet(e)){const a=Array.from(o.value(e)),c=o.dtype==="f32"?lt:je;let d=` x="${c(a[0])}" y="${c(a[1])}"`;a.length>2&&i&&(d+=` z="${c(a[2])}"`),r+=`${n}<viz:position${d}/>
106
+ `}for(const[a,c]of[["size",t.size],["thickness",t.thickness]])if(c?.isSet(e)){const d=c.value(e),u=c.dtype==="f32"?lt(d):je(d);r+=`${n}<viz:${a} value="${W(u)}"/>
107
+ `}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}/>
108
+ `}return r}function vS(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}">
109
+ `;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}/>
110
+ `;continue}i+=`${l}>
111
+ `,o.defaultText!==null&&(i+=`${n} <default>${et(o.defaultText)}</default>
112
+ `),o.optionsText!==null&&(i+=`${n} <options>${et(o.optionsText)}</options>
113
+ `),i+=`${n} </attribute>
114
+ `}i+=`${n}</attributes>
115
+ `}}return i}function DS(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*kS(t,e){const n=sv(t,e?.styles),i=n?.snapshot??t,r=Ev(i,e),{version:s}=r,o=bl(i,"any",r.options.sanitizeIds),l=b=>W(String(o.idAt(b))),a=BB[s],{meta:c}=i;yield`<?xml version="1.0" encoding="UTF-8"?>
116
+ `,yield`<gexf xmlns="${a.gexf}" xmlns:viz="${a.viz}" version="${s}">
117
+ `,yield CY(c,n),yield kY(i,r),yield vS("node",r.nodeAttrs," "),yield vS("edge",r.edgeAttrs," ");const{nodeRoles:d}=r,u=$Y(d.position);yield` <nodes count="${i.nodeCount}">
118
+ `;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))}"`),_+=AS(d,b,r);let S=IS(r.nodeAttrs,b,r," ");if(d.parents?.isSet(b)){const I=Go(d.parents,b);if(I.length>0){S+=` <parents>
119
+ `;for(const T of I)S+=` <parent for="${l(T)}"/>
120
+ `;S+=` </parents>
121
+ `}}S+=TS(d,b,r," "),S+=CS(d,b," ",u),S+=n?.node(b," ")??"",yield S.length===0?` <node${_}/>
122
+ `:` <node${_}>
123
+ ${S} </node>
124
+ `}yield` </nodes>
125
+ `;const{edgeRoles:f}=r,h=i.edgeList(),p=Ut(i,{foldMutual:!0}),g=wt(i),m=Sv(i);let y=0;for(let b=0;b<i.edgeCount;b++)DS(i,b,p)!==null&&y++;yield` <edges count="${y}">
126
+ `;for(let b=0;b<i.edgeCount;b++){const _=DS(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 I=g.text(b);I!==null&&(S+=` weight="${I}"`),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+=AS(f,b,r);let T=IS(r.edgeAttrs,b,r," ");T+=TS(f,b,r," "),T+=CS(f,b," ",!1),T+=n?.edge(b," ")??"",yield T.length===0?` <edge${S}/>
127
+ `:` <edge${S}>
128
+ ${T} </edge>
129
+ `}yield` </edges>
130
+ `,yield` </graph>
131
+ `,yield`</gexf>
132
+ `}function CY(t,e){let n="";t.creator!==null&&(n+=` <creator>${et(t.creator)}</creator>
133
+ `),t.description!==null&&(n+=` <description>${et(t.description)}</description>
134
+ `),t.keywords.length>0&&(n+=` <keywords>${et(t.keywords.join(", "))}</keywords>
135
+ `),e!==null&&(n+=` ${e.blockElement}
136
+ `);const i=t.modified===null?"":` lastmodifieddate="${W(t.modified)}"`;return n.length===0&&i.length===0?"":n.length===0?` <meta${i}/>
137
+ `:` <meta${i}>
138
+ ${n} </meta>
139
+ `}function vY(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 DY(t,e){const n=ea(t,"timestamp"),i={start:ea(t,"start"),end:ea(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 kY(t,e){const{meta:n}=t;let i=` defaultedgetype="${Sv(t)}"`,r=n.mode??"static";return e.temporal&&r==="static"&&(r="dynamic"),e.version==="1.2"&&r==="slice"&&(r="dynamic"),i+=` mode="${r}"`,i+=vY(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+=DY(t,e),` <graph${i}>
140
+ `}function Sv(t){return t.directed?ea(t,"defaultedgetype")?.trim().toLowerCase()==="mutual"?"mutual":"directed":"undirected"}function ea(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 RY=Object.freeze({format:xi,options:Object.freeze(["version"]),capabilities:jb,styles:Object.freeze({capabilities:rH}),check(t,e){const n=sv(t,e?.styles);return Object.freeze([...Ev(n?.snapshot??t,e).notes,...n?.notes??[]])},export(t,e){return ei(kS(t,e))},async exportToString(t,e){return ti(kS(t,e))}});Object.freeze({...xn,...Pn,COLUMN_TYPE:ny,XML_SYNTAX:Vu,XML_NESTING:Ku,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,ENCODING_CONFLICT:ul,EMPTY_INPUT:Mt,NOT_GEXF:lv,NO_GRAPH:rs,MULTIPLE_GRAPHS:Zn,MISSING_NODES:Fg,MISSING_ID:at,MISSING_ENDPOINT:Jn,UNKNOWN_NODE:"E_UNKNOWN_NODE",EDGE_TYPE:av,UNKNOWN_PARENT:Mi,UNKNOWN_PID:gv,PARENT_CYCLE:fl,BAD_VALUE:ne,ATTRIBUTES_CLASS:cv,ATTRIBUTE_ID:dv,HEADER_VALUE:No,COUNT_HINT:Wd,COUNT_MISMATCH:Us,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Oi,DUPLICATE_ATTRIBUTE:de,ATTRIBUTE_TYPE:uv,UNKNOWN_ATTR_TYPE:Zt,BAD_DEFAULT:Wo,BAD_OPTIONS:pA,COLUMN_RENAMED:ln,ROLE_TAKEN:yn,UNKNOWN_ATTRIBUTE:zg,ATTVALUE_SHAPE:Wg,TIMED_VALUE_ON_STATIC:fv,PRECISION:ie,ID_MERGED:Rn,WEIGHT_IGNORED:hv,VIZ_SKIPPED:pv,VIZ_DYNAMIC_DROPPED:mv,SPELL_OPEN_DROPPED:zH,VIZ_VALUE:Bg,OPEN_BOUND_CONFLICT:yv,TIMESTAMP_CONFLICT:bv,VALUE_OUTSIDE_OPTIONS:Hg,UNKNOWN_ELEMENT:$t,UNKNOWN_XML_ATTRIBUTE:zd,STRAY_TEXT:Xu,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er});const LY=[[/yfiles|yed/i,"yed"],[/cytoscape/i,"cytoscape"],[/gephi/i,"gephi"],[/graphviz/i,"graphviz"],[/pajek/i,"pajek"],[/networkx/i,"networkx"],[/tulip/i,"tulip"]];function Fb(t){return t==null?null:LY.find(([e])=>e.test(t))?.[1]??null}const PY="graphics";function xY(t){if(t.nodes.byRole("position")===null)return null;const e=t.graph.has("Creator")?t.graph.value("Creator",0):null,n=Ov(t),i=typeof e=="string"?e:null,r=n?"graphviz":Fb(t.meta.creator??i);return{units:"px",sourceDims:3,yAxis:r==="gephi"||r==="tulip"||n?"up":"down",tool:r,medianNodeSize:MY(t,r==="gephi")}}function Ov(t){return(t.meta.creator??null)!==null||t.graph.has("Creator")||!t.graph.has("version")?!1:Number(t.graph.value("version",0))===2}function MY(t,e){const n=t.nodes.get(PY),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 Qm(i)}const Ff=0,ys=1,zb=2,ft=3,Ce=4,zf=5,Ia="_networkx_list_start",$a="[]",Kg="()",jr="graphty_originalId",vd=kn,UY=kn,GY=kn,jY=kn,FY=/^[A-Za-z_]\w*$/,zY=/^[A-Za-z]\w*$/,WY=/^[+-]?\d+$/,BY=/^[+-]?(?:(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)$/,Nv=/^[+-]?(?:inf|infinity|nan)$/i,HY=/^(?:inf|infinity|nan)$/i;class Fr extends Error{constructor(e,n,i){super(n),this.name="GmlSyntaxError",this.code=e,this.line=i}}class YY{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,`
141
+ `)),this.backslashEscapes&&n.includes("\\")&&(n=n.replaceAll(/\\([\s\S])/g,"$1")),!n.includes("&"))return n;const i=this.onUnknownEntity;return U2(n,i===null?void 0:r=>{i(r,this.line[e])})}isBracket(e){return this.kind[e]>=Ce}nextPair(e){const n=e+1;return this.kind[n]===Ce?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 VY(t){const e=new YY(t,Math.max(1024,t.length>>>3));e.backslashEscapes=JY(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?XY(n):i===91||i===93?(e.push(i===91?Ce:zf,n.i,n.i+1,n.line),n.i++):KY(n,i)||qY(n)}return nV(e),e}function KY(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=QY(n,t.i);else return!1;return!0}function XY(t){const{text:e,tokens:n,i}=t,r=n.backslashEscapes?ZY(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 Fr(GY,`unclosed string opened at line ${t.line}${o}`,t.line)}n.push(ft,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 qY(t){const{text:e,i:n}=t;let i=n+1;for(;i<e.length&&!eV(e.codePointAt(i)??0);)i++;t.tokens.push(tV(e,n,i,t.line),n,i,t.line),t.i=i}function JY(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 ZY(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 QY(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 eV(t){return t===32||t===9||t===10||t===13||t===11||t===12||t===91||t===93||t===34||t===35}function tV(t,e,n,i){const r=t.slice(e,n);if(FY.test(r))return Ff;if(WY.test(r))return ys;if(BY.test(r)||Nv.test(r))return zb;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 Fr(UY,`cannot tokenize "${l}" at line ${i}${c}`,i)}function nV(t){const{count:e,kind:n}=t,i=new Uint32Array(e),r=[];let s=0;for(;s<e;){const o=n[s];if(o===zf){const a=r.pop();if(a===void 0)throw new Fr(vd,`unexpected "]" at line ${t.line[s]}: no open "["`,t.line[s]);i[a]=s,s++;continue}if(o!==Ff)throw new Fr(vd,`expected a key at line ${t.line[s]}, found ${Av(t,s)}`,t.line[s]);const l=s+1;if(l>=e)throw new Fr(vd,`key "${t.textOf(s)}" at line ${t.line[s]} has no value`,t.line[s]);iV(t,s)===Ce&&r.push(l),s=l+1}if(r.length>0){const o=r[r.length-1];throw new Fr(jY,`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 iV(t,e){const{kind:n}=t,i=e+1,r=n[i]===Ff&&!HY.test(t.textOf(i));if(r&&t.textOf(e)==="Creator")return n[i]=ft,ft;if(n[i]===zf||r)throw new Fr(vd,`expected a value for key "${t.textOf(e)}" at line ${t.line[e]}, found ${Av(t,i)}`,t.line[i]);return n[i]}function Av(t,e){switch(t.kind[e]){case Ce:return'"["';case zf:return'"]"';case ft:return`the string "${t.textOf(e)}"`;default:return`"${t.textOf(e)}"`}}function bs(t){if(Nv.test(t)){const e=t.toLowerCase();return e.endsWith("nan")?Number.NaN:e.startsWith("-")?-1/0:1/0}return Number(t)}function jo(t){return zY.test(t)}const Wb="W_GML_KEY_MANGLED";function Cl(t){const e=t.replaceAll(/\W/g,"_");return/^[A-Za-z]/.test(e)?e:`x${e}`}function Xg(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&&qg(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]===ft?rV(r,o,t.stringOf(l)):t.kind[l]===Ce?i.push({record:Object.create(null),listKeys:null,close:t.match[l],next:l+1,key:o}):qg(r,o,bs(t.textOf(l)))}return n}function rV(t,e,n){if(n===Ia){t.record[e]=[],t.listKeys??=new Set,t.listKeys.add(e);return}qg(t,e,n===$a||n===Kg?[]:n)}function qg(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 sV(t,e){return t.kind[e]===Ce?Xg(t,e):bs(t.textOf(e))}const Jg=[[/^\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}]],oV={dialect:"gml",tool:null,vocabulary:"graphlet",spelling:"css",units:"px",labelKey:!0},lV={dialect:"graphviz",tool:"graphviz",vocabulary:"graphviz",spelling:"graphviz",units:"px",labelKey:!0},Tv={...Jg[0][1],tool:null},Bb=Cl(Z),Au=Cl("graphty.style.");function Tu(t,e){return Cl(Ef(t,e))}function Iv(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 aV=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"]]),cV=["isGroup","gid"];function dV(t){if(t.graph.has(Bb))return Tv;const e=t.meta.creator??Iv(t,"Creator")??"";for(const[n,i]of Jg)if(n.test(e))return i;return e.trim()===""&&(cV.some(n=>t.nodes.has(n))||t.graph.has("hierarchic"))?Jg[0][1]:e.trim()===""&&Ov(t)?lV:oV}const uV=new Map([["none",["none","none"]],["last",["none","triangle"]],["first",["triangle","none"]],["both",["triangle","triangle"]]]),fV=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"]]),hV=["none","solid","dashed","dotted","dash-dot","dash-dot"],pV=new Map([["none","none"],["solid","solid"],["dash","dashed"],["dot","dotted"],["dashdot","dash-dot"],["dashdotdot","dash-dot"]]),gV=new Map([["rect","rectangle"],["roundedrect","round-rectangle"],["rhomb","diamond"],["image","rectangle"]]),mV=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"]]),yV=new Set(["triangle","invtriangle","pentagon","hexagon","octagon"]),bV=["outline","autoSizePolicy","model","configuration","borderDistance","modelName","modelPosition"],RS=Xy.edge.get("targetArrow")?.[0]?.[1];function Hb(t){return typeof t=="string"||typeof t=="number"?String(t).slice(0,De):"a record"}function ot(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Vs(t,...e){for(const n of e)if(Object.hasOwn(t,n)&&t[n]!==void 0)return t[n]}function Ks(t,e,n,i,r,s){if(t===void 0)return;const o=$e(t,i.spelling,s(e));if(o===null)return;r(e,o.color);const l=_l(o,null,s(e),n!==null);n!==null&&r(n,l)}function Wf(t,e,n,i){if(t===void 0)return null;if(n.vocabulary==="ogdf"){const r=Yb(t);return r===void 0?(B(i,v.UNKNOWN_VALUE,Hb(t)),null):r==="none"?null:r}return oe(e,t,n.spelling,i)}function Yb(t){const e=typeof t=="string"||typeof t=="number"?String(t).trim():"";return/^\d+$/.test(e)?hV[Number(e)]:pV.get(e.toLowerCase())}function EV(t,e,n,i){const r=t.trim().toLowerCase(),s=mV.get(r);if(s!==void 0){n("shape","polygon"),n("shapePoints",s),yV.has(r)&&n("shapePointsStretch",!1);return}n("shape",oe("shape",gV.get(r)??t,e.spelling,i("shape")))}function wV(t,e,n,i){const r=e.vocabulary;if(r==="graphviz"){NV(t,e,n,i);return}TV(t,e,n,i),IV(t,e,n,i),n("borderStyle",Wf(r==="ogdf"?t.stipple:t.outlineStyle,"borderStyle",e,i("borderStyle"))),r==="ogdf"&&t.stipple!==void 0&&Yb(t.stipple)==="none"&&n("borderWidth",0),_V(t,e,n,i),r==="ogdf"&&OV(t.label,n,i),SV(t,e,n,i)}function _V(t,e,n,i){if(e.tool==="gephi"){const r=t.w===void 0?null:V(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:V(t.w,i("width"))),n("height",t.h===void 0?null:V(t.h,i("height")))}function SV(t,e,n,i){const r=e.vocabulary;if(r==="ogdf"&&typeof t.type=="string")EV(t.type,e,n,i);else if(r==="cytoscape"&&t.type!==void 0){const s=ct(t.type,i("shape"))?.trim().toLowerCase()??"",o=fV.get(s);o===void 0&&B(i("shape"),v.UNKNOWN_VALUE,s.slice(0,De)),n("shape",o??null)}else if(t.type!==void 0)n("shape",oe("shape",t.type,e.spelling,i("shape")));else if(r==="yed"&&typeof t.customconfiguration=="string"){const s=vf(t.customconfiguration);n("shape",s?.shape??null),s?.points!==void 0&&n("shapePoints",s.points)}}function OV(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:Ea(i,n("labelOffsetX"))),e("labelOffsetY",r===void 0?null:Ea(r,n("labelOffsetY")))}function NV(t,e,n,i){const r=typeof t.type=="string"?t.type.trim().toLowerCase():"";if(Number(t.hasFill)===1||r==="point"){const c=$e(t.fill??"black",e.spelling,i("fill"),{use:"fill"});n("fill",c?.color??null),n("fillOpacity",c?.alpha??null)}else t.fill!==void 0&&B(i("fill"),v.UNFILLED,Hb(t.fill));fW(r)?n("borderWidth",0):(Ks(t.outline,"borderColor",null,e,n,i),n("borderWidth",t.width===void 0?null:V(t.width,i("borderWidth"))));const s=Wf(t.outlineStyle,"borderStyle",e,i("borderStyle"));n("borderStyle",s),AV(t,r,s,e,n,i);const o=2*kb*((Db.get(r)??1)-1),l=(c,d)=>{const u=c===void 0?null:V(c,i(d));return u===null?null:Math.max(0,u-o)};n("width",l(t.w,"width")),n("height",l(Vs(t,"H","h"),"height")),Number(t.visible)===0&&t.visible!==void 0&&n("visible",!1);const a=uW(r);if(r==="polygon")n("shape","rectangle");else if(a!==void 0)n("shape","polygon"),n("shapePoints",a),n("shapePointsStretch",!1);else if(Ib.has(r)){const c=(d,u)=>d===void 0?null:V(d,i(u));OC(r,c(t.w,"width"),c(Vs(t,"H","h"),"height"),n,()=>{const d=t.width===void 0?1:Number(t.width);return Number.isFinite(d)?Math.max(0,d):1},()=>$e(t.outline??"black",e.spelling,i("outerBorderColor"),{use:"line"})?.color??null)}else t.type!==void 0&&n("shape",oe("shape",t.type,"graphviz",i("shape")))}function AV(t,e,n,i,r,s){const o=Db.get(e)??1;if(o<2)return;const l=$e(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,kb-c)),(n==="dashed"||n==="dotted")&&r("outerBorderStyle",n),o>2&&B(s("outerBorderWidth"),v.NOT_CARRIED,`type ${e}`)}function TV(t,e,n,i){if(e.vocabulary==="yed"&&Number(t.hasFill)===0){B(i("fill"),v.NO_FILL,"hasFill 0"),n("fillOpacity",0);return}Ks(t.fill,"fill","fillOpacity",e,n,i),t.fill2!==void 0&&B(i("fill"),v.GRADIENT,Hb(t.fill2))}function IV(t,e,n,i){const r=e.vocabulary;if(r==="yed"&&Number(t.hasOutline)===0){n("borderWidth",0);return}Ks(r==="ogdf"?Vs(t,"outline","line"):t.outline,"borderColor",null,e,n,i);const s=$V(t,r);n("borderWidth",s===void 0?null:V(s,i("borderWidth")))}function $V(t,e){switch(e){case"yed":return t.outlineWidth;case"cytoscape":return Vs(t,"outline_width","width");case"ogdf":return t.lineWidth;default:return Vs(t,"width","outlineWidth")}}function CV(t,e,n,i){const r=e.vocabulary;if(r==="graphviz"){kV(t,e,n,i);return}Ks(t.fill,"color","opacity",e,n,i);const s=r==="ogdf"?Vs(t,"lineWidth","width"):t.width;n("width",s===void 0?null:V(s,i("width"))),n("lineStyle",Wf(r==="ogdf"?t.stipple:t.style,"lineStyle",e,i("lineStyle"))),r==="ogdf"&&t.stipple!==void 0&&Yb(t.stipple)==="none"&&n("visible",!1),vV(t,e,n,i),r==="yed"&&RV(t,n)}function vV(t,e,n,i){if(typeof t.arrow=="string"){const r=uV.get(t.arrow.trim().toLowerCase());r===void 0?B(i("targetArrow"),v.UNKNOWN_VALUE,t.arrow.slice(0,De)):(n("sourceArrow",r[0]),n("targetArrow",r[1]))}for(const[r,s]of[[["sourceArrow","source_arrow"],"sourceArrow"],[["targetArrow","target_arrow"],"targetArrow"]]){const o=Vs(t,...r);o!==void 0&&n(s,e.vocabulary==="cytoscape"&&RS!==void 0?RS(o,i(s)):oe("arrow",o,e.spelling,i(s)))}}const DV=new Map([["first",[!1,!0]],["last",[!0,!1]],["both",[!0,!0]],["none",[!1,!1]]]);function kV(t,e,n,i){Ks(t.fill,"color","opacity",e,n,i),n("width",t.width===void 0?null:V(t.width,i("width"))),n("lineStyle",Wf(t.style,"lineStyle",e,i("lineStyle"))),Number(t.visible)===0&&t.visible!==void 0&&n("visible",!1);const r=$v(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?$C(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 $v(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()),DV.get(n)??null}function RV(t,e){if(t.smoothBends!==void 0){const n=ot(t.Line)?t.Line.point:void 0;e("curved",Number(t.smoothBends)===1&&Array.isArray(n)&&n.length>2)}}function LV(t,e,n,i,r){const s=(Array.isArray(t)?t:[t]).filter(c=>ot(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&&B(r("label"),v.EXTRA_LABELS,`${String(l+1)} labels`),o.text!==void 0&&i("label",e.vocabulary==="graphviz"?Cv(o.text,r("label")):nt(o.text,r("label")));const a=e.vocabulary==="yed"||bV.some(c=>Object.hasOwn(o,c));if(o.color!==void 0||o.fontColor!==void 0?Ks(o.color??o.fontColor,"labelColor","labelOpacity",e,i,r):o.fill!==void 0&&!a&&Ks(o.fill,"labelColor",null,e,i,r),o.fill!==void 0&&a&&B(r("label"),v.NOT_CARRIED,"label background"),PV(o,a||e.vocabulary==="cytoscape",i,r),n&&o.anchor!==void 0){const c=ct(o.anchor,r("labelPosition"))?.trim().toLowerCase()??"",d=aV.get(c);d===void 0&&B(r("labelPosition"),v.UNKNOWN_VALUE,c.slice(0,De)),i("labelPosition",d??null)}}function Cv(t,e){const n=nt(t,e);return n===null?null:n.replaceAll(/\\[nlr]/g,`
142
+ `).replace(/\n$/,"")}function PV(t,e,n,i){n("labelSize",t.fontSize===void 0?null:V(t.fontSize,i("labelSize")));const r=t.fontName===void 0?null:nt(t.fontName,i("labelFont"));n("labelFont",e&&typeof r=="string"?wf(r):r);const s=ct(t.fontStyle,i("labelWeight"))?.trim().toLowerCase();if(s!==void 0){const o=P$.get(s);o===void 0?B(i("labelWeight"),v.UNKNOWN_VALUE,s.slice(0,De)):(n("labelWeight",o[0]),n("labelItalic",o[1]))}}function vv(t,e,n,i,r,s,o){let l=!1;const a=(d,u)=>{l||=d==="label"&&u!==null,s(d,u)};ot(e)&&(t==="node"?wV:CV)(e,r,s,o),n!=null&&LV(n,r,t==="node",a,o);const c=r.vocabulary==="cytoscape"?t==="node":r.labelKey&&(ot(e)||n!==void 0);!l&&c&&i!==null&&i!==void 0&&(s("label",r.vocabulary==="graphviz"?Cv(i,o("label")):nt(i,o("label"))),t==="node"&&r.tool===null&&r.vocabulary==="graphlet"&&s("labelPosition","center"))}const xV=10;function MV(t,e){const n=t.nodeCount,i=o=>{const[l,a]=An(t,o),[c,d]=Iu(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+xV))}}function UV(t,e,n,i){const r=n==="node"?t.nodes:t.edges,s=pi(r,"label",i);return e.vocabulary==="cytoscape"&&n==="node"&&(s===void 0||s==="")?String(t.ids.idOf(i)):s}function pi(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 Iu(t,e){const n=pi(t.nodes,"graphics",e);return ot(n)?[Number(n.w??Number.NaN),Number(n.h??Number.NaN)]:[Number.NaN,Number.NaN]}function GV(t,e,n,i,r){const s=ot(e)&&ot(e.Line)?e.Line.point:void 0,o=ot(s)?[s]:s;if(!Array.isArray(o)||o.length<(i?1:2))return;const l=o.map(f=>ot(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?zs(An(t,a),Iu(t,a),d,!0):Ol(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:zs(g,Iu(t,h),[p],!0);m!==null&&r(f,m)}}function jV(t,e,n,i){const r=ot(e)&&ot(e.Line)?e.Line.point:void 0,s=ot(r)?[r]:r;if(!Array.isArray(s)||!ot(e))return;let o=s.map(d=>ot(d)?[Number(d.x),Number(d.y)]:[Number.NaN,0]);const l=(o.length-1)%3,a=l===2||l===1&&$v(e,t.directed)?.[0]===!0;o=o.slice(a?1:0,o.length-(l===2||l===1&&!a?1:0));const c=IC(An(t,t.edgeSource(n)),An(t,t.edgeTarget(n)),[o]);c!==null&&i("bends",c)}function Dv(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 kv(t,e,n,i){const r=x(t[0]-e[0]),s=x((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 FV(t,e,n,i){const r=pi(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))];kv([Number(s[1]),Number(s[2])],Dv([o,l]),!0,i)}function zV(t,e,n,i){const r=ot(e)&&ot(e.Line)?e.Line.point:void 0,s=ot(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=>ot(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];kv([(d[0][0]+d[1][0])/2,(d[0][1]+d[1][1])/2],Dv(d),!1,i)}function WV(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 BV(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(vv(a,pi(c,"graphics",f),pi(c,"LabelGraphics",f),UV(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;jV(t,pi(c,"graphics",f),f,(g,m)=>{r=!0,p||=g==="bends",u.put(f,g,m)}),FV(t,f,p,(g,m)=>{u.put(f,g,m)})}else a==="edge"&&e.vocabulary==="ogdf"&&zV(t,pi(c,"graphics",f),f,(p,g)=>{u.put(f,p,g)});a==="edge"&&e.vocabulary!=="graphviz"&&GV(t,pi(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 HV(t,e){const n=oc(e,to(t));if(!n.ok||n.block.values!==void 0)return e;const i=LS(t,"node",n.block.columns.node),r=LS(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 LS(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=Tu(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 PS(t){return[...t.names()].filter(e=>e==="graphics"||e==="LabelGraphics"||e.startsWith(Au))}function YV(t,e){const n=new re,i={...dV(t),directed:t.directed},r=BV(t,i,n,e);i.vocabulary==="ogdf"&&MV(t,r.node);const s=Iv(t,Bb),o=s===null?null:HV(t,s);if(o!==null&&KV(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=pi(t.edges,"value",d);return typeof u!="number"||!Number.isFinite(u)?null:u>0?u:1})),WV(t,r.edge));const l={rules:[],columns:new Map},a=i.tool==="gephi"?Gb(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:PS(t.nodes),edge:PS(t.edges)}}}const Ca=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"}),Rv={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 Lv(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=Lg(F$,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=Df(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=Lg(Nb,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 Pv(t,e){const n={},i=t("color");typeof i=="string"&&(n.fill=Df(i,t("opacity")));const r=t("width");typeof r=="number"&&(n.width=r);const s=t("lineStyle");typeof s=="string"&&(n.style=Aa(Nb,s,s==="long-dash"?"dashed":"line","lineStyle",e));for(const l of["sourceArrow","targetArrow"]){const a=t(l);typeof a=="string"&&(n[l]=Aa(z$,a,"standard",l,e))}const o=t("curved");return typeof o=="boolean"&&(n.smoothBends=o?1:0),n}function xv(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=W$(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 Mv(t,e,n){const i={};if(ot(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 VV(t,e){const n=Array.isArray(t)?t:[t],i=Mv(n[0],Rv.label,e??{}),r=n.slice(1).filter(s=>s!=null);return r.length===0?i:i===void 0?r:[i,...r]}function KV(t,e,n){const i=new re;no(t,e,"gml",r=>({values:n[r],properties:Ca[r],writes:Ca[r],readBack:(s,o)=>{const l=XV(r,o,i);return a=>l.get(a)??null}}))}function XV(t,e,n){const i=()=>{},r=t==="node"?Lv(e,i):Pv(e,i),s=new Map;return vv(t,r,xv(e)??void 0,void 0,Tv,(o,l)=>{l!==null&&s.set(o,l)},o=>({notes:n,target:t,property:o})),s}function Uv(t,e){if(e===void 0)return null;const n=new Al,i=t.withColumns(),r=[];for(const c of["node","edge"]){const d=c==="node"?i.nodes:i.edges;qV(t,e,c,d,n);const u=rC(e.rules.styles.rules,c);for(const f of d.names().filter(h=>Cl(h).startsWith(Au))){const h=d.get(f);d.remove(f),h!==null&&!(f.startsWith(Au)&&!u.has(f))&&r.push(ZV(d,c,f,h))}}let{block:s}=e;const o=[...e.rules.columns.node.keys()].map(c=>Tu("node",c)),l=[...e.rules.columns.edge.keys()].map(c=>Tu("edge",c));new Set(o).size!==o.length||new Set(l).size!==l.length?s=Sl(e.rules,{inlineColumns:!0,snapshot:t}):QV(i,e),i.graph.set(Bb,[s],{dtype:"string"});const a=[...r,...s===e.block?[]:sc(s,e.rules.styles.rules.length,"size"),...n.notes("yEd's GML")];return{snapshot:i,notes:a}}function qV(t,e,n,i,r){const s=n==="node"?t.nodeCount:t.edgeCount,o=(f,h)=>{r.add(n,f,h)},l=Ws((f,h)=>e.picture(f,h),n,Ca[n]),a=Ws((f,h)=>e.picture(f,h),"node",Ca.node),c=f=>{const[h,p]=[a(f)("width"),a(f)("height")];return typeof h=="number"&&typeof p=="number"?[h,p]:Iu(t,f)},d=[],u=[];for(let f=0;f<s;f++){const h=n==="node"?Lv(l(f),o):Pv(l(f),o);if(n==="edge"){const p=JV(t,l(f),f,c);p!==null&&(h.Line=p)}d.push(Mv(pi(i,"graphics",f),Rv[n],h)),u.push(VV(pi(i,"LabelGraphics",f),xv(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 JV(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?fu(o,i(r),a):G1(o,l,a));const d=(h,p,g)=>{const m=e(h);return typeof m=="string"?fu(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 ZV(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:Wb,message:`${e} column "${n}" is written as "${r}": keys starting with ${Au} hold graphty's style values`,column:n,count:null})}function QV(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(Tu(n,r),l?s.map(c=>c===null?null:String(c)):s,{dtype:a})}}}const eK="W_GML_RECORD_NUMBER_TYPE",tK="W_GML_RECORD_BOOLEAN",nK="W_GML_RECORD_NULL",iK="E_GML_NESTED_ARRAY",rK="W_GML_JSON_ARRAY",Gv="E_GML_INVALID_KEY",sK="E_GML_RESERVED_KEY",oK="W_GML_POSITION_COMPONENTS",lK="W_GML_GRAPHICS_OVERRIDDEN",aK="E_GML_GRAPHICS_CONFLICT",cK="value",dK=new Set(["label","id","key"]),uK=Object.freeze({label:"label",id:"id",key:"key"}),jv=Xe({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}),fK=new Set(["directed","pair","mutual","weight","timeText","originalId","position","color","size","shape","thickness","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]),Fv=new Set(["id"]),hK=new Set(["source","target","directed"]),zv=new Set(["node","edge","directed","multigraph"]),pK=new Set(["graph"]),gK=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;function Wv(t,e){const n=dt(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:cK}else if(typeof r!="string"||!jo(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 mK(t){const{role:e}=t.meta;return e===null||!fK.has(e)}function yK(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 Bv(t){return t.flags.weighted}function $u(t){return t.meta.extra.gmlTopLevel===!0}function bK(t){return gK.test(t)?t:Li(t)}function EK(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 zr(t,e,n,i,r,s=()=>!0){const o=new Set(e),l=[],a=[...t].filter(d=>mK(d)&&s(d)),c=EK(a,n,o);for(const d of a){const u=d===c?"label":yK(d.meta);let f=u;const h=jo(u),p=d!==c&&o.has(u);if(!h||p){const g=h?sK:Gv;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=Hv(h?u:Cl(u),o),r?.push(Tn(Wb,`${n} column "${d.meta.name}" is written as "${f}"`,d.meta.name))}o.add(f),l.push({column:d,key:f})}return l}function Hv(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 Hc(t,e,n,i){t[e]||(t[e]=!0,n[i]++)}function ta(t,e,n,i){if(t===null){Hc(i,"nulls",e,"nulls");return}switch(typeof t){case"number":Hc(i,"numbers",e,"numbers");return;case"boolean":Hc(i,"booleans",e,"booleans");return;case"string":return}if(Array.isArray(t)){n&&Hc(i,"nested",e,"nestedArrays");for(const s of t)ta(s,e,!0,i);return}const r=t;for(const s of Object.keys(r))jo(s)||e.invalidKeys++,ta(r[s],e,!1,i)}function Ul(t){return`${t} row${O(t)}`}function wK(t,e,n,i,r){e>0&&t.push(Tn(n,i,r,e))}function Yc(t,e,n,i){for(const{column:r}of t){const s=_K(r);if(s===null)continue;const{name:o}=r.meta,l=`${e} column "${o}"`,a=(d,u,f)=>{wK(i,d,u,f,o)};a(s.numbers,eK,`${l} holds numbers in ${Ul(s.numbers)}; GML records cannot keep the int / real distinction`),a(s.booleans,tK,`${l} holds booleans in ${Ul(s.booleans)}; written as 1 / 0`),a(s.nulls,nK,`${l} holds nulls in ${Ul(s.nulls)}; GML has no null, the key is omitted`),a(s.arrays,rK,`${l} holds arrays as values in ${Ul(s.arrays)}; written as repeated keys, they re-import as a list`),a(s.nestedArrays,iK,`${l} holds arrays nested in arrays in ${Ul(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?Wb:Gv,n.mangle?`${l}: ${c} and are rewritten`:`${l}: ${c}; the save fails unless sanitizeKeys is "mangle"`)}}function _K(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)ta(s,e,!0,r)}else ta(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))ta(r,e,!0,i)}return e}return null}function Vb(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 Yv(t){return t.nodes.typed("graphics","json")}function SK(t,e){const n=Vb(t);if(n===null)return;n.meta.components>3&&e.push(Tn(oK,`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=Yv(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(lK,`${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(aK,`${s} node graphics value${O(s)} ${C(s,"is","are")} not records and cannot hold the position; the save fails`,"graphics",s))}function xS(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 Qs(nf);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 OK(t,e,n){const i=Vb(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 MS(t,e){const n=Wv(t,e),i=Un(t,jv,n.common,{positionDtype:"f64",roles:dK,roleNames:uK}),r=new Set(Fv);(n.common.sanitizeIds==="mangle"&&NK(t)>0||t.nodes.byRole("originalId")!==null)&&r.add(jr);const s=t.edges.byRole("id"),o=Vv(t,n,s),l=Kv(t),a=zr(t.nodes,r,"node",n,i),c=zr(t.edges,o,"edge",n,i,h=>h!==s),d=zr(t.graph,zv,"graph",n,i,h=>!$u(h)),u=zr(t.graph,l,"top-level",n,i,$u);if(Yc(a,"node",n,i),Yc(c,"edge",n,i),Yc(d,"graph",n,i),Yc(u,"top-level",n,i),SK(t,i),OK(t,a,i),xS(a,"node",i),xS(c,"edge",i),!Bv(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=Ut(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 Vv(t,e,n){const i=new Set(hK);return Bv(t)&&i.add(e.weightKey),n!==null&&i.add("id"),i}function Kv(t){const e=new Set(pK);return t.meta.creator!==null&&e.add("Creator"),t.meta.sourceFormat==="gml"&&t.meta.sourceVersion!==null&&e.add("Version"),e}function NK(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 Zg(t,e){switch(e.dtype){case"i32":case"u32":case"u8":return Ue(t);case"f32":return Gs(t,"f32");default:return e.origin?.type==="int"&&Number.isInteger(t)?Ue(t):Gs(t,"f64")}}function Xv(t){switch(typeof t){case"number":return Number.isInteger(t)?Ue(t):Gs(t,"f64");case"boolean":return t?"1":"0";default:return Li(t)}}function AK(t,e,n){switch(typeof t){case"number":switch(e){case"i32":case"u32":case"u8":return Ue(t);case"f32":return Gs(t,"f32");case"json":return Xv(t);default:return n.origin?.type==="int"&&Number.isInteger(t)?Ue(t):Gs(t,"f64")}case"boolean":return t?"1":"0";case"string":return Li(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 TK{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}
143
+ `)}raw(e){this.lines.push(`${e}
144
+ `)}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,Zg(i.data[r],s));else for(let a=0;a<l;a++)this.line(e,n,Zg(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,Li(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,Li($a));return}i.length===1&&this.line(e,n,Li(Ia));for(const o of i)r==="json"&&typeof o=="object"?this.json(e,n,o,s.name,!0):this.line(e,n,AK(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,Li($a));return}i.length===1&&this.line(e,n,Li(Ia));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,Xv(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(jo(e)&&!n.has(e))return e;if(!this.mangle)throw new N("E_UNSUPPORTED",`column "${i}": record key "${e}" ${jo(e)?"repeats a key":"is not a GML key"}; pass sanitizeKeys: "mangle" to rewrite it`,{reason:"gml key",column:i,key:e});return Hv(jo(e)?e:Cl(e),n)}}function IK(t,e){const n=Wv(t,e),i=bl(t,"integer",n.common.sanitizeIds),r=gl(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(Fv);(i.changed>0||l!==null)&&a.add(jr);const c=t.edges.byRole("id"),d=Vv(t,n,c),u=Kv(t);return{snapshot:t,plan:n,ids:i,writeDirected:o,foldPairs:s,nodeColumns:zr(t.nodes,a,"node",n,null,f=>!(f.meta.name==="graphics"&&f.dtype==="json")),edgeColumns:zr(t.edges,d,"edge",n,null,f=>f!==c),graphColumns:zr(t.graph,zv,"graph",n,null,f=>!$u(f)),topColumns:zr(t.graph,u,"top-level",n,null,$u),position:Vb(t),graphics:Yv(t),originalIds:l,edgeIds:c,weights:wt(t),folding:Ut(t)}}function US(t){return typeof t=="string"?Li(t):Number.isSafeInteger(t)?Ue(t):Gs(t,"f64")}function*$K(t){const{snapshot:e,plan:n,ids:i}=t,r=new TK(n.mangle),{meta:s}=e;s.creator!==null&&r.line("","Creator",Li(s.creator)),s.sourceFormat==="gml"&&s.sourceVersion!==null&&r.line("","Version",bK(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",Ue(i.idAt(d))),i.isChanged(d))r.line(" ",jr,US(i.originalAt(d)));else if(t.originalIds?.isSet(d)){const u=t.originalIds.value(d);(typeof u=="string"||typeof u=="number")&&r.line(" ",jr,US(u))}for(const{column:u,key:f}of t.nodeColumns)u.isSet(d)&&r.cell(" ",f,u,d);CK(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",Ue(i.idAt(l.src[d]))),r.line(" ","target",Ue(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)?Ue(u):Gs(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 CK(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],Zg(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 vK=Object.freeze({format:"gml",options:Object.freeze(["sanitizeKeys","weightKey"]),capabilities:jv,styles:Object.freeze({capabilities:Ca}),check(t,e){const n=Uv(t,e?.styles);return n===null?MS(t,e):Object.freeze([...MS(n.snapshot,e),...n.notes])},export(t,e){return ei(GS(t,e))},exportToString(t,e){return ti(GS(t,e))}});function*GS(t,e){yield*$K(IK(Uv(t,e?.styles)?.snapshot??t,e))}const Qg=rs,qv=Zn,Jv=at,Zv="E_GML_MISSING_LABEL",Qv=Jn,em="E_GML_ID_TYPE",eD="W_GML_STRING_ID",tm=sn,nm="E_GML_REPEATED_KEY",tD="E_GML_ELEMENT_TYPE",nD="E_GML_FLAG_TYPE",Dd="W_GML_FLAG_VALUE",DK=/^\s*[+-]?\d+\s*$/,im="W_GML_UNKNOWN_ENTITY",rm="W_GML_GRAPHICS",sm="W_GML_NESTED_ELEMENT",kd="W_GML_GROUPS",kK="graphty.parent",om=ua,zl=ie,RK=ln,LK=yn,iD="W_GML_ID_DROPPED",jS={ids:"canonical",defaultDirected:!1,weightFrom:"value"},Rd=1,Cu=2,na=4,ia=8,PK=-2147483648,xK=2147483647,MK=64,FS=new Set(["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","restoreMangledIds","long","errorLimit","signal","onProgress"]),cp=-1,zS=-2;function UK(t,e){return lm(t,e)==="label"}function dp(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function lm(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 WS{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",im,`character entity ${n} cannot be decoded; it is kept as written`,{line:i,element:n},`${im}:${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]===Ce;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,zS)}failNoGraph(e,n){n>=0&&this.report.fail(Qg,`the graph key at line ${e.line[n]} holds ${yo(e,n)}, not a [ ... ] block; the input contains no graph block`,{line:e.line[n]}),this.report.fail(Qg,"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]===Ce&&(this.nodeCount++,this.scanElement("node",o));break;case"edge":n.kind[o]===Ce&&(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,cp)}}}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===jr&&s?(this.hasOriginalId=!0,!0):n==="id":n==="source"||n==="target"||n==="directed"?!0:n===r?(this.weightKinds|=GK(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&&lm(n,i)===null?new Qs: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]!==Ce&&(l.rest=!0),o.kind[r]){case ft:{const c=o.textOf(r);if(c===Ia||!UK(n,i)&&(c===$a||c===Kg)){l.list=!0;return}l.kinds|=na,l.dict!==null&&!l.dict.decided&&l.dict.observe(c);return}case ys:{l.kinds|=Rd;const c=Number(o.textOf(r));(c<PK||c>xK)&&(l.wide=!0,Number.isSafeInteger(c)||(l.unsafe=!0));return}case Ce:l.kinds|=ia,n==="node"&&i==="graphics"&&this.positions&&this.inspectGraphics(l,r);return;default:{l.kinds|=Cu;const c=o.textOf(r);/\d/.test(c)&&!Number.isFinite(Number(c))&&this.report.warnOnce("precision",zl,`${n} key "${i}" holds the real ${c}, beyond the f64 range; it is stored as ${bs(c)>0?"":"-"}Infinity`,{line:o.line[r],element:i},`${zl}:overflow:${n}:${i}`)}}}noteStructure(e,n,i){const r=this.requireTokens();e!=="graph"&&(n==="graph"||n==="node"||n==="edge")&&r.kind[i]===Ce&&this.report.warnOnce("unsupported",sm,`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},`${sm}:${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]===ys||i.kind[c+1]===zb;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 Qn(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(iD,`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",kd,`gid ${e.kind[i]===Ce?"[...]":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(kK,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]===Ce){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]===ft?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",kd,`cluster vertex ${yo(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=Xg(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",kd,`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=dp(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&na)!==0&&(n.kinds&(Rd|Cu))!==0&&(n.kinds&ia)===0&&this.report.warnOnce("coercion",om,`${e} key "${n.key}" mixes numbers and strings; the column is string and the numbers are kept as written`,{element:n.key},`${om}:${e}:${n.key}`),n.unsafe&&!i&&this.report.warnOnce("precision",zl,`${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},`${zl}:${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"&&BS(n)==="int",s=r?"string":BS(n);let o=jK(s,n);o==="string"&&!n.list&&n.dict!==null&&n.kinds===na&&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:lm(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&ia)!==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",RK,`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]===ft?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===Rd?"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]===ft&&DK.test(i.stringOf(e));if(r)this.report.warning("validation-error",Dd,`flag "${n}" is written as the string ${yo(i,e)}; read as an integer`,{line:i.line[e],element:n});else if(i.kind[e]!==ys)return this.report.error("validation-error",nD,`flag "${n}" must be the integer 0 or 1, found ${yo(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",Dd,`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,zS)}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]===Ce?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",Dd,`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,cp)}}}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]===Ce?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",tD,`${e} must be a [ ... ] block, found ${yo(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===jr&&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",tm,`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",tm,`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===jr&&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 T=e+1;T<l;T=i.nextPair(T)){const D=i.textOf(T);D==="source"?u=this.structuralToken(u,T,"source"):D==="target"?f=this.structuralToken(f,T,"target"):D==="directed"?p=this.structuralToken(p,T,"directed"):D===o.weightFrom&&(h=T+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,I=this.readFlag(p,"directed")??this.headerDirected;d=this.requireResolver().addEdge(g,m,I?"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]===ft)return this.report.warnOnce("validation-error",eD,`${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]!==ys)throw new N("E_INVALID_ID",`${n} must be an integer or a string, found ${yo(i,e)}`,{reason:"not an integer",key:n,value:i.kind[e]===Ce?"[...]":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 ft:return this.coercer.text(n.stringOf(e));case ys:return this.coerceInteger(e,Number(n.textOf(e)));case Ce: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(bs(n.textOf(e)))}}restoredId(e){const n=this.requireTokens();switch(n.kind[e]){case ft:return n.stringOf(e);case Ce:throw new N("E_INVALID_ID",`${jr} must be a string or a number`,{reason:"record original id"});default:return bs(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 ft:return Vn(n.stringOf(e),this.report);case Ce:throw new N("E_INVALID_WEIGHT","edge weight is a record",{value:"[...]"});default:{const i=n.textOf(e),r=sf(bs(i));return r!==void 0&&ZA(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",Jv,e.message,{line:n,element:"node"});return;case"missing label":i.error("missing-value",Zv,e.message,{line:n,element:"node"});return;case"duplicate key":i.error("validation-error",nm,e.message,{line:n,element:"node"});return;case"not an integer":i.error("validation-error",em,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",Qv,e.message,{line:n,element:i});return}if(e.code==="E_INVALID_ID"&&s==="duplicate key"){r.error("validation-error",nm,e.message,{line:n,element:i});return}if(e.code==="E_INVALID_ID"&&s==="not an integer"){r.error("validation-error",em,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,HS(e)),i===cp&&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]===Ce?Xg(s,u):this.scalarOf(e,u)),a=l[0],c=e.position;let d=a;if(dp(a)&&c!==null){const u=this.writePosition(c,n,this.keepPositionSource?{...a}:a,r);d=this.keepPositionSource?a:u}else dp(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",rm,`${n}; the value is kept in the graphics json column (warned once for every such node)`,i,`${rm}:${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]===ft){const o=s.textOf(n);if(o===Ia||o===$a||o===Kg)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,HS(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 bs(i.textOf(n));case"string":return r===ft?i.stringOf(n):i.textOf(n);default:return r===ft?i.stringOf(n):sV(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:rD(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=fe(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>=MK&&(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 GK(t,e){switch(t.kind[e]){case ys:return Rd;case ft:return na;case Ce:return ia;default:return Cu}}function BS(t){return(t.kinds&ia)!==0?"record":(t.kinds&na)!==0?"string":(t.kinds&Cu)!==0?"real":"int"}function jK(t,e){switch(t){case"int":return e.wide?"f64":"i32";case"real":return"f64";case"string":return"string";default:return"json"}}function rD(t){return t.kind}function HS(t){const e={name:t.name,dtype:t.dtype,nullable:!0,origin:{format:"gml",id:t.key,title:null,type:rD(t),namespace:null}};return t.list&&(e.itemDtype=t.itemDtype??"string"),t.top&&(e.extra={gmlTopLevel:!0}),e}function yo(t,e){switch(t.kind[e]){case Ce:return"a record";case ft:return`the string "${t.textOf(e)}"`;case zb:return`the real ${t.textOf(e)}`;case Ff:return`the word ${t.textOf(e)}`;default:return t.textOf(e)}}const FK=/^(?:\s|#[^\n]*\n)*graph\s*\[/,zK=/(?:^|\s)graph\s*\[/,WK=/^(?:\s|#[^\n]*\n)*[A-Za-z_]\w*\s+(?:"|[+-]?[0-9.]|\[)/;function BK(t){let e=new TextDecoder("utf-8",{fatal:!1}).decode(t);return e.charCodeAt(0)===65279&&(e=e.slice(1)),FK.test(e)?.95:WK.test(e)?zK.test(e)?.85:.4:0}const sD=Object.freeze({format:"gml",options:Object.freeze(["dictionaries","keepPositionSource","positions"]),extensions:Object.freeze([".gml"]),mimeTypes:Object.freeze(["text/x-gml","text/plain"]),sniff:BK,styles:YV,positions:xY,async import(t,e,n){if(eo(n))return $b(sD,t,e,n);const i=Qe(n,jS),r=new te("gml",i.errorLimit);bt(e,n,r),Et(n,r,FS);const s=YS(await Br(t,r,i),r);F(i.signal);const o=new WS(e,r,i,n);return o.run(s),o.graphCount>1&&r.warning("unsupported",qv,`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=Qe(n,jS),r=new te("gml",i.errorLimit);Et(n,r,FS);const s=YS(await Br(t,r,i),r),o=[];let l=1;for(let a=0;a<l;a++){F(i.signal);const c=a===0?r:new te("gml",i.errorLimit),d=e(a);bt(d,n,c);const u=new WS(d,c,i,n,a);u.run(s),l=u.graphCount,o.push(c.finish())}return F(i.signal),o}});function YS(t,e){try{return VY(t)}catch(n){throw n instanceof Fr&&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:bn,NO_GRAPH:Qg,MULTIPLE_GRAPHS:qv,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,MISSING_ID:Jv,MISSING_LABEL:Zv,MISSING_ENDPOINT:Qv,ID_TYPE:em,STRING_ID:eD,DUPLICATE_NODE:tm,REPEATED_KEY:nm,ELEMENT_TYPE:tD,FLAG_TYPE:nD,FLAG_VALUE:Dd,UNKNOWN_ENTITY:im,PRECISION:zl,GRAPHICS:rm,NESTED_ELEMENT:sm,GROUPS:kd,WIDENED:om,COLUMN_RENAMED:ln,ROLE_TAKEN:LK,ID_MERGED:Rn,OPTION_IGNORED:Jt,SINK_OPTION:Ln,DIRECTION_REFUSED:Ei,DIRECTION_FORCED:Yn,MIXED_DIRECTION:Er,ID_DROPPED:iD});const Xs="@_",vl="#text";class HK{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[Xs+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;VK(n,e.name,YK(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?(Sr(e.text)||(e.node[vl]=e.text),e.node):e.text}}function YK(t){return!t.hasAttrs&&!t.hasChildren?t.text:(Sr(t.text)||(t.node[vl]=t.text),t.node)}function VK(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 vu(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=vu(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===vl){if(n!==null&&typeof n=="object")return"#text must be a scalar";continue}if(e.startsWith(Xs)){const r=e.slice(Xs.length);if(!nu(r))return`"${r}" is not an XML attribute name`;if(n!==null&&typeof n=="object")return`attribute ${r} must be a scalar`;continue}if(!nu(e))return`"${e}" is not an XML element name`;const i=vu(n);if(i!==null)return i}return null}function va(t,e,n){const i=vu(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(et(Da(t)));return}const r=t;let s=null;for(const[o,l]of Object.entries(r))o===vl?s=Da(l):o.startsWith(Xs)||Kb(o,l,e,n);s!==null&&n.push(et(s))}function Kb(t,e,n,i){if(Array.isArray(e)){for(const s of e)Kb(t,s,n,i);return}const r=n===null?"":`
145
+ ${n}`;if(e===null||typeof e!="object"){const s=Da(e);i.push(s.length===0?`${r}<${t}/>`:`${r}<${t}>${et(s)}</${t}>`);return}KK(t,e,n,i)}function KK(t,e,n,i){const r=n===null?"":`
146
+ ${n}`,{attrs:s,text:o,hasChildren:l}=XK(e);if(!l){i.push(o===null||o.length===0?`${r}<${t}${s}/>`:`${r}<${t}${s}>${et(o)}</${t}>`);return}const a=n===null||o!==null?null:`${n} `;i.push(`${r}<${t}${s}>`),o!==null&&i.push(et(o));for(const[c,d]of Object.entries(e))c!==vl&&!c.startsWith(Xs)&&Kb(c,d,a,i);i.push(a===null?`</${t}>`:`${r}</${t}>`)}function XK(t){let e="",n=null,i=!1;for(const[r,s]of Object.entries(t))r===vl?n=Da(s):r.startsWith(Xs)?e+=` ${r.slice(Xs.length)}="${W(Da(s))}"`:i=!0;return{attrs:e,text:n,hasChildren:i}}function Da(t){switch(typeof t){case"string":return t;case"number":case"boolean":case"bigint":return String(t);default:return""}}const ka="yfiles.",qK={position:{dtype:"f64",components:3,role:"position",mutable:!0,extra:{units:"px",yAxis:"down",anchor:"top-left",width:`${ka}width`,height:`${ka}height`}},width:{dtype:"f64"},height:{dtype:"f64"},color:{dtype:"string"},borderColor:{dtype:"string"},borderWidth:{dtype:"f64"},label:{dtype:"string",role:"label"},shape:{dtype:"string"}},JK={color:{dtype:"string"},width:{dtype:"f64"},directed:{dtype:"bool"},targetArrow:{dtype:"string"},sourceArrow:{dtype:"string"}};function ZK(t,e,n){return{...(t==="node"?qK:JK)[e],name:ka+e,nullable:!0,origin:{format:"graphml",id:n,title:null,type:t==="node"?"ShapeNode":"PolyLineEdge",namespace:"yfiles"}}}function QK(t){return t.nodes.byRole("position")?.meta.origin?.namespace==="yfiles"?{tool:"yed"}:null}function oD(t){return t.dtype!=="json"&&t.origin?.namespace==="yfiles"&&t.name.startsWith(ka)}function eX(t,e,n){const i=t.meta.name.slice(ka.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=tX(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 tX(t,e,n,i){const r=new Set;for(const s of t){const o=lD(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 lD(t,e,n=[]){const i=[];if(t==="node"){const r=un(e,"ShapeNode"),s=un(e,"RectD");s!==void 0?am({"@_x":kt(s,"X"),"@_y":kt(s,"Y"),"@_width":kt(s,"Width"),"@_height":kt(s,"Height")},i,n):r===void 0?am(un(rX(e),"Geometry"),i,n):nX(r,i,n)}else{const r=un(e,"PolyLineEdge");r!==void 0&&oX(r,i,n)}return i}function nX(t,e,n){am(un(t,"Geometry"),e,n),Gi(e,"color",dm(kt(un(t,"Fill"),"color")));const i=un(t,"BorderStyle");Gi(e,"borderColor",dm(kt(i,"color"))),Gi(e,"borderWidth",Io(kt(i,"width"),"borderWidth",n));const r=un(t,"NodeLabel");(typeof r=="string"?r.length>0:r!==void 0)&&e.push(["label",(typeof r=="string"?r:lX(r)??"").trim()]),Gi(e,"shape",cm(kt(un(t,"Shape"),"type")))}function am(t,e,n){const i=Io(kt(t,"x"),"x",n),r=Io(kt(t,"y"),"y",n);i!==void 0&&r!==void 0&&e.push(["position",[i,r,0]]),Gi(e,"width",Io(kt(t,"width"),"width",n)),Gi(e,"height",Io(kt(t,"height"),"height",n))}const iX=["GenericNode","ImageNode","SVGNode","UMLClassNode","UMLNoteNode","TableNode"];function rX(t){for(const i of iX){const r=un(t,i);if(r!==void 0)return r}const e=un(un(t,"ProxyAutoBoundsNode"),"Realizers"),n=Number.parseInt(kt(e,"active")??"0",10);return sX(e)[Number.isNaN(n)?0:n]}function sX(t){return typeof t!="object"||t===null?[]:Object.entries(t).filter(([e])=>!e.startsWith("@_")&&e!=="#text").flatMap(([,e])=>Array.isArray(e)?e:[e])}function oX(t,e,n){const i=un(t,"LineStyle");Gi(e,"color",dm(kt(i,"color"))),Gi(e,"width",Io(kt(i,"width"),"width",n));const r=un(t,"Arrows");if(r!==void 0&&typeof r=="object"){const s=kt(r,"target"),o=kt(r,"source");e.push(["directed",s!==void 0&&s!=="none"]),Gi(e,"targetArrow",s==="none"?void 0:cm(s)),Gi(e,"sourceArrow",o==="none"?void 0:cm(o))}}function Gi(t,e,n){n!==void 0&&t.push([e,n])}function un(t,e){if(!(typeof t!="object"||t===null)){for(const[n,i]of Object.entries(t))if(!n.startsWith("@_")&&n!=="#text"&&vs(n)===e)return Array.isArray(i)?i[0]:i}}function kt(t,e){if(typeof t!="object"||t===null)return;const n=t[`@_${e}`];return typeof n=="string"?n:void 0}function lX(t){const e=typeof t=="object"&&t!==null?t["#text"]:void 0;return typeof e=="string"?e:void 0}function cm(t){return t===void 0||t.length===0?void 0:t}function aX(t){if(t===void 0||t.length===0)return;const e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}function Io(t,e,n){const i=aX(t);return i===void 0&&t!==void 0&&t.length>0&&n.push(e),i}function dm(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 aD=Xe({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}),cX=new Set(["directed","pair","mutual","weight","timeText","originalId"]),dX=new Set(["position","color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen"]),cD=new Set(["label","id","sourcePort","targetPort","parent"]),uX={graph:new Set,node:new Set(["parent"]),edge:new Set(["id","sourcePort","targetPort"])},fX=Object.freeze({label:dr,id:cb,sourcePort:db,targetPort:ub,parent:fb}),hX="weight",pX={boolean:"bool",int:"i32",long:"f64",float:"f32",double:"f64",string:"string"},gX=2147483647,mX={node:"nodegraphics",edge:"edgegraphics",graph:"resources"};function yX(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 bX(t){const e=t.meta.extra[ZI];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 EX(t,e,n,i=!1){const r=new Set([...t.nodes,...t.edges].filter(T=>oD(T.meta)).map(T=>T.meta.name)),s=Un(t,aD,e,{roles:cD,roleNames:fX}).filter(T=>T.code!==w.JSON&&(T.column===null||!r.has(T.column))),o=(T,D,P=null,k=null)=>{s.push(Object.freeze({code:T,message:D,column:P,count:k}))};s.push(...Cy(t));const l=bX(t),a=new wX,c=up(t.graph,"graph",s,o),d=up(t.nodes,"node",s,o),u=up(t.edges,"edge",s,o),f=_X([...c,...d,...u],a);if(i){const T=new Map(f.map((P,k)=>[P.id,k])),D=(P,k)=>(T.get(P.keyId)??0)-(T.get(k.keyId)??0);d.sort(D),u.sort(D)}VS(d,JI,o),VS(u,qI,o);const h=SX(t,u,a,f,o),p=RX(t);p>0&&o(ur.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&&OX(t,g,e,o);const y=LX(t)>0&&e.sanitizeIds==="mangle",b=y?a.next(null):null,_=Ut(t,{foldMutual:!0});_.mutualCount>0&&o(ur.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=NX(t,_,n,l),I=xX(t);return I.reordered&&o(ur.HIERARCHY_REORDERED,"nodes are written in containment order (children nested under their parent); node indices change after a round trip",I.parent?.meta.name??null),I.unreachable>0&&o(ur.PARENT_CYCLE,`${I.unreachable} node${O(I.unreachable)} whose parent chain never reaches a root ${C(I.unreachable,"is","are")} written at the top level`,I.parent?.meta.name??null,I.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:I,meta:l,needsOriginalIdKey:y}}function VS(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 wX{constructor(){this.used=new Set,this.counter=0}next(e){if(e!==null&&yl(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 _X(t,e){const n=[],i=new Map;for(const s of t){const{origin:o}=s.column.meta;if(o!==null&&o.format===rt&&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===rt&&o.id!==null?i.get(o.id)??[s]:[s],c=l.length>1&&l.every(p=>p===s||AX(s,p))?l:[s],d=e.next(o!==null&&o.format===rt?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 SX(t,e,n,i,r){const s=wt(t),o=t.meta.weightOrigin,l=s.weighted&&o!==null&&o.format===rt,a=l&&o.title!==null?o.title:hX;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")&&!DX(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 OX(t,e,n,i){e.dtype!=="string"&&e.dtype!=="dict"&&i(ur.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=PX(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 NX(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)||(uD(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 AX(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 up(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(oD(a)){const g=e==="graph"?0:eX(l,s,e);g>0&&i(ur.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(ur.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&&(cX.has(c)||dX.has(c)||uX[e].has(c)))continue;c!==null&&c!=="label"&&cD.has(c)&&(dD(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=kX(l);g>0&&i(ur.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===rt;let p=null;u||(p=h&&f.title!==null?f.title:d,c==="label"&&e!=="graph"&&p!==dr?p=TX(l,e,o,n,i):c===null&&e!=="graph"&&p===dr&&i(w.ROLE_ASSUMED,`${e} column "${d}" has no role but is titled "${dr}", which the importer reads back with the label role`,d,l.length-l.nullCount)),r.push({column:l,domain:e,keyId:"",attrType:u?null:IX(l),attrName:p,yfilesType:u?f?.type??mX[e]:null,yfiles:u})}return r}function TX(t,e,n,i,r){const{name:s}=t.meta;return n.has(dr)?(dD(i,s),r(w.ROLE,`${e} column "${s}" (label) is written as a plain attribute: the label slot (a key titled "${dr}") is taken by column "${dr}" and the role is lost`,s,t.length-t.nullCount),s):dr}function dD(t,e){const n=t.findIndex(i=>i.code===w.COLUMN_NAME_CHANGED&&i.column===e);n>=0&&t.splice(n,1)}function IX(t){const{meta:e}=t,{origin:n}=e,i=n!==null&&n.format===rt&&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"&&CX(t)?"long":"double";case"u8":return"int";case"u32":return vX(t)<=gX?"int":"long";case"string":return i!==null&&i.trim().toLowerCase()==="long"&&$X(t)?"long":i!==null&&pX[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 $X(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!/^[+-]?\d+$/.test(String(t.value(e))))return!1;return!0}function CX(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 vX(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 DX(t,e){for(let n=0;n<t.edgeCount;n++)if(e.isExplicit(n)&&!Number.isInteger(e.value(n)))return!1;return!0}function kX(t){if(t.dtype!=="json")return 0;let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&vu(t.values[n])!==null&&e++;return e}function RX(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"?yl(r)&&Qd(r):!Number.isSafeInteger(r))&&n++}return n}function LX(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++)yl(String(e.idOf(i)))||n++;return n}function PX(t){let e=0;for(let n=0;n<t.length;n++)t.isSet(n)&&!yl(Ld(t,n))&&e++;return e}function Ld(t,e){const n=t.value(e);return typeof n=="string"?n:typeof n=="number"?Number.isInteger(n)?Ue(n):je(n):String(n)}function uD(t,e){return t.mateOf(e)===A&&t.sourceDirected(e)}function xX(t){const e=t.nodes.byRole("parent"),n=ec(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 MX(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 lt(t.data[e]);case"f64":{const i=t.data[e];return(n==="long"||n==="int")&&Number.isInteger(i)?Ue(i):je(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 UX(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"?lt(n):(e==="long"||e==="int")&&Number.isInteger(n)?Ue(n):je(n);case"string":return n;default:return JSON.stringify(n)??""}}function Xb(t,e,n,i){const{column:r}=t;if(r.isSet(e)){if(t.yfiles&&r.dtype==="json"){GX(t.keyId,r.values[e],n,i);return}i.push(`
147
+ ${n}<data key="${t.keyId}">${et(MX(r,e,t.attrType))}</data>`)}}function GX(t,e,n,i){if(e===null||typeof e!="object"||Array.isArray(e)){const r=[];va(e,n,r),i.push(`
148
+ ${n}<data key="${t}">${r.join("")}</data>`);return}i.push(`
149
+ ${n}<data key="${t}">`),va(e,`${n} `,i),i.push(`
150
+ ${n}</data>`)}function jX(t,e,n,i){if(t.yfilesType===null){i.push(`
151
+ ${n}<default>${et(UX(e,t.attrType)??"")}</default>`);return}const r=e.meta.default;if(r!==null&&typeof r=="object"&&!Array.isArray(r))i.push(`
152
+ ${n}<default>`),va(r,`${n} `,i),i.push(`
153
+ ${n}</default>`);else{const s=[];va(r,n,s),i.push(`
154
+ ${n}<default>${s.join("")}</default>`)}}function FX(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}/>
155
+ `;const l=[`${i}>`],a=`${e} `;return typeof s=="string"&&l.push(`
156
+ ${a}<desc>${et(s)}</desc>`),o&&jX(t,r,a,l),l.push(`
157
+ ${e}</key>
158
+ `),l.join("")}function zX(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=Ld(t,o);yl(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(Ld(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=eT(Ld(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*KS(t,e){const n=bl(t,"nmtoken",e.options.sanitizeIds),i=zX(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"?>
159
+ `,yield WX(e);for(const g of e.keys)yield FX(g,r);e.originalIdKey!==null&&(yield`${r}<key id="${e.originalIdKey}" for="node" attr.name="${ks}" attr.type="string"/>
160
+ `);const a=e.meta?.graphId??"G";yield`${r}<graph id="${W(a)}" edgedefault="${e.edgedefault}">`;const{description:c}=t.meta;c!==null&&(yield`
161
+ ${s}<desc>${et(c)}</desc>`);const d=[];for(const g of e.graphColumns)Xb(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*YX(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=BX(t,e,g,String(n.idAt(p.src[g])),String(n.idAt(p.dst[g])));yield HX(e,g,i[g],m,[s,o])}yield`
162
+ ${r}</graph>
163
+ </graphml>
164
+ `}function WX(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(Hw)&&e.y===void 0)&&(e.y=Hw),Object.values(e).includes(Sd)||(e.xsi=Sd);let i=`<graphml xmlns="${gs}"`;for(const[s,o]of Object.entries(e))i+=` xmlns:${s}="${W(o)}"`;const r=Object.entries(e).find(([,s])=>s===Sd)?.[0]??"xsi";return`${i} ${r}:schemaLocation="${f9}">
165
+ `}function BX(t,e,n,i,r){let s=` source="${W(i)}" target="${W(r)}"`;const o=t.directed&&uD(e.folding,n);o!==(e.edgedefault==="directed")&&(s+=` directed="${o?"true":"false"}"`);const l=XS(e.sourcePortColumn,n);l!==null&&(s+=` sourceport="${W(l)}"`);const a=XS(e.targetPortColumn,n);return a!==null&&(s+=` targetport="${W(a)}"`),s}function HX(t,e,n,i,r){const[s,o]=r,l=[`
166
+ ${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(`
167
+ ${o}<data key="${c}">${et(u)}</data>`)}for(const c of t.edgeColumns)Xb(c,e,o,l);return l.length===a?l.push("/>"):(l.splice(a,0,">"),l.push(`
168
+ ${s}</edge>`)),l.join("")}function XS(t,e){if(!t?.isSet(e))return null;const n=t.value(e);return typeof n=="string"?n:String(n)}function*YX(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=[`
169
+ ${g}<node id="${W(String(n.idAt(h)))}"`],y=m.length;e.originalIdKey!==null&&n.isChanged(h)&&m.push(`
170
+ ${g}${r}<data key="${e.originalIdKey}">${et(String(n.originalAt(h)))}</data>`);for(const b of e.nodeColumns)Xb(b,h,g+r,m);if(d(h)){m.splice(y,0,">");const b=`${String(n.idAt(h))}:`;return m.push(`
171
+ ${g}${r}<graph id="${W(b)}" edgedefault="${e.edgedefault}">`),m.join("")}return m.length===y?m.push("/>"):(m.splice(y,0,">"),m.push(`
172
+ ${g}</node>`)),m.join("")},f=h=>{const p=i+r.repeat(h*2);return`
173
+ ${p}${r}</graph>
174
+ ${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 VX=Object.freeze({format:rt,options:Object.freeze(["edgedefault","pretty"]),capabilities:aD,styles:Object.freeze({capabilities:Na}),check(t,e){const{plan:n,styled:i}=fp(t,e);return Object.freeze([...n.notes,...i?.notes??[]])},export(t,e){const{plan:n,written:i}=fp(t,e);return ei(KS(i,n))},exportToString(t,e){const{plan:n,written:i}=fp(t,e);return ti(KS(i,n))}});function fp(t,e){const n=t7(t,e?.styles),i=n?.snapshot??t,r=EX(i,dt(e),yX(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 fD=16,pn=Symbol("x:Null"),KX=/^\{\s*[\w.-]*:?GraphMLReference\s+([^\s}]+)\s*\}$/,XX=/^\{\s*[\w.-]*:?Null\s*\}$/,qX=new Set(["NodeStyle","EdgeStyle","NodeLabels","EdgeLabels","NodeGeometry","EdgeGeometry"]);function JX(t){if(typeof t!="string"||!t.includes("://"))return null;const e=t.slice(t.lastIndexOf("/")+1);return qX.has(e)||e==="SharedData"?e:null}function hp(t){const e=new Map;for(const n of t){const i=n.dtype==="json"&&n.meta.origin?.namespace==="yfiles"?JX(n.meta.origin.type):null;i!==null&&!e.has(i)&&e.set(i,n.meta.name)}return e}class ZX{constructor(e){this.shared=new Map,this.cycles=0;for(const n of yt(e,"SharedData"))Or(n)&&this.collect(n)}collect(e){for(const n of Object.keys(e).filter(i=>!i.startsWith("@_")&&i!=="#text"))for(const i of yt(e,Ui(n))){const r=QX(i);r!==null&&!this.shared.has(r)&&this.shared.set(r,{tag:Ui(n),e:i})}}tooDeep(e){return e>fD?(this.cycles++,!0):!1}object(e,n){return e==="GraphMLReference"?this.shared.get(R(n,"ResourceKey")??"")??null:{tag:e,e:n}}first(e){if(!Or(e))return null;for(const n of Object.keys(e))if(!n.startsWith("@_")&&n!=="#text")return this.object(Ui(n),yt(e,Ui(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>De)return i;if(XX.test(i))return pn;const r=KX.exec(i);return r!==null?this.shared.get(r[1])??null:i}}function QX(t){if(!Or(t))return null;for(const e of Object.keys(t))if(e.startsWith("@_")&&Ui(e.slice(2))==="Key"){const n=t[e];return typeof n=="string"?n:null}return null}function Je(t,e){const n=R(t.e,e);return n!==void 0?n:ce(t.e,`${t.tag}.${e}`)}function ji(t,e,n,i=0){if(t.tooDeep(i))return null;const r=t.deref(e,i);if(r===null||r===pn)return r;if(typeof r=="string")return{raw:r,dialect:"yfiles3"};const{tag:s}=r;if(s==="SolidColorFill")return ji(t,Je(r,"color"),n,i+1);if(s==="Color")return ji(t,R(r.e,"value"),n,i+1);if(s==="CssFill"){const o=R(r.e,"cssString");return o===void 0?null:{raw:o,dialect:"css"}}if(s.endsWith("Gradient")){n?.();const o=yt(r.e,"GradientStop")[0]??yt(ce(r.e,`${s}.GradientStops`),"GradientStop")[0];return o===void 0?null:ji(t,R(o,"color"),null,i+1)}return s==="Stroke"?ji(t,Je(r,"fill"),n,i+1):null}const eq=new Map([["solid","solid"],["dash","dashed"],["dot","dotted"],["dashdot","dash-dot"],["dashdotdot","dash-dot"]]);function Ra(t,e){const n=t.deref(e);if(n===null||n===pn)return n;if(typeof n=="string"||n.tag!=="Stroke")return{color:ji(t,e,null),width:1,line:"solid"};let i="solid";const r=t.deref(Je(n,"dashStyle"),1);if(typeof r=="string"){const o=r.slice(0,De).toLowerCase().replaceAll("_","");i=eq.get(o)??`other:${o}`}else if(r!==null&&r!==pn){const o=(R(r.e,"dashes")??"").slice(0,De).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=Je(n,"thickness");return{color:ji(t,Je(n,"fill"),null),width:typeof s=="string"?s:1,line:i}}function Dl(t,e,n,i,r){if(t===null||t===pn)return;const s=$e(t.raw,t.dialect,r(e));if(s===null)return;i(e,s.color);const o=_l(s,null,r(e),n!==null);n!==null&&i(n,o)}const Vc="#FF000000",tq="#FFB7C9E3",hD=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"}]]),nq=10;function qS(t,e,n,i){const r=t===void 0?e:V(t,i("cornerRadius"));if(r===0){n("shape","rectangle");return}n("shape","round-rectangle"),n("cornerRadius",r)}function iq(t,e,n,i){const r=s=>{Dl(ji(t,s,()=>{B(i("fill"),v.GRADIENT,e.tag)}),"fill","fillOpacity",n,i)};switch(e.tag){case"BevelNodeStyle":return r(Je(e,"color")??Vc),n("borderWidth",0),qS(R(e.e,"radius"),10,n,i),!0;case"PanelNodeStyle":return r(Je(e,"color")??Vc),n("borderWidth",0),n("shape","rectangle"),!0;case"ShinyPlateNodeStyle":{r(Je(e,"fill")??Vc);const s=Je(e,"stroke");return s===void 0?n("borderWidth",0):um(Ra(t,s),n,i),qS(R(e.e,"radius"),5,n,i),!0}case"FlowchartNodeStyle":{r(Je(e,"fill")??tq);const s=R(e.e,"type")??"";s==="annotation"?n("borderWidth",0):um(Ra(t,Je(e,"stroke")??Vc),n,i);const o=s===""||s==="annotation"?null:vf(`flowchart.${s}`);return o===null&&s!==""&&s!=="annotation"&&B(i("shape"),v.UNKNOWN_VALUE,s.slice(0,De)),n("shape",o?.shape??"rectangle"),o?.points!==void 0&&n("shapePoints",o.points),!0}default:return!1}}function um(t,e,n){t===pn?e("borderWidth",0):t!==null&&(Dl(t.color,"borderColor","borderOpacity",e,n),e("borderWidth",V(t.width,n("borderWidth"))),e("borderStyle",oe("borderStyle",t.line,"yfiles3",n("borderStyle"))))}function rq(t,e,n,i,r){const s=sq(t,t.first(e));if(s===null||typeof s!="object"){e!=null&&e!==""&&B(i("fill"),v.UNRESOLVED,"NodeStyle");return}const o=s;if(iq(t,o,n,i))return;Dl(ji(t,Je(o,"fill"),()=>{B(i("fill"),v.GRADIENT,o.tag)}),"fill","fillOpacity",n,i),um(Ra(t,Je(o,"stroke")),n,i),n("shape",oq(o,i));const l=hD.get(fm(R(o.e,"shape"))??"")?.points;l!==void 0&&n("shapePoints",l);const a=o.tag==="RectangleNodeStyle"?R(o.e,"cornerSize"):void 0;a!==void 0&&n("cornerRadius",V(a,i("cornerRadius")));const c=o.tag==="ShapeNodeStyle"?fm(R(o.e,"shape")):null;c==="round-rectangle"?n("cornerRadius",nq):c==="pill"&&r!==null&&n("cornerRadius",Math.min(r.width,r.height)/2)}function fm(t){return t===void 0?null:t.slice(0,De).trim().toLowerCase().replaceAll("_","-")}function sq(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(Je(n,"wrappedStyle"))}return n}function oq(t,e){const n=R(t.e,"shape");return n!==void 0?hD.get(fm(n)??"")?.shape??oe("shape",n,"yfiles3",e("shape")):t.tag==="RectangleNodeStyle"?R(t.e,"cornerSize")===void 0?"rectangle":"round-rectangle":t.tag==="ShapeNodeStyle"?"rectangle":(B(e("shape"),v.UNKNOWN_VALUE,t.tag),`other:${t.tag}`)}function lq(t,e,n,i){const r=t.first(e);if(r===null)return;const s=Ra(t,Je(r,"stroke"));s===pn?B(i("color"),v.NO_STROKE,"{x:Null}"):s!==null&&(Dl(s.color,"color","opacity",n,i),n("width",V(s.width,i("width"))),n("lineStyle",oe("lineStyle",s.line,"yfiles3",i("lineStyle"))));for(const o of["source","target"])aq(t,t.deref(Je(r,`${o}Arrow`)),o,n,i)}function aq(t,e,n,i,r){const s=`${n}Arrow`;let o=null,l=!1;if(e!==null&&e!==pn&&typeof e=="object"){o=R(e.e,"type")??"DEFAULT";const a=ji(t,Je(e,"fill"),null),c=a===pn?Ra(t,Je(e,"stroke")):null;l=c!==null&&c!==pn,Dl(c!==null&&c!==pn?c.color:a,`${n}ArrowColor`,null,i,r)}else typeof e=="string"&&(o=e);if(o!==null){const a=oe("arrow",cq.get(o.toUpperCase())??o,"yfiles3",r(s));i(s,l?dq.get(a??"")??a:a)}}const cq=new Map([["DEFAULT","triangle"],["STEALTH","triangle"],["ELLIPSE","circle"]]),dq=new Map([["triangle","triangle-open"],["diamond","diamond-open"],["circle","circle-open"]]);function uq(t,e,n,i,r){const s=yt(ce(e,"List"),"Bend").map(f=>{const[h,p]=(R(f,"Location")??"").split(",").map(Number);return[h,p]}),[o,l,a]=i,c=a?zs([o[0],o[1]],[o[2],o[3]],s,!0):Ol([o[0],o[1]],[l[0],l[1]],s,!0);r("bends",c);const d=t.first(n),u=d===null?void 0:R(d.e,"smoothingLength");c!==null&&d?.tag==="PolylineEdgeStyle"&&Number(u)>0&&r("curved",!0)}const fq=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"]]),hq=new Map([["ExteriorLabelModelParameter","outside"],["ExteriorNodeLabelModelParameter","outside"],["SandwichParameter","outside"],["SandwichLabelModelParameter","outside"],["InteriorLabelModelParameter","inside"],["InteriorNodeLabelModelParameter","inside"],["InteriorStretchLabelModelParameter","inside"],["StretchNodeLabelModelParameter","inside"]]),pq=/^\{\s*[\w.-]*:?Static\s+(?:[\w.-]+:)?(\w+)\.(\w+)\s*\}$/;function pD(t,e){const n=R(e,"LayoutParameter");if(n!==void 0){const r=pq.exec(n.slice(0,De).trim());if(r!==null)return{tag:`${r[1]}Parameter`,e:{"@_Position":r[2]}}}const i=t.deref(n??ce(e,"Label.LayoutParameter"));return i===null||i===pn||typeof i!="object"?null:i}function gq(t,e){const n=pD(t,e),i=n===null?void 0:hq.get(n.tag);if(n===null||i===void 0)return"center";const r=R(n.e,"Position")??"",s=fq.get(r.slice(0,De).toLowerCase().replaceAll("_",""));return s===void 0?"center":i==="inside"?`inside-${s}`:s}const mq=new Map([["aboveedge","top"],["belowedge","bottom"],["onedge","center"],["centerabove","top"],["centerbelow","bottom"],["centercentered","center"]]),yq=new Map([["NinePositionsEdgeLabelModelParameter","Position"],["EdgePathLabelModelParameter","SideOfEdge"]]);function bq(t,e){const n=pD(t,e);if(n===null)return null;const i=R(n.e,"Ratio");if(i!==void 0&&Number(i)!==.5)return null;const r=yq.get(n.tag),s=r===void 0?void 0:R(n.e,r);return s===void 0?null:mq.get(s.slice(0,De).toLowerCase())??null}function Eq(t,e,n,i){let r,s="",o=0;for(const a of yt(ce(e,"List"),"Label")){const c=R(a,"Text")??wb(ce(a,"Label.Text"))??"";c.trim().length!==0&&(r===void 0?(r=a,s=c):o++)}if(r===void 0)return;o>0&&B(i("label"),v.EXTRA_LABELS,`${String(o+1)} labels`),n("label",nt(s,i("label"))),n("labelPosition",i("label").target==="node"?gq(t,r):bq(t,r));const l=t.deref(R(r,"Style")??ce(r,"Label.Style"));l===null||l===pn||typeof l!="object"||!l.tag.endsWith("LabelStyle")||(Dl(ji(t,Je(l,"textFill"),null),"labelColor",null,n,i),wq(t.deref(Je(l,"font")),n,i))}function wq(t,e,n){if(t===null||t===pn||typeof t!="object"||t.tag!=="Font")return;e("labelSize",V(R(t.e,"fontSize"),n("labelSize")));const i=R(t.e,"fontFamily");i!==void 0&&e("labelFont",nt(i.replaceAll(/(^['"])|(['"]$)/g,""),n("labelFont")));const r=R(t.e,"fontWeight");r!==void 0&&e("labelWeight",oe("weight",r,"yfiles3",n("labelWeight")))}const _q={node:["NodeStyle","NodeLabels","NodeGeometry"],edge:["EdgeStyle","EdgeLabels","EdgeGeometry"]};function Sq(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]=_q[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,I)=>{u.put(m,S,I)};let _=null;if(p!==void 0&&!a){const S=D=>l.subarray(4*D,4*D+4),[I,T]=[i.edgeSource(m),i.edgeTarget(m)];uq(o,g(p,m),g(f,m),[S(I),S(T),I===T],b)}else p!==void 0&&(_=Oq(g(p,m),m,l,b,y));f!==void 0&&a?rq(o,g(f,m),b,y,_):f!==void 0&&lq(o,g(f,m),b,y),h!==void 0&&Eq(o,g(h,m),b,y)}return u.values}function Oq(t,e,n,i,r){const s=ce(t,"RectD"),o=V(R(s,"Width"),r("width")),l=V(R(s,"Height"),r("height"));if(i("width",o),i("height",l),o===null||l===null)return null;const[a,c]=[Number(R(s,"X")),Number(R(s,"Y"))];return n.set([a+o/2,c+l/2,o,l],4*e),{width:o,height:l}}function Nq(t,e,n){const i=hp(t.nodes),r=hp(t.edges);if(![...i.keys(),...r.keys()].some(h=>h!=="SharedData"))return null;const l=hp(t.graph).get("SharedData"),a=new ZX(l===void 0?null:K(t.graph.value(l,0))),c=new Float64Array(4*t.nodeCount).fill(Number.NaN),d=(h,p)=>Sq({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(fD)} or circular (${String(a.cycles)})`}),{node:u,edge:f}}const Aq=["r","g","b","size"];function gD(t){return t.has("r")&&t.has("g")&&t.has("b")}function Tq(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:gD(s),size:r==="node"&&s.has("size"),label:s.has("label")};for(let c=0;c<o;c++)n.budget.spend(r,1),Iq(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 Iq(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,$e({r:o,g:l,b:a},"gephi",s(c))?.color??null)}}if(i.size){const o=V(K(t.value("size",n)),s("width"));r("width",o),r("height",o)}i.label&&r("label",nt(K(t.value("label",n)),s("label")))}function $q(t,e){const n=t.graph.has(Z)?K(t.graph.value(Z,0)):null;typeof n=="string"&&Vz(t,n,e)}function Cq(t,e){const n=new re,i={node:Rg(t.nodes),edge:Rg(t.edges)},r=Nq(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=zz(t,n,e.budget);if(s!==null)return $q(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(gD(t.nodes)){const o=Tq(t,n,e);delete o.edge.color;const l=Gb(t,{fill:o.node.fill,width:o.node.width},{},e.budget),a=c=>Aq.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",nt(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 vq(t,e){return e==="xmlns"||/^(xmlns|xml|xsi):/.test(e)||mD(t,e)}function Dq(t,e,n){return n?`the <${t}> parse hint ${e} is ignored`:jq.has(e)?`the <${t}> attribute ${e} is not kept`:`the <${t}> attribute ${e} is not a GraphML attribute; it is not kept`}const kq=new Set(["id","edgedefault","parse.nodes","parse.edges"]),Rq=new Set(["id"]),Lq=new Set(["id","for","attr.name","attr.type","name","type","yfiles.type"]),Pq=new Set(["key"]),xq=new Set(["id"]),Mq=new Set(["node","type"]),Uq=new Set(["name"]),JS=new Set;function mD(t,e){return t==="key"&&e.endsWith(":attr.uri")}function Gq(t){for(const[e,n]of t)if(mD("key",e)&&n.length>0)return n;return null}const jq=new Set(["id","port","parse.order","parse.nodeids","parse.edgeids"]),ZS=16,Fq=new Set(["id","source","target","directed","sourceport","targetport"]),zq={ids:"canonical",defaultDirected:!1,weightFrom:"weight"},Wq=4096,Bq=new Set(["json","skip"]),Hq=64,Yq=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","long","restoreMangledIds","hyperedges","errorLimit","signal","onProgress"]);class QS{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 Vq{constructor(e,n,i,r){this.ctx=[],this.keys=new Map,this.graphs=[],this.nodes=[],this.declared=new QS,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 QS,this.deferred=[],this.graphIds=new Set,this.topGraphs=0,this.rootNs=gs,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 Qn(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(vs(e));return}const o=vs(e);if(s!==null&&r!==gs&&r!==""&&r!==this.rootNs){this.unknownElement(e,i);return}switch(s){case null:o!=="graphml"&&this.report.fail(G.NOT_GRAPHML,`the root element is <${e}>, not <graphml>`,{line:i}),r!==gs&&r!==""&&this.report.warning("validation-error",G.NAMESPACE,r===null?`the root <${e}> uses an undeclared prefix; read as GraphML`:`the root <${e}> is in the namespace ${JSON.stringify(r)}, not ${gs}; read as GraphML`,{line:i,element:r}),this.rootNs=r,this.reportUnreadAttributes("graphml",n,JS,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:Sr(e)||this.report.warnOnce("validation-error",G.STRAY_TEXT,"text where GraphML allows only elements was ignored",{line:n})}}finish(){this.graphSeen||this.report.fail(G.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",G.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:rt,description:this.description??void 0,weightOrigin:this.weightOrigin===null?void 0:{format:rt,id:this.weightOrigin.id,title:this.weightOrigin.title,type:this.weightOrigin.type,namespace:null},extra:{[ZI]:e}})}readRoot(e){for(const[n,i]of e)n.startsWith("xmlns:")&&i!==gs&&i!==Sd&&(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,JS,r),this.pendingKey!==null&&(this.pendingKey.defaultText!==null||this.pendingKey.defaultTree!==void 0)&&this.report.warning("validation-error",G.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",G.DESC_DROPPED,`the <desc> of a ${this.graphs.length===1?"second top-level":"nested"} <graph> is not kept`,{line:r},`${G.DESC_DROPPED}:graph`),this.ctx.push(10));return;case"data":s?this.beginData(i,r,"graph"):(this.report.warnOnce("unsupported",G.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",G.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",G.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",G.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",G.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",G.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",G.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",G.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,Uq,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",G.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,Mq,r),this.readEndpoint(i,r),this.ctx.push(10);return;case"data":this.report.warnOnce("unsupported",G.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",G.DESC_DROPPED,"the <desc> of a hyperedge is not kept by the star / clique expansions",{line:r},`${G.DESC_DROPPED}:hyperedge`),this.ctx.push(10);return;default:this.unknownElement(e,r)}}unknownElement(e,n){this.report.warnOnce("unsupported",G.UNKNOWN_ELEMENT,eJ(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",G.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)&&!vq(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>=ZS&&!r&&this.unknownOverflow.set(e,(this.unknownOverflow.get(e)??0)+1),s.add(n),s.size>ZS&&!r))return;const o=r?G.PARSE_HINT_IGNORED:G.UNKNOWN_XML_ATTRIBUTE;this.report.warning("unsupported",o,Dq(e,n,r),{line:i,element:n})}beginGraph(e,n,i){this.reportUnreadAttributes("graph",e,kq,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",G.EDGEDEFAULT_MISSING,r?`<graph> has no edgedefault; read as ${c}`:`a nested <graph> has no edgedefault; it takes its container's (${c})`,{line:n},`${G.EDGEDEFAULT_MISSING}:${r?"top":"nested"}`)}else l=r?this.options.defaultDirected:this.graphs[this.graphs.length-1].directed,this.report.error("validation-error",G.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",G.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",G.PARSE_HINT_IGNORED,`the ${c} hint of a second top-level <graph> is ignored`,{line:n,element:c},`${G.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",G.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",G.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=Kq(e);return r===null||r>cA?(this.report.warning("validation-error",G.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,Lq,n);const i=e.get("id")??null;i!==null&&this.unknownKeyIds.delete(i)&&this.report.warning("missing-value",G.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",G.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",G.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?Gq(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",G.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",G.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",G.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&&by(s,this.options.weightFrom)){l=!0,this.weightOrigin??={id:e.id,title:e.attrName,type:e.attrType};continue}if(f==="node"&&!r&&s===ks){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=pa({format:rt,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===dr?"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",G.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:rt,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(g9,e.id,this.takenIn("node")),dtype:"string",nullable:!0,role:"originalId",origin:{format:rt,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=fe(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"?JI:qI,i=Zd(this.sink,e);return r=>n.has(r)||i(r)}beginData(e,n,i){this.reportUnreadAttributes("data",e,Pq,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",G.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",G.UNKNOWN_KEY,`<data> references undeclared key "${r}"`,{line:n,element:r})):!l.skipped&&!l.domains.includes(i)?this.report.warnOnce("validation-error",G.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",G.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 HK,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",G.ORIGINAL_ID_IGNORED,typeof i=="string"?`the ${ks} value comes after the node's nested <graph>, which added the node under its written id; it is not restored`:`the ${ks} 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",G.DATA_NESTED,"a weight value must be text",r);return}s.weightKey!==null&&s.weightKey!==n.id&&this.report.warning("validation-error",G.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=Vn(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=lD(e,i,o);for(const a of o)this.report.warnOnce("validation-error",G.YFILES_VALUE,`a yFiles ${e} ${a} that is not a number is not mapped to its yfiles column (the graphics tree is kept)`,r,`${G.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}=fe(this.sink,e,ZK(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(ur.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",G.DATA_STRUCTURED,`<data> of the untyped attribute "${e.name}" holds elements; they are kept as XML text`,{line:i.line,element:e.name},`${G.DATA_STRUCTURED}:${e.name}`);const s=[];return va(n,"",s),s.join("").trim()}if(typeof n!="string"){this.report.error("validation-error",G.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"&&Sr(n)))try{const s=ga(n,r,e.listSyntax);return r.precision&&Jd(r,n)&&this.report.warnOnce("precision",ie,`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"&&Gp(e)&&this.report.warnOnce("precision",ie,`values of "${i}" beyond the double range (${e.trim()}) are stored as Infinity`,{line:r.line,element:i},`${ie}:overflow:${i}`)}beginNode(e,n){this.reportUnreadAttributes("node",e,Rq,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",G.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",G.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",G.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:fb,dtype:"u32",role:"parent",refersTo:"node",nullable:!0,origin:{format:rt,id:null,title:null,type:"graph",namespace:null}})),this.parentHandle}beginEdge(e,n){this.reportUnreadAttributes("edge",e,Fq,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",G.MISSING_ENDPOINT,"<edge> without a source",a)),(o===void 0||o.length===0)&&(this.skipEdge(l),this.report.error("missing-value",G.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",G.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",G.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:cb,dtype:"string",role:"id",unique:!0,nullable:!0,origin:{format:rt,id:null,title:null,type:"id",namespace:null}})),this.edgeIdHandle}portColumn(e){return e==="source"?(this.sourcePortHandle===A&&(this.sourcePortHandle=this.sink.declareEdgeColumn({name:db,dtype:"string",role:"sourcePort",nullable:!0,origin:{format:rt,id:null,title:null,type:"sourceport",namespace:null}})),this.sourcePortHandle):(this.targetPortHandle===A&&(this.targetPortHandle=this.sink.declareEdgeColumn({name:ub,dtype:"string",role:"targetPort",nullable:!0,origin:{format:rt,id:null,title:null,type:"targetport",namespace:null}})),this.targetPortHandle)}beginHyperedge(e,n){this.reportUnreadAttributes("hyperedge",e,xq,n);const i=e.get("id")??null,r={line:n,element:i};switch(this.options.hyperedges){case"error":throw this.report.error("unsupported",G.HYPEREDGE,'hyperedge refused (hyperedges: "error")',r),this.report.abort("hyperedge refused",{code:G.HYPEREDGE});case"skip":this.report.warnOnce("unsupported",G.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",G.HYPEREDGE_ENDPOINT,"<endpoint> without a node",r);return}if(o!=="in"&&o!=="out"&&o!=="undir"){this.skipEdge(i),this.report.error("validation-error",G.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",G.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",G.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:m9,dtype:"bool",nullable:!0,origin:{format:rt,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>=Hq&&(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",G.ID_MERGED,`id "${i.text}" merged with "${i.previousText}" as ${i.id} under ids: "number"`,{line:n,element:e})}}function Kq(t){if(t===void 0||!/^\d+$/.test(t))return null;const e=Number(t);return Number.isSafeInteger(e)?e:null}function Xq(t){const e=t?.yfiles;if(e===void 0)return"json";if(typeof e!="string"||!Bq.has(e))throw new N("E_UNSUPPORTED",`option yfiles: ${JSON.stringify(e)} is not "json" or "skip"`,{option:"yfiles",found:e});return e}function qq(t){const e=hT(t.subarray(0,Wq));if(!/^\uFEFF?\s*</.test(e))return 0;const n=e.search(/<([\w.-]+:)?graphml[\s>/]/);return n>=0?e.includes(gs,n)?1:.9:/^\s*<(\?xml|!--|!DOCTYPE)/.test(e)?.05:0}async function Jq(t,e,n){const i=Qe(n,zq),r=Xq(n),s=new te(rt,i.errorLimit);bt(e,n,s,!0),Et(n,s,Yq);const o=new Vq(e,s,i,r);try{await uf(Nr(t,s,{...i,declaredEncoding:df,xml:!0}),o)}catch(l){throw l instanceof Ay&&s.fail(G.EMPTY_INPUT,"the input is empty (no markup at all)",{line:l.line}),l instanceof ee&&s.fail(l instanceof cf?G.XML_NESTING:G.XML_SYNTAX,l.message,{line:l.line}),l}return o.finish(),F(i.signal),s.finish()}const Zq=Object.freeze({format:rt,options:Object.freeze(["yfiles"]),extensions:h9,mimeTypes:p9,sniff:qq,styles:Cq,positions:QK,import:Jq}),Qq=new Set(["graphml","key","default","graph","node","edge","hyperedge","endpoint","port","data","desc","locator"]);function eJ(t){return t==="key"?"element <key> is only allowed as a child of <graphml>, before the first <graph>; it was skipped":Qq.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 Vi=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"}}),tJ=Object.freeze({relation:{dtype:"dict",role:"kind"},qualifiers:{dtype:"json"},meta:{dtype:"json"}}),lo="graphty.placeholder";function La(t,e){if(e===lo)return{name:e,dtype:"bool",nullable:!0,origin:{format:"graphty",id:"placeholder"}};const n=(t==="node"?Vi:tJ)[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 Bf="http://purl.obolibrary.org/obo/",nJ="https://purl.obolibrary.org/obo/",nr="http://www.geneontology.org/formats/oboInOwl#";function Du(t){const e=[Bf,nJ].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 Pa=new Set(["EXACT","BROAD","NARROW","RELATED"]);function iJ(t){const e=t.startsWith(nr)?t.slice(nr.length):t,n=/^has(Exact|Broad|Narrow|Related)Synonym$/.exec(e);return n===null?null:n[1].toUpperCase()}const uc=new Map([[`${nr}hasOBONamespace`,"namespace"],[`${nr}hasAlternativeId`,"alt_id"],[`${nr}created_by`,"created_by"],[`${nr}creation_date`,"creation_date"],[`${Bf}IAO_0100001`,"replaced_by"],[`${nr}consider`,"consider"],[`${nr}shorthand`,"shorthand"]]),rJ=new Set([w.DTYPE,w.LIST,w.JSON,w.COMPONENTS,w.GRAPH_ATTRIBUTES]),sJ=new Set(["label","kind"]),oJ=Object.freeze({label:"name"}),lJ=Object.freeze({kind:"relation"}),xa=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen","position","color","size","shape","thickness"]),aJ=new Set(["Term","Instance","Typedef"]);function Se(t,e){if(!t.isSet(e))return;const n=t.value(e);return ArrayBuffer.isView(n)?Array.from(n):n}function nl(t,e){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return Co(t,e==="f32"||e==="i32"||e==="u32"||e==="u8"?e:"f64");default:return JSON.stringify(t)??"null"}}function yD(t,e){switch(t){case"list":case"bool":case"json":return e.dtype===t;default:return ku(e)}}function bD(t){return t===void 0?[]:Array.isArray(t)?t:[t]}function ra(t,e,n){const i=t.byRole(e);if(i!==null)return{column:ku(i)?i:null,assumed:!1};const r=t.get(n);return r!==null&&r.meta.role===null&&ku(r)?{column:r,assumed:!0}:{column:null,assumed:!1}}function ku(t){return t.dtype==="string"||t.dtype==="dict"}function cJ(t){const e=t.nodes.get(lo);return e!==null&&e.dtype==="bool"?e:null}function ED(t,e,n){const i=new Uint8Array(t.nodeCount),r=cJ(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 wD(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 qb(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 _D(t,e,n){const{label:i,note:r}=n;let s=null;const o=t.edges.byRole("kind"),l={roles:sJ,nodeRoleNames:i===null?{}:oJ,edgeRoleNames:o!==null&&ku(o)?lJ:{}};for(const a of Un(t,n.caps,e,l))rJ.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 dJ(t,n),s}function dJ(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(Ja,`node column "name" is written as each node's name and reads back as the label`,"name",n.length-n.nullCount)}function SD(t,e,n,i,r){const s=[["node",t.nodes,o=>e.some(l=>o.isSet(l))||o.meta.name===lo&&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&&(xa.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 Jb(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(oy,`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 uJ=2e8;class Hf{#e={node:0,edge:0};constructor(e=uJ){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 fJ=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",""]]),hm=[{selector:":parent",style:{shape:"rectangle","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)"}}],OD=16,Re=t=>({property:t,type:"text"}),eO=t=>({property:t,type:"color"}),hJ=[["background-image",Re("_bgImage")],["background-fit",Re("_bgFit")],["background-width",Re("_bgWidth")],["background-height",Re("_bgHeight")],["background-width-relative-to",Re("_bgWidthRel")],["background-height-relative-to",Re("_bgHeightRel")],["background-position-x",Re("_bgPosX")],["background-position-y",Re("_bgPosY")],["background-offset-x",Re("_bgOffX")],["background-offset-y",Re("_bgOffY")],["background-repeat",Re("_bgRepeat")],["background-clip",Re("_bgClip")],["background-image-smoothing",Re("_bgSmooth")],["background-image-opacity",Re("_bgOpacity")],["pie-size",Re("_pieSize")],["pie-hole",Re("_pieHole")],["pie-start-angle",Re("_pieStart")],["stripe-size",Re("_stripeSize")],["stripe-direction",Re("_stripeDir")],...Array.from({length:OD},(t,e)=>[[`pie-${String(e+1)}-background-color`,eO(`_pieC${String(e+1)}`)],[`pie-${String(e+1)}-background-size`,Re(`_pieS${String(e+1)}`)],[`pie-${String(e+1)}-background-opacity`,Re(`_pieO${String(e+1)}`)],[`stripe-${String(e+1)}-background-color`,eO(`_stripeC${String(e+1)}`)],[`stripe-${String(e+1)}-background-size`,Re(`_stripeS${String(e+1)}`)],[`stripe-${String(e+1)}-background-opacity`,Re(`_stripeO${String(e+1)}`)]]).flat()];function fc(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 il=t=>Math.round(t*1e6)/1e6;function Ma(t,e){const n=fc(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:il(i)}function pJ(t){const e=Number.parseFloat(t??"");return!Number.isFinite(e)||e<=0?0:(t??"").trim().endsWith("%")?e/100:e}function Ua(t){const e=fc(t);return e===null?null:e[1]==="%"?il(e[0]/100):e[1]===""?il(e[0]):null}function gJ(t){const e=(t??"").trim().split(/\s+/)[0]??"",n=/^url\((['"]?)(.*)\1\)$/.exec(e)?.[2]??e;return n===""||n==="none"?null:n}function mJ(t){const e=fc(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 il((n%360+360)%360)}function tO(t,e,n){const i=[],r=[],s=[];for(let o=1;o<=OD;o++){const l=fc(t.get(`${e}S${String(o)}`)?.[n]),a=l!==null&&(l[1]==="%"||l[1]==="")?il(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 yJ(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};bJ(o);const l=tO(e,"_pie",s);l!==null&&SJ(o,l);const a=tO(e,"_stripe",s);a!==null&&OJ(o,a)}}function bJ(t){const e=gJ(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"),EJ(t),wJ(t),_J(t)}function EJ(t){const e=pJ(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:Ma(t.word("_bgWidth"),n(t.word("_bgWidthRel"),t.w)),s=i?null:Ma(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 wJ(t){const e=Ua(t.word("_bgPosX")),n=Ua(t.word("_bgPosY"));e!==null&&e>=0&&t.put("imagePositionX",e),n!==null&&n>=0&&t.put("imagePositionY",n);const i=Ma(t.word("_bgOffX"),t.w),r=Ma(t.word("_bgOffY"),t.h);i!==null&&t.put("imageOffsetX",i),r!==null&&t.put("imageOffsetY",r)}function _J(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 SJ(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=fc(n)?.[1]==="px"?Ma(n,null):null,r=i===null?Ua(n):i/Math.min(t.w,t.h);r!==null&&t.put("pieRadius",il(r));const s=Ua(t.word("_pieHole"));s!==null&&s>=0&&s<=1&&t.put("pieHole",s);const o=mJ(t.word("_pieStart"));o!==null&&t.put("pieRotation",o)}function OJ(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=Ua(t.word("_stripeSize"));n!==null&&n>=0&&t.put("stripeSize",n)}const pp=["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"],Kc=["tee","triangle","triangle-tee","circle-triangle","triangle-cross","triangle-backcurve","vee","square","circle","diamond","chevron","none"],NJ=["normal","bold","bolder","lighter","100","200","300","400","500","600","800","900",100,200,300,400,500,600,700,800,900],ND=["bezier","unbundled-bezier","haystack","segments","straight","straight-triangle","taxi","round-segments","round-taxi"],AJ=new Set(["haystack","straight","straight-triangle","segments","taxi","round-segments","round-taxi"]),AD=[["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"]}]],TJ=["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"],IJ=16;function $J(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(rl(e[i]))},${String(rl(-e[i+1]))}`);return n.join(" ")}function CJ(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(rl(e[i]))} ${String(rl(-e[i+1]))}`);return n.join(" ")}const rl=t=>Math.round(t*1e6)/1e6+0;function nO(){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])=>`${rl(2*(s-e)/(n-e)-1)},${rl(2*(o-i)/(r-i)-1)}`).join(" ")}const TD=new Map([["heptagon",nO()],["round-heptagon",nO()],["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"]]),vJ=new Set(["round-triangle","round-diamond","round-pentagon","round-hexagon","round-octagon"]);function ID(t){const{shape:e}=t,n=r=>typeof r=="string"&&r.startsWith("other:")?TD.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,iO(o))}),t.shapePoints=s;return}const i=n(e);i!==void 0&&(t.shape=iO(e),t.shapePoints=i)}function iO(t){return typeof t=="string"&&t.startsWith("other:round-")?"other:round-polygon":"polygon"}const DJ=new Map([["solid","none"],["linear-gradient","linear"],["radial-gradient","radial"]]);function kJ(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 $D(t,e){const n=[];for(const i of kJ(t.trim())){const r=i===""?null:$e(i,"css",e);if(r===null)return;n.push(r.color)}return n.join(" ")}function RJ(t,e){return $D(t,e)?.split(" ")??[]}function CD(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=>x(n)).join(" "):void 0}const LJ=new Set(["fanSpacing","outerBorderOffset"]),Zb=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:pp}],["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:pp}],["overlay-corner-radius",{property:"overlayCornerRadius",type:"size"}],["shape",{property:"shape",type:"enum",enums:pp}],["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"}],["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:TJ}],...hJ,...AD]),Qb=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:Kc}],["source-arrow-shape",{property:"sourceArrow",type:"enum",enums:Kc}],["target-arrow-color",{property:"targetArrowColor",type:"color"}],["source-arrow-color",{property:"sourceArrowColor",type:"color"}],["mid-target-arrow-shape",{property:"midTargetArrow",type:"enum",enums:Kc}],["mid-source-arrow-shape",{property:"midSourceArrow",type:"enum",enums:Kc}],["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:ND}],["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"}],["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"}],...AD]);function Yf(t){return t==="node"?Zb:Qb}const PJ=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 vD(t){return PJ.get(t)??t}function e0(t){return vD(t.replaceAll(/[A-Z]/g,e=>`-${e.toLowerCase()}`))}const pr="throws",st=String.raw`[-+]?(?:(?:\d+|\d*\.\d+)(?:[Ee][+-]?\d+)?)`,xJ=new RegExp(`^(${st})(px|em)?$`),rO=new RegExp(String.raw`^\s*${st}\s*$`),MJ=new RegExp(String.raw`^rgb[a]?\((${st}[%]?)\s*,\s*(${st}[%]?)\s*,\s*(${st}[%]?)(?:\s*,\s*(${st}))?\)$`),UJ=new RegExp(String.raw`^hsl[a]?\((${st})\s*,\s*(${st}[%])\s*,\s*(${st}[%])(?:\s*,\s*(${st}))?\)$`),sO=new RegExp(String.raw`^(?:${st}|\w+|rgb[a]?\((?:${st}[%]?)\s*,\s*(?:${st}[%]?)\s*,\s*(?:${st}[%]?)(?:\s*,\s*(?:${st}))?\)`+String.raw`|hsl[a]?\((?:${st})\s*,\s*(?:${st}[%])\s*,\s*(?:${st}[%])(?:\s*,\s*(?:${st}))?\)`+String.raw`|\#[0-9a-fA-F]{3}|\#[0-9a-fA-F]{6})$`),GJ=/^[\w.]+$/,jJ=/^[\w\- "]$/;function FJ(t){return t==="transparent"?"#000000":t==="rebeccapurple"?void 0:wl.get(t)}function zJ(t){const e=FJ(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=MJ.exec(t);return n===null?BJ(t):WJ(n)}function WJ(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 BJ(t){const e=UJ.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 DD(t){const e=t.split(",");return e.length===1?e[0].length>0&&Kf(e[0],Vf):HJ(e[0])&&YJ(e.at(-1)??"")&&e.slice(1,-1).every(n=>VJ(n))}function Vf(t){return jJ.test(t)}function Ru(t){return/\s/.test(t)}function Kf(t,e){return Array.from(t).every(e)}function HJ(t){let e=0;for(;e<t.length&&Vf(t[e]);)e++;return e>0&&Kf(t.slice(e),Ru)}function YJ(t){let e=t.length;for(;e>0&&Vf(t[e-1]);)e--;return e<t.length&&Kf(t.slice(0,e),Ru)}function VJ(t){let e=0,n=t.length;for(;e<n&&Ru(t[e]);)e++;for(;n>e&&Ru(t[n-1]);)n--;return e===n?t.includes(" "):Kf(t.slice(e,n),Vf)}function Ps(t,e,n=!1){const i=typeof e=="string"?e.trim():e;switch(t.type){case"color":return KJ(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 XJ(t,i,e);case"text":return{kind:"word",value:String(i),str:String(i)};case"fontFamily":{const r=String(i);return DD(r)?{kind:"word",value:r,str:r}:null}case"fontWeight":case"enum":{const s=(t.type==="fontWeight"?NJ: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 KJ(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 pr;const e=zJ(t);return e===null?null:{kind:"color",rgb:e,str:`rgb(${e[0]},${e[1]},${e[2]})`}}function XJ(t,e,n){let i="px",r=e;if(typeof e=="string"){const o=xJ.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 qJ(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 kD(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 t0(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=JJ(t,i,n);if(r!==void 0)return r}return Ps(t,e)}function JJ(t,e,n){if(e.startsWith("d")){const i=kD(e,"data")?.trim();return i===void 0||!GJ.test(i)?void 0:n==="bypass"?null:{kind:"data",field:i}}if(!(!e.startsWith("m")||e.length<10))return ZJ(t,e,n)}function ZJ(t,e,n){const i=kD(e,"mapData");if(i===null)return;const r=qJ(i);if(!QJ(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=Ps(t,r[3].trim()),l=Ps(t,r[4].trim());if(o===null||l===null||o===pr||l===pr)return null;if(o.str===l.str||o.kind==="number"&&l.kind==="number"&&oO(o)===oO(l)){const a=Ps(t,o.str);return a===pr?null:a}return{kind:"mapData",field:r[0].trim(),fieldMin:Number.parseFloat(r[1]),fieldMax:Number.parseFloat(r[2]),min:o,max:l}}function QJ(t){return t.length===5&&/^[\w.]+\s*$/.test(t[0])&&rO.test(t[1])&&rO.test(t[2])&&sO.test(t[3].trim())&&sO.test(t[4].replace(/^\s+/,""))}function oO(t){return t.value}function eZ(t,e){let n=t;for(const i of e.split(".")){if(!n)break;n=n[i]}return n}function tZ(t,e,n){const i=eZ(n,e.field);if(i==null)return null;if(e.kind==="data")return Ps(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"?Ps(t,o.value+(l.value-o.value)*s):null}function nZ(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 Ga(t,e,n){switch(e.kind){case"color":return nZ(e,n);case"number":return x((LJ.has(t.property)?e.value/2:e.value)*(e.units==="em"?IJ: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 DJ.get(String(i))??void 0;case"gradientColors":return $D(String(i),n);case"gradientStops":return CD(String(i));case"labelItalic":return i==="italic"||i==="oblique";case"curved":return!AJ.has(String(i));case"shapePoints":return $J(String(i))??void 0;case"underlayShape":case"overlayShape":return oe("shape",String(i),"cytoscape-js",n)??void 0;case"shape":{const r=String(i).toLowerCase();return r==="polygon"?"polygon":TD.has(r)||vJ.has(r)?`other:${r}`:oe("shape",String(i),"cytoscape-js",n)??void 0}case"borderStyle":return oe("borderStyle",String(i),"cytoscape-js",n)??void 0;case"outerBorderStyle":return i==="double"?"solid":oe("borderStyle",String(i),"cytoscape-js",n)??void 0;case"lineStyle":return oe("lineStyle",String(i),"cytoscape-js",n)??void 0;case"sourceArrow":case"targetArrow":case"midSourceArrow":case"midTargetArrow":return oe("arrow",String(i),"cytoscape-js",n)??void 0;case"labelWeight":return oe("weight",String(i),"cytoscape-js",n)??void 0;default:return i}}function iZ(t,e,n,i){const r=Yf(t).get(e0(e));if(r===void 0||typeof n!="string")return null;const s=Ps(r,n,!0);return s===null||s===pr?null:Ga(r,s,i)}function rZ(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 Ao(t){const e=t.trim().split(/\s+/).map(n=>Number.parseFloat(n));return e.every(n=>Number.isFinite(n))?e:[]}function lO(t){const e=t.trim(),n=Number.parseFloat(e);return e.endsWith("deg")?n*Math.PI/180:n}function sl(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(aO(r,o),aO(s,l));return[n+r*a,i+s*a]}function aO(t,e){return t===0?1/0:e/Math.abs(t)}function cO(t,e,n){const i=sl(e,n.center),r=sl(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 dO(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 sZ(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=uO(f,i?(a+d)/2:0),g=uO(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:I,sgn:T,forced:D}=oZ(t,m,b,_),P=t.taxiTurnMinDistance??10,k=Oe=>Math.abs(Oe)<P||Math.abs(Oe)>=Math.abs(I);if((k(S)||k(Math.abs(I)-Math.abs(S)))&&!D)return aZ(y,{x1:r,y1:s,x2:o,y2:l,pl:_,pdx:f,pdy:h},e.size,n.size);const Y=i?(y?c:a)/2*T:0;if(y){const Oe=s+S+Y;return[[r,Oe],[o,Oe]]}const me=r+S+Y;return[[me,s],[me,l]]}function uO(t,e){return t>0?Math.max(t-e,0):Math.min(t+e,0)}function oZ(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))&&lZ(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 lZ(t,e){return t==="downward"&&e<0||t==="upward"&&e>0||t==="leftward"&&e>0||t==="rightward"&&e<0}function aZ(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 RD(t,e,n){const i=sl(t,n[0]),r=sl(e,n.at(-1)??e.center);return j1([i,...n,r],0).slice(1,-1)}function cZ(t,e,n,i){const r=t.curveStyle;if(r==="haystack")return null;if(e===n)return uZ(t,e,i);let s=[];if(r.endsWith("segments")){const o=Ao(t.segmentDistances??"20"),l=Ao(t.segmentWeights??"0.5");s=dO(cO(t,e,n),l,o)}else if(r.endsWith("taxi"))s=sZ(t,e,n);else if(r==="unbundled-bezier"){const o=Ao(t.controlPointDistances??String(t.controlPointStepSize??40)),l=Ao(t.controlPointWeights??"0.5"),a=dO(cO(t,e,n),l,o);s=a.length===0?[]:RD(e,n,a)}if(s.length>0&&r.startsWith("round-")){const o=Ao((r==="round-taxi"?t.taxiRadius:t.segmentRadii)??"15"),l=(t.radiusType??"arc-radius").trim().split(/\s+/),a=sl(e,s[0]),c=sl(n,s.at(-1)??n.center);s=dZ([a,...s,c],o,l).slice(1,-1)}return s.length===0?null:Ol(e.center,n.center,s,!0)}const fO=8;function dZ(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]],I=Math.hypot(S[0],S[1]),T=Math.hypot(b,_),D=[s[0]+S[0]/I*T,s[1]+S[1]/I*T],P=Math.atan2(s[1]+f[1]*b-D[1],s[0]+f[0]*b-D[0]);let U=Math.atan2(s[1]+h[1]*b-D[1],s[0]+h[0]*b-D[0])-P;U-=2*Math.PI*Math.round(U/(2*Math.PI));for(let Y=0;Y<=fO;Y++){const me=P+U*Y/fO;i.push([D[0]+Math.cos(me)*_,D[1]+Math.sin(me)*_])}}return i.push(t.at(-1)??t[0]),i}function uZ(t,e,n){const r=t.curveStyle==="unbundled-bezier"?Ao(t.controlPointDistances??"").at(0)??Number.NaN:t.controlPointStepSize??40,s=lO(t.loopDirection??"-45deg"),o=lO(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=RD(e,e,[u(l-o/2),u(l+o/2)]);return zs(e.center,e.box,f,!0)}const fZ=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"]),hZ=1<<22,LD=new Set("!\"#$%&'()*+,./:;<=>?@[]^`{|}~"),pZ=["!=",">=","<=","*=","^=","$=","=",">","<"],gZ=["indegree","outdegree","degree"];function mZ(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 yZ(t){return t!==void 0&&/\s/.test(t)}class bZ{constructor(e){this.text=e,this.pos=0}spaceEnd(e){let n=e;for(;n<this.text.length&&yZ(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(mZ(s)||s==="-"||n&&s===".")i++;else if(s==="\\"&&i+1<r.length&&LD.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 pZ)if(n.startsWith(s,i))return r.includes("!")&&s==="!="?null:{text:r+s,end:i+s.length};return null}}function n0(t){let e="",n=0;for(;n<t.length;){const i=t[n]==="\\"&&n+1<t.length&&LD.has(t[n+1]);e+=i?t[n+1]:t[n],n+=i?2:1}return e}function PD(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 sa(t,e){t.queries[t.queries.length-1]=e}function pm(t){return t.queries.at(-1)}function hO(t){return(e,n)=>{if(e.subject===null){const s={checks:[]},o={checks:[]},l=pm(e);return s.checks.push(t==="child"?{type:"child",parent:l,child:o}:{type:"descendant",ancestor:l,descendant:o}),sa(e,s),e.compoundCount++,o}if(e.subject===n){const s={checks:[]},o=pm(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}),sa(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 EZ(t){const e=t.text[t.pos];return wZ(t)??(e===":"?_Z(t):null)??(e==="#"||e==="."?SZ(t,e):null)??(e==="["?IZ(t,t.pos):null)??OZ(t)??(e==="$"?AZ(t):null)}function qs(t,e){return{end:t,fill:(n,i)=>(i.checks.push(e),null)}}function wZ(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 _Z(t){const e=t.pos;let n=null;for(const i of fZ)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 SZ(t,e){const n=t.name(t.pos+1,e==="#");return n===null?null:qs(n.end,{type:e==="#"?"id":"class",value:n0(n.raw)})}function OZ(t){const e=t.text,n=t.pos,i=t.spaceEnd(n);if(e[i]===",")return{end:t.spaceEnd(i+1),fill:NZ};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"?hO("child"):TZ(s)}}return{end:i,fill:hO("descendant")}}function NZ(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 AZ(t){return{end:t.pos+1,fill:(e,n)=>{if(e.subject!==null&&e.subject!==n)return!1;e.subject=n;const i=pm(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 TZ(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]}),sa(e,r),e.edgeCount++,i):t==="directed"?(r.checks.push({type:"nodeSource",source:n,target:i}),sa(e,r),e.edgeCount++,i):(r.checks.push({type:"nodeNeighbor",node:n,neighbor:i}),sa(e,r),i)}}function IZ(t,e){const n=t.spaceEnd(e+1);return $Z(t,n)??CZ(t,n)??(t.text[e+1]==="["?vZ(t,e):null)}function $Z(t,e){const n=t.text,i=t.name(e,!0);if(i===null)return null;const r=n0(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}=PD(o.text);return qs(t.spaceEnd(c)+1,{type:"compare",field:r,op:f,not:h,ci:p,value:u})}function CZ(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:n0(r.raw),op:i})}function vZ(t,e){const n=t.text,i=t.spaceEnd(e+2),r=gZ.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}=PD(s.text);return qs(t.spaceEnd(l)+2,{type:"meta",field:r,op:c,not:d,ci:u,value:a})}function DZ(t){return/^\s*$/.test(t.length>1024?t.slice(0,1024):t)&&t.trim()===""}function Lu(t){if(typeof t!="string"||DZ(t))return{queries:[],invalid:!1};if(t.length>hZ)return{queries:[],invalid:!0};const e=new bZ(t),n={checks:[]},i={queries:[n],subject:null,edgeCount:0,compoundCount:0,counts:[]};let r=n;for(e.pos=e.spaceEnd(0);;){const o=EZ(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 gp=/[\n\r\u2028\u2029]/,i0=/\s/;function kZ(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 pO(t,e){let n=e;for(;n<t.length&&i0.test(t[n]);)n++;return n}function xD(t){let e=t.length;for(;e>0&&i0.test(t[e-1]);)e--;return t.slice(0,e)}function RZ(t,e,n){const i=t.length,r=n[e],s=t.indexOf(":",r+1);if(s<0)return null;const o=xD(t.slice(r,s));if(o===""||gp.test(o))return null;const l=n[s+1];for(let a=l+1;a<=i&&!gp.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(!gp.test(t[a]))return{name:o,value:t[a],end:i}}return null}function LZ(t){const e=new Int32Array(t.length+1);e[t.length]=t.length;for(let n=t.length-1;n>=0;n--)e[n]=i0.test(t[n])?e[n+1]:n;return e}function PZ(t){const e=kZ(t),n=[];let i=0;for(;pO(e,i)<e.length;){const r=pO(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=xD(e.slice(o,s)),c=e.slice(s+1,l);if(i=l+1,a!=="core"&&Lu(a).invalid)continue;const d=xZ(c);if(d===null)return{entries:n,stop:"BAD_PROPERTY"};n.push({selector:a,properties:d,dashOnly:!0})}return{entries:n,stop:null}}function xZ(t){const e=[],n=LZ(t);let i=0;for(;n[i]<t.length;){const r=RZ(t,i,n);if(r===null)return null;e.push([r.name,r.value]),i=r.end}return e}function Jr(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function MZ(t){return typeof t=="number"&&!Number.isNaN(t)?String(t):typeof t=="string"&&t!==""&&!/^\s+$/.test(t)?t:null}function UZ(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 GZ(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 jZ(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 FZ(t){const{nodeJson:e,edgeJson:n}=zZ(t),i=new Map,r=BZ(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:HZ(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}=jZ(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 zZ(t){const e=[],n=[],i=(r,s)=>{const o=WZ(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(Jr(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 WZ(t,e){if(!Jr(t))return;const n=t.data??{};if(!Jr(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 BZ(t){let e=0;return(n,i,r)=>{const s=Jr(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=MZ(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:GZ(n.classes),...UZ(n,i)}}}function HZ(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 oa(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 YZ(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 VZ(t,e){if(typeof t=="string"){const{entries:i,stop:r}=PZ(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(!Jr(i))continue;const r=i.style??i.css,s=[];if(Jr(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 gm=64;function MD(t,e=0){if(e>gm)return e;let n=e;for(const i of t.checks)for(const r of KZ(i))if(n=Math.max(n,MD(r,e+1)),n>gm)return n;return n}function KZ(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 gO(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 XZ=new Set(["child","parent","descendant","ancestor","split","directedEdge","undirectedEdge","nodeSource","nodeTarget","nodeNeighbor"]),qZ=new Set(["active","inactive","grabbed","free","animated","unanimated","visible","hidden","transparent","backgrounding","nonbackgrounding"]);class UD extends Error{}const JZ=4096;class ZZ{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>=JZ&&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 UD}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 XZ.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 oa(s,e.field)!==void 0;case"bool":{const o=oa(s,e.field);return e.op==="?"?!!o:e.op==="!"?!o:o===void 0}case"compare":return gO(oa(s,e.field),e.op,e.not,e.ci,e.value);case"meta":{const o=n==="node"?this[e.field][i]:void 0;return gO(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;qZ.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 QZ{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=oa(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 eQ(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 mO=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"]]),tQ=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 r0(t){const e=t.notes??new re,n=t.budget??new Hf,i=FZ(t.elements),r=[];t.toolDefaults!==!1&&hm.forEach((u,f)=>{r.push({index:f-hm.length,tool:!0,text:u.selector,selector:Lu(u.selector),properties:Object.entries(u.style),dashOnly:!0})});const s=VZ(t.style,e);let o=0,l=0;s.forEach((u,f)=>{let h=Lu(u.selector);h.invalid&&o++,h.queries.some(p=>MD(p)>gm)&&(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 ZZ(i,e),c=yO("node",i,r,a,t,{notes:e,budget:n,nodes:null}),d=yO("edge",i,r,a,t,{notes:e,budget:n,nodes:c});return{node:c,edge:d,graph:i}}function GD(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=nQ(n,r[d].id);u>=0&&c[u]<0&&(c[u]=d)}return c}const s=new Int32Array(n.edgeCount).fill(-1),o=GD("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 nQ(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 jD(t,e,n){let i=t.get(e);return i===void 0&&(i=new Array(n),t.set(e,i)),i}function yO(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}=iQ(t,a,n,i,r,o,l),f=GD(t,e,r.snapshot,o),h=new Int32Array(a.length).fill(-1);f.forEach((m,y)=>{m>=0&&(h[m]=y)}),sQ(t,a,d,h,o),t==="edge"&&uQ(e,d.get("curve-style"));const p=oQ(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=Nn(m,"curve-style",KQ);XQ(y,p),s.nodes!==null&&PQ(e,m,y,s.nodes,p)}if(t==="node"){const m={kind:t,els:a,cells:d,order:f,rendered:r.rendered,notes:o};WQ(e,m,p),YQ(e,m,p)}t==="edge"&&cQ(e,aQ(e,d,r.rendered),h,p.curved);const g=QQ(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 iQ(t,e,n,i,r,s,o){const l=e.length,a=Yf(t),c=g=>{o.spend(t,g)},d=new QZ(e,c),u=new Map,f=new Map,h=[];let p=!1;for(const g of n){r.signal?.throwIfAborted();const m=fQ(g,t,a,s,f);if(m.length===0)continue;const y=o.exhausted(t)?null:rQ(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 _=jD(u,b.name,l);for(const S of y)_[S]=FD(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 rQ(t,e,n,i,r,s){n.begin(e.kind,s,r.signal);try{return pQ(t,e.kind,e.n,n,i)}catch(o){if(!(o instanceof UD))throw o;return null}finally{n.end()}}function sQ(t,e,n,i,r){const s=Yf(t);for(let o=0;o<e.length;o++){const{json:l}=e[o],a=l.style??l.css;if(Jr(a))for(const c of Object.keys(a)){const d=e0(c),u=s.get(d),f=a[c];if(u===void 0||f===""||f===null)continue;const h=t0(u,f,"bypass");if(h===null||h===pr||!s0(h)){r.add(v.BAD_VALUE,t,u.property,{sample:f,element:i[o]});continue}jD(n,d,e.length)[o]=h}}}function oQ(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 Yf(t)){if(!n.has(f)&&r===void 0)continue;const p=Nn(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)})}mQ(t,l,c,a,s),t==="node"&&ID(a);const u={};for(const[f,h]of Object.entries(a))h.some(p=>p!==null)&&(u[f]=h);return u}function Nn(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]=zD(n,e,u,{notes:s,target:i,property:n.property,element:d}))}return o!==void 0&&lQ(t,o,e,n,a),a}function lQ(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=iZ(s,n,c[n],d);r[a]=u===void 0||u===""&&i.type==="text"?null:u}}}function aQ(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 cQ(t,e,n,i){if(i!==void 0)for(const r of dQ(t,e)){const s=r.length%2===1?n[r[(r.length-1)/2]]:-1;s>=0&&(i[s]=!1)}}function dQ(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 uQ(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 fQ(t,e,n,i,r){const s=[];for(const[o,l]of t.properties){const a=t.dashOnly?vD(o):e0(o),c=n.get(a);if(c===void 0){e==="node"&&!hQ.has(a)&&!t.tool&&r.set(a,(r.get(a)??0)+1);continue}const d=t0(c,l,"rule");if(d===null||d===pr){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 hQ=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"]);function pQ(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=eQ(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 FD(t,e){const n=t.parsed;return n.kind==="data"||n.kind==="mapData"?tZ(t.spec,n,YZ(e))??"reset":n.kind==="fn"?"fn":n}const mp=new Map;function gQ(t,e){const n=`${e.type}|${t}`;if(!mp.has(n)){const i=fJ.get(t),r=i===void 0?null:t0(e,i,"flat");mp.set(n,r===null||r===pr||!s0(r)?null:r)}return mp.get(n)??null}function s0(t){return t.kind==="color"||t.kind==="number"||t.kind==="word"}function zD(t,e,n,i){if(n===pr){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"?gQ(e,t):n;return r===null?null:Ga(t,r,i)}function mQ(t,e,n,i,r){const s=[...i.opacity??new Array(e).fill(null)];yQ(e,n,i),t==="node"&&bQ(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)=>ZQ(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"?(yJ(e,n,i),RQ(e,n,i,r)):(JQ(e,n,i,r),DQ(e,n.get("_lineOpacity"),i)),EQ(t,e,n,i),OQ(t,e,n,i),TQ(t,e,n,i,r,s),SQ(t,e,n,i)}function yQ(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 bQ(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 EQ(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&&wQ(d,e,i[o],{fallback:l,pattern:a},c?n:null)}}function wQ(t,e,n,i,r){for(let s=0;s<e;s++){if(t[s]!=="dashed")continue;const o=n?.[s],l=_Q(r,s,i.pattern,typeof o=="number"?o:i.fallback);l!==null&&(t[s]=l)}}function _Q(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:rZ(r,i,t?.get("_dashCap")?.[e]??"butt")}function ol(t,e,n){let i=t[e];return i===void 0&&(i=new Array(n).fill(null),t[e]=i),i}function SQ(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"])ol(i,u,e)[l]=0;ol(i,"label",e)[l]=""}}i.visible=o}function OQ(t,e,n,i){NQ(e,n.get("_transform"),i.label);const r=n.get("_justification");if(r!==void 0&&t==="edge")AQ(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:vQ(c)))}}function NQ(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 AQ(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&&(ol(i,"labelShiftX",t)[s]=o)}}function TQ(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&&$Q(t,h,n,l,r,u(s[h]));(y||b)&&IQ(t,h,n,l,r)}}function IQ(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 $Q(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 CQ(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 vQ(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 DQ(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 kQ=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 RQ(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=RJ(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=CD(o?.[c]??"");f?.split(" ").length===u.length&&(a("fillGradientStops")[c]=f),d?a("fillGradientKind")[c]="radial":a("fillGradientAngle")[c]=kQ.get(l?.[c]??"to-bottom")??90}}const LQ=[["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 PQ(t,e,n,i,r){const s=new Map(LQ.map(([h,p,g])=>[h,Nn(e,p,g)])),o=new Map;i.elements.forEach((h,p)=>{h!==null&&o.set(h,p)});const l=h=>xQ(t.nodes[h],o,i),a=[["labelRotation",Nn(e,"text-rotation",Es)],["sourceLabelRotation",Nn(e,"source-text-rotation",Es)],["targetLabelRotation",Nn(e,"target-text-rotation",Es)]],c=[Nn(e,"source-endpoint",Es),Nn(e,"target-endpoint",Es)],d=new Map,u=e.order.length;let f=null;for(let h=0;h<u;h++){const p=e.order[h],g=MQ(t,p,l);if(g===null)continue;const{src:m,tgt:y,loop:b}=g;b||UQ(r,a,h,u,CQ(m.center,y.center));const _=zQ(s,h,n[h]),S=cZ(_,m,y,b?GQ(d,t.source[p],_):0);S!==null&&(f??=r.bends??new Array(u).fill(null),f[h]=S,ol(r,"curved",u)[h]=!1),b||jQ(_.curveStyle,[c[0][h],c[1][h]],[m,y],(I,T)=>{ol(r,I,u)[h]=T})}f!==null&&(r.bends=f)}function xQ(t,e,n){const i=e.get(t),r=t.json.position;if(i===void 0||!Jr(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 MQ(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 UQ(t,e,n,i,r){for(const[s,o]of e)o[n]==="autorotate"&&(ol(t,s,i)[n]=r)}function GQ(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 jQ(t,e,n,i){t==="taxi"||t==="round-taxi"||["sourcePort","targetPort"].forEach((r,s)=>{const o=t==="haystack"?"0,0":FQ(String(e[s]??""),n[s]);o!==null&&i(r,o)})}function FQ(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 zQ(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 Es={property:"_text",type:"text"};function WQ(t,e,n){const i=Nn(e,"padding",Es),r=["width","height"].map(l=>Nn(e,l,VQ)),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:WD(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 BQ={property:"_valign",type:"enum",enums:["top","top-inside","center","bottom","bottom-inside"]},HQ={property:"_halign",type:"enum",enums:["left","left-inside","center","right","right-inside"]};function bO(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 YQ(t,e,n){const i=Nn(e,"text-valign",BQ),r=Nn(e,"text-halign",HQ),s=Nn(e,"padding",Es),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:WD(s[a]),g=_=>{const S=n[_]?.[a];return typeof S=="number"?S:30+2*p},m=bO(d,g("width")/2,p),y=bO(c,g("height")/2,p),b=(_,S)=>{const I=n[_]?.[a];l(_)[a]=(typeof I=="number"?I: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 VQ={property:"_size",type:"nodeSize"};function WD(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 KQ={property:"_curve",type:"enum",enums:ND};function XQ(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 BD=new Map([["triangle","triangle-open"],["diamond","diamond-open"],["circle","circle-open"],["square","other:open-square"]]);function qQ(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=BD.get(r);s!==void 0&&n.parsed.value==="hollow"&&(t[i]=s)}}function JQ(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=BD.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 ZQ(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)?tQ.get(`${r},${s}`)??null:mO.get(`${n?"center":r},${i?"center":s}`)??null:mO.get(`${r},${s}`)??null}function QQ(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(eee(g,b.entry,b.list,_,b.props))}return{rules:pee(g,m),columns:h,rawColumns:[...p]}}function eee(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+hm.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=tee(t,e,n,h.spec.property);g!==null&&(o.set(h.spec.property,g),l=!0)}else if(s0(p)){const g=Ga(h.spec,p,{notes:new re,target:t.kind,property:h.spec.property});g!==void 0&&s.set(h.spec.property,g)}else o.set(h.spec.property,uee(t,e,n,h))}const c=Object.fromEntries(s);t.kind==="node"?ID(c):qQ(c,r);const d=Object.fromEntries(o),u=o.size>0;return{rule:()=>{const h=see(t,e,n);return{id:a,target:t.kind,role:nee(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:iee(e.selector,t.kind),list:n}}function tee(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 nee(t,e){return t?"mapping":"all"in e?"defaults":"group"}function iee(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 Pd(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=oa(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 ree(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=ic(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 see(t,e,n){const i=oee(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 oee(t,e){if(e.invalid)return null;const n=[];for(const i of e.queries){const r=lee(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 aee(n)}function lee(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 aee(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||!Pd(t,e.field)?null:e.not?{not:{eq:[{data:e.field},e.value]}}:{eq:[{data:e.field},e.value]};case"exist":return Pd(t,e.field)?{has:{data:e.field}}:null;case"bool":return e.op==="^"&&Pd(t,e.field)?{not:{has:{data:e.field}}}:null;case"meta":return e.ci||!ree(t,e.field)?null:dee(e.field,e.op,e.not,e.value);default:return null}}function dee(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 uee(t,e,n,i){const r=i.parsed,s=new Array(n.length),o={notes:new re,target:t.kind,property:i.spec.property};for(let d=0;d<n.length;d++){const u=FD(i,t.els[n[d]]),f=zD(i.spec,i.name,u,o);s[d]=f??null}t.spend(n.length*2);const l=hee(t,r,i);if(l!==null&&t.snapshot!==void 0){const d=fee(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 fee(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=El(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):yf(n.points,rc(d))),c>=0&&u!==s[a])return!1}return!0}function hee(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 re,target:t.kind,property:n.spec.property},r=Ga(n.spec,e.min,i),s=Ga(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 pee(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(gee(t,e.slice(r,o),s,i));r=o}return n}function gee(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]=mee(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 mee(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&&Pd(t,a)&&yee(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 yee(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 bee(t){const e=t.notes??new re,n=r0({...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 $o="graphty_import";function EO(t){return`graphty_style_${t.replaceAll(/\W/g,"_")}`}const HD=/^[A-Za-z_]\w*$/,Eee=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"]]),wee=new Map([["none","none"],["triangle","triangle"],["vee","vee"],["tee","tee"],["diamond","diamond"],["circle","circle"],["square","square"]]),_ee=new Map([["none","solid"],["linear","linear-gradient"],["radial","radial-gradient"]]),See={sourceArrow:"source-arrow-shape",targetArrow:"target-arrow-shape",midSourceArrow:"mid-source-arrow-shape",midTargetArrow:"mid-target-arrow-shape"},Oee=new Map([["triangle-open","triangle"],["diamond-open","diamond"],["circle-open","circle"]]),Nee=new Map([["half","triangle"],["inverted","triangle"],["crow","vee"]]);function o0(t,e,n){const i=t==="node"?Zb:Qb;switch(e){case"visible":return ve({display:n===!1?"none":"element"});case"shapePoints":return Iee(String(n));case"labelItalic":return ve({"font-style":n===!0?"italic":"normal"});case"curved":return ve({"curve-style":n===!0?"unbundled-bezier":"straight"});case"labelPosition":return Cee(String(n));case"fanSpacing":case"labelWrapWidth":return Gl(n,r=>$ee(e,r));case"gradientKind":return Aee(String(n));case"gradientStops":return ve({"line-gradient-stop-positions":String(n).trim().split(/\s+/).map(r=>`${x(Number(r)*100)}%`).join(" ")});case"outerBorderOffset":return Gl(n,r=>ve({"outline-offset":x(r*2)}));case"outerBorderStyle":return Tee(String(n));case"shape":return YD("shape",String(n),Eee,i);case"borderStyle":return VD(String(n));case"lineStyle":return Dee(String(n));case"sourceArrow":case"targetArrow":case"midSourceArrow":case"midTargetArrow":return vee(See[e],String(n),i);case"labelFont":return DD(String(n))?ve({"font-family":String(n)}):null;case"labelBackground":return ve({"text-background-color":String(n),"text-background-opacity":1});case"labelOutlineColor":return ve({"text-outline-color":String(n)});case"labelOutlineWidth":return Gl(n,r=>ve({"text-outline-width":x(r/2)}));case"labelPadding":return Gl(n,r=>ve({"text-background-padding":r}));case"labelBorderColor":return ve({"text-border-color":String(n),"text-border-opacity":1});case"labelBorderWidth":return Gl(n,r=>ve({"text-border-width":r,"text-border-opacity":1}));default:return kee(e,n,i)}}function Gl(t,e){return typeof t=="number"?e(t):null}function Aee(t){const e=_ee.get(t);return e===void 0?null:ve({"line-fill":e})}function Tee(t){const e=VD(t);return e===null?null:{...e,props:{"outline-style":e.props["border-style"]}}}function Iee(t){const e=CJ(t);return e===null?null:ve({"shape-polygon-points":e})}function $ee(t,e){return ve(t==="fanSpacing"?{"control-point-step-size":x(e*2)}:{"text-wrap":"wrap","text-max-width":e})}function ve(t){return{props:t,approximate:!1}}function l0(t){return{props:t,approximate:!0}}function Cee(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 ve({"text-valign":s(i),"text-halign":s(r)})}function YD(t,e,n,i){const r=n.get(e);if(r!==void 0)return ve({[t]:r});const s=e.startsWith("other:")?e.slice(6):null;return s!==null&&i.get(t)?.enums?.includes(s)===!0?ve({[t]:s}):null}function vee(t,e,n){const i=t.replace("-shape","-fill"),r=Oee.get(e);if(r!==void 0)return ve({[t]:r,[i]:"hollow"});const s=YD(t,e,wee,n),o=Nee.get(e),l=s??(o===void 0?null:l0({[t]:o}));return l===null||e==="none"?l:{...l,props:{...l.props,[i]:"filled"}}}function VD(t){return t==="dash-dot"?l0({"border-style":"dashed"}):["solid","dotted","dashed","double"].includes(t)?ve({"border-style":t}):null}function Dee(t){return["solid","dotted","dashed"].includes(t)?ve({"line-style":t}):l0({"line-style":t==="dash-dot"||t==="long-dash"?"dashed":"solid"})}function kee(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)?ve({[r]:" "}):ve({[r]:typeof e=="boolean"?String(e):e})}function a0(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 Xf(t,e,n){const i=t.keys[e].get(n);if(i!==void 0)return{key:i,fresh:!1};let r=EO(n),s=2;for(;t.used[e].has(r);)r=`${EO(n)}_${String(s)}`,s++;return t.keys[e].set(n,r),t.used[e].add(r),{key:r,fresh:!0}}function qf(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 c0(t,e,n){if("all"in n)return n.all?[""]:null;if("has"in n){const i=ja(t,e,n.has);return i===null||!("style"in n.has)?null:[`[${i}]`]}if("eq"in n)return KD(t,e,n.eq,"=");if("in"in n){const i=ja(t,e,n.in[0]),r=n.in[1].map(s=>a0(s));return r.length===0?[]:i===null||r.includes(null)?null:r.map(s=>`[${i} = ${String(s)}]`)}return"not"in n?Ree(t,e,n.not):"and"in n?Lee(t,e,n.and):"or"in n?Pee(t,e,n.or):null}function KD(t,e,n,i){const r=ja(t,e,n[0]),s=a0(n[1]);return r===null||s===null?null:[`[${r} ${i} ${s}]`]}function Ree(t,e,n){if("has"in n&&"style"in n.has){const i=ja(t,e,n.has);return i===null?null:[`[^${i}]`]}return"eq"in n?KD(t,e,n.eq,"!="):null}function Lee(t,e,n){let i=[""];for(const r of n){const s=c0(t,e,r);if(s===null||(i=i.flatMap(o=>s.map(l=>o+l)),i.length>8))return null}return i}function Pee(t,e,n){const i=[];for(const r of n){const s=c0(t,e,r);if(s===null)return null;i.push(...s)}return i.length>8?null:i}function ja(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}=Xf(t,e,n.style);return s&&qf(t,e,r,i),r}return"data"in n&&HD.test(n.data)&&n.data!==$o&&!n.data.startsWith("graphty_")?n.data:null}function xee(t,e,n){const i=`${e.target}${t.scope}`,r=c0(t,e.target,e.where);if(r!==null)return r.map(a=>i+a);const s=Ar(e.target,t.data[e.target].length,t.extracted.columns[e.target],t.extracted.features[e.target]),{key:o}=Xf(t,e.target,`emit.where.${String(n)}`),l=new Array(s.n);for(let a=0;a<s.n;a++)l[a]=Ro(e.where,s,a)?!0:null;return qf(t,e.target,o,l),[`${i}[${o}]`]}function Mee(t,e,n){const{target:i}=e,r=xee(t,e,n),s={};for(const[o,l]of Object.entries(e.set??{})){if(l===void 0)continue;const a=Ur(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&&Gee(t,e,n,r,o,l)}function Uee(t,e,n){const i=o0(t,e,n);return i!==null&&!i.approximate}function Ur(t,e,n,i){const r=o0(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 Gee(t,e,n,i,r,s){const{target:o}=e;if(s.kind==="discrete"){const l=ja(t,o,s.by),a=s.table.map(([c])=>a0(c));if(l===null||a.includes(null)){wO(t,e,n,i,r);return}s.table.forEach(([,c],d)=>{const u=Ur(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"&&jee(o,r)){const l=Fee(t,o,s.by,n);if(l!==null){zee(t,o,i,r,l,s.points);return}}wO(t,e,n,i,r)}function jee(t,e){const n=ni[t].get(e);return n==="number"||n==="opacity"||n==="color"}function Fee(t,e,n,i){const r=Ar(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&&HD.test(n.data)&&!n.data.startsWith("graphty_"))return n.data;const{key:o}=Xf(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 qf(t,e,o,l),o}function zee(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)}]`,Ur(t,e,i,a.below));for(let d=0;d+1<s.length;d++){const u=s[d],f=s[d+1],h=Ur(t,e,i,u.above),p=Ur(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)}]`,Ur(t,e,i,c.above));for(const d of s)l(`[${r} = ${o(d.at)}]`,Ur(t,e,i,d.value))}function wO(t,e,n,i,r){const{target:s}=e,o=t.data[s].length,l=Ar(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=Si([c],s,r,l),u=new Map;for(let f=0;f<o;f++){const h=d[f];if(h===null)continue;const p=Ur(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}=Xf(t,s,`emit.value.${String(n)}.${f}`);qf(t,s,p,h);for(const g of i)t.stylesheet.push({selector:`${g}[${p}]`,style:{[f]:`data(${p})`}})}}function XD(t,e={}){const n=new re,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?"":`[${$o} = "${i}"]`,stylesheet:[],data:{node:Array.from({length:r},()=>({})),edge:Array.from({length:s},()=>({}))},keys:{node:new Map,edge:new Map},used:{node:new Set([$o,..._O(t,"node")]),edge:new Set([$o,..._O(t,"edge")])}};if(i!==void 0)for(const d of[o.data.node,o.data.edge])for(const u of d)u[$o]=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"&&Mee(o,d,u)});const a=Wee(o,l);for(const d of o.stylesheet)Lu(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 Wee(t,e){const{extracted:n}=t,i=t.data.node.length,r=[];for(let a=0;a<i;a++)r.push({group:"nodes",data:{...SO(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:{...SO(n,"edge",a),...t.data.edge[a],id:`e${String(a)}`,source:"n0",target:s}});const o=r0({elements:r,style:t.stylesheet,toolDefaults:!1}),l={node:[],edge:[]};for(const a of["node","edge"]){const c=t.data[a].length,d=Ar(a,c,n.columns[a],n.features[a]),u=new Array(c).fill(null);for(const p of ni[a].keys()){const g=Si(e,a,p,d);Vee(u,a,p,g,o[a].values[p])}const f=p=>Si(e,a,p,d);a==="node"&&Yee(u,f,o.node.values),Bee(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)Hee(u,f,o[a].values,p);l[a]=u}return l}function Bee(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":x(l/a)}:l>0&&(t[o]={...t[o],opacity:x(l),"line-opacity":x(a/l),"text-opacity":1}))}}function Hee(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]:x(h/p)})}}function Yee(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 Vee(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:o0(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 SO(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 d0=Object.freeze(["node-link","d3","jgf","cytoscape","graphology","vis","obographs"]),qD=Object.freeze([...d0,"adjacency","tree"]),u0="json";function OO(t){const e=t.meta.extra[u0];return $(e)?e:null}function $(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function z(t,e){return Object.hasOwn(t,e)}function JD(t){return typeof t=="string"&&d0.includes(t)}function Kee(t){return typeof t=="string"&&qD.includes(t)}function Fa(t){if(Array.isArray(t)){const n=mm(t);return t.length===0||n!==null&&$(n.data)?"cytoscape":null}if(!$(t))return null;const e=Xee(t)??qee(t);return e===void 0?Jee(t):e}function Xee(t){if(z(t,"elements"))return"cytoscape";if($(t.graph)&&(z(t.graph,"nodes")||z(t.graph,"edges")))return"jgf";if(Array.isArray(t.graphs))return t.graphs.some(e=>$(e)&&nte(e))?"obographs":"jgf"}function qee(t){if(!(z(t,"edges")||z(t,"links")))return z(t,"nodes")?z(t,"adjacency")?"adjacency":void 0:z(t,"children")?"tree":null}function Jee(t){const e=mm(t.nodes),n=mm(z(t,"edges")?t.edges:t.links);if($(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:ete(e,n);return r!==void 0?r:!i&&n===null&&Qee(t.options)?"vis":!z(t,"directed")&&!z(t,"multigraph")&&!z(t,"graph")&&z(t,"links")?"d3":"node-link"}const Zee=["nodes","edges","groups","physics","layout","interaction","manipulation","configure","autoResize","clickToUse","locale","locales","height","width"];function Qee(t){return $(t)&&Zee.some(e=>z(t,e))}function ete(t,e){return t!==null&&z(t,"key")&&!z(t,"id")?"graphology":e===null?t!==null&&z(t,"id")&&$(t.attributes)?"graphology":void 0:z(e,"from")?z(e,"to")&&!z(e,"source")?"vis":void 0:z(e,"undirected")||$(e.attributes)?"graphology":void 0}const tte=new Set(["CLASS","INDIVIDUAL","PROPERTY"]);function nte(t){if(t===null)return!1;const e=i=>$(i)&&(z(i,"obj")&&(z(i,"sub")||z(i,"subj"))||z(i,"pred")),n=i=>$(i)&&(z(i,"lbl")||z(i,"meta")||tte.has(i.type));return Array.isArray(t.edges)&&t.edges.some(e)||Array.isArray(t.nodes)&&t.nodes.some(n)}function mm(t){if(!Array.isArray(t))return null;const e=t.find(n=>$(n));return $(e)?e:null}function ite(t){const e=t.extra[u0];if(!$(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:JD(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:$(e.cytoscape)?e.cytoscape:void 0}}const ZD=Object.freeze({"node-link":!1,d3:!1,jgf:!0,cytoscape:!0,graphology:!0,vis:!1,adjacency:!1,tree:!0,obographs:!0}),rte=Object.freeze(["f64","i32","bool","string"]),bo={multiEdges:!0,selfLoops:!0,idCharset:"any",dtypes:rte,components:!1,lists:!1,json:!0,defaults:!1,options:!1,temporal:"none",positions:!1,viz:!1},ste=Object.freeze({"node-link":Xe({...bo,mixedDirection:!1,edgeIds:"none",hierarchy:!1,graphAttributes:!0}),d3:Xe({...bo,mixedDirection:!1,edgeIds:"none",hierarchy:!1,graphAttributes:!1}),jgf:Xe({...bo,mixedDirection:!0,edgeIds:"optional",hierarchy:!1,graphAttributes:!0}),cytoscape:Xe({...bo,positions:!0,mixedDirection:!1,edgeIds:"required",hierarchy:!0,graphAttributes:!0}),graphology:Xe({...bo,mixedDirection:!0,edgeIds:"optional",hierarchy:!1,graphAttributes:!0}),vis:Xe({...bo,mixedDirection:!1,edgeIds:"optional",hierarchy:!1,graphAttributes:!1}),obographs:Xe({mixedDirection:!1,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"any"})});function Jf(t){return ste[t]}const QD=new Set(["selected","selectable","locked","grabbable","pannable","removed","scratch","renderedPosition"]),ote=new Set(["data","group","position","classes"]),Rt=Object.freeze({data:"#data",element:"#element"}),f0=Object.freeze(["source","src","from"]),h0=Object.freeze(["target","dst","to"]),lte="position",ek="classes",ate="parent";function Zf(t){const e=/^(-?)(\d{16,})$/.exec(t);if(e===null||Number.isSafeInteger(Number(t)))return t;const[,n,i]=e,r=nT(i),s=r.length>1?`.${r.slice(1)}`:"";return`${n}${r[0]}${s}e+${i.length-1}`}const cte=.5,Gr=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 ute(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 fte(t){const e=t.indexOf(";");return(e<0?t:t.slice(0,e)).trim().toLowerCase()}function p0(t){if(typeof t=="string")return new TextEncoder().encode(t.slice(0,Gr)).subarray(0,Gr);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 p0(new TextDecoder(e).decode(t.subarray(0,Gr)))}return t.byteLength>Gr?t.subarray(0,Gr):t}function NO(t,e,n){const i=typeof t.filename=="string"?ute(t.filename):null,r=typeof t.mimeType=="string"?fte(t.mimeType):null,s=t.head===void 0||t.head===null?null:p0(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?hte(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?tk(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 hte(t,e,n){try{return Ate(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<cte&&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 tk(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=gte(i);if(r=s,typeof s=="object"&&s!==null&&!Array.isArray(s)&&!["edges","links","directed","multigraph","graph"].some(o=>o in s)){const o=Fa(s);return o==="node-link"?null:o}}return Fa(r)}function gte(t){const e=bte(t);if(t.startsWith("[")){const r=e.get("nodes[0]");return r===void 0?null:[za(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 za(e.get(t));case"graphs":return yte(e);case"nodes":case"edges":case"links":{const n=e.get(`${t}[0]`);return n===void 0?[]:[za(n)]}default:return!0}}function yte(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=[za(e)]),n!==void 0&&(i.edges=[za(n)]),[i]}function za(t){const e={};if(t!==void 0)for(const n of t)e[n]=n==="attributes"||n==="data"?{}:!0;return e}function bte(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=Ote(t,l+1);if(d<0)break;const u=t.slice(l+1,d);l=d+1,o&&(s=Nte(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=Ete(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 Ete(t,e){switch(t.length){case 1:return t[0]==="object"?"":null;case 2:return wte(t,e);case 3:return _te(t,e);case 5:return Ste(t,e);default:return null}}function wte(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 _te(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 Ste(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 Ote(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 Nte(t){if(!t.includes("\\"))return t;try{return JSON.parse(`"${t}"`)}catch{return t}}function Ate(t){return t>0?Math.min(t,1):0}const Tte={padding:30},Ite=["vx","vy","fx","fy","index","physics"];function $te(t){if(t.nodes.byRole("position")!==null)return OO(t)?.dialect==="cytoscape"?{containersFollowChildren:!0}:null;const e=yp(t.nodes.get("x")),n=yp(t.nodes.get("y"));if(e===null||n===null)return null;const i=yp(t.nodes.get("z")),r=OO(t)?.dialect,s=r!=="graphology"&&Ite.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:Tte}:{}}}function yp(t){const e=["f64","f32","i32","u32","u8"];return t!==null&&t.meta.components===1&&e.includes(t.dtype)?t:null}const nk={renderEdgeLabels:!1,edgeLabelAnchors:"nodeLabels"},g0=["node","edge"];function Cte(t,e){const n=e.kept;if(!$(n))return null;switch(n.dialect){case"cytoscape":return vte(t,n,e);case"graphology":return Pte(t,n,e);case"vis":return Nne(t,n,e);case"node-link":return n.networkx===!0?Rte(t):n.block===null?null:{canonical:!0,block:n.block};default:return n.block===null?null:{canonical:!0,block:n.block}}}function vte(t,e,n){const i=(e.style===void 0||e.style===null)&&e.generatedBy?.startsWith("cytoscape-")===!0,r=e.block!==null&&oc(e.block,to(t)).ok,s=bee({elements:kte(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,y0(t,e.block,{node:s.node?.values??{},edge:s.edge?.values??{}},Dte,Uee)):i&&(o="cytoscape"),{...s,tool:o,block:e.block}}const AO=t=>e=>{const n=e(t);return typeof n=="string"?n.trim():null},ym={node:["label"],edge:["label","sourceLabel","targetLabel"]},Dte={node:Object.fromEntries(ym.node.map(t=>[t,AO(t)])),edge:{...Object.fromEntries(ym.edge.map(t=>[t,AO(t)])),curved:(t,e,n)=>n.edgeSource(e)===n.edgeTarget(e)&&t("curved")!==null?!0:t("curved")}};function kte(t,e){if(e===void 0||e.size===0)return t;const n=i=>{const r=$(i)?e.get(i):void 0;return r===void 0||!$(i)?i:{...i,data:{...i.data,id:r}}};return Array.isArray(t)?t.map(n):$(t)&&Array.isArray(t.nodes)?{...t,nodes:t.nodes.map(n)}:t}function Rte(t){return{canonical:!0,dialect:null,tool:"networkx",units:"px",node:{values:{}},edge:Lte(t)}}function Lte(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 Vr(t,e,n){const i=e==="node"?t.nodes:t.edges;return i.has(n)?r=>K(i.value(n,r)):null}function m0(t){const e={};return{values:e,put:(n,i,r)=>{r!==null&&ik(e,n,t,i,r)}}}function ik(t,e,n,i,r){t[e]??=new Array(n).fill(null),t[e][i]=r}function Pte(t,e,n){const i=new re,r={node:{},edge:{}},s={node:[],edge:[]},o=xte(t,e.sigma??nk);for(const l of g0){const a=l==="node"?t.nodeCount:t.edgeCount,{values:c,put:d}=m0(a),u={color:Vr(t,l,"color"),size:Vr(t,l,"size"),label:Vr(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});Mte(u,l,l==="node"||o(f),f,d,h)}r[l]=c}return y0(t,jte(t,e),r,zte),{canonical:!0,dialect:"graphology",tool:"sigma",opacityInColor:!0,units:"relative",node:{values:r.node},edge:{values:r.edge},notes:i.list(),readFrom:s}}function xte(t,e){if(!e.renderEdgeLabels)return()=>!1;if(e.edgeLabelAnchors==="allNodes")return()=>!0;const n=Vr(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 Mte(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"];Gte(r,c,d,i,o(i),s(c))}if(l!==null&&Ute(r,e,i,l(i),s),a!==null&&n){const c=nt(a(i),s("label"));r("label",i,c===null?null:c.replaceAll(/[\t\n\f\r]/g," "))}}function Ute(t,e,n,i,r){if(e==="node"){const s=Number(i)<0?0:V(i,r("width")),o=s===null?null:s*2;t("width",n,o),t("height",n,o)}else{const s=V(i,r("width"));t("width",n,s===null?null:s/2)}}function Gte(t,e,n,i,r,s){if(r==null)return;const o=$e(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 jte(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 y0(t,e,n,i,r){no(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);Fte(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 Fte(t,e,n,i,r){for(let s=0;s<i;s++){const o=n[s];o!==null&&!r(o)&&ik(t,e,i,s,o)}}const bm=t=>{const e=t("width"),n=t("height");return typeof e=="number"&&typeof n=="number"?Math.max(e,n):e??n},zte={node:{width:bm,height:bm}},kl=new Set(["image","circularImage","diamond","dot","star","triangle","triangleDown","hexagon","square","icon"]),Wte=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}]]),b0=5,E0=14,TO=[["#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"]],Bte="#97C2FC",Hte="#2B7CE9",Yte="#848484";function Vte(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:Kte(i)}}function Kte(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 xs(t,e){if(!$(t))return{};const n={},i=(r,s)=>{s!=null&&(n[r]=s)};return e==="node"?Xte(t,i):ene(t,i),i("hidden",t.hidden),i("label",t.label),i("title",t.title),i("wrapWidth",$(t.widthConstraint)?t.widthConstraint.maximum:t.widthConstraint),$(t.scaling)&&i("scalingLabel",t.scaling.label),tne(t.font,i),e==="edge"&&t.font!==void 0&&t.font!==null&&i("fontText",typeof t.font=="string"),n}function Xte(t,e){const{color:n}=t;if(typeof n=="string"){const i=Vte(n.trim());e("fill",i.background),e("border",i.border)}else $(n)&&(e("fill",n.background),e("border",n.border));e("shape",t.shape),e("size",t.size),e("value",t.value),$(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",$(t.widthConstraint)?t.widthConstraint.minimum:t.widthConstraint),e("heightMin",$(t.heightConstraint)?t.heightConstraint.minimum:t.heightConstraint),e("valign",$(t.heightConstraint)?t.heightConstraint.valign:void 0),e("image",$(t.image)?t.image.unselected:t.image),e("brokenImage",t.brokenImage),e("imagePadding",t.imagePadding),$(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)),$(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 qte(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),Jte(a,t,n),a}function Jte(t,e,n){const i=Qte(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 Zte(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"?$e(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 Qte(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)}:$(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 ene(t,e){const{color:n}=t;if(typeof n=="string")e("edgeColor",n),e("inherit",!1);else if($(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),$(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)}function tne(t,e){if($(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 hc(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=$e(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),Ene(t,i,s,n)):(o("color","opacity",t.edgeColor),_ne(t,s,n),nne(t,s,o)),t.hidden!==void 0&&nc(t.hidden,n("visible"))===!0&&s("visible",!1),ine(t,e,s,o,n),r}function nne(t,e,n){if(!$(t.background))return;const i=t.background,r=t.smooth===!1||$(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=rk(i,!1);s!==null&&e("outlineStyle",s)}function ine(t,e,n,i,r){t.fontSize!==void 0&&n("labelSize",V(t.fontSize,r("labelSize"))),t.fontFace!==void 0&&n("labelFont",nt(t.fontFace,r("labelFont"))),t.label!==void 0&&rne(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",nt(t.title,r("tooltip")));const s=$(t.scalingLabel)?t.scalingLabel.drawThreshold:void 0;typeof s=="number"&&Number.isFinite(s)&&n("labelMinScreenSize",Math.max(0,s-1)),sne(t,e,n,i,r)}function rne(t,e,n,i){const r=e==="edge"&&t.fontText===!0?"":nt(t.label,i("label")),s=typeof r=="string"?lne(r,t.fontMulti):null;if(n("label",s?.text??r),s!==null){const o=cne(s.runs,t,i("labelRuns"));n("labelRuns",o),o!==null&&n("labelRunAlign",dne(t,e))}for(const[o,l]of Object.entries(one[s?.mod??"normal"]??{}))n(o,l)}function sne(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",V(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 one={bold:{labelWeight:"bold"},ital:{labelItalic:!0},boldital:{labelWeight:"bold",labelItalic:!0},mono:{labelFont:"monospace"}};function IO(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 rk(t,e){return t.dashes===void 0||t.dashes===!1?null:Qf(t.dashes===!0?[5,5]:t.dashes,typeof t.size=="number"?t.size:10,e)}function Qf(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 lne(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]=yne(s,o,n);r.push({text:u,mod:bne(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 ane={bold:{mod:"bold"},ital:{mod:"italic"},boldital:{mod:"bold italic"},mono:{mod:"",face:"monospace",size:15,vadjust:2}};function cne(t,e,n){const i={face:typeof e.fontFace=="string"?e.fontFace:"arial",size:typeof e.fontSize=="number"?e.fontSize:E0,color:typeof e.fontColor=="string"?e.fontColor:null,vadjust:typeof e.fontVadjust=="number"&&Number.isFinite(e.fontVadjust)?e.fontVadjust:0},r=$(e.fontMods)?e.fontMods:{};let s=!1;const o=t.map(l=>{const a={text:l.text},c=ane[l.mod];if(c===void 0)return a;const d=hne(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"?$e(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 kl.has(n)?"hanging":"middle"}function une(t){return 2+t/6}function fne(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(`
175
+ `).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 hne(t){if($(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"]]),gne={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=gne[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 yne(t,e,n){if(n==="md")return t[e]==="\\"&&e+1<t.length?[t[e+1],e+2]:[t[e],e+1];const i=[["&lt;","<"],["&amp;","&"]].find(([r])=>t.startsWith(r,e));return i===void 0?[t[e],e+1]:[i[1],e+i[0].length]}function bne(t){return t.mono?"mono":t.bold?t.ital?"boldital":"bold":t.ital?"ital":"normal"}function Ene(t,e,n,i){if(t.shape!==void 0&&(n("shape",oe("shape",t.shape,"vis",i("shape"))),typeof t.shape=="string"&&n("labelPosition",kl.has(t.shape)?"bottom":"center")),e&&t.size!==void 0){const r=V(t.size,i("width"));n("width",r===null?null:2*r),n("height",r===null?null:2*r)}t.borderWidth!==void 0&&n("borderWidth",V(t.borderWidth,i("borderWidth"))),wne(t,n,i)}function wne(t,e,n){if(t.opacity!==void 0){const i=tc(t.opacity,"vis",n("opacity"));e("opacity",IO(t.fill)?i:null),e("borderOpacity",IO(t.border)?i:null)}if(t.borderDashes!==void 0){const i=typeof t.borderWidth=="number"?t.borderWidth:1;e("borderStyle",Qf(t.borderDashes===!0?[5,15]:t.borderDashes,i,!1))}}function _ne(t,e,n){if(t.edgeOpacity!==void 0&&e("opacity",tc(t.edgeOpacity,"vis",n("opacity"))),t.width!==void 0&&e("width",V(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":Qf(r,i,!0))}if(t.arrows!==void 0){const[i,r,s]=One(t.arrows,n);e("targetArrow",i),e("sourceArrow",r),e("midTargetArrow",s);const o=a=>{const c=$(t.arrows)?t.arrows[a]:void 0;return $(c)?c.scaleFactor:void 0},l=o("to")??o("from")??o("middle");l!==void 0&&e("arrowSize",V(l,n("arrowSize"))),Sne(t.arrows,e,n)}}function Sne(t,e,n){if($(t))for(const[i,r]of[["to","targetArrow"],["from","sourceArrow"],["middle","midTargetArrow"]]){const s=t[i];!$(s)||s.type!=="image"||typeof s.src!="string"||s.src===""||(e(`${r}Image`,s.src),s.imageWidth!==void 0&&e(`${r}ImageWidth`,V(s.imageWidth,n(`${r}ImageWidth`))),s.imageHeight!==void 0&&e(`${r}ImageHeight`,V(s.imageHeight,n(`${r}ImageHeight`))))}}function One(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(!$(t))return null;const o=t[i];return o===!0?"triangle":o===void 0?s:!$(o)||o.enabled===!1?"none":oe("arrow",o.type??"arrow","vis",e(r))};return[n("to","targetArrow"),n("from","sourceArrow"),n("middle","midTargetArrow",null)]}function Nne(t,e,n){const i=new re,r=$(e.options)?e.options:{},s=t.nodeCount,o=k=>U=>({notes:i,target:k,property:U}),l=[],a=new Map,c=xs(r.nodes,"node"),d=Vr(t,"node","group"),u=k=>{const U=d?.(k);return typeof U=="string"||typeof U=="number"?String(U):null},{groupLayers:f,paletteRows:h}=Pne(s,u,vO(e,r));n.budget.spend("node",s);const p=m0(s),g=[],m=ak(t,"node"),y=Ane(s,u,m,f,c),b=xne(f,vO(e,r));for(let k=0;k<s;k++){const U=u(k),Y=m(k),me=xs(Y,"node"),Oe=U===null?{}:b(U,Y),Fe=bp(me)??bp(Oe)??bp(c)??"ellipse";g.push(Fe);const J=Q=>({notes:i,target:"node",property:Q,element:k,budget:n.budget}),Gt=Tne(c,Oe,me,U!==null&&Y.color!==void 0);for(const[Q,ut]of Object.entries(Ine(Gt,Fe,y,J)))p.put(Q,k,ut)}const _=hc(c,"node",o("node"),!0);Object.keys(_).length>0&&l.push(_0("node.vis.defaults","node","defaults","declared",{all:!0},_)),$ne(s,u,f,h,o("node"),l,a);const S=Tr("vis-network")?.node,I=k=>p.values.borderColor?.[k]??S?.borderColor?.value??"#2b7ce9",T=jne(t,p.values,g),D=Mne(t,xs(r.edges,"edge"),I,T,i,n),P={node:p.values,edge:D.values};return y0(t,e.block,P,nie(t,P.edge)),{canonical:!0,dialect:"vis",tool:"vis-network",opacityInColor:!0,units:"px",node:{values:P.node,rules:l,columns:a},edge:{values:P.edge,rules:D.rules,columns:D.columns},notes:i.list(),block:e.block,readFrom:{node:wm.node.filter(k=>t.nodes.has(k)),edge:wm.edge.filter(k=>t.edges.has(k))}}}function bp(t){return typeof t.shape=="string"?t.shape:null}function Ane(t,e,n,i,r){return ok(t,s=>{const o=e(s),a=xs(n(s),"node").value??(o===null?void 0:i.get(o)?.value)??r.value;return typeof a=="number"&&Number.isFinite(a)?a:null})}function Tne(t,e,n,i){const r={...t,...e,...n};return i&&(r.fill??=Bte,r.border??=Hte),r}function Ine(t,e,n,i){const r=kl.has(e),s=hc(t,"node",i,r),o=r?Cne(t,e,Lne(t,n,i),i):vne(t,e);if(r&&t.label!==void 0){const a=Em(t,n)??(typeof t.fontSize=="number"?t.fontSize:E0),c=typeof s.labelRuns=="string"?fne(s.labelRuns,a):0,d=typeof s.labelOffsetY=="number"?s.labelOffsetY:0;s.labelOffsetY=d+c+une(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=Em(t,n);return l!==null&&(s.labelSize=l),s}function $ne(t,e,n,i,r,s,o){let l=0;for(const[a,c]of n){const d=i.get(a)??hc(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=_0(`node.vis.group.${String(l++)}`,"node","group",f,{has:{style:u}},d);s.push({...h,facts:{names:[[u,a]]}})}}function Cne(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,qte(t,e,{width:2*n,height:2*n})),e==="icon"&&Object.assign(r,{shape:"none"},Zte(t,i("glyphColor"))),e==="triangleDown"&&(r.shape="polygon",r.shapePoints="-1,1 0,-1 1,1"),r}function vne(t,e){const n=sk(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.top:i;n.labelPosition="inside-top",n.labelOffsetY=typeof r=="number"&&Number.isFinite(r)&&r>=0?r:b0}return e==="box"&&typeof t.borderRadius=="number"&&Number.isFinite(t.borderRadius)&&(n.cornerRadius=Math.max(0,t.borderRadius)),n}function sk(t,e){const n=Wte.get(e);if(n===void 0)return{};const i=g=>typeof g=="number"&&Number.isFinite(g)&&g>=0?g:null,r=i(t.fontSize)??E0,s=typeof t.label=="string"?Math.max(1,t.label.split(`
176
+ `).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}=Dne(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 Dne(t,e){const n=s=>typeof s=="number"&&Number.isFinite(s)&&s>=0?s:null,i=s=>($(t)?n(t[s]):n(t))??b0,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 Em(t,e){const n=eh(t.value),i=t.scalingLabel;if(n===null||e===null||!$(i)||i.enabled!==!0)return null;const r=typeof i.min=="number"?i.min:14,s=typeof i.max=="number"?i.max:30;return w0(n,e,r,s)}const kne=25,$O=[10,30];function ok(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 eh=t=>typeof t=="number"&&Number.isFinite(t)?t:null;function w0(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 CO=[1,15];function Rne(t,e,n,i){if(n===null)return{};const r=eh(t.value);if(r!==null){const s=typeof t.scalingMin=="number"?t.scalingMin:CO[0],o=typeof t.scalingMax=="number"?t.scalingMax:CO[1];return{width:w0(r,n,s,o)}}return{width:(e.width===void 0?null:V(e.width,i("width")))??1}}function Lne(t,e,n){const i=eh(t.value);if(i!==null&&e!==null){const s=typeof t.scalingMin=="number"?t.scalingMin:$O[0],o=typeof t.scalingMax=="number"?t.scalingMax:$O[1];return w0(i,e,s,o)}return(t.size===void 0?null:V(t.size,n("width")))??kne}function vO(t,e){return $(e.groups)?e.groups:$(t.groups)?t.groups:{}}function Pne(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,xs(n[l],"node"));else{const[a,c]=TO[s++%TO.length];i.set(l,{fill:c,border:a}),r.set(l,{fill:c.toLowerCase(),borderColor:a.toLowerCase()})}}return{groupLayers:i,paletteRows:r}}function xne(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"&&($(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=$(o)?xs(Object.fromEntries(Object.entries(o).filter(([d])=>!l.includes(d))),"node"):{},n.set(a,c)),c}}function Mne(t,e,n,i,r,s){const o=t.edgeCount,l=m0(o),a=Zne(t,"edge"),c=new Array(o).fill(null);let d=0;const u=ok(o,g=>eh({...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},_=k=>({notes:r,target:"edge",property:k,element:g,budget:s.budget}),[S,I]=[t.edgeSource(g),t.edgeTarget(g)],T={...hc(b,"edge",_,!0),...Rne(b,e,u,_),...Kne(e,m,S,I,i),...zne(b,u,i.at(S),i.at(I))};f||=b.hidden!==!0&&![void 0,!1,"false"].includes(b.dashes);const D=f&&$(b.background)?rk(b.background,!0):null;D!==null&&(T.outlineStyle=D);const P=Une(T,m.inherit??e.inherit??"from",n,S,I);for(const[k,U]of Object.entries(T))l.put(k,g,U);P!==null&&(c[g]=P,d++)}s.budget.spend("edge",o);const{rules:h,columns:p}=Gne(e,r,c,d);return{values:l.values,rules:h,columns:p}}function Une(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=Yte),null)}function Gne(t,e,n,i){const r=[],s=new Map,o=hc(t,"edge",l=>({notes:e,target:"edge",property:l}),!0);return Object.keys(o).length>0&&r.push(_0("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 jne(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]=[Vr(t,"node","x"),Vr(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 Fne(...t){const e={enabled:!0,type:"dynamic",roundness:.5,forceDirection:"none"};for(const n of t)typeof n=="boolean"?e.enabled=n:$(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 zne(t,e,n,i){const r={},s=Em(t,e);s!==null&&(r.labelSize=s);const o=Wne(t.fontAlign,n,i);return o!==null&&(r.labelRotation=o),r}function Wne(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 Bne(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 Hne(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 DO(t,e,i,i*.5+.5);case"curvedCCW":return DO(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 Hne(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 DO(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 Yne(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 Vne(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`${Zr((s*i+o*r)/l)},${Zr((r*s-i*o)/l)}`}const Zr=t=>String(Math.round(t*1e4)/1e4||0);function Kne(t,e,n,i,r){if(n===i)return Xne(t,e,r.box(n));const s=Fne(t.smooth,e.smooth),[o,l]=[r.at(n),r.at(i)];return!s.enabled||s.type==="dynamic"||o===null||l===null||o[0]===l[0]&&o[1]===l[1]?{}:{curved:!0,bendCurve:"bezier",bends:(s.type==="cubicBezier"?Yne(o,l,s):[Bne(o,l,s)]).map(c=>Vne(o,l,c)).join(" ")}}function Xne(t,e,n){if(n===null)return{};const i=(g,m)=>$(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=lk(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 Jne(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 qne(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(`${Zr(y/l)},${Zr(b/a)}`)}return{curved:!0,bendCurve:"midpoints",bends:p.join(" ")}}const xd=96;function qne(t,e,n,i,r){const[s,o]=r,l=[];for(let a=0;a<=xd;a++){const c=i+Math.PI+2*Math.PI*(a%xd)/xd;l.push(`${Zr((t+n*Math.cos(c))/s)},${Zr((e+n*Math.sin(c))/o)}`)}return{curved:!1,bends:l.join(" ")}}function Jne(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 I=(y+b)*.5,T=I*2*Math.PI;_=[s+n*Math.cos(T),o-n*Math.sin(T)];const D=lk(r,Math.atan2(-_[1],-_[0]))-Math.hypot(_[0],_[1]);if(Math.abs(D)<.05)break;D>0==m>0?y=I:b=I}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)*xd)),g=[];for(let m=0;m<=p;m++){const y=d+(u-d)*m/p;g.push(`${Zr((s+n*Math.cos(y))/f)},${Zr(-(o+n*Math.sin(y))/h)}`)}return{curved:!1,bends:g.join(" ")}}function lk(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 wm={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","widthConstraint"]};function Zne(t,e){const n=ak(t,e);return i=>xs(n(i),e)}function ak(t,e){const n=wm[e].map(i=>[i,Vr(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 _0(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 Qne=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]]]),eie=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 ll(t){const e=Qne.get(t);return e!==void 0?e:t.startsWith("other:")?[t.slice(6),!0]:["dot",!1]}function ck(t){if(t==="none")return[null,!0];const e=eie.get(t);return e!==void 0?e:t.startsWith("other:")?[t.slice(6),!0]:["arrow",!1]}const _m=t=>{const e=t("shape"),n=typeof e=="string"?ll(e)[0]:"ellipse";return kl.has(n)?bm(t):null},tie=t=>{const e=t("shape");return typeof e=="string"?ll(e)[0]:"ellipse"},kO=t=>e=>{const n=tie(e),i=_m(e);return n==="hexagon"&&typeof i=="number"?t==="height"?Math.sqrt(3)*i/2:(2-Math.sqrt(3))*i/4:t==="labelOffsetY"&&n==="database"?b0:null},Eo=t=>e=>{const n=e("shape"),i=typeof n=="string"?ll(n)[0]:"ellipse";return sk({fontSize:e("labelSize"),label:e("label")},i)[t]??null};function nie(t,e){const n=i=>(r,s)=>t.edgeSource(s)===t.edgeTarget(s)?e[i]?.[s]??null:r(i);return{node:RO.node,edge:{...RO.edge,bends:n("bends"),bendCurve:n("bendCurve"),curved:n("curved")}}}const RO={node:{width:t=>_m(t)??Eo("width")(t),height:t=>kO("height")(t)??_m(t)??Eo("height")(t),labelOffsetY:kO("labelOffsetY"),labelFit:Eo("labelFit"),labelPaddingX:Eo("labelPaddingX"),labelPaddingY:Eo("labelPaddingY"),labelFitSquare:Eo("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 re,target:"node",property:"shape"};return oe("shape",ll(e)[0],"vis",n)},labelPosition:t=>{const e=t("shape");if(typeof e!="string")return null;const n=ll(e)[0];return n==="database"?"inside-top":kl.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 Qf([5,5],typeof n=="number"?n:1,!0)},targetArrow:t=>LO(t("targetArrow")),sourceArrow:t=>LO(t("sourceArrow"))}};function LO(t){if(typeof t!="string")return null;const[e]=ck(t),n={notes:new re,target:"edge",property:"targetArrow"};return e===null?"none":oe("arrow",e,"vis",n)}function PO(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 hs={cytoscape:{node:PO(Zb,["labelPosition","labelItalic","visible"]),edge:PO(Qb,["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"]}},dk=Object.freeze({node:Object.freeze([...new Set([...hs.cytoscape.node,...hs.vis.node,...hs.graphology.node])]),edge:Object.freeze([...new Set([...hs.cytoscape.edge,...hs.vis.edge,...hs.graphology.edge])]),block:"native"}),xO=new Set(["node-link","jgf","graphology"]);function iie(t,e,n){if(n===void 0)return null;const i=e==="cytoscape"||e==="graphology"||e==="vis"?hs[e]:null,r=[...fie(n,e,i),...rie(t,e,n)];if(e==="obographs")return{snapshot:t,topLevelBlock:null,stylesheet:null,groups:null,notes:r};const s=t.withColumns(),o=cie(n.rules.styles.rules);for(const[d,u]of[[s.nodes,"node"],[s.edges,"edge"]]){sie(d,e,o[u]);for(const[f,h]of n.tags[u])Pu(d,f,h)}s.graph.has(Z)&&s.graph.remove(Z),xO.has(e)&&s.graph.set(Z,[n.block],{dtype:"string"});let l=null;const a=new Al,c=new pie(s.nodes);if(e==="cytoscape"){const d=oie(s,n);({stylesheet:l}=d),r.push(...d.notes.map(hie)),lie(n,a)}else e==="graphology"?gie(s,n,a,c):e==="vis"&&mie(s,n,a,c);return r.push(...a.notes(`the ${e} dialect of JSON`),...c.notes(e)),{snapshot:s,topLevelBlock:xO.has(e)?null:n.block,stylesheet:l,groups:e==="vis"?aie(s):null,notes:r}}function rie(t,e,n){let i=null;return e==="jgf"&&!uie(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 sie(t,e,n){for(const i of t.names())(i.startsWith("graphty.style.")||i.startsWith("graphty_style_")||i===$o)&&!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 oie(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=XD({...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)Pu(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)&&Pu(r,"style#element",a)}return i}function lie(t,e){for(const n of g0)for(const i of ym[n])for(const r of t.picture(n,i))typeof r=="string"&&r.trim()!==r&&e.add(n,i,JSON.stringify(r))}function aie(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 cie(t){const e={node:new Set,edge:new Set};for(const n of t){const i=[...die(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 die(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 uie(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 fie(t,e,n){const i=[];for(const r of g0){const s=new Set(dk[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 hie(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 Pu(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 At(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}Pu(t,e,n)}const uk="W_JSON_STYLE_KEY_REPLACED";class pie{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:uk,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 fk(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 hk(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 gie(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);At(s,"color",c.map((u,f)=>fk(u,d[f])),i),At(s,"size",o==="node"?hk(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),At(s,"label",r(o,"label"),i)}}function MO(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});At(t,"scaling",r,n)}function mie(t,e,n,i){const r=(b,_)=>e.picture(b,_),s=b=>{const _=r(b,"labelColor"),S=r(b,"labelSize"),I=r(b,"labelFont");return _.map((T,D)=>{const P={};return _[D]!==null&&(P.color=_[D]),S[D]!==null&&(P.size=S[D]),I[D]!==null&&(P.face=I[D]),Object.keys(P).length===0?null:P})},o=(b,_)=>{At(b,"label",r(_,"label"),i),At(b,"title",r(_,"tooltip"),i),At(b,"font",s(_),i),At(b,"hidden",r(_,"visible").map(S=>S===!1?!0:null),i)},l=r("node","fill"),a=r("node","fillOpacity"),c=r("node","borderColor");At(t.nodes,"color",l.map((b,_)=>{const S={},I=fk(l[_],a[_]);return I!==null&&(S.background=I),typeof c[_]=="string"&&(S.border=c[_]),Object.keys(S).length===0?null:S}),i);const d=hk(r("node","width"),r("node","height"),n),u=r("node","shape").map((b,_)=>{const[S,I]=typeof b=="string"?ll(b):[null,!0],T=S==="dot"&&b==="ellipse"&&d[_]===null?"ellipse":S;return I||n.add("node","shape",b),d[_]!==null&&!kl.has(T??"ellipse")&&n.add("node","width",`${String(b??"ellipse")} sized by its label`),T});At(t.nodes,"shape",u,i);const f=d.map(b=>b===null?null:b/2);At(t.nodes,"size",f,i),MO(t.nodes,f,i),At(t.nodes,"borderWidth",r("node","borderWidth"),i),At(t.nodes,"opacity",r("node","opacity"),i),o(t.nodes,"node");const h=r("edge","color"),p=r("edge","opacity");At(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");At(t.edges,"width",g,i),MO(t.edges,g,i),At(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");At(t.edges,"arrows",m.map((b,_)=>{const S={};for(const[I,T,D]of[["to",m[_],"targetArrow"],["from",y[_],"sourceArrow"]]){if(typeof T!="string")continue;const[P,k]=ck(T);k||n.add("edge",D,T),S[I]=P===null?{enabled:!1}:{enabled:!0,type:P}}return Object.keys(S).length===0?null:S}),i),o(t.edges,"edge")}const L=Object.freeze({...xn,...Pn,EMPTY_INPUT:Mt,SYNTAX:kn,DIALECT:"E_JSON_DIALECT",SHAPE:"E_JSON_SHAPE",MISSING_SECTION:"W_MISSING_SECTION",BAD_ELEMENT:"E_BAD_ELEMENT",MISSING_ID:at,UNSUPPORTED_ID:"E_UNSUPPORTED_ID",MISSING_ENDPOINT:Jn,BAD_INDEX:"E_BAD_INDEX",BAD_VALUE:ne,BAD_FLAG:"W_BAD_FLAG",UNKNOWN_PARENT:Mi,DUPLICATE_NODE:sn,DUPLICATE_EDGE_ID:Oi,ID_MERGED:Rn,EDGE_ID_STRINGIFIED:"W_EDGE_ID_STRINGIFIED",MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,OBOGRAPHS_SUBJ:"W_JSON_OBOGRAPHS_SUBJ",DANGLING_REFERENCE:Ki,TOO_LARGE:hl,HYPEREDGE:uA,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:qu,BIG_INTEGER:"W_JSON_BIG_INTEGER",UNKNOWN_ENCODING:bn,PRECISION:ie,INCONSISTENT:"W_JSON_INCONSISTENT",INDEX_LINKS:"W_JSON_INDEX_LINKS",PARENT_CYCLE:fl,EMPTY_COLUMN_DROPPED:sy,UNKNOWN_ELEMENT:$t,DUPLICATE_ATTRIBUTE:de,COLUMN_RENAMED:ln,ROLE_TAKEN:yn}),yie=new Set(["ids","nodeIdFrom","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","hyperedges","errorLimit","signal","onProgress"]),Ep={ids:"keep",defaultDirected:!1,weightFrom:"weight"},bie=4096,wp=5,Eie=64,wie=['"nodes"','"links"','"edges"','"elements"','"graph"','"graphs"'],_ie="\uFEFF",pk=new Set(["id","source","target","relation","directed","label","metadata"]),Sie=new Set([...pk,"nodes"]),Oie=/^(?:0|[1-9]\d{0,9})$/,Nie=new Set(["label","metadata"]),Aie=new Set(["key","attributes"]),gk=new Set(["key","source","target","attributes","undirected"]),Tie=new Set(["id","attributes"]),Iie=new Set([...gk,"id"]),$ie=new Set(["label","x","y","size","color"]),Cie=new Set(["label","size","color"]),vie=Object.freeze(["from"]),Die=Object.freeze(["to"]),Sm=new Set(["node-link","d3","vis","graphology"]);function _p(t){const e=t??{},n=e.dialect??"auto";if(n!=="auto"&&!Kee(n))throw di("dialect",n,[...qD,"auto"]);const i=e.indexLinks??"auto";if(i!=="auto"&&typeof i!="boolean")throw di("indexLinks",i,["true","false","auto"]);const r=e.graphIndex??0;if(!Number.isInteger(r)||r<0)throw di("graphIndex",r,["a non-negative integer"]);const s=e.oboIds??"curie";if(s!=="curie"&&s!=="iri")throw di("oboIds",s,["curie","iri"]);const o=e.typedefs??"metadata";if(o!=="metadata"&&o!=="nodes")throw di("typedefs",o,["metadata","nodes"]);const l=UO("nodesPath",e.nodesPath),a=UO("edgesPath",e.edgesPath);if((l!==null||a!==null)&&n!=="auto"&&!Sm.has(n))throw di(l===null?"edgesPath":"nodesPath",n,[...Sm]);return{dialect:n,nodeIdKey:Xc("nodeIdKey",e.nodeIdKey),edgesKey:Xc("edgesKey",e.edgesKey),sourceKey:Xc("sourceKey",e.sourceKey),targetKey:Xc("targetKey",e.targetKey),indexLinks:i,graphIndex:r,choice:{graphIndex:e.graphIndex,graphName:e.graphName},oboIds:s,typedefs:o,nodesPath:l,edgesPath:a,sigma:kie(e.sigmaSettings)}}function kie(t){if(t===void 0)return nk;if(!$(t))throw di("sigmaSettings",t,["an object of sigma.js settings"]);const{renderEdgeLabels:e=!1,edgeLabelAnchors:n="nodeLabels"}=t;if(typeof e!="boolean")throw di("sigmaSettings.renderEdgeLabels",e,["true","false"]);if(n!=="nodeLabels"&&n!=="allNodes")throw di("sigmaSettings.edgeLabelAnchors",n,["nodeLabels","allNodes"]);return{renderEdgeLabels:e,edgeLabelAnchors:n}}function UO(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 di(t,e,["a dotted path of non-empty keys"]);return n}function GO(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($(n)&&z(n,i))n=n[i];else return;return n}function Rie(t,e,n){const{nodesPath:i,edgesPath:r}=e;if(i===null&&r===null)return t;const s=(d,u)=>{const f=GO(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=GO(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($(l)?l:{}).filter(([d])=>!a.has(d)));if(r!==null&&r.length>o.length&&o.every((d,u)=>r[u]===d)){const d=mk(c,r.slice(o.length));c=$(d)?d:{}}return i!==null&&(c.nodes=s("nodesPath",i)),r!==null&&(c[yk(e,r)]=s("edgesPath",r)),c}function mk(t,e){if(e.length===0)return;const[n,...i]=e;if(!$(t)||!z(t,n))return t;const r=Object.entries(t).map(([s,o])=>[s,s===n?mk(o,i):o]).filter(([,s])=>s!==void 0);return r.length===0?void 0:Object.fromEntries(r)}function yk(t,e){return t.edgesKey??(e.at(-1)==="links"?"links":"edges")}function Lie(t,e,n){if(e!=="auto")return e;if(n&&$(t)&&z(t,"links")&&!z(t,"edges")){const{links:r,...s}=t,o=Fa({...s,edges:r});if(o==="vis"||o==="graphology")return o}const i=Fa(t);return i!==null&&Sm.has(i)?i:"node-link"}function Sp(t,e,n){if(e.nodesPath===null&&e.edgesPath===null)return{root:t,dialect:Gie(t,e.dialect,n)};const i=Rie(t,e,n),r=Lie(i,e.dialect,e.edgesPath!==null);if(e.edgesPath!==null&&(r==="vis"||r==="graphology")&&$(i)){const s=yk(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 Xc(t,e){if(e===void 0)return null;if(typeof e!="string"||e.length===0)throw di(t,e,["a non-empty key"]);return e}function di(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 jO{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",sy,`${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 Pie{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 Qn(e,n,i.onMixedDirection),this.nodes=new jO(e,"node",n),this.edges=new jO(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:ZD[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<wp&&this.danglingIds.push(e);const n=typeof e=="number"?String(e):Number(e);this.nearMatches.length<wp&&(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>wp?", ...":""}${n}`,{element:String(this.danglingIds[0])})}checkAbort(){++this.elementsSinceCheck>=Eie&&(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:{[u0]: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(!$(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 sf(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}${Rt.data}`:u;e.write(n,f,r[u],Rt.data,o)}for(const u of Object.keys(i))s.has(u)||e.write(n,c?u:`${u}${Rt.element}`,i[u],Rt.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(!$(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 Op(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&&!XT.test(t)&&!t3.test(t))return zO(t,e),n;let s;try{if(s=Py(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,Uie(t,i),{line:Mie(r,i)}):(zO(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: ${FO(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): ${FO(s.inexact)}`),n)}function FO(t){const e=t.length-WO,n=t.slice(0,WO).join(", ");return e>0?`${n} and ${e} more`:n}const qc=10;function zO(t,e){const n=d3(t);let i=1,r=0;for(const{key:s,offset:o}of n.slice(0,qc))i+=Md(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>qc&&e.warning("merged",L.DUPLICATE_ATTRIBUTE,`${n.length-qc} more repeated key${O(n.length-qc)}; each earlier value is dropped`)}function Md(t,e,n){let i=0;for(let r=t.indexOf(`
177
+ `,e);r>=0&&r<n;r=t.indexOf(`
178
+ `,r+1))i++;return i}const xie=64*1024*1024;function Mie(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 Md(t,0,Number(i[1]))+1;if(!e.startsWith("Unexpected token")||t.length>xie)return Md(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 Md(t,0,r)+1}function Uie(t,e){return Tre(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 WO=10;function Gie(t,e,n){if(e!=="auto")return e;const i=Fa(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)"):$(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 Qr(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 es(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 Wa(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 jie=new Set(["nodes","edges",Z]),Fie=new Set(["nodes","edges","options","attributes",Z]),zie=new Set(["id","type","label","directed","metadata","nodes","edges","hyperedges"]);function hr(t,e){return t.some(n=>$(n)&&n[e]!==void 0&&n[e]!==null)}function Om(t,e){return typeof t=="number"&&Number.isInteger(t)&&t>=0&&t<e}function Wie(t,e,n){const{report:i,json:r}=t,s=r.edgesKey??(z(e,"edges")||!z(e,"links")?"edges":"links"),{nodeList:o,edgeList:l}=Bie(t,e,s),a=Qr(e.directed,"directed",t.defaultDirected(n),i),c=z(e,"multigraph")?Qr(e.multigraph,"multigraph",!1,i):null;t.setHeader(a),t.writeGraphDict(e.graph,"graph"),Wa(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:pc(e),networkx:d},t.sink.reserve(o.length,l.length);const u=Hie(t,o),f=u===null;let h;f?h=!0:r.indexLinks==="auto"?h=qie(o,l,u,r):{indexLinks:h}=r,h&&!f&&r.indexLinks==="auto"&&Xie(t,o,l,u);const p=Yie(t,o,u,h);F(t.options.signal);const g=Kie(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 Bie(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 Hie(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=>hr(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 Yie(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;$(l)?a=Vie(t,l,s,n):t.badElement("node",o),r?.push(a)}return r}function Vie(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:(th(t.nodes,l,e,o,a=>a!==i),o)}function Kie(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(!$(h)){t.badElement("edge",f);continue}const p=es(h,s.sourceKey,f0),g=es(h,s.targetKey,h0);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=BO(t,p.value,i,f,"source"),y=BO(t,g.value,i,f,"target");if(m===null||y===null){t.countSkipped("edge");continue}const b=t.weightOf(h);if(c!==null){const I=bk(m,y,o==="directed");if(r===!1)d+=c.has(I)?1:0,c.add(I);else if(z(h,"key")){const T=`${I} ${JSON.stringify(h.key)}`;if(c.has(T))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(T)}}const _=t.pushEdge(m,y,o,b,f),{weightFrom:S}=t.options;for(const I of Object.keys(h))I!==p.key&&I!==g.key&&I!==S&&t.edges.write(_,I,h[I],Rt.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 bk(t,e,n){const i=JSON.stringify(t),r=JSON.stringify(e);return n||i<=r?`${i} ${r}`:`${r} ${i}`}function Xie(t,e,n,i){const r=new Set;for(const s of e)$(s)&&typeof s[i]=="string"&&r.add(s[i]);for(const s of n)if($(s)){for(const o of[es(s,t.json.sourceKey,f0).value,es(s,t.json.targetKey,h0).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 th(t,e,n,i,r){for(const s of Object.keys(n))r(s)&&t.write(e,s,n[s],Rt.data,String(i))}function qie(t,e,n,i){if(e.length===0||t.length===0)return!1;for(const s of t)if($(s)&&typeof s[n]=="number")return!1;let r=0;for(const s of e){if(!$(s))continue;const o=es(s,i.sourceKey,f0).value,l=es(s,i.targetKey,h0).value;if(o!==void 0&&typeof o!="number"||l!==void 0&&typeof l!="number")return!1;(Om(o,1/0)||Om(l,1/0))&&r++}return r>0}function BO(t,e,n,i,r){if(n===null)return t.coerceId(e,`${i}.${r}`);if(!Om(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 Jie(t,e){const{report:n,json:i}=t,r=Dn(e.nodes,"nodes",n)??[],s=Dn(e.edges,"edges",n)??[];Wa(t,e,jie,""),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(!$(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&&th(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(!$(p)){t.badElement("edge",h);continue}const g=es(p,i.sourceKey,vie),m=es(p,i.targetKey,Die);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:I}=t.options;for(const T of Object.keys(p))T!==g.key&&T!==m.key&&T!=="id"&&T!==I&&t.edges.write(S,T,p[T],Rt.data,h)}catch(y){t.skip(y,"edge",h)}}const u=a==="undirected"?s.filter(f=>$(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:pc(e),options:e.options,groups:e.groups},t.setMeta({dialect:"vis",nodeIdKey:o,sourceKey:c??void 0,targetKey:d??void 0},t.weightOriginPatch())}function Zie(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=Qr(e.directed,"directed",t.defaultDirected("adjacency"),n),o=z(e,"multigraph")?Qr(e.multigraph,"multigraph",!1,n):null;t.setHeader(s),t.writeGraphDict(lre(e.graph)?Object.fromEntries(e.graph):e.graph,"graph"),ere(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)=>tre(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++)nre(t,d,u,l[u]);rre(t,i.length,r===null?null:l.length,d.disagreeing,d.pending),t.setMeta({},{declaredMultigraph:o,...t.weightOriginPatch()})}const Qie=new Set(["nodes","adjacency","directed","multigraph","graph"]);function ere(t,e){for(const n of Object.keys(e))Qie.has(n)||t.report.warning("unsupported",L.UNREAD_KEY,`top-level key ${n} (${Ye(e[n])}) is not read; dropped`,{element:n})}function tre(t,e,n,i){if(!$(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:(th(t.nodes,s,e,r,o=>o!==i),r)}function nre(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++)ire(t,e,o,i[l],s,`${s}[${l}]`)}function ire(t,e,n,i,r,s){const{idKey:o}=e;if(!$(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=ore(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],Rt.data,r)}catch(l){t.skip(l,"edge",s)}}function rre(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 sre(t,e){return $(e)?Object.fromEntries(Object.entries(e).sort(([n],[i])=>n<i?-1:1)):e}function ore(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)),sre),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 lre(t){return Array.isArray(t)&&t.every(e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="string")}function are(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(!$(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(th(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 cre(t,e){const{report:n}=t,i=Dn(e.nodes,"nodes",n)??[],r=Dn(e.edges,"edges",n)??[];Wa(t,e,Fie,"");const s=$(e.options)?e.options:{};z(e,"options")&&!$(e.options)&&n.warning("validation-error",L.BAD_FLAG,"options is not an object; ignored",{element:"options"});const o=dre(t,s);t.setHeader(o==="mixed"?ure(t,r):o==="directed");const l=z(s,"multi")?Qr(s.multi,"options.multi",!1,n):null,a=z(s,"allowSelfLoops")?Qr(s.allowSelfLoops,"options.allowSelfLoops",!0,n):void 0;t.writeGraphDict(e.attributes,"attributes");const c=i.find(f=>$(f)),d=$(c)&&!z(c,"key")&&z(c,"id");t.styleSource={dialect:"graphology",block:pc(e),gephi:d,sigma:t.json.sigma},t.reportNodeIdFrom("graphology","the node key"),t.sink.reserve(i.length,r.length),fre(t,i,d),F(t.options.signal);const u=hre(t,r,{type:o,gephi:d,multi:l,allowSelfLoops:a});mre(t,u,o),t.setMeta({dialect:"graphology",allowSelfLoops:a},{declaredMultigraph:l,...t.weightOriginPatch()})}function dre(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 ure(t,e){const n=e.filter(r=>$(r)),i=n.filter(r=>r.undirected===!0).length;return n.length===0?t.defaultDirected("graphology"):i<n.length}function fre(t,e,n){const i=n?"id":"key";for(let r=0;r<e.length;r++){const s=`nodes[${r}]`,o=e[r];if(!$(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}yre(t,l,o,"attributes",n?Tie:Aie,s,n)}}function hre(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=pre(t,e[l],a);if(c!==null)try{const d=gre(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 pre(t,e,n){return $(e)?!$n(e,"source")||!$n(e,"target")?(t.missingEndpoint(n,$n(e,"source")?"target":"source"),null):e:(t.badElement("edge",n),null)}function gre(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=Qr(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&&!$(f)&&o.error("validation-error",L.BAD_VALUE,`${n}: attributes must be an object, found ${Ye(f)}`,{element:n});const h=$(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?Iie:gk,n,{weightFrom:t.options.weightFrom,plain:a,dataKeys:a?Cie:void 0}),r.allowSelfLoops===!1&&c===d&&s.selfLoops++,`${u} ${bk(c,d,u==="directed")}`}function mre(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 yre(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&&!$(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,$(a)?a:{},r,s,{plain:o,dataKeys:o?$ie:void 0})}catch(a){t.report.recordError(a,{element:String(e)})}return l}function bre(t,e){const{report:n}=t,i=Are(t,e),r=Dn(i.edges,"graph.edges",n)??[],s=Dn(i.hyperedges,"graph.hyperedges",n)??[],o=i.nodes;o!=null&&!$(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=Ere(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},hr(l,"label"));if($(o))for(const h of Nre(t,e,i,o))wre(t,h,o[h],u);else for(let h=0;h<l.length;h++)_re(t,l[h],u,`nodes[${h}]`);F(t.options.signal);const f=Sre(t,r,s);for(let h=0;h<r.length;h++)Ore(t,r[h],`edges[${h}]`,a,f);Ire(t,s,a,f),t.setMeta(c,{name:d,...t.weightOriginPatch()})}function Ere(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=>$(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&&!$(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${Rt.element}`,{element:r}),wk(t,s,n??{},i,r)}function _re(t,e,n,i){if(!$(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}wk(t,r,e,n,i)}function Sre(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},hr(e,"relation")||hr(n,"relation")),s=t.edges.declareIf({name:"label",dtype:"string",role:"label",nullable:!0},hr(e,"label")||hr(n,"label"));return(o,l,a,c,d,u=pk)=>{const{metadata:f}=o,h=$(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&&!$(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 Ore(t,e,n,i,r){if(!$(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=Qr(e.directed,`${n}.directed`,i,t.report);r(e,s,o,l?"directed":"undirected",n)}catch(s){t.skip(s,"edge",n)}}function Nre(t,e,n,i){const r=Object.keys(i);if(!r.some(o=>Oie.test(o)))return r;const s=$(e.graph)?["graph","nodes"]:["graphs",e.graphs.indexOf(n),"nodes"];return p3(t.text,s)??r}function Are(t,e){const n=$(e.graph);Wa(t,e,new Set([n?"graph":"graphs"]),"");const i=n?e.graph:Ek(t,e,"JGF"),r=n?"graph.":`graphs[${e.graphs.indexOf(i)}].`;Wa(t,i,zie,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 Ek(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:pl(r.map(Nm),t.json.choice,i);r.length>1&&t.json.all!==!0&&!eo(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 $(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 Nm(t){if(!$(t))return null;for(const e of["id","label","lbl"])if(typeof t[e]=="string")return t[e];return null}function Jc(t){return t==null?0:Array.isArray(t)?t.length:$(t)?Object.keys(t).length:null}function HO(t,e){if((e==="jgf"||e==="obographs")&&$(t)){if(Array.isArray(t.graphs)&&!$(t.graph))return t.graphs.map((n,i)=>({index:i,name:Nm(n),nodes:$(n)?Jc(n.nodes):null,edges:$(n)?Jc(n.edges):null}));if($(t.graph)){const{graph:n}=t;return[{index:0,name:Nm(n),nodes:Jc(n.nodes),edges:Jc(n.edges)}]}}return[{index:0,name:null,nodes:null,edges:null}]}function Tre(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 wk(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&&!$(o)&&t.report.error("validation-error",L.BAD_VALUE,`${r}: metadata must be an object`,{element:r}),t.writeNested(t.nodes,s,n,$(o)?o:{},Nie,r)}catch(o){t.report.recordError(o,{element:String(e)})}}function Ire(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,Sie)}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(!$(d)){t.badElement("edge",c);continue}try{if(Array.isArray(d.nodes)){const u=$re(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;YO(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"});YO(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 _k?(r.error("unsupported",u.code,u.message,{element:c}),t.countSkipped("edge")):t.skip(u,"edge",c)}}}class _k extends N{}const Np=1e6;function YO(t,e,n){if(e.used+t>Np)throw new _k("E_TOO_LARGE",`${n}: the expansion makes ${t} edges, which with the ${e.used} already expanded is more than ${Np}; the hyperedge is skipped`,{count:t,used:e.used,limit:Np});e.used+=t}function $re(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 Cre(t,e){const{elements:n,extra:i}=vre(t,e),{nodes:r,edges:s}=Ure(t,n),o=Gre(r);t.styleSource={dialect:"cytoscape",block:pc(e),elements:n??[],style:$(e)?e.style:void 0,generatedBy:$(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=Dre(t,r),a=t.edges.declareIf({name:ek,dtype:"list",itemDtype:"string",role:"classes",nullable:!0},hr(s,"classes")),c=[];for(let d=0;d<r.length;d++){const u=`nodes[${d}]`,f=r[d];if($(f)&&$(f.data)){const h=f.data.id===void 0?o.get(f):f.data.id;kre(t,f,f.data,h,u,l,c)}else t.badElement("node",u,"an element with a data object")}Lre(t,c,l.parent),F(t.options.signal),xre(t,s,a),t.setMeta({dialect:"cytoscape",cytoscape:i},t.weightOriginPatch())}function vre(t,e){if(Array.isArray(e))return{elements:e};$(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 Dre(t,e){const n=(i,r)=>i.some(s=>$(s)&&$(s.data)&&s.data[r]!==void 0);return{position:t.nodes.declareIf({name:lte,dtype:"f64",components:3,role:"position",mutable:!0,nullable:!0,extra:{sourceDims:e.some(jre)?3:2,units:"file"},origin:{format:"json",namespace:"cytoscape"}},hr(e,"position")),classes:t.nodes.declareIf({name:ek,dtype:"list",itemDtype:"string",role:"classes",nullable:!0},hr(e,"classes")),parent:t.nodes.declareIf({name:ate,dtype:"u32",role:"parent",refersTo:"node",nullable:!0},n(e,"parent"))}}function kre(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],Rt.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})}Rre(t,s.position,c,e.position,r),Sk(t,t.nodes,s.classes,c,e.classes,r),Ok(t.nodes,c,e,r)}catch(d){l.recordError(d,{element:String(a)})}}}function Rre(t,e,n,i,r){if(i==null)return;const s=$(i)?i.z??0:0;$(i)&&Ap(i.x)&&Ap(i.y)&&Ap(s)?t.nodes.set(e,n,[i.x,zo(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 Lre(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)&&Pre(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 Pre(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 xre(t,e,n){const i=t.declareEdgeIds(e,s=>$(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(!$(l)||!$(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}Mre(t,{ids:i,kind:r,edgeClassesColumn:n},l,a,o)}}function Mre(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],Rt.data,r);Sk(t,t.edges,l,u,n.classes,r),Ok(t.edges,u,n,r)}catch(a){t.skip(a,"edge",r)}}function Ure(t,e){const{report:n}=t;if(Array.isArray(e)){const i=[],r=[];return e.forEach((s,o)=>{$(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}]`}),($(s)&&!Fre(s)?r:i).push(s)}),{nodes:i,edges:r}}return $(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 Gre(t){const e=new Map,n=t.filter(r=>$(r)&&$(r.data)&&r.data.id===void 0);if(n.length===0)return e;const i=new Set;for(const r of t){const s=$(r)&&$(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 pc(t){return $(t)&&typeof t[Z]=="string"?t[Z]:null}function jre(t){return $(t)&&$(t.position)&&typeof t.position.z=="number"}function Ap(t){return typeof t=="number"&&Number.isFinite(t)}function Fre(t){if(t.group==="nodes")return!0;if(t.group==="edges")return!1;const{data:e}=t;return!($(e)&&z(e,"source")&&z(e,"target"))}function Sk(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 Ok(t,e,n,i){for(const r of Object.keys(n)){if(ote.has(r))continue;const s=QD.has(r)?r:`${r}${Rt.element}`;t.write(e,s,n[r],Rt.data,i)}}const zre=Object.freeze({format:"json",options:Object.freeze(["dialect","edgesKey","edgesPath","indexLinks","nodeIdKey","nodesPath","oboIds","sigmaSettings","sourceKey","targetKey","typedefs"]),extensions:Object.freeze([".json"]),positions:$te,mimeTypes:Object.freeze(["application/json"]),sniff(t){const e=new TextDecoder("utf-8").decode(p0(t).subarray(0,bie)),n=(e.startsWith(_ie)?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("[")&&tk(n)!=="cytoscape"?Math.min(i,.3):i},async import(t,e,n){const i=Qe(n,Ep),r=_p(n),s=new te("json",i.errorLimit),o=await Br(t,s,{...i,bomlessUtf16:!0}),{root:l,dialect:a}=Sp(Op(o,s),r,s);return VO({root:l,dialect:a,text:o},e,s,i,r,n),s.finish()},async listGraphs(t,e){const n=Qe(e,Ep),i=_p(e),r=new te("json",n.errorLimit),s=await Br(t,r,{...n,bomlessUtf16:!0}),{root:o,dialect:l}=Sp(Op(s,r),i,r);return HO(o,l)},async importAll(t,e,n){const i=Qe(n,Ep),r=_p(n),s=new te("json",i.errorLimit),o=await Br(t,s,{...i,bomlessUtf16:!0}),{root:l,dialect:a}=Sp(Op(o,s),r,s),c=HO(l,a).length,d=[];for(let u=0;u<Math.max(c,1);u++){const f=u===0?s:new te("json",i.errorLimit);VO({root:l,dialect:a,text:o},e(u),f,i,{...r,graphIndex:u,all:!0},n),d.push(f.finish())}return d},styles:Cte});function VO(t,e,n,i,r,s){const{root:o,dialect:l,text:a}=t,c=new Pie(e,n,i,r,s?.defaultDirected!==void 0);c.text=a,bt(e,s,n,l==="obographs"),Et(s,n,yie),Wre(c,o,l),n.keepForStyles(c.styleSource??{dialect:l,block:pc(o)}),c.reportDangling(),c.nodes.reportNullOnly(),c.edges.reportNullOnly(),F(i.signal)}function Wre(t,e,n){if(n==="cytoscape"){Cre(t,e);return}const 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":Wie(t,i,n);break;case"jgf":bre(t,i);break;case"graphology":cre(t,i);break;case"vis":Jie(t,i);break;case"adjacency":Zie(t,i);break;case"tree":are(t,i);break;case"obographs":Kre(t,i);break;default:{const r=n;throw new N("E_UNSUPPORTED",`unknown dialect ${r}`,{option:"dialect",found:r})}}}const Nk=new Set(["id","lbl","type","propertyType","meta"]),Ak=new Set(["definition","comments","subsets","xrefs","synonyms","basicPropertyValues","deprecated"]),S0=Object.freeze({CLASS:"Term",INDIVIDUAL:"Instance",PROPERTY:"Typedef"}),Tk=Object.freeze({is_a:"is_a",subPropertyOf:"is_a",type:"instance_of",inverseOf:"inverse_of"}),Ik=new Set(["subPropertyOf","inverseOf"]);class Bre{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}=fe(this.ctx.sink,e,La(e,n),this.ctx.report);return this.handles.set(i,s),s}}const Hre=["logicalDefinitionAxioms","equivalentNodesSets","domainRangeAxioms","propertyChainAxioms"],Yre=new Set(["sub","subj","pred","obj","meta"]);function Vre(t,e){const n=new Map,i=new Set,r=new Set;for(const o of t){if(!$(o)||typeof o.id!="string")continue;if(o.type!=="PROPERTY"){r.add(o.id);continue}i.add(o.id);const l=$k(o.meta).find(a=>uc.get(a.pred)==="shorthand");l!==void 0&&n.set(o.id,l.val)}const s=o=>e==="curie"?Du(o):o;return{id:o=>e==="curie"?n.get(o)??Du(o):o,relation:o=>Tk[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 $k(t,e=null,n=""){if(!$(t)||t.basicPropertyValues===void 0||t.basicPropertyValues===null)return[];const i=`${n}.meta.basicPropertyValues`;if(!Array.isArray(t.basicPropertyValues))return e!==null&&Lt(e,`${i} must be an array; it is dropped`,i),[];const r=[];return t.basicPropertyValues.forEach((s,o)=>{$(s)&&typeof s.pred=="string"&&typeof s.val=="string"?r.push(s):e!==null&&Lt(e,`${i}[${o}] needs a string pred and a string val; it is dropped`,`${i}[${o}]`)}),r}function la(t,e,n){if(e==null)return[];if(!Array.isArray(e))return Lt(t,`${n} must be an array; it is dropped`,n),[];const i=[];return e.forEach((r,s)=>{typeof r=="string"?i.push(r):$(r)&&typeof r.val=="string"?i.push(r.val):Lt(t,`${n}[${s}] is not a string or a { val } record; it is dropped`,`${n}[${s}]`)}),i}function Kre(t,e){const n=Ek(t,e,"OBO Graphs"),i=KO(t,n,"nodes"),r=KO(t,n,"edges"),s=Vre(i,t.json.oboIds),o=new Bre(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++)Xre(t,o,s,i[f],`nodes[${f}]`);const l=ise(t,o,s,r),a={};for(const f of Object.keys(n))f!=="nodes"&&f!=="edges"&&(a[f]=n[f]);for(const f of Hre){const h=n[f];h!=null&&!Array.isArray(h)&&Lt(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 KO(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 Xre(t,e,n,i,r){if(!$(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}):Lt(t,`${r}.id must be a string; the node is skipped`),t.countSkipped("node");return}if(typeof i.type=="string"&&S0[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"){qre(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{Jre(t,e,n,i,c,r)}catch(d){t.report.recordError(d,{element:i.id})}}function qre(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 Jre(t,e,n,i,r,s){const o={},l=(c,d)=>{const u=i[c];typeof u=="string"?e.node(d,r,d==="type"?S0[u]??u:u):u!=null&&Lt(t,`${s}.${c} must be a string`)};l("type","type"),l("lbl","name"),l("propertyType","propertyType");for(const c of Object.keys(i))Nk.has(c)||(o[c]=i[c]);const{meta:a}=i;$(a)?Zre(t,e,n,a,r,o,s):a!=null&&Lt(t,`${s}.meta must be an object`),Object.keys(o).length>0&&e.node("obo.unrecognized",r,o)}function Zre(t,e,n,i,r,s,o){const l=`${o}.meta`;Qre(t,e,i.definition,r,s,l);const a=la(t,i.comments,`${l}.comments`);a.length>0&&e.node("comment",r,a.join(`
179
+ `));const c=la(t,i.subsets,`${l}.subsets`).map(f=>n.id(f));c.length>0&&e.node("subset",r,c);const d=la(t,i.xrefs,`${l}.xrefs`);d.length>0&&e.node("xref",r,d);const u=ese(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&&Lt(t,`${l}.deprecated must be a boolean; it is dropped`,`${l}.deprecated`),tse(t,e,n,i,r,s,o);for(const f of Object.keys(i))Ak.has(f)||(s[`meta.${f}`]=i[f])}function Qre(t,e,n,i,r,s){if($(n)){const o=la(t,n.xrefs,`${s}.definition.xrefs`);typeof n.val=="string"?(e.node("def",i,n.val),e.node("def.xrefs",i,o)):Lt(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&&Lt(t,`${s}.definition must be an object with a val; it is dropped`,`${s}.definition`)}function ese(t,e,n,i){if(n==null)return[];if(!Array.isArray(n))return Lt(t,`${i} must be an array; it is dropped`,i),[];const r=[];return n.forEach((s,o)=>{const l=`${i}[${o}]`;if(!$(s)){Lt(t,`${l} is not an object; it is dropped`,l);return}if(typeof s.val!="string"){Lt(t,`${l} has no string val; it is dropped`,`${l}.val`);return}const a=typeof s.pred=="string"?iJ(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:la(t,s.xrefs,`${l}.xrefs`)};typeof s.synonymType=="string"?c.type=e.id(s.synonymType):s.synonymType!==void 0&&s.synonymType!==null&&Lt(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 tse(t,e,n,i,r,s,o){const l=new Map,a=new Map,c=[];$k(i,t,o).forEach(({pred:u,val:f,meta:h},p)=>{const g=uc.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),Vi[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 Lt(t,e,n){t.report.error("validation-error",L.BAD_VALUE,e,n===void 0?void 0:{element:n})}function nse(t,e,n){const{report:i}=t;for(const r of Object.keys(e))Yre.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 ise(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(lo,h,!0),f};for(let d=0;d<i.length;d++){const u=`edges[${d}]`,f=i[d];if(!$(f)){t.badElement("edge",u);continue}const h=nse(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"&&Ik.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)):Lt(t,`${u} has no pred; its relation is unset`),$(f.meta)?e.edge("meta",_,f.meta):f.meta!==void 0&&f.meta!==null&&Lt(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 or=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"}),Zc=Object.freeze({COLUMN_AS_PROPERTY_VALUE:oy,RELATION_ASSUMED:ly,TYPEDEF_NODES:ay,GRAPH_COLUMN_AS_METADATA:Ju}),rse=Object.freeze({Term:"CLASS",Instance:"INDIVIDUAL",Typedef:"PROPERTY"}),sse=new Map([...uc].map(([t,e])=>[e,t])),ose=Object.freeze({is_a:"is_a",instance_of:"type"}),lse=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"]),ase=["namespace","alt_id","created_by","creation_date","replaced_by","consider"],XO=/^[A-Za-z][A-Za-z0-9+.-]*:\/\//,cse=/^([A-Za-z][A-Za-z0-9.-]*):(.+)$/;function dse(t){const e=t.meta.extra.obographs,n=$(e)?e:{},i={};if($(n.properties))for(const[r,s]of Object.entries(n.properties))$(s)&&(i[r]=s);return{ids:n.ids==="iri"?"iri":"curie",graph:$(n.graph)?n.graph:{},document:$(n.document)?n.document:{},properties:i,propertyEdges:Array.isArray(n.propertyEdges)?n.propertyEdges:[]}}function use(t){if(!$(t)||!Array.isArray(t.basicPropertyValues))return null;for(const e of t.basicPropertyValues)if($(e)&&typeof e.pred=="string"&&uc.get(e.pred)==="shorthand"&&typeof e.val=="string")return e.val;return null}function fse(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.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`${Bf}${l}.owl`}function Qi(t,e){return typeof t=="number"?Number.isFinite(t)?Object.is(t,-0)?"-0":Zf(JSON.stringify(t)):(e.count++,"null"):Array.isArray(t)?`[${t.map(n=>Qi(n,e)).join(",")}]`:$(t)?`{${Object.entries(t).filter(([,n])=>n!==void 0).map(([n,i])=>`${JSON.stringify(n)}:${Qi(i,e)}`).join(",")}}`:JSON.stringify(t)??"null"}function Qc(t,e=!1){return Array.isArray(t)&&(e||t.length>0)&&t.every(n=>typeof n=="string")}function hse(t,e){const n=Se(t,e);return n===void 0?[]:t.dtype==="list"?n.map(r=>nl(r,t.child.dtype)):[t.dtype==="json"||t.meta.components>1?JSON.stringify(n)??"null":nl(n,t.dtype)]}function pse(t){const e=[];for(const n of t.graph){const i=n.dtype==="list"?n.child.dtype:n.dtype;for(const r of bD(Se(n,0)))e.push({pred:n.meta.name,val:typeof r=="string"?r:nl(r,i)})}return e}function gse(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 mse(t,e){let n=0;for(const i of e)for(const r of Se(t,i)??[])n+=r.datatype===null?0:1;return n}class yse{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=dse(e),this.ontologyIri=fse(e,this.kept,n.ontologyIri),this.indent=n.indent!==""?`
180
+ ${n.indent}`:"";for(const[i,r]of Object.entries(this.kept.properties)){const s=use(r.meta);s!==null&&(this.shorthands.set(i,s),this.shorthandIris.set(s,i))}this.folding=Ut(e),this.ends=e.edgeList();for(let i=0;i<e.edgeCount;i++)this.folding.folded(i)||this.written.push(i);if(this.weights=wt(e),this.planIds(),this.planNodes(),this.fatal=_D(e,n.common,{caps:Jf("obographs"),label:this.label,labelAssumed:ra(e.nodes,"label","name").assumed,edgeSlot:"edge meta",note:this.note})??this.emptyIdError(),this.planColumnNotes(),this.planEdges(n.common),SD(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(cy,`${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)??Du(e)}expand(e){if(XO.test(e))return e;const n=cse.exec(e);return n!==null&&!n[1].includes("_")?`${Bf}${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=[ose[e],this.shorthandIris.get(e),this.expand(e),e].filter(o=>o!==void 0&&!Ik.has(o)),r=o=>Tk[o]??this.shorthands.get(o)??Du(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&&!XO.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=ED(e,this.written,{outgoingAllowed:!0,changed:s=>this.changedRows.has(s)});const r=wD(this.frameless,this.written.flatMap(s=>[n[s],i[s]]));r>0&&this.note(Zu,`${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=ra(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 lse){const o=e.nodes.get(s);o!==null&&o!==this.label&&o.meta.role===null&&bse(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&&xa.has(r)||s===lo&&this.rows.every(o=>!i.isSet(o))||(this.properties.push(i),Jb(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(or.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(ay,`${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]]])gse(r,c==="name"?"string":Vi[c].dtype,d);const l=this.placed.get("property_value"),a=l===void 0?0:mse(l,n);a>0&&r(or.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(Ju,`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=ra(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)||$(Se(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&&xa.has(f))continue;this.edgeColumns.push(u);const h=i.filter(p=>u.isSet(p)).length;h>0&&r(or.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(or.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:Se(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(ly,`${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(or.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(Mp,`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(Mp,`${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:Se(i,n)}nodeRecord(e){const n={id:this.iris[e]},i=this.label===null?void 0:Se(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=rse[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($(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),Qi(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 ase){const s=this.at(r,e),o=sse.get(r)??r;for(const l of bD(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:`${nr}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 hse(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:Se(this.metaColumn,e),o=$(s)?{...s}:{};for(const l of this.edgeColumns){const a=Se(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),Qi(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=$(e.graph.meta)?{...e.graph.meta}:{},l=Array.isArray(o.basicPropertyValues)?[...o.basicPropertyValues]:[];return l.push(...pse(n)),l.length>0&&(o.basicPropertyValues=l),Object.keys(o).length>0&&(i.meta=o),Qi(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=Qi(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(Qi(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(Qi(s,this.nonfinite));yield`]${this.graphTail()}]`;const r=Qi(this.kept.document,this.nonfinite);yield r==="{}"?`}
181
+ `:`,${r.slice(1)}
182
+ `}}function Ck(t,e){const n=new yse(t,e);return{notes:n.notes,write:()=>n.write()}}function bse(t,e,n,i){const r=Vi[t];if(!yD(r.dtype,e)||e.meta.components>1)return!1;const s=o=>{switch(t){case"type":return typeof o=="string"&&!Object.hasOwn(S0,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 Qc(o,!0);case"xref":case"alt_id":return Qc(o);case"subset":case"replaced_by":case"consider":return Qc(o)&&o.every(i);case"synonym":return Array.isArray(o)&&o.length>0&&o.every(l=>$(l)&&Object.keys(l).length===("meta"in l?5:4)&&(l.text===null||typeof l.text=="string")&&(l.scope===null||typeof l.scope=="string"&&Pa.has(l.scope))&&(l.type===null||i(l.type))&&Qc(l.xrefs,!0));case"property_value":return Array.isArray(o)&&o.length>0&&o.every(l=>$(l)&&Object.keys(l).length===3&&i(l.relation)&&!uc.has(String(l.relation))&&typeof l.value=="string"&&(l.datatype===null||typeof l.datatype=="string"));case"obo.unrecognized":return $(o)&&Object.keys(o).every(l=>l.startsWith("meta.")?!Ak.has(l.slice(5))&&l.length>5:!Nk.has(l));default:return!1}};return n.every(o=>!e.isSet(o)||s(Se(e,o)))}const gr=Object.freeze({NONFINITE_AS_NULL:cy,DIRECTION_DROPPED:Mp,MUTUAL_EXPANDED:w.MUTUAL_EXPANDED,NUMERIC_IDS_STRINGIFIED:"W_NUMERIC_IDS_STRINGIFIED",ID_TEXT_COLLISION:w.ID_TEXT_COLLISION,NODE_ORDER:Zu,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:or.EDGE_COLUMN_AS_META,OBOGRAPHS_ID_CHANGED:or.ID_CHANGED,OBOGRAPHS_DATATYPE_DROPPED:or.DATATYPE_DROPPED,OBOGRAPHS_TYPE_GAINED:or.TYPE_GAINED,COLUMN_AS_PROPERTY_VALUE:Zc.COLUMN_AS_PROPERTY_VALUE,RELATION_ASSUMED:Zc.RELATION_ASSUMED,TYPEDEF_NODES:Zc.TYPEDEF_NODES,GRAPH_COLUMN_AS_METADATA:Zc.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:uk}),Ese=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"]),_se=new Set(["start","end","timestamp","timestamps","spells","open","spellsOpen"]),Sse=new Set(["jgf","cytoscape","graphology"]);function Ose(t,e){const n=e??{},i=dt(e),r=ite(t.meta);let s;if(n.dialect===void 0||JA("json",n.dialect))s=r.dialect??"node-link";else if(JD(n.dialect))({dialect:s}=n);else throw Am("dialect",n.dialect,d0);const o=iT(n.indent,""),l=r.dialect===s,a=(y,b)=>l&&y!==void 0?y:b,c=wo("edgesKey",n.edgesKey)??a(r.edgesKey,s==="d3"?"links":"edges");let d;n.nodeIdKey!==void 0?d=wo("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 Am("indexLinks",u,["true","false"]);d===null&&(u=!0);const f=wo("sourceKey",n.sourceKey)??a(r.sourceKey,s==="vis"?"from":"source"),h=wo("targetKey",n.targetKey)??a(r.targetKey,s==="vis"?"to":"target"),{weightOrigin:p}=t.meta,g=wo("weightKey",n.weightKey)??(p!==null&&p.format==="json"&&p.id!==null?p.id:"weight"),m=wo("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 wo(t,e){if(e===void 0)return null;if(typeof e!="string"||e.length===0)throw Am(t,e,["a non-empty key"]);return e}function Am(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 Tm(t,e,n){return Number.isFinite(t)?Zf(e?lt(t):je(t)):(n.count++,"null")}function lr(t,e,n){switch(typeof t){case"number":return Tm(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=>lr(s,e,n)).join(",")}]`;const i=JSON.stringify(t);return i===void 0?"null":i}function O0(t,e,n,i){switch(t.dtype){case"list":return lr(t.sliceOf(e),t.child.dtype==="f32",i);case"json":return lr(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 lr(t.value(e),!1,i);case"f32":return lr(t.value(e),!0,i);default:return lr(t.value(e),!1,i)}}function Nse(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 gc{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!==""?`
183
+ ${this.indent.repeat(this.depth)}`:""}}function vk(t,e){const{dialect:n}=e,i=Jf(n),r=Un(t,i,e.common,{roles:Ese[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:Tse(t,e),nonfinite:{count:0}},l=Tp(o,t.nodes,"node"),a=Tp(o,t.edges,"edge"),c=i.graphAttributes?Tp(o,t.graph,"graph"):[];Ase(r,[...l,...a]);const d=Cse(o,a);o.nonfinite.count>0&&s(gr.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}=vse(o),h=t.flags.multigraph||t.meta.declaredMultigraph===!0;n==="jgf"&&kse(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 Ase(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 Tse(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 Tp(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)||_se.has(d)))continue;n!=="graph"&&(t.nonfinite.count+=Nse(a));const f=Ise(t,a,n);if(f!==null){f!==Im&&s.push(f);continue}let h=c.name,p="attribute";if(Sse.has(i)&&n!=="graph"&&(h.endsWith(Rt.element)?(h=h.slice(0,-Rt.element.length),p="element"):i==="cytoscape"&&QD.has(h)?p="element":h.endsWith(Rt.data)&&(h=h.slice(0,-Rt.data.length))),p==="attribute"&&o.has(h)){r(gr.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(gr.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),$se(t,a,n,u),s.push({column:a,key:h,slot:p})}return s}const Im=Symbol("skipped");function Ise(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 Im}if(o==="position"&&n==="node"){if(i==="cytoscape"&&(e.dtype==="f32"||e.dtype==="f64")&&s.components>=2){const a=Dse(e);return a>0&&r(gr.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):Im: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 $se(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 Cse(t,e){const{snapshot:n,nonfinite:i}=t,r=wt(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:Zf(o)}}function vse(t){const{snapshot:e,dialect:n,caps:i,note:r}=t,s=Ut(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&&gl(e)>0&&t.resolved.common.onMixedDirection==="undirected"&&(o=!1),n==="cytoscape"||n==="vis"||n==="d3"){const l=ZD[n];o!==l&&r(gr.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 Dse(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 kse(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),Rse(f)){o++;const h=Number(f);(c||h<=l)&&(a=!1),l=h}else c=!0}r>0&&e(gr.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(gr.ID_TEXT_COLLISION,`${s} node id${O(s)} ${C(s,"shares","share")} their text with another id; the save fails`,null,s),a||e(gr.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 Rse(t){return/^(0|[1-9]\d*)$/.test(t)&&Number(t)<4294967295}function*Lse(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===gr.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*Mse(t,e);return;case"vis":yield*Use(t,e);return;case"graphology":yield*Gse(t,e);return;case"jgf":yield*jse(t,e);return;case"cytoscape":yield*Fse(t,e);return;default:{const i=n;throw new N("E_UNSUPPORTED",`unknown dialect ${i}`,{option:"dialect",found:i})}}}function qe(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=Pse(r.column),a=Array.from(o).slice(0,l);s=lr(a,r.column.dtype==="f32",t.nonfinite);break}case"classes":s=JSON.stringify(r.column.sliceOf(n).join(" "));break;default:s=O0(r.column,n,t.ids,t.nonfinite);break}t.w.member(r.key,s)}}const gn=new Set(["attribute","position"]),al=new Set(["element","classes"]);function Pse(t){const e=t.meta.extra.sourceDims;return typeof e=="number"&&e>=1&&e<=t.meta.components?e:t.meta.components}function xu(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":Zf(String(t)):JSON.stringify(t)}function nh(t,e,n){const i=t.edgeIds;return i?.isSet(e)?O0(i,e,n.ids,n.nonfinite):null}function mc(t,e){const{folding:n}=t;return n.folded(e)?"skip":t.directed?n.sourceDirected(e)?"directed":Jf(t.resolved.dialect).mixedDirection?"undirected":t.resolved.common.onMixedDirection==="directed"?"directed":"undirected":"undirected"}function ih(t,e){t.w.open("{");for(const n of e.graph)n.column.isSet(0)&&t.w.member(n.key,O0(n.column,0,t.ids,t.nonfinite));t.w.close("}")}function xse(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*Mse(t,e){const{resolved:n}=e,i={w:new gc(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"),ih(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))),qe(i,e.nodes,s,gn),r.close("}"),yield r.take();r.close("]"),r.key(n.edgesKey),r.open("[");for(let s=0;s<t.edgeCount;s++){if(mc(e,s)==="skip")continue;const[l,a]=xse(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),qe(i,e.edges,s,gn),r.close("}"),yield r.take()}r.close("]"),N0(i,e),r.close("}"),yield r.take()}function N0(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*Use(t,e){const{resolved:n}=e,i={w:new gc(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))),qe(i,e.nodes,o,gn),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");for(let o=0;o<t.edgeCount;o++){if(mc(e,o)==="skip")continue;const l=t.edgeList();r.item(),r.open("{");const a=nh(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),qe(i,e.edges,o,gn),r.close("}"),yield r.take()}r.close("]"),N0(i,e),r.close("}"),yield r.take()}function*Gse(t,e){const{resolved:n}=e,i={w:new gc(n.indent),ids:t.ids,nonfinite:{count:0}},{w:r}=i;let s;e.directed?s=gl(t)>0?"mixed":"directed":s="undirected",r.open("{"),r.key("attributes"),ih(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))),xu(e.nodes,o,gn)&&(r.key("attributes"),r.open("{"),qe(i,e.nodes,o,gn),r.close("}")),qe(i,e.nodes,o,al),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");for(let o=0;o<t.edgeCount;o++){const l=mc(e,o);if(l==="skip")continue;const a=t.edgeList();r.item(),r.open("{");const c=nh(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||xu(e.edges,o,gn))&&(r.key("attributes"),r.open("{"),d!==null&&r.member(n.weightKey,d),qe(i,e.edges,o,gn),r.close("}")),qe(i,e.edges,o,al),r.close("}"),yield r.take()}r.close("]"),r.close("}"),yield r.take()}function*jse(t,e){const{resolved:n}=e,i={w:new gc(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"),ih(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("{"),qe(i,e.nodes,l,s),xu(e.nodes,l,gn)&&(r.key("metadata"),r.open("{"),qe(i,e.nodes,l,gn),r.close("}")),qe(i,e.nodes,l,al),r.close("}"),yield r.take();r.close("}"),r.key("edges"),r.open("[");for(let l=0;l<t.edgeCount;l++){const a=mc(e,l);if(a==="skip")continue;const c=t.edgeList();r.item(),r.open("{");const d=nh(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])))),qe(i,e.edges,l,o),e.directed&&a==="undirected"&&r.member("directed","false"),qe(i,e.edges,l,s);const u=e.weights(l);(u!==null||xu(e.edges,l,gn))&&(r.key("metadata"),r.open("{"),u!==null&&r.member(n.weightKey,u),qe(i,e.edges,l,gn),r.close("}")),qe(i,e.edges,l,al),r.close("}"),yield r.take()}r.close("]"),r.close("}"),r.close("}"),yield r.take()}function*Fse(t,e){const{resolved:n}=e,i={w:new gc(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))),qe(i,e.nodes,l,s),qe(i,e.nodes,l,gn),r.close("}"),zse(i,e,l),qe(i,e.nodes,l,al),r.close("}"),yield r.take();r.close("]"),r.key("edges"),r.open("[");const o=Bse(t,e);for(let l=0;l<t.edgeCount;l++){if(mc(e,l)==="skip")continue;const a=t.edgeList();r.item(),r.open("{"),r.key("data"),r.open("{"),r.member("id",nh(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),qe(i,e.edges,l,gn),r.close("}"),qe(i,e.edges,l,al),r.close("}"),yield r.take()}r.close("]"),r.close("}"),e.graph.some(l=>l.column.isSet(0))&&(r.key("data"),ih(i,e)),Wse(i,e),N0(i,e),r.close("}"),yield r.take()}function zse(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",Tm(s[0],o,t.nonfinite)),i.member("y",Tm(zo(s[1]),o,t.nonfinite)),i.close("}")}}function Wse(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,lr(i[s],!1,t.nonfinite));r!==null&&n.member("style",lr(r,!1,t.nonfinite))}function Bse(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 qO(t,e){const n=e.styled?.snapshot??t;return e.dialect==="obographs"?Ck(n,e).write():Lse(n,vk(n,e))}function Ip(t,e){const n=Ose(t,e),i=iie(t,n.dialect,e?.styles);return i===null?n:{...n,styled:i}}const Hse=Object.freeze({format:"json",options:Object.freeze(["dialect","edgesKey","indent","indexLinks","nodeIdKey","ontologyIri","sourceKey","targetKey","weightKey"]),capabilities:Jf("node-link"),styles:Object.freeze({capabilities:dk}),check(t,e){const n=Ip(t,e),i=n.styled?.snapshot??t,r=n.dialect==="obographs"?Ck(i,n).notes:vk(i,n).notes;return Object.freeze([...r,...n.styled?.notes??[]])},export(t,e){return ei(qO(t,Ip(t,e)))},exportToString(t,e){return ti(qO(t,Ip(t,e)))}}),Yse=new Set(["ID","LABEL","START_ID","END_ID","TYPE","IGNORE"]),Vse=new Set(["ID","START_ID","END_ID"]),Kse=/^[^:{}()]*:\s*(ID|START_ID|END_ID)\s*(\(|\{|$)/i,Xse=/^([^:(){}]*)(?::([^:(){}]*))?(?:\(([^)]*)\))?(?:\{([^}]*)\})?$/;function Dk(t,e,n){let i=!1;for(let r=0;r<e;r++){const s=t[r];if(s.includes(":")&&Kse.test(s.trim())){if(n?.[r]!==!0)return!0;i=!0}}return i&&n!==void 0&&qse(t,e,n)}function qse(t,e,n){for(let i=0;i<e;i++){if(!n[i])return!1;try{kk(t[i])}catch{return!1}}return!0}function kk(t){const e=t.trim(),n=Xse.exec(e);if(n===null)throw Fi(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=Qse(t,n[4]);if(r===null)return Jse(t,i,s,o);if(r.length===0)throw Fi(t,"an empty field type");const l=r.toUpperCase();if(Yse.has(l))return Zse(t,i,l,s,o);if(i.length===0)throw Fi(t,"a property column needs a name");if(s!==null)throw Fi(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 Jse(t,e,n,i){if(e.length===0)throw Fi(t,"an empty header cell");if(n!==null||i.size>0)throw Fi(t,"an id space or options need a field type");return{text:t,name:e,kind:"PROPERTY",type:null,space:null,options:i}}function Zse(t,e,n,i,r){if(i!==null&&!Vse.has(n))throw Fi(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 Fi(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 Qse(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 Fi(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 Fi(t,"an option needs a key");n.set(s,o)}return n}function Fi(t,e){return new N("E_UNSUPPORTED",`header cell "${t}": ${e}`,{reason:"header",cell:t,detail:e})}function cs(t,e,n){const i=`${t}:${e}`;return n===null?i:`${i}(${n})`}const Rk="labels",Lk="type",Pk="idSpace",eoe="originalId",$m="E_NEO4J_HEADER",Cm="E_NEO4J_COLUMN_COUNT",xk=at,Mk=Jn,Uk=sn,Gk="E_NEO4J_ID_SPACE_COLLISION",jk="E_NEO4J_ENDPOINT_SPACE",Fk=Rn,vm="W_NEO4J_HEADER_OPTION_IGNORED",zk=yn,Wk="W_NEO4J_MISSING_TYPE",Bk="W_NEO4J_SECTION_KIND",Hk=Ki,toe="W_NEO4J_IGNORED_COLUMNS",noe=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightFrom","weightDtype","long","errorLimit","signal","onProgress"]),ts="neo4j",ioe=64,roe={name:Rk,dtype:"list",itemDtype:"dict",nullable:!0,role:"labels",origin:{format:ts,id:":LABEL",title:null,type:"LABEL",namespace:null}},soe={name:Lk,dtype:"dict",nullable:!0,role:"kind",origin:{format:ts,id:":TYPE",title:null,type:"TYPE",namespace:null}},ooe={name:Pk,dtype:"dict",nullable:!0,role:"idSpace",origin:{format:ts,id:":ID",title:null,type:"ID",namespace:null}},loe={name:eoe,dtype:"string",nullable:!0,origin:{format:ts,id:":ID",title:null,type:null,namespace:null}},aoe={";":"semicolon",",":"comma","|":"pipe"},coe=Object.freeze([","," "]);function doe(t){const e=t??{},n=e.arrayDelimiter??";",i=aoe[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=Oy({delimiter:e.delimiter??null,quote:e.quote??'"',candidates:coe.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:JO("nodes",e.nodes),relationships:JO("relationships",e.relationships),syntax:r,listSyntax:i}}function JO(t,e){if(e==null)return[];const n=Array.isArray(e)?e:[e];for(const i of n)if(!kA(i))throw new N("E_UNSUPPORTED",`option ${t}: an entry is not an ImportInput`,{option:t,found:typeof i});return n}class uoe{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 foe{constructor(e,n){this.offset=0,this.lastDone=0,this.callback=e;let i=0;for(const r of n){const s=mP(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 hoe{constructor(e,n,i,r){this.registry=new uoe,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 Qn(e,n,i.onMixedDirection)}async run(e){const n=new foe(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(toe,`${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 aT(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||Dk(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>=ioe&&(c=0,F(n.signal))}}return l===0&&i===null&&!r&&this.report.fail($m,"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(kk(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 Lr("a header mixes :ID with :START_ID / :END_ID");if(!c&&!d){const f=r.some(h=>h.name==="_id"||h.name==="_start");throw Lr(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",Bk,`a ${c?"node":"relationship"} header in a file given as ${this.expectedKind==="node"?"nodes":"relationships"}; read by its header`,{line:i}),Soe(r),this.ignoredColumns+=(s.get("IGNORE")??[]).length,c){if(o.length>1)throw Lr("a node header has more than one :ID column");if(s.has("TYPE"))throw Lr("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 Lr("a relationship header needs exactly one :START_ID and one :END_ID column");if(s.has("LABEL"))throw Lr("a relationship header cannot have a :LABEL column");const u=s.get("TYPE")??[];if(u.length>1)throw Lr("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 tt)){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($m,`${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",vm,`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:ts,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",vm,`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:ts,id:n.name,title:null,type:n.type,namespace:null,listSyntax:a,long:this.common.long};let d=pa(c),u={...d.decl,...r},f;try{f=ko(o,e,u)}catch(h){if(!(h instanceof N)||h.code!=="E_COLUMN_EXISTS")throw h;d=pa({...c,taken:Zd(o,e)}),u={...d.decl,...r,name:d.decl.name},f=ko(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",roe))}ensureType(){this.typeHandle===A&&(this.typeHandle=this.declareReserved("edge",soe))}ensureIdSpace(){this.idSpaceHandle===A&&(this.idSpaceHandle=this.declareReserved("node",ooe),this.originalIdHandle=this.declareReserved("node",loe))}declareReserved(e,n){const{sink:i,report:r}=this;let s=n;for(;;)try{return ko(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,Zd(i,e));r.warning("coercion",Za,`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",zk,`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",Cm,`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",xk,"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=$p(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",Gk,`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",Uk,`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 tt)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",Hk,`${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",Cm,`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",Mk,`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=$p(h,e.startSpace),m=$p(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",jk,`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=Vn(o[e.weightCell],this.report)}catch(I){s.recordError(I,{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((I,T)=>(T===0||I!==g)&&r.indexOf(I)===A);let S;try{S=this.direction.addEdge(g,m,"directed",b,{line:a,element:f})}catch(I){s.recordError(I,{line:a,element:f}),s.counts.skippedEdges++;return}for(const I of _)s.counts.nodes++,this.placeholders.push({id:I,index:r.indexOf(I)});if(e.typeCell>=0){const I=o[e.typeCell];I.length>0?this.guarded(a,f,()=>{r.setEdgeValue(this.typeHandle,S,I)}):s.warning("missing-value",Wk,"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",Fk,`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]?_oe(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}Eoe(u,o[c.cell],d)&&this.overflows.push(c.name),u.precision&&Jd(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=jp(o,s);i[e.cell]=l.value,r[e.cell]=o===n?l.text:n}else i[e.cell]=ga(n,s,this.options.listSyntax),yoe(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=yy(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",ie,`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",ie,`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 ha(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 $p(t,e){return e===null?t:`${e}:${String(t)}`}const poe={byte:[-128,127],short:[-32768,32767]};function goe(t){if(moe.test(t))return!0;const e=/^[+-]?P([^T]*)(?:T(.*))?$/i.exec(t);return e===null||e[2]===""||e[1]===""&&e[2]===void 0?!1:ZO(e[1],"YMWD")&&ZO(e[2]??"","HMS")}const moe=/^[+-]?P\d{4}-?\d{2}-?\d{2}T\d{2}:?\d{2}:?\d{2}(?:\.\d+)?$/i;function ZO(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 yoe(t,e,n){const i=t.declared.trim().toLowerCase().replace(/\[\]$/,""),r=t.list&&Array.isArray(e)?e:[e],s=poe[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"&&!goe(o.trim())),l){const a=s===void 0?"":` (${s[0]} to ${s[1]})`;throw new N("E_COLUMN_TYPE",`"${n}" is not ${AA(i)}${a}`,{value:n,kind:i})}}}const boe=34028234663852886e22;function Eoe(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)>boe))}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=Do(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 _oe(t){if(t.list)return[];if(t.kind==="string"||t.kind==="duration")return""}function Soe(t){const e=new Set;for(const n of t)if(!(n.name.length===0||n.kind==="IGNORE")){if(e.has(n.name))throw Lr(`property "${n.name}" is declared twice`);e.add(n.name)}}function Lr(t){return new N("E_UNSUPPORTED",t,{reason:"header"})}function Ooe(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 Dk(r,r.length)?.95:0}const Noe=Object.freeze({format:ts,options:Object.freeze(["arrayDelimiter","delimiter","nodes","quote","relationships"]),extensions:Object.freeze([".csv",".tsv"]),mimeTypes:Object.freeze(["text/csv","text/tab-separated-values"]),sniff:Ooe,async import(t,e,n){const i=Qe(n,{ids:"canonical",defaultDirected:!0,weightFrom:"weight"}),r=doe(n),s=new te(ts,i.errorLimit);bt(e,n,s),Et(n,s,noe);const o=new hoe(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()}}),Dm="W_NEO4J_UNDIRECTED_AS_DIRECTED",Yk=os,Aoe=EA,Vk="E_NEO4J_WEIGHT_COLUMN_TAKEN",Kk="E_NEO4J_ID_COLUMN_TAKEN",Xk="W_NEO4J_MULTIPLE_ID_PROPERTIES",Toe="W_NEO4J_DECLARED_TYPE_CHANGED",Ioe="W_NEO4J_ARRAY_DELIMITER",$oe=new Set(["kind","labels","idSpace"]),Ba="neo4j",qk="ID",Coe="weight",voe=Object.freeze({kind:Lk,labels:Rk,idSpace:Pk}),km=Xe({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}),Doe=new Set(["directed","pair","mutual","weight","timeText","originalId","parent","parents","start","end","timestamp","timestamps","spells","open","spellsOpen"]),koe=new Set([w.MIXED_DIRECTION,w.MIXED_DIRECTION_ERROR,w.MULTI_EDGES,w.SELF_LOOPS,w.EDGE_IDS_GENERATED,w.EDGE_IDS_DROPPED,Dm,Vk]),Roe=new Set([w.ID_MANGLED,w.ID_CHARSET,w.ID_RENUMBERED,Yk,Kk,Xk]),Loe=new Set([";",",","|"]),Poe=new Set(["all","nodes","relationships"]);function xoe(t,e){const n=t??{},i=n.part??"all";if(!Poe.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(!Loe.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={...Oy({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 Moe{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=>Uoe(o.meta))??null,this.labels=e.nodes.byRole("labels"),this.kind=e.edges.byRole("kind");for(const o of e.nodes)QO(o.meta)&&this.idColumns.push(o);const r=Un(e,km,i,{roles:$oe,roleNames:voe,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=Ut(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(Dm,`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(Dm,`${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&&Doe.has(d)||e==="node"&&(QO(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:py(Ba,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:eN(r),kind:tN(s),temporal:s.temporal}:nN(f);s!==null&&s.list&&s.kind==="long"&&f==="f64"&&(p=this.integralOrDouble(e,eN(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:cs(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:tN(s),temporal:s.temporal}:l=nN(i.dtype);const c=i.role==="position"||i.role!==null&&Goe(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"&&!km.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:cs(i.name,`${l.type}[]`,null),scalar:l,list:!0,companion:n};const u=r===null&&i.origin?.format===Ba&&i.dtype==="string"?i.name:cs(i.name,l.type,null);return{column:e,header:u,scalar:l,list:!1,companion:n}}integralOrDouble(e,n,i){return Boe(e)?{type:n,kind:"integer",temporal:null}:(this.note(Toe,`${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(td(l,n,null).includes(r)){s++;break}}s>0&&this.note(Ioe,`${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=wt(e),r=this.edgeColumns.find(s=>s.column.meta.name===n);return r!==void 0&&i.weighted?(this.note(Vk,`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===Coe&&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++)Qd(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):Qd(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(Yk,`${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(Aoe,`${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(Kk,`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(Xk,`${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"?koe.has(r.code)?!1:r.column===null||!n.edges.has(r.column)||n.nodes.has(r.column):Roe.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?nd(n,e):Foe(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=[cs(e,qk,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)}
184
+ `,file:{kind:"nodes",name:iN("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)}
185
+ `}*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=[cs("","START_ID",e),cs("","END_ID",n)];this.kind!==null&&r.push(":TYPE"),this.weights!==null&&r.push(cs(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)}
186
+ `,file:{kind:"relationships",name:iN("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)?nd(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)}
187
+ `}cell(e){if(e===null)return"";const{quote:n}=this.options.syntax;return e.length===0?n+n:ff(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):nd(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)?nd(s,n):null;return td(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(td(a,r,null));else o.push(td(l,r,null));return o.join(this.options.arrayDelimiter)}}function Uoe(t){return t.role===null&&t.dtype==="string"&&t.origin!==null&&t.origin.format===Ba&&t.origin.id===":ID"&&t.origin.type===null}function QO(t){return t.role===null&&t.dtype==="string"&&t.origin!==null&&t.origin.format===Ba&&t.origin.type===qk}function Goe(t){return t==="color"||t==="size"||t==="shape"||t==="thickness"}function eN(t){const e=t.trim();return e.endsWith("[]")?e.slice(0,-2):e}function tN(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 nN(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 ed(t,e){return typeof t=="number"?e(t):String(t)}function td(t,e,n){switch(e.kind){case"integer":return ed(t,Ue);case"float":return ed(t,lt);case"double":return ed(t,je);case"boolean":return t===!0?"true":"false";case"string":return String(t);case"temporal":return n??ed(t,i=>e.temporal===null?String(i):fa(i,e.temporal));case"point":return joe(t);case"json":return JSON.stringify(t)??"";default:{const i=e.kind;throw new N("E_UNSUPPORTED",`unknown cell kind ${i}`,{kind:i})}}}function joe(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}:${je(i)}`);else if(typeof i=="string")e.push(`${n}:'${i.replaceAll("'","")}'`);else return JSON.stringify(t)??"";return`{${e.join(", ")}}`}function Foe(t){return typeof t=="string"?t:Number.isInteger(t)?Ue(t):String(t)}function nd(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 zoe=Object.freeze({format:Ba,options:Object.freeze(["arrayDelimiter","delimiter","idColumn","part","quote","weightColumn"]),capabilities:km,check(t,e){return Object.freeze([...Cp(t,e).notes])},export(t,e){return ei(Cp(t,e).lines())},exportToString(t,e){return ti(Cp(t,e).lines())}});function iN(t,e,n){return[t,e??"",n??""].filter(r=>r!=="").join("-").replaceAll(/[^\w.-]/g,"_")}function Cp(t,e){return new Moe(t,xoe(e,Woe(t)),dt(e))}function Woe(t){const n=t.meta.extra?.neo4j?.weightProperty;return typeof n=="string"&&n!==""?n:null}function Boe(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:ny,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,CSV_UNCLOSED_QUOTE:wy,CSV_QUOTE:_y,HEADER:$m,COLUMN_COUNT:Cm,MISSING_ID:xk,MISSING_ENDPOINT:Mk,DUPLICATE_NODE:Uk,ID_SPACE_COLLISION:Gk,ENDPOINT_SPACE:jk,ID_MERGED:Fk,HEADER_OPTION_IGNORED:vm,UNKNOWN_ATTR_TYPE:Zt,PRECISION:ie,COLUMN_RENAMED:ln,ROLE_TAKEN:zk,OPTION_IGNORED:Jt,SINK_OPTION:Ln,MISSING_TYPE:Wk,SECTION_KIND:Bk,DANGLING_REFERENCE:Hk});const Hoe=Object.freeze({n:`
188
+ `,t:" ",W:" "});function Tt(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+=Hoe[r]??r}}return e}function Jk(t,e){let n=0;for(let i=e-1;i>=0&&t.charAt(i)==="\\";i--)n++;return n%2===1}function Yoe(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 Voe(t){return t.endsWith("\\")&&!Jk(t,t.length-1)}function Koe(t){for(let e=0;e<t.length;e++){if(t.charAt(e)==="\\"){e++;continue}if(t.charAt(e)===":")return{tag:Tt(t.slice(0,e).trim()),rest:t.slice(e+1).trimStart()}}return null}const rN=String.raw`\"!`,sN=String.raw`\"[]{}`;function Rm(t){let e=!1;const n=[-2,-2,-2];let i=Mu(t,0,rN,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=Mu(t,r==="\\"?i+2:i+1,rN,n)}return t.trimEnd()}function Mu(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 Wl(t){if(!t.endsWith("}"))return{value:t,qualifiers:null,badBlock:null};const e=Xoe(t),n=[];let i=t.length,r=null;for(;i>0&&t.charAt(i-1)==="}"&&!Jk(t,i-1);){const o=e.get(i-1)??-1,l=o<0?null:Joe(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]))Zk(s,l,a)}return{value:t.slice(0,i),qualifiers:s,badBlock:r}}function Xoe(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 qoe(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 Zk(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 Joe(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=Tt(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=A0(t,n+1);if(a<0)return null;l=Tt(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=Tt(t.slice(n,a).trim()),n=a}Zk(e,o,l),r=!0}return r?e:null}function A0(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 Bl(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=A0(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:Tt(t.slice(i+1,l))+c,unterminated:o<0}),i=a;continue}if(r==="["){const o=Zoe(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:Tt(t.slice(i,Math.min(s,n))),unterminated:!1}),i=s}return e}function Zoe(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 Qk(t){const{value:e,qualifiers:n}=Wl(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=Tt((i<0?e:e.slice(0,i)).trim());if(r.length===0)return null;let s=null,o=!1;if(i>=0){const l=A0(e,i+1);o=l<0,s=Tt(e.slice(i+1,l<0?e.length:l))}return{id:r,description:s,qualifiers:n,unterminated:o}}function oN(t){const e=[];let n=!1,i=0,r=0;const s=o=>{const l=Qk(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 Qoe(t){let e=!1,n=!1;const i=[-2,-2,-2,-2,-2,-2];let r=Mu(t,0,sN,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=Mu(t,s==="\\"?r+2:r+1,sN,i)}return!1}const ele=/\r\n|\r|\f/g;function tle(t){return t.includes("\r")||t.includes("\f")}function mr(t){return t.replaceAll(ele,`
189
+ `).replaceAll(/[\\"\n\t]/g,e=>{switch(e){case`
190
+ `:return String.raw`\n`;case" ":return String.raw`\t`;default:return`\\${e}`}})}function ao(t){return mr(t).replaceAll(/[!{}[\],]/g,e=>`\\${e}`)}function co(t){return t.length>0&&!eR.test(t)}const eR=/[\s!{}\p{Cc}]/u;function en(t){const e=t.replaceAll(/[\\"]/g,n=>`\\${n}`);return e.startsWith("[")?`\\${e}`:e}function rh(t){return t.length>0&&t===t.trim()&&!/[=",{}[\]!\\\n\r\t\f]/.test(t)}function T0(t){return t.length===0?"":` {${t.map(([n,i])=>`${n}="${mr(i)}"`).join(", ")}}`}const H=Object.freeze({...xn,...Pn,EMPTY_INPUT:Mt,INVALID_UTF8:Kt,INVALID_ENCODING:rn,ENCODING_FALLBACK:on,UNKNOWN_ENCODING:bn,MISSING_ID:at,BAD_VALUE:ne,DUPLICATE_NODE:sn,DUPLICATE_ATTRIBUTE:de,UNKNOWN_ELEMENT:$t,DANGLING_REFERENCE:Ki,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:Za,ROLE_TAKEN:yn,OPTION_IGNORED:Jt,SINK_OPTION:Ln}),nle=new Set(["ids","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","weightDtype","errorLimit","signal","onProgress","encoding","restoreMangledIds"]),ile="graphty:originalId",rle={ids:"keep",defaultDirected:!0,weightFrom:null},tR=64,lN=4096,vp=new Set(["Term","Typedef","Instance"]),sle=/^(import|typeref|id-mapping|default-relationship-id-prefix|owl-axioms|treat-xrefs-as-.*)$/,ole=new Map([["typeref","import"],["version","data-version"]]),nR=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]]]),lle=new Set(["is_a","instance_of","disjoint_from","inverse_of","union_of","intersection_of"]),sh=new Set(["name","namespace","comment","created_by","creation_date","domain","range","inverse_of"]),oh=new Set(Object.keys(Vi).filter(t=>Vi[t].dtype==="bool")),yc=new Set(["alt_id","subset","replaced_by","consider","union_of","equivalent_to","disjoint_from","transitive_over","disjoint_over"]),ale=new Set(["format-version","data-version","version","date","saved-by","auto-generated-by","default-namespace","ontology","default-relationship-id-prefix"]),cle=/^(GO_)?1\.[024]$/,dle=new Set([...yc,"is_a","instance_of","relationship","intersection_of"]),ule=100;function iR(t){for(const e of t)if(e<" "&&e!==" "&&e!==`
191
+ `&&e!=="\f"&&e!=="\r"||e==="")return!0;return!1}function aN(t){return t.length>0&&!iR(t)&&!/[\s{}"<>[\]()]/.test(t)}function To(){return Object.create(null)}function id(t,e,n){Object.hasOwn(t,e)?t[e].push(n):t[e]=[n]}const Uu=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 fle(t){const e=t?.obsolete??"keep",n=t?.typedefs??"metadata";if(e!=="keep"&&e!=="drop")throw cN("obsolete",e,["keep","drop"]);if(n!=="metadata"&&n!=="nodes")throw cN("typedefs",n,["metadata","nodes"]);return{obsolete:e,typedefs:n}}function cN(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 hle{constructor(e,n,i){this.header=To(),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=Koe(Rm(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",H.SYNTAX,o,"line",n);return}const s={tag:r.tag,value:Rm(r.rest),line:n};this.frame===null?(aN(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&&!vp.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",H.SYNTAX,a,`[${r}]`,n)}const l=vp.has(r)||o&&/^[A-Za-z]/.test(r)&&aN(r);return l||(this.firstBadLine??=n),this.startFrame(r,n,l),!0}startFrame(e,n,i){this.finishFrame(),this.frameSeen||=i;const r=vp.has(e)?e:null;r===null&&this.tally("validation-error",H.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){id(this.header,e.tag,e.value);const{tag:n}=e;ale.has(n)&&this.header[n].length>1&&this.tally("validation-error",H.DUPLICATE_ATTRIBUTE,"a single-valued header tag given twice; the first is kept",n,e.line);const i=Bl(Wl(e.value).value),r=i.length>0&&i[0].kind==="word"?i[0].text:null;if(n==="format-version")this.version??=Tt(e.value).trim();else if(n==="default-namespace")this.defaultNamespace??=r;else if((n==="subsetdef"||n==="synonymtypedef")&&r===null)this.tally("parse-error",H.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"&&Pa.has(l.text));this.synonymTypes.set(r,o?.text??null)}const s=ole.get(n);s!==void 0&&this.tally("coercion",H.DEPRECATED_TAG,`the 1.0 header tag is read as ${s}`,n,e.line),sle.test(n)&&this.tally("unsupported",H.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=To();for(const c of e.clauses)id(a,c.tag,c.value);this.unknownFrames.push({type:e.name,clauses:a});return}++this.framesSinceCheck>=tR&&(this.framesSinceCheck=0,F(this.signal));const n=e.clauses.findIndex(a=>a.tag==="id"),i=n<0?null:Wl(e.clauses[n].value),r=i===null?"":i.value.trim(),s=Tt(r).trim(),o=e.kind!=="Typedef"||this.typedefsAsNodes;if(s.length===0){this.report.error("missing-value",H.MISSING_ID,`a [${e.kind}] frame has no id; it is skipped`,{line:e.line}),o&&this.report.counts.skippedNodes++;return}if(Bl(r).length>1||iR(s)){this.report.error("validation-error",H.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",H.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",H.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",H.ID_KIND_CLASH,`an id names both a ${s.kind} and an ${e}; the ${s.kind} is the node`,n,i):this.tally("merged",H.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:To()};return r.set(n,o),o}clauseParts(e){let{tag:n}=e,i=null;const r=nR.get(n);r!==void 0&&(this.tally("coercion",H.DEPRECATED_TAG,`the 1.0 tag is read as ${r[0]}`,n,e.line),[n,i]=r);let s=Wl(e.value);const o=dle.has(n)?qoe(s.value):-1;o>=0&&(this.tally("parse-error",H.SYNTAX,"a qualifier block without its closing brace was dropped",n,e.line),s=Wl(s.value.slice(0,o).trimEnd()));const{qualifiers:l}=s;return s.badBlock!==null?this.tally("parse-error",H.SYNTAX,"a closing brace that is not a qualifier block was kept as text",n,e.line):Qoe(s.value)&&this.tally("parse-error",H.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,rd({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"&&id(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(Uu.has(r)&&e.kind!=="Typedef"){this.unrecognized(e,n);return}if(sh.has(r)){this.text(e,r,l,o,n.line);return}if(oh.has(r)){const d=Tt(l).trim();if(d!=="true"&&d!=="false"){this.report.error("validation-error",H.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=Bl(l);if(yc.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",H.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",H.BAD_VALUE,`relationship needs a relation and a target, found ${JSON.stringify(Tt(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",H.BAD_VALUE,`intersection_of needs a class, or a relation and a class, found ${JSON.stringify(Tt(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,rd(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",H.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=Qk(l);if(d===null){this.report.error("validation-error",H.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){Bl(i).some(l=>l.kind==="quoted"&&l.unterminated)&&this.tally("parse-error",H.SYNTAX,"an unterminated quote; the text after it, a comment included, is kept",n,s);const o=Tt(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",H.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",H.SYNTAX,"the text is not quoted; the whole value is kept",n,s),{text:Tt(i).trim(),xrefs:[]};if(r[0].unterminated)return this.tally("parse-error",H.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",H.SYNTAX,"the xref list is missing",n,s),{text:r[0].text,xrefs:[]};o.unterminated&&this.tally("parse-error",H.SYNTAX,"an xref list without its closing ]; kept as read",n,s),r.length>2&&this.tally("parse-error",H.SYNTAX,"text after the xref list was ignored",n,s);const l=oN(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",H.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",H.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&&Pa.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",H.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",H.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",H.UNDECLARED,"a synonym type no synonymtypedef declares",c,s):h!==null&&(a=h)}(o.length>2||l===void 0)&&this.tally("parse-error",H.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",H.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",H.SYNTAX,"an xref list without its closing ]; kept as read","synonym",s);const f=l===void 0?[]:oN(l.text);this.describe(e,f,"synonym",s),this.xrefQualifiers(e,"synonym",f),this.push(e,"synonym",rd({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",H.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",H.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",H.SYNTAX,"a datatype that is not a word was ignored","property_value",r.line),s=null),this.push(e,"property_value",rd({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",H.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",H.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=To(),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=To(),e.values.set("obo.unrecognized",i)),id(i,n.tag,Tt(n.value)),this.tally("validation-error",H.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>ule){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",H.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 cle.test(this.version)||this.tally("validation-error",H.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())&&dN(e.trim())===null&&this.tally("validation-error",H.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:Tt(i[0]).trim()};return{name:e("ontology"),sourceFormat:"obo",sourceVersion:this.version,created:dN(e("date")),creator:e("saved-by")}}headerRecord(){return this.header}namespaceDefault(){return this.defaultNamespace}}function rd(t,e){return e===null?t:{...t,qualifiers:e}}function dN(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 ple(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",H.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",H.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",H.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",H.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(!lle.has(p.relation)&&!l.has(p.relation)&&t.tally("validation-error",H.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(),gle(r,a,n,d,e,new Set(t.typedefs.keys())),s.size>0&&e.warning("merged",H.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 gle(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",H.DANGLING_REFERENCE,`${e.length} target${O(e.length)} no frame declares: ${l.join(", ")}${a}; ${c}`,{element:e[0]})}class mle{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",H.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>=tR&&(this.since=0,F(this.signal))}}function yle(t,e,n,i,r){const s=ple(t,n,i.addMissingNodes,r),o=new mle(e,n,i);i.restoreMangledIds&&ble(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(Vi):[])a.has(d)&&c.set(d,fe(e,"node",La("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=fe(e,"node",La("node",lo),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 ble(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===ile)??-1;if(r===void 0||s<0)continue;const o=Ele(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 Ele(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 Qn(i,r,n.onMixedDirection);if(s.setHeader(!0),t.edges.length===0)return;const o=fe(i,"edge",La("edge","relation"),r).handle,l=t.edges.some(a=>a.edge.qualifiers!==null)?fe(i,"edge",La("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 _le(t,e){const n=[];let i=0;const r=(s,o)=>{for(const l of Yoe(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",H.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",H.DEPRECATED_SYNTAX,"a backslash line continuation was joined (deprecated in 1.4)","\\",i)}if(Voe(s)&&Rm(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",H.DEPRECATED_SYNTAX,"a backslash line continuation was joined (deprecated in 1.4)","\\",i),r(n.join(""),i))}function Sle(t){let e=new TextDecoder("utf-8").decode(t.subarray(0,lN));e.charCodeAt(0)===65279&&(e=e.slice(1));const n=e.split(/\r\n|\r|\n|\f/);n.length>1&&t.byteLength>=lN&&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 Ole=Object.freeze({format:"obo",options:Object.freeze(["obsolete","typedefs"]),extensions:Object.freeze([".obo"]),mimeTypes:Object.freeze(["text/obo","application/obo"]),sniff(t){return Sle(t)},async import(t,e,n){const i=Qe(n,rle),r=fle(n),s=new te("obo",i.errorLimit);bt(e,n,s,!0),Et(n,s,nle);const o=new hle(s,i.signal,r.typedefs==="nodes");await _le(new Up(t,s,i),o),o.finishFrame(),o.significant||s.fail(H.EMPTY_INPUT,"the input is empty");const l=o.notObo();l!==null&&s.fail(H.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(),yle(o,e,s,i,r);const a=To();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()}}),Kn=Object.freeze({COLUMN_AS_PROPERTY_VALUE:oy,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:ly,RELATION_RENAMED:"W_OBO_RELATION_RENAMED",ONTOLOGY_NAME:"W_OBO_ONTOLOGY_NAME",TYPEDEF_NODES:ay,TYPE_GAINED:"W_OBO_TYPE_GAINED",EDGE_ORDER:"W_OBO_EDGE_ORDER",GRAPH_COLUMN_AS_METADATA:Ju,LINE_END:"W_OBO_LINE_END",NODE_ORDER:Zu,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:Ja,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}),rR=Xe({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}),lh="graphty:originalId",Dp="relation",Nle="qualifiers",sR="weight",oR=new Set(["is_a","instance_of","disjoint_from","inverse_of","union_of","intersection_of"]),lR="\0edges",I0="obo.unrecognized",Ale=["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",lR,"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",I0],Tle=["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"],Ile=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",...sh,...oh,...yc,...nR.keys()]),$le=new Set(Object.keys(Vi).filter(t=>t!=="type"&&t!=="name"&&t!=="propertyType")),Cle=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 Ha(t){return t.length>0&&t===t.trim()}function _n(t,e,n=!0){return Array.isArray(t)&&(!n||t.length>0)&&t.every(e)}function sd(t){return typeof t=="string"&&t.length>0&&Ha(t)}function ds(t){return typeof t=="string"&&co(t)}function jl(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")?qb(i.qualifiers,rh)?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 bc(t){const e=t.replaceAll(new RegExp(eR.source,"gu"),"_");return e.length===0?"_":e}function $0(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 vle(t){const e=t?.relation??"is_a";if(typeof e!="string"||!co(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 Dle(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),co(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=kle(t,r,s,n):s.length>0&&Rle(r,s,l,n),{ids:r,originals:l,fatal:a??Lle(t,r,n)}}function kle(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 Rle(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=bc(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 ${lh} property values (JSON text; an import with restoreMangledIds: true reads them back as the ids)`,null,e.length)}function Lle(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 Ple(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(Kn.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(Kn.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(Kn.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 xle(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=Se(i,r);if(typeof s!="string"||!aJ.has(s))return{kinds:n.fill("Term"),type:null};n[r]=s}return{kinds:n,type:i}}function Mle(t,e,n,i,r){const s=Vi[t];if(!yD(s.dtype,e)||e.meta.components>1)return!1;const o=Uu.has(t),l=a=>{if(sh.has(t))return typeof a=="string"&&Ha(a);if(oh.has(t))return typeof a=="boolean";if(yc.has(t))return _n(a,ds);switch(t){case"def":return typeof a=="string";case"def.xrefs":return _n(a,sd,!1);case"xref":return _n(a,sd);case"xref.descriptions":return typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.values(a).every(c=>typeof c=="string");case"synonym":return _n(a,c=>jl(c,["text","scope","type","xrefs"])&&typeof c.text=="string"&&typeof c.scope=="string"&&Pa.has(c.scope)&&(c.type===null||ds(c.type))&&(c.type===null||(r.get(c.type)??c.scope)===c.scope)&&_n(c.xrefs,sd,!1));case"intersection_of":return _n(a,c=>jl(c,["relation","target"])&&(c.relation===null||ds(c.relation))&&ds(c.target));case"property_value":return _n(a,c=>jl(c,["relation","value","datatype"])&&ds(c.relation)&&c.relation!==lh&&typeof c.value=="string"&&(c.datatype===null||ds(c.datatype)));case"holds_over_chain":case"equivalent_to_chain":return _n(a,c=>_n(c,ds)&&c.length===2);case"expand_assertion_to":case"expand_expression_to":return _n(a,c=>jl(c,["template","xrefs"])&&typeof c.template=="string"&&_n(c.xrefs,sd,!1));case"obo.qualifiers":return typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.values(a).every(c=>_n(c,d=>jl(d,["value"])&&Object.hasOwn(d,"qualifiers")&&typeof d.value=="string"&&qb(d.qualifiers,rh)));default:return!1}};for(const a of n)if(e.isSet(a)&&(o&&i[a]!=="Typedef"||!l(Se(e,a))))return!1;return!0}function Ule(t,e,n){if(t.dtype!=="json")return!1;for(const i of e){const r=Se(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((Ile.has(s)||Uu.has(s))&&!(Uu.has(s)&&n[i]!=="Typedef")&&!(s==="instance_of"&&n[i]!=="Instance")||s.length===0||!Ha(s)||!_n(o,a=>typeof a=="string"&&Ha(a)))return!1}}return!0}function Gle(t){const e=new Map;for(const n of t.synonymtypedef??[]){const i=Bl(n);if(i.length>0&&i[0].kind==="word"){const r=i.slice(1).find(s=>s.kind==="word"&&Pa.has(s.text));e.set(i[0].text,r?.text??null)}}return e}function jle(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 Fle(t,e,n,i){e.length>0&&!t.nodes.has("type")&&i(Kn.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(Kn.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 aR(t,e){const n=dt(e),i=vle(e),r=[],s=(it,mh,TL=null,IL=null)=>{r.push(Object.freeze({code:it,message:mh,column:TL,count:IL}))};let o=null;const{ids:l,originals:a,fatal:c}=Dle(t,n.sanitizeIds,s);o??=c;const d=Ut(t),{written:u,edgeStart:f,edgeOrder:h,dst:p}=Ple(t,d,n,s),g=ED(t,u,{outgoingAllowed:!1,changed:it=>a.has(it)}),m=wD(g,Array.from(h,it=>p[it]));m>0&&s(Zu,`${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 it=0;it<t.nodeCount;it++)g[it]===0&&y.push(it);const{kinds:b,type:_}=xle(t,g);Fle(t,y,b,s);const S=jle(t),I=Gle(S.header),T=ra(t.nodes,"label","name"),D=T.column,P=D!==null&&y.every(it=>!D.isSet(it)||Ha(String(D.value(it))))?D:null,k=zle(t,y,b,I,P);o??=_D(t,n,{caps:rR,label:P,labelAssumed:T.assumed,edgeSlot:"a qualifier",note:s}),Ble(t,P,k,s);const U=Hle(t,y,g,P,k,_,s),Y=ra(t.edges,"kind",Dp),me=Yle(t,u,Y.column,i.relation,s);Y.assumed&&Y.column!==null&&s(Ja,`edge column "${Dp}" 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")`,Dp,Y.column.length-Y.column.nullCount);const Oe=wt(t),{qualifiers:Fe,edgeColumns:J}=Vle(t,u,Y.column,Oe,s);SD(t,y,g,u,s);const Gt={notes:r,fatal:o,options:i,ids:l,originals:a,frameless:g,kinds:b,label:P,tags:k,properties:U,edgeStart:f,edgeOrder:h,dst:p,relations:me,qualifiers:Fe,edgeColumns:J,weights:Oe,header:[],tail:[]};let Q=pN(Gt,y);if(!Q.qualifiersPlaced){k.delete("obo.qualifiers");const it=t.nodes.get("obo.qualifiers");it!==null&&(U.push({column:it,relation:"obo.qualifiers"}),Jb(s,it,y,"property_value lines (relation obo.qualifiers)")),Q=pN(Gt,y)}Q.duplicates>0&&s(Kn.DUPLICATE_CLAUSE,`${Q.duplicates} clause${O(Q.duplicates)} ${C(Q.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,Q.duplicates);const ut=Xle(t,S.header,i,y,k,s,Q),gh=Qle({kept:S,rows:y,kinds:b,ids:l,properties:U,relations:me,edges:h,xref:k.get("xref")??null});return Q.lineEnds>0&&s(Kn.LINE_END,`${Q.lineEnds} text${O(Q.lineEnds)} ${C(Q.lineEnds,"holds","hold")} a carriage return or form feed, which OBO cannot carry; written as a line feed`,null,Q.lineEnds),{...Gt,header:ut,tail:gh}}function zle(t,e,n,i,r){const s=new Map;for(const c of $le){const d=t.nodes.get(c);d===null||d===r||d.meta.role!==null&&d.meta.role!=="label"||(c===I0?Ule(d,e,n):Mle(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=>Wle(s,a,c))&&s.delete("xref.descriptions"),s}function Wle(t,e,n){const i=Se(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(Se(l,n))}for(const o of["synonym","expand_assertion_to","expand_expression_to"]){const l=t.get(o),a=l===void 0?void 0:Se(l,n);if(Array.isArray(a))for(const c of a)s(c.xrefs)}return Object.keys(i).every(o=>r.has(o))}function Ble(t,e,n,i){for(const[r,s]of[...n,...e===null?[]:[["name",e]]]){const o=r==="name"?"string":Vi[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(Ju,`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 Hle(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&&xa.has(d)||u===lo&&e.every(h=>!c.isSet(h))&&n.includes(1))continue;const f=co(u)&&u!==lh?u:bc(u.replaceAll(":","_"));l.push({column:c,relation:f}),Jb(o,c,e,`property_value lines (relation ${f})`)}return l}function Yle(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:Se(n,a);if(typeof c!="string"){o++;continue}co(c)?s[a]=c:(s[a]=bc(c),l++)}return o>0&&r(Kn.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(Kn.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 Vle(t,e,n,i,r){const s=Kle(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&&xa.has(u))continue;const h=rh(f)?f:bc(f.replaceAll(/[=",[\]\\]/g,"_"));o.push({column:d,name:h});const p=l(d);p>0&&r(Kn.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(Kn.EDGE_COLUMN_AS_QUALIFIER,`${c} explicit edge weight${O(c)} ${C(c,"is","are")} written as the qualifier ${sR} and read back inside the qualifiers column, not as weights`,t.edges.byRole("weight")?.meta.name??null,c),{qualifiers:s,edgeColumns:o}}function Kle(t,e){const n=t.edges.get(Nle);return n?.dtype!=="json"||n.meta.role!==null?null:e.every(r=>!n.isSet(r)||qb(Se(n,r),rh))?n:null}function Xle(t,e,n,i,r,s,o){const{values:l,filled:a}=qle(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=[...Tle.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(`${C0(f)}: ${h}`);d.length===0&&i.length===0&&d.push("format-version: 1.4");for(const f of t.graph){const h=co(f.meta.name)?f.meta.name:bc(f.meta.name);for(const p of fR({column:f,relation:h},0,o))d.push(`property_value: ${p}`)}return d}function qle(t,e,n,i){const{meta:r}=t,s=new Map(Object.entries(e).map(([c,d])=>[c,d.map(cR)])),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",Zle(r.created)),l("saved-by",r.creator===null?null:ao(r.creator)));const a=Jle(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 Jle(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(Kn.ONTOLOGY_NAME,`the graph name ${JSON.stringify(e)} is not an ontology id; written as ${r}`,null,null),r}function cR(t){return t.replaceAll(/\r\n|\r|\n|\f/g,String.raw`\n`)}function C0(t){return ao(t).replaceAll(":",String.raw`\:`)}function Zle(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 Qle(t){const{kept:e,rows:n,properties:i,relations:r}=t,s=[],o=eae(t);tae(e.typedefs,o,s);const l=(c,d)=>{o.has(c)||(o.add(c),s.push("","[Typedef]",`id: ${en(c)}`,`name: ${ao(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,"_")}]`,...dR(c.clauses));return s}function eae(t){const{rows:e,kinds:n,ids:i,xref:r}=t,s=new Set(oR);for(const o of e){if(n[o]!=="Typedef")continue;s.add(i[o]);const l=r===null?void 0:Se(r,o);for(const a of Array.isArray(l)?l:[])s.add(String(a))}return s}function tae(t,e,n){for(const[i,r]of Object.entries(t))if(!(e.has(i)&&!oR.has(i))){e.add(i),n.push("","[Typedef]",`id: ${en(i)}`,...dR(r,"id"));for(const s of r.xref??[])e.add(s.trim())}}function dR(t,e=null){return Object.entries(t).filter(([n])=>n!==e).flatMap(([n,i])=>i.map(r=>`${C0(n)}: ${cR(r)}`))}class nae{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),T0($0(i[r].qualifiers)))}placed(){return Object.entries(this.entries).every(([e,n])=>(this.next.get(e)??0)===n.length)}}function yi(t,e){return tle(e)&&t.lineEnds++,e}function uR(t,e,n){let i=ao(yi(t.stats,e));const r=t.p.tags.get("xref.descriptions"),s=r===void 0?void 0:Se(r,t.row);return s!==void 0&&Object.hasOwn(s,e)&&!t.described.has(e)&&(t.described.add(e),i+=` "${mr(yi(t.stats,s[e]))}"`),n!==null&&(i+=t.cursor.block(n,e)),i}function Lm(t,e,n){const i=`${n}.xrefs`;return`[${e.map(r=>uR(t,r,i)).join(", ")}]`}function fR(t,e,n){const{column:i,relation:r}=t,s=Se(i,e);if(s===void 0)return[];const o=en(r),l=(a,c)=>{let d,u=Cle[c]??"xsd:string";return typeof a=="number"&&u==="xsd:double"?d=iae(a,c):typeof a=="string"||typeof a=="boolean"||typeof a=="number"?d=nl(a,c):(d=JSON.stringify(a)??"null",u="xsd:string"),`${o} "${mr(yi(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 iae(t,e){return Number.isNaN(t)?"NaN":Number.isFinite(t)?Co(t,e==="f32"?"f32":"f64"):t>0?"INF":"-INF"}function rae(t,e){const{p:n}=t,i=[];if(n.qualifiers!==null){const s=Se(n.qualifiers,e);s!==void 0&&i.push(...$0(s))}for(const{column:s,name:o}of n.edgeColumns)i.push(...sae(s,e).map(l=>[o,l]));const r=n.weights.text(e);r!==null&&i.push([sR,r]);for(const[,s]of i)yi(t.stats,s);return T0(i)}function sae(t,e){const n=Se(t,e);return n===void 0?[]:t.dtype==="list"?n.map(i=>nl(i,t.child.dtype)):[t.dtype==="json"?JSON.stringify(n)??"null":nl(n,t.dtype)]}function hR(t,e,n,i){const r=Se(n,t.row);if(r===void 0)return;const{cursor:s,stats:o}=t,l=(a,c,d=!1)=>{i.push(`${e}: ${d?a:ao(yi(o,a))}${s.block(e,c)}`)};if(sh.has(e)){l(r,r);return}if(oh.has(e)){l(r?"true":"false",r?"true":"false",!0);return}if(yc.has(e)){for(const a of r)l(en(a),a,!0);return}Object.hasOwn(uN,e)&&uN[e](t,e,r,i)}function Ud(t){return t===void 0?"":T0($0(t))}const uN={def(t,e,n,i){const r=t.p.tags.get("def.xrefs"),s=r===void 0?[]:Se(r,t.row)??[],o=n;i.push(`def: "${mr(yi(t.stats,o))}" ${Lm(t,s,"def")}${t.cursor.block("def",o)}`)},xref(t,e,n,i){for(const r of n)i.push(`xref: ${uR(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: "${mr(yi(t.stats,r.text))}" ${r.scope}${s} ${Lm(t,r.xrefs,"synonym")}${Ud(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)}${Ud(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&&co(r.value)?en(r.value):`"${mr(yi(t.stats,r.value))}"${s}`;i.push(`property_value: ${en(r.relation)} ${o}${Ud(r.qualifiers)}`)}},holds_over_chain:fN,equivalent_to_chain:fN,expand_assertion_to:hN,expand_expression_to:hN,[I0](t,e,n,i){for(const[r,s]of Object.entries(n))for(const o of s)i.push(`${C0(r)}: ${ao(yi(t.stats,o))}`)}};function fN(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 hN(t,e,n,i){for(const r of n)i.push(`${e}: "${mr(yi(t.stats,r.template))}" ${Lm(t,r.xrefs,e)}${Ud(r.qualifiers)}`)}function pR(t,e,n){const i=t.tags.get("obo.qualifiers"),r={p:t,row:e,cursor:new nae(i===void 0?void 0:Se(i,e)),described:new Set,stats:n},s=[`[${t.kinds[e]}]`,`id: ${en(t.ids[e])}`];for(const o of Ale)if(o==="name")oae(r,s);else if(o==="property_value")lae(r,s);else if(o===lR)aae(r,s);else{const l=t.tags.get(o);l!==void 0&&hR(r,o,l,s)}return n.qualifiersPlaced&&=r.cursor.placed(),s}function oae(t,e){const n=t.p.label===null?void 0:Se(t.p.label,t.row);typeof n=="string"&&e.push(`name: ${ao(yi(t.stats,n))}${t.cursor.block("name",n)}`)}function lae(t,e){const{p:n,row:i}=t,r=n.originals.get(i);r!==void 0&&e.push(`property_value: ${lh} "${mr(JSON.stringify(r))}" xsd:string`);const s=n.tags.get("property_value");s!==void 0&&hR(t,"property_value",s,e);for(const o of n.properties)for(const l of fR(o,i,t.stats))e.push(`property_value: ${l}`)}function aae(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=rae(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 pN(t,e){const n={lineEnds:0,qualifiersPlaced:!0,duplicates:0};for(const i of e){const r=pR(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*cae(t){if(t.fatal!==null)throw t.fatal;yield t.header.map(n=>`${n}
192
+ `).join("");const e={lineEnds:0,qualifiersPlaced:!0};for(let n=0;n<t.ids.length;n++)t.frameless[n]===0&&(yield`
193
+ ${pR(t,n,e).join(`
194
+ `)}
195
+ `);t.tail.length>0&&(yield`${t.tail.join(`
196
+ `)}
197
+ `)}function*gN(t,e){yield*cae(aR(t,e))}const dae=Object.freeze({format:"obo",options:Object.freeze(["ontology","relation"]),capabilities:rR,check(t,e){return Object.freeze([...aR(t,e).notes])},export(t,e){return ei(gN(t,e))},exportToString(t,e){return ti(gN(t,e))}}),mN=500;function yN(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,mN,!0),height:i(n.height,mN,!0),partition:i(n.partition,0,!1),vector:i(n.vector,0,!1),vector2:i(n.vector2,0,!1),ini:r}}function Gu(t,e){const n=t.ini.get(e);return n!==void 0&&n!=="0"&&n!=="false"}function uae(t){return t!==null&&Gu(t,"Form8.withLabels1")}function ah(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 bN=["#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"],gR=20,mR="#ffd9bc",EN=8;function Pm(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 Vt(t,e,n){return t[e]??=new Array(n).fill(null),t[e]}function fae(t,e,n){const i=e.nodeCount,r=Vt(n,"width",i),s=Vt(n,"height",i);hae(t,r,s),yae(t,e,r,s),pae(t,e,n);const o=ah(t,"TransparencyofVertices");if(o!==null&&o<1){const l=Math.max(0,o),a=Vt(n,"fillOpacity",i);a.forEach((c,d)=>{a[d]=(typeof c=="number"?c:1)*l}),Vt(n,"borderOpacity",i).fill(l*l)}Gu(t,"Form10.effect3d")&&mae(e,n),gae(t,n,i);for(const l of["width","height"])n[l].every(a=>a===null)&&Reflect.deleteProperty(n,l)}function hae(t,e,n){const i=ah(t,"Form8.SizeofVertices");if(i===null||i===EN)return;const r=i/EN,s=o=>typeof o=="number"?o*r:gR*r*r;for(let o=0;o<e.length;o++)e[o]=s(e[o]),n[o]=s(n[o])}function pae(t,e,n){const i=Pm(e,"partition",t.partition);if(i===null)return;const r=Vt(n,"fill",e.nodeCount);for(let s=0;s<e.nodeCount;s++){const o=i(s);o!==null&&(r[s]=bN[Math.abs(o)%bN.length])}}function gae(t,e,n){const i=ah(t,"Form8.MarkVerticesUsing");i===2?Vt(e,"label",n).forEach((r,s,o)=>{o[s]=String(s+1)}):(i===3||i===4)&&Vt(e,"label",n).fill("")}function mae(t,e){const n=t.nodeCount,i=Vt(e,"fill",n),r=Vt(e,"fillGradient",n),s=Vt(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]):mR;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 yae(t,e,n,i){const r=Pm(e,"vector",t.vector);if(r===null)return;const s=Pm(e,"vector",t.vector2),o=(l,a,c)=>{c!==null&&c>=0&&(l[a]=(typeof l[a]=="number"?l[a]:gR)*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 bae(t,e,n,i){const r=e.edgeCount,s=ah(t,"TransparencyofLines");if(s!==null&&s<1){const o=Vt(i,"opacity",r);o.forEach((l,a)=>{o[a]=(typeof l=="number"?l:1)*Math.max(0,s)})}if(Gu(t,"Form10.StraightLinesOnly1")){const o=Vt(i,"curved",r);for(let l=0;l<r;l++){const a=i.bends?.[l];a==null&&(o[l]=!1)}}if(Gu(t,"Form10.ColorGradientLines")){const o=n.fill,l=f=>typeof o?.[f]=="string"?o[f]:mR,a=Vt(i,"gradientColors",r),c=Vt(i,"gradientKind",r),d=Vt(i,"sourceArrowColor",r),u=Vt(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 gi="label",yR="position",Pt="shape",bR="relation",Eae="spells",ER="value",wR="value",wae="partition",_ae="vector",v0=new Set(["ellipse","box","diamond","triangle","cross","empty","house","man","woman"]);function xm(t){return v0.has(t.toLowerCase())}const yr="graphty_originalId",Mm="% graphty.styles ",Sae=new Map([["network","network"],["vertices","vertices"],["arcs","arcs"],["edges","edges"],["arcslist","arcslist"],["edgeslist","edgeslist"],["matrix","matrix"],["partition","partition"],["vector","vector"]]),Um=/^[+-]?\d+$/,Oae=/^(\*|[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)(?:-(\*|[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))?$/;function _R(t,e){const n=new Nae(t,e);let i=0;for(;i<t.length;)i=n.step(i);return n.finish()}class Nae{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&&kp(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&&kp(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&&!kp(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 kp(t){return t===32||t===9||t===13||t===12||t===11}function SR(t){return Aae.has(t.toLowerCase())}const Aae=new Set(["permutation","cluster","hierarchy"]);function OR(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 NR(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 AR(t){const e=_R(t.trimStart().slice(1));if(e===null||e.length===0||e[0].length===0)return null;const n=e[0],i=Sae.get(n.toLowerCase())??"unsupported";let r;switch(i){case"vertices":r=Tae(e);break;case"arcs":case"edges":case"arcslist":case"edgeslist":case"matrix":r=Iae(e);break;case"network":case"partition":case"vector":r=$ae(e);break;case"unsupported":r={...br,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 br={count:null,secondCount:null,relation:null,name:null,next:1};function Tae(t){if(t.length<2||!Um.test(t[1]))return br;const e=Number(t[1]);return t.length<3||!Um.test(t[2])?{...br,count:e,next:2}:{...br,count:e,secondCount:Number(t[2]),next:3}}function Iae(t){if(t.length<2||!t[1].startsWith(":")||!Um.test(t[1].slice(1)))return br;const e=Number(t[1].slice(1));return t.length<3?{...br,relation:e,next:2}:{...br,relation:e,name:t[2],next:3}}function $ae(t){return t.length<2?br:{...br,name:t.slice(1).join(" "),next:t.length}}function Rp(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 Cae(t){return t.length>=2&&t.startsWith("[")&&t.endsWith("]")}function vae(t){const e=t.slice(1,-1);if(e.trim().length===0)return[];const n=[];for(const i of e.split(/[,/]/))n.push(Dae(t,i));return n}function Dae(t,e){const n=Oae.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 TR=/&#(?:[xX]([\da-fA-F]+)|(\d+));/g;function kae(t,e){return t.includes("&#")?t.replaceAll(TR,(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 Rae(t){return t.includes("&#")?t.replaceAll(TR,e=>`&#38;${e.slice(1)}`):t}function Lae(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 Pae(t){return t.length===0||/[\s"]/.test(t)||t.startsWith("[")||t.startsWith("*")||t.startsWith("%")||xm(t)?!1:!/^[+-]?(\.\d|\d)/.test(t)&&!/^[+-]?(?:nan|inf|infinity)$/i.test(t)}const IR=new Set(["bc","bw","s_size","phi","r","q","lc","la","lr","lphi","fos","font"]),D0=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","arrowPosition","label","labelColor","labelSize","labelFont"]),block:"native"}),Ya=20,$R=new Map([["other:man",[2.502,6.487]],["other:woman",[3.003,6.478]]]),ns=500,k0=["ic","bc","bw","s_size","x_fact","y_fact","phi","q","lc","fos","font","lr","lphi","la"],CR=["c","w","p","s","ap","l","lc","fos","font"],ch={node:[Pt,...k0],edge:["c","w","p","s","ap"]},xae=ch.edge.filter(t=>t!=="p"),dh=2,Gm={color:"#999999",width:1};function Mae(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 wN="directed",Uae={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 aa(t,e,n,i,r){if(t===null)return;const s=$e(t,"dvips",r(e));if(s===null){const l=Gae.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=_l(s,null,r(e),n!==null);n!==null&&i(n,o)}const Gae=new Map([["fill","#ffffff"],["color","#000000"]]);function ca(t,e,n,i){t!==null&&n(e,V(t,i(e)))}function vR(t,e,n,i=null){const r=t(gi);r!==null&&r!==""&&e("label",nt(r,n("label")));const s=t(Pt),o=s===null?null:oe("shape",s,"dvips",n("shape"));if(s!==null&&e("shape",o),aa(t("ic"),"fill","fillOpacity",e,n),aa(t("bc"),"borderColor",null,e,n),ca(t("bw"),"borderWidth",e,n),Bae(t,e,n,$R.get(String(o))),Fae(t,e,o),aa(t("lc"),"labelColor",null,e,n),ca(t("fos"),"labelSize",e,n),kR(t("font"),e,n),Vae(t,e,n),Wae(t("la"),e,n,i),o==="none")for(const[l,a]of zae)e(l,a)}const jae=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]]]]),DR=.001;function Fae(t,e,n){const i=bi(t("phi"))??0,r=bi(t("q"))??DR,s=[[-1,0],[-r,1],[r,1],[1,0],[r,-1],[-r,-1]],o=n==="diamond"?s:jae.get(String(n));if(o===void 0||n!=="diamond"&&i%360===0)return;const[l,a]=[bi(t("x_fact"))||1,bi(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 zae=[["labelSize",1],["labelColor","#ffffff"],["labelPosition","center"],["labelOffsetX",0],["labelOffsetY",0],["labelShiftX",0]];function kR(t,e,n){if(t===null||t==="")return;const i=typeof t=="string"?X$(t.trim()):null;if(i===null){RR(t,"labelFont",e,n);return}e("labelFont",i.family)}function Wae(t,e,n,i){let r=t===null?null:V(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 Bae(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 a=l===null?1:V(l,n(s)),c=i?.[o]??1;e(s,a===null?null:Number((Ya*a*c).toPrecision(15)))}}function RR(t,e,n,i){t!==null&&t!==""&&n(e,nt(t,i(e)))}const Hae=new Map([["right",0],["top-right",90],["left",180],["bottom-right",285]]),Yae=new Map([["top","top-right"],["top-left","top-right"],["bottom","bottom-right"],["bottom-left","bottom-right"]]);function Vae(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?LR:V(i,n("labelPosition")),l=r===null?jm:V(r,n("labelPosition")),a=s===null?R0:V(s,n("labelSize"));if(o===null||l===null||a===null)return;const[c,d]=Kae(o,l,a);e("labelPosition","center"),e("labelOffsetX",c),e("labelOffsetY",d),e("labelShiftX",o===0?0:.5)}function Kae(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)-L0*n)]}const LR=20,jm=285,R0=15,L0=.3465;function PR(t,e,n,i,r=!0,s=null,o=null){aa(t("c"),"color","opacity",e,n),ca(t("w"),"width",(d,u)=>{e(d,typeof u=="number"&&!i?u*dh:u)},n);const l=t("p");l==="Dots"?e("lineStyle",P0(t,i)):l==="Solid"?e("lineStyle","solid"):l!==null&&(B(n("lineStyle"),v.UNKNOWN_VALUE,typeof l=="string"?l:JSON.stringify(l)),e("lineStyle","solid")),ca(t("s"),"arrowSize",e,n),oce(t("ap"),e,n);const a=o===null?t:Xae(t),c=o===null?null:qae(a,e,o);r&&(RR(t("l"),"label",e,n),c===null?SN(t,e,n,s):SN(a,e,n,[ns,0],Jae(c))),o===null&&Qae(t,e,s),aa(t("lc"),"labelColor",null,e,n),ca(t("fos"),"labelSize",e,n),kR(t("font"),e,n)}const _N={a1:-70,k1:.3,a2:-70,k2:.3};function Xae(t){return e=>t(e)??(e in _N?_N[e]:null)}function qae(t,e,n){const r=Va(t,[ns,0]);if(r===null)return null;const[[s,o],[l,a]]=r,c=ns,[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 Jae(t){const[e,n]=t;return Math.atan2(n[1]-e[1],n[0]-e[0])*180/Math.PI}function Zae(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:Ya)/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 SN(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 I=t(b);return I===null?_:V(I,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",R0,"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??tce(t,i,f+.5))-d)%360+360,m=g*Math.PI/180,y=L0*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 Qae(t,e,n){const i=Va(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(" "))}function ece(t,e,n,i){const r=bi(t("ap"))??0,s=Math.hypot(n[0],n[1]);if(r!==0||s===0||Va(t,n)===null)return;const[o,l]=[n[0]/s,n[1]/s],a=1/Math.hypot(o/(i[0]/2),l/(i[1]/2)),c=1.5+5*(bi(t("s"))??1),d=-(bi(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=Va(t,h);if(p===null)return;const g=s*s,m=b=>String(Math.round(b*1e4)/1e4||0),y=p.map(([b,_])=>{const[S,I]=[b*h[0]+_*h[1],b*h[1]-_*h[0]];return`${m((S*n[0]+I*n[1])/g)},${m((S*n[1]-I*n[0])/g)}`});e("bends",y.join(" "))}function Va(t,e){const[n,i,r,s]=["a1","k1","a2","k2"].map(u=>bi(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 tce(t,e,n){const i=Va(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 nce(t,e,n,i=!0){t===0?n("visible",!1):t!==null&&t<0&&e("p")===null&&n("lineStyle",P0(e,i))}const ice=5;function P0(t,e){const i=(bi(t("w"))??1)*(e?1:dh);return ice<=1.5*Math.max(1,i)?"dotted":"dashed"}function rce(t,e,n,i){for(const[r,s,o]of[["h1","sourcePort",n],["h2","targetPort",i]]){const l=bi(t(r)),a=l===null?null:sce(o,l);if(a!==null){const c=d=>String(Number(d.toFixed(4))+0);e(s,`${c(a[0])},${c(a[1])}`)}}}function sce(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 bi(t){return typeof t=="string"&&t.trim()!==""&&(t=Number(t)),typeof t=="number"&&Number.isFinite(t)?t:null}function oce(t,e,n){if(t===null)return;const i=V(t,n("arrowPosition"));if(i!==null&&i>1){B(n("arrowPosition"),v.NOT_CARRIED,`ap ${String(i)}`);return}i!==0&&e("arrowPosition",i)}function ON(t,e){return n=>{const i=t.has(n)?K(t.value(n,e)):null;return lce.has(n)&&typeof i=="string"&&ace.test(i)?null:i}}const lce=new Set(["ic","bc","lc","c"]),ace=/^[\d.]+(?: [\d.]+)*$/;function x0(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}function NN(t,e){return e.filter(n=>t.has(n))}function cce(t,e){const n=new re,{block:i,draw:r,voided:s}=uce(e.kept),o=uae(r),l=dce(t),a=r??{width:ns,height:ns},c=new Map,d=T=>{const[D,P]=[l(t.edgeSource(T)),l(t.edgeTarget(T))];return D===null||P===null?null:[(P[0]-D[0])*a.width,(P[1]-D[1])*a.height]},u=T=>{const D=T==="node"?t.nodes:t.edges,P=T==="node"?t.nodeCount:t.edgeCount,k=qr(P),U=Mae(T==="node"?ch.node:xae,T==="node");for(let Y=0;Y<P;Y++){e.budget.spend(T,1);const me=Gt=>({notes:n,target:T,property:Gt,element:Y,budget:e.budget}),Oe=(Gt,Q)=>{k.put(Y,Gt,Q)},Fe=ON(D,Y),J=T==="node"&&s.has(Y)?fce(Fe,p[Y-1]??null):U(Fe);T==="node"?(vR(J,Oe,me,l(Y)),p[Y]=J(Pt)):f(Y,J,Oe,me)}return k.values},f=(T,D,P,k)=>{const U=d(T),Y=U!==null&&i===null&&t.edgeSource(T)===t.edgeTarget(T)?me=>{c.set(T,me)}:null;PR(D,P,k,h[T],o,U,Y),h[T]&&Y===null&&U!==null&&ece(D,P,U,b(t.edgeTarget(T))),nce(m(T),D,P,h[T]),rce(D,P,p[t.edgeSource(T)],p[t.edgeTarget(T)])},h=x0(t),p=[],g=wt(t),m=T=>g.isExplicit(T)?g.value(T):bi(ON(t.edges,T)(ER)),y=u("node"),b=T=>{const D=P=>{const k=y[P]?.[T];return typeof k=="number"&&k>0?k:Ya};return[D("width"),D("height")]},_=u("edge");r!==null&&(fae(r,t,y),bae(r,t,y,_)),Zae(t,c,y,_),i!==null&&Oce(t,i,{node:y,edge:_},o);const S=[],I=new Map;return h.some(Boolean)&&(I.set(wN,h.map(T=>T?!0:null)),S.push({id:"edge.tool.arrow",target:"edge",role:"group",origin:"tool",where:{has:{style:wN}},set:{targetArrow:"triangle",color:Gm.color,width:Gm.width}})),{canonical:!0,dialect:"dvips",tool:"pajek",units:"px",node:{values:y},edge:{values:_,rules:S,columns:I},notes:n.list(),block:i,readFrom:{node:NN(t.nodes,[Pt,...k0]),edge:NN(t.edges,CR)}}}function dce(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 uce(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===gi?t(n):n===Pt?e:null}const hce=new Map([["ellipse","ellipse"],["rectangle","box"],["diamond","diamond"],["triangle","triangle"],["none","empty"],["other:cross","cross"],["other:house","house"],["other:man","man"],["other:woman","woman"]]),pce=new Map([["round-rectangle","box"],["parallelogram","box"],["trapezoid","box"],["vee","triangle"]]),gce=new Map([...w1].reverse().map(([t,e])=>[e,t]));function uh(t){return gce.get(t)??`RGB${t.slice(1).toUpperCase()}`}function xR(t,e,n){for(const i of e){const r=t(i);r!==null&&r!==1&&n(i,r)}}function mce(t,e){const n=t("shape");if(typeof n!="string")return"ellipse";const i=hce.get(n);if(i!==void 0)return i;if(n==="polygon"&&MR(t)!==null)return"diamond";e("shape",n);const r=t("shapePoints");return n==="polygon"&&r!==null&&e("shapePoints",r),pce.get(n)??"ellipse"}function MR(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 cl(t,e){return Tr("pajek")?.[t]?.[e]?.value}function UR(t,e){const n=new Map;xR(t,["fillOpacity","opacity"],e);const i=mce(t,e);i!=="ellipse"&&n.set(Pt,i);const r=MR(t);r!==null&&r!==DR&&n.set("q",r),yce(t,n),bce(t,n);const s=t("borderWidth");return typeof s=="number"&&s!==cl("node","borderWidth")&&n.set("bw",s),GR(t,n,cl("node","labelFont")),Ece(t,n,e),n}function yce(t,e){const n=[["fill","ic"],["borderColor","bc"],["labelColor","lc"]];for(const[i,r]of n){const s=t(i);typeof s=="string"&&s!==cl("node",i)&&e.set(r,uh(s))}}function bce(t,e){const n=[["width","x_fact",Ya],["height","y_fact",Ya],["labelSize","fos",1]],i=$R.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!==cl("node",r))&&e.set(s,Number((l/(o*a)).toPrecision(15)))}}function GR(t,e,n){const i=t("labelFont"),r=typeof i=="string"&&i!==""?Tb(i,!1,!1):null;r!==null&&r!==n&&e.set("font",r)}function Ece(t,e,n){const i=t("labelPosition");if(typeof i!="string")return;if(i==="center"){const o=wce(t);o===null?e.set("lr",0):(o[0]!==LR||o[1]!==jm)&&(e.set("lr",o[0]),e.set("lphi",o[1]));return}const r=Yae.get(i);r!==void 0&&n("labelPosition",i);const s=Hae.get(r??i);s!==void 0&&s!==jm&&e.set("lphi",s)}function wce(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+L0*(typeof r=="number"?r:R0),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 jR(t){return t?Gm:{color:cl("edge","color"),width:cl("edge","width")}}function FR(t,e,n){const i=new Map;xR(t,["opacity"],n);const r=jR(e),s=t("color");typeof s=="string"&&s!==r.color&&i.set("c",uh(s));const o=t("width");typeof o=="number"&&o!==r.width&&i.set("w",e?o:Number((o/dh).toPrecision(15)));const l=t("lineStyle");typeof l=="string"&&l!=="solid"&&Sce(l,i,e,n)&&i.set("p","Dots");const a=t("arrowPosition");typeof a=="number"&&a>0&&i.set("ap",a),_ce(t,i,n);const c=t("targetArrow");c!==null&&c!==(e?"triangle":"none")&&n("targetArrow",c);const d=t("sourceArrow");return d!==null&&d!=="none"&&n("sourceArrow",d),i}function _ce(t,e,n){const i=t("label");if(typeof i=="string"&&i!==""){const o=fh(i);o!==i&&n("label",i),e.set("l",o)}const r=t("labelColor");typeof r=="string"&&e.set("lc",uh(r));const s=t("labelSize");typeof s=="number"&&e.set("fos",s),GR(t,e)}function Sce(t,e,n,i){return t===P0(r=>e.get(r)??null,n)?!0:(i("lineStyle",t),["dashed","dotted","dash-dot","long-dash"].includes(t))}function Oce(t,e,n,i){const r=new re,s=x0(t);no(t,e,"pajek",o=>({values:n[o],properties:Uae[o],writes:D0[o],readBack:(l,a)=>{const c=Tce(o,a,s[l],r,i);return d=>c.get(d)??null},take:(l,a)=>a!==null||Ace.has(l)||Nce.has(l)}))}const Nce=new Set(["shapePoints","shapePointsStretch"]),Ace=new Set(["labelOffsetX","labelOffsetY","labelShiftX"]);function Tce(t,e,n,i,r){const s=()=>{},o=t==="node"?UR(e,s):FR(e,n,s),l=new Map,a=t==="node"?e("label"):null;typeof a=="string"&&o.set(gi,fh(a)),t==="node"&&[...o.keys()].every(f=>f===gi)&&o.set(Pt,"ellipse");for(const f of t==="edge"?ch.edge:[])o.has(f)||o.set(f,WR(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"?vR(c,d,u):PR(c,d,u,n,r),l}function zR(t,e){if(e===void 0)return null;const n=new Al,i=t.withColumns(),r=x0(t);for(const l of["node","edge"]){const a=l==="node"?i.nodes:i.edges,c=(p,g)=>{n.add(l,p,g)},d=Ws((p,g)=>e.picture(p,g),l,D0[l]),u=l==="node"?t.nodeCount:t.edgeCount,h=Dce(u,p=>l==="node"?UR(d(p),c):FR(d(p),r[p],c));l==="edge"&&Ice(t,h),vce(l,h,r),Cce(a,l==="node"?[Pt,...k0]:CR,h)}i.nodes.set(gi,$ce(e,t.nodeCount,n),{dtype:"string",role:"label"},{replaceRole:!0});const s=n.notes("Pajek"),o=Sl(e.rules,{inlineColumns:!0,snapshot:t});return s.push(...sc(o,e.rules.styles.rules.length,"size")),{snapshot:i,comment:Mm+o,notes:s}}function Ice(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]=fh(s))}i!==void 0&&e.set("l",i)}function $ce(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]=fh(o),r[s]!==o&&n.add("node","label",o))}return r}function fh(t){return t.replaceAll(/\r\n|[\r\n]/g," ").replaceAll('"',"'")}function Cce(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 vce(t,e,n){if(t==="node"){const i=[...e.values()];if(i.length===0)return;const r=i[0].length,s=e.get(Pt)??new Array(r).fill(null);for(let o=0;o<r;o++)i.every(l=>l[o]===null)&&(s[o]="ellipse");e.set(Pt,s);return}for(const i of ch.edge){const r=e.get(i);if(r!==void 0)for(let s=0;s<r.length;s++)r[s]??=WR(i,n[s])}}function WR(t,e){const n=jR(e);switch(t){case"c":return uh(String(n.color));case"w":return e?Number(n.width):Number(n.width)/dh;case"p":return"Solid";default:return 0}}function Dce(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 xt=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}),kce=new Set(["label"]),Rce=Object.freeze({label:"label",position:yR}),Lce=new Set(["directed","pair","mutual","weight","timeText","originalId"]),Pce=new Set(["color","size","shape","thickness","parent","parents","open","spellsOpen"]),xce=new Set(["start","end","timestamp","timestamps"]),hh=Xe({mixedDirection:!0,multiEdges:!0,selfLoops:!0,edgeIds:"none",idCharset:"dense-1-based",dtypes:["f64","i32","bool","string"],temporal:"spells",positions:!0});function ju(t,e,n){const i=[];for(const r of t){const s=Mce(r,e,n);s!==null&&i.push({column:r,slot:s})}return i}function Js(t,e,n,i){t?.push(In(e,n,i.meta.name,i.length-i.nullCount))}function Mce(t,e,n){const{role:i,name:r}=t.meta;return i==="label"&&e==="node"?Uce(t,n):i==="position"?Gce(t,e,n):i==="spells"?jce(t,e,n):i!==null&&xce.has(i)?(Js(n,xt.TEMPORAL_DROPPED,`${e} column "${r}" (${i}) cannot be written; Pajek intervals come from the spells role`,t),null):Fce(t,e)?null:zce(t,e,n)}function Uce(t,e){const{name:n,dtype:i}=t.meta;return i!=="string"&&i!=="dict"&&Js(e,xt.LABEL_AS_TEXT,`node column "${n}" (label) is ${i}; labels are text and re-import as string`,t),"label"}function Gce(t,e,n){const{name:i,components:r}=t.meta;return e==="edge"?(Js(n,w.POSITIONS,`edge column "${i}" (position) cannot be written`,t),null):r===2||r===3?"position":(Js(n,xt.POSITION_STRIDE,`node column "${i}" (position) has ${r} components; Pajek coordinates are x y [z]`,t),null)}function jce(t,e,n){const{name:i,dtype:r,itemDtype:s}=t.meta;return r==="list"&&(s==="f64"||s==="i32"||s==="f32")?"spells":(Js(n,w.SPELLS,`${e} column "${i}" (spells) is not a list of number pairs; it cannot be written`,t),null)}function Fce(t,e){const{role:n,dtype:i}=t.meta;return n!==null&&(Lce.has(n)||Pce.has(n))?!0:e==="edge"&&n==="id"||i==="list"||i==="json"}function zce(t,e,n){const{name:i,dtype:r}=t.meta,s=r==="dict"||r==="string";return s&&e==="node"&&i===Pt?Wce(t,n):s&&e==="edge"&&i===bR?"relation":Pae(i)?"param":(Js(n,xt.KEY_DROPPED,`${e} column "${i}" cannot be a Pajek parameter key; it is not written`,t),null)}function Wce(t,e){return Yce(t)?"shape":(t.meta.dtype==="dict"&&Js(e,xt.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 Bce(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===gi);s!==void 0&&(n.push(In(xt.ROLE_ASSUMED,`node column "${gi}" has no role; written as a parameter, it reads back as the vertex label (role label)`,gi,s.length-s.nullCount)),i!==null&&i!==s&&n.push(In(xt.COLUMN_DROPPED,`node column "${i.meta.name}" (the labels) reads back replaced by the parameter "${gi}"`,i.meta.name,i.length-i.nullCount)));const o=r===0?0:Hce(t.nodeCount,i);o>0&&n.push(In(xt.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?gi:i.meta.name,o))}function Hce(t,e){let n=0;for(let i=0;i<t;i++)e?.isSet(i)||n++;return n}function Yce(t){for(let e=0;e<t.length;e++)if(t.isSet(e)&&!v0.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 AN(t,e){switch(e){case"i32":case"u32":case"u8":return Ue(t);case"f32":return lt(t);case"f64":return _r(t,"f64");default:{const n=e;throw new Error(`unknown numeric dtype ${n}`)}}}function Ka(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 AN(n,t.dtype);const i=[],r=n;for(let s=0;s<r.length;s++)i.push(AN(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 Fu(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);vy(d)?r==="param"&&Xn(d)!=="string"&&a++:o++}}o>0&&n.push(In(xt.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(xt.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(xt.NONFINITE_AS_TEXT,`${l} non-finite value${O(l)} of ${e} column "${s}" ${C(l,"is","are")} written as text`,s,l))}}function BR(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 Vce(t,e,n,i){return t?.isSet(n)?Ka(t,n):i||e.isChanged(n)?Bi(e.originalAt(n)):null}function HR(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 Lae(i)}function Kce(t,e,n){if(!t.isSet(e))return null;const i=t.dtype,r=t.value(e),s=Co(r[0],i),o=Co(r[1],i);return t.meta.components===3&&n?`${s} ${o} ${Co(r[2],i)}`:`${s} ${o}`}function Xce(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*TN(t,e,n=null){const i=bl(t,hh.idCharset,e.mangle?"mangle":"error"),r=YR(ju(t.nodes,"node",null),e.mangle),s=ju(t.edges,"edge",null),o=[];Fu(r,"node",o),Fu(s,"edge",o),VR(t.nodeCount,i,e.mangle,o);for(const a of o)if(a.code===xt.TEXT)throw new N("E_UNSUPPORTED",a.message,{reason:"pajek label",column:a.column,count:a.count});n!==null&&(yield`${n}
198
+ `),e.networkHeader&&(yield e.name===null?`*Network
199
+ `:`*Network ${e.name}
200
+ `);const l=BR(t);yield l!==null&&!Number.isNaN(l)?`*Vertices ${t.nodeCount} ${l}
201
+ `:`*Vertices ${t.nodeCount}
202
+ `,yield*qce(t,i,r,e.mangle),yield*Qce(t,s)}function YR(t,e){return e?t.filter(n=>!(n.slot==="param"&&n.column.meta.name===yr)):t}function VR(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=Bi(l);vy(a)?n&&typeof Qa(a)!=typeof l&&s++:r++}r>0&&i.push(In(xt.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(xt.ID_TEXT_TYPE,`${s} original id${O(s)} ${C(s,"reads","read")} back from ${yr} as the other type under ids: "canonical" (a string "1" becomes 1, a number 1.5 becomes "1.5")`,null,s))}function*qce(t,e,n,i){const r=Jce(n),s=r.position!==null&&Xce(r.position);for(let o=0;o<t.nodeCount;o++){const l=Zce(r,o,s);if(i&&e.isChanged(o)&&l.push(`${yr} ${Ho(Bi(e.originalAt(o)))}`),r.spells!==null){const d=HR(r.spells,o);d!==null&&l.push(d)}const a=Vce(r.labels,e,o,l.length>0);let c=String(o+1);a!==null&&(c+=` ${Ho(Rae(a))}`),l.length>0&&(c+=` ${l.join(" ")}`),yield`${c}
203
+ `}}function Jce(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 Zce(t,e,n){const{position:i,shape:r}=t,s=[],o=i===null?null:Kce(i,e,n);o!==null&&s.push(o);const l=s.length>0,a=r?.isSet(e)===!0;if(a){const d=Ka(r,e);s.push(v0.has(d)?d:`${Pt} ${Ho(d)}`)}const c=s.length;for(const d of t.params)d.isSet(e)&&(l&&!a&&s.length===c&&IR.has(d.meta.name)&&s.push("ellipse"),s.push(`${d.meta.name} ${Ho(Ka(d,e))}`));return s}function*Qce(t,e){const n=Ut(t,{foldMutual:!0}),i=wt(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)?Ka(o,h):null;if(!f||g!==d||m!==u){d=g,u=m,f=!0;const _=g==="arcs"?"*Arcs":"*Edges";if(m===null)yield`${_}
204
+ `;else{let S=c.get(m);S===void 0&&(S=c.size+1,c.set(m,S)),yield`${_} :${S} ${Ho(m)}
205
+ `}}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} ${Ho(Ka(_,h))}`);if(l!==null){const _=HR(l,h);_!==null&&(y+=` ${_}`)}yield`${y}
206
+ `}f||(yield t.directed?`*Arcs
207
+ `:`*Edges
208
+ `)}function Fm(t,e){const n=dt(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 ede=Object.freeze({format:"pajek",options:Object.freeze(["name","networkHeader"]),capabilities:hh,styles:Object.freeze({capabilities:D0}),check(t,e){const n=zR(t,e?.styles);return n===null?$N(t,e):Object.freeze([...$N(n.snapshot,KR(e)),...n.notes])},export(t,e){return ei(IN(t,e))},exportToString(t,e){return ti(IN(t,e))}});function IN(t,e){const n=zR(t,e?.styles);return n===null?TN(t,Fm(t,e)):TN(n.snapshot,Fm(n.snapshot,KR(e)),n.comment)}function KR(t){return t?.sanitizeIds===void 0?{...t,sanitizeIds:"mangle"}:t}function tde(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===Pt;(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 nde(t,e,n){return Un(t,hh,e,{roles:kce,roleNames:Rce,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 $N(t,e){const n=dt(e),{mangle:i}=Fm(t,e),r=[],s=ju(t.nodes,"node",r),o=YR(s,i),l=ju(t.edges,"edge",r),a=bl(t,hh.idCharset,i?"mangle":"error");VR(t.nodeCount,a,i,r);const c=o.length===s.length?void 0:s.find(f=>f.slot==="param"&&f.column.meta.name===yr);c!==void 0&&r.push(In(xt.KEY_DROPPED,`node column "${yr}" is the parameter the exporter writes the original ids under (sanitizeIds "mangle"); it is not written`,yr,c.column.length-c.column.nullCount));const d=tde(t,[...o,...l]);r.push(...nde(t,n,d)),Bce(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));Fu(o,"node",r),Fu(l,"edge",r);const u=Ut(t,{foldMutual:!0});return u.mutualCount>0&&r.push(In(xt.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(BR(t))&&r.push(In(xt.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:bn,NO_VERTICES:"E_PAJEK_NO_VERTICES",VERTICES_COUNT:"E_PAJEK_VERTICES_COUNT",MULTIPLE_GRAPHS:Zn,GRAPH_NOT_FOUND:wr,AMBIGUOUS_GRAPH_NAME:ss,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:lf,COLUMN_RENAMED:Za,ROLE_TAKEN:yn,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:de,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:ie,TRAILING_VALUE:"W_PAJEK_TRAILING_VALUE",NAN_VALUE:"W_PAJEK_NAN_VALUE"}),CN=new Set(["ids","nodeIdFrom","restoreMangledIds","addMissingNodes","duplicateEdges","selfLoops","onMixedDirection","defaultDirected","weightFrom","weightDtype","errorLimit","signal","onProgress"]),vN={ids:"canonical",defaultDirected:!0,weightFrom:wR},DN=64,ide=new Set([0,1,"auto"]),rde=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,sde=/^[+-]?(?:nan|inf|infinity)$/i,ode=/^[+-]?nan$/i,lde={name:gi,dtype:"string",nullable:!0,role:"label",origin:{format:"pajek",id:"label"}},ade={name:Pt,dtype:"dict",nullable:!0,origin:{format:"pajek",id:"shape"}},cde={name:bR,dtype:"dict",nullable:!0,origin:{format:"pajek",id:"relation"}};function kN(){return{name:Eae,dtype:"list",itemDtype:"f64",itemComponents:2,nullable:!0,role:"spells",origin:{format:"pajek",id:"interval"}}}function dde(t,e){return{name:yR,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 zm={width:ns,height:ns};class St extends Error{constructor(e,n,i){super(i),this.name="PajekLineError",this.category=e,this.code=n}}function ude(t){return Number.isInteger(t)&&t>=-2147483648&&t<=2147483647}const fde=/^-?\d+$/,hde=/^(\d+):$/;class RN{constructor(e,n,i,r,s=zm){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 Qn(e,n,i.onMixedDirection),this.coercer=new Mn(i.ids)}comment(e){if(this.styleBlockKept)return;const n=e.trimStart();n.startsWith(Mm)&&(this.styleBlockKept=!0,this.keptBlock=n.slice(Mm.length),this.report.keepForStyles(this.keptBlock))}line(e,n){if(OR(e))return this.comment(e),!1;const i=this.objectHeader;this.objectHeader=!1;try{if(NR(e))return this.header(e,n,i),this.ended;switch(this.section){case"none":throw new St("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 St?(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?wae:_ae,null,u=>e.has(u));e.add(o);const{handle:l,decl:a}=fe(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=AR(e);if(s===null)throw this.section="skip",new St("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=SR(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 rf(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&&!mde(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&&xm(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&&IR.has(f.keys[0])&&this.voided.push(g),l!==null&&(this.labelHandle=this.nodeHandle(this.labelHandle,lde,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,kN(),n),this.sink.setNodeValue(this.nodeSpellsHandle,g,f.spells))}vertexNumber(e,n){if(!Rp(e[0]))throw this.report.counts.skippedNodes++,new St("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 St("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&&li(e[n])&&li(e[n+1])){const r=Number(e[n]),s=Number(e[n+1]);return n+2<e.length&&li(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&&li(e[n]))throw this.report.counts.skippedNodes++,new St("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 ${yr} ${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?fe(this.sink,"node",n,this.report,{line:i}).handle:e}writeShape(e,n,i){if(this.shapeHandle===A&&this.nodeParams.has(Pt)){this.writeParameter("node",Pt,e,n);return}this.shapeHandle=this.nodeHandle(this.shapeHandle,ade,i),this.sink.setNodeValue(this.shapeHandle,e,n)}labelOf(e,n,i){return kae(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&&(rde.test(n[i])||sde.test(n[i]))&&!li(n[i]))throw this.report.counts.skippedNodes++,new St("parse-error",q.VERTEX_LINE,`vertex ${s}: coordinate "${n[i]}" is not a finite number`);const l=n[1];r&&li(l)&&!Number.isInteger(Number(l))&&!XR(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=fe(this.sink,"node",dde(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(yr);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 ${yr} ${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=hde.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||!Rp(i[0])||!Rp(i[1]))throw this.report.counts.skippedEdges++,new St("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&&li(i[a])?(c=i[a],a++):a<i.length&&ode.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(by(wR,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",ER,p,c),this.writeEdgeExtras(p,d,r)}listLine(e,n){const i=this.tokens(e,"edge",n);for(const s of i)if(!fde.test(s))throw this.report.counts.skippedEdges++,new St("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 St("validation-error",q.MATRIX_ROWS,`*Matrix row ${r+1} is beyond the ${o} declared row${O(o)}`);if(i.length<l)throw new St("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(!li(i[a]))throw new St("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(!li(s)||i.kind==="partition"&&!ude(Number(s)))throw i.values.push(null),new St("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=fe(r,"edge",kN(),this.report).handle),r.setEdgeValue(this.edgeSpellsHandle,e,n.spells))}writeRelation(e,n=this.relation){n!==null&&(this.relationHandle===A&&(this.relationHandle=fe(this.sink,"edge",cde,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 St("missing-value",q.UNKNOWN_NODE,`vertex ${e} is outside ${this.base}..${this.base+this.vertexCount-1}`);return n}weightOf(e){try{return Vn(e,this.report)}catch(n){throw this.report.counts.skippedEdges++,n}}tokens(e,n,i){const r={oddQuote:!1},s=_R(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 St("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"&&xm(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=pde.has(a)?gde(e,l+1):null;s.values.push(c??e[l+1]),l+=c===null?2:4}return s}loneLastToken(e,n,i){if(li(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 St("parse-error",n==="node"?q.VERTEX_LINE:q.LINE,`parameter "${e}" has no value`)}intervals(e,n,i){if(!Cae(e))throw this.skip(n),new St("validation-error",q.INTERVAL,`time interval ${e} is not closed by "]"`);try{const r=vae(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===Pt&&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 Ey(n,e,this.sink,this.report),s.set(n,o)),o.write(i,r)}}const pde=new Set(["ic","bc","lc","c"]);function gde(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 mde(t,e){if(XR(t,e))return!1;let n=0;for(;1+n<e.length&&li(e[1+n]);)n++;return n===2}function XR(t,e){return t.trimStart().slice(e[0].length).trimStart().startsWith('"')}function LN(t){if(t===void 0)return"auto";if(ide.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 qR=Object.freeze({format:"pajek",options:Object.freeze(["firstVertex","pajekDraw"]),extensions:Object.freeze([".net",".paj"]),mimeTypes:Object.freeze(["text/x-pajek","text/plain"]),styles:cce,positions(t){return t.nodes.byRole("position")!==null?null:{units:"file",pxPerUnit:ns,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(eo(n))return $b(qR,t,e,n);const i=Qe(n,vN),r=LN(n?.firstVertex),s=yN(n?.pajekDraw),o=new te("pajek",i.errorLimit);bt(e,n,o),Et(n,o,CN);const l=new RN(e,o,i,r,s??zm),a=new Up(t,o,i);let c=null,d=0,u=0;for await(const f of a){const h=PN(f);c!==null?c.line(h):l.line(h,a.line)&&(c=new bde,c.line(h),d=a.line),++u>=DN&&(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=Qe(n,vN),r=LN(n?.firstVertex),s=yN(n?.pajekDraw),o=[new te("pajek",i.errorLimit)];Et(n,o[0],CN);const l=()=>{const f=o[o.length-1],h=e(o.length-1);return bt(h,n,f),new RN(h,f,i,r,s??zm)},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 Up(t,o[0],i);let u=0;for await(const f of d){const h=PN(f);c.line(h,d.line)&&(a(c),o.push(new te("pajek",i.errorLimit)),c=l(),c.line(h,d.line)),++u>=DN&&(u=0,F(i.signal))}return a(c),F(i.signal),o.map(f=>f.finish())}});function PN(t){return t.codePointAt(0)===65279?t.slice(1):t}class bde{constructor(){this.count=0,this.objects=0,this.named=!1,this.populated=!1,this.afterObjectHeader=!1}line(e){if(OR(e))return;const{afterObjectHeader:n}=this;if(this.afterObjectHeader=!1,!NR(e))return;const i=AR(e);if(i===null)return;const{kind:r}=i;r==="partition"||r==="vector"?(this.afterObjectHeader=!0,this.objects++):r==="unsupported"?this.afterObjectHeader=SR(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 Ede=String.raw`\n or \t`,JR=Xe({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}),wde=new Set(["label","id","parent","parents","position"]),_de=Object.freeze({label:Bs,id:Jo,parent:lc,position:Nl}),Sde=new Set(["color","size","shape","thickness","start","end","timestamp","timestamps","spells","open","spellsOpen"]),Ode={node:new Set(["id","label","name"]),edge:new Set(["id","label","name","source","target","weight"])},Nde=new Set(["directed","pair","mutual","weight","parent","parents","position"]),Ade=new Set([Bs,Nl,ro,Qt,lc,Nf,Hs,ac,Zo,_a]),Tde=new Set([Jo,Bs,Qt]),Ide={graph:new Set([Qt]),node:Ade,edge:Tde},$de=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"]),ZR=2147483647;function Wm(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 QR(t)>ZR?["integer","Long"]:["integer","Integer"];case"f32":case"f64":return t.meta.origin?.type==="long"&&Cde(t)?["integer","Long"]:["real","Double"];default:return["string","String"]}}function Cde(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 QR(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 Hl(t,e){const{origin:n}=t.meta;return n!==null&&n.namespace===e}function Lp(t,e,n,i){const r=[],s=Ide[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&&(Nde.has(a.role)||Sde.has(a.role)||a.role==="id"||a.role==="timeText"))continue;const c=vde(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"&&Lde(l,e,i);const u=a.dtype==="list"?a.itemDtype:a.dtype,[f,h]=a.dtype==="list"?["list","List"]:Rde(l,Wm(l,u));r.push({column:l,name:a.name,kind:c,type:f,cyType:h,elementType:a.dtype==="list"?Wm(l,u)[1]:null})}return r}function vde(t,e,n){const{meta:i}=t;return e!=="graph"&&kde(t,e)?"xml":i.role==="label"||!n&&e!=="graph"&&i.role===null&&i.name===Bs&&(i.dtype==="string"||i.dtype==="dict")?"label":i.dtype==="json"&&i.name===Qt&&Hl(t,hn)?"graphics":e!=="node"?"att":Dde(t)}function Dde(t){const{meta:e}=t;return e.name===ro&&e.dtype==="f64"&&e.role===null?"z":e.name===Hs&&e.dtype==="json"&&Hl(t,hn)?"subgraph":e.name===ac&&e.dtype==="string"&&Hl(t,Af)?"nested":e.name===Zo&&e.dtype==="string"&&Hl(t,hn)?"pointer":e.name===_a&&e.dtype==="list"&&Hl(t,hn)?"networks":"att"}function kde(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)&&!Ode[e].has(n.name)}function Rde(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 Lde(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(dn.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(dn.WIDENED_TYPE,`${s} (${o}) is written as a wider Cytoscape type and reads back as ${Pde(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(dn.BACKSLASH_ESCAPE,`${s}: ${l} value${O(l)} ${C(l,"holds","hold")} a literal ${Ede}, 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 Qs;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(dn.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 Pde(t,e){return e==="u8"||e==="u32"&&QR(t)<=ZR?"i32":"f64"}function eL(t,e,n){const i=Un(t,JR,e,{roles:wde,roleNames:_de,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(...Cy(t));const s=Ut(t);s.mutualCount>0&&r(dn.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=jde(t);o>0&&r(dn.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(dn.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=ec(t);a.unreachable>0&&r(dn.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(dn.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&&!Ude(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&&Gde(d,t,r),xde(t,r);const u=wt(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:Lp(t.graph,"graph",t,r),nodes:Lp(t.nodes,"node",t,r),edges:Lp(t.edges,"edge",t,r),folding:s,weights:u,hierarchy:a,reachable:Mde(t.nodeCount,a),position:d,edgeId:l}}function xde(t,e){const n=t.edges.byRole("label")??t.edges.get(Bs);if(n===null||t.edges.get(ql)!==null)return;let i=0;for(let r=0;r<n.length;r++)n.isSet(r)&&Ag(dl(n.value(r)))!==null&&i++;i>0&&e(dn.INTERACTION_FROM_LABEL,`${i} edge label${O(i)} ${C(i,"has","have")} Cytoscape's "a (i) b" shape and read back with an "${ql}" column`,ql,i)}function Mde(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 Ude(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 Gde(t,e,n){const{meta:i}=t;i.components!==3&&n(dn.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(dn.POSITION,`${r} position${O(r)} with a non-finite coordinate ${C(r,"is","are")} not written`,i.name,r);const o=e.nodes.get(ro);s>0&&n(dn.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 jde(t){let e=0;for(let n=0;n<t.nodeCount;n++)typeof t.ids.idOf(n)=="number"&&e++;return e}function Gd(t,e){return e===null?"":` ${t}="${e}"`}function Bm(t){return t.map(([e,n])=>` ${e}="${W(String(n))}"`).join("")}function xN(t,e,n){let i;return typeof t=="boolean"?i=t?"1":"0":typeof t=="number"?i=e==="f32"?lt(t):je(t):typeof t=="string"?i=n?t.replaceAll(`
209
+ `,String.raw`\n`).replaceAll(" ",String.raw`\t`):t:ArrayBuffer.isView(t)?i=JSON.stringify(Array.from(t)):i=JSON.stringify(t)??"",W(i)}function dl(t){return typeof t=="string"?t:typeof t=="number"?je(t):typeof t=="boolean"?t?"true":"false":JSON.stringify(t)??""}function tL(t,e){let n="";for(const i of t)i.kind==="xml"&&i.column.isSet(e)&&(n+=` ${i.name}="${W(dl(i.column.value(e)))}"`);return n}function*M0(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=Gd("type",s.type)+Gd("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}${Gd("cy:elementType",s.elementType)}${d}/>
210
+ `;continue}if(o.dtype==="list"){const u=[...o.sliceOf(e)],[f,h]=Wm(o,o.meta.itemDtype);if(yield`${a}${c} cy:elementType="${s.elementType??"String"}"${d}${u.length===0?"/>":">"}
211
+ `,u.length>0){for(const p of u)yield`${r} <att name="${W(s.name)}" value="${xN(p,o.meta.itemDtype,i.escapes)}" type="${f}" cy:type="${h}"/>
212
+ `;yield`${r}</att>
213
+ `}continue}yield`${a} value="${xN(o.value(e),o.dtype,i.escapes)}"${c}${d}/>
214
+ `}}function*U0(t,e,n){const i=[...e],r=[];for(const[o,l]of Object.entries(t??{}))o==="Line"?r.push([o,l]):typeof l=="string"&&($de.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${Bm(i)}`;if(r.length===0){yield`${s}/>
215
+ `;return}yield`${s}>
216
+ `;for(const[o,l]of r)if(o==="Line"&&Array.isArray(l)){yield`${n} <Line>
217
+ `;for(const a of l){const c=typeof a=="object"&&a!==null?Object.entries(a):[];yield`${n} <point${Bm(c)}/>
218
+ `}yield`${n} </Line>
219
+ `}else yield*zu(o,l,`${n} `);yield`${n}</graphics>
220
+ `}function*zu(t,e,n){const i=t===null?"":` name="${W(t)}"`;if(Array.isArray(e)){yield`${n}<att${i} type="list">
221
+ `;for(const r of e)yield*zu(t,r,`${n} `);yield`${n}</att>
222
+ `}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}${Bm(r)}/>
223
+ `;return}yield`${n}<att${i}>
224
+ `;for(const[s,o]of r)yield*zu(s,o,`${n} `);yield`${n}</att>
225
+ `}else e==null?yield`${n}<att${i} type="string"/>
226
+ `:yield`${n}<att${i} value="${W(dl(e))}" type="string"/>
227
+ `}function Di(t,e){return t.find(n=>n.kind===e)?.column??null}function mi(t,e){return t?.isSet(e)?t.value(e):null}function Fde(t,e,n){const i=zde(t,e,n),r=mi(e,n);return typeof r=="number"&&i.push(["z",je(r)]),i}function zde(t,e,n){const i=mi(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"?lt:je,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*Wde(t,e,n,i){yield`${i}<att name="__isGroup" value="1" type="boolean" cy:type="Boolean" cy:hidden="1"/>
228
+ `;const r=typeof e.id=="string"?` id="${W(e.id)}"`:"",s=typeof e.label=="string"?` label="${W(e.label)}"`:"";yield`${i}<att>
229
+ ${i} <graph${r}${s}>
230
+ `;const o=typeof e.atts=="object"&&e.atts!==null?Object.entries(e.atts):[];for(const[l,a]of o)yield*zu(l,a,`${i} `);for(const l of n)yield`${i} <node xlink:href="#${W(Bi(t.ids.idOf(l)))}"/>
231
+ `;yield`${i} </graph>
232
+ ${i}</att>
233
+ `}function*Bde(t,e,n,i,r){const s=Di(e.nodes,"label"),o=mi(s,n),l=o===null?"":` label="${W(dl(o))}"`;yield`${i}<node id="${W(Bi(t.ids.idOf(n)))}"${l}${tL(e.nodes,n)}>
234
+ `;const a=`${i} `;yield*M0(e.nodes,n,n===0,e,a);const c=e.reachable[n]===1?e.hierarchy.childrenOf(n):[],d=mi(Di(e.nodes,"nested"),n),u=mi(Di(e.nodes,"pointer"),n),f=mi(Di(e.nodes,"subgraph"),n);c.length>0||f!==null?yield*Wde(t,f??{},c,a):typeof d=="string"?yield`${a}<att>
235
+ ${a} <graph label="${W(d)}"/>
236
+ ${a}</att>
237
+ `:typeof u=="string"&&(yield`${a}<att>
238
+ ${a} <graph xlink:href="${W(u)}"/>
239
+ ${a}</att>
240
+ `);const h=mi(Di(e.nodes,"graphics"),n),p=r===void 0?h:EI("node",r,n,h);yield*U0(p,Fde(e,Di(e.nodes,"z"),n),a),yield`${i}</node>
241
+ `}function*MN(t,e){const n=Kde(t,e),i=e?.styles,r=t.meta.extra[uI],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"?>
242
+ `,yield`<graph${s}${a} directed="${l}" cy:documentVersion="3.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="${nb}" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cy="${dI}" xmlns="${wa}">
243
+ `,yield*Hde(t),yield*M0(n.graph,0,!0,n," ");const c=mi(Di(n.graph,"graphics"),0);yield*U0(i===void 0?c:yG(i,c),[]," ");for(let d=0;d<t.nodeCount;d++)yield*Bde(t,n,d," ",i);yield*Yde(t,n),yield*Vde(t,n,i),yield`</graph>
244
+ `}function*Hde(t){const{name:e,description:n,created:i}=t.meta;n===null&&i===null||(yield` <att name="networkMetadata">
245
+ <rdf:RDF>
246
+ <rdf:Description rdf:about="http://www.cytoscape.org/">
247
+ `,e!==null&&(yield` <dc:title>${et(e)}</dc:title>
248
+ `),n!==null&&(yield` <dc:description>${et(n)}</dc:description>
249
+ `),i!==null&&(yield` <dc:date>${et(i)}</dc:date>
250
+ `),yield` </rdf:Description>
251
+ </rdf:RDF>
252
+ </att>
253
+ `)}function*Yde(t,e){const n=Di(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>
254
+ <graph id="${W(r)}">
255
+ `;for(const o of s)yield` <node xlink:href="#${W(Bi(t.ids.idOf(o)))}"/>
256
+ `;yield` </graph>
257
+ </att>
258
+ `}}function*Vde(t,e,n){const{folding:i,weights:r}=e,s=Di(e.edges,"label"),o=Di(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=mi(e.edgeId,c),p=mi(s,c),g=r.text(c),m=h===null?"":` id="${W(dl(h))}"`,y=p===null?"":` label="${W(dl(p))}"`,b=W(Bi(t.ids.idOf(d))),_=W(Bi(t.ids.idOf(u)));yield` <edge${m}${y} source="${b}" target="${_}" cy:directed="${f?"1":"0"}"${Gd("weight",g)}${tL(e.edges,c)}>
259
+ `,yield*M0(e.edges,c,a,e," ");const S=mi(o,c);yield*U0(n===void 0?S:EI("edge",n,c,S),[]," "),yield` </edge>
260
+ `,a=!1}}function nL(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 Kde(t,e){const n=eL(t,dt(e),nL(e)),i=n.notes.find(r=>r.code===dn.XML_ILLEGAL_CHAR);if(i!==void 0)throw new N("E_COLUMN_TYPE",i.message,{code:i.code,column:i.column});return n}const Xde=Object.freeze({format:Ht,options:Object.freeze(["cytoscapeEscapes"]),capabilities:JR,styles:Object.freeze({capabilities:bI}),check:(t,e)=>Object.freeze([...eL(t,dt(e),nL(e)).notes,...e?.styles===void 0?[]:mG(e.styles,t)]),export:(t,e)=>ei(MN(t,e)),exportToString:(t,e)=>ti(MN(t,e))}),G0=[{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}],j0=["expand","probe","validate","page"],Xa={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"}]},qde=Object.freeze({plainName:"Cypher database",kind:"database",version:1,auth:["basic","bearer","aws-sigv4"],authRequired:"optional",features:j0,params:[...G0,Xa]}),Jde=Object.freeze({plainName:"Neo4j",kind:"database",version:1,auth:["basic","bearer"],authRequired:"optional",features:j0,params:[...G0,{...Xa,values:Xa.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}]}),Zde=Object.freeze({plainName:"Amazon Neptune",kind:"database",version:1,auth:["aws-sigv4"],authRequired:"optional",features:j0,params:[...G0,{...Xa,values:Xa.values?.filter(t=>t.value.startsWith("neptune"))}],runtimes:{browser:{supported:!1,reason:"cors"},worker:{supported:!1,reason:"cors"}}}),Dpe=Object.freeze({E_FETCH:dA,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"}),Qde="ndex",eue="cypher",tue="neo4j",nue="neptune",iue="rest",rue="openalex",sue="sparql",kpe="_source.stub",Rpe="_source.entity",Lpe="_source.degree",oue="source:",lue={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 be(t,e,n,i){return t.fork().failWith(lue[e]??"unsupported",e,n,void 0,i,i)}function da(t,e,n,i="source"){be(new te(i,0),t,e,n)}function Hm(t,e,n,i){t.warning("unsupported",e,n,void 0,i)}const aue=/^[a-z0-9]+(-[a-z0-9]+)*$/,cue=[["expand","expand"],["probe","probe"],["list","list"],["validate","validate"]];function Wu(t,e,n){da("E_SOURCE_INVALID",n,{id:t,reason:e})}function iL(t){(typeof t!="string"||!aue.test(t))&&Wu(String(t),"id",`source id ${JSON.stringify(t)} must be lowercase letters, digits and dashes`)}function due(t){return cue.filter(([,e])=>typeof t[e]=="function").map(([e])=>e)}function jd(t,e){iL(t.id),["records","file","import"].filter(r=>typeof t[r]=="function").length!==1&&Wu(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(due(t));for(const s of i)s!=="page"&&!r.has(s)&&Wu(t.id,"features",`source ${t.id} declares ${s} but has no ${s} method`)}}function uue(t){iL(t.id),(typeof t.load!="function"||typeof t.descriptor!="object")&&Wu(t.id,"lazy",`lazy source ${t.id} needs a descriptor and a load function`)}function Ppe(t){return jd(t),t}function fue(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 hue(t){let e;try{e=new URL(typeof t=="string"?t:"")}catch{return"type"}return e.username!==""||e.password!==""?"credentials-in-url":null}function pue(t,e){switch(t.type){case"integer":case"number":return fue(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 hue(e);default:return null}}function gue(t,e,n){(typeof t!="object"||t===null)&&be(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=pue(i,r),o!==null&&be(n,"E_SOURCE_PARAM",`parameter ${i.name}: ${o}`,{name:i.name,reason:o})}}const mue=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 rL(t){return mue.get(t)}async function bue(t,e){const n=rL(t);if(n===void 0)return da("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 Rr(async()=>{const{signRequest:r}=await import("./sigv4-EokFic1V-CWJiFeEe.js");return{signRequest:r}},[],import.meta.url);return i(e,n.options)}case"custom":return n.apply(e);default:return e}}function xpe(t){const e=rL(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 us(t,e,n,i,r){return{id:t,plainName:e,params:{uuid:n},counts:{nodes:i,edges:r}}}const Eue=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:[us("ndex-wp5483","WikiPathways WP5483","86719f5b-1439-11f0-9806-005056ae3c32",57,34),us("ndex-nci-pid","NCI PID cancer signaling","640e2cef-795d-11e8-a4bf-0ac135e8bacf",2794,25296),us("ndex-huri","HuRI human interactome","73bc2c06-5fb2-11e9-9f06-0ac135e8bacf",8275,52569),us("ndex-signor","Signor","523fff27-afe8-11e9-8bb4-0ac135e8bacf",10339,33381),us("ndex-dgidb","DGIdb drugs and target genes","7e5e64ff-f6cf-11ea-99da-0ac135e8bacf",12100,32814),us("ndex-wikipathways-landscape","WikiPathways landscape","2b3ed6af-5031-11eb-9e72-0ac135e8bacf",32077,74109),{...us("ndex-pcnet","PCNet 2.2","8b4b54fa-e87d-11ee-9621-005056ae23aa",18558,3323928),whole:!1}]}),UN=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"}}}}),GN=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"}}}}),wue=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:GN,identifiers:"TP53",species:"9606",add_nodes:"20"},endpoint:GN.endpoint,counts:{nodes:21,edges:113}},{id:"deps-dev-webpack",plainName:"deps.dev: webpack 5.90.0",params:{mapping:UN,system:"npm",package:"webpack",version:"5.90.0"},endpoint:UN.endpoint,counts:{nodes:84,edges:121}}]}),_ue=Object.freeze({plainName:"OpenAlex",kind:"rest",version:1,defaultEndpoint:"https://api.openalex.org",auth:["api-key"],authRequired:"optional",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}]}),Sue=`PREFIX wd: <http://www.wikidata.org/entity/>
261
+ PREFIX wdt: <http://www.wikidata.org/prop/direct/>
262
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
263
+ CONSTRUCT { ?person wdt:P184 ?advisor . ?person rdfs:label ?name . ?advisor rdfs:label ?advisorName . }
264
+ WHERE {
265
+ ?person wdt:P166 wd:Q38104 ; wdt:P184 ?advisor ; rdfs:label ?name .
266
+ ?advisor rdfs:label ?advisorName .
267
+ FILTER(lang(?name) = "en" && lang(?advisorName) = "en")
268
+ }`,Oue=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:Sue,pageSize:100,language:"en",predicates:["http://www.wikidata.org/prop/direct/"]}}]}),Nue=new Set([429,502,503,504]),Aue=new Set([101,204,205,304]),Tue=new Set([301,302,303,307,308]),Iue=5;class qa extends Error{constructor(e,n){super(`${e} reached at ${String(n)}`),this.limit=e,this.value=n,this.name="LimitStop"}}function sL(){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 Ym(t){const e=t.replaceAll(/(?:^\[)|(?:\]$)/g,"").toLowerCase();return e==="localhost"||e.endsWith(".localhost")||/^127(\.\d{1,3}){3}$/.test(e)||e==="::1"}function jN(t){const e=t.replaceAll(/(?:^\[)|(?:\]$)/g,"").toLowerCase();return Ym(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 FN=new Map;function od(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 zN(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 $ue(t,e){return t===void 0?[]:t.origins.length>0?t.origins:e===null?[]:[Wn(e)]}class Cue{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??sL(),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=$ue(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{be(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"&&be(i,"E_SOURCE_LIMIT",`${e} of ${String(n)} reached`,{limit:e,value:n}),this.warnedLimits.has(e)||(this.warnedLimits.add(e),Hm(i,"W_SOURCE_LIMIT",`${e} reached at ${String(n)}; what came first is kept`,{limit:e,value:n})),new qa(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 qa))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 be(n,"E_SOURCE_PARAM","a relative URL needs an endpoint",{name:"endpoint",reason:"missing"})}(r.username!==""||r.password!=="")&&be(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&&!Ym(r.hostname)&&be(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=FN.get(i)??{active:0,times:[],waiters:[]};for(FN.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 od(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||Aue.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 be(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 be(i,"E_SOURCE_FORBIDDEN",`${s} answered 403`,{status:r,serverCode:null});case 404:return be(i,"E_SOURCE_NOT_FOUND",`${s} answered 404`,{what:"url",value:s});case 429:return be(i,"E_SOURCE_QUOTA",`${s} answered 429`,{retryAfterMs:zN(e)});default:return be(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 bue(r.credential,f),p=new URL(h.url);return Wn(p)!==Wn(e)&&be(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&&!Ym(e.hostname)&&r.allowInsecure!==!0&&be(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||!Tue.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>=Iue?be(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&&!jN(n.hostname)&&jN(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 be(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 od(this.backoff(0),this.signal),!0):be(l,"E_SOURCE_BLOCKED",`the browser refused ${Fn(n)}`,{url:Fn(n),cause:a})}return i<r?(await od(this.backoff(i),this.signal),!0):be(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(!Nue.has(c.status)||a>=o)return this.settle(c,i,n,a,l);l.push(c.status);const d=zN(c);await c.body?.cancel().catch(()=>{}),await od(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;Hm(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 be(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 oL=new WeakMap;function Mpe(t){const e=oL.get(t)??{};return{credential:e.credential,allowInsecure:e.allowInsecure,userAgent:e.userAgent}}function vue(t){const e=new Cue(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 oL.set(i,t.options),{ctx:i,state:e.state,info:r=>e.info(r),dispose:()=>{e.dispose()}}}const Bu="__Annotations",F0="org.cytoscape.view.presentation.annotations.",Due=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"]]),lL=["circle","triangle","vee","diamond","triangle-open","none","other:x","triangle","tee"],WN=[10,17,17,17,17,0,10,5,0],kue=10,Rue=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 Lue(t){const{graph:e}=t,n=e.has(Bu)?e.value(Bu,0):null,r=aL(n).map(cL),s=new Map(r.map((a,c)=>[a.get("uuid")??String(c),a])),o=[],l=new Set;return r.forEach((a,c)=>{const d=xue(a,String(c),s);d===null?l.add((a.get("type")??"").replace(F0,"")):o.push(...d)}),{annotations:o,skipped:[...l]}}function Pue(t){const{graph:e}=t,n=e.has(Bu)?e.value(Bu,0):null;return aL(n).flatMap((i,r)=>{const s=cL(i),o=s.get("URL")??"";if((s.get("type")??"").replace(F0,"")!=="ImageAnnotation"||o==="")return[];const l=fn(s.get("zoom"))??1,a=Ie(s.get("x"))??0,c=Ie(s.get("y"))??0,d=(fn(s.get("width"))??0)/l,u=(fn(s.get("height"))??0)/l,f=Ms(s.get("edgeColor"))??{color:"#000000",alpha:1},h=Ie(s.get("opacity"));return[{id:s.get("uuid")??String(r),layer:s.get("canvas")==="background"?"background":"foreground",z:Ie(s.get("z"))??0,kind:"image",rotation:Ie(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*Hu(s.get("edgeOpacity")),borderWidth:(Ie(s.get("edgeThickness"))??0)/l}]})}function aL(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 cL(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 xue(t,e,n){const i=(t.get("type")??"").replace(F0,""),r=fn(t.get("zoom"))??1,s={id:t.get("uuid")??e,layer:t.get("canvas")==="background"?"background":"foreground",z:Ie(t.get("z"))??0};switch(i){case"ShapeAnnotation":return[BN(t,s,r)];case"TextAnnotation":return[HN(t,s,r,{x:Ie(t.get("x"))??0,y:-(Ie(t.get("y"))??0)},"top-left")];case"BoundedTextAnnotation":{const o=BN(t,s,r);return[o,HN(t,{...s,id:`${s.id}:text`},r,o.center,"center")]}case"ArrowAnnotation":return Mue(t,s,r,n);default:return null}}function BN(t,e,n){const i=Ie(t.get("x"))??0,r=Ie(t.get("y"))??0,s=(fn(t.get("width"))??0)/n,o=(fn(t.get("height"))??0)/n,l=Ms(t.get("fillColor")),a=Ms(t.get("edgeColor"))??{color:"#000000",alpha:1};return{...e,kind:"shape",rotation:Ie(t.get("rotation"))??0,center:{x:i+s/2,y:-(r+o/2)},width:s,height:o,shape:Due.get((t.get("shapeType")??"rectangle").toLowerCase())??"rectangle",fill:l?.color??null,fillOpacity:l===null?0:l.alpha*Hu(t.get("fillOpacity")),borderColor:a.color,borderOpacity:a.alpha*Hu(t.get("edgeOpacity")),borderWidth:(Ie(t.get("edgeThickness"))??1)/n}}function HN(t,e,n,i,r){const s=Ie(t.get("fontStyle"))??0,o=Ms(t.get("color"))??{color:"#000000",alpha:1};return{...e,kind:"text",rotation:Ie(t.get("rotation"))??0,text:t.get("text")??"",at:i,anchor:r,fontSize:(fn(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 Mue(t,e,n,i){const r=VN(i.get(t.get("sourceAnnotation")??""),n),s=VN(i.get(t.get("targetAnnotation")??""),n),o=XN(t.get("targetPoint"))??XN(t.get("targetNode")),l={x:Ie(t.get("x"))??0,y:Ie(t.get("y"))??0},a=r===null?l:Vm(r),c=o??(s===null?null:Vm(s));if(c===null)return null;const d=r!==null&&r.width>0&&r.height>0?KN(r,c):{x:c.x>l.x?l.x:a.x,y:c.y>l.y?l.y:a.y},u=o??KN(s??{x:c.x,y:c.y,width:0,height:0},a),f=Ms(t.get("lineColor"))??{color:"#000000",alpha:1},h=Ms(t.get("sourceColor"))?.color??f.color,p=Ms(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*Hu(t.get("lineOpacity")),width:Math.max(1,(fn(t.get("lineThickness"))??1)/n/2),sourceArrow:Km(t.get("sourceType")),targetArrow:Km(t.get("targetType")),sourceSize:fn(t.get("sourceSize"))??1,targetSize:fn(t.get("targetSize"))??1,sourceColor:h,targetColor:p,...YN("source",t.get("sourceType"),fn(t.get("sourceSize"))??1),...YN("target",t.get("targetType"),fn(t.get("targetSize"))??1)}]}function YN(t,e,n){const i=Km(e);if(i==="none")return{};const r=Ie(e)??lL.indexOf(i),s=WN[r]??WN[1];return{[`${t}HeadLength`]:s*n,[`${t}HeadWidth`]:kue*n}}function VN(t,e){if(t===void 0)return null;const n=Ie(t.get("x")),i=Ie(t.get("y"));return n===null||i===null?null:{x:n,y:i,width:(fn(t.get("width"))??0)/e,height:(fn(t.get("height"))??0)/e}}function Vm(t){return{x:t.x+t.width/2,y:t.y+t.height/2}}function KN(t,e){const n=Vm(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 Km(t){if(t===void 0)return"none";const e=Ie(t);return e!==null?lL[e]??"triangle":Rue.get(t.trim().toLowerCase())??"triangle"}function XN(t){const[e,n]=(t??"").split(",").map(i=>Ie(i));return e==null||n===null||n===void 0?null:{x:e,y:n}}function Ms(t){const e=Ie(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 Hu(t){const e=Ie(t);return e===null?1:Math.min(1,Math.max(0,e/100))}function Ie(t){if(t===void 0||t.trim()==="")return null;const e=Number(t);return Number.isFinite(e)?e:null}function fn(t){const e=Ie(t);return e!==null&&e>0?e:null}function Ec(t){return t==null?"\0null":`${typeof t}:${String(t)}`}function Uue(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=Ec(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 Gue(t){let e=2166136261;for(const n of t)e=Math.imul(e^n,16777619);return e>>>0}function jue(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 Fue(t){const e=new Map,n=[];for(const[i,r]of t){const{blocks:s,k:o}=Uue(r),l=Gue(s),a=e.get(l)??[],c=a.find(f=>jue(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 z0=8,zue=256,Wue=.2;function Bue(t,e,n,i){const r=t.styled.length;if(!e.categorical||e.raw||r<z0||e.distinct<2||e.distinct>Math.min(zue,r/2)||e.distinct>=.9*n)return null;i(n);const{values:s}=e.feature,{votes:o,nullBlocks:l}=Hue(t,s),{table:a,exceptions:c}=Yue(o);let d=c;const u=Vue(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,Wue*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 Hue(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=Ec(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 Yue(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 Vue(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(Ec(o)))return null;r||=o===null||o===!1}}return r}const dL=64,Kue=4,Xue=new Set(["width","height"]),uL="class";function que(t){const e=new Set;for(const n of t)if(e.add(Ec(n)),e.size>dL+1)return!1;return!0}function Jue(t,e,n){let i="",r=!1;for(const s of t){const o=(e.get(s)??[])[n]??null;r||=o!==null,i+=`${Ec(o)}`}return r?i:null}function Zue(t,e,n,i,r){const s=e.filter(g=>ni[t].get(g)!=="text"&&!Xue.has(g)&&que(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=Jue(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>dL)return null}else y.count++}if(o.size===0||a<z0||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:uL},h=(g,m)=>(n.get(g)??[])[m]??null,p=[];if(c.length<=Math.min(Kue,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 Que=8,efe=4096,tfe=/^#[0-9a-f]{6}$/;function nfe(t){return typeof t=="number"||typeof t=="string"&&tfe.test(t)}function ife(t,e,n,i){const r=[];let s=0;for(;s<t.length;){let o=s;for(;o+1<t.length;){const l=rfe(t,e,s,o+1,n);if(i(o+1-s),!l)break;o++}if(r.push([s,o]),r.length>Que)return null;s=o+1}return r}function rfe(t,e,n,i,r){for(let s=n+1;s<i;s++){const o=m1(e[n],e[i],(t[s]-t[n])/(t[i]-t[n]));if(r?!jy(o,e[s]):o!==e[s])return!1}return!0}function sfe(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 ofe(t,e,n,i){if(!e.numeric||e.raw||t.styled.length<z0)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=lfe(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 lfe(t,e,n,i,r){const s=new Map;for(const o of t.props){const l=afe(t,e,n.get(o)??[],i,r);if(l===null)return null;s.set(o,l)}return s}function afe(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(!nfe(u)||h!==void 0&&h!==u){o=!1;break}s.set(f,u)}if(r(t.styled.length),!o||s.size<2||s.size>efe||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=ife(l,a,i,r);return c===null||c.length*3>l.length?null:sfe(l,a,c)}const cfe=16,dfe=64,ufe=new Set(["width","height","borderWidth","labelSize","labelWrapWidth","labelPaddingX","labelPaddingY","labelOffsetX","labelOffsetY","fanSpacing","nodeGap"]);function fL(t,e,n={}){const i=n.notes??new re,r=n.budget??new Hf,s=n.toolDefaults!==!1&&t.tool!==void 0&&t.tool!==null?Tr(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:ffe(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(...wfe(g,h,c[u],new Set(n.rawColumns?.[u]??[]),{set:p,derived:s?.derived??[]},n.signal))}const d=hfe(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 ffe(t,e,n){const i={};for(const[r,s]of Object.entries(t[e]))s!==void 0&&Xo(e,r,s.value)&&!(ufe.has(r)&&t.units!==n)&&(i[r]=s.value);return Object.keys(i).length===0?null:i}function hfe(t,e){const n={},i=Object.entries(t?.graph??{});for(const[r,s]of i)s!==void 0&&Xo("graph",r,s.value)&&(n[r]=s.value);for(const[r,s]of Object.entries(e))Xo("graph",r,s)&&(n[r]=s);return n}function Fo(t,e){let n=e,i=2;for(;t.ids.has(n);)n=`${e}#${String(i)}`,i++;return t.ids.add(n),n}function Rl(t,e,n){t.map??={},t.map[e]=n}function pfe(t,e){const n=new Map;for(const[i,r]of Object.entries(e?.values??{})){if(r===void 0)continue;if(!ni[t.target].has(i)&&!i.startsWith("graphty:")){t.notes.add(v.NOT_CARRIED,t.target,i,{sample:i});continue}const s=gfe(t,i,r);t.spend(t.n),s.some(o=>o!==null)&&n.set(i,s)}return n}function gfe(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&&Xo(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 qN(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 W0(t){return[...Object.keys(t.set??{}),...Object.keys(t.map??{})]}function mfe(t,e,n){const i=Ar(t.target,t.n,t.columns,n),r=[];for(const o of e.filter(l=>l.target===t.target)){const l={...o,set:qN(o.set),map:qN(o.map)};l.set===void 0&&delete l.set,l.map===void 0&&delete l.map,E6(o.where)||yfe(t,l,o,i),r.push(l)}const s=bfe(t.target,r);for(const o of s)o.id=Fo(t,o.id);return s}function yfe(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++)Ro(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 bfe(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 JN=["passdata","discrete","continuous","opaque"];function Efe(t,e,n,i){const r=new Map;for(const o of e.props){const l=El(t.target,o),a=ni[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 wfe(t,e,n,i,r,s){const{target:o,n:l}=t,a=r.set;for(const[Q,ut]of e?.columns??[])t.columns.set(Q,ut);const c=pfe(t,e),d=a===null?[]:[{id:Fo(t,`${o}.tool`),target:o,role:"defaults",origin:"tool",where:{all:!0},set:a}];d.push(..._fe(t,r.derived,n,e?.rules??[],c));const u=mfe(t,e?.rules??[],n),f=new Set(u.flatMap(W0)),{defaults:h,rest:p}=Sfe(l,c,f);t.spend(l*c.size);const g=[];Object.keys(h).length>0&&g.push({id:Fo(t,`${o}.defaults`),target:o,role:"defaults",origin:"inferred",where:{all:!0},set:h});const m=Fue(p);t.spend(l*p.length);const y=n.map(Q=>wU(Q,"data"in Q.ref&&i.has(Q.ref.data))).sort((Q,ut)=>Q.distinct-ut.distinct);t.spend(l*n.length);const b=y.filter(Q=>Q.categorical||Q.numeric).slice(0,dfe),_=[],S=new Map,I={id:`${o}.passthrough`,target:o,role:"passthrough",origin:"inferred",where:{all:!0},map:{}},T={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"}},P=[],k=new Map;let U=0;const Y={groups:_,mappings:S,passData:I,passRaw:T,copy:D,opaque:P,tolerated:k};for(const Q of m){if(s?.throwIfAborted(),t.budget.exhausted(o)){U++,P.push({fam:Q,raw:null});continue}Nfe(t,Y,Q,Ofe(t,Q,b,y,c),c)}U>0&&t.notes.add(v.BUDGET,o,null,{count:U}),Ife(t,Y,U,c);const me=Q=>Object.keys(Q.map??{}).length>0,Oe=Array.from(S.values()).sort((Q,ut)=>vfe(Q.id,ut.id)),Fe=[...d,...u,...g,..._,...Oe,...[I,T,D].filter(me)];for(const Q of Fe.slice(d.length+u.length+g.length))Q.id=Fo(t,Q.id);const J=Ar(o,l,t.columns,n);Dfe(t,Fe,c,J);const Gt=Rfe(t,Fe,c,a,k,J);return Gt!==null&&Fe.push(Gt),Fe.map(B0)}function _fe(t,e,n,i,r){const s=new Set([...i.filter(l=>l.origin==="tool").flatMap(W0),...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:Fo(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 Sfe(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 Ofe(t,e,n,i,r){const{target:s,n:o}=t,l=[];if(!e.props.some(d=>ni[s].get(d)==="text"))for(const d of n){const u=Bue(e,d,o,t.spend);u!==null&&l.push(u);const f=ofe(e,d,r,t.spend);if(f!==null&&l.push(f),t.budget.exhausted(s))break}const c=Efe(t,e,r,i);return c!==null&&l.push(c),l.push({type:"opaque",cost:250}),l.sort((d,u)=>d.cost-u.cost||JN.indexOf(d.type)-JN.indexOf(u.type)),l[0]}function Nfe(t,e,n,i,r){if(i.type==="discrete")Afe(t,e,n,i,r);else if(i.type==="continuous")Tfe(t,e,n,i,r);else if(i.type==="passdata"&&!i.raw)for(const s of n.props)Rl(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 hL(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 pL(t,e){"style"in e.feature.ref&&t.columns.set(e.feature.ref.style,e.feature.values)}function Afe(t,e,n,i,r){const{target:s}=t;pL(t,i.info);const o=hL(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]]);Rl(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 Tfe(t,e,n,i,r){const{target:s}=t;pL(t,i.info);const o=hL(t,e,`continuous|${i.info.name}`,`${s}.ramp.${i.info.name}`);for(const l of n.props){const a=i.points.get(l)??[];if(Rl(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)yf(a,rc(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 Ife(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:Zue(r,o,i,s,t.spend),a=new Set(l?.classed??[]);l!==null&&$fe(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,Cfe(t,e.copy,f,i.get(f)??[])):Rl(e.passRaw,f,{kind:"passthrough",by:h.feature.ref})}e.copy.facts={reason:n>0?"BUDGET":"NO_EXPLANATION",distinctValues:c}}function $fe(t,e,n){t.columns.set(uL,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 Cfe(t,e,n,i){return t.columns.set(`copy.${n}`,i.slice()),Rl(e,n,{kind:"passthrough",by:{style:`copy.${n}`}}),t.spend(t.n),new Set(i.filter(r=>r!==null)).size}function B0(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 vfe(t,e){return t===e?0:t<e?-1:1}function ZN(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 QN={inferred:0,declared:1,tool:2};function Dfe(t,e,n,i){const r=cfe-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||(QN[f.origin]??1)-(QN[h.origin]??1)||a(f)-a(h)||ZN(h)-ZN(f)||e.indexOf(h)-e.indexOf(f)});const c=l[0],d=e.map(B0);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(W0(c))){const h=n.get(f),p=h===void 0?Si(d,t.target,f,i,t.budget):h.slice();t.columns.set(`copy.${f}`,p),Rl(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 kfe(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&&jy(e[s],o))&&(r??=new Array(t).fill(null),r[s]=o)}return r}function Rfe(t,e,n,i,r,s){const o=e.map(B0),l=o.filter(d=>d.origin==="tool"),a=l.length>(i===null?0:1),c={};for(const[d,u]of n){const f=Si(o,t.target,d,s,t.budget),h=a?Si(l,t.target,d,s,t.budget):null,p=i?.[d]??null,g=y=>u[y]??(h===null?p:h[y]),m=kfe(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:Fo(t,`${t.target}.exceptions`),target:t.target,role:"exceptions",origin:"inferred",where:{all:!0},map:c}}const gL=["node","edge"],Lfe=new Set(["shape","borderStyle","lineStyle","arrow","arrowSide","weight","position","labelFit","borderPosition"]);function Pfe(t,e,n,i={}){const r=i.signal??void 0,s=new re,o=i.budget??new Hf,l=Pue(e).length>0;for(const p of Lue(e).skipped)l&&p==="ImageAnnotation"||s.add(v.ANNOTATION_SKIPPED,"graph","annotations",{sample:p});const a=Mfe(t,e,n,{notes:s,budget:o,signal:r}),c=to(e),d=xfe(t,e,a,s,c);if(d!==null)return d;if(a===null){const p=s.list();return p.length===0?null:jfe(t.format,p,e,c)}const u={node:new Set(a.raw.node),edge:new Set(a.raw.edge)},f={node:Kr(e,"node").filter(p=>!("data"in p.ref&&u.node.has(p.ref.data))),edge:Kr(e,"edge").filter(p=>!("data"in p.ref&&u.edge.has(p.ref.data)))},h=fL({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 xfe(t,e,n,i,r){const s=n?.block??Gfe(e,Z);if(s===void 0)return null;const o=oc(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=L1(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 Mfe(t,e,n,i){const{notes:r,budget:s,signal:o}=i;o?.throwIfAborted();let l;if(t.styles===void 0)l=qfe(e,t.format,r,s);else{const a=t.styles(e,{signal:o,budget:s,kept:YL(n)});l=a===null?null:Ffe(a,e,r,s,o)}return o?.throwIfAborted(),l===null?null:Ufe(l,e)}function Ufe(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 Gfe(t,e){return t.graph.has(e)?K(t.graph.value(e,0)):void 0}function jfe(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:Kr(n,"node"),edge:Kr(n,"edge")},fingerprint:i}}function Ffe(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 gL){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=zfe(e,a,u,f,n,o[a]);h!==null&&d.set(u,h)}l[a]={values:mL(a,d,s,H0(e,a),n,i)}}return{dialect:s,tool:null,units:c1(s),graph:{},node:l.node,edge:l.edge,raw:o,notes:[]}}function H0(t,e){return e==="node"?t.nodeCount:t.edgeCount}function zfe(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=H0(t,e),c=new Array(a);for(let d=0;d<a;d++)c[d]=K(l.value(o,d));return c}function mL(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}=Wfe(o,c,d);l[c]=u,f!==null&&a.set(c,f)}for(const[c,d]of a)Hfe(o,l,c,d);return l}function Wfe(t,e,n){const{target:i,dialect:r,n:s,notes:o,budget:l}=t,a=ni[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=Bfe(n[u],f);if(h==null)continue;if(a!=="color"){c[u]=Kfe(a,e,h,r,f);continue}const p=$e(h,r,f,{use:Vfe(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 Bfe(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 Hfe(t,e,n,i){const{target:r,n:s,notes:o}=t,l=Yfe.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=_l({color:e[n][c],alpha:d},f,u,a!==null);a!==null&&(a[c]=h)}}const Yfe=new Map([["node.fill","fillOpacity"],["edge.color","opacity"]]);function Vfe(t,e){return e==="fill"?"fill":t==="edge"&&e==="color"?"edge":"line"}function Kfe(t,e,n,i,r){switch(t){case"number":return V(n,r,i==="graphviz"&&(e==="width"||e==="height")?gt:1);case"signed":return Ea(n,r);case"opacity":return tc(n,i,r);case"boolean":return nc(n,r);case"text":return nt(n,r);case void 0:return typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n)?n:null;default:return Lfe.has(t)?oe(t,n,i,r):null}}const Xfe={node:[["color",["fill"]],["size",["width","height"]],["shape",["shape"]],["hidden",["visible"]]],edge:[["color",["color"]],["thickness",["width"]],["shape",["lineStyle"]],["hidden",["visible"]]]};function qfe(t,e,n,i){const r={node:[],edge:[]},s={node:{values:{}},edge:{values:{}}};for(const o of gL){const l=o==="node"?t.nodes:t.edges,a=H0(t,o),c=new Map;for(const[d,u]of Xfe[o]){const f=l.byRole(d);if(f===null)continue;r[o].push(f.meta.name);const h=Jfe(l,f.meta,d,a);for(const p of u)c.set(p,h)}s[o]={values:mL(o,c,e,a,n,i)}}return r.node.length===0&&r.edge.length===0?null:{dialect:e,tool:null,units:c1(e),graph:{},node:s.node,edge:s.edge,raw:r,notes:[]}}function Jfe(t,e,n,i){return Array.from({length:i},(r,s)=>{const o=K(t.value(e.name,s));return n==="color"?Zfe(o,e.dtype):n==="hidden"?typeof o=="boolean"?!o:null:o})}function Zfe(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 Qfe="E_TOO_MANY_EMPTY_CELLS",ehe=2**24;function yL(t){if(t===void 0)return ehe;if(typeof t=="number"&&t>=0&&(Number.isInteger(t)||t===1/0))return t;throw new N("E_UNSUPPORTED",`option maxEmptyCells: ${Hi(t)} is not a non-negative integer or Infinity`,{option:"maxEmptyCells",found:t})}class the extends xp{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 te(this.format,1/0).fail(Qfe,`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 nhe(){return[{id:Qde,descriptor:Eue,load:async()=>(await Rr(async()=>{const{ndexSource:t}=await import("./sources-ndex-CxnPOYff.js");return{ndexSource:t}},[],import.meta.url)).ndexSource},{id:eue,descriptor:qde,load:async()=>(await Rr(async()=>{const{cypherSource:t}=await import("./sources-cypher-BGGD4kJ9.js");return{cypherSource:t}},[],import.meta.url)).cypherSource},{id:tue,descriptor:Jde,load:async()=>(await Rr(async()=>{const{neo4jSource:t}=await import("./sources-cypher-BGGD4kJ9.js");return{neo4jSource:t}},[],import.meta.url)).neo4jSource},{id:nue,descriptor:Zde,load:async()=>(await Rr(async()=>{const{neptuneSource:t}=await import("./sources-cypher-BGGD4kJ9.js");return{neptuneSource:t}},[],import.meta.url)).neptuneSource},{id:iue,descriptor:wue,load:async()=>(await Rr(async()=>{const{restMappingSource:t}=await import("./sources-rest-BPNV8mX-.js");return{restMappingSource:t}},[],import.meta.url)).restMappingSource},{id:rue,descriptor:_ue,load:async()=>(await Rr(async()=>{const{openalexSource:t}=await import("./sources-rest-BPNV8mX-.js");return{openalexSource:t}},[],import.meta.url)).openalexSource},{id:sue,descriptor:Oue,load:async()=>(await Rr(async()=>{const{sparqlSource:t}=await import("./sources-sparql-BiqRQuHD.js");return{sparqlSource:t}},[],import.meta.url)).sparqlSource}]}const bL="~v",ihe=new Set(["endpoint","credential","cursor","limits","retry","idPrefix","allowInsecure","fetch","userAgent","builder","freeze","onProgress","signal"]),rhe=new Set(["E_SOURCE_AUTH","E_SOURCE_FORBIDDEN"]);function Wr(t){return`${oue}${t}`}function Xm(t,e){return t==null?null:Object.freeze({...t,[bL]:e})}function EL(t,e,n,i){const{descriptor:r}=t,s=r?.version??1,o=new te(Wr(t.id),n.errorLimit??100);she(t,o),gue(e,r,o);const l={};for(const f of r?.params??[])f.default!==void 0&&(l[f.name]=f.default);Object.assign(l,e);const a=ohe(n.endpoint??r?.defaultEndpoint??null,o);n.credential?.origins.length===0&&a===null&&be(o,"E_SOURCE_PARAM","a credential needs an endpoint or its own origins",{name:"credential",reason:"credential-unbound"});const c=lhe(n.cursor,s,o),d={nodes:new Set,edgesAtStart:0,sink:null},u=vue({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})});return{report:o,created:u,params:l,counts:d}}function she(t,e){const{descriptor:n}=t,i=sL(),r=n?.runtimes?.[i];r?.supported===!1&&be(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&&be(e,"E_SOURCE_RUNTIME",`source ${t.id} needs a secure context`,{runtime:i,reason:"needs-secure-context"})}function ohe(t,e){if(t===null)return null;let n;try{n=new URL(t)}catch{be(e,"E_SOURCE_PARAM","the endpoint is not a URL",{name:"endpoint",reason:"type"})}return(n.username!==""||n.password!=="")&&be(e,"E_SOURCE_PARAM","the endpoint may not carry a user name or password",{name:"endpoint",reason:"credentials-in-url"}),n}function lhe(t,e,n){if(t==null)return null;const{[bL]:i,...r}=t;return i!==void 0&&i!==e&&be(n,"E_SOURCE_PARAM","the cursor was made by another version of the source",{name:"cursor",reason:"stale-cursor"}),Object.freeze(r)}function wL(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 ahe(t,e){const n={signal:e};for(const[i,r]of Object.entries(t))ihe.has(i)||(n[i]=r);return n}function _L(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 che(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),_L(e,a);const c=dhe(t,e,s,i);uhe(t,e,o,l,i,c)}function dhe(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",at,`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 uhe(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",at,`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??=hhe(e),e.setEdgeValue(c,g,String(h))),o.counts.edges++}catch(g){o.recordError(g,{element:`${String(u)} -> ${String(f)}`}),o.counts.skippedEdges++}}}function fhe(t){return t===null?"":Wn(t)}function hhe(t){const e=t.edgeColumn("id");return e===A?t.declareEdgeColumn({name:"id",dtype:"string",role:"id",nullable:!0}):e}function phe(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 ghe(t,e,n){if(!(t instanceof qa)){if(e>0&&t instanceof tt&&rhe.has(String(t.issue?.code))){const i=t.issue?.params??{};Hm(n.report,"W_SOURCE_AUTH","a later page needs a credential; the pages before it are kept",{origin:typeof i.origin=="string"?i.origin:fhe(n.created.ctx.endpoint),status:typeof i.status=="number"?i.status:null});return}throw t}}async function mhe(t,e,n){const{ctx:i}=n.created,r=t.records,s=phe(r(n.params,i));let o=i.cursor,l=0,a=!1;try{for(;;){let c;try{c=await s.next()}catch(d){return ghe(d,l,n),a=!0,o}if(c.done===!0)return l===0?null:o;if(che(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 yhe(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 qm(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 qm(i,n),c=g$(a).find(d=>!d.directory&&e.sniff({filename:d.name})!==null);if(c===void 0)throw new tt("the zip holds no graph file",new te("zip",0).finish());i=await m$(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 qm(t,e){return await jA(t,{signal:e})??new TextEncoder().encode(typeof t=="string"?t:"")}async function bhe(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 yhe(l,i,s.signal);let{format:u}=l,f=a;if(u===void 0){const p=await qm(a,s.signal);u=i.sniff({filename:c,mimeType:d,head:p.subarray(0,Gr)})?.format,f=p,u===void 0&&be(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,ahe(r,s.signal))),_L(e,l.meta??{}),u}async function eA(t,e,n,i,r){const s=EL(t,e,i,typeof t.file=="function"?"bytes":"items"),{ctx:o}=s.created,l=t.descriptor?.version??1,a=wL(n,s,i.idPrefix);try{if(typeof t.records=="function"){const u=await mhe(t,a,s);return F(o.signal),{report:Fd(s.report.finish(),s,Xm(u,l)),format:Wr(t.id)}}if(typeof t.file=="function"){const u=await bhe(t,a,s,r,i);return{report:Fd(s.report.finish(),s,null),format:u}}const c=t.import,d=await SL(c(s.params,a,o),s);return F(o.signal),{report:Fd(d,s,Xm(s.created.state.finish?.next,l)),format:Wr(t.id)}}catch(c){throw Y0(c,s)}finally{s.created.dispose()}}async function ld(t,e,n,i,r){typeof t[e]!="function"&&be(new te(Wr(t.id),0),"E_SOURCE_UNSUPPORTED",`source ${t.id} has no ${e}`,{feature:e});const s=EL(t,n,i,"items");try{const o=await r(s);return F(s.created.ctx.signal),o}catch(o){throw Y0(o,s)}finally{s.created.dispose()}}function Fd(t,e,n){const r=e.report.finish().issues.filter(s=>!t.issues.includes(s));return Object.freeze({...t,issues:r.length===0?t.issues:Object.freeze([...t.issues,...r]),warningCount:t.warningCount+r.filter(s=>s.severity==="warning").length,errorCount:t.errorCount+r.filter(s=>s.severity==="error").length,source:e.created.info(n)})}function Y0(t,e){const{signal:n}=e.created.ctx;if(n.aborted)return n.reason;if(t instanceof qa)return Y0(Ehe(t,e),e);if(t instanceof tt&&t.report.source===void 0){const i=new tt(t.message,{...t.report,source:e.created.info(null)},t.details);return i.stack=t.stack,i}return t}function Ehe(t,e){try{return be(e.report,"E_SOURCE_LIMIT",t.message,{limit:t.limit,value:t.value})}catch(n){return n}}async function SL(t,e){try{return await t}catch(n){if(n instanceof qa)return e.report.finish();throw n}}function tA(t){const e=t;return typeof e.load=="function"&&e.records===void 0&&e.file===void 0&&e.import===void 0}class whe{constructor(e,n){this.formats=e,this.building=n,this.entries=new Map}register(e){tA(e)?uue(e):jd(e),this.entries.has(e.id)&&da("E_SOURCE_INVALID",`a source with id ${e.id} is already registered`,{id:e.id,reason:"duplicate"});const n=tA(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 jd(e),e;const n=this.entries.get(e);if(n===void 0)return da("E_SOURCE_UNKNOWN",`no source has id ${JSON.stringify(e)}`,{id:e,known:[...this.entries.keys()]},Wr(e));if(n.source!==null)return n.source;const i=n.lazy;return n.loading??=i.load().then(r=>(r.id!==i.id&&da("E_SOURCE_INVALID",`lazy source ${i.id} loaded a source with id ${r.id}`,{id:i.id,reason:"lazy"}),jd(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,Wr(r.id)),{report:o,format:l}=await eA(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 eA(s,n,i,r,this.formats)).report}async expand(e,n,i={}){const r=await this.resolve(e),s=this.building.newBuilder(i,Wr(r.id)),o=await ld(r,"expand",n.params,i,async l=>{const a=wL(s,l,i.idPrefix),c=r.expand?.({...n,params:l.params},a,l.created.ctx),d=await SL(c,l);return Fd(d,l,Xm(l.created.state.finish?.next,r.descriptor?.version??1))});return this.building.freeze(Wr(r.id),s,o,i)}async probe(e,n,i={}){const r=await this.resolve(e);return ld(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 ld({...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 ld(s,"validate",n,r,o=>s.validate?.(o.params,i,o.created.ctx))}}const _he="E_UNKNOWN_FORMAT",She="W_SNIFF_FAILED",Ohe=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"]),Nhe=new Set(["format","filename","mimeType","builder","freeze","maxEmptyCells","styles"]);class Ahe{constructor(){this.importerMap=new Map,this.exporterMap=new Map,this.sources=new whe(this,{newBuilder:(e,n)=>cd(e,n),freeze:(e,n,i,r)=>Pp({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 oA("importer",e,this.importerMap.keys());return n}exporter(e){const n=this.exporterMap.get(e);if(n===void 0)throw oA("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 NO(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:X0,message:sA(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[pl(u,i,new te(l.format,0))]}let a,c;try{a=cd(i,o.importer.format),c=await o.importer.import(o.source,a,ad(i))}catch(d){throw await o.peeked?.close(),o.sniff===null?iA(d,l.format,i.filename):d}return Pp(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||KL(d))throw d;return nA(s,e,`${a} failed: ${vhe(e,d)}`,null,d)}if(!c.ok){await c.body?.cancel().catch(()=>{});const d=`${String(c.status)} ${c.statusText}`.trim();return nA(s,e,`${a} failed: ${d}`,c.status,null)}return this.importGraph(c.body??new Uint8Array(0),{...s,filename:s.filename??Dhe(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(cd(n,i.format)),s=[await i.import(e.source,r[0],ad(n))]):s=await i.importAll(e.source,()=>{const o=cd(n,i.format);return r.push(o),o},ad(n))}catch(o){throw await e.peeked?.close(),rA(e.sniff===null?iA(o,i.format,n.filename):o,r.length-1)}return s.map((o,l)=>{try{return Pp(e,r[l],o,n)}catch(a){throw rA(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,ad(i))}finally{await r.peeked?.close()}}async choose(e,n){const i=ef(e),r=n.format??"auto";if(r!=="auto")return{importer:this.importer(r),sniff:null,source:i,peeked:null,warnings:[]};const s=Qe(n,{ids:"keep",defaultDirected:!0,weightFrom:null});yL(n.maxEmptyCells);const o=await jhe(i,Gr,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 te("unknown",0),d=[];try{const h={filename:n.filename,mimeType:n.mimeType,head:l},p=NO(h,this.importerMap.values(),(g,m)=>{d.push(c.warning("unsupported",She,`the ${g} importer's sniff() threw (${XL(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=$A(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<Gr)return e.fail(Mt,s===""?"the input is empty":"the input holds only whitespace");const o=i===null?"":`: it is ${i}`;return e.fail(_he,`the input is not in a graph format graph-io recognizes${Ghe(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?Lhe(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=f7(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 OL(r.refusal);return r.exporter.exportToString(r.snapshot,r.options)}exportGraphToBytes(e,n,i){return s2(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))&&!b7(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:X0,message:sA(l),column:null,count:null}))])}unknownOptions(e){if(e==null)return[];const n=new Set(Ohe);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:Phe(i)})})}}function The(){const t=new Ahe().registerImporter(zre).registerExporter(Hse).registerImporter(Zq).registerExporter(VX).registerImporter(dY).registerExporter(RY).registerImporter(gM).registerExporter(HM).registerImporter(sD).registerExporter(vK).registerImporter(BC).registerExporter(yB).registerImporter(qR).registerExporter(ede).registerImporter(Noe).registerExporter(zoe).registerImporter(rj).registerExporter(Xde).registerImporter(zG).registerExporter(u9).registerImporter(Y8).registerExporter(w8).registerImporter(Ole).registerExporter(dae).registerImporter(gz).registerExporter(cF);for(const e of nhe())t.registerSource(e);return t}const ph=The();function Ihe(t,e){return ph.importGraph(t,e)}async function $he(t,e,n){return ph.exportGraphToString(t,e,n)}function Che(t,e,n){return ph.checkExport(t,e,n)}function nA(t,e,n,i,r){const s=t.format===void 0||t.format==="auto"?"unknown":t.format;return new te(s,0).fail(dA,n,void 0,{url:String(e),status:i,cause:r})}function iA(t,e,n){if(!(t instanceof tt)||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 tt(`${i} could not be read as ${e}: ${t.message}`,t.report,t.details)}function vhe(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 Dhe(t){const e=new URL(t,"http://localhost/").pathname,n=e.slice(e.lastIndexOf("/")+1);return n===""?null:n}function ad(t){const e={};for(const[n,i]of Object.entries(t))Nhe.has(n)||(e[n]=i);return e}function cd(t,e){const n=yL(t.maxEmptyCells);try{return khe(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 khe(t,e,n){return new the({weightDtype:t.weightDtype??"f64",...t.builder,directed:!0,addMissingNodes:t.addMissingNodes??!0,duplicateEdges:t.duplicateEdges??"keep",selfLoops:t.selfLoops??"keep"},e,n)}function rA(t,e){return!(t instanceof tt)||e<0?t:new tt(`graph ${e}: ${t.message}`,t.report,{...t.details,graphIndex:e})}function Pp(t,e,n,i){let r;try{r=e.freezeWithReport(i.freeze)}catch(d){throw Uhe(d,n)}const{warnings:s}=t,o=i.styles;let l;o!==void 0&&o!==!1&&(l=Pfe(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?Rhe(n):n,c={format:t.importer.format,sniff:t.sniff,snapshot:r.snapshot,report:Mhe(xhe(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 Rhe(t){const e=t.issues.filter(n=>n.code!==Zs);return e.length===t.issues.length?t:Object.freeze({...t,issues:Object.freeze(e),warningCount:t.warningCount-(t.issues.length-e.length)})}function OL(t){return new N("E_UNSUPPORTED",t.message,{code:t.code})}function Lhe(t){return{[Symbol.asyncIterator]:()=>({next:()=>Promise.reject(OL(t))})}}function Phe(t){return t===void 0?null:t.styles===void 0?t.capabilities:Object.freeze({...t.capabilities,styles:t.styles.capabilities})}function sA(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 xhe(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:jL,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 Mhe(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",UL,`${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",GL,`${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 Uhe(t,e){if(!(t instanceof N)||t instanceof tt)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 tt(`the graph cannot be frozen: ${t.message}`,i,{code:t.code,...t.details})}function oA(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 Ghe(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 jhe(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"?Whe(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=zhe(r,i,o);return{head:Fhe(r,e),input:l,close:()=>l.close()}}function Fhe(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 zhe(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 Whe(t,e){const n=LA(t);let i=!1;return{async next(){if(i)return{done:!0,value:void 0};let r;try{r=await RA(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 is=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"}),Bhe=8,lA=80;class Hhe{#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<Bhe){const o=Yhe(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 Yhe(t){const e=typeof t=="string"?t:JSON.stringify(t)??String(t);return e.length>lA?`${e.slice(0,lA-3)}...`:e}const Vhe=new Set(["W_PAJEK_COORD_DIMS","W_DOT_POS_DIMS"]),Khe={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 Xhe(t,e,n,i={}){const r=i.signal??null;r?.throwIfAborted();const s=new Hhe,o=qhe(t,e,r);if(o===null)return fpe(e,s),s.list().length===0?null:ppe(t,e,s);const l=e.nodeCount,a=epe(l,o,s);r?.throwIfAborted();const c=spe(e);if(o.extra.containersFollowChildren===!0)for(const p of c)a.values.fill(Number.NaN,3*p,3*p+3);const d=ope(o,a);lpe(o,a,c,d);const{placed:u,total:f}=ape(a,c,s),h=cpe(a,u,s);return dpe(n,s),upe(e,s),{version:1,source:{format:t.format,tool:o.tool??Fb(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??gpe(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:mpe(a.values),groups:d,notes:NL(s)}}function qhe(t,e,n){const i=t.positions?.(e,{signal:n})??null;if(i?.x!==void 0&&i.y!==void 0)return Zhe(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:Jhe(e,i);const s={...Yu(r.meta.extra),...Yu(i??{})};return{read:Qhe(r),size:K0(e,s),extra:s,...V0(i)}}function Jhe(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:K0(t,s),extra:s,...V0(e)}}function Zhe(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:K0(t,o),extra:o,...V0(e)}}function V0(t){return{groups:t?.groups??[],medianNodeSize:t?.medianNodeSize,tool:t?.tool}}function Qhe(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 epe(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(is.NON_FINITE,{element:o,sample:r.join(",")}));e.extra.zeroUnplaced===!0&&ipe(i),e.extra.originUnplaced===!0&&tpe(i);const s=e.extra.sourceDims===3&&!rpe(i);return npe(i,e.extra,e.size,s,n),{values:i,realZ:s}}function tpe(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 npe(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(is.ANCHOR_NO_SIZE,{element:o/3}),s[0]=t[o],s[1]=t[o+1],s[2]=t[o+2],Zm(s,e,l,i),t.set(s,o)}}function K0(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 ipe(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 rpe(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 spe(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 ope(t,e){const n=[];for(const{node:i,box:r}of t.groups){const s=[r.x,r.y,0];Zm(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 lpe(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 ape(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(is.PARTIAL,{element:l});return{placed:s,total:o}}function cpe(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(is.STACKED,{count:e,sample:Array.from(i.subarray(r,r+3)).join(",")}),i.fill(Number.NaN),!0}function dpe(t,e){for(const n of t.issues)Vhe.has(n.code)&&e.add(is.DIMS_MIXED,{sample:n.code})}function upe(t,e){for(const n of t.nodes)/^position@\d+$/.test(n.meta.name)&&n.meta.role===null&&e.add(is.OTHER_VIEWS,{sample:n.meta.name})}function fpe(t,e){const n=s=>[...t.nodes].find(o=>o.meta.name.toLowerCase()===s&&o.meta.components===1&&hpe(o.dtype)),i=n("x"),r=n("y");i!==void 0&&r!==void 0&&(e.add(is.NOT_READ,{sample:i.meta.name}),e.add(is.NOT_READ,{sample:r.meta.name}))}function hpe(t){return t==="f64"||t==="f32"||t==="i32"||t==="u32"||t==="u8"}function NL(t){return t.list().map(e=>({code:e.code,params:{count:e.count,samples:e.samples},elements:e.elements,message:`${Khe[e.code]} (${e.count})`}))}function ppe(t,e,n){return{version:1,source:{format:t.format,tool:Fb(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:NL(n)}}function gpe(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 Qm(i)}function mpe(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 ype=()=>null;function bpe(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"?ype:o}return{selector:n.selector,style:r}}):t}function Epe(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 wpe(t){const e=t.notes??new re,n=t.budget??new Hf;let i;if(t.rendered!==void 0){i=new Map;const o=Epe(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=r0({elements:t.elements,style:bpe(t.style),snapshot:t.snapshot,toolDefaults:t.toolDefaults,rendered:i,notes:e,budget:n,signal:t.signal}),s=t.snapshot;return fL({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:to(s)},{node:Kr(s,"node"),edge:Kr(s,"edge")},{toolDefaults:t.toolDefaults,notes:e,budget:n,signal:t.signal,rawColumns:{node:r.node.rawColumns,edge:r.edge.rawColumns}})}let aA=0;function _pe(t){return{category:"unsupported",severity:"warning",code:t.code,message:t.message,line:null,element:t.params.property}}async function Upe(t,e="auto",n={}){const{applyStyles:i,importId:r,...s}=n,o=await Ihe(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 tt(`nothing could be read from the input as ${o.format}: ${f?.code??"E_IMPORT"}: ${f?.message??""}`,o.report,{format:o.format})}const l=[],a=vL(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=Xhe(ph.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:DL(c?.coords[3*f+1]??0)}}let d={};if(o.styles!==void 0&&o.styles!==null){aA++;const f=XD(o.styles,{importId:r??String(aA)}),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(_pe))}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 Spe=new Set(["W_ID_TEXT_TYPE","W_ID_RENUMBERED","W_CSV_NODE_ORDER","W_STORAGE_CLASS_CHANGED"]);function Ope(t){return Spe.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 AL(t){return t.cy()}function Jm(t){return t.style()}function Npe(t,e){const n=Jm(AL(t));if(n===void 0)return null;const i=t.nodes(),r=kL(t);return wpe({elements:{nodes:i.jsons(),edges:r.jsons()},style:n.json(),rendered:[...i.map(s=>s.style()),...r.map(s=>s.style())],snapshot:e})}function Ape(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 Tpe(t,e){const n=Jm(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(Jm(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 Ipe=new Set(["gml","cx2"]);async function Gpe(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=CL(t,{directed:i,format:e,integerIds:Ipe.has(e)}),a=s===!0?Npe(t,l):null,c={sanitizeIds:"mangle",...e==="json"?{dialect:"cytoscape"}:{},...o,...a===null?{}:{styles:a}};if(r!==void 0){const d=[...a===null?Tpe(AL(t),s===!0):Ape(a),...Che(l,e,c).filter(Ope)];d.length>0&&r(d)}return $he(l,e,c)}export{Gpe as A,Upe as B,qde as C,UN as D,tt as I,Eue as N,_ue as O,ie as P,wue as R,Dpe as S,Qde as a,Mpe as b,Y8 as c,Ppe as d,da as e,be as f,eue as g,Jde as h,Ym as i,tue as j,Zde as k,nue as l,Lpe as m,iue as n,Wn as o,rue as p,Rpe as q,kpe as r,od as s,F as t,xpe as u,GN as v,Hm as w,Oue as x,sue as y,sL as z};