11'use strict' ;
22
33import * as vscode from 'vscode' ;
4+ import * as path from 'path' ;
45import fs = require( 'fs' )
56
67export function getSvgUri ( uri : vscode . Uri ) {
@@ -19,6 +20,8 @@ export class SvgDocumentContentProvider implements vscode.TextDocumentContentPro
1920 private _onDidChange = new vscode . EventEmitter < vscode . Uri > ( ) ;
2021 private _waiting : boolean = false ;
2122
23+ public constructor ( protected context : vscode . ExtensionContext ) { }
24+
2225 public provideTextDocumentContent ( uri : vscode . Uri ) : Thenable < string > {
2326 let sourceUri = vscode . Uri . parse ( uri . query ) ;
2427 console . log ( sourceUri ) ;
@@ -44,6 +47,10 @@ export class SvgDocumentContentProvider implements vscode.TextDocumentContentPro
4447 }
4548 }
4649
50+ private getPath ( file : string ) : string {
51+ return path . join ( this . context . extensionPath , file ) ;
52+ }
53+
4754 protected snippet ( properties ) : string {
4855 let showTransGrid = vscode . workspace . getConfiguration ( 'svgviewer' ) . get ( 'transparencygrid' ) ;
4956 let transparencycolor = vscode . workspace . getConfiguration ( 'svgviewer' ) . get ( 'transparencycolor' ) ;
@@ -54,6 +61,7 @@ export class SvgDocumentContentProvider implements vscode.TextDocumentContentPro
5461<style type="text/css">
5562.svgbg img {
5663 background: ` + transparencycolor + `;
64+ transform-origin: top left;
5765}
5866</style>` ;
5967 } else {
@@ -63,18 +71,24 @@ export class SvgDocumentContentProvider implements vscode.TextDocumentContentPro
6371 background:initial;
6472 background-image: url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAeUlEQVRYR+3XMQ4AIQhEUTiU9+/hUGy9Wk2G8luDIS8EMWdmYvF09+JtEUmBpieCJiA96AIiiKAswEsik10JCCIoCrAsiGBPOIK2YFWt/knOOW5Nv/ykQNMTQRMwEERQFWAOqmJ3PIIIigIMahHs3ahZt0xCetAEjA99oc8dGNmnIAAAAABJRU5ErkJggg==);
6573 background-position: left,top;
74+ transform-origin: top left;
6675}
6776</style>` ;
6877 }
6978 }
70- return `<!DOCTYPE html><html><head>${ transparencyGridCss } </head><body><div class="svgbg"><img src="data:image/svg+xml,${ encodeURIComponent ( properties ) } "></div></body></html>` ;
79+
80+ return `<!DOCTYPE html><html><head>${ transparencyGridCss }
81+ <script src="${ this . getPath ( 'media/preview.js' ) } "></script>
82+ </script></head><body>
83+ <div class="svgbg"><img id="svgimg" src="data:image/svg+xml,${ encodeURIComponent ( properties ) } "></div>
84+ </body></html>` ;
7185 }
7286}
7387
7488export class SvgFileContentProvider extends SvgDocumentContentProvider {
7589 filename : string ;
76- constructor ( previewUri : vscode . Uri , filename : string ) {
77- super ( ) ;
90+ constructor ( protected context : vscode . ExtensionContext , previewUri : vscode . Uri , filename : string ) {
91+ super ( context ) ;
7892 this . filename = filename ;
7993 vscode . workspace . createFileSystemWatcher ( this . filename , true , false , true ) . onDidChange ( ( e : vscode . Uri ) => {
8094 this . update ( previewUri ) ;
0 commit comments