import * as vscode from 'vscode' ; import * as js2flowchart from "js2flowchart" ; const flowcharts = { 'JS Flowchart' : 'null' , } ; export function activate ( context ) { context . subscriptions . push ( vscode . commands . registerCommand ( 'ShowJSFlowchart.start' , ( ) => { FlowchartPanel . createOrShow ( context . extensionPath ) ; vscode . window . onDidChangeTextEditorSelection ( ( caught ) => { if ( caught . textEditor === vscode . window . activeTextEditor ) { if ( FlowchartPanel . currentPanel ) { FlowchartPanel . currentPanel . _update ( ) ; } } } ) ; } ) ) ; } /**
 * Manages cat coding webview panels
 */ class FlowchartPanel { /**
     * Track the currently panel. Only allow a single panel to exist at a time.
     */ public static currentPanel : FlowchartPanel | undefined ; public static readonly viewType = 'JS Flowchart' ; private readonly _panel : vscode . WebviewPanel ; private readonly _extensionPath : string ; private _disposables : vscode . Disposable [ ] = [ ] ; public static createOrShow ( extensionPath ) { const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ; if ( FlowchartPanel . currentPanel ) { FlowchartPanel . currentPanel . _panel . reveal ( column ) ; return ; } const panel = vscode . window . createWebviewPanel ( FlowchartPanel . viewType , 'JS Flowchart' , vscode . ViewColumn . Beside , { enableScripts : true , } ) ; FlowchartPanel . currentPanel = new FlowchartPanel ( panel , extensionPath ) ; } public static revive ( panel , extensionPath ) { FlowchartPanel . currentPanel = new FlowchartPanel ( panel , extensionPath ) ; } private constructor ( panel , extensionPath ) { this . _panel = panel ; this . _extensionPath = extensionPath ; this . _update ( ) ; this . _panel . onDidDispose ( ( ) => this . dispose ( ) , null , this . _disposables ) ; this . _panel . onDidChangeViewState ( e => { if ( this . _panel . visible ) { this . _update ( ) ; } } , null , this . _disposables ) ; this . _panel . webview . onDidReceiveMessage ( message => { switch ( message . command ) { case 'alert' : vscode . window . showErrorMessage ( message . text ) ; return ; } } , null , this . _disposables ) ; } public doRefactor ( ) { this . _panel . webview . postMessage ( { command : 'refactor' } ) ; } public dispose ( ) { FlowchartPanel . currentPanel = undefined ; this . _panel . dispose ( ) ; while ( this . _disposables . length ) { const x = this . _disposables . pop ( ) ; if ( x ) { x . dispose ( ) ; } } } public _update ( ) { const webview = this . _panel . webview ; this . _updateForFC ( webview , 'JS Flowchart' ) ; return ; } private _updateForFC ( webview , FCName ) { this . _panel . title = FCName ; this . _panel . webview . html = this . _getHtmlForWebview ( ) ; } private _getHtmlForWebview ( ) { const svg1 = getNonce ( ) ; const SelectedText = getSelectedText ( ) ; return `
			<html lang="en">
			<body style="background-color:white;">
				<div>${ svg1 }</div>
				<!--
				<h1 id="lines-of-code-counter">0</h1>
				<div>${ SelectedText }</div>-->
			</body>
            </html>` ; } } var text = '' ; var svg1 = " " ; function getNonce ( ) { if ( vscode . window . activeTextEditor === undefined ) { return svg1 ; } else if ( vscode . window . activeTextEditor != null ) { let WindowP = vscode . window . activeTextEditor ; let wordRange = new vscode . Range ( WindowP . selection . start , WindowP . selection . end ) ; text = WindowP . document . getText ( wordRange ) ; } const { createSVGRender , convertCodeToFlowTree } = js2flowchart ; const flowTree = convertCodeToFlowTree ( text ) , svgRender = createSVGRender ( ) ; svgRender . applyLightTheme ( ) ; svg1 = svgRender . buildShapesTree ( flowTree ) . print ( ) ; return svg1 ; } function getSelectedText ( ) { let text = '' ; if ( vscode . window . activeTextEditor != null ) { let WindowP = vscode . window . activeTextEditor ; let wordRange = new vscode . Range ( WindowP . selection . start , WindowP . selection . end ) ; text = WindowP . document . getText ( wordRange ) ; return text ; } }