Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

docs: preloads docs assets #4384

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/js/ganache/ganache.min.js.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions docs/assets/js/inject-editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require.config({
paths: {
vs: "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.28.0/min/vs"
},
onNodeCreated: function (node) {
node.setAttribute("crossorigin", "anonymous");
}
});

Expand All @@ -13,7 +16,7 @@ function escapeHtml(unsafe) {
.replace(/'/g, "'");
}

function getTheme() {
function getTheme(userTheme) {
const styles = getComputedStyle(document.querySelector("#page"));

const format = str => str.trim().substring(1, 9);
Expand Down Expand Up @@ -55,7 +58,7 @@ function getTheme() {
{ token: "string", foreground: text4 },
{ token: "keyword", foreground: text6 }
];
const base = getUserColorTheme() === "light" ? "vs" : "vs-dark";
const base = userTheme === "light" ? "vs" : "vs-dark";
return {
base,
colors: {
Expand All @@ -75,7 +78,7 @@ function getTheme() {
const newTheme = e.target.checked === true ? "light" : "dark";
localStorage.setItem("theme", newTheme);
document.documentElement.setAttribute("data-theme", newTheme);
monaco.editor.defineTheme("ganache", getTheme());
monaco.editor.defineTheme("ganache", getTheme(newTheme));
});
})();

Expand Down Expand Up @@ -103,9 +106,9 @@ require(["vs/editor/editor.main"], function () {
const libUri = "ts:filename/provider.d.ts";
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);
monaco.editor.createModel(libSource, "typescript", monaco.Uri.parse(libUri));
monaco.editor.defineTheme("ganache", getTheme());
monaco.editor.defineTheme("ganache", getTheme(userColorTheme));

const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
let ganachePromise = null;
async function downloadGanacheIfNeeded() {
if (Ganache) return;
Expand Down
18 changes: 0 additions & 18 deletions docs/assets/js/preload.js

This file was deleted.

232 changes: 127 additions & 105 deletions docs/index.html

Large diffs are not rendered by default.

198 changes: 99 additions & 99 deletions docs/typedoc/classes/default.html

Large diffs are not rendered by default.

43 changes: 35 additions & 8 deletions scripts/build-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ const preamble =

**Pro Tip**: You can define your own provider by adding \`const provider = ganache.provider({})\` to the start of any example and passing in your [startup options](https://trufflesuite.com/docs/ganache/reference/cli-options/).`);

// this font is loaded when you navigate to ganache. Others are loaded as well, but they are dependent on the
// User-Agent and thus different browsers get different versions. To verify check what fonts are downloaded, load
// ganache.dev with devtools open, and check the `Font` tab within the Network tab.
const fontPreload = `
<link rel="preload" crossorigin="anonymous" as="font" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.28.0/min/vs/base/browser/ui/codicons/codicon/codicon.ttf">
`;

const html = `
<!DOCTYPE html>
<html lang="en">
Expand All @@ -455,17 +462,44 @@ const html = `
<meta name="description" content="Ganache Ethereum JSON-RPC Documentation" />
<meta name="author" content="David Murdoch" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="./assets/js/preload.js"></script>

<link rel="shortcut icon" href="./assets/img/favicon.png" />

${fontPreload}

<link href="https://fonts.googleapis.com/css?family=Open+Sans:300i,300,400|Share+Tech+Mono&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Grand+Hotel&text=Ganache" rel="stylesheet" />
<link rel="stylesheet" href="./assets/css/main.css" />
<link rel="stylesheet" href="./assets/css/highlight-truffle.css" />
<link rel="preload" as="script" href="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous" />
<link rel="preload" as="script" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.28.0/min/vs/editor/editor.main.js" crossorigin="anonymous" />
<link rel="preload" as="script" href="./assets/js/inject-editor.js" />

<script>
function getUserColorTheme() {
const localTheme = localStorage.getItem("theme");
if (localTheme) {
return localTheme;
} else if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: light)").matches
) {
return "light";
} else {
return "dark";
}
}

const userColorTheme = getUserColorTheme();
document.documentElement.setAttribute("data-theme", userColorTheme);
</script>
</head>
<body>
<input type="checkbox" id="sidebar-switch" tabindex="1">
<input type="checkbox" id="theme-switch" tabindex="2">
<script>
document.querySelector("#theme-switch").checked = userColorTheme === "light";
</script>
<div class="container" id="page">
<header>
<svg style="position:absolute;pointer-events:none;opacity:0;" width="10" height="10" viewBox="0 0 10 10">
Expand Down Expand Up @@ -516,13 +550,6 @@ const html = `
</article>
</main>
</div>
<script>
(function initColorTheme() {
const theme = getUserColorTheme();
const checked = theme === "light" ? true : false;
document.querySelector("#theme-switch").checked = checked;
})();
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
<script src="./assets/js/inject-editor.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/ganache/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.