@graphty/cytoscape-extensions 0.0.28 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/algorithm-options.d.ts +5 -0
- package/dist/algorithm-options.d.ts.map +1 -0
- package/dist/algorithm-options.js +285 -0
- package/dist/algorithm-options.js.map +1 -0
- package/dist/algorithms.d.ts +489 -0
- package/dist/algorithms.d.ts.map +1 -0
- package/dist/algorithms.js +1184 -0
- package/dist/algorithms.js.map +1 -0
- package/dist/cdn/chunks/elements-DIunzJUl.js +1 -0
- package/dist/cdn/chunks/gpu-platform-browser-DnQwf3s0.js +2825 -0
- package/dist/cdn/chunks/index-C-jUF_Ve.js +1 -0
- package/dist/cdn/chunks/index-C4RZkds_.js +10 -0
- package/dist/cdn/chunks/io-D-Vr0j3W.js +269 -0
- package/dist/cdn/chunks/preload-helper-Crt_PPe8.js +1 -0
- package/dist/cdn/chunks/samples-Dja23zzq.js +1 -0
- package/dist/cdn/chunks/sigv4-BXwVbza3-DZCCNyQA.js +3 -0
- package/dist/cdn/chunks/sources-cypher-oj3S6pKb.js +5 -0
- package/dist/cdn/chunks/sources-ndex-BgZhxHsL.js +1 -0
- package/dist/cdn/chunks/sources-rest-E6On5P3z.js +1 -0
- package/dist/cdn/chunks/sources-sparql-BAxh1dw-.js +5 -0
- package/dist/cdn/cytoscape-extensions.js +1 -0
- package/dist/cdn/io.js +1 -0
- package/dist/cytoscape-extensions.bundle.js +2825 -0
- package/dist/elements.d.ts +69 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.js +343 -0
- package/dist/elements.js.map +1 -0
- package/dist/gpu-platform-browser.d.ts +11 -0
- package/dist/gpu-platform-browser.d.ts.map +1 -0
- package/dist/gpu-platform-browser.js +22 -0
- package/dist/gpu-platform-browser.js.map +1 -0
- package/dist/gpu-platform-node.d.ts +15 -0
- package/dist/gpu-platform-node.d.ts.map +1 -0
- package/dist/gpu-platform-node.js +27 -0
- package/dist/gpu-platform-node.js.map +1 -0
- package/dist/gpu.d.ts +149 -0
- package/dist/gpu.d.ts.map +1 -0
- package/dist/gpu.js +312 -0
- package/dist/gpu.js.map +1 -0
- package/dist/graph-data.d.ts +101 -0
- package/dist/graph-data.d.ts.map +1 -0
- package/dist/graph-data.js +147 -0
- package/dist/graph-data.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +111 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +258 -0
- package/dist/io.js.map +1 -0
- package/dist/layouts.d.ts +207 -0
- package/dist/layouts.d.ts.map +1 -0
- package/dist/layouts.js +615 -0
- package/dist/layouts.js.map +1 -0
- package/dist/lazy.d.ts +21 -0
- package/dist/lazy.d.ts.map +1 -0
- package/dist/lazy.js +32 -0
- package/dist/lazy.js.map +1 -0
- package/dist/samples.d.ts +115 -0
- package/dist/samples.d.ts.map +1 -0
- package/dist/samples.js +237 -0
- package/dist/samples.js.map +1 -0
- package/dist/snapshot.d.ts +81 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +225 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/webgpu-provider.d.ts +25 -0
- package/dist/webgpu-provider.d.ts.map +1 -0
- package/dist/webgpu-provider.js +53 -0
- package/dist/webgpu-provider.js.map +1 -0
- package/package.json +13 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as Qe,h as L,M as O,g as se,f as Xe}from"./preload-helper-Crt_PPe8.js";import{G as Ke}from"./index-C-jUF_Ve.js";import{b as Je,s as Ve}from"./elements-DIunzJUl.js";const Ye="https://graphty.app/data/graph-samples/v1/";async function Ze(n,e={}){if(!/^[a-z0-9][a-z0-9-]*$/.test(n))throw new RangeError(`not a dataset name: ${JSON.stringify(n)}`);const t=e.baseUrl??Ye,r=new URL(`${n}.gsnp.gz`,t.endsWith("/")?t:`${t}/`),o=await(e.fetch??fetch)(r,{signal:e.signal??null});if(!o.ok||o.body===null)throw new Error(`fetching ${r.href} failed: HTTP ${o.status}`);return Qe(await et(new Uint8Array(await o.arrayBuffer())))}async function et(n){if(n[0]!==31||n[1]!==139)return n;const e=new Blob([n]).stream().pipeThrough(new DecompressionStream("gzip"));return new Uint8Array(await new Response(e).arrayBuffer())}const tt=466688986;function we(n,e,t,r,o){const i=n>>>0,c=e>>>0,l=(tt^i^c)>>>0;let s=t+i|0,a=r+c|0;s=s+a|0,a=(a<<13|a>>>19)^s,s=s+a|0,a=(a<<15|a>>>17)^s,s=s+a|0,a=(a<<26|a>>>6)^s,s=s+a|0,a=(a<<6|a>>>26)^s,s=s+c|0,a=a+l+1|0,s=s+a|0,a=(a<<17|a>>>15)^s,s=s+a|0,a=(a<<29|a>>>3)^s,s=s+a|0,a=(a<<16|a>>>16)^s,s=s+a|0,a=(a<<24|a>>>8)^s,s=s+l|0,a=a+i+2|0,s=s+a|0,a=(a<<13|a>>>19)^s,s=s+a|0,a=(a<<15|a>>>17)^s,s=s+a|0,a=(a<<26|a>>>6)^s,s=s+a|0,a=(a<<6|a>>>26)^s,s=s+i|0,a=a+c+3|0,s=s+a|0,a=(a<<17|a>>>15)^s,s=s+a|0,a=(a<<29|a>>>3)^s,s=s+a|0,a=(a<<16|a>>>16)^s,s=s+a|0,a=(a<<24|a>>>8)^s,s=s+c|0,a=a+l+4|0,s=s+a|0,a=(a<<13|a>>>19)^s,s=s+a|0,a=(a<<15|a>>>17)^s,s=s+a|0,a=(a<<26|a>>>6)^s,s=s+a|0,a=(a<<6|a>>>26)^s,s=s+l|0,a=a+i+5|0,o[0]=s,o[1]=a}const K=4294967296,nt=9007199254740992;function rt(n){let e=2166136261;for(let t=0;t<n.length;t++)e^=n.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0}const ot=0;function v(n){const e=n??ot;return Ue(e),e}function Ue(n){if(!Number.isSafeInteger(n)||n<0)throw new RangeError(`seed must be an integer in [0, 2^53), got ${String(n)}`)}class S{constructor(e,t,r){this.key=new Uint32Array(2),this.out=new Uint32Array(2),this.counter=0,this.spare=-1,Ue(e),this.seedLo=e>>>0,this.seedHi=Math.floor(e/K),this.domain=rt(t),this.reset(r)}reset(e){we(this.seedLo,this.seedHi,this.domain,e>>>0,this.key),this.counter=0,this.spare=-1}nextU32(){if(this.spare>=0){const t=this.spare;return this.spare=-1,t}const e=this.counter++;return we(this.key[0],this.key[1],e>>>0,Math.floor(e/K),this.out),this.spare=this.out[1],this.out[0]}nextFloat(){const e=this.nextU32()>>>5,t=this.nextU32()>>>6;return(e*67108864+t)/nt}nextBelow(e){if(e<=K){const o=e===1?0:4294967295>>>Math.clz32(e-1);for(;;){const i=(this.nextU32()&o)>>>0;if(i<e)return i}}const t=Math.ceil(e/K),r=4294967295>>>Math.clz32(t-1);for(;;){const i=((this.nextU32()&r)>>>0)*K+this.nextU32();if(i<e)return i}}nextSkip(e){return Math.floor(L(1-this.nextFloat())/e)}}function re(n,e){const t=n.nodeColumns?.[e];if(t===void 0||!ArrayBuffer.isView(t))throw new RangeError(`weights: the graph has no numeric node column "${e}"`);return t}function st(n,e,t){const r=n.src.length,o=new Float32Array(r),{src:i,dst:c}=n,l=new S(t,"weights",0);switch(e.kind){case"uniform":{const s=e.min??0,a=e.max??1;if(!(Number.isFinite(s)&&Number.isFinite(a)&&s<=a))throw new RangeError(`weights: uniform needs finite min <= max, got ${s} and ${a}`);for(let u=0;u<r;u++)o[u]=s+(a-s)*l.nextFloat();break}case"integer":{const{min:s,max:a}=e;if(!(Number.isSafeInteger(s)&&Number.isSafeInteger(a)&&s<=a))throw new RangeError(`weights: integer needs integers min <= max, got ${s} and ${a}`);for(let u=0;u<r;u++)o[u]=s+l.nextBelow(a-s+1);break}case"exponential":{const s=e.mean??1;if(!(s>0&&Number.isFinite(s)))throw new RangeError(`weights: exponential needs a positive mean, got ${s}`);for(let a=0;a<r;a++)o[a]=-s*L(1-l.nextFloat());break}case"euclidean":{const s=re(n,"x"),a=re(n,"y"),u=n.nodeColumns?.z===void 0?null:re(n,"z");for(let f=0;f<r;f++){const h=s[i[f]]-s[c[f]],d=a[i[f]]-a[c[f]],m=u===null?0:u[i[f]]-u[c[f]];o[f]=Math.sqrt(h*h+d*d+m*m)}break}default:{const s=re(n,e.column),a=e.combine??"sum";for(let u=0;u<r;u++){const f=s[i[u]],h=s[c[u]];o[u]=it(a,f,h)}}}return o}function it(n,e,t){switch(n){case"source":return e;case"target":return t;case"sum":return e+t;case"mean":return(e+t)/2;case"product":return e*t;case"min":return Math.min(e,t);case"max":return Math.max(e,t);default:return Math.abs(e-t)}}function at(n,e,t){return{...n,weights:st(n,e,v(t))}}function x(n,e){return e.weights===void 0?n:at(n,e.weights,e.seed)}const le=["bull","chvatal","cubical","desargues","diamond","dodecahedral","frucht","heawood","hoffman-singleton","house","house-x","icosahedral","krackhardt-kite","moebius-kantor","octahedral","pappus","sedgewick-maze","tetrahedral","truncated-cube","truncated-tetrahedron","tutte"],pe={bull:[5,[0,1,0,2,1,2,1,3,2,4]],chvatal:[12,[0,1,0,4,0,6,0,9,1,2,1,5,1,7,2,3,2,6,2,8,3,4,3,7,3,9,4,5,4,8,5,10,5,11,6,10,6,11,7,8,7,11,8,10,9,10,9,11]],cubical:[8,[0,1,0,3,0,4,1,2,1,7,2,3,2,6,3,5,4,5,4,7,5,6,6,7]],desargues:[20,[0,1,0,19,0,5,1,2,1,16,2,3,2,11,3,4,3,14,4,5,4,9,5,6,6,7,6,15,7,8,7,18,8,9,8,13,9,10,10,11,10,19,11,12,12,13,12,17,13,14,14,15,15,16,16,17,17,18,18,19]],diamond:[4,[0,1,0,2,1,2,1,3,2,3]],dodecahedral:[20,[0,1,0,19,0,10,1,2,1,8,2,3,2,6,3,4,3,19,4,5,4,17,5,6,5,15,6,7,7,8,7,14,8,9,9,10,9,13,10,11,11,12,11,18,12,13,12,16,13,14,14,15,15,16,16,17,17,18,18,19]],frucht:[12,[0,1,0,6,0,7,1,2,1,7,2,3,2,8,3,4,3,9,4,5,4,9,5,6,5,10,6,10,7,11,8,11,8,9,10,11]],heawood:[14,[0,1,0,13,0,5,1,2,1,10,2,3,2,7,3,4,3,12,4,5,4,9,5,6,6,7,6,11,7,8,8,9,8,13,9,10,10,11,11,12,12,13]],"hoffman-singleton":[50,[0,1,0,2,0,3,0,6,0,7,0,8,0,9,1,17,1,12,1,26,1,27,1,28,1,29,2,10,2,11,2,13,2,14,2,15,2,16,3,4,3,5,3,30,3,35,3,40,3,45,4,11,4,17,4,34,4,39,4,44,4,49,5,12,5,10,5,33,5,38,5,43,5,48,6,22,6,18,6,31,6,39,6,43,6,47,7,34,7,23,7,19,7,37,7,41,7,48,8,33,8,36,8,24,8,20,8,42,8,49,9,32,9,38,9,44,9,25,9,21,9,46,10,17,10,18,10,19,10,20,10,21,11,12,11,32,11,37,11,42,11,47,12,31,12,36,12,41,12,46,13,30,13,26,13,22,13,36,13,44,13,48,14,31,14,27,14,23,14,38,14,40,14,49,15,34,15,35,15,28,15,24,15,43,15,46,16,33,16,39,16,41,16,45,16,29,16,25,17,22,17,23,17,24,17,25,18,32,18,26,18,35,18,41,18,49,19,30,19,27,19,39,19,42,19,46,20,31,20,37,20,28,20,44,20,45,21,34,21,36,21,40,21,47,21,29,22,33,22,37,22,40,22,46,23,32,23,36,23,43,23,45,24,30,24,38,24,41,24,47,25,31,25,35,25,42,25,48,26,34,26,38,26,42,26,45,27,33,27,35,27,44,27,47,28,32,28,39,28,40,28,48,29,30,29,37,29,43,29,49,30,31,30,32,31,34,32,33,33,34,35,36,35,37,36,39,37,38,38,39,40,41,40,42,41,44,42,43,43,44,45,46,45,47,46,49,47,48,48,49]],house:[5,[0,1,0,2,1,3,2,3,2,4,3,4]],"house-x":[5,[0,1,0,2,0,3,1,3,1,2,2,3,2,4,3,4]],icosahedral:[12,[0,1,0,5,0,7,0,8,0,11,1,2,1,5,1,6,1,8,2,3,2,6,2,8,2,9,3,4,3,6,3,9,3,10,4,5,4,6,4,10,4,11,5,6,5,11,7,8,7,9,7,10,7,11,8,9,9,10,10,11]],"krackhardt-kite":[10,[0,1,0,2,0,3,0,5,1,3,1,4,1,6,2,3,2,5,3,4,3,5,3,6,4,6,5,6,5,7,6,7,7,8,8,9]],"moebius-kantor":[16,[0,1,0,15,0,5,1,2,1,12,2,3,2,7,3,4,3,14,4,5,4,9,5,6,6,7,6,11,7,8,8,9,8,13,9,10,10,11,10,15,11,12,12,13,13,14,14,15]],octahedral:[6,[0,1,0,2,0,3,0,4,1,2,1,3,1,5,2,4,2,5,3,4,3,5,4,5]],pappus:[18,[0,1,0,17,0,5,1,2,1,8,2,3,2,13,3,4,3,10,4,5,4,15,5,6,6,7,6,11,7,8,7,14,8,9,9,10,9,16,10,11,11,12,12,13,12,17,13,14,14,15,15,16,16,17]],"sedgewick-maze":[8,[0,2,0,7,0,5,1,7,2,6,3,4,3,5,4,5,4,7,4,6]],tetrahedral:[4,[0,1,0,2,0,3,1,2,1,3,2,3]],"truncated-cube":[24,[0,1,0,2,0,4,1,11,1,14,2,3,2,4,3,6,3,8,4,5,5,16,5,18,6,7,6,8,7,10,7,12,8,9,9,17,9,20,10,11,10,12,11,14,12,13,13,21,13,22,14,15,15,19,15,23,16,17,16,18,17,20,18,19,19,23,20,21,21,22,22,23]],"truncated-tetrahedron":[12,[0,1,0,2,0,9,1,2,1,6,2,3,3,4,3,11,4,5,4,11,5,6,5,7,6,7,7,8,8,9,8,10,9,10,10,11]],tutte:[46,[0,1,0,2,0,3,1,4,1,26,2,10,2,11,3,18,3,19,4,5,4,33,5,6,5,29,6,7,6,27,7,8,7,14,8,9,8,38,9,10,9,37,10,39,11,12,11,39,12,13,12,35,13,14,13,15,14,34,15,16,15,22,16,17,16,44,17,18,17,43,18,45,19,20,19,45,20,21,20,41,21,22,21,23,22,40,23,24,23,27,24,25,24,32,25,26,25,31,26,33,27,28,28,29,28,32,29,30,30,31,30,33,31,32,34,35,34,38,35,36,36,37,36,39,37,38,40,41,40,44,41,42,42,43,42,45,43,44]]};function ct(n,e={}){const t=Object.prototype.hasOwnProperty.call(pe,n)?pe[n]:void 0;if(t===void 0)throw new RangeError(`unknown named graph "${n}"; see NAMED_GRAPH_NAMES`);const[r,o]=t,i=o.length/2,c=new Uint32Array(i),l=new Uint32Array(i);for(let s=0;s<i;s++)c[s]=o[2*s],l[s]=o[2*s+1];return x({directed:!1,nodeCount:r,src:c,dst:l},e)}function b(n,e,t,r,o){return{name:n,plainName:e,type:"integer",default:t,min:r,...o===void 0?{}:{max:o}}}function B(n,e,t,r,o){return{name:n,plainName:e,type:"number",default:t,min:r,...o===void 0?{}:{max:o}}}function N(n,e,t){return B(n,e,t,0,1)}function q(n,e,t){return{name:n,plainName:e,type:"boolean",default:t}}const $=b("seed","Seed",0,0,Number.MAX_SAFE_INTEGER);function U(n,e=1){return b("n","Nodes",n,e)}function A(n,e,t,r){return{name:n,plainName:e,description:t,params:r,thumbnail:`generator-${n}.webp`}}Object.freeze([A("ak","AK flow network","A hard maximum-flow instance of 4k + 6 nodes, built to defeat augmenting-path methods.",[b("k","Size",4,1,499998)]),A("balanced-tree","Balanced tree","A rooted tree in which every inner node has the same number of children.",[b("branching","Children per node",3,1),b("height","Height",4,0)]),A("barabasi-albert","Barabasi-Albert","A scale-free network grown by preferential attachment: new nodes link to well-connected ones.",[U(150,2),b("m","Edges per new node",2,1),N("triadProbability","Triangle closing",0),$]),A("barbell","Barbell","Two complete graphs joined by a path.",[b("cliqueSize","Clique size",8,2),b("pathLength","Path length",6,0)]),A("bianconi-barabasi","Bianconi-Barabasi","Preferential attachment weighted by a random fitness per node, so a late node can still become a hub.",[U(150,2),b("m","Edges per new node",2,1),$]),A("bipartite-configuration-model","Bipartite configuration model","A random two-sided network with a set degree on every left node.",[b("left","Left nodes",20,1),b("right","Right nodes",30,1),b("degree","Left degree",3,0),$]),A("caveman","Caveman","Separate complete graphs: the extreme of community structure.",[b("cliques","Cliques",6,1),b("size","Clique size",6,1)]),A("chung-lu","Chung-Lu","A random network whose node degrees follow a power law in expectation.",[U(150),b("minDegree","Smallest degree",2,1),b("maxDegree","Largest degree",40,1),B("exponent","Degree exponent",2.5,0),$]),A("circular-ladder","Circular ladder","Two cycles with every pair of matching nodes joined: a prism.",[U(20,3)]),A("complete","Complete graph","Every node joined to every other node.",[U(12)]),A("complete-bipartite","Complete bipartite","Two groups with every node of one joined to every node of the other.",[b("a","First group",6,0),b("b","Second group",8,0)]),A("complete-multipartite","Complete multipartite","Several equal groups with every pair of nodes in different groups joined.",[b("parts","Groups",3,1),b("partSize","Group size",4,1)]),A("configuration-model","Configuration model","A random network with a power-law degree sequence, wired by pairing edge ends at random.",[U(150),b("minDegree","Smallest degree",2,1),b("maxDegree","Largest degree",20,1),B("exponent","Degree exponent",2.5,0),$]),A("connected-caveman","Connected caveman","A ring of near-complete groups, each with one edge rewired to its neighbor group.",[b("cliques","Cliques",8,2),b("size","Clique size",6,2)]),A("cycle","Cycle","Nodes joined in a single ring.",[U(30)]),A("degree-corrected-sbm","Degree-corrected block model","Communities with power-law degrees inside them: a stochastic block model with hubs.",[b("blocks","Communities",3,1),b("blockSize","Community size",40,1),b("minDegree","Smallest degree",3,1),b("maxDegree","Largest degree",15,1),B("exponent","Degree exponent",2.5,0),N("mixing","Mixing",.05),$]),A("directed-configuration-model","Directed configuration model","A random directed network in which every node has the same in-degree and out-degree.",[U(60),b("degree","Degree",2,0),$]),A("duplication-divergence","Duplication-divergence","A network grown by copying nodes and losing some copied edges, a model of protein interactions.",[U(100,2),B("retention","Edge retention",.4,0,1),$]),A("empty","Empty graph","Nodes with no edges at all.",[U(20,0)]),A("erdos-renyi","Erdos-Renyi","A random network in which every pair of nodes is joined with the same probability.",[U(100,0),N("p","Edge probability",.04),q("directed","Directed",!1),$]),A("erdos-renyi-gnm","Erdos-Renyi (fixed edges)","A random network with an exact number of edges placed uniformly at random.",[U(100,0),b("m","Edges",200,0),$]),A("forest-fire","Forest fire","A directed network grown by new nodes burning through their neighbors' links, as citation networks grow.",[U(100),B("forward","Forward burning",.35,0,.999),B("backward","Backward burning",.3,0),$]),A("genrmf","GENRMF flow network","A stack of grid frames joined by random arcs, a standard maximum-flow benchmark.",[b("a","Frame side",3,1),b("b","Frames",4,1),b("c1","Smallest capacity",1,0),b("c2","Largest capacity",100,0),$]),A("grid","Grid","A two-dimensional square lattice.",[b("rows","Rows",15,1),b("cols","Columns",15,1),q("periodic","Wrap around",!1),q("diagonals","Diagonals",!1)]),A("grid-3d","3D grid","A three-dimensional cubic lattice.",[b("rows","Rows",6,1),b("cols","Columns",6,1),b("layers","Layers",4,1),q("periodic","Wrap around",!1),q("diagonals","Diagonals",!1)]),A("grid-flow-network","Grid flow network","A grid of arcs with random capacities between a source on the left and a sink on the right.",[b("rows","Rows",8,1),b("cols","Columns",8,2),b("minCapacity","Smallest capacity",1,0),b("maxCapacity","Largest capacity",10,0),$]),A("hexagonal-lattice","Hexagonal lattice","A honeycomb of hexagons.",[b("rows","Rows",6,1),b("cols","Columns",8,1)]),A("hyperbolic","Hyperbolic random graph","Points in the hyperbolic plane joined when close, giving hubs, clustering and short paths at once.",[U(150,0),B("averageDegree","Average degree",4,.01),B("exponent","Degree exponent",2.5,2.01),B("temperature","Temperature",0,0,.99),$]),A("hypercube","Hypercube","The corners of a cube in any number of dimensions, joined along its edges.",[b("dimension","Dimensions",4,0,20)]),A("knn","Nearest neighbors","Random points, each joined to the points closest to it.",[U(150,0),b("k","Neighbors per node",3,0),q("directed","Directed",!1),$]),A("kronecker","Kronecker graph","A self-similar directed network made by repeatedly multiplying a small core-periphery pattern.",[b("power","Power",7,1,20),$]),A("ladder","Ladder","Two paths with every pair of matching nodes joined.",[U(20)]),A("layered-flow-network","Layered flow network","Layers of nodes between a source and a sink, with random arcs from each layer to the next.",[b("layers","Layers",3,1),b("width","Layer width",6,1),N("p","Arc probability",.5),b("minCapacity","Smallest capacity",1,0),b("maxCapacity","Largest capacity",10,0),$]),A("lfr","LFR benchmark","A benchmark network with planted communities and power-law degrees, for testing community detection.",[U(250),b("minDegree","Smallest degree",4,1),b("maxDegree","Largest degree",30,1),B("degreeExponent","Degree exponent",2.5,0),b("minCommunity","Smallest community",20,1),b("maxCommunity","Largest community",60,1),B("communityExponent","Community size exponent",1.5,0),N("mixing","Mixing",.1),$]),A("lollipop","Lollipop","A complete graph with a path hanging from it.",[b("cliqueSize","Clique size",8,1),b("pathLength","Path length",10,0)]),A("mobius-ladder","Mobius ladder","A ladder bent into a ring with a half twist.",[U(20,4)]),A("named","Named graph","A famous small graph from graph theory, chosen by name.",[{name:"name",plainName:"Graph",type:"choice",default:"frucht",choices:le}]),A("newman-watts","Newman-Watts","A ring lattice with random shortcuts added: a small world.",[U(60,3),b("k","Ring neighbors",4,2),N("p","Shortcut probability",.1),$]),A("path","Path","Nodes joined in a single line.",[U(30)]),A("petersen","Petersen graph","The ten-node graph that is the counterexample to many conjectures.",[]),A("planted-partition","Planted partition","Equal groups with dense links inside each group and sparse links between them.",[b("groups","Groups",4,1),b("groupSize","Group size",30,1),N("pIn","Inside probability",.2),N("pOut","Between probability",.005),$]),A("price","Price citation model","A directed citation network in which well-cited papers attract more citations.",[U(150),b("citations","Citations per paper",2,1),B("attractiveness","Attractiveness",1,.001),$]),A("random-apollonian","Random Apollonian network","A planar network grown by repeatedly splitting a random triangle in three.",[U(40,3),$]),A("random-bipartite","Random bipartite","Two groups with every pair across them joined with the same probability.",[b("n1","First group",15,0),b("n2","Second group",20,0),N("p","Edge probability",.15),$]),A("random-dag","Random layered DAG","Layers of nodes with random arcs from each layer to the next.",[b("layers","Layers",5,1),b("width","Layer width",8,1),N("p","Arc probability",.25),$]),A("random-geometric","Random geometric","Random points in a square, joined when they are closer than a set distance.",[U(200,0),B("radius","Radius",.1,0),q("periodic","Wrap around",!1),$]),A("random-order-dag","Random ordered DAG","Nodes in a fixed order with each forward arc present at the same probability.",[U(50,0),N("p","Arc probability",.08),$]),A("random-recursive-tree","Random recursive tree","A tree grown by attaching each new node to a uniformly random earlier one.",[U(100),$]),A("random-regular","Random regular","A random network in which every node has the same degree.",[U(60,0),b("d","Degree",3,0),$]),A("random-tree","Random tree","A tree drawn uniformly from all labeled trees on its nodes.",[U(100),$]),A("ring-of-cliques","Ring of cliques","Complete graphs joined one to the next in a ring.",[b("cliques","Cliques",8,2),b("size","Clique size",5,2)]),A("rmat","R-MAT","A skewed, scale-free directed network made by recursive quadrant choice, as in Graph500.",[b("scale","Scale (log2 of nodes)",7,0,31),b("edgeFactor","Edges per node",4,0),$]),A("star","Star","One hub joined to every other node.",[U(20)]),A("stochastic-block-model","Stochastic block model","Blocks of nodes whose link probability depends only on the two blocks.",[b("blocks","Blocks",3,1),b("blockSize","Block size",40,1),N("pIn","Inside probability",.1),N("pOut","Between probability",.005),$]),A("triangular-lattice","Triangular lattice","A plane tiled with triangles.",[b("rows","Rows",8,1),b("cols","Columns",10,1)]),A("watts-strogatz","Watts-Strogatz","A ring lattice with some edges rewired at random: the classic small world.",[U(60,3),b("k","Ring neighbors",4,2),N("beta","Rewiring probability",.1),$]),A("waxman","Waxman","Random points joined with a probability that falls with their distance, a model of the Internet.",[U(200,0),B("alpha","Distance scale",.05,1e-4),N("beta","Density",1),$]),A("wheel","Wheel","A cycle with a hub joined to every node of it.",[U(20)]),A("wilson-maze","Maze","A random spanning tree of a grid: a perfect maze.",[b("rows","Rows",12,1),b("cols","Columns",12,1),$])]);const lt=["road-ny","ogbn-arxiv","go-basic","disease-ontology","bioplex3-hct116","com-dblp"],ut=["karate","florentine-families","davis-southern-women","les-miserables","football","political-books","dolphins","contiguous-usa","knuth-miles","celegans-neural","political-blogs","openflights","venice-transit","yeast-perturbation","stelzl-interactome","wikipathways-senescence-autophagy","go-slim-generic"],ye=[...ut,...lt];function p(n,e,t,r=O){if(!Number.isInteger(e)||e<t||e>r)throw new RangeError(`${n} must be an integer in [${t}, ${r}], got ${String(e)}`)}function D(n,e){if(!(e>=0&&e<=1))throw new RangeError(`${n} must be a probability in [0, 1], got ${String(e)}`)}function F(n){if(n>O)throw new RangeError(`the graph would have ${n} edges, above the limit of ${O}`)}class R{constructor(e){this.length=0;const t=Math.max(16,Math.min(e,O));this.src=new Uint32Array(t),this.dst=new Uint32Array(t)}push(e,t){this.length===this.src.length&&this.grow(),this.src[this.length]=e,this.dst[this.length]=t,this.length++}finish(){return this.length===this.src.length?{src:this.src,dst:this.dst}:{src:this.src.slice(0,this.length),dst:this.dst.slice(0,this.length)}}grow(){F(this.length+1);const e=Math.min(this.src.length*2,O),t=new Uint32Array(e),r=new Uint32Array(e);t.set(this.src),r.set(this.dst),this.src=t,this.dst=r}}function Z(n,e){const t=n*e;return F(t),new R(Math.ceil(t+6*Math.sqrt(t*(1-e))+16))}function ee(n,e,t,r,o,i,c){if(e===0||o>=i)return;if(e===1){for(let s=o;s<i;s++)c.push(r,s);return}let l=o+n.nextSkip(t);for(;l<i;)c.push(r,l),l+=1+n.nextSkip(t)}function M(n,e,t,r){const{src:o,dst:i}=e.finish();return r===void 0?{directed:t,nodeCount:n,src:o,dst:i}:{directed:t,nodeCount:n,src:o,dst:i,nodeColumns:r}}function ft(n,e){const t=new S(e,"bipartite-matching",0),r=new Uint32Array(n);for(let o=0;o<n;o++)r[o]=o;for(let o=n-1;o>0;o--){const i=t.nextBelow(o+1),c=r[o];r[o]=r[i],r[i]=c}return r}function ht(n,e,t,r,o){const{n1:i,n2:c,p:l}=n,s=v(n.seed),a=L(1-l),u=new S(s,"bipartite",0);for(let f=t;f<r;f++){u.reset(f);let h=e===null?-1:e[f];const d=m=>{h>=0&&h<m&&o.push(f,i+h),h>=0&&h<=m&&(h=-1),o.push(f,i+m)};if(l===1)for(let m=0;m<c;m++)d(m);else if(l>0){let m=u.nextSkip(a);for(;m<c;)d(m),m+=1+u.nextSkip(a)}h>=0&&o.push(f,i+h)}}function dt(n){const{n1:e,n2:t,p:r}=n;p("n1",e,0),p("n2",t,0),p("n1 + n2",e+t,0),D("p",r);const o=v(n.seed);let i=null;if(n.perfectMatching===!0){if(e!==t)throw new RangeError(`perfectMatching needs n1 === n2, got ${e} and ${t}`);i=ft(e,o)}const c=Z(e*t,r);ht(n,i,0,e,c);const l=new Uint8Array(e+t).fill(1,e);return x(M(e+t,c,!1,{side:l}),n)}function gt(n){const{sizes:e,probabilities:t}=n,r=v(n.seed),o=e.length;if(p("sizes.length",o,1),t.length!==o)throw new RangeError(`probabilities must be ${o} x ${o}`);const i=[0];for(let s=0;s<o;s++){if(p(`sizes[${s}]`,e[s],0),i.push(i[s]+e[s]),t[s].length!==o)throw new RangeError(`probabilities must be ${o} x ${o}`);for(let a=0;a<o;a++)if(D(`probabilities[${s}][${a}]`,t[s][a]),t[s][a]!==t[a][s])throw new RangeError(`probabilities must be symmetric: [${s}][${a}] differs from [${a}][${s}]`)}const c=i[o];p("the total size",c,0);const l=new Uint32Array(c);for(let s=0;s<o;s++)l.fill(s,i[s],i[s+1]);return{n:c,seed:r,starts:i,block:l,p:t,logQ:t.map(s=>s.map(a=>L(1-a)))}}function mt(n,e,t,r){const{starts:o,block:i,p:c,logQ:l}=n,s=new S(n.seed,"sbm",0),a=o.length-1;for(let u=e;u<t;u++){s.reset(u);const f=i[u];for(let h=f;h<a;h++)ee(s,c[f][h],l[f][h],u,h===f?u+1:o[h],o[h+1],r)}}function ze(n){const e=gt(n);let t=0,r=0;for(let i=0;i<e.starts.length-1;i++)for(let c=i;c<e.starts.length-1;c++){const l=e.starts[i+1]-e.starts[i],s=e.starts[c+1]-e.starts[c],a=i===c?l*(l-1)/2:l*s;t+=a*e.p[i][c],r+=a}const o=Z(r,r===0?0:t/r);return mt(e,0,e.n,o),x(M(e.n,o,!1,{community:e.block}),n)}function wt(n){const{groups:e,groupSize:t,pIn:r,pOut:o,seed:i}=n;return p("groups",e,1),p("groupSize",t,1),ze({sizes:new Array(e).fill(t),probabilities:Array.from({length:e},(c,l)=>Array.from({length:e},(s,a)=>l===a?r:o)),seed:i,weights:n.weights})}function W(n,e,t){for(let r=e;r<e+t;r++)for(let o=r+1;o<e+t;o++)n.push(r,o)}function pt(n){const{n:e}=n;p("n",e,0);const t=new R(e);for(let r=0;r+1<e;r++)t.push(r,r+1);return x(M(e,t,!1),n)}function yt(n){const{n:e}=n;p("n",e,3);const t=new R(e);for(let r=0;r+1<e;r++)t.push(r,r+1);return t.push(e-1,0),x(M(e,t,!1),n)}function bt(n){const{n:e}=n;p("n",e,1);const t=new R(e);for(let r=1;r<e;r++)t.push(0,r);return x(M(e,t,!1),n)}function At(n){const{n:e}=n;p("n",e,4);const t=new R(2*e);for(let r=1;r<e;r++)t.push(0,r);for(let r=1;r+1<e;r++)t.push(r,r+1);return t.push(e-1,1),x(M(e,t,!1),n)}function xt(n){const{n:e}=n;p("n",e,0);const t=e*(e-1)/2;F(t);const r=new R(t);return W(r,0,e),x(M(e,r,!1),n)}function kt(n){const{a:e,b:t}=n;p("a",e,0),p("b",t,0),p("a + b",e+t,0),F(e*t);const r=new R(e*t);for(let i=0;i<e;i++)for(let c=0;c<t;c++)r.push(i,e+c);const o=new Uint8Array(e+t).fill(1,e);return x(M(e+t,r,!1,{side:o}),n)}function Mt(n){const{dimension:e}=n;p("dimension",e,0,26);const t=2**e,r=new R(e*t/2);for(let o=0;o<t;o++)for(let i=0;i<e;i++){const c=o|1<<i;c!==o&&r.push(o,c)}return x(M(t,r,!1),n)}function Rt(n){const{n:e}=n;return p("n",e,1),p("2n",2*e,2),x(M(2*e,Fe(e),!1),n)}function Et(n){const{cliqueSize:e,pathLength:t}=n;p("cliqueSize",e,2),p("pathLength",t,0);const r=2*e+t;p("2 * cliqueSize + pathLength",r,4),F(e*(e-1)+t+1);const o=new R(e*(e-1)+t+1);W(o,0,e);for(let i=e-1;i<e+t;i++)o.push(i,i+1);return W(o,e+t,e),x(M(r,o,!1),n)}function St(n){const{cliqueSize:e,pathLength:t}=n;p("cliqueSize",e,2),p("pathLength",t,0),p("cliqueSize + pathLength",e+t,2),F(e*(e-1)/2+t);const r=new R(e*(e-1)/2+t);W(r,0,e);for(let o=e-1;o+1<e+t;o++)r.push(o,o+1);return x(M(e+t,r,!1),n)}function fe(n,e){const t=new Uint32Array(n*e);for(let r=0;r<n;r++)t.fill(r,r*e,(r+1)*e);return t}function vt(n){const{cliques:e,size:t}=n;p("cliques",e,1),p("size",t,1);const r=e*t;p("cliques * size",r,1),F(r*(t-1)/2);const o=new R(r*(t-1)/2);for(let i=0;i<e;i++)W(o,i*t,t);return x(M(r,o,!1,{community:fe(e,t)}),n)}function $t(n){const{cliques:e,size:t}=n;p("cliques",e,2),p("size",t,2);const r=e*t;p("cliques * size",r,4),F(r*(t-1)/2);const o=new R(r*(t-1)/2);for(let i=0;i<e;i++){const c=i*t;for(let l=c;l<c+t;l++)for(let s=l+1;s<c+t;s++)l===c&&s===c+1?o.push(c,(c-1+r)%r):o.push(l,s)}return x(M(r,o,!1,{community:fe(e,t)}),n)}function Ut(n){const{branching:e,height:t}=n;p("branching",e,1),p("height",t,0);let r=0,o=1;for(let c=0;c<=t;c++)r+=o,o*=e,p("node count",r,1);const i=new R(r);for(let c=1;c<r;c++)i.push(Math.floor((c-1)/e),c);return x(M(r,i,!1),n)}function zt(n={}){const e=new R(15);for(let t=0;t<5;t++)e.push(t,(t+1)%5);for(let t=0;t<5;t++)e.push(t,t+5);for(let t=0;t<5;t++)e.push(5+t,5+(t+2)%5);return x(M(10,e,!1),n)}function Ft(n){return p("n",n.n,0),x(M(n.n,new R(0),!1),n)}function Ct(n){const{sizes:e}=n,t=[0];for(let l=0;l<e.length;l++)p(`sizes[${l}]`,e[l],0),t.push(t[l]+e[l]);const r=t[e.length];p("the total size",r,0);let o=r*(r-1)/2;for(const l of e)o-=l*(l-1)/2;F(o);const i=new Uint32Array(r);for(let l=0;l<e.length;l++)i.fill(l,t[l],t[l+1]);const c=new R(o);for(let l=0;l<r;l++)for(let s=t[i[l]+1];s<r;s++)c.push(l,s);return x(M(r,c,!1,{part:i}),n)}function Gt(n){const{n:e}=n;p("n",e,3),F(3*e);const t=Fe(e);return t.push(e-1,0),t.push(2*e-1,e),x(M(2*e,t,!1),n)}function Dt(n){const{n:e}=n;p("n",e,3),F(3*e);const t=new R(3*e);for(let r=0;r+1<2*e;r++)t.push(r,r+1);t.push(2*e-1,0);for(let r=0;r<e;r++)t.push(r,r+e);return x(M(2*e,t,!1),n)}function Fe(n){const e=new R(3*n);for(let t=0;t<2;t++)for(let r=0;r+1<n;r++)e.push(t*n+r,t*n+r+1);for(let t=0;t<n;t++)e.push(t,n+t);return e}function Lt(n){const{cliques:e,size:t}=n;p("cliques",e,2),p("size",t,2);const r=e*t;p("cliques * size",r,4);const o=r*(t-1)/2+e;F(o);const i=new R(o);for(let c=0;c<e;c++)W(i,c*t,t),i.push(c*t+1,(c+1)*t%r);return x(M(r,i,!1,{community:fe(e,t)}),n)}function Nt(n,e){return n===0?e===0?1:e>0?0:1/0:se(e*L(n))}const Bt=2**24;function jt(n,e){if(!(Number.isFinite(e)&&e>=0))throw new RangeError(`${n} must be a finite number >= 0, got ${String(e)}`)}function be(n,e,t,r){jt(n[0],e),p(n[1],t,1),p(n[2],r,t,Math.min(O,t+Bt-1));const o=r-t+1,i=new Float64Array(o);let c=0;for(let l=0;l<o;l++)c+=Nt(t+l,-e),i[l]=c;return l=>{const s=l.nextFloat()*c;let a=0,u=o-1;for(;a<u;){const f=a+u>>>1;i[f]>s?u=f:a=f+1}return t+a}}function Tt(n,e,t){let r=0;for(const i of n)r+=i;if(r%2===0)return;const o=n.length-1;if(n[o]<t)n[o]++;else if(n[o]>e)n[o]--;else throw new RangeError(`cannot make the degree sum even: every degree is ${e} and n is odd`)}function V(n,e){p(`${n}.length`,e.length,0);let t=0;for(let r=0;r<e.length;r++){const o=e[r];Number.isInteger(o)&&o>=0&&o<=O||p(`${n}[${r}]`,o,0),t+=o}return F(t/2),t}function Y(n,e){if(e!==void 0&&e!=="keep"&&e!=="erase")throw new RangeError(`${n} must be "keep" or "erase", got ${e}`);return e==="keep"}function T(n,e,t=0){const r=new Uint32Array(e);let o=0;for(let i=0;i<n.length;i++)r.fill(i+t,o,o+n[i]),o+=n[i];return r}function H(n,e){for(let t=n.length-1;t>0;t--){const r=e.nextBelow(t+1),o=n[t];n[t]=n[r],n[r]=o}}function he(n,e,t,r,o){const{directed:i,keepLoops:c,keepMulti:l,group:s}=r,a=e.length,u=new Uint8Array(a).fill(1);for(let f=0;f<a;f++){const h=e[f],d=t[f];(!c&&h===d||s!==void 0&&s[h]===s[d])&&(u[f]=0)}if(!l){const f=w=>i?e[w]:Math.min(e[w],t[w]),h=new Uint32Array(n+1);for(let w=0;w<a;w++)h[f(w)+1]++;for(let w=0;w<n;w++)h[w+1]+=h[w];const d=h.slice(0,n),m=new Uint32Array(a);for(let w=0;w<a;w++)m[d[f(w)]++]=w;const g=new Uint32Array(n);for(let w=0;w<a;w++){const y=m[w];if(u[y]===0)continue;const k=f(y),E=i?t[y]:Math.max(e[y],t[y]);g[E]===k+1?u[y]=0:g[E]=k+1}}for(let f=0;f<a;f++)u[f]===1&&o.push(e[f],t[f])}function ue(n,e,t,r,o,i){const c=e.length/2,l=new Uint32Array(c),s=new Uint32Array(c);for(let a=0;a<c;a++)l[a]=e[2*a],s[a]=e[2*a+1];he(n,l,s,{directed:!1,keepLoops:t,keepMulti:r,group:i},o)}function _t(n){const{degrees:e}=n,t=v(n.seed),r=Y("selfLoops",n.selfLoops),o=Y("multiEdges",n.multiEdges),i=V("degrees",e);if(i%2!==0)throw new RangeError(`the degree sum must be even, got ${i}`);const c=e.length,l=T(e,i);H(l,new S(t,"configuration",0));const s=new R(i/2);return ue(c,l,r,o,s),x(M(c,s,!1),n)}function Pt(n){const{outDegrees:e,inDegrees:t}=n,r=v(n.seed),o=Y("selfLoops",n.selfLoops),i=Y("multiEdges",n.multiEdges),c=V("outDegrees",e),l=V("inDegrees",t);if(e.length!==t.length)throw new RangeError("outDegrees and inDegrees must have the same length");if(c!==l)throw new RangeError(`the out-degree sum (${c}) must equal the in-degree sum (${l})`);const s=e.length,a=T(t,l);H(a,new S(r,"configuration-directed",0));const u=new R(c);return he(s,T(e,c),a,{directed:!0,keepLoops:o,keepMulti:i},u),x(M(s,u,!0),n)}function qt(n){const{leftDegrees:e,rightDegrees:t}=n,r=v(n.seed),o=Y("multiEdges",n.multiEdges),i=V("leftDegrees",e),c=V("rightDegrees",t);if(i!==c)throw new RangeError(`the left degree sum (${i}) must equal the right degree sum (${c})`);const l=e.length,s=l+t.length;p("the node count",s,0);const a=T(t,c,l);H(a,new S(r,"bipartite-configuration",0));const u=new R(i);he(s,T(e,i),a,{directed:!1,keepLoops:!0,keepMulti:o},u);const f=new Uint8Array(s).fill(1,l);return x(M(s,u,!1,{side:f}),n)}function Ce(n){p("expectedDegrees.length",n.length,0);let e=0;for(let t=0;t<n.length;t++){if(!(Number.isFinite(n[t])&&n[t]>=0))throw new RangeError(`expectedDegrees[${t}] must be a finite number >= 0, got ${String(n[t])}`);e+=n[t]}return e}function Ge(n,e,t,r,o,i){const c=n.length,l=new Uint32Array(c),s=new Uint32Array(c);for(let u=0;u<c;u++)l[u]=u;for(let u=0;u+1<e.length;u++)l.subarray(e[u],e[u+1]).sort((f,h)=>n[h]-n[f]||f-h),s.fill(u,e[u],e[u+1]);const a=Float64Array.from(l,u=>n[u]);return{n:c,seed:r,domain:o,order:l,weight:a,rowBlock:s,starts:e,factor:t,total:i}}function Ot(n){const e=v(n.seed),t=Ce(n.expectedDegrees),r=n.expectedDegrees.length;return Ge(n.expectedDegrees,[0,r],[[t>0?1/t:0]],e,"chung-lu",t)}function It(n,e,t,r){const{order:o,weight:i,rowBlock:c,starts:l,factor:s}=n,a=new S(n.seed,n.domain,0),u=l.length-1;for(let f=e;f<t;f++){a.reset(f);const h=c[f];for(let d=h;d<u;d++){const m=s[h][d]*i[f];let g=d===h?f+1:l[d];const w=l[d+1];if(m===0||g>=w)continue;let y=Math.min(1,m*i[g]);for(;g<w&&y>0;){if(y!==1){const E=L(1-y);if(E===0||(g+=a.nextSkip(E),g>=w))break}const k=Math.min(1,m*i[g]);a.nextFloat()<k/y&&r.push(o[f],o[g]),y=k,g++}}}}function De(n,e,t){const r=n.total/2;F(r);const o=new R(Math.ceil(r+6*Math.sqrt(r)+16));return It(n,0,n.n,o),x(M(n.n,o,!1,e),t)}function Wt(n){return De(Ot(n),void 0,n)}function Ht(n){const{sizes:e,expectedDegrees:t,mixing:r}=n,o=v(n.seed);p("sizes.length",e.length,1),D("mixing",r);const i=Ce(t),c=[0];for(let f=0;f<e.length;f++)p(`sizes[${f}]`,e[f],0),c.push(c[f]+e[f]);if(c[e.length]!==t.length)throw new RangeError(`the sizes sum to ${c[e.length]}, but expectedDegrees has ${t.length} entries`);const l=e.map((f,h)=>{let d=0;for(let m=c[h];m<c[h+1];m++)d+=t[m];return d}),s=i>0?r/i:0,a=l.map(f=>f>0?(1-r)/f:0),u=l.map((f,h)=>l.map((d,m)=>h===m?a[h]:s));return Ge(t,c,u,o,"dcsbm",i)}function Qt(n){const e=Ht(n),t=new Uint32Array(e.n);for(let r=0;r+1<e.starts.length;r++)t.fill(r,e.starts[r],e.starts[r+1]);return De(e,{community:t},n)}const ce=100,Xt=1e3;function Kt(n,e,t,r,o){o.fill(0);const i=(s,a)=>{const u=s*e;for(let f=u;f<u+o[s];f++)if(r[f]===a)return!0;return!1},c=new Uint32Array(n);let l=T(new Uint32Array(n).fill(e),n*e);for(let s=0;s<Xt&&l.length>0;s++){H(l,t);const a=[];for(let m=0;m<l.length;m+=2){const g=Math.min(l[m],l[m+1]),w=Math.max(l[m],l[m+1]);if(g!==w&&!i(g,w))r[g*e+o[g]++]=w,r[w*e+o[w]++]=g;else for(const y of[g,w])c[y]++===0&&a.push(y)}a.sort((m,g)=>m-g);let u=a.length===0;for(let m=0;m<a.length&&!u;m++)for(let g=m+1;g<a.length&&!u;g++)u=!i(a[m],a[g]);if(!u)return!1;let f=0;for(const m of a)f+=c[m];const h=new Uint32Array(f);let d=0;for(const m of a)h.fill(m,d,d+c[m]),d+=c[m],c[m]=0;l=h}return l.length===0}function Jt(n){const{n:e,d:t}=n,r=v(n.seed);if(p("n",e,0),p("d",t,0,Math.max(0,e-1)),e*t%2!==0)throw new RangeError(`n * d must be even, got ${e} * ${t}`);F(e*t/2);const o=new R(e*t/2);if(t>0){const i=new Uint32Array(e*t),c=new Uint32Array(e),l=new S(r,"random-regular",0);let s=0;for(;s<ce&&(l.reset(s),!Kt(e,t,l,i,c));s++);if(s===ce)throw new RangeError(`randomRegularGraph found no ${t}-regular graph on ${e} nodes in ${ce} attempts`);Vt(e,t,i,o)}return x(M(e,o,!1),n)}function Vt(n,e,t,r){for(let o=0;o<n;o++){const i=t.subarray(o*e,o*e+e).sort();for(const c of i)c>o&&r.push(o,c)}}function Ae(n,e){if(e!==void 0&&e!=="keep"&&e!=="erase")throw new RangeError(`${n} must be "keep" or "erase", got ${e}`)}function Le(n,e,t,r,o,i){const c=r.directed??!0,l=e.length;if(r.permute===!0){const u=new Uint32Array(n);for(let h=0;h<n;h++)u[h]=h;const f=new S(o,i,0);for(let h=n-1;h>0;h--){const d=f.nextBelow(h+1),m=u[h];u[h]=u[d],u[d]=m}for(let h=0;h<l;h++)e[h]=u[e[h]],t[h]=u[t[h]]}const s=new Uint8Array(l).fill(1);if(r.selfLoops==="erase")for(let u=0;u<l;u++)e[u]===t[u]&&(s[u]=0);if(r.multiEdges==="erase"){const u=c?e:e.map((d,m)=>Math.min(d,t[m])),f=c?t:e.map((d,m)=>Math.max(d,t[m])),h=new Uint32Array(l);for(let d=0;d<l;d++)h[d]=d;h.sort((d,m)=>u[d]-u[m]||f[d]-f[m]||d-m);for(let d=1;d<l;d++){const m=h[d-1],g=h[d];u[m]===u[g]&&f[m]===f[g]&&(s[g]=0)}}const a=new R(l);for(let u=0;u<l;u++)s[u]===1&&a.push(e[u],t[u]);return M(n,a,c)}function Ne(n){return Ae("selfLoops",n.selfLoops),Ae("multiEdges",n.multiEdges),v(n.seed)}function Yt(n){const{initiator:e,power:t}=n,r=e.length;p("initiator.length",r,1);let o=0;for(let w=0;w<r;w++){p(`initiator[${w}].length`,e[w].length,r,r);for(const y of e[w])D(`initiator[${w}] entries`,y),o+=y}p("power",t,1,64);let i=1,c=1;for(let w=0;w<t;w++)i*=r,c*=o;p("k^power (the node count)",i,1);const l=n.edges??Math.round(c);if(F(l),p("edges",l,0),l>0&&o===0)throw new RangeError("edges must be 0 when the initiator is all zeros");const s=Ne(n),a=r*r,u=new Float64Array(a);let f=0,h=0;for(let w=0;w<a;w++){const y=e[Math.floor(w/r)][w%r];f+=y,u[w]=f/o,y>0&&(h=w)}u.fill(1,h);const d=new Uint32Array(l),m=new Uint32Array(l),g=new S(s,"kronecker",0);for(let w=0;w<l;w++){g.reset(w);let y=0,k=0;for(let E=0;E<t;E++){const G=g.nextFloat();let C=0;for(;G>=u[C];)C++;y=y*r+Math.floor(C/r),k=k*r+C%r}d[w]=y,m[w]=k}return x(Le(i,d,m,n,s,"kronecker-permute"),n)}function Zt(n){const{scale:e}=n,t=n.edgeFactor??16,r=n.a??.57,o=n.b??.19,i=n.c??.19,c=n.d??.05;if(p("scale",e,0,31),p("edgeFactor",t,0),D("a",r),D("b",o),D("c",i),D("d",c),Math.abs(r+o+i+c-1)>1e-9)throw new RangeError(`a + b + c + d must be 1, got ${r+o+i+c}`);const l=2**e,s=t*l;F(s);const a=Ne(n),u=r+o,f=r+o+i,h=new Uint32Array(s),d=new Uint32Array(s),m=new S(a,"rmat",0);for(let g=0;g<s;g++){m.reset(g);let w=0,y=0;for(let k=0;k<e;k++){const E=m.nextFloat();w*=2,y*=2,E<r||(E<u?y+=1:E<f?w+=1:(w+=1,y+=1))}h[g]=w,d[g]=y}return x(Le(l,h,d,n,a,"rmat-permute"),n)}function en(n){const{n:e,citations:t}=n,r=n.attractiveness??1;if(p("n",e,1),p("citations",t,1),!(r>0&&Number.isFinite(r)))throw new RangeError(`attractiveness must be a positive number, got ${String(r)}`);const o=v(n.seed),i=Math.min(t,e),c=i*(i-1)/2+(e-i)*t;F(c);const l=new S(o,"price",0),s=new R(c),a=new Int32Array(e).fill(-1);for(let u=1;u<e;u++){const f=s.length;if(u<=t){for(let h=0;h<u;h++)s.push(u,h);continue}tn(l,s,a,u,t,f+r*u)}return x(M(e,s,!0),n)}function tn(n,e,t,r,o,i){const c=e.length;for(let l=0;l<o;){const a=n.nextFloat()*i<c?e.dst[n.nextBelow(c)]:n.nextBelow(r);t[a]!==r&&(t[a]=r,e.push(r,a),l++)}}function nn(n,e,t,r){const{n:o,p:i}=n,c=L(1-i),l=new S(v(n.seed),"order-dag",0);for(let s=e;s<t;s++)l.reset(s),ee(l,i,c,s,s+1,o,r)}function rn(n){const{n:e,p:t}=n;p("n",e,0),D("p",t),v(n.seed);const r=Z(e*(e-1)/2,t);return nn(n,0,e,r),x(M(e,r,!0),n)}function on(n,e,t,r){const{n:o,p:i}=n,c=L(1-i);if(n.directed===!0){sn(o,i,c,v(n.seed),e,t,r);return}const l=new S(v(n.seed),"gnp",0);for(let s=e;s<t;s++)l.reset(s),ee(l,i,c,s,s+1,o,r)}function sn(n,e,t,r,o,i,c){if(e===0)return;const l=new S(r,"gnp-directed",0);for(let s=o;s<i;s++){l.reset(s);let a=e===1?0:l.nextSkip(t);for(;a<n-1;)c.push(s,a<s?a:a+1),a+=e===1?1:1+l.nextSkip(t)}}function an(n){const{n:e,p:t}=n;p("n",e,0),D("p",t),v(n.seed);const r=n.directed===!0,o=e*(e-1)/(r?1:2),i=Z(o,t);return on(n,0,e,i),x(M(e,i,r),n)}class cn{constructor(e){let t=16;for(;t<e*2;)t*=2;this.slots=new Float64Array(t).fill(-1),this.mask=t-1}add(e){let t=Math.imul(e>>>0^Math.floor(e/4294967296),2654435761)&this.mask;for(;;){const r=this.slots[t];if(r===-1)return this.slots[t]=e,!0;if(r===e)return!1;t=t+1&this.mask}}}function ln(n){const{n:e,m:t}=n,r=v(n.seed);p("n",e,0,2**27);const o=e*(e-1)/2;p("m",t,0,Math.min(o,2**32-2));const i=new S(r,"gnm",0),c=new Float64Array(t),l=new cn(t);for(let f=0,h=o-t;h<o;h++,f++){const d=i.nextBelow(h+1);l.add(d)?c[f]=d:(l.add(h),c[f]=h)}c.sort();const s=new R(t);let a=0,u=0;for(let f=0;f<t;f++){const h=c[f];for(;h>=u+(e-a-1);)u+=e-a-1,a++;s.push(a,a+1+(h-u))}return x(M(e,s,!1),n)}const J=2**24;function Be(n,e){const t=n.minCapacity??1,r=n.maxCapacity??10;return p("minCapacity",t,0,J),p("maxCapacity",r,t,Math.floor(J/e)),{min:t,max:r}}function ie(n,e,t,r,o,i){const{src:c,dst:l}=e.finish(),s=new Uint8Array(n);return s[r]=1,s[o]=2,{directed:!0,nodeCount:n,src:c,dst:l,weights:Float32Array.from(t),nodeColumns:{...i,role:s},source:r,sink:o}}function je(n,e,t,r,o,i){const c=e+o*r+i,l=n.length;return i+1<r&&n.push(c,c+1),o+1<t&&n.push(c,c+r),i>0&&n.push(c,c-1),o>0&&n.push(c,c-r),n.length-l}function un(n){const{rows:e,cols:t}=n;p("rows",e,1),p("cols",t,2);const r=e*t;p("rows * cols + 2 (the node count)",r+2,0);const{min:o,max:i}=Be(n,4),c=v(n.seed),l=2*(e*(t-1)+t*(e-1))+2*e;F(l);const s=new R(l),a=[],u=new S(c,"grid-flow",0),f=new Float64Array(r+2),h=new Float64Array(r+2);for(let g=0;g<e;g++)for(let w=0;w<t;w++){const y=g*t+w;f[y]=w,h[y]=g,u.reset(y);const k=je(s,0,e,t,g,w);for(let E=0;E<k;E++)a.push(o+u.nextBelow(i-o+1))}const d=r,m=r+1;f[d]=-1,f[m]=t,h[d]=(e-1)/2,h[m]=(e-1)/2;for(let g=0;g<e;g++)s.push(d,g*t),a.push(4*i);for(let g=0;g<e;g++)s.push(g*t+t-1,m),a.push(4*i);return ie(r+2,s,a,d,m,{x:f,y:h})}function fn(n){const{layers:e,p:t}=n;p("layers.length",e.length,1),D("p",t);const r=[0];let o=0;for(let a=0;a<e.length;a++)p(`layers[${a}]`,e[a],1),r.push(r[a]+e[a]),o=Math.max(o,e[a]);const i=r[e.length];p("the total size + 2 (the node count)",i+2,0);const{min:c,max:l}=Be(n,o),s=new Uint32Array(i);for(let a=0;a<e.length;a++)s.fill(a,r[a],r[a+1]);return{starts:r,layerOf:s,p:t,min:c,max:l,terminal:l*o,seed:v(n.seed)}}function hn(n,e,t,r,o){const{starts:i,layerOf:c,p:l,min:s,max:a}=n,u=L(1-l),f=new S(n.seed,"layered-flow",0),h=i.length-2;for(let d=e;d<t;d++){const m=c[d];if(m<h){f.reset(d);const g=r.length;ee(f,l,u,d,i[m+1],i[m+2],r);for(let w=g;w<r.length;w++)o.push(s+f.nextBelow(a-s+1))}}}function dn(n){const e=fn(n),{starts:t}=e,r=t.length-1,o=t[r],i=new R(o),c=[];hn(e,0,o,i,c);const l=o,s=o+1,{terminal:a}=e;for(let f=t[0];f<t[1];f++)i.push(l,f),c.push(a);for(let f=t[r-1];f<t[r];f++)i.push(f,s),c.push(a);const u=new Uint32Array(o+2);for(let f=0;f<o;f++)u[f]=e.layerOf[f]+1;return u[s]=r+1,ie(o+2,i,c,l,s,{layer:u})}function gn(n){const{a:e,b:t,c1:r,c2:o}=n;p("a",e,1),p("b",t,1);const i=e*e;if(p("a * a * b (the node count)",i*t,2),p("c1",r,0,J),p("c2",o,r,J),o*i>J)throw new RangeError(`c2 * a * a must be at most 2^24 to stay exact, got ${o*i}`);const c=v(n.seed),l=i*t,s=t*4*e*(e-1)+(t-1)*i;F(s);const a=new R(s),u=[],f=new Uint32Array(l),h=new Uint32Array(i),d=new S(c,"genrmf",0);for(let m=0;m<t;m++){const g=m*i;if(f.fill(m,g,g+i),mn(a,u,g,e,o*i),m===t-1)break;d.reset(m),wn(d,h,a,u,g,r,o)}return ie(l,a,u,0,l-1,{frame:f})}function mn(n,e,t,r,o){for(let i=0;i<r;i++)for(let c=0;c<r;c++){const l=je(n,t,r,r,i,c);for(let s=0;s<l;s++)e.push(o)}}function wn(n,e,t,r,o,i,c){const l=e.length;for(let s=0;s<l;s++)e[s]=s;for(let s=l-1;s>0;s--){const a=n.nextBelow(s+1),u=e[s];e[s]=e[a],e[a]=u}for(let s=0;s<l;s++)t.push(o+s,o+l+e[s]),r.push(i+n.nextBelow(c-i+1))}const oe=1e6;function pn(n){const{k:e}=n;p("k",e,1,499998);const t=4*e+6,r=new R(6*e+7),o=[],i=(a,u,f)=>{r.push(a,u),o.push(f)},c=e+3,l=2*e+3,s=2*e+4;for(let a=0;a<e;a++)i(2+a,3+a,e+1-a),i(2+a,c,1);i(2+e,l,1),i(2+e,c,1);for(let a=c;a<l;a++)i(a,a+1,e+1);for(let a=0;a<=2*e;a++)i(s+a,s+a+1,e);for(let a=0;a<e;a++)i(s+a,s+2*e+1-a,1);return i(0,2,oe),i(0,s,oe),i(l,1,oe),i(s+2*e+1,1,oe),ie(t,r,o,0,1,{})}const yn=Math.SQRT2,xe=5e8;function Te(n){const e=n??2;if(e!==2&&e!==3)throw new RangeError(`dimension must be 2 or 3, got ${String(e)}`);return e}function de(n,e,t=!1){if(!(Number.isFinite(e)&&(t?e>0:e>=0)))throw new RangeError(`${n} must be a finite number ${t?">":">="} 0, got ${String(e)}`)}function ae(n,e,t,r){const o=Array.from({length:r},()=>new Float64Array(t)),i=new S(n,e,0);for(let c=0;c<t;c++){i.reset(c);for(const l of o)l[c]=i.nextFloat()}return o}function ge(n){const e=["x","y","z"];return Object.fromEntries(n.map((t,r)=>[e[r],t]))}function _e(n,e){let t=1;for(;(t+1)**e<=n;)t++;return t}function Pe(n,e,t,r){const o=n[0].length,i=t.map((f,h)=>(r[h]-f)/e||1),c=n.map(()=>new Uint32Array(o)),l=new Uint32Array(o),s=new Uint32Array(e**n.length+1);for(let f=0;f<o;f++){let h=0;for(let d=0;d<n.length;d++){const m=Math.min(e-1,Math.floor((n[d][f]-t[d])/i[d]));c[d][f]=m,h=h*e+m}l[f]=h,s[h+1]++}for(let f=0;f+1<s.length;f++)s[f+1]+=s[f];const a=s.slice(0,-1),u=new Uint32Array(o);for(let f=0;f<o;f++)u[a[l[f]]++]=f;return{g:e,lo:t,side:i,start:s,items:u,cell:c}}function bn(n){const{n:e,radius:t}=n;p("n",e,0),de("radius",t);const r=Te(n.dimension),o=n.periodic??!1,i=v(n.seed),c=ae(i,"rgg-points",e,r),l=t*t,s=Math.max(1,Math.min(Math.floor((1-1e-9)/t),_e(Math.max(1,e),r))),a=Pe(c,s,new Array(r).fill(0),new Array(r).fill(1)),u=r===2?Math.PI*l:4/3*Math.PI*l*t,f=e*(e-1)/2,h=new R(Math.ceil(Math.min(f,f*u*1.1,1<<24)+16)),d={axes:c,grid:a,periodic:o,r2:l,around:xn(s,o),found:new An};for(let m=0;m<e;m++)for(const g of kn(d,m))h.push(m,g);return x(M(e,h,!1,ge(c)),n)}class An{constructor(){this.data=new Uint32Array(16),this.count=0}push(e){if(this.count===this.data.length){const t=new Uint32Array(this.count*2);t.set(this.data),this.data=t}this.data[this.count++]=e}}function xn(n,e){return Array.from({length:n},(t,r)=>{const o=e?[(r+n-1)%n,r,(r+1)%n]:[r-1,r,r+1].filter(i=>i>=0&&i<n);return[...new Set(o)]})}function kn(n,e){const{grid:t,around:r,found:o}=n,{g:i,cell:c}=t,l=c.length===3;o.count=0;const s=l?r[c[2][e]]:[0];for(const a of r[c[0][e]])for(const u of r[c[1][e]])for(const f of s)Mn(n,e,l?(a*i+u)*i+f:a*i+u);return o.data.subarray(0,o.count).sort()}function Mn(n,e,t){const{axes:r,grid:o,periodic:i,r2:c,found:l}=n;for(let s=o.start[t];s<o.start[t+1];s++){const a=o.items[s];if(a<=e)continue;let u=0;for(const f of r){let h=Math.abs(f[e]-f[a]);i&&h>.5&&(h=1-h),u+=h*h}u<=c&&l.push(a)}}function Rn(n){const{n:e,alpha:t,beta:r}=n;p("n",e,0),de("alpha",t,!0),D("beta",r);const o=v(n.seed);if(r*e*e/2>xe)throw new RangeError(`waxmanGraph: beta n^2 / 2 = ${r*e*e/2} candidate pairs, above the limit of ${xe}`);const[i,c]=ae(o,"waxman-points",e,2);return{n:e,seed:o,beta:r,logQ:L(1-r),scale:t*yn,x:i,y:c}}const ke=1e-9;function En(n,e,t){if(t>=1e-100&&t<=1e100){const o=t*(1-e)/Math.sqrt(e);if(n>o*o*(1+ke))return!1;const i=2*t*(1-e)/(1+e);if(n<i*i*(1-ke))return!0}const r=t*L(e);return n<r*r}function Sn(n,e,t,r){const{n:o,beta:i,logQ:c,scale:l,x:s,y:a}=n;if(i===0)return;const u=new S(n.seed,"waxman",0),f=()=>i===1?0:u.nextSkip(c);for(let h=e;h<t;h++){u.reset(h);for(let d=h+1+f();d<o;d+=1+f()){const m=s[h]-s[d],g=a[h]-a[d];En(m*m+g*g,u.nextFloat(),l)&&r.push(h,d)}}}function vn(n){const e=Rn(n),t=new R(Math.min(Math.ceil(e.beta*e.n*e.n/8),1<<24)+16);return Sn(e,0,e.n,t),x(M(e.n,t,!1,ge([e.x,e.y])),n)}function $n(n,e,t,r,o){const i=ae(n,"knn-centres",r,t),c=Array.from({length:t},()=>new Float64Array(e)),l=new Uint32Array(e),s=new S(n,"knn-points",0),a=new Float64Array(4);for(let u=0;u<e;u++){s.reset(u);const f=s.nextBelow(r);l[u]=f;for(let h=0;h<t;h+=2){let d,m,g;do d=2*s.nextFloat()-1,m=2*s.nextFloat()-1,g=d*d+m*m;while(g>=1||g===0);const w=Math.sqrt(-2*L(g)/g);a[h]=d*w,a[h+1]=m*w}for(let h=0;h<t;h++)c[h][u]=i[h][f]+o*a[h]}return{axes:c,community:l}}function Un(n,e){const t=n[0].length,r=n.length;if(e===0)return new Uint32Array(0);const o=new Uint32Array(t*e),i=n.map(a=>a.reduce((u,f)=>Math.min(u,f),1/0)),c=n.map(a=>a.reduce((u,f)=>Math.max(u,f),-1/0)),l=_e(Math.max(1,t/e),r),s={axes:n,grid:Pe(n,l,i,c),best:new zn(e),slack:1e-12*Math.max(1,...i.map(Math.abs),...c.map(Math.abs)),cell:new Array(r).fill(0),offset:new Array(r).fill(0)};for(let a=0;a<t;a++){Fn(s,a);const u=o.subarray(a*e,(a+1)*e);u.set(s.best.index),u.sort()}return o}class zn{constructor(e){this.k=e,this.count=0,this.d2=new Float64Array(e),this.index=new Uint32Array(e)}consider(e,t){const{k:r,d2:o,index:i}=this;if(this.count===r&&(e>o[r-1]||e===o[r-1]&&t>i[r-1]))return;let c=this.count<r?this.count++:r-1;for(;c>0&&(o[c-1]>e||o[c-1]===e&&i[c-1]>t);)o[c]=o[c-1],i[c]=i[c-1],c--;o[c]=e,i[c]=t}}function Fn(n,e){const{grid:t,cell:r}=n;for(let o=0;o<r.length;o++)r[o]=t.cell[o][e];n.best.count=0;for(let o=0;;o++)if(Gn(n,e,o),Cn(r,o,t.g)||Bn(n,e,o))return}function Cn(n,e,t){return n.every(r=>r-e<=0&&r+e>=t-1)}function Gn(n,e,t){const{cell:r,offset:o,grid:i}=n;o.fill(-t);do{const c=Ln(r,o,i.g,t);c>=0&&Dn(n,e,c)}while(Nn(o,t))}function Dn(n,e,t){const{axes:r,grid:o,best:i}=n;for(let c=o.start[t];c<o.start[t+1];c++){const l=o.items[c];if(l!==e){let s=0;for(const a of r){const u=Math.abs(a[e]-a[l]);s+=u*u}i.consider(s,l)}}}function Ln(n,e,t,r){let o=0,i=!0,c=0;for(let l=0;l<n.length;l++){const s=n[l]+e[l];(s<0||s>=t)&&(i=!1),o=Math.max(o,Math.abs(e[l])),c=c*t+s}return i&&o===r?c:-1}function Nn(n,e){let t=n.length-1;for(;t>=0&&n[t]===e;)n[t]=-e,t--;return t<0?!1:(n[t]++,!0)}function Bn(n,e,t){const{axes:r,grid:o,best:i,cell:c,slack:l}=n;if(i.count!==i.k)return!1;let s=1/0;for(let a=0;a<c.length;a++){const u=r[a][e]-o.lo[a];s=Math.min(s,u-(c[a]-t)*o.side[a],(c[a]+t+1)*o.side[a]-u)}return s-=l,s>0&&i.d2[i.k-1]<s*s*(1-1e-9)}function jn(n){const{n:e,k:t,clusters:r,spread:o}=n;p("n",e,0),p("k",t,0,Math.max(0,e-1));const i=Te(n.dimension),c=n.directed??!0;if(r===void 0&&o!==void 0)throw new RangeError("spread needs clusters");const l=v(n.seed);let s;const a={};if(r===void 0)s=ae(l,"knn-points",e,i);else{p("clusters",r,1);const h=o??.05;de("spread",h);let d;({axes:s,community:d}=$n(l,e,i,r,h)),a.community=d}Object.assign(a,ge(s));const u=Un(s,t);F(e*t);let f;if(c){f=new R(e*t);for(let h=0;h<e;h++)for(let d=h*t;d<(h+1)*t;d++)f.push(h,u[d])}else{const h=new Uint32Array(e+1);for(let g=0;g<e;g++)for(let w=g*t;w<(g+1)*t;w++)h[Math.min(g,u[w])+1]++;for(let g=0;g<e;g++)h[g+1]+=h[g];const d=h.slice(0,-1),m=new Uint32Array(e*t);for(let g=0;g<e;g++)for(let w=g*t;w<(g+1)*t;w++){const y=u[w];m[d[Math.min(g,y)]++]=Math.max(g,y)}f=new R(e*t);for(let g=0;g<e;g++){const w=m.subarray(h[g],h[g+1]).sort();for(let y=0;y<w.length;y++)(y===0||w[y]!==w[y-1])&&f.push(g,w[y])}}return x(M(e,f,c,a),n)}function Tn(n){const{n:e}=n;p("n",e,1);const t=new S(v(n.seed),"recursive-tree",0),r=new Uint32Array(e-1),o=new Uint32Array(e-1);for(let i=1;i<e;i++)r[i-1]=t.nextBelow(i),o[i-1]=i;return x({directed:!1,nodeCount:e,src:r,dst:o},n)}function _n(n,e,t){for(let r=0;r<t;r++){const o=r+n.nextBelow(e.length-r),i=e[r];e[r]=e[o],e[o]=i}}function Pn(n,e){if(!(n>=0&&n<1))throw new RangeError(`forward must be a probability in [0, 1), got ${String(n)}`);if(!(e>=0&&e*n<1))throw new RangeError(`backward must be >= 0 with backward * forward < 1, got ${String(e)}`)}function qn(n){const{n:e,forward:t,backward:r}=n,o=n.maxBurn??1e3;p("n",e,1),Pn(t,r),p("maxBurn",o,1);const i=new S(v(n.seed),"forest-fire",0),c=r*t,l=L(t),s=L(c),a=Array.from({length:e},()=>[]),u=Array.from({length:e},()=>[]),f=new Uint32Array(e),h=new R(4*e),d=[],m=(g,w,y)=>{const k=w.filter(G=>f[G]!==g),E=Math.min(y,k.length,o-d.length);_n(i,k,E);for(let G=0;G<E;G++)f[k[G]]=g,d.push(k[G])};for(let g=1;g<e;g++){d.length=0;const w=i.nextBelow(g);f[w]=g,d.push(w);for(let y=0;y<d.length&&d.length<o;y++){const k=d[y],E=t===0?0:i.nextSkip(l),G=c===0?0:i.nextSkip(s);m(g,a[k],E),m(g,u[k],G)}for(const y of d)h.push(g,y),a[g].push(y),u[y].push(g)}return x(M(e,h,!0),n)}function On(n){const{n:e,retention:t}=n;if(p("n",e,2),!(t>0&&t<=1))throw new RangeError(`retention must be a probability in (0, 1], got ${String(t)}`);const r=new S(v(n.seed),"duplication-divergence",0),o=Array.from({length:e},()=>[]),i=new R(4*e);i.push(0,1),o[0].push(1),o[1].push(0);const c=1e3*e;let l=0;for(let s=2;s<e;){if(++l>c)throw new RangeError(`duplicationDivergenceGraph gave up after ${c} attempts at ${s} of ${e} nodes: retention ${t} is too small`);const a=o[r.nextBelow(s)];for(const u of a)r.nextFloat()<t&&(i.push(s,u),o[s].push(u));for(const u of o[s])o[u].push(s);o[s].length>0&&s++}return x(M(e,i,!1),n)}function In(n){const{n:e,k:t,p:r}=n;if(p("k",t,2),t%2!==0)throw new RangeError(`k must be even, got ${t}`);p("n",e,t+1),D("p",r);const o=t/2,i=e*o;F(2*i);const c=new R(i+Math.ceil(i*r+6*Math.sqrt(i)+16)),l=new Uint32Array(e).fill(t),s=new Set,a=(f,h)=>f<h?f*e+h:h*e+f;for(let f=0;f<e;f++)for(let h=1;h<=o;h++){const d=(f+h)%e;c.push(f,d),s.add(a(f,d))}const u=new S(v(n.seed),"newman-watts",0);for(let f=0;f<i;f++){const h=c.src[f];if(u.nextFloat()>=r||l[h]>=e-1)continue;let d=u.nextBelow(e);for(;d===h||s.has(a(h,d));)d=u.nextBelow(e);c.push(h,d),s.add(a(h,d)),l[h]++,l[d]++}return x(M(e,c,!1),n)}function Wn(n){const{n:e,m:t}=n;p("m",t,1),p("n",e,t+1);const r=v(n.seed);F(t*(t+1)/2+(e-t-1)*t);const o=new Float64Array(e);if(n.fitness===void 0){const g=new S(r,"fitness",0);for(let w=0;w<e;w++)g.reset(w),o[w]=1-g.nextFloat()}else{if(n.fitness.length!==e)throw new RangeError(`fitness must have n = ${e} values, got ${n.fitness.length}`);for(let g=0;g<e;g++){const w=n.fitness[g];if(!(w>0&&Number.isFinite(w)))throw new RangeError(`fitness[${g}] must be finite and positive, got ${String(w)}`);o[g]=w}}const i=new R(t*(t+1)/2+(e-t-1)*t),c=new Uint32Array(e);for(let g=0;g<=t;g++){for(let w=g+1;w<=t;w++)i.push(g,w);c[g]=t}const l=new Float64Array(e),s=new Float64Array(e+1),a=(g,w)=>{l[g]+=w;for(let y=g+1;y<=e;y+=y&-y)s[y]+=w};let u=1;for(;u*2<=e;)u*=2;const f=(g,w)=>{let y=0,k=g;for(let E=u;E>=1;E=Math.floor(E/2))y+E<=e&&s[y+E]<=k&&(y+=E,k-=s[y]);for(y=Math.min(y,w-1);l[y]===0;)y--;return y};let h=0;for(let g=0;g<=t;g++)a(g,o[g]*t),h+=o[g]*t;const d=new S(r,"bianconi-barabasi",0),m=new Uint32Array(t);for(let g=t+1;g<e;g++){let w=h;for(let y=0;y<t;y++){const k=f(d.nextFloat()*w,g);m[y]=k,w-=l[k],a(k,-l[k])}for(let y=0;y<t;y++){const k=m[y];i.push(g,k),c[k]++,a(k,o[k]*c[k])}c[g]=t,a(g,o[g]*t),h=0;for(let y=e;y>0;y-=y&-y)h+=s[y]}return x(M(e,i,!1,{fitness:o}),n)}function Hn(n){const{n:e}=n;p("n",e,3);const t=3*e-6;F(t);const r=new S(v(n.seed),"apollonian",0),o=2*e-5,i=new Uint32Array(o),c=new Uint32Array(o),l=new Uint32Array(o);i[0]=0,c[0]=1,l[0]=2;let s=1;const a=new Uint32Array(t),u=new Uint32Array(t);a.set([0,0,1]),u.set([1,2,2]);let f=3;for(let h=3;h<e;h++){const d=r.nextBelow(s),m=i[d],g=c[d],w=l[d];a.fill(h,f,f+3),u[f++]=m,u[f++]=g,u[f++]=w,l[d]=h,i[s]=g,c[s]=w,l[s++]=h,i[s]=m,c[s]=w,l[s++]=h}return x({directed:!1,nodeCount:e,src:a,dst:u},n)}function Qn(n,e,t,r){const o=Math.floor(n/t),i=n-o*t;let c=0;return i>0&&(r[c++]=n-1),i+1<t&&(r[c++]=n+1),o>0&&(r[c++]=n-t),o+1<e&&(r[c++]=n+t),c}function Xn(n){const{rows:e,cols:t}=n;p("rows",e,1),p("cols",t,1);const r=e*t;p("rows * cols",r,1);const o=new S(v(n.seed),"wilson",0),i=new Uint8Array(r),c=new Uint32Array(r),l=new Uint32Array(r-1),s=new Uint32Array(r-1),a=new Uint32Array(4);i[0]=1;let u=0;for(let d=1;d<r;d++){let m=d;for(;i[m]===0;){const g=Qn(m,e,t,a);c[m]=a[o.nextBelow(g)],m=c[m]}for(m=d;i[m]===0;m=c[m])i[m]=1,l[u]=m,s[u++]=c[m]}const f=new Float64Array(r),h=new Float64Array(r);for(let d=0;d<r;d++)h[d]=Math.floor(d/t),f[d]=d-h[d]*t;return x({directed:!1,nodeCount:r,src:l,dst:s,nodeColumns:{x:f,y:h}},n)}const Me=.7853981633974483,Kn=-.16666666666666632,Jn=.00833333333332249,Vn=-.0001984126982985795,Yn=27557313707070068e-22,Zn=-25050760253406863e-24,er=158969099521155e-24,tr=.0416666666666666,nr=-.001388888888887411,rr=2480158728947673e-20,or=-27557314351390663e-23,sr=2087572321298175e-24,ir=-11359647557788195e-27;function Re(n){const e=n*n,t=Jn+e*(Vn+e*(Yn+e*(Zn+e*er)));return n+e*n*(Kn+e*t)}function Ee(n){const e=n*n,t=e*e,r=e*(tr+e*(nr+e*rr))+t*t*(or+e*(sr+e*ir)),o=.5*e,i=1-o;return i+(1-i-o+e*r)}function Se(n,e){const t=n*8,r=Math.floor(t),o=(t-r)*Me,i=(r&1)===1,c=i?Me-o:o,l=i?Re(c):Ee(c),s=i?Ee(c):Re(c);switch(r>>1&3){case 0:e[0]=l,e[1]=s;break;case 1:e[0]=-s,e[1]=l;break;case 2:e[0]=-l,e[1]=-s;break;default:e[0]=s,e[1]=-l}}const ar=2e4;function ve(n){return(se(n)+se(-n))/2}function qe(n){return L(n+Math.sqrt((n-1)*(n+1)))}function cr(n){const{n:e,averageDegree:t,exponent:r}=n,o=n.temperature??0;if(p("n",e,0,ar),!(Number.isFinite(t)&&t>0))throw new RangeError(`averageDegree must be a finite number > 0, got ${String(t)}`);if(!(Number.isFinite(r)&&r>2))throw new RangeError(`exponent must be a finite number > 2, got ${String(r)}`);if(!(o>=0&&o<1))throw new RangeError(`temperature must be in [0, 1), got ${String(o)}`);const i=v(n.seed),c=(r-1)/2,l=c/(c-.5);let s=1;if(o>0){const C=new Float64Array(2);Se(o/2,C),s=Math.PI*o/C[1]}const a=2*l*l*e/(Math.PI*t)*s;if(e>=2&&!(a>1))throw new RangeError(`averageDegree ${t} is too large for n = ${e}: the disk radius would be <= 0`);const u=e>=2?2*L(a):0,f=ve(c*u);if(!Number.isFinite(f))throw new RangeError(`exponent ${r} is too large: cosh(alpha R) overflows`);const h=new Float64Array(e),d=new Float64Array(e),m=new Float64Array(e),g=new Float64Array(e),w=new Float64Array(e),y=new Float64Array(e),k=new Float64Array(e),E=new Float64Array(2),G=new S(i,"hyperbolic-points",0);for(let C=0;C<e;C++){G.reset(C),Se(G.nextFloat(),E);const _=qe(1+(f-1)*G.nextFloat())/c,P=se(_);h[C]=E[0],d[C]=E[1],m[C]=(P+1/P)/2,g[C]=(P-1/P)/2,k[C]=_,w[C]=_*E[0],y[C]=_*E[1]}return{n:e,seed:i,temperature:o,R:u,coshR:ve(u),cosT:h,sinT:d,coshr:m,sinhr:g,x:w,y,radius:k}}function lr(n,e,t,r){const{n:o,R:i,coshR:c,temperature:l,cosT:s,sinT:a,coshr:u,sinhr:f}=n,h=new S(n.seed,"hyperbolic",0);for(let d=e;d<t;d++){h.reset(d);for(let m=d+1;m<o;m++){const g=u[d]*u[m]-f[d]*f[m]*(s[d]*s[m]+a[d]*a[m]);if(l===0){g<c&&r.push(d,m);continue}const w=h.nextFloat();qe(Math.max(1,g))<i+2*l*L((1-w)/w)&&r.push(d,m)}}}function ur(n){const e=cr(n),t=new R(Math.ceil(e.n*n.averageDegree*.75)+16);return lr(e,0,e.n,t),x(M(e.n,t,!1,{x:e.x,y:e.y,radius:e.radius}),n)}function fr(n){const e=[[1,0,0],[0,1,0],[0,0,1]];if(!n)return e;for(let t=0;t<=1;t++)for(let r=-1;r<=1;r++)for(let o=-1;o<=1;o++){const i=Math.abs(o)+Math.abs(r)+Math.abs(t)===1;hr(t,r,o)&&!i&&e.push([o,r,t])}return e}function hr(n,e,t){return n!==0?n>0:e===0?t>0:e>0}function dr(n,e){if(n.obstacles===void 0)return null;const t=n.obstacles;if(D("obstacles",t),t>=1)throw new RangeError("obstacles must be below 1");const r=new Uint8Array(e),o=new S(v(n.seed),"grid-obstacles",0);for(let i=0;i<e;i++)o.reset(i),r[i]=o.nextFloat()<t?1:0;return r}function gr(n,e,t,r){const{sizes:o,wraps:i}=n;for(let c=0;c<3;c++){let l=e[c]+t[c];if(l<0||l>=o[c]){if(!i[c])return-1;l=(l+o[c])%o[c]}r[c]=l}return r[2]*n.plane+r[1]*o[0]+r[0]}function mr(n,e,t,r,o){const{blocked:i}=e;for(const c of e.offsets){const l=gr(e,r,c,o);l>=0&&i?.[l]!==1&&n.push(t,l)}}function wr(n){const[e,t,r]=n.sizes,{plane:o,blocked:i}=n,c=new R(o*r*Math.min(n.offsets.length,3)),l=[0,0,0];for(let s=0;s<r;s++)for(let a=0;a<t;a++)for(let u=0;u<e;u++){const f=s*o+a*e+u;i?.[f]!==1&&mr(c,n,f,[u,a,s],l)}return c}function pr(n,e,t){const r=n*e*t,o=n*e,i=new Float64Array(r),c=new Float64Array(r),l=t>1?new Float64Array(r):null;for(let s=0;s<r;s++)i[s]=s%e,c[s]=Math.floor(s/e)%n,l!==null&&(l[s]=Math.floor(s/o));return l===null?{x:i,y:c}:{x:i,y:c,z:l}}function Oe(n){const{rows:e,cols:t,layers:r}=n;p("rows",e,1),p("cols",t,1),p("layers",r,1);const o=e*t*r;p("rows * cols * layers",o,1);const i=n.periodic===!0,c=n.directed===!0;if(i&&c)throw new RangeError("directed grids cannot be periodic: the wrap-around arcs would close cycles");const l=fr(n.diagonals===!0);F(o*l.length);const s=dr(n,o),a=[t,e,r],u=a.map(m=>i&&m>=3),f=wr({sizes:a,wraps:u,plane:e*t,offsets:l,blocked:s}),h={};s!==null&&(h.blocked=s),n.positions===!0&&Object.assign(h,pr(e,t,r));const d=M(o,f,c,Object.keys(h).length>0?h:void 0);return x(d,n)}function yr(n){return Oe({...n,layers:1})}const Ie=.8660254037844386;function We(n){p("rows",n.rows,1),p("cols",n.cols,1);const e=n.rows*n.cols;return p("rows * cols",e,1),F(3*e),e}function br(n,e){const t=new Float64Array(n),r=new Float64Array(n);for(let o=0;o<n;o++){const i=Math.floor(o/e);t[o]=o%e+i/2,r[o]=i*Ie}return{x:t,y:r}}function Ar(n,e){const t=new Float64Array(n),r=new Float64Array(n);for(let o=0;o<n;o++){const i=Math.floor(o/e),c=o%e;t[o]=c*Ie,r[o]=1.5*i+((i+c)%2===0?.5:0)}return{x:t,y:r}}function xr(n){const e=We(n),{rows:t,cols:r}=n,o=new R(3*e);for(let c=0;c<t;c++)for(let l=0;l<r;l++){const s=c*r+l;l+1<r&&o.push(s,s+1),c+1<t&&(o.push(s,s+r),l>0&&o.push(s,s+r-1))}const i=n.positions===!0?br(e,r):void 0;return x(M(e,o,!1,i),n)}function kr(n){const e=We(n),{rows:t,cols:r}=n,o=new R(2*e);for(let c=0;c<t;c++)for(let l=0;l<r;l++){const s=c*r+l;l+1<r&&o.push(s,s+1),c+1<t&&(c+l)%2===0&&o.push(s,s+r)}const i=n.positions===!0?Ar(e,r):void 0;return x(M(e,o,!1,i),n)}const Mr=1e6;function Rr(n,e,t,r,o){if(Math.ceil(n/t)*e>n)throw new RangeError(`there is no partition of ${n} nodes into communities of ${e} to ${t} nodes`);const i=new S(o,"lfr-sizes",0),c=[];let l=-n;for(;l<0;){const s=r(i);c.push(s),l+=s}c.length*e>n&&(l-=c[c.length-1],c.pop());for(let s=c.length-1;s>=0&&l!==0;s--){const a=l>0?-Math.min(l,c[s]-e):Math.min(-l,t-c[s]);c[s]+=a,l+=a}return c}function Er(n,e,t){const r=n.length,o=Uint32Array.from({length:r},(f,h)=>h).sort((f,h)=>n[h]-n[f]||f-h),i=Uint32Array.from(e,(f,h)=>h).sort((f,h)=>e[h]-e[f]||f-h),c=e.slice(),l=[],s=new Uint32Array(r),a=new S(t,"lfr-assign",0);let u=0;for(const f of o){for(;u<i.length&&e[i[u]]>n[f];)l.push(i[u++]);if(l.length===0)throw new RangeError(`could not assign communities: node ${f} needs a community of more than ${n[f]} nodes; raise maxCommunity or mixing, or lower maxDegree`);const h=a.nextBelow(l.length),d=l[h];s[f]=d,--c[d]===0&&(l[h]=l[l.length-1],l.pop())}return s}function Sr(n){const{n:e,minDegree:t,maxDegree:r,minCommunity:o,maxCommunity:i,mixing:c}=n,l=v(n.seed);p("n",e,1,Mr),p("maxDegree",r,1,e-1),D("mixing",c),p("maxCommunity",i,1,e);const s=be(["degreeExponent","minDegree","maxDegree"],n.degreeExponent,t,r),a=be(["communityExponent","minCommunity","maxCommunity"],n.communityExponent,o,i),u=new Uint32Array(e),f=new S(l,"lfr-degrees",0);for(let z=0;z<e;z++)u[z]=s(f);Tt(u,t,r);const h=Rr(e,o,i,a,l),d=Uint32Array.from(u,z=>Math.round((1-c)*z)),m=Er(d,h,l),g=new Uint32Array(h.length+1);for(let z=0;z<h.length;z++)g[z+1]=g[z]+h[z];const w=g.slice(0,h.length),y=new Uint32Array(e);for(let z=0;z<e;z++)y[w[m[z]]++]=z;let k=0;for(const z of u)k+=z;const E=new R(k/2),G=new S(l,"lfr-internal",0);for(let z=0;z<h.length;z++){const Q=y.subarray(g[z],g[z+1]),I=Uint32Array.from(Q,j=>d[j]);let te=0,ne=0;for(let j=0;j<I.length;j++)te+=I[j],I[j]>I[ne]&&(ne=j);te%2===1&&(I[ne]--,d[Q[ne]]--,te--);const X=T(I,te);for(let j=0;j<X.length;j++)X[j]=Q[X[j]];G.reset(z),H(X,G),ue(e,X,!1,!1,E)}const C=Uint32Array.from(u,(z,Q)=>z-d[Q]);let _=0;for(const z of C)_+=z;const P=T(C,_);return H(P,new S(l,"lfr-external",0)),ue(e,P,!1,!1,E,m),x(M(e,E,!1,{community:m}),n)}function vr(n){const{n:e,m:t}=n,r=n.triadProbability??0;p("m",t,1),p("n",e,t+1),D("triadProbability",r);const o=v(n.seed),i=(e-t)*t;F(i);const c=new S(o,"barabasi-albert",0),l=new R(i),s=new Uint32Array(t+2*i);let a=0;for(let d=0;d<t;d++)s[a++]=d;const u=r>0?Array.from({length:e},()=>[]):null,f=new Array(t),h=(d,m)=>{l.push(d,m),s[a++]=m,u!==null&&(u[d].push(m),u[m].push(d))};for(let d=t;d<e;d++){let m=0;for(;m<t;){const y=s[c.nextBelow(a)];let k=!0;for(let E=0;E<m;E++)k&&=f[E]!==y;k&&(f[m++]=y)}let g=0,w=f[g++];h(d,w);for(let y=1;y<t;y++){if(u!==null&&c.nextFloat()<r){const k=u[d],E=u[w].filter(G=>G!==d&&!k.includes(G));if(E.length>0){h(d,E[c.nextBelow(E.length)]);continue}}do w=f[g++];while(u!==null&&u[d].includes(w)&&g<t);if(u?.[d].includes(w))do w=s[c.nextBelow(a)];while(w===d||u[d].includes(w));h(d,w)}for(let y=0;y<t;y++)s[a++]=d}return x(M(e,l,!1),n)}function $r(n){const{n:e,k:t,beta:r}=n;if(p("k",t,2),t%2!==0)throw new RangeError(`k must be even, got ${t}`);p("n",e,t+1),D("beta",r);const o=v(n.seed),i=t/2,c=e*i;F(c);const l=new Uint32Array(c),s=new Uint32Array(c),a=new Uint32Array(e).fill(t),u=new Set,f=(d,m)=>d<m?d*e+m:m*e+d;for(let d=0;d<e;d++)for(let m=1;m<=i;m++){const g=(d+m)%e;l[d*i+m-1]=d,s[d*i+m-1]=g,u.add(f(d,g))}const h=new S(o,"watts-strogatz",0);for(let d=1;d<=i;d++)for(let m=0;m<e;m++){if(h.nextFloat()>=r||a[m]>=e-1)continue;let g=h.nextBelow(e);for(;g===m||u.has(f(m,g));)g=h.nextBelow(e);const w=m*i+d-1,y=s[w];u.delete(f(m,y)),u.add(f(m,g)),a[y]--,a[g]++,s[w]=g}return x({directed:!1,nodeCount:e,src:l,dst:s},n)}function Ur(n){const{n:e}=n;p("n",e,1);const t=v(n.seed),r=new R(e);if(e===1)return x(M(1,r,!1),n);const o=new S(t,"prufer",0),i=new Uint32Array(e-2),c=new Uint32Array(e).fill(1);for(let a=0;a<e-2;a++)i[a]=o.nextBelow(e),c[i[a]]++;let l=0;for(;c[l]!==1;)l++;let s=l;for(let a=0;a<e-2;a++){const u=i[a];if(r.push(s,u),c[u]--,c[u]===1&&u<l)s=u;else{for(l++;c[l]!==1;)l++;s=l}}return r.push(s,e-1),x(M(e,r,!1),n)}function zr(n,e,t,r,o,i,c){const l=L(1-t),s=new S(r,"layered-dag",0),a=n.length-2;for(let u=o;u<i;u++){const f=e[u];f<a&&(s.reset(u),ee(s,t,l,u,n[f+1],n[f+2],c))}}function Fr(n){const{layers:e,p:t}=n;p("layers.length",e.length,1),D("p",t);const r=v(n.seed),o=[0];let i=0;for(let a=0;a<e.length;a++)p(`layers[${a}]`,e[a],0),o.push(o[a]+e[a]),a>0&&(i+=e[a-1]*e[a]);const c=o[e.length];p("the total size",c,0);const l=new Uint32Array(c);for(let a=0;a<e.length;a++)l.fill(a,o[a],o[a+1]);const s=Z(i,t);return zr(o,l,t,r,0,c,s),x(M(c,s,!0,{layer:l}),n)}const $e={ak:pn,"balanced-tree":Ut,"barabasi-albert":vr,barbell:Et,"bianconi-barabasi":Wn,"bipartite-configuration-model":qt,caveman:vt,"chung-lu":Wt,"circular-ladder":Gt,complete:xt,"complete-bipartite":kt,"complete-multipartite":Ct,"configuration-model":_t,"connected-caveman":$t,cycle:yt,"degree-corrected-sbm":Qt,"directed-configuration-model":Pt,"duplication-divergence":On,empty:Ft,"erdos-renyi":an,"erdos-renyi-gnm":ln,"forest-fire":qn,genrmf:gn,grid:yr,"grid-3d":Oe,"grid-flow-network":un,"hexagonal-lattice":kr,hyperbolic:ur,hypercube:Mt,knn:jn,kronecker:Yt,ladder:Rt,"layered-flow-network":dn,lfr:Sr,lollipop:St,"mobius-ladder":Dt,named:n=>{if(!le.includes(n.name))throw me("named graph",n.name,le);return ct(n.name,n)},"newman-watts":In,path:pt,petersen:zt,"planted-partition":wt,price:en,"random-apollonian":Hn,"random-bipartite":dt,"random-dag":Fr,"random-geometric":bn,"random-order-dag":rn,"random-recursive-tree":Tn,"random-regular":Jt,"random-tree":Ur,"ring-of-cliques":Lt,rmat:Zt,star:bt,"stochastic-block-model":ze,"triangular-lattice":xr,"watts-strogatz":$r,waxman:vn,wheel:At,"wilson-maze":Xn},Br=["karate","florentine-families","davis-southern-women","les-miserables","football","political-books","dolphins","contiguous-usa","knuth-miles","celegans-neural","political-blogs","openflights","yeast-perturbation","stelzl-interactome","wikipathways-senescence-autophagy","go-slim-generic"];function Cr(n,e){let t=Array.from({length:e.length+1},(r,o)=>o);for(let r=1;r<=n.length;r++){const o=[r];for(let i=1;i<=e.length;i++)o[i]=Math.min(t[i]+1,o[i-1]+1,t[i-1]+(n[r-1]===e[i-1]?0:1));t=o}return t[e.length]}function me(n,e,t){let r="",o=1/0;for(const c of t){const l=Cr(e,c);l<o&&(r=c,o=l)}const i=o<=Math.max(2,e.length/3)?` (did you mean ${JSON.stringify(r)}?)`:"";return new RangeError(`unknown ${n} ${JSON.stringify(e)}${i}; the ${n}s are ${t.join(", ")}`)}function He(n){const e="src"in n?Xe(n):n;return{elements:Ve(e),directed:e.directed}}function Gr(n){const{x:e,y:t,...r}=n.nodeColumns??{};if(!ArrayBuffer.isView(e)||!ArrayBuffer.isView(t))return n;const o=e,i=t,c=new Float64Array(2*n.nodeCount);for(let l=0;l<n.nodeCount;l++)c[2*l]=o[l],c[2*l+1]=i[l];return{...n,nodeColumns:{...r,position:{data:c,decl:{dtype:"f64",components:2,role:"position"}}}}}function jr(n,e){const t=$e[n];if(t===void 0)throw me("generator",n,Object.keys($e));const r=Ke[n]??[];for(const[c,l]of Object.entries(e??{}))if(l!==void 0&&!r.includes(c))throw new RangeError(`generator ${JSON.stringify(n)}: unknown option ${c}; the options are ${r.join(", ")}`);const o=He(Gr(t(e)));let i=0;for(const c of o.elements)c.group==="edges"&&(c.data.id=`e${String(i++)}`);return o}async function Tr(n,e={}){if(e.signal?.throwIfAborted(),e.baseUrl===void 0&&!ye.includes(n))throw me("dataset",n,ye);const t=await Ze(n,e);e.signal?.throwIfAborted();const r=He(t);for(const o of r.elements){const{x:i,y:c}=o.data;typeof i=="number"&&typeof c=="number"&&(o.position={x:i,y:Je(c)},delete o.data.x,delete o.data.y)}return r}export{Br as BUNDLED_DATASET_NAMES,$e as GENERATORS,le as NAMED_GRAPH_NAMES,Tr as datasetElements,jr as generateElements};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{z as k,e as E}from"./io-D-Vr0j3W.js";import"./preload-helper-Crt_PPe8.js";import"./elements-DIunzJUl.js";const z=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function l(e,n){return e>>>n|e<<32-n}function v(e){const n=Math.ceil((e.length+9)/64),r=new Uint8Array(n*64);r.set(e),r[e.length]=128;const o=new DataView(r.buffer);return o.setUint32(r.length-8,Math.floor(e.length/536870912)),o.setUint32(r.length-4,e.length*8>>>0),r}function D(e,n,r,o){for(let t=0;t<16;t++)n[t]=r.getUint32(o+t*4);for(let t=16;t<64;t++){const h=l(n[t-15],7)^l(n[t-15],18)^n[t-15]>>>3,w=l(n[t-2],17)^l(n[t-2],19)^n[t-2]>>>10;n[t]=n[t-16]+h+n[t-7]+w>>>0}let[s,u,i,a,c,g,d,m]=e;for(let t=0;t<64;t++){const h=m+(l(c,6)^l(c,11)^l(c,25))+(c&g^~c&d)+z[t]+n[t]>>>0,w=(l(s,2)^l(s,13)^l(s,22))+(s&u^s&i^u&i)>>>0;m=d,d=g,g=c,c=a+h>>>0,a=i,i=u,u=s,s=h+w>>>0}const y=[s,u,i,a,c,g,d,m];for(let t=0;t<8;t++)e[t]=e[t]+y[t]>>>0}function j(e){const n=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),r=v(e),o=new DataView(r.buffer),s=new Uint32Array(64);for(let i=0;i<r.length;i+=64)D(n,s,o,i);const u=new DataView(new ArrayBuffer(32));return n.forEach((i,a)=>{u.setUint32(a*4,i)}),u.buffer}const W=new Set(["user-agent","expect","x-amzn-trace-id","authorization","content-length"]);function A(e){return new TextEncoder().encode(e)}function C(e,n){return e===n?0:e<n?-1:1}async function M(){const e=globalThis.crypto;return e?.subtle!==void 0?e.subtle:k()!=="node"?null:(await import("node:crypto")).webcrypto.subtle}function b(e){return Array.from(new Uint8Array(e),n=>n.toString(16).padStart(2,"0")).join("")}async function H(e){const n=await M();return b(n===null?j(e instanceof Uint8Array?e:new Uint8Array(e)):await n.digest("SHA-256",e))}function O(e){return H(typeof e=="string"?A(e):e)}async function U(e,n){const r=await M();r===null&&E("E_SOURCE_RUNTIME","AWS signing needs Web Crypto, which a browser has only on a secure page",{runtime:k(),reason:"needs-secure-context"});const o=await r.importKey("raw",e,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);return r.sign("HMAC",o,A(n))}function $(e){return encodeURIComponent(e).replaceAll(/[!'()*]/g,n=>`%${(n.codePointAt(0)??0).toString(16).toUpperCase()}`)}function _(e){return[...e.searchParams].map(([n,r])=>[$(n),$(r)]).sort(([n,r],[o,s])=>C(n,o)||C(r,s)).map(([n,r])=>`${n}=${r}`).join("&")}function I(e){return e.toISOString().replaceAll(/[-:]/g,"").replace(/\.\d{3}/,"")}async function P(e,n,r=new Date){const o=typeof n.credentials=="function"?await n.credentials():n.credentials,s=k();(s==="browser"||s==="worker")&&(o.sessionToken??"")===""&&E("E_SOURCE_PARAM","long-term AWS keys are never used in a browser",{name:"credential",reason:"long-term-key"});const u=n.service??"neptune-db",i=new URL(e.url),a=new Headers(e.headers),c=a.get("x-amz-date")??I(r);a.set("x-amz-date",c),o.sessionToken!==void 0&&o.sessionToken!==""&&a.set("x-amz-security-token",o.sessionToken);const g=e.method.toUpperCase(),d=g==="GET"||g==="HEAD"?new Uint8Array(0):await e.clone().arrayBuffer(),m=new Map([["host",i.host]]);a.forEach((f,p)=>{W.has(p)||m.set(p,f.trim().replaceAll(/\s+/g," "))});const y=[...m.keys()].sort((f,p)=>+(f>p)-+(f<p)),t=y.join(";"),h=[g,i.pathname.split("/").map($).join("/"),_(i),...y.map(f=>`${f}:${m.get(f)??""}`),"",t,await H(d)].join(`
|
|
2
|
+
`),w=c.slice(0,8),x=`${w}/${n.region}/${u}/aws4_request`,R=["AWS4-HMAC-SHA256",c,x,await H(A(h))].join(`
|
|
3
|
+
`);let S=await U(A(`AWS4${o.secretAccessKey}`),w);for(const f of[n.region,u,"aws4_request"])S=await U(S,f);const T=b(await U(S,R));return a.set("Authorization",`AWS4-HMAC-SHA256 Credential=${o.accessKeyId}/${x}, SignedHeaders=${t}, Signature=${T}`),new Request(e,{headers:a})}export{O as sha256Hex,P as signRequest};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{_ as be,I as q}from"./preload-helper-Crt_PPe8.js";import{d as Se,t as w,o as x,b as ie,I as Z,S as K,f as p,i as ae,u as Re,w as G,P as ee,e as Ne,C as we,g as _e,h as Ae,j as $e,k as Oe,l as Te,m as Ce}from"./io-D-Vr0j3W.js";import{sha256Hex as Ie}from"./sigv4-BXwVbza3-DZCCNyQA.js";import"./elements-DIunzJUl.js";class L{constructor(e,n,r){this.id=e,this.labels=n,this.properties=r}}class j{constructor(e,n,r,s,o){this.id=e,this.start=n,this.end=r,this.type=s,this.properties=o}}const te=BigInt(Number.MAX_SAFE_INTEGER);function D(t,e,n){let r;try{r=BigInt(t)}catch{return Number(t)}return r<=te&&r>=-te?Number(r):n.long==="string"?r.toString():(n.report.warnOnce("precision",ee,`column ${e}: an integer beyond 2^53 was stored as the nearest 64-bit float; pass long: "string" to keep every digit`,void 0,`${ee}:${e}`),Number(r))}function M(t,e,n,r){const s=Date.parse(Pe(t));return Number.isNaN(s)?(G(r.report,"W_SOURCE_VALUE",`column ${n}: a ${e} kept as text`,{type:e,column:n,as:"string"}),t):s}function le(t,e,n){G(n.report,"W_SOURCE_VALUE",`column ${e}: a ${t} value was dropped`,{type:t,column:e,as:"dropped"})}function _(t,e){const n={};for(const[r,s]of Object.entries(t)){const o=e(s,r);o!==void 0&&(n[r]=o)}return n}function Ue(t){const e=/^SRID=(\d+);POINT(?: Z)? ?\(([^)]*)\)$/i.exec(t.trim());if(e===null)return t;const[n=0,r=0,s]=e[2].trim().split(/\s+/).map(Number);return s===void 0?{srid:Number(e[1]),x:n,y:r}:{srid:Number(e[1]),x:n,y:r,z:s}}function O(t,e,n){if(t===null||typeof t!="object"||!("$type"in t))return t??null;const{$type:r,_value:s}=t;switch(r){case"Null":return null;case"Boolean":case"String":return s;case"Integer":return D(String(s),e,n);case"Float":return Number(s);case"Date":return M(`${String(s)}T00:00:00Z`,r,e,n);case"OffsetDateTime":case"ZonedDateTime":return M(String(s),r,e,n);case"LocalDateTime":case"LocalTime":case"Time":case"Duration":return String(s);case"Point":return Ue(String(s));case"Base64":le(r,e,n);return;case"List":return s.map(o=>O(o,e,n));case"Map":return _(s,o=>O(o,e,n));case"Node":{const o=s;return new L(o._element_id,o._labels,_(o._properties,(i,a)=>O(i,a,n)))}case"Relationship":{const o=s;return new j(o._element_id,o._start_node_element_id,o._end_node_element_id,o._type,_(o._properties,(i,a)=>O(i,a,n)))}case"Path":return s.map(o=>O(o,e,n));default:return G(n.report,"W_SOURCE_VALUE",`column ${e}: a ${r} kept as text`,{type:r,column:e,as:"string"}),typeof s=="string"?s:JSON.stringify(s)}}function Pe(t){const e=t.length-1;if(t[e]!=="]")return t;const n=t.indexOf("[",t.lastIndexOf("]",e-1)+1);return n===-1||n>=e?t:t.slice(0,n)}function De(t,e,n,r){const s=_(t.properties,(i,a)=>T(i,a,n,r)),o=t.elementId??String(t.identity);return e?new L(o,[...t.labels??[]],s):new j(o,t.startNodeElementId??String(t.start),t.endNodeElementId??String(t.end),t.type??"",s)}function Me(t){const e=Number(String(t.srid));return t.z===void 0?{srid:e,x:t.x,y:t.y}:{srid:e,x:t.x,y:t.y,z:t.z}}function T(t,e,n,r){if(t==null)return null;if(typeof t!="object")return typeof t=="bigint"?D(t.toString(),e,n):t;const s=()=>t.toString();if(r.isInt(t))return D(s(),e,n);if(r.isNode(t)||r.isRelationship(t))return De(t,r.isNode(t),n,r);if(r.isPath(t)){const o=t;return[o.start,...o.segments.flatMap(i=>[i.relationship,i.end])].map(i=>T(i,e,n,r))}if(r.isDate(t))return M(`${s()}T00:00:00Z`,"Date",e,n);if(r.isDateTime(t))return M(s(),"DateTime",e,n);if(r.isLocalDateTime(t)||r.isLocalTime(t)||r.isTime(t)||r.isDuration(t))return s();if(r.isPoint(t))return Me(t);if(t instanceof Uint8Array||t instanceof ArrayBuffer){le("ByteArray",e,n);return}return Array.isArray(t)?t.map(o=>T(o,e,n,r)):_(t,o=>T(o,e,n,r))}function U(t,e,n){if(typeof t=="number"&&Number.isInteger(t)&&!Number.isSafeInteger(t))return D(BigInt(t).toString(),e,n);if(t===null||typeof t!="object")return t??null;if(Array.isArray(t))return t.map(o=>U(o,e,n));const r=t,s=()=>_(r["~properties"]??{},(o,i)=>U(o,i,n));switch(r["~entityType"]){case"node":return new L(String(r["~id"]),r["~labels"]??[],s());case"relationship":return new j(String(r["~id"]),String(r["~start"]),String(r["~end"]),String(r["~type"]),s());default:return _(r,o=>U(o,e,n))}}const ke="labels",ve="type",xe={name:ke,dtype:"list",itemDtype:"dict",nullable:!0,role:"labels"},Le={name:ve,dtype:"dict",nullable:!0,role:"kind"},je={name:"id",dtype:"string",nullable:!0,role:"id"};class ne{constructor(){this.nodes=new Map,this.rels=new Map,this.degrees=new Map}add(e,n){const r=n?e.fields.indexOf("key"):-1,s=n?e.fields.indexOf("degree"):-1,o=n?e.fields.indexOf("degrees"):-1;for(const i of e.rows)i.forEach((a,l)=>{if(l===o&&Array.isArray(a))for(const u of a)Array.isArray(u)&&typeof u[1]=="number"&&this.degrees.set(String(u[0]),u[1]);else l!==r&&l!==s&&this.visit(a)}),r>=0&&s>=0&&typeof i[s]=="number"&&this.degrees.set(String(i[r]),i[s])}visit(e){e instanceof L?this.nodes.set(e.id,e):e instanceof j?this.rels.set(e.id,e):Array.isArray(e)?e.forEach(n=>{this.visit(n)}):e!==null&&typeof e=="object"&&Object.values(e).forEach(n=>{this.visit(n)})}get empty(){return this.nodes.size===0&&this.rels.size===0}}function He(t,e,n){t.rows.length>0&&e.empty&&p(n,"E_SOURCE_NOT_A_GRAPH","the query returned no node, relationship or path",{columns:t.fields})}function ce(t,e){const n=e===null?void 0:t.properties[e];return typeof n=="string"||typeof n=="number"?n:t.id}function F(t,e,n){const r=n==="node"?t.nodeColumn(e.name):t.edgeColumn(e.name);return r!==q?r:n==="node"?t.declareNodeColumn(e):t.declareEdgeColumn(e)}function ue(t,e,n,r,s){e.edgeCount===0&&!e.directedLocked&&!e.directed&&e.setDirected(!0);const o=We(t,e,n,r,s);Fe(t,e,o,r,s,t.nodes.size)}function We(t,e,n,r,s){const o=new Map;let i=0;for(const a of t.nodes.values()){i++%64===0&&w(s);const l=ce(a,n);o.set(a.id,l);const u=t.degrees.get(String(n===null?a.id:l));try{const c=e.indexOf(l)===q,d=e.addNodeRecord(l,u===void 0?a.properties:{...a.properties,[Ce]:u});e.setNodeValue(F(e,xe,"node"),d,a.labels),c&&r.counts.nodes++}catch(c){r.recordError(c,{element:String(l)}),r.counts.skippedNodes++}}return o}function Fe(t,e,n,r,s,o){let i=o;for(const a of t.rels.values()){i++%64===0&&w(s);const l=n.get(a.start)??a.start,u=n.get(a.end)??a.end;try{for(const d of[l,u])e.indexOf(d)===q&&(e.addNode(d),r.counts.nodes++);const c=e.addEdgeRecord(l,u,a.properties,null);e.setEdgeValue(F(e,Le,"edge"),c,a.type),e.setEdgeValue(F(e,je,"edge"),c,a.id),r.counts.edges++}catch(c){r.recordError(c,{element:`${String(l)} -> ${String(u)}`}),r.counts.skippedEdges++}}}function z(t,e){return t===e?0:t<e?-1:1}function Be(t,e){return`${JSON.stringify(t)}:${k(e)}`}function k(t){return Array.isArray(t)?`[${t.map(k).join(",")}]`:t!==null&&typeof t=="object"?`{${Object.entries(t).sort(([r],[s])=>z(r,s)).map(([r,s])=>Be(r,s)).join(",")}}`:JSON.stringify(t)??"null"}function re(t,e){const n=new Map,r=[];for(const s of t.nodes.values()){const o=ce(s,e);n.set(s.id,o),r.push(k(["n",o,[...s.labels].sort(z),s.properties]))}for(const s of t.rels.values())r.push(k(["r",s.id,n.get(s.start)??s.start,n.get(s.end)??s.end,s.type,s.properties]));return r}function v(t,e="Neo4j"){const n=t===null?Number.NaN:Number.parseInt(t,10);return{name:"neo4j",elementIds:Number.isNaN(n)||n>=5,product:e,version:t,readOnly:"enforced"}}function qe(t){const[e="",n=""]=t.split("/");return e.toLowerCase()==="neo4j"?v(n===""?null:n):{name:"neo4j",elementIds:!1,product:e,version:n===""?null:n,readOnly:"enforced"}}function C(t=null){return{name:"neptune",elementIds:!1,product:"Neptune",version:t,readOnly:"not-enforced"}}function de(t){return{product:t.product,profile:t.name,readOnly:t.readOnly,...t.version===null?{}:{version:t.version}}}const pe=10,Ge=1e5,ze=1e3;function fe(t){return typeof t!="string"||t===""||t.includes("\0")?"identifier":null}function Je(t){return fe(t)!==null&&Ne("E_SOURCE_PARAM","a Cypher identifier must be a non-empty string without NUL",{name:"identifier",reason:"identifier"}),`\`${t.replaceAll("`","``")}\``}function P(t,e,n){return fe(t)!==null&&p(n,"E_SOURCE_PARAM",`parameter ${e}: not a Cypher identifier`,{name:e,reason:"identifier"}),Je(t)}function N(t,e,n,r,s){return(typeof t!="number"||!Number.isInteger(t))&&p(s,"E_SOURCE_PARAM",`parameter ${e}: not an integer`,{name:e,reason:"type"}),(t<n||t>r)&&p(s,"E_SOURCE_PARAM",`parameter ${e}: outside ${String(n)} to ${String(r)}`,{name:e,reason:"range"}),String(t)}function A(t,e,n,r=!0){return r&&n.idProperty!==null?`${t}.${n.idProperty}`:e.elementIds?`elementId(${t})`:`id(${t})`}function S(t,e){const n=[];if(e.labels.length>0){const r=`${t}:`;n.push(`(${e.labels.map(s=>r+s).join(" OR ")})`)}return e.idProperty!==null&&n.push(`${t}.${e.idProperty} IS NOT NULL`),n.length===0?null:n.join(" AND ")}function H(t){return t.relationshipTypes.length===0?"":`:${t.relationshipTypes.join("|")}`}function he(t){return`size([(${t})--() | 1])`}const Ve={out:["-","->"],in:["<-","-"],both:["-","-"]};function se(t,e,n,r,s){const o=S("n",e);return["MATCH (n)",o===null?null:`WHERE ${o}`,`WITH n, ${A("n",t,e)} AS key`,r?"WHERE key > $after":null,s?`RETURN n, key, ${he("n")} AS degree`:"RETURN n, key",`ORDER BY key LIMIT ${n}`].filter(i=>i!==null).join(" ")}function Ye(t,e,n,r){const s=S("a",e),o=S("b",e),i=[s,o].filter(a=>a!==null);return[`MATCH (a)-[r${H(e)}]->(b)`,i.length===0?null:`WHERE ${i.join(" AND ")}`,`WITH a, r, b, ${A("r",t,e,!1)} AS key`,r?"WHERE key > $after":null,"RETURN a, r, b, key",`ORDER BY key LIMIT ${n}`].filter(a=>a!==null).join(" ")}function Xe(t,e){const n=A("a",t,e),r=A("b",t,e),s=[S("a",e),S("b",e)].filter(a=>a!==null),o=s.length===0?"":` AND ${s.join(" AND ")}`,i=`MATCH (a)-[r${H(e)}]->(b)`;return[`${i} WHERE ${n} IN $keys AND ${r} <= $last${o} RETURN a, r, b`,"UNION ALL",`${i} WHERE ${r} IN $keys AND ${n} <= $last AND NOT ${n} IN $keys${o} RETURN a, r, b`].join(" ")}function ye(t,e,n,r){const s=`[${H(e)}*1..${n.depth}]`,[o,i]=Ve[n.direction],a=`${o}${s}${i}`,l=S("x",e),u=r?`, [m IN CASE WHEN p IS NULL THEN [s] ELSE nodes(p) END | [${A("m",t,e)}, ${he("m")}]] AS degrees`:"",c=[`MATCH (s) WHERE ${A("s",t,e)} IN $ids`,`OPTIONAL MATCH p = (s)${a}(x)${B(l)}`];return n.limit===null?[...c,"WITH s, p",`RETURN s, p${u}`].join(" "):[...c,`WITH s, p, ${A("x",t,e)} AS key`,n.after===!0?"WHERE key > $after":null,`WITH s, p, key ORDER BY key LIMIT ${n.limit}`,`RETURN s, p, key${u}`].filter(d=>d!==null).join(" ")}function B(t){return t===null?"":` WHERE ${t}`}function Qe(t){const e=S("n",t),n=[S("a",t),S("b",t)].filter(r=>r!==null);return[`MATCH (n)${B(e)} RETURN count(n) AS c`,`MATCH (a)-[r${H(t)}]->(b)${B(n.length===0?null:n.join(" AND "))} RETURN count(r) AS c`]}function Ze(t){return`MATCH (${t===void 0?"n":`n:${t}`}) RETURN count(n) AS c`}const Ke=500;function J(t,e,n,r){const s=e.code??"";if(/Security\.Unauthorized|AuthenticationRateLimit|UnauthorizedException/i.test(s))return p(t,"E_SOURCE_AUTH",`${n} refused the login`,{origin:n,status:e.status,scheme:null,serverCode:e.code});if(/Security\.Forbidden|AccessMode|AccessDenied/i.test(s))return p(t,"E_SOURCE_FORBIDDEN",`${n} refused the statement`,{status:e.status,serverCode:e.code});if(/TimedOut|Timeout|TimeLimitExceeded/i.test(s))return p(t,"E_SOURCE_TIMEOUT",`${n} timed the statement out`,{timeoutMs:null,serverSide:!0});if(/DatabaseNotFound/i.test(s))return p(t,"E_SOURCE_NOT_FOUND",`${n} has no database ${String(r)}`,{what:"database",value:r??null});const o=/line (\d+), column (\d+)/i.exec(e.message);return p(t,"E_SOURCE_QUERY",`${n} refused the query: ${s}`,{serverCode:e.code,line:o===null?null:Number(o[1]),column:o===null?null:Number(o[2]),serverMessage:e.showable&&e.message!==""?e.message.slice(0,Ke):null})}function V(t){try{return JSON.parse(t)}catch{return null}}function et(t,e){const n=[...new Set(t.flatMap(r=>Object.keys(r)))];return{fields:n,rows:t.map(r=>n.map(s=>e(r[s],s)))}}const oe="neo4j-driver",tt=new Set(["bolt:","bolt+s:","bolt+ssc:"]);async function nt(t){let e;try{e=await be(()=>import("./index-C4RZkds_.js").then(n=>n.i),[],import.meta.url)}catch{return p(t.ctx.report,"E_SOURCE_RUNTIME",`the bolt transport needs ${oe} installed`,{runtime:t.ctx.runtime,reason:"needs-peer-dependency",package:oe})}return e.default??e}function rt(t,e){const n=globalThis.location;t.runtime==="browser"&&n?.protocol==="https:"&&e.protocol==="bolt:"&&!ae(e.hostname)&&p(t.report,"E_SOURCE_RUNTIME","an https page cannot open a plain Bolt WebSocket",{runtime:t.runtime,reason:"insecure-endpoint"})}async function st(t,e){const{ctx:n}=t,{report:r}=n,s=(d,f)=>p(r,"E_SOURCE_PARAM",f,{name:"endpoint",reason:d}),o=n.endpoint??s("missing","the bolt transport needs an endpoint");tt.has(o.protocol)||s(o.protocol.startsWith("neo4j")?"routing":"scheme",`${o.protocol} is not a direct Bolt scheme`),rt(n,o);const{credential:i,allowInsecure:a}=ie(n),l=x(o);if(!(i!==void 0&&(i.origins.length===0||i.origins.includes(l)))||i===void 0)return{url:o,auth:void 0};o.protocol==="bolt+ssc:"&&s("unverified-tls","bolt+ssc accepts any certificate, so no credential is sent over it"),o.protocol==="bolt:"&&!ae(o.hostname)&&a!==!0&&s("insecure-endpoint","a credential is never sent without TLS");const c=Re(i);if(c!==void 0&&"username"in c)return{url:o,auth:e.auth.basic(c.username,c.password)};if(c!==void 0&&"token"in c){const d=typeof c.token=="string"?c.token:await c.token();return{url:o,auth:e.auth.bearer(d)}}return p(r,"E_SOURCE_PARAM","the bolt transport takes a basic or bearer credential",{name:"credential",reason:"kind"})}async function ot(t){const{ctx:e,params:n,m:r}=t;w(e.signal);const s=await nt(t),{url:o,auth:i}=await st(t,s);w(e.signal);const a=x(o),{userAgent:l}=ie(e),u=s.driver(`${o.protocol}//${o.host}`,i,l===void 0?{}:{userAgent:l}),c=u.session({defaultAccessMode:s.session.READ,...n.database===void 0?{}:{database:n.database}});let d=null;const f=()=>(d??=c.close().catch(()=>{}).then(()=>u.close()).catch(()=>{}),d),h=()=>{f()};e.signal.addEventListener("abort",h,{once:!0});const E=m=>{w(e.signal);const $=m,R=typeof $.code=="string"?$.code:null;return R===null||R==="ServiceUnavailable"||R==="SessionExpired"?e.runtime==="browser"?p(e.report,"E_SOURCE_BLOCKED",`${a} could not be reached over Bolt`,{url:a,cause:"unknown"}):p(e.report,"E_FETCH",`${a} could not be reached over Bolt`,{url:a,status:null}):J(e.report,{code:R,message:typeof $.message=="string"?$.message:"",status:null,showable:R.startsWith("Neo.ClientError.")},a,n.database)};let y=null;const g=async()=>{if(y===null){const m=await u.getServerInfo().catch(E);y=qe(m.agent??"")}return y},b=e.limits.timeoutMs;return{async run(m,$){w(e.signal);const R=await c.run(m,$,b===void 0?void 0:{timeout:b}).catch(E),X=(R.records[0]?.keys??[]).map(String);return{fields:X,rows:R.records.map(ge=>X.map(Q=>T(ge.get(Q),Q,r,s)))}},profile:g,probe:g,close:async()=>{e.signal.removeEventListener("abort",h),await f()}}}function me(t,e){(t.runtime==="browser"||t.runtime==="worker")&&p(t.report,"E_SOURCE_RUNTIME",`the ${e} transport cannot run in a browser`,{runtime:t.runtime,reason:"cors"})}function it(t){for(let e=t.lastIndexOf("{");e>0;e=t.lastIndexOf("{",e-1)){const n=V(t.slice(e));if(n!==null&&typeof n.code=="string")return n}return null}async function Ee(t,e){const{ctx:n,m:r}=t,s=n.endpoint===null?"":x(n.endpoint),o=await e.text(),i=V(o);let a=typeof i?.code=="string"?i:null;return i===null&&(a=it(o)),a!==null&&J(n.report,{code:a.code??null,message:a.detailedMessage??a.message??"",status:e.status,showable:i!==null&&e.status>=400&&e.status<500},s,void 0),e.ok||p(n.report,"E_FETCH",`${s} answered ${String(e.status)}`,{url:s,status:e.status}),(i===null||!Array.isArray(i.results))&&p(n.report,"E_SOURCE_RESPONSE","the Neptune answer has no results",{expected:"json",contentType:e.headers.get("content-type")}),et(i.results,(l,u)=>U(l,u,r))}function at(t){const{ctx:e}=t;return me(e,"neptune-https"),{async run(n,r){const s=await e.fetch("openCypher",{method:"POST",idempotent:!0,allowStatus:[400,500],body:new URLSearchParams({query:n,parameters:JSON.stringify(r)})});return Ee(t,s)},profile:()=>Promise.resolve(C()),probe:async()=>{const n=await e.fetchJson("status");return C(typeof n.dbEngineVersion=="string"?n.dbEngineVersion:null)},close:()=>Promise.resolve()}}function lt(t){const{ctx:e}=t;me(e,"neptune-analytics");const n=async(r,s)=>{const o=await e.fetch("queries",{method:"POST",idempotent:!0,allowStatus:[400,500],headers:{"Content-Type":"application/json"},body:JSON.stringify({query:r,language:"OPEN_CYPHER",parameters:s})});return Ee(t,o)};return{run:n,profile:()=>Promise.resolve(C()),probe:async()=>(await n("RETURN 1 AS ok",{}),C()),close:()=>Promise.resolve()}}const ct="application/vnd.neo4j.query.v1.1",ut=[400,404,500];function dt(t){const{ctx:e,params:n,m:r}=t,s=n.database??"neo4j",o=`db/${encodeURIComponent(s)}/query/v2`,i=e.endpoint===null?"":x(e.endpoint),a=async(l,u)=>{const c=await e.fetch(o,{method:"POST",idempotent:!0,allowStatus:ut,headers:{"Content-Type":"application/json",Accept:ct},body:JSON.stringify({statement:l,parameters:u,accessMode:"Read"})}),d=V(await c.text()),f=d?.errors?.[0];f!==void 0&&J(e.report,{code:f.code??null,message:f.message??"",status:c.status,showable:c.status>=400&&c.status<500},i,n.database),c.status===404&&p(e.report,"E_SOURCE_NOT_FOUND",`${i} has no Query API at ${o}`,{what:"url",value:`${i}/${o}`}),c.ok||p(e.report,"E_FETCH",`${i} answered ${String(c.status)}`,{url:`${i}/${o}`,status:c.status}),d?.data===void 0&&p(e.report,"E_SOURCE_RESPONSE","the Query API answer has no data",{expected:"json",contentType:c.headers.get("content-type")});const{fields:h,values:E}=d.data;return{fields:h,rows:E.map(y=>y.map((g,b)=>O(g,h[b]??"",r)))}};return{run:a,profile:()=>Promise.resolve(v(null)),probe:async()=>{const l=await a("CALL dbms.components() YIELD name, versions, edition RETURN name, versions, edition",{}),c=(l.rows.find(f=>f[0]==="Neo4j Kernel")??l.rows[0])?.[1],d=Array.isArray(c)&&typeof c[0]=="string"?c[0]:null;return v(d)},close:()=>Promise.resolve()}}const pt=new Set(["out","in","both"]);function ft(t){let e=t.length;for(;e>0&&t[e-1]===";";)e--;return t.slice(0,e)}function W(t,e,n){return t==null?[]:Array.isArray(t)?t:typeof t=="string"||typeof t=="number"?[t]:p(n,"E_SOURCE_PARAM",`parameter ${e}: not a list`,{name:e,reason:"type"})}function ht(t,e,n){if(t.transport!==void 0)return t.transport;const r=e.endpoint?.protocol??"";return r.startsWith("bolt")||r.startsWith("neo4j")?"bolt":e.endpoint?.hostname.endsWith(".neptune-graph.amazonaws.com")===!0?"neptune-analytics":n.transport}class yt{constructor(e,n,r){this.transport=e,this.params=n,this.ctx=r,this.known=null,this.degree=!0;const{report:s}=r;this.idProperty=n.idProperty??null,this.filters={labels:W(n.labels,"labels",s).map(o=>P(o,"labels",s)),relationshipTypes:W(n.relationshipTypes,"relationshipTypes",s).map(o=>P(o,"relationshipTypes",s)),idProperty:this.idProperty===null?null:P(this.idProperty,"idProperty",s)}}async profile(){if(this.known===null){const e=await this.transport.profile();this.known=e,this.params.profile==="neptune"?this.known=C(e.version):this.params.profile==="neo4j"&&e.name!=="neo4j"&&(this.known=v(e.version))}return this.known}async generated(e,n){let r;try{r=await this.transport.run(e(this.degree),n)}catch(o){if(!this.degree||!(o instanceof Z)||o.issue?.code!==K.E_SOURCE_QUERY)throw o;this.degree=!1,r=await this.transport.run(e(!1),n)}const s=new ne;return s.add(r,!0),{collected:s,rows:r.rows,fields:r.fields}}async*pages(e,n=!0){const{params:r,ctx:s}=this,{report:o}=s,i=r.mode??(typeof r.query=="string"&&r.query!==""?"query":"all");if(i==="query"){(typeof r.query!="string"||r.query.trim()==="")&&p(o,"E_SOURCE_PARAM","mode query needs a query",{name:"query",reason:"required"}),yield await this.userQuery(r.query,e);return}const a=await this.profile();if(i==="neighborhood"){const l=W(r.ids,"ids",o);l.length===0&&p(o,"E_SOURCE_PARAM","mode neighborhood needs ids",{name:"ids",reason:"required"});const u={depth:N(r.depth??1,"depth",1,pe,o),direction:"both",limit:s.limits.maxNodes===void 0?null:N(s.limits.maxNodes,"maxNodes",1,Number.MAX_SAFE_INTEGER,o)},{collected:c}=await this.generated(d=>ye(a,this.filters,u,d),{ids:l});yield{collected:c,next:null};return}yield*this.everything(a,e,n)}async userQuery(e,n){const{params:r,ctx:s}=this,o=r.parameters??{},i=n?.rows??s.limits.maxNodes,a=i==null?null:Number(N(i,"maxNodes",1,Number.MAX_SAFE_INTEGER,s.report));let l;try{l=await this.transport.run(a===null?e:`CALL {
|
|
2
|
+
${ft(e.trim())}
|
|
3
|
+
}
|
|
4
|
+
RETURN * LIMIT ${String(a)}`,o)}catch(d){if(a===null||!(d instanceof Z)||d.issue?.code!==K.E_SOURCE_QUERY)throw d;return p(s.report,"E_SOURCE_PARAM","the server cannot cap this query; load it without maxNodes",{name:"maxNodes",reason:"uncappable"})}const u=new ne;u.add(l,!1),He(l,u,s.report);const c=a!==null&&l.rows.length>=a;return{collected:u,next:c?{rows:a*2}:null}}async*everything(e,n,r){const{params:s,ctx:o}=this,i=N(s.pageSize??ze,"pageSize",1,Ge,o.report);n===null&&r&&(this.counted=await this.count(e));const a=o.limits.maxNodes;if(a!==void 0&&n?.phase!=="edges"){const f=Number(N(a,"maxNodes",1,Number.MAX_SAFE_INTEGER,o.report));yield*this.cappedNodes(e,n,Math.min(Number(i),f));return}let l=n?.phase==="edges"?"edges":"nodes",u=n?.after??null;const{counted:c}=this,d=s.countFirst===!0&&c!==void 0?(c.nodes??0)+(c.edges??0):void 0;for(;;){const f=l==="nodes",{collected:h,rows:E,fields:y}=await this.generated(m=>f?se(e,this.filters,i,u!==null,m):Ye(e,this.filters,i,u!==null),u===null?{}:{after:u}),g=mt(l,E,y,Number(i));yield{collected:h,next:g};const{counts:b}=o.report;if(o.progress(b.nodes+b.edges,d,"items"),g===null)return;l=g.phase==="edges"?"edges":"nodes",u=g.after??null}}async*cappedNodes(e,n,r){let s=n?.after??null;for(;;){const{collected:o,rows:i,fields:a}=await this.generated(f=>se(e,this.filters,String(r),s!==null,f),s===null?{}:{after:s}),l=a.indexOf("key"),u=i.at(-1)?.[l],c=typeof u=="string"||typeof u=="number"?u:null;if(c!==null){const f=i.map(E=>E[l]),h=await this.transport.run(Xe(e,this.filters),{keys:f,last:c});o.add(h,!1)}const d=i.length>=r&&c!==null?{phase:"nodes",after:c}:null;if(yield{collected:o,next:d},d===null)return;s=c}}async count(e){const n=async i=>{const a=Number((await this.transport.run(i,{})).rows[0]?.[0]);return Number.isSafeInteger(a)&&a>=0?a:void 0},{labels:r,idProperty:s}=this.filters;if(this.params.countFirst===!0){const[i,a]=Qe(this.filters),[l,u]=await Promise.all([n(i),n(a)]);return{...l===void 0?{}:{nodes:l},...u===void 0?{}:{edges:u}}}if(e.name!=="neo4j"||r.length>1||s!==null)return;const o=await n(Ze(r[0]));return o===void 0?void 0:{nodes:o}}async facts(e){const n=await this.profile(),r=await Ie([...e].sort(z).join(`
|
|
5
|
+
`));return{server:de(n),validators:n.version===null?{contentHash:r}:{contentHash:r,serverVersion:n.version}}}}function mt(t,e,n,r){const s=e.at(-1)?.[n.indexOf("key")],o=typeof s=="string"||typeof s=="number"?s:null;return e.length>=r&&o!==null?{phase:t,after:o}:t==="nodes"?{phase:"edges",after:null}:null}async function Et(t,e,n){w(e.signal);const r={ctx:e,params:t,m:{long:t.long??"f64",report:e.report}},s=ht(t,e,n);let o;switch(s){case"bolt":o=await ot(r);break;case"neptune-https":o=at(r);break;case"neptune-analytics":o=lt(r);break;default:o=dt(r);break}try{return new yt(o,t,e)}catch(i){throw await o.close(),i}}async function I(t,e,n,r){const s=await Et(t,e,n);try{return await r(s)}finally{await s.transport.close()}}function Y(t){return Se({id:t.id,descriptor:t.descriptor,import:(e,n,r)=>I(e,r,t,async s=>{const o=[];let i=null;for await(const l of s.pages(r.cursor))if(ue(l.collected,n,s.idProperty,r.report,r.signal),o.push(...re(l.collected,s.idProperty)),{next:i}=l,i!==null&&r.limits.reached())break;const a=s.counted===void 0?{}:{total:s.counted};return r.finish({next:i,...a,...await s.facts(o)})}),expand:(e,n,r)=>I(e.params,r,t,s=>gt(s,e,n)),probe:(e,n)=>I(e,n,t,async r=>{const s=await r.transport.probe();return{ok:!0,server:de(s)}}),validate:(e,n,r)=>I(e,r,t,async s=>{const o=[];for await(const l of s.pages(null,!1))o.push(...re(l.collected,s.idProperty));const{validators:i}=await s.facts(o);let a="unverifiable";return n.contentHash!==void 0&&(a=n.contentHash===i.contentHash?"current":"changed"),{status:a,via:"hash",validators:i}})})}async function gt(t,e,n){const{ctx:r}=t,{report:s}=r;e.ids.length===0&&p(s,"E_SOURCE_PARAM","an expansion needs seed ids",{name:"ids",reason:"required"});const o=e.direction??"both";pt.has(o)||p(s,"E_SOURCE_PARAM","direction must be out, in or both",{name:"direction",reason:"enum"});const i=e.limit??r.limits.maxNodes,a=r.cursor?.after??null,l={depth:N(e.depth??1,"depth",1,pe,s),direction:o,limit:i===void 0?null:N(i,"limit",1,Number.MAX_SAFE_INTEGER,s),after:a!==null},u=e.relationshipTypes===void 0?t.filters:{...t.filters,relationshipTypes:e.relationshipTypes.map(m=>P(m,"relationshipTypes",s))},c=await t.profile(),{collected:d,rows:f,fields:h}=await t.generated(m=>ye(c,u,l,m),{ids:e.ids,...a===null?{}:{after:a}});ue(d,n,t.idProperty,s,r.signal);const{server:E}=await t.facts([]),y=f.at(-1)?.[h.indexOf("key")],b=l.limit!==null&&f.length>=Number(l.limit)&&(typeof y=="string"||typeof y=="number")?{after:y}:null;return r.finish({server:E,next:b})}const wt=Y({id:_e,descriptor:we,transport:"query-api"}),_t=Y({id:$e,descriptor:Ae,transport:"query-api"}),At=Y({id:Te,descriptor:Oe,transport:"neptune-https"});export{we as CYPHER_DESCRIPTOR,Ae as NEO4J_DESCRIPTOR,Oe as NEPTUNE_DESCRIPTOR,Je as cypherIdentifier,wt as cypherSource,_t as neo4jSource,At as neptuneSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as g,N as v,a as w,f as s,c as _}from"./io-D-Vr0j3W.js";import"./preload-helper-Crt_PPe8.js";import"./elements-DIunzJUl.js";const O=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,C="accesskey",b=[401,403,404];function y(e){e.endpoint?.searchParams.has(C)===!0&&s(e.report,"E_SOURCE_PARAM","an access key goes in a credential, never in the endpoint",{name:"endpoint",reason:"credentials-in-url"})}function p(e,t){y(t);const n=String(e);return/accesskey/i.test(n)&&s(t.report,"E_SOURCE_PARAM","an access key goes in a credential, never in the uuid",{name:"uuid",reason:"credentials-in-url"}),O.test(n)||s(t.report,"E_SOURCE_PARAM","the uuid is not a network UUID",{name:"uuid",reason:"format"}),n.toLowerCase()}async function l(e,t,n,o={}){const i=await e.fetch(t,{...o,allowStatus:b});if(i.ok)return i;const r=new URL(t,e.endpoint??void 0),a=await R(i),{status:d}=i;return d===401&&s(e.report,"E_SOURCE_AUTH",`NDEx answered ${String(d)}`,{origin:r.origin,status:d,scheme:i.headers.get("www-authenticate")?.split(/\s/)[0]??null,serverCode:a}),d===403&&s(e.report,"E_SOURCE_FORBIDDEN","NDEx answered 403",{status:d,serverCode:a}),s(e.report,"E_SOURCE_NOT_FOUND","NDEx has no such network",{what:n===null?"url":"network",value:n??`${r.origin}${r.pathname}`})}async function R(e){try{const t=await e.json();return typeof t.errorCode=="string"?t.errorCode.slice(0,100):null}catch{return null}}const A=10;function N(e){return`"${e.replaceAll(/["\\]/g,String.raw`\$&`)}"`}function U(e,t){const{ids:n}=e,{idAttribute:o}=e.params,i=e.depth??1;(!Number.isInteger(i)||i<1||i>A)&&s(t.report,"E_SOURCE_PARAM","depth is an integer from 1 to 10",{name:"depth",reason:"range"}),n.length===0&&s(t.report,"E_SOURCE_PARAM","an expansion needs at least one id",{name:"ids",reason:"required"});const r=e.limit===void 0?{}:{edgeLimit:e.limit,errorWhenLimitIsOver:!1};if(o!==void 0)return/^[A-Za-z_][\w.]*$/.test(o)||s(t.report,"E_SOURCE_PARAM","idAttribute is not an attribute name",{name:"idAttribute",reason:"identifier"}),{searchString:n.map(u=>`${o}:${N(String(u))}`).join(" "),searchDepth:i,...r};const a=n.map(Number);return a.some(d=>!Number.isSafeInteger(d))&&s(t.report,"E_SOURCE_PARAM","NDEx node ids are integers; set idAttribute to seed by name",{name:"ids",reason:"type"}),{searchString:"",searchDepth:i,nodeIds:a,...r}}async function D(e,t,n){const o=p(e.params.uuid,n);e.direction!==void 0&&e.direction!=="both"&&s(n.report,"E_SOURCE_UNSUPPORTED","NDEx expands in both directions only",{feature:"direction",needs:"both"}),(e.relationshipTypes??[]).length>0&&s(n.report,"E_SOURCE_UNSUPPORTED","NDEx cannot filter an expansion by relationship type",{feature:"relationshipTypes"});const i=await l(n,`v2/search/network/${o}/query`,o,{method:"POST",idempotent:!0,headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(U(e,n))});return n.report.include(await _.import(i.body??"",t,{signal:n.signal})),n.finish()}async function f(e,t){const n=await l(t,`v3/networks/${e}/summary`,e,{headers:{Accept:"application/json"}}),o=await n.text();try{return{summary:JSON.parse(o),bytes:new TextEncoder().encode(o).byteLength}}catch{return s(t.report,"E_SOURCE_RESPONSE","the NDEx summary is not JSON",{expected:"json",contentType:n.headers.get("content-type")})}}function h(e){return typeof e=="number"&&Number.isFinite(e)?new Date(e).toISOString():void 0}function m(e,t){return t==="cx"?e.cxFileSize:e.cx2FileSize}function k(e,t,n){const o=[["maxNodes",e.nodeCount,n.limits.maxNodes],["maxEdges",e.edgeCount,n.limits.maxEdges],["maxBytes",m(e,t),n.limits.maxBytes]];for(const[i,r,a]of o)r!==void 0&&a!==void 0&&r>a&&s(n.report,"E_SOURCE_LIMIT",`the network's ${i} of ${String(r)} is over the cap`,{limit:i,value:r})}function T(e){const t={},n=h(e.modificationTime);n!==void 0&&(t.modified=n),typeof e.visibility=="string"&&(t.visibility=e.visibility);for(const o of["rights","rightsHolder"]){const i=e.properties?.[o]?.v;typeof i=="string"&&(t[o]=i)}return t}function E(e){const t=h(e.modificationTime);return t===void 0?{}:{modified:t}}const x=g({id:w,descriptor:v,async file(e,t){const n=p(e.uuid,t),o=e.format??"cx2",{summary:i,bytes:r}=await f(n,t);k(i,o,t);const a=m(i,o);t.progress(r,a===void 0?void 0:r+a,"bytes"),t.finish({validators:E(i)});const d=o==="cx"?`v2/network/${n}`:`v3/networks/${n}`;return{body:await l(t,d,n),format:o,meta:T(i)}},async probe(e,t){const n=p(e.uuid,t),{summary:o}=await f(n,t);return{ok:!0,counts:{nodes:o.nodeCount,edges:o.edgeCount,bytes:m(o,e.format??"cx2")}}},async list(e,t){y(t);const n=Number(e.cursor?.start??0),o=e.size??25,i=await t.fetchJson(`v2/search/network?start=${String(n)}&size=${String(o)}`,{method:"POST",idempotent:!0,headers:{"Content-Type":"application/json"},body:JSON.stringify({searchString:e.search??""})}),r=Array.isArray(i.networks)?i.networks:s(t.report,"E_SOURCE_RESPONSE","the NDEx search answer has no networks",{expected:"ndex-search",contentType:"application/json"}),{numFound:a}=i,d=r.flatMap(c=>typeof c.externalId=="string"?[{params:{uuid:c.externalId},name:c.name??c.externalId,nodeCount:c.nodeCount,edgeCount:c.edgeCount,modified:h(c.modificationTime)}]:[]),u=typeof a=="number"?a:void 0,S=u===void 0?r.length===o:n+r.length<u;return{items:d,next:S&&r.length>0?{start:n+r.length}:null,total:u}},async validate(e,t,n){const o=p(e.uuid,n),i=E((await f(o,n)).summary);return t.modified===void 0||i.modified===void 0?{status:"unverifiable",validators:i}:t.modified===i.modified?{status:"current",via:"modified",validators:i}:{status:"changed",via:"modified",changedAt:i.modified,validators:i}},expand:D});export{v as NDEX_DESCRIPTOR,x as ndexSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as C,R as W,n as F,O as V,p as G,f as l,o as X,s as J,I as Y,w as U,q as Z,r as N,t as M}from"./io-D-Vr0j3W.js";import{D as Vt,v as Gt}from"./io-D-Vr0j3W.js";import"./preload-helper-Crt_PPe8.js";import"./elements-DIunzJUl.js";const K=/^([^.[\]]+)(\[\])?$/,T=new Map;function L(n){const t=T.get(n);if(t!==void 0)return t;let e=[];if(n!==".")for(const i of n.split(".")){const s=K.exec(i);if(s===null){e=null;break}e.push({key:s[1],flatten:s[2]!==void 0})}return T.set(n,e),e}function g(n,t){let e=n===void 0?[]:[n];for(const i of L(t)??[]){const s=[];for(const o of e){if(typeof o!="object"||o===null||!Object.hasOwn(o,i.key))continue;const a=o[i.key];i.flatten&&Array.isArray(a)?s.push(...a):a!=null&&s.push(a)}e=s}return e.filter(i=>i!=null)}function y(n,t){return g(n,t)[0]}function Q(n,t){const e=g(n,t);return e.length===1&&Array.isArray(e[0])?e[0]:e}const E=/\{([^{}]*)\}/g,tt=/^[A-Za-z_][A-Za-z0-9_-]*$/;function et(n){const t=[];for(const e of n.matchAll(E)){if(!tt.test(e[1]))return null;t.push(e[1])}return/[{}]/.test(n.replaceAll(E,""))?null:t}function R(n,t,e,i){return n.replaceAll(E,(s,o)=>{const a=t[o];return a===void 0&&l(i,"E_SOURCE_PARAM",`the mapping's template needs ${o}`,{name:o,reason:"required"}),e(a)})}function it(n){return t=>((t==="."||t===".."||t==="")&&l(n,"E_SOURCE_PARAM","a path value may not be empty or a dot segment",{name:"path",reason:"path"}),encodeURIComponent(t))}function x(n,t,e){const i=t.pathname.replace(/\/$/,"");return(n.origin!==t.origin||!(n.pathname===i||n.pathname.startsWith(`${i}/`)))&&l(e,"E_SOURCE_PARAM","a request left the mapping's endpoint",{name:"url",reason:"origin"}),n}function nt(n,t,e,i){const s=R(t.path,e,it(i),i),o=new URL(`${n.origin}${n.pathname.replace(/\/$/,"")}${s}`);for(const[d,r]of Object.entries(t.query??{}))o.searchParams.set(d,R(r,e,c=>c,i));if(x(o,n,i),t.method!=="POST")return{url:o,init:{}};const a=k(t.body,e,i);return{url:o,init:{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a??null),idempotent:!0}}}function k(n,t,e){return typeof n=="string"?R(n,t,i=>i,e):Array.isArray(n)?n.map(i=>k(i,t,e)):typeof n=="object"&&n!==null?Object.fromEntries(Object.entries(n).map(([i,s])=>[i,k(s,t,e)])):n}function u(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function h(n,t,e,i,s=!1){n===void 0&&!i||(typeof n!="string"?e("missing",t):!(s&&n==="#")&&L(n)===null&&e("selector",t))}function I(n,t,e){typeof n!="string"?e("missing",t):et(n)===null&&e("template",t)}function st(n,t,e){if(n!==void 0){if(!u(n)){e("missing",`${t}.query`);return}for(const[i,s]of Object.entries(n))I(s,`${t}.query.${i}`,e)}}function ot(n){return u(n)&&Number.isInteger(n.max)&&n.max>=1&&typeof n.join=="string"}function rt(n,t,e,i){if(!u(n)){i("missing",t);return}n.method!==void 0&&n.method!=="GET"&&n.method!=="POST"&&i("missing",`${t}.method`),I(n.path,`${t}.path`,i),typeof n.path=="string"&&!n.path.startsWith("/")&&i("template",`${t}.path`),st(n.query,t,i),h(n.records,`${t}.records`,i,!0),typeof n.entity!="string"?i("missing",`${t}.entity`):e.has(n.entity)||i("unknown-entity",`${t}.entity`),n.batch!==void 0&&!ot(n.batch)&&i("batch",`${t}.batch`),n.paging!==void 0&&at(n.paging,`${t}.paging`,i)}function at(n,t,e){const i=n;if(!u(i)){e("paging",t);return}switch(i.style){case"cursor":(typeof i.param!="string"||typeof i.first!="string")&&e("paging",t),h(i.next,`${t}.next`,e,!0);break;case"offset":{const s=i.size;typeof i.param=="string"&&u(s)&&typeof s.param=="string"&&Number.isInteger(s.value)&&s.value>0&&(i.unit===void 0||i.unit==="items"||i.unit==="pages")&&(i.base===void 0||i.base===0||i.base===1)||e("paging",t);break}case"link-header":i.rel!==void 0&&typeof i.rel!="string"&&e("paging",t);break;case"next-url":h(i.next,`${t}.next`,e,!0);break;default:e("paging",`${t}.style`)}}function dt(n,t,e,i){if(!u(n)){i("missing",t);return}const s=n;if(typeof s.type!="string"&&i("missing",`${t}.type`),h(s.each,`${t}.each`,i,!1),"pairs"in s)h(s.pairs,`${t}.pairs`,i,!0);else if(h(s.to,`${t}.to`,i,!0),h(s.from,`${t}.from`,i,!1),u(s.fields))for(const[o,a]of Object.entries(s.fields))h(a,`${t}.fields.${o}`,i,!0);else s.fields!==void 0&&i("missing",`${t}.fields`);s.entity!==void 0&&(typeof s.entity!="string"||!e.has(s.entity))&&i("unknown-entity",`${t}.entity`)}function ct(n,t,e,i){if(!u(n)){i("missing",t);return}if(h(n.id,`${t}.id`,i,!0,!0),n.stripPrefix!==void 0&&typeof n.stripPrefix!="string"&&i("missing",`${t}.stripPrefix`),n.label!==void 0&&typeof n.label!="string"&&i("missing",`${t}.label`),n.node!==void 0&&n.node&&i("missing",`${t}.node`),u(n.fields))for(const[s,o]of Object.entries(n.fields))h(o,`${t}.fields.${s}`,i,!0,!0);else n.fields!==void 0&&i("missing",`${t}.fields`);Array.isArray(n.edges)?n.edges.forEach((s,o)=>{dt(s,`${t}.edges.${String(o)}`,e,i)}):n.edges!==void 0&&i("missing",`${t}.edges`),Array.isArray(n.embedded)?n.embedded.forEach((s,o)=>{const a=`${t}.embedded.${String(o)}`;if(!u(s)){i("missing",a);return}h(s.at,`${a}.at`,i,!0),(typeof s.entity!="string"||!e.has(s.entity))&&i("unknown-entity",`${a}.entity`)}):n.embedded!==void 0&&i("missing",`${t}.embedded`)}function ut(n,t,e){const i=[["load",n.load],["hydrate",n.hydrate],["seed",n.seed]];u(n.expand)?i.push(["expand.in",n.expand.in],["expand.out",n.expand.out]):i.push(["expand",n.expand]);for(const[s,o]of i)o===void 0&&s!=="load"||(typeof o!="string"?e("missing",s):t.has(o)||e("unknown-request",s))}function ft(n,t){let e=null;try{e=new URL(typeof n=="string"?n:"")}catch{}(e===null||e.protocol!=="https:"&&e.protocol!=="http:"||e.username!==""||e.password!==""||e.search!==""||e.hash!=="")&&t("endpoint","endpoint")}function lt(n){const t=[],e=(d,r)=>{t.push(Object.freeze({code:d,at:r}))};if(!u(n))return e("missing",""),t;const i=n;i.version!==1&&e("version","version"),ft(i.endpoint,e);const s=u(i.requests)?i.requests:{},o=u(i.entities)?i.entities:{};u(i.requests)||e("missing","requests"),u(i.entities)||e("missing","entities");const a=new Set(Object.keys(o));for(const[d,r]of Object.entries(s))rt(r,`requests.${d}`,a,e);for(const[d,r]of Object.entries(o))ct(r,`entities.${d}`,a,e);return ut(i,new Set(Object.keys(s)),e),ht(i,e),h(i.modified,"modified",e,!1),i.directed!==void 0&&typeof i.directed!="boolean"&&e("missing","directed"),t}function ht(n,t){for(const[e,i]of[["rateLimit.requests",n.rateLimit?.requests],["rateLimit.perMs",n.rateLimit?.perMs]])n.rateLimit!==void 0&&!(typeof i=="number"&&i>0)&&t("number",e);n.budgetHeaders!==void 0&&(typeof n.budgetHeaders.remaining!="string"||n.budgetHeaders.reset!==void 0&&typeof n.budgetHeaders.reset!="string")&&t("missing","budgetHeaders")}function pt(n){switch(n?.style){case"cursor":return n.first;case"offset":return n.base??0;default:return null}}function D(n,t,e,i,s){if(e===null)return n;const o=new URL(n);switch(t?.style){case"cursor":return o.searchParams.set(t.param,String(e)),o;case"offset":return o.searchParams.set(t.param,String(e)),o.searchParams.set(t.size.param,String(t.size.value)),o;default:return x(new URL(String(e),n),i,s)}}function gt(n,t,e,i){return D(n,t,pt(t),e,i)}function mt(n,t){for(const e of n.split(/,(?=\s*<)/)){const i=/^\s*<([^>]*)>(.*)$/.exec(e);if(i===null)continue;if(/;\s*rel="?([^";]+)"?/i.exec(i[2])?.[1].split(/\s+/).includes(t))return i[1]}return null}function yt(n,t,e,i){const s=t.headers.get("link");if(s===null)return t.runtime==="browser"&&l(i,"E_SOURCE_RESPONSE","the Link header cannot be read",{expected:"link-header",contentType:t.headers.get("content-type")}),null;const o=mt(s,n);return o===null?null:x(new URL(o,t.url),e,i).href}function bt(n,t,e,i,s){switch(n?.style){case"cursor":{const o=y(e.body,n.next);return typeof o=="string"&&o!==""||typeof o=="number"?o:null}case"offset":{if(e.records<n.size.value||e.records===0)return null;const o=n.unit==="pages"?1:n.size.value;return Number(t)+o}case"link-header":return yt(n.rel??"next",e,i,s);case"next-url":{const o=y(e.body,n.next);return typeof o=="string"&&o!==""?x(new URL(o,e.url),i,s).href:null}default:return null}}function A(n=[]){return{full:new Set,stubs:new Set,known:new Set(n),modified:null}}function b(n,t){if(typeof n!="string"&&typeof n!="number")return null;const e=String(n),i=t?.stripPrefix;return i!==void 0&&i!==""&&e.startsWith(i)?e.slice(i.length):e}function O(n,t,e){return t==="#"?e:t.includes("[]")?g(n,t):y(n,t)}class vt{constructor(t,e){this.mapping=t,this.state=e,this.out={nodes:[],edges:[]},this.pending=[]}addRecords(t,e){const i=this.mapping.entities[e];t.forEach((s,o)=>{const a=i.node===!1?null:b(O(s,i.id,o),i);if(i.node!==!1){if(a===null)return;this.addNode(s,o,a,e,i)}const d=this.mapping.modified===void 0?void 0:y(s,this.mapping.modified);typeof d=="string"&&(this.state.modified===null||d>this.state.modified)&&(this.state.modified=d),this.pending.push({record:s,entity:e,id:a});for(const r of i.embedded??[])this.addRecords(g(s,r.at),r.entity)})}addNode(t,e,i,s,o){const a={labels:[o.label??s]};if(o.fields===void 0)for(const[d,r]of Object.entries(t))d!=="id"&&d!=="labels"&&(typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&(a[d]=r);else for(const[d,r]of Object.entries(o.fields)){const c=O(t,r,e);c!==void 0&&(a[d]=c)}this.state.stubs.has(i)&&(a[N]=!1),this.state.full.add(i),this.out.nodes.push({id:i,...a})}end(t,e){const{full:i,stubs:s,known:o}=this.state;i.has(t)||s.has(t)||o.has(t)||(s.add(t),this.out.nodes.push({id:t,[N]:!0,...e===void 0?{}:{[Z]:e}}))}runRule(t,e,i,s){const o=t.each===void 0?[e]:g(e,t.each);"pairs"in t?this.runPairsRule(t,o,i):this.runLinkRule(t,o,i,s)}runPairsRule(t,e,i){const s=t.entity??i,o=this.mapping.entities[s];for(const a of e){const d=[...new Set(g(a,t.pairs).map(r=>b(r,o)))].filter(r=>r!==null);for(let r=0;r<d.length;r++)for(let c=r+1;c<d.length;c++)this.end(d[r],s),this.end(d[c],s),this.out.edges.push({source:d[r],target:d[c],type:t.type})}}runLinkRule(t,e,i,s){const o=this.mapping.entities[i],a=t.entity===void 0?o:this.mapping.entities[t.entity];for(const d of e){const r=t.from===void 0?s:b(y(d,t.from),o);if(r===null)continue;const c=g(d,t.to).map(f=>b(f,a)).filter(f=>f!==null);for(const f of c)this.end(r,t.from===void 0?i:void 0),this.end(f,t.entity),this.out.edges.push({...xt(t.fields,d),source:r,target:f,type:t.type})}}finish(){for(const{record:t,entity:e,id:i}of this.pending)for(const s of this.mapping.entities[e].edges??[])this.runRule(s,t,e,i);return this.pending.length=0,this.out}}function xt(n,t){const e={};for(const[i,s]of Object.entries(n??{})){const o=O(t,s,0);o!==void 0&&(e[i]=o)}return e}function $(n,t,e){const i=new vt(n,e);for(const s of t)i.addRecords(s.records,s.entity);return i.finish()}const wt=new Set(["E_SOURCE_AUTH","E_SOURCE_FORBIDDEN"]);function St(n){return Math.max(0,n>1e9?n*1e3-Date.now():n*1e3)}class v{constructor(t,e,i){this.plan=t,this.ctx=e,this.paced=i,this.facts={},this.last=0,this.endpoint=new URL(t.mapping.endpoint),e.endpoint!==null&&X(e.endpoint)!==this.endpoint.origin&&l(e.report,"E_SOURCE_PARAM","the endpoint is not the mapping's",{name:"endpoint",reason:"origin"})}async pace(){const t=this.plan.mapping.rateLimit;if(!this.paced||t===void 0)return;const e=this.last+t.perMs/t.requests-Date.now();e>0&&await J(e,this.ctx.signal),this.last=Date.now()}noteBudget(t){const e=this.plan.mapping.budgetHeaders,i=e===void 0?null:t.get(e.remaining);if(e===void 0||i===null||!Number.isFinite(Number(i)))return;const s=e.reset===void 0?null:Number(t.get(e.reset)??Number.NaN),o=s===null||!Number.isFinite(s)?void 0:St(s);this.facts.budget={remaining:Number(i),...o===void 0?{}:{resetMs:o}}}async read(t,e,i,s){const o=this.plan.mapping.requests[t],{report:a}=this.ctx,d=nt(this.endpoint,o,e,a),r=i===void 0?gt(d.url,o.paging,this.endpoint,a):D(d.url,o.paging,i,this.endpoint,a);await this.pace();const c=await this.ctx.fetch(r,{...d.init,headers:{accept:"application/json",...d.init.headers,...s},allowStatus:[304]});if(this.noteBudget(c.headers),c.status===304)return{records:[],next:null,headers:c.headers,status:304};const f=await c.text();let p;try{p=JSON.parse(f)}catch{l(a,"E_SOURCE_RESPONSE","the response is not JSON",{expected:"json",contentType:c.headers.get("content-type")})}const P=Q(p,o.records),B=i??null,H=bt(o.paging,i??(o.paging?.style==="offset"?o.paging.base??0:B),{body:p,headers:c.headers,url:r,records:P.length,runtime:this.ctx.runtime},this.endpoint,a);return{records:P,next:H,headers:c.headers,status:c.status}}finish(t,e=null){return t?.modified!==null&&t?.modified!==void 0&&(this.facts.validators={...this.facts.validators,modified:t.modified}),this.ctx.finish({...this.facts,next:e})}noteValidators(t){const e=t.get("etag"),i=t.get("last-modified");this.facts.validators={...this.facts.validators,...e===null?{}:{etag:e},...i===null?{}:{lastModified:i}}}meta(){const{directed:t}=this.plan.mapping;return t===void 0?void 0:{directed:t}}}function _t(n,t){const e={};for(const[i,s]of Object.entries(n))i!==t&&(typeof s=="string"||typeof s=="number"||typeof s=="boolean")&&(e[i]=String(s));return e}async function*Et(n){const{mapping:t,values:e}=n.plan,{cursor:i}=n.ctx;i!==null&&i.r!==t.load&&l(n.ctx.report,"E_SOURCE_PARAM","the cursor is not this mapping's",{name:"cursor",reason:"stale-cursor"});const s=A(),o=[];if(i===null&&t.seed!==void 0){const c=await n.read(t.seed,e,void 0);o.push({records:c.records,entity:t.requests[t.seed].entity})}const{entity:a}=t.requests[t.load];let d=i===null?void 0:i.at,r=!0;for(;;){const c=await n.read(t.load,e,d);r&&i===null&&n.noteValidators(c.headers);const f=$(t,[...o.splice(0),{records:c.records,entity:a}],s);n.finish(s);const p=c.next===null?null:{r:t.load,at:c.next};if(yield{nodes:f.nodes,edges:f.edges,next:p,meta:r?n.meta():void 0},c.next===null)return;r=!1,d=c.next}}function Rt(n,t,e,i){const{report:s}=e;let o=0;for(const{id:a,...d}of n.nodes){o++%64===0&&M(e.signal);try{t.addNodeRecord(a,d),s.counts.nodes++}catch(r){s.recordError(r,{element:String(a)}),s.counts.skippedNodes++}}for(const{source:a,target:d,...r}of n.edges)if(o++%64===0&&M(e.signal),!(i!==void 0&&!i.has(String(r.type))))try{t.addEdgeRecord(a,d,r),s.counts.edges++}catch(c){s.recordError(c,{element:`${String(a)} -> ${String(d)}`}),s.counts.skippedEdges++}}function kt(n,t){if(t.depth===0)return n.hydrate===void 0?[]:[n.hydrate];const{expand:e}=n;if(typeof e=="string"||e===void 0)return e===void 0?[]:[e];const i=t.direction??"both",s=[i!=="out"?e.in:void 0,i!=="in"?e.out:void 0];return[...new Set(s.filter(o=>o!==void 0))]}function Ot(n,t){const e=[];for(let i=0;i<n.length;i+=t)e.push(n.slice(i,i+t));return e}async function At(n,t,e){return new $t(n,t,e).expand()}class $t{constructor(t,e,i){this.run=t,this.request=e,this.sink=i,this.added=0,this.wrote=!1;const{ctx:s}=t;this.mapping=t.plan.mapping,this.names=kt(this.mapping,e),this.names.length===0&&l(s.report,"E_SOURCE_UNSUPPORTED","the mapping has no request for this expansion",{feature:e.depth===0?"hydrate":"expand"}),e.ids.length===0&&l(s.report,"E_SOURCE_PARAM","an expansion needs seed ids",{name:"ids",reason:"required"}),this.state=A([...e.ids.map(String),...(e.exclude??[]).map(String)]),this.types=e.relationshipTypes===void 0?void 0:new Set(e.relationshipTypes),this.mapping.directed!==void 0&&i.edgeCount===0&&i.setDirected(this.mapping.directed)}async expand(){let t=this.request.ids.map(String);const e=Math.max(1,this.request.depth??1);for(let i=1;i<=e&&t.length>0;i++){const s=[],o=await this.hop(i,t,s);if(o!==null)return o;t=[...new Set(s)]}return this.run.finish(this.state,null)}async hop(t,e,i){for(const[s,o]of this.names.entries()){const a=this.mapping.requests[o].batch?.max??1;for(const[d,r]of Ot(e,a).entries()){if(this.skipped({hop:t,x:s,b:d}))continue;const c=await this.readBatch({hop:t,x:s,b:d},o,r,e,i);if(c!==null)return c}}return null}skipped(t){const{hop:e,x:i,b:s}=t,o=this.run.ctx.cursor;if(e!==1||o===null)return!1;const a=Number(o.x);return i<a||i===a&&s<Number(o.b)}startPosition(t){const{hop:e,x:i,b:s}=t,o=this.run.ctx.cursor;return e===1&&o!==null&&i===Number(o.x)&&s===Number(o.b)?o.at??void 0:void 0}async readBatch(t,e,i,s,o){const a=this.mapping.requests[e],d={...this.run.plan.values,id:i[0],ids:i.join(a.batch?.join??",")};let r=this.startPosition(t);for(;;){let c;try{c=await this.run.read(e,d,r)}catch(p){return this.authStop(p,t.hop===1?{x:t.x,b:t.b,at:r??null}:null)}this.writeNew(c,a.entity,o);const f=this.capStop(t,c,s);if(f!==null||c.next===null)return f;r=c.next}}authStop(t,e){if(!this.wrote||!(t instanceof Y)||!wt.has(String(t.issue?.code)))throw t;const i=t.issue?.params??{};return U(this.run.ctx.report,"W_SOURCE_AUTH","a later page needs a credential; the pages before it are kept",{origin:typeof i.origin=="string"?i.origin:this.run.endpoint.origin,status:typeof i.status=="number"?i.status:null}),this.run.finish(this.state,e)}writeNew(t,e,i){const{state:s}=this,o=new Set([...s.full,...s.stubs]),a=$(this.mapping,[{records:t.records,entity:e}],s);Rt(a,this.sink,this.run.ctx,this.types),this.wrote=!0;for(const d of a.nodes){const r=String(d.id);!o.has(r)&&!s.known.has(r)&&(i.push(r),this.added++)}}capStop(t,e,i){const{hop:s,x:o,b:a}=t,{ctx:d}=this.run,r=this.request.limit!==void 0&&this.added>=this.request.limit;if(r&&U(d.report,"W_SOURCE_LIMIT","the expansion reached its limit",{limit:"limit",value:this.added}),!r&&!d.limits.reached())return null;const c=e.next===null?null:{x:o,b:a,at:e.next};return this.run.finish(this.state,s===1?c??Pt(o,a,this.names,i,this.mapping):null)}}function Pt(n,t,e,i,s){const o=Math.ceil(i.length/(s.requests[e[n]].batch?.max??1));return t+1<o?{x:n,b:t+1,at:null}:n+1<e.length?{x:n+1,b:0,at:null}:null}async function Ut(n,t){const{mapping:e,values:i}=n.plan,s={};t.etag!==void 0&&(s["if-none-match"]=t.etag),t.lastModified!==void 0&&(s["if-modified-since"]=t.lastModified);const o=A(),a=[];if(e.seed!==void 0){const c=await n.read(e.seed,i,void 0);a.push({records:c.records,entity:e.requests[e.seed].entity})}const d=await n.read(e.load,i,void 0,s);if(d.status===304)return{status:"current",via:t.etag===void 0?"modified":"etag",validators:t};$(e,[...a,{records:d.records,entity:e.requests[e.load].entity}],o),n.noteValidators(d.headers);const r={...n.facts.validators,...o.modified===null?{}:{modified:o.modified}};return t.etag!==void 0&&r.etag!==void 0?{status:t.etag===r.etag?"current":"changed",via:"etag",validators:r}:t.modified!==void 0&&r.modified!==void 0?r.modified>t.modified?{status:"changed",via:"modified",changedAt:r.modified,validators:r}:{status:"current",via:"modified",validators:r}:{status:"unverifiable",validators:r}}function z(n,t){return{records:(e,i)=>Et(new v(n(e,i,"load"),i,t)),expand:(e,i,s)=>At(new v(n(e.params,s,"expand"),s,t),e,i),async probe(e,i){const s=new v(n(e,i,"probe"),i,t),o=await s.read(s.plan.mapping.load,s.plan.values,void 0);return o.records.length===0&&o.status!==304&&l(i.report,"E_SOURCE_NOT_FOUND","the load request found no records",{what:"records",value:s.plan.mapping.load}),{ok:!0}},validate:(e,i,s)=>Ut(new v(n(e,s,"validate"),s,t),i)}}function Nt(n,t){const[e]=lt(n);return e!==void 0&&l(t.report,"E_SOURCE_PARAM",`the mapping is invalid at ${e.at}`,{name:"mapping",reason:e.code,at:e.at}),n}const Bt=C({id:F,descriptor:W,...z((n,t)=>({mapping:Nt(n.mapping,t),values:_t(n,"mapping")}),!0)}),w="https://openalex.org/",Mt="id,display_name,publication_year,cited_by_count,updated_date,referenced_works";function S(n,t,e){return{path:"/works",query:{filter:n,"per-page":t,select:"{select}"},batch:{max:50,join:"|"},records:"results",entity:"work",...e?{paging:{style:"cursor",param:"cursor",first:"*",next:"meta.next_cursor"}}:{}}}const _={id:"id",stripPrefix:w,fields:{name:"display_name"}},m=Object.freeze({version:1,endpoint:"https://api.openalex.org",load:"citing",seed:"by-id",expand:{in:"citing",out:"by-id"},hydrate:"by-id",directed:!0,modified:"updated_date",auth:{kind:"api-key",query:"api_key"},rateLimit:{requests:10,perMs:1e3},budgetHeaders:{remaining:"x-ratelimit-remaining",reset:"x-ratelimit-reset"},requests:{citing:S("cites:{ids}","200",!0),"by-id":S("openalex:{ids}","50",!1),authored:S("authorships.author.id:{ids}","200",!0),"authors-by-id":{path:"/authors",query:{filter:"openalex:{ids}","per-page":"50",select:"id,display_name"},batch:{max:50,join:"|"},records:"results",entity:"author"}},entities:{work:{id:"id",stripPrefix:w,fields:{title:"display_name",year:"publication_year",citedBy:"cited_by_count",updated:"updated_date"},edges:[{to:"referenced_works[]",type:"cites",entity:"work"},{to:"authorships[].author.id",type:"authored_by",entity:"author"},{each:"authorships[]",from:"author.id",to:"institutions[].id",type:"affiliated_with",entity:"institution"},{to:"topics[].id",type:"has_topic",entity:"topic"}],embedded:[{at:"authorships[].author",entity:"author"},{at:"authorships[].institutions[]",entity:"institution"},{at:"topics[]",entity:"topic"}]},author:_,institution:_,topic:_}});function Tt(n){const t=typeof n=="string"?n.split(","):[];Array.isArray(n)&&t.push(...n);const e=new Set(t.map(i=>String(i).trim()).filter(i=>i!==""));return e.has("institutions")&&e.add("authors"),e}function jt(n){const{work:t}=m.entities,e=s=>s==="cites"||s==="authored_by"&&n.has("authors")||s==="affiliated_with"&&n.has("institutions")||s==="has_topic"&&n.has("topics"),i=s=>n.has(`${s}s`);return{...m,entities:{...m.entities,work:{...t,edges:t.edges?.filter(s=>e(s.type)),embedded:t.embedded?.filter(s=>i(s.entity))}}}}function qt(n,t){const e=n.has("institutions");return{...m,load:t?"by-id":"authored",seed:void 0,expand:"authored",hydrate:"authors-by-id",directed:!1,entities:{...m.entities,work:{id:"id",stripPrefix:w,node:!1,edges:[{pairs:"authorships[].author.id",type:"coauthor",entity:"author"},...e?[{each:"authorships[]",from:"author.id",to:"institutions[].id",type:"affiliated_with",entity:"institution"}]:[]],embedded:[{at:"authorships[].author",entity:"author"},...e?[{at:"authorships[].institutions[]",entity:"institution"}]:[]]}}}}function j(n,t,e,i){const s=typeof n=="string"?n.trim().replace(w,""):"";return new RegExp(String.raw`^${e}\d+$`,"i").test(s)||l(i.report,"E_SOURCE_PARAM",`${t} is not an OpenAlex id`,{name:t,reason:"format"}),s.toUpperCase()}function Ct(n,t,e){const i=n.graph??"citation",s=Tt(n.include),o=n.work!==void 0&&n.work!=="",a=n.author!==void 0&&n.author!=="";e!=="expand"&&o===a&&l(t.report,"E_SOURCE_PARAM","give exactly one of work and author",{name:"work",reason:o?"exclusive":"required"});let d="";if(o?d=j(n.work,"work","W",t):a&&(d=j(n.author,"author","A",t)),i==="coauthorship")return{mapping:qt(s,o),values:{ids:d,select:e==="validate"?"id,updated_date":"id,updated_date,authorships"}};let r=Mt+(s.has("authors")?",authorships":"")+(s.has("topics")?",topics":"");e==="validate"&&(r="id,updated_date");const c=jt(s);return{mapping:o?c:{...c,load:"authored",seed:void 0},values:{ids:d,select:r}}}const Lt=/^[WAIT]\d+$/,q=z(Ct,!1),Ht=C({id:G,descriptor:V,...q,expand(n,t,e){for(const i of n.ids)Lt.test(String(i))||l(e.report,"E_SOURCE_PARAM","an expansion seed is not an OpenAlex id",{name:"ids",reason:"format"});return q.expand(n,t,e)}});export{Vt as DEPS_DEV_MAPPING,V as OPENALEX_DESCRIPTOR,m as OPENALEX_MAPPING,W as REST_DESCRIPTOR,Gt as STRING_MAPPING,lt as checkRestMapping,Ht as openalexSource,Bt as restMappingSource};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{d as Q,x as W,y as B,f as u,t as X}from"./io-D-Vr0j3W.js";import{sha256Hex as j}from"./sigv4-BXwVbza3-DZCCNyQA.js";import"./preload-helper-Crt_PPe8.js";import"./elements-DIunzJUl.js";const R=/\s*(?:<([^<>]*)>|_:([\w.-]*[\w-])|"((?:[^"\\]|\\.)*)"(?:@([A-Za-z][\w-]*)|\^\^<([^<>]*)>)?)/y,_=/\s*\.\s*(?:#.*)?$/y,N="http://www.w3.org/2001/XMLSchema#",q=new Set(["integer","decimal","double","float","int","long","short","byte","nonNegativeInteger","nonPositiveInteger","positiveInteger","negativeInteger","unsignedInt","unsignedLong","unsignedShort","unsignedByte"].map(e=>N+e));function v(e){if(!e.includes("\\"))return e;const t={t:" ",b:"\b",n:`
|
|
2
|
+
`,r:"\r",f:"\f"};return e.replaceAll(/\\(?:u([\da-fA-F]{4})|U([\da-fA-F]{8})|(.))/g,(n,r,o,a)=>{const s=r??o;return s!==void 0?String.fromCodePoint(Number.parseInt(s,16)):t[a??""]??a??""})}function A(e,t){R.lastIndex=t;const n=R.exec(e);if(n===null)return null;const[,r,o,a,s,i]=n;let l;return r!==void 0?l={kind:"iri",value:v(r)}:o===void 0?l={kind:"literal",value:v(a??""),lang:s?.toLowerCase()??"",datatype:i??""}:l={kind:"bnode",value:`_:${o}`},{term:l,end:R.lastIndex}}function Y(e){const t=[],n=e.split(/\r?\n/);for(let r=0;r<n.length;r++){const o=n[r],a=o.trim();if(a===""||a.startsWith("#"))continue;const s=A(o,0),i=s===null?null:A(o,s.end),l=i===null?null:A(o,i.end);if(_.lastIndex=l?.end??0,s===null||i===null||l===null||s.term.kind==="literal"||i.term.kind!=="iri"||!_.test(o))return{triples:t,badLine:r+1};t.push({s:s.term,p:i.term.value,o:l.term})}return{triples:t,badLine:null}}function $(e){const t=Math.max(e.lastIndexOf("#"),e.lastIndexOf("/"),e.lastIndexOf(":")),n=e.slice(t+1);return n===""?e:n}function G(e){if(q.has(e.datatype)){const t=Number(e.value);return Number.isFinite(t)?t:e.value}return e.datatype===`${N}boolean`?e.value==="true"||e.value==="1":e.value}function Z(e,t){return t===""||e===""||e===t||e.startsWith(`${t}-`)}function U(e,t,n){const r=n??{nodes:new Map,edges:[]};for(const{s:o,p:a,o:s}of e){let i=r.nodes.get(o.value);if(i===void 0&&(i={},r.nodes.set(o.value,i)),s.kind==="literal"){const l=$(a);Z(s.lang,t)&&!(l in i)&&(i[l]=G(s))}else r.edges.push({source:o.value,target:s.value,type:$(a),predicate:a})}return r}function K(e){const t=e.o.kind==="literal"?JSON.stringify([e.o.value,e.o.lang,e.o.datatype]):e.o.value;return`${e.s.value} ${e.p} ${t}`}const J=/[\s<>"{}|^`\\]/,x=/^[a-z]{1,8}(-[a-z\d]{1,8})*$/i;function ee(e){return e.replaceAll(/<[^<>\s]*>/g,"<>").replaceAll(/"""[\s\S]*?"""|'''[\s\S]*?'''|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'/g,'""').replaceAll(/#[^\n]*/g,"")}const te=/\b(INSERT|DELETE|LOAD|CLEAR|DROP|CREATE|ADD|MOVE|COPY|WITH)\b/i,L=/^\s*(?:BASE|PREFIX\s*[^\s:<]*:)\s*<>/i;function ne(e){let t=e;for(let n=L.exec(t);n!==null;n=L.exec(t))t=t.slice(n[0].length);return t}function re(e){return e.replaceAll(/[?$]\w+/g,"?v").replaceAll(/[\w.%:-]+/g,t=>t.includes(":")?"_":t)}function oe(e){let t=0;for(const n of e)if(n==="{")t++;else if(n==="}")t--;else if(n===";"&&t<=0)return!0;return!1}function se(e){const t=ne(ee(e)),n=re(t),r=/^\s*([A-Za-z]+)/.exec(n)?.[1]?.toUpperCase()??"",a=!(te.test(n)||oe(n))&&["CONSTRUCT","DESCRIBE","SELECT","ASK"].includes(r)?r.toLowerCase():null,s=n.slice(n.lastIndexOf("}")+1);let i=[];if(a==="construct"){const l=/\bCONSTRUCT\s*\{([^}]*)\}/i.exec(t)?.[1]??"";i=[...new Set(l.match(/[?$]\w+/g)??[])].map(d=>`?${d.slice(1)}`)}return{form:a,ownLimit:/\b(LIMIT|OFFSET)\b/i.test(s),ordered:/\bORDER\s+BY\b/i.test(s),templateVars:i}}function I(e,t,n,r){const o=t.ordered||t.templateVars.length===0?"":`
|
|
3
|
+
ORDER BY ${t.templateVars.join(" ")}`,a=r>0?` OFFSET ${String(r)}`:"";return`${e.trimEnd()}${o}
|
|
4
|
+
LIMIT ${String(n)}${a}`}function O(e){const t=String(e);return/^[a-z][\w+.-]*:/i.test(t)&&!J.test(t)?`<${t}>`:null}function T(e){const{language:t,predicates:n}=e,r=t===""?"":` FILTER(!isLiteral(?o) || lang(?o) = "" || langMatches(lang(?o), "${t}"))`,o=n.map(a=>`STRSTARTS(STR(?p), "${a}")`).join(" || ");return n.length===0?r:`${r} FILTER(isLiteral(?o) || ${o})`}function ie(e){return x.test(e)}function ae(e,t,n){return I(`CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o .${T(e)} }`,{ordered:!1,templateVars:["?s","?p","?o"]},t,n)}function M(e,t,n,r,o){const a=e.join(" "),s=`{ VALUES ?s { ${a} } ?s ?p ?o .${T(n)} }`,i=`{ VALUES ?o { ${a} } ?s ?p ?o .${T({...n,language:""})} }`;let l=`${s} UNION ${i}`;return t!=="both"&&(l=t==="out"?s:i),I(`CONSTRUCT { ?s ?p ?o } WHERE { ${l} }`,{ordered:!1,templateVars:["?s","?p","?o"]},r,o)}const P=1e3,le=500,ue=10,ce="application/n-triples, text/plain;q=0.9";async function h(e,t){X(e.signal);const n=await e.fetch(e.endpoint??"",{method:"POST",idempotent:!0,headers:{Accept:ce,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({query:t}).toString(),allowStatus:[400]});if(n.status===400){const i=(await n.text()).trim().slice(0,500);u(e.report,"E_SOURCE_QUERY","the endpoint refused the query",{serverCode:null,line:null,column:null,serverMessage:i===""?null:i})}const r=n.headers.get("content-type"),o=()=>u(e.report,"E_SOURCE_RESPONSE","the endpoint did not answer N-Triples",{expected:"n-triples",contentType:r});r!==null&&/html|json|xml/i.test(r)&&o();const{triples:a,badLine:s}=Y(await n.text());return s!==null&&o(),a}function y(e,t,n,r){return(!Number.isInteger(e)||e<1||e>n)&&u(r.report,"E_SOURCE_PARAM",`${t} is an integer from 1 to ${String(n)}`,{name:t,reason:"range"}),e}function m(e,t){const n=e.language??"";return n!==""&&!ie(n)&&u(t.report,"E_SOURCE_PARAM","language is a language tag",{name:"language",reason:"type"}),n.toLowerCase()}function D(e,t){const n=e.predicates??[],r=typeof n=="string"?[n]:n;for(const o of r)(typeof o!="string"||O(o)===null)&&u(t.report,"E_SOURCE_PARAM","predicates are IRI prefixes",{name:"predicates",reason:"iri"});return r}function k(e,t,n){return(e===void 0||e.length===0)&&u(n.report,"E_SOURCE_PARAM",`${t} needs at least one IRI`,{name:t,reason:"required"}),e.map(r=>O(r)??u(n.report,"E_SOURCE_PARAM",`${t}: not an IRI`,{name:t,reason:"iri"}))}function F(e,t){const n=y(e.pageSize??P,"pageSize",1e4,t),r={language:m(e,t),predicates:D(e,t)},o=e.query?.trim()??"",a=e.mode??(o===""?"all":"query");if(a==="neighborhood"){const i=k(e.ids,"ids",t);return{at:l=>M(i,"both",r,n,l),paged:!0}}if(a==="all")return{at:i=>ae(r,n,i),paged:!0};o===""&&u(t.report,"E_SOURCE_PARAM","mode query needs a query",{name:"query",reason:"required"});const s=se(o);return s.form!=="construct"&&s.form!=="describe"&&u(t.report,"E_SOURCE_PARAM","the query must be CONSTRUCT or DESCRIBE",{name:"query",reason:"form"}),s.ownLimit?{at:()=>o,paged:!1}:{at:i=>I(o,s,n,i),paged:!0}}function z(e,t,n){const{report:r}=n;t.edgeCount===0&&t.setDirected(!0);for(const[o,a]of e.nodes)try{t.addNodeRecord(o,a),r.counts.nodes++}catch(s){r.recordError(s,{element:o}),r.counts.skippedNodes++}for(const{source:o,target:a,...s}of e.edges)try{t.addEdgeRecord(o,a,s,null),r.counts.edges++}catch(i){r.recordError(i,{element:`${o} -> ${a}`}),r.counts.skippedEdges++}}function de(e,t){return e===t?0:e<t?-1:1}function H(e){return j(e.map(K).sort(de).join(`
|
|
5
|
+
`))}async function fe(e,t,n){const r=F(e,n),o=e.pageSize??P,a=Number(n.cursor?.offset??0),s=m(e,n);let i=a,l=null,d;for(;;){const f=await h(n,r.at(i));i===0&&(d=await H(f)),z(U(f,s),t,n);const{counts:p}=n.report;if(n.progress(p.nodes+p.edges,void 0,"items"),!r.paged||f.length===0){l=null;break}if(i+=o,l={offset:i},n.limits.reached())break}return n.finish({next:l,...d===void 0?{}:{validators:{contentHash:d}}})}async function pe(e,t,n){const r=e.direction??"both";["out","in","both"].includes(r)||u(n.report,"E_SOURCE_PARAM","direction must be out, in or both",{name:"direction",reason:"enum"});const o=y(e.depth??1,"depth",ue,n),a=y(e.limit??le,"limit",Number.MAX_SAFE_INTEGER,n),s=m(e.params,n),i={language:s,predicates:D(e.params,n)},l=e.relationshipTypes===void 0?null:new Set(e.relationshipTypes),d=o===1?Number(n.cursor?.offset??0):0,f=new Set(e.ids.map(String));let p=k(e.ids,"ids",n),C=null;const g={nodes:new Map,edges:[]};for(let b=0;b<o&&p.length>0;b++){const w=await h(n,M(p,r,i,a,d)),S=g.edges.length;if(U(w,s,g),l!==null){const c=g.edges.slice(S).filter(E=>l.has(E.type)||l.has(E.predicate));g.edges.splice(S,1/0,...c)}o===1&&w.length>0&&(C={offset:d+a});const V=g.edges.slice(S).flatMap(c=>[c.source,c.target]);p=[...new Set(V)].filter(c=>!f.has(c)).flatMap(c=>{f.add(c);const E=O(c);return E===null?[]:[E]})}return z(g,t,n),n.finish({next:C})}const Se=Q({id:B,descriptor:W,import:fe,expand:pe,probe:async(e,t)=>(await h(t,"CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o } LIMIT 1"),m(e,t),{ok:!0}),validate:async(e,t,n)=>{const r=await H(await h(n,F(e,n).at(0)));let o="unverifiable";return t.contentHash!==void 0&&(o=t.contentHash===r?"current":"changed"),{status:o,via:"hash",validators:{contentHash:r}}}});export{W as SPARQL_DESCRIPTOR,Se as sparqlSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as t,b as A,c as o,I as e,L as S,d as _,g as E,t as I,w as L}from"./chunks/index-C-jUF_Ve.js";import"./chunks/preload-helper-Crt_PPe8.js";export{t as ALGORITHM_NAMES,A as ASYNC_ALGORITHM_NAMES,o as GPU_SIZE_FLOOR,e as IdTakenError,S as LAYOUT_NAMES,_ as configureWebGpu,E as default,I as toSnapshot,L as writeData};
|
package/dist/cdn/io.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as r,B as p}from"./chunks/io-D-Vr0j3W.js";import"./chunks/elements-DIunzJUl.js";import"./chunks/preload-helper-Crt_PPe8.js";export{r as exportElements,p as importElements};
|