vue-hook-optimizer 0.0.70 → 0.0.72-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SFCStyleBlock } from '@vue/compiler-sfc';
2
2
  export { parse } from '@vue/compiler-sfc';
3
- import { Node, Edge } from 'vis-network';
3
+ import { Edge, Node } from 'vis-network';
4
4
 
5
5
  interface TypedNode {
6
6
  label: string;
@@ -20,14 +20,20 @@ declare enum NodeType {
20
20
  declare function analyze$4(content: string, lineOffset?: number, jsx?: boolean): {
21
21
  graph: {
22
22
  nodes: Set<TypedNode>;
23
- edges: Map<TypedNode, Set<TypedNode>>;
23
+ edges: Map<TypedNode, Set<{
24
+ node: TypedNode;
25
+ type: "get" | "set";
26
+ }>>;
24
27
  };
25
28
  nodesUsedInTemplate: Set<string>;
26
29
  };
27
30
 
28
31
  declare function analyze$3(content: string, lineOffset?: number, jsx?: boolean): {
29
32
  nodes: Set<TypedNode>;
30
- edges: Map<TypedNode, Set<TypedNode>>;
33
+ edges: Map<TypedNode, Set<{
34
+ node: TypedNode;
35
+ type: "get" | "set";
36
+ }>>;
31
37
  };
32
38
 
33
39
  declare function analyze$2(styles: SFCStyleBlock[]): Set<string>;
@@ -37,7 +43,10 @@ declare function analyze$1(content: string): Set<string>;
37
43
  declare function analyze(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
38
44
  graph: {
39
45
  nodes: Set<TypedNode>;
40
- edges: Map<TypedNode, Set<TypedNode>>;
46
+ edges: Map<TypedNode, Set<{
47
+ node: TypedNode;
48
+ type: "get" | "set";
49
+ }>>;
41
50
  };
42
51
  nodesUsedInTemplate: Set<string>;
43
52
  };
@@ -62,7 +71,10 @@ interface Suggestion {
62
71
  }
63
72
  declare function gen(graph: {
64
73
  nodes: Set<TypedNode>;
65
- edges: Map<TypedNode, Set<TypedNode>>;
74
+ edges: Map<TypedNode, Set<{
75
+ node: TypedNode;
76
+ type: 'get' | 'set';
77
+ }>>;
66
78
  }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): Suggestion[];
67
79
 
68
80
  type CustomNode = Node & {
@@ -70,7 +82,10 @@ type CustomNode = Node & {
70
82
  };
71
83
  declare function getVisData(graph: {
72
84
  nodes: Set<TypedNode>;
73
- edges: Map<TypedNode, Set<TypedNode>>;
85
+ edges: Map<TypedNode, Set<{
86
+ node: TypedNode;
87
+ type: 'get' | 'set';
88
+ }>>;
74
89
  }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): {
75
90
  nodes: CustomNode[];
76
91
  edges: Edge[];
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SFCStyleBlock } from '@vue/compiler-sfc';
2
2
  export { parse } from '@vue/compiler-sfc';
3
- import { Node, Edge } from 'vis-network';
3
+ import { Edge, Node } from 'vis-network';
4
4
 
5
5
  interface TypedNode {
6
6
  label: string;
@@ -20,14 +20,20 @@ declare enum NodeType {
20
20
  declare function analyze$4(content: string, lineOffset?: number, jsx?: boolean): {
21
21
  graph: {
22
22
  nodes: Set<TypedNode>;
23
- edges: Map<TypedNode, Set<TypedNode>>;
23
+ edges: Map<TypedNode, Set<{
24
+ node: TypedNode;
25
+ type: "get" | "set";
26
+ }>>;
24
27
  };
25
28
  nodesUsedInTemplate: Set<string>;
26
29
  };
27
30
 
28
31
  declare function analyze$3(content: string, lineOffset?: number, jsx?: boolean): {
29
32
  nodes: Set<TypedNode>;
30
- edges: Map<TypedNode, Set<TypedNode>>;
33
+ edges: Map<TypedNode, Set<{
34
+ node: TypedNode;
35
+ type: "get" | "set";
36
+ }>>;
31
37
  };
32
38
 
33
39
  declare function analyze$2(styles: SFCStyleBlock[]): Set<string>;
@@ -37,7 +43,10 @@ declare function analyze$1(content: string): Set<string>;
37
43
  declare function analyze(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): {
38
44
  graph: {
39
45
  nodes: Set<TypedNode>;
40
- edges: Map<TypedNode, Set<TypedNode>>;
46
+ edges: Map<TypedNode, Set<{
47
+ node: TypedNode;
48
+ type: "get" | "set";
49
+ }>>;
41
50
  };
42
51
  nodesUsedInTemplate: Set<string>;
43
52
  };
@@ -62,7 +71,10 @@ interface Suggestion {
62
71
  }
63
72
  declare function gen(graph: {
64
73
  nodes: Set<TypedNode>;
65
- edges: Map<TypedNode, Set<TypedNode>>;
74
+ edges: Map<TypedNode, Set<{
75
+ node: TypedNode;
76
+ type: 'get' | 'set';
77
+ }>>;
66
78
  }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): Suggestion[];
67
79
 
68
80
  type CustomNode = Node & {
@@ -70,7 +82,10 @@ type CustomNode = Node & {
70
82
  };
71
83
  declare function getVisData(graph: {
72
84
  nodes: Set<TypedNode>;
73
- edges: Map<TypedNode, Set<TypedNode>>;
85
+ edges: Map<TypedNode, Set<{
86
+ node: TypedNode;
87
+ type: 'get' | 'set';
88
+ }>>;
74
89
  }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): {
75
90
  nodes: CustomNode[];
76
91
  edges: Edge[];
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  NodeType: () => NodeType,
34
34
  SuggestionType: () => SuggestionType,
35
35
  analyzeOptions: () => analyze2,
@@ -42,7 +42,7 @@ __export(index_exports, {
42
42
  getVisData: () => getVisData,
43
43
  parse: () => import_compiler_sfc5.parse
44
44
  });
45
- module.exports = __toCommonJS(index_exports);
45
+ module.exports = __toCommonJS(src_exports);
46
46
 
47
47
  // src/analyze/options.ts
48
48
  var import_traverse2 = __toESM(require("@babel/traverse"));
@@ -123,9 +123,19 @@ var NodeCollection = class {
123
123
  return this.nodes.get(node);
124
124
  }).filter((node) => !!node));
125
125
  const edges = new Map(Array.from(graph.edges).map(([from, to]) => {
126
- return [this.nodes.get(from), new Set(Array.from(to).map((node) => {
127
- return this.nodes.get(node);
128
- }).filter((node) => !!node))];
126
+ const labelMap = /* @__PURE__ */ new Map();
127
+ for (const item of to) {
128
+ const node = this.nodes.get(item.label);
129
+ if (!node) {
130
+ continue;
131
+ }
132
+ const existing = labelMap.get(item.label);
133
+ if (!existing || existing.type === "get" && item.type === "set") {
134
+ labelMap.set(item.label, { node, type: item.type });
135
+ }
136
+ }
137
+ const items = Array.from(labelMap.values());
138
+ return [this.nodes.get(from), new Set(items)];
129
139
  }));
130
140
  return {
131
141
  nodes,
@@ -158,6 +168,23 @@ function getComment(node) {
158
168
  });
159
169
  return comment.trim();
160
170
  }
171
+ function isWritingNode(path) {
172
+ const assignParent = path.findParent((p) => p.isAssignmentExpression());
173
+ if (assignParent) {
174
+ const leftNode = assignParent.node.left;
175
+ if (leftNode.start != null && path.node.start >= leftNode.start && path.node.end <= leftNode.end) {
176
+ return true;
177
+ }
178
+ }
179
+ const updateParent = path.findParent((p) => p.isUpdateExpression());
180
+ if (updateParent) {
181
+ const argNode = updateParent.node.argument;
182
+ if (argNode.start != null && path.node.start >= argNode.start && path.node.end <= argNode.end) {
183
+ return true;
184
+ }
185
+ }
186
+ return false;
187
+ }
161
188
 
162
189
  // src/analyze/setupScript.ts
163
190
  var traverse = import_traverse.default.default?.default || import_traverse.default.default || import_traverse.default;
@@ -409,7 +436,10 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
409
436
  const watchArgsNames = Array.from(watchArgs).map((arg) => arg.name);
410
437
  watchArgs.forEach((watchArg) => {
411
438
  if (!watchArgsNames.includes(path1.node.name)) {
412
- graph.edges.get(watchArg.name)?.add(path1.node.name);
439
+ graph.edges.get(watchArg.name)?.add({
440
+ label: path1.node.name,
441
+ type: isWritingNode(path1) ? "set" : "get"
442
+ });
413
443
  }
414
444
  });
415
445
  }
@@ -437,14 +467,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
437
467
  Identifier(path1) {
438
468
  const binding = path1.scope.getBinding(path1.node.name);
439
469
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
440
- graph.edges.get(name)?.add(path1.node.name);
470
+ graph.edges.get(name)?.add({
471
+ label: path1.node.name,
472
+ type: isWritingNode(path1) ? "set" : "get"
473
+ });
441
474
  }
442
475
  },
443
476
  MemberExpression(path1) {
444
477
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
445
478
  const binding = path1.scope.getBinding(path1.node.object.name);
446
479
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
447
- graph.edges.get(name)?.add(path1.node.property.name);
480
+ graph.edges.get(name)?.add({
481
+ label: path1.node.property.name,
482
+ type: isWritingNode(path1) ? "set" : "get"
483
+ });
448
484
  }
449
485
  }
450
486
  }
