import vscode from 'vscode' ; import path from 'path' ; param context param webviewPanel param options returns export const getUmiHTMLContent = ( context , webviewPanel , options ? ) : string => { const title = options ! . title || 'umijs' ; const rootPath = options ! . rootPath || 'web' ; const style = options ! . style || '' ; const getDiskPath = ( fileName ) => { return webviewPanel . webview . asWebviewUri ( vscode . Uri . file ( path . join ( context . extensionPath , rootPath , 'dist' , fileName ) ) ) ; } ; const umiVersion = require ( '../../../umi/package.json' ) . version ; return `
    <html>
      <head>
        <meta charset="utf-8" />
        <meta
          name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
        />
        <title>${ title }</title>
        <link rel="stylesheet" href="${ getDiskPath ( 'umi.css' ) }" />
        <style>
          // 给 webview 内容加上主题
          #root {
            background-color: var(--vscode-editor-background);
          }
          body {
            padding: 0 var(--container-paddding);
            color: var(--vscode-foreground);
            font-size: var(--vscode-font-size);
            font-weight: var(--vscode-font-weight);
            font-family: var(--vscode-font-family);
            background-color: var(--vscode-editor-background);
          }
          body.vscode-light {
            color: black;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-light h1, h2, h3, h4, h5, h6 {
            color: black;
          }
          body.vscode-dark {
            color: white;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-dark h1, h2, h3, h4, h5, h6 {
            color: white;
          }
          body.vscode-high-contrast {
            color: red;
            background-color: var(--vscode-editor-background);
          }
          body.vscode-high-contrast h1, h2, h3, h4, h5, h6 {
            color: red;
          }
          ${ style }
        </style>
        <script>
          //! umi version: ${ umiVersion }
        </script>
      </head>
      <body>
        <div id="root"></div>

        <script src="${ getDiskPath ( 'umi.js' ) }"></script>
      </body>
    </html>
  ` ; } ; let currentPanel ; param context param viewType param title param iconPath returns export const createUmiWebviewPanel = ( context , viewType , title , iconPath ) => { const columnToShowIn = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ; if ( currentPanel ) { currentPanel . reveal ( columnToShowIn ) ; } else { currentPanel = vscode . window . createWebviewPanel ( viewType , title , vscode . ViewColumn . One , { enableScripts : true , localResourceRoots : [ vscode . Uri . file ( path . join ( context . extensionPath , 'web/dist' ) ) ] , retainContextWhenHidden : true , } ) ; currentPanel . iconPath = vscode . Uri . file ( path . join ( context . extensionPath , iconPath ) ) ; currentPanel . webview . html = getUmiHTMLContent ( context , currentPanel ) ; } currentPanel . onDidDispose ( ( ) => { currentPanel = undefined ; } , null , context . subscriptions ) ; return currentPanel ; } ;