UNPKG

vue-hook-optimizer

Version:

a tool that helps refactor and optimize hook abstractions in Vue components

181 lines (179 loc) 5.53 kB
import "@babel/traverse"; import { SFCStyleBlock, parse } from "@vue/compiler-sfc"; import "@babel/types"; import { Edge, Node } from "vis-network"; //#region src/analyze/utils.d.ts interface TypedNode { label: string; type: NodeType; info?: Partial<{ line: number; column: number; comment: string; used: Set<string>; }>; } declare enum NodeType { var = "var", fun = "fun", } type RelationType = 'get' | 'set' | 'call'; //#endregion //#region src/analyze/options.d.ts declare function analyze(content: string, lineOffset?: number, jsx?: boolean): { graph: { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }; nodesUsedInTemplate: Set<string>; }; //#endregion //#region src/analyze/setupScript.d.ts declare function analyze$1(content: string, lineOffset?: number, jsx?: boolean): { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }; //#endregion //#region src/analyze/style.d.ts declare function analyze$2(styles: SFCStyleBlock[]): Set<string>; //#endregion //#region src/analyze/template.d.ts declare function analyze$3(content: string): Set<string>; //#endregion //#region src/analyze/tsx.d.ts declare function analyze$4(content: string, type?: "vue" | "react", lineOffset?: number, addInfo?: boolean): { graph: { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }; nodesUsedInTemplate: Set<string>; }; //#endregion //#region src/mermaid.d.ts interface MermaidOptions { direction?: 'TB' | 'BT' | 'LR' | 'RL'; } declare function getMermaidText(graph: { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>, options?: MermaidOptions): string; //#endregion //#region src/suggest/index.d.ts declare enum SuggestionType { info = "info", warning = "warning", error = "error", } interface Suggestion { type: SuggestionType; message: string; nodeInfo?: TypedNode | Array<TypedNode>; } declare function gen(graph: { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>, options?: Partial<{ ellipsis: boolean; communitySeed: number; }>): Suggestion[]; //#endregion //#region src/suggest/community.d.ts interface Community { id: number; nodes: Set<TypedNode>; } interface CommunityResult { communities: Community[]; nodeToCommuntiy: Map<TypedNode, number>; } /** * Extract the base/root word from an identifier by removing common prefixes/suffixes. * Only removes prefixes at the start and suffixes at the end. * e.g., "handleOpenChange" -> ["open"] * "isVisible" -> ["visible"] * "userName" -> ["user", "name"] */ interface DetectCommunitiesOptions { maxIterations?: number; seed?: number; /** * Weight for semantic similarity (0-1). * Higher values give more importance to naming patterns. * Default: 1.0 */ semanticWeight?: number; /** * Minimum semantic similarity threshold for enhancing existing edges (0-1). * Only structurally connected node pairs with similarity above this threshold * will have their edge weight enhanced by semantic similarity. * Note: Semantic similarity alone does not create new edges. * Default: 0.3 */ similarityThreshold?: number; } /** * Label Propagation Algorithm for community detection with semantic awareness. * * Each node starts with its own unique label. In each iteration, * nodes adopt the most frequent label among their neighbors, * weighted by both structural connections and semantic similarity. * * Semantic similarity considers: * - Shared base words (e.g., "open" in "isOpen" and "handleOpenChange") * - Substring relationships * - Common naming patterns (handler/state pairs) * * This helps identify groups of nodes that are tightly connected * and could potentially be extracted into separate hooks. */ declare function detectCommunities(graph: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>, options?: DetectCommunitiesOptions): CommunityResult; /** * Generate HSL colors for communities. * Uses golden ratio to distribute hues evenly. */ declare function generateCommunityColors(communityCount: number): string[]; /** * Generate RGBA colors for VS Code decorations. * Returns both background (low opacity) and foreground (high opacity) colors. */ declare function generateCommunityColorsRGBA(communityCount: number): Array<{ background: string; foreground: string; border: string; }>; //#endregion //#region src/vis.d.ts type CustomNode = Node & { info: TypedNode['info']; }; declare function getVisData(graph: { nodes: Set<TypedNode>; edges: Map<TypedNode, Set<{ node: TypedNode; type: RelationType; }>>; }, nodesUsedInTemplate: Set<string>, nodesUsedInStyle?: Set<string>): { nodes: CustomNode[]; edges: Edge[]; }; //#endregion export { type Community, type CommunityResult, type NodeType, type RelationType, Suggestion, SuggestionType, type TypedNode, analyze as analyzeOptions, analyze$1 as analyzeSetupScript, analyze$2 as analyzeStyle, analyze$3 as analyzeTemplate, analyze$4 as analyzeTsx, detectCommunities, gen, generateCommunityColors, generateCommunityColorsRGBA, getMermaidText, getVisData, parse }; //# sourceMappingURL=index.d.ts.map