@@ -462,14 +498,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
462
498
  Identifier(path1) {
463
499
  const binding = path1.scope.getBinding(path1.node.name);
464
500
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
465
- graph.edges.get(name)?.add(path1.node.name);
501
+ graph.edges.get(name)?.add({
502
+ label: path1.node.name,
503
+ type: isWritingNode(path1) ? "set" : "get"
504
+ });
466
505
  }
467
506
  },
468
507
  MemberExpression(path1) {
469
508
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
470
509
  const binding = path1.scope.getBinding(path1.node.object.name);
471
510
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
472
- graph.edges.get(name)?.add(path1.node.property.name);
511
+ graph.edges.get(name)?.add({
512
+ label: path1.node.property.name,
513
+ type: isWritingNode(path1) ? "set" : "get"
514
+ });
473
515
  }
474
516
  }
475
517
  }
@@ -486,14 +528,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
486
528
  Identifier(path1) {
487
529
  const binding = path1.scope.getBinding(path1.node.name);
488
530
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
489
- graph.edges.get(name)?.add(path1.node.name);
531
+ graph.edges.get(name)?.add({
532
+ label: path1.node.name,
533
+ type: isWritingNode(path1) ? "set" : "get"
534
+ });
490
535
  }
491
536
  },
492
537
  MemberExpression(path1) {
493
538
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
494
539
  const binding = path1.scope.getBinding(path1.node.object.name);
495
540
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
496
- graph.edges.get(name)?.add(path1.node.property.name);
541
+ graph.edges.get(name)?.add({
542
+ label: path1.node.property.name,
543
+ type: isWritingNode(path1) ? "set" : "get"
544
+ });
497
545
  }
