@@ -19,26 +19,22 @@ const highlighted = await codeToHtml(code, {
1919---
2020
2121<figure
22- class =" my-0 rounded-lg overflow-hidden border border-neutral-25 text-step--1"
22+ class =" my-0 w-full min-w-0 rounded-lg border border-neutral-25 text-step--1"
2323 data-component =" code-block"
2424>
25- { /* Title bar */ }
2625 <div
27- class =" flex items-center gap-space-xs px-space-s py-space-2xs bg-[#f6f8fa] border-b border-neutral-25"
26+ class =" flex items-center gap-space-xs px-space-s py-space-2xs bg-[#f6f8fa] border-b border-neutral-25 rounded-t-lg "
2827 >
29- { /* Decorative window dots */ }
3028 <div class =" flex items-center gap-[6px] shrink-0" aria-hidden =" true" >
3129 <span class =" block h-3 w-3 rounded-full bg-[#ff5f57]" ></span >
3230 <span class =" block h-3 w-3 rounded-full bg-[#febc2e]" ></span >
3331 <span class =" block h-3 w-3 rounded-full bg-[#28c840]" ></span >
3432 </div >
3533
36- { /* Filename / title */ }
37- <span class =" flex-1 text-neutral-900 text-step--2 truncate" >
34+ <span class =" flex-1 min-w-0 truncate text-neutral-900 text-step--2" >
3835 { title ?? language }
3936 </span >
4037
41- { /* Copy button */ }
4238 <button
4339 type =" button"
4440 class =" copy-btn shrink-0 inline-flex items-center gap-[5px] cursor-pointer
@@ -75,19 +71,61 @@ const highlighted = await codeToHtml(code, {
7571 </button >
7672 </div >
7773
78- { /* Highlighted code */ }
7974 <div
80- class =" overflow-x-auto
81- [&_pre]:m-0 [&_pre]:p-space-s [&_pre]:leading-relaxed [&_pre]:bg-white!
82- [&_code]:font-mono [&_code]:text-step--1
83- [&_.line]:min-h-[1.5em]"
75+ class =" code-block-scroll rounded-b-lg"
76+ data-lenis-prevent-touch
8477 set:html ={ highlighted }
8578 />
8679</figure >
8780
81+ <style >
82+ /* Shiki: block .line + newline nodes between spans; contain:inline-size for mobile scroll. */
83+ [data-component='code-block'] {
84+ contain: inline-size;
85+ }
86+
87+ [data-component='code-block'] .code-block-scroll {
88+ display: block;
89+ width: 100%;
90+ min-width: 0;
91+ overflow-x: auto;
92+ overflow-y: hidden;
93+ overscroll-behavior-x: contain;
94+ -webkit-overflow-scrolling: touch;
95+ touch-action: pan-x pan-y;
96+ line-height: 1.5;
97+ }
98+
99+ [data-component='code-block'] .code-block-scroll :global(pre) {
100+ display: block;
101+ width: max-content;
102+ min-width: 100%;
103+ margin: 0;
104+ padding: var(--spacing-space-s);
105+ background-color: #fff !important;
106+ white-space: normal;
107+ }
108+
109+ [data-component='code-block'] .code-block-scroll :global(code),
110+ [data-component='code-block'] .code-block-scroll :global(.line) {
111+ display: block;
112+ width: max-content;
113+ min-width: 100%;
114+ font-family: ui-monospace, monospace;
115+ font-size: var(--text-step--1);
116+ line-height: inherit;
117+ }
118+
119+ [data-component='code-block'] .code-block-scroll :global(.line) {
120+ white-space: pre;
121+ }
122+ </style >
123+
88124<script >
89125 document.addEventListener('click', (e) => {
90- const btn = (e.target as Element)?.closest<HTMLButtonElement>('.copy-btn')
126+ const btn = (e.target as Element)?.closest<HTMLButtonElement>(
127+ '[data-component="code-block"] .copy-btn'
128+ )
91129 if (!btn) return
92130
93131 const code = btn.dataset.code ?? ''
0 commit comments