add mode7 font

+ can now inject custom theme styles
This commit is contained in:
Felix Roos 2023-08-28 23:52:24 +02:00
parent 0e3d84e5ca
commit 289376840e
7 changed files with 24 additions and 2 deletions

View File

@ -12,6 +12,7 @@ export const settings = {
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: '#0f380f', gutterForeground: '#0f380f',
light: true, light: true,
customStyle: '.cm-line { line-height: 1 }',
}; };
export default createTheme({ export default createTheme({
theme: 'light', theme: 'light',

View File

@ -8,7 +8,7 @@ let colorC = 'red';
let colorD = '#f8fc55'; let colorD = '#f8fc55';
export const settings = { export const settings = {
background: '#00000f', background: '#000000',
foreground: colorA, // whats that? foreground: colorA, // whats that?
caret: colorC, caret: colorC,
selection: colorD, selection: colorD,
@ -17,6 +17,7 @@ export const settings = {
lineBackground: '#00000080', lineBackground: '#00000080',
gutterBackground: 'transparent', gutterBackground: 'transparent',
gutterForeground: '#8a919966', gutterForeground: '#8a919966',
customStyle: '.cm-line { line-height: 1 }',
}; };
let punctuation = colorD; let punctuation = colorD;

Binary file not shown.

View File

@ -46,12 +46,14 @@ const base = BASE_URL;
{pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />} {pwaInfo && <Fragment set:html={pwaInfo.webManifest.linkTag} />}
<script> <script>
import { settings } from '../repl/themes.mjs'; import { settings, injectStyle } from '../repl/themes.mjs';
import { settingsMap } from '../settings.mjs'; import { settingsMap } from '../settings.mjs';
import { listenKeys } from 'nanostores'; import { listenKeys } from 'nanostores';
const themeStyle = document.createElement('style'); const themeStyle = document.createElement('style');
themeStyle.id = 'strudel-theme'; themeStyle.id = 'strudel-theme';
document.head.append(themeStyle); document.head.append(themeStyle);
let resetThemeStyle;
function activateTheme(name) { function activateTheme(name) {
if (!settings[name]) { if (!settings[name]) {
console.warn('theme', name, 'has no settings.. defaulting to strudelTheme settings'); console.warn('theme', name, 'has no settings.. defaulting to strudelTheme settings');
@ -70,6 +72,11 @@ const base = BASE_URL;
} else { } else {
document.documentElement.classList.add('dark'); document.documentElement.classList.add('dark');
} }
resetThemeStyle?.();
resetThemeStyle = undefined;
if (themeSettings.customStyle) {
resetThemeStyle = injectStyle(themeSettings.customStyle);
}
} }
activateTheme(settingsMap.get().theme); activateTheme(settingsMap.get().theme);

View File

@ -377,6 +377,7 @@ const fontFamilyOptions = {
'FiraCode-SemiBold': 'FiraCode SemiBold', 'FiraCode-SemiBold': 'FiraCode SemiBold',
protracker3: 'protracker3', protracker3: 'protracker3',
teletext: 'teletext', teletext: 'teletext',
mode7: 'mode7',
}; };
function SettingsTab({ scheduler }) { function SettingsTab({ scheduler }) {

View File

@ -475,3 +475,11 @@ function getCircularReplacer() {
function stringifySafe(json) { function stringifySafe(json) {
return JSON.stringify(json, getCircularReplacer()); return JSON.stringify(json, getCircularReplacer());
} }
export function injectStyle(rule) {
const newStyle = document.createElement('style');
document.head.appendChild(newStyle);
const styleSheet = newStyle.sheet;
const ruleIndex = styleSheet.insertRule(rule, 0);
return () => styleSheet.deleteRule(ruleIndex);
}

View File

@ -34,6 +34,10 @@
font-family: 'teletext'; font-family: 'teletext';
src: url('/fonts/teletext/EuropeanTeletext.ttf'); src: url('/fonts/teletext/EuropeanTeletext.ttf');
} }
@font-face {
font-family: 'mode7';
src: url('/fonts/mode7/MODE7GX3.TTF');
}
.prose > h1:not(:first-child) { .prose > h1:not(:first-child) {
margin-top: 30px; margin-top: 30px;