summaryrefslogtreecommitdiffstats
path: root/compile_assets/scss/admonition.scss
blob: 4d4075f5a244f09fb40a9de33f489425d6e80021 (plain)
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
261
262
263
264
265
266
267
////
/// Copyright (c) 2016-2022 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////

@use "sass:color";
@use "sass:list";
@use "./lib";

// ----------------------------------------------------------------------------
// Variables
// ----------------------------------------------------------------------------

/// Admonition flavours
$admonitions: (
  // pencil
  admonish-note: $clr-blue-a200
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20.71 7.04c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.37-.39-1.02-.39-1.41 0l-1.84 1.83 3.75 3.75M3 17.25V21h3.75L17.81 9.93l-3.75-3.75L3 17.25z'/></svg>",
  // clipboard-text
  admonish-abstract admonish-summary admonish-tldr: $clr-light-blue-a400
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17 9H7V7h10m0 6H7v-2h10m-3 6H7v-2h7M12 3a1 1 0 0 1 1 1 1 1 0 0 1-1 1 1 1 0 0 1-1-1 1 1 0 0 1 1-1m7 0h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2z'/></svg>",
  // information
  admonish-info admonish-todo: $clr-cyan-a700
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 9h-2V7h2m0 10h-2v-6h2m-1-9A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2z'/></svg>",
  // fire
  admonish-tip admonish-hint admonish-important: $clr-teal-a700
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M17.66 11.2c-.23-.3-.51-.56-.77-.82-.67-.6-1.43-1.03-2.07-1.66C13.33 7.26 13 4.85 13.95 3c-.95.23-1.78.75-2.49 1.32-2.59 2.08-3.61 5.75-2.39 8.9.04.1.08.2.08.33 0 .22-.15.42-.35.5-.23.1-.47.04-.66-.12a.58.58 0 0 1-.14-.17c-1.13-1.43-1.31-3.48-.55-5.12C5.78 10 4.87 12.3 5 14.47c.06.5.12 1 .29 1.5.14.6.41 1.2.71 1.73 1.08 1.73 2.95 2.97 4.96 3.22 2.14.27 4.43-.12 6.07-1.6 1.83-1.66 2.47-4.32 1.53-6.6l-.13-.26c-.21-.46-.77-1.26-.77-1.26m-3.16 6.3c-.28.24-.74.5-1.1.6-1.12.4-2.24-.16-2.9-.82 1.19-.28 1.9-1.16 2.11-2.05.17-.8-.15-1.46-.28-2.23-.12-.74-.1-1.37.17-2.06.19.38.39.76.63 1.06.77 1 1.98 1.44 2.24 2.8.04.14.06.28.06.43.03.82-.33 1.72-.93 2.27z'/></svg>",
  // check-bold
  admonish-success admonish-check admonish-done: $clr-green-a700
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m9 20.42-6.21-6.21 2.83-2.83L9 14.77l9.88-9.89 2.83 2.83L9 20.42z'/></svg>",
  // help-circle
  admonish-question admonish-help admonish-faq: $clr-light-green-a700
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='m15.07 11.25-.9.92C13.45 12.89 13 13.5 13 15h-2v-.5c0-1.11.45-2.11 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41a2 2 0 0 0-2-2 2 2 0 0 0-2 2H8a4 4 0 0 1 4-4 4 4 0 0 1 4 4 3.2 3.2 0 0 1-.93 2.25M13 19h-2v-2h2M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10c0-5.53-4.5-10-10-10z'/></svg>",
  // alert
  admonish-warning admonish-caution admonish-attention: $clr-orange-a400
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M13 14h-2V9h2m0 9h-2v-2h2M1 21h22L12 2 1 21z'/></svg>",
  // close-thick
  admonish-failure admonish-fail admonish-missing: $clr-red-a200
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M20 6.91 17.09 4 12 9.09 6.91 4 4 6.91 9.09 12 4 17.09 6.91 20 12 14.91 17.09 20 20 17.09 14.91 12 20 6.91z'/></svg>",
  // lighting-bold
  admonish-danger admonish-error: $clr-red-a400
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M11 15H6l7-14v8h5l-7 14v-8z'/></svg>",
  // bug
  admonish-bug: $clr-pink-a400
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 12h-4v-2h4m0 6h-4v-2h4m6-6h-2.81a5.985 5.985 0 0 0-1.82-1.96L17 4.41 15.59 3l-2.17 2.17a6.002 6.002 0 0 0-2.83 0L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8z'/></svg>",
  // format-list-numbered
  admonish-example: $clr-deep-purple-a200
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M7 13v-2h14v2H7m0 6v-2h14v2H7M7 7V5h14v2H7M3 8V5H2V4h2v4H3m-1 9v-1h3v4H2v-1h2v-.5H3v-1h1V17H2m2.25-7a.75.75 0 0 1 .75.75c0 .2-.08.39-.21.52L3.12 13H5v1H2v-.92L4 11H2v-1h2.25z'/></svg>",
  // format-quote-close
  admonish-quote admonish-cite: $clr-grey
    "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M14 17h3l2-4V7h-6v6h3M6 17h3l2-4V7H5v6h3l-2 4z'/></svg>"
) !default;

// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Static content - base for all admonitions
// ----------------------------------------------------------------------------

// Admonition
:is(.admonition) {
  display: flow-root;
  margin: 1.5625em 0;
  padding: 0 1.2rem;
  // variable provided downstream by mdbook
  color: var(--fg);
  // font-size: 1.2rem;
  page-break-inside: avoid;
  // variable provided downstream by mdbook
  background-color: var(--bg);
  border: 0 solid black;
  border-inline-start-width: 0.4rem;
  border-radius: 0.2rem;
  box-shadow:
    0 0.2rem 1rem rgba(0, 0, 0, 0.05),
    0 0 0.1rem rgba(0, 0, 0, 0.1);

  // [print]: Omit shadow as it may lead to rendering errors
  @media print {
    box-shadow: none;
  }

  // Hack: Chrome exhibits a weird issue where it will set nested elements to
  // content-box. Doesn't happen in other browsers, so looks like a bug.
  > * {
    box-sizing: border-box;
  }

  // Adjust vertical spacing for nested admonitions
  :is(.admonition) {
    margin-top: 1em;
    margin-bottom: 1em;
  }

  // Adjust spacing for single-child tabbed block container
  > .tabbed-set:only-child {
    margin-top: 0;
  }

  // Adjust spacing on last child
  html & > :last-child {
    margin-bottom: 1.2rem;
  }
}

// Anchor links
a.admonition-anchor-link {
  // Don't display the link by default
  display: none;

  // Position to the left of the element to link to
  position: absolute;
  left: -1.2rem;
  // Ensure we have enough padding, so that we can move the mouse to click on it
  padding-right: 1rem;

  &:link,
  &:visited {
    // Don't make links colored (override to standard text color)
    // variable provided downstream by mdbook
    color: var(--fg);
  }
  &:link:hover,
  &:visited:hover {
    // No underline on hover
    text-decoration: none;
  }

  &::before {
    content: "§";
  }
}

// Admonition title
:is(.admonition-title, summary.admonition-title) {
  position: relative;
  min-height: 4rem;
  margin-block: 0;
  margin-inline: -1.6rem -1.2rem;
  padding-block: 0.8rem;
  padding-inline: 4.4rem 1.2rem;
  font-weight: 700;
  background-color: color.adjust($clr-blue-a200, $alpha: -0.9);
  // Always print title bar tint
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
  // Compatilility with rendering markdown inside the content
  display: flex;

  // Compatilility with rendering markdown inside the content
  & p {
    margin: 0;
  }

  // Adjust spacing for title-only admonitions
  html &:last-child {
    margin-bottom: 0;
  }

  // Admonition icon
  &::before {
    position: absolute;
    top: 0.625em;
    inset-inline-start: 1.6rem;
    width: 2rem;
    height: 2rem;
    background-color: $clr-blue-a200;
    // Always print icon
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
    mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
    -webkit-mask-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"></svg>');
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
    mask-size: contain;
    -webkit-mask-size: contain;
    content: "";
  }

  // Show anchor link on hover over title
  &:hover a.admonition-anchor-link {
    display: initial;
  }
}

summary.admonition-title {
  details.admonition > &::after {
    position: absolute;
    top: 0.625em;
    inset-inline-end: 1.6rem;
    height: 2rem;
    width: 2rem;
    background-color: currentcolor;
    mask-image: var(--md-details-icon);
    -webkit-mask-image: var(--md-details-icon);
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
    mask-size: contain;
    -webkit-mask-size: contain;
    content: "";
    transform: rotate(0deg);
    transition: transform 0.25s;
  }

  details[open].admonition > &::after {
    transform: rotate(90deg);
  }
}

:root {
  --md-details-icon: url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
}

// Generate rules for each specified admonition variant
@include lib.from-admonitions($admonitions);

// ----------------------------------------------------------------------------
// Rules: themes
// ----------------------------------------------------------------------------
//
// One rule per builtin theme in mdbook, overriding the default fg/bg if matched
//
// This must be after the variant CSS, so it can override they styles set there

.navy {
  & :is(.admonition) {
    background-color: var(--sidebar-bg);
  }
}

.ayu,
.coal {
  & :is(.admonition) {
    background-color: var(--theme-hover);
  }
}

.rust {
  & :is(.admonition) {
    background-color: var(--sidebar-bg);
    color: var(--sidebar-fg);
  }

  & .admonition-anchor-link {
    &:link,
    &:visited {
      color: var(--sidebar-fg);
    }
  }
}