@graphty/layout 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/README.md +317 -237
  2. package/dist/src/algorithms/index.d.ts +5 -0
  3. package/dist/src/algorithms/index.js +6 -0
  4. package/dist/src/algorithms/index.js.map +1 -0
  5. package/dist/src/algorithms/optimization/index.d.ts +7 -0
  6. package/dist/src/algorithms/optimization/index.js +7 -0
  7. package/dist/src/algorithms/optimization/index.js.map +1 -0
  8. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +32 -0
  9. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +176 -0
  10. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -0
  11. package/dist/src/algorithms/optimization/lbfgs.d.ts +13 -0
  12. package/dist/src/algorithms/optimization/lbfgs.js +56 -0
  13. package/dist/src/algorithms/optimization/lbfgs.js.map +1 -0
  14. package/dist/src/algorithms/optimization/line-search.d.ts +15 -0
  15. package/dist/src/algorithms/optimization/line-search.js +37 -0
  16. package/dist/src/algorithms/optimization/line-search.js.map +1 -0
  17. package/dist/src/algorithms/optimization/types.d.ts +5 -0
  18. package/dist/src/algorithms/optimization/types.js +5 -0
  19. package/dist/src/algorithms/optimization/types.js.map +1 -0
  20. package/dist/src/algorithms/planarity/check.d.ts +17 -0
  21. package/dist/src/algorithms/planarity/check.js +30 -0
  22. package/dist/src/algorithms/planarity/check.js.map +1 -0
  23. package/dist/src/algorithms/planarity/embedding.d.ts +29 -0
  24. package/dist/src/algorithms/planarity/embedding.js +179 -0
  25. package/dist/src/algorithms/planarity/embedding.js.map +1 -0
  26. package/dist/src/algorithms/planarity/index.d.ts +7 -0
  27. package/dist/src/algorithms/planarity/index.js +8 -0
  28. package/dist/src/algorithms/planarity/index.js.map +1 -0
  29. package/dist/src/algorithms/planarity/lr-test.d.ts +15 -0
  30. package/dist/src/algorithms/planarity/lr-test.js +54 -0
  31. package/dist/src/algorithms/planarity/lr-test.js.map +1 -0
  32. package/dist/src/algorithms/planarity/special-graphs.d.ts +28 -0
  33. package/dist/src/algorithms/planarity/special-graphs.js +108 -0
  34. package/dist/src/algorithms/planarity/special-graphs.js.map +1 -0
  35. package/dist/src/generators/basic.d.ts +28 -0
  36. package/dist/src/generators/basic.js +79 -0
  37. package/dist/src/generators/basic.js.map +1 -0
  38. package/dist/src/generators/bipartite.d.ts +16 -0
  39. package/dist/src/generators/bipartite.js +40 -0
  40. package/dist/src/generators/bipartite.js.map +1 -0
  41. package/dist/src/generators/grid.d.ts +11 -0
  42. package/dist/src/generators/grid.js +37 -0
  43. package/dist/src/generators/grid.js.map +1 -0
  44. package/dist/src/generators/index.d.ts +8 -0
  45. package/dist/src/generators/index.js +9 -0
  46. package/dist/src/generators/index.js.map +1 -0
  47. package/dist/src/generators/random.d.ts +12 -0
  48. package/dist/src/generators/random.js +34 -0
  49. package/dist/src/generators/random.js.map +1 -0
  50. package/dist/src/generators/scale-free.d.ts +12 -0
  51. package/dist/src/generators/scale-free.js +62 -0
  52. package/dist/src/generators/scale-free.js.map +1 -0
  53. package/dist/src/index.d.ts +10 -0
  54. package/dist/src/index.js +15 -0
  55. package/dist/src/index.js.map +1 -0
  56. package/dist/src/layouts/basic/index.d.ts +4 -0
  57. package/dist/src/layouts/basic/index.js +5 -0
  58. package/dist/src/layouts/basic/index.js.map +1 -0
  59. package/dist/src/layouts/basic/random.d.ts +14 -0
  60. package/dist/src/layouts/basic/random.js +27 -0
  61. package/dist/src/layouts/basic/random.js.map +1 -0
  62. package/dist/src/layouts/force-directed/arf.d.ts +13 -0
  63. package/dist/src/layouts/force-directed/arf.js +103 -0
  64. package/dist/src/layouts/force-directed/arf.js.map +1 -0
  65. package/dist/src/layouts/force-directed/forceatlas2.d.ts +22 -0
  66. package/dist/src/layouts/force-directed/forceatlas2.js +322 -0
  67. package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -0
  68. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +19 -0
  69. package/dist/src/layouts/force-directed/fruchterman-reingold.js +131 -0
  70. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -0
  71. package/dist/src/layouts/force-directed/index.d.ts +8 -0
  72. package/dist/src/layouts/force-directed/index.js +9 -0
  73. package/dist/src/layouts/force-directed/index.js.map +1 -0
  74. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +15 -0
  75. package/dist/src/layouts/force-directed/kamada-kawai.js +87 -0
  76. package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -0
  77. package/dist/src/layouts/force-directed/spring.d.ts +19 -0
  78. package/dist/src/layouts/force-directed/spring.js +23 -0
  79. package/dist/src/layouts/force-directed/spring.js.map +1 -0
  80. package/dist/src/layouts/geometric/circular.d.ts +14 -0
  81. package/dist/src/layouts/geometric/circular.js +67 -0
  82. package/dist/src/layouts/geometric/circular.js.map +1 -0
  83. package/dist/src/layouts/geometric/index.d.ts +6 -0
  84. package/dist/src/layouts/geometric/index.js +7 -0
  85. package/dist/src/layouts/geometric/index.js.map +1 -0
  86. package/dist/src/layouts/geometric/shell.d.ts +15 -0
  87. package/dist/src/layouts/geometric/shell.js +67 -0
  88. package/dist/src/layouts/geometric/shell.js.map +1 -0
  89. package/dist/src/layouts/geometric/spiral.d.ts +16 -0
  90. package/dist/src/layouts/geometric/spiral.js +73 -0
  91. package/dist/src/layouts/geometric/spiral.js.map +1 -0
  92. package/dist/src/layouts/hierarchical/bfs.d.ts +12 -0
  93. package/dist/src/layouts/hierarchical/bfs.js +62 -0
  94. package/dist/src/layouts/hierarchical/bfs.js.map +1 -0
  95. package/dist/src/layouts/hierarchical/bipartite.d.ts +16 -0
  96. package/dist/src/layouts/hierarchical/bipartite.js +72 -0
  97. package/dist/src/layouts/hierarchical/bipartite.js.map +1 -0
  98. package/dist/src/layouts/hierarchical/index.d.ts +6 -0
  99. package/dist/src/layouts/hierarchical/index.js +7 -0
  100. package/dist/src/layouts/hierarchical/index.js.map +1 -0
  101. package/dist/src/layouts/hierarchical/multipartite.d.ts +12 -0
  102. package/dist/src/layouts/hierarchical/multipartite.js +73 -0
  103. package/dist/src/layouts/hierarchical/multipartite.js.map +1 -0
  104. package/dist/src/layouts/index.d.ts +8 -0
  105. package/dist/src/layouts/index.js +9 -0
  106. package/dist/src/layouts/index.js.map +1 -0
  107. package/dist/src/layouts/specialized/index.d.ts +5 -0
  108. package/dist/src/layouts/specialized/index.js +6 -0
  109. package/dist/src/layouts/specialized/index.js.map +1 -0
  110. package/dist/src/layouts/specialized/planar.d.ts +14 -0
  111. package/dist/src/layouts/specialized/planar.js +47 -0
  112. package/dist/src/layouts/specialized/planar.js.map +1 -0
  113. package/dist/src/layouts/specialized/spectral.d.ts +14 -0
  114. package/dist/src/layouts/specialized/spectral.js +106 -0
  115. package/dist/src/layouts/specialized/spectral.js.map +1 -0
  116. package/dist/src/types/embedding.d.ts +9 -0
  117. package/dist/src/types/embedding.js +5 -0
  118. package/dist/src/types/embedding.js.map +1 -0
  119. package/dist/src/types/graph.d.ts +10 -0
  120. package/dist/src/types/graph.js +5 -0
  121. package/dist/src/types/graph.js.map +1 -0
  122. package/dist/src/types/index.d.ts +6 -0
  123. package/dist/src/types/index.js +7 -0
  124. package/dist/src/types/index.js.map +1 -0
  125. package/dist/src/types/layout.d.ts +6 -0
  126. package/dist/src/types/layout.js +5 -0
  127. package/dist/src/types/layout.js.map +1 -0
  128. package/dist/src/utils/graph.d.ts +34 -0
  129. package/dist/src/utils/graph.js +69 -0
  130. package/dist/src/utils/graph.js.map +1 -0
  131. package/dist/src/utils/index.d.ts +8 -0
  132. package/dist/src/utils/index.js +9 -0
  133. package/dist/src/utils/index.js.map +1 -0
  134. package/dist/src/utils/numpy.d.ts +17 -0
  135. package/dist/src/utils/numpy.js +101 -0
  136. package/dist/src/utils/numpy.js.map +1 -0
  137. package/dist/src/utils/params.d.ts +17 -0
  138. package/dist/src/utils/params.js +22 -0
  139. package/dist/src/utils/params.js.map +1 -0
  140. package/dist/src/utils/random.d.ts +14 -0
  141. package/dist/src/utils/random.js +42 -0
  142. package/dist/src/utils/random.js.map +1 -0
  143. package/dist/src/utils/rescale.d.ts +21 -0
  144. package/dist/src/utils/rescale.js +119 -0
  145. package/dist/src/utils/rescale.js.map +1 -0
  146. package/dist/vitest.config.js +1 -1
  147. package/dist/vitest.config.js.map +1 -1
  148. package/package.json +15 -1
  149. package/.env.example +0 -11
  150. package/.github/workflows/ci.yml +0 -101
  151. package/.releaserc.json +0 -22
  152. package/CHANGELOG.md +0 -45
  153. package/CLAUDE.md +0 -104
  154. package/CONTRIBUTING.md +0 -1
  155. package/DEPLOYMENT.md +0 -59
  156. package/commitlint.config.js +0 -37
  157. package/examples/3d-force-directed.html +0 -611
  158. package/examples/3d-kamada-kawai.html +0 -379
  159. package/examples/3d-layout-comparison.html +0 -448
  160. package/examples/3d-spherical-layout.html +0 -319
  161. package/examples/arf-layout.html +0 -524
  162. package/examples/bfs-layout.html +0 -487
  163. package/examples/bipartite-layout.html +0 -382
  164. package/examples/circular-layout.html +0 -292
  165. package/examples/forceatlas2-layout.html +0 -588
  166. package/examples/index.html +0 -241
  167. package/examples/kamada-kawai-layout.html +0 -425
  168. package/examples/layout-helpers.js +0 -486
  169. package/examples/multipartite-layout.html +0 -410
  170. package/examples/planar-layout.html +0 -388
  171. package/examples/random-layout.html +0 -328
  172. package/examples/shell-layout.html +0 -323
  173. package/examples/spectral-layout.html +0 -335
  174. package/examples/spiral-layout.html +0 -447
  175. package/examples/spring-layout.html +0 -313
  176. package/test/arf-layout.test.ts +0 -443
  177. package/test/bfs-layout.test.ts +0 -427
  178. package/test/bipartite-layout.test.ts +0 -344
  179. package/test/circular-layout.test.ts +0 -442
  180. package/test/forceatlas2-layout.test.ts +0 -405
  181. package/test/fruchterman-reingold-layout.test.ts +0 -477
  182. package/test/graph-generators.test.ts +0 -450
  183. package/test/kamada-kawai-layout.test.ts +0 -623
  184. package/test/multipartite-layout.test.ts +0 -404
  185. package/test/planar-layout.test.ts +0 -266
  186. package/test/random-layout.test.ts +0 -254
  187. package/test/rescale-layout.test.ts +0 -373
  188. package/test/shell-layout.test.ts +0 -347
  189. package/test/spectral-layout.test.ts +0 -378
  190. package/test/spiral-layout.test.ts +0 -338
  191. package/test/spring-layout.test.ts +0 -241
  192. package/test/test-utils.ts +0 -34
  193. package/test/utils-graph.test.ts +0 -155
  194. package/test/utils-index.test.ts +0 -77
  195. package/test/utils-numpy.test.ts +0 -272
  196. package/test/utils-params.test.ts +0 -99
  197. package/test/utils-random.test.ts +0 -229
  198. package/tsconfig.json +0 -16
  199. package/vite.config.js +0 -36
  200. package/vitest.config.ts +0 -30
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Re-export all layout algorithms
3
+ */
4
+ export * from './basic';
5
+ export * from './geometric';
6
+ export * from './force-directed';
7
+ export * from './hierarchical';
8
+ export * from './specialized';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Re-export all layout algorithms
3
+ */
4
+ export * from './basic';
5
+ export * from './geometric';
6
+ export * from './force-directed';
7
+ export * from './hierarchical';
8
+ export * from './specialized';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layouts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Specialized layout algorithms
3
+ */
4
+ export { spectralLayout } from './spectral';
5
+ export { planarLayout } from './planar';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Specialized layout algorithms
3
+ */
4
+ export { spectralLayout } from './spectral';
5
+ export { planarLayout } from './planar';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Planar layout algorithm
3
+ */
4
+ import { Graph, PositionMap } from '../../types';
5
+ /**
6
+ * Position nodes without edge intersections (planar layout).
7
+ *
8
+ * @param G - Graph
9
+ * @param scale - Scale factor for positions
10
+ * @param center - Coordinate pair around which to center the layout
11
+ * @param dim - Dimension of layout (must be 2)
12
+ * @returns Positions dictionary keyed by node
13
+ */
14
+ export declare function planarLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number): PositionMap;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Planar layout algorithm
3
+ */
4
+ import { _processParams } from '../../utils/params';
5
+ import { getNodesFromGraph, getEdgesFromGraph } from '../../utils/graph';
6
+ import { rescaleLayout } from '../../utils/rescale';
7
+ import { checkPlanarity, combinatorialEmbeddingToPos } from '../../algorithms/planarity';
8
+ /**
9
+ * Position nodes without edge intersections (planar layout).
10
+ *
11
+ * @param G - Graph
12
+ * @param scale - Scale factor for positions
13
+ * @param center - Coordinate pair around which to center the layout
14
+ * @param dim - Dimension of layout (must be 2)
15
+ * @returns Positions dictionary keyed by node
16
+ */
17
+ export function planarLayout(G, scale = 1, center = null, dim = 2) {
18
+ if (dim !== 2) {
19
+ throw new Error("can only handle 2 dimensions");
20
+ }
21
+ const processed = _processParams(G, center || [0, 0], dim);
22
+ // Planar layout requires a proper Graph, not just a list of nodes
23
+ if (Array.isArray(processed.G)) {
24
+ throw new Error('Planar layout requires a Graph with edges, not just a list of nodes');
25
+ }
26
+ const graph = processed.G;
27
+ center = processed.center;
28
+ const nodes = getNodesFromGraph(graph);
29
+ const edges = getEdgesFromGraph(graph);
30
+ if (nodes.length === 0) {
31
+ return {};
32
+ }
33
+ // Check if graph is planar and get embedding
34
+ const { isPlanar, embedding } = checkPlanarity(graph, nodes, edges);
35
+ if (!isPlanar) {
36
+ throw new Error("G is not planar.");
37
+ }
38
+ if (!embedding) {
39
+ throw new Error("Failed to generate planar embedding.");
40
+ }
41
+ // Convert embedding to positions
42
+ let pos = combinatorialEmbeddingToPos(embedding, nodes);
43
+ // Rescale the positions
44
+ pos = rescaleLayout(pos, scale, center);
45
+ return pos;
46
+ }
47
+ //# sourceMappingURL=planar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planar.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/planar.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzF;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,CAAQ,EACR,QAAgB,CAAC,EACjB,SAA0B,IAAI,EAC9B,MAAc,CAAC;IAEf,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE3D,kEAAkE;IAClE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAE1B,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAEvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,6CAA6C;IAC7C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAEpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,iCAAiC;IACjC,IAAI,GAAG,GAAG,2BAA2B,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAExD,wBAAwB;IACxB,GAAG,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAgB,CAAC;IAEvD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Spectral layout algorithm using eigenvectors of the graph Laplacian
3
+ */
4
+ import { Graph, PositionMap } from '../../types';
5
+ /**
6
+ * Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
7
+ *
8
+ * @param G - Graph
9
+ * @param scale - Scale factor for positions
10
+ * @param center - Coordinate pair around which to center the layout
11
+ * @param dim - Dimension of layout
12
+ * @returns Positions dictionary keyed by node
13
+ */
14
+ export declare function spectralLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number): PositionMap;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Spectral layout algorithm using eigenvectors of the graph Laplacian
3
+ */
4
+ import { _processParams } from '../../utils/params';
5
+ import { getNodesFromGraph, getEdgesFromGraph } from '../../utils/graph';
6
+ import { rescaleLayout } from '../../utils/rescale';
7
+ /**
8
+ * Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
9
+ *
10
+ * @param G - Graph
11
+ * @param scale - Scale factor for positions
12
+ * @param center - Coordinate pair around which to center the layout
13
+ * @param dim - Dimension of layout
14
+ * @returns Positions dictionary keyed by node
15
+ */
16
+ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
17
+ const processed = _processParams(G, center, dim);
18
+ const graph = processed.G;
19
+ center = processed.center;
20
+ const nodes = getNodesFromGraph(graph);
21
+ if (nodes.length <= 2) {
22
+ if (nodes.length === 0) {
23
+ return {};
24
+ }
25
+ else if (nodes.length === 1) {
26
+ return { [nodes[0]]: center };
27
+ }
28
+ else {
29
+ return {
30
+ [nodes[0]]: center.map(v => v - scale),
31
+ [nodes[1]]: center.map(v => v + scale)
32
+ };
33
+ }
34
+ }
35
+ // Create adjacency matrix
36
+ const N = nodes.length;
37
+ const nodeIndices = {};
38
+ nodes.forEach((node, i) => { nodeIndices[node] = i; });
39
+ const A = Array(N).fill(0).map(() => Array(N).fill(0));
40
+ const edges = getEdgesFromGraph(graph);
41
+ for (const [source, target] of edges) {
42
+ const i = nodeIndices[source];
43
+ const j = nodeIndices[target];
44
+ A[i][j] = 1;
45
+ A[j][i] = 1; // Make symmetric for undirected graphs
46
+ }
47
+ // Create Laplacian matrix: L = D - A where D is degree matrix
48
+ const L = Array(N).fill(0).map(() => Array(N).fill(0));
49
+ for (let i = 0; i < N; i++) {
50
+ // Compute degree (sum of row)
51
+ L[i][i] = A[i].reduce((sum, val) => sum + val, 0);
52
+ for (let j = 0; j < N; j++) {
53
+ L[i][j] -= A[i][j];
54
+ }
55
+ }
56
+ // Compute eigenvectors using power iteration method
57
+ // We need the smallest non-zero eigenvectors of L
58
+ const eigenvectors = [];
59
+ // For each dimension, find an eigenvector
60
+ for (let d = 0; d < dim; d++) {
61
+ let vector = Array(N).fill(0).map(() => Math.random() - 0.5);
62
+ // Orthogonalize against previous eigenvectors
63
+ for (const ev of eigenvectors) {
64
+ const dot = vector.reduce((acc, val, idx) => acc + val * ev[idx], 0);
65
+ vector = vector.map((val, idx) => val - dot * ev[idx]);
66
+ }
67
+ // Normalize
68
+ const norm = Math.sqrt(vector.reduce((acc, val) => acc + val * val, 0));
69
+ vector = vector.map(val => val / norm);
70
+ // Apply shifted inverse iteration to find smallest non-zero eigenvector
71
+ // This is a simplification of the actual algorithm
72
+ for (let iter = 0; iter < 100; iter++) {
73
+ // Apply Laplacian
74
+ const newVec = Array(N).fill(0);
75
+ for (let i = 0; i < N; i++) {
76
+ for (let j = 0; j < N; j++) {
77
+ newVec[i] += L[i][j] * vector[j];
78
+ }
79
+ }
80
+ // Orthogonalize against the constant vector (eigenvector with eigenvalue 0)
81
+ const mean = newVec.reduce((acc, val) => acc + val, 0) / N;
82
+ newVec.forEach((val, idx, arr) => { arr[idx] = val - mean; });
83
+ // Normalize
84
+ const newNorm = Math.sqrt(newVec.reduce((acc, val) => acc + val * val, 0));
85
+ if (newNorm < 1e-10)
86
+ continue; // Skip if vector is close to zero
87
+ vector = newVec.map(val => val / newNorm);
88
+ }
89
+ eigenvectors.push(vector);
90
+ }
91
+ // Create position array from eigenvectors
92
+ const positions = Array(N).fill(0).map(() => Array(dim).fill(0));
93
+ for (let i = 0; i < N; i++) {
94
+ for (let d = 0; d < dim; d++) {
95
+ positions[i][d] = eigenvectors[d][i];
96
+ }
97
+ }
98
+ // Rescale and create position dictionary
99
+ const scaledPositions = rescaleLayout(positions, scale);
100
+ const pos = {};
101
+ nodes.forEach((node, i) => {
102
+ pos[node] = scaledPositions[i].map((val, j) => val + center[j]);
103
+ });
104
+ return pos;
105
+ }
106
+ //# sourceMappingURL=spectral.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spectral.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/spectral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,E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AG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,yCAAyC;IACzC,MAAM,eAAe,GAAG,aAAa,CAAC,SAAgB,EAAE,KAAK,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,CAAS,EAAE,EAAE;QACtC,GAAG,CAAC,IAAI,CAAC,GAAI,eAA8B,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Embedding type for planar layout algorithms
3
+ */
4
+ import { Node, Position } from './index';
5
+ export interface Embedding {
6
+ nodeOrder: Node[];
7
+ faceList: Node[][];
8
+ nodePositions: Record<Node, Position>;
9
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Embedding type for planar layout algorithms
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=embedding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embedding.js","sourceRoot":"","sources":["../../../src/types/embedding.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Core graph type definitions
3
+ */
4
+ export type Node = string | number;
5
+ export type Edge = [Node, Node];
6
+ export type Graph = {
7
+ nodes: () => Node[];
8
+ edges: () => Edge[];
9
+ getEdgeData?: (source: Node, target: Node, attr: string) => any;
10
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Core graph type definitions
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../../src/types/graph.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Re-export all type definitions
3
+ */
4
+ export * from './graph';
5
+ export * from './layout';
6
+ export * from './embedding';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-export all type definitions
3
+ */
4
+ export * from './graph';
5
+ export * from './layout';
6
+ export * from './embedding';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Layout-specific type definitions
3
+ */
4
+ import { Node } from './graph';
5
+ export type Position = number[];
6
+ export type PositionMap = Record<Node, Position>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Layout-specific type definitions
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/types/layout.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Graph utility functions
3
+ */
4
+ import { Graph, Node, Edge } from '../types';
5
+ /**
6
+ * Extract nodes from a graph object
7
+ *
8
+ * @param G - Graph or list of nodes
9
+ * @returns Array of nodes
10
+ */
11
+ export declare function getNodesFromGraph(G: Graph | Node[]): Node[];
12
+ /**
13
+ * Extract edges from a graph object
14
+ *
15
+ * @param G - Graph or list of nodes
16
+ * @returns Array of edges
17
+ */
18
+ export declare function getEdgesFromGraph(G: Graph | Node[]): Edge[];
19
+ /**
20
+ * Get the degree of a node in the graph
21
+ *
22
+ * @param graph - Graph object
23
+ * @param node - Node to get degree for
24
+ * @returns Degree of the node
25
+ */
26
+ export declare function getNodeDegree(graph: Graph, node: Node): number;
27
+ /**
28
+ * Get the neighbors of a node in the graph
29
+ *
30
+ * @param graph - Graph object
31
+ * @param node - Node to get neighbors for
32
+ * @returns Array of neighbor nodes
33
+ */
34
+ export declare function getNeighbors(graph: Graph, node: Node): Node[];
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Graph utility functions
3
+ */
4
+ /**
5
+ * Extract nodes from a graph object
6
+ *
7
+ * @param G - Graph or list of nodes
8
+ * @returns Array of nodes
9
+ */
10
+ export function getNodesFromGraph(G) {
11
+ if (Array.isArray(G)) {
12
+ return G;
13
+ }
14
+ return G.nodes();
15
+ }
16
+ /**
17
+ * Extract edges from a graph object
18
+ *
19
+ * @param G - Graph or list of nodes
20
+ * @returns Array of edges
21
+ */
22
+ export function getEdgesFromGraph(G) {
23
+ if (Array.isArray(G)) {
24
+ return [];
25
+ }
26
+ return G.edges();
27
+ }
28
+ /**
29
+ * Get the degree of a node in the graph
30
+ *
31
+ * @param graph - Graph object
32
+ * @param node - Node to get degree for
33
+ * @returns Degree of the node
34
+ */
35
+ export function getNodeDegree(graph, node) {
36
+ if (!graph.edges)
37
+ return 0;
38
+ const edges = graph.edges();
39
+ let degree = 0;
40
+ for (const [source, target] of edges) {
41
+ if (source === node || target === node) {
42
+ degree++;
43
+ }
44
+ }
45
+ return degree;
46
+ }
47
+ /**
48
+ * Get the neighbors of a node in the graph
49
+ *
50
+ * @param graph - Graph object
51
+ * @param node - Node to get neighbors for
52
+ * @returns Array of neighbor nodes
53
+ */
54
+ export function getNeighbors(graph, node) {
55
+ if (!graph.edges)
56
+ return [];
57
+ const neighbors = new Set();
58
+ const edges = graph.edges();
59
+ for (const [source, target] of edges) {
60
+ if (source === node) {
61
+ neighbors.add(target);
62
+ }
63
+ else if (target === node) {
64
+ neighbors.add(source);
65
+ }
66
+ }
67
+ return Array.from(neighbors);
68
+ }
69
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../../src/utils/graph.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAiB;IACjD,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAiB;IACjD,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,IAAU;IACpD,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IAE3B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACrC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACvC,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAY,EAAE,IAAU;IACnD,IAAI,CAAC,KAAK,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAE5B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAQ,CAAC;IAClC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAE5B,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACrC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAC3B,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Re-export all utilities
3
+ */
4
+ export * from './numpy';
5
+ export * from './random';
6
+ export * from './graph';
7
+ export * from './params';
8
+ export * from './rescale';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Re-export all utilities
3
+ */
4
+ export * from './numpy';
5
+ export * from './random';
6
+ export * from './graph';
7
+ export * from './params';
8
+ export * from './rescale';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * NumPy-like array manipulation functions
3
+ * Maintains exact same functionality as original implementation
4
+ */
5
+ export declare const np: {
6
+ zeros: (shape: number | number[]) => number | number[] | number[][] | any[];
7
+ ones: (shape: number | number[]) => number | any[];
8
+ linspace: (start: number, stop: number, num: number) => number[];
9
+ array: (arr: any) => any[];
10
+ repeat: (a: any, repeats: number) => any[];
11
+ mean: (arr: number[] | number[][], axis?: number | null) => number | number[];
12
+ add: (a: number | number[], b: number | number[]) => number | number[];
13
+ subtract: (a: number | number[], b: number | number[]) => number | number[];
14
+ max: (arr: number | number[]) => number;
15
+ min: (arr: number | number[]) => number;
16
+ norm: (arr: number[]) => number;
17
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * NumPy-like array manipulation functions
3
+ * Maintains exact same functionality as original implementation
4
+ */
5
+ export const np = {
6
+ zeros: function (shape) {
7
+ if (typeof shape === 'number') {
8
+ return Array(shape).fill(0);
9
+ }
10
+ if (shape.length === 1) {
11
+ return Array(shape[0]).fill(0);
12
+ }
13
+ return Array(shape[0]).fill(0).map(() => this.zeros(shape.slice(1)));
14
+ },
15
+ ones: function (shape) {
16
+ if (typeof shape === 'number') {
17
+ return Array(shape).fill(1);
18
+ }
19
+ if (shape.length === 1) {
20
+ return Array(shape[0]).fill(1);
21
+ }
22
+ return Array(shape[0]).fill(1).map(() => this.ones(shape.slice(1)));
23
+ },
24
+ linspace: function (start, stop, num) {
25
+ if (num === 1) {
26
+ return [start];
27
+ }
28
+ const step = (stop - start) / (num - 1);
29
+ return Array.from({ length: num }, (_, i) => start + i * step);
30
+ },
31
+ array: function (arr) {
32
+ return Array.isArray(arr) ? [...arr] : [arr];
33
+ },
34
+ repeat: function (a, repeats) {
35
+ const result = [];
36
+ for (let i = 0; i < repeats; i++) {
37
+ result.push(...np.array(a));
38
+ }
39
+ return result;
40
+ },
41
+ mean: function (arr, axis = null) {
42
+ if (axis === null) {
43
+ const flatArr = Array.isArray(arr[0])
44
+ ? arr.flat(Infinity)
45
+ : arr;
46
+ const sum = flatArr.reduce((a, b) => a + b, 0);
47
+ return sum / flatArr.length;
48
+ }
49
+ if (axis === 0) {
50
+ const result = [];
51
+ const matrix = arr;
52
+ for (let i = 0; i < matrix[0].length; i++) {
53
+ let sum = 0;
54
+ for (let j = 0; j < matrix.length; j++) {
55
+ sum += matrix[j][i];
56
+ }
57
+ result.push(sum / matrix.length);
58
+ }
59
+ return result;
60
+ }
61
+ return arr.map(row => np.mean(row));
62
+ },
63
+ add: function (a, b) {
64
+ if (!Array.isArray(a) && !Array.isArray(b)) {
65
+ return a + b;
66
+ }
67
+ if (!Array.isArray(a)) {
68
+ return b.map(val => a + val);
69
+ }
70
+ if (!Array.isArray(b)) {
71
+ return a.map(val => val + b);
72
+ }
73
+ return a.map((val, i) => val + b[i]);
74
+ },
75
+ subtract: function (a, b) {
76
+ if (!Array.isArray(a) && !Array.isArray(b)) {
77
+ return a - b;
78
+ }
79
+ if (!Array.isArray(a)) {
80
+ return b.map(val => a - val);
81
+ }
82
+ if (!Array.isArray(b)) {
83
+ return a.map(val => val - b);
84
+ }
85
+ return a.map((val, i) => val - b[i]);
86
+ },
87
+ max: function (arr) {
88
+ if (!Array.isArray(arr))
89
+ return arr;
90
+ return Math.max(...arr.flat(Infinity));
91
+ },
92
+ min: function (arr) {
93
+ if (!Array.isArray(arr))
94
+ return arr;
95
+ return Math.min(...arr.flat(Infinity));
96
+ },
97
+ norm: function (arr) {
98
+ return Math.sqrt(arr.reduce((sum, val) => sum + val * val, 0));
99
+ }
100
+ };
101
+ //# sourceMappingURL=numpy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numpy.js","sourceRoot":"","sources":["../../../src/utils/numpy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,KAAK,EAAE,UAAU,KAAwB;QACvC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,C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CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,OAAQ,CAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,OAAQ,CAAc,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAI,CAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,GAAG,EAAE,UAAU,GAAsB;QACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAI,GAAgB,CAAC,IAAI,CAAC,QAAQ,CAAa,CAAC,CAAC;IACnE,CAAC;IAED,GAAG,EAAE,UAAU,GAAsB;QACnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC;QACpC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAI,GAAgB,CAAC,IAAI,CAAC,QAAQ,CAAa,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,EAAE,UAAU,GAAa;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;CACF,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Parameter processing utilities
3
+ */
4
+ import { Graph, Node } from '../types';
5
+ /**
6
+ * Process and validate layout parameters
7
+ * Helper function similar to _process_params in Python version
8
+ *
9
+ * @param G - Graph object or array of nodes
10
+ * @param center - Center coordinates or null
11
+ * @param dim - Dimension of layout
12
+ * @returns Processed parameters
13
+ */
14
+ export declare function _processParams(G: Graph | Node[], center: number[] | null, dim: number): {
15
+ G: Graph | Node[];
16
+ center: number[];
17
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Parameter processing utilities
3
+ */
4
+ /**
5
+ * Process and validate layout parameters
6
+ * Helper function similar to _process_params in Python version
7
+ *
8
+ * @param G - Graph object or array of nodes
9
+ * @param center - Center coordinates or null
10
+ * @param dim - Dimension of layout
11
+ * @returns Processed parameters
12
+ */
13
+ export function _processParams(G, center, dim) {
14
+ if (!center) {
15
+ center = Array(dim).fill(0);
16
+ }
17
+ if (center.length !== dim) {
18
+ throw new Error("length of center coordinates must match dimension of layout");
19
+ }
20
+ return { G, center };
21
+ }
22
+ //# sourceMappingURL=params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../../src/utils/params.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,CAAiB,EAAE,MAAuB,EAAE,GAAW;IACpF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Random number generator for seed-based randomization
3
+ * Maintains exact same functionality as original implementation
4
+ */
5
+ export declare class RandomNumberGenerator {
6
+ private seed;
7
+ private m;
8
+ private a;
9
+ private c;
10
+ private _state;
11
+ constructor(seed?: number);
12
+ _next(): number;
13
+ rand(shape?: number | number[] | null): number | number[] | number[][];
14
+ }