dsh-ustc-quota 1.1.39 → 1.1.46

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 (4) hide show
  1. package/README.md +1 -1
  2. package/client.js +114 -113
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -108,7 +108,7 @@ key-c 8.7/30 29% 8.7/70 12% 11.1/100 11%
108
108
  ## 面板位置
109
109
 
110
110
  - 卡片默认在左侧边栏底部。**鼠标移到卡片上时,标题左边的品牌图标会变成方向图标**(布局图示,标出卡片将要去的那一侧),点一下即可换边;移开鼠标图标复原。选择会记住,重启后保持。
111
- - 排版自适应:每个窗口一行显示「数值 · 进度条 · 百分比」,三段各自固定宽度对齐,跨行不参差;刷新时间并入「3h / 12h / 24h」表头行右侧。用宽度换高度,卡片更矮更紧凑。
111
+ - 排版自适应:**只在右侧并且卡片宽度 ≥ 340px** 时才用单行式(每个窗口一行「数值 · 进度条 · 百分比」,两端对齐、重置时间与窗口名同行)。左侧边栏与窄卡片始终沿用原紧凑双行式,不因宽度变化而跳动。
112
112
  - 右侧位置会在对话区右侧**预留一条槽**:插件给对话列加右侧内边距(约列宽的 26%,封顶 34%),正文与轮次导航条整体左移,卡片占住这条槽——因此不遮挡正文、不遮挡轮次导航条、也不遮挡右侧原生按钮。上沿从「对话 / 轨迹 / 看板」选项卡下的分隔线以下 6px 开始。
113
113
  - 窄窗口或打开侧栏时槽宽自动收窄(下限 140px),卡片始终可见;如果连正文最小宽度都不够,则允许卡片比常规更窄,而不是消失。