498
546
  }
499
547
  }
@@ -515,14 +563,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
515
563
  Identifier(path1) {
516
564
  const binding = path1.scope.getBinding(path1.node.name);
517
565
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
518
- graph.edges.get(name)?.add(path1.node.name);
566
+ graph.edges.get(name)?.add({
567
+ label: path1.node.name,
568
+ type: isWritingNode(path1) ? "set" : "get"
569
+ });
519
570
  }
520
571
  },
521
572
  MemberExpression(path1) {
522
573
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
523
574
  const binding = path1.scope.getBinding(path1.node.object.name);
524
575
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
525
- graph.edges.get(name)?.add(path1.node.property.name);
576
+ graph.edges.get(name)?.add({
577
+ label: path1.node.property.name,
578
+ type: isWritingNode(path1) ? "set" : "get"
579
+ });
526
580
  }
527
581
  }
528
582
  }
@@ -533,14 +587,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
533
587
  if (path.node.init.type === "Identifier") {
534
588
  const binding = path.scope.getBinding(path.node.init.name);
535
589
  if (graph.nodes.has(path.node.init.name) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
536
- graph.edges.get(name)?.add(path.node.init.name);
590
+ graph.edges.get(name)?.add({
591
+ label: path.node.init.name,
592
+ type: isWritingNode(path) ? "set" : "get"
593
+ });
537
594
  }
538
595
  } else {
539
596
  traverse(path.node.init, {
540
597
  Identifier(path1) {
541
598
  const binding = path1.scope.getBinding(path1.node.name);
542
599
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
543
- graph.edges.get(name)?.add(path1.node.name);
600
+ graph.edges.get(name)?.add({
601
+ label: path1.node.name,
602
+ type: isWritingNode(path1) ? "set" : "get"
603
+ });
544
604
  }
545
605
  }
546
606
  }, path.scope, path);
