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:
+439
-11
@@ -2872,7 +2872,7 @@ return { THEME_ACCENT_PRESETS, FONT_SCALE_FACTORS, PANEL_SCALE_FACTORS, normaliz
|
||||
})();
|
||||
|
||||
// --- src/core/domPatch.js ---
|
||||
const { h, patchText, patchAttr, patchClasses, patchStyleVar, isEventInside, patchKeyedList } = (() => {
|
||||
const { h, patchText, patchAttr, patchClasses, patchStyleVar, isEventInside, patchKeyedList, positionAnchoredPopup } = (() => {
|
||||
/**
|
||||
* @fileoverview Incremental DOM patching utilities and keyed list reconciler.
|
||||
* Prevents full innerHTML replacements and preserves active DOM element state.
|
||||
@@ -3077,7 +3077,198 @@ function patchKeyedList(
|
||||
}
|
||||
}
|
||||
}
|
||||
return { h, patchText, patchAttr, patchClasses, patchStyleVar, isEventInside, 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]
|
||||
*/
|
||||
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`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { h, patchText, patchAttr, patchClasses, patchStyleVar, isEventInside, patchKeyedList, positionAnchoredPopup };
|
||||
})();
|
||||
|
||||
// --- src/core/component.js ---
|
||||
@@ -6271,6 +6462,37 @@ 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) {
|
||||
@@ -6286,6 +6508,10 @@ 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) {
|
||||
@@ -6476,6 +6702,7 @@ const CustomSelect = defineComponent({
|
||||
patchAttr(triggerBtn, 'title', titleText);
|
||||
if (isOpen) {
|
||||
renderMenuOptions();
|
||||
positionMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6487,7 +6714,12 @@ 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();
|
||||
@@ -6824,15 +7056,47 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6894,7 +7158,12 @@ 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();
|
||||
@@ -14073,7 +14342,7 @@ return { STEP_COLUMN_KEYS, DEFAULT_STEP_COLUMN_KEYS, formatCustomTokenComboHeade
|
||||
})();
|
||||
|
||||
// --- src/components/widgets/CapsuleBarWidget.js ---
|
||||
const { RING_RADIUS, RING_CIRCUMFERENCE, buildCapsuleSlotContext, resolveMultiSessionCapsuleState, createCapsuleSlotNode, syncCapsuleSlotNodes, CapsuleBarWidget } = (() => {
|
||||
const { RING_RADIUS, RING_CIRCUMFERENCE, tokenizeCapsuleOdometerText, patchCapsuleOdometerText, buildCapsuleSlotContext, resolveMultiSessionCapsuleState, createCapsuleSlotNode, syncCapsuleSlotNodes, CapsuleBarWidget } = (() => {
|
||||
/**
|
||||
* @fileoverview Shared Decoupled Capsule Bar Primitives & Widget (`CapsuleBarWidget.js`).
|
||||
* Powers both the live host window capsule (`WindowOverlayShell.js`) and the
|
||||
@@ -14084,6 +14353,165 @@ const { RING_RADIUS, RING_CIRCUMFERENCE, buildCapsuleSlotContext, resolveMultiSe
|
||||
const RING_RADIUS = 5.2;
|
||||
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 }>}
|
||||
*/
|
||||
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 与动画。
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -14289,7 +14717,7 @@ function syncCapsuleSlotNodes(capsuleSlots, capsuleSeps, slotKeys, slotCtx) {
|
||||
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));
|
||||
@@ -14435,7 +14863,7 @@ 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;
|
||||
}
|
||||
@@ -14456,7 +14884,7 @@ 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);
|
||||
@@ -14475,7 +14903,7 @@ const CapsuleBarWidget = defineComponent({
|
||||
};
|
||||
},
|
||||
});
|
||||
return { RING_RADIUS, RING_CIRCUMFERENCE, buildCapsuleSlotContext, resolveMultiSessionCapsuleState, createCapsuleSlotNode, syncCapsuleSlotNodes, CapsuleBarWidget };
|
||||
return { RING_RADIUS, RING_CIRCUMFERENCE, tokenizeCapsuleOdometerText, patchCapsuleOdometerText, buildCapsuleSlotContext, resolveMultiSessionCapsuleState, createCapsuleSlotNode, syncCapsuleSlotNodes, CapsuleBarWidget };
|
||||
})();
|
||||
|
||||
// --- src/components/widgets/StepTableWidget.js ---
|
||||
@@ -25414,7 +25842,7 @@ 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();
|
||||
|
||||
@@ -25454,7 +25882,7 @@ function mountWindowOverlay() {
|
||||
'is-running': runningCount > 0 && !hasWaiting,
|
||||
'is-waiting': runningCount > 0 && hasWaiting,
|
||||
});
|
||||
patchText(multiLabel, multiBtnText);
|
||||
patchCapsuleOdometerText(multiLabel, multiBtnText, { resetKey: 'multi' });
|
||||
|
||||
renderMultiRunningPanel(
|
||||
rawRunningList,
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>用量监控</title>
|
||||
<link rel="stylesheet" href="/styles.css?v=1795085924190">
|
||||
<link rel="stylesheet" href="/styles.css?v=1795088041305">
|
||||
<script src="/preload.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app-root"></div>
|
||||
<script src="/app.js?v=1795085924190"></script>
|
||||
<script src="/app.js?v=1795088041305"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,10 +406,10 @@ html[data-standalone="true"] .app-shell {
|
||||
|
||||
.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 {
|
||||
@@ -6099,6 +6099,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 {
|
||||
@@ -6182,3 +6187,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,12 @@ import {
|
||||
} from '../src/core/appearance.js';
|
||||
import { createTrendAreaChart } from '../src/components/charts/TrendAreaChart.js';
|
||||
import { computePublicationFit } from '../src/components/charts/SessionStepCharts.js';
|
||||
import { CustomSelect } from '../src/components/ui/CustomSelect.js';
|
||||
import { SegmentedControl } from '../src/components/ui/SegmentedControl.js';
|
||||
import {
|
||||
patchCapsuleOdometerText,
|
||||
tokenizeCapsuleOdometerText,
|
||||
} from '../src/components/widgets/CapsuleBarWidget.js';
|
||||
import { ContextWindowWidget } from '../src/components/widgets/ContextWindowWidget.js';
|
||||
import { LiveActivityWidget } from '../src/components/widgets/LiveActivityWidget.js';
|
||||
import { StepTableWidget } from '../src/components/widgets/StepTableWidget.js';
|
||||
@@ -988,3 +993,173 @@ test('StepTableWidget virtualizes large sessions (>80 rows) with exact turn-rail
|
||||
|
||||
stepTable.destroy();
|
||||
});
|
||||
|
||||
test('CustomSelect collision detection clamps left/right overflow and flips upward near bottom boundary', (t) => {
|
||||
const prevDoc = globalThis.document;
|
||||
const prevWin = globalThis.window;
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
globalThis.window = {
|
||||
innerWidth: 1200,
|
||||
innerHeight: 800,
|
||||
getComputedStyle: () => ({ overflow: 'visible', overflowX: 'visible', overflowY: 'visible' }),
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
};
|
||||
|
||||
let selectComp = null;
|
||||
t.after(() => {
|
||||
selectComp?.destroy?.();
|
||||
globalThis.document = prevDoc;
|
||||
globalThis.window = prevWin;
|
||||
});
|
||||
|
||||
const shell = document.createElement('div');
|
||||
shell.className = 'wm-popover-panel';
|
||||
shell.getBoundingClientRect = () => ({ left: 20, top: 40, right: 560, bottom: 620, width: 540, height: 580 });
|
||||
document.body.appendChild(shell);
|
||||
|
||||
selectComp = CustomSelect({
|
||||
className: 'steps-inline-scope-select',
|
||||
modelValue: 'all',
|
||||
options: [
|
||||
{ value: 'all', label: '全部汇总', meta: '1994步' },
|
||||
{ value: 'main', label: '主代理', meta: '1759步' },
|
||||
{ value: 'w1', label: '蜂群 #1 · @entry-runtime', meta: '17步' },
|
||||
],
|
||||
});
|
||||
shell.appendChild(selectComp.el);
|
||||
|
||||
const menuEl = selectComp.refs.menuEl;
|
||||
const triggerBtn = selectComp.refs.triggerBtn;
|
||||
|
||||
// 1. Trigger near left edge with a wide 260px menu whose raw layout overflows left (-50 < 26)
|
||||
selectComp.el.getBoundingClientRect = () => ({ left: 90, top: 100, right: 190, bottom: 124, width: 100, height: 24 });
|
||||
triggerBtn.getBoundingClientRect = () => ({ left: 90, top: 100, right: 190, bottom: 124, width: 100, height: 24 });
|
||||
menuEl.offsetWidth = 260;
|
||||
menuEl.offsetHeight = 180;
|
||||
menuEl.scrollHeight = 180;
|
||||
menuEl.getBoundingClientRect = () => ({ left: -50, top: 128, right: 210, bottom: 308, width: 260, height: 180 });
|
||||
|
||||
triggerBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
|
||||
assert.equal(menuEl.style.left, '0px');
|
||||
assert.equal(menuEl.style.right, 'auto');
|
||||
assert.equal(menuEl.classList.contains('is-above'), false);
|
||||
|
||||
// 2. Trigger near right edge (460..540) overflows right (460+260 > 554) -> right-aligns cleanly inside shell
|
||||
triggerBtn.dispatchEvent({ type: 'click', stopPropagation() {} }); // close
|
||||
selectComp.el.getBoundingClientRect = () => ({ left: 460, top: 100, right: 540, bottom: 124, width: 80, height: 24 });
|
||||
triggerBtn.getBoundingClientRect = () => ({ left: 460, top: 100, right: 540, bottom: 124, width: 80, height: 24 });
|
||||
menuEl.getBoundingClientRect = () => ({ left: 460, top: 128, right: 720, bottom: 308, width: 260, height: 180 });
|
||||
|
||||
triggerBtn.dispatchEvent({ type: 'click', stopPropagation() {} }); // reopen
|
||||
assert.equal(menuEl.style.left, '-180px', 'Right-edge menu shifts left to align with trigger right edge (540-260=280, offset=-180)');
|
||||
assert.equal(menuEl.style.right, 'auto');
|
||||
|
||||
// 3. Trigger near bottom edge (580..604) flips upward (.is-above)
|
||||
triggerBtn.dispatchEvent({ type: 'click', stopPropagation() {} }); // close
|
||||
selectComp.el.getBoundingClientRect = () => ({ left: 90, top: 580, right: 190, bottom: 604, width: 100, height: 24 });
|
||||
triggerBtn.getBoundingClientRect = () => ({ left: 90, top: 580, right: 190, bottom: 604, width: 100, height: 24 });
|
||||
menuEl.getBoundingClientRect = () => ({ left: 90, top: 608, right: 350, bottom: 788, width: 260, height: 180 });
|
||||
|
||||
triggerBtn.dispatchEvent({ type: 'click', stopPropagation() {} }); // reopen
|
||||
assert.equal(menuEl.classList.contains('is-above'), true);
|
||||
assert.equal(menuEl.style.bottom, 'calc(100% + 4px)');
|
||||
assert.equal(menuEl.style.top, 'auto');
|
||||
});
|
||||
|
||||
test('Capsule odometer digit rolling (0.15s) and color transition (0.1s) stay strictly isolated to Modern UI', (t) => {
|
||||
const prevDoc = globalThis.document;
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
t.after(() => {
|
||||
globalThis.document = prevDoc;
|
||||
});
|
||||
|
||||
// Tokenizer keys integer digits right-to-left by place value and fraction digits left-to-right
|
||||
const toks = tokenizeCapsuleOdometerText('37.2 t/s');
|
||||
assert.deepEqual(
|
||||
toks.map((x) => `${x.key}=${x.kind === 'digit' ? x.digit : x.text}`),
|
||||
['n:0:i:1=3', 'n:0:i:0=7', 'n:0:dot=.', 'n:0:f:0=2', 's:0= t/s']
|
||||
);
|
||||
|
||||
const host = document.createElement('div');
|
||||
const slotText = document.createElement('span');
|
||||
slotText.className = 'wm-slot-text wm-speed-text';
|
||||
host.appendChild(slotText);
|
||||
document.body.appendChild(host);
|
||||
|
||||
// 1. Classic UI (no data-modern-ui): strictly plain text, zero odometer reels
|
||||
patchCapsuleOdometerText(slotText, '37.2 t/s', { resetKey: 'tps' });
|
||||
assert.equal(slotText.textContent, '37.2 t/s');
|
||||
assert.equal(slotText.querySelectorAll('.wm-od-digit').length, 0);
|
||||
assert.equal(slotText.hasAttribute('data-od-active'), false);
|
||||
|
||||
// 2. Enable Modern UI: builds 3 digit reels in place and preserves reel identity across digit updates
|
||||
host.setAttribute('data-modern-ui', 'true');
|
||||
patchCapsuleOdometerText(slotText, '37.2 t/s', { resetKey: 'tps' });
|
||||
assert.equal(slotText.getAttribute('data-od-active'), '1');
|
||||
assert.equal(slotText.getAttribute('data-od-value'), '37.2 t/s');
|
||||
assert.equal(slotText.getAttribute('aria-label'), '37.2 t/s');
|
||||
const reels1 = slotText.querySelectorAll('.wm-od-digit');
|
||||
assert.equal(reels1.length, 3);
|
||||
const tensTrack = reels1[0].querySelector('.wm-od-track');
|
||||
const onesTrack = reels1[1].querySelector('.wm-od-track');
|
||||
const fracTrack = reels1[2].querySelector('.wm-od-track');
|
||||
assert.equal(tensTrack.style.getPropertyValue('--od-val'), '3');
|
||||
assert.equal(onesTrack.style.getPropertyValue('--od-val'), '7');
|
||||
assert.equal(fracTrack.style.getPropertyValue('--od-val'), '2');
|
||||
|
||||
// Update 37.2 -> 38.5: same DOM reel nodes reused, only changed digits update --od-val
|
||||
patchCapsuleOdometerText(slotText, '38.5 t/s', { resetKey: 'tps' });
|
||||
const reels2 = slotText.querySelectorAll('.wm-od-digit');
|
||||
assert.equal(reels2[0], reels1[0]);
|
||||
assert.equal(reels2[1], reels1[1]);
|
||||
assert.equal(reels2[2], reels1[2]);
|
||||
assert.equal(tensTrack.style.getPropertyValue('--od-val'), '3');
|
||||
assert.equal(onesTrack.style.getPropertyValue('--od-val'), '8');
|
||||
assert.equal(fracTrack.style.getPropertyValue('--od-val'), '5');
|
||||
|
||||
// Digit count change 38.5 -> 9.4 -> 12.6 preserves ones & tenths place reels cleanly
|
||||
patchCapsuleOdometerText(slotText, '9.4 t/s', { resetKey: 'tps' });
|
||||
const reels3 = slotText.querySelectorAll('.wm-od-digit');
|
||||
assert.equal(reels3.length, 2);
|
||||
assert.equal(reels3[0], reels1[1], 'Ones-place reel stays mounted across 2-digit -> 1-digit shrink');
|
||||
assert.equal(reels3[1], reels1[2], 'Tenths-place reel stays mounted');
|
||||
assert.equal(onesTrack.style.getPropertyValue('--od-val'), '9');
|
||||
assert.equal(fracTrack.style.getPropertyValue('--od-val'), '4');
|
||||
|
||||
patchCapsuleOdometerText(slotText, '12.6 t/s', { resetKey: 'tps' });
|
||||
const reels4 = slotText.querySelectorAll('.wm-od-digit');
|
||||
assert.equal(reels4.length, 3);
|
||||
assert.equal(reels4[1], reels1[1], 'Ones-place reel stays mounted across 1-digit -> 2-digit grow');
|
||||
assert.equal(reels4[2], reels1[2], 'Tenths-place reel stays mounted');
|
||||
assert.equal(reels4[0].querySelector('.wm-od-track').style.getPropertyValue('--od-val'), '1');
|
||||
assert.equal(onesTrack.style.getPropertyValue('--od-val'), '2');
|
||||
assert.equal(fracTrack.style.getPropertyValue('--od-val'), '6');
|
||||
|
||||
// 3. Disable Modern UI: restores clean plain text with zero leftover odometer DOM
|
||||
host.removeAttribute('data-modern-ui');
|
||||
patchCapsuleOdometerText(slotText, '12.6 t/s', { resetKey: 'tps' });
|
||||
assert.equal(slotText.textContent, '12.6 t/s');
|
||||
assert.equal(slotText.querySelectorAll('.wm-od-digit').length, 0);
|
||||
assert.equal(slotText.hasAttribute('data-od-active'), false);
|
||||
|
||||
// 4. Compiled CSS strictly scopes 150ms roll & 100ms color transition under [data-modern-ui="true"]
|
||||
const builtStyles = fs.readFileSync(new URL('../styles.css', import.meta.url), 'utf8');
|
||||
assert.match(builtStyles, /\.steps-inline-scope-select\s+\.select-menu[\s\S]*?left:\s*0;\s*right:\s*auto;/);
|
||||
assert.match(builtStyles, /\[data-modern-ui="true"\]\s+\.select-menu\.is-above/);
|
||||
assert.match(
|
||||
builtStyles,
|
||||
/\[data-modern-ui="true"\]\s+\.wm-od-track\s*\{[^}]*transition:\s*transform\s+150ms/
|
||||
);
|
||||
assert.match(
|
||||
builtStyles,
|
||||
/\[data-modern-ui="true"\]\s+\.wm-multi-label\s*\{[^}]*transition:\s*color\s+100ms/
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
builtStyles,
|
||||
/(?:^|\n)\.wm-od-track\s*\{/,
|
||||
'Odometer roll CSS must ONLY exist under [data-modern-ui="true"]'
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user