|
1 | 1 | <style is:global> |
2 | 2 | .station-content pre:not([data-python-output]) { |
3 | 3 | position: relative; |
| 4 | + width: 100%; |
| 5 | + max-width: 100%; |
| 6 | + min-width: 0; |
4 | 7 | margin-top: 1.5rem; |
5 | 8 | overflow: hidden; |
6 | 9 | border: 1px solid rgb(16 29 39 / 18%); |
|
10 | 13 |
|
11 | 14 | .station-content pre:not([data-python-output]) .code-header { |
12 | 15 | display: flex; |
| 16 | + min-width: 0; |
13 | 17 | align-items: center; |
14 | 18 | justify-content: space-between; |
| 19 | + gap: 1rem; |
15 | 20 | min-height: 2.5rem; |
16 | 21 | padding: 0.4rem 0.75rem; |
17 | 22 | border-bottom: 1px solid rgb(16 29 39 / 10%); |
18 | 23 | background: var(--color-paper); |
19 | 24 | } |
20 | 25 |
|
21 | 26 | .station-content pre:not([data-python-output]) .code-lang { |
| 27 | + overflow: hidden; |
| 28 | + color: var(--color-brand); |
22 | 29 | font-family: var(--font-mono); |
23 | 30 | font-size: 0.65rem; |
24 | 31 | font-weight: 700; |
25 | 32 | letter-spacing: 0.12em; |
26 | | - color: var(--color-brand); |
| 33 | + text-overflow: ellipsis; |
27 | 34 | text-transform: uppercase; |
| 35 | + white-space: nowrap; |
28 | 36 | } |
29 | 37 |
|
30 | 38 | .station-content pre:not([data-python-output]) code { |
31 | 39 | display: block; |
32 | | - min-width: max-content; |
| 40 | + width: 100%; |
| 41 | + max-width: 100%; |
| 42 | + min-width: 0; |
33 | 43 | overflow-x: auto; |
34 | 44 | padding: 1rem 1.1rem; |
35 | 45 | background: transparent !important; |
36 | 46 | font-family: var(--font-mono); |
37 | 47 | font-size: 0.9rem; |
38 | 48 | line-height: 1.8; |
| 49 | + white-space: pre; |
| 50 | + overscroll-behavior-x: contain; |
| 51 | + scrollbar-width: thin; |
| 52 | + -webkit-overflow-scrolling: touch; |
| 53 | + } |
| 54 | + |
| 55 | + .station-content pre:not([data-python-output]) code::-webkit-scrollbar { |
| 56 | + height: 0.45rem; |
| 57 | + } |
| 58 | + |
| 59 | + .station-content pre:not([data-python-output]) code::-webkit-scrollbar-track { |
| 60 | + background: transparent; |
| 61 | + } |
| 62 | + |
| 63 | + .station-content pre:not([data-python-output]) code::-webkit-scrollbar-thumb { |
| 64 | + border-radius: 999px; |
| 65 | + background: rgb(100 116 139 / 35%); |
39 | 66 | } |
40 | 67 |
|
41 | 68 | .station-content :not(pre) > code { |
| 69 | + max-width: 100%; |
42 | 70 | border-bottom: 2px solid var(--color-accent); |
43 | 71 | background: #edf4ff; |
44 | 72 | padding: 0.1rem 0.3rem; |
45 | 73 | color: var(--color-ink); |
46 | 74 | font-family: var(--font-mono); |
47 | 75 | font-size: 0.9em; |
48 | 76 | font-weight: 600; |
| 77 | + overflow-wrap: anywhere; |
49 | 78 | } |
50 | 79 |
|
51 | 80 | .station-content pre:not([data-python-output]) + p, |
|
59 | 88 | display: grid; |
60 | 89 | width: 1.75rem; |
61 | 90 | height: 1.75rem; |
| 91 | + flex-shrink: 0; |
62 | 92 | place-items: center; |
63 | 93 | border: 1px solid rgb(16 29 39 / 15%); |
64 | 94 | border-radius: 0.35rem; |
|
115 | 145 | opacity: 1; |
116 | 146 | transform: scale(1); |
117 | 147 | } |
| 148 | + |
| 149 | + @media (max-width: 39.999rem) { |
| 150 | + .station-content pre:not([data-python-output]) { |
| 151 | + border-radius: 0.4rem; |
| 152 | + } |
| 153 | + |
| 154 | + .station-content pre:not([data-python-output]) code { |
| 155 | + padding: 0.9rem; |
| 156 | + font-size: 0.8rem; |
| 157 | + line-height: 1.7; |
| 158 | + } |
| 159 | + |
| 160 | + .station-content pre:not([data-python-output]) .code-header { |
| 161 | + padding-right: 0.6rem; |
| 162 | + padding-left: 0.6rem; |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + @media (prefers-reduced-motion: reduce) { |
| 167 | + .copy-btn, |
| 168 | + .copy-btn svg { |
| 169 | + transition: none; |
| 170 | + } |
| 171 | + } |
118 | 172 | </style> |
119 | 173 |
|
120 | 174 | <script> |
|
149 | 203 | header.className = "code-header"; |
150 | 204 |
|
151 | 205 | const languageLabel = document.createElement("span"); |
| 206 | + |
152 | 207 | languageLabel.className = "code-lang"; |
153 | 208 | languageLabel.textContent = language; |
154 | 209 |
|
155 | 210 | const copyButton = document.createElement("button"); |
| 211 | + |
156 | 212 | copyButton.type = "button"; |
157 | 213 | copyButton.className = "copy-btn"; |
| 214 | + |
158 | 215 | copyButton.setAttribute("aria-label", "Copiar código"); |
| 216 | + |
159 | 217 | copyButton.setAttribute("title", "Copiar código"); |
| 218 | + |
160 | 219 | copyButton.innerHTML = ` |
161 | | - <svg class="icon" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
162 | | - <rect x="9" y="9" width="12" height="12" rx="2"></rect> |
163 | | - <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path> |
| 220 | + <svg |
| 221 | + class="icon" |
| 222 | + aria-hidden="true" |
| 223 | + viewBox="0 0 24 24" |
| 224 | + fill="none" |
| 225 | + stroke-width="2" |
| 226 | + stroke-linecap="round" |
| 227 | + stroke-linejoin="round" |
| 228 | + > |
| 229 | + <rect |
| 230 | + x="9" |
| 231 | + y="9" |
| 232 | + width="12" |
| 233 | + height="12" |
| 234 | + rx="2" |
| 235 | + ></rect> |
| 236 | + |
| 237 | + <path |
| 238 | + d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" |
| 239 | + ></path> |
164 | 240 | </svg> |
165 | | - <svg class="check" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"> |
166 | | - <polyline points="20 6 9 17 4 12"></polyline> |
| 241 | + |
| 242 | + <svg |
| 243 | + class="check" |
| 244 | + aria-hidden="true" |
| 245 | + viewBox="0 0 24 24" |
| 246 | + fill="none" |
| 247 | + stroke-width="2.5" |
| 248 | + stroke-linecap="round" |
| 249 | + stroke-linejoin="round" |
| 250 | + > |
| 251 | + <polyline |
| 252 | + points="20 6 9 17 4 12" |
| 253 | + ></polyline> |
167 | 254 | </svg> |
168 | 255 | `; |
169 | 256 |
|
170 | 257 | copyButton.addEventListener("click", async () => { |
171 | 258 | try { |
172 | 259 | await copyText(code.textContent ?? ""); |
| 260 | + |
173 | 261 | copyButton.classList.add("is-copied"); |
| 262 | + |
174 | 263 | copyButton.setAttribute("aria-label", "Código copiado"); |
175 | 264 |
|
176 | 265 | window.setTimeout(() => { |
177 | 266 | copyButton.classList.remove("is-copied"); |
| 267 | + |
178 | 268 | copyButton.setAttribute("aria-label", "Copiar código"); |
179 | 269 | }, 1_400); |
180 | 270 | } catch { |
|
191 | 281 | } |
192 | 282 |
|
193 | 283 | setupCodeBlocks(); |
| 284 | + |
194 | 285 | document.addEventListener("astro:page-load", setupCodeBlocks); |
195 | 286 | </script> |
0 commit comments