Skip to content

Commit

Permalink
Merge pull request #62 from terrastruct/update
Browse files Browse the repository at this point in the history
batch of updates
  • Loading branch information
alixander authored Sep 4, 2024
2 parents ca83aca + e85f342 commit ddd6f34
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
build
dist
d2-playground
.DS_Store
5 changes: 5 additions & 0 deletions src/assets/icons/sketch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion src/css/hero.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@
#hero-text {
margin-top: 12px;
color: var(--steel-850);
text-align: center;
}

#hero-text-tagline {
font-size: 14px;
font-family: "Source Sans Pro Medium";
text-align: center;
}

#hero-text-version {
font-size: 12px;
margin-top: 0.4rem;
color: var(--steel-550);
}

#hero-left-drawing,
Expand Down
2 changes: 2 additions & 0 deletions src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
--blue-400: #6b8afb;
--blue-500: #4a6ff3;
--blue-600: #234cda;
--blue-600-filter: brightness(0) saturate(100%) invert(21%) sepia(100%) saturate(3335%)
hue-rotate(227deg) brightness(88%) contrast(94%);
--alert-100: #ffcfd8;
--alert-200: #ff8096;
--alert-300: #f35471;
Expand Down
20 changes: 19 additions & 1 deletion src/css/responsive.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,26 @@
display: none;
}
#sketch {
display: none;
}
#sketch-mobile {
display: flex !important;
flex-direction: column;
gap: 2px;
align-items: center;
padding: 0.4rem;
border-radius: 4px;
}
#sketch-mobile-icon {
margin-top: 2px;
}
.sketch-mobile-activated {
background: var(--blue-050);
#sketch-mobile-icon {
filter: var(--blue-600-filter);
}
}
#download-cli {
display: none;
}
#zoom-container {
display: none;
Expand Down
Binary file modified src/d2.wasm
Binary file not shown.
17 changes: 14 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
>
<a
class="nav-menu-item"
id="download-cli"
target="_blank"
href="https://github.com/terrastruct/d2#install"
>
Expand Down Expand Up @@ -119,8 +120,11 @@
/>
</picture>
<div id="hero-text">
An online runner to play, learn, and create with D2, the modern diagram
scripting language that turns text to diagrams.
<div id="hero-text-tagline">
An online runner to play, learn, and create with D2, the modern diagram
scripting language that turns text to diagrams.
</div>
<div id="hero-text-version"></div>
</div>
</div>
<div id="hero-right-drawing">
Expand Down Expand Up @@ -215,6 +219,13 @@
</label>
</div>
</div>
<div id="sketch-mobile" style="display: none">
<img
id="sketch-mobile-icon"
src="assets/icons/sketch.svg"
class="btn-icon"
/>
</div>
</div>
<div id="render-toolbar-right" class="workstation-toolbar-right">
<div id="export" class="btn-menu-container">
Expand Down Expand Up @@ -330,7 +341,7 @@
</a>
</div>
<div class="footer-vertical-divider">|</div>
<div class="footer-bottom-content">&copy; 2023 Terrastruct, Inc.</div>
<div class="footer-bottom-content">&copy; 2024 Terrastruct, Inc.</div>
</div>
</div>
<script src="js/vendor/panzoom.js"></script>
Expand Down
3 changes: 3 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ async function init() {
Layout.init();
Modal.init();

const versionDOM = document.getElementById("hero-text-version");
versionDOM.innerHTML = `d2 version: ${d2Version()}`;

// TODO defer load hero images all the way here
}

Expand Down
1 change: 1 addition & 0 deletions src/js/modules/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async function initMonaco() {
() => undefined
);
monacoEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, compile);
monacoEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, compile);
provider.registry.setTheme(lightTheme);
monaco.editor.setTheme(lightTheme);

Expand Down
7 changes: 4 additions & 3 deletions src/js/modules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ async function exportPNG() {
const width = parseFloat(viewBox[2]) * window.devicePixelRatio;
const height = parseFloat(viewBox[3]) * window.devicePixelRatio;

const encoded =
"data:image/svg+xml;base64," +
btoa(unescape(encodeURIComponent(new XMLSerializer().serializeToString(svgEl))));
const blob = new Blob([new XMLSerializer().serializeToString(svgEl)], {
type: "image/svg+xml",
});
const encoded = URL.createObjectURL(blob);

const tempImg = new Image();
const loadImage = () => {
Expand Down
24 changes: 21 additions & 3 deletions src/js/modules/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import QueryParams from "../lib/queryparams";

function init() {
readQueryParam();
document.getElementById("sketch-checkbox").addEventListener("change", toggleSketch);
document
.getElementById("sketch-checkbox")
.addEventListener("change", (e) => toggleSketch(e.target.checked));
document
.getElementById("sketch-mobile-icon")
.addEventListener("click", () => toggleSketch(QueryParams.get("sketch") === "0"));
updateMobileIcon(QueryParams.get("sketch") === "1");
}

function readQueryParam() {
Expand All @@ -24,9 +30,9 @@ function readQueryParam() {
}
}

function toggleSketch(e) {
function toggleSketch(on) {
const icon = document.getElementById("sketch-toggle-icon");
if (e.target.checked) {
if (on) {
icon.src = "assets/icons/toggle_check.svg";
QueryParams.set("sketch", "1");
} else {
Expand All @@ -36,6 +42,18 @@ function toggleSketch(e) {
if (Editor.getDiagramSVG()) {
Editor.compile();
}

updateMobileIcon(on);
}

function updateMobileIcon(on) {
const icon = document.getElementById("sketch-mobile");

if (on) {
icon.classList.add("sketch-mobile-activated");
} else {
icon.classList.remove("sketch-mobile-activated");
}
}

function getValue() {
Expand Down

0 comments on commit ddd6f34

Please sign in to comment.