Spaces:
Paused
Paused
File size: 11,635 Bytes
e9f1e84 e9a92c8 e9f1e84 5eeaf48 e9f1e84 5eeaf48 e9f1e84 5eeaf48 e9f1e84 b29876c e9f1e84 6f39f7c e9f1e84 5eeaf48 e9f1e84 b954a83 3d482be e9f1e84 3d482be e9a92c8 e9f1e84 3d482be e9a92c8 3d482be e9f1e84 3d482be e9a92c8 3d482be e9f1e84 5eeaf48 e9a92c8 e9f1e84 3d482be e9a92c8 3d482be e9a92c8 3d482be e9a92c8 3d482be e9a92c8 3d482be e9a92c8 3d482be e9f1e84 3d482be e9f1e84 e9a92c8 3d482be e9a92c8 e9f1e84 e9a92c8 e9f1e84 3d482be d6d612b e9f1e84 3d482be e9f1e84 e9a92c8 e9f1e84 5eeaf48 e9f1e84 5eeaf48 e9f1e84 5eeaf48 b954a83 5eeaf48 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 e9f1e84 b954a83 5eeaf48 e9f1e84 5eeaf48 b954a83 5eeaf48 e9f1e84 5eeaf48 b954a83 5eeaf48 b954a83 5eeaf48 e9f1e84 5eeaf48 b954a83 e9f1e84 b954a83 5eeaf48 e9f1e84 5eeaf48 e9a92c8 | 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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | """Fixed-position assets for three native Gradio mechanics-tutor dialogs."""
from __future__ import annotations
FLOATING_TUTOR_CSS = r"""
:where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
) {
background: linear-gradient(110deg, #6d28d9, #db2777) !important;
border: 1px solid rgba(255, 255, 255, .48) !important;
border-radius: 999px !important;
box-shadow: 0 14px 34px rgba(76, 29, 149, .36) !important;
color: white !important;
font-weight: 850 !important;
left: auto !important;
margin: 0 !important;
min-height: 44px !important;
min-width: 142px !important;
opacity: 1 !important;
pointer-events: auto !important;
position: fixed !important;
right: max(18px, env(safe-area-inset-right)) !important;
visibility: visible !important;
width: auto !important;
z-index: 2147483000 !important;
}
:where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
) button {
background: transparent !important;
border: 0 !important;
border-radius: inherit !important;
color: inherit !important;
font-weight: inherit !important;
}
:where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
):hover {
box-shadow: 0 17px 40px rgba(76, 29, 149, .44) !important;
}
#floating-tutor-launcher-top {
bottom: auto !important;
top: max(18px, env(safe-area-inset-top)) !important;
}
#floating-tutor-launcher-middle {
bottom: auto !important;
top: 50% !important;
transform: translateY(-50%) !important;
}
#floating-tutor-launcher {
bottom: max(18px, env(safe-area-inset-bottom)) !important;
top: auto !important;
}
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) {
background: rgba(255, 255, 255, .99) !important;
border: 1px solid rgba(109, 40, 217, .24) !important;
border-radius: 22px !important;
box-shadow: 0 24px 68px rgba(30, 41, 59, .32) !important;
left: auto !important;
margin: 0 !important;
max-height: calc(100vh - 36px) !important;
overflow-x: hidden !important;
overflow-y: auto !important;
padding: 14px !important;
position: fixed !important;
right: 178px !important;
width: min(430px, calc(100vw - 210px)) !important;
z-index: 2147482999 !important;
}
#floating-tutor-panel-top {
bottom: auto !important;
top: max(18px, env(safe-area-inset-top)) !important;
}
#floating-tutor-panel-middle {
bottom: auto !important;
top: 50% !important;
transform: translateY(-50%) !important;
}
#floating-tutor-panel {
bottom: max(18px, env(safe-area-inset-bottom)) !important;
top: auto !important;
}
.floating-tutor-dialog-header {
align-items: center;
border-bottom: 1px solid #e2e8f0;
margin-bottom: 7px;
padding-bottom: 7px;
}
.floating-tutor-dialog-title h3 {
color: #172554;
font-size: 17px;
margin: 0 0 2px;
}
.floating-tutor-dialog-title p {
color: #7c3aed;
font-size: 10px;
font-weight: 850;
letter-spacing: .06em;
margin: 0;
}
.floating-tutor-close {
border-radius: 50% !important;
flex: 0 0 36px !important;
font-size: 18px !important;
height: 36px !important;
min-width: 36px !important;
padding: 0 !important;
width: 36px !important;
}
.floating-open-full-tutor {
color: #6d28d9 !important;
font-size: 12px !important;
margin-bottom: 5px !important;
}
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) .floating-tutor-context {
background: linear-gradient(100deg, #eef2ff, #fdf2f8);
border-radius: 12px;
font-size: 11px;
padding: 7px 10px;
}
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) .floating-tutor-context h3 { font-size: 13px; margin: 0 0 3px; }
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) .floating-tutor-context p { margin: 0; }
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) .floating-tutor-chat { min-height: 210px; }
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) .floating-tutor-composer {
background: rgba(255, 255, 255, .99);
border: 1px solid rgba(109, 40, 217, .15);
border-radius: 14px;
bottom: 0;
padding: 9px !important;
position: sticky;
z-index: 2;
}
.floating-tutor-composer-note { font-size: 11px; margin: 0; }
.floating-tutor-status { font-size: 10px; margin: 0; }
body.exam-mode-active :where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
) {
display: none !important;
}
@media (max-width: 640px) {
:where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
) {
min-height: 40px !important;
min-width: 118px !important;
right: max(8px, env(safe-area-inset-right)) !important;
}
:where(
#floating-tutor-panel-top,
#floating-tutor-panel-middle,
#floating-tutor-panel
) {
max-height: calc(100vh - 20px) !important;
right: max(8px, env(safe-area-inset-right)) !important;
width: calc(100vw - 16px) !important;
}
}
@media (prefers-reduced-motion: reduce) {
:where(
#floating-tutor-launcher-top,
#floating-tutor-launcher-middle,
#floating-tutor-launcher
) {
transition: none !important;
}
}
"""
# Every visible launcher below is the real native Gradio component. JavaScript
# only corrects fixed positioning under transformed or scrolling ancestors; it
# never clones, clicks, hides, reparents, or replaces a Gradio control.
FLOATING_TUTOR_VIEWPORT_JS = r"""
() => {
const SLOTS = [
{name: "top", launcherId: "floating-tutor-launcher-top", panelId: "floating-tutor-panel-top"},
{name: "middle", launcherId: "floating-tutor-launcher-middle", panelId: "floating-tutor-panel-middle"},
{name: "bottom", launcherId: "floating-tutor-launcher", panelId: "floating-tutor-panel"},
];
const viewportBounds = () => {
const viewport = window.visualViewport;
const left = viewport ? viewport.offsetLeft : 0;
const top = viewport ? viewport.offsetTop : 0;
const width = viewport ? viewport.width : document.documentElement.clientWidth;
const height = viewport ? viewport.height : document.documentElement.clientHeight;
const inset = window.matchMedia("(max-width: 640px)").matches ? 8 : 18;
return {left, top, width, height, right: left + width, bottom: top + height, inset};
};
const clamp = (value, minimum, maximum) =>
Math.min(Math.max(value, minimum), Math.max(minimum, maximum));
const setFixedPosition = (element, desiredLeft, desiredTop, zIndex) => {
if (!element) return;
element.style.setProperty("position", "fixed", "important");
element.style.setProperty("left", `${desiredLeft}px`, "important");
element.style.setProperty("top", `${desiredTop}px`, "important");
element.style.setProperty("right", "auto", "important");
element.style.setProperty("bottom", "auto", "important");
element.style.setProperty("transform", "none", "important");
element.style.setProperty("z-index", String(zIndex), "important");
// Correct coordinates when a transformed Gradio ancestor establishes a
// containing block for fixed descendants. The component remains native.
const actual = element.getBoundingClientRect();
if (Math.abs(actual.left - desiredLeft) > 0.5) {
element.style.setProperty(
"left",
`${desiredLeft + desiredLeft - actual.left}px`,
"important",
);
}
if (Math.abs(actual.top - desiredTop) > 0.5) {
element.style.setProperty(
"top",
`${desiredTop + desiredTop - actual.top}px`,
"important",
);
}
};
const slotTop = (name, height, bounds) => {
const safeTop = bounds.top + bounds.inset;
const safeBottom = bounds.bottom - bounds.inset;
if (name === "top") return safeTop;
if (name === "middle") return safeTop + Math.max(0, (safeBottom - safeTop - height) / 2);
return safeBottom - height;
};
const positionSlot = (slot) => {
const launcher = document.getElementById(slot.launcherId);
if (!launcher) return;
const bounds = viewportBounds();
const launcherRect = launcher.getBoundingClientRect();
const launcherWidth = Math.max(118, launcherRect.width || 142);
const launcherHeight = Math.max(40, launcherRect.height || 44);
const launcherLeft = bounds.right - bounds.inset - launcherWidth;
const launcherTop = slotTop(slot.name, launcherHeight, bounds);
setFixedPosition(launcher, launcherLeft, launcherTop, 2147483000);
launcher.style.setProperty("opacity", "1", "important");
launcher.style.setProperty("visibility", "visible", "important");
launcher.style.setProperty("pointer-events", "auto", "important");
const panel = document.getElementById(slot.panelId);
if (!panel) return;
const availableWidth = Math.max(260, bounds.width - bounds.inset * 2);
const desktopWidth = Math.min(430, Math.max(260, availableWidth - launcherWidth - 14));
const mobile = window.matchMedia("(max-width: 640px)").matches;
const panelWidth = mobile ? availableWidth : desktopWidth;
const maximumHeight = Math.max(180, bounds.height - bounds.inset * 2);
panel.style.setProperty("width", `${panelWidth}px`, "important");
panel.style.setProperty("max-height", `${maximumHeight}px`, "important");
const panelRect = panel.getBoundingClientRect();
const panelHeight = Math.min(maximumHeight, Math.max(260, panelRect.height || 560));
const safeLeft = bounds.left + bounds.inset;
const panelLeft = mobile
? safeLeft
: clamp(launcherLeft - 12 - panelWidth, safeLeft, bounds.right - bounds.inset - panelWidth);
const panelTop = slotTop(slot.name, panelHeight, bounds);
setFixedPosition(panel, panelLeft, panelTop, 2147482999);
const button = launcher.matches("button") ? launcher : launcher.querySelector("button");
if (button && button.dataset.threeTutorPositionHook !== "true") {
button.dataset.threeTutorPositionHook = "true";
button.addEventListener("click", () => {
window.requestAnimationFrame(positionAll);
window.setTimeout(positionAll, 120);
window.setTimeout(positionAll, 360);
});
}
};
const positionAll = () => SLOTS.forEach(positionSlot);
if (!window.__m1ThreeTutorLaunchersInstalled) {
window.__m1ThreeTutorLaunchersInstalled = true;
let frame = 0;
const schedulePosition = () => {
window.cancelAnimationFrame(frame);
frame = window.requestAnimationFrame(positionAll);
};
window.addEventListener("scroll", schedulePosition, {passive: true, capture: true});
document.addEventListener("scroll", schedulePosition, {passive: true, capture: true});
window.addEventListener("resize", schedulePosition, {passive: true});
window.addEventListener("orientationchange", schedulePosition, {passive: true});
if (window.visualViewport) {
window.visualViewport.addEventListener("scroll", schedulePosition, {passive: true});
window.visualViewport.addEventListener("resize", schedulePosition, {passive: true});
}
new MutationObserver(schedulePosition).observe(document.body, {
childList: true,
subtree: true,
});
if (window.ResizeObserver) {
const observer = new ResizeObserver(schedulePosition);
observer.observe(document.documentElement);
observer.observe(document.body);
window.__m1ThreeTutorResizeObserver = observer;
}
}
positionAll();
return [];
}
"""
|