Spaces:
Sleeping
Sleeping
Fix: Blue box reshaping with window size
Browse files
__pycache__/text_explanations.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/text_explanations.cpython-310.pyc and b/__pycache__/text_explanations.cpython-310.pyc differ
|
|
|
text_explanations.py
CHANGED
|
@@ -56,53 +56,81 @@ css = """#myProgress {
|
|
| 56 |
|
| 57 |
js_progress_bar = """
|
| 58 |
function move(start, end, total_duration, current_index, n_ann, total_ann) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
index = current_index + 1
|
| 63 |
-
progressText.innerText = `${index} / ${total_ann} (Completed: ${n_ann})`;
|
| 64 |
-
|
| 65 |
-
const waveform = document.querySelector('#audio_to_annotate #waveform div');
|
| 66 |
-
const shadowRoot = waveform.shadowRoot;
|
| 67 |
-
const canvases = shadowRoot.querySelector('.wrapper');
|
| 68 |
-
|
| 69 |
-
console.log(canvases.offsetWidth)
|
| 70 |
-
|
| 71 |
-
const leftOffsetPct = start / total_duration;
|
| 72 |
-
const widthPct = (end - start) / total_duration;
|
| 73 |
|
| 74 |
-
|
| 75 |
-
const blockColor = getComputedStyle(document.documentElement)
|
| 76 |
-
.getPropertyValue('--block-title-background-fill')
|
| 77 |
-
.trim() || 'red'; // Default to red if variable is not found
|
| 78 |
-
|
| 79 |
-
// Create a style element for the shadow DOM
|
| 80 |
-
const style = document.createElement('style');
|
| 81 |
style.textContent = `
|
|
|
|
| 82 |
.wrapper::after {
|
| 83 |
content: '';
|
| 84 |
position: absolute;
|
| 85 |
top: 0;
|
| 86 |
-
left: ${
|
| 87 |
-
width: ${
|
| 88 |
height: 100%;
|
| 89 |
background-color: blue;
|
| 90 |
z-index: 999;
|
| 91 |
opacity: 0.5;
|
|
|
|
| 92 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
-
shadowRoot.appendChild(style);
|
| 102 |
|
| 103 |
-
console.log(start + ' ' + end + ' ' + total_duration);
|
| 104 |
-
console.log(n_ann + ' ' + total_ann);
|
| 105 |
-
}
|
| 106 |
"""
|
| 107 |
|
| 108 |
|
|
|
|
| 56 |
|
| 57 |
js_progress_bar = """
|
| 58 |
function move(start, end, total_duration, current_index, n_ann, total_ann) {
|
| 59 |
+
var elem = document.getElementById("myBar");
|
| 60 |
+
elem.style.width = (n_ann / total_ann) * 100 + "%";
|
| 61 |
+
const index = current_index + 1;
|
| 62 |
+
progressText.innerText = `${index} / ${total_ann} (Completed: ${n_ann})`;
|
| 63 |
+
|
| 64 |
+
const waveform = document.querySelector('#audio_to_annotate #waveform div');
|
| 65 |
+
if (!waveform) return;
|
| 66 |
+
const shadowRoot = waveform.shadowRoot;
|
| 67 |
+
if (!shadowRoot) return;
|
| 68 |
+
const canvases = shadowRoot.querySelector('.wrapper');
|
| 69 |
+
if (!canvases) return;
|
| 70 |
+
|
| 71 |
+
const leftOffsetPct = start / total_duration;
|
| 72 |
+
const widthPct = (end - start) / total_duration;
|
| 73 |
+
|
| 74 |
+
// Ensure there is a single style element we can update
|
| 75 |
+
let style = shadowRoot.querySelector('style[data-overlay-style="true"]');
|
| 76 |
+
if (!style) {
|
| 77 |
+
style = document.createElement('style');
|
| 78 |
+
style.setAttribute('data-overlay-style', 'true');
|
| 79 |
+
shadowRoot.appendChild(style);
|
| 80 |
+
}
|
| 81 |
|
| 82 |
+
// Function to (re)compute and apply the rule
|
| 83 |
+
const applyOverlayRule = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
const w = canvases.offsetWidth || 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
style.textContent = `
|
| 87 |
+
.wrapper { position: relative; }
|
| 88 |
.wrapper::after {
|
| 89 |
content: '';
|
| 90 |
position: absolute;
|
| 91 |
top: 0;
|
| 92 |
+
left: ${w * leftOffsetPct}px;
|
| 93 |
+
width: ${w * widthPct}px;
|
| 94 |
height: 100%;
|
| 95 |
background-color: blue;
|
| 96 |
z-index: 999;
|
| 97 |
opacity: 0.5;
|
| 98 |
+
pointer-events: none;
|
| 99 |
}
|
| 100 |
+
`;
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
// Apply once now
|
| 104 |
+
applyOverlayRule();
|
| 105 |
+
|
| 106 |
+
// Attach a single ResizeObserver (memoized on the element)
|
| 107 |
+
if (!canvases.__overlayResizeObserver) {
|
| 108 |
+
const ro = new ResizeObserver(() => {
|
| 109 |
+
applyOverlayRule();
|
| 110 |
+
});
|
| 111 |
+
ro.observe(canvases);
|
| 112 |
+
canvases.__overlayResizeObserver = ro;
|
| 113 |
+
|
| 114 |
+
// Optional: also respond to window resizes (covers zoom/scrollbar layout edge cases)
|
| 115 |
+
const onWinResize = () => applyOverlayRule();
|
| 116 |
+
window.addEventListener('resize', onWinResize);
|
| 117 |
+
canvases.__overlayWinResizeCleanup = () => window.removeEventListener('resize', onWinResize);
|
| 118 |
+
}
|
| 119 |
|
| 120 |
+
// Optional: cleanup helper you can call when tearing down the UI
|
| 121 |
+
canvases.__cleanupOverlay = () => {
|
| 122 |
+
if (canvases.__overlayResizeObserver) {
|
| 123 |
+
canvases.__overlayResizeObserver.disconnect();
|
| 124 |
+
delete canvases.__overlayResizeObserver;
|
| 125 |
}
|
| 126 |
+
if (canvases.__overlayWinResizeCleanup) {
|
| 127 |
+
canvases.__overlayWinResizeCleanup();
|
| 128 |
+
delete canvases.__overlayWinResizeCleanup;
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
|
| 132 |
+
}
|
|
|
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
"""
|
| 135 |
|
| 136 |
|