-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout_marginalia.ts
260 lines (217 loc) · 5.52 KB
/
layout_marginalia.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import { Expression, Invocation, new_macro } from "./tsgen.ts";
export class LayoutOptions {
/* All distances in rem */
// padding-top for the body
padding_top = 4;
// padding-bottom for the body
padding_bottom = 2;
// padding-right for the body
padding_right = 1;
// padding-left for the body
padding_left = 1;
// spacing between marginalia and the main contents
spacing_marginalia = 2;
// maximum width for the main contents
max_width_main = 32;
// maximum width for the marginalia
max_width_marginalia = 18;
// width of the toc
toc = 15;
// width of main content and the marginalia together
wide(): number {
return this.max_width_main + this.spacing_marginalia +
this.max_width_marginalia;
}
// width of main content, the marginalia, and their left and right margins
// if the screen is less wide than this, the marginalia disappear
wide_and_margins(): number {
return this.wide() + this.padding_left + this.padding_right;
}
wide_and_margins_and_toc(): number {
return this.wide() + this.padding_left + this.padding_right + this.toc
}
}
export function layout_marginalia(opts: LayoutOptions): Expression {
const macro = new_macro(
(_args, _ctx) => {
return `*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
}
body {
overflow-x: hidden;
}
.container_main {
padding-left: ${opts.padding_left}rem;
padding-right: ${opts.padding_right}rem;
padding-bottom: ${opts.padding_bottom}rem;
padding-top: ${opts.padding_top}rem;
max-width: ${opts.wide()}rem;
position: relative;
margin: auto;
display: flex;
flex-direction: column;
min-height: 100vh;
}
.container_main > * {
max-width: ${opts.max_width_main}rem;
}
.wide {
width: 100%;
}
@media (min-width: ${opts.wide_and_margins()}rem) {
.wide {
position: relative;
width: ${opts.wide()}rem;
max-width: calc(100vw - ${opts.padding_left}rem - 2 * ${opts.padding_right}rem);
clear: right;
}
.wideIfPossible {
position: relative;
width: ${opts.wide()}rem;
max-width: calc(100vw - ${opts.padding_left}rem - 2 * ${opts.padding_right}rem);
clear: right;
}
}
.widefixed {
position: relative;
width: ${opts.wide()}rem;
clear: right;
}
.verywide {
position: relative;
min-width: calc(100vw - calc(${
opts.padding_left + opts.padding_right
}rem + 0.5 * calc(100vw - ${opts.wide()}rem)));
max-width: calc(100vw - ${opts.padding_left}rem - 2 * ${opts.padding_right}rem);
clear: right;
}
.verywidefixed {
position: relative;
min-width: calc(100vw - calc(${
opts.padding_left + opts.padding_right
}rem + 0.5 * calc(100vw - ${opts.wide()}rem)));
clear: right;
}
.aside:not(.inline) {
display: none;
}
/* Used to prevent linebreaks just before a sidenote indicator. */
.nowrap {
white-space: nowrap;
}
.aside_counter {
display: none;
}
.preview {
background: var(--nearly-white);
box-shadow: 5px 5px 10px 0px rgba(68, 68, 68, 0.80);
padding: 1rem;
max-width: calc(100vw + 1rem - ${
opts.padding_left + opts.padding_right
}rem);
position: absolute;
border: 1px solid #DDDDDD;
border-left: 3px solid var(--green);
overflow: hidden;
}
.preview .aside {
display: none;
}
.preview.previewwide {
max-width: calc(8px + 100vw - calc(var(--padding-left) + var(--padding-right) + 0.5 * calc(100vw - var(--max-width-slightlywide))));
}
.preview.previewslightlywide {
max-width: calc(var(--max-width-slightlywide) + 8px);
}
.preview_content > *:first-child {
margin-top: 0;
}
.preview_content > *:last-child {
margin-bottom: 0;
}
@media (max-width: ${opts.wide_and_margins()}rem) {
.container_main > * {
margin: auto;
}
}
@media (min-width: ${opts.wide_and_margins()}rem) {
.aside, code .aside {
display: initial;
/* display: block; */
float: right;
clear: right;
position: relative;
width: ${opts.max_width_marginalia}rem;
margin-right: ${-(opts.spacing_marginalia +
opts.max_width_marginalia)}rem;
font-size: 0.9rem;
margin-bottom: 1em;
white-space: normal;
}
.aside a.ref.type, .aside a.ref.symbol, .aside code, .aside a.ref.param, .aside a.ref.value, .aside a.ref.member, .aside a.ref.fn, .aside .path {
font-size: 0.85rem;
}
.aside figcaption {
font-size: 0.9rem;
}
.aside:not(.inline) {
display: initial;
}
.aside_counter {
display: initial;
vertical-align: super;
font-size: 0.7em;
}
.preview .aside_counter {
display: none;
}
.aside > .aside_counter {
margin-right: 0.2rem;
}
.preview {
max-width: calc(${opts.max_width_main}rem + 1rem);
}
.preview .aside {
display: none;
}
}
@media (min-width: ${opts.wide_and_margins() + (opts.toc * 2)}rem) {
.toc {
font-size: 1rem;
width: ${opts.toc}rem;
position: fixed;
top: 4em;
transform: translateX(-${opts.toc + opts.padding_left}em) translateY(2rem);
height: 0;
overflow: visible;
}
.toc li {
list-style: none;
padding-left: 0.5em;
line-height: 1;
margin: 0.6em 0 !important;
}
.toc li.tocActive {
list-style-type: "☞";
}
.toc_top {
display: block !important;
}
nav.toc > ol {
padding: 0;
}
.toc code {
font-size: 0.9rem;
background: none;
}
}
`;
},
);
return new Invocation(macro, []);
}