dsh-ustc-quota 1.1.55 → 1.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,7 +112,7 @@ key-c 8.7/30 29% 8.7/70 12% 11.1/100 11%
112
112
  - 右侧位置会在对话区右侧**预留一条槽**:插件给对话列加右侧内边距(约列宽的 26%,封顶 34%),正文与轮次导航条整体左移,卡片占住这条槽——因此不遮挡正文、不遮挡轮次导航条、也不遮挡右侧原生按钮。上沿从「对话 / 轨迹 / 看板」选项卡下的分隔线以下 6px 开始。
113
113
  - 窄窗口或打开侧栏时槽宽自动收窄(下限 140px),卡片始终可见;如果连正文最小宽度都不够,则允许卡片比常规更窄,而不是消失。
114
114
  - 换边不重新加载:两处卡片共用同一份已取到的数据。底色用左侧边栏的底色(`--dsw-specific-sidebar-fill`),阴影与左侧一致。
115
- - 右侧卡片宽度上限 420px(避免空状态把卡片拉得过宽),并与其它插件的右侧卡片(如 Codex Advisor)自动上下排开;测量一时失败时退回固定位置显示,不会整块消失。
115
+ - 右侧卡片宽度上限 480px,每列数值按该列最宽内容自动定宽,多余空间给进度条;与其它插件的右侧卡片(如 Codex Advisor)自动上下排开;测量一时失败时退回固定位置显示,不会整块消失。
116
116
  ## 更新
117
117
 
118
118
  - 标题「USTC 词元额度」右侧显示灰色小字版本号;点击版本号可手动检查更新;