@@ -555,14 +615,20 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
555
615
  Identifier(path1) {
556
616
  const binding = path1.scope.getBinding(path1.node.name);
557
617
  if (graph.nodes.has(path1.node.name) && (path1.parent.type !== "MemberExpression" && path1.parent.type !== "OptionalMemberExpression" || path1.parent.object === path1.node) && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
558
- graph.edges.get(name)?.add(path1.node.name);
618
+ graph.edges.get(name)?.add({
619
+ label: path1.node.name,
620
+ type: isWritingNode(path1) ? "set" : "get"
621
+ });
559
622
  }
560
623
  },
561
624
  MemberExpression(path1) {
562
625
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
563
626
  const binding = path1.scope.getBinding(path1.node.object.name);
564
627
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
565
- graph.edges.get(name)?.add(path1.node.property.name);
628
+ graph.edges.get(name)?.add({
629
+ label: path1.node.property.name,
630
+ type: isWritingNode(path1) ? "set" : "get"
631
+ });
566
632
  }
567
633
  }
568
634
  }
@@ -577,7 +643,10 @@ function processSetup(ast, parentScope, parentPath, _spread, _lineOffset = 0) {
577
643
  if (path1.node.object.type === "Identifier" && spread.includes(path1.node.object.name)) {
578
644
  const binding = path1.scope.getBinding(path1.node.object.name);
579
645
  if (spread.includes(path1.node.object.name) && path1.node.property.type === "Identifier" && (binding?.scope.block.type === "Program" || parentScope === binding?.scope)) {
580
- graph.edges.get(name)?.add(path1.node.property.name);
646
+ graph.edges.get(name)?.add({
647
+ label: path1.node.property.name,
648
+ type: isWritingNode(path1) ? "set" : "get"
649
+ });
581
650
  }
582
651
  }
583
652
  }
@@ -818,7 +887,10 @@ function analyze2(content, lineOffset = 0, jsx = false) {
818
887
  nodeCollection.addNode(name, path3.node.key, {
819
888
  comment: getComment(path3.node)
820
889
  });
821
- graph.edges.set(name, /* @__PURE__ */ new Set([valName]));
890
+ graph.edges.set(name, /* @__PURE__ */ new Set([{
891
+ label: valName,
892
+ type: isWritingNode(path3) ? "set" : "get"
893
+ }]));
822
894
  }
823
895
  }
824
896
  }
@@ -938,7 +1010,10 @@ function analyze2(content, lineOffset = 0, jsx = false) {
938
1010
  traverse2(prop, {
939
1011
  MemberExpression(path2) {
940
1012
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
941
- graph.edges.get(name)?.add(path2.node.property.name);
1013
+ graph.edges.get(name)?.add({
1014
+ label: path2.node.property.name,
1015
+ type: isWritingNode(path2) ? "set" : "get"
1016
+ });
942
1017
  }
943
1018
  }
944
1019
  }, path1.scope, path1);
@@ -950,7 +1025,10 @@ function analyze2(content, lineOffset = 0, jsx = false) {
950
1025
  traverse2(prop1, {
951
1026
  MemberExpression(path2) {
952
1027
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
953
- graph.edges.get(name)?.add(path2.node.property.name);
1028
+ graph.edges.get(name)?.add({
1029
+ label: path2.node.property.name,
1030
+ type: isWritingNode(path2) ? "set" : "get"
1031
+ });
954
1032
  }
955
1033
  }
956
1034
  }, path1.scope, path1);
@@ -969,7 +1047,10 @@ function analyze2(content, lineOffset = 0, jsx = false) {
969
1047
  traverse2(prop, {
970
1048
  MemberExpression(path2) {
971
1049
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
972
- graph.edges.get(name)?.add(path2.node.property.name);
1050
+ graph.edges.get(name)?.add({
1051
+ label: path2.node.property.name,
1052
+ type: isWritingNode(path2) ? "set" : "get"
1053
+ });
973
1054
  }
974
1055
  }
975
1056
  }, path1.scope, path1);