114
114
  - 换边不重新加载:两处卡片共用同一份已取到的数据。底色用左侧边栏的底色(`--dsw-specific-sidebar-fill`),阴影与左侧一致。
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.39';
14
+ const CLIENT_VERSION = '1.1.46';
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`;
@@ -476,8 +476,8 @@ window.__ModuleLoader__.load({
476
476
  },
477
477
  legendRow: {
478
478
  display: 'grid',
479
- gridTemplateColumns: 'var(--ustc-key-col, 36px) repeat(3, minmax(0, 1fr)) auto',
480
- columnGap: 8,
479
+ gridTemplateColumns: 'var(--ustc-key-col, 36px) repeat(3, minmax(0, 1fr))',
480
+ columnGap: 'var(--ustc-gap, 4px)',
481
481
  alignItems: 'center',
482
482
  minWidth: 0,
483
483
  paddingBottom: 4,
@@ -486,7 +486,7 @@ window.__ModuleLoader__.load({
486
486
  keyRow: {
487
487
  display: 'grid',
488
488
  gridTemplateColumns: 'var(--ustc-key-col, 36px) repeat(3, minmax(0, 1fr))',
489
- columnGap: 8,
489
+ columnGap: 'var(--ustc-gap, 4px)',
490
490
  alignItems: 'center',
491
491
  minWidth: 0,
492
492
  paddingTop: 6,
@@ -499,6 +499,14 @@ window.__ModuleLoader__.load({
499
499
  alignItems: 'center',
500
500
  gap: 0,
501
501
  },
502
+ legendCellWide: {
503
+ minWidth: 0,
504
+ display: 'flex',
505
+ flexDirection: 'row',
506
+ alignItems: 'baseline',
507
+ justifyContent: 'center',
508
+ gap: 5,
509
+ },
502
510
  legendName: {
503
511
  fontSize: 10,
504
512
  fontWeight: 700,
@@ -561,6 +569,12 @@ window.__ModuleLoader__.load({
561
569
  cursor: 'help',
562
570
  },
563
571
  cell: {
572
+ minWidth: 0,
573
+ display: 'flex',
574
+ flexDirection: 'column',
575
+ gap: 2,
576
+ },
577
+ cellWide: {
564
578
  minWidth: 0,
565
579
  display: 'flex',
566
580
  flexDirection: 'row',
@@ -584,7 +598,17 @@ window.__ModuleLoader__.load({
584
598
  minWidth: 0,
585
599
  },
586
600
  value: {
601
+ minWidth: 0,
602
+ fontSize: 10.5,
603
+ fontWeight: 650,
604
+ color: 'var(--dsw-alias-label-primary)',
605
+ whiteSpace: 'nowrap',
606
+ overflow: 'hidden',
607
+ textOverflow: 'ellipsis',
608
+ },
609
+ valueWide: {
587
610
  flex: '0 0 auto',
611
+ width: 'var(--ustc-value-w, 44px)',
588
612
  textAlign: 'right',
589
613
  fontSize: 10,
590
614
  fontWeight: 650,
@@ -593,7 +617,7 @@ window.__ModuleLoader__.load({
593
617
  overflow: 'hidden',
594
618
  textOverflow: 'ellipsis',
595
619
  },
596
- percent: {
620
+ percentWide: {
597
621
  flex: '0 0 auto',
598
622
  width: 24,
599
623
  textAlign: 'right',
@@ -601,6 +625,12 @@ window.__ModuleLoader__.load({
601
625
  color: 'var(--dsw-alias-label-secondary)',
602
626
  whiteSpace: 'nowrap',
603
627
  },
628
+ percent: {
629
+ flex: '0 0 auto',
630
+ fontSize: 8.5,
631
+ color: 'var(--dsw-alias-label-secondary)',
632
+ whiteSpace: 'nowrap',
633
+ },
604
634
  bar: {
605
635
  position: 'relative',
606
636
  height: 6,
@@ -1164,72 +1194,6 @@ window.__ModuleLoader__.load({
1164
1194
  const DOCK_TRANSCRIPT_FLOOR = 360;
1165
1195
 
1166
1196
 
1167
- // When the blank strip beside the transcript is too narrow, free room on the
1168
- // right instead of letting the card shrink: pad the conversation column and pin
1169
- // the transcript to the left edge of that padded box.
1170
- const DOCK_COMFORT = 220;
1171
- let pushedColumn = null;
1172
- let pushedTarget = null;
1173
- let pushedSaved = null;
1174
- let padState = 0;
1175
-
1176
- function transcriptOf() {
1177
- const flow = document.querySelector('[data-slot="conversation.chat.flow"]');
1178
- if (!flow) return null;
1179
- let node = flow;
1180
- for (let i = 0; i < 6 && node; i += 1) {
1181
- const style = getComputedStyle(node);
1182
- if (style.marginLeft === 'auto' || style.marginRight === 'auto') return node;
1183
- node = node.parentElement;
1184
- }
1185
- return flow.firstElementChild || flow;
1186
- }
1187
-
1188
- function pushConversation(reserve) {
1189
- const holder = document.querySelector('[data-slot="main.conversation"]');
1190
- const column = holder ? (holder.firstElementChild || holder) : null;
1191
- if (!column) return;
1192
- const target = transcriptOf();
1193
- if (!target) return;
1194
- if (pushedColumn !== column) {
1195
- releaseConversation();
1196
- pushedColumn = column;
1197
- pushedSaved = {
1198
- pad: column.style.getPropertyValue('padding-right'),
1199
- padPriority: column.style.getPropertyPriority('padding-right'),
1200
- };
1201
- }
1202
- if (pushedTarget !== target) {
1203
- if (pushedTarget) {
1204
- pushedTarget.style.removeProperty('margin-left');
1205
- pushedTarget.style.removeProperty('margin-right');
1206
- }
1207
- pushedTarget = target;
1208
- target.style.setProperty('margin-left', '0px', 'important');
1209
- target.style.setProperty('margin-right', 'auto', 'important');
1210
- }
1211
- const wanted = reserve + 'px';
1212
- if (column.style.getPropertyValue('padding-right') !== wanted) {
1213
- column.style.setProperty('padding-right', wanted, 'important');
1214
- }
1215
- padState = reserve;
1216
- }
1217
-
1218
- function releaseConversation() {
1219
- if (pushedTarget) {
1220
- pushedTarget.style.removeProperty('margin-left');
1221
- pushedTarget.style.removeProperty('margin-right');
1222
- pushedTarget = null;
1223
- }
1224
- if (pushedColumn && pushedSaved) {
1225
- if (pushedSaved.pad) pushedColumn.style.setProperty('padding-right', pushedSaved.pad, pushedSaved.padPriority);
1226
- else pushedColumn.style.removeProperty('padding-right');
1227
- }
1228
- pushedColumn = null;
1229
- pushedSaved = null;
1230
- padState = 0;
1231
- }
1232
-
1233
1197
  function measureRightDock() {
1234
1198
  const holder = document.querySelector('[data-slot="main.conversation"]');
1235
1199
  const column = holder ? (holder.firstElementChild || holder) : null;
@@ -1249,15 +1213,18 @@ window.__ModuleLoader__.load({
1249
1213
  }
1250
1214
  if (boundaryRight === null) boundaryRight = columnRect.left + columnRect.width * 0.5 + 24;
1251
1215
 
1252
- // Right bound: whatever native chrome lives at the column's right edge — the
1253
- // turn rail when there are turns, otherwise the right-sidebar rail button.
1216
+ // Right bound: the turn rail when there are turns; otherwise the collapsed
1217
+ // right-sidebar icon rail, which only counts when it sits at the far right.
1254
1218
  let rightLimit = columnRect.right;
1255
1219
  for (const button of document.querySelectorAll('button[aria-label]')) {
1256
1220
  const label = button.getAttribute('aria-label') || '';
1257
- if (!/turnNavigation|轮次|跳转|右侧边栏/i.test(label)) continue;
1221
+ const isTurn = /turnNavigation|轮次|跳转/i.test(label);
1222
+ const isRail = /右侧边栏/.test(label);
1223
+ if (!isTurn && !isRail) continue;
1258
1224
  const rect = button.getBoundingClientRect();
1259
1225
  if (rect.width <= 0 || rect.height <= 0) continue;
1260
1226
  if (rect.left <= boundaryRight) continue;
1227
+ if (isRail && columnRect.right - rect.left > 72) continue;
1261
1228
  if (rect.left < rightLimit) rightLimit = rect.left;
1262
1229
  }
1263
1230
  if (rightLimit > columnRect.right) rightLimit = columnRect.right;
@@ -1309,20 +1276,7 @@ window.__ModuleLoader__.load({
1309
1276
  observer = new ResizeObserver(schedule);
1310
1277
  observer.observe(column);
1311
1278
  }
1312
- const next = measureRightDock();
1313
- if (activeRef.current && next) {
1314
- const natural = next.naturalSpan;
1315
- let pad = padState;
1316
- if (natural < DOCK_COMFORT - 8) pad = pad + (DOCK_COMFORT - natural);
1317
- else if (natural > DOCK_COMFORT + 24) pad = Math.max(0, pad - (natural - DOCK_COMFORT));
1318
- const limit = Math.max(0, next.columnWidth - 340);
1319
- pad = Math.min(Math.round(pad), limit);
1320
- if (pad > 0) pushConversation(pad);
1321
- else releaseConversation();
1322
- } else {
1323
- releaseConversation();
1324
- }
1325
- setBox(next);
1279
+ setBox(measureRightDock());
1326
1280
  };
1327
1281
  function schedule() {
1328
1282
  if (!frame) frame = window.requestAnimationFrame(measure);
@@ -1362,6 +1316,9 @@ window.__ModuleLoader__.load({
1362
1316
  const position = usePanelPosition();
1363
1317
  const active = props.active !== false;
1364
1318
  const [cardHovered, setCardHovered] = React.useState(false);
1319
+ const [narrow, setNarrow] = React.useState(false);
1320
+ // The one-line layout needs ~340px of card width; below that keep the compact card.
1321
+ const wideLayout = placement === 'right' && !narrow;
1365
1322
  const [markHovered, setMarkHovered] = React.useState(false);
1366
1323
  const activeRef = React.useRef(active);
1367
1324
  activeRef.current = active;
@@ -1547,6 +1504,19 @@ window.__ModuleLoader__.load({
1547
1504
  };
1548
1505
  }, [load]);
1549
1506
 
1507
+ React.useLayoutEffect(() => {
1508
+ const root = rootRef.current;
1509
+ if (!root || typeof ResizeObserver !== 'function') return undefined;
1510
+ const observer = new ResizeObserver(() => {
1511
+ // Border-box width: the padding-free content box is always smaller and would
1512
+ // misfire the threshold by the card's own insets.
1513
+ const width = root.getBoundingClientRect().width;
1514
+ setNarrow(width < 340);
1515
+ });
1516
+ observer.observe(root);
1517
+ return () => { observer.disconnect(); };
1518
+ }, [props.wide]);
1519
+
1550
1520
  React.useLayoutEffect(() => {
1551
1521
  const root = rootRef.current;
1552
1522
  if (!root) return undefined;
@@ -1746,7 +1716,7 @@ window.__ModuleLoader__.load({
1746
1716
  ...candidates.map((window) => `${window.id}: ${window.resetAt ? formatFull(window.resetAt) : t('notConfigured')}`),
1747
1717
  ].join('\n')
1748
1718
  : label;
1749
- return h('div', { style: STYLE.legendCell, title },
1719
+ return h('div', { style: wideLayout ? STYLE.legendCellWide : STYLE.legendCell, title },
1750
1720
  h('div', { style: STYLE.legendName }, label),
1751
1721
  h('div', { style: STYLE.legendReset }, resetText)
1752
1722
  );
@@ -1803,30 +1773,44 @@ window.__ModuleLoader__.load({
1803
1773
  if (window.source) titleParts.push(sourceLabel(window.source));
1804
1774
  if (isStale) titleParts.push(t('stale'));
1805
1775
 
1806
- return h('div', { style: STYLE.cell, title: titleParts.join(' · ') },
1807
- h('span', { style: STYLE.value }, `${isStale ? '≈ ' : ''}${valueText}`),
1808
- h('div', {
1809
- style: { ...STYLE.inlineBar, opacity: isStale ? 0.55 : 1 },
1810
- role: 'progressbar',
1811
- 'aria-label': label,
1812
- 'aria-valuemin': 0,
1813
- 'aria-valuemax': 100,
1814
- 'aria-valuenow': ratio === null ? undefined : Math.round(Math.min(1, Math.max(0, ratio)) * 100),
1815
- 'aria-valuetext': percent || valueText,
1776
+ const barNode = (style) => h('div', {
1777
+ style: { ...style, opacity: isStale ? 0.55 : 1 },
1778
+ role: 'progressbar',
1779
+ 'aria-label': label,
1780
+ 'aria-valuemin': 0,
1781
+ 'aria-valuemax': 100,
1782
+ 'aria-valuenow': ratio === null ? undefined : Math.round(Math.min(1, Math.max(0, ratio)) * 100),
1783
+ 'aria-valuetext': percent || valueText,
1784
+ },
1785
+ h('div', { style: STYLE.track, 'aria-hidden': true }),
1786
+ h('div', {
1787
+ style: {
1788
+ position: 'relative',
1789
+ height: '100%',
1790
+ width: fillWidth,
1791
+ background: usedColor,
1792
+ borderRadius: 999,
1793
+ transition: 'width 200ms ease',
1816
1794
  },
1817
- h('div', { style: STYLE.track, 'aria-hidden': true }),
1818
- h('div', {
1819
- style: {
1820
- position: 'relative',
1821
- height: '100%',
1822
- width: fillWidth,
1823
- background: usedColor,
1824
- borderRadius: 999,
1825
- transition: 'width 200ms ease',
1826
- },
1827
- })
1795
+ })
1796
+ );
1797
+ const valueNode = (style) => h('span', { style }, `${isStale ? '≈ ' : ''}${valueText}`);
1798
+ const percentNode = (style) => (percent ? h('span', { style: { ...style, color: percentColor } }, percent) : null);
1799
+
1800
+ if (wideLayout) {
1801
+ return h('div', { style: STYLE.cellWide, title: titleParts.join(' · ') },
1802
+ valueNode(STYLE.valueWide),
1803
+ barNode(STYLE.inlineBar),
1804
+ percentNode(STYLE.percentWide)
1805
+ );
1806
+ }
1807
+
1808
+ return h('div', { style: STYLE.cell, title: titleParts.join(' · ') },
1809
+ h('div', { style: STYLE.valueLine },
1810
+ valueNode(STYLE.value),
1811
+ percentNode(STYLE.percent)
1828
1812
  ),
1829
- percent ? h('span', { style: { ...STYLE.percent, color: percentColor } }, percent) : null
1813
+ barNode(STYLE.bar)
1830
1814
  );
1831
1815
  }
1832
1816
 
@@ -1880,7 +1864,24 @@ window.__ModuleLoader__.load({
1880
1864
 
1881
1865
  const failed = keys.filter((key) => key.ok === false);
1882
1866
  const keyColumnWidth = keyColumnWidthFor(keys, activeProvider, defaultProvider);
1883
- const tableStyle = { ...STYLE.table, '--ustc-key-col': `${keyColumnWidth}px` };
1867
+ // Align the bars by sizing the value column to the longest value on screen.
1868
+ let valueChars = 3;
1869
+ for (const key of keys) {
1870
+ for (const window of (key.windows || [])) {
1871
+ const usedValue = typeof window.used === 'number' && Number.isFinite(window.used) ? window.used : null;
1872
+ const limitValue = typeof window.limit === 'number' && Number.isFinite(window.limit) ? window.limit : null;
1873
+ const text = usedValue === null
1874
+ ? '—'
1875
+ : `${formatNumber(usedValue)}/${limitValue === null ? '—' : formatNumber(limitValue)}`;
1876
+ if (text.length > valueChars) valueChars = text.length;
1877
+ }
1878
+ }
1879
+ const tableStyle = {
1880
+ ...STYLE.table,
1881
+ '--ustc-key-col': `${keyColumnWidth}px`,
1882
+ '--ustc-gap': wideLayout ? '16px' : '4px',
1883
+ '--ustc-value-w': `${Math.min(12, valueChars + 0.5)}ch`,
1884
+ };
1884
1885
  const versionTitle = updateInfo && updateInfo.updateAvailable
1885
1886
  ? `${t('updateAvailable')} v${updateInfo.latestVersion}`
1886
1887
  : updateChecking
@@ -1919,6 +1920,7 @@ window.__ModuleLoader__.load({
1919
1920
  : null,
1920
1921
  error && snapshot ? h('span', { style: STYLE.warn, title: error }, '!') : null,
1921
1922
 
1923
+ h('span', { style: STYLE.meta }, updated ? `${t('updatedLabel')} ${updated}` : ''),
1922
1924
  h('button', {
1923
1925
  type: 'button',
1924
1926
  'aria-label': t('refresh'),
@@ -1955,7 +1957,6 @@ window.__ModuleLoader__.load({
1955
1957
  h('div', { style: STYLE.legendRow },
1956
1958
  h('div', { key: 'corner' }),
1957
1959
  WINDOW_IDS.map((id) => h(React.Fragment, { key: id }, windowLegend(id))),
1958
- h('div', { key: 'updated', style: STYLE.legendMeta, title: updated || '' }, updated ? `${t('updatedLabel')} ${updated}` : '')
1959
1960
  ),
1960
1961
  keys.map((key, index) => keyRow(key, index, activeProvider))
1961
1962
  ),
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.39';
25
+ const PLUGIN_VERSION = '1.1.46';
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.39",
3
+ "version": "1.1.46",
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).",