dsh-ustc-quota 1.1.55 → 1.1.56

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.
Files changed (3) hide show
  1. package/client.js +30 -20
  2. package/index.js +1 -1
  3. package/package.json +1 -1
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.56';
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)',
@@ -1839,12 +1839,14 @@ window.__ModuleLoader__.load({
1839
1839
  },
1840
1840
  })
1841
1841
  );
1842
- const valueNode = (style) => h('span', { style }, `${isStale ? '≈ ' : ''}${valueText}`);
1842
+ const valueNode = (style) => h('span', { style: style }, `${isStale ? '≈ ' : ''}${valueText}`);
1843
1843
  const percentNode = (style) => (percent ? h('span', { style: { ...style, color: percentColor } }, percent) : null);
1844
1844
 
1845
1845
  if (wideLayout) {
1846
+ const cellValueWidth = valueWidths.get(window.id);
1847
+ const valueStyle = cellValueWidth ? { ...STYLE.valueWide, width: `${cellValueWidth}px` } : STYLE.valueWide;
1846
1848
  return h('div', { style: STYLE.cellWide, title: titleParts.join(' · ') },
1847
- valueNode(STYLE.valueWide),
1849
+ valueNode(valueStyle),
1848
1850
  barNode(STYLE.inlineBar),
1849
1851
  percentNode(STYLE.percentWide)
1850
1852
  );
@@ -1921,28 +1923,36 @@ window.__ModuleLoader__.load({
1921
1923
  if (text.length > valueChars) valueChars = text.length;
1922
1924
  }
1923
1925
  }
1924
- // Width = exactly the widest value on screen, measured with the card's own font.
1925
- let valueWidthPx = null;
1926
+ // Width per window column: each column only needs to fit its own widest value,
1927
+ // so 3h/12h do not inherit the 24h column's wider numbers.
1928
+ const valueWidths = new Map();
1926
1929
  try {
1927
1930
  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 || [])) {
1931
+ if (rootNode && rootNode.isConnected) {
1932
+ const probe = document.createElement('span');
1933
+ probe.style.position = 'absolute';
1934
+ probe.style.visibility = 'hidden';
1935
+ probe.style.pointerEvents = 'none';
1936
+ probe.style.whiteSpace = 'nowrap';
1937
+ probe.style.fontSize = '10px';
1938
+ probe.style.fontWeight = '650';
1939
+ rootNode.appendChild(probe);
1940
+ for (const windowId of WINDOW_IDS) {
1941
+ let widest = 0;
1942
+ for (const key of keys) {
1943
+ const window = (key.windows || []).find((item) => item.id === windowId);
1944
+ if (!window) continue;
1936
1945
  const usedValue = typeof window.used === 'number' && Number.isFinite(window.used) ? window.used : null;
1937
1946
  const limitValue = typeof window.limit === 'number' && Number.isFinite(window.limit) ? window.limit : null;
1938
1947
  const text = usedValue === null
1939
1948
  ? '—'
1940
1949
  : `${formatNumber(usedValue)}/${limitValue === null ? '—' : formatNumber(limitValue)}`;
1941
- const rendered = window.state === 'stale' ? `≈ ${text}` : text;
1942
- widest = Math.max(widest, ctx.measureText(rendered).width);
1950
+ probe.textContent = window.state === 'stale' ? `≈ ${text}` : text;
1951
+ widest = Math.max(widest, probe.getBoundingClientRect().width);
1943
1952
  }
1953
+ if (widest > 0) valueWidths.set(windowId, Math.ceil(widest));
1944
1954
  }
1945
- if (widest > 0) valueWidthPx = Math.ceil(widest) + 1;
1955
+ rootNode.removeChild(probe);
1946
1956
  }
1947
1957
  } catch {
1948
1958
  // measurement is best-effort; the ch fallback below still aligns the columns
@@ -1954,7 +1964,7 @@ window.__ModuleLoader__.load({
1954
1964
  ...STYLE.table,
1955
1965
  '--ustc-key-col': `${keyColumnWidth}px`,
1956
1966
  '--ustc-gap': wideLayout ? '6px' : '4px',
1957
- '--ustc-value-w': valueWidthPx ? `${valueWidthPx}px` : `${Math.min(12, valueChars + 0.5)}ch`,
1967
+ '--ustc-value-w': `${Math.min(12, valueChars + 0.5)}ch`,
1958
1968
  };
1959
1969
  const versionTitle = updateInfo && updateInfo.updateAvailable
1960
1970
  ? `${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.56';
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.56",
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).",