This repository has been archived by the owner on Apr 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from cssho/NpmRebuild
PNG export support linux/macos.
- Loading branch information
Showing
3 changed files
with
87 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export class SvgDocumentContentProvider implements vscode.TextDocumentContentProvider { | ||
private _onDidChange = new vscode.EventEmitter<vscode.Uri>(); | ||
|
||
public provideTextDocumentContent(uri: vscode.Uri): string { | ||
return this.createSvgSnippet(); | ||
} | ||
|
||
get onDidChange(): vscode.Event<vscode.Uri> { | ||
return this._onDidChange.event; | ||
} | ||
|
||
public update(uri: vscode.Uri) { | ||
this._onDidChange.fire(uri); | ||
} | ||
|
||
private createSvgSnippet() { | ||
return this.extractSnippet(); | ||
} | ||
|
||
private extractSnippet(): string { | ||
let editor = vscode.window.activeTextEditor; | ||
let text = editor.document.getText(); | ||
return this.snippet(text); | ||
} | ||
|
||
private errorSnippet(error: string): string { | ||
return ` | ||
<body> | ||
${error} | ||
</body>`; | ||
} | ||
|
||
private snippet(properties): string { | ||
let showTransGrid = vscode.workspace.getConfiguration('svgviewer').get('transparencygrid'); | ||
let transparencyGridCss = ''; | ||
if (showTransGrid) { | ||
transparencyGridCss = ` | ||
<style type="text/css"> | ||
.svgbg svg { | ||
background:initial; | ||
background-image: url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAeUlEQVRYR+3XMQ4AIQhEUTiU9+/hUGy9Wk2G8luDIS8EMWdmYvF09+JtEUmBpieCJiA96AIiiKAswEsik10JCCIoCrAsiGBPOIK2YFWt/knOOW5Nv/ykQNMTQRMwEERQFWAOqmJ3PIIIigIMahHs3ahZt0xCetAEjA99oc8dGNmnIAAAAABJRU5ErkJggg==); | ||
background-position: left,top; | ||
} | ||
</style>`; | ||
} | ||
return `<!DOCTYPE html><html><head>${transparencyGridCss}</head><body><div class="svgbg">${properties}</div></body></html>`; | ||
} | ||
} |