-
Notifications
You must be signed in to change notification settings - Fork 11
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 #19 from BarryNolte/d2-vscode-extension-signed
First PR creating the viewer for d2 files in VsCode.
- Loading branch information
Showing
10 changed files
with
3,848 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.DS_Store | ||
node_modules | ||
*.vsix | ||
dist |
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,173 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" title="d2 Diagram"> | ||
<title>Diagram</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta charset="utf-8"> | ||
|
||
<head> | ||
<style> | ||
#toolbar { | ||
z-index: 100; | ||
position: fixed; | ||
left: 0px; | ||
top: 0px; | ||
background-color: #909090; | ||
padding-left: 15px; | ||
padding-right: 200px; | ||
padding-bottom: 5px; | ||
width: 100%; | ||
color: #0D32B2; | ||
} | ||
|
||
#zoomSlider { | ||
appearance: none; | ||
border-radius: 3px; | ||
background: #0D32B2; | ||
height: 5px; | ||
} | ||
|
||
#zoomSlider::-webkit-slider-thumb { | ||
appearance: none; | ||
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; | ||
border: 1px solid darkblue; | ||
height: 20px; | ||
width: 8px; | ||
margin-bottom: 5px; | ||
border-radius: 3px; | ||
background: lightblue; | ||
cursor: pointer; | ||
} | ||
|
||
#percent { | ||
display: inline-block; | ||
font-family: monospace; | ||
font-size: 18px; | ||
font-weight: 600; | ||
width: 55px; | ||
} | ||
|
||
button { | ||
margin-top: 3px; | ||
color: #0D32B2; | ||
border-color: #0D32B2; | ||
background-color: #F7F8FE; | ||
border-radius: 6px; | ||
border: 3 3 3 3; | ||
box-shadow: 1px 1px 1px black, 0px 0px 1px 0d0d0d; | ||
padding: 5px; | ||
min-width: 50px; | ||
font-size: 14px; | ||
font-weight: 600; | ||
} | ||
|
||
svg { | ||
position: absolute; | ||
left: 0px; | ||
top: 0px; | ||
transform-origin: 0px 0px; | ||
} | ||
|
||
body { | ||
background-color: var(--vscode-editor-background); | ||
color: var(--vscode-editor-foreground); | ||
fill: var(--vscode-editor-foreground); | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> | ||
<script> | ||
var zoomLevel = 100; | ||
var percent; | ||
var zoomSlider; | ||
var fitMode = true; | ||
|
||
function getSvgElement() { | ||
var svgs = document.getElementsByTagName('svg'); | ||
return svgs[0]; | ||
} | ||
function init() { | ||
percent = document.getElementById('percent'); | ||
zoomSlider = document.getElementById('zoomSlider'); | ||
zoomFit(); | ||
} | ||
function zoomPlus() { | ||
zoomLevel = Math.min(150, zoomLevel + 5); | ||
setZoomLevel(zoomLevel); | ||
} | ||
function zoomMinus() { | ||
zoomLevel = Math.max(10, zoomLevel - 5); | ||
setZoomLevel(zoomLevel); | ||
} | ||
function zoomFit() { | ||
setZoomLevel(100); | ||
var svg = getSvgElement(); | ||
svg.style.height = "100%"; | ||
svg.style.width = "100%"; | ||
setZoomText(false) | ||
|
||
fitMode = true; | ||
} | ||
function setZoomLevel(zl) { | ||
var svg = getSvgElement(); | ||
svg.style.height = ""; | ||
svg.style.width = ""; | ||
svg.style.zoom = zl / 100.0; | ||
setZoomText(true); | ||
|
||
zoomSlider.value = zl; | ||
|
||
fitMode = false; | ||
} | ||
function sliderOnChange() { setZoomLevel(zoomSlider.value); } | ||
function setZoomText(text) { | ||
var svg = getSvgElement(); | ||
|
||
if (text === true) { | ||
percent.innerText = (svg.style.zoom * 100.0).toFixed() + "%"; | ||
} | ||
else { | ||
percent.innerText = "Fit"; | ||
} | ||
} | ||
|
||
window.addEventListener("DOMContentLoaded", () => { | ||
init(); | ||
}); | ||
|
||
window.addEventListener("message", (event) => { | ||
const message = event.data; // The JSON data our extension sent | ||
|
||
switch (message.command) { | ||
case "render": | ||
var previewWrapper = document.getElementById('previewWrapper'); | ||
previewWrapper.innerHTML = message.data; | ||
|
||
if (fitMode === true) { | ||
zoomFit(); | ||
} else { | ||
setZoomLevel(zoomLevel); | ||
} | ||
break; | ||
} | ||
}); | ||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
<div id="toolbar"> | ||
<button onclick="zoomMinus();" title="Zoom Out">Out</button> | ||
<input id="zoomSlider" title="Zoom" onchange="sliderOnChange()" type="range" min="10" max="150" value="100" | ||
step="5"> | ||
<button onclick="zoomPlus();" title="Zoom In">In</button> | ||
<span id="percent"></span> | ||
<button id="zoomFit" onclick="zoomFit()" title="Fit to window">Fit to window</button> | ||
</div> | ||
<div id="previewWrapper"> | ||
<svg> | ||
<text font-size="x-large" x="20" y="50">Loading...</text> | ||
</svg> | ||
</div> | ||
|
||
<body> | ||
<html> |
Oops, something went wrong.