mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
fix(panel): add popup collision clamping and modern-ui capsule odometer
This commit is contained in:
@@ -34,6 +34,7 @@ import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
|
||||
import {
|
||||
buildCapsuleSlotContext,
|
||||
createCapsuleSlotNode,
|
||||
patchCapsuleOdometerText,
|
||||
resolveMultiSessionCapsuleState,
|
||||
syncCapsuleSlotNodes,
|
||||
} from '../widgets/CapsuleBarWidget.js';
|
||||
@@ -2383,7 +2384,7 @@ export function mountWindowOverlay() {
|
||||
|
||||
if (!telemetry) {
|
||||
patchClasses(multiBtn, { 'is-running': false, 'is-waiting': false });
|
||||
patchText(multiLabel, t('capsule.multiZero'));
|
||||
patchCapsuleOdometerText(multiLabel, t('capsule.multiZero'), { resetKey: 'multi' });
|
||||
patchText(multiRunningMetaEl, t('multi.loading'));
|
||||
multiRunningWidget.refs.stopLiveTicker();
|
||||
|
||||
@@ -2423,7 +2424,7 @@ export function mountWindowOverlay() {
|
||||
'is-running': runningCount > 0 && !hasWaiting,
|
||||
'is-waiting': runningCount > 0 && hasWaiting,
|
||||
});
|
||||
patchText(multiLabel, multiBtnText);
|
||||
patchCapsuleOdometerText(multiLabel, multiBtnText, { resetKey: 'multi' });
|
||||
|
||||
renderMultiRunningPanel(
|
||||
rawRunningList,
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchText,
|
||||
positionAnchoredPopup,
|
||||
} from '../../core/domPatch.js';
|
||||
import { formatCompactDateTime } from '../../core/formatters.js';
|
||||
import { createSvgIcon } from '../../icons/SvgIcon.js';
|
||||
@@ -195,15 +196,47 @@ export const CustomDateTimePicker = defineComponent({
|
||||
|
||||
const rootEl = h('div', { className: 'datetime-picker' }, [triggerBtn, popoverEl]);
|
||||
|
||||
function positionPopover() {
|
||||
if (!isOpen) return;
|
||||
positionAnchoredPopup(rootEl, triggerBtn, popoverEl, {
|
||||
margin: 6,
|
||||
gap: 4,
|
||||
maxHeight: 0,
|
||||
minFlipSpace: 260,
|
||||
});
|
||||
}
|
||||
|
||||
let boundReposition = false;
|
||||
function handleViewportChange() {
|
||||
if (!isOpen) return;
|
||||
positionPopover();
|
||||
}
|
||||
|
||||
function setRepositionListeners(active) {
|
||||
if (active === boundReposition) return;
|
||||
boundReposition = active;
|
||||
if (typeof window !== 'undefined' && window.addEventListener) {
|
||||
if (active) {
|
||||
window.addEventListener('resize', handleViewportChange, { passive: true });
|
||||
window.addEventListener('scroll', handleViewportChange, true);
|
||||
} else {
|
||||
window.removeEventListener('resize', handleViewportChange);
|
||||
window.removeEventListener('scroll', handleViewportChange, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function togglePopover(nextOpen) {
|
||||
isOpen = Boolean(nextOpen);
|
||||
patchAttr(popoverEl, 'hidden', !isOpen);
|
||||
patchAttr(triggerBtn, 'aria-expanded', isOpen ? 'true' : 'false');
|
||||
setRepositionListeners(isOpen);
|
||||
if (isOpen) {
|
||||
const cur = new Date(getProps().modelValue || Date.now());
|
||||
viewYear = cur.getFullYear();
|
||||
viewMonth = cur.getMonth();
|
||||
renderCalendar();
|
||||
positionPopover();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +298,12 @@ export const CustomDateTimePicker = defineComponent({
|
||||
|
||||
if (typeof document !== 'undefined' && document.addEventListener) {
|
||||
document.addEventListener('click', handleDocClick, true);
|
||||
onCleanup(() => document.removeEventListener('click', handleDocClick, true));
|
||||
onCleanup(() => {
|
||||
setRepositionListeners(false);
|
||||
document.removeEventListener('click', handleDocClick, true);
|
||||
});
|
||||
} else {
|
||||
onCleanup(() => setRepositionListeners(false));
|
||||
}
|
||||
|
||||
syncDisplay();
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
patchClasses,
|
||||
patchKeyedList,
|
||||
patchText,
|
||||
positionAnchoredPopup,
|
||||
} from '../../core/domPatch.js';
|
||||
import { isEnglishLocale, t } from '../../i18n/index.js';
|
||||
import { createSvgIcon, patchSvgIcon } from '../../icons/SvgIcon.js';
|
||||
@@ -102,6 +103,37 @@ export const CustomSelect = defineComponent({
|
||||
return new Set(normalizeMultiSelection(modelValue, options, allValue));
|
||||
}
|
||||
|
||||
function positionMenu() {
|
||||
if (!isOpen) return;
|
||||
positionAnchoredPopup(rootEl, triggerBtn, menuEl, {
|
||||
margin: 6,
|
||||
gap: 4,
|
||||
maxHeight: 220,
|
||||
minFlipSpace: 140,
|
||||
});
|
||||
}
|
||||
|
||||
let boundReposition = false;
|
||||
function handleViewportChange(e) {
|
||||
if (!isOpen) return;
|
||||
if (e?.type === 'scroll' && e.target === menuEl) return;
|
||||
positionMenu();
|
||||
}
|
||||
|
||||
function setRepositionListeners(active) {
|
||||
if (active === boundReposition) return;
|
||||
boundReposition = active;
|
||||
if (typeof window !== 'undefined' && window.addEventListener) {
|
||||
if (active) {
|
||||
window.addEventListener('resize', handleViewportChange, { passive: true });
|
||||
window.addEventListener('scroll', handleViewportChange, true);
|
||||
} else {
|
||||
window.removeEventListener('resize', handleViewportChange);
|
||||
window.removeEventListener('scroll', handleViewportChange, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleOpen(nextOpen) {
|
||||
isOpen = Boolean(nextOpen);
|
||||
if (isOpen) {
|
||||
@@ -117,6 +149,10 @@ export const CustomSelect = defineComponent({
|
||||
patchAttr(triggerBtn, 'aria-expanded', isOpen ? 'true' : 'false');
|
||||
patchAttr(menuEl, 'hidden', !isOpen);
|
||||
patchSvgIcon(chevronIcon, isOpen ? 'chevron-up' : 'chevron-down');
|
||||
setRepositionListeners(isOpen);
|
||||
if (isOpen) {
|
||||
positionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
function chooseOption(option) {
|
||||
@@ -307,6 +343,7 @@ export const CustomSelect = defineComponent({
|
||||
patchAttr(triggerBtn, 'title', titleText);
|
||||
if (isOpen) {
|
||||
renderMenuOptions();
|
||||
positionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +355,12 @@ export const CustomSelect = defineComponent({
|
||||
|
||||
if (typeof document !== 'undefined' && document.addEventListener) {
|
||||
document.addEventListener('click', handleDocClick, true);
|
||||
onCleanup(() => document.removeEventListener('click', handleDocClick, true));
|
||||
onCleanup(() => {
|
||||
setRepositionListeners(false);
|
||||
document.removeEventListener('click', handleDocClick, true);
|
||||
});
|
||||
} else {
|
||||
onCleanup(() => setRepositionListeners(false));
|
||||
}
|
||||
|
||||
syncTriggerAndMenu();
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
* real-UI structure preview (`SettingsStructureTab.js`), ensuring 100% DOM/CSS parity.
|
||||
*/
|
||||
|
||||
import { isModernUiActiveForElement } from '../../core/appearance.js';
|
||||
import { defineComponent } from '../../core/component.js';
|
||||
import { h, patchAttr, patchClasses, patchText } from '../../core/domPatch.js';
|
||||
import { h, patchAttr, patchClasses, patchStyleVar, patchText } from '../../core/domPatch.js';
|
||||
import { t } from '../../i18n/index.js';
|
||||
import { createSvgIcon, SVG_NS } from '../../icons/SvgIcon.js';
|
||||
import { resolveCapsuleMetricPresentation } from '../../registries/metricRegistry.js';
|
||||
@@ -19,6 +20,165 @@ import { buildFallbackRunningConversations } from './LiveActivityWidget.js';
|
||||
export const RING_RADIUS = 5.2;
|
||||
export const RING_CIRCUMFERENCE = +(2 * Math.PI * RING_RADIUS).toFixed(2);
|
||||
|
||||
const ODOMETER_DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
const capsuleOdometerState = new WeakMap();
|
||||
|
||||
/**
|
||||
* 将胶囊指标文本拆分为「按数位对齐的数字滚轮 + 静态字符片段」:
|
||||
* - 整数部分从右向左按位次键控(个位 `i:0`、十位 `i:1`...),小数部分从左向右键控(`f:0`...);
|
||||
* - 位数增减时既有数位节点原地复用,仅发生变化的数字位执行 0.15s 老虎机垂直滚动,未变位与单位纹丝不动。
|
||||
*
|
||||
* @param {string} rawText
|
||||
* @returns {Array<{ key: string, kind: 'digit' | 'static', digit?: number, text?: string }>}
|
||||
*/
|
||||
export function tokenizeCapsuleOdometerText(rawText) {
|
||||
const str = String(rawText ?? '');
|
||||
if (!str) return [];
|
||||
const parts = str.split(/(\d+(?:\.\d+)?)/g);
|
||||
const tokens = [];
|
||||
let numIdx = 0;
|
||||
let staticIdx = 0;
|
||||
|
||||
for (let p = 0; p < parts.length; p += 1) {
|
||||
const seg = parts[p];
|
||||
if (!seg) continue;
|
||||
if (/^\d+(?:\.\d+)?$/.test(seg)) {
|
||||
const dotPos = seg.indexOf('.');
|
||||
const intPart = dotPos >= 0 ? seg.slice(0, dotPos) : seg;
|
||||
const fracPart = dotPos >= 0 ? seg.slice(dotPos + 1) : '';
|
||||
const intLen = intPart.length;
|
||||
for (let i = 0; i < intLen; i += 1) {
|
||||
const place = intLen - 1 - i;
|
||||
tokens.push({
|
||||
key: `n:${numIdx}:i:${place}`,
|
||||
kind: 'digit',
|
||||
digit: Number(intPart[i]),
|
||||
});
|
||||
}
|
||||
if (dotPos >= 0) {
|
||||
tokens.push({ key: `n:${numIdx}:dot`, kind: 'static', text: '.' });
|
||||
for (let j = 0; j < fracPart.length; j += 1) {
|
||||
tokens.push({
|
||||
key: `n:${numIdx}:f:${j}`,
|
||||
kind: 'digit',
|
||||
digit: Number(fracPart[j]),
|
||||
});
|
||||
}
|
||||
}
|
||||
numIdx += 1;
|
||||
} else {
|
||||
tokens.push({ key: `s:${staticIdx}`, kind: 'static', text: seg });
|
||||
staticIdx += 1;
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function createOdometerDigitReel(initialDigit) {
|
||||
const cells = ODOMETER_DIGITS.map((d) => h('span', { className: 'wm-od-cell', text: d }));
|
||||
const trackEl = h('span', { className: 'wm-od-track' }, cells);
|
||||
patchStyleVar(trackEl, '--od-val', String(initialDigit));
|
||||
const digitEl = h('span', { className: 'wm-od-digit', 'aria-hidden': 'true' }, [trackEl]);
|
||||
return { el: digitEl, trackEl, kind: 'digit', digit: initialDigit };
|
||||
}
|
||||
|
||||
/**
|
||||
* 在实验性新 UI (`[data-modern-ui="true"]`) 下将胶囊数字渲染为 0.15s 老虎机垂直滚轮;
|
||||
* 经典 UI 或无数字占位文本(如 `-- t/s`)严格退回原生纯文本 `patchText`,零多余 DOM 与动画。
|
||||
*/
|
||||
export function patchCapsuleOdometerText(
|
||||
el,
|
||||
nextValue,
|
||||
{ resetKey = '', modernUi = undefined } = {}
|
||||
) {
|
||||
if (!el) return false;
|
||||
const nextStr = String(nextValue ?? '');
|
||||
const isModern = typeof modernUi === 'boolean' ? modernUi : isModernUiActiveForElement(el);
|
||||
const prev = capsuleOdometerState.get(el);
|
||||
|
||||
if (!isModern || !/\d/.test(nextStr)) {
|
||||
if (prev?.active) {
|
||||
while (el.firstChild) el.removeChild(el.firstChild);
|
||||
patchAttr(el, 'data-od-active', null);
|
||||
patchAttr(el, 'data-od-value', null);
|
||||
patchAttr(el, 'aria-label', null);
|
||||
}
|
||||
const changed = patchText(el, nextStr);
|
||||
capsuleOdometerState.set(el, { active: false, text: nextStr, resetKey, nodes: null });
|
||||
return changed;
|
||||
}
|
||||
|
||||
if (prev?.active && prev.text === nextStr && prev.resetKey === resetKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let nodes;
|
||||
if (!prev?.active || prev.resetKey !== resetKey || !(prev.nodes instanceof Map)) {
|
||||
while (el.firstChild) el.removeChild(el.firstChild);
|
||||
nodes = new Map();
|
||||
} else {
|
||||
nodes = prev.nodes;
|
||||
}
|
||||
|
||||
const tokens = tokenizeCapsuleOdometerText(nextStr);
|
||||
const nextKeys = new Set();
|
||||
const orderedEls = [];
|
||||
|
||||
for (let i = 0; i < tokens.length; i += 1) {
|
||||
const tok = tokens[i];
|
||||
nextKeys.add(tok.key);
|
||||
let rec = nodes.get(tok.key);
|
||||
if (!rec || rec.kind !== tok.kind) {
|
||||
if (rec?.el?.parentNode === el) {
|
||||
el.removeChild(rec.el);
|
||||
}
|
||||
if (tok.kind === 'digit') {
|
||||
rec = createOdometerDigitReel(tok.digit);
|
||||
} else {
|
||||
rec = {
|
||||
el: h('span', { className: 'wm-od-static', 'aria-hidden': 'true', text: tok.text }),
|
||||
trackEl: null,
|
||||
kind: 'static',
|
||||
text: tok.text,
|
||||
};
|
||||
}
|
||||
nodes.set(tok.key, rec);
|
||||
} else if (tok.kind === 'digit') {
|
||||
if (rec.digit !== tok.digit) {
|
||||
patchStyleVar(rec.trackEl, '--od-val', String(tok.digit));
|
||||
rec.digit = tok.digit;
|
||||
}
|
||||
} else if (rec.text !== tok.text) {
|
||||
patchText(rec.el, tok.text);
|
||||
rec.text = tok.text;
|
||||
}
|
||||
orderedEls.push(rec.el);
|
||||
}
|
||||
|
||||
for (const [oldKey, rec] of nodes.entries()) {
|
||||
if (!nextKeys.has(oldKey)) {
|
||||
if (rec.el?.parentNode === el) {
|
||||
el.removeChild(rec.el);
|
||||
}
|
||||
nodes.delete(oldKey);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < orderedEls.length; i += 1) {
|
||||
const targetNode = orderedEls[i];
|
||||
const currentNode = el.children[i] || null;
|
||||
if (currentNode !== targetNode) {
|
||||
el.insertBefore(targetNode, currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
patchAttr(el, 'data-od-active', '1');
|
||||
patchAttr(el, 'data-od-value', nextStr);
|
||||
patchAttr(el, 'aria-label', nextStr);
|
||||
capsuleOdometerState.set(el, { active: true, text: nextStr, resetKey, nodes });
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute shared context ring + 1..5 capsule slot metric payload from telemetry & scoped conversation.
|
||||
*/
|
||||
@@ -224,7 +384,7 @@ export function syncCapsuleSlotNodes(capsuleSlots, capsuleSeps, slotKeys, slotCt
|
||||
patchAttr(slot.el, 'class', fullSegClass);
|
||||
const fullTextClass = `${pres.textClass}${toneCls ? ` ${toneCls}` : ''}`;
|
||||
patchAttr(slot.textSpan, 'class', fullTextClass);
|
||||
patchText(slot.textSpan, pres.text);
|
||||
patchCapsuleOdometerText(slot.textSpan, pres.text, { resetKey: pres.metric });
|
||||
|
||||
if (pres.showRing) {
|
||||
slot.ringFill.setAttribute('stroke-dashoffset', String(pres.dashOffset));
|
||||
@@ -370,7 +530,7 @@ export const CapsuleBarWidget = defineComponent({
|
||||
|
||||
if (!data) {
|
||||
patchClasses(multiBtn, { 'is-running': false, 'is-waiting': false });
|
||||
patchText(multiLabel, t('capsule.multiZero'));
|
||||
patchCapsuleOdometerText(multiLabel, t('capsule.multiZero'), { resetKey: 'multi' });
|
||||
syncCapsuleSlotNodes(capsuleSlots, capsuleSeps, slotKeys, { hasTelemetry: false });
|
||||
return;
|
||||
}
|
||||
@@ -391,7 +551,7 @@ export const CapsuleBarWidget = defineComponent({
|
||||
'is-running': runningCount > 0 && !hasWaiting,
|
||||
'is-waiting': runningCount > 0 && hasWaiting,
|
||||
});
|
||||
patchText(multiLabel, multiBtnText);
|
||||
patchCapsuleOdometerText(multiLabel, multiBtnText, { resetKey: 'multi' });
|
||||
|
||||
patchClasses(capsuleBtn, { 'is-running': slotCtx.isRunning });
|
||||
syncCapsuleSlotNodes(capsuleSlots, capsuleSeps, slotKeys, slotCtx);
|
||||
|
||||
@@ -202,3 +202,194 @@ export function patchKeyedList(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const CLIPPING_OVERFLOW_RE = /(?:hidden|clip|auto|scroll)/i;
|
||||
|
||||
/**
|
||||
* 解析浮层所在的可视裁剪边界(兼容 Shadow DOM 悬浮窗 `.wm-popover-panel`、
|
||||
* 侧栏 `.app-shell`、自定义滚动容器 `.custom-scroll-content` 与窗口视口)。
|
||||
*
|
||||
* @param {HTMLElement} anchorRootEl
|
||||
* @returns {{ left: number, top: number, right: number, bottom: number, width: number, height: number } | null}
|
||||
*/
|
||||
function resolvePopupBoundaryRect(anchorRootEl) {
|
||||
if (!anchorRootEl) return null;
|
||||
const winW = typeof window !== 'undefined' ? Number(window.innerWidth || 0) : 0;
|
||||
const winH = typeof window !== 'undefined' ? Number(window.innerHeight || 0) : 0;
|
||||
let boundLeft = 0;
|
||||
let boundTop = 0;
|
||||
let boundRight = winW > 0 ? winW : Infinity;
|
||||
let boundBottom = winH > 0 ? winH : Infinity;
|
||||
let hasBoundary = winW > 0 && winH > 0;
|
||||
|
||||
const getStyle =
|
||||
typeof window !== 'undefined' && typeof window.getComputedStyle === 'function'
|
||||
? window.getComputedStyle
|
||||
: null;
|
||||
|
||||
let cur = anchorRootEl.parentNode || null;
|
||||
while (cur) {
|
||||
if (cur.nodeType === 1 || typeof cur.getBoundingClientRect === 'function') {
|
||||
const cls = cur.classList;
|
||||
const isShell = Boolean(
|
||||
cls?.contains?.('wm-popover-panel') ||
|
||||
cls?.contains?.('wm-multi-panel') ||
|
||||
cls?.contains?.('app-shell') ||
|
||||
cls?.contains?.('custom-scroll-host') ||
|
||||
cls?.contains?.('custom-scroll-content')
|
||||
);
|
||||
let clipsX = isShell;
|
||||
let clipsY = isShell;
|
||||
if (!isShell && getStyle) {
|
||||
try {
|
||||
const cs = getStyle(cur);
|
||||
if (cs) {
|
||||
clipsX = CLIPPING_OVERFLOW_RE.test(cs.overflowX || cs.overflow || '');
|
||||
clipsY = CLIPPING_OVERFLOW_RE.test(cs.overflowY || cs.overflow || '');
|
||||
}
|
||||
} catch {
|
||||
// 忽略 Mock DOM 样式查询异常
|
||||
}
|
||||
}
|
||||
if (clipsX || clipsY) {
|
||||
const r = cur.getBoundingClientRect?.();
|
||||
if (r && r.width > 0 && r.height > 0) {
|
||||
hasBoundary = true;
|
||||
if (clipsX) {
|
||||
boundLeft = Math.max(boundLeft, r.left);
|
||||
boundRight = Math.min(boundRight, r.right);
|
||||
}
|
||||
if (clipsY) {
|
||||
boundTop = Math.max(boundTop, r.top);
|
||||
boundBottom = Math.min(boundBottom, r.bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 到达 ShadowRoot 或文档顶层后停止,避免误受宿主页面外层容器干扰
|
||||
if (!cur.parentNode) break;
|
||||
cur = cur.parentNode;
|
||||
}
|
||||
|
||||
if (!hasBoundary || !Number.isFinite(boundRight) || !Number.isFinite(boundBottom)) {
|
||||
return null;
|
||||
}
|
||||
const width = Math.max(0, boundRight - boundLeft);
|
||||
const height = Math.max(0, boundBottom - boundTop);
|
||||
if (width <= 0 || height <= 0) return null;
|
||||
return { left: boundLeft, top: boundTop, right: boundRight, bottom: boundBottom, width, height };
|
||||
}
|
||||
|
||||
/**
|
||||
* 为锚定在触发器上的绝对定位下拉浮层执行水平/垂直碰撞检测与边界夹紧:
|
||||
* - 水平方向优先左对齐,右侧溢出时切右对齐,仍越界则直接夹紧在容器可视安全区内;
|
||||
* - 垂直方向底部空间不足且上方更宽裕时自动向上翻转(追加 `.is-above`),并按可用空间收紧 `max-height`。
|
||||
*
|
||||
* @param {HTMLElement} rootEl 定位基准容器 (`position: relative`)
|
||||
* @param {HTMLElement} triggerEl 触发按钮
|
||||
* @param {HTMLElement} popupEl 下拉浮层 (`position: absolute`)
|
||||
* @param {{ margin?: number, gap?: number, maxHeight?: number, minFlipSpace?: number }} [opts]
|
||||
*/
|
||||
export function positionAnchoredPopup(
|
||||
rootEl,
|
||||
triggerEl,
|
||||
popupEl,
|
||||
{ margin = 6, gap = 4, maxHeight = 220, minFlipSpace = 140 } = {}
|
||||
) {
|
||||
if (!rootEl || !triggerEl || !popupEl || !popupEl.style) return;
|
||||
if (popupEl.hasAttribute?.('hidden')) return;
|
||||
|
||||
const rootRect = rootEl.getBoundingClientRect?.();
|
||||
const triggerRect = triggerEl.getBoundingClientRect?.();
|
||||
if (
|
||||
!rootRect ||
|
||||
!triggerRect ||
|
||||
!(triggerRect.width > 0 && triggerRect.height > 0)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bound = resolvePopupBoundaryRect(rootEl);
|
||||
if (!bound) return;
|
||||
|
||||
// 清除旧的动态夹紧值以便读取自然布局宽度
|
||||
popupEl.style.left = '';
|
||||
popupEl.style.right = '';
|
||||
popupEl.style.top = '';
|
||||
popupEl.style.bottom = '';
|
||||
popupEl.style.minWidth = '';
|
||||
popupEl.style.maxWidth = '';
|
||||
popupEl.style.maxHeight = '';
|
||||
|
||||
const availWidth = Math.max(120, Math.floor(bound.width - margin * 2));
|
||||
popupEl.style.maxWidth = `${availWidth}px`;
|
||||
|
||||
const rawRect = popupEl.getBoundingClientRect?.();
|
||||
// 优先读取 offsetWidth,避免入场动画 scale(0.975) 导致测宽偏小
|
||||
const naturalW = Math.max(
|
||||
Number(popupEl.offsetWidth || 0),
|
||||
Math.ceil(Number(rawRect?.width || 0))
|
||||
);
|
||||
if (naturalW > availWidth) {
|
||||
popupEl.style.minWidth = '0px';
|
||||
}
|
||||
const popupW = Math.min(availWidth, naturalW > 0 ? naturalW : Math.max(triggerRect.width, 210));
|
||||
|
||||
const safeLeft = bound.left + margin;
|
||||
const safeRight = bound.right - margin;
|
||||
const rawLeft = Number(rawRect?.left);
|
||||
const rawRight = Number(rawRect?.right);
|
||||
const hasRawBox = Number.isFinite(rawLeft) && Number.isFinite(rawRight) && rawRight > rawLeft;
|
||||
// 若入场缩放动画(如 scale(0.975))正在首帧生效,按对称补偿还原终态边界再判断是否越界
|
||||
const scalePadX = hasRawBox ? Math.max(0, (popupW - (rawRight - rawLeft)) / 2) : 0;
|
||||
const naturalLeft = hasRawBox ? rawLeft - scalePadX : triggerRect.left;
|
||||
const naturalRight = hasRawBox
|
||||
? Math.max(rawRight + scalePadX, naturalLeft + popupW)
|
||||
: naturalLeft + popupW;
|
||||
const fitsAsDefault = hasRawBox && naturalLeft >= safeLeft && naturalRight <= safeRight;
|
||||
|
||||
if (!fitsAsDefault) {
|
||||
let targetLeft = triggerRect.left;
|
||||
if (targetLeft + popupW > safeRight) {
|
||||
const rightAlignedLeft = triggerRect.right - popupW;
|
||||
if (rightAlignedLeft >= safeLeft) {
|
||||
targetLeft = rightAlignedLeft;
|
||||
} else {
|
||||
targetLeft = Math.max(safeLeft, safeRight - popupW);
|
||||
}
|
||||
}
|
||||
if (targetLeft < safeLeft) {
|
||||
targetLeft = safeLeft;
|
||||
}
|
||||
|
||||
const offsetLeft = Math.round(targetLeft - rootRect.left);
|
||||
popupEl.style.left = `${offsetLeft}px`;
|
||||
popupEl.style.right = 'auto';
|
||||
}
|
||||
|
||||
const spaceBelow = Math.max(0, bound.bottom - triggerRect.bottom - gap - margin);
|
||||
const spaceAbove = Math.max(0, triggerRect.top - bound.top - gap - margin);
|
||||
const naturalH = Math.max(
|
||||
Number(popupEl.scrollHeight || 0),
|
||||
Number(popupEl.offsetHeight || 0),
|
||||
Math.ceil(Number(rawRect?.height || 0))
|
||||
);
|
||||
const desiredH = maxHeight > 0 ? Math.min(maxHeight, naturalH || maxHeight) : naturalH || 240;
|
||||
const shouldOpenAbove =
|
||||
spaceBelow < Math.min(desiredH, minFlipSpace) && spaceAbove > spaceBelow;
|
||||
|
||||
patchClasses(popupEl, { 'is-above': shouldOpenAbove });
|
||||
if (shouldOpenAbove) {
|
||||
popupEl.style.top = 'auto';
|
||||
popupEl.style.bottom = `calc(100% + ${gap}px)`;
|
||||
if (maxHeight > 0) {
|
||||
popupEl.style.maxHeight = `${Math.max(88, Math.floor(Math.min(maxHeight, spaceAbove)))}px`;
|
||||
}
|
||||
} else {
|
||||
popupEl.style.top = `calc(100% + ${gap}px)`;
|
||||
popupEl.style.bottom = 'auto';
|
||||
if (maxHeight > 0) {
|
||||
popupEl.style.maxHeight = `${Math.max(88, Math.floor(Math.min(maxHeight, spaceBelow)))}px`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
|
||||
.steps-inline-scope-select .select-menu,
|
||||
.steps-inline-model-select .select-menu {
|
||||
left: auto;
|
||||
right: 0;
|
||||
left: 0;
|
||||
right: auto;
|
||||
min-width: 220px;
|
||||
max-width: min(320px, 82vw);
|
||||
max-width: min(320px, calc(100vw - 24px));
|
||||
}
|
||||
|
||||
.session-left {
|
||||
|
||||
@@ -623,6 +623,11 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
|
||||
animation: anim-modern-pop-in 150ms var(--ease-modern);
|
||||
}
|
||||
|
||||
[data-modern-ui="true"] .select-menu.is-above,
|
||||
[data-modern-ui="true"] .dt-popover.is-above {
|
||||
animation-name: anim-modern-pop-in-up;
|
||||
}
|
||||
|
||||
[data-modern-ui="true"] .trend-tooltip,
|
||||
[data-modern-ui="true"] .cons-breakdown-popover,
|
||||
[data-modern-ui="true"] .turn-prompt-tip {
|
||||
@@ -706,3 +711,91 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* --- 8. 顶栏胶囊老虎机滚动数字 (0.15s) 与语义色平滑渐变 (0.1s),严格限定实验性新 UI --- */
|
||||
:host([data-modern-ui="true"]) .wm-cap-slot,
|
||||
:host([data-modern-ui="true"]) .wm-cap-slot .wm-slot-text,
|
||||
:host([data-modern-ui="true"]) .wm-multi-label,
|
||||
[data-modern-ui="true"] .wm-cap-slot,
|
||||
[data-modern-ui="true"] .wm-cap-slot .wm-slot-text,
|
||||
[data-modern-ui="true"] .wm-multi-label {
|
||||
transition: color 100ms ease-out;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-ring-fill,
|
||||
[data-modern-ui="true"] .wm-ring-fill {
|
||||
transition:
|
||||
stroke-dashoffset var(--dur-normal) var(--ease-modern),
|
||||
stroke 100ms ease-out;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-multi-dot,
|
||||
[data-modern-ui="true"] .wm-multi-dot {
|
||||
transition: background-color 100ms ease-out;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-slot-text[data-od-active="1"],
|
||||
:host([data-modern-ui="true"]) .wm-multi-label[data-od-active="1"],
|
||||
[data-modern-ui="true"] .wm-slot-text[data-od-active="1"],
|
||||
[data-modern-ui="true"] .wm-multi-label[data-od-active="1"] {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-od-digit,
|
||||
[data-modern-ui="true"] .wm-od-digit {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
overflow: hidden;
|
||||
vertical-align: top;
|
||||
text-align: center;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-od-track,
|
||||
[data-modern-ui="true"] .wm-od-track {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
transform: translate3d(0, calc(var(--od-val, 0) * -18px), 0);
|
||||
transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1);
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-od-cell,
|
||||
[data-modern-ui="true"] .wm-od-cell {
|
||||
display: block;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:host([data-modern-ui="true"]) .wm-od-static,
|
||||
[data-modern-ui="true"] .wm-od-static {
|
||||
display: inline-block;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
vertical-align: top;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
:host([data-modern-ui="true"]) .wm-od-track,
|
||||
[data-modern-ui="true"] .wm-od-track,
|
||||
:host([data-modern-ui="true"]) .wm-cap-slot,
|
||||
:host([data-modern-ui="true"]) .wm-cap-slot .wm-slot-text,
|
||||
:host([data-modern-ui="true"]) .wm-multi-label,
|
||||
:host([data-modern-ui="true"]) .wm-ring-fill,
|
||||
:host([data-modern-ui="true"]) .wm-multi-dot,
|
||||
[data-modern-ui="true"] .wm-cap-slot,
|
||||
[data-modern-ui="true"] .wm-cap-slot .wm-slot-text,
|
||||
[data-modern-ui="true"] .wm-multi-label,
|
||||
[data-modern-ui="true"] .wm-ring-fill,
|
||||
[data-modern-ui="true"] .wm-multi-dot {
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user