techfreakworm commited on
Commit
de7d60a
·
unverified ·
1 Parent(s): d625691

fix(ui): stop layout 'dance' on mobile — cage audio waveform width

Browse files

The Gradio audio component uses wavesurfer.js, which renders the
waveform at a pixel-per-second rate. For a 60s clip that's ~600px wide,
which on mobile (~360px viewport) pushes the parent column past the
viewport edge. Worse: flex children default to min-width: auto, meaning
they CANNOT shrink below their intrinsic content size — so the column
itself widens to fit the waveform, and the whole layout 'dances' between
the pre-generation narrow state and the post-generation wide state.

Fix:
- min-width: 0 on .ams-content + .ams-body > * so flex children
can shrink below content intrinsic width
- overflow: hidden + max-width: 100% on .ams-out-audio so the
waveform is clipped at the column edge
- width/max-width: 100% on every wavesurfer container layer
(.component-wrapper, .waveform-container, #waveform, canvas)
- max-width: 100% + overflow-x: hidden on .ams-content as a
last-line defense against any other wide child

Files changed (1) hide show
  1. theme.py +42 -0
theme.py CHANGED
@@ -195,6 +195,14 @@ main, .contain {{
195
  .ams-body {{
196
  gap:12px !important;
197
  align-items:stretch !important;
 
 
 
 
 
 
 
 
198
  }}
199
 
200
  /* ============================================================
@@ -287,6 +295,19 @@ main, .contain {{
287
  border-radius:{RADIUS} !important;
288
  padding:14px !important;
289
  min-height:540px;
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }}
291
  .ams-tab-pane {{
292
  background:transparent !important;
@@ -471,6 +492,27 @@ main, .contain {{
471
  }}
472
  .ams-content .ams-out-audio {{
473
  min-height:90px !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  }}
475
  .ams-content .ams-out-meta {{
476
  min-height:80px !important;
 
195
  .ams-body {{
196
  gap:12px !important;
197
  align-items:stretch !important;
198
+ /* Same flex-shrink fix as ``.ams-content``: without ``min-width: 0`` on
199
+ the children, a wide audio waveform inside the content column can
200
+ blow the row past the viewport on mobile. */
201
+ max-width:100% !important;
202
+ overflow:hidden !important;
203
+ }}
204
+ .ams-body > * {{
205
+ min-width:0 !important;
206
  }}
207
 
208
  /* ============================================================
 
295
  border-radius:{RADIUS} !important;
296
  padding:14px !important;
297
  min-height:540px;
298
+ /* Flex children default to ``min-width: auto`` which means they CANNOT
299
+ shrink below their content's intrinsic width. The wavesurfer.js
300
+ waveform renders pixel-perfect to the audio duration (e.g. a 60 s
301
+ clip wants ~600 px), which would push this column wider than the
302
+ viewport on mobile and cause the layout to "dance" between
303
+ pre-generation and post-generation widths. ``min-width: 0`` lets
304
+ the column shrink, and the audio block's own ``overflow: hidden``
305
+ clips the inner waveform. */
306
+ min-width:0 !important;
307
+ /* Match: the row child is also constrained so the audio waveform
308
+ can't push it out of bounds on mobile. */
309
+ max-width:100% !important;
310
+ overflow-x:hidden !important;
311
  }}
312
  .ams-tab-pane {{
313
  background:transparent !important;
 
492
  }}
493
  .ams-content .ams-out-audio {{
494
  min-height:90px !important;
495
+ /* Wavesurfer's waveform renders one pixel per audio frame at the
496
+ ``minPxPerSec`` rate; for a 60 s clip that can exceed the
497
+ column's width. Cage it so it can't push the parent wider. */
498
+ min-width:0 !important;
499
+ max-width:100% !important;
500
+ overflow:hidden !important;
501
+ }}
502
+ .ams-content .ams-out-audio .component-wrapper,
503
+ .ams-content .ams-out-audio .waveform-container,
504
+ .ams-content .ams-out-audio [data-testid^="waveform"],
505
+ .ams-content .ams-out-audio #waveform {{
506
+ width:100% !important;
507
+ max-width:100% !important;
508
+ min-width:0 !important;
509
+ overflow:hidden !important;
510
+ }}
511
+ /* Wavesurfer renders a <canvas> sized in CSS pixels from the audio
512
+ duration; force it to the wrapper's width on small screens. */
513
+ .ams-content .ams-out-audio canvas,
514
+ .ams-content .ams-out-audio wave {{
515
+ max-width:100% !important;
516
  }}
517
  .ams-content .ams-out-meta {{
518
  min-height:80px !important;