@@ -997,7 +1078,10 @@ function analyze2(content, lineOffset = 0, jsx = false) {
997
1078
  MemberExpression(path2) {
998
1079
  if (path2.node.object.type === "ThisExpression" && path2.node.property.type === "Identifier") {
999
1080
  if (watchArg && watchArg.name !== path2.node.property.name) {
1000
- graph.edges.get(watchArg.name)?.add(path2.node.property.name);
1081
+ graph.edges.get(watchArg.name)?.add({
1082
+ label: path2.node.property.name,
1083
+ type: isWritingNode(path2) ? "set" : "get"
1084
+ });
1001
1085
  }
1002
1086
  }
1003
1087
  }
@@ -1555,7 +1639,10 @@ function addIdentifiesToGraphByScanReturn({ path: path1, graph, nodeCollection,
1555
1639
  nodeCollection.addNode(name, path3.node.key, {
1556
1640
  comment: getComment(path3.node)
1557
1641
  });
1558
- graph.edges.set(name, /* @__PURE__ */ new Set([valName]));
1642
+ graph.edges.set(name, /* @__PURE__ */ new Set([{
1643
+ label: valName,
1644
+ type: isWritingNode(path3) ? "set" : "get"
1645
+ }]));
1559
1646
  }
1560
1647
  }
1561
1648
  }
@@ -1714,7 +1801,10 @@ function processByReturnJSX(params) {
1714
1801
  function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
1715
1802
  const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
1716
1803
  if (scope === bindingScope && collectionNodes.has(toName)) {
1717
- graph.edges.get(fromName)?.add(toName);
1804
+ graph.edges.get(fromName)?.add({
1805
+ label: toName,
1806
+ type: isWritingNode(path) ? "set" : "get"
1807
+ });
1718
1808
  }
1719
1809
  }