package/client.js CHANGED
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({
11
11
  const UPDATE_ENDPOINT = 'plugins/dsh-ustc-quota/update';
12
12
  const UPDATE_APPLY_ENDPOINT = 'plugins/dsh-ustc-quota/update/apply';
13
13
  const WINDOW_IDS = ['3h', '12h', '24h'];
14
- const CLIENT_VERSION = '1.1.55';
14
+ const CLIENT_VERSION = '1.1.57';
15
15
  const UPDATE_INTERVAL_MS = 24 * 60 * 60 * 1000;
16
16
  const CLIENT_VERSION_KEY = `${NS}:client-version`;
17
17
  const CLIENT_RELOAD_KEY = `${NS}:client-reload`;
@@ -622,9 +622,9 @@ window.__ModuleLoader__.load({
622
622
  valueWide: {
623
623
  flex: '0 0 auto',
624
624
  width: 'var(--ustc-value-w, 44px)',
625
- textAlign: 'left',
626
- padding: 0,
627
- margin: 0,
625
+ textAlign: 'right',
626
+ padding: '0 2px 0 0',
627
+ margin: '0 0 0 -2px',
628
628
  fontSize: 10,
629
629
  fontWeight: 650,
630
630
  color: 'var(--dsw-alias-label-primary)',
@@ -1278,11 +1278,20 @@ window.__ModuleLoader__.load({
1278
1278
  const floored = span < 240;
1279
1279
  let stackTop = contentTop;
1280
1280
  try {
1281
- // Other plugins place their own right docks with the same anchor; stack below
1282
- // any of them that already occupy this band so the cards never overlap.
1281
+ // Other plugins place their own right docks on the same anchor. Deferring to
1282
+ // every neighbour that overlaps this band makes two docks chase each other
1283
+ // downwards: each one steps below the other, forever. Break the symmetry —
1284
+ // yield only to a neighbour that starts strictly above this slot, or that
1285
+ // starts at the same top and sorts earlier by id. Exactly one dock then
1286
+ // yields per pair, so the arrangement settles after a single step.
1287
+ const MY_DOCK_ID = 'ustc-quota';
1283
1288
  for (const node of document.querySelectorAll('[data-codex-advisor-dock="right"]')) {
1284
1289
  const rect = node.getBoundingClientRect();
1285
1290
  if (rect.height <= 0 || rect.width <= 0) continue;
1291
+ const NEIGHBOUR_DOCK_ID = 'codex-advisor';
1292
+ const startsAbove = rect.top < contentTop - 1;
1293
+ const tiedAndEarlier = Math.abs(rect.top - contentTop) <= 1 && NEIGHBOUR_DOCK_ID < MY_DOCK_ID;
1294
+ if (!startsAbove && !tiedAndEarlier) continue;
1286
1295
  if (rect.bottom > stackTop && rect.top < columnRect.bottom) {
1287
1296
  stackTop = Math.max(stackTop, Math.round(rect.bottom) + DOCK_GAP);
1288
1297
  }
@@ -1839,12 +1848,14 @@ window.__ModuleLoader__.load({
1839
1848
  },
1840
1849
  })
1841
1850
  );
1842
- const valueNode = (style) => h('span', { style }, `${isStale ? '≈ ' : ''}${valueText}`);
1851
+ const valueNode = (style) => h('span', { style: style }, `${isStale ? '≈ ' : ''}${valueText}`);
1843
1852
  const percentNode = (style) => (percent ? h('span', { style: { ...style, color: percentColor } }, percent) : null);
1844
1853
 
1845
1854
  if (wideLayout) {
1855
+ const cellValueWidth = valueWidths.get(window.id);
1856
+ const valueStyle = cellValueWidth ? { ...STYLE.valueWide, width: `${cellValueWidth}px` } : STYLE.valueWide;
1846
1857
  return h('div', { style: STYLE.cellWide, title: titleParts.join(' · ') },
1847
- valueNode(STYLE.valueWide),
1858
+ valueNode(valueStyle),
1848
1859
  barNode(STYLE.inlineBar),
1849
1860
  percentNode(STYLE.percentWide)
1850
1861
  );
@@ -1921,28 +1932,36 @@ window.__ModuleLoader__.load({
1921
1932
  if (text.length > valueChars) valueChars = text.length;
1922
1933
  }
1923
1934
  }
1924
- // Width = exactly the widest value on screen, measured with the card's own font.
1925
- let valueWidthPx = null;
1935
+ // Width per window column: each column only needs to fit its own widest value,
1936
+ // so 3h/12h do not inherit the 24h column's wider numbers.
1937
+ const valueWidths = new Map();
1926
1938
  try {
1927
1939
  const rootNode = rootRef.current;
1928
- const canvas = document.createElement('canvas');
1929
- const ctx = canvas && canvas.getContext ? canvas.getContext('2d') : null;
1930
- if (ctx) {
1931
- const family = rootNode ? getComputedStyle(rootNode).fontFamily : 'system-ui';
1932
- ctx.font = '650 10px ' + family;
1933
- let widest = 0;
1934
- for (const key of keys) {
1935
- for (const window of (key.windows || [])) {
1940
+ if (rootNode && rootNode.isConnected) {
1941
+ const probe = document.createElement('span');
1942
+ probe.style.position = 'absolute';
1943
+ probe.style.visibility = 'hidden';
1944
+ probe.style.pointerEvents = 'none';
1945
+ probe.style.whiteSpace = 'nowrap';
1946
+ probe.style.fontSize = '10px';
1947
+ probe.style.fontWeight = '650';
1948
+ rootNode.appendChild(probe);
1949
+ for (const windowId of WINDOW_IDS) {
1950
+ let widest = 0;
1951
+ for (const key of keys) {
1952
+ const window = (key.windows || []).find((item) => item.id === windowId);
1953
+ if (!window) continue;
1936
1954
  const usedValue = typeof window.used === 'number' && Number.isFinite(window.used) ? window.used : null;
1937
1955
  const limitValue = typeof window.limit === 'number' && Number.isFinite(window.limit) ? window.limit : null;
1938
1956
  const text = usedValue === null
1939
1957
  ? '—'
1940
1958
  : `${formatNumber(usedValue)}/${limitValue === null ? '—' : formatNumber(limitValue)}`;
1941
- const rendered = window.state === 'stale' ? `≈ ${text}` : text;
1942
- widest = Math.max(widest, ctx.measureText(rendered).width);
1959
+ probe.textContent = window.state === 'stale' ? `≈ ${text}` : text;
1960
+ widest = Math.max(widest, probe.getBoundingClientRect().width);
1943
1961
  }
1962
+ if (widest > 0) valueWidths.set(windowId, Math.ceil(widest));
1944
1963
  }
1945
- if (widest > 0) valueWidthPx = Math.ceil(widest) + 1;
1964
+ rootNode.removeChild(probe);
1946
1965
  }
1947
1966
  } catch {
1948
1967
  // measurement is best-effort; the ch fallback below still aligns the columns
@@ -1954,7 +1973,7 @@ window.__ModuleLoader__.load({
1954
1973
  ...STYLE.table,
1955
1974
  '--ustc-key-col': `${keyColumnWidth}px`,
1956
1975
  '--ustc-gap': wideLayout ? '6px' : '4px',
1957
- '--ustc-value-w': valueWidthPx ? `${valueWidthPx}px` : `${Math.min(12, valueChars + 0.5)}ch`,
1976
+ '--ustc-value-w': `${Math.min(12, valueChars + 0.5)}ch`,
1958
1977
  };
1959
1978
  const versionTitle = updateInfo && updateInfo.updateAvailable
1960
1979
  ? `${t('updateAvailable')} v${updateInfo.latestVersion}`
package/index.js CHANGED
@@ -22,7 +22,7 @@ const ROUTE_PATH = '/plugins/dsh-ustc-quota/snapshot';
22
22
  const UPDATE_PATH = '/plugins/dsh-ustc-quota/update';
23
23
  const UPDATE_APPLY_PATH = '/plugins/dsh-ustc-quota/update/apply';
24
24
  const UPDATE_TOKEN_TTL_MS = 30 * 60 * 1000;
25
- const PLUGIN_VERSION = '1.1.55';
25
+ const PLUGIN_VERSION = '1.1.57';
26
26
  const KEY_INFO_PATH = 'key/info';
27
27
  const USER_INFO_PATH = 'user/info';
28
28
  const DISCOVERY_TTL_MS = 30000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ustc-quota",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Live 3h/12h/24h USTC token quota card in the DSH sidebar (works with the USTC TokenWorks distribution).",