diff --git a/sidecars/panel/app.js b/sidecars/panel/app.js index c06b8f3..126e59a 100644 --- a/sidecars/panel/app.js +++ b/sidecars/panel/app.js @@ -1463,9 +1463,6 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({ 'quota.ratePopTitle': '实测倍率预估', 'quota.ratePopAccountScope': '{account}', 'quota.ratePopAccountCurrent': '当前账号', - 'quota.ratePopWkCapTitle': '预测周额度', - 'quota.ratePopWkCapPrelim': '· 初估', - 'quota.ratePopWkCapPartial': '· {ready}/{total} 池', 'quota.ratePopPoolFallback': '池综合均值', 'quota.ratePopEq5hLabel': '5h 满池', 'quota.ratePopEqWkLabel': '周限满池', @@ -1474,7 +1471,6 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({ 'quota.ratePopPrelimSlope': '斜率初估', 'quota.ratePopPrelimCycle': '周期初估', 'quota.ratePopEmpty': '暂未采集到足够的单模型干净样本(周限满 2% 或单模型满 3 次无抖动扣费后自动生成)。', - 'quota.ratePopNote': '按净消耗及精确计价折算,同池最省为 1x,按账号隔离。', 'quota.ratePopSharedBadge': '共享活跃', 'quota.ratePopSharedBadgeTip': '最近 15 分钟内检测到同池外部消耗,新增预占将在二次验证后展示', 'quota.ratePopExternalDetail': '检测到家庭组 / 其他设备消耗(已排除约 {detail}),不计入预占', @@ -2366,9 +2362,6 @@ const I18N_MESSAGES_EN_US = Object.freeze({ 'quota.ratePopTitle': 'Estimated Burn Rates', 'quota.ratePopAccountScope': '{account}', 'quota.ratePopAccountCurrent': 'Current account', - 'quota.ratePopWkCapTitle': 'Est. Weekly Quota', - 'quota.ratePopWkCapPrelim': '· est.', - 'quota.ratePopWkCapPartial': '· {ready}/{total} pools', 'quota.ratePopPoolFallback': 'Pool average', 'quota.ratePopEq5hLabel': '5h full', 'quota.ratePopEqWkLabel': 'Weekly full', @@ -2377,7 +2370,6 @@ const I18N_MESSAGES_EN_US = Object.freeze({ 'quota.ratePopPrelimSlope': 'slope est.', 'quota.ratePopPrelimCycle': 'cycle est.', 'quota.ratePopEmpty': 'Not enough clean samples yet (unlocks at 2% weekly burn or 3 clean single-model steps).', - 'quota.ratePopNote': 'Measured from net burn & priced steps; lowest in pool = 1x. Account isolated.', 'quota.ratePopSharedBadge': 'Shared active', 'quota.ratePopSharedBadgeTip': 'External pool usage seen within 15 min; new reservations display after verification', 'quota.ratePopExternalDetail': 'Family group / other-device usage detected (~{detail} excluded from reservations)', @@ -14244,8 +14236,6 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { let hoveredCellEl = null; let lastPointer = null; let lastRenderSig = ''; - let lastTickLabelsSig = ''; - let hasRenderedOnce = false; let hasRenderedLineOnce = false; let peakReadyArmed = false; let peakReadyRaf = 0; @@ -14253,40 +14243,13 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { let morphRafId = 0; let committedSegs = []; let liveMorphSegs = null; - const transientClassTimers = new Map(); + const vGridLinePool = []; + const xAxisTickPool = []; + const hmMonthPool = []; + const hmCellPool = []; const CURVE_MORPH_DURATION_MS = 240; - function cleanupTransientClass(el) { - const rec = transientClassTimers.get(el); - if (!rec) return; - clearTimeout(rec.tid); - el?.removeEventListener?.('animationend', rec.onEnd); - el?.classList?.remove(rec.cls); - transientClassTimers.delete(el); - } - - function triggerTransientClass(el, cls, fallbackMs = 650) { - if (!el || !el.classList) return; - cleanupTransientClass(el); - el.classList.remove(cls); - void el.offsetWidth; - const onEnd = (ev) => { - if (ev && ev.target && ev.target !== el) return; - cleanupTransientClass(el); - }; - const tid = setTimeout(() => cleanupTransientClass(el), fallbackMs); - transientClassTimers.set(el, { cls, tid, onEnd }); - el.addEventListener?.('animationend', onEnd); - el.classList.add(cls); - } - - function clearAllTransientTimers() { - for (const el of Array.from(transientClassTimers.keys())) { - cleanupTransientClass(el); - } - } - function cancelCurveMorph() { if ( morphRafId && @@ -14912,7 +14875,6 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { cancelTipTrackRaf(); cancelCurveMorph(); cancelPeakReadyRaf(); - clearAllTransientTimers(); plotStage.removeEventListener('mousemove', handlePointerMove); plotStage.removeEventListener('click', handleLineClick); plotStage.removeEventListener('mouseleave', clearHover); @@ -14961,14 +14923,6 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { patchAttr(plotStage, 'hidden', useHeatmap); patchAttr(xAxisEl, 'hidden', useHeatmap); patchAttr(heatmapStage, 'hidden', !useHeatmap); - if (hasRenderedOnce && modeChanged && canAnimateInBrowser()) { - if (useHeatmap) { - triggerTransientClass(heatmapStage, 'is-stage-entering'); - } else { - triggerTransientClass(plotStage, 'is-stage-entering'); - triggerTransientClass(xAxisEl, 'is-switching'); - } - } if (!useHeatmap) { syncViewWidth(); @@ -15042,51 +14996,97 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { patchStyleVar(hmBodyEl, '--hm-weeks', String(totalWeeks)); patchStyleVar(hmBodyEl, '--hm-gap', `${gapPx}px`); - // 重建顶部对齐月份标签 - while (hmMonthsEl.firstChild) hmMonthsEl.removeChild(hmMonthsEl.firstChild); + // 就地增量补丁顶部对齐月份标签,避免文字节点销毁重建 const monthTicks = buildHeatmapMonthTicks(slots, firstDow, totalWeeks); - for (const mt of monthTicks) { - const mEl = h('span', { className: 'trend-hm-month text-mono', text: mt.text }); + for (let i = 0; i < monthTicks.length; i++) { + const mt = monthTicks[i]; + let mEl = hmMonthPool[i]; + if (!mEl) { + mEl = h('span', { className: 'trend-hm-month text-mono' }); + hmMonthPool.push(mEl); + } + patchText(mEl, mt.text); patchStyleVar(mEl, '--hm-col', String(mt.col)); - hmMonthsEl.appendChild(mEl); + if (hmMonthsEl.children[i] !== mEl) { + hmMonthsEl.insertBefore(mEl, hmMonthsEl.children[i] || null); + } + } + while (hmMonthsEl.children.length > monthTicks.length) { + hmMonthsEl.removeChild(hmMonthsEl.lastChild); } - // 重建 7 行 × N 周列的每日小格子(一格一天),使用 DocumentFragment 一次性批量挂载减少重排 - while (hmGridEl.firstChild) hmGridEl.removeChild(hmGridEl.firstChild); - hoveredCellEl = null; + // 就地增量复用 7 行 × N 周列的每日小格子,首次批量新增节点使用 DocumentFragment 挂载 currentCellEls = new Array(slots.length); - const gridFrag = - typeof document !== 'undefined' && typeof document.createDocumentFragment === 'function' + const prevMountedCount = hmGridEl.children.length; + const newCellsFrag = + totalCells > prevMountedCount && + typeof document !== 'undefined' && + typeof document.createDocumentFragment === 'function' ? document.createDocumentFragment() : null; - const gridTarget = gridFrag || hmGridEl; - for (let pad = 0; pad < firstDow; pad++) { - gridTarget.appendChild( - h('span', { className: 'trend-hm-cell is-pad', 'aria-hidden': 'true' }) - ); + for (let nodeIdx = 0; nodeIdx < totalCells; nodeIdx++) { + let cellEl = hmCellPool[nodeIdx]; + if (!cellEl) { + cellEl = h('span', { className: 'trend-hm-cell' }); + hmCellPool.push(cellEl); + } + if (nodeIdx < firstDow) { + patchClasses(cellEl, { + 'is-pad': true, + 'is-hovered': false, + 'lv-0': false, + 'lv-1': false, + 'lv-2': false, + 'lv-3': false, + 'lv-4': false, + }); + patchAttr(cellEl, 'aria-hidden', 'true'); + patchAttr(cellEl, 'role', null); + patchAttr(cellEl, 'data-slot-idx', null); + patchAttr(cellEl, 'data-hm-col', null); + patchAttr(cellEl, 'data-hm-row', null); + } else { + const i = nodeIdx - firstDow; + const slot = slots[i]; + const tok = safeSlotTokens(slot?.tokens); + const lv = resolveHeatmapLevel(tok, thresholds); + const col = Math.floor(nodeIdx / 7); + const row = nodeIdx % 7; + patchClasses(cellEl, { + 'is-pad': false, + 'is-hovered': hoveredIdx === i, + 'lv-0': lv === 0, + 'lv-1': lv === 1, + 'lv-2': lv === 2, + 'lv-3': lv === 3, + 'lv-4': lv === 4, + }); + patchAttr(cellEl, 'aria-hidden', null); + patchAttr(cellEl, 'role', 'gridcell'); + patchAttr(cellEl, 'data-slot-idx', String(i)); + patchAttr(cellEl, 'data-hm-col', String(col)); + patchAttr(cellEl, 'data-hm-row', String(row)); + currentCellEls[i] = cellEl; + } + if (nodeIdx < prevMountedCount) { + if (hmGridEl.children[nodeIdx] !== cellEl) { + hmGridEl.insertBefore(cellEl, hmGridEl.children[nodeIdx] || null); + } + } else if (newCellsFrag) { + newCellsFrag.appendChild(cellEl); + } else { + hmGridEl.appendChild(cellEl); + } } - - for (let i = 0; i < slots.length; i++) { - const slot = slots[i]; - const tok = safeSlotTokens(slot?.tokens); - const lv = resolveHeatmapLevel(tok, thresholds); - const gridPos = firstDow + i; - const col = Math.floor(gridPos / 7); - const row = gridPos % 7; - const cellEl = h('span', { - className: `trend-hm-cell lv-${lv}`, - 'data-slot-idx': String(i), - 'data-hm-col': String(col), - 'data-hm-row': String(row), - role: 'gridcell', - }); - gridTarget.appendChild(cellEl); - currentCellEls[i] = cellEl; + if (newCellsFrag) { + hmGridEl.appendChild(newCellsFrag); } - if (gridFrag) { - hmGridEl.appendChild(gridFrag); + while (hmGridEl.children.length > totalCells) { + hmGridEl.removeChild(hmGridEl.lastChild); } + hoveredCellEl = + hoveredIdx >= 0 && hoveredIdx < slots.length ? currentCellEls[hoveredIdx] || null : null; if (typeof requestAnimationFrame === 'function') { requestAnimationFrame(() => { @@ -15114,7 +15114,6 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { } else if (hoveredIdx >= 0) { showHeatmapHoverAtIndex(hoveredIdx, currentCellEls[hoveredIdx], lastPointer); } - hasRenderedOnce = true; return; } @@ -15175,21 +15174,11 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { } hasRenderedLineOnce = true; - // 渲染对齐底部刻度的垂直参考网格线及 X 轴标签(起止标签严格左右贴边) + // 就地增量补丁垂直参考网格线及底部 X 轴标签,保持文字常驻不重排不闪烁 const tickIndices = computeTickIndices(slots); - const nextTickLabelsSig = tickIndices - .map((tIdx) => `${tIdx}:${slots[tIdx]?.label || ''}`) - .join('|'); - const ticksChanged = - hasRenderedOnce && - !modeChanged && - lastTickLabelsSig !== '' && - nextTickLabelsSig !== lastTickLabelsSig; - lastTickLabelsSig = nextTickLabelsSig; - - while (vGridGroup.firstChild) vGridGroup.removeChild(vGridGroup.firstChild); - while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild); tickElsByIdx = new Map(); + let vLineCount = 0; + let tickCount = 0; for (let i = 0; i < tickIndices.length; i++) { const tIdx = tickIndices[i]; @@ -15198,34 +15187,57 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { if (!pt || !slot) continue; if (i > 0 && i < tickIndices.length - 1) { - const vLine = document.createElementNS(SVG_NS, 'line'); - vLine.setAttribute('x1', pt.x.toFixed(1)); - vLine.setAttribute('y1', '16'); - vLine.setAttribute('x2', pt.x.toFixed(1)); - vLine.setAttribute('y2', String(BOTTOM_Y)); - vGridGroup.appendChild(vLine); + let vLine = vGridLinePool[vLineCount]; + if (!vLine) { + vLine = document.createElementNS(SVG_NS, 'line'); + vLine.setAttribute('y1', '16'); + vLine.setAttribute('y2', String(BOTTOM_Y)); + vGridLinePool.push(vLine); + } + const xFixed = pt.x.toFixed(1); + patchAttr(vLine, 'x1', xFixed); + patchAttr(vLine, 'x2', xFixed); + if (vGridGroup.children[vLineCount] !== vLine) { + vGridGroup.insertBefore(vLine, vGridGroup.children[vLineCount] || null); + } + vLineCount++; } const isFirst = !isSingle && i === 0; const isLast = !isSingle && i === tickIndices.length - 1; const pct = isFirst ? 0 : isLast ? 100 : (pt.x / viewW) * 100; - const tickEl = h('span', { - className: `trend-x-tick text-mono${isFirst ? ' is-start' : isLast ? ' is-end' : ''}`, - text: slot.label || '', - title: formatTrendSlotFullLabel(slot) || slot.label || '', + let tickRec = xAxisTickPool[tickCount]; + if (!tickRec) { + const el = h('span', { className: 'trend-x-tick text-mono' }); + const rec = { el, slotIdx: tIdx }; + el.onclick = () => { + lastPointer = null; + showLineHoverAtIndex(rec.slotIdx); + }; + tickRec = rec; + xAxisTickPool.push(tickRec); + } + tickRec.slotIdx = tIdx; + patchClasses(tickRec.el, { + 'is-start': isFirst, + 'is-end': isLast, + 'is-hovered': hoveredIdx === tIdx, }); - patchStyleVar(tickEl, '--tick-x', `${pct.toFixed(2)}%`); - tickEl.onclick = () => { - lastPointer = null; - showLineHoverAtIndex(tIdx); - }; - xAxisEl.appendChild(tickEl); - tickElsByIdx.set(tIdx, tickEl); + patchText(tickRec.el, slot.label || ''); + patchAttr(tickRec.el, 'title', formatTrendSlotFullLabel(slot) || slot.label || ''); + patchStyleVar(tickRec.el, '--tick-x', `${pct.toFixed(2)}%`); + if (xAxisEl.children[tickCount] !== tickRec.el) { + xAxisEl.insertBefore(tickRec.el, xAxisEl.children[tickCount] || null); + } + tickElsByIdx.set(tIdx, tickRec.el); + tickCount++; } - if (ticksChanged && canAnimateInBrowser()) { - triggerTransientClass(xAxisEl, 'is-switching'); - triggerTransientClass(vGridGroup, 'is-switching'); + while (vGridGroup.children.length > vLineCount) { + vGridGroup.removeChild(vGridGroup.lastChild); + } + while (xAxisEl.children.length > tickCount) { + xAxisEl.removeChild(xAxisEl.lastChild); } } @@ -15259,7 +15271,6 @@ function createTrendAreaChart({ onSelectSlot = null } = {}) { } else if (hoveredIdx >= 0) { showLineHoverAtIndex(hoveredIdx, lastPointer); } - hasRenderedOnce = true; } return { el: chartWrap, update, destroy }; @@ -19598,88 +19609,6 @@ function formatPoolFullCapRef(eqUsd, eqTok) { return usdStr; } -function resolveWeeklyCapacitySummary(quotas) { - if (!quotas || typeof quotas !== 'object') return null; - if (quotas.weekly?.isOfficial === false) return null; - const direct = quotas.weeklyCapacityEstimate; - if (direct && typeof direct === 'object') { - if ( - direct.status === 'custom_mode' || - !Number.isFinite(Number(direct.totalEqWeeklyUsd)) || - Number(direct.totalEqWeeklyUsd) <= 0 - ) { - return null; - } - return direct; - } - - const rawPools = Array.isArray(quotas.pools) ? quotas.pools : []; - const candidatePools = rawPools.filter( - (p) => - p && - (p.hasWeekly || - p.weeklyUsedPct != null || - Number.isFinite(p.rateEstimate?.eqFullWeeklyUsd)) - ); - const targetPools = candidatePools.length > 0 ? candidatePools : rawPools; - if (targetPools.length === 0) return null; - - let sumUsd = 0; - let sumTokens = 0; - let readyPoolCount = 0; - let tokenReadyPoolCount = 0; - let hasPreliminary = false; - - for (const p of targetPools) { - const est = p?.rateEstimate && typeof p.rateEstimate === 'object' ? p.rateEstimate : null; - let eqUsd = - Number.isFinite(est?.eqFullWeeklyUsd) && est.eqFullWeeklyUsd > 0 - ? Number(est.eqFullWeeklyUsd) - : null; - let eqTok = - Number.isFinite(est?.eqFullWeeklyTokens) && est.eqFullWeeklyTokens > 0 - ? Math.round(Number(est.eqFullWeeklyTokens)) - : null; - if (eqUsd === null && Array.isArray(est?.models) && est.models.length > 0) { - const wkModels = est.models.filter( - (m) => Number.isFinite(m?.eqFullWeeklyUsd) && m.eqFullWeeklyUsd > 0 - ); - if (wkModels.length > 0) { - eqUsd = - wkModels.reduce((acc, m) => acc + Number(m.eqFullWeeklyUsd), 0) / wkModels.length; - const tokModels = wkModels.filter( - (m) => Number.isFinite(m?.eqFullWeeklyTokens) && m.eqFullWeeklyTokens > 0 - ); - if (tokModels.length === wkModels.length) { - eqTok = Math.round( - tokModels.reduce((acc, m) => acc + Number(m.eqFullWeeklyTokens), 0) / tokModels.length - ); - } - } - } - if (eqUsd !== null) { - readyPoolCount += 1; - sumUsd += eqUsd; - if (est?.isPreliminaryWeekly) hasPreliminary = true; - if (eqTok !== null) { - tokenReadyPoolCount += 1; - sumTokens += eqTok; - } - } - } - - if (readyPoolCount === 0) return null; - const totalPoolCount = targetPools.length; - return { - status: readyPoolCount < totalPoolCount ? 'partial' : 'ready', - totalEqWeeklyUsd: +sumUsd.toFixed(1), - totalEqWeeklyTokens: tokenReadyPoolCount === readyPoolCount ? Math.round(sumTokens) : null, - readyPoolCount, - totalPoolCount, - hasPreliminary, - }; -} - function formatRatePerUsdValue(rate) { const num = Number(rate); if (!Number.isFinite(num) || num <= 0) return '--'; @@ -19804,13 +19733,11 @@ function createRateModelCard({ function buildRatePopoverSig(data) { const locale = getEffectiveLocale(); const acct = String(data?.account?.email || data?.account?.name || '').trim(); - const isOfficial = data?.quotas?.weekly?.isOfficial !== false; - const wkCapSig = JSON.stringify(data?.quotas?.weeklyCapacityEstimate || null); const pools = Array.isArray(data?.quotas?.pools) ? data.quotas.pools : []; const poolSig = pools .map((p) => `${p.poolKey || ''}:${p.poolLabel || ''}:${JSON.stringify(p.rateEstimate || null)}`) .join('|'); - return `${locale}|${acct}|${isOfficial}|${wkCapSig}|${poolSig}`; + return `${locale}|${acct}|${poolSig}`; } const QuotaPoolsWidget = defineComponent({ @@ -19828,32 +19755,7 @@ const QuotaPoolsWidget = defineComponent({ className: 'quota-rate-pop-account', text: t('quota.ratePopAccountCurrent'), }); - const ratePopWkLabelEl = h('span', { text: t('quota.ratePopWkCapTitle') }); - const ratePopWkSubEl = h('span', { - className: 'quota-rate-wk-sub', - hidden: true, - text: '', - }); - const ratePopWkUsdEl = h('span', { className: 'quota-rate-wk-usd text-mono', text: '--' }); - const ratePopWkTokEl = h('span', { - className: 'quota-rate-wk-tok text-mono', - hidden: true, - text: '', - }); - const ratePopWkSummaryEl = h( - 'div', - { className: 'quota-rate-wk-summary', hidden: true }, - [ - h('span', { className: 'quota-rate-wk-k' }, [ratePopWkLabelEl, ratePopWkSubEl]), - h('span', { className: 'quota-rate-wk-v' }, [ratePopWkUsdEl, ratePopWkTokEl]), - ] - ); - ratePopWkSummaryEl.hidden = true; const ratePopBodyEl = h('div', { className: 'quota-rate-pop-body' }); - const ratePopNoteEl = h('div', { - className: 'quota-rate-pop-note', - text: t('quota.ratePopNote'), - }); const ratePopoverEl = h( 'div', { @@ -19863,9 +19765,7 @@ const QuotaPoolsWidget = defineComponent({ }, [ h('div', { className: 'quota-rate-pop-head' }, [ratePopTitleEl, ratePopAccountEl]), - ratePopWkSummaryEl, ratePopBodyEl, - ratePopNoteEl, ] ); ratePopoverEl.hidden = true; @@ -19943,7 +19843,6 @@ const QuotaPoolsWidget = defineComponent({ lastRatePopSig = sig; patchText(ratePopTitleEl, t('quota.ratePopTitle')); - patchText(ratePopNoteEl, t('quota.ratePopNote')); patchAttr(rateHelpBtn, 'aria-label', t('quota.rateHelpAria')); const acctMasked = maskAccountLabel(data?.account?.email || data?.account?.name || ''); @@ -19955,38 +19854,6 @@ const QuotaPoolsWidget = defineComponent({ ); patchAttr(ratePopAccountEl, 'title', acctMasked || null); - const wkCap = resolveWeeklyCapacitySummary(data?.quotas); - if (wkCap) { - ratePopWkSummaryEl.hidden = false; - patchAttr(ratePopWkSummaryEl, 'hidden', false); - patchText(ratePopWkLabelEl, t('quota.ratePopWkCapTitle')); - const wkSubText = - wkCap.status === 'partial' && Number(wkCap.totalPoolCount) > 0 - ? t('quota.ratePopWkCapPartial', { - ready: Number(wkCap.readyPoolCount) || 0, - total: Number(wkCap.totalPoolCount) || 0, - }) - : wkCap.hasPreliminary - ? t('quota.ratePopWkCapPrelim') - : ''; - ratePopWkSubEl.hidden = !wkSubText; - patchAttr(ratePopWkSubEl, 'hidden', !wkSubText); - patchText(ratePopWkSubEl, wkSubText); - patchText(ratePopWkUsdEl, `≈ ${formatRateEqUsd(wkCap.totalEqWeeklyUsd)}`); - const hasWkTok = - Number.isFinite(Number(wkCap.totalEqWeeklyTokens)) && - Number(wkCap.totalEqWeeklyTokens) > 0; - ratePopWkTokEl.hidden = !hasWkTok; - patchAttr(ratePopWkTokEl, 'hidden', !hasWkTok); - patchText( - ratePopWkTokEl, - hasWkTok ? `· ${formatTokens(Number(wkCap.totalEqWeeklyTokens))}` : '' - ); - } else { - ratePopWkSummaryEl.hidden = true; - patchAttr(ratePopWkSummaryEl, 'hidden', true); - } - while (ratePopBodyEl.firstChild) { ratePopBodyEl.removeChild(ratePopBodyEl.firstChild); } @@ -30473,11 +30340,7 @@ const ConsumptionView = defineComponent({ let lastAnimatedRankingKey = ''; let lastAnimatedSortSig = ''; const consAnimTimers = new Map(); - const TRANSIENT_CONS_CLASSES = [ - 'is-range-switching', - 'is-tab-entering', - 'is-bars-revealing', - ]; + const TRANSIENT_CONS_CLASSES = ['is-bars-revealing']; function cleanupConsAnim(el) { const rec = consAnimTimers.get(el); @@ -32295,13 +32158,7 @@ const ConsumptionView = defineComponent({ !tabSwitched && nextSortSig !== lastAnimatedSortSig; - if (rangeSwitched) { - triggerConsAnim(unifiedMatrixEl, 'is-range-switching'); - triggerConsAnim(activeRankingEl, 'is-range-switching'); - triggerConsAnim(sourcesListEl, 'is-range-switching'); - } else if (tabSwitched) { - triggerConsAnim(activeRankingEl, 'is-tab-entering'); - } else if (sortSwitched) { + if (tabSwitched || sortSwitched) { triggerConsAnim(activeRankingEl, 'is-bars-revealing'); } if (!hasCompletedInitialDraw) { diff --git a/sidecars/panel/index.html b/sidecars/panel/index.html index 2cff9c0..f295268 100644 --- a/sidecars/panel/index.html +++ b/sidecars/panel/index.html @@ -4,11 +4,11 @@ 用量监控 - +
- + diff --git a/sidecars/panel/src/components/charts/TrendAreaChart.js b/sidecars/panel/src/components/charts/TrendAreaChart.js index 90575c5..bb75c6f 100644 --- a/sidecars/panel/src/components/charts/TrendAreaChart.js +++ b/sidecars/panel/src/components/charts/TrendAreaChart.js @@ -553,8 +553,6 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { let hoveredCellEl = null; let lastPointer = null; let lastRenderSig = ''; - let lastTickLabelsSig = ''; - let hasRenderedOnce = false; let hasRenderedLineOnce = false; let peakReadyArmed = false; let peakReadyRaf = 0; @@ -562,40 +560,13 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { let morphRafId = 0; let committedSegs = []; let liveMorphSegs = null; - const transientClassTimers = new Map(); + const vGridLinePool = []; + const xAxisTickPool = []; + const hmMonthPool = []; + const hmCellPool = []; const CURVE_MORPH_DURATION_MS = 240; - function cleanupTransientClass(el) { - const rec = transientClassTimers.get(el); - if (!rec) return; - clearTimeout(rec.tid); - el?.removeEventListener?.('animationend', rec.onEnd); - el?.classList?.remove(rec.cls); - transientClassTimers.delete(el); - } - - function triggerTransientClass(el, cls, fallbackMs = 650) { - if (!el || !el.classList) return; - cleanupTransientClass(el); - el.classList.remove(cls); - void el.offsetWidth; - const onEnd = (ev) => { - if (ev && ev.target && ev.target !== el) return; - cleanupTransientClass(el); - }; - const tid = setTimeout(() => cleanupTransientClass(el), fallbackMs); - transientClassTimers.set(el, { cls, tid, onEnd }); - el.addEventListener?.('animationend', onEnd); - el.classList.add(cls); - } - - function clearAllTransientTimers() { - for (const el of Array.from(transientClassTimers.keys())) { - cleanupTransientClass(el); - } - } - function cancelCurveMorph() { if ( morphRafId && @@ -1221,7 +1192,6 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { cancelTipTrackRaf(); cancelCurveMorph(); cancelPeakReadyRaf(); - clearAllTransientTimers(); plotStage.removeEventListener('mousemove', handlePointerMove); plotStage.removeEventListener('click', handleLineClick); plotStage.removeEventListener('mouseleave', clearHover); @@ -1270,14 +1240,6 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { patchAttr(plotStage, 'hidden', useHeatmap); patchAttr(xAxisEl, 'hidden', useHeatmap); patchAttr(heatmapStage, 'hidden', !useHeatmap); - if (hasRenderedOnce && modeChanged && canAnimateInBrowser()) { - if (useHeatmap) { - triggerTransientClass(heatmapStage, 'is-stage-entering'); - } else { - triggerTransientClass(plotStage, 'is-stage-entering'); - triggerTransientClass(xAxisEl, 'is-switching'); - } - } if (!useHeatmap) { syncViewWidth(); @@ -1351,51 +1313,97 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { patchStyleVar(hmBodyEl, '--hm-weeks', String(totalWeeks)); patchStyleVar(hmBodyEl, '--hm-gap', `${gapPx}px`); - // 重建顶部对齐月份标签 - while (hmMonthsEl.firstChild) hmMonthsEl.removeChild(hmMonthsEl.firstChild); + // 就地增量补丁顶部对齐月份标签,避免文字节点销毁重建 const monthTicks = buildHeatmapMonthTicks(slots, firstDow, totalWeeks); - for (const mt of monthTicks) { - const mEl = h('span', { className: 'trend-hm-month text-mono', text: mt.text }); + for (let i = 0; i < monthTicks.length; i++) { + const mt = monthTicks[i]; + let mEl = hmMonthPool[i]; + if (!mEl) { + mEl = h('span', { className: 'trend-hm-month text-mono' }); + hmMonthPool.push(mEl); + } + patchText(mEl, mt.text); patchStyleVar(mEl, '--hm-col', String(mt.col)); - hmMonthsEl.appendChild(mEl); + if (hmMonthsEl.children[i] !== mEl) { + hmMonthsEl.insertBefore(mEl, hmMonthsEl.children[i] || null); + } + } + while (hmMonthsEl.children.length > monthTicks.length) { + hmMonthsEl.removeChild(hmMonthsEl.lastChild); } - // 重建 7 行 × N 周列的每日小格子(一格一天),使用 DocumentFragment 一次性批量挂载减少重排 - while (hmGridEl.firstChild) hmGridEl.removeChild(hmGridEl.firstChild); - hoveredCellEl = null; + // 就地增量复用 7 行 × N 周列的每日小格子,首次批量新增节点使用 DocumentFragment 挂载 currentCellEls = new Array(slots.length); - const gridFrag = - typeof document !== 'undefined' && typeof document.createDocumentFragment === 'function' + const prevMountedCount = hmGridEl.children.length; + const newCellsFrag = + totalCells > prevMountedCount && + typeof document !== 'undefined' && + typeof document.createDocumentFragment === 'function' ? document.createDocumentFragment() : null; - const gridTarget = gridFrag || hmGridEl; - for (let pad = 0; pad < firstDow; pad++) { - gridTarget.appendChild( - h('span', { className: 'trend-hm-cell is-pad', 'aria-hidden': 'true' }) - ); + for (let nodeIdx = 0; nodeIdx < totalCells; nodeIdx++) { + let cellEl = hmCellPool[nodeIdx]; + if (!cellEl) { + cellEl = h('span', { className: 'trend-hm-cell' }); + hmCellPool.push(cellEl); + } + if (nodeIdx < firstDow) { + patchClasses(cellEl, { + 'is-pad': true, + 'is-hovered': false, + 'lv-0': false, + 'lv-1': false, + 'lv-2': false, + 'lv-3': false, + 'lv-4': false, + }); + patchAttr(cellEl, 'aria-hidden', 'true'); + patchAttr(cellEl, 'role', null); + patchAttr(cellEl, 'data-slot-idx', null); + patchAttr(cellEl, 'data-hm-col', null); + patchAttr(cellEl, 'data-hm-row', null); + } else { + const i = nodeIdx - firstDow; + const slot = slots[i]; + const tok = safeSlotTokens(slot?.tokens); + const lv = resolveHeatmapLevel(tok, thresholds); + const col = Math.floor(nodeIdx / 7); + const row = nodeIdx % 7; + patchClasses(cellEl, { + 'is-pad': false, + 'is-hovered': hoveredIdx === i, + 'lv-0': lv === 0, + 'lv-1': lv === 1, + 'lv-2': lv === 2, + 'lv-3': lv === 3, + 'lv-4': lv === 4, + }); + patchAttr(cellEl, 'aria-hidden', null); + patchAttr(cellEl, 'role', 'gridcell'); + patchAttr(cellEl, 'data-slot-idx', String(i)); + patchAttr(cellEl, 'data-hm-col', String(col)); + patchAttr(cellEl, 'data-hm-row', String(row)); + currentCellEls[i] = cellEl; + } + if (nodeIdx < prevMountedCount) { + if (hmGridEl.children[nodeIdx] !== cellEl) { + hmGridEl.insertBefore(cellEl, hmGridEl.children[nodeIdx] || null); + } + } else if (newCellsFrag) { + newCellsFrag.appendChild(cellEl); + } else { + hmGridEl.appendChild(cellEl); + } } - - for (let i = 0; i < slots.length; i++) { - const slot = slots[i]; - const tok = safeSlotTokens(slot?.tokens); - const lv = resolveHeatmapLevel(tok, thresholds); - const gridPos = firstDow + i; - const col = Math.floor(gridPos / 7); - const row = gridPos % 7; - const cellEl = h('span', { - className: `trend-hm-cell lv-${lv}`, - 'data-slot-idx': String(i), - 'data-hm-col': String(col), - 'data-hm-row': String(row), - role: 'gridcell', - }); - gridTarget.appendChild(cellEl); - currentCellEls[i] = cellEl; + if (newCellsFrag) { + hmGridEl.appendChild(newCellsFrag); } - if (gridFrag) { - hmGridEl.appendChild(gridFrag); + while (hmGridEl.children.length > totalCells) { + hmGridEl.removeChild(hmGridEl.lastChild); } + hoveredCellEl = + hoveredIdx >= 0 && hoveredIdx < slots.length ? currentCellEls[hoveredIdx] || null : null; if (typeof requestAnimationFrame === 'function') { requestAnimationFrame(() => { @@ -1423,7 +1431,6 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { } else if (hoveredIdx >= 0) { showHeatmapHoverAtIndex(hoveredIdx, currentCellEls[hoveredIdx], lastPointer); } - hasRenderedOnce = true; return; } @@ -1484,21 +1491,11 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { } hasRenderedLineOnce = true; - // 渲染对齐底部刻度的垂直参考网格线及 X 轴标签(起止标签严格左右贴边) + // 就地增量补丁垂直参考网格线及底部 X 轴标签,保持文字常驻不重排不闪烁 const tickIndices = computeTickIndices(slots); - const nextTickLabelsSig = tickIndices - .map((tIdx) => `${tIdx}:${slots[tIdx]?.label || ''}`) - .join('|'); - const ticksChanged = - hasRenderedOnce && - !modeChanged && - lastTickLabelsSig !== '' && - nextTickLabelsSig !== lastTickLabelsSig; - lastTickLabelsSig = nextTickLabelsSig; - - while (vGridGroup.firstChild) vGridGroup.removeChild(vGridGroup.firstChild); - while (xAxisEl.firstChild) xAxisEl.removeChild(xAxisEl.firstChild); tickElsByIdx = new Map(); + let vLineCount = 0; + let tickCount = 0; for (let i = 0; i < tickIndices.length; i++) { const tIdx = tickIndices[i]; @@ -1507,34 +1504,57 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { if (!pt || !slot) continue; if (i > 0 && i < tickIndices.length - 1) { - const vLine = document.createElementNS(SVG_NS, 'line'); - vLine.setAttribute('x1', pt.x.toFixed(1)); - vLine.setAttribute('y1', '16'); - vLine.setAttribute('x2', pt.x.toFixed(1)); - vLine.setAttribute('y2', String(BOTTOM_Y)); - vGridGroup.appendChild(vLine); + let vLine = vGridLinePool[vLineCount]; + if (!vLine) { + vLine = document.createElementNS(SVG_NS, 'line'); + vLine.setAttribute('y1', '16'); + vLine.setAttribute('y2', String(BOTTOM_Y)); + vGridLinePool.push(vLine); + } + const xFixed = pt.x.toFixed(1); + patchAttr(vLine, 'x1', xFixed); + patchAttr(vLine, 'x2', xFixed); + if (vGridGroup.children[vLineCount] !== vLine) { + vGridGroup.insertBefore(vLine, vGridGroup.children[vLineCount] || null); + } + vLineCount++; } const isFirst = !isSingle && i === 0; const isLast = !isSingle && i === tickIndices.length - 1; const pct = isFirst ? 0 : isLast ? 100 : (pt.x / viewW) * 100; - const tickEl = h('span', { - className: `trend-x-tick text-mono${isFirst ? ' is-start' : isLast ? ' is-end' : ''}`, - text: slot.label || '', - title: formatTrendSlotFullLabel(slot) || slot.label || '', + let tickRec = xAxisTickPool[tickCount]; + if (!tickRec) { + const el = h('span', { className: 'trend-x-tick text-mono' }); + const rec = { el, slotIdx: tIdx }; + el.onclick = () => { + lastPointer = null; + showLineHoverAtIndex(rec.slotIdx); + }; + tickRec = rec; + xAxisTickPool.push(tickRec); + } + tickRec.slotIdx = tIdx; + patchClasses(tickRec.el, { + 'is-start': isFirst, + 'is-end': isLast, + 'is-hovered': hoveredIdx === tIdx, }); - patchStyleVar(tickEl, '--tick-x', `${pct.toFixed(2)}%`); - tickEl.onclick = () => { - lastPointer = null; - showLineHoverAtIndex(tIdx); - }; - xAxisEl.appendChild(tickEl); - tickElsByIdx.set(tIdx, tickEl); + patchText(tickRec.el, slot.label || ''); + patchAttr(tickRec.el, 'title', formatTrendSlotFullLabel(slot) || slot.label || ''); + patchStyleVar(tickRec.el, '--tick-x', `${pct.toFixed(2)}%`); + if (xAxisEl.children[tickCount] !== tickRec.el) { + xAxisEl.insertBefore(tickRec.el, xAxisEl.children[tickCount] || null); + } + tickElsByIdx.set(tIdx, tickRec.el); + tickCount++; } - if (ticksChanged && canAnimateInBrowser()) { - triggerTransientClass(xAxisEl, 'is-switching'); - triggerTransientClass(vGridGroup, 'is-switching'); + while (vGridGroup.children.length > vLineCount) { + vGridGroup.removeChild(vGridGroup.lastChild); + } + while (xAxisEl.children.length > tickCount) { + xAxisEl.removeChild(xAxisEl.lastChild); } } @@ -1568,7 +1588,6 @@ export function createTrendAreaChart({ onSelectSlot = null } = {}) { } else if (hoveredIdx >= 0) { showLineHoverAtIndex(hoveredIdx, lastPointer); } - hasRenderedOnce = true; } return { el: chartWrap, update, destroy }; diff --git a/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js b/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js index 157d4dc..83614b4 100644 --- a/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js +++ b/sidecars/panel/src/components/widgets/QuotaPoolsWidget.js @@ -424,88 +424,6 @@ function formatPoolFullCapRef(eqUsd, eqTok) { return usdStr; } -function resolveWeeklyCapacitySummary(quotas) { - if (!quotas || typeof quotas !== 'object') return null; - if (quotas.weekly?.isOfficial === false) return null; - const direct = quotas.weeklyCapacityEstimate; - if (direct && typeof direct === 'object') { - if ( - direct.status === 'custom_mode' || - !Number.isFinite(Number(direct.totalEqWeeklyUsd)) || - Number(direct.totalEqWeeklyUsd) <= 0 - ) { - return null; - } - return direct; - } - - const rawPools = Array.isArray(quotas.pools) ? quotas.pools : []; - const candidatePools = rawPools.filter( - (p) => - p && - (p.hasWeekly || - p.weeklyUsedPct != null || - Number.isFinite(p.rateEstimate?.eqFullWeeklyUsd)) - ); - const targetPools = candidatePools.length > 0 ? candidatePools : rawPools; - if (targetPools.length === 0) return null; - - let sumUsd = 0; - let sumTokens = 0; - let readyPoolCount = 0; - let tokenReadyPoolCount = 0; - let hasPreliminary = false; - - for (const p of targetPools) { - const est = p?.rateEstimate && typeof p.rateEstimate === 'object' ? p.rateEstimate : null; - let eqUsd = - Number.isFinite(est?.eqFullWeeklyUsd) && est.eqFullWeeklyUsd > 0 - ? Number(est.eqFullWeeklyUsd) - : null; - let eqTok = - Number.isFinite(est?.eqFullWeeklyTokens) && est.eqFullWeeklyTokens > 0 - ? Math.round(Number(est.eqFullWeeklyTokens)) - : null; - if (eqUsd === null && Array.isArray(est?.models) && est.models.length > 0) { - const wkModels = est.models.filter( - (m) => Number.isFinite(m?.eqFullWeeklyUsd) && m.eqFullWeeklyUsd > 0 - ); - if (wkModels.length > 0) { - eqUsd = - wkModels.reduce((acc, m) => acc + Number(m.eqFullWeeklyUsd), 0) / wkModels.length; - const tokModels = wkModels.filter( - (m) => Number.isFinite(m?.eqFullWeeklyTokens) && m.eqFullWeeklyTokens > 0 - ); - if (tokModels.length === wkModels.length) { - eqTok = Math.round( - tokModels.reduce((acc, m) => acc + Number(m.eqFullWeeklyTokens), 0) / tokModels.length - ); - } - } - } - if (eqUsd !== null) { - readyPoolCount += 1; - sumUsd += eqUsd; - if (est?.isPreliminaryWeekly) hasPreliminary = true; - if (eqTok !== null) { - tokenReadyPoolCount += 1; - sumTokens += eqTok; - } - } - } - - if (readyPoolCount === 0) return null; - const totalPoolCount = targetPools.length; - return { - status: readyPoolCount < totalPoolCount ? 'partial' : 'ready', - totalEqWeeklyUsd: +sumUsd.toFixed(1), - totalEqWeeklyTokens: tokenReadyPoolCount === readyPoolCount ? Math.round(sumTokens) : null, - readyPoolCount, - totalPoolCount, - hasPreliminary, - }; -} - function formatRatePerUsdValue(rate) { const num = Number(rate); if (!Number.isFinite(num) || num <= 0) return '--'; @@ -630,13 +548,11 @@ function createRateModelCard({ function buildRatePopoverSig(data) { const locale = getEffectiveLocale(); const acct = String(data?.account?.email || data?.account?.name || '').trim(); - const isOfficial = data?.quotas?.weekly?.isOfficial !== false; - const wkCapSig = JSON.stringify(data?.quotas?.weeklyCapacityEstimate || null); const pools = Array.isArray(data?.quotas?.pools) ? data.quotas.pools : []; const poolSig = pools .map((p) => `${p.poolKey || ''}:${p.poolLabel || ''}:${JSON.stringify(p.rateEstimate || null)}`) .join('|'); - return `${locale}|${acct}|${isOfficial}|${wkCapSig}|${poolSig}`; + return `${locale}|${acct}|${poolSig}`; } export const QuotaPoolsWidget = defineComponent({ @@ -654,32 +570,7 @@ export const QuotaPoolsWidget = defineComponent({ className: 'quota-rate-pop-account', text: t('quota.ratePopAccountCurrent'), }); - const ratePopWkLabelEl = h('span', { text: t('quota.ratePopWkCapTitle') }); - const ratePopWkSubEl = h('span', { - className: 'quota-rate-wk-sub', - hidden: true, - text: '', - }); - const ratePopWkUsdEl = h('span', { className: 'quota-rate-wk-usd text-mono', text: '--' }); - const ratePopWkTokEl = h('span', { - className: 'quota-rate-wk-tok text-mono', - hidden: true, - text: '', - }); - const ratePopWkSummaryEl = h( - 'div', - { className: 'quota-rate-wk-summary', hidden: true }, - [ - h('span', { className: 'quota-rate-wk-k' }, [ratePopWkLabelEl, ratePopWkSubEl]), - h('span', { className: 'quota-rate-wk-v' }, [ratePopWkUsdEl, ratePopWkTokEl]), - ] - ); - ratePopWkSummaryEl.hidden = true; const ratePopBodyEl = h('div', { className: 'quota-rate-pop-body' }); - const ratePopNoteEl = h('div', { - className: 'quota-rate-pop-note', - text: t('quota.ratePopNote'), - }); const ratePopoverEl = h( 'div', { @@ -689,9 +580,7 @@ export const QuotaPoolsWidget = defineComponent({ }, [ h('div', { className: 'quota-rate-pop-head' }, [ratePopTitleEl, ratePopAccountEl]), - ratePopWkSummaryEl, ratePopBodyEl, - ratePopNoteEl, ] ); ratePopoverEl.hidden = true; @@ -769,7 +658,6 @@ export const QuotaPoolsWidget = defineComponent({ lastRatePopSig = sig; patchText(ratePopTitleEl, t('quota.ratePopTitle')); - patchText(ratePopNoteEl, t('quota.ratePopNote')); patchAttr(rateHelpBtn, 'aria-label', t('quota.rateHelpAria')); const acctMasked = maskAccountLabel(data?.account?.email || data?.account?.name || ''); @@ -781,38 +669,6 @@ export const QuotaPoolsWidget = defineComponent({ ); patchAttr(ratePopAccountEl, 'title', acctMasked || null); - const wkCap = resolveWeeklyCapacitySummary(data?.quotas); - if (wkCap) { - ratePopWkSummaryEl.hidden = false; - patchAttr(ratePopWkSummaryEl, 'hidden', false); - patchText(ratePopWkLabelEl, t('quota.ratePopWkCapTitle')); - const wkSubText = - wkCap.status === 'partial' && Number(wkCap.totalPoolCount) > 0 - ? t('quota.ratePopWkCapPartial', { - ready: Number(wkCap.readyPoolCount) || 0, - total: Number(wkCap.totalPoolCount) || 0, - }) - : wkCap.hasPreliminary - ? t('quota.ratePopWkCapPrelim') - : ''; - ratePopWkSubEl.hidden = !wkSubText; - patchAttr(ratePopWkSubEl, 'hidden', !wkSubText); - patchText(ratePopWkSubEl, wkSubText); - patchText(ratePopWkUsdEl, `≈ ${formatRateEqUsd(wkCap.totalEqWeeklyUsd)}`); - const hasWkTok = - Number.isFinite(Number(wkCap.totalEqWeeklyTokens)) && - Number(wkCap.totalEqWeeklyTokens) > 0; - ratePopWkTokEl.hidden = !hasWkTok; - patchAttr(ratePopWkTokEl, 'hidden', !hasWkTok); - patchText( - ratePopWkTokEl, - hasWkTok ? `· ${formatTokens(Number(wkCap.totalEqWeeklyTokens))}` : '' - ); - } else { - ratePopWkSummaryEl.hidden = true; - patchAttr(ratePopWkSummaryEl, 'hidden', true); - } - while (ratePopBodyEl.firstChild) { ratePopBodyEl.removeChild(ratePopBodyEl.firstChild); } diff --git a/sidecars/panel/src/i18n/en-US.js b/sidecars/panel/src/i18n/en-US.js index 91eb943..faebf89 100644 --- a/sidecars/panel/src/i18n/en-US.js +++ b/sidecars/panel/src/i18n/en-US.js @@ -204,9 +204,6 @@ export const I18N_MESSAGES_EN_US = Object.freeze({ 'quota.ratePopTitle': 'Estimated Burn Rates', 'quota.ratePopAccountScope': '{account}', 'quota.ratePopAccountCurrent': 'Current account', - 'quota.ratePopWkCapTitle': 'Est. Weekly Quota', - 'quota.ratePopWkCapPrelim': '· est.', - 'quota.ratePopWkCapPartial': '· {ready}/{total} pools', 'quota.ratePopPoolFallback': 'Pool average', 'quota.ratePopEq5hLabel': '5h full', 'quota.ratePopEqWkLabel': 'Weekly full', @@ -215,7 +212,6 @@ export const I18N_MESSAGES_EN_US = Object.freeze({ 'quota.ratePopPrelimSlope': 'slope est.', 'quota.ratePopPrelimCycle': 'cycle est.', 'quota.ratePopEmpty': 'Not enough clean samples yet (unlocks at 2% weekly burn or 3 clean single-model steps).', - 'quota.ratePopNote': 'Measured from net burn & priced steps; lowest in pool = 1x. Account isolated.', 'quota.ratePopSharedBadge': 'Shared active', 'quota.ratePopSharedBadgeTip': 'External pool usage seen within 15 min; new reservations display after verification', 'quota.ratePopExternalDetail': 'Family group / other-device usage detected (~{detail} excluded from reservations)', diff --git a/sidecars/panel/src/i18n/zh-CN.js b/sidecars/panel/src/i18n/zh-CN.js index f6632e6..845f698 100644 --- a/sidecars/panel/src/i18n/zh-CN.js +++ b/sidecars/panel/src/i18n/zh-CN.js @@ -204,9 +204,6 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({ 'quota.ratePopTitle': '实测倍率预估', 'quota.ratePopAccountScope': '{account}', 'quota.ratePopAccountCurrent': '当前账号', - 'quota.ratePopWkCapTitle': '预测周额度', - 'quota.ratePopWkCapPrelim': '· 初估', - 'quota.ratePopWkCapPartial': '· {ready}/{total} 池', 'quota.ratePopPoolFallback': '池综合均值', 'quota.ratePopEq5hLabel': '5h 满池', 'quota.ratePopEqWkLabel': '周限满池', @@ -215,7 +212,6 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({ 'quota.ratePopPrelimSlope': '斜率初估', 'quota.ratePopPrelimCycle': '周期初估', 'quota.ratePopEmpty': '暂未采集到足够的单模型干净样本(周限满 2% 或单模型满 3 次无抖动扣费后自动生成)。', - 'quota.ratePopNote': '按净消耗及精确计价折算,同池最省为 1x,按账号隔离。', 'quota.ratePopSharedBadge': '共享活跃', 'quota.ratePopSharedBadgeTip': '最近 15 分钟内检测到同池外部消耗,新增预占将在二次验证后展示', 'quota.ratePopExternalDetail': '检测到家庭组 / 其他设备消耗(已排除约 {detail}),不计入预占', diff --git a/sidecars/panel/src/styles/modern-ui.css b/sidecars/panel/src/styles/modern-ui.css index 2aa2d83..ace339a 100644 --- a/sidecars/panel/src/styles/modern-ui.css +++ b/sidecars/panel/src/styles/modern-ui.css @@ -840,20 +840,17 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell { } [data-modern-ui="true"] .step-anomaly-tip-list, -[data-modern-ui="true"] .step-anomaly-tip-hint, -[data-modern-ui="true"] .quota-rate-pop-head, -[data-modern-ui="true"] .quota-rate-wk-summary, -[data-modern-ui="true"] .quota-rate-pool-group + .quota-rate-pool-group, -[data-modern-ui="true"] .quota-rate-model-row + .quota-rate-model-row, -[data-modern-ui="true"] .quota-rate-pop-note, -:host([data-modern-ui="true"]) .quota-rate-pop-head, -:host([data-modern-ui="true"]) .quota-rate-wk-summary, -:host([data-modern-ui="true"]) .quota-rate-pool-group + .quota-rate-pool-group, -:host([data-modern-ui="true"]) .quota-rate-model-row + .quota-rate-model-row, -:host([data-modern-ui="true"]) .quota-rate-pop-note { +[data-modern-ui="true"] .step-anomaly-tip-hint { border-color: var(--modern-surface-hover); } +[data-modern-ui="true"] .quota-rate-shared-badge, +[data-modern-ui="true"] .quota-rate-ext-banner, +:host([data-modern-ui="true"]) .quota-rate-shared-badge, +:host([data-modern-ui="true"]) .quota-rate-ext-banner { + border: none; +} + [data-modern-ui="true"] .trend-tooltip:not(.is-hm-top):not(.is-hm-bottom):not(.is-rich-breakdown) { top: 2px; bottom: auto; diff --git a/sidecars/panel/src/styles/views-consumption.css b/sidecars/panel/src/styles/views-consumption.css index 899a5f8..762d784 100644 --- a/sidecars/panel/src/styles/views-consumption.css +++ b/sidecars/panel/src/styles/views-consumption.css @@ -406,36 +406,7 @@ } .trend-peak-pill.is-ready { - transition: - left 240ms cubic-bezier(0.22, 1, 0.36, 1), - opacity 180ms cubic-bezier(0.22, 1, 0.36, 1); -} - -@keyframes anim-cons-axis-fade { - from { - opacity: 0.3; - } - to { - opacity: 1; - } -} - -@keyframes anim-cons-stage-in { - from { - opacity: 0; - } - to { - opacity: 1; - } -} - -@keyframes anim-cons-content-switch { - from { - opacity: 0.52; - } - to { - opacity: 1; - } + transition: left 240ms cubic-bezier(0.22, 1, 0.36, 1); } @keyframes anim-cons-bar-grow { @@ -447,25 +418,6 @@ } } -.trend-x-axis.is-switching, -.trend-v-grid.is-switching { - animation: anim-cons-axis-fade 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.trend-plot-stage.is-stage-entering, -.trend-heatmap-stage.is-stage-entering, -.cons-item-list.is-tab-entering, -.cons-ranking-empty.is-tab-entering { - animation: anim-cons-stage-in 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.cons-unified-matrix.is-range-switching, -.cons-item-list.is-range-switching, -.cons-ranking-empty.is-range-switching { - animation: anim-cons-content-switch 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.cons-item-list.is-tab-entering .progress-track, .cons-item-list.is-bars-revealing .progress-track { transform-origin: left center; animation: anim-cons-bar-grow 240ms cubic-bezier(0.22, 1, 0.36, 1) both; @@ -478,15 +430,6 @@ .trend-hm-cell { transition: none !important; } - .trend-x-axis.is-switching, - .trend-v-grid.is-switching, - .trend-plot-stage.is-stage-entering, - .trend-heatmap-stage.is-stage-entering, - .cons-item-list.is-tab-entering, - .cons-ranking-empty.is-tab-entering, - .cons-unified-matrix.is-range-switching, - .cons-item-list.is-range-switching, - .cons-ranking-empty.is-range-switching, .cons-item-list.is-bars-revealing .progress-track { animation: none !important; } diff --git a/sidecars/panel/src/styles/views-overview.css b/sidecars/panel/src/styles/views-overview.css index 32c9de0..7fddd57 100644 --- a/sidecars/panel/src/styles/views-overview.css +++ b/sidecars/panel/src/styles/views-overview.css @@ -699,8 +699,6 @@ justify-content: space-between; gap: 10px; min-width: 0; - padding-bottom: 6px; - border-bottom: 1px solid var(--border-hairline); } .quota-rate-pop-title { @@ -721,65 +719,10 @@ min-width: 0; } -.quota-rate-wk-summary { - display: flex; - align-items: baseline; - justify-content: space-between; - gap: 8px; - min-width: 0; - padding-bottom: 7px; - border-bottom: 1px solid var(--border-hairline); -} - -.quota-rate-wk-summary[hidden] { - display: none; -} - -.quota-rate-wk-k { - display: inline-flex; - align-items: baseline; - gap: 5px; - min-width: 0; - font-size: var(--fs-sm); - font-weight: 500; - color: var(--text-secondary); - white-space: nowrap; -} - -.quota-rate-wk-sub { - font-family: var(--font-mono); - font-variant-numeric: tabular-nums; - font-size: var(--fs-2xs); - font-weight: 400; - color: var(--text-muted); -} - -.quota-rate-wk-v { - display: inline-flex; - align-items: baseline; - gap: 4px; - font-family: var(--font-mono); - font-variant-numeric: tabular-nums; - white-space: nowrap; - flex-shrink: 0; -} - -.quota-rate-wk-usd { - font-size: var(--fs-md); - font-weight: 600; - color: var(--text-primary); -} - -.quota-rate-wk-tok { - font-size: var(--fs-xs); - font-weight: 400; - color: var(--text-muted); -} - .quota-rate-pop-body { display: flex; flex-direction: column; - gap: 8px; + gap: 10px; max-height: min(300px, 58vh); overflow-x: hidden; overflow-y: auto; @@ -792,11 +735,6 @@ gap: 5px; } -.quota-rate-pool-group + .quota-rate-pool-group { - padding-top: 7px; - border-top: 1px solid var(--border-hairline); -} - .quota-rate-pool-head { display: flex; align-items: center; @@ -845,7 +783,7 @@ .quota-rate-model-list { display: flex; flex-direction: column; - gap: 7px; + gap: 8px; } .quota-rate-model-row { @@ -855,11 +793,6 @@ min-width: 0; } -.quota-rate-model-row + .quota-rate-model-row { - padding-top: 7px; - border-top: 1px solid var(--border-hairline); -} - .quota-rate-row-top { display: flex; align-items: baseline; @@ -960,14 +893,6 @@ color: var(--text-secondary); } -.quota-rate-pop-note { - padding-top: 6px; - border-top: 1px solid var(--border-hairline); - font-size: var(--fs-2xs); - line-height: 1.45; - color: var(--text-muted); -} - /* --- 4. 上下文双列图例网格 (Context 10-Channel Legend Grid) --- */ .ctx-legend-grid { display: grid; diff --git a/sidecars/panel/src/views/ConsumptionView.js b/sidecars/panel/src/views/ConsumptionView.js index fa87a5c..50384bb 100644 --- a/sidecars/panel/src/views/ConsumptionView.js +++ b/sidecars/panel/src/views/ConsumptionView.js @@ -406,11 +406,7 @@ export const ConsumptionView = defineComponent({ let lastAnimatedRankingKey = ''; let lastAnimatedSortSig = ''; const consAnimTimers = new Map(); - const TRANSIENT_CONS_CLASSES = [ - 'is-range-switching', - 'is-tab-entering', - 'is-bars-revealing', - ]; + const TRANSIENT_CONS_CLASSES = ['is-bars-revealing']; function cleanupConsAnim(el) { const rec = consAnimTimers.get(el); @@ -2228,13 +2224,7 @@ export const ConsumptionView = defineComponent({ !tabSwitched && nextSortSig !== lastAnimatedSortSig; - if (rangeSwitched) { - triggerConsAnim(unifiedMatrixEl, 'is-range-switching'); - triggerConsAnim(activeRankingEl, 'is-range-switching'); - triggerConsAnim(sourcesListEl, 'is-range-switching'); - } else if (tabSwitched) { - triggerConsAnim(activeRankingEl, 'is-tab-entering'); - } else if (sortSwitched) { + if (tabSwitched || sortSwitched) { triggerConsAnim(activeRankingEl, 'is-bars-revealing'); } if (!hasCompletedInitialDraw) { diff --git a/sidecars/panel/styles.css b/sidecars/panel/styles.css index 235a641..4eac4b1 100644 --- a/sidecars/panel/styles.css +++ b/sidecars/panel/styles.css @@ -2417,8 +2417,6 @@ html[data-standalone="true"] .app-shell { justify-content: space-between; gap: 10px; min-width: 0; - padding-bottom: 6px; - border-bottom: 1px solid var(--border-hairline); } .quota-rate-pop-title { @@ -2439,65 +2437,10 @@ html[data-standalone="true"] .app-shell { min-width: 0; } -.quota-rate-wk-summary { - display: flex; - align-items: baseline; - justify-content: space-between; - gap: 8px; - min-width: 0; - padding-bottom: 7px; - border-bottom: 1px solid var(--border-hairline); -} - -.quota-rate-wk-summary[hidden] { - display: none; -} - -.quota-rate-wk-k { - display: inline-flex; - align-items: baseline; - gap: 5px; - min-width: 0; - font-size: var(--fs-sm); - font-weight: 500; - color: var(--text-secondary); - white-space: nowrap; -} - -.quota-rate-wk-sub { - font-family: var(--font-mono); - font-variant-numeric: tabular-nums; - font-size: var(--fs-2xs); - font-weight: 400; - color: var(--text-muted); -} - -.quota-rate-wk-v { - display: inline-flex; - align-items: baseline; - gap: 4px; - font-family: var(--font-mono); - font-variant-numeric: tabular-nums; - white-space: nowrap; - flex-shrink: 0; -} - -.quota-rate-wk-usd { - font-size: var(--fs-md); - font-weight: 600; - color: var(--text-primary); -} - -.quota-rate-wk-tok { - font-size: var(--fs-xs); - font-weight: 400; - color: var(--text-muted); -} - .quota-rate-pop-body { display: flex; flex-direction: column; - gap: 8px; + gap: 10px; max-height: min(300px, 58vh); overflow-x: hidden; overflow-y: auto; @@ -2510,11 +2453,6 @@ html[data-standalone="true"] .app-shell { gap: 5px; } -.quota-rate-pool-group + .quota-rate-pool-group { - padding-top: 7px; - border-top: 1px solid var(--border-hairline); -} - .quota-rate-pool-head { display: flex; align-items: center; @@ -2563,7 +2501,7 @@ html[data-standalone="true"] .app-shell { .quota-rate-model-list { display: flex; flex-direction: column; - gap: 7px; + gap: 8px; } .quota-rate-model-row { @@ -2573,11 +2511,6 @@ html[data-standalone="true"] .app-shell { min-width: 0; } -.quota-rate-model-row + .quota-rate-model-row { - padding-top: 7px; - border-top: 1px solid var(--border-hairline); -} - .quota-rate-row-top { display: flex; align-items: baseline; @@ -2678,14 +2611,6 @@ html[data-standalone="true"] .app-shell { color: var(--text-secondary); } -.quota-rate-pop-note { - padding-top: 6px; - border-top: 1px solid var(--border-hairline); - font-size: var(--fs-2xs); - line-height: 1.45; - color: var(--text-muted); -} - /* --- 4. 上下文双列图例网格 (Context 10-Channel Legend Grid) --- */ .ctx-legend-grid { display: grid; @@ -3280,36 +3205,7 @@ html[data-standalone="true"] .app-shell { } .trend-peak-pill.is-ready { - transition: - left 240ms cubic-bezier(0.22, 1, 0.36, 1), - opacity 180ms cubic-bezier(0.22, 1, 0.36, 1); -} - -@keyframes anim-cons-axis-fade { - from { - opacity: 0.3; - } - to { - opacity: 1; - } -} - -@keyframes anim-cons-stage-in { - from { - opacity: 0; - } - to { - opacity: 1; - } -} - -@keyframes anim-cons-content-switch { - from { - opacity: 0.52; - } - to { - opacity: 1; - } + transition: left 240ms cubic-bezier(0.22, 1, 0.36, 1); } @keyframes anim-cons-bar-grow { @@ -3321,25 +3217,6 @@ html[data-standalone="true"] .app-shell { } } -.trend-x-axis.is-switching, -.trend-v-grid.is-switching { - animation: anim-cons-axis-fade 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.trend-plot-stage.is-stage-entering, -.trend-heatmap-stage.is-stage-entering, -.cons-item-list.is-tab-entering, -.cons-ranking-empty.is-tab-entering { - animation: anim-cons-stage-in 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.cons-unified-matrix.is-range-switching, -.cons-item-list.is-range-switching, -.cons-ranking-empty.is-range-switching { - animation: anim-cons-content-switch 220ms cubic-bezier(0.22, 1, 0.36, 1) both; -} - -.cons-item-list.is-tab-entering .progress-track, .cons-item-list.is-bars-revealing .progress-track { transform-origin: left center; animation: anim-cons-bar-grow 240ms cubic-bezier(0.22, 1, 0.36, 1) both; @@ -3352,15 +3229,6 @@ html[data-standalone="true"] .app-shell { .trend-hm-cell { transition: none !important; } - .trend-x-axis.is-switching, - .trend-v-grid.is-switching, - .trend-plot-stage.is-stage-entering, - .trend-heatmap-stage.is-stage-entering, - .cons-item-list.is-tab-entering, - .cons-ranking-empty.is-tab-entering, - .cons-unified-matrix.is-range-switching, - .cons-item-list.is-range-switching, - .cons-ranking-empty.is-range-switching, .cons-item-list.is-bars-revealing .progress-track { animation: none !important; } @@ -8860,20 +8728,17 @@ html[data-standalone="true"][data-modern-ui="true"] .app-shell { } [data-modern-ui="true"] .step-anomaly-tip-list, -[data-modern-ui="true"] .step-anomaly-tip-hint, -[data-modern-ui="true"] .quota-rate-pop-head, -[data-modern-ui="true"] .quota-rate-wk-summary, -[data-modern-ui="true"] .quota-rate-pool-group + .quota-rate-pool-group, -[data-modern-ui="true"] .quota-rate-model-row + .quota-rate-model-row, -[data-modern-ui="true"] .quota-rate-pop-note, -:host([data-modern-ui="true"]) .quota-rate-pop-head, -:host([data-modern-ui="true"]) .quota-rate-wk-summary, -:host([data-modern-ui="true"]) .quota-rate-pool-group + .quota-rate-pool-group, -:host([data-modern-ui="true"]) .quota-rate-model-row + .quota-rate-model-row, -:host([data-modern-ui="true"]) .quota-rate-pop-note { +[data-modern-ui="true"] .step-anomaly-tip-hint { border-color: var(--modern-surface-hover); } +[data-modern-ui="true"] .quota-rate-shared-badge, +[data-modern-ui="true"] .quota-rate-ext-banner, +:host([data-modern-ui="true"]) .quota-rate-shared-badge, +:host([data-modern-ui="true"]) .quota-rate-ext-banner { + border: none; +} + [data-modern-ui="true"] .trend-tooltip:not(.is-hm-top):not(.is-hm-bottom):not(.is-rich-breakdown) { top: 2px; bottom: auto; diff --git a/sidecars/panel/test/cross-module-regressions.test.mjs b/sidecars/panel/test/cross-module-regressions.test.mjs index 87ed9ec..0701578 100644 --- a/sidecars/panel/test/cross-module-regressions.test.mjs +++ b/sidecars/panel/test/cross-module-regressions.test.mjs @@ -1673,3 +1673,204 @@ test('xlsxBuilder enforces 32,767 UTF-16 cell limit without splitting surrogate const cellA3 = cellMatches[1][1]; assert.equal(cellA3, 'ok\uFFFDmid\uFFFDend'); }); + +test('ConsumptionView and TrendAreaChart patch text DOM nodes in-place without opacity flicker classes on date range switches', async () => { + const consCss = fs.readFileSync( + fileURLToPath(new URL('../src/styles/views-consumption.css', import.meta.url)), + 'utf8' + ); + for (const bannedToken of [ + 'is-range-switching', + 'is-tab-entering', + 'is-switching', + 'is-stage-entering', + 'anim-cons-content-switch', + 'anim-cons-axis-fade', + 'anim-cons-stage-in', + ]) { + assert.equal( + consCss.includes(bannedToken), + false, + `Expected views-consumption.css not to contain text-opacity flicker rule "${bannedToken}"` + ); + } + + const { createMockDom } = await import('./mock-dom.mjs'); + const prevDoc = globalThis.document; + const prevWin = globalThis.window; + const { document } = createMockDom(); + globalThis.document = document; + globalThis.window = { + location: { origin: 'http://127.0.0.1:41234', href: 'http://127.0.0.1:41234/' }, + getComputedStyle: () => ({ overflow: 'visible', overflowX: 'visible', overflowY: 'visible' }), + matchMedia: () => ({ matches: false }), + requestAnimationFrame: (cb) => setTimeout(() => cb(performance.now()), 0), + cancelAnimationFrame: (id) => clearTimeout(id), + addEventListener() {}, + removeEventListener() {}, + }; + + try { + const { ConsumptionView } = await import('../src/views/ConsumptionView.js'); + const { telemetryStore } = await import('../src/store/telemetryStore.js'); + const { uiStore } = await import('../src/store/uiStore.js'); + const prevTelState = { ...telemetryStore.getState() }; + const prevUiState = { ...uiStore.getState() }; + + uiStore.setState( + { activeView: 'consumption', monitorVisible: true, settingsOpen: false }, + { sync: true } + ); + const view = ConsumptionView(); + document.body.appendChild(view.el); + + const makeRangePayload = (rangeKey, tokBase, labels) => ({ + settings: { modelDisplayMode: 'short', showUpstreamModel: false, orchestratorIdMode: 'label' }, + consumption: { + revision: 0, + selectedRange: { + key: rangeKey, + label: rangeKey, + startMs: 1_760_000_000_000, + endMs: 1_760_086_400_000, + }, + account: { + totalTokens: tokBase, + inputTokens: Math.round(tokBase * 0.2), + cacheReadTokens: Math.round(tokBase * 0.7), + outputTokens: Math.round(tokBase * 0.1), + responseTokens: Math.round(tokBase * 0.07), + thinkingTokens: Math.round(tokBase * 0.03), + calls: 12, + costUsd: 1.25, + savedCostUsd: 0.85, + cacheHitPct: 77.8, + }, + trendSeries: labels.map((lbl, idx) => ({ + index: idx, + startMs: 1_760_000_000_000 + idx * 3_600_000, + endMs: 1_760_000_000_000 + (idx + 1) * 3_600_000, + granularity: labels.length > 90 ? 'day' : 'hour', + label: lbl, + fullLabel: lbl, + tokens: 1_000 * (idx + 1), + calls: 1, + costUsd: 0.05, + })), + sourcesBreakdown: [ + { + name: 'antigravity', + label: 'Antigravity IDE', + totalTokens: tokBase, + calls: 12, + costUsd: 1.25, + models: [{ label: 'Claude Opus 4.6', shortName: 'Claude Opus 4.6', totalTokens: tokBase, calls: 12 }], + }, + ], + topConversations: [], + topWorkspaces: [], + monthlyYear: 2026, + monthlySeries: Array.from({ length: 12 }, (_, m) => ({ + month: m + 1, + totalTokens: m === 10 ? tokBase : 0, + costUsd: m === 10 ? 1.25 : 0, + calls: m === 10 ? 12 : 0, + })), + }, + modelBreakdown: [ + { + label: 'Claude Opus 4.6', + shortName: 'Claude Opus 4.6', + totalTokens: tokBase, + inputTokens: Math.round(tokBase * 0.2), + cacheReadTokens: Math.round(tokBase * 0.7), + responseTokens: Math.round(tokBase * 0.07), + thinkingTokens: Math.round(tokBase * 0.03), + outputTokens: Math.round(tokBase * 0.1), + calls: 12, + costUsd: 1.25, + }, + ], + }); + + telemetryStore.setState( + { + selectedTimeRange: 'today', + telemetry: makeRangePayload('today', 100_000, ['00:00', '06:00', '12:00', '18:00']), + }, + { sync: true } + ); + + const matrixEl = view.el.querySelector('.cons-unified-matrix'); + const heroNumEl = view.el.querySelector('.cons-hero-num'); + const modelRowEl = view.el.querySelector('.cons-item-row'); + const modelTitleTextEl = modelRowEl.querySelector('.cons-row-title-text'); + const sourceRowEl = view.el.querySelector('.cons-source-row'); + const xAxisEl = view.el.querySelector('.trend-x-axis'); + const initialTicks = xAxisEl.querySelectorAll('.trend-x-tick'); + assert.equal(initialTicks.length, 4); + + // Switch to 7d: same model, same source, updated numbers & tick labels -> all DOM nodes reused in-place, zero opacity flicker classes + telemetryStore.setState( + { + selectedTimeRange: '7d', + telemetry: makeRangePayload('7d', 450_000, ['11/18', '11/20', '11/22', '11/24']), + }, + { sync: true } + ); + + assert.equal(view.el.querySelector('.cons-hero-num'), heroNumEl, 'Hero token element persists'); + assert.equal(view.el.querySelector('.cons-item-row'), modelRowEl, 'Model row element persists'); + assert.equal( + view.el.querySelector('.cons-item-row .cons-row-title-text'), + modelTitleTextEl, + 'Model title text node persists' + ); + assert.equal(view.el.querySelector('.cons-source-row'), sourceRowEl, 'Source row element persists'); + + const nextTicks = xAxisEl.querySelectorAll('.trend-x-tick'); + assert.equal(nextTicks.length, 4); + for (let i = 0; i < 4; i++) { + assert.equal(nextTicks[i], initialTicks[i], `Trend X-axis tick #${i} reused in-place`); + } + assert.equal(nextTicks[0].textContent, '11/18'); + + for (const cls of ['is-range-switching', 'is-tab-entering', 'is-switching', 'is-stage-entering']) { + assert.equal(matrixEl.classList.contains(cls), false); + assert.equal(modelRowEl.parentNode.classList.contains(cls), false); + assert.equal(sourceRowEl.parentNode.classList.contains(cls), false); + assert.equal(xAxisEl.classList.contains(cls), false); + } + + // Switch to >90d heatmap and update counts -> month labels and grid cells reuse pooled nodes in-place + const hmLabelsA = Array.from({ length: 95 }, (_, idx) => `08/${String((idx % 28) + 1).padStart(2, '0')}`); + telemetryStore.setState( + { + selectedTimeRange: 'all', + telemetry: makeRangePayload('all', 900_000, hmLabelsA), + }, + { sync: true } + ); + const hmGridEl = view.el.querySelector('.trend-hm-grid'); + const firstGridCells = [...hmGridEl.children]; + assert.ok(firstGridCells.length >= 95); + + telemetryStore.setState( + { + selectedTimeRange: 'all', + telemetry: makeRangePayload('all', 950_000, hmLabelsA), + }, + { sync: true } + ); + const secondGridCells = [...hmGridEl.children]; + assert.equal(secondGridCells.length, firstGridCells.length); + assert.equal(secondGridCells[10], firstGridCells[10], 'Heatmap cell DOM node reused in-place'); + + view.destroy(); + telemetryStore.setState(prevTelState, { sync: true }); + uiStore.setState(prevUiState, { sync: true }); + } finally { + globalThis.document = prevDoc; + globalThis.window = prevWin; + } +}); diff --git a/sidecars/panel/test/quota-reservation.test.mjs b/sidecars/panel/test/quota-reservation.test.mjs index 79f6bf6..3988e98 100644 --- a/sidecars/panel/test/quota-reservation.test.mjs +++ b/sidecars/panel/test/quota-reservation.test.mjs @@ -2208,7 +2208,7 @@ test('quota-reservation: 3-tier hybrid estimator unlocks cycle_ratio & anchor_sl assert.equal(pAfterRestart.get('Claude & GPT').rateEstimate?.eqFullWeeklyTokens, 12_500_000); }); -test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, preliminary labels, and full-pool token references', async () => { +test('QuotaPoolsWidget ? popover renders preliminary labels and full-pool token references without weekly summary row, footer note, or divider rules', async () => { const { document } = createMockDom(); const origDocument = globalThis.document; const origWindow = globalThis.window; @@ -2231,8 +2231,9 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin const widget = QuotaPoolsWidget(); const popover = widget.refs.ratePopoverEl; - // 1. Collecting state: top weekly summary hidden until at least 1 pool has a weekly capacity estimate - assert.equal(popover.querySelector('.quota-rate-wk-summary')?.hidden, true); + // 1. Minimalist layout: no redundant weekly summary row or footer note element + assert.equal(popover.querySelector('.quota-rate-wk-summary'), null); + assert.equal(popover.querySelector('.quota-rate-pop-note'), null); // 2. Partial + Preliminary state (Claude ready via anchor_slope, Gemini still collecting) widget.refs.update({ @@ -2280,9 +2281,8 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin minuteTick: 1, }); - const wkSummary = popover.querySelector('.quota-rate-wk-summary'); - assert.equal(wkSummary.hidden, false); - assert.match(wkSummary.textContent, /预测周额度.*· 1\/2 池.*≈ \$48.*· 9\.9M/); + assert.doesNotMatch(popover.textContent, /预测周额度/); + assert.doesNotMatch(popover.textContent, /同池最省/); const fallbackRow = popover.querySelector('.quota-rate-model-row.is-fallback'); assert.ok(fallbackRow); assert.match(fallbackRow.textContent, /池综合均值/); @@ -2292,7 +2292,7 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin const wkRowLeft = widget.refs.poolsListEl.querySelectorAll('.quota-win-left')[1]; assert.match(wkRowLeft.getAttribute('title') || '', /满池约 \$48 \(9\.9M\)/); - // 3. All pools calibrated & ready: sums USD + Tokens cleanly ($50 + $35 = $85, 10.3M + 14.2M = 24.5M) + // 3. All pools calibrated & ready: renders per-pool model & fallback cards cleanly const allReadyData = { account: { email: 'sjee80343@gmail.com', tierName: 'Google AI Pro' }, quotas: { @@ -2367,33 +2367,21 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin }, }; widget.refs.update({ data: allReadyData, minuteTick: 2 }); - assert.equal(wkSummary.hidden, false); - assert.equal(wkSummary.querySelector('.quota-rate-wk-sub').hidden, true); - assert.match(wkSummary.textContent, /预测周额度≈ \$85· 24\.5M/); + assert.match(popover.textContent, /Claude Sonnet 4\.6.*5h 满池≈ \$50· 10\.3M.*周限满池≈ \$50· 10\.3M/); + assert.match(popover.textContent, /Gemini.*池综合均值.*5h 满池≈ \$35· 14\.2M/); - // 4. English locale switch updates weekly summary, model cards, and row title tooltip without reload + // 4. English locale switch updates model cards and row title tooltip without reload setI18nLanguage('en-US'); widget.refs.update({ data: allReadyData, minuteTick: 3 }); - assert.match(wkSummary.textContent, /Est\. Weekly Quota≈ \$85· 24\.5M/); + assert.doesNotMatch(popover.textContent, /Est\. Weekly Quota/); + assert.doesNotMatch(popover.textContent, /lowest in pool/); + assert.match(popover.textContent, /5h full≈ \$50· 10\.3M.*Weekly full≈ \$50· 10\.3M/); assert.match( widget.refs.poolsListEl.querySelectorAll('.quota-win-left')[1].getAttribute('title') || '', /Full ~\$50 \(10\.3M\)/ ); - // 5. Custom local weekly budget mode hides official weekly capacity summary - widget.refs.update({ - data: { - ...allReadyData, - quotas: { - ...allReadyData.quotas, - weekly: { isOfficial: false }, - }, - }, - minuteTick: 4, - }); - assert.equal(wkSummary.hidden, true); - - // 6. Pool with 5h-only model card + pool-level preliminary weekly estimate renders supplementary weekly fallback row + // 5. Pool with 5h-only model card + pool-level preliminary weekly estimate renders supplementary weekly fallback row setI18nLanguage('zh-CN'); widget.refs.update({ data: { @@ -2443,8 +2431,6 @@ test('QuotaPoolsWidget ? popover renders Est. Weekly Quota summary row, prelimin }, minuteTick: 5, }); - assert.equal(wkSummary.hidden, false); - assert.match(wkSummary.textContent, /预测周额度.*· 初估.*≈ \$600.*· 200\.0M/); const mixedRows = popover.querySelectorAll('.quota-rate-model-row'); assert.equal(mixedRows.length, 2, 'renders 5h model card + supplementary pool weekly fallback row'); assert.match(mixedRows[0].textContent, /Gemini 3\.1 Pro.*5h 满池≈ \$150/);