Spaces:
Paused
Paused
Upload 27 files
Browse filesFiles changed (4)
- README.md+14-12
- START_HERE.txt+5-3
- app.py+2-2
- floating_tutor.py+277-83
59 unmodified lines6061626364656667686970115 unmodified lines18618718818919019119219319419519619719819959 unmodified linesFace Inference Providers, with automatic verified-local fallback;- a deterministic local tutor for core explanations and image/OCR checking,plus an optional OpenAI route when `OPENAI_API_KEY` is configured;- a persistent, gently animated bottom-right **Ask Teacher** control on the first page and every tab;both its launcher and pop-up are attached directly to the browser viewport,self-adjust at the top or bottom during page/nested-panel scrolling, resizing,zoom, orientation changes, and mobile-keyboard viewport changes, open overthe page without changing tabs, keep their own compact mission-linked conversation, andhyperlinks to the full multimodal tutor;- a protected **Examination lock** that disables the mission generator, everytraining tab, worksheet tools, theory, progress, and Ask Teacher during an115 unmodified lines### Mechanics Tutor ChatThe floating **Ask Teacher** button stays at the bottom-right of the screen onMission Control and every other tab, including while the page is scrolling.Click it to open a separate compact text-tutor box above the button, sothe learner can ask for a first hint, equation choice, or custom clarificationwithout leaving the experiment or worksheet. Its visible question field acceptsfree-form questions and sends them with Enter or **Ask Teacher**. A gentleattention-ring animation and green availability indicator keep the launcherdiscoverable without moving it away from the safe bottom-right position. The compact chathas its own conversation and follows the current generated Mission Control orCreative Lab problem and its verified solution. Qwen is the default engine;the verified local and optional OpenAI engines remain selectable. Select **Open full59 unmodified lines6061626364656667686970115 unmodified lines18618718818919019119219319419519619719819920020159 unmodified linesFace Inference Providers, with automatic verified-local fallback;- a deterministic local tutor for core explanations and image/OCR checking,plus an optional OpenAI route when `OPENAI_API_KEY` is configured;- a draggable **Ask Teacher** control on the first page and every tab; learnerscan drag the launcher anywhere on the visible screen with a mouse, pen, ortouch, drag the open chat from its header, and retain both positions acrosspage scrolling, resizing, and browser reloads; it opens over the page withoutchanging tabs, keeps its own compact mission-linked conversation, andhyperlinks to the full multimodal tutor;- a protected **Examination lock** that disables the mission generator, everytraining tab, worksheet tools, theory, progress, and Ask Teacher during an115 unmodified lines### Mechanics Tutor ChatThe draggable **Ask Teacher** button starts at the bottom-right of the screen onMission Control and every other tab. Drag the grip to move it anywhere insidethe visible viewport; the saved relative position remains usable after scrolling,resizing, zooming, orientation changes, and browser reloads. Click it to open aseparate compact text-tutor box near the button, then drag the box header when adifferent placement is preferred. Dragging is kept separate from clicking, somoving the launcher never submits a chat request. The learner can ask for afirst hint, equation choice, or custom clarificationwithout leaving the experiment or worksheet. Its visible question field acceptsfree-form questions and sends them with Enter or **Ask Teacher**. The compact chathas its own conversation and follows the current generated Mission Control orCreative Lab problem and its verified solution. Qwen is the default engine;the verified local and optional OpenAI engines remain selectable. Select **Open full
90 unmodified lines91929394959697989910010190 unmodified linesMECHANICS TUTOR CHAT--------------------The animated "Ask Teacher" button remains at the bottom-right of the visible browser screenwhile scrolling on the first page and every tab. Click it to open a separatecompact chat box above the button without changing the current tab. Type aquestion about the active Mission Control or Creative Lab problem and pressEnter or "Ask Teacher". The reply uses that problem and its verified solution.The default engine is open-source Qwen through Hugging Face. Add HF_TOKEN to theSpace secrets, then select a Qwen model. If the provider is unavailable, theverified local tutor answers automatically.90 unmodified lines91929394959697989910010110210390 unmodified linesMECHANICS TUTOR CHAT--------------------The draggable "Ask Teacher" button starts at the bottom-right of the visiblebrowser screen. Drag its grip anywhere with a mouse, pen, or touch. Its positionis retained while scrolling and after browser reloads. Click it to open a separatecompact chat box above the button without changing the current tab. Type aquestion about the active Mission Control or Creative Lab problem and pressEnter or "Ask Teacher". Drag the chat header if the open box should move. Thereply uses that problem and its verified solution.The default engine is open-source Qwen through Hugging Face. Add HF_TOKEN to theSpace secrets, then select a Qwen model. If the provider is unavailable, theverified local tutor answers automatically.
2021 unmodified lines202220232024202520262027202820292030203120322033203420352021 unmodified lines# Kept outside gr.Tabs so the launcher and popup remain available on every# tab, including the first page, without changing the learner's current tab.floating_tutor_launcher = gr.Button("💬 Ask Teacher",variant="primary",elem_id="floating-tutor-launcher",)with gr.Group(visible=False, elem_id="floating-tutor-panel") as floating_tutor_panel:with gr.Row(elem_classes=["floating-tutor-dialog-header"]):gr.Markdown("### Ask Teacher · Mechanics\n\nMISSION-LINKED QUESTION HELP",elem_classes=["floating-tutor-dialog-title"],scale=8,)2021 unmodified lines202220232024202520262027202820292030203120322033203420352021 unmodified lines# Kept outside gr.Tabs so the launcher and popup remain available on every# tab, including the first page, without changing the learner's current tab.floating_tutor_launcher = gr.Button("⠿ 💬 Ask Teacher",variant="primary",elem_id="floating-tutor-launcher",)with gr.Group(visible=False, elem_id="floating-tutor-panel") as floating_tutor_panel:with gr.Row(elem_classes=["floating-tutor-dialog-header"]):gr.Markdown("### Ask Teacher · Mechanics\n\nDRAG THIS HEADER TO MOVE · MISSION-LINKED HELP",elem_classes=["floating-tutor-dialog-title"],scale=8,)
11 unmodified lines1213141516171812 unmodified lines313233343536373839404142434445464748495051525354555657585960616263646566676869707170 unmodified lines14214314414514614715 unmodified lines16316416516616716842 unmodified lines2112122132142152162172188 unmodified lines2272282292302312322 unmodified lines2352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073087 unmodified lines31631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834911 unmodified linesbottom: max(18px, env(safe-area-inset-bottom)) !important;box-shadow: 0 14px 34px rgba(76, 29, 149, .36) !important;color: white !important;cursor: pointer !important;display: inline-flex !important;font-family: inherit !important;font-size: 14px !important;12 unmodified linesright: max(18px, env(safe-area-inset-right)) !important;top: auto !important;transform: translateZ(0);visibility: visible !important;width: auto !important;z-index: 2147483000 !important;}#floating-tutor-viewport-launcher::before {animation: m1-teacher-attention-ring 2.8s ease-out infinite;border: 2px solid rgba(236, 72, 153, .55);border-radius: inherit;content: "";inset: -5px;pointer-events: none;position: absolute;}#floating-tutor-viewport-launcher::after {animation: m1-teacher-online-pulse 1.8s ease-in-out infinite;background: #22c55e;border: 2px solid white;border-radius: 50%;box-shadow: 0 0 0 3px rgba(34, 197, 94, .18);content: "";height: 11px;pointer-events: none;position: absolute;right: 3px;top: 2px;width: 11px;}@keyframes m1-teacher-attention-ring {0% { opacity: 0; transform: scale(.92); }20% { opacity: .85; }75%, 100% { opacity: 0; transform: scale(1.14); }}@keyframes m1-teacher-online-pulse {0%, 100% { opacity: .72; transform: scale(.82); }50% { opacity: 1; transform: scale(1.08); }}#floating-tutor-viewport-launcher:hover {box-shadow: 0 17px 40px rgba(76, 29, 149, .44) !important;70 unmodified linesborder-bottom: 1px solid #e2e8f0;margin-bottom: 7px;padding-bottom: 7px;}.floating-tutor-dialog-title h3 {color: #172554;15 unmodified linesmin-width: 36px !important;padding: 0 !important;width: 36px !important;}#floating-open-full-tutor {color: #6d28d9 !important;42 unmodified lines@media (prefers-reduced-motion: reduce) {#floating-tutor-launcher,#floating-tutor-viewport-launcher { transform: none !important; }#floating-tutor-viewport-launcher::before,#floating-tutor-viewport-launcher::after { animation: none !important; }}"""8 unmodified linesconst PROXY_ID = "floating-tutor-viewport-launcher";const NATIVE_ID = "floating-tutor-launcher";const PANEL_ID = "floating-tutor-panel";const nativeButton = () => {const host = document.getElementById(NATIVE_ID);2 unmodified linesreturn host.querySelector("button");};const viewportMetrics = () => {const mobile = window.matchMedia("(max-width: 520px)").matches;const inset = mobile ? 12 : 18;const viewport = window.visualViewport;const viewportWidth = viewport ? viewport.width : document.documentElement.clientWidth;const viewportHeight = viewport ? viewport.height : document.documentElement.clientHeight;const extraRight = viewport? Math.max(0, window.innerWidth - viewport.offsetLeft - viewport.width): 0;const extraBottom = viewport? Math.max(0, window.innerHeight - viewport.offsetTop - viewport.height): 0;return {mobile, inset, viewportWidth, viewportHeight, extraRight, extraBottom};};const pinToViewport = (button) => {if (!button) return;const {inset, extraRight, extraBottom} = viewportMetrics();button.style.setProperty("position", "fixed", "important");button.style.setProperty("right", `${inset + extraRight}px`, "important");button.style.setProperty("bottom", `${inset + extraBottom}px`, "important");button.style.setProperty("left", "auto", "important");button.style.setProperty("top", "auto", "important");button.style.setProperty("transform", "translate3d(0, 0, 0)", "important");button.style.setProperty("visibility", "visible", "important");button.style.setProperty("z-index", "2147483000", "important");};const portalAndPinPanel = (button) => {const panel = document.getElementById(PANEL_ID);if (!panel) return null;if (panel.parentElement !== document.body) document.body.appendChild(panel);panel.classList.add("viewport-panel-portal");const {inset, viewportWidth, viewportHeight, extraRight, extraBottom} = viewportMetrics();const launcherHeight = Math.max(42, button?.getBoundingClientRect().height || 44);const panelWidth = Math.max(180, Math.min(430, viewportWidth - inset * 2));const panelBottom = inset + extraBottom + launcherHeight + 12;const panelHeight = Math.max(140, viewportHeight - launcherHeight - inset * 3 - 12);panel.style.setProperty("position", "fixed", "important");panel.style.setProperty("right", `${inset + extraRight}px`, "important");panel.style.setProperty("bottom", `${panelBottom}px`, "important");panel.style.setProperty("left", "auto", "important");panel.style.setProperty("top", "auto", "important");panel.style.setProperty("width", `${panelWidth}px`, "important");panel.style.setProperty("max-height", `${panelHeight}px`, "important");panel.style.setProperty("transform", "translate3d(0, 0, 0)", "important");panel.style.setProperty("z-index", "2147482999", "important");return panel;};const install = () => {let proxy = document.getElementById(PROXY_ID);if (!proxy) {proxy = document.createElement("button");proxy.id = PROXY_ID;proxy.type = "button";proxy.textContent = "💬 Ask Teacher";proxy.setAttribute("aria-label", "Open Ask Teacher for the active mechanics problem");proxy.setAttribute("aria-controls", "floating-tutor-panel");proxy.addEventListener("click", () => {const target = nativeButton();if (target) target.click();});document.body.appendChild(proxy);}pinToViewport(proxy);portalAndPinPanel(proxy);const nativeHost = document.getElementById(NATIVE_ID);if (nativeHost) {nativeHost.classList.add("viewport-proxy-active");7 unmodified linesif (!window.__m1TutorViewportLauncherInstalled) {window.__m1TutorViewportLauncherInstalled = true;let frame = 0;const schedulePin = () => {window.cancelAnimationFrame(frame);frame = window.requestAnimationFrame(() => {const proxy = install();pinToViewport(proxy);portalAndPinPanel(proxy);});};window.__m1TutorViewportSchedule = schedulePin;window.addEventListener("scroll", schedulePin, {passive: true, capture: true});document.addEventListener("scroll", schedulePin, {passive: true, capture: true});window.addEventListener("resize", schedulePin, {passive: true});window.addEventListener("orientationchange", schedulePin, {passive: true});if (window.visualViewport) {window.visualViewport.addEventListener("scroll", schedulePin, {passive: true});window.visualViewport.addEventListener("resize", schedulePin, {passive: true});}new MutationObserver(() => install()).observe(document.body, {childList: true,subtree: true,});if (window.ResizeObserver) {const resizeObserver = new ResizeObserver(schedulePin);resizeObserver.observe(document.documentElement);resizeObserver.observe(document.body);window.__m1TutorViewportResizeObserver = resizeObserver;}window.__m1TutorViewportHeartbeat = window.setInterval(schedulePin, 1200);}install();11 unmodified lines1213141516171812 unmodified lines31323334353637383940414243444546474849505152535455565770 unmodified lines12812913013113213313413513613713813915 unmodified lines15515615715815916016142 unmodified lines2042052062072082098 unmodified lines2182192202212222232242252262272282292302312322332342352362372382392402412422432442452462 unmodified lines2492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025037 unmodified lines51151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254311 unmodified linesbottom: max(18px, env(safe-area-inset-bottom)) !important;box-shadow: 0 14px 34px rgba(76, 29, 149, .36) !important;color: white !important;cursor: grab !important;display: inline-flex !important;font-family: inherit !important;font-size: 14px !important;12 unmodified linesright: max(18px, env(safe-area-inset-right)) !important;top: auto !important;transform: translateZ(0);touch-action: none !important;user-select: none !important;visibility: visible !important;width: auto !important;z-index: 2147483000 !important;}#floating-tutor-viewport-launcher.is-dragging {cursor: grabbing !important;transition: none !important;}#floating-tutor-viewport-launcher .ask-teacher-drag-grip {color: rgba(255, 255, 255, .82);font-size: 17px;font-weight: 900;letter-spacing: -4px;margin-left: -3px;margin-right: 2px;pointer-events: none;}#floating-tutor-viewport-launcher .ask-teacher-label {pointer-events: none;}#floating-tutor-viewport-launcher:hover {box-shadow: 0 17px 40px rgba(76, 29, 149, .44) !important;70 unmodified linesborder-bottom: 1px solid #e2e8f0;margin-bottom: 7px;padding-bottom: 7px;cursor: grab;touch-action: none;user-select: none;}#floating-tutor-panel.panel-is-dragging .floating-tutor-dialog-header {cursor: grabbing;}.floating-tutor-dialog-title h3 {color: #172554;15 unmodified linesmin-width: 36px !important;padding: 0 !important;width: 36px !important;cursor: pointer !important;}#floating-open-full-tutor {color: #6d28d9 !important;42 unmodified lines@media (prefers-reduced-motion: reduce) {#floating-tutor-launcher,#floating-tutor-viewport-launcher { transform: none !important; }}"""8 unmodified linesconst PROXY_ID = "floating-tutor-viewport-launcher";const NATIVE_ID = "floating-tutor-launcher";const PANEL_ID = "floating-tutor-panel";const LAUNCHER_POSITION_KEY = "m1-ask-teacher-launcher-position-v1";const PANEL_POSITION_KEY = "m1-ask-teacher-panel-position-v1";const DRAG_THRESHOLD = 5;let launcherPosition = null;let panelPosition = null;let suppressLauncherClickUntil = 0;const readPosition = (key) => {try {const value = JSON.parse(window.localStorage.getItem(key) || "null");if (value && Number.isFinite(value.x) && Number.isFinite(value.y)) {return {x: Math.max(0, Math.min(1, value.x)), y: Math.max(0, Math.min(1, value.y))};}} catch (_) {}return null;};const writePosition = (key, value) => {try { window.localStorage.setItem(key, JSON.stringify(value)); } catch (_) {}};launcherPosition = readPosition(LAUNCHER_POSITION_KEY);panelPosition = readPosition(PANEL_POSITION_KEY);const nativeButton = () => {const host = document.getElementById(NATIVE_ID);2 unmodified linesreturn host.querySelector("button");};const viewportBounds = () => {const mobile = window.matchMedia("(max-width: 520px)").matches;const inset = mobile ? 12 : 18;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;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 normalizedPosition = (rect) => {const bounds = viewportBounds();const safeLeft = bounds.left + bounds.inset;const safeTop = bounds.top + bounds.inset;const horizontalRange = Math.max(1, bounds.width - bounds.inset * 2 - rect.width);const verticalRange = Math.max(1, bounds.height - bounds.inset * 2 - rect.height);return {x: clamp((rect.left - safeLeft) / horizontalRange, 0, 1),y: clamp((rect.top - safeTop) / verticalRange, 0, 1),};};const positionFromNormalized = (element, position, fallback) => {if (!element) return;const bounds = viewportBounds();const rect = element.getBoundingClientRect();const safeLeft = bounds.left + bounds.inset;const safeTop = bounds.top + bounds.inset;const horizontalRange = Math.max(0, bounds.width - bounds.inset * 2 - rect.width);const verticalRange = Math.max(0, bounds.height - bounds.inset * 2 - rect.height);const selected = position || fallback;element.style.setProperty("position", "fixed", "important");element.style.setProperty("left", `${safeLeft + selected.x * horizontalRange}px`, "important");element.style.setProperty("top", `${safeTop + selected.y * verticalRange}px`, "important");element.style.setProperty("right", "auto", "important");element.style.setProperty("bottom", "auto", "important");element.style.setProperty("transform", "translate3d(0, 0, 0)", "important");};const positionLauncher = (button) => {if (!button || button.classList.contains("is-dragging")) return;positionFromNormalized(button, launcherPosition, {x: 1, y: 1});button.style.setProperty("visibility", "visible", "important");button.style.setProperty("position", "fixed", "important");button.style.setProperty("z-index", "2147483000", "important");};const positionPanel = (button, panel) => {if (!panel || panel.classList.contains("panel-is-dragging")) return;const bounds = viewportBounds();const panelWidth = Math.max(180, Math.min(430, bounds.width - bounds.inset * 2));const maximumHeight = Math.max(140, bounds.height - bounds.inset * 2);panel.style.setProperty("width", `${panelWidth}px`, "important");panel.style.setProperty("max-height", `${maximumHeight}px`, "important");panel.style.setProperty("position", "fixed", "important");panel.style.setProperty("right", "auto", "important");panel.style.setProperty("bottom", "auto", "important");panel.style.setProperty("transform", "translate3d(0, 0, 0)", "important");panel.style.setProperty("z-index", "2147482999", "important");if (panelPosition) {positionFromNormalized(panel, panelPosition, {x: 1, y: 0});return;}const launcherRect = button?.getBoundingClientRect();const panelRect = panel.getBoundingClientRect();if (!launcherRect) {positionFromNormalized(panel, null, {x: 1, y: 0});return;}const gap = 12;const safeLeft = bounds.left + bounds.inset;const safeTop = bounds.top + bounds.inset;const safeRight = bounds.right - bounds.inset;const safeBottom = bounds.bottom - bounds.inset;const spaceAbove = Math.max(0, launcherRect.top - safeTop - gap);const spaceBelow = Math.max(0, safeBottom - launcherRect.bottom - gap);const useAbove = spaceAbove >= spaceBelow;const availableHeight = Math.max(140, useAbove ? spaceAbove : spaceBelow);panel.style.setProperty("max-height", `${Math.min(maximumHeight, availableHeight)}px`, "important");const estimatedHeight = Math.min(Math.max(220, panelRect.height || 520),Math.min(maximumHeight, availableHeight),);const left = clamp(launcherRect.right - panelWidth, safeLeft, safeRight - panelWidth);const top = useAbove? clamp(launcherRect.top - gap - estimatedHeight, safeTop, safeBottom - estimatedHeight): clamp(launcherRect.bottom + gap, safeTop, safeBottom - estimatedHeight);panel.style.setProperty("left", `${left}px`, "important");panel.style.setProperty("top", `${top}px`, "important");};const portalPanel = (button) => {const panel = document.getElementById(PANEL_ID);if (!panel) return null;if (panel.parentElement !== document.body) document.body.appendChild(panel);panel.classList.add("viewport-panel-portal");positionPanel(button, panel);makePanelDraggable(panel);return panel;};const makeLauncherDraggable = (button) => {if (!button || button.dataset.askTeacherDraggable === "true") return;button.dataset.askTeacherDraggable = "true";let drag = null;button.addEventListener("pointerdown", (event) => {if (event.button !== undefined && event.button !== 0) return;const rect = button.getBoundingClientRect();drag = {pointerId: event.pointerId,startX: event.clientX,startY: event.clientY,originLeft: rect.left,originTop: rect.top,width: rect.width,height: rect.height,moved: false,};try { button.setPointerCapture(event.pointerId); } catch (_) {}});button.addEventListener("pointermove", (event) => {if (!drag || event.pointerId !== drag.pointerId) return;const dx = event.clientX - drag.startX;const dy = event.clientY - drag.startY;if (!drag.moved && Math.hypot(dx, dy) < DRAG_THRESHOLD) return;drag.moved = true;event.preventDefault();button.classList.add("is-dragging");const bounds = viewportBounds();const left = clamp(drag.originLeft + dx,bounds.left + bounds.inset,bounds.right - bounds.inset - drag.width,);const top = clamp(drag.originTop + dy,bounds.top + bounds.inset,bounds.bottom - bounds.inset - drag.height,);button.style.setProperty("left", `${left}px`, "important");button.style.setProperty("top", `${top}px`, "important");button.style.setProperty("right", "auto", "important");button.style.setProperty("bottom", "auto", "important");if (!panelPosition) positionPanel(button, document.getElementById(PANEL_ID));});const finishDrag = (event) => {if (!drag || (event.pointerId !== undefined && event.pointerId !== drag.pointerId)) return;if (drag.moved) {suppressLauncherClickUntil = Date.now() + 450;launcherPosition = normalizedPosition(button.getBoundingClientRect());writePosition(LAUNCHER_POSITION_KEY, launcherPosition);}button.classList.remove("is-dragging");try { button.releasePointerCapture(drag.pointerId); } catch (_) {}drag = null;};button.addEventListener("pointerup", finishDrag);button.addEventListener("pointercancel", finishDrag);};function makePanelDraggable(panel) {const header = panel?.querySelector(".floating-tutor-dialog-header");if (!header || header.dataset.askTeacherDraggable === "true") return;header.dataset.askTeacherDraggable = "true";header.setAttribute("title", "Drag to move Ask Teacher");let drag = null;header.addEventListener("pointerdown", (event) => {if (event.button !== undefined && event.button !== 0) return;if (event.target.closest("button, a, input, textarea, select")) return;const rect = panel.getBoundingClientRect();drag = {pointerId: event.pointerId,startX: event.clientX,startY: event.clientY,originLeft: rect.left,originTop: rect.top,width: rect.width,height: rect.height,};panel.classList.add("panel-is-dragging");try { header.setPointerCapture(event.pointerId); } catch (_) {}event.preventDefault();});header.addEventListener("pointermove", (event) => {if (!drag || event.pointerId !== drag.pointerId) return;event.preventDefault();const bounds = viewportBounds();const left = clamp(drag.originLeft + event.clientX - drag.startX,bounds.left + bounds.inset,bounds.right - bounds.inset - drag.width,);const top = clamp(drag.originTop + event.clientY - drag.startY,bounds.top + bounds.inset,bounds.bottom - bounds.inset - drag.height,);panel.style.setProperty("left", `${left}px`, "important");panel.style.setProperty("top", `${top}px`, "important");panel.style.setProperty("right", "auto", "important");panel.style.setProperty("bottom", "auto", "important");});const finishPanelDrag = (event) => {if (!drag || (event.pointerId !== undefined && event.pointerId !== drag.pointerId)) return;panelPosition = normalizedPosition(panel.getBoundingClientRect());writePosition(PANEL_POSITION_KEY, panelPosition);panel.classList.remove("panel-is-dragging");try { header.releasePointerCapture(drag.pointerId); } catch (_) {}drag = null;};header.addEventListener("pointerup", finishPanelDrag);header.addEventListener("pointercancel", finishPanelDrag);}const install = () => {let proxy = document.getElementById(PROXY_ID);if (!proxy) {proxy = document.createElement("button");proxy.id = PROXY_ID;proxy.type = "button";proxy.innerHTML = '<span class="ask-teacher-drag-grip" aria-hidden="true">⠿</span><span class="ask-teacher-label">💬 Ask Teacher</span>';proxy.setAttribute("aria-label", "Ask Teacher. Drag to move or click to open for the active mechanics problem");proxy.setAttribute("aria-controls", "floating-tutor-panel");proxy.addEventListener("click", () => {if (Date.now() < suppressLauncherClickUntil) return;const target = nativeButton();if (target) {target.click();window.requestAnimationFrame(() => portalPanel(proxy));window.setTimeout(() => portalPanel(proxy), 180);}});document.body.appendChild(proxy);}positionLauncher(proxy);makeLauncherDraggable(proxy);portalPanel(proxy);const nativeHost = document.getElementById(NATIVE_ID);if (nativeHost) {nativeHost.classList.add("viewport-proxy-active");7 unmodified linesif (!window.__m1TutorViewportLauncherInstalled) {window.__m1TutorViewportLauncherInstalled = true;let frame = 0;const schedulePosition = () => {window.cancelAnimationFrame(frame);frame = window.requestAnimationFrame(() => {const proxy = install();positionLauncher(proxy);portalPanel(proxy);});};window.__m1AskTeacherSchedulePosition = schedulePosition;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(() => install()).observe(document.body, {childList: true,subtree: true,});if (window.ResizeObserver) {const resizeObserver = new ResizeObserver(schedulePosition);resizeObserver.observe(document.documentElement);resizeObserver.observe(document.body);window.__m1AskTeacherResizeObserver = resizeObserver;}}install();
README.md+14-12
START_HERE.txt+5-3
app.py+2-2
floating_tutor.py+277-83