Skip to content

Commit 81006ab

Browse files
feat: add p shortcut to toggle between pdf/presentation mode
This also refactors the browser scripts into separate files, and adds a new method of building the scripts.
1 parent eed6cce commit 81006ab

File tree

14 files changed

+688
-571
lines changed

14 files changed

+688
-571
lines changed

browser/css.ts

Lines changed: 0 additions & 230 deletions
This file was deleted.

browser/css/modes/base.ts

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* eslint-disable no-inline-comments */
2+
3+
import { Component } from '#lib/core/components/class';
4+
import type { SlydeHtmlDocumentCssProperties } from '#browser/css/types';
5+
6+
/** Passes the provided arguments as CSS variables up the tree. */
7+
export const variables = function variables({
8+
background,
9+
foreground,
10+
primary,
11+
secondary,
12+
size,
13+
}: SlydeHtmlDocumentCssProperties): string {
14+
return /*CSS*/ `
15+
/*
16+
!!!! Any changes to this function removing variables are very much breaking changes !!!!
17+
*/
18+
:root {
19+
--width: ${size.width} !important;
20+
--height: ${size.height} !important;
21+
--foreground: ${foreground} !important;
22+
--background: ${background} !important;
23+
--secondary: ${secondary} !important;
24+
--primary: ${primary} !important;
25+
}
26+
`;
27+
};
28+
29+
/** All the CSS for the HTML body. */
30+
export const html = /*CSS*/ `
31+
html {
32+
height: 100vh;
33+
width: 100vw;
34+
margin: 0;
35+
padding: 0;
36+
display: flex;
37+
justify-content: center;
38+
align-items: center;
39+
background-color: black;
40+
font-family: "DejaVu Sans", sans-serif !important;
41+
}
42+
`;
43+
44+
/** Disables all scrollbars everywhere */
45+
const scrollBars = /*CSS*/ `
46+
* {
47+
scrollbar-width: none;
48+
-ms-overflow-style: none;
49+
}
50+
51+
*::-webkit-scrollbar {
52+
display: none;
53+
}
54+
`;
55+
56+
/** A list of things that should never be displayed. */
57+
const hide = /*CSS*/ `
58+
head, style, script {
59+
display: none !important;
60+
visibility: hidden !important;
61+
}
62+
`;
63+
64+
/** Styles the latex containers created by the latex parsers. */
65+
const latex = /*CSS*/ `
66+
mjx-container {
67+
display: inline-block;
68+
vertical-align: middle;
69+
}
70+
`;
71+
72+
const fontSize = 1;
73+
74+
/** The CSS related to the body. */
75+
const body = /*CSS*/ `
76+
body { /* Calculation of --unit */
77+
color: var(--foreground);
78+
position: relative;
79+
80+
--unit: min(
81+
(min(100vw, calc(100vh * var(--width) / var(--height))) / var(--width)),
82+
(min(100vh, calc(100vw * var(--height) / var(--width))) / var(--height)),
83+
) !important;
84+
85+
container-name: document;
86+
container-type: size;
87+
width: calc(var(--width) * var(--unit));
88+
}
89+
90+
body { /* Calculation of the --font size. */
91+
--font-size: min(
92+
${fontSize} * 1vw * (100 / var(--width)),
93+
100vh * (${fontSize} / var(--height))
94+
) !important;
95+
font-size: var(--font-size);
96+
}
97+
`;
98+
99+
/** CSS related to the slides */
100+
const slide = /*CSS*/ `
101+
body slyde-component[level="${Component.level.slide}"] {
102+
display: block;
103+
background-color: var(--background);
104+
width: 100%;
105+
aspect-ratio: var(--width) / var(--height);
106+
}
107+
`;
108+
109+
/** CSS related to anchors */
110+
const anchors = /*CSS*/ `
111+
a { color: var(--secondary) }
112+
a:hover { text-decoration: underline }
113+
`;
114+
115+
/** The default CSS to display regardless of the mode we're in. */
116+
export const baseCSS = function baseCSS(args: SlydeHtmlDocumentCssProperties): string {
117+
return /* CSS */ `
118+
${variables(args)}
119+
${html}
120+
${scrollBars}
121+
${hide}
122+
${latex}
123+
${body}
124+
${slide}
125+
${anchors}
126+
`;
127+
};

browser/css/modes/pdf.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* This file contains all the CSS to ONLY apply when the document is in "PDF" mode.
3+
*/
4+
//
5+
6+
import { Component } from '#lib/core/components/class';
7+
8+
/** The CSS for the body. */
9+
// eslint-disable-next-line no-inline-comments
10+
const body = /*CSS*/ `
11+
body {
12+
overflow-x: scroll;
13+
height: 100vh;
14+
}
15+
` as const;
16+
17+
// eslint-disable-next-line no-inline-comments
18+
const slide = /*CSS*/ `
19+
body slyde-component[level="${Component.level.slide}"] {
20+
margin-bottom: var(--unit);
21+
}
22+
23+
body slyde-component[level="${Component.level.slide}"]:last-child {
24+
margin-bottom: 0;
25+
}
26+
` as const;
27+
28+
/** The CSS to apply when in this mode */
29+
export const pdfModeStyle = `${body}${slide}`;

0 commit comments

Comments
 (0)