1720
1810
  function addUsed({ name, path, parentPath: parentPath2 }) {
@@ -1833,7 +1923,10 @@ function processByReact(params) {
1833
1923
  function addEdge({ fromName, toName, path, scope, toScope, collectionNodes }) {
1834
1924
  const bindingScope = toScope || path.scope.getBinding(toName)?.scope;
1835
1925
  if (scope === bindingScope && collectionNodes.has(toName)) {
1836
- graph.edges.get(fromName)?.add(toName);
1926
+ graph.edges.get(fromName)?.add({
1927
+ label: toName,
1928
+ type: isWritingNode(path) ? "set" : "get"
1929
+ });
1837
1930
  }
1838
1931
  }
1839
1932
  function addUsed({ name, path, parentPath: parentPath2 }) {
@@ -2040,7 +2133,7 @@ function noIndegreeFilter(graph) {
2040
2133
  });
2041
2134
  graph.forEach((targets, node) => {
2042
2135
  targets.forEach((target) => {
2043
- indegree.set(target, (indegree.get(target) || 0) + 1);
2136
+ indegree.set(target.node, (indegree.get(target.node) || 0) + 1);
2044
2137
  });
2045
2138
  });
2046
2139
  return nodes.filter((node) => indegree.get(node) === 0);
@@ -2054,8 +2147,8 @@ function findLinearPaths(graph) {
2054
2147
  nodeInDegrees.set(node, 0);
2055
2148
  }
2056
2149
  for (const edge of edges) {
2057
- const inDegree = nodeInDegrees.get(edge) || 0;
2058
- nodeInDegrees.set(edge, inDegree + 1);
2150
+ const inDegree = nodeInDegrees.get(edge.node) || 0;
2151
+ nodeInDegrees.set(edge.node, inDegree + 1);
2059
2152
  }
2060
2153
  }
2061
2154
  function dfs2(node, path) {
@@ -2070,7 +2163,7 @@ function findLinearPaths(graph) {
2070
2163
  addOrUpdatePath([...path]);
2071
2164
  }
2072
2165
  } else {
2073
- const nextNode = Array.from(edges)[0];
2166
+ const nextNode = Array.from(edges)[0].node;
2074
2167
  const nextNodeInDegree = nodeInDegrees.get(nextNode) || 0;
2075
2168
  if (nextNodeInDegree === 1) {
2076
2169
  dfs2(nextNode, path);
@@ -2132,19 +2225,19 @@ function findArticulationPoints(graph) {
2132
2225
  time++;
2133
2226
  visited.add(node);
2134
2227
  for (const neighbor of graph2.get(node) || []) {
2135
- if (!visited.has(neighbor)) {
2228
+ if (!visited.has(neighbor.node)) {
2136
2229
  children++;
2137
- parent.set(neighbor, node);
2138
- APUtil(graph2, neighbor);
2139
- low.set(node, Math.min(low.get(node), low.get(neighbor)));
2230
+ parent.set(neighbor.node, node);
2231
+ APUtil(graph2, neighbor.node);
2232
+ low.set(node, Math.min(low.get(node), low.get(neighbor.node)));
2140
2233
  if (parent.get(node) === null && children > 1) {
2141
2234
  ap.add(node);
2142
2235
  }
2143
- if (parent.get(node) !== null && low.get(neighbor) >= disc.get(node)) {
2236
+ if (parent.get(node) !== null && low.get(neighbor.node) >= disc.get(node)) {
2144
2237
  ap.add(node);
2145
2238
  }
2146
- } else if (neighbor !== parent.get(node)) {
2147
- low.set(node, Math.min(low.get(node), disc.get(neighbor)));
2239
+ } else if (neighbor.node !== parent.get(node)) {
2240
+ low.set(node, Math.min(low.get(node), disc.get(neighbor.node)));
2148
2241
  }
2149
2242
  }
2150
2243
  }
@@ -2161,8 +2254,8 @@ function dfs(graph, node, targets, visited, component) {
2161
2254
  component.add(node);
2162
2255
  visited.add(node);
2163
2256
  targets.forEach((target) => {
2164
- if (!visited.has(target)) {
2165
- dfs(graph, target, graph.get(target) || /* @__PURE__ */ new Set(), visited, component);
2257
+ if (!visited.has(target.node)) {
2258
+ dfs(graph, target.node, graph.get(target.node) || /* @__PURE__ */ new Set(), visited, component);
2166
2259
  }
2167
2260
  });
2168
2261
  }
@@ -2220,10 +2313,15 @@ function hasCycle(graph) {
2220
2313
  function dfs2(node) {
2221
2314
  if (visited.has(node)) {
2222
2315
  if (onStack.has(node)) {
2223
- while (stack[0] !== node) {
2224
- onStack.delete(stack.shift());
2225
- }
2226
- return true;
2316
+ const idx = stack.indexOf(node);
2317
+ const cycle = stack.slice(idx);
2318
+ const allSet = cycle.every((curr, i) => {
2319
+ const next = cycle[(i + 1) % cycle.length];
2320
+ return Array.from(graph.get(curr) || []).some(
2321
+ (edge) => edge.node === next && edge.type === "set"
2322
+ );
2323
+ });
2324
+ return allSet;
2227
2325
  }
2228
2326
  return false;
2229
2327
  }
@@ -2231,7 +2329,7 @@ function hasCycle(graph) {
2231
2329
  onStack.add(node);
2232
2330
  stack.push(node);
2233
2331
  for (const neighbor of graph.get(node) || /* @__PURE__ */ new Set()) {
2234
- if (dfs2(neighbor)) {
2332
+ if (dfs2(neighbor.node)) {
2235
2333
  return true;
2236
2334
  }
2237
2335
  }
@@ -2340,7 +2438,7 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2340
2438
  graph.edges.forEach((edge) => {
2341
2439
  edge.forEach((to) => {
2342
2440
  if (to) {
2343
- inDegreeMap[to.label] = (inDegreeMap[to.label] || 0) + 1;
2441
+ inDegreeMap[to.node.label] = (inDegreeMap[to.node.label] || 0) + 1;
2344
2442
  }
2345
2443
  });
2346
2444
  });
@@ -2374,7 +2472,7 @@ function getVisData(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__
2374
2472
  }
2375
2473
  edges.push({
2376
2474
  from: key.label,
2377
- to: to.label,
2475
+ to: to.node.label,
2378
2476
  arrows: {
2379
2477
  to: {
2380
2478
  enabled: true,