vue-hook-optimizer 0.0.81 → 0.0.82
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.cjs +23 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +23 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1703,8 +1703,21 @@ function buildUndirectedGraph(graph) {
|
|
|
1703
1703
|
}
|
|
1704
1704
|
return undirected;
|
|
1705
1705
|
}
|
|
1706
|
-
function
|
|
1707
|
-
|
|
1706
|
+
function createSeededRandom(seed) {
|
|
1707
|
+
if (seed === void 0) return Math.random;
|
|
1708
|
+
let state = seed;
|
|
1709
|
+
return () => {
|
|
1710
|
+
state = state * 1103515245 + 12345 & 2147483647;
|
|
1711
|
+
return state / 2147483647;
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
function shuffleArray(array, random = Math.random) {
|
|
1715
|
+
const result = [...array];
|
|
1716
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
1717
|
+
const j = Math.floor(random() * (i + 1));
|
|
1718
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
1719
|
+
}
|
|
1720
|
+
return result;
|
|
1708
1721
|
}
|
|
1709
1722
|
/**
|
|
1710
1723
|
* Label Propagation Algorithm for community detection.
|
|
@@ -1716,7 +1729,9 @@ function sortNodesDeterministically(nodes) {
|
|
|
1716
1729
|
* This helps identify groups of nodes that are tightly connected
|
|
1717
1730
|
* and could potentially be extracted into separate hooks.
|
|
1718
1731
|
*/
|
|
1719
|
-
function detectCommunities(graph,
|
|
1732
|
+
function detectCommunities(graph, options = {}) {
|
|
1733
|
+
const { maxIterations = 100 } = options;
|
|
1734
|
+
const random = createSeededRandom(options.seed);
|
|
1720
1735
|
const undirectedGraph = buildUndirectedGraph(graph);
|
|
1721
1736
|
const nodes = Array.from(undirectedGraph.keys());
|
|
1722
1737
|
if (nodes.length === 0) return {
|
|
@@ -1732,8 +1747,8 @@ function detectCommunities(graph, maxIterations = 100) {
|
|
|
1732
1747
|
while (changed && iterations < maxIterations) {
|
|
1733
1748
|
changed = false;
|
|
1734
1749
|
iterations++;
|
|
1735
|
-
const
|
|
1736
|
-
for (const node of
|
|
1750
|
+
const shuffledNodes = shuffleArray(nodes, random);
|
|
1751
|
+
for (const node of shuffledNodes) {
|
|
1737
1752
|
const neighbors = undirectedGraph.get(node);
|
|
1738
1753
|
if (!neighbors || neighbors.size === 0) continue;
|
|
1739
1754
|
const labelCounts = /* @__PURE__ */ new Map();
|
|
@@ -1749,7 +1764,7 @@ function detectCommunities(graph, maxIterations = 100) {
|
|
|
1749
1764
|
} else if (count === maxCount) maxLabels.push(label);
|
|
1750
1765
|
const currentLabel = labels.get(node);
|
|
1751
1766
|
if (maxLabels.includes(currentLabel)) continue;
|
|
1752
|
-
const newLabel = Math.
|
|
1767
|
+
const newLabel = maxLabels[Math.floor(random() * maxLabels.length)];
|
|
1753
1768
|
if (newLabel !== currentLabel) {
|
|
1754
1769
|
labels.set(node, newLabel);
|
|
1755
1770
|
changed = true;
|
|
@@ -2052,7 +2067,7 @@ let SuggestionType = /* @__PURE__ */ function(SuggestionType$1) {
|
|
|
2052
2067
|
return SuggestionType$1;
|
|
2053
2068
|
}({});
|
|
2054
2069
|
function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new Set(), options) {
|
|
2055
|
-
const { ellipsis = true } = options ?? {};
|
|
2070
|
+
const { ellipsis = true, communitySeed } = options ?? {};
|
|
2056
2071
|
const usedNodes = new Set([...nodesUsedInTemplate, ...nodesUsedInStyle]);
|
|
2057
2072
|
const suggestions = [];
|
|
2058
2073
|
const splitedGraph = splitGraph(graph.edges);
|
|
@@ -2106,7 +2121,7 @@ function gen(graph, nodesUsedInTemplate, nodesUsedInStyle = /* @__PURE__ */ new
|
|
|
2106
2121
|
nodeInfo: node
|
|
2107
2122
|
});
|
|
2108
2123
|
});
|
|
2109
|
-
const communityResult = detectCommunities(graph.edges);
|
|
2124
|
+
const communityResult = detectCommunities(graph.edges, { seed: communitySeed });
|
|
2110
2125
|
const { communities } = communityResult;
|
|
2111
2126
|
const extractableCommunities = communities.filter((community) => {
|
|
2112
2127
|
const nodes = Array.from(community.nodes